@fifthrevision/axle 0.19.0 → 0.21.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/dist/accumulator-BLjnX0uz.js +1 -0
- package/dist/accumulator-svhGVEwB.d.ts +1156 -0
- package/dist/index.d.ts +289 -549
- package/dist/index.js +22 -1
- package/dist/{models-Whj6ZP3l.d.ts → models-BWhStxxX.d.ts} +3 -2
- package/dist/models-Cx50YJNx.js +1 -0
- package/dist/providers/models.d.ts +1 -1
- package/dist/providers/models.js +1 -1
- package/dist/ui.d.ts +2 -2
- package/dist/ui.js +1 -1
- package/package.json +9 -29
- package/README.md +0 -621
- package/dist/ProceduralMemory-CNxHj5B2.js +0 -45
- package/dist/accumulator-D2NgIGxp.d.ts +0 -547
- package/dist/accumulator-vmmD3pxt.js +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -6
- package/dist/models-Bp_jVWHN.js +0 -1
- package/dist/models-C7fdWvZ6.js +0 -1
|
@@ -0,0 +1,1156 @@
|
|
|
1
|
+
import { ZodObject, z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Token usage reported by a provider response.
|
|
6
|
+
*/
|
|
7
|
+
interface Stats {
|
|
8
|
+
/** Total effective input tokens. Includes `cachedIn` and `cacheWriteIn` when reported. */
|
|
9
|
+
in: number;
|
|
10
|
+
/** Total output tokens. Includes `reasoningOut` when reported. */
|
|
11
|
+
out: number;
|
|
12
|
+
/** Input tokens served from provider prompt/context cache. Included in `in`. */
|
|
13
|
+
cachedIn?: number;
|
|
14
|
+
/** Input tokens written into provider prompt/context cache. Included in `in`. */
|
|
15
|
+
cacheWriteIn?: number;
|
|
16
|
+
/** Output tokens spent on reasoning/thinking. Included in `out`. */
|
|
17
|
+
reasoningOut?: number;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/messages/stream.d.ts
|
|
21
|
+
interface StreamChunk {
|
|
22
|
+
type: "start" | "text-start" | "text-delta" | "text-citation" | "text-complete" | "tool-call-start" | "tool-call-args-delta" | "tool-call-complete" | "thinking-start" | "thinking-delta" | "thinking-summary-delta" | "thinking-metadata" | "thinking-complete" | "provider-tool-start" | "provider-tool-complete" | "complete" | "error";
|
|
23
|
+
id?: string;
|
|
24
|
+
data?: any;
|
|
25
|
+
}
|
|
26
|
+
interface StreamStartChunk extends StreamChunk {
|
|
27
|
+
type: "start";
|
|
28
|
+
id: string;
|
|
29
|
+
data: {
|
|
30
|
+
model: string;
|
|
31
|
+
timestamp: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
interface StreamCompleteChunk extends StreamChunk {
|
|
35
|
+
type: "complete";
|
|
36
|
+
data: {
|
|
37
|
+
finishReason: AxleStopReason;
|
|
38
|
+
usage: Stats;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
interface StreamErrorChunk extends StreamChunk {
|
|
42
|
+
type: "error";
|
|
43
|
+
data: {
|
|
44
|
+
type: string;
|
|
45
|
+
message: string;
|
|
46
|
+
usage?: Stats;
|
|
47
|
+
raw?: any;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
interface StreamTextStartChunk extends StreamChunk {
|
|
51
|
+
type: "text-start";
|
|
52
|
+
data: {
|
|
53
|
+
index: number;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
interface StreamTextDeltaChunk extends StreamChunk {
|
|
57
|
+
type: "text-delta";
|
|
58
|
+
data: {
|
|
59
|
+
index: number;
|
|
60
|
+
text: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
interface StreamTextCitationChunk extends StreamChunk {
|
|
64
|
+
type: "text-citation";
|
|
65
|
+
data: {
|
|
66
|
+
index: number;
|
|
67
|
+
citation: Citation;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
interface StreamTextCompleteChunk extends StreamChunk {
|
|
71
|
+
type: "text-complete";
|
|
72
|
+
data: {
|
|
73
|
+
index: number;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
interface StreamThinkingStartChunk extends StreamChunk {
|
|
77
|
+
type: "thinking-start";
|
|
78
|
+
data: {
|
|
79
|
+
index: number;
|
|
80
|
+
id?: string;
|
|
81
|
+
redacted?: boolean;
|
|
82
|
+
continuity?: ThinkingContinuity;
|
|
83
|
+
providerMetadata?: Record<string, unknown>;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
interface StreamThinkingDeltaChunk extends StreamChunk {
|
|
87
|
+
type: "thinking-delta";
|
|
88
|
+
data: {
|
|
89
|
+
index: number;
|
|
90
|
+
text: string;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
interface StreamThinkingSummaryDeltaChunk extends StreamChunk {
|
|
94
|
+
type: "thinking-summary-delta";
|
|
95
|
+
data: {
|
|
96
|
+
index: number;
|
|
97
|
+
text: string;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
interface StreamThinkingMetadataChunk extends StreamChunk {
|
|
101
|
+
type: "thinking-metadata";
|
|
102
|
+
data: {
|
|
103
|
+
index: number;
|
|
104
|
+
continuity?: ThinkingContinuity;
|
|
105
|
+
redacted?: boolean;
|
|
106
|
+
providerMetadata?: Record<string, unknown>;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
interface StreamThinkingCompleteChunk extends StreamChunk {
|
|
110
|
+
type: "thinking-complete";
|
|
111
|
+
data: {
|
|
112
|
+
index: number;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
interface StreamToolCallStartChunk extends StreamChunk {
|
|
116
|
+
type: "tool-call-start";
|
|
117
|
+
data: {
|
|
118
|
+
index: number;
|
|
119
|
+
id: string;
|
|
120
|
+
name: string;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
interface StreamToolCallArgsDeltaChunk extends StreamChunk {
|
|
124
|
+
type: "tool-call-args-delta";
|
|
125
|
+
data: {
|
|
126
|
+
index: number;
|
|
127
|
+
id: string;
|
|
128
|
+
name: string;
|
|
129
|
+
delta: string;
|
|
130
|
+
accumulated: string;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
interface StreamToolCallCompleteChunk extends StreamChunk {
|
|
134
|
+
type: "tool-call-complete";
|
|
135
|
+
data: {
|
|
136
|
+
index: number;
|
|
137
|
+
id: string;
|
|
138
|
+
name: string;
|
|
139
|
+
arguments: any;
|
|
140
|
+
providerMetadata?: Record<string, unknown>;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
interface StreamProviderToolStartChunk extends StreamChunk {
|
|
144
|
+
type: "provider-tool-start";
|
|
145
|
+
data: {
|
|
146
|
+
index: number;
|
|
147
|
+
id: string;
|
|
148
|
+
name: string;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
interface StreamProviderToolCompleteChunk extends StreamChunk {
|
|
152
|
+
type: "provider-tool-complete";
|
|
153
|
+
data: {
|
|
154
|
+
index: number;
|
|
155
|
+
id: string;
|
|
156
|
+
name: string;
|
|
157
|
+
output?: unknown;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
type AnyStreamChunk = StreamStartChunk | StreamCompleteChunk | StreamErrorChunk | StreamTextStartChunk | StreamTextDeltaChunk | StreamTextCitationChunk | StreamTextCompleteChunk | StreamThinkingStartChunk | StreamThinkingDeltaChunk | StreamThinkingSummaryDeltaChunk | StreamThinkingMetadataChunk | StreamThinkingCompleteChunk | StreamToolCallStartChunk | StreamToolCallArgsDeltaChunk | StreamToolCallCompleteChunk | StreamProviderToolStartChunk | StreamProviderToolCompleteChunk;
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/tracer/types.d.ts
|
|
163
|
+
type SpanStatus = "ok" | "error";
|
|
164
|
+
type EventLevel = "debug" | "info" | "warn" | "error";
|
|
165
|
+
type SpanType = string;
|
|
166
|
+
interface SpanEvent {
|
|
167
|
+
name: string;
|
|
168
|
+
timestamp: number;
|
|
169
|
+
level: EventLevel;
|
|
170
|
+
attributes?: Record<string, unknown>;
|
|
171
|
+
}
|
|
172
|
+
interface SpanData {
|
|
173
|
+
traceId: string;
|
|
174
|
+
spanId: string;
|
|
175
|
+
parentSpanId?: string;
|
|
176
|
+
name: string;
|
|
177
|
+
type?: SpanType;
|
|
178
|
+
startTime: number;
|
|
179
|
+
endTime?: number;
|
|
180
|
+
status: SpanStatus;
|
|
181
|
+
attributes: Record<string, unknown>;
|
|
182
|
+
events: SpanEvent[];
|
|
183
|
+
result?: SpanResult;
|
|
184
|
+
}
|
|
185
|
+
interface SpanOptions {
|
|
186
|
+
type?: SpanType;
|
|
187
|
+
}
|
|
188
|
+
type SpanResult = LLMResult | ToolResult;
|
|
189
|
+
interface LLMResult {
|
|
190
|
+
kind: "llm";
|
|
191
|
+
model: string;
|
|
192
|
+
request: LLMRequest;
|
|
193
|
+
response: LLMResponse;
|
|
194
|
+
usage?: TokenUsage;
|
|
195
|
+
finishReason?: string;
|
|
196
|
+
}
|
|
197
|
+
interface LLMRequest {
|
|
198
|
+
messages: unknown[];
|
|
199
|
+
system?: string;
|
|
200
|
+
tools?: unknown[];
|
|
201
|
+
}
|
|
202
|
+
interface LLMResponse {
|
|
203
|
+
content: unknown;
|
|
204
|
+
}
|
|
205
|
+
interface TokenUsage {
|
|
206
|
+
inputTokens?: number;
|
|
207
|
+
outputTokens?: number;
|
|
208
|
+
totalTokens?: number;
|
|
209
|
+
cachedInputTokens?: number;
|
|
210
|
+
cacheWriteInputTokens?: number;
|
|
211
|
+
reasoningOutputTokens?: number;
|
|
212
|
+
}
|
|
213
|
+
interface ToolResult {
|
|
214
|
+
kind: "tool";
|
|
215
|
+
name: string;
|
|
216
|
+
input: unknown;
|
|
217
|
+
output: unknown;
|
|
218
|
+
}
|
|
219
|
+
interface TraceWriter {
|
|
220
|
+
onSpanStart(span: SpanData): void;
|
|
221
|
+
onSpanUpdate?(span: SpanData): void;
|
|
222
|
+
onSpanEnd(span: SpanData): void;
|
|
223
|
+
onEvent?(span: SpanData, event: SpanEvent): void;
|
|
224
|
+
flush?(): Promise<void>;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Tracing context for a span. Created by Tracer.startSpan().
|
|
228
|
+
* Can create child spans and log events within the span's scope.
|
|
229
|
+
*/
|
|
230
|
+
interface TracingContext {
|
|
231
|
+
startSpan(name: string, options?: SpanOptions): TracingContext;
|
|
232
|
+
end(status?: SpanStatus): void;
|
|
233
|
+
debug(message: string, attributes?: Record<string, unknown>): void;
|
|
234
|
+
info(message: string, attributes?: Record<string, unknown>): void;
|
|
235
|
+
warn(message: string, attributes?: Record<string, unknown>): void;
|
|
236
|
+
error(message: string, attributes?: Record<string, unknown>): void;
|
|
237
|
+
setAttribute(key: string, value: unknown): void;
|
|
238
|
+
setAttributes(attributes: Record<string, unknown>): void;
|
|
239
|
+
setResult(result: SpanResult): void;
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/utils/file.d.ts
|
|
243
|
+
type FileKind = "image" | "document" | "text";
|
|
244
|
+
type TextSource = {
|
|
245
|
+
type: "text";
|
|
246
|
+
content: string;
|
|
247
|
+
} | {
|
|
248
|
+
type: "url";
|
|
249
|
+
url: string;
|
|
250
|
+
} | {
|
|
251
|
+
type: "ref";
|
|
252
|
+
ref: unknown;
|
|
253
|
+
};
|
|
254
|
+
type BinarySource = {
|
|
255
|
+
type: "base64";
|
|
256
|
+
data: string;
|
|
257
|
+
} | {
|
|
258
|
+
type: "url";
|
|
259
|
+
url: string;
|
|
260
|
+
} | {
|
|
261
|
+
type: "ref";
|
|
262
|
+
ref: unknown;
|
|
263
|
+
};
|
|
264
|
+
interface BaseFile {
|
|
265
|
+
mimeType: string;
|
|
266
|
+
name: string;
|
|
267
|
+
size?: number;
|
|
268
|
+
}
|
|
269
|
+
type TextFileInfo = BaseFile & {
|
|
270
|
+
kind: "text";
|
|
271
|
+
source: TextSource;
|
|
272
|
+
};
|
|
273
|
+
type BinaryFileInfo = BaseFile & {
|
|
274
|
+
kind: "image" | "document";
|
|
275
|
+
source: BinarySource;
|
|
276
|
+
};
|
|
277
|
+
type FileInfo = TextFileInfo | BinaryFileInfo;
|
|
278
|
+
type InlineTextFile = TextFileInfo & {
|
|
279
|
+
source: {
|
|
280
|
+
type: "text";
|
|
281
|
+
content: string;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
type InlineBinaryFile = BinaryFileInfo & {
|
|
285
|
+
source: {
|
|
286
|
+
type: "base64";
|
|
287
|
+
data: string;
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
type DeferredFileInfo = FileInfo & {
|
|
291
|
+
source: {
|
|
292
|
+
type: "ref";
|
|
293
|
+
ref: unknown;
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
type ConcreteFileInfo = FileInfo & {
|
|
297
|
+
source: {
|
|
298
|
+
type: "text";
|
|
299
|
+
} | {
|
|
300
|
+
type: "base64";
|
|
301
|
+
} | {
|
|
302
|
+
type: "url";
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
type FileProviderId = "anthropic" | "openai" | "gemini" | "chatcompletions";
|
|
306
|
+
type FileResolveFormat = "base64" | "url" | "text" | "gemini-file-uri";
|
|
307
|
+
type ResolvedFileSource = {
|
|
308
|
+
type: "base64";
|
|
309
|
+
data: string;
|
|
310
|
+
mimeType?: string;
|
|
311
|
+
name?: string;
|
|
312
|
+
} | {
|
|
313
|
+
type: "url";
|
|
314
|
+
url: string;
|
|
315
|
+
mimeType?: string;
|
|
316
|
+
name?: string;
|
|
317
|
+
} | {
|
|
318
|
+
type: "text";
|
|
319
|
+
content: string;
|
|
320
|
+
mimeType?: string;
|
|
321
|
+
name?: string;
|
|
322
|
+
} | {
|
|
323
|
+
type: "gemini-file-uri";
|
|
324
|
+
uri: string;
|
|
325
|
+
mimeType?: string;
|
|
326
|
+
name?: string;
|
|
327
|
+
};
|
|
328
|
+
interface FileResolveRequest {
|
|
329
|
+
file: DeferredFileInfo;
|
|
330
|
+
ref: unknown;
|
|
331
|
+
provider: FileProviderId;
|
|
332
|
+
model: string;
|
|
333
|
+
accepted: FileResolveFormat[];
|
|
334
|
+
signal?: AbortSignal;
|
|
335
|
+
}
|
|
336
|
+
type FileResolver = (request: FileResolveRequest) => Promise<ResolvedFileSource>;
|
|
337
|
+
/**
|
|
338
|
+
* Load a file with the specified encoding or auto-detect based on file extension
|
|
339
|
+
* @param filePath - Path to the file
|
|
340
|
+
* @param encoding - How to load the file: "utf-8" for text, "base64" for binary, or omit for auto-detection
|
|
341
|
+
* @returns FileInfo object with appropriate content based on encoding
|
|
342
|
+
*/
|
|
343
|
+
declare function loadFileContent(filePath: string): Promise<FileInfo>;
|
|
344
|
+
declare function loadFileContent(filePath: string, encoding: "utf-8"): Promise<InlineTextFile>;
|
|
345
|
+
declare function loadFileContent(filePath: string, encoding: "base64"): Promise<InlineBinaryFile>;
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region src/providers/types.d.ts
|
|
348
|
+
/**
|
|
349
|
+
* Internal services available to provider adapters while executing a model request.
|
|
350
|
+
*/
|
|
351
|
+
interface ProviderRuntime {
|
|
352
|
+
/** Request-scoped tracing span used by provider adapters. */
|
|
353
|
+
tracer?: TracingContext;
|
|
354
|
+
/** Resolves file references before provider-specific request conversion. */
|
|
355
|
+
fileResolver?: FileResolver;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Raw provider-specific request fields.
|
|
359
|
+
*
|
|
360
|
+
* Provider adapters apply this after Axle-normalized options, so these values
|
|
361
|
+
* can intentionally override Axle's provider mappings.
|
|
362
|
+
*/
|
|
363
|
+
interface ProviderOptions {
|
|
364
|
+
[key: string]: any;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Controls how the model may use tools during a single model request.
|
|
368
|
+
*/
|
|
369
|
+
type ToolChoice = "auto" | "none" | "required" | {
|
|
370
|
+
type: "tool";
|
|
371
|
+
name: string;
|
|
372
|
+
};
|
|
373
|
+
/**
|
|
374
|
+
* Provider-portable options for a single model request.
|
|
375
|
+
*
|
|
376
|
+
* These fields are normalized by Axle and mapped to each provider's request
|
|
377
|
+
* shape. Use `providerOptions` for provider-specific controls that are not
|
|
378
|
+
* represented here.
|
|
379
|
+
*/
|
|
380
|
+
interface AxleModelRequestOptions {
|
|
381
|
+
/** Enables or disables provider reasoning/thinking controls where supported. */
|
|
382
|
+
reasoning?: boolean;
|
|
383
|
+
/** Maximum output tokens to request from the model. */
|
|
384
|
+
maxOutputTokens?: number;
|
|
385
|
+
/** Sampling temperature, when supported by the provider/model. */
|
|
386
|
+
temperature?: number;
|
|
387
|
+
/** Nucleus sampling value, mapped to provider-specific casing. */
|
|
388
|
+
topP?: number;
|
|
389
|
+
/** Stop sequence or sequences for text generation. */
|
|
390
|
+
stop?: string | string[];
|
|
391
|
+
/** Constrains tool use for this model request. */
|
|
392
|
+
toolChoice?: ToolChoice;
|
|
393
|
+
/** Requests that the provider avoid parallel tool calls when supported. */
|
|
394
|
+
parallelToolCalls?: boolean;
|
|
395
|
+
/** Raw provider-specific request fields applied after normalized mappings. */
|
|
396
|
+
providerOptions?: ProviderOptions;
|
|
397
|
+
/** Abort signal for the in-flight model request. */
|
|
398
|
+
signal?: AbortSignal;
|
|
399
|
+
}
|
|
400
|
+
interface AIProvider {
|
|
401
|
+
get name(): string;
|
|
402
|
+
/** @internal */
|
|
403
|
+
createGenerationRequest(model: string, params: ProviderGenerationParams): Promise<ModelResult>;
|
|
404
|
+
/** @internal */
|
|
405
|
+
createStreamingRequest(model: string, params: ProviderStreamParams): AsyncGenerator<AnyStreamChunk, void, unknown>;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Parameters passed to provider adapters for one non-streaming generation call.
|
|
409
|
+
*/
|
|
410
|
+
interface ProviderGenerationParams extends AxleModelRequestOptions {
|
|
411
|
+
/** Conversation messages to send to the provider. */
|
|
412
|
+
messages: Array<AxleMessage>;
|
|
413
|
+
/** Optional system/developer instruction for the request. */
|
|
414
|
+
system?: string;
|
|
415
|
+
/** Executable tools exposed as provider function tools. */
|
|
416
|
+
tools?: Array<ToolDefinition>;
|
|
417
|
+
/** Provider-managed tools such as web search or code execution. */
|
|
418
|
+
providerTools?: Array<ProviderTool>;
|
|
419
|
+
/** Internal services available during provider request creation. */
|
|
420
|
+
runtime: ProviderRuntime;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Parameters passed to provider adapters for one streaming generation call.
|
|
424
|
+
*/
|
|
425
|
+
interface ProviderStreamParams extends ProviderGenerationParams {}
|
|
426
|
+
interface ModelResponse {
|
|
427
|
+
type: "success";
|
|
428
|
+
role: "assistant";
|
|
429
|
+
id: string;
|
|
430
|
+
model: string;
|
|
431
|
+
text: string;
|
|
432
|
+
content: Array<ContentPartText | ContentPartThinking | ContentPartToolCall>;
|
|
433
|
+
finishReason: AxleStopReason;
|
|
434
|
+
usage: Stats;
|
|
435
|
+
raw: any;
|
|
436
|
+
}
|
|
437
|
+
interface ModelError {
|
|
438
|
+
type: "error";
|
|
439
|
+
error: {
|
|
440
|
+
type: string;
|
|
441
|
+
message: string;
|
|
442
|
+
};
|
|
443
|
+
usage?: Stats;
|
|
444
|
+
raw?: any;
|
|
445
|
+
}
|
|
446
|
+
type ModelResult = ModelResponse | ModelError;
|
|
447
|
+
interface ContextUsage {
|
|
448
|
+
total: number;
|
|
449
|
+
system: number;
|
|
450
|
+
tools: number;
|
|
451
|
+
mcpTools: number;
|
|
452
|
+
providerTools: number;
|
|
453
|
+
messages: number;
|
|
454
|
+
limit?: number;
|
|
455
|
+
free?: number;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Client-level transport options for provider adapters.
|
|
459
|
+
*
|
|
460
|
+
* These options are applied when the provider client is constructed, not per
|
|
461
|
+
* model request.
|
|
462
|
+
*/
|
|
463
|
+
interface ProviderClientOptions {
|
|
464
|
+
/**
|
|
465
|
+
* Number of retry attempts after the first request. Axle's built-in
|
|
466
|
+
* providers default to `2`; use `0` to disable retries.
|
|
467
|
+
*/
|
|
468
|
+
maxRetries?: number;
|
|
469
|
+
/**
|
|
470
|
+
* Request timeout in milliseconds. Omit to use the provider SDK default.
|
|
471
|
+
*/
|
|
472
|
+
timeoutMs?: number;
|
|
473
|
+
}
|
|
474
|
+
declare enum AxleStopReason {
|
|
475
|
+
Stop = "stop",
|
|
476
|
+
Length = "length",
|
|
477
|
+
FunctionCall = "function_call",
|
|
478
|
+
Error = "error",
|
|
479
|
+
Custom = "custom",
|
|
480
|
+
Cancelled = "cancelled"
|
|
481
|
+
}
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/messages/message.d.ts
|
|
484
|
+
/**
|
|
485
|
+
* Model-facing conversation message.
|
|
486
|
+
*
|
|
487
|
+
* This is Axle's canonical conversation state. Providers consume these
|
|
488
|
+
* messages after adapter-specific conversion, while turns are derived from
|
|
489
|
+
* them for presentation.
|
|
490
|
+
*/
|
|
491
|
+
type AxleMessage = AxleUserMessage | AxleAssistantMessage | AxleToolCallMessage;
|
|
492
|
+
/**
|
|
493
|
+
* Host-owned render metadata attached to a message.
|
|
494
|
+
*
|
|
495
|
+
* Providers ignore this data; it exists so hosts can carry stable presentation
|
|
496
|
+
* hints through history and into renderable turns.
|
|
497
|
+
*/
|
|
498
|
+
type MessageMetadata = Record<string, unknown>;
|
|
499
|
+
/**
|
|
500
|
+
* Content returned by a tool call.
|
|
501
|
+
*
|
|
502
|
+
* Tool results may be simple text or structured parts when the result includes
|
|
503
|
+
* file data.
|
|
504
|
+
*/
|
|
505
|
+
type ToolResultPart = {
|
|
506
|
+
type: "text";
|
|
507
|
+
text: string;
|
|
508
|
+
} | {
|
|
509
|
+
type: "file";
|
|
510
|
+
file: ConcreteFileInfo;
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* Message authored by the user or host application.
|
|
514
|
+
*/
|
|
515
|
+
interface AxleUserMessage {
|
|
516
|
+
/** Message role discriminator. */
|
|
517
|
+
role: "user";
|
|
518
|
+
/** Stable message id. Generated by Axle when a user turn is compiled. */
|
|
519
|
+
id?: string;
|
|
520
|
+
/** Optional user name passed through to providers that support it. */
|
|
521
|
+
name?: string;
|
|
522
|
+
/** User-authored text or mixed content parts. */
|
|
523
|
+
content: string | Array<ContentPart>;
|
|
524
|
+
/** Stable host-owned render metadata copied to the corresponding user turn. */
|
|
525
|
+
metadata?: MessageMetadata;
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Message authored by the assistant/model.
|
|
529
|
+
*/
|
|
530
|
+
interface AxleAssistantMessage {
|
|
531
|
+
/** Message role discriminator. */
|
|
532
|
+
role: "assistant";
|
|
533
|
+
/** Stable assistant message id. */
|
|
534
|
+
id: string;
|
|
535
|
+
/** Model identifier that produced this message, when known. */
|
|
536
|
+
model?: string;
|
|
537
|
+
/** Assistant content parts in model order. */
|
|
538
|
+
content: Array<ContentPartText | ContentPartThinking | ContentPartToolCall | ContentPartProviderTool>;
|
|
539
|
+
/** Provider-normalized reason the assistant message stopped. */
|
|
540
|
+
finishReason?: AxleStopReason;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Message carrying results for one or more tool calls.
|
|
544
|
+
*/
|
|
545
|
+
interface AxleToolCallMessage {
|
|
546
|
+
/** Message role discriminator. */
|
|
547
|
+
role: "tool";
|
|
548
|
+
/** Stable tool-result message id. */
|
|
549
|
+
id: string;
|
|
550
|
+
/** Tool call results included in this message. */
|
|
551
|
+
content: Array<AxleToolCallResult>;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Result payload for a single tool call.
|
|
555
|
+
*/
|
|
556
|
+
interface AxleToolCallResult {
|
|
557
|
+
/** Tool call id this result answers. */
|
|
558
|
+
id: string;
|
|
559
|
+
/** Tool name that produced the result. */
|
|
560
|
+
name: string;
|
|
561
|
+
/** Tool result content. */
|
|
562
|
+
content: string | ToolResultPart[];
|
|
563
|
+
/** Whether the tool result represents an execution error. */
|
|
564
|
+
isError?: boolean;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Any content part Axle can carry in a user or assistant message.
|
|
568
|
+
*/
|
|
569
|
+
type ContentPart = ContentPartText | ContentPartFile | ContentPartToolCall | ContentPartThinking | ContentPartProviderTool;
|
|
570
|
+
/**
|
|
571
|
+
* Plain text content.
|
|
572
|
+
*/
|
|
573
|
+
interface ContentPartText {
|
|
574
|
+
/** Part discriminator. */
|
|
575
|
+
type: "text";
|
|
576
|
+
/** Text content. */
|
|
577
|
+
text: string;
|
|
578
|
+
/** Source citations that support spans of this text, when supplied by the provider. */
|
|
579
|
+
citations?: Citation[];
|
|
580
|
+
/** Provider-specific metadata that is not part of Axle's normalized contract. */
|
|
581
|
+
providerMetadata?: Record<string, unknown>;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* File attachment content.
|
|
585
|
+
*/
|
|
586
|
+
interface ContentPartFile {
|
|
587
|
+
/** Part discriminator. */
|
|
588
|
+
type: "file";
|
|
589
|
+
/** File metadata and source reference. */
|
|
590
|
+
file: FileInfo;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Model reasoning or thinking content.
|
|
594
|
+
*/
|
|
595
|
+
interface ContentPartThinking {
|
|
596
|
+
/** Part discriminator. */
|
|
597
|
+
type: "thinking";
|
|
598
|
+
/** Provider thinking block id, when supplied. */
|
|
599
|
+
id?: string;
|
|
600
|
+
/** Renderable reasoning text content, when the provider exposes it. */
|
|
601
|
+
text?: string;
|
|
602
|
+
/** Optional provider-supplied reasoning summary. */
|
|
603
|
+
summary?: string;
|
|
604
|
+
/** Whether the provider redacted the reasoning content. */
|
|
605
|
+
redacted?: boolean;
|
|
606
|
+
/** Provider continuity payload that should be preserved for future requests. */
|
|
607
|
+
continuity?: ThinkingContinuity;
|
|
608
|
+
/** Provider-specific metadata that is not part of Axle's normalized contract. */
|
|
609
|
+
providerMetadata?: Record<string, unknown>;
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Source attribution attached to model text.
|
|
613
|
+
*
|
|
614
|
+
* Providers expose citations with different source records and locator
|
|
615
|
+
* metadata. Axle keeps the common renderable surface small: what source is
|
|
616
|
+
* cited, and where that citation applies in the generated output text.
|
|
617
|
+
*/
|
|
618
|
+
interface Citation {
|
|
619
|
+
/** Source being cited. */
|
|
620
|
+
source: CitationSource;
|
|
621
|
+
/** Character/byte offsets in the generated output text, when supplied. */
|
|
622
|
+
outputSpan?: CitationOutputSpan;
|
|
623
|
+
/** Provider-specific citation payload fields not covered by the normalized shape. */
|
|
624
|
+
providerMetadata?: Record<string, unknown>;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Citation source categories Axle currently normalizes from provider APIs.
|
|
628
|
+
*/
|
|
629
|
+
type CitationSource = {
|
|
630
|
+
type: "web";
|
|
631
|
+
title?: string;
|
|
632
|
+
url: string;
|
|
633
|
+
citedText?: string;
|
|
634
|
+
} | {
|
|
635
|
+
type: "document";
|
|
636
|
+
title?: string;
|
|
637
|
+
fileId?: string;
|
|
638
|
+
citedText?: string;
|
|
639
|
+
locator?: DocumentLocator;
|
|
640
|
+
} | {
|
|
641
|
+
type: "search-result";
|
|
642
|
+
title?: string;
|
|
643
|
+
url?: string;
|
|
644
|
+
citedText?: string;
|
|
645
|
+
locator?: DocumentLocator;
|
|
646
|
+
} | {
|
|
647
|
+
type: "retrieved-context";
|
|
648
|
+
title?: string;
|
|
649
|
+
uri?: string;
|
|
650
|
+
citedText?: string;
|
|
651
|
+
locator?: DocumentLocator;
|
|
652
|
+
} | {
|
|
653
|
+
type: "unknown";
|
|
654
|
+
citedText?: string;
|
|
655
|
+
};
|
|
656
|
+
/**
|
|
657
|
+
* Provider-reported location inside a cited source.
|
|
658
|
+
*/
|
|
659
|
+
type DocumentLocator = {
|
|
660
|
+
type: "char";
|
|
661
|
+
start?: number;
|
|
662
|
+
end?: number;
|
|
663
|
+
} | {
|
|
664
|
+
type: "page";
|
|
665
|
+
start?: number;
|
|
666
|
+
end?: number;
|
|
667
|
+
} | {
|
|
668
|
+
type: "block";
|
|
669
|
+
start?: number;
|
|
670
|
+
end?: number;
|
|
671
|
+
} | {
|
|
672
|
+
type: "part";
|
|
673
|
+
index?: number;
|
|
674
|
+
};
|
|
675
|
+
/**
|
|
676
|
+
* Citation coordinates in generated output text.
|
|
677
|
+
*/
|
|
678
|
+
interface CitationOutputSpan {
|
|
679
|
+
/** Inclusive output offset. */
|
|
680
|
+
start?: number;
|
|
681
|
+
/** Exclusive output offset. */
|
|
682
|
+
end?: number;
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Opaque provider state needed to continue reasoning across requests.
|
|
686
|
+
*/
|
|
687
|
+
type ThinkingContinuity = {
|
|
688
|
+
provider: "openai";
|
|
689
|
+
encrypted: string;
|
|
690
|
+
} | {
|
|
691
|
+
provider: "anthropic";
|
|
692
|
+
signature?: string;
|
|
693
|
+
redactedData?: string;
|
|
694
|
+
} | {
|
|
695
|
+
provider: "gemini";
|
|
696
|
+
thoughtSignature: string;
|
|
697
|
+
};
|
|
698
|
+
/**
|
|
699
|
+
* Axle-managed tool call request emitted by the assistant.
|
|
700
|
+
*/
|
|
701
|
+
interface ContentPartToolCall {
|
|
702
|
+
/** Part discriminator. */
|
|
703
|
+
type: "tool-call";
|
|
704
|
+
/** Tool call id used to pair the call with its result. */
|
|
705
|
+
id: string;
|
|
706
|
+
/** Tool name to execute. */
|
|
707
|
+
name: string;
|
|
708
|
+
/** Parsed tool parameters. */
|
|
709
|
+
parameters: Record<string, unknown>;
|
|
710
|
+
/** Provider-specific metadata associated with the tool call. */
|
|
711
|
+
providerMetadata?: Record<string, unknown>;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Provider-managed built-in tool call or result.
|
|
715
|
+
*/
|
|
716
|
+
interface ContentPartProviderTool {
|
|
717
|
+
/** Part discriminator. */
|
|
718
|
+
type: "provider-tool";
|
|
719
|
+
/** Provider tool call id. */
|
|
720
|
+
id: string;
|
|
721
|
+
/** Provider tool name. */
|
|
722
|
+
name: string;
|
|
723
|
+
/** Provider-specific tool input. */
|
|
724
|
+
input?: unknown;
|
|
725
|
+
/** Provider-specific tool output. */
|
|
726
|
+
output?: unknown;
|
|
727
|
+
}
|
|
728
|
+
//#endregion
|
|
729
|
+
//#region src/tools/registry.d.ts
|
|
730
|
+
declare class ToolRegistry {
|
|
731
|
+
private tools;
|
|
732
|
+
private mcpTools;
|
|
733
|
+
private providerTools;
|
|
734
|
+
constructor(init?: {
|
|
735
|
+
tools?: ExecutableTool[];
|
|
736
|
+
providerTools?: ProviderTool[];
|
|
737
|
+
});
|
|
738
|
+
add(tool: ExecutableTool): void;
|
|
739
|
+
add(tools: ExecutableTool[]): void;
|
|
740
|
+
addMcp(tool: ExecutableTool): void;
|
|
741
|
+
addMcp(tools: ExecutableTool[]): void;
|
|
742
|
+
addProvider(tool: ProviderTool): void;
|
|
743
|
+
addProvider(tools: ProviderTool[]): void;
|
|
744
|
+
remove(name: string): boolean;
|
|
745
|
+
has(name: string): boolean;
|
|
746
|
+
get(name: string): ExecutableTool | undefined;
|
|
747
|
+
getProvider(name: string): ProviderTool | undefined;
|
|
748
|
+
executable(): ExecutableTool[];
|
|
749
|
+
local(): ExecutableTool[];
|
|
750
|
+
mcp(): ExecutableTool[];
|
|
751
|
+
provider(): ProviderTool[];
|
|
752
|
+
get size(): number;
|
|
753
|
+
}
|
|
754
|
+
//#endregion
|
|
755
|
+
//#region src/tools/types.d.ts
|
|
756
|
+
interface ToolContext {
|
|
757
|
+
registry: ToolRegistry;
|
|
758
|
+
signal: AbortSignal;
|
|
759
|
+
emit: (chunk: string) => void;
|
|
760
|
+
tracer?: TracingContext;
|
|
761
|
+
}
|
|
762
|
+
interface ExecutableTool<TSchema extends ZodObject<any> = ZodObject<any>> {
|
|
763
|
+
type?: "function";
|
|
764
|
+
name: string;
|
|
765
|
+
description: string;
|
|
766
|
+
schema: TSchema;
|
|
767
|
+
execute(input: z.infer<TSchema>, ctx: ToolContext): Promise<string | ToolResultPart[]>;
|
|
768
|
+
configure?(config: Record<string, any>): void;
|
|
769
|
+
summarize?(input: z.infer<TSchema>): string;
|
|
770
|
+
}
|
|
771
|
+
interface ProviderTool {
|
|
772
|
+
type: "provider";
|
|
773
|
+
name: string;
|
|
774
|
+
config?: Record<string, unknown>;
|
|
775
|
+
}
|
|
776
|
+
type ToolDefinition = Pick<ExecutableTool, "name" | "description" | "schema">;
|
|
777
|
+
//#endregion
|
|
778
|
+
//#region src/turns/types.d.ts
|
|
779
|
+
/**
|
|
780
|
+
* Lifecycle state for a renderable turn.
|
|
781
|
+
*
|
|
782
|
+
* Turns are presentation state. They describe what a consumer can render, not
|
|
783
|
+
* the canonical model conversation state.
|
|
784
|
+
*/
|
|
785
|
+
type TurnStatus = "streaming" | "complete" | "cancelled" | "error";
|
|
786
|
+
/**
|
|
787
|
+
* Host-owned stable render metadata attached to a turn.
|
|
788
|
+
*
|
|
789
|
+
* Metadata is not model state and has no lifecycle. Use annotations for
|
|
790
|
+
* mutable, async, or explicitly placed UI state.
|
|
791
|
+
*/
|
|
792
|
+
type TurnMetadata = Record<string, unknown>;
|
|
793
|
+
/**
|
|
794
|
+
* ISO timestamp metadata for a turn, part, action, or annotation.
|
|
795
|
+
*/
|
|
796
|
+
interface TimingInfo {
|
|
797
|
+
/** ISO timestamp for when the item started. */
|
|
798
|
+
start: string;
|
|
799
|
+
/** ISO timestamp for when the item finished, when known. */
|
|
800
|
+
end?: string;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* Where an annotation should render relative to its target.
|
|
804
|
+
*/
|
|
805
|
+
type AnnotationPlacement = "before" | "after";
|
|
806
|
+
/**
|
|
807
|
+
* Lifecycle state for an annotation.
|
|
808
|
+
*
|
|
809
|
+
* Omit this for static/informational annotations that do not have a running or
|
|
810
|
+
* terminal state.
|
|
811
|
+
*/
|
|
812
|
+
type AnnotationStatus = "running" | "complete" | "cancelled" | "error";
|
|
813
|
+
/**
|
|
814
|
+
* Render metadata attached to a session, turn, or turn part.
|
|
815
|
+
*
|
|
816
|
+
* Annotations let hosts attach out-of-band UI such as sandbox startup, eval
|
|
817
|
+
* results, or deployment state without turning that data into model state.
|
|
818
|
+
*
|
|
819
|
+
* @typeParam TData - Consumer-owned payload for the annotation kind.
|
|
820
|
+
* @typeParam TKind - Discriminator for the annotation kind.
|
|
821
|
+
*/
|
|
822
|
+
interface Annotation<TData = unknown, TKind extends string = string> {
|
|
823
|
+
/** Globally unique annotation id. */
|
|
824
|
+
id: string;
|
|
825
|
+
/** Consumer-defined annotation kind, used as a discriminator. */
|
|
826
|
+
kind: TKind;
|
|
827
|
+
/** Human-readable label for generic renderers. */
|
|
828
|
+
label: string;
|
|
829
|
+
/** Render placement relative to the target. Defaults to `"after"` when accumulated. */
|
|
830
|
+
placement?: AnnotationPlacement;
|
|
831
|
+
/** Optional lifecycle state for the annotation. */
|
|
832
|
+
status?: AnnotationStatus;
|
|
833
|
+
/** Consumer-owned annotation payload. */
|
|
834
|
+
data?: TData;
|
|
835
|
+
/** Optional timing metadata. */
|
|
836
|
+
timing?: TimingInfo;
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Renderable presentation state for one user or agent turn.
|
|
840
|
+
*
|
|
841
|
+
* `Turn` is the snapshot counterpart to `TurnEvent`: events describe changes,
|
|
842
|
+
* and turns are the accumulated render state. The model-facing conversation
|
|
843
|
+
* remains `AxleMessage[]`.
|
|
844
|
+
*
|
|
845
|
+
* @typeParam TAnnotation - Annotation union supported by the host renderer.
|
|
846
|
+
*/
|
|
847
|
+
interface Turn<TAnnotation extends Annotation = Annotation> {
|
|
848
|
+
/** Stable turn id. */
|
|
849
|
+
id: string;
|
|
850
|
+
/** Whether the turn was produced by the user or the agent. */
|
|
851
|
+
owner: "user" | "agent";
|
|
852
|
+
/** Renderable parts in display order. */
|
|
853
|
+
parts: TurnPart<TAnnotation>[];
|
|
854
|
+
/** Current lifecycle state for the turn. */
|
|
855
|
+
status: TurnStatus;
|
|
856
|
+
/** Annotations attached to the whole turn. */
|
|
857
|
+
annotations?: TAnnotation[];
|
|
858
|
+
/** Stable host-owned render metadata copied from the source message. */
|
|
859
|
+
metadata?: TurnMetadata;
|
|
860
|
+
/** Optional timing metadata. */
|
|
861
|
+
timing?: TimingInfo;
|
|
862
|
+
/** Token usage accumulated for this turn, when available. */
|
|
863
|
+
usage?: Stats;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Any renderable part within a turn.
|
|
867
|
+
*/
|
|
868
|
+
type TurnPart<TAnnotation extends Annotation = Annotation> = TextPart<TAnnotation> | FilePart<TAnnotation> | ThinkingPart<TAnnotation> | ActionPart<TAnnotation>;
|
|
869
|
+
/**
|
|
870
|
+
* Assistant or user text content.
|
|
871
|
+
*/
|
|
872
|
+
interface TextPart<TAnnotation extends Annotation = Annotation> {
|
|
873
|
+
/** Stable part id. */
|
|
874
|
+
id: string;
|
|
875
|
+
/** Part discriminator. */
|
|
876
|
+
type: "text";
|
|
877
|
+
/** Accumulated text content. */
|
|
878
|
+
text: string;
|
|
879
|
+
/** Source citations that support spans of this text, when supplied by the provider. */
|
|
880
|
+
citations?: Citation[];
|
|
881
|
+
/** Provider-specific metadata that is not part of Axle's normalized contract. */
|
|
882
|
+
providerMetadata?: Record<string, unknown>;
|
|
883
|
+
/** Annotations attached to this part. */
|
|
884
|
+
annotations?: TAnnotation[];
|
|
885
|
+
/** Optional timing metadata. */
|
|
886
|
+
timing?: TimingInfo;
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* File content attached to a user turn.
|
|
890
|
+
*/
|
|
891
|
+
interface FilePart<TAnnotation extends Annotation = Annotation> {
|
|
892
|
+
/** Stable part id. */
|
|
893
|
+
id: string;
|
|
894
|
+
/** Part discriminator. */
|
|
895
|
+
type: "file";
|
|
896
|
+
/** File metadata and source reference. */
|
|
897
|
+
file: FileInfo;
|
|
898
|
+
/** Annotations attached to this part. */
|
|
899
|
+
annotations?: TAnnotation[];
|
|
900
|
+
/** Optional timing metadata. */
|
|
901
|
+
timing?: TimingInfo;
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Model thinking or reasoning content when surfaced by the provider.
|
|
905
|
+
*/
|
|
906
|
+
interface ThinkingPart<TAnnotation extends Annotation = Annotation> {
|
|
907
|
+
/** Stable part id. */
|
|
908
|
+
id: string;
|
|
909
|
+
/** Part discriminator. */
|
|
910
|
+
type: "thinking";
|
|
911
|
+
/** Accumulated renderable thinking text, when the provider exposes it. */
|
|
912
|
+
text?: string;
|
|
913
|
+
/** Optional provider-supplied summary. */
|
|
914
|
+
summary?: string;
|
|
915
|
+
/** Whether the provider marked the thinking content as redacted. */
|
|
916
|
+
redacted?: boolean;
|
|
917
|
+
/** Provider continuity payload that should be preserved for future requests. */
|
|
918
|
+
continuity?: ThinkingContinuity;
|
|
919
|
+
/** Provider-specific metadata that is not part of Axle's normalized contract. */
|
|
920
|
+
providerMetadata?: Record<string, unknown>;
|
|
921
|
+
/** Annotations attached to this part. */
|
|
922
|
+
annotations?: TAnnotation[];
|
|
923
|
+
/** Optional timing metadata. */
|
|
924
|
+
timing?: TimingInfo;
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Shared fields for tool, subagent, and provider-managed actions.
|
|
928
|
+
*
|
|
929
|
+
* @internal
|
|
930
|
+
*/
|
|
931
|
+
interface ActionPartBase<TAnnotation extends Annotation = Annotation> {
|
|
932
|
+
id: string;
|
|
933
|
+
type: "action";
|
|
934
|
+
kind: string;
|
|
935
|
+
status: "pending" | "running" | "complete" | "cancelled" | "error";
|
|
936
|
+
annotations?: TAnnotation[];
|
|
937
|
+
timing?: TimingInfo;
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Action part for an executable Axle tool call.
|
|
941
|
+
*/
|
|
942
|
+
interface ToolAction<TAnnotation extends Annotation = Annotation> extends ActionPartBase<TAnnotation> {
|
|
943
|
+
/** Action discriminator. */
|
|
944
|
+
kind: "tool";
|
|
945
|
+
/** Tool display and execution details. */
|
|
946
|
+
detail: {
|
|
947
|
+
/** Tool name. */name: string; /** Parsed tool parameters once execution starts. */
|
|
948
|
+
parameters: Record<string, unknown>; /** Accumulated JSON argument text before parameters are parsed. */
|
|
949
|
+
pendingArgs?: string; /** Tool result or in-progress output. */
|
|
950
|
+
result?: ActionResult;
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Action part for a nested agent/subagent run.
|
|
955
|
+
*/
|
|
956
|
+
interface SubagentAction<TAnnotation extends Annotation = Annotation> extends ActionPartBase<TAnnotation> {
|
|
957
|
+
/** Action discriminator. */
|
|
958
|
+
kind: "agent";
|
|
959
|
+
/** Subagent display and result details. */
|
|
960
|
+
detail: {
|
|
961
|
+
/** Subagent name. */name: string; /** Optional subagent configuration shown to renderers. */
|
|
962
|
+
config?: Record<string, unknown>; /** Child turns produced by the subagent. */
|
|
963
|
+
children: Turn<TAnnotation>[]; /** Final subagent result, when available. */
|
|
964
|
+
result?: ActionResult;
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Action part for provider-managed tools such as hosted web search or code
|
|
969
|
+
* execution.
|
|
970
|
+
*/
|
|
971
|
+
interface ProviderToolAction<TAnnotation extends Annotation = Annotation> extends ActionPartBase<TAnnotation> {
|
|
972
|
+
/** Action discriminator. */
|
|
973
|
+
kind: "provider-tool";
|
|
974
|
+
/** Provider tool display and result details. */
|
|
975
|
+
detail: {
|
|
976
|
+
/** Provider tool name. */name: string; /** Provider-specific input, when surfaced. */
|
|
977
|
+
input?: unknown; /** Provider tool result, when surfaced. */
|
|
978
|
+
result?: ActionResult;
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* Any action part in a turn.
|
|
983
|
+
*/
|
|
984
|
+
type ActionPart<TAnnotation extends Annotation = Annotation> = ToolAction<TAnnotation> | SubagentAction<TAnnotation> | ProviderToolAction<TAnnotation>;
|
|
985
|
+
/**
|
|
986
|
+
* Renderable result for an action.
|
|
987
|
+
*/
|
|
988
|
+
type ActionResult = {
|
|
989
|
+
type: "in-progress";
|
|
990
|
+
content: string;
|
|
991
|
+
} | {
|
|
992
|
+
type: "success";
|
|
993
|
+
content: unknown;
|
|
994
|
+
} | {
|
|
995
|
+
type: "error";
|
|
996
|
+
error: {
|
|
997
|
+
type: string;
|
|
998
|
+
message: string;
|
|
999
|
+
};
|
|
1000
|
+
};
|
|
1001
|
+
//#endregion
|
|
1002
|
+
//#region src/turns/events.d.ts
|
|
1003
|
+
type AnnotationTarget = {
|
|
1004
|
+
type: "session";
|
|
1005
|
+
} | {
|
|
1006
|
+
type: "turn";
|
|
1007
|
+
turnId: string;
|
|
1008
|
+
} | {
|
|
1009
|
+
type: "part";
|
|
1010
|
+
turnId: string;
|
|
1011
|
+
partId: string;
|
|
1012
|
+
};
|
|
1013
|
+
type AnnotationEvent<TAnnotation extends Annotation = Annotation> = {
|
|
1014
|
+
type: "annotation:start";
|
|
1015
|
+
target: AnnotationTarget;
|
|
1016
|
+
annotation: TAnnotation;
|
|
1017
|
+
} | {
|
|
1018
|
+
type: "annotation:update";
|
|
1019
|
+
target: AnnotationTarget;
|
|
1020
|
+
annotation: TAnnotation;
|
|
1021
|
+
} | {
|
|
1022
|
+
type: "annotation:end";
|
|
1023
|
+
target: AnnotationTarget;
|
|
1024
|
+
annotation: TAnnotation;
|
|
1025
|
+
};
|
|
1026
|
+
type TurnEvent<TAnnotation extends Annotation = Annotation> = {
|
|
1027
|
+
type: "session:restore";
|
|
1028
|
+
turns: Turn<TAnnotation>[];
|
|
1029
|
+
sessionAnnotations?: TAnnotation[];
|
|
1030
|
+
config?: Record<string, unknown>;
|
|
1031
|
+
} | {
|
|
1032
|
+
type: "turn:user";
|
|
1033
|
+
turn: Turn<TAnnotation>;
|
|
1034
|
+
} | {
|
|
1035
|
+
type: "turn:start";
|
|
1036
|
+
turnId: string;
|
|
1037
|
+
timing?: TimingInfo;
|
|
1038
|
+
} | {
|
|
1039
|
+
type: "turn:end";
|
|
1040
|
+
turnId: string;
|
|
1041
|
+
status: TurnStatus;
|
|
1042
|
+
usage: Stats;
|
|
1043
|
+
timing?: TimingInfo;
|
|
1044
|
+
} | {
|
|
1045
|
+
type: "part:start";
|
|
1046
|
+
turnId: string;
|
|
1047
|
+
part: TurnPart<TAnnotation>;
|
|
1048
|
+
} | {
|
|
1049
|
+
type: "text:delta";
|
|
1050
|
+
turnId: string;
|
|
1051
|
+
partId: string;
|
|
1052
|
+
delta: string;
|
|
1053
|
+
} | {
|
|
1054
|
+
type: "text:citation";
|
|
1055
|
+
turnId: string;
|
|
1056
|
+
partId: string;
|
|
1057
|
+
citation: Citation;
|
|
1058
|
+
} | {
|
|
1059
|
+
type: "thinking:delta";
|
|
1060
|
+
turnId: string;
|
|
1061
|
+
partId: string;
|
|
1062
|
+
delta: string;
|
|
1063
|
+
} | {
|
|
1064
|
+
type: "thinking:summary-delta";
|
|
1065
|
+
turnId: string;
|
|
1066
|
+
partId: string;
|
|
1067
|
+
delta: string;
|
|
1068
|
+
} | {
|
|
1069
|
+
type: "thinking:update";
|
|
1070
|
+
turnId: string;
|
|
1071
|
+
partId: string;
|
|
1072
|
+
redacted?: boolean;
|
|
1073
|
+
continuity?: ThinkingContinuity;
|
|
1074
|
+
providerMetadata?: Record<string, unknown>;
|
|
1075
|
+
} | {
|
|
1076
|
+
type: "part:end";
|
|
1077
|
+
turnId: string;
|
|
1078
|
+
partId: string;
|
|
1079
|
+
timing?: TimingInfo;
|
|
1080
|
+
} | {
|
|
1081
|
+
type: "action:args-delta";
|
|
1082
|
+
turnId: string;
|
|
1083
|
+
partId: string;
|
|
1084
|
+
delta: string;
|
|
1085
|
+
accumulated: string;
|
|
1086
|
+
} | {
|
|
1087
|
+
type: "action:running";
|
|
1088
|
+
turnId: string;
|
|
1089
|
+
partId: string;
|
|
1090
|
+
parameters?: Record<string, unknown>;
|
|
1091
|
+
} | {
|
|
1092
|
+
type: "action:progress";
|
|
1093
|
+
turnId: string;
|
|
1094
|
+
partId: string;
|
|
1095
|
+
chunk: string;
|
|
1096
|
+
} | {
|
|
1097
|
+
type: "action:complete";
|
|
1098
|
+
turnId: string;
|
|
1099
|
+
partId: string;
|
|
1100
|
+
result: ActionResult;
|
|
1101
|
+
timing?: TimingInfo;
|
|
1102
|
+
} | {
|
|
1103
|
+
type: "action:error";
|
|
1104
|
+
turnId: string;
|
|
1105
|
+
partId: string;
|
|
1106
|
+
error: {
|
|
1107
|
+
type: string;
|
|
1108
|
+
message: string;
|
|
1109
|
+
};
|
|
1110
|
+
timing?: TimingInfo;
|
|
1111
|
+
} | {
|
|
1112
|
+
type: "action:child-event";
|
|
1113
|
+
turnId: string;
|
|
1114
|
+
partId: string;
|
|
1115
|
+
event: TurnEvent<TAnnotation>;
|
|
1116
|
+
} | AnnotationEvent<TAnnotation> | {
|
|
1117
|
+
type: "error";
|
|
1118
|
+
error: {
|
|
1119
|
+
type: string;
|
|
1120
|
+
message: string;
|
|
1121
|
+
};
|
|
1122
|
+
};
|
|
1123
|
+
//#endregion
|
|
1124
|
+
//#region src/turns/accumulator.d.ts
|
|
1125
|
+
interface TurnAccumulatorState<TAnnotation extends Annotation = Annotation> {
|
|
1126
|
+
turns: Turn<TAnnotation>[];
|
|
1127
|
+
sessionAnnotations?: TAnnotation[];
|
|
1128
|
+
}
|
|
1129
|
+
type UnknownEvent = {
|
|
1130
|
+
type: string;
|
|
1131
|
+
};
|
|
1132
|
+
type AccumulatableEvent<TAnnotation extends Annotation = Annotation, THostEvent extends UnknownEvent = UnknownEvent> = TurnEvent<TAnnotation> | THostEvent;
|
|
1133
|
+
type TurnAccumulatorResult<TAnnotation extends Annotation = Annotation, THostEvent extends UnknownEvent = UnknownEvent> = {
|
|
1134
|
+
handled: true;
|
|
1135
|
+
state: TurnAccumulatorState<TAnnotation>;
|
|
1136
|
+
event: TurnEvent<TAnnotation>;
|
|
1137
|
+
} | {
|
|
1138
|
+
handled: false;
|
|
1139
|
+
state: TurnAccumulatorState<TAnnotation>;
|
|
1140
|
+
event: THostEvent;
|
|
1141
|
+
};
|
|
1142
|
+
declare class TurnAccumulator<TAnnotation extends Annotation = Annotation, THostEvent extends UnknownEvent = UnknownEvent> {
|
|
1143
|
+
private _state;
|
|
1144
|
+
constructor(init?: TurnAccumulatorState<TAnnotation>);
|
|
1145
|
+
get state(): TurnAccumulatorState<TAnnotation>;
|
|
1146
|
+
apply(event: AccumulatableEvent<TAnnotation, THostEvent>): TurnAccumulatorResult<TAnnotation, THostEvent>;
|
|
1147
|
+
private replaceState;
|
|
1148
|
+
private replaceTurns;
|
|
1149
|
+
private updateTurn;
|
|
1150
|
+
private updatePart;
|
|
1151
|
+
private addAnnotation;
|
|
1152
|
+
private replaceAnnotation;
|
|
1153
|
+
private handled;
|
|
1154
|
+
}
|
|
1155
|
+
//#endregion
|
|
1156
|
+
export { ModelResult as $, AxleAssistantMessage as A, ContentPartProviderTool as B, TurnPart as C, ToolContext as D, ProviderTool as E, Citation as F, MessageMetadata as G, ContentPartThinking as H, CitationOutputSpan as I, AIProvider as J, ThinkingContinuity as K, CitationSource as L, AxleToolCallMessage as M, AxleToolCallResult as N, ToolDefinition as O, AxleUserMessage as P, ModelError as Q, ContentPart as R, TurnMetadata as S, ExecutableTool as T, ContentPartToolCall as U, ContentPartText as V, DocumentLocator as W, AxleStopReason as X, AxleModelRequestOptions as Y, ContextUsage as Z, TextPart as _, TraceWriter as _t, UnknownEvent as a, FileKind as at, ToolAction as b, TurnEvent as c, FileResolveRequest as ct, Annotation as d, loadFileContent as dt, ProviderClientOptions as et, AnnotationPlacement as f, EventLevel as ft, SubagentAction as g, SpanType as gt, ProviderToolAction as h, SpanOptions as ht, TurnAccumulatorState as i, FileInfo as it, AxleMessage as j, ToolRegistry as k, ActionPart as l, FileResolver as lt, FilePart as m, SpanEvent as mt, TurnAccumulator as n, ToolChoice as nt, AnnotationEvent as o, FileProviderId as ot, AnnotationStatus as p, SpanData as pt, ToolResultPart as q, TurnAccumulatorResult as r, DeferredFileInfo as rt, AnnotationTarget as s, FileResolveFormat as st, AccumulatableEvent as t, ProviderOptions as tt, ActionResult as u, ResolvedFileSource as ut, ThinkingPart as v, TracingContext as vt, TurnStatus as w, Turn as x, TimingInfo as y, Stats as yt, ContentPartFile as z };
|