@tanstack/openai-base 0.9.14 → 0.9.15
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 +1 -1
- package/dist/esm/adapters/responses-text.js +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/tools/apply-patch-tool.js +3 -2
- package/dist/esm/tools/apply-patch-tool.js.map +1 -1
- package/dist/esm/tools/code-interpreter-tool.js +4 -3
- package/dist/esm/tools/code-interpreter-tool.js.map +1 -1
- package/dist/esm/tools/computer-use-tool.js +4 -3
- package/dist/esm/tools/computer-use-tool.js.map +1 -1
- package/dist/esm/tools/custom-tool.js +4 -3
- package/dist/esm/tools/custom-tool.js.map +1 -1
- package/dist/esm/tools/file-search-tool.js +4 -3
- package/dist/esm/tools/file-search-tool.js.map +1 -1
- package/dist/esm/tools/image-generation-tool.d.ts +2 -4
- package/dist/esm/tools/image-generation-tool.js +6 -7
- package/dist/esm/tools/image-generation-tool.js.map +1 -1
- package/dist/esm/tools/index.js +14 -0
- package/dist/esm/tools/local-shell-tool.js +3 -2
- package/dist/esm/tools/local-shell-tool.js.map +1 -1
- package/dist/esm/tools/mcp-tool.js +7 -6
- package/dist/esm/tools/mcp-tool.js.map +1 -1
- package/dist/esm/tools/openai-provider-tool.d.ts +20 -0
- package/dist/esm/tools/openai-provider-tool.js +49 -0
- package/dist/esm/tools/openai-provider-tool.js.map +1 -0
- package/dist/esm/tools/shell-tool.js +4 -3
- package/dist/esm/tools/shell-tool.js.map +1 -1
- package/dist/esm/tools/tool-converter.js +7 -18
- package/dist/esm/tools/tool-converter.js.map +1 -1
- package/dist/esm/tools/web-search-preview-tool.d.ts +1 -2
- package/dist/esm/tools/web-search-preview-tool.js +5 -5
- package/dist/esm/tools/web-search-preview-tool.js.map +1 -1
- package/dist/esm/tools/web-search-tool.d.ts +2 -4
- package/dist/esm/tools/web-search-tool.js +6 -7
- package/dist/esm/tools/web-search-tool.js.map +1 -1
- package/package.json +3 -3
- package/src/tools/apply-patch-tool.ts +9 -5
- package/src/tools/code-interpreter-tool.ts +17 -8
- package/src/tools/computer-use-tool.ts +14 -7
- package/src/tools/custom-tool.ts +14 -7
- package/src/tools/file-search-tool.ts +14 -7
- package/src/tools/image-generation-tool.ts +19 -11
- package/src/tools/local-shell-tool.ts +9 -5
- package/src/tools/mcp-tool.ts +19 -9
- package/src/tools/openai-provider-tool.ts +72 -0
- package/src/tools/shell-tool.ts +17 -9
- package/src/tools/tool-converter.ts +28 -43
- package/src/tools/web-search-preview-tool.ts +17 -8
- package/src/tools/web-search-tool.ts +18 -10
|
@@ -3,8 +3,8 @@ import { buildChatCompletionsUsage } from "../usage.js";
|
|
|
3
3
|
import { extractRequestOptions } from "../utils/request-options.js";
|
|
4
4
|
import { convertToolsToChatCompletionsFormat } from "./chat-completions-tool-converter.js";
|
|
5
5
|
import { EventType, normalizeSystemPrompts } from "@tanstack/ai";
|
|
6
|
-
import { BaseTextAdapter } from "@tanstack/ai/adapters";
|
|
7
6
|
import { toRunErrorPayload, toRunErrorRawEvent } from "@tanstack/ai/adapter-internals";
|
|
7
|
+
import { BaseTextAdapter } from "@tanstack/ai/adapters";
|
|
8
8
|
import { generateId } from "@tanstack/ai-utils";
|
|
9
9
|
//#region src/adapters/chat-completions-text.ts
|
|
10
10
|
/**
|
|
@@ -3,8 +3,8 @@ import { buildResponsesUsage } from "../usage.js";
|
|
|
3
3
|
import { extractRequestOptions } from "../utils/request-options.js";
|
|
4
4
|
import { convertToolsToResponsesFormat } from "./responses-tool-converter.js";
|
|
5
5
|
import { EventType, normalizeSystemPrompts } from "@tanstack/ai";
|
|
6
|
-
import { BaseTextAdapter } from "@tanstack/ai/adapters";
|
|
7
6
|
import { toRunErrorPayload, toRunErrorRawEvent } from "@tanstack/ai/adapter-internals";
|
|
7
|
+
import { BaseTextAdapter } from "@tanstack/ai/adapters";
|
|
8
8
|
import { generateId } from "@tanstack/ai-utils";
|
|
9
9
|
//#region src/adapters/responses-text.ts
|
|
10
10
|
/**
|
package/dist/esm/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import { convertShellToolToAdapterFormat, shellTool } from "./tools/shell-tool.j
|
|
|
13
13
|
import { convertWebSearchPreviewToolToAdapterFormat, webSearchPreviewTool } from "./tools/web-search-preview-tool.js";
|
|
14
14
|
import { convertWebSearchToolToAdapterFormat, webSearchTool } from "./tools/web-search-tool.js";
|
|
15
15
|
import { convertToolsToProviderFormat } from "./tools/tool-converter.js";
|
|
16
|
+
import "./tools/index.js";
|
|
16
17
|
import { convertFunctionToolToChatCompletionsFormat, convertToolsToChatCompletionsFormat } from "./adapters/chat-completions-tool-converter.js";
|
|
17
18
|
import { OpenAIBaseChatCompletionsTextAdapter } from "./adapters/chat-completions-text.js";
|
|
18
19
|
import { convertFunctionToolToResponsesFormat, convertToolsToResponsesFormat } from "./adapters/responses-tool-converter.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { openAIProviderTool } from "./openai-provider-tool.js";
|
|
1
2
|
//#region src/tools/apply-patch-tool.ts
|
|
2
3
|
/**
|
|
3
4
|
* Converts a standard Tool to OpenAI ApplyPatchTool format
|
|
@@ -12,11 +13,11 @@ function convertApplyPatchToolToAdapterFormat(_tool) {
|
|
|
12
13
|
* re-wrap this in their own package.
|
|
13
14
|
*/
|
|
14
15
|
function applyPatchTool() {
|
|
15
|
-
return {
|
|
16
|
+
return openAIProviderTool({
|
|
16
17
|
name: "apply_patch",
|
|
17
18
|
description: "Apply a patch to modify files",
|
|
18
19
|
metadata: {}
|
|
19
|
-
};
|
|
20
|
+
}, "apply_patch");
|
|
20
21
|
}
|
|
21
22
|
//#endregion
|
|
22
23
|
export { applyPatchTool, convertApplyPatchToolToAdapterFormat };
|
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
{"version":3,"file":"apply-patch-tool.js","names":[],"sources":["../../../src/tools/apply-patch-tool.ts"],"sourcesContent":["import { openAIProviderTool } from './openai-provider-tool'\nimport 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 openAIProviderTool(\n {\n name: 'apply_patch',\n description: 'Apply a patch to modify files',\n metadata: {},\n },\n 'apply_patch',\n )\n}\n"],"mappings":";;;;;AAYA,SAAgB,qCACd,OACsB;CACtB,OAAO,EACL,MAAM,cACR;AACF;;;;;;;AAQA,SAAgB,iBAAuB;CACrC,OAAO,mBACL;EACE,MAAM;EACN,aAAa;EACb,UAAU,CAAC;CACb,GACA,aACF;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getOpenAIProviderToolMetadata, openAIProviderTool } from "./openai-provider-tool.js";
|
|
1
2
|
//#region src/tools/code-interpreter-tool.ts
|
|
2
3
|
/**
|
|
3
4
|
* Converts a standard Tool to OpenAI CodeInterpreterTool format
|
|
@@ -5,7 +6,7 @@
|
|
|
5
6
|
function convertCodeInterpreterToolToAdapterFormat(tool) {
|
|
6
7
|
return {
|
|
7
8
|
type: "code_interpreter",
|
|
8
|
-
container: tool.
|
|
9
|
+
container: getOpenAIProviderToolMetadata(tool).container
|
|
9
10
|
};
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
@@ -15,14 +16,14 @@ function convertCodeInterpreterToolToAdapterFormat(tool) {
|
|
|
15
16
|
* re-wrap this in their own package.
|
|
16
17
|
*/
|
|
17
18
|
function codeInterpreterTool(container) {
|
|
18
|
-
return {
|
|
19
|
+
return openAIProviderTool({
|
|
19
20
|
name: "code_interpreter",
|
|
20
21
|
description: "Execute code in a sandboxed environment",
|
|
21
22
|
metadata: {
|
|
22
23
|
type: "code_interpreter",
|
|
23
24
|
container
|
|
24
25
|
}
|
|
25
|
-
};
|
|
26
|
+
}, "code_interpreter");
|
|
26
27
|
}
|
|
27
28
|
//#endregion
|
|
28
29
|
export { codeInterpreterTool, convertCodeInterpreterToolToAdapterFormat };
|
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
{"version":3,"file":"code-interpreter-tool.js","names":[],"sources":["../../../src/tools/code-interpreter-tool.ts"],"sourcesContent":["import {\n getOpenAIProviderToolMetadata,\n openAIProviderTool,\n} from './openai-provider-tool'\nimport 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 = getOpenAIProviderToolMetadata(\n tool,\n ) 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 openAIProviderTool(\n {\n name: 'code_interpreter',\n description: 'Execute code in a sandboxed environment',\n metadata: {\n type: 'code_interpreter',\n container,\n },\n },\n 'code_interpreter',\n )\n}\n"],"mappings":";;;;;AAiBA,SAAgB,0CACd,MAC2B;CAI3B,OAAO;EACL,MAAM;EACN,WALe,8BACf,IAIW,CAAA,CAAS;CACtB;AACF;;;;;;;AAQA,SAAgB,oBACd,WACM;CACN,OAAO,mBACL;EACE,MAAM;EACN,aAAa;EACb,UAAU;GACR,MAAM;GACN;EACF;CACF,GACA,kBACF;AACF"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { getOpenAIProviderToolMetadata, openAIProviderTool } from "./openai-provider-tool.js";
|
|
1
2
|
//#region src/tools/computer-use-tool.ts
|
|
2
3
|
/**
|
|
3
4
|
* Converts a standard Tool to OpenAI ComputerUseTool format
|
|
4
5
|
*/
|
|
5
6
|
function convertComputerUseToolToAdapterFormat(tool) {
|
|
6
|
-
const metadata = tool
|
|
7
|
+
const metadata = getOpenAIProviderToolMetadata(tool);
|
|
7
8
|
return {
|
|
8
9
|
type: "computer_use_preview",
|
|
9
10
|
display_height: metadata.display_height,
|
|
@@ -18,11 +19,11 @@ function convertComputerUseToolToAdapterFormat(tool) {
|
|
|
18
19
|
* re-wrap this in their own package.
|
|
19
20
|
*/
|
|
20
21
|
function computerUseTool(toolData) {
|
|
21
|
-
return {
|
|
22
|
+
return openAIProviderTool({
|
|
22
23
|
name: "computer_use_preview",
|
|
23
24
|
description: "Control a virtual computer",
|
|
24
25
|
metadata: { ...toolData }
|
|
25
|
-
};
|
|
26
|
+
}, "computer_use");
|
|
26
27
|
}
|
|
27
28
|
//#endregion
|
|
28
29
|
export { computerUseTool, convertComputerUseToolToAdapterFormat };
|
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
{"version":3,"file":"computer-use-tool.js","names":[],"sources":["../../../src/tools/computer-use-tool.ts"],"sourcesContent":["import {\n getOpenAIProviderToolMetadata,\n openAIProviderTool,\n} from './openai-provider-tool'\nimport 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 = getOpenAIProviderToolMetadata(tool) 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 openAIProviderTool(\n {\n name: 'computer_use_preview',\n description: 'Control a virtual computer',\n metadata: {\n ...toolData,\n },\n },\n 'computer_use',\n )\n}\n"],"mappings":";;;;;AAeA,SAAgB,sCACd,MACuB;CACvB,MAAM,WAAW,8BAA8B,IAAI;CACnD,OAAO;EACL,MAAM;EACN,gBAAgB,SAAS;EACzB,eAAe,SAAS;EACxB,aAAa,SAAS;CACxB;AACF;;;;;;;AAQA,SAAgB,gBAAgB,UAAuC;CACrE,OAAO,mBACL;EACE,MAAM;EACN,aAAa;EACb,UAAU,EACR,GAAG,SACL;CACF,GACA,cACF;AACF"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { getOpenAIProviderToolMetadata, openAIProviderTool } from "./openai-provider-tool.js";
|
|
1
2
|
//#region src/tools/custom-tool.ts
|
|
2
3
|
/**
|
|
3
4
|
* Converts a standard Tool to OpenAI CustomTool format
|
|
4
5
|
*/
|
|
5
6
|
function convertCustomToolToAdapterFormat(tool) {
|
|
6
|
-
const metadata = tool
|
|
7
|
+
const metadata = getOpenAIProviderToolMetadata(tool);
|
|
7
8
|
return {
|
|
8
9
|
type: "custom",
|
|
9
10
|
name: metadata.name,
|
|
@@ -15,11 +16,11 @@ function convertCustomToolToAdapterFormat(tool) {
|
|
|
15
16
|
* Creates a standard Tool from CustomTool parameters.
|
|
16
17
|
*/
|
|
17
18
|
function customTool(toolData) {
|
|
18
|
-
return {
|
|
19
|
+
return openAIProviderTool({
|
|
19
20
|
name: "custom",
|
|
20
21
|
description: toolData.description || "A custom tool",
|
|
21
22
|
metadata: { ...toolData }
|
|
22
|
-
};
|
|
23
|
+
}, "custom");
|
|
23
24
|
}
|
|
24
25
|
//#endregion
|
|
25
26
|
export { convertCustomToolToAdapterFormat, customTool };
|
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
{"version":3,"file":"custom-tool.js","names":[],"sources":["../../../src/tools/custom-tool.ts"],"sourcesContent":["import {\n getOpenAIProviderToolMetadata,\n openAIProviderTool,\n} from './openai-provider-tool'\nimport 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 = getOpenAIProviderToolMetadata(tool) 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 openAIProviderTool(\n {\n name: 'custom',\n description: toolData.description || 'A custom tool',\n metadata: {\n ...toolData,\n },\n },\n 'custom',\n )\n}\n"],"mappings":";;;;;AAeA,SAAgB,iCAAiC,MAA8B;CAC7E,MAAM,WAAW,8BAA8B,IAAI;CAKnD,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,mBACL;EACE,MAAM;EACN,aAAa,SAAS,eAAe;EACrC,UAAU,EACR,GAAG,SACL;CACF,GACA,QACF;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getOpenAIProviderToolMetadata, openAIProviderTool } from "./openai-provider-tool.js";
|
|
1
2
|
//#region src/tools/file-search-tool.ts
|
|
2
3
|
var validateMaxNumResults = (maxNumResults) => {
|
|
3
4
|
if (maxNumResults !== void 0 && (maxNumResults < 1 || maxNumResults > 50)) throw new Error("max_num_results must be between 1 and 50.");
|
|
@@ -6,7 +7,7 @@ var validateMaxNumResults = (maxNumResults) => {
|
|
|
6
7
|
* Converts a standard Tool to OpenAI FileSearchTool format
|
|
7
8
|
*/
|
|
8
9
|
function convertFileSearchToolToAdapterFormat(tool) {
|
|
9
|
-
const metadata = tool
|
|
10
|
+
const metadata = getOpenAIProviderToolMetadata(tool);
|
|
10
11
|
return {
|
|
11
12
|
type: "file_search",
|
|
12
13
|
vector_store_ids: metadata.vector_store_ids,
|
|
@@ -23,11 +24,11 @@ function convertFileSearchToolToAdapterFormat(tool) {
|
|
|
23
24
|
*/
|
|
24
25
|
function fileSearchTool(toolData) {
|
|
25
26
|
validateMaxNumResults(toolData.max_num_results);
|
|
26
|
-
return {
|
|
27
|
+
return openAIProviderTool({
|
|
27
28
|
name: "file_search",
|
|
28
29
|
description: "Search files in vector stores",
|
|
29
30
|
metadata: { ...toolData }
|
|
30
|
-
};
|
|
31
|
+
}, "file_search");
|
|
31
32
|
}
|
|
32
33
|
//#endregion
|
|
33
34
|
export { convertFileSearchToolToAdapterFormat, fileSearchTool, validateMaxNumResults };
|
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
{"version":3,"file":"file-search-tool.js","names":[],"sources":["../../../src/tools/file-search-tool.ts"],"sourcesContent":["import {\n getOpenAIProviderToolMetadata,\n openAIProviderTool,\n} from './openai-provider-tool'\nimport 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 = getOpenAIProviderToolMetadata(tool) 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 openAIProviderTool(\n {\n name: 'file_search',\n description: 'Search files in vector stores',\n metadata: {\n ...toolData,\n },\n },\n 'file_search',\n )\n}\n\nexport { validateMaxNumResults }\n"],"mappings":";;AASA,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,8BAA8B,IAAI;CAInD,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,mBACL;EACE,MAAM;EACN,aAAa;EACb,UAAU,EACR,GAAG,SACL;CACF,GACA,aACF;AACF"}
|
|
@@ -7,10 +7,8 @@ export type ImageGenerationTool = ImageGenerationToolConfig;
|
|
|
7
7
|
declare const validatePartialImages: (value: number | undefined) => void;
|
|
8
8
|
/**
|
|
9
9
|
* Converts a standard Tool to OpenAI ImageGenerationTool format. Spread
|
|
10
|
-
* `metadata` first, then force `type: 'image_generation'` last
|
|
11
|
-
* `metadata.type`
|
|
12
|
-
* the dispatcher (which routed by `tool.name`) would emit a tool whose
|
|
13
|
-
* runtime `type` doesn't match `image_generation`.
|
|
10
|
+
* `metadata` first, then force `type: 'image_generation'` last so a stray
|
|
11
|
+
* `metadata.type` cannot shadow the wire discriminator.
|
|
14
12
|
*/
|
|
15
13
|
export declare function convertImageGenerationToolToAdapterFormat(tool: Tool): ImageGenerationToolConfig;
|
|
16
14
|
/**
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
+
import { getOpenAIProviderToolMetadata, openAIProviderTool } from "./openai-provider-tool.js";
|
|
1
2
|
//#region src/tools/image-generation-tool.ts
|
|
2
3
|
var validatePartialImages = (value) => {
|
|
3
4
|
if (value !== void 0 && (value < 0 || value > 3)) throw new Error("partial_images must be between 0 and 3");
|
|
4
5
|
};
|
|
5
6
|
/**
|
|
6
7
|
* Converts a standard Tool to OpenAI ImageGenerationTool format. Spread
|
|
7
|
-
* `metadata` first, then force `type: 'image_generation'` last
|
|
8
|
-
* `metadata.type`
|
|
9
|
-
* the dispatcher (which routed by `tool.name`) would emit a tool whose
|
|
10
|
-
* runtime `type` doesn't match `image_generation`.
|
|
8
|
+
* `metadata` first, then force `type: 'image_generation'` last so a stray
|
|
9
|
+
* `metadata.type` cannot shadow the wire discriminator.
|
|
11
10
|
*/
|
|
12
11
|
function convertImageGenerationToolToAdapterFormat(tool) {
|
|
13
12
|
return {
|
|
14
|
-
...tool
|
|
13
|
+
...getOpenAIProviderToolMetadata(tool),
|
|
15
14
|
type: "image_generation"
|
|
16
15
|
};
|
|
17
16
|
}
|
|
@@ -23,11 +22,11 @@ function convertImageGenerationToolToAdapterFormat(tool) {
|
|
|
23
22
|
*/
|
|
24
23
|
function imageGenerationTool(toolData) {
|
|
25
24
|
validatePartialImages(toolData.partial_images);
|
|
26
|
-
return {
|
|
25
|
+
return openAIProviderTool({
|
|
27
26
|
name: "image_generation",
|
|
28
27
|
description: "Generate images based on text descriptions",
|
|
29
28
|
metadata: { ...toolData }
|
|
30
|
-
};
|
|
29
|
+
}, "image_generation");
|
|
31
30
|
}
|
|
32
31
|
//#endregion
|
|
33
32
|
export { convertImageGenerationToolToAdapterFormat, imageGenerationTool, validatePartialImages };
|
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
{"version":3,"file":"image-generation-tool.js","names":[],"sources":["../../../src/tools/image-generation-tool.ts"],"sourcesContent":["import {\n getOpenAIProviderToolMetadata,\n openAIProviderTool,\n} from './openai-provider-tool'\nimport 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 so a stray\n * `metadata.type` cannot shadow the wire discriminator.\n */\nexport function convertImageGenerationToolToAdapterFormat(\n tool: Tool,\n): ImageGenerationToolConfig {\n const metadata = getOpenAIProviderToolMetadata(tool) as Omit<\n ImageGenerationToolConfig,\n 'type'\n >\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 openAIProviderTool(\n {\n name: 'image_generation',\n description: 'Generate images based on text descriptions',\n metadata: {\n ...toolData,\n },\n },\n 'image_generation',\n )\n}\n\nexport { validatePartialImages }\n"],"mappings":";;AAcA,IAAM,yBAAyB,UAA8B;CAC3D,IAAI,UAAU,KAAA,MAAc,QAAQ,KAAK,QAAQ,IAC/C,MAAM,IAAI,MAAM,wCAAwC;AAE5D;;;;;;AAOA,SAAgB,0CACd,MAC2B;CAK3B,OAAO;EACL,GALe,8BAA8B,IAK1C;EACH,MAAM;CACR;AACF;;;;;;;AAQA,SAAgB,oBACd,UACM;CACN,sBAAsB,SAAS,cAAc;CAC7C,OAAO,mBACL;EACE,MAAM;EACN,aAAa;EACb,UAAU,EACR,GAAG,SACL;CACF,GACA,kBACF;AACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { applyPatchTool, convertApplyPatchToolToAdapterFormat } from "./apply-patch-tool.js";
|
|
2
|
+
import { codeInterpreterTool, convertCodeInterpreterToolToAdapterFormat } from "./code-interpreter-tool.js";
|
|
3
|
+
import { computerUseTool, convertComputerUseToolToAdapterFormat } from "./computer-use-tool.js";
|
|
4
|
+
import { convertCustomToolToAdapterFormat, customTool } from "./custom-tool.js";
|
|
5
|
+
import { convertFileSearchToolToAdapterFormat, fileSearchTool, validateMaxNumResults } from "./file-search-tool.js";
|
|
6
|
+
import { convertFunctionToolToAdapterFormat } from "./function-tool.js";
|
|
7
|
+
import { convertImageGenerationToolToAdapterFormat, imageGenerationTool, validatePartialImages } from "./image-generation-tool.js";
|
|
8
|
+
import { convertLocalShellToolToAdapterFormat, localShellTool } from "./local-shell-tool.js";
|
|
9
|
+
import { convertMCPToolToAdapterFormat, mcpTool, validateMCPtool } from "./mcp-tool.js";
|
|
10
|
+
import { convertShellToolToAdapterFormat, shellTool } from "./shell-tool.js";
|
|
11
|
+
import { convertWebSearchPreviewToolToAdapterFormat, webSearchPreviewTool } from "./web-search-preview-tool.js";
|
|
12
|
+
import { convertWebSearchToolToAdapterFormat, webSearchTool } from "./web-search-tool.js";
|
|
13
|
+
import { convertToolsToProviderFormat } from "./tool-converter.js";
|
|
14
|
+
export { applyPatchTool, codeInterpreterTool, computerUseTool, convertApplyPatchToolToAdapterFormat, convertCodeInterpreterToolToAdapterFormat, convertComputerUseToolToAdapterFormat, convertCustomToolToAdapterFormat, convertFileSearchToolToAdapterFormat, convertFunctionToolToAdapterFormat, convertImageGenerationToolToAdapterFormat, convertLocalShellToolToAdapterFormat, convertMCPToolToAdapterFormat, convertShellToolToAdapterFormat, convertToolsToProviderFormat, convertWebSearchPreviewToolToAdapterFormat, convertWebSearchToolToAdapterFormat, customTool, fileSearchTool, imageGenerationTool, localShellTool, mcpTool, shellTool, validateMCPtool, validateMaxNumResults, validatePartialImages, webSearchPreviewTool, webSearchTool };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { openAIProviderTool } from "./openai-provider-tool.js";
|
|
1
2
|
//#region src/tools/local-shell-tool.ts
|
|
2
3
|
/**
|
|
3
4
|
* Converts a standard Tool to OpenAI LocalShellTool format
|
|
@@ -12,11 +13,11 @@ function convertLocalShellToolToAdapterFormat(_tool) {
|
|
|
12
13
|
* re-wrap this in their own package.
|
|
13
14
|
*/
|
|
14
15
|
function localShellTool() {
|
|
15
|
-
return {
|
|
16
|
+
return openAIProviderTool({
|
|
16
17
|
name: "local_shell",
|
|
17
18
|
description: "Execute local shell commands",
|
|
18
19
|
metadata: {}
|
|
19
|
-
};
|
|
20
|
+
}, "local_shell");
|
|
20
21
|
}
|
|
21
22
|
//#endregion
|
|
22
23
|
export { convertLocalShellToolToAdapterFormat, localShellTool };
|
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
{"version":3,"file":"local-shell-tool.js","names":[],"sources":["../../../src/tools/local-shell-tool.ts"],"sourcesContent":["import { openAIProviderTool } from './openai-provider-tool'\nimport 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 openAIProviderTool(\n {\n name: 'local_shell',\n description: 'Execute local shell commands',\n metadata: {},\n },\n 'local_shell',\n )\n}\n"],"mappings":";;;;;AAcA,SAAgB,qCACd,OACsB;CACtB,OAAO,EACL,MAAM,cACR;AACF;;;;;;;AAQA,SAAgB,iBAAuB;CACrC,OAAO,mBACL;EACE,MAAM;EACN,aAAa;EACb,UAAU,CAAC;CACb,GACA,aACF;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getOpenAIProviderToolMetadata, openAIProviderTool } from "./openai-provider-tool.js";
|
|
1
2
|
//#region src/tools/mcp-tool.ts
|
|
2
3
|
function validateMCPtool(tool) {
|
|
3
4
|
if (!tool.server_url && !tool.connector_id) throw new Error("Either server_url or connector_id must be provided.");
|
|
@@ -7,12 +8,12 @@ function validateMCPtool(tool) {
|
|
|
7
8
|
* Converts a standard Tool to OpenAI MCPTool format
|
|
8
9
|
*/
|
|
9
10
|
function convertMCPToolToAdapterFormat(tool) {
|
|
10
|
-
const
|
|
11
|
-
...tool
|
|
11
|
+
const convertedTool = {
|
|
12
|
+
...getOpenAIProviderToolMetadata(tool),
|
|
12
13
|
type: "mcp"
|
|
13
14
|
};
|
|
14
|
-
validateMCPtool(
|
|
15
|
-
return
|
|
15
|
+
validateMCPtool(convertedTool);
|
|
16
|
+
return convertedTool;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Creates a standard Tool from MCPTool parameters.
|
|
@@ -25,11 +26,11 @@ function mcpTool(toolData) {
|
|
|
25
26
|
...toolData,
|
|
26
27
|
type: "mcp"
|
|
27
28
|
});
|
|
28
|
-
return {
|
|
29
|
+
return openAIProviderTool({
|
|
29
30
|
name: "mcp",
|
|
30
31
|
description: toolData.server_description || "",
|
|
31
32
|
metadata: toolData
|
|
32
|
-
};
|
|
33
|
+
}, "mcp");
|
|
33
34
|
}
|
|
34
35
|
//#endregion
|
|
35
36
|
export { convertMCPToolToAdapterFormat, mcpTool, validateMCPtool };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-tool.js","names":[],"sources":["../../../src/tools/mcp-tool.ts"],"sourcesContent":["import type { Tool as SDKTool } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\ntype MCPToolConfig = SDKTool.Mcp\n\nexport type { MCPToolConfig }\n\n/** @deprecated Renamed to `MCPToolConfig`. Will be removed in a future release. */\nexport type MCPTool = MCPToolConfig\n\nexport function validateMCPtool(tool: MCPToolConfig) {\n if (!tool.server_url && !tool.connector_id) {\n throw new Error('Either server_url or connector_id must be provided.')\n }\n if (tool.connector_id && tool.server_url) {\n throw new Error('Only one of server_url or connector_id can be provided.')\n }\n}\n\n/**\n * Converts a standard Tool to OpenAI MCPTool format\n */\nexport function convertMCPToolToAdapterFormat(tool: Tool): MCPToolConfig {\n const metadata = tool
|
|
1
|
+
{"version":3,"file":"mcp-tool.js","names":[],"sources":["../../../src/tools/mcp-tool.ts"],"sourcesContent":["import {\n getOpenAIProviderToolMetadata,\n openAIProviderTool,\n} from './openai-provider-tool'\nimport type { Tool as SDKTool } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\ntype MCPToolConfig = SDKTool.Mcp\n\nexport type { MCPToolConfig }\n\n/** @deprecated Renamed to `MCPToolConfig`. Will be removed in a future release. */\nexport type MCPTool = MCPToolConfig\n\nexport function validateMCPtool(tool: MCPToolConfig) {\n if (!tool.server_url && !tool.connector_id) {\n throw new Error('Either server_url or connector_id must be provided.')\n }\n if (tool.connector_id && tool.server_url) {\n throw new Error('Only one of server_url or connector_id can be provided.')\n }\n}\n\n/**\n * Converts a standard Tool to OpenAI MCPTool format\n */\nexport function convertMCPToolToAdapterFormat(tool: Tool): MCPToolConfig {\n const metadata = getOpenAIProviderToolMetadata(tool) as Omit<\n MCPToolConfig,\n 'type'\n >\n\n const convertedTool: MCPToolConfig = {\n ...metadata,\n type: 'mcp',\n }\n\n validateMCPtool(convertedTool)\n return convertedTool\n}\n\n/**\n * Creates a standard Tool from MCPTool 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 mcpTool(toolData: Omit<MCPToolConfig, 'type'>): Tool {\n validateMCPtool({ ...toolData, type: 'mcp' })\n\n return openAIProviderTool(\n {\n name: 'mcp',\n description: toolData.server_description || '',\n metadata: toolData,\n },\n 'mcp',\n )\n}\n"],"mappings":";;AAcA,SAAgB,gBAAgB,MAAqB;CACnD,IAAI,CAAC,KAAK,cAAc,CAAC,KAAK,cAC5B,MAAM,IAAI,MAAM,qDAAqD;CAEvE,IAAI,KAAK,gBAAgB,KAAK,YAC5B,MAAM,IAAI,MAAM,yDAAyD;AAE7E;;;;AAKA,SAAgB,8BAA8B,MAA2B;CAMvE,MAAM,gBAA+B;EACnC,GANe,8BAA8B,IAM1C;EACH,MAAM;CACR;CAEA,gBAAgB,aAAa;CAC7B,OAAO;AACT;;;;;;;AAQA,SAAgB,QAAQ,UAA6C;CACnE,gBAAgB;EAAE,GAAG;EAAU,MAAM;CAAM,CAAC;CAE5C,OAAO,mBACL;EACE,MAAM;EACN,aAAa,SAAS,sBAAsB;EAC5C,UAAU;CACZ,GACA,KACF;AACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Tool } from '@tanstack/ai';
|
|
2
|
+
declare const OPENAI_PROVIDER_TOOL_KINDS: {
|
|
3
|
+
readonly apply_patch: "openai.apply_patch";
|
|
4
|
+
readonly code_interpreter: "openai.code_interpreter";
|
|
5
|
+
readonly computer_use: "openai.computer_use";
|
|
6
|
+
readonly custom: "openai.custom";
|
|
7
|
+
readonly file_search: "openai.file_search";
|
|
8
|
+
readonly image_generation: "openai.image_generation";
|
|
9
|
+
readonly local_shell: "openai.local_shell";
|
|
10
|
+
readonly mcp: "openai.mcp";
|
|
11
|
+
readonly shell: "openai.shell";
|
|
12
|
+
readonly web_search: "openai.web_search";
|
|
13
|
+
readonly web_search_preview: "openai.web_search_preview";
|
|
14
|
+
};
|
|
15
|
+
export type OpenAIProviderToolKind = keyof typeof OPENAI_PROVIDER_TOOL_KINDS;
|
|
16
|
+
export declare function openAIProviderTool(tool: Tool, toolKind: OpenAIProviderToolKind): Tool;
|
|
17
|
+
export declare function getOpenAIProviderToolKind(tool: Tool): OpenAIProviderToolKind | undefined;
|
|
18
|
+
/** Returns adapter metadata without the internal runtime discriminator. */
|
|
19
|
+
export declare function getOpenAIProviderToolMetadata(tool: Tool): Tool['metadata'];
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/tools/openai-provider-tool.ts
|
|
2
|
+
var OPENAI_PROVIDER_TOOL_KINDS = {
|
|
3
|
+
apply_patch: "openai.apply_patch",
|
|
4
|
+
code_interpreter: "openai.code_interpreter",
|
|
5
|
+
computer_use: "openai.computer_use",
|
|
6
|
+
custom: "openai.custom",
|
|
7
|
+
file_search: "openai.file_search",
|
|
8
|
+
image_generation: "openai.image_generation",
|
|
9
|
+
local_shell: "openai.local_shell",
|
|
10
|
+
mcp: "openai.mcp",
|
|
11
|
+
shell: "openai.shell",
|
|
12
|
+
web_search: "openai.web_search",
|
|
13
|
+
web_search_preview: "openai.web_search_preview"
|
|
14
|
+
};
|
|
15
|
+
function openAIProviderTool(tool, toolKind) {
|
|
16
|
+
return {
|
|
17
|
+
...tool,
|
|
18
|
+
metadata: {
|
|
19
|
+
...tool.metadata,
|
|
20
|
+
__kind: OPENAI_PROVIDER_TOOL_KINDS[toolKind]
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function getOpenAIProviderToolKind(tool) {
|
|
25
|
+
switch (tool.metadata?.["__kind"]) {
|
|
26
|
+
case "openai.apply_patch": return "apply_patch";
|
|
27
|
+
case "openai.code_interpreter": return "code_interpreter";
|
|
28
|
+
case "openai.computer_use": return "computer_use";
|
|
29
|
+
case "openai.custom": return "custom";
|
|
30
|
+
case "openai.file_search": return "file_search";
|
|
31
|
+
case "openai.image_generation": return "image_generation";
|
|
32
|
+
case "openai.local_shell": return "local_shell";
|
|
33
|
+
case "openai.mcp": return "mcp";
|
|
34
|
+
case "openai.shell": return "shell";
|
|
35
|
+
case "openai.web_search": return "web_search";
|
|
36
|
+
case "openai.web_search_preview": return "web_search_preview";
|
|
37
|
+
default: return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Returns adapter metadata without the internal runtime discriminator. */
|
|
41
|
+
function getOpenAIProviderToolMetadata(tool) {
|
|
42
|
+
if (!tool.metadata) return;
|
|
43
|
+
const { __kind: _kind, ...metadata } = tool.metadata;
|
|
44
|
+
return metadata;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { getOpenAIProviderToolKind, getOpenAIProviderToolMetadata, openAIProviderTool };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=openai-provider-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-provider-tool.js","names":[],"sources":["../../../src/tools/openai-provider-tool.ts"],"sourcesContent":["import type { Tool } from '@tanstack/ai'\n\nconst OPENAI_PROVIDER_TOOL_KINDS = {\n apply_patch: 'openai.apply_patch',\n code_interpreter: 'openai.code_interpreter',\n computer_use: 'openai.computer_use',\n custom: 'openai.custom',\n file_search: 'openai.file_search',\n image_generation: 'openai.image_generation',\n local_shell: 'openai.local_shell',\n mcp: 'openai.mcp',\n shell: 'openai.shell',\n web_search: 'openai.web_search',\n web_search_preview: 'openai.web_search_preview',\n} as const\n\nexport type OpenAIProviderToolKind = keyof typeof OPENAI_PROVIDER_TOOL_KINDS\n\nexport function openAIProviderTool(\n tool: Tool,\n toolKind: OpenAIProviderToolKind,\n): Tool {\n return {\n ...tool,\n metadata: {\n ...tool.metadata,\n __kind: OPENAI_PROVIDER_TOOL_KINDS[toolKind],\n },\n }\n}\n\nexport function getOpenAIProviderToolKind(\n tool: Tool,\n): OpenAIProviderToolKind | undefined {\n const toolKind = tool.metadata?.['__kind']\n switch (toolKind) {\n case 'openai.apply_patch':\n return 'apply_patch'\n case 'openai.code_interpreter':\n return 'code_interpreter'\n case 'openai.computer_use':\n return 'computer_use'\n case 'openai.custom':\n return 'custom'\n case 'openai.file_search':\n return 'file_search'\n case 'openai.image_generation':\n return 'image_generation'\n case 'openai.local_shell':\n return 'local_shell'\n case 'openai.mcp':\n return 'mcp'\n case 'openai.shell':\n return 'shell'\n case 'openai.web_search':\n return 'web_search'\n case 'openai.web_search_preview':\n return 'web_search_preview'\n default:\n return undefined\n }\n}\n\n/** Returns adapter metadata without the internal runtime discriminator. */\nexport function getOpenAIProviderToolMetadata(tool: Tool): Tool['metadata'] {\n if (!tool.metadata) {\n return undefined\n }\n const { __kind: _kind, ...metadata } = tool.metadata\n void _kind\n return metadata\n}\n"],"mappings":";AAEA,IAAM,6BAA6B;CACjC,aAAa;CACb,kBAAkB;CAClB,cAAc;CACd,QAAQ;CACR,aAAa;CACb,kBAAkB;CAClB,aAAa;CACb,KAAK;CACL,OAAO;CACP,YAAY;CACZ,oBAAoB;AACtB;AAIA,SAAgB,mBACd,MACA,UACM;CACN,OAAO;EACL,GAAG;EACH,UAAU;GACR,GAAG,KAAK;GACR,QAAQ,2BAA2B;EACrC;CACF;AACF;AAEA,SAAgB,0BACd,MACoC;CAEpC,QADiB,KAAK,WAAW,WACjC;EACE,KAAK,sBACH,OAAO;EACT,KAAK,2BACH,OAAO;EACT,KAAK,uBACH,OAAO;EACT,KAAK,iBACH,OAAO;EACT,KAAK,sBACH,OAAO;EACT,KAAK,2BACH,OAAO;EACT,KAAK,sBACH,OAAO;EACT,KAAK,cACH,OAAO;EACT,KAAK,gBACH,OAAO;EACT,KAAK,qBACH,OAAO;EACT,KAAK,6BACH,OAAO;EACT,SACE;CACJ;AACF;;AAGA,SAAgB,8BAA8B,MAA8B;CAC1E,IAAI,CAAC,KAAK,UACR;CAEF,MAAM,EAAE,QAAQ,OAAO,GAAG,aAAa,KAAK;CAE5C,OAAO;AACT"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { getOpenAIProviderToolMetadata, openAIProviderTool } from "./openai-provider-tool.js";
|
|
1
2
|
//#region src/tools/shell-tool.ts
|
|
2
3
|
/**
|
|
3
4
|
* Converts a standard Tool to OpenAI ShellTool format, preserving any
|
|
4
5
|
* `environment` (container config + skills) stored in metadata.
|
|
5
6
|
*/
|
|
6
7
|
function convertShellToolToAdapterFormat(tool) {
|
|
7
|
-
const metadata = tool
|
|
8
|
+
const metadata = getOpenAIProviderToolMetadata(tool) ?? {};
|
|
8
9
|
return {
|
|
9
10
|
type: "shell",
|
|
10
11
|
...metadata.environment !== void 0 && { environment: metadata.environment }
|
|
@@ -17,11 +18,11 @@ function convertShellToolToAdapterFormat(tool) {
|
|
|
17
18
|
* re-wrap this in their own package.
|
|
18
19
|
*/
|
|
19
20
|
function shellTool(config = {}) {
|
|
20
|
-
return {
|
|
21
|
+
return openAIProviderTool({
|
|
21
22
|
name: "shell",
|
|
22
23
|
description: "Execute shell commands",
|
|
23
24
|
metadata: { ...config.environment !== void 0 && { environment: config.environment } }
|
|
24
|
-
};
|
|
25
|
+
}, "shell");
|
|
25
26
|
}
|
|
26
27
|
//#endregion
|
|
27
28
|
export { convertShellToolToAdapterFormat, shellTool };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-tool.js","names":[],"sources":["../../../src/tools/shell-tool.ts"],"sourcesContent":["import type { FunctionShellTool as ShellToolConfig } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\nexport type { ShellToolConfig }\n\n/** @deprecated Renamed to `ShellToolConfig`. Will be removed in a future release. */\nexport type ShellTool = ShellToolConfig\n\n/**\n * Config accepted by {@link shellTool}. `environment` mirrors the OpenAI\n * Responses API shell tool environment (e.g. `container_auto` + `skills`).\n * Typed via indexed access so it tracks the installed SDK without naming the\n * union members directly.\n */\nexport interface ShellToolFactoryConfig {\n environment?: NonNullable<ShellToolConfig['environment']>\n}\n\n/**\n * Converts a standard Tool to OpenAI ShellTool format, preserving any\n * `environment` (container config + skills) stored in metadata.\n */\nexport function convertShellToolToAdapterFormat(tool: Tool): ShellToolConfig {\n const metadata = (tool
|
|
1
|
+
{"version":3,"file":"shell-tool.js","names":[],"sources":["../../../src/tools/shell-tool.ts"],"sourcesContent":["import {\n getOpenAIProviderToolMetadata,\n openAIProviderTool,\n} from './openai-provider-tool'\nimport type { FunctionShellTool as ShellToolConfig } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\nexport type { ShellToolConfig }\n\n/** @deprecated Renamed to `ShellToolConfig`. Will be removed in a future release. */\nexport type ShellTool = ShellToolConfig\n\n/**\n * Config accepted by {@link shellTool}. `environment` mirrors the OpenAI\n * Responses API shell tool environment (e.g. `container_auto` + `skills`).\n * Typed via indexed access so it tracks the installed SDK without naming the\n * union members directly.\n */\nexport interface ShellToolFactoryConfig {\n environment?: NonNullable<ShellToolConfig['environment']>\n}\n\n/**\n * Converts a standard Tool to OpenAI ShellTool format, preserving any\n * `environment` (container config + skills) stored in metadata.\n */\nexport function convertShellToolToAdapterFormat(tool: Tool): ShellToolConfig {\n const metadata = (getOpenAIProviderToolMetadata(tool) ??\n {}) as ShellToolFactoryConfig\n return {\n type: 'shell',\n ...(metadata.environment !== undefined && {\n environment: metadata.environment,\n }),\n }\n}\n\n/**\n * Creates a standard Tool from ShellTool 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 shellTool(config: ShellToolFactoryConfig = {}): Tool {\n return openAIProviderTool(\n {\n name: 'shell',\n description: 'Execute shell commands',\n metadata: {\n ...(config.environment !== undefined && {\n environment: config.environment,\n }),\n },\n },\n 'shell',\n )\n}\n"],"mappings":";;;;;;AA0BA,SAAgB,gCAAgC,MAA6B;CAC3E,MAAM,WAAY,8BAA8B,IAAI,KAClD,CAAC;CACH,OAAO;EACL,MAAM;EACN,GAAI,SAAS,gBAAgB,KAAA,KAAa,EACxC,aAAa,SAAS,YACxB;CACF;AACF;;;;;;;AAQA,SAAgB,UAAU,SAAiC,CAAC,GAAS;CACnE,OAAO,mBACL;EACE,MAAM;EACN,aAAa;EACb,UAAU,EACR,GAAI,OAAO,gBAAgB,KAAA,KAAa,EACtC,aAAa,OAAO,YACtB,EACF;CACF,GACA,OACF;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getOpenAIProviderToolKind } from "./openai-provider-tool.js";
|
|
1
2
|
import { convertApplyPatchToolToAdapterFormat } from "./apply-patch-tool.js";
|
|
2
3
|
import { convertCodeInterpreterToolToAdapterFormat } from "./code-interpreter-tool.js";
|
|
3
4
|
import { convertComputerUseToolToAdapterFormat } from "./computer-use-tool.js";
|
|
@@ -10,30 +11,19 @@ import { convertMCPToolToAdapterFormat } from "./mcp-tool.js";
|
|
|
10
11
|
import { convertShellToolToAdapterFormat } from "./shell-tool.js";
|
|
11
12
|
import { convertWebSearchPreviewToolToAdapterFormat } from "./web-search-preview-tool.js";
|
|
12
13
|
import { convertWebSearchToolToAdapterFormat } from "./web-search-tool.js";
|
|
14
|
+
import { assertUniqueToolNames } from "@tanstack/ai/adapter-internals";
|
|
13
15
|
//#region src/tools/tool-converter.ts
|
|
14
|
-
var SPECIAL_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
15
|
-
"apply_patch",
|
|
16
|
-
"code_interpreter",
|
|
17
|
-
"computer_use_preview",
|
|
18
|
-
"file_search",
|
|
19
|
-
"image_generation",
|
|
20
|
-
"local_shell",
|
|
21
|
-
"mcp",
|
|
22
|
-
"shell",
|
|
23
|
-
"web_search_preview",
|
|
24
|
-
"web_search",
|
|
25
|
-
"custom"
|
|
26
|
-
]);
|
|
27
16
|
/**
|
|
28
17
|
* Converts an array of standard Tools to OpenAI-specific format
|
|
29
18
|
*/
|
|
30
19
|
function convertToolsToProviderFormat(tools) {
|
|
20
|
+
assertUniqueToolNames(tools);
|
|
31
21
|
return tools.map((tool) => {
|
|
32
|
-
|
|
33
|
-
if (SPECIAL_TOOL_NAMES.has(toolName)) switch (toolName) {
|
|
22
|
+
switch (getOpenAIProviderToolKind(tool)) {
|
|
34
23
|
case "apply_patch": return convertApplyPatchToolToAdapterFormat(tool);
|
|
35
24
|
case "code_interpreter": return convertCodeInterpreterToolToAdapterFormat(tool);
|
|
36
|
-
case "
|
|
25
|
+
case "computer_use": return convertComputerUseToolToAdapterFormat(tool);
|
|
26
|
+
case "custom": return convertCustomToolToAdapterFormat(tool);
|
|
37
27
|
case "file_search": return convertFileSearchToolToAdapterFormat(tool);
|
|
38
28
|
case "image_generation": return convertImageGenerationToolToAdapterFormat(tool);
|
|
39
29
|
case "local_shell": return convertLocalShellToolToAdapterFormat(tool);
|
|
@@ -41,9 +31,8 @@ function convertToolsToProviderFormat(tools) {
|
|
|
41
31
|
case "shell": return convertShellToolToAdapterFormat(tool);
|
|
42
32
|
case "web_search_preview": return convertWebSearchPreviewToolToAdapterFormat(tool);
|
|
43
33
|
case "web_search": return convertWebSearchToolToAdapterFormat(tool);
|
|
44
|
-
case
|
|
34
|
+
case void 0: return convertFunctionToolToAdapterFormat(tool);
|
|
45
35
|
}
|
|
46
|
-
return convertFunctionToolToAdapterFormat(tool);
|
|
47
36
|
});
|
|
48
37
|
}
|
|
49
38
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-converter.js","names":[],"sources":["../../../src/tools/tool-converter.ts"],"sourcesContent":["import { convertApplyPatchToolToAdapterFormat } from './apply-patch-tool'\nimport { convertCodeInterpreterToolToAdapterFormat } from './code-interpreter-tool'\nimport { convertComputerUseToolToAdapterFormat } from './computer-use-tool'\nimport { convertCustomToolToAdapterFormat } from './custom-tool'\nimport { convertFileSearchToolToAdapterFormat } from './file-search-tool'\nimport { convertFunctionToolToAdapterFormat } from './function-tool'\nimport { convertImageGenerationToolToAdapterFormat } from './image-generation-tool'\nimport { convertLocalShellToolToAdapterFormat } from './local-shell-tool'\nimport { convertMCPToolToAdapterFormat } from './mcp-tool'\nimport { convertShellToolToAdapterFormat } from './shell-tool'\nimport { convertWebSearchPreviewToolToAdapterFormat } from './web-search-preview-tool'\nimport { convertWebSearchToolToAdapterFormat } from './web-search-tool'\nimport type { OpenAITool } from './index'\nimport
|
|
1
|
+
{"version":3,"file":"tool-converter.js","names":[],"sources":["../../../src/tools/tool-converter.ts"],"sourcesContent":["import { convertApplyPatchToolToAdapterFormat } from './apply-patch-tool'\nimport { convertCodeInterpreterToolToAdapterFormat } from './code-interpreter-tool'\nimport { convertComputerUseToolToAdapterFormat } from './computer-use-tool'\nimport { convertCustomToolToAdapterFormat } from './custom-tool'\nimport { convertFileSearchToolToAdapterFormat } from './file-search-tool'\nimport { convertFunctionToolToAdapterFormat } from './function-tool'\nimport { convertImageGenerationToolToAdapterFormat } from './image-generation-tool'\nimport { convertLocalShellToolToAdapterFormat } from './local-shell-tool'\nimport { convertMCPToolToAdapterFormat } from './mcp-tool'\nimport { getOpenAIProviderToolKind } from './openai-provider-tool'\nimport { convertShellToolToAdapterFormat } from './shell-tool'\nimport { convertWebSearchPreviewToolToAdapterFormat } from './web-search-preview-tool'\nimport { convertWebSearchToolToAdapterFormat } from './web-search-tool'\nimport type { OpenAITool } from './index'\nimport { assertUniqueToolNames } from '@tanstack/ai/adapter-internals'\nimport type { Tool } from '@tanstack/ai'\n\n/**\n * Converts an array of standard Tools to OpenAI-specific format\n */\nexport function convertToolsToProviderFormat(\n tools: Array<Tool>,\n): Array<OpenAITool> {\n assertUniqueToolNames(tools)\n return tools.map((tool) => {\n switch (getOpenAIProviderToolKind(tool)) {\n case 'apply_patch':\n return convertApplyPatchToolToAdapterFormat(tool)\n case 'code_interpreter':\n return convertCodeInterpreterToolToAdapterFormat(tool)\n case 'computer_use':\n return convertComputerUseToolToAdapterFormat(tool)\n case 'custom':\n return convertCustomToolToAdapterFormat(tool)\n case 'file_search':\n return convertFileSearchToolToAdapterFormat(tool)\n case 'image_generation':\n return convertImageGenerationToolToAdapterFormat(tool)\n case 'local_shell':\n return convertLocalShellToolToAdapterFormat(tool)\n case 'mcp':\n return convertMCPToolToAdapterFormat(tool)\n case 'shell':\n return convertShellToolToAdapterFormat(tool)\n case 'web_search_preview':\n return convertWebSearchPreviewToolToAdapterFormat(tool)\n case 'web_search':\n return convertWebSearchToolToAdapterFormat(tool)\n case undefined:\n return convertFunctionToolToAdapterFormat(tool)\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,SAAgB,6BACd,OACmB;CACnB,sBAAsB,KAAK;CAC3B,OAAO,MAAM,KAAK,SAAS;EACzB,QAAQ,0BAA0B,IAAI,GAAtC;GACE,KAAK,eACH,OAAO,qCAAqC,IAAI;GAClD,KAAK,oBACH,OAAO,0CAA0C,IAAI;GACvD,KAAK,gBACH,OAAO,sCAAsC,IAAI;GACnD,KAAK,UACH,OAAO,iCAAiC,IAAI;GAC9C,KAAK,eACH,OAAO,qCAAqC,IAAI;GAClD,KAAK,oBACH,OAAO,0CAA0C,IAAI;GACvD,KAAK,eACH,OAAO,qCAAqC,IAAI;GAClD,KAAK,OACH,OAAO,8BAA8B,IAAI;GAC3C,KAAK,SACH,OAAO,gCAAgC,IAAI;GAC7C,KAAK,sBACH,OAAO,2CAA2C,IAAI;GACxD,KAAK,cACH,OAAO,oCAAoC,IAAI;GACjD,KAAK,KAAA,GACH,OAAO,mCAAmC,IAAI;EAClD;CACF,CAAC;AACH"}
|
|
@@ -6,8 +6,7 @@ export type WebSearchPreviewTool = WebSearchPreviewToolConfig;
|
|
|
6
6
|
/**
|
|
7
7
|
* Converts a standard Tool to OpenAI WebSearchPreviewTool format. Force the
|
|
8
8
|
* literal `type: 'web_search_preview'` instead of trusting `metadata.type`,
|
|
9
|
-
*
|
|
10
|
-
* malformed payload while the dispatcher already routed by `tool.name`.
|
|
9
|
+
* so a missing or wrong metadata type cannot produce a malformed payload.
|
|
11
10
|
*/
|
|
12
11
|
export declare function convertWebSearchPreviewToolToAdapterFormat(tool: Tool): WebSearchPreviewToolConfig;
|
|
13
12
|
/**
|