@tanstack/openai-base 0.9.3 → 0.9.5
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.d.ts +116 -0
- package/dist/esm/adapters/chat-completions-text.js +967 -0
- package/dist/esm/adapters/chat-completions-text.js.map +1 -0
- package/dist/esm/adapters/chat-completions-tool-converter.d.ts +35 -0
- package/dist/esm/adapters/chat-completions-tool-converter.js +42 -0
- package/dist/esm/adapters/chat-completions-tool-converter.js.map +1 -0
- package/dist/esm/adapters/responses-text.d.ts +135 -0
- package/dist/esm/adapters/responses-text.js +1324 -0
- package/dist/esm/adapters/responses-text.js.map +1 -0
- package/dist/esm/adapters/responses-tool-converter.d.ts +42 -0
- package/dist/esm/adapters/responses-tool-converter.js +38 -0
- package/dist/esm/adapters/responses-tool-converter.js.map +1 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +59 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/tools/apply-patch-tool.d.ts +16 -0
- package/dist/esm/tools/apply-patch-tool.js +17 -0
- package/dist/esm/tools/apply-patch-tool.js.map +1 -0
- package/dist/esm/tools/code-interpreter-tool.d.ts +17 -0
- package/dist/esm/tools/code-interpreter-tool.js +22 -0
- package/dist/esm/tools/code-interpreter-tool.js.map +1 -0
- package/dist/esm/tools/computer-use-tool.d.ts +16 -0
- package/dist/esm/tools/computer-use-tool.js +23 -0
- package/dist/esm/tools/computer-use-tool.js.map +1 -0
- package/dist/esm/tools/custom-tool.d.ts +13 -0
- package/dist/esm/tools/custom-tool.js +25 -0
- package/dist/esm/tools/custom-tool.js.map +1 -0
- package/dist/esm/tools/file-search-tool.d.ts +18 -0
- package/dist/esm/tools/file-search-tool.js +35 -0
- package/dist/esm/tools/file-search-tool.js.map +1 -0
- package/dist/esm/tools/function-tool.d.ts +23 -0
- package/dist/esm/tools/function-tool.js +33 -0
- package/dist/esm/tools/function-tool.js.map +1 -0
- package/dist/esm/tools/image-generation-tool.d.ts +23 -0
- package/dist/esm/tools/image-generation-tool.js +28 -0
- package/dist/esm/tools/image-generation-tool.js.map +1 -0
- package/dist/esm/tools/index.d.ts +27 -0
- package/dist/esm/tools/local-shell-tool.d.ts +17 -0
- package/dist/esm/tools/local-shell-tool.js +17 -0
- package/dist/esm/tools/local-shell-tool.js.map +1 -0
- package/dist/esm/tools/mcp-tool.d.ts +18 -0
- package/dist/esm/tools/mcp-tool.js +31 -0
- package/dist/esm/tools/mcp-tool.js.map +1 -0
- package/dist/esm/tools/shell-tool.d.ts +26 -0
- package/dist/esm/tools/shell-tool.js +25 -0
- package/dist/esm/tools/shell-tool.js.map +1 -0
- package/dist/esm/tools/tool-choice.d.ts +17 -0
- package/dist/esm/tools/tool-converter.d.ts +6 -0
- package/dist/esm/tools/tool-converter.js +61 -0
- package/dist/esm/tools/tool-converter.js.map +1 -0
- package/dist/esm/tools/web-search-preview-tool.d.ts +19 -0
- package/dist/esm/tools/web-search-preview-tool.js +19 -0
- package/dist/esm/tools/web-search-preview-tool.js.map +1 -0
- package/dist/esm/tools/web-search-tool.d.ts +20 -0
- package/dist/esm/tools/web-search-tool.js +19 -0
- package/dist/esm/tools/web-search-tool.js.map +1 -0
- package/dist/esm/usage.d.ts +34 -0
- package/dist/esm/usage.js +83 -0
- package/dist/esm/usage.js.map +1 -0
- package/dist/esm/utils/request-options.d.ts +14 -0
- package/dist/esm/utils/request-options.js +11 -0
- package/dist/esm/utils/request-options.js.map +1 -0
- package/dist/esm/utils/schema-converter.d.ts +39 -0
- package/dist/esm/utils/schema-converter.js +145 -0
- package/dist/esm/utils/schema-converter.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const validateMaxNumResults = (maxNumResults) => {
|
|
2
|
+
if (maxNumResults !== void 0 && (maxNumResults < 1 || maxNumResults > 50)) {
|
|
3
|
+
throw new Error("max_num_results must be between 1 and 50.");
|
|
4
|
+
}
|
|
5
|
+
};
|
|
6
|
+
function convertFileSearchToolToAdapterFormat(tool) {
|
|
7
|
+
const metadata = tool.metadata;
|
|
8
|
+
return {
|
|
9
|
+
type: "file_search",
|
|
10
|
+
vector_store_ids: metadata.vector_store_ids,
|
|
11
|
+
...metadata.max_num_results !== void 0 && {
|
|
12
|
+
max_num_results: metadata.max_num_results
|
|
13
|
+
},
|
|
14
|
+
...metadata.ranking_options !== void 0 && {
|
|
15
|
+
ranking_options: metadata.ranking_options
|
|
16
|
+
},
|
|
17
|
+
...metadata.filters !== void 0 && { filters: metadata.filters }
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function fileSearchTool(toolData) {
|
|
21
|
+
validateMaxNumResults(toolData.max_num_results);
|
|
22
|
+
return {
|
|
23
|
+
name: "file_search",
|
|
24
|
+
description: "Search files in vector stores",
|
|
25
|
+
metadata: {
|
|
26
|
+
...toolData
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
convertFileSearchToolToAdapterFormat,
|
|
32
|
+
fileSearchTool,
|
|
33
|
+
validateMaxNumResults
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=file-search-tool.js.map
|
|
@@ -0,0 +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"],"names":[],"mappings":"AAKA,MAAM,wBAAwB,CAAC,kBAAsC;AACnE,MACE,kBAAkB,WACjB,gBAAgB,KAAK,gBAAgB,KACtC;AACA,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AACF;AAQO,SAAS,qCACd,MACsB;AACtB,QAAM,WAAW,KAAK;AAItB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,kBAAkB,SAAS;AAAA,IAC3B,GAAI,SAAS,oBAAoB,UAAa;AAAA,MAC5C,iBAAiB,SAAS;AAAA,IAAA;AAAA,IAE5B,GAAI,SAAS,oBAAoB,UAAa;AAAA,MAC5C,iBAAiB,SAAS;AAAA,IAAA;AAAA,IAE5B,GAAI,SAAS,YAAY,UAAa,EAAE,SAAS,SAAS,QAAA;AAAA,EAAQ;AAEtE;AAQO,SAAS,eAAe,UAAsC;AACnE,wBAAsB,SAAS,eAAe;AAC9C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,MACR,GAAG;AAAA,IAAA;AAAA,EACL;AAEJ;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FunctionTool as FunctionToolConfig } from 'openai/resources/responses/responses';
|
|
2
|
+
import { Tool } from '@tanstack/ai';
|
|
3
|
+
export type { FunctionToolConfig };
|
|
4
|
+
/** @deprecated Renamed to `FunctionToolConfig`. Will be removed in a future release. */
|
|
5
|
+
export type FunctionTool = FunctionToolConfig;
|
|
6
|
+
/**
|
|
7
|
+
* Converts a standard Tool to OpenAI FunctionTool format.
|
|
8
|
+
*
|
|
9
|
+
* Tool schemas are already converted to JSON Schema in the ai layer.
|
|
10
|
+
* We apply OpenAI-specific transformations for strict mode:
|
|
11
|
+
* - All properties in required array
|
|
12
|
+
* - Optional fields made nullable
|
|
13
|
+
* - additionalProperties: false
|
|
14
|
+
*
|
|
15
|
+
* This enables strict mode for all tools automatically.
|
|
16
|
+
*
|
|
17
|
+
* Some tool schemas (e.g. MCP server tools that use `oneOf`, `$ref`, or
|
|
18
|
+
* `$defs`) cannot be expressed under OpenAI's strict Structured Outputs
|
|
19
|
+
* subset. For those we fall back to a non-strict tool definition — stripping
|
|
20
|
+
* only the formats OpenAI rejects — so the tool is still usable instead of
|
|
21
|
+
* failing the request with a 400 "Invalid schema" error.
|
|
22
|
+
*/
|
|
23
|
+
export declare function convertFunctionToolToAdapterFormat(tool: Tool): FunctionToolConfig;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isStrictModeCompatible, stripUnsupportedFormats, makeStructuredOutputCompatible } from "../utils/schema-converter.js";
|
|
2
|
+
function convertFunctionToolToAdapterFormat(tool) {
|
|
3
|
+
const inputSchema = tool.inputSchema ?? {
|
|
4
|
+
type: "object",
|
|
5
|
+
properties: {},
|
|
6
|
+
required: []
|
|
7
|
+
};
|
|
8
|
+
if (!isStrictModeCompatible(inputSchema)) {
|
|
9
|
+
return {
|
|
10
|
+
type: "function",
|
|
11
|
+
name: tool.name,
|
|
12
|
+
description: tool.description,
|
|
13
|
+
parameters: stripUnsupportedFormats(inputSchema),
|
|
14
|
+
strict: false
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const jsonSchema = makeStructuredOutputCompatible(
|
|
18
|
+
inputSchema,
|
|
19
|
+
inputSchema.required || []
|
|
20
|
+
);
|
|
21
|
+
jsonSchema.additionalProperties = false;
|
|
22
|
+
return {
|
|
23
|
+
type: "function",
|
|
24
|
+
name: tool.name,
|
|
25
|
+
description: tool.description,
|
|
26
|
+
parameters: jsonSchema,
|
|
27
|
+
strict: true
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
convertFunctionToolToAdapterFormat
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=function-tool.js.map
|
|
@@ -0,0 +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"],"names":[],"mappings":";AA8BO,SAAS,mCACd,MACoB;AACpB,QAAM,cAAe,KAAK,eAAe;AAAA,IACvC,MAAM;AAAA,IACN,YAAY,CAAA;AAAA,IACZ,UAAU,CAAA;AAAA,EAAC;AAGb,MAAI,CAAC,uBAAuB,WAAW,GAAG;AACxC,WAAO;AAAA,MACL,MAAM;AAAA,MACN,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB,YAAY,wBAAwB,WAAW;AAAA,MAC/C,QAAQ;AAAA,IAAA;AAAA,EAEZ;AAEA,QAAM,aAAa;AAAA,IACjB;AAAA,IACA,YAAY,YAAY,CAAA;AAAA,EAAC;AAG3B,aAAW,uBAAuB;AAElC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,KAAK;AAAA,IACX,aAAa,KAAK;AAAA,IAClB,YAAY;AAAA,IACZ,QAAQ;AAAA,EAAA;AAEZ;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Tool as SDKTool } from 'openai/resources/responses/responses';
|
|
2
|
+
import { Tool } from '@tanstack/ai';
|
|
3
|
+
type ImageGenerationToolConfig = SDKTool.ImageGeneration;
|
|
4
|
+
export type { ImageGenerationToolConfig };
|
|
5
|
+
/** @deprecated Renamed to `ImageGenerationToolConfig`. Will be removed in a future release. */
|
|
6
|
+
export type ImageGenerationTool = ImageGenerationToolConfig;
|
|
7
|
+
declare const validatePartialImages: (value: number | undefined) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Converts a standard Tool to OpenAI ImageGenerationTool format. Spread
|
|
10
|
+
* `metadata` first, then force `type: 'image_generation'` last — otherwise a
|
|
11
|
+
* `metadata.type` snuck in by a hand-built tool would shadow the literal and
|
|
12
|
+
* the dispatcher (which routed by `tool.name`) would emit a tool whose
|
|
13
|
+
* runtime `type` doesn't match `image_generation`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function convertImageGenerationToolToAdapterFormat(tool: Tool): ImageGenerationToolConfig;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a standard Tool from ImageGenerationTool parameters.
|
|
18
|
+
*
|
|
19
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
20
|
+
* re-wrap this in their own package.
|
|
21
|
+
*/
|
|
22
|
+
export declare function imageGenerationTool(toolData: Omit<ImageGenerationToolConfig, 'type'>): Tool;
|
|
23
|
+
export { validatePartialImages };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const validatePartialImages = (value) => {
|
|
2
|
+
if (value !== void 0 && (value < 0 || value > 3)) {
|
|
3
|
+
throw new Error("partial_images must be between 0 and 3");
|
|
4
|
+
}
|
|
5
|
+
};
|
|
6
|
+
function convertImageGenerationToolToAdapterFormat(tool) {
|
|
7
|
+
const metadata = tool.metadata;
|
|
8
|
+
return {
|
|
9
|
+
...metadata,
|
|
10
|
+
type: "image_generation"
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function imageGenerationTool(toolData) {
|
|
14
|
+
validatePartialImages(toolData.partial_images);
|
|
15
|
+
return {
|
|
16
|
+
name: "image_generation",
|
|
17
|
+
description: "Generate images based on text descriptions",
|
|
18
|
+
metadata: {
|
|
19
|
+
...toolData
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
convertImageGenerationToolToAdapterFormat,
|
|
25
|
+
imageGenerationTool,
|
|
26
|
+
validatePartialImages
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=image-generation-tool.js.map
|
|
@@ -0,0 +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"],"names":[],"mappings":"AAUA,MAAM,wBAAwB,CAAC,UAA8B;AAC3D,MAAI,UAAU,WAAc,QAAQ,KAAK,QAAQ,IAAI;AACnD,UAAM,IAAI,MAAM,wCAAwC;AAAA,EAC1D;AACF;AASO,SAAS,0CACd,MAC2B;AAC3B,QAAM,WAAW,KAAK;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM;AAAA,EAAA;AAEV;AAQO,SAAS,oBACd,UACM;AACN,wBAAsB,SAAS,cAAc;AAC7C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,MACR,GAAG;AAAA,IAAA;AAAA,EACL;AAEJ;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ApplyPatchToolConfig } from './apply-patch-tool.js';
|
|
2
|
+
import { CodeInterpreterToolConfig } from './code-interpreter-tool.js';
|
|
3
|
+
import { ComputerUseToolConfig } from './computer-use-tool.js';
|
|
4
|
+
import { CustomToolConfig } from './custom-tool.js';
|
|
5
|
+
import { FileSearchToolConfig } from './file-search-tool.js';
|
|
6
|
+
import { FunctionToolConfig } from './function-tool.js';
|
|
7
|
+
import { ImageGenerationToolConfig } from './image-generation-tool.js';
|
|
8
|
+
import { LocalShellToolConfig } from './local-shell-tool.js';
|
|
9
|
+
import { MCPToolConfig } from './mcp-tool.js';
|
|
10
|
+
import { ShellToolConfig } from './shell-tool.js';
|
|
11
|
+
import { WebSearchPreviewToolConfig } from './web-search-preview-tool.js';
|
|
12
|
+
import { WebSearchToolConfig } from './web-search-tool.js';
|
|
13
|
+
export type OpenAITool = ApplyPatchToolConfig | CodeInterpreterToolConfig | ComputerUseToolConfig | CustomToolConfig | FileSearchToolConfig | FunctionToolConfig | ImageGenerationToolConfig | LocalShellToolConfig | MCPToolConfig | ShellToolConfig | WebSearchPreviewToolConfig | WebSearchToolConfig;
|
|
14
|
+
export * from './apply-patch-tool.js';
|
|
15
|
+
export * from './code-interpreter-tool.js';
|
|
16
|
+
export * from './computer-use-tool.js';
|
|
17
|
+
export * from './custom-tool.js';
|
|
18
|
+
export * from './file-search-tool.js';
|
|
19
|
+
export * from './function-tool.js';
|
|
20
|
+
export * from './image-generation-tool.js';
|
|
21
|
+
export * from './local-shell-tool.js';
|
|
22
|
+
export * from './mcp-tool.js';
|
|
23
|
+
export * from './shell-tool.js';
|
|
24
|
+
export type * from './tool-choice.js';
|
|
25
|
+
export * from './tool-converter.js';
|
|
26
|
+
export * from './web-search-preview-tool.js';
|
|
27
|
+
export * from './web-search-tool.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Tool as SDKTool } from 'openai/resources/responses/responses';
|
|
2
|
+
import { Tool } from '@tanstack/ai';
|
|
3
|
+
type LocalShellToolConfig = SDKTool.LocalShell;
|
|
4
|
+
export type { LocalShellToolConfig };
|
|
5
|
+
/** @deprecated Renamed to `LocalShellToolConfig`. Will be removed in a future release. */
|
|
6
|
+
export type LocalShellTool = LocalShellToolConfig;
|
|
7
|
+
/**
|
|
8
|
+
* Converts a standard Tool to OpenAI LocalShellTool format
|
|
9
|
+
*/
|
|
10
|
+
export declare function convertLocalShellToolToAdapterFormat(_tool: Tool): LocalShellToolConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a standard Tool from LocalShellTool parameters.
|
|
13
|
+
*
|
|
14
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
15
|
+
* re-wrap this in their own package.
|
|
16
|
+
*/
|
|
17
|
+
export declare function localShellTool(): Tool;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function convertLocalShellToolToAdapterFormat(_tool) {
|
|
2
|
+
return {
|
|
3
|
+
type: "local_shell"
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
function localShellTool() {
|
|
7
|
+
return {
|
|
8
|
+
name: "local_shell",
|
|
9
|
+
description: "Execute local shell commands",
|
|
10
|
+
metadata: {}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
convertLocalShellToolToAdapterFormat,
|
|
15
|
+
localShellTool
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=local-shell-tool.js.map
|
|
@@ -0,0 +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"],"names":[],"mappings":"AAaO,SAAS,qCACd,OACsB;AACtB,SAAO;AAAA,IACL,MAAM;AAAA,EAAA;AAEV;AAQO,SAAS,iBAAuB;AACrC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU,CAAA;AAAA,EAAC;AAEf;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Tool as SDKTool } from 'openai/resources/responses/responses';
|
|
2
|
+
import { Tool } from '@tanstack/ai';
|
|
3
|
+
type MCPToolConfig = SDKTool.Mcp;
|
|
4
|
+
export type { MCPToolConfig };
|
|
5
|
+
/** @deprecated Renamed to `MCPToolConfig`. Will be removed in a future release. */
|
|
6
|
+
export type MCPTool = MCPToolConfig;
|
|
7
|
+
export declare function validateMCPtool(tool: MCPToolConfig): void;
|
|
8
|
+
/**
|
|
9
|
+
* Converts a standard Tool to OpenAI MCPTool format
|
|
10
|
+
*/
|
|
11
|
+
export declare function convertMCPToolToAdapterFormat(tool: Tool): MCPToolConfig;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a standard Tool from MCPTool parameters.
|
|
14
|
+
*
|
|
15
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
16
|
+
* re-wrap this in their own package.
|
|
17
|
+
*/
|
|
18
|
+
export declare function mcpTool(toolData: Omit<MCPToolConfig, 'type'>): Tool;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function validateMCPtool(tool) {
|
|
2
|
+
if (!tool.server_url && !tool.connector_id) {
|
|
3
|
+
throw new Error("Either server_url or connector_id must be provided.");
|
|
4
|
+
}
|
|
5
|
+
if (tool.connector_id && tool.server_url) {
|
|
6
|
+
throw new Error("Only one of server_url or connector_id can be provided.");
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function convertMCPToolToAdapterFormat(tool) {
|
|
10
|
+
const metadata = tool.metadata;
|
|
11
|
+
const mcpTool2 = {
|
|
12
|
+
...metadata,
|
|
13
|
+
type: "mcp"
|
|
14
|
+
};
|
|
15
|
+
validateMCPtool(mcpTool2);
|
|
16
|
+
return mcpTool2;
|
|
17
|
+
}
|
|
18
|
+
function mcpTool(toolData) {
|
|
19
|
+
validateMCPtool({ ...toolData });
|
|
20
|
+
return {
|
|
21
|
+
name: "mcp",
|
|
22
|
+
description: toolData.server_description || "",
|
|
23
|
+
metadata: toolData
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
convertMCPToolToAdapterFormat,
|
|
28
|
+
mcpTool,
|
|
29
|
+
validateMCPtool
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=mcp-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tool.js","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.metadata as Omit<MCPToolConfig, 'type'>\n\n const mcpTool: MCPToolConfig = {\n ...metadata,\n type: 'mcp',\n }\n\n validateMCPtool(mcpTool)\n return mcpTool\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 {\n name: 'mcp',\n description: toolData.server_description || '',\n metadata: toolData,\n }\n}\n"],"names":["mcpTool"],"mappings":"AAUO,SAAS,gBAAgB,MAAqB;AACnD,MAAI,CAAC,KAAK,cAAc,CAAC,KAAK,cAAc;AAC1C,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACA,MAAI,KAAK,gBAAgB,KAAK,YAAY;AACxC,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC3E;AACF;AAKO,SAAS,8BAA8B,MAA2B;AACvE,QAAM,WAAW,KAAK;AAEtB,QAAMA,WAAyB;AAAA,IAC7B,GAAG;AAAA,IACH,MAAM;AAAA,EAAA;AAGR,kBAAgBA,QAAO;AACvB,SAAOA;AACT;AAQO,SAAS,QAAQ,UAA6C;AACnE,kBAAgB,EAAE,GAAG,SAAsB,CAAC;AAE5C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa,SAAS,sBAAsB;AAAA,IAC5C,UAAU;AAAA,EAAA;AAEd;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FunctionShellTool as ShellToolConfig } from 'openai/resources/responses/responses';
|
|
2
|
+
import { Tool } from '@tanstack/ai';
|
|
3
|
+
export type { ShellToolConfig };
|
|
4
|
+
/** @deprecated Renamed to `ShellToolConfig`. Will be removed in a future release. */
|
|
5
|
+
export type ShellTool = ShellToolConfig;
|
|
6
|
+
/**
|
|
7
|
+
* Config accepted by {@link shellTool}. `environment` mirrors the OpenAI
|
|
8
|
+
* Responses API shell tool environment (e.g. `container_auto` + `skills`).
|
|
9
|
+
* Typed via indexed access so it tracks the installed SDK without naming the
|
|
10
|
+
* union members directly.
|
|
11
|
+
*/
|
|
12
|
+
export interface ShellToolFactoryConfig {
|
|
13
|
+
environment?: NonNullable<ShellToolConfig['environment']>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Converts a standard Tool to OpenAI ShellTool format, preserving any
|
|
17
|
+
* `environment` (container config + skills) stored in metadata.
|
|
18
|
+
*/
|
|
19
|
+
export declare function convertShellToolToAdapterFormat(tool: Tool): ShellToolConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a standard Tool from ShellTool parameters.
|
|
22
|
+
*
|
|
23
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
24
|
+
* re-wrap this in their own package.
|
|
25
|
+
*/
|
|
26
|
+
export declare function shellTool(config?: ShellToolFactoryConfig): Tool;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function convertShellToolToAdapterFormat(tool) {
|
|
2
|
+
const metadata = tool.metadata ?? {};
|
|
3
|
+
return {
|
|
4
|
+
type: "shell",
|
|
5
|
+
...metadata.environment !== void 0 && {
|
|
6
|
+
environment: metadata.environment
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function shellTool(config = {}) {
|
|
11
|
+
return {
|
|
12
|
+
name: "shell",
|
|
13
|
+
description: "Execute shell commands",
|
|
14
|
+
metadata: {
|
|
15
|
+
...config.environment !== void 0 && {
|
|
16
|
+
environment: config.environment
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
convertShellToolToAdapterFormat,
|
|
23
|
+
shellTool
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=shell-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-tool.js","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.metadata ?? {}) 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 {\n name: 'shell',\n description: 'Execute shell commands',\n metadata: {\n ...(config.environment !== undefined && {\n environment: config.environment,\n }),\n },\n }\n}\n"],"names":[],"mappings":"AAsBO,SAAS,gCAAgC,MAA6B;AAC3E,QAAM,WAAY,KAAK,YAAY,CAAA;AACnC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,GAAI,SAAS,gBAAgB,UAAa;AAAA,MACxC,aAAa,SAAS;AAAA,IAAA;AAAA,EACxB;AAEJ;AAQO,SAAS,UAAU,SAAiC,IAAU;AACnE,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,MACR,GAAI,OAAO,gBAAgB,UAAa;AAAA,QACtC,aAAa,OAAO;AAAA,MAAA;AAAA,IACtB;AAAA,EACF;AAEJ;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface MCPToolChoice {
|
|
2
|
+
type: 'mcp';
|
|
3
|
+
server_label: string;
|
|
4
|
+
}
|
|
5
|
+
interface FunctionToolChoice {
|
|
6
|
+
type: 'function';
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
interface CustomToolChoice {
|
|
10
|
+
type: 'custom';
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
interface HostedToolChoice {
|
|
14
|
+
type: 'file_search' | 'web_search_preview' | 'computer_use_preview' | 'code_interpreter' | 'image_generation' | 'shell' | 'apply_patch';
|
|
15
|
+
}
|
|
16
|
+
export type ToolChoice = MCPToolChoice | FunctionToolChoice | CustomToolChoice | HostedToolChoice;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { convertApplyPatchToolToAdapterFormat } from "./apply-patch-tool.js";
|
|
2
|
+
import { convertCodeInterpreterToolToAdapterFormat } from "./code-interpreter-tool.js";
|
|
3
|
+
import { convertComputerUseToolToAdapterFormat } from "./computer-use-tool.js";
|
|
4
|
+
import { convertCustomToolToAdapterFormat } from "./custom-tool.js";
|
|
5
|
+
import { convertFileSearchToolToAdapterFormat } from "./file-search-tool.js";
|
|
6
|
+
import { convertFunctionToolToAdapterFormat } from "./function-tool.js";
|
|
7
|
+
import { convertImageGenerationToolToAdapterFormat } from "./image-generation-tool.js";
|
|
8
|
+
import { convertLocalShellToolToAdapterFormat } from "./local-shell-tool.js";
|
|
9
|
+
import { convertMCPToolToAdapterFormat } from "./mcp-tool.js";
|
|
10
|
+
import { convertShellToolToAdapterFormat } from "./shell-tool.js";
|
|
11
|
+
import { convertWebSearchPreviewToolToAdapterFormat } from "./web-search-preview-tool.js";
|
|
12
|
+
import { convertWebSearchToolToAdapterFormat } from "./web-search-tool.js";
|
|
13
|
+
const SPECIAL_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
14
|
+
"apply_patch",
|
|
15
|
+
"code_interpreter",
|
|
16
|
+
"computer_use_preview",
|
|
17
|
+
"file_search",
|
|
18
|
+
"image_generation",
|
|
19
|
+
"local_shell",
|
|
20
|
+
"mcp",
|
|
21
|
+
"shell",
|
|
22
|
+
"web_search_preview",
|
|
23
|
+
"web_search",
|
|
24
|
+
"custom"
|
|
25
|
+
]);
|
|
26
|
+
function convertToolsToProviderFormat(tools) {
|
|
27
|
+
return tools.map((tool) => {
|
|
28
|
+
const toolName = tool.name;
|
|
29
|
+
if (SPECIAL_TOOL_NAMES.has(toolName)) {
|
|
30
|
+
switch (toolName) {
|
|
31
|
+
case "apply_patch":
|
|
32
|
+
return convertApplyPatchToolToAdapterFormat();
|
|
33
|
+
case "code_interpreter":
|
|
34
|
+
return convertCodeInterpreterToolToAdapterFormat(tool);
|
|
35
|
+
case "computer_use_preview":
|
|
36
|
+
return convertComputerUseToolToAdapterFormat(tool);
|
|
37
|
+
case "file_search":
|
|
38
|
+
return convertFileSearchToolToAdapterFormat(tool);
|
|
39
|
+
case "image_generation":
|
|
40
|
+
return convertImageGenerationToolToAdapterFormat(tool);
|
|
41
|
+
case "local_shell":
|
|
42
|
+
return convertLocalShellToolToAdapterFormat();
|
|
43
|
+
case "mcp":
|
|
44
|
+
return convertMCPToolToAdapterFormat(tool);
|
|
45
|
+
case "shell":
|
|
46
|
+
return convertShellToolToAdapterFormat(tool);
|
|
47
|
+
case "web_search_preview":
|
|
48
|
+
return convertWebSearchPreviewToolToAdapterFormat(tool);
|
|
49
|
+
case "web_search":
|
|
50
|
+
return convertWebSearchToolToAdapterFormat(tool);
|
|
51
|
+
case "custom":
|
|
52
|
+
return convertCustomToolToAdapterFormat(tool);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return convertFunctionToolToAdapterFormat(tool);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
convertToolsToProviderFormat
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=tool-converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-converter.js","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 type { Tool } from '@tanstack/ai'\n\nconst SPECIAL_TOOL_NAMES = new Set([\n 'apply_patch',\n 'code_interpreter',\n 'computer_use_preview',\n 'file_search',\n 'image_generation',\n 'local_shell',\n 'mcp',\n 'shell',\n 'web_search_preview',\n 'web_search',\n 'custom',\n])\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 return tools.map((tool) => {\n const toolName = tool.name\n\n if (SPECIAL_TOOL_NAMES.has(toolName)) {\n switch (toolName) {\n case 'apply_patch':\n return convertApplyPatchToolToAdapterFormat(tool)\n case 'code_interpreter':\n return convertCodeInterpreterToolToAdapterFormat(tool)\n case 'computer_use_preview':\n return convertComputerUseToolToAdapterFormat(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 'custom':\n return convertCustomToolToAdapterFormat(tool)\n }\n }\n\n return convertFunctionToolToAdapterFormat(tool)\n })\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAeA,MAAM,yCAAyB,IAAI;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAKM,SAAS,6BACd,OACmB;AACnB,SAAO,MAAM,IAAI,CAAC,SAAS;AACzB,UAAM,WAAW,KAAK;AAEtB,QAAI,mBAAmB,IAAI,QAAQ,GAAG;AACpC,cAAQ,UAAA;AAAA,QACN,KAAK;AACH,iBAAO,qCAAyC;AAAA,QAClD,KAAK;AACH,iBAAO,0CAA0C,IAAI;AAAA,QACvD,KAAK;AACH,iBAAO,sCAAsC,IAAI;AAAA,QACnD,KAAK;AACH,iBAAO,qCAAqC,IAAI;AAAA,QAClD,KAAK;AACH,iBAAO,0CAA0C,IAAI;AAAA,QACvD,KAAK;AACH,iBAAO,qCAAyC;AAAA,QAClD,KAAK;AACH,iBAAO,8BAA8B,IAAI;AAAA,QAC3C,KAAK;AACH,iBAAO,gCAAgC,IAAI;AAAA,QAC7C,KAAK;AACH,iBAAO,2CAA2C,IAAI;AAAA,QACxD,KAAK;AACH,iBAAO,oCAAoC,IAAI;AAAA,QACjD,KAAK;AACH,iBAAO,iCAAiC,IAAI;AAAA,MAAA;AAAA,IAElD;AAEA,WAAO,mCAAmC,IAAI;AAAA,EAChD,CAAC;AACH;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WebSearchPreviewTool as WebSearchPreviewToolConfig } from 'openai/resources/responses/responses';
|
|
2
|
+
import { Tool } from '@tanstack/ai';
|
|
3
|
+
export type { WebSearchPreviewToolConfig };
|
|
4
|
+
/** @deprecated Renamed to `WebSearchPreviewToolConfig`. Will be removed in a future release. */
|
|
5
|
+
export type WebSearchPreviewTool = WebSearchPreviewToolConfig;
|
|
6
|
+
/**
|
|
7
|
+
* Converts a standard Tool to OpenAI WebSearchPreviewTool format. Force the
|
|
8
|
+
* literal `type: 'web_search_preview'` instead of trusting `metadata.type`,
|
|
9
|
+
* since a hand-authored tool with a missing or wrong `type` would emit a
|
|
10
|
+
* malformed payload while the dispatcher already routed by `tool.name`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function convertWebSearchPreviewToolToAdapterFormat(tool: Tool): WebSearchPreviewToolConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a standard Tool from WebSearchPreviewTool parameters.
|
|
15
|
+
*
|
|
16
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
17
|
+
* re-wrap this in their own package.
|
|
18
|
+
*/
|
|
19
|
+
export declare function webSearchPreviewTool(toolData: WebSearchPreviewToolConfig): Tool;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function convertWebSearchPreviewToolToAdapterFormat(tool) {
|
|
2
|
+
const metadata = tool.metadata;
|
|
3
|
+
return {
|
|
4
|
+
...metadata,
|
|
5
|
+
type: "web_search_preview"
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function webSearchPreviewTool(toolData) {
|
|
9
|
+
return {
|
|
10
|
+
name: "web_search_preview",
|
|
11
|
+
description: "Search the web (preview version)",
|
|
12
|
+
metadata: toolData
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
convertWebSearchPreviewToolToAdapterFormat,
|
|
17
|
+
webSearchPreviewTool
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=web-search-preview-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search-preview-tool.js","sources":["../../../src/tools/web-search-preview-tool.ts"],"sourcesContent":["import type { WebSearchPreviewTool as WebSearchPreviewToolConfig } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\nexport type { WebSearchPreviewToolConfig }\n\n/** @deprecated Renamed to `WebSearchPreviewToolConfig`. Will be removed in a future release. */\nexport type WebSearchPreviewTool = WebSearchPreviewToolConfig\n\n/**\n * Converts a standard Tool to OpenAI WebSearchPreviewTool format. Force the\n * literal `type: 'web_search_preview'` instead of trusting `metadata.type`,\n * since a hand-authored tool with a missing or wrong `type` would emit a\n * malformed payload while the dispatcher already routed by `tool.name`.\n */\nexport function convertWebSearchPreviewToolToAdapterFormat(\n tool: Tool,\n): WebSearchPreviewToolConfig {\n const metadata = tool.metadata as Omit<WebSearchPreviewToolConfig, 'type'>\n return {\n ...metadata,\n type: 'web_search_preview',\n }\n}\n\n/**\n * Creates a standard Tool from WebSearchPreviewTool 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 webSearchPreviewTool(\n toolData: WebSearchPreviewToolConfig,\n): Tool {\n return {\n name: 'web_search_preview',\n description: 'Search the web (preview version)',\n metadata: toolData,\n }\n}\n"],"names":[],"mappings":"AAcO,SAAS,2CACd,MAC4B;AAC5B,QAAM,WAAW,KAAK;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM;AAAA,EAAA;AAEV;AAQO,SAAS,qBACd,UACM;AACN,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EAAA;AAEd;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WebSearchTool as WebSearchToolConfig } from 'openai/resources/responses/responses';
|
|
2
|
+
import { Tool } from '@tanstack/ai';
|
|
3
|
+
export type { WebSearchToolConfig };
|
|
4
|
+
/** @deprecated Renamed to `WebSearchToolConfig`. Will be removed in a future release. */
|
|
5
|
+
export type WebSearchTool = WebSearchToolConfig;
|
|
6
|
+
/**
|
|
7
|
+
* Converts a standard Tool to OpenAI WebSearchTool format. Spread `metadata`
|
|
8
|
+
* first, then force `type: 'web_search'` last to keep the runtime `type`
|
|
9
|
+
* matching the discriminator the dispatcher routed by — otherwise a tool
|
|
10
|
+
* authored by hand with a different `metadata.type` would emit a malformed
|
|
11
|
+
* payload.
|
|
12
|
+
*/
|
|
13
|
+
export declare function convertWebSearchToolToAdapterFormat(tool: Tool): WebSearchToolConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a standard Tool from WebSearchTool parameters.
|
|
16
|
+
*
|
|
17
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
18
|
+
* re-wrap this in their own package.
|
|
19
|
+
*/
|
|
20
|
+
export declare function webSearchTool(toolData: WebSearchToolConfig): Tool;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function convertWebSearchToolToAdapterFormat(tool) {
|
|
2
|
+
const metadata = tool.metadata;
|
|
3
|
+
return {
|
|
4
|
+
...metadata,
|
|
5
|
+
type: "web_search"
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function webSearchTool(toolData) {
|
|
9
|
+
return {
|
|
10
|
+
name: "web_search",
|
|
11
|
+
description: "Search the web",
|
|
12
|
+
metadata: toolData
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
convertWebSearchToolToAdapterFormat,
|
|
17
|
+
webSearchTool
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=web-search-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search-tool.js","sources":["../../../src/tools/web-search-tool.ts"],"sourcesContent":["import type { WebSearchTool as WebSearchToolConfig } from 'openai/resources/responses/responses'\nimport type { Tool } from '@tanstack/ai'\n\nexport type { WebSearchToolConfig }\n\n/** @deprecated Renamed to `WebSearchToolConfig`. Will be removed in a future release. */\nexport type WebSearchTool = WebSearchToolConfig\n\n/**\n * Converts a standard Tool to OpenAI WebSearchTool format. Spread `metadata`\n * first, then force `type: 'web_search'` last to keep the runtime `type`\n * matching the discriminator the dispatcher routed by — otherwise a tool\n * authored by hand with a different `metadata.type` would emit a malformed\n * payload.\n */\nexport function convertWebSearchToolToAdapterFormat(\n tool: Tool,\n): WebSearchToolConfig {\n const metadata = tool.metadata as Omit<WebSearchToolConfig, 'type'>\n return {\n ...metadata,\n type: 'web_search',\n }\n}\n\n/**\n * Creates a standard Tool from WebSearchTool 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 webSearchTool(toolData: WebSearchToolConfig): Tool {\n return {\n name: 'web_search',\n description: 'Search the web',\n metadata: toolData,\n }\n}\n"],"names":[],"mappings":"AAeO,SAAS,oCACd,MACqB;AACrB,QAAM,WAAW,KAAK;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM;AAAA,EAAA;AAEV;AAQO,SAAS,cAAc,UAAqC;AACjE,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EAAA;AAEd;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TokenUsage } from '@tanstack/ai';
|
|
2
|
+
import { default as OpenAI } from 'openai';
|
|
3
|
+
/**
|
|
4
|
+
* Build normalized {@link TokenUsage} from an OpenAI-compatible Chat
|
|
5
|
+
* Completions `usage` object.
|
|
6
|
+
*
|
|
7
|
+
* Shared by every provider that routes through
|
|
8
|
+
* {@link OpenAIBaseChatCompletionsTextAdapter} (OpenAI Chat Completions, Grok,
|
|
9
|
+
* Groq). Surfaces cached prompt tokens and reasoning/audio detail tokens when
|
|
10
|
+
* the provider reports them. Returns `undefined` when the provider reported no
|
|
11
|
+
* usage object, so callers omit the field rather than fabricating zeroed totals.
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildChatCompletionsUsage(usage: OpenAI.Chat.Completions.ChatCompletion['usage'] | undefined | null): TokenUsage | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Build normalized {@link TokenUsage} from an OpenAI Responses API
|
|
16
|
+
* `ResponseUsage` object.
|
|
17
|
+
*
|
|
18
|
+
* Shared by every provider that routes through
|
|
19
|
+
* {@link OpenAIBaseResponsesTextAdapter}. Surfaces cached prompt tokens and
|
|
20
|
+
* reasoning detail tokens when present. Returns `undefined` when the provider
|
|
21
|
+
* reported no usage object, so callers omit the field rather than fabricating
|
|
22
|
+
* zeroed totals.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildResponsesUsage(usage: OpenAI.Responses.ResponseUsage | undefined | null): TokenUsage | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Build normalized {@link TokenUsage} from an OpenAI Images API `usage` object.
|
|
27
|
+
*
|
|
28
|
+
* Shared by every provider that generates images through the OpenAI Images SDK
|
|
29
|
+
* (OpenAI, Grok). Token-billed image models (e.g. gpt-image-1) report an input
|
|
30
|
+
* breakdown of text vs image tokens, which is surfaced on `promptTokensDetails`.
|
|
31
|
+
* Models that don't return usage (e.g. DALL·E) yield `undefined` so callers can
|
|
32
|
+
* omit the field rather than emit zeroed totals.
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildImagesUsage(usage: OpenAI.Images.ImagesResponse['usage'] | undefined | null): TokenUsage | undefined;
|