mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-08-29 04:26:38 +00:00
68 lines
2.4 KiB
TypeScript
68 lines
2.4 KiB
TypeScript
/**
|
|
* Exa-backed `WebSearchProvider` plugin. It contributes to the `ctx.web`
|
|
* registry without owning the service.
|
|
*
|
|
* @module @deepseek-ai/dsh-web-search-exa
|
|
*/
|
|
|
|
import type { Context } from '@deepseek-ai/cordis'
|
|
import { launchEnvironmentOf } from '@deepseek-ai/dsh-launch-environment'
|
|
import z from '@deepseek-ai/schemastery'
|
|
import type {} from '@deepseek-ai/dsh-web'
|
|
import {
|
|
ExaSearchProvider,
|
|
EXA_DEFAULT_BASE_URL,
|
|
EXA_DEFAULT_HIGHLIGHTS_PER_RESULT,
|
|
EXA_DEFAULT_SEARCH_TYPE,
|
|
} from './provider.ts'
|
|
|
|
export {
|
|
EXA_DEFAULT_BASE_URL,
|
|
EXA_DEFAULT_HIGHLIGHTS_PER_RESULT,
|
|
EXA_DEFAULT_SEARCH_TYPE,
|
|
EXA_PROVIDER_ID,
|
|
ExaSearchProvider,
|
|
} from './provider.ts'
|
|
export type { ExaSearchProviderOptions } from './provider.ts'
|
|
|
|
/** Cordis plugin name used by loader diagnostics. */
|
|
export const name = 'web-search-exa'
|
|
|
|
/** The web seam this provider registers into. */
|
|
export const inject = ['web']
|
|
|
|
/** Plugin config (all optional — `apply` fills env-var and constant defaults). */
|
|
export interface Config {
|
|
/** Exa API key. Falls back to `$EXA_API_KEY`. Empty → provider unavailable. */
|
|
apiKey?: string
|
|
/** Endpoint base; `/search` is appended. Defaults to the public API. */
|
|
baseURL?: string
|
|
/** Retrieval mode sent as Exa's `type`. Defaults to `auto`. */
|
|
searchType?: 'auto' | 'keyword' | 'neural'
|
|
/** Default result count when a request carries no `maxResults`. Omitted = none. */
|
|
numResults?: number
|
|
/** Highlight sentences requested per result. Defaults to 1. */
|
|
highlightsPerResult?: number
|
|
}
|
|
|
|
export const Config: z<Config> = z.object({
|
|
apiKey: z.string(),
|
|
baseURL: z.string(),
|
|
searchType: z.union(['auto', 'keyword', 'neural'] as const),
|
|
numResults: z.number().step(1).min(1),
|
|
highlightsPerResult: z.number().step(1).min(1),
|
|
})
|
|
|
|
/** Register the Exa search provider with `ctx.web`. */
|
|
export function apply(ctx: Context, config: Config): void {
|
|
ctx.web.registerSearchProvider(new ExaSearchProvider({
|
|
// Every environment layer may name this key: the product trusts the
|
|
// project it is launched in, and the managed store is not involved here.
|
|
apiKey: config.apiKey ?? launchEnvironmentOf(ctx).get('EXA_API_KEY')?.value ?? '',
|
|
baseURL: config.baseURL ?? EXA_DEFAULT_BASE_URL,
|
|
searchType: config.searchType ?? EXA_DEFAULT_SEARCH_TYPE,
|
|
highlightsPerResult: config.highlightsPerResult ?? EXA_DEFAULT_HIGHLIGHTS_PER_RESULT,
|
|
...config.numResults !== undefined ? { numResults: config.numResults } : {},
|
|
}))
|
|
}
|