@deepseek-ai/dsh-web 0.2.2-rc.1 → 0.2.2-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +18 -12
- package/README.md +38 -7
- package/README.zh.md +38 -7
- package/lib/index.js +220 -112
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +178 -0
- package/lib/typert.remote-client.d.ts +25 -0
- package/lib/typert.remote-client.d.ts.map +1 -0
- package/lib/typert.remote-client.js +45 -0
- package/lib/types/index.d.ts +24 -11
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +277 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/types.d.ts +57 -7
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js +18 -0
- package/lib/types/types.js.map +1 -0
- package/package.json +28 -5
- package/src/index.ts +305 -0
- package/src/types.ts +202 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vocabulary for the web capability seam (`ctx.web`). Search and fetch deliberately share one
|
|
3
|
+
* seam so provider selection, cancellation, errors, and product configuration have one owner,
|
|
4
|
+
* while retaining separate request and result types.
|
|
5
|
+
* @module @deepseek-ai/dsh-web/types
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { HarnessError } from '@deepseek-ai/dsh-llm'
|
|
9
|
+
import type { LocalizedText } from '@deepseek-ai/dsh-package-manifest'
|
|
10
|
+
|
|
11
|
+
declare module '@deepseek-ai/cordis' {
|
|
12
|
+
interface Events {
|
|
13
|
+
/**
|
|
14
|
+
* The set of registered search or fetch providers changed: one provider
|
|
15
|
+
* registered, or its registration was disposed. Payload-free; consumers
|
|
16
|
+
* re-read `ctx.web.listProviders()` (Remote `web/listProviders`) for the
|
|
17
|
+
* new list. Fires after each committed registry mutation. Observer failures
|
|
18
|
+
* are contained and cannot veto the mutation.
|
|
19
|
+
* @mode emit
|
|
20
|
+
*/
|
|
21
|
+
'web/providers-changed'(): void
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* What one search-capable backend is asked to search. Each request carries one
|
|
27
|
+
* query; a consumer may issue several requests. `maxResults` is a
|
|
28
|
+
* `dsh-tool-web`-layer bound passed through unchanged and enforced on the way
|
|
29
|
+
* back by the seam (see {@link WebSearchResult}).
|
|
30
|
+
*/
|
|
31
|
+
export interface WebSearchRequest {
|
|
32
|
+
readonly query: string
|
|
33
|
+
/**
|
|
34
|
+
* Upper bound on returned sources; the seam truncates to it. Omitted = no
|
|
35
|
+
* bound. `dsh-tool-web` always sets it. A provider whose API supports a
|
|
36
|
+
* result-count control (the DeepSeek Search API's `count`) should apply it
|
|
37
|
+
* at the request layer as a cost/latency optimization; the seam enforces the
|
|
38
|
+
* bound regardless.
|
|
39
|
+
*/
|
|
40
|
+
readonly maxResults?: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Normalized search outcome. `content` is optional provider-generated answer
|
|
45
|
+
* text or summary (DeepSeek returns none; a provider whose API generates an
|
|
46
|
+
* answer returns it here).
|
|
47
|
+
* `sources[]` is the portable citation shape. `truncated` is set by the seam
|
|
48
|
+
* when it cut `sources[]` down to `maxResults`.
|
|
49
|
+
*/
|
|
50
|
+
export interface WebSearchResult {
|
|
51
|
+
/** Optional provider-generated answer text, search context, or summary. */
|
|
52
|
+
readonly content?: string
|
|
53
|
+
/** Citeable sources, already truncated to the request's `maxResults`. */
|
|
54
|
+
readonly sources: readonly WebSearchSource[]
|
|
55
|
+
/** True when the seam dropped sources to honor `maxResults`. */
|
|
56
|
+
readonly truncated: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* One citeable source. A source always has a URL; `title`, `snippet`, `summary`,
|
|
61
|
+
* and `publishedAt` are optional because not every provider returns them — forcing
|
|
62
|
+
* adapters to invent them would make the seam lie (some providers return
|
|
63
|
+
* URL-only citations). `dsh-tool-web` renders `title ?? hostname(url)` for display.
|
|
64
|
+
*/
|
|
65
|
+
export interface WebSearchSource {
|
|
66
|
+
readonly url: string
|
|
67
|
+
readonly title?: string
|
|
68
|
+
/** Short excerpt suited to display. */
|
|
69
|
+
readonly snippet?: string
|
|
70
|
+
/** Longer excerpt suited to model reading; consumers bound its length. */
|
|
71
|
+
readonly summary?: string
|
|
72
|
+
/** Publication/crawl timestamp as a provider-supplied ISO-8601 string. */
|
|
73
|
+
readonly publishedAt?: string
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* What one fetch-capable backend is asked to retrieve. The request deliberately
|
|
78
|
+
* omits timeout, format, prompt, and extraction controls: cancellation is a
|
|
79
|
+
* direct execution argument, while presentation and higher-level LLM concerns
|
|
80
|
+
* belong outside safe retrieval.
|
|
81
|
+
*/
|
|
82
|
+
export interface WebFetchRequest {
|
|
83
|
+
readonly url: string
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Normalized fetch outcome. A successful network fetch of a non-2xx response is
|
|
88
|
+
* a result, not an error: the status code is part of the fetched resource
|
|
89
|
+
* state. {@link WebError} is reserved for failures to safely retrieve or
|
|
90
|
+
* represent the resource.
|
|
91
|
+
*/
|
|
92
|
+
export interface WebFetchResult {
|
|
93
|
+
/** The final URL after allowed redirects (the request URL is in the request). */
|
|
94
|
+
readonly url: string
|
|
95
|
+
/** HTTP status code of the fetched response. */
|
|
96
|
+
readonly statusCode: number
|
|
97
|
+
/** Decoded body, classified by content kind. */
|
|
98
|
+
readonly body: WebFetchBody
|
|
99
|
+
/** True when the provider capped the decoded body. */
|
|
100
|
+
readonly truncated: boolean
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The decoded body of a fetched resource. A CLOSED discriminated union owned by
|
|
105
|
+
* `dsh-web`: the provider decodes the kind and `dsh-tool-web` renders it, so a
|
|
106
|
+
* new kind is a coordinated change across known packages, not a plugin
|
|
107
|
+
* extension. Consumers `switch` on `kind` ending in `default: assertNever(...)`
|
|
108
|
+
* so adding a kind breaks compilation at every consumer until handled. Each arm
|
|
109
|
+
* stays its own object literal even where fields coincide, so an arm can gain
|
|
110
|
+
* fields the others lack.
|
|
111
|
+
*/
|
|
112
|
+
export type WebFetchBody =
|
|
113
|
+
| { readonly kind: 'html'; readonly content: string }
|
|
114
|
+
| { readonly kind: 'text'; readonly content: string }
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A search-capable backend. Registered with `ctx.web.registerSearchProvider`.
|
|
118
|
+
* `id` is a stable string, unique within the search capability kind.
|
|
119
|
+
*/
|
|
120
|
+
export interface WebSearchProvider {
|
|
121
|
+
readonly id: string
|
|
122
|
+
/** Display name of this provider; consumers display `id` when it is omitted. */
|
|
123
|
+
readonly title?: string
|
|
124
|
+
/**
|
|
125
|
+
* What a provider picker shows under this provider when it is selected: what the provider
|
|
126
|
+
* is suited for and what it costs or cannot do. Translations are keyed by lowercase language
|
|
127
|
+
* id with a required English entry; consumers show nothing when it is omitted.
|
|
128
|
+
*/
|
|
129
|
+
readonly description?: LocalizedText
|
|
130
|
+
/** Cheap local usability check; must not make network calls. */
|
|
131
|
+
available(): boolean
|
|
132
|
+
/**
|
|
133
|
+
* Whether a search made for a model request on the `llmProvider` chat route has a
|
|
134
|
+
* credential to send. Checks configuration only and must not make network calls.
|
|
135
|
+
* Omitted = ready.
|
|
136
|
+
* @param llmProvider - the provider route id of the model request, when known.
|
|
137
|
+
* @returns false when that request's searches could not authenticate.
|
|
138
|
+
*/
|
|
139
|
+
ready?(llmProvider: string | undefined): Promise<boolean>
|
|
140
|
+
/** Run one search; honor `signal` for cancellation. */
|
|
141
|
+
search(request: WebSearchRequest, signal?: AbortSignal): Promise<WebSearchResult>
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* A fetch-capable backend. Registered with `ctx.web.registerFetchProvider`.
|
|
146
|
+
* `id` is a stable string, unique within the fetch capability kind.
|
|
147
|
+
*/
|
|
148
|
+
export interface WebFetchProvider {
|
|
149
|
+
readonly id: string
|
|
150
|
+
/** Display name of this provider; consumers display `id` when it is omitted. */
|
|
151
|
+
readonly title?: string
|
|
152
|
+
/**
|
|
153
|
+
* What a provider picker shows under this provider when it is selected: what the provider
|
|
154
|
+
* is suited for and what it costs or cannot do. Translations are keyed by lowercase language
|
|
155
|
+
* id with a required English entry; consumers show nothing when it is omitted.
|
|
156
|
+
*/
|
|
157
|
+
readonly description?: LocalizedText
|
|
158
|
+
/** Cheap local usability check; must not make network calls. */
|
|
159
|
+
available(): boolean
|
|
160
|
+
/**
|
|
161
|
+
* Whether a fetch made for a model request on the `llmProvider` chat route has a
|
|
162
|
+
* credential to send. Checks configuration only and must not make network calls.
|
|
163
|
+
* Omitted = ready.
|
|
164
|
+
* @param llmProvider - the provider route id of the model request, when known.
|
|
165
|
+
* @returns false when that request's fetches could not authenticate.
|
|
166
|
+
*/
|
|
167
|
+
ready?(llmProvider: string | undefined): Promise<boolean>
|
|
168
|
+
/** Retrieve one URL; honor `signal` for cancellation. */
|
|
169
|
+
fetch(request: WebFetchRequest, signal?: AbortSignal): Promise<WebFetchResult>
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** One registered provider as listed by {@link WebProviderList}. */
|
|
173
|
+
export interface WebProviderInfo {
|
|
174
|
+
/** The provider's registry id, the value `searchProvider` / `fetchProvider` select. */
|
|
175
|
+
readonly id: string
|
|
176
|
+
/** The provider's display name; absent when the provider declares none. */
|
|
177
|
+
readonly title?: string
|
|
178
|
+
/** The provider's picker description; absent when the provider declares none. */
|
|
179
|
+
readonly description?: LocalizedText
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Every currently registered search and fetch provider, each list in
|
|
184
|
+
* registration order. Availability does not filter the lists: a registered
|
|
185
|
+
* provider whose `available()` answers false is still listed.
|
|
186
|
+
*/
|
|
187
|
+
export interface WebProviderList {
|
|
188
|
+
/** Registered search providers. */
|
|
189
|
+
readonly search: readonly WebProviderInfo[]
|
|
190
|
+
/** Registered fetch providers. */
|
|
191
|
+
readonly fetch: readonly WebProviderInfo[]
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Typed web error with a machine-routable, open-string `code` and chained `cause`.
|
|
196
|
+
* Consumers must tolerate provider-specific codes. Shared codes cover unavailable,
|
|
197
|
+
* missing, unusable, ambiguous, or duplicate providers, cancellation, and provider failure;
|
|
198
|
+
* the local fetch provider additionally distinguishes invalid or blocked URLs, redirects,
|
|
199
|
+
* size and timeout limits, and unsupported content types. Tool execution exposes the code in
|
|
200
|
+
* structured error metadata.
|
|
201
|
+
*/
|
|
202
|
+
export class WebError extends HarnessError {}
|