llmist 3.0.0 → 4.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/{chunk-NBPKLSXJ.js → chunk-Q6NQRMYD.js} +2 -2
- package/dist/chunk-Q6NQRMYD.js.map +1 -0
- package/dist/{chunk-67MMSOAT.js → chunk-RHR2M6T6.js} +643 -51
- package/dist/chunk-RHR2M6T6.js.map +1 -0
- package/dist/cli.cjs +914 -84
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +273 -35
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +642 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -6
- package/dist/index.d.ts +43 -6
- package/dist/index.js +2 -2
- package/dist/{mock-stream-COHw8h9b.d.cts → mock-stream-BvNYtrlG.d.cts} +223 -3
- package/dist/{mock-stream-COHw8h9b.d.ts → mock-stream-BvNYtrlG.d.ts} +223 -3
- package/dist/testing/index.cjs +642 -50
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +2 -2
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-67MMSOAT.js.map +0 -1
- package/dist/chunk-NBPKLSXJ.js.map +0 -1
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 { 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,
|
|
4
|
-
export {
|
|
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, K as SubagentEvent, b as LLMStreamChunk, N as ExecutionContext, O as GadgetExecuteReturn, P as GadgetExample, A as AbstractGadget, Q as ParsedGadgetCall, U as GadgetExecutionResult, V as MediaKind, W as MediaMetadata, X as GadgetExecuteResultWithMedia, Y as ProviderAdapter, Z as ModelDescriptor, _ as ModelSpec, $ as LLMGenerationOptions, a as LLMStream, a0 as ImageModelSpec, a1 as ImageGenerationOptions, a2 as ImageGenerationResult, a3 as SpeechModelSpec, a4 as SpeechGenerationOptions, a5 as SpeechGenerationResult } from './mock-stream-BvNYtrlG.cjs';
|
|
4
|
+
export { ae as AfterGadgetExecutionAction, af as AfterGadgetExecutionControllerContext, ag as AfterLLMCallAction, ah as AfterLLMCallControllerContext, ai as AfterLLMErrorAction, a9 as AgentBuilder, aj as AgentOptions, aI as AudioContentPart, aJ as AudioMimeType, aK as AudioSource, ak as BeforeGadgetExecutionAction, al as BeforeLLMCallAction, am as ChunkInterceptorContext, aL as ContentPart, an as Controllers, b8 as CostEstimate, bu as CostReportingLLMist, aF as DEFAULT_COMPACTION_CONFIG, bk as DEFAULT_HINTS, bl as DEFAULT_PROMPTS, aG as DEFAULT_SUMMARIZATION_PROMPT, aa as EventHandlers, bs as GadgetClass, bv as GadgetExecuteResult, ao as GadgetExecutionControllerContext, bt as GadgetOrClass, ap as GadgetParameterInterceptorContext, aq as GadgetResultInterceptorContext, bw as GadgetSkippedEvent, bg as HintContext, a6 as HistoryMessage, aM as ImageBase64Source, aN as ImageContentPart, aO as ImageMimeType, aP as ImageSource, aQ as ImageUrlSource, ar as Interceptors, as as LLMCallControllerContext, at as LLMErrorControllerContext, b6 as LLMMessageBuilder, aH as LLMistOptions, au as MessageInterceptorContext, b4 as MessageRole, av 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, b9 as ModelFeatures, bf as ModelIdentifierParser, ba as ModelLimits, bb as ModelPricing, aw as ObserveChunkContext, ax as ObserveCompactionContext, ay as ObserveGadgetCompleteContext, az as ObserveGadgetStartContext, aA as ObserveLLMCallContext, aB as ObserveLLMCompleteContext, aC as ObserveLLMErrorContext, aD as Observers, bh as PromptContext, bi as PromptTemplate, bj as PromptTemplateConfig, be as ProviderIdentifier, bx as StoredMedia, aE as SubagentContext, by as SubagentStreamEvent, aR as TextContentPart, bp as TextGenerationOptions, bz as TextOnlyAction, bA as TextOnlyContext, bB as TextOnlyCustomHandler, bC as TextOnlyGadgetConfig, bD as TextOnlyHandler, bE as TextOnlyStrategy, a7 as TrailingMessage, a8 as TrailingMessageContext, bc as VisionAnalyzeOptions, bd as VisionAnalyzeResult, aS as audioFromBase64, aT as audioFromBuffer, ab as collectEvents, ac as collectText, bq as complete, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, aU as detectAudioMimeType, aV as detectImageMimeType, b5 as extractMessageText, g as getMockManager, aW as imageFromBase64, aX as imageFromBuffer, aY as imageFromUrl, aZ as isAudioPart, a_ as isDataUrl, a$ as isImagePart, b0 as isTextPart, m as mockLLM, b7 as normalizeMessageContent, b1 as parseDataUrl, bm as resolveHintTemplate, bn as resolvePromptTemplate, bo as resolveRulesTemplate, ad as runWithHandlers, br as stream, b2 as text, b3 as toBase64 } from './mock-stream-BvNYtrlG.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';
|
|
@@ -1199,6 +1199,8 @@ interface StreamProcessorOptions {
|
|
|
1199
1199
|
agentConfig?: AgentContextConfig;
|
|
1200
1200
|
/** Subagent-specific configuration overrides */
|
|
1201
1201
|
subagentConfig?: SubagentConfigMap;
|
|
1202
|
+
/** Callback for subagent gadgets to report subagent events to parent */
|
|
1203
|
+
onSubagentEvent?: (event: SubagentEvent) => void;
|
|
1202
1204
|
}
|
|
1203
1205
|
/**
|
|
1204
1206
|
* Result of stream processing.
|
|
@@ -1261,13 +1263,26 @@ declare class StreamProcessor {
|
|
|
1261
1263
|
private failedInvocations;
|
|
1262
1264
|
constructor(options: StreamProcessorOptions);
|
|
1263
1265
|
/**
|
|
1264
|
-
* Process an LLM stream and
|
|
1266
|
+
* Process an LLM stream and yield events in real-time.
|
|
1267
|
+
*
|
|
1268
|
+
* This is an async generator that yields events immediately as they occur:
|
|
1269
|
+
* - Text events are yielded as text is streamed from the LLM
|
|
1270
|
+
* - gadget_call events are yielded immediately when a gadget call is parsed
|
|
1271
|
+
* - gadget_result events are yielded when gadget execution completes
|
|
1272
|
+
*
|
|
1273
|
+
* The final event is always a StreamCompletionEvent containing metadata.
|
|
1265
1274
|
*/
|
|
1266
|
-
process(stream: AsyncIterable<LLMStreamChunk>):
|
|
1275
|
+
process(stream: AsyncIterable<LLMStreamChunk>): AsyncGenerator<StreamEvent>;
|
|
1267
1276
|
/**
|
|
1268
1277
|
* Process a single parsed event (text or gadget call).
|
|
1278
|
+
* @deprecated Use processEventGenerator for real-time streaming
|
|
1269
1279
|
*/
|
|
1270
1280
|
private processEvent;
|
|
1281
|
+
/**
|
|
1282
|
+
* Process a single parsed event, yielding events in real-time.
|
|
1283
|
+
* Generator version of processEvent for streaming support.
|
|
1284
|
+
*/
|
|
1285
|
+
private processEventGenerator;
|
|
1271
1286
|
/**
|
|
1272
1287
|
* Process a text event through interceptors.
|
|
1273
1288
|
*/
|
|
@@ -1280,11 +1295,24 @@ declare class StreamProcessor {
|
|
|
1280
1295
|
* After each execution, pending gadgets are checked to see if they can now run.
|
|
1281
1296
|
*/
|
|
1282
1297
|
private processGadgetCall;
|
|
1298
|
+
/**
|
|
1299
|
+
* Process a gadget call, yielding events in real-time.
|
|
1300
|
+
*
|
|
1301
|
+
* Key difference from processGadgetCall: yields gadget_call event IMMEDIATELY
|
|
1302
|
+
* when parsed (before execution), enabling real-time UI feedback.
|
|
1303
|
+
*/
|
|
1304
|
+
private processGadgetCallGenerator;
|
|
1283
1305
|
/**
|
|
1284
1306
|
* Execute a gadget through the full hook lifecycle.
|
|
1285
1307
|
* This is the core execution logic, extracted from processGadgetCall.
|
|
1308
|
+
* @deprecated Use executeGadgetGenerator for real-time streaming
|
|
1286
1309
|
*/
|
|
1287
1310
|
private executeGadgetWithHooks;
|
|
1311
|
+
/**
|
|
1312
|
+
* Execute a gadget and yield the result event.
|
|
1313
|
+
* Generator version that yields gadget_result immediately when execution completes.
|
|
1314
|
+
*/
|
|
1315
|
+
private executeGadgetGenerator;
|
|
1288
1316
|
/**
|
|
1289
1317
|
* Handle a gadget that cannot execute because a dependency failed.
|
|
1290
1318
|
* Calls the onDependencySkipped controller to allow customization.
|
|
@@ -1295,6 +1323,14 @@ declare class StreamProcessor {
|
|
|
1295
1323
|
* Executes ready gadgets in parallel and continues until no more can be triggered.
|
|
1296
1324
|
*/
|
|
1297
1325
|
private processPendingGadgets;
|
|
1326
|
+
/**
|
|
1327
|
+
* Process pending gadgets, yielding events in real-time.
|
|
1328
|
+
* Generator version that yields events as gadgets complete.
|
|
1329
|
+
*
|
|
1330
|
+
* Note: Gadgets are still executed in parallel for efficiency,
|
|
1331
|
+
* but results are yielded as they become available.
|
|
1332
|
+
*/
|
|
1333
|
+
private processPendingGadgetsGenerator;
|
|
1298
1334
|
/**
|
|
1299
1335
|
* Safely execute an observer, catching and logging any errors.
|
|
1300
1336
|
* Observers are non-critical, so errors are logged but don't crash the system.
|
|
@@ -1693,10 +1729,11 @@ declare class GadgetExecutor {
|
|
|
1693
1729
|
private readonly mediaStore?;
|
|
1694
1730
|
private readonly agentConfig?;
|
|
1695
1731
|
private readonly subagentConfig?;
|
|
1732
|
+
private readonly onSubagentEvent?;
|
|
1696
1733
|
private readonly logger;
|
|
1697
1734
|
private readonly errorFormatter;
|
|
1698
1735
|
private readonly argPrefix;
|
|
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);
|
|
1736
|
+
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, onSubagentEvent?: ((event: SubagentEvent) => void) | undefined);
|
|
1700
1737
|
/**
|
|
1701
1738
|
* Creates a promise that rejects with a TimeoutException after the specified timeout.
|
|
1702
1739
|
* Aborts the provided AbortController before rejecting, allowing gadgets to clean up.
|
|
@@ -2570,4 +2607,4 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
|
|
|
2570
2607
|
}
|
|
2571
2608
|
declare function createOpenAIProviderFromEnv(): OpenAIChatProvider | null;
|
|
2572
2609
|
|
|
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 };
|
|
2610
|
+
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, SubagentEvent, 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 };
|
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 { 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,
|
|
4
|
-
export {
|
|
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, K as SubagentEvent, b as LLMStreamChunk, N as ExecutionContext, O as GadgetExecuteReturn, P as GadgetExample, A as AbstractGadget, Q as ParsedGadgetCall, U as GadgetExecutionResult, V as MediaKind, W as MediaMetadata, X as GadgetExecuteResultWithMedia, Y as ProviderAdapter, Z as ModelDescriptor, _ as ModelSpec, $ as LLMGenerationOptions, a as LLMStream, a0 as ImageModelSpec, a1 as ImageGenerationOptions, a2 as ImageGenerationResult, a3 as SpeechModelSpec, a4 as SpeechGenerationOptions, a5 as SpeechGenerationResult } from './mock-stream-BvNYtrlG.js';
|
|
4
|
+
export { ae as AfterGadgetExecutionAction, af as AfterGadgetExecutionControllerContext, ag as AfterLLMCallAction, ah as AfterLLMCallControllerContext, ai as AfterLLMErrorAction, a9 as AgentBuilder, aj as AgentOptions, aI as AudioContentPart, aJ as AudioMimeType, aK as AudioSource, ak as BeforeGadgetExecutionAction, al as BeforeLLMCallAction, am as ChunkInterceptorContext, aL as ContentPart, an as Controllers, b8 as CostEstimate, bu as CostReportingLLMist, aF as DEFAULT_COMPACTION_CONFIG, bk as DEFAULT_HINTS, bl as DEFAULT_PROMPTS, aG as DEFAULT_SUMMARIZATION_PROMPT, aa as EventHandlers, bs as GadgetClass, bv as GadgetExecuteResult, ao as GadgetExecutionControllerContext, bt as GadgetOrClass, ap as GadgetParameterInterceptorContext, aq as GadgetResultInterceptorContext, bw as GadgetSkippedEvent, bg as HintContext, a6 as HistoryMessage, aM as ImageBase64Source, aN as ImageContentPart, aO as ImageMimeType, aP as ImageSource, aQ as ImageUrlSource, ar as Interceptors, as as LLMCallControllerContext, at as LLMErrorControllerContext, b6 as LLMMessageBuilder, aH as LLMistOptions, au as MessageInterceptorContext, b4 as MessageRole, av 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, b9 as ModelFeatures, bf as ModelIdentifierParser, ba as ModelLimits, bb as ModelPricing, aw as ObserveChunkContext, ax as ObserveCompactionContext, ay as ObserveGadgetCompleteContext, az as ObserveGadgetStartContext, aA as ObserveLLMCallContext, aB as ObserveLLMCompleteContext, aC as ObserveLLMErrorContext, aD as Observers, bh as PromptContext, bi as PromptTemplate, bj as PromptTemplateConfig, be as ProviderIdentifier, bx as StoredMedia, aE as SubagentContext, by as SubagentStreamEvent, aR as TextContentPart, bp as TextGenerationOptions, bz as TextOnlyAction, bA as TextOnlyContext, bB as TextOnlyCustomHandler, bC as TextOnlyGadgetConfig, bD as TextOnlyHandler, bE as TextOnlyStrategy, a7 as TrailingMessage, a8 as TrailingMessageContext, bc as VisionAnalyzeOptions, bd as VisionAnalyzeResult, aS as audioFromBase64, aT as audioFromBuffer, ab as collectEvents, ac as collectText, bq as complete, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, aU as detectAudioMimeType, aV as detectImageMimeType, b5 as extractMessageText, g as getMockManager, aW as imageFromBase64, aX as imageFromBuffer, aY as imageFromUrl, aZ as isAudioPart, a_ as isDataUrl, a$ as isImagePart, b0 as isTextPart, m as mockLLM, b7 as normalizeMessageContent, b1 as parseDataUrl, bm as resolveHintTemplate, bn as resolvePromptTemplate, bo as resolveRulesTemplate, ad as runWithHandlers, br as stream, b2 as text, b3 as toBase64 } from './mock-stream-BvNYtrlG.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';
|
|
@@ -1199,6 +1199,8 @@ interface StreamProcessorOptions {
|
|
|
1199
1199
|
agentConfig?: AgentContextConfig;
|
|
1200
1200
|
/** Subagent-specific configuration overrides */
|
|
1201
1201
|
subagentConfig?: SubagentConfigMap;
|
|
1202
|
+
/** Callback for subagent gadgets to report subagent events to parent */
|
|
1203
|
+
onSubagentEvent?: (event: SubagentEvent) => void;
|
|
1202
1204
|
}
|
|
1203
1205
|
/**
|
|
1204
1206
|
* Result of stream processing.
|
|
@@ -1261,13 +1263,26 @@ declare class StreamProcessor {
|
|
|
1261
1263
|
private failedInvocations;
|
|
1262
1264
|
constructor(options: StreamProcessorOptions);
|
|
1263
1265
|
/**
|
|
1264
|
-
* Process an LLM stream and
|
|
1266
|
+
* Process an LLM stream and yield events in real-time.
|
|
1267
|
+
*
|
|
1268
|
+
* This is an async generator that yields events immediately as they occur:
|
|
1269
|
+
* - Text events are yielded as text is streamed from the LLM
|
|
1270
|
+
* - gadget_call events are yielded immediately when a gadget call is parsed
|
|
1271
|
+
* - gadget_result events are yielded when gadget execution completes
|
|
1272
|
+
*
|
|
1273
|
+
* The final event is always a StreamCompletionEvent containing metadata.
|
|
1265
1274
|
*/
|
|
1266
|
-
process(stream: AsyncIterable<LLMStreamChunk>):
|
|
1275
|
+
process(stream: AsyncIterable<LLMStreamChunk>): AsyncGenerator<StreamEvent>;
|
|
1267
1276
|
/**
|
|
1268
1277
|
* Process a single parsed event (text or gadget call).
|
|
1278
|
+
* @deprecated Use processEventGenerator for real-time streaming
|
|
1269
1279
|
*/
|
|
1270
1280
|
private processEvent;
|
|
1281
|
+
/**
|
|
1282
|
+
* Process a single parsed event, yielding events in real-time.
|
|
1283
|
+
* Generator version of processEvent for streaming support.
|
|
1284
|
+
*/
|
|
1285
|
+
private processEventGenerator;
|
|
1271
1286
|
/**
|
|
1272
1287
|
* Process a text event through interceptors.
|
|
1273
1288
|
*/
|
|
@@ -1280,11 +1295,24 @@ declare class StreamProcessor {
|
|
|
1280
1295
|
* After each execution, pending gadgets are checked to see if they can now run.
|
|
1281
1296
|
*/
|
|
1282
1297
|
private processGadgetCall;
|
|
1298
|
+
/**
|
|
1299
|
+
* Process a gadget call, yielding events in real-time.
|
|
1300
|
+
*
|
|
1301
|
+
* Key difference from processGadgetCall: yields gadget_call event IMMEDIATELY
|
|
1302
|
+
* when parsed (before execution), enabling real-time UI feedback.
|
|
1303
|
+
*/
|
|
1304
|
+
private processGadgetCallGenerator;
|
|
1283
1305
|
/**
|
|
1284
1306
|
* Execute a gadget through the full hook lifecycle.
|
|
1285
1307
|
* This is the core execution logic, extracted from processGadgetCall.
|
|
1308
|
+
* @deprecated Use executeGadgetGenerator for real-time streaming
|
|
1286
1309
|
*/
|
|
1287
1310
|
private executeGadgetWithHooks;
|
|
1311
|
+
/**
|
|
1312
|
+
* Execute a gadget and yield the result event.
|
|
1313
|
+
* Generator version that yields gadget_result immediately when execution completes.
|
|
1314
|
+
*/
|
|
1315
|
+
private executeGadgetGenerator;
|
|
1288
1316
|
/**
|
|
1289
1317
|
* Handle a gadget that cannot execute because a dependency failed.
|
|
1290
1318
|
* Calls the onDependencySkipped controller to allow customization.
|
|
@@ -1295,6 +1323,14 @@ declare class StreamProcessor {
|
|
|
1295
1323
|
* Executes ready gadgets in parallel and continues until no more can be triggered.
|
|
1296
1324
|
*/
|
|
1297
1325
|
private processPendingGadgets;
|
|
1326
|
+
/**
|
|
1327
|
+
* Process pending gadgets, yielding events in real-time.
|
|
1328
|
+
* Generator version that yields events as gadgets complete.
|
|
1329
|
+
*
|
|
1330
|
+
* Note: Gadgets are still executed in parallel for efficiency,
|
|
1331
|
+
* but results are yielded as they become available.
|
|
1332
|
+
*/
|
|
1333
|
+
private processPendingGadgetsGenerator;
|
|
1298
1334
|
/**
|
|
1299
1335
|
* Safely execute an observer, catching and logging any errors.
|
|
1300
1336
|
* Observers are non-critical, so errors are logged but don't crash the system.
|
|
@@ -1693,10 +1729,11 @@ declare class GadgetExecutor {
|
|
|
1693
1729
|
private readonly mediaStore?;
|
|
1694
1730
|
private readonly agentConfig?;
|
|
1695
1731
|
private readonly subagentConfig?;
|
|
1732
|
+
private readonly onSubagentEvent?;
|
|
1696
1733
|
private readonly logger;
|
|
1697
1734
|
private readonly errorFormatter;
|
|
1698
1735
|
private readonly argPrefix;
|
|
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);
|
|
1736
|
+
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, onSubagentEvent?: ((event: SubagentEvent) => void) | undefined);
|
|
1700
1737
|
/**
|
|
1701
1738
|
* Creates a promise that rejects with a TimeoutException after the specified timeout.
|
|
1702
1739
|
* Aborts the provided AbortController before rejecting, allowing gadgets to clean up.
|
|
@@ -2570,4 +2607,4 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
|
|
|
2570
2607
|
}
|
|
2571
2608
|
declare function createOpenAIProviderFromEnv(): OpenAIChatProvider | null;
|
|
2572
2609
|
|
|
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 };
|
|
2610
|
+
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, SubagentEvent, 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 };
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
resultWithImages,
|
|
12
12
|
resultWithMedia,
|
|
13
13
|
z
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-Q6NQRMYD.js";
|
|
15
15
|
import {
|
|
16
16
|
AbortException,
|
|
17
17
|
AbstractGadget,
|
|
@@ -89,7 +89,7 @@ import {
|
|
|
89
89
|
toBase64,
|
|
90
90
|
validateAndApplyDefaults,
|
|
91
91
|
validateGadgetParams
|
|
92
|
-
} from "./chunk-
|
|
92
|
+
} from "./chunk-RHR2M6T6.js";
|
|
93
93
|
export {
|
|
94
94
|
AbortException,
|
|
95
95
|
AbstractGadget,
|
|
@@ -986,6 +986,25 @@ interface GadgetSkippedEvent {
|
|
|
986
986
|
/** The error message from the failed dependency */
|
|
987
987
|
failedDependencyError: string;
|
|
988
988
|
}
|
|
989
|
+
/**
|
|
990
|
+
* Event emitted when stream processing completes, containing metadata.
|
|
991
|
+
* This allows the async generator to "return" metadata while still yielding events.
|
|
992
|
+
*/
|
|
993
|
+
interface StreamCompletionEvent {
|
|
994
|
+
type: "stream_complete";
|
|
995
|
+
/** The reason the LLM stopped generating (e.g., "stop", "tool_use") */
|
|
996
|
+
finishReason: string | null;
|
|
997
|
+
/** Token usage statistics from the LLM call */
|
|
998
|
+
usage?: TokenUsage;
|
|
999
|
+
/** Raw response text from the LLM */
|
|
1000
|
+
rawResponse: string;
|
|
1001
|
+
/** Final message after all interceptors applied */
|
|
1002
|
+
finalMessage: string;
|
|
1003
|
+
/** Whether any gadgets were executed during this iteration */
|
|
1004
|
+
didExecuteGadgets: boolean;
|
|
1005
|
+
/** Whether to break the agent loop (e.g., TaskComplete was called) */
|
|
1006
|
+
shouldBreakLoop: boolean;
|
|
1007
|
+
}
|
|
989
1008
|
type StreamEvent = {
|
|
990
1009
|
type: "text";
|
|
991
1010
|
content: string;
|
|
@@ -1003,7 +1022,57 @@ type StreamEvent = {
|
|
|
1003
1022
|
} | {
|
|
1004
1023
|
type: "compaction";
|
|
1005
1024
|
event: CompactionEvent;
|
|
1006
|
-
};
|
|
1025
|
+
} | SubagentStreamEvent | StreamCompletionEvent;
|
|
1026
|
+
/** Event for forwarding subagent activity through the stream */
|
|
1027
|
+
interface SubagentStreamEvent {
|
|
1028
|
+
type: "subagent_event";
|
|
1029
|
+
subagentEvent: SubagentEvent;
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Information about an LLM call within a subagent.
|
|
1033
|
+
* Used by parent agents to display real-time progress of subagent LLM calls.
|
|
1034
|
+
*/
|
|
1035
|
+
interface LLMCallInfo {
|
|
1036
|
+
/** Iteration number within the subagent loop */
|
|
1037
|
+
iteration: number;
|
|
1038
|
+
/** Model identifier (e.g., "sonnet", "gpt-4o") */
|
|
1039
|
+
model: string;
|
|
1040
|
+
/** Input tokens sent to the LLM */
|
|
1041
|
+
inputTokens?: number;
|
|
1042
|
+
/** Output tokens received from the LLM */
|
|
1043
|
+
outputTokens?: number;
|
|
1044
|
+
/** Reason the LLM stopped generating (e.g., "stop", "tool_use") */
|
|
1045
|
+
finishReason?: string;
|
|
1046
|
+
/** Elapsed time in milliseconds */
|
|
1047
|
+
elapsedMs?: number;
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Event emitted by subagent gadgets to report internal agent activity.
|
|
1051
|
+
* Enables real-time display of subagent LLM calls and gadget executions.
|
|
1052
|
+
*
|
|
1053
|
+
* @example
|
|
1054
|
+
* ```typescript
|
|
1055
|
+
* // Forwarding events from subagent to parent
|
|
1056
|
+
* for await (const event of subagent.run()) {
|
|
1057
|
+
* ctx.onSubagentEvent?.({
|
|
1058
|
+
* type: event.type === "gadget_call" ? "gadget_call" : "gadget_result",
|
|
1059
|
+
* gadgetInvocationId: parentInvocationId,
|
|
1060
|
+
* depth: 1,
|
|
1061
|
+
* event,
|
|
1062
|
+
* });
|
|
1063
|
+
* }
|
|
1064
|
+
* ```
|
|
1065
|
+
*/
|
|
1066
|
+
interface SubagentEvent {
|
|
1067
|
+
/** Type of subagent event */
|
|
1068
|
+
type: "llm_call_start" | "llm_call_end" | "gadget_call" | "gadget_result";
|
|
1069
|
+
/** Invocation ID of the parent gadget this subagent event belongs to */
|
|
1070
|
+
gadgetInvocationId: string;
|
|
1071
|
+
/** Nesting depth (1 = direct child, 2 = grandchild, etc.) */
|
|
1072
|
+
depth: number;
|
|
1073
|
+
/** The actual event data - either a StreamEvent or LLMCallInfo */
|
|
1074
|
+
event: StreamEvent | LLMCallInfo;
|
|
1075
|
+
}
|
|
1007
1076
|
|
|
1008
1077
|
type TextOnlyHandler = TextOnlyStrategy | TextOnlyGadgetConfig | TextOnlyCustomHandler;
|
|
1009
1078
|
/**
|
|
@@ -1314,6 +1383,39 @@ interface ExecutionContext {
|
|
|
1314
1383
|
* ```
|
|
1315
1384
|
*/
|
|
1316
1385
|
subagentConfig?: SubagentConfigMap;
|
|
1386
|
+
/**
|
|
1387
|
+
* Unique invocation ID for this gadget execution.
|
|
1388
|
+
* Used by `withParentContext()` to identify which parent gadget
|
|
1389
|
+
* nested events belong to.
|
|
1390
|
+
*/
|
|
1391
|
+
invocationId?: string;
|
|
1392
|
+
/**
|
|
1393
|
+
* Callback for subagent gadgets to report internal events to the parent.
|
|
1394
|
+
*
|
|
1395
|
+
* When provided, subagent gadgets (like BrowseWeb) can use this callback
|
|
1396
|
+
* to report their internal LLM calls and gadget executions in real-time.
|
|
1397
|
+
* This enables the parent agent to display subagent progress indicators.
|
|
1398
|
+
*
|
|
1399
|
+
* **Recommended:** Use `builder.withParentContext(ctx)` instead of calling
|
|
1400
|
+
* this directly - it handles all the forwarding automatically.
|
|
1401
|
+
*
|
|
1402
|
+
* @example
|
|
1403
|
+
* ```typescript
|
|
1404
|
+
* // In a subagent gadget like BrowseWeb - just ONE LINE needed:
|
|
1405
|
+
* execute: async (params, ctx) => {
|
|
1406
|
+
* const agent = new AgentBuilder(client)
|
|
1407
|
+
* .withModel(model)
|
|
1408
|
+
* .withGadgets(Navigate, Click)
|
|
1409
|
+
* .withParentContext(ctx) // <-- Enables automatic event forwarding!
|
|
1410
|
+
* .ask(task);
|
|
1411
|
+
*
|
|
1412
|
+
* for await (const event of agent.run()) {
|
|
1413
|
+
* // Events automatically forwarded - just process normally
|
|
1414
|
+
* }
|
|
1415
|
+
* }
|
|
1416
|
+
* ```
|
|
1417
|
+
*/
|
|
1418
|
+
onSubagentEvent?: (event: SubagentEvent) => void;
|
|
1317
1419
|
}
|
|
1318
1420
|
/**
|
|
1319
1421
|
* Parent agent configuration passed to gadgets.
|
|
@@ -2940,6 +3042,34 @@ declare function collectText(agentGenerator: AsyncGenerator<StreamEvent>): Promi
|
|
|
2940
3042
|
* @module agent/hooks
|
|
2941
3043
|
*/
|
|
2942
3044
|
|
|
3045
|
+
/**
|
|
3046
|
+
* Metadata present when an event originates from a subagent.
|
|
3047
|
+
* Undefined for top-level agent events.
|
|
3048
|
+
*
|
|
3049
|
+
* When using subagent gadgets (like BrowseWeb), hook observers receive events
|
|
3050
|
+
* from both the main agent AND subagents. Check this context to distinguish.
|
|
3051
|
+
*
|
|
3052
|
+
* @example
|
|
3053
|
+
* ```typescript
|
|
3054
|
+
* observers: {
|
|
3055
|
+
* onLLMCallStart: (ctx) => {
|
|
3056
|
+
* if (ctx.subagentContext) {
|
|
3057
|
+
* // Event from a subagent
|
|
3058
|
+
* console.log(`↳ Subagent LLM (depth=${ctx.subagentContext.depth})`);
|
|
3059
|
+
* } else {
|
|
3060
|
+
* // Event from the main agent
|
|
3061
|
+
* console.log('Main agent LLM call');
|
|
3062
|
+
* }
|
|
3063
|
+
* }
|
|
3064
|
+
* }
|
|
3065
|
+
* ```
|
|
3066
|
+
*/
|
|
3067
|
+
interface SubagentContext {
|
|
3068
|
+
/** Invocation ID of the parent gadget that spawned this subagent */
|
|
3069
|
+
parentGadgetInvocationId: string;
|
|
3070
|
+
/** Nesting depth: 1 = direct child, 2 = grandchild, etc. */
|
|
3071
|
+
depth: number;
|
|
3072
|
+
}
|
|
2943
3073
|
/**
|
|
2944
3074
|
* Context provided when an LLM call starts.
|
|
2945
3075
|
* Read-only observation point.
|
|
@@ -2948,6 +3078,8 @@ interface ObserveLLMCallContext {
|
|
|
2948
3078
|
iteration: number;
|
|
2949
3079
|
options: Readonly<LLMGenerationOptions>;
|
|
2950
3080
|
logger: Logger<ILogObj>;
|
|
3081
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3082
|
+
subagentContext?: SubagentContext;
|
|
2951
3083
|
}
|
|
2952
3084
|
/**
|
|
2953
3085
|
* Context provided when an LLM call is ready to execute.
|
|
@@ -2960,6 +3092,8 @@ interface ObserveLLMCallReadyContext {
|
|
|
2960
3092
|
/** Final options after any controller modifications (e.g., trailing messages) */
|
|
2961
3093
|
options: Readonly<LLMGenerationOptions>;
|
|
2962
3094
|
logger: Logger<ILogObj>;
|
|
3095
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3096
|
+
subagentContext?: SubagentContext;
|
|
2963
3097
|
}
|
|
2964
3098
|
/**
|
|
2965
3099
|
* Context provided when an LLM call completes successfully.
|
|
@@ -2976,6 +3110,8 @@ interface ObserveLLMCompleteContext {
|
|
|
2976
3110
|
/** The final message that will be added to history (after interceptors) */
|
|
2977
3111
|
finalMessage: string;
|
|
2978
3112
|
logger: Logger<ILogObj>;
|
|
3113
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3114
|
+
subagentContext?: SubagentContext;
|
|
2979
3115
|
}
|
|
2980
3116
|
/**
|
|
2981
3117
|
* Context provided when an LLM call fails.
|
|
@@ -2988,6 +3124,8 @@ interface ObserveLLMErrorContext {
|
|
|
2988
3124
|
/** Whether the error was recovered by a controller */
|
|
2989
3125
|
recovered: boolean;
|
|
2990
3126
|
logger: Logger<ILogObj>;
|
|
3127
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3128
|
+
subagentContext?: SubagentContext;
|
|
2991
3129
|
}
|
|
2992
3130
|
/**
|
|
2993
3131
|
* Context provided when a gadget execution starts.
|
|
@@ -3000,6 +3138,8 @@ interface ObserveGadgetStartContext {
|
|
|
3000
3138
|
/** Parameters after controller modifications */
|
|
3001
3139
|
parameters: Readonly<Record<string, unknown>>;
|
|
3002
3140
|
logger: Logger<ILogObj>;
|
|
3141
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3142
|
+
subagentContext?: SubagentContext;
|
|
3003
3143
|
}
|
|
3004
3144
|
/**
|
|
3005
3145
|
* Context provided when a gadget execution completes.
|
|
@@ -3020,6 +3160,8 @@ interface ObserveGadgetCompleteContext {
|
|
|
3020
3160
|
/** Cost of gadget execution in USD. 0 if gadget didn't report cost. */
|
|
3021
3161
|
cost?: number;
|
|
3022
3162
|
logger: Logger<ILogObj>;
|
|
3163
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3164
|
+
subagentContext?: SubagentContext;
|
|
3023
3165
|
}
|
|
3024
3166
|
/**
|
|
3025
3167
|
* Context provided when a gadget is skipped due to a failed dependency.
|
|
@@ -3035,6 +3177,8 @@ interface ObserveGadgetSkippedContext {
|
|
|
3035
3177
|
/** The error message from the failed dependency */
|
|
3036
3178
|
failedDependencyError: string;
|
|
3037
3179
|
logger: Logger<ILogObj>;
|
|
3180
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3181
|
+
subagentContext?: SubagentContext;
|
|
3038
3182
|
}
|
|
3039
3183
|
/**
|
|
3040
3184
|
* Context provided for each stream chunk.
|
|
@@ -3049,6 +3193,8 @@ interface ObserveChunkContext {
|
|
|
3049
3193
|
/** Token usage if available (providers send usage at stream start/end) */
|
|
3050
3194
|
usage?: TokenUsage;
|
|
3051
3195
|
logger: Logger<ILogObj>;
|
|
3196
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3197
|
+
subagentContext?: SubagentContext;
|
|
3052
3198
|
}
|
|
3053
3199
|
/**
|
|
3054
3200
|
* Observers: Read-only hooks for side effects.
|
|
@@ -3091,6 +3237,8 @@ interface ObserveCompactionContext {
|
|
|
3091
3237
|
stats: CompactionStats;
|
|
3092
3238
|
/** Logger instance */
|
|
3093
3239
|
logger: Logger<ILogObj>;
|
|
3240
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3241
|
+
subagentContext?: SubagentContext;
|
|
3094
3242
|
}
|
|
3095
3243
|
/**
|
|
3096
3244
|
* Context provided when the agent is aborted via AbortSignal.
|
|
@@ -3103,6 +3251,8 @@ interface ObserveAbortContext {
|
|
|
3103
3251
|
reason?: unknown;
|
|
3104
3252
|
/** Logger instance */
|
|
3105
3253
|
logger: Logger<ILogObj>;
|
|
3254
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3255
|
+
subagentContext?: SubagentContext;
|
|
3106
3256
|
}
|
|
3107
3257
|
/**
|
|
3108
3258
|
* Context for chunk interception.
|
|
@@ -3475,6 +3625,8 @@ interface AgentOptions {
|
|
|
3475
3625
|
signal?: AbortSignal;
|
|
3476
3626
|
/** Subagent-specific configuration overrides (from CLI config) */
|
|
3477
3627
|
subagentConfig?: SubagentConfigMap;
|
|
3628
|
+
/** Callback for subagent gadgets to report subagent events to parent */
|
|
3629
|
+
onSubagentEvent?: (event: SubagentEvent) => void;
|
|
3478
3630
|
}
|
|
3479
3631
|
/**
|
|
3480
3632
|
* Agent: Lean orchestrator that delegates to StreamProcessor.
|
|
@@ -3519,11 +3671,19 @@ declare class Agent {
|
|
|
3519
3671
|
private readonly signal?;
|
|
3520
3672
|
private readonly agentContextConfig;
|
|
3521
3673
|
private readonly subagentConfig?;
|
|
3674
|
+
private readonly userSubagentEventCallback?;
|
|
3675
|
+
private readonly pendingSubagentEvents;
|
|
3676
|
+
private readonly onSubagentEvent;
|
|
3522
3677
|
/**
|
|
3523
3678
|
* Creates a new Agent instance.
|
|
3524
3679
|
* @internal This constructor is private. Use LLMist.createAgent() or AgentBuilder instead.
|
|
3525
3680
|
*/
|
|
3526
3681
|
constructor(key: typeof AGENT_INTERNAL_KEY, options: AgentOptions);
|
|
3682
|
+
/**
|
|
3683
|
+
* Flush pending subagent events as StreamEvents.
|
|
3684
|
+
* Called from run() to yield queued subagent events from subagent gadgets.
|
|
3685
|
+
*/
|
|
3686
|
+
private flushPendingSubagentEvents;
|
|
3527
3687
|
/**
|
|
3528
3688
|
* Get the gadget registry for this agent.
|
|
3529
3689
|
*
|
|
@@ -3729,6 +3889,8 @@ declare class AgentBuilder {
|
|
|
3729
3889
|
private signal?;
|
|
3730
3890
|
private trailingMessage?;
|
|
3731
3891
|
private subagentConfig?;
|
|
3892
|
+
private subagentEventCallback?;
|
|
3893
|
+
private parentContext?;
|
|
3732
3894
|
constructor(client?: LLMist);
|
|
3733
3895
|
/**
|
|
3734
3896
|
* Set the model to use.
|
|
@@ -4144,6 +4306,62 @@ declare class AgentBuilder {
|
|
|
4144
4306
|
* ```
|
|
4145
4307
|
*/
|
|
4146
4308
|
withSubagentConfig(config: SubagentConfigMap): this;
|
|
4309
|
+
/**
|
|
4310
|
+
* Set the callback for subagent events.
|
|
4311
|
+
*
|
|
4312
|
+
* Subagent gadgets (like BrowseWeb) can use ExecutionContext.onSubagentEvent
|
|
4313
|
+
* to report their internal LLM calls and gadget executions in real-time.
|
|
4314
|
+
* This callback receives those events, enabling hierarchical progress display.
|
|
4315
|
+
*
|
|
4316
|
+
* @param callback - Function to handle subagent events
|
|
4317
|
+
* @returns This builder for chaining
|
|
4318
|
+
*
|
|
4319
|
+
* @example
|
|
4320
|
+
* ```typescript
|
|
4321
|
+
* .withSubagentEventCallback((event) => {
|
|
4322
|
+
* if (event.type === "llm_call_start") {
|
|
4323
|
+
* console.log(` Subagent LLM #${event.event.iteration} starting...`);
|
|
4324
|
+
* } else if (event.type === "gadget_call") {
|
|
4325
|
+
* console.log(` ⏵ ${event.event.call.gadgetName}...`);
|
|
4326
|
+
* }
|
|
4327
|
+
* })
|
|
4328
|
+
* ```
|
|
4329
|
+
*/
|
|
4330
|
+
withSubagentEventCallback(callback: (event: SubagentEvent) => void): this;
|
|
4331
|
+
/**
|
|
4332
|
+
* Enable automatic subagent event forwarding to parent agent.
|
|
4333
|
+
*
|
|
4334
|
+
* When building a subagent inside a gadget, call this method to automatically
|
|
4335
|
+
* forward all LLM calls and gadget events to the parent agent. This enables
|
|
4336
|
+
* hierarchical progress display without any manual event handling.
|
|
4337
|
+
*
|
|
4338
|
+
* The method extracts `invocationId` and `onSubagentEvent` from the execution
|
|
4339
|
+
* context and sets up automatic forwarding via hooks and event wrapping.
|
|
4340
|
+
*
|
|
4341
|
+
* @param ctx - ExecutionContext passed to the gadget's execute() method
|
|
4342
|
+
* @param depth - Nesting depth (default: 1 for direct child)
|
|
4343
|
+
* @returns This builder for chaining
|
|
4344
|
+
*
|
|
4345
|
+
* @example
|
|
4346
|
+
* ```typescript
|
|
4347
|
+
* // In a subagent gadget like BrowseWeb - ONE LINE enables auto-forwarding:
|
|
4348
|
+
* execute: async (params, ctx) => {
|
|
4349
|
+
* const agent = new AgentBuilder(client)
|
|
4350
|
+
* .withModel(model)
|
|
4351
|
+
* .withGadgets(Navigate, Click, Screenshot)
|
|
4352
|
+
* .withParentContext(ctx) // <-- This is all you need!
|
|
4353
|
+
* .ask(params.task);
|
|
4354
|
+
*
|
|
4355
|
+
* for await (const event of agent.run()) {
|
|
4356
|
+
* // Events automatically forwarded - just process normally
|
|
4357
|
+
* if (event.type === "text") {
|
|
4358
|
+
* result = event.content;
|
|
4359
|
+
* }
|
|
4360
|
+
* }
|
|
4361
|
+
* }
|
|
4362
|
+
* ```
|
|
4363
|
+
*/
|
|
4364
|
+
withParentContext(ctx: ExecutionContext, depth?: number): this;
|
|
4147
4365
|
/**
|
|
4148
4366
|
* Add an ephemeral trailing message that appears at the end of each LLM request.
|
|
4149
4367
|
*
|
|
@@ -4193,7 +4411,9 @@ declare class AgentBuilder {
|
|
|
4193
4411
|
*/
|
|
4194
4412
|
withSyntheticGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): this;
|
|
4195
4413
|
/**
|
|
4196
|
-
* Compose the final hooks, including
|
|
4414
|
+
* Compose the final hooks, including:
|
|
4415
|
+
* - Trailing message injection (if configured)
|
|
4416
|
+
* - Subagent event forwarding for LLM calls (if parentContext is set)
|
|
4197
4417
|
*/
|
|
4198
4418
|
private composeHooks;
|
|
4199
4419
|
/**
|
|
@@ -5101,4 +5321,4 @@ declare function createTextMockStream(text: string, options?: {
|
|
|
5101
5321
|
usage?: MockResponse["usage"];
|
|
5102
5322
|
}): LLMStream;
|
|
5103
5323
|
|
|
5104
|
-
export { type
|
|
5324
|
+
export { type LLMGenerationOptions as $, AbstractGadget as A, type MessageContent as B, type CompactionConfig as C, GadgetRegistry as D, MediaStore as E, type AgentContextConfig as F, type GadgetMediaOutput as G, type HintTemplate as H, type IConversationManager as I, type SubagentConfigMap as J, type SubagentEvent as K, type LLMMessage as L, MockProviderAdapter as M, type ExecutionContext as N, type GadgetExecuteReturn as O, type GadgetExample as P, type ParsedGadgetCall as Q, type ResolvedCompactionConfig as R, type StreamEvent as S, type TokenUsage as T, type GadgetExecutionResult as U, type MediaKind as V, type MediaMetadata as W, type GadgetExecuteResultWithMedia as X, type ProviderAdapter as Y, type ModelDescriptor as Z, type ModelSpec as _, type LLMStream as a, isImagePart as a$, type ImageModelSpec as a0, type ImageGenerationOptions as a1, type ImageGenerationResult as a2, type SpeechModelSpec as a3, type SpeechGenerationOptions as a4, type SpeechGenerationResult as a5, type HistoryMessage as a6, type TrailingMessage as a7, type TrailingMessageContext as a8, AgentBuilder as a9, type ObserveLLMCallContext as aA, type ObserveLLMCompleteContext as aB, type ObserveLLMErrorContext as aC, type Observers as aD, type SubagentContext as aE, DEFAULT_COMPACTION_CONFIG as aF, DEFAULT_SUMMARIZATION_PROMPT as aG, type LLMistOptions as aH, type AudioContentPart as aI, type AudioMimeType as aJ, type AudioSource as aK, type ContentPart as aL, type ImageBase64Source as aM, type ImageContentPart as aN, type ImageMimeType as aO, type ImageSource as aP, type ImageUrlSource as aQ, type TextContentPart as aR, audioFromBase64 as aS, audioFromBuffer as aT, detectAudioMimeType as aU, detectImageMimeType as aV, imageFromBase64 as aW, imageFromBuffer as aX, imageFromUrl as aY, isAudioPart as aZ, isDataUrl as a_, type EventHandlers as aa, collectEvents as ab, collectText as ac, runWithHandlers as ad, type AfterGadgetExecutionAction as ae, type AfterGadgetExecutionControllerContext as af, type AfterLLMCallAction as ag, type AfterLLMCallControllerContext as ah, type AfterLLMErrorAction as ai, type AgentOptions as aj, type BeforeGadgetExecutionAction as ak, type BeforeLLMCallAction as al, type ChunkInterceptorContext as am, type Controllers as an, type GadgetExecutionControllerContext as ao, type GadgetParameterInterceptorContext as ap, type GadgetResultInterceptorContext as aq, type Interceptors as ar, type LLMCallControllerContext as as, type LLMErrorControllerContext as at, type MessageInterceptorContext as au, type MessageTurn as av, type ObserveChunkContext as aw, type ObserveCompactionContext as ax, type ObserveGadgetCompleteContext as ay, type ObserveGadgetStartContext as az, type LLMStreamChunk as b, isTextPart as b0, parseDataUrl as b1, text as b2, toBase64 as b3, type MessageRole as b4, extractMessageText as b5, LLMMessageBuilder as b6, normalizeMessageContent as b7, type CostEstimate as b8, type ModelFeatures as b9, type TextOnlyContext as bA, type TextOnlyCustomHandler as bB, type TextOnlyGadgetConfig as bC, type TextOnlyHandler as bD, type TextOnlyStrategy as bE, type ModelLimits as ba, type ModelPricing as bb, type VisionAnalyzeOptions as bc, type VisionAnalyzeResult as bd, type ProviderIdentifier as be, ModelIdentifierParser as bf, type HintContext as bg, type PromptContext as bh, type PromptTemplate as bi, type PromptTemplateConfig as bj, DEFAULT_HINTS as bk, DEFAULT_PROMPTS as bl, resolveHintTemplate as bm, resolvePromptTemplate as bn, resolveRulesTemplate as bo, type TextGenerationOptions as bp, complete as bq, stream as br, type GadgetClass as bs, type GadgetOrClass as bt, type CostReportingLLMist as bu, type GadgetExecuteResult as bv, type GadgetSkippedEvent as bw, type StoredMedia as bx, type SubagentStreamEvent as by, type TextOnlyAction as bz, createMockAdapter as c, MockBuilder as d, createMockClient as e, MockManager as f, getMockManager as g, createMockStream as h, createTextMockStream as i, type MockAudioData as j, type MockImageData as k, type MockMatcher as l, mockLLM as m, type MockMatcherContext as n, type MockOptions as o, type MockRegistration as p, type MockResponse as q, type MockStats as r, type AgentHooks as s, ModelRegistry as t, LLMist as u, type CompactionEvent as v, type CompactionStats as w, type CompactionStrategy as x, type CompactionContext as y, type CompactionResult as z };
|