@langchain/openai 1.2.7 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/azure/chat_models/common.cjs +9 -10
  3. package/dist/azure/chat_models/common.cjs.map +1 -1
  4. package/dist/azure/chat_models/common.d.cts +0 -1
  5. package/dist/azure/chat_models/common.d.cts.map +1 -1
  6. package/dist/azure/chat_models/common.d.ts +0 -1
  7. package/dist/azure/chat_models/common.d.ts.map +1 -1
  8. package/dist/azure/chat_models/common.js +1 -1
  9. package/dist/azure/chat_models/common.js.map +1 -1
  10. package/dist/azure/chat_models/completions.cjs.map +1 -1
  11. package/dist/azure/chat_models/completions.d.cts.map +1 -1
  12. package/dist/azure/chat_models/completions.d.ts.map +1 -1
  13. package/dist/azure/chat_models/completions.js.map +1 -1
  14. package/dist/azure/chat_models/index.cjs.map +1 -1
  15. package/dist/azure/chat_models/index.d.cts +0 -1
  16. package/dist/azure/chat_models/index.d.cts.map +1 -1
  17. package/dist/azure/chat_models/index.d.ts +0 -1
  18. package/dist/azure/chat_models/index.d.ts.map +1 -1
  19. package/dist/azure/chat_models/index.js.map +1 -1
  20. package/dist/azure/chat_models/responses.cjs.map +1 -1
  21. package/dist/azure/chat_models/responses.d.cts.map +1 -1
  22. package/dist/azure/chat_models/responses.d.ts.map +1 -1
  23. package/dist/azure/chat_models/responses.js.map +1 -1
  24. package/dist/azure/embeddings.cjs +10 -13
  25. package/dist/azure/embeddings.cjs.map +1 -1
  26. package/dist/azure/embeddings.d.cts +1 -2
  27. package/dist/azure/embeddings.d.cts.map +1 -1
  28. package/dist/azure/embeddings.d.ts +1 -2
  29. package/dist/azure/embeddings.d.ts.map +1 -1
  30. package/dist/azure/embeddings.js +3 -5
  31. package/dist/azure/embeddings.js.map +1 -1
  32. package/dist/azure/llms.cjs +9 -10
  33. package/dist/azure/llms.cjs.map +1 -1
  34. package/dist/azure/llms.d.cts +2 -2
  35. package/dist/azure/llms.d.cts.map +1 -1
  36. package/dist/azure/llms.d.ts +2 -2
  37. package/dist/azure/llms.d.ts.map +1 -1
  38. package/dist/azure/llms.js +3 -3
  39. package/dist/azure/llms.js.map +1 -1
  40. package/dist/chat_models/base.cjs +38 -45
  41. package/dist/chat_models/base.cjs.map +1 -1
  42. package/dist/chat_models/base.d.cts.map +1 -1
  43. package/dist/chat_models/base.d.ts.map +1 -1
  44. package/dist/chat_models/base.js +10 -16
  45. package/dist/chat_models/base.js.map +1 -1
  46. package/dist/chat_models/completions.cjs +9 -13
  47. package/dist/chat_models/completions.cjs.map +1 -1
  48. package/dist/chat_models/completions.d.cts.map +1 -1
  49. package/dist/chat_models/completions.d.ts.map +1 -1
  50. package/dist/chat_models/completions.js +3 -6
  51. package/dist/chat_models/completions.js.map +1 -1
  52. package/dist/chat_models/index.cjs.map +1 -1
  53. package/dist/chat_models/index.d.cts.map +1 -1
  54. package/dist/chat_models/index.d.ts.map +1 -1
  55. package/dist/chat_models/index.js.map +1 -1
  56. package/dist/chat_models/profiles.cjs +291 -94
  57. package/dist/chat_models/profiles.cjs.map +1 -1
  58. package/dist/chat_models/profiles.js +291 -94
  59. package/dist/chat_models/profiles.js.map +1 -1
  60. package/dist/chat_models/responses.cjs +4 -7
  61. package/dist/chat_models/responses.cjs.map +1 -1
  62. package/dist/chat_models/responses.d.cts.map +1 -1
  63. package/dist/chat_models/responses.d.ts.map +1 -1
  64. package/dist/chat_models/responses.js +2 -4
  65. package/dist/chat_models/responses.js.map +1 -1
  66. package/dist/converters/completions.cjs +36 -45
  67. package/dist/converters/completions.cjs.map +1 -1
  68. package/dist/converters/completions.d.cts +0 -1
  69. package/dist/converters/completions.d.cts.map +1 -1
  70. package/dist/converters/completions.d.ts +0 -1
  71. package/dist/converters/completions.d.ts.map +1 -1
  72. package/dist/converters/completions.js +14 -22
  73. package/dist/converters/completions.js.map +1 -1
  74. package/dist/converters/index.js +2 -0
  75. package/dist/converters/responses.cjs +39 -54
  76. package/dist/converters/responses.cjs.map +1 -1
  77. package/dist/converters/responses.d.cts.map +1 -1
  78. package/dist/converters/responses.d.ts.map +1 -1
  79. package/dist/converters/responses.js +31 -45
  80. package/dist/converters/responses.js.map +1 -1
  81. package/dist/embeddings.cjs +11 -15
  82. package/dist/embeddings.cjs.map +1 -1
  83. package/dist/embeddings.d.cts +1 -3
  84. package/dist/embeddings.d.cts.map +1 -1
  85. package/dist/embeddings.d.ts +1 -3
  86. package/dist/embeddings.d.ts.map +1 -1
  87. package/dist/embeddings.js +3 -6
  88. package/dist/embeddings.js.map +1 -1
  89. package/dist/index.cjs +2 -2
  90. package/dist/llms.cjs +27 -33
  91. package/dist/llms.cjs.map +1 -1
  92. package/dist/llms.d.cts +0 -1
  93. package/dist/llms.d.cts.map +1 -1
  94. package/dist/llms.d.ts +0 -1
  95. package/dist/llms.d.ts.map +1 -1
  96. package/dist/llms.js +15 -20
  97. package/dist/llms.js.map +1 -1
  98. package/dist/tools/applyPatch.cjs +3 -4
  99. package/dist/tools/applyPatch.cjs.map +1 -1
  100. package/dist/tools/applyPatch.d.cts +0 -1
  101. package/dist/tools/applyPatch.d.cts.map +1 -1
  102. package/dist/tools/applyPatch.d.ts +0 -1
  103. package/dist/tools/applyPatch.d.ts.map +1 -1
  104. package/dist/tools/applyPatch.js.map +1 -1
  105. package/dist/tools/codeInterpreter.cjs.map +1 -1
  106. package/dist/tools/codeInterpreter.d.cts +0 -1
  107. package/dist/tools/codeInterpreter.d.cts.map +1 -1
  108. package/dist/tools/codeInterpreter.d.ts +0 -1
  109. package/dist/tools/codeInterpreter.d.ts.map +1 -1
  110. package/dist/tools/codeInterpreter.js.map +1 -1
  111. package/dist/tools/computerUse.cjs +7 -13
  112. package/dist/tools/computerUse.cjs.map +1 -1
  113. package/dist/tools/computerUse.d.cts +0 -1
  114. package/dist/tools/computerUse.d.cts.map +1 -1
  115. package/dist/tools/computerUse.d.ts +0 -1
  116. package/dist/tools/computerUse.d.ts.map +1 -1
  117. package/dist/tools/computerUse.js +1 -6
  118. package/dist/tools/computerUse.js.map +1 -1
  119. package/dist/tools/custom.cjs +6 -7
  120. package/dist/tools/custom.cjs.map +1 -1
  121. package/dist/tools/custom.d.cts.map +1 -1
  122. package/dist/tools/custom.d.ts.map +1 -1
  123. package/dist/tools/custom.js.map +1 -1
  124. package/dist/tools/dalle.cjs +10 -16
  125. package/dist/tools/dalle.cjs.map +1 -1
  126. package/dist/tools/dalle.d.cts +0 -1
  127. package/dist/tools/dalle.d.cts.map +1 -1
  128. package/dist/tools/dalle.d.ts +0 -1
  129. package/dist/tools/dalle.d.ts.map +1 -1
  130. package/dist/tools/dalle.js +6 -11
  131. package/dist/tools/dalle.js.map +1 -1
  132. package/dist/tools/fileSearch.cjs.map +1 -1
  133. package/dist/tools/fileSearch.d.cts +0 -1
  134. package/dist/tools/fileSearch.d.cts.map +1 -1
  135. package/dist/tools/fileSearch.d.ts +0 -1
  136. package/dist/tools/fileSearch.d.ts.map +1 -1
  137. package/dist/tools/fileSearch.js.map +1 -1
  138. package/dist/tools/imageGeneration.cjs.map +1 -1
  139. package/dist/tools/imageGeneration.d.cts +0 -1
  140. package/dist/tools/imageGeneration.d.cts.map +1 -1
  141. package/dist/tools/imageGeneration.d.ts +0 -1
  142. package/dist/tools/imageGeneration.d.ts.map +1 -1
  143. package/dist/tools/imageGeneration.js.map +1 -1
  144. package/dist/tools/index.cjs.map +1 -1
  145. package/dist/tools/index.d.cts +0 -1
  146. package/dist/tools/index.d.cts.map +1 -1
  147. package/dist/tools/index.d.ts +0 -1
  148. package/dist/tools/index.d.ts.map +1 -1
  149. package/dist/tools/index.js.map +1 -1
  150. package/dist/tools/localShell.cjs +3 -4
  151. package/dist/tools/localShell.cjs.map +1 -1
  152. package/dist/tools/localShell.d.cts +0 -1
  153. package/dist/tools/localShell.d.cts.map +1 -1
  154. package/dist/tools/localShell.d.ts +0 -1
  155. package/dist/tools/localShell.d.ts.map +1 -1
  156. package/dist/tools/localShell.js.map +1 -1
  157. package/dist/tools/mcp.cjs.map +1 -1
  158. package/dist/tools/mcp.d.cts +0 -1
  159. package/dist/tools/mcp.d.cts.map +1 -1
  160. package/dist/tools/mcp.d.ts +0 -1
  161. package/dist/tools/mcp.d.ts.map +1 -1
  162. package/dist/tools/mcp.js.map +1 -1
  163. package/dist/tools/shell.cjs +3 -4
  164. package/dist/tools/shell.cjs.map +1 -1
  165. package/dist/tools/shell.d.cts +0 -1
  166. package/dist/tools/shell.d.cts.map +1 -1
  167. package/dist/tools/shell.d.ts +0 -1
  168. package/dist/tools/shell.d.ts.map +1 -1
  169. package/dist/tools/shell.js.map +1 -1
  170. package/dist/tools/webSearch.cjs.map +1 -1
  171. package/dist/tools/webSearch.d.cts +0 -1
  172. package/dist/tools/webSearch.d.cts.map +1 -1
  173. package/dist/tools/webSearch.d.ts +0 -1
  174. package/dist/tools/webSearch.d.ts.map +1 -1
  175. package/dist/tools/webSearch.js.map +1 -1
  176. package/dist/types.d.cts +0 -1
  177. package/dist/types.d.cts.map +1 -1
  178. package/dist/types.d.ts +0 -1
  179. package/dist/types.d.ts.map +1 -1
  180. package/dist/utils/azure.cjs +2 -3
  181. package/dist/utils/azure.cjs.map +1 -1
  182. package/dist/utils/azure.d.cts.map +1 -1
  183. package/dist/utils/azure.d.ts.map +1 -1
  184. package/dist/utils/azure.js.map +1 -1
  185. package/dist/utils/client.cjs +9 -3
  186. package/dist/utils/client.cjs.map +1 -1
  187. package/dist/utils/client.d.cts.map +1 -1
  188. package/dist/utils/client.d.ts.map +1 -1
  189. package/dist/utils/client.js +8 -1
  190. package/dist/utils/client.js.map +1 -1
  191. package/dist/utils/errors.cjs.map +1 -1
  192. package/dist/utils/errors.js.map +1 -1
  193. package/dist/utils/misc.cjs +2 -3
  194. package/dist/utils/misc.cjs.map +1 -1
  195. package/dist/utils/misc.d.cts +0 -1
  196. package/dist/utils/misc.d.cts.map +1 -1
  197. package/dist/utils/misc.d.ts +0 -1
  198. package/dist/utils/misc.d.ts.map +1 -1
  199. package/dist/utils/misc.js.map +1 -1
  200. package/dist/utils/output.cjs +7 -8
  201. package/dist/utils/output.cjs.map +1 -1
  202. package/dist/utils/output.js.map +1 -1
  203. package/dist/utils/prompts.cjs +1 -2
  204. package/dist/utils/prompts.cjs.map +1 -1
  205. package/dist/utils/prompts.d.cts +0 -1
  206. package/dist/utils/prompts.d.cts.map +1 -1
  207. package/dist/utils/prompts.d.ts +0 -1
  208. package/dist/utils/prompts.d.ts.map +1 -1
  209. package/dist/utils/prompts.js +1 -2
  210. package/dist/utils/prompts.js.map +1 -1
  211. package/dist/utils/tools.cjs +9 -12
  212. package/dist/utils/tools.cjs.map +1 -1
  213. package/dist/utils/tools.d.cts +0 -1
  214. package/dist/utils/tools.d.cts.map +1 -1
  215. package/dist/utils/tools.d.ts +0 -1
  216. package/dist/utils/tools.d.ts.map +1 -1
  217. package/dist/utils/tools.js +5 -7
  218. package/dist/utils/tools.js.map +1 -1
  219. package/package.json +4 -4
  220. package/dist/_virtual/rolldown_runtime.cjs +0 -25
@@ -1 +1 @@
1
- {"version":3,"file":"azure.d.ts","names":["OpenAIEndpointConfig","Promise","getEndpoint","HeaderValue","HeadersLike","Headers","Record","isHeaders","normalizeHeaders","getFormattedEnv","getHeadersWithUserAgent"],"sources":["../../src/utils/azure.d.ts"],"sourcesContent":["export interface OpenAIEndpointConfig {\n azureOpenAIApiDeploymentName?: string;\n azureOpenAIApiInstanceName?: string;\n azureOpenAIApiKey?: string;\n azureADTokenProvider?: () => Promise<string>;\n azureOpenAIBasePath?: string;\n baseURL?: string | null;\n azureOpenAIEndpoint?: string;\n}\n/**\n * This function generates an endpoint URL for (Azure) OpenAI\n * based on the configuration parameters provided.\n *\n * @param {OpenAIEndpointConfig} config - The configuration object for the (Azure) endpoint.\n *\n * @property {string} config.azureOpenAIApiDeploymentName - The deployment name of Azure OpenAI.\n * @property {string} config.azureOpenAIApiInstanceName - The instance name of Azure OpenAI, e.g. `example-resource`.\n * @property {string} config.azureOpenAIApiKey - The API Key for Azure OpenAI.\n * @property {string} config.azureOpenAIBasePath - The base path for Azure OpenAI, e.g. `https://example-resource.azure.openai.com/openai/deployments/`.\n * @property {string} config.baseURL - Some other custom base path URL.\n * @property {string} config.azureOpenAIEndpoint - The endpoint for the Azure OpenAI instance, e.g. `https://example-resource.azure.openai.com/`.\n *\n * The function operates as follows:\n * - If both `azureOpenAIBasePath` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`).\n * - If both `azureOpenAIEndpoint` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`).\n * - If `azureOpenAIApiKey` is provided, it checks for `azureOpenAIApiInstanceName` and `azureOpenAIApiDeploymentName` and throws an error if any of these is missing. If both are provided, it generates an URL incorporating these parameters.\n * - If none of the above conditions are met, return any custom `baseURL`.\n * - The function returns the generated URL as a string, or undefined if no custom paths are specified.\n *\n * @throws Will throw an error if the necessary parameters for generating the URL are missing.\n *\n * @returns {string | undefined} The generated (Azure) OpenAI endpoint URL.\n */\nexport declare function getEndpoint(config: OpenAIEndpointConfig): string | null | undefined;\ntype HeaderValue = string | undefined | null;\nexport type HeadersLike = Headers | readonly HeaderValue[][] | Record<string, HeaderValue | readonly HeaderValue[]> | undefined | null | {\n values: Headers;\n [key: string]: unknown;\n};\nexport declare function isHeaders(headers: unknown): headers is Headers;\n/**\n * Normalizes various header formats into a consistent Record format.\n *\n * This function accepts headers in multiple formats and converts them to a\n * Record<string, HeaderValue | readonly HeaderValue[]> for consistent handling.\n *\n * @param headers - The headers to normalize. Can be:\n * - A Headers instance\n * - An array of [key, value] pairs\n * - A plain object with string keys\n * - A NullableHeaders-like object with a 'values' property containing Headers\n * - null or undefined\n * @returns A normalized Record containing the header key-value pairs\n *\n * @example\n * ```ts\n * // With Headers instance\n * const headers1 = new Headers([['content-type', 'application/json']]);\n * const normalized1 = normalizeHeaders(headers1);\n *\n * // With plain object\n * const headers2 = { 'content-type': 'application/json' };\n * const normalized2 = normalizeHeaders(headers2);\n *\n * // With array of pairs\n * const headers3 = [['content-type', 'application/json']];\n * const normalized3 = normalizeHeaders(headers3);\n * ```\n */\nexport declare function normalizeHeaders(headers: HeadersLike): Record<string, HeaderValue | readonly HeaderValue[]>;\nexport declare function getFormattedEnv(): string;\nexport declare function getHeadersWithUserAgent(headers: HeadersLike, isAzure?: boolean, version?: string): Record<string, string>;\nexport {};\n//# sourceMappingURL=azure.d.ts.map"],"mappings":";UAAiBA,oBAAAA;EAAAA,4BAAoB,CAAA,EAAA,MAIJC;EA6BTC,0BAAoBF,CAAAA,EAAAA,MAAAA;EACvCG,iBAAW,CAAA,EAAA,MAAA;EACJC,oBAAW,CAAA,EAAA,GAAA,GA/BUH,OA+BV,CAAA,MAAA,CAAA;EAAGI,mBAAAA,CAAAA,EAAAA,MAAAA;EAAmBF,OAAAA,CAAAA,EAAAA,MAAAA,GAAAA,IAAAA;EAAiCA,mBAAAA,CAAAA,EAAAA,MAAAA;;;;AAC3D;AAGnB;AA8BA;;;;;AAAsE;AACtE;AACA;;;;;;;;;;;;;iBAtCwBD,WAAAA,SAAoBF;KACvCG,WAAAA;KACOC,WAAAA,GAAcC,mBAAmBF,kBAAkBG,eAAeH,uBAAuBA;UACzFE;;;iBAGYE,SAAAA,+BAAwCF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8BxCG,gBAAAA,UAA0BJ,cAAcE,eAAeH,uBAAuBA;iBAC9EM,eAAAA,CAAAA;iBACAC,uBAAAA,UAAiCN,mDAAmDE"}
1
+ {"version":3,"file":"azure.d.ts","names":[],"sources":["../../src/utils/azure.ts"],"mappings":";UAGiB,oBAAA;EACf,4BAAA;EACA,0BAAA;EACA,iBAAA;EACA,oBAAA,SAA6B,OAAA;EAC7B,mBAAA;EACA,OAAA;EACA,mBAAA;AAAA;;;;;;;AA2BF;;;;;AAyCC;;;;;AAGD;;;;;;;;iBA5CgB,WAAA,CAAY,MAAA,EAAQ,oBAAA;AAAA,KA2C/B,WAAA;AAAA,KACO,WAAA,GACR,OAAA,YACS,WAAA,OACT,MAAA,SAAe,WAAA,YAAuB,WAAA;EAIpC,MAAA,EAAQ,OAAA;EAAA,CAAU,GAAA;AAAA;AAAA,iBAER,SAAA,CAAU,OAAA,YAAmB,OAAA,IAAW,OAAA;;;;;;;AAAxD;;;;;;;;;AAsCA;;;;;;;;;;;;;;iBAAgB,gBAAA,CACd,OAAA,EAAS,WAAA,GACR,MAAA,SAAe,WAAA,YAAuB,WAAA;AAAA,iBAgCzB,eAAA,CAAA;AAAA,iBAUA,uBAAA,CACd,OAAA,EAAS,WAAA,EACT,OAAA,YACA,OAAA,YACC,MAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"azure.js","names":["config: OpenAIEndpointConfig","headers: unknown","headers: HeadersLike","entries: [string, string][]"],"sources":["../../src/utils/azure.ts"],"sourcesContent":["import { getEnv } from \"@langchain/core/utils/env\";\nimport { iife } from \"./misc.js\";\n\nexport interface OpenAIEndpointConfig {\n azureOpenAIApiDeploymentName?: string;\n azureOpenAIApiInstanceName?: string;\n azureOpenAIApiKey?: string;\n azureADTokenProvider?: () => Promise<string>;\n azureOpenAIBasePath?: string;\n baseURL?: string | null;\n azureOpenAIEndpoint?: string;\n}\n\n/**\n * This function generates an endpoint URL for (Azure) OpenAI\n * based on the configuration parameters provided.\n *\n * @param {OpenAIEndpointConfig} config - The configuration object for the (Azure) endpoint.\n *\n * @property {string} config.azureOpenAIApiDeploymentName - The deployment name of Azure OpenAI.\n * @property {string} config.azureOpenAIApiInstanceName - The instance name of Azure OpenAI, e.g. `example-resource`.\n * @property {string} config.azureOpenAIApiKey - The API Key for Azure OpenAI.\n * @property {string} config.azureOpenAIBasePath - The base path for Azure OpenAI, e.g. `https://example-resource.azure.openai.com/openai/deployments/`.\n * @property {string} config.baseURL - Some other custom base path URL.\n * @property {string} config.azureOpenAIEndpoint - The endpoint for the Azure OpenAI instance, e.g. `https://example-resource.azure.openai.com/`.\n *\n * The function operates as follows:\n * - If both `azureOpenAIBasePath` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`).\n * - If both `azureOpenAIEndpoint` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`).\n * - If `azureOpenAIApiKey` is provided, it checks for `azureOpenAIApiInstanceName` and `azureOpenAIApiDeploymentName` and throws an error if any of these is missing. If both are provided, it generates an URL incorporating these parameters.\n * - If none of the above conditions are met, return any custom `baseURL`.\n * - The function returns the generated URL as a string, or undefined if no custom paths are specified.\n *\n * @throws Will throw an error if the necessary parameters for generating the URL are missing.\n *\n * @returns {string | undefined} The generated (Azure) OpenAI endpoint URL.\n */\nexport function getEndpoint(config: OpenAIEndpointConfig) {\n const {\n azureOpenAIApiDeploymentName,\n azureOpenAIApiInstanceName,\n azureOpenAIApiKey,\n azureOpenAIBasePath,\n baseURL,\n azureADTokenProvider,\n azureOpenAIEndpoint,\n } = config;\n\n if (\n (azureOpenAIApiKey || azureADTokenProvider) &&\n azureOpenAIBasePath &&\n azureOpenAIApiDeploymentName\n ) {\n return `${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`;\n }\n if (\n (azureOpenAIApiKey || azureADTokenProvider) &&\n azureOpenAIEndpoint &&\n azureOpenAIApiDeploymentName\n ) {\n return `${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`;\n }\n\n if (azureOpenAIApiKey || azureADTokenProvider) {\n if (!azureOpenAIApiInstanceName) {\n throw new Error(\n \"azureOpenAIApiInstanceName is required when using azureOpenAIApiKey\"\n );\n }\n if (!azureOpenAIApiDeploymentName) {\n throw new Error(\n \"azureOpenAIApiDeploymentName is a required parameter when using azureOpenAIApiKey\"\n );\n }\n return `https://${azureOpenAIApiInstanceName}.openai.azure.com/openai/deployments/${azureOpenAIApiDeploymentName}`;\n }\n\n return baseURL;\n}\n\ntype HeaderValue = string | undefined | null;\nexport type HeadersLike =\n | Headers\n | readonly HeaderValue[][]\n | Record<string, HeaderValue | readonly HeaderValue[]>\n | undefined\n | null\n // NullableHeaders\n | { values: Headers; [key: string]: unknown };\n\nexport function isHeaders(headers: unknown): headers is Headers {\n return (\n typeof Headers !== \"undefined\" &&\n headers !== null &&\n typeof headers === \"object\" &&\n Object.prototype.toString.call(headers) === \"[object Headers]\"\n );\n}\n\n/**\n * Normalizes various header formats into a consistent Record format.\n *\n * This function accepts headers in multiple formats and converts them to a\n * Record<string, HeaderValue | readonly HeaderValue[]> for consistent handling.\n *\n * @param headers - The headers to normalize. Can be:\n * - A Headers instance\n * - An array of [key, value] pairs\n * - A plain object with string keys\n * - A NullableHeaders-like object with a 'values' property containing Headers\n * - null or undefined\n * @returns A normalized Record containing the header key-value pairs\n *\n * @example\n * ```ts\n * // With Headers instance\n * const headers1 = new Headers([['content-type', 'application/json']]);\n * const normalized1 = normalizeHeaders(headers1);\n *\n * // With plain object\n * const headers2 = { 'content-type': 'application/json' };\n * const normalized2 = normalizeHeaders(headers2);\n *\n * // With array of pairs\n * const headers3 = [['content-type', 'application/json']];\n * const normalized3 = normalizeHeaders(headers3);\n * ```\n */\nexport function normalizeHeaders(\n headers: HeadersLike\n): Record<string, HeaderValue | readonly HeaderValue[]> {\n const output = iife(() => {\n // If headers is a Headers instance\n if (isHeaders(headers)) {\n return headers;\n }\n // If headers is an array of [key, value] pairs\n else if (Array.isArray(headers)) {\n return new Headers(headers);\n }\n // If headers is a NullableHeaders-like object (has 'values' property that is a Headers)\n else if (\n typeof headers === \"object\" &&\n headers !== null &&\n \"values\" in headers &&\n isHeaders(headers.values)\n ) {\n return headers.values;\n }\n // If headers is a plain object\n else if (typeof headers === \"object\" && headers !== null) {\n const entries: [string, string][] = Object.entries(headers)\n .filter(([, v]) => typeof v === \"string\")\n .map(([k, v]) => [k, v as string]);\n return new Headers(entries);\n }\n return new Headers();\n });\n\n return Object.fromEntries(output.entries());\n}\n\nexport function getFormattedEnv() {\n let env = getEnv();\n if (env === \"node\" || env === \"deno\") {\n env = `(${env}/${process.version}; ${process.platform}; ${process.arch})`;\n }\n return env;\n}\n\n// Note: ideally version would be imported from package.json, but there's\n// currently no good way to do that for all supported environments (Node, Deno, Browser).\nexport function getHeadersWithUserAgent(\n headers: HeadersLike,\n isAzure = false,\n version = \"1.0.0\"\n): Record<string, string> {\n const normalizedHeaders = normalizeHeaders(headers);\n const env = getFormattedEnv();\n const library = `langchainjs${isAzure ? \"-azure\" : \"\"}-openai`;\n return {\n ...normalizedHeaders,\n \"User-Agent\": normalizedHeaders[\"User-Agent\"]\n ? `${library}/${version} (${env})${normalizedHeaders[\"User-Agent\"]}`\n : `${library}/${version} (${env})`,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,YAAYA,QAA8B;CACxD,MAAM,EACJ,8BACA,4BACA,mBACA,qBACA,SACA,sBACA,qBACD,GAAG;AAEJ,MACG,qBAAqB,yBACtB,uBACA,6BAEA,QAAO,GAAG,oBAAoB,CAAC,EAAE,8BAA8B;AAEjE,MACG,qBAAqB,yBACtB,uBACA,6BAEA,QAAO,GAAG,oBAAoB,oBAAoB,EAAE,8BAA8B;AAGpF,KAAI,qBAAqB,sBAAsB;AAC7C,MAAI,CAAC,2BACH,OAAM,IAAI,MACR;AAGJ,MAAI,CAAC,6BACH,OAAM,IAAI,MACR;AAGJ,SAAO,CAAC,QAAQ,EAAE,2BAA2B,qCAAqC,EAAE,8BAA8B;CACnH;AAED,QAAO;AACR;AAYD,SAAgB,UAAUC,SAAsC;AAC9D,QACE,OAAO,YAAY,eACnB,YAAY,QACZ,OAAO,YAAY,YACnB,OAAO,UAAU,SAAS,KAAK,QAAQ,KAAK;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BD,SAAgB,iBACdC,SACsD;CACtD,MAAM,SAAS,KAAK,MAAM;AAExB,MAAI,UAAU,QAAQ,CACpB,QAAO;WAGA,MAAM,QAAQ,QAAQ,CAC7B,QAAO,IAAI,QAAQ;WAInB,OAAO,YAAY,YACnB,YAAY,QACZ,YAAY,WACZ,UAAU,QAAQ,OAAO,CAEzB,QAAO,QAAQ;WAGR,OAAO,YAAY,YAAY,YAAY,MAAM;GACxD,MAAMC,UAA8B,OAAO,QAAQ,QAAQ,CACxD,OAAO,CAAC,GAAG,EAAE,KAAK,OAAO,MAAM,SAAS,CACxC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAY,EAAC;AACpC,UAAO,IAAI,QAAQ;EACpB;AACD,SAAO,IAAI;CACZ,EAAC;AAEF,QAAO,OAAO,YAAY,OAAO,SAAS,CAAC;AAC5C;AAED,SAAgB,kBAAkB;CAChC,IAAI,MAAM,QAAQ;AAClB,KAAI,QAAQ,UAAU,QAAQ,QAC5B,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,QAAQ,QAAQ,EAAE,EAAE,QAAQ,SAAS,EAAE,EAAE,QAAQ,KAAK,CAAC,CAAC;AAE3E,QAAO;AACR;AAID,SAAgB,wBACdD,SACA,UAAU,OACV,UAAU,SACc;CACxB,MAAM,oBAAoB,iBAAiB,QAAQ;CACnD,MAAM,MAAM,iBAAiB;CAC7B,MAAM,UAAU,CAAC,WAAW,EAAE,UAAU,WAAW,GAAG,OAAO,CAAC;AAC9D,QAAO;EACL,GAAG;EACH,cAAc,kBAAkB,gBAC5B,GAAG,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,CAAC,EAAE,kBAAkB,eAAe,GAClE,GAAG,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAC;CACrC;AACF"}
1
+ {"version":3,"file":"azure.js","names":[],"sources":["../../src/utils/azure.ts"],"sourcesContent":["import { getEnv } from \"@langchain/core/utils/env\";\nimport { iife } from \"./misc.js\";\n\nexport interface OpenAIEndpointConfig {\n azureOpenAIApiDeploymentName?: string;\n azureOpenAIApiInstanceName?: string;\n azureOpenAIApiKey?: string;\n azureADTokenProvider?: () => Promise<string>;\n azureOpenAIBasePath?: string;\n baseURL?: string | null;\n azureOpenAIEndpoint?: string;\n}\n\n/**\n * This function generates an endpoint URL for (Azure) OpenAI\n * based on the configuration parameters provided.\n *\n * @param {OpenAIEndpointConfig} config - The configuration object for the (Azure) endpoint.\n *\n * @property {string} config.azureOpenAIApiDeploymentName - The deployment name of Azure OpenAI.\n * @property {string} config.azureOpenAIApiInstanceName - The instance name of Azure OpenAI, e.g. `example-resource`.\n * @property {string} config.azureOpenAIApiKey - The API Key for Azure OpenAI.\n * @property {string} config.azureOpenAIBasePath - The base path for Azure OpenAI, e.g. `https://example-resource.azure.openai.com/openai/deployments/`.\n * @property {string} config.baseURL - Some other custom base path URL.\n * @property {string} config.azureOpenAIEndpoint - The endpoint for the Azure OpenAI instance, e.g. `https://example-resource.azure.openai.com/`.\n *\n * The function operates as follows:\n * - If both `azureOpenAIBasePath` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`).\n * - If both `azureOpenAIEndpoint` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`).\n * - If `azureOpenAIApiKey` is provided, it checks for `azureOpenAIApiInstanceName` and `azureOpenAIApiDeploymentName` and throws an error if any of these is missing. If both are provided, it generates an URL incorporating these parameters.\n * - If none of the above conditions are met, return any custom `baseURL`.\n * - The function returns the generated URL as a string, or undefined if no custom paths are specified.\n *\n * @throws Will throw an error if the necessary parameters for generating the URL are missing.\n *\n * @returns {string | undefined} The generated (Azure) OpenAI endpoint URL.\n */\nexport function getEndpoint(config: OpenAIEndpointConfig) {\n const {\n azureOpenAIApiDeploymentName,\n azureOpenAIApiInstanceName,\n azureOpenAIApiKey,\n azureOpenAIBasePath,\n baseURL,\n azureADTokenProvider,\n azureOpenAIEndpoint,\n } = config;\n\n if (\n (azureOpenAIApiKey || azureADTokenProvider) &&\n azureOpenAIBasePath &&\n azureOpenAIApiDeploymentName\n ) {\n return `${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`;\n }\n if (\n (azureOpenAIApiKey || azureADTokenProvider) &&\n azureOpenAIEndpoint &&\n azureOpenAIApiDeploymentName\n ) {\n return `${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`;\n }\n\n if (azureOpenAIApiKey || azureADTokenProvider) {\n if (!azureOpenAIApiInstanceName) {\n throw new Error(\n \"azureOpenAIApiInstanceName is required when using azureOpenAIApiKey\"\n );\n }\n if (!azureOpenAIApiDeploymentName) {\n throw new Error(\n \"azureOpenAIApiDeploymentName is a required parameter when using azureOpenAIApiKey\"\n );\n }\n return `https://${azureOpenAIApiInstanceName}.openai.azure.com/openai/deployments/${azureOpenAIApiDeploymentName}`;\n }\n\n return baseURL;\n}\n\ntype HeaderValue = string | undefined | null;\nexport type HeadersLike =\n | Headers\n | readonly HeaderValue[][]\n | Record<string, HeaderValue | readonly HeaderValue[]>\n | undefined\n | null\n // NullableHeaders\n | { values: Headers; [key: string]: unknown };\n\nexport function isHeaders(headers: unknown): headers is Headers {\n return (\n typeof Headers !== \"undefined\" &&\n headers !== null &&\n typeof headers === \"object\" &&\n Object.prototype.toString.call(headers) === \"[object Headers]\"\n );\n}\n\n/**\n * Normalizes various header formats into a consistent Record format.\n *\n * This function accepts headers in multiple formats and converts them to a\n * Record<string, HeaderValue | readonly HeaderValue[]> for consistent handling.\n *\n * @param headers - The headers to normalize. Can be:\n * - A Headers instance\n * - An array of [key, value] pairs\n * - A plain object with string keys\n * - A NullableHeaders-like object with a 'values' property containing Headers\n * - null or undefined\n * @returns A normalized Record containing the header key-value pairs\n *\n * @example\n * ```ts\n * // With Headers instance\n * const headers1 = new Headers([['content-type', 'application/json']]);\n * const normalized1 = normalizeHeaders(headers1);\n *\n * // With plain object\n * const headers2 = { 'content-type': 'application/json' };\n * const normalized2 = normalizeHeaders(headers2);\n *\n * // With array of pairs\n * const headers3 = [['content-type', 'application/json']];\n * const normalized3 = normalizeHeaders(headers3);\n * ```\n */\nexport function normalizeHeaders(\n headers: HeadersLike\n): Record<string, HeaderValue | readonly HeaderValue[]> {\n const output = iife(() => {\n // If headers is a Headers instance\n if (isHeaders(headers)) {\n return headers;\n }\n // If headers is an array of [key, value] pairs\n else if (Array.isArray(headers)) {\n return new Headers(headers);\n }\n // If headers is a NullableHeaders-like object (has 'values' property that is a Headers)\n else if (\n typeof headers === \"object\" &&\n headers !== null &&\n \"values\" in headers &&\n isHeaders(headers.values)\n ) {\n return headers.values;\n }\n // If headers is a plain object\n else if (typeof headers === \"object\" && headers !== null) {\n const entries: [string, string][] = Object.entries(headers)\n .filter(([, v]) => typeof v === \"string\")\n .map(([k, v]) => [k, v as string]);\n return new Headers(entries);\n }\n return new Headers();\n });\n\n return Object.fromEntries(output.entries());\n}\n\nexport function getFormattedEnv() {\n let env = getEnv();\n if (env === \"node\" || env === \"deno\") {\n env = `(${env}/${process.version}; ${process.platform}; ${process.arch})`;\n }\n return env;\n}\n\n// Note: ideally version would be imported from package.json, but there's\n// currently no good way to do that for all supported environments (Node, Deno, Browser).\nexport function getHeadersWithUserAgent(\n headers: HeadersLike,\n isAzure = false,\n version = \"1.0.0\"\n): Record<string, string> {\n const normalizedHeaders = normalizeHeaders(headers);\n const env = getFormattedEnv();\n const library = `langchainjs${isAzure ? \"-azure\" : \"\"}-openai`;\n return {\n ...normalizedHeaders,\n \"User-Agent\": normalizedHeaders[\"User-Agent\"]\n ? `${library}/${version} (${env})${normalizedHeaders[\"User-Agent\"]}`\n : `${library}/${version} (${env})`,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,YAAY,QAA8B;CACxD,MAAM,EACJ,8BACA,4BACA,mBACA,qBACA,SACA,sBACA,wBACE;AAEJ,MACG,qBAAqB,yBACtB,uBACA,6BAEA,QAAO,GAAG,oBAAoB,GAAG;AAEnC,MACG,qBAAqB,yBACtB,uBACA,6BAEA,QAAO,GAAG,oBAAoB,sBAAsB;AAGtD,KAAI,qBAAqB,sBAAsB;AAC7C,MAAI,CAAC,2BACH,OAAM,IAAI,MACR,sEACD;AAEH,MAAI,CAAC,6BACH,OAAM,IAAI,MACR,oFACD;AAEH,SAAO,WAAW,2BAA2B,uCAAuC;;AAGtF,QAAO;;AAaT,SAAgB,UAAU,SAAsC;AAC9D,QACE,OAAO,YAAY,eACnB,YAAY,QACZ,OAAO,YAAY,YACnB,OAAO,UAAU,SAAS,KAAK,QAAQ,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiChD,SAAgB,iBACd,SACsD;CACtD,MAAM,SAAS,WAAW;AAExB,MAAI,UAAU,QAAQ,CACpB,QAAO;WAGA,MAAM,QAAQ,QAAQ,CAC7B,QAAO,IAAI,QAAQ,QAAQ;WAI3B,OAAO,YAAY,YACnB,YAAY,QACZ,YAAY,WACZ,UAAU,QAAQ,OAAO,CAEzB,QAAO,QAAQ;WAGR,OAAO,YAAY,YAAY,YAAY,MAAM;GACxD,MAAM,UAA8B,OAAO,QAAQ,QAAQ,CACxD,QAAQ,GAAG,OAAO,OAAO,MAAM,SAAS,CACxC,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,EAAY,CAAC;AACpC,UAAO,IAAI,QAAQ,QAAQ;;AAE7B,SAAO,IAAI,SAAS;GACpB;AAEF,QAAO,OAAO,YAAY,OAAO,SAAS,CAAC;;AAG7C,SAAgB,kBAAkB;CAChC,IAAI,MAAM,QAAQ;AAClB,KAAI,QAAQ,UAAU,QAAQ,OAC5B,OAAM,IAAI,IAAI,GAAG,QAAQ,QAAQ,IAAI,QAAQ,SAAS,IAAI,QAAQ,KAAK;AAEzE,QAAO;;AAKT,SAAgB,wBACd,SACA,UAAU,OACV,UAAU,SACc;CACxB,MAAM,oBAAoB,iBAAiB,QAAQ;CACnD,MAAM,MAAM,iBAAiB;CAC7B,MAAM,UAAU,cAAc,UAAU,WAAW,GAAG;AACtD,QAAO;EACL,GAAG;EACH,cAAc,kBAAkB,gBAC5B,GAAG,QAAQ,GAAG,QAAQ,IAAI,IAAI,GAAG,kBAAkB,kBACnD,GAAG,QAAQ,GAAG,QAAQ,IAAI,IAAI;EACnC"}
@@ -1,8 +1,13 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
1
  const require_errors = require('./errors.cjs');
3
- const openai = require_rolldown_runtime.__toESM(require("openai"));
2
+ let openai = require("openai");
3
+ let _langchain_core_errors = require("@langchain/core/errors");
4
4
 
5
5
  //#region src/utils/client.ts
6
+ function _isOpenAIContextOverflowError(e) {
7
+ if (String(e).includes("context_length_exceeded")) return true;
8
+ 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;
9
+ return false;
10
+ }
6
11
  function wrapOpenAIClientError(e) {
7
12
  if (!e || typeof e !== "object") return e;
8
13
  let error;
@@ -12,7 +17,8 @@ function wrapOpenAIClientError(e) {
12
17
  } else if (e.constructor.name === openai.APIUserAbortError.name && "message" in e && typeof e.message === "string") {
13
18
  error = new Error(e.message);
14
19
  error.name = "AbortError";
15
- } else if ("status" in e && e.status === 400 && "message" in e && typeof e.message === "string" && e.message.includes("tool_calls")) error = require_errors.addLangChainErrorFields(e, "INVALID_TOOL_RESULTS");
20
+ } else if (_isOpenAIContextOverflowError(e)) error = _langchain_core_errors.ContextOverflowError.fromError(e);
21
+ else if ("status" in e && e.status === 400 && "message" in e && typeof e.message === "string" && e.message.includes("tool_calls")) error = require_errors.addLangChainErrorFields(e, "INVALID_TOOL_RESULTS");
16
22
  else if ("status" in e && e.status === 401) error = require_errors.addLangChainErrorFields(e, "MODEL_AUTHENTICATION");
17
23
  else if ("status" in e && e.status === 429) error = require_errors.addLangChainErrorFields(e, "MODEL_RATE_LIMIT");
18
24
  else if ("status" in e && e.status === 404) error = require_errors.addLangChainErrorFields(e, "MODEL_NOT_FOUND");
@@ -1 +1 @@
1
- {"version":3,"file":"client.cjs","names":["e: unknown","APIConnectionTimeoutError","APIUserAbortError","addLangChainErrorFields"],"sources":["../../src/utils/client.ts"],"sourcesContent":["import { APIConnectionTimeoutError, APIUserAbortError } from \"openai\";\nimport { addLangChainErrorFields } from \"./errors.js\";\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 (\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":";;;;;AAGA,SAAgB,sBAAsBA,GAAY;AAChD,KAAI,CAAC,KAAK,OAAO,MAAM,SACrB,QAAO;CAGT,IAAI;AACJ,KACE,EAAE,YAAY,SAASC,iCAA0B,QACjD,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;EACA,QAAQ,IAAI,MAAM,EAAE;EACpB,MAAM,OAAO;CACd,WACC,EAAE,YAAY,SAASC,yBAAkB,QACzC,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;EACA,QAAQ,IAAI,MAAM,EAAE;EACpB,MAAM,OAAO;CACd,WACC,YAAY,KACZ,EAAE,WAAW,OACb,aAAa,KACb,OAAO,EAAE,YAAY,YACrB,EAAE,QAAQ,SAAS,aAAa,EAEhC,QAAQC,uCAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,KACvC,QAAQA,uCAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,KACvC,QAAQA,uCAAwB,GAAG,mBAAmB;UAC7C,YAAY,KAAK,EAAE,WAAW,KACvC,QAAQA,uCAAwB,GAAG,kBAAkB;MAErD,QAAQ;AAEV,QAAO;AACR"}
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,iCAA0B,QACjD,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;AACA,UAAQ,IAAI,MAAM,EAAE,QAAQ;AAC5B,QAAM,OAAO;YAEb,EAAE,YAAY,SAASC,yBAAkB,QACzC,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;AACA,UAAQ,IAAI,MAAM,EAAE,QAAQ;AAC5B,QAAM,OAAO;YACJ,8BAA8B,EAAE,CACzC,SAAQC,4CAAqB,UAAU,EAAW;UAElD,YAAY,KACZ,EAAE,WAAW,OACb,aAAa,KACb,OAAO,EAAE,YAAY,YACrB,EAAE,QAAQ,SAAS,aAAa,CAEhC,SAAQC,uCAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQA,uCAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQA,uCAAwB,GAAG,mBAAmB;UAC7C,YAAY,KAAK,EAAE,WAAW,IACvC,SAAQA,uCAAwB,GAAG,kBAAkB;KAErD,SAAQ;AAEV,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.cts","names":["wrapOpenAIClientError"],"sources":["../../src/utils/client.d.ts"],"sourcesContent":["export declare function wrapOpenAIClientError(e: unknown): any;\n//# sourceMappingURL=client.d.ts.map"],"mappings":";iBAAwBA,qBAAAA"}
1
+ {"version":3,"file":"client.d.cts","names":[],"sources":["../../src/utils/client.ts"],"mappings":";iBAoBgB,qBAAA,CAAsB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","names":["wrapOpenAIClientError"],"sources":["../../src/utils/client.d.ts"],"sourcesContent":["export declare function wrapOpenAIClientError(e: unknown): any;\n//# sourceMappingURL=client.d.ts.map"],"mappings":";iBAAwBA,qBAAAA"}
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../../src/utils/client.ts"],"mappings":";iBAoBgB,qBAAA,CAAsB,CAAA"}
@@ -1,7 +1,13 @@
1
1
  import { addLangChainErrorFields } from "./errors.js";
2
2
  import { APIConnectionTimeoutError, APIUserAbortError } from "openai";
3
+ import { ContextOverflowError } from "@langchain/core/errors";
3
4
 
4
5
  //#region src/utils/client.ts
6
+ function _isOpenAIContextOverflowError(e) {
7
+ if (String(e).includes("context_length_exceeded")) return true;
8
+ 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;
9
+ return false;
10
+ }
5
11
  function wrapOpenAIClientError(e) {
6
12
  if (!e || typeof e !== "object") return e;
7
13
  let error;
@@ -11,7 +17,8 @@ function wrapOpenAIClientError(e) {
11
17
  } else if (e.constructor.name === APIUserAbortError.name && "message" in e && typeof e.message === "string") {
12
18
  error = new Error(e.message);
13
19
  error.name = "AbortError";
14
- } else if ("status" in e && e.status === 400 && "message" in e && typeof e.message === "string" && e.message.includes("tool_calls")) error = addLangChainErrorFields(e, "INVALID_TOOL_RESULTS");
20
+ } else if (_isOpenAIContextOverflowError(e)) error = ContextOverflowError.fromError(e);
21
+ else if ("status" in e && e.status === 400 && "message" in e && typeof e.message === "string" && e.message.includes("tool_calls")) error = addLangChainErrorFields(e, "INVALID_TOOL_RESULTS");
15
22
  else if ("status" in e && e.status === 401) error = addLangChainErrorFields(e, "MODEL_AUTHENTICATION");
16
23
  else if ("status" in e && e.status === 429) error = addLangChainErrorFields(e, "MODEL_RATE_LIMIT");
17
24
  else if ("status" in e && e.status === 404) error = addLangChainErrorFields(e, "MODEL_NOT_FOUND");
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":["e: unknown"],"sources":["../../src/utils/client.ts"],"sourcesContent":["import { APIConnectionTimeoutError, APIUserAbortError } from \"openai\";\nimport { addLangChainErrorFields } from \"./errors.js\";\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 (\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":";;;;AAGA,SAAgB,sBAAsBA,GAAY;AAChD,KAAI,CAAC,KAAK,OAAO,MAAM,SACrB,QAAO;CAGT,IAAI;AACJ,KACE,EAAE,YAAY,SAAS,0BAA0B,QACjD,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;EACA,QAAQ,IAAI,MAAM,EAAE;EACpB,MAAM,OAAO;CACd,WACC,EAAE,YAAY,SAAS,kBAAkB,QACzC,aAAa,KACb,OAAO,EAAE,YAAY,UACrB;EACA,QAAQ,IAAI,MAAM,EAAE;EACpB,MAAM,OAAO;CACd,WACC,YAAY,KACZ,EAAE,WAAW,OACb,aAAa,KACb,OAAO,EAAE,YAAY,YACrB,EAAE,QAAQ,SAAS,aAAa,EAEhC,QAAQ,wBAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,KACvC,QAAQ,wBAAwB,GAAG,uBAAuB;UACjD,YAAY,KAAK,EAAE,WAAW,KACvC,QAAQ,wBAAwB,GAAG,mBAAmB;UAC7C,YAAY,KAAK,EAAE,WAAW,KACvC,QAAQ,wBAAwB,GAAG,kBAAkB;MAErD,QAAQ;AAEV,QAAO;AACR"}
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 +1 @@
1
- {"version":3,"file":"errors.cjs","names":["error: any","lc_error_code: LangChainErrorCodes"],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n// Duplicate of core\n// TODO: Remove once we stop supporting 0.2.x core versions\nexport type LangChainErrorCodes =\n | \"INVALID_PROMPT_INPUT\"\n | \"INVALID_TOOL_RESULTS\"\n | \"MESSAGE_COERCION_FAILURE\"\n | \"MODEL_AUTHENTICATION\"\n | \"MODEL_NOT_FOUND\"\n | \"MODEL_RATE_LIMIT\"\n | \"OUTPUT_PARSING_FAILURE\";\n\nexport function addLangChainErrorFields(\n error: any,\n lc_error_code: LangChainErrorCodes\n) {\n (error as any).lc_error_code = lc_error_code;\n error.message = `${error.message}\\n\\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langchain/errors/${lc_error_code}/\\n`;\n return error;\n}\n"],"mappings":";;AAaA,SAAgB,wBACdA,OACAC,eACA;CACC,MAAc,gBAAgB;CAC/B,MAAM,UAAU,GAAG,MAAM,QAAQ,oFAAoF,EAAE,cAAc,GAAG,CAAC;AACzI,QAAO;AACR"}
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n// Duplicate of core\n// TODO: Remove once we stop supporting 0.2.x core versions\nexport type LangChainErrorCodes =\n | \"CONTEXT_OVERFLOW\"\n | \"INVALID_PROMPT_INPUT\"\n | \"INVALID_TOOL_RESULTS\"\n | \"MESSAGE_COERCION_FAILURE\"\n | \"MODEL_AUTHENTICATION\"\n | \"MODEL_NOT_FOUND\"\n | \"MODEL_RATE_LIMIT\"\n | \"OUTPUT_PARSING_FAILURE\";\n\nexport function addLangChainErrorFields(\n error: any,\n lc_error_code: LangChainErrorCodes\n) {\n (error as any).lc_error_code = lc_error_code;\n error.message = `${error.message}\\n\\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langchain/errors/${lc_error_code}/\\n`;\n return error;\n}\n"],"mappings":";;AAcA,SAAgB,wBACd,OACA,eACA;AACA,CAAC,MAAc,gBAAgB;AAC/B,OAAM,UAAU,GAAG,MAAM,QAAQ,sFAAsF,cAAc;AACrI,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":["error: any","lc_error_code: LangChainErrorCodes"],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n// Duplicate of core\n// TODO: Remove once we stop supporting 0.2.x core versions\nexport type LangChainErrorCodes =\n | \"INVALID_PROMPT_INPUT\"\n | \"INVALID_TOOL_RESULTS\"\n | \"MESSAGE_COERCION_FAILURE\"\n | \"MODEL_AUTHENTICATION\"\n | \"MODEL_NOT_FOUND\"\n | \"MODEL_RATE_LIMIT\"\n | \"OUTPUT_PARSING_FAILURE\";\n\nexport function addLangChainErrorFields(\n error: any,\n lc_error_code: LangChainErrorCodes\n) {\n (error as any).lc_error_code = lc_error_code;\n error.message = `${error.message}\\n\\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langchain/errors/${lc_error_code}/\\n`;\n return error;\n}\n"],"mappings":";AAaA,SAAgB,wBACdA,OACAC,eACA;CACC,MAAc,gBAAgB;CAC/B,MAAM,UAAU,GAAG,MAAM,QAAQ,oFAAoF,EAAE,cAAc,GAAG,CAAC;AACzI,QAAO;AACR"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n// Duplicate of core\n// TODO: Remove once we stop supporting 0.2.x core versions\nexport type LangChainErrorCodes =\n | \"CONTEXT_OVERFLOW\"\n | \"INVALID_PROMPT_INPUT\"\n | \"INVALID_TOOL_RESULTS\"\n | \"MESSAGE_COERCION_FAILURE\"\n | \"MODEL_AUTHENTICATION\"\n | \"MODEL_NOT_FOUND\"\n | \"MODEL_RATE_LIMIT\"\n | \"OUTPUT_PARSING_FAILURE\";\n\nexport function addLangChainErrorFields(\n error: any,\n lc_error_code: LangChainErrorCodes\n) {\n (error as any).lc_error_code = lc_error_code;\n error.message = `${error.message}\\n\\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langchain/errors/${lc_error_code}/\\n`;\n return error;\n}\n"],"mappings":";AAcA,SAAgB,wBACd,OACA,eACA;AACA,CAAC,MAAc,gBAAgB;AAC/B,OAAM,UAAU,GAAG,MAAM,QAAQ,sFAAsF,cAAc;AACrI,QAAO"}
@@ -1,5 +1,4 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- const __langchain_core_messages = require_rolldown_runtime.__toESM(require("@langchain/core/messages"));
1
+ let _langchain_core_messages = require("@langchain/core/messages");
3
2
 
4
3
  //#region src/utils/misc.ts
5
4
  const iife = (fn) => fn();
@@ -30,7 +29,7 @@ function messageToOpenAIRole(message) {
30
29
  case "function": return "function";
31
30
  case "tool": return "tool";
32
31
  case "generic":
33
- if (!__langchain_core_messages.ChatMessage.isInstance(message)) throw new Error("Invalid generic chat message");
32
+ if (!_langchain_core_messages.ChatMessage.isInstance(message)) throw new Error("Invalid generic chat message");
34
33
  return extractGenericMessageCustomRole(message);
35
34
  default: throw new Error(`Unknown message type: ${type}`);
36
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"misc.cjs","names":["fn: () => T","model?: string","message: ChatMessage","block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock","message: BaseMessage","ChatMessage","model: string"],"sources":["../../src/utils/misc.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport {\n BaseMessage,\n ChatMessage,\n ContentBlock,\n Data,\n} from \"@langchain/core/messages\";\n\nexport const iife = <T>(fn: () => T) => fn();\n\nexport function isReasoningModel(model?: string) {\n if (!model) return false;\n if (/^o\\d/.test(model ?? \"\")) return true;\n if (model.startsWith(\"gpt-5\") && !model.startsWith(\"gpt-5-chat\")) return true;\n return false;\n}\n\nexport function extractGenericMessageCustomRole(message: ChatMessage) {\n if (\n message.role !== \"system\" &&\n message.role !== \"developer\" &&\n message.role !== \"assistant\" &&\n message.role !== \"user\" &&\n message.role !== \"function\" &&\n message.role !== \"tool\"\n ) {\n console.warn(`Unknown message role: ${message.role}`);\n }\n\n return message.role as OpenAIClient.ChatCompletionRole;\n}\n\nexport function getFilenameFromMetadata(\n block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock\n): string | undefined {\n return (block.metadata?.filename ??\n block.metadata?.name ??\n block.metadata?.title) as string;\n}\n\nexport function getRequiredFilenameFromMetadata(\n block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock\n): string {\n const filename = (block.metadata?.filename ??\n block.metadata?.name ??\n block.metadata?.title) as string;\n\n if (!filename) {\n throw new Error(\n \"a filename or name or title is needed via meta-data for OpenAI when working with multimodal blocks\"\n );\n }\n\n return filename;\n}\nexport function messageToOpenAIRole(\n message: BaseMessage\n): OpenAIClient.ChatCompletionRole {\n const type = message._getType();\n switch (type) {\n case \"system\":\n return \"system\";\n case \"ai\":\n return \"assistant\";\n case \"human\":\n return \"user\";\n case \"function\":\n return \"function\";\n case \"tool\":\n return \"tool\";\n case \"generic\": {\n if (!ChatMessage.isInstance(message))\n throw new Error(\"Invalid generic chat message\");\n return extractGenericMessageCustomRole(message);\n }\n default:\n throw new Error(`Unknown message type: ${type}`);\n }\n}\n\nexport function _modelPrefersResponsesAPI(model: string): boolean {\n if (model.includes(\"gpt-5.2-pro\")) return true;\n // Codex models are Responses API only\n if (model.includes(\"codex\")) return true;\n return false;\n}\n"],"mappings":";;;;AAQA,MAAa,OAAO,CAAIA,OAAgB,IAAI;AAE5C,SAAgB,iBAAiBC,OAAgB;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,OAAO,KAAK,SAAS,GAAG,CAAE,QAAO;AACrC,KAAI,MAAM,WAAW,QAAQ,IAAI,CAAC,MAAM,WAAW,aAAa,CAAE,QAAO;AACzE,QAAO;AACR;AAED,SAAgB,gCAAgCC,SAAsB;AACpE,KACE,QAAQ,SAAS,YACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,UACjB,QAAQ,SAAS,cACjB,QAAQ,SAAS,QAEjB,QAAQ,KAAK,CAAC,sBAAsB,EAAE,QAAQ,MAAM,CAAC;AAGvD,QAAO,QAAQ;AAChB;AAED,SAAgB,wBACdC,OAIoB;AACpB,QAAQ,MAAM,UAAU,YACtB,MAAM,UAAU,QAChB,MAAM,UAAU;AACnB;AAED,SAAgB,gCACdA,OAIQ;CACR,MAAM,WAAY,MAAM,UAAU,YAChC,MAAM,UAAU,QAChB,MAAM,UAAU;AAElB,KAAI,CAAC,SACH,OAAM,IAAI,MACR;AAIJ,QAAO;AACR;AACD,SAAgB,oBACdC,SACiC;CACjC,MAAM,OAAO,QAAQ,UAAU;AAC/B,SAAQ,MAAR;EACE,KAAK,SACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,QACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK;AACH,OAAI,CAACC,sCAAY,WAAW,QAAQ,CAClC,OAAM,IAAI,MAAM;AAClB,UAAO,gCAAgC,QAAQ;EAEjD,QACE,OAAM,IAAI,MAAM,CAAC,sBAAsB,EAAE,MAAM;CAClD;AACF;AAED,SAAgB,0BAA0BC,OAAwB;AAChE,KAAI,MAAM,SAAS,cAAc,CAAE,QAAO;AAE1C,KAAI,MAAM,SAAS,QAAQ,CAAE,QAAO;AACpC,QAAO;AACR"}
1
+ {"version":3,"file":"misc.cjs","names":["ChatMessage"],"sources":["../../src/utils/misc.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport {\n BaseMessage,\n ChatMessage,\n ContentBlock,\n Data,\n} from \"@langchain/core/messages\";\n\nexport const iife = <T>(fn: () => T) => fn();\n\nexport function isReasoningModel(model?: string) {\n if (!model) return false;\n if (/^o\\d/.test(model ?? \"\")) return true;\n if (model.startsWith(\"gpt-5\") && !model.startsWith(\"gpt-5-chat\")) return true;\n return false;\n}\n\nexport function extractGenericMessageCustomRole(message: ChatMessage) {\n if (\n message.role !== \"system\" &&\n message.role !== \"developer\" &&\n message.role !== \"assistant\" &&\n message.role !== \"user\" &&\n message.role !== \"function\" &&\n message.role !== \"tool\"\n ) {\n console.warn(`Unknown message role: ${message.role}`);\n }\n\n return message.role as OpenAIClient.ChatCompletionRole;\n}\n\nexport function getFilenameFromMetadata(\n block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock\n): string | undefined {\n return (block.metadata?.filename ??\n block.metadata?.name ??\n block.metadata?.title) as string;\n}\n\nexport function getRequiredFilenameFromMetadata(\n block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock\n): string {\n const filename = (block.metadata?.filename ??\n block.metadata?.name ??\n block.metadata?.title) as string;\n\n if (!filename) {\n throw new Error(\n \"a filename or name or title is needed via meta-data for OpenAI when working with multimodal blocks\"\n );\n }\n\n return filename;\n}\nexport function messageToOpenAIRole(\n message: BaseMessage\n): OpenAIClient.ChatCompletionRole {\n const type = message._getType();\n switch (type) {\n case \"system\":\n return \"system\";\n case \"ai\":\n return \"assistant\";\n case \"human\":\n return \"user\";\n case \"function\":\n return \"function\";\n case \"tool\":\n return \"tool\";\n case \"generic\": {\n if (!ChatMessage.isInstance(message))\n throw new Error(\"Invalid generic chat message\");\n return extractGenericMessageCustomRole(message);\n }\n default:\n throw new Error(`Unknown message type: ${type}`);\n }\n}\n\nexport function _modelPrefersResponsesAPI(model: string): boolean {\n if (model.includes(\"gpt-5.2-pro\")) return true;\n // Codex models are Responses API only\n if (model.includes(\"codex\")) return true;\n return false;\n}\n"],"mappings":";;;AAQA,MAAa,QAAW,OAAgB,IAAI;AAE5C,SAAgB,iBAAiB,OAAgB;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,OAAO,KAAK,SAAS,GAAG,CAAE,QAAO;AACrC,KAAI,MAAM,WAAW,QAAQ,IAAI,CAAC,MAAM,WAAW,aAAa,CAAE,QAAO;AACzE,QAAO;;AAGT,SAAgB,gCAAgC,SAAsB;AACpE,KACE,QAAQ,SAAS,YACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,UACjB,QAAQ,SAAS,cACjB,QAAQ,SAAS,OAEjB,SAAQ,KAAK,yBAAyB,QAAQ,OAAO;AAGvD,QAAO,QAAQ;;AAGjB,SAAgB,wBACd,OAIoB;AACpB,QAAQ,MAAM,UAAU,YACtB,MAAM,UAAU,QAChB,MAAM,UAAU;;AAGpB,SAAgB,gCACd,OAIQ;CACR,MAAM,WAAY,MAAM,UAAU,YAChC,MAAM,UAAU,QAChB,MAAM,UAAU;AAElB,KAAI,CAAC,SACH,OAAM,IAAI,MACR,qGACD;AAGH,QAAO;;AAET,SAAgB,oBACd,SACiC;CACjC,MAAM,OAAO,QAAQ,UAAU;AAC/B,SAAQ,MAAR;EACE,KAAK,SACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,QACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK;AACH,OAAI,CAACA,qCAAY,WAAW,QAAQ,CAClC,OAAM,IAAI,MAAM,+BAA+B;AACjD,UAAO,gCAAgC,QAAQ;EAEjD,QACE,OAAM,IAAI,MAAM,yBAAyB,OAAO;;;AAItD,SAAgB,0BAA0B,OAAwB;AAChE,KAAI,MAAM,SAAS,cAAc,CAAE,QAAO;AAE1C,KAAI,MAAM,SAAS,QAAQ,CAAE,QAAO;AACpC,QAAO"}
@@ -2,7 +2,6 @@ import { OpenAI as OpenAI$1 } from "openai";
2
2
  import { BaseMessage, ContentBlock } from "@langchain/core/messages";
3
3
 
4
4
  //#region src/utils/misc.d.ts
5
-
6
5
  declare function messageToOpenAIRole(message: BaseMessage): OpenAI$1.ChatCompletionRole;
7
6
  //#endregion
8
7
  export { messageToOpenAIRole };
@@ -1 +1 @@
1
- {"version":3,"file":"misc.d.cts","names":["OpenAI","OpenAIClient","BaseMessage","ChatMessage","ContentBlock","Data","iife","T","isReasoningModel","extractGenericMessageCustomRole","ChatCompletionRole","getFilenameFromMetadata","Multimodal","File","Video","StandardFileBlock","getRequiredFilenameFromMetadata","messageToOpenAIRole","_modelPrefersResponsesAPI"],"sources":["../../src/utils/misc.d.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport { BaseMessage, ChatMessage, ContentBlock, Data } from \"@langchain/core/messages\";\nexport declare const iife: <T>(fn: () => T) => T;\nexport declare function isReasoningModel(model?: string): boolean;\nexport declare function extractGenericMessageCustomRole(message: ChatMessage): OpenAIClient.ChatCompletionRole;\nexport declare function getFilenameFromMetadata(block: ContentBlock.Multimodal.File | ContentBlock.Multimodal.Video | Data.StandardFileBlock): string | undefined;\nexport declare function getRequiredFilenameFromMetadata(block: ContentBlock.Multimodal.File | ContentBlock.Multimodal.Video | Data.StandardFileBlock): string;\nexport declare function messageToOpenAIRole(message: BaseMessage): OpenAIClient.ChatCompletionRole;\nexport declare function _modelPrefersResponsesAPI(model: string): boolean;\n//# sourceMappingURL=misc.d.ts.map"],"mappings":";;;;;iBAOwBiB,mBAAAA,UAA6Bf,cAAcD,QAAAA,CAAaS"}
1
+ {"version":3,"file":"misc.d.cts","names":[],"sources":["../../src/utils/misc.ts"],"mappings":";;;;iBA6DgB,mBAAA,CACd,OAAA,EAAS,WAAA,GACR,QAAA,CAAa,kBAAA"}
@@ -2,7 +2,6 @@ import { OpenAI as OpenAI$1 } from "openai";
2
2
  import { BaseMessage, ChatMessage, ContentBlock } from "@langchain/core/messages";
3
3
 
4
4
  //#region src/utils/misc.d.ts
5
-
6
5
  declare function messageToOpenAIRole(message: BaseMessage): OpenAI$1.ChatCompletionRole;
7
6
  //#endregion
8
7
  export { messageToOpenAIRole };
@@ -1 +1 @@
1
- {"version":3,"file":"misc.d.ts","names":["OpenAI","OpenAIClient","BaseMessage","ChatMessage","ContentBlock","Data","iife","T","isReasoningModel","extractGenericMessageCustomRole","ChatCompletionRole","getFilenameFromMetadata","Multimodal","File","Video","StandardFileBlock","getRequiredFilenameFromMetadata","messageToOpenAIRole","_modelPrefersResponsesAPI"],"sources":["../../src/utils/misc.d.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport { BaseMessage, ChatMessage, ContentBlock, Data } from \"@langchain/core/messages\";\nexport declare const iife: <T>(fn: () => T) => T;\nexport declare function isReasoningModel(model?: string): boolean;\nexport declare function extractGenericMessageCustomRole(message: ChatMessage): OpenAIClient.ChatCompletionRole;\nexport declare function getFilenameFromMetadata(block: ContentBlock.Multimodal.File | ContentBlock.Multimodal.Video | Data.StandardFileBlock): string | undefined;\nexport declare function getRequiredFilenameFromMetadata(block: ContentBlock.Multimodal.File | ContentBlock.Multimodal.Video | Data.StandardFileBlock): string;\nexport declare function messageToOpenAIRole(message: BaseMessage): OpenAIClient.ChatCompletionRole;\nexport declare function _modelPrefersResponsesAPI(model: string): boolean;\n//# sourceMappingURL=misc.d.ts.map"],"mappings":";;;;;iBAOwBiB,mBAAAA,UAA6Bf,cAAcD,QAAAA,CAAaS"}
1
+ {"version":3,"file":"misc.d.ts","names":[],"sources":["../../src/utils/misc.ts"],"mappings":";;;;iBA6DgB,mBAAA,CACd,OAAA,EAAS,WAAA,GACR,QAAA,CAAa,kBAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"misc.js","names":["iife","fn: () => T","model?: string","message: ChatMessage","block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock","message: BaseMessage","model: string"],"sources":["../../src/utils/misc.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport {\n BaseMessage,\n ChatMessage,\n ContentBlock,\n Data,\n} from \"@langchain/core/messages\";\n\nexport const iife = <T>(fn: () => T) => fn();\n\nexport function isReasoningModel(model?: string) {\n if (!model) return false;\n if (/^o\\d/.test(model ?? \"\")) return true;\n if (model.startsWith(\"gpt-5\") && !model.startsWith(\"gpt-5-chat\")) return true;\n return false;\n}\n\nexport function extractGenericMessageCustomRole(message: ChatMessage) {\n if (\n message.role !== \"system\" &&\n message.role !== \"developer\" &&\n message.role !== \"assistant\" &&\n message.role !== \"user\" &&\n message.role !== \"function\" &&\n message.role !== \"tool\"\n ) {\n console.warn(`Unknown message role: ${message.role}`);\n }\n\n return message.role as OpenAIClient.ChatCompletionRole;\n}\n\nexport function getFilenameFromMetadata(\n block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock\n): string | undefined {\n return (block.metadata?.filename ??\n block.metadata?.name ??\n block.metadata?.title) as string;\n}\n\nexport function getRequiredFilenameFromMetadata(\n block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock\n): string {\n const filename = (block.metadata?.filename ??\n block.metadata?.name ??\n block.metadata?.title) as string;\n\n if (!filename) {\n throw new Error(\n \"a filename or name or title is needed via meta-data for OpenAI when working with multimodal blocks\"\n );\n }\n\n return filename;\n}\nexport function messageToOpenAIRole(\n message: BaseMessage\n): OpenAIClient.ChatCompletionRole {\n const type = message._getType();\n switch (type) {\n case \"system\":\n return \"system\";\n case \"ai\":\n return \"assistant\";\n case \"human\":\n return \"user\";\n case \"function\":\n return \"function\";\n case \"tool\":\n return \"tool\";\n case \"generic\": {\n if (!ChatMessage.isInstance(message))\n throw new Error(\"Invalid generic chat message\");\n return extractGenericMessageCustomRole(message);\n }\n default:\n throw new Error(`Unknown message type: ${type}`);\n }\n}\n\nexport function _modelPrefersResponsesAPI(model: string): boolean {\n if (model.includes(\"gpt-5.2-pro\")) return true;\n // Codex models are Responses API only\n if (model.includes(\"codex\")) return true;\n return false;\n}\n"],"mappings":";;;AAQA,MAAaA,SAAO,CAAIC,OAAgB,IAAI;AAE5C,SAAgB,iBAAiBC,OAAgB;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,OAAO,KAAK,SAAS,GAAG,CAAE,QAAO;AACrC,KAAI,MAAM,WAAW,QAAQ,IAAI,CAAC,MAAM,WAAW,aAAa,CAAE,QAAO;AACzE,QAAO;AACR;AAED,SAAgB,gCAAgCC,SAAsB;AACpE,KACE,QAAQ,SAAS,YACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,UACjB,QAAQ,SAAS,cACjB,QAAQ,SAAS,QAEjB,QAAQ,KAAK,CAAC,sBAAsB,EAAE,QAAQ,MAAM,CAAC;AAGvD,QAAO,QAAQ;AAChB;AAED,SAAgB,wBACdC,OAIoB;AACpB,QAAQ,MAAM,UAAU,YACtB,MAAM,UAAU,QAChB,MAAM,UAAU;AACnB;AAED,SAAgB,gCACdA,OAIQ;CACR,MAAM,WAAY,MAAM,UAAU,YAChC,MAAM,UAAU,QAChB,MAAM,UAAU;AAElB,KAAI,CAAC,SACH,OAAM,IAAI,MACR;AAIJ,QAAO;AACR;AACD,SAAgB,oBACdC,SACiC;CACjC,MAAM,OAAO,QAAQ,UAAU;AAC/B,SAAQ,MAAR;EACE,KAAK,SACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,QACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK;AACH,OAAI,CAAC,YAAY,WAAW,QAAQ,CAClC,OAAM,IAAI,MAAM;AAClB,UAAO,gCAAgC,QAAQ;EAEjD,QACE,OAAM,IAAI,MAAM,CAAC,sBAAsB,EAAE,MAAM;CAClD;AACF;AAED,SAAgB,0BAA0BC,OAAwB;AAChE,KAAI,MAAM,SAAS,cAAc,CAAE,QAAO;AAE1C,KAAI,MAAM,SAAS,QAAQ,CAAE,QAAO;AACpC,QAAO;AACR"}
1
+ {"version":3,"file":"misc.js","names":["iife"],"sources":["../../src/utils/misc.ts"],"sourcesContent":["import type { OpenAI as OpenAIClient } from \"openai\";\nimport {\n BaseMessage,\n ChatMessage,\n ContentBlock,\n Data,\n} from \"@langchain/core/messages\";\n\nexport const iife = <T>(fn: () => T) => fn();\n\nexport function isReasoningModel(model?: string) {\n if (!model) return false;\n if (/^o\\d/.test(model ?? \"\")) return true;\n if (model.startsWith(\"gpt-5\") && !model.startsWith(\"gpt-5-chat\")) return true;\n return false;\n}\n\nexport function extractGenericMessageCustomRole(message: ChatMessage) {\n if (\n message.role !== \"system\" &&\n message.role !== \"developer\" &&\n message.role !== \"assistant\" &&\n message.role !== \"user\" &&\n message.role !== \"function\" &&\n message.role !== \"tool\"\n ) {\n console.warn(`Unknown message role: ${message.role}`);\n }\n\n return message.role as OpenAIClient.ChatCompletionRole;\n}\n\nexport function getFilenameFromMetadata(\n block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock\n): string | undefined {\n return (block.metadata?.filename ??\n block.metadata?.name ??\n block.metadata?.title) as string;\n}\n\nexport function getRequiredFilenameFromMetadata(\n block:\n | ContentBlock.Multimodal.File\n | ContentBlock.Multimodal.Video\n | Data.StandardFileBlock\n): string {\n const filename = (block.metadata?.filename ??\n block.metadata?.name ??\n block.metadata?.title) as string;\n\n if (!filename) {\n throw new Error(\n \"a filename or name or title is needed via meta-data for OpenAI when working with multimodal blocks\"\n );\n }\n\n return filename;\n}\nexport function messageToOpenAIRole(\n message: BaseMessage\n): OpenAIClient.ChatCompletionRole {\n const type = message._getType();\n switch (type) {\n case \"system\":\n return \"system\";\n case \"ai\":\n return \"assistant\";\n case \"human\":\n return \"user\";\n case \"function\":\n return \"function\";\n case \"tool\":\n return \"tool\";\n case \"generic\": {\n if (!ChatMessage.isInstance(message))\n throw new Error(\"Invalid generic chat message\");\n return extractGenericMessageCustomRole(message);\n }\n default:\n throw new Error(`Unknown message type: ${type}`);\n }\n}\n\nexport function _modelPrefersResponsesAPI(model: string): boolean {\n if (model.includes(\"gpt-5.2-pro\")) return true;\n // Codex models are Responses API only\n if (model.includes(\"codex\")) return true;\n return false;\n}\n"],"mappings":";;;AAQA,MAAaA,UAAW,OAAgB,IAAI;AAE5C,SAAgB,iBAAiB,OAAgB;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,OAAO,KAAK,SAAS,GAAG,CAAE,QAAO;AACrC,KAAI,MAAM,WAAW,QAAQ,IAAI,CAAC,MAAM,WAAW,aAAa,CAAE,QAAO;AACzE,QAAO;;AAGT,SAAgB,gCAAgC,SAAsB;AACpE,KACE,QAAQ,SAAS,YACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,eACjB,QAAQ,SAAS,UACjB,QAAQ,SAAS,cACjB,QAAQ,SAAS,OAEjB,SAAQ,KAAK,yBAAyB,QAAQ,OAAO;AAGvD,QAAO,QAAQ;;AAGjB,SAAgB,wBACd,OAIoB;AACpB,QAAQ,MAAM,UAAU,YACtB,MAAM,UAAU,QAChB,MAAM,UAAU;;AAGpB,SAAgB,gCACd,OAIQ;CACR,MAAM,WAAY,MAAM,UAAU,YAChC,MAAM,UAAU,QAChB,MAAM,UAAU;AAElB,KAAI,CAAC,SACH,OAAM,IAAI,MACR,qGACD;AAGH,QAAO;;AAET,SAAgB,oBACd,SACiC;CACjC,MAAM,OAAO,QAAQ,UAAU;AAC/B,SAAQ,MAAR;EACE,KAAK,SACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,QACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK;AACH,OAAI,CAAC,YAAY,WAAW,QAAQ,CAClC,OAAM,IAAI,MAAM,+BAA+B;AACjD,UAAO,gCAAgC,QAAQ;EAEjD,QACE,OAAM,IAAI,MAAM,yBAAyB,OAAO;;;AAItD,SAAgB,0BAA0B,OAAwB;AAChE,KAAI,MAAM,SAAS,cAAc,CAAE,QAAO;AAE1C,KAAI,MAAM,SAAS,QAAQ,CAAE,QAAO;AACpC,QAAO"}
@@ -1,8 +1,7 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- const __langchain_core_utils_types = require_rolldown_runtime.__toESM(require("@langchain/core/utils/types"));
3
- const __langchain_core_utils_json_schema = require_rolldown_runtime.__toESM(require("@langchain/core/utils/json_schema"));
4
- const zod_v4_core = require_rolldown_runtime.__toESM(require("zod/v4/core"));
5
- const openai_helpers_zod = require_rolldown_runtime.__toESM(require("openai/helpers/zod"));
1
+ let _langchain_core_utils_types = require("@langchain/core/utils/types");
2
+ let _langchain_core_utils_json_schema = require("@langchain/core/utils/json_schema");
3
+ let zod_v4_core = require("zod/v4/core");
4
+ let openai_helpers_zod = require("openai/helpers/zod");
6
5
 
7
6
  //#region src/utils/output.ts
8
7
  const SUPPORTED_METHODS = [
@@ -50,14 +49,14 @@ function makeParseableResponseFormat(response_format, parser) {
50
49
  return obj;
51
50
  }
52
51
  function interopZodResponseFormat(zodSchema, name, props) {
53
- if ((0, __langchain_core_utils_types.isZodSchemaV3)(zodSchema)) return (0, openai_helpers_zod.zodResponseFormat)(zodSchema, name, props);
54
- if ((0, __langchain_core_utils_types.isZodSchemaV4)(zodSchema)) return makeParseableResponseFormat({
52
+ if ((0, _langchain_core_utils_types.isZodSchemaV3)(zodSchema)) return (0, openai_helpers_zod.zodResponseFormat)(zodSchema, name, props);
53
+ if ((0, _langchain_core_utils_types.isZodSchemaV4)(zodSchema)) return makeParseableResponseFormat({
55
54
  type: "json_schema",
56
55
  json_schema: {
57
56
  ...props,
58
57
  name,
59
58
  strict: true,
60
- schema: (0, __langchain_core_utils_json_schema.toJsonSchema)(zodSchema, {
59
+ schema: (0, _langchain_core_utils_json_schema.toJsonSchema)(zodSchema, {
61
60
  cycles: "ref",
62
61
  reused: "ref",
63
62
  override(ctx) {
@@ -1 +1 @@
1
- {"version":3,"file":"output.cjs","names":["model: string","method: unknown","response_format: ResponseFormatJSONSchema","parser: (content: string) => ParsedT","zodSchema: InteropZodType","name: string","props: Omit<ResponseFormatJSONSchema.JSONSchema, \"schema\" | \"strict\" | \"name\">","content: string","messages: unknown"],"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;AACD;;;;;;;;;;AAYD,SAAgB,0BACdA,OACAC,QACiB;;;;AAIjB,KACE,OAAO,WAAW,eAClB,CAAC,kBAAkB,SAAS,OAA0B,CAEtD,OAAM,IAAI,MACR,CAAC,gBAAgB,EAAE,OAAO,yBAAyB,EAAE,kBAAkB,KACrE,KACD,EAAE;CAIP,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,CAAC,wCAAwC,EAAE,MAAM,uEAAuE,CAAC;;;;AAO7H,QAAQ,UAA8B;AACvC;AAGD,SAAS,4BACPC,iBACAC,QACA;CACA,MAAM,MAAM,EAAE,GAAG,gBAAiB;CAElC,OAAO,iBAAiB,KAAK;EAC3B,QAAQ;GACN,OAAO;GACP,YAAY;EACb;EACD,WAAW;GACT,OAAO;GACP,YAAY;EACb;CACF,EAAC;AAEF,QAAO;AACR;AAED,SAAgB,yBACdC,WACAC,MACAC,OACA;AACA,qDAAkB,UAAU,CAC1B,kDAAyB,WAAW,MAAM,MAAM;AAElD,qDAAkB,UAAU,CAC1B,QAAO,4BACL;EACE,MAAM;EACN,aAAa;GACX,GAAG;GACH;GACA,QAAQ;GACR,6DAAqB,WAAW;IAC9B,QAAQ;IACR,QAAQ;IACR,SAAS,KAAK;KACZ,IAAI,WAAW,QAAQ;IAGxB;GAOF,EAAC;EACH;CACF,GACD,CAAC,mCAAoB,WAAW,KAAK,MAAM,QAAQ,CAAC,CACrD;AAEH,OAAM,IAAI,MAAM;AACjB;;;;;;;;AASD,SAAgB,uBACdC,SACAC,UACyB;;;;;AAKzB,KACE,YACA,OAAO,aAAa,YACpB,YAAY,YACZ,MAAM,QAAQ,SAAS,OAAO,EAC9B;EACA,MAAM,SAAS,SAAS,OACrB,OAAO,CAAC,UAAU,OAAO,OAAO,WAAW,QAAQ,SAAS,CAC5D,IACC,CAAC,WACE;GACC,MAAM;GACN,KAAK,MAAM,UAAU;EACtB,GACJ;AACH,SAAO,CAAC;GAAE,MAAM;GAAQ,MAAM;EAAS,GAAE,GAAG,MAAO;CACpD;AAED,QAAO;AACR"}
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,oDAAkB,UAAU,CAC1B,kDAAyB,WAAW,MAAM,MAAM;AAElD,oDAAkB,UAAU,CAC1B,QAAO,4BACL;EACE,MAAM;EACN,aAAa;GACX,GAAG;GACH;GACA,QAAQ;GACR,4DAAqB,WAAW;IAC9B,QAAQ;IACR,QAAQ;IACR,SAAS,KAAK;AACZ,SAAI,WAAW,QAAQ;;IAU1B,CAAC;GACH;EACF,GACA,mCAAoB,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 +1 @@
1
- {"version":3,"file":"output.js","names":["model: string","method: unknown","response_format: ResponseFormatJSONSchema","parser: (content: string) => ParsedT","zodSchema: InteropZodType","name: string","props: Omit<ResponseFormatJSONSchema.JSONSchema, \"schema\" | \"strict\" | \"name\">","parseV4","content: string","messages: unknown"],"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;AACD;;;;;;;;;;AAYD,SAAgB,0BACdA,OACAC,QACiB;;;;AAIjB,KACE,OAAO,WAAW,eAClB,CAAC,kBAAkB,SAAS,OAA0B,CAEtD,OAAM,IAAI,MACR,CAAC,gBAAgB,EAAE,OAAO,yBAAyB,EAAE,kBAAkB,KACrE,KACD,EAAE;CAIP,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,CAAC,wCAAwC,EAAE,MAAM,uEAAuE,CAAC;;;;AAO7H,QAAQ,UAA8B;AACvC;AAGD,SAAS,4BACPC,iBACAC,QACA;CACA,MAAM,MAAM,EAAE,GAAG,gBAAiB;CAElC,OAAO,iBAAiB,KAAK;EAC3B,QAAQ;GACN,OAAO;GACP,YAAY;EACb;EACD,WAAW;GACT,OAAO;GACP,YAAY;EACb;CACF,EAAC;AAEF,QAAO;AACR;AAED,SAAgB,yBACdC,WACAC,MACAC,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;KACZ,IAAI,WAAW,QAAQ;IAGxB;GAOF,EAAC;EACH;CACF,GACD,CAAC,YAAYC,MAAQ,WAAW,KAAK,MAAM,QAAQ,CAAC,CACrD;AAEH,OAAM,IAAI,MAAM;AACjB;;;;;;;;AASD,SAAgB,uBACdC,SACAC,UACyB;;;;;AAKzB,KACE,YACA,OAAO,aAAa,YACpB,YAAY,YACZ,MAAM,QAAQ,SAAS,OAAO,EAC9B;EACA,MAAM,SAAS,SAAS,OACrB,OAAO,CAAC,UAAU,OAAO,OAAO,WAAW,QAAQ,SAAS,CAC5D,IACC,CAAC,WACE;GACC,MAAM;GACN,KAAK,MAAM,UAAU;EACtB,GACJ;AACH,SAAO,CAAC;GAAE,MAAM;GAAQ,MAAM;EAAS,GAAE,GAAG,MAAO;CACpD;AAED,QAAO;AACR"}
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"}
@@ -33,8 +33,7 @@ const require_completions = require('../converters/completions.cjs');
33
33
  * @returns A partial OpenAI payload.
34
34
  */
35
35
  function convertPromptToOpenAI(formattedPrompt) {
36
- const messages = formattedPrompt.toChatMessages();
37
- return { messages: require_completions.convertMessagesToCompletionsMessageParams({ messages }) };
36
+ return { messages: require_completions.convertMessagesToCompletionsMessageParams({ messages: formattedPrompt.toChatMessages() }) };
38
37
  }
39
38
 
40
39
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.cjs","names":["formattedPrompt: BasePromptValue","convertMessagesToCompletionsMessageParams"],"sources":["../../src/utils/prompts.ts"],"sourcesContent":["import type { BasePromptValue } from \"@langchain/core/prompt_values\";\nimport type { OpenAI } from \"openai\";\nimport { convertMessagesToCompletionsMessageParams } from \"../converters/completions.js\";\n\n/**\n * Convert a formatted LangChain prompt (e.g. pulled from the hub) into\n * a format expected by OpenAI's JS SDK.\n *\n * Requires the \"@langchain/openai\" package to be installed in addition\n * to the OpenAI SDK.\n *\n * @example\n * ```ts\n * import { convertPromptToOpenAI } from \"langsmith/utils/hub/openai\";\n * import { pull } from \"langchain/hub\";\n *\n * import OpenAI from 'openai';\n *\n * const prompt = await pull(\"jacob/joke-generator\");\n * const formattedPrompt = await prompt.invoke({\n * topic: \"cats\",\n * });\n *\n * const { messages } = convertPromptToOpenAI(formattedPrompt);\n *\n * const openAIClient = new OpenAI();\n *\n * const openaiResponse = await openAIClient.chat.completions.create({\n * model: \"gpt-4o-mini\",\n * messages,\n * });\n * ```\n * @param formattedPrompt\n * @returns A partial OpenAI payload.\n */\n// TODO: make this a converter\nexport function convertPromptToOpenAI(formattedPrompt: BasePromptValue): {\n messages: OpenAI.Chat.ChatCompletionMessageParam[];\n} {\n const messages = formattedPrompt.toChatMessages();\n return {\n messages: convertMessagesToCompletionsMessageParams({\n messages,\n }) as OpenAI.Chat.ChatCompletionMessageParam[],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,sBAAsBA,iBAEpC;CACA,MAAM,WAAW,gBAAgB,gBAAgB;AACjD,QAAO,EACL,UAAUC,8DAA0C,EAClD,SACD,EAAC,CACH;AACF"}
1
+ {"version":3,"file":"prompts.cjs","names":["convertMessagesToCompletionsMessageParams"],"sources":["../../src/utils/prompts.ts"],"sourcesContent":["import type { BasePromptValue } from \"@langchain/core/prompt_values\";\nimport type { OpenAI } from \"openai\";\nimport { convertMessagesToCompletionsMessageParams } from \"../converters/completions.js\";\n\n/**\n * Convert a formatted LangChain prompt (e.g. pulled from the hub) into\n * a format expected by OpenAI's JS SDK.\n *\n * Requires the \"@langchain/openai\" package to be installed in addition\n * to the OpenAI SDK.\n *\n * @example\n * ```ts\n * import { convertPromptToOpenAI } from \"langsmith/utils/hub/openai\";\n * import { pull } from \"langchain/hub\";\n *\n * import OpenAI from 'openai';\n *\n * const prompt = await pull(\"jacob/joke-generator\");\n * const formattedPrompt = await prompt.invoke({\n * topic: \"cats\",\n * });\n *\n * const { messages } = convertPromptToOpenAI(formattedPrompt);\n *\n * const openAIClient = new OpenAI();\n *\n * const openaiResponse = await openAIClient.chat.completions.create({\n * model: \"gpt-4o-mini\",\n * messages,\n * });\n * ```\n * @param formattedPrompt\n * @returns A partial OpenAI payload.\n */\n// TODO: make this a converter\nexport function convertPromptToOpenAI(formattedPrompt: BasePromptValue): {\n messages: OpenAI.Chat.ChatCompletionMessageParam[];\n} {\n const messages = formattedPrompt.toChatMessages();\n return {\n messages: convertMessagesToCompletionsMessageParams({\n messages,\n }) as OpenAI.Chat.ChatCompletionMessageParam[],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,sBAAsB,iBAEpC;AAEA,QAAO,EACL,UAAUA,8DAA0C,EAClD,UAHa,gBAAgB,gBAAgB,EAI9C,CAAC,EACH"}
@@ -2,7 +2,6 @@ import { OpenAI as OpenAI$1 } from "openai";
2
2
  import { BasePromptValue } from "@langchain/core/prompt_values";
3
3
 
4
4
  //#region src/utils/prompts.d.ts
5
-
6
5
  /**
7
6
  * Convert a formatted LangChain prompt (e.g. pulled from the hub) into
8
7
  * a format expected by OpenAI's JS SDK.
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.d.cts","names":["BasePromptValue","OpenAI","convertPromptToOpenAI","Chat","ChatCompletionMessageParam"],"sources":["../../src/utils/prompts.d.ts"],"sourcesContent":["import type { BasePromptValue } from \"@langchain/core/prompt_values\";\nimport type { OpenAI } from \"openai\";\n/**\n * Convert a formatted LangChain prompt (e.g. pulled from the hub) into\n * a format expected by OpenAI's JS SDK.\n *\n * Requires the \"@langchain/openai\" package to be installed in addition\n * to the OpenAI SDK.\n *\n * @example\n * ```ts\n * import { convertPromptToOpenAI } from \"langsmith/utils/hub/openai\";\n * import { pull } from \"langchain/hub\";\n *\n * import OpenAI from 'openai';\n *\n * const prompt = await pull(\"jacob/joke-generator\");\n * const formattedPrompt = await prompt.invoke({\n * topic: \"cats\",\n * });\n *\n * const { messages } = convertPromptToOpenAI(formattedPrompt);\n *\n * const openAIClient = new OpenAI();\n *\n * const openaiResponse = await openAIClient.chat.completions.create({\n * model: \"gpt-4o-mini\",\n * messages,\n * });\n * ```\n * @param formattedPrompt\n * @returns A partial OpenAI payload.\n */\nexport declare function convertPromptToOpenAI(formattedPrompt: BasePromptValue): {\n messages: OpenAI.Chat.ChatCompletionMessageParam[];\n};\n//# sourceMappingURL=prompts.d.ts.map"],"mappings":";;;;;;;AAiCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAwBE,qBAAAA,kBAAuCF;YACjDC,QAAAA,CAAOE,IAAAA,CAAKC"}
1
+ {"version":3,"file":"prompts.d.cts","names":[],"sources":["../../src/utils/prompts.ts"],"mappings":";;;;;;AAoCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,qBAAA,CAAsB,eAAA,EAAiB,eAAA;EACrD,QAAA,EAAU,QAAA,CAAO,IAAA,CAAK,0BAAA;AAAA"}
@@ -2,7 +2,6 @@ import { OpenAI as OpenAI$1 } from "openai";
2
2
  import { BasePromptValue } from "@langchain/core/prompt_values";
3
3
 
4
4
  //#region src/utils/prompts.d.ts
5
-
6
5
  /**
7
6
  * Convert a formatted LangChain prompt (e.g. pulled from the hub) into
8
7
  * a format expected by OpenAI's JS SDK.
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.d.ts","names":["BasePromptValue","OpenAI","convertPromptToOpenAI","Chat","ChatCompletionMessageParam"],"sources":["../../src/utils/prompts.d.ts"],"sourcesContent":["import type { BasePromptValue } from \"@langchain/core/prompt_values\";\nimport type { OpenAI } from \"openai\";\n/**\n * Convert a formatted LangChain prompt (e.g. pulled from the hub) into\n * a format expected by OpenAI's JS SDK.\n *\n * Requires the \"@langchain/openai\" package to be installed in addition\n * to the OpenAI SDK.\n *\n * @example\n * ```ts\n * import { convertPromptToOpenAI } from \"langsmith/utils/hub/openai\";\n * import { pull } from \"langchain/hub\";\n *\n * import OpenAI from 'openai';\n *\n * const prompt = await pull(\"jacob/joke-generator\");\n * const formattedPrompt = await prompt.invoke({\n * topic: \"cats\",\n * });\n *\n * const { messages } = convertPromptToOpenAI(formattedPrompt);\n *\n * const openAIClient = new OpenAI();\n *\n * const openaiResponse = await openAIClient.chat.completions.create({\n * model: \"gpt-4o-mini\",\n * messages,\n * });\n * ```\n * @param formattedPrompt\n * @returns A partial OpenAI payload.\n */\nexport declare function convertPromptToOpenAI(formattedPrompt: BasePromptValue): {\n messages: OpenAI.Chat.ChatCompletionMessageParam[];\n};\n//# sourceMappingURL=prompts.d.ts.map"],"mappings":";;;;;;;AAiCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAwBE,qBAAAA,kBAAuCF;YACjDC,QAAAA,CAAOE,IAAAA,CAAKC"}
1
+ {"version":3,"file":"prompts.d.ts","names":[],"sources":["../../src/utils/prompts.ts"],"mappings":";;;;;;AAoCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,qBAAA,CAAsB,eAAA,EAAiB,eAAA;EACrD,QAAA,EAAU,QAAA,CAAO,IAAA,CAAK,0BAAA;AAAA"}
@@ -33,8 +33,7 @@ import { convertMessagesToCompletionsMessageParams } from "../converters/complet
33
33
  * @returns A partial OpenAI payload.
34
34
  */
35
35
  function convertPromptToOpenAI(formattedPrompt) {
36
- const messages = formattedPrompt.toChatMessages();
37
- return { messages: convertMessagesToCompletionsMessageParams({ messages }) };
36
+ return { messages: convertMessagesToCompletionsMessageParams({ messages: formattedPrompt.toChatMessages() }) };
38
37
  }
39
38
 
40
39
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.js","names":["formattedPrompt: BasePromptValue"],"sources":["../../src/utils/prompts.ts"],"sourcesContent":["import type { BasePromptValue } from \"@langchain/core/prompt_values\";\nimport type { OpenAI } from \"openai\";\nimport { convertMessagesToCompletionsMessageParams } from \"../converters/completions.js\";\n\n/**\n * Convert a formatted LangChain prompt (e.g. pulled from the hub) into\n * a format expected by OpenAI's JS SDK.\n *\n * Requires the \"@langchain/openai\" package to be installed in addition\n * to the OpenAI SDK.\n *\n * @example\n * ```ts\n * import { convertPromptToOpenAI } from \"langsmith/utils/hub/openai\";\n * import { pull } from \"langchain/hub\";\n *\n * import OpenAI from 'openai';\n *\n * const prompt = await pull(\"jacob/joke-generator\");\n * const formattedPrompt = await prompt.invoke({\n * topic: \"cats\",\n * });\n *\n * const { messages } = convertPromptToOpenAI(formattedPrompt);\n *\n * const openAIClient = new OpenAI();\n *\n * const openaiResponse = await openAIClient.chat.completions.create({\n * model: \"gpt-4o-mini\",\n * messages,\n * });\n * ```\n * @param formattedPrompt\n * @returns A partial OpenAI payload.\n */\n// TODO: make this a converter\nexport function convertPromptToOpenAI(formattedPrompt: BasePromptValue): {\n messages: OpenAI.Chat.ChatCompletionMessageParam[];\n} {\n const messages = formattedPrompt.toChatMessages();\n return {\n messages: convertMessagesToCompletionsMessageParams({\n messages,\n }) as OpenAI.Chat.ChatCompletionMessageParam[],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,sBAAsBA,iBAEpC;CACA,MAAM,WAAW,gBAAgB,gBAAgB;AACjD,QAAO,EACL,UAAU,0CAA0C,EAClD,SACD,EAAC,CACH;AACF"}
1
+ {"version":3,"file":"prompts.js","names":[],"sources":["../../src/utils/prompts.ts"],"sourcesContent":["import type { BasePromptValue } from \"@langchain/core/prompt_values\";\nimport type { OpenAI } from \"openai\";\nimport { convertMessagesToCompletionsMessageParams } from \"../converters/completions.js\";\n\n/**\n * Convert a formatted LangChain prompt (e.g. pulled from the hub) into\n * a format expected by OpenAI's JS SDK.\n *\n * Requires the \"@langchain/openai\" package to be installed in addition\n * to the OpenAI SDK.\n *\n * @example\n * ```ts\n * import { convertPromptToOpenAI } from \"langsmith/utils/hub/openai\";\n * import { pull } from \"langchain/hub\";\n *\n * import OpenAI from 'openai';\n *\n * const prompt = await pull(\"jacob/joke-generator\");\n * const formattedPrompt = await prompt.invoke({\n * topic: \"cats\",\n * });\n *\n * const { messages } = convertPromptToOpenAI(formattedPrompt);\n *\n * const openAIClient = new OpenAI();\n *\n * const openaiResponse = await openAIClient.chat.completions.create({\n * model: \"gpt-4o-mini\",\n * messages,\n * });\n * ```\n * @param formattedPrompt\n * @returns A partial OpenAI payload.\n */\n// TODO: make this a converter\nexport function convertPromptToOpenAI(formattedPrompt: BasePromptValue): {\n messages: OpenAI.Chat.ChatCompletionMessageParam[];\n} {\n const messages = formattedPrompt.toChatMessages();\n return {\n messages: convertMessagesToCompletionsMessageParams({\n messages,\n }) as OpenAI.Chat.ChatCompletionMessageParam[],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,sBAAsB,iBAEpC;AAEA,QAAO,EACL,UAAU,0CAA0C,EAClD,UAHa,gBAAgB,gBAAgB,EAI9C,CAAC,EACH"}
@@ -1,7 +1,6 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- const __langchain_core_utils_function_calling = require_rolldown_runtime.__toESM(require("@langchain/core/utils/function_calling"));
3
- const __langchain_core_utils_types = require_rolldown_runtime.__toESM(require("@langchain/core/utils/types"));
4
- const __langchain_core_utils_json_schema = require_rolldown_runtime.__toESM(require("@langchain/core/utils/json_schema"));
1
+ let _langchain_core_utils_function_calling = require("@langchain/core/utils/function_calling");
2
+ let _langchain_core_utils_types = require("@langchain/core/utils/types");
3
+ let _langchain_core_utils_json_schema = require("@langchain/core/utils/json_schema");
5
4
 
6
5
  //#region src/utils/tools.ts
7
6
  /**
@@ -17,7 +16,7 @@ const __langchain_core_utils_json_schema = require_rolldown_runtime.__toESM(requ
17
16
  */
18
17
  function _convertToOpenAITool(tool, fields) {
19
18
  let toolDef;
20
- if ((0, __langchain_core_utils_function_calling.isLangChainTool)(tool)) toolDef = (0, __langchain_core_utils_function_calling.convertToOpenAITool)(tool);
19
+ if ((0, _langchain_core_utils_function_calling.isLangChainTool)(tool)) toolDef = (0, _langchain_core_utils_function_calling.convertToOpenAITool)(tool);
21
20
  else toolDef = tool;
22
21
  if (fields?.strict !== void 0) toolDef.function.strict = fields.strict;
23
22
  return toolDef;
@@ -74,7 +73,7 @@ function formatType(param, indent) {
74
73
  }
75
74
  }
76
75
  function formatToOpenAIToolChoice(toolChoice) {
77
- if (!toolChoice) return void 0;
76
+ if (!toolChoice) return;
78
77
  else if (toolChoice === "any" || toolChoice === "required") return "required";
79
78
  else if (toolChoice === "auto") return "auto";
80
79
  else if (toolChoice === "none") return "none";
@@ -105,7 +104,7 @@ function isOpenAICustomTool(tool) {
105
104
  return "type" in tool && tool.type === "custom" && "custom" in tool && typeof tool.custom === "object" && tool.custom !== null;
106
105
  }
107
106
  function parseCustomToolCall(rawToolCall) {
108
- if (rawToolCall.type !== "custom_tool_call") return void 0;
107
+ if (rawToolCall.type !== "custom_tool_call") return;
109
108
  return {
110
109
  ...rawToolCall,
111
110
  type: "tool_call",
@@ -124,7 +123,7 @@ function parseCustomToolCall(rawToolCall) {
124
123
  * @returns A ComputerToolCall object if valid, undefined otherwise
125
124
  */
126
125
  function parseComputerCall(rawToolCall) {
127
- if (rawToolCall.type !== "computer_call") return void 0;
126
+ if (rawToolCall.type !== "computer_call") return;
128
127
  return {
129
128
  ...rawToolCall,
130
129
  type: "tool_call",
@@ -148,14 +147,13 @@ function isCustomToolCall(toolCall) {
148
147
  }
149
148
  function convertCompletionsCustomTool(tool) {
150
149
  const getFormat = () => {
151
- if (!tool.custom.format) return void 0;
150
+ if (!tool.custom.format) return;
152
151
  if (tool.custom.format.type === "grammar") return {
153
152
  type: "grammar",
154
153
  definition: tool.custom.format.grammar.definition,
155
154
  syntax: tool.custom.format.grammar.syntax
156
155
  };
157
156
  if (tool.custom.format.type === "text") return { type: "text" };
158
- return void 0;
159
157
  };
160
158
  return {
161
159
  type: "custom",
@@ -166,7 +164,7 @@ function convertCompletionsCustomTool(tool) {
166
164
  }
167
165
  function convertResponsesCustomTool(tool) {
168
166
  const getFormat = () => {
169
- if (!tool.format) return void 0;
167
+ if (!tool.format) return;
170
168
  if (tool.format.type === "grammar") return {
171
169
  type: "grammar",
172
170
  grammar: {
@@ -175,7 +173,6 @@ function convertResponsesCustomTool(tool) {
175
173
  }
176
174
  };
177
175
  if (tool.format.type === "text") return { type: "text" };
178
- return void 0;
179
176
  };
180
177
  return {
181
178
  type: "custom",