@langchain/openai 1.1.0 → 1.1.2

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 (91) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/azure/chat_models/common.cjs +4 -9
  3. package/dist/azure/chat_models/common.cjs.map +1 -1
  4. package/dist/azure/chat_models/common.js +6 -11
  5. package/dist/azure/chat_models/common.js.map +1 -1
  6. package/dist/azure/chat_models/completions.d.cts +1 -1
  7. package/dist/azure/chat_models/index.cjs +1 -1
  8. package/dist/azure/chat_models/index.d.cts +2 -2
  9. package/dist/azure/chat_models/index.js +1 -1
  10. package/dist/azure/chat_models/responses.cjs +1 -1
  11. package/dist/azure/chat_models/responses.d.cts +1 -1
  12. package/dist/azure/chat_models/responses.js +1 -1
  13. package/dist/azure/embeddings.cjs +5 -8
  14. package/dist/azure/embeddings.cjs.map +1 -1
  15. package/dist/azure/embeddings.js +5 -8
  16. package/dist/azure/embeddings.js.map +1 -1
  17. package/dist/azure/llms.cjs +4 -7
  18. package/dist/azure/llms.cjs.map +1 -1
  19. package/dist/azure/llms.js +5 -8
  20. package/dist/azure/llms.js.map +1 -1
  21. package/dist/chat_models/base.cjs +26 -4
  22. package/dist/chat_models/base.cjs.map +1 -1
  23. package/dist/chat_models/base.d.cts +22 -3
  24. package/dist/chat_models/base.d.cts.map +1 -1
  25. package/dist/chat_models/base.d.ts +25 -6
  26. package/dist/chat_models/base.d.ts.map +1 -1
  27. package/dist/chat_models/base.js +27 -5
  28. package/dist/chat_models/base.js.map +1 -1
  29. package/dist/chat_models/completions.cjs +2 -2
  30. package/dist/chat_models/completions.d.cts +1 -1
  31. package/dist/chat_models/completions.js +2 -2
  32. package/dist/chat_models/index.cjs +1 -1
  33. package/dist/chat_models/index.d.cts +3 -3
  34. package/dist/chat_models/index.d.ts +4 -4
  35. package/dist/chat_models/index.js +1 -1
  36. package/dist/chat_models/profiles.cjs +567 -0
  37. package/dist/chat_models/profiles.cjs.map +1 -0
  38. package/dist/chat_models/profiles.js +566 -0
  39. package/dist/chat_models/profiles.js.map +1 -0
  40. package/dist/chat_models/responses.cjs +1 -1
  41. package/dist/chat_models/responses.d.cts +1 -1
  42. package/dist/chat_models/responses.js +1 -1
  43. package/dist/converters/completions.cjs +3 -1
  44. package/dist/converters/completions.d.cts +319 -0
  45. package/dist/converters/completions.d.cts.map +1 -0
  46. package/dist/converters/completions.d.ts +319 -0
  47. package/dist/converters/completions.d.ts.map +1 -0
  48. package/dist/converters/completions.js +2 -2
  49. package/dist/converters/index.cjs +2 -0
  50. package/dist/converters/index.js +2 -0
  51. package/dist/converters/responses.cjs +5 -2
  52. package/dist/converters/responses.d.cts +310 -0
  53. package/dist/converters/responses.d.cts.map +1 -0
  54. package/dist/converters/responses.d.ts +310 -0
  55. package/dist/converters/responses.d.ts.map +1 -0
  56. package/dist/converters/responses.js +3 -3
  57. package/dist/embeddings.cjs +3 -1
  58. package/dist/embeddings.cjs.map +1 -1
  59. package/dist/embeddings.d.cts +4 -2
  60. package/dist/embeddings.d.cts.map +1 -1
  61. package/dist/embeddings.d.ts +4 -2
  62. package/dist/embeddings.d.ts.map +1 -1
  63. package/dist/embeddings.js +3 -1
  64. package/dist/embeddings.js.map +1 -1
  65. package/dist/index.cjs +26 -9
  66. package/dist/index.d.cts +6 -4
  67. package/dist/index.d.ts +6 -4
  68. package/dist/index.js +8 -5
  69. package/dist/llms.cjs +3 -2
  70. package/dist/llms.cjs.map +1 -1
  71. package/dist/llms.d.cts +4 -4
  72. package/dist/llms.d.cts.map +1 -1
  73. package/dist/llms.d.ts +3 -3
  74. package/dist/llms.d.ts.map +1 -1
  75. package/dist/llms.js +3 -2
  76. package/dist/llms.js.map +1 -1
  77. package/dist/types.d.cts +7 -7
  78. package/dist/types.d.cts.map +1 -1
  79. package/dist/types.d.ts +7 -7
  80. package/dist/types.d.ts.map +1 -1
  81. package/dist/utils/azure.cjs +18 -0
  82. package/dist/utils/azure.cjs.map +1 -1
  83. package/dist/utils/azure.d.cts +5 -1
  84. package/dist/utils/azure.d.cts.map +1 -1
  85. package/dist/utils/azure.d.ts +5 -1
  86. package/dist/utils/azure.d.ts.map +1 -1
  87. package/dist/utils/azure.js +16 -1
  88. package/dist/utils/azure.js.map +1 -1
  89. package/dist/utils/tools.cjs +1 -1
  90. package/dist/utils/tools.js +1 -1
  91. package/package.json +9 -6
@@ -0,0 +1,319 @@
1
+ import { OpenAI as OpenAI$1 } from "openai";
2
+ import { BaseMessage, BaseMessageChunk, ContentBlock, StandardContentBlockConverter } from "@langchain/core/messages";
3
+ import { Converter } from "@langchain/core/utils/format";
4
+ import { ChatCompletionContentPart, ChatCompletionContentPartImage, ChatCompletionContentPartInputAudio, ChatCompletionContentPartText } from "openai/resources/chat/completions";
5
+
6
+ //#region src/converters/completions.d.ts
7
+
8
+ /**
9
+ * @deprecated This converter is an internal detail of the OpenAI provider. Do not use it directly. This will be revisited in a future release.
10
+ */
11
+ declare const completionsApiContentBlockConverter: StandardContentBlockConverter<{
12
+ text: ChatCompletionContentPartText;
13
+ image: ChatCompletionContentPartImage;
14
+ audio: ChatCompletionContentPartInputAudio;
15
+ file: ChatCompletionContentPart.File;
16
+ }>;
17
+ /**
18
+ * Converts an OpenAI Chat Completions API message to a LangChain BaseMessage.
19
+ *
20
+ * This converter transforms messages from OpenAI's Chat Completions API format into
21
+ * LangChain's internal message representation, handling various message types and
22
+ * preserving metadata, tool calls, and other relevant information.
23
+ *
24
+ * @remarks
25
+ * The converter handles the following message roles:
26
+ * - `assistant`: Converted to {@link AIMessage} with support for tool calls, function calls,
27
+ * audio content, and multi-modal outputs
28
+ * - Other roles: Converted to generic {@link ChatMessage}
29
+ *
30
+ * For assistant messages, the converter:
31
+ * - Parses and validates tool calls, separating valid and invalid calls
32
+ * - Preserves function call information in additional_kwargs
33
+ * - Includes usage statistics and system fingerprint in response_metadata
34
+ * - Handles multi-modal content (text, images, audio)
35
+ * - Optionally includes the raw API response for debugging
36
+ *
37
+ * @param params - Conversion parameters
38
+ * @param params.message - The OpenAI chat completion message to convert
39
+ * @param params.rawResponse - The complete raw response from OpenAI's API, used to extract
40
+ * metadata like model name, usage statistics, and system fingerprint
41
+ * @param params.includeRawResponse - If true, includes the raw OpenAI response in the
42
+ * message's additional_kwargs under the `__raw_response` key. Useful for debugging
43
+ * or accessing provider-specific fields. Defaults to false.
44
+ *
45
+ * @returns A LangChain BaseMessage instance:
46
+ * - {@link AIMessage} for assistant messages with tool calls, metadata, and content
47
+ * - {@link ChatMessage} for all other message types
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const baseMessage = convertCompletionsMessageToBaseMessage({
52
+ * message: {
53
+ * role: "assistant",
54
+ * content: "Hello! How can I help you?",
55
+ * tool_calls: [
56
+ * {
57
+ * id: "call_123",
58
+ * type: "function",
59
+ * function: { name: "get_weather", arguments: '{"location":"NYC"}' }
60
+ * }
61
+ * ]
62
+ * },
63
+ * rawResponse: completionResponse,
64
+ * includeRawResponse: true
65
+ * });
66
+ * // Returns an AIMessage with parsed tool calls and metadata
67
+ * ```
68
+ *
69
+ * @throws {Error} If tool call parsing fails, the invalid tool call is captured in
70
+ * the `invalid_tool_calls` array rather than throwing an error
71
+ *
72
+ */
73
+ declare const convertCompletionsMessageToBaseMessage: Converter<{
74
+ message: OpenAI$1.Chat.Completions.ChatCompletionMessage;
75
+ rawResponse: OpenAI$1.Chat.Completions.ChatCompletion;
76
+ includeRawResponse?: boolean;
77
+ }, BaseMessage>;
78
+ /**
79
+ * Converts an OpenAI Chat Completions API delta (streaming chunk) to a LangChain BaseMessageChunk.
80
+ *
81
+ * This converter is used during streaming responses to transform incremental updates from OpenAI's
82
+ * Chat Completions API into LangChain message chunks. It handles various message types, tool calls,
83
+ * function calls, audio content, and role-specific message chunk creation.
84
+ *
85
+ * @param params - Conversion parameters
86
+ * @param params.delta - The delta object from an OpenAI streaming chunk containing incremental
87
+ * message updates. May include content, role, tool_calls, function_call, audio, etc.
88
+ * @param params.rawResponse - The complete raw ChatCompletionChunk response from OpenAI,
89
+ * containing metadata like model info, usage stats, and the delta
90
+ * @param params.includeRawResponse - Optional flag to include the raw OpenAI response in the
91
+ * message chunk's additional_kwargs. Useful for debugging or accessing provider-specific data
92
+ * @param params.defaultRole - Optional default role to use if the delta doesn't specify one.
93
+ * Typically used to maintain role consistency across chunks in a streaming response
94
+ *
95
+ * @returns A BaseMessageChunk subclass appropriate for the message role:
96
+ * - HumanMessageChunk for "user" role
97
+ * - AIMessageChunk for "assistant" role (includes tool call chunks)
98
+ * - SystemMessageChunk for "system" or "developer" roles
99
+ * - FunctionMessageChunk for "function" role
100
+ * - ToolMessageChunk for "tool" role
101
+ * - ChatMessageChunk for any other role
102
+ *
103
+ * @example
104
+ * Basic streaming text chunk:
105
+ * ```typescript
106
+ * const chunk = convertCompletionsDeltaToBaseMessageChunk({
107
+ * delta: { role: "assistant", content: "Hello" },
108
+ * rawResponse: { id: "chatcmpl-123", model: "gpt-4", ... }
109
+ * });
110
+ * // Returns: AIMessageChunk with content "Hello"
111
+ * ```
112
+ *
113
+ * @example
114
+ * Streaming chunk with tool call:
115
+ * ```typescript
116
+ * const chunk = convertCompletionsDeltaToBaseMessageChunk({
117
+ * delta: {
118
+ * role: "assistant",
119
+ * tool_calls: [{
120
+ * index: 0,
121
+ * id: "call_123",
122
+ * function: { name: "get_weather", arguments: '{"location":' }
123
+ * }]
124
+ * },
125
+ * rawResponse: { id: "chatcmpl-123", ... }
126
+ * });
127
+ * // Returns: AIMessageChunk with tool_call_chunks containing partial tool call data
128
+ * ```
129
+ *
130
+ * @remarks
131
+ * - Tool calls are converted to ToolCallChunk objects with incremental data
132
+ * - Audio content includes the chunk index from the raw response
133
+ * - The "developer" role is mapped to SystemMessageChunk with a special marker
134
+ * - Response metadata includes model provider info and usage statistics
135
+ * - Function calls and tool calls are stored in additional_kwargs for compatibility
136
+ */
137
+ declare const convertCompletionsDeltaToBaseMessageChunk: Converter<{
138
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
139
+ delta: Record<string, any>;
140
+ rawResponse: OpenAI$1.Chat.Completions.ChatCompletionChunk;
141
+ includeRawResponse?: boolean;
142
+ defaultRole?: OpenAI$1.Chat.ChatCompletionRole;
143
+ }, BaseMessageChunk>;
144
+ /**
145
+ * Converts a standard LangChain content block to an OpenAI Completions API content part.
146
+ *
147
+ * This converter transforms LangChain's standardized content blocks (image, audio, file)
148
+ * into the format expected by OpenAI's Chat Completions API. It handles various content
149
+ * types including images (URL or base64), audio (base64), and files (data or file ID).
150
+ *
151
+ * @param block - The standard content block to convert. Can be an image, audio, or file block.
152
+ *
153
+ * @returns An OpenAI Chat Completions content part object, or undefined if the block
154
+ * cannot be converted (e.g., missing required data).
155
+ *
156
+ * @example
157
+ * Image with URL:
158
+ * ```typescript
159
+ * const block = { type: "image", url: "https://example.com/image.jpg" };
160
+ * const part = convertStandardContentBlockToCompletionsContentPart(block);
161
+ * // Returns: { type: "image_url", image_url: { url: "https://example.com/image.jpg" } }
162
+ * ```
163
+ *
164
+ * @example
165
+ * Image with base64 data:
166
+ * ```typescript
167
+ * const block = { type: "image", data: "iVBORw0KGgo...", mimeType: "image/png" };
168
+ * const part = convertStandardContentBlockToCompletionsContentPart(block);
169
+ * // Returns: { type: "image_url", image_url: { url: "data:image/png;base64,iVBORw0KGgo..." } }
170
+ * ```
171
+ */
172
+ declare const convertStandardContentBlockToCompletionsContentPart: Converter<ContentBlock.Standard, OpenAI$1.Chat.Completions.ChatCompletionContentPartImage | OpenAI$1.Chat.Completions.ChatCompletionContentPartInputAudio | OpenAI$1.Chat.Completions.ChatCompletionContentPart.File | undefined>;
173
+ /**
174
+ * Converts a LangChain BaseMessage with standard content blocks to an OpenAI Chat Completions API message parameter.
175
+ *
176
+ * This converter transforms LangChain's standardized message format (using contentBlocks) into the format
177
+ * expected by OpenAI's Chat Completions API. It handles role mapping, content filtering, and multi-modal
178
+ * content conversion for various message types.
179
+ *
180
+ * @remarks
181
+ * The converter performs the following transformations:
182
+ * - Maps LangChain message roles to OpenAI API roles (user, assistant, system, developer, tool, function)
183
+ * - For reasoning models, automatically converts "system" role to "developer" role
184
+ * - Filters content blocks based on message role (most roles only include text blocks)
185
+ * - For user messages, converts multi-modal content blocks (images, audio, files) to OpenAI format
186
+ * - Preserves tool call IDs for tool messages and function names for function messages
187
+ *
188
+ * Role-specific behavior:
189
+ * - **developer**: Returns only text content blocks (used for reasoning models)
190
+ * - **system**: Returns only text content blocks
191
+ * - **assistant**: Returns only text content blocks
192
+ * - **tool**: Returns only text content blocks with tool_call_id preserved
193
+ * - **function**: Returns text content blocks joined as a single string with function name
194
+ * - **user** (default): Returns multi-modal content including text, images, audio, and files
195
+ *
196
+ * @param params - Conversion parameters
197
+ * @param params.message - The LangChain BaseMessage to convert. Must have contentBlocks property
198
+ * containing an array of standard content blocks (text, image, audio, file, etc.)
199
+ * @param params.model - Optional model name. Used to determine if special role mapping is needed
200
+ * (e.g., "system" -> "developer" for reasoning models like o1)
201
+ *
202
+ * @returns An OpenAI ChatCompletionMessageParam object formatted for the Chat Completions API.
203
+ * The structure varies by role:
204
+ * - Developer/System/Assistant: `{ role, content: TextBlock[] }`
205
+ * - Tool: `{ role: "tool", tool_call_id, content: TextBlock[] }`
206
+ * - Function: `{ role: "function", name, content: string }`
207
+ * - User: `{ role: "user", content: Array<TextPart | ImagePart | AudioPart | FilePart> }`
208
+ *
209
+ * @example
210
+ * Simple text message:
211
+ * ```typescript
212
+ * const message = new HumanMessage({
213
+ * content: [{ type: "text", text: "Hello!" }]
214
+ * });
215
+ * const param = convertStandardContentMessageToCompletionsMessage({ message });
216
+ * // Returns: { role: "user", content: [{ type: "text", text: "Hello!" }] }
217
+ * ```
218
+ *
219
+ * @example
220
+ * Multi-modal user message with image:
221
+ * ```typescript
222
+ * const message = new HumanMessage({
223
+ * content: [
224
+ * { type: "text", text: "What's in this image?" },
225
+ * { type: "image", url: "https://example.com/image.jpg" }
226
+ * ]
227
+ * });
228
+ * const param = convertStandardContentMessageToCompletionsMessage({ message });
229
+ * // Returns: {
230
+ * // role: "user",
231
+ * // content: [
232
+ * // { type: "text", text: "What's in this image?" },
233
+ * // { type: "image_url", image_url: { url: "https://example.com/image.jpg" } }
234
+ * // ]
235
+ * // }
236
+ * ```
237
+ */
238
+ declare const convertStandardContentMessageToCompletionsMessage: Converter<{
239
+ message: BaseMessage;
240
+ model?: string;
241
+ }, OpenAI$1.Chat.Completions.ChatCompletionMessageParam>;
242
+ /**
243
+ * Converts an array of LangChain BaseMessages to OpenAI Chat Completions API message parameters.
244
+ *
245
+ * This converter transforms LangChain's internal message representation into the format required
246
+ * by OpenAI's Chat Completions API. It handles various message types, roles, content formats,
247
+ * tool calls, function calls, audio messages, and special model-specific requirements.
248
+ *
249
+ * @remarks
250
+ * The converter performs several key transformations:
251
+ * - Maps LangChain message types to OpenAI roles (user, assistant, system, tool, function, developer)
252
+ * - Converts standard content blocks (v1 format) using a specialized converter
253
+ * - Handles multimodal content including text, images, audio, and data blocks
254
+ * - Preserves tool calls and function calls with proper formatting
255
+ * - Applies model-specific role mappings (e.g., "system" → "developer" for reasoning models)
256
+ * - Splits audio messages into separate message parameters when needed
257
+ *
258
+ * @param params - Conversion parameters
259
+ * @param params.messages - Array of LangChain BaseMessages to convert. Can include any message
260
+ * type: HumanMessage, AIMessage, SystemMessage, ToolMessage, FunctionMessage, etc.
261
+ * @param params.model - Optional model name used to determine if special role mapping is needed.
262
+ * For reasoning models (o1, o3, etc.), "system" role is converted to "developer" role.
263
+ *
264
+ * @returns Array of ChatCompletionMessageParam objects formatted for OpenAI's Chat Completions API.
265
+ * Some messages may be split into multiple parameters (e.g., audio messages).
266
+ *
267
+ * @example
268
+ * Basic message conversion:
269
+ * ```typescript
270
+ * const messages = [
271
+ * new HumanMessage("What's the weather like?"),
272
+ * new AIMessage("Let me check that for you.")
273
+ * ];
274
+ *
275
+ * const params = convertMessagesToCompletionsMessageParams({
276
+ * messages,
277
+ * model: "gpt-4"
278
+ * });
279
+ * // Returns:
280
+ * // [
281
+ * // { role: "user", content: "What's the weather like?" },
282
+ * // { role: "assistant", content: "Let me check that for you." }
283
+ * // ]
284
+ * ```
285
+ *
286
+ * @example
287
+ * Message with tool calls:
288
+ * ```typescript
289
+ * const messages = [
290
+ * new AIMessage({
291
+ * content: "",
292
+ * tool_calls: [{
293
+ * id: "call_123",
294
+ * name: "get_weather",
295
+ * args: { location: "San Francisco" }
296
+ * }]
297
+ * })
298
+ * ];
299
+ *
300
+ * const params = convertMessagesToCompletionsMessageParams({ messages });
301
+ * // Returns:
302
+ * // [{
303
+ * // role: "assistant",
304
+ * // content: "",
305
+ * // tool_calls: [{
306
+ * // id: "call_123",
307
+ * // type: "function",
308
+ * // function: { name: "get_weather", arguments: '{"location":"San Francisco"}' }
309
+ * // }]
310
+ * // }]
311
+ * ```
312
+ */
313
+ declare const convertMessagesToCompletionsMessageParams: Converter<{
314
+ messages: BaseMessage[];
315
+ model?: string;
316
+ }, OpenAI$1.Chat.Completions.ChatCompletionMessageParam[]>;
317
+ //#endregion
318
+ export { completionsApiContentBlockConverter, convertCompletionsDeltaToBaseMessageChunk, convertCompletionsMessageToBaseMessage, convertMessagesToCompletionsMessageParams, convertStandardContentBlockToCompletionsContentPart, convertStandardContentMessageToCompletionsMessage };
319
+ //# sourceMappingURL=completions.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completions.d.cts","names":["BaseMessage","BaseMessageChunk","StandardContentBlockConverter","ContentBlock","Converter","ChatCompletionContentPartText","ChatCompletionContentPartImage","ChatCompletionContentPartInputAudio","ChatCompletionContentPart","OpenAI","OpenAIClient","completionsApiContentBlockConverter","File","convertCompletionsMessageToBaseMessage","Chat","Completions","ChatCompletionMessage","ChatCompletion","convertCompletionsDeltaToBaseMessageChunk","Record","ChatCompletionChunk","ChatCompletionRole","convertStandardContentBlockToCompletionsContentPart","Standard","convertStandardContentMessageToCompletionsMessage","ChatCompletionMessageParam","convertMessagesToCompletionsMessageParams"],"sources":["../../src/converters/completions.d.ts"],"sourcesContent":["import { BaseMessage, BaseMessageChunk, StandardContentBlockConverter, ContentBlock } from \"@langchain/core/messages\";\nimport { Converter } from \"@langchain/core/utils/format\";\nimport type { ChatCompletionContentPartText, ChatCompletionContentPartImage, ChatCompletionContentPartInputAudio, ChatCompletionContentPart } from \"openai/resources/chat/completions\";\nimport { OpenAI as OpenAIClient } from \"openai\";\n/**\n * @deprecated This converter is an internal detail of the OpenAI provider. Do not use it directly. This will be revisited in a future release.\n */\nexport declare const completionsApiContentBlockConverter: StandardContentBlockConverter<{\n text: ChatCompletionContentPartText;\n image: ChatCompletionContentPartImage;\n audio: ChatCompletionContentPartInputAudio;\n file: ChatCompletionContentPart.File;\n}>;\n/**\n * Converts an OpenAI Chat Completions API message to a LangChain BaseMessage.\n *\n * This converter transforms messages from OpenAI's Chat Completions API format into\n * LangChain's internal message representation, handling various message types and\n * preserving metadata, tool calls, and other relevant information.\n *\n * @remarks\n * The converter handles the following message roles:\n * - `assistant`: Converted to {@link AIMessage} with support for tool calls, function calls,\n * audio content, and multi-modal outputs\n * - Other roles: Converted to generic {@link ChatMessage}\n *\n * For assistant messages, the converter:\n * - Parses and validates tool calls, separating valid and invalid calls\n * - Preserves function call information in additional_kwargs\n * - Includes usage statistics and system fingerprint in response_metadata\n * - Handles multi-modal content (text, images, audio)\n * - Optionally includes the raw API response for debugging\n *\n * @param params - Conversion parameters\n * @param params.message - The OpenAI chat completion message to convert\n * @param params.rawResponse - The complete raw response from OpenAI's API, used to extract\n * metadata like model name, usage statistics, and system fingerprint\n * @param params.includeRawResponse - If true, includes the raw OpenAI response in the\n * message's additional_kwargs under the `__raw_response` key. Useful for debugging\n * or accessing provider-specific fields. Defaults to false.\n *\n * @returns A LangChain BaseMessage instance:\n * - {@link AIMessage} for assistant messages with tool calls, metadata, and content\n * - {@link ChatMessage} for all other message types\n *\n * @example\n * ```typescript\n * const baseMessage = convertCompletionsMessageToBaseMessage({\n * message: {\n * role: \"assistant\",\n * content: \"Hello! How can I help you?\",\n * tool_calls: [\n * {\n * id: \"call_123\",\n * type: \"function\",\n * function: { name: \"get_weather\", arguments: '{\"location\":\"NYC\"}' }\n * }\n * ]\n * },\n * rawResponse: completionResponse,\n * includeRawResponse: true\n * });\n * // Returns an AIMessage with parsed tool calls and metadata\n * ```\n *\n * @throws {Error} If tool call parsing fails, the invalid tool call is captured in\n * the `invalid_tool_calls` array rather than throwing an error\n *\n */\nexport declare const convertCompletionsMessageToBaseMessage: Converter<{\n message: OpenAIClient.Chat.Completions.ChatCompletionMessage;\n rawResponse: OpenAIClient.Chat.Completions.ChatCompletion;\n includeRawResponse?: boolean;\n}, BaseMessage>;\n/**\n * Converts an OpenAI Chat Completions API delta (streaming chunk) to a LangChain BaseMessageChunk.\n *\n * This converter is used during streaming responses to transform incremental updates from OpenAI's\n * Chat Completions API into LangChain message chunks. It handles various message types, tool calls,\n * function calls, audio content, and role-specific message chunk creation.\n *\n * @param params - Conversion parameters\n * @param params.delta - The delta object from an OpenAI streaming chunk containing incremental\n * message updates. May include content, role, tool_calls, function_call, audio, etc.\n * @param params.rawResponse - The complete raw ChatCompletionChunk response from OpenAI,\n * containing metadata like model info, usage stats, and the delta\n * @param params.includeRawResponse - Optional flag to include the raw OpenAI response in the\n * message chunk's additional_kwargs. Useful for debugging or accessing provider-specific data\n * @param params.defaultRole - Optional default role to use if the delta doesn't specify one.\n * Typically used to maintain role consistency across chunks in a streaming response\n *\n * @returns A BaseMessageChunk subclass appropriate for the message role:\n * - HumanMessageChunk for \"user\" role\n * - AIMessageChunk for \"assistant\" role (includes tool call chunks)\n * - SystemMessageChunk for \"system\" or \"developer\" roles\n * - FunctionMessageChunk for \"function\" role\n * - ToolMessageChunk for \"tool\" role\n * - ChatMessageChunk for any other role\n *\n * @example\n * Basic streaming text chunk:\n * ```typescript\n * const chunk = convertCompletionsDeltaToBaseMessageChunk({\n * delta: { role: \"assistant\", content: \"Hello\" },\n * rawResponse: { id: \"chatcmpl-123\", model: \"gpt-4\", ... }\n * });\n * // Returns: AIMessageChunk with content \"Hello\"\n * ```\n *\n * @example\n * Streaming chunk with tool call:\n * ```typescript\n * const chunk = convertCompletionsDeltaToBaseMessageChunk({\n * delta: {\n * role: \"assistant\",\n * tool_calls: [{\n * index: 0,\n * id: \"call_123\",\n * function: { name: \"get_weather\", arguments: '{\"location\":' }\n * }]\n * },\n * rawResponse: { id: \"chatcmpl-123\", ... }\n * });\n * // Returns: AIMessageChunk with tool_call_chunks containing partial tool call data\n * ```\n *\n * @remarks\n * - Tool calls are converted to ToolCallChunk objects with incremental data\n * - Audio content includes the chunk index from the raw response\n * - The \"developer\" role is mapped to SystemMessageChunk with a special marker\n * - Response metadata includes model provider info and usage statistics\n * - Function calls and tool calls are stored in additional_kwargs for compatibility\n */\nexport declare const convertCompletionsDeltaToBaseMessageChunk: Converter<{\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n delta: Record<string, any>;\n rawResponse: OpenAIClient.Chat.Completions.ChatCompletionChunk;\n includeRawResponse?: boolean;\n defaultRole?: OpenAIClient.Chat.ChatCompletionRole;\n}, BaseMessageChunk>;\n/**\n * Converts a standard LangChain content block to an OpenAI Completions API content part.\n *\n * This converter transforms LangChain's standardized content blocks (image, audio, file)\n * into the format expected by OpenAI's Chat Completions API. It handles various content\n * types including images (URL or base64), audio (base64), and files (data or file ID).\n *\n * @param block - The standard content block to convert. Can be an image, audio, or file block.\n *\n * @returns An OpenAI Chat Completions content part object, or undefined if the block\n * cannot be converted (e.g., missing required data).\n *\n * @example\n * Image with URL:\n * ```typescript\n * const block = { type: \"image\", url: \"https://example.com/image.jpg\" };\n * const part = convertStandardContentBlockToCompletionsContentPart(block);\n * // Returns: { type: \"image_url\", image_url: { url: \"https://example.com/image.jpg\" } }\n * ```\n *\n * @example\n * Image with base64 data:\n * ```typescript\n * const block = { type: \"image\", data: \"iVBORw0KGgo...\", mimeType: \"image/png\" };\n * const part = convertStandardContentBlockToCompletionsContentPart(block);\n * // Returns: { type: \"image_url\", image_url: { url: \"data:image/png;base64,iVBORw0KGgo...\" } }\n * ```\n */\nexport declare const convertStandardContentBlockToCompletionsContentPart: Converter<ContentBlock.Standard, OpenAIClient.Chat.Completions.ChatCompletionContentPartImage | OpenAIClient.Chat.Completions.ChatCompletionContentPartInputAudio | OpenAIClient.Chat.Completions.ChatCompletionContentPart.File | undefined>;\n/**\n * Converts a LangChain BaseMessage with standard content blocks to an OpenAI Chat Completions API message parameter.\n *\n * This converter transforms LangChain's standardized message format (using contentBlocks) into the format\n * expected by OpenAI's Chat Completions API. It handles role mapping, content filtering, and multi-modal\n * content conversion for various message types.\n *\n * @remarks\n * The converter performs the following transformations:\n * - Maps LangChain message roles to OpenAI API roles (user, assistant, system, developer, tool, function)\n * - For reasoning models, automatically converts \"system\" role to \"developer\" role\n * - Filters content blocks based on message role (most roles only include text blocks)\n * - For user messages, converts multi-modal content blocks (images, audio, files) to OpenAI format\n * - Preserves tool call IDs for tool messages and function names for function messages\n *\n * Role-specific behavior:\n * - **developer**: Returns only text content blocks (used for reasoning models)\n * - **system**: Returns only text content blocks\n * - **assistant**: Returns only text content blocks\n * - **tool**: Returns only text content blocks with tool_call_id preserved\n * - **function**: Returns text content blocks joined as a single string with function name\n * - **user** (default): Returns multi-modal content including text, images, audio, and files\n *\n * @param params - Conversion parameters\n * @param params.message - The LangChain BaseMessage to convert. Must have contentBlocks property\n * containing an array of standard content blocks (text, image, audio, file, etc.)\n * @param params.model - Optional model name. Used to determine if special role mapping is needed\n * (e.g., \"system\" -> \"developer\" for reasoning models like o1)\n *\n * @returns An OpenAI ChatCompletionMessageParam object formatted for the Chat Completions API.\n * The structure varies by role:\n * - Developer/System/Assistant: `{ role, content: TextBlock[] }`\n * - Tool: `{ role: \"tool\", tool_call_id, content: TextBlock[] }`\n * - Function: `{ role: \"function\", name, content: string }`\n * - User: `{ role: \"user\", content: Array<TextPart | ImagePart | AudioPart | FilePart> }`\n *\n * @example\n * Simple text message:\n * ```typescript\n * const message = new HumanMessage({\n * content: [{ type: \"text\", text: \"Hello!\" }]\n * });\n * const param = convertStandardContentMessageToCompletionsMessage({ message });\n * // Returns: { role: \"user\", content: [{ type: \"text\", text: \"Hello!\" }] }\n * ```\n *\n * @example\n * Multi-modal user message with image:\n * ```typescript\n * const message = new HumanMessage({\n * content: [\n * { type: \"text\", text: \"What's in this image?\" },\n * { type: \"image\", url: \"https://example.com/image.jpg\" }\n * ]\n * });\n * const param = convertStandardContentMessageToCompletionsMessage({ message });\n * // Returns: {\n * // role: \"user\",\n * // content: [\n * // { type: \"text\", text: \"What's in this image?\" },\n * // { type: \"image_url\", image_url: { url: \"https://example.com/image.jpg\" } }\n * // ]\n * // }\n * ```\n */\nexport declare const convertStandardContentMessageToCompletionsMessage: Converter<{\n message: BaseMessage;\n model?: string;\n}, OpenAIClient.Chat.Completions.ChatCompletionMessageParam>;\n/**\n * Converts an array of LangChain BaseMessages to OpenAI Chat Completions API message parameters.\n *\n * This converter transforms LangChain's internal message representation into the format required\n * by OpenAI's Chat Completions API. It handles various message types, roles, content formats,\n * tool calls, function calls, audio messages, and special model-specific requirements.\n *\n * @remarks\n * The converter performs several key transformations:\n * - Maps LangChain message types to OpenAI roles (user, assistant, system, tool, function, developer)\n * - Converts standard content blocks (v1 format) using a specialized converter\n * - Handles multimodal content including text, images, audio, and data blocks\n * - Preserves tool calls and function calls with proper formatting\n * - Applies model-specific role mappings (e.g., \"system\" → \"developer\" for reasoning models)\n * - Splits audio messages into separate message parameters when needed\n *\n * @param params - Conversion parameters\n * @param params.messages - Array of LangChain BaseMessages to convert. Can include any message\n * type: HumanMessage, AIMessage, SystemMessage, ToolMessage, FunctionMessage, etc.\n * @param params.model - Optional model name used to determine if special role mapping is needed.\n * For reasoning models (o1, o3, etc.), \"system\" role is converted to \"developer\" role.\n *\n * @returns Array of ChatCompletionMessageParam objects formatted for OpenAI's Chat Completions API.\n * Some messages may be split into multiple parameters (e.g., audio messages).\n *\n * @example\n * Basic message conversion:\n * ```typescript\n * const messages = [\n * new HumanMessage(\"What's the weather like?\"),\n * new AIMessage(\"Let me check that for you.\")\n * ];\n *\n * const params = convertMessagesToCompletionsMessageParams({\n * messages,\n * model: \"gpt-4\"\n * });\n * // Returns:\n * // [\n * // { role: \"user\", content: \"What's the weather like?\" },\n * // { role: \"assistant\", content: \"Let me check that for you.\" }\n * // ]\n * ```\n *\n * @example\n * Message with tool calls:\n * ```typescript\n * const messages = [\n * new AIMessage({\n * content: \"\",\n * tool_calls: [{\n * id: \"call_123\",\n * name: \"get_weather\",\n * args: { location: \"San Francisco\" }\n * }]\n * })\n * ];\n *\n * const params = convertMessagesToCompletionsMessageParams({ messages });\n * // Returns:\n * // [{\n * // role: \"assistant\",\n * // content: \"\",\n * // tool_calls: [{\n * // id: \"call_123\",\n * // type: \"function\",\n * // function: { name: \"get_weather\", arguments: '{\"location\":\"San Francisco\"}' }\n * // }]\n * // }]\n * ```\n */\nexport declare const convertMessagesToCompletionsMessageParams: Converter<{\n messages: BaseMessage[];\n model?: string;\n}, OpenAIClient.Chat.Completions.ChatCompletionMessageParam[]>;\n"],"mappings":";;;;;;;;;AAOA;AAKE,cALmBW,mCAKnB,EALwDT,6BAKxD,CAAA;EAAA,IAJQG,EAAAA,6BAAAA;EAA6B,KAC5BC,EAAAA,8BAAAA;EAA8B,KAC9BC,EAAAA,mCAAAA;EAAmC,IACpCC,EAAAA,yBAAAA,CAA0BI,IAAAA;CAAI,CAAA;AAJ+C;AA8DvF;;;;;;AAAsE;AAgEtE;;;;;;;AAAyE;AAmCzE;;;;;;;AAAmF;AAkEnF;;;;;AAAiF;AA2EjF;;;;;AAAyE;;;;;;;;;;;;;;;;;;;;;cAhPpDC,wCAAwCT;WAChDM,QAAAA,CAAaI,IAAAA,CAAKC,WAAAA,CAAYC;eAC1BN,QAAAA,CAAaI,IAAAA,CAAKC,WAAAA,CAAYE;;GAE5CjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4DkBkB,2CAA2Cd;;SAErDe;eACMT,QAAAA,CAAaI,IAAAA,CAAKC,WAAAA,CAAYK;;gBAE7BV,QAAAA,CAAaI,IAAAA,CAAKO;GACjCpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6BkBqB,qDAAqDlB,UAAUD,YAAAA,CAAaoB,UAAUb,QAAAA,CAAaI,IAAAA,CAAKC,WAAAA,CAAYT,iCAAiCI,QAAAA,CAAaI,IAAAA,CAAKC,WAAAA,CAAYR,sCAAsCG,QAAAA,CAAaI,IAAAA,CAAKC,WAAAA,CAAYP,yBAAAA,CAA0BI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkEjRY,mDAAmDpB;WAC3DJ;;GAEVU,QAAAA,CAAaI,IAAAA,CAAKC,WAAAA,CAAYU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwEZC,2CAA2CtB;YAClDJ;;GAEXU,QAAAA,CAAaI,IAAAA,CAAKC,WAAAA,CAAYU"}