@tanstack/openai-base 0.1.0 → 0.2.1
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/LICENSE +21 -0
- package/dist/esm/adapters/chat-completions-text.d.ts +2 -2
- package/dist/esm/adapters/chat-completions-text.js +183 -80
- package/dist/esm/adapters/chat-completions-text.js.map +1 -1
- package/dist/esm/adapters/chat-completions-tool-converter.js +3 -1
- package/dist/esm/adapters/chat-completions-tool-converter.js.map +1 -1
- package/dist/esm/adapters/image.js +33 -13
- package/dist/esm/adapters/image.js.map +1 -1
- package/dist/esm/adapters/responses-text.d.ts +4 -5
- package/dist/esm/adapters/responses-text.js +260 -135
- package/dist/esm/adapters/responses-text.js.map +1 -1
- package/dist/esm/adapters/responses-tool-converter.js +3 -1
- package/dist/esm/adapters/responses-tool-converter.js.map +1 -1
- package/dist/esm/adapters/summarize.js +63 -25
- package/dist/esm/adapters/summarize.js.map +1 -1
- package/dist/esm/adapters/transcription.d.ts +0 -5
- package/dist/esm/adapters/transcription.js +53 -61
- package/dist/esm/adapters/transcription.js.map +1 -1
- package/dist/esm/adapters/tts.js +27 -14
- package/dist/esm/adapters/tts.js.map +1 -1
- package/dist/esm/adapters/video.d.ts +24 -0
- package/dist/esm/adapters/video.js +72 -26
- package/dist/esm/adapters/video.js.map +1 -1
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.js +4 -2
- package/dist/esm/tools/apply-patch-tool.d.ts +8 -3
- package/dist/esm/tools/apply-patch-tool.js.map +1 -1
- package/dist/esm/tools/code-interpreter-tool.d.ts +9 -4
- package/dist/esm/tools/code-interpreter-tool.js.map +1 -1
- package/dist/esm/tools/computer-use-tool.d.ts +9 -4
- package/dist/esm/tools/computer-use-tool.js.map +1 -1
- package/dist/esm/tools/custom-tool.d.ts +6 -4
- package/dist/esm/tools/custom-tool.js.map +1 -1
- package/dist/esm/tools/file-search-tool.d.ts +11 -4
- package/dist/esm/tools/file-search-tool.js +3 -2
- package/dist/esm/tools/file-search-tool.js.map +1 -1
- package/dist/esm/tools/function-tool.d.ts +4 -2
- package/dist/esm/tools/function-tool.js.map +1 -1
- package/dist/esm/tools/image-generation-tool.d.ts +16 -5
- package/dist/esm/tools/image-generation-tool.js +4 -3
- package/dist/esm/tools/image-generation-tool.js.map +1 -1
- package/dist/esm/tools/index.d.ts +13 -13
- package/dist/esm/tools/local-shell-tool.d.ts +8 -3
- package/dist/esm/tools/local-shell-tool.js.map +1 -1
- package/dist/esm/tools/mcp-tool.d.ts +10 -5
- package/dist/esm/tools/mcp-tool.js.map +1 -1
- package/dist/esm/tools/shell-tool.d.ts +8 -3
- package/dist/esm/tools/shell-tool.js.map +1 -1
- package/dist/esm/tools/web-search-preview-tool.d.ts +13 -5
- package/dist/esm/tools/web-search-preview-tool.js +2 -3
- package/dist/esm/tools/web-search-preview-tool.js.map +1 -1
- package/dist/esm/tools/web-search-tool.d.ts +14 -5
- package/dist/esm/tools/web-search-tool.js +4 -1
- package/dist/esm/tools/web-search-tool.js.map +1 -1
- package/dist/esm/utils/request-options.d.ts +14 -0
- package/dist/esm/utils/request-options.js +8 -0
- package/dist/esm/utils/request-options.js.map +1 -0
- package/package.json +16 -19
- package/dist/esm/types/message-metadata.d.ts +0 -19
- package/dist/esm/types/provider-options.d.ts +0 -40
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Tool } from '@tanstack/ai';
|
|
2
2
|
import { default as OpenAI } from 'openai';
|
|
3
|
-
export type
|
|
3
|
+
export type FunctionToolConfig = OpenAI.Responses.FunctionTool;
|
|
4
|
+
/** @deprecated Renamed to `FunctionToolConfig`. Will be removed in a future release. */
|
|
5
|
+
export type FunctionTool = FunctionToolConfig;
|
|
4
6
|
/**
|
|
5
7
|
* Converts a standard Tool to OpenAI FunctionTool format.
|
|
6
8
|
*
|
|
@@ -12,4 +14,4 @@ export type FunctionTool = OpenAI.Responses.FunctionTool;
|
|
|
12
14
|
*
|
|
13
15
|
* This enables strict mode for all tools automatically.
|
|
14
16
|
*/
|
|
15
|
-
export declare function convertFunctionToolToAdapterFormat(tool: Tool):
|
|
17
|
+
export declare function convertFunctionToolToAdapterFormat(tool: Tool): FunctionToolConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-tool.js","sources":["../../../src/tools/function-tool.ts"],"sourcesContent":["import { makeStructuredOutputCompatible } from '../utils/schema-converter'\nimport type { JSONSchema, Tool } from '@tanstack/ai'\nimport type OpenAI from 'openai'\n\nexport type
|
|
1
|
+
{"version":3,"file":"function-tool.js","sources":["../../../src/tools/function-tool.ts"],"sourcesContent":["import { makeStructuredOutputCompatible } from '../utils/schema-converter'\nimport type { JSONSchema, Tool } from '@tanstack/ai'\nimport type OpenAI from 'openai'\n\nexport type FunctionToolConfig = OpenAI.Responses.FunctionTool\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 */\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 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":";AAoBO,SAAS,mCACd,MACoB;AACpB,QAAM,cAAe,KAAK,eAAe;AAAA,IACvC,MAAM;AAAA,IACN,YAAY,CAAA;AAAA,IACZ,UAAU,CAAA;AAAA,EAAC;AAGb,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;"}
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { default as OpenAI } from 'openai';
|
|
2
2
|
import { Tool } from '@tanstack/ai';
|
|
3
|
-
export type
|
|
3
|
+
export type ImageGenerationToolConfig = OpenAI.Responses.Tool.ImageGeneration;
|
|
4
|
+
/** @deprecated Renamed to `ImageGenerationToolConfig`. Will be removed in a future release. */
|
|
5
|
+
export type ImageGenerationTool = ImageGenerationToolConfig;
|
|
6
|
+
declare const validatePartialImages: (value: number | undefined) => void;
|
|
4
7
|
/**
|
|
5
|
-
* Converts a standard Tool to OpenAI ImageGenerationTool format
|
|
8
|
+
* Converts a standard Tool to OpenAI ImageGenerationTool format. Spread
|
|
9
|
+
* `metadata` first, then force `type: 'image_generation'` last — otherwise a
|
|
10
|
+
* `metadata.type` snuck in by a hand-built tool would shadow the literal and
|
|
11
|
+
* the dispatcher (which routed by `tool.name`) would emit a tool whose
|
|
12
|
+
* runtime `type` doesn't match `image_generation`.
|
|
6
13
|
*/
|
|
7
|
-
export declare function convertImageGenerationToolToAdapterFormat(tool: Tool):
|
|
14
|
+
export declare function convertImageGenerationToolToAdapterFormat(tool: Tool): ImageGenerationToolConfig;
|
|
8
15
|
/**
|
|
9
|
-
* Creates a standard Tool from ImageGenerationTool parameters
|
|
16
|
+
* Creates a standard Tool from ImageGenerationTool parameters.
|
|
17
|
+
*
|
|
18
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
19
|
+
* re-wrap this in their own package.
|
|
10
20
|
*/
|
|
11
|
-
export declare function imageGenerationTool(toolData: Omit<
|
|
21
|
+
export declare function imageGenerationTool(toolData: Omit<ImageGenerationToolConfig, 'type'>): Tool;
|
|
22
|
+
export { validatePartialImages };
|
|
@@ -6,8 +6,8 @@ const validatePartialImages = (value) => {
|
|
|
6
6
|
function convertImageGenerationToolToAdapterFormat(tool) {
|
|
7
7
|
const metadata = tool.metadata;
|
|
8
8
|
return {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
...metadata,
|
|
10
|
+
type: "image_generation"
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
function imageGenerationTool(toolData) {
|
|
@@ -22,6 +22,7 @@ function imageGenerationTool(toolData) {
|
|
|
22
22
|
}
|
|
23
23
|
export {
|
|
24
24
|
convertImageGenerationToolToAdapterFormat,
|
|
25
|
-
imageGenerationTool
|
|
25
|
+
imageGenerationTool,
|
|
26
|
+
validatePartialImages
|
|
26
27
|
};
|
|
27
28
|
//# sourceMappingURL=image-generation-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-generation-tool.js","sources":["../../../src/tools/image-generation-tool.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { Tool } from '@tanstack/ai'\n\nexport type
|
|
1
|
+
{"version":3,"file":"image-generation-tool.js","sources":["../../../src/tools/image-generation-tool.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { Tool } from '@tanstack/ai'\n\nexport type ImageGenerationToolConfig = OpenAI.Responses.Tool.ImageGeneration\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":"AAQA,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;"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
export type OpenAITool =
|
|
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
14
|
export * from './apply-patch-tool.js';
|
|
15
15
|
export * from './code-interpreter-tool.js';
|
|
16
16
|
export * from './computer-use-tool.js';
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { default as OpenAI } from 'openai';
|
|
2
2
|
import { Tool } from '@tanstack/ai';
|
|
3
|
-
export type
|
|
3
|
+
export type LocalShellToolConfig = OpenAI.Responses.Tool.LocalShell;
|
|
4
|
+
/** @deprecated Renamed to `LocalShellToolConfig`. Will be removed in a future release. */
|
|
5
|
+
export type LocalShellTool = LocalShellToolConfig;
|
|
4
6
|
/**
|
|
5
7
|
* Converts a standard Tool to OpenAI LocalShellTool format
|
|
6
8
|
*/
|
|
7
|
-
export declare function convertLocalShellToolToAdapterFormat(_tool: Tool):
|
|
9
|
+
export declare function convertLocalShellToolToAdapterFormat(_tool: Tool): LocalShellToolConfig;
|
|
8
10
|
/**
|
|
9
|
-
* Creates a standard Tool from LocalShellTool parameters
|
|
11
|
+
* Creates a standard Tool from LocalShellTool parameters.
|
|
12
|
+
*
|
|
13
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
14
|
+
* re-wrap this in their own package.
|
|
10
15
|
*/
|
|
11
16
|
export declare function localShellTool(): Tool;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-shell-tool.js","sources":["../../../src/tools/local-shell-tool.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { Tool } from '@tanstack/ai'\n\nexport type
|
|
1
|
+
{"version":3,"file":"local-shell-tool.js","sources":["../../../src/tools/local-shell-tool.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { Tool } from '@tanstack/ai'\n\nexport type LocalShellToolConfig = OpenAI.Responses.Tool.LocalShell\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":"AAWO,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;"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { default as OpenAI } from 'openai';
|
|
2
2
|
import { Tool } from '@tanstack/ai';
|
|
3
|
-
export type
|
|
4
|
-
|
|
3
|
+
export type MCPToolConfig = OpenAI.Responses.Tool.Mcp;
|
|
4
|
+
/** @deprecated Renamed to `MCPToolConfig`. Will be removed in a future release. */
|
|
5
|
+
export type MCPTool = MCPToolConfig;
|
|
6
|
+
export declare function validateMCPtool(tool: MCPToolConfig): void;
|
|
5
7
|
/**
|
|
6
8
|
* Converts a standard Tool to OpenAI MCPTool format
|
|
7
9
|
*/
|
|
8
|
-
export declare function convertMCPToolToAdapterFormat(tool: Tool):
|
|
10
|
+
export declare function convertMCPToolToAdapterFormat(tool: Tool): MCPToolConfig;
|
|
9
11
|
/**
|
|
10
|
-
* Creates a standard Tool from MCPTool parameters
|
|
12
|
+
* Creates a standard Tool from MCPTool parameters.
|
|
13
|
+
*
|
|
14
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
15
|
+
* re-wrap this in their own package.
|
|
11
16
|
*/
|
|
12
|
-
export declare function mcpTool(toolData: Omit<
|
|
17
|
+
export declare function mcpTool(toolData: Omit<MCPToolConfig, 'type'>): Tool;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-tool.js","sources":["../../../src/tools/mcp-tool.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { Tool } from '@tanstack/ai'\n\nexport type
|
|
1
|
+
{"version":3,"file":"mcp-tool.js","sources":["../../../src/tools/mcp-tool.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { Tool } from '@tanstack/ai'\n\nexport type MCPToolConfig = OpenAI.Responses.Tool.Mcp\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":"AAQO,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;"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { default as OpenAI } from 'openai';
|
|
2
2
|
import { Tool } from '@tanstack/ai';
|
|
3
|
-
export type
|
|
3
|
+
export type ShellToolConfig = OpenAI.Responses.FunctionShellTool;
|
|
4
|
+
/** @deprecated Renamed to `ShellToolConfig`. Will be removed in a future release. */
|
|
5
|
+
export type ShellTool = ShellToolConfig;
|
|
4
6
|
/**
|
|
5
7
|
* Converts a standard Tool to OpenAI ShellTool format
|
|
6
8
|
*/
|
|
7
|
-
export declare function convertShellToolToAdapterFormat(_tool: Tool):
|
|
9
|
+
export declare function convertShellToolToAdapterFormat(_tool: Tool): ShellToolConfig;
|
|
8
10
|
/**
|
|
9
|
-
* Creates a standard Tool from ShellTool parameters
|
|
11
|
+
* Creates a standard Tool from ShellTool parameters.
|
|
12
|
+
*
|
|
13
|
+
* Base (non-branded) factory. Providers that need branded return types should
|
|
14
|
+
* re-wrap this in their own package.
|
|
10
15
|
*/
|
|
11
16
|
export declare function shellTool(): Tool;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-tool.js","sources":["../../../src/tools/shell-tool.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { Tool } from '@tanstack/ai'\n\nexport type
|
|
1
|
+
{"version":3,"file":"shell-tool.js","sources":["../../../src/tools/shell-tool.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { Tool } from '@tanstack/ai'\n\nexport type ShellToolConfig = OpenAI.Responses.FunctionShellTool\n\n/** @deprecated Renamed to `ShellToolConfig`. Will be removed in a future release. */\nexport type ShellTool = ShellToolConfig\n\n/**\n * Converts a standard Tool to OpenAI ShellTool format\n */\nexport function convertShellToolToAdapterFormat(_tool: Tool): ShellToolConfig {\n return {\n type: 'shell',\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(): Tool {\n return {\n name: 'shell',\n description: 'Execute shell commands',\n metadata: {},\n }\n}\n"],"names":[],"mappings":"AAWO,SAAS,gCAAgC,OAA8B;AAC5E,SAAO;AAAA,IACL,MAAM;AAAA,EAAA;AAEV;AAQO,SAAS,YAAkB;AAChC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU,CAAA;AAAA,EAAC;AAEf;"}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { default as OpenAI } from 'openai';
|
|
2
2
|
import { Tool } from '@tanstack/ai';
|
|
3
|
-
export type
|
|
3
|
+
export type WebSearchPreviewToolConfig = OpenAI.Responses.WebSearchPreviewTool;
|
|
4
|
+
/** @deprecated Renamed to `WebSearchPreviewToolConfig`. Will be removed in a future release. */
|
|
5
|
+
export type WebSearchPreviewTool = WebSearchPreviewToolConfig;
|
|
4
6
|
/**
|
|
5
|
-
* Converts a standard Tool to OpenAI WebSearchPreviewTool format
|
|
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`.
|
|
6
11
|
*/
|
|
7
|
-
export declare function convertWebSearchPreviewToolToAdapterFormat(tool: Tool):
|
|
12
|
+
export declare function convertWebSearchPreviewToolToAdapterFormat(tool: Tool): WebSearchPreviewToolConfig;
|
|
8
13
|
/**
|
|
9
|
-
* Creates a standard Tool from WebSearchPreviewTool parameters
|
|
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.
|
|
10
18
|
*/
|
|
11
|
-
export declare function webSearchPreviewTool(toolData:
|
|
19
|
+
export declare function webSearchPreviewTool(toolData: WebSearchPreviewToolConfig): Tool;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
function convertWebSearchPreviewToolToAdapterFormat(tool) {
|
|
2
2
|
const metadata = tool.metadata;
|
|
3
3
|
return {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
user_location: metadata.user_location
|
|
4
|
+
...metadata,
|
|
5
|
+
type: "web_search_preview"
|
|
7
6
|
};
|
|
8
7
|
}
|
|
9
8
|
function webSearchPreviewTool(toolData) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-search-preview-tool.js","sources":["../../../src/tools/web-search-preview-tool.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { Tool } from '@tanstack/ai'\n\nexport type
|
|
1
|
+
{"version":3,"file":"web-search-preview-tool.js","sources":["../../../src/tools/web-search-preview-tool.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { Tool } from '@tanstack/ai'\n\nexport type WebSearchPreviewToolConfig = OpenAI.Responses.WebSearchPreviewTool\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;"}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { default as OpenAI } from 'openai';
|
|
2
2
|
import { Tool } from '@tanstack/ai';
|
|
3
|
-
export type
|
|
3
|
+
export type WebSearchToolConfig = OpenAI.Responses.WebSearchTool;
|
|
4
|
+
/** @deprecated Renamed to `WebSearchToolConfig`. Will be removed in a future release. */
|
|
5
|
+
export type WebSearchTool = WebSearchToolConfig;
|
|
4
6
|
/**
|
|
5
|
-
* Converts a standard Tool to OpenAI WebSearchTool format
|
|
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.
|
|
6
12
|
*/
|
|
7
|
-
export declare function convertWebSearchToolToAdapterFormat(tool: Tool):
|
|
13
|
+
export declare function convertWebSearchToolToAdapterFormat(tool: Tool): WebSearchToolConfig;
|
|
8
14
|
/**
|
|
9
|
-
* Creates a standard Tool from WebSearchTool parameters
|
|
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.
|
|
10
19
|
*/
|
|
11
|
-
export declare function webSearchTool(toolData:
|
|
20
|
+
export declare function webSearchTool(toolData: WebSearchToolConfig): Tool;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-search-tool.js","sources":["../../../src/tools/web-search-tool.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { Tool } from '@tanstack/ai'\n\nexport type
|
|
1
|
+
{"version":3,"file":"web-search-tool.js","sources":["../../../src/tools/web-search-tool.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { Tool } from '@tanstack/ai'\n\nexport type WebSearchToolConfig = OpenAI.Responses.WebSearchTool\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,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract `headers` and `signal` from a `Request | RequestInit` for the OpenAI
|
|
3
|
+
* SDK's per-call `RequestOptions`. `Request` exposes `headers` as a `Headers`
|
|
4
|
+
* instance (HeadersInit-compatible) while `RequestInit` exposes `HeadersInit`
|
|
5
|
+
* directly — this helper accepts either shape so callers don't need to cast.
|
|
6
|
+
*
|
|
7
|
+
* Always returns an object (possibly empty) rather than `undefined` so test
|
|
8
|
+
* assertions that match the second argument shape via `expect.anything()` /
|
|
9
|
+
* `expect.objectContaining()` keep working when no request override was set.
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractRequestOptions(request: Request | RequestInit | undefined): {
|
|
12
|
+
headers?: HeadersInit;
|
|
13
|
+
signal?: AbortSignal | null;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-options.js","sources":["../../../src/utils/request-options.ts"],"sourcesContent":["/**\n * Extract `headers` and `signal` from a `Request | RequestInit` for the OpenAI\n * SDK's per-call `RequestOptions`. `Request` exposes `headers` as a `Headers`\n * instance (HeadersInit-compatible) while `RequestInit` exposes `HeadersInit`\n * directly — this helper accepts either shape so callers don't need to cast.\n *\n * Always returns an object (possibly empty) rather than `undefined` so test\n * assertions that match the second argument shape via `expect.anything()` /\n * `expect.objectContaining()` keep working when no request override was set.\n */\nexport function extractRequestOptions(\n request: Request | RequestInit | undefined,\n): { headers?: HeadersInit; signal?: AbortSignal | null } {\n if (!request) return {}\n return { headers: request.headers, signal: request.signal ?? undefined }\n}\n"],"names":[],"mappings":"AAUO,SAAS,sBACd,SACwD;AACxD,MAAI,CAAC,QAAS,QAAO,CAAA;AACrB,SAAO,EAAE,SAAS,QAAQ,SAAS,QAAQ,QAAQ,UAAU,OAAA;AAC/D;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/openai-base",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Shared base adapters and utilities for OpenAI-compatible providers in TanStack AI",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,19 +22,6 @@
|
|
|
22
22
|
"dist",
|
|
23
23
|
"src"
|
|
24
24
|
],
|
|
25
|
-
"publishConfig": {
|
|
26
|
-
"access": "public"
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"build": "vite build",
|
|
30
|
-
"clean": "premove ./build ./dist",
|
|
31
|
-
"lint:fix": "eslint ./src --fix",
|
|
32
|
-
"test:build": "publint --strict",
|
|
33
|
-
"test:eslint": "eslint ./src",
|
|
34
|
-
"test:lib": "vitest run",
|
|
35
|
-
"test:lib:dev": "pnpm test:lib --watch",
|
|
36
|
-
"test:types": "tsc"
|
|
37
|
-
},
|
|
38
25
|
"keywords": [
|
|
39
26
|
"ai",
|
|
40
27
|
"openai",
|
|
@@ -43,15 +30,25 @@
|
|
|
43
30
|
"base"
|
|
44
31
|
],
|
|
45
32
|
"dependencies": {
|
|
46
|
-
"
|
|
47
|
-
"
|
|
33
|
+
"openai": "^6.9.1",
|
|
34
|
+
"@tanstack/ai-utils": "0.2.0"
|
|
48
35
|
},
|
|
49
36
|
"peerDependencies": {
|
|
50
|
-
"@tanstack/ai": "
|
|
37
|
+
"@tanstack/ai": "^0.16.0"
|
|
51
38
|
},
|
|
52
39
|
"devDependencies": {
|
|
53
|
-
"@tanstack/ai": "workspace:*",
|
|
54
40
|
"@vitest/coverage-v8": "4.0.14",
|
|
55
|
-
"vite": "^7.2.7"
|
|
41
|
+
"vite": "^7.2.7",
|
|
42
|
+
"@tanstack/ai": "0.16.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "vite build",
|
|
46
|
+
"clean": "premove ./build ./dist",
|
|
47
|
+
"lint:fix": "eslint ./src --fix",
|
|
48
|
+
"test:build": "publint --strict",
|
|
49
|
+
"test:eslint": "eslint ./src",
|
|
50
|
+
"test:lib": "vitest run",
|
|
51
|
+
"test:lib:dev": "pnpm test:lib --watch",
|
|
52
|
+
"test:types": "tsc"
|
|
56
53
|
}
|
|
57
54
|
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export interface OpenAICompatibleImageMetadata {
|
|
2
|
-
detail?: 'auto' | 'low' | 'high';
|
|
3
|
-
}
|
|
4
|
-
export interface OpenAICompatibleAudioMetadata {
|
|
5
|
-
format?: 'mp3' | 'wav' | 'flac' | 'ogg' | 'webm' | 'aac';
|
|
6
|
-
}
|
|
7
|
-
export interface OpenAICompatibleVideoMetadata {
|
|
8
|
-
}
|
|
9
|
-
export interface OpenAICompatibleDocumentMetadata {
|
|
10
|
-
}
|
|
11
|
-
export interface OpenAICompatibleTextMetadata {
|
|
12
|
-
}
|
|
13
|
-
export interface OpenAICompatibleMessageMetadataByModality {
|
|
14
|
-
text: OpenAICompatibleTextMetadata;
|
|
15
|
-
image: OpenAICompatibleImageMetadata;
|
|
16
|
-
audio: OpenAICompatibleAudioMetadata;
|
|
17
|
-
video: OpenAICompatibleVideoMetadata;
|
|
18
|
-
document: OpenAICompatibleDocumentMetadata;
|
|
19
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export interface OpenAICompatibleBaseOptions {
|
|
2
|
-
temperature?: number;
|
|
3
|
-
top_p?: number;
|
|
4
|
-
max_tokens?: number;
|
|
5
|
-
frequency_penalty?: number;
|
|
6
|
-
presence_penalty?: number;
|
|
7
|
-
stop?: string | Array<string>;
|
|
8
|
-
user?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface OpenAICompatibleReasoningOptions {
|
|
11
|
-
reasoning?: {
|
|
12
|
-
effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high';
|
|
13
|
-
summary?: 'auto' | 'detailed';
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export interface OpenAICompatibleStructuredOutputOptions {
|
|
17
|
-
text?: {
|
|
18
|
-
format: {
|
|
19
|
-
type: string;
|
|
20
|
-
name?: string;
|
|
21
|
-
schema?: Record<string, unknown>;
|
|
22
|
-
strict?: boolean;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export interface OpenAICompatibleToolsOptions {
|
|
27
|
-
max_tool_calls?: number;
|
|
28
|
-
parallel_tool_calls?: boolean;
|
|
29
|
-
tool_choice?: 'auto' | 'none' | 'required' | {
|
|
30
|
-
type: 'function';
|
|
31
|
-
function: {
|
|
32
|
-
name: string;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
export interface OpenAICompatibleStreamingOptions {
|
|
37
|
-
stream_options?: {
|
|
38
|
-
include_usage?: boolean;
|
|
39
|
-
};
|
|
40
|
-
}
|