MCPcopy Create free account
hub / github.com/Noumena-Network/code / performFirstPartyWebSearch

Function performFirstPartyWebSearch

src/services/api/webSearch.ts:37–72  ·  view source on GitHub ↗
(
  input: FirstPartyWebSearchInput,
  options: {
    signal?: AbortSignal
    fetch?: typeof fetch
  } = {},
)

Source from the content-addressed store, hash-verified

35}
36
37export 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}

Callers 1

Calls 5

getWrappedClientFetchFunction · 0.85
parseErrorBodyFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected