From 3aa7e7d327d50e18a165fe9af99ef47fabdbfbe9 Mon Sep 17 00:00:00 2001 From: arvinxx Date: Fri, 15 Dec 2023 23:47:16 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20fix=20function=20apiName?= =?UTF-8?q?=20length?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tool/slices/plugin/selectors.test.ts | 21 ++++++++++++++++++- src/store/tool/slices/plugin/selectors.ts | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/store/tool/slices/plugin/selectors.test.ts b/src/store/tool/slices/plugin/selectors.test.ts index f640beb2c1de..3a157fe2fe9f 100644 --- a/src/store/tool/slices/plugin/selectors.test.ts +++ b/src/store/tool/slices/plugin/selectors.test.ts @@ -54,8 +54,27 @@ 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' }]); + expect(result).toEqual([{ name: 'plugin-1____api-1' }]); }); + 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([]); diff --git a/src/store/tool/slices/plugin/selectors.ts b/src/store/tool/slices/plugin/selectors.ts index 617f6274438c..1aff8020f1ab 100644 --- a/src/store/tool/slices/plugin/selectors.ts +++ b/src/store/tool/slices/plugin/selectors.ts @@ -91,7 +91,8 @@ const enabledSchema = ) .flatMap((manifest) => manifest.api.map((m) => { - const pluginType = manifest.type ? `${PLUGIN_SCHEMA_SEPARATOR + manifest.type}` : ''; + const pluginType = + manifest.type !== 'default' ? `${PLUGIN_SCHEMA_SEPARATOR + manifest.type}` : ''; // 将插件的 identifier 作为前缀,避免重复 let apiName = manifest.identifier + PLUGIN_SCHEMA_SEPARATOR + m.name + pluginType;