{"version":3,"file":"exa.mjs","names":[],"sources":["../../src/providers/exa.ts"],"sourcesContent":["import type { SearchResult, SearchRequestOptions, ProviderConfig } from \"../core/types.ts\";\nimport { Provider } from \"../core/provider.ts\";\nimport { AuthError, normalizeError } from \"../core/errors.ts\";\n\ninterface ExaSearchRequest {\n  readonly query: string;\n  readonly type?: string;\n  readonly numResults?: number;\n  readonly category?: string;\n  readonly includeDomains?: readonly string[];\n  readonly excludeDomains?: readonly string[];\n  readonly startPublishedDate?: string;\n  readonly endPublishedDate?: string;\n  readonly contents?: { text: boolean; highlights: boolean; summary?: true };\n}\n\ninterface ExaResult {\n  readonly id: string;\n  readonly url: string;\n  readonly title: string | null;\n  readonly score?: number;\n  readonly publishedDate?: string;\n  readonly author?: string;\n  readonly image?: string;\n  readonly favicon?: string;\n  readonly text?: string;\n  readonly highlights?: readonly string[];\n  readonly highlightScores?: readonly number[];\n  readonly summary?: string;\n}\n\ninterface ExaSearchResponse {\n  readonly requestId: string;\n  readonly results: readonly ExaResult[];\n}\n\nexport class ExaProvider extends Provider {\n  static readonly providerName = \"exa\";\n  static readonly defaultBaseURL = \"https://api.exa.ai\";\n\n  private readonly apiKey: string;\n\n  constructor(config: Readonly<ProviderConfig>) {\n    super(config, ExaProvider);\n    if (!config.apiKey) {\n      throw new AuthError(\"Missing API key for Exa. Set EXA_API_KEY\", \"exa\");\n    }\n\n    this.apiKey = config.apiKey;\n  }\n\n  async search(query: string, options?: SearchRequestOptions): Promise<SearchResult[]> {\n    const searchOptions = options ?? {};\n    const body = {\n      query,\n      type: \"auto\",\n      numResults: searchOptions.maxResults,\n      category: searchOptions.category,\n      includeDomains: searchOptions.includeDomains,\n      excludeDomains: searchOptions.excludeDomains,\n      startPublishedDate: searchOptions.startPublishedDate,\n      endPublishedDate: searchOptions.endPublishedDate,\n      contents: {\n        text: searchOptions.fullText ?? false,\n        highlights: includeHighlights(searchOptions),\n        ...(searchOptions.summary ? { summary: true } : {}),\n      },\n    } satisfies ExaSearchRequest;\n\n    try {\n      const url = `${this.baseURL}/search`;\n      const headers = { \"x-api-key\": this.apiKey };\n      const response = await this.client.postJSON<ExaSearchResponse>(\n        url,\n        body,\n        headers,\n        searchOptions.signal,\n      );\n      return response.results.map(mapResult);\n    } catch (error) {\n      throw normalizeError(error, \"exa\");\n    }\n  }\n}\n\nfunction includeHighlights(options?: SearchRequestOptions): boolean {\n  return options?.highlights ?? true;\n}\n\nfunction mapResult(result: ExaResult): SearchResult {\n  return {\n    url: result.url,\n    title: result.title ?? \"\",\n    snippet: result.highlights?.[0] ?? (result.text ? result.text.slice(0, 200) : \"\"),\n    score: result.score,\n    publishedDate: result.publishedDate,\n    author: result.author,\n    image: result.image,\n    favicon: result.favicon,\n    text: result.text,\n    highlights: result.highlights ? [...result.highlights] : undefined,\n    summary: result.summary,\n  };\n}\n"],"mappings":";;;AAoCA,IAAa,cAAb,MAAa,oBAAoB,SAAS;CACxC,OAAgB,eAAe;CAC/B,OAAgB,iBAAiB;CAEjC;CAEA,YAAY,QAAkC;EAC5C,MAAM,QAAQ,WAAW;EACzB,IAAI,CAAC,OAAO,QACV,MAAM,IAAI,UAAU,4CAA4C,KAAK;EAGvE,KAAK,SAAS,OAAO;CACvB;CAEA,MAAM,OAAO,OAAe,SAAyD;EACnF,MAAM,gBAAgB,WAAW,CAAC;EAClC,MAAM,OAAO;GACX;GACA,MAAM;GACN,YAAY,cAAc;GAC1B,UAAU,cAAc;GACxB,gBAAgB,cAAc;GAC9B,gBAAgB,cAAc;GAC9B,oBAAoB,cAAc;GAClC,kBAAkB,cAAc;GAChC,UAAU;IACR,MAAM,cAAc,YAAY;IAChC,YAAY,kBAAkB,aAAa;IAC3C,GAAI,cAAc,UAAU,EAAE,SAAS,KAAK,IAAI,CAAC;GACnD;EACF;EAEA,IAAI;GACF,MAAM,MAAM,GAAG,KAAK,QAAQ;GAC5B,MAAM,UAAU,EAAE,aAAa,KAAK,OAAO;GAO3C,QAAO,MANgB,KAAK,OAAO,SACjC,KACA,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