forked from deepseek-ai/deepseek-harness
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
70 lines (63 loc) · 2.71 KB
/
Copy pathindex.ts
File metadata and controls
70 lines (63 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* `@deepseek-ai/dsh-web-search-exa`: registers an Exa-backed `WebSearchProvider`
* with `ctx.web`. A function/namespace plugin (NOT a default-export service):
* a search provider does not own the `ctx.web` key — it registers INTO the
* seam's provider registry, exactly as `@deepseek-ai/dsh-llm-deepseek`
* registers an adapter into `ctx.llm`. The key is owned by `@deepseek-ai/dsh-web`.
*
* @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 } : {},
}))
}