mixdog 1.4.3 → 1.4.4

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 (80) hide show
  1. package/package.json +1 -1
  2. package/src/defaults/shipped-history.json +4 -0
  3. package/src/defaults/skills/computer-use/SKILL.md +14 -3
  4. package/src/defaults/skills/memory-management/SKILL.md +10 -5
  5. package/src/defaults/skills/setup/references/actions.md +1 -1
  6. package/src/rules/agent-mode/MIXY.md +5 -3
  7. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +2 -1
  8. package/src/runtime/agent/orchestrator/providers/anthropic-api-request.mjs +11 -1
  9. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-start.mjs +4 -0
  10. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-outcome.mjs +2 -0
  11. package/src/runtime/agent/orchestrator/providers/anthropic-turn-result.mjs +2 -0
  12. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +2 -0
  13. package/src/runtime/agent/orchestrator/providers/custom-provider-config.mjs +121 -9
  14. package/src/runtime/agent/orchestrator/providers/custom-provider.mjs +4 -1
  15. package/src/runtime/agent/orchestrator/providers/lib/generation-window.mjs +9 -0
  16. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-send.mjs +9 -1
  17. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-result.mjs +2 -0
  18. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-state.mjs +5 -0
  19. package/src/runtime/agent/orchestrator/providers/openai-compat-options.mjs +3 -0
  20. package/src/runtime/agent/orchestrator/providers/openai-compat-response-normalization.mjs +2 -0
  21. package/src/runtime/agent/orchestrator/providers/openai-compat-responses.mjs +10 -1
  22. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events.mjs +3 -0
  23. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-outcome.mjs +2 -0
  24. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state.mjs +9 -2
  25. package/src/runtime/agent/orchestrator/providers/openrouter-provider-routing.mjs +28 -0
  26. package/src/runtime/agent/orchestrator/providers/openrouter.mjs +4 -1
  27. package/src/runtime/agent/orchestrator/providers/registry.mjs +30 -25
  28. package/src/runtime/agent/orchestrator/runtime-core/ask-user-result.mjs +66 -0
  29. package/src/runtime/agent/orchestrator/session/manager/runtime-liveness.mjs +8 -1
  30. package/src/runtime/agent/orchestrator/session/store.mjs +12 -6
  31. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-output-silence.mjs +64 -0
  32. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-task-output.mjs +20 -6
  33. package/src/runtime/agent/orchestrator/tools/builtin/task-tool.mjs +12 -1
  34. package/src/runtime/channels/lib/routines-db.mjs +35 -0
  35. package/src/runtime/channels/lib/schedules-db.mjs +4 -0
  36. package/src/runtime/channels/lib/webhooks-db.mjs +4 -0
  37. package/src/runtime/computer-bridge/action-schema.mjs +2 -2
  38. package/src/runtime/computer-bridge/core-actions.mjs +16 -2
  39. package/src/runtime/computer-bridge/result-canonical.mjs +6 -0
  40. package/src/runtime/memory/tool-defs.mjs +1 -1
  41. package/src/runtime/shared/llm/usage-accounting.mjs +110 -19
  42. package/src/runtime/shared/llm/usage-context.mjs +1 -1
  43. package/src/runtime/shared/llm/usage-ledger-quota.mjs +2 -0
  44. package/src/runtime/shared/llm/usage-ledger-requests.mjs +183 -0
  45. package/src/runtime/shared/llm/usage-ledger-rollup.mjs +7 -3
  46. package/src/runtime/shared/llm/usage-ledger-worker.mjs +2 -0
  47. package/src/runtime/shared/llm/usage-ledger.mjs +57 -1
  48. package/src/runtime/shared/llm/usage-request-status.mjs +48 -0
  49. package/src/runtime/shared/tool-result-summary.mjs +1 -1
  50. package/src/session-runtime/agent-home-delivery.mjs +76 -8
  51. package/src/session-runtime/agent-task-sessions.mjs +63 -22
  52. package/src/session-runtime/boot/apis.mjs +15 -0
  53. package/src/session-runtime/boot/tools.mjs +8 -2
  54. package/src/session-runtime/internal-tool-executor/ask-user-tool.mjs +3 -58
  55. package/src/session-runtime/model-route/route-persist.mjs +12 -4
  56. package/src/session-runtime/provider-models/row-hydration.mjs +2 -0
  57. package/src/session-runtime/routine-owner.mjs +9 -3
  58. package/src/session-runtime/services/agent-task-status.mjs +29 -1
  59. package/src/session-runtime/services/agent-tool/job-views/session-progress.mjs +3 -0
  60. package/src/session-runtime/services/agent-tool/render.mjs +6 -1
  61. package/src/session-runtime/services/channel-admin.mjs +44 -3
  62. package/src/session-runtime/services/plugin-admin.mjs +46 -7
  63. package/src/session-runtime/services/provider-admin.mjs +5 -0
  64. package/src/session-runtime/setup-tool/agent-settings-actions.mjs +1 -1
  65. package/src/session-runtime/setup-tool/executor.mjs +1 -1
  66. package/src/session-runtime/setup-tool/extended-actions.mjs +1 -1
  67. package/src/session-runtime/setup-tool/settings-contract.mjs +2 -2
  68. package/src/session-runtime/usage-stats-api.mjs +117 -1
  69. package/src/session-runtime/workflow-agents-api/agent-connectors.mjs +36 -29
  70. package/src/session-runtime/workflow-agents-api/agent-editor.mjs +183 -23
  71. package/src/standalone/session-protocol.mjs +1 -0
  72. package/src/standalone/session-service/retention/busy.mjs +3 -2
  73. package/src/tui/app/model-picker/model-footer.mjs +1 -1
  74. package/src/tui/app/model-picker/provider-models-list.mjs +7 -3
  75. package/src/tui/app/model-picker/route-selection/fast-parameters.mjs +23 -3
  76. package/src/tui/app/model-picker/route-selection.mjs +1 -0
  77. package/src/tui/dist/index.mjs +41 -7
  78. package/src/tui/session/session-api/integrations.mjs +3 -0
  79. package/src/tui/session/tool-approval-settle.mjs +24 -4
  80. package/src/tui/session/tool-approval.mjs +35 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mixdog",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Open-source coding agent that matches Codex on Terminal-Bench 2.1 with 63% fewer tokens.",
@@ -247,6 +247,7 @@
247
247
  "27135bd0ba3468258d3b43c752501929",
248
248
  "398b50b687206544149feeb0a5b02c09",
249
249
  "3f8b7b4cd798dba866eccd7d09c76248",
250
+ "45534843b3a94a6ab2c6bb5f141c5133",
250
251
  "733d30c3ca6745c96a69f7e237f3d8c0",
251
252
  "75bdf20949f1e125f82b51ebca6a2ab4",
252
253
  "7b9ce58540ed4609f290dc981a7e1719",
@@ -264,6 +265,7 @@
264
265
  "e10367dd4291a0b3d8ee8e8dd60eae36",
265
266
  "e1f2526aaf123fb77072aa8975f890de",
266
267
  "e67f30ec5bbdd36d7feaabd35b7504b3",
268
+ "e84164eff9dc833fc52f24bd33ecd699",
267
269
  "edc3519cf07e37702a5793bb23e0643c",
268
270
  "f0798c546c172a742e3384d82322ede4"
269
271
  ],
@@ -326,6 +328,7 @@
326
328
  "1533630b81ebace2bc9ece6fda02bb11",
327
329
  "261a34fce0fb0f73abfd1b1e2add3602",
328
330
  "356bf57f7087fe2c40c5dcd99622c3e9",
331
+ "427128f8cd113299422ccd395194b272",
329
332
  "a8ffffd02f438cdd6005e09cfe6cf42f",
330
333
  "aad47f68614152e4b338cf3684f72304"
331
334
  ],
@@ -419,6 +422,7 @@
419
422
  "ade615dd0f6ae6ed1601023e5b9cb692",
420
423
  "b21681ecfeb523c0d7dd89a299ec05a9",
421
424
  "b4f9c79dcb08151e6275b5ee35c2bca4",
425
+ "b96f637e5a5acc2406fb1922f7004291",
422
426
  "bca9732a1cecd2ce3a26e905b57d3b25",
423
427
  "c6db973f51166fc42814808ae0001797",
424
428
  "c82197acd9111f4a6dcda24baccffb86",
@@ -70,6 +70,9 @@ GNOME with Mixdog's own shell extension, which the app sets up); prefer accessib
70
70
  decorates the real pointer. Visual feedback is not proof of action success.
71
71
  A background semantic action may queue behind foreground work to protect
72
72
  focus; waiting for that guard never switches its delivery mode.
73
+ On Chromium and Electron targets a background semantic action can briefly
74
+ bring the target forward; one guarded attempt then tries to put the user's
75
+ window back, and it is skipped when the user has acted meanwhile.
73
76
  - **Foreground (explicit):** use when the target/gesture requires real pointer
74
77
  or keyboard focus, background is known unsupported, or the user requests a
75
78
  visible demonstration. A click or drag is not automatically foreground:
@@ -204,13 +207,21 @@ refs still work.
204
207
 
205
208
  ## Waiting and verification
206
209
 
207
- - `wait` inside `act` is only a short settle (5 s each, 10 s total).
210
+ - Every `act` already settles and re-observes, so add no trailing `wait`.
211
+ Use `wait` inside `act` only for a known async delay (5 s each, 10 s total):
212
+ it is a fixed pause. `quiet:true` ends it early once the window set,
213
+ foreground, title and bounds stop changing; use it when waiting for a window
214
+ or dialog to open, close or move. It does not see content changes inside a
215
+ window (canvas, text): a real condition is a `verify`.
208
216
  - `wait_for_user` waits for control to return, without holding the input queue.
209
217
  Read its status: a successful tool response alone does not mean it resumed.
210
218
  - For anything longer use `verify`: AND-combined predicates (`present`,
211
219
  `absent`, `title_contains`, `window_exists`) with `timeout_ms` and
212
220
  `stable_samples`. It reads state only, so prior refs stay valid.
213
221
  - Never loop on `capture` to poll; `verify` is the bounded wait.
222
+ - `verify` stops early with `unknown` and an `unknown_reason` when the window's
223
+ tree is cached unusable or its reads keep timing out; do not rerun it
224
+ unchanged.
214
225
  - `unknown` means the observation could not prove the condition. In particular,
215
226
  empty, truncated, or failed accessibility reads do not prove text is absent.
216
227
 
@@ -256,8 +267,8 @@ surface `computer`); one-time codes, passkeys, security keys and app approvals
256
267
  are the user's step (`handoff_user` kind `takeover`). Never type a password or
257
268
  code with `type`/`set_value`, even one shown on screen.
258
269
 
259
- **Keyboard-driven navigation** — `act` with `key` steps such as `ctrl+s`
260
- and a trailing short `wait`; verify with `verify` rather than another capture.
270
+ **Keyboard-driven navigation** — `act` with `key` steps such as `ctrl+s`;
271
+ the act settles itself. Verify with `verify` rather than another capture.
261
272
  `alt+f4` is blocked in every delivery mode. To close a window, obtain the
262
273
  user's go-ahead and use `window` with the `close` operation.
263
274
 
@@ -22,16 +22,21 @@ Current repository state belongs to repository tools, not memory.
22
22
  ## Curate standing memory
23
23
 
24
24
  Store only user-specific preferences and constraints, as compact English
25
- statements. Before adding or editing one, show its exact content
26
- and scope and obtain approval. An explicit request for that exact change
27
- already supplies approval.
25
+ statements. When the user asks you to remember something, save it and report
26
+ the exact text and scope you saved. An entry you propose yourself, or one
27
+ whose scope is unclear, waits for the user's approval first.
28
28
 
29
29
  Never turn inferred lessons into standing instructions or duplicate profile,
30
30
  settings, rules, tool contracts, or skills. Do not save ordinary task outcomes
31
31
  as preferences; automatic history already preserves them.
32
32
 
33
- Omit `project_id` for the current Project, use `common` for shared memory,
34
- or an explicit Project slug for another Project. The `*` scope is read-only.
33
+ Pick the scope by what the entry is about, not where the conversation is:
34
+ `common` when it holds in any Project (how to address or answer the user,
35
+ approvals, git and release habits, general working style); a Project only
36
+ when it depends on that Project's code, paths, tools or conventions. Omit
37
+ `project_id` for the current Project, or name another Project's slug. The `*`
38
+ scope is read-only. Write each entry so it reads alone, without pointing at
39
+ earlier conversation or entries.
35
40
  `agent_id: "self"` selects your own agent memory instead: only you read it,
36
41
  and it is the only pool an unattended run (schedule, webhook, group room,
37
42
  delegated agent) may write; common and Project memory change only while the
@@ -376,7 +376,7 @@ markers are read with `status desktop`.
376
376
  to set both; and `colorTheme`
377
377
  (an imported theme id from `status appearance` `colorThemes`, or `"builtin"`).
378
378
  Also `timeFormat` (system|12h|24h), `sidePanelPosition` (right|bottom|auto),
379
- `uiScale` (0.85–1.2, step 0.05), `codeSize` (10–20), `codeLigatures`
379
+ `uiScale` (0.85–1.5, step 0.05), `codeSize` (10–20), `codeLigatures`
380
380
  (bool) and `chatTextSize` (small|default|large|extra-large). Also
381
381
  `composerStyle` (simple|basic|detail; the UI label "Normal" is `basic`) and
382
382
  `questionAnswerConfirm` (bool: a single-choice pick waits for Send/Next).
@@ -18,9 +18,11 @@
18
18
  session run by Lead and agents is "agent mode" (에이전트 모드). A session
19
19
  you start with `session create` is an "agent task session" (에이전트 작업
20
20
  세션); any other is a "session" (세션). Use those words with the user.
21
- - You coordinate the user's bots and agents: route each request to the one
22
- best suited for it (a bot, a sub-agent, or an agent task session for a
23
- big multi-step plan).
21
+ - You coordinate the user's bots and agents. What you can settle in this
22
+ reply with a few quick lookups, you answer yourself. Work that needs its
23
+ own investigation or writing and a report back goes to the bot whose role
24
+ fits it (Bots), or to a sub-agent when no bot's role fits; an agent task
25
+ session only for a big multi-step plan.
24
26
  - Asked how the bots are doing, what they did or what is pending, call
25
27
  `session` action `bots` first (with a bot's id for its recent sessions) and
26
28
  answer from it. Each bot's chat is `sess_home_<id>`; `session read` opens it.
@@ -601,7 +601,8 @@ export function wrapProviderAdmission(provider, providerName, scheduler = provid
601
601
  return accountProviderSend(
602
602
  providerName,
603
603
  this,
604
- () => originalSend.call(this, messages, model, tools, admittedOpts),
604
+ // Accounting hands back the options with its first-output probe.
605
+ (accountedOpts) => originalSend.call(this, messages, model, tools, accountedOpts),
605
606
  model,
606
607
  admittedOpts
607
608
  );
@@ -20,6 +20,7 @@ import { applyAnthropicServerFallback } from './anthropic-server-fallback.mjs';
20
20
  import { fastModeAvailable } from './anthropic-fast-mode.mjs';
21
21
  import { applyAnthropicEffortToBody, shouldIncludeEffortBeta } from './anthropic-effort.mjs';
22
22
  import { isCustomProviderName, resolveCustomReasoning } from './custom-reasoning.mjs';
23
+ import { applyCustomRequestBody, customRequestHeaders } from './custom-provider-config.mjs';
23
24
  import {
24
25
  anthropicThinkingActive,
25
26
  anthropicTurnScopedReminders,
@@ -73,6 +74,8 @@ export async function buildAnthropicApiRequest({
73
74
  capabilityModel = useModel,
74
75
  // A gateway-supplied output limit for the model; wins over the Anthropic catalog.
75
76
  modelMaxOutputTokens = opts?.modelMaxOutputTokens ?? null,
77
+ // A custom provider's normalized config: its extra request JSON and headers.
78
+ customConfig = null,
76
79
  }) {
77
80
  // A user-defined provider's reasoning comes from its own model row only:
78
81
  // the global by-model-id capability index and the Claude-id ladders are
@@ -171,6 +174,11 @@ export async function buildAnthropicApiRequest({
171
174
  gatewayEffort,
172
175
  effortProjection,
173
176
  });
177
+ // User-defined extra fields (e.g. `thinking`) go over the body before the
178
+ // tool_choice guard, so a forced choice is still dropped while the merged
179
+ // body has thinking on. The app-owned keys (model, messages, tools, stream,
180
+ // tool_choice, …) are refused inside.
181
+ if (isCustom && customConfig) applyCustomRequestBody(params, customConfig, useModel);
174
182
  if (params.tools) resolveRequestToolChoice(params, opts, config);
175
183
  // Fast mode → speed: "fast" on models Anthropic marks as speed-capable.
176
184
  // Suppressed while the fast capacity pool is cooling down.
@@ -197,7 +205,9 @@ export async function buildAnthropicApiRequest({
197
205
  capabilityModel,
198
206
  effortProjection,
199
207
  });
200
- const requestHeaders = requestHeadersFor(betas, { config, opts });
208
+ const appHeaders = requestHeadersFor(betas, { config, opts });
209
+ const requestHeaders =
210
+ isCustom && customConfig ? customRequestHeaders(customConfig, useModel, appHeaders) : appHeaders;
201
211
 
202
212
  // `betas`: the selected beta names, whether or not this route sends them as a header.
203
213
  return { params, requestHeaders, betas, knownToolNames, fastModeLatched: fastLatched };
@@ -63,6 +63,10 @@ export function createContentBlockStart({ turn, blocks, state, progress, seedTex
63
63
  // The call opened; its input still streams before onToolCall.
64
64
  reportStreamItemStart(onStreamItemStart, { kind: 'tool' });
65
65
  }
66
+ // Any output block opening starts the generation (generation-window.mjs),
67
+ // a thinking block above all: under omitted or "updates" thinking display
68
+ // it streams nothing until its signature at the end.
69
+ if (block?.type && !fallback) turn.firstOutputAt ||= Date.now();
66
70
  if (block?.type === 'text') {
67
71
  // Seed the ordered text slot. An empty block still needs its slot (it
68
72
  // separates thinking runs); a non-empty opening `text` is model output
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import { stampStreamOutcome, STREAM_TRANSPORTS } from '../lib/stream-outcome.mjs';
9
9
  import { createProviderReplay } from '../lib/provider-replay.mjs';
10
+ import { generationWindow } from '../lib/generation-window.mjs';
10
11
  import { OAUTH_STREAM_LABELS } from '../lib/anthropic-stream-labels.mjs';
11
12
  import { anthropicFallbackProviderMetadata } from '../anthropic-server-fallback.mjs';
12
13
 
@@ -155,6 +156,7 @@ export function createTurnOutcome({ turn, blocks, state, labels = OAUTH_STREAM_L
155
156
  assistantBlocks,
156
157
  providerReplay: createProviderReplay('anthropic', assistantBlocks),
157
158
  providerMetadata: anthropicFallbackProviderMetadata(turn.fallbackEvents),
159
+ ...generationWindow(turn.firstOutputAt),
158
160
  };
159
161
  };
160
162
 
@@ -83,6 +83,8 @@ export function buildAnthropicTurnResult(parseResult, { provider, useModel, opts
83
83
  ...(parseResult.providerMetadata && typeof parseResult.providerMetadata === 'object'
84
84
  ? { providerMetadata: parseResult.providerMetadata }
85
85
  : {}),
86
+ // The answering stream's own generation window (generation-window.mjs).
87
+ ...(parseResult.generationMs != null ? { generationMs: parseResult.generationMs } : {}),
86
88
  usage: {
87
89
  inputTokens: input,
88
90
  outputTokens: output,
@@ -186,6 +186,7 @@ export class AnthropicProvider {
186
186
  fastModeLatched: this.fastModeBetaHeaderLatched,
187
187
  modelInfo: isCustomProviderName(this.name) ? this.getCachedModelInfo?.(model) || null : null,
188
188
  capabilityModel: this._capabilityModel(model),
189
+ customConfig: this.customConfig ?? null,
189
190
  });
190
191
  return sendAnthropicCacheWarm({
191
192
  providerName: this.name,
@@ -229,6 +230,7 @@ export class AnthropicProvider {
229
230
  // Custom providers carry per-model reasoning settings on their own rows.
230
231
  modelInfo: isCustomProviderName(this.name) ? this.getCachedModelInfo?.(useModel) || null : null,
231
232
  capabilityModel: this._capabilityModel(useModel),
233
+ customConfig: this.customConfig ?? null,
232
234
  });
233
235
  this.fastModeBetaHeaderLatched = fastModeLatched;
234
236
 
@@ -13,6 +13,35 @@ export const CUSTOM_REASONING_WIRE_FORMATS = Object.freeze(['standard', 'deepsee
13
13
  export const CUSTOM_PROVIDER_AUTH_MODES = Object.freeze(['key', 'none']);
14
14
  export const CUSTOM_MODEL_OVERRIDE_LIMIT = 500;
15
15
  export const CUSTOM_HEADER_LIMIT = 64;
16
+ // Serialized size cap of one extra-request JSON object (provider or model).
17
+ export const CUSTOM_REQUEST_BODY_MAX_CHARS = 16384;
18
+ // What the Chat, Responses and Messages wires build themselves (body fields
19
+ // the app sets, or whose override would break replay, tool use or streaming).
20
+ export const CUSTOM_RESERVED_BODY_KEYS = Object.freeze(
21
+ new Set([
22
+ 'model',
23
+ 'messages',
24
+ 'input',
25
+ 'system',
26
+ 'instructions',
27
+ 'tools',
28
+ 'tool_choice',
29
+ 'parallel_tool_calls',
30
+ 'stream',
31
+ 'stream_options',
32
+ 'previous_response_id',
33
+ 'store',
34
+ 'include',
35
+ 'prompt_cache_key',
36
+ 'max_tokens',
37
+ 'max_output_tokens',
38
+ 'max_completion_tokens',
39
+ ])
40
+ );
41
+ // Transport headers the HTTP client owns; model-level headers may not set them.
42
+ export const CUSTOM_MODEL_REFUSED_HEADERS = Object.freeze(
43
+ new Set(['content-type', 'content-length', 'host', 'connection', 'transfer-encoding', 'proxy-authorization'])
44
+ );
16
45
 
17
46
  const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
18
47
  const MAX_MODEL_ID = 256;
@@ -74,6 +103,8 @@ const OVERRIDE_KEYS = new Set([
74
103
  'maxOutputTokens',
75
104
  'supportsVision',
76
105
  'reasoning',
106
+ 'requestBody',
107
+ 'requestHeaders',
77
108
  ]);
78
109
  const REASONING_KEYS = new Set(['levels', 'wireFormat', 'wireValues', 'replay']);
79
110
  const DISCOVERY_KEYS = new Set(['newModelsHidden']);
@@ -93,6 +124,7 @@ const V2_TOP_LEVEL_KEYS = new Set([
93
124
  'wires',
94
125
  'modelWires',
95
126
  'headers',
127
+ 'requestBody',
96
128
  'id',
97
129
  'apiKey',
98
130
  'apiKeyEnv',
@@ -244,6 +276,10 @@ function normalizeOverride(id, raw, protocol, legacy) {
244
276
  const reasoning = normalizeReasoning(raw.reasoning, `${label}.reasoning`, protocol);
245
277
  if (Object.keys(reasoning).length) out.reasoning = reasoning;
246
278
  }
279
+ const requestBody = normalizeRequestBody(raw.requestBody, `${label}.requestBody`);
280
+ if (Object.keys(requestBody).length) out.requestBody = requestBody;
281
+ const requestHeaders = normalizeHeaders(raw.requestHeaders, `${label}.requestHeaders`, CUSTOM_MODEL_REFUSED_HEADERS);
282
+ if (Object.keys(requestHeaders).length) out.requestHeaders = requestHeaders;
247
283
  return out;
248
284
  }
249
285
 
@@ -307,31 +343,98 @@ function normalizeModelWires(raw, protocol, wires) {
307
343
  // `headers`: extra HTTP headers sent with every request to the endpoint
308
344
  // (inference, model discovery, connection test). Names are case-insensitive
309
345
  // tokens; the credential headers belong to the API key field.
310
- function normalizeHeaders(raw) {
346
+ function normalizeHeaders(raw, label = 'headers', refused = AUTH_HEADERS) {
311
347
  if (raw === undefined) return {};
312
- if (!isPlainObject(raw)) fail('headers must be an object of header names to string values');
348
+ if (!isPlainObject(raw)) fail(`${label} must be an object of header names to string values`);
313
349
  const names = Object.keys(raw);
314
- if (names.length > CUSTOM_HEADER_LIMIT) fail(`at most ${CUSTOM_HEADER_LIMIT} headers are allowed`);
350
+ if (names.length > CUSTOM_HEADER_LIMIT) fail(`at most ${CUSTOM_HEADER_LIMIT} ${label} are allowed`);
315
351
  const seen = new Set();
316
352
  const entries = [];
317
353
  for (const name of names) {
318
354
  if (name.length > MAX_HEADER_TEXT || !HEADER_NAME.test(name))
319
- fail(`headers has an invalid header name: ${JSON.stringify(name.slice(0, 64))}`);
355
+ fail(`${label} has an invalid header name: ${JSON.stringify(name.slice(0, 64))}`);
320
356
  const lower = name.toLowerCase();
321
- if (AUTH_HEADERS.has(lower)) fail(`headers must not set ${name}: authentication belongs to the API key field`);
322
- if (seen.has(lower)) fail(`headers has duplicate header: ${name}`);
357
+ if (AUTH_HEADERS.has(lower)) fail(`${label} must not set ${name}: authentication belongs to the API key field`);
358
+ if (refused.has(lower)) fail(`${label} must not set ${name}: the app owns this header`);
359
+ if (seen.has(lower)) fail(`${label} has duplicate header: ${name}`);
323
360
  seen.add(lower);
324
- if (typeof raw[name] !== 'string') fail(`headers.${name} must be a string`);
361
+ if (typeof raw[name] !== 'string') fail(`${label}.${name} must be a string`);
325
362
  // Validate before trimming, and trim only HTTP whitespace (space, tab), so
326
363
  // CR/LF is refused rather than stripped and other characters are kept.
327
- if (!HEADER_VALUE.test(raw[name])) fail(`headers.${name} has an invalid value`);
364
+ if (!HEADER_VALUE.test(raw[name])) fail(`${label}.${name} has an invalid value`);
328
365
  const value = raw[name].replace(/^[ \t]+|[ \t]+$/g, '');
329
- if (value.length > MAX_HEADER_TEXT) fail(`headers.${name} has an invalid value`);
366
+ if (value.length > MAX_HEADER_TEXT) fail(`${label}.${name} has an invalid value`);
330
367
  entries.push([name, value]);
331
368
  }
332
369
  return Object.fromEntries(entries);
333
370
  }
334
371
 
372
+ // `requestBody` (provider and model): extra JSON request fields. A shallow
373
+ // object, size-capped; the keys the app builds the request from can never be set here.
374
+ function normalizeRequestBody(raw, label) {
375
+ if (raw === undefined) return {};
376
+ if (!isPlainObject(raw)) fail(`${label} must be a JSON object`);
377
+ let size;
378
+ try {
379
+ size = JSON.stringify(raw)?.length;
380
+ } catch {
381
+ fail(`${label} must be JSON-serializable`);
382
+ }
383
+ if (!Number.isInteger(size)) fail(`${label} must be JSON-serializable`);
384
+ if (size > CUSTOM_REQUEST_BODY_MAX_CHARS)
385
+ fail(`${label} must be at most ${CUSTOM_REQUEST_BODY_MAX_CHARS} characters`);
386
+ const out = {};
387
+ for (const key of Object.keys(raw)) {
388
+ if (UNSAFE_KEYS.has(key)) fail(`${label} has an unsafe key: ${key}`);
389
+ if (CUSTOM_RESERVED_BODY_KEYS.has(key)) fail(`${label} must not set ${key}: the app owns this field`);
390
+ out[key] = raw[key];
391
+ }
392
+ return out;
393
+ }
394
+
395
+ /**
396
+ * The extra request fields and headers for one model of a normalized config:
397
+ * provider JSON, then model JSON over it (shallow); provider headers, then
398
+ * model headers over them. Reserved keys are stripped again here, so a stored
399
+ * config that somehow carries one still cannot override the app. Headers are
400
+ * the model layer only: the provider's ride the engine's default headers.
401
+ */
402
+ export function resolveCustomRequestExtras(config, model) {
403
+ const override =
404
+ config?.modelOverrides && Object.hasOwn(config.modelOverrides, model) ? config.modelOverrides[model] : null;
405
+ const body = {};
406
+ for (const layer of [config?.requestBody, override?.requestBody]) {
407
+ for (const [key, value] of Object.entries(layer || {})) {
408
+ if (!CUSTOM_RESERVED_BODY_KEYS.has(key) && !UNSAFE_KEYS.has(key)) body[key] = structuredClone(value);
409
+ }
410
+ }
411
+ const headers = {};
412
+ for (const [name, value] of Object.entries(override?.requestHeaders || {})) {
413
+ const lower = name.toLowerCase();
414
+ if (!AUTH_HEADERS.has(lower) && !CUSTOM_MODEL_REFUSED_HEADERS.has(lower)) headers[name] = value;
415
+ }
416
+ return { body, headers };
417
+ }
418
+
419
+ /** `params` (the finished request body) with the extras layered over it; reserved keys keep the app's value. */
420
+ export function applyCustomRequestBody(params, config, model) {
421
+ const { body } = resolveCustomRequestExtras(config, model ?? params?.model);
422
+ for (const [key, value] of Object.entries(body)) params[key] = value;
423
+ return params;
424
+ }
425
+
426
+ /** Per-request headers: the model's extra headers under the caller's own. */
427
+ export function customRequestHeaders(config, model, requestHeaders) {
428
+ const { headers } = resolveCustomRequestExtras(config, model);
429
+ if (!Object.keys(headers).length) return requestHeaders;
430
+ if (requestHeaders instanceof Headers || Array.isArray(requestHeaders)) {
431
+ const merged = new Headers(headers);
432
+ for (const [name, value] of new Headers(requestHeaders)) merged.set(name, value);
433
+ return merged;
434
+ }
435
+ return { ...headers, ...(requestHeaders || {}) };
436
+ }
437
+
335
438
  // Legacy (pre-v2) `models: [{ id, name?, contextWindow?, maxOutputTokens? }]`
336
439
  // become manual, visible overrides; their presence hides newly discovered ids.
337
440
  function migrateLegacy(input) {
@@ -374,6 +477,7 @@ export function normalizeCustomProviderConfig(input) {
374
477
  if (input.wires !== undefined || input.modelWires !== undefined)
375
478
  fail('wires and modelWires require schemaVersion 2');
376
479
  if (input.headers !== undefined) fail('headers require schemaVersion 2');
480
+ if (input.requestBody !== undefined) fail('requestBody requires schemaVersion 2');
377
481
  source = migrateLegacy(input);
378
482
  } else if (Number.isInteger(version) && version > CUSTOM_PROVIDER_SCHEMA_VERSION)
379
483
  fail(`unsupported schemaVersion ${version}; update mixdog to use this provider`);
@@ -407,6 +511,7 @@ export function normalizeCustomProviderConfig(input) {
407
511
  const wires = normalizeWires(source.wires, protocol);
408
512
  const modelWires = normalizeModelWires(source.modelWires, protocol, wires);
409
513
  const headers = normalizeHeaders(source.headers);
514
+ const requestBody = normalizeRequestBody(source.requestBody, 'requestBody');
410
515
  return {
411
516
  type: 'custom',
412
517
  schemaVersion: CUSTOM_PROVIDER_SCHEMA_VERSION,
@@ -417,6 +522,7 @@ export function normalizeCustomProviderConfig(input) {
417
522
  auth,
418
523
  ...(apiKeyEnv && auth === 'key' ? { apiKeyEnv } : {}),
419
524
  ...(Object.keys(headers).length ? { headers } : {}),
525
+ ...(Object.keys(requestBody).length ? { requestBody } : {}),
420
526
  discovery: { newModelsHidden },
421
527
  modelOverrides: normalizeOverrides(source.modelOverrides, protocol, legacy),
422
528
  ...(wires ? { wires } : {}),
@@ -471,6 +577,12 @@ function effectiveRow(base, override, { providerId, discovered, newModelsHidden
471
577
  outputTokens: ov.maxOutputTokens ?? (Number(base.outputTokens) > 0 ? Number(base.outputTokens) : null),
472
578
  hidden,
473
579
  manual: ov.manual === true,
580
+ // What the model has without its own override (a reset restores these).
581
+ inherited: {
582
+ name: base.name || base.id,
583
+ contextWindow: Number(base.contextWindow) > 0 ? Number(base.contextWindow) : 0,
584
+ maxOutputTokens: Number(base.outputTokens) > 0 ? Number(base.outputTokens) : null,
585
+ },
474
586
  // An explicit override (false included) beats the catalog; unset keeps the base.
475
587
  ...(typeof ov.supportsVision === 'boolean' ? { supportsVision: ov.supportsVision } : {}),
476
588
  supportsReasoning: levels ? levels.some((level) => level !== 'none') : base.supportsReasoning === true,
@@ -217,8 +217,11 @@ export async function createCustomProvider(id, config) {
217
217
  // The bound Messages engine reads the parent's model rows, so a routed
218
218
  // Messages request carries the same row-driven thinking/effort as the
219
219
  // Anthropic protocol.
220
- if (provider.messagesEngine)
220
+ if (provider.messagesEngine) {
221
221
  provider.messagesEngine.getCachedModelInfo = (model) => provider.getCachedModelInfo(model);
222
+ // …and the same extra request fields and headers.
223
+ provider.messagesEngine.customConfig = cfg;
224
+ }
222
225
  provider.customConfig = cfg;
223
226
  provider._customKeyless = keyless;
224
227
  provider._applyCustomRows(provider._customRows());
@@ -0,0 +1,9 @@
1
+ /**
2
+ * A stream's success result carries its own generation window: from this
3
+ * stream's first output to its end. Usage accounting computes speed from it
4
+ * (usage-accounting.mjs), so a retried, reconnected or fallen-back send is
5
+ * timed by the stream that answered, never by an abandoned attempt or the
6
+ * backoff before it. A result without one (a non-streaming recovery, a
7
+ * stream that showed no output start) has no speed.
8
+ */
9
+ export const generationWindow = (firstOutputAt) => (firstOutputAt ? { generationMs: Date.now() - firstOutputAt } : {});
@@ -24,6 +24,7 @@ import { compatFirstByteWindowMs, compatRetryOptions, withCompatRetryProfile } f
24
24
  import { TIMEOUT_PHASE } from '../../../shared/provider-timeout-phase.mjs';
25
25
  import { preparePdfTextForProvider } from './media-normalization.mjs';
26
26
  import { customWireFormat, isCustomProviderName, resolveCustomReasoning } from './custom-reasoning.mjs';
27
+ import { applyCustomRequestBody, customRequestHeaders } from './custom-provider-config.mjs';
27
28
  import { geminiAcceptedTools } from './gemini-schema.mjs';
28
29
  import { acceptedWireTools } from './lib/claude-bridge-schema.mjs';
29
30
  import { isGeminiFamilyModel } from './gemini-family.mjs';
@@ -124,15 +125,22 @@ export async function sendCompatChat(provider, messages, useModel, tools, opts)
124
125
  });
125
126
  applyCompatProviderChatOptions(params, provider.name, opts, provider.config, modelInfo);
126
127
  profile?.applyParams?.(params, { opts, config: provider.config, modelInfo });
128
+ // A custom provider's own extra JSON goes over the reasoning fields; stream
129
+ // flags below and the app-owned keys stay the app's.
130
+ if (isCustom && provider.customConfig) applyCustomRequestBody(params, provider.customConfig, useModel);
127
131
  const firstByteTimeoutMs = profile?.firstByteTimeoutMs || PROVIDER_FIRST_BYTE_TIMEOUT_MS;
128
132
  const totalSignal = createPassthroughSignal(signal);
129
133
  const cacheRouting = provider.name === 'xai' ? xaiCacheRouting(opts, params, tools || [], useModel) : null;
130
134
  const cacheRoutingKey = cacheRouting?.key || null;
131
135
  // xAI Chat pins a conversation to the server holding its cached prefix with
132
136
  // the x-grok-conv-id header (the Responses equivalent is prompt_cache_key).
133
- const requestHeaders = cacheRoutingKey
137
+ const callerHeaders = cacheRoutingKey
134
138
  ? { 'x-grok-conv-id': cacheRoutingKey, ...(opts.requestHeaders || {}) }
135
139
  : opts.requestHeaders;
140
+ const requestHeaders =
141
+ isCustom && provider.customConfig
142
+ ? customRequestHeaders(provider.customConfig, useModel, callerHeaders)
143
+ : callerHeaders;
136
144
  params.stream = true;
137
145
  params.stream_options = { include_usage: true };
138
146
  let assembled;
@@ -4,6 +4,7 @@
4
4
  * reconstructed response, tool-call parsing and dispatch, and the result.
5
5
  */
6
6
  import { dedupeToolCallList } from '../lib/leaked-toolcall.mjs';
7
+ import { generationWindow } from '../lib/generation-window.mjs';
7
8
  import { truncatedCompatStreamError } from '../lib/openai-tool-args.mjs';
8
9
  import {
9
10
  emitCompatToolCallOnce,
@@ -104,5 +105,6 @@ export function settleCompatStream(state, { label, parseToolCalls }) {
104
105
  reasoningSource: state.sawReasoningContent ? state.reasoningSource : null,
105
106
  reasoningDetails: state.reasoningDetails.length ? state.reasoningDetails : null,
106
107
  rawUsage: state.rawUsage,
108
+ ...generationWindow(state.firstOutputAt),
107
109
  };
108
110
  }
@@ -14,6 +14,7 @@ import {
14
14
  import { chatCompletionUsage } from '../openai-compat-response-normalization.mjs';
15
15
  import { noteAbandonedUsage } from '../../../../shared/llm/usage-context.mjs';
16
16
  import { createToolCallAccumulator } from './tool-call-acc.mjs';
17
+ import { isVisibleStreamProgress } from '../../../../shared/stream-progress.mjs';
17
18
 
18
19
  export function createCompatStreamState({
19
20
  providerName,
@@ -65,6 +66,10 @@ export function reportTransport(state) {
65
66
 
66
67
  export function reportProgress(state, kind) {
67
68
  if (kind !== 'transport') state.semanticIdleDeadlineAt = Date.now() + state.idleMs;
69
+ // A chat stream shows output only as deltas: the first visible one starts
70
+ // the generation (generation-window.mjs). Usage accounting trusts it only
71
+ // from a provider that streams every token, reasoning included.
72
+ if (isVisibleStreamProgress(kind)) state.firstOutputAt ||= Date.now();
68
73
  try {
69
74
  state.onStreamDelta?.(kind);
70
75
  } catch {}
@@ -4,6 +4,7 @@ import {
4
4
  normalizeOpencodeGoReasoningEffort,
5
5
  } from './openai-compat-xai.mjs';
6
6
  import { isCustomProviderName, resolveCustomReasoning } from './custom-reasoning.mjs';
7
+ import { openRouterProviderRouting } from './openrouter-provider-routing.mjs';
7
8
 
8
9
  function normalizeReasoningEffort(value, allowed) {
9
10
  const effort = String(value ?? '')
@@ -66,6 +67,8 @@ export function applyCompatProviderChatOptions(params, providerName, opts = {},
66
67
  if (providerName === 'openrouter') {
67
68
  const reasoning = openRouterReasoning(opts, config);
68
69
  if (reasoning) params.reasoning = reasoning;
70
+ const routing = openRouterProviderRouting(opts);
71
+ if (routing) params.provider = routing;
69
72
  return params;
70
73
  }
71
74
  if (providerName === 'xai') {
@@ -242,6 +242,8 @@ export function normalizeCompatChatResponse({
242
242
  ...(reasoningContent !== null ? { reasoningContent } : {}),
243
243
  ...(Object.keys(providerMetadata).length ? { providerMetadata } : {}),
244
244
  usage: response.usage ? chatCompletionUsage(providerName, response.usage) : undefined,
245
+ // The answering stream's own generation window (generation-window.mjs).
246
+ ...(assembled.generationMs != null ? { generationMs: assembled.generationMs } : {}),
245
247
  };
246
248
  }
247
249
 
@@ -26,6 +26,7 @@ import { nativeDeferredFamilyForRoute } from './wire-route.mjs';
26
26
  import { preparePdfTextForProvider } from './media-normalization.mjs';
27
27
  import { normalizeOpencodeGoReasoningEffort } from './openai-compat-xai.mjs';
28
28
  import { isCustomProviderName, resolveCustomReasoning } from './custom-reasoning.mjs';
29
+ import { applyCustomRequestBody, customRequestHeaders } from './custom-provider-config.mjs';
29
30
  import { projectEffortConfiguration, withEffortConfigurationFallback } from './effort-configuration.mjs';
30
31
  import { normalizeCacheKey } from '../agent-runtime/cache-strategy.mjs';
31
32
  import { createProviderReplay } from './lib/provider-replay.mjs';
@@ -205,6 +206,10 @@ function buildCompatResponsesParams({
205
206
  (typeof provider.getCachedModelInfo === 'function' && provider.getCachedModelInfo(useModel)) || null;
206
207
  hook(params, { useModel, opts, modelInfo });
207
208
  }
209
+ // A custom provider's own extra JSON; the app-owned keys are never overridden.
210
+ if (isCustomProviderName(provider.name) && provider.customConfig) {
211
+ applyCustomRequestBody(params, provider.customConfig, useModel);
212
+ }
208
213
  return params;
209
214
  }
210
215
 
@@ -344,7 +349,11 @@ async function sendCompatResponsesOnce(provider, requestMessages, useModel, tool
344
349
  // Custom routes only: a gateway route that opts into prompt_cache_key keeps
345
350
  // its own headers.
346
351
  const headers = isCustomProviderName(provider.name)
347
- ? customSessionHeaders(provider, sessionCacheKey, opts.requestHeaders)
352
+ ? customSessionHeaders(
353
+ provider,
354
+ sessionCacheKey,
355
+ customRequestHeaders(provider.customConfig, useModel, opts.requestHeaders)
356
+ )
348
357
  : opts.requestHeaders;
349
358
 
350
359
  try {
@@ -44,6 +44,9 @@ export function createResponseEvents({
44
44
  }
45
45
  break;
46
46
  case 'response.output_item.added':
47
+ // An encrypted reasoning item opens as the model starts thinking:
48
+ // the first item starts the generation (generation-window.mjs).
49
+ state.firstOutputAt ||= Date.now();
47
50
  output.onOutputItemAdded(event.item);
48
51
  reportStreamItemStart(onStreamItemStart, responsesItemStart(event.item));
49
52
  break;
@@ -10,6 +10,7 @@ import { _displayCodexModel } from '../openai-codex-model.mjs';
10
10
  import { createProviderReplay } from '../lib/provider-replay.mjs';
11
11
  import { createResponseStamps } from './response-stamps.mjs';
12
12
  import { refusalResultFields } from '../openai-ws-response-state/refusals.mjs';
13
+ import { generationWindow } from '../lib/generation-window.mjs';
13
14
 
14
15
  export function createResponseOutcome({ state }) {
15
16
  const { stampToolSafety, stampOutcome, stallPartial, stampStreamError, attachStreamPartial, endedEarlyError } =
@@ -87,6 +88,7 @@ export function createResponseOutcome({ state }) {
87
88
  serviceTier: state.serviceTier || undefined,
88
89
  // A refused turn: typed stop reason and the refusal text.
89
90
  ...refusalResultFields(state.refusals, state.content),
91
+ ...generationWindow(state.firstOutputAt),
90
92
  };
91
93
  };
92
94