llmist 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-67MMSOAT.js → chunk-JCFPJMRQ.js} +540 -51
- package/dist/chunk-JCFPJMRQ.js.map +1 -0
- package/dist/{chunk-NBPKLSXJ.js → chunk-LFI4WQVV.js} +2 -2
- package/dist/cli.cjs +741 -64
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +203 -15
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +539 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -5
- package/dist/index.d.ts +42 -5
- package/dist/index.js +2 -2
- package/dist/{mock-stream-COHw8h9b.d.cts → mock-stream-CTLm00_q.d.cts} +163 -3
- package/dist/{mock-stream-COHw8h9b.d.ts → mock-stream-CTLm00_q.d.ts} +163 -3
- package/dist/testing/index.cjs +539 -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 → chunk-LFI4WQVV.js.map} +0 -0
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, K as ExecutionContext,
|
|
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, N as NestedAgentEvent, b as LLMStreamChunk, K 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-CTLm00_q.cjs';
|
|
4
|
+
export { ae as AfterGadgetExecutionAction, af as AfterGadgetExecutionControllerContext, ag as AfterLLMCallAction, ah as AfterLLMCallControllerContext, ai as AfterLLMErrorAction, a9 as AgentBuilder, aj as AgentOptions, aH as AudioContentPart, aI as AudioMimeType, aJ as AudioSource, ak as BeforeGadgetExecutionAction, al as BeforeLLMCallAction, am as ChunkInterceptorContext, aK as ContentPart, an as Controllers, b7 as CostEstimate, bt as CostReportingLLMist, aE as DEFAULT_COMPACTION_CONFIG, bj as DEFAULT_HINTS, bk as DEFAULT_PROMPTS, aF as DEFAULT_SUMMARIZATION_PROMPT, aa as EventHandlers, br as GadgetClass, bu as GadgetExecuteResult, ao as GadgetExecutionControllerContext, bs as GadgetOrClass, ap as GadgetParameterInterceptorContext, aq as GadgetResultInterceptorContext, bv as GadgetSkippedEvent, bf as HintContext, a6 as HistoryMessage, aL as ImageBase64Source, aM as ImageContentPart, aN as ImageMimeType, aO as ImageSource, aP as ImageUrlSource, ar as Interceptors, as as LLMCallControllerContext, at as LLMErrorControllerContext, b5 as LLMMessageBuilder, aG as LLMistOptions, au as MessageInterceptorContext, b3 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, b8 as ModelFeatures, be as ModelIdentifierParser, b9 as ModelLimits, ba 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, bg as PromptContext, bh as PromptTemplate, bi as PromptTemplateConfig, bd as ProviderIdentifier, bw as StoredMedia, aQ as TextContentPart, bo as TextGenerationOptions, bx as TextOnlyAction, by as TextOnlyContext, bz as TextOnlyCustomHandler, bA as TextOnlyGadgetConfig, bB as TextOnlyHandler, bC as TextOnlyStrategy, a7 as TrailingMessage, a8 as TrailingMessageContext, bb as VisionAnalyzeOptions, bc as VisionAnalyzeResult, aR as audioFromBase64, aS as audioFromBuffer, ab as collectEvents, ac as collectText, bp as complete, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, aT as detectAudioMimeType, aU as detectImageMimeType, b4 as extractMessageText, g as getMockManager, aV as imageFromBase64, aW as imageFromBuffer, aX as imageFromUrl, aY as isAudioPart, aZ as isDataUrl, a_ as isImagePart, a$ as isTextPart, m as mockLLM, b6 as normalizeMessageContent, b0 as parseDataUrl, bl as resolveHintTemplate, bm as resolvePromptTemplate, bn as resolveRulesTemplate, ad as runWithHandlers, bq as stream, b1 as text, b2 as toBase64 } from './mock-stream-CTLm00_q.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 nested events to parent */
|
|
1203
|
+
onNestedEvent?: (event: NestedAgentEvent) => 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 onNestedEvent?;
|
|
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, onNestedEvent?: ((event: NestedAgentEvent) => 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.
|
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, K as ExecutionContext,
|
|
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, N as NestedAgentEvent, b as LLMStreamChunk, K 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-CTLm00_q.js';
|
|
4
|
+
export { ae as AfterGadgetExecutionAction, af as AfterGadgetExecutionControllerContext, ag as AfterLLMCallAction, ah as AfterLLMCallControllerContext, ai as AfterLLMErrorAction, a9 as AgentBuilder, aj as AgentOptions, aH as AudioContentPart, aI as AudioMimeType, aJ as AudioSource, ak as BeforeGadgetExecutionAction, al as BeforeLLMCallAction, am as ChunkInterceptorContext, aK as ContentPart, an as Controllers, b7 as CostEstimate, bt as CostReportingLLMist, aE as DEFAULT_COMPACTION_CONFIG, bj as DEFAULT_HINTS, bk as DEFAULT_PROMPTS, aF as DEFAULT_SUMMARIZATION_PROMPT, aa as EventHandlers, br as GadgetClass, bu as GadgetExecuteResult, ao as GadgetExecutionControllerContext, bs as GadgetOrClass, ap as GadgetParameterInterceptorContext, aq as GadgetResultInterceptorContext, bv as GadgetSkippedEvent, bf as HintContext, a6 as HistoryMessage, aL as ImageBase64Source, aM as ImageContentPart, aN as ImageMimeType, aO as ImageSource, aP as ImageUrlSource, ar as Interceptors, as as LLMCallControllerContext, at as LLMErrorControllerContext, b5 as LLMMessageBuilder, aG as LLMistOptions, au as MessageInterceptorContext, b3 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, b8 as ModelFeatures, be as ModelIdentifierParser, b9 as ModelLimits, ba 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, bg as PromptContext, bh as PromptTemplate, bi as PromptTemplateConfig, bd as ProviderIdentifier, bw as StoredMedia, aQ as TextContentPart, bo as TextGenerationOptions, bx as TextOnlyAction, by as TextOnlyContext, bz as TextOnlyCustomHandler, bA as TextOnlyGadgetConfig, bB as TextOnlyHandler, bC as TextOnlyStrategy, a7 as TrailingMessage, a8 as TrailingMessageContext, bb as VisionAnalyzeOptions, bc as VisionAnalyzeResult, aR as audioFromBase64, aS as audioFromBuffer, ab as collectEvents, ac as collectText, bp as complete, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, aT as detectAudioMimeType, aU as detectImageMimeType, b4 as extractMessageText, g as getMockManager, aV as imageFromBase64, aW as imageFromBuffer, aX as imageFromUrl, aY as isAudioPart, aZ as isDataUrl, a_ as isImagePart, a$ as isTextPart, m as mockLLM, b6 as normalizeMessageContent, b0 as parseDataUrl, bl as resolveHintTemplate, bm as resolvePromptTemplate, bn as resolveRulesTemplate, ad as runWithHandlers, bq as stream, b1 as text, b2 as toBase64 } from './mock-stream-CTLm00_q.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 nested events to parent */
|
|
1203
|
+
onNestedEvent?: (event: NestedAgentEvent) => 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 onNestedEvent?;
|
|
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, onNestedEvent?: ((event: NestedAgentEvent) => 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.
|
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-LFI4WQVV.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-JCFPJMRQ.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,52 @@ type StreamEvent = {
|
|
|
1003
1022
|
} | {
|
|
1004
1023
|
type: "compaction";
|
|
1005
1024
|
event: CompactionEvent;
|
|
1006
|
-
};
|
|
1025
|
+
} | StreamCompletionEvent;
|
|
1026
|
+
/**
|
|
1027
|
+
* Information about an LLM call within a nested subagent.
|
|
1028
|
+
* Used by parent agents to display real-time progress of subagent LLM calls.
|
|
1029
|
+
*/
|
|
1030
|
+
interface LLMCallInfo {
|
|
1031
|
+
/** Iteration number within the subagent loop */
|
|
1032
|
+
iteration: number;
|
|
1033
|
+
/** Model identifier (e.g., "sonnet", "gpt-4o") */
|
|
1034
|
+
model: string;
|
|
1035
|
+
/** Input tokens sent to the LLM */
|
|
1036
|
+
inputTokens?: number;
|
|
1037
|
+
/** Output tokens received from the LLM */
|
|
1038
|
+
outputTokens?: number;
|
|
1039
|
+
/** Reason the LLM stopped generating (e.g., "stop", "tool_use") */
|
|
1040
|
+
finishReason?: string;
|
|
1041
|
+
/** Elapsed time in milliseconds */
|
|
1042
|
+
elapsedMs?: number;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Event emitted by subagent gadgets to report internal agent activity.
|
|
1046
|
+
* Enables real-time display of nested LLM calls and gadget executions.
|
|
1047
|
+
*
|
|
1048
|
+
* @example
|
|
1049
|
+
* ```typescript
|
|
1050
|
+
* // Forwarding events from subagent to parent
|
|
1051
|
+
* for await (const event of subagent.run()) {
|
|
1052
|
+
* ctx.onNestedEvent?.({
|
|
1053
|
+
* type: event.type === "gadget_call" ? "gadget_call" : "gadget_result",
|
|
1054
|
+
* gadgetInvocationId: parentInvocationId,
|
|
1055
|
+
* depth: 1,
|
|
1056
|
+
* event,
|
|
1057
|
+
* });
|
|
1058
|
+
* }
|
|
1059
|
+
* ```
|
|
1060
|
+
*/
|
|
1061
|
+
interface NestedAgentEvent {
|
|
1062
|
+
/** Type of nested event */
|
|
1063
|
+
type: "llm_call_start" | "llm_call_end" | "gadget_call" | "gadget_result";
|
|
1064
|
+
/** Invocation ID of the parent gadget this nested event belongs to */
|
|
1065
|
+
gadgetInvocationId: string;
|
|
1066
|
+
/** Nesting depth (1 = direct child, 2 = grandchild, etc.) */
|
|
1067
|
+
depth: number;
|
|
1068
|
+
/** The actual event data - either a StreamEvent or LLMCallInfo */
|
|
1069
|
+
event: StreamEvent | LLMCallInfo;
|
|
1070
|
+
}
|
|
1007
1071
|
|
|
1008
1072
|
type TextOnlyHandler = TextOnlyStrategy | TextOnlyGadgetConfig | TextOnlyCustomHandler;
|
|
1009
1073
|
/**
|
|
@@ -1314,6 +1378,39 @@ interface ExecutionContext {
|
|
|
1314
1378
|
* ```
|
|
1315
1379
|
*/
|
|
1316
1380
|
subagentConfig?: SubagentConfigMap;
|
|
1381
|
+
/**
|
|
1382
|
+
* Unique invocation ID for this gadget execution.
|
|
1383
|
+
* Used by `withParentContext()` to identify which parent gadget
|
|
1384
|
+
* nested events belong to.
|
|
1385
|
+
*/
|
|
1386
|
+
invocationId?: string;
|
|
1387
|
+
/**
|
|
1388
|
+
* Callback for subagent gadgets to report internal events to the parent.
|
|
1389
|
+
*
|
|
1390
|
+
* When provided, subagent gadgets (like BrowseWeb) can use this callback
|
|
1391
|
+
* to report their internal LLM calls and gadget executions in real-time.
|
|
1392
|
+
* This enables the parent agent to display nested progress indicators.
|
|
1393
|
+
*
|
|
1394
|
+
* **Recommended:** Use `builder.withParentContext(ctx)` instead of calling
|
|
1395
|
+
* this directly - it handles all the forwarding automatically.
|
|
1396
|
+
*
|
|
1397
|
+
* @example
|
|
1398
|
+
* ```typescript
|
|
1399
|
+
* // In a subagent gadget like BrowseWeb - just ONE LINE needed:
|
|
1400
|
+
* execute: async (params, ctx) => {
|
|
1401
|
+
* const agent = new AgentBuilder(client)
|
|
1402
|
+
* .withModel(model)
|
|
1403
|
+
* .withGadgets(Navigate, Click)
|
|
1404
|
+
* .withParentContext(ctx) // <-- Enables automatic event forwarding!
|
|
1405
|
+
* .ask(task);
|
|
1406
|
+
*
|
|
1407
|
+
* for await (const event of agent.run()) {
|
|
1408
|
+
* // Events automatically forwarded - just process normally
|
|
1409
|
+
* }
|
|
1410
|
+
* }
|
|
1411
|
+
* ```
|
|
1412
|
+
*/
|
|
1413
|
+
onNestedEvent?: (event: NestedAgentEvent) => void;
|
|
1317
1414
|
}
|
|
1318
1415
|
/**
|
|
1319
1416
|
* Parent agent configuration passed to gadgets.
|
|
@@ -3475,6 +3572,8 @@ interface AgentOptions {
|
|
|
3475
3572
|
signal?: AbortSignal;
|
|
3476
3573
|
/** Subagent-specific configuration overrides (from CLI config) */
|
|
3477
3574
|
subagentConfig?: SubagentConfigMap;
|
|
3575
|
+
/** Callback for subagent gadgets to report nested events to parent */
|
|
3576
|
+
onNestedEvent?: (event: NestedAgentEvent) => void;
|
|
3478
3577
|
}
|
|
3479
3578
|
/**
|
|
3480
3579
|
* Agent: Lean orchestrator that delegates to StreamProcessor.
|
|
@@ -3519,6 +3618,7 @@ declare class Agent {
|
|
|
3519
3618
|
private readonly signal?;
|
|
3520
3619
|
private readonly agentContextConfig;
|
|
3521
3620
|
private readonly subagentConfig?;
|
|
3621
|
+
private readonly onNestedEvent?;
|
|
3522
3622
|
/**
|
|
3523
3623
|
* Creates a new Agent instance.
|
|
3524
3624
|
* @internal This constructor is private. Use LLMist.createAgent() or AgentBuilder instead.
|
|
@@ -3729,6 +3829,8 @@ declare class AgentBuilder {
|
|
|
3729
3829
|
private signal?;
|
|
3730
3830
|
private trailingMessage?;
|
|
3731
3831
|
private subagentConfig?;
|
|
3832
|
+
private nestedEventCallback?;
|
|
3833
|
+
private parentContext?;
|
|
3732
3834
|
constructor(client?: LLMist);
|
|
3733
3835
|
/**
|
|
3734
3836
|
* Set the model to use.
|
|
@@ -4144,6 +4246,62 @@ declare class AgentBuilder {
|
|
|
4144
4246
|
* ```
|
|
4145
4247
|
*/
|
|
4146
4248
|
withSubagentConfig(config: SubagentConfigMap): this;
|
|
4249
|
+
/**
|
|
4250
|
+
* Set the callback for nested subagent events.
|
|
4251
|
+
*
|
|
4252
|
+
* Subagent gadgets (like BrowseWeb) can use ExecutionContext.onNestedEvent
|
|
4253
|
+
* to report their internal LLM calls and gadget executions in real-time.
|
|
4254
|
+
* This callback receives those events, enabling hierarchical progress display.
|
|
4255
|
+
*
|
|
4256
|
+
* @param callback - Function to handle nested agent events
|
|
4257
|
+
* @returns This builder for chaining
|
|
4258
|
+
*
|
|
4259
|
+
* @example
|
|
4260
|
+
* ```typescript
|
|
4261
|
+
* .withNestedEventCallback((event) => {
|
|
4262
|
+
* if (event.type === "llm_call_start") {
|
|
4263
|
+
* console.log(` Nested LLM #${event.event.iteration} starting...`);
|
|
4264
|
+
* } else if (event.type === "gadget_call") {
|
|
4265
|
+
* console.log(` ⏵ ${event.event.call.gadgetName}...`);
|
|
4266
|
+
* }
|
|
4267
|
+
* })
|
|
4268
|
+
* ```
|
|
4269
|
+
*/
|
|
4270
|
+
withNestedEventCallback(callback: (event: NestedAgentEvent) => void): this;
|
|
4271
|
+
/**
|
|
4272
|
+
* Enable automatic nested event forwarding to parent agent.
|
|
4273
|
+
*
|
|
4274
|
+
* When building a subagent inside a gadget, call this method to automatically
|
|
4275
|
+
* forward all LLM calls and gadget events to the parent agent. This enables
|
|
4276
|
+
* hierarchical progress display without any manual event handling.
|
|
4277
|
+
*
|
|
4278
|
+
* The method extracts `invocationId` and `onNestedEvent` from the execution
|
|
4279
|
+
* context and sets up automatic forwarding via hooks and event wrapping.
|
|
4280
|
+
*
|
|
4281
|
+
* @param ctx - ExecutionContext passed to the gadget's execute() method
|
|
4282
|
+
* @param depth - Nesting depth (default: 1 for direct child)
|
|
4283
|
+
* @returns This builder for chaining
|
|
4284
|
+
*
|
|
4285
|
+
* @example
|
|
4286
|
+
* ```typescript
|
|
4287
|
+
* // In a subagent gadget like BrowseWeb - ONE LINE enables auto-forwarding:
|
|
4288
|
+
* execute: async (params, ctx) => {
|
|
4289
|
+
* const agent = new AgentBuilder(client)
|
|
4290
|
+
* .withModel(model)
|
|
4291
|
+
* .withGadgets(Navigate, Click, Screenshot)
|
|
4292
|
+
* .withParentContext(ctx) // <-- This is all you need!
|
|
4293
|
+
* .ask(params.task);
|
|
4294
|
+
*
|
|
4295
|
+
* for await (const event of agent.run()) {
|
|
4296
|
+
* // Events automatically forwarded - just process normally
|
|
4297
|
+
* if (event.type === "text") {
|
|
4298
|
+
* result = event.content;
|
|
4299
|
+
* }
|
|
4300
|
+
* }
|
|
4301
|
+
* }
|
|
4302
|
+
* ```
|
|
4303
|
+
*/
|
|
4304
|
+
withParentContext(ctx: ExecutionContext, depth?: number): this;
|
|
4147
4305
|
/**
|
|
4148
4306
|
* Add an ephemeral trailing message that appears at the end of each LLM request.
|
|
4149
4307
|
*
|
|
@@ -4193,7 +4351,9 @@ declare class AgentBuilder {
|
|
|
4193
4351
|
*/
|
|
4194
4352
|
withSyntheticGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): this;
|
|
4195
4353
|
/**
|
|
4196
|
-
* Compose the final hooks, including
|
|
4354
|
+
* Compose the final hooks, including:
|
|
4355
|
+
* - Trailing message injection (if configured)
|
|
4356
|
+
* - Nested event forwarding for LLM calls (if parentContext is set)
|
|
4197
4357
|
*/
|
|
4198
4358
|
private composeHooks;
|
|
4199
4359
|
/**
|
|
@@ -5101,4 +5261,4 @@ declare function createTextMockStream(text: string, options?: {
|
|
|
5101
5261
|
usage?: MockResponse["usage"];
|
|
5102
5262
|
}): LLMStream;
|
|
5103
5263
|
|
|
5104
|
-
export { type
|
|
5264
|
+
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 ExecutionContext as K, type LLMMessage as L, MockProviderAdapter as M, type NestedAgentEvent 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, isTextPart 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, DEFAULT_COMPACTION_CONFIG as aE, DEFAULT_SUMMARIZATION_PROMPT as aF, type LLMistOptions as aG, type AudioContentPart as aH, type AudioMimeType as aI, type AudioSource as aJ, type ContentPart as aK, type ImageBase64Source as aL, type ImageContentPart as aM, type ImageMimeType as aN, type ImageSource as aO, type ImageUrlSource as aP, type TextContentPart as aQ, audioFromBase64 as aR, audioFromBuffer as aS, detectAudioMimeType as aT, detectImageMimeType as aU, imageFromBase64 as aV, imageFromBuffer as aW, imageFromUrl as aX, isAudioPart as aY, isDataUrl as aZ, isImagePart 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, parseDataUrl as b0, text as b1, toBase64 as b2, type MessageRole as b3, extractMessageText as b4, LLMMessageBuilder as b5, normalizeMessageContent as b6, type CostEstimate as b7, type ModelFeatures as b8, type ModelLimits as b9, type TextOnlyGadgetConfig as bA, type TextOnlyHandler as bB, type TextOnlyStrategy as bC, type ModelPricing as ba, type VisionAnalyzeOptions as bb, type VisionAnalyzeResult as bc, type ProviderIdentifier as bd, ModelIdentifierParser as be, type HintContext as bf, type PromptContext as bg, type PromptTemplate as bh, type PromptTemplateConfig as bi, DEFAULT_HINTS as bj, DEFAULT_PROMPTS as bk, resolveHintTemplate as bl, resolvePromptTemplate as bm, resolveRulesTemplate as bn, type TextGenerationOptions as bo, complete as bp, stream as bq, type GadgetClass as br, type GadgetOrClass as bs, type CostReportingLLMist as bt, type GadgetExecuteResult as bu, type GadgetSkippedEvent as bv, type StoredMedia as bw, type TextOnlyAction as bx, type TextOnlyContext as by, type TextOnlyCustomHandler 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 };
|