@langchain/openai 0.6.9 → 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +8 -8
  2. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  3. package/dist/azure/chat_models.cjs +661 -808
  4. package/dist/azure/chat_models.cjs.map +1 -0
  5. package/dist/azure/chat_models.d.cts +449 -0
  6. package/dist/azure/chat_models.d.cts.map +1 -0
  7. package/dist/azure/chat_models.d.ts +32 -28
  8. package/dist/azure/chat_models.d.ts.map +1 -0
  9. package/dist/azure/chat_models.js +660 -804
  10. package/dist/azure/chat_models.js.map +1 -0
  11. package/dist/azure/embeddings.cjs +81 -130
  12. package/dist/azure/embeddings.cjs.map +1 -0
  13. package/dist/azure/embeddings.d.cts +27 -0
  14. package/dist/azure/embeddings.d.cts.map +1 -0
  15. package/dist/azure/embeddings.d.ts +25 -20
  16. package/dist/azure/embeddings.d.ts.map +1 -0
  17. package/dist/azure/embeddings.js +80 -126
  18. package/dist/azure/embeddings.js.map +1 -0
  19. package/dist/azure/llms.cjs +109 -168
  20. package/dist/azure/llms.cjs.map +1 -0
  21. package/dist/azure/llms.d.cts +33 -0
  22. package/dist/azure/llms.d.cts.map +1 -0
  23. package/dist/azure/llms.d.ts +31 -25
  24. package/dist/azure/llms.d.ts.map +1 -0
  25. package/dist/azure/llms.js +108 -164
  26. package/dist/azure/llms.js.map +1 -0
  27. package/dist/chat_models.cjs +1951 -2774
  28. package/dist/chat_models.cjs.map +1 -0
  29. package/dist/chat_models.d.cts +930 -0
  30. package/dist/chat_models.d.cts.map +1 -0
  31. package/dist/chat_models.d.ts +365 -348
  32. package/dist/chat_models.d.ts.map +1 -0
  33. package/dist/chat_models.js +1946 -2764
  34. package/dist/chat_models.js.map +1 -0
  35. package/dist/embeddings.cjs +136 -193
  36. package/dist/embeddings.cjs.map +1 -0
  37. package/dist/embeddings.d.cts +115 -0
  38. package/dist/embeddings.d.cts.map +1 -0
  39. package/dist/embeddings.d.ts +88 -81
  40. package/dist/embeddings.d.ts.map +1 -0
  41. package/dist/embeddings.js +134 -188
  42. package/dist/embeddings.js.map +1 -0
  43. package/dist/index.cjs +47 -34
  44. package/dist/index.d.cts +16 -0
  45. package/dist/index.d.ts +16 -13
  46. package/dist/index.js +17 -13
  47. package/dist/langchain-core/dist/types/_internal.d.cts +11 -0
  48. package/dist/langchain-core/dist/types/_internal.d.cts.map +1 -0
  49. package/dist/langchain-core/dist/types/_internal.d.ts +11 -0
  50. package/dist/langchain-core/dist/types/_internal.d.ts.map +1 -0
  51. package/dist/langchain-core/dist/utils/stream.d.cts +26 -0
  52. package/dist/langchain-core/dist/utils/stream.d.cts.map +1 -0
  53. package/dist/langchain-core/dist/utils/stream.d.ts +26 -0
  54. package/dist/langchain-core/dist/utils/stream.d.ts.map +1 -0
  55. package/dist/llms.cjs +312 -468
  56. package/dist/llms.cjs.map +1 -0
  57. package/dist/llms.d.cts +123 -0
  58. package/dist/llms.d.cts.map +1 -0
  59. package/dist/llms.d.ts +93 -87
  60. package/dist/llms.d.ts.map +1 -0
  61. package/dist/llms.js +309 -462
  62. package/dist/llms.js.map +1 -0
  63. package/dist/tools/custom.cjs +25 -26
  64. package/dist/tools/custom.cjs.map +1 -0
  65. package/dist/tools/custom.d.cts +10 -0
  66. package/dist/tools/custom.d.cts.map +1 -0
  67. package/dist/tools/custom.d.ts +8 -3
  68. package/dist/tools/custom.d.ts.map +1 -0
  69. package/dist/tools/custom.js +24 -23
  70. package/dist/tools/custom.js.map +1 -0
  71. package/dist/tools/dalle.cjs +104 -194
  72. package/dist/tools/dalle.cjs.map +1 -0
  73. package/dist/tools/dalle.d.cts +123 -0
  74. package/dist/tools/dalle.d.cts.map +1 -0
  75. package/dist/tools/dalle.d.ts +111 -104
  76. package/dist/tools/dalle.d.ts.map +1 -0
  77. package/dist/tools/dalle.js +102 -189
  78. package/dist/tools/dalle.js.map +1 -0
  79. package/dist/tools/index.cjs +1 -17
  80. package/dist/tools/index.js +1 -1
  81. package/dist/types.d.cts +263 -0
  82. package/dist/types.d.cts.map +1 -0
  83. package/dist/types.d.ts +244 -237
  84. package/dist/types.d.ts.map +1 -0
  85. package/dist/utils/azure.cjs +86 -47
  86. package/dist/utils/azure.cjs.map +1 -0
  87. package/dist/utils/azure.d.cts +76 -0
  88. package/dist/utils/azure.d.cts.map +1 -0
  89. package/dist/utils/azure.d.ts +51 -9
  90. package/dist/utils/azure.d.ts.map +1 -0
  91. package/dist/utils/azure.js +85 -45
  92. package/dist/utils/azure.js.map +1 -0
  93. package/dist/utils/client.cjs +25 -0
  94. package/dist/utils/client.cjs.map +1 -0
  95. package/dist/utils/client.d.cts +5 -0
  96. package/dist/utils/client.d.cts.map +1 -0
  97. package/dist/utils/client.d.ts +5 -0
  98. package/dist/utils/client.d.ts.map +1 -0
  99. package/dist/utils/client.js +24 -0
  100. package/dist/utils/client.js.map +1 -0
  101. package/dist/utils/errors.cjs +9 -8
  102. package/dist/utils/errors.cjs.map +1 -0
  103. package/dist/utils/errors.js +9 -6
  104. package/dist/utils/errors.js.map +1 -0
  105. package/dist/utils/message_inputs.cjs +139 -0
  106. package/dist/utils/message_inputs.cjs.map +1 -0
  107. package/dist/utils/message_inputs.d.cts +9 -0
  108. package/dist/utils/message_inputs.d.cts.map +1 -0
  109. package/dist/utils/message_inputs.d.ts +9 -0
  110. package/dist/utils/message_inputs.d.ts.map +1 -0
  111. package/dist/utils/message_inputs.js +137 -0
  112. package/dist/utils/message_inputs.js.map +1 -0
  113. package/dist/utils/misc.cjs +30 -0
  114. package/dist/utils/misc.cjs.map +1 -0
  115. package/dist/utils/misc.d.cts +9 -0
  116. package/dist/utils/misc.d.cts.map +1 -0
  117. package/dist/utils/misc.d.ts +9 -0
  118. package/dist/utils/misc.d.ts.map +1 -0
  119. package/dist/utils/misc.js +27 -0
  120. package/dist/utils/misc.js.map +1 -0
  121. package/dist/utils/output.cjs +74 -0
  122. package/dist/utils/output.cjs.map +1 -0
  123. package/dist/utils/output.js +72 -0
  124. package/dist/utils/output.js.map +1 -0
  125. package/dist/utils/prompts.cjs +39 -38
  126. package/dist/utils/prompts.cjs.map +1 -0
  127. package/dist/utils/prompts.d.cts +42 -0
  128. package/dist/utils/prompts.d.cts.map +1 -0
  129. package/dist/utils/prompts.d.ts +10 -4
  130. package/dist/utils/prompts.d.ts.map +1 -0
  131. package/dist/utils/prompts.js +40 -36
  132. package/dist/utils/prompts.js.map +1 -0
  133. package/dist/utils/standard.cjs +113 -0
  134. package/dist/utils/standard.cjs.map +1 -0
  135. package/dist/utils/standard.js +111 -0
  136. package/dist/utils/standard.js.map +1 -0
  137. package/dist/utils/tools.cjs +150 -127
  138. package/dist/utils/tools.cjs.map +1 -0
  139. package/dist/utils/tools.d.cts +13 -0
  140. package/dist/utils/tools.d.cts.map +1 -0
  141. package/dist/utils/tools.d.ts +12 -42
  142. package/dist/utils/tools.d.ts.map +1 -0
  143. package/dist/utils/tools.js +146 -123
  144. package/dist/utils/tools.js.map +1 -0
  145. package/package.json +32 -40
  146. package/dist/tools/index.d.ts +0 -1
  147. package/dist/types.cjs +0 -2
  148. package/dist/types.js +0 -1
  149. package/dist/utils/errors.d.ts +0 -2
  150. package/dist/utils/headers.cjs +0 -39
  151. package/dist/utils/headers.d.ts +0 -8
  152. package/dist/utils/headers.js +0 -35
  153. package/dist/utils/openai-format-fndef.cjs +0 -80
  154. package/dist/utils/openai-format-fndef.d.ts +0 -44
  155. package/dist/utils/openai-format-fndef.js +0 -77
  156. package/dist/utils/openai.cjs +0 -127
  157. package/dist/utils/openai.d.ts +0 -15
  158. package/dist/utils/openai.js +0 -119
  159. package/index.cjs +0 -1
  160. package/index.d.cts +0 -1
  161. package/index.d.ts +0 -1
  162. package/index.js +0 -1
@@ -1,50 +1,89 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEndpoint = getEndpoint;
1
+ const require_misc = require('./misc.cjs');
2
+
3
+ //#region src/utils/azure.ts
4
4
  /**
5
- * This function generates an endpoint URL for (Azure) OpenAI
6
- * based on the configuration parameters provided.
7
- *
8
- * @param {OpenAIEndpointConfig} config - The configuration object for the (Azure) endpoint.
9
- *
10
- * @property {string} config.azureOpenAIApiDeploymentName - The deployment name of Azure OpenAI.
11
- * @property {string} config.azureOpenAIApiInstanceName - The instance name of Azure OpenAI, e.g. `example-resource`.
12
- * @property {string} config.azureOpenAIApiKey - The API Key for Azure OpenAI.
13
- * @property {string} config.azureOpenAIBasePath - The base path for Azure OpenAI, e.g. `https://example-resource.azure.openai.com/openai/deployments/`.
14
- * @property {string} config.baseURL - Some other custom base path URL.
15
- * @property {string} config.azureOpenAIEndpoint - The endpoint for the Azure OpenAI instance, e.g. `https://example-resource.azure.openai.com/`.
16
- *
17
- * The function operates as follows:
18
- * - If both `azureOpenAIBasePath` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`).
19
- * - If both `azureOpenAIEndpoint` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`).
20
- * - 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.
21
- * - If none of the above conditions are met, return any custom `baseURL`.
22
- * - The function returns the generated URL as a string, or undefined if no custom paths are specified.
23
- *
24
- * @throws Will throw an error if the necessary parameters for generating the URL are missing.
25
- *
26
- * @returns {string | undefined} The generated (Azure) OpenAI endpoint URL.
27
- */
5
+ * This function generates an endpoint URL for (Azure) OpenAI
6
+ * based on the configuration parameters provided.
7
+ *
8
+ * @param {OpenAIEndpointConfig} config - The configuration object for the (Azure) endpoint.
9
+ *
10
+ * @property {string} config.azureOpenAIApiDeploymentName - The deployment name of Azure OpenAI.
11
+ * @property {string} config.azureOpenAIApiInstanceName - The instance name of Azure OpenAI, e.g. `example-resource`.
12
+ * @property {string} config.azureOpenAIApiKey - The API Key for Azure OpenAI.
13
+ * @property {string} config.azureOpenAIBasePath - The base path for Azure OpenAI, e.g. `https://example-resource.azure.openai.com/openai/deployments/`.
14
+ * @property {string} config.baseURL - Some other custom base path URL.
15
+ * @property {string} config.azureOpenAIEndpoint - The endpoint for the Azure OpenAI instance, e.g. `https://example-resource.azure.openai.com/`.
16
+ *
17
+ * The function operates as follows:
18
+ * - If both `azureOpenAIBasePath` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`).
19
+ * - If both `azureOpenAIEndpoint` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`).
20
+ * - 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.
21
+ * - If none of the above conditions are met, return any custom `baseURL`.
22
+ * - The function returns the generated URL as a string, or undefined if no custom paths are specified.
23
+ *
24
+ * @throws Will throw an error if the necessary parameters for generating the URL are missing.
25
+ *
26
+ * @returns {string | undefined} The generated (Azure) OpenAI endpoint URL.
27
+ */
28
28
  function getEndpoint(config) {
29
- const { azureOpenAIApiDeploymentName, azureOpenAIApiInstanceName, azureOpenAIApiKey, azureOpenAIBasePath, baseURL, azureADTokenProvider, azureOpenAIEndpoint, } = config;
30
- if ((azureOpenAIApiKey || azureADTokenProvider) &&
31
- azureOpenAIBasePath &&
32
- azureOpenAIApiDeploymentName) {
33
- return `${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`;
34
- }
35
- if ((azureOpenAIApiKey || azureADTokenProvider) &&
36
- azureOpenAIEndpoint &&
37
- azureOpenAIApiDeploymentName) {
38
- return `${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`;
39
- }
40
- if (azureOpenAIApiKey || azureADTokenProvider) {
41
- if (!azureOpenAIApiInstanceName) {
42
- throw new Error("azureOpenAIApiInstanceName is required when using azureOpenAIApiKey");
43
- }
44
- if (!azureOpenAIApiDeploymentName) {
45
- throw new Error("azureOpenAIApiDeploymentName is a required parameter when using azureOpenAIApiKey");
46
- }
47
- return `https://${azureOpenAIApiInstanceName}.openai.azure.com/openai/deployments/${azureOpenAIApiDeploymentName}`;
48
- }
49
- return baseURL;
29
+ const { azureOpenAIApiDeploymentName, azureOpenAIApiInstanceName, azureOpenAIApiKey, azureOpenAIBasePath, baseURL, azureADTokenProvider, azureOpenAIEndpoint } = config;
30
+ if ((azureOpenAIApiKey || azureADTokenProvider) && azureOpenAIBasePath && azureOpenAIApiDeploymentName) return `${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`;
31
+ if ((azureOpenAIApiKey || azureADTokenProvider) && azureOpenAIEndpoint && azureOpenAIApiDeploymentName) return `${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`;
32
+ if (azureOpenAIApiKey || azureADTokenProvider) {
33
+ if (!azureOpenAIApiInstanceName) throw new Error("azureOpenAIApiInstanceName is required when using azureOpenAIApiKey");
34
+ if (!azureOpenAIApiDeploymentName) throw new Error("azureOpenAIApiDeploymentName is a required parameter when using azureOpenAIApiKey");
35
+ return `https://${azureOpenAIApiInstanceName}.openai.azure.com/openai/deployments/${azureOpenAIApiDeploymentName}`;
36
+ }
37
+ return baseURL;
38
+ }
39
+ function isHeaders(headers) {
40
+ return typeof Headers !== "undefined" && headers !== null && typeof headers === "object" && Object.prototype.toString.call(headers) === "[object Headers]";
50
41
  }
42
+ /**
43
+ * Normalizes various header formats into a consistent Record format.
44
+ *
45
+ * This function accepts headers in multiple formats and converts them to a
46
+ * Record<string, HeaderValue | readonly HeaderValue[]> for consistent handling.
47
+ *
48
+ * @param headers - The headers to normalize. Can be:
49
+ * - A Headers instance
50
+ * - An array of [key, value] pairs
51
+ * - A plain object with string keys
52
+ * - A NullableHeaders-like object with a 'values' property containing Headers
53
+ * - null or undefined
54
+ * @returns A normalized Record containing the header key-value pairs
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * // With Headers instance
59
+ * const headers1 = new Headers([['content-type', 'application/json']]);
60
+ * const normalized1 = normalizeHeaders(headers1);
61
+ *
62
+ * // With plain object
63
+ * const headers2 = { 'content-type': 'application/json' };
64
+ * const normalized2 = normalizeHeaders(headers2);
65
+ *
66
+ * // With array of pairs
67
+ * const headers3 = [['content-type', 'application/json']];
68
+ * const normalized3 = normalizeHeaders(headers3);
69
+ * ```
70
+ */
71
+ function normalizeHeaders(headers) {
72
+ const output = require_misc.iife(() => {
73
+ if (isHeaders(headers)) return headers;
74
+ else if (Array.isArray(headers)) return new Headers(headers);
75
+ else if (typeof headers === "object" && headers !== null && "values" in headers && isHeaders(headers.values)) return headers.values;
76
+ else if (typeof headers === "object" && headers !== null) {
77
+ const entries = Object.entries(headers).filter(([, v]) => typeof v === "string").map(([k, v]) => [k, v]);
78
+ return new Headers(entries);
79
+ }
80
+ return new Headers();
81
+ });
82
+ return Object.fromEntries(output.entries());
83
+ }
84
+
85
+ //#endregion
86
+ exports.getEndpoint = getEndpoint;
87
+ exports.isHeaders = isHeaders;
88
+ exports.normalizeHeaders = normalizeHeaders;
89
+ //# sourceMappingURL=azure.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"azure.cjs","names":["config: OpenAIEndpointConfig","headers: unknown","headers: HeadersLike","iife","entries: [string, string][]"],"sources":["../../src/utils/azure.ts"],"sourcesContent":["import { 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,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,SAASC,kBAAK,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"}
@@ -0,0 +1,76 @@
1
+ //#region src/utils/azure.d.ts
2
+ interface OpenAIEndpointConfig {
3
+ azureOpenAIApiDeploymentName?: string;
4
+ azureOpenAIApiInstanceName?: string;
5
+ azureOpenAIApiKey?: string;
6
+ azureADTokenProvider?: () => Promise<string>;
7
+ azureOpenAIBasePath?: string;
8
+ baseURL?: string | null;
9
+ azureOpenAIEndpoint?: string;
10
+ }
11
+ /**
12
+ * This function generates an endpoint URL for (Azure) OpenAI
13
+ * based on the configuration parameters provided.
14
+ *
15
+ * @param {OpenAIEndpointConfig} config - The configuration object for the (Azure) endpoint.
16
+ *
17
+ * @property {string} config.azureOpenAIApiDeploymentName - The deployment name of Azure OpenAI.
18
+ * @property {string} config.azureOpenAIApiInstanceName - The instance name of Azure OpenAI, e.g. `example-resource`.
19
+ * @property {string} config.azureOpenAIApiKey - The API Key for Azure OpenAI.
20
+ * @property {string} config.azureOpenAIBasePath - The base path for Azure OpenAI, e.g. `https://example-resource.azure.openai.com/openai/deployments/`.
21
+ * @property {string} config.baseURL - Some other custom base path URL.
22
+ * @property {string} config.azureOpenAIEndpoint - The endpoint for the Azure OpenAI instance, e.g. `https://example-resource.azure.openai.com/`.
23
+ *
24
+ * The function operates as follows:
25
+ * - If both `azureOpenAIBasePath` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`).
26
+ * - If both `azureOpenAIEndpoint` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`).
27
+ * - 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.
28
+ * - If none of the above conditions are met, return any custom `baseURL`.
29
+ * - The function returns the generated URL as a string, or undefined if no custom paths are specified.
30
+ *
31
+ * @throws Will throw an error if the necessary parameters for generating the URL are missing.
32
+ *
33
+ * @returns {string | undefined} The generated (Azure) OpenAI endpoint URL.
34
+ */
35
+ declare function getEndpoint(config: OpenAIEndpointConfig): string | null | undefined;
36
+ type HeaderValue = string | undefined | null;
37
+ type HeadersLike = Headers | readonly HeaderValue[][] | Record<string, HeaderValue | readonly HeaderValue[]> | undefined | null
38
+ // NullableHeaders
39
+ | {
40
+ values: Headers;
41
+ [key: string]: unknown;
42
+ };
43
+ declare function isHeaders(headers: unknown): headers is Headers;
44
+ /**
45
+ * Normalizes various header formats into a consistent Record format.
46
+ *
47
+ * This function accepts headers in multiple formats and converts them to a
48
+ * Record<string, HeaderValue | readonly HeaderValue[]> for consistent handling.
49
+ *
50
+ * @param headers - The headers to normalize. Can be:
51
+ * - A Headers instance
52
+ * - An array of [key, value] pairs
53
+ * - A plain object with string keys
54
+ * - A NullableHeaders-like object with a 'values' property containing Headers
55
+ * - null or undefined
56
+ * @returns A normalized Record containing the header key-value pairs
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * // With Headers instance
61
+ * const headers1 = new Headers([['content-type', 'application/json']]);
62
+ * const normalized1 = normalizeHeaders(headers1);
63
+ *
64
+ * // With plain object
65
+ * const headers2 = { 'content-type': 'application/json' };
66
+ * const normalized2 = normalizeHeaders(headers2);
67
+ *
68
+ * // With array of pairs
69
+ * const headers3 = [['content-type', 'application/json']];
70
+ * const normalized3 = normalizeHeaders(headers3);
71
+ * ```
72
+ */
73
+ declare function normalizeHeaders(headers: HeadersLike): Record<string, HeaderValue | readonly HeaderValue[]>;
74
+ //#endregion
75
+ export { HeadersLike, OpenAIEndpointConfig, getEndpoint, isHeaders, normalizeHeaders };
76
+ //# sourceMappingURL=azure.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"azure.d.cts","names":["OpenAIEndpointConfig","Promise","getEndpoint","HeaderValue","HeadersLike","Headers","Record","isHeaders","normalizeHeaders"],"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// NullableHeaders\n | {\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 {};\n"],"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;EAAA,mBAAA,CAAA,EAAA,MAAA;EAAA,OAAGI,CAAAA,EAAAA,MAAAA,GAAAA,IAAAA;EAAO,mBAAYF,CAAAA,EAAAA,MAAAA;;;;;AAG1B;AAGnB;AA8BA;;;;;;AAAsE;;;;;;;;;;;;;iBAtC9CD,WAAAA,SAAoBF;KACvCG,WAAAA;KACOC,WAAAA,GAAcC,mBAAmBF,kBAAkBG,eAAeH,uBAAuBA;;;UAGzFE;;;iBAGYE,SAAAA,+BAAwCF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8BxCG,gBAAAA,UAA0BJ,cAAcE,eAAeH,uBAAuBA"}
@@ -1,11 +1,12 @@
1
- export interface OpenAIEndpointConfig {
2
- azureOpenAIApiDeploymentName?: string;
3
- azureOpenAIApiInstanceName?: string;
4
- azureOpenAIApiKey?: string;
5
- azureADTokenProvider?: () => Promise<string>;
6
- azureOpenAIBasePath?: string;
7
- baseURL?: string | null;
8
- azureOpenAIEndpoint?: string;
1
+ //#region src/utils/azure.d.ts
2
+ interface OpenAIEndpointConfig {
3
+ azureOpenAIApiDeploymentName?: string;
4
+ azureOpenAIApiInstanceName?: string;
5
+ azureOpenAIApiKey?: string;
6
+ azureADTokenProvider?: () => Promise<string>;
7
+ azureOpenAIBasePath?: string;
8
+ baseURL?: string | null;
9
+ azureOpenAIEndpoint?: string;
9
10
  }
10
11
  /**
11
12
  * This function generates an endpoint URL for (Azure) OpenAI
@@ -31,4 +32,45 @@ export interface OpenAIEndpointConfig {
31
32
  *
32
33
  * @returns {string | undefined} The generated (Azure) OpenAI endpoint URL.
33
34
  */
34
- export declare function getEndpoint(config: OpenAIEndpointConfig): string | null | undefined;
35
+ declare function getEndpoint(config: OpenAIEndpointConfig): string | null | undefined;
36
+ type HeaderValue = string | undefined | null;
37
+ type HeadersLike = Headers | readonly HeaderValue[][] | Record<string, HeaderValue | readonly HeaderValue[]> | undefined | null
38
+ // NullableHeaders
39
+ | {
40
+ values: Headers;
41
+ [key: string]: unknown;
42
+ };
43
+ declare function isHeaders(headers: unknown): headers is Headers;
44
+ /**
45
+ * Normalizes various header formats into a consistent Record format.
46
+ *
47
+ * This function accepts headers in multiple formats and converts them to a
48
+ * Record<string, HeaderValue | readonly HeaderValue[]> for consistent handling.
49
+ *
50
+ * @param headers - The headers to normalize. Can be:
51
+ * - A Headers instance
52
+ * - An array of [key, value] pairs
53
+ * - A plain object with string keys
54
+ * - A NullableHeaders-like object with a 'values' property containing Headers
55
+ * - null or undefined
56
+ * @returns A normalized Record containing the header key-value pairs
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * // With Headers instance
61
+ * const headers1 = new Headers([['content-type', 'application/json']]);
62
+ * const normalized1 = normalizeHeaders(headers1);
63
+ *
64
+ * // With plain object
65
+ * const headers2 = { 'content-type': 'application/json' };
66
+ * const normalized2 = normalizeHeaders(headers2);
67
+ *
68
+ * // With array of pairs
69
+ * const headers3 = [['content-type', 'application/json']];
70
+ * const normalized3 = normalizeHeaders(headers3);
71
+ * ```
72
+ */
73
+ declare function normalizeHeaders(headers: HeadersLike): Record<string, HeaderValue | readonly HeaderValue[]>;
74
+ //#endregion
75
+ export { HeadersLike, OpenAIEndpointConfig, getEndpoint, isHeaders, normalizeHeaders };
76
+ //# sourceMappingURL=azure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"azure.d.ts","names":["OpenAIEndpointConfig","Promise","getEndpoint","HeaderValue","HeadersLike","Headers","Record","isHeaders","normalizeHeaders"],"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// NullableHeaders\n | {\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 {};\n"],"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;EAAA,mBAAA,CAAA,EAAA,MAAA;EAAA,OAAGI,CAAAA,EAAAA,MAAAA,GAAAA,IAAAA;EAAO,mBAAYF,CAAAA,EAAAA,MAAAA;;;;;AAG1B;AAGnB;AA8BA;;;;;;AAAsE;;;;;;;;;;;;;iBAtC9CD,WAAAA,SAAoBF;KACvCG,WAAAA;KACOC,WAAAA,GAAcC,mBAAmBF,kBAAkBG,eAAeH,uBAAuBA;;;UAGzFE;;;iBAGYE,SAAAA,+BAAwCF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8BxCG,gBAAAA,UAA0BJ,cAAcE,eAAeH,uBAAuBA"}
@@ -1,47 +1,87 @@
1
+ import { iife } from "./misc.js";
2
+
3
+ //#region src/utils/azure.ts
1
4
  /**
2
- * This function generates an endpoint URL for (Azure) OpenAI
3
- * based on the configuration parameters provided.
4
- *
5
- * @param {OpenAIEndpointConfig} config - The configuration object for the (Azure) endpoint.
6
- *
7
- * @property {string} config.azureOpenAIApiDeploymentName - The deployment name of Azure OpenAI.
8
- * @property {string} config.azureOpenAIApiInstanceName - The instance name of Azure OpenAI, e.g. `example-resource`.
9
- * @property {string} config.azureOpenAIApiKey - The API Key for Azure OpenAI.
10
- * @property {string} config.azureOpenAIBasePath - The base path for Azure OpenAI, e.g. `https://example-resource.azure.openai.com/openai/deployments/`.
11
- * @property {string} config.baseURL - Some other custom base path URL.
12
- * @property {string} config.azureOpenAIEndpoint - The endpoint for the Azure OpenAI instance, e.g. `https://example-resource.azure.openai.com/`.
13
- *
14
- * The function operates as follows:
15
- * - If both `azureOpenAIBasePath` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`).
16
- * - If both `azureOpenAIEndpoint` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`).
17
- * - 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.
18
- * - If none of the above conditions are met, return any custom `baseURL`.
19
- * - The function returns the generated URL as a string, or undefined if no custom paths are specified.
20
- *
21
- * @throws Will throw an error if the necessary parameters for generating the URL are missing.
22
- *
23
- * @returns {string | undefined} The generated (Azure) OpenAI endpoint URL.
24
- */
25
- export function getEndpoint(config) {
26
- const { azureOpenAIApiDeploymentName, azureOpenAIApiInstanceName, azureOpenAIApiKey, azureOpenAIBasePath, baseURL, azureADTokenProvider, azureOpenAIEndpoint, } = config;
27
- if ((azureOpenAIApiKey || azureADTokenProvider) &&
28
- azureOpenAIBasePath &&
29
- azureOpenAIApiDeploymentName) {
30
- return `${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`;
31
- }
32
- if ((azureOpenAIApiKey || azureADTokenProvider) &&
33
- azureOpenAIEndpoint &&
34
- azureOpenAIApiDeploymentName) {
35
- return `${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`;
36
- }
37
- if (azureOpenAIApiKey || azureADTokenProvider) {
38
- if (!azureOpenAIApiInstanceName) {
39
- throw new Error("azureOpenAIApiInstanceName is required when using azureOpenAIApiKey");
40
- }
41
- if (!azureOpenAIApiDeploymentName) {
42
- throw new Error("azureOpenAIApiDeploymentName is a required parameter when using azureOpenAIApiKey");
43
- }
44
- return `https://${azureOpenAIApiInstanceName}.openai.azure.com/openai/deployments/${azureOpenAIApiDeploymentName}`;
45
- }
46
- return baseURL;
5
+ * This function generates an endpoint URL for (Azure) OpenAI
6
+ * based on the configuration parameters provided.
7
+ *
8
+ * @param {OpenAIEndpointConfig} config - The configuration object for the (Azure) endpoint.
9
+ *
10
+ * @property {string} config.azureOpenAIApiDeploymentName - The deployment name of Azure OpenAI.
11
+ * @property {string} config.azureOpenAIApiInstanceName - The instance name of Azure OpenAI, e.g. `example-resource`.
12
+ * @property {string} config.azureOpenAIApiKey - The API Key for Azure OpenAI.
13
+ * @property {string} config.azureOpenAIBasePath - The base path for Azure OpenAI, e.g. `https://example-resource.azure.openai.com/openai/deployments/`.
14
+ * @property {string} config.baseURL - Some other custom base path URL.
15
+ * @property {string} config.azureOpenAIEndpoint - The endpoint for the Azure OpenAI instance, e.g. `https://example-resource.azure.openai.com/`.
16
+ *
17
+ * The function operates as follows:
18
+ * - If both `azureOpenAIBasePath` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`).
19
+ * - If both `azureOpenAIEndpoint` and `azureOpenAIApiDeploymentName` (plus `azureOpenAIApiKey`) are provided, it returns an URL combining these two parameters (`${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`).
20
+ * - 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.
21
+ * - If none of the above conditions are met, return any custom `baseURL`.
22
+ * - The function returns the generated URL as a string, or undefined if no custom paths are specified.
23
+ *
24
+ * @throws Will throw an error if the necessary parameters for generating the URL are missing.
25
+ *
26
+ * @returns {string | undefined} The generated (Azure) OpenAI endpoint URL.
27
+ */
28
+ function getEndpoint(config) {
29
+ const { azureOpenAIApiDeploymentName, azureOpenAIApiInstanceName, azureOpenAIApiKey, azureOpenAIBasePath, baseURL, azureADTokenProvider, azureOpenAIEndpoint } = config;
30
+ if ((azureOpenAIApiKey || azureADTokenProvider) && azureOpenAIBasePath && azureOpenAIApiDeploymentName) return `${azureOpenAIBasePath}/${azureOpenAIApiDeploymentName}`;
31
+ if ((azureOpenAIApiKey || azureADTokenProvider) && azureOpenAIEndpoint && azureOpenAIApiDeploymentName) return `${azureOpenAIEndpoint}/openai/deployments/${azureOpenAIApiDeploymentName}`;
32
+ if (azureOpenAIApiKey || azureADTokenProvider) {
33
+ if (!azureOpenAIApiInstanceName) throw new Error("azureOpenAIApiInstanceName is required when using azureOpenAIApiKey");
34
+ if (!azureOpenAIApiDeploymentName) throw new Error("azureOpenAIApiDeploymentName is a required parameter when using azureOpenAIApiKey");
35
+ return `https://${azureOpenAIApiInstanceName}.openai.azure.com/openai/deployments/${azureOpenAIApiDeploymentName}`;
36
+ }
37
+ return baseURL;
47
38
  }
39
+ function isHeaders(headers) {
40
+ return typeof Headers !== "undefined" && headers !== null && typeof headers === "object" && Object.prototype.toString.call(headers) === "[object Headers]";
41
+ }
42
+ /**
43
+ * Normalizes various header formats into a consistent Record format.
44
+ *
45
+ * This function accepts headers in multiple formats and converts them to a
46
+ * Record<string, HeaderValue | readonly HeaderValue[]> for consistent handling.
47
+ *
48
+ * @param headers - The headers to normalize. Can be:
49
+ * - A Headers instance
50
+ * - An array of [key, value] pairs
51
+ * - A plain object with string keys
52
+ * - A NullableHeaders-like object with a 'values' property containing Headers
53
+ * - null or undefined
54
+ * @returns A normalized Record containing the header key-value pairs
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * // With Headers instance
59
+ * const headers1 = new Headers([['content-type', 'application/json']]);
60
+ * const normalized1 = normalizeHeaders(headers1);
61
+ *
62
+ * // With plain object
63
+ * const headers2 = { 'content-type': 'application/json' };
64
+ * const normalized2 = normalizeHeaders(headers2);
65
+ *
66
+ * // With array of pairs
67
+ * const headers3 = [['content-type', 'application/json']];
68
+ * const normalized3 = normalizeHeaders(headers3);
69
+ * ```
70
+ */
71
+ function normalizeHeaders(headers) {
72
+ const output = iife(() => {
73
+ if (isHeaders(headers)) return headers;
74
+ else if (Array.isArray(headers)) return new Headers(headers);
75
+ else if (typeof headers === "object" && headers !== null && "values" in headers && isHeaders(headers.values)) return headers.values;
76
+ else if (typeof headers === "object" && headers !== null) {
77
+ const entries = Object.entries(headers).filter(([, v]) => typeof v === "string").map(([k, v]) => [k, v]);
78
+ return new Headers(entries);
79
+ }
80
+ return new Headers();
81
+ });
82
+ return Object.fromEntries(output.entries());
83
+ }
84
+
85
+ //#endregion
86
+ export { getEndpoint, isHeaders, normalizeHeaders };
87
+ //# sourceMappingURL=azure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"azure.js","names":["config: OpenAIEndpointConfig","headers: unknown","headers: HeadersLike","entries: [string, string][]"],"sources":["../../src/utils/azure.ts"],"sourcesContent":["import { 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,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"}
@@ -0,0 +1,25 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_errors = require('./errors.cjs');
3
+ const openai = require_rolldown_runtime.__toESM(require("openai"));
4
+
5
+ //#region src/utils/client.ts
6
+ function wrapOpenAIClientError(e) {
7
+ if (!e || typeof e !== "object") return e;
8
+ let error;
9
+ if (e.constructor.name === openai.APIConnectionTimeoutError.name && "message" in e && typeof e.message === "string") {
10
+ error = new Error(e.message);
11
+ error.name = "TimeoutError";
12
+ } else if (e.constructor.name === openai.APIUserAbortError.name && "message" in e && typeof e.message === "string") {
13
+ error = new Error(e.message);
14
+ 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");
16
+ else if ("status" in e && e.status === 401) error = require_errors.addLangChainErrorFields(e, "MODEL_AUTHENTICATION");
17
+ else if ("status" in e && e.status === 429) error = require_errors.addLangChainErrorFields(e, "MODEL_RATE_LIMIT");
18
+ else if ("status" in e && e.status === 404) error = require_errors.addLangChainErrorFields(e, "MODEL_NOT_FOUND");
19
+ else error = e;
20
+ return error;
21
+ }
22
+
23
+ //#endregion
24
+ exports.wrapOpenAIClientError = wrapOpenAIClientError;
25
+ //# sourceMappingURL=client.cjs.map
@@ -0,0 +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"}
@@ -0,0 +1,5 @@
1
+ //#region src/utils/client.d.ts
2
+ declare function wrapOpenAIClientError(e: unknown): any;
3
+ //#endregion
4
+ export { wrapOpenAIClientError };
5
+ //# sourceMappingURL=client.d.cts.map
@@ -0,0 +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"],"mappings":";iBAAwBA,qBAAAA"}
@@ -0,0 +1,5 @@
1
+ //#region src/utils/client.d.ts
2
+ declare function wrapOpenAIClientError(e: unknown): any;
3
+ //#endregion
4
+ export { wrapOpenAIClientError };
5
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +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"],"mappings":";iBAAwBA,qBAAAA"}
@@ -0,0 +1,24 @@
1
+ import { addLangChainErrorFields } from "./errors.js";
2
+ import { APIConnectionTimeoutError, APIUserAbortError } from "openai";
3
+
4
+ //#region src/utils/client.ts
5
+ function wrapOpenAIClientError(e) {
6
+ if (!e || typeof e !== "object") return e;
7
+ let error;
8
+ if (e.constructor.name === APIConnectionTimeoutError.name && "message" in e && typeof e.message === "string") {
9
+ error = new Error(e.message);
10
+ error.name = "TimeoutError";
11
+ } else if (e.constructor.name === APIUserAbortError.name && "message" in e && typeof e.message === "string") {
12
+ error = new Error(e.message);
13
+ 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");
15
+ else if ("status" in e && e.status === 401) error = addLangChainErrorFields(e, "MODEL_AUTHENTICATION");
16
+ else if ("status" in e && e.status === 429) error = addLangChainErrorFields(e, "MODEL_RATE_LIMIT");
17
+ else if ("status" in e && e.status === 404) error = addLangChainErrorFields(e, "MODEL_NOT_FOUND");
18
+ else error = e;
19
+ return error;
20
+ }
21
+
22
+ //#endregion
23
+ export { wrapOpenAIClientError };
24
+ //# sourceMappingURL=client.js.map
@@ -0,0 +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,10 +1,11 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
- /* eslint-disable no-param-reassign */
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.addLangChainErrorFields = addLangChainErrorFields;
1
+
2
+ //#region src/utils/errors.ts
6
3
  function addLangChainErrorFields(error, lc_error_code) {
7
- error.lc_error_code = lc_error_code;
8
- error.message = `${error.message}\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${lc_error_code}/\n`;
9
- return error;
4
+ error.lc_error_code = lc_error_code;
5
+ error.message = `${error.message}\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${lc_error_code}/\n`;
6
+ return error;
10
7
  }
8
+
9
+ //#endregion
10
+ exports.addLangChainErrorFields = addLangChainErrorFields;
11
+ //# sourceMappingURL=errors.cjs.map
@@ -0,0 +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/* eslint-disable no-param-reassign */\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://js.langchain.com/docs/troubleshooting/errors/${lc_error_code}/\\n`;\n return error;\n}\n"],"mappings":";;AAcA,SAAgB,wBACdA,OACAC,eACA;CACC,MAAc,gBAAgB;CAC/B,MAAM,UAAU,GAAG,MAAM,QAAQ,8EAA8E,EAAE,cAAc,GAAG,CAAC;AACnI,QAAO;AACR"}
@@ -1,7 +1,10 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /* eslint-disable no-param-reassign */
3
- export function addLangChainErrorFields(error, lc_error_code) {
4
- error.lc_error_code = lc_error_code;
5
- error.message = `${error.message}\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${lc_error_code}/\n`;
6
- return error;
1
+ //#region src/utils/errors.ts
2
+ function addLangChainErrorFields(error, lc_error_code) {
3
+ error.lc_error_code = lc_error_code;
4
+ error.message = `${error.message}\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${lc_error_code}/\n`;
5
+ return error;
7
6
  }
7
+
8
+ //#endregion
9
+ export { addLangChainErrorFields };
10
+ //# sourceMappingURL=errors.js.map