llmist 6.0.0 → 6.1.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.
@@ -398,7 +398,7 @@ interface MessageTurn {
398
398
  * Event emitted when compaction occurs.
399
399
  * This is included in StreamEvent for UI visibility.
400
400
  */
401
- interface CompactionEvent {
401
+ interface CompactionEvent$1 {
402
402
  /** The strategy that performed the compaction */
403
403
  strategy: string;
404
404
  /** Token count before compaction */
@@ -502,7 +502,7 @@ interface CompactionConfig {
502
502
  * Callback invoked when compaction occurs.
503
503
  * Useful for logging or analytics.
504
504
  */
505
- onCompaction?: (event: CompactionEvent) => void;
505
+ onCompaction?: (event: CompactionEvent$1) => void;
506
506
  }
507
507
  /**
508
508
  * Default configuration values for compaction.
@@ -524,7 +524,679 @@ interface ResolvedCompactionConfig {
524
524
  preserveRecentTurns: number;
525
525
  summarizationModel?: string;
526
526
  summarizationPrompt: string;
527
- onCompaction?: (event: CompactionEvent) => void;
527
+ onCompaction?: (event: CompactionEvent$1) => void;
528
+ }
529
+
530
+ interface LLMGenerationOptions {
531
+ model: string;
532
+ messages: LLMMessage[];
533
+ maxTokens?: number;
534
+ temperature?: number;
535
+ topP?: number;
536
+ stopSequences?: string[];
537
+ responseFormat?: "text";
538
+ metadata?: Record<string, unknown>;
539
+ extra?: Record<string, unknown>;
540
+ /**
541
+ * Optional abort signal for cancelling the request mid-flight.
542
+ *
543
+ * When the signal is aborted, the provider will attempt to cancel
544
+ * the underlying HTTP request and the stream will terminate with
545
+ * an abort error. Use `isAbortError()` from `@/core/errors` to
546
+ * detect cancellation in error handling.
547
+ *
548
+ * @example
549
+ * ```typescript
550
+ * const controller = new AbortController();
551
+ *
552
+ * const stream = client.stream({
553
+ * model: "claude-3-5-sonnet-20241022",
554
+ * messages: [{ role: "user", content: "Tell me a long story" }],
555
+ * signal: controller.signal,
556
+ * });
557
+ *
558
+ * // Cancel after 5 seconds
559
+ * setTimeout(() => controller.abort(), 5000);
560
+ *
561
+ * try {
562
+ * for await (const chunk of stream) {
563
+ * process.stdout.write(chunk.text);
564
+ * }
565
+ * } catch (error) {
566
+ * if (isAbortError(error)) {
567
+ * console.log("\nRequest was cancelled");
568
+ * } else {
569
+ * throw error;
570
+ * }
571
+ * }
572
+ * ```
573
+ */
574
+ signal?: AbortSignal;
575
+ }
576
+ interface TokenUsage {
577
+ inputTokens: number;
578
+ outputTokens: number;
579
+ totalTokens: number;
580
+ /** Number of input tokens served from cache (subset of inputTokens) */
581
+ cachedInputTokens?: number;
582
+ /** Number of input tokens written to cache (subset of inputTokens, Anthropic only) */
583
+ cacheCreationInputTokens?: number;
584
+ }
585
+ interface LLMStreamChunk {
586
+ text: string;
587
+ /**
588
+ * Indicates that the provider has finished producing output and includes the reason if available.
589
+ */
590
+ finishReason?: string | null;
591
+ /**
592
+ * Token usage information, typically available in the final chunk when the stream completes.
593
+ */
594
+ usage?: TokenUsage;
595
+ /**
596
+ * Provider specific payload emitted at the same time as the text chunk. This is useful for debugging and tests.
597
+ */
598
+ rawEvent?: unknown;
599
+ }
600
+ interface LLMStream extends AsyncIterable<LLMStreamChunk> {
601
+ }
602
+ type ProviderIdentifier = string;
603
+ interface ModelDescriptor {
604
+ provider: string;
605
+ name: string;
606
+ }
607
+ declare class ModelIdentifierParser {
608
+ private readonly defaultProvider;
609
+ constructor(defaultProvider?: string);
610
+ parse(identifier: string): ModelDescriptor;
611
+ }
612
+
613
+ /**
614
+ * Unified event types for the Execution Tree.
615
+ *
616
+ * All events carry full tree context (nodeId, parentId, depth, path).
617
+ * No special SubagentEvent wrapper needed - subagent events are regular
618
+ * events with depth > 0.
619
+ *
620
+ * @module core/execution-events
621
+ */
622
+
623
+ /**
624
+ * Base properties shared by all execution events.
625
+ * Every event carries full tree context.
626
+ */
627
+ interface BaseExecutionEvent {
628
+ /** Monotonically increasing event ID */
629
+ eventId: number;
630
+ /** Event timestamp */
631
+ timestamp: number;
632
+ /** Node that emitted this event */
633
+ nodeId: string;
634
+ /** Parent node ID (null for root events) */
635
+ parentId: string | null;
636
+ /** Nesting depth (0 = root, 1 = child, etc.) */
637
+ depth: number;
638
+ /** Full path from root to this node */
639
+ path: string[];
640
+ }
641
+ /**
642
+ * Emitted when an LLM call starts.
643
+ */
644
+ interface LLMCallStartEvent extends BaseExecutionEvent {
645
+ type: "llm_call_start";
646
+ /** Iteration number within agent loop (1-indexed) */
647
+ iteration: number;
648
+ /** Model identifier */
649
+ model: string;
650
+ /** Request messages */
651
+ request?: LLMMessage[];
652
+ }
653
+ /**
654
+ * Emitted for each streaming chunk from LLM.
655
+ */
656
+ interface LLMCallStreamEvent extends BaseExecutionEvent {
657
+ type: "llm_call_stream";
658
+ /** Text chunk */
659
+ chunk: string;
660
+ }
661
+ /**
662
+ * Emitted when an LLM call completes successfully.
663
+ */
664
+ interface LLMCallCompleteEvent extends BaseExecutionEvent {
665
+ type: "llm_call_complete";
666
+ /** Complete response text */
667
+ response: string;
668
+ /** Token usage */
669
+ usage?: TokenUsage;
670
+ /** Finish reason from LLM */
671
+ finishReason?: string | null;
672
+ /** Cost in USD */
673
+ cost?: number;
674
+ }
675
+ /**
676
+ * Emitted when an LLM call fails.
677
+ */
678
+ interface LLMCallErrorEvent extends BaseExecutionEvent {
679
+ type: "llm_call_error";
680
+ /** The error that occurred */
681
+ error: Error;
682
+ /** Whether the error was recovered by a controller */
683
+ recovered: boolean;
684
+ }
685
+ /**
686
+ * Emitted when a gadget call is parsed from LLM output (before execution).
687
+ */
688
+ interface GadgetCallEvent extends BaseExecutionEvent {
689
+ type: "gadget_call";
690
+ /** Invocation ID */
691
+ invocationId: string;
692
+ /** Gadget name */
693
+ name: string;
694
+ /** Parameters */
695
+ parameters: Record<string, unknown>;
696
+ /** Dependencies (other invocation IDs) */
697
+ dependencies: string[];
698
+ }
699
+ /**
700
+ * Emitted when gadget execution starts.
701
+ */
702
+ interface GadgetStartEvent extends BaseExecutionEvent {
703
+ type: "gadget_start";
704
+ /** Invocation ID */
705
+ invocationId: string;
706
+ /** Gadget name */
707
+ name: string;
708
+ }
709
+ /**
710
+ * Emitted when gadget execution completes successfully.
711
+ */
712
+ interface GadgetCompleteEvent extends BaseExecutionEvent {
713
+ type: "gadget_complete";
714
+ /** Invocation ID */
715
+ invocationId: string;
716
+ /** Gadget name */
717
+ name: string;
718
+ /** Result string */
719
+ result: string;
720
+ /** Execution time in ms */
721
+ executionTimeMs: number;
722
+ /** Cost in USD */
723
+ cost?: number;
724
+ /** Media outputs */
725
+ media?: GadgetMediaOutput[];
726
+ }
727
+ /**
728
+ * Emitted when gadget execution fails.
729
+ */
730
+ interface GadgetErrorEvent extends BaseExecutionEvent {
731
+ type: "gadget_error";
732
+ /** Invocation ID */
733
+ invocationId: string;
734
+ /** Gadget name */
735
+ name: string;
736
+ /** Error message */
737
+ error: string;
738
+ /** Execution time in ms */
739
+ executionTimeMs: number;
740
+ }
741
+ /**
742
+ * Emitted when a gadget is skipped.
743
+ */
744
+ interface GadgetSkippedEvent$1 extends BaseExecutionEvent {
745
+ type: "gadget_skipped";
746
+ /** Invocation ID */
747
+ invocationId: string;
748
+ /** Gadget name */
749
+ name: string;
750
+ /** Reason for skipping */
751
+ reason: "dependency_failed" | "controller_skip";
752
+ /** Error message (combines reason and failedDependencyError for consistency with GadgetErrorEvent) */
753
+ error: string;
754
+ /** Failed dependency invocation ID (if dependency_failed) */
755
+ failedDependency?: string;
756
+ /** Error message from failed dependency */
757
+ failedDependencyError?: string;
758
+ }
759
+ /**
760
+ * Emitted for text output from LLM (pure notification, not a tree node).
761
+ */
762
+ interface TextEvent extends BaseExecutionEvent {
763
+ type: "text";
764
+ /** Text content */
765
+ content: string;
766
+ }
767
+ /**
768
+ * Emitted when context compaction occurs.
769
+ */
770
+ interface CompactionEvent extends BaseExecutionEvent {
771
+ type: "compaction";
772
+ /** Tokens before compaction */
773
+ tokensBefore: number;
774
+ /** Tokens after compaction */
775
+ tokensAfter: number;
776
+ /** Compaction strategy used */
777
+ strategy: string;
778
+ /** Messages removed */
779
+ messagesRemoved: number;
780
+ }
781
+ /**
782
+ * Emitted when human input is required.
783
+ */
784
+ interface HumanInputRequiredEvent extends BaseExecutionEvent {
785
+ type: "human_input_required";
786
+ /** Question for the user */
787
+ question: string;
788
+ /** Gadget name requesting input */
789
+ gadgetName: string;
790
+ /** Invocation ID */
791
+ invocationId: string;
792
+ }
793
+ /**
794
+ * Emitted when the execution stream completes.
795
+ */
796
+ interface StreamCompleteEvent extends BaseExecutionEvent {
797
+ type: "stream_complete";
798
+ /** Whether any gadgets were executed */
799
+ didExecuteGadgets: boolean;
800
+ /** Whether the agent loop should break */
801
+ shouldBreakLoop: boolean;
802
+ /** Total cost for this iteration */
803
+ iterationCost?: number;
804
+ }
805
+ /**
806
+ * All LLM-related events.
807
+ */
808
+ type LLMEvent = LLMCallStartEvent | LLMCallStreamEvent | LLMCallCompleteEvent | LLMCallErrorEvent;
809
+ /**
810
+ * All gadget-related events.
811
+ */
812
+ type GadgetEvent = GadgetCallEvent | GadgetStartEvent | GadgetCompleteEvent | GadgetErrorEvent | GadgetSkippedEvent$1;
813
+ /**
814
+ * Union of all execution events.
815
+ */
816
+ type ExecutionEvent = LLMCallStartEvent | LLMCallStreamEvent | LLMCallCompleteEvent | LLMCallErrorEvent | GadgetCallEvent | GadgetStartEvent | GadgetCompleteEvent | GadgetErrorEvent | GadgetSkippedEvent$1 | TextEvent | CompactionEvent | HumanInputRequiredEvent | StreamCompleteEvent;
817
+ /**
818
+ * Event type discriminator.
819
+ */
820
+ type ExecutionEventType = ExecutionEvent["type"] | "*";
821
+ /**
822
+ * Check if an event is an LLM event.
823
+ */
824
+ declare function isLLMEvent(event: ExecutionEvent): event is LLMEvent;
825
+ /**
826
+ * Check if an event is a gadget event.
827
+ */
828
+ declare function isGadgetEvent(event: ExecutionEvent): event is GadgetEvent;
829
+ /**
830
+ * Check if an event is from a subagent (nested execution).
831
+ */
832
+ declare function isSubagentEvent(event: ExecutionEvent): boolean;
833
+ /**
834
+ * Check if an event is from the root agent.
835
+ */
836
+ declare function isRootEvent(event: ExecutionEvent): boolean;
837
+ /**
838
+ * Filter events by depth.
839
+ */
840
+ declare function filterByDepth(events: ExecutionEvent[], depth: number): ExecutionEvent[];
841
+ /**
842
+ * Filter events by parent node.
843
+ */
844
+ declare function filterByParent(events: ExecutionEvent[], parentId: string): ExecutionEvent[];
845
+ /**
846
+ * Filter events to only root-level events.
847
+ */
848
+ declare function filterRootEvents(events: ExecutionEvent[]): ExecutionEvent[];
849
+ /**
850
+ * Group events by their parent node.
851
+ */
852
+ declare function groupByParent(events: ExecutionEvent[]): Map<string | null, ExecutionEvent[]>;
853
+
854
+ /**
855
+ * First-class Execution Tree model for nested subagent support.
856
+ *
857
+ * The ExecutionTree is THE single source of truth for execution state.
858
+ * All nodes (including nested subagent nodes) live in one tree.
859
+ * Events are projections of tree changes.
860
+ *
861
+ * @module core/execution-tree
862
+ */
863
+
864
+ /**
865
+ * Unique identifier for any execution node.
866
+ * Format examples: "llm_1", "gadget_abc123", "llm_1_2" (nested)
867
+ */
868
+ type NodeId = string;
869
+ /**
870
+ * Node type discriminator.
871
+ */
872
+ type ExecutionNodeType = "llm_call" | "gadget";
873
+ /**
874
+ * Base properties shared by all execution nodes.
875
+ */
876
+ interface BaseExecutionNode {
877
+ /** Unique identifier for this node */
878
+ id: NodeId;
879
+ /** Node type discriminator */
880
+ type: ExecutionNodeType;
881
+ /** Parent node ID (null for root nodes) */
882
+ parentId: NodeId | null;
883
+ /** Nesting depth (0 = root, 1 = child of gadget, etc.) */
884
+ depth: number;
885
+ /** Path from root to this node: ["llm_1", "gadget_abc", "llm_1_1"] */
886
+ path: NodeId[];
887
+ /** Creation timestamp */
888
+ createdAt: number;
889
+ /** Completion timestamp (null if in progress) */
890
+ completedAt: number | null;
891
+ }
892
+ /**
893
+ * LLM call execution node.
894
+ */
895
+ interface LLMCallNode extends BaseExecutionNode {
896
+ type: "llm_call";
897
+ /** Iteration number within the agent loop (1-indexed for display) */
898
+ iteration: number;
899
+ /** Model identifier */
900
+ model: string;
901
+ /** Request messages (set when call starts) */
902
+ request?: LLMMessage[];
903
+ /** Accumulated response text */
904
+ response: string;
905
+ /** Token usage (set on completion) */
906
+ usage?: TokenUsage;
907
+ /** Finish reason from LLM */
908
+ finishReason?: string | null;
909
+ /** Cost in USD */
910
+ cost?: number;
911
+ /** Child node IDs (gadgets spawned by this LLM call) */
912
+ children: NodeId[];
913
+ }
914
+ /**
915
+ * Gadget execution state.
916
+ */
917
+ type GadgetState = "pending" | "running" | "completed" | "failed" | "skipped";
918
+ /**
919
+ * Gadget execution node.
920
+ */
921
+ interface GadgetNode extends BaseExecutionNode {
922
+ type: "gadget";
923
+ /** Invocation ID (LLM-generated or auto) */
924
+ invocationId: string;
925
+ /** Gadget name */
926
+ name: string;
927
+ /** Parameters passed to the gadget */
928
+ parameters: Record<string, unknown>;
929
+ /** Dependencies (other invocation IDs this gadget waits for) */
930
+ dependencies: string[];
931
+ /** Execution state */
932
+ state: GadgetState;
933
+ /** Result string (if completed successfully) */
934
+ result?: string;
935
+ /** Error message (if failed or skipped) */
936
+ error?: string;
937
+ /** Failed dependency invocation ID (if skipped due to dependency) */
938
+ failedDependency?: string;
939
+ /** Execution time in milliseconds */
940
+ executionTimeMs?: number;
941
+ /** Cost in USD */
942
+ cost?: number;
943
+ /** Media outputs from this gadget */
944
+ media?: GadgetMediaOutput[];
945
+ /** Child node IDs (nested LLM calls for subagent gadgets) */
946
+ children: NodeId[];
947
+ /** Whether this gadget is a subagent (has nested LLM calls) */
948
+ isSubagent: boolean;
949
+ }
950
+ /**
951
+ * Union of all execution node types.
952
+ */
953
+ type ExecutionNode = LLMCallNode | GadgetNode;
954
+ interface AddLLMCallParams {
955
+ /** Iteration number (1-indexed) */
956
+ iteration: number;
957
+ /** Model identifier */
958
+ model: string;
959
+ /** Request messages */
960
+ request?: LLMMessage[];
961
+ /** Parent node ID (for subagent LLM calls) */
962
+ parentId?: NodeId | null;
963
+ }
964
+ interface AddGadgetParams {
965
+ /** Invocation ID */
966
+ invocationId: string;
967
+ /** Gadget name */
968
+ name: string;
969
+ /** Parameters */
970
+ parameters: Record<string, unknown>;
971
+ /** Dependencies */
972
+ dependencies?: string[];
973
+ /** Parent LLM call node ID */
974
+ parentId?: NodeId | null;
975
+ }
976
+ interface CompleteLLMCallParams {
977
+ /** Accumulated response text */
978
+ response?: string;
979
+ /** Token usage */
980
+ usage?: TokenUsage;
981
+ /** Finish reason */
982
+ finishReason?: string | null;
983
+ /** Cost in USD */
984
+ cost?: number;
985
+ }
986
+ interface CompleteGadgetParams {
987
+ /** Result string */
988
+ result?: string;
989
+ /** Error message */
990
+ error?: string;
991
+ /** Failed dependency (for skipped gadgets) */
992
+ failedDependency?: string;
993
+ /** Execution time in ms */
994
+ executionTimeMs?: number;
995
+ /** Cost in USD */
996
+ cost?: number;
997
+ /** Media outputs */
998
+ media?: GadgetMediaOutput[];
999
+ }
1000
+
1001
+ /** Event listener function type */
1002
+ type EventListener = (event: ExecutionEvent) => void;
1003
+ /**
1004
+ * The Execution Tree - single source of truth for all execution state.
1005
+ *
1006
+ * Features:
1007
+ * - Stores all nodes (LLM calls, gadgets) in a hierarchical structure
1008
+ * - Emits events on mutations
1009
+ * - Provides query methods for aggregation (costs, media, descendants)
1010
+ * - Supports single shared tree model for nested subagents
1011
+ *
1012
+ * @example
1013
+ * ```typescript
1014
+ * const tree = new ExecutionTree();
1015
+ *
1016
+ * // Add root LLM call
1017
+ * const llmNode = tree.addLLMCall({ iteration: 1, model: "sonnet" });
1018
+ *
1019
+ * // Add gadget under the LLM call
1020
+ * const gadgetNode = tree.addGadget({
1021
+ * invocationId: "gc_1",
1022
+ * name: "ReadFile",
1023
+ * parameters: { path: "/foo.txt" },
1024
+ * parentId: llmNode.id,
1025
+ * });
1026
+ *
1027
+ * // Complete the gadget
1028
+ * tree.completeGadget(gadgetNode.id, { result: "file contents", executionTimeMs: 50 });
1029
+ *
1030
+ * // Query total cost
1031
+ * console.log(tree.getTotalCost());
1032
+ * ```
1033
+ */
1034
+ declare class ExecutionTree {
1035
+ private nodes;
1036
+ private rootIds;
1037
+ private eventListeners;
1038
+ private eventIdCounter;
1039
+ private invocationIdToNodeId;
1040
+ private eventQueue;
1041
+ private eventWaiters;
1042
+ private isCompleted;
1043
+ /**
1044
+ * Base depth for all nodes in this tree.
1045
+ * Used when this tree is a subagent's view into a parent tree.
1046
+ */
1047
+ readonly baseDepth: number;
1048
+ /**
1049
+ * Parent node ID for subagent trees.
1050
+ * All root nodes in this tree will have this as their parentId.
1051
+ */
1052
+ readonly parentNodeId: NodeId | null;
1053
+ constructor(options?: {
1054
+ baseDepth?: number;
1055
+ parentNodeId?: NodeId | null;
1056
+ });
1057
+ private generateLLMCallId;
1058
+ private gadgetIdCounter;
1059
+ private generateGadgetId;
1060
+ private emit;
1061
+ private createBaseEventProps;
1062
+ /**
1063
+ * Add a new LLM call node to the tree.
1064
+ */
1065
+ addLLMCall(params: AddLLMCallParams): LLMCallNode;
1066
+ /**
1067
+ * Add text to an LLM call's response (for streaming).
1068
+ */
1069
+ appendLLMResponse(nodeId: NodeId, chunk: string): void;
1070
+ /**
1071
+ * Complete an LLM call node.
1072
+ */
1073
+ completeLLMCall(nodeId: NodeId, params: CompleteLLMCallParams): void;
1074
+ /**
1075
+ * Mark an LLM call as failed.
1076
+ */
1077
+ failLLMCall(nodeId: NodeId, error: Error, recovered: boolean): void;
1078
+ /**
1079
+ * Add a new gadget node to the tree.
1080
+ */
1081
+ addGadget(params: AddGadgetParams): GadgetNode;
1082
+ /**
1083
+ * Mark a gadget as started (running).
1084
+ */
1085
+ startGadget(nodeId: NodeId): void;
1086
+ /**
1087
+ * Complete a gadget node successfully.
1088
+ */
1089
+ completeGadget(nodeId: NodeId, params: CompleteGadgetParams): void;
1090
+ /**
1091
+ * Mark a gadget as skipped due to dependency failure.
1092
+ */
1093
+ skipGadget(nodeId: NodeId, failedDependency: string, failedDependencyError: string, reason: "dependency_failed" | "controller_skip"): void;
1094
+ /**
1095
+ * Emit a text event (notification only, not stored in tree).
1096
+ */
1097
+ emitText(content: string, llmCallNodeId: NodeId): void;
1098
+ /**
1099
+ * Get a node by ID.
1100
+ */
1101
+ getNode(id: NodeId): ExecutionNode | undefined;
1102
+ /**
1103
+ * Get a gadget node by invocation ID.
1104
+ */
1105
+ getNodeByInvocationId(invocationId: string): GadgetNode | undefined;
1106
+ /**
1107
+ * Get all root nodes (depth 0 for this tree).
1108
+ */
1109
+ getRoots(): ExecutionNode[];
1110
+ /**
1111
+ * Get children of a node.
1112
+ */
1113
+ getChildren(id: NodeId): ExecutionNode[];
1114
+ /**
1115
+ * Get ancestors of a node (from root to parent).
1116
+ */
1117
+ getAncestors(id: NodeId): ExecutionNode[];
1118
+ /**
1119
+ * Get all descendants of a node.
1120
+ */
1121
+ getDescendants(id: NodeId, type?: ExecutionNodeType): ExecutionNode[];
1122
+ /**
1123
+ * Get the current (most recent incomplete) LLM call node.
1124
+ */
1125
+ getCurrentLLMCallId(): NodeId | undefined;
1126
+ /**
1127
+ * Get total cost for entire tree.
1128
+ */
1129
+ getTotalCost(): number;
1130
+ /**
1131
+ * Get total cost for a subtree (node and all descendants).
1132
+ */
1133
+ getSubtreeCost(nodeId: NodeId): number;
1134
+ /**
1135
+ * Get token usage for entire tree.
1136
+ */
1137
+ getTotalTokens(): {
1138
+ input: number;
1139
+ output: number;
1140
+ cached: number;
1141
+ };
1142
+ /**
1143
+ * Get token usage for a subtree.
1144
+ */
1145
+ getSubtreeTokens(nodeId: NodeId): {
1146
+ input: number;
1147
+ output: number;
1148
+ cached: number;
1149
+ };
1150
+ /**
1151
+ * Collect all media from a subtree.
1152
+ */
1153
+ getSubtreeMedia(nodeId: NodeId): GadgetMediaOutput[];
1154
+ /**
1155
+ * Check if a subtree is complete (all nodes finished).
1156
+ */
1157
+ isSubtreeComplete(nodeId: NodeId): boolean;
1158
+ /**
1159
+ * Get node counts.
1160
+ */
1161
+ getNodeCount(): {
1162
+ llmCalls: number;
1163
+ gadgets: number;
1164
+ };
1165
+ /**
1166
+ * Subscribe to events of a specific type.
1167
+ * Returns unsubscribe function.
1168
+ *
1169
+ * @param type - Event type to subscribe to (use "*" for all events)
1170
+ * @param listener - Callback function that receives matching events
1171
+ * @returns Unsubscribe function
1172
+ *
1173
+ * @example
1174
+ * ```typescript
1175
+ * const unsubscribe = tree.on("gadget_complete", (event) => {
1176
+ * if (event.type === "gadget_complete") {
1177
+ * console.log(`Gadget ${event.name} completed`);
1178
+ * }
1179
+ * });
1180
+ * ```
1181
+ */
1182
+ on(type: ExecutionEventType, listener: EventListener): () => void;
1183
+ /**
1184
+ * Subscribe to all events.
1185
+ */
1186
+ onAll(listener: EventListener): () => void;
1187
+ /**
1188
+ * Get async iterable of all events.
1189
+ * Events are yielded as they occur.
1190
+ */
1191
+ events(): AsyncGenerator<ExecutionEvent>;
1192
+ /**
1193
+ * Mark the tree as complete (no more events will be emitted).
1194
+ */
1195
+ complete(): void;
1196
+ /**
1197
+ * Check if the tree is complete.
1198
+ */
1199
+ isComplete(): boolean;
528
1200
  }
529
1201
 
530
1202
  /**
@@ -643,89 +1315,6 @@ declare class ModelRegistry {
643
1315
  getCheapestModel(inputTokens: number, outputTokens: number, providerId?: string): ModelSpec | undefined;
644
1316
  }
645
1317
 
646
- interface LLMGenerationOptions {
647
- model: string;
648
- messages: LLMMessage[];
649
- maxTokens?: number;
650
- temperature?: number;
651
- topP?: number;
652
- stopSequences?: string[];
653
- responseFormat?: "text";
654
- metadata?: Record<string, unknown>;
655
- extra?: Record<string, unknown>;
656
- /**
657
- * Optional abort signal for cancelling the request mid-flight.
658
- *
659
- * When the signal is aborted, the provider will attempt to cancel
660
- * the underlying HTTP request and the stream will terminate with
661
- * an abort error. Use `isAbortError()` from `@/core/errors` to
662
- * detect cancellation in error handling.
663
- *
664
- * @example
665
- * ```typescript
666
- * const controller = new AbortController();
667
- *
668
- * const stream = client.stream({
669
- * model: "claude-3-5-sonnet-20241022",
670
- * messages: [{ role: "user", content: "Tell me a long story" }],
671
- * signal: controller.signal,
672
- * });
673
- *
674
- * // Cancel after 5 seconds
675
- * setTimeout(() => controller.abort(), 5000);
676
- *
677
- * try {
678
- * for await (const chunk of stream) {
679
- * process.stdout.write(chunk.text);
680
- * }
681
- * } catch (error) {
682
- * if (isAbortError(error)) {
683
- * console.log("\nRequest was cancelled");
684
- * } else {
685
- * throw error;
686
- * }
687
- * }
688
- * ```
689
- */
690
- signal?: AbortSignal;
691
- }
692
- interface TokenUsage {
693
- inputTokens: number;
694
- outputTokens: number;
695
- totalTokens: number;
696
- /** Number of input tokens served from cache (subset of inputTokens) */
697
- cachedInputTokens?: number;
698
- /** Number of input tokens written to cache (subset of inputTokens, Anthropic only) */
699
- cacheCreationInputTokens?: number;
700
- }
701
- interface LLMStreamChunk {
702
- text: string;
703
- /**
704
- * Indicates that the provider has finished producing output and includes the reason if available.
705
- */
706
- finishReason?: string | null;
707
- /**
708
- * Token usage information, typically available in the final chunk when the stream completes.
709
- */
710
- usage?: TokenUsage;
711
- /**
712
- * Provider specific payload emitted at the same time as the text chunk. This is useful for debugging and tests.
713
- */
714
- rawEvent?: unknown;
715
- }
716
- interface LLMStream extends AsyncIterable<LLMStreamChunk> {
717
- }
718
- type ProviderIdentifier = string;
719
- interface ModelDescriptor {
720
- provider: string;
721
- name: string;
722
- }
723
- declare class ModelIdentifierParser {
724
- private readonly defaultProvider;
725
- constructor(defaultProvider?: string);
726
- parse(identifier: string): ModelDescriptor;
727
- }
728
-
729
1318
  /**
730
1319
  * Quick execution methods for simple use cases.
731
1320
  *
@@ -1021,7 +1610,7 @@ type StreamEvent = {
1021
1610
  invocationId: string;
1022
1611
  } | {
1023
1612
  type: "compaction";
1024
- event: CompactionEvent;
1613
+ event: CompactionEvent$1;
1025
1614
  } | SubagentStreamEvent | StreamCompletionEvent;
1026
1615
  /** Event for forwarding subagent activity through the stream */
1027
1616
  interface SubagentStreamEvent {
@@ -1091,6 +1680,8 @@ interface SubagentEvent {
1091
1680
  gadgetInvocationId: string;
1092
1681
  /** Nesting depth (1 = direct child, 2 = grandchild, etc.) */
1093
1682
  depth: number;
1683
+ /** LLM iteration number within the subagent (for gadget parenting in TUI) */
1684
+ iteration?: number;
1094
1685
  /** The actual event data - either a StreamEvent or LLMCallInfo */
1095
1686
  event: StreamEvent | LLMCallInfo;
1096
1687
  }
@@ -1437,6 +2028,88 @@ interface ExecutionContext {
1437
2028
  * ```
1438
2029
  */
1439
2030
  onSubagentEvent?: (event: SubagentEvent) => void;
2031
+ /**
2032
+ * The execution tree tracking all LLM calls and gadget executions.
2033
+ *
2034
+ * Subagent gadgets can use the tree to:
2035
+ * - Automatically aggregate costs via `tree.getSubtreeCost(nodeId)`
2036
+ * - Collect media outputs via `tree.getSubtreeMedia(nodeId)`
2037
+ * - Query token usage via `tree.getSubtreeTokens(nodeId)`
2038
+ *
2039
+ * When using `withParentContext(ctx)`, the subagent shares the parent's tree,
2040
+ * enabling unified cost tracking and progress visibility across all nesting levels.
2041
+ *
2042
+ * This is optional - it will be `undefined` for:
2043
+ * - Gadgets executed via CLI `gadget run` command
2044
+ * - Direct gadget testing without agent context
2045
+ * - Legacy code that hasn't adopted the ExecutionTree model
2046
+ *
2047
+ * @example
2048
+ * ```typescript
2049
+ * execute: async (params, ctx) => {
2050
+ * // Build subagent with parent context (shares tree)
2051
+ * const agent = new AgentBuilder(client)
2052
+ * .withParentContext(ctx)
2053
+ * .withGadgets(Navigate, Click)
2054
+ * .ask(params.task);
2055
+ *
2056
+ * for await (const event of agent.run()) {
2057
+ * // Process events...
2058
+ * }
2059
+ *
2060
+ * // After subagent completes, costs are automatically tracked in tree
2061
+ * // No need for manual cost aggregation!
2062
+ * const subtreeCost = ctx.tree?.getSubtreeCost(ctx.nodeId!);
2063
+ *
2064
+ * // Media from all nested gadgets also aggregated
2065
+ * const allMedia = ctx.tree?.getSubtreeMedia(ctx.nodeId!);
2066
+ *
2067
+ * return { result: "done", media: allMedia };
2068
+ * }
2069
+ * ```
2070
+ */
2071
+ tree?: ExecutionTree;
2072
+ /**
2073
+ * The tree node ID for this gadget execution.
2074
+ *
2075
+ * This identifies the current gadget's node in the execution tree.
2076
+ * Use with tree methods to query/aggregate data for this subtree:
2077
+ * - `tree.getSubtreeCost(nodeId)` - total cost including nested calls
2078
+ * - `tree.getSubtreeMedia(nodeId)` - all media from nested gadgets
2079
+ * - `tree.getSubtreeTokens(nodeId)` - token usage breakdown
2080
+ * - `tree.getDescendants(nodeId)` - all child nodes
2081
+ *
2082
+ * Note: This is distinct from `invocationId` which identifies the gadget call
2083
+ * (used in conversation history). `nodeId` is the tree node identifier.
2084
+ */
2085
+ nodeId?: NodeId;
2086
+ /**
2087
+ * Nesting depth of this gadget execution.
2088
+ *
2089
+ * - 0 = Root level (direct gadget call from main agent)
2090
+ * - 1 = First-level subagent (gadget called by a gadget)
2091
+ * - 2+ = Deeper nesting
2092
+ *
2093
+ * Useful for:
2094
+ * - Conditional behavior based on nesting level
2095
+ * - Logging with appropriate indentation
2096
+ * - Limiting recursion depth
2097
+ *
2098
+ * @example
2099
+ * ```typescript
2100
+ * execute: async (params, ctx) => {
2101
+ * // Prevent infinite recursion
2102
+ * if ((ctx.depth ?? 0) > 3) {
2103
+ * return "Maximum nesting depth reached";
2104
+ * }
2105
+ *
2106
+ * // Log with depth-aware indentation
2107
+ * const indent = " ".repeat(ctx.depth ?? 0);
2108
+ * console.log(`${indent}Executing at depth ${ctx.depth}`);
2109
+ * }
2110
+ * ```
2111
+ */
2112
+ depth?: number;
1440
2113
  }
1441
2114
  /**
1442
2115
  * Parent agent configuration passed to gadgets.
@@ -2143,13 +2816,16 @@ declare class LLMMessageBuilder {
2143
2816
  * Record a gadget execution result in the message history.
2144
2817
  * Creates an assistant message with the gadget invocation and a user message with the result.
2145
2818
  *
2819
+ * The invocationId is shown to the LLM so it can reference previous calls when building dependencies.
2820
+ *
2146
2821
  * @param gadget - Name of the gadget that was executed
2147
2822
  * @param parameters - Parameters that were passed to the gadget
2148
2823
  * @param result - Text result from the gadget execution
2824
+ * @param invocationId - Invocation ID (shown to LLM so it can reference for dependencies)
2149
2825
  * @param media - Optional media outputs from the gadget
2150
2826
  * @param mediaIds - Optional IDs for the media outputs
2151
2827
  */
2152
- addGadgetCallResult(gadget: string, parameters: Record<string, unknown>, result: string, media?: GadgetMediaOutput[], mediaIds?: string[]): this;
2828
+ addGadgetCallResult(gadget: string, parameters: Record<string, unknown>, result: string, invocationId: string, media?: GadgetMediaOutput[], mediaIds?: string[]): this;
2153
2829
  /**
2154
2830
  * Format parameters as Block format with JSON Pointer paths.
2155
2831
  * Uses the configured argPrefix for consistency with system prompt.
@@ -3253,7 +3929,7 @@ interface ObserveCompactionContext {
3253
3929
  /** Agent iteration when compaction occurred */
3254
3930
  iteration: number;
3255
3931
  /** Details of the compaction event */
3256
- event: CompactionEvent;
3932
+ event: CompactionEvent$1;
3257
3933
  /** Cumulative compaction statistics */
3258
3934
  stats: CompactionStats;
3259
3935
  /** Logger instance */
@@ -3623,15 +4299,6 @@ interface AgentOptions {
3623
4299
  /** Maps text content to the result string (optional, defaults to text) */
3624
4300
  resultMapping?: (text: string) => string;
3625
4301
  };
3626
- /** Stop on gadget error */
3627
- stopOnGadgetError?: boolean;
3628
- /** Custom error recovery logic */
3629
- canRecoverFromGadgetError?: (context: {
3630
- error: string;
3631
- gadgetName: string;
3632
- errorType: "parse" | "validation" | "execution";
3633
- parameters?: Record<string, unknown>;
3634
- }) => boolean | Promise<boolean>;
3635
4302
  /** Default gadget timeout */
3636
4303
  defaultGadgetTimeoutMs?: number;
3637
4304
  /** Custom prompt configuration for gadget system prompts */
@@ -3648,6 +4315,22 @@ interface AgentOptions {
3648
4315
  subagentConfig?: SubagentConfigMap;
3649
4316
  /** Callback for subagent gadgets to report subagent events to parent */
3650
4317
  onSubagentEvent?: (event: SubagentEvent) => void;
4318
+ /**
4319
+ * Shared execution tree for tracking all LLM calls and gadget executions.
4320
+ * If provided (by a parent subagent), nodes are added to this tree.
4321
+ * If not provided, the Agent creates its own tree.
4322
+ */
4323
+ parentTree?: ExecutionTree;
4324
+ /**
4325
+ * Parent node ID in the tree (when this agent is a subagent).
4326
+ * Used to set parentId on all nodes created by this agent.
4327
+ */
4328
+ parentNodeId?: NodeId;
4329
+ /**
4330
+ * Base depth for nodes created by this agent.
4331
+ * Root agents use 0; subagents use (parentDepth + 1).
4332
+ */
4333
+ baseDepth?: number;
3651
4334
  }
3652
4335
  /**
3653
4336
  * Agent: Lean orchestrator that delegates to StreamProcessor.
@@ -3679,8 +4362,6 @@ declare class Agent {
3679
4362
  private readonly requestHumanInput?;
3680
4363
  private readonly textOnlyHandler;
3681
4364
  private readonly textWithGadgetsHandler?;
3682
- private readonly stopOnGadgetError;
3683
- private readonly canRecoverFromGadgetError?;
3684
4365
  private readonly defaultGadgetTimeoutMs?;
3685
4366
  private readonly defaultMaxTokens?;
3686
4367
  private hasUserPrompt;
@@ -3695,6 +4376,10 @@ declare class Agent {
3695
4376
  private readonly userSubagentEventCallback?;
3696
4377
  private readonly pendingSubagentEvents;
3697
4378
  private readonly onSubagentEvent;
4379
+ private syntheticInvocationCounter;
4380
+ private readonly tree;
4381
+ private readonly parentNodeId;
4382
+ private readonly baseDepth;
3698
4383
  /**
3699
4384
  * Creates a new Agent instance.
3700
4385
  * @internal This constructor is private. Use LLMist.createAgent() or AgentBuilder instead.
@@ -3752,6 +4437,46 @@ declare class Agent {
3752
4437
  * ```
3753
4438
  */
3754
4439
  getMediaStore(): MediaStore;
4440
+ /**
4441
+ * Get the execution tree for this agent.
4442
+ *
4443
+ * The execution tree provides a first-class model of all LLM calls and gadget executions,
4444
+ * including nested subagent activity. Use this to:
4445
+ * - Query execution state: `tree.getNode(id)`
4446
+ * - Get total cost: `tree.getTotalCost()`
4447
+ * - Get subtree cost/media/tokens: `tree.getSubtreeCost(nodeId)`
4448
+ * - Subscribe to events: `tree.on("llm_call_complete", handler)`
4449
+ * - Stream all events: `for await (const event of tree.events())`
4450
+ *
4451
+ * For subagents (created with `withParentContext`), the tree is shared with the parent,
4452
+ * enabling unified tracking and real-time visibility across all nesting levels.
4453
+ *
4454
+ * @returns The ExecutionTree instance
4455
+ *
4456
+ * @example
4457
+ * ```typescript
4458
+ * const agent = LLMist.createAgent()
4459
+ * .withModel("sonnet")
4460
+ * .withGadgets(BrowseWeb)
4461
+ * .ask("Research topic X");
4462
+ *
4463
+ * for await (const event of agent.run()) {
4464
+ * // Process events...
4465
+ * }
4466
+ *
4467
+ * // After execution, query the tree
4468
+ * const tree = agent.getTree();
4469
+ * console.log(`Total cost: $${tree.getTotalCost().toFixed(4)}`);
4470
+ *
4471
+ * // Inspect all LLM calls
4472
+ * for (const node of tree.getAllNodes()) {
4473
+ * if (node.type === "llm_call") {
4474
+ * console.log(`LLM #${node.iteration}: ${node.model}`);
4475
+ * }
4476
+ * }
4477
+ * ```
4478
+ */
4479
+ getTree(): ExecutionTree;
3755
4480
  /**
3756
4481
  * Manually trigger context compaction.
3757
4482
  *
@@ -3775,7 +4500,7 @@ declare class Agent {
3775
4500
  * }
3776
4501
  * ```
3777
4502
  */
3778
- compact(): Promise<CompactionEvent | null>;
4503
+ compact(): Promise<CompactionEvent$1 | null>;
3779
4504
  /**
3780
4505
  * Get compaction statistics.
3781
4506
  *
@@ -3901,8 +4626,6 @@ declare class AgentBuilder {
3901
4626
  private gadgetArgPrefix?;
3902
4627
  private textOnlyHandler?;
3903
4628
  private textWithGadgetsHandler?;
3904
- private stopOnGadgetError?;
3905
- private canRecoverFromGadgetError?;
3906
4629
  private defaultGadgetTimeoutMs?;
3907
4630
  private gadgetOutputLimit?;
3908
4631
  private gadgetOutputLimitPercent?;
@@ -4140,61 +4863,6 @@ declare class AgentBuilder {
4140
4863
  parameterMapping: (text: string) => Record<string, unknown>;
4141
4864
  resultMapping?: (text: string) => string;
4142
4865
  }): this;
4143
- /**
4144
- * Set whether to stop gadget execution on first error.
4145
- *
4146
- * When true (default), if a gadget fails:
4147
- * - Subsequent gadgets in the same response are skipped
4148
- * - LLM stream is cancelled to save costs
4149
- * - Agent loop continues with error in context
4150
- *
4151
- * When false:
4152
- * - All gadgets in the response still execute
4153
- * - LLM stream continues to completion
4154
- *
4155
- * @param stop - Whether to stop on gadget error
4156
- * @returns This builder for chaining
4157
- *
4158
- * @example
4159
- * ```typescript
4160
- * .withStopOnGadgetError(false)
4161
- * ```
4162
- */
4163
- withStopOnGadgetError(stop: boolean): this;
4164
- /**
4165
- * Set custom error handling logic.
4166
- *
4167
- * Provides fine-grained control over whether to continue after different types of errors.
4168
- * Overrides `stopOnGadgetError` when provided.
4169
- *
4170
- * **Note:** This builder method configures the underlying `canRecoverFromGadgetError` option
4171
- * in `AgentOptions`. The method is named `withErrorHandler` for better developer experience,
4172
- * but maps to the `canRecoverFromGadgetError` property internally.
4173
- *
4174
- * @param handler - Function that decides whether to continue after an error.
4175
- * Return `true` to continue execution, `false` to stop.
4176
- * @returns This builder for chaining
4177
- *
4178
- * @example
4179
- * ```typescript
4180
- * .withErrorHandler((context) => {
4181
- * // Stop on parse errors, continue on validation/execution errors
4182
- * if (context.errorType === "parse") {
4183
- * return false;
4184
- * }
4185
- * if (context.error.includes("CRITICAL")) {
4186
- * return false;
4187
- * }
4188
- * return true;
4189
- * })
4190
- * ```
4191
- */
4192
- withErrorHandler(handler: (context: {
4193
- error: string;
4194
- gadgetName: string;
4195
- errorType: "parse" | "validation" | "execution";
4196
- parameters?: Record<string, unknown>;
4197
- }) => boolean | Promise<boolean>): this;
4198
4866
  /**
4199
4867
  * Set default timeout for gadget execution.
4200
4868
  *
@@ -4359,6 +5027,15 @@ declare class AgentBuilder {
4359
5027
  * The method extracts `invocationId` and `onSubagentEvent` from the execution
4360
5028
  * context and sets up automatic forwarding via hooks and event wrapping.
4361
5029
  *
5030
+ * **NEW: Shared Tree Model** - When the parent provides an ExecutionTree via context,
5031
+ * the subagent shares that tree instead of creating its own. This enables:
5032
+ * - Unified cost tracking across all nesting levels
5033
+ * - Automatic media aggregation via `tree.getSubtreeMedia(nodeId)`
5034
+ * - Real-time visibility of nested execution in the parent
5035
+ *
5036
+ * **Signal Forwarding** - When parent context includes a signal, it's automatically
5037
+ * forwarded to the subagent for proper cancellation propagation.
5038
+ *
4362
5039
  * @param ctx - ExecutionContext passed to the gadget's execute() method
4363
5040
  * @param depth - Nesting depth (default: 1 for direct child)
4364
5041
  * @returns This builder for chaining
@@ -4379,6 +5056,11 @@ declare class AgentBuilder {
4379
5056
  * result = event.content;
4380
5057
  * }
4381
5058
  * }
5059
+ *
5060
+ * // After subagent completes, costs are automatically aggregated
5061
+ * // No manual tracking needed - use tree methods:
5062
+ * const totalCost = ctx.tree?.getSubtreeCost(ctx.nodeId!);
5063
+ * const allMedia = ctx.tree?.getSubtreeMedia(ctx.nodeId!);
4382
5064
  * }
4383
5065
  * ```
4384
5066
  */
@@ -4410,11 +5092,13 @@ declare class AgentBuilder {
4410
5092
  *
4411
5093
  * This is useful for in-context learning - showing the LLM what "past self"
4412
5094
  * did correctly so it mimics the pattern. The call is formatted with proper
4413
- * markers and parameter format.
5095
+ * markers and parameter format, including the invocation ID so the LLM can
5096
+ * reference previous calls when building dependencies.
4414
5097
  *
4415
5098
  * @param gadgetName - Name of the gadget
4416
5099
  * @param parameters - Parameters passed to the gadget
4417
5100
  * @param result - Result returned by the gadget
5101
+ * @param invocationId - Invocation ID (shown to LLM so it can reference for dependencies)
4418
5102
  * @returns This builder for chaining
4419
5103
  *
4420
5104
  * @example
@@ -4426,15 +5110,18 @@ declare class AgentBuilder {
4426
5110
  * done: false,
4427
5111
  * type: 'info'
4428
5112
  * },
4429
- * 'ℹ️ 👋 Hello!\n\nHere\'s what I can do:\n- Analyze code\n- Run commands'
5113
+ * 'ℹ️ 👋 Hello!\n\nHere\'s what I can do:\n- Analyze code\n- Run commands',
5114
+ * 'gc_1'
4430
5115
  * )
4431
5116
  * ```
4432
5117
  */
4433
- withSyntheticGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): this;
5118
+ withSyntheticGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string, invocationId: string): this;
4434
5119
  /**
4435
- * Compose the final hooks, including:
4436
- * - Trailing message injection (if configured)
4437
- * - Subagent event forwarding for LLM calls (if parentContext is set)
5120
+ * Compose the final hooks, including trailing message injection if configured.
5121
+ *
5122
+ * Note: Subagent event visibility is now handled entirely by the ExecutionTree.
5123
+ * When a subagent uses withParentContext(ctx), it shares the parent's tree,
5124
+ * and all events are automatically visible to tree subscribers (like the TUI).
4438
5125
  */
4439
5126
  private composeHooks;
4440
5127
  /**
@@ -4604,9 +5291,10 @@ interface IConversationManager {
4604
5291
  addAssistantMessage(content: string): void;
4605
5292
  /**
4606
5293
  * Adds a gadget call and its result to the conversation.
5294
+ * The invocationId is shown to the LLM so it can reference previous calls when building dependencies.
4607
5295
  * Optionally includes media outputs (images, audio, etc.) for multimodal results.
4608
5296
  */
4609
- addGadgetCallResult(gadgetName: string, parameters: Record<string, unknown>, result: string, media?: GadgetMediaOutput[], mediaIds?: string[]): void;
5297
+ addGadgetCallResult(gadgetName: string, parameters: Record<string, unknown>, result: string, invocationId: string, media?: GadgetMediaOutput[], mediaIds?: string[]): void;
4610
5298
  /**
4611
5299
  * Gets the complete conversation history including base messages (system prompts, gadget instructions).
4612
5300
  */
@@ -5342,4 +6030,4 @@ declare function createTextMockStream(text: string, options?: {
5342
6030
  usage?: MockResponse["usage"];
5343
6031
  }): LLMStream;
5344
6032
 
5345
- export { type LLMGenerationOptions as $, AbstractGadget as A, type MessageContent as B, type CompactionConfig as C, GadgetRegistry as D, MediaStore as E, type AgentContextConfig as F, type GadgetMediaOutput as G, type HintTemplate as H, type IConversationManager as I, type SubagentConfigMap as J, type SubagentEvent as K, type LLMMessage as L, MockProviderAdapter as M, type ExecutionContext as N, type GadgetExecuteReturn as O, type GadgetExample as P, type ParsedGadgetCall as Q, type ResolvedCompactionConfig as R, type StreamEvent as S, type TokenUsage as T, type GadgetExecutionResult as U, type MediaKind as V, type MediaMetadata as W, type GadgetExecuteResultWithMedia as X, type ProviderAdapter as Y, type ModelDescriptor as Z, type ModelSpec as _, type LLMStream as a, isImagePart as a$, type ImageModelSpec as a0, type ImageGenerationOptions as a1, type ImageGenerationResult as a2, type SpeechModelSpec as a3, type SpeechGenerationOptions as a4, type SpeechGenerationResult as a5, type HistoryMessage as a6, type TrailingMessage as a7, type TrailingMessageContext as a8, AgentBuilder as a9, type ObserveLLMCallContext as aA, type ObserveLLMCompleteContext as aB, type ObserveLLMErrorContext as aC, type Observers as aD, type SubagentContext as aE, DEFAULT_COMPACTION_CONFIG as aF, DEFAULT_SUMMARIZATION_PROMPT as aG, type LLMistOptions as aH, type AudioContentPart as aI, type AudioMimeType as aJ, type AudioSource as aK, type ContentPart as aL, type ImageBase64Source as aM, type ImageContentPart as aN, type ImageMimeType as aO, type ImageSource as aP, type ImageUrlSource as aQ, type TextContentPart as aR, audioFromBase64 as aS, audioFromBuffer as aT, detectAudioMimeType as aU, detectImageMimeType as aV, imageFromBase64 as aW, imageFromBuffer as aX, imageFromUrl as aY, isAudioPart as aZ, isDataUrl as a_, type EventHandlers as aa, collectEvents as ab, collectText as ac, runWithHandlers as ad, type AfterGadgetExecutionAction as ae, type AfterGadgetExecutionControllerContext as af, type AfterLLMCallAction as ag, type AfterLLMCallControllerContext as ah, type AfterLLMErrorAction as ai, type AgentOptions as aj, type BeforeGadgetExecutionAction as ak, type BeforeLLMCallAction as al, type ChunkInterceptorContext as am, type Controllers as an, type GadgetExecutionControllerContext as ao, type GadgetParameterInterceptorContext as ap, type GadgetResultInterceptorContext as aq, type Interceptors as ar, type LLMCallControllerContext as as, type LLMErrorControllerContext as at, type MessageInterceptorContext as au, type MessageTurn as av, type ObserveChunkContext as aw, type ObserveCompactionContext as ax, type ObserveGadgetCompleteContext as ay, type ObserveGadgetStartContext as az, type LLMStreamChunk as b, isTextPart as b0, parseDataUrl as b1, text as b2, toBase64 as b3, type MessageRole as b4, extractMessageText as b5, LLMMessageBuilder as b6, normalizeMessageContent as b7, type CostEstimate as b8, type ModelFeatures as b9, type TextOnlyContext as bA, type TextOnlyCustomHandler as bB, type TextOnlyGadgetConfig as bC, type TextOnlyHandler as bD, type TextOnlyStrategy as bE, type ModelLimits as ba, type ModelPricing as bb, type VisionAnalyzeOptions as bc, type VisionAnalyzeResult as bd, type ProviderIdentifier as be, ModelIdentifierParser as bf, type HintContext as bg, type PromptContext as bh, type PromptTemplate as bi, type PromptTemplateConfig as bj, DEFAULT_HINTS as bk, DEFAULT_PROMPTS as bl, resolveHintTemplate as bm, resolvePromptTemplate as bn, resolveRulesTemplate as bo, type TextGenerationOptions as bp, complete as bq, stream as br, type GadgetClass as bs, type GadgetOrClass as bt, type CostReportingLLMist as bu, type GadgetExecuteResult as bv, type GadgetSkippedEvent as bw, type StoredMedia as bx, type SubagentStreamEvent as by, type TextOnlyAction as bz, createMockAdapter as c, MockBuilder as d, createMockClient as e, MockManager as f, getMockManager as g, createMockStream as h, createTextMockStream as i, type MockAudioData as j, type MockImageData as k, type MockMatcher as l, mockLLM as m, type MockMatcherContext as n, type MockOptions as o, type MockRegistration as p, type MockResponse as q, type MockStats as r, type AgentHooks as s, ModelRegistry as t, LLMist as u, type CompactionEvent as v, type CompactionStats as w, type CompactionStrategy as x, type CompactionContext as y, type CompactionResult as z };
6033
+ export { type ModelDescriptor as $, AbstractGadget as A, type MessageContent as B, type CompactionConfig as C, GadgetRegistry as D, MediaStore as E, type AgentContextConfig as F, type GadgetMediaOutput as G, type HintTemplate as H, type IConversationManager as I, type SubagentConfigMap as J, type SubagentEvent as K, type LLMMessage as L, MockProviderAdapter as M, ExecutionTree as N, type NodeId as O, type ExecutionContext as P, type GadgetExecuteReturn as Q, type ResolvedCompactionConfig as R, type StreamEvent as S, type TokenUsage as T, type GadgetExample as U, type ParsedGadgetCall as V, type GadgetExecutionResult as W, type MediaKind as X, type MediaMetadata as Y, type GadgetExecuteResultWithMedia as Z, type ProviderAdapter as _, type LLMStream as a, type GadgetSkippedEvent$1 as a$, type ModelSpec as a0, type LLMGenerationOptions as a1, type ImageModelSpec as a2, type ImageGenerationOptions as a3, type ImageGenerationResult as a4, type SpeechModelSpec as a5, type SpeechGenerationOptions as a6, type SpeechGenerationResult as a7, type HistoryMessage as a8, type TrailingMessage as a9, type ObserveGadgetCompleteContext as aA, type ObserveGadgetStartContext as aB, type ObserveLLMCallContext as aC, type ObserveLLMCompleteContext as aD, type ObserveLLMErrorContext as aE, type Observers as aF, type SubagentContext as aG, DEFAULT_COMPACTION_CONFIG as aH, DEFAULT_SUMMARIZATION_PROMPT as aI, type LLMistOptions as aJ, type AddGadgetParams as aK, type AddLLMCallParams as aL, type CompleteGadgetParams as aM, type CompleteLLMCallParams as aN, type ExecutionNode as aO, type ExecutionNodeType as aP, type GadgetNode as aQ, type GadgetState as aR, type LLMCallNode as aS, type BaseExecutionEvent as aT, type CompactionEvent as aU, type ExecutionEvent as aV, type ExecutionEventType as aW, type GadgetCallEvent as aX, type GadgetCompleteEvent as aY, type GadgetErrorEvent as aZ, type GadgetEvent as a_, type TrailingMessageContext as aa, AgentBuilder as ab, type EventHandlers as ac, collectEvents as ad, collectText as ae, runWithHandlers as af, type AfterGadgetExecutionAction as ag, type AfterGadgetExecutionControllerContext as ah, type AfterLLMCallAction as ai, type AfterLLMCallControllerContext as aj, type AfterLLMErrorAction as ak, type AgentOptions as al, type BeforeGadgetExecutionAction as am, type BeforeLLMCallAction as an, type ChunkInterceptorContext as ao, type Controllers as ap, type GadgetExecutionControllerContext as aq, type GadgetParameterInterceptorContext as ar, type GadgetResultInterceptorContext as as, type Interceptors as at, type LLMCallControllerContext as au, type LLMErrorControllerContext as av, type MessageInterceptorContext as aw, type MessageTurn as ax, type ObserveChunkContext as ay, type ObserveCompactionContext as az, type LLMStreamChunk as b, complete as b$, type GadgetStartEvent as b0, type HumanInputRequiredEvent as b1, type LLMCallCompleteEvent as b2, type LLMCallErrorEvent as b3, type LLMCallStartEvent as b4, type LLMCallStreamEvent as b5, type LLMEvent as b6, type StreamCompleteEvent as b7, type TextEvent as b8, filterByDepth as b9, isImagePart as bA, isTextPart as bB, parseDataUrl as bC, text as bD, toBase64 as bE, type MessageRole as bF, extractMessageText as bG, LLMMessageBuilder as bH, normalizeMessageContent as bI, type CostEstimate as bJ, type ModelFeatures as bK, type ModelLimits as bL, type ModelPricing as bM, type VisionAnalyzeOptions as bN, type VisionAnalyzeResult as bO, type ProviderIdentifier as bP, ModelIdentifierParser as bQ, type HintContext as bR, type PromptContext as bS, type PromptTemplate as bT, type PromptTemplateConfig as bU, DEFAULT_HINTS as bV, DEFAULT_PROMPTS as bW, resolveHintTemplate as bX, resolvePromptTemplate as bY, resolveRulesTemplate as bZ, type TextGenerationOptions as b_, filterByParent as ba, filterRootEvents as bb, groupByParent as bc, isGadgetEvent as bd, isLLMEvent as be, isRootEvent as bf, isSubagentEvent as bg, type AudioContentPart as bh, type AudioMimeType as bi, type AudioSource as bj, type ContentPart as bk, type ImageBase64Source as bl, type ImageContentPart as bm, type ImageMimeType as bn, type ImageSource as bo, type ImageUrlSource as bp, type TextContentPart as bq, audioFromBase64 as br, audioFromBuffer as bs, detectAudioMimeType as bt, detectImageMimeType as bu, imageFromBase64 as bv, imageFromBuffer as bw, imageFromUrl as bx, isAudioPart as by, isDataUrl as bz, createMockAdapter as c, stream as c0, type GadgetClass as c1, type GadgetOrClass as c2, type CostReportingLLMist as c3, type GadgetExecuteResult as c4, type GadgetSkippedEvent as c5, type StoredMedia as c6, type SubagentStreamEvent as c7, type TextOnlyAction as c8, type TextOnlyContext as c9, type TextOnlyCustomHandler as ca, type TextOnlyGadgetConfig as cb, type TextOnlyHandler as cc, type TextOnlyStrategy as cd, MockBuilder as d, createMockClient as e, MockManager as f, getMockManager as g, createMockStream as h, createTextMockStream as i, type MockAudioData as j, type MockImageData as k, type MockMatcher as l, mockLLM as m, type MockMatcherContext as n, type MockOptions as o, type MockRegistration as p, type MockResponse as q, type MockStats as r, type AgentHooks as s, ModelRegistry as t, LLMist as u, type CompactionEvent$1 as v, type CompactionStats as w, type CompactionStrategy as x, type CompactionContext as y, type CompactionResult as z };