From 04561b03ecda4ef60c43c28ec0207b40edbd5007 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Wed, 18 Nov 2026 18:17:50 -0800 Subject: [PATCH 1/2] fix(integrations): stop the higgsfield and exa tools crashing on missing credentials and array inputs --- apps/sim/tools/exa/exa.test.ts | 12 ++++++++++++ apps/sim/tools/exa/utils.ts | 17 ++++++++++------- apps/sim/tools/higgsfield/utils.test.ts | 11 +++++++++++ apps/sim/tools/higgsfield/utils.ts | 14 ++++++++++++-- 4 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 apps/sim/tools/higgsfield/utils.test.ts diff --git a/apps/sim/tools/exa/exa.test.ts b/apps/sim/tools/exa/exa.test.ts index a7baba1ccb8..e7addceb437 100644 --- a/apps/sim/tools/exa/exa.test.ts +++ b/apps/sim/tools/exa/exa.test.ts @@ -107,6 +107,12 @@ describe('exa_search request body', () => { expect(body.includeDomains).toEqual(['a.com', 'b.com', 'c.com']) }) + it('accepts domain filters an agent passes as an array', () => { + const body = searchBody({ includeDomains: ['a.com', ' b.com ', ''], excludeDomains: [] }) + expect(body.includeDomains).toEqual(['a.com', 'b.com']) + expect(body).not.toHaveProperty('excludeDomains') + }) + it('parses a stringified outputSchema from the JSON editor', () => { const body = searchBody({ outputSchema: '{"type":"object"}' }) expect(body.outputSchema).toEqual({ type: 'object' }) @@ -138,6 +144,12 @@ describe('exa_get_contents request body', () => { expect(result.urls).toBeUndefined() }) + it('accepts urls and subpage targets an agent passes as arrays', () => { + const result = body({ urls: ['https://a.com', ' https://b.com '], subpageTarget: ['docs'] }) + expect(result.urls).toEqual(['https://a.com', 'https://b.com']) + expect(result.subpageTarget).toEqual(['docs']) + }) + it('rejects both selectors, which Exa 400s on', () => { expect(() => body({ urls: 'https://a.com', ids: 'id-1' })).toThrow(/not both/) }) diff --git a/apps/sim/tools/exa/utils.ts b/apps/sim/tools/exa/utils.ts index f22374d0195..b8f947440e7 100644 --- a/apps/sim/tools/exa/utils.ts +++ b/apps/sim/tools/exa/utils.ts @@ -1,12 +1,15 @@ +import { toStringOrNull } from '@sim/utils/coerce' import type { ExaFreshnessParams } from '@/tools/exa/types' -/** Splits a comma-separated user string into a trimmed, non-empty list. */ -export function parseCommaList(value: string | undefined): string[] | undefined { - if (!value) return undefined - const items = value - .split(',') - .map((item) => item.trim()) - .filter((item) => item.length > 0) +/** + * Reads a list param as a trimmed, non-empty list. Block inputs send a comma-separated + * string; agent tool calls often send an array instead. Anything else reads as unset. + */ +export function parseCommaList(value: unknown): string[] | undefined { + const parts = Array.isArray(value) ? value : typeof value === 'string' ? value.split(',') : [] + const items = parts + .map((item) => toStringOrNull(item)?.trim()) + .filter((item): item is string => Boolean(item)) return items.length > 0 ? items : undefined } diff --git a/apps/sim/tools/higgsfield/utils.test.ts b/apps/sim/tools/higgsfield/utils.test.ts new file mode 100644 index 00000000000..77835532d57 --- /dev/null +++ b/apps/sim/tools/higgsfield/utils.test.ts @@ -0,0 +1,11 @@ +import { describe, expect, it } from 'vitest' +import { UserFailure } from '@/lib/core/errors/user-failure' +import { higgsfieldGenerateTool } from '@/tools/higgsfield/generate' + +describe('higgsfield_generate request', () => { + it('asks for a credential instead of crashing when none was resolved', () => { + const params = { model: 'higgsfield-ai/soul/standard', input: '{}' } as never + expect(() => higgsfieldGenerateTool.request.url(params)).toThrow(UserFailure) + expect(() => higgsfieldGenerateTool.request.url(params)).toThrow(/Higgsfield credential/) + }) +}) diff --git a/apps/sim/tools/higgsfield/utils.ts b/apps/sim/tools/higgsfield/utils.ts index 41604845868..29d7eb91d00 100644 --- a/apps/sim/tools/higgsfield/utils.ts +++ b/apps/sim/tools/higgsfield/utils.ts @@ -2,6 +2,7 @@ import { createLogger } from '@sim/logger' import { getErrorMessage } from '@sim/utils/errors' import { sleep } from '@sim/utils/helpers' import { toArray, toRecord } from '@sim/utils/object' +import { UserFailure } from '@/lib/core/errors/user-failure' import { DEFAULT_EXECUTION_TIMEOUT_MS } from '@/lib/core/execution-limits' import { HIGGSFIELD_API_BASE, @@ -85,8 +86,17 @@ export function buildHiggsfieldUrl( return url.toString() } -/** Auth headers, plus a JSON content type for requests that send a body. */ -export function higgsfieldHeaders(accessToken: string, hasBody = false): Record { +/** + * Auth headers, plus a JSON content type for requests that send a body. An Agent tool + * with no credential selected reaches here with no key. + */ +export function higgsfieldHeaders( + accessToken: string | undefined, + hasBody = false +): Record { + if (!accessToken) { + throw new UserFailure('Select a Higgsfield credential to run this tool') + } return { ...higgsfieldAuthHeaders(accessToken), ...(hasBody ? { 'Content-Type': 'application/json' } : {}), From 5169c7ea6e76107c2bd4c819b78ab60baef2d5c7 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Wed, 18 Nov 2026 18:29:36 -0800 Subject: [PATCH 2/2] fix(integrations): type-safe higgsfield credential regression test --- apps/sim/tools/higgsfield/utils.test.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/sim/tools/higgsfield/utils.test.ts b/apps/sim/tools/higgsfield/utils.test.ts index 77835532d57..c8b2fe79fab 100644 --- a/apps/sim/tools/higgsfield/utils.test.ts +++ b/apps/sim/tools/higgsfield/utils.test.ts @@ -1,11 +1,10 @@ import { describe, expect, it } from 'vitest' import { UserFailure } from '@/lib/core/errors/user-failure' -import { higgsfieldGenerateTool } from '@/tools/higgsfield/generate' +import { higgsfieldHeaders } from '@/tools/higgsfield/utils' -describe('higgsfield_generate request', () => { +describe('higgsfieldHeaders', () => { it('asks for a credential instead of crashing when none was resolved', () => { - const params = { model: 'higgsfield-ai/soul/standard', input: '{}' } as never - expect(() => higgsfieldGenerateTool.request.url(params)).toThrow(UserFailure) - expect(() => higgsfieldGenerateTool.request.url(params)).toThrow(/Higgsfield credential/) + expect(() => higgsfieldHeaders(undefined, true)).toThrow(UserFailure) + expect(() => higgsfieldHeaders(undefined, true)).toThrow(/Higgsfield credential/) }) })