llmist 0.8.0 → 1.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-4IMGADVY.js → chunk-OIPLYP7M.js} +40 -5
- package/dist/chunk-OIPLYP7M.js.map +1 -0
- package/dist/{chunk-62M4TDAK.js → chunk-VXPZQZF5.js} +432 -555
- package/dist/chunk-VXPZQZF5.js.map +1 -0
- package/dist/cli.cjs +1069 -658
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +638 -95
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +464 -558
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -9
- package/dist/index.d.ts +78 -9
- package/dist/index.js +2 -2
- package/dist/{mock-stream-CjmvWDc3.d.cts → mock-stream-DKF5yatf.d.cts} +41 -102
- package/dist/{mock-stream-CjmvWDc3.d.ts → mock-stream-DKF5yatf.d.ts} +41 -102
- package/dist/testing/index.cjs +464 -558
- 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 +2 -2
- package/package.json +1 -1
- package/dist/chunk-4IMGADVY.js.map +0 -1
- package/dist/chunk-62M4TDAK.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ZodType, ZodTypeAny } from 'zod';
|
|
2
2
|
export { z } from 'zod';
|
|
3
|
-
import { A as AgentHooks, o as ModelRegistry, L as LLMMessage,
|
|
4
|
-
export {
|
|
3
|
+
import { A as AgentHooks, o as ModelRegistry, L as LLMMessage, S as StreamEvent, T as TokenUsage, G as GadgetRegistry, p as LLMStreamChunk, q as GadgetExample, B as BaseGadget, P as ParsedGadgetCall, r as GadgetExecutionResult, s as ProviderAdapter, t as ModelDescriptor, u as ModelSpec, v as LLMGenerationOptions, w as LLMStream } from './mock-stream-DKF5yatf.cjs';
|
|
4
|
+
export { D as AfterGadgetExecutionAction, F as AfterGadgetExecutionControllerContext, I as AfterLLMCallAction, J as AfterLLMCallControllerContext, K as AfterLLMErrorAction, x as AgentBuilder, N as AgentOptions, O as BeforeGadgetExecutionAction, Q as BeforeLLMCallAction, R as ChunkInterceptorContext, U as Controllers, ab as CostEstimate, ak as DEFAULT_PROMPTS, E as EventHandlers, aq as GadgetClass, V as GadgetExecutionControllerContext, ar as GadgetOrClass, W as GadgetParameterInterceptorContext, X as GadgetResultInterceptorContext, H as HistoryMessage, Y as Interceptors, Z as LLMCallControllerContext, _ as LLMErrorControllerContext, aa as LLMMessageBuilder, a9 as LLMRole, a8 as LLMist, a7 as LLMistOptions, $ as MessageInterceptorContext, a as MockBuilder, d as MockManager, h as MockMatcher, i as MockMatcherContext, j as MockOptions, M as MockProviderAdapter, k as MockRegistration, l as MockResponse, n as MockStats, ac as ModelFeatures, ag as ModelIdentifierParser, ad as ModelLimits, ae as ModelPricing, a0 as ObserveChunkContext, a1 as ObserveGadgetCompleteContext, a2 as ObserveGadgetStartContext, a3 as ObserveLLMCallContext, a4 as ObserveLLMCompleteContext, a5 as ObserveLLMErrorContext, a6 as Observers, ah as PromptConfig, ai as PromptContext, aj as PromptTemplate, af as ProviderIdentifier, an as QuickOptions, as as TextOnlyAction, at as TextOnlyContext, au as TextOnlyCustomHandler, av as TextOnlyGadgetConfig, aw as TextOnlyHandler, ax as TextOnlyStrategy, y as collectEvents, z as collectText, ao as complete, c as createMockAdapter, b as createMockClient, e as createMockStream, f as createTextMockStream, g as getMockManager, m as mockLLM, al as resolvePromptTemplate, am as resolveRulesTemplate, C as runWithHandlers, ap as stream } from './mock-stream-DKF5yatf.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';
|
|
@@ -724,11 +724,12 @@ interface IConversationManager {
|
|
|
724
724
|
* Options for ConversationManager constructor.
|
|
725
725
|
*/
|
|
726
726
|
interface ConversationManagerOptions {
|
|
727
|
-
parameterFormat?: ParameterFormat;
|
|
728
727
|
/** Custom gadget start marker prefix */
|
|
729
728
|
startPrefix?: string;
|
|
730
729
|
/** Custom gadget end marker prefix */
|
|
731
730
|
endPrefix?: string;
|
|
731
|
+
/** Custom argument prefix for block format */
|
|
732
|
+
argPrefix?: string;
|
|
732
733
|
}
|
|
733
734
|
/**
|
|
734
735
|
* Default implementation of IConversationManager.
|
|
@@ -738,7 +739,6 @@ declare class ConversationManager implements IConversationManager {
|
|
|
738
739
|
private readonly baseMessages;
|
|
739
740
|
private readonly initialMessages;
|
|
740
741
|
private readonly historyBuilder;
|
|
741
|
-
private readonly parameterFormat;
|
|
742
742
|
constructor(baseMessages: LLMMessage[], initialMessages: LLMMessage[], options?: ConversationManagerOptions);
|
|
743
743
|
addUserMessage(content: string): void;
|
|
744
744
|
addAssistantMessage(content: string): void;
|
|
@@ -761,12 +761,12 @@ interface StreamProcessorOptions {
|
|
|
761
761
|
iteration: number;
|
|
762
762
|
/** Gadget registry for execution */
|
|
763
763
|
registry: GadgetRegistry;
|
|
764
|
-
/** Parameter format for parsing */
|
|
765
|
-
parameterFormat: ParameterFormat;
|
|
766
764
|
/** Custom gadget start prefix */
|
|
767
765
|
gadgetStartPrefix?: string;
|
|
768
766
|
/** Custom gadget end prefix */
|
|
769
767
|
gadgetEndPrefix?: string;
|
|
768
|
+
/** Custom argument prefix for block format */
|
|
769
|
+
gadgetArgPrefix?: string;
|
|
770
770
|
/** Hooks for lifecycle events */
|
|
771
771
|
hooks?: AgentHooks;
|
|
772
772
|
/** Logger instance */
|
|
@@ -1269,12 +1269,22 @@ declare class HumanInputException extends Error {
|
|
|
1269
1269
|
constructor(question: string);
|
|
1270
1270
|
}
|
|
1271
1271
|
|
|
1272
|
+
interface ErrorFormatterOptions {
|
|
1273
|
+
/** Custom argument prefix for block format examples. Default: "!!!ARG:" */
|
|
1274
|
+
argPrefix?: string;
|
|
1275
|
+
/** Custom start prefix for block format examples. Default: "!!!GADGET_START:" */
|
|
1276
|
+
startPrefix?: string;
|
|
1277
|
+
/** Custom end prefix for block format examples. Default: "!!!GADGET_END" */
|
|
1278
|
+
endPrefix?: string;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1272
1281
|
declare class GadgetExecutor {
|
|
1273
1282
|
private readonly registry;
|
|
1274
1283
|
private readonly onHumanInputRequired?;
|
|
1275
1284
|
private readonly defaultGadgetTimeoutMs?;
|
|
1276
1285
|
private readonly logger;
|
|
1277
|
-
|
|
1286
|
+
private readonly errorFormatter;
|
|
1287
|
+
constructor(registry: GadgetRegistry, onHumanInputRequired?: ((question: string) => Promise<string>) | undefined, logger?: Logger<ILogObj>, defaultGadgetTimeoutMs?: number | undefined, errorFormatterOptions?: ErrorFormatterOptions);
|
|
1278
1288
|
/**
|
|
1279
1289
|
* Creates a promise that rejects with a TimeoutException after the specified timeout.
|
|
1280
1290
|
*/
|
|
@@ -1283,6 +1293,65 @@ declare class GadgetExecutor {
|
|
|
1283
1293
|
executeAll(calls: ParsedGadgetCall[]): Promise<GadgetExecutionResult[]>;
|
|
1284
1294
|
}
|
|
1285
1295
|
|
|
1296
|
+
interface StreamParserOptions {
|
|
1297
|
+
startPrefix?: string;
|
|
1298
|
+
endPrefix?: string;
|
|
1299
|
+
/** Prefix for block format arguments. Default: "!!!ARG:" */
|
|
1300
|
+
argPrefix?: string;
|
|
1301
|
+
}
|
|
1302
|
+
declare class StreamParser {
|
|
1303
|
+
private buffer;
|
|
1304
|
+
private lastReportedTextLength;
|
|
1305
|
+
private readonly startPrefix;
|
|
1306
|
+
private readonly endPrefix;
|
|
1307
|
+
private readonly argPrefix;
|
|
1308
|
+
constructor(options?: StreamParserOptions);
|
|
1309
|
+
private takeTextUntil;
|
|
1310
|
+
/**
|
|
1311
|
+
* Parse gadget name, handling both old format (name:invocationId) and new format (just name).
|
|
1312
|
+
* For new format, generates a unique invocation ID.
|
|
1313
|
+
*/
|
|
1314
|
+
private parseGadgetName;
|
|
1315
|
+
/**
|
|
1316
|
+
* Extract the error message from a parse error.
|
|
1317
|
+
* Preserves full message since the error formatter adds contextual help
|
|
1318
|
+
* that benefits from precise, detailed error information.
|
|
1319
|
+
*/
|
|
1320
|
+
private extractParseError;
|
|
1321
|
+
/**
|
|
1322
|
+
* Parse parameter string using block format
|
|
1323
|
+
*/
|
|
1324
|
+
private parseParameters;
|
|
1325
|
+
feed(chunk: string): Generator<StreamEvent>;
|
|
1326
|
+
finalize(): Generator<StreamEvent>;
|
|
1327
|
+
reset(): void;
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
/**
|
|
1331
|
+
* Type-safe gadget factory with automatic parameter inference.
|
|
1332
|
+
*
|
|
1333
|
+
* Gadget eliminates the need for manual type assertions
|
|
1334
|
+
* by automatically inferring parameter types from the Zod schema.
|
|
1335
|
+
*
|
|
1336
|
+
* @example
|
|
1337
|
+
* ```typescript
|
|
1338
|
+
* class Calculator extends Gadget({
|
|
1339
|
+
* description: "Performs arithmetic operations",
|
|
1340
|
+
* schema: z.object({
|
|
1341
|
+
* operation: z.enum(["add", "subtract"]),
|
|
1342
|
+
* a: z.number(),
|
|
1343
|
+
* b: z.number(),
|
|
1344
|
+
* }),
|
|
1345
|
+
* }) {
|
|
1346
|
+
* // ✨ params is automatically typed!
|
|
1347
|
+
* execute(params: this['params']): string {
|
|
1348
|
+
* const { operation, a, b } = params; // All typed!
|
|
1349
|
+
* return operation === "add" ? String(a + b) : String(a - b);
|
|
1350
|
+
* }
|
|
1351
|
+
* }
|
|
1352
|
+
* ```
|
|
1353
|
+
*/
|
|
1354
|
+
|
|
1286
1355
|
/**
|
|
1287
1356
|
* Infer the TypeScript type from a Zod schema.
|
|
1288
1357
|
*/
|
|
@@ -1389,7 +1458,7 @@ declare function Gadget<TSchema extends ZodType>(config: GadgetConfig<TSchema>):
|
|
|
1389
1458
|
*/
|
|
1390
1459
|
execute(params: Record<string, unknown>): string | Promise<string>;
|
|
1391
1460
|
get instruction(): string;
|
|
1392
|
-
getInstruction(
|
|
1461
|
+
getInstruction(argPrefix?: string): string;
|
|
1393
1462
|
} & {
|
|
1394
1463
|
params: InferSchema<TSchema>;
|
|
1395
1464
|
};
|
|
@@ -1766,4 +1835,4 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
|
|
|
1766
1835
|
}
|
|
1767
1836
|
declare function createOpenAIProviderFromEnv(): OpenAIChatProvider | null;
|
|
1768
1837
|
|
|
1769
|
-
export { AgentHooks, AnthropicMessagesProvider, BaseGadget, BreakLoopException, ConversationManager, type CreateGadgetConfig, Gadget, type GadgetConfig, GadgetExample, GadgetExecutionResult, GadgetExecutor, GadgetOutputStore, GadgetRegistry, GeminiGenerativeProvider, HookPresets, HumanInputException, type IConversationManager, LLMGenerationOptions, LLMMessage, LLMStream, LLMStreamChunk, type LoggerOptions, type LoggingOptions, MODEL_ALIASES, ModelDescriptor, ModelRegistry, ModelSpec, OpenAIChatProvider, ParsedGadgetCall, ProviderAdapter, type StoredOutput, StreamEvent, type StreamProcessingResult, StreamProcessor, type StreamProcessorOptions, TokenUsage, type ValidationIssue, type ValidationResult, createAnthropicProviderFromEnv, createGadget, createGadgetOutputViewer, createGeminiProviderFromEnv, createLogger, createOpenAIProviderFromEnv, defaultLogger, discoverProviderAdapters, getModelId, getProvider, hasProviderPrefix, resolveModel, validateAndApplyDefaults, validateGadgetParams };
|
|
1838
|
+
export { AgentHooks, AnthropicMessagesProvider, BaseGadget, BreakLoopException, ConversationManager, type CreateGadgetConfig, Gadget, type GadgetConfig, GadgetExample, GadgetExecutionResult, GadgetExecutor, GadgetOutputStore, GadgetRegistry, GeminiGenerativeProvider, HookPresets, HumanInputException, type IConversationManager, LLMGenerationOptions, LLMMessage, LLMStream, LLMStreamChunk, type LoggerOptions, type LoggingOptions, MODEL_ALIASES, ModelDescriptor, ModelRegistry, ModelSpec, OpenAIChatProvider, ParsedGadgetCall, ProviderAdapter, type StoredOutput, StreamEvent, StreamParser, type StreamProcessingResult, StreamProcessor, type StreamProcessorOptions, TokenUsage, type ValidationIssue, type ValidationResult, createAnthropicProviderFromEnv, createGadget, createGadgetOutputViewer, createGeminiProviderFromEnv, createLogger, createOpenAIProviderFromEnv, defaultLogger, discoverProviderAdapters, getModelId, getProvider, hasProviderPrefix, resolveModel, validateAndApplyDefaults, validateGadgetParams };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ZodType, ZodTypeAny } from 'zod';
|
|
2
2
|
export { z } from 'zod';
|
|
3
|
-
import { A as AgentHooks, o as ModelRegistry, L as LLMMessage,
|
|
4
|
-
export {
|
|
3
|
+
import { A as AgentHooks, o as ModelRegistry, L as LLMMessage, S as StreamEvent, T as TokenUsage, G as GadgetRegistry, p as LLMStreamChunk, q as GadgetExample, B as BaseGadget, P as ParsedGadgetCall, r as GadgetExecutionResult, s as ProviderAdapter, t as ModelDescriptor, u as ModelSpec, v as LLMGenerationOptions, w as LLMStream } from './mock-stream-DKF5yatf.js';
|
|
4
|
+
export { D as AfterGadgetExecutionAction, F as AfterGadgetExecutionControllerContext, I as AfterLLMCallAction, J as AfterLLMCallControllerContext, K as AfterLLMErrorAction, x as AgentBuilder, N as AgentOptions, O as BeforeGadgetExecutionAction, Q as BeforeLLMCallAction, R as ChunkInterceptorContext, U as Controllers, ab as CostEstimate, ak as DEFAULT_PROMPTS, E as EventHandlers, aq as GadgetClass, V as GadgetExecutionControllerContext, ar as GadgetOrClass, W as GadgetParameterInterceptorContext, X as GadgetResultInterceptorContext, H as HistoryMessage, Y as Interceptors, Z as LLMCallControllerContext, _ as LLMErrorControllerContext, aa as LLMMessageBuilder, a9 as LLMRole, a8 as LLMist, a7 as LLMistOptions, $ as MessageInterceptorContext, a as MockBuilder, d as MockManager, h as MockMatcher, i as MockMatcherContext, j as MockOptions, M as MockProviderAdapter, k as MockRegistration, l as MockResponse, n as MockStats, ac as ModelFeatures, ag as ModelIdentifierParser, ad as ModelLimits, ae as ModelPricing, a0 as ObserveChunkContext, a1 as ObserveGadgetCompleteContext, a2 as ObserveGadgetStartContext, a3 as ObserveLLMCallContext, a4 as ObserveLLMCompleteContext, a5 as ObserveLLMErrorContext, a6 as Observers, ah as PromptConfig, ai as PromptContext, aj as PromptTemplate, af as ProviderIdentifier, an as QuickOptions, as as TextOnlyAction, at as TextOnlyContext, au as TextOnlyCustomHandler, av as TextOnlyGadgetConfig, aw as TextOnlyHandler, ax as TextOnlyStrategy, y as collectEvents, z as collectText, ao as complete, c as createMockAdapter, b as createMockClient, e as createMockStream, f as createTextMockStream, g as getMockManager, m as mockLLM, al as resolvePromptTemplate, am as resolveRulesTemplate, C as runWithHandlers, ap as stream } from './mock-stream-DKF5yatf.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';
|
|
@@ -724,11 +724,12 @@ interface IConversationManager {
|
|
|
724
724
|
* Options for ConversationManager constructor.
|
|
725
725
|
*/
|
|
726
726
|
interface ConversationManagerOptions {
|
|
727
|
-
parameterFormat?: ParameterFormat;
|
|
728
727
|
/** Custom gadget start marker prefix */
|
|
729
728
|
startPrefix?: string;
|
|
730
729
|
/** Custom gadget end marker prefix */
|
|
731
730
|
endPrefix?: string;
|
|
731
|
+
/** Custom argument prefix for block format */
|
|
732
|
+
argPrefix?: string;
|
|
732
733
|
}
|
|
733
734
|
/**
|
|
734
735
|
* Default implementation of IConversationManager.
|
|
@@ -738,7 +739,6 @@ declare class ConversationManager implements IConversationManager {
|
|
|
738
739
|
private readonly baseMessages;
|
|
739
740
|
private readonly initialMessages;
|
|
740
741
|
private readonly historyBuilder;
|
|
741
|
-
private readonly parameterFormat;
|
|
742
742
|
constructor(baseMessages: LLMMessage[], initialMessages: LLMMessage[], options?: ConversationManagerOptions);
|
|
743
743
|
addUserMessage(content: string): void;
|
|
744
744
|
addAssistantMessage(content: string): void;
|
|
@@ -761,12 +761,12 @@ interface StreamProcessorOptions {
|
|
|
761
761
|
iteration: number;
|
|
762
762
|
/** Gadget registry for execution */
|
|
763
763
|
registry: GadgetRegistry;
|
|
764
|
-
/** Parameter format for parsing */
|
|
765
|
-
parameterFormat: ParameterFormat;
|
|
766
764
|
/** Custom gadget start prefix */
|
|
767
765
|
gadgetStartPrefix?: string;
|
|
768
766
|
/** Custom gadget end prefix */
|
|
769
767
|
gadgetEndPrefix?: string;
|
|
768
|
+
/** Custom argument prefix for block format */
|
|
769
|
+
gadgetArgPrefix?: string;
|
|
770
770
|
/** Hooks for lifecycle events */
|
|
771
771
|
hooks?: AgentHooks;
|
|
772
772
|
/** Logger instance */
|
|
@@ -1269,12 +1269,22 @@ declare class HumanInputException extends Error {
|
|
|
1269
1269
|
constructor(question: string);
|
|
1270
1270
|
}
|
|
1271
1271
|
|
|
1272
|
+
interface ErrorFormatterOptions {
|
|
1273
|
+
/** Custom argument prefix for block format examples. Default: "!!!ARG:" */
|
|
1274
|
+
argPrefix?: string;
|
|
1275
|
+
/** Custom start prefix for block format examples. Default: "!!!GADGET_START:" */
|
|
1276
|
+
startPrefix?: string;
|
|
1277
|
+
/** Custom end prefix for block format examples. Default: "!!!GADGET_END" */
|
|
1278
|
+
endPrefix?: string;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1272
1281
|
declare class GadgetExecutor {
|
|
1273
1282
|
private readonly registry;
|
|
1274
1283
|
private readonly onHumanInputRequired?;
|
|
1275
1284
|
private readonly defaultGadgetTimeoutMs?;
|
|
1276
1285
|
private readonly logger;
|
|
1277
|
-
|
|
1286
|
+
private readonly errorFormatter;
|
|
1287
|
+
constructor(registry: GadgetRegistry, onHumanInputRequired?: ((question: string) => Promise<string>) | undefined, logger?: Logger<ILogObj>, defaultGadgetTimeoutMs?: number | undefined, errorFormatterOptions?: ErrorFormatterOptions);
|
|
1278
1288
|
/**
|
|
1279
1289
|
* Creates a promise that rejects with a TimeoutException after the specified timeout.
|
|
1280
1290
|
*/
|
|
@@ -1283,6 +1293,65 @@ declare class GadgetExecutor {
|
|
|
1283
1293
|
executeAll(calls: ParsedGadgetCall[]): Promise<GadgetExecutionResult[]>;
|
|
1284
1294
|
}
|
|
1285
1295
|
|
|
1296
|
+
interface StreamParserOptions {
|
|
1297
|
+
startPrefix?: string;
|
|
1298
|
+
endPrefix?: string;
|
|
1299
|
+
/** Prefix for block format arguments. Default: "!!!ARG:" */
|
|
1300
|
+
argPrefix?: string;
|
|
1301
|
+
}
|
|
1302
|
+
declare class StreamParser {
|
|
1303
|
+
private buffer;
|
|
1304
|
+
private lastReportedTextLength;
|
|
1305
|
+
private readonly startPrefix;
|
|
1306
|
+
private readonly endPrefix;
|
|
1307
|
+
private readonly argPrefix;
|
|
1308
|
+
constructor(options?: StreamParserOptions);
|
|
1309
|
+
private takeTextUntil;
|
|
1310
|
+
/**
|
|
1311
|
+
* Parse gadget name, handling both old format (name:invocationId) and new format (just name).
|
|
1312
|
+
* For new format, generates a unique invocation ID.
|
|
1313
|
+
*/
|
|
1314
|
+
private parseGadgetName;
|
|
1315
|
+
/**
|
|
1316
|
+
* Extract the error message from a parse error.
|
|
1317
|
+
* Preserves full message since the error formatter adds contextual help
|
|
1318
|
+
* that benefits from precise, detailed error information.
|
|
1319
|
+
*/
|
|
1320
|
+
private extractParseError;
|
|
1321
|
+
/**
|
|
1322
|
+
* Parse parameter string using block format
|
|
1323
|
+
*/
|
|
1324
|
+
private parseParameters;
|
|
1325
|
+
feed(chunk: string): Generator<StreamEvent>;
|
|
1326
|
+
finalize(): Generator<StreamEvent>;
|
|
1327
|
+
reset(): void;
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
/**
|
|
1331
|
+
* Type-safe gadget factory with automatic parameter inference.
|
|
1332
|
+
*
|
|
1333
|
+
* Gadget eliminates the need for manual type assertions
|
|
1334
|
+
* by automatically inferring parameter types from the Zod schema.
|
|
1335
|
+
*
|
|
1336
|
+
* @example
|
|
1337
|
+
* ```typescript
|
|
1338
|
+
* class Calculator extends Gadget({
|
|
1339
|
+
* description: "Performs arithmetic operations",
|
|
1340
|
+
* schema: z.object({
|
|
1341
|
+
* operation: z.enum(["add", "subtract"]),
|
|
1342
|
+
* a: z.number(),
|
|
1343
|
+
* b: z.number(),
|
|
1344
|
+
* }),
|
|
1345
|
+
* }) {
|
|
1346
|
+
* // ✨ params is automatically typed!
|
|
1347
|
+
* execute(params: this['params']): string {
|
|
1348
|
+
* const { operation, a, b } = params; // All typed!
|
|
1349
|
+
* return operation === "add" ? String(a + b) : String(a - b);
|
|
1350
|
+
* }
|
|
1351
|
+
* }
|
|
1352
|
+
* ```
|
|
1353
|
+
*/
|
|
1354
|
+
|
|
1286
1355
|
/**
|
|
1287
1356
|
* Infer the TypeScript type from a Zod schema.
|
|
1288
1357
|
*/
|
|
@@ -1389,7 +1458,7 @@ declare function Gadget<TSchema extends ZodType>(config: GadgetConfig<TSchema>):
|
|
|
1389
1458
|
*/
|
|
1390
1459
|
execute(params: Record<string, unknown>): string | Promise<string>;
|
|
1391
1460
|
get instruction(): string;
|
|
1392
|
-
getInstruction(
|
|
1461
|
+
getInstruction(argPrefix?: string): string;
|
|
1393
1462
|
} & {
|
|
1394
1463
|
params: InferSchema<TSchema>;
|
|
1395
1464
|
};
|
|
@@ -1766,4 +1835,4 @@ declare class OpenAIChatProvider extends BaseProviderAdapter {
|
|
|
1766
1835
|
}
|
|
1767
1836
|
declare function createOpenAIProviderFromEnv(): OpenAIChatProvider | null;
|
|
1768
1837
|
|
|
1769
|
-
export { AgentHooks, AnthropicMessagesProvider, BaseGadget, BreakLoopException, ConversationManager, type CreateGadgetConfig, Gadget, type GadgetConfig, GadgetExample, GadgetExecutionResult, GadgetExecutor, GadgetOutputStore, GadgetRegistry, GeminiGenerativeProvider, HookPresets, HumanInputException, type IConversationManager, LLMGenerationOptions, LLMMessage, LLMStream, LLMStreamChunk, type LoggerOptions, type LoggingOptions, MODEL_ALIASES, ModelDescriptor, ModelRegistry, ModelSpec, OpenAIChatProvider, ParsedGadgetCall, ProviderAdapter, type StoredOutput, StreamEvent, type StreamProcessingResult, StreamProcessor, type StreamProcessorOptions, TokenUsage, type ValidationIssue, type ValidationResult, createAnthropicProviderFromEnv, createGadget, createGadgetOutputViewer, createGeminiProviderFromEnv, createLogger, createOpenAIProviderFromEnv, defaultLogger, discoverProviderAdapters, getModelId, getProvider, hasProviderPrefix, resolveModel, validateAndApplyDefaults, validateGadgetParams };
|
|
1838
|
+
export { AgentHooks, AnthropicMessagesProvider, BaseGadget, BreakLoopException, ConversationManager, type CreateGadgetConfig, Gadget, type GadgetConfig, GadgetExample, GadgetExecutionResult, GadgetExecutor, GadgetOutputStore, GadgetRegistry, GeminiGenerativeProvider, HookPresets, HumanInputException, type IConversationManager, LLMGenerationOptions, LLMMessage, LLMStream, LLMStreamChunk, type LoggerOptions, type LoggingOptions, MODEL_ALIASES, ModelDescriptor, ModelRegistry, ModelSpec, OpenAIChatProvider, ParsedGadgetCall, ProviderAdapter, type StoredOutput, StreamEvent, StreamParser, type StreamProcessingResult, StreamProcessor, type StreamProcessorOptions, TokenUsage, type ValidationIssue, type ValidationResult, createAnthropicProviderFromEnv, createGadget, createGadgetOutputViewer, createGeminiProviderFromEnv, createLogger, createOpenAIProviderFromEnv, defaultLogger, discoverProviderAdapters, getModelId, getProvider, hasProviderPrefix, resolveModel, validateAndApplyDefaults, validateGadgetParams };
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
mockLLM,
|
|
11
11
|
validateAndApplyDefaults,
|
|
12
12
|
validateGadgetParams
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-OIPLYP7M.js";
|
|
14
14
|
import {
|
|
15
15
|
AgentBuilder,
|
|
16
16
|
AnthropicMessagesProvider,
|
|
@@ -74,7 +74,7 @@ import {
|
|
|
74
74
|
resolveRulesTemplate,
|
|
75
75
|
runWithHandlers,
|
|
76
76
|
stream
|
|
77
|
-
} from "./chunk-
|
|
77
|
+
} from "./chunk-VXPZQZF5.js";
|
|
78
78
|
|
|
79
79
|
// src/index.ts
|
|
80
80
|
init_builder();
|
|
@@ -40,7 +40,7 @@ interface GadgetExecutionResult {
|
|
|
40
40
|
interface ParsedGadgetCall {
|
|
41
41
|
gadgetName: string;
|
|
42
42
|
invocationId: string;
|
|
43
|
-
|
|
43
|
+
parametersRaw: string;
|
|
44
44
|
parameters?: Record<string, unknown>;
|
|
45
45
|
parseError?: string;
|
|
46
46
|
}
|
|
@@ -116,46 +116,6 @@ type TextOnlyAction = {
|
|
|
116
116
|
parameters: Record<string, unknown>;
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
type ParameterFormat = "json" | "yaml" | "toml" | "auto";
|
|
120
|
-
interface StreamParserOptions {
|
|
121
|
-
startPrefix?: string;
|
|
122
|
-
endPrefix?: string;
|
|
123
|
-
/**
|
|
124
|
-
* Format for parsing gadget parameters.
|
|
125
|
-
* - 'json': Parse as JSON (more robust, recommended for complex nested data)
|
|
126
|
-
* - 'yaml': Parse as YAML (backward compatible)
|
|
127
|
-
* - 'auto': Try JSON first, fall back to YAML
|
|
128
|
-
* @default 'json'
|
|
129
|
-
*/
|
|
130
|
-
parameterFormat?: ParameterFormat;
|
|
131
|
-
}
|
|
132
|
-
declare class StreamParser {
|
|
133
|
-
private buffer;
|
|
134
|
-
private lastReportedTextLength;
|
|
135
|
-
private readonly startPrefix;
|
|
136
|
-
private readonly endPrefix;
|
|
137
|
-
private readonly parameterFormat;
|
|
138
|
-
constructor(options?: StreamParserOptions);
|
|
139
|
-
private takeTextUntil;
|
|
140
|
-
/**
|
|
141
|
-
* Parse gadget name, handling both old format (name:invocationId) and new format (just name).
|
|
142
|
-
* For new format, generates a unique invocation ID.
|
|
143
|
-
*/
|
|
144
|
-
private parseGadgetName;
|
|
145
|
-
/**
|
|
146
|
-
* Truncate verbose parse errors to avoid context overflow.
|
|
147
|
-
* Keeps first meaningful line and limits total length.
|
|
148
|
-
*/
|
|
149
|
-
private truncateParseError;
|
|
150
|
-
/**
|
|
151
|
-
* Parse parameter string according to configured format
|
|
152
|
-
*/
|
|
153
|
-
private parseParameters;
|
|
154
|
-
feed(chunk: string): Generator<StreamEvent>;
|
|
155
|
-
finalize(): Generator<StreamEvent>;
|
|
156
|
-
reset(): void;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
119
|
/**
|
|
160
120
|
* Internal base class for gadgets. Most users should use the `Gadget` class
|
|
161
121
|
* (formerly TypedGadget) or `createGadget()` function instead, as they provide
|
|
@@ -205,29 +165,29 @@ declare abstract class BaseGadget {
|
|
|
205
165
|
/**
|
|
206
166
|
* Auto-generated instruction text for the LLM.
|
|
207
167
|
* Combines name, description, and parameter schema into a formatted instruction.
|
|
208
|
-
* @deprecated Use getInstruction(
|
|
168
|
+
* @deprecated Use getInstruction() instead
|
|
209
169
|
*/
|
|
210
170
|
get instruction(): string;
|
|
211
171
|
/**
|
|
212
|
-
* Generate instruction text for the LLM
|
|
172
|
+
* Generate instruction text for the LLM.
|
|
213
173
|
* Combines name, description, and parameter schema into a formatted instruction.
|
|
214
174
|
*
|
|
215
|
-
* @param
|
|
175
|
+
* @param argPrefix - Optional custom argument prefix for block format examples
|
|
216
176
|
* @returns Formatted instruction string
|
|
217
177
|
*/
|
|
218
|
-
getInstruction(
|
|
178
|
+
getInstruction(argPrefix?: string): string;
|
|
219
179
|
}
|
|
220
180
|
|
|
221
181
|
/**
|
|
222
182
|
* Context provided to prompt template functions for rendering dynamic content.
|
|
223
183
|
*/
|
|
224
184
|
interface PromptContext {
|
|
225
|
-
/** The parameter format being used (json or yaml) */
|
|
226
|
-
parameterFormat: ParameterFormat;
|
|
227
185
|
/** Custom gadget start prefix */
|
|
228
186
|
startPrefix: string;
|
|
229
187
|
/** Custom gadget end prefix */
|
|
230
188
|
endPrefix: string;
|
|
189
|
+
/** Custom argument prefix for block format */
|
|
190
|
+
argPrefix: string;
|
|
231
191
|
/** Number of gadgets being registered */
|
|
232
192
|
gadgetCount: number;
|
|
233
193
|
/** Names of all gadgets */
|
|
@@ -268,41 +228,16 @@ interface PromptConfig {
|
|
|
268
228
|
*/
|
|
269
229
|
criticalUsage?: PromptTemplate;
|
|
270
230
|
/**
|
|
271
|
-
* Format description for
|
|
272
|
-
* Default
|
|
231
|
+
* Format description for the block parameter format.
|
|
232
|
+
* Default uses the configured argPrefix dynamically.
|
|
273
233
|
*/
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Format description for JSON parameter format.
|
|
277
|
-
* Default: "Parameters in JSON format (valid JSON object)"
|
|
278
|
-
*/
|
|
279
|
-
formatDescriptionJson?: PromptTemplate;
|
|
280
|
-
/**
|
|
281
|
-
* Format description for TOML parameter format.
|
|
282
|
-
* Default: "Parameters in TOML format (key = value pairs, use heredoc for multiline: key = <<<EOF ... EOF)"
|
|
283
|
-
*/
|
|
284
|
-
formatDescriptionToml?: PromptTemplate;
|
|
234
|
+
formatDescription?: PromptTemplate;
|
|
285
235
|
/**
|
|
286
236
|
* Rules that appear in the rules section.
|
|
287
237
|
* Can be an array of strings or a function that returns an array.
|
|
288
|
-
* Default includes
|
|
238
|
+
* Default includes rules about not using function calling.
|
|
289
239
|
*/
|
|
290
240
|
rules?: PromptTemplate | string[] | ((context: PromptContext) => string[]);
|
|
291
|
-
/**
|
|
292
|
-
* Schema label for JSON format.
|
|
293
|
-
* Default: "\n\nInput Schema (JSON):"
|
|
294
|
-
*/
|
|
295
|
-
schemaLabelJson?: PromptTemplate;
|
|
296
|
-
/**
|
|
297
|
-
* Schema label for YAML format.
|
|
298
|
-
* Default: "\n\nInput Schema (YAML):"
|
|
299
|
-
*/
|
|
300
|
-
schemaLabelYaml?: PromptTemplate;
|
|
301
|
-
/**
|
|
302
|
-
* Schema label for TOML format.
|
|
303
|
-
* Default: "\n\nInput Schema (TOML):"
|
|
304
|
-
*/
|
|
305
|
-
schemaLabelToml?: PromptTemplate;
|
|
306
241
|
/**
|
|
307
242
|
* Custom examples to show in the examples section.
|
|
308
243
|
* If provided, replaces the default examples entirely.
|
|
@@ -312,7 +247,6 @@ interface PromptConfig {
|
|
|
312
247
|
}
|
|
313
248
|
/**
|
|
314
249
|
* Default prompt templates used by llmist.
|
|
315
|
-
* These match the original hardcoded strings.
|
|
316
250
|
*/
|
|
317
251
|
declare const DEFAULT_PROMPTS: Required<Omit<PromptConfig, "rules" | "customExamples"> & {
|
|
318
252
|
rules: (context: PromptContext) => string[];
|
|
@@ -338,17 +272,19 @@ declare class LLMMessageBuilder {
|
|
|
338
272
|
private readonly messages;
|
|
339
273
|
private startPrefix;
|
|
340
274
|
private endPrefix;
|
|
275
|
+
private argPrefix;
|
|
341
276
|
private promptConfig;
|
|
342
277
|
constructor(promptConfig?: PromptConfig);
|
|
343
278
|
/**
|
|
344
279
|
* Set custom prefixes for gadget markers.
|
|
345
280
|
* Used to configure history builder to match system prompt markers.
|
|
346
281
|
*/
|
|
347
|
-
withPrefixes(startPrefix: string, endPrefix: string): this;
|
|
282
|
+
withPrefixes(startPrefix: string, endPrefix: string, argPrefix?: string): this;
|
|
348
283
|
addSystem(content: string, metadata?: Record<string, unknown>): this;
|
|
349
|
-
addGadgets(gadgets: BaseGadget[],
|
|
284
|
+
addGadgets(gadgets: BaseGadget[], options?: {
|
|
350
285
|
startPrefix?: string;
|
|
351
286
|
endPrefix?: string;
|
|
287
|
+
argPrefix?: string;
|
|
352
288
|
}): this;
|
|
353
289
|
private buildGadgetsSection;
|
|
354
290
|
private buildUsageSection;
|
|
@@ -356,8 +292,12 @@ declare class LLMMessageBuilder {
|
|
|
356
292
|
private buildRulesSection;
|
|
357
293
|
addUser(content: string, metadata?: Record<string, unknown>): this;
|
|
358
294
|
addAssistant(content: string, metadata?: Record<string, unknown>): this;
|
|
359
|
-
addGadgetCall(gadget: string, parameters: Record<string, unknown>, result: string
|
|
360
|
-
|
|
295
|
+
addGadgetCall(gadget: string, parameters: Record<string, unknown>, result: string): this;
|
|
296
|
+
/**
|
|
297
|
+
* Format parameters as Block format with JSON Pointer paths.
|
|
298
|
+
* Uses the configured argPrefix for consistency with system prompt.
|
|
299
|
+
*/
|
|
300
|
+
private formatBlockParameters;
|
|
361
301
|
build(): LLMMessage[];
|
|
362
302
|
}
|
|
363
303
|
|
|
@@ -972,7 +912,7 @@ interface EventHandlers {
|
|
|
972
912
|
onGadgetCall?: (call: {
|
|
973
913
|
gadgetName: string;
|
|
974
914
|
parameters?: Record<string, unknown>;
|
|
975
|
-
|
|
915
|
+
parametersRaw: string;
|
|
976
916
|
}) => void | Promise<void>;
|
|
977
917
|
/** Called when a gadget execution completes */
|
|
978
918
|
onGadgetResult?: (result: {
|
|
@@ -1553,12 +1493,12 @@ interface AgentOptions {
|
|
|
1553
1493
|
hooks?: AgentHooks;
|
|
1554
1494
|
/** Callback for human input */
|
|
1555
1495
|
onHumanInputRequired?: (question: string) => Promise<string>;
|
|
1556
|
-
/** Parameter format */
|
|
1557
|
-
parameterFormat?: ParameterFormat;
|
|
1558
1496
|
/** Custom gadget start prefix */
|
|
1559
1497
|
gadgetStartPrefix?: string;
|
|
1560
1498
|
/** Custom gadget end prefix */
|
|
1561
1499
|
gadgetEndPrefix?: string;
|
|
1500
|
+
/** Custom gadget argument prefix for block format parameters */
|
|
1501
|
+
gadgetArgPrefix?: string;
|
|
1562
1502
|
/** Initial messages */
|
|
1563
1503
|
initialMessages?: Array<{
|
|
1564
1504
|
role: "system" | "user" | "assistant";
|
|
@@ -1620,9 +1560,9 @@ declare class Agent {
|
|
|
1620
1560
|
private readonly hooks;
|
|
1621
1561
|
private readonly conversation;
|
|
1622
1562
|
private readonly registry;
|
|
1623
|
-
private readonly parameterFormat;
|
|
1624
1563
|
private readonly gadgetStartPrefix?;
|
|
1625
1564
|
private readonly gadgetEndPrefix?;
|
|
1565
|
+
private readonly gadgetArgPrefix?;
|
|
1626
1566
|
private readonly onHumanInputRequired?;
|
|
1627
1567
|
private readonly textOnlyHandler;
|
|
1628
1568
|
private readonly textWithGadgetsHandler?;
|
|
@@ -1751,9 +1691,9 @@ declare class AgentBuilder {
|
|
|
1751
1691
|
private gadgets;
|
|
1752
1692
|
private initialMessages;
|
|
1753
1693
|
private onHumanInputRequired?;
|
|
1754
|
-
private parameterFormat?;
|
|
1755
1694
|
private gadgetStartPrefix?;
|
|
1756
1695
|
private gadgetEndPrefix?;
|
|
1696
|
+
private gadgetArgPrefix?;
|
|
1757
1697
|
private textOnlyHandler?;
|
|
1758
1698
|
private textWithGadgetsHandler?;
|
|
1759
1699
|
private stopOnGadgetError?;
|
|
@@ -1898,18 +1838,6 @@ declare class AgentBuilder {
|
|
|
1898
1838
|
* ```
|
|
1899
1839
|
*/
|
|
1900
1840
|
onHumanInput(handler: (question: string) => Promise<string>): this;
|
|
1901
|
-
/**
|
|
1902
|
-
* Set the parameter format for gadget calls.
|
|
1903
|
-
*
|
|
1904
|
-
* @param format - Parameter format ("json" or "xml")
|
|
1905
|
-
* @returns This builder for chaining
|
|
1906
|
-
*
|
|
1907
|
-
* @example
|
|
1908
|
-
* ```typescript
|
|
1909
|
-
* .withParameterFormat("xml")
|
|
1910
|
-
* ```
|
|
1911
|
-
*/
|
|
1912
|
-
withParameterFormat(format: ParameterFormat): this;
|
|
1913
1841
|
/**
|
|
1914
1842
|
* Set custom gadget marker prefix.
|
|
1915
1843
|
*
|
|
@@ -1934,6 +1862,18 @@ declare class AgentBuilder {
|
|
|
1934
1862
|
* ```
|
|
1935
1863
|
*/
|
|
1936
1864
|
withGadgetEndPrefix(suffix: string): this;
|
|
1865
|
+
/**
|
|
1866
|
+
* Set custom argument prefix for block format parameters.
|
|
1867
|
+
*
|
|
1868
|
+
* @param prefix - Custom prefix for argument markers (default: "!!!ARG:")
|
|
1869
|
+
* @returns This builder for chaining
|
|
1870
|
+
*
|
|
1871
|
+
* @example
|
|
1872
|
+
* ```typescript
|
|
1873
|
+
* .withGadgetArgPrefix("<<ARG>>")
|
|
1874
|
+
* ```
|
|
1875
|
+
*/
|
|
1876
|
+
withGadgetArgPrefix(prefix: string): this;
|
|
1937
1877
|
/**
|
|
1938
1878
|
* Set the text-only handler strategy.
|
|
1939
1879
|
*
|
|
@@ -2114,10 +2054,9 @@ declare class AgentBuilder {
|
|
|
2114
2054
|
*/
|
|
2115
2055
|
withSyntheticGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): this;
|
|
2116
2056
|
/**
|
|
2117
|
-
* Format parameters
|
|
2118
|
-
* Uses heredoc for multiline string values.
|
|
2057
|
+
* Format parameters as block format with JSON Pointer paths.
|
|
2119
2058
|
*/
|
|
2120
|
-
private
|
|
2059
|
+
private formatBlockParameters;
|
|
2121
2060
|
/**
|
|
2122
2061
|
* Build and create the agent with the given user prompt.
|
|
2123
2062
|
* Returns the Agent instance ready to run.
|
|
@@ -2773,4 +2712,4 @@ declare function createTextMockStream(text: string, options?: {
|
|
|
2773
2712
|
usage?: MockResponse["usage"];
|
|
2774
2713
|
}): LLMStream;
|
|
2775
2714
|
|
|
2776
|
-
export { type
|
|
2715
|
+
export { type MessageInterceptorContext as $, type AgentHooks as A, BaseGadget as B, runWithHandlers as C, type AfterGadgetExecutionAction as D, type EventHandlers as E, type AfterGadgetExecutionControllerContext as F, GadgetRegistry as G, type HistoryMessage as H, type AfterLLMCallAction as I, type AfterLLMCallControllerContext as J, type AfterLLMErrorAction as K, type LLMMessage as L, MockProviderAdapter as M, type AgentOptions as N, type BeforeGadgetExecutionAction as O, type ParsedGadgetCall as P, type BeforeLLMCallAction as Q, type ChunkInterceptorContext as R, type StreamEvent as S, type TokenUsage as T, type Controllers as U, type GadgetExecutionControllerContext as V, type GadgetParameterInterceptorContext as W, type GadgetResultInterceptorContext as X, type Interceptors as Y, type LLMCallControllerContext as Z, type LLMErrorControllerContext as _, MockBuilder as a, type ObserveChunkContext as a0, type ObserveGadgetCompleteContext as a1, type ObserveGadgetStartContext as a2, type ObserveLLMCallContext as a3, type ObserveLLMCompleteContext as a4, type ObserveLLMErrorContext as a5, type Observers as a6, type LLMistOptions as a7, LLMist as a8, type LLMRole as a9, LLMMessageBuilder as aa, type CostEstimate as ab, type ModelFeatures as ac, type ModelLimits as ad, type ModelPricing as ae, type ProviderIdentifier as af, ModelIdentifierParser as ag, type PromptConfig as ah, type PromptContext as ai, type PromptTemplate as aj, DEFAULT_PROMPTS as ak, resolvePromptTemplate as al, resolveRulesTemplate as am, type QuickOptions as an, complete as ao, stream as ap, type GadgetClass as aq, type GadgetOrClass as ar, type TextOnlyAction as as, type TextOnlyContext as at, type TextOnlyCustomHandler as au, type TextOnlyGadgetConfig as av, type TextOnlyHandler as aw, type TextOnlyStrategy as ax, createMockClient as b, createMockAdapter as c, MockManager as d, createMockStream as e, createTextMockStream as f, getMockManager as g, type MockMatcher as h, type MockMatcherContext as i, type MockOptions as j, type MockRegistration as k, type MockResponse as l, mockLLM as m, type MockStats as n, ModelRegistry as o, type LLMStreamChunk as p, type GadgetExample as q, type GadgetExecutionResult as r, type ProviderAdapter as s, type ModelDescriptor as t, type ModelSpec as u, type LLMGenerationOptions as v, type LLMStream as w, AgentBuilder as x, collectEvents as y, collectText as z };
|