llmist 6.1.0 → 7.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/README.md +6 -1
- package/dist/{chunk-7BJX376V.js → chunk-5KEZ7SQX.js} +13 -25
- package/dist/chunk-5KEZ7SQX.js.map +1 -0
- package/dist/{chunk-VAJLPRJ6.js → chunk-SFZIL2VR.js} +410 -493
- package/dist/chunk-SFZIL2VR.js.map +1 -0
- package/dist/cli.cjs +11533 -11843
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +5528 -5751
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +5779 -5872
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -299
- package/dist/index.d.ts +75 -299
- package/dist/index.js +5 -3
- package/dist/{mock-stream-Cq1Sxezz.d.cts → mock-stream-r5vjy2Iq.d.cts} +1103 -739
- package/dist/{mock-stream-Cq1Sxezz.d.ts → mock-stream-r5vjy2Iq.d.ts} +1103 -739
- package/dist/testing/index.cjs +401 -486
- 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 +2 -1
- package/dist/chunk-7BJX376V.js.map +0 -1
- package/dist/chunk-VAJLPRJ6.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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, N as ExecutionTree, O as NodeId, b as LLMStreamChunk, P as
|
|
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-r5vjy2Iq.js';
|
|
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-r5vjy2Iq.js';
|
|
5
5
|
import { Logger, ILogObj } from 'tslog';
|
|
6
|
+
export { ILogObj, Logger } from 'tslog';
|
|
6
7
|
import { MessageCreateParamsStreaming, MessageStreamEvent } from '@anthropic-ai/sdk/resources/messages';
|
|
7
8
|
import OpenAI from 'openai';
|
|
8
9
|
import { ChatCompletionChunk } from 'openai/resources/chat/completions';
|
|
@@ -1198,6 +1199,16 @@ interface StreamProcessorOptions {
|
|
|
1198
1199
|
parentNodeId?: NodeId | null;
|
|
1199
1200
|
/** Base depth for nodes created by this processor */
|
|
1200
1201
|
baseDepth?: number;
|
|
1202
|
+
/**
|
|
1203
|
+
* Set of invocation IDs that completed in previous iterations.
|
|
1204
|
+
* Used to resolve dependencies on gadgets from prior LLM responses.
|
|
1205
|
+
*/
|
|
1206
|
+
priorCompletedInvocations?: Set<string>;
|
|
1207
|
+
/**
|
|
1208
|
+
* Set of invocation IDs that failed in previous iterations.
|
|
1209
|
+
* Used to skip gadgets that depend on previously-failed gadgets.
|
|
1210
|
+
*/
|
|
1211
|
+
priorFailedInvocations?: Set<string>;
|
|
1201
1212
|
}
|
|
1202
1213
|
/**
|
|
1203
1214
|
* Result of stream processing.
|
|
@@ -1262,6 +1273,10 @@ declare class StreamProcessor {
|
|
|
1262
1273
|
private inFlightExecutions;
|
|
1263
1274
|
/** Queue of completed gadget results ready to be yielded (for real-time streaming) */
|
|
1264
1275
|
private completedResultsQueue;
|
|
1276
|
+
/** Invocation IDs completed in previous iterations (read-only reference from Agent) */
|
|
1277
|
+
private readonly priorCompletedInvocations;
|
|
1278
|
+
/** Invocation IDs that failed in previous iterations (read-only reference from Agent) */
|
|
1279
|
+
private readonly priorFailedInvocations;
|
|
1265
1280
|
constructor(options: StreamProcessorOptions);
|
|
1266
1281
|
/**
|
|
1267
1282
|
* Process an LLM stream and yield events in real-time.
|
|
@@ -1282,30 +1297,17 @@ declare class StreamProcessor {
|
|
|
1282
1297
|
* Process a text event through interceptors.
|
|
1283
1298
|
*/
|
|
1284
1299
|
private processTextEvent;
|
|
1285
|
-
/**
|
|
1286
|
-
* Process a gadget call through the full lifecycle, handling dependencies.
|
|
1287
|
-
*
|
|
1288
|
-
* Gadgets without dependencies (or with all dependencies satisfied) execute immediately.
|
|
1289
|
-
* Gadgets with unsatisfied dependencies are queued for later execution.
|
|
1290
|
-
* After each execution, pending gadgets are checked to see if they can now run.
|
|
1291
|
-
*/
|
|
1292
|
-
private processGadgetCall;
|
|
1293
1300
|
/**
|
|
1294
1301
|
* Process a gadget call, yielding events in real-time.
|
|
1295
1302
|
*
|
|
1296
|
-
*
|
|
1297
|
-
*
|
|
1303
|
+
* Yields gadget_call event IMMEDIATELY when parsed (before execution),
|
|
1304
|
+
* enabling real-time UI feedback.
|
|
1298
1305
|
*/
|
|
1299
1306
|
private processGadgetCallGenerator;
|
|
1300
1307
|
/**
|
|
1301
|
-
* Execute a gadget through the full hook lifecycle.
|
|
1302
|
-
*
|
|
1303
|
-
*
|
|
1304
|
-
*/
|
|
1305
|
-
private executeGadgetWithHooks;
|
|
1306
|
-
/**
|
|
1307
|
-
* Execute a gadget and yield the result event.
|
|
1308
|
-
* Generator version that yields gadget_result immediately when execution completes.
|
|
1308
|
+
* Execute a gadget through the full hook lifecycle and yield events.
|
|
1309
|
+
* Handles parameter interception, before/after controllers, observers,
|
|
1310
|
+
* execution, result interception, and tree tracking.
|
|
1309
1311
|
*/
|
|
1310
1312
|
private executeGadgetGenerator;
|
|
1311
1313
|
/**
|
|
@@ -1336,14 +1338,9 @@ declare class StreamProcessor {
|
|
|
1336
1338
|
private handleFailedDependency;
|
|
1337
1339
|
/**
|
|
1338
1340
|
* Process pending gadgets whose dependencies are now satisfied.
|
|
1339
|
-
*
|
|
1340
|
-
*/
|
|
1341
|
-
private processPendingGadgets;
|
|
1342
|
-
/**
|
|
1343
|
-
* Process pending gadgets, yielding events in real-time.
|
|
1344
|
-
* Generator version that yields events as gadgets complete.
|
|
1341
|
+
* Yields events in real-time as gadgets complete.
|
|
1345
1342
|
*
|
|
1346
|
-
*
|
|
1343
|
+
* Gadgets are executed in parallel for efficiency,
|
|
1347
1344
|
* but results are yielded as they become available.
|
|
1348
1345
|
*/
|
|
1349
1346
|
private processPendingGadgetsGenerator;
|
|
@@ -1357,6 +1354,16 @@ declare class StreamProcessor {
|
|
|
1357
1354
|
* All observers run concurrently and failures are tracked but don't crash.
|
|
1358
1355
|
*/
|
|
1359
1356
|
private runObserversInParallel;
|
|
1357
|
+
/**
|
|
1358
|
+
* Get all invocation IDs that completed successfully in this iteration.
|
|
1359
|
+
* Used by Agent to accumulate completed IDs across iterations.
|
|
1360
|
+
*/
|
|
1361
|
+
getCompletedInvocationIds(): Set<string>;
|
|
1362
|
+
/**
|
|
1363
|
+
* Get all invocation IDs that failed in this iteration.
|
|
1364
|
+
* Used by Agent to accumulate failed IDs across iterations.
|
|
1365
|
+
*/
|
|
1366
|
+
getFailedInvocationIds(): Set<string>;
|
|
1360
1367
|
}
|
|
1361
1368
|
|
|
1362
1369
|
/**
|
|
@@ -1473,116 +1480,6 @@ declare function getProvider(model: string): string | undefined;
|
|
|
1473
1480
|
*/
|
|
1474
1481
|
declare function getModelId(model: string): string;
|
|
1475
1482
|
|
|
1476
|
-
/**
|
|
1477
|
-
* Function-based gadget creation helper.
|
|
1478
|
-
*
|
|
1479
|
-
* For simple gadgets, use createGadget() instead of defining a class.
|
|
1480
|
-
* Parameters are automatically typed from the Zod schema.
|
|
1481
|
-
*
|
|
1482
|
-
* @example
|
|
1483
|
-
* ```typescript
|
|
1484
|
-
* const calculator = createGadget({
|
|
1485
|
-
* description: "Performs arithmetic operations",
|
|
1486
|
-
* schema: z.object({
|
|
1487
|
-
* operation: z.enum(["add", "subtract"]),
|
|
1488
|
-
* a: z.number(),
|
|
1489
|
-
* b: z.number(),
|
|
1490
|
-
* }),
|
|
1491
|
-
* execute: ({ operation, a, b }) => {
|
|
1492
|
-
* // Automatically typed!
|
|
1493
|
-
* return operation === "add" ? String(a + b) : String(a - b);
|
|
1494
|
-
* },
|
|
1495
|
-
* });
|
|
1496
|
-
* ```
|
|
1497
|
-
*/
|
|
1498
|
-
|
|
1499
|
-
/**
|
|
1500
|
-
* Infer the TypeScript type from a Zod schema.
|
|
1501
|
-
*/
|
|
1502
|
-
type InferSchema$1<T> = T extends ZodType<infer U> ? U : never;
|
|
1503
|
-
/**
|
|
1504
|
-
* Configuration for creating a function-based gadget.
|
|
1505
|
-
*/
|
|
1506
|
-
interface CreateGadgetConfig<TSchema extends ZodType> {
|
|
1507
|
-
/** Optional custom name (defaults to "FunctionGadget") */
|
|
1508
|
-
name?: string;
|
|
1509
|
-
/** Human-readable description of what the gadget does */
|
|
1510
|
-
description: string;
|
|
1511
|
-
/** Zod schema for parameter validation */
|
|
1512
|
-
schema: TSchema;
|
|
1513
|
-
/**
|
|
1514
|
-
* Execution function with typed parameters.
|
|
1515
|
-
* Can return string or { result, cost? }.
|
|
1516
|
-
* Optionally receives ExecutionContext for callback-based cost reporting.
|
|
1517
|
-
*/
|
|
1518
|
-
execute: (params: InferSchema$1<TSchema>, ctx?: ExecutionContext) => GadgetExecuteReturn | Promise<GadgetExecuteReturn>;
|
|
1519
|
-
/** Optional timeout in milliseconds */
|
|
1520
|
-
timeoutMs?: number;
|
|
1521
|
-
/** Optional usage examples to help LLMs understand proper invocation */
|
|
1522
|
-
examples?: GadgetExample<InferSchema$1<TSchema>>[];
|
|
1523
|
-
}
|
|
1524
|
-
/**
|
|
1525
|
-
* Creates a gadget from a function (simpler than class-based approach).
|
|
1526
|
-
*
|
|
1527
|
-
* This is perfect for simple gadgets where you don't need the full
|
|
1528
|
-
* power of a class. Parameters are automatically typed from the schema.
|
|
1529
|
-
*
|
|
1530
|
-
* @param config - Configuration with execute function and schema
|
|
1531
|
-
* @returns Gadget instance ready to be registered
|
|
1532
|
-
*
|
|
1533
|
-
* @example
|
|
1534
|
-
* ```typescript
|
|
1535
|
-
* import { z } from 'zod';
|
|
1536
|
-
* import { createGadget } from 'llmist';
|
|
1537
|
-
*
|
|
1538
|
-
* // Simple calculator gadget
|
|
1539
|
-
* const calculator = createGadget({
|
|
1540
|
-
* description: "Performs arithmetic operations",
|
|
1541
|
-
* schema: z.object({
|
|
1542
|
-
* operation: z.enum(["add", "subtract", "multiply", "divide"]),
|
|
1543
|
-
* a: z.number().describe("First number"),
|
|
1544
|
-
* b: z.number().describe("Second number"),
|
|
1545
|
-
* }),
|
|
1546
|
-
* execute: ({ operation, a, b }) => {
|
|
1547
|
-
* // Parameters are automatically typed!
|
|
1548
|
-
* switch (operation) {
|
|
1549
|
-
* case "add": return String(a + b);
|
|
1550
|
-
* case "subtract": return String(a - b);
|
|
1551
|
-
* case "multiply": return String(a * b);
|
|
1552
|
-
* case "divide": return String(a / b);
|
|
1553
|
-
* }
|
|
1554
|
-
* },
|
|
1555
|
-
* });
|
|
1556
|
-
* ```
|
|
1557
|
-
*
|
|
1558
|
-
* @example
|
|
1559
|
-
* ```typescript
|
|
1560
|
-
* // Async gadget with custom name and timeout
|
|
1561
|
-
* const weather = createGadget({
|
|
1562
|
-
* name: "weather",
|
|
1563
|
-
* description: "Fetches current weather for a city",
|
|
1564
|
-
* schema: z.object({
|
|
1565
|
-
* city: z.string().min(1).describe("City name"),
|
|
1566
|
-
* }),
|
|
1567
|
-
* timeoutMs: 10000,
|
|
1568
|
-
* execute: async ({ city }) => {
|
|
1569
|
-
* const response = await fetch(`https://api.weather.com/${city}`);
|
|
1570
|
-
* const data = await response.json();
|
|
1571
|
-
* return `Weather in ${city}: ${data.description}, ${data.temp}°C`;
|
|
1572
|
-
* },
|
|
1573
|
-
* });
|
|
1574
|
-
* ```
|
|
1575
|
-
*
|
|
1576
|
-
* @example
|
|
1577
|
-
* ```typescript
|
|
1578
|
-
* // Use with agent
|
|
1579
|
-
* const agent = LLMist.createAgent()
|
|
1580
|
-
* .withGadgets(calculator, weather)
|
|
1581
|
-
* .ask("What's the weather in Paris and what's 10 + 5?");
|
|
1582
|
-
* ```
|
|
1583
|
-
*/
|
|
1584
|
-
declare function createGadget<TSchema extends ZodType>(config: CreateGadgetConfig<TSchema>): AbstractGadget;
|
|
1585
|
-
|
|
1586
1483
|
/**
|
|
1587
1484
|
* Signal that a gadget throws to indicate task completion and agent termination.
|
|
1588
1485
|
*
|
|
@@ -1751,11 +1648,6 @@ declare class GadgetExecutor {
|
|
|
1751
1648
|
private unifyExecuteResult;
|
|
1752
1649
|
execute(call: ParsedGadgetCall): Promise<GadgetExecutionResult>;
|
|
1753
1650
|
executeAll(calls: ParsedGadgetCall[]): Promise<GadgetExecutionResult[]>;
|
|
1754
|
-
/**
|
|
1755
|
-
* Deep equality check for objects/arrays.
|
|
1756
|
-
* Used to detect if parameters were modified by an interceptor.
|
|
1757
|
-
*/
|
|
1758
|
-
private deepEquals;
|
|
1759
1651
|
}
|
|
1760
1652
|
|
|
1761
1653
|
/**
|
|
@@ -1825,161 +1717,6 @@ declare class GadgetCallParser {
|
|
|
1825
1717
|
reset(): void;
|
|
1826
1718
|
}
|
|
1827
1719
|
|
|
1828
|
-
/**
|
|
1829
|
-
* Type-safe gadget factory with automatic parameter inference.
|
|
1830
|
-
*
|
|
1831
|
-
* Gadget eliminates the need for manual type assertions
|
|
1832
|
-
* by automatically inferring parameter types from the Zod schema.
|
|
1833
|
-
*
|
|
1834
|
-
* @example
|
|
1835
|
-
* ```typescript
|
|
1836
|
-
* class Calculator extends Gadget({
|
|
1837
|
-
* description: "Performs arithmetic operations",
|
|
1838
|
-
* schema: z.object({
|
|
1839
|
-
* operation: z.enum(["add", "subtract"]),
|
|
1840
|
-
* a: z.number(),
|
|
1841
|
-
* b: z.number(),
|
|
1842
|
-
* }),
|
|
1843
|
-
* }) {
|
|
1844
|
-
* // ✨ params is automatically typed!
|
|
1845
|
-
* execute(params: this['params']): string {
|
|
1846
|
-
* const { operation, a, b } = params; // All typed!
|
|
1847
|
-
* return operation === "add" ? String(a + b) : String(a - b);
|
|
1848
|
-
* }
|
|
1849
|
-
* }
|
|
1850
|
-
* ```
|
|
1851
|
-
*/
|
|
1852
|
-
|
|
1853
|
-
/**
|
|
1854
|
-
* Infer the TypeScript type from a Zod schema.
|
|
1855
|
-
*/
|
|
1856
|
-
type InferSchema<T> = T extends ZodType<infer U> ? U : never;
|
|
1857
|
-
/**
|
|
1858
|
-
* Configuration for creating a typed gadget.
|
|
1859
|
-
*/
|
|
1860
|
-
interface GadgetConfig<TSchema extends ZodType> {
|
|
1861
|
-
/** Human-readable description of what the gadget does */
|
|
1862
|
-
description: string;
|
|
1863
|
-
/** Zod schema for parameter validation */
|
|
1864
|
-
schema: TSchema;
|
|
1865
|
-
/** Optional custom name (defaults to class name) */
|
|
1866
|
-
name?: string;
|
|
1867
|
-
/** Optional timeout in milliseconds */
|
|
1868
|
-
timeoutMs?: number;
|
|
1869
|
-
/** Optional usage examples to help LLMs understand proper invocation */
|
|
1870
|
-
examples?: GadgetExample<InferSchema<TSchema>>[];
|
|
1871
|
-
}
|
|
1872
|
-
/**
|
|
1873
|
-
* Factory function to create a typed gadget base class.
|
|
1874
|
-
*
|
|
1875
|
-
* The returned class automatically infers parameter types from the Zod schema,
|
|
1876
|
-
* eliminating the need for manual type assertions in the execute method.
|
|
1877
|
-
*
|
|
1878
|
-
* @param config - Configuration with description and schema
|
|
1879
|
-
* @returns Base class to extend with typed execute method
|
|
1880
|
-
*
|
|
1881
|
-
* @example
|
|
1882
|
-
* ```typescript
|
|
1883
|
-
* import { z } from 'zod';
|
|
1884
|
-
* import { Gadget } from 'llmist';
|
|
1885
|
-
*
|
|
1886
|
-
* class Calculator extends Gadget({
|
|
1887
|
-
* description: "Performs arithmetic operations",
|
|
1888
|
-
* schema: z.object({
|
|
1889
|
-
* operation: z.enum(["add", "subtract", "multiply", "divide"]),
|
|
1890
|
-
* a: z.number().describe("First number"),
|
|
1891
|
-
* b: z.number().describe("Second number"),
|
|
1892
|
-
* }),
|
|
1893
|
-
* }) {
|
|
1894
|
-
* execute(params: this['params']): string {
|
|
1895
|
-
* // params is automatically typed as:
|
|
1896
|
-
* // { operation: "add" | "subtract" | "multiply" | "divide"; a: number; b: number }
|
|
1897
|
-
* const { operation, a, b } = params;
|
|
1898
|
-
*
|
|
1899
|
-
* switch (operation) {
|
|
1900
|
-
* case "add": return String(a + b);
|
|
1901
|
-
* case "subtract": return String(a - b);
|
|
1902
|
-
* case "multiply": return String(a * b);
|
|
1903
|
-
* case "divide": return String(a / b);
|
|
1904
|
-
* }
|
|
1905
|
-
* }
|
|
1906
|
-
* }
|
|
1907
|
-
* ```
|
|
1908
|
-
*
|
|
1909
|
-
* @example
|
|
1910
|
-
* ```typescript
|
|
1911
|
-
* // With async execution
|
|
1912
|
-
* class WeatherGadget extends Gadget({
|
|
1913
|
-
* description: "Fetches weather for a city",
|
|
1914
|
-
* schema: z.object({
|
|
1915
|
-
* city: z.string().min(1).describe("City name"),
|
|
1916
|
-
* }),
|
|
1917
|
-
* timeoutMs: 10000,
|
|
1918
|
-
* }) {
|
|
1919
|
-
* async execute(params: this['params']): Promise<string> {
|
|
1920
|
-
* const { city } = params; // Automatically typed as { city: string }
|
|
1921
|
-
* const weather = await fetchWeather(city);
|
|
1922
|
-
* return `Weather in ${city}: ${weather}`;
|
|
1923
|
-
* }
|
|
1924
|
-
* }
|
|
1925
|
-
* ```
|
|
1926
|
-
*/
|
|
1927
|
-
declare function Gadget<TSchema extends ZodType>(config: GadgetConfig<TSchema>): {
|
|
1928
|
-
new (): {
|
|
1929
|
-
description: string;
|
|
1930
|
-
parameterSchema: TSchema;
|
|
1931
|
-
name: string | undefined;
|
|
1932
|
-
timeoutMs: number | undefined;
|
|
1933
|
-
examples: GadgetExample<InferSchema<TSchema>>[] | undefined;
|
|
1934
|
-
/**
|
|
1935
|
-
* Type helper property for accessing inferred parameter type.
|
|
1936
|
-
* This is used in the execute method signature: `execute(params: this['params'])`
|
|
1937
|
-
*
|
|
1938
|
-
* Note: This is just for type inference - the actual params in execute()
|
|
1939
|
-
* will be Record<string, unknown> which you can safely cast to this['params']
|
|
1940
|
-
*/
|
|
1941
|
-
readonly params: InferSchema<TSchema>;
|
|
1942
|
-
/**
|
|
1943
|
-
* Execute the gadget. Subclasses should cast params to this['params'].
|
|
1944
|
-
*
|
|
1945
|
-
* @param params - Validated parameters from the LLM
|
|
1946
|
-
* @param ctx - Optional execution context for cost reporting and LLM access
|
|
1947
|
-
* @returns Result as a string, or an object with result and optional cost
|
|
1948
|
-
*
|
|
1949
|
-
* @example
|
|
1950
|
-
* ```typescript
|
|
1951
|
-
* // Simple string return (free gadget)
|
|
1952
|
-
* execute(params: this['params']) {
|
|
1953
|
-
* return String(params.a + params.b);
|
|
1954
|
-
* }
|
|
1955
|
-
*
|
|
1956
|
-
* // Using context for callback-based cost reporting
|
|
1957
|
-
* execute(params: this['params'], ctx) {
|
|
1958
|
-
* ctx.reportCost(0.001);
|
|
1959
|
-
* return "result";
|
|
1960
|
-
* }
|
|
1961
|
-
*
|
|
1962
|
-
* // Using wrapped LLMist for automatic cost tracking
|
|
1963
|
-
* async execute(params: this['params'], ctx) {
|
|
1964
|
-
* return ctx.llmist.complete('Summarize: ' + params.text);
|
|
1965
|
-
* }
|
|
1966
|
-
* ```
|
|
1967
|
-
*/
|
|
1968
|
-
execute(params: Record<string, unknown>, ctx?: ExecutionContext): GadgetExecuteReturn | Promise<GadgetExecuteReturn>;
|
|
1969
|
-
throwIfAborted(ctx?: ExecutionContext): void;
|
|
1970
|
-
onAbort(ctx: ExecutionContext | undefined, cleanup: () => void | Promise<void>): void;
|
|
1971
|
-
createLinkedAbortController(ctx?: ExecutionContext): AbortController;
|
|
1972
|
-
get instruction(): string;
|
|
1973
|
-
getInstruction(optionsOrArgPrefix?: string | {
|
|
1974
|
-
argPrefix?: string;
|
|
1975
|
-
startPrefix?: string;
|
|
1976
|
-
endPrefix?: string;
|
|
1977
|
-
}): string;
|
|
1978
|
-
} & {
|
|
1979
|
-
params: InferSchema<TSchema>;
|
|
1980
|
-
};
|
|
1981
|
-
};
|
|
1982
|
-
|
|
1983
1720
|
/**
|
|
1984
1721
|
* Helper functions for gadget authors to easily return media outputs.
|
|
1985
1722
|
*
|
|
@@ -2720,4 +2457,43 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
|
|
|
2720
2457
|
}
|
|
2721
2458
|
declare function createOpenAIProviderFromEnv(): OpenAIChatProvider | null;
|
|
2722
2459
|
|
|
2723
|
-
|
|
2460
|
+
/**
|
|
2461
|
+
* Get host llmist exports from execution context.
|
|
2462
|
+
*
|
|
2463
|
+
* External gadgets MUST use this instead of importing classes directly from 'llmist'
|
|
2464
|
+
* to ensure they use the same version as the host CLI, enabling proper tree sharing
|
|
2465
|
+
* and avoiding the "dual-package problem".
|
|
2466
|
+
*
|
|
2467
|
+
* @param ctx - The execution context passed to gadget.execute()
|
|
2468
|
+
* @returns The host's llmist exports (AgentBuilder, Gadget, etc.)
|
|
2469
|
+
* @throws Error if ctx or ctx.hostExports is undefined
|
|
2470
|
+
*
|
|
2471
|
+
* @example
|
|
2472
|
+
* ```typescript
|
|
2473
|
+
* import { getHostExports, Gadget, z } from 'llmist';
|
|
2474
|
+
* import type { ExecutionContext } from 'llmist';
|
|
2475
|
+
*
|
|
2476
|
+
* class BrowseWeb extends Gadget({
|
|
2477
|
+
* name: 'BrowseWeb',
|
|
2478
|
+
* description: 'Browse a website autonomously',
|
|
2479
|
+
* schema: z.object({ task: z.string(), url: z.string() }),
|
|
2480
|
+
* }) {
|
|
2481
|
+
* async execute(params: this['params'], ctx?: ExecutionContext) {
|
|
2482
|
+
* // Get host's AgentBuilder to ensure tree sharing works correctly
|
|
2483
|
+
* const { AgentBuilder } = getHostExports(ctx!);
|
|
2484
|
+
*
|
|
2485
|
+
* const agent = new AgentBuilder()
|
|
2486
|
+
* .withParentContext(ctx!)
|
|
2487
|
+
* .withGadgets(Navigate, Click, Screenshot)
|
|
2488
|
+
* .ask(params.task);
|
|
2489
|
+
*
|
|
2490
|
+
* for await (const event of agent.run()) {
|
|
2491
|
+
* // Events flow through host's shared tree
|
|
2492
|
+
* }
|
|
2493
|
+
* }
|
|
2494
|
+
* }
|
|
2495
|
+
* ```
|
|
2496
|
+
*/
|
|
2497
|
+
declare function getHostExports(ctx: ExecutionContext): HostExports;
|
|
2498
|
+
|
|
2499
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Gadget,
|
|
3
2
|
HookPresets,
|
|
4
3
|
createHints,
|
|
5
4
|
createMediaOutput,
|
|
6
5
|
filterByDepth,
|
|
7
6
|
filterByParent,
|
|
8
7
|
filterRootEvents,
|
|
8
|
+
getHostExports,
|
|
9
9
|
groupByParent,
|
|
10
10
|
isGadgetEvent,
|
|
11
11
|
isLLMEvent,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
resultWithImages,
|
|
23
23
|
resultWithMedia,
|
|
24
24
|
z
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-5KEZ7SQX.js";
|
|
26
26
|
import {
|
|
27
27
|
AbortException,
|
|
28
28
|
AbstractGadget,
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
DEFAULT_PROMPTS,
|
|
36
36
|
DEFAULT_SUMMARIZATION_PROMPT,
|
|
37
37
|
ExecutionTree,
|
|
38
|
+
Gadget,
|
|
38
39
|
GadgetCallParser,
|
|
39
40
|
GadgetExecutor,
|
|
40
41
|
GadgetOutputStore,
|
|
@@ -101,7 +102,7 @@ import {
|
|
|
101
102
|
toBase64,
|
|
102
103
|
validateAndApplyDefaults,
|
|
103
104
|
validateGadgetParams
|
|
104
|
-
} from "./chunk-
|
|
105
|
+
} from "./chunk-SFZIL2VR.js";
|
|
105
106
|
export {
|
|
106
107
|
AbortException,
|
|
107
108
|
AbstractGadget,
|
|
@@ -163,6 +164,7 @@ export {
|
|
|
163
164
|
filterByDepth,
|
|
164
165
|
filterByParent,
|
|
165
166
|
filterRootEvents,
|
|
167
|
+
getHostExports,
|
|
166
168
|
getMockManager,
|
|
167
169
|
getModelId,
|
|
168
170
|
getProvider,
|