llm-exe 3.0.0 → 3.1.0-beta.1
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-2BUGTOKA.mjs +7194 -0
- package/dist/chunk-7W6GBE2Y.mjs +39 -0
- package/dist/chunk-PX2FFNZQ.mjs +40 -0
- package/dist/cli/cli.d.mts +1 -0
- package/dist/cli/cli.d.ts +1 -0
- package/dist/cli/cli.js +7090 -0
- package/dist/cli/cli.mjs +251 -0
- package/dist/config/node.d.mts +15 -0
- package/dist/config/node.d.ts +15 -0
- package/dist/config/node.js +6850 -0
- package/dist/config/node.mjs +11 -0
- package/dist/index.d.mts +94 -1160
- package/dist/index.d.ts +94 -1160
- package/dist/index.js +431 -6
- package/dist/index.mjs +503 -7175
- package/dist/types-CDOBItt6.d.mts +1223 -0
- package/dist/types-CDOBItt6.d.ts +1223 -0
- package/package.json +15 -3
- package/readme.md +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,116 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as BaseParser, c as BaseParserWithJson, J as JsonParserOptions, d as ListToJsonParserOptions, P as ParserOutput, e as ExecutionContext, S as StringParser, O as OutputResultContent, f as OutputResult, g as BasePrompt, h as PromptOptions, I as IPromptChatMessages, C as ChatPromptType, i as ChatPromptOptions, j as IChatMessageRole, k as IChatMessageContentDetailed, l as IChatMessages, m as PromptType, n as PlainObject, o as BaseExecutor, p as CoreExecutorInput, q as CoreExecutorExecuteOptions, D as DefaultState, r as DefaultStateItem, s as Dialogue, t as BaseLlm, u as BaseState, L as LlmExecutor, v as ExecutorWithLlmOptions, w as PromptInput, x as BaseLlCall, y as LlmExecutorHooks, G as GenericFunctionCall, z as LlmExecutorWithFunctionsOptions, A as CallableExecutorCore, F as FunctionOrExecutor, H as PromptPartial, K as PromptHelper, M as replaceTemplateString, N as replaceTemplateStringAsync, Q as OutputResultsText, T as OutputResultsFunction, U as IChatMessage, V as IChatUserMessage, W as IChatAssistantMessage, X as IChatSystemMessage, Y as configs, Z as AllUseLlmOptions, _ as Config, $ as AllLlm, a0 as EmbeddingProviderKey, a1 as AllEmbedding, a2 as EmbeddingOutputResult, E as ExecutorConfigPatch, a as ExecutorConfig, b as ExecutorCreateOptions, R as RunOverrides, a3 as Format } from './types-CDOBItt6.js';
|
|
2
|
+
export { a4 as BaseStateItem, a5 as CreateParserType, a7 as ExecutorContext, a8 as ExecutorExecutionMetadata, a9 as HookErrorRecord, ac as JsonParserMatch, a6 as LlmProvider, aa as LlmProviderKey, ab as UseLlmKey } from './types-CDOBItt6.js';
|
|
2
3
|
import { Narrow } from 'json-schema-to-ts/lib/types/type-utils';
|
|
3
|
-
|
|
4
|
-
type PrimitiveValue = bigint | boolean | null | number | string | symbol | undefined;
|
|
5
|
-
type ObjectValue = PrimitiveValue | PlainObject | ObjectArray;
|
|
6
|
-
interface PlainObject {
|
|
7
|
-
[key: string]: ObjectValue;
|
|
8
|
-
}
|
|
9
|
-
interface ObjectArray extends Array<ObjectValue> {
|
|
10
|
-
}
|
|
11
|
-
interface Serializable {
|
|
12
|
-
serialize?(): Record<string, any>;
|
|
13
|
-
deserialize?(): void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type IChatMessageRole = "system" | "model" | "assistant" | "user" | "function" | "function_call";
|
|
17
|
-
interface IChatMessageContentDetailed {
|
|
18
|
-
type: string;
|
|
19
|
-
text?: string;
|
|
20
|
-
image_url?: {
|
|
21
|
-
url: string;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
interface IChatMessageBase {
|
|
25
|
-
role: IChatMessageRole;
|
|
26
|
-
content: string | null | IChatMessageContentDetailed[];
|
|
27
|
-
}
|
|
28
|
-
interface IChatUserMessage extends IChatMessageBase {
|
|
29
|
-
role: Extract<IChatMessageRole, "user">;
|
|
30
|
-
content: string | IChatMessageContentDetailed[];
|
|
31
|
-
name?: string;
|
|
32
|
-
}
|
|
33
|
-
interface IChatFunctionMessage extends IChatMessageBase {
|
|
34
|
-
id?: string;
|
|
35
|
-
role: Extract<IChatMessageRole, "function">;
|
|
36
|
-
content: string;
|
|
37
|
-
name: string;
|
|
38
|
-
}
|
|
39
|
-
interface IChatAssistantMessage extends IChatMessageBase {
|
|
40
|
-
role: Extract<IChatMessageRole, "assistant" | "model">;
|
|
41
|
-
content: string;
|
|
42
|
-
function_call?: undefined;
|
|
43
|
-
}
|
|
44
|
-
interface IChatFunctionCallMessage extends IChatMessageBase {
|
|
45
|
-
role: Extract<IChatMessageRole, "function_call">;
|
|
46
|
-
content: null;
|
|
47
|
-
function_call: {
|
|
48
|
-
name: string;
|
|
49
|
-
arguments: string;
|
|
50
|
-
id?: string;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
interface IChatSystemMessage extends IChatMessageBase {
|
|
54
|
-
role: Extract<IChatMessageRole, "system">;
|
|
55
|
-
content: string;
|
|
56
|
-
}
|
|
57
|
-
interface IChatMessagesPlaceholder {
|
|
58
|
-
role: "placeholder";
|
|
59
|
-
content: string;
|
|
60
|
-
}
|
|
61
|
-
type IPromptMessages = (IChatSystemMessage | IChatMessagesPlaceholder)[];
|
|
62
|
-
type IPromptChatMessages = (IChatUserMessage | IChatAssistantMessage | IChatFunctionCallMessage | IChatSystemMessage | IChatMessagesPlaceholder | IChatFunctionMessage)[];
|
|
63
|
-
type IChatMessage = IChatUserMessage | IChatAssistantMessage | IChatFunctionCallMessage | IChatSystemMessage | IChatFunctionMessage;
|
|
64
|
-
type IChatMessages = IChatMessage[];
|
|
4
|
+
import { JSONSchema, FromSchema } from 'json-schema-to-ts';
|
|
65
5
|
|
|
66
6
|
type OpenAIChatModelName = "gpt-3.5-turbo" | "gpt-3.5-turbo-0613" | "gpt-3.5-turbo-16k" | "gpt-4-0613" | "gpt-4" | "gpt-4o" | "gpt-4o-mini" | "gpt-4-0613" | "gpt-4-32k-0613" | `gpt-4${string}` | `gpt-3.5-turbo-${string}`;
|
|
67
7
|
type OpenAIConversationModelName = "davinci" | "text-curie-001" | "text-babbage-001" | "text-ada-001";
|
|
68
8
|
type OpenAIEmbeddingModelName = "text-embedding-ada-002";
|
|
69
9
|
type OpenAIModelName = OpenAIChatModelName | OpenAIConversationModelName | OpenAIEmbeddingModelName;
|
|
70
10
|
|
|
71
|
-
/**
|
|
72
|
-
* BaseParser is an abstract class for parsing text and enforcing JSON schema on the parsed data.
|
|
73
|
-
*/
|
|
74
|
-
declare abstract class BaseParser<T = any, TInput = string> {
|
|
75
|
-
name: string;
|
|
76
|
-
target: "text" | "function_call";
|
|
77
|
-
/**
|
|
78
|
-
* Create a new BaseParser.
|
|
79
|
-
* @param name - The name of the parser.
|
|
80
|
-
* @param target - Whether the parser consumes text or function-call output.
|
|
81
|
-
*/
|
|
82
|
-
constructor(name: string, target?: "text" | "function_call");
|
|
83
|
-
/**
|
|
84
|
-
* Parse the given text and return the parsed data.
|
|
85
|
-
* @abstract
|
|
86
|
-
* @param text - The text to parse.
|
|
87
|
-
* @param [attributes] - Optional attributes to use during parsing.
|
|
88
|
-
* @returns The parsed data.
|
|
89
|
-
*/
|
|
90
|
-
abstract parse(text: TInput, attributes?: Record<string, any>): T;
|
|
91
|
-
}
|
|
92
|
-
declare abstract class BaseParserWithJson<S extends JSONSchema | undefined = undefined, T = S extends JSONSchema ? FromSchema<S> : Record<string, any>, TInput = string> extends BaseParser<T, TInput> {
|
|
93
|
-
schema: S;
|
|
94
|
-
validateSchema: boolean;
|
|
95
|
-
constructor(name: string, options: ParserSchemaOptions<S>);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* v3 parser contract:
|
|
100
|
-
* Category: pass-through
|
|
101
|
-
* Mode: string pass-through
|
|
102
|
-
*
|
|
103
|
-
* Accepts any string and returns it exactly.
|
|
104
|
-
* Throws LlmExeError(parser.parse_failed) for non-string input.
|
|
105
|
-
* Executor output normalization owns OutputResult handling before parser
|
|
106
|
-
* invocation.
|
|
107
|
-
*
|
|
108
|
-
*/
|
|
109
|
-
declare class StringParser extends BaseParser<string> {
|
|
110
|
-
constructor();
|
|
111
|
-
parse(text: string, _attributes?: Record<string, any>): string;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
11
|
type BooleanParserMatch = "exact" | "extract";
|
|
115
12
|
interface BooleanParserOptions {
|
|
116
13
|
match?: BooleanParserMatch;
|
|
@@ -407,98 +304,6 @@ declare class LlmNativeFunctionParser<T extends BaseParser<any, any>> extends Ba
|
|
|
407
304
|
*/
|
|
408
305
|
declare const OpenAiFunctionParser: typeof LlmNativeFunctionParser;
|
|
409
306
|
|
|
410
|
-
declare function replaceTemplateString(templateString?: string, substitutions?: Record<string, any>, configuration?: PromptTemplateOptions): string;
|
|
411
|
-
|
|
412
|
-
declare function replaceTemplateStringAsync(templateString?: string, substitutions?: Record<string, any>, configuration?: PromptTemplateOptions): Promise<string>;
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* BasePrompt should be extended.
|
|
416
|
-
*/
|
|
417
|
-
declare abstract class BasePrompt<I extends Record<string, any>> {
|
|
418
|
-
readonly type: PromptType;
|
|
419
|
-
messages: IPromptMessages | IPromptChatMessages;
|
|
420
|
-
partials: PromptPartial[];
|
|
421
|
-
helpers: PromptHelper[];
|
|
422
|
-
validateInput: ValidateInputMode;
|
|
423
|
-
replaceTemplateString: typeof replaceTemplateString;
|
|
424
|
-
replaceTemplateStringAsync: typeof replaceTemplateStringAsync;
|
|
425
|
-
filters: {
|
|
426
|
-
pre: ((prompt: string) => string)[];
|
|
427
|
-
post: ((prompt: string) => string)[];
|
|
428
|
-
};
|
|
429
|
-
/**
|
|
430
|
-
* constructor description
|
|
431
|
-
* @param initialPromptMessage An initial message to add to the prompt.
|
|
432
|
-
*/
|
|
433
|
-
constructor(initialPromptMessage?: string, options?: PromptOptions);
|
|
434
|
-
/**
|
|
435
|
-
* addToPrompt description
|
|
436
|
-
* @param content The message content
|
|
437
|
-
* @param role The role of the user. Defaults to system for base text prompt.
|
|
438
|
-
* @return instance of BasePrompt.
|
|
439
|
-
*/
|
|
440
|
-
addToPrompt(content: string, role?: string): BasePrompt<I>;
|
|
441
|
-
/**
|
|
442
|
-
* addSystemMessage description
|
|
443
|
-
* @param content The message content
|
|
444
|
-
* @return returns BasePrompt so it can be chained.
|
|
445
|
-
*/
|
|
446
|
-
addSystemMessage(content: string): this;
|
|
447
|
-
/**
|
|
448
|
-
* registerPartial description
|
|
449
|
-
* @param partialOrPartials Additional partials that can be made available to the template parser.
|
|
450
|
-
* @return BasePrompt so it can be chained.
|
|
451
|
-
*/
|
|
452
|
-
registerPartial(partialOrPartials: PromptPartial | PromptPartial[]): this;
|
|
453
|
-
/**
|
|
454
|
-
* registerHelpers description
|
|
455
|
-
* @param helperOrHelpers Additional helper functions that can be made available to the template parser.
|
|
456
|
-
* @return BasePrompt so it can be chained.
|
|
457
|
-
*/
|
|
458
|
-
registerHelpers(helperOrHelpers: PromptHelper | PromptHelper[]): this;
|
|
459
|
-
/**
|
|
460
|
-
* Returns the Handlebars-bearing strings that should be validated, along
|
|
461
|
-
* with a location label used for error context. Subclasses with structured
|
|
462
|
-
* message content (e.g. ChatPrompt) should override.
|
|
463
|
-
*/
|
|
464
|
-
protected getTemplateContents(): {
|
|
465
|
-
content: string;
|
|
466
|
-
location: string;
|
|
467
|
-
}[];
|
|
468
|
-
protected preflightValidate(values: I): void;
|
|
469
|
-
/**
|
|
470
|
-
* format description
|
|
471
|
-
* @param values The message content
|
|
472
|
-
* @param separator The separator between messages. defaults to "\n\n"
|
|
473
|
-
* @return returns messages formatted with template replacement
|
|
474
|
-
*/
|
|
475
|
-
format(values: I, separator?: string): string | IChatMessages;
|
|
476
|
-
/**
|
|
477
|
-
* format description
|
|
478
|
-
* @param values The message content
|
|
479
|
-
* @param separator The separator between messages. defaults to "\n\n"
|
|
480
|
-
* @return returns messages formatted with template replacement
|
|
481
|
-
*/
|
|
482
|
-
formatAsync(values: I, separator?: string): Promise<string | IChatMessages>;
|
|
483
|
-
runPromptFilter(prompt: string, filters: ((prompt: string, values: I) => string)[], values: I): string;
|
|
484
|
-
getReplacements(values: I): Omit<I, "input"> & {
|
|
485
|
-
input: any;
|
|
486
|
-
_input: any;
|
|
487
|
-
};
|
|
488
|
-
/**
|
|
489
|
-
* Validates that `input` provides every variable referenced by this prompt's
|
|
490
|
-
* templates, and that every identifiable helper call is registered.
|
|
491
|
-
*
|
|
492
|
-
* @breaking v3: previously returned `this.messages.length > 0` with no
|
|
493
|
-
* `input` parameter. For the old behavior, read `prompt.messages.length > 0`
|
|
494
|
-
* directly.
|
|
495
|
-
*
|
|
496
|
-
* @throws LlmExeError with code `"prompt.missing_template_variable"` listing
|
|
497
|
-
* all missing variables and helpers.
|
|
498
|
-
*/
|
|
499
|
-
validate(input: I): void;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
307
|
/**
|
|
503
308
|
* `TextPrompt` provides a standard text-based prompt.
|
|
504
309
|
* The text prompt can be used with models such as davinci.
|
|
@@ -614,40 +419,6 @@ declare class ChatPrompt<I extends Record<string, any>> extends BasePrompt<I> {
|
|
|
614
419
|
formatAsync(values: I): Promise<IChatMessages>;
|
|
615
420
|
}
|
|
616
421
|
|
|
617
|
-
type TextPromptType = "text";
|
|
618
|
-
type ChatPromptType = "chat";
|
|
619
|
-
type PromptType = TextPromptType | ChatPromptType;
|
|
620
|
-
type PromptHelper = {
|
|
621
|
-
name: string;
|
|
622
|
-
handler: (args: any) => any;
|
|
623
|
-
};
|
|
624
|
-
type PromptPartial = {
|
|
625
|
-
name: string;
|
|
626
|
-
template: string;
|
|
627
|
-
};
|
|
628
|
-
type ValidateInputMode = false | "strict" | "warn";
|
|
629
|
-
interface PromptTemplateOptions {
|
|
630
|
-
partials?: PromptPartial[];
|
|
631
|
-
helpers?: PromptHelper[];
|
|
632
|
-
}
|
|
633
|
-
interface PromptOptions extends PromptTemplateOptions {
|
|
634
|
-
preFilters?: ((prompt: string) => string)[];
|
|
635
|
-
postFilters?: ((prompt: string) => string)[];
|
|
636
|
-
replaceTemplateString?: (...args: any[]) => string;
|
|
637
|
-
/**
|
|
638
|
-
* Controls whether `format()` preflights input against the variables
|
|
639
|
-
* referenced by the prompt's templates. See `validate(input)`.
|
|
640
|
-
*
|
|
641
|
-
* - `false` (default): no preflight; rendering proceeds.
|
|
642
|
-
* - `"strict"`: throw `LlmExeError("prompt.missing_template_variable")` before rendering.
|
|
643
|
-
* - `"warn"`: emit a Node warning via `process.emitWarning` and continue rendering.
|
|
644
|
-
*/
|
|
645
|
-
validateInput?: ValidateInputMode;
|
|
646
|
-
}
|
|
647
|
-
interface ChatPromptOptions extends PromptOptions {
|
|
648
|
-
allowUnsafeUserTemplate?: boolean;
|
|
649
|
-
}
|
|
650
|
-
|
|
651
422
|
/**
|
|
652
423
|
* `createPrompt` Creates a new instance of a prompt.
|
|
653
424
|
*
|
|
@@ -664,281 +435,31 @@ declare function createPrompt<I extends Record<string, any>>(type?: PromptType,
|
|
|
664
435
|
*/
|
|
665
436
|
declare function createChatPrompt<I extends Record<string, any>>(initialSystemPromptMessage?: string, options?: ChatPromptOptions): ChatPrompt<I>;
|
|
666
437
|
|
|
667
|
-
/**
|
|
668
|
-
* BaseExecutor
|
|
669
|
-
* @template I - Input type.
|
|
670
|
-
* @template O - Output type.
|
|
671
|
-
* @template H - Hooks type.
|
|
672
|
-
*/
|
|
673
|
-
declare abstract class BaseExecutor<I extends PlainObject, O = any, H extends BaseExecutorHooks = BaseExecutorHooks> {
|
|
674
|
-
/**
|
|
675
|
-
* @property id - internal id of the executor
|
|
676
|
-
*/
|
|
677
|
-
readonly id: string;
|
|
678
|
-
/**
|
|
679
|
-
* @property type - type of executor
|
|
680
|
-
*/
|
|
681
|
-
type: string;
|
|
682
|
-
/**
|
|
683
|
-
* @property created - timestamp date created
|
|
684
|
-
*/
|
|
685
|
-
readonly created: number;
|
|
686
|
-
/**
|
|
687
|
-
* @property name - name of executor
|
|
688
|
-
*/
|
|
689
|
-
name: string;
|
|
690
|
-
/**
|
|
691
|
-
* @property executions -
|
|
692
|
-
*/
|
|
693
|
-
executions: number;
|
|
694
|
-
traceId: string | null;
|
|
695
|
-
/**
|
|
696
|
-
* @property hooks - hooks to be ran during execution
|
|
697
|
-
*/
|
|
698
|
-
hooks: any;
|
|
699
|
-
readonly allowedHooks: any[];
|
|
700
|
-
/**
|
|
701
|
-
* @property maxHooksPerEvent - Maximum number of hooks allowed per event
|
|
702
|
-
*/
|
|
703
|
-
readonly maxHooksPerEvent: number;
|
|
704
|
-
constructor(name: string, type: string, options?: CoreExecutorExecuteOptions<H>);
|
|
705
|
-
abstract handler(input: I, _options?: any, _context?: ExecutionContext<I, O>): Promise<any>;
|
|
706
|
-
/**
|
|
707
|
-
* Build a per-call execution context snapshot. Captures the current
|
|
708
|
-
* execution metadata so the snapshot reflects state at the time it was
|
|
709
|
-
* taken (e.g. `handlerInput` becomes available after `getHandlerInput`).
|
|
710
|
-
*/
|
|
711
|
-
protected snapshotContext(execution: ExecutorExecutionMetadata<I, O>): ExecutionContext<I, O>;
|
|
712
|
-
/**
|
|
713
|
-
*
|
|
714
|
-
* Used to filter the input of the handler.
|
|
715
|
-
*
|
|
716
|
-
* Throws a `TypeError` if `_input` is `null` or `undefined`. The declared
|
|
717
|
-
* input type is `I extends PlainObject`; omitting input or passing an
|
|
718
|
-
* explicit `null` is a contract violation with no valid coercion, so we
|
|
719
|
-
* surface it loudly rather than silently wrapping it.
|
|
720
|
-
*
|
|
721
|
-
* Non-object inputs (strings, numbers, arrays) are intentionally coerced
|
|
722
|
-
* to `{ input: value }` via {@link ensureInputIsObject}. This preserves the
|
|
723
|
-
* convenience pattern used by tool/function callables, which forward raw
|
|
724
|
-
* string arguments into an executor.
|
|
725
|
-
*
|
|
726
|
-
* @param _input
|
|
727
|
-
* @returns original input formatted for handler
|
|
728
|
-
*/
|
|
729
|
-
getHandlerInput(_input: I, _metadata: ExecutorExecutionMetadata<I, any>, _options?: any): Promise<any>;
|
|
730
|
-
/**
|
|
731
|
-
*
|
|
732
|
-
* Used to filter the output of the handler
|
|
733
|
-
* @param _input
|
|
734
|
-
* @returns output O
|
|
735
|
-
*/
|
|
736
|
-
getHandlerOutput(out: any, _metadata: ExecutorExecutionMetadata<any, O>, _options?: any, _context?: ExecutionContext<I, O>): O;
|
|
737
|
-
/**
|
|
738
|
-
*
|
|
739
|
-
* execute - Runs the executor
|
|
740
|
-
* @param _input
|
|
741
|
-
* @returns handler output
|
|
742
|
-
*/
|
|
743
|
-
execute(_input: I, _options?: any): Promise<O>;
|
|
744
|
-
private collectHookErrors;
|
|
745
|
-
metadata(): Record<string, any>;
|
|
746
|
-
getMetadata(metadata?: Record<string, any>): ExecutorMetadata;
|
|
747
|
-
runHook(hook: keyof H, _metadata: ExecutorExecutionMetadata): HookErrorRecord[];
|
|
748
|
-
setHooks(hooks?: CoreExecutorHookInput<H>): this;
|
|
749
|
-
removeHook(eventName: keyof H, fn: ListenerFunction): this;
|
|
750
|
-
on(eventName: keyof H, fn: ListenerFunction): this;
|
|
751
|
-
off(eventName: keyof H, fn: ListenerFunction): this;
|
|
752
|
-
once(eventName: keyof H, fn: ListenerFunction): this;
|
|
753
|
-
withTraceId(traceId: string): this;
|
|
754
|
-
getTraceId(): string | null;
|
|
755
|
-
/**
|
|
756
|
-
* Clear all hooks for a specific event or all events
|
|
757
|
-
* Useful for preventing memory leaks in long-running processes
|
|
758
|
-
* @param eventName - The event name to clear hooks for
|
|
759
|
-
*/
|
|
760
|
-
clearHooks(eventName?: keyof H): this;
|
|
761
|
-
/**
|
|
762
|
-
* Get the count of hooks for monitoring memory usage
|
|
763
|
-
* @param eventName - Optional event name to get count for
|
|
764
|
-
* @returns Hook count for specific event or all events
|
|
765
|
-
*/
|
|
766
|
-
getHookCount(eventName?: keyof H): number | Record<string, number>;
|
|
767
|
-
}
|
|
768
|
-
|
|
769
438
|
/**
|
|
770
439
|
* Core Function Executor
|
|
771
440
|
*/
|
|
772
441
|
declare class CoreExecutor<I extends PlainObject, O> extends BaseExecutor<I, O> {
|
|
773
|
-
_handler: (input: I) => Promise<any> | any;
|
|
774
|
-
constructor(fn: CoreExecutorInput<I, O>, options?: CoreExecutorExecuteOptions);
|
|
775
|
-
handler(_input: I): Promise<O>;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
declare abstract class BaseStateItem<T> implements Serializable {
|
|
779
|
-
protected key: string;
|
|
780
|
-
protected value: T;
|
|
781
|
-
protected initialValue: T;
|
|
782
|
-
constructor(key: string, initialValue: T);
|
|
783
|
-
setValue(value: T): void;
|
|
784
|
-
getKey(): string;
|
|
785
|
-
getValue(): T;
|
|
786
|
-
resetValue(): void;
|
|
787
|
-
serializeValue(): {
|
|
788
|
-
[x: string]: T;
|
|
789
|
-
};
|
|
790
|
-
serialize(): {
|
|
791
|
-
class: string;
|
|
792
|
-
name: string;
|
|
793
|
-
value: any;
|
|
794
|
-
};
|
|
795
|
-
}
|
|
796
|
-
declare class DefaultStateItem extends BaseStateItem<any> {
|
|
797
|
-
constructor(name: string, defaultValue: any);
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
declare class Dialogue extends BaseStateItem<IChatMessages> {
|
|
801
|
-
name: string;
|
|
802
|
-
constructor(name: string);
|
|
803
|
-
setUserMessage(content: string | IChatMessageContentDetailed[], name?: string): this;
|
|
804
|
-
setAssistantMessage(content: string | OutputResultsText): this;
|
|
805
|
-
setSystemMessage(content: string): this;
|
|
806
|
-
setToolMessage(content: string, name: string, id?: string): this;
|
|
807
|
-
setFunctionMessage(content: string, name: string, id?: string): this;
|
|
808
|
-
/**
|
|
809
|
-
* Set
|
|
810
|
-
*/
|
|
811
|
-
setToolCallMessage(input: {
|
|
812
|
-
name: string;
|
|
813
|
-
arguments: string;
|
|
814
|
-
id?: string;
|
|
815
|
-
}): this;
|
|
816
|
-
setFunctionCallMessage(input: {
|
|
817
|
-
name: string;
|
|
818
|
-
arguments: string;
|
|
819
|
-
id?: string;
|
|
820
|
-
} | {
|
|
821
|
-
function_call: {
|
|
822
|
-
name: string;
|
|
823
|
-
arguments: string;
|
|
824
|
-
id?: string;
|
|
825
|
-
};
|
|
826
|
-
}): this;
|
|
827
|
-
setMessageTurn(userMessage: string, assistantMessage: string, systemMessage?: string): this;
|
|
828
|
-
/**
|
|
829
|
-
* Aliases using `add*` naming to match ChatPrompt's API.
|
|
830
|
-
* These delegate to the corresponding `set*` methods.
|
|
831
|
-
*/
|
|
832
|
-
addUserMessage(content: string | IChatMessageContentDetailed[], name?: string): this;
|
|
833
|
-
addAssistantMessage(content: string | OutputResultsText): this;
|
|
834
|
-
addSystemMessage(content: string): this;
|
|
835
|
-
addToolMessage(content: string, name: string, id?: string): this;
|
|
836
|
-
addToolCallMessage(input: {
|
|
837
|
-
name: string;
|
|
838
|
-
arguments: string;
|
|
839
|
-
id?: string;
|
|
840
|
-
}): this;
|
|
841
|
-
addFunctionMessage(content: string, name: string, id?: string): this;
|
|
842
|
-
addFunctionCallMessage(input: {
|
|
843
|
-
name: string;
|
|
844
|
-
arguments: string;
|
|
845
|
-
id?: string;
|
|
846
|
-
} | {
|
|
847
|
-
function_call: {
|
|
848
|
-
name: string;
|
|
849
|
-
arguments: string;
|
|
850
|
-
id?: string;
|
|
851
|
-
};
|
|
852
|
-
}): this;
|
|
853
|
-
addMessageTurn(userMessage: string, assistantMessage: string, systemMessage?: string): this;
|
|
854
|
-
addHistory(messages: IChatMessages): this;
|
|
855
|
-
setHistory(messages: IChatMessages): this;
|
|
856
|
-
getHistory(): IChatMessages;
|
|
857
|
-
serialize(): {
|
|
858
|
-
class: string;
|
|
859
|
-
name: string;
|
|
860
|
-
value: IChatMessage[];
|
|
861
|
-
};
|
|
862
|
-
/**
|
|
863
|
-
* Add LLM output to dialogue history in the order it was returned
|
|
864
|
-
*
|
|
865
|
-
* @param output - The LLM output result from llm.call()
|
|
866
|
-
* @returns this for chaining
|
|
867
|
-
*/
|
|
868
|
-
addFromOutput(output: OutputResult | BaseLlCall): this;
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
declare abstract class BaseState {
|
|
872
|
-
dialogues: {
|
|
873
|
-
[key in string]: Dialogue;
|
|
874
|
-
};
|
|
875
|
-
attributes: Record<string, any>;
|
|
876
|
-
context: Record<string, BaseStateItem<any>>;
|
|
877
|
-
constructor();
|
|
878
|
-
createDialogue(name?: string): Dialogue;
|
|
879
|
-
useDialogue(name?: string): Dialogue;
|
|
880
|
-
getDialogue(name?: string): Dialogue;
|
|
881
|
-
createContextItem<T extends BaseStateItem<any>>(item: T): T;
|
|
882
|
-
getContext<T>(key: string): BaseStateItem<T>;
|
|
883
|
-
getContextValue<T>(key: string): T;
|
|
884
|
-
setAttribute(key: string, value: any): void;
|
|
885
|
-
deleteAttribute(key: string): void;
|
|
886
|
-
clearAttributes(): void;
|
|
887
|
-
serialize(): {
|
|
888
|
-
dialogues: any;
|
|
889
|
-
context: any;
|
|
890
|
-
attributes: any;
|
|
891
|
-
};
|
|
892
|
-
abstract saveState(): Promise<void>;
|
|
893
|
-
}
|
|
894
|
-
declare class DefaultState extends BaseState {
|
|
895
|
-
constructor();
|
|
896
|
-
saveState(): Promise<void>;
|
|
442
|
+
_handler: (input: I, context?: ExecutionContext<I, O>) => Promise<any> | any;
|
|
443
|
+
constructor(fn: CoreExecutorInput<I, O>, options?: CoreExecutorExecuteOptions<I, O>);
|
|
444
|
+
handler(_input: I, _options?: any, _context?: ExecutionContext<I, O>): Promise<O>;
|
|
897
445
|
}
|
|
898
446
|
|
|
899
447
|
declare function createState(): DefaultState;
|
|
900
448
|
declare function createDialogue(name: string): Dialogue;
|
|
901
449
|
declare function createStateItem<T>(name: string, defaultValue: T): DefaultStateItem;
|
|
902
450
|
|
|
903
|
-
/**
|
|
904
|
-
* Core Executor With LLM
|
|
905
|
-
*/
|
|
906
|
-
declare class LlmExecutor<Llm extends BaseLlm<any>, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser<any, any>, State extends BaseState> extends BaseExecutor<PromptInput<Prompt>, ParserOutput<Parser>, LlmExecutorHooks> {
|
|
907
|
-
llm: Llm;
|
|
908
|
-
prompt: Prompt | undefined;
|
|
909
|
-
promptFn: any;
|
|
910
|
-
parser: StringParser | Parser;
|
|
911
|
-
constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>);
|
|
912
|
-
/**
|
|
913
|
-
* Runs the executor against the configured LLM and prompt.
|
|
914
|
-
*
|
|
915
|
-
* `null` and `undefined` are rejected with a `TypeError`: the declared
|
|
916
|
-
* input type requires an object, and silently coercing missing input hides a
|
|
917
|
-
* clear contract violation. Use `{}` for prompts that declare no template
|
|
918
|
-
* variables. See issue #410.
|
|
919
|
-
*/
|
|
920
|
-
execute(_input: PromptInput<Prompt>, _options?: LlmExecutorExecuteOptions): Promise<ParserOutput<Parser>>;
|
|
921
|
-
handler(_input: PromptInput<Prompt>, _options?: LlmExecutorExecuteOptions, _context?: ExecutionContext<PromptInput<Prompt>, ParserOutput<Parser>>): Promise<any>;
|
|
922
|
-
getHandlerInput(_input: PromptInput<Prompt>): Promise<any>;
|
|
923
|
-
getHandlerOutput(out: BaseLlCall, _metadata: ExecutorExecutionMetadata<PromptInput<Prompt>, ParserOutput<Parser>>, _options?: LlmExecutorExecuteOptions, _context?: ExecutionContext<PromptInput<Prompt>, ParserOutput<Parser>>): ParserOutput<Parser>;
|
|
924
|
-
metadata(): {
|
|
925
|
-
llm: Record<string, any>;
|
|
926
|
-
};
|
|
927
|
-
getTraceId(): string | null;
|
|
928
|
-
}
|
|
929
|
-
|
|
930
451
|
/**
|
|
931
452
|
* Core Executor With LLM
|
|
932
453
|
*/
|
|
933
454
|
declare class LlmExecutorWithFunctions<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState = BaseState> extends LlmExecutor<Llm, Prompt, LlmFunctionParser<Parser>, State> {
|
|
934
|
-
constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>);
|
|
455
|
+
constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<PromptInput<Prompt>, ParserOutput<LlmFunctionParser<Parser>>, BaseLlCall, ReturnType<Prompt["format"]>, LlmExecutorHooks>);
|
|
935
456
|
execute<T extends GenericFunctionCall>(_input: PromptInput<Prompt>, _options: LlmExecutorWithFunctionsOptions<T>): Promise<OutputResultContent[] | ParserOutput<Parser>>;
|
|
936
457
|
}
|
|
937
458
|
/**
|
|
938
459
|
* @deprecated Use `LlmExecutorWithFunctions` instead.
|
|
939
460
|
*/
|
|
940
461
|
declare class LlmExecutorOpenAiFunctions<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState = BaseState> extends LlmExecutor<Llm, Prompt, LlmNativeFunctionParser<Parser>, State> {
|
|
941
|
-
constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>);
|
|
462
|
+
constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<PromptInput<Prompt>, ParserOutput<LlmNativeFunctionParser<Parser>>, BaseLlCall, ReturnType<Prompt["format"]>, LlmExecutorHooks>);
|
|
942
463
|
execute<T extends GenericFunctionCall>(_input: PromptInput<Prompt>, _options: LlmExecutorWithFunctionsOptions<T>): Promise<ParserOutput<Parser> | {
|
|
943
464
|
name: string;
|
|
944
465
|
arguments: any;
|
|
@@ -952,7 +473,7 @@ declare class LlmExecutorOpenAiFunctions<Llm extends BaseLlm, Prompt extends Bas
|
|
|
952
473
|
* @param handler - The handler function.
|
|
953
474
|
* @returns - A new CoreExecutor instance.
|
|
954
475
|
*/
|
|
955
|
-
declare function createCoreExecutor<I extends PlainObject, O>(handler: (input: I) => Promise<O> | O, options?: CoreExecutorExecuteOptions): CoreExecutor<I, O>;
|
|
476
|
+
declare function createCoreExecutor<I extends PlainObject, O>(handler: (input: I, context?: ExecutionContext<I, O>) => Promise<O> | O, options?: CoreExecutorExecuteOptions<I, O>): CoreExecutor<I, O>;
|
|
956
477
|
/**
|
|
957
478
|
* Function to create a core executor with Llm.
|
|
958
479
|
* @template Llm - Llm type.
|
|
@@ -962,607 +483,8 @@ declare function createCoreExecutor<I extends PlainObject, O>(handler: (input: I
|
|
|
962
483
|
* @param options - Options for BaseExecutorV3.
|
|
963
484
|
* @returns - A new LlmExecutor instance.
|
|
964
485
|
*/
|
|
965
|
-
declare function createLlmExecutor<Llm extends BaseLlm<any>, Prompt extends BasePrompt<any>, Parser extends BaseParser, State extends BaseState>(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>): LlmExecutor<Llm, Prompt, Parser, State>;
|
|
966
|
-
declare function createLlmFunctionExecutor<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState>(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>): LlmExecutorWithFunctions<Llm, Prompt, Parser, State>;
|
|
967
|
-
|
|
968
|
-
declare const hookOnComplete = "onComplete";
|
|
969
|
-
declare const hookOnError = "onError";
|
|
970
|
-
declare const hookOnSuccess = "onSuccess";
|
|
971
|
-
|
|
972
|
-
type ListenerFunction = (...args: any[]) => void;
|
|
973
|
-
type ParserOutput<P> = P extends BaseParser<infer T, any> ? T : never;
|
|
974
|
-
type PromptInput<P> = P extends BasePrompt<infer T> ? T : never;
|
|
975
|
-
interface ExecutorWithLlmOptions<Llm, Prompt, Parser, State> {
|
|
976
|
-
name?: string;
|
|
977
|
-
llm: Llm;
|
|
978
|
-
prompt: Prompt | ((values: PromptInput<Prompt>) => Prompt);
|
|
979
|
-
parser?: Parser;
|
|
980
|
-
state?: State;
|
|
981
|
-
__mock_response_key__?: string;
|
|
982
|
-
}
|
|
983
|
-
interface CoreExecutorInput<I, O> {
|
|
984
|
-
name?: string;
|
|
985
|
-
handler: (input: I) => Promise<O> | O;
|
|
986
|
-
getHandlerInput?(input: I): Promise<any>;
|
|
987
|
-
getHandlerOutput?(out: any): O;
|
|
988
|
-
}
|
|
989
|
-
type FunctionOrExecutor<I extends PlainObject | {
|
|
990
|
-
input: string;
|
|
991
|
-
}, O> = ((input: I) => Promise<O> | O) | BaseExecutor<I, O>;
|
|
992
|
-
interface ExecutorMetadata {
|
|
993
|
-
id: string;
|
|
994
|
-
type: string;
|
|
995
|
-
name: string;
|
|
996
|
-
created: number;
|
|
997
|
-
executions: number;
|
|
998
|
-
metadata?: Record<string, any>;
|
|
999
|
-
}
|
|
1000
|
-
interface HookErrorRecord {
|
|
1001
|
-
hook: string;
|
|
1002
|
-
error: unknown;
|
|
1003
|
-
errorMessage: string;
|
|
1004
|
-
errorCategory?: string;
|
|
1005
|
-
errorCode?: string;
|
|
1006
|
-
errorContext?: unknown;
|
|
1007
|
-
errorCause?: unknown;
|
|
1008
|
-
}
|
|
1009
|
-
interface ExecutorExecutionMetadata<I = any, O = any> {
|
|
1010
|
-
start: null | number;
|
|
1011
|
-
end: null | number;
|
|
1012
|
-
input: I;
|
|
1013
|
-
handlerInput?: any;
|
|
1014
|
-
handlerOutput?: any;
|
|
1015
|
-
output?: O;
|
|
1016
|
-
errorMessage?: string;
|
|
1017
|
-
error?: Error;
|
|
1018
|
-
errorCategory?: string;
|
|
1019
|
-
errorCode?: string;
|
|
1020
|
-
errorContext?: unknown;
|
|
1021
|
-
errorCause?: unknown;
|
|
1022
|
-
hookErrors?: HookErrorRecord[];
|
|
1023
|
-
metadata?: null | ExecutorMetadata;
|
|
1024
|
-
}
|
|
1025
|
-
interface ExecutorContext<I = any, O = any, A = Record<string, any>> extends ExecutorExecutionMetadata<I, O> {
|
|
1026
|
-
metadata: ExecutorMetadata;
|
|
1027
|
-
attributes: A;
|
|
1028
|
-
}
|
|
1029
|
-
/**
|
|
1030
|
-
* Per-call execution context. Built by `BaseExecutor.execute()` and threaded
|
|
1031
|
-
* through `handler()`, `llm.call()`, parsers, and warnings. Provides a single
|
|
1032
|
-
* place to read the resolved trace ID, stable executor identity, and the
|
|
1033
|
-
* mutable execution state for the current run.
|
|
1034
|
-
*/
|
|
1035
|
-
interface ExecutionContext<I = any, O = any, A = Record<string, any>> {
|
|
1036
|
-
traceId?: string;
|
|
1037
|
-
executor: ExecutorMetadata;
|
|
1038
|
-
execution: ExecutorExecutionMetadata<I, O>;
|
|
1039
|
-
attributes: A;
|
|
1040
|
-
}
|
|
1041
|
-
interface BaseExecutorHooks {
|
|
1042
|
-
[hookOnError]: ListenerFunction[];
|
|
1043
|
-
[hookOnSuccess]: ListenerFunction[];
|
|
1044
|
-
[hookOnComplete]: ListenerFunction[];
|
|
1045
|
-
}
|
|
1046
|
-
interface LlmExecutorHooks extends BaseExecutorHooks {
|
|
1047
|
-
}
|
|
1048
|
-
type CoreExecutorHookInput<H = BaseExecutorHooks> = {
|
|
1049
|
-
[key in keyof H]?: ListenerFunction | ListenerFunction[];
|
|
1050
|
-
};
|
|
1051
|
-
interface CoreExecutorExecuteOptions<T = BaseExecutorHooks> {
|
|
1052
|
-
hooks?: CoreExecutorHookInput<T>;
|
|
1053
|
-
}
|
|
1054
|
-
interface CallableExecutorCore {
|
|
1055
|
-
name: string;
|
|
1056
|
-
description: string;
|
|
1057
|
-
parameters?: Record<string, any>;
|
|
1058
|
-
}
|
|
1059
|
-
interface LlmExecutorExecuteOptions {
|
|
1060
|
-
functions?: CallableExecutorCore[];
|
|
1061
|
-
functionCall?: any;
|
|
1062
|
-
jsonSchema?: Record<string, any>;
|
|
1063
|
-
}
|
|
1064
|
-
type GenericFunctionCall = "auto" | "none" | "any" | {
|
|
1065
|
-
name: string;
|
|
1066
|
-
};
|
|
1067
|
-
interface LlmExecutorWithFunctionsOptions<T extends GenericFunctionCall = "auto"> extends LlmExecutorExecuteOptions {
|
|
1068
|
-
functions?: CallableExecutorCore[];
|
|
1069
|
-
functionCall?: T;
|
|
1070
|
-
functionCallStrictInput?: boolean;
|
|
1071
|
-
jsonSchema?: Record<string, any>;
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
interface ParserSchemaOptions<S extends JSONSchema | undefined = undefined> {
|
|
1075
|
-
schema?: S;
|
|
1076
|
-
validateSchema?: boolean;
|
|
1077
|
-
}
|
|
1078
|
-
type JsonParserMatch = "exact" | "extract";
|
|
1079
|
-
interface JsonParserOptions<S extends JSONSchema | undefined = undefined> extends ParserSchemaOptions<S> {
|
|
1080
|
-
match?: JsonParserMatch;
|
|
1081
|
-
}
|
|
1082
|
-
interface ListToJsonParserOptions<S extends JSONSchema | undefined = undefined> extends ParserSchemaOptions<S> {
|
|
1083
|
-
keyTransform?: "camelCase" | "preserve";
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
/**
|
|
1087
|
-
* Internal Formats
|
|
1088
|
-
*/
|
|
1089
|
-
interface OutputResultsBase {
|
|
1090
|
-
type: "text" | "function_use";
|
|
1091
|
-
text?: string;
|
|
1092
|
-
}
|
|
1093
|
-
interface OutputResultsText extends OutputResultsBase {
|
|
1094
|
-
type: "text";
|
|
1095
|
-
text: string;
|
|
1096
|
-
}
|
|
1097
|
-
interface OutputResultsFunction extends OutputResultsBase {
|
|
1098
|
-
type: "function_use";
|
|
1099
|
-
name: string;
|
|
1100
|
-
input: Record<string, any>;
|
|
1101
|
-
functionId: string;
|
|
1102
|
-
}
|
|
1103
|
-
type OutputResultContent = OutputResultsText | OutputResultsFunction;
|
|
1104
|
-
interface OutputResult {
|
|
1105
|
-
id: string;
|
|
1106
|
-
name?: string;
|
|
1107
|
-
created: number;
|
|
1108
|
-
stopReason: string;
|
|
1109
|
-
content: OutputResultContent[];
|
|
1110
|
-
options?: OutputResultContent[][];
|
|
1111
|
-
usage: {
|
|
1112
|
-
input_tokens: number;
|
|
1113
|
-
output_tokens: number;
|
|
1114
|
-
total_tokens: number;
|
|
1115
|
-
};
|
|
1116
|
-
}
|
|
1117
|
-
interface EmbeddingOutputResult {
|
|
1118
|
-
id: string;
|
|
1119
|
-
model?: string;
|
|
1120
|
-
created: number;
|
|
1121
|
-
embedding: number[][];
|
|
1122
|
-
usage: {
|
|
1123
|
-
input_tokens: number;
|
|
1124
|
-
output_tokens: number;
|
|
1125
|
-
total_tokens: number;
|
|
1126
|
-
};
|
|
1127
|
-
}
|
|
1128
|
-
interface BaseLlmOptions {
|
|
1129
|
-
traceId?: null | string;
|
|
1130
|
-
timeout?: number;
|
|
1131
|
-
maxDelay?: number;
|
|
1132
|
-
numOfAttempts?: number;
|
|
1133
|
-
jitter?: "none" | "full";
|
|
1134
|
-
promptType?: PromptType;
|
|
1135
|
-
endpoint?: string;
|
|
1136
|
-
headers?: Record<string, string>;
|
|
1137
|
-
}
|
|
1138
|
-
interface GenericEmbeddingOptions extends BaseLlmOptions {
|
|
1139
|
-
model?: string;
|
|
1140
|
-
dimensions?: number;
|
|
1141
|
-
}
|
|
1142
|
-
interface OpenAiEmbeddingOptions extends GenericEmbeddingOptions {
|
|
1143
|
-
model?: string;
|
|
1144
|
-
openAiApiKey?: string;
|
|
1145
|
-
baseUrl?: string;
|
|
1146
|
-
}
|
|
1147
|
-
interface AmazonEmbeddingOptions extends GenericEmbeddingOptions {
|
|
1148
|
-
model: string;
|
|
1149
|
-
awsRegion?: string;
|
|
1150
|
-
awsSecretKey?: string;
|
|
1151
|
-
awsAccessKey?: string;
|
|
1152
|
-
}
|
|
1153
|
-
interface CohereBedrockEmbeddingOptions extends AmazonEmbeddingOptions {
|
|
1154
|
-
inputType?: "search_document" | "search_query" | "classification" | "clustering";
|
|
1155
|
-
truncate?: "NONE" | "START" | "END" | "LEFT" | "RIGHT";
|
|
1156
|
-
}
|
|
1157
|
-
interface GenericLLm extends BaseLlmOptions {
|
|
1158
|
-
model?: string;
|
|
1159
|
-
system?: string;
|
|
1160
|
-
prompt?: string | {
|
|
1161
|
-
role: string;
|
|
1162
|
-
content: string;
|
|
1163
|
-
}[];
|
|
1164
|
-
temperature?: number;
|
|
1165
|
-
topP?: number;
|
|
1166
|
-
stream?: boolean;
|
|
1167
|
-
streamOptions?: Record<string, any>;
|
|
1168
|
-
maxTokens?: number;
|
|
1169
|
-
stopSequences?: string[];
|
|
1170
|
-
effort?: "minimal" | "low" | "medium" | "high";
|
|
1171
|
-
}
|
|
1172
|
-
interface OpenAiRequest extends GenericLLm {
|
|
1173
|
-
model: string;
|
|
1174
|
-
frequencyPenalty?: number;
|
|
1175
|
-
logitBias?: Record<string, any> | null;
|
|
1176
|
-
responseFormat?: Record<string, any>;
|
|
1177
|
-
openAiApiKey?: string;
|
|
1178
|
-
useJson?: boolean;
|
|
1179
|
-
}
|
|
1180
|
-
interface XAiRequest extends GenericLLm {
|
|
1181
|
-
model: string;
|
|
1182
|
-
frequencyPenalty?: number;
|
|
1183
|
-
logitBias?: Record<string, any> | null;
|
|
1184
|
-
responseFormat?: Record<string, any>;
|
|
1185
|
-
xAiApiKey?: string;
|
|
1186
|
-
useJson?: boolean;
|
|
1187
|
-
}
|
|
1188
|
-
interface AmazonBedrockRequest extends GenericLLm {
|
|
1189
|
-
model: string;
|
|
1190
|
-
awsRegion?: string;
|
|
1191
|
-
awsSecretKey?: string;
|
|
1192
|
-
awsAccessKey?: string;
|
|
1193
|
-
}
|
|
1194
|
-
interface AnthropicRequest extends GenericLLm {
|
|
1195
|
-
model: string;
|
|
1196
|
-
anthropicApiKey?: string;
|
|
1197
|
-
topK?: number;
|
|
1198
|
-
metadata?: {
|
|
1199
|
-
user_id?: string;
|
|
1200
|
-
};
|
|
1201
|
-
serviceTier?: "auto" | "standard_only";
|
|
1202
|
-
}
|
|
1203
|
-
interface GeminiRequest extends GenericLLm {
|
|
1204
|
-
model: string;
|
|
1205
|
-
geminiApiKey?: string;
|
|
1206
|
-
}
|
|
1207
|
-
interface DeepseekRequest extends GenericLLm {
|
|
1208
|
-
model: string;
|
|
1209
|
-
responseFormat?: Record<string, any>;
|
|
1210
|
-
deepseekApiKey?: string;
|
|
1211
|
-
useJson?: boolean;
|
|
1212
|
-
}
|
|
1213
|
-
type AllEmbedding = {
|
|
1214
|
-
"openai.embedding.v1": {
|
|
1215
|
-
input: OpenAiEmbeddingOptions;
|
|
1216
|
-
};
|
|
1217
|
-
"amazon.embedding.v1": {
|
|
1218
|
-
input: AmazonEmbeddingOptions;
|
|
1219
|
-
};
|
|
1220
|
-
"amazon:cohere.embedding.v1": {
|
|
1221
|
-
input: CohereBedrockEmbeddingOptions;
|
|
1222
|
-
};
|
|
1223
|
-
};
|
|
1224
|
-
type AllLlm = {
|
|
1225
|
-
"openai.chat.v1": {
|
|
1226
|
-
input: OpenAiRequest;
|
|
1227
|
-
};
|
|
1228
|
-
"openai.chat-mock.v1": {
|
|
1229
|
-
input: OpenAiRequest;
|
|
1230
|
-
};
|
|
1231
|
-
"anthropic.chat.v1": {
|
|
1232
|
-
input: AnthropicRequest;
|
|
1233
|
-
};
|
|
1234
|
-
"amazon:anthropic.chat.v1": {
|
|
1235
|
-
input: AnthropicRequest & AmazonBedrockRequest;
|
|
1236
|
-
};
|
|
1237
|
-
"amazon:meta.chat.v1": {
|
|
1238
|
-
input: AmazonBedrockRequest;
|
|
1239
|
-
};
|
|
1240
|
-
"xai.chat.v1": {
|
|
1241
|
-
input: XAiRequest;
|
|
1242
|
-
};
|
|
1243
|
-
"ollama.chat.v1": {
|
|
1244
|
-
input: GenericLLm;
|
|
1245
|
-
};
|
|
1246
|
-
"google.chat.v1": {
|
|
1247
|
-
input: GeminiRequest;
|
|
1248
|
-
};
|
|
1249
|
-
"deepseek.chat.v1": {
|
|
1250
|
-
input: DeepseekRequest;
|
|
1251
|
-
};
|
|
1252
|
-
};
|
|
1253
|
-
type AllUseLlmOptions = AllLlm & {
|
|
1254
|
-
"openai.gpt-5.2": {
|
|
1255
|
-
input: Omit<OpenAiRequest, "model">;
|
|
1256
|
-
};
|
|
1257
|
-
"openai.gpt-5-mini": {
|
|
1258
|
-
input: Omit<OpenAiRequest, "model">;
|
|
1259
|
-
};
|
|
1260
|
-
"openai.gpt-5-nano": {
|
|
1261
|
-
input: Omit<OpenAiRequest, "model">;
|
|
1262
|
-
};
|
|
1263
|
-
"openai.gpt-4.1": {
|
|
1264
|
-
input: Omit<OpenAiRequest, "model">;
|
|
1265
|
-
};
|
|
1266
|
-
"openai.gpt-4.1-mini": {
|
|
1267
|
-
input: Omit<OpenAiRequest, "model">;
|
|
1268
|
-
};
|
|
1269
|
-
"openai.gpt-4.1-nano": {
|
|
1270
|
-
input: Omit<OpenAiRequest, "model">;
|
|
1271
|
-
};
|
|
1272
|
-
"openai.o3": {
|
|
1273
|
-
input: Omit<OpenAiRequest, "model">;
|
|
1274
|
-
};
|
|
1275
|
-
"openai.gpt-4": {
|
|
1276
|
-
input: Omit<OpenAiRequest, "model">;
|
|
1277
|
-
};
|
|
1278
|
-
"openai.gpt-4o": {
|
|
1279
|
-
input: Omit<OpenAiRequest, "model">;
|
|
1280
|
-
};
|
|
1281
|
-
"openai.gpt-4o-mini": {
|
|
1282
|
-
input: Omit<OpenAiRequest, "model">;
|
|
1283
|
-
};
|
|
1284
|
-
"openai.o4-mini": {
|
|
1285
|
-
input: Omit<OpenAiRequest, "model">;
|
|
1286
|
-
};
|
|
1287
|
-
"anthropic.claude-opus-4-8": {
|
|
1288
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1289
|
-
};
|
|
1290
|
-
"anthropic.claude-opus-4-7": {
|
|
1291
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1292
|
-
};
|
|
1293
|
-
"anthropic.claude-sonnet-4-6": {
|
|
1294
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1295
|
-
};
|
|
1296
|
-
"anthropic.claude-opus-4-5": {
|
|
1297
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1298
|
-
};
|
|
1299
|
-
"anthropic.claude-haiku-4-5": {
|
|
1300
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1301
|
-
};
|
|
1302
|
-
"anthropic.claude-sonnet-4-5": {
|
|
1303
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1304
|
-
};
|
|
1305
|
-
"anthropic.claude-opus-4-6": {
|
|
1306
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1307
|
-
};
|
|
1308
|
-
"anthropic.claude-opus-4-1": {
|
|
1309
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1310
|
-
};
|
|
1311
|
-
"anthropic.claude-sonnet-4-0": {
|
|
1312
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1313
|
-
};
|
|
1314
|
-
"anthropic.claude-opus-4-0": {
|
|
1315
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1316
|
-
};
|
|
1317
|
-
"anthropic.claude-sonnet-4": {
|
|
1318
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1319
|
-
};
|
|
1320
|
-
"anthropic.claude-opus-4": {
|
|
1321
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1322
|
-
};
|
|
1323
|
-
"anthropic.claude-3-7-sonnet": {
|
|
1324
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1325
|
-
};
|
|
1326
|
-
"anthropic.claude-3-5-sonnet": {
|
|
1327
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1328
|
-
};
|
|
1329
|
-
"anthropic.claude-3-5-haiku": {
|
|
1330
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1331
|
-
};
|
|
1332
|
-
"anthropic.claude-3-opus": {
|
|
1333
|
-
input: Omit<AnthropicRequest, "model">;
|
|
1334
|
-
};
|
|
1335
|
-
"google.gemini-2.5-flash": {
|
|
1336
|
-
input: Omit<GeminiRequest, "model">;
|
|
1337
|
-
};
|
|
1338
|
-
"google.gemini-2.5-flash-lite": {
|
|
1339
|
-
input: Omit<GeminiRequest, "model">;
|
|
1340
|
-
};
|
|
1341
|
-
"google.gemini-2.5-pro": {
|
|
1342
|
-
input: Omit<GeminiRequest, "model">;
|
|
1343
|
-
};
|
|
1344
|
-
"google.gemini-3.1-flash-lite": {
|
|
1345
|
-
input: Omit<GeminiRequest, "model">;
|
|
1346
|
-
};
|
|
1347
|
-
"google.gemini-3.5-flash": {
|
|
1348
|
-
input: Omit<GeminiRequest, "model">;
|
|
1349
|
-
};
|
|
1350
|
-
"google.gemini-2.0-flash": {
|
|
1351
|
-
input: Omit<GeminiRequest, "model">;
|
|
1352
|
-
};
|
|
1353
|
-
"google.gemini-2.0-flash-lite": {
|
|
1354
|
-
input: Omit<GeminiRequest, "model">;
|
|
1355
|
-
};
|
|
1356
|
-
"google.gemini-1.5-pro": {
|
|
1357
|
-
input: Omit<GeminiRequest, "model">;
|
|
1358
|
-
};
|
|
1359
|
-
"xai.grok-2": {
|
|
1360
|
-
input: Omit<XAiRequest, "model">;
|
|
1361
|
-
};
|
|
1362
|
-
"xai.grok-3": {
|
|
1363
|
-
input: Omit<XAiRequest, "model">;
|
|
1364
|
-
};
|
|
1365
|
-
"xai.grok-3-mini": {
|
|
1366
|
-
input: Omit<XAiRequest, "model">;
|
|
1367
|
-
};
|
|
1368
|
-
"xai.grok-4": {
|
|
1369
|
-
input: Omit<XAiRequest, "model">;
|
|
1370
|
-
};
|
|
1371
|
-
"xai.grok-4-fast": {
|
|
1372
|
-
input: Omit<XAiRequest, "model">;
|
|
1373
|
-
};
|
|
1374
|
-
"xai.grok-4-1-fast": {
|
|
1375
|
-
input: Omit<XAiRequest, "model">;
|
|
1376
|
-
};
|
|
1377
|
-
"xai.grok-4.3": {
|
|
1378
|
-
input: Omit<XAiRequest, "model">;
|
|
1379
|
-
};
|
|
1380
|
-
"xai.grok-4.20": {
|
|
1381
|
-
input: Omit<XAiRequest, "model">;
|
|
1382
|
-
};
|
|
1383
|
-
"xai.grok-4.20-reasoning": {
|
|
1384
|
-
input: Omit<XAiRequest, "model">;
|
|
1385
|
-
};
|
|
1386
|
-
"ollama.deepseek-r1": {
|
|
1387
|
-
input: GenericLLm;
|
|
1388
|
-
};
|
|
1389
|
-
"ollama.llama3.3": {
|
|
1390
|
-
input: GenericLLm;
|
|
1391
|
-
};
|
|
1392
|
-
"ollama.llama3.2": {
|
|
1393
|
-
input: GenericLLm;
|
|
1394
|
-
};
|
|
1395
|
-
"ollama.llama3.1": {
|
|
1396
|
-
input: GenericLLm;
|
|
1397
|
-
};
|
|
1398
|
-
"ollama.qwq": {
|
|
1399
|
-
input: GenericLLm;
|
|
1400
|
-
};
|
|
1401
|
-
"ollama.gemma3": {
|
|
1402
|
-
input: GenericLLm;
|
|
1403
|
-
};
|
|
1404
|
-
"ollama.mistral": {
|
|
1405
|
-
input: GenericLLm;
|
|
1406
|
-
};
|
|
1407
|
-
"ollama.qwen2.5": {
|
|
1408
|
-
input: GenericLLm;
|
|
1409
|
-
};
|
|
1410
|
-
"ollama.qwen3": {
|
|
1411
|
-
input: GenericLLm;
|
|
1412
|
-
};
|
|
1413
|
-
"ollama.qwen3.5": {
|
|
1414
|
-
input: GenericLLm;
|
|
1415
|
-
};
|
|
1416
|
-
"ollama.gemma4": {
|
|
1417
|
-
input: GenericLLm;
|
|
1418
|
-
};
|
|
1419
|
-
"ollama.gpt-oss": {
|
|
1420
|
-
input: GenericLLm;
|
|
1421
|
-
};
|
|
1422
|
-
"deepseek.chat": {
|
|
1423
|
-
input: DeepseekRequest;
|
|
1424
|
-
};
|
|
1425
|
-
"deepseek.v4-flash": {
|
|
1426
|
-
input: Omit<DeepseekRequest, "model">;
|
|
1427
|
-
};
|
|
1428
|
-
"deepseek.v4-pro": {
|
|
1429
|
-
input: Omit<DeepseekRequest, "model">;
|
|
1430
|
-
};
|
|
1431
|
-
};
|
|
1432
|
-
type LlmProviderKey = keyof AllLlm;
|
|
1433
|
-
type EmbeddingProviderKey = keyof AllEmbedding;
|
|
1434
|
-
type UseLlmKey = keyof AllUseLlmOptions;
|
|
1435
|
-
interface BaseLlCall {
|
|
1436
|
-
getResultContent: () => OutputResultContent[];
|
|
1437
|
-
getResultText: () => string;
|
|
1438
|
-
getResult: () => OutputResult;
|
|
1439
|
-
}
|
|
1440
|
-
interface BaseRequest<_T extends Record<string, any>> {
|
|
1441
|
-
call: (...args: any[]) => Promise<_T>;
|
|
1442
|
-
getTraceId: () => string | null;
|
|
1443
|
-
withTraceId: (traceId: string) => void;
|
|
1444
|
-
getMetadata: () => Record<string, any>;
|
|
1445
|
-
}
|
|
1446
|
-
interface BaseLlm<_T extends BaseLlCall = BaseLlCall> extends BaseRequest<_T> {
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
type LlmProvider = "openai.chat" | "openai.embedding" | "google.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "amazon:cohere.embedding" | "xai.chat" | "google.chat" | "ollama.chat" | "deepseek.chat";
|
|
1450
|
-
interface Config<Pk = LlmProviderKey> {
|
|
1451
|
-
/**
|
|
1452
|
-
* Unique identifier for this configuration (e.g., "openai.chat.v1", "anthropic.claude-3-opus")
|
|
1453
|
-
* Used to reference this config when calling useLlm()
|
|
1454
|
-
*/
|
|
1455
|
-
key: Pk;
|
|
1456
|
-
/**
|
|
1457
|
-
* The provider type this config is for (e.g., "openai.chat", "anthropic.chat")
|
|
1458
|
-
* Used internally for provider-specific logic
|
|
1459
|
-
*/
|
|
1460
|
-
provider: LlmProvider;
|
|
1461
|
-
/**
|
|
1462
|
-
* HTTP method for the API request (typically "POST" for LLM providers)
|
|
1463
|
-
*/
|
|
1464
|
-
method: "POST" | "PUT" | "GET";
|
|
1465
|
-
/**
|
|
1466
|
-
* API endpoint URL template. Supports template variables using {{variable}} syntax
|
|
1467
|
-
* Variables are replaced with values from the state object
|
|
1468
|
-
* @example "https://api.openai.com/v1/chat/completions"
|
|
1469
|
-
* @example "https://bedrock-runtime.{{awsRegion}}.amazonaws.com/model/{{model}}/invoke"
|
|
1470
|
-
*/
|
|
1471
|
-
endpoint: string;
|
|
1472
|
-
/**
|
|
1473
|
-
* HTTP headers template as a JSON string. Supports template variables using {{variable}} syntax
|
|
1474
|
-
* @example '{"Authorization":"Bearer {{openAiApiKey}}", "Content-Type": "application/json"}'
|
|
1475
|
-
* // TODO: make this also accept object and function
|
|
1476
|
-
*/
|
|
1477
|
-
headers: string;
|
|
1478
|
-
options: {
|
|
1479
|
-
[key in string]: {
|
|
1480
|
-
/**
|
|
1481
|
-
* Default value for this parameter if not provided by the user
|
|
1482
|
-
* Can be a static value or a function that returns the value
|
|
1483
|
-
* @example 4096
|
|
1484
|
-
* @example () => process.env.OPENAI_API_KEY
|
|
1485
|
-
*/
|
|
1486
|
-
default?: any;
|
|
1487
|
-
/**
|
|
1488
|
-
* Whether this parameter is required
|
|
1489
|
-
* [true, "error message"] - Required with custom error
|
|
1490
|
-
* [true] - Required with default error message
|
|
1491
|
-
* @example [true, "maxTokens is required for Anthropic"]
|
|
1492
|
-
*/
|
|
1493
|
-
required?: [boolean, string] | [boolean];
|
|
1494
|
-
};
|
|
1495
|
-
};
|
|
1496
|
-
mapBody: {
|
|
1497
|
-
[key in string]: {
|
|
1498
|
-
/**
|
|
1499
|
-
* The target field name in the provider's request body.
|
|
1500
|
-
* Supports dot notation for nested fields (e.g., "response_format.type")
|
|
1501
|
-
*/
|
|
1502
|
-
key: string;
|
|
1503
|
-
/**
|
|
1504
|
-
* Default value to use if the source field is not provided
|
|
1505
|
-
*/
|
|
1506
|
-
default?: any;
|
|
1507
|
-
/**
|
|
1508
|
-
* Transform function to convert the value before mapping to the request body
|
|
1509
|
-
* @param value - The input value from the user's state
|
|
1510
|
-
* @param state - The complete user state object containing all parameters
|
|
1511
|
-
* @param config - The current Config object (for access to options, etc.)
|
|
1512
|
-
* @returns The transformed value to be included in the request body
|
|
1513
|
-
*/
|
|
1514
|
-
transform?: (value: any, state: Record<string, any>, config: Record<string, any>) => any;
|
|
1515
|
-
};
|
|
1516
|
-
};
|
|
1517
|
-
/**
|
|
1518
|
-
* Maps executor-level options (jsonSchema, functions, functionCall) to provider-specific request formats
|
|
1519
|
-
* @optional - Only needed if provider supports these features
|
|
1520
|
-
*/
|
|
1521
|
-
mapOptions?: {
|
|
1522
|
-
/**
|
|
1523
|
-
* Transform JSON schema into provider-specific format
|
|
1524
|
-
* @param schema - The JSON schema object
|
|
1525
|
-
* @param options - Executor options (e.g., functionCallStrictInput)
|
|
1526
|
-
* @param currentInput - Current accumulated input state (for merging)
|
|
1527
|
-
* @param config - The full config object
|
|
1528
|
-
* @returns Provider-specific request body additions
|
|
1529
|
-
*/
|
|
1530
|
-
jsonSchema?: (schema: any, options: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
|
|
1531
|
-
/**
|
|
1532
|
-
* Transform function call mode into provider-specific format
|
|
1533
|
-
* @param call - Function call mode ("auto", "any", "none", or specific function)
|
|
1534
|
-
* @param options - Executor options
|
|
1535
|
-
* @param currentInput - Current accumulated input state (for merging)
|
|
1536
|
-
* @param config - The full config object
|
|
1537
|
-
* @returns Provider-specific request body additions
|
|
1538
|
-
*/
|
|
1539
|
-
functionCall?: (call: any, options?: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
|
|
1540
|
-
/**
|
|
1541
|
-
* Transform function definitions into provider-specific format
|
|
1542
|
-
* @param functions - Array of function definitions
|
|
1543
|
-
* @param options - Executor options (e.g., functionCallStrictInput)
|
|
1544
|
-
* @param currentInput - Current accumulated input state (for merging)
|
|
1545
|
-
* @param config - The full config object
|
|
1546
|
-
* @returns Provider-specific request body additions
|
|
1547
|
-
*/
|
|
1548
|
-
functions?: (functions: any[], options?: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
|
|
1549
|
-
};
|
|
1550
|
-
/**
|
|
1551
|
-
* Optional response transformer for chat/LLM configs. The LLM call path
|
|
1552
|
-
* (`llm.call.ts`) defaults to `OutputDefault` when this is omitted.
|
|
1553
|
-
* Embedding configs do not use this — their flow dispatches via
|
|
1554
|
-
* `getEmbeddingOutputParser` instead.
|
|
1555
|
-
*/
|
|
1556
|
-
transformResponse?: (result: any, _config?: Config<any>, headers?: Record<string, string>) => OutputResult;
|
|
1557
|
-
/**
|
|
1558
|
-
* Marks this config as deprecated. When set, useLlm() will emit a one-time
|
|
1559
|
-
* deprecation warning to inform users about upcoming model shutdowns.
|
|
1560
|
-
*/
|
|
1561
|
-
deprecated?: {
|
|
1562
|
-
shorthand: string;
|
|
1563
|
-
message: string;
|
|
1564
|
-
};
|
|
1565
|
-
}
|
|
486
|
+
declare function createLlmExecutor<Llm extends BaseLlm<any>, Prompt extends BasePrompt<any>, Parser extends BaseParser, State extends BaseState>(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<PromptInput<Prompt>, ParserOutput<Parser>, BaseLlCall, ReturnType<Prompt["format"]>, LlmExecutorHooks>): LlmExecutor<Llm, Prompt, Parser, State>;
|
|
487
|
+
declare function createLlmFunctionExecutor<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState>(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<PromptInput<Prompt>, ParserOutput<LlmFunctionParser<Parser>>, BaseLlCall, ReturnType<Prompt["format"]>, LlmExecutorHooks>): LlmExecutorWithFunctions<Llm, Prompt, Parser, State>;
|
|
1566
488
|
|
|
1567
489
|
type JsonSafe = string | number | boolean | null | JsonSafe[] | {
|
|
1568
490
|
[key: string]: JsonSafe;
|
|
@@ -1604,6 +526,29 @@ type InvalidHeadersContext = BaseErrorContext & {
|
|
|
1604
526
|
headerTemplate?: string;
|
|
1605
527
|
replacedHeadersExcerpt?: string;
|
|
1606
528
|
};
|
|
529
|
+
type ConfigParseContext = BaseErrorContext & {
|
|
530
|
+
format?: string;
|
|
531
|
+
position?: number;
|
|
532
|
+
snippet?: string;
|
|
533
|
+
source?: string;
|
|
534
|
+
};
|
|
535
|
+
type ConfigInvalidContext = BaseErrorContext & {
|
|
536
|
+
field?: string;
|
|
537
|
+
expected?: unknown;
|
|
538
|
+
received?: unknown;
|
|
539
|
+
schemaErrors?: string[];
|
|
540
|
+
availableProviders?: string[];
|
|
541
|
+
};
|
|
542
|
+
type ConfigFileContext = BaseErrorContext & {
|
|
543
|
+
path?: string;
|
|
544
|
+
syscall?: string;
|
|
545
|
+
errno?: string;
|
|
546
|
+
};
|
|
547
|
+
type ConfigFormatContext = BaseErrorContext & {
|
|
548
|
+
format?: string;
|
|
549
|
+
path?: string;
|
|
550
|
+
supported?: string[];
|
|
551
|
+
};
|
|
1607
552
|
type ParserInvalidTypeContext = BaseErrorContext & {
|
|
1608
553
|
parser?: unknown;
|
|
1609
554
|
availableParsers?: string[];
|
|
@@ -1710,6 +655,11 @@ type ErrorContextByCode = {
|
|
|
1710
655
|
"configuration.missing_env": MissingConfigurationContext;
|
|
1711
656
|
"configuration.missing_option": MissingConfigurationContext;
|
|
1712
657
|
"configuration.invalid_headers": InvalidHeadersContext;
|
|
658
|
+
"configuration.parse_failed": ConfigParseContext;
|
|
659
|
+
"configuration.invalid_config": ConfigInvalidContext;
|
|
660
|
+
"configuration.file_not_found": ConfigFileContext;
|
|
661
|
+
"configuration.file_read_failed": ConfigFileContext;
|
|
662
|
+
"configuration.unsupported_format": ConfigFormatContext;
|
|
1713
663
|
"parser.invalid_type": ParserInvalidTypeContext;
|
|
1714
664
|
"parser.invalid_input": ParserParseFailedContext;
|
|
1715
665
|
"parser.parse_failed": ParserParseFailedContext;
|
|
@@ -1771,6 +721,9 @@ type LlmExeErrorJson<C extends ErrorCodes = ErrorCodes> = {
|
|
|
1771
721
|
cause?: SerializableCause;
|
|
1772
722
|
truncated?: boolean;
|
|
1773
723
|
};
|
|
724
|
+
type SerializeOptions = {
|
|
725
|
+
includeStack?: boolean;
|
|
726
|
+
};
|
|
1774
727
|
|
|
1775
728
|
declare function enforceResultAttributes<O>(input: any): {
|
|
1776
729
|
result: O;
|
|
@@ -1910,6 +863,8 @@ declare function importHelpers(_helpers: {
|
|
|
1910
863
|
|
|
1911
864
|
declare function filterObjectOnSchema(schema: any, doc: any, detach?: any, property?: string): any;
|
|
1912
865
|
|
|
866
|
+
declare function escapeTemplateString(input: string): string;
|
|
867
|
+
|
|
1913
868
|
declare const asyncCallWithTimeout: <T = any>(asyncPromise: Promise<T>, timeLimit?: number) => Promise<T>;
|
|
1914
869
|
|
|
1915
870
|
declare function guessProviderFromModel(payload: {
|
|
@@ -1929,6 +884,7 @@ declare const index_LlmExeError: typeof LlmExeError;
|
|
|
1929
884
|
declare const index_assert: typeof assert;
|
|
1930
885
|
declare const index_asyncCallWithTimeout: typeof asyncCallWithTimeout;
|
|
1931
886
|
declare const index_defineSchema: typeof defineSchema;
|
|
887
|
+
declare const index_escapeTemplateString: typeof escapeTemplateString;
|
|
1932
888
|
declare const index_filterObjectOnSchema: typeof filterObjectOnSchema;
|
|
1933
889
|
declare const index_guessProviderFromModel: typeof guessProviderFromModel;
|
|
1934
890
|
declare const index_importHelpers: typeof importHelpers;
|
|
@@ -1942,7 +898,7 @@ declare const index_registerPartials: typeof registerPartials;
|
|
|
1942
898
|
declare const index_replaceTemplateString: typeof replaceTemplateString;
|
|
1943
899
|
declare const index_replaceTemplateStringAsync: typeof replaceTemplateStringAsync;
|
|
1944
900
|
declare namespace index {
|
|
1945
|
-
export { index_LLM_EXE_ERROR_SYMBOL as LLM_EXE_ERROR_SYMBOL, index_LlmExeError as LlmExeError, index_assert as assert, index_asyncCallWithTimeout as asyncCallWithTimeout, index_defineSchema as defineSchema, index_filterObjectOnSchema as filterObjectOnSchema, index_guessProviderFromModel as guessProviderFromModel, index_importHelpers as importHelpers, index_importPartials as importPartials, index_isLlmExeError as isLlmExeError, index_isObjectStringified as isObjectStringified, index_maybeParseJSON as maybeParseJSON, index_maybeStringifyJSON as maybeStringifyJSON, index_registerHelpers as registerHelpers, index_registerPartials as registerPartials, index_replaceTemplateString as replaceTemplateString, index_replaceTemplateStringAsync as replaceTemplateStringAsync };
|
|
901
|
+
export { index_LLM_EXE_ERROR_SYMBOL as LLM_EXE_ERROR_SYMBOL, index_LlmExeError as LlmExeError, index_assert as assert, index_asyncCallWithTimeout as asyncCallWithTimeout, index_defineSchema as defineSchema, index_escapeTemplateString as escapeTemplateString, index_filterObjectOnSchema as filterObjectOnSchema, index_guessProviderFromModel as guessProviderFromModel, index_importHelpers as importHelpers, index_importPartials as importPartials, index_isLlmExeError as isLlmExeError, index_isObjectStringified as isObjectStringified, index_maybeParseJSON as maybeParseJSON, index_maybeStringifyJSON as maybeStringifyJSON, index_registerHelpers as registerHelpers, index_registerPartials as registerPartials, index_replaceTemplateString as replaceTemplateString, index_replaceTemplateStringAsync as replaceTemplateStringAsync };
|
|
1946
902
|
}
|
|
1947
903
|
|
|
1948
904
|
declare function isOutputResult(obj: any): obj is OutputResult;
|
|
@@ -1974,75 +930,6 @@ declare namespace guards {
|
|
|
1974
930
|
export { guards_hasFunctionCall as hasFunctionCall, guards_hasToolCall as hasToolCall, guards_isAssistantMessage as isAssistantMessage, guards_isFunctionCall as isFunctionCall, guards_isOutputResult as isOutputResult, guards_isOutputResultContentText as isOutputResultContentText, guards_isSystemMessage as isSystemMessage, guards_isToolCall as isToolCall, guards_isUserMessage as isUserMessage };
|
|
1975
931
|
}
|
|
1976
932
|
|
|
1977
|
-
declare const configs: {
|
|
1978
|
-
"deepseek.chat.v1": Config<keyof AllLlm>;
|
|
1979
|
-
"deepseek.chat": Config<keyof AllLlm>;
|
|
1980
|
-
"deepseek.v4-flash": Config<keyof AllLlm>;
|
|
1981
|
-
"deepseek.v4-pro": Config<keyof AllLlm>;
|
|
1982
|
-
"google.gemini-2.0-flash": Config<keyof AllLlm>;
|
|
1983
|
-
"google.gemini-2.0-flash-lite": Config<keyof AllLlm>;
|
|
1984
|
-
"google.gemini-1.5-pro": Config<keyof AllLlm>;
|
|
1985
|
-
"google.gemini-2.5-pro": Config<any>;
|
|
1986
|
-
"google.gemini-2.5-flash-lite": Config<any>;
|
|
1987
|
-
"google.gemini-2.5-flash": Config<any>;
|
|
1988
|
-
"google.chat.v1": Config<keyof AllLlm>;
|
|
1989
|
-
"google.gemini-3.1-flash-lite": Config<keyof AllLlm>;
|
|
1990
|
-
"google.gemini-3.5-flash": Config<keyof AllLlm>;
|
|
1991
|
-
"ollama.chat.v1": Config<keyof AllLlm>;
|
|
1992
|
-
"ollama.deepseek-r1": Config<keyof AllLlm>;
|
|
1993
|
-
"ollama.llama3.3": Config<keyof AllLlm>;
|
|
1994
|
-
"ollama.llama3.2": Config<keyof AllLlm>;
|
|
1995
|
-
"ollama.llama3.1": Config<keyof AllLlm>;
|
|
1996
|
-
"ollama.qwq": Config<keyof AllLlm>;
|
|
1997
|
-
"ollama.gemma3": Config<keyof AllLlm>;
|
|
1998
|
-
"ollama.mistral": Config<keyof AllLlm>;
|
|
1999
|
-
"ollama.qwen2.5": Config<keyof AllLlm>;
|
|
2000
|
-
"ollama.qwen3": Config<keyof AllLlm>;
|
|
2001
|
-
"ollama.qwen3.5": Config<keyof AllLlm>;
|
|
2002
|
-
"ollama.gemma4": Config<keyof AllLlm>;
|
|
2003
|
-
"ollama.gpt-oss": Config<keyof AllLlm>;
|
|
2004
|
-
"xai.chat.v1": Config<keyof AllLlm>;
|
|
2005
|
-
"xai.grok-2": Config<keyof AllLlm>;
|
|
2006
|
-
"xai.grok-3": Config<keyof AllLlm>;
|
|
2007
|
-
"xai.grok-3-mini": Config<keyof AllLlm>;
|
|
2008
|
-
"xai.grok-4": Config<keyof AllLlm>;
|
|
2009
|
-
"xai.grok-4-fast": Config<keyof AllLlm>;
|
|
2010
|
-
"xai.grok-4-1-fast": Config<keyof AllLlm>;
|
|
2011
|
-
"xai.grok-4.3": Config<keyof AllLlm>;
|
|
2012
|
-
"xai.grok-4.20": Config<keyof AllLlm>;
|
|
2013
|
-
"xai.grok-4.20-reasoning": Config<keyof AllLlm>;
|
|
2014
|
-
"amazon:anthropic.chat.v1": Config<keyof AllLlm>;
|
|
2015
|
-
"amazon:meta.chat.v1": Config<keyof AllLlm>;
|
|
2016
|
-
"anthropic.claude-3-opus": Config<any>;
|
|
2017
|
-
"anthropic.claude-3-5-haiku": Config<any>;
|
|
2018
|
-
"anthropic.claude-3-5-sonnet": Config<any>;
|
|
2019
|
-
"anthropic.claude-3-7-sonnet": Config<any>;
|
|
2020
|
-
"anthropic.claude-opus-4": Config<any>;
|
|
2021
|
-
"anthropic.claude-sonnet-4": Config<any>;
|
|
2022
|
-
"anthropic.claude-opus-4-1": Config<any>;
|
|
2023
|
-
"anthropic.claude-opus-4-6": Config<any>;
|
|
2024
|
-
"anthropic.chat.v1": Config<keyof AllLlm>;
|
|
2025
|
-
"anthropic.claude-opus-4-8": Config<keyof AllLlm>;
|
|
2026
|
-
"anthropic.claude-opus-4-7": Config<keyof AllLlm>;
|
|
2027
|
-
"anthropic.claude-sonnet-4-6": Config<keyof AllLlm>;
|
|
2028
|
-
"anthropic.claude-opus-4-5": Config<keyof AllLlm>;
|
|
2029
|
-
"anthropic.claude-haiku-4-5": Config<keyof AllLlm>;
|
|
2030
|
-
"anthropic.claude-sonnet-4-5": Config<keyof AllLlm>;
|
|
2031
|
-
"openai.o4-mini": Config<any>;
|
|
2032
|
-
"openai.chat.v1": Config<keyof AllLlm>;
|
|
2033
|
-
"openai.chat-mock.v1": Config<keyof AllLlm>;
|
|
2034
|
-
"openai.gpt-5.2": Config<keyof AllLlm>;
|
|
2035
|
-
"openai.gpt-5-mini": Config<keyof AllLlm>;
|
|
2036
|
-
"openai.gpt-5-nano": Config<keyof AllLlm>;
|
|
2037
|
-
"openai.gpt-4.1": Config<keyof AllLlm>;
|
|
2038
|
-
"openai.gpt-4.1-mini": Config<keyof AllLlm>;
|
|
2039
|
-
"openai.gpt-4.1-nano": Config<keyof AllLlm>;
|
|
2040
|
-
"openai.o3": Config<keyof AllLlm>;
|
|
2041
|
-
"openai.gpt-4": Config<keyof AllLlm>;
|
|
2042
|
-
"openai.gpt-4o": Config<keyof AllLlm>;
|
|
2043
|
-
"openai.gpt-4o-mini": Config<keyof AllLlm>;
|
|
2044
|
-
};
|
|
2045
|
-
|
|
2046
933
|
declare function useLlm<T extends keyof typeof configs>(provider: T, options?: AllUseLlmOptions[T]["input"]): BaseLlm;
|
|
2047
934
|
declare function useLlmConfiguration<T extends keyof typeof configs>(config: Config<any>): (options?: AllUseLlmOptions[T]["input"]) => {
|
|
2048
935
|
call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions, context?: ExecutionContext) => Promise<{
|
|
@@ -2092,4 +979,51 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
|
|
|
2092
979
|
};
|
|
2093
980
|
};
|
|
2094
981
|
|
|
2095
|
-
|
|
982
|
+
type AnyConfigExecutor = LlmExecutor<any, any, any, any>;
|
|
983
|
+
/**
|
|
984
|
+
* Validate and normalize a config object into an `ExecutorConfig`. Browser-safe.
|
|
985
|
+
*
|
|
986
|
+
* Public alias for the internal `normalizeConfig` (which is not exported). The
|
|
987
|
+
* exported name matches the `parseExecutorConfig` / `executorFromConfig` family
|
|
988
|
+
* and decouples the public API from the internal signature.
|
|
989
|
+
*/
|
|
990
|
+
declare function loadExecutorConfig(object: unknown, patch?: ExecutorConfigPatch): ExecutorConfig;
|
|
991
|
+
/**
|
|
992
|
+
* Build a native `LlmExecutor` from a config. `createOptions` sets
|
|
993
|
+
* construction-time options such as hooks. `executorOptions` is not applied
|
|
994
|
+
* here; the caller passes it at execute time via `.execute(input, options)`.
|
|
995
|
+
* An `executorOptions.functions` array selects the function-calling executor.
|
|
996
|
+
*/
|
|
997
|
+
declare function executorFromConfig(config: ExecutorConfig, createOptions?: ExecutorCreateOptions): AnyConfigExecutor;
|
|
998
|
+
/**
|
|
999
|
+
* Run a config once. Deep-merges `overrides.data` over `config.data` and
|
|
1000
|
+
* shallow-merges `overrides.executorOptions` over `config.executorOptions`,
|
|
1001
|
+
* then executes. `executorOptions` is passed to `.execute()`, which is where a
|
|
1002
|
+
* function executor receives its `functions`.
|
|
1003
|
+
*/
|
|
1004
|
+
declare function runConfig(config: ExecutorConfig, overrides?: RunOverrides, createOptions?: ExecutorCreateOptions): Promise<unknown>;
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* Parse a config from an in-memory string in a known (or auto-detected) format.
|
|
1008
|
+
* Async for surface uniformity with the file/URL loaders. Browser-safe.
|
|
1009
|
+
*/
|
|
1010
|
+
declare function parseExecutorConfig(source: string, opts: {
|
|
1011
|
+
format: Format;
|
|
1012
|
+
} & ExecutorConfigPatch): Promise<ExecutorConfig>;
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Load a config from a URL. `fetch` defaults to the global but is injectable
|
|
1016
|
+
* (testable without network). The library never chooses the URL — the caller
|
|
1017
|
+
* does — so the trust decision is the caller's. Browser-safe.
|
|
1018
|
+
*/
|
|
1019
|
+
declare function loadConfigFromUrl(url: string, opts?: {
|
|
1020
|
+
fetch?: typeof fetch;
|
|
1021
|
+
init?: RequestInit;
|
|
1022
|
+
format?: Format;
|
|
1023
|
+
} & ExecutorConfigPatch): Promise<ExecutorConfig>;
|
|
1024
|
+
|
|
1025
|
+
declare function serializeLlmExeError(error: unknown, options?: SerializeOptions): JsonSafe;
|
|
1026
|
+
|
|
1027
|
+
declare function formatLlmExeErrorForLog(error: unknown): string;
|
|
1028
|
+
|
|
1029
|
+
export { BaseExecutor, BaseLlm, BaseParser, BasePrompt, type BooleanParserMatch, type BooleanParserOptions, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, EmbeddingProviderKey, type ErrorCategory, type ErrorCodes, type ErrorContextByCode, ExecutionContext, ExecutorConfig, ExecutorConfigPatch, Format, IChatMessages, JsonParserOptions, LLM_EXE_ERROR_SYMBOL, LlmExeError, LlmExecutorOpenAiFunctions, LlmExecutorWithFunctions, LlmNativeFunctionParser, type NormalizedProviderError, type NumberParserMatch, type NumberParserOptions, type OpenAIModelName, OpenAiFunctionParser, type ProviderErrorContext, type StringExtractMatch, type StringExtractParserOptions, TextPrompt, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createLlmFunctionExecutor, createOpenAiCompatibleConfiguration, createParser, createPrompt, createState, createStateItem, defineSchema, executorFromConfig, formatLlmExeErrorForLog, guards, isLlmExeError, loadConfigFromUrl, loadExecutorConfig, parseExecutorConfig, registerHelpers, registerPartials, runConfig, serializeLlmExeError, useExecutors, useLlm, useLlmConfiguration, index as utils };
|