@langchain/openai 1.3.0-dev-1773962633795 → 1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"client.cjs","names":["APIConnectionTimeoutError","APIUserAbortError","ContextOverflowError","addLangChainErrorFields"],"sources":["../../src/utils/client.ts"],"sourcesContent":["import { APIConnectionTimeoutError, APIUserAbortError } from \"openai\";\nimport { ContextOverflowError } from \"@langchain/core/errors\";\nimport { addLangChainErrorFields } from \"./errors.js\";\n\nfunction _isOpenAIContextOverflowError(e: object): boolean {\n const errorStr = String(e);\n if (errorStr.includes(\"context_length_exceeded\")) {\n return true;\n }\n if (\n \"message\" in e &&\n typeof e.message === \"string\" &&\n (e.message.includes(\"Input tokens exceed the configured limit\") ||\n e.message.includes(\"exceeds the context window\"))\n ) {\n return true;\n }\n return false;\n}\n\nexport function wrapOpenAIClientError(e: unknown) {\n if (!e || typeof e !== \"object\") {\n return e;\n }\n\n let error;\n if (\n e.constructor.name === APIConnectionTimeoutError.name &&\n \"message\" in e &&\n typeof e.message === \"string\"\n ) {\n error = new Error(e.message);\n error.name = \"TimeoutError\";\n } else if (\n e.constructor.name === APIUserAbortError.name &&\n \"message\" in e &&\n typeof e.message === \"string\"\n ) {\n error = new Error(e.message);\n error.name = \"AbortError\";\n } else if (_isOpenAIContextOverflowError(e)) {\n error = ContextOverflowError.fromError(e as Error);\n } else if (\n \"status\" in e &&\n e.status === 400 &&\n \"message\" in e &&\n typeof e.message === \"string\" &&\n e.message.includes(\"tool_calls\")\n ) {\n error = addLangChainErrorFields(e, \"INVALID_TOOL_RESULTS\");\n } else if (\"status\" in e && e.status === 401) {\n error = addLangChainErrorFields(e, \"MODEL_AUTHENTICATION\");\n } else if (\"status\" in e && e.status === 429) {\n error = addLangChainErrorFields(e, \"MODEL_RATE_LIMIT\");\n } else if (\"status\" in e && e.status === 404) {\n error = addLangChainErrorFields(e, \"MODEL_NOT_FOUND\");\n } else {\n error = e;\n }\n return error;\n}\n"],"mappings":";;;;AAIA,SAAS,8BAA8B,GAAoB;AAEzD,KADiB,OAAO,EAAE,CACb,SAAS,0BAA0B,CAC9C,QAAO;AAET,KACE,aAAa,KACb,OAAO,EAAE,YAAY,aACpB,EAAE,QAAQ,SAAS,2CAA2C,IAC7D,EAAE,QAAQ,SAAS,6BAA6B,EAElD,QAAO;AAET,QAAO;;AAGT,SAAgB,sBAAsB,GAAY;AAChD,KAAI,CAAC,KAAK,OAAO,MAAM,SACrB,QAAO;CAGT,IAAI;AACJ,KACE,EAAE,YAAY,SAASA,OAAAA,0BAA0B,QACjD,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;AACA,UAAQ,IAAI,MAAM,EAAE,QAAQ;AAC5B,QAAM,OAAO;YAEb,EAAE,YAAY,SAASC,OAAAA,kBAAkB,QACzC,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;AACA,UAAQ,IAAI,MAAM,EAAE,QAAQ;AAC5B,QAAM,OAAO;YACJ,8BAA8B,EAAE,CACzC,SAAQC,uBAAAA,qBAAqB,UAAU,EAAW;UAElD,YAAY,KACZ,EAAE,WAAW,OACb,aAAa,KACb,OAAO,EAAE,YAAY,YACrB,EAAE,QAAQ,SAAS,aAAa,CAEhC,SAAQC,eAAAA,wBAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQA,eAAAA,wBAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQA,eAAAA,wBAAwB,GAAG,mBAAmB;UAC7C,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQA,eAAAA,wBAAwB,GAAG,kBAAkB;KAErD,SAAQ;AAEV,QAAO"}
1
+ {"version":3,"file":"client.cjs","names":["APIConnectionTimeoutError","APIUserAbortError","ContextOverflowError","addLangChainErrorFields"],"sources":["../../src/utils/client.ts"],"sourcesContent":["import { APIConnectionTimeoutError, APIUserAbortError } from \"openai\";\nimport { ContextOverflowError } from \"@langchain/core/errors\";\nimport { addLangChainErrorFields } from \"./errors.js\";\n\nfunction _isOpenAIContextOverflowError(e: object): boolean {\n const errorStr = String(e);\n if (errorStr.includes(\"context_length_exceeded\")) {\n return true;\n }\n if (\n \"message\" in e &&\n typeof e.message === \"string\" &&\n (e.message.includes(\"Input tokens exceed the configured limit\") ||\n e.message.includes(\"exceeds the context window\") ||\n e.message.includes(\"maximum context length\"))\n ) {\n return true;\n }\n return false;\n}\n\nexport function wrapOpenAIClientError(e: unknown) {\n if (!e || typeof e !== \"object\") {\n return e;\n }\n\n let error;\n if (\n e.constructor.name === APIConnectionTimeoutError.name &&\n \"message\" in e &&\n typeof e.message === \"string\"\n ) {\n error = new Error(e.message);\n error.name = \"TimeoutError\";\n } else if (\n e.constructor.name === APIUserAbortError.name &&\n \"message\" in e &&\n typeof e.message === \"string\"\n ) {\n error = new Error(e.message);\n error.name = \"AbortError\";\n } else if (_isOpenAIContextOverflowError(e)) {\n error = ContextOverflowError.fromError(e as Error);\n } else if (\n \"status\" in e &&\n e.status === 400 &&\n \"message\" in e &&\n typeof e.message === \"string\" &&\n e.message.includes(\"tool_calls\")\n ) {\n error = addLangChainErrorFields(e, \"INVALID_TOOL_RESULTS\");\n } else if (\"status\" in e && e.status === 401) {\n error = addLangChainErrorFields(e, \"MODEL_AUTHENTICATION\");\n } else if (\"status\" in e && e.status === 429) {\n error = addLangChainErrorFields(e, \"MODEL_RATE_LIMIT\");\n } else if (\"status\" in e && e.status === 404) {\n error = addLangChainErrorFields(e, \"MODEL_NOT_FOUND\");\n } else {\n error = e;\n }\n return error;\n}\n"],"mappings":";;;;AAIA,SAAS,8BAA8B,GAAoB;AAEzD,KADiB,OAAO,EAAE,CACb,SAAS,0BAA0B,CAC9C,QAAO;AAET,KACE,aAAa,KACb,OAAO,EAAE,YAAY,aACpB,EAAE,QAAQ,SAAS,2CAA2C,IAC7D,EAAE,QAAQ,SAAS,6BAA6B,IAChD,EAAE,QAAQ,SAAS,yBAAyB,EAE9C,QAAO;AAET,QAAO;;AAGT,SAAgB,sBAAsB,GAAY;AAChD,KAAI,CAAC,KAAK,OAAO,MAAM,SACrB,QAAO;CAGT,IAAI;AACJ,KACE,EAAE,YAAY,SAASA,OAAAA,0BAA0B,QACjD,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;AACA,UAAQ,IAAI,MAAM,EAAE,QAAQ;AAC5B,QAAM,OAAO;YAEb,EAAE,YAAY,SAASC,OAAAA,kBAAkB,QACzC,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;AACA,UAAQ,IAAI,MAAM,EAAE,QAAQ;AAC5B,QAAM,OAAO;YACJ,8BAA8B,EAAE,CACzC,SAAQC,uBAAAA,qBAAqB,UAAU,EAAW;UAElD,YAAY,KACZ,EAAE,WAAW,OACb,aAAa,KACb,OAAO,EAAE,YAAY,YACrB,EAAE,QAAQ,SAAS,aAAa,CAEhC,SAAQC,eAAAA,wBAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQA,eAAAA,wBAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQA,eAAAA,wBAAwB,GAAG,mBAAmB;UAC7C,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQA,eAAAA,wBAAwB,GAAG,kBAAkB;KAErD,SAAQ;AAEV,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.cts","names":[],"sources":["../../src/utils/client.ts"],"mappings":";iBAoBgB,qBAAA,CAAsB,CAAA"}
1
+ {"version":3,"file":"client.d.cts","names":[],"sources":["../../src/utils/client.ts"],"mappings":";iBAqBgB,qBAAA,CAAsB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","names":[],"sources":["../../src/utils/client.ts"],"mappings":";iBAoBgB,qBAAA,CAAsB,CAAA"}
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../../src/utils/client.ts"],"mappings":";iBAqBgB,qBAAA,CAAsB,CAAA"}
@@ -4,7 +4,7 @@ import { ContextOverflowError } from "@langchain/core/errors";
4
4
  //#region src/utils/client.ts
5
5
  function _isOpenAIContextOverflowError(e) {
6
6
  if (String(e).includes("context_length_exceeded")) return true;
7
- if ("message" in e && typeof e.message === "string" && (e.message.includes("Input tokens exceed the configured limit") || e.message.includes("exceeds the context window"))) return true;
7
+ if ("message" in e && typeof e.message === "string" && (e.message.includes("Input tokens exceed the configured limit") || e.message.includes("exceeds the context window") || e.message.includes("maximum context length"))) return true;
8
8
  return false;
9
9
  }
10
10
  function wrapOpenAIClientError(e) {
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["../../src/utils/client.ts"],"sourcesContent":["import { APIConnectionTimeoutError, APIUserAbortError } from \"openai\";\nimport { ContextOverflowError } from \"@langchain/core/errors\";\nimport { addLangChainErrorFields } from \"./errors.js\";\n\nfunction _isOpenAIContextOverflowError(e: object): boolean {\n const errorStr = String(e);\n if (errorStr.includes(\"context_length_exceeded\")) {\n return true;\n }\n if (\n \"message\" in e &&\n typeof e.message === \"string\" &&\n (e.message.includes(\"Input tokens exceed the configured limit\") ||\n e.message.includes(\"exceeds the context window\"))\n ) {\n return true;\n }\n return false;\n}\n\nexport function wrapOpenAIClientError(e: unknown) {\n if (!e || typeof e !== \"object\") {\n return e;\n }\n\n let error;\n if (\n e.constructor.name === APIConnectionTimeoutError.name &&\n \"message\" in e &&\n typeof e.message === \"string\"\n ) {\n error = new Error(e.message);\n error.name = \"TimeoutError\";\n } else if (\n e.constructor.name === APIUserAbortError.name &&\n \"message\" in e &&\n typeof e.message === \"string\"\n ) {\n error = new Error(e.message);\n error.name = \"AbortError\";\n } else if (_isOpenAIContextOverflowError(e)) {\n error = ContextOverflowError.fromError(e as Error);\n } else if (\n \"status\" in e &&\n e.status === 400 &&\n \"message\" in e &&\n typeof e.message === \"string\" &&\n e.message.includes(\"tool_calls\")\n ) {\n error = addLangChainErrorFields(e, \"INVALID_TOOL_RESULTS\");\n } else if (\"status\" in e && e.status === 401) {\n error = addLangChainErrorFields(e, \"MODEL_AUTHENTICATION\");\n } else if (\"status\" in e && e.status === 429) {\n error = addLangChainErrorFields(e, \"MODEL_RATE_LIMIT\");\n } else if (\"status\" in e && e.status === 404) {\n error = addLangChainErrorFields(e, \"MODEL_NOT_FOUND\");\n } else {\n error = e;\n }\n return error;\n}\n"],"mappings":";;;;AAIA,SAAS,8BAA8B,GAAoB;AAEzD,KADiB,OAAO,EAAE,CACb,SAAS,0BAA0B,CAC9C,QAAO;AAET,KACE,aAAa,KACb,OAAO,EAAE,YAAY,aACpB,EAAE,QAAQ,SAAS,2CAA2C,IAC7D,EAAE,QAAQ,SAAS,6BAA6B,EAElD,QAAO;AAET,QAAO;;AAGT,SAAgB,sBAAsB,GAAY;AAChD,KAAI,CAAC,KAAK,OAAO,MAAM,SACrB,QAAO;CAGT,IAAI;AACJ,KACE,EAAE,YAAY,SAAS,0BAA0B,QACjD,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;AACA,UAAQ,IAAI,MAAM,EAAE,QAAQ;AAC5B,QAAM,OAAO;YAEb,EAAE,YAAY,SAAS,kBAAkB,QACzC,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;AACA,UAAQ,IAAI,MAAM,EAAE,QAAQ;AAC5B,QAAM,OAAO;YACJ,8BAA8B,EAAE,CACzC,SAAQ,qBAAqB,UAAU,EAAW;UAElD,YAAY,KACZ,EAAE,WAAW,OACb,aAAa,KACb,OAAO,EAAE,YAAY,YACrB,EAAE,QAAQ,SAAS,aAAa,CAEhC,SAAQ,wBAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQ,wBAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQ,wBAAwB,GAAG,mBAAmB;UAC7C,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQ,wBAAwB,GAAG,kBAAkB;KAErD,SAAQ;AAEV,QAAO"}
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../src/utils/client.ts"],"sourcesContent":["import { APIConnectionTimeoutError, APIUserAbortError } from \"openai\";\nimport { ContextOverflowError } from \"@langchain/core/errors\";\nimport { addLangChainErrorFields } from \"./errors.js\";\n\nfunction _isOpenAIContextOverflowError(e: object): boolean {\n const errorStr = String(e);\n if (errorStr.includes(\"context_length_exceeded\")) {\n return true;\n }\n if (\n \"message\" in e &&\n typeof e.message === \"string\" &&\n (e.message.includes(\"Input tokens exceed the configured limit\") ||\n e.message.includes(\"exceeds the context window\") ||\n e.message.includes(\"maximum context length\"))\n ) {\n return true;\n }\n return false;\n}\n\nexport function wrapOpenAIClientError(e: unknown) {\n if (!e || typeof e !== \"object\") {\n return e;\n }\n\n let error;\n if (\n e.constructor.name === APIConnectionTimeoutError.name &&\n \"message\" in e &&\n typeof e.message === \"string\"\n ) {\n error = new Error(e.message);\n error.name = \"TimeoutError\";\n } else if (\n e.constructor.name === APIUserAbortError.name &&\n \"message\" in e &&\n typeof e.message === \"string\"\n ) {\n error = new Error(e.message);\n error.name = \"AbortError\";\n } else if (_isOpenAIContextOverflowError(e)) {\n error = ContextOverflowError.fromError(e as Error);\n } else if (\n \"status\" in e &&\n e.status === 400 &&\n \"message\" in e &&\n typeof e.message === \"string\" &&\n e.message.includes(\"tool_calls\")\n ) {\n error = addLangChainErrorFields(e, \"INVALID_TOOL_RESULTS\");\n } else if (\"status\" in e && e.status === 401) {\n error = addLangChainErrorFields(e, \"MODEL_AUTHENTICATION\");\n } else if (\"status\" in e && e.status === 429) {\n error = addLangChainErrorFields(e, \"MODEL_RATE_LIMIT\");\n } else if (\"status\" in e && e.status === 404) {\n error = addLangChainErrorFields(e, \"MODEL_NOT_FOUND\");\n } else {\n error = e;\n }\n return error;\n}\n"],"mappings":";;;;AAIA,SAAS,8BAA8B,GAAoB;AAEzD,KADiB,OAAO,EAAE,CACb,SAAS,0BAA0B,CAC9C,QAAO;AAET,KACE,aAAa,KACb,OAAO,EAAE,YAAY,aACpB,EAAE,QAAQ,SAAS,2CAA2C,IAC7D,EAAE,QAAQ,SAAS,6BAA6B,IAChD,EAAE,QAAQ,SAAS,yBAAyB,EAE9C,QAAO;AAET,QAAO;;AAGT,SAAgB,sBAAsB,GAAY;AAChD,KAAI,CAAC,KAAK,OAAO,MAAM,SACrB,QAAO;CAGT,IAAI;AACJ,KACE,EAAE,YAAY,SAAS,0BAA0B,QACjD,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;AACA,UAAQ,IAAI,MAAM,EAAE,QAAQ;AAC5B,QAAM,OAAO;YAEb,EAAE,YAAY,SAAS,kBAAkB,QACzC,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;AACA,UAAQ,IAAI,MAAM,EAAE,QAAQ;AAC5B,QAAM,OAAO;YACJ,8BAA8B,EAAE,CACzC,SAAQ,qBAAqB,UAAU,EAAW;UAElD,YAAY,KACZ,EAAE,WAAW,OACb,aAAa,KACb,OAAO,EAAE,YAAY,YACrB,EAAE,QAAQ,SAAS,aAAa,CAEhC,SAAQ,wBAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQ,wBAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQ,wBAAwB,GAAG,mBAAmB;UAC7C,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQ,wBAAwB,GAAG,kBAAkB;KAErD,SAAQ;AAEV,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"output.cjs","names":[],"sources":["../../src/utils/output.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport {\n InteropZodType,\n isZodSchemaV3,\n isZodSchemaV4,\n} from \"@langchain/core/utils/types\";\nimport { parse as parseV4 } from \"zod/v4/core\";\nimport { ResponseFormatJSONSchema } from \"openai/resources\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { ContentBlock, UsageMetadata } from \"@langchain/core/messages\";\nimport { toJsonSchema } from \"@langchain/core/utils/json_schema\";\n\nconst SUPPORTED_METHODS = [\n \"jsonSchema\",\n \"functionCalling\",\n \"jsonMode\",\n] as const;\ntype SupportedMethod = (typeof SUPPORTED_METHODS)[number];\n\n/**\n * Get the structured output method for a given model. By default, it uses\n * `jsonSchema` if the model supports it, otherwise it uses `functionCalling`.\n *\n * @throws if the method is invalid, e.g. is not a string or invalid method is provided.\n * @param model - The model name.\n * @param config - The structured output method options.\n * @returns The structured output method.\n */\nexport function getStructuredOutputMethod(\n model: string,\n method: unknown\n): SupportedMethod {\n /**\n * If a method is provided, validate it.\n */\n if (\n typeof method !== \"undefined\" &&\n !SUPPORTED_METHODS.includes(method as SupportedMethod)\n ) {\n throw new Error(\n `Invalid method: ${method}. Supported methods are: ${SUPPORTED_METHODS.join(\n \", \"\n )}`\n );\n }\n\n const hasSupportForJsonSchema =\n !model.startsWith(\"gpt-3\") &&\n !model.startsWith(\"gpt-4-\") &&\n model !== \"gpt-4\";\n\n /**\n * If the model supports JSON Schema, use it by default.\n */\n if (hasSupportForJsonSchema && !method) {\n return \"jsonSchema\";\n }\n\n if (!hasSupportForJsonSchema && method === \"jsonSchema\") {\n throw new Error(\n `JSON Schema is not supported for model \"${model}\". Please use a different method, e.g. \"functionCalling\" or \"jsonMode\".`\n );\n }\n\n /**\n * If the model does not support JSON Schema, use function calling by default.\n */\n return (method as SupportedMethod) ?? \"functionCalling\";\n}\n\n// inlined from openai/lib/parser.ts\nfunction makeParseableResponseFormat<ParsedT>(\n response_format: ResponseFormatJSONSchema,\n parser: (content: string) => ParsedT\n) {\n const obj = { ...response_format };\n\n Object.defineProperties(obj, {\n $brand: {\n value: \"auto-parseable-response-format\",\n enumerable: false,\n },\n $parseRaw: {\n value: parser,\n enumerable: false,\n },\n });\n\n return obj;\n}\n\nexport function interopZodResponseFormat(\n zodSchema: InteropZodType,\n name: string,\n props: Omit<ResponseFormatJSONSchema.JSONSchema, \"schema\" | \"strict\" | \"name\">\n) {\n if (isZodSchemaV3(zodSchema)) {\n return zodResponseFormat(zodSchema, name, props);\n }\n if (isZodSchemaV4(zodSchema)) {\n return makeParseableResponseFormat(\n {\n type: \"json_schema\",\n json_schema: {\n ...props,\n name,\n strict: true,\n schema: toJsonSchema(zodSchema, {\n cycles: \"ref\", // equivalent to nameStrategy: 'duplicate-ref'\n reused: \"ref\", // equivalent to $refStrategy: 'extract-to-root'\n override(ctx) {\n ctx.jsonSchema.title = name; // equivalent to `name` property\n // TODO: implement `nullableStrategy` patch-fix (zod doesn't support openApi3 json schema target)\n // TODO: implement `openaiStrictMode` patch-fix (where optional properties without `nullable` are not supported)\n },\n /// property equivalents from native `zodResponseFormat` fn\n // openaiStrictMode: true,\n // name,\n // nameStrategy: 'duplicate-ref',\n // $refStrategy: 'extract-to-root',\n // nullableStrategy: 'property',\n }),\n },\n },\n (content) => parseV4(zodSchema, JSON.parse(content))\n );\n }\n throw new Error(\"Unsupported schema response format\");\n}\n\n/**\n * Handle multi modal response content.\n *\n * @param content The content of the message.\n * @param messages The messages of the response.\n * @returns The new content of the message.\n */\nexport function handleMultiModalOutput(\n content: string,\n messages: unknown\n): ContentBlock[] | string {\n /**\n * Handle OpenRouter image responses\n * @see https://openrouter.ai/docs/features/multimodal/image-generation#api-usage\n */\n if (\n messages &&\n typeof messages === \"object\" &&\n \"images\" in messages &&\n Array.isArray(messages.images)\n ) {\n const images = messages.images\n .filter((image) => typeof image?.image_url?.url === \"string\")\n .map(\n (image) =>\n ({\n type: \"image\",\n url: image.image_url.url as string,\n }) as const\n );\n return [{ type: \"text\", text: content }, ...images];\n }\n\n return content;\n}\n\n// TODO: make this a converter\nexport function _convertOpenAIResponsesUsageToLangChainUsage(\n usage?: OpenAIClient.Responses.ResponseUsage\n): UsageMetadata {\n const inputTokenDetails = {\n ...(usage?.input_tokens_details?.cached_tokens != null && {\n cache_read: usage?.input_tokens_details?.cached_tokens,\n }),\n };\n const outputTokenDetails = {\n ...(usage?.output_tokens_details?.reasoning_tokens != null && {\n reasoning: usage?.output_tokens_details?.reasoning_tokens,\n }),\n };\n return {\n input_tokens: usage?.input_tokens ?? 0,\n output_tokens: usage?.output_tokens ?? 0,\n total_tokens: usage?.total_tokens ?? 0,\n input_token_details: inputTokenDetails,\n output_token_details: outputTokenDetails,\n };\n}\n"],"mappings":";;;;;AAYA,MAAM,oBAAoB;CACxB;CACA;CACA;CACD;;;;;;;;;;AAYD,SAAgB,0BACd,OACA,QACiB;;;;AAIjB,KACE,OAAO,WAAW,eAClB,CAAC,kBAAkB,SAAS,OAA0B,CAEtD,OAAM,IAAI,MACR,mBAAmB,OAAO,2BAA2B,kBAAkB,KACrE,KACD,GACF;CAGH,MAAM,0BACJ,CAAC,MAAM,WAAW,QAAQ,IAC1B,CAAC,MAAM,WAAW,SAAS,IAC3B,UAAU;;;;AAKZ,KAAI,2BAA2B,CAAC,OAC9B,QAAO;AAGT,KAAI,CAAC,2BAA2B,WAAW,aACzC,OAAM,IAAI,MACR,2CAA2C,MAAM,yEAClD;;;;AAMH,QAAQ,UAA8B;;AAIxC,SAAS,4BACP,iBACA,QACA;CACA,MAAM,MAAM,EAAE,GAAG,iBAAiB;AAElC,QAAO,iBAAiB,KAAK;EAC3B,QAAQ;GACN,OAAO;GACP,YAAY;GACb;EACD,WAAW;GACT,OAAO;GACP,YAAY;GACb;EACF,CAAC;AAEF,QAAO;;AAGT,SAAgB,yBACd,WACA,MACA,OACA;AACA,MAAA,GAAA,4BAAA,eAAkB,UAAU,CAC1B,SAAA,GAAA,mBAAA,mBAAyB,WAAW,MAAM,MAAM;AAElD,MAAA,GAAA,4BAAA,eAAkB,UAAU,CAC1B,QAAO,4BACL;EACE,MAAM;EACN,aAAa;GACX,GAAG;GACH;GACA,QAAQ;GACR,SAAA,GAAA,kCAAA,cAAqB,WAAW;IAC9B,QAAQ;IACR,QAAQ;IACR,SAAS,KAAK;AACZ,SAAI,WAAW,QAAQ;;IAU1B,CAAC;GACH;EACF,GACA,aAAA,GAAA,YAAA,OAAoB,WAAW,KAAK,MAAM,QAAQ,CAAC,CACrD;AAEH,OAAM,IAAI,MAAM,qCAAqC;;;;;;;;;AAUvD,SAAgB,uBACd,SACA,UACyB;;;;;AAKzB,KACE,YACA,OAAO,aAAa,YACpB,YAAY,YACZ,MAAM,QAAQ,SAAS,OAAO,EAC9B;EACA,MAAM,SAAS,SAAS,OACrB,QAAQ,UAAU,OAAO,OAAO,WAAW,QAAQ,SAAS,CAC5D,KACE,WACE;GACC,MAAM;GACN,KAAK,MAAM,UAAU;GACtB,EACJ;AACH,SAAO,CAAC;GAAE,MAAM;GAAQ,MAAM;GAAS,EAAE,GAAG,OAAO;;AAGrD,QAAO"}
1
+ {"version":3,"file":"output.cjs","names":[],"sources":["../../src/utils/output.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport {\n InteropZodType,\n isZodSchemaV3,\n isZodSchemaV4,\n} from \"@langchain/core/utils/types\";\nimport { parse as parseV4, type $ZodType } from \"zod/v4/core\";\nimport { ResponseFormatJSONSchema } from \"openai/resources\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { ContentBlock, UsageMetadata } from \"@langchain/core/messages\";\nimport { toJsonSchema } from \"@langchain/core/utils/json_schema\";\n\nconst SUPPORTED_METHODS = [\n \"jsonSchema\",\n \"functionCalling\",\n \"jsonMode\",\n] as const;\ntype SupportedMethod = (typeof SUPPORTED_METHODS)[number];\n\n/**\n * Get the structured output method for a given model. By default, it uses\n * `jsonSchema` if the model supports it, otherwise it uses `functionCalling`.\n *\n * @throws if the method is invalid, e.g. is not a string or invalid method is provided.\n * @param model - The model name.\n * @param config - The structured output method options.\n * @returns The structured output method.\n */\nexport function getStructuredOutputMethod(\n model: string,\n method: unknown\n): SupportedMethod {\n /**\n * If a method is provided, validate it.\n */\n if (\n typeof method !== \"undefined\" &&\n !SUPPORTED_METHODS.includes(method as SupportedMethod)\n ) {\n throw new Error(\n `Invalid method: ${method}. Supported methods are: ${SUPPORTED_METHODS.join(\n \", \"\n )}`\n );\n }\n\n const hasSupportForJsonSchema =\n !model.startsWith(\"gpt-3\") &&\n !model.startsWith(\"gpt-4-\") &&\n model !== \"gpt-4\";\n\n /**\n * If the model supports JSON Schema, use it by default.\n */\n if (hasSupportForJsonSchema && !method) {\n return \"jsonSchema\";\n }\n\n if (!hasSupportForJsonSchema && method === \"jsonSchema\") {\n throw new Error(\n `JSON Schema is not supported for model \"${model}\". Please use a different method, e.g. \"functionCalling\" or \"jsonMode\".`\n );\n }\n\n /**\n * If the model does not support JSON Schema, use function calling by default.\n */\n return (method as SupportedMethod) ?? \"functionCalling\";\n}\n\n// inlined from openai/lib/parser.ts\nfunction makeParseableResponseFormat<ParsedT>(\n response_format: ResponseFormatJSONSchema,\n parser: (content: string) => ParsedT\n) {\n const obj = { ...response_format };\n\n Object.defineProperties(obj, {\n $brand: {\n value: \"auto-parseable-response-format\",\n enumerable: false,\n },\n $parseRaw: {\n value: parser,\n enumerable: false,\n },\n });\n\n return obj;\n}\n\nexport function interopZodResponseFormat(\n zodSchema: InteropZodType,\n name: string,\n props: Omit<ResponseFormatJSONSchema.JSONSchema, \"schema\" | \"strict\" | \"name\">\n) {\n if (isZodSchemaV3(zodSchema)) {\n return zodResponseFormat(zodSchema as never, name, props);\n }\n if (isZodSchemaV4(zodSchema)) {\n return makeParseableResponseFormat(\n {\n type: \"json_schema\",\n json_schema: {\n ...props,\n name,\n strict: true,\n schema: toJsonSchema(zodSchema, {\n cycles: \"ref\", // equivalent to nameStrategy: 'duplicate-ref'\n reused: \"ref\", // equivalent to $refStrategy: 'extract-to-root'\n override(ctx) {\n ctx.jsonSchema.title = name; // equivalent to `name` property\n // TODO: implement `nullableStrategy` patch-fix (zod doesn't support openApi3 json schema target)\n // TODO: implement `openaiStrictMode` patch-fix (where optional properties without `nullable` are not supported)\n },\n /// property equivalents from native `zodResponseFormat` fn\n // openaiStrictMode: true,\n // name,\n // nameStrategy: 'duplicate-ref',\n // $refStrategy: 'extract-to-root',\n // nullableStrategy: 'property',\n }),\n },\n },\n (content) =>\n parseV4(zodSchema as unknown as $ZodType, JSON.parse(content))\n );\n }\n throw new Error(\"Unsupported schema response format\");\n}\n\n/**\n * Handle multi modal response content.\n *\n * @param content The content of the message.\n * @param messages The messages of the response.\n * @returns The new content of the message.\n */\nexport function handleMultiModalOutput(\n content: string,\n messages: unknown\n): ContentBlock[] | string {\n /**\n * Handle OpenRouter image responses\n * @see https://openrouter.ai/docs/features/multimodal/image-generation#api-usage\n */\n if (\n messages &&\n typeof messages === \"object\" &&\n \"images\" in messages &&\n Array.isArray(messages.images)\n ) {\n const images = messages.images\n .filter((image) => typeof image?.image_url?.url === \"string\")\n .map(\n (image) =>\n ({\n type: \"image\",\n url: image.image_url.url as string,\n }) as const\n );\n return [{ type: \"text\", text: content }, ...images];\n }\n\n return content;\n}\n\n// TODO: make this a converter\nexport function _convertOpenAIResponsesUsageToLangChainUsage(\n usage?: OpenAIClient.Responses.ResponseUsage\n): UsageMetadata {\n const inputTokenDetails = {\n ...(usage?.input_tokens_details?.cached_tokens != null && {\n cache_read: usage?.input_tokens_details?.cached_tokens,\n }),\n };\n const outputTokenDetails = {\n ...(usage?.output_tokens_details?.reasoning_tokens != null && {\n reasoning: usage?.output_tokens_details?.reasoning_tokens,\n }),\n };\n return {\n input_tokens: usage?.input_tokens ?? 0,\n output_tokens: usage?.output_tokens ?? 0,\n total_tokens: usage?.total_tokens ?? 0,\n input_token_details: inputTokenDetails,\n output_token_details: outputTokenDetails,\n };\n}\n"],"mappings":";;;;;AAYA,MAAM,oBAAoB;CACxB;CACA;CACA;CACD;;;;;;;;;;AAYD,SAAgB,0BACd,OACA,QACiB;;;;AAIjB,KACE,OAAO,WAAW,eAClB,CAAC,kBAAkB,SAAS,OAA0B,CAEtD,OAAM,IAAI,MACR,mBAAmB,OAAO,2BAA2B,kBAAkB,KACrE,KACD,GACF;CAGH,MAAM,0BACJ,CAAC,MAAM,WAAW,QAAQ,IAC1B,CAAC,MAAM,WAAW,SAAS,IAC3B,UAAU;;;;AAKZ,KAAI,2BAA2B,CAAC,OAC9B,QAAO;AAGT,KAAI,CAAC,2BAA2B,WAAW,aACzC,OAAM,IAAI,MACR,2CAA2C,MAAM,yEAClD;;;;AAMH,QAAQ,UAA8B;;AAIxC,SAAS,4BACP,iBACA,QACA;CACA,MAAM,MAAM,EAAE,GAAG,iBAAiB;AAElC,QAAO,iBAAiB,KAAK;EAC3B,QAAQ;GACN,OAAO;GACP,YAAY;GACb;EACD,WAAW;GACT,OAAO;GACP,YAAY;GACb;EACF,CAAC;AAEF,QAAO;;AAGT,SAAgB,yBACd,WACA,MACA,OACA;AACA,MAAA,GAAA,4BAAA,eAAkB,UAAU,CAC1B,SAAA,GAAA,mBAAA,mBAAyB,WAAoB,MAAM,MAAM;AAE3D,MAAA,GAAA,4BAAA,eAAkB,UAAU,CAC1B,QAAO,4BACL;EACE,MAAM;EACN,aAAa;GACX,GAAG;GACH;GACA,QAAQ;GACR,SAAA,GAAA,kCAAA,cAAqB,WAAW;IAC9B,QAAQ;IACR,QAAQ;IACR,SAAS,KAAK;AACZ,SAAI,WAAW,QAAQ;;IAU1B,CAAC;GACH;EACF,GACA,aAAA,GAAA,YAAA,OACS,WAAkC,KAAK,MAAM,QAAQ,CAAC,CACjE;AAEH,OAAM,IAAI,MAAM,qCAAqC;;;;;;;;;AAUvD,SAAgB,uBACd,SACA,UACyB;;;;;AAKzB,KACE,YACA,OAAO,aAAa,YACpB,YAAY,YACZ,MAAM,QAAQ,SAAS,OAAO,EAC9B;EACA,MAAM,SAAS,SAAS,OACrB,QAAQ,UAAU,OAAO,OAAO,WAAW,QAAQ,SAAS,CAC5D,KACE,WACE;GACC,MAAM;GACN,KAAK,MAAM,UAAU;GACtB,EACJ;AACH,SAAO,CAAC;GAAE,MAAM;GAAQ,MAAM;GAAS,EAAE,GAAG,OAAO;;AAGrD,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"output.js","names":["parseV4"],"sources":["../../src/utils/output.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport {\n InteropZodType,\n isZodSchemaV3,\n isZodSchemaV4,\n} from \"@langchain/core/utils/types\";\nimport { parse as parseV4 } from \"zod/v4/core\";\nimport { ResponseFormatJSONSchema } from \"openai/resources\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { ContentBlock, UsageMetadata } from \"@langchain/core/messages\";\nimport { toJsonSchema } from \"@langchain/core/utils/json_schema\";\n\nconst SUPPORTED_METHODS = [\n \"jsonSchema\",\n \"functionCalling\",\n \"jsonMode\",\n] as const;\ntype SupportedMethod = (typeof SUPPORTED_METHODS)[number];\n\n/**\n * Get the structured output method for a given model. By default, it uses\n * `jsonSchema` if the model supports it, otherwise it uses `functionCalling`.\n *\n * @throws if the method is invalid, e.g. is not a string or invalid method is provided.\n * @param model - The model name.\n * @param config - The structured output method options.\n * @returns The structured output method.\n */\nexport function getStructuredOutputMethod(\n model: string,\n method: unknown\n): SupportedMethod {\n /**\n * If a method is provided, validate it.\n */\n if (\n typeof method !== \"undefined\" &&\n !SUPPORTED_METHODS.includes(method as SupportedMethod)\n ) {\n throw new Error(\n `Invalid method: ${method}. Supported methods are: ${SUPPORTED_METHODS.join(\n \", \"\n )}`\n );\n }\n\n const hasSupportForJsonSchema =\n !model.startsWith(\"gpt-3\") &&\n !model.startsWith(\"gpt-4-\") &&\n model !== \"gpt-4\";\n\n /**\n * If the model supports JSON Schema, use it by default.\n */\n if (hasSupportForJsonSchema && !method) {\n return \"jsonSchema\";\n }\n\n if (!hasSupportForJsonSchema && method === \"jsonSchema\") {\n throw new Error(\n `JSON Schema is not supported for model \"${model}\". Please use a different method, e.g. \"functionCalling\" or \"jsonMode\".`\n );\n }\n\n /**\n * If the model does not support JSON Schema, use function calling by default.\n */\n return (method as SupportedMethod) ?? \"functionCalling\";\n}\n\n// inlined from openai/lib/parser.ts\nfunction makeParseableResponseFormat<ParsedT>(\n response_format: ResponseFormatJSONSchema,\n parser: (content: string) => ParsedT\n) {\n const obj = { ...response_format };\n\n Object.defineProperties(obj, {\n $brand: {\n value: \"auto-parseable-response-format\",\n enumerable: false,\n },\n $parseRaw: {\n value: parser,\n enumerable: false,\n },\n });\n\n return obj;\n}\n\nexport function interopZodResponseFormat(\n zodSchema: InteropZodType,\n name: string,\n props: Omit<ResponseFormatJSONSchema.JSONSchema, \"schema\" | \"strict\" | \"name\">\n) {\n if (isZodSchemaV3(zodSchema)) {\n return zodResponseFormat(zodSchema, name, props);\n }\n if (isZodSchemaV4(zodSchema)) {\n return makeParseableResponseFormat(\n {\n type: \"json_schema\",\n json_schema: {\n ...props,\n name,\n strict: true,\n schema: toJsonSchema(zodSchema, {\n cycles: \"ref\", // equivalent to nameStrategy: 'duplicate-ref'\n reused: \"ref\", // equivalent to $refStrategy: 'extract-to-root'\n override(ctx) {\n ctx.jsonSchema.title = name; // equivalent to `name` property\n // TODO: implement `nullableStrategy` patch-fix (zod doesn't support openApi3 json schema target)\n // TODO: implement `openaiStrictMode` patch-fix (where optional properties without `nullable` are not supported)\n },\n /// property equivalents from native `zodResponseFormat` fn\n // openaiStrictMode: true,\n // name,\n // nameStrategy: 'duplicate-ref',\n // $refStrategy: 'extract-to-root',\n // nullableStrategy: 'property',\n }),\n },\n },\n (content) => parseV4(zodSchema, JSON.parse(content))\n );\n }\n throw new Error(\"Unsupported schema response format\");\n}\n\n/**\n * Handle multi modal response content.\n *\n * @param content The content of the message.\n * @param messages The messages of the response.\n * @returns The new content of the message.\n */\nexport function handleMultiModalOutput(\n content: string,\n messages: unknown\n): ContentBlock[] | string {\n /**\n * Handle OpenRouter image responses\n * @see https://openrouter.ai/docs/features/multimodal/image-generation#api-usage\n */\n if (\n messages &&\n typeof messages === \"object\" &&\n \"images\" in messages &&\n Array.isArray(messages.images)\n ) {\n const images = messages.images\n .filter((image) => typeof image?.image_url?.url === \"string\")\n .map(\n (image) =>\n ({\n type: \"image\",\n url: image.image_url.url as string,\n }) as const\n );\n return [{ type: \"text\", text: content }, ...images];\n }\n\n return content;\n}\n\n// TODO: make this a converter\nexport function _convertOpenAIResponsesUsageToLangChainUsage(\n usage?: OpenAIClient.Responses.ResponseUsage\n): UsageMetadata {\n const inputTokenDetails = {\n ...(usage?.input_tokens_details?.cached_tokens != null && {\n cache_read: usage?.input_tokens_details?.cached_tokens,\n }),\n };\n const outputTokenDetails = {\n ...(usage?.output_tokens_details?.reasoning_tokens != null && {\n reasoning: usage?.output_tokens_details?.reasoning_tokens,\n }),\n };\n return {\n input_tokens: usage?.input_tokens ?? 0,\n output_tokens: usage?.output_tokens ?? 0,\n total_tokens: usage?.total_tokens ?? 0,\n input_token_details: inputTokenDetails,\n output_token_details: outputTokenDetails,\n };\n}\n"],"mappings":";;;;;AAYA,MAAM,oBAAoB;CACxB;CACA;CACA;CACD;;;;;;;;;;AAYD,SAAgB,0BACd,OACA,QACiB;;;;AAIjB,KACE,OAAO,WAAW,eAClB,CAAC,kBAAkB,SAAS,OAA0B,CAEtD,OAAM,IAAI,MACR,mBAAmB,OAAO,2BAA2B,kBAAkB,KACrE,KACD,GACF;CAGH,MAAM,0BACJ,CAAC,MAAM,WAAW,QAAQ,IAC1B,CAAC,MAAM,WAAW,SAAS,IAC3B,UAAU;;;;AAKZ,KAAI,2BAA2B,CAAC,OAC9B,QAAO;AAGT,KAAI,CAAC,2BAA2B,WAAW,aACzC,OAAM,IAAI,MACR,2CAA2C,MAAM,yEAClD;;;;AAMH,QAAQ,UAA8B;;AAIxC,SAAS,4BACP,iBACA,QACA;CACA,MAAM,MAAM,EAAE,GAAG,iBAAiB;AAElC,QAAO,iBAAiB,KAAK;EAC3B,QAAQ;GACN,OAAO;GACP,YAAY;GACb;EACD,WAAW;GACT,OAAO;GACP,YAAY;GACb;EACF,CAAC;AAEF,QAAO;;AAGT,SAAgB,yBACd,WACA,MACA,OACA;AACA,KAAI,cAAc,UAAU,CAC1B,QAAO,kBAAkB,WAAW,MAAM,MAAM;AAElD,KAAI,cAAc,UAAU,CAC1B,QAAO,4BACL;EACE,MAAM;EACN,aAAa;GACX,GAAG;GACH;GACA,QAAQ;GACR,QAAQ,aAAa,WAAW;IAC9B,QAAQ;IACR,QAAQ;IACR,SAAS,KAAK;AACZ,SAAI,WAAW,QAAQ;;IAU1B,CAAC;GACH;EACF,GACA,YAAYA,MAAQ,WAAW,KAAK,MAAM,QAAQ,CAAC,CACrD;AAEH,OAAM,IAAI,MAAM,qCAAqC;;;;;;;;;AAUvD,SAAgB,uBACd,SACA,UACyB;;;;;AAKzB,KACE,YACA,OAAO,aAAa,YACpB,YAAY,YACZ,MAAM,QAAQ,SAAS,OAAO,EAC9B;EACA,MAAM,SAAS,SAAS,OACrB,QAAQ,UAAU,OAAO,OAAO,WAAW,QAAQ,SAAS,CAC5D,KACE,WACE;GACC,MAAM;GACN,KAAK,MAAM,UAAU;GACtB,EACJ;AACH,SAAO,CAAC;GAAE,MAAM;GAAQ,MAAM;GAAS,EAAE,GAAG,OAAO;;AAGrD,QAAO"}
1
+ {"version":3,"file":"output.js","names":["parseV4"],"sources":["../../src/utils/output.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport {\n InteropZodType,\n isZodSchemaV3,\n isZodSchemaV4,\n} from \"@langchain/core/utils/types\";\nimport { parse as parseV4, type $ZodType } from \"zod/v4/core\";\nimport { ResponseFormatJSONSchema } from \"openai/resources\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { ContentBlock, UsageMetadata } from \"@langchain/core/messages\";\nimport { toJsonSchema } from \"@langchain/core/utils/json_schema\";\n\nconst SUPPORTED_METHODS = [\n \"jsonSchema\",\n \"functionCalling\",\n \"jsonMode\",\n] as const;\ntype SupportedMethod = (typeof SUPPORTED_METHODS)[number];\n\n/**\n * Get the structured output method for a given model. By default, it uses\n * `jsonSchema` if the model supports it, otherwise it uses `functionCalling`.\n *\n * @throws if the method is invalid, e.g. is not a string or invalid method is provided.\n * @param model - The model name.\n * @param config - The structured output method options.\n * @returns The structured output method.\n */\nexport function getStructuredOutputMethod(\n model: string,\n method: unknown\n): SupportedMethod {\n /**\n * If a method is provided, validate it.\n */\n if (\n typeof method !== \"undefined\" &&\n !SUPPORTED_METHODS.includes(method as SupportedMethod)\n ) {\n throw new Error(\n `Invalid method: ${method}. Supported methods are: ${SUPPORTED_METHODS.join(\n \", \"\n )}`\n );\n }\n\n const hasSupportForJsonSchema =\n !model.startsWith(\"gpt-3\") &&\n !model.startsWith(\"gpt-4-\") &&\n model !== \"gpt-4\";\n\n /**\n * If the model supports JSON Schema, use it by default.\n */\n if (hasSupportForJsonSchema && !method) {\n return \"jsonSchema\";\n }\n\n if (!hasSupportForJsonSchema && method === \"jsonSchema\") {\n throw new Error(\n `JSON Schema is not supported for model \"${model}\". Please use a different method, e.g. \"functionCalling\" or \"jsonMode\".`\n );\n }\n\n /**\n * If the model does not support JSON Schema, use function calling by default.\n */\n return (method as SupportedMethod) ?? \"functionCalling\";\n}\n\n// inlined from openai/lib/parser.ts\nfunction makeParseableResponseFormat<ParsedT>(\n response_format: ResponseFormatJSONSchema,\n parser: (content: string) => ParsedT\n) {\n const obj = { ...response_format };\n\n Object.defineProperties(obj, {\n $brand: {\n value: \"auto-parseable-response-format\",\n enumerable: false,\n },\n $parseRaw: {\n value: parser,\n enumerable: false,\n },\n });\n\n return obj;\n}\n\nexport function interopZodResponseFormat(\n zodSchema: InteropZodType,\n name: string,\n props: Omit<ResponseFormatJSONSchema.JSONSchema, \"schema\" | \"strict\" | \"name\">\n) {\n if (isZodSchemaV3(zodSchema)) {\n return zodResponseFormat(zodSchema as never, name, props);\n }\n if (isZodSchemaV4(zodSchema)) {\n return makeParseableResponseFormat(\n {\n type: \"json_schema\",\n json_schema: {\n ...props,\n name,\n strict: true,\n schema: toJsonSchema(zodSchema, {\n cycles: \"ref\", // equivalent to nameStrategy: 'duplicate-ref'\n reused: \"ref\", // equivalent to $refStrategy: 'extract-to-root'\n override(ctx) {\n ctx.jsonSchema.title = name; // equivalent to `name` property\n // TODO: implement `nullableStrategy` patch-fix (zod doesn't support openApi3 json schema target)\n // TODO: implement `openaiStrictMode` patch-fix (where optional properties without `nullable` are not supported)\n },\n /// property equivalents from native `zodResponseFormat` fn\n // openaiStrictMode: true,\n // name,\n // nameStrategy: 'duplicate-ref',\n // $refStrategy: 'extract-to-root',\n // nullableStrategy: 'property',\n }),\n },\n },\n (content) =>\n parseV4(zodSchema as unknown as $ZodType, JSON.parse(content))\n );\n }\n throw new Error(\"Unsupported schema response format\");\n}\n\n/**\n * Handle multi modal response content.\n *\n * @param content The content of the message.\n * @param messages The messages of the response.\n * @returns The new content of the message.\n */\nexport function handleMultiModalOutput(\n content: string,\n messages: unknown\n): ContentBlock[] | string {\n /**\n * Handle OpenRouter image responses\n * @see https://openrouter.ai/docs/features/multimodal/image-generation#api-usage\n */\n if (\n messages &&\n typeof messages === \"object\" &&\n \"images\" in messages &&\n Array.isArray(messages.images)\n ) {\n const images = messages.images\n .filter((image) => typeof image?.image_url?.url === \"string\")\n .map(\n (image) =>\n ({\n type: \"image\",\n url: image.image_url.url as string,\n }) as const\n );\n return [{ type: \"text\", text: content }, ...images];\n }\n\n return content;\n}\n\n// TODO: make this a converter\nexport function _convertOpenAIResponsesUsageToLangChainUsage(\n usage?: OpenAIClient.Responses.ResponseUsage\n): UsageMetadata {\n const inputTokenDetails = {\n ...(usage?.input_tokens_details?.cached_tokens != null && {\n cache_read: usage?.input_tokens_details?.cached_tokens,\n }),\n };\n const outputTokenDetails = {\n ...(usage?.output_tokens_details?.reasoning_tokens != null && {\n reasoning: usage?.output_tokens_details?.reasoning_tokens,\n }),\n };\n return {\n input_tokens: usage?.input_tokens ?? 0,\n output_tokens: usage?.output_tokens ?? 0,\n total_tokens: usage?.total_tokens ?? 0,\n input_token_details: inputTokenDetails,\n output_token_details: outputTokenDetails,\n };\n}\n"],"mappings":";;;;;AAYA,MAAM,oBAAoB;CACxB;CACA;CACA;CACD;;;;;;;;;;AAYD,SAAgB,0BACd,OACA,QACiB;;;;AAIjB,KACE,OAAO,WAAW,eAClB,CAAC,kBAAkB,SAAS,OAA0B,CAEtD,OAAM,IAAI,MACR,mBAAmB,OAAO,2BAA2B,kBAAkB,KACrE,KACD,GACF;CAGH,MAAM,0BACJ,CAAC,MAAM,WAAW,QAAQ,IAC1B,CAAC,MAAM,WAAW,SAAS,IAC3B,UAAU;;;;AAKZ,KAAI,2BAA2B,CAAC,OAC9B,QAAO;AAGT,KAAI,CAAC,2BAA2B,WAAW,aACzC,OAAM,IAAI,MACR,2CAA2C,MAAM,yEAClD;;;;AAMH,QAAQ,UAA8B;;AAIxC,SAAS,4BACP,iBACA,QACA;CACA,MAAM,MAAM,EAAE,GAAG,iBAAiB;AAElC,QAAO,iBAAiB,KAAK;EAC3B,QAAQ;GACN,OAAO;GACP,YAAY;GACb;EACD,WAAW;GACT,OAAO;GACP,YAAY;GACb;EACF,CAAC;AAEF,QAAO;;AAGT,SAAgB,yBACd,WACA,MACA,OACA;AACA,KAAI,cAAc,UAAU,CAC1B,QAAO,kBAAkB,WAAoB,MAAM,MAAM;AAE3D,KAAI,cAAc,UAAU,CAC1B,QAAO,4BACL;EACE,MAAM;EACN,aAAa;GACX,GAAG;GACH;GACA,QAAQ;GACR,QAAQ,aAAa,WAAW;IAC9B,QAAQ;IACR,QAAQ;IACR,SAAS,KAAK;AACZ,SAAI,WAAW,QAAQ;;IAU1B,CAAC;GACH;EACF,GACA,YACCA,MAAQ,WAAkC,KAAK,MAAM,QAAQ,CAAC,CACjE;AAEH,OAAM,IAAI,MAAM,qCAAqC;;;;;;;;;AAUvD,SAAgB,uBACd,SACA,UACyB;;;;;AAKzB,KACE,YACA,OAAO,aAAa,YACpB,YAAY,YACZ,MAAM,QAAQ,SAAS,OAAO,EAC9B;EACA,MAAM,SAAS,SAAS,OACrB,QAAQ,UAAU,OAAO,OAAO,WAAW,QAAQ,SAAS,CAC5D,KACE,WACE;GACC,MAAM;GACN,KAAK,MAAM,UAAU;GACtB,EACJ;AACH,SAAO,CAAC;GAAE,MAAM;GAAQ,MAAM;GAAS,EAAE,GAAG,OAAO;;AAGrD,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/openai",
3
- "version": "1.3.0-dev-1773962633795",
3
+ "version": "1.3.1",
4
4
  "description": "OpenAI integrations for LangChain.js",
5
5
  "author": "LangChain",
6
6
  "license": "MIT",
@@ -19,7 +19,7 @@
19
19
  "zod": "^3.25.76 || ^4"
20
20
  },
21
21
  "peerDependencies": {
22
- "@langchain/core": "^1.1.33-dev-1773962633795"
22
+ "@langchain/core": "^1.1.36"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@azure/identity": "^4.2.1",
@@ -36,9 +36,9 @@
36
36
  "uuid": "^11.1.0",
37
37
  "vitest": "^3.2.4",
38
38
  "zod-to-json-schema": "^3.24.6",
39
- "@langchain/eslint": "0.1.1",
40
- "@langchain/core": "^1.1.33-dev-1773962633795",
41
39
  "@langchain/standard-tests": "0.0.23",
40
+ "@langchain/eslint": "0.1.1",
41
+ "@langchain/core": "^1.1.36",
42
42
  "@langchain/tsconfig": "0.0.1"
43
43
  },
44
44
  "publishConfig": {