Skip to content

Commit d2b0ddd

Browse files
committed
improvement(search): accept several same-kind native queries per account and cap oversized read limits
1 parent e715c5b commit d2b0ddd

6 files changed

Lines changed: 21 additions & 19 deletions

File tree

‎apps/sim/lib/api/contracts/mothership-assistant-tools.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ describe('Assistant execution contracts', () => {
5757
expect(accepts([trip, { ...trip, accountId: 'other' }])).toBe(true)
5858
})
5959

60-
it('takes one GitHub or GitLab query per account and kind', () => {
60+
it('runs several same-kind GitHub queries on one account but refuses kind fan-out overlap', () => {
6161
const accepts = (nativeQueries: Record<string, string>[]) =>
6262
searchWorkspaceInputSchema.safeParse({ query: 'launch', nativeQueries }).success
6363
const github = { provider: 'github', accountId: 'account', query: 'repo:org/repo launch' }
6464
const kinds = ['issues', 'commits', 'code', 'repositories'].map((kind) => ({ ...github, kind }))
6565
expect(accepts(kinds)).toBe(true)
66-
expect(accepts([kinds[0]!, { ...kinds[0]!, query: 'repo:org/repo deploy' }])).toBe(false)
66+
expect(accepts([kinds[0]!, { ...kinds[0]!, query: 'repo:org/repo deploy' }])).toBe(true)
6767
expect(accepts([kinds[0]!, github])).toBe(false)
6868
expect(
6969
searchWorkspaceInputSchema.safeParse({ nativeQueries: [{ provider: 'github', query: '' }] })

‎apps/sim/lib/api/contracts/mothership-assistant-tools.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ export const nativeSearchQueriesSchema = z
102102
addIssue('Duplicate native query.')
103103
else if (
104104
hasSearchKinds(query.provider) &&
105-
earlier.some((previous) => !previous.kind || !query.kind || previous.kind === query.kind)
105+
earlier.some((previous) => !previous.kind || !query.kind)
106106
)
107107
addIssue(
108-
'Send one query per account and kind for GitHub, GitLab, or HubSpot. Use provider-supported operators for alternatives, or send another call.'
108+
'A GitHub, GitLab, or HubSpot query without a kind already searches every kind; give each query on this account a kind.'
109109
)
110110
else if (busiestAccountLoad(earlier) >= MAX_NATIVE_QUERIES_PER_ACCOUNT)
111111
addIssue(
@@ -246,11 +246,12 @@ export const readDocumentInputSchema = z.object({
246246
.min(1)
247247
.max(4000)
248248
.describe('Canonical document ID returned by search or selected document context.'),
249+
/** A larger request is capped rather than refused: the server returns at most 8 chunks anyway. */
249250
limit: z
250-
.number()
251-
.int()
252-
.min(1)
253-
.max(8)
251+
.preprocess(
252+
(limit) => (typeof limit === 'number' && limit > 8 ? 8 : limit),
253+
z.number().int().min(1).max(8)
254+
)
254255
.default(3)
255256
.describe(
256257
'Maximum number of chunks, from 1 to 8 (default 3); the server may return fewer to fit its text budget. Follow next for more context.'

‎apps/sim/lib/mothership/generated/sim-assistant-tools.generated.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ export const nativeSearchQueriesSchema = z
119119
addIssue('Duplicate native query.')
120120
else if (
121121
hasSearchKinds(query.provider) &&
122-
earlier.some((previous) => !previous.kind || !query.kind || previous.kind === query.kind)
122+
earlier.some((previous) => !previous.kind || !query.kind)
123123
)
124124
addIssue(
125-
'Send one query per account and kind for GitHub, GitLab, or HubSpot. Use provider-supported operators for alternatives, or send another call.'
125+
'A GitHub, GitLab, or HubSpot query without a kind already searches every kind; give each query on this account a kind.'
126126
)
127127
else if (busiestAccountLoad(earlier) >= MAX_NATIVE_QUERIES_PER_ACCOUNT)
128128
addIssue(
@@ -263,11 +263,12 @@ export const readDocumentInputSchema = z.object({
263263
.min(1)
264264
.max(4000)
265265
.describe('Canonical document ID returned by search or selected document context.'),
266+
/** A larger request is capped rather than refused: the server returns at most 8 chunks anyway. */
266267
limit: z
267-
.number()
268-
.int()
269-
.min(1)
270-
.max(8)
268+
.preprocess(
269+
(limit) => (typeof limit === 'number' && limit > 8 ? 8 : limit),
270+
z.number().int().min(1).max(8)
271+
)
271272
.default(3)
272273
.describe(
273274
'Maximum number of chunks, from 1 to 8 (default 3); the server may return fewer to fit its text budget. Follow next for more context.'

‎apps/sim/lib/mothership/generated/tool-catalog-v1.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5196,7 +5196,6 @@ export const ReadDocument: ToolCatalogEntry = {
51965196
description: 'Canonical document ID returned by search or selected document context.',
51975197
},
51985198
limit: {
5199-
default: 3,
52005199
description:
52015200
'Maximum number of chunks, from 1 to 8 (default 3); the server may return fewer to fit its text budget. Follow next for more context.',
52025201
type: 'integer',

‎apps/sim/lib/mothership/generated/tool-schemas-v1.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5184,7 +5184,6 @@ export const TOOL_RUNTIME_SCHEMAS: Record<string, ToolRuntimeSchemaEntry> = {
51845184
description: 'Canonical document ID returned by search or selected document context.',
51855185
},
51865186
limit: {
5187-
default: 3,
51885187
description:
51895188
'Maximum number of chunks, from 1 to 8 (default 3); the server may return fewer to fit its text budget. Follow next for more context.',
51905189
type: 'integer',

‎apps/sim/lib/mothership/tools/server/knowledge/workspace-search.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ describe('Assistant retrieval tools', () => {
376376
expect(mocks.search).not.toHaveBeenCalled()
377377
expect(mocks.read).not.toHaveBeenCalled()
378378
})
379-
it('reads a selected document through the shared use case and rejects unbounded pages', async () => {
379+
it('reads a selected document through the shared use case and caps oversized pages', async () => {
380380
expect(
381381
await readDocumentServerTool.execute({ documentId: 'doc', startChunkIndex: 20 }, context)
382382
).toMatchObject({ success: true })
@@ -392,7 +392,9 @@ describe('Assistant retrieval tools', () => {
392392
)
393393
expect(
394394
await readDocumentServerTool.execute({ documentId: 'doc', limit: 9 }, context)
395-
).toMatchObject({ success: false })
396-
expect(mocks.read).toHaveBeenCalledOnce()
395+
).toMatchObject({ success: true })
396+
expect(mocks.read).toHaveBeenLastCalledWith(
397+
expect.objectContaining({ input: expect.objectContaining({ limit: 8 }) })
398+
)
397399
})
398400
})

0 commit comments

Comments
 (0)