maestro-agent-sdk 0.1.37 → 0.1.39

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 (73) hide show
  1. package/README.md +55 -62
  2. package/dist/core/loop.d.ts.map +1 -1
  3. package/dist/core/loop.js +5 -43
  4. package/dist/core/loop.js.map +1 -1
  5. package/dist/index.d.ts +1 -5
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -6
  8. package/dist/index.js.map +1 -1
  9. package/dist/memory/aux-model-map.d.ts +2 -43
  10. package/dist/memory/aux-model-map.d.ts.map +1 -1
  11. package/dist/memory/aux-model-map.js +3 -85
  12. package/dist/memory/aux-model-map.js.map +1 -1
  13. package/dist/platform/config.d.ts +0 -7
  14. package/dist/platform/config.d.ts.map +1 -1
  15. package/dist/platform/config.js +0 -14
  16. package/dist/platform/config.js.map +1 -1
  17. package/dist/platform/version.d.ts +1 -1
  18. package/dist/platform/version.js +1 -1
  19. package/dist/provider.d.ts +12 -55
  20. package/dist/provider.d.ts.map +1 -1
  21. package/dist/provider.js +99 -156
  22. package/dist/provider.js.map +1 -1
  23. package/dist/registry.d.ts +6 -39
  24. package/dist/registry.d.ts.map +1 -1
  25. package/dist/registry.js +9 -76
  26. package/dist/registry.js.map +1 -1
  27. package/dist/sub-agent/runner.d.ts.map +1 -1
  28. package/dist/sub-agent/runner.js +0 -3
  29. package/dist/sub-agent/runner.js.map +1 -1
  30. package/dist/tools/builtin/bash.js +2 -2
  31. package/dist/tools/builtin/bash.js.map +1 -1
  32. package/dist/tools/builtin/bash_background.js +1 -1
  33. package/dist/tools/builtin/bash_background.js.map +1 -1
  34. package/dist/tools/builtin/gemini_image_qa.d.ts +12 -0
  35. package/dist/tools/builtin/gemini_image_qa.d.ts.map +1 -0
  36. package/dist/tools/builtin/gemini_image_qa.js +195 -0
  37. package/dist/tools/builtin/gemini_image_qa.js.map +1 -0
  38. package/dist/tools/builtin/read.d.ts.map +1 -1
  39. package/dist/tools/builtin/read.js +6 -6
  40. package/dist/tools/builtin/read.js.map +1 -1
  41. package/dist/tools/index.d.ts +1 -0
  42. package/dist/tools/index.d.ts.map +1 -1
  43. package/dist/tools/index.js +1 -0
  44. package/dist/tools/index.js.map +1 -1
  45. package/dist/types.d.ts +1 -1
  46. package/dist/types.d.ts.map +1 -1
  47. package/dist/types.js +2 -2
  48. package/dist/types.js.map +1 -1
  49. package/package.json +2 -24
  50. package/dist/providers/anthropic.d.ts +0 -328
  51. package/dist/providers/anthropic.d.ts.map +0 -1
  52. package/dist/providers/anthropic.js +0 -857
  53. package/dist/providers/anthropic.js.map +0 -1
  54. package/dist/providers/codex-auth.d.ts +0 -149
  55. package/dist/providers/codex-auth.d.ts.map +0 -1
  56. package/dist/providers/codex-auth.js +0 -332
  57. package/dist/providers/codex-auth.js.map +0 -1
  58. package/dist/providers/codex-stream.d.ts +0 -42
  59. package/dist/providers/codex-stream.d.ts.map +0 -1
  60. package/dist/providers/codex-stream.js +0 -345
  61. package/dist/providers/codex-stream.js.map +0 -1
  62. package/dist/providers/codex-translators.d.ts +0 -105
  63. package/dist/providers/codex-translators.d.ts.map +0 -1
  64. package/dist/providers/codex-translators.js +0 -244
  65. package/dist/providers/codex-translators.js.map +0 -1
  66. package/dist/providers/codex.d.ts +0 -234
  67. package/dist/providers/codex.d.ts.map +0 -1
  68. package/dist/providers/codex.js +0 -461
  69. package/dist/providers/codex.js.map +0 -1
  70. package/dist/providers/fallback.d.ts +0 -71
  71. package/dist/providers/fallback.d.ts.map +0 -1
  72. package/dist/providers/fallback.js +0 -223
  73. package/dist/providers/fallback.js.map +0 -1
@@ -1,244 +0,0 @@
1
- /**
2
- * Maestro ↔ Codex Responses API format translators.
3
- *
4
- * The Responses API is OpenAI's newer thread-style endpoint. It speaks a
5
- * different shape than Chat Completions:
6
- *
7
- * - Messages aren't a `messages` array — they're "input items" with
8
- * polymorphic types (`message`, `function_call`, `function_call_output`,
9
- * `reasoning`).
10
- * - Tools live as top-level items, not inside an assistant message.
11
- * - Text parts split by direction: user → `input_text`, assistant →
12
- * `output_text`. Mixing them yields 400.
13
- * - There is no `system` role; the instructions ride in a top-level
14
- * `instructions` field on the request body.
15
- *
16
- * This module owns those translations and nothing else — the provider class
17
- * stays focused on HTTP / streaming concerns.
18
- *
19
- * Hermes reference: `agent/codex_responses_adapter.py::_chat_messages_to_responses_input`
20
- * and `_responses_tools`. We diverge from hermes in two places:
21
- *
22
- * 1. We start from Maestro's Anthropic-shaped `ProviderContentBlock[]`, not
23
- * from OpenAI Chat Completions messages. Hermes does this conversion in
24
- * two hops (Anthropic → ChatCompletions → Responses); we do it in one to
25
- * keep the data path shorter and the type signatures honest.
26
- *
27
- * 2. We don't replay `codex_reasoning_items` / `codex_message_items` from
28
- * prior turns yet. Reasoning replay (with `encrypted_content`) is what
29
- * lets the Responses API maintain a coherent reasoning chain across
30
- * turns — but maestro's loop currently drops the encrypted blobs after
31
- * each turn, so there's nothing to replay. A future PR can extend
32
- * `ProviderContentBlock` with a `codex_encrypted_reasoning` variant and
33
- * wire the replay here.
34
- */
35
- export function translateToolsToResponses(tools) {
36
- if (!tools || tools.length === 0)
37
- return undefined;
38
- const out = [];
39
- for (const t of tools) {
40
- if (!t?.name || t.name.length === 0)
41
- continue;
42
- out.push({
43
- type: "function",
44
- name: t.name,
45
- description: t.description ?? "",
46
- strict: false,
47
- parameters: t.input_schema ?? {
48
- type: "object",
49
- properties: {},
50
- },
51
- });
52
- }
53
- return out.length > 0 ? out : undefined;
54
- }
55
- /**
56
- * Convert one Maestro message into one-or-more Responses input items.
57
- *
58
- * Why one message can produce multiple items:
59
- * - An assistant message with `text` + `tool_use` emits a `message` item AND
60
- * one `function_call` per tool_use, in that exact order.
61
- * - A user message with `tool_result` blocks emits a separate
62
- * `function_call_output` per result. Text/image blocks accompanying the
63
- * tool_results are flushed as their own `message` item before each result
64
- * so call-result ordering with surrounding text is preserved (matches
65
- * DeepSeek/Anthropic intent).
66
- */
67
- export function translateMessageToResponsesItems(msg) {
68
- // String-content fast path covers DeepSeek-style plain text replays.
69
- if (typeof msg.content === "string") {
70
- return [
71
- {
72
- type: "message",
73
- role: msg.role,
74
- content: msg.content,
75
- },
76
- ];
77
- }
78
- if (msg.role === "user") {
79
- return translateUserBlocks(msg.content);
80
- }
81
- return translateAssistantBlocks(msg.content);
82
- }
83
- function translateUserBlocks(blocks) {
84
- const out = [];
85
- let buffered = [];
86
- const flush = () => {
87
- if (buffered.length === 0)
88
- return;
89
- out.push({
90
- type: "message",
91
- role: "user",
92
- content: condenseUserParts(buffered),
93
- });
94
- buffered = [];
95
- };
96
- for (const block of blocks) {
97
- if (block.type === "text") {
98
- if (block.text.length > 0)
99
- buffered.push({ type: "input_text", text: block.text });
100
- }
101
- else if (block.type === "image") {
102
- const url = imageBlockToDataUrl(block.source);
103
- if (url)
104
- buffered.push({ type: "input_image", image_url: url });
105
- }
106
- else if (block.type === "document") {
107
- // Responses API doesn't accept PDF blocks directly at user message
108
- // level — placeholder so the model knows the attachment existed.
109
- // Caller should pre-extract text (e.g. via Read tool) for real content.
110
- buffered.push({
111
- type: "input_text",
112
- text: `[document ${block.source.media_type}; PDF not visible to GPT-5 directly — extract text first.]`,
113
- });
114
- }
115
- else if (block.type === "tool_result") {
116
- // tool_result MUST be its own item; flush any accumulated user content
117
- // first so ordering with surrounding text/image is preserved.
118
- flush();
119
- out.push({
120
- type: "function_call_output",
121
- call_id: block.tool_use_id,
122
- output: toolResultToResponsesOutput(block.content),
123
- });
124
- }
125
- // Other block types (tool_use, thinking) don't legally appear on user
126
- // messages — silently skip if encountered.
127
- }
128
- flush();
129
- return out;
130
- }
131
- function translateAssistantBlocks(blocks) {
132
- const out = [];
133
- const textParts = [];
134
- // Collect text first so the assistant message lands once, before any
135
- // function_calls. The Responses API doesn't require this order strictly
136
- // (it tolerates [function_call, message] too) but the matching chat-side
137
- // semantics are "the assistant said X, then called tool Y" — we keep that
138
- // narrative order in the replay.
139
- for (const block of blocks) {
140
- if (block.type === "text" && block.text.length > 0) {
141
- textParts.push({ type: "output_text", text: block.text });
142
- }
143
- // We could surface `thinking` blocks here as `reasoning` items, but doing
144
- // so without the `encrypted_content` blob the model originally produced
145
- // would just be plain-text reasoning the API treats as ordinary assistant
146
- // output — that hurts more than it helps (reveals chain-of-thought to
147
- // anything that later reads the rollout). Drop until we plumb encrypted
148
- // replay end-to-end.
149
- }
150
- if (textParts.length > 0) {
151
- out.push({ type: "message", role: "assistant", content: textParts });
152
- }
153
- for (const block of blocks) {
154
- if (block.type === "tool_use") {
155
- out.push({
156
- type: "function_call",
157
- call_id: block.id,
158
- name: block.name,
159
- arguments: JSON.stringify(block.input ?? {}),
160
- });
161
- }
162
- }
163
- return out;
164
- }
165
- /**
166
- * If a user message ends up as a single text part, collapse to a plain string
167
- * — keeps the wire shape predictable and avoids tripping any validator that
168
- * expects a string when no image is attached. Mixed / image-bearing messages
169
- * keep the array form. Mirrors DeepSeek's `condenseUserParts`.
170
- */
171
- function condenseUserParts(parts) {
172
- if (parts.length === 1 && parts[0].type === "input_text")
173
- return parts[0].text;
174
- return parts;
175
- }
176
- /**
177
- * Build a `data:<mime>;base64,<data>` URL from a Maestro image source. The
178
- * Responses API accepts either a hosted URL or a data URL — we always emit
179
- * the latter so the host doesn't need to publish a temporary URL.
180
- *
181
- * Returns `undefined` for malformed sources rather than throwing — the
182
- * containing message still flows, just without the image part.
183
- */
184
- function imageBlockToDataUrl(source) {
185
- if (source.type === "url" && source.url)
186
- return source.url;
187
- if (source.type === "base64" && source.data) {
188
- const mime = source.media_type ?? "image/png";
189
- return `data:${mime};base64,${source.data}`;
190
- }
191
- return undefined;
192
- }
193
- /**
194
- * Convert a `tool_result.content` value into the shape the Responses API
195
- * accepts inside `function_call_output.output`.
196
- *
197
- * - String → string (fast path; the majority of tools return plain text).
198
- * - Block array of only text → joined string (smaller wire payload).
199
- * - Mixed array (text + image) → structured array; image blocks become
200
- * `input_image` parts. Document blocks become a text placeholder for the
201
- * same reason as user-message documents.
202
- */
203
- function toolResultToResponsesOutput(content) {
204
- if (typeof content === "string")
205
- return content;
206
- const parts = [];
207
- for (const b of content) {
208
- if (b.type === "text") {
209
- parts.push({ type: "input_text", text: b.text });
210
- }
211
- else if (b.type === "image") {
212
- const url = imageBlockToDataUrl(b.source);
213
- if (url)
214
- parts.push({ type: "input_image", image_url: url });
215
- }
216
- else if (b.type === "document") {
217
- const bytes = b.source.data ? Math.floor((b.source.data.length * 3) / 4) : 0;
218
- parts.push({
219
- type: "input_text",
220
- text: `[document ${b.source.media_type} ${bytes} bytes — extract text first.]`,
221
- });
222
- }
223
- }
224
- // All-text → collapse to a single string for compactness.
225
- if (parts.every((p) => p.type === "input_text")) {
226
- return parts.map((p) => p.text).join("\n");
227
- }
228
- return parts;
229
- }
230
- /**
231
- * Top-level: translate the full Maestro message history into a flat array of
232
- * Responses input items. The `system` string is consumed by the provider into
233
- * the request's `instructions` field — it does NOT appear here.
234
- */
235
- export function translateMessagesToResponses(messages) {
236
- const out = [];
237
- for (const msg of messages) {
238
- for (const item of translateMessageToResponsesItems(msg)) {
239
- out.push(item);
240
- }
241
- }
242
- return out;
243
- }
244
- //# sourceMappingURL=codex-translators.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codex-translators.js","sourceRoot":"","sources":["../../src/providers/codex-translators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AA6BH,MAAM,UAAU,yBAAyB,CACvC,KAAgD;IAEhD,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACnD,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QAC9C,GAAG,CAAC,IAAI,CAAC;YACP,IAAI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CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7E,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,aAAa,CAAC,CAAC,MAAM,CAAC,UAAU,IAAI,KAAK,+BAA+B;aAC/E,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,0DAA0D;IAC1D,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,YAAY,CAAC,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAE,CAA0C,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAC1C,QAAoC;IAEpC,MAAM,GAAG,GAAyB,EAAE,CAAC;IACrC,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,KAAK,MAAM,IAAI,IAAI,gCAAgC,CAAC,GAAG,CAAC,EAAE,CAAC;YACzD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,234 +0,0 @@
1
- /**
2
- * CodexResponsesProvider — call OpenAI's Responses API through the ChatGPT
3
- * Codex backend using a `codex login` OAuth token.
4
- *
5
- * High-level shape:
6
- *
7
- * ┌────────────────────────┐ ┌──────────────────────────────────────┐
8
- * │ AIAgent loop │ │ CodexResponsesProvider │
9
- * │ ProviderMessage[] ─┼───▶│ - resolveAccessToken (refresh-aware)│
10
- * │ │ │ - translateMessagesToResponses │
11
- * │ │ │ - translateToolsToResponses │
12
- * │ │ │ - POST /responses (stream:true) │
13
- * │ ProviderStreamChunk ◀┼────│ - parseCodexStream │
14
- * └────────────────────────┘ └──────────────────────────────────────┘
15
- *
16
- * Pinned constraints (verified empirically against
17
- * `https://chatgpt.com/backend-api/codex/responses` on 2026-05-23):
18
- *
19
- * - **Stream is required**: non-streaming requests return
20
- * `400 {"detail":"Stream must be set to true"}`.
21
- * - **Model whitelist**: ChatGPT-account requests are limited to a small
22
- * set of codex-issued model slugs (`gpt-5.5`, `gpt-5.4`, `gpt-5.4-mini`,
23
- * `gpt-5.3-codex`, `gpt-5.2`, ...). Passing `gpt-5` returns 400 with
24
- * `not supported when using Codex with a ChatGPT account`.
25
- * - **Cloudflare headers required**: `originator: codex_cli_rs` plus a
26
- * codex-shaped `User-Agent` are mandatory on non-residential IPs.
27
- * - **`store: false`**: required when the rollout lives on the client side.
28
- * Without it, the server expects subsequent requests to look items up
29
- * by `id` and 404s when they can't.
30
- *
31
- * What this provider does NOT cover (deliberate scope cuts):
32
- *
33
- * - Reasoning chain replay across turns (would need `encrypted_content`
34
- * plumbed into the message history). Reasoning summaries flow through
35
- * as `thinking` blocks for the current turn only.
36
- * - Built-in hosted tools (`web_search`, `file_search`). Only
37
- * user-supplied function tools are wired.
38
- * - Token-bucket rate-limit handling. The backend rate-limits aggressively
39
- * for free accounts; surfacing a structured retry hint can be a follow-up.
40
- *
41
- * Hermes reference: `agent/transports/codex.py` + `_run_codex_stream`. We
42
- * implement the same wire contract using only `fetch` and the SSE parser in
43
- * `codex-stream.ts`, with no httpx / OpenAI SDK dependency.
44
- */
45
- import type { Provider, ProviderCompleteOptions, ProviderResponse, ProviderStreamChunk } from "../providers/base.js";
46
- import { type CodexAuthError } from "../providers/codex-auth.js";
47
- import { type ResponsesInputItem } from "../providers/codex-translators.js";
48
- import type { EffortLevel } from "../types.js";
49
- /**
50
- * Map maestro's `EffortLevel` to the Responses API `reasoning.effort` string.
51
- *
52
- * Codex backend accepts `low | medium | high | xhigh`. The 5-tier maestro
53
- * scale collapses as follows:
54
- * - `low` / `medium` / `high` → direct passthrough.
55
- * - `xhigh` → passthrough (Codex actually supports this tier on gpt-5.x).
56
- * - `max` → `xhigh`. Codex has no `max`; we pick the deepest tier the
57
- * backend exposes rather than silently dropping the user's intent.
58
- */
59
- export declare function effortForCodex(e: EffortLevel | undefined): string | undefined;
60
- export interface CodexProviderOptions {
61
- /** Override the Codex backend URL. Defaults to the ChatGPT-hosted
62
- * endpoint. The `/responses` suffix is appended automatically. */
63
- baseUrl?: string;
64
- /** Override the timeout for the OAuth refresh round-trip. The streaming
65
- * request itself uses `idleTimeoutMs` / `totalTimeoutMs` (see below) — the
66
- * agent loop also owns abort via signal. */
67
- refreshTimeoutMs?: number;
68
- /**
69
- * Skew window (seconds) for the refresh decision. When the cached access
70
- * token is within this many seconds of `exp`, the next provider call
71
- * refreshes before making the API request. Defaults to 5 minutes — large
72
- * enough to cover one long streaming turn without rolling over mid-stream.
73
- */
74
- refreshSkewSeconds?: number;
75
- /**
76
- * Socket *inactivity* timeout (ms) for the `/responses` stream. Resets on
77
- * every byte, so a healthy long stream is never cut — it only bounds the
78
- * time-to-first-byte (the gpt-5.* Codex backend buffers reasoning before
79
- * sending headers) and mid-stream stalls. This replaces the old reliance on
80
- * Bun's hard-coded ~300 s fetch ceiling (which `AbortSignal` could not raise;
81
- * see `node-fetch.ts`). Default 1_800_000 ms (30 min) — wide headroom above
82
- * Hermes' stale watchdog floor for large (>100K-token) contexts. Production showed gpt-5.5
83
- * TTFB hitting ~230 s on big bodies and a 240 s default false-cutting a
84
- * legitimately slow response, so we give wide headroom; a true hang is still
85
- * bounded by this idle window plus the `totalTimeoutMs` backstop.
86
- */
87
- idleTimeoutMs?: number;
88
- /**
89
- * Absolute wall-clock ceiling (ms) for the whole request + stream. The hard
90
- * backstop if the model keeps dribbling bytes forever. Default 5_400_000 ms
91
- * (90 min) — well above Hermes' `HERMES_API_TIMEOUT` default to allow very
92
- * long reasoning turns.
93
- */
94
- totalTimeoutMs?: number;
95
- /**
96
- * @deprecated Use `totalTimeoutMs`. Retained for back-compat: when set and
97
- * `totalTimeoutMs` is not, it is used as the total ceiling.
98
- */
99
- fetchTimeoutMs?: number;
100
- /**
101
- * Codex wire-diet: per-request cap (chars) on *older* tool outputs
102
- * (`function_call_output.output`) before the POST. The Codex ChatGPT backend
103
- * mandates `store: false` (verified: `store: true` → 400 "Store must be set
104
- * to false"), so the FULL conversation is re-uploaded on every tool
105
- * iteration — a 50KB file read keeps inflating every subsequent request body
106
- * (observed 200–550KB bodies, ~1 req/iteration, 10–16 iterations/turn). The
107
- * native `codex` binary and Hermes (`_INLINE_SHELL_MAX_OUTPUT = 4000`) keep
108
- * tool outputs small for exactly this reason. We trim only outputs OLDER than
109
- * `keepRecentToolOutputsFull` (the model still sees fresh results in full),
110
- * head+tail preserved with an elision marker. Does NOT mutate stored history
111
- * — wire-only, codex-only. Default 4_000 (aggressive, matches Hermes'
112
- * `_INLINE_SHELL_MAX_OUTPUT`). Set 0 / Infinity to disable. */
113
- toolOutputWireCapChars?: number;
114
- /**
115
- * Number of most-recent tool outputs kept at full size by the wire-diet
116
- * above. The current iteration's fresh tool results must survive intact so
117
- * the model can act on them. Default 2 (current + immediately-prior). */
118
- keepRecentToolOutputsFull?: number;
119
- /**
120
- * Compaction trigger ratio surfaced to the agent loop via the `Provider`
121
- * interface. Codex re-uploads the full conversation every tool iteration
122
- * (store:false, no caching), so it compacts EARLIER than the cross-provider
123
- * default (0.6). Default 0.35 → threshold = contextWindow × 0.35 (e.g. ~70K at
124
- * a 200K window vs 120K at 0.6) so codex compacts well before the body grows
125
- * heavy. Set to match the cross-provider default to opt out. */
126
- compactionTriggerRatio?: number;
127
- /**
128
- * Tail-protect surfaced via `Provider.compactionTailProtect`. Codex keeps a
129
- * shorter verbatim tail (default 4 vs the compressor's 6) so each compaction
130
- * folds more of the middle into the summary — Hermes-style harder squeeze,
131
- * keeping the re-uploaded residual small. */
132
- compactionTailProtect?: number;
133
- }
134
- /**
135
- * Provider implementation. Construct once per process; safe to share across
136
- * concurrent agent turns (token refresh is best-effort idempotent under the
137
- * skew check + on-disk persistence).
138
- */
139
- export declare class CodexResponsesProvider implements Provider {
140
- private readonly baseUrl;
141
- private readonly refreshTimeoutMs;
142
- private readonly refreshSkewSeconds;
143
- private readonly idleTimeoutMs;
144
- private readonly totalTimeoutMs;
145
- private readonly toolOutputWireCapChars;
146
- private readonly keepRecentToolOutputsFull;
147
- /** Surfaced to the agent loop (see `Provider.compactionTriggerRatio`). Codex
148
- * compacts earlier than cache-friendly providers because it re-uploads the
149
- * whole conversation every iteration. */
150
- readonly compactionTriggerRatio: number;
151
- /** Surfaced via `Provider.compactionTailProtect`. Shorter tail than the
152
- * compressor default so codex compactions fold more of the middle. */
153
- readonly compactionTailProtect: number;
154
- /** Surfaced via `Provider.guidedCompaction`. Codex opts into focus-steered
155
- * compaction (active task preserved in full); other providers don't. */
156
- readonly guidedCompaction = true;
157
- constructor(opts?: CodexProviderOptions);
158
- /**
159
- * Build the `nodeFetch` init shared by the initial POST and the 401-refresh
160
- * retry. We route through `node:http` (not Bun's global `fetch`) because Bun
161
- * caps `fetch` at a hard, unconfigurable ~300 s; `AbortSignal` can only
162
- * shorten that, never raise it (see `node-fetch.ts` for the empirical proof).
163
- * The two-layer timeout (idle + total) is honored by node:http, and the
164
- * caller's `abortSignal` still wins immediately for user cancels.
165
- */
166
- private buildFetchInit;
167
- /**
168
- * Factory parity with `DeepseekProvider.fromEnv()` — for Codex the "env"
169
- * inputs are really the on-disk `~/.codex/auth.json` (no API key env var
170
- * makes sense for OAuth). The factory still throws early if the auth file
171
- * is missing or stale, so a host can fail fast at startup instead of on
172
- * the first user message.
173
- */
174
- static fromEnv(opts?: CodexProviderOptions): CodexResponsesProvider;
175
- /**
176
- * Streaming entry point. The Codex backend rejects non-streaming requests
177
- * outright, so this is the load-bearing method — `complete()` is just a
178
- * convenience wrapper around it.
179
- */
180
- stream(opts: ProviderCompleteOptions): AsyncGenerator<ProviderStreamChunk>;
181
- /**
182
- * Non-streaming entry point. The Codex backend doesn't support
183
- * `stream: false`, so we drain `stream()` into a single `ProviderResponse`.
184
- * Callers that want progressive UI updates should use `stream()` directly.
185
- *
186
- * The reconstruction follows DeepseekProvider's convention:
187
- * - text deltas collapse into one `text` content block per stream;
188
- * - tool_use_start + tool_use_input_delta + tool_use_complete bundle
189
- * into one `tool_use` block with parsed JSON args;
190
- * - thinking_complete blocks are forwarded verbatim.
191
- *
192
- * Block order in the returned `content`: thinking → text → tool_use,
193
- * matching the assistant-history convention the loop expects on replay.
194
- */
195
- complete(opts: ProviderCompleteOptions): Promise<ProviderResponse>;
196
- }
197
- /**
198
- * Build the JSON body the Responses API expects.
199
- *
200
- * Notable fields:
201
- * - `instructions`: maestro's `system` string. The Responses API has no
202
- * `system` role; this slot is the canonical place for persona / global
203
- * constraints.
204
- * - `input`: the message history as Responses input items
205
- * (translateMessagesToResponses).
206
- * - `tools` / `tool_choice` / `parallel_tool_calls`: standard.
207
- * - `store: false`: keep the conversation client-side. With `store: true`
208
- * the server expects subsequent requests to reference earlier items
209
- * by ID and 404s when they don't — incompatible with maestro's
210
- * stateless turn model.
211
- * - `stream: true`: required; non-streaming returns 400.
212
- * - `reasoning`: only emitted when the caller picked an effort tier.
213
- * We always include `summary: "auto"` so the model surfaces a
214
- * human-readable reasoning trace alongside the encrypted content.
215
- * - `include: ["reasoning.encrypted_content"]`: makes the encrypted
216
- * reasoning blob available in `output_item.done` payloads. We don't
217
- * replay it yet, but capturing it now keeps the future replay path
218
- * a translator change rather than another wire change.
219
- */
220
- /**
221
- * Codex wire-diet. Trims `function_call_output.output` for tool results OLDER
222
- * than the `keepRecent` most recent ones, preserving head+tail with an elision
223
- * marker. Pure function over the input-item array; the caller's stored message
224
- * history is untouched (this only shrinks the bytes on the wire).
225
- *
226
- * Why only `function_call_output`: it's a free-form string, safe to truncate.
227
- * We deliberately do NOT touch `function_call.arguments` — that's a JSON string
228
- * the backend may parse, and mid-string truncation would corrupt it.
229
- */
230
- export declare function dietToolOutputs(input: ResponsesInputItem[], capChars: number, keepRecent: number): ResponsesInputItem[];
231
- export { CodexAuthError } from "../providers/codex-auth.js";
232
- export type { CodexProviderOptions as _CodexProviderOptions };
233
- export type _CodexAuthError = CodexAuthError;
234
- //# sourceMappingURL=codex.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/providers/codex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAGH,OAAO,KAAK,EACV,QAAQ,EACR,uBAAuB,EAEvB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,cAAc,EAAyC,MAAM,wBAAwB,CAAC;AAEpG,OAAO,EACL,KAAK,kBAAkB,EAGxB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,SAAS,CAAC;AAOvD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAe7E;AAED,MAAM,WAAW,oBAAoB;IACnC;uEACmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;iDAE6C;IAC7C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;;;;;mEAY+D;IAC/D,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;6EAGyE;IACzE,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC;;;;;;oEAMgE;IAChE,sBAAsB,CAAC,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