@langchain/openai 1.0.0 → 1.1.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 (106) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/azure/chat_models/completions.d.cts +1 -1
  3. package/dist/azure/chat_models/index.cjs +1 -1
  4. package/dist/azure/chat_models/index.d.cts +2 -2
  5. package/dist/azure/chat_models/index.js +1 -1
  6. package/dist/azure/chat_models/responses.cjs +1 -1
  7. package/dist/azure/chat_models/responses.d.cts +1 -1
  8. package/dist/azure/chat_models/responses.js +1 -1
  9. package/dist/azure/embeddings.cjs +1 -1
  10. package/dist/azure/embeddings.js +1 -1
  11. package/dist/chat_models/base.cjs +24 -3
  12. package/dist/chat_models/base.cjs.map +1 -1
  13. package/dist/chat_models/base.d.cts +20 -1
  14. package/dist/chat_models/base.d.cts.map +1 -1
  15. package/dist/chat_models/base.d.ts +23 -4
  16. package/dist/chat_models/base.d.ts.map +1 -1
  17. package/dist/chat_models/base.js +24 -3
  18. package/dist/chat_models/base.js.map +1 -1
  19. package/dist/chat_models/completions.cjs +36 -106
  20. package/dist/chat_models/completions.cjs.map +1 -1
  21. package/dist/chat_models/completions.d.cts +18 -7
  22. package/dist/chat_models/completions.d.cts.map +1 -1
  23. package/dist/chat_models/completions.d.ts +17 -6
  24. package/dist/chat_models/completions.d.ts.map +1 -1
  25. package/dist/chat_models/completions.js +37 -107
  26. package/dist/chat_models/completions.js.map +1 -1
  27. package/dist/chat_models/index.cjs +1 -1
  28. package/dist/chat_models/index.cjs.map +1 -1
  29. package/dist/chat_models/index.d.cts +3 -3
  30. package/dist/chat_models/index.d.ts +4 -4
  31. package/dist/chat_models/index.js +1 -1
  32. package/dist/chat_models/index.js.map +1 -1
  33. package/dist/chat_models/profiles.cjs +567 -0
  34. package/dist/chat_models/profiles.cjs.map +1 -0
  35. package/dist/chat_models/profiles.js +566 -0
  36. package/dist/chat_models/profiles.js.map +1 -0
  37. package/dist/chat_models/responses.cjs +14 -375
  38. package/dist/chat_models/responses.cjs.map +1 -1
  39. package/dist/chat_models/responses.d.cts +2 -17
  40. package/dist/chat_models/responses.d.cts.map +1 -1
  41. package/dist/chat_models/responses.d.ts +1 -16
  42. package/dist/chat_models/responses.d.ts.map +1 -1
  43. package/dist/chat_models/responses.js +15 -376
  44. package/dist/chat_models/responses.js.map +1 -1
  45. package/dist/converters/completions.cjs +605 -0
  46. package/dist/converters/completions.cjs.map +1 -0
  47. package/dist/converters/completions.d.cts +319 -0
  48. package/dist/converters/completions.d.cts.map +1 -0
  49. package/dist/converters/completions.d.ts +319 -0
  50. package/dist/converters/completions.d.ts.map +1 -0
  51. package/dist/converters/completions.js +599 -0
  52. package/dist/converters/completions.js.map +1 -0
  53. package/dist/converters/index.cjs +2 -0
  54. package/dist/converters/index.js +2 -0
  55. package/dist/converters/responses.cjs +895 -0
  56. package/dist/converters/responses.cjs.map +1 -0
  57. package/dist/converters/responses.d.cts +310 -0
  58. package/dist/converters/responses.d.cts.map +1 -0
  59. package/dist/converters/responses.d.ts +310 -0
  60. package/dist/converters/responses.d.ts.map +1 -0
  61. package/dist/converters/responses.js +889 -0
  62. package/dist/converters/responses.js.map +1 -0
  63. package/dist/embeddings.cjs +1 -1
  64. package/dist/embeddings.js +1 -1
  65. package/dist/index.cjs +24 -11
  66. package/dist/index.d.cts +4 -3
  67. package/dist/index.d.ts +4 -3
  68. package/dist/index.js +7 -5
  69. package/dist/llms.cjs +2 -2
  70. package/dist/llms.d.cts +1 -1
  71. package/dist/llms.js +2 -2
  72. package/dist/types.d.cts +2 -2
  73. package/dist/types.d.ts +2 -2
  74. package/dist/utils/errors.cjs +1 -1
  75. package/dist/utils/errors.cjs.map +1 -1
  76. package/dist/utils/errors.js +1 -1
  77. package/dist/utils/errors.js.map +1 -1
  78. package/dist/utils/misc.js +2 -2
  79. package/dist/utils/misc.js.map +1 -1
  80. package/dist/utils/output.cjs +0 -12
  81. package/dist/utils/output.cjs.map +1 -1
  82. package/dist/utils/output.js +1 -12
  83. package/dist/utils/output.js.map +1 -1
  84. package/dist/utils/prompts.cjs +2 -2
  85. package/dist/utils/prompts.cjs.map +1 -1
  86. package/dist/utils/prompts.d.cts +1 -0
  87. package/dist/utils/prompts.d.cts.map +1 -1
  88. package/dist/utils/prompts.d.ts +1 -0
  89. package/dist/utils/prompts.d.ts.map +1 -1
  90. package/dist/utils/prompts.js +2 -2
  91. package/dist/utils/prompts.js.map +1 -1
  92. package/dist/utils/tools.cjs +1 -1
  93. package/dist/utils/tools.js +1 -1
  94. package/package.json +9 -6
  95. package/dist/utils/message_inputs.cjs +0 -139
  96. package/dist/utils/message_inputs.cjs.map +0 -1
  97. package/dist/utils/message_inputs.d.cts +0 -9
  98. package/dist/utils/message_inputs.d.cts.map +0 -1
  99. package/dist/utils/message_inputs.d.ts +0 -9
  100. package/dist/utils/message_inputs.d.ts.map +0 -1
  101. package/dist/utils/message_inputs.js +0 -137
  102. package/dist/utils/message_inputs.js.map +0 -1
  103. package/dist/utils/standard.cjs +0 -315
  104. package/dist/utils/standard.cjs.map +0 -1
  105. package/dist/utils/standard.js +0 -313
  106. package/dist/utils/standard.js.map +0 -1
@@ -0,0 +1,310 @@
1
+ import { ChatOpenAIReasoningSummary } from "../types.js";
2
+ import { OpenAI as OpenAI$1 } from "openai";
3
+ import { AIMessage, BaseMessage, UsageMetadata } from "@langchain/core/messages";
4
+ import { ChatGenerationChunk } from "@langchain/core/outputs";
5
+ import { Converter } from "@langchain/core/utils/format";
6
+
7
+ //#region src/converters/responses.d.ts
8
+ type ExcludeController<T> = T extends {
9
+ controller: unknown;
10
+ } ? never : T;
11
+ type ResponsesCreate = OpenAI$1.Responses["create"];
12
+ type ResponsesParse = OpenAI$1.Responses["parse"];
13
+ type ResponsesCreateInvoke = ExcludeController<Awaited<ReturnType<ResponsesCreate>>>;
14
+ type ResponsesParseInvoke = ExcludeController<Awaited<ReturnType<ResponsesParse>>>;
15
+ type ResponsesInputItem = OpenAI$1.Responses.ResponseInputItem;
16
+ /**
17
+ * Converts OpenAI Responses API usage statistics to LangChain's UsageMetadata format.
18
+ *
19
+ * This converter transforms token usage information from OpenAI's Responses API into
20
+ * the standardized UsageMetadata format used throughout LangChain. It handles both
21
+ * basic token counts and detailed token breakdowns including cached tokens and
22
+ * reasoning tokens.
23
+ *
24
+ * @param usage - The usage statistics object from OpenAI's Responses API containing
25
+ * token counts and optional detailed breakdowns.
26
+ *
27
+ * @returns A UsageMetadata object containing:
28
+ * - `input_tokens`: Total number of tokens in the input/prompt (defaults to 0 if not provided)
29
+ * - `output_tokens`: Total number of tokens in the model's output (defaults to 0 if not provided)
30
+ * - `total_tokens`: Combined total of input and output tokens (defaults to 0 if not provided)
31
+ * - `input_token_details`: Object containing detailed input token information:
32
+ * - `cache_read`: Number of tokens read from cache (only included if available)
33
+ * - `output_token_details`: Object containing detailed output token information:
34
+ * - `reasoning`: Number of tokens used for reasoning (only included if available)
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const usage = {
39
+ * input_tokens: 100,
40
+ * output_tokens: 50,
41
+ * total_tokens: 150,
42
+ * input_tokens_details: { cached_tokens: 20 },
43
+ * output_tokens_details: { reasoning_tokens: 10 }
44
+ * };
45
+ *
46
+ * const metadata = convertResponsesUsageToUsageMetadata(usage);
47
+ * // Returns:
48
+ * // {
49
+ * // input_tokens: 100,
50
+ * // output_tokens: 50,
51
+ * // total_tokens: 150,
52
+ * // input_token_details: { cache_read: 20 },
53
+ * // output_token_details: { reasoning: 10 }
54
+ * // }
55
+ * ```
56
+ *
57
+ * @remarks
58
+ * - The function safely handles undefined or null values by using optional chaining
59
+ * and nullish coalescing operators
60
+ * - Detailed token information (cache_read, reasoning) is only included in the result
61
+ * if the corresponding values are present in the input
62
+ * - Token counts default to 0 if not provided in the usage object
63
+ * - This converter is specifically designed for OpenAI's Responses API format and
64
+ * may differ from other OpenAI API endpoints
65
+ */
66
+ declare const convertResponsesUsageToUsageMetadata: Converter<OpenAI$1.Responses.ResponseUsage | undefined, UsageMetadata>;
67
+ /**
68
+ * Converts an OpenAI Responses API response to a LangChain AIMessage.
69
+ *
70
+ * This converter processes the output from OpenAI's Responses API (both `create` and `parse` methods)
71
+ * and transforms it into a LangChain AIMessage object with all relevant metadata, tool calls, and content.
72
+ *
73
+ * @param response - The response object from OpenAI's Responses API. Can be either:
74
+ * - ResponsesCreateInvoke: Result from `responses.create()`
75
+ * - ResponsesParseInvoke: Result from `responses.parse()`
76
+ *
77
+ * @returns An AIMessage containing:
78
+ * - `id`: The message ID from the response output
79
+ * - `content`: Array of message content blocks (text, images, etc.)
80
+ * - `tool_calls`: Array of successfully parsed tool calls
81
+ * - `invalid_tool_calls`: Array of tool calls that failed to parse
82
+ * - `usage_metadata`: Token usage information converted to LangChain format
83
+ * - `additional_kwargs`: Extra data including:
84
+ * - `refusal`: Refusal text if the model refused to respond
85
+ * - `reasoning`: Reasoning output for reasoning models
86
+ * - `tool_outputs`: Results from built-in tools (web search, file search, etc.)
87
+ * - `parsed`: Parsed structured output when using json_schema format
88
+ * - Function call ID mappings for tracking
89
+ * - `response_metadata`: Metadata about the response including model, timestamps, status, etc.
90
+ *
91
+ * @throws Error if the response contains an error object. The error message and code are extracted
92
+ * from the response.error field.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const response = await client.responses.create({
97
+ * model: "gpt-4",
98
+ * input: [{ type: "message", content: "Hello" }]
99
+ * });
100
+ * const message = convertResponsesMessageToAIMessage(response);
101
+ * console.log(message.content); // Message content
102
+ * console.log(message.tool_calls); // Any tool calls made
103
+ * ```
104
+ *
105
+ * @remarks
106
+ * The converter handles multiple output item types:
107
+ * - `message`: Text and structured content from the model
108
+ * - `function_call`: Tool/function calls that need to be executed
109
+ * - `reasoning`: Reasoning traces from reasoning models (o1, o3, etc.)
110
+ * - `custom_tool_call`: Custom tool invocations
111
+ * - Built-in tool outputs: web_search, file_search, code_interpreter, etc.
112
+ *
113
+ * Tool calls are parsed and validated. Invalid tool calls (malformed JSON, etc.) are captured
114
+ * in the `invalid_tool_calls` array rather than throwing errors.
115
+ */
116
+ declare const convertResponsesMessageToAIMessage: Converter<ResponsesCreateInvoke | ResponsesParseInvoke, AIMessage>;
117
+ /**
118
+ * Converts a LangChain ChatOpenAI reasoning summary to an OpenAI Responses API reasoning item.
119
+ *
120
+ * This converter transforms reasoning summaries that have been accumulated during streaming
121
+ * (where summary parts may arrive in multiple chunks with the same index) into the final
122
+ * consolidated format expected by OpenAI's Responses API. It combines summary parts that
123
+ * share the same index and removes the index field from the final output.
124
+ *
125
+ * @param reasoning - A ChatOpenAI reasoning summary object containing:
126
+ * - `id`: The reasoning item ID
127
+ * - `type`: The type of reasoning (typically "reasoning")
128
+ * - `summary`: Array of summary parts, each with:
129
+ * - `text`: The summary text content
130
+ * - `type`: The summary type (e.g., "summary_text")
131
+ * - `index`: The index used to group related summary parts during streaming
132
+ *
133
+ * @returns An OpenAI Responses API ResponseReasoningItem with:
134
+ * - All properties from the input reasoning object
135
+ * - `summary`: Consolidated array of summary objects with:
136
+ * - `text`: Combined text from all parts with the same index
137
+ * - `type`: The summary type
138
+ * - No `index` field (removed after consolidation)
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * // Input: Reasoning summary with multiple parts at the same index
143
+ * const reasoning = {
144
+ * id: "reasoning_123",
145
+ * type: "reasoning",
146
+ * summary: [
147
+ * { text: "First ", type: "summary_text", index: 0 },
148
+ * { text: "part", type: "summary_text", index: 0 },
149
+ * { text: "Second part", type: "summary_text", index: 1 }
150
+ * ]
151
+ * };
152
+ *
153
+ * const result = convertReasoningSummaryToResponsesReasoningItem(reasoning);
154
+ * // Returns:
155
+ * // {
156
+ * // id: "reasoning_123",
157
+ * // type: "reasoning",
158
+ * // summary: [
159
+ * // { text: "First part", type: "summary_text" },
160
+ * // { text: "Second part", type: "summary_text" }
161
+ * // ]
162
+ * // }
163
+ * ```
164
+ *
165
+ * @remarks
166
+ * - This converter is primarily used when reconstructing complete reasoning items from
167
+ * streaming chunks, where summary parts may arrive incrementally with index markers
168
+ * - Summary parts with the same index are concatenated in the order they appear
169
+ * - If the reasoning summary contains only one part, no reduction is performed
170
+ * - The index field is used internally during streaming to track which summary parts
171
+ * belong together, but is removed from the final output as it's not part of the
172
+ * OpenAI Responses API schema
173
+ * - This is the inverse operation of the streaming accumulation that happens in
174
+ * `convertResponsesDeltaToChatGenerationChunk`
175
+ */
176
+ declare const convertReasoningSummaryToResponsesReasoningItem: Converter<ChatOpenAIReasoningSummary, OpenAI$1.Responses.ResponseReasoningItem>;
177
+ /**
178
+ * Converts OpenAI Responses API stream events to LangChain ChatGenerationChunk objects.
179
+ *
180
+ * This converter processes streaming events from OpenAI's Responses API and transforms them
181
+ * into LangChain ChatGenerationChunk objects that can be used in streaming chat applications.
182
+ * It handles various event types including text deltas, tool calls, reasoning, and metadata updates.
183
+ *
184
+ * @param event - A streaming event from OpenAI's Responses API
185
+ *
186
+ * @returns A ChatGenerationChunk containing:
187
+ * - `text`: Concatenated text content from all text parts in the event
188
+ * - `message`: An AIMessageChunk with:
189
+ * - `id`: Message ID (set when a message output item is added)
190
+ * - `content`: Array of content blocks (text with optional annotations)
191
+ * - `tool_call_chunks`: Incremental tool call data (name, args, id)
192
+ * - `usage_metadata`: Token usage information (only in completion events)
193
+ * - `additional_kwargs`: Extra data including:
194
+ * - `refusal`: Refusal text if the model refused to respond
195
+ * - `reasoning`: Reasoning output for reasoning models (id, type, summary)
196
+ * - `tool_outputs`: Results from built-in tools (web search, file search, etc.)
197
+ * - `parsed`: Parsed structured output when using json_schema format
198
+ * - Function call ID mappings for tracking
199
+ * - `response_metadata`: Metadata about the response (model, id, etc.)
200
+ * - `generationInfo`: Additional generation information (e.g., tool output status)
201
+ *
202
+ * Returns `null` for events that don't produce meaningful chunks:
203
+ * - Partial image generation events (to avoid storing all partial images in history)
204
+ * - Unrecognized event types
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * const stream = await client.responses.create({
209
+ * model: "gpt-4",
210
+ * input: [{ type: "message", content: "Hello" }],
211
+ * stream: true
212
+ * });
213
+ *
214
+ * for await (const event of stream) {
215
+ * const chunk = convertResponsesDeltaToChatGenerationChunk(event);
216
+ * if (chunk) {
217
+ * console.log(chunk.text); // Incremental text
218
+ * console.log(chunk.message.tool_call_chunks); // Tool call updates
219
+ * }
220
+ * }
221
+ * ```
222
+ *
223
+ * @remarks
224
+ * - Text content is accumulated in an array with index tracking for proper ordering
225
+ * - Tool call chunks include incremental arguments that need to be concatenated by the consumer
226
+ * - Reasoning summaries are built incrementally across multiple events
227
+ * - Function call IDs are tracked in `additional_kwargs` to map call_id to item id
228
+ * - The `text` field is provided for legacy compatibility with `onLLMNewToken` callbacks
229
+ * - Usage metadata is only available in `response.completed` events
230
+ * - Partial images are intentionally ignored to prevent memory bloat in conversation history
231
+ */
232
+ declare const convertResponsesDeltaToChatGenerationChunk: Converter<OpenAI$1.Responses.ResponseStreamEvent, ChatGenerationChunk | null>;
233
+ /**
234
+ * Converts a single LangChain BaseMessage to OpenAI Responses API input format.
235
+ *
236
+ * This converter transforms a LangChain message into one or more ResponseInputItem objects
237
+ * that can be used with OpenAI's Responses API. It handles complex message structures including
238
+ * tool calls, reasoning blocks, multimodal content, and various content block types.
239
+ *
240
+ * @param message - The LangChain BaseMessage to convert. Can be any message type including
241
+ * HumanMessage, AIMessage, SystemMessage, ToolMessage, etc.
242
+ *
243
+ * @returns An array of ResponseInputItem objects.
244
+ *
245
+ * @example
246
+ * Basic text message conversion:
247
+ * ```typescript
248
+ * const message = new HumanMessage("Hello, how are you?");
249
+ * const items = convertStandardContentMessageToResponsesInput(message);
250
+ * // Returns: [{ type: "message", role: "user", content: [{ type: "input_text", text: "Hello, how are you?" }] }]
251
+ * ```
252
+ *
253
+ * @example
254
+ * AI message with tool calls:
255
+ * ```typescript
256
+ * const message = new AIMessage({
257
+ * content: "I'll check the weather for you.",
258
+ * tool_calls: [{
259
+ * id: "call_123",
260
+ * name: "get_weather",
261
+ * args: { location: "San Francisco" }
262
+ * }]
263
+ * });
264
+ * const items = convertStandardContentMessageToResponsesInput(message);
265
+ * // Returns:
266
+ * // [
267
+ * // { type: "message", role: "assistant", content: [{ type: "input_text", text: "I'll check the weather for you." }] },
268
+ * // { type: "function_call", call_id: "call_123", name: "get_weather", arguments: '{"location":"San Francisco"}' }
269
+ * // ]
270
+ * ```
271
+ */
272
+ declare const convertStandardContentMessageToResponsesInput: Converter<BaseMessage, OpenAI$1.Responses.ResponseInputItem[]>;
273
+ /**
274
+ * - MCP (Model Context Protocol) approval responses
275
+ * - Zero Data Retention (ZDR) mode handling
276
+ *
277
+ * @param params - Conversion parameters
278
+ * @param params.messages - Array of LangChain BaseMessages to convert
279
+ * @param params.zdrEnabled - Whether Zero Data Retention mode is enabled. When true, certain
280
+ * metadata like message IDs and function call IDs are omitted from the output
281
+ * @param params.model - The model name being used. Used to determine if special role mapping
282
+ * is needed (e.g., "system" -> "developer" for reasoning models)
283
+ *
284
+ * @returns Array of ResponsesInputItem objects formatted for the OpenAI Responses API
285
+ *
286
+ * @throws {Error} When a function message is encountered (not supported)
287
+ * @throws {Error} When computer call output format is invalid
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * const messages = [
292
+ * new HumanMessage("Hello"),
293
+ * new AIMessage({ content: "Hi there!", tool_calls: [...] })
294
+ * ];
295
+ *
296
+ * const input = convertMessagesToResponsesInput({
297
+ * messages,
298
+ * zdrEnabled: false,
299
+ * model: "gpt-4"
300
+ * });
301
+ * ```
302
+ */
303
+ declare const convertMessagesToResponsesInput: Converter<{
304
+ messages: BaseMessage[];
305
+ zdrEnabled: boolean;
306
+ model: string;
307
+ }, ResponsesInputItem[]>;
308
+ //#endregion
309
+ export { ResponsesCreate, ResponsesCreateInvoke, ResponsesInputItem, ResponsesParse, ResponsesParseInvoke, convertMessagesToResponsesInput, convertReasoningSummaryToResponsesReasoningItem, convertResponsesDeltaToChatGenerationChunk, convertResponsesMessageToAIMessage, convertResponsesUsageToUsageMetadata, convertStandardContentMessageToResponsesInput };
310
+ //# sourceMappingURL=responses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.d.ts","names":["OpenAI","OpenAIClient","AIMessage","BaseMessage","UsageMetadata","ChatGenerationChunk","ChatOpenAIReasoningSummary","Converter","ExcludeController","T","ResponsesCreate","Responses","ResponsesParse","ResponsesCreateInvoke","ReturnType","Awaited","ResponsesParseInvoke","ResponsesInputItem","ResponseInputItem","convertResponsesUsageToUsageMetadata","ResponseUsage","convertResponsesMessageToAIMessage","convertReasoningSummaryToResponsesReasoningItem","ResponseReasoningItem","convertResponsesDeltaToChatGenerationChunk","ResponseStreamEvent","convertStandardContentMessageToResponsesInput","convertMessagesToResponsesInput"],"sources":["../../src/converters/responses.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport { AIMessage, type BaseMessage, type UsageMetadata } from \"@langchain/core/messages\";\nimport { ChatGenerationChunk } from \"@langchain/core/outputs\";\nimport { ChatOpenAIReasoningSummary } from \"../types.js\";\nimport { Converter } from \"@langchain/core/utils/format\";\ntype ExcludeController<T> = T extends {\n controller: unknown;\n} ? never : T;\nexport type ResponsesCreate = OpenAIClient.Responses[\"create\"];\nexport type ResponsesParse = OpenAIClient.Responses[\"parse\"];\nexport type ResponsesCreateInvoke = ExcludeController<Awaited<ReturnType<ResponsesCreate>>>;\nexport type ResponsesParseInvoke = ExcludeController<Awaited<ReturnType<ResponsesParse>>>;\nexport type ResponsesInputItem = OpenAIClient.Responses.ResponseInputItem;\n/**\n * Converts OpenAI Responses API usage statistics to LangChain's UsageMetadata format.\n *\n * This converter transforms token usage information from OpenAI's Responses API into\n * the standardized UsageMetadata format used throughout LangChain. It handles both\n * basic token counts and detailed token breakdowns including cached tokens and\n * reasoning tokens.\n *\n * @param usage - The usage statistics object from OpenAI's Responses API containing\n * token counts and optional detailed breakdowns.\n *\n * @returns A UsageMetadata object containing:\n * - `input_tokens`: Total number of tokens in the input/prompt (defaults to 0 if not provided)\n * - `output_tokens`: Total number of tokens in the model's output (defaults to 0 if not provided)\n * - `total_tokens`: Combined total of input and output tokens (defaults to 0 if not provided)\n * - `input_token_details`: Object containing detailed input token information:\n * - `cache_read`: Number of tokens read from cache (only included if available)\n * - `output_token_details`: Object containing detailed output token information:\n * - `reasoning`: Number of tokens used for reasoning (only included if available)\n *\n * @example\n * ```typescript\n * const usage = {\n * input_tokens: 100,\n * output_tokens: 50,\n * total_tokens: 150,\n * input_tokens_details: { cached_tokens: 20 },\n * output_tokens_details: { reasoning_tokens: 10 }\n * };\n *\n * const metadata = convertResponsesUsageToUsageMetadata(usage);\n * // Returns:\n * // {\n * // input_tokens: 100,\n * // output_tokens: 50,\n * // total_tokens: 150,\n * // input_token_details: { cache_read: 20 },\n * // output_token_details: { reasoning: 10 }\n * // }\n * ```\n *\n * @remarks\n * - The function safely handles undefined or null values by using optional chaining\n * and nullish coalescing operators\n * - Detailed token information (cache_read, reasoning) is only included in the result\n * if the corresponding values are present in the input\n * - Token counts default to 0 if not provided in the usage object\n * - This converter is specifically designed for OpenAI's Responses API format and\n * may differ from other OpenAI API endpoints\n */\nexport declare const convertResponsesUsageToUsageMetadata: Converter<OpenAIClient.Responses.ResponseUsage | undefined, UsageMetadata>;\n/**\n * Converts an OpenAI Responses API response to a LangChain AIMessage.\n *\n * This converter processes the output from OpenAI's Responses API (both `create` and `parse` methods)\n * and transforms it into a LangChain AIMessage object with all relevant metadata, tool calls, and content.\n *\n * @param response - The response object from OpenAI's Responses API. Can be either:\n * - ResponsesCreateInvoke: Result from `responses.create()`\n * - ResponsesParseInvoke: Result from `responses.parse()`\n *\n * @returns An AIMessage containing:\n * - `id`: The message ID from the response output\n * - `content`: Array of message content blocks (text, images, etc.)\n * - `tool_calls`: Array of successfully parsed tool calls\n * - `invalid_tool_calls`: Array of tool calls that failed to parse\n * - `usage_metadata`: Token usage information converted to LangChain format\n * - `additional_kwargs`: Extra data including:\n * - `refusal`: Refusal text if the model refused to respond\n * - `reasoning`: Reasoning output for reasoning models\n * - `tool_outputs`: Results from built-in tools (web search, file search, etc.)\n * - `parsed`: Parsed structured output when using json_schema format\n * - Function call ID mappings for tracking\n * - `response_metadata`: Metadata about the response including model, timestamps, status, etc.\n *\n * @throws Error if the response contains an error object. The error message and code are extracted\n * from the response.error field.\n *\n * @example\n * ```typescript\n * const response = await client.responses.create({\n * model: \"gpt-4\",\n * input: [{ type: \"message\", content: \"Hello\" }]\n * });\n * const message = convertResponsesMessageToAIMessage(response);\n * console.log(message.content); // Message content\n * console.log(message.tool_calls); // Any tool calls made\n * ```\n *\n * @remarks\n * The converter handles multiple output item types:\n * - `message`: Text and structured content from the model\n * - `function_call`: Tool/function calls that need to be executed\n * - `reasoning`: Reasoning traces from reasoning models (o1, o3, etc.)\n * - `custom_tool_call`: Custom tool invocations\n * - Built-in tool outputs: web_search, file_search, code_interpreter, etc.\n *\n * Tool calls are parsed and validated. Invalid tool calls (malformed JSON, etc.) are captured\n * in the `invalid_tool_calls` array rather than throwing errors.\n */\nexport declare const convertResponsesMessageToAIMessage: Converter<ResponsesCreateInvoke | ResponsesParseInvoke, AIMessage>;\n/**\n * Converts a LangChain ChatOpenAI reasoning summary to an OpenAI Responses API reasoning item.\n *\n * This converter transforms reasoning summaries that have been accumulated during streaming\n * (where summary parts may arrive in multiple chunks with the same index) into the final\n * consolidated format expected by OpenAI's Responses API. It combines summary parts that\n * share the same index and removes the index field from the final output.\n *\n * @param reasoning - A ChatOpenAI reasoning summary object containing:\n * - `id`: The reasoning item ID\n * - `type`: The type of reasoning (typically \"reasoning\")\n * - `summary`: Array of summary parts, each with:\n * - `text`: The summary text content\n * - `type`: The summary type (e.g., \"summary_text\")\n * - `index`: The index used to group related summary parts during streaming\n *\n * @returns An OpenAI Responses API ResponseReasoningItem with:\n * - All properties from the input reasoning object\n * - `summary`: Consolidated array of summary objects with:\n * - `text`: Combined text from all parts with the same index\n * - `type`: The summary type\n * - No `index` field (removed after consolidation)\n *\n * @example\n * ```typescript\n * // Input: Reasoning summary with multiple parts at the same index\n * const reasoning = {\n * id: \"reasoning_123\",\n * type: \"reasoning\",\n * summary: [\n * { text: \"First \", type: \"summary_text\", index: 0 },\n * { text: \"part\", type: \"summary_text\", index: 0 },\n * { text: \"Second part\", type: \"summary_text\", index: 1 }\n * ]\n * };\n *\n * const result = convertReasoningSummaryToResponsesReasoningItem(reasoning);\n * // Returns:\n * // {\n * // id: \"reasoning_123\",\n * // type: \"reasoning\",\n * // summary: [\n * // { text: \"First part\", type: \"summary_text\" },\n * // { text: \"Second part\", type: \"summary_text\" }\n * // ]\n * // }\n * ```\n *\n * @remarks\n * - This converter is primarily used when reconstructing complete reasoning items from\n * streaming chunks, where summary parts may arrive incrementally with index markers\n * - Summary parts with the same index are concatenated in the order they appear\n * - If the reasoning summary contains only one part, no reduction is performed\n * - The index field is used internally during streaming to track which summary parts\n * belong together, but is removed from the final output as it's not part of the\n * OpenAI Responses API schema\n * - This is the inverse operation of the streaming accumulation that happens in\n * `convertResponsesDeltaToChatGenerationChunk`\n */\nexport declare const convertReasoningSummaryToResponsesReasoningItem: Converter<ChatOpenAIReasoningSummary, OpenAIClient.Responses.ResponseReasoningItem>;\n/**\n * Converts OpenAI Responses API stream events to LangChain ChatGenerationChunk objects.\n *\n * This converter processes streaming events from OpenAI's Responses API and transforms them\n * into LangChain ChatGenerationChunk objects that can be used in streaming chat applications.\n * It handles various event types including text deltas, tool calls, reasoning, and metadata updates.\n *\n * @param event - A streaming event from OpenAI's Responses API\n *\n * @returns A ChatGenerationChunk containing:\n * - `text`: Concatenated text content from all text parts in the event\n * - `message`: An AIMessageChunk with:\n * - `id`: Message ID (set when a message output item is added)\n * - `content`: Array of content blocks (text with optional annotations)\n * - `tool_call_chunks`: Incremental tool call data (name, args, id)\n * - `usage_metadata`: Token usage information (only in completion events)\n * - `additional_kwargs`: Extra data including:\n * - `refusal`: Refusal text if the model refused to respond\n * - `reasoning`: Reasoning output for reasoning models (id, type, summary)\n * - `tool_outputs`: Results from built-in tools (web search, file search, etc.)\n * - `parsed`: Parsed structured output when using json_schema format\n * - Function call ID mappings for tracking\n * - `response_metadata`: Metadata about the response (model, id, etc.)\n * - `generationInfo`: Additional generation information (e.g., tool output status)\n *\n * Returns `null` for events that don't produce meaningful chunks:\n * - Partial image generation events (to avoid storing all partial images in history)\n * - Unrecognized event types\n *\n * @example\n * ```typescript\n * const stream = await client.responses.create({\n * model: \"gpt-4\",\n * input: [{ type: \"message\", content: \"Hello\" }],\n * stream: true\n * });\n *\n * for await (const event of stream) {\n * const chunk = convertResponsesDeltaToChatGenerationChunk(event);\n * if (chunk) {\n * console.log(chunk.text); // Incremental text\n * console.log(chunk.message.tool_call_chunks); // Tool call updates\n * }\n * }\n * ```\n *\n * @remarks\n * - Text content is accumulated in an array with index tracking for proper ordering\n * - Tool call chunks include incremental arguments that need to be concatenated by the consumer\n * - Reasoning summaries are built incrementally across multiple events\n * - Function call IDs are tracked in `additional_kwargs` to map call_id to item id\n * - The `text` field is provided for legacy compatibility with `onLLMNewToken` callbacks\n * - Usage metadata is only available in `response.completed` events\n * - Partial images are intentionally ignored to prevent memory bloat in conversation history\n */\nexport declare const convertResponsesDeltaToChatGenerationChunk: Converter<OpenAIClient.Responses.ResponseStreamEvent, ChatGenerationChunk | null>;\n/**\n * Converts a single LangChain BaseMessage to OpenAI Responses API input format.\n *\n * This converter transforms a LangChain message into one or more ResponseInputItem objects\n * that can be used with OpenAI's Responses API. It handles complex message structures including\n * tool calls, reasoning blocks, multimodal content, and various content block types.\n *\n * @param message - The LangChain BaseMessage to convert. Can be any message type including\n * HumanMessage, AIMessage, SystemMessage, ToolMessage, etc.\n *\n * @returns An array of ResponseInputItem objects.\n *\n * @example\n * Basic text message conversion:\n * ```typescript\n * const message = new HumanMessage(\"Hello, how are you?\");\n * const items = convertStandardContentMessageToResponsesInput(message);\n * // Returns: [{ type: \"message\", role: \"user\", content: [{ type: \"input_text\", text: \"Hello, how are you?\" }] }]\n * ```\n *\n * @example\n * AI message with tool calls:\n * ```typescript\n * const message = new AIMessage({\n * content: \"I'll check the weather for you.\",\n * tool_calls: [{\n * id: \"call_123\",\n * name: \"get_weather\",\n * args: { location: \"San Francisco\" }\n * }]\n * });\n * const items = convertStandardContentMessageToResponsesInput(message);\n * // Returns:\n * // [\n * // { type: \"message\", role: \"assistant\", content: [{ type: \"input_text\", text: \"I'll check the weather for you.\" }] },\n * // { type: \"function_call\", call_id: \"call_123\", name: \"get_weather\", arguments: '{\"location\":\"San Francisco\"}' }\n * // ]\n * ```\n */\nexport declare const convertStandardContentMessageToResponsesInput: Converter<BaseMessage, OpenAIClient.Responses.ResponseInputItem[]>;\n/**\n * - MCP (Model Context Protocol) approval responses\n * - Zero Data Retention (ZDR) mode handling\n *\n * @param params - Conversion parameters\n * @param params.messages - Array of LangChain BaseMessages to convert\n * @param params.zdrEnabled - Whether Zero Data Retention mode is enabled. When true, certain\n * metadata like message IDs and function call IDs are omitted from the output\n * @param params.model - The model name being used. Used to determine if special role mapping\n * is needed (e.g., \"system\" -> \"developer\" for reasoning models)\n *\n * @returns Array of ResponsesInputItem objects formatted for the OpenAI Responses API\n *\n * @throws {Error} When a function message is encountered (not supported)\n * @throws {Error} When computer call output format is invalid\n *\n * @example\n * ```typescript\n * const messages = [\n * new HumanMessage(\"Hello\"),\n * new AIMessage({ content: \"Hi there!\", tool_calls: [...] })\n * ];\n *\n * const input = convertMessagesToResponsesInput({\n * messages,\n * zdrEnabled: false,\n * model: \"gpt-4\"\n * });\n * ```\n */\nexport declare const convertMessagesToResponsesInput: Converter<{\n messages: BaseMessage[];\n zdrEnabled: boolean;\n model: string;\n}, ResponsesInputItem[]>;\nexport {};\n"],"mappings":";;;;;;;KAKKQ,uBAAuBC;;AAD6B,CAAA,GACpDD,KAAAA,GAEOC,CAFPD;AAAiB,KAGVE,eAAAA,GAAkBT,QAAAA,CAAaU,SAHrB,CAAA,QAAA,CAAA;AAAMF,KAIhBG,cAAAA,GAAiBX,QAAAA,CAAaU,SAJdF,CAAAA,OAAAA,CAAAA;AAEhBA,KAGAI,qBAAAA,GAAwBL,iBAHxBC,CAG0CM,OAH1CN,CAGkDK,UAHlDL,CAG6DC,eAH7DD,CAAAA,CAAAA,CAAAA;AAAC,KAIDO,oBAAAA,GAAuBR,iBAJtB,CAIwCO,OAJxC,CAIgDD,UAJhD,CAI2DF,cAJ3D,CAAA,CAAA,CAAA;AACDF,KAIAO,kBAAAA,GAAqBhB,QAAAA,CAAaU,SAAAA,CAAUO,iBAJJ;AACpD;AACA;;;;;;AAAqD;AACrD;;;;;;AAAoD;AACpD;AAmDA;;;;;AAAoE;AAkDpE;;;;;;AAAkE;AA4DlE;;;;;AAA+E;AAwD/E;;;;;AAA0E;AAwC1E;;;;;AAA6E;AA+B7E;;;AAIGD,cAjPkBE,oCAiPlBF,EAjPwDV,SAiPxDU,CAjPkEhB,QAAAA,CAAaU,SAAAA,CAAUS,aAiPzFH,GAAAA,SAAAA,EAjPoHb,aAiPpHa,CAAAA;;AAJ4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA3L1CI,oCAAoCd,UAAUM,wBAAwBG,sBAAsBd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4D5FoB,iDAAiDf,UAAUD,4BAA4BL,QAAAA,CAAaU,SAAAA,CAAUY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwD9GC,4CAA4CjB,UAAUN,QAAAA,CAAaU,SAAAA,CAAUc,qBAAqBpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwClGqB,+CAA+CnB,UAAUJ,aAAaF,QAAAA,CAAaU,SAAAA,CAAUO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+B7FS,iCAAiCpB;YACxCJ;;;GAGXc"}