llmist 2.5.0 → 3.0.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.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ZodType, ZodTypeAny } from 'zod';
2
2
  export { z } from 'zod';
3
- import { A as AgentHooks, s as ModelRegistry, I as IConversationManager, b as LLMMessage, t as MessageContent, S as StreamEvent, T as TokenUsage, G as GadgetRegistry, u as LLMist, a as LLMStreamChunk, C as CompactionStrategy, R as ResolvedCompactionConfig, v as CompactionContext, w as CompactionResult, x as CompactionConfig, y as CompactionEvent, z as CompactionStats, H as HintTemplate, E as ExecutionContext, D as GadgetExecuteReturn, F as GadgetExample, B as BaseGadget, P as ParsedGadgetCall, J as GadgetExecutionResult, K as ProviderAdapter, N as ModelDescriptor, O as ModelSpec, Q as LLMGenerationOptions, L as LLMStream, U as ImageModelSpec, V as ImageGenerationOptions, W as ImageGenerationResult, X as SpeechModelSpec, Y as SpeechGenerationOptions, Z as SpeechGenerationResult } from './mock-stream-ga4KIiwX.cjs';
4
- export { a6 as AfterGadgetExecutionAction, a7 as AfterGadgetExecutionControllerContext, a8 as AfterLLMCallAction, a9 as AfterLLMCallControllerContext, aa as AfterLLMErrorAction, a1 as AgentBuilder, ab as AgentOptions, az as AudioContentPart, aA as AudioMimeType, aB as AudioSource, ac as BeforeGadgetExecutionAction, ad as BeforeLLMCallAction, ae as ChunkInterceptorContext, aC as ContentPart, af as Controllers, b1 as CostEstimate, bl as CostReportingLLMist, aw as DEFAULT_COMPACTION_CONFIG, bb as DEFAULT_HINTS, bc as DEFAULT_PROMPTS, ax as DEFAULT_SUMMARIZATION_PROMPT, a2 as EventHandlers, bj as GadgetClass, bm as GadgetExecuteResult, ag as GadgetExecutionControllerContext, bk as GadgetOrClass, ah as GadgetParameterInterceptorContext, ai as GadgetResultInterceptorContext, bn as GadgetSkippedEvent, b7 as HintContext, _ as HistoryMessage, aD as ImageBase64Source, aE as ImageContentPart, aF as ImageMimeType, aG as ImageSource, aH as ImageUrlSource, aj as Interceptors, ak as LLMCallControllerContext, al as LLMErrorControllerContext, aZ as LLMMessageBuilder, aX as LLMRole, ay as LLMistOptions, am as MessageInterceptorContext, au as MessageTurn, d as MockBuilder, f as MockManager, l as MockMatcher, n as MockMatcherContext, o as MockOptions, M as MockProviderAdapter, p as MockRegistration, q as MockResponse, r as MockStats, b2 as ModelFeatures, b6 as ModelIdentifierParser, b3 as ModelLimits, b4 as ModelPricing, an as ObserveChunkContext, av as ObserveCompactionContext, ao as ObserveGadgetCompleteContext, ap as ObserveGadgetStartContext, aq as ObserveLLMCallContext, ar as ObserveLLMCompleteContext, as as ObserveLLMErrorContext, at as Observers, b8 as PromptConfig, b9 as PromptContext, ba as PromptTemplate, b5 as ProviderIdentifier, bg as QuickOptions, aI as TextContentPart, bo as TextOnlyAction, bp as TextOnlyContext, bq as TextOnlyCustomHandler, br as TextOnlyGadgetConfig, bs as TextOnlyHandler, bt as TextOnlyStrategy, $ as TrailingMessage, a0 as TrailingMessageContext, a$ as VisionAnalyzeOptions, b0 as VisionAnalyzeResult, aJ as audioFromBase64, aK as audioFromBuffer, a3 as collectEvents, a4 as collectText, bh as complete, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, aL as detectAudioMimeType, aM as detectImageMimeType, aY as extractText, g as getMockManager, aN as imageFromBase64, aO as imageFromBuffer, aP as imageFromUrl, aQ as isAudioPart, aR as isDataUrl, aS as isImagePart, aT as isTextPart, m as mockLLM, a_ as normalizeContent, aU as parseDataUrl, bd as resolveHintTemplate, be as resolvePromptTemplate, bf as resolveRulesTemplate, a5 as runWithHandlers, bi as stream, aV as text, aW as toBase64 } from './mock-stream-ga4KIiwX.cjs';
3
+ import { s as AgentHooks, t as ModelRegistry, u as LLMist, C as CompactionConfig, I as IConversationManager, v as CompactionEvent, L as LLMMessage, w as CompactionStats, x as CompactionStrategy, R as ResolvedCompactionConfig, y as CompactionContext, z as CompactionResult, B as MessageContent, G as GadgetMediaOutput, H as HintTemplate, S as StreamEvent, T as TokenUsage, D as GadgetRegistry, E as MediaStore, F as AgentContextConfig, J as SubagentConfigMap, b as LLMStreamChunk, K as ExecutionContext, N as GadgetExecuteReturn, O as GadgetExample, A as AbstractGadget, P as ParsedGadgetCall, Q as GadgetExecutionResult, U as MediaKind, V as MediaMetadata, W as GadgetExecuteResultWithMedia, X as ProviderAdapter, Y as ModelDescriptor, Z as ModelSpec, _ as LLMGenerationOptions, a as LLMStream, $ as ImageModelSpec, a0 as ImageGenerationOptions, a1 as ImageGenerationResult, a2 as SpeechModelSpec, a3 as SpeechGenerationOptions, a4 as SpeechGenerationResult } from './mock-stream-COHw8h9b.cjs';
4
+ export { ad as AfterGadgetExecutionAction, ae as AfterGadgetExecutionControllerContext, af as AfterLLMCallAction, ag as AfterLLMCallControllerContext, ah as AfterLLMErrorAction, a8 as AgentBuilder, ai as AgentOptions, aG as AudioContentPart, aH as AudioMimeType, aI as AudioSource, aj as BeforeGadgetExecutionAction, ak as BeforeLLMCallAction, al as ChunkInterceptorContext, aJ as ContentPart, am as Controllers, b6 as CostEstimate, bs as CostReportingLLMist, aD as DEFAULT_COMPACTION_CONFIG, bi as DEFAULT_HINTS, bj as DEFAULT_PROMPTS, aE as DEFAULT_SUMMARIZATION_PROMPT, a9 as EventHandlers, bq as GadgetClass, bt as GadgetExecuteResult, an as GadgetExecutionControllerContext, br as GadgetOrClass, ao as GadgetParameterInterceptorContext, ap as GadgetResultInterceptorContext, bu as GadgetSkippedEvent, be as HintContext, a5 as HistoryMessage, aK as ImageBase64Source, aL as ImageContentPart, aM as ImageMimeType, aN as ImageSource, aO as ImageUrlSource, aq as Interceptors, ar as LLMCallControllerContext, as as LLMErrorControllerContext, b4 as LLMMessageBuilder, aF as LLMistOptions, at as MessageInterceptorContext, b2 as MessageRole, au as MessageTurn, d as MockBuilder, f as MockManager, l as MockMatcher, n as MockMatcherContext, o as MockOptions, M as MockProviderAdapter, p as MockRegistration, q as MockResponse, r as MockStats, b7 as ModelFeatures, bd as ModelIdentifierParser, b8 as ModelLimits, b9 as ModelPricing, av as ObserveChunkContext, aw as ObserveCompactionContext, ax as ObserveGadgetCompleteContext, ay as ObserveGadgetStartContext, az as ObserveLLMCallContext, aA as ObserveLLMCompleteContext, aB as ObserveLLMErrorContext, aC as Observers, bf as PromptContext, bg as PromptTemplate, bh as PromptTemplateConfig, bc as ProviderIdentifier, bv as StoredMedia, aP as TextContentPart, bn as TextGenerationOptions, bw as TextOnlyAction, bx as TextOnlyContext, by as TextOnlyCustomHandler, bz as TextOnlyGadgetConfig, bA as TextOnlyHandler, bB as TextOnlyStrategy, a6 as TrailingMessage, a7 as TrailingMessageContext, ba as VisionAnalyzeOptions, bb as VisionAnalyzeResult, aQ as audioFromBase64, aR as audioFromBuffer, aa as collectEvents, ab as collectText, bo as complete, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, aS as detectAudioMimeType, aT as detectImageMimeType, b3 as extractMessageText, g as getMockManager, aU as imageFromBase64, aV as imageFromBuffer, aW as imageFromUrl, aX as isAudioPart, aY as isDataUrl, aZ as isImagePart, a_ as isTextPart, m as mockLLM, b5 as normalizeMessageContent, a$ as parseDataUrl, bk as resolveHintTemplate, bl as resolvePromptTemplate, bm as resolveRulesTemplate, ac as runWithHandlers, bp as stream, b0 as text, b1 as toBase64 } from './mock-stream-COHw8h9b.cjs';
5
5
  import { Logger, ILogObj } from 'tslog';
6
6
  import { MessageCreateParamsStreaming, MessageStreamEvent } from '@anthropic-ai/sdk/resources/messages';
7
7
  import OpenAI from 'openai';
@@ -713,289 +713,93 @@ declare class HookPresets {
713
713
  }
714
714
 
715
715
  /**
716
- * ConversationManager handles conversation state and message building.
717
- * Extracted from AgentLoop to follow Single Responsibility Principle.
718
- */
719
-
720
- /**
721
- * Options for ConversationManager constructor.
722
- */
723
- interface ConversationManagerOptions {
724
- /** Custom gadget start marker prefix */
725
- startPrefix?: string;
726
- /** Custom gadget end marker prefix */
727
- endPrefix?: string;
728
- /** Custom argument prefix for block format */
729
- argPrefix?: string;
730
- }
731
- /**
732
- * Default implementation of IConversationManager.
733
- * Manages conversation history by building on top of base messages (system prompt, gadget instructions).
734
- */
735
- declare class ConversationManager implements IConversationManager {
736
- private readonly baseMessages;
737
- private readonly initialMessages;
738
- private historyBuilder;
739
- private readonly startPrefix?;
740
- private readonly endPrefix?;
741
- private readonly argPrefix?;
742
- constructor(baseMessages: LLMMessage[], initialMessages: LLMMessage[], options?: ConversationManagerOptions);
743
- addUserMessage(content: MessageContent): void;
744
- addAssistantMessage(content: string): void;
745
- addGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): void;
746
- getMessages(): LLMMessage[];
747
- getHistoryMessages(): LLMMessage[];
748
- getBaseMessages(): LLMMessage[];
749
- replaceHistory(newHistory: LLMMessage[]): void;
750
- }
751
-
752
- /**
753
- * StreamProcessor: The heart of the new hooks architecture.
716
+ * CompactionManager - Central orchestrator for context compaction.
754
717
  *
755
- * Replaces the complex wiring between Agent, ResponseProcessor, and GadgetRuntime.
756
- * Owns ALL stream processing and hook coordination with a clean, predictable flow.
718
+ * Monitors token usage and coordinates compaction strategies to keep
719
+ * conversation context within model limits.
757
720
  */
758
721
 
759
722
  /**
760
- * Configuration for the StreamProcessor.
761
- */
762
- interface StreamProcessorOptions {
763
- /** Current iteration number */
764
- iteration: number;
765
- /** Gadget registry for execution */
766
- registry: GadgetRegistry;
767
- /** Custom gadget start prefix */
768
- gadgetStartPrefix?: string;
769
- /** Custom gadget end prefix */
770
- gadgetEndPrefix?: string;
771
- /** Custom argument prefix for block format */
772
- gadgetArgPrefix?: string;
773
- /** Hooks for lifecycle events */
774
- hooks?: AgentHooks;
775
- /** Logger instance */
776
- logger?: Logger<ILogObj>;
777
- /** Callback for human input */
778
- onHumanInputRequired?: (question: string) => Promise<string>;
779
- /** Whether to stop on gadget errors */
780
- stopOnGadgetError?: boolean;
781
- /** Custom error continuation logic */
782
- shouldContinueAfterError?: (context: {
783
- error: string;
784
- gadgetName: string;
785
- errorType: "parse" | "validation" | "execution";
786
- parameters?: Record<string, unknown>;
787
- }) => boolean | Promise<boolean>;
788
- /** Default gadget timeout */
789
- defaultGadgetTimeoutMs?: number;
790
- /** LLMist client for ExecutionContext.llmist */
791
- client?: LLMist;
792
- }
793
- /**
794
- * Result of stream processing.
723
+ * Pre-computed token counts to avoid redundant counting.
724
+ * Passed from checkAndCompact to compact for efficiency.
795
725
  */
796
- interface StreamProcessingResult {
797
- /** All emitted events */
798
- outputs: StreamEvent[];
799
- /** Whether the loop should break */
800
- shouldBreakLoop: boolean;
801
- /** Whether any gadgets were executed */
802
- didExecuteGadgets: boolean;
803
- /** LLM finish reason */
804
- finishReason: string | null;
805
- /** Token usage (including cached token counts when available) */
806
- usage?: TokenUsage;
807
- /** The raw accumulated response text */
808
- rawResponse: string;
809
- /** The final message (after interceptors) */
810
- finalMessage: string;
726
+ interface PrecomputedTokens {
727
+ historyMessages: LLMMessage[];
728
+ baseMessages: LLMMessage[];
729
+ historyTokens: number;
730
+ baseTokens: number;
731
+ currentTokens: number;
811
732
  }
812
733
  /**
813
- * StreamProcessor: Coordinates all stream processing and hook execution.
734
+ * CompactionManager orchestrates context compaction for an agent.
814
735
  *
815
- * Execution order:
816
- * 1. Raw chunk arrives from LLM
817
- * 2. Interceptor: interceptRawChunk (transform raw text)
818
- * 3. Observer: onStreamChunk (logging)
819
- * 4. Parse for gadgets
820
- * 5. If gadget found:
821
- * a. Interceptor: interceptGadgetParameters (transform params)
822
- * b. Controller: beforeGadgetExecution (can skip)
823
- * c. Observer: onGadgetExecutionStart
824
- * d. Execute gadget
825
- * e. Interceptor: interceptGadgetResult (transform result)
826
- * f. Controller: afterGadgetExecution (can provide fallback)
827
- * g. Observer: onGadgetExecutionComplete
828
- * 6. If text chunk:
829
- * a. Interceptor: interceptTextChunk (transform display text)
830
- * b. Yield to user
831
- * 7. Stream complete
832
- * 8. Interceptor: interceptAssistantMessage (transform final message)
736
+ * It:
737
+ * - Monitors token usage before each LLM call
738
+ * - Triggers compaction when threshold is exceeded
739
+ * - Coordinates with ConversationManager to update history
740
+ * - Tracks statistics for observability
833
741
  */
834
- declare class StreamProcessor {
835
- private readonly iteration;
836
- private readonly registry;
837
- private readonly hooks;
838
- private readonly logger;
839
- private readonly parser;
840
- private readonly executor;
841
- private readonly stopOnGadgetError;
842
- private readonly shouldContinueAfterError?;
843
- private accumulatedText;
844
- private shouldStopExecution;
845
- private observerFailureCount;
846
- /** Gadgets waiting for their dependencies to complete */
847
- private pendingGadgets;
848
- /** Completed gadget results, keyed by invocation ID */
849
- private completedResults;
850
- /** Invocation IDs of gadgets that have failed (error or skipped due to dependency) */
851
- private failedInvocations;
852
- constructor(options: StreamProcessorOptions);
853
- /**
854
- * Process an LLM stream and return structured results.
855
- */
856
- process(stream: AsyncIterable<LLMStreamChunk>): Promise<StreamProcessingResult>;
857
- /**
858
- * Process a single parsed event (text or gadget call).
859
- */
860
- private processEvent;
861
- /**
862
- * Process a text event through interceptors.
863
- */
864
- private processTextEvent;
742
+ declare class CompactionManager {
743
+ private readonly client;
744
+ private readonly model;
745
+ private readonly config;
746
+ private readonly strategy;
747
+ private modelLimits?;
748
+ private totalCompactions;
749
+ private totalTokensSaved;
750
+ private lastTokenCount;
751
+ constructor(client: LLMist, model: string, config?: CompactionConfig);
865
752
  /**
866
- * Process a gadget call through the full lifecycle, handling dependencies.
753
+ * Check if compaction is needed and perform it if so.
867
754
  *
868
- * Gadgets without dependencies (or with all dependencies satisfied) execute immediately.
869
- * Gadgets with unsatisfied dependencies are queued for later execution.
870
- * After each execution, pending gadgets are checked to see if they can now run.
871
- */
872
- private processGadgetCall;
873
- /**
874
- * Execute a gadget through the full hook lifecycle.
875
- * This is the core execution logic, extracted from processGadgetCall.
876
- */
877
- private executeGadgetWithHooks;
878
- /**
879
- * Handle a gadget that cannot execute because a dependency failed.
880
- * Calls the onDependencySkipped controller to allow customization.
881
- */
882
- private handleFailedDependency;
883
- /**
884
- * Process pending gadgets whose dependencies are now satisfied.
885
- * Executes ready gadgets in parallel and continues until no more can be triggered.
886
- */
887
- private processPendingGadgets;
888
- /**
889
- * Safely execute an observer, catching and logging any errors.
890
- * Observers are non-critical, so errors are logged but don't crash the system.
755
+ * @param conversation - The conversation manager to compact
756
+ * @param iteration - Current agent iteration (for event metadata)
757
+ * @returns CompactionEvent if compaction was performed, null otherwise
891
758
  */
892
- private safeObserve;
759
+ checkAndCompact(conversation: IConversationManager, iteration: number): Promise<CompactionEvent | null>;
893
760
  /**
894
- * Execute multiple observers in parallel.
895
- * All observers run concurrently and failures are tracked but don't crash.
761
+ * Force compaction regardless of threshold.
762
+ *
763
+ * @param conversation - The conversation manager to compact
764
+ * @param iteration - Current agent iteration (for event metadata). Use -1 for manual compaction.
765
+ * @param precomputed - Optional pre-computed token counts (passed from checkAndCompact for efficiency)
766
+ * @returns CompactionEvent with compaction details
896
767
  */
897
- private runObserversInParallel;
768
+ compact(conversation: IConversationManager, iteration: number, precomputed?: PrecomputedTokens): Promise<CompactionEvent | null>;
898
769
  /**
899
- * Check if execution should continue after an error.
900
- *
901
- * Returns true if we should continue processing subsequent gadgets, false if we should stop.
902
- *
903
- * Logic:
904
- * - If custom shouldContinueAfterError is provided, use it
905
- * - Otherwise, use stopOnGadgetError config:
906
- * - stopOnGadgetError=true → return false (stop execution)
907
- * - stopOnGadgetError=false → return true (continue execution)
770
+ * Get compaction statistics.
908
771
  */
909
- private checkContinueAfterError;
772
+ getStats(): CompactionStats;
910
773
  /**
911
- * Determine the type of error from a gadget execution.
774
+ * Check if compaction is enabled.
912
775
  */
913
- private determineErrorType;
776
+ isEnabled(): boolean;
914
777
  }
915
778
 
916
779
  /**
917
- * Storage for large gadget outputs that exceed the configured limit.
780
+ * Hybrid Compaction Strategy
918
781
  *
919
- * When a gadget returns more data than the configured limit, the output
920
- * is stored here and can be browsed later using GadgetOutputViewer.
921
- */
922
- /**
923
- * Metadata and content for a stored gadget output.
782
+ * Combines sliding window and summarization for the best of both worlds:
783
+ * 1. Identifies which turns to compact vs keep (like sliding window)
784
+ * 2. Summarizes the older turns (like summarization)
785
+ * 3. Returns summary + recent turns intact
786
+ *
787
+ * Falls back to sliding window if there are too few turns to summarize.
924
788
  */
925
- interface StoredOutput {
926
- /** Unique identifier (e.g., "Search_d34db33f") */
927
- id: string;
928
- /** Name of the gadget that produced this output */
929
- gadgetName: string;
930
- /** Full output content */
931
- content: string;
932
- /** Size in bytes */
933
- byteSize: number;
934
- /** Number of lines */
935
- lineCount: number;
936
- /** When the output was stored */
937
- timestamp: Date;
938
- }
789
+
939
790
  /**
940
- * In-memory store for large gadget outputs.
941
- *
942
- * Outputs are stored with generated IDs in the format `{GadgetName}_{hex8}`.
943
- * The store is tied to an agent run and cleared when the agent completes.
944
- *
945
- * @example
946
- * ```typescript
947
- * const store = new GadgetOutputStore();
948
- * const id = store.store("Search", largeOutput);
949
- * // id = "Search_a1b2c3d4"
791
+ * Hybrid strategy - summarizes old turns + keeps recent turns.
950
792
  *
951
- * const stored = store.get(id);
952
- * console.log(stored?.lineCount); // 4200
953
- * ```
793
+ * This is the recommended default strategy as it:
794
+ * - Preserves important historical context via summarization
795
+ * - Keeps recent conversation turns verbatim for continuity
796
+ * - Falls back gracefully to sliding window when appropriate
954
797
  */
955
- declare class GadgetOutputStore {
956
- private outputs;
957
- /**
958
- * Store a gadget output and return its ID.
959
- *
960
- * @param gadgetName - Name of the gadget that produced the output
961
- * @param content - Full output content to store
962
- * @returns Generated ID for retrieving the output later
963
- */
964
- store(gadgetName: string, content: string): string;
965
- /**
966
- * Retrieve a stored output by ID.
967
- *
968
- * @param id - The output ID (e.g., "Search_d34db33f")
969
- * @returns The stored output or undefined if not found
970
- */
971
- get(id: string): StoredOutput | undefined;
972
- /**
973
- * Check if an output exists.
974
- *
975
- * @param id - The output ID to check
976
- * @returns True if the output exists
977
- */
978
- has(id: string): boolean;
979
- /**
980
- * Get all stored output IDs.
981
- *
982
- * @returns Array of output IDs
983
- */
984
- getIds(): string[];
985
- /**
986
- * Get the number of stored outputs.
987
- */
988
- get size(): number;
989
- /**
990
- * Clear all stored outputs.
991
- * Called when the agent run completes.
992
- */
993
- clear(): void;
994
- /**
995
- * Generate a unique ID for a stored output.
996
- * Format: {GadgetName}_{8 hex chars}
997
- */
998
- private generateId;
798
+ declare class HybridStrategy implements CompactionStrategy {
799
+ readonly name = "hybrid";
800
+ private readonly slidingWindow;
801
+ private readonly summarization;
802
+ compact(messages: LLMMessage[], config: ResolvedCompactionConfig, context: CompactionContext): Promise<CompactionResult>;
999
803
  }
1000
804
 
1001
805
  /**
@@ -1055,93 +859,125 @@ declare class SummarizationStrategy implements CompactionStrategy {
1055
859
  }
1056
860
 
1057
861
  /**
1058
- * Hybrid Compaction Strategy
1059
- *
1060
- * Combines sliding window and summarization for the best of both worlds:
1061
- * 1. Identifies which turns to compact vs keep (like sliding window)
1062
- * 2. Summarizes the older turns (like summarization)
1063
- * 3. Returns summary + recent turns intact
1064
- *
1065
- * Falls back to sliding window if there are too few turns to summarize.
862
+ * ConversationManager handles conversation state and message building.
863
+ * Extracted from AgentLoop to follow Single Responsibility Principle.
1066
864
  */
1067
865
 
1068
866
  /**
1069
- * Hybrid strategy - summarizes old turns + keeps recent turns.
1070
- *
1071
- * This is the recommended default strategy as it:
1072
- * - Preserves important historical context via summarization
1073
- * - Keeps recent conversation turns verbatim for continuity
1074
- * - Falls back gracefully to sliding window when appropriate
867
+ * Options for ConversationManager constructor.
1075
868
  */
1076
- declare class HybridStrategy implements CompactionStrategy {
1077
- readonly name = "hybrid";
1078
- private readonly slidingWindow;
1079
- private readonly summarization;
1080
- compact(messages: LLMMessage[], config: ResolvedCompactionConfig, context: CompactionContext): Promise<CompactionResult>;
869
+ interface ConversationManagerOptions {
870
+ /** Custom gadget start marker prefix */
871
+ startPrefix?: string;
872
+ /** Custom gadget end marker prefix */
873
+ endPrefix?: string;
874
+ /** Custom argument prefix for block format */
875
+ argPrefix?: string;
876
+ }
877
+ /**
878
+ * Default implementation of IConversationManager.
879
+ * Manages conversation history by building on top of base messages (system prompt, gadget instructions).
880
+ */
881
+ declare class ConversationManager implements IConversationManager {
882
+ private readonly baseMessages;
883
+ private readonly initialMessages;
884
+ private historyBuilder;
885
+ private readonly startPrefix?;
886
+ private readonly endPrefix?;
887
+ private readonly argPrefix?;
888
+ constructor(baseMessages: LLMMessage[], initialMessages: LLMMessage[], options?: ConversationManagerOptions);
889
+ addUserMessage(content: MessageContent): void;
890
+ addAssistantMessage(content: string): void;
891
+ addGadgetCallResult(gadgetName: string, parameters: Record<string, unknown>, result: string, media?: GadgetMediaOutput[], mediaIds?: string[]): void;
892
+ getMessages(): LLMMessage[];
893
+ getHistoryMessages(): LLMMessage[];
894
+ getBaseMessages(): LLMMessage[];
895
+ replaceHistory(newHistory: LLMMessage[]): void;
1081
896
  }
1082
897
 
1083
898
  /**
1084
- * CompactionManager - Central orchestrator for context compaction.
899
+ * Storage for large gadget outputs that exceed the configured limit.
1085
900
  *
1086
- * Monitors token usage and coordinates compaction strategies to keep
1087
- * conversation context within model limits.
901
+ * When a gadget returns more data than the configured limit, the output
902
+ * is stored here and can be browsed later using GadgetOutputViewer.
1088
903
  */
1089
-
1090
904
  /**
1091
- * Pre-computed token counts to avoid redundant counting.
1092
- * Passed from checkAndCompact to compact for efficiency.
905
+ * Metadata and content for a stored gadget output.
1093
906
  */
1094
- interface PrecomputedTokens {
1095
- historyMessages: LLMMessage[];
1096
- baseMessages: LLMMessage[];
1097
- historyTokens: number;
1098
- baseTokens: number;
1099
- currentTokens: number;
907
+ interface StoredOutput {
908
+ /** Unique identifier (e.g., "Search_d34db33f") */
909
+ id: string;
910
+ /** Name of the gadget that produced this output */
911
+ gadgetName: string;
912
+ /** Full output content */
913
+ content: string;
914
+ /** Size in bytes */
915
+ byteSize: number;
916
+ /** Number of lines */
917
+ lineCount: number;
918
+ /** When the output was stored */
919
+ timestamp: Date;
1100
920
  }
1101
921
  /**
1102
- * CompactionManager orchestrates context compaction for an agent.
922
+ * In-memory store for large gadget outputs.
1103
923
  *
1104
- * It:
1105
- * - Monitors token usage before each LLM call
1106
- * - Triggers compaction when threshold is exceeded
1107
- * - Coordinates with ConversationManager to update history
1108
- * - Tracks statistics for observability
924
+ * Outputs are stored with generated IDs in the format `{GadgetName}_{hex8}`.
925
+ * The store is tied to an agent run and cleared when the agent completes.
926
+ *
927
+ * @example
928
+ * ```typescript
929
+ * const store = new GadgetOutputStore();
930
+ * const id = store.store("Search", largeOutput);
931
+ * // id = "Search_a1b2c3d4"
932
+ *
933
+ * const stored = store.get(id);
934
+ * console.log(stored?.lineCount); // 4200
935
+ * ```
1109
936
  */
1110
- declare class CompactionManager {
1111
- private readonly client;
1112
- private readonly model;
1113
- private readonly config;
1114
- private readonly strategy;
1115
- private modelLimits?;
1116
- private totalCompactions;
1117
- private totalTokensSaved;
1118
- private lastTokenCount;
1119
- constructor(client: LLMist, model: string, config?: CompactionConfig);
937
+ declare class GadgetOutputStore {
938
+ private outputs;
939
+ /**
940
+ * Store a gadget output and return its ID.
941
+ *
942
+ * @param gadgetName - Name of the gadget that produced the output
943
+ * @param content - Full output content to store
944
+ * @returns Generated ID for retrieving the output later
945
+ */
946
+ store(gadgetName: string, content: string): string;
947
+ /**
948
+ * Retrieve a stored output by ID.
949
+ *
950
+ * @param id - The output ID (e.g., "Search_d34db33f")
951
+ * @returns The stored output or undefined if not found
952
+ */
953
+ get(id: string): StoredOutput | undefined;
954
+ /**
955
+ * Check if an output exists.
956
+ *
957
+ * @param id - The output ID to check
958
+ * @returns True if the output exists
959
+ */
960
+ has(id: string): boolean;
1120
961
  /**
1121
- * Check if compaction is needed and perform it if so.
962
+ * Get all stored output IDs.
1122
963
  *
1123
- * @param conversation - The conversation manager to compact
1124
- * @param iteration - Current agent iteration (for event metadata)
1125
- * @returns CompactionEvent if compaction was performed, null otherwise
964
+ * @returns Array of output IDs
1126
965
  */
1127
- checkAndCompact(conversation: IConversationManager, iteration: number): Promise<CompactionEvent | null>;
966
+ getIds(): string[];
1128
967
  /**
1129
- * Force compaction regardless of threshold.
1130
- *
1131
- * @param conversation - The conversation manager to compact
1132
- * @param iteration - Current agent iteration (for event metadata). Use -1 for manual compaction.
1133
- * @param precomputed - Optional pre-computed token counts (passed from checkAndCompact for efficiency)
1134
- * @returns CompactionEvent with compaction details
968
+ * Get the number of stored outputs.
1135
969
  */
1136
- compact(conversation: IConversationManager, iteration: number, precomputed?: PrecomputedTokens): Promise<CompactionEvent | null>;
970
+ get size(): number;
1137
971
  /**
1138
- * Get compaction statistics.
972
+ * Clear all stored outputs.
973
+ * Called when the agent run completes.
1139
974
  */
1140
- getStats(): CompactionStats;
975
+ clear(): void;
1141
976
  /**
1142
- * Check if compaction is enabled.
977
+ * Generate a unique ID for a stored output.
978
+ * Format: {GadgetName}_{8 hex chars}
1143
979
  */
1144
- isEnabled(): boolean;
980
+ private generateId;
1145
981
  }
1146
982
 
1147
983
  /**
@@ -1194,128 +1030,298 @@ interface IterationHintOptions {
1194
1030
  * - "urgent": Show only when >= 80% through iterations
1195
1031
  * @default "always"
1196
1032
  */
1197
- timing?: "always" | "late" | "urgent";
1033
+ timing?: "always" | "late" | "urgent";
1034
+ /**
1035
+ * Whether to include urgency indicators for late iterations.
1036
+ * Adds extra text when running low on iterations.
1037
+ * @default true
1038
+ */
1039
+ showUrgency?: boolean;
1040
+ /**
1041
+ * Custom template. Supports placeholders: {iteration}, {maxIterations}, {remaining}
1042
+ * Or a function receiving HintContext.
1043
+ * @default DEFAULT_HINTS.iterationProgressHint
1044
+ */
1045
+ template?: HintTemplate;
1046
+ }
1047
+ /**
1048
+ * Options for parallel gadget usage hint.
1049
+ */
1050
+ interface ParallelGadgetHintOptions {
1051
+ /**
1052
+ * Minimum number of gadget calls to consider "efficient".
1053
+ * If response has fewer calls, hint will suggest parallelization.
1054
+ * @default 2
1055
+ */
1056
+ minGadgetsForEfficiency?: number;
1057
+ /**
1058
+ * Custom message when single gadget detected.
1059
+ * @default DEFAULT_HINTS.parallelGadgetsHint
1060
+ */
1061
+ message?: string;
1062
+ /**
1063
+ * Whether to enable this hint.
1064
+ * @default true
1065
+ */
1066
+ enabled?: boolean;
1067
+ }
1068
+ /**
1069
+ * Combined hints configuration for createHints().
1070
+ */
1071
+ interface HintsConfig {
1072
+ /**
1073
+ * Enable iteration progress hints.
1074
+ * Pass `true` for defaults, or options object for customization.
1075
+ */
1076
+ iterationProgress?: boolean | IterationHintOptions;
1077
+ /**
1078
+ * Enable parallel gadget hints.
1079
+ * Pass `true` for defaults, or options object for customization.
1080
+ */
1081
+ parallelGadgets?: boolean | ParallelGadgetHintOptions;
1082
+ /**
1083
+ * Additional custom hooks to merge.
1084
+ */
1085
+ custom?: AgentHooks[];
1086
+ }
1087
+ /**
1088
+ * Creates a proactive hint that informs the LLM about iteration progress.
1089
+ *
1090
+ * This hint is injected before each LLM call (via beforeLLMCall controller),
1091
+ * helping the LLM understand how much "budget" remains for completing the task.
1092
+ *
1093
+ * @param options - Configuration options
1094
+ * @returns AgentHooks that can be merged with other hooks
1095
+ *
1096
+ * @example
1097
+ * ```typescript
1098
+ * // Basic usage - show on every iteration
1099
+ * const hooks = iterationProgressHint();
1100
+ *
1101
+ * // Show only when running low on iterations
1102
+ * const hooks = iterationProgressHint({ timing: "late" });
1103
+ *
1104
+ * // Custom template
1105
+ * const hooks = iterationProgressHint({
1106
+ * template: "Turn {iteration} of {maxIterations}. {remaining} turns left.",
1107
+ * });
1108
+ * ```
1109
+ */
1110
+ declare function iterationProgressHint(options?: IterationHintOptions): AgentHooks;
1111
+ /**
1112
+ * Creates a reactive hint that encourages parallel gadget usage.
1113
+ *
1114
+ * This hint analyzes the LLM's response and, if only a single gadget was called,
1115
+ * appends a reminder that multiple gadgets can be used in parallel for efficiency.
1116
+ *
1117
+ * @param options - Configuration options
1118
+ * @returns AgentHooks that can be merged with other hooks
1119
+ *
1120
+ * @example
1121
+ * ```typescript
1122
+ * // Basic usage
1123
+ * const hooks = parallelGadgetHint();
1124
+ *
1125
+ * // Custom threshold and message
1126
+ * const hooks = parallelGadgetHint({
1127
+ * minGadgetsForEfficiency: 3,
1128
+ * message: "Consider calling multiple gadgets at once!",
1129
+ * });
1130
+ * ```
1131
+ */
1132
+ declare function parallelGadgetHint(options?: ParallelGadgetHintOptions): AgentHooks;
1133
+ /**
1134
+ * Creates combined hints from a configuration object.
1135
+ *
1136
+ * This is a convenience function that creates and merges multiple hints
1137
+ * based on a simple configuration object.
1138
+ *
1139
+ * @param config - Configuration for which hints to enable
1140
+ * @returns Merged AgentHooks
1141
+ *
1142
+ * @example
1143
+ * ```typescript
1144
+ * const hooks = createHints({
1145
+ * iterationProgress: { timing: "late" },
1146
+ * parallelGadgets: true,
1147
+ * });
1148
+ *
1149
+ * const agent = new AgentBuilder()
1150
+ * .withHooks(HookPresets.merge(existingHooks, hooks))
1151
+ * .build();
1152
+ * ```
1153
+ */
1154
+ declare function createHints(config: HintsConfig): AgentHooks;
1155
+
1156
+ /**
1157
+ * StreamProcessor: The heart of the new hooks architecture.
1158
+ *
1159
+ * Replaces the complex wiring between Agent, ResponseProcessor, and GadgetRuntime.
1160
+ * Owns ALL stream processing and hook coordination with a clean, predictable flow.
1161
+ */
1162
+
1163
+ /**
1164
+ * Configuration for the StreamProcessor.
1165
+ */
1166
+ interface StreamProcessorOptions {
1167
+ /** Current iteration number */
1168
+ iteration: number;
1169
+ /** Gadget registry for execution */
1170
+ registry: GadgetRegistry;
1171
+ /** Custom gadget start prefix */
1172
+ gadgetStartPrefix?: string;
1173
+ /** Custom gadget end prefix */
1174
+ gadgetEndPrefix?: string;
1175
+ /** Custom argument prefix for block format */
1176
+ gadgetArgPrefix?: string;
1177
+ /** Hooks for lifecycle events */
1178
+ hooks?: AgentHooks;
1179
+ /** Logger instance */
1180
+ logger?: Logger<ILogObj>;
1181
+ /** Callback for requesting human input during execution */
1182
+ requestHumanInput?: (question: string) => Promise<string>;
1183
+ /** Whether to stop on gadget errors */
1184
+ stopOnGadgetError?: boolean;
1185
+ /** Custom error recovery logic */
1186
+ canRecoverFromGadgetError?: (context: {
1187
+ error: string;
1188
+ gadgetName: string;
1189
+ errorType: "parse" | "validation" | "execution";
1190
+ parameters?: Record<string, unknown>;
1191
+ }) => boolean | Promise<boolean>;
1192
+ /** Default gadget timeout */
1193
+ defaultGadgetTimeoutMs?: number;
1194
+ /** LLMist client for ExecutionContext.llmist */
1195
+ client?: LLMist;
1196
+ /** MediaStore for storing gadget media outputs */
1197
+ mediaStore?: MediaStore;
1198
+ /** Parent agent configuration for subagents to inherit */
1199
+ agentConfig?: AgentContextConfig;
1200
+ /** Subagent-specific configuration overrides */
1201
+ subagentConfig?: SubagentConfigMap;
1202
+ }
1203
+ /**
1204
+ * Result of stream processing.
1205
+ */
1206
+ interface StreamProcessingResult {
1207
+ /** All emitted events */
1208
+ outputs: StreamEvent[];
1209
+ /** Whether the loop should break */
1210
+ shouldBreakLoop: boolean;
1211
+ /** Whether any gadgets were executed */
1212
+ didExecuteGadgets: boolean;
1213
+ /** LLM finish reason */
1214
+ finishReason: string | null;
1215
+ /** Token usage (including cached token counts when available) */
1216
+ usage?: TokenUsage;
1217
+ /** The raw accumulated response text */
1218
+ rawResponse: string;
1219
+ /** The final message (after interceptors) */
1220
+ finalMessage: string;
1221
+ }
1222
+ /**
1223
+ * StreamProcessor: Coordinates all stream processing and hook execution.
1224
+ *
1225
+ * Execution order:
1226
+ * 1. Raw chunk arrives from LLM
1227
+ * 2. Interceptor: interceptRawChunk (transform raw text)
1228
+ * 3. Observer: onStreamChunk (logging)
1229
+ * 4. Parse for gadgets
1230
+ * 5. If gadget found:
1231
+ * a. Interceptor: interceptGadgetParameters (transform params)
1232
+ * b. Controller: beforeGadgetExecution (can skip)
1233
+ * c. Observer: onGadgetExecutionStart
1234
+ * d. Execute gadget
1235
+ * e. Interceptor: interceptGadgetResult (transform result)
1236
+ * f. Controller: afterGadgetExecution (can provide fallback)
1237
+ * g. Observer: onGadgetExecutionComplete
1238
+ * 6. If text chunk:
1239
+ * a. Interceptor: interceptTextChunk (transform display text)
1240
+ * b. Yield to user
1241
+ * 7. Stream complete
1242
+ * 8. Interceptor: interceptAssistantMessage (transform final message)
1243
+ */
1244
+ declare class StreamProcessor {
1245
+ private readonly iteration;
1246
+ private readonly registry;
1247
+ private readonly hooks;
1248
+ private readonly logger;
1249
+ private readonly parser;
1250
+ private readonly executor;
1251
+ private readonly stopOnGadgetError;
1252
+ private readonly canRecoverFromGadgetError?;
1253
+ private responseText;
1254
+ private executionHalted;
1255
+ private observerFailureCount;
1256
+ /** Gadgets waiting for their dependencies to complete */
1257
+ private gadgetsAwaitingDependencies;
1258
+ /** Completed gadget results, keyed by invocation ID */
1259
+ private completedResults;
1260
+ /** Invocation IDs of gadgets that have failed (error or skipped due to dependency) */
1261
+ private failedInvocations;
1262
+ constructor(options: StreamProcessorOptions);
1263
+ /**
1264
+ * Process an LLM stream and return structured results.
1265
+ */
1266
+ process(stream: AsyncIterable<LLMStreamChunk>): Promise<StreamProcessingResult>;
1267
+ /**
1268
+ * Process a single parsed event (text or gadget call).
1269
+ */
1270
+ private processEvent;
1271
+ /**
1272
+ * Process a text event through interceptors.
1273
+ */
1274
+ private processTextEvent;
1198
1275
  /**
1199
- * Whether to include urgency indicators for late iterations.
1200
- * Adds extra text when running low on iterations.
1201
- * @default true
1276
+ * Process a gadget call through the full lifecycle, handling dependencies.
1277
+ *
1278
+ * Gadgets without dependencies (or with all dependencies satisfied) execute immediately.
1279
+ * Gadgets with unsatisfied dependencies are queued for later execution.
1280
+ * After each execution, pending gadgets are checked to see if they can now run.
1202
1281
  */
1203
- showUrgency?: boolean;
1282
+ private processGadgetCall;
1204
1283
  /**
1205
- * Custom template. Supports placeholders: {iteration}, {maxIterations}, {remaining}
1206
- * Or a function receiving HintContext.
1207
- * @default DEFAULT_HINTS.iterationProgressHint
1284
+ * Execute a gadget through the full hook lifecycle.
1285
+ * This is the core execution logic, extracted from processGadgetCall.
1208
1286
  */
1209
- template?: HintTemplate;
1210
- }
1211
- /**
1212
- * Options for parallel gadget usage hint.
1213
- */
1214
- interface ParallelGadgetHintOptions {
1287
+ private executeGadgetWithHooks;
1215
1288
  /**
1216
- * Minimum number of gadget calls to consider "efficient".
1217
- * If response has fewer calls, hint will suggest parallelization.
1218
- * @default 2
1289
+ * Handle a gadget that cannot execute because a dependency failed.
1290
+ * Calls the onDependencySkipped controller to allow customization.
1219
1291
  */
1220
- minGadgetsForEfficiency?: number;
1292
+ private handleFailedDependency;
1221
1293
  /**
1222
- * Custom message when single gadget detected.
1223
- * @default DEFAULT_HINTS.parallelGadgetsHint
1294
+ * Process pending gadgets whose dependencies are now satisfied.
1295
+ * Executes ready gadgets in parallel and continues until no more can be triggered.
1224
1296
  */
1225
- message?: string;
1297
+ private processPendingGadgets;
1226
1298
  /**
1227
- * Whether to enable this hint.
1228
- * @default true
1299
+ * Safely execute an observer, catching and logging any errors.
1300
+ * Observers are non-critical, so errors are logged but don't crash the system.
1229
1301
  */
1230
- enabled?: boolean;
1231
- }
1232
- /**
1233
- * Combined hints configuration for createHints().
1234
- */
1235
- interface HintsConfig {
1302
+ private safeObserve;
1236
1303
  /**
1237
- * Enable iteration progress hints.
1238
- * Pass `true` for defaults, or options object for customization.
1304
+ * Execute multiple observers in parallel.
1305
+ * All observers run concurrently and failures are tracked but don't crash.
1239
1306
  */
1240
- iterationProgress?: boolean | IterationHintOptions;
1307
+ private runObserversInParallel;
1241
1308
  /**
1242
- * Enable parallel gadget hints.
1243
- * Pass `true` for defaults, or options object for customization.
1309
+ * Check if execution can recover from an error.
1310
+ *
1311
+ * Returns true if we should continue processing subsequent gadgets, false if we should stop.
1312
+ *
1313
+ * Logic:
1314
+ * - If custom canRecoverFromGadgetError is provided, use it
1315
+ * - Otherwise, use stopOnGadgetError config:
1316
+ * - stopOnGadgetError=true → return false (stop execution)
1317
+ * - stopOnGadgetError=false → return true (continue execution)
1244
1318
  */
1245
- parallelGadgets?: boolean | ParallelGadgetHintOptions;
1319
+ private checkCanRecoverFromError;
1246
1320
  /**
1247
- * Additional custom hooks to merge.
1321
+ * Determine the type of error from a gadget execution.
1248
1322
  */
1249
- custom?: AgentHooks[];
1323
+ private determineErrorType;
1250
1324
  }
1251
- /**
1252
- * Creates a proactive hint that informs the LLM about iteration progress.
1253
- *
1254
- * This hint is injected before each LLM call (via beforeLLMCall controller),
1255
- * helping the LLM understand how much "budget" remains for completing the task.
1256
- *
1257
- * @param options - Configuration options
1258
- * @returns AgentHooks that can be merged with other hooks
1259
- *
1260
- * @example
1261
- * ```typescript
1262
- * // Basic usage - show on every iteration
1263
- * const hooks = iterationProgressHint();
1264
- *
1265
- * // Show only when running low on iterations
1266
- * const hooks = iterationProgressHint({ timing: "late" });
1267
- *
1268
- * // Custom template
1269
- * const hooks = iterationProgressHint({
1270
- * template: "Turn {iteration} of {maxIterations}. {remaining} turns left.",
1271
- * });
1272
- * ```
1273
- */
1274
- declare function iterationProgressHint(options?: IterationHintOptions): AgentHooks;
1275
- /**
1276
- * Creates a reactive hint that encourages parallel gadget usage.
1277
- *
1278
- * This hint analyzes the LLM's response and, if only a single gadget was called,
1279
- * appends a reminder that multiple gadgets can be used in parallel for efficiency.
1280
- *
1281
- * @param options - Configuration options
1282
- * @returns AgentHooks that can be merged with other hooks
1283
- *
1284
- * @example
1285
- * ```typescript
1286
- * // Basic usage
1287
- * const hooks = parallelGadgetHint();
1288
- *
1289
- * // Custom threshold and message
1290
- * const hooks = parallelGadgetHint({
1291
- * minGadgetsForEfficiency: 3,
1292
- * message: "Consider calling multiple gadgets at once!",
1293
- * });
1294
- * ```
1295
- */
1296
- declare function parallelGadgetHint(options?: ParallelGadgetHintOptions): AgentHooks;
1297
- /**
1298
- * Creates combined hints from a configuration object.
1299
- *
1300
- * This is a convenience function that creates and merges multiple hints
1301
- * based on a simple configuration object.
1302
- *
1303
- * @param config - Configuration for which hints to enable
1304
- * @returns Merged AgentHooks
1305
- *
1306
- * @example
1307
- * ```typescript
1308
- * const hooks = createHints({
1309
- * iterationProgress: { timing: "late" },
1310
- * parallelGadgets: true,
1311
- * });
1312
- *
1313
- * const agent = new AgentBuilder()
1314
- * .withHooks(HookPresets.merge(existingHooks, hooks))
1315
- * .build();
1316
- * ```
1317
- */
1318
- declare function createHints(config: HintsConfig): AgentHooks;
1319
1325
 
1320
1326
  /**
1321
1327
  * Model shortcuts and aliases for more expressive DX.
@@ -1539,33 +1545,14 @@ interface CreateGadgetConfig<TSchema extends ZodType> {
1539
1545
  * .ask("What's the weather in Paris and what's 10 + 5?");
1540
1546
  * ```
1541
1547
  */
1542
- declare function createGadget<TSchema extends ZodType>(config: CreateGadgetConfig<TSchema>): BaseGadget;
1543
-
1544
- /**
1545
- * Create a GadgetOutputViewer gadget instance bound to a specific output store.
1546
- *
1547
- * This is a factory function because the gadget needs access to the output store,
1548
- * which is created per-agent-run.
1549
- *
1550
- * @param store - The GadgetOutputStore to read outputs from
1551
- * @param maxOutputChars - Maximum characters to return (default: 76,800 = ~19k tokens)
1552
- * @returns A GadgetOutputViewer gadget instance
1553
- *
1554
- * @example
1555
- * ```typescript
1556
- * const store = new GadgetOutputStore();
1557
- * const viewer = createGadgetOutputViewer(store, 76_800);
1558
- * registry.register("GadgetOutputViewer", viewer);
1559
- * ```
1560
- */
1561
- declare function createGadgetOutputViewer(store: GadgetOutputStore, maxOutputChars?: number): BaseGadget;
1548
+ declare function createGadget<TSchema extends ZodType>(config: CreateGadgetConfig<TSchema>): AbstractGadget;
1562
1549
 
1563
1550
  /**
1564
- * Exception that gadgets can throw to signal the agent loop should terminate.
1551
+ * Signal that a gadget throws to indicate task completion and agent termination.
1565
1552
  *
1566
- * When a gadget throws this exception, the agent loop will:
1553
+ * When a gadget throws this signal, the agent loop will:
1567
1554
  * 1. Complete the current iteration
1568
- * 2. Return the exception message as the gadget's result
1555
+ * 2. Return the signal message as the gadget's result
1569
1556
  * 3. Exit the loop instead of continuing to the next iteration
1570
1557
  *
1571
1558
  * @example
@@ -1581,12 +1568,12 @@ declare function createGadgetOutputViewer(store: GadgetOutputStore, maxOutputCha
1581
1568
  * }) {
1582
1569
  * execute(params: this['params']): string {
1583
1570
  * const message = params.message || 'Task completed';
1584
- * throw new BreakLoopException(message);
1571
+ * throw new TaskCompletionSignal(message);
1585
1572
  * }
1586
1573
  * }
1587
1574
  * ```
1588
1575
  */
1589
- declare class BreakLoopException extends Error {
1576
+ declare class TaskCompletionSignal extends Error {
1590
1577
  constructor(message?: string);
1591
1578
  }
1592
1579
  /**
@@ -1594,7 +1581,7 @@ declare class BreakLoopException extends Error {
1594
1581
  *
1595
1582
  * When a gadget throws this exception, the agent loop will:
1596
1583
  * 1. Pause execution and wait for human input
1597
- * 2. If `onHumanInputRequired` callback is provided, call it and await the answer
1584
+ * 2. If `requestHumanInput` callback is provided, call it and await the answer
1598
1585
  * 3. Return the user's answer as the gadget's result
1599
1586
  * 4. Continue the loop with the answer added to conversation history
1600
1587
  *
@@ -1613,15 +1600,49 @@ declare class BreakLoopException extends Error {
1613
1600
  * }),
1614
1601
  * }) {
1615
1602
  * execute(params: this['params']): string {
1616
- * throw new HumanInputException(params.question);
1603
+ * throw new HumanInputRequiredException(params.question);
1617
1604
  * }
1618
1605
  * }
1619
1606
  * ```
1620
1607
  */
1621
- declare class HumanInputException extends Error {
1608
+ declare class HumanInputRequiredException extends Error {
1622
1609
  readonly question: string;
1623
1610
  constructor(question: string);
1624
1611
  }
1612
+ /**
1613
+ * Exception thrown when a gadget execution exceeds its timeout limit.
1614
+ *
1615
+ * When a gadget's execution time exceeds either:
1616
+ * - The gadget's own `timeoutMs` property, or
1617
+ * - The global `defaultGadgetTimeoutMs` configured in runtime/agent loop options
1618
+ *
1619
+ * The executor will automatically throw this exception and return it as an error.
1620
+ *
1621
+ * @example
1622
+ * ```typescript
1623
+ * import { z } from 'zod';
1624
+ *
1625
+ * class SlowApiGadget extends Gadget({
1626
+ * name: 'SlowApi',
1627
+ * description: 'Calls a slow external API',
1628
+ * timeoutMs: 5000, // 5 second timeout
1629
+ * schema: z.object({
1630
+ * endpoint: z.string(),
1631
+ * }),
1632
+ * }) {
1633
+ * async execute(params: this['params']): Promise<string> {
1634
+ * // If this takes longer than 5 seconds, execution will be aborted
1635
+ * const response = await fetch(params.endpoint);
1636
+ * return await response.text();
1637
+ * }
1638
+ * }
1639
+ * ```
1640
+ */
1641
+ declare class TimeoutException extends Error {
1642
+ readonly timeoutMs: number;
1643
+ readonly gadgetName: string;
1644
+ constructor(gadgetName: string, timeoutMs: number);
1645
+ }
1625
1646
  /**
1626
1647
  * Exception thrown when gadget execution is aborted.
1627
1648
  *
@@ -1637,7 +1658,7 @@ declare class HumanInputException extends Error {
1637
1658
  * schema: z.object({ data: z.string() }),
1638
1659
  * }) {
1639
1660
  * async execute(params: this['params'], ctx: ExecutionContext): Promise<string> {
1640
- * // Check at key points - throws AbortError if aborted
1661
+ * // Check at key points - throws AbortException if aborted
1641
1662
  * this.throwIfAborted(ctx);
1642
1663
  *
1643
1664
  * await this.doPartOne(params.data);
@@ -1651,7 +1672,7 @@ declare class HumanInputException extends Error {
1651
1672
  * }
1652
1673
  * ```
1653
1674
  */
1654
- declare class AbortError extends Error {
1675
+ declare class AbortException extends Error {
1655
1676
  constructor(message?: string);
1656
1677
  }
1657
1678
 
@@ -1666,23 +1687,27 @@ interface ErrorFormatterOptions {
1666
1687
 
1667
1688
  declare class GadgetExecutor {
1668
1689
  private readonly registry;
1669
- private readonly onHumanInputRequired?;
1690
+ private readonly requestHumanInput?;
1670
1691
  private readonly defaultGadgetTimeoutMs?;
1671
1692
  private readonly client?;
1693
+ private readonly mediaStore?;
1694
+ private readonly agentConfig?;
1695
+ private readonly subagentConfig?;
1672
1696
  private readonly logger;
1673
1697
  private readonly errorFormatter;
1674
1698
  private readonly argPrefix;
1675
- constructor(registry: GadgetRegistry, onHumanInputRequired?: ((question: string) => Promise<string>) | undefined, logger?: Logger<ILogObj>, defaultGadgetTimeoutMs?: number | undefined, errorFormatterOptions?: ErrorFormatterOptions, client?: LLMist | undefined);
1699
+ constructor(registry: GadgetRegistry, requestHumanInput?: ((question: string) => Promise<string>) | undefined, logger?: Logger<ILogObj>, defaultGadgetTimeoutMs?: number | undefined, errorFormatterOptions?: ErrorFormatterOptions, client?: LLMist | undefined, mediaStore?: MediaStore | undefined, agentConfig?: AgentContextConfig | undefined, subagentConfig?: SubagentConfigMap | undefined);
1676
1700
  /**
1677
1701
  * Creates a promise that rejects with a TimeoutException after the specified timeout.
1678
1702
  * Aborts the provided AbortController before rejecting, allowing gadgets to clean up.
1679
1703
  */
1680
1704
  private createTimeoutPromise;
1681
1705
  /**
1682
- * Normalizes gadget execute result to consistent format.
1683
- * Handles both string returns (backwards compat) and object returns with cost.
1706
+ * Unify gadget execute result to consistent internal format.
1707
+ * Handles string returns (backwards compat), object returns with cost,
1708
+ * and object returns with media.
1684
1709
  */
1685
- private normalizeExecuteResult;
1710
+ private unifyExecuteResult;
1686
1711
  execute(call: ParsedGadgetCall): Promise<GadgetExecutionResult>;
1687
1712
  executeAll(calls: ParsedGadgetCall[]): Promise<GadgetExecutionResult[]>;
1688
1713
  /**
@@ -1692,22 +1717,49 @@ declare class GadgetExecutor {
1692
1717
  private deepEquals;
1693
1718
  }
1694
1719
 
1720
+ /**
1721
+ * Create a GadgetOutputViewer gadget instance bound to a specific output store.
1722
+ *
1723
+ * This is a factory function because the gadget needs access to the output store,
1724
+ * which is created per-agent-run.
1725
+ *
1726
+ * @param store - The GadgetOutputStore to read outputs from
1727
+ * @param maxOutputChars - Maximum characters to return (default: 76,800 = ~19k tokens)
1728
+ * @returns A GadgetOutputViewer gadget instance
1729
+ *
1730
+ * @example
1731
+ * ```typescript
1732
+ * const store = new GadgetOutputStore();
1733
+ * const viewer = createGadgetOutputViewer(store, 76_800);
1734
+ * registry.register("GadgetOutputViewer", viewer);
1735
+ * ```
1736
+ */
1737
+ declare function createGadgetOutputViewer(store: GadgetOutputStore, maxOutputChars?: number): AbstractGadget;
1738
+
1695
1739
  interface StreamParserOptions {
1696
1740
  startPrefix?: string;
1697
1741
  endPrefix?: string;
1698
1742
  /** Prefix for block format arguments. Default: "!!!ARG:" */
1699
1743
  argPrefix?: string;
1700
1744
  }
1701
- declare class StreamParser {
1745
+ /**
1746
+ * Parser for extracting gadget invocations from LLM text output.
1747
+ * Processes text chunks incrementally and emits events for text and gadget calls.
1748
+ */
1749
+ declare class GadgetCallParser {
1702
1750
  private buffer;
1703
- private lastReportedTextLength;
1751
+ private lastEmittedTextOffset;
1704
1752
  private readonly startPrefix;
1705
1753
  private readonly endPrefix;
1706
1754
  private readonly argPrefix;
1707
1755
  constructor(options?: StreamParserOptions);
1708
- private takeTextUntil;
1709
1756
  /**
1710
- * Parse gadget name with optional invocation ID and dependencies.
1757
+ * Extract and consume text up to the given index.
1758
+ * Returns undefined if no meaningful text to emit.
1759
+ */
1760
+ private extractTextSegment;
1761
+ /**
1762
+ * Parse gadget invocation metadata from the header line.
1711
1763
  *
1712
1764
  * Supported formats:
1713
1765
  * - `GadgetName` - Auto-generate ID, no dependencies
@@ -1716,7 +1768,7 @@ declare class StreamParser {
1716
1768
  *
1717
1769
  * Dependencies must be comma-separated invocation IDs.
1718
1770
  */
1719
- private parseGadgetName;
1771
+ private parseInvocationMetadata;
1720
1772
  /**
1721
1773
  * Extract the error message from a parse error.
1722
1774
  * Preserves full message since the error formatter adds contextual help
@@ -1887,6 +1939,207 @@ declare function Gadget<TSchema extends ZodType>(config: GadgetConfig<TSchema>):
1887
1939
  };
1888
1940
  };
1889
1941
 
1942
+ /**
1943
+ * Helper functions for gadget authors to easily return media outputs.
1944
+ *
1945
+ * These functions provide type-specific conveniences while using the
1946
+ * generic GadgetMediaOutput system underneath.
1947
+ *
1948
+ * @example
1949
+ * ```typescript
1950
+ * import { resultWithImage } from "llmist/gadgets";
1951
+ *
1952
+ * const screenshotGadget = createGadget({
1953
+ * name: "Screenshot",
1954
+ * schema: z.object({ url: z.string() }),
1955
+ * execute: async ({ url }) => {
1956
+ * const screenshot = await takeScreenshot(url);
1957
+ * return resultWithImage(
1958
+ * `Screenshot of ${url}`,
1959
+ * screenshot,
1960
+ * { description: "Webpage screenshot" }
1961
+ * );
1962
+ * },
1963
+ * });
1964
+ * ```
1965
+ */
1966
+
1967
+ /**
1968
+ * Create a GadgetMediaOutput from raw data.
1969
+ *
1970
+ * @param kind - Type of media
1971
+ * @param data - Raw binary data (Buffer or Uint8Array)
1972
+ * @param mimeType - MIME type string
1973
+ * @param options - Optional description, metadata, and fileName
1974
+ * @returns A GadgetMediaOutput ready to include in results
1975
+ */
1976
+ declare function createMediaOutput(kind: MediaKind, data: Buffer | Uint8Array, mimeType: string, options?: {
1977
+ description?: string;
1978
+ metadata?: MediaMetadata;
1979
+ fileName?: string;
1980
+ }): GadgetMediaOutput;
1981
+ /**
1982
+ * Create a result with multiple media outputs.
1983
+ *
1984
+ * @param result - Text result string
1985
+ * @param media - Array of GadgetMediaOutput items (must not be empty)
1986
+ * @param cost - Optional cost in USD
1987
+ * @returns A GadgetExecuteResultWithMedia
1988
+ * @throws Error if media array is empty
1989
+ *
1990
+ * @example
1991
+ * ```typescript
1992
+ * return resultWithMedia(
1993
+ * "Generated 2 charts",
1994
+ * [
1995
+ * createMediaOutput("image", barChartPng, "image/png", { description: "Bar chart" }),
1996
+ * createMediaOutput("image", pieChartPng, "image/png", { description: "Pie chart" }),
1997
+ * ],
1998
+ * 0.002
1999
+ * );
2000
+ * ```
2001
+ */
2002
+ declare function resultWithMedia(result: string, media: GadgetMediaOutput[], cost?: number): GadgetExecuteResultWithMedia;
2003
+ /**
2004
+ * Options for resultWithImage helper.
2005
+ */
2006
+ interface ImageOptions {
2007
+ /** MIME type (auto-detected if not provided) */
2008
+ mimeType?: string;
2009
+ /** Human-readable description */
2010
+ description?: string;
2011
+ /** Image dimensions and other metadata */
2012
+ metadata?: MediaMetadata;
2013
+ /** Cost in USD */
2014
+ cost?: number;
2015
+ /** Filename to use when saving (if not provided, auto-generated) */
2016
+ fileName?: string;
2017
+ }
2018
+ /**
2019
+ * Create a result with a single image output.
2020
+ *
2021
+ * @param result - Text result string
2022
+ * @param imageData - Raw image data (PNG, JPEG, GIF, WebP)
2023
+ * @param options - Optional MIME type, description, metadata, cost
2024
+ * @returns A GadgetExecuteResultWithMedia
2025
+ *
2026
+ * @example
2027
+ * ```typescript
2028
+ * const screenshot = await page.screenshot({ type: "png" });
2029
+ * return resultWithImage(
2030
+ * "Screenshot captured",
2031
+ * screenshot,
2032
+ * { description: "Homepage screenshot", metadata: { width: 1920, height: 1080 } }
2033
+ * );
2034
+ * ```
2035
+ */
2036
+ declare function resultWithImage(result: string, imageData: Buffer | Uint8Array, options?: ImageOptions): GadgetExecuteResultWithMedia;
2037
+ /**
2038
+ * Image item for resultWithImages helper.
2039
+ */
2040
+ interface ImageItem {
2041
+ /** Raw image data */
2042
+ data: Buffer | Uint8Array;
2043
+ /** MIME type (auto-detected if not provided) */
2044
+ mimeType?: string;
2045
+ /** Human-readable description */
2046
+ description?: string;
2047
+ /** Image dimensions and other metadata */
2048
+ metadata?: MediaMetadata;
2049
+ /** Filename to use when saving (if not provided, auto-generated) */
2050
+ fileName?: string;
2051
+ }
2052
+ /**
2053
+ * Create a result with multiple image outputs.
2054
+ *
2055
+ * @param result - Text result string
2056
+ * @param images - Array of image items (must not be empty)
2057
+ * @param cost - Optional cost in USD
2058
+ * @returns A GadgetExecuteResultWithMedia
2059
+ * @throws Error if images array is empty
2060
+ *
2061
+ * @example
2062
+ * ```typescript
2063
+ * return resultWithImages(
2064
+ * "Generated comparison images",
2065
+ * [
2066
+ * { data: beforeImg, description: "Before" },
2067
+ * { data: afterImg, description: "After" },
2068
+ * ],
2069
+ * 0.01
2070
+ * );
2071
+ * ```
2072
+ */
2073
+ declare function resultWithImages(result: string, images: ImageItem[], cost?: number): GadgetExecuteResultWithMedia;
2074
+ /**
2075
+ * Options for resultWithAudio helper.
2076
+ */
2077
+ interface AudioOptions {
2078
+ /** MIME type (auto-detected if not provided) */
2079
+ mimeType?: string;
2080
+ /** Human-readable description */
2081
+ description?: string;
2082
+ /** Duration in milliseconds */
2083
+ durationMs?: number;
2084
+ /** Cost in USD */
2085
+ cost?: number;
2086
+ /** Filename to use when saving (if not provided, auto-generated) */
2087
+ fileName?: string;
2088
+ }
2089
+ /**
2090
+ * Create a result with a single audio output.
2091
+ *
2092
+ * @param result - Text result string
2093
+ * @param audioData - Raw audio data (MP3, WAV, OGG, etc.)
2094
+ * @param options - Optional MIME type, description, duration, cost
2095
+ * @returns A GadgetExecuteResultWithMedia
2096
+ *
2097
+ * @example
2098
+ * ```typescript
2099
+ * const speech = await generateSpeech(text);
2100
+ * return resultWithAudio(
2101
+ * `Generated speech for: "${text.slice(0, 50)}..."`,
2102
+ * speech,
2103
+ * { mimeType: "audio/mp3", durationMs: 5000 }
2104
+ * );
2105
+ * ```
2106
+ */
2107
+ declare function resultWithAudio(result: string, audioData: Buffer | Uint8Array, options?: AudioOptions): GadgetExecuteResultWithMedia;
2108
+ /**
2109
+ * Options for resultWithFile helper.
2110
+ */
2111
+ interface FileOptions {
2112
+ /** Human-readable description */
2113
+ description?: string;
2114
+ /** Cost in USD */
2115
+ cost?: number;
2116
+ /** Filename to use when saving (if not provided, auto-generated) */
2117
+ fileName?: string;
2118
+ }
2119
+ /**
2120
+ * Create a result with a generic file output.
2121
+ *
2122
+ * Use this for arbitrary file types that don't fit image/audio categories.
2123
+ *
2124
+ * @param result - Text result string
2125
+ * @param fileData - Raw file data
2126
+ * @param mimeType - MIME type (required, not auto-detected)
2127
+ * @param options - Optional description and cost
2128
+ * @returns A GadgetExecuteResultWithMedia
2129
+ *
2130
+ * @example
2131
+ * ```typescript
2132
+ * const pdf = await generatePdf(content);
2133
+ * return resultWithFile(
2134
+ * "Generated PDF report",
2135
+ * pdf,
2136
+ * "application/pdf",
2137
+ * { description: "Monthly report" }
2138
+ * );
2139
+ * ```
2140
+ */
2141
+ declare function resultWithFile(result: string, fileData: Buffer | Uint8Array, mimeType: string, options?: FileOptions): GadgetExecuteResultWithMedia;
2142
+
1890
2143
  /**
1891
2144
  * Validation utilities for gadget parameters.
1892
2145
  *
@@ -1978,7 +2231,7 @@ declare function validateAndApplyDefaults<T = Record<string, unknown>>(schema: Z
1978
2231
  * }
1979
2232
  * ```
1980
2233
  */
1981
- declare function validateGadgetParams(gadget: BaseGadget, params: Record<string, unknown>): ValidationResult;
2234
+ declare function validateGadgetParams(gadget: AbstractGadget, params: Record<string, unknown>): ValidationResult;
1982
2235
 
1983
2236
  /**
1984
2237
  * Logger configuration options for the library.
@@ -2070,16 +2323,16 @@ declare abstract class BaseProviderAdapter implements ProviderAdapter {
2070
2323
  */
2071
2324
  protected prepareMessages(messages: LLMMessage[]): LLMMessage[];
2072
2325
  /**
2073
- * Build the provider-specific request payload.
2326
+ * Build the provider-specific API request.
2074
2327
  * This method must be implemented by each concrete provider.
2075
2328
  *
2076
2329
  * @param options - The generation options
2077
2330
  * @param descriptor - The model descriptor
2078
2331
  * @param spec - Optional model specification with metadata
2079
2332
  * @param messages - The prepared messages
2080
- * @returns Provider-specific payload ready for the API call
2333
+ * @returns Provider-specific request object ready for the API call
2081
2334
  */
2082
- protected abstract buildRequestPayload(options: LLMGenerationOptions, descriptor: ModelDescriptor, spec: ModelSpec | undefined, messages: LLMMessage[]): unknown;
2335
+ protected abstract buildApiRequest(options: LLMGenerationOptions, descriptor: ModelDescriptor, spec: ModelSpec | undefined, messages: LLMMessage[]): unknown;
2083
2336
  /**
2084
2337
  * Execute the stream request using the provider's SDK.
2085
2338
  * This method must be implemented by each concrete provider.
@@ -2090,13 +2343,13 @@ declare abstract class BaseProviderAdapter implements ProviderAdapter {
2090
2343
  */
2091
2344
  protected abstract executeStreamRequest(payload: unknown, signal?: AbortSignal): Promise<AsyncIterable<unknown>>;
2092
2345
  /**
2093
- * Wrap the provider-specific stream into the universal LLMStream format.
2346
+ * Normalize the provider-specific stream into the universal LLMStream format.
2094
2347
  * This method must be implemented by each concrete provider.
2095
2348
  *
2096
2349
  * @param rawStream - The provider-specific stream
2097
2350
  * @returns Universal LLMStream
2098
2351
  */
2099
- protected abstract wrapStream(rawStream: AsyncIterable<unknown>): LLMStream;
2352
+ protected abstract normalizeProviderStream(rawStream: AsyncIterable<unknown>): LLMStream;
2100
2353
  }
2101
2354
 
2102
2355
  declare class AnthropicMessagesProvider extends BaseProviderAdapter {
@@ -2107,7 +2360,7 @@ declare class AnthropicMessagesProvider extends BaseProviderAdapter {
2107
2360
  generateImage(): Promise<never>;
2108
2361
  supportsSpeechGeneration(_modelId: string): boolean;
2109
2362
  generateSpeech(): Promise<never>;
2110
- protected buildRequestPayload(options: LLMGenerationOptions, descriptor: ModelDescriptor, spec: ModelSpec | undefined, messages: LLMMessage[]): MessageCreateParamsStreaming;
2363
+ protected buildApiRequest(options: LLMGenerationOptions, descriptor: ModelDescriptor, spec: ModelSpec | undefined, messages: LLMMessage[]): MessageCreateParamsStreaming;
2111
2364
  /**
2112
2365
  * Convert llmist content to Anthropic's content block format.
2113
2366
  * Handles text, images (base64 only), and applies cache_control.
@@ -2118,7 +2371,7 @@ declare class AnthropicMessagesProvider extends BaseProviderAdapter {
2118
2371
  */
2119
2372
  private convertImagePart;
2120
2373
  protected executeStreamRequest(payload: MessageCreateParamsStreaming, signal?: AbortSignal): Promise<AsyncIterable<MessageStreamEvent>>;
2121
- protected wrapStream(iterable: AsyncIterable<unknown>): LLMStream;
2374
+ protected normalizeProviderStream(iterable: AsyncIterable<unknown>): LLMStream;
2122
2375
  /**
2123
2376
  * Count tokens in messages using Anthropic's native token counting API.
2124
2377
  *
@@ -2193,7 +2446,7 @@ declare class GeminiGenerativeProvider extends BaseProviderAdapter {
2193
2446
  getSpeechModelSpecs(): SpeechModelSpec[];
2194
2447
  supportsSpeechGeneration(modelId: string): boolean;
2195
2448
  generateSpeech(options: SpeechGenerationOptions): Promise<SpeechGenerationResult>;
2196
- protected buildRequestPayload(options: LLMGenerationOptions, descriptor: ModelDescriptor, _spec: ModelSpec | undefined, messages: LLMMessage[]): {
2449
+ protected buildApiRequest(options: LLMGenerationOptions, descriptor: ModelDescriptor, _spec: ModelSpec | undefined, messages: LLMMessage[]): {
2197
2450
  model: string;
2198
2451
  contents: GeminiContent[];
2199
2452
  config: Record<string, unknown>;
@@ -2229,8 +2482,8 @@ declare class GeminiGenerativeProvider extends BaseProviderAdapter {
2229
2482
  */
2230
2483
  private convertToGeminiParts;
2231
2484
  private buildGenerationConfig;
2232
- protected wrapStream(iterable: AsyncIterable<unknown>): LLMStream;
2233
- private extractText;
2485
+ protected normalizeProviderStream(iterable: AsyncIterable<unknown>): LLMStream;
2486
+ private extractMessageText;
2234
2487
  private extractFinishReason;
2235
2488
  private extractUsage;
2236
2489
  /**
@@ -2270,7 +2523,7 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
2270
2523
  getSpeechModelSpecs(): SpeechModelSpec[];
2271
2524
  supportsSpeechGeneration(modelId: string): boolean;
2272
2525
  generateSpeech(options: SpeechGenerationOptions): Promise<SpeechGenerationResult>;
2273
- protected buildRequestPayload(options: LLMGenerationOptions, descriptor: ModelDescriptor, spec: ModelSpec | undefined, messages: LLMMessage[]): Parameters<OpenAI["chat"]["completions"]["create"]>[0];
2526
+ protected buildApiRequest(options: LLMGenerationOptions, descriptor: ModelDescriptor, spec: ModelSpec | undefined, messages: LLMMessage[]): Parameters<OpenAI["chat"]["completions"]["create"]>[0];
2274
2527
  /**
2275
2528
  * Convert an LLMMessage to OpenAI's ChatCompletionMessageParam.
2276
2529
  * Handles role-specific content type requirements:
@@ -2289,7 +2542,7 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
2289
2542
  */
2290
2543
  private convertImagePart;
2291
2544
  protected executeStreamRequest(payload: Parameters<OpenAI["chat"]["completions"]["create"]>[0], signal?: AbortSignal): Promise<AsyncIterable<ChatCompletionChunk>>;
2292
- protected wrapStream(iterable: AsyncIterable<unknown>): LLMStream;
2545
+ protected normalizeProviderStream(iterable: AsyncIterable<unknown>): LLMStream;
2293
2546
  /**
2294
2547
  * Count tokens in messages using OpenAI's tiktoken library.
2295
2548
  *
@@ -2317,4 +2570,4 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
2317
2570
  }
2318
2571
  declare function createOpenAIProviderFromEnv(): OpenAIChatProvider | null;
2319
2572
 
2320
- export { AbortError, AgentHooks, AnthropicMessagesProvider, BaseGadget, BreakLoopException, CompactionConfig, CompactionContext, CompactionEvent, CompactionManager, CompactionResult, CompactionStats, CompactionStrategy, ConversationManager, type CreateGadgetConfig, ExecutionContext, Gadget, type GadgetConfig, GadgetExample, GadgetExecuteReturn, GadgetExecutionResult, GadgetExecutor, GadgetOutputStore, GadgetRegistry, GeminiGenerativeProvider, HintTemplate, type HintsConfig, HookPresets, HumanInputException, HybridStrategy, IConversationManager, type IterationHintOptions, LLMGenerationOptions, LLMMessage, LLMStream, LLMStreamChunk, LLMist, type LoggerOptions, type LoggingOptions, MODEL_ALIASES, MessageContent, ModelDescriptor, ModelRegistry, ModelSpec, OpenAIChatProvider, type ParallelGadgetHintOptions, ParsedGadgetCall, ProviderAdapter, ResolvedCompactionConfig, SlidingWindowStrategy, type StoredOutput, StreamEvent, StreamParser, type StreamProcessingResult, StreamProcessor, type StreamProcessorOptions, SummarizationStrategy, TokenUsage, type ValidationIssue, type ValidationResult, createAnthropicProviderFromEnv, createGadget, createGadgetOutputViewer, createGeminiProviderFromEnv, createHints, createLogger, createOpenAIProviderFromEnv, defaultLogger, discoverProviderAdapters, getModelId, getProvider, hasProviderPrefix, iterationProgressHint, parallelGadgetHint, resolveModel, validateAndApplyDefaults, validateGadgetParams };
2573
+ export { AbortException, AbstractGadget, AgentHooks, AnthropicMessagesProvider, CompactionConfig, CompactionContext, CompactionEvent, CompactionManager, CompactionResult, CompactionStats, CompactionStrategy, ConversationManager, type CreateGadgetConfig, ExecutionContext, Gadget, GadgetCallParser, type GadgetConfig, GadgetExample, GadgetExecuteResultWithMedia, GadgetExecuteReturn, GadgetExecutionResult, GadgetExecutor, GadgetMediaOutput, GadgetOutputStore, GadgetRegistry, GeminiGenerativeProvider, HintTemplate, type HintsConfig, HookPresets, HumanInputRequiredException, HybridStrategy, IConversationManager, type IterationHintOptions, LLMGenerationOptions, LLMMessage, LLMStream, LLMStreamChunk, LLMist, type LoggerOptions, type LoggingOptions, MODEL_ALIASES, MediaKind, MediaMetadata, MediaStore, MessageContent, ModelDescriptor, ModelRegistry, ModelSpec, OpenAIChatProvider, type ParallelGadgetHintOptions, ParsedGadgetCall, ProviderAdapter, ResolvedCompactionConfig, SlidingWindowStrategy, type StoredOutput, StreamEvent, type StreamProcessingResult, StreamProcessor, type StreamProcessorOptions, SummarizationStrategy, TaskCompletionSignal, TimeoutException, TokenUsage, type ValidationIssue, type ValidationResult, createAnthropicProviderFromEnv, createGadget, createGadgetOutputViewer, createGeminiProviderFromEnv, createHints, createLogger, createMediaOutput, createOpenAIProviderFromEnv, defaultLogger, discoverProviderAdapters, getModelId, getProvider, hasProviderPrefix, iterationProgressHint, parallelGadgetHint, resolveModel, resultWithAudio, resultWithFile, resultWithImage, resultWithImages, resultWithMedia, validateAndApplyDefaults, validateGadgetParams };