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..c8b2fe79fab --- /dev/null +++ b/apps/sim/tools/higgsfield/utils.test.ts @@ -0,0 +1,10 @@ +import { describe, expect, it } from 'vitest' +import { UserFailure } from '@/lib/core/errors/user-failure' +import { higgsfieldHeaders } from '@/tools/higgsfield/utils' + +describe('higgsfieldHeaders', () => { + it('asks for a credential instead of crashing when none was resolved', () => { + expect(() => higgsfieldHeaders(undefined, true)).toThrow(UserFailure) + expect(() => higgsfieldHeaders(undefined, true)).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' } : {}),