@askalf/dario 6.2.0 → 6.3.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,108 @@
1
+ /**
2
+ * Inbound OpenAI Responses API (v6.3) — `POST /v1/responses` on dario.
3
+ *
4
+ * Codex CLI 0.154 dropped `wire_api = "chat"` (openai/codex discussion 7782):
5
+ * a custom provider must speak the Responses API or it cannot be used at all.
6
+ * The OpenAI Agents SDK and everything newer from OpenAI speak the same shape.
7
+ * This module makes dario a Responses endpoint, so those clients run on a
8
+ * Claude subscription — and on a ChatGPT one, through the codex leg.
9
+ *
10
+ * Shape of the work: the request is translated ONCE at the front door into
11
+ * the Anthropic Messages body every other dario path already understands
12
+ * (`responsesRequestToAnthropic`), the request then runs as an ordinary
13
+ * Anthropic-shape request — pool, template, codex leg, mid-stream
14
+ * continuation, all of it — and every byte written back to the client passes
15
+ * through `ResponsesOut`, which turns Anthropic SSE (or a buffered Anthropic
16
+ * message, or an Anthropic error body) into the Responses wire shape. Nothing
17
+ * downstream of the front door knows the client is a Responses client.
18
+ *
19
+ * The reverse direction — an Anthropic-shape request served by the codex
20
+ * backend — has lived in anthropic-responses-translate.ts since 5.5.87. The
21
+ * two translators share types and nothing else on purpose: each direction is
22
+ * read against the wire captures that motivated it.
23
+ *
24
+ * What is dropped, and said so once per process at verbose: hosted tool types
25
+ * the pool cannot run (`web_search`, `file_search`, `mcp`, …), `reasoning`
26
+ * items on the way in (the encrypted content is OpenAI's, and the pool does
27
+ * not need them back), `text.format`, `previous_response_id` (dario is
28
+ * stateless; a 400, not a silent ignore).
29
+ */
30
+ import type { ServerResponse } from 'node:http';
31
+ export interface InboundTranslation {
32
+ body: Record<string, unknown>;
33
+ /** Things that did not survive the translation, one line each. */
34
+ warnings: string[];
35
+ /**
36
+ * Request features the Messages shape has no honest answer for — the
37
+ * route that serves the request decides what to do: the codex passthrough
38
+ * forwards the original body and never sees this; the Claude pool answers
39
+ * a 400 naming the field rather than silently ignoring it.
40
+ */
41
+ unsupported: string[];
42
+ }
43
+ export declare class ResponsesRequestError extends Error {
44
+ readonly param?: string | undefined;
45
+ constructor(message: string, param?: string | undefined);
46
+ }
47
+ /**
48
+ * The Responses request as the Anthropic Messages body the rest of dario
49
+ * serves. Throws ResponsesRequestError for shapes that cannot be served
50
+ * honestly (no model, no input, `previous_response_id`).
51
+ */
52
+ export declare function responsesRequestToAnthropic(req: Record<string, unknown>): InboundTranslation;
53
+ /** The 400 the Claude pool answers for a Responses feature it cannot serve. */
54
+ export declare function unsupportedOnClaudeError(field: string): Record<string, unknown>;
55
+ /** A buffered Anthropic message → a Responses response object. */
56
+ export declare function anthropicMessageToResponses(msg: Record<string, unknown>, createdAt?: number): Record<string, unknown>;
57
+ /** An Anthropic error body → the OpenAI error envelope. */
58
+ export declare function anthropicErrorToResponses(body: Record<string, unknown>): Record<string, unknown>;
59
+ /**
60
+ * Anthropic SSE → Responses SSE, incrementally. One instance per response.
61
+ * Comments (`: dario continuation …`) ride through untouched; `ping` is
62
+ * dropped; `error` becomes `response.failed` + an `error` event.
63
+ */
64
+ export declare class ResponsesOutStream {
65
+ private seq;
66
+ private id;
67
+ private createdAt;
68
+ private model;
69
+ private started;
70
+ private readonly output;
71
+ private readonly open;
72
+ private usage;
73
+ private stopReason;
74
+ private done;
75
+ private readonly splitter;
76
+ constructor(requestModel: string);
77
+ private ev;
78
+ private snapshot;
79
+ feed(chunk: string | Uint8Array): string;
80
+ /** Whatever is still buffered (a partial frame) — nothing a Responses client can use. */
81
+ end(): string;
82
+ get finished(): boolean;
83
+ private frame;
84
+ private blockStart;
85
+ private blockDelta;
86
+ private blockStop;
87
+ }
88
+ /**
89
+ * Everything dario writes to a Responses client passes through here. The
90
+ * first bytes decide the mode: SSE frames are translated as they arrive; a
91
+ * JSON body (a buffered message, or an error) is held and translated at end().
92
+ */
93
+ export declare class ResponsesOut {
94
+ private mode;
95
+ private json;
96
+ private readonly stream;
97
+ private readonly decoder;
98
+ constructor(requestModel: string);
99
+ write(chunk: string | Uint8Array): string;
100
+ end(): string;
101
+ }
102
+ /**
103
+ * The ServerResponse a Responses client is served through: every write is
104
+ * translated, everything else reaches the real response untouched (headers,
105
+ * events, `writableEnded`, `destroyed`). Bound methods, so `res.on('close')`
106
+ * and friends keep working on the real object.
107
+ */
108
+ export declare function wrapResponsesClient(res: ServerResponse, out: ResponsesOut): ServerResponse;