Skip to content

Commit 905b5f6

Browse files
committed
fix(integrations): send only Lite-supported Exa params, skip untouched Exa fields, widen the Tavily error reader, and clear stale Jina search values
1 parent 46777ae commit 905b5f6

10 files changed

Lines changed: 141 additions & 34 deletions

File tree

‎apps/sim/blocks/blocks/exa.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ export const ExaBlock: BlockConfig = {
604604
if (params.extrasImageLinks) {
605605
result.extrasImageLinks = Number(params.extrasImageLinks)
606606
}
607-
if (params.maxAgeHours !== undefined && String(params.maxAgeHours).trim() !== '') {
607+
if (params.maxAgeHours != null && String(params.maxAgeHours).trim() !== '') {
608608
result.maxAgeHours = Number(params.maxAgeHours)
609609
}
610610
if (params.livecrawlTimeout) {

‎apps/sim/blocks/blocks/jina.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ export const JinaBlock: BlockConfig = {
176176
*/
177177
params: (params, context) => {
178178
if (mapperOperation(params, context) !== 'jina_search') return {}
179-
const result: Record<string, unknown> = {}
180-
const returnFormat = params.searchReturnFormat || toolCallArg(context, params.returnFormat)
181-
if (returnFormat) result.returnFormat = returnFormat
182-
const retainImages = params.searchRetainImages || toolCallArg(context, params.retainImages)
183-
if (retainImages) result.retainImages = retainImages
184-
return result
179+
return {
180+
returnFormat:
181+
params.searchReturnFormat || toolCallArg(context, params.returnFormat) || undefined,
182+
retainImages:
183+
params.searchRetainImages || toolCallArg(context, params.retainImages) || undefined,
184+
}
185185
},
186186
},
187187
},

‎apps/sim/tools/error-extractors.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,29 @@ describe('Error Extractors', () => {
169169
})
170170

171171
describe('extractErrorMessage with explicit extractorId', () => {
172+
it.each([
173+
[
174+
'a FastAPI validation array',
175+
{
176+
detail: [
177+
{ loc: ['body', 'max_results'], msg: 'Input should be less than or equal to 20' },
178+
{ loc: ['body', 'topic'], msg: "Input should be 'general', 'news' or 'finance'" },
179+
],
180+
},
181+
"Input should be less than or equal to 20; Input should be 'general', 'news' or 'finance'",
182+
],
183+
['a plain-text body', 'Upstream gateway timeout', 'Upstream gateway timeout'],
184+
['a top-level error string', { error: 'Rate limit exceeded' }, 'Rate limit exceeded'],
185+
['an unrecognized body', { unexpected: true }, 'Bad Request'],
186+
])('reads the Tavily message from %s', (_label, data, expected) => {
187+
expect(
188+
extractErrorMessage(
189+
{ status: 400, statusText: 'Bad Request', data },
190+
ErrorExtractorId.TAVILY_ERRORS
191+
)
192+
).toBe(expected)
193+
})
194+
172195
it("reads Tavily's detail.error message instead of the bare status text", () => {
173196
const errorInfo: ErrorInfo = {
174197
status: 400,

‎apps/sim/tools/error-extractors.ts‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* 2. Add the ID to ErrorExtractorId constant at the bottom of this file
2020
*/
2121

22+
import { isRecordLike } from '@sim/utils/object'
2223
import { parseGraphErrorFromData } from '@/tools/microsoft_excel/utils'
2324
import { formatQuickBooksFaultDetail, sanitizeQuickBooksFaultData } from '@/tools/quickbooks/fault'
2425

@@ -643,13 +644,28 @@ const ERROR_EXTRACTORS: ErrorExtractorConfig[] = [
643644
},
644645
{
645646
id: 'tavily-errors',
646-
description: 'Tavily error body: `detail.error` string (FastAPI-style detail object)',
647+
description:
648+
'Tavily error bodies: FastAPI `detail` as an object with `error`, a string, or a validation array; a top-level `error`; or a plain-text body',
647649
examples: ['Tavily'],
648650
explicitOnly: true,
649651
extract: (errorInfo) => {
650-
const detail = errorInfo?.data?.detail
652+
const data = errorInfo?.data
653+
if (typeof data === 'string') return data.trim() || errorInfo?.statusText
654+
const detail = data?.detail
651655
if (typeof detail === 'string') return detail
652-
return typeof detail?.error === 'string' ? detail.error : undefined
656+
if (typeof detail?.error === 'string') return detail.error
657+
if (Array.isArray(detail)) {
658+
const messages = detail
659+
.map((issue: unknown) =>
660+
isRecordLike(issue) && typeof issue.msg === 'string' ? issue.msg : undefined
661+
)
662+
.filter((message): message is string => Boolean(message))
663+
if (messages.length > 0) return messages.join('; ')
664+
}
665+
if (typeof data?.error === 'string') return data.error
666+
if (typeof data?.error?.message === 'string') return data.error.message
667+
if (typeof data?.message === 'string') return data.message
668+
return errorInfo?.statusText
653669
},
654670
},
655671
{

‎apps/sim/tools/exa/exa.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,55 @@ describe('exa_answer', () => {
157157
})
158158
})
159159

160+
describe('exa_search untouched fields and Lite', () => {
161+
it('omits fields a block never filled in (null) instead of sending them', () => {
162+
const body = searchBody({
163+
text: null,
164+
highlights: null,
165+
summary: null,
166+
maxAgeHours: null,
167+
livecrawlTimeout: null,
168+
})
169+
expect(body).not.toHaveProperty('contents')
170+
})
171+
172+
it('sends only the parameters Lite accepts', () => {
173+
const body = searchBody({
174+
type: 'lite',
175+
numResults: 5,
176+
includeDomains: 'a.com',
177+
text: true,
178+
highlights: true,
179+
summary: true,
180+
summaryQuery: 'pricing',
181+
subpages: 2,
182+
subpageTarget: 'docs',
183+
extrasLinks: 3,
184+
maxAgeHours: 24,
185+
livecrawlTimeout: 5000,
186+
startCrawlDate: '2024-01-01',
187+
outputSchema: { type: 'object', properties: {} },
188+
systemPrompt: 'be brief',
189+
})
190+
expect(body).toEqual({
191+
query: 'q',
192+
type: 'lite',
193+
numResults: 5,
194+
includeDomains: ['a.com'],
195+
contents: { text: true, highlights: true },
196+
})
197+
})
198+
})
199+
160200
describe('exa block', () => {
201+
it('leaves Max Content Age unset when the field was never filled in', () => {
202+
const params = ExaBlock.tools.config?.params?.({
203+
operation: 'exa_search',
204+
maxAgeHours: null,
205+
}) as Record<string, unknown>
206+
expect(params).not.toHaveProperty('maxAgeHours')
207+
})
208+
161209
it('routes the retired research operation to the agent tool', () => {
162210
expect(ExaBlock.tools.config?.tool?.({ operation: 'exa_research' })).toBe('exa_agent')
163211
})

‎apps/sim/tools/exa/find_similar_links.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export const findSimilarLinksTool: ToolConfig<
152152
const contents: Record<string, any> = {}
153153
if (params.text !== undefined) contents.text = params.text
154154
if (params.highlights !== undefined) contents.highlights = params.highlights
155-
if (params.summary !== undefined) contents.summary = params.summary
155+
if (String(params.summary) === 'true') contents.summary = true
156156

157157
applyFreshness(contents, params)
158158

‎apps/sim/tools/exa/get_contents.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ export const getContentsTool: ToolConfig<ExaGetContentsParams, ExaGetContentsRes
147147

148148
if (params.summaryQuery) {
149149
body.summary = { query: params.summaryQuery }
150-
} else if (params.summary !== undefined) {
151-
body.summary = params.summary
150+
} else if (String(params.summary) === 'true') {
151+
body.summary = true
152152
}
153153

154154
if (params.subpages !== undefined) body.subpages = Number(params.subpages)

‎apps/sim/tools/exa/search.ts‎

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ import {
99
} from '@/tools/exa/utils'
1010
import type { ToolConfig } from '@/tools/types'
1111

12+
/** Content options every search type except Lite accepts: summaries, subpages, extras, and freshness. */
13+
function addNonLiteContents(contents: Record<string, unknown>, params: ExaSearchParams): void {
14+
if (params.summaryQuery) {
15+
contents.summary = { query: params.summaryQuery }
16+
} else if (String(params.summary) === 'true') {
17+
contents.summary = true
18+
}
19+
20+
if (params.subpages) contents.subpages = Number(params.subpages)
21+
const subpageTarget = parseCommaList(params.subpageTarget)
22+
if (subpageTarget) contents.subpageTarget = subpageTarget
23+
24+
const extras = buildExtras(params)
25+
if (extras) contents.extras = extras
26+
27+
applyFreshness(contents, params)
28+
}
29+
1230
export const searchTool: ToolConfig<ExaSearchParams, ExaSearchResponse> = {
1331
id: 'exa_search',
1432
name: 'Exa Search',
@@ -231,36 +249,30 @@ export const searchTool: ToolConfig<ExaSearchParams, ExaSearchResponse> = {
231249

232250
if (params.startPublishedDate) body.startPublishedDate = params.startPublishedDate
233251
if (params.endPublishedDate) body.endPublishedDate = params.endPublishedDate
234-
if (params.startCrawlDate) body.startCrawlDate = params.startCrawlDate
235-
if (params.endCrawlDate) body.endCrawlDate = params.endCrawlDate
236-
237-
const outputSchema = parseJsonSchema(params.outputSchema, 'outputSchema')
238-
if (outputSchema) body.outputSchema = outputSchema
239-
if (params.systemPrompt) body.systemPrompt = params.systemPrompt
240252

241253
/**
242254
* On `/search` the content options are nested under `contents` — unlike
243255
* `/contents`, where the same fields sit at the top level.
244256
*/
245257
const contents: Record<string, any> = {}
246258

247-
if (params.text !== undefined) contents.text = params.text
248-
if (params.highlights !== undefined) contents.highlights = params.highlights
259+
if (params.text != null) contents.text = params.text
260+
if (params.highlights != null) contents.highlights = params.highlights
249261

250-
if (params.summaryQuery) {
251-
contents.summary = { query: params.summaryQuery }
252-
} else if (params.summary !== undefined) {
253-
contents.summary = params.summary
254-
}
255-
256-
if (params.subpages) contents.subpages = Number(params.subpages)
257-
const subpageTarget = parseCommaList(params.subpageTarget)
258-
if (subpageTarget) contents.subpageTarget = subpageTarget
262+
/**
263+
* Lite rejects every parameter outside query, filters, and text/highlights contents,
264+
* so the options other search types accept are only added for them.
265+
*/
266+
if (params.type !== 'lite') {
267+
if (params.startCrawlDate) body.startCrawlDate = params.startCrawlDate
268+
if (params.endCrawlDate) body.endCrawlDate = params.endCrawlDate
259269

260-
const extras = buildExtras(params)
261-
if (extras) contents.extras = extras
270+
const outputSchema = parseJsonSchema(params.outputSchema, 'outputSchema')
271+
if (outputSchema) body.outputSchema = outputSchema
272+
if (params.systemPrompt) body.systemPrompt = params.systemPrompt
262273

263-
applyFreshness(contents, params)
274+
addNonLiteContents(contents, params)
275+
}
264276

265277
if (Object.keys(contents).length > 0) {
266278
body.contents = contents

‎apps/sim/tools/exa/utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function applyFreshness(target: Record<string, any>, params: ExaFreshness
5353
target.livecrawl = params.livecrawl
5454
}
5555

56-
if (params.livecrawlTimeout !== undefined && String(params.livecrawlTimeout).trim() !== '') {
56+
if (params.livecrawlTimeout != null && String(params.livecrawlTimeout).trim() !== '') {
5757
target.livecrawlTimeout = Number(params.livecrawlTimeout)
5858
}
5959
}

‎apps/sim/tools/jina/search.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@ describe('jina_search request', () => {
1818

1919
expect(mapped).toEqual({ returnFormat: 'html', retainImages: 'none' })
2020
})
21+
22+
it("drops Read URL's stored format and image values on Search", () => {
23+
const raw = { operation: 'jina_search', returnFormat: 'screenshot', retainImages: 'none' }
24+
const merged = { ...raw, ...JinaBlock.tools.config?.params?.(raw) }
25+
26+
expect(merged.returnFormat).toBeUndefined()
27+
expect(merged.retainImages).toBeUndefined()
28+
})
2129
})

0 commit comments

Comments
 (0)