@qilin-agent/llm 0.0.0-stage → 3.1.3
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.i18n.yaml +64 -0
- package/README.md +177 -2
- package/README.zh.md +178 -0
- package/lib/index.js +2388 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +626 -0
- package/lib/typert.remote-client.d.ts +26 -0
- package/lib/typert.remote-client.js +109 -0
- package/lib/types/adapter-failure.d.ts +14 -0
- package/lib/types/adapter-failure.js +108 -0
- package/lib/types/api-key.d.ts +28 -0
- package/lib/types/api-key.js +34 -0
- package/lib/types/assembler.d.ts +75 -0
- package/lib/types/assembler.js +191 -0
- package/lib/types/assistant-stream.d.ts +166 -0
- package/lib/types/assistant-stream.js +458 -0
- package/lib/types/attribution.d.ts +47 -0
- package/lib/types/attribution.js +46 -0
- package/lib/types/brand.d.ts +56 -0
- package/lib/types/brand.js +53 -0
- package/lib/types/call-config.d.ts +53 -0
- package/lib/types/call-config.js +46 -0
- package/lib/types/content.d.ts +149 -0
- package/lib/types/content.js +355 -0
- package/lib/types/error.d.ts +81 -0
- package/lib/types/error.js +153 -0
- package/lib/types/index.d.ts +416 -0
- package/lib/types/index.js +948 -0
- package/lib/types/message.d.ts +246 -0
- package/lib/types/message.js +101 -0
- package/lib/types/retry-policy.d.ts +66 -0
- package/lib/types/retry-policy.js +127 -0
- package/lib/types/types.d.ts +532 -0
- package/lib/types/types.js +7 -0
- package/package.json +74 -3
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical provider-neutral message and streaming vocabulary for the loop,
|
|
3
|
+
* session log, and plugins. Adapters alone translate provider wire messages;
|
|
4
|
+
* mapped interfaces make the content, source, and finish unions extensible.
|
|
5
|
+
*/
|
|
6
|
+
import type { Branded } from '@qilin-agent/brand';
|
|
7
|
+
import type { FileAttachmentRef, ImageAttachmentRef } from '@qilin-agent/attachment';
|
|
8
|
+
import type { MessageId, ToolCallId, ProviderRequestId, ReasoningEffortId } from './brand.ts';
|
|
9
|
+
import type { Message, UserMessage } from './message.ts';
|
|
10
|
+
declare module '@qilin-agent/kylin' {
|
|
11
|
+
interface Events {
|
|
12
|
+
/**
|
|
13
|
+
* The provider topology changed: an adapter registered or unregistered
|
|
14
|
+
* routes, or the configurable-provider directory gained or lost entries.
|
|
15
|
+
* This payload-free registry notification fires at each commit point
|
|
16
|
+
* (including registration disposal); consumers re-read `listProviders()`,
|
|
17
|
+
* `listModels()`, or `listConfigurableProviders()` for the new state.
|
|
18
|
+
* Observer failures are contained and cannot veto the registry mutation.
|
|
19
|
+
* @mode emit
|
|
20
|
+
*/
|
|
21
|
+
'llm/adapters-updated'(): void;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export type { AssistantMessage, DeveloperMessage, AssistantProviderMetadata, Message, MessageSource, MessageSourceMap, ModelMessageSource, ToolMessageSource, ToolResultMessage, UserMessage, } from './message.ts';
|
|
25
|
+
/** Serializable provider or transport failure facts; policy decides whether they are retryable. */
|
|
26
|
+
export interface LlmFailure {
|
|
27
|
+
/** Human-readable provider or transport failure. */
|
|
28
|
+
readonly message: string;
|
|
29
|
+
/** Stable provider-neutral machine-routing code. */
|
|
30
|
+
readonly code: string;
|
|
31
|
+
/** HTTP status returned by the provider, when available. */
|
|
32
|
+
readonly status?: number;
|
|
33
|
+
/** Provider-requested delay in milliseconds, when valid and available. */
|
|
34
|
+
readonly providerRetryAfterMs?: number;
|
|
35
|
+
/** Opaque provider-issued request identifier for diagnostics. */
|
|
36
|
+
readonly requestId?: ProviderRequestId;
|
|
37
|
+
/**
|
|
38
|
+
* With code `IMAGE_OFFLOAD_REQUIRED`: how many more of the oldest retained
|
|
39
|
+
* image occurrences the route needs offloaded before the same request fits
|
|
40
|
+
* its exact byte accounting. `qilin-compaction-image-offload` records the
|
|
41
|
+
* selected occurrences in an `image/offload` event and retries the step.
|
|
42
|
+
*/
|
|
43
|
+
readonly offloadImages?: number;
|
|
44
|
+
}
|
|
45
|
+
/** Plain text visible to the end user. */
|
|
46
|
+
export interface TextBlock {
|
|
47
|
+
type: 'text';
|
|
48
|
+
text: string;
|
|
49
|
+
}
|
|
50
|
+
/** Reasoning / thinking content, distinct from visible text. */
|
|
51
|
+
export interface ReasoningBlock {
|
|
52
|
+
type: 'reasoning';
|
|
53
|
+
text: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A durable raster image reference, valid in user or assistant content. The
|
|
57
|
+
* block is deliberately role-neutral; assistant-side rendering is forward
|
|
58
|
+
* compatibility — the current production adapters declare text-only output,
|
|
59
|
+
* so only user messages may carry images.
|
|
60
|
+
*/
|
|
61
|
+
export interface ImageBlock {
|
|
62
|
+
type: 'image';
|
|
63
|
+
/** Immutable bytes and intrinsic display metadata owned by the attachment service. */
|
|
64
|
+
attachment: ImageAttachmentRef;
|
|
65
|
+
/**
|
|
66
|
+
* Derived from a durable image-offload decision or preserved by a message
|
|
67
|
+
* rewrite. Every route sends placeholder text naming the image and its
|
|
68
|
+
* available read-only path instead of image bytes.
|
|
69
|
+
*/
|
|
70
|
+
offloaded?: true;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A durable verbatim file reference, valid in user content. Files never reach
|
|
74
|
+
* a provider natively: request assembly projects every occurrence to
|
|
75
|
+
* deterministic handle text (name, byte size, and the read-only saved path),
|
|
76
|
+
* so adapters and providers see text in its place while the durable log keeps
|
|
77
|
+
* the structured reference for presentation and authorization.
|
|
78
|
+
*/
|
|
79
|
+
export interface FileBlock {
|
|
80
|
+
type: 'file';
|
|
81
|
+
/** Immutable verbatim bytes and display metadata owned by the attachment service. */
|
|
82
|
+
attachment: FileAttachmentRef;
|
|
83
|
+
}
|
|
84
|
+
/** A tool invocation requested by the model. */
|
|
85
|
+
export interface ToolCallBlock {
|
|
86
|
+
type: 'tool-call';
|
|
87
|
+
/** Provider-issued call id; correlates with the matching tool result. */
|
|
88
|
+
id: ToolCallId;
|
|
89
|
+
name: string;
|
|
90
|
+
/** Raw JSON string as produced by the model. */
|
|
91
|
+
arguments: string;
|
|
92
|
+
}
|
|
93
|
+
/** Activates a tool definition from the developer event's referenced request header. */
|
|
94
|
+
export interface ToolAdditionBlock {
|
|
95
|
+
type: 'tool-addition';
|
|
96
|
+
/** Name of exactly one tool in the referenced historical header. */
|
|
97
|
+
toolName: string;
|
|
98
|
+
/**
|
|
99
|
+
* Reserved against inline definitions; the historical request header owns the schema.
|
|
100
|
+
* @persistenceReserved
|
|
101
|
+
*/
|
|
102
|
+
tool?: never;
|
|
103
|
+
}
|
|
104
|
+
/** Records the dynamic removal of a tool identified by its session-local name. */
|
|
105
|
+
export interface ToolRemovalBlock {
|
|
106
|
+
type: 'tool-removal';
|
|
107
|
+
toolName: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Merge-extensible content blocks keyed by `type`. New core blocks must land
|
|
111
|
+
* with adapter, UI, and compaction support. Tool-change blocks belong to
|
|
112
|
+
* developer messages; `projectToolUpdates` selects what each route receives.
|
|
113
|
+
*/
|
|
114
|
+
export interface ContentBlockMap {
|
|
115
|
+
'text': TextBlock;
|
|
116
|
+
'reasoning': ReasoningBlock;
|
|
117
|
+
'image': ImageBlock;
|
|
118
|
+
'file': FileBlock;
|
|
119
|
+
'tool-call': ToolCallBlock;
|
|
120
|
+
'tool-addition': ToolAdditionBlock;
|
|
121
|
+
'tool-removal': ToolRemovalBlock;
|
|
122
|
+
}
|
|
123
|
+
/** The block `type` tag vocabulary; widens as plugins add entries to {@link ContentBlockMap}. */
|
|
124
|
+
export type ContentBlockType = keyof ContentBlockMap;
|
|
125
|
+
/** Any known content block, derived from {@link ContentBlockMap}; switch on `type` and fall through unknowns (merge-extensible). */
|
|
126
|
+
export type ContentBlock = ContentBlockMap[ContentBlockType];
|
|
127
|
+
/**
|
|
128
|
+
* Why a model response stopped.
|
|
129
|
+
* Merge-extensible so adapters can surface provider-specific reasons.
|
|
130
|
+
*/
|
|
131
|
+
export interface FinishReasonMap {
|
|
132
|
+
'stop': {
|
|
133
|
+
kind: 'stop';
|
|
134
|
+
};
|
|
135
|
+
'tool-calls': {
|
|
136
|
+
kind: 'tool-calls';
|
|
137
|
+
};
|
|
138
|
+
'max-tokens': {
|
|
139
|
+
kind: 'max-tokens';
|
|
140
|
+
};
|
|
141
|
+
'aborted': {
|
|
142
|
+
kind: 'aborted';
|
|
143
|
+
failure: LlmFailure;
|
|
144
|
+
};
|
|
145
|
+
'error': {
|
|
146
|
+
kind: 'error';
|
|
147
|
+
failure: LlmFailure;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/** Any known finish reason, derived from {@link FinishReasonMap}; switch on `kind` and fall through unknowns (merge-extensible). */
|
|
151
|
+
export type FinishReason = FinishReasonMap[keyof FinishReasonMap];
|
|
152
|
+
/**
|
|
153
|
+
* Token accounting for one model call (cache fields are optional).
|
|
154
|
+
*
|
|
155
|
+
* Counts are DISJOINT: `inputTokens` is uncached input only; cached input is
|
|
156
|
+
* reported separately as `cacheReadTokens`/`cacheWriteTokens` (billed input =
|
|
157
|
+
* sum of the three). Adapters whose providers fold cache hits into a total
|
|
158
|
+
* prompt count (DeepSeek's `prompt_tokens`) subtract them out.
|
|
159
|
+
*/
|
|
160
|
+
export interface TokenUsage {
|
|
161
|
+
inputTokens: number;
|
|
162
|
+
outputTokens: number;
|
|
163
|
+
/**
|
|
164
|
+
* Exact full-call total including aggregate prompt and output tokens.
|
|
165
|
+
*
|
|
166
|
+
* Adapters preserve a provider total or derive it from authoritative
|
|
167
|
+
* aggregate prompt/output counters; they omit it when unavailable or
|
|
168
|
+
* inconsistent.
|
|
169
|
+
*/
|
|
170
|
+
totalTokens?: number;
|
|
171
|
+
cacheReadTokens?: number;
|
|
172
|
+
cacheWriteTokens?: number;
|
|
173
|
+
reasoningTokens?: number;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Request price of one ordered image occurrence under one exact model route's
|
|
177
|
+
* request projection. Every occurrence resolves to the pair the wire actually
|
|
178
|
+
* carries: provider visual tokens for a retained image, plus the model-visible
|
|
179
|
+
* text sent with or instead of it (request-preview handle, offload placeholder,
|
|
180
|
+
* or text-only substitution). The caller prices `text` with its own text
|
|
181
|
+
* estimator so provider pricing never fixes a text tokenization.
|
|
182
|
+
*/
|
|
183
|
+
export interface LlmImageRequestPrice {
|
|
184
|
+
/** Provider visual tokens for the retained request image; 0 when only text represents this occurrence. */
|
|
185
|
+
visualTokens: number;
|
|
186
|
+
/** Model-visible text sent for this occurrence, to be priced by the caller's text estimator. */
|
|
187
|
+
text: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Provider-side request-image pricing for one exact model route. Implemented
|
|
191
|
+
* by adapters whose provider charges visual tokens; consumers (the token
|
|
192
|
+
* meter) resolve it synchronously per measurement, so implementations must not
|
|
193
|
+
* perform I/O.
|
|
194
|
+
*/
|
|
195
|
+
export interface LlmImageRequestPricing {
|
|
196
|
+
/**
|
|
197
|
+
* Price every image occurrence of one request projection.
|
|
198
|
+
* @param images - surface image blocks in request order, one entry per occurrence; an `offloaded` block
|
|
199
|
+
* is priced as its placeholder text.
|
|
200
|
+
* @returns one price per occurrence, aligned by index with `images`.
|
|
201
|
+
*/
|
|
202
|
+
priceImages(images: readonly ImageBlock[]): readonly LlmImageRequestPrice[];
|
|
203
|
+
}
|
|
204
|
+
/** Display metadata for one registered provider route. */
|
|
205
|
+
export interface LlmProviderInfo {
|
|
206
|
+
/** Provider route key used by {@link GenerateOptions.provider}. */
|
|
207
|
+
id: string;
|
|
208
|
+
/** Human-readable provider name for selectors and diagnostics. */
|
|
209
|
+
name: string;
|
|
210
|
+
}
|
|
211
|
+
/** Merge-extensible provider model modality vocabulary. */
|
|
212
|
+
export interface ModelModalityMap {
|
|
213
|
+
text: 'text';
|
|
214
|
+
image: 'image';
|
|
215
|
+
}
|
|
216
|
+
/** Any declared provider model modality. */
|
|
217
|
+
export type ModelModality = ModelModalityMap[keyof ModelModalityMap];
|
|
218
|
+
/**
|
|
219
|
+
* One provider route an adapter plugin can activate through configuration,
|
|
220
|
+
* whether or not the route is currently registered. Configuration surfaces
|
|
221
|
+
* merge this directory with `listProviders()` to offer every configurable
|
|
222
|
+
* provider alongside its live/dormant state.
|
|
223
|
+
*/
|
|
224
|
+
export interface LlmConfigurableProvider {
|
|
225
|
+
/** Provider route key this entry activates when configured. */
|
|
226
|
+
provider: string;
|
|
227
|
+
/** Human-readable provider name for configuration surfaces. */
|
|
228
|
+
displayName: string;
|
|
229
|
+
/** User-settings namespace whose section configures this provider. */
|
|
230
|
+
settingsNs: string;
|
|
231
|
+
/**
|
|
232
|
+
* Path from that namespace's section root to this provider's profile
|
|
233
|
+
* object; empty when the whole section is the profile.
|
|
234
|
+
*/
|
|
235
|
+
settingsPath: readonly string[];
|
|
236
|
+
/**
|
|
237
|
+
* Whether the owning adapter knows this route only because configuration
|
|
238
|
+
* declared it — a gateway or self-hosted server it ships nothing about.
|
|
239
|
+
* Absent means the adapter draws no such distinction; false means it does
|
|
240
|
+
* and this route is one of its own. Only the adapter can answer: a stored
|
|
241
|
+
* profile is how a user-added route AND a corrected shipped one both look
|
|
242
|
+
* from outside.
|
|
243
|
+
*/
|
|
244
|
+
declared?: boolean;
|
|
245
|
+
/** Configuration diagnostic for repair; unaffected models may remain serviceable. */
|
|
246
|
+
error?: string;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* One interrogation of a provider endpoint that configuration has not stored
|
|
250
|
+
* yet. Configuration surfaces send the draft a user is still editing, so the
|
|
251
|
+
* request carries the endpoint and credential directly instead of naming a
|
|
252
|
+
* route: a provider being added has no route to name.
|
|
253
|
+
*/
|
|
254
|
+
export interface LlmModelDiscoveryRequest {
|
|
255
|
+
/**
|
|
256
|
+
* Route the draft is editing, when it edits an existing one. A route whose
|
|
257
|
+
* adapter already knows its models answers from that knowledge instead of
|
|
258
|
+
* asking the endpoint — the adapter's own registry is the better answer, and
|
|
259
|
+
* it costs no network call.
|
|
260
|
+
*/
|
|
261
|
+
provider?: string;
|
|
262
|
+
/**
|
|
263
|
+
* Endpoint to interrogate. Optional because a route the adapter already
|
|
264
|
+
* describes needs none; a route it does not must supply one.
|
|
265
|
+
*/
|
|
266
|
+
baseURL?: string;
|
|
267
|
+
/** Wire protocol the endpoint speaks, when the draft names one. */
|
|
268
|
+
api?: string;
|
|
269
|
+
/** Credential for this interrogation alone; the harness never stores it. */
|
|
270
|
+
apiKey?: string;
|
|
271
|
+
}
|
|
272
|
+
/** Provider-side discovery request with operation-local cancellation attached. */
|
|
273
|
+
export interface LlmModelDiscoveryOperation extends LlmModelDiscoveryRequest {
|
|
274
|
+
/** Caller cancellation; implementations must settle promptly after it aborts. */
|
|
275
|
+
signal?: AbortSignal;
|
|
276
|
+
}
|
|
277
|
+
declare module '@qilin-agent/typert-protocol' {
|
|
278
|
+
interface RemoteErrorDetailsMap {
|
|
279
|
+
/** A draft provider interrogation refused or failed. */
|
|
280
|
+
'llm/model-discovery-rejected': {
|
|
281
|
+
readonly settingsNs: string;
|
|
282
|
+
readonly baseURL?: string;
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* One model an endpoint reports about itself. Every field but the id is
|
|
288
|
+
* optional because most provider listings disclose an id and nothing else;
|
|
289
|
+
* a surface adopting one of these still owes the capacities its adapter needs.
|
|
290
|
+
*/
|
|
291
|
+
export interface LlmDiscoveredModel {
|
|
292
|
+
/** Model id the endpoint accepts. */
|
|
293
|
+
id: string;
|
|
294
|
+
/** Human-readable name when the endpoint supplies one. */
|
|
295
|
+
name?: string;
|
|
296
|
+
/** Maximum combined request and response context, when disclosed. */
|
|
297
|
+
contextWindow?: number;
|
|
298
|
+
/** Maximum output tokens, when disclosed. */
|
|
299
|
+
maxTokens?: number;
|
|
300
|
+
/** Accepted input types when disclosed by the catalog or endpoint; absent means unknown. */
|
|
301
|
+
inputModalities?: readonly ModelModality[];
|
|
302
|
+
}
|
|
303
|
+
/** One adapter-discovered model; catalog membership is advisory, not request validation. */
|
|
304
|
+
export interface LlmModelInfo {
|
|
305
|
+
/** Provider route that owns this model entry. */
|
|
306
|
+
provider: string;
|
|
307
|
+
/** Model id passed to {@link GenerateOptions.model}. */
|
|
308
|
+
id: string;
|
|
309
|
+
/** Human-readable model name for selectors. */
|
|
310
|
+
name: string;
|
|
311
|
+
/** Optional user-facing distinction from otherwise similar models. */
|
|
312
|
+
description?: string;
|
|
313
|
+
/** Accepted request modalities; absent means unknown, while an explicit omission is negative capability. */
|
|
314
|
+
inputModalities?: readonly ModelModality[];
|
|
315
|
+
}
|
|
316
|
+
/** Provider-owned context capacity for one exact provider/model route. */
|
|
317
|
+
export interface LlmModelContext {
|
|
318
|
+
/** Maximum combined request and response context in tokens. */
|
|
319
|
+
contextWindow: number;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Request-image budget one exact image-capable route enforces over the
|
|
323
|
+
* retained occurrences' exact request-version bytes; for the `base64`
|
|
324
|
+
* representation each byte count expands to its encoded length. A route whose
|
|
325
|
+
* retained occurrences exceed the budget fails the request with
|
|
326
|
+
* `IMAGE_OFFLOAD_REQUIRED` naming the additional occurrences to offload.
|
|
327
|
+
*/
|
|
328
|
+
export interface LlmImageRequestBudget {
|
|
329
|
+
/** Whether the route accounts raw file bytes or inline base64 length. */
|
|
330
|
+
representation: 'raw' | 'base64';
|
|
331
|
+
/** Accumulated represented image bytes the route accepts; absent leaves bytes unbounded. */
|
|
332
|
+
maxBytes?: number;
|
|
333
|
+
/** Image occurrences the route accepts; absent leaves the count unbounded. */
|
|
334
|
+
maxImages?: number;
|
|
335
|
+
/** Represented bytes removed as one deterministic advance step; absent removes the minimum. */
|
|
336
|
+
byteQuantum?: number;
|
|
337
|
+
/** Occurrences removed as one deterministic advance step; absent removes the minimum. */
|
|
338
|
+
countQuantum?: number;
|
|
339
|
+
}
|
|
340
|
+
/** Display metadata for one adapter-owned reasoning effort. */
|
|
341
|
+
export interface LlmReasoningEffortInfo {
|
|
342
|
+
/** Opaque stable value accepted by {@link GenerateOptions.reasoningEffort}. */
|
|
343
|
+
id: ReasoningEffortId;
|
|
344
|
+
/** Human-readable effort name for selectors and diagnostics. */
|
|
345
|
+
name: string;
|
|
346
|
+
/** Optional user-facing distinction from otherwise similar efforts. */
|
|
347
|
+
description?: string;
|
|
348
|
+
}
|
|
349
|
+
/** Selectable reasoning efforts for one exact provider/model route. */
|
|
350
|
+
export interface LlmModelReasoningInfo {
|
|
351
|
+
/** Supported efforts in adapter-preferred display order. */
|
|
352
|
+
efforts: readonly LlmReasoningEffortInfo[];
|
|
353
|
+
/**
|
|
354
|
+
* Adapter-configured default materialized into requests when callers omit
|
|
355
|
+
* an effort. Absence preserves the provider's own default.
|
|
356
|
+
*/
|
|
357
|
+
defaultEffort?: ReasoningEffortId;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* How a model applies a system prompt that changes mid-conversation.
|
|
361
|
+
* `'in-history'`: the model reads the latest `system` message at any position
|
|
362
|
+
* of `messages` as the complete effective system prompt, so a changed prompt
|
|
363
|
+
* can follow the cached history instead of rewriting message 0.
|
|
364
|
+
*/
|
|
365
|
+
export type SystemPromptUpdate = 'in-history';
|
|
366
|
+
/**
|
|
367
|
+
* How a model accepts native tool declarations that change mid-conversation.
|
|
368
|
+
* `'addition-only'`: the model reads a `tool-addition` block in a later
|
|
369
|
+
* developer message as activating a tool declared with `deferLoading`, so an
|
|
370
|
+
* added tool follows the cached history instead of rewriting the declaration
|
|
371
|
+
* list. `'in-history'`: the model additionally reads `tool-removal` blocks,
|
|
372
|
+
* so a removed tool keeps its declaration and the removal follows the history.
|
|
373
|
+
* Absent means every request declares the complete current tool list.
|
|
374
|
+
*/
|
|
375
|
+
export type ToolUpdate = 'in-history' | 'addition-only';
|
|
376
|
+
/** Exact-route model metadata resolved by its owning adapter. */
|
|
377
|
+
export interface LlmResolvedModelInfo extends LlmModelInfo {
|
|
378
|
+
/** Provider-owned context capacity when known. */
|
|
379
|
+
context?: LlmModelContext;
|
|
380
|
+
/** Adapter-configured per-request output cap materialized when callers omit one. */
|
|
381
|
+
defaultMaxTokens?: number;
|
|
382
|
+
/** Adapter-owned selectable reasoning levels when exposed. */
|
|
383
|
+
reasoning?: LlmModelReasoningInfo;
|
|
384
|
+
/** Declared mid-conversation system prompt handling; absent means only a leading system message is read. */
|
|
385
|
+
systemPromptUpdate?: SystemPromptUpdate;
|
|
386
|
+
/** Declared mid-conversation tool declaration handling; absent means every request declares the complete tool list. */
|
|
387
|
+
toolUpdate?: ToolUpdate;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Adapter-private lossless-JSON state for replaying a successful response,
|
|
391
|
+
* carried by a terminal `finish` chunk and stored on the assembled assistant
|
|
392
|
+
* message's model source. Both halves stay opaque to the harness; only the
|
|
393
|
+
* split is shared vocabulary, so assembly can keep stored metadata aligned
|
|
394
|
+
* with stored content without reading either half.
|
|
395
|
+
*/
|
|
396
|
+
export interface ReplayEnvelope {
|
|
397
|
+
/** Response-level adapter-private metadata (ids, native stop reason). */
|
|
398
|
+
response: unknown;
|
|
399
|
+
/**
|
|
400
|
+
* Per-block adapter-private metadata, one entry per emitted block in
|
|
401
|
+
* first-seen stream order. When assembly drops a block it drops the entry at
|
|
402
|
+
* the same position; entries whose length does not match the emitted block
|
|
403
|
+
* count discard the whole envelope. An adapter whose metadata is independent
|
|
404
|
+
* of block structure omits this field and the envelope passes through
|
|
405
|
+
* assembly unchanged.
|
|
406
|
+
*/
|
|
407
|
+
blocks?: readonly unknown[];
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Raw streaming protocol emitted by adapters.
|
|
411
|
+
* Block indexes correlate interleaved deltas, and `block-end` carries the
|
|
412
|
+
* assembled block. Adapters emit usage before the terminal finish and nothing
|
|
413
|
+
* afterward; tool arguments remain raw JSON strings. An adapter implementation
|
|
414
|
+
* may throw, but `LlmRuntime.stream()` normalizes that failure to a terminal
|
|
415
|
+
* `error` or `aborted` finish before exposing it to consumers.
|
|
416
|
+
*/
|
|
417
|
+
export type StreamChunk = {
|
|
418
|
+
type: 'block-start';
|
|
419
|
+
index: number;
|
|
420
|
+
blockType: ContentBlockType;
|
|
421
|
+
} | {
|
|
422
|
+
type: 'text-delta';
|
|
423
|
+
index: number;
|
|
424
|
+
text: string;
|
|
425
|
+
} | {
|
|
426
|
+
type: 'reasoning-delta';
|
|
427
|
+
index: number;
|
|
428
|
+
text: string;
|
|
429
|
+
} | {
|
|
430
|
+
type: 'tool-call-delta';
|
|
431
|
+
index: number;
|
|
432
|
+
id: ToolCallId;
|
|
433
|
+
name?: string;
|
|
434
|
+
argumentsDelta: string;
|
|
435
|
+
} | {
|
|
436
|
+
type: 'block-end';
|
|
437
|
+
index: number;
|
|
438
|
+
block: ContentBlock;
|
|
439
|
+
} | {
|
|
440
|
+
type: 'usage';
|
|
441
|
+
usage: TokenUsage;
|
|
442
|
+
} | {
|
|
443
|
+
type: 'finish';
|
|
444
|
+
reason: FinishReason;
|
|
445
|
+
/** Replay metadata for a successful response; see {@link ReplayEnvelope}. */
|
|
446
|
+
replayState?: ReplayEnvelope;
|
|
447
|
+
};
|
|
448
|
+
/**
|
|
449
|
+
* JSON-schema description of a tool, as sent to the model.
|
|
450
|
+
*
|
|
451
|
+
* Declared here (not in qilin-tools) because it is part of {@link GenerateOptions};
|
|
452
|
+
* qilin-tools' ToolDefinition and qilin-system-prompt's PromptAssembly both import
|
|
453
|
+
* it from this package.
|
|
454
|
+
*/
|
|
455
|
+
export interface ToolSchema {
|
|
456
|
+
/**
|
|
457
|
+
* Requests deferred loading of the tool definition into model context,
|
|
458
|
+
* independently of whether a tool-addition block records the tool.
|
|
459
|
+
* Uses Anthropic's defer_loading terminology.
|
|
460
|
+
*/
|
|
461
|
+
deferLoading?: true;
|
|
462
|
+
name: string;
|
|
463
|
+
description: string;
|
|
464
|
+
/** JSON Schema object for the arguments. */
|
|
465
|
+
parameters: Record<string, unknown>;
|
|
466
|
+
}
|
|
467
|
+
/** User input for one LLM request; it has no durable Session identity or source. */
|
|
468
|
+
export interface RequestUserInput {
|
|
469
|
+
readonly role: 'user';
|
|
470
|
+
readonly content: UserMessage['content'];
|
|
471
|
+
readonly id?: never;
|
|
472
|
+
readonly source?: never;
|
|
473
|
+
}
|
|
474
|
+
/** A durable conversation message or a user input used only for one request. */
|
|
475
|
+
export type RequestMessage = Message | RequestUserInput;
|
|
476
|
+
/** Logged tool declarations and update identities since the last declaration reset. */
|
|
477
|
+
export interface ToolHistory {
|
|
478
|
+
/** Complete active declarations at the start of this history. */
|
|
479
|
+
readonly tools: readonly ToolSchema[];
|
|
480
|
+
/** Ordered developer messages, with additions resolved from their historical headers. */
|
|
481
|
+
readonly updates: readonly {
|
|
482
|
+
/** Identity used to locate this update in the derived request history. */
|
|
483
|
+
readonly messageId: MessageId;
|
|
484
|
+
/** Added definitions resolved from the event's referenced request header. */
|
|
485
|
+
readonly additions: readonly ToolSchema[];
|
|
486
|
+
}[];
|
|
487
|
+
}
|
|
488
|
+
/** A single model request, fully assembled. */
|
|
489
|
+
export interface GenerateOptions {
|
|
490
|
+
/** Registered provider route selecting the adapter instance. */
|
|
491
|
+
provider: string;
|
|
492
|
+
model: string;
|
|
493
|
+
/** Adapter-owned reasoning effort selected for this exact model. */
|
|
494
|
+
reasoningEffort?: ReasoningEffortId;
|
|
495
|
+
/**
|
|
496
|
+
* Ordered conversation messages, exactly as the provider sees them. A
|
|
497
|
+
* loop-built request passes the derived history (qilin-agent-loop), whose
|
|
498
|
+
* leading system-role message carries the system prompt; a hand-built
|
|
499
|
+
* one-shot may include identity-free user inputs.
|
|
500
|
+
*/
|
|
501
|
+
messages: RequestMessage[];
|
|
502
|
+
/**
|
|
503
|
+
* System prompt text for one-shot callers; adapters map it to the provider's
|
|
504
|
+
* system slot ahead of `messages`. Loop-built requests leave it undefined.
|
|
505
|
+
*/
|
|
506
|
+
system?: string;
|
|
507
|
+
/** Tool schemas (adapters map to the provider's `tools` field). */
|
|
508
|
+
tools?: ToolSchema[];
|
|
509
|
+
/** Session-folded tool history used for route projection; omission sends complete declarations without tool updates. */
|
|
510
|
+
toolHistory?: ToolHistory;
|
|
511
|
+
temperature?: number;
|
|
512
|
+
maxTokens?: number;
|
|
513
|
+
/**
|
|
514
|
+
* Stop sequences: generation halts as soon as the model produces any one of
|
|
515
|
+
* these strings (adapters map to the provider's stop field, e.g. OpenAI
|
|
516
|
+
* `stop`). The stop string itself is not included in the output.
|
|
517
|
+
*/
|
|
518
|
+
stop?: string[];
|
|
519
|
+
signal?: AbortSignal;
|
|
520
|
+
/**
|
|
521
|
+
* Session identity stamped by the loop for request routing. Replay uses it
|
|
522
|
+
* to separate cursors; adapters may map it to model-hidden transport metadata.
|
|
523
|
+
*/
|
|
524
|
+
sessionId?: Branded<'SessionId'>;
|
|
525
|
+
/**
|
|
526
|
+
* Provider-neutral classification for an auxiliary model call. Adapters may
|
|
527
|
+
* map the purpose to model-hidden transport metadata or purpose-specific
|
|
528
|
+
* generation policy. Ordinary conversation requests leave it unset.
|
|
529
|
+
*/
|
|
530
|
+
purpose?: 'compaction' | 'session-title';
|
|
531
|
+
}
|
|
532
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical provider-neutral message and streaming vocabulary for the loop,
|
|
3
|
+
* session log, and plugins. Adapters alone translate provider wire messages;
|
|
4
|
+
* mapped interfaces make the content, source, and finish unions extensible.
|
|
5
|
+
*/
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qilin-agent/llm",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "Provider-neutral LLM service interface for the QiLin",
|
|
4
|
+
"version": "3.1.3",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/kkutysllb/QiLin.git",
|
|
11
|
+
"directory": "packages/llm/llm"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "lib/index.js",
|
|
18
|
+
"types": "lib/types/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./lib/types/index.d.ts",
|
|
22
|
+
"default": "./lib/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./types": {
|
|
25
|
+
"types": "./lib/types/types.d.ts",
|
|
26
|
+
"default": "./lib/types/types.js"
|
|
27
|
+
},
|
|
28
|
+
"./brand": {
|
|
29
|
+
"types": "./lib/types/brand.d.ts",
|
|
30
|
+
"default": "./lib/types/brand.js"
|
|
31
|
+
},
|
|
32
|
+
"./message": {
|
|
33
|
+
"types": "./lib/types/message.d.ts",
|
|
34
|
+
"default": "./lib/types/message.js"
|
|
35
|
+
},
|
|
36
|
+
"./assistant-stream": {
|
|
37
|
+
"types": "./lib/types/assistant-stream.d.ts",
|
|
38
|
+
"default": "./lib/types/assistant-stream.js"
|
|
39
|
+
},
|
|
40
|
+
"./typert": {
|
|
41
|
+
"types": "./lib/typert.host.d.ts",
|
|
42
|
+
"default": "./lib/typert.host.js"
|
|
43
|
+
},
|
|
44
|
+
"./remote": {
|
|
45
|
+
"types": "./lib/typert.remote-client.d.ts",
|
|
46
|
+
"default": "./lib/typert.remote-client.js"
|
|
47
|
+
},
|
|
48
|
+
"./src/*": "./src/*",
|
|
49
|
+
"./package.json": "./package.json"
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"lib/index.js",
|
|
53
|
+
"lib/types/**/*.js",
|
|
54
|
+
"lib/types/**/*.d.ts",
|
|
55
|
+
"lib/typert.host.js",
|
|
56
|
+
"lib/typert.host.d.ts",
|
|
57
|
+
"lib/typert.remote-client.js",
|
|
58
|
+
"lib/typert.remote-client.d.ts"
|
|
59
|
+
],
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@qilin-agent/kylin": "~4.0.3"
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"zod": "^4.4.3",
|
|
66
|
+
"@qilin-agent/schemastery": "~3.18.3",
|
|
67
|
+
"@qilin-agent/util-crypto": "3.1.3",
|
|
68
|
+
"@qilin-agent/timeout": "3.1.3",
|
|
69
|
+
"@qilin-agent/brand": "3.1.3",
|
|
70
|
+
"@qilin-agent/util-values": "3.1.3",
|
|
71
|
+
"@qilin-agent/typert-protocol": "3.1.3"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@qilin-agent/attachment": "3.1.3",
|
|
75
|
+
"@qilin-agent/kylin": "~4.0.3"
|
|
76
|
+
}
|
|
6
77
|
}
|