fix: add the unsynced note whatever the resource type search returns

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-10-08 16:33:46 +02:00
co-authored by Claude Opus 5.5
parent 9440eb2f9d
commit 51934ef478
2 changed files with 13 additions and 8 deletions
@@ -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)
@@ -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<ResourceType, 'name' | 'schema'>[]; 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: