Skip to content

Commit

Permalink
🐛 fix: fix function apiName length
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Dec 16, 2023
1 parent 3aa8219 commit b6f8c16
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/services/__tests__/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('ChatService', () => {

expect(getChatCompletionSpy).toHaveBeenCalledWith(
expect.objectContaining({
functions: expect.arrayContaining([{ name: 'plugin1____api1____default' }]),
functions: expect.arrayContaining([{ name: 'plugin1____api1' }]),
messages: expect.anything(),
}),
undefined,
Expand Down
25 changes: 22 additions & 3 deletions src/store/tool/slices/plugin/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const mockState = {
manifest: {
identifier: 'plugin-2',
api: [{ name: 'api-2' }],
type: 'default',
},
type: 'plugin',
},
Expand All @@ -53,9 +52,29 @@ const mockState = {
describe('pluginSelectors', () => {
describe('enabledSchema', () => {
it('enabledSchema should return correct ChatCompletionFunctions array', () => {
const result = pluginSelectors.enabledSchema(['plugin-1'])(mockState);
expect(result).toEqual([{ name: 'plugin-1____api-1____default' }]);
const result = pluginSelectors.enabledSchema(['plugin-1', 'plugin-2'])(mockState);
expect(result).toEqual([{ name: 'plugin-1____api-1' }, { name: 'plugin-2____api-2' }]);
});

it('enabledSchema should return with standalone plugin', () => {
const result = pluginSelectors.enabledSchema(['plugin-3'])({
...mockState,
installedPlugins: [
...mockState.installedPlugins,
{
identifier: 'plugin-3',
manifest: {
identifier: 'plugin-3',
api: [{ name: 'api-3' }],
type: 'standalone',
},
type: 'plugin',
},
],
} as ToolStoreState);
expect(result).toEqual([{ name: 'plugin-3____api-3____standalone' }]);
});

it('enabledSchema should return empty', () => {
const result = pluginSelectors.enabledSchema([])(mockState);
expect(result).toEqual([]);
Expand Down
5 changes: 4 additions & 1 deletion src/store/tool/slices/plugin/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ const enabledSchema =
)
.flatMap((manifest) =>
manifest.api.map((m) => {
const pluginType = manifest.type ? `${PLUGIN_SCHEMA_SEPARATOR + manifest.type}` : '';
const pluginType =
manifest.type && manifest.type !== 'default'
? `${PLUGIN_SCHEMA_SEPARATOR + manifest.type}`
: '';

// 将插件的 identifier 作为前缀,避免重复
let apiName = manifest.identifier + PLUGIN_SCHEMA_SEPARATOR + m.name + pluginType;
Expand Down

0 comments on commit b6f8c16

Please sign in to comment.