Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/sim/tools/exa/exa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down Expand Up @@ -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/)
})
Expand Down
17 changes: 10 additions & 7 deletions apps/sim/tools/exa/utils.ts
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down
10 changes: 10 additions & 0 deletions apps/sim/tools/higgsfield/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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/)
})
})
14 changes: 12 additions & 2 deletions apps/sim/tools/higgsfield/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<string, string> {
/**
* 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<string, string> {
if (!accessToken) {
throw new UserFailure('Select a Higgsfield credential to run this tool')
}
return {
...higgsfieldAuthHeaders(accessToken),
...(hasBody ? { 'Content-Type': 'application/json' } : {}),
Expand Down
Loading