@tanstack/openai-base 0.9.9 → 0.9.11
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/esm/adapters/chat-completions-text.js +844 -962
- package/dist/esm/adapters/chat-completions-text.js.map +1 -1
- package/dist/esm/adapters/chat-completions-tool-converter.js +54 -38
- package/dist/esm/adapters/chat-completions-tool-converter.js.map +1 -1
- package/dist/esm/adapters/responses-text.d.ts +22 -8
- package/dist/esm/adapters/responses-text.js +1193 -1319
- package/dist/esm/adapters/responses-text.js.map +1 -1
- package/dist/esm/adapters/responses-tool-converter.js +50 -34
- package/dist/esm/adapters/responses-tool-converter.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +4 -43
- package/dist/esm/tools/apply-patch-tool.js +20 -13
- package/dist/esm/tools/apply-patch-tool.js.map +1 -1
- package/dist/esm/tools/code-interpreter-tool.js +26 -18
- package/dist/esm/tools/code-interpreter-tool.js.map +1 -1
- package/dist/esm/tools/computer-use-tool.js +26 -19
- package/dist/esm/tools/computer-use-tool.js.map +1 -1
- package/dist/esm/tools/custom-tool.js +23 -21
- package/dist/esm/tools/custom-tool.js.map +1 -1
- package/dist/esm/tools/file-search-tool.js +30 -30
- package/dist/esm/tools/file-search-tool.js.map +1 -1
- package/dist/esm/tools/function-tool.js +44 -31
- package/dist/esm/tools/function-tool.js.map +1 -1
- package/dist/esm/tools/image-generation-tool.js +30 -23
- package/dist/esm/tools/image-generation-tool.js.map +1 -1
- package/dist/esm/tools/local-shell-tool.js +20 -13
- package/dist/esm/tools/local-shell-tool.js.map +1 -1
- package/dist/esm/tools/mcp-tool.js +31 -25
- package/dist/esm/tools/mcp-tool.js.map +1 -1
- package/dist/esm/tools/shell-tool.js +25 -21
- package/dist/esm/tools/shell-tool.js.map +1 -1
- package/dist/esm/tools/tool-converter.js +37 -46
- package/dist/esm/tools/tool-converter.js.map +1 -1
- package/dist/esm/tools/web-search-preview-tool.js +26 -15
- package/dist/esm/tools/web-search-preview-tool.js.map +1 -1
- package/dist/esm/tools/web-search-tool.js +27 -15
- package/dist/esm/tools/web-search-tool.js.map +1 -1
- package/dist/esm/usage.js +88 -76
- package/dist/esm/usage.js.map +1 -1
- package/dist/esm/utils/request-options.js +20 -9
- package/dist/esm/utils/request-options.js.map +1 -1
- package/dist/esm/utils/schema-converter.js +193 -146
- package/dist/esm/utils/schema-converter.js.map +1 -1
- package/package.json +7 -7
- package/src/adapters/responses-text.ts +84 -57
- package/src/index.ts +4 -1
- package/dist/esm/index.js.map +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -10,50 +10,11 @@ import { convertImageGenerationToolToAdapterFormat, imageGenerationTool, validat
|
|
|
10
10
|
import { convertLocalShellToolToAdapterFormat, localShellTool } from "./tools/local-shell-tool.js";
|
|
11
11
|
import { convertMCPToolToAdapterFormat, mcpTool, validateMCPtool } from "./tools/mcp-tool.js";
|
|
12
12
|
import { convertShellToolToAdapterFormat, shellTool } from "./tools/shell-tool.js";
|
|
13
|
-
import { convertToolsToProviderFormat } from "./tools/tool-converter.js";
|
|
14
13
|
import { convertWebSearchPreviewToolToAdapterFormat, webSearchPreviewTool } from "./tools/web-search-preview-tool.js";
|
|
15
14
|
import { convertWebSearchToolToAdapterFormat, webSearchTool } from "./tools/web-search-tool.js";
|
|
16
|
-
import {
|
|
15
|
+
import { convertToolsToProviderFormat } from "./tools/tool-converter.js";
|
|
17
16
|
import { convertFunctionToolToChatCompletionsFormat, convertToolsToChatCompletionsFormat } from "./adapters/chat-completions-tool-converter.js";
|
|
18
|
-
import {
|
|
17
|
+
import { OpenAIBaseChatCompletionsTextAdapter } from "./adapters/chat-completions-text.js";
|
|
19
18
|
import { convertFunctionToolToResponsesFormat, convertToolsToResponsesFormat } from "./adapters/responses-tool-converter.js";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
OpenAIBaseResponsesTextAdapter,
|
|
23
|
-
applyPatchTool,
|
|
24
|
-
buildChatCompletionsUsage,
|
|
25
|
-
buildImagesUsage,
|
|
26
|
-
buildResponsesUsage,
|
|
27
|
-
codeInterpreterTool,
|
|
28
|
-
computerUseTool,
|
|
29
|
-
convertApplyPatchToolToAdapterFormat,
|
|
30
|
-
convertCodeInterpreterToolToAdapterFormat,
|
|
31
|
-
convertComputerUseToolToAdapterFormat,
|
|
32
|
-
convertCustomToolToAdapterFormat,
|
|
33
|
-
convertFileSearchToolToAdapterFormat,
|
|
34
|
-
convertFunctionToolToAdapterFormat,
|
|
35
|
-
convertFunctionToolToChatCompletionsFormat,
|
|
36
|
-
convertFunctionToolToResponsesFormat,
|
|
37
|
-
convertImageGenerationToolToAdapterFormat,
|
|
38
|
-
convertLocalShellToolToAdapterFormat,
|
|
39
|
-
convertMCPToolToAdapterFormat,
|
|
40
|
-
convertShellToolToAdapterFormat,
|
|
41
|
-
convertToolsToChatCompletionsFormat,
|
|
42
|
-
convertToolsToProviderFormat,
|
|
43
|
-
convertToolsToResponsesFormat,
|
|
44
|
-
convertWebSearchPreviewToolToAdapterFormat,
|
|
45
|
-
convertWebSearchToolToAdapterFormat,
|
|
46
|
-
customTool,
|
|
47
|
-
fileSearchTool,
|
|
48
|
-
imageGenerationTool,
|
|
49
|
-
localShellTool,
|
|
50
|
-
makeStructuredOutputCompatible,
|
|
51
|
-
mcpTool,
|
|
52
|
-
shellTool,
|
|
53
|
-
validateMCPtool,
|
|
54
|
-
validateMaxNumResults,
|
|
55
|
-
validatePartialImages,
|
|
56
|
-
webSearchPreviewTool,
|
|
57
|
-
webSearchTool
|
|
58
|
-
};
|
|
59
|
-
//# sourceMappingURL=index.js.map
|
|
19
|
+
import { OpenAIBaseResponsesTextAdapter } from "./adapters/responses-text.js";
|
|
20
|
+
export { OpenAIBaseChatCompletionsTextAdapter, OpenAIBaseResponsesTextAdapter, applyPatchTool, buildChatCompletionsUsage, buildImagesUsage, buildResponsesUsage, codeInterpreterTool, computerUseTool, convertApplyPatchToolToAdapterFormat, convertCodeInterpreterToolToAdapterFormat, convertComputerUseToolToAdapterFormat, convertCustomToolToAdapterFormat, convertFileSearchToolToAdapterFormat, convertFunctionToolToAdapterFormat, convertFunctionToolToChatCompletionsFormat, convertFunctionToolToResponsesFormat, convertImageGenerationToolToAdapterFormat, convertLocalShellToolToAdapterFormat, convertMCPToolToAdapterFormat, convertShellToolToAdapterFormat, convertToolsToChatCompletionsFormat, convertToolsToProviderFormat, convertToolsToResponsesFormat, convertWebSearchPreviewToolToAdapterFormat, convertWebSearchToolToAdapterFormat, customTool, fileSearchTool, imageGenerationTool, localShellTool, makeStructuredOutputCompatible, mcpTool, shellTool, validateMCPtool, validateMaxNumResults, validatePartialImages, webSearchPreviewTool, webSearchTool };
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
+
//#region src/tools/apply-patch-tool.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts a standard Tool to OpenAI ApplyPatchTool format
|
|
4
|
+
*/
|
|
1
5
|
function convertApplyPatchToolToAdapterFormat(_tool) {
|
|
2
|
-
|
|
3
|
-
type: "apply_patch"
|
|
4
|
-
};
|
|
6
|
+
return { type: "apply_patch" };
|
|
5
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates a standard Tool from ApplyPatchTool parameters.
|
|
10
|
+
*
|
|
11
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
12
|
+
* re-wrap this in their own package.
|
|
13
|
+
*/
|
|
6
14
|
function applyPatchTool() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
return {
|
|
16
|
+
name: "apply_patch",
|
|
17
|
+
description: "Apply a patch to modify files",
|
|
18
|
+
metadata: {}
|
|
19
|
+
};
|
|
12
20
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=apply-patch-tool.js.map
|
|
21
|
+
//#endregion
|
|
22
|
+
export { applyPatchTool, convertApplyPatchToolToAdapterFormat };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=apply-patch-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-patch-tool.js","sources":["../../../src/tools/apply-patch-tool.ts"],"sourcesContent":["import type { ApplyPatchTool as ApplyPatchToolConfig } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\nexport type { ApplyPatchToolConfig }\n\n/** @deprecated Renamed to `ApplyPatchToolConfig`. Will be removed in a future release. */\nexport type ApplyPatchTool = ApplyPatchToolConfig\n\n/**\n * Converts a standard Tool to OpenAI ApplyPatchTool format\n */\nexport function convertApplyPatchToolToAdapterFormat(\n _tool: Tool,\n): ApplyPatchToolConfig {\n return {\n type: 'apply_patch',\n }\n}\n\n/**\n * Creates a standard Tool from ApplyPatchTool parameters.\n *\n * Base (non-branded) factory. Providers that need branded return types should\n * re-wrap this in their own package.\n */\nexport function applyPatchTool(): Tool {\n return {\n name: 'apply_patch',\n description: 'Apply a patch to modify files',\n metadata: {},\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"apply-patch-tool.js","names":[],"sources":["../../../src/tools/apply-patch-tool.ts"],"sourcesContent":["import type { ApplyPatchTool as ApplyPatchToolConfig } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\nexport type { ApplyPatchToolConfig }\n\n/** @deprecated Renamed to `ApplyPatchToolConfig`. Will be removed in a future release. */\nexport type ApplyPatchTool = ApplyPatchToolConfig\n\n/**\n * Converts a standard Tool to OpenAI ApplyPatchTool format\n */\nexport function convertApplyPatchToolToAdapterFormat(\n _tool: Tool,\n): ApplyPatchToolConfig {\n return {\n type: 'apply_patch',\n }\n}\n\n/**\n * Creates a standard Tool from ApplyPatchTool parameters.\n *\n * Base (non-branded) factory. Providers that need branded return types should\n * re-wrap this in their own package.\n */\nexport function applyPatchTool(): Tool {\n return {\n name: 'apply_patch',\n description: 'Apply a patch to modify files',\n metadata: {},\n }\n}\n"],"mappings":";;;;AAWA,SAAgB,qCACd,OACsB;CACtB,OAAO,EACL,MAAM,cACR;AACF;;;;;;;AAQA,SAAgB,iBAAuB;CACrC,OAAO;EACL,MAAM;EACN,aAAa;EACb,UAAU,CAAC;CACb;AACF"}
|
|
@@ -1,22 +1,30 @@
|
|
|
1
|
+
//#region src/tools/code-interpreter-tool.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts a standard Tool to OpenAI CodeInterpreterTool format
|
|
4
|
+
*/
|
|
1
5
|
function convertCodeInterpreterToolToAdapterFormat(tool) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
6
|
+
return {
|
|
7
|
+
type: "code_interpreter",
|
|
8
|
+
container: tool.metadata.container
|
|
9
|
+
};
|
|
7
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a standard Tool from CodeInterpreterTool parameters.
|
|
13
|
+
*
|
|
14
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
15
|
+
* re-wrap this in their own package.
|
|
16
|
+
*/
|
|
8
17
|
function codeInterpreterTool(container) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
return {
|
|
19
|
+
name: "code_interpreter",
|
|
20
|
+
description: "Execute code in a sandboxed environment",
|
|
21
|
+
metadata: {
|
|
22
|
+
type: "code_interpreter",
|
|
23
|
+
container
|
|
24
|
+
}
|
|
25
|
+
};
|
|
17
26
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=code-interpreter-tool.js.map
|
|
27
|
+
//#endregion
|
|
28
|
+
export { codeInterpreterTool, convertCodeInterpreterToolToAdapterFormat };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=code-interpreter-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-interpreter-tool.js","sources":["../../../src/tools/code-interpreter-tool.ts"],"sourcesContent":["import type { Tool as SDKTool } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\ntype CodeInterpreterToolConfig = SDKTool.CodeInterpreter\n\nexport type { CodeInterpreterToolConfig }\n\n/** @deprecated Renamed to `CodeInterpreterToolConfig`. Will be removed in a future release. */\nexport type CodeInterpreterTool = CodeInterpreterToolConfig\n\n/**\n * Converts a standard Tool to OpenAI CodeInterpreterTool format\n */\nexport function convertCodeInterpreterToolToAdapterFormat(\n tool: Tool,\n): CodeInterpreterToolConfig {\n const metadata = tool.metadata as CodeInterpreterToolConfig\n return {\n type: 'code_interpreter',\n container: metadata.container,\n }\n}\n\n/**\n * Creates a standard Tool from CodeInterpreterTool parameters.\n *\n * Base (non-branded) factory. Providers that need branded return types should\n * re-wrap this in their own package.\n */\nexport function codeInterpreterTool(\n container: CodeInterpreterToolConfig,\n): Tool {\n return {\n name: 'code_interpreter',\n description: 'Execute code in a sandboxed environment',\n metadata: {\n type: 'code_interpreter',\n container,\n },\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"code-interpreter-tool.js","names":[],"sources":["../../../src/tools/code-interpreter-tool.ts"],"sourcesContent":["import type { Tool as SDKTool } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\ntype CodeInterpreterToolConfig = SDKTool.CodeInterpreter\n\nexport type { CodeInterpreterToolConfig }\n\n/** @deprecated Renamed to `CodeInterpreterToolConfig`. Will be removed in a future release. */\nexport type CodeInterpreterTool = CodeInterpreterToolConfig\n\n/**\n * Converts a standard Tool to OpenAI CodeInterpreterTool format\n */\nexport function convertCodeInterpreterToolToAdapterFormat(\n tool: Tool,\n): CodeInterpreterToolConfig {\n const metadata = tool.metadata as CodeInterpreterToolConfig\n return {\n type: 'code_interpreter',\n container: metadata.container,\n }\n}\n\n/**\n * Creates a standard Tool from CodeInterpreterTool parameters.\n *\n * Base (non-branded) factory. Providers that need branded return types should\n * re-wrap this in their own package.\n */\nexport function codeInterpreterTool(\n container: CodeInterpreterToolConfig,\n): Tool {\n return {\n name: 'code_interpreter',\n description: 'Execute code in a sandboxed environment',\n metadata: {\n type: 'code_interpreter',\n container,\n },\n }\n}\n"],"mappings":";;;;AAaA,SAAgB,0CACd,MAC2B;CAE3B,OAAO;EACL,MAAM;EACN,WAHe,KAAK,SAGA;CACtB;AACF;;;;;;;AAQA,SAAgB,oBACd,WACM;CACN,OAAO;EACL,MAAM;EACN,aAAa;EACb,UAAU;GACR,MAAM;GACN;EACF;CACF;AACF"}
|
|
@@ -1,23 +1,30 @@
|
|
|
1
|
+
//#region src/tools/computer-use-tool.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts a standard Tool to OpenAI ComputerUseTool format
|
|
4
|
+
*/
|
|
1
5
|
function convertComputerUseToolToAdapterFormat(tool) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const metadata = tool.metadata;
|
|
7
|
+
return {
|
|
8
|
+
type: "computer_use_preview",
|
|
9
|
+
display_height: metadata.display_height,
|
|
10
|
+
display_width: metadata.display_width,
|
|
11
|
+
environment: metadata.environment
|
|
12
|
+
};
|
|
9
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a standard Tool from ComputerUseTool parameters.
|
|
16
|
+
*
|
|
17
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
18
|
+
* re-wrap this in their own package.
|
|
19
|
+
*/
|
|
10
20
|
function computerUseTool(toolData) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
};
|
|
21
|
+
return {
|
|
22
|
+
name: "computer_use_preview",
|
|
23
|
+
description: "Control a virtual computer",
|
|
24
|
+
metadata: { ...toolData }
|
|
25
|
+
};
|
|
18
26
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL=computer-use-tool.js.map
|
|
27
|
+
//#endregion
|
|
28
|
+
export { computerUseTool, convertComputerUseToolToAdapterFormat };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=computer-use-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computer-use-tool.js","sources":["../../../src/tools/computer-use-tool.ts"],"sourcesContent":["import type { ComputerUsePreviewTool as ComputerUseToolConfig } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\nexport type { ComputerUseToolConfig }\n\n/** @deprecated Renamed to `ComputerUseToolConfig`. Will be removed in a future release. */\nexport type ComputerUseTool = ComputerUseToolConfig\n\n/**\n * Converts a standard Tool to OpenAI ComputerUseTool format\n */\nexport function convertComputerUseToolToAdapterFormat(\n tool: Tool,\n): ComputerUseToolConfig {\n const metadata = tool.metadata as ComputerUseToolConfig\n return {\n type: 'computer_use_preview',\n display_height: metadata.display_height,\n display_width: metadata.display_width,\n environment: metadata.environment,\n }\n}\n\n/**\n * Creates a standard Tool from ComputerUseTool parameters.\n *\n * Base (non-branded) factory. Providers that need branded return types should\n * re-wrap this in their own package.\n */\nexport function computerUseTool(toolData: ComputerUseToolConfig): Tool {\n return {\n name: 'computer_use_preview',\n description: 'Control a virtual computer',\n metadata: {\n ...toolData,\n },\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"computer-use-tool.js","names":[],"sources":["../../../src/tools/computer-use-tool.ts"],"sourcesContent":["import type { ComputerUsePreviewTool as ComputerUseToolConfig } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\nexport type { ComputerUseToolConfig }\n\n/** @deprecated Renamed to `ComputerUseToolConfig`. Will be removed in a future release. */\nexport type ComputerUseTool = ComputerUseToolConfig\n\n/**\n * Converts a standard Tool to OpenAI ComputerUseTool format\n */\nexport function convertComputerUseToolToAdapterFormat(\n tool: Tool,\n): ComputerUseToolConfig {\n const metadata = tool.metadata as ComputerUseToolConfig\n return {\n type: 'computer_use_preview',\n display_height: metadata.display_height,\n display_width: metadata.display_width,\n environment: metadata.environment,\n }\n}\n\n/**\n * Creates a standard Tool from ComputerUseTool parameters.\n *\n * Base (non-branded) factory. Providers that need branded return types should\n * re-wrap this in their own package.\n */\nexport function computerUseTool(toolData: ComputerUseToolConfig): Tool {\n return {\n name: 'computer_use_preview',\n description: 'Control a virtual computer',\n metadata: {\n ...toolData,\n },\n }\n}\n"],"mappings":";;;;AAWA,SAAgB,sCACd,MACuB;CACvB,MAAM,WAAW,KAAK;CACtB,OAAO;EACL,MAAM;EACN,gBAAgB,SAAS;EACzB,eAAe,SAAS;EACxB,aAAa,SAAS;CACxB;AACF;;;;;;;AAQA,SAAgB,gBAAgB,UAAuC;CACrE,OAAO;EACL,MAAM;EACN,aAAa;EACb,UAAU,EACR,GAAG,SACL;CACF;AACF"}
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
+
//#region src/tools/custom-tool.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts a standard Tool to OpenAI CustomTool format
|
|
4
|
+
*/
|
|
1
5
|
function convertCustomToolToAdapterFormat(tool) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
...metadata.format !== void 0 && { format: metadata.format }
|
|
10
|
-
};
|
|
6
|
+
const metadata = tool.metadata;
|
|
7
|
+
return {
|
|
8
|
+
type: "custom",
|
|
9
|
+
name: metadata.name,
|
|
10
|
+
...metadata.description !== void 0 && { description: metadata.description },
|
|
11
|
+
...metadata.format !== void 0 && { format: metadata.format }
|
|
12
|
+
};
|
|
11
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a standard Tool from CustomTool parameters.
|
|
16
|
+
*/
|
|
12
17
|
function customTool(toolData) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
};
|
|
18
|
+
return {
|
|
19
|
+
name: "custom",
|
|
20
|
+
description: toolData.description || "A custom tool",
|
|
21
|
+
metadata: { ...toolData }
|
|
22
|
+
};
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=custom-tool.js.map
|
|
24
|
+
//#endregion
|
|
25
|
+
export { convertCustomToolToAdapterFormat, customTool };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=custom-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-tool.js","sources":["../../../src/tools/custom-tool.ts"],"sourcesContent":["import type { CustomTool as CustomToolConfig } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\nexport type { CustomToolConfig }\n\n/** @deprecated Renamed to `CustomToolConfig`. Will be removed in a future release. */\nexport type CustomTool = CustomToolConfig\n\n/**\n * Converts a standard Tool to OpenAI CustomTool format\n */\nexport function convertCustomToolToAdapterFormat(tool: Tool): CustomToolConfig {\n const metadata = tool.metadata as CustomToolConfig\n // Conditional spread: the SDK's `CustomToolConfig` declares optional\n // fields as `description?: string` (no `| undefined`) under\n // exactOptionalPropertyTypes, so we omit absent fields rather than\n // passing them through as explicit `undefined`.\n return {\n type: 'custom',\n name: metadata.name,\n ...(metadata.description !== undefined && {\n description: metadata.description,\n }),\n ...(metadata.format !== undefined && { format: metadata.format }),\n }\n}\n\n/**\n * Creates a standard Tool from CustomTool parameters.\n */\nexport function customTool(toolData: CustomToolConfig): Tool {\n return {\n name: 'custom',\n description: toolData.description || 'A custom tool',\n metadata: {\n ...toolData,\n },\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"custom-tool.js","names":[],"sources":["../../../src/tools/custom-tool.ts"],"sourcesContent":["import type { CustomTool as CustomToolConfig } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\nexport type { CustomToolConfig }\n\n/** @deprecated Renamed to `CustomToolConfig`. Will be removed in a future release. */\nexport type CustomTool = CustomToolConfig\n\n/**\n * Converts a standard Tool to OpenAI CustomTool format\n */\nexport function convertCustomToolToAdapterFormat(tool: Tool): CustomToolConfig {\n const metadata = tool.metadata as CustomToolConfig\n // Conditional spread: the SDK's `CustomToolConfig` declares optional\n // fields as `description?: string` (no `| undefined`) under\n // exactOptionalPropertyTypes, so we omit absent fields rather than\n // passing them through as explicit `undefined`.\n return {\n type: 'custom',\n name: metadata.name,\n ...(metadata.description !== undefined && {\n description: metadata.description,\n }),\n ...(metadata.format !== undefined && { format: metadata.format }),\n }\n}\n\n/**\n * Creates a standard Tool from CustomTool parameters.\n */\nexport function customTool(toolData: CustomToolConfig): Tool {\n return {\n name: 'custom',\n description: toolData.description || 'A custom tool',\n metadata: {\n ...toolData,\n },\n }\n}\n"],"mappings":";;;;AAWA,SAAgB,iCAAiC,MAA8B;CAC7E,MAAM,WAAW,KAAK;CAKtB,OAAO;EACL,MAAM;EACN,MAAM,SAAS;EACf,GAAI,SAAS,gBAAgB,KAAA,KAAa,EACxC,aAAa,SAAS,YACxB;EACA,GAAI,SAAS,WAAW,KAAA,KAAa,EAAE,QAAQ,SAAS,OAAO;CACjE;AACF;;;;AAKA,SAAgB,WAAW,UAAkC;CAC3D,OAAO;EACL,MAAM;EACN,aAAa,SAAS,eAAe;EACrC,UAAU,EACR,GAAG,SACL;CACF;AACF"}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
//#region src/tools/file-search-tool.ts
|
|
2
|
+
var validateMaxNumResults = (maxNumResults) => {
|
|
3
|
+
if (maxNumResults !== void 0 && (maxNumResults < 1 || maxNumResults > 50)) throw new Error("max_num_results must be between 1 and 50.");
|
|
5
4
|
};
|
|
5
|
+
/**
|
|
6
|
+
* Converts a standard Tool to OpenAI FileSearchTool format
|
|
7
|
+
*/
|
|
6
8
|
function convertFileSearchToolToAdapterFormat(tool) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
ranking_options: metadata.ranking_options
|
|
16
|
-
},
|
|
17
|
-
...metadata.filters !== void 0 && { filters: metadata.filters }
|
|
18
|
-
};
|
|
9
|
+
const metadata = tool.metadata;
|
|
10
|
+
return {
|
|
11
|
+
type: "file_search",
|
|
12
|
+
vector_store_ids: metadata.vector_store_ids,
|
|
13
|
+
...metadata.max_num_results !== void 0 && { max_num_results: metadata.max_num_results },
|
|
14
|
+
...metadata.ranking_options !== void 0 && { ranking_options: metadata.ranking_options },
|
|
15
|
+
...metadata.filters !== void 0 && { filters: metadata.filters }
|
|
16
|
+
};
|
|
19
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates a standard Tool from FileSearchTool parameters.
|
|
20
|
+
*
|
|
21
|
+
* Validates max_num_results. Base (non-branded) factory; providers that need
|
|
22
|
+
* branded return types should re-wrap in their own package.
|
|
23
|
+
*/
|
|
20
24
|
function fileSearchTool(toolData) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
};
|
|
25
|
+
validateMaxNumResults(toolData.max_num_results);
|
|
26
|
+
return {
|
|
27
|
+
name: "file_search",
|
|
28
|
+
description: "Search files in vector stores",
|
|
29
|
+
metadata: { ...toolData }
|
|
30
|
+
};
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=file-search-tool.js.map
|
|
32
|
+
//#endregion
|
|
33
|
+
export { convertFileSearchToolToAdapterFormat, fileSearchTool, validateMaxNumResults };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=file-search-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-search-tool.js","sources":["../../../src/tools/file-search-tool.ts"],"sourcesContent":["import type { FileSearchTool as FileSearchToolConfig } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\nexport type { FileSearchToolConfig }\n\nconst validateMaxNumResults = (maxNumResults: number | undefined) => {\n if (\n maxNumResults !== undefined &&\n (maxNumResults < 1 || maxNumResults > 50)\n ) {\n throw new Error('max_num_results must be between 1 and 50.')\n }\n}\n\n/** @deprecated Renamed to `FileSearchToolConfig`. Will be removed in a future release. */\nexport type FileSearchTool = FileSearchToolConfig\n\n/**\n * Converts a standard Tool to OpenAI FileSearchTool format\n */\nexport function convertFileSearchToolToAdapterFormat(\n tool: Tool,\n): FileSearchToolConfig {\n const metadata = tool.metadata as FileSearchToolConfig\n // Conditional spread: SDK's `FileSearchToolConfig` declares the\n // optional fields without `| undefined`, so we omit absent values\n // rather than passing them through as explicit `undefined`.\n return {\n type: 'file_search',\n vector_store_ids: metadata.vector_store_ids,\n ...(metadata.max_num_results !== undefined && {\n max_num_results: metadata.max_num_results,\n }),\n ...(metadata.ranking_options !== undefined && {\n ranking_options: metadata.ranking_options,\n }),\n ...(metadata.filters !== undefined && { filters: metadata.filters }),\n }\n}\n\n/**\n * Creates a standard Tool from FileSearchTool parameters.\n *\n * Validates max_num_results. Base (non-branded) factory; providers that need\n * branded return types should re-wrap in their own package.\n */\nexport function fileSearchTool(toolData: FileSearchToolConfig): Tool {\n validateMaxNumResults(toolData.max_num_results)\n return {\n name: 'file_search',\n description: 'Search files in vector stores',\n metadata: {\n ...toolData,\n },\n }\n}\n\nexport { validateMaxNumResults }\n"],"
|
|
1
|
+
{"version":3,"file":"file-search-tool.js","names":[],"sources":["../../../src/tools/file-search-tool.ts"],"sourcesContent":["import type { FileSearchTool as FileSearchToolConfig } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\nexport type { FileSearchToolConfig }\n\nconst validateMaxNumResults = (maxNumResults: number | undefined) => {\n if (\n maxNumResults !== undefined &&\n (maxNumResults < 1 || maxNumResults > 50)\n ) {\n throw new Error('max_num_results must be between 1 and 50.')\n }\n}\n\n/** @deprecated Renamed to `FileSearchToolConfig`. Will be removed in a future release. */\nexport type FileSearchTool = FileSearchToolConfig\n\n/**\n * Converts a standard Tool to OpenAI FileSearchTool format\n */\nexport function convertFileSearchToolToAdapterFormat(\n tool: Tool,\n): FileSearchToolConfig {\n const metadata = tool.metadata as FileSearchToolConfig\n // Conditional spread: SDK's `FileSearchToolConfig` declares the\n // optional fields without `| undefined`, so we omit absent values\n // rather than passing them through as explicit `undefined`.\n return {\n type: 'file_search',\n vector_store_ids: metadata.vector_store_ids,\n ...(metadata.max_num_results !== undefined && {\n max_num_results: metadata.max_num_results,\n }),\n ...(metadata.ranking_options !== undefined && {\n ranking_options: metadata.ranking_options,\n }),\n ...(metadata.filters !== undefined && { filters: metadata.filters }),\n }\n}\n\n/**\n * Creates a standard Tool from FileSearchTool parameters.\n *\n * Validates max_num_results. Base (non-branded) factory; providers that need\n * branded return types should re-wrap in their own package.\n */\nexport function fileSearchTool(toolData: FileSearchToolConfig): Tool {\n validateMaxNumResults(toolData.max_num_results)\n return {\n name: 'file_search',\n description: 'Search files in vector stores',\n metadata: {\n ...toolData,\n },\n }\n}\n\nexport { validateMaxNumResults }\n"],"mappings":";AAKA,IAAM,yBAAyB,kBAAsC;CACnE,IACE,kBAAkB,KAAA,MACjB,gBAAgB,KAAK,gBAAgB,KAEtC,MAAM,IAAI,MAAM,2CAA2C;AAE/D;;;;AAQA,SAAgB,qCACd,MACsB;CACtB,MAAM,WAAW,KAAK;CAItB,OAAO;EACL,MAAM;EACN,kBAAkB,SAAS;EAC3B,GAAI,SAAS,oBAAoB,KAAA,KAAa,EAC5C,iBAAiB,SAAS,gBAC5B;EACA,GAAI,SAAS,oBAAoB,KAAA,KAAa,EAC5C,iBAAiB,SAAS,gBAC5B;EACA,GAAI,SAAS,YAAY,KAAA,KAAa,EAAE,SAAS,SAAS,QAAQ;CACpE;AACF;;;;;;;AAQA,SAAgB,eAAe,UAAsC;CACnE,sBAAsB,SAAS,eAAe;CAC9C,OAAO;EACL,MAAM;EACN,aAAa;EACb,UAAU,EACR,GAAG,SACL;CACF;AACF"}
|
|
@@ -1,33 +1,46 @@
|
|
|
1
|
-
import { isStrictModeCompatible,
|
|
1
|
+
import { isStrictModeCompatible, makeStructuredOutputCompatible, stripUnsupportedFormats } from "../utils/schema-converter.js";
|
|
2
|
+
//#region src/tools/function-tool.ts
|
|
3
|
+
/**
|
|
4
|
+
* Converts a standard Tool to OpenAI FunctionTool format.
|
|
5
|
+
*
|
|
6
|
+
* Tool schemas are already converted to JSON Schema in the ai layer.
|
|
7
|
+
* We apply OpenAI-specific transformations for strict mode:
|
|
8
|
+
* - All properties in required array
|
|
9
|
+
* - Optional fields made nullable
|
|
10
|
+
* - additionalProperties: false
|
|
11
|
+
*
|
|
12
|
+
* This enables strict mode for all tools automatically.
|
|
13
|
+
*
|
|
14
|
+
* Some tool schemas (e.g. MCP server tools that use `oneOf`, `$ref`, or
|
|
15
|
+
* `$defs`) cannot be expressed under OpenAI's strict Structured Outputs
|
|
16
|
+
* subset. For those we fall back to a non-strict tool definition — stripping
|
|
17
|
+
* only the formats OpenAI rejects — so the tool is still usable instead of
|
|
18
|
+
* failing the request with a 400 "Invalid schema" error.
|
|
19
|
+
*/
|
|
2
20
|
function convertFunctionToolToAdapterFormat(tool) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
name: tool.name,
|
|
25
|
-
description: tool.description,
|
|
26
|
-
parameters: jsonSchema,
|
|
27
|
-
strict: true
|
|
28
|
-
};
|
|
21
|
+
const inputSchema = tool.inputSchema ?? {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {},
|
|
24
|
+
required: []
|
|
25
|
+
};
|
|
26
|
+
if (!isStrictModeCompatible(inputSchema)) return {
|
|
27
|
+
type: "function",
|
|
28
|
+
name: tool.name,
|
|
29
|
+
description: tool.description,
|
|
30
|
+
parameters: stripUnsupportedFormats(inputSchema),
|
|
31
|
+
strict: false
|
|
32
|
+
};
|
|
33
|
+
const jsonSchema = makeStructuredOutputCompatible(inputSchema, inputSchema.required || []);
|
|
34
|
+
jsonSchema.additionalProperties = false;
|
|
35
|
+
return {
|
|
36
|
+
type: "function",
|
|
37
|
+
name: tool.name,
|
|
38
|
+
description: tool.description,
|
|
39
|
+
parameters: jsonSchema,
|
|
40
|
+
strict: true
|
|
41
|
+
};
|
|
29
42
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
//# sourceMappingURL=function-tool.js.map
|
|
43
|
+
//#endregion
|
|
44
|
+
export { convertFunctionToolToAdapterFormat };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=function-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-tool.js","sources":["../../../src/tools/function-tool.ts"],"sourcesContent":["import {\n isStrictModeCompatible,\n makeStructuredOutputCompatible,\n stripUnsupportedFormats,\n} from '../utils/schema-converter'\nimport type { FunctionTool as FunctionToolConfig } from 'openai/resources/responses/responses'\nimport type { JSONSchema, Tool } from '@tanstack/ai'\n\nexport type { FunctionToolConfig }\n\n/** @deprecated Renamed to `FunctionToolConfig`. Will be removed in a future release. */\nexport type FunctionTool = FunctionToolConfig\n\n/**\n * Converts a standard Tool to OpenAI FunctionTool format.\n *\n * Tool schemas are already converted to JSON Schema in the ai layer.\n * We apply OpenAI-specific transformations for strict mode:\n * - All properties in required array\n * - Optional fields made nullable\n * - additionalProperties: false\n *\n * This enables strict mode for all tools automatically.\n *\n * Some tool schemas (e.g. MCP server tools that use `oneOf`, `$ref`, or\n * `$defs`) cannot be expressed under OpenAI's strict Structured Outputs\n * subset. For those we fall back to a non-strict tool definition — stripping\n * only the formats OpenAI rejects — so the tool is still usable instead of\n * failing the request with a 400 \"Invalid schema\" error.\n */\nexport function convertFunctionToolToAdapterFormat(\n tool: Tool,\n): FunctionToolConfig {\n const inputSchema = (tool.inputSchema ?? {\n type: 'object',\n properties: {},\n required: [],\n }) as JSONSchema\n\n if (!isStrictModeCompatible(inputSchema)) {\n return {\n type: 'function',\n name: tool.name,\n description: tool.description,\n parameters: stripUnsupportedFormats(inputSchema),\n strict: false,\n } satisfies FunctionToolConfig\n }\n\n const jsonSchema = makeStructuredOutputCompatible(\n inputSchema,\n inputSchema.required || [],\n )\n\n jsonSchema.additionalProperties = false\n\n return {\n type: 'function',\n name: tool.name,\n description: tool.description,\n parameters: jsonSchema,\n strict: true,\n } satisfies FunctionToolConfig\n}\n"],"
|
|
1
|
+
{"version":3,"file":"function-tool.js","names":[],"sources":["../../../src/tools/function-tool.ts"],"sourcesContent":["import {\n isStrictModeCompatible,\n makeStructuredOutputCompatible,\n stripUnsupportedFormats,\n} from '../utils/schema-converter'\nimport type { FunctionTool as FunctionToolConfig } from 'openai/resources/responses/responses'\nimport type { JSONSchema, Tool } from '@tanstack/ai'\n\nexport type { FunctionToolConfig }\n\n/** @deprecated Renamed to `FunctionToolConfig`. Will be removed in a future release. */\nexport type FunctionTool = FunctionToolConfig\n\n/**\n * Converts a standard Tool to OpenAI FunctionTool format.\n *\n * Tool schemas are already converted to JSON Schema in the ai layer.\n * We apply OpenAI-specific transformations for strict mode:\n * - All properties in required array\n * - Optional fields made nullable\n * - additionalProperties: false\n *\n * This enables strict mode for all tools automatically.\n *\n * Some tool schemas (e.g. MCP server tools that use `oneOf`, `$ref`, or\n * `$defs`) cannot be expressed under OpenAI's strict Structured Outputs\n * subset. For those we fall back to a non-strict tool definition — stripping\n * only the formats OpenAI rejects — so the tool is still usable instead of\n * failing the request with a 400 \"Invalid schema\" error.\n */\nexport function convertFunctionToolToAdapterFormat(\n tool: Tool,\n): FunctionToolConfig {\n const inputSchema = (tool.inputSchema ?? {\n type: 'object',\n properties: {},\n required: [],\n }) as JSONSchema\n\n if (!isStrictModeCompatible(inputSchema)) {\n return {\n type: 'function',\n name: tool.name,\n description: tool.description,\n parameters: stripUnsupportedFormats(inputSchema),\n strict: false,\n } satisfies FunctionToolConfig\n }\n\n const jsonSchema = makeStructuredOutputCompatible(\n inputSchema,\n inputSchema.required || [],\n )\n\n jsonSchema.additionalProperties = false\n\n return {\n type: 'function',\n name: tool.name,\n description: tool.description,\n parameters: jsonSchema,\n strict: true,\n } satisfies FunctionToolConfig\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,mCACd,MACoB;CACpB,MAAM,cAAe,KAAK,eAAe;EACvC,MAAM;EACN,YAAY,CAAC;EACb,UAAU,CAAC;CACb;CAEA,IAAI,CAAC,uBAAuB,WAAW,GACrC,OAAO;EACL,MAAM;EACN,MAAM,KAAK;EACX,aAAa,KAAK;EAClB,YAAY,wBAAwB,WAAW;EAC/C,QAAQ;CACV;CAGF,MAAM,aAAa,+BACjB,aACA,YAAY,YAAY,CAAC,CAC3B;CAEA,WAAW,uBAAuB;CAElC,OAAO;EACL,MAAM;EACN,MAAM,KAAK;EACX,aAAa,KAAK;EAClB,YAAY;EACZ,QAAQ;CACV;AACF"}
|
|
@@ -1,28 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
//#region src/tools/image-generation-tool.ts
|
|
2
|
+
var validatePartialImages = (value) => {
|
|
3
|
+
if (value !== void 0 && (value < 0 || value > 3)) throw new Error("partial_images must be between 0 and 3");
|
|
5
4
|
};
|
|
5
|
+
/**
|
|
6
|
+
* Converts a standard Tool to OpenAI ImageGenerationTool format. Spread
|
|
7
|
+
* `metadata` first, then force `type: 'image_generation'` last — otherwise a
|
|
8
|
+
* `metadata.type` snuck in by a hand-built tool would shadow the literal and
|
|
9
|
+
* the dispatcher (which routed by `tool.name`) would emit a tool whose
|
|
10
|
+
* runtime `type` doesn't match `image_generation`.
|
|
11
|
+
*/
|
|
6
12
|
function convertImageGenerationToolToAdapterFormat(tool) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
13
|
+
return {
|
|
14
|
+
...tool.metadata,
|
|
15
|
+
type: "image_generation"
|
|
16
|
+
};
|
|
12
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates a standard Tool from ImageGenerationTool parameters.
|
|
20
|
+
*
|
|
21
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
22
|
+
* re-wrap this in their own package.
|
|
23
|
+
*/
|
|
13
24
|
function imageGenerationTool(toolData) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
};
|
|
25
|
+
validatePartialImages(toolData.partial_images);
|
|
26
|
+
return {
|
|
27
|
+
name: "image_generation",
|
|
28
|
+
description: "Generate images based on text descriptions",
|
|
29
|
+
metadata: { ...toolData }
|
|
30
|
+
};
|
|
22
31
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=image-generation-tool.js.map
|
|
32
|
+
//#endregion
|
|
33
|
+
export { convertImageGenerationToolToAdapterFormat, imageGenerationTool, validatePartialImages };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=image-generation-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-generation-tool.js","sources":["../../../src/tools/image-generation-tool.ts"],"sourcesContent":["import type { Tool as SDKTool } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\ntype ImageGenerationToolConfig = SDKTool.ImageGeneration\n\nexport type { ImageGenerationToolConfig }\n\n/** @deprecated Renamed to `ImageGenerationToolConfig`. Will be removed in a future release. */\nexport type ImageGenerationTool = ImageGenerationToolConfig\n\nconst validatePartialImages = (value: number | undefined) => {\n if (value !== undefined && (value < 0 || value > 3)) {\n throw new Error('partial_images must be between 0 and 3')\n }\n}\n\n/**\n * Converts a standard Tool to OpenAI ImageGenerationTool format. Spread\n * `metadata` first, then force `type: 'image_generation'` last — otherwise a\n * `metadata.type` snuck in by a hand-built tool would shadow the literal and\n * the dispatcher (which routed by `tool.name`) would emit a tool whose\n * runtime `type` doesn't match `image_generation`.\n */\nexport function convertImageGenerationToolToAdapterFormat(\n tool: Tool,\n): ImageGenerationToolConfig {\n const metadata = tool.metadata as Omit<ImageGenerationToolConfig, 'type'>\n return {\n ...metadata,\n type: 'image_generation',\n }\n}\n\n/**\n * Creates a standard Tool from ImageGenerationTool parameters.\n *\n * Base (non-branded) factory. Providers that need branded return types should\n * re-wrap this in their own package.\n */\nexport function imageGenerationTool(\n toolData: Omit<ImageGenerationToolConfig, 'type'>,\n): Tool {\n validatePartialImages(toolData.partial_images)\n return {\n name: 'image_generation',\n description: 'Generate images based on text descriptions',\n metadata: {\n ...toolData,\n },\n }\n}\n\nexport { validatePartialImages }\n"],"
|
|
1
|
+
{"version":3,"file":"image-generation-tool.js","names":[],"sources":["../../../src/tools/image-generation-tool.ts"],"sourcesContent":["import type { Tool as SDKTool } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\ntype ImageGenerationToolConfig = SDKTool.ImageGeneration\n\nexport type { ImageGenerationToolConfig }\n\n/** @deprecated Renamed to `ImageGenerationToolConfig`. Will be removed in a future release. */\nexport type ImageGenerationTool = ImageGenerationToolConfig\n\nconst validatePartialImages = (value: number | undefined) => {\n if (value !== undefined && (value < 0 || value > 3)) {\n throw new Error('partial_images must be between 0 and 3')\n }\n}\n\n/**\n * Converts a standard Tool to OpenAI ImageGenerationTool format. Spread\n * `metadata` first, then force `type: 'image_generation'` last — otherwise a\n * `metadata.type` snuck in by a hand-built tool would shadow the literal and\n * the dispatcher (which routed by `tool.name`) would emit a tool whose\n * runtime `type` doesn't match `image_generation`.\n */\nexport function convertImageGenerationToolToAdapterFormat(\n tool: Tool,\n): ImageGenerationToolConfig {\n const metadata = tool.metadata as Omit<ImageGenerationToolConfig, 'type'>\n return {\n ...metadata,\n type: 'image_generation',\n }\n}\n\n/**\n * Creates a standard Tool from ImageGenerationTool parameters.\n *\n * Base (non-branded) factory. Providers that need branded return types should\n * re-wrap this in their own package.\n */\nexport function imageGenerationTool(\n toolData: Omit<ImageGenerationToolConfig, 'type'>,\n): Tool {\n validatePartialImages(toolData.partial_images)\n return {\n name: 'image_generation',\n description: 'Generate images based on text descriptions',\n metadata: {\n ...toolData,\n },\n }\n}\n\nexport { validatePartialImages }\n"],"mappings":";AAUA,IAAM,yBAAyB,UAA8B;CAC3D,IAAI,UAAU,KAAA,MAAc,QAAQ,KAAK,QAAQ,IAC/C,MAAM,IAAI,MAAM,wCAAwC;AAE5D;;;;;;;;AASA,SAAgB,0CACd,MAC2B;CAE3B,OAAO;EACL,GAFe,KAAK;EAGpB,MAAM;CACR;AACF;;;;;;;AAQA,SAAgB,oBACd,UACM;CACN,sBAAsB,SAAS,cAAc;CAC7C,OAAO;EACL,MAAM;EACN,aAAa;EACb,UAAU,EACR,GAAG,SACL;CACF;AACF"}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
+
//#region src/tools/local-shell-tool.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts a standard Tool to OpenAI LocalShellTool format
|
|
4
|
+
*/
|
|
1
5
|
function convertLocalShellToolToAdapterFormat(_tool) {
|
|
2
|
-
|
|
3
|
-
type: "local_shell"
|
|
4
|
-
};
|
|
6
|
+
return { type: "local_shell" };
|
|
5
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates a standard Tool from LocalShellTool parameters.
|
|
10
|
+
*
|
|
11
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
12
|
+
* re-wrap this in their own package.
|
|
13
|
+
*/
|
|
6
14
|
function localShellTool() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
return {
|
|
16
|
+
name: "local_shell",
|
|
17
|
+
description: "Execute local shell commands",
|
|
18
|
+
metadata: {}
|
|
19
|
+
};
|
|
12
20
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=local-shell-tool.js.map
|
|
21
|
+
//#endregion
|
|
22
|
+
export { convertLocalShellToolToAdapterFormat, localShellTool };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=local-shell-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-shell-tool.js","sources":["../../../src/tools/local-shell-tool.ts"],"sourcesContent":["import type { Tool as SDKTool } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\ntype LocalShellToolConfig = SDKTool.LocalShell\n\nexport type { LocalShellToolConfig }\n\n/** @deprecated Renamed to `LocalShellToolConfig`. Will be removed in a future release. */\nexport type LocalShellTool = LocalShellToolConfig\n\n/**\n * Converts a standard Tool to OpenAI LocalShellTool format\n */\nexport function convertLocalShellToolToAdapterFormat(\n _tool: Tool,\n): LocalShellToolConfig {\n return {\n type: 'local_shell',\n }\n}\n\n/**\n * Creates a standard Tool from LocalShellTool parameters.\n *\n * Base (non-branded) factory. Providers that need branded return types should\n * re-wrap this in their own package.\n */\nexport function localShellTool(): Tool {\n return {\n name: 'local_shell',\n description: 'Execute local shell commands',\n metadata: {},\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"local-shell-tool.js","names":[],"sources":["../../../src/tools/local-shell-tool.ts"],"sourcesContent":["import type { Tool as SDKTool } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\ntype LocalShellToolConfig = SDKTool.LocalShell\n\nexport type { LocalShellToolConfig }\n\n/** @deprecated Renamed to `LocalShellToolConfig`. Will be removed in a future release. */\nexport type LocalShellTool = LocalShellToolConfig\n\n/**\n * Converts a standard Tool to OpenAI LocalShellTool format\n */\nexport function convertLocalShellToolToAdapterFormat(\n _tool: Tool,\n): LocalShellToolConfig {\n return {\n type: 'local_shell',\n }\n}\n\n/**\n * Creates a standard Tool from LocalShellTool parameters.\n *\n * Base (non-branded) factory. Providers that need branded return types should\n * re-wrap this in their own package.\n */\nexport function localShellTool(): Tool {\n return {\n name: 'local_shell',\n description: 'Execute local shell commands',\n metadata: {},\n }\n}\n"],"mappings":";;;;AAaA,SAAgB,qCACd,OACsB;CACtB,OAAO,EACL,MAAM,cACR;AACF;;;;;;;AAQA,SAAgB,iBAAuB;CACrC,OAAO;EACL,MAAM;EACN,aAAa;EACb,UAAU,CAAC;CACb;AACF"}
|