llm-exe 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -31,21 +31,23 @@ interface IChatUserMessage extends IChatMessageBase {
31
31
  name?: string;
32
32
  }
33
33
  interface IChatFunctionMessage extends IChatMessageBase {
34
+ id?: string;
34
35
  role: Extract<IChatMessageRole, "function">;
35
36
  content: string;
36
37
  name: string;
37
38
  }
38
39
  interface IChatAssistantMessage extends IChatMessageBase {
39
- role: Extract<IChatMessageRole, "assistant">;
40
+ role: Extract<IChatMessageRole, "assistant" | "model">;
40
41
  content: string;
41
42
  function_call?: undefined;
42
43
  }
43
- interface IChatAssistantFunctionCallMessage extends IChatMessageBase {
44
- role: Extract<IChatMessageRole, "assistant">;
44
+ interface IChatFunctionCallMessage extends IChatMessageBase {
45
+ role: Extract<IChatMessageRole, "function_call">;
45
46
  content: null;
46
- function_call?: {
47
+ function_call: {
47
48
  name: string;
48
49
  arguments: string;
50
+ id?: string;
49
51
  };
50
52
  }
51
53
  interface IChatSystemMessage extends IChatMessageBase {
@@ -57,8 +59,8 @@ interface IChatMessagesPlaceholder {
57
59
  content: string;
58
60
  }
59
61
  type IPromptMessages = (IChatSystemMessage | IChatMessagesPlaceholder)[];
60
- type IPromptChatMessages = (IChatUserMessage | IChatAssistantMessage | IChatAssistantFunctionCallMessage | IChatSystemMessage | IChatMessagesPlaceholder | IChatFunctionMessage)[];
61
- type IChatMessage = IChatUserMessage | IChatAssistantMessage | IChatAssistantFunctionCallMessage | IChatSystemMessage | IChatFunctionMessage;
62
+ type IPromptChatMessages = (IChatUserMessage | IChatAssistantMessage | IChatFunctionCallMessage | IChatSystemMessage | IChatMessagesPlaceholder | IChatFunctionMessage)[];
63
+ type IChatMessage = IChatUserMessage | IChatAssistantMessage | IChatFunctionCallMessage | IChatSystemMessage | IChatFunctionMessage;
62
64
  type IChatMessages = IChatMessage[];
63
65
 
64
66
  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}`;
@@ -66,6 +68,7 @@ type OpenAIConversationModelName = "davinci" | "text-curie-001" | "text-babbage-
66
68
  type OpenAIEmbeddingModelName = "text-embedding-ada-002";
67
69
  type OpenAIModelName = OpenAIChatModelName | OpenAIConversationModelName | OpenAIEmbeddingModelName;
68
70
 
71
+ type ParserInput = string | OutputResult;
69
72
  /**
70
73
  * BaseParser is an abstract class for parsing text and enforcing JSON schema on the parsed data.
71
74
  */
@@ -86,7 +89,7 @@ declare abstract class BaseParser<T = any> {
86
89
  * @param [attributes] - Optional attributes to use during parsing.
87
90
  * @returns The parsed data.
88
91
  */
89
- abstract parse(text: string | OutputResultContent[], attributes?: Record<string, any>): T;
92
+ abstract parse(text: ParserInput, attributes?: Record<string, any>): T;
90
93
  }
91
94
  declare abstract class BaseParserWithJson<S extends JSONSchema | undefined = undefined, T = S extends JSONSchema ? FromSchema<S> : Record<string, any>> extends BaseParser<T> {
92
95
  schema: S;
@@ -103,7 +106,7 @@ interface StringParserOptions extends BaseParserOptions {
103
106
  }
104
107
  declare class StringParser extends BaseParser<string> {
105
108
  constructor(options?: StringParserOptions);
106
- parse(text: string | OutputResultContent[], _options?: Record<string, any>): string;
109
+ parse(text: string | OutputResult, _options?: Record<string, any>): string;
107
110
  }
108
111
 
109
112
  interface BooleanParserOptions extends BaseParserOptions {
@@ -301,16 +304,27 @@ declare function createParser<T extends Extract<CreateParserType, "json">, S ext
301
304
  declare function createParser<T extends CreateParserType, S extends JSONSchema | undefined = undefined>(type: T, options?: BaseParserOptionsWithSchema<S> | BaseParserOptions): JsonParser<S> | ListToJsonParser<S> | StringParser | NumberParser | BooleanParser | ListToArrayParser | ListToKeyValueParser | ReplaceStringTemplateParser | MarkdownCodeBlockParser | MarkdownCodeBlocksParser | StringExtractParser;
302
305
  declare function createCustomParser<O>(name: string, parserFn: (text: string, inputValues: ExecutorContext<any, any>) => O): CustomParser<ReturnType<typeof parserFn>>;
303
306
 
307
+ declare class LlmFunctionParser<T extends BaseParser<any>> extends BaseParser<ParserOutput<T> | OutputResultContent[]> {
308
+ parser: T;
309
+ constructor(options: LlmNativeFunctionParserOptions<T>);
310
+ parse(text: OutputResult, _options?: Record<string, any>): OutputResultContent[] | ParserOutput<T>;
311
+ }
312
+ interface LlmNativeFunctionParserOptions<T extends BaseParser<any>> extends BaseParserOptions {
313
+ parser: T;
314
+ }
304
315
  interface LlmNativeFunctionParserOptions<T extends BaseParser<any>> extends BaseParserOptions {
305
316
  parser: T;
306
317
  }
318
+ /**
319
+ * @deprecated Use `LlmFunctionParser` instead.
320
+ */
307
321
  declare class LlmNativeFunctionParser<T extends BaseParser<any>> extends BaseParser<ParserOutput<T> | {
308
322
  name: any;
309
323
  arguments: any;
310
324
  }> {
311
325
  parser: T;
312
326
  constructor(options: LlmNativeFunctionParserOptions<T>);
313
- parse(text: OutputResultContent[], _options?: Record<string, any>): ParserOutput<T> | {
327
+ parse(text: OutputResult, _options?: Record<string, any>): ParserOutput<T> | {
314
328
  name: string;
315
329
  arguments: any;
316
330
  };
@@ -435,7 +449,7 @@ declare class ChatPrompt<I extends Record<string, any>> extends BasePrompt<I> {
435
449
  * @param name (optional) The name of the user. Only accepted if role is `user`.
436
450
  * @return instance of ChatPrompt.
437
451
  */
438
- addToPrompt(content: string, role: Extract<IChatMessageRole, "assistant">, name?: undefined): ChatPrompt<I>;
452
+ addToPrompt(content: string, role: Extract<IChatMessageRole, "assistant" | "model">, name?: undefined): ChatPrompt<I>;
439
453
  addToPrompt(content: string, role: Extract<IChatMessageRole, "system">, name?: undefined): ChatPrompt<I>;
440
454
  addToPrompt(content: string, role: Extract<IChatMessageRole, "user">, name?: string): ChatPrompt<I>;
441
455
  addToPrompt(content: string, role: Extract<IChatMessageRole, "function">, name: string): ChatPrompt<I>;
@@ -458,7 +472,7 @@ declare class ChatPrompt<I extends Record<string, any>> extends BasePrompt<I> {
458
472
  * @param content The message content.
459
473
  * @return ChatPrompt so it can be chained.
460
474
  */
461
- addFunctionMessage(content: string, name: string): ChatPrompt<I>;
475
+ addFunctionMessage(content: string, name: string, id?: string): ChatPrompt<I>;
462
476
  /**
463
477
  * addFunctionCallMessage Helper to add an assistant message to the prompt.
464
478
  * @param content The message content.
@@ -467,6 +481,7 @@ declare class ChatPrompt<I extends Record<string, any>> extends BasePrompt<I> {
467
481
  addFunctionCallMessage(function_call?: {
468
482
  name: string;
469
483
  arguments: string;
484
+ id?: string;
470
485
  }): this;
471
486
  /**
472
487
  * addFromHistory Adds multiple messages at one time.
@@ -657,13 +672,27 @@ declare class Dialogue extends BaseStateItem<IChatMessages> {
657
672
  name: string;
658
673
  constructor(name: string);
659
674
  setUserMessage(content: string | IChatMessageContentDetailed[], name?: string): this;
660
- setAssistantMessage(content: string): this;
675
+ setAssistantMessage(content: string | OutputResultsText): this;
661
676
  setSystemMessage(content: string): this;
662
- setFunctionMessage(content: string, name: string): this;
677
+ setToolMessage(content: string, name: string, id?: string): void;
678
+ setFunctionMessage(content: string, name: string, id?: string): this;
679
+ /**
680
+ * Set
681
+ */
682
+ setToolCallMessage(input: {
683
+ name: string;
684
+ arguments: string;
685
+ id?: string;
686
+ }): void;
663
687
  setFunctionCallMessage(input: {
688
+ name: string;
689
+ arguments: string;
690
+ id?: string;
691
+ } | {
664
692
  function_call: {
665
693
  name: string;
666
694
  arguments: string;
695
+ id?: string;
667
696
  };
668
697
  }): this;
669
698
  setMessageTurn(userMessage: string, assistantMessage: string, systemMessage?: string): this;
@@ -674,6 +703,13 @@ declare class Dialogue extends BaseStateItem<IChatMessages> {
674
703
  name: string;
675
704
  value: IChatMessage[];
676
705
  };
706
+ /**
707
+ * Add LLM output to dialogue history in the order it was returned
708
+ *
709
+ * @param output - The LLM output result from llm.call()
710
+ * @returns this for chaining
711
+ */
712
+ addFromOutput(output: OutputResult | BaseLlCall): this;
677
713
  }
678
714
 
679
715
  declare abstract class BaseState {
@@ -730,14 +766,19 @@ declare class LlmExecutor<Llm extends BaseLlm<any>, Prompt extends BasePrompt<Re
730
766
  /**
731
767
  * Core Executor With LLM
732
768
  */
733
- declare class LlmExecutorWithFunctions<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState> extends LlmExecutor<Llm, Prompt, Parser, State> {
769
+ 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> {
734
770
  constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>);
735
- execute<T extends GenericFunctionCall>(_input: PromptInput<Prompt>, _options: LlmExecutorWithFunctionsOptions<T>): Promise<ParserOutput<Parser>>;
771
+ execute<T extends GenericFunctionCall>(_input: PromptInput<Prompt>, _options: LlmExecutorWithFunctionsOptions<T>): Promise<OutputResultContent[] | ParserOutput<Parser>>;
736
772
  }
737
773
  /**
738
774
  * @deprecated Use `LlmExecutorWithFunctions` instead.
739
775
  */
740
- declare class LlmExecutorOpenAiFunctions<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState> extends LlmExecutorWithFunctions<Llm, Prompt, Parser, State> {
776
+ 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> {
777
+ constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>);
778
+ execute<T extends GenericFunctionCall>(_input: PromptInput<Prompt>, _options: LlmExecutorWithFunctionsOptions<T>): Promise<ParserOutput<Parser> | {
779
+ name: string;
780
+ arguments: any;
781
+ }>;
741
782
  }
742
783
 
743
784
  /**
@@ -848,6 +889,9 @@ interface BaseParserOptionsWithSchema<S extends JSONSchema | undefined = undefin
848
889
  validateSchema?: boolean;
849
890
  }
850
891
 
892
+ /**
893
+ * Internal Formats
894
+ */
851
895
  interface OutputResultsBase {
852
896
  type: "text" | "function_use";
853
897
  text?: string;
@@ -860,6 +904,7 @@ interface OutputResultsFunction extends OutputResultsBase {
860
904
  type: "function_use";
861
905
  name: string;
862
906
  input: Record<string, any>;
907
+ functionId: string;
863
908
  }
864
909
  type OutputResultContent = OutputResultsText | OutputResultsFunction;
865
910
  interface OutputResult {
@@ -1241,6 +1286,35 @@ declare namespace index {
1241
1286
  export { 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_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 };
1242
1287
  }
1243
1288
 
1289
+ declare function isOutputResult(obj: any): obj is OutputResult;
1290
+ declare function isOutputResultContentText(obj: any): obj is OutputResultsText;
1291
+ /**
1292
+ * Does a llm response have a tool/function call?
1293
+ */
1294
+ declare function isFunctionCall(result: any): result is OutputResultsFunction;
1295
+ declare function isToolCall(result: any): result is OutputResultsFunction;
1296
+ /**
1297
+ * Is it a tool/function Call
1298
+ */
1299
+ declare function hasFunctionCall(results: any): boolean;
1300
+ declare function hasToolCall(results: any): boolean;
1301
+ declare function isUserMessage(message: IChatMessage): message is IChatUserMessage;
1302
+ declare function isAssistantMessage(message: IChatMessage): message is IChatAssistantMessage;
1303
+ declare function isSystemMessage(message: IChatMessage): message is IChatSystemMessage;
1304
+
1305
+ declare const guards_hasFunctionCall: typeof hasFunctionCall;
1306
+ declare const guards_hasToolCall: typeof hasToolCall;
1307
+ declare const guards_isAssistantMessage: typeof isAssistantMessage;
1308
+ declare const guards_isFunctionCall: typeof isFunctionCall;
1309
+ declare const guards_isOutputResult: typeof isOutputResult;
1310
+ declare const guards_isOutputResultContentText: typeof isOutputResultContentText;
1311
+ declare const guards_isSystemMessage: typeof isSystemMessage;
1312
+ declare const guards_isToolCall: typeof isToolCall;
1313
+ declare const guards_isUserMessage: typeof isUserMessage;
1314
+ declare namespace guards {
1315
+ 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 };
1316
+ }
1317
+
1244
1318
  declare const configs: {
1245
1319
  "deepseek.chat.v1": Config<keyof AllLlm>;
1246
1320
  "deepseek.chat": Config<keyof AllLlm>;
@@ -1270,11 +1344,7 @@ declare const configs: {
1270
1344
  };
1271
1345
 
1272
1346
  declare function useLlm<T extends keyof typeof configs>(provider: T, options?: AllUseLlmOptions[T]["input"]): {
1273
- call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions) => Promise<{
1274
- getResultContent: (index?: number) => OutputResultContent[];
1275
- getResultText: () => string;
1276
- getResult: () => OutputResult;
1277
- }>;
1347
+ call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions) => Promise<BaseLlCall>;
1278
1348
  getTraceId: () => string | null;
1279
1349
  withTraceId: (id: string) => void;
1280
1350
  getMetadata: () => {
@@ -1308,4 +1378,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
1308
1378
  };
1309
1379
  };
1310
1380
 
1311
- 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, registerHelpers, registerPartials, useExecutors, useLlm, index as utils };
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 };
package/dist/index.d.ts CHANGED
@@ -31,21 +31,23 @@ interface IChatUserMessage extends IChatMessageBase {
31
31
  name?: string;
32
32
  }
33
33
  interface IChatFunctionMessage extends IChatMessageBase {
34
+ id?: string;
34
35
  role: Extract<IChatMessageRole, "function">;
35
36
  content: string;
36
37
  name: string;
37
38
  }
38
39
  interface IChatAssistantMessage extends IChatMessageBase {
39
- role: Extract<IChatMessageRole, "assistant">;
40
+ role: Extract<IChatMessageRole, "assistant" | "model">;
40
41
  content: string;
41
42
  function_call?: undefined;
42
43
  }
43
- interface IChatAssistantFunctionCallMessage extends IChatMessageBase {
44
- role: Extract<IChatMessageRole, "assistant">;
44
+ interface IChatFunctionCallMessage extends IChatMessageBase {
45
+ role: Extract<IChatMessageRole, "function_call">;
45
46
  content: null;
46
- function_call?: {
47
+ function_call: {
47
48
  name: string;
48
49
  arguments: string;
50
+ id?: string;
49
51
  };
50
52
  }
51
53
  interface IChatSystemMessage extends IChatMessageBase {
@@ -57,8 +59,8 @@ interface IChatMessagesPlaceholder {
57
59
  content: string;
58
60
  }
59
61
  type IPromptMessages = (IChatSystemMessage | IChatMessagesPlaceholder)[];
60
- type IPromptChatMessages = (IChatUserMessage | IChatAssistantMessage | IChatAssistantFunctionCallMessage | IChatSystemMessage | IChatMessagesPlaceholder | IChatFunctionMessage)[];
61
- type IChatMessage = IChatUserMessage | IChatAssistantMessage | IChatAssistantFunctionCallMessage | IChatSystemMessage | IChatFunctionMessage;
62
+ type IPromptChatMessages = (IChatUserMessage | IChatAssistantMessage | IChatFunctionCallMessage | IChatSystemMessage | IChatMessagesPlaceholder | IChatFunctionMessage)[];
63
+ type IChatMessage = IChatUserMessage | IChatAssistantMessage | IChatFunctionCallMessage | IChatSystemMessage | IChatFunctionMessage;
62
64
  type IChatMessages = IChatMessage[];
63
65
 
64
66
  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}`;
@@ -66,6 +68,7 @@ type OpenAIConversationModelName = "davinci" | "text-curie-001" | "text-babbage-
66
68
  type OpenAIEmbeddingModelName = "text-embedding-ada-002";
67
69
  type OpenAIModelName = OpenAIChatModelName | OpenAIConversationModelName | OpenAIEmbeddingModelName;
68
70
 
71
+ type ParserInput = string | OutputResult;
69
72
  /**
70
73
  * BaseParser is an abstract class for parsing text and enforcing JSON schema on the parsed data.
71
74
  */
@@ -86,7 +89,7 @@ declare abstract class BaseParser<T = any> {
86
89
  * @param [attributes] - Optional attributes to use during parsing.
87
90
  * @returns The parsed data.
88
91
  */
89
- abstract parse(text: string | OutputResultContent[], attributes?: Record<string, any>): T;
92
+ abstract parse(text: ParserInput, attributes?: Record<string, any>): T;
90
93
  }
91
94
  declare abstract class BaseParserWithJson<S extends JSONSchema | undefined = undefined, T = S extends JSONSchema ? FromSchema<S> : Record<string, any>> extends BaseParser<T> {
92
95
  schema: S;
@@ -103,7 +106,7 @@ interface StringParserOptions extends BaseParserOptions {
103
106
  }
104
107
  declare class StringParser extends BaseParser<string> {
105
108
  constructor(options?: StringParserOptions);
106
- parse(text: string | OutputResultContent[], _options?: Record<string, any>): string;
109
+ parse(text: string | OutputResult, _options?: Record<string, any>): string;
107
110
  }
108
111
 
109
112
  interface BooleanParserOptions extends BaseParserOptions {
@@ -301,16 +304,27 @@ declare function createParser<T extends Extract<CreateParserType, "json">, S ext
301
304
  declare function createParser<T extends CreateParserType, S extends JSONSchema | undefined = undefined>(type: T, options?: BaseParserOptionsWithSchema<S> | BaseParserOptions): JsonParser<S> | ListToJsonParser<S> | StringParser | NumberParser | BooleanParser | ListToArrayParser | ListToKeyValueParser | ReplaceStringTemplateParser | MarkdownCodeBlockParser | MarkdownCodeBlocksParser | StringExtractParser;
302
305
  declare function createCustomParser<O>(name: string, parserFn: (text: string, inputValues: ExecutorContext<any, any>) => O): CustomParser<ReturnType<typeof parserFn>>;
303
306
 
307
+ declare class LlmFunctionParser<T extends BaseParser<any>> extends BaseParser<ParserOutput<T> | OutputResultContent[]> {
308
+ parser: T;
309
+ constructor(options: LlmNativeFunctionParserOptions<T>);
310
+ parse(text: OutputResult, _options?: Record<string, any>): OutputResultContent[] | ParserOutput<T>;
311
+ }
312
+ interface LlmNativeFunctionParserOptions<T extends BaseParser<any>> extends BaseParserOptions {
313
+ parser: T;
314
+ }
304
315
  interface LlmNativeFunctionParserOptions<T extends BaseParser<any>> extends BaseParserOptions {
305
316
  parser: T;
306
317
  }
318
+ /**
319
+ * @deprecated Use `LlmFunctionParser` instead.
320
+ */
307
321
  declare class LlmNativeFunctionParser<T extends BaseParser<any>> extends BaseParser<ParserOutput<T> | {
308
322
  name: any;
309
323
  arguments: any;
310
324
  }> {
311
325
  parser: T;
312
326
  constructor(options: LlmNativeFunctionParserOptions<T>);
313
- parse(text: OutputResultContent[], _options?: Record<string, any>): ParserOutput<T> | {
327
+ parse(text: OutputResult, _options?: Record<string, any>): ParserOutput<T> | {
314
328
  name: string;
315
329
  arguments: any;
316
330
  };
@@ -435,7 +449,7 @@ declare class ChatPrompt<I extends Record<string, any>> extends BasePrompt<I> {
435
449
  * @param name (optional) The name of the user. Only accepted if role is `user`.
436
450
  * @return instance of ChatPrompt.
437
451
  */
438
- addToPrompt(content: string, role: Extract<IChatMessageRole, "assistant">, name?: undefined): ChatPrompt<I>;
452
+ addToPrompt(content: string, role: Extract<IChatMessageRole, "assistant" | "model">, name?: undefined): ChatPrompt<I>;
439
453
  addToPrompt(content: string, role: Extract<IChatMessageRole, "system">, name?: undefined): ChatPrompt<I>;
440
454
  addToPrompt(content: string, role: Extract<IChatMessageRole, "user">, name?: string): ChatPrompt<I>;
441
455
  addToPrompt(content: string, role: Extract<IChatMessageRole, "function">, name: string): ChatPrompt<I>;
@@ -458,7 +472,7 @@ declare class ChatPrompt<I extends Record<string, any>> extends BasePrompt<I> {
458
472
  * @param content The message content.
459
473
  * @return ChatPrompt so it can be chained.
460
474
  */
461
- addFunctionMessage(content: string, name: string): ChatPrompt<I>;
475
+ addFunctionMessage(content: string, name: string, id?: string): ChatPrompt<I>;
462
476
  /**
463
477
  * addFunctionCallMessage Helper to add an assistant message to the prompt.
464
478
  * @param content The message content.
@@ -467,6 +481,7 @@ declare class ChatPrompt<I extends Record<string, any>> extends BasePrompt<I> {
467
481
  addFunctionCallMessage(function_call?: {
468
482
  name: string;
469
483
  arguments: string;
484
+ id?: string;
470
485
  }): this;
471
486
  /**
472
487
  * addFromHistory Adds multiple messages at one time.
@@ -657,13 +672,27 @@ declare class Dialogue extends BaseStateItem<IChatMessages> {
657
672
  name: string;
658
673
  constructor(name: string);
659
674
  setUserMessage(content: string | IChatMessageContentDetailed[], name?: string): this;
660
- setAssistantMessage(content: string): this;
675
+ setAssistantMessage(content: string | OutputResultsText): this;
661
676
  setSystemMessage(content: string): this;
662
- setFunctionMessage(content: string, name: string): this;
677
+ setToolMessage(content: string, name: string, id?: string): void;
678
+ setFunctionMessage(content: string, name: string, id?: string): this;
679
+ /**
680
+ * Set
681
+ */
682
+ setToolCallMessage(input: {
683
+ name: string;
684
+ arguments: string;
685
+ id?: string;
686
+ }): void;
663
687
  setFunctionCallMessage(input: {
688
+ name: string;
689
+ arguments: string;
690
+ id?: string;
691
+ } | {
664
692
  function_call: {
665
693
  name: string;
666
694
  arguments: string;
695
+ id?: string;
667
696
  };
668
697
  }): this;
669
698
  setMessageTurn(userMessage: string, assistantMessage: string, systemMessage?: string): this;
@@ -674,6 +703,13 @@ declare class Dialogue extends BaseStateItem<IChatMessages> {
674
703
  name: string;
675
704
  value: IChatMessage[];
676
705
  };
706
+ /**
707
+ * Add LLM output to dialogue history in the order it was returned
708
+ *
709
+ * @param output - The LLM output result from llm.call()
710
+ * @returns this for chaining
711
+ */
712
+ addFromOutput(output: OutputResult | BaseLlCall): this;
677
713
  }
678
714
 
679
715
  declare abstract class BaseState {
@@ -730,14 +766,19 @@ declare class LlmExecutor<Llm extends BaseLlm<any>, Prompt extends BasePrompt<Re
730
766
  /**
731
767
  * Core Executor With LLM
732
768
  */
733
- declare class LlmExecutorWithFunctions<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState> extends LlmExecutor<Llm, Prompt, Parser, State> {
769
+ 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> {
734
770
  constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>);
735
- execute<T extends GenericFunctionCall>(_input: PromptInput<Prompt>, _options: LlmExecutorWithFunctionsOptions<T>): Promise<ParserOutput<Parser>>;
771
+ execute<T extends GenericFunctionCall>(_input: PromptInput<Prompt>, _options: LlmExecutorWithFunctionsOptions<T>): Promise<OutputResultContent[] | ParserOutput<Parser>>;
736
772
  }
737
773
  /**
738
774
  * @deprecated Use `LlmExecutorWithFunctions` instead.
739
775
  */
740
- declare class LlmExecutorOpenAiFunctions<Llm extends BaseLlm, Prompt extends BasePrompt<Record<string, any>>, Parser extends BaseParser, State extends BaseState> extends LlmExecutorWithFunctions<Llm, Prompt, Parser, State> {
776
+ 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> {
777
+ constructor(llmConfiguration: ExecutorWithLlmOptions<Llm, Prompt, Parser, State>, options?: CoreExecutorExecuteOptions<LlmExecutorHooks>);
778
+ execute<T extends GenericFunctionCall>(_input: PromptInput<Prompt>, _options: LlmExecutorWithFunctionsOptions<T>): Promise<ParserOutput<Parser> | {
779
+ name: string;
780
+ arguments: any;
781
+ }>;
741
782
  }
742
783
 
743
784
  /**
@@ -848,6 +889,9 @@ interface BaseParserOptionsWithSchema<S extends JSONSchema | undefined = undefin
848
889
  validateSchema?: boolean;
849
890
  }
850
891
 
892
+ /**
893
+ * Internal Formats
894
+ */
851
895
  interface OutputResultsBase {
852
896
  type: "text" | "function_use";
853
897
  text?: string;
@@ -860,6 +904,7 @@ interface OutputResultsFunction extends OutputResultsBase {
860
904
  type: "function_use";
861
905
  name: string;
862
906
  input: Record<string, any>;
907
+ functionId: string;
863
908
  }
864
909
  type OutputResultContent = OutputResultsText | OutputResultsFunction;
865
910
  interface OutputResult {
@@ -1241,6 +1286,35 @@ declare namespace index {
1241
1286
  export { 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_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 };
1242
1287
  }
1243
1288
 
1289
+ declare function isOutputResult(obj: any): obj is OutputResult;
1290
+ declare function isOutputResultContentText(obj: any): obj is OutputResultsText;
1291
+ /**
1292
+ * Does a llm response have a tool/function call?
1293
+ */
1294
+ declare function isFunctionCall(result: any): result is OutputResultsFunction;
1295
+ declare function isToolCall(result: any): result is OutputResultsFunction;
1296
+ /**
1297
+ * Is it a tool/function Call
1298
+ */
1299
+ declare function hasFunctionCall(results: any): boolean;
1300
+ declare function hasToolCall(results: any): boolean;
1301
+ declare function isUserMessage(message: IChatMessage): message is IChatUserMessage;
1302
+ declare function isAssistantMessage(message: IChatMessage): message is IChatAssistantMessage;
1303
+ declare function isSystemMessage(message: IChatMessage): message is IChatSystemMessage;
1304
+
1305
+ declare const guards_hasFunctionCall: typeof hasFunctionCall;
1306
+ declare const guards_hasToolCall: typeof hasToolCall;
1307
+ declare const guards_isAssistantMessage: typeof isAssistantMessage;
1308
+ declare const guards_isFunctionCall: typeof isFunctionCall;
1309
+ declare const guards_isOutputResult: typeof isOutputResult;
1310
+ declare const guards_isOutputResultContentText: typeof isOutputResultContentText;
1311
+ declare const guards_isSystemMessage: typeof isSystemMessage;
1312
+ declare const guards_isToolCall: typeof isToolCall;
1313
+ declare const guards_isUserMessage: typeof isUserMessage;
1314
+ declare namespace guards {
1315
+ 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 };
1316
+ }
1317
+
1244
1318
  declare const configs: {
1245
1319
  "deepseek.chat.v1": Config<keyof AllLlm>;
1246
1320
  "deepseek.chat": Config<keyof AllLlm>;
@@ -1270,11 +1344,7 @@ declare const configs: {
1270
1344
  };
1271
1345
 
1272
1346
  declare function useLlm<T extends keyof typeof configs>(provider: T, options?: AllUseLlmOptions[T]["input"]): {
1273
- call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions) => Promise<{
1274
- getResultContent: (index?: number) => OutputResultContent[];
1275
- getResultText: () => string;
1276
- getResult: () => OutputResult;
1277
- }>;
1347
+ call: (messages: string | IChatMessages, options?: LlmExecutorWithFunctionsOptions) => Promise<BaseLlCall>;
1278
1348
  getTraceId: () => string | null;
1279
1349
  withTraceId: (id: string) => void;
1280
1350
  getMetadata: () => {
@@ -1308,4 +1378,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
1308
1378
  };
1309
1379
  };
1310
1380
 
1311
- 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, registerHelpers, registerPartials, useExecutors, useLlm, index as utils };
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 };