llm-exe 2.3.1 → 2.3.3

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/index.d.mts CHANGED
@@ -226,14 +226,14 @@ declare class StringExtractParser extends BaseParser<string> {
226
226
  * Creates a parser based on the given type.
227
227
  * @template S - JSON schema type.
228
228
  * @param type - The type of parser to create.
229
- * @returns An instance of ListToKeyValueParser.
229
+ * @returns An instance of MarkdownCodeBlocksParser.
230
230
  */
231
231
  declare function createParser<T extends Extract<CreateParserType, "markdownCodeBlocks">>(type: T, options?: BaseParserOptions): MarkdownCodeBlocksParser;
232
232
  /**
233
233
  * Creates a parser based on the given type.
234
234
  * @template S - JSON schema type.
235
235
  * @param type - The type of parser to create.
236
- * @returns An instance of ListToKeyValueParser.
236
+ * @returns An instance of MarkdownCodeBlockParser.
237
237
  */
238
238
  declare function createParser<T extends Extract<CreateParserType, "markdownCodeBlock">>(type: T, options?: BaseParserOptions): MarkdownCodeBlockParser;
239
239
  /**
@@ -432,8 +432,8 @@ declare class ChatPrompt<I extends Record<string, any>> extends BasePrompt<I> {
432
432
  readonly type: ChatPromptType;
433
433
  /**
434
434
  * @property parseUserTemplates - Whether or not to allow parsing
435
- * user messages with the template engine. This could be a risk,
436
- * so we only parse user messages if explicitly set.
435
+ * user messages with the template engine. Defaults to true.
436
+ * Set `allowUnsafeUserTemplate: false` in options to disable.
437
437
  */
438
438
  private parseUserTemplates;
439
439
  /**
@@ -468,13 +468,13 @@ declare class ChatPrompt<I extends Record<string, any>> extends BasePrompt<I> {
468
468
  */
469
469
  addAssistantMessage(content: string): ChatPrompt<I>;
470
470
  /**
471
- * addFunctionMessage Helper to add an assistant message to the prompt.
471
+ * addFunctionMessage Helper to add a function message to the prompt.
472
472
  * @param content The message content.
473
473
  * @return ChatPrompt so it can be chained.
474
474
  */
475
475
  addFunctionMessage(content: string, name: string, id?: string): ChatPrompt<I>;
476
476
  /**
477
- * addFunctionCallMessage Helper to add an assistant message to the prompt.
477
+ * addFunctionCallMessage Helper to add a function_call message to the prompt.
478
478
  * @param content The message content.
479
479
  * @return ChatPrompt so it can be chained.
480
480
  */
@@ -602,6 +602,10 @@ declare abstract class BaseExecutor<I extends PlainObject, O = any, H extends Ba
602
602
  */
603
603
  hooks: any;
604
604
  readonly allowedHooks: any[];
605
+ /**
606
+ * @property maxHooksPerEvent - Maximum number of hooks allowed per event
607
+ */
608
+ readonly maxHooksPerEvent: number;
605
609
  constructor(name: string, type: string, options?: CoreExecutorExecuteOptions<H>);
606
610
  abstract handler(input: I, _options?: any): Promise<any>;
607
611
  /**
@@ -635,6 +639,18 @@ declare abstract class BaseExecutor<I extends PlainObject, O = any, H extends Ba
635
639
  once(eventName: keyof H, fn: ListenerFunction): this;
636
640
  withTraceId(traceId: string): this;
637
641
  getTraceId(): string | null;
642
+ /**
643
+ * Clear all hooks for a specific event or all events
644
+ * Useful for preventing memory leaks in long-running processes
645
+ * @param eventName - The event name to clear hooks for
646
+ */
647
+ clearHooks(eventName?: keyof H): this;
648
+ /**
649
+ * Get the count of hooks for monitoring memory usage
650
+ * @param eventName - Optional event name to get count for
651
+ * @returns Hook count for specific event or all events
652
+ */
653
+ getHookCount(eventName?: keyof H): number | Record<string, number>;
638
654
  }
639
655
 
640
656
  /**
@@ -674,7 +690,7 @@ declare class Dialogue extends BaseStateItem<IChatMessages> {
674
690
  setUserMessage(content: string | IChatMessageContentDetailed[], name?: string): this;
675
691
  setAssistantMessage(content: string | OutputResultsText): this;
676
692
  setSystemMessage(content: string): this;
677
- setToolMessage(content: string, name: string, id?: string): void;
693
+ setToolMessage(content: string, name: string, id?: string): this;
678
694
  setFunctionMessage(content: string, name: string, id?: string): this;
679
695
  /**
680
696
  * Set
@@ -683,7 +699,7 @@ declare class Dialogue extends BaseStateItem<IChatMessages> {
683
699
  name: string;
684
700
  arguments: string;
685
701
  id?: string;
686
- }): void;
702
+ }): this;
687
703
  setFunctionCallMessage(input: {
688
704
  name: string;
689
705
  arguments: string;
@@ -938,6 +954,8 @@ interface BaseLlmOptions {
938
954
  numOfAttempts?: number;
939
955
  jitter?: "none" | "full";
940
956
  promptType?: PromptType;
957
+ endpoint?: string;
958
+ headers?: Record<string, string>;
941
959
  }
942
960
  interface GenericEmbeddingOptions extends BaseLlmOptions {
943
961
  model?: string;
@@ -966,6 +984,7 @@ interface GenericLLm extends BaseLlmOptions {
966
984
  streamOptions?: Record<string, any>;
967
985
  maxTokens?: number;
968
986
  stopSequences?: string[];
987
+ effort?: "minimal" | "low" | "medium" | "high";
969
988
  }
970
989
  interface OpenAiRequest extends GenericLLm {
971
990
  model: string;
@@ -984,6 +1003,11 @@ interface AmazonBedrockRequest extends GenericLLm {
984
1003
  interface AnthropicRequest extends GenericLLm {
985
1004
  model: string;
986
1005
  anthropicApiKey?: string;
1006
+ topK?: number;
1007
+ metadata?: {
1008
+ user_id?: string;
1009
+ };
1010
+ serviceTier?: "auto" | "standard_only";
987
1011
  }
988
1012
  interface GeminiRequest extends GenericLLm {
989
1013
  model: string;
@@ -1033,6 +1057,30 @@ type AllLlm = {
1033
1057
  };
1034
1058
  };
1035
1059
  type AllUseLlmOptions = AllLlm & {
1060
+ "openai.gpt-5.2": {
1061
+ input: Omit<OpenAiRequest, "model">;
1062
+ };
1063
+ "openai.gpt-5-mini": {
1064
+ input: Omit<OpenAiRequest, "model">;
1065
+ };
1066
+ "openai.gpt-5-nano": {
1067
+ input: Omit<OpenAiRequest, "model">;
1068
+ };
1069
+ "openai.gpt-4.1": {
1070
+ input: Omit<OpenAiRequest, "model">;
1071
+ };
1072
+ "openai.gpt-4.1-mini": {
1073
+ input: Omit<OpenAiRequest, "model">;
1074
+ };
1075
+ "openai.gpt-4.1-nano": {
1076
+ input: Omit<OpenAiRequest, "model">;
1077
+ };
1078
+ "openai.o3": {
1079
+ input: Omit<OpenAiRequest, "model">;
1080
+ };
1081
+ "openai.o4-mini": {
1082
+ input: Omit<OpenAiRequest, "model">;
1083
+ };
1036
1084
  "openai.gpt-4": {
1037
1085
  input: OpenAiRequest;
1038
1086
  };
@@ -1042,6 +1090,12 @@ type AllUseLlmOptions = AllLlm & {
1042
1090
  "openai.gpt-4o-mini": {
1043
1091
  input: Omit<OpenAiRequest, "model">;
1044
1092
  };
1093
+ "anthropic.claude-opus-4-6": {
1094
+ input: Omit<AnthropicRequest, "model">;
1095
+ };
1096
+ "anthropic.claude-sonnet-4-6": {
1097
+ input: Omit<AnthropicRequest, "model">;
1098
+ };
1045
1099
  "anthropic.claude-sonnet-4-0": {
1046
1100
  input: Omit<AnthropicRequest, "model">;
1047
1101
  };
@@ -1051,18 +1105,24 @@ type AllUseLlmOptions = AllLlm & {
1051
1105
  "anthropic.claude-3-7-sonnet": {
1052
1106
  input: Omit<AnthropicRequest, "model">;
1053
1107
  };
1054
- "anthropic.claude-3-5-sonnet": {
1108
+ "anthropic.claude-sonnet-4": {
1055
1109
  input: Omit<AnthropicRequest, "model">;
1056
1110
  };
1057
- "anthropic.claude-3-opus": {
1111
+ "anthropic.claude-opus-4": {
1058
1112
  input: Omit<AnthropicRequest, "model">;
1059
1113
  };
1060
- "anthropic.claude-3-sonnet": {
1114
+ "anthropic.claude-3-5-sonnet": {
1061
1115
  input: Omit<AnthropicRequest, "model">;
1062
1116
  };
1063
1117
  "anthropic.claude-3-5-haiku": {
1064
1118
  input: Omit<AnthropicRequest, "model">;
1065
1119
  };
1120
+ "anthropic.claude-3-opus": {
1121
+ input: Omit<AnthropicRequest, "model">;
1122
+ };
1123
+ "anthropic.claude-3-haiku": {
1124
+ input: Omit<AnthropicRequest, "model">;
1125
+ };
1066
1126
  "google.gemini-2.5-pro-exp-03-25": {
1067
1127
  input: Omit<GeminiRequest, "model">;
1068
1128
  };
@@ -1090,9 +1150,15 @@ type AllUseLlmOptions = AllLlm & {
1090
1150
  "xai.grok-3": {
1091
1151
  input: OpenAiRequest;
1092
1152
  };
1153
+ "xai.grok-3-mini": {
1154
+ input: Omit<OpenAiRequest, "model">;
1155
+ };
1093
1156
  "xai.grok-4": {
1094
1157
  input: OpenAiRequest;
1095
1158
  };
1159
+ "xai.grok-4-fast": {
1160
+ input: Omit<OpenAiRequest, "model">;
1161
+ };
1096
1162
  "ollama.deepseek-r1": {
1097
1163
  input: GenericLLm;
1098
1164
  };
@@ -1131,25 +1197,106 @@ interface BaseLlm<_T extends BaseLlCall = BaseLlCall> extends BaseRequest<_T> {
1131
1197
 
1132
1198
  type LlmProvider = "openai.chat" | "openai.embedding" | "google.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "xai.chat" | "google.chat" | "ollama.chat" | "deepseek.chat";
1133
1199
  interface Config<Pk = LlmProviderKey> {
1200
+ /**
1201
+ * Unique identifier for this configuration (e.g., "openai.chat.v1", "anthropic.claude-3-opus")
1202
+ * Used to reference this config when calling useLlm()
1203
+ */
1134
1204
  key: Pk;
1205
+ /**
1206
+ * The provider type this config is for (e.g., "openai.chat", "anthropic.chat")
1207
+ * Used internally for provider-specific logic
1208
+ */
1135
1209
  provider: LlmProvider;
1136
- method: string;
1210
+ /**
1211
+ * HTTP method for the API request (typically "POST" for LLM providers)
1212
+ */
1213
+ method: "POST" | "PUT" | "GET";
1214
+ /**
1215
+ * API endpoint URL template. Supports template variables using {{variable}} syntax
1216
+ * Variables are replaced with values from the state object
1217
+ * @example "https://api.openai.com/v1/chat/completions"
1218
+ * @example "https://bedrock-runtime.{{awsRegion}}.amazonaws.com/model/{{model}}/invoke"
1219
+ */
1137
1220
  endpoint: string;
1221
+ /**
1222
+ * HTTP headers template as a JSON string. Supports template variables using {{variable}} syntax
1223
+ * @example '{"Authorization":"Bearer {{openAiApiKey}}", "Content-Type": "application/json"}'
1224
+ * // TODO: make this also accept object and function
1225
+ */
1226
+ headers: string;
1138
1227
  options: {
1139
1228
  [key in string]: {
1140
- default?: number | string;
1229
+ /**
1230
+ * Default value for this parameter if not provided by the user
1231
+ * Can be a static value or a function that returns the value
1232
+ * @example 4096
1233
+ * @example () => process.env.OPENAI_API_KEY
1234
+ */
1235
+ default?: any;
1236
+ /**
1237
+ * Whether this parameter is required
1238
+ * [true, "error message"] - Required with custom error
1239
+ * [true] - Required with default error message
1240
+ * @example [true, "maxTokens is required for Anthropic"]
1241
+ */
1141
1242
  required?: [boolean, string] | [boolean];
1142
1243
  };
1143
1244
  };
1144
1245
  mapBody: {
1145
1246
  [key in string]: {
1247
+ /**
1248
+ * The target field name in the provider's request body.
1249
+ * Supports dot notation for nested fields (e.g., "response_format.type")
1250
+ */
1146
1251
  key: string;
1147
- default?: number | string;
1148
- sanitize?: (i: any, arg: Record<string, any>, arg2: Record<string, any>) => any;
1252
+ /**
1253
+ * Default value to use if the source field is not provided
1254
+ */
1255
+ default?: any;
1256
+ /**
1257
+ * Transform function to convert the value before mapping to the request body
1258
+ * @param value - The input value from the user's state
1259
+ * @param state - The complete user state object containing all parameters
1260
+ * @param config - The current Config object (for access to options, etc.)
1261
+ * @returns The transformed value to be included in the request body
1262
+ */
1263
+ transform?: (value: any, state: Record<string, any>, config: Record<string, any>) => any;
1149
1264
  };
1150
1265
  };
1151
- headers: string;
1152
- prompt?: (messages: IChatMessages) => any;
1266
+ /**
1267
+ * Maps executor-level options (jsonSchema, functions, functionCall) to provider-specific request formats
1268
+ * @optional - Only needed if provider supports these features
1269
+ */
1270
+ mapOptions?: {
1271
+ /**
1272
+ * Transform JSON schema into provider-specific format
1273
+ * @param schema - The JSON schema object
1274
+ * @param options - Executor options (e.g., functionCallStrictInput)
1275
+ * @param currentInput - Current accumulated input state (for merging)
1276
+ * @param config - The full config object
1277
+ * @returns Provider-specific request body additions
1278
+ */
1279
+ jsonSchema?: (schema: any, options: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
1280
+ /**
1281
+ * Transform function call mode into provider-specific format
1282
+ * @param call - Function call mode ("auto", "any", "none", or specific function)
1283
+ * @param options - Executor options
1284
+ * @param currentInput - Current accumulated input state (for merging)
1285
+ * @param config - The full config object
1286
+ * @returns Provider-specific request body additions
1287
+ */
1288
+ functionCall?: (call: any, options?: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
1289
+ /**
1290
+ * Transform function definitions into provider-specific format
1291
+ * @param functions - Array of function definitions
1292
+ * @param options - Executor options (e.g., functionCallStrictInput)
1293
+ * @param currentInput - Current accumulated input state (for merging)
1294
+ * @param config - The full config object
1295
+ * @returns Provider-specific request body additions
1296
+ */
1297
+ functions?: (functions: any[], options?: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
1298
+ };
1299
+ transformResponse: (result: any, _config?: Config<any>) => OutputResult;
1153
1300
  }
1154
1301
 
1155
1302
  declare function enforceResultAttributes<O>(input: any): {
@@ -1355,24 +1502,42 @@ declare const configs: {
1355
1502
  "xai.chat.v1": Config<keyof AllLlm>;
1356
1503
  "xai.grok-2": Config<keyof AllLlm>;
1357
1504
  "xai.grok-3": Config<keyof AllLlm>;
1505
+ "xai.grok-3-mini": Config<keyof AllLlm>;
1358
1506
  "xai.grok-4": Config<keyof AllLlm>;
1507
+ "xai.grok-4-fast": Config<keyof AllLlm>;
1359
1508
  "amazon:anthropic.chat.v1": Config<keyof AllLlm>;
1360
1509
  "amazon:meta.chat.v1": Config<keyof AllLlm>;
1361
1510
  "anthropic.chat.v1": Config<keyof AllLlm>;
1362
- "anthropic.claude-sonnet-4-0": Config<keyof AllLlm>;
1363
- "anthropic.claude-opus-4-0": Config<keyof AllLlm>;
1511
+ "anthropic.claude-opus-4-6": Config<keyof AllLlm>;
1512
+ "anthropic.claude-sonnet-4-6": Config<keyof AllLlm>;
1513
+ "anthropic.claude-sonnet-4": Config<keyof AllLlm>;
1514
+ "anthropic.claude-opus-4": Config<keyof AllLlm>;
1364
1515
  "anthropic.claude-3-7-sonnet": Config<keyof AllLlm>;
1365
1516
  "anthropic.claude-3-5-sonnet": Config<keyof AllLlm>;
1366
1517
  "anthropic.claude-3-5-haiku": Config<keyof AllLlm>;
1367
1518
  "anthropic.claude-3-opus": Config<keyof AllLlm>;
1519
+ "anthropic.claude-3-haiku": Config<keyof AllLlm>;
1368
1520
  "openai.chat.v1": Config<keyof AllLlm>;
1369
1521
  "openai.chat-mock.v1": Config<keyof AllLlm>;
1522
+ "openai.gpt-5.2": Config<keyof AllLlm>;
1523
+ "openai.gpt-5-mini": Config<keyof AllLlm>;
1524
+ "openai.gpt-5-nano": Config<keyof AllLlm>;
1525
+ "openai.gpt-4.1": Config<keyof AllLlm>;
1526
+ "openai.gpt-4.1-mini": Config<keyof AllLlm>;
1527
+ "openai.gpt-4.1-nano": Config<keyof AllLlm>;
1528
+ "openai.o3": Config<keyof AllLlm>;
1529
+ "openai.o4-mini": Config<keyof AllLlm>;
1370
1530
  "openai.gpt-4o": Config<keyof AllLlm>;
1371
1531
  "openai.gpt-4o-mini": Config<keyof AllLlm>;
1372
1532
  };
1373
1533
 
1374
- declare function useLlm<T extends keyof typeof configs>(provider: T, options?: AllUseLlmOptions[T]["input"]): {
1375
- call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions) => Promise<BaseLlCall>;
1534
+ declare function useLlm<T extends keyof typeof configs>(provider: T, options?: AllUseLlmOptions[T]["input"]): BaseLlm;
1535
+ declare function useLlmConfiguration<T extends keyof typeof configs>(config: Config<any>): (options?: AllUseLlmOptions[T]["input"]) => {
1536
+ call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions) => Promise<{
1537
+ getResultContent: (index?: number) => OutputResultContent[];
1538
+ getResultText: (index?: number) => string;
1539
+ getResult: () => OutputResult;
1540
+ }>;
1376
1541
  getTraceId: () => string | null;
1377
1542
  withTraceId: (id: string) => void;
1378
1543
  getMetadata: () => {
@@ -1387,6 +1552,14 @@ declare function useLlm<T extends keyof typeof configs>(provider: T, options?: A
1387
1552
  };
1388
1553
  };
1389
1554
 
1555
+ declare function createOpenAiCompatibleConfiguration<K extends Config["key"]>(overrides: {
1556
+ key: string;
1557
+ provider: string;
1558
+ endpoint: string;
1559
+ apiKeyMapping: [string, string];
1560
+ transformResponse?: any;
1561
+ }): Config<keyof AllLlm>;
1562
+
1390
1563
  declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, options: AllEmbedding[T]["input"]): {
1391
1564
  call: (messages: string | string[], options?: LlmExecutorWithFunctionsOptions) => Promise<{
1392
1565
  getEmbedding: (index?: number) => number[];
@@ -1406,4 +1579,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
1406
1579
  };
1407
1580
  };
1408
1581
 
1409
- export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type EmbeddingProviderKey, type ExecutorContext, type IChatMessages, LlmExecutorOpenAiFunctions, LlmExecutorWithFunctions, LlmNativeFunctionParser, type LlmProvider, type LlmProviderKey, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, type UseLlmKey, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createLlmFunctionExecutor, createParser, createPrompt, createState, createStateItem, defineSchema, guards, registerHelpers, registerPartials, useExecutors, useLlm, index as utils };
1582
+ export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type EmbeddingProviderKey, type ExecutorContext, type IChatMessages, LlmExecutorOpenAiFunctions, LlmExecutorWithFunctions, LlmNativeFunctionParser, type LlmProvider, type LlmProviderKey, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, type UseLlmKey, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createLlmFunctionExecutor, createOpenAiCompatibleConfiguration, createParser, createPrompt, createState, createStateItem, defineSchema, guards, registerHelpers, registerPartials, useExecutors, useLlm, useLlmConfiguration, index as utils };