@morlay/ui-conversation-manager 0.0.2-alpha.0
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/LICENSE +21 -0
- package/README.md +97 -0
- package/dist/client.cjs +1257 -0
- package/dist/client.d.cts +3125 -0
- package/dist/client.d.mts +3125 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +5 -0
- package/package.json +70 -0
- package/src/client/ConversationManagerIcon.tsx +9 -0
- package/src/client/ConversationManagerPage.styles.ts +247 -0
- package/src/client/ConversationManagerPage.tsx +801 -0
- package/src/client/controller.ts +216 -0
- package/src/client/format.ts +22 -0
- package/src/client/index.ts +76 -0
- package/src/client/locales.ts +152 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,3125 @@
|
|
|
1
|
+
import "react";
|
|
2
|
+
import { Context, Service } from "@deepseek-ai/cordis";
|
|
3
|
+
import { MainPanelId } from "@deepseek-ai/dsh-client-ui-layout/client";
|
|
4
|
+
import { InjectFace, PropsLocale, PropsRuntime } from "@deepseek-ai/dsh-client-ui-slots";
|
|
5
|
+
//#region src/client/locales.d.ts
|
|
6
|
+
/** 「对话管理」页面的文案字典。 */
|
|
7
|
+
/** 简体中文是 key 真源。 */
|
|
8
|
+
declare const zh: {
|
|
9
|
+
panel: string;
|
|
10
|
+
title: string;
|
|
11
|
+
search: string;
|
|
12
|
+
loading: string;
|
|
13
|
+
empty: string;
|
|
14
|
+
emptySearch: string;
|
|
15
|
+
archived: string;
|
|
16
|
+
subagent: string;
|
|
17
|
+
showSubagents: string;
|
|
18
|
+
"view.sessions": string;
|
|
19
|
+
"view.usage": string;
|
|
20
|
+
"usage.overview": string;
|
|
21
|
+
"usage.all": string;
|
|
22
|
+
"usage.range": string;
|
|
23
|
+
"usage.range.all": string;
|
|
24
|
+
"usage.range.day": string;
|
|
25
|
+
"usage.range.week": string;
|
|
26
|
+
"usage.range.days": string;
|
|
27
|
+
"usage.models": string;
|
|
28
|
+
"usage.sessions": string;
|
|
29
|
+
"usage.loading": string;
|
|
30
|
+
"usage.empty": string;
|
|
31
|
+
"usage.input": string;
|
|
32
|
+
"usage.inputWithCache": string;
|
|
33
|
+
"usage.output": string;
|
|
34
|
+
"usage.cacheInput": string;
|
|
35
|
+
"usage.cacheRate": string;
|
|
36
|
+
"usage.reasoning": string;
|
|
37
|
+
"usage.total": string;
|
|
38
|
+
"usage.events": string;
|
|
39
|
+
"usage.subagentOnly": string;
|
|
40
|
+
"usage.unknownModel": string;
|
|
41
|
+
archive: string;
|
|
42
|
+
archiveNamed: string;
|
|
43
|
+
unarchive: string;
|
|
44
|
+
unarchiveNamed: string;
|
|
45
|
+
remove: string;
|
|
46
|
+
removeNamed: string;
|
|
47
|
+
export: string;
|
|
48
|
+
exportNamed: string;
|
|
49
|
+
ungrouped: string;
|
|
50
|
+
"page.previous": string;
|
|
51
|
+
"page.next": string;
|
|
52
|
+
"page.label": string;
|
|
53
|
+
"gc.button": string;
|
|
54
|
+
"gc.title": string;
|
|
55
|
+
"gc.description": string;
|
|
56
|
+
"gc.confirm": string;
|
|
57
|
+
"gc.cancel": string;
|
|
58
|
+
"gc.running": string;
|
|
59
|
+
"gc.done": string;
|
|
60
|
+
import: string;
|
|
61
|
+
importing: string;
|
|
62
|
+
imported: string;
|
|
63
|
+
confirmTitle: string;
|
|
64
|
+
confirmDescription: string;
|
|
65
|
+
confirmAccept: string;
|
|
66
|
+
confirmCancel: string;
|
|
67
|
+
close: string;
|
|
68
|
+
"failure.notArchived": string;
|
|
69
|
+
"failure.live": string;
|
|
70
|
+
"failure.missing": string;
|
|
71
|
+
"failure.other": string;
|
|
72
|
+
"time.now": string;
|
|
73
|
+
"time.minutes": string;
|
|
74
|
+
"time.hours": string;
|
|
75
|
+
"time.days": string;
|
|
76
|
+
"time.months": string;
|
|
77
|
+
"time.years": string;
|
|
78
|
+
};
|
|
79
|
+
/** 「对话管理」页面字典的 key 集合。 */
|
|
80
|
+
type ConversationManagerKey = keyof typeof zh;
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region ../../../vendor/deepseek-harness/packages/core/scope/lib/types/index.d.ts
|
|
83
|
+
declare const ScopedBrand: unique symbol;
|
|
84
|
+
/**
|
|
85
|
+
* A routing-only event receiver built by {@link scopeTarget}. The type
|
|
86
|
+
* parameter records the subject type for dispatch checking; the carrier does
|
|
87
|
+
* not expose the subject's properties. Event payloads carry the real subject.
|
|
88
|
+
*/
|
|
89
|
+
type Scoped<T extends object> = object & {
|
|
90
|
+
readonly [ScopedBrand]: T;
|
|
91
|
+
};
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region ../../../vendor/deepseek-harness/packages/typert/protocol/lib/types/owned-value.d.ts
|
|
94
|
+
/** Generic invocation-owned values returned by synchronous Client Context resolvers. */
|
|
95
|
+
/** Shared identity across independently bundled Context providers and Gateway. */
|
|
96
|
+
declare const TYPERT_OWNED_VALUE: unique symbol;
|
|
97
|
+
/** A borrowed payload paired with the invocation owner's idempotent cleanup. */
|
|
98
|
+
interface TypertOwnedValue<Value> extends Disposable {
|
|
99
|
+
readonly [TYPERT_OWNED_VALUE]: true;
|
|
100
|
+
readonly value: Value;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region ../../../vendor/deepseek-harness/packages/typert/protocol/lib/types/types.d.ts
|
|
104
|
+
declare const LOOKUP_HOST: unique symbol;
|
|
105
|
+
declare const LOOKUP_WIRE: unique symbol;
|
|
106
|
+
declare const CONTEXT_WIRE: unique symbol;
|
|
107
|
+
/** Type-level association between a Host object and its wire identity. */
|
|
108
|
+
interface TypertLookup<Host, Wire> {
|
|
109
|
+
readonly [LOOKUP_HOST]: Host;
|
|
110
|
+
readonly [LOOKUP_WIRE]: Wire;
|
|
111
|
+
}
|
|
112
|
+
/** Extract the Host object associated with one lookup declaration. */
|
|
113
|
+
type TypertLookupHost<Lookup> = Lookup extends TypertLookup<infer Host, infer _Wire> ? Host : never;
|
|
114
|
+
/** Extract the wire identity associated with one lookup declaration. */
|
|
115
|
+
type TypertLookupWire<Lookup> = Lookup extends TypertLookup<infer _Host, infer Wire> ? Wire : never;
|
|
116
|
+
/** Type-level association between a scoped Context kind and its wire identity. */
|
|
117
|
+
interface TypertContext<Wire> {
|
|
118
|
+
readonly [CONTEXT_WIRE]: Wire;
|
|
119
|
+
}
|
|
120
|
+
/** Extract the wire identity associated with one scoped Context declaration. */
|
|
121
|
+
type TypertContextWire<ContextType> = ContextType extends TypertContext<infer Wire> ? Wire : never;
|
|
122
|
+
/** Merge-extensible Host object lookup declarations. */
|
|
123
|
+
interface TypertLookupMap {}
|
|
124
|
+
/** Merge-extensible scoped Context declarations. */
|
|
125
|
+
interface TypertContextMap {}
|
|
126
|
+
/** Awaitable disposer returned by Cordis-owned Typert registrations. */
|
|
127
|
+
type TypertDisposer = () => Promise<void>;
|
|
128
|
+
type StringKeyOf<Value> = Extract<keyof Value, string>;
|
|
129
|
+
/** Minimal runtime-schema capability carried by strict generated codecs. */
|
|
130
|
+
interface TypertSchema<Output = unknown> {
|
|
131
|
+
/**
|
|
132
|
+
* Parse and validate one boundary value.
|
|
133
|
+
* @param value - untrusted boundary value.
|
|
134
|
+
* @returns the validated value.
|
|
135
|
+
*/
|
|
136
|
+
parse(value: unknown): Output;
|
|
137
|
+
}
|
|
138
|
+
/** Codec attached to one invocation parameter or result. */
|
|
139
|
+
type TypertCodec = {
|
|
140
|
+
readonly mode: 'strict';
|
|
141
|
+
readonly typeSymbol: string;
|
|
142
|
+
/** Materialize and return the process-realm schema on first boundary use. */
|
|
143
|
+
readonly create: () => TypertSchema;
|
|
144
|
+
} | {
|
|
145
|
+
readonly mode: 'src-json';
|
|
146
|
+
};
|
|
147
|
+
/** One ordered business parameter in a Remote invocation. */
|
|
148
|
+
interface InvocationParameterDescriptor {
|
|
149
|
+
/** Source-level parameter name. */
|
|
150
|
+
readonly name: string;
|
|
151
|
+
/** Required key in the wire `args` object. */
|
|
152
|
+
readonly wire: string;
|
|
153
|
+
/** Whether the value is JSON or requires a registered Host lookup. */
|
|
154
|
+
readonly source: 'json' | 'lookup';
|
|
155
|
+
/** Lookup key when `source` is `lookup`. */
|
|
156
|
+
readonly lookup?: string;
|
|
157
|
+
/** Boundary codec for the wire representation. */
|
|
158
|
+
readonly codec: TypertCodec;
|
|
159
|
+
/** Missing wire fields decode to `undefined` only for an explicitly declared `T | undefined`. */
|
|
160
|
+
readonly acceptsUndefined?: true;
|
|
161
|
+
}
|
|
162
|
+
/** Source position retained for diagnostics from generated definitions. */
|
|
163
|
+
interface InvocationSourceLocation {
|
|
164
|
+
readonly file: string;
|
|
165
|
+
readonly line: number;
|
|
166
|
+
readonly column: number;
|
|
167
|
+
}
|
|
168
|
+
/** Carrier-independent description of one exported method invocation. */
|
|
169
|
+
interface InvocationDescriptor {
|
|
170
|
+
/** Globally stable generated identity. */
|
|
171
|
+
readonly id: string;
|
|
172
|
+
/** Cordis service key owning the method. */
|
|
173
|
+
readonly service: string;
|
|
174
|
+
/** Wire namespace, defaulting to the service key. */
|
|
175
|
+
readonly namespace: string;
|
|
176
|
+
/** Public instance method name. */
|
|
177
|
+
readonly method: string;
|
|
178
|
+
/** Service member invoked when the exported method name is an alias. */
|
|
179
|
+
readonly implementation?: string;
|
|
180
|
+
/** Absent for unary calls; stream calls validate and deliver every yielded item. */
|
|
181
|
+
readonly mode?: 'stream';
|
|
182
|
+
/** Receiver selection mode. */
|
|
183
|
+
readonly invocation: {
|
|
184
|
+
readonly kind: 'direct';
|
|
185
|
+
} | {
|
|
186
|
+
readonly kind: 'context';
|
|
187
|
+
readonly context: string;
|
|
188
|
+
readonly wire: string;
|
|
189
|
+
readonly codec: TypertCodec;
|
|
190
|
+
};
|
|
191
|
+
/** Optional consuming-Context projection for one direct lookup parameter. */
|
|
192
|
+
readonly scope?: {
|
|
193
|
+
/** Context kind whose Client adapter supplies the identity. */
|
|
194
|
+
readonly context: string;
|
|
195
|
+
/** Lookup parameter wire field replaced by the Context identity. */
|
|
196
|
+
readonly wire: string;
|
|
197
|
+
};
|
|
198
|
+
/** Ordered business parameters. */
|
|
199
|
+
readonly parameters: readonly InvocationParameterDescriptor[];
|
|
200
|
+
/** Transport cancellation injected after business parameters instead of entering wire args. */
|
|
201
|
+
readonly cancellation?: {
|
|
202
|
+
/** Reserved final Host method parameter. */
|
|
203
|
+
readonly parameter: 'signal';
|
|
204
|
+
};
|
|
205
|
+
/** Codec for the unary result or each yielded stream item. */
|
|
206
|
+
readonly result: TypertCodec;
|
|
207
|
+
/** Source declaration used only for diagnostics. */
|
|
208
|
+
readonly sourceLocation?: InvocationSourceLocation;
|
|
209
|
+
}
|
|
210
|
+
/** Generated Host contract selected explicitly by a Client assembly. */
|
|
211
|
+
interface TypertRemoteContribution {
|
|
212
|
+
/** npm package that owns the Remote methods. */
|
|
213
|
+
readonly package: string;
|
|
214
|
+
/** Consumer-side invocation descriptors generated from that package. */
|
|
215
|
+
readonly descriptors: readonly InvocationDescriptor[];
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Resolve one validated wire identity, synchronously or asynchronously.
|
|
219
|
+
* @param id - validated wire identity.
|
|
220
|
+
* @returns the Host object, or `undefined` when unavailable.
|
|
221
|
+
*/
|
|
222
|
+
type TypertLookupResolver<Host = unknown, Wire = unknown> = (id: Wire) => Host | undefined | Promise<Host | undefined>;
|
|
223
|
+
/** Runtime provider for one declared Host object lookup. */
|
|
224
|
+
interface TypertLookupProvider<Host = unknown, Wire = unknown> {
|
|
225
|
+
/** Source parameter name recognized by the SRC weak parser. */
|
|
226
|
+
readonly parameter: string;
|
|
227
|
+
/** Wire field replacing the Host object parameter. */
|
|
228
|
+
readonly wire: string;
|
|
229
|
+
/** Canonical Host type symbol used by strict generation. */
|
|
230
|
+
readonly hostTypeSymbol: string;
|
|
231
|
+
/** Canonical wire type symbol used by strict generation. */
|
|
232
|
+
readonly wireTypeSymbol: string;
|
|
233
|
+
/**
|
|
234
|
+
* Resolve a wire identity through the provider's default policy.
|
|
235
|
+
* @param id - validated wire identity.
|
|
236
|
+
* @returns the object, `undefined` when unavailable, or either asynchronously.
|
|
237
|
+
*/
|
|
238
|
+
resolve(id: Wire): Host | undefined | Promise<Host | undefined>;
|
|
239
|
+
}
|
|
240
|
+
/** Stable wire declaration retained after a lookup provider unloads. */
|
|
241
|
+
interface TypertLookupDefinition {
|
|
242
|
+
/** Merge-declared lookup key. */
|
|
243
|
+
readonly key: string;
|
|
244
|
+
/** Source parameter name recognized by the SRC weak parser. */
|
|
245
|
+
readonly parameter: string;
|
|
246
|
+
/** Wire field replacing the Host object parameter. */
|
|
247
|
+
readonly wire: string;
|
|
248
|
+
/** Canonical Host type symbol used by strict generation. */
|
|
249
|
+
readonly hostTypeSymbol: string;
|
|
250
|
+
/** Canonical wire type symbol used by strict generation. */
|
|
251
|
+
readonly wireTypeSymbol: string;
|
|
252
|
+
}
|
|
253
|
+
/** Host wire-to-Context resolver plus the declaration used by strict Remote methods. */
|
|
254
|
+
interface TypertHostContextAdapter<Wire = unknown> {
|
|
255
|
+
/** Wire field carrying the Context identity. */
|
|
256
|
+
readonly wire: string;
|
|
257
|
+
/** Canonical wire type symbol used by strict generation. */
|
|
258
|
+
readonly wireTypeSymbol: string;
|
|
259
|
+
/**
|
|
260
|
+
* Resolve a validated wire identity to a live Host Context.
|
|
261
|
+
* @param id - validated wire identity.
|
|
262
|
+
* @returns the Context, or `undefined` when it is unavailable.
|
|
263
|
+
*/
|
|
264
|
+
resolve(id: Wire): Context | undefined | Promise<Context | undefined>;
|
|
265
|
+
}
|
|
266
|
+
/** Composition-owned resolver replacing one Host Context adapter's default lookup policy. */
|
|
267
|
+
type TypertHostContextResolver<Wire = unknown> = (id: Wire) => Context | undefined | Promise<Context | undefined>;
|
|
268
|
+
/** Client-side bidirectional Context adapter. */
|
|
269
|
+
interface TypertClientContextAdapter<Wire = unknown> {
|
|
270
|
+
/**
|
|
271
|
+
* Read the identity represented by a live Client Context.
|
|
272
|
+
* @param ctx - Client Context inspected by a scoped Remote caller.
|
|
273
|
+
* @returns the wire identity, or `undefined` for another Context kind.
|
|
274
|
+
*/
|
|
275
|
+
identity(ctx: Context): Wire | undefined;
|
|
276
|
+
/**
|
|
277
|
+
* Resolve a validated identity synchronously for one Client invocation.
|
|
278
|
+
* @param id - validated wire identity.
|
|
279
|
+
* @returns a borrowed or invocation-owned Client Context, or undefined when unavailable.
|
|
280
|
+
*/
|
|
281
|
+
resolve(id: Wire): Context | TypertOwnedValue<Context> | undefined;
|
|
282
|
+
}
|
|
283
|
+
/** Notification emitted after a Typert runtime registry changes. */
|
|
284
|
+
interface TypertRegistryChange {
|
|
285
|
+
readonly kind: 'local' | 'remote' | 'lookup' | 'host-context' | 'client-context';
|
|
286
|
+
readonly key: string;
|
|
287
|
+
}
|
|
288
|
+
/** Listener for one Typert runtime registry. */
|
|
289
|
+
type TypertRegistryListener = (change: TypertRegistryChange) => void;
|
|
290
|
+
/** Current-environment invocation definitions. */
|
|
291
|
+
interface TypertLocalRegistry {
|
|
292
|
+
/**
|
|
293
|
+
* Look up one invocation by `<namespace>/<method>`.
|
|
294
|
+
* @param endpoint - canonical endpoint.
|
|
295
|
+
* @returns the live descriptor, or `undefined` when absent.
|
|
296
|
+
*/
|
|
297
|
+
get(endpoint: string): InvocationDescriptor | undefined;
|
|
298
|
+
/**
|
|
299
|
+
* Report whether a strict definition has existed during this Typert Service lifetime.
|
|
300
|
+
* @param endpoint - canonical endpoint.
|
|
301
|
+
* @returns `true` after the endpoint has been registered at least once, even if withdrawn.
|
|
302
|
+
*/
|
|
303
|
+
hasSeen(endpoint: string): boolean;
|
|
304
|
+
/** @returns a registration-order snapshot of local descriptors. */
|
|
305
|
+
list(): readonly InvocationDescriptor[];
|
|
306
|
+
/**
|
|
307
|
+
* Observe later local-definition changes.
|
|
308
|
+
* @param listener - synchronous contained observer.
|
|
309
|
+
* @returns disposer for this subscription.
|
|
310
|
+
*/
|
|
311
|
+
subscribe(listener: TypertRegistryListener): TypertDisposer;
|
|
312
|
+
}
|
|
313
|
+
/** Consumer-selected Remote contribution registry. */
|
|
314
|
+
interface TypertRemoteRegistry {
|
|
315
|
+
/**
|
|
316
|
+
* Register one generated contribution for the calling Cordis fiber.
|
|
317
|
+
* @param contribution - generated Remote descriptors.
|
|
318
|
+
* @returns disposer withdrawing the exact contribution.
|
|
319
|
+
*/
|
|
320
|
+
register(contribution: TypertRemoteContribution): TypertDisposer;
|
|
321
|
+
/**
|
|
322
|
+
* Look up one Remote descriptor by endpoint.
|
|
323
|
+
* @param endpoint - canonical endpoint.
|
|
324
|
+
* @returns the descriptor, or `undefined` when unmounted.
|
|
325
|
+
*/
|
|
326
|
+
get(endpoint: string): InvocationDescriptor | undefined;
|
|
327
|
+
/** @returns a registration-order snapshot of Remote descriptors. */
|
|
328
|
+
list(): readonly InvocationDescriptor[];
|
|
329
|
+
/**
|
|
330
|
+
* Observe later Remote contribution changes.
|
|
331
|
+
* @param listener - synchronous contained observer.
|
|
332
|
+
* @returns disposer for this subscription.
|
|
333
|
+
*/
|
|
334
|
+
subscribe(listener: TypertRegistryListener): TypertDisposer;
|
|
335
|
+
}
|
|
336
|
+
/** Runtime registry for Host object lookup providers. */
|
|
337
|
+
interface TypertLookupRegistry {
|
|
338
|
+
/**
|
|
339
|
+
* Register one provider under its merge-declared key.
|
|
340
|
+
* @param key - lookup key.
|
|
341
|
+
* @param provider - owning package's live resolver.
|
|
342
|
+
* @returns disposer withdrawing the exact provider.
|
|
343
|
+
*/
|
|
344
|
+
register<K extends StringKeyOf<TypertLookupMap>>(key: K, provider: TypertLookupProvider<TypertLookupHost<TypertLookupMap[K]>, TypertLookupWire<TypertLookupMap[K]>>): TypertDisposer;
|
|
345
|
+
/**
|
|
346
|
+
* Replace one provider's default resolution policy while this contribution is active.
|
|
347
|
+
* Configuration may precede provider registration; without a live provider, `get()` remains unavailable.
|
|
348
|
+
* @param key - lookup key whose wire declaration remains provider-owned.
|
|
349
|
+
* @param resolver - composition-owned resolver used by every lookup of this key.
|
|
350
|
+
* @returns disposer restoring the provider's default resolver.
|
|
351
|
+
*/
|
|
352
|
+
configure<K extends StringKeyOf<TypertLookupMap>>(key: K, resolver: TypertLookupResolver<TypertLookupHost<TypertLookupMap[K]>, TypertLookupWire<TypertLookupMap[K]>>): TypertDisposer;
|
|
353
|
+
/**
|
|
354
|
+
* Look up one provider by runtime key.
|
|
355
|
+
* @param key - descriptor lookup key.
|
|
356
|
+
* @returns the live provider, or `undefined` when absent.
|
|
357
|
+
*/
|
|
358
|
+
get(key: string): TypertLookupProvider | undefined;
|
|
359
|
+
/** @returns lookup declarations observed during this Typert Service lifetime. */
|
|
360
|
+
definitions(): readonly TypertLookupDefinition[];
|
|
361
|
+
/** @returns a snapshot of registered provider keys. */
|
|
362
|
+
keys(): readonly string[];
|
|
363
|
+
/**
|
|
364
|
+
* Observe later lookup changes.
|
|
365
|
+
* @param listener - synchronous contained observer.
|
|
366
|
+
* @returns disposer for this subscription.
|
|
367
|
+
*/
|
|
368
|
+
subscribe(listener: TypertRegistryListener): TypertDisposer;
|
|
369
|
+
}
|
|
370
|
+
/** Runtime registry for the Host and Client adapters of each Context kind. */
|
|
371
|
+
interface TypertContextRegistry {
|
|
372
|
+
/**
|
|
373
|
+
* Register a Host Context adapter.
|
|
374
|
+
* @param key - merge-declared Context key.
|
|
375
|
+
* @param adapter - owning package's Host resolver and wire declaration.
|
|
376
|
+
* @returns disposer withdrawing the exact adapter.
|
|
377
|
+
*/
|
|
378
|
+
registerHost<K extends StringKeyOf<TypertContextMap>>(key: K, adapter: TypertHostContextAdapter<TypertContextWire<TypertContextMap[K]>>): TypertDisposer;
|
|
379
|
+
/**
|
|
380
|
+
* Override one Host Context key's resolution policy for the calling fiber.
|
|
381
|
+
* Configuration may precede provider registration and restores the provider's default resolver on disposal.
|
|
382
|
+
* @param key - merge-declared Context key.
|
|
383
|
+
* @param resolver - composition-owned resolver used by every Host Context lookup of this key.
|
|
384
|
+
* @returns disposer restoring the provider's default resolver.
|
|
385
|
+
*/
|
|
386
|
+
configureHost<K extends StringKeyOf<TypertContextMap>>(key: K, resolver: TypertHostContextResolver<TypertContextWire<TypertContextMap[K]>>): TypertDisposer;
|
|
387
|
+
/**
|
|
388
|
+
* Register a Client Context adapter.
|
|
389
|
+
* @param key - merge-declared Context key.
|
|
390
|
+
* @param adapter - owning package's bidirectional Client projection.
|
|
391
|
+
* @returns disposer withdrawing the exact adapter.
|
|
392
|
+
*/
|
|
393
|
+
registerClient<K extends StringKeyOf<TypertContextMap>>(key: K, adapter: TypertClientContextAdapter<TypertContextWire<TypertContextMap[K]>>): TypertDisposer;
|
|
394
|
+
/**
|
|
395
|
+
* Look up a Host Context adapter.
|
|
396
|
+
* @param key - descriptor Context key.
|
|
397
|
+
* @returns the adapter, or `undefined` when absent.
|
|
398
|
+
*/
|
|
399
|
+
getHost(key: string): TypertHostContextAdapter | undefined;
|
|
400
|
+
/**
|
|
401
|
+
* Look up a Client Context adapter.
|
|
402
|
+
* @param key - descriptor Context key.
|
|
403
|
+
* @returns the adapter, or `undefined` when absent.
|
|
404
|
+
*/
|
|
405
|
+
getClient(key: string): TypertClientContextAdapter | undefined;
|
|
406
|
+
/**
|
|
407
|
+
* Observe later Context adapter changes.
|
|
408
|
+
* @param listener - synchronous contained observer.
|
|
409
|
+
* @returns disposer for this subscription.
|
|
410
|
+
*/
|
|
411
|
+
subscribe(listener: TypertRegistryListener): TypertDisposer;
|
|
412
|
+
}
|
|
413
|
+
/** Minimal Typert runtime consumed through dependency inversion. */
|
|
414
|
+
interface TypertRegistryContract {
|
|
415
|
+
readonly local: TypertLocalRegistry;
|
|
416
|
+
readonly remotes: TypertRemoteRegistry;
|
|
417
|
+
readonly lookups: TypertLookupRegistry;
|
|
418
|
+
readonly contexts: TypertContextRegistry;
|
|
419
|
+
}
|
|
420
|
+
declare module '@deepseek-ai/cordis' {
|
|
421
|
+
interface Context {
|
|
422
|
+
typert: TypertRegistryContract;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
//#endregion
|
|
426
|
+
//#region ../../../vendor/deepseek-harness/packages/typert/protocol/lib/types/index.d.ts
|
|
427
|
+
/** Options for an explicit Service-to-Gateway binding. */
|
|
428
|
+
interface TypertGatewayBindingOptions {
|
|
429
|
+
/** Wire namespace; defaults to the Cordis service key. */
|
|
430
|
+
readonly namespace?: string;
|
|
431
|
+
}
|
|
432
|
+
/** Visible declaration that one Service participates in Typert Gateway export. */
|
|
433
|
+
interface TypertGatewayBinding<Service extends object = object> {
|
|
434
|
+
readonly service: Service;
|
|
435
|
+
readonly serviceKey: string;
|
|
436
|
+
readonly namespace: string;
|
|
437
|
+
}
|
|
438
|
+
/** Cordis Service base that exposes its registered name through Typert Gateway. */
|
|
439
|
+
declare abstract class TypertRemoteService<out T = never> extends Service<T> {
|
|
440
|
+
/** Visible binding consumed by the Gateway's source-mode discovery. */
|
|
441
|
+
readonly typertRemote: TypertGatewayBinding<this>;
|
|
442
|
+
/**
|
|
443
|
+
* Register the Service and bind the same key to Typert Gateway.
|
|
444
|
+
* @param ctx - owning Cordis Context.
|
|
445
|
+
* @param serviceKey - exact Cordis service key and default wire namespace.
|
|
446
|
+
* @param options - optional distinct wire namespace.
|
|
447
|
+
*/
|
|
448
|
+
protected constructor(ctx: Context, serviceKey: string, options?: TypertGatewayBindingOptions);
|
|
449
|
+
}
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region ../../../vendor/deepseek-harness/packages/util/brand/lib/types/index.d.ts
|
|
452
|
+
/**
|
|
453
|
+
* Duplicate-install-safe nominal primitive helpers.
|
|
454
|
+
*
|
|
455
|
+
* A brand makes structurally identical strings or numbers non-interchangeable
|
|
456
|
+
* at the type level: a `SessionId` cannot be passed where a `ToolCallId` is
|
|
457
|
+
* expected, and an event sequence cannot be passed as a log offset. Comparison,
|
|
458
|
+
* logging, and serialization retain the underlying primitive behavior.
|
|
459
|
+
*
|
|
460
|
+
* This package owns no concrete domain value and keeps no runtime identity or mutable
|
|
461
|
+
* state, so independently installed copies produce interchangeable values.
|
|
462
|
+
*
|
|
463
|
+
* @module @deepseek-ai/dsh-brand
|
|
464
|
+
*/
|
|
465
|
+
declare const BRAND: unique symbol;
|
|
466
|
+
/** A string carrying a compile-time-only brand `B`. */
|
|
467
|
+
type Branded<B extends string> = string & {
|
|
468
|
+
readonly [BRAND]: B;
|
|
469
|
+
};
|
|
470
|
+
/** A number carrying a compile-time-only brand `B`. */
|
|
471
|
+
type BrandedNumber<B extends string> = number & {
|
|
472
|
+
readonly [BRAND]: B;
|
|
473
|
+
};
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region ../../../vendor/deepseek-harness/packages/attachment/attachment/lib/types/error.d.ts
|
|
476
|
+
declare const ATTACHMENT_ERROR_CODES: readonly ["TOO_MANY_IMAGES", "IMAGES_TOO_LARGE", "UNSUPPORTED_IMAGE_TYPE", "INVALID_IMAGE_BASE64", "INVALID_IMAGE", "IMAGE_TYPE_MISMATCH", "IMAGE_TOO_LARGE", "IMAGE_TOO_MANY_PIXELS", "IMAGE_DIMENSION_TOO_LARGE", "INVALID_FILE_BASE64", "INVALID_ATTACHMENT_REF", "ATTACHMENT_CORRUPT", "ATTACHMENT_WRITE_FAILED", "ATTACHMENT_NOT_FOUND", "ATTACHMENT_READ_FAILED", "ATTACHMENT_PROJECTION_UNSUPPORTED", "ATTACHMENT_FILES_UNSUPPORTED"];
|
|
477
|
+
/** Stable attachment failure codes used for protocol error routing. */
|
|
478
|
+
type AttachmentErrorCode = typeof ATTACHMENT_ERROR_CODES[number];
|
|
479
|
+
/**
|
|
480
|
+
* Stable failures suitable for host RPC error mapping.
|
|
481
|
+
*
|
|
482
|
+
* Deliberately re-implements the `HarnessError` shape instead of extending it:
|
|
483
|
+
* the base lives in `@deepseek-ai/dsh-llm`, which itself depends on this
|
|
484
|
+
* package (`ImageBlock` references `ImageAttachmentRef`), so sharing the base
|
|
485
|
+
* would create a dependency cycle. Consumers route on `code`, never on the
|
|
486
|
+
* prototype chain, so the shapes stay interchangeable at the wire boundary.
|
|
487
|
+
*/
|
|
488
|
+
declare class AttachmentError extends Error {
|
|
489
|
+
/** Stable machine-routing failure code. */
|
|
490
|
+
readonly code: AttachmentErrorCode;
|
|
491
|
+
/**
|
|
492
|
+
* @param message - human-readable failure description without raw bytes or host paths.
|
|
493
|
+
* @param code - stable machine-routing code.
|
|
494
|
+
* @param options - optional chained cause.
|
|
495
|
+
*/
|
|
496
|
+
constructor(message: string, code: AttachmentErrorCode, options?: ErrorOptions);
|
|
497
|
+
}
|
|
498
|
+
//#endregion
|
|
499
|
+
//#region ../../../vendor/deepseek-harness/packages/attachment/attachment/lib/types/brand.d.ts
|
|
500
|
+
/** Opaque content-addressed identifier for one immutable attachment object. */
|
|
501
|
+
type AttachmentId = Branded<'AttachmentId'>;
|
|
502
|
+
/**
|
|
503
|
+
* Brand a validated storage identifier.
|
|
504
|
+
* @param value - backend-produced opaque identifier.
|
|
505
|
+
* @returns the branded identifier.
|
|
506
|
+
*/
|
|
507
|
+
declare function AttachmentId(value: string): AttachmentId;
|
|
508
|
+
/** Opaque deterministic identity for one request-image transformation. */
|
|
509
|
+
type ImageVariantId = Branded<'ImageVariantId'>;
|
|
510
|
+
/**
|
|
511
|
+
* Brand a validated request-image transformation identifier.
|
|
512
|
+
* @param value - attachment-provider-produced opaque identifier.
|
|
513
|
+
* @returns the branded identifier.
|
|
514
|
+
*/
|
|
515
|
+
declare function ImageVariantId(value: string): ImageVariantId;
|
|
516
|
+
//#endregion
|
|
517
|
+
//#region ../../../vendor/deepseek-harness/packages/attachment/attachment/lib/types/types.d.ts
|
|
518
|
+
/** Raster image formats accepted by the version-one attachment path. */
|
|
519
|
+
type ImageMediaType = 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif';
|
|
520
|
+
/** Durable, serializable reference to one immutable normalized image. */
|
|
521
|
+
interface ImageAttachmentRef {
|
|
522
|
+
/** Opaque storage identifier; never a filesystem path or bearer URL. */
|
|
523
|
+
attachmentId: AttachmentId;
|
|
524
|
+
/** Media type verified from the stored bytes. */
|
|
525
|
+
mediaType: ImageMediaType;
|
|
526
|
+
/** Exact encoded byte length. */
|
|
527
|
+
bytes: number;
|
|
528
|
+
/** Intrinsic encoded width in pixels. */
|
|
529
|
+
width: number;
|
|
530
|
+
/** Intrinsic encoded height in pixels. */
|
|
531
|
+
height: number;
|
|
532
|
+
/** Optional display name stripped of local path information. */
|
|
533
|
+
name?: string;
|
|
534
|
+
/**
|
|
535
|
+
* Input dimensions after applying EXIF orientation and before normalization
|
|
536
|
+
* scaling. Present only when normalization reduced the image.
|
|
537
|
+
*/
|
|
538
|
+
originalDimensions?: {
|
|
539
|
+
width: number;
|
|
540
|
+
height: number;
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Durable, serializable reference to one verbatim stored file. Files are
|
|
545
|
+
* stored byte-for-byte with no normalization; `attachmentId` is the sha256
|
|
546
|
+
* digest of exactly those bytes.
|
|
547
|
+
*/
|
|
548
|
+
interface FileAttachmentRef {
|
|
549
|
+
/** Opaque content-addressed storage identifier; never a filesystem path or bearer URL. */
|
|
550
|
+
attachmentId: AttachmentId;
|
|
551
|
+
/** Sanitized display filename, also the stored object's leaf name. */
|
|
552
|
+
name: string;
|
|
553
|
+
/** Exact byte length. */
|
|
554
|
+
bytes: number;
|
|
555
|
+
}
|
|
556
|
+
/** Base64-encoded file upload accompanying one wire request. */
|
|
557
|
+
interface EncodedFileAttachment {
|
|
558
|
+
/** Canonical base64 encoding of the file bytes. */
|
|
559
|
+
data: string;
|
|
560
|
+
/** Optional display name; it is never interpreted as a path. */
|
|
561
|
+
name?: string;
|
|
562
|
+
}
|
|
563
|
+
/** Request to durably commit one file verbatim. */
|
|
564
|
+
interface SaveFileAttachment {
|
|
565
|
+
data: Uint8Array;
|
|
566
|
+
/** Optional browser/provider display name; it is never interpreted as a path. */
|
|
567
|
+
name?: string;
|
|
568
|
+
}
|
|
569
|
+
/** Request to durably commit one file from bounded byte chunks. */
|
|
570
|
+
interface SaveFileStreamAttachment {
|
|
571
|
+
/** Exact file bytes in order; providers must not retain the complete sequence in memory. */
|
|
572
|
+
data: AsyncIterable<Uint8Array>;
|
|
573
|
+
/** Optional cancellation for source reads and storage writes. */
|
|
574
|
+
signal?: AbortSignal;
|
|
575
|
+
/** Optional browser/provider display name; it is never interpreted as a path. */
|
|
576
|
+
name?: string;
|
|
577
|
+
}
|
|
578
|
+
/** Deployment-resolved limits used by upload admission and request buffering. */
|
|
579
|
+
interface ImageAttachmentLimits {
|
|
580
|
+
maxImageBytes: number;
|
|
581
|
+
maxImagesPerMessage: number;
|
|
582
|
+
maxMessageImageBytes: number;
|
|
583
|
+
maxImagePixels: number;
|
|
584
|
+
/** Maximum intrinsic width and maximum intrinsic height in pixels for one image. */
|
|
585
|
+
maxImageDimension: number;
|
|
586
|
+
mediaTypes: readonly ImageMediaType[];
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Browser-submitted prompt content accepted by Host prompt endpoints; the
|
|
590
|
+
* accepting Host promotes image parts to durable references through
|
|
591
|
+
* `ctx.attachments.admitPromptContent()` before any message is created, so a wire caller can
|
|
592
|
+
* never cite an attachment it did not upload.
|
|
593
|
+
*/
|
|
594
|
+
type PromptContentPart = {
|
|
595
|
+
readonly type: 'text';
|
|
596
|
+
readonly text: string;
|
|
597
|
+
} | {
|
|
598
|
+
readonly type: 'image';
|
|
599
|
+
readonly mediaType: ImageMediaType;
|
|
600
|
+
readonly data: string;
|
|
601
|
+
readonly name?: string;
|
|
602
|
+
};
|
|
603
|
+
/** Host prompt content whose file receipts are resolved and whose image bytes await admission. */
|
|
604
|
+
type AttachmentAdmissionPart = PromptContentPart | {
|
|
605
|
+
readonly type: 'file';
|
|
606
|
+
readonly attachment: FileAttachmentRef;
|
|
607
|
+
};
|
|
608
|
+
/** Host-admitted prompt content with every attachment represented by its durable reference. */
|
|
609
|
+
type AdmittedPromptContentPart = {
|
|
610
|
+
readonly type: 'text';
|
|
611
|
+
readonly text: string;
|
|
612
|
+
} | {
|
|
613
|
+
readonly type: 'image';
|
|
614
|
+
readonly attachment: ImageAttachmentRef;
|
|
615
|
+
} | {
|
|
616
|
+
readonly type: 'file';
|
|
617
|
+
readonly attachment: FileAttachmentRef;
|
|
618
|
+
};
|
|
619
|
+
/** Request to validate and durably commit one image. */
|
|
620
|
+
interface SaveImageAttachment {
|
|
621
|
+
data: Uint8Array;
|
|
622
|
+
/** Caller-declared media type, checked against fully decoded bytes. */
|
|
623
|
+
mediaType: ImageMediaType;
|
|
624
|
+
/** Optional browser/provider display name; it is never interpreted as a path. */
|
|
625
|
+
name?: string;
|
|
626
|
+
}
|
|
627
|
+
/** Stored image bytes returned after reference and digest verification. */
|
|
628
|
+
interface StoredImageAttachment {
|
|
629
|
+
ref: ImageAttachmentRef;
|
|
630
|
+
data: Uint8Array;
|
|
631
|
+
}
|
|
632
|
+
/** Deterministic request-image target selected by one exact model route for one attachment. */
|
|
633
|
+
interface ImageRequestTarget {
|
|
634
|
+
/** Target width in pixels; a target above the source keeps the source width. */
|
|
635
|
+
width: number;
|
|
636
|
+
/** Target height in pixels; a target above the source keeps the source height. */
|
|
637
|
+
height: number;
|
|
638
|
+
/** Encoded-byte target before base64 expansion or Files API upload; the smallest quality-ladder output is kept when no quality fits. */
|
|
639
|
+
maxBytes: number;
|
|
640
|
+
}
|
|
641
|
+
/** Cached request version derived from one provider-independent normalized attachment. */
|
|
642
|
+
interface RequestImageAttachment {
|
|
643
|
+
/** Cache and upload-index key over the attachment id, policy, and fixed encoder parameters. */
|
|
644
|
+
variantId: ImageVariantId;
|
|
645
|
+
/** Durable normalized attachment from which this request version was derived. */
|
|
646
|
+
attachment: ImageAttachmentRef;
|
|
647
|
+
/** Encoded request bytes. */
|
|
648
|
+
data: Uint8Array;
|
|
649
|
+
mediaType: ImageMediaType;
|
|
650
|
+
bytes: number;
|
|
651
|
+
width: number;
|
|
652
|
+
height: number;
|
|
653
|
+
/** Provider-compatible sample depth proven after request encoding. */
|
|
654
|
+
depth: 'uchar';
|
|
655
|
+
/** Provider-compatible color space proven after request encoding. */
|
|
656
|
+
space: 'srgb';
|
|
657
|
+
/** Whether the encoded request version retains an alpha channel. */
|
|
658
|
+
hasAlpha: boolean;
|
|
659
|
+
}
|
|
660
|
+
//#endregion
|
|
661
|
+
//#region ../../../vendor/deepseek-harness/packages/attachment/attachment/lib/types/index.d.ts
|
|
662
|
+
declare module '@deepseek-ai/cordis' {
|
|
663
|
+
interface Context {
|
|
664
|
+
attachments: AttachmentStore;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
/** Immutable binary attachment service. Implementations validate bytes before publishing a reference. */
|
|
668
|
+
declare abstract class AttachmentStore extends Service {
|
|
669
|
+
constructor(ctx: Context);
|
|
670
|
+
/** Deployment-resolved image policy used by authoritative and fast-path validation. */
|
|
671
|
+
abstract readonly imageLimits: ImageAttachmentLimits;
|
|
672
|
+
/**
|
|
673
|
+
* Validate one image without persisting it.
|
|
674
|
+
* Batch callers validate every member before saving any member.
|
|
675
|
+
* @param input - encoded bytes, declared media type, and optional display name.
|
|
676
|
+
* @returns completion after the encoded raster has been fully decoded.
|
|
677
|
+
*/
|
|
678
|
+
abstract validateImage(input: SaveImageAttachment): Promise<void>;
|
|
679
|
+
/**
|
|
680
|
+
* Validate one ordered image batch before committing any member.
|
|
681
|
+
* Validation failures start no writes; storage failures return no partial
|
|
682
|
+
* references, although already published content-addressed objects may stay
|
|
683
|
+
* unreachable until a future retention policy collects them.
|
|
684
|
+
* @param inputs - encoded images in their owning message order.
|
|
685
|
+
* @returns durable references in the exact input order.
|
|
686
|
+
*/
|
|
687
|
+
protected validateImageBatch(inputs: readonly SaveImageAttachment[]): void;
|
|
688
|
+
/**
|
|
689
|
+
* Validate and durably commit one ordered image batch.
|
|
690
|
+
* @param inputs - encoded images in owning-message order.
|
|
691
|
+
* @returns durable normalized attachment references in the same order after every member succeeds.
|
|
692
|
+
*/
|
|
693
|
+
saveImages(inputs: readonly SaveImageAttachment[]): Promise<readonly ImageAttachmentRef[]>;
|
|
694
|
+
/**
|
|
695
|
+
* Admit one Host prompt and replace each uploaded image with its durable reference.
|
|
696
|
+
* Text and durable file references pass through unchanged. A prompt without image parts performs no storage operation.
|
|
697
|
+
* @param content - prompt parts in message order after file receipt resolution.
|
|
698
|
+
* @returns admitted prompt parts in the same order as `content`.
|
|
699
|
+
* @throws AttachmentError when the image batch is refused.
|
|
700
|
+
*/
|
|
701
|
+
admitPromptContent(content: readonly AttachmentAdmissionPart[]): Promise<AdmittedPromptContentPart[]>;
|
|
702
|
+
/**
|
|
703
|
+
* Decode and durably commit one canonical base64 file upload.
|
|
704
|
+
* @param input - canonical base64 bytes and optional display name.
|
|
705
|
+
* @returns the durable content-addressed file reference.
|
|
706
|
+
* @throws AttachmentError when the encoding or storage operation is refused.
|
|
707
|
+
*/
|
|
708
|
+
admitEncodedFile(input: EncodedFileAttachment): Promise<FileAttachmentRef>;
|
|
709
|
+
/**
|
|
710
|
+
* Identify a failure emitted by this attachment capability by its stable code.
|
|
711
|
+
* @param error - value caught from an attachment operation.
|
|
712
|
+
* @returns whether the value is an attachment failure.
|
|
713
|
+
*/
|
|
714
|
+
isAttachmentError(error: unknown): error is AttachmentError;
|
|
715
|
+
/**
|
|
716
|
+
* Validate and durably commit one image before its owning session event is appended.
|
|
717
|
+
* The returned reference describes the persisted normalized image. When
|
|
718
|
+
* normalization reduces the raster, its `originalDimensions` records the
|
|
719
|
+
* orientation-applied input dimensions.
|
|
720
|
+
* @param input - encoded bytes, declared media type, and optional display name.
|
|
721
|
+
* @returns the durable content-addressed normalized image reference.
|
|
722
|
+
*/
|
|
723
|
+
abstract saveImage(input: SaveImageAttachment): Promise<ImageAttachmentRef>;
|
|
724
|
+
/**
|
|
725
|
+
* Read one image and verify that bytes still match the recorded reference.
|
|
726
|
+
* @param ref - durable reference from the session log.
|
|
727
|
+
* @param signal - optional cancellation for backend read and verification work.
|
|
728
|
+
* @returns the verified bytes and normalized attachment reference.
|
|
729
|
+
* @throws the signal reason when aborted, or a storage error when verification fails.
|
|
730
|
+
*/
|
|
731
|
+
abstract readImage(ref: ImageAttachmentRef, signal?: AbortSignal): Promise<StoredImageAttachment>;
|
|
732
|
+
/**
|
|
733
|
+
* Locate the provider-owned normalized object in the harness host filesystem.
|
|
734
|
+
* @param ref - durable normalized attachment reference.
|
|
735
|
+
* @returns an absolute host path, or undefined when this backend is not host-file-backed.
|
|
736
|
+
* @throws an AttachmentError when the durable reference is invalid.
|
|
737
|
+
*/
|
|
738
|
+
imageHostPath(ref: ImageAttachmentRef): string | undefined;
|
|
739
|
+
/**
|
|
740
|
+
* Durably commit one file byte-for-byte before its owning session event is
|
|
741
|
+
* appended. Files carry no admission limits: any byte content and length is
|
|
742
|
+
* accepted, and the stored object is the exact submitted bytes. Backends
|
|
743
|
+
* without verbatim file storage keep this default rejection.
|
|
744
|
+
* @param input - exact bytes and optional display name.
|
|
745
|
+
* @returns the durable content-addressed file reference.
|
|
746
|
+
*/
|
|
747
|
+
saveFile(input: SaveFileAttachment): Promise<FileAttachmentRef>;
|
|
748
|
+
/**
|
|
749
|
+
* Durably commit one file byte-for-byte from bounded chunks. Providers must
|
|
750
|
+
* apply backpressure and must not collect the complete file in memory.
|
|
751
|
+
* Backends without streamed verbatim storage keep this default rejection.
|
|
752
|
+
* @param input - ordered exact bytes, optional cancellation, and display name.
|
|
753
|
+
* @returns the durable content-addressed file reference.
|
|
754
|
+
*/
|
|
755
|
+
saveFileStream(input: SaveFileStreamAttachment): Promise<FileAttachmentRef>;
|
|
756
|
+
/**
|
|
757
|
+
* Read and verify one verbatim stored file as bounded chunks. Providers must
|
|
758
|
+
* not collect the complete file in memory. Backends without verbatim file
|
|
759
|
+
* reads keep this default rejection.
|
|
760
|
+
* @param ref - durable reference from the session log.
|
|
761
|
+
* @param signal - optional cancellation for backend reads and verification work.
|
|
762
|
+
* @returns exact file bytes in order; integrity failures reject the iteration.
|
|
763
|
+
*/
|
|
764
|
+
readFileStream(ref: FileAttachmentRef, signal?: AbortSignal): AsyncIterable<Uint8Array>;
|
|
765
|
+
/**
|
|
766
|
+
* Locate the verbatim stored file object in the harness host filesystem.
|
|
767
|
+
* @param ref - durable file reference.
|
|
768
|
+
* @returns an absolute host path, or undefined when this backend is not host-file-backed.
|
|
769
|
+
* @throws an AttachmentError when the durable reference is invalid.
|
|
770
|
+
*/
|
|
771
|
+
fileHostPath(ref: FileAttachmentRef): string | undefined;
|
|
772
|
+
/**
|
|
773
|
+
* Generate or read one deterministic model-request version from the stored normalized image.
|
|
774
|
+
* @param ref - durable provider-independent normalized attachment reference.
|
|
775
|
+
* @param target - route-chosen dimensions and byte target; an unmet byte target yields the smallest ladder output.
|
|
776
|
+
* @param signal - optional cancellation.
|
|
777
|
+
* @returns request bytes and the cache/upload identity covering every transform input.
|
|
778
|
+
*/
|
|
779
|
+
readImageRequest(ref: ImageAttachmentRef, target: ImageRequestTarget, signal?: AbortSignal): Promise<RequestImageAttachment>;
|
|
780
|
+
}
|
|
781
|
+
//#endregion
|
|
782
|
+
//#region ../../../vendor/deepseek-harness/packages/llm/llm/lib/types/brand.d.ts
|
|
783
|
+
/** Stable identity carried by one message across inbox, log, and model-request boundaries. */
|
|
784
|
+
type MessageId = Branded<'MessageId'>;
|
|
785
|
+
/**
|
|
786
|
+
* Brand a message identifier.
|
|
787
|
+
* @param id - the opaque message identifier.
|
|
788
|
+
* @returns the same string with the message-id brand.
|
|
789
|
+
*/
|
|
790
|
+
declare function MessageId(id: string): MessageId;
|
|
791
|
+
/**
|
|
792
|
+
* Correlates a model-issued tool call with its result. Provider-issued for
|
|
793
|
+
* real adapters; synthesized by mocks/assembler fallbacks.
|
|
794
|
+
*/
|
|
795
|
+
type ToolCallId = Branded<'ToolCallId'>;
|
|
796
|
+
/**
|
|
797
|
+
* Brand a string as a {@link ToolCallId}.
|
|
798
|
+
* @param id - the provider-issued or synthesized call id.
|
|
799
|
+
* @returns the same string with the tool-call-id brand.
|
|
800
|
+
*/
|
|
801
|
+
declare function ToolCallId(id: string): ToolCallId;
|
|
802
|
+
/** Provider-issued request identifier retained for diagnostics across package boundaries. */
|
|
803
|
+
type ProviderRequestId = Branded<'ProviderRequestId'>;
|
|
804
|
+
/**
|
|
805
|
+
* Brand a provider-issued request identifier.
|
|
806
|
+
* @param id - the opaque provider-issued string.
|
|
807
|
+
* @returns the same string, branded; no validation is performed.
|
|
808
|
+
*/
|
|
809
|
+
declare function ProviderRequestId(id: string): ProviderRequestId;
|
|
810
|
+
/** Adapter-owned identifier for one model's selectable reasoning effort. */
|
|
811
|
+
type ReasoningEffortId = Branded<'ReasoningEffortId'>;
|
|
812
|
+
/**
|
|
813
|
+
* Brand an adapter-owned reasoning-effort identifier.
|
|
814
|
+
* @param id - the opaque identifier exposed by one model capability.
|
|
815
|
+
* @returns the same string, branded; no validation is performed.
|
|
816
|
+
*/
|
|
817
|
+
declare function ReasoningEffortId(id: string): ReasoningEffortId;
|
|
818
|
+
//#endregion
|
|
819
|
+
//#region ../../../vendor/deepseek-harness/packages/llm/llm/lib/types/message.d.ts
|
|
820
|
+
/** Provider/model identity and adapter-private replay data for an assistant message. */
|
|
821
|
+
interface AssistantProviderMetadata {
|
|
822
|
+
/** Provider route that produced the message. */
|
|
823
|
+
provider: string;
|
|
824
|
+
/** Provider model id that produced the message. */
|
|
825
|
+
model: string;
|
|
826
|
+
/**
|
|
827
|
+
* Lossless-JSON adapter state needed to replay the provider response.
|
|
828
|
+
* `LlmRuntime` exposes it to a target adapter only when that adapter instance
|
|
829
|
+
* currently owns both this historical provider and the target provider.
|
|
830
|
+
*/
|
|
831
|
+
replayState?: unknown;
|
|
832
|
+
}
|
|
833
|
+
/** Required source of an assistant message produced by a routed model. */
|
|
834
|
+
interface ModelMessageSource extends AssistantProviderMetadata {
|
|
835
|
+
kind: 'model';
|
|
836
|
+
}
|
|
837
|
+
/** Required source of a user-role message carrying one tool result. */
|
|
838
|
+
interface ToolMessageSource {
|
|
839
|
+
kind: 'tool';
|
|
840
|
+
callId: ToolCallId;
|
|
841
|
+
}
|
|
842
|
+
/** One named contribution to a `snapshot`-form context, in assembly order. */
|
|
843
|
+
interface ContextSnapshotSection {
|
|
844
|
+
/** The contributing subsystem's name. */
|
|
845
|
+
readonly name: string;
|
|
846
|
+
/** That contribution's model-facing text, exactly as assembled. */
|
|
847
|
+
readonly text: string;
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Producer-declared {@link ContextForm} and the fields that form requires,
|
|
851
|
+
* mixed into the source types that carry one.
|
|
852
|
+
*
|
|
853
|
+
* Discriminated by `form` so a producer cannot select a form without the
|
|
854
|
+
* fields needed to present it: a `notice` must record its one-line
|
|
855
|
+
* account, a `snapshot` its sections. Omitting `form` stays valid — an
|
|
856
|
+
* undeclared context is the documented default.
|
|
857
|
+
*/
|
|
858
|
+
type ContextFormed = {
|
|
859
|
+
readonly form?: never;
|
|
860
|
+
} | {
|
|
861
|
+
readonly form: 'instructions';
|
|
862
|
+
} | {
|
|
863
|
+
readonly form: 'catalog';
|
|
864
|
+
} | {
|
|
865
|
+
readonly form: 'snapshot';
|
|
866
|
+
/** The named contributions this snapshot assembled, in order. */
|
|
867
|
+
readonly sections: readonly ContextSnapshotSection[];
|
|
868
|
+
} | {
|
|
869
|
+
readonly form: 'notice';
|
|
870
|
+
/** One-line account of what happened, shown without expanding the row. */
|
|
871
|
+
readonly summary: string;
|
|
872
|
+
} | {
|
|
873
|
+
readonly form: 'relay';
|
|
874
|
+
} | {
|
|
875
|
+
readonly form: 'recall';
|
|
876
|
+
};
|
|
877
|
+
/**
|
|
878
|
+
* Where a message (or injected content) came from.
|
|
879
|
+
* Merge-extensible sum type — plugins add their own `kind`s.
|
|
880
|
+
*/
|
|
881
|
+
interface MessageSourceMap {
|
|
882
|
+
user: {
|
|
883
|
+
kind: 'user';
|
|
884
|
+
};
|
|
885
|
+
plugin: {
|
|
886
|
+
kind: 'plugin';
|
|
887
|
+
plugin: string;
|
|
888
|
+
} & ContextFormed;
|
|
889
|
+
model: ModelMessageSource;
|
|
890
|
+
tool: ToolMessageSource;
|
|
891
|
+
}
|
|
892
|
+
/** Any known message source, derived from {@link MessageSourceMap}; switch on `kind` and fall through unknowns (merge-extensible). */
|
|
893
|
+
type MessageSource = MessageSourceMap[keyof MessageSourceMap];
|
|
894
|
+
/** One immutable message representation shared by delivery, durable history, and model requests. */
|
|
895
|
+
interface Message {
|
|
896
|
+
/** Stable identity preserved across every representation boundary. */
|
|
897
|
+
readonly id: MessageId;
|
|
898
|
+
/** Provider-neutral conversation role. */
|
|
899
|
+
readonly role: 'system' | 'user' | 'assistant';
|
|
900
|
+
/** Exact model-facing blocks. */
|
|
901
|
+
readonly content: ContentBlock[];
|
|
902
|
+
/** Required source fields supplied by the producer. */
|
|
903
|
+
readonly source: MessageSource;
|
|
904
|
+
}
|
|
905
|
+
/** A user-role specialization of the one shared message representation. */
|
|
906
|
+
interface UserMessage extends Message {
|
|
907
|
+
readonly role: 'user';
|
|
908
|
+
}
|
|
909
|
+
/** A model-produced assistant specialization of the shared message representation. */
|
|
910
|
+
interface AssistantMessage extends Message {
|
|
911
|
+
readonly role: 'assistant';
|
|
912
|
+
readonly source: ModelMessageSource;
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* A system-role specialization of the shared message representation: one
|
|
916
|
+
* rendered system prompt attributed to the plugin that assembled it. Empty
|
|
917
|
+
* `content` means "no system prompt" and projects to no wire message.
|
|
918
|
+
*/
|
|
919
|
+
interface SystemMessage extends Message {
|
|
920
|
+
readonly role: 'system';
|
|
921
|
+
readonly source: MessageSourceMap['plugin'];
|
|
922
|
+
}
|
|
923
|
+
/** A tool-result specialization whose model-facing block retains call correlation. */
|
|
924
|
+
interface ToolResultMessage extends Message {
|
|
925
|
+
readonly role: 'user';
|
|
926
|
+
readonly content: [ToolResultBlock];
|
|
927
|
+
readonly source: ToolMessageSource;
|
|
928
|
+
}
|
|
929
|
+
//#endregion
|
|
930
|
+
//#region ../../../vendor/deepseek-harness/packages/llm/llm/lib/types/types.d.ts
|
|
931
|
+
declare module '@deepseek-ai/cordis' {
|
|
932
|
+
interface Events {
|
|
933
|
+
/**
|
|
934
|
+
* The provider topology changed: an adapter registered or unregistered
|
|
935
|
+
* routes, or the configurable-provider directory gained or lost entries.
|
|
936
|
+
* This payload-free registry notification fires at each commit point
|
|
937
|
+
* (including registration disposal); consumers re-read `listProviders()`,
|
|
938
|
+
* `listModels()`, or `listConfigurableProviders()` for the new state.
|
|
939
|
+
* Observer failures are contained and cannot veto the registry mutation.
|
|
940
|
+
* @mode emit
|
|
941
|
+
*/
|
|
942
|
+
'llm/adapters-updated'(): void;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
/** Serializable provider or transport failure facts; policy decides whether they are retryable. */
|
|
946
|
+
interface LlmFailure {
|
|
947
|
+
/** Human-readable provider or transport failure. */
|
|
948
|
+
readonly message: string;
|
|
949
|
+
/** Stable provider-neutral machine-routing code. */
|
|
950
|
+
readonly code: string;
|
|
951
|
+
/** HTTP status returned by the provider, when available. */
|
|
952
|
+
readonly status?: number;
|
|
953
|
+
/** Provider-requested delay in milliseconds, when valid and available. */
|
|
954
|
+
readonly providerRetryAfterMs?: number;
|
|
955
|
+
/** Opaque provider-issued request identifier for diagnostics. */
|
|
956
|
+
readonly requestId?: ProviderRequestId;
|
|
957
|
+
/**
|
|
958
|
+
* With code `IMAGE_OFFLOAD_REQUIRED`: how many more of the oldest retained
|
|
959
|
+
* image occurrences the route needs offloaded before the same request fits
|
|
960
|
+
* its exact byte accounting. `dsh-compaction-image-offload` records the
|
|
961
|
+
* selected occurrences in an `image/offload` event and retries the step.
|
|
962
|
+
*/
|
|
963
|
+
readonly offloadImages?: number;
|
|
964
|
+
}
|
|
965
|
+
/** Plain text visible to the end user. */
|
|
966
|
+
interface TextBlock {
|
|
967
|
+
type: 'text';
|
|
968
|
+
text: string;
|
|
969
|
+
}
|
|
970
|
+
/** Reasoning / thinking content, distinct from visible text. */
|
|
971
|
+
interface ReasoningBlock {
|
|
972
|
+
type: 'reasoning';
|
|
973
|
+
text: string;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* A durable raster image reference, valid in user or assistant content. The
|
|
977
|
+
* block is deliberately role-neutral; assistant-side rendering is forward
|
|
978
|
+
* compatibility — the current production adapters declare text-only output,
|
|
979
|
+
* so only user messages may carry images.
|
|
980
|
+
*/
|
|
981
|
+
interface ImageBlock {
|
|
982
|
+
type: 'image';
|
|
983
|
+
/** Immutable bytes and intrinsic display metadata owned by the attachment service. */
|
|
984
|
+
attachment: ImageAttachmentRef;
|
|
985
|
+
/**
|
|
986
|
+
* Derived from a durable image-offload decision or preserved by a message
|
|
987
|
+
* rewrite. Every route sends placeholder text naming the image and its
|
|
988
|
+
* available read-only path instead of image bytes.
|
|
989
|
+
*/
|
|
990
|
+
offloaded?: true;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* A durable verbatim file reference, valid in user content. Files never reach
|
|
994
|
+
* a provider natively: request assembly projects every occurrence to
|
|
995
|
+
* deterministic handle text (name, byte size, and the read-only saved path),
|
|
996
|
+
* so adapters and providers see text in its place while the durable log keeps
|
|
997
|
+
* the structured reference for presentation and authorization.
|
|
998
|
+
*/
|
|
999
|
+
interface FileBlock {
|
|
1000
|
+
type: 'file';
|
|
1001
|
+
/** Immutable verbatim bytes and display metadata owned by the attachment service. */
|
|
1002
|
+
attachment: FileAttachmentRef;
|
|
1003
|
+
}
|
|
1004
|
+
/** A tool invocation requested by the model. */
|
|
1005
|
+
interface ToolCallBlock {
|
|
1006
|
+
type: 'tool-call';
|
|
1007
|
+
/** Provider-issued call id; correlates with the matching tool result. */
|
|
1008
|
+
id: ToolCallId;
|
|
1009
|
+
name: string;
|
|
1010
|
+
/** Raw JSON string as produced by the model. */
|
|
1011
|
+
arguments: string;
|
|
1012
|
+
}
|
|
1013
|
+
/** The result of a tool invocation, sent back to the model. */
|
|
1014
|
+
interface ToolResultBlock {
|
|
1015
|
+
type: 'tool-result';
|
|
1016
|
+
toolCallId: ToolCallId;
|
|
1017
|
+
content: ContentBlock[];
|
|
1018
|
+
isError?: boolean;
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Merge-extensible content blocks keyed by `type`. New core blocks must land
|
|
1022
|
+
* with adapter, UI, and compaction support.
|
|
1023
|
+
*/
|
|
1024
|
+
interface ContentBlockMap {
|
|
1025
|
+
'text': TextBlock;
|
|
1026
|
+
'reasoning': ReasoningBlock;
|
|
1027
|
+
'image': ImageBlock;
|
|
1028
|
+
'file': FileBlock;
|
|
1029
|
+
'tool-call': ToolCallBlock;
|
|
1030
|
+
'tool-result': ToolResultBlock;
|
|
1031
|
+
}
|
|
1032
|
+
/** The block `type` tag vocabulary; widens as plugins add entries to {@link ContentBlockMap}. */
|
|
1033
|
+
type ContentBlockType = keyof ContentBlockMap;
|
|
1034
|
+
/** Any known content block, derived from {@link ContentBlockMap}; switch on `type` and fall through unknowns (merge-extensible). */
|
|
1035
|
+
type ContentBlock = ContentBlockMap[ContentBlockType];
|
|
1036
|
+
/**
|
|
1037
|
+
* Why a model response stopped.
|
|
1038
|
+
* Merge-extensible so adapters can surface provider-specific reasons.
|
|
1039
|
+
*/
|
|
1040
|
+
interface FinishReasonMap {
|
|
1041
|
+
'stop': {
|
|
1042
|
+
kind: 'stop';
|
|
1043
|
+
};
|
|
1044
|
+
'tool-calls': {
|
|
1045
|
+
kind: 'tool-calls';
|
|
1046
|
+
};
|
|
1047
|
+
'max-tokens': {
|
|
1048
|
+
kind: 'max-tokens';
|
|
1049
|
+
};
|
|
1050
|
+
'aborted': {
|
|
1051
|
+
kind: 'aborted';
|
|
1052
|
+
failure: LlmFailure;
|
|
1053
|
+
};
|
|
1054
|
+
'error': {
|
|
1055
|
+
kind: 'error';
|
|
1056
|
+
failure: LlmFailure;
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
/** Any known finish reason, derived from {@link FinishReasonMap}; switch on `kind` and fall through unknowns (merge-extensible). */
|
|
1060
|
+
type FinishReason = FinishReasonMap[keyof FinishReasonMap];
|
|
1061
|
+
/**
|
|
1062
|
+
* Token accounting for one model call (cache fields are optional).
|
|
1063
|
+
*
|
|
1064
|
+
* Counts are DISJOINT: `inputTokens` is uncached input only; cached input is
|
|
1065
|
+
* reported separately as `cacheReadTokens`/`cacheWriteTokens` (billed input =
|
|
1066
|
+
* sum of the three). Adapters whose providers fold cache hits into a total
|
|
1067
|
+
* prompt count (DeepSeek's `prompt_tokens`) subtract them out.
|
|
1068
|
+
*/
|
|
1069
|
+
interface TokenUsage {
|
|
1070
|
+
inputTokens: number;
|
|
1071
|
+
outputTokens: number;
|
|
1072
|
+
/**
|
|
1073
|
+
* Exact full-call total including aggregate prompt and output tokens.
|
|
1074
|
+
*
|
|
1075
|
+
* Adapters preserve a provider total or derive it from authoritative
|
|
1076
|
+
* aggregate prompt/output counters; they omit it when unavailable or
|
|
1077
|
+
* inconsistent.
|
|
1078
|
+
*/
|
|
1079
|
+
totalTokens?: number;
|
|
1080
|
+
cacheReadTokens?: number;
|
|
1081
|
+
cacheWriteTokens?: number;
|
|
1082
|
+
reasoningTokens?: number;
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Request price of one ordered image occurrence under one exact model route's
|
|
1086
|
+
* request projection. Every occurrence resolves to the pair the wire actually
|
|
1087
|
+
* carries: provider visual tokens for a retained image, plus the model-visible
|
|
1088
|
+
* text sent with or instead of it (request-preview handle, offload placeholder,
|
|
1089
|
+
* or text-only substitution). The caller prices `text` with its own text
|
|
1090
|
+
* estimator so provider pricing never fixes a text tokenization.
|
|
1091
|
+
*/
|
|
1092
|
+
interface LlmImageRequestPrice {
|
|
1093
|
+
/** Provider visual tokens for the retained request image; 0 when only text represents this occurrence. */
|
|
1094
|
+
visualTokens: number;
|
|
1095
|
+
/** Model-visible text sent for this occurrence, to be priced by the caller's text estimator. */
|
|
1096
|
+
text: string;
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Provider-side request-image pricing for one exact model route. Implemented
|
|
1100
|
+
* by adapters whose provider charges visual tokens; consumers (the token
|
|
1101
|
+
* meter) resolve it synchronously per measurement, so implementations must not
|
|
1102
|
+
* perform I/O.
|
|
1103
|
+
*/
|
|
1104
|
+
interface LlmImageRequestPricing {
|
|
1105
|
+
/**
|
|
1106
|
+
* Price every image occurrence of one request projection.
|
|
1107
|
+
* @param images - surface image blocks in request order, one entry per occurrence; an `offloaded` block
|
|
1108
|
+
* is priced as its placeholder text.
|
|
1109
|
+
* @returns one price per occurrence, aligned by index with `images`.
|
|
1110
|
+
*/
|
|
1111
|
+
priceImages(images: readonly ImageBlock[]): readonly LlmImageRequestPrice[];
|
|
1112
|
+
}
|
|
1113
|
+
/** Display metadata for one registered provider route. */
|
|
1114
|
+
interface LlmProviderInfo {
|
|
1115
|
+
/** Provider route key used by {@link GenerateOptions.provider}. */
|
|
1116
|
+
id: string;
|
|
1117
|
+
/** Human-readable provider name for selectors and diagnostics. */
|
|
1118
|
+
name: string;
|
|
1119
|
+
}
|
|
1120
|
+
/** Merge-extensible provider model modality vocabulary. */
|
|
1121
|
+
interface ModelModalityMap {
|
|
1122
|
+
text: 'text';
|
|
1123
|
+
image: 'image';
|
|
1124
|
+
}
|
|
1125
|
+
/** Any declared provider model modality. */
|
|
1126
|
+
type ModelModality = ModelModalityMap[keyof ModelModalityMap];
|
|
1127
|
+
/**
|
|
1128
|
+
* One provider route an adapter plugin can activate through configuration,
|
|
1129
|
+
* whether or not the route is currently registered. Configuration surfaces
|
|
1130
|
+
* merge this directory with `listProviders()` to offer every configurable
|
|
1131
|
+
* provider alongside its live/dormant state.
|
|
1132
|
+
*/
|
|
1133
|
+
interface LlmConfigurableProvider {
|
|
1134
|
+
/** Provider route key this entry activates when configured. */
|
|
1135
|
+
provider: string;
|
|
1136
|
+
/** Human-readable provider name for configuration surfaces. */
|
|
1137
|
+
displayName: string;
|
|
1138
|
+
/** User-settings namespace whose section configures this provider. */
|
|
1139
|
+
settingsNs: string;
|
|
1140
|
+
/**
|
|
1141
|
+
* Path from that namespace's section root to this provider's profile
|
|
1142
|
+
* object; empty when the whole section is the profile.
|
|
1143
|
+
*/
|
|
1144
|
+
settingsPath: readonly string[];
|
|
1145
|
+
/**
|
|
1146
|
+
* Whether the owning adapter knows this route only because configuration
|
|
1147
|
+
* declared it — a gateway or self-hosted server it ships nothing about.
|
|
1148
|
+
* Absent means the adapter draws no such distinction; false means it does
|
|
1149
|
+
* and this route is one of its own. Only the adapter can answer: a stored
|
|
1150
|
+
* profile is how a user-added route AND a corrected shipped one both look
|
|
1151
|
+
* from outside.
|
|
1152
|
+
*/
|
|
1153
|
+
declared?: boolean;
|
|
1154
|
+
/** Configuration diagnostic for repair; unaffected models may remain serviceable. */
|
|
1155
|
+
error?: string;
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* One interrogation of a provider endpoint that configuration has not stored
|
|
1159
|
+
* yet. Configuration surfaces send the draft a user is still editing, so the
|
|
1160
|
+
* request carries the endpoint and credential directly instead of naming a
|
|
1161
|
+
* route: a provider being added has no route to name.
|
|
1162
|
+
*/
|
|
1163
|
+
interface LlmModelDiscoveryRequest {
|
|
1164
|
+
/**
|
|
1165
|
+
* Route the draft is editing, when it edits an existing one. A route whose
|
|
1166
|
+
* adapter already knows its models answers from that knowledge instead of
|
|
1167
|
+
* asking the endpoint — the adapter's own registry is the better answer, and
|
|
1168
|
+
* it costs no network call.
|
|
1169
|
+
*/
|
|
1170
|
+
provider?: string;
|
|
1171
|
+
/**
|
|
1172
|
+
* Endpoint to interrogate. Optional because a route the adapter already
|
|
1173
|
+
* describes needs none; a route it does not must supply one.
|
|
1174
|
+
*/
|
|
1175
|
+
baseURL?: string;
|
|
1176
|
+
/** Wire protocol the endpoint speaks, when the draft names one. */
|
|
1177
|
+
api?: string;
|
|
1178
|
+
/** Credential for this interrogation alone; the harness never stores it. */
|
|
1179
|
+
apiKey?: string;
|
|
1180
|
+
}
|
|
1181
|
+
declare module '@deepseek-ai/dsh-typert-protocol' {
|
|
1182
|
+
interface RemoteErrorDetailsMap {
|
|
1183
|
+
/** A draft provider interrogation refused or failed. */
|
|
1184
|
+
'llm/model-discovery-rejected': {
|
|
1185
|
+
readonly settingsNs: string;
|
|
1186
|
+
readonly baseURL?: string;
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* One model an endpoint reports about itself. Every field but the id is
|
|
1192
|
+
* optional because most provider listings disclose an id and nothing else;
|
|
1193
|
+
* a surface adopting one of these still owes the capacities its adapter needs.
|
|
1194
|
+
*/
|
|
1195
|
+
interface LlmDiscoveredModel {
|
|
1196
|
+
/** Model id the endpoint accepts. */
|
|
1197
|
+
id: string;
|
|
1198
|
+
/** Human-readable name when the endpoint supplies one. */
|
|
1199
|
+
name?: string;
|
|
1200
|
+
/** Maximum combined request and response context, when disclosed. */
|
|
1201
|
+
contextWindow?: number;
|
|
1202
|
+
/** Maximum output tokens, when disclosed. */
|
|
1203
|
+
maxTokens?: number;
|
|
1204
|
+
/** Accepted input types when disclosed by the catalog or endpoint; absent means unknown. */
|
|
1205
|
+
inputModalities?: readonly ModelModality[];
|
|
1206
|
+
}
|
|
1207
|
+
/** One adapter-discovered model; catalog membership is advisory, not request validation. */
|
|
1208
|
+
interface LlmModelInfo {
|
|
1209
|
+
/** Provider route that owns this model entry. */
|
|
1210
|
+
provider: string;
|
|
1211
|
+
/** Model id passed to {@link GenerateOptions.model}. */
|
|
1212
|
+
id: string;
|
|
1213
|
+
/** Human-readable model name for selectors. */
|
|
1214
|
+
name: string;
|
|
1215
|
+
/** Optional user-facing distinction from otherwise similar models. */
|
|
1216
|
+
description?: string;
|
|
1217
|
+
/** Accepted request modalities; absent means unknown, while an explicit omission is negative capability. */
|
|
1218
|
+
inputModalities?: readonly ModelModality[];
|
|
1219
|
+
}
|
|
1220
|
+
/** Provider-owned context capacity for one exact provider/model route. */
|
|
1221
|
+
interface LlmModelContext {
|
|
1222
|
+
/** Maximum combined request and response context in tokens. */
|
|
1223
|
+
contextWindow: number;
|
|
1224
|
+
}
|
|
1225
|
+
/** Display metadata for one adapter-owned reasoning effort. */
|
|
1226
|
+
interface LlmReasoningEffortInfo {
|
|
1227
|
+
/** Opaque stable value accepted by {@link GenerateOptions.reasoningEffort}. */
|
|
1228
|
+
id: ReasoningEffortId;
|
|
1229
|
+
/** Human-readable effort name for selectors and diagnostics. */
|
|
1230
|
+
name: string;
|
|
1231
|
+
/** Optional user-facing distinction from otherwise similar efforts. */
|
|
1232
|
+
description?: string;
|
|
1233
|
+
}
|
|
1234
|
+
/** Selectable reasoning efforts for one exact provider/model route. */
|
|
1235
|
+
interface LlmModelReasoningInfo {
|
|
1236
|
+
/** Supported efforts in adapter-preferred display order. */
|
|
1237
|
+
efforts: readonly LlmReasoningEffortInfo[];
|
|
1238
|
+
/**
|
|
1239
|
+
* Adapter-configured default materialized into requests when callers omit
|
|
1240
|
+
* an effort. Absence preserves the provider's own default.
|
|
1241
|
+
*/
|
|
1242
|
+
defaultEffort?: ReasoningEffortId;
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* How a model applies a system prompt that changes mid-conversation.
|
|
1246
|
+
* `'in-history'`: the model reads the latest `system` message at any position
|
|
1247
|
+
* of `messages` as the complete effective system prompt, so a changed prompt
|
|
1248
|
+
* can follow the cached history instead of rewriting message 0.
|
|
1249
|
+
*/
|
|
1250
|
+
type SystemPromptUpdate = 'in-history';
|
|
1251
|
+
/** Exact-route model metadata resolved by its owning adapter. */
|
|
1252
|
+
interface LlmResolvedModelInfo extends LlmModelInfo {
|
|
1253
|
+
/** Provider-owned context capacity when known. */
|
|
1254
|
+
context?: LlmModelContext;
|
|
1255
|
+
/** Adapter-configured per-request output cap materialized when callers omit one. */
|
|
1256
|
+
defaultMaxTokens?: number;
|
|
1257
|
+
/** Adapter-owned selectable reasoning levels when exposed. */
|
|
1258
|
+
reasoning?: LlmModelReasoningInfo;
|
|
1259
|
+
/** Declared mid-conversation system prompt handling; absent means only a leading system message is read. */
|
|
1260
|
+
systemPromptUpdate?: SystemPromptUpdate;
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Adapter-private lossless-JSON state for replaying a successful response,
|
|
1264
|
+
* carried by a terminal `finish` chunk and stored on the assembled assistant
|
|
1265
|
+
* message's model source. Both halves stay opaque to the harness; only the
|
|
1266
|
+
* split is shared vocabulary, so assembly can keep stored metadata aligned
|
|
1267
|
+
* with stored content without reading either half.
|
|
1268
|
+
*/
|
|
1269
|
+
interface ReplayEnvelope {
|
|
1270
|
+
/** Response-level adapter-private metadata (ids, native stop reason). */
|
|
1271
|
+
response: unknown;
|
|
1272
|
+
/**
|
|
1273
|
+
* Per-block adapter-private metadata, one entry per emitted block in
|
|
1274
|
+
* first-seen stream order. When assembly drops a block it drops the entry at
|
|
1275
|
+
* the same position; entries whose length does not match the emitted block
|
|
1276
|
+
* count discard the whole envelope. An adapter whose metadata is independent
|
|
1277
|
+
* of block structure omits this field and the envelope passes through
|
|
1278
|
+
* assembly unchanged.
|
|
1279
|
+
*/
|
|
1280
|
+
blocks?: readonly unknown[];
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Raw streaming protocol emitted by adapters.
|
|
1284
|
+
* Block indexes correlate interleaved deltas, and `block-end` carries the
|
|
1285
|
+
* assembled block. Adapters emit usage before the terminal finish and nothing
|
|
1286
|
+
* afterward; tool arguments remain raw JSON strings. An adapter implementation
|
|
1287
|
+
* may throw, but `LlmRuntime.stream()` normalizes that failure to a terminal
|
|
1288
|
+
* `error` or `aborted` finish before exposing it to consumers.
|
|
1289
|
+
*/
|
|
1290
|
+
type StreamChunk = {
|
|
1291
|
+
type: 'block-start';
|
|
1292
|
+
index: number;
|
|
1293
|
+
blockType: ContentBlockType;
|
|
1294
|
+
} | {
|
|
1295
|
+
type: 'text-delta';
|
|
1296
|
+
index: number;
|
|
1297
|
+
text: string;
|
|
1298
|
+
} | {
|
|
1299
|
+
type: 'reasoning-delta';
|
|
1300
|
+
index: number;
|
|
1301
|
+
text: string;
|
|
1302
|
+
} | {
|
|
1303
|
+
type: 'tool-call-delta';
|
|
1304
|
+
index: number;
|
|
1305
|
+
id: ToolCallId;
|
|
1306
|
+
name?: string;
|
|
1307
|
+
argumentsDelta: string;
|
|
1308
|
+
} | {
|
|
1309
|
+
type: 'block-end';
|
|
1310
|
+
index: number;
|
|
1311
|
+
block: ContentBlock;
|
|
1312
|
+
} | {
|
|
1313
|
+
type: 'usage';
|
|
1314
|
+
usage: TokenUsage;
|
|
1315
|
+
} | {
|
|
1316
|
+
type: 'finish';
|
|
1317
|
+
reason: FinishReason;
|
|
1318
|
+
/** Replay metadata for a successful response; see {@link ReplayEnvelope}. */
|
|
1319
|
+
replayState?: ReplayEnvelope;
|
|
1320
|
+
};
|
|
1321
|
+
/**
|
|
1322
|
+
* JSON-schema description of a tool, as sent to the model.
|
|
1323
|
+
*
|
|
1324
|
+
* Declared here (not in dsh-tools) because it is part of {@link GenerateOptions};
|
|
1325
|
+
* dsh-tools' ToolDefinition and dsh-system-prompt's PromptAssembly both import
|
|
1326
|
+
* it from this package.
|
|
1327
|
+
*/
|
|
1328
|
+
interface ToolSchema {
|
|
1329
|
+
name: string;
|
|
1330
|
+
description: string;
|
|
1331
|
+
/** JSON Schema object for the arguments. */
|
|
1332
|
+
parameters: Record<string, unknown>;
|
|
1333
|
+
}
|
|
1334
|
+
/** A single model request, fully assembled. */
|
|
1335
|
+
interface GenerateOptions {
|
|
1336
|
+
/** Registered provider route selecting the adapter instance. */
|
|
1337
|
+
provider: string;
|
|
1338
|
+
model: string;
|
|
1339
|
+
/** Adapter-owned reasoning effort selected for this exact model. */
|
|
1340
|
+
reasoningEffort?: ReasoningEffortId;
|
|
1341
|
+
/**
|
|
1342
|
+
* Ordered conversation messages, exactly as the provider sees them. A
|
|
1343
|
+
* loop-built request passes the derived history (dsh-agent-loop), whose
|
|
1344
|
+
* leading system-role message carries the system prompt; a hand-built
|
|
1345
|
+
* one-shot passes any list.
|
|
1346
|
+
*/
|
|
1347
|
+
messages: Message[];
|
|
1348
|
+
/**
|
|
1349
|
+
* System prompt text for one-shot callers; adapters map it to the provider's
|
|
1350
|
+
* system slot ahead of `messages`. Loop-built requests leave it undefined.
|
|
1351
|
+
*/
|
|
1352
|
+
system?: string;
|
|
1353
|
+
/** Tool schemas (adapters map to the provider's `tools` field). */
|
|
1354
|
+
tools?: ToolSchema[];
|
|
1355
|
+
temperature?: number;
|
|
1356
|
+
maxTokens?: number;
|
|
1357
|
+
/**
|
|
1358
|
+
* Stop sequences: generation halts as soon as the model produces any one of
|
|
1359
|
+
* these strings (adapters map to the provider's stop field, e.g. OpenAI
|
|
1360
|
+
* `stop`). The stop string itself is not included in the output.
|
|
1361
|
+
*/
|
|
1362
|
+
stop?: string[];
|
|
1363
|
+
signal?: AbortSignal;
|
|
1364
|
+
/**
|
|
1365
|
+
* Session identity stamped by the loop for request routing. Replay uses it
|
|
1366
|
+
* to separate cursors; adapters may map it to model-hidden transport metadata.
|
|
1367
|
+
*/
|
|
1368
|
+
sessionId?: Branded<'SessionId'>;
|
|
1369
|
+
/**
|
|
1370
|
+
* Provider-neutral classification for an auxiliary model call. Adapters may
|
|
1371
|
+
* map the purpose to model-hidden transport metadata or purpose-specific
|
|
1372
|
+
* generation policy. Ordinary conversation requests leave it unset.
|
|
1373
|
+
*/
|
|
1374
|
+
purpose?: 'compaction' | 'session-title';
|
|
1375
|
+
}
|
|
1376
|
+
//#endregion
|
|
1377
|
+
//#region ../../../vendor/deepseek-harness/vendor/cosmokit/lib/types/types.d.ts
|
|
1378
|
+
declare function isArrayBufferLike(value: any): value is ArrayBufferLike;
|
|
1379
|
+
declare function isArrayBufferSource(value: any): value is Binary.Source;
|
|
1380
|
+
/** Binary source detection and base64/hex conversion helpers. */
|
|
1381
|
+
declare namespace Binary {
|
|
1382
|
+
type Source<T extends ArrayBufferLike = ArrayBufferLike> = T | ArrayBufferView<T>;
|
|
1383
|
+
const is: typeof isArrayBufferLike;
|
|
1384
|
+
const isSource: typeof isArrayBufferSource;
|
|
1385
|
+
function fromSource<T extends ArrayBufferLike>(source: Source<T>): T;
|
|
1386
|
+
function toBase64(source: Source): string;
|
|
1387
|
+
function fromBase64(source: string): ArrayBuffer | Uint8Array<ArrayBuffer>;
|
|
1388
|
+
function toHex(source: Source): string;
|
|
1389
|
+
function fromHex(source: string): ArrayBuffer;
|
|
1390
|
+
}
|
|
1391
|
+
//#endregion
|
|
1392
|
+
//#region ../../../vendor/deepseek-harness/vendor/cosmokit/lib/types/misc.d.ts
|
|
1393
|
+
/** String/symbol keyed dictionary type. */
|
|
1394
|
+
type Dict<T = any, K extends string | symbol = string> = { [key in K]: T; };
|
|
1395
|
+
//#endregion
|
|
1396
|
+
//#region ../../../node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts
|
|
1397
|
+
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
1398
|
+
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
1399
|
+
/** The Standard properties. */
|
|
1400
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
1401
|
+
}
|
|
1402
|
+
declare namespace StandardTypedV1 {
|
|
1403
|
+
/** The Standard Typed properties interface. */
|
|
1404
|
+
interface Props<Input = unknown, Output = Input> {
|
|
1405
|
+
/** The version number of the standard. */
|
|
1406
|
+
readonly version: 1;
|
|
1407
|
+
/** The vendor name of the schema library. */
|
|
1408
|
+
readonly vendor: string;
|
|
1409
|
+
/** Inferred types associated with the schema. */
|
|
1410
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
1411
|
+
}
|
|
1412
|
+
/** The Standard Typed types interface. */
|
|
1413
|
+
interface Types<Input = unknown, Output = Input> {
|
|
1414
|
+
/** The input type of the schema. */
|
|
1415
|
+
readonly input: Input;
|
|
1416
|
+
/** The output type of the schema. */
|
|
1417
|
+
readonly output: Output;
|
|
1418
|
+
}
|
|
1419
|
+
/** Infers the input type of a Standard Typed. */
|
|
1420
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
1421
|
+
/** Infers the output type of a Standard Typed. */
|
|
1422
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
1423
|
+
}
|
|
1424
|
+
/** The Standard Schema interface. */
|
|
1425
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
1426
|
+
/** The Standard Schema properties. */
|
|
1427
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
1428
|
+
}
|
|
1429
|
+
declare namespace StandardSchemaV1 {
|
|
1430
|
+
/** The Standard Schema properties interface. */
|
|
1431
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
1432
|
+
/** Validates unknown input values. */
|
|
1433
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
1434
|
+
}
|
|
1435
|
+
/** The result interface of the validate function. */
|
|
1436
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
1437
|
+
/** The result interface if validation succeeds. */
|
|
1438
|
+
interface SuccessResult<Output> {
|
|
1439
|
+
/** The typed output value. */
|
|
1440
|
+
readonly value: Output;
|
|
1441
|
+
/** A falsy value for `issues` indicates success. */
|
|
1442
|
+
readonly issues?: undefined;
|
|
1443
|
+
}
|
|
1444
|
+
interface Options {
|
|
1445
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
1446
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
1447
|
+
}
|
|
1448
|
+
/** The result interface if validation fails. */
|
|
1449
|
+
interface FailureResult {
|
|
1450
|
+
/** The issues of failed validation. */
|
|
1451
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
1452
|
+
}
|
|
1453
|
+
/** The issue interface of the failure output. */
|
|
1454
|
+
interface Issue {
|
|
1455
|
+
/** The error message of the issue. */
|
|
1456
|
+
readonly message: string;
|
|
1457
|
+
/** The path of the issue, if any. */
|
|
1458
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
1459
|
+
}
|
|
1460
|
+
/** The path segment interface of the issue. */
|
|
1461
|
+
interface PathSegment {
|
|
1462
|
+
/** The key representing a path segment. */
|
|
1463
|
+
readonly key: PropertyKey;
|
|
1464
|
+
}
|
|
1465
|
+
/** The Standard types interface. */
|
|
1466
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
1467
|
+
/** Infers the input type of a Standard. */
|
|
1468
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
1469
|
+
/** Infers the output type of a Standard. */
|
|
1470
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
1471
|
+
}
|
|
1472
|
+
//#endregion
|
|
1473
|
+
//#region ../../../vendor/deepseek-harness/vendor/schemastery/lib/types/index.d.ts
|
|
1474
|
+
declare const kSchema: unique symbol;
|
|
1475
|
+
declare global {
|
|
1476
|
+
namespace Schemastery {
|
|
1477
|
+
/** Convert primitive constructors, constants, and existing schemas into a schema type. */
|
|
1478
|
+
type From<X> = X extends string | number | boolean ? Schema<X> : X extends Schema ? X : X extends typeof String ? Schema<string> : X extends typeof Number ? Schema<number> : X extends typeof Boolean ? Schema<boolean> : X extends typeof Function ? Schema<Function, (...args: any[]) => any> : X extends Constructor<infer S> ? Schema<S> : never;
|
|
1479
|
+
type TypeS1<X> = X extends Schema<infer S, unknown> ? S : never;
|
|
1480
|
+
type Inverse<X> = X extends Schema<any, infer Y> ? (arg: Y) => void : never;
|
|
1481
|
+
/** Input type accepted by a schema-like value. */
|
|
1482
|
+
type TypeS<X> = TypeS1<From<X>>;
|
|
1483
|
+
/** Output type returned by a schema-like value after validation. */
|
|
1484
|
+
type TypeT<X> = ReturnType<From<X>>;
|
|
1485
|
+
/** Resolver callback used by custom schema types registered with `Schema.extend()`. */
|
|
1486
|
+
type Resolve = (data: any, schema: Schema, options: Options, strict?: boolean) => [any, any?];
|
|
1487
|
+
/** Input type accepted by one schema in an intersection. */
|
|
1488
|
+
type IntersectS<X> = From<X> extends Schema<infer S, unknown> ? S : never;
|
|
1489
|
+
/** Output type returned by one schema in an intersection. */
|
|
1490
|
+
type IntersectT<X> = Inverse<From<X>> extends ((arg: infer T) => void) ? T : never;
|
|
1491
|
+
type TupleS<X extends readonly any[]> = X extends readonly [infer L, ...infer R] ? [TypeS<L>?, ...TupleS<R>] : any[];
|
|
1492
|
+
type TupleT<X extends readonly any[]> = X extends readonly [infer L, ...infer R] ? [TypeT<L>?, ...TupleT<R>] : any[];
|
|
1493
|
+
type ObjectS<X extends Dict> = { [K in keyof X]?: TypeS<X[K]> | null; } & Dict;
|
|
1494
|
+
type ObjectT<X extends Dict> = { [K in keyof X]: TypeT<X[K]>; } & Dict;
|
|
1495
|
+
type Constructor<T = any> = new (...args: any[]) => T;
|
|
1496
|
+
/** Static constructor and factory methods exposed by the default `Schema` export. */
|
|
1497
|
+
interface Static {
|
|
1498
|
+
<T = any>(options: Partial<Schema<T>>): Schema<T>;
|
|
1499
|
+
new <T = any>(options: Partial<Schema<T>>): Schema<T>;
|
|
1500
|
+
prototype: Schema;
|
|
1501
|
+
/** Validate a value against a schema node and return `[output, adaptedInput?]`. */
|
|
1502
|
+
resolve: Resolve;
|
|
1503
|
+
/** Infer a schema from a primitive value, constructor, or existing schema. */
|
|
1504
|
+
from<X = any>(source?: X): From<X>;
|
|
1505
|
+
/** Register a resolver for a custom schema `type`. */
|
|
1506
|
+
extend(type: string, resolve: Resolve): void;
|
|
1507
|
+
/** Accept any value without validation. */
|
|
1508
|
+
any<T = any>(): Schema<T>;
|
|
1509
|
+
/** Accept only nullable input. */
|
|
1510
|
+
never(): Schema<never>;
|
|
1511
|
+
/** Accept exactly one constant value. */
|
|
1512
|
+
const<const T>(value: T): Schema<T>;
|
|
1513
|
+
/** Accept strings, with optional metadata constraints added by instance methods. */
|
|
1514
|
+
string(): Schema<string>;
|
|
1515
|
+
/** Accept numbers, with optional range and step constraints. */
|
|
1516
|
+
number(): Schema<number>;
|
|
1517
|
+
/** Accept non-negative integer numbers. */
|
|
1518
|
+
natural(): Schema<number>;
|
|
1519
|
+
/** Accept a number between 0 and 1 and mark it as a slider. */
|
|
1520
|
+
percent(): Schema<number>;
|
|
1521
|
+
/** Accept booleans. */
|
|
1522
|
+
boolean(): Schema<boolean>;
|
|
1523
|
+
/** Accept `Date` instances or parse datetime strings into `Date` objects. */
|
|
1524
|
+
date(): Schema<string | Date, Date>;
|
|
1525
|
+
/** Accept `RegExp` instances or parse strings into regular expressions. */
|
|
1526
|
+
regExp(flag?: string): Schema<string | RegExp, RegExp>;
|
|
1527
|
+
/** Accept binary sources and normalize them to `ArrayBufferLike`. */
|
|
1528
|
+
arrayBuffer(): Schema<Binary.Source, ArrayBufferLike>;
|
|
1529
|
+
arrayBuffer(encoding: 'hex' | 'base64'): Schema<Binary.Source | string, ArrayBufferLike>;
|
|
1530
|
+
/** Accept a numeric bitset or string keys and normalize to a number. */
|
|
1531
|
+
bitset<K extends string>(bits: Partial<Record<K, number>>): Schema<number | readonly K[], number>;
|
|
1532
|
+
/** Accept functions. */
|
|
1533
|
+
function(): Schema<Function, (...args: any[]) => any>;
|
|
1534
|
+
/** Accept instances of a constructor or objects whose constructor name matches. */
|
|
1535
|
+
is(constructor: string): Schema;
|
|
1536
|
+
is<T>(constructor: Constructor<T>): Schema<T>;
|
|
1537
|
+
/** Accept arrays whose elements match `inner`. */
|
|
1538
|
+
array<X>(inner: X): Schema<TypeS<X>[], TypeT<X>[]>;
|
|
1539
|
+
/** Accept plain objects with values matching `inner` and optional key schema. */
|
|
1540
|
+
dict<X, Y extends Schema<any, string> = Schema<string>>(inner: X, sKey?: Y): Schema<Dict<TypeS<X>, TypeS<Y>>, Dict<TypeT<X>, TypeT<Y>>>;
|
|
1541
|
+
/** Accept tuple arrays where each index matches the corresponding schema. */
|
|
1542
|
+
tuple<const X extends readonly any[]>(list: X): Schema<TupleS<X>, TupleT<X>>;
|
|
1543
|
+
/** Accept plain objects whose declared properties match the schema dictionary. */
|
|
1544
|
+
object<X extends Dict>(dict: X): Schema<ObjectS<X>, ObjectT<X>>;
|
|
1545
|
+
/** Accept values matching at least one schema in `list`. */
|
|
1546
|
+
union<const X>(list: readonly X[]): Schema<TypeS<X>, TypeT<X>>;
|
|
1547
|
+
/** Accept values matching every schema in `list`, merging object outputs. */
|
|
1548
|
+
intersect<const X>(list: readonly X[]): Schema<IntersectS<X>, IntersectT<X>>;
|
|
1549
|
+
/** Validate with `inner`, then convert the result with `callback`. */
|
|
1550
|
+
transform<X, T>(inner: X, callback: (value: TypeS<X>, options: Schemastery.Options) => T, preserve?: boolean): Schema<TypeS<X>, T>;
|
|
1551
|
+
/** Defer construction of a recursive schema until validation or serialization. */
|
|
1552
|
+
lazy<X extends Schema>(callback: () => X): X;
|
|
1553
|
+
ValidationError: typeof ValidationError;
|
|
1554
|
+
}
|
|
1555
|
+
/** Runtime validation options shared by all schema calls. */
|
|
1556
|
+
interface Options {
|
|
1557
|
+
/** Remove invalid object properties instead of throwing when possible. */
|
|
1558
|
+
autofix?: boolean;
|
|
1559
|
+
/** Skip validation for selected values and schema nodes. */
|
|
1560
|
+
ignore?(data: any, schema: Schema): boolean;
|
|
1561
|
+
/** Path used to format nested validation errors. */
|
|
1562
|
+
path?: (keyof any)[];
|
|
1563
|
+
}
|
|
1564
|
+
/** UI and validation metadata attached by schema builder methods. */
|
|
1565
|
+
interface Meta<T = any> {
|
|
1566
|
+
default?: T extends {} ? Partial<T> : T;
|
|
1567
|
+
required?: boolean;
|
|
1568
|
+
disabled?: boolean;
|
|
1569
|
+
collapse?: boolean;
|
|
1570
|
+
badges?: {
|
|
1571
|
+
text: string;
|
|
1572
|
+
type: string;
|
|
1573
|
+
}[];
|
|
1574
|
+
hidden?: boolean;
|
|
1575
|
+
loose?: boolean;
|
|
1576
|
+
role?: string;
|
|
1577
|
+
extra?: any;
|
|
1578
|
+
link?: string;
|
|
1579
|
+
description?: string | Dict<string>;
|
|
1580
|
+
comment?: string;
|
|
1581
|
+
pattern?: {
|
|
1582
|
+
source: string;
|
|
1583
|
+
flags?: string;
|
|
1584
|
+
};
|
|
1585
|
+
max?: number;
|
|
1586
|
+
min?: number;
|
|
1587
|
+
step?: number;
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
/** Callable schema instance that validates input and returns normalized output. */
|
|
1591
|
+
interface Schemastery<S = any, T = S> {
|
|
1592
|
+
(data?: S | null, options?: Schemastery.Options): T;
|
|
1593
|
+
new (data?: S | null, options?: Schemastery.Options): T;
|
|
1594
|
+
[kSchema]: true;
|
|
1595
|
+
uid: number;
|
|
1596
|
+
meta: Schemastery.Meta<T>;
|
|
1597
|
+
type: string;
|
|
1598
|
+
sKey?: Schema;
|
|
1599
|
+
inner?: Schema;
|
|
1600
|
+
list?: Schema[];
|
|
1601
|
+
dict?: Dict<Schema>;
|
|
1602
|
+
bits?: Dict<number>;
|
|
1603
|
+
callback?: Function;
|
|
1604
|
+
constructor?: string | Function;
|
|
1605
|
+
builder?: Function;
|
|
1606
|
+
value?: T;
|
|
1607
|
+
refs?: Dict<Schema>;
|
|
1608
|
+
preserve?: boolean;
|
|
1609
|
+
'~standard': StandardSchemaV1.Props;
|
|
1610
|
+
/** Format this schema as a compact TypeScript-like type string. */
|
|
1611
|
+
toString(inline?: boolean): string;
|
|
1612
|
+
/** Serialize this schema, preserving shared and recursive references. */
|
|
1613
|
+
toJSON(): Schema<S, T>;
|
|
1614
|
+
/** Mark nullable input as invalid unless a default supplies a fallback. */
|
|
1615
|
+
required(value?: boolean): Schema<S, T>;
|
|
1616
|
+
/** Hide this schema node from UI renderers. */
|
|
1617
|
+
hidden(value?: boolean): Schema<S, T>;
|
|
1618
|
+
/** Return the default value instead of throwing when validation fails. */
|
|
1619
|
+
loose(value?: boolean): Schema<S, T>;
|
|
1620
|
+
/** Attach a renderer role and optional role-specific metadata. */
|
|
1621
|
+
role(text: string, extra?: any): Schema<S, T>;
|
|
1622
|
+
/** Attach an external documentation link. */
|
|
1623
|
+
link(link: string): Schema<S, T>;
|
|
1624
|
+
/** Set the fallback value used for nullable input. */
|
|
1625
|
+
default(value: T): Schema<S, T>;
|
|
1626
|
+
/** Attach an auxiliary comment for documentation or form UIs. */
|
|
1627
|
+
comment(text: string): Schema<S, T>;
|
|
1628
|
+
/** Attach a localized or plain description for documentation or form UIs. */
|
|
1629
|
+
description(text: string): Schema<S, T>;
|
|
1630
|
+
/** Mark this schema node as disabled for form UIs. */
|
|
1631
|
+
disabled(value?: boolean): Schema<S, T>;
|
|
1632
|
+
/** Request collapsed rendering for nested form UIs. */
|
|
1633
|
+
collapse(value?: boolean): Schema<S, T>;
|
|
1634
|
+
/** Add a deprecated badge to this schema node. */
|
|
1635
|
+
deprecated(): Schema<S, T>;
|
|
1636
|
+
/** Add an experimental badge to this schema node. */
|
|
1637
|
+
experimental(): Schema<S, T>;
|
|
1638
|
+
/** Require strings to match a regular expression. */
|
|
1639
|
+
pattern(regexp: RegExp): Schema<S, T>;
|
|
1640
|
+
/** Set an inclusive maximum for numbers or collection lengths. */
|
|
1641
|
+
max(value: number): Schema<S, T>;
|
|
1642
|
+
/** Set an inclusive minimum for numbers or collection lengths. */
|
|
1643
|
+
min(value: number): Schema<S, T>;
|
|
1644
|
+
/** Set the numeric increment constraint. */
|
|
1645
|
+
step(value: number): Schema<S, T>;
|
|
1646
|
+
/** Add or replace an object property schema. */
|
|
1647
|
+
set(key: string, value: Schema): Schema<S, T>;
|
|
1648
|
+
/** Append a tuple, union, or intersection member schema. */
|
|
1649
|
+
push(value: Schema): Schema<S, T>;
|
|
1650
|
+
/** Remove values equal to schema defaults from normalized output. */
|
|
1651
|
+
simplify(value?: any): any;
|
|
1652
|
+
/** Return a schema clone with descriptions merged from locale messages. */
|
|
1653
|
+
i18n(messages: Dict): Schema<S, T>;
|
|
1654
|
+
/** Attach arbitrary metadata consumed by form renderers and downstream tools. */
|
|
1655
|
+
extra<K extends keyof Schemastery.Meta>(key: K, value: Schemastery.Meta[K]): Schema<S, T>;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
declare class ValidationError extends TypeError {
|
|
1659
|
+
options: Schemastery.Options;
|
|
1660
|
+
name: string;
|
|
1661
|
+
constructor(message: string, options: Schemastery.Options);
|
|
1662
|
+
static is(error: any): error is ValidationError;
|
|
1663
|
+
}
|
|
1664
|
+
type Schema<S = any, T = S> = Schemastery<S, T>;
|
|
1665
|
+
declare const Schema: Schemastery.Static;
|
|
1666
|
+
//#endregion
|
|
1667
|
+
//#region ../../../vendor/deepseek-harness/packages/llm/llm/lib/types/retry-policy.d.ts
|
|
1668
|
+
/** Fully resolved backoff shared by both retry modes. */
|
|
1669
|
+
interface ResolvedRetryBackoff {
|
|
1670
|
+
readonly initialDelayMs: number;
|
|
1671
|
+
readonly maxDelayMs: number;
|
|
1672
|
+
readonly jitterRatio: number;
|
|
1673
|
+
}
|
|
1674
|
+
/** Fully resolved bounded transient retry policy. */
|
|
1675
|
+
interface ResolvedNormalRetryPolicy extends ResolvedRetryBackoff {
|
|
1676
|
+
readonly mode: 'normal';
|
|
1677
|
+
readonly maxRetries: number;
|
|
1678
|
+
readonly retryableCodes: readonly string[];
|
|
1679
|
+
}
|
|
1680
|
+
/** Fully resolved unbounded retry policy. */
|
|
1681
|
+
interface ResolvedAlwaysRetryPolicy extends ResolvedRetryBackoff {
|
|
1682
|
+
readonly mode: 'always';
|
|
1683
|
+
}
|
|
1684
|
+
/** Immutable provider policy captured when its adapter route is registered. */
|
|
1685
|
+
type ResolvedRetryPolicy = ResolvedNormalRetryPolicy | ResolvedAlwaysRetryPolicy;
|
|
1686
|
+
//#endregion
|
|
1687
|
+
//#region ../../../vendor/deepseek-harness/packages/llm/llm/lib/types/call-config.d.ts
|
|
1688
|
+
/**
|
|
1689
|
+
* Provider, model, reasoning effort, and sampling scalars of one conversation's
|
|
1690
|
+
* requests. Every field maps 1:1 onto the same-named `GenerateOptions` field;
|
|
1691
|
+
* the loop builds requests from the logged header rather than accepting these
|
|
1692
|
+
* per call.
|
|
1693
|
+
*/
|
|
1694
|
+
interface LlmCallConfig {
|
|
1695
|
+
provider: string;
|
|
1696
|
+
model: string;
|
|
1697
|
+
reasoningEffort?: ReasoningEffortId;
|
|
1698
|
+
temperature?: number;
|
|
1699
|
+
maxTokens?: number;
|
|
1700
|
+
stop?: string[];
|
|
1701
|
+
}
|
|
1702
|
+
/**
|
|
1703
|
+
* Effective config fields supplied by exact-model adapter resolution rather
|
|
1704
|
+
* than by the caller's request proposal.
|
|
1705
|
+
*/
|
|
1706
|
+
interface LlmCallConfigAdapterDefaults {
|
|
1707
|
+
reasoningEffort?: true;
|
|
1708
|
+
maxTokens?: true;
|
|
1709
|
+
}
|
|
1710
|
+
//#endregion
|
|
1711
|
+
//#region ../../../vendor/deepseek-harness/packages/llm/llm/lib/types/assistant-stream.d.ts
|
|
1712
|
+
/** Lossless compact records embedded in durable Assistant attempt events. */
|
|
1713
|
+
type AssistantStreamRecord = {
|
|
1714
|
+
readonly type: 'text-chunks';
|
|
1715
|
+
readonly time0: number;
|
|
1716
|
+
readonly index: number;
|
|
1717
|
+
readonly dt: readonly number[];
|
|
1718
|
+
readonly texts: readonly string[];
|
|
1719
|
+
} | {
|
|
1720
|
+
readonly type: 'reasoning-chunks';
|
|
1721
|
+
readonly time0: number;
|
|
1722
|
+
readonly index: number;
|
|
1723
|
+
readonly dt: readonly number[];
|
|
1724
|
+
readonly texts: readonly string[];
|
|
1725
|
+
} | {
|
|
1726
|
+
readonly type: 'tool-call-chunks';
|
|
1727
|
+
readonly time0: number;
|
|
1728
|
+
readonly index: number;
|
|
1729
|
+
readonly dt: readonly number[];
|
|
1730
|
+
readonly id: ToolCallId;
|
|
1731
|
+
readonly name?: string;
|
|
1732
|
+
readonly args: readonly string[];
|
|
1733
|
+
} | {
|
|
1734
|
+
readonly type: 'chunk';
|
|
1735
|
+
readonly time: number;
|
|
1736
|
+
readonly chunk: StreamChunk;
|
|
1737
|
+
};
|
|
1738
|
+
//#endregion
|
|
1739
|
+
//#region ../../../vendor/deepseek-harness/packages/llm/llm/lib/types/index.d.ts
|
|
1740
|
+
declare module '@deepseek-ai/cordis' {
|
|
1741
|
+
interface Context {
|
|
1742
|
+
llm: LlmRuntime;
|
|
1743
|
+
}
|
|
1744
|
+
interface Events {
|
|
1745
|
+
/**
|
|
1746
|
+
* Waterfall around every streaming model call (retry, replay, routing).
|
|
1747
|
+
* Bound to the {@link LlmRuntime}; call `next()` to reach the resolved
|
|
1748
|
+
* adapter's stream, or yield your own chunks to short-circuit.
|
|
1749
|
+
* @param options - the full request. A LOOP-built request carries the
|
|
1750
|
+
* process-local {@link markAgentLoopRequest} identity and arrives deep-frozen
|
|
1751
|
+
* (mutation throws): its content is a pure function of the session log (the
|
|
1752
|
+
* reconstructability Agent Note), so listeners read it, never rewrite it.
|
|
1753
|
+
* Hand-built calls do not carry that marker; their messages already obey
|
|
1754
|
+
* the immutable creation contract.
|
|
1755
|
+
* @mode waterfall
|
|
1756
|
+
*/
|
|
1757
|
+
'llm/stream'(this: LlmRuntime, options: GenerateOptions, next: () => AsyncIterable<StreamChunk>): AsyncIterable<StreamChunk>;
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
/** One model call whose config and adapter registration were resolved together. */
|
|
1761
|
+
interface PreparedLlmCall {
|
|
1762
|
+
/** Detached, deep-frozen config with any adapter-owned default materialized. */
|
|
1763
|
+
readonly config: LlmCallConfig;
|
|
1764
|
+
/** Immutable retry policy captured with the adapter registration. */
|
|
1765
|
+
readonly retryPolicy: ResolvedRetryPolicy;
|
|
1766
|
+
/** Detached context metadata resolved with the registration-bound call. */
|
|
1767
|
+
readonly context?: LlmModelContext;
|
|
1768
|
+
/** Exact model modalities captured with the adapter dispatch generation. */
|
|
1769
|
+
readonly inputModalities?: readonly ModelModality[];
|
|
1770
|
+
/** Exact model system prompt update mode captured with the adapter dispatch generation. */
|
|
1771
|
+
readonly systemPromptUpdate?: SystemPromptUpdate;
|
|
1772
|
+
/** Config fields materialized by the captured adapter rather than proposed by the caller. */
|
|
1773
|
+
readonly adapterDefaults: LlmCallConfigAdapterDefaults;
|
|
1774
|
+
/**
|
|
1775
|
+
* Dispatch this call once through the registration captured during
|
|
1776
|
+
* preparation. The request's call-config fields must match {@link config};
|
|
1777
|
+
* reuse or mismatch fails with `INVALID_PREPARED_CALL`.
|
|
1778
|
+
* @param options - fully assembled request carrying the prepared config.
|
|
1779
|
+
* @returns the chunk stream, including the `llm/stream` waterfall.
|
|
1780
|
+
*/
|
|
1781
|
+
stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
1782
|
+
}
|
|
1783
|
+
/** One adapter-owned model-resolution generation bound to its eventual stream call. */
|
|
1784
|
+
interface PreparedAdapterCall {
|
|
1785
|
+
/** Exact model metadata from the same adapter generation as {@link stream}. */
|
|
1786
|
+
readonly model: LlmResolvedModelInfo;
|
|
1787
|
+
/** Dispatch through that generation without re-reading dynamic connection facts. */
|
|
1788
|
+
stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
1789
|
+
}
|
|
1790
|
+
/**
|
|
1791
|
+
* Provider-wire adapter for the harness message and stream vocabulary. Register implementations
|
|
1792
|
+
* with `ctx.llm.registerAdapter(providers, adapter)`. Every provider HTTP request must include
|
|
1793
|
+
* `attributionHeaders()`; prove the headers are added in the wire request or library header hook. The direct-fetch
|
|
1794
|
+
* DeepSeek and library-backed pi-ai adapters meet this contract through different internals.
|
|
1795
|
+
*/
|
|
1796
|
+
declare abstract class LlmAdapter {
|
|
1797
|
+
/**
|
|
1798
|
+
* Describe one provider route owned by this adapter.
|
|
1799
|
+
* @param provider - a route passed to `registerAdapter()` for this instance.
|
|
1800
|
+
* @returns detached display metadata whose id must equal `provider`.
|
|
1801
|
+
*/
|
|
1802
|
+
providerInfo(provider: string): LlmProviderInfo;
|
|
1803
|
+
/**
|
|
1804
|
+
* Return the provider-owned retry policy captured with this route.
|
|
1805
|
+
* @param _provider - a route passed to `registerAdapter()` for this instance.
|
|
1806
|
+
* @returns a resolved policy, or `undefined` to use the normal defaults.
|
|
1807
|
+
*/
|
|
1808
|
+
providerRetryPolicy(_provider: string): ResolvedRetryPolicy | undefined;
|
|
1809
|
+
/**
|
|
1810
|
+
* Resolve provider-side request-image pricing for one exact model route.
|
|
1811
|
+
* The default declares none, so consumers fall back to their own neutral
|
|
1812
|
+
* estimate. Implementations must answer synchronously without I/O; the
|
|
1813
|
+
* token meter resolves this per measurement.
|
|
1814
|
+
* @param _provider - a route passed to `registerAdapter()` for this instance.
|
|
1815
|
+
* @param _model - exact model id passed to {@link GenerateOptions.model}.
|
|
1816
|
+
* @returns route-owned image pricing, or `undefined` when the route declares none.
|
|
1817
|
+
*/
|
|
1818
|
+
imageRequestPricing(_provider: string, _model: string): LlmImageRequestPricing | undefined;
|
|
1819
|
+
/**
|
|
1820
|
+
* List models this adapter can currently advertise for one owned provider.
|
|
1821
|
+
* The result is advisory: an adapter may accept unlisted model ids, and
|
|
1822
|
+
* consumers must not turn absence into request rejection.
|
|
1823
|
+
* @param _provider - one provider route owned by this adapter.
|
|
1824
|
+
* @returns discoverable models in adapter-preferred order.
|
|
1825
|
+
*/
|
|
1826
|
+
listModels(_provider: string): Promise<readonly LlmModelInfo[]>;
|
|
1827
|
+
/**
|
|
1828
|
+
* Resolve all metadata available for one exact model. This query is
|
|
1829
|
+
* independent of the advisory catalog and does not validate request routing.
|
|
1830
|
+
* @param provider - one provider route owned by this adapter.
|
|
1831
|
+
* @param model - exact model id passed to {@link GenerateOptions.model}.
|
|
1832
|
+
* @param _signal - cancellation for this exact-model lookup; asynchronous
|
|
1833
|
+
* implementations must settle promptly after it aborts.
|
|
1834
|
+
* @returns provider/model identity plus any context, call-default, and reasoning metadata.
|
|
1835
|
+
*/
|
|
1836
|
+
resolveModel(provider: string, model: string, _signal?: AbortSignal): Promise<LlmResolvedModelInfo>;
|
|
1837
|
+
/**
|
|
1838
|
+
* Bind exact model metadata and the eventual request dispatch to one adapter generation.
|
|
1839
|
+
* Dynamic adapters override this so settings changes between preparation and
|
|
1840
|
+
* dispatch cannot combine one generation's capabilities with another's endpoint.
|
|
1841
|
+
* @param provider - registered provider route.
|
|
1842
|
+
* @param model - exact model id.
|
|
1843
|
+
* @param signal - cancellation for model resolution.
|
|
1844
|
+
* @returns model metadata and a one-generation stream entry point.
|
|
1845
|
+
*/
|
|
1846
|
+
prepareCall(provider: string, model: string, signal?: AbortSignal): Promise<PreparedAdapterCall>;
|
|
1847
|
+
/**
|
|
1848
|
+
* Stream one model call as raw chunks. The only required method.
|
|
1849
|
+
* @param options - the fully-assembled request; implementations must honor `options.signal`.
|
|
1850
|
+
* @returns the chunk stream, obeying the adapter contract documented on `StreamChunk`.
|
|
1851
|
+
*/
|
|
1852
|
+
abstract stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* What {@link LlmRuntime.registerAdapter} returns: the disposer, plus an
|
|
1856
|
+
* atomic route replacement for the same adapter instance.
|
|
1857
|
+
*/
|
|
1858
|
+
interface AdapterRegistrationHandle {
|
|
1859
|
+
/** Release every route this registration currently holds. */
|
|
1860
|
+
(): void;
|
|
1861
|
+
/**
|
|
1862
|
+
* Replace this registration's routes with `providers`, keeping the same
|
|
1863
|
+
* adapter instance. The candidate set is validated in full first — a
|
|
1864
|
+
* conflict with another adapter, an invalid name, or bad provider metadata
|
|
1865
|
+
* throws and leaves the current routes untouched — and the swap itself is
|
|
1866
|
+
* one synchronous section, so no request can observe a gap. An empty array
|
|
1867
|
+
* is legal here (a settings section that emptied holds zero routes while
|
|
1868
|
+
* staying registered), unlike an empty initial registration.
|
|
1869
|
+
*
|
|
1870
|
+
* Throws `LlmError` with code `REGISTRATION_DISPOSED` once the registration
|
|
1871
|
+
* has been released: its routes are gone and its disposer has already run,
|
|
1872
|
+
* so anything registered afterwards would have no owner left to release it.
|
|
1873
|
+
* @param providers - the complete next route set for this registration.
|
|
1874
|
+
*/
|
|
1875
|
+
replace(providers: string[]): void;
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
* A live configurable-provider registration, disposable and atomically
|
|
1879
|
+
* replaceable — the directory counterpart of {@link AdapterRegistrationHandle}.
|
|
1880
|
+
*/
|
|
1881
|
+
interface DirectoryRegistrationHandle {
|
|
1882
|
+
/** Withdraw every entry this registration currently holds. */
|
|
1883
|
+
(): void;
|
|
1884
|
+
/**
|
|
1885
|
+
* Replace this registration's entries with `entries`. The candidate set is
|
|
1886
|
+
* validated in full first — an entry another registration already declares,
|
|
1887
|
+
* a duplicate within the set, or invalid metadata throws and leaves the
|
|
1888
|
+
* current entries untouched — and the swap is one synchronous section, so no
|
|
1889
|
+
* reader observes a gap. An empty array is legal here, unlike an empty
|
|
1890
|
+
* initial registration.
|
|
1891
|
+
*
|
|
1892
|
+
* Throws `LlmError` with code `REGISTRATION_DISPOSED` once the registration
|
|
1893
|
+
* has been disposed.
|
|
1894
|
+
*/
|
|
1895
|
+
replace(entries: readonly LlmConfigurableProvider[]): void;
|
|
1896
|
+
}
|
|
1897
|
+
/**
|
|
1898
|
+
* The abstract `llm` service: an adapter registry plus a streaming model-call
|
|
1899
|
+
* API, interceptable via the `llm/stream` waterfall.
|
|
1900
|
+
*/
|
|
1901
|
+
declare class LlmRuntime extends TypertRemoteService {
|
|
1902
|
+
private adapters;
|
|
1903
|
+
private directory;
|
|
1904
|
+
private discoveries;
|
|
1905
|
+
constructor(ctx: Context);
|
|
1906
|
+
/** Notify topology observers without letting one broken listener veto the commit. */
|
|
1907
|
+
private emitAdaptersUpdated;
|
|
1908
|
+
/** Contained-listener diagnostic shared by the sync and async failure paths. */
|
|
1909
|
+
private warnAdaptersListenerFailure;
|
|
1910
|
+
/**
|
|
1911
|
+
* Register an adapter for the given provider routes. Throws `LlmError` with code
|
|
1912
|
+
* `DUPLICATE_ADAPTER` if any provider already has an adapter (all-or-nothing).
|
|
1913
|
+
* Disposed with the fiber.
|
|
1914
|
+
* @param providers - every provider route this adapter should serve.
|
|
1915
|
+
* @param adapter - the adapter that streams calls for those providers.
|
|
1916
|
+
* @returns the disposer, carrying {@link AdapterRegistrationHandle.replace}.
|
|
1917
|
+
*/
|
|
1918
|
+
registerAdapter(providers: string[], adapter: LlmAdapter): AdapterRegistrationHandle;
|
|
1919
|
+
/**
|
|
1920
|
+
* Validate one candidate route set for `adapter`, treating routes this
|
|
1921
|
+
* registration already holds as available. Nothing is mutated: a rejected
|
|
1922
|
+
* candidate leaves the registry exactly as it was.
|
|
1923
|
+
*/
|
|
1924
|
+
private prepareRoutes;
|
|
1925
|
+
/**
|
|
1926
|
+
* Swap this registration's routes for the prepared ones in one synchronous
|
|
1927
|
+
* section, so no observer can see the registry between the release and the
|
|
1928
|
+
* re-registration. The route set's one mutation point is also where
|
|
1929
|
+
* `llm/adapters-updated` is published, so a `replace` announces itself
|
|
1930
|
+
* exactly like a first registration.
|
|
1931
|
+
*/
|
|
1932
|
+
private commitRoutes;
|
|
1933
|
+
/**
|
|
1934
|
+
* Describe provider routes with a registered adapter.
|
|
1935
|
+
* @returns detached provider metadata in registration order.
|
|
1936
|
+
*/
|
|
1937
|
+
listProviders(): LlmProviderInfo[];
|
|
1938
|
+
/**
|
|
1939
|
+
* Declare provider routes an adapter plugin can activate through
|
|
1940
|
+
* configuration. Registration is all-or-nothing: an empty list, invalid
|
|
1941
|
+
* entry, or a provider already declared by any registration throws
|
|
1942
|
+
* `LlmError` without registering the rest. Disposed with the fiber.
|
|
1943
|
+
* @param entries - every configurable provider this plugin owns.
|
|
1944
|
+
* @returns a handle that withdraws all of them, and can atomically replace them.
|
|
1945
|
+
*/
|
|
1946
|
+
registerConfigurableProviders(entries: readonly LlmConfigurableProvider[]): DirectoryRegistrationHandle;
|
|
1947
|
+
/**
|
|
1948
|
+
* List every declared configurable provider, registered or dormant.
|
|
1949
|
+
* @returns detached directory entries in declaration order.
|
|
1950
|
+
*/
|
|
1951
|
+
listConfigurableProviders(): LlmConfigurableProvider[];
|
|
1952
|
+
/**
|
|
1953
|
+
* Offer to interrogate provider endpoints on behalf of the settings
|
|
1954
|
+
* namespace this plugin owns. The namespace is the key because that is what
|
|
1955
|
+
* a configuration surface already holds from the configurable-provider
|
|
1956
|
+
* directory, and because a provider being *added* has no route to name yet.
|
|
1957
|
+
* Disposed with the fiber.
|
|
1958
|
+
* @param settingsNs - the namespace whose profiles this discovery serves.
|
|
1959
|
+
* @param discover - interrogates one endpoint and must honor the supplied signal.
|
|
1960
|
+
* @returns the disposer that withdraws the offer.
|
|
1961
|
+
*/
|
|
1962
|
+
registerModelDiscovery(settingsNs: string, discover: (request: LlmModelDiscoveryRequest, signal?: AbortSignal) => Promise<readonly LlmDiscoveredModel[]>): () => void;
|
|
1963
|
+
/**
|
|
1964
|
+
* Interrogate one provider endpoint for the models it advertises. The
|
|
1965
|
+
* request describes a draft, not a stored route, so nothing here reads or
|
|
1966
|
+
* writes settings or credentials — the caller owns both, and the reply is
|
|
1967
|
+
* candidate metadata a surface may offer for adoption.
|
|
1968
|
+
* @param settingsNs - namespace whose registered discovery serves this draft.
|
|
1969
|
+
* @param request - the endpoint, protocol, and one-shot credential to use.
|
|
1970
|
+
* @param signal - caller cancellation.
|
|
1971
|
+
* @returns the advertised models, deduplicated in endpoint order.
|
|
1972
|
+
*/
|
|
1973
|
+
discoverModels(settingsNs: string, request: LlmModelDiscoveryRequest, signal?: AbortSignal): Promise<LlmDiscoveredModel[]>;
|
|
1974
|
+
/**
|
|
1975
|
+
* Remote adapter for one draft provider interrogation.
|
|
1976
|
+
* @param settingsNs - namespace whose registered discovery serves this draft.
|
|
1977
|
+
* @param request - endpoint, protocol, and one-shot credential to use.
|
|
1978
|
+
* @param signal - caller cancellation supplied by the Remote carrier.
|
|
1979
|
+
* @returns advertised models in endpoint order.
|
|
1980
|
+
* @throws RemoteError with `llm/model-discovery-rejected` when discovery refuses or fails.
|
|
1981
|
+
*/
|
|
1982
|
+
remoteDiscoverModels(settingsNs: string, request: LlmModelDiscoveryRequest, signal: AbortSignal): Promise<LlmDiscoveredModel[]>;
|
|
1983
|
+
/**
|
|
1984
|
+
* Resolve the retry policy captured when one provider route was registered.
|
|
1985
|
+
* @param provider - registered provider route to inspect.
|
|
1986
|
+
* @returns the provider-owned policy, with normal defaults already resolved.
|
|
1987
|
+
*/
|
|
1988
|
+
providerRetryPolicy(provider: string): ResolvedRetryPolicy;
|
|
1989
|
+
/**
|
|
1990
|
+
* Resolve provider-side request-image pricing for one exact route, or
|
|
1991
|
+
* `undefined` when the provider is unregistered or declares none. Unknown
|
|
1992
|
+
* providers degrade to `undefined` rather than throwing because callers
|
|
1993
|
+
* price durable history whose route may no longer be mounted.
|
|
1994
|
+
* @param provider - provider route named by a request header.
|
|
1995
|
+
* @param model - exact model id named by the same header.
|
|
1996
|
+
* @returns the owning adapter's image pricing for the route, when declared.
|
|
1997
|
+
*/
|
|
1998
|
+
imageRequestPricing(provider: string, model: string): LlmImageRequestPricing | undefined;
|
|
1999
|
+
/**
|
|
2000
|
+
* Resolve the exact text one durable file occurrence contributes to every
|
|
2001
|
+
* provider request in the current execution environment.
|
|
2002
|
+
* @param ref - durable verbatim file reference from model history.
|
|
2003
|
+
* @returns the same deterministic handle text used at adapter dispatch.
|
|
2004
|
+
*/
|
|
2005
|
+
fileRequestText(ref: FileAttachmentRef): string;
|
|
2006
|
+
/** Detach typed adapter-owned modality metadata. */
|
|
2007
|
+
private detachedModalities;
|
|
2008
|
+
/**
|
|
2009
|
+
* Discover models advertised by one registered provider. Catalog membership
|
|
2010
|
+
* is advisory and never changes routing or request validation.
|
|
2011
|
+
* @param provider - registered provider route to inspect.
|
|
2012
|
+
* @returns detached model metadata in adapter-preferred order.
|
|
2013
|
+
*/
|
|
2014
|
+
listModels(provider: string): Promise<LlmModelInfo[]>;
|
|
2015
|
+
/**
|
|
2016
|
+
* Resolve and validate all metadata from the adapter that owns one exact
|
|
2017
|
+
* route. The result is detached from adapter-owned objects; catalog
|
|
2018
|
+
* membership remains advisory and does not control request routing.
|
|
2019
|
+
* @param provider - registered provider route to inspect.
|
|
2020
|
+
* @param model - exact model id passed to the adapter.
|
|
2021
|
+
* @param signal - optional cancellation for adapter-owned asynchronous lookup.
|
|
2022
|
+
* @returns exact model identity plus available context and reasoning metadata.
|
|
2023
|
+
*/
|
|
2024
|
+
resolveModelInfo(provider: string, model: string, signal?: AbortSignal): Promise<LlmResolvedModelInfo>;
|
|
2025
|
+
private resolveModelInfoFor;
|
|
2026
|
+
/** Validate and detach one adapter-returned exact model result. */
|
|
2027
|
+
private normalizeModelInfo;
|
|
2028
|
+
/**
|
|
2029
|
+
* Validate a conversation call config against its exact model capability and
|
|
2030
|
+
* materialize adapter-configured defaults. Unsupported explicit efforts
|
|
2031
|
+
* reject before provider I/O; no clamping or aliasing is performed. This
|
|
2032
|
+
* standalone query does not bind a later dispatch; use {@link prepareCall}
|
|
2033
|
+
* when logging and streaming must share one adapter registration.
|
|
2034
|
+
* @param config - provider/model route and optional request controls.
|
|
2035
|
+
* @param signal - optional cancellation for adapter-owned capability lookup.
|
|
2036
|
+
* @returns a detached config only when a default must be materialized.
|
|
2037
|
+
*/
|
|
2038
|
+
resolveCallConfig(config: LlmCallConfig, signal?: AbortSignal): Promise<LlmCallConfig>;
|
|
2039
|
+
private resolveCallFor;
|
|
2040
|
+
/** Validate request controls against one already-bound exact model result. */
|
|
2041
|
+
private resolveCallWithInfo;
|
|
2042
|
+
/**
|
|
2043
|
+
* Resolve one call under its current adapter registration. The returned
|
|
2044
|
+
* one-shot handle keeps that registration across header logging and dispatch,
|
|
2045
|
+
* so HMR cannot combine one adapter's capability result with another adapter.
|
|
2046
|
+
* @param config - provider/model route and optional request controls.
|
|
2047
|
+
* @param signal - optional cancellation for adapter-owned capability lookup.
|
|
2048
|
+
* @returns a prepared config and its registration-bound stream entry point.
|
|
2049
|
+
*/
|
|
2050
|
+
prepareCall(config: LlmCallConfig, signal?: AbortSignal): Promise<PreparedLlmCall>;
|
|
2051
|
+
private registration;
|
|
2052
|
+
/** Remove replay state whose historical route is owned by another adapter. */
|
|
2053
|
+
private forAdapter;
|
|
2054
|
+
/**
|
|
2055
|
+
* Resolve the current execution-world read path of one durable file
|
|
2056
|
+
* reference through the mounted attachment and filesystem providers.
|
|
2057
|
+
*/
|
|
2058
|
+
private fileReadPath;
|
|
2059
|
+
/**
|
|
2060
|
+
* Final adapter boundary. Adapter selection, dispatch, iterator construction,
|
|
2061
|
+
* and iteration failures become one terminal failure chunk. Middleware and
|
|
2062
|
+
* downstream consumer failures remain thrown plugin or consumer errors.
|
|
2063
|
+
*/
|
|
2064
|
+
private adapterStream;
|
|
2065
|
+
/**
|
|
2066
|
+
* Stream one model call as raw chunks (token-level deltas). Replay state is
|
|
2067
|
+
* retained only when the same adapter instance owns its historical provider
|
|
2068
|
+
* and the target provider. Final adapter selection remains fixed through
|
|
2069
|
+
* asynchronous exact-model resolution and dispatch. Adapter selection,
|
|
2070
|
+
* dispatch, and iteration failures become terminal `error` or `aborted`
|
|
2071
|
+
* finish chunks; middleware, nested-call, cleanup, and consumer failures
|
|
2072
|
+
* remain thrown.
|
|
2073
|
+
* @param options - the full request; `options.provider` selects the adapter.
|
|
2074
|
+
* @returns the chunk stream, possibly wrapped by `llm/stream` listeners.
|
|
2075
|
+
*/
|
|
2076
|
+
stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
2077
|
+
private streamWithRegistration;
|
|
2078
|
+
}
|
|
2079
|
+
//#endregion
|
|
2080
|
+
//#region ../../../vendor/deepseek-harness/packages/util/values/lib/types/index.d.ts
|
|
2081
|
+
/** Duplicate-install-safe JSON and immutable-value helpers. @module @deepseek-ai/dsh-util-values */
|
|
2082
|
+
/** A value that round-trips through JSON without loss. */
|
|
2083
|
+
type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
2084
|
+
[key: string]: JsonValue;
|
|
2085
|
+
};
|
|
2086
|
+
//#endregion
|
|
2087
|
+
//#region ../../../vendor/deepseek-harness/packages/core/session/lib/types/types.d.ts
|
|
2088
|
+
/** Identifies one session in the store (and its persistence artifacts). */
|
|
2089
|
+
type SessionId = Branded<'SessionId'>;
|
|
2090
|
+
/**
|
|
2091
|
+
* Brand a string as a {@link SessionId}.
|
|
2092
|
+
* @param id - the raw session id string.
|
|
2093
|
+
* @returns the same string with the session-id brand.
|
|
2094
|
+
*/
|
|
2095
|
+
declare function SessionId(id: string): SessionId;
|
|
2096
|
+
/** Sequence number of one existing event in a Session log. */
|
|
2097
|
+
type SessionSeq = BrandedNumber<'SessionSeq'>;
|
|
2098
|
+
/**
|
|
2099
|
+
* Admit a numeric value as an existing Session event position.
|
|
2100
|
+
* @param value - non-negative safe integer admitted by the owning log operation.
|
|
2101
|
+
* @returns the same number with the Session-sequence brand.
|
|
2102
|
+
*/
|
|
2103
|
+
declare function SessionSeq(value: number): SessionSeq;
|
|
2104
|
+
/** A Session log gap, prefix length, or read offset, which may equal the event count. */
|
|
2105
|
+
type SessionLogOffset = BrandedNumber<'SessionLogOffset'>;
|
|
2106
|
+
/**
|
|
2107
|
+
* Admit a numeric value as a Session log offset.
|
|
2108
|
+
* @param value - non-negative safe integer used as a gap or prefix length.
|
|
2109
|
+
* @returns the same number with the Session-log-offset brand.
|
|
2110
|
+
*/
|
|
2111
|
+
declare function SessionLogOffset(value: number): SessionLogOffset;
|
|
2112
|
+
/**
|
|
2113
|
+
* Current logical Session format version, stamped into every newly written
|
|
2114
|
+
* {@link SessionHeader}. Current Session and persistence code accept only this
|
|
2115
|
+
* value; header-only readers classify supported historical formats, while an
|
|
2116
|
+
* event-body read composes the build-static adjacent chain and publishes only
|
|
2117
|
+
* this final generation before constructing a Session.
|
|
2118
|
+
*
|
|
2119
|
+
* The version is a single monotonic integer with no major/minor split. Whether
|
|
2120
|
+
* a bump is needed is decided by what the WRITER emits, never by what a newer
|
|
2121
|
+
* reader can accept: bump exactly when an older runtime could no longer handle
|
|
2122
|
+
* a new log with full semantic correctness ("parses without error" is not
|
|
2123
|
+
* correctness — silently skipping content that shapes reconstruction is a
|
|
2124
|
+
* wrong read). Only structural changes reach that bar: the header shape, the
|
|
2125
|
+
* {@link SessionEvent} envelope, core event semantics, or the surface
|
|
2126
|
+
* mechanism (the {@link SurfaceEventType} set and {@link SurfaceOp} variants).
|
|
2127
|
+
* Adding an ordinary event type does not bump — the per-event
|
|
2128
|
+
* {@link SessionEvent.ignorable} guard covers vocabulary growth instead. When
|
|
2129
|
+
* in doubt, bump: a near-identity upgrade step is almost free, a missed bump
|
|
2130
|
+
* makes older runtimes read new logs wrong silently. The released migration,
|
|
2131
|
+
* immutable prior-generation, and current fast-path rules are recorded in
|
|
2132
|
+
* `.agents/notes/implemented/architecture/2026-08-31-released-session-format-migrations.md`.
|
|
2133
|
+
*/
|
|
2134
|
+
declare const SESSION_FORMAT_VERSION = 3;
|
|
2135
|
+
/**
|
|
2136
|
+
* Immutable validated storage metadata, kept outside the conversation event log.
|
|
2137
|
+
*/
|
|
2138
|
+
interface SessionHeader {
|
|
2139
|
+
/**
|
|
2140
|
+
* Current logical format version, stamped from {@link SESSION_FORMAT_VERSION}.
|
|
2141
|
+
* Historical physical headers are translated before entering this interface.
|
|
2142
|
+
*/
|
|
2143
|
+
readonly version: typeof SESSION_FORMAT_VERSION;
|
|
2144
|
+
/** The session's id (mirrors the {@link Session}'s id). */
|
|
2145
|
+
readonly id: SessionId;
|
|
2146
|
+
/** Non-negative safe-integer Unix epoch milliseconds when the session was created. */
|
|
2147
|
+
readonly createdAt: number;
|
|
2148
|
+
/** Absolute working directory the session was created in (if any). */
|
|
2149
|
+
readonly cwd?: string;
|
|
2150
|
+
/** The session this one was forked from (seed lineage), if any. */
|
|
2151
|
+
readonly parentSession?: SessionId;
|
|
2152
|
+
/**
|
|
2153
|
+
* Whether this Session contains a fork-inherited event prefix. The exact prefix
|
|
2154
|
+
* length is Session state rather than ordinary header metadata.
|
|
2155
|
+
*/
|
|
2156
|
+
readonly isSeeded: boolean;
|
|
2157
|
+
/**
|
|
2158
|
+
* Coarse product classification for a session created as a subagent child.
|
|
2159
|
+
* This is presentation metadata, not proof that the child is continuable.
|
|
2160
|
+
*/
|
|
2161
|
+
readonly origin?: 'subagent';
|
|
2162
|
+
/**
|
|
2163
|
+
* Delegation depth: absent (zero) for a top-level session, parent depth + 1
|
|
2164
|
+
* for a subagent child. Persisted so a recursion budget survives restart and
|
|
2165
|
+
* resume — a runtime-only depth would reset a resumed child to top-level.
|
|
2166
|
+
*/
|
|
2167
|
+
readonly delegationDepth?: number;
|
|
2168
|
+
/**
|
|
2169
|
+
* Id of the agent preset this session's agent was composed from, when the
|
|
2170
|
+
* deployment composes per session. Durable because the preset decides the
|
|
2171
|
+
* session's tools and prompt: a resume that restored a different composition
|
|
2172
|
+
* would replay history the model can no longer act on.
|
|
2173
|
+
*/
|
|
2174
|
+
readonly agentPreset?: string;
|
|
2175
|
+
}
|
|
2176
|
+
/**
|
|
2177
|
+
* Options for creating a {@link Session} via the store. `seed` replays/forks
|
|
2178
|
+
* an existing event log; `meta` carries the caller-supplied storage fields the
|
|
2179
|
+
* store folds into a {@link SessionHeader}.
|
|
2180
|
+
*/
|
|
2181
|
+
interface CreateSessionOptions {
|
|
2182
|
+
/** Initial replay or fork history supplied at construction. */
|
|
2183
|
+
readonly seed?: readonly SessionEvent[];
|
|
2184
|
+
/**
|
|
2185
|
+
* Exact fork-inherited prefix length when `meta.isSeeded` is true. The
|
|
2186
|
+
* constructor seed is exactly this inherited prefix; the constructor
|
|
2187
|
+
* appends the child-owned tagged marker at the cut.
|
|
2188
|
+
*/
|
|
2189
|
+
readonly inheritedEventCount?: SessionLogOffset;
|
|
2190
|
+
/**
|
|
2191
|
+
* Storage metadata read once before publication. `isSeeded` marks fork
|
|
2192
|
+
* lineage; supplying replay history alone does not make it inherited.
|
|
2193
|
+
*/
|
|
2194
|
+
readonly meta?: {
|
|
2195
|
+
readonly cwd?: string;
|
|
2196
|
+
readonly parentSession?: SessionId;
|
|
2197
|
+
readonly createdAt?: number;
|
|
2198
|
+
readonly isSeeded?: boolean;
|
|
2199
|
+
readonly origin?: 'subagent';
|
|
2200
|
+
readonly delegationDepth?: number;
|
|
2201
|
+
readonly agentPreset?: string;
|
|
2202
|
+
};
|
|
2203
|
+
}
|
|
2204
|
+
/**
|
|
2205
|
+
* Aliasing state of an adoptable Session seed. `shared-frozen` permits deeply
|
|
2206
|
+
* frozen aliases plus independently owned unfrozen values in the same seed.
|
|
2207
|
+
*/
|
|
2208
|
+
type SessionSeedEventState = 'detached' | 'shared-frozen';
|
|
2209
|
+
/**
|
|
2210
|
+
* Adoptable storage values transferred to {@link SessionStore.prepare}
|
|
2211
|
+
* without another copy or freeze pass.
|
|
2212
|
+
*/
|
|
2213
|
+
interface RestoredSessionOptions {
|
|
2214
|
+
/** Events that are independently owned or already deeply frozen. */
|
|
2215
|
+
readonly seed: SessionEvent[];
|
|
2216
|
+
/** Independently owned storage metadata to validate and freeze in place. */
|
|
2217
|
+
readonly meta: SessionHeader;
|
|
2218
|
+
/** Exact number of fork-inherited leading events decoded from storage. */
|
|
2219
|
+
readonly inheritedEventCount: SessionLogOffset;
|
|
2220
|
+
/** Aliasing state carried from the operation that produced the seed. */
|
|
2221
|
+
readonly eventState: SessionSeedEventState;
|
|
2222
|
+
}
|
|
2223
|
+
/** Inputs accepted while constructing an unpublished Session. */
|
|
2224
|
+
type PrepareSessionOptions = (CreateSessionOptions & {
|
|
2225
|
+
readonly eventState?: undefined;
|
|
2226
|
+
}) | RestoredSessionOptions;
|
|
2227
|
+
/** Why an active agent driver was cancelled. */
|
|
2228
|
+
type AgentCancelCause = {
|
|
2229
|
+
readonly kind: 'user';
|
|
2230
|
+
} | {
|
|
2231
|
+
readonly kind: 'parent';
|
|
2232
|
+
} | {
|
|
2233
|
+
readonly kind: 'hook';
|
|
2234
|
+
readonly reason: string;
|
|
2235
|
+
} | {
|
|
2236
|
+
readonly kind: 'disposed';
|
|
2237
|
+
};
|
|
2238
|
+
/** Durable cancellation cause, including imports whose original coarse record carried no cause. */
|
|
2239
|
+
type TurnEndCancelCause = AgentCancelCause | {
|
|
2240
|
+
readonly kind: 'legacy';
|
|
2241
|
+
};
|
|
2242
|
+
/**
|
|
2243
|
+
* Why a turn ended. Merge-extensible sum type.
|
|
2244
|
+
*/
|
|
2245
|
+
interface TurnEndReasonMap {
|
|
2246
|
+
completed: {
|
|
2247
|
+
kind: 'completed';
|
|
2248
|
+
};
|
|
2249
|
+
/** A cancellation request interrupted the live turn. */
|
|
2250
|
+
aborted: {
|
|
2251
|
+
kind: 'aborted';
|
|
2252
|
+
reason: TurnEndCancelCause;
|
|
2253
|
+
};
|
|
2254
|
+
blocked: {
|
|
2255
|
+
kind: 'blocked';
|
|
2256
|
+
};
|
|
2257
|
+
/**
|
|
2258
|
+
* The turn failed. `error` is always a structured failure: the `LlmError`
|
|
2259
|
+
* facts verbatim, or `{ message: errorChain(error), code: 'UNKNOWN' }`
|
|
2260
|
+
* flattened from any other error.
|
|
2261
|
+
*/
|
|
2262
|
+
error: {
|
|
2263
|
+
kind: 'error';
|
|
2264
|
+
error: LlmFailure;
|
|
2265
|
+
};
|
|
2266
|
+
/** At least one step reached its output-token ceiling, even if a plugin continued the turn. */
|
|
2267
|
+
'max-tokens': {
|
|
2268
|
+
kind: 'max-tokens';
|
|
2269
|
+
};
|
|
2270
|
+
/**
|
|
2271
|
+
* A crash-orphaned turn was closed after the fact: agent-loop resume appends
|
|
2272
|
+
* this closer for a stored log whose last turn never ended, and session-query
|
|
2273
|
+
* synthesizes it on cold reads. The loop never emits this marker live, and
|
|
2274
|
+
* the events recorded before the crash remain intact.
|
|
2275
|
+
*/
|
|
2276
|
+
interrupted: {
|
|
2277
|
+
kind: 'interrupted';
|
|
2278
|
+
};
|
|
2279
|
+
}
|
|
2280
|
+
/** The union over {@link TurnEndReasonMap} — why a turn ended; plugins extend it by merging variants into the map. */
|
|
2281
|
+
type TurnEndReason = TurnEndReasonMap[keyof TurnEndReasonMap];
|
|
2282
|
+
/**
|
|
2283
|
+
* Logged request state outside derived history: call config and tools. The
|
|
2284
|
+
* system prompt is derived history — surface node 0, a `system/message` event.
|
|
2285
|
+
* The latest full `request/header` snapshot reconstructs the header; canonical
|
|
2286
|
+
* empty optional fields are absent.
|
|
2287
|
+
*/
|
|
2288
|
+
interface EpochHeader {
|
|
2289
|
+
/** The conversation's call configuration (provider, model, reasoning effort, and sampling scalars). */
|
|
2290
|
+
config: LlmCallConfig;
|
|
2291
|
+
/** Effective config fields materialized from the exact adapter rather than proposed by a caller. */
|
|
2292
|
+
adapterDefaults?: LlmCallConfigAdapterDefaults;
|
|
2293
|
+
/** Assembled tool schemas; absent for a tool-less request. */
|
|
2294
|
+
tools?: ToolSchema[];
|
|
2295
|
+
}
|
|
2296
|
+
/** Registration-bound metadata for one resolved model route. */
|
|
2297
|
+
interface RequestContext {
|
|
2298
|
+
/** Registered provider route the metadata belongs to. */
|
|
2299
|
+
provider: string;
|
|
2300
|
+
/** Provider-owned model id the metadata belongs to. */
|
|
2301
|
+
model: string;
|
|
2302
|
+
/** Maximum combined request and response context in tokens, when advertised. */
|
|
2303
|
+
contextWindow?: number;
|
|
2304
|
+
/** `'in-history'` when the route reads the latest `system` message at any position as the effective system prompt. */
|
|
2305
|
+
systemPromptUpdate?: SystemPromptUpdate;
|
|
2306
|
+
}
|
|
2307
|
+
/**
|
|
2308
|
+
* Why a `request/header` snapshot was appended: `'initial'` — the log's first
|
|
2309
|
+
* header (a new conversation); `'resume'` — a loop instance's first request
|
|
2310
|
+
* over a log that already has header events (process restart, fork seed);
|
|
2311
|
+
* `'change'` — a later request used a different header, with `startsSeries`
|
|
2312
|
+
* preserving a coincident series boundary; `'series'` — an unchanged header
|
|
2313
|
+
* began an explicitly distinct message series or followed a surface replacement.
|
|
2314
|
+
*/
|
|
2315
|
+
type RequestHeaderReason = 'initial' | 'resume' | 'change' | 'series';
|
|
2316
|
+
/**
|
|
2317
|
+
* The merge-extensible, append-only source of truth for an agent interaction.
|
|
2318
|
+
* Message history is derived from this log. Every event is lossless JSON and
|
|
2319
|
+
* sequence numbers stay contiguous. Assistant attempt events embed their exact
|
|
2320
|
+
* compact raw streams so persistence stores one durable settlement per attempt.
|
|
2321
|
+
*/
|
|
2322
|
+
interface SessionEventMap {
|
|
2323
|
+
/**
|
|
2324
|
+
* Opens turn `turn` before the loop claims queued input or runs pre-step.
|
|
2325
|
+
* Rejection, empty input, cancellation, or failure may close it with no
|
|
2326
|
+
* step; otherwise the following identified `user/message` event or batch
|
|
2327
|
+
* records the messages entering the step.
|
|
2328
|
+
*/
|
|
2329
|
+
'turn/start': {
|
|
2330
|
+
turn: number;
|
|
2331
|
+
};
|
|
2332
|
+
/**
|
|
2333
|
+
* Closes turn `turn` with the {@link TurnEndReason} that ended it. A turn
|
|
2334
|
+
* with no entered step has no `step/start` or `step/end`. The loop does not await a
|
|
2335
|
+
* flush at turn boundaries: `dsh-session-checkpoint-policy` owns the
|
|
2336
|
+
* per-request durability checkpoint, and consumers that read storage after
|
|
2337
|
+
* `whenIdle()` flush themselves. Success commits the turn; rejection is
|
|
2338
|
+
* reported live and does not prevent later work.
|
|
2339
|
+
*/
|
|
2340
|
+
'turn/end': {
|
|
2341
|
+
turn: number;
|
|
2342
|
+
reason: TurnEndReason;
|
|
2343
|
+
};
|
|
2344
|
+
/** Opens step `step` of turn `turn` — one model call plus the tool executions it requested. */
|
|
2345
|
+
'step/start': {
|
|
2346
|
+
turn: number;
|
|
2347
|
+
step: number;
|
|
2348
|
+
};
|
|
2349
|
+
/** Closes step `step` of turn `turn`. */
|
|
2350
|
+
'step/end': {
|
|
2351
|
+
turn: number;
|
|
2352
|
+
step: number;
|
|
2353
|
+
};
|
|
2354
|
+
/**
|
|
2355
|
+
* A user-role message on the model-visible surface: a direct human prompt
|
|
2356
|
+
* (the queued message claimed for this turn), a synthetic `agent.inject()`
|
|
2357
|
+
* context (file-change notices, subdir AGENTS.md, skill content, cron
|
|
2358
|
+
* notifications, …), or an entered goal continuation round. All three
|
|
2359
|
+
* project their `content` verbatim; `source` tells them apart.
|
|
2360
|
+
*/
|
|
2361
|
+
'user/message': UserMessage;
|
|
2362
|
+
/**
|
|
2363
|
+
* The rendered system prompt on the model-visible surface. The loop appends
|
|
2364
|
+
* the first one as surface node 0 before the step's first `user/message`.
|
|
2365
|
+
* A prepared in-history route can append nonempty changes in a continuing
|
|
2366
|
+
* series. An incapable route or new series normalizes text to the first system
|
|
2367
|
+
* node. Normalization empties nonempty later nodes, then rewrites the head if
|
|
2368
|
+
* needed, through logged per-node replacements. An empty rendering always
|
|
2369
|
+
* clears all active system nodes, leaving no older instructions model-visible.
|
|
2370
|
+
* Empty later nodes are dormant and project to no message; an empty head with
|
|
2371
|
+
* no active later node records "no system prompt". Restored nonempty text follows
|
|
2372
|
+
* the same route and series rule; empty nodes never restore older text.
|
|
2373
|
+
*/
|
|
2374
|
+
'system/message': {
|
|
2375
|
+
turn: number;
|
|
2376
|
+
step: number;
|
|
2377
|
+
message: SystemMessage;
|
|
2378
|
+
};
|
|
2379
|
+
/**
|
|
2380
|
+
* Assembled assistant message for one step (derived history uses this).
|
|
2381
|
+
* Carries the step's `usage` when the adapter reported token accounting, so
|
|
2382
|
+
* the model output and its accounting travel together (there is no separate
|
|
2383
|
+
* usage record). `usage` is absent when the adapter reported none. A turn
|
|
2384
|
+
* cancelled mid-stream finalizes its delivered text/reasoning prefix as this
|
|
2385
|
+
* event with `interrupted: true`; undispatched tool calls are absent. The
|
|
2386
|
+
* marker distinguishes that prefix without re-deriving interruption from turn
|
|
2387
|
+
* boundaries. An aborted turn with no such event streamed no visible content.
|
|
2388
|
+
*/
|
|
2389
|
+
'assistant/message': {
|
|
2390
|
+
turn: number;
|
|
2391
|
+
step: number;
|
|
2392
|
+
message: AssistantMessage;
|
|
2393
|
+
/** Exact timed model stream, compacted without joining delta boundaries. */
|
|
2394
|
+
stream: AssistantStreamRecord[];
|
|
2395
|
+
usage?: TokenUsage;
|
|
2396
|
+
interrupted?: true;
|
|
2397
|
+
};
|
|
2398
|
+
/**
|
|
2399
|
+
* One model attempt that committed no surface message. The embedded stream
|
|
2400
|
+
* preserves a failed, retried, cancelled, or stream-error attempt that
|
|
2401
|
+
* reached settlement without fabricating model-visible history.
|
|
2402
|
+
*/
|
|
2403
|
+
'assistant/attempt': {
|
|
2404
|
+
turn: number;
|
|
2405
|
+
step: number;
|
|
2406
|
+
stream: AssistantStreamRecord[];
|
|
2407
|
+
};
|
|
2408
|
+
/**
|
|
2409
|
+
* The model requested one tool invocation: `name` with the raw `arguments`
|
|
2410
|
+
* JSON string exactly as the model produced it (unparsed). `callId` pairs the
|
|
2411
|
+
* call with its `tool/result`.
|
|
2412
|
+
*/
|
|
2413
|
+
'tool/call': {
|
|
2414
|
+
turn: number;
|
|
2415
|
+
step: number;
|
|
2416
|
+
callId: ToolCallId;
|
|
2417
|
+
name: string;
|
|
2418
|
+
arguments: string;
|
|
2419
|
+
};
|
|
2420
|
+
/**
|
|
2421
|
+
* A completed tool call's model-facing result, optional internal failure
|
|
2422
|
+
* identity and user-facing reason, and optional tool-private `meta`
|
|
2423
|
+
* presentation payload. The reason remains outside the model-facing message.
|
|
2424
|
+
* `meta` is
|
|
2425
|
+
* opaque to the core (the producing tool owns its shape and reads it back in
|
|
2426
|
+
* `presentResult`) but MUST be JSON-serializable: `Session.append`
|
|
2427
|
+
* runtime-validates all event data with `isJsonValue`, so a non-serializable
|
|
2428
|
+
* `meta` is rejected at the source, and the durable log reproduces the
|
|
2429
|
+
* identical card on replay. Absent
|
|
2430
|
+
* unless the tool attaches one (e.g. `dsh-tool-fs` carries its result-time
|
|
2431
|
+
* contextual diff here).
|
|
2432
|
+
*/
|
|
2433
|
+
'tool/result': {
|
|
2434
|
+
turn: number;
|
|
2435
|
+
step: number;
|
|
2436
|
+
message: ToolResultMessage;
|
|
2437
|
+
/**
|
|
2438
|
+
* Optional failure identity and raw user-facing reason, outside model content;
|
|
2439
|
+
* allowed only when the tool-result block has `isError: true`.
|
|
2440
|
+
*/
|
|
2441
|
+
error?: {
|
|
2442
|
+
name: string;
|
|
2443
|
+
code: string;
|
|
2444
|
+
reason?: string;
|
|
2445
|
+
};
|
|
2446
|
+
meta?: JsonValue;
|
|
2447
|
+
};
|
|
2448
|
+
/**
|
|
2449
|
+
* Full header for the next request, appended inside its step before dispatch.
|
|
2450
|
+
* It is log-only; the latest snapshot reconstructs the request header.
|
|
2451
|
+
*/
|
|
2452
|
+
'request/header': {
|
|
2453
|
+
header: EpochHeader;
|
|
2454
|
+
reason: RequestHeaderReason;
|
|
2455
|
+
/** A changed header also begins a distinct model-message series. */
|
|
2456
|
+
startsSeries?: true;
|
|
2457
|
+
};
|
|
2458
|
+
/**
|
|
2459
|
+
* Route metadata for the next request, logged only when the route, capacity,
|
|
2460
|
+
* or system prompt update mode changes. It does not participate in request
|
|
2461
|
+
* reconstruction or header equality. Prompt admission uses the bound prepared
|
|
2462
|
+
* call's capability, not this snapshot from an earlier request.
|
|
2463
|
+
*/
|
|
2464
|
+
'request/context': RequestContext;
|
|
2465
|
+
/**
|
|
2466
|
+
* Marks the end of a constructor seed. Events before it have smaller seq
|
|
2467
|
+
* values and came from the seed (resume, fork, or replay); this lifecycle
|
|
2468
|
+
* produced none of them. This log-only event is the durable projection of
|
|
2469
|
+
* {@link Session.firstLiveSeq}.
|
|
2470
|
+
*
|
|
2471
|
+
* A fresh fork child owns one `{ inherited: true }` marker at its exact
|
|
2472
|
+
* inherited-prefix cut, even when that prefix ends in an ancestor marker.
|
|
2473
|
+
* The last tagged marker is the current Session's cut; untagged markers keep
|
|
2474
|
+
* ordinary restore and replay lifecycle boundaries.
|
|
2475
|
+
*
|
|
2476
|
+
* `Session`'s constructor is the only legitimate writer. The invariant
|
|
2477
|
+
* companion deliberately constrains nothing here, so a plugin appending one
|
|
2478
|
+
* would silently classify every live bracket before it as seed history.
|
|
2479
|
+
*
|
|
2480
|
+
* An owner of a standalone open/close bracket (`compaction/start` …
|
|
2481
|
+
* `compaction/end`) reads it because seed history and live work are otherwise
|
|
2482
|
+
* byte-identical: an unmatched opening marker before this event belongs to
|
|
2483
|
+
* an ended lifecycle, whatever ended it. NOT a liveness signal about other
|
|
2484
|
+
* writers — a concurrently live session holds its own boundary elsewhere,
|
|
2485
|
+
* so tolerating concurrent writers needs a signal beyond the log.
|
|
2486
|
+
*/
|
|
2487
|
+
'session/end-seed': {
|
|
2488
|
+
inherited?: true;
|
|
2489
|
+
};
|
|
2490
|
+
}
|
|
2491
|
+
/** The appendable event-type keys of {@link SessionEventMap}, plugin-merged extensions included. */
|
|
2492
|
+
type SessionEventType = keyof SessionEventMap;
|
|
2493
|
+
/**
|
|
2494
|
+
* The subset of {@link SessionEventType} values whose events produce LLM
|
|
2495
|
+
* messages and are eligible to appear on the ordered surface. Only these
|
|
2496
|
+
* event types may carry {@link SurfaceOp}; system, user, and tool events may also cite
|
|
2497
|
+
* earlier sources through {@link SessionEvent.sourceEventSeqs}.
|
|
2498
|
+
*/
|
|
2499
|
+
type SurfaceEventType = 'system/message' | 'user/message' | 'assistant/message' | 'tool/result';
|
|
2500
|
+
/**
|
|
2501
|
+
* How a session event entered the ordered surface. Only valid on
|
|
2502
|
+
* {@link SurfaceEventType} events.
|
|
2503
|
+
*
|
|
2504
|
+
* - `'append'`: added to the tail — normal path for user/assistant/tool
|
|
2505
|
+
* messages.
|
|
2506
|
+
* - `{ op: 'replace', startSeq, endSeq }`: replaces surface nodes from `startSeq`
|
|
2507
|
+
* (inclusive) through `endSeq` (inclusive) with this node. Both must exist as
|
|
2508
|
+
* surface nodes in the current surface. `startSeq === endSeq` replaces a single
|
|
2509
|
+
* node. The node's {@link SessionEvent.sourceEventSeqs} must include every
|
|
2510
|
+
* shadowed surface node. Used by compaction; any surface-replacing producer
|
|
2511
|
+
* may use it.
|
|
2512
|
+
*/
|
|
2513
|
+
type SurfaceOp = 'append' | {
|
|
2514
|
+
op: 'replace';
|
|
2515
|
+
startSeq: SessionSeq;
|
|
2516
|
+
endSeq: SessionSeq;
|
|
2517
|
+
};
|
|
2518
|
+
/**
|
|
2519
|
+
* Surface placement and cited source-event seqs for {@link Session.append}. Required on
|
|
2520
|
+
* message-producing events and forbidden on log-only events.
|
|
2521
|
+
*/
|
|
2522
|
+
type SurfaceIntent<T extends SurfaceEventType = SurfaceEventType> = {
|
|
2523
|
+
surfaceOp: SurfaceOp;
|
|
2524
|
+
} & (T extends 'assistant/message' ? {
|
|
2525
|
+
/** Assistant messages embed their provider stream instead of citing source events. */
|
|
2526
|
+
sourceEventSeqs?: never;
|
|
2527
|
+
} : {
|
|
2528
|
+
/** Complete non-empty set of known earlier source-event seqs. */
|
|
2529
|
+
sourceEventSeqs?: SessionSeq[];
|
|
2530
|
+
});
|
|
2531
|
+
/**
|
|
2532
|
+
* One immutable entry in the session log.
|
|
2533
|
+
*
|
|
2534
|
+
* A proper discriminated union over `type` (not independent `type`/`data`
|
|
2535
|
+
* unions), so `switch (event.type)` narrows `event.data` without casts.
|
|
2536
|
+
*
|
|
2537
|
+
* The {@link sourceEventSeqs} and {@link surfaceOp} fields are conditional:
|
|
2538
|
+
* they only exist on {@link SurfaceEventType} variants (`system/message`, `user/message`,
|
|
2539
|
+
* `assistant/message`, `tool/result`).
|
|
2540
|
+
* Non-surface events (boundary markers, attempts, errors) never carry
|
|
2541
|
+
* surface metadata — the compiler enforces this at `Session.append()`
|
|
2542
|
+
* call sites.
|
|
2543
|
+
*/
|
|
2544
|
+
type SessionEvent<T extends SessionEventType = SessionEventType> = { [K in SessionEventType]: {
|
|
2545
|
+
type: K;
|
|
2546
|
+
/** Monotonic sequence number within the session. */
|
|
2547
|
+
seq: SessionSeq;
|
|
2548
|
+
/** Unix epoch milliseconds. */
|
|
2549
|
+
time: number;
|
|
2550
|
+
data: SessionEventMap[K];
|
|
2551
|
+
/**
|
|
2552
|
+
* Marks an event a reader may safely skip when it does not recognize
|
|
2553
|
+
* `type`. Absent means required: a reader meeting an unrecognized type
|
|
2554
|
+
* without this marker MUST refuse to reconstruct the session instead of
|
|
2555
|
+
* silently dropping the event, because an unrecognized required event may
|
|
2556
|
+
* change how the rest of the log is interpreted. A writer sets `true` only
|
|
2557
|
+
* on purely informational records whose loss cannot affect reconstruction;
|
|
2558
|
+
* defaulting to required means a forgotten marker over-refuses (an
|
|
2559
|
+
* inconvenience) rather than silently resuming a gutted session.
|
|
2560
|
+
*/
|
|
2561
|
+
ignorable?: true;
|
|
2562
|
+
} & (K extends SurfaceEventType ? SurfaceIntent<K> : {
|
|
2563
|
+
surfaceOp?: never;
|
|
2564
|
+
sourceEventSeqs?: never;
|
|
2565
|
+
}); }[T];
|
|
2566
|
+
declare module '@deepseek-ai/dsh-typert-protocol' {
|
|
2567
|
+
interface RemoteErrorDetailsMap {
|
|
2568
|
+
/** The named Session does not exist; produced by every layer that resolves a SessionId. */
|
|
2569
|
+
'session/not-found': {
|
|
2570
|
+
readonly sessionId: SessionId;
|
|
2571
|
+
};
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
//#endregion
|
|
2575
|
+
//#region ../../../vendor/deepseek-harness/packages/core/session/lib/types/surface.d.ts
|
|
2576
|
+
/** Readonly history immediately before a message-projection event. */
|
|
2577
|
+
interface SessionMessageProjectionContext {
|
|
2578
|
+
/** Current message-producing event sequences in model-visible order. */
|
|
2579
|
+
nodes: readonly SessionSeq[];
|
|
2580
|
+
/** Contiguous event window; entries at or beyond the candidate seq are not committed inputs. */
|
|
2581
|
+
events: readonly SessionEvent[];
|
|
2582
|
+
/** Absolute sequence of the window's first event. */
|
|
2583
|
+
baseSeq: SessionLogOffset;
|
|
2584
|
+
/** Previously projected messages keyed by their original event sequences. */
|
|
2585
|
+
messages: ReadonlyMap<SessionSeq, Message>;
|
|
2586
|
+
}
|
|
2587
|
+
/** Pure interpretation of one plugin-owned event that changes existing message content. */
|
|
2588
|
+
interface SessionMessageProjection<T extends SessionEventType = SessionEventType> {
|
|
2589
|
+
/** Event interpreted by this definition; declare it with `@messageProjection` in SessionEventMap. */
|
|
2590
|
+
type: T;
|
|
2591
|
+
/**
|
|
2592
|
+
* Validate the complete durable decision before returning any updates. Preserve
|
|
2593
|
+
* message identities and publish immutable copies without mutating the input.
|
|
2594
|
+
* @param event - candidate event, not yet applied to the supplied history.
|
|
2595
|
+
* @param context - history preceding this decision.
|
|
2596
|
+
* @returns changed current messages keyed by their original sequences.
|
|
2597
|
+
* @throws when the durable decision cannot be applied to this history.
|
|
2598
|
+
*/
|
|
2599
|
+
project(event: SessionEvent<T>, context: SessionMessageProjectionContext): ReadonlyMap<SessionSeq, Message>;
|
|
2600
|
+
}
|
|
2601
|
+
/** Readonly live projection of the message-producing session events. */
|
|
2602
|
+
interface SessionSurface {
|
|
2603
|
+
/** Current surface event sequences in model-visible order. */
|
|
2604
|
+
readonly nodes: readonly SessionSeq[];
|
|
2605
|
+
/** Monotonic count of committed positional replacements. */
|
|
2606
|
+
readonly replaceGeneration: number;
|
|
2607
|
+
/** Monotonic count of committed replacements and plugin-owned message changes. */
|
|
2608
|
+
readonly contentGeneration: number;
|
|
2609
|
+
}
|
|
2610
|
+
//#endregion
|
|
2611
|
+
//#region ../../../vendor/deepseek-harness/packages/core/session/lib/types/index.d.ts
|
|
2612
|
+
declare module '@deepseek-ai/cordis' {
|
|
2613
|
+
interface Context {
|
|
2614
|
+
sessions: SessionStore;
|
|
2615
|
+
}
|
|
2616
|
+
interface Events {
|
|
2617
|
+
/**
|
|
2618
|
+
* Creation announcement during session publication. A synchronous throw vetoes and rolls
|
|
2619
|
+
* back with a paired disposal; detach requested during dispatch is deferred.
|
|
2620
|
+
* A returned-promise rejection is logged but cannot retroactively veto this
|
|
2621
|
+
* synchronous boundary.
|
|
2622
|
+
* Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners
|
|
2623
|
+
* receive only sessions entered through that agent's context.
|
|
2624
|
+
* @param session - the session just entered and announced.
|
|
2625
|
+
* @dshScopeScan unsupported
|
|
2626
|
+
* @mode emit
|
|
2627
|
+
*/
|
|
2628
|
+
'session/created'(this: Scoped<Session>, session: Session): void;
|
|
2629
|
+
/**
|
|
2630
|
+
* Emitted once when an announced session leaves the store, including
|
|
2631
|
+
* publication rollback, but never for an entry whose creation announcement
|
|
2632
|
+
* did not begin. Listener failures are logged and contained.
|
|
2633
|
+
* Scope-filtered dispatch (`@deepseek-ai/dsh-scope`) reuses the owner scope.
|
|
2634
|
+
* @param session - the session that is no longer live in the store.
|
|
2635
|
+
* @dshScopeScan unsupported
|
|
2636
|
+
* @mode emit
|
|
2637
|
+
*/
|
|
2638
|
+
'session/disposed'(this: Scoped<Session>, session: Session): void;
|
|
2639
|
+
/**
|
|
2640
|
+
* Post-commit, fire-and-forget append feed. The listener snapshot resolves
|
|
2641
|
+
* before the log push, but callbacks run after it; observer failures are
|
|
2642
|
+
* logged and contained without making the committed append fail.
|
|
2643
|
+
* Scope-filtered dispatch (`@deepseek-ai/dsh-scope`): agent-scoped listeners
|
|
2644
|
+
* receive only events from sessions entered through that agent's context.
|
|
2645
|
+
* @param session - the session whose log grew.
|
|
2646
|
+
* @param event - the appended event, exactly as recorded.
|
|
2647
|
+
* @dshScopeScan unsupported
|
|
2648
|
+
* @mode emit
|
|
2649
|
+
*/
|
|
2650
|
+
'session/event'(this: Scoped<Session>, session: Session, event: SessionEvent): void;
|
|
2651
|
+
/**
|
|
2652
|
+
* Awaited parallel durability checkpoint: every listener runs and the
|
|
2653
|
+
* caller awaits all of them, with no waterfall veto. Scope-filtered dispatch
|
|
2654
|
+
* (`@deepseek-ai/dsh-scope`) reuses the session's owner scope.
|
|
2655
|
+
* @param session - the session whose buffered events must reach durable storage.
|
|
2656
|
+
* @dshScopeScan unsupported
|
|
2657
|
+
* @mode parallel
|
|
2658
|
+
*/
|
|
2659
|
+
'session/flush'(this: Scoped<Session>, session: Session): Promise<void> | void;
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
declare module '@deepseek-ai/dsh-typert-protocol' {
|
|
2663
|
+
interface TypertLookupMap {
|
|
2664
|
+
session: TypertLookup<Session, SessionId>;
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
/**
|
|
2668
|
+
* An event-sourced session: an append-only log of {@link SessionEvent}s.
|
|
2669
|
+
*
|
|
2670
|
+
* Plain class (not a Service) — create live instances via
|
|
2671
|
+
* `ctx.sessions.create()` and detached instances via {@link create}.
|
|
2672
|
+
* Seeding with an existing event log replays/forks a session.
|
|
2673
|
+
* @typert object
|
|
2674
|
+
*/
|
|
2675
|
+
declare class Session {
|
|
2676
|
+
private log;
|
|
2677
|
+
/** Single incremental owner of surface acceptance and projection state. */
|
|
2678
|
+
private readonly surfaceManager;
|
|
2679
|
+
/** The ordered surface over this session's event log. */
|
|
2680
|
+
get surface(): SessionSurface;
|
|
2681
|
+
/**
|
|
2682
|
+
* Detached, deep-frozen creation metadata (format version, cwd, lineage,
|
|
2683
|
+
* and whether fork history exists). Supplied by the store via `ctx.sessions.create()`. When a
|
|
2684
|
+
* `Session` is created without a store-owned header, a minimal header is
|
|
2685
|
+
* synthesized (stamped with the current {@link SESSION_FORMAT_VERSION}) so
|
|
2686
|
+
* `session.header` is always present. Kept out of the event log — it is a
|
|
2687
|
+
* storage concern, not replayable conversation state.
|
|
2688
|
+
*/
|
|
2689
|
+
readonly header: SessionHeader;
|
|
2690
|
+
/** Number of leading events inherited from this Session's fork parent. */
|
|
2691
|
+
readonly inheritedEventCount: SessionLogOffset;
|
|
2692
|
+
/** The session identity, derived from its durable header's single copy. */
|
|
2693
|
+
get id(): SessionId;
|
|
2694
|
+
/**
|
|
2695
|
+
* The first seq appended IN THIS PROCESS: the length of the constructor
|
|
2696
|
+
* seed (0 without one). Events with smaller seq values entered through
|
|
2697
|
+
* construction — replay, fork, or resume — and were never published on the
|
|
2698
|
+
* `session/event` firehose (constructor seeds do not emit). This offset marks
|
|
2699
|
+
* the constructor-input boundary for lifecycle ownership and persistence
|
|
2700
|
+
* adoption; consumers that need complete canonical history still start at
|
|
2701
|
+
* seq 0. Distinct from {@link inheritedEventCount}, the DURABLE
|
|
2702
|
+
* fork-lineage cut: a resumed session's constructor seed is its full stored
|
|
2703
|
+
* log, while the inherited count keeps the original fork value — this field is the
|
|
2704
|
+
* in-process construction fact.
|
|
2705
|
+
*
|
|
2706
|
+
* Not persisted itself: a seeded session projects it into the log as the
|
|
2707
|
+
* `session/end-seed` event, which is what a consumer reading STORED history
|
|
2708
|
+
* reads. Locate the LAST such event, not necessarily one at this seq — a
|
|
2709
|
+
* seed already ending in one is not re-marked, so reopening an untouched
|
|
2710
|
+
* session leaves that event at a smaller seq than `firstLiveSeq`. Prefer
|
|
2711
|
+
* this field in-process: it is exact before the marker reaches storage.
|
|
2712
|
+
*
|
|
2713
|
+
* When this lifecycle appends the marker, it occupies this seq before the
|
|
2714
|
+
* store attaches and therefore does not publish either. Otherwise this seq
|
|
2715
|
+
* holds an ordinary published write.
|
|
2716
|
+
*/
|
|
2717
|
+
readonly firstLiveSeq: SessionLogOffset;
|
|
2718
|
+
/**
|
|
2719
|
+
* Create a detached session by validating and snapshotting borrowed seed
|
|
2720
|
+
* events and storage metadata.
|
|
2721
|
+
* @param id - session identity.
|
|
2722
|
+
* @param seed - optional borrowed replay or fork events.
|
|
2723
|
+
* @param header - optional borrowed storage metadata.
|
|
2724
|
+
* @param inheritedEventCount - exact fork-inherited prefix length for a seeded header.
|
|
2725
|
+
* @param projections - pure interpreters for plugin-owned message changes.
|
|
2726
|
+
* @returns a detached session.
|
|
2727
|
+
* @throws when a seed event requires a missing message interpreter or fails validation.
|
|
2728
|
+
*/
|
|
2729
|
+
static create(id: SessionId, seed?: readonly SessionEvent[], header?: SessionHeader, inheritedEventCount?: SessionLogOffset, projections?: readonly SessionMessageProjection[]): Session;
|
|
2730
|
+
/**
|
|
2731
|
+
* Restore a detached session by adopting an independently owned or deeply frozen seed.
|
|
2732
|
+
* Runtime-required event fields, event envelopes, sequence continuity, surface
|
|
2733
|
+
* transitions, and header fields are validated without copying or freezing events.
|
|
2734
|
+
* Embedded Assistant streams remain opaque until a stream consumer or storage
|
|
2735
|
+
* verifier reads them.
|
|
2736
|
+
* @param id - restored session identity.
|
|
2737
|
+
* @param seed - independently owned or deeply frozen events.
|
|
2738
|
+
* @param header - independently owned storage metadata.
|
|
2739
|
+
* @param inheritedEventCount - exact fork-inherited prefix length decoded from storage.
|
|
2740
|
+
* @param eventState - aliasing state carried from the operation that produced the seed.
|
|
2741
|
+
* @param projections - pure interpreters for plugin-owned message changes.
|
|
2742
|
+
* @returns a restored detached session.
|
|
2743
|
+
* @throws when a seed event requires a missing message interpreter or fails validation.
|
|
2744
|
+
*/
|
|
2745
|
+
static fromRestore(id: SessionId, seed: readonly SessionEvent[], header: SessionHeader, inheritedEventCount: SessionLogOffset, eventState: SessionSeedEventState, projections?: readonly SessionMessageProjection[]): Session;
|
|
2746
|
+
private constructor();
|
|
2747
|
+
/** Cached immutable full snapshot of the private append-only log. */
|
|
2748
|
+
private eventsSnapshot;
|
|
2749
|
+
/**
|
|
2750
|
+
* Return the immutable event stored at one exact sequence number.
|
|
2751
|
+
* @deprecated Existing logic may remain unmigrated for now, but new calls are prohibited.
|
|
2752
|
+
* See the [Agent Note](../../../../.agents/notes/implemented/architecture/2026-09-09-deprecate-synchronous-session-event-reads.md).
|
|
2753
|
+
* @param seq - event sequence number.
|
|
2754
|
+
* @returns the accepted event, or undefined when the log does not contain it.
|
|
2755
|
+
*/
|
|
2756
|
+
eventAt(seq: SessionSeq): SessionEvent | undefined;
|
|
2757
|
+
/**
|
|
2758
|
+
* Materialize an immutable snapshot of a half-open event sequence range.
|
|
2759
|
+
* A full current snapshot is reused until the next append; every previously
|
|
2760
|
+
* returned snapshot remains stable after later appends.
|
|
2761
|
+
* @deprecated Existing logic may remain unmigrated for now, but new calls are prohibited.
|
|
2762
|
+
* See the [Agent Note](../../../../.agents/notes/implemented/architecture/2026-09-09-deprecate-synchronous-session-event-reads.md).
|
|
2763
|
+
* @param fromSeq - non-negative inclusive sequence number; defaults to the log start.
|
|
2764
|
+
* @param toSeqExclusive - non-negative exclusive sequence number; defaults to the current end.
|
|
2765
|
+
* @returns a frozen array of the selected deeply frozen events.
|
|
2766
|
+
*/
|
|
2767
|
+
snapshotEvents(fromSeq?: SessionLogOffset, toSeqExclusive?: SessionLogOffset): readonly SessionEvent[];
|
|
2768
|
+
/**
|
|
2769
|
+
* Return this Session's events after its fork-inherited prefix.
|
|
2770
|
+
* @deprecated Existing logic may remain unmigrated for now, but new calls are prohibited.
|
|
2771
|
+
* See the [Agent Note](../../../../.agents/notes/implemented/architecture/2026-09-09-deprecate-synchronous-session-event-reads.md).
|
|
2772
|
+
* @returns a fresh array containing child-owned events in log order.
|
|
2773
|
+
*/
|
|
2774
|
+
ownEvents(): readonly SessionEvent[];
|
|
2775
|
+
/**
|
|
2776
|
+
* Whether one existing event position is outside the fork-inherited prefix.
|
|
2777
|
+
* @param seq - event position in this Session.
|
|
2778
|
+
* @returns true when the event belongs to this Session rather than its parent.
|
|
2779
|
+
*/
|
|
2780
|
+
isOwnSeq(seq: SessionSeq): boolean;
|
|
2781
|
+
/** The next event's sequence number — always the log length (the `seq = log.length` contiguity contract). */
|
|
2782
|
+
get seq(): SessionLogOffset;
|
|
2783
|
+
/**
|
|
2784
|
+
* Append one typed event to the log and synchronously notify observers via
|
|
2785
|
+
* the store-owned, module-private publication hooks. The hot path never blocks
|
|
2786
|
+
* on I/O — persistence plugins buffer asynchronously. Once the event enters
|
|
2787
|
+
* the log, the append is committed: observer failures are logged and
|
|
2788
|
+
* contained per listener, so they do not change the return value or prevent
|
|
2789
|
+
* later listeners from observing the same accepted event.
|
|
2790
|
+
*
|
|
2791
|
+
* @param type - The event type (key of {@link SessionEventMap}).
|
|
2792
|
+
* @param data - The event payload; must be JSON-serializable.
|
|
2793
|
+
* @param opts - Surface metadata: `surfaceOp` controls how the event enters
|
|
2794
|
+
* the ordered surface; `sourceEventSeqs` lists the seq numbers of earlier
|
|
2795
|
+
* events this one derives from. REQUIRED for
|
|
2796
|
+
* {@link SurfaceEventType} events (every message-producing event must
|
|
2797
|
+
* declare how it joins the surface, the sole source of derived model
|
|
2798
|
+
* history) and
|
|
2799
|
+
* rejected by the compiler for non-surface types like `turn/start` or
|
|
2800
|
+
* `assistant/attempt`. Assistant messages embed their exact provider
|
|
2801
|
+
* stream and cannot cite top-level source events.
|
|
2802
|
+
* @returns the logged event — its assigned `seq`/`time` plus the SNAPSHOT of
|
|
2803
|
+
* `data` that entered the log, so reading `event.data` back sees the logged
|
|
2804
|
+
* value, never the caller's still-mutable input.
|
|
2805
|
+
* @throws if `data` or surface metadata is not losslessly JSON-serializable
|
|
2806
|
+
* (BigInt, function, symbol, undefined, negative zero, non-finite number,
|
|
2807
|
+
* circular reference, sparse array, or an exotic object such as
|
|
2808
|
+
* Map/Set/Date/class instance), or when the candidate violates the
|
|
2809
|
+
* request-header empty-field or tool-error consistency rules, or the
|
|
2810
|
+
* canonical surface contract (marker shape and eligibility, unique
|
|
2811
|
+
* earlier source-event references, positional replacement validity, and complete
|
|
2812
|
+
* shadowed-node coverage). One iterative pass reads, validates, and
|
|
2813
|
+
* copies each nested value once, so a stateful getter cannot supply one value
|
|
2814
|
+
* to validation and another to storage. The event log is the durable source
|
|
2815
|
+
* of truth, so a bad event fails at the append site rather than later during
|
|
2816
|
+
* a backend flush. A synchronous internal dispatch validation failure or an
|
|
2817
|
+
* append reentered while this acceptance/publication boundary is open also
|
|
2818
|
+
* rejects before the log changes.
|
|
2819
|
+
*/
|
|
2820
|
+
append<T extends SessionEventType>(type: T, data: SessionEventMap[T], ...opts: T extends SurfaceEventType ? [opts: SurfaceIntent<T>] : []): SessionEvent<T>;
|
|
2821
|
+
/** Cached fold of the request-header events — see {@link requestHeader}. */
|
|
2822
|
+
private headerFold;
|
|
2823
|
+
/** Log position (events consumed) the header fold has reached. */
|
|
2824
|
+
private headerFoldSeq;
|
|
2825
|
+
/**
|
|
2826
|
+
* The {@link EpochHeader} in force after the log's last header event — the
|
|
2827
|
+
* header the NEXT request will be compared against — or undefined before
|
|
2828
|
+
* the first `request/header` snapshot. The live, incrementally-maintained
|
|
2829
|
+
* form of `foldRequestHeader(session.snapshotEvents())`: each header event is folded
|
|
2830
|
+
* once, when first seen, so a per-step read costs O(new events).
|
|
2831
|
+
* @returns the folded header, or undefined when no header event exists yet.
|
|
2832
|
+
*/
|
|
2833
|
+
requestHeader(): EpochHeader | undefined;
|
|
2834
|
+
/** Cached fold of `request/context` events. */
|
|
2835
|
+
private contextFold;
|
|
2836
|
+
private contextFoldSeq;
|
|
2837
|
+
/**
|
|
2838
|
+
* Return the latest resolved route metadata, or `undefined` before the first
|
|
2839
|
+
* `request/context` event. Each event is folded once.
|
|
2840
|
+
* @returns the latest immutable route metadata.
|
|
2841
|
+
*/
|
|
2842
|
+
requestContext(): RequestContext | undefined;
|
|
2843
|
+
/** The derived-message cache: frozen projections, extended per unseen node. */
|
|
2844
|
+
private derived;
|
|
2845
|
+
/** Surface position (nodes projected) the cache has reached. */
|
|
2846
|
+
private derivedNodes;
|
|
2847
|
+
/** {@link SurfaceManager.contentGeneration} the cache was built under. */
|
|
2848
|
+
private derivedGeneration;
|
|
2849
|
+
/**
|
|
2850
|
+
* Derive the LLM message history by walking the ordered sequences of
|
|
2851
|
+
* message-producing events maintained by `surfaceOp` markers. The
|
|
2852
|
+
* surface is the single source of derived history: every message-producing
|
|
2853
|
+
* append records its `surfaceOp`, so a raw event with no marker (a chunk, a
|
|
2854
|
+
* turn boundary) is correctly absent, and a compaction `replace` deletes the
|
|
2855
|
+
* shadowed nodes from the derivation. The projection rules are
|
|
2856
|
+
* {@link deriveEventMessage}, with logged message projections applied
|
|
2857
|
+
* without changing node membership or message identity.
|
|
2858
|
+
*
|
|
2859
|
+
* CACHED: pure tail growth costs O(new nodes); a replacement or message projection
|
|
2860
|
+
* ({@link SessionSurface.contentGeneration}) rebuilds. The returned array is
|
|
2861
|
+
* a fresh snapshot per call (later appends never grow an array a caller
|
|
2862
|
+
* already holds); the `Message` objects in it are SHARED and **deep-frozen**.
|
|
2863
|
+
* Unchanged content reuses frozen event data; projected blocks are frozen
|
|
2864
|
+
* derived copies. Consumers cannot mutate the log through either form.
|
|
2865
|
+
* @returns a fresh array of the shared, frozen derived history.
|
|
2866
|
+
*/
|
|
2867
|
+
deriveMessages(): Message[];
|
|
2868
|
+
/**
|
|
2869
|
+
* Project one event with all committed message projections applied.
|
|
2870
|
+
* The original durable event remains unchanged.
|
|
2871
|
+
* @param event - the event to project.
|
|
2872
|
+
* @returns the derived message, or null when the event produces none.
|
|
2873
|
+
*/
|
|
2874
|
+
deriveEventMessage(event: SessionEvent): Message | null;
|
|
2875
|
+
}
|
|
2876
|
+
/** A fork source: either the live session object or its live store id. */
|
|
2877
|
+
type SessionForkSource = Session | SessionId;
|
|
2878
|
+
/**
|
|
2879
|
+
* In-memory session store (`ctx.sessions`).
|
|
2880
|
+
*
|
|
2881
|
+
* Persistence is intentionally not implemented here — the agent lifecycle
|
|
2882
|
+
* attaches a session-log writer to each published session's write handle;
|
|
2883
|
+
* a session published outside that lifecycle persists nothing.
|
|
2884
|
+
*/
|
|
2885
|
+
declare class SessionStore extends Service {
|
|
2886
|
+
private store;
|
|
2887
|
+
private counter;
|
|
2888
|
+
private readonly projections;
|
|
2889
|
+
/** Borrowed definitions for detached replay; contributions live until their registering fibers unload. */
|
|
2890
|
+
get messageProjections(): readonly SessionMessageProjection[];
|
|
2891
|
+
/**
|
|
2892
|
+
* Register one event interpreter for live creation, restore, and fork.
|
|
2893
|
+
* Disposing the contribution makes sessions that used it refuse further derivation.
|
|
2894
|
+
* @param projection - pure definition owned by the event's plugin.
|
|
2895
|
+
* @returns the fiber-owned disposer.
|
|
2896
|
+
* @throws when another definition already owns this event type.
|
|
2897
|
+
*/
|
|
2898
|
+
registerMessageProjection(projection: SessionMessageProjection): () => Promise<void>;
|
|
2899
|
+
constructor(ctx: Context);
|
|
2900
|
+
/**
|
|
2901
|
+
* Create a session owned by the calling fiber: disposing that fiber stops
|
|
2902
|
+
* event notification and removes the session from the store. `options.seed`
|
|
2903
|
+
* populates the session with a copy of those events (replay/fork);
|
|
2904
|
+
* `options.meta` attaches creation metadata (validated absolute `cwd`, seed
|
|
2905
|
+
* and parent lineage, and delegation depth) as the immutable
|
|
2906
|
+
* {@link SessionHeader} (the store fills `version`/`id`/`createdAt`).
|
|
2907
|
+
*
|
|
2908
|
+
* For an agent whose session must be torn down IN ORDER with its loop (so the
|
|
2909
|
+
* loop's final events are published before the store attachment ends), do NOT use this
|
|
2910
|
+
* — fold the session lifecycle into the agent's own effect via
|
|
2911
|
+
* {@link prepare} + {@link enter} + {@link announce} (see
|
|
2912
|
+
* `dsh-agent-loop`'s creation transaction).
|
|
2913
|
+
*
|
|
2914
|
+
* @param id - the session id; omitted, the store mints `session-<n>`.
|
|
2915
|
+
* @param options - seed events and/or creation metadata for the header.
|
|
2916
|
+
* @returns the live session, already entered and announced.
|
|
2917
|
+
* @throws if a session with `id` already exists, metadata is not a plain
|
|
2918
|
+
* lossless-JSON record with valid scalar fields, or `meta.cwd` is a
|
|
2919
|
+
* non-absolute path (storage backends key directories off it).
|
|
2920
|
+
*/
|
|
2921
|
+
create(id?: SessionId, options?: CreateSessionOptions): Session;
|
|
2922
|
+
/**
|
|
2923
|
+
* Build a session WITHOUT entering it into the store — validate the id/cwd and
|
|
2924
|
+
* construct the {@link Session} (with its immutable {@link SessionHeader}).
|
|
2925
|
+
* Pairs with {@link enter} + {@link announce}: a caller that owns a composite
|
|
2926
|
+
* `ctx.effect` (the agent factory) folds the session lifecycle into that ONE
|
|
2927
|
+
* effect so a fiber unload tears the session + agent down as a single ORDERED
|
|
2928
|
+
* chain rather than as racing sibling effects — which would remove the publication hooks
|
|
2929
|
+
* before the driver's closing events commit, dropping them.
|
|
2930
|
+
*
|
|
2931
|
+
* @param id - the session id; omitted, the store mints `session-<n>`.
|
|
2932
|
+
* @param options - seed events and/or creation metadata for the header. With
|
|
2933
|
+
* `eventState`, every seed event is either independently owned or any
|
|
2934
|
+
* shared value is deeply frozen; {@link Session.fromRestore} validates and
|
|
2935
|
+
* adopts those values without copying or freezing them.
|
|
2936
|
+
* @returns the constructed session, NOT yet in the store.
|
|
2937
|
+
* @throws if a session with `id` already exists, metadata is not a plain
|
|
2938
|
+
* lossless-JSON record with valid scalar fields, or `meta.cwd` is a
|
|
2939
|
+
* non-absolute path.
|
|
2940
|
+
*/
|
|
2941
|
+
prepare(id?: SessionId, options?: PrepareSessionOptions): Session;
|
|
2942
|
+
/**
|
|
2943
|
+
* Enter a {@link prepare}d session into the store: install the module-private
|
|
2944
|
+
* append publication hooks and add it to the store. Returns the DETACH
|
|
2945
|
+
* disposer (hooks + store removal). Does NOT emit `session/created` —
|
|
2946
|
+
* the caller yields this disposer inside its effect and THEN calls
|
|
2947
|
+
* {@link announce}, so a throwing `session/created` listener rolls the attach
|
|
2948
|
+
* back instead of leaking it.
|
|
2949
|
+
*
|
|
2950
|
+
* Re-checks the id for a duplicate: `prepare` and `enter` are public
|
|
2951
|
+
* cross-package primitives and a caller may interleave arbitrary work (or
|
|
2952
|
+
* another create) between them, so a stale prepared session must NOT overwrite
|
|
2953
|
+
* a live store entry of the same id — its detach disposer would later delete
|
|
2954
|
+
* the REAL session. The {@link create} convenience and the agent factory call
|
|
2955
|
+
* the two back-to-back so they never trip this, but the public API cannot
|
|
2956
|
+
* assume that.
|
|
2957
|
+
*
|
|
2958
|
+
* @param session - a {@link prepare}d session not yet in the store.
|
|
2959
|
+
* @returns the detach disposer (publication hooks + store removal). When called from
|
|
2960
|
+
* a synchronous `session/created` listener, removal and disposal wait until
|
|
2961
|
+
* that creation dispatch unwinds.
|
|
2962
|
+
* @throws if a session with this id is already in the store.
|
|
2963
|
+
*/
|
|
2964
|
+
enter(session: Session): () => void;
|
|
2965
|
+
/** Remove one exact entered session and emit its paired disposal when announced. */
|
|
2966
|
+
private detachEntered;
|
|
2967
|
+
/** Emit `session/created` exactly once for an {@link enter}ed session (with
|
|
2968
|
+
* the carrier {@link enter} captured). Separate from {@link enter} so the
|
|
2969
|
+
* caller can yield the detach disposer first (rollback safety — see
|
|
2970
|
+
* {@link enter}).
|
|
2971
|
+
* @param session - the entered session to announce to listeners.
|
|
2972
|
+
* @throws if the session is not live or its announcement already began,
|
|
2973
|
+
* including a reentrant call from a creation listener. */
|
|
2974
|
+
announce(session: Session): void;
|
|
2975
|
+
/** Emit the paired teardown notification with per-listener containment. */
|
|
2976
|
+
private emitDisposed;
|
|
2977
|
+
/**
|
|
2978
|
+
* Dispatch the awaited `session/flush` durability checkpoint for `session`,
|
|
2979
|
+
* with the carrier captured at {@link enter}. THE flush entry point: the
|
|
2980
|
+
* store owns the carrier, so callers (the checkpoint policy's per-request
|
|
2981
|
+
* barrier, goal-round-driver's idle checkpoint, teardown drains, and consumers
|
|
2982
|
+
* that flush themselves before reading storage) must come through here
|
|
2983
|
+
* rather than dispatch a raw `ctx.parallel('session/flush', …)` — one owner,
|
|
2984
|
+
* one spelling, and the scoped-dispatch invariant can pin it.
|
|
2985
|
+
* @param session - the session whose buffered events must reach durable storage.
|
|
2986
|
+
* @returns whether at least one durability listener participated, after every
|
|
2987
|
+
* listener has settled successfully.
|
|
2988
|
+
* @throws the first registered listener failure after every listener settles.
|
|
2989
|
+
*/
|
|
2990
|
+
flush(session: Session): Promise<boolean>;
|
|
2991
|
+
/** Return the exact live entry; detached/prepared objects reject. */
|
|
2992
|
+
private liveEntryFor;
|
|
2993
|
+
/**
|
|
2994
|
+
* Look up a live session.
|
|
2995
|
+
* @param id - the session id to look up.
|
|
2996
|
+
* @returns the session, or undefined when no live session has that id.
|
|
2997
|
+
*/
|
|
2998
|
+
get(id: SessionId): Session | undefined;
|
|
2999
|
+
/**
|
|
3000
|
+
* All live sessions, in creation order.
|
|
3001
|
+
* @returns a fresh array; mutating it does not affect the store.
|
|
3002
|
+
*/
|
|
3003
|
+
list(): Session[];
|
|
3004
|
+
/**
|
|
3005
|
+
* Create a live child session from a stable prefix of a live source.
|
|
3006
|
+
* `boundary` is an inclusive source event seq; omitted means the source's
|
|
3007
|
+
* current last event. The selected slice may end with a between-turn event
|
|
3008
|
+
* but must not end inside an open turn.
|
|
3009
|
+
*
|
|
3010
|
+
* @param source - Live source session object or id.
|
|
3011
|
+
* @param boundary - Inclusive source event seq to fork through; omitted means
|
|
3012
|
+
* the source's current last event, and omitted on an empty source forks an
|
|
3013
|
+
* empty child.
|
|
3014
|
+
* @param childSessionId - Optional child session id; omitted delegates to
|
|
3015
|
+
* `SessionStore`'s id policy.
|
|
3016
|
+
* @returns The created live child session.
|
|
3017
|
+
*/
|
|
3018
|
+
fork(source: SessionForkSource, boundary?: SessionSeq, childSessionId?: SessionId): Session;
|
|
3019
|
+
private _forkSeed;
|
|
3020
|
+
private _resolveForkSource;
|
|
3021
|
+
}
|
|
3022
|
+
//#endregion
|
|
3023
|
+
//#region src/client/controller.d.ts
|
|
3024
|
+
/** 时间范围的语义键(与 session-rdb `./usage` 的 `UsageRangeKey` 镜像)。 */
|
|
3025
|
+
type UsageRangeKey = "all" | "day" | "week" | "7d" | "30d" | "90d";
|
|
3026
|
+
/** 一段用量合计(与 session-rdb `./usage` 的回报结构镜像)。 */
|
|
3027
|
+
interface UsageTotals {
|
|
3028
|
+
events: number;
|
|
3029
|
+
inputTokens: number;
|
|
3030
|
+
outputTokens: number;
|
|
3031
|
+
cacheReadTokens: number;
|
|
3032
|
+
reasoningTokens: number;
|
|
3033
|
+
totalTokens: number;
|
|
3034
|
+
}
|
|
3035
|
+
/** 一天 × 一个模型 × 是否子代理 的用量桶。 */
|
|
3036
|
+
interface UsageBucket extends UsageTotals {
|
|
3037
|
+
day: string;
|
|
3038
|
+
provider: string | null;
|
|
3039
|
+
model: string | null;
|
|
3040
|
+
subagent: boolean;
|
|
3041
|
+
}
|
|
3042
|
+
/** 一条会话的用量行。 */
|
|
3043
|
+
interface UsageSessionRow extends UsageTotals {
|
|
3044
|
+
sessionId: string;
|
|
3045
|
+
title: string | null;
|
|
3046
|
+
subagent: boolean;
|
|
3047
|
+
archived: boolean;
|
|
3048
|
+
}
|
|
3049
|
+
/** 一次统计请求的回报:总览 + subagent 拆分 + 桶 + 会话行。 */
|
|
3050
|
+
interface SessionUsageReport {
|
|
3051
|
+
totals: UsageTotals;
|
|
3052
|
+
subagent: UsageTotals;
|
|
3053
|
+
/** 只被人类会话引用的部分。 */
|
|
3054
|
+
human: UsageTotals;
|
|
3055
|
+
buckets: UsageBucket[];
|
|
3056
|
+
sessions: UsageSessionRow[];
|
|
3057
|
+
}
|
|
3058
|
+
/** 页面之外的服务面:归档状态与列表刷新都归它们的既有 owner。 */
|
|
3059
|
+
interface ConversationManagerPorts {
|
|
3060
|
+
archiveSession(sessionId: SessionId): Promise<void>;
|
|
3061
|
+
unarchiveSession(sessionId: SessionId): Promise<void>;
|
|
3062
|
+
refresh(): Promise<void>;
|
|
3063
|
+
}
|
|
3064
|
+
/** GC 一次执行的回报。 */
|
|
3065
|
+
interface ConversationManagerGcResult {
|
|
3066
|
+
orphanSessions: number;
|
|
3067
|
+
orphanEvents: number;
|
|
3068
|
+
stoppedAgents: number;
|
|
3069
|
+
}
|
|
3070
|
+
/** 页面从注入面拿到的动作(属性语法:页面解构后直接调用,不绑 this)。 */
|
|
3071
|
+
interface ConversationManagerFace {
|
|
3072
|
+
archive: (sessionId: SessionId) => Promise<void>;
|
|
3073
|
+
unarchive: (sessionId: SessionId) => Promise<void>;
|
|
3074
|
+
remove: (sessionId: SessionId) => Promise<void>;
|
|
3075
|
+
exportZip: (sessionId: SessionId) => Promise<void>;
|
|
3076
|
+
importZip: (file: File) => Promise<SessionId>;
|
|
3077
|
+
collectGarbage: () => Promise<ConversationManagerGcResult>;
|
|
3078
|
+
loadUsage: (range: UsageRangeKey) => Promise<SessionUsageReport>;
|
|
3079
|
+
}
|
|
3080
|
+
/** 带 host 错误码的请求失败:页面据此选本地化文案。 */
|
|
3081
|
+
declare class ConversationManagerRequestError extends Error {
|
|
3082
|
+
readonly code: string | undefined;
|
|
3083
|
+
constructor(message: string, code: string | undefined);
|
|
3084
|
+
}
|
|
3085
|
+
/** 页面的动作:host 交互收在这里,页面只见数据与回调。 */
|
|
3086
|
+
declare class ConversationManagerController {
|
|
3087
|
+
private readonly ports;
|
|
3088
|
+
readonly face: ConversationManagerFace;
|
|
3089
|
+
constructor(ports: ConversationManagerPorts);
|
|
3090
|
+
private remove;
|
|
3091
|
+
private exportZip;
|
|
3092
|
+
private importZip;
|
|
3093
|
+
private collectGarbage;
|
|
3094
|
+
/**
|
|
3095
|
+
* 用量统计:host 侧聚合,前端各维度本地折叠。
|
|
3096
|
+
* @param range - 时间范围语义键(`all` 不限、`day`/`week` 自然日/周、其余最近 N 天)。
|
|
3097
|
+
*/
|
|
3098
|
+
private loadUsage;
|
|
3099
|
+
}
|
|
3100
|
+
//#endregion
|
|
3101
|
+
//#region src/client/ConversationManagerIcon.d.ts
|
|
3102
|
+
/** nav 图标只画字形:尺寸由 nav 行给,选中态由 nav 行的按钮承担。 */
|
|
3103
|
+
type ConversationManagerIconProps = PropsRuntime<"sidebar.panellist">;
|
|
3104
|
+
//#endregion
|
|
3105
|
+
//#region src/client/ConversationManagerPage.d.ts
|
|
3106
|
+
/** 页面 props:main 座位的运行时份额 + 本包字典 + 注入的动作。 */
|
|
3107
|
+
type ConversationManagerPageProps = PropsRuntime<"main"> & PropsLocale<"conversationManager"> & InjectFace<ConversationManagerFace>;
|
|
3108
|
+
//#endregion
|
|
3109
|
+
//#region src/client/index.d.ts
|
|
3110
|
+
declare module "@deepseek-ai/dsh-client-ui-slots" {
|
|
3111
|
+
interface LocaleNamespaceMap {
|
|
3112
|
+
conversationManager: ConversationManagerKey;
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
/** 本包字典的 namespace。 */
|
|
3116
|
+
declare const NS = "conversationManager";
|
|
3117
|
+
/** nav 行与主面板共用的 id。 */
|
|
3118
|
+
declare const PANEL_ID: MainPanelId;
|
|
3119
|
+
/** nav 行的位置:紧邻官方 Plugins 行(order 0)。 */
|
|
3120
|
+
declare const PANEL_ORDER = 1;
|
|
3121
|
+
/** 页面用到的服务。 */
|
|
3122
|
+
declare const inject: string[];
|
|
3123
|
+
declare function apply(ctx: Context): void;
|
|
3124
|
+
//#endregion
|
|
3125
|
+
export { ConversationManagerController, type ConversationManagerFace, type ConversationManagerIconProps, type ConversationManagerKey, type ConversationManagerPageProps, type ConversationManagerPorts, ConversationManagerRequestError, NS, PANEL_ID, PANEL_ORDER, apply, inject };
|