@codeproxy/core 0.1.0

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.
@@ -0,0 +1,694 @@
1
+ type UpstreamFormat = 'anthropic' | 'openai-chat';
2
+ interface CacheStats {
3
+ cachedTokens: number;
4
+ cacheCreationTokens: number;
5
+ inputTokens: number;
6
+ outputTokens: number;
7
+ totalTokens: number;
8
+ }
9
+ interface CreateResponsesFetchOptions {
10
+ /** Upstream API format. If omitted, inferred from `baseUrl`. */
11
+ upstreamFormat?: UpstreamFormat;
12
+ /** Upstream endpoint URL. Required. */
13
+ baseUrl: string;
14
+ /** Override upstream API version header (Anthropic only). */
15
+ apiVersion?: string;
16
+ /** Replace the caller-provided `model` field before translation. */
17
+ model?: string;
18
+ /** Extra headers merged into every upstream call. */
19
+ defaultHeaders?: Record<string, string>;
20
+ /** Underlying fetch. Defaults to `globalThis.fetch`. */
21
+ fetch?: typeof fetch;
22
+ /** Non-/responses traffic forward target. Defaults to `options.fetch`. */
23
+ passthroughFetch?: typeof fetch;
24
+ /** Drop image/file parts from user messages (e.g. DeepSeek text-only models). */
25
+ dropImages?: boolean;
26
+ /** Optional callback to receive cache statistics. */
27
+ onCacheStats?: (stats: CacheStats) => void;
28
+ /** Override reasoning_effort sent to the upstream model (OpenAI Chat / Anthropic). */
29
+ reasoning_effort?: string;
30
+ /** Override thinking configuration sent to the upstream model. */
31
+ thinking?: unknown;
32
+ /** Timeout in milliseconds for upstream requests. Defaults to no timeout. */
33
+ timeoutMs?: number;
34
+ /** Fallback upstream for requests where the last user message contains images. */
35
+ fallbackUpstream?: {
36
+ baseUrl: string;
37
+ upstreamFormat?: UpstreamFormat;
38
+ model?: string;
39
+ defaultHeaders?: Record<string, string>;
40
+ apiVersion?: string;
41
+ reasoning_effort?: string;
42
+ thinking?: unknown;
43
+ };
44
+ }
45
+ declare function createResponsesFetch(options: CreateResponsesFetchOptions): typeof fetch;
46
+
47
+ /**
48
+ * OpenAI Responses API type definitions (subset used by this library).
49
+ * Only the fields relevant to request translation and event emission are typed.
50
+ * Other fields pass through as `unknown` / `Record<string, unknown>`.
51
+ */
52
+ type ResponsesInputItem = string | ResponsesMessageItem | ResponsesReasoningItem | ResponsesFunctionCallItem | ResponsesFunctionCallOutputItem | ResponsesLocalShellCallItem | ResponsesCommandExecutionItem | ResponsesCommandExecutionOutputItem | ResponsesCustomToolCallItem | ResponsesCustomToolCallOutputItem | ResponsesFileChangeItem | ResponsesFileChangeOutputItem | ResponsesWebSearchCallItem | Record<string, unknown>;
53
+ interface ResponsesContentPart {
54
+ type: 'input_text' | 'text' | 'output_text' | 'reasoning_text' | 'input_image' | 'image' | 'image_url' | 'input_file' | 'file' | 'tool_result' | string;
55
+ text?: string;
56
+ image_url?: string | {
57
+ url: string;
58
+ };
59
+ source?: Record<string, unknown>;
60
+ data?: string;
61
+ base64?: string;
62
+ media_type?: string;
63
+ mime_type?: string;
64
+ file_data?: string;
65
+ file_url?: string | {
66
+ url: string;
67
+ };
68
+ tool_use_id?: string;
69
+ call_id?: string;
70
+ content?: unknown;
71
+ cache_control?: Record<string, unknown>;
72
+ [key: string]: unknown;
73
+ }
74
+ interface ResponsesMessageItem {
75
+ type?: 'message' | 'agentMessage';
76
+ role?: 'user' | 'assistant' | 'model' | 'system' | 'developer' | string;
77
+ content?: string | ResponsesContentPart[] | unknown;
78
+ reasoning_content?: string;
79
+ thought_signature?: string;
80
+ [key: string]: unknown;
81
+ }
82
+ interface ResponsesReasoningItem {
83
+ type: 'reasoning';
84
+ content?: Array<{
85
+ type?: string;
86
+ text?: string;
87
+ } | string> | string;
88
+ thought_signature?: string;
89
+ [key: string]: unknown;
90
+ }
91
+ interface ResponsesFunctionCallItem {
92
+ type: 'function_call';
93
+ id?: string;
94
+ call_id?: string;
95
+ name?: string;
96
+ arguments?: string | Record<string, unknown>;
97
+ [key: string]: unknown;
98
+ }
99
+ interface ResponsesFunctionCallOutputItem {
100
+ type: 'function_call_output';
101
+ id?: string;
102
+ call_id?: string;
103
+ output?: unknown;
104
+ [key: string]: unknown;
105
+ }
106
+ interface ResponsesLocalShellCallItem {
107
+ type: 'local_shell_call';
108
+ id?: string;
109
+ call_id?: string;
110
+ action?: {
111
+ type?: string;
112
+ exec?: {
113
+ command?: string[];
114
+ working_directory?: string;
115
+ };
116
+ command?: string[];
117
+ };
118
+ [key: string]: unknown;
119
+ }
120
+ interface ResponsesCommandExecutionItem {
121
+ type: 'commandExecution';
122
+ id?: string;
123
+ call_id?: string;
124
+ command?: string;
125
+ cwd?: string;
126
+ [key: string]: unknown;
127
+ }
128
+ interface ResponsesCommandExecutionOutputItem {
129
+ type: 'commandExecutionOutput';
130
+ id?: string;
131
+ call_id?: string;
132
+ output?: unknown;
133
+ stdout?: string;
134
+ stderr?: string;
135
+ [key: string]: unknown;
136
+ }
137
+ interface ResponsesCustomToolCallItem {
138
+ type: 'custom_tool_call';
139
+ id?: string;
140
+ call_id?: string;
141
+ name?: string;
142
+ input?: unknown;
143
+ [key: string]: unknown;
144
+ }
145
+ interface ResponsesCustomToolCallOutputItem {
146
+ type: 'custom_tool_call_output';
147
+ id?: string;
148
+ call_id?: string;
149
+ output?: unknown;
150
+ [key: string]: unknown;
151
+ }
152
+ interface ResponsesFileChangeItem {
153
+ type: 'fileChange';
154
+ id?: string;
155
+ call_id?: string;
156
+ changes?: Array<{
157
+ path?: string;
158
+ [k: string]: unknown;
159
+ }>;
160
+ [key: string]: unknown;
161
+ }
162
+ interface ResponsesFileChangeOutputItem {
163
+ type: 'fileChangeOutput';
164
+ id?: string;
165
+ call_id?: string;
166
+ output?: unknown;
167
+ [key: string]: unknown;
168
+ }
169
+ interface ResponsesWebSearchCallItem {
170
+ type: 'web_search_call';
171
+ id?: string;
172
+ call_id?: string;
173
+ action?: Record<string, unknown>;
174
+ [key: string]: unknown;
175
+ }
176
+ interface ResponsesTool {
177
+ type: 'function' | string;
178
+ name?: string;
179
+ description?: string;
180
+ parameters?: Record<string, unknown>;
181
+ strict?: boolean;
182
+ function?: {
183
+ name: string;
184
+ description?: string;
185
+ parameters?: Record<string, unknown>;
186
+ strict?: boolean;
187
+ };
188
+ [key: string]: unknown;
189
+ }
190
+ type ResponsesToolChoice = 'auto' | 'required' | 'none' | {
191
+ type: 'function';
192
+ function: {
193
+ name: string;
194
+ };
195
+ } | {
196
+ type: 'auto' | 'any';
197
+ } | null | undefined;
198
+ interface ResponsesReasoningConfig {
199
+ effort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | string;
200
+ summary?: string;
201
+ [key: string]: unknown;
202
+ }
203
+ interface ResponsesRequest {
204
+ model: string;
205
+ input?: ResponsesInputItem[] | string;
206
+ instructions?: string | Array<string | {
207
+ text?: string;
208
+ }>;
209
+ tools?: ResponsesTool[];
210
+ tool_choice?: ResponsesToolChoice;
211
+ temperature?: number;
212
+ top_p?: number;
213
+ max_output_tokens?: number;
214
+ max_tokens?: number;
215
+ stream?: boolean;
216
+ reasoning?: ResponsesReasoningConfig;
217
+ metadata?: Record<string, unknown>;
218
+ store?: boolean;
219
+ previous_response_id?: string | null;
220
+ [key: string]: unknown;
221
+ }
222
+ interface ResponsesOutputMessage {
223
+ id: string;
224
+ type: 'message';
225
+ role: 'assistant';
226
+ status: 'completed' | 'in_progress';
227
+ content: Array<{
228
+ type: 'output_text';
229
+ text: string;
230
+ } | {
231
+ type: string;
232
+ [k: string]: unknown;
233
+ }>;
234
+ }
235
+ interface ResponsesOutputFunctionCall {
236
+ id: string;
237
+ type: 'function_call' | 'local_shell_call' | string;
238
+ status: 'completed' | 'in_progress';
239
+ name?: string;
240
+ arguments?: string;
241
+ call_id?: string;
242
+ action?: {
243
+ type?: string;
244
+ command?: string[];
245
+ };
246
+ }
247
+ interface ResponsesOutputReasoning {
248
+ id: string;
249
+ type: 'reasoning';
250
+ summary: unknown[];
251
+ content: Array<{
252
+ type: 'reasoning_text';
253
+ text: string;
254
+ }>;
255
+ status?: 'completed' | 'in_progress';
256
+ }
257
+ type ResponsesOutputItem = ResponsesOutputMessage | ResponsesOutputFunctionCall | ResponsesOutputReasoning | Record<string, unknown>;
258
+ interface ResponsesUsage {
259
+ input_tokens: number;
260
+ output_tokens: number;
261
+ total_tokens: number;
262
+ input_tokens_details?: {
263
+ cached_tokens?: number;
264
+ cache_creation_tokens?: number;
265
+ };
266
+ }
267
+ interface ResponsesResponse {
268
+ id: string;
269
+ object: 'response';
270
+ created_at: number;
271
+ completed_at?: number;
272
+ model: string;
273
+ status: 'completed' | 'in_progress' | 'failed';
274
+ output: ResponsesOutputItem[];
275
+ usage?: ResponsesUsage;
276
+ temperature?: number;
277
+ top_p?: number;
278
+ tool_choice?: unknown;
279
+ tools?: unknown[];
280
+ parallel_tool_calls?: boolean;
281
+ store?: boolean;
282
+ metadata?: Record<string, unknown>;
283
+ [key: string]: unknown;
284
+ }
285
+ interface ResponsesStreamEvent {
286
+ id: string;
287
+ object: 'response.event';
288
+ type: string;
289
+ created_at: number;
290
+ sequence_number: number;
291
+ [key: string]: unknown;
292
+ }
293
+
294
+ /** Anthropic Messages API type definitions (subset). */
295
+ interface AnthropicTextBlock {
296
+ type: 'text';
297
+ text: string;
298
+ cache_control?: Record<string, unknown>;
299
+ }
300
+ interface AnthropicImageSource {
301
+ type: 'base64' | 'url';
302
+ media_type?: string;
303
+ data?: string;
304
+ url?: string;
305
+ }
306
+ interface AnthropicImageBlock {
307
+ type: 'image';
308
+ source: AnthropicImageSource;
309
+ cache_control?: Record<string, unknown>;
310
+ }
311
+ interface AnthropicDocumentBlock {
312
+ type: 'document';
313
+ source: AnthropicImageSource;
314
+ cache_control?: Record<string, unknown>;
315
+ }
316
+ interface AnthropicToolUseBlock {
317
+ type: 'tool_use';
318
+ id: string;
319
+ name: string;
320
+ input: Record<string, unknown>;
321
+ cache_control?: Record<string, unknown>;
322
+ }
323
+ interface AnthropicToolResultBlock {
324
+ type: 'tool_result';
325
+ tool_use_id: string;
326
+ content: string | AnthropicContentBlock[];
327
+ is_error?: boolean;
328
+ cache_control?: Record<string, unknown>;
329
+ }
330
+ interface AnthropicThinkingBlock {
331
+ type: 'thinking';
332
+ thinking: string;
333
+ signature?: string;
334
+ }
335
+ type AnthropicContentBlock = AnthropicTextBlock | AnthropicImageBlock | AnthropicDocumentBlock | AnthropicToolUseBlock | AnthropicToolResultBlock | AnthropicThinkingBlock | {
336
+ type: string;
337
+ [k: string]: unknown;
338
+ };
339
+ interface AnthropicMessage {
340
+ role: 'user' | 'assistant';
341
+ content: AnthropicContentBlock[] | string;
342
+ }
343
+ interface AnthropicTool {
344
+ name: string;
345
+ description?: string;
346
+ input_schema: Record<string, unknown>;
347
+ }
348
+ type AnthropicToolChoice = {
349
+ type: 'auto';
350
+ } | {
351
+ type: 'any';
352
+ } | {
353
+ type: 'tool';
354
+ name: string;
355
+ };
356
+ interface AnthropicThinkingConfig {
357
+ type: 'enabled' | 'disabled';
358
+ budget_tokens?: number;
359
+ }
360
+ interface AnthropicRequest {
361
+ model: string;
362
+ messages: AnthropicMessage[];
363
+ system?: string | AnthropicTextBlock[];
364
+ max_tokens: number;
365
+ temperature?: number;
366
+ top_p?: number;
367
+ tools?: (AnthropicTool | Record<string, unknown>)[];
368
+ tool_choice?: AnthropicToolChoice;
369
+ metadata?: Record<string, unknown>;
370
+ thinking?: AnthropicThinkingConfig;
371
+ stream?: boolean;
372
+ [k: string]: unknown;
373
+ }
374
+ interface AnthropicUsage {
375
+ input_tokens: number;
376
+ output_tokens: number;
377
+ cache_creation_input_tokens?: number;
378
+ cache_read_input_tokens?: number;
379
+ }
380
+ interface AnthropicResponse {
381
+ id: string;
382
+ type: 'message';
383
+ role: 'assistant';
384
+ model: string;
385
+ content: AnthropicContentBlock[];
386
+ stop_reason?: string;
387
+ stop_sequence?: string | null;
388
+ usage: AnthropicUsage;
389
+ }
390
+ /** Anthropic streaming SSE events. */
391
+ type AnthropicStreamEvent = {
392
+ type: 'message_start';
393
+ message: AnthropicResponse;
394
+ } | {
395
+ type: 'content_block_start';
396
+ index: number;
397
+ content_block: AnthropicContentBlock;
398
+ } | {
399
+ type: 'content_block_delta';
400
+ index: number;
401
+ delta: {
402
+ type: 'text_delta';
403
+ text: string;
404
+ } | {
405
+ type: 'thinking_delta';
406
+ thinking: string;
407
+ } | {
408
+ type: 'input_json_delta';
409
+ partial_json: string;
410
+ } | {
411
+ type: 'signature_delta';
412
+ signature: string;
413
+ } | {
414
+ type: string;
415
+ [k: string]: unknown;
416
+ };
417
+ } | {
418
+ type: 'content_block_stop';
419
+ index: number;
420
+ } | {
421
+ type: 'message_delta';
422
+ delta: Record<string, unknown>;
423
+ usage?: AnthropicUsage;
424
+ } | {
425
+ type: 'message_stop';
426
+ } | {
427
+ type: 'ping';
428
+ } | {
429
+ type: string;
430
+ [k: string]: unknown;
431
+ };
432
+
433
+ interface TranslateRequestOptions$1 {
434
+ /** Default max tokens when not provided (Anthropic requires `max_tokens`). */
435
+ defaultMaxTokens?: number;
436
+ /** Thinking budget overrides, keyed by effort. */
437
+ reasoningBudgets?: Partial<Record<'minimal' | 'low' | 'medium' | 'high' | 'xhigh', number>>;
438
+ }
439
+ interface TranslateRequestResult$1 {
440
+ request: AnthropicRequest;
441
+ hasPromptCache: boolean;
442
+ }
443
+ /** Convert a Responses API request into an Anthropic Messages API request. */
444
+ declare function translateRequest$1(data: ResponsesRequest, options?: TranslateRequestOptions$1): TranslateRequestResult$1;
445
+
446
+ interface TranslateResponseOptions$1 {
447
+ responseId?: string;
448
+ createdAt?: number;
449
+ model?: string;
450
+ }
451
+ /** Convert a non-streaming Anthropic response into a Responses-API response. */
452
+ declare function translateResponse$1(body: AnthropicResponse, options?: TranslateResponseOptions$1): ResponsesResponse;
453
+ declare function mapOutputItems(content: AnthropicContentBlock[]): ResponsesOutputItem[];
454
+
455
+ interface TranslateStreamOptions$1 {
456
+ model?: string;
457
+ responseId?: string;
458
+ createdAt?: number;
459
+ requestMetadata?: ResponsesStreamMetadata$1;
460
+ }
461
+ interface ResponsesStreamMetadata$1 {
462
+ temperature?: number;
463
+ top_p?: number;
464
+ tools?: unknown[];
465
+ tool_choice?: unknown;
466
+ store?: boolean;
467
+ metadata?: Record<string, unknown>;
468
+ }
469
+ /**
470
+ * Consume an Anthropic SSE stream and yield Responses-API SSE events.
471
+ */
472
+ declare function translateStream$1(stream: ReadableStream<Uint8Array>, options?: TranslateStreamOptions$1): AsyncGenerator<ResponsesStreamEvent, void, void>;
473
+ /**
474
+ * Consume an async iterable of parsed Anthropic events and yield Responses events.
475
+ */
476
+ declare function translateAnthropicEvents(events: AsyncIterable<AnthropicStreamEvent> | Iterable<AnthropicStreamEvent>, options?: TranslateStreamOptions$1): AsyncGenerator<ResponsesStreamEvent, void, void>;
477
+
478
+ declare const index$2_mapOutputItems: typeof mapOutputItems;
479
+ declare const index$2_translateAnthropicEvents: typeof translateAnthropicEvents;
480
+ declare namespace index$2 {
481
+ export { type ResponsesStreamMetadata$1 as ResponsesStreamMetadata, type TranslateRequestOptions$1 as TranslateRequestOptions, type TranslateRequestResult$1 as TranslateRequestResult, type TranslateResponseOptions$1 as TranslateResponseOptions, type TranslateStreamOptions$1 as TranslateStreamOptions, index$2_mapOutputItems as mapOutputItems, index$2_translateAnthropicEvents as translateAnthropicEvents, translateRequest$1 as translateRequest, translateResponse$1 as translateResponse, translateStream$1 as translateStream };
482
+ }
483
+
484
+ /**
485
+ * OpenAI chat/completions API type definitions (subset used by the openai-chat upstream format).
486
+ * Only the fields needed for request/response/stream translation are typed.
487
+ */
488
+ interface OpenAiChatToolCall {
489
+ id?: string;
490
+ type?: 'function' | string;
491
+ function?: {
492
+ name?: string;
493
+ arguments?: string | Record<string, unknown>;
494
+ };
495
+ }
496
+ interface OpenAiChatMessage {
497
+ role: 'system' | 'user' | 'assistant' | 'tool' | string;
498
+ content?: string | Array<{
499
+ type: string;
500
+ text?: string;
501
+ [k: string]: unknown;
502
+ }> | null;
503
+ name?: string;
504
+ tool_call_id?: string;
505
+ tool_calls?: OpenAiChatToolCall[];
506
+ reasoning_content?: string;
507
+ [key: string]: unknown;
508
+ }
509
+ interface OpenAiChatFunctionTool {
510
+ type: 'function';
511
+ function: {
512
+ name: string;
513
+ description?: string;
514
+ parameters?: Record<string, unknown>;
515
+ };
516
+ }
517
+ interface OpenAiChatWebSearchTool {
518
+ type: 'web_search';
519
+ web_search: {
520
+ enable: boolean;
521
+ search_engine?: string;
522
+ [k: string]: unknown;
523
+ };
524
+ }
525
+ type OpenAiChatTool = OpenAiChatFunctionTool | OpenAiChatWebSearchTool | Record<string, unknown>;
526
+ type OpenAiChatToolChoice = 'auto' | 'required' | 'none' | {
527
+ type: 'function';
528
+ function: {
529
+ name: string;
530
+ };
531
+ } | Record<string, unknown>;
532
+ interface OpenAiChatRequest {
533
+ model: string;
534
+ messages: OpenAiChatMessage[];
535
+ stream?: boolean;
536
+ temperature?: number;
537
+ top_p?: number;
538
+ max_tokens?: number;
539
+ tools?: OpenAiChatTool[];
540
+ tool_choice?: OpenAiChatToolChoice;
541
+ [key: string]: unknown;
542
+ }
543
+ interface OpenAiChatUsage {
544
+ prompt_tokens?: number;
545
+ completion_tokens?: number;
546
+ total_tokens?: number;
547
+ prompt_tokens_details?: {
548
+ cached_tokens?: number;
549
+ [key: string]: unknown;
550
+ };
551
+ [key: string]: unknown;
552
+ }
553
+ interface OpenAiChatChoice {
554
+ index?: number;
555
+ message: {
556
+ role?: string;
557
+ content?: string | null;
558
+ tool_calls?: OpenAiChatToolCall[];
559
+ reasoning_content?: string;
560
+ [key: string]: unknown;
561
+ };
562
+ finish_reason?: string;
563
+ [key: string]: unknown;
564
+ }
565
+ interface OpenAiChatResponse {
566
+ id?: string;
567
+ object?: string;
568
+ created?: number;
569
+ model?: string;
570
+ choices: OpenAiChatChoice[];
571
+ usage?: OpenAiChatUsage;
572
+ [key: string]: unknown;
573
+ }
574
+ interface OpenAiChatStreamDeltaToolCall {
575
+ index: number;
576
+ id?: string;
577
+ type?: string;
578
+ function?: {
579
+ name?: string;
580
+ arguments?: string | Record<string, unknown>;
581
+ };
582
+ }
583
+ interface OpenAiChatStreamDelta {
584
+ role?: string;
585
+ content?: string;
586
+ reasoning_content?: string;
587
+ tool_calls?: OpenAiChatStreamDeltaToolCall[];
588
+ [key: string]: unknown;
589
+ }
590
+ interface OpenAiChatStreamChoice {
591
+ index?: number;
592
+ delta?: OpenAiChatStreamDelta;
593
+ finish_reason?: string | null;
594
+ [key: string]: unknown;
595
+ }
596
+ interface OpenAiChatStreamChunk {
597
+ id?: string;
598
+ object?: string;
599
+ created?: number;
600
+ model?: string;
601
+ choices?: OpenAiChatStreamChoice[];
602
+ usage?: OpenAiChatUsage;
603
+ [key: string]: unknown;
604
+ }
605
+
606
+ interface TranslateRequestOptions {
607
+ /** Default max tokens when not provided. */
608
+ defaultMaxTokens?: number;
609
+ /** If true, backfill reasoning_content on assistant tool-call messages. */
610
+ backfillReasoning?: boolean;
611
+ /** Placeholder string for backfilled reasoning_content. Defaults to '.'. */
612
+ reasoningPlaceholder?: string;
613
+ /** If true, strip `strict` from function tools (some upstreams reject it). */
614
+ /** If true, drop image/file parts from user messages (e.g. DeepSeek text-only models). */
615
+ dropImages?: boolean;
616
+ }
617
+ interface TranslateRequestResult {
618
+ request: OpenAiChatRequest;
619
+ }
620
+ /** Convert a Responses API request into an OpenAI Chat API request. */
621
+ declare function translateRequest(data: ResponsesRequest, options?: TranslateRequestOptions): TranslateRequestResult;
622
+
623
+ interface TranslateResponseOptions {
624
+ responseId?: string;
625
+ createdAt?: number;
626
+ model?: string;
627
+ }
628
+ /** Convert an OpenAI Chat response into a Responses-API response. */
629
+ declare function translateResponse(body: OpenAiChatResponse, options?: TranslateResponseOptions): ResponsesResponse;
630
+
631
+ interface ResponsesStreamMetadata {
632
+ temperature?: number;
633
+ top_p?: number;
634
+ tools?: unknown[];
635
+ tool_choice?: unknown;
636
+ store?: boolean;
637
+ metadata?: Record<string, unknown>;
638
+ }
639
+ interface TranslateStreamOptions {
640
+ model?: string;
641
+ responseId?: string;
642
+ createdAt?: number;
643
+ requestMetadata?: ResponsesStreamMetadata;
644
+ }
645
+ /**
646
+ * Consume an OpenAI-chat-style SSE stream and yield Responses-API SSE events.
647
+ */
648
+ declare function translateStream(stream: ReadableStream<Uint8Array>, options?: TranslateStreamOptions): AsyncGenerator<ResponsesStreamEvent, void, void>;
649
+
650
+ type index$1_ResponsesStreamMetadata = ResponsesStreamMetadata;
651
+ type index$1_TranslateRequestOptions = TranslateRequestOptions;
652
+ type index$1_TranslateRequestResult = TranslateRequestResult;
653
+ type index$1_TranslateResponseOptions = TranslateResponseOptions;
654
+ type index$1_TranslateStreamOptions = TranslateStreamOptions;
655
+ declare const index$1_translateRequest: typeof translateRequest;
656
+ declare const index$1_translateResponse: typeof translateResponse;
657
+ declare const index$1_translateStream: typeof translateStream;
658
+ declare namespace index$1 {
659
+ export { type index$1_ResponsesStreamMetadata as ResponsesStreamMetadata, type index$1_TranslateRequestOptions as TranslateRequestOptions, type index$1_TranslateRequestResult as TranslateRequestResult, type index$1_TranslateResponseOptions as TranslateResponseOptions, type index$1_TranslateStreamOptions as TranslateStreamOptions, index$1_translateRequest as translateRequest, index$1_translateResponse as translateResponse, index$1_translateStream as translateStream };
660
+ }
661
+
662
+ /**
663
+ * Unified translation layer for Responses API.
664
+ *
665
+ * This module translates between OpenAI Responses API format and upstream
666
+ * API formats. You specify the upstream API format (`anthropic` or
667
+ * `openai-chat`) instead of a named provider.
668
+ *
669
+ * - `anthropic` → Anthropic Messages API
670
+ * - `openai-chat` → OpenAI-compatible Chat Completions API (OpenAI, ZAI, etc.)
671
+ */
672
+
673
+ type index_ResponsesRequest = ResponsesRequest;
674
+ type index_ResponsesResponse = ResponsesResponse;
675
+ type index_ResponsesStreamEvent = ResponsesStreamEvent;
676
+ declare namespace index {
677
+ export { type index_ResponsesRequest as ResponsesRequest, type index_ResponsesResponse as ResponsesResponse, type index_ResponsesStreamEvent as ResponsesStreamEvent, index$2 as anthropic, index$1 as openai };
678
+ }
679
+
680
+ /**
681
+ * SSE helpers.
682
+ *
683
+ * - `parseSseStream`: Consume a ReadableStream of bytes and yield parsed
684
+ * `{ event, data }` pairs. Works in both browser (fetch body) and Node 18+.
685
+ * - `encodeSseEvent`: Serialize a `{ event, data }` pair to the SSE wire format.
686
+ */
687
+ interface SseMessage {
688
+ event?: string;
689
+ data: string;
690
+ }
691
+ declare function parseSseStream(stream: ReadableStream<Uint8Array>): AsyncGenerator<SseMessage, void, void>;
692
+ declare function encodeSseEvent(event: string, data: unknown): string;
693
+
694
+ export { type AnthropicContentBlock, type AnthropicMessage, type AnthropicRequest, type AnthropicResponse, type AnthropicStreamEvent, type AnthropicTool, type AnthropicToolChoice, type AnthropicUsage, type CacheStats, type CreateResponsesFetchOptions, type OpenAiChatMessage, type OpenAiChatRequest, type OpenAiChatResponse, type OpenAiChatStreamChunk, type OpenAiChatTool, type OpenAiChatToolCall, type ResponsesContentPart, type ResponsesInputItem, type ResponsesOutputFunctionCall, type ResponsesOutputItem, type ResponsesOutputMessage, type ResponsesOutputReasoning, type ResponsesRequest, type ResponsesResponse, type ResponsesStreamEvent, type ResponsesTool, type ResponsesToolChoice, type ResponsesUsage, type SseMessage, type UpstreamFormat, createResponsesFetch, encodeSseEvent, parseSseStream, index as translate };