(
input: FirstPartyWebSearchInput,
options: {
signal?: AbortSignal
fetch?: typeof fetch
} = {},
)
| 35 | } |
| 36 | |
| 37 | export async function performFirstPartyWebSearch( |
| 38 | input: FirstPartyWebSearchInput, |
| 39 | options: { |
| 40 | signal?: AbortSignal |
| 41 | fetch?: typeof fetch |
| 42 | } = {}, |
| 43 | ): Promise<FirstPartyWebSearchResult> { |
| 44 | const baseURL = getNoumenaWebSearchBaseUrl() |
| 45 | if (!baseURL) { |
| 46 | throw new Error('Noumena web search requires a platform API base URL.') |
| 47 | } |
| 48 | |
| 49 | const headers = await getFirstPartyRequestHeaders({ |
| 50 | includeApiKeyHeader: true, |
| 51 | }) |
| 52 | const fetchImpl = |
| 53 | options.fetch ?? getWrappedClientFetch(undefined, 'web_search_tool') ?? fetch |
| 54 | const response = await fetchImpl(new URL('/v1/web_search', baseURL).toString(), { |
| 55 | method: 'POST', |
| 56 | headers: { |
| 57 | 'content-type': 'application/json', |
| 58 | ...headers, |
| 59 | }, |
| 60 | body: JSON.stringify(input), |
| 61 | signal: options.signal, |
| 62 | }) |
| 63 | |
| 64 | if (!response.ok) { |
| 65 | const body = await parseErrorBody(response) |
| 66 | throw new Error( |
| 67 | `Noumena web search failed with ${response.status}${body ? `: ${body}` : ''}`, |
| 68 | ) |
| 69 | } |
| 70 | |
| 71 | return (await response.json()) as FirstPartyWebSearchResult |
| 72 | } |
no test coverage detected