@tanstack/openai-base 0.8.6 → 0.8.8

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.
@@ -13,5 +13,11 @@ export type FunctionTool = FunctionToolConfig;
13
13
  * - additionalProperties: false
14
14
  *
15
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.
16
22
  */
17
23
  export declare function convertFunctionToolToAdapterFormat(tool: Tool): FunctionToolConfig;
@@ -1,10 +1,19 @@
1
- import { makeStructuredOutputCompatible } from "../utils/schema-converter.js";
1
+ import { isStrictModeCompatible, stripUnsupportedFormats, makeStructuredOutputCompatible } from "../utils/schema-converter.js";
2
2
  function convertFunctionToolToAdapterFormat(tool) {
3
3
  const inputSchema = tool.inputSchema ?? {
4
4
  type: "object",
5
5
  properties: {},
6
6
  required: []
7
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
+ }
8
17
  const jsonSchema = makeStructuredOutputCompatible(
9
18
  inputSchema,
10
19
  inputSchema.required || []
@@ -1 +1 @@
1
- {"version":3,"file":"function-tool.js","sources":["../../../src/tools/function-tool.ts"],"sourcesContent":["import { makeStructuredOutputCompatible } 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 */\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
+ {"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;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/openai-base",
3
- "version": "0.8.6",
3
+ "version": "0.8.8",
4
4
  "description": "Shared OpenAI SDK base adapters for TanStack AI providers using Chat Completions and Responses APIs.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -47,13 +47,13 @@
47
47
  "@tanstack/ai-utils": "0.2.2"
48
48
  },
49
49
  "peerDependencies": {
50
- "@tanstack/ai": "^0.32.0"
50
+ "@tanstack/ai": "^0.33.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@vitest/coverage-v8": "4.0.14",
54
54
  "vite": "^7.3.3",
55
55
  "zod": "^4.2.0",
56
- "@tanstack/ai": "0.32.0"
56
+ "@tanstack/ai": "0.33.0"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "vite build",
@@ -1,4 +1,8 @@
1
- import { makeStructuredOutputCompatible } from '../utils/schema-converter'
1
+ import {
2
+ isStrictModeCompatible,
3
+ makeStructuredOutputCompatible,
4
+ stripUnsupportedFormats,
5
+ } from '../utils/schema-converter'
2
6
  import type { FunctionTool as FunctionToolConfig } from 'openai/resources/responses/responses'
3
7
  import type { JSONSchema, Tool } from '@tanstack/ai'
4
8
 
@@ -17,6 +21,12 @@ export type FunctionTool = FunctionToolConfig
17
21
  * - additionalProperties: false
18
22
  *
19
23
  * This enables strict mode for all tools automatically.
24
+ *
25
+ * Some tool schemas (e.g. MCP server tools that use `oneOf`, `$ref`, or
26
+ * `$defs`) cannot be expressed under OpenAI's strict Structured Outputs
27
+ * subset. For those we fall back to a non-strict tool definition — stripping
28
+ * only the formats OpenAI rejects — so the tool is still usable instead of
29
+ * failing the request with a 400 "Invalid schema" error.
20
30
  */
21
31
  export function convertFunctionToolToAdapterFormat(
22
32
  tool: Tool,
@@ -27,6 +37,16 @@ export function convertFunctionToolToAdapterFormat(
27
37
  required: [],
28
38
  }) as JSONSchema
29
39
 
40
+ if (!isStrictModeCompatible(inputSchema)) {
41
+ return {
42
+ type: 'function',
43
+ name: tool.name,
44
+ description: tool.description,
45
+ parameters: stripUnsupportedFormats(inputSchema),
46
+ strict: false,
47
+ } satisfies FunctionToolConfig
48
+ }
49
+
30
50
  const jsonSchema = makeStructuredOutputCompatible(
31
51
  inputSchema,
32
52
  inputSchema.required || [],