From 51934ef4786a2f4d4e37890100d270c067bfccd3 Mon Sep 17 00:00:00 2001 From: hugocasa Date: Thu, 8 Oct 2026 16:33:46 +0200 Subject: [PATCH] fix: add the unsynced note whatever the resource type search returns Co-Authored-By: Claude Opus 5.5 --- .../components/copilot/chat/script/core.test.ts | 4 +++- .../lib/components/copilot/chat/script/core.ts | 17 ++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/frontend/src/lib/components/copilot/chat/script/core.test.ts b/frontend/src/lib/components/copilot/chat/script/core.test.ts index 6bfcbc1d21..51ed20f04a 100644 --- a/frontend/src/lib/components/copilot/chat/script/core.test.ts +++ b/frontend/src/lib/components/copilot/chat/script/core.test.ts @@ -22,7 +22,9 @@ describe('searchResourceTypes', () => { [['ai_skill', 'ai_instruction'], true], [Array.from({ length: 30 }, (_, i) => `type_${i}`), false] ])('notes only an instance that never synced with the hub (%#)', async (names, noted) => { - vi.spyOn(ResourceService, 'queryResourceTypes').mockResolvedValue([]) + vi.spyOn(ResourceService, 'queryResourceTypes').mockResolvedValue([ + { name: 'ai_skill', score: 0.8 } + ]) vi.spyOn(ResourceService, 'listResourceTypeNames').mockResolvedValue(names) const { note } = await searchResourceTypes('stripe', 'ws', 5) diff --git a/frontend/src/lib/components/copilot/chat/script/core.ts b/frontend/src/lib/components/copilot/chat/script/core.ts index 94272656a0..0543e0b089 100644 --- a/frontend/src/lib/components/copilot/chat/script/core.ts +++ b/frontend/src/lib/components/copilot/chat/script/core.ts @@ -72,18 +72,21 @@ export function formatResourceTypes( // so fewer than this means the instance never synced with the hub. const UNSYNCED_RESOURCE_TYPE_COUNT = 20 -/** When nothing matches, a note says whether the instance seems never to have synced with the hub. */ +/** + * The note on an unsynced instance cannot wait for an empty result: the similarity search + * still returns the nearest of the few types there are (the instance's own `ai_skill` scores + * about 0.8 for "confluence"). + */ export async function searchResourceTypes( query: string, workspace: string, limit: number ): Promise<{ resourceTypes: Pick[]; note?: string }> { - const resourceTypes = await ResourceService.queryResourceTypes({ workspace, text: query, limit }) - if (resourceTypes.length > 0) { - return { resourceTypes } - } - const count = new Set(await ResourceService.listResourceTypeNames({ workspace }).catch(() => [])) - .size + const [resourceTypes, names] = await Promise.all([ + ResourceService.queryResourceTypes({ workspace, text: query, limit }), + ResourceService.listResourceTypeNames({ workspace }).catch(() => []) + ]) + const count = new Set(names).size return { resourceTypes, note: