Skip to content

Commit 911d599

Browse files
authored
fix(integrations): stop the higgsfield and exa tools crashing on missing credentials and array inputs (#10198)
* fix(integrations): stop the higgsfield and exa tools crashing on missing credentials and array inputs * fix(integrations): type-safe higgsfield credential regression test
1 parent ad8ff86 commit 911d599

4 files changed

Lines changed: 44 additions & 9 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ describe('exa_search request body', () => {
107107
expect(body.includeDomains).toEqual(['a.com', 'b.com', 'c.com'])
108108
})
109109

110+
it('accepts domain filters an agent passes as an array', () => {
111+
const body = searchBody({ includeDomains: ['a.com', ' b.com ', ''], excludeDomains: [] })
112+
expect(body.includeDomains).toEqual(['a.com', 'b.com'])
113+
expect(body).not.toHaveProperty('excludeDomains')
114+
})
115+
110116
it('parses a stringified outputSchema from the JSON editor', () => {
111117
const body = searchBody({ outputSchema: '{"type":"object"}' })
112118
expect(body.outputSchema).toEqual({ type: 'object' })
@@ -138,6 +144,12 @@ describe('exa_get_contents request body', () => {
138144
expect(result.urls).toBeUndefined()
139145
})
140146

147+
it('accepts urls and subpage targets an agent passes as arrays', () => {
148+
const result = body({ urls: ['https://a.com', ' https://b.com '], subpageTarget: ['docs'] })
149+
expect(result.urls).toEqual(['https://a.com', 'https://b.com'])
150+
expect(result.subpageTarget).toEqual(['docs'])
151+
})
152+
141153
it('rejects both selectors, which Exa 400s on', () => {
142154
expect(() => body({ urls: 'https://a.com', ids: 'id-1' })).toThrow(/not both/)
143155
})

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import { toStringOrNull } from '@sim/utils/coerce'
12
import type { ExaFreshnessParams } from '@/tools/exa/types'
23

3-
/** Splits a comma-separated user string into a trimmed, non-empty list. */
4-
export function parseCommaList(value: string | undefined): string[] | undefined {
5-
if (!value) return undefined
6-
const items = value
7-
.split(',')
8-
.map((item) => item.trim())
9-
.filter((item) => item.length > 0)
4+
/**
5+
* Reads a list param as a trimmed, non-empty list. Block inputs send a comma-separated
6+
* string; agent tool calls often send an array instead. Anything else reads as unset.
7+
*/
8+
export function parseCommaList(value: unknown): string[] | undefined {
9+
const parts = Array.isArray(value) ? value : typeof value === 'string' ? value.split(',') : []
10+
const items = parts
11+
.map((item) => toStringOrNull(item)?.trim())
12+
.filter((item): item is string => Boolean(item))
1013
return items.length > 0 ? items : undefined
1114
}
1215

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { UserFailure } from '@/lib/core/errors/user-failure'
3+
import { higgsfieldHeaders } from '@/tools/higgsfield/utils'
4+
5+
describe('higgsfieldHeaders', () => {
6+
it('asks for a credential instead of crashing when none was resolved', () => {
7+
expect(() => higgsfieldHeaders(undefined, true)).toThrow(UserFailure)
8+
expect(() => higgsfieldHeaders(undefined, true)).toThrow(/Higgsfield credential/)
9+
})
10+
})

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createLogger } from '@sim/logger'
22
import { getErrorMessage } from '@sim/utils/errors'
33
import { sleep } from '@sim/utils/helpers'
44
import { toArray, toRecord } from '@sim/utils/object'
5+
import { UserFailure } from '@/lib/core/errors/user-failure'
56
import { DEFAULT_EXECUTION_TIMEOUT_MS } from '@/lib/core/execution-limits'
67
import {
78
HIGGSFIELD_API_BASE,
@@ -85,8 +86,17 @@ export function buildHiggsfieldUrl(
8586
return url.toString()
8687
}
8788

88-
/** Auth headers, plus a JSON content type for requests that send a body. */
89-
export function higgsfieldHeaders(accessToken: string, hasBody = false): Record<string, string> {
89+
/**
90+
* Auth headers, plus a JSON content type for requests that send a body. An Agent tool
91+
* with no credential selected reaches here with no key.
92+
*/
93+
export function higgsfieldHeaders(
94+
accessToken: string | undefined,
95+
hasBody = false
96+
): Record<string, string> {
97+
if (!accessToken) {
98+
throw new UserFailure('Select a Higgsfield credential to run this tool')
99+
}
90100
return {
91101
...higgsfieldAuthHeaders(accessToken),
92102
...(hasBody ? { 'Content-Type': 'application/json' } : {}),

0 commit comments

Comments
 (0)