tool-schema 0.3.0 → 0.3.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/dist/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts","../src/util.ts","../src/targets/openai.ts","../src/targets/anthropic.ts","../src/targets/gemini.ts","../src/targets/mcp.ts","../src/transform.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { readFileSync } from 'node:fs';\nimport { toToolSchema, toTool } from './transform.js';\nimport type { JSONSchema, Target, ToolSchemaOptions } from './types.js';\n\nconst TARGETS: Target[] = ['openai', 'openai-strict', 'anthropic', 'gemini', 'gemini-jsonschema', 'mcp'];\n\nconst HELP = `tool-schema - convert a JSON Schema into a provider valid tool schema\n\nUsage:\n tool-schema [file.json] --target <target> [options]\n cat schema.json | tool-schema --target gemini\n\nTargets:\n ${TARGETS.join(', ')}\n\nOptions:\n -t, --target <name> Provider target (default: openai)\n --tool <name> Wrap the result as a full tool definition with this name\n --description <text> Tool description (with --tool)\n --responses OpenAI: emit the Responses API tool shape\n --uppercase-types Gemini: emit upper case OpenAPI type names\n --quiet Do not print warnings to stderr\n -h, --help Show this help\n\nReads from the given file or from stdin. Prints the converted schema (or tool)\nas JSON to stdout. Warnings go to stderr and never pollute stdout.`;\n\ninterface Args {\n file?: string;\n target: Target;\n tool?: string;\n description?: string;\n responses: boolean;\n uppercase: boolean;\n quiet: boolean;\n help: boolean;\n}\n\nfunction parseArgs(argv: string[]): Args {\n const args: Args = {\n target: 'openai',\n responses: false,\n uppercase: false,\n quiet: false,\n help: false,\n };\n for (let i = 0; i < argv.length; i++) {\n const a = argv[i];\n switch (a) {\n case '-h':\n case '--help':\n args.help = true;\n break;\n case '-t':\n case '--target':\n args.target = argv[++i] as Target;\n break;\n case '--tool':\n args.tool = argv[++i];\n break;\n case '--description':\n args.description = argv[++i];\n break;\n case '--responses':\n args.responses = true;\n break;\n case '--uppercase-types':\n args.uppercase = true;\n break;\n case '--quiet':\n args.quiet = true;\n break;\n default:\n if (a.startsWith('-')) {\n throw new Error(`Unknown option: ${a}`);\n }\n args.file = a;\n }\n }\n return args;\n}\n\nfunction readInput(file?: string): string {\n if (file) return readFileSync(file, 'utf8');\n return readFileSync(0, 'utf8');\n}\n\nfunction main(): void {\n let args: Args;\n try {\n args = parseArgs(process.argv.slice(2));\n } catch (err) {\n process.stderr.write(`${(err as Error).message}\\n`);\n process.exit(2);\n }\n\n if (args.help) {\n process.stdout.write(`${HELP}\\n`);\n return;\n }\n\n if (!TARGETS.includes(args.target)) {\n process.stderr.write(`Invalid target '${args.target}'. Valid: ${TARGETS.join(', ')}\\n`);\n process.exit(2);\n }\n\n let schema: JSONSchema;\n try {\n schema = JSON.parse(readInput(args.file)) as JSONSchema;\n } catch (err) {\n process.stderr.write(`Could not read or parse input: ${(err as Error).message}\\n`);\n process.exit(1);\n return;\n }\n\n const options: ToolSchemaOptions = {\n target: args.target,\n openaiResponses: args.responses,\n geminiUppercaseTypes: args.uppercase,\n };\n\n const { output, warnings, lossy } = args.tool\n ? (() => {\n const r = toTool({ name: args.tool!, description: args.description, schema }, options);\n return { output: r.tool, warnings: r.warnings, lossy: r.lossy };\n })()\n : (() => {\n const r = toToolSchema(schema, options);\n return { output: r.schema, warnings: r.warnings, lossy: r.lossy };\n })();\n\n process.stdout.write(`${JSON.stringify(output, null, 2)}\\n`);\n\n if (!args.quiet && warnings.length > 0) {\n process.stderr.write(`\\n${warnings.length} warning(s) for target '${args.target}'${lossy ? ' (lossy)' : ''}:\\n`);\n for (const w of warnings) {\n process.stderr.write(` ${w.path} [${w.code}] ${w.message}\\n`);\n }\n }\n}\n\nmain();\n","import type { JSONSchema, Warning, WarningCode } from './types.js';\n\n/** Collects warnings and tracks whether the conversion lost information. */\nexport class Warnings {\n readonly list: Warning[] = [];\n lossy = false;\n\n add(path: string, code: WarningCode, message: string, lossy = true): void {\n this.list.push({ path, code, message });\n if (lossy) this.lossy = true;\n }\n}\n\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** A deep, structurally faithful clone. Uses the platform `structuredClone`. */\nexport function clone<T>(value: T): T {\n return structuredClone(value);\n}\n\n/** Returns the schema's declared types as an array (empty when untyped). */\nexport function typesOf(schema: JSONSchema): string[] {\n if (typeof schema.type === 'string') return [schema.type];\n if (Array.isArray(schema.type)) return schema.type.filter((t) => typeof t === 'string');\n return [];\n}\n\n/**\n * Heuristic: does this node describe an object? True when `type` is `object`\n * (or a union containing it) or when it is untyped but carries object keywords.\n */\nexport function isObjectSchema(schema: JSONSchema): boolean {\n const types = typesOf(schema);\n if (types.includes('object')) return true;\n if (types.length > 0) return false;\n return isPlainObject(schema.properties) || schema.additionalProperties !== undefined;\n}\n\n/**\n * Makes a schema accept `null`. Adds `null` to a string/array `type`, appends a\n * `{ type: 'null' }` branch to an `anyOf`, otherwise wraps the node in an\n * `anyOf` with a null branch. Used by OpenAI strict mode where every property\n * must be `required`, so optional fields are expressed as nullable instead.\n */\nexport function makeNullable(schema: JSONSchema): JSONSchema {\n if (typeof schema.type === 'string') {\n if (schema.type === 'null') return schema;\n return { ...schema, type: [schema.type, 'null'] };\n }\n if (Array.isArray(schema.type)) {\n if (schema.type.includes('null')) return schema;\n return { ...schema, type: [...schema.type, 'null'] };\n }\n if (Array.isArray(schema.anyOf)) {\n if (schema.anyOf.some((b) => typesOf(b).includes('null'))) return schema;\n return { ...schema, anyOf: [...schema.anyOf, { type: 'null' }] };\n }\n return { anyOf: [schema, { type: 'null' }] };\n}\n\n/**\n * Resolves local `$ref` pointers (`#/$defs/...` or `#/definitions/...`) by\n * inlining them. Non local refs are left untouched. Recursive refs are replaced\n * with an empty schema and reported, since target dialects that need inlining\n * (Gemini route A) cannot express recursion.\n */\nexport function dereference(root: JSONSchema, warnings: Warnings): JSONSchema {\n const defs: Record<string, JSONSchema> = {\n ...(isPlainObject(root.definitions) ? (root.definitions as Record<string, JSONSchema>) : {}),\n ...(isPlainObject(root.$defs) ? (root.$defs as Record<string, JSONSchema>) : {}),\n };\n\n const resolve = (ref: string): JSONSchema | undefined => {\n const m = /^#\\/(?:\\$defs|definitions)\\/(.+)$/.exec(ref);\n if (!m) return undefined;\n const key = decodeURIComponent(m[1].replace(/~1/g, '/').replace(/~0/g, '~'));\n return defs[key];\n };\n\n const walk = (node: JSONSchema, path: string, seen: Set<string>): JSONSchema => {\n if (!isPlainObject(node)) return node;\n if (typeof node.$ref === 'string') {\n const ref = node.$ref;\n const target = resolve(ref);\n if (!target) return node; // leave external / unknown refs in place\n if (seen.has(ref)) {\n warnings.add(path, 'recursive-ref', `Recursive $ref '${ref}' cannot be inlined; replaced with an open schema.`);\n return {};\n }\n const { $ref: _drop, ...rest } = node;\n void _drop;\n warnings.add(path, 'inlined-ref', `Inlined $ref '${ref}'.`, false);\n const merged = { ...clone(target), ...rest };\n return walk(merged, path, new Set([...seen, ref]));\n }\n return mapChildren(node, path, (child, childPath) => walk(child, childPath, seen));\n };\n\n const out = walk(clone(root), '#', new Set());\n delete out.$defs;\n delete out.definitions;\n return out;\n}\n\n/**\n * Applies `fn` to every direct sub schema of `node`, returning a new node. Walks\n * the standard applicator keywords. Leaf keywords are copied as is.\n */\nexport function mapChildren(\n node: JSONSchema,\n path: string,\n fn: (child: JSONSchema, childPath: string) => JSONSchema,\n): JSONSchema {\n const out: JSONSchema = { ...node };\n\n if (isPlainObject(out.properties)) {\n const props: Record<string, JSONSchema> = {};\n for (const [k, v] of Object.entries(out.properties as Record<string, JSONSchema>)) {\n props[k] = fn(v, `${path}/properties/${k}`);\n }\n out.properties = props;\n }\n\n if (Array.isArray(out.items)) {\n out.items = out.items.map((it, i) => fn(it, `${path}/items/${i}`));\n } else if (isPlainObject(out.items)) {\n out.items = fn(out.items as JSONSchema, `${path}/items`);\n }\n\n if (isPlainObject(out.additionalProperties)) {\n out.additionalProperties = fn(out.additionalProperties as JSONSchema, `${path}/additionalProperties`);\n }\n\n for (const key of ['anyOf', 'oneOf', 'allOf'] as const) {\n const arr = out[key];\n if (Array.isArray(arr)) {\n out[key] = arr.map((b, i) => fn(b, `${path}/${key}/${i}`));\n }\n }\n\n if (isPlainObject(out.not)) out.not = fn(out.not as JSONSchema, `${path}/not`);\n for (const key of ['if', 'then', 'else'] as const) {\n if (isPlainObject(out[key])) out[key] = fn(out[key] as JSONSchema, `${path}/${key}`);\n }\n\n if (isPlainObject(out.patternProperties)) {\n const pp: Record<string, JSONSchema> = {};\n for (const [k, v] of Object.entries(out.patternProperties as Record<string, JSONSchema>)) {\n pp[k] = fn(v, `${path}/patternProperties/${k}`);\n }\n out.patternProperties = pp;\n }\n\n for (const key of ['$defs', 'definitions', 'dependentSchemas'] as const) {\n const map = out[key];\n if (isPlainObject(map)) {\n const next: Record<string, JSONSchema> = {};\n for (const [k, v] of Object.entries(map as Record<string, JSONSchema>)) {\n next[k] = fn(v as JSONSchema, `${path}/${key}/${k}`);\n }\n out[key] = next;\n }\n }\n\n return out;\n}\n\n/** Ensures the root is an object schema, reporting when it was not. */\nexport function ensureObjectRoot(schema: JSONSchema, warnings: Warnings, target: string): JSONSchema {\n if (isObjectSchema(schema)) {\n if (typesOf(schema).length === 0) return { type: 'object', ...schema };\n return schema;\n }\n warnings.add(\n '#',\n 'root-not-object',\n `${target} requires the root schema to be an object; wrapped the schema under a 'value' property.`,\n );\n return {\n type: 'object',\n properties: { value: schema },\n required: ['value'],\n };\n}\n","import type { JSONSchema, TransformResult } from '../types.js';\nimport {\n Warnings,\n clone,\n isObjectSchema,\n isPlainObject,\n makeNullable,\n mapChildren,\n ensureObjectRoot,\n} from '../util.js';\n\n/** Formats OpenAI Structured Outputs accepts. Others are dropped in strict mode. */\nconst FORMAT_WHITELIST = new Set([\n 'date-time',\n 'time',\n 'date',\n 'duration',\n 'email',\n 'hostname',\n 'ipv4',\n 'ipv6',\n 'uuid',\n]);\n\n/** Keywords OpenAI strict mode rejects outright. */\nconst UNSUPPORTED = [\n 'not',\n 'if',\n 'then',\n 'else',\n 'dependentRequired',\n 'dependentSchemas',\n 'patternProperties',\n 'unevaluatedProperties',\n] as const;\n\nconst MAX_PROPERTIES = 5000;\nconst MAX_DEPTH = 10;\nconst MAX_ENUM_VALUES = 1000;\n\n/** OpenAI non strict: tool parameters should be an object, otherwise pass through. */\nexport function toOpenAI(input: JSONSchema): TransformResult {\n const warnings = new Warnings();\n const schema = ensureObjectRoot(clone(input), warnings, 'OpenAI');\n return { schema, warnings: warnings.list, lossy: warnings.lossy };\n}\n\n/**\n * OpenAI Structured Outputs / `strict: true`. Enforces: every object has\n * `additionalProperties: false`; every property is `required` (optional ones\n * become nullable); unsupported keywords are stripped; `allOf` is merged; only\n * whitelisted `format` values survive. `$defs` / `$ref` and `anyOf` are kept.\n */\nexport function toOpenAIStrict(input: JSONSchema): TransformResult {\n const warnings = new Warnings();\n\n const transform = (node: JSONSchema, path: string): JSONSchema => {\n if (!isPlainObject(node)) return node;\n let s: JSONSchema = { ...node };\n\n if (Array.isArray(s.allOf)) {\n s = mergeAllOf(s, path, warnings);\n }\n\n for (const kw of UNSUPPORTED) {\n if (kw in s) {\n delete s[kw];\n warnings.add(path, 'stripped-keyword', `'${kw}' is not supported in OpenAI strict mode; removed.`);\n }\n }\n\n if (typeof s.format === 'string' && !FORMAT_WHITELIST.has(s.format)) {\n warnings.add(\n `${path}/format`,\n 'unsupported-format',\n `format '${s.format}' is not in OpenAI's whitelist; removed.`,\n );\n delete s.format;\n }\n\n // Recurse into all sub schemas first (anyOf branches, items, $defs, ...).\n s = mapChildren(s, path, transform);\n\n if (isObjectSchema(s) && isPlainObject(s.properties)) {\n const props = s.properties as Record<string, JSONSchema>;\n const originalRequired = new Set(Array.isArray(s.required) ? s.required : []);\n const nextProps: Record<string, JSONSchema> = {};\n for (const key of Object.keys(props)) {\n let child = props[key];\n if (!originalRequired.has(key)) {\n child = makeNullable(child);\n warnings.add(\n `${path}/properties/${key}`,\n 'forced-required',\n `Optional property '${key}' was made required and nullable for OpenAI strict mode.`,\n );\n }\n nextProps[key] = child;\n }\n s.properties = nextProps;\n s.required = Object.keys(nextProps);\n if (s.additionalProperties !== false) {\n warnings.add(\n path,\n 'forced-additional-properties',\n \"Set 'additionalProperties: false' as required by strict mode.\",\n false,\n );\n }\n s.additionalProperties = false;\n } else if (isObjectSchema(s)) {\n // Object without declared properties: strict mode still forbids extra keys.\n if (s.additionalProperties !== false) {\n warnings.add(\n path,\n 'forced-additional-properties',\n \"Set 'additionalProperties: false' on a property-less object.\",\n false,\n );\n }\n s.additionalProperties = false;\n }\n\n return s;\n };\n\n const schema = ensureObjectRoot(transform(clone(input), '#'), warnings, 'OpenAI strict mode');\n checkLimits(schema, warnings);\n return { schema, warnings: warnings.list, lossy: warnings.lossy };\n}\n\n/** Shallow merges `allOf` object subschemas into the parent, then drops `allOf`. */\nfunction mergeAllOf(node: JSONSchema, path: string, warnings: Warnings): JSONSchema {\n const parts = node.allOf as JSONSchema[];\n const { allOf: _drop, ...base } = node;\n void _drop;\n const merged: JSONSchema = { ...base };\n const props: Record<string, JSONSchema> = isPlainObject(merged.properties)\n ? { ...(merged.properties as Record<string, JSONSchema>) }\n : {};\n const required = new Set<string>(Array.isArray(merged.required) ? merged.required : []);\n\n for (const part of parts) {\n if (!isPlainObject(part)) continue;\n if (isPlainObject(part.properties)) {\n Object.assign(props, part.properties);\n }\n if (Array.isArray(part.required)) {\n for (const r of part.required) required.add(r);\n }\n if (part.type && !merged.type) merged.type = part.type;\n }\n\n if (Object.keys(props).length > 0) merged.properties = props;\n if (required.size > 0) merged.required = [...required];\n if (!merged.type && (merged.properties || isObjectSchema(merged))) merged.type = 'object';\n warnings.add(path, 'merged-allof', \"Merged 'allOf' subschemas into the parent (unsupported in strict mode).\");\n return merged;\n}\n\nfunction checkLimits(schema: JSONSchema, warnings: Warnings): void {\n let propertyCount = 0;\n let maxDepth = 0;\n\n const visit = (node: JSONSchema, depth: number): void => {\n if (!isPlainObject(node)) return;\n maxDepth = Math.max(maxDepth, depth);\n if (isPlainObject(node.properties)) {\n const keys = Object.keys(node.properties as Record<string, JSONSchema>);\n propertyCount += keys.length;\n }\n if (Array.isArray(node.enum) && node.enum.length > MAX_ENUM_VALUES) {\n warnings.add(\n '#',\n 'limit-exceeded',\n `An enum has ${node.enum.length} values; OpenAI allows at most ${MAX_ENUM_VALUES}.`,\n false,\n );\n }\n const children = collectChildren(node);\n for (const c of children) visit(c, depth + 1);\n };\n\n visit(schema, 0);\n if (propertyCount > MAX_PROPERTIES) {\n warnings.add(\n '#',\n 'limit-exceeded',\n `Schema has ${propertyCount} object properties; OpenAI allows at most ${MAX_PROPERTIES}.`,\n false,\n );\n }\n if (maxDepth > MAX_DEPTH) {\n warnings.add(\n '#',\n 'limit-exceeded',\n `Schema nests ${maxDepth} levels deep; OpenAI allows at most ${MAX_DEPTH}.`,\n false,\n );\n }\n}\n\nfunction collectChildren(node: JSONSchema): JSONSchema[] {\n const out: JSONSchema[] = [];\n if (isPlainObject(node.properties)) out.push(...Object.values(node.properties as Record<string, JSONSchema>));\n if (Array.isArray(node.items)) out.push(...node.items);\n else if (isPlainObject(node.items)) out.push(node.items as JSONSchema);\n for (const key of ['anyOf', 'oneOf', 'allOf'] as const) {\n const arr = node[key];\n if (Array.isArray(arr)) out.push(...arr);\n }\n if (isPlainObject(node.$defs)) out.push(...Object.values(node.$defs as Record<string, JSONSchema>));\n return out.filter(isPlainObject) as JSONSchema[];\n}\n","import type { JSONSchema, TransformResult } from '../types.js';\nimport { Warnings, clone, ensureObjectRoot } from '../util.js';\n\n/**\n * Anthropic tool use. The API is permissive: it accepts standard JSON Schema for\n * `input_schema` (anyOf, oneOf, allOf, $ref, format, pattern, ...). The only hard\n * requirement is that the root is an object, so that is all we enforce.\n */\nexport function toAnthropic(input: JSONSchema): TransformResult {\n const warnings = new Warnings();\n const schema = ensureObjectRoot(clone(input), warnings, 'Anthropic');\n return { schema, warnings: warnings.list, lossy: warnings.lossy };\n}\n","import type { JSONSchema, TransformResult } from '../types.js';\nimport { Warnings, clone, dereference, ensureObjectRoot, isPlainObject, mapChildren, typesOf } from '../util.js';\n\n/**\n * Keywords absent from Gemini's `Schema` proto (route A). Sending them either\n * errors or is silently ignored, so they are stripped.\n */\nconst STRIP = [\n '$schema',\n '$id',\n '$anchor',\n '$ref',\n 'oneOf',\n 'allOf',\n 'not',\n 'if',\n 'then',\n 'else',\n 'additionalProperties',\n 'patternProperties',\n 'unevaluatedProperties',\n 'const',\n 'dependentRequired',\n 'dependentSchemas',\n 'multipleOf',\n 'exclusiveMinimum',\n 'exclusiveMaximum',\n 'uniqueItems',\n 'contentEncoding',\n 'contentMediaType',\n '$defs',\n 'definitions',\n] as const;\n\nconst TYPE_UPPER: Record<string, string> = {\n string: 'STRING',\n number: 'NUMBER',\n integer: 'INTEGER',\n boolean: 'BOOLEAN',\n array: 'ARRAY',\n object: 'OBJECT',\n null: 'NULL',\n};\n\ninterface GeminiOptions {\n uppercaseTypes?: boolean;\n}\n\n/**\n * Gemini function calling, route A (`parameters` as an OpenAPI 3.0 subset).\n * Inlines `$ref`, strips unsupported keywords, converts nullable unions to\n * `nullable: true`, collapses `anyOf` null branches, and coerces enum values to\n * strings. Use the `gemini-jsonschema` target for the richer\n * `parametersJsonSchema` route.\n */\nexport function toGemini(input: JSONSchema, options: GeminiOptions = {}): TransformResult {\n const warnings = new Warnings();\n const dereferenced = dereference(clone(input), warnings);\n\n const transform = (node: JSONSchema, path: string): JSONSchema => {\n if (!isPlainObject(node)) return node;\n let s: JSONSchema = { ...node };\n\n for (const kw of STRIP) {\n if (kw in s) {\n delete s[kw];\n warnings.add(path, 'stripped-keyword', `'${kw}' is not supported by Gemini (route A); removed.`);\n }\n }\n\n s = collapseNullableUnion(s, path, warnings);\n s = mapChildren(s, path, transform);\n s = collapseAnyOf(s, path, warnings);\n coerceEnum(s, path, warnings);\n return s;\n };\n\n let schema = ensureObjectRoot(transform(dereferenced, '#'), warnings, 'Gemini');\n if (options.uppercaseTypes) schema = uppercaseTypes(schema);\n return { schema, warnings: warnings.list, lossy: warnings.lossy };\n}\n\n/** Final pass: rewrite JSON Schema type names to Gemini's upper case enum. */\nfunction uppercaseTypes(node: JSONSchema): JSONSchema {\n if (!isPlainObject(node)) return node;\n const out: JSONSchema = { ...node };\n if (typeof out.type === 'string') {\n out.type = TYPE_UPPER[out.type] ?? out.type;\n } else if (Array.isArray(out.type)) {\n out.type = out.type.map((t) => TYPE_UPPER[t] ?? t);\n }\n return mapChildren(out, '#', (child) => uppercaseTypes(child));\n}\n\n/** Gemini route B (`parametersJsonSchema`): richer JSON Schema, object root only. */\nexport function toGeminiJsonSchema(input: JSONSchema): TransformResult {\n const warnings = new Warnings();\n const schema = ensureObjectRoot(clone(input), warnings, 'Gemini (parametersJsonSchema)');\n return { schema, warnings: warnings.list, lossy: warnings.lossy };\n}\n\n/** Converts `type: ['string', 'null']` into `type: 'string', nullable: true`. */\nfunction collapseNullableUnion(node: JSONSchema, path: string, warnings: Warnings): JSONSchema {\n if (!Array.isArray(node.type)) return node;\n const nonNull = node.type.filter((t) => t !== 'null');\n const hadNull = node.type.includes('null');\n const out: JSONSchema = { ...node };\n if (nonNull.length === 0) {\n out.type = 'string';\n } else {\n out.type = nonNull[0];\n if (nonNull.length > 1) {\n warnings.add(\n path,\n 'union-types',\n `Gemini cannot express a union of types [${nonNull.join(', ')}]; kept '${nonNull[0]}'.`,\n );\n }\n }\n if (hadNull) {\n out.nullable = true;\n warnings.add(path, 'collapsed-nullable', \"Converted nullable type union into 'nullable: true'.\", false);\n }\n return out;\n}\n\n/** Removes `{ type: 'null' }` branches from `anyOf`, mapping them to `nullable`. */\nfunction collapseAnyOf(node: JSONSchema, path: string, warnings: Warnings): JSONSchema {\n if (!Array.isArray(node.anyOf)) return node;\n const branches = node.anyOf as JSONSchema[];\n const nonNull = branches.filter((b) => !(typesOf(b).length === 1 && typesOf(b)[0] === 'null'));\n const hadNull = nonNull.length !== branches.length;\n const out: JSONSchema = { ...node };\n\n if (hadNull) {\n out.nullable = true;\n warnings.add(path, 'collapsed-nullable', \"Converted an anyOf null branch into 'nullable: true'.\", false);\n }\n\n if (nonNull.length === 0) {\n delete out.anyOf;\n if (!out.type) out.type = 'string';\n } else if (nonNull.length === 1) {\n // Flatten a single remaining branch into the parent.\n delete out.anyOf;\n const branch = nonNull[0];\n for (const [k, v] of Object.entries(branch)) {\n if (k === 'description' && out.description) continue;\n out[k] = v;\n }\n } else {\n out.anyOf = nonNull;\n }\n return out;\n}\n\n/** Gemini enum values must be strings. Coerces and reports when they were not. */\nfunction coerceEnum(node: JSONSchema, path: string, warnings: Warnings): void {\n if (!Array.isArray(node.enum)) return;\n const allStrings = node.enum.every((v) => typeof v === 'string');\n if (!allStrings) {\n node.enum = node.enum.map((v) => String(v));\n warnings.add(`${path}/enum`, 'enum-coerced', 'Gemini enum values must be strings; coerced non string values.');\n }\n if (!node.type) node.type = 'string';\n}\n","import type { JSONSchema, TransformResult } from '../types.js';\nimport { Warnings, clone, ensureObjectRoot } from '../util.js';\n\n/**\n * MCP (Model Context Protocol) tools. The most permissive input target:\n * `inputSchema` is standard JSON Schema and the spec only requires the root to\n * be an object. All input keywords are preserved. MCP `outputSchema` is handled\n * at the tool envelope layer because it describes `structuredContent` and does\n * not share the input object-root constraint.\n */\nexport function toMcp(input: JSONSchema): TransformResult {\n const warnings = new Warnings();\n const schema = ensureObjectRoot(clone(input), warnings, 'MCP');\n return { schema, warnings: warnings.list, lossy: warnings.lossy };\n}\n","import type {\n JSONSchema,\n LintResult,\n Target,\n ToolDefinition,\n ToolResult,\n ToolSchemaOptions,\n TransformResult,\n Warning,\n} from './types.js';\nimport { toOpenAI, toOpenAIStrict } from './targets/openai.js';\nimport { toAnthropic } from './targets/anthropic.js';\nimport { toGemini, toGeminiJsonSchema } from './targets/gemini.js';\nimport { toMcp } from './targets/mcp.js';\nimport { clone } from './util.js';\n\nconst EMPTY_OBJECT_SCHEMA: JSONSchema = { type: 'object', properties: {} };\n\n/**\n * Convert any JSON Schema into a schema that is valid for a provider's tool /\n * function calling parameters.\n *\n * @example\n * const { schema, warnings } = toToolSchema(mySchema, { target: 'openai-strict' });\n */\nexport function toToolSchema(schema: JSONSchema, options: ToolSchemaOptions = {}): TransformResult {\n const target = options.target ?? 'openai';\n switch (target) {\n case 'openai':\n return toOpenAI(schema);\n case 'openai-strict':\n return toOpenAIStrict(schema);\n case 'anthropic':\n return toAnthropic(schema);\n case 'gemini':\n return toGemini(schema, { uppercaseTypes: options.geminiUppercaseTypes });\n case 'gemini-jsonschema':\n return toGeminiJsonSchema(schema);\n case 'mcp':\n return toMcp(schema);\n default:\n throw new Error(`Unknown target: ${String(target satisfies never)}`);\n }\n}\n\n/**\n * Build a complete, provider shaped tool / function declaration: the right\n * wrapper keys (`function`, `input_schema`, `parameters`, `inputSchema`), the\n * converted parameter schema, and provider specific extras such as `strict` or\n * MCP `annotations`.\n */\nexport function toTool(def: ToolDefinition, options: ToolSchemaOptions = {}): ToolResult {\n const target = options.target ?? 'openai';\n const result = toToolSchema(def.schema ?? EMPTY_OBJECT_SCHEMA, options);\n const warnings: Warning[] = [...result.warnings];\n validateName(def.name, target, warnings);\n\n const tool = buildTool(def, result.schema, target, options);\n return { tool, warnings, lossy: result.lossy };\n}\n\n/**\n * Report what would change to make `schema` valid for a target, without\n * applying it. `ok` is true when the schema is already conformant.\n */\nexport function lintToolSchema(schema: JSONSchema, options: ToolSchemaOptions = {}): LintResult {\n const { warnings } = toToolSchema(schema, options);\n return { ok: warnings.length === 0, issues: warnings };\n}\n\nfunction buildTool(\n def: ToolDefinition,\n schema: JSONSchema,\n target: Target,\n options: ToolSchemaOptions,\n): Record<string, unknown> {\n const { name, description } = def;\n\n switch (target) {\n case 'openai':\n case 'openai-strict': {\n const strict = target === 'openai-strict';\n if (options.openaiResponses) {\n return {\n type: 'function',\n name,\n ...(description ? { description } : {}),\n parameters: schema,\n ...(strict ? { strict: true } : {}),\n };\n }\n return {\n type: 'function',\n function: {\n name,\n ...(description ? { description } : {}),\n parameters: schema,\n ...(strict ? { strict: true } : {}),\n },\n };\n }\n case 'anthropic':\n return {\n name,\n ...(description ? { description } : {}),\n input_schema: schema,\n ...(options.anthropicStrict ? { strict: true } : {}),\n };\n case 'gemini':\n return {\n name,\n ...(description ? { description } : {}),\n parameters: schema,\n };\n case 'gemini-jsonschema':\n return {\n name,\n ...(description ? { description } : {}),\n parametersJsonSchema: schema,\n };\n case 'mcp':\n return {\n name,\n ...(description ? { description } : {}),\n inputSchema: schema,\n ...(def.outputSchema ? { outputSchema: clone(def.outputSchema) } : {}),\n ...(def.annotations ? { annotations: def.annotations } : {}),\n };\n default:\n throw new Error(`Unknown target: ${String(target satisfies never)}`);\n }\n}\n\nconst NAME_RULES: Record<Target, { pattern: RegExp; label: string }> = {\n openai: { pattern: /^[a-zA-Z0-9_-]{1,64}$/, label: 'OpenAI (letters, digits, _ and -, max 64)' },\n 'openai-strict': { pattern: /^[a-zA-Z0-9_-]{1,64}$/, label: 'OpenAI (letters, digits, _ and -, max 64)' },\n anthropic: { pattern: /^[a-zA-Z0-9_-]{1,64}$/, label: 'Anthropic (letters, digits, _ and -, max 64)' },\n gemini: { pattern: /^[a-zA-Z0-9_:.-]{1,128}$/, label: 'Gemini (letters, digits, _ : . -, max 128)' },\n 'gemini-jsonschema': { pattern: /^[a-zA-Z0-9_:.-]{1,128}$/, label: 'Gemini (letters, digits, _ : . -, max 128)' },\n mcp: { pattern: /^[a-zA-Z0-9_-]{1,128}$/, label: 'MCP (letters, digits, _ and -)' },\n};\n\nfunction validateName(name: string, target: Target, warnings: Warning[]): void {\n const rule = NAME_RULES[target];\n if (!rule.pattern.test(name)) {\n warnings.push({\n path: '#/name',\n code: 'invalid-name',\n message: `Tool name '${name}' does not match the ${rule.label} naming rule.`,\n });\n }\n}\n"],"mappings":";;;;AACA,qBAA6B;;;ACEtB,IAAM,WAAN,MAAe;AAAA,EACX,OAAkB,CAAC;AAAA,EAC5B,QAAQ;AAAA,EAER,IAAI,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,OAAO,MAAM,KAAK,EAAE,IAAI,MAAM,EAAE,IAAI,KAAK,EAAE,OAAO;AAAA,CAAI;AAAA,IAChE;AAAA,EACF;AACF;AAEA,KAAK;","names":[]}
1
+ {"version":3,"sources":["../src/cli.ts","../src/util.ts","../src/targets/openai.ts","../src/targets/anthropic.ts","../src/targets/gemini.ts","../src/targets/mcp.ts","../src/transform.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { readFileSync } from 'node:fs';\nimport { toToolSchema, toTool } from './transform.js';\nimport type { JSONSchema, Target, ToolSchemaOptions } from './types.js';\n\nconst TARGETS: Target[] = ['openai', 'openai-strict', 'anthropic', 'gemini', 'gemini-jsonschema', 'mcp'];\n\nconst HELP = `tool-schema - convert a JSON Schema into a provider valid tool schema\n\nUsage:\n tool-schema [file.json] --target <target> [options]\n cat schema.json | tool-schema --target gemini\n\nTargets:\n ${TARGETS.join(', ')}\n\nOptions:\n -t, --target <name> Provider target (default: openai)\n --tool <name> Wrap the result as a full tool definition with this name\n --description <text> Tool description (with --tool)\n --responses OpenAI: emit the Responses API tool shape\n --uppercase-types Gemini: emit upper case OpenAPI type names\n --quiet Do not print warnings to stderr\n -h, --help Show this help\n\nReads from the given file or from stdin. Prints the converted schema (or tool)\nas JSON to stdout. Warnings go to stderr and never pollute stdout.`;\n\ninterface Args {\n file?: string;\n target: Target;\n tool?: string;\n description?: string;\n responses: boolean;\n uppercase: boolean;\n quiet: boolean;\n help: boolean;\n}\n\nfunction parseArgs(argv: string[]): Args {\n const args: Args = {\n target: 'openai',\n responses: false,\n uppercase: false,\n quiet: false,\n help: false,\n };\n for (let i = 0; i < argv.length; i++) {\n const a = argv[i];\n switch (a) {\n case '-h':\n case '--help':\n args.help = true;\n break;\n case '-t':\n case '--target':\n args.target = argv[++i] as Target;\n break;\n case '--tool':\n args.tool = argv[++i];\n break;\n case '--description':\n args.description = argv[++i];\n break;\n case '--responses':\n args.responses = true;\n break;\n case '--uppercase-types':\n args.uppercase = true;\n break;\n case '--quiet':\n args.quiet = true;\n break;\n default:\n if (a.startsWith('-')) {\n throw new Error(`Unknown option: ${a}`);\n }\n args.file = a;\n }\n }\n return args;\n}\n\nfunction readInput(file?: string): string {\n if (file) return readFileSync(file, 'utf8');\n return readFileSync(0, 'utf8');\n}\n\nfunction main(): void {\n let args: Args;\n try {\n args = parseArgs(process.argv.slice(2));\n } catch (err) {\n process.stderr.write(`${(err as Error).message}\\n`);\n process.exit(2);\n }\n\n if (args.help) {\n process.stdout.write(`${HELP}\\n`);\n return;\n }\n\n if (!TARGETS.includes(args.target)) {\n process.stderr.write(`Invalid target '${args.target}'. Valid: ${TARGETS.join(', ')}\\n`);\n process.exit(2);\n }\n\n let schema: JSONSchema;\n try {\n schema = JSON.parse(readInput(args.file)) as JSONSchema;\n } catch (err) {\n process.stderr.write(`Could not read or parse input: ${(err as Error).message}\\n`);\n process.exit(1);\n return;\n }\n\n const options: ToolSchemaOptions = {\n target: args.target,\n openaiResponses: args.responses,\n geminiUppercaseTypes: args.uppercase,\n };\n\n const { output, warnings, lossy } = args.tool\n ? (() => {\n const r = toTool({ name: args.tool!, description: args.description, schema }, options);\n return { output: r.tool, warnings: r.warnings, lossy: r.lossy };\n })()\n : (() => {\n const r = toToolSchema(schema, options);\n return { output: r.schema, warnings: r.warnings, lossy: r.lossy };\n })();\n\n process.stdout.write(`${JSON.stringify(output, null, 2)}\\n`);\n\n if (!args.quiet && warnings.length > 0) {\n process.stderr.write(`\\n${warnings.length} warning(s) for target '${args.target}'${lossy ? ' (lossy)' : ''}:\\n`);\n for (const w of warnings) {\n process.stderr.write(` ${w.path} [${w.code}] ${w.message}\\n`);\n }\n }\n}\n\nmain();\n","import type { JSONSchema, Warning, WarningCode } from './types.js';\n\n/** Collects warnings and tracks whether the conversion lost information. */\nexport class Warnings {\n readonly list: Warning[] = [];\n lossy = false;\n\n add(path: string, code: WarningCode, message: string, lossy = true): void {\n this.list.push({ path, code, message });\n if (lossy) this.lossy = true;\n }\n}\n\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** A deep, structurally faithful clone. Uses the platform `structuredClone`. */\nexport function clone<T>(value: T): T {\n return structuredClone(value);\n}\n\n/** Returns the schema's declared types as an array (empty when untyped). */\nexport function typesOf(schema: JSONSchema): string[] {\n if (typeof schema.type === 'string') return [schema.type];\n if (Array.isArray(schema.type)) return schema.type.filter((t) => typeof t === 'string');\n return [];\n}\n\n/**\n * Heuristic: does this node describe an object? True when `type` is `object`\n * (or a union containing it) or when it is untyped but carries object keywords.\n */\nexport function isObjectSchema(schema: JSONSchema): boolean {\n const types = typesOf(schema);\n if (types.includes('object')) return true;\n if (types.length > 0) return false;\n return isPlainObject(schema.properties) || schema.additionalProperties !== undefined;\n}\n\n/**\n * Makes a schema accept `null`. Adds `null` to a string/array `type`, appends a\n * `{ type: 'null' }` branch to an `anyOf`, otherwise wraps the node in an\n * `anyOf` with a null branch. Used by OpenAI strict mode where every property\n * must be `required`, so optional fields are expressed as nullable instead.\n */\nexport function makeNullable(schema: JSONSchema): JSONSchema {\n if (typeof schema.type === 'string') {\n if (schema.type === 'null') return schema;\n return withNullEnum({ ...schema, type: [schema.type, 'null'] });\n }\n if (Array.isArray(schema.type)) {\n if (schema.type.includes('null')) return withNullEnum(schema);\n return withNullEnum({ ...schema, type: [...schema.type, 'null'] });\n }\n if (Array.isArray(schema.anyOf)) {\n if (schema.anyOf.some((b) => typesOf(b).includes('null'))) return schema;\n return { ...schema, anyOf: [...schema.anyOf, { type: 'null' }] };\n }\n return { anyOf: [schema, { type: 'null' }] };\n}\n\nfunction withNullEnum(schema: JSONSchema): JSONSchema {\n if (!Array.isArray(schema.enum) || schema.enum.some((value) => value === null)) {\n return schema;\n }\n return { ...schema, enum: [...schema.enum, null] };\n}\n\n/**\n * Resolves local `$ref` pointers (`#/$defs/...` or `#/definitions/...`) by\n * inlining them. Non local refs are left untouched. Recursive refs are replaced\n * with an empty schema and reported, since target dialects that need inlining\n * (Gemini route A) cannot express recursion.\n */\nexport function dereference(root: JSONSchema, warnings: Warnings): JSONSchema {\n const resolve = (ref: string): JSONSchema | undefined => {\n if (ref === '#') return root;\n if (!ref.startsWith('#/')) return undefined;\n\n let current: unknown = root;\n for (const segment of ref.slice(2).split('/').map(decodePointerSegment)) {\n if (!isPlainObject(current) && !Array.isArray(current)) return undefined;\n current = (current as Record<string, unknown>)[segment];\n }\n return isPlainObject(current) ? (current as JSONSchema) : undefined;\n };\n\n const walk = (node: JSONSchema, path: string, seen: Set<string>): JSONSchema => {\n if (!isPlainObject(node)) return node;\n if (typeof node.$ref === 'string') {\n const ref = node.$ref;\n const target = resolve(ref);\n if (!target) return node; // leave external / unknown refs in place\n if (seen.has(ref)) {\n warnings.add(path, 'recursive-ref', `Recursive $ref '${ref}' cannot be inlined; replaced with an open schema.`);\n return {};\n }\n const { $ref: _drop, ...rest } = node;\n void _drop;\n warnings.add(path, 'inlined-ref', `Inlined $ref '${ref}'.`, false);\n const merged = { ...clone(target), ...rest };\n return walk(merged, path, new Set([...seen, ref]));\n }\n const { $defs: _defs, definitions: _definitions, ...withoutDefinitions } = node;\n void _defs;\n void _definitions;\n return mapChildren(withoutDefinitions, path, (child, childPath) => walk(child, childPath, seen));\n };\n\n const out = walk(clone(root), '#', new Set());\n delete out.$defs;\n delete out.definitions;\n return out;\n}\n\nfunction decodePointerSegment(segment: string): string {\n try {\n return decodeURIComponent(segment).replace(/~1/g, '/').replace(/~0/g, '~');\n } catch {\n return segment.replace(/~1/g, '/').replace(/~0/g, '~');\n }\n}\n\nfunction encodePointerSegment(segment: string): string {\n return segment.replace(/~/g, '~0').replace(/\\//g, '~1');\n}\n\nexport function pointerPath(path: string, ...segments: Array<string | number>): string {\n return `${path}/${segments.map((segment) => encodePointerSegment(String(segment))).join('/')}`;\n}\n\n/**\n * Applies `fn` to every direct sub schema of `node`, returning a new node. Walks\n * the standard applicator keywords. Leaf keywords are copied as is.\n */\nexport function mapChildren(\n node: JSONSchema,\n path: string,\n fn: (child: JSONSchema, childPath: string) => JSONSchema,\n): JSONSchema {\n const out: JSONSchema = { ...node };\n\n if (isPlainObject(out.properties)) {\n const props: Record<string, JSONSchema> = {};\n for (const [k, v] of Object.entries(out.properties as Record<string, JSONSchema>)) {\n props[k] = fn(v, pointerPath(path, 'properties', k));\n }\n out.properties = props;\n }\n\n if (Array.isArray(out.items)) {\n out.items = out.items.map((it, i) => fn(it, pointerPath(path, 'items', i)));\n } else if (isPlainObject(out.items)) {\n out.items = fn(out.items as JSONSchema, pointerPath(path, 'items'));\n }\n\n if (isPlainObject(out.additionalProperties)) {\n out.additionalProperties = fn(out.additionalProperties as JSONSchema, pointerPath(path, 'additionalProperties'));\n }\n\n for (const key of ['anyOf', 'oneOf', 'allOf'] as const) {\n const arr = out[key];\n if (Array.isArray(arr)) {\n out[key] = arr.map((b, i) => fn(b, pointerPath(path, key, i)));\n }\n }\n\n if (isPlainObject(out.not)) out.not = fn(out.not as JSONSchema, pointerPath(path, 'not'));\n for (const key of ['if', 'then', 'else'] as const) {\n if (isPlainObject(out[key])) out[key] = fn(out[key] as JSONSchema, pointerPath(path, key));\n }\n\n if (isPlainObject(out.patternProperties)) {\n const pp: Record<string, JSONSchema> = {};\n for (const [k, v] of Object.entries(out.patternProperties as Record<string, JSONSchema>)) {\n pp[k] = fn(v, pointerPath(path, 'patternProperties', k));\n }\n out.patternProperties = pp;\n }\n\n for (const key of ['$defs', 'definitions', 'dependentSchemas'] as const) {\n const map = out[key];\n if (isPlainObject(map)) {\n const next: Record<string, JSONSchema> = {};\n for (const [k, v] of Object.entries(map as Record<string, JSONSchema>)) {\n next[k] = fn(v as JSONSchema, pointerPath(path, key, k));\n }\n out[key] = next;\n }\n }\n\n return out;\n}\n\n/** Ensures the root is an object schema, reporting when it was not. */\nexport function ensureObjectRoot(schema: JSONSchema, warnings: Warnings, target: string): JSONSchema {\n if (isObjectSchema(schema)) {\n if (typesOf(schema).length === 0) return { type: 'object', ...schema };\n return schema;\n }\n warnings.add(\n '#',\n 'root-not-object',\n `${target} requires the root schema to be an object; wrapped the schema under a 'value' property.`,\n );\n return {\n type: 'object',\n properties: { value: schema },\n required: ['value'],\n };\n}\n","import type { JSONSchema, TransformResult } from '../types.js';\nimport {\n Warnings,\n clone,\n isObjectSchema,\n isPlainObject,\n makeNullable,\n mapChildren,\n ensureObjectRoot,\n pointerPath,\n} from '../util.js';\n\n/** Formats OpenAI Structured Outputs accepts. Others are dropped in strict mode. */\nconst FORMAT_WHITELIST = new Set([\n 'date-time',\n 'time',\n 'date',\n 'duration',\n 'email',\n 'hostname',\n 'ipv4',\n 'ipv6',\n 'uuid',\n]);\n\n/** Keywords OpenAI strict mode rejects outright. */\nconst UNSUPPORTED = [\n 'not',\n 'if',\n 'then',\n 'else',\n 'dependentRequired',\n 'dependentSchemas',\n 'patternProperties',\n 'unevaluatedProperties',\n] as const;\n\nconst MAX_PROPERTIES = 5000;\nconst MAX_DEPTH = 10;\nconst MAX_ENUM_VALUES = 1000;\n\n/** OpenAI non strict: tool parameters should be an object, otherwise pass through. */\nexport function toOpenAI(input: JSONSchema): TransformResult {\n const warnings = new Warnings();\n const schema = ensureObjectRoot(clone(input), warnings, 'OpenAI');\n return { schema, warnings: warnings.list, lossy: warnings.lossy };\n}\n\n/**\n * OpenAI Structured Outputs / `strict: true`. Enforces: every object has\n * `additionalProperties: false`; every property is `required` (optional ones\n * become nullable); unsupported keywords are stripped; `allOf` is merged; only\n * whitelisted `format` values survive. `$defs` / `$ref` and `anyOf` are kept.\n */\nexport function toOpenAIStrict(input: JSONSchema): TransformResult {\n const warnings = new Warnings();\n\n const transform = (node: JSONSchema, path: string): JSONSchema => {\n if (!isPlainObject(node)) return node;\n let s: JSONSchema = { ...node };\n\n if (Array.isArray(s.allOf)) {\n s = mergeAllOf(s, path, warnings);\n }\n\n for (const kw of UNSUPPORTED) {\n if (kw in s) {\n delete s[kw];\n warnings.add(path, 'stripped-keyword', `'${kw}' is not supported in OpenAI strict mode; removed.`);\n }\n }\n\n if (typeof s.format === 'string' && !FORMAT_WHITELIST.has(s.format)) {\n warnings.add(\n `${path}/format`,\n 'unsupported-format',\n `format '${s.format}' is not in OpenAI's whitelist; removed.`,\n );\n delete s.format;\n }\n\n // Recurse into all sub schemas first (anyOf branches, items, $defs, ...).\n s = mapChildren(s, path, transform);\n\n if (isObjectSchema(s) && isPlainObject(s.properties)) {\n const props = s.properties as Record<string, JSONSchema>;\n const originalRequired = new Set(Array.isArray(s.required) ? s.required : []);\n const nextProps: Record<string, JSONSchema> = {};\n for (const key of Object.keys(props)) {\n let child = props[key];\n if (!originalRequired.has(key)) {\n child = makeNullable(child);\n warnings.add(\n pointerPath(path, 'properties', key),\n 'forced-required',\n `Optional property '${key}' was made required and nullable for OpenAI strict mode.`,\n );\n }\n nextProps[key] = child;\n }\n s.properties = nextProps;\n s.required = Object.keys(nextProps);\n if (s.additionalProperties !== false) {\n warnings.add(\n path,\n 'forced-additional-properties',\n \"Set 'additionalProperties: false' as required by strict mode.\",\n false,\n );\n }\n s.additionalProperties = false;\n } else if (isObjectSchema(s)) {\n // Object without declared properties: strict mode still forbids extra keys.\n if (s.additionalProperties !== false) {\n warnings.add(\n path,\n 'forced-additional-properties',\n \"Set 'additionalProperties: false' on a property-less object.\",\n false,\n );\n }\n s.additionalProperties = false;\n }\n\n return s;\n };\n\n const schema = ensureObjectRoot(transform(clone(input), '#'), warnings, 'OpenAI strict mode');\n checkLimits(schema, warnings);\n return { schema, warnings: warnings.list, lossy: warnings.lossy };\n}\n\n/** Shallow merges `allOf` object subschemas into the parent, then drops `allOf`. */\nfunction mergeAllOf(node: JSONSchema, path: string, warnings: Warnings): JSONSchema {\n const parts = node.allOf as JSONSchema[];\n const { allOf: _drop, ...base } = node;\n void _drop;\n const merged: JSONSchema = { ...base };\n const props: Record<string, JSONSchema> = isPlainObject(merged.properties)\n ? { ...(merged.properties as Record<string, JSONSchema>) }\n : {};\n const required = new Set<string>(Array.isArray(merged.required) ? merged.required : []);\n\n for (const part of parts) {\n if (!isPlainObject(part)) continue;\n if (isPlainObject(part.properties)) {\n Object.assign(props, part.properties);\n }\n if (Array.isArray(part.required)) {\n for (const r of part.required) required.add(r);\n }\n if (part.type && !merged.type) merged.type = part.type;\n }\n\n if (Object.keys(props).length > 0) merged.properties = props;\n if (required.size > 0) merged.required = [...required];\n if (!merged.type && (merged.properties || isObjectSchema(merged))) merged.type = 'object';\n warnings.add(path, 'merged-allof', \"Merged 'allOf' subschemas into the parent (unsupported in strict mode).\");\n return merged;\n}\n\nfunction checkLimits(schema: JSONSchema, warnings: Warnings): void {\n let propertyCount = 0;\n let maxDepth = 0;\n\n const visit = (node: JSONSchema, depth: number): void => {\n if (!isPlainObject(node)) return;\n maxDepth = Math.max(maxDepth, depth);\n if (isPlainObject(node.properties)) {\n const keys = Object.keys(node.properties as Record<string, JSONSchema>);\n propertyCount += keys.length;\n }\n if (Array.isArray(node.enum) && node.enum.length > MAX_ENUM_VALUES) {\n warnings.add(\n '#',\n 'limit-exceeded',\n `An enum has ${node.enum.length} values; OpenAI allows at most ${MAX_ENUM_VALUES}.`,\n false,\n );\n }\n const children = collectChildren(node);\n for (const c of children) visit(c, depth + 1);\n };\n\n visit(schema, 0);\n if (propertyCount > MAX_PROPERTIES) {\n warnings.add(\n '#',\n 'limit-exceeded',\n `Schema has ${propertyCount} object properties; OpenAI allows at most ${MAX_PROPERTIES}.`,\n false,\n );\n }\n if (maxDepth > MAX_DEPTH) {\n warnings.add(\n '#',\n 'limit-exceeded',\n `Schema nests ${maxDepth} levels deep; OpenAI allows at most ${MAX_DEPTH}.`,\n false,\n );\n }\n}\n\nfunction collectChildren(node: JSONSchema): JSONSchema[] {\n const out: JSONSchema[] = [];\n if (isPlainObject(node.properties)) out.push(...Object.values(node.properties as Record<string, JSONSchema>));\n if (Array.isArray(node.items)) out.push(...node.items);\n else if (isPlainObject(node.items)) out.push(node.items as JSONSchema);\n for (const key of ['anyOf', 'oneOf', 'allOf'] as const) {\n const arr = node[key];\n if (Array.isArray(arr)) out.push(...arr);\n }\n if (isPlainObject(node.$defs)) out.push(...Object.values(node.$defs as Record<string, JSONSchema>));\n return out.filter(isPlainObject) as JSONSchema[];\n}\n","import type { JSONSchema, TransformResult } from '../types.js';\nimport { Warnings, clone, ensureObjectRoot } from '../util.js';\n\n/**\n * Anthropic tool use. The API is permissive: it accepts standard JSON Schema for\n * `input_schema` (anyOf, oneOf, allOf, $ref, format, pattern, ...). The only hard\n * requirement is that the root is an object, so that is all we enforce.\n */\nexport function toAnthropic(input: JSONSchema): TransformResult {\n const warnings = new Warnings();\n const schema = ensureObjectRoot(clone(input), warnings, 'Anthropic');\n return { schema, warnings: warnings.list, lossy: warnings.lossy };\n}\n","import type { JSONSchema, TransformResult } from '../types.js';\nimport { Warnings, clone, dereference, ensureObjectRoot, isPlainObject, mapChildren, typesOf } from '../util.js';\n\n/**\n * Keywords absent from Gemini's `Schema` proto (route A). Sending them either\n * errors or is silently ignored, so they are stripped.\n */\nconst STRIP = [\n '$schema',\n '$id',\n '$anchor',\n '$ref',\n 'oneOf',\n 'allOf',\n 'not',\n 'if',\n 'then',\n 'else',\n 'additionalProperties',\n 'patternProperties',\n 'unevaluatedProperties',\n 'const',\n 'dependentRequired',\n 'dependentSchemas',\n 'multipleOf',\n 'exclusiveMinimum',\n 'exclusiveMaximum',\n 'uniqueItems',\n 'contentEncoding',\n 'contentMediaType',\n '$defs',\n 'definitions',\n] as const;\n\nconst TYPE_UPPER: Record<string, string> = {\n string: 'STRING',\n number: 'NUMBER',\n integer: 'INTEGER',\n boolean: 'BOOLEAN',\n array: 'ARRAY',\n object: 'OBJECT',\n null: 'NULL',\n};\n\ninterface GeminiOptions {\n uppercaseTypes?: boolean;\n}\n\n/**\n * Gemini function calling, route A (`parameters` as an OpenAPI 3.0 subset).\n * Inlines `$ref`, strips unsupported keywords, converts nullable unions to\n * `nullable: true`, collapses `anyOf` null branches, and coerces enum values to\n * strings. Use the `gemini-jsonschema` target for the richer\n * `parametersJsonSchema` route.\n */\nexport function toGemini(input: JSONSchema, options: GeminiOptions = {}): TransformResult {\n const warnings = new Warnings();\n const dereferenced = dereference(clone(input), warnings);\n\n const transform = (node: JSONSchema, path: string): JSONSchema => {\n if (!isPlainObject(node)) return node;\n let s: JSONSchema = { ...node };\n\n for (const kw of STRIP) {\n if (kw in s) {\n delete s[kw];\n warnings.add(path, 'stripped-keyword', `'${kw}' is not supported by Gemini (route A); removed.`);\n }\n }\n\n s = collapseNullableUnion(s, path, warnings);\n s = mapChildren(s, path, transform);\n s = collapseAnyOf(s, path, warnings);\n coerceEnum(s, path, warnings);\n return s;\n };\n\n let schema = ensureObjectRoot(transform(dereferenced, '#'), warnings, 'Gemini');\n if (options.uppercaseTypes) schema = uppercaseTypes(schema);\n return { schema, warnings: warnings.list, lossy: warnings.lossy };\n}\n\n/** Final pass: rewrite JSON Schema type names to Gemini's upper case enum. */\nfunction uppercaseTypes(node: JSONSchema): JSONSchema {\n if (!isPlainObject(node)) return node;\n const out: JSONSchema = { ...node };\n if (typeof out.type === 'string') {\n out.type = TYPE_UPPER[out.type] ?? out.type;\n } else if (Array.isArray(out.type)) {\n out.type = out.type.map((t) => TYPE_UPPER[t] ?? t);\n }\n return mapChildren(out, '#', (child) => uppercaseTypes(child));\n}\n\n/** Gemini route B (`parametersJsonSchema`): richer JSON Schema, object root only. */\nexport function toGeminiJsonSchema(input: JSONSchema): TransformResult {\n const warnings = new Warnings();\n const schema = ensureObjectRoot(clone(input), warnings, 'Gemini (parametersJsonSchema)');\n return { schema, warnings: warnings.list, lossy: warnings.lossy };\n}\n\n/** Converts `type: ['string', 'null']` into `type: 'string', nullable: true`. */\nfunction collapseNullableUnion(node: JSONSchema, path: string, warnings: Warnings): JSONSchema {\n if (!Array.isArray(node.type)) return node;\n const nonNull = node.type.filter((t) => t !== 'null');\n const hadNull = node.type.includes('null');\n const out: JSONSchema = { ...node };\n if (nonNull.length === 0) {\n out.type = 'string';\n } else {\n out.type = nonNull[0];\n if (nonNull.length > 1) {\n warnings.add(\n path,\n 'union-types',\n `Gemini cannot express a union of types [${nonNull.join(', ')}]; kept '${nonNull[0]}'.`,\n );\n }\n }\n if (hadNull) {\n out.nullable = true;\n warnings.add(path, 'collapsed-nullable', \"Converted nullable type union into 'nullable: true'.\", false);\n }\n return out;\n}\n\n/** Removes `{ type: 'null' }` branches from `anyOf`, mapping them to `nullable`. */\nfunction collapseAnyOf(node: JSONSchema, path: string, warnings: Warnings): JSONSchema {\n if (!Array.isArray(node.anyOf)) return node;\n const branches = node.anyOf as JSONSchema[];\n const nonNull = branches.filter((b) => !(typesOf(b).length === 1 && typesOf(b)[0] === 'null'));\n const hadNull = nonNull.length !== branches.length;\n const out: JSONSchema = { ...node };\n\n if (hadNull) {\n out.nullable = true;\n warnings.add(path, 'collapsed-nullable', \"Converted an anyOf null branch into 'nullable: true'.\", false);\n }\n\n if (nonNull.length === 0) {\n delete out.anyOf;\n if (!out.type) out.type = 'string';\n } else if (nonNull.length === 1) {\n // Flatten a single remaining branch into the parent.\n delete out.anyOf;\n const branch = nonNull[0];\n for (const [k, v] of Object.entries(branch)) {\n if (k === 'description' && out.description) continue;\n out[k] = v;\n }\n } else {\n out.anyOf = nonNull;\n }\n return out;\n}\n\n/** Gemini enum values must be strings. Coerces and reports when they were not. */\nfunction coerceEnum(node: JSONSchema, path: string, warnings: Warnings): void {\n if (!Array.isArray(node.enum)) return;\n const allStrings = node.enum.every((v) => typeof v === 'string');\n if (!allStrings) {\n node.enum = node.enum.map((v) => String(v));\n warnings.add(`${path}/enum`, 'enum-coerced', 'Gemini enum values must be strings; coerced non string values.');\n }\n if (!node.type) node.type = 'string';\n}\n","import type { JSONSchema, TransformResult } from '../types.js';\nimport { Warnings, clone, ensureObjectRoot } from '../util.js';\n\n/**\n * MCP (Model Context Protocol) tools. The most permissive input target:\n * `inputSchema` is standard JSON Schema and the spec only requires the root to\n * be an object. All input keywords are preserved. MCP `outputSchema` is handled\n * at the tool envelope layer because it describes `structuredContent` and does\n * not share the input object-root constraint.\n */\nexport function toMcp(input: JSONSchema): TransformResult {\n const warnings = new Warnings();\n const schema = ensureObjectRoot(clone(input), warnings, 'MCP');\n return { schema, warnings: warnings.list, lossy: warnings.lossy };\n}\n","import type {\n JSONSchema,\n LintResult,\n Target,\n ToolDefinition,\n ToolResult,\n ToolSchemaOptions,\n TransformResult,\n Warning,\n} from './types.js';\nimport { toOpenAI, toOpenAIStrict } from './targets/openai.js';\nimport { toAnthropic } from './targets/anthropic.js';\nimport { toGemini, toGeminiJsonSchema } from './targets/gemini.js';\nimport { toMcp } from './targets/mcp.js';\nimport { clone } from './util.js';\n\nconst EMPTY_OBJECT_SCHEMA: JSONSchema = { type: 'object', properties: {} };\n\n/**\n * Convert any JSON Schema into a schema that is valid for a provider's tool /\n * function calling parameters.\n *\n * @example\n * const { schema, warnings } = toToolSchema(mySchema, { target: 'openai-strict' });\n */\nexport function toToolSchema(schema: JSONSchema, options: ToolSchemaOptions = {}): TransformResult {\n const target = options.target ?? 'openai';\n switch (target) {\n case 'openai':\n return toOpenAI(schema);\n case 'openai-strict':\n return toOpenAIStrict(schema);\n case 'anthropic':\n return toAnthropic(schema);\n case 'gemini':\n return toGemini(schema, { uppercaseTypes: options.geminiUppercaseTypes });\n case 'gemini-jsonschema':\n return toGeminiJsonSchema(schema);\n case 'mcp':\n return toMcp(schema);\n default:\n throw new Error(`Unknown target: ${String(target satisfies never)}`);\n }\n}\n\n/**\n * Build a complete, provider shaped tool / function declaration: the right\n * wrapper keys (`function`, `input_schema`, `parameters`, `inputSchema`), the\n * converted parameter schema, and provider specific extras such as `strict` or\n * MCP `annotations`.\n */\nexport function toTool(def: ToolDefinition, options: ToolSchemaOptions = {}): ToolResult {\n const target = options.target ?? 'openai';\n const result = toToolSchema(def.schema ?? EMPTY_OBJECT_SCHEMA, options);\n const warnings: Warning[] = [...result.warnings];\n validateName(def.name, target, warnings);\n\n const tool = buildTool(def, result.schema, target, options);\n return { tool, warnings, lossy: result.lossy };\n}\n\n/**\n * Report what would change to make `schema` valid for a target, without\n * applying it. `ok` is true when the schema is already conformant.\n */\nexport function lintToolSchema(schema: JSONSchema, options: ToolSchemaOptions = {}): LintResult {\n const { warnings } = toToolSchema(schema, options);\n return { ok: warnings.length === 0, issues: warnings };\n}\n\nfunction buildTool(\n def: ToolDefinition,\n schema: JSONSchema,\n target: Target,\n options: ToolSchemaOptions,\n): Record<string, unknown> {\n const { name, description } = def;\n\n switch (target) {\n case 'openai':\n case 'openai-strict': {\n const strict = target === 'openai-strict';\n if (options.openaiResponses) {\n return {\n type: 'function',\n name,\n ...(description ? { description } : {}),\n parameters: schema,\n ...(strict ? { strict: true } : {}),\n };\n }\n return {\n type: 'function',\n function: {\n name,\n ...(description ? { description } : {}),\n parameters: schema,\n ...(strict ? { strict: true } : {}),\n },\n };\n }\n case 'anthropic':\n return {\n name,\n ...(description ? { description } : {}),\n input_schema: schema,\n ...(options.anthropicStrict ? { strict: true } : {}),\n };\n case 'gemini':\n return {\n name,\n ...(description ? { description } : {}),\n parameters: schema,\n };\n case 'gemini-jsonschema':\n return {\n name,\n ...(description ? { description } : {}),\n parametersJsonSchema: schema,\n };\n case 'mcp':\n return {\n name,\n ...(description ? { description } : {}),\n inputSchema: schema,\n ...(def.outputSchema ? { outputSchema: clone(def.outputSchema) } : {}),\n ...(def.annotations ? { annotations: def.annotations } : {}),\n };\n default:\n throw new Error(`Unknown target: ${String(target satisfies never)}`);\n }\n}\n\nconst NAME_RULES: Record<Target, { pattern: RegExp; label: string }> = {\n openai: { pattern: /^[a-zA-Z0-9_-]{1,64}$/, label: 'OpenAI (letters, digits, _ and -, max 64)' },\n 'openai-strict': { pattern: /^[a-zA-Z0-9_-]{1,64}$/, label: 'OpenAI (letters, digits, _ and -, max 64)' },\n anthropic: { pattern: /^[a-zA-Z0-9_-]{1,64}$/, label: 'Anthropic (letters, digits, _ and -, max 64)' },\n gemini: { pattern: /^[a-zA-Z0-9_:.-]{1,128}$/, label: 'Gemini (letters, digits, _ : . -, max 128)' },\n 'gemini-jsonschema': { pattern: /^[a-zA-Z0-9_:.-]{1,128}$/, label: 'Gemini (letters, digits, _ : . -, max 128)' },\n mcp: { pattern: /^[a-zA-Z0-9_-]{1,128}$/, label: 'MCP (letters, digits, _ and -)' },\n};\n\nfunction validateName(name: string, target: Target, warnings: Warning[]): void {\n const rule = NAME_RULES[target];\n if (!rule.pattern.test(name)) {\n warnings.push({\n path: '#/name',\n code: 'invalid-name',\n message: `Tool name '${name}' does not match the ${rule.label} naming rule.`,\n });\n }\n}\n"],"mappings":";;;;AACA,qBAA6B;;;ACEtB,IAAM,WAAN,MAAe;AAAA,EACX,OAAkB,CAAC;AAAA,EAC5B,QAAQ;AAAA,EAER,IAAI,MAAc,MAAmB,SAAiB,QAAQ,MAAY;AACxE,SAAK,KAAK,KAAK,EAAE,MAAM,MAAM,QAAQ,CAAC;AACtC,QAAI,MAAO,MAAK,QAAQ;AAAA,EAC1B;AACF;AAEO,SAAS,cAAc,OAAkD;AAC9E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAGO,SAAS,MAAS,OAAa;AACpC,SAAO,gBAAgB,KAAK;AAC9B;AAGO,SAAS,QAAQ,QAA8B;AACpD,MAAI,OAAO,OAAO,SAAS,SAAU,QAAO,CAAC,OAAO,IAAI;AACxD,MAAI,MAAM,QAAQ,OAAO,IAAI,EAAG,QAAO,OAAO,KAAK,OAAO,CAAC,MAAM,OAAO,MAAM,QAAQ;AACtF,SAAO,CAAC;AACV;AAMO,SAAS,eAAe,QAA6B;AAC1D,QAAM,QAAQ,QAAQ,MAAM;AAC5B,MAAI,MAAM,SAAS,QAAQ,EAAG,QAAO;AACrC,MAAI,MAAM,SAAS,EAAG,QAAO;AAC7B,SAAO,cAAc,OAAO,UAAU,KAAK,OAAO,yBAAyB;AAC7E;AAQO,SAAS,aAAa,QAAgC;AAC3D,MAAI,OAAO,OAAO,SAAS,UAAU;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K,UAAU;AACxB,cAAQ,OAAO,MAAM,KAAK,EAAE,IAAI,MAAM,EAAE,IAAI,KAAK,EAAE,OAAO;AAAA,CAAI;AAAA,IAChE;AAAA,EACF;AACF;AAEA,KAAK;","names":[]}
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  toTool,
4
4
  toToolSchema
5
- } from "./chunk-HM2FG6DI.js";
5
+ } from "./chunk-5J6BWTJC.js";
6
6
 
7
7
  // src/cli.ts
8
8
  import { readFileSync } from "fs";
package/dist/index.cjs CHANGED
@@ -57,11 +57,11 @@ function isObjectSchema(schema) {
57
57
  function makeNullable(schema) {
58
58
  if (typeof schema.type === "string") {
59
59
  if (schema.type === "null") return schema;
60
- return { ...schema, type: [schema.type, "null"] };
60
+ return withNullEnum({ ...schema, type: [schema.type, "null"] });
61
61
  }
62
62
  if (Array.isArray(schema.type)) {
63
- if (schema.type.includes("null")) return schema;
64
- return { ...schema, type: [...schema.type, "null"] };
63
+ if (schema.type.includes("null")) return withNullEnum(schema);
64
+ return withNullEnum({ ...schema, type: [...schema.type, "null"] });
65
65
  }
66
66
  if (Array.isArray(schema.anyOf)) {
67
67
  if (schema.anyOf.some((b) => typesOf(b).includes("null"))) return schema;
@@ -69,16 +69,22 @@ function makeNullable(schema) {
69
69
  }
70
70
  return { anyOf: [schema, { type: "null" }] };
71
71
  }
72
+ function withNullEnum(schema) {
73
+ if (!Array.isArray(schema.enum) || schema.enum.some((value) => value === null)) {
74
+ return schema;
75
+ }
76
+ return { ...schema, enum: [...schema.enum, null] };
77
+ }
72
78
  function dereference(root, warnings) {
73
- const defs = {
74
- ...isPlainObject(root.definitions) ? root.definitions : {},
75
- ...isPlainObject(root.$defs) ? root.$defs : {}
76
- };
77
79
  const resolve = (ref) => {
78
- const m = /^#\/(?:\$defs|definitions)\/(.+)$/.exec(ref);
79
- if (!m) return void 0;
80
- const key = decodeURIComponent(m[1].replace(/~1/g, "/").replace(/~0/g, "~"));
81
- return defs[key];
80
+ if (ref === "#") return root;
81
+ if (!ref.startsWith("#/")) return void 0;
82
+ let current = root;
83
+ for (const segment of ref.slice(2).split("/").map(decodePointerSegment)) {
84
+ if (!isPlainObject(current) && !Array.isArray(current)) return void 0;
85
+ current = current[segment];
86
+ }
87
+ return isPlainObject(current) ? current : void 0;
82
88
  };
83
89
  const walk = (node, path, seen) => {
84
90
  if (!isPlainObject(node)) return node;
@@ -96,44 +102,60 @@ function dereference(root, warnings) {
96
102
  const merged = { ...clone(target), ...rest };
97
103
  return walk(merged, path, /* @__PURE__ */ new Set([...seen, ref]));
98
104
  }
99
- return mapChildren(node, path, (child, childPath) => walk(child, childPath, seen));
105
+ const { $defs: _defs, definitions: _definitions, ...withoutDefinitions } = node;
106
+ void _defs;
107
+ void _definitions;
108
+ return mapChildren(withoutDefinitions, path, (child, childPath) => walk(child, childPath, seen));
100
109
  };
101
110
  const out = walk(clone(root), "#", /* @__PURE__ */ new Set());
102
111
  delete out.$defs;
103
112
  delete out.definitions;
104
113
  return out;
105
114
  }
115
+ function decodePointerSegment(segment) {
116
+ try {
117
+ return decodeURIComponent(segment).replace(/~1/g, "/").replace(/~0/g, "~");
118
+ } catch {
119
+ return segment.replace(/~1/g, "/").replace(/~0/g, "~");
120
+ }
121
+ }
122
+ function encodePointerSegment(segment) {
123
+ return segment.replace(/~/g, "~0").replace(/\//g, "~1");
124
+ }
125
+ function pointerPath(path, ...segments) {
126
+ return `${path}/${segments.map((segment) => encodePointerSegment(String(segment))).join("/")}`;
127
+ }
106
128
  function mapChildren(node, path, fn) {
107
129
  const out = { ...node };
108
130
  if (isPlainObject(out.properties)) {
109
131
  const props = {};
110
132
  for (const [k, v] of Object.entries(out.properties)) {
111
- props[k] = fn(v, `${path}/properties/${k}`);
133
+ props[k] = fn(v, pointerPath(path, "properties", k));
112
134
  }
113
135
  out.properties = props;
114
136
  }
115
137
  if (Array.isArray(out.items)) {
116
- out.items = out.items.map((it, i) => fn(it, `${path}/items/${i}`));
138
+ out.items = out.items.map((it, i) => fn(it, pointerPath(path, "items", i)));
117
139
  } else if (isPlainObject(out.items)) {
118
- out.items = fn(out.items, `${path}/items`);
140
+ out.items = fn(out.items, pointerPath(path, "items"));
119
141
  }
120
142
  if (isPlainObject(out.additionalProperties)) {
121
- out.additionalProperties = fn(out.additionalProperties, `${path}/additionalProperties`);
143
+ out.additionalProperties = fn(out.additionalProperties, pointerPath(path, "additionalProperties"));
122
144
  }
123
145
  for (const key of ["anyOf", "oneOf", "allOf"]) {
124
146
  const arr = out[key];
125
147
  if (Array.isArray(arr)) {
126
- out[key] = arr.map((b, i) => fn(b, `${path}/${key}/${i}`));
148
+ out[key] = arr.map((b, i) => fn(b, pointerPath(path, key, i)));
127
149
  }
128
150
  }
129
- if (isPlainObject(out.not)) out.not = fn(out.not, `${path}/not`);
151
+ if (isPlainObject(out.not)) out.not = fn(out.not, pointerPath(path, "not"));
130
152
  for (const key of ["if", "then", "else"]) {
131
- if (isPlainObject(out[key])) out[key] = fn(out[key], `${path}/${key}`);
153
+ if (isPlainObject(out[key])) out[key] = fn(out[key], pointerPath(path, key));
132
154
  }
133
155
  if (isPlainObject(out.patternProperties)) {
134
156
  const pp = {};
135
157
  for (const [k, v] of Object.entries(out.patternProperties)) {
136
- pp[k] = fn(v, `${path}/patternProperties/${k}`);
158
+ pp[k] = fn(v, pointerPath(path, "patternProperties", k));
137
159
  }
138
160
  out.patternProperties = pp;
139
161
  }
@@ -142,7 +164,7 @@ function mapChildren(node, path, fn) {
142
164
  if (isPlainObject(map)) {
143
165
  const next = {};
144
166
  for (const [k, v] of Object.entries(map)) {
145
- next[k] = fn(v, `${path}/${key}/${k}`);
167
+ next[k] = fn(v, pointerPath(path, key, k));
146
168
  }
147
169
  out[key] = next;
148
170
  }
@@ -228,7 +250,7 @@ function toOpenAIStrict(input) {
228
250
  if (!originalRequired.has(key)) {
229
251
  child = makeNullable(child);
230
252
  warnings.add(
231
- `${path}/properties/${key}`,
253
+ pointerPath(path, "properties", key),
232
254
  "forced-required",
233
255
  `Optional property '${key}' was made required and nullable for OpenAI strict mode.`
234
256
  );