llmist 2.3.0 → 2.5.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, q as ModelRegistry, I as IConversationManager, b as LLMMessage, S as StreamEvent, T as TokenUsage, G as GadgetRegistry, r as LLMist, a as LLMStreamChunk, C as CompactionStrategy, R as ResolvedCompactionConfig, s as CompactionContext, t as CompactionResult, u as CompactionConfig, v as CompactionEvent, w as CompactionStats, H as HintTemplate, E as ExecutionContext, x as GadgetExecuteReturn, y as GadgetExample, B as BaseGadget, P as ParsedGadgetCall, z as GadgetExecutionResult, D as ProviderAdapter, F as ModelDescriptor, J as ModelSpec, K as LLMGenerationOptions, L as LLMStream } from './mock-stream-wRfUqXx4.cjs';
4
- export { Z as AfterGadgetExecutionAction, _ as AfterGadgetExecutionControllerContext, $ as AfterLLMCallAction, a0 as AfterLLMCallControllerContext, a1 as AfterLLMErrorAction, U as AgentBuilder, a2 as AgentOptions, a3 as BeforeGadgetExecutionAction, a4 as BeforeLLMCallAction, a5 as ChunkInterceptorContext, a6 as Controllers, as as CostEstimate, aM as CostReportingLLMist, an as DEFAULT_COMPACTION_CONFIG, aC as DEFAULT_HINTS, aD as DEFAULT_PROMPTS, ao as DEFAULT_SUMMARIZATION_PROMPT, V as EventHandlers, aK as GadgetClass, aN as GadgetExecuteResult, a7 as GadgetExecutionControllerContext, aL as GadgetOrClass, a8 as GadgetParameterInterceptorContext, a9 as GadgetResultInterceptorContext, ay as HintContext, N as HistoryMessage, aa as Interceptors, ab as LLMCallControllerContext, ac as LLMErrorControllerContext, ar as LLMMessageBuilder, aq as LLMRole, ap as LLMistOptions, ad as MessageInterceptorContext, al as MessageTurn, d as MockBuilder, f as MockManager, j as MockMatcher, k as MockMatcherContext, l as MockOptions, M as MockProviderAdapter, n as MockRegistration, o as MockResponse, p as MockStats, at as ModelFeatures, ax as ModelIdentifierParser, au as ModelLimits, av as ModelPricing, ae as ObserveChunkContext, am as ObserveCompactionContext, af as ObserveGadgetCompleteContext, ag as ObserveGadgetStartContext, ah as ObserveLLMCallContext, ai as ObserveLLMCompleteContext, aj as ObserveLLMErrorContext, ak as Observers, az as PromptConfig, aA as PromptContext, aB as PromptTemplate, aw as ProviderIdentifier, aH as QuickOptions, aO as TextOnlyAction, aP as TextOnlyContext, aQ as TextOnlyCustomHandler, aR as TextOnlyGadgetConfig, aS as TextOnlyHandler, aT as TextOnlyStrategy, O as TrailingMessage, Q as TrailingMessageContext, W as collectEvents, X as collectText, aI as complete, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, g as getMockManager, m as mockLLM, aE as resolveHintTemplate, aF as resolvePromptTemplate, aG as resolveRulesTemplate, Y as runWithHandlers, aJ as stream } from './mock-stream-wRfUqXx4.cjs';
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';
5
5
  import { Logger, ILogObj } from 'tslog';
6
6
  import { MessageCreateParamsStreaming, MessageStreamEvent } from '@anthropic-ai/sdk/resources/messages';
7
7
  import OpenAI from 'openai';
@@ -740,7 +740,7 @@ declare class ConversationManager implements IConversationManager {
740
740
  private readonly endPrefix?;
741
741
  private readonly argPrefix?;
742
742
  constructor(baseMessages: LLMMessage[], initialMessages: LLMMessage[], options?: ConversationManagerOptions);
743
- addUserMessage(content: string): void;
743
+ addUserMessage(content: MessageContent): void;
744
744
  addAssistantMessage(content: string): void;
745
745
  addGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): void;
746
746
  getMessages(): LLMMessage[];
@@ -843,6 +843,12 @@ declare class StreamProcessor {
843
843
  private accumulatedText;
844
844
  private shouldStopExecution;
845
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;
846
852
  constructor(options: StreamProcessorOptions);
847
853
  /**
848
854
  * Process an LLM stream and return structured results.
@@ -857,9 +863,28 @@ declare class StreamProcessor {
857
863
  */
858
864
  private processTextEvent;
859
865
  /**
860
- * Process a gadget call through the full lifecycle.
866
+ * Process a gadget call through the full lifecycle, handling dependencies.
867
+ *
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.
861
871
  */
862
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;
863
888
  /**
864
889
  * Safely execute an observer, catching and logging any errors.
865
890
  * Observers are non-critical, so errors are logged but don't crash the system.
@@ -1682,8 +1707,14 @@ declare class StreamParser {
1682
1707
  constructor(options?: StreamParserOptions);
1683
1708
  private takeTextUntil;
1684
1709
  /**
1685
- * Parse gadget name, handling both old format (name:invocationId) and new format (just name).
1686
- * For new format, generates a unique invocation ID.
1710
+ * Parse gadget name with optional invocation ID and dependencies.
1711
+ *
1712
+ * Supported formats:
1713
+ * - `GadgetName` - Auto-generate ID, no dependencies
1714
+ * - `GadgetName:my_id` - Explicit ID, no dependencies
1715
+ * - `GadgetName:my_id:dep1,dep2` - Explicit ID with dependencies
1716
+ *
1717
+ * Dependencies must be comma-separated invocation IDs.
1687
1718
  */
1688
1719
  private parseGadgetName;
1689
1720
  /**
@@ -2072,7 +2103,20 @@ declare class AnthropicMessagesProvider extends BaseProviderAdapter {
2072
2103
  readonly providerId: "anthropic";
2073
2104
  supports(descriptor: ModelDescriptor): boolean;
2074
2105
  getModelSpecs(): ModelSpec[];
2106
+ supportsImageGeneration(_modelId: string): boolean;
2107
+ generateImage(): Promise<never>;
2108
+ supportsSpeechGeneration(_modelId: string): boolean;
2109
+ generateSpeech(): Promise<never>;
2075
2110
  protected buildRequestPayload(options: LLMGenerationOptions, descriptor: ModelDescriptor, spec: ModelSpec | undefined, messages: LLMMessage[]): MessageCreateParamsStreaming;
2111
+ /**
2112
+ * Convert llmist content to Anthropic's content block format.
2113
+ * Handles text, images (base64 only), and applies cache_control.
2114
+ */
2115
+ private convertToAnthropicContent;
2116
+ /**
2117
+ * Convert an image content part to Anthropic's image block format.
2118
+ */
2119
+ private convertImagePart;
2076
2120
  protected executeStreamRequest(payload: MessageCreateParamsStreaming, signal?: AbortSignal): Promise<AsyncIterable<MessageStreamEvent>>;
2077
2121
  protected wrapStream(iterable: AsyncIterable<unknown>): LLMStream;
2078
2122
  /**
@@ -2104,6 +2148,24 @@ declare function createAnthropicProviderFromEnv(): AnthropicMessagesProvider | n
2104
2148
 
2105
2149
  declare function discoverProviderAdapters(): ProviderAdapter[];
2106
2150
 
2151
+ /**
2152
+ * Gemini content part - can be text or inline data (images/audio).
2153
+ */
2154
+ type GeminiPart = {
2155
+ text: string;
2156
+ } | {
2157
+ inlineData: {
2158
+ mimeType: string;
2159
+ data: string;
2160
+ };
2161
+ };
2162
+ /**
2163
+ * Gemini content with role and multimodal parts.
2164
+ */
2165
+ type GeminiContent = {
2166
+ role: string;
2167
+ parts: GeminiPart[];
2168
+ };
2107
2169
  type GeminiChunk = {
2108
2170
  text?: () => string;
2109
2171
  candidates?: Array<{
@@ -2125,24 +2187,20 @@ declare class GeminiGenerativeProvider extends BaseProviderAdapter {
2125
2187
  readonly providerId: "gemini";
2126
2188
  supports(descriptor: ModelDescriptor): boolean;
2127
2189
  getModelSpecs(): ModelSpec[];
2190
+ getImageModelSpecs(): ImageModelSpec[];
2191
+ supportsImageGeneration(modelId: string): boolean;
2192
+ generateImage(options: ImageGenerationOptions): Promise<ImageGenerationResult>;
2193
+ getSpeechModelSpecs(): SpeechModelSpec[];
2194
+ supportsSpeechGeneration(modelId: string): boolean;
2195
+ generateSpeech(options: SpeechGenerationOptions): Promise<SpeechGenerationResult>;
2128
2196
  protected buildRequestPayload(options: LLMGenerationOptions, descriptor: ModelDescriptor, _spec: ModelSpec | undefined, messages: LLMMessage[]): {
2129
2197
  model: string;
2130
- contents: Array<{
2131
- role: string;
2132
- parts: Array<{
2133
- text: string;
2134
- }>;
2135
- }>;
2198
+ contents: GeminiContent[];
2136
2199
  config: Record<string, unknown>;
2137
2200
  };
2138
2201
  protected executeStreamRequest(payload: {
2139
2202
  model: string;
2140
- contents: Array<{
2141
- role: string;
2142
- parts: Array<{
2143
- text: string;
2144
- }>;
2145
- }>;
2203
+ contents: GeminiContent[];
2146
2204
  config: Record<string, unknown>;
2147
2205
  }, signal?: AbortSignal): Promise<AsyncIterable<GeminiChunk>>;
2148
2206
  /**
@@ -2160,8 +2218,16 @@ declare class GeminiGenerativeProvider extends BaseProviderAdapter {
2160
2218
  * - Model: "Understood."
2161
2219
  */
2162
2220
  private convertMessagesToContents;
2221
+ /**
2222
+ * Merge consecutive messages with the same role (required by Gemini).
2223
+ * Handles multimodal content by converting to Gemini's part format.
2224
+ */
2163
2225
  private mergeConsecutiveMessages;
2164
- private convertContentsForNewSDK;
2226
+ /**
2227
+ * Convert llmist content to Gemini's part format.
2228
+ * Handles text, images, and audio (Gemini supports all three).
2229
+ */
2230
+ private convertToGeminiParts;
2165
2231
  private buildGenerationConfig;
2166
2232
  protected wrapStream(iterable: AsyncIterable<unknown>): LLMStream;
2167
2233
  private extractText;
@@ -2198,7 +2264,30 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
2198
2264
  readonly providerId: "openai";
2199
2265
  supports(descriptor: ModelDescriptor): boolean;
2200
2266
  getModelSpecs(): ModelSpec[];
2267
+ getImageModelSpecs(): ImageModelSpec[];
2268
+ supportsImageGeneration(modelId: string): boolean;
2269
+ generateImage(options: ImageGenerationOptions): Promise<ImageGenerationResult>;
2270
+ getSpeechModelSpecs(): SpeechModelSpec[];
2271
+ supportsSpeechGeneration(modelId: string): boolean;
2272
+ generateSpeech(options: SpeechGenerationOptions): Promise<SpeechGenerationResult>;
2201
2273
  protected buildRequestPayload(options: LLMGenerationOptions, descriptor: ModelDescriptor, spec: ModelSpec | undefined, messages: LLMMessage[]): Parameters<OpenAI["chat"]["completions"]["create"]>[0];
2274
+ /**
2275
+ * Convert an LLMMessage to OpenAI's ChatCompletionMessageParam.
2276
+ * Handles role-specific content type requirements:
2277
+ * - system/assistant: string content only
2278
+ * - user: string or multimodal array content
2279
+ */
2280
+ private convertToOpenAIMessage;
2281
+ /**
2282
+ * Convert llmist content to OpenAI's content format.
2283
+ * Optimizes by returning string for text-only content, array for multimodal.
2284
+ */
2285
+ private convertToOpenAIContent;
2286
+ /**
2287
+ * Convert an image content part to OpenAI's image_url format.
2288
+ * Supports both URLs and base64 data URLs.
2289
+ */
2290
+ private convertImagePart;
2202
2291
  protected executeStreamRequest(payload: Parameters<OpenAI["chat"]["completions"]["create"]>[0], signal?: AbortSignal): Promise<AsyncIterable<ChatCompletionChunk>>;
2203
2292
  protected wrapStream(iterable: AsyncIterable<unknown>): LLMStream;
2204
2293
  /**
@@ -2228,4 +2317,4 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
2228
2317
  }
2229
2318
  declare function createOpenAIProviderFromEnv(): OpenAIChatProvider | null;
2230
2319
 
2231
- 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, 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 };
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 };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ZodType, ZodTypeAny } from 'zod';
2
2
  export { z } from 'zod';
3
- import { A as AgentHooks, q as ModelRegistry, I as IConversationManager, b as LLMMessage, S as StreamEvent, T as TokenUsage, G as GadgetRegistry, r as LLMist, a as LLMStreamChunk, C as CompactionStrategy, R as ResolvedCompactionConfig, s as CompactionContext, t as CompactionResult, u as CompactionConfig, v as CompactionEvent, w as CompactionStats, H as HintTemplate, E as ExecutionContext, x as GadgetExecuteReturn, y as GadgetExample, B as BaseGadget, P as ParsedGadgetCall, z as GadgetExecutionResult, D as ProviderAdapter, F as ModelDescriptor, J as ModelSpec, K as LLMGenerationOptions, L as LLMStream } from './mock-stream-wRfUqXx4.js';
4
- export { Z as AfterGadgetExecutionAction, _ as AfterGadgetExecutionControllerContext, $ as AfterLLMCallAction, a0 as AfterLLMCallControllerContext, a1 as AfterLLMErrorAction, U as AgentBuilder, a2 as AgentOptions, a3 as BeforeGadgetExecutionAction, a4 as BeforeLLMCallAction, a5 as ChunkInterceptorContext, a6 as Controllers, as as CostEstimate, aM as CostReportingLLMist, an as DEFAULT_COMPACTION_CONFIG, aC as DEFAULT_HINTS, aD as DEFAULT_PROMPTS, ao as DEFAULT_SUMMARIZATION_PROMPT, V as EventHandlers, aK as GadgetClass, aN as GadgetExecuteResult, a7 as GadgetExecutionControllerContext, aL as GadgetOrClass, a8 as GadgetParameterInterceptorContext, a9 as GadgetResultInterceptorContext, ay as HintContext, N as HistoryMessage, aa as Interceptors, ab as LLMCallControllerContext, ac as LLMErrorControllerContext, ar as LLMMessageBuilder, aq as LLMRole, ap as LLMistOptions, ad as MessageInterceptorContext, al as MessageTurn, d as MockBuilder, f as MockManager, j as MockMatcher, k as MockMatcherContext, l as MockOptions, M as MockProviderAdapter, n as MockRegistration, o as MockResponse, p as MockStats, at as ModelFeatures, ax as ModelIdentifierParser, au as ModelLimits, av as ModelPricing, ae as ObserveChunkContext, am as ObserveCompactionContext, af as ObserveGadgetCompleteContext, ag as ObserveGadgetStartContext, ah as ObserveLLMCallContext, ai as ObserveLLMCompleteContext, aj as ObserveLLMErrorContext, ak as Observers, az as PromptConfig, aA as PromptContext, aB as PromptTemplate, aw as ProviderIdentifier, aH as QuickOptions, aO as TextOnlyAction, aP as TextOnlyContext, aQ as TextOnlyCustomHandler, aR as TextOnlyGadgetConfig, aS as TextOnlyHandler, aT as TextOnlyStrategy, O as TrailingMessage, Q as TrailingMessageContext, W as collectEvents, X as collectText, aI as complete, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, g as getMockManager, m as mockLLM, aE as resolveHintTemplate, aF as resolvePromptTemplate, aG as resolveRulesTemplate, Y as runWithHandlers, aJ as stream } from './mock-stream-wRfUqXx4.js';
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.js';
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.js';
5
5
  import { Logger, ILogObj } from 'tslog';
6
6
  import { MessageCreateParamsStreaming, MessageStreamEvent } from '@anthropic-ai/sdk/resources/messages';
7
7
  import OpenAI from 'openai';
@@ -740,7 +740,7 @@ declare class ConversationManager implements IConversationManager {
740
740
  private readonly endPrefix?;
741
741
  private readonly argPrefix?;
742
742
  constructor(baseMessages: LLMMessage[], initialMessages: LLMMessage[], options?: ConversationManagerOptions);
743
- addUserMessage(content: string): void;
743
+ addUserMessage(content: MessageContent): void;
744
744
  addAssistantMessage(content: string): void;
745
745
  addGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): void;
746
746
  getMessages(): LLMMessage[];
@@ -843,6 +843,12 @@ declare class StreamProcessor {
843
843
  private accumulatedText;
844
844
  private shouldStopExecution;
845
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;
846
852
  constructor(options: StreamProcessorOptions);
847
853
  /**
848
854
  * Process an LLM stream and return structured results.
@@ -857,9 +863,28 @@ declare class StreamProcessor {
857
863
  */
858
864
  private processTextEvent;
859
865
  /**
860
- * Process a gadget call through the full lifecycle.
866
+ * Process a gadget call through the full lifecycle, handling dependencies.
867
+ *
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.
861
871
  */
862
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;
863
888
  /**
864
889
  * Safely execute an observer, catching and logging any errors.
865
890
  * Observers are non-critical, so errors are logged but don't crash the system.
@@ -1682,8 +1707,14 @@ declare class StreamParser {
1682
1707
  constructor(options?: StreamParserOptions);
1683
1708
  private takeTextUntil;
1684
1709
  /**
1685
- * Parse gadget name, handling both old format (name:invocationId) and new format (just name).
1686
- * For new format, generates a unique invocation ID.
1710
+ * Parse gadget name with optional invocation ID and dependencies.
1711
+ *
1712
+ * Supported formats:
1713
+ * - `GadgetName` - Auto-generate ID, no dependencies
1714
+ * - `GadgetName:my_id` - Explicit ID, no dependencies
1715
+ * - `GadgetName:my_id:dep1,dep2` - Explicit ID with dependencies
1716
+ *
1717
+ * Dependencies must be comma-separated invocation IDs.
1687
1718
  */
1688
1719
  private parseGadgetName;
1689
1720
  /**
@@ -2072,7 +2103,20 @@ declare class AnthropicMessagesProvider extends BaseProviderAdapter {
2072
2103
  readonly providerId: "anthropic";
2073
2104
  supports(descriptor: ModelDescriptor): boolean;
2074
2105
  getModelSpecs(): ModelSpec[];
2106
+ supportsImageGeneration(_modelId: string): boolean;
2107
+ generateImage(): Promise<never>;
2108
+ supportsSpeechGeneration(_modelId: string): boolean;
2109
+ generateSpeech(): Promise<never>;
2075
2110
  protected buildRequestPayload(options: LLMGenerationOptions, descriptor: ModelDescriptor, spec: ModelSpec | undefined, messages: LLMMessage[]): MessageCreateParamsStreaming;
2111
+ /**
2112
+ * Convert llmist content to Anthropic's content block format.
2113
+ * Handles text, images (base64 only), and applies cache_control.
2114
+ */
2115
+ private convertToAnthropicContent;
2116
+ /**
2117
+ * Convert an image content part to Anthropic's image block format.
2118
+ */
2119
+ private convertImagePart;
2076
2120
  protected executeStreamRequest(payload: MessageCreateParamsStreaming, signal?: AbortSignal): Promise<AsyncIterable<MessageStreamEvent>>;
2077
2121
  protected wrapStream(iterable: AsyncIterable<unknown>): LLMStream;
2078
2122
  /**
@@ -2104,6 +2148,24 @@ declare function createAnthropicProviderFromEnv(): AnthropicMessagesProvider | n
2104
2148
 
2105
2149
  declare function discoverProviderAdapters(): ProviderAdapter[];
2106
2150
 
2151
+ /**
2152
+ * Gemini content part - can be text or inline data (images/audio).
2153
+ */
2154
+ type GeminiPart = {
2155
+ text: string;
2156
+ } | {
2157
+ inlineData: {
2158
+ mimeType: string;
2159
+ data: string;
2160
+ };
2161
+ };
2162
+ /**
2163
+ * Gemini content with role and multimodal parts.
2164
+ */
2165
+ type GeminiContent = {
2166
+ role: string;
2167
+ parts: GeminiPart[];
2168
+ };
2107
2169
  type GeminiChunk = {
2108
2170
  text?: () => string;
2109
2171
  candidates?: Array<{
@@ -2125,24 +2187,20 @@ declare class GeminiGenerativeProvider extends BaseProviderAdapter {
2125
2187
  readonly providerId: "gemini";
2126
2188
  supports(descriptor: ModelDescriptor): boolean;
2127
2189
  getModelSpecs(): ModelSpec[];
2190
+ getImageModelSpecs(): ImageModelSpec[];
2191
+ supportsImageGeneration(modelId: string): boolean;
2192
+ generateImage(options: ImageGenerationOptions): Promise<ImageGenerationResult>;
2193
+ getSpeechModelSpecs(): SpeechModelSpec[];
2194
+ supportsSpeechGeneration(modelId: string): boolean;
2195
+ generateSpeech(options: SpeechGenerationOptions): Promise<SpeechGenerationResult>;
2128
2196
  protected buildRequestPayload(options: LLMGenerationOptions, descriptor: ModelDescriptor, _spec: ModelSpec | undefined, messages: LLMMessage[]): {
2129
2197
  model: string;
2130
- contents: Array<{
2131
- role: string;
2132
- parts: Array<{
2133
- text: string;
2134
- }>;
2135
- }>;
2198
+ contents: GeminiContent[];
2136
2199
  config: Record<string, unknown>;
2137
2200
  };
2138
2201
  protected executeStreamRequest(payload: {
2139
2202
  model: string;
2140
- contents: Array<{
2141
- role: string;
2142
- parts: Array<{
2143
- text: string;
2144
- }>;
2145
- }>;
2203
+ contents: GeminiContent[];
2146
2204
  config: Record<string, unknown>;
2147
2205
  }, signal?: AbortSignal): Promise<AsyncIterable<GeminiChunk>>;
2148
2206
  /**
@@ -2160,8 +2218,16 @@ declare class GeminiGenerativeProvider extends BaseProviderAdapter {
2160
2218
  * - Model: "Understood."
2161
2219
  */
2162
2220
  private convertMessagesToContents;
2221
+ /**
2222
+ * Merge consecutive messages with the same role (required by Gemini).
2223
+ * Handles multimodal content by converting to Gemini's part format.
2224
+ */
2163
2225
  private mergeConsecutiveMessages;
2164
- private convertContentsForNewSDK;
2226
+ /**
2227
+ * Convert llmist content to Gemini's part format.
2228
+ * Handles text, images, and audio (Gemini supports all three).
2229
+ */
2230
+ private convertToGeminiParts;
2165
2231
  private buildGenerationConfig;
2166
2232
  protected wrapStream(iterable: AsyncIterable<unknown>): LLMStream;
2167
2233
  private extractText;
@@ -2198,7 +2264,30 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
2198
2264
  readonly providerId: "openai";
2199
2265
  supports(descriptor: ModelDescriptor): boolean;
2200
2266
  getModelSpecs(): ModelSpec[];
2267
+ getImageModelSpecs(): ImageModelSpec[];
2268
+ supportsImageGeneration(modelId: string): boolean;
2269
+ generateImage(options: ImageGenerationOptions): Promise<ImageGenerationResult>;
2270
+ getSpeechModelSpecs(): SpeechModelSpec[];
2271
+ supportsSpeechGeneration(modelId: string): boolean;
2272
+ generateSpeech(options: SpeechGenerationOptions): Promise<SpeechGenerationResult>;
2201
2273
  protected buildRequestPayload(options: LLMGenerationOptions, descriptor: ModelDescriptor, spec: ModelSpec | undefined, messages: LLMMessage[]): Parameters<OpenAI["chat"]["completions"]["create"]>[0];
2274
+ /**
2275
+ * Convert an LLMMessage to OpenAI's ChatCompletionMessageParam.
2276
+ * Handles role-specific content type requirements:
2277
+ * - system/assistant: string content only
2278
+ * - user: string or multimodal array content
2279
+ */
2280
+ private convertToOpenAIMessage;
2281
+ /**
2282
+ * Convert llmist content to OpenAI's content format.
2283
+ * Optimizes by returning string for text-only content, array for multimodal.
2284
+ */
2285
+ private convertToOpenAIContent;
2286
+ /**
2287
+ * Convert an image content part to OpenAI's image_url format.
2288
+ * Supports both URLs and base64 data URLs.
2289
+ */
2290
+ private convertImagePart;
2202
2291
  protected executeStreamRequest(payload: Parameters<OpenAI["chat"]["completions"]["create"]>[0], signal?: AbortSignal): Promise<AsyncIterable<ChatCompletionChunk>>;
2203
2292
  protected wrapStream(iterable: AsyncIterable<unknown>): LLMStream;
2204
2293
  /**
@@ -2228,4 +2317,4 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
2228
2317
  }
2229
2318
  declare function createOpenAIProviderFromEnv(): OpenAIChatProvider | null;
2230
2319
 
2231
- 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, 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 };
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 };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  iterationProgressHint,
6
6
  parallelGadgetHint,
7
7
  z
8
- } from "./chunk-ZDNV7DDO.js";
8
+ } from "./chunk-IHSZUAYN.js";
9
9
  import {
10
10
  AbortError,
11
11
  AgentBuilder,
@@ -37,6 +37,8 @@ import {
37
37
  StreamParser,
38
38
  StreamProcessor,
39
39
  SummarizationStrategy,
40
+ audioFromBase64,
41
+ audioFromBuffer,
40
42
  collectEvents,
41
43
  collectText,
42
44
  complete,
@@ -51,21 +53,35 @@ import {
51
53
  createOpenAIProviderFromEnv,
52
54
  createTextMockStream,
53
55
  defaultLogger,
56
+ detectAudioMimeType,
57
+ detectImageMimeType,
54
58
  discoverProviderAdapters,
59
+ extractText,
55
60
  getMockManager,
56
61
  getModelId,
57
62
  getProvider,
58
63
  hasProviderPrefix,
64
+ imageFromBase64,
65
+ imageFromBuffer,
66
+ imageFromUrl,
67
+ isAudioPart,
68
+ isDataUrl,
69
+ isImagePart,
70
+ isTextPart,
59
71
  mockLLM,
72
+ normalizeContent,
73
+ parseDataUrl,
60
74
  resolveHintTemplate,
61
75
  resolveModel,
62
76
  resolvePromptTemplate,
63
77
  resolveRulesTemplate,
64
78
  runWithHandlers,
65
79
  stream,
80
+ text,
81
+ toBase64,
66
82
  validateAndApplyDefaults,
67
83
  validateGadgetParams
68
- } from "./chunk-GANXNBIZ.js";
84
+ } from "./chunk-YHS2DYXP.js";
69
85
  export {
70
86
  AbortError,
71
87
  AgentBuilder,
@@ -99,6 +115,8 @@ export {
99
115
  StreamParser,
100
116
  StreamProcessor,
101
117
  SummarizationStrategy,
118
+ audioFromBase64,
119
+ audioFromBuffer,
102
120
  collectEvents,
103
121
  collectText,
104
122
  complete,
@@ -114,20 +132,34 @@ export {
114
132
  createOpenAIProviderFromEnv,
115
133
  createTextMockStream,
116
134
  defaultLogger,
135
+ detectAudioMimeType,
136
+ detectImageMimeType,
117
137
  discoverProviderAdapters,
138
+ extractText,
118
139
  getMockManager,
119
140
  getModelId,
120
141
  getProvider,
121
142
  hasProviderPrefix,
143
+ imageFromBase64,
144
+ imageFromBuffer,
145
+ imageFromUrl,
146
+ isAudioPart,
147
+ isDataUrl,
148
+ isImagePart,
149
+ isTextPart,
122
150
  iterationProgressHint,
123
151
  mockLLM,
152
+ normalizeContent,
124
153
  parallelGadgetHint,
154
+ parseDataUrl,
125
155
  resolveHintTemplate,
126
156
  resolveModel,
127
157
  resolvePromptTemplate,
128
158
  resolveRulesTemplate,
129
159
  runWithHandlers,
130
160
  stream,
161
+ text,
162
+ toBase64,
131
163
  validateAndApplyDefaults,
132
164
  validateGadgetParams,
133
165
  z