diff --git a/frontend/src/lib/components/copilot/chat/shared.test.ts b/frontend/src/lib/components/copilot/chat/shared.test.ts index 1c3d733020..9087e07ec5 100644 --- a/frontend/src/lib/components/copilot/chat/shared.test.ts +++ b/frontend/src/lib/components/copilot/chat/shared.test.ts @@ -1433,7 +1433,10 @@ describe('createSearchHubScriptsTool', () => { toolCallbacks: { setToolStatus: vi.fn() } } as any) - expect(JSON.parse(raw).results.map((r: any) => r.integration)).toContain('salesforce') + const integrations = JSON.parse(raw).results.map((r: any) => r.integration) + expect(integrations).toContain('salesforce') + // reserving room for the tail must not re-emit it when nothing was cut + expect(new Set(integrations).size).toBe(integrations.length) }) // Ranking buries an integration the query names when other integrations' scripts diff --git a/frontend/src/lib/components/copilot/chat/shared.ts b/frontend/src/lib/components/copilot/chat/shared.ts index babcc2aa5c..200578c1b4 100644 --- a/frontend/src/lib/components/copilot/chat/shared.ts +++ b/frontend/src/lib/components/copilot/chat/shared.ts @@ -1519,14 +1519,13 @@ export const createSearchHubScriptsTool = (withContent: boolean = false) => ({ } // Each result costs a content fetch, so cap the fan-out when content is wanted. - // Keep the tail: hits appended for a named integration sit there, and dropping - // them would undo the reason they were fetched. - const matches = withContent - ? [ - ...scripts.slice(0, MAX_FETCHED_HUB_SCRIPTS - mentionedHits), - ...scripts.slice(scripts.length - mentionedHits) - ] - : scripts + // Cut from the middle: hits appended for a named integration sit at the tail, + // and dropping those would undo the reason they were fetched. + let matches = scripts + if (withContent && scripts.length > MAX_FETCHED_HUB_SCRIPTS) { + const mentioned = scripts.slice(scripts.length - mentionedHits) + matches = [...scripts.slice(0, MAX_FETCHED_HUB_SCRIPTS - mentioned.length), ...mentioned] + } toolCallbacks.setToolStatus(toolId, { content: `Found ${matches.length} hub script${matches.length === 1 ? '' : 's'} for ${subject}` })