@fifthrevision/axle 0.18.0 → 0.20.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/index.d.ts CHANGED
@@ -1,23 +1,7 @@
1
+ import { A as FileResolveRequest, B as TracingContext, C as TurnStatus, D as FileKind, E as FileInfo, F as SpanData, I as SpanEvent, L as SpanOptions, M as ResolvedFileSource, N as loadFileContent, O as FileProviderId, P as EventLevel, R as SpanType, S as TurnPart, T as DeferredFileInfo, V as Stats, _ as TextPart, b as ToolAction, c as TurnEvent, d as Annotation, f as AnnotationPlacement, g as SubagentAction, h as ProviderToolAction, i as TurnAccumulatorState, j as FileResolver, k as FileResolveFormat, l as ActionPart, m as FilePart, n as TurnAccumulator, o as AnnotationEvent, p as AnnotationStatus, r as TurnAccumulatorResult, s as AnnotationTarget, t as AccumulatableEvent, u as ActionResult, v as ThinkingPart, w as ConcreteFileInfo, x as Turn, z as TraceWriter } from "./accumulator-D2NgIGxp.js";
1
2
  import * as z$2 from "zod";
2
3
  import { ZodObject, z } from "zod";
3
4
 
4
- //#region src/types.d.ts
5
- /**
6
- * Token usage reported by a provider response.
7
- */
8
- interface Stats {
9
- /** Total effective input tokens. Includes `cachedIn` and `cacheWriteIn` when reported. */
10
- in: number;
11
- /** Total output tokens. Includes `reasoningOut` when reported. */
12
- out: number;
13
- /** Input tokens served from provider prompt/context cache. Included in `in`. */
14
- cachedIn?: number;
15
- /** Input tokens written into provider prompt/context cache. Included in `in`. */
16
- cacheWriteIn?: number;
17
- /** Output tokens spent on reasoning/thinking. Included in `out`. */
18
- reasoningOut?: number;
19
- }
20
- //#endregion
21
5
  //#region src/messages/stream.d.ts
22
6
  interface StreamChunk {
23
7
  type: "start" | "text-start" | "text-delta" | "text-complete" | "tool-call-start" | "tool-call-args-delta" | "tool-call-complete" | "thinking-start" | "thinking-delta" | "thinking-summary-delta" | "thinking-complete" | "provider-tool-start" | "provider-tool-complete" | "complete" | "error";
@@ -143,192 +127,24 @@ interface StreamProviderToolCompleteChunk extends StreamChunk {
143
127
  }
144
128
  type AnyStreamChunk = StreamStartChunk | StreamCompleteChunk | StreamErrorChunk | StreamTextStartChunk | StreamTextDeltaChunk | StreamTextCompleteChunk | StreamThinkingStartChunk | StreamThinkingDeltaChunk | StreamThinkingSummaryDeltaChunk | StreamThinkingCompleteChunk | StreamToolCallStartChunk | StreamToolCallArgsDeltaChunk | StreamToolCallCompleteChunk | StreamProviderToolStartChunk | StreamProviderToolCompleteChunk;
145
129
  //#endregion
146
- //#region src/tracer/types.d.ts
147
- type SpanStatus = "ok" | "error";
148
- type EventLevel = "debug" | "info" | "warn" | "error";
149
- type SpanType = string;
150
- interface SpanEvent {
151
- name: string;
152
- timestamp: number;
153
- level: EventLevel;
154
- attributes?: Record<string, unknown>;
155
- }
156
- interface SpanData {
157
- traceId: string;
158
- spanId: string;
159
- parentSpanId?: string;
160
- name: string;
161
- type?: SpanType;
162
- startTime: number;
163
- endTime?: number;
164
- status: SpanStatus;
165
- attributes: Record<string, unknown>;
166
- events: SpanEvent[];
167
- result?: SpanResult;
168
- }
169
- interface SpanOptions {
170
- type?: SpanType;
171
- }
172
- type SpanResult = LLMResult | ToolResult;
173
- interface LLMResult {
174
- kind: "llm";
175
- model: string;
176
- request: LLMRequest;
177
- response: LLMResponse;
178
- usage?: TokenUsage;
179
- finishReason?: string;
180
- }
181
- interface LLMRequest {
182
- messages: unknown[];
183
- system?: string;
184
- tools?: unknown[];
185
- }
186
- interface LLMResponse {
187
- content: unknown;
188
- }
189
- interface TokenUsage {
190
- inputTokens?: number;
191
- outputTokens?: number;
192
- totalTokens?: number;
193
- cachedInputTokens?: number;
194
- cacheWriteInputTokens?: number;
195
- reasoningOutputTokens?: number;
196
- }
197
- interface ToolResult {
198
- kind: "tool";
199
- name: string;
200
- input: unknown;
201
- output: unknown;
202
- }
203
- interface TraceWriter {
204
- onSpanStart(span: SpanData): void;
205
- onSpanUpdate?(span: SpanData): void;
206
- onSpanEnd(span: SpanData): void;
207
- onEvent?(span: SpanData, event: SpanEvent): void;
208
- flush?(): Promise<void>;
209
- }
210
- /**
211
- * Tracing context for a span. Created by Tracer.startSpan().
212
- * Can create child spans and log events within the span's scope.
213
- */
214
- interface TracingContext {
215
- startSpan(name: string, options?: SpanOptions): TracingContext;
216
- end(status?: SpanStatus): void;
217
- debug(message: string, attributes?: Record<string, unknown>): void;
218
- info(message: string, attributes?: Record<string, unknown>): void;
219
- warn(message: string, attributes?: Record<string, unknown>): void;
220
- error(message: string, attributes?: Record<string, unknown>): void;
221
- setAttribute(key: string, value: unknown): void;
222
- setAttributes(attributes: Record<string, unknown>): void;
223
- setResult(result: SpanResult): void;
224
- }
225
- //#endregion
226
- //#region src/utils/file.d.ts
227
- type FileKind = "image" | "document" | "text";
228
- type TextSource = {
229
- type: "text";
230
- content: string;
231
- } | {
232
- type: "url";
233
- url: string;
234
- } | {
235
- type: "ref";
236
- ref: unknown;
237
- };
238
- type BinarySource = {
239
- type: "base64";
240
- data: string;
241
- } | {
242
- type: "url";
243
- url: string;
244
- } | {
245
- type: "ref";
246
- ref: unknown;
247
- };
248
- interface BaseFile {
249
- mimeType: string;
250
- name: string;
251
- size?: number;
252
- }
253
- type TextFileInfo = BaseFile & {
254
- kind: "text";
255
- source: TextSource;
256
- };
257
- type BinaryFileInfo = BaseFile & {
258
- kind: "image" | "document";
259
- source: BinarySource;
260
- };
261
- type FileInfo = TextFileInfo | BinaryFileInfo;
262
- type InlineTextFile = TextFileInfo & {
263
- source: {
264
- type: "text";
265
- content: string;
266
- };
267
- };
268
- type InlineBinaryFile = BinaryFileInfo & {
269
- source: {
270
- type: "base64";
271
- data: string;
272
- };
273
- };
274
- type DeferredFileInfo = FileInfo & {
275
- source: {
276
- type: "ref";
277
- ref: unknown;
278
- };
130
+ //#region src/providers/types.d.ts
131
+ type AnthropicProviderConfig = {
132
+ "api-key": string;
133
+ model?: string;
279
134
  };
280
- type ConcreteFileInfo = FileInfo & {
281
- source: {
282
- type: "text";
283
- } | {
284
- type: "base64";
285
- } | {
286
- type: "url";
287
- };
135
+ type OpenAIProviderConfig = {
136
+ "api-key": string;
137
+ model?: string;
288
138
  };
289
- type FileProviderId = "anthropic" | "openai" | "gemini" | "chatcompletions";
290
- type FileResolveFormat = "base64" | "url" | "text" | "gemini-file-uri";
291
- type ResolvedFileSource = {
292
- type: "base64";
293
- data: string;
294
- mimeType?: string;
295
- name?: string;
296
- } | {
297
- type: "url";
298
- url: string;
299
- mimeType?: string;
300
- name?: string;
301
- } | {
302
- type: "text";
303
- content: string;
304
- mimeType?: string;
305
- name?: string;
306
- } | {
307
- type: "gemini-file-uri";
308
- uri: string;
309
- mimeType?: string;
310
- name?: string;
139
+ type GeminiProviderConfig = {
140
+ "api-key": string;
141
+ model?: string;
311
142
  };
312
- interface FileResolveRequest {
313
- file: DeferredFileInfo;
314
- ref: unknown;
315
- provider: FileProviderId;
143
+ type ChatCompletionsProviderConfig = {
144
+ "base-url": string;
316
145
  model: string;
317
- accepted: FileResolveFormat[];
318
- signal?: AbortSignal;
319
- }
320
- type FileResolver = (request: FileResolveRequest) => Promise<ResolvedFileSource>;
321
- /**
322
- * Load a file with the specified encoding or auto-detect based on file extension
323
- * @param filePath - Path to the file
324
- * @param encoding - How to load the file: "utf-8" for text, "base64" for binary, or omit for auto-detection
325
- * @returns FileInfo object with appropriate content based on encoding
326
- */
327
- declare function loadFileContent(filePath: string): Promise<FileInfo>;
328
- declare function loadFileContent(filePath: string, encoding: "utf-8"): Promise<InlineTextFile>;
329
- declare function loadFileContent(filePath: string, encoding: "base64"): Promise<InlineBinaryFile>;
330
- //#endregion
331
- //#region src/providers/types.d.ts
146
+ "api-key"?: string;
147
+ };
332
148
  /**
333
149
  * Internal services available to provider adapters while executing a model request.
334
150
  */
@@ -608,20 +424,87 @@ declare class MCP {
608
424
  private assertConnected;
609
425
  }
610
426
  //#endregion
611
- //#region src/store/types.d.ts
612
- interface FileStore {
613
- read(path: string): Promise<string | null>;
614
- write(path: string, content: string): Promise<void>;
427
+ //#region src/core/parse.d.ts
428
+ type OutputSchema = z$2.ZodTypeAny;
429
+ type ParsedSchema<T extends OutputSchema> = z$2.output<T>;
430
+ declare function parseResponse<T extends OutputSchema>(rawValue: string, schema?: T): ParsedSchema<T> | string;
431
+ //#endregion
432
+ //#region src/core/Instruct.d.ts
433
+ type InstructInputs = Record<string, unknown>;
434
+ type InstructVarsMode = "required" | "optional";
435
+ interface InstructOptions<TSchema extends OutputSchema | undefined = OutputSchema | undefined> {
436
+ prompt: string;
437
+ schema?: TSchema;
438
+ vars?: InstructVarsMode;
439
+ }
440
+ declare class Instruct<TSchema extends OutputSchema | undefined = undefined> {
441
+ prompt: string;
442
+ inputs: InstructInputs;
443
+ files: FileInfo[];
444
+ textReferences: Array<{
445
+ content: string;
446
+ name?: string;
447
+ }>;
448
+ vars: InstructVarsMode;
449
+ schema: TSchema;
450
+ constructor(options: InstructOptions<TSchema>);
451
+ clone(): Instruct<TSchema>;
452
+ withInputs(inputs: InstructInputs): Instruct<TSchema>;
453
+ withInput(name: string, value: unknown): Instruct<TSchema>;
454
+ setInputs(inputs: InstructInputs): void;
455
+ addInput(name: string, value: unknown): void;
456
+ addFile(file: FileInfo | string, options?: {
457
+ name?: string;
458
+ }): void;
459
+ hasFiles(): boolean;
460
+ render(options?: {
461
+ vars?: InstructVarsMode;
462
+ }): string;
463
+ }
464
+ //#endregion
465
+ //#region src/core/agent/history.d.ts
466
+ /**
467
+ * In-memory conversation and presentation history for an agent.
468
+ *
469
+ * `log` is the canonical model-facing message history. `turns` and
470
+ * `sessionAnnotations` are renderable presentation state for consumers.
471
+ *
472
+ * @typeParam TAnnotation - Annotation union supported by the host renderer.
473
+ */
474
+ declare class History<TAnnotation extends Annotation = Annotation> {
475
+ private _turns;
476
+ private _log;
477
+ private _sessionAnnotations;
478
+ constructor(init?: {
479
+ turns?: Turn<TAnnotation>[];
480
+ log?: AxleMessage[];
481
+ sessionAnnotations?: TAnnotation[];
482
+ });
483
+ get turns(): Turn<TAnnotation>[];
484
+ get log(): AxleMessage[];
485
+ get sessionAnnotations(): TAnnotation[];
486
+ addTurn(turn: Turn<TAnnotation>): void;
487
+ replaceTurns(turns: Turn<TAnnotation>[]): void;
488
+ replaceLog(messages: AxleMessage[]): void;
489
+ replaceSessionAnnotations(annotations?: TAnnotation[]): void;
490
+ appendToLog(messages: AxleMessage | AxleMessage[]): void;
491
+ latestTurn(): Turn<TAnnotation> | undefined;
492
+ toString(): string;
615
493
  }
616
494
  //#endregion
617
495
  //#region src/memory/types.d.ts
618
496
  interface MemoryContext {
619
- name?: string;
620
- scope?: Record<string, string>;
497
+ /** Optional agent name provided by the host. */
498
+ agentName?: string;
499
+ /** Stable conversation/session id from the agent. */
500
+ sessionId: string;
501
+ /** Current system prompt, before memory augmentation. */
621
502
  system?: string;
503
+ /** Full message context available for recall or extraction. */
622
504
  messages: AxleMessage[];
505
+ /** Newly produced messages to record after a turn completes. */
623
506
  newMessages?: AxleMessage[];
624
- store: FileStore;
507
+ /** Optional tracing context. */
625
508
  tracer?: TracingContext;
626
509
  }
627
510
  interface RecallResult {
@@ -677,167 +560,6 @@ type GenerateResult<TResponse = AxleAssistantMessage> = {
677
560
  };
678
561
  type StreamResult<TResponse = AxleAssistantMessage> = GenerateResult<TResponse>;
679
562
  //#endregion
680
- //#region src/turns/types.d.ts
681
- type TurnStatus = "streaming" | "complete" | "cancelled" | "error";
682
- interface TimingInfo {
683
- start: string;
684
- end?: string;
685
- }
686
- interface Turn {
687
- id: string;
688
- owner: "user" | "agent";
689
- parts: TurnPart[];
690
- status: TurnStatus;
691
- timing?: TimingInfo;
692
- usage?: Stats;
693
- }
694
- type TurnPart = TextPart | FilePart | ThinkingPart | ActionPart;
695
- interface TextPart {
696
- id: string;
697
- type: "text";
698
- text: string;
699
- timing?: TimingInfo;
700
- }
701
- interface FilePart {
702
- id: string;
703
- type: "file";
704
- file: FileInfo;
705
- timing?: TimingInfo;
706
- }
707
- interface ThinkingPart {
708
- id: string;
709
- type: "thinking";
710
- text: string;
711
- summary?: string;
712
- redacted?: boolean;
713
- timing?: TimingInfo;
714
- }
715
- interface ActionPartBase {
716
- id: string;
717
- type: "action";
718
- kind: string;
719
- status: "pending" | "running" | "complete" | "cancelled" | "error";
720
- timing?: TimingInfo;
721
- }
722
- interface ToolAction extends ActionPartBase {
723
- kind: "tool";
724
- detail: {
725
- name: string;
726
- parameters: Record<string, unknown>;
727
- pendingArgs?: string;
728
- result?: ActionResult;
729
- };
730
- }
731
- interface SubagentAction extends ActionPartBase {
732
- kind: "agent";
733
- detail: {
734
- name: string;
735
- config?: Record<string, unknown>;
736
- children: Turn[];
737
- result?: ActionResult;
738
- };
739
- }
740
- interface ProviderToolAction extends ActionPartBase {
741
- kind: "provider-tool";
742
- detail: {
743
- name: string;
744
- input?: unknown;
745
- result?: ActionResult;
746
- };
747
- }
748
- type ActionPart = ToolAction | SubagentAction | ProviderToolAction;
749
- type ActionResult = {
750
- type: "in-progress";
751
- content: string;
752
- } | {
753
- type: "success";
754
- content: unknown;
755
- } | {
756
- type: "error";
757
- error: {
758
- type: string;
759
- message: string;
760
- };
761
- };
762
- //#endregion
763
- //#region src/turns/events.d.ts
764
- type AgentEvent = {
765
- type: "session:restore";
766
- turns: Turn[];
767
- config?: Record<string, unknown>;
768
- } | {
769
- type: "turn:user";
770
- turn: Turn;
771
- } | {
772
- type: "turn:start";
773
- turnId: string;
774
- } | {
775
- type: "turn:end";
776
- turnId: string;
777
- status: TurnStatus;
778
- usage: Stats;
779
- timing?: TimingInfo;
780
- } | {
781
- type: "part:start";
782
- turnId: string;
783
- part: TurnPart;
784
- } | {
785
- type: "text:delta";
786
- turnId: string;
787
- partId: string;
788
- delta: string;
789
- } | {
790
- type: "thinking:delta";
791
- turnId: string;
792
- partId: string;
793
- delta: string;
794
- } | {
795
- type: "part:end";
796
- turnId: string;
797
- partId: string;
798
- timing?: TimingInfo;
799
- } | {
800
- type: "action:args-delta";
801
- turnId: string;
802
- partId: string;
803
- delta: string;
804
- accumulated: string;
805
- } | {
806
- type: "action:running";
807
- turnId: string;
808
- partId: string;
809
- parameters?: Record<string, unknown>;
810
- } | {
811
- type: "action:progress";
812
- turnId: string;
813
- partId: string;
814
- chunk: string;
815
- } | {
816
- type: "action:complete";
817
- turnId: string;
818
- partId: string;
819
- result: ActionResult;
820
- } | {
821
- type: "action:error";
822
- turnId: string;
823
- partId: string;
824
- error: {
825
- type: string;
826
- message: string;
827
- };
828
- } | {
829
- type: "action:child-event";
830
- turnId: string;
831
- partId: string;
832
- event: AgentEvent;
833
- } | {
834
- type: "error";
835
- error: {
836
- type: string;
837
- message: string;
838
- };
839
- };
840
- //#endregion
841
563
  //#region src/utils/utils.d.ts
842
564
  interface Handle<T> {
843
565
  cancel(reason?: unknown): void;
@@ -854,74 +576,153 @@ declare function createHandle<T>(queue: Promise<void>, work: (signal: AbortSigna
854
576
  settled: Promise<void>;
855
577
  };
856
578
  //#endregion
857
- //#region src/core/history.d.ts
858
- declare class History {
859
- private _turns;
860
- private _log;
861
- constructor(init?: {
862
- turns?: Turn[];
863
- log?: AxleMessage[];
864
- });
865
- get turns(): Turn[];
866
- get log(): AxleMessage[];
867
- addTurn(turn: Turn): void;
868
- appendToLog(messages: AxleMessage | AxleMessage[]): void;
869
- latestTurn(): Turn | undefined;
870
- toString(): string;
871
- }
872
- //#endregion
873
- //#region src/core/parse.d.ts
874
- type OutputSchema = z$2.ZodTypeAny;
875
- type ParsedSchema<T extends OutputSchema> = z$2.output<T>;
876
- declare function parseResponse<T extends OutputSchema>(rawValue: string, schema?: T): ParsedSchema<T> | string;
877
- //#endregion
878
- //#region src/core/Instruct.d.ts
879
- type InstructInputs = Record<string, unknown>;
880
- type InstructVarsMode = "required" | "optional";
881
- interface InstructOptions<TSchema extends OutputSchema | undefined = OutputSchema | undefined> {
882
- prompt: string;
883
- schema?: TSchema;
884
- vars?: InstructVarsMode;
885
- }
886
- declare class Instruct<TSchema extends OutputSchema | undefined = undefined> {
887
- prompt: string;
888
- inputs: InstructInputs;
889
- files: FileInfo[];
890
- textReferences: Array<{
891
- content: string;
892
- name?: string;
893
- }>;
894
- vars: InstructVarsMode;
895
- schema: TSchema;
896
- constructor(options: InstructOptions<TSchema>);
897
- clone(): Instruct<TSchema>;
898
- withInputs(inputs: InstructInputs): Instruct<TSchema>;
899
- withInput(name: string, value: unknown): Instruct<TSchema>;
900
- setInputs(inputs: InstructInputs): void;
901
- addInput(name: string, value: unknown): void;
902
- addFile(file: FileInfo | string, options?: {
903
- name?: string;
904
- }): void;
905
- hasFiles(): boolean;
906
- render(options?: {
907
- vars?: InstructVarsMode;
908
- }): string;
909
- }
910
- //#endregion
911
- //#region src/core/Agent.d.ts
579
+ //#region src/core/agent/types.d.ts
580
+ /**
581
+ * Runtime configuration for an `Agent`.
582
+ *
583
+ * This contains executable objects and process-local services. It is not meant
584
+ * to be serialized directly. Use `AgentDefinition` for a serializable recipe
585
+ * and `createAgentConfig()` to produce an `AgentConfig`.
586
+ */
912
587
  interface AgentConfig extends Omit<AxleModelRequestOptions, "signal"> {
588
+ /** Provider adapter used to execute model requests. */
913
589
  provider: AIProvider;
590
+ /** Model identifier passed to the provider. */
914
591
  model: string;
592
+ /** Stable conversation/session id. Generated when omitted. */
593
+ sessionId?: string;
594
+ /** Optional system/developer instruction. */
915
595
  system?: string;
596
+ /** Optional agent name passed to host services such as memory. */
916
597
  name?: string;
917
- scope?: Record<string, string>;
598
+ /** Executable tools available to the agent. */
918
599
  tools?: ExecutableTool[];
600
+ /** Provider-managed tools such as hosted search or code execution. */
919
601
  providerTools?: ProviderTool[];
602
+ /** MCP clients whose tools should be lazily resolved. */
920
603
  mcps?: MCP[];
604
+ /** Optional memory implementation. */
921
605
  memory?: AgentMemory;
606
+ /** Optional tracing context. */
922
607
  tracer?: TracingContext;
608
+ /** Optional file resolver for request file references. */
923
609
  fileResolver?: FileResolver;
924
610
  }
611
+ /**
612
+ * Serializable provider reference for an agent definition.
613
+ *
614
+ * `type` is host-defined. Common values are provider names such as `"openai"`,
615
+ * `"anthropic"`, `"gemini"`, or `"chatcompletions"`, but core does not
616
+ * interpret the value. `config` is passed through to the host resolver.
617
+ */
618
+ interface ProviderDefinition {
619
+ /** Host-defined provider discriminator. */
620
+ type: string;
621
+ /** Serializable provider configuration or references, such as `apiKeyEnv`. */
622
+ config?: Record<string, unknown>;
623
+ }
624
+ /**
625
+ * Serializable reference to an executable tool.
626
+ */
627
+ interface ToolDefinitionRef {
628
+ /** Host-defined tool name or id. */
629
+ name: string;
630
+ /** Optional serializable tool configuration passed to the resolver. */
631
+ config?: Record<string, unknown>;
632
+ }
633
+ /**
634
+ * Serializable reference to a provider-managed tool.
635
+ */
636
+ interface ProviderToolDefinitionRef {
637
+ /** Provider tool name. */
638
+ name: string;
639
+ /** Optional provider tool configuration. */
640
+ config?: Record<string, unknown>;
641
+ }
642
+ /**
643
+ * Serializable request options for an agent definition.
644
+ */
645
+ interface AgentDefinitionRequestOptions extends Omit<AxleModelRequestOptions, "signal"> {}
646
+ /**
647
+ * Serializable recipe for reconstructing an agent.
648
+ *
649
+ * This is deliberately not executable by itself. Hosts resolve provider and
650
+ * tool references into runtime objects using an `AgentDefinitionResolver`.
651
+ * Harness concerns such as memory implementations, file resolvers, tracing,
652
+ * transport, and stores should be modeled outside this core definition.
653
+ */
654
+ interface AgentDefinition {
655
+ /** Agent definition schema version. */
656
+ version: 1;
657
+ /** Optional agent name passed to host services such as memory. */
658
+ name?: string;
659
+ /** Provider reference resolved by the host. */
660
+ provider: ProviderDefinition;
661
+ /** Optional model identifier passed to the resolved provider. */
662
+ model?: string;
663
+ /** Optional system/developer instruction. */
664
+ system?: string;
665
+ /** Provider-portable request defaults. */
666
+ request?: AgentDefinitionRequestOptions;
667
+ /** Serializable executable tool references. */
668
+ tools?: ToolDefinitionRef[];
669
+ /** Serializable provider-managed tool references. */
670
+ providerTools?: ProviderToolDefinitionRef[];
671
+ /** Serializable MCP client configuration. */
672
+ mcps?: MCPConfig[];
673
+ }
674
+ type MaybePromise<T> = T | Promise<T>;
675
+ /**
676
+ * Executable dependencies resolved from an `AgentDefinition`.
677
+ */
678
+ interface ResolvedAgentDefinition {
679
+ /** Provider adapter used to execute model requests. */
680
+ provider: AIProvider;
681
+ /** Model identifier used when `AgentDefinition.model` is omitted. */
682
+ model?: string;
683
+ /** Executable tools resolved from `AgentDefinition.tools`. */
684
+ tools?: ExecutableTool[];
685
+ /** Provider-managed tools resolved from `AgentDefinition.providerTools`. */
686
+ providerTools?: ProviderTool[];
687
+ /** MCP clients resolved from `AgentDefinition.mcps`. */
688
+ mcps?: MCP[];
689
+ }
690
+ /**
691
+ * Host function used to turn an `AgentDefinition` into executable dependencies.
692
+ */
693
+ type AgentDefinitionResolver = (definition: AgentDefinition) => MaybePromise<ResolvedAgentDefinition>;
694
+ /**
695
+ * Serializable continuation and presentation state for an `Agent`.
696
+ *
697
+ * This is the data needed to continue a model conversation and restore the
698
+ * renderable turn state. It intentionally does not include executable runtime
699
+ * objects such as providers, tools, MCP clients, memory implementations, file
700
+ * resolvers, or tracers. Recreate those from host-owned configuration, then
701
+ * call `agent.restore(session)`.
702
+ *
703
+ * @typeParam TAnnotation - Annotation union supported by the host renderer.
704
+ */
705
+ interface AgentSession<TAnnotation extends Annotation = Annotation> {
706
+ /** Agent session schema version. */
707
+ version: 1;
708
+ /** Stable conversation/session id. */
709
+ sessionId: string;
710
+ /** Canonical model-facing message history used for continuation. */
711
+ messages: AxleMessage[];
712
+ /** Renderable turn state for exact UI restoration. */
713
+ turns?: Turn<TAnnotation>[];
714
+ /** Session-level annotations for generic renderer state. */
715
+ sessionAnnotations?: TAnnotation[];
716
+ }
717
+ /**
718
+ * Serializable saved agent payload: definition plus continuation state.
719
+ */
720
+ interface SavedAgent<TAnnotation extends Annotation = Annotation> {
721
+ /** Serializable recipe used to reconstruct runtime config. */
722
+ definition: AgentDefinition;
723
+ /** Serializable continuation and presentation state. */
724
+ session: AgentSession<TAnnotation>;
725
+ }
925
726
  interface AgentResult<T = string> {
926
727
  ok: true;
927
728
  response: T;
@@ -936,21 +737,22 @@ interface AgentErrorResult {
936
737
  usage: Stats;
937
738
  }
938
739
  type AgentHandle<T = string> = Handle<AgentResult<T> | AgentErrorResult>;
939
- type AgentEventCallback = (event: AgentEvent) => void;
740
+ type TurnEventCallback = (event: TurnEvent) => void;
940
741
  interface SendMessageOptions extends AxleModelRequestOptions {
941
742
  fileResolver?: FileResolver;
942
743
  }
744
+ //#endregion
745
+ //#region src/core/agent/Agent.d.ts
943
746
  declare class Agent {
944
747
  readonly provider: AIProvider;
945
748
  readonly model: string;
946
749
  readonly history: History;
947
750
  readonly tracer?: TracingContext;
948
751
  readonly name?: string;
949
- readonly scope?: Record<string, string>;
950
- readonly store: FileStore;
951
752
  readonly fileResolver?: FileResolver;
952
753
  readonly requestOptions: Omit<AxleModelRequestOptions, "signal">;
953
754
  readonly registry: ToolRegistry;
755
+ sessionId: string;
954
756
  system: string | undefined;
955
757
  private mcps;
956
758
  private resolvedMcps;
@@ -961,8 +763,24 @@ declare class Agent {
961
763
  addMcp(mcp: MCP): void;
962
764
  addMcps(mcps: MCP[]): void;
963
765
  hasTools(): boolean;
964
- on(callback: AgentEventCallback): void;
766
+ on(callback: TurnEventCallback): void;
965
767
  context(): ContextUsage;
768
+ /**
769
+ * Capture the serializable session state for later continuation.
770
+ *
771
+ * The returned object contains message history and renderable turn state, but
772
+ * not executable configuration such as providers, tools, MCP clients, memory,
773
+ * or tracers.
774
+ */
775
+ snapshot(): AgentSession;
776
+ /**
777
+ * Replace the agent's continuation and render state from a saved session.
778
+ *
779
+ * Restore does not change runtime configuration. The current provider, model,
780
+ * tools, MCP clients, memory, and other constructor-supplied objects remain in
781
+ * effect.
782
+ */
783
+ restore(session: AgentSession): void;
966
784
  send(message: string | Instruct<undefined>, options?: SendMessageOptions): AgentHandle<string>;
967
785
  send<TSchema extends OutputSchema>(instruct: Instruct<TSchema>, options?: SendMessageOptions): AgentHandle<ParsedSchema<TSchema>>;
968
786
  private resolveMcpTools;
@@ -971,6 +789,17 @@ declare class Agent {
971
789
  private run;
972
790
  }
973
791
  //#endregion
792
+ //#region src/core/agent/createAgentConfig.d.ts
793
+ /**
794
+ * Create executable `Agent` config from a serializable agent definition.
795
+ *
796
+ * Core resolves only what it can safely construct from serializable data. The
797
+ * host remains responsible for executable dependencies such as providers,
798
+ * tools, and MCP clients. Harness runtime services such as memory and file
799
+ * resolvers should be layered onto the returned config by the host.
800
+ */
801
+ declare function createAgentConfig(definition: AgentDefinition, resolver: AgentDefinitionResolver): Promise<AgentConfig>;
802
+ //#endregion
974
803
  //#region src/core/userTurn.d.ts
975
804
  type InstructResponse<TSchema extends OutputSchema | undefined> = TSchema extends OutputSchema ? ParsedSchema<TSchema> : string;
976
805
  //#endregion
@@ -1032,7 +861,7 @@ declare class AxleAgentAbortError extends AxleAbortError {
1032
861
  usage?: Stats;
1033
862
  });
1034
863
  toJSON(): {
1035
- turn?: Turn | undefined;
864
+ turn?: Turn<Annotation<unknown, string>> | undefined;
1036
865
  usage?: Stats | undefined;
1037
866
  partial?: AxleAssistantMessage | undefined;
1038
867
  messages?: AxleMessage[] | undefined;
@@ -1127,6 +956,17 @@ declare const Anthropic: {
1127
956
  //#region src/providers/chatcompletions/provider.d.ts
1128
957
  declare function chatCompletions(baseUrl: string, apiKey?: string): AIProvider;
1129
958
  //#endregion
959
+ //#region src/providers/context.d.ts
960
+ interface ContextEstimateInput {
961
+ system?: string;
962
+ tools?: ToolDefinition[];
963
+ providerTools?: ProviderTool[];
964
+ mcpTools?: ToolDefinition[];
965
+ messages: AxleMessage[];
966
+ limit?: number;
967
+ }
968
+ declare function estimateContextUsage(input: ContextEstimateInput): ContextUsage;
969
+ //#endregion
1130
970
  //#region src/providers/gemini/provider.d.ts
1131
971
  declare function gemini(apiKey: string): AIProvider;
1132
972
  //#endregion
@@ -1364,124 +1204,21 @@ declare const OpenAI: {
1364
1204
  readonly DefaultModel: "gpt-5.4-mini";
1365
1205
  };
1366
1206
  //#endregion
1367
- //#region src/providers/context.d.ts
1368
- interface ContextEstimateInput {
1369
- system?: string;
1370
- tools?: ToolDefinition[];
1371
- providerTools?: ProviderTool[];
1372
- mcpTools?: ToolDefinition[];
1373
- messages: AxleMessage[];
1374
- limit?: number;
1375
- }
1376
- declare function estimateContextUsage(input: ContextEstimateInput): ContextUsage;
1377
- //#endregion
1378
- //#region src/cli/configs/schemas.d.ts
1379
- declare const BraveProviderConfigSchema: z.ZodObject<{
1380
- "api-key": z.ZodString;
1381
- rateLimit: z.ZodOptional<z.ZodNumber>;
1382
- }, z.core.$strip>;
1383
- type BraveProviderConfig = z.infer<typeof BraveProviderConfigSchema>;
1384
- declare const ExecProviderConfigSchema: z.ZodObject<{
1385
- timeout: z.ZodOptional<z.ZodNumber>;
1386
- maxBuffer: z.ZodOptional<z.ZodNumber>;
1387
- cwd: z.ZodOptional<z.ZodString>;
1388
- }, z.core.$strip>;
1389
- type ExecProviderConfig = z.infer<typeof ExecProviderConfigSchema>;
1390
- //#endregion
1391
- //#region src/tools/brave.d.ts
1392
- declare const braveSearchSchema: z$2.ZodObject<{
1393
- searchTerm: z$2.ZodString;
1394
- }, z$2.core.$strip>;
1395
- declare class BraveSearchTool implements ExecutableTool<typeof braveSearchSchema> {
1396
- name: string;
1397
- description: string;
1398
- schema: z$2.ZodObject<{
1399
- searchTerm: z$2.ZodString;
1400
- }, z$2.core.$strip>;
1401
- apiKey: string | undefined;
1402
- throttle: number | undefined;
1403
- lastExecTime: number;
1404
- constructor(config?: BraveProviderConfig);
1405
- configure(config: BraveProviderConfig): void;
1406
- execute(params: z$2.infer<typeof braveSearchSchema>, ctx: ToolContext): Promise<string>;
1407
- }
1408
- declare const braveSearchTool: BraveSearchTool;
1409
- //#endregion
1410
- //#region src/tools/calculator.d.ts
1411
- declare const calculatorSchema: z.ZodObject<{
1412
- operation: z.ZodEnum<{
1413
- add: "add";
1414
- subtract: "subtract";
1415
- multiply: "multiply";
1416
- divide: "divide";
1417
- }>;
1418
- a: z.ZodNumber;
1419
- b: z.ZodNumber;
1420
- }, z.core.$strip>;
1421
- declare const calculatorTool: ExecutableTool<typeof calculatorSchema>;
1422
- //#endregion
1423
- //#region src/tools/exec/index.d.ts
1424
- declare const execSchema: z$2.ZodObject<{
1425
- command: z$2.ZodString;
1426
- }, z$2.core.$strip>;
1427
- declare class ExecTool implements ExecutableTool<typeof execSchema> {
1428
- name: string;
1429
- description: string;
1430
- schema: z$2.ZodObject<{
1431
- command: z$2.ZodString;
1432
- }, z$2.core.$strip>;
1433
- private timeout;
1434
- private maxBuffer;
1435
- private cwd?;
1436
- constructor(config?: ExecProviderConfig);
1437
- configure(config: ExecProviderConfig): void;
1438
- summarize(params: z$2.infer<typeof execSchema>): string;
1439
- execute(params: z$2.infer<typeof execSchema>, ctx: ToolContext): Promise<string>;
1440
- }
1441
- declare const execTool: ExecTool;
1442
- //#endregion
1443
- //#region src/tools/patch-file.d.ts
1444
- declare const patchFileSchema: z.ZodObject<{
1445
- path: z.ZodString;
1446
- old_string: z.ZodString;
1447
- new_string: z.ZodString;
1448
- start_line: z.ZodNumber;
1449
- end_line: z.ZodNumber;
1450
- }, z.core.$strip>;
1451
- declare const patchFileTool: ExecutableTool<typeof patchFileSchema>;
1452
- //#endregion
1453
- //#region src/tools/read-file.d.ts
1454
- declare const readFileSchema: z.ZodObject<{
1455
- path: z.ZodString;
1456
- }, z.core.$strip>;
1457
- declare const readFileTool: ExecutableTool<typeof readFileSchema>;
1458
- //#endregion
1459
- //#region src/tools/write-file.d.ts
1460
- declare const writeFileSchema: z.ZodObject<{
1461
- path: z.ZodString;
1462
- content: z.ZodString;
1463
- }, z.core.$strip>;
1464
- declare const writeFileTool: ExecutableTool<typeof writeFileSchema>;
1465
- //#endregion
1466
- //#region src/turns/builder.d.ts
1467
- declare class TurnBuilder {
1468
- private currentTurn;
1207
+ //#region src/turns/eventBuilder.d.ts
1208
+ declare class TurnEventBuilder {
1209
+ private currentTurnId;
1210
+ private currentTurnTiming;
1469
1211
  private currentTextPart;
1470
1212
  private currentThinkingPart;
1471
1213
  private toolIdMap;
1472
1214
  private accumulatedUsage;
1473
- createUserTurn(message: AxleUserMessage): {
1474
- turn: Turn;
1475
- events: AgentEvent[];
1476
- };
1477
- startAgentTurn(): {
1478
- turn: Turn;
1479
- events: AgentEvent[];
1480
- };
1481
- handleStreamEvent(event: StreamEvent): AgentEvent[];
1482
- finalizeTurn(outcome?: "complete" | "cancelled" | "error"): AgentEvent[];
1215
+ createUserTurn(message: AxleUserMessage): TurnEvent[];
1216
+ startAgentTurn(): Extract<TurnEvent, {
1217
+ type: "turn:start";
1218
+ }>;
1219
+ handleStreamEvent(event: StreamEvent): TurnEvent[];
1220
+ finalizeTurn(outcome?: "complete" | "cancelled" | "error"): TurnEvent[];
1483
1221
  private closeOpenParts;
1484
- private findActionPart;
1485
1222
  }
1486
1223
  //#endregion
1487
1224
  //#region src/tracer/tracer.d.ts
@@ -1559,36 +1296,14 @@ declare class SimpleWriter implements TraceWriter {
1559
1296
  onEvent(span: SpanData, event: SpanEvent): void;
1560
1297
  }
1561
1298
  //#endregion
1562
- //#region src/memory/ProceduralMemory.d.ts
1563
- interface ProceduralMemoryConfig {
1564
- provider: AIProvider;
1565
- model: string;
1566
- enableTools?: boolean;
1567
- }
1568
- declare class ProceduralMemory implements AgentMemory {
1569
- private provider;
1570
- private model;
1571
- private enableTools;
1572
- private lastStore?;
1573
- private lastName?;
1574
- private lastScope?;
1575
- constructor(config: ProceduralMemoryConfig);
1576
- recall(context: MemoryContext): Promise<RecallResult>;
1577
- record(context: MemoryContext): Promise<void>;
1578
- tools(): ExecutableTool[];
1579
- private formatMessages;
1580
- private parseInstructions;
1581
- private getStorePath;
1582
- private loadStore;
1583
- private saveStore;
1584
- }
1585
- //#endregion
1586
- //#region src/store/LocalFileStore.d.ts
1587
- declare class LocalFileStore implements FileStore {
1588
- readonly rootPath: string;
1589
- constructor(rootPath: string);
1299
+ //#region src/store/types.d.ts
1300
+ interface FileStore {
1590
1301
  read(path: string): Promise<string | null>;
1591
1302
  write(path: string, content: string): Promise<void>;
1592
1303
  }
1593
1304
  //#endregion
1594
- export { type AIProvider, type ActionPart, type ActionResult, Agent, type AgentConfig, type AgentEvent, type AgentEventCallback, type AgentHandle, type AgentMemory, type AgentResult, Anthropic, AxleAbortError, AxleAgentAbortError, type AxleAssistantMessage, AxleError, type AxleMessage, type AxleModelRequestOptions, AxleStopReason, type AxleToolCallMessage, type AxleToolCallResult, AxleToolFatalError, type AxleUserMessage, type ContentPart, type ContentPartFile, type ContentPartProviderTool, type ContentPartText, type ContentPartThinking, type ContentPartToolCall, type ContextUsage, type DeferredFileInfo, type EventLevel, type ExecutableTool, type FileInfo, type FileKind, type FilePart, type FileProviderId, type FileResolveFormat, type FileResolveRequest, type FileResolver, type FileStore, Gemini, type GenerateInstructParams, type GenerateInstructResult, type GenerateParams, type Handle, History, Instruct, type InstructInputs, type InstructOptions, type InstructResponse, InstructVariableError, type InstructVarsMode, LocalFileStore, MCP, type MCPConfig, type MCPHttpConfig, type MCPStdioConfig, type MemoryContext, OpenAI, ProceduralMemory, type ProceduralMemoryConfig, type ProviderOptions, type ProviderTool, type ProviderToolAction, type RecallResult, type ResolvedFileSource, type SendMessageOptions, SimpleWriter, type SimpleWriterOptions, type SpanData, type SpanOptions, type SpanType, type StreamEvent, type StreamEventCallback, type StreamHandle, type StreamInstructHandle, type StreamInstructParams, type StreamInstructResult, type StreamParams, type StreamResult, type SubagentAction, TaskError, type TextPart, type ThinkingPart, type ToolAction, type ToolChoice, type ToolContext, type ToolDefinition, ToolRegistry, type ToolResultPart, type TraceWriter, Tracer, type TracingContext, type Turn, TurnBuilder, type TurnPart, type TurnStatus, anthropic, braveSearchTool, calculatorTool, chatCompletions, createHandle, estimateContextUsage, execTool, gemini, generate, generateTurn, loadFileContent, openai, parseResponse, patchFileTool, readFileTool, stream, writeFileTool };
1305
+ //#region src/utils/stats.d.ts
1306
+ declare function createStats(): Stats;
1307
+ declare function addStats(total: Stats, usage?: Stats): void;
1308
+ //#endregion
1309
+ export { type AIProvider, type AccumulatableEvent, type ActionPart, type ActionResult, Agent, type AgentConfig, type AgentDefinition, type AgentDefinitionRequestOptions, type AgentDefinitionResolver, type AgentErrorResult, type AgentHandle, type AgentMemory, type AgentResult, type AgentSession, type Annotation, type AnnotationEvent, type AnnotationPlacement, type AnnotationStatus, type AnnotationTarget, Anthropic, type AnthropicProviderConfig, AxleAbortError, AxleAgentAbortError, type AxleAssistantMessage, AxleError, type AxleMessage, type AxleModelRequestOptions, AxleStopReason, type AxleToolCallMessage, type AxleToolCallResult, AxleToolFatalError, type AxleUserMessage, type ChatCompletionsProviderConfig, type ContentPart, type ContentPartFile, type ContentPartProviderTool, type ContentPartText, type ContentPartThinking, type ContentPartToolCall, type ContextUsage, type DeferredFileInfo, type EventLevel, type ExecutableTool, type FileInfo, type FileKind, type FilePart, type FileProviderId, type FileResolveFormat, type FileResolveRequest, type FileResolver, type FileStore, Gemini, type GeminiProviderConfig, type GenerateInstructParams, type GenerateInstructResult, type GenerateParams, type Handle, History, Instruct, type InstructInputs, type InstructOptions, type InstructResponse, InstructVariableError, type InstructVarsMode, MCP, type MCPConfig, type MCPHttpConfig, type MCPStdioConfig, type MaybePromise, type MemoryContext, OpenAI, type OpenAIProviderConfig, type OutputSchema, type ParsedSchema, type ProviderDefinition, type ProviderOptions, type ProviderTool, type ProviderToolAction, type ProviderToolDefinitionRef, type RecallResult, type ResolvedAgentDefinition, type ResolvedFileSource, type SavedAgent, type SendMessageOptions, SimpleWriter, type SimpleWriterOptions, type SpanData, type SpanOptions, type SpanType, type Stats, type StreamEvent, type StreamEventCallback, type StreamHandle, type StreamInstructHandle, type StreamInstructParams, type StreamInstructResult, type StreamParams, type StreamResult, type SubagentAction, TaskError, type TextPart, type ThinkingPart, type ToolAction, type ToolChoice, type ToolContext, type ToolDefinition, type ToolDefinitionRef, ToolRegistry, type ToolResultPart, type TraceWriter, Tracer, type TracingContext, type Turn, TurnAccumulator, type TurnAccumulatorResult, type TurnAccumulatorState, type TurnEvent, TurnEventBuilder, type TurnEventCallback, type TurnPart, type TurnStatus, addStats, anthropic, chatCompletions, createAgentConfig, createHandle, createStats, estimateContextUsage, gemini, generate, generateTurn, loadFileContent, openai, parseResponse, stream };