llmist 6.0.0 → 6.2.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-EIE5VRSI.js → chunk-36YSBSGB.js} +967 -396
- package/dist/chunk-36YSBSGB.js.map +1 -0
- package/dist/{chunk-F62X5W2G.js → chunk-EJEP5MHQ.js} +108 -25
- package/dist/chunk-EJEP5MHQ.js.map +1 -0
- package/dist/cli.cjs +11874 -9401
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +3008 -1101
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +6589 -5923
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +184 -311
- package/dist/index.d.ts +184 -311
- package/dist/index.js +29 -3
- package/dist/{mock-stream-CAY53Q6u.d.cts → mock-stream-DG4wF-NH.d.cts} +1161 -161
- package/dist/{mock-stream-CAY53Q6u.d.ts → mock-stream-DG4wF-NH.d.ts} +1161 -161
- package/dist/testing/index.cjs +956 -389
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +3 -3
- package/dist/testing/index.d.ts +3 -3
- package/dist/testing/index.js +1 -1
- package/package.json +2 -1
- package/dist/chunk-EIE5VRSI.js.map +0 -1
- package/dist/chunk-F62X5W2G.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { 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, K as SubagentEvent,
|
|
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, N as ExecutionTree, O as NodeId, b as LLMStreamChunk, P as ParsedGadgetCall, Q as GadgetExecutionResult, A as AbstractGadget, U as MediaKind, V as MediaMetadata, W as GadgetExecuteResultWithMedia, X as ExecutionContext, 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, a6 as HostExports } from './mock-stream-DG4wF-NH.cjs';
|
|
4
|
+
export { aJ as AddGadgetParams, aK as AddLLMCallParams, af as AfterGadgetExecutionAction, ag as AfterGadgetExecutionControllerContext, ah as AfterLLMCallAction, ai as AfterLLMCallControllerContext, aj as AfterLLMErrorAction, aa as AgentBuilder, ak as AgentOptions, bg as AudioContentPart, bh as AudioMimeType, bi as AudioSource, aS as BaseExecutionEvent, al as BeforeGadgetExecutionAction, am as BeforeLLMCallAction, an as ChunkInterceptorContext, aL as CompleteGadgetParams, aM as CompleteLLMCallParams, bj as ContentPart, ao as Controllers, bI as CostEstimate, c6 as CostReportingLLMist, c0 as CreateGadgetConfig, aG as DEFAULT_COMPACTION_CONFIG, bU as DEFAULT_HINTS, bV as DEFAULT_PROMPTS, aH as DEFAULT_SUMMARIZATION_PROMPT, ab as EventHandlers, aU as ExecutionEvent, aV as ExecutionEventType, aN as ExecutionNode, aO as ExecutionNodeType, c5 as Gadget, aW as GadgetCallEvent, c2 as GadgetClass, aX as GadgetCompleteEvent, c4 as GadgetConfig, aY as GadgetErrorEvent, aZ as GadgetEvent, c7 as GadgetExample, c8 as GadgetExecuteResult, c9 as GadgetExecuteReturn, ap as GadgetExecutionControllerContext, aP as GadgetNode, c3 as GadgetOrClass, aq as GadgetParameterInterceptorContext, ar as GadgetResultInterceptorContext, ca as GadgetSkippedEvent, a$ as GadgetStartEvent, aQ as GadgetState, bQ as HintContext, a7 as HistoryMessage, b0 as HumanInputRequiredEvent, bk as ImageBase64Source, bl as ImageContentPart, bm as ImageMimeType, bn as ImageSource, bo as ImageUrlSource, as as Interceptors, b1 as LLMCallCompleteEvent, at as LLMCallControllerContext, b2 as LLMCallErrorEvent, aR as LLMCallNode, b3 as LLMCallStartEvent, b4 as LLMCallStreamEvent, au as LLMErrorControllerContext, b5 as LLMEvent, bG as LLMMessageBuilder, aI as LLMistOptions, av as MessageInterceptorContext, bE as MessageRole, aw 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, bJ as ModelFeatures, bP as ModelIdentifierParser, bK as ModelLimits, bL as ModelPricing, ax as ObserveChunkContext, ay as ObserveCompactionContext, az as ObserveGadgetCompleteContext, aA as ObserveGadgetStartContext, aB as ObserveLLMCallContext, aC as ObserveLLMCompleteContext, aD as ObserveLLMErrorContext, aE as Observers, bR as PromptContext, bS as PromptTemplate, bT as PromptTemplateConfig, bO as ProviderIdentifier, cb as StoredMedia, b6 as StreamCompleteEvent, aF as SubagentContext, cc as SubagentStreamEvent, bp as TextContentPart, b7 as TextEvent, bZ as TextGenerationOptions, cd as TextOnlyAction, ce as TextOnlyContext, cf as TextOnlyCustomHandler, cg as TextOnlyGadgetConfig, ch as TextOnlyHandler, ci as TextOnlyStrategy, a8 as TrailingMessage, a9 as TrailingMessageContext, aT as TreeCompactionEvent, a_ as TreeGadgetSkippedEvent, bM as VisionAnalyzeOptions, bN as VisionAnalyzeResult, bq as audioFromBase64, br as audioFromBuffer, ac as collectEvents, ad as collectText, b_ as complete, c1 as createGadget, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, bs as detectAudioMimeType, bt as detectImageMimeType, bF as extractMessageText, b8 as filterByDepth, b9 as filterByParent, ba as filterRootEvents, g as getMockManager, bb as groupByParent, bu as imageFromBase64, bv as imageFromBuffer, bw as imageFromUrl, bx as isAudioPart, by as isDataUrl, bc as isGadgetEvent, bz as isImagePart, bd as isLLMEvent, be as isRootEvent, bf as isSubagentEvent, bA as isTextPart, m as mockLLM, bH as normalizeMessageContent, bB as parseDataUrl, bW as resolveHintTemplate, bX as resolvePromptTemplate, bY as resolveRulesTemplate, ae as runWithHandlers, b$ as stream, bC as text, bD as toBase64 } from './mock-stream-DG4wF-NH.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';
|
|
@@ -888,7 +888,7 @@ declare class ConversationManager implements IConversationManager {
|
|
|
888
888
|
constructor(baseMessages: LLMMessage[], initialMessages: LLMMessage[], options?: ConversationManagerOptions);
|
|
889
889
|
addUserMessage(content: MessageContent): void;
|
|
890
890
|
addAssistantMessage(content: string): void;
|
|
891
|
-
addGadgetCallResult(gadgetName: string, parameters: Record<string, unknown>, result: string, media?: GadgetMediaOutput[], mediaIds?: string[]): void;
|
|
891
|
+
addGadgetCallResult(gadgetName: string, parameters: Record<string, unknown>, result: string, invocationId: string, media?: GadgetMediaOutput[], mediaIds?: string[]): void;
|
|
892
892
|
getMessages(): LLMMessage[];
|
|
893
893
|
getHistoryMessages(): LLMMessage[];
|
|
894
894
|
getBaseMessages(): LLMMessage[];
|
|
@@ -1180,15 +1180,6 @@ interface StreamProcessorOptions {
|
|
|
1180
1180
|
logger?: Logger<ILogObj>;
|
|
1181
1181
|
/** Callback for requesting human input during execution */
|
|
1182
1182
|
requestHumanInput?: (question: string) => Promise<string>;
|
|
1183
|
-
/** Whether to stop on gadget errors */
|
|
1184
|
-
stopOnGadgetError?: boolean;
|
|
1185
|
-
/** Custom error recovery logic */
|
|
1186
|
-
canRecoverFromGadgetError?: (context: {
|
|
1187
|
-
error: string;
|
|
1188
|
-
gadgetName: string;
|
|
1189
|
-
errorType: "parse" | "validation" | "execution";
|
|
1190
|
-
parameters?: Record<string, unknown>;
|
|
1191
|
-
}) => boolean | Promise<boolean>;
|
|
1192
1183
|
/** Default gadget timeout */
|
|
1193
1184
|
defaultGadgetTimeoutMs?: number;
|
|
1194
1185
|
/** LLMist client for ExecutionContext.llmist */
|
|
@@ -1201,6 +1192,12 @@ interface StreamProcessorOptions {
|
|
|
1201
1192
|
subagentConfig?: SubagentConfigMap;
|
|
1202
1193
|
/** Callback for subagent gadgets to report subagent events to parent */
|
|
1203
1194
|
onSubagentEvent?: (event: SubagentEvent) => void;
|
|
1195
|
+
/** Execution tree for tracking LLM calls and gadget executions */
|
|
1196
|
+
tree?: ExecutionTree;
|
|
1197
|
+
/** Parent node ID (for gadget nodes created by this processor) */
|
|
1198
|
+
parentNodeId?: NodeId | null;
|
|
1199
|
+
/** Base depth for nodes created by this processor */
|
|
1200
|
+
baseDepth?: number;
|
|
1204
1201
|
}
|
|
1205
1202
|
/**
|
|
1206
1203
|
* Result of stream processing.
|
|
@@ -1250,10 +1247,10 @@ declare class StreamProcessor {
|
|
|
1250
1247
|
private readonly logger;
|
|
1251
1248
|
private readonly parser;
|
|
1252
1249
|
private readonly executor;
|
|
1253
|
-
private readonly
|
|
1254
|
-
private readonly
|
|
1250
|
+
private readonly tree?;
|
|
1251
|
+
private readonly parentNodeId;
|
|
1252
|
+
private readonly baseDepth;
|
|
1255
1253
|
private responseText;
|
|
1256
|
-
private executionHalted;
|
|
1257
1254
|
private observerFailureCount;
|
|
1258
1255
|
/** Gadgets waiting for their dependencies to complete */
|
|
1259
1256
|
private gadgetsAwaitingDependencies;
|
|
@@ -1263,6 +1260,8 @@ declare class StreamProcessor {
|
|
|
1263
1260
|
private failedInvocations;
|
|
1264
1261
|
/** Promises for independent gadgets currently executing (fire-and-forget) */
|
|
1265
1262
|
private inFlightExecutions;
|
|
1263
|
+
/** Queue of completed gadget results ready to be yielded (for real-time streaming) */
|
|
1264
|
+
private completedResultsQueue;
|
|
1266
1265
|
constructor(options: StreamProcessorOptions);
|
|
1267
1266
|
/**
|
|
1268
1267
|
* Process an LLM stream and yield events in real-time.
|
|
@@ -1275,14 +1274,8 @@ declare class StreamProcessor {
|
|
|
1275
1274
|
* The final event is always a StreamCompletionEvent containing metadata.
|
|
1276
1275
|
*/
|
|
1277
1276
|
process(stream: AsyncIterable<LLMStreamChunk>): AsyncGenerator<StreamEvent>;
|
|
1278
|
-
/**
|
|
1279
|
-
* Process a single parsed event (text or gadget call).
|
|
1280
|
-
* @deprecated Use processEventGenerator for real-time streaming
|
|
1281
|
-
*/
|
|
1282
|
-
private processEvent;
|
|
1283
1277
|
/**
|
|
1284
1278
|
* Process a single parsed event, yielding events in real-time.
|
|
1285
|
-
* Generator version of processEvent for streaming support.
|
|
1286
1279
|
*/
|
|
1287
1280
|
private processEventGenerator;
|
|
1288
1281
|
/**
|
|
@@ -1316,17 +1309,26 @@ declare class StreamProcessor {
|
|
|
1316
1309
|
*/
|
|
1317
1310
|
private executeGadgetGenerator;
|
|
1318
1311
|
/**
|
|
1319
|
-
* Execute a gadget and
|
|
1312
|
+
* Execute a gadget and push events to the completed results queue (non-blocking).
|
|
1320
1313
|
* Used for fire-and-forget parallel execution of independent gadgets.
|
|
1314
|
+
* Results are pushed to completedResultsQueue for real-time streaming to the caller.
|
|
1321
1315
|
*/
|
|
1322
1316
|
private executeGadgetAndCollect;
|
|
1323
1317
|
/**
|
|
1324
|
-
*
|
|
1325
|
-
*
|
|
1326
|
-
*
|
|
1327
|
-
|
|
1318
|
+
* Drain all completed results from the queue.
|
|
1319
|
+
* Used to yield results as they complete during stream processing.
|
|
1320
|
+
* @returns Generator that yields all events currently in the queue
|
|
1321
|
+
*/
|
|
1322
|
+
private drainCompletedResults;
|
|
1323
|
+
/**
|
|
1324
|
+
* Wait for all in-flight gadget executions to complete, yielding events in real-time.
|
|
1325
|
+
* Called at stream end to ensure all parallel executions finish.
|
|
1326
|
+
* Results and subagent events are pushed to completedResultsQueue during execution.
|
|
1327
|
+
* This generator yields queued events while polling, enabling real-time display
|
|
1328
|
+
* of subagent activity (LLM calls, nested gadgets) during long-running gadgets.
|
|
1329
|
+
* Clears the inFlightExecutions map after all gadgets complete.
|
|
1328
1330
|
*/
|
|
1329
|
-
private
|
|
1331
|
+
private waitForInFlightExecutions;
|
|
1330
1332
|
/**
|
|
1331
1333
|
* Handle a gadget that cannot execute because a dependency failed.
|
|
1332
1334
|
* Calls the onDependencySkipped controller to allow customization.
|
|
@@ -1355,22 +1357,6 @@ declare class StreamProcessor {
|
|
|
1355
1357
|
* All observers run concurrently and failures are tracked but don't crash.
|
|
1356
1358
|
*/
|
|
1357
1359
|
private runObserversInParallel;
|
|
1358
|
-
/**
|
|
1359
|
-
* Check if execution can recover from an error.
|
|
1360
|
-
*
|
|
1361
|
-
* Returns true if we should continue processing subsequent gadgets, false if we should stop.
|
|
1362
|
-
*
|
|
1363
|
-
* Logic:
|
|
1364
|
-
* - If custom canRecoverFromGadgetError is provided, use it
|
|
1365
|
-
* - Otherwise, use stopOnGadgetError config:
|
|
1366
|
-
* - stopOnGadgetError=true → return false (stop execution)
|
|
1367
|
-
* - stopOnGadgetError=false → return true (continue execution)
|
|
1368
|
-
*/
|
|
1369
|
-
private checkCanRecoverFromError;
|
|
1370
|
-
/**
|
|
1371
|
-
* Determine the type of error from a gadget execution.
|
|
1372
|
-
*/
|
|
1373
|
-
private determineErrorType;
|
|
1374
1360
|
}
|
|
1375
1361
|
|
|
1376
1362
|
/**
|
|
@@ -1487,116 +1473,6 @@ declare function getProvider(model: string): string | undefined;
|
|
|
1487
1473
|
*/
|
|
1488
1474
|
declare function getModelId(model: string): string;
|
|
1489
1475
|
|
|
1490
|
-
/**
|
|
1491
|
-
* Function-based gadget creation helper.
|
|
1492
|
-
*
|
|
1493
|
-
* For simple gadgets, use createGadget() instead of defining a class.
|
|
1494
|
-
* Parameters are automatically typed from the Zod schema.
|
|
1495
|
-
*
|
|
1496
|
-
* @example
|
|
1497
|
-
* ```typescript
|
|
1498
|
-
* const calculator = createGadget({
|
|
1499
|
-
* description: "Performs arithmetic operations",
|
|
1500
|
-
* schema: z.object({
|
|
1501
|
-
* operation: z.enum(["add", "subtract"]),
|
|
1502
|
-
* a: z.number(),
|
|
1503
|
-
* b: z.number(),
|
|
1504
|
-
* }),
|
|
1505
|
-
* execute: ({ operation, a, b }) => {
|
|
1506
|
-
* // Automatically typed!
|
|
1507
|
-
* return operation === "add" ? String(a + b) : String(a - b);
|
|
1508
|
-
* },
|
|
1509
|
-
* });
|
|
1510
|
-
* ```
|
|
1511
|
-
*/
|
|
1512
|
-
|
|
1513
|
-
/**
|
|
1514
|
-
* Infer the TypeScript type from a Zod schema.
|
|
1515
|
-
*/
|
|
1516
|
-
type InferSchema$1<T> = T extends ZodType<infer U> ? U : never;
|
|
1517
|
-
/**
|
|
1518
|
-
* Configuration for creating a function-based gadget.
|
|
1519
|
-
*/
|
|
1520
|
-
interface CreateGadgetConfig<TSchema extends ZodType> {
|
|
1521
|
-
/** Optional custom name (defaults to "FunctionGadget") */
|
|
1522
|
-
name?: string;
|
|
1523
|
-
/** Human-readable description of what the gadget does */
|
|
1524
|
-
description: string;
|
|
1525
|
-
/** Zod schema for parameter validation */
|
|
1526
|
-
schema: TSchema;
|
|
1527
|
-
/**
|
|
1528
|
-
* Execution function with typed parameters.
|
|
1529
|
-
* Can return string or { result, cost? }.
|
|
1530
|
-
* Optionally receives ExecutionContext for callback-based cost reporting.
|
|
1531
|
-
*/
|
|
1532
|
-
execute: (params: InferSchema$1<TSchema>, ctx?: ExecutionContext) => GadgetExecuteReturn | Promise<GadgetExecuteReturn>;
|
|
1533
|
-
/** Optional timeout in milliseconds */
|
|
1534
|
-
timeoutMs?: number;
|
|
1535
|
-
/** Optional usage examples to help LLMs understand proper invocation */
|
|
1536
|
-
examples?: GadgetExample<InferSchema$1<TSchema>>[];
|
|
1537
|
-
}
|
|
1538
|
-
/**
|
|
1539
|
-
* Creates a gadget from a function (simpler than class-based approach).
|
|
1540
|
-
*
|
|
1541
|
-
* This is perfect for simple gadgets where you don't need the full
|
|
1542
|
-
* power of a class. Parameters are automatically typed from the schema.
|
|
1543
|
-
*
|
|
1544
|
-
* @param config - Configuration with execute function and schema
|
|
1545
|
-
* @returns Gadget instance ready to be registered
|
|
1546
|
-
*
|
|
1547
|
-
* @example
|
|
1548
|
-
* ```typescript
|
|
1549
|
-
* import { z } from 'zod';
|
|
1550
|
-
* import { createGadget } from 'llmist';
|
|
1551
|
-
*
|
|
1552
|
-
* // Simple calculator gadget
|
|
1553
|
-
* const calculator = createGadget({
|
|
1554
|
-
* description: "Performs arithmetic operations",
|
|
1555
|
-
* schema: z.object({
|
|
1556
|
-
* operation: z.enum(["add", "subtract", "multiply", "divide"]),
|
|
1557
|
-
* a: z.number().describe("First number"),
|
|
1558
|
-
* b: z.number().describe("Second number"),
|
|
1559
|
-
* }),
|
|
1560
|
-
* execute: ({ operation, a, b }) => {
|
|
1561
|
-
* // Parameters are automatically typed!
|
|
1562
|
-
* switch (operation) {
|
|
1563
|
-
* case "add": return String(a + b);
|
|
1564
|
-
* case "subtract": return String(a - b);
|
|
1565
|
-
* case "multiply": return String(a * b);
|
|
1566
|
-
* case "divide": return String(a / b);
|
|
1567
|
-
* }
|
|
1568
|
-
* },
|
|
1569
|
-
* });
|
|
1570
|
-
* ```
|
|
1571
|
-
*
|
|
1572
|
-
* @example
|
|
1573
|
-
* ```typescript
|
|
1574
|
-
* // Async gadget with custom name and timeout
|
|
1575
|
-
* const weather = createGadget({
|
|
1576
|
-
* name: "weather",
|
|
1577
|
-
* description: "Fetches current weather for a city",
|
|
1578
|
-
* schema: z.object({
|
|
1579
|
-
* city: z.string().min(1).describe("City name"),
|
|
1580
|
-
* }),
|
|
1581
|
-
* timeoutMs: 10000,
|
|
1582
|
-
* execute: async ({ city }) => {
|
|
1583
|
-
* const response = await fetch(`https://api.weather.com/${city}`);
|
|
1584
|
-
* const data = await response.json();
|
|
1585
|
-
* return `Weather in ${city}: ${data.description}, ${data.temp}°C`;
|
|
1586
|
-
* },
|
|
1587
|
-
* });
|
|
1588
|
-
* ```
|
|
1589
|
-
*
|
|
1590
|
-
* @example
|
|
1591
|
-
* ```typescript
|
|
1592
|
-
* // Use with agent
|
|
1593
|
-
* const agent = LLMist.createAgent()
|
|
1594
|
-
* .withGadgets(calculator, weather)
|
|
1595
|
-
* .ask("What's the weather in Paris and what's 10 + 5?");
|
|
1596
|
-
* ```
|
|
1597
|
-
*/
|
|
1598
|
-
declare function createGadget<TSchema extends ZodType>(config: CreateGadgetConfig<TSchema>): AbstractGadget;
|
|
1599
|
-
|
|
1600
1476
|
/**
|
|
1601
1477
|
* Signal that a gadget throws to indicate task completion and agent termination.
|
|
1602
1478
|
*
|
|
@@ -1744,13 +1620,17 @@ declare class GadgetExecutor {
|
|
|
1744
1620
|
private readonly agentConfig?;
|
|
1745
1621
|
private readonly subagentConfig?;
|
|
1746
1622
|
private readonly onSubagentEvent?;
|
|
1623
|
+
private readonly tree?;
|
|
1624
|
+
private readonly parentNodeId?;
|
|
1625
|
+
private readonly baseDepth?;
|
|
1747
1626
|
private readonly logger;
|
|
1748
1627
|
private readonly errorFormatter;
|
|
1749
1628
|
private readonly argPrefix;
|
|
1750
|
-
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);
|
|
1629
|
+
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, tree?: ExecutionTree | undefined, parentNodeId?: (NodeId | null) | undefined, baseDepth?: number | undefined);
|
|
1751
1630
|
/**
|
|
1752
1631
|
* Creates a promise that rejects with a TimeoutException after the specified timeout.
|
|
1753
1632
|
* Aborts the provided AbortController before rejecting, allowing gadgets to clean up.
|
|
1633
|
+
* Returns both the promise and a cancel function to clear the timeout when no longer needed.
|
|
1754
1634
|
*/
|
|
1755
1635
|
private createTimeoutPromise;
|
|
1756
1636
|
/**
|
|
@@ -1835,161 +1715,6 @@ declare class GadgetCallParser {
|
|
|
1835
1715
|
reset(): void;
|
|
1836
1716
|
}
|
|
1837
1717
|
|
|
1838
|
-
/**
|
|
1839
|
-
* Type-safe gadget factory with automatic parameter inference.
|
|
1840
|
-
*
|
|
1841
|
-
* Gadget eliminates the need for manual type assertions
|
|
1842
|
-
* by automatically inferring parameter types from the Zod schema.
|
|
1843
|
-
*
|
|
1844
|
-
* @example
|
|
1845
|
-
* ```typescript
|
|
1846
|
-
* class Calculator extends Gadget({
|
|
1847
|
-
* description: "Performs arithmetic operations",
|
|
1848
|
-
* schema: z.object({
|
|
1849
|
-
* operation: z.enum(["add", "subtract"]),
|
|
1850
|
-
* a: z.number(),
|
|
1851
|
-
* b: z.number(),
|
|
1852
|
-
* }),
|
|
1853
|
-
* }) {
|
|
1854
|
-
* // ✨ params is automatically typed!
|
|
1855
|
-
* execute(params: this['params']): string {
|
|
1856
|
-
* const { operation, a, b } = params; // All typed!
|
|
1857
|
-
* return operation === "add" ? String(a + b) : String(a - b);
|
|
1858
|
-
* }
|
|
1859
|
-
* }
|
|
1860
|
-
* ```
|
|
1861
|
-
*/
|
|
1862
|
-
|
|
1863
|
-
/**
|
|
1864
|
-
* Infer the TypeScript type from a Zod schema.
|
|
1865
|
-
*/
|
|
1866
|
-
type InferSchema<T> = T extends ZodType<infer U> ? U : never;
|
|
1867
|
-
/**
|
|
1868
|
-
* Configuration for creating a typed gadget.
|
|
1869
|
-
*/
|
|
1870
|
-
interface GadgetConfig<TSchema extends ZodType> {
|
|
1871
|
-
/** Human-readable description of what the gadget does */
|
|
1872
|
-
description: string;
|
|
1873
|
-
/** Zod schema for parameter validation */
|
|
1874
|
-
schema: TSchema;
|
|
1875
|
-
/** Optional custom name (defaults to class name) */
|
|
1876
|
-
name?: string;
|
|
1877
|
-
/** Optional timeout in milliseconds */
|
|
1878
|
-
timeoutMs?: number;
|
|
1879
|
-
/** Optional usage examples to help LLMs understand proper invocation */
|
|
1880
|
-
examples?: GadgetExample<InferSchema<TSchema>>[];
|
|
1881
|
-
}
|
|
1882
|
-
/**
|
|
1883
|
-
* Factory function to create a typed gadget base class.
|
|
1884
|
-
*
|
|
1885
|
-
* The returned class automatically infers parameter types from the Zod schema,
|
|
1886
|
-
* eliminating the need for manual type assertions in the execute method.
|
|
1887
|
-
*
|
|
1888
|
-
* @param config - Configuration with description and schema
|
|
1889
|
-
* @returns Base class to extend with typed execute method
|
|
1890
|
-
*
|
|
1891
|
-
* @example
|
|
1892
|
-
* ```typescript
|
|
1893
|
-
* import { z } from 'zod';
|
|
1894
|
-
* import { Gadget } from 'llmist';
|
|
1895
|
-
*
|
|
1896
|
-
* class Calculator extends Gadget({
|
|
1897
|
-
* description: "Performs arithmetic operations",
|
|
1898
|
-
* schema: z.object({
|
|
1899
|
-
* operation: z.enum(["add", "subtract", "multiply", "divide"]),
|
|
1900
|
-
* a: z.number().describe("First number"),
|
|
1901
|
-
* b: z.number().describe("Second number"),
|
|
1902
|
-
* }),
|
|
1903
|
-
* }) {
|
|
1904
|
-
* execute(params: this['params']): string {
|
|
1905
|
-
* // params is automatically typed as:
|
|
1906
|
-
* // { operation: "add" | "subtract" | "multiply" | "divide"; a: number; b: number }
|
|
1907
|
-
* const { operation, a, b } = params;
|
|
1908
|
-
*
|
|
1909
|
-
* switch (operation) {
|
|
1910
|
-
* case "add": return String(a + b);
|
|
1911
|
-
* case "subtract": return String(a - b);
|
|
1912
|
-
* case "multiply": return String(a * b);
|
|
1913
|
-
* case "divide": return String(a / b);
|
|
1914
|
-
* }
|
|
1915
|
-
* }
|
|
1916
|
-
* }
|
|
1917
|
-
* ```
|
|
1918
|
-
*
|
|
1919
|
-
* @example
|
|
1920
|
-
* ```typescript
|
|
1921
|
-
* // With async execution
|
|
1922
|
-
* class WeatherGadget extends Gadget({
|
|
1923
|
-
* description: "Fetches weather for a city",
|
|
1924
|
-
* schema: z.object({
|
|
1925
|
-
* city: z.string().min(1).describe("City name"),
|
|
1926
|
-
* }),
|
|
1927
|
-
* timeoutMs: 10000,
|
|
1928
|
-
* }) {
|
|
1929
|
-
* async execute(params: this['params']): Promise<string> {
|
|
1930
|
-
* const { city } = params; // Automatically typed as { city: string }
|
|
1931
|
-
* const weather = await fetchWeather(city);
|
|
1932
|
-
* return `Weather in ${city}: ${weather}`;
|
|
1933
|
-
* }
|
|
1934
|
-
* }
|
|
1935
|
-
* ```
|
|
1936
|
-
*/
|
|
1937
|
-
declare function Gadget<TSchema extends ZodType>(config: GadgetConfig<TSchema>): {
|
|
1938
|
-
new (): {
|
|
1939
|
-
description: string;
|
|
1940
|
-
parameterSchema: TSchema;
|
|
1941
|
-
name: string | undefined;
|
|
1942
|
-
timeoutMs: number | undefined;
|
|
1943
|
-
examples: GadgetExample<InferSchema<TSchema>>[] | undefined;
|
|
1944
|
-
/**
|
|
1945
|
-
* Type helper property for accessing inferred parameter type.
|
|
1946
|
-
* This is used in the execute method signature: `execute(params: this['params'])`
|
|
1947
|
-
*
|
|
1948
|
-
* Note: This is just for type inference - the actual params in execute()
|
|
1949
|
-
* will be Record<string, unknown> which you can safely cast to this['params']
|
|
1950
|
-
*/
|
|
1951
|
-
readonly params: InferSchema<TSchema>;
|
|
1952
|
-
/**
|
|
1953
|
-
* Execute the gadget. Subclasses should cast params to this['params'].
|
|
1954
|
-
*
|
|
1955
|
-
* @param params - Validated parameters from the LLM
|
|
1956
|
-
* @param ctx - Optional execution context for cost reporting and LLM access
|
|
1957
|
-
* @returns Result as a string, or an object with result and optional cost
|
|
1958
|
-
*
|
|
1959
|
-
* @example
|
|
1960
|
-
* ```typescript
|
|
1961
|
-
* // Simple string return (free gadget)
|
|
1962
|
-
* execute(params: this['params']) {
|
|
1963
|
-
* return String(params.a + params.b);
|
|
1964
|
-
* }
|
|
1965
|
-
*
|
|
1966
|
-
* // Using context for callback-based cost reporting
|
|
1967
|
-
* execute(params: this['params'], ctx) {
|
|
1968
|
-
* ctx.reportCost(0.001);
|
|
1969
|
-
* return "result";
|
|
1970
|
-
* }
|
|
1971
|
-
*
|
|
1972
|
-
* // Using wrapped LLMist for automatic cost tracking
|
|
1973
|
-
* async execute(params: this['params'], ctx) {
|
|
1974
|
-
* return ctx.llmist.complete('Summarize: ' + params.text);
|
|
1975
|
-
* }
|
|
1976
|
-
* ```
|
|
1977
|
-
*/
|
|
1978
|
-
execute(params: Record<string, unknown>, ctx?: ExecutionContext): GadgetExecuteReturn | Promise<GadgetExecuteReturn>;
|
|
1979
|
-
throwIfAborted(ctx?: ExecutionContext): void;
|
|
1980
|
-
onAbort(ctx: ExecutionContext | undefined, cleanup: () => void | Promise<void>): void;
|
|
1981
|
-
createLinkedAbortController(ctx?: ExecutionContext): AbortController;
|
|
1982
|
-
get instruction(): string;
|
|
1983
|
-
getInstruction(optionsOrArgPrefix?: string | {
|
|
1984
|
-
argPrefix?: string;
|
|
1985
|
-
startPrefix?: string;
|
|
1986
|
-
endPrefix?: string;
|
|
1987
|
-
}): string;
|
|
1988
|
-
} & {
|
|
1989
|
-
params: InferSchema<TSchema>;
|
|
1990
|
-
};
|
|
1991
|
-
};
|
|
1992
|
-
|
|
1993
1718
|
/**
|
|
1994
1719
|
* Helper functions for gadget authors to easily return media outputs.
|
|
1995
1720
|
*
|
|
@@ -2334,6 +2059,115 @@ declare function createLogger(options?: LoggerOptions): Logger<ILogObj>;
|
|
|
2334
2059
|
*/
|
|
2335
2060
|
declare const defaultLogger: Logger<ILogObj>;
|
|
2336
2061
|
|
|
2062
|
+
/**
|
|
2063
|
+
* Config resolution utility for subagent gadgets.
|
|
2064
|
+
*
|
|
2065
|
+
* Simplifies the common pattern of resolving configuration from multiple sources:
|
|
2066
|
+
* 1. Runtime params (explicit gadget call parameters)
|
|
2067
|
+
* 2. Subagent config (from CLI [subagents.Name] sections)
|
|
2068
|
+
* 3. Parent agent config (model inheritance)
|
|
2069
|
+
* 4. Package defaults
|
|
2070
|
+
*
|
|
2071
|
+
* @module utils/config-resolver
|
|
2072
|
+
*/
|
|
2073
|
+
|
|
2074
|
+
/**
|
|
2075
|
+
* Options for resolving a single config value.
|
|
2076
|
+
*/
|
|
2077
|
+
interface ResolveValueOptions<T> {
|
|
2078
|
+
/** Runtime parameter value (highest priority) */
|
|
2079
|
+
runtime?: T;
|
|
2080
|
+
/** Subagent config key to check */
|
|
2081
|
+
subagentKey?: string;
|
|
2082
|
+
/** Parent config key to check (for inheritance) - "model" or "temperature" */
|
|
2083
|
+
parentKey?: "model" | "temperature";
|
|
2084
|
+
/** Default value (lowest priority) */
|
|
2085
|
+
defaultValue: T;
|
|
2086
|
+
/** Whether "inherit" string means use parent value */
|
|
2087
|
+
handleInherit?: boolean;
|
|
2088
|
+
}
|
|
2089
|
+
/**
|
|
2090
|
+
* Resolve a single configuration value through the priority chain.
|
|
2091
|
+
*
|
|
2092
|
+
* Priority (highest to lowest):
|
|
2093
|
+
* 1. Runtime parameter (if provided and not undefined)
|
|
2094
|
+
* 2. Subagent config (from ctx.subagentConfig[gadgetName][key])
|
|
2095
|
+
* 3. Parent config (from ctx.agentConfig[key], if parentKey specified)
|
|
2096
|
+
* 4. Default value
|
|
2097
|
+
*
|
|
2098
|
+
* Special handling for "inherit" string:
|
|
2099
|
+
* - If handleInherit is true and value is "inherit", falls through to parent/default
|
|
2100
|
+
*
|
|
2101
|
+
* @param ctx - ExecutionContext from gadget execution
|
|
2102
|
+
* @param gadgetName - Name of the subagent gadget (e.g., "BrowseWeb")
|
|
2103
|
+
* @param options - Resolution options
|
|
2104
|
+
* @returns Resolved value
|
|
2105
|
+
*
|
|
2106
|
+
* @example
|
|
2107
|
+
* ```typescript
|
|
2108
|
+
* const model = resolveValue(ctx, "BrowseWeb", {
|
|
2109
|
+
* runtime: params.model,
|
|
2110
|
+
* subagentKey: "model",
|
|
2111
|
+
* parentKey: "model",
|
|
2112
|
+
* defaultValue: "sonnet",
|
|
2113
|
+
* handleInherit: true,
|
|
2114
|
+
* });
|
|
2115
|
+
* ```
|
|
2116
|
+
*/
|
|
2117
|
+
declare function resolveValue<T>(ctx: ExecutionContext, gadgetName: string, options: ResolveValueOptions<T>): T;
|
|
2118
|
+
/**
|
|
2119
|
+
* Bulk configuration resolution for subagent gadgets.
|
|
2120
|
+
*
|
|
2121
|
+
* Takes a map of config keys to their resolution options and returns
|
|
2122
|
+
* a fully resolved configuration object.
|
|
2123
|
+
*
|
|
2124
|
+
* @param ctx - ExecutionContext from gadget execution
|
|
2125
|
+
* @param gadgetName - Name of the subagent gadget (e.g., "BrowseWeb")
|
|
2126
|
+
* @param config - Map of config keys to resolution options
|
|
2127
|
+
* @returns Fully resolved configuration object
|
|
2128
|
+
*
|
|
2129
|
+
* @example
|
|
2130
|
+
* ```typescript
|
|
2131
|
+
* // Before: 27 lines of manual fallback logic
|
|
2132
|
+
* const subagentConfig = ctx.subagentConfig?.Dhalsim ?? {};
|
|
2133
|
+
* const parentModel = ctx.agentConfig?.model;
|
|
2134
|
+
* const model = params.model ?? subagentConfig.model ?? parentModel ?? "sonnet";
|
|
2135
|
+
* const maxIterations = params.maxIterations ?? subagentConfig.maxIterations ?? 15;
|
|
2136
|
+
* const headless = params.headless ?? subagentConfig.headless ?? true;
|
|
2137
|
+
*
|
|
2138
|
+
* // After: One function call
|
|
2139
|
+
* const { model, maxIterations, headless } = resolveConfig(ctx, "BrowseWeb", {
|
|
2140
|
+
* model: { runtime: params.model, subagentKey: "model", parentKey: "model", defaultValue: "sonnet", handleInherit: true },
|
|
2141
|
+
* maxIterations: { runtime: params.maxIterations, subagentKey: "maxIterations", defaultValue: 15 },
|
|
2142
|
+
* headless: { runtime: params.headless, subagentKey: "headless", defaultValue: true },
|
|
2143
|
+
* });
|
|
2144
|
+
* ```
|
|
2145
|
+
*/
|
|
2146
|
+
declare function resolveConfig<T extends Record<string, unknown>>(ctx: ExecutionContext, gadgetName: string, config: {
|
|
2147
|
+
[K in keyof T]: ResolveValueOptions<T[K]>;
|
|
2148
|
+
}): T;
|
|
2149
|
+
/**
|
|
2150
|
+
* Convenience function for resolving subagent model with "inherit" support.
|
|
2151
|
+
*
|
|
2152
|
+
* This is the most common resolution pattern for subagent gadgets:
|
|
2153
|
+
* - Use runtime model if provided
|
|
2154
|
+
* - Check subagent config for model override
|
|
2155
|
+
* - Inherit parent model if configured
|
|
2156
|
+
* - Fall back to default
|
|
2157
|
+
*
|
|
2158
|
+
* @param ctx - ExecutionContext from gadget execution
|
|
2159
|
+
* @param gadgetName - Name of the subagent gadget
|
|
2160
|
+
* @param runtimeModel - Model from gadget parameters
|
|
2161
|
+
* @param defaultModel - Default model if nothing else specified
|
|
2162
|
+
* @returns Resolved model string
|
|
2163
|
+
*
|
|
2164
|
+
* @example
|
|
2165
|
+
* ```typescript
|
|
2166
|
+
* const model = resolveSubagentModel(ctx, "BrowseWeb", params.model, "sonnet");
|
|
2167
|
+
* ```
|
|
2168
|
+
*/
|
|
2169
|
+
declare function resolveSubagentModel(ctx: ExecutionContext, gadgetName: string, runtimeModel: string | undefined, defaultModel: string): string;
|
|
2170
|
+
|
|
2337
2171
|
/**
|
|
2338
2172
|
* Base Provider Adapter
|
|
2339
2173
|
*
|
|
@@ -2621,4 +2455,43 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
|
|
|
2621
2455
|
}
|
|
2622
2456
|
declare function createOpenAIProviderFromEnv(): OpenAIChatProvider | null;
|
|
2623
2457
|
|
|
2624
|
-
|
|
2458
|
+
/**
|
|
2459
|
+
* Get host llmist exports from execution context.
|
|
2460
|
+
*
|
|
2461
|
+
* External gadgets MUST use this instead of importing classes directly from 'llmist'
|
|
2462
|
+
* to ensure they use the same version as the host CLI, enabling proper tree sharing
|
|
2463
|
+
* and avoiding the "dual-package problem".
|
|
2464
|
+
*
|
|
2465
|
+
* @param ctx - The execution context passed to gadget.execute()
|
|
2466
|
+
* @returns The host's llmist exports (AgentBuilder, Gadget, etc.)
|
|
2467
|
+
* @throws Error if ctx or ctx.hostExports is undefined
|
|
2468
|
+
*
|
|
2469
|
+
* @example
|
|
2470
|
+
* ```typescript
|
|
2471
|
+
* import { getHostExports, Gadget, z } from 'llmist';
|
|
2472
|
+
* import type { ExecutionContext } from 'llmist';
|
|
2473
|
+
*
|
|
2474
|
+
* class BrowseWeb extends Gadget({
|
|
2475
|
+
* name: 'BrowseWeb',
|
|
2476
|
+
* description: 'Browse a website autonomously',
|
|
2477
|
+
* schema: z.object({ task: z.string(), url: z.string() }),
|
|
2478
|
+
* }) {
|
|
2479
|
+
* async execute(params: this['params'], ctx?: ExecutionContext) {
|
|
2480
|
+
* // Get host's AgentBuilder to ensure tree sharing works correctly
|
|
2481
|
+
* const { AgentBuilder } = getHostExports(ctx!);
|
|
2482
|
+
*
|
|
2483
|
+
* const agent = new AgentBuilder()
|
|
2484
|
+
* .withParentContext(ctx!)
|
|
2485
|
+
* .withGadgets(Navigate, Click, Screenshot)
|
|
2486
|
+
* .ask(params.task);
|
|
2487
|
+
*
|
|
2488
|
+
* for await (const event of agent.run()) {
|
|
2489
|
+
* // Events flow through host's shared tree
|
|
2490
|
+
* }
|
|
2491
|
+
* }
|
|
2492
|
+
* }
|
|
2493
|
+
* ```
|
|
2494
|
+
*/
|
|
2495
|
+
declare function getHostExports(ctx: ExecutionContext): HostExports;
|
|
2496
|
+
|
|
2497
|
+
export { AbortException, AbstractGadget, AgentHooks, AnthropicMessagesProvider, CompactionConfig, CompactionContext, CompactionEvent, CompactionManager, CompactionResult, CompactionStats, CompactionStrategy, ConversationManager, ExecutionContext, ExecutionTree, GadgetCallParser, GadgetExecuteResultWithMedia, GadgetExecutionResult, GadgetExecutor, GadgetMediaOutput, GadgetOutputStore, GadgetRegistry, GeminiGenerativeProvider, HintTemplate, type HintsConfig, HookPresets, HostExports, HumanInputRequiredException, HybridStrategy, IConversationManager, type IterationHintOptions, LLMGenerationOptions, LLMMessage, LLMStream, LLMStreamChunk, LLMist, type LoggerOptions, type LoggingOptions, MODEL_ALIASES, MediaKind, MediaMetadata, MediaStore, MessageContent, ModelDescriptor, ModelRegistry, ModelSpec, NodeId, OpenAIChatProvider, type ParallelGadgetHintOptions, ParsedGadgetCall, ProviderAdapter, type ResolveValueOptions, ResolvedCompactionConfig, SlidingWindowStrategy, type StoredOutput, StreamEvent, type StreamProcessingResult, StreamProcessor, type StreamProcessorOptions, SubagentEvent, SummarizationStrategy, TaskCompletionSignal, TimeoutException, TokenUsage, type ValidationIssue, type ValidationResult, createAnthropicProviderFromEnv, createGadgetOutputViewer, createGeminiProviderFromEnv, createHints, createLogger, createMediaOutput, createOpenAIProviderFromEnv, defaultLogger, discoverProviderAdapters, getHostExports, getModelId, getProvider, hasProviderPrefix, iterationProgressHint, parallelGadgetHint, resolveConfig, resolveModel, resolveSubagentModel, resolveValue, resultWithAudio, resultWithFile, resultWithImage, resultWithImages, resultWithMedia, validateAndApplyDefaults, validateGadgetParams };
|