@amux.ai/adapter-openai 0.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,1546 @@
1
+ 'use strict';
2
+
3
+ var llmBridge = require('@amux.ai/llm-bridge');
4
+
5
+ // src/inbound/error-parser.ts
6
+ function parseError(error) {
7
+ return llmBridge.parseOpenAICompatibleError(error);
8
+ }
9
+
10
+ // src/inbound/request-parser.ts
11
+ function parseRequest(request) {
12
+ const req = request;
13
+ let system;
14
+ const messages = [];
15
+ for (const msg of req.messages) {
16
+ if (msg.role === "system") {
17
+ if (typeof msg.content === "string") {
18
+ system = system ? `${system}
19
+ ${msg.content}` : msg.content;
20
+ }
21
+ } else {
22
+ messages.push(parseMessage(msg));
23
+ }
24
+ }
25
+ const tools = req.tools?.map((tool) => parseTool(tool));
26
+ const toolChoice = req.tool_choice ? parseToolChoice(req.tool_choice) : void 0;
27
+ return {
28
+ messages,
29
+ model: req.model,
30
+ tools,
31
+ toolChoice,
32
+ stream: req.stream,
33
+ system,
34
+ generation: {
35
+ temperature: req.temperature,
36
+ topP: req.top_p,
37
+ maxTokens: req.max_tokens ?? req.max_completion_tokens,
38
+ stopSequences: req.stop ? Array.isArray(req.stop) ? req.stop : [req.stop] : void 0,
39
+ presencePenalty: req.presence_penalty,
40
+ frequencyPenalty: req.frequency_penalty,
41
+ n: req.n,
42
+ seed: req.seed,
43
+ responseFormat: req.response_format ? {
44
+ type: req.response_format.type,
45
+ jsonSchema: req.response_format.json_schema
46
+ } : void 0,
47
+ logprobs: req.logprobs,
48
+ topLogprobs: req.top_logprobs
49
+ },
50
+ metadata: {
51
+ userId: req.user
52
+ },
53
+ raw: request
54
+ };
55
+ }
56
+ function parseMessage(msg) {
57
+ return {
58
+ role: msg.role,
59
+ content: parseContent(msg.content),
60
+ name: msg.name,
61
+ toolCalls: msg.tool_calls,
62
+ toolCallId: msg.tool_call_id
63
+ };
64
+ }
65
+ function parseContent(content) {
66
+ if (content === null || content === void 0) {
67
+ return "";
68
+ }
69
+ if (typeof content === "string") {
70
+ return content;
71
+ }
72
+ return content.map((part) => {
73
+ if (part.type === "text") {
74
+ return {
75
+ type: "text",
76
+ text: part.text
77
+ };
78
+ }
79
+ if (part.type === "image_url") {
80
+ const url = part.image_url.url;
81
+ if (url.startsWith("data:")) {
82
+ const match = url.match(/^data:([^;]+);base64,(.+)$/);
83
+ if (match) {
84
+ return {
85
+ type: "image",
86
+ source: {
87
+ type: "base64",
88
+ mediaType: match[1],
89
+ data: match[2]
90
+ }
91
+ };
92
+ }
93
+ }
94
+ return {
95
+ type: "image",
96
+ source: {
97
+ type: "url",
98
+ url
99
+ }
100
+ };
101
+ }
102
+ return {
103
+ type: "text",
104
+ text: JSON.stringify(part)
105
+ };
106
+ });
107
+ }
108
+ function parseTool(tool) {
109
+ return {
110
+ type: "function",
111
+ function: {
112
+ name: tool.function.name,
113
+ description: tool.function.description,
114
+ parameters: tool.function.parameters,
115
+ strict: tool.function.strict
116
+ }
117
+ };
118
+ }
119
+ function parseToolChoice(choice) {
120
+ if (typeof choice === "string") {
121
+ return choice;
122
+ }
123
+ return {
124
+ type: "function",
125
+ function: {
126
+ name: choice.function.name
127
+ }
128
+ };
129
+ }
130
+ function parseResponse(response) {
131
+ const res = response;
132
+ const choices = res.choices.map((choice) => ({
133
+ index: choice.index,
134
+ message: {
135
+ role: choice.message.role,
136
+ content: choice.message.content ?? "",
137
+ toolCalls: choice.message.tool_calls
138
+ },
139
+ finishReason: llmBridge.mapFinishReason(choice.finish_reason),
140
+ logprobs: choice.logprobs
141
+ }));
142
+ return {
143
+ id: res.id,
144
+ model: res.model,
145
+ choices,
146
+ created: res.created,
147
+ systemFingerprint: res.system_fingerprint,
148
+ usage: llmBridge.parseOpenAIUsage(res.usage),
149
+ raw: response
150
+ };
151
+ }
152
+
153
+ // src/inbound/stream-parser.ts
154
+ function mapFinishReason2(reason) {
155
+ const reasonMap = {
156
+ stop: "stop",
157
+ length: "length",
158
+ tool_calls: "tool_calls",
159
+ content_filter: "content_filter",
160
+ function_call: "tool_calls"
161
+ };
162
+ return reasonMap[reason] ?? "stop";
163
+ }
164
+ function parseStream(chunk) {
165
+ const data = chunk;
166
+ if (!data.choices || data.choices.length === 0) {
167
+ if (data.usage) {
168
+ return {
169
+ type: "end",
170
+ id: data.id,
171
+ model: data.model,
172
+ usage: {
173
+ promptTokens: data.usage.prompt_tokens,
174
+ completionTokens: data.usage.completion_tokens,
175
+ totalTokens: data.usage.total_tokens,
176
+ details: data.usage.completion_tokens_details ? {
177
+ reasoningTokens: data.usage.completion_tokens_details.reasoning_tokens
178
+ } : void 0
179
+ },
180
+ raw: chunk
181
+ };
182
+ }
183
+ return null;
184
+ }
185
+ const choice = data.choices[0];
186
+ if (!choice) {
187
+ return null;
188
+ }
189
+ const delta = choice.delta;
190
+ if (delta.role && !delta.content && !delta.tool_calls) {
191
+ return {
192
+ type: "start",
193
+ id: data.id,
194
+ model: data.model,
195
+ raw: chunk
196
+ };
197
+ }
198
+ if (delta.content) {
199
+ return {
200
+ type: "content",
201
+ id: data.id,
202
+ model: data.model,
203
+ content: {
204
+ type: "content",
205
+ delta: delta.content,
206
+ index: choice.index
207
+ },
208
+ raw: chunk
209
+ };
210
+ }
211
+ if (delta.tool_calls && delta.tool_calls.length > 0) {
212
+ const toolCall = delta.tool_calls[0];
213
+ if (toolCall) {
214
+ return {
215
+ type: "tool_call",
216
+ id: data.id,
217
+ model: data.model,
218
+ toolCall: {
219
+ type: "tool_call",
220
+ id: toolCall.id,
221
+ name: toolCall.function?.name,
222
+ arguments: toolCall.function?.arguments,
223
+ index: toolCall.index
224
+ },
225
+ raw: chunk
226
+ };
227
+ }
228
+ }
229
+ if (choice.finish_reason) {
230
+ return {
231
+ type: "end",
232
+ id: data.id,
233
+ model: data.model,
234
+ finishReason: mapFinishReason2(choice.finish_reason),
235
+ usage: data.usage ? {
236
+ promptTokens: data.usage.prompt_tokens,
237
+ completionTokens: data.usage.completion_tokens,
238
+ totalTokens: data.usage.total_tokens,
239
+ details: data.usage.completion_tokens_details ? {
240
+ reasoningTokens: data.usage.completion_tokens_details.reasoning_tokens
241
+ } : void 0
242
+ } : void 0,
243
+ raw: chunk
244
+ };
245
+ }
246
+ return null;
247
+ }
248
+
249
+ // src/outbound/request-builder.ts
250
+ function buildRequest(ir) {
251
+ const messages = [];
252
+ if (ir.system) {
253
+ messages.push({
254
+ role: "system",
255
+ content: ir.system
256
+ });
257
+ }
258
+ for (const msg of ir.messages) {
259
+ messages.push({
260
+ role: msg.role,
261
+ content: buildContent(msg.content),
262
+ name: msg.name,
263
+ tool_calls: msg.toolCalls,
264
+ tool_call_id: msg.toolCallId
265
+ });
266
+ }
267
+ const request = {
268
+ model: ir.model ?? "gpt-4",
269
+ messages,
270
+ stream: ir.stream
271
+ };
272
+ if (ir.tools && ir.tools.length > 0) {
273
+ request.tools = ir.tools.map((tool) => ({
274
+ type: "function",
275
+ function: {
276
+ name: tool.function.name,
277
+ description: tool.function.description,
278
+ parameters: tool.function.parameters,
279
+ strict: tool.function.strict
280
+ }
281
+ }));
282
+ }
283
+ if (ir.toolChoice) {
284
+ request.tool_choice = ir.toolChoice;
285
+ }
286
+ if (ir.generation) {
287
+ if (ir.generation.temperature !== void 0) {
288
+ request.temperature = ir.generation.temperature;
289
+ }
290
+ if (ir.generation.topP !== void 0) {
291
+ request.top_p = ir.generation.topP;
292
+ }
293
+ if (ir.generation.maxTokens !== void 0) {
294
+ request.max_tokens = ir.generation.maxTokens;
295
+ }
296
+ if (ir.generation.stopSequences && ir.generation.stopSequences.length > 0) {
297
+ request.stop = ir.generation.stopSequences;
298
+ }
299
+ if (ir.generation.presencePenalty !== void 0) {
300
+ request.presence_penalty = ir.generation.presencePenalty;
301
+ }
302
+ if (ir.generation.frequencyPenalty !== void 0) {
303
+ request.frequency_penalty = ir.generation.frequencyPenalty;
304
+ }
305
+ if (ir.generation.n !== void 0) {
306
+ request.n = ir.generation.n;
307
+ }
308
+ if (ir.generation.seed !== void 0) {
309
+ request.seed = ir.generation.seed;
310
+ }
311
+ if (ir.generation.responseFormat) {
312
+ request.response_format = {
313
+ type: ir.generation.responseFormat.type,
314
+ json_schema: ir.generation.responseFormat.jsonSchema
315
+ };
316
+ }
317
+ if (ir.generation.logprobs !== void 0) {
318
+ request.logprobs = ir.generation.logprobs;
319
+ }
320
+ if (ir.generation.topLogprobs !== void 0) {
321
+ request.top_logprobs = ir.generation.topLogprobs;
322
+ }
323
+ }
324
+ if (ir.metadata?.userId) {
325
+ request.user = ir.metadata.userId;
326
+ }
327
+ if (ir.stream) {
328
+ request.stream_options = { include_usage: true };
329
+ }
330
+ return request;
331
+ }
332
+ function buildContent(content) {
333
+ if (typeof content === "string") {
334
+ return content || null;
335
+ }
336
+ if (!content || content.length === 0) {
337
+ return null;
338
+ }
339
+ const allText = content.every((part) => part.type === "text");
340
+ if (allText) {
341
+ return content.map((part) => part.type === "text" ? part.text : "").join("");
342
+ }
343
+ return content.map((part) => {
344
+ if (part.type === "text") {
345
+ return { type: "text", text: part.text };
346
+ }
347
+ if (part.type === "image") {
348
+ const imgPart = part;
349
+ if (imgPart.source.type === "url") {
350
+ return {
351
+ type: "image_url",
352
+ image_url: { url: imgPart.source.url }
353
+ };
354
+ }
355
+ return {
356
+ type: "image_url",
357
+ image_url: {
358
+ url: `data:${imgPart.source.mediaType};base64,${imgPart.source.data}`
359
+ }
360
+ };
361
+ }
362
+ return { type: "text", text: JSON.stringify(part) };
363
+ });
364
+ }
365
+ function buildResponse(ir) {
366
+ return {
367
+ id: ir.id,
368
+ object: "chat.completion",
369
+ created: ir.created ?? Math.floor(Date.now() / 1e3),
370
+ model: ir.model,
371
+ system_fingerprint: ir.systemFingerprint,
372
+ choices: ir.choices.map((choice) => ({
373
+ index: choice.index,
374
+ message: {
375
+ role: choice.message.role,
376
+ content: llmBridge.contentToString(choice.message.content),
377
+ tool_calls: choice.message.toolCalls
378
+ },
379
+ finish_reason: choice.finishReason ?? "stop",
380
+ logprobs: choice.logprobs
381
+ })),
382
+ usage: ir.usage ? {
383
+ prompt_tokens: ir.usage.promptTokens,
384
+ completion_tokens: ir.usage.completionTokens,
385
+ total_tokens: ir.usage.totalTokens,
386
+ completion_tokens_details: ir.usage.details?.reasoningTokens ? {
387
+ reasoning_tokens: ir.usage.details.reasoningTokens
388
+ } : void 0
389
+ } : void 0
390
+ };
391
+ }
392
+
393
+ // src/outbound/stream-builder.ts
394
+ function createStreamBuilder() {
395
+ let chunkId = `chatcmpl-${Date.now()}`;
396
+ let model = "";
397
+ const created = Math.floor(Date.now() / 1e3);
398
+ const toolCallsState = /* @__PURE__ */ new Map();
399
+ return {
400
+ process(event) {
401
+ const events = [];
402
+ if (event.id) chunkId = event.id;
403
+ if (event.model) model = event.model;
404
+ if (event.type === "start") {
405
+ events.push({
406
+ event: "data",
407
+ data: {
408
+ id: chunkId,
409
+ object: "chat.completion.chunk",
410
+ created,
411
+ model,
412
+ choices: [{
413
+ index: 0,
414
+ delta: { role: "assistant", content: "" },
415
+ finish_reason: null
416
+ }]
417
+ }
418
+ });
419
+ }
420
+ if (event.type === "content" && event.content?.delta) {
421
+ events.push({
422
+ event: "data",
423
+ data: {
424
+ id: chunkId,
425
+ object: "chat.completion.chunk",
426
+ created,
427
+ model,
428
+ choices: [{
429
+ index: 0,
430
+ delta: { content: event.content.delta },
431
+ finish_reason: null
432
+ }]
433
+ }
434
+ });
435
+ }
436
+ if (event.type === "reasoning" && event.reasoning?.delta) {
437
+ events.push({
438
+ event: "data",
439
+ data: {
440
+ id: chunkId,
441
+ object: "chat.completion.chunk",
442
+ created,
443
+ model,
444
+ choices: [{
445
+ index: 0,
446
+ delta: { content: event.reasoning.delta },
447
+ finish_reason: null
448
+ }]
449
+ }
450
+ });
451
+ }
452
+ if (event.type === "tool_call" && event.toolCall) {
453
+ const toolIndex = event.toolCall.index ?? 0;
454
+ const toolCallDelta = { index: toolIndex };
455
+ if (event.toolCall.name) {
456
+ toolCallDelta.id = event.toolCall.id || `call_${Date.now()}_${toolIndex}`;
457
+ toolCallDelta.type = "function";
458
+ toolCallDelta.function = { name: event.toolCall.name };
459
+ toolCallsState.set(toolIndex, {
460
+ id: toolCallDelta.id,
461
+ name: event.toolCall.name
462
+ });
463
+ }
464
+ if (event.toolCall.arguments) {
465
+ toolCallDelta.function = {
466
+ ...toolCallDelta.function,
467
+ arguments: event.toolCall.arguments
468
+ };
469
+ }
470
+ events.push({
471
+ event: "data",
472
+ data: {
473
+ id: chunkId,
474
+ object: "chat.completion.chunk",
475
+ created,
476
+ model,
477
+ choices: [{
478
+ index: 0,
479
+ delta: { tool_calls: [toolCallDelta] },
480
+ finish_reason: null
481
+ }]
482
+ }
483
+ });
484
+ }
485
+ if (event.type === "end") {
486
+ const finishReason = mapFinishReason3(event.finishReason);
487
+ const finalChunk = {
488
+ id: chunkId,
489
+ object: "chat.completion.chunk",
490
+ created,
491
+ model,
492
+ choices: [{
493
+ index: 0,
494
+ delta: {},
495
+ finish_reason: finishReason
496
+ }]
497
+ };
498
+ if (event.usage) {
499
+ finalChunk.usage = {
500
+ prompt_tokens: event.usage.promptTokens ?? 0,
501
+ completion_tokens: event.usage.completionTokens ?? 0,
502
+ total_tokens: event.usage.totalTokens ?? 0
503
+ };
504
+ }
505
+ events.push({ event: "data", data: finalChunk });
506
+ }
507
+ if (event.type === "error" && event.error) {
508
+ events.push({
509
+ event: "data",
510
+ data: {
511
+ error: {
512
+ message: event.error.message,
513
+ type: "server_error",
514
+ code: event.error.code
515
+ }
516
+ }
517
+ });
518
+ }
519
+ return events;
520
+ },
521
+ finalize() {
522
+ return [{ event: "data", data: "[DONE]" }];
523
+ }
524
+ };
525
+ }
526
+ function mapFinishReason3(reason) {
527
+ if (!reason) return "stop";
528
+ const reasonMap = {
529
+ stop: "stop",
530
+ length: "length",
531
+ tool_calls: "tool_calls",
532
+ content_filter: "content_filter",
533
+ end_turn: "stop",
534
+ max_tokens: "length"
535
+ };
536
+ return reasonMap[reason] ?? "stop";
537
+ }
538
+
539
+ // src/adapter.ts
540
+ var openaiAdapter = {
541
+ name: "openai",
542
+ version: "1.0.0",
543
+ capabilities: {
544
+ streaming: true,
545
+ tools: true,
546
+ vision: true,
547
+ multimodal: true,
548
+ systemPrompt: true,
549
+ toolChoice: true,
550
+ reasoning: false,
551
+ webSearch: false,
552
+ jsonMode: true,
553
+ logprobs: true,
554
+ seed: true
555
+ },
556
+ inbound: {
557
+ parseRequest: (request) => {
558
+ return parseRequest(request);
559
+ },
560
+ parseResponse: (response) => {
561
+ return parseResponse(response);
562
+ },
563
+ parseStream: (chunk) => {
564
+ return parseStream(chunk);
565
+ },
566
+ parseError: (error) => {
567
+ return parseError(error);
568
+ }
569
+ },
570
+ outbound: {
571
+ buildRequest: (ir) => {
572
+ return buildRequest(ir);
573
+ },
574
+ buildResponse: (ir) => {
575
+ return buildResponse(ir);
576
+ },
577
+ createStreamBuilder
578
+ },
579
+ getInfo() {
580
+ return {
581
+ name: this.name,
582
+ version: this.version,
583
+ capabilities: this.capabilities,
584
+ endpoint: {
585
+ baseUrl: "https://api.openai.com",
586
+ chatPath: "/v1/chat/completions",
587
+ modelsPath: "/v1/models"
588
+ }
589
+ };
590
+ }
591
+ };
592
+
593
+ // src/responses/request-parser.ts
594
+ function parseResponsesRequest(request) {
595
+ const req = request;
596
+ let system = req.instructions;
597
+ const { messages, developerSystem } = parseInput(req.input);
598
+ if (developerSystem) {
599
+ system = system ? `${system}
600
+ ${developerSystem}` : developerSystem;
601
+ }
602
+ const tools = req.tools?.filter((tool) => tool.type === "function").map((tool) => ({
603
+ type: "function",
604
+ function: {
605
+ name: tool.name,
606
+ description: tool.description,
607
+ parameters: tool.parameters,
608
+ strict: tool.strict
609
+ }
610
+ }));
611
+ const toolChoice = req.tool_choice ? parseToolChoice2(req.tool_choice) : void 0;
612
+ let responseFormat;
613
+ if (req.text?.format) {
614
+ if (req.text.format.type === "json_object") {
615
+ responseFormat = { type: "json_object" };
616
+ } else if (req.text.format.type === "json_schema" && req.text.format.json_schema) {
617
+ responseFormat = {
618
+ type: "json_schema",
619
+ jsonSchema: {
620
+ name: req.text.format.json_schema.name,
621
+ description: req.text.format.json_schema.description,
622
+ schema: req.text.format.json_schema.schema,
623
+ strict: req.text.format.json_schema.strict
624
+ }
625
+ };
626
+ }
627
+ }
628
+ const generation = {
629
+ temperature: req.temperature,
630
+ topP: req.top_p,
631
+ maxTokens: req.max_output_tokens,
632
+ responseFormat
633
+ };
634
+ return {
635
+ messages,
636
+ model: req.model,
637
+ tools: tools && tools.length > 0 ? tools : void 0,
638
+ toolChoice,
639
+ stream: req.stream,
640
+ system,
641
+ generation,
642
+ metadata: {
643
+ userId: req.user,
644
+ ...req.metadata || {}
645
+ },
646
+ extensions: {
647
+ responses: {
648
+ truncation: req.truncation,
649
+ store: req.store,
650
+ reasoning: req.reasoning,
651
+ previousResponseId: req.previous_response_id,
652
+ parallelToolCalls: req.parallel_tool_calls,
653
+ text: req.text,
654
+ // Track built-in tools for outbound
655
+ builtInTools: req.tools?.filter((t) => t.type !== "function")
656
+ }
657
+ },
658
+ raw: request
659
+ };
660
+ }
661
+ function parseInput(input) {
662
+ if (typeof input === "string") {
663
+ return {
664
+ messages: [
665
+ {
666
+ role: "user",
667
+ content: input
668
+ }
669
+ ]
670
+ };
671
+ }
672
+ const messages = [];
673
+ let developerSystem;
674
+ for (const item of input) {
675
+ if (item.type === "item_reference") {
676
+ continue;
677
+ }
678
+ const role = item.role;
679
+ const content = item.content;
680
+ if (role === "system" || role === "developer") {
681
+ if (typeof content === "string") {
682
+ developerSystem = developerSystem ? `${developerSystem}
683
+ ${content}` : content;
684
+ } else {
685
+ const text = content.filter((p) => p.type === "input_text").map((p) => p.text).join("");
686
+ developerSystem = developerSystem ? `${developerSystem}
687
+ ${text}` : text;
688
+ }
689
+ continue;
690
+ }
691
+ messages.push({
692
+ role,
693
+ content: parseContent2(content)
694
+ });
695
+ }
696
+ return { messages, developerSystem };
697
+ }
698
+ function parseContent2(content) {
699
+ if (typeof content === "string") {
700
+ return content;
701
+ }
702
+ return content.map((part) => {
703
+ if (part.type === "input_text") {
704
+ return {
705
+ type: "text",
706
+ text: part.text
707
+ };
708
+ }
709
+ if (part.type === "input_image") {
710
+ if (part.image_url.startsWith("data:")) {
711
+ const match = part.image_url.match(/^data:([^;]+);base64,(.+)$/);
712
+ if (match) {
713
+ return {
714
+ type: "image",
715
+ source: {
716
+ type: "base64",
717
+ mediaType: match[1],
718
+ data: match[2]
719
+ }
720
+ };
721
+ }
722
+ }
723
+ return {
724
+ type: "image",
725
+ source: {
726
+ type: "url",
727
+ url: part.image_url
728
+ }
729
+ };
730
+ }
731
+ if (part.type === "input_file") {
732
+ return {
733
+ type: "text",
734
+ text: `[File: ${part.file_id}]`
735
+ };
736
+ }
737
+ return {
738
+ type: "text",
739
+ text: JSON.stringify(part)
740
+ };
741
+ });
742
+ }
743
+ function parseToolChoice2(choice) {
744
+ if (typeof choice === "string") {
745
+ return choice;
746
+ }
747
+ return {
748
+ type: "function",
749
+ function: {
750
+ name: choice.name
751
+ }
752
+ };
753
+ }
754
+
755
+ // src/responses/response-parser.ts
756
+ function mapFinishReason4(status) {
757
+ const statusMap = {
758
+ completed: "stop",
759
+ failed: "stop",
760
+ incomplete: "length",
761
+ in_progress: "stop"
762
+ };
763
+ return statusMap[status] ?? "stop";
764
+ }
765
+ function parseResponsesResponse(response) {
766
+ const res = response;
767
+ const { content, toolCalls, reasoning } = extractOutputContent(res.output, res.output_text);
768
+ const choices = [
769
+ {
770
+ index: 0,
771
+ message: {
772
+ role: "assistant",
773
+ content,
774
+ toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
775
+ reasoningContent: reasoning || void 0
776
+ },
777
+ finishReason: mapFinishReason4(res.status)
778
+ }
779
+ ];
780
+ return {
781
+ id: res.id,
782
+ model: res.model,
783
+ choices,
784
+ created: res.created_at,
785
+ usage: res.usage ? {
786
+ promptTokens: res.usage.input_tokens,
787
+ completionTokens: res.usage.output_tokens,
788
+ totalTokens: res.usage.total_tokens,
789
+ details: {
790
+ ...res.usage.output_tokens_details?.reasoning_tokens ? { reasoningTokens: res.usage.output_tokens_details.reasoning_tokens } : {},
791
+ ...res.usage.input_tokens_details?.cached_tokens ? { cachedTokens: res.usage.input_tokens_details.cached_tokens } : {}
792
+ }
793
+ } : void 0,
794
+ raw: response
795
+ };
796
+ }
797
+ function extractOutputContent(output, outputText) {
798
+ let content = "";
799
+ const toolCalls = [];
800
+ let reasoning = null;
801
+ if (outputText && (!output || output.length === 0)) {
802
+ return { content: outputText, toolCalls: [], reasoning: null };
803
+ }
804
+ for (const item of output) {
805
+ if (item.type === "message") {
806
+ for (const part of item.content) {
807
+ if (part.type === "output_text") {
808
+ content += part.text;
809
+ } else if (part.type === "refusal") {
810
+ content += `[Refusal: ${part.refusal}]`;
811
+ }
812
+ }
813
+ } else if (item.type === "function_call") {
814
+ toolCalls.push({
815
+ id: item.call_id,
816
+ type: "function",
817
+ function: {
818
+ name: item.name,
819
+ arguments: item.arguments
820
+ }
821
+ });
822
+ } else if (item.type === "reasoning") {
823
+ const reasoningItem = item;
824
+ if (reasoningItem.summary && reasoningItem.summary.length > 0) {
825
+ reasoning = reasoningItem.summary.filter((s) => s.type === "summary_text").map((s) => s.text).join("");
826
+ } else if (reasoningItem.content && reasoningItem.content.length > 0) {
827
+ reasoning = reasoningItem.content.filter((c) => c.type === "reasoning_text").map((c) => c.text).join("");
828
+ }
829
+ }
830
+ }
831
+ if (!content && outputText) {
832
+ content = outputText;
833
+ }
834
+ return { content, toolCalls, reasoning };
835
+ }
836
+
837
+ // src/responses/stream-parser.ts
838
+ function mapFinishReason5(status) {
839
+ const statusMap = {
840
+ completed: "stop",
841
+ failed: "stop",
842
+ incomplete: "length"
843
+ };
844
+ return statusMap[status] ?? "stop";
845
+ }
846
+ function parseResponsesStream(chunk) {
847
+ const event = chunk;
848
+ switch (event.type) {
849
+ case "response.created":
850
+ case "response.in_progress":
851
+ return {
852
+ type: "start",
853
+ id: event.response?.id ?? "",
854
+ model: event.response?.model ?? "",
855
+ raw: chunk
856
+ };
857
+ case "response.output_text.delta":
858
+ return {
859
+ type: "content",
860
+ id: "",
861
+ model: "",
862
+ content: {
863
+ type: "content",
864
+ delta: event.delta ?? "",
865
+ index: event.output_index ?? 0
866
+ },
867
+ raw: chunk
868
+ };
869
+ case "response.reasoning_summary_text.delta":
870
+ return {
871
+ type: "reasoning",
872
+ id: "",
873
+ model: "",
874
+ reasoning: {
875
+ type: "reasoning",
876
+ delta: event.delta ?? ""
877
+ },
878
+ raw: chunk
879
+ };
880
+ case "response.function_call_arguments.delta":
881
+ return {
882
+ type: "tool_call",
883
+ id: "",
884
+ model: "",
885
+ toolCall: {
886
+ type: "tool_call",
887
+ arguments: event.delta,
888
+ index: event.output_index ?? 0
889
+ },
890
+ raw: chunk
891
+ };
892
+ case "response.output_item.added":
893
+ if (event.item?.type === "function_call") {
894
+ return {
895
+ type: "tool_call",
896
+ id: "",
897
+ model: "",
898
+ toolCall: {
899
+ type: "tool_call",
900
+ id: event.item.call_id,
901
+ name: event.item.name,
902
+ index: event.output_index ?? 0
903
+ },
904
+ raw: chunk
905
+ };
906
+ }
907
+ return null;
908
+ case "response.completed":
909
+ case "response.failed":
910
+ case "response.incomplete":
911
+ return {
912
+ type: "end",
913
+ id: event.response?.id ?? "",
914
+ model: event.response?.model ?? "",
915
+ finishReason: mapFinishReason5(event.response?.status ?? "completed"),
916
+ usage: event.response?.usage ? {
917
+ promptTokens: event.response.usage.input_tokens,
918
+ completionTokens: event.response.usage.output_tokens,
919
+ totalTokens: event.response.usage.total_tokens,
920
+ details: event.response.usage.output_tokens_details?.reasoning_tokens ? {
921
+ reasoningTokens: event.response.usage.output_tokens_details.reasoning_tokens
922
+ } : void 0
923
+ } : void 0,
924
+ raw: chunk
925
+ };
926
+ case "error":
927
+ return {
928
+ type: "error",
929
+ id: "",
930
+ model: "",
931
+ error: {
932
+ type: "api",
933
+ message: event.error?.message ?? "Unknown error",
934
+ code: event.error?.code
935
+ },
936
+ raw: chunk
937
+ };
938
+ default:
939
+ return null;
940
+ }
941
+ }
942
+
943
+ // src/responses/request-builder.ts
944
+ function buildResponsesRequest(ir) {
945
+ const input = [];
946
+ for (const msg of ir.messages) {
947
+ if (msg.role === "system") {
948
+ continue;
949
+ }
950
+ input.push({
951
+ type: "message",
952
+ role: msg.role,
953
+ content: buildContent2(msg.content)
954
+ });
955
+ }
956
+ const request = {
957
+ model: ir.model ?? "gpt-5",
958
+ input: input.length === 1 && input[0]?.type === "message" && typeof input[0].content === "string" && input[0].role === "user" ? input[0].content : input,
959
+ stream: ir.stream
960
+ };
961
+ if (ir.system) {
962
+ request.instructions = ir.system;
963
+ }
964
+ const tools = [];
965
+ if (ir.tools && ir.tools.length > 0) {
966
+ for (const tool of ir.tools) {
967
+ tools.push({
968
+ type: "function",
969
+ name: tool.function.name,
970
+ description: tool.function.description,
971
+ parameters: tool.function.parameters,
972
+ strict: tool.function.strict
973
+ });
974
+ }
975
+ }
976
+ const responsesExt = ir.extensions?.responses;
977
+ const builtInTools = responsesExt?.builtInTools;
978
+ if (builtInTools) {
979
+ tools.push(...builtInTools);
980
+ }
981
+ if (tools.length > 0) {
982
+ request.tools = tools;
983
+ }
984
+ if (ir.toolChoice) {
985
+ if (typeof ir.toolChoice === "string") {
986
+ request.tool_choice = ir.toolChoice;
987
+ } else if (ir.toolChoice.type === "function" && ir.toolChoice.function) {
988
+ request.tool_choice = {
989
+ type: "function",
990
+ name: ir.toolChoice.function.name
991
+ };
992
+ }
993
+ }
994
+ if (ir.generation) {
995
+ if (ir.generation.temperature !== void 0) {
996
+ request.temperature = ir.generation.temperature;
997
+ }
998
+ if (ir.generation.topP !== void 0) {
999
+ request.top_p = ir.generation.topP;
1000
+ }
1001
+ if (ir.generation.maxTokens !== void 0) {
1002
+ request.max_output_tokens = ir.generation.maxTokens;
1003
+ }
1004
+ }
1005
+ if (ir.metadata?.userId) {
1006
+ request.user = ir.metadata.userId;
1007
+ }
1008
+ if (responsesExt) {
1009
+ if (responsesExt.truncation !== void 0) {
1010
+ request.truncation = responsesExt.truncation;
1011
+ }
1012
+ if (responsesExt.store !== void 0) {
1013
+ request.store = responsesExt.store;
1014
+ }
1015
+ if (responsesExt.reasoning !== void 0) {
1016
+ request.reasoning = responsesExt.reasoning;
1017
+ }
1018
+ if (responsesExt.previousResponseId !== void 0) {
1019
+ request.previous_response_id = responsesExt.previousResponseId;
1020
+ }
1021
+ if (responsesExt.parallelToolCalls !== void 0) {
1022
+ request.parallel_tool_calls = responsesExt.parallelToolCalls;
1023
+ }
1024
+ if (responsesExt.text !== void 0) {
1025
+ request.text = responsesExt.text;
1026
+ }
1027
+ }
1028
+ if (ir.generation?.responseFormat) {
1029
+ if (ir.generation.responseFormat.type === "json_object") {
1030
+ request.text = {
1031
+ format: { type: "json_object" }
1032
+ };
1033
+ } else if (ir.generation.responseFormat.type === "json_schema" && ir.generation.responseFormat.jsonSchema) {
1034
+ request.text = {
1035
+ format: {
1036
+ type: "json_schema",
1037
+ json_schema: {
1038
+ name: ir.generation.responseFormat.jsonSchema.name,
1039
+ description: ir.generation.responseFormat.jsonSchema.description,
1040
+ schema: ir.generation.responseFormat.jsonSchema.schema,
1041
+ strict: ir.generation.responseFormat.jsonSchema.strict
1042
+ }
1043
+ }
1044
+ };
1045
+ }
1046
+ }
1047
+ return request;
1048
+ }
1049
+ function buildContent2(content) {
1050
+ if (typeof content === "string") {
1051
+ return content;
1052
+ }
1053
+ if (!content || content.length === 0) {
1054
+ return "";
1055
+ }
1056
+ const allText = content.every((part) => part.type === "text");
1057
+ if (allText) {
1058
+ return content.map((part) => part.type === "text" ? part.text : "").join("");
1059
+ }
1060
+ return content.map((part) => {
1061
+ if (part.type === "text") {
1062
+ return { type: "input_text", text: part.text };
1063
+ }
1064
+ if (part.type === "image") {
1065
+ const imgPart = part;
1066
+ if (imgPart.source.type === "url") {
1067
+ return {
1068
+ type: "input_image",
1069
+ image_url: imgPart.source.url
1070
+ };
1071
+ }
1072
+ return {
1073
+ type: "input_image",
1074
+ image_url: `data:${imgPart.source.mediaType};base64,${imgPart.source.data}`
1075
+ };
1076
+ }
1077
+ return { type: "input_text", text: JSON.stringify(part) };
1078
+ });
1079
+ }
1080
+
1081
+ // src/responses/response-builder.ts
1082
+ function contentToOutput(content) {
1083
+ if (typeof content === "string") {
1084
+ return content ? [{ type: "output_text", text: content }] : [];
1085
+ }
1086
+ if (!content || content.length === 0) {
1087
+ return [];
1088
+ }
1089
+ const text = content.filter((part) => part.type === "text").map((part) => part.type === "text" ? part.text : "").join("");
1090
+ return text ? [{ type: "output_text", text }] : [];
1091
+ }
1092
+ function buildResponsesResponse(ir) {
1093
+ const output = [];
1094
+ const choice = ir.choices[0];
1095
+ if (choice) {
1096
+ const messageContent = contentToOutput(choice.message.content);
1097
+ if (messageContent.length > 0) {
1098
+ output.push({
1099
+ type: "message",
1100
+ id: `msg_${ir.id}`,
1101
+ role: "assistant",
1102
+ content: messageContent,
1103
+ status: "completed"
1104
+ });
1105
+ }
1106
+ if (choice.message.toolCalls) {
1107
+ for (const toolCall of choice.message.toolCalls) {
1108
+ output.push({
1109
+ type: "function_call",
1110
+ id: `fc_${toolCall.id}`,
1111
+ call_id: toolCall.id,
1112
+ name: toolCall.function.name,
1113
+ arguments: toolCall.function.arguments,
1114
+ status: "completed"
1115
+ });
1116
+ }
1117
+ }
1118
+ if (choice.message.reasoningContent) {
1119
+ output.unshift({
1120
+ type: "reasoning",
1121
+ id: `rs_${ir.id}`,
1122
+ content: [{ type: "reasoning_text", text: choice.message.reasoningContent }]
1123
+ });
1124
+ }
1125
+ }
1126
+ return {
1127
+ id: ir.id,
1128
+ object: "response",
1129
+ created_at: ir.created ?? Math.floor(Date.now() / 1e3),
1130
+ model: ir.model,
1131
+ status: "completed",
1132
+ output,
1133
+ usage: ir.usage ? {
1134
+ input_tokens: ir.usage.promptTokens,
1135
+ output_tokens: ir.usage.completionTokens,
1136
+ total_tokens: ir.usage.totalTokens,
1137
+ output_tokens_details: ir.usage.details?.reasoningTokens ? {
1138
+ reasoning_tokens: ir.usage.details.reasoningTokens
1139
+ } : void 0
1140
+ } : void 0
1141
+ };
1142
+ }
1143
+
1144
+ // src/responses/stream-builder.ts
1145
+ function createResponsesStreamBuilder() {
1146
+ let responseId = "";
1147
+ let model = "";
1148
+ let currentOutputIndex = -1;
1149
+ let reasoningItemAdded = false;
1150
+ let reasoningPartAdded = false;
1151
+ let messageItemAdded = false;
1152
+ let contentPartAdded = false;
1153
+ let accumulatedText = "";
1154
+ let accumulatedReasoning = "";
1155
+ let sequenceNumber = 0;
1156
+ let reasoningItemId = "";
1157
+ let messageItemId = "";
1158
+ function nextSeq() {
1159
+ return sequenceNumber++;
1160
+ }
1161
+ function ensureReasoningItemAdded(events) {
1162
+ if (!reasoningItemAdded) {
1163
+ reasoningItemAdded = true;
1164
+ currentOutputIndex++;
1165
+ reasoningItemId = `rs_${responseId || Date.now()}`;
1166
+ events.push({
1167
+ event: "response.output_item.added",
1168
+ data: {
1169
+ type: "response.output_item.added",
1170
+ output_index: currentOutputIndex,
1171
+ item_id: reasoningItemId,
1172
+ sequence_number: nextSeq(),
1173
+ item: {
1174
+ type: "reasoning",
1175
+ id: reasoningItemId,
1176
+ summary: [],
1177
+ status: "in_progress"
1178
+ }
1179
+ }
1180
+ });
1181
+ }
1182
+ }
1183
+ function ensureReasoningPartAdded(events) {
1184
+ if (!reasoningPartAdded) {
1185
+ reasoningPartAdded = true;
1186
+ events.push({
1187
+ event: "response.reasoning_summary_part.added",
1188
+ data: {
1189
+ type: "response.reasoning_summary_part.added",
1190
+ item_id: reasoningItemId,
1191
+ output_index: currentOutputIndex,
1192
+ summary_index: 0,
1193
+ sequence_number: nextSeq(),
1194
+ part: {
1195
+ type: "summary_text",
1196
+ text: ""
1197
+ }
1198
+ }
1199
+ });
1200
+ }
1201
+ }
1202
+ function ensureMessageItemAdded(events) {
1203
+ if (!messageItemAdded) {
1204
+ messageItemAdded = true;
1205
+ currentOutputIndex++;
1206
+ messageItemId = `msg_${responseId || Date.now()}`;
1207
+ events.push({
1208
+ event: "response.output_item.added",
1209
+ data: {
1210
+ type: "response.output_item.added",
1211
+ output_index: currentOutputIndex,
1212
+ item_id: messageItemId,
1213
+ sequence_number: nextSeq(),
1214
+ item: {
1215
+ type: "message",
1216
+ id: messageItemId,
1217
+ role: "assistant",
1218
+ content: [],
1219
+ status: "in_progress"
1220
+ }
1221
+ }
1222
+ });
1223
+ }
1224
+ }
1225
+ function ensureContentPartAdded(events) {
1226
+ if (!contentPartAdded) {
1227
+ contentPartAdded = true;
1228
+ events.push({
1229
+ event: "response.content_part.added",
1230
+ data: {
1231
+ type: "response.content_part.added",
1232
+ output_index: currentOutputIndex,
1233
+ item_id: messageItemId,
1234
+ content_index: 0,
1235
+ sequence_number: nextSeq(),
1236
+ part: {
1237
+ type: "output_text",
1238
+ text: ""
1239
+ }
1240
+ }
1241
+ });
1242
+ }
1243
+ }
1244
+ return {
1245
+ process(event) {
1246
+ const events = [];
1247
+ if (event.id) responseId = event.id || `resp_${Date.now()}`;
1248
+ if (event.model) model = event.model || "";
1249
+ if (event.type === "start") {
1250
+ events.push({
1251
+ event: "response.created",
1252
+ data: {
1253
+ type: "response.created",
1254
+ sequence_number: nextSeq(),
1255
+ response: {
1256
+ id: responseId,
1257
+ object: "response",
1258
+ created_at: Math.floor(Date.now() / 1e3),
1259
+ model,
1260
+ status: "in_progress",
1261
+ output: []
1262
+ }
1263
+ }
1264
+ });
1265
+ }
1266
+ if (event.type === "reasoning" && event.reasoning?.delta) {
1267
+ ensureReasoningItemAdded(events);
1268
+ ensureReasoningPartAdded(events);
1269
+ accumulatedReasoning += event.reasoning.delta;
1270
+ events.push({
1271
+ event: "response.reasoning_summary_text.delta",
1272
+ data: {
1273
+ type: "response.reasoning_summary_text.delta",
1274
+ item_id: reasoningItemId,
1275
+ output_index: 0,
1276
+ // Reasoning is always at output_index 0
1277
+ summary_index: 0,
1278
+ sequence_number: nextSeq(),
1279
+ delta: event.reasoning.delta
1280
+ }
1281
+ });
1282
+ }
1283
+ if (event.type === "content" && event.content?.delta) {
1284
+ ensureMessageItemAdded(events);
1285
+ ensureContentPartAdded(events);
1286
+ accumulatedText += event.content.delta;
1287
+ events.push({
1288
+ event: "response.output_text.delta",
1289
+ data: {
1290
+ type: "response.output_text.delta",
1291
+ output_index: currentOutputIndex,
1292
+ item_id: messageItemId,
1293
+ content_index: 0,
1294
+ sequence_number: nextSeq(),
1295
+ delta: event.content.delta
1296
+ }
1297
+ });
1298
+ }
1299
+ if (event.type === "tool_call" && event.toolCall) {
1300
+ if (event.toolCall.name) {
1301
+ currentOutputIndex++;
1302
+ const toolItemId = `fc_${event.toolCall.id || currentOutputIndex}`;
1303
+ events.push({
1304
+ event: "response.output_item.added",
1305
+ data: {
1306
+ type: "response.output_item.added",
1307
+ output_index: currentOutputIndex,
1308
+ item_id: toolItemId,
1309
+ sequence_number: nextSeq(),
1310
+ item: {
1311
+ type: "function_call",
1312
+ id: toolItemId,
1313
+ call_id: event.toolCall.id || `call_${currentOutputIndex}`,
1314
+ name: event.toolCall.name,
1315
+ arguments: "",
1316
+ status: "in_progress"
1317
+ }
1318
+ }
1319
+ });
1320
+ }
1321
+ if (event.toolCall.arguments) {
1322
+ events.push({
1323
+ event: "response.function_call_arguments.delta",
1324
+ data: {
1325
+ type: "response.function_call_arguments.delta",
1326
+ output_index: currentOutputIndex,
1327
+ item_id: messageItemId,
1328
+ sequence_number: nextSeq(),
1329
+ delta: event.toolCall.arguments
1330
+ }
1331
+ });
1332
+ }
1333
+ }
1334
+ if (event.type === "end") {
1335
+ const output = [];
1336
+ if (reasoningItemAdded) {
1337
+ output.push({
1338
+ type: "reasoning",
1339
+ id: reasoningItemId,
1340
+ summary: accumulatedReasoning ? [{ type: "summary_text", text: accumulatedReasoning }] : [],
1341
+ status: "completed"
1342
+ });
1343
+ events.push({
1344
+ event: "response.reasoning_summary_text.done",
1345
+ data: {
1346
+ type: "response.reasoning_summary_text.done",
1347
+ item_id: reasoningItemId,
1348
+ output_index: 0,
1349
+ summary_index: 0,
1350
+ sequence_number: nextSeq(),
1351
+ text: accumulatedReasoning
1352
+ }
1353
+ });
1354
+ events.push({
1355
+ event: "response.reasoning_summary_part.done",
1356
+ data: {
1357
+ type: "response.reasoning_summary_part.done",
1358
+ item_id: reasoningItemId,
1359
+ output_index: 0,
1360
+ summary_index: 0,
1361
+ sequence_number: nextSeq(),
1362
+ part: {
1363
+ type: "summary_text",
1364
+ text: accumulatedReasoning
1365
+ }
1366
+ }
1367
+ });
1368
+ events.push({
1369
+ event: "response.output_item.done",
1370
+ data: {
1371
+ type: "response.output_item.done",
1372
+ output_index: 0,
1373
+ item_id: reasoningItemId,
1374
+ sequence_number: nextSeq(),
1375
+ item: {
1376
+ type: "reasoning",
1377
+ id: reasoningItemId,
1378
+ summary: [{ type: "summary_text", text: accumulatedReasoning }],
1379
+ status: "completed"
1380
+ }
1381
+ }
1382
+ });
1383
+ }
1384
+ if (messageItemAdded) {
1385
+ const messageOutputIndex = reasoningItemAdded ? 1 : 0;
1386
+ output.push({
1387
+ type: "message",
1388
+ id: messageItemId,
1389
+ role: "assistant",
1390
+ content: accumulatedText ? [{ type: "output_text", text: accumulatedText }] : [],
1391
+ status: "completed"
1392
+ });
1393
+ if (contentPartAdded) {
1394
+ events.push({
1395
+ event: "response.output_text.done",
1396
+ data: {
1397
+ type: "response.output_text.done",
1398
+ output_index: messageOutputIndex,
1399
+ item_id: messageItemId,
1400
+ content_index: 0,
1401
+ sequence_number: nextSeq(),
1402
+ text: accumulatedText
1403
+ }
1404
+ });
1405
+ events.push({
1406
+ event: "response.content_part.done",
1407
+ data: {
1408
+ type: "response.content_part.done",
1409
+ output_index: messageOutputIndex,
1410
+ item_id: messageItemId,
1411
+ content_index: 0,
1412
+ sequence_number: nextSeq(),
1413
+ part: {
1414
+ type: "output_text",
1415
+ text: accumulatedText
1416
+ }
1417
+ }
1418
+ });
1419
+ }
1420
+ events.push({
1421
+ event: "response.output_item.done",
1422
+ data: {
1423
+ type: "response.output_item.done",
1424
+ output_index: messageOutputIndex,
1425
+ item_id: messageItemId,
1426
+ sequence_number: nextSeq(),
1427
+ item: {
1428
+ type: "message",
1429
+ id: messageItemId,
1430
+ role: "assistant",
1431
+ content: accumulatedText ? [{ type: "output_text", text: accumulatedText }] : [],
1432
+ status: "completed"
1433
+ }
1434
+ }
1435
+ });
1436
+ }
1437
+ events.push({
1438
+ event: "response.completed",
1439
+ data: {
1440
+ type: "response.completed",
1441
+ sequence_number: nextSeq(),
1442
+ response: {
1443
+ id: responseId,
1444
+ object: "response",
1445
+ created_at: Math.floor(Date.now() / 1e3),
1446
+ model,
1447
+ status: "completed",
1448
+ output,
1449
+ output_text: accumulatedText || void 0,
1450
+ usage: event.usage ? {
1451
+ input_tokens: event.usage.promptTokens,
1452
+ output_tokens: event.usage.completionTokens,
1453
+ total_tokens: event.usage.totalTokens,
1454
+ output_tokens_details: event.usage.details?.reasoningTokens ? {
1455
+ reasoning_tokens: event.usage.details.reasoningTokens
1456
+ } : void 0
1457
+ } : void 0
1458
+ }
1459
+ }
1460
+ });
1461
+ }
1462
+ if (event.type === "error" && event.error) {
1463
+ events.push({
1464
+ event: "error",
1465
+ data: {
1466
+ type: "error",
1467
+ sequence_number: nextSeq(),
1468
+ error: {
1469
+ type: "api_error",
1470
+ code: event.error.code || "unknown",
1471
+ message: event.error.message
1472
+ }
1473
+ }
1474
+ });
1475
+ }
1476
+ return events;
1477
+ },
1478
+ finalize() {
1479
+ return [];
1480
+ }
1481
+ };
1482
+ }
1483
+
1484
+ // src/responses-adapter.ts
1485
+ var openaiResponsesAdapter = {
1486
+ name: "openai-responses",
1487
+ version: "1.0.0",
1488
+ capabilities: {
1489
+ streaming: true,
1490
+ tools: true,
1491
+ vision: true,
1492
+ multimodal: true,
1493
+ systemPrompt: true,
1494
+ toolChoice: true,
1495
+ reasoning: true,
1496
+ // Responses API supports reasoning models (o3, o4-mini)
1497
+ webSearch: true,
1498
+ // Built-in web search tool
1499
+ jsonMode: true,
1500
+ // Supported via text.format
1501
+ logprobs: false,
1502
+ // Not supported in Responses API
1503
+ seed: false
1504
+ // Not supported in Responses API
1505
+ },
1506
+ inbound: {
1507
+ parseRequest: (request) => {
1508
+ return parseResponsesRequest(request);
1509
+ },
1510
+ parseResponse: (response) => {
1511
+ return parseResponsesResponse(response);
1512
+ },
1513
+ parseStream: (chunk) => {
1514
+ return parseResponsesStream(chunk);
1515
+ },
1516
+ parseError: (error) => {
1517
+ return parseError(error);
1518
+ }
1519
+ },
1520
+ outbound: {
1521
+ buildRequest: (ir) => {
1522
+ return buildResponsesRequest(ir);
1523
+ },
1524
+ buildResponse: (ir) => {
1525
+ return buildResponsesResponse(ir);
1526
+ },
1527
+ createStreamBuilder: createResponsesStreamBuilder
1528
+ },
1529
+ getInfo() {
1530
+ return {
1531
+ name: this.name,
1532
+ version: this.version,
1533
+ capabilities: this.capabilities,
1534
+ endpoint: {
1535
+ baseUrl: "https://api.openai.com",
1536
+ chatPath: "/v1/responses",
1537
+ modelsPath: "/v1/models"
1538
+ }
1539
+ };
1540
+ }
1541
+ };
1542
+
1543
+ exports.openaiAdapter = openaiAdapter;
1544
+ exports.openaiResponsesAdapter = openaiResponsesAdapter;
1545
+ //# sourceMappingURL=index.cjs.map
1546
+ //# sourceMappingURL=index.cjs.map