modelfusion 0.71.0 → 0.72.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.
Files changed (140) hide show
  1. package/README.md +57 -45
  2. package/core/FunctionEvent.d.ts +5 -5
  3. package/guard/guard.cjs +5 -4
  4. package/guard/guard.d.ts +1 -1
  5. package/guard/guard.js +5 -4
  6. package/model-function/ModelCallEvent.d.ts +2 -2
  7. package/model-function/generate-structure/StructureGenerationEvent.d.ts +2 -2
  8. package/model-function/generate-structure/StructureParseError.cjs +10 -0
  9. package/model-function/generate-structure/StructureParseError.d.ts +8 -0
  10. package/model-function/generate-structure/StructureParseError.js +10 -0
  11. package/model-function/generate-structure/index.cjs +0 -3
  12. package/model-function/generate-structure/index.d.ts +0 -3
  13. package/model-function/generate-structure/index.js +0 -3
  14. package/model-function/index.cjs +0 -1
  15. package/model-function/index.d.ts +0 -1
  16. package/model-function/index.js +0 -1
  17. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
  18. package/model-provider/openai/chat/OpenAIChatMessage.cjs +16 -25
  19. package/model-provider/openai/chat/OpenAIChatMessage.d.ts +10 -28
  20. package/model-provider/openai/chat/OpenAIChatMessage.js +16 -25
  21. package/model-provider/openai/chat/OpenAIChatModel.cjs +2 -48
  22. package/model-provider/openai/chat/OpenAIChatModel.d.ts +15 -107
  23. package/model-provider/openai/chat/OpenAIChatModel.js +2 -48
  24. package/package.json +1 -1
  25. package/tool/Tool.cjs +5 -16
  26. package/tool/Tool.d.ts +9 -14
  27. package/tool/Tool.js +5 -16
  28. package/tool/ToolCall.d.ts +15 -0
  29. package/tool/ToolCallArgumentsValidationError.cjs +49 -0
  30. package/tool/ToolCallArgumentsValidationError.d.ts +23 -0
  31. package/tool/ToolCallArgumentsValidationError.js +45 -0
  32. package/tool/ToolCallError.cjs +34 -0
  33. package/tool/ToolCallError.d.ts +17 -0
  34. package/tool/ToolCallError.js +30 -0
  35. package/{model-function/generate-tool-call → tool}/ToolCallGenerationError.cjs +4 -4
  36. package/{model-function/generate-tool-call → tool}/ToolCallGenerationError.d.ts +1 -1
  37. package/{model-function/generate-tool-call → tool}/ToolCallGenerationError.js +2 -2
  38. package/{model-function/generate-tool-call/ToolCallParametersValidationError.cjs → tool/ToolCallParseError.cjs} +13 -13
  39. package/{model-function/generate-tool-call/ToolCallParametersValidationError.d.ts → tool/ToolCallParseError.d.ts} +6 -6
  40. package/{model-function/generate-tool-call/ToolCallParametersValidationError.js → tool/ToolCallParseError.js} +11 -11
  41. package/tool/ToolCallResult.d.ts +13 -0
  42. package/{model-function/generate-tool-call → tool}/ToolDefinition.d.ts +2 -2
  43. package/tool/ToolExecutionError.cjs +5 -4
  44. package/tool/ToolExecutionError.d.ts +4 -4
  45. package/tool/ToolExecutionError.js +5 -4
  46. package/tool/WebSearchTool.cjs +4 -4
  47. package/tool/WebSearchTool.d.ts +2 -2
  48. package/tool/WebSearchTool.js +4 -4
  49. package/tool/{ExecuteToolEvent.d.ts → execute-tool/ExecuteToolEvent.d.ts} +1 -1
  50. package/tool/{executeTool.cjs → execute-tool/executeTool.cjs} +15 -15
  51. package/tool/{executeTool.d.ts → execute-tool/executeTool.d.ts} +6 -6
  52. package/tool/{executeTool.js → execute-tool/executeTool.js} +15 -15
  53. package/tool/execute-tool/index.cjs +18 -0
  54. package/tool/execute-tool/index.d.ts +2 -0
  55. package/tool/execute-tool/index.js +2 -0
  56. package/tool/execute-tool/safeExecuteToolCall.cjs +34 -0
  57. package/tool/execute-tool/safeExecuteToolCall.d.ts +5 -0
  58. package/tool/execute-tool/safeExecuteToolCall.js +30 -0
  59. package/tool/generate-tool-call/TextGenerationToolCallModel.cjs +59 -0
  60. package/tool/generate-tool-call/TextGenerationToolCallModel.d.ts +35 -0
  61. package/tool/generate-tool-call/TextGenerationToolCallModel.js +55 -0
  62. package/{model-function → tool}/generate-tool-call/ToolCallGenerationEvent.d.ts +1 -1
  63. package/{model-function → tool}/generate-tool-call/ToolCallGenerationModel.d.ts +3 -3
  64. package/{model-function → tool}/generate-tool-call/generateToolCall.cjs +11 -11
  65. package/{model-function → tool}/generate-tool-call/generateToolCall.d.ts +3 -3
  66. package/{model-function → tool}/generate-tool-call/generateToolCall.js +11 -11
  67. package/tool/generate-tool-call/index.cjs +20 -0
  68. package/tool/generate-tool-call/index.d.ts +4 -0
  69. package/tool/generate-tool-call/index.js +4 -0
  70. package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationEvent.d.ts +1 -1
  71. package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationModel.d.ts +3 -3
  72. package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/generateToolCallsOrText.cjs +8 -8
  73. package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/generateToolCallsOrText.d.ts +3 -3
  74. package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/generateToolCallsOrText.js +8 -8
  75. package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/index.cjs +0 -7
  76. package/tool/generate-tool-calls-or-text/index.d.ts +3 -0
  77. package/tool/generate-tool-calls-or-text/index.js +3 -0
  78. package/tool/index.cjs +12 -7
  79. package/tool/index.d.ts +12 -7
  80. package/tool/index.js +12 -7
  81. package/tool/{UseToolEvent.d.ts → use-tool/UseToolEvent.d.ts} +1 -1
  82. package/tool/use-tool/index.cjs +18 -0
  83. package/tool/use-tool/index.d.ts +2 -0
  84. package/tool/use-tool/index.js +2 -0
  85. package/tool/use-tool/useTool.cjs +30 -0
  86. package/tool/use-tool/useTool.d.ts +16 -0
  87. package/tool/use-tool/useTool.js +26 -0
  88. package/tool/use-tools-or-generate-text/UseToolsOrGenerateTextEvent.d.ts +7 -0
  89. package/tool/use-tools-or-generate-text/index.cjs +18 -0
  90. package/tool/use-tools-or-generate-text/index.d.ts +2 -0
  91. package/tool/use-tools-or-generate-text/index.js +2 -0
  92. package/tool/use-tools-or-generate-text/useToolsOrGenerateText.cjs +48 -0
  93. package/tool/use-tools-or-generate-text/useToolsOrGenerateText.d.ts +18 -0
  94. package/tool/use-tools-or-generate-text/useToolsOrGenerateText.js +44 -0
  95. package/util/getErrorMessage.cjs +3 -0
  96. package/util/getErrorMessage.d.ts +1 -1
  97. package/util/getErrorMessage.js +3 -0
  98. package/model-function/generate-structure/NoSuchStructureError.cjs +0 -17
  99. package/model-function/generate-structure/NoSuchStructureError.d.ts +0 -4
  100. package/model-function/generate-structure/NoSuchStructureError.js +0 -13
  101. package/model-function/generate-structure/StructureOrTextGenerationModel.d.ts +0 -26
  102. package/model-function/generate-structure/generateStructureOrText.cjs +0 -54
  103. package/model-function/generate-structure/generateStructureOrText.d.ts +0 -97
  104. package/model-function/generate-structure/generateStructureOrText.js +0 -50
  105. package/model-function/generate-tool-call/ToolCall.d.ts +0 -5
  106. package/model-function/generate-tool-call/index.d.ts +0 -10
  107. package/model-function/generate-tool-call/index.js +0 -10
  108. package/tool/NoSuchToolError.cjs +0 -25
  109. package/tool/NoSuchToolError.d.ts +0 -10
  110. package/tool/NoSuchToolError.js +0 -21
  111. package/tool/UseToolOrGenerateTextEvent.d.ts +0 -7
  112. package/tool/useTool.cjs +0 -40
  113. package/tool/useTool.d.ts +0 -15
  114. package/tool/useTool.js +0 -36
  115. package/tool/useToolOrGenerateText.cjs +0 -50
  116. package/tool/useToolOrGenerateText.d.ts +0 -23
  117. package/tool/useToolOrGenerateText.js +0 -46
  118. /package/{model-function/generate-tool-call → tool}/NoSuchToolDefinitionError.cjs +0 -0
  119. /package/{model-function/generate-tool-call → tool}/NoSuchToolDefinitionError.d.ts +0 -0
  120. /package/{model-function/generate-tool-call → tool}/NoSuchToolDefinitionError.js +0 -0
  121. /package/{model-function/generate-tool-call → tool}/ToolCall.cjs +0 -0
  122. /package/{model-function/generate-tool-call → tool}/ToolCall.js +0 -0
  123. /package/{model-function/generate-structure/StructureOrTextGenerationModel.cjs → tool/ToolCallResult.cjs} +0 -0
  124. /package/{model-function/generate-structure/StructureOrTextGenerationModel.js → tool/ToolCallResult.js} +0 -0
  125. /package/{model-function/generate-tool-call → tool}/ToolDefinition.cjs +0 -0
  126. /package/{model-function/generate-tool-call → tool}/ToolDefinition.js +0 -0
  127. /package/tool/{ExecuteToolEvent.cjs → execute-tool/ExecuteToolEvent.cjs} +0 -0
  128. /package/tool/{ExecuteToolEvent.js → execute-tool/ExecuteToolEvent.js} +0 -0
  129. /package/{model-function → tool}/generate-tool-call/ToolCallGenerationEvent.cjs +0 -0
  130. /package/{model-function → tool}/generate-tool-call/ToolCallGenerationEvent.js +0 -0
  131. /package/{model-function → tool}/generate-tool-call/ToolCallGenerationModel.cjs +0 -0
  132. /package/{model-function → tool}/generate-tool-call/ToolCallGenerationModel.js +0 -0
  133. /package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationEvent.cjs +0 -0
  134. /package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationEvent.js +0 -0
  135. /package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationModel.cjs +0 -0
  136. /package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationModel.js +0 -0
  137. /package/tool/{UseToolEvent.cjs → use-tool/UseToolEvent.cjs} +0 -0
  138. /package/tool/{UseToolEvent.js → use-tool/UseToolEvent.js} +0 -0
  139. /package/tool/{UseToolOrGenerateTextEvent.cjs → use-tools-or-generate-text/UseToolsOrGenerateTextEvent.cjs} +0 -0
  140. /package/tool/{UseToolOrGenerateTextEvent.js → use-tools-or-generate-text/UseToolsOrGenerateTextEvent.js} +0 -0
package/tool/useTool.cjs DELETED
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useTool = void 0;
4
- const executeFunctionCall_js_1 = require("../core/executeFunctionCall.cjs");
5
- const generateStructure_js_1 = require("../model-function/generate-structure/generateStructure.cjs");
6
- const executeTool_js_1 = require("./executeTool.cjs");
7
- /**
8
- * `useTool` uses `generateStructure` to generate parameters for a tool and then executes the tool with the parameters.
9
- *
10
- * @returns The result contains the name of the tool (`tool` property),
11
- * the parameters (`parameters` property, typed),
12
- * and the result of the tool execution (`result` property, typed).
13
- */
14
- async function useTool(model, tool, prompt, options) {
15
- // Note: PROMPT must not be a function.
16
- const expandedPrompt = typeof prompt === "function"
17
- ? prompt(tool)
18
- : prompt;
19
- return (0, executeFunctionCall_js_1.executeFunctionCall)({
20
- options,
21
- input: expandedPrompt,
22
- functionType: "use-tool",
23
- execute: async (options) => {
24
- const { value } = await (0, generateStructure_js_1.generateStructure)(model, {
25
- name: tool.name,
26
- description: tool.description,
27
- schema: tool.inputSchema,
28
- }, expandedPrompt, {
29
- ...options,
30
- returnType: "full",
31
- });
32
- return {
33
- tool: tool.name,
34
- parameters: value,
35
- result: await (0, executeTool_js_1.executeTool)(tool, value, options),
36
- };
37
- },
38
- });
39
- }
40
- exports.useTool = useTool;
package/tool/useTool.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { FunctionOptions } from "../core/FunctionOptions.js";
2
- import { StructureGenerationModel, StructureGenerationModelSettings } from "../model-function/generate-structure/StructureGenerationModel.js";
3
- import { Tool } from "./Tool.js";
4
- /**
5
- * `useTool` uses `generateStructure` to generate parameters for a tool and then executes the tool with the parameters.
6
- *
7
- * @returns The result contains the name of the tool (`tool` property),
8
- * the parameters (`parameters` property, typed),
9
- * and the result of the tool execution (`result` property, typed).
10
- */
11
- export declare function useTool<PROMPT, TOOL extends Tool<any, any, any>>(model: StructureGenerationModel<PROMPT, StructureGenerationModelSettings>, tool: TOOL, prompt: PROMPT | ((tool: TOOL) => PROMPT), options?: FunctionOptions): Promise<{
12
- tool: TOOL["name"];
13
- parameters: TOOL["inputSchema"];
14
- result: Awaited<ReturnType<TOOL["execute"]>>;
15
- }>;
package/tool/useTool.js DELETED
@@ -1,36 +0,0 @@
1
- import { executeFunctionCall } from "../core/executeFunctionCall.js";
2
- import { generateStructure } from "../model-function/generate-structure/generateStructure.js";
3
- import { executeTool } from "./executeTool.js";
4
- /**
5
- * `useTool` uses `generateStructure` to generate parameters for a tool and then executes the tool with the parameters.
6
- *
7
- * @returns The result contains the name of the tool (`tool` property),
8
- * the parameters (`parameters` property, typed),
9
- * and the result of the tool execution (`result` property, typed).
10
- */
11
- export async function useTool(model, tool, prompt, options) {
12
- // Note: PROMPT must not be a function.
13
- const expandedPrompt = typeof prompt === "function"
14
- ? prompt(tool)
15
- : prompt;
16
- return executeFunctionCall({
17
- options,
18
- input: expandedPrompt,
19
- functionType: "use-tool",
20
- execute: async (options) => {
21
- const { value } = await generateStructure(model, {
22
- name: tool.name,
23
- description: tool.description,
24
- schema: tool.inputSchema,
25
- }, expandedPrompt, {
26
- ...options,
27
- returnType: "full",
28
- });
29
- return {
30
- tool: tool.name,
31
- parameters: value,
32
- result: await executeTool(tool, value, options),
33
- };
34
- },
35
- });
36
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useToolOrGenerateText = void 0;
4
- const executeFunctionCall_js_1 = require("../core/executeFunctionCall.cjs");
5
- const generateStructureOrText_js_1 = require("../model-function/generate-structure/generateStructureOrText.cjs");
6
- const NoSuchToolError_js_1 = require("./NoSuchToolError.cjs");
7
- const executeTool_js_1 = require("./executeTool.cjs");
8
- async function useToolOrGenerateText(model, tools, prompt, options) {
9
- // Note: PROMPT must not be a function.
10
- const expandedPrompt = typeof prompt === "function"
11
- ? prompt(tools)
12
- : prompt;
13
- return (0, executeFunctionCall_js_1.executeFunctionCall)({
14
- options,
15
- input: expandedPrompt,
16
- functionType: "use-tool-or-generate-text",
17
- execute: async (options) => {
18
- const modelResponse = await (0, generateStructureOrText_js_1.generateStructureOrText)(model, tools.map((tool) => ({
19
- name: tool.name,
20
- description: tool.description,
21
- schema: tool.inputSchema,
22
- })), expandedPrompt, {
23
- ...options,
24
- returnType: "structure",
25
- });
26
- const { structure, text } = modelResponse;
27
- if (structure == null) {
28
- return {
29
- tool: null,
30
- parameters: null,
31
- result: null,
32
- text,
33
- };
34
- }
35
- const tool = tools.find((tool) => tool.name === structure);
36
- if (tool == null) {
37
- throw new NoSuchToolError_js_1.NoSuchToolError(structure.toString());
38
- }
39
- const toolParameters = modelResponse.value;
40
- const result = await (0, executeTool_js_1.executeTool)(tool, toolParameters, options);
41
- return {
42
- tool: structure,
43
- result,
44
- parameters: toolParameters,
45
- text: text, // string | null is the expected value here
46
- };
47
- },
48
- });
49
- }
50
- exports.useToolOrGenerateText = useToolOrGenerateText;
@@ -1,23 +0,0 @@
1
- import { FunctionOptions } from "../core/FunctionOptions.js";
2
- import { StructureOrTextGenerationModel, StructureOrTextGenerationModelSettings } from "../model-function/generate-structure/StructureOrTextGenerationModel.js";
3
- import { Tool } from "./Tool.js";
4
- type ToolArray<T extends Tool<any, any, any>[]> = T;
5
- type ToToolMap<T extends ToolArray<Tool<any, any, any>[]>> = {
6
- [K in T[number]["name"]]: Extract<T[number], Tool<K, any, any>>;
7
- };
8
- type ToToolUnion<T> = {
9
- [KEY in keyof T]: T[KEY] extends Tool<any, infer INPUT, infer OUTPUT> ? {
10
- tool: KEY;
11
- parameters: INPUT;
12
- result: OUTPUT;
13
- text: string | null;
14
- } : never;
15
- }[keyof T];
16
- type ToOutputValue<TOOLS extends ToolArray<Tool<any, any, any>[]>> = ToToolUnion<ToToolMap<TOOLS>>;
17
- export declare function useToolOrGenerateText<PROMPT, SETTINGS extends StructureOrTextGenerationModelSettings, TOOLS extends Array<Tool<any, any, any>>>(model: StructureOrTextGenerationModel<PROMPT, SETTINGS>, tools: TOOLS, prompt: PROMPT | ((tools: TOOLS) => PROMPT), options?: FunctionOptions): Promise<{
18
- tool: null;
19
- parameters: null;
20
- result: null;
21
- text: string;
22
- } | ToOutputValue<TOOLS>>;
23
- export {};
@@ -1,46 +0,0 @@
1
- import { executeFunctionCall } from "../core/executeFunctionCall.js";
2
- import { generateStructureOrText } from "../model-function/generate-structure/generateStructureOrText.js";
3
- import { NoSuchToolError } from "./NoSuchToolError.js";
4
- import { executeTool } from "./executeTool.js";
5
- export async function useToolOrGenerateText(model, tools, prompt, options) {
6
- // Note: PROMPT must not be a function.
7
- const expandedPrompt = typeof prompt === "function"
8
- ? prompt(tools)
9
- : prompt;
10
- return executeFunctionCall({
11
- options,
12
- input: expandedPrompt,
13
- functionType: "use-tool-or-generate-text",
14
- execute: async (options) => {
15
- const modelResponse = await generateStructureOrText(model, tools.map((tool) => ({
16
- name: tool.name,
17
- description: tool.description,
18
- schema: tool.inputSchema,
19
- })), expandedPrompt, {
20
- ...options,
21
- returnType: "structure",
22
- });
23
- const { structure, text } = modelResponse;
24
- if (structure == null) {
25
- return {
26
- tool: null,
27
- parameters: null,
28
- result: null,
29
- text,
30
- };
31
- }
32
- const tool = tools.find((tool) => tool.name === structure);
33
- if (tool == null) {
34
- throw new NoSuchToolError(structure.toString());
35
- }
36
- const toolParameters = modelResponse.value;
37
- const result = await executeTool(tool, toolParameters, options);
38
- return {
39
- tool: structure,
40
- result,
41
- parameters: toolParameters,
42
- text: text, // string | null is the expected value here
43
- };
44
- },
45
- });
46
- }