llm-exe 2.3.0 → 2.3.2

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
@@ -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
  /**
@@ -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;
@@ -1042,21 +1066,33 @@ type AllUseLlmOptions = AllLlm & {
1042
1066
  "openai.gpt-4o-mini": {
1043
1067
  input: Omit<OpenAiRequest, "model">;
1044
1068
  };
1069
+ "anthropic.claude-sonnet-4-0": {
1070
+ input: Omit<AnthropicRequest, "model">;
1071
+ };
1072
+ "anthropic.claude-opus-4-0": {
1073
+ input: Omit<AnthropicRequest, "model">;
1074
+ };
1045
1075
  "anthropic.claude-3-7-sonnet": {
1046
1076
  input: Omit<AnthropicRequest, "model">;
1047
1077
  };
1048
- "anthropic.claude-3-5-sonnet": {
1078
+ "anthropic.claude-sonnet-4": {
1049
1079
  input: Omit<AnthropicRequest, "model">;
1050
1080
  };
1051
- "anthropic.claude-3-opus": {
1081
+ "anthropic.claude-opus-4": {
1052
1082
  input: Omit<AnthropicRequest, "model">;
1053
1083
  };
1054
- "anthropic.claude-3-sonnet": {
1084
+ "anthropic.claude-3-5-sonnet": {
1055
1085
  input: Omit<AnthropicRequest, "model">;
1056
1086
  };
1057
1087
  "anthropic.claude-3-5-haiku": {
1058
1088
  input: Omit<AnthropicRequest, "model">;
1059
1089
  };
1090
+ "anthropic.claude-3-opus": {
1091
+ input: Omit<AnthropicRequest, "model">;
1092
+ };
1093
+ "anthropic.claude-3-haiku": {
1094
+ input: Omit<AnthropicRequest, "model">;
1095
+ };
1060
1096
  "google.gemini-2.5-pro-exp-03-25": {
1061
1097
  input: Omit<GeminiRequest, "model">;
1062
1098
  };
@@ -1066,12 +1102,27 @@ type AllUseLlmOptions = AllLlm & {
1066
1102
  "google.gemini-2.0-flash-lite": {
1067
1103
  input: Omit<GeminiRequest, "model">;
1068
1104
  };
1105
+ "google.gemini-2.5-flash": {
1106
+ input: Omit<GeminiRequest, "model">;
1107
+ };
1108
+ "google.gemini-2.5-flash-lite": {
1109
+ input: Omit<GeminiRequest, "model">;
1110
+ };
1069
1111
  "google.gemini-1.5-pro": {
1070
1112
  input: Omit<GeminiRequest, "model">;
1071
1113
  };
1114
+ "google.gemini-2.5-pro": {
1115
+ input: Omit<GeminiRequest, "model">;
1116
+ };
1072
1117
  "xai.grok-2": {
1073
1118
  input: OpenAiRequest;
1074
1119
  };
1120
+ "xai.grok-3": {
1121
+ input: OpenAiRequest;
1122
+ };
1123
+ "xai.grok-4": {
1124
+ input: OpenAiRequest;
1125
+ };
1075
1126
  "ollama.deepseek-r1": {
1076
1127
  input: GenericLLm;
1077
1128
  };
@@ -1110,25 +1161,106 @@ interface BaseLlm<_T extends BaseLlCall = BaseLlCall> extends BaseRequest<_T> {
1110
1161
 
1111
1162
  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";
1112
1163
  interface Config<Pk = LlmProviderKey> {
1164
+ /**
1165
+ * Unique identifier for this configuration (e.g., "openai.chat.v1", "anthropic.claude-3-opus")
1166
+ * Used to reference this config when calling useLlm()
1167
+ */
1113
1168
  key: Pk;
1169
+ /**
1170
+ * The provider type this config is for (e.g., "openai.chat", "anthropic.chat")
1171
+ * Used internally for provider-specific logic
1172
+ */
1114
1173
  provider: LlmProvider;
1115
- method: string;
1174
+ /**
1175
+ * HTTP method for the API request (typically "POST" for LLM providers)
1176
+ */
1177
+ method: "POST" | "PUT" | "GET";
1178
+ /**
1179
+ * API endpoint URL template. Supports template variables using {{variable}} syntax
1180
+ * Variables are replaced with values from the state object
1181
+ * @example "https://api.openai.com/v1/chat/completions"
1182
+ * @example "https://bedrock-runtime.{{awsRegion}}.amazonaws.com/model/{{model}}/invoke"
1183
+ */
1116
1184
  endpoint: string;
1185
+ /**
1186
+ * HTTP headers template as a JSON string. Supports template variables using {{variable}} syntax
1187
+ * @example '{"Authorization":"Bearer {{openAiApiKey}}", "Content-Type": "application/json"}'
1188
+ * // TODO: make this also accept object and function
1189
+ */
1190
+ headers: string;
1117
1191
  options: {
1118
1192
  [key in string]: {
1119
- default?: number | string;
1193
+ /**
1194
+ * Default value for this parameter if not provided by the user
1195
+ * Can be a static value or a function that returns the value
1196
+ * @example 4096
1197
+ * @example () => process.env.OPENAI_API_KEY
1198
+ */
1199
+ default?: any;
1200
+ /**
1201
+ * Whether this parameter is required
1202
+ * [true, "error message"] - Required with custom error
1203
+ * [true] - Required with default error message
1204
+ * @example [true, "maxTokens is required for Anthropic"]
1205
+ */
1120
1206
  required?: [boolean, string] | [boolean];
1121
1207
  };
1122
1208
  };
1123
1209
  mapBody: {
1124
1210
  [key in string]: {
1211
+ /**
1212
+ * The target field name in the provider's request body.
1213
+ * Supports dot notation for nested fields (e.g., "response_format.type")
1214
+ */
1125
1215
  key: string;
1126
- default?: number | string;
1127
- sanitize?: (i: any, arg: Record<string, any>, arg2: Record<string, any>) => any;
1216
+ /**
1217
+ * Default value to use if the source field is not provided
1218
+ */
1219
+ default?: any;
1220
+ /**
1221
+ * Transform function to convert the value before mapping to the request body
1222
+ * @param value - The input value from the user's state
1223
+ * @param state - The complete user state object containing all parameters
1224
+ * @param config - The current Config object (for access to options, etc.)
1225
+ * @returns The transformed value to be included in the request body
1226
+ */
1227
+ transform?: (value: any, state: Record<string, any>, config: Record<string, any>) => any;
1128
1228
  };
1129
1229
  };
1130
- headers: string;
1131
- prompt?: (messages: IChatMessages) => any;
1230
+ /**
1231
+ * Maps executor-level options (jsonSchema, functions, functionCall) to provider-specific request formats
1232
+ * @optional - Only needed if provider supports these features
1233
+ */
1234
+ mapOptions?: {
1235
+ /**
1236
+ * Transform JSON schema into provider-specific format
1237
+ * @param schema - The JSON schema object
1238
+ * @param options - Executor options (e.g., functionCallStrictInput)
1239
+ * @param currentInput - Current accumulated input state (for merging)
1240
+ * @param config - The full config object
1241
+ * @returns Provider-specific request body additions
1242
+ */
1243
+ jsonSchema?: (schema: any, options: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
1244
+ /**
1245
+ * Transform function call mode into provider-specific format
1246
+ * @param call - Function call mode ("auto", "any", "none", or specific function)
1247
+ * @param options - Executor options
1248
+ * @param currentInput - Current accumulated input state (for merging)
1249
+ * @param config - The full config object
1250
+ * @returns Provider-specific request body additions
1251
+ */
1252
+ functionCall?: (call: any, options?: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
1253
+ /**
1254
+ * Transform function definitions into provider-specific format
1255
+ * @param functions - Array of function definitions
1256
+ * @param options - Executor options (e.g., functionCallStrictInput)
1257
+ * @param currentInput - Current accumulated input state (for merging)
1258
+ * @param config - The full config object
1259
+ * @returns Provider-specific request body additions
1260
+ */
1261
+ functions?: (functions: any[], options?: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
1262
+ };
1263
+ transformResponse: (result: any, _config?: Config<any>) => OutputResult;
1132
1264
  }
1133
1265
 
1134
1266
  declare function enforceResultAttributes<O>(input: any): {
@@ -1321,7 +1453,10 @@ declare const configs: {
1321
1453
  "google.chat.v1": Config<keyof AllLlm>;
1322
1454
  "google.gemini-2.0-flash": Config<keyof AllLlm>;
1323
1455
  "google.gemini-2.0-flash-lite": Config<keyof AllLlm>;
1456
+ "google.gemini-2.5-flash": Config<keyof AllLlm>;
1457
+ "google.gemini-2.5-flash-lite": Config<keyof AllLlm>;
1324
1458
  "google.gemini-1.5-pro": Config<keyof AllLlm>;
1459
+ "google.gemini-2.5-pro": Config<keyof AllLlm>;
1325
1460
  "ollama.chat.v1": Config<keyof AllLlm>;
1326
1461
  "ollama.deepseek-r1": Config<keyof AllLlm>;
1327
1462
  "ollama.llama3.3": Config<keyof AllLlm>;
@@ -1330,21 +1465,31 @@ declare const configs: {
1330
1465
  "ollama.qwq": Config<keyof AllLlm>;
1331
1466
  "xai.chat.v1": Config<keyof AllLlm>;
1332
1467
  "xai.grok-2": Config<keyof AllLlm>;
1468
+ "xai.grok-3": Config<keyof AllLlm>;
1469
+ "xai.grok-4": Config<keyof AllLlm>;
1333
1470
  "amazon:anthropic.chat.v1": Config<keyof AllLlm>;
1334
1471
  "amazon:meta.chat.v1": Config<keyof AllLlm>;
1335
1472
  "anthropic.chat.v1": Config<keyof AllLlm>;
1473
+ "anthropic.claude-sonnet-4": Config<keyof AllLlm>;
1474
+ "anthropic.claude-opus-4": Config<keyof AllLlm>;
1336
1475
  "anthropic.claude-3-7-sonnet": Config<keyof AllLlm>;
1337
1476
  "anthropic.claude-3-5-sonnet": Config<keyof AllLlm>;
1338
1477
  "anthropic.claude-3-5-haiku": Config<keyof AllLlm>;
1339
1478
  "anthropic.claude-3-opus": Config<keyof AllLlm>;
1479
+ "anthropic.claude-3-haiku": Config<keyof AllLlm>;
1340
1480
  "openai.chat.v1": Config<keyof AllLlm>;
1341
1481
  "openai.chat-mock.v1": Config<keyof AllLlm>;
1342
1482
  "openai.gpt-4o": Config<keyof AllLlm>;
1343
1483
  "openai.gpt-4o-mini": Config<keyof AllLlm>;
1344
1484
  };
1345
1485
 
1346
- declare function useLlm<T extends keyof typeof configs>(provider: T, options?: AllUseLlmOptions[T]["input"]): {
1347
- call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions) => Promise<BaseLlCall>;
1486
+ declare function useLlm<T extends keyof typeof configs>(provider: T, options?: AllUseLlmOptions[T]["input"]): BaseLlm;
1487
+ declare function useLlmConfiguration<T extends keyof typeof configs>(config: Config<any>): (options?: AllUseLlmOptions[T]["input"]) => {
1488
+ call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions) => Promise<{
1489
+ getResultContent: (index?: number) => OutputResultContent[];
1490
+ getResultText: (index?: number) => string;
1491
+ getResult: () => OutputResult;
1492
+ }>;
1348
1493
  getTraceId: () => string | null;
1349
1494
  withTraceId: (id: string) => void;
1350
1495
  getMetadata: () => {
@@ -1359,6 +1504,14 @@ declare function useLlm<T extends keyof typeof configs>(provider: T, options?: A
1359
1504
  };
1360
1505
  };
1361
1506
 
1507
+ declare function createOpenAiCompatibleConfiguration<K extends Config["key"]>(overrides: {
1508
+ key: string;
1509
+ provider: string;
1510
+ endpoint: string;
1511
+ apiKeyMapping: [string, string];
1512
+ transformResponse?: any;
1513
+ }): Config<keyof AllLlm>;
1514
+
1362
1515
  declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, options: AllEmbedding[T]["input"]): {
1363
1516
  call: (messages: string | string[], options?: LlmExecutorWithFunctionsOptions) => Promise<{
1364
1517
  getEmbedding: (index?: number) => number[];
@@ -1378,4 +1531,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
1378
1531
  };
1379
1532
  };
1380
1533
 
1381
- 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 };
1534
+ 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 };
package/dist/index.d.ts CHANGED
@@ -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
  /**
@@ -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;
@@ -1042,21 +1066,33 @@ type AllUseLlmOptions = AllLlm & {
1042
1066
  "openai.gpt-4o-mini": {
1043
1067
  input: Omit<OpenAiRequest, "model">;
1044
1068
  };
1069
+ "anthropic.claude-sonnet-4-0": {
1070
+ input: Omit<AnthropicRequest, "model">;
1071
+ };
1072
+ "anthropic.claude-opus-4-0": {
1073
+ input: Omit<AnthropicRequest, "model">;
1074
+ };
1045
1075
  "anthropic.claude-3-7-sonnet": {
1046
1076
  input: Omit<AnthropicRequest, "model">;
1047
1077
  };
1048
- "anthropic.claude-3-5-sonnet": {
1078
+ "anthropic.claude-sonnet-4": {
1049
1079
  input: Omit<AnthropicRequest, "model">;
1050
1080
  };
1051
- "anthropic.claude-3-opus": {
1081
+ "anthropic.claude-opus-4": {
1052
1082
  input: Omit<AnthropicRequest, "model">;
1053
1083
  };
1054
- "anthropic.claude-3-sonnet": {
1084
+ "anthropic.claude-3-5-sonnet": {
1055
1085
  input: Omit<AnthropicRequest, "model">;
1056
1086
  };
1057
1087
  "anthropic.claude-3-5-haiku": {
1058
1088
  input: Omit<AnthropicRequest, "model">;
1059
1089
  };
1090
+ "anthropic.claude-3-opus": {
1091
+ input: Omit<AnthropicRequest, "model">;
1092
+ };
1093
+ "anthropic.claude-3-haiku": {
1094
+ input: Omit<AnthropicRequest, "model">;
1095
+ };
1060
1096
  "google.gemini-2.5-pro-exp-03-25": {
1061
1097
  input: Omit<GeminiRequest, "model">;
1062
1098
  };
@@ -1066,12 +1102,27 @@ type AllUseLlmOptions = AllLlm & {
1066
1102
  "google.gemini-2.0-flash-lite": {
1067
1103
  input: Omit<GeminiRequest, "model">;
1068
1104
  };
1105
+ "google.gemini-2.5-flash": {
1106
+ input: Omit<GeminiRequest, "model">;
1107
+ };
1108
+ "google.gemini-2.5-flash-lite": {
1109
+ input: Omit<GeminiRequest, "model">;
1110
+ };
1069
1111
  "google.gemini-1.5-pro": {
1070
1112
  input: Omit<GeminiRequest, "model">;
1071
1113
  };
1114
+ "google.gemini-2.5-pro": {
1115
+ input: Omit<GeminiRequest, "model">;
1116
+ };
1072
1117
  "xai.grok-2": {
1073
1118
  input: OpenAiRequest;
1074
1119
  };
1120
+ "xai.grok-3": {
1121
+ input: OpenAiRequest;
1122
+ };
1123
+ "xai.grok-4": {
1124
+ input: OpenAiRequest;
1125
+ };
1075
1126
  "ollama.deepseek-r1": {
1076
1127
  input: GenericLLm;
1077
1128
  };
@@ -1110,25 +1161,106 @@ interface BaseLlm<_T extends BaseLlCall = BaseLlCall> extends BaseRequest<_T> {
1110
1161
 
1111
1162
  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";
1112
1163
  interface Config<Pk = LlmProviderKey> {
1164
+ /**
1165
+ * Unique identifier for this configuration (e.g., "openai.chat.v1", "anthropic.claude-3-opus")
1166
+ * Used to reference this config when calling useLlm()
1167
+ */
1113
1168
  key: Pk;
1169
+ /**
1170
+ * The provider type this config is for (e.g., "openai.chat", "anthropic.chat")
1171
+ * Used internally for provider-specific logic
1172
+ */
1114
1173
  provider: LlmProvider;
1115
- method: string;
1174
+ /**
1175
+ * HTTP method for the API request (typically "POST" for LLM providers)
1176
+ */
1177
+ method: "POST" | "PUT" | "GET";
1178
+ /**
1179
+ * API endpoint URL template. Supports template variables using {{variable}} syntax
1180
+ * Variables are replaced with values from the state object
1181
+ * @example "https://api.openai.com/v1/chat/completions"
1182
+ * @example "https://bedrock-runtime.{{awsRegion}}.amazonaws.com/model/{{model}}/invoke"
1183
+ */
1116
1184
  endpoint: string;
1185
+ /**
1186
+ * HTTP headers template as a JSON string. Supports template variables using {{variable}} syntax
1187
+ * @example '{"Authorization":"Bearer {{openAiApiKey}}", "Content-Type": "application/json"}'
1188
+ * // TODO: make this also accept object and function
1189
+ */
1190
+ headers: string;
1117
1191
  options: {
1118
1192
  [key in string]: {
1119
- default?: number | string;
1193
+ /**
1194
+ * Default value for this parameter if not provided by the user
1195
+ * Can be a static value or a function that returns the value
1196
+ * @example 4096
1197
+ * @example () => process.env.OPENAI_API_KEY
1198
+ */
1199
+ default?: any;
1200
+ /**
1201
+ * Whether this parameter is required
1202
+ * [true, "error message"] - Required with custom error
1203
+ * [true] - Required with default error message
1204
+ * @example [true, "maxTokens is required for Anthropic"]
1205
+ */
1120
1206
  required?: [boolean, string] | [boolean];
1121
1207
  };
1122
1208
  };
1123
1209
  mapBody: {
1124
1210
  [key in string]: {
1211
+ /**
1212
+ * The target field name in the provider's request body.
1213
+ * Supports dot notation for nested fields (e.g., "response_format.type")
1214
+ */
1125
1215
  key: string;
1126
- default?: number | string;
1127
- sanitize?: (i: any, arg: Record<string, any>, arg2: Record<string, any>) => any;
1216
+ /**
1217
+ * Default value to use if the source field is not provided
1218
+ */
1219
+ default?: any;
1220
+ /**
1221
+ * Transform function to convert the value before mapping to the request body
1222
+ * @param value - The input value from the user's state
1223
+ * @param state - The complete user state object containing all parameters
1224
+ * @param config - The current Config object (for access to options, etc.)
1225
+ * @returns The transformed value to be included in the request body
1226
+ */
1227
+ transform?: (value: any, state: Record<string, any>, config: Record<string, any>) => any;
1128
1228
  };
1129
1229
  };
1130
- headers: string;
1131
- prompt?: (messages: IChatMessages) => any;
1230
+ /**
1231
+ * Maps executor-level options (jsonSchema, functions, functionCall) to provider-specific request formats
1232
+ * @optional - Only needed if provider supports these features
1233
+ */
1234
+ mapOptions?: {
1235
+ /**
1236
+ * Transform JSON schema into provider-specific format
1237
+ * @param schema - The JSON schema object
1238
+ * @param options - Executor options (e.g., functionCallStrictInput)
1239
+ * @param currentInput - Current accumulated input state (for merging)
1240
+ * @param config - The full config object
1241
+ * @returns Provider-specific request body additions
1242
+ */
1243
+ jsonSchema?: (schema: any, options: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
1244
+ /**
1245
+ * Transform function call mode into provider-specific format
1246
+ * @param call - Function call mode ("auto", "any", "none", or specific function)
1247
+ * @param options - Executor options
1248
+ * @param currentInput - Current accumulated input state (for merging)
1249
+ * @param config - The full config object
1250
+ * @returns Provider-specific request body additions
1251
+ */
1252
+ functionCall?: (call: any, options?: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
1253
+ /**
1254
+ * Transform function definitions into provider-specific format
1255
+ * @param functions - Array of function definitions
1256
+ * @param options - Executor options (e.g., functionCallStrictInput)
1257
+ * @param currentInput - Current accumulated input state (for merging)
1258
+ * @param config - The full config object
1259
+ * @returns Provider-specific request body additions
1260
+ */
1261
+ functions?: (functions: any[], options?: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
1262
+ };
1263
+ transformResponse: (result: any, _config?: Config<any>) => OutputResult;
1132
1264
  }
1133
1265
 
1134
1266
  declare function enforceResultAttributes<O>(input: any): {
@@ -1321,7 +1453,10 @@ declare const configs: {
1321
1453
  "google.chat.v1": Config<keyof AllLlm>;
1322
1454
  "google.gemini-2.0-flash": Config<keyof AllLlm>;
1323
1455
  "google.gemini-2.0-flash-lite": Config<keyof AllLlm>;
1456
+ "google.gemini-2.5-flash": Config<keyof AllLlm>;
1457
+ "google.gemini-2.5-flash-lite": Config<keyof AllLlm>;
1324
1458
  "google.gemini-1.5-pro": Config<keyof AllLlm>;
1459
+ "google.gemini-2.5-pro": Config<keyof AllLlm>;
1325
1460
  "ollama.chat.v1": Config<keyof AllLlm>;
1326
1461
  "ollama.deepseek-r1": Config<keyof AllLlm>;
1327
1462
  "ollama.llama3.3": Config<keyof AllLlm>;
@@ -1330,21 +1465,31 @@ declare const configs: {
1330
1465
  "ollama.qwq": Config<keyof AllLlm>;
1331
1466
  "xai.chat.v1": Config<keyof AllLlm>;
1332
1467
  "xai.grok-2": Config<keyof AllLlm>;
1468
+ "xai.grok-3": Config<keyof AllLlm>;
1469
+ "xai.grok-4": Config<keyof AllLlm>;
1333
1470
  "amazon:anthropic.chat.v1": Config<keyof AllLlm>;
1334
1471
  "amazon:meta.chat.v1": Config<keyof AllLlm>;
1335
1472
  "anthropic.chat.v1": Config<keyof AllLlm>;
1473
+ "anthropic.claude-sonnet-4": Config<keyof AllLlm>;
1474
+ "anthropic.claude-opus-4": Config<keyof AllLlm>;
1336
1475
  "anthropic.claude-3-7-sonnet": Config<keyof AllLlm>;
1337
1476
  "anthropic.claude-3-5-sonnet": Config<keyof AllLlm>;
1338
1477
  "anthropic.claude-3-5-haiku": Config<keyof AllLlm>;
1339
1478
  "anthropic.claude-3-opus": Config<keyof AllLlm>;
1479
+ "anthropic.claude-3-haiku": Config<keyof AllLlm>;
1340
1480
  "openai.chat.v1": Config<keyof AllLlm>;
1341
1481
  "openai.chat-mock.v1": Config<keyof AllLlm>;
1342
1482
  "openai.gpt-4o": Config<keyof AllLlm>;
1343
1483
  "openai.gpt-4o-mini": Config<keyof AllLlm>;
1344
1484
  };
1345
1485
 
1346
- declare function useLlm<T extends keyof typeof configs>(provider: T, options?: AllUseLlmOptions[T]["input"]): {
1347
- call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions) => Promise<BaseLlCall>;
1486
+ declare function useLlm<T extends keyof typeof configs>(provider: T, options?: AllUseLlmOptions[T]["input"]): BaseLlm;
1487
+ declare function useLlmConfiguration<T extends keyof typeof configs>(config: Config<any>): (options?: AllUseLlmOptions[T]["input"]) => {
1488
+ call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions) => Promise<{
1489
+ getResultContent: (index?: number) => OutputResultContent[];
1490
+ getResultText: (index?: number) => string;
1491
+ getResult: () => OutputResult;
1492
+ }>;
1348
1493
  getTraceId: () => string | null;
1349
1494
  withTraceId: (id: string) => void;
1350
1495
  getMetadata: () => {
@@ -1359,6 +1504,14 @@ declare function useLlm<T extends keyof typeof configs>(provider: T, options?: A
1359
1504
  };
1360
1505
  };
1361
1506
 
1507
+ declare function createOpenAiCompatibleConfiguration<K extends Config["key"]>(overrides: {
1508
+ key: string;
1509
+ provider: string;
1510
+ endpoint: string;
1511
+ apiKeyMapping: [string, string];
1512
+ transformResponse?: any;
1513
+ }): Config<keyof AllLlm>;
1514
+
1362
1515
  declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, options: AllEmbedding[T]["input"]): {
1363
1516
  call: (messages: string | string[], options?: LlmExecutorWithFunctionsOptions) => Promise<{
1364
1517
  getEmbedding: (index?: number) => number[];
@@ -1378,4 +1531,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
1378
1531
  };
1379
1532
  };
1380
1533
 
1381
- 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 };
1534
+ 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 };