@zvada/agent-server 0.3.14 → 0.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.15
4
+
5
+ - Codex runs the nearest thinking level its model accepts. `off` sent effort
6
+ `minimal`, which every current Codex model rejects, so the turn failed
7
+ ("Unsupported value: 'minimal' is not supported with the 'gpt-6-astra'
8
+ model"); it now sends the model's lowest effort. A level above the model's
9
+ top becomes that top. `codex-app-server` asks the CLI (`model/list`) what the
10
+ thread's model accepts, including a model `~/.codex/config.toml` selected;
11
+ `codex-sdk` uses the catalog.
12
+ - `MODEL_CATALOG` lists each model's real levels instead of all seven for
13
+ every model, and adds `gpt-5.6-sol`, `gpt-5.6-terra`, `gpt-5.6-luna` and
14
+ Claude's `fable` alias. Codex models offer no `off`; Claude models offer no
15
+ `ultra` (it runs as `max`); Haiku lists none. `gpt-5.5` is labeled API-key
16
+ only: Codex refuses it for a ChatGPT login.
17
+ - Add `clampThinkingLevel(level, supported)` and `modelThinkingLevels(harness,
18
+ model)` for pickers that switch models.
19
+ - Development only: lift `vite` (through vitest) to 8.3 past a newly
20
+ published advisory so the audit passes.
21
+
3
22
  ## 0.3.14
4
23
 
5
24
  - Update the managed CLIs and development SDKs: Codex 0.160.0 and Claude Agent
package/docs/harnesses.md CHANGED
@@ -68,8 +68,13 @@ servers its config names. Set `ENABLE_CLAUDEAI_MCP_SERVERS=true` in the
68
68
  server's or the turn's env to load them.
69
69
 
70
70
  `thinkingLevel` runs from `off` to `ultra`. Claude's ceiling is `max` (it runs
71
- `ultra` as `max`); Codex passes the level through, and not every model offers
72
- `ultra`.
71
+ `ultra` as `max`), and Claude Code silently lowers a level its model lacks.
72
+ Codex runs the nearest level the model accepts: `off` becomes the model's
73
+ lowest (current models reject `minimal`), and a level above its top becomes
74
+ that top. `codex-app-server` reads what each model accepts from `model/list`;
75
+ `codex-sdk` uses `MODEL_CATALOG`. `MODEL_CATALOG` lists each model's own
76
+ levels, and `clampThinkingLevel` picks the nearest one when a picker switches
77
+ models.
73
78
 
74
79
  Consult `runtime.capabilities(harness)` before relying on a capability.
75
80
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zvada/agent-server",
3
- "version": "0.3.14",
3
+ "version": "0.3.15",
4
4
  "description": "Harness-agnostic agent execution engine: run Claude Code, Codex (SDK/CLI + app-server), and any ACP agent behind one interface with a normalized event stream, multi-turn sessions, and resume. Root export is the wire contract; /core, /server, /client are the seats.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -6,8 +6,14 @@ import type {
6
6
  AgentInput,
7
7
  PermissionMode,
8
8
  PermissionToolCall,
9
+ ThinkingLevel,
10
+ } from "../../../protocol/index.ts";
11
+ import {
12
+ AsyncQueue,
13
+ codexReasoningEffort,
14
+ isThinkingLevel,
15
+ modelThinkingLevels,
9
16
  } from "../../../protocol/index.ts";
10
- import { AsyncQueue, codexReasoningEffort } from "../../../protocol/index.ts";
11
17
  import { SessionResumeError } from "../../utils/errors.ts";
12
18
  import type {
13
19
  AgentExecuteOptions,
@@ -60,6 +66,16 @@ export interface AppServerSession {
60
66
  /** Credentials and permission broker belong only to the current execute. */
61
67
  turn?: AppServerTurn;
62
68
  idleTimer?: ReturnType<typeof setTimeout>;
69
+ /** The thread's model, as Codex resolved it (config.toml included). */
70
+ model?: string;
71
+ /** What each model accepts, from this process's `model/list`; read once. */
72
+ modelEfforts?: Promise<ReadonlyMap<string, CodexModelThinking> | undefined>;
73
+ }
74
+
75
+ /** A model's thinking levels, and the native effort that `off` means for it. */
76
+ export interface CodexModelThinking {
77
+ levels: readonly ThinkingLevel[];
78
+ off?: "none" | "minimal";
63
79
  }
64
80
 
65
81
  interface AppServerTurn {
@@ -225,6 +241,58 @@ export function appServerNotificationEndsTurn(notification: CodexNotification):
225
241
  );
226
242
  }
227
243
 
244
+ const MODEL_LIST_TIMEOUT_MS = 5_000;
245
+
246
+ /**
247
+ * The thinking levels each model the logged-in account can run accepts, from
248
+ * `model/list`. Codex's `none` or `minimal` is `off`, and is remembered so
249
+ * `off` sends the value the model advertised (`none` when it offers both).
250
+ * `undefined` when the CLI cannot answer; callers fall back to `MODEL_CATALOG`.
251
+ */
252
+ export async function listModelThinking(
253
+ client: Pick<CodexAppServerClient, "request">,
254
+ ): Promise<ReadonlyMap<string, CodexModelThinking> | undefined> {
255
+ const models = new Map<string, CodexModelThinking>();
256
+ let cursor: string | undefined;
257
+ try {
258
+ for (let page = 0; page < 10; page++) {
259
+ const result = (await client.request(
260
+ "model/list",
261
+ { includeHidden: true, ...(cursor && { cursor }) },
262
+ MODEL_LIST_TIMEOUT_MS,
263
+ )) as { data?: unknown; nextCursor?: unknown } | undefined;
264
+ if (!Array.isArray(result?.data)) break;
265
+ for (const entry of result.data as Array<Record<string, unknown>>) {
266
+ const efforts = Array.isArray(entry.supportedReasoningEfforts)
267
+ ? (entry.supportedReasoningEfforts as Array<{ reasoningEffort?: unknown }>).map(
268
+ ({ reasoningEffort }) => reasoningEffort,
269
+ )
270
+ : [];
271
+ const off = efforts.includes("none")
272
+ ? "none"
273
+ : efforts.includes("minimal")
274
+ ? "minimal"
275
+ : undefined;
276
+ const levels: ThinkingLevel[] = [
277
+ ...(off ? (["off"] as const) : []),
278
+ ...efforts.filter(
279
+ (effort): effort is ThinkingLevel =>
280
+ typeof effort === "string" && effort !== "off" && isThinkingLevel(effort),
281
+ ),
282
+ ];
283
+ for (const name of [entry.model, entry.id])
284
+ if (typeof name === "string" && levels.length)
285
+ models.set(name, { levels, ...(off && { off }) });
286
+ }
287
+ cursor = typeof result.nextCursor === "string" ? result.nextCursor : undefined;
288
+ if (!cursor) break;
289
+ }
290
+ } catch {
291
+ // An older CLI, a slow answer or a closed process: the catalog decides.
292
+ }
293
+ return models.size ? models : undefined;
294
+ }
295
+
228
296
  /**
229
297
  * Codex harness backed by a long-lived `codex app-server` subprocess speaking
230
298
  * JSON-RPC. Unlike the SDK harness this streams token-level deltas. A client +
@@ -359,7 +427,7 @@ export class CodexAppServerAgent extends SessionAgent {
359
427
  cause instanceof Error ? cause.message : String(cause),
360
428
  { cause },
361
429
  );
362
- })) as { thread?: { id?: string } };
430
+ })) as { thread?: { id?: string }; model?: unknown };
363
431
  const threadId = result?.thread?.id;
364
432
  if (resumeThreadId && threadId !== resumeThreadId) {
365
433
  throw new SessionResumeError(
@@ -370,6 +438,7 @@ export class CodexAppServerAgent extends SessionAgent {
370
438
  if (!threadId) throw new Error("codex app-server thread/start returned no thread id");
371
439
  signal.throwIfAborted();
372
440
  session.threadId = threadId;
441
+ session.model = typeof result.model === "string" ? result.model : options.model;
373
442
  this.sessions.set(options.sessionId, session);
374
443
  return session;
375
444
  } catch (error) {
@@ -422,6 +491,16 @@ export class CodexAppServerAgent extends SessionAgent {
422
491
  session.mcpFingerprint = fingerprint;
423
492
  }
424
493
 
494
+ /** What the thread's model accepts: live from this process, else the catalog. */
495
+ private async modelThinking(session: AppServerSession): Promise<CodexModelThinking | undefined> {
496
+ if (!session.model) return undefined;
497
+ session.modelEfforts ??= listModelThinking(session.client);
498
+ const live = (await session.modelEfforts)?.get(session.model);
499
+ if (live) return live;
500
+ const levels = modelThinkingLevels("codex-app-server", session.model);
501
+ return levels && { levels };
502
+ }
503
+
425
504
  private async authenticate(session: AppServerSession): Promise<void> {
426
505
  session.turn?.signal.throwIfAborted();
427
506
  const auth = session.turn?.auth;
@@ -714,8 +793,18 @@ export class CodexAppServerAgent extends SessionAgent {
714
793
  threadId,
715
794
  input: toUserInput(input),
716
795
  };
717
- if (options.model) turnParams.model = options.model;
718
- if (options.thinkingLevel) turnParams.effort = codexReasoningEffort(options.thinkingLevel);
796
+ if (options.model) {
797
+ turnParams.model = options.model;
798
+ session.model = options.model;
799
+ }
800
+ if (options.thinkingLevel) {
801
+ const accepts = await this.modelThinking(session);
802
+ turnParams.effort = codexReasoningEffort(
803
+ options.thinkingLevel,
804
+ accepts?.levels,
805
+ accepts?.off,
806
+ );
807
+ }
719
808
 
720
809
  if (controller.signal.aborted) throw new Error("turn aborted");
721
810
  if (this.invalidatedClients.has(client)) {
@@ -1,6 +1,6 @@
1
1
  import type { Codex, Thread, ThreadEvent, ThreadOptions } from "@openai/codex-sdk";
2
2
  import type { AgentCapabilities, AgentInput, PermissionMode } from "../../../protocol/index.ts";
3
- import { codexReasoningEffort } from "../../../protocol/index.ts";
3
+ import { codexReasoningEffort, modelThinkingLevels } from "../../../protocol/index.ts";
4
4
  import { SessionResumeError } from "../../utils/errors.ts";
5
5
  import type { AgentExecuteOptions, RawAgentEvent } from "../base.ts";
6
6
  import { configFingerprint } from "../config-fingerprint.ts";
@@ -101,7 +101,8 @@ function toCodexInput(input: AgentInput): string {
101
101
  .join("\n\n");
102
102
  }
103
103
 
104
- function threadOptions(options: AgentExecuteOptions): ThreadOptions {
104
+ /** `codex exec` options for a turn. Exported for tests. */
105
+ export function threadOptions(options: AgentExecuteOptions): ThreadOptions {
105
106
  const opts: ThreadOptions = {
106
107
  workingDirectory: options.cwd,
107
108
  skipGitRepoCheck: true,
@@ -112,8 +113,13 @@ function threadOptions(options: AgentExecuteOptions): ThreadOptions {
112
113
  : {}),
113
114
  };
114
115
  if (options.model) opts.model = options.model;
116
+ // `codex exec` cannot list models, so the catalog says what a model accepts.
115
117
  if (options.thinkingLevel)
116
- opts.modelReasoningEffort = codexReasoningEffort(options.thinkingLevel);
118
+ opts.modelReasoningEffort = codexReasoningEffort(
119
+ options.thinkingLevel,
120
+ options.model ? modelThinkingLevels("codex-sdk", options.model) : undefined,
121
+ "minimal",
122
+ );
117
123
  return opts;
118
124
  }
119
125
 
@@ -36,7 +36,8 @@ export const DEFAULT_PINS: Record<CliTool, string> = {
36
36
  // methods, token usage, approvals, and host-managed ChatGPT auth changed
37
37
  // only additively since 0.153.4. The GPT-6 family needs 0.159 or newer.
38
38
  // Since 0.160 a thread has one writer: resuming it from a second process
39
- // fails until the first releases it.
39
+ // fails until the first releases it. On every bump, re-read `model/list`
40
+ // and update MODEL_CATALOG's Codex models and thinking levels.
40
41
  codex: "0.160.0",
41
42
  };
42
43
 
@@ -1,5 +1,5 @@
1
1
  import type { AgentHarness } from "./harness.ts";
2
- import { THINKING_LEVELS, type ThinkingLevel } from "./thinking.ts";
2
+ import type { ThinkingLevel } from "./thinking.ts";
3
3
 
4
4
  /**
5
5
  * Advisory catalog of known-good models per harness. `model` on a RunConfig is
@@ -10,32 +10,52 @@ export interface ModelInfo {
10
10
  readonly id: string;
11
11
  readonly harness: AgentHarness;
12
12
  readonly label: string;
13
+ /** The levels the model runs as distinct settings, lowest first. Empty: no control. */
13
14
  readonly thinking: readonly ThinkingLevel[];
14
15
  }
15
16
 
16
- const ALL: readonly ThinkingLevel[] = THINKING_LEVELS;
17
+ const UP_TO_XHIGH: readonly ThinkingLevel[] = ["low", "medium", "high", "xhigh"];
18
+ const UP_TO_MAX: readonly ThinkingLevel[] = [...UP_TO_XHIGH, "max"];
19
+ const UP_TO_ULTRA: readonly ThinkingLevel[] = [...UP_TO_MAX, "ultra"];
17
20
 
18
- // As listed by Codex CLI 0.160.0. The GPT-6 family needs CLI 0.159 or newer.
19
- const CODEX_MODELS: ReadonlyArray<readonly [id: string, label: string]> = [
20
- ["gpt-6.1-sol", "GPT-6.1 Sol"],
21
- ["gpt-6-astra", "GPT-6 Astra"],
22
- ["gpt-6-sol", "GPT-6 Sol"],
23
- ["gpt-6-luna", "GPT-6 Luna"],
24
- ["gpt-5.5", "GPT-5.5"],
21
+ // Claude Code 2.1.288 aliases. The 5.5 models reject disabled thinking and
22
+ // Claude runs `ultra` as `max`, so neither `off` nor `ultra` is a setting of
23
+ // its own. Haiku 4.5 has no effort control.
24
+ const CLAUDE_MODELS: ReadonlyArray<readonly [string, string, readonly ThinkingLevel[]]> = [
25
+ ["sonnet", "Claude Sonnet (latest)", UP_TO_MAX],
26
+ ["opus", "Claude Opus (latest)", UP_TO_MAX],
27
+ ["fable", "Claude Fable (latest)", UP_TO_MAX],
28
+ ["haiku", "Claude Haiku (latest)", []],
29
+ ];
30
+
31
+ // As Codex CLI 0.160.0 `model/list` reports them. No model accepts `minimal`,
32
+ // so none offers `off`. The GPT-6 family needs CLI 0.159 or newer.
33
+ const CODEX_MODELS: ReadonlyArray<readonly [string, string, readonly ThinkingLevel[]]> = [
34
+ ["gpt-6.1-sol", "GPT-6.1 Sol", UP_TO_ULTRA],
35
+ ["gpt-6-astra", "GPT-6 Astra", UP_TO_ULTRA],
36
+ ["gpt-6-sol", "GPT-6 Sol", UP_TO_ULTRA],
37
+ ["gpt-6-luna", "GPT-6 Luna", UP_TO_MAX],
38
+ ["gpt-5.6-sol", "GPT-5.6 Sol", UP_TO_ULTRA],
39
+ ["gpt-5.6-terra", "GPT-5.6 Terra", UP_TO_ULTRA],
40
+ ["gpt-5.6-luna", "GPT-5.6 Luna", UP_TO_MAX],
41
+ // Codex refuses it for a ChatGPT login.
42
+ ["gpt-5.5", "GPT-5.5 (API key)", UP_TO_XHIGH],
25
43
  ];
26
44
 
27
45
  export const MODEL_CATALOG: readonly ModelInfo[] = [
28
- // Claude (the claude CLI also accepts the bare aliases "sonnet"/"opus"/"haiku").
29
- { id: "sonnet", harness: "claude-code", label: "Claude Sonnet (latest)", thinking: ALL },
30
- { id: "opus", harness: "claude-code", label: "Claude Opus (latest)", thinking: ALL },
31
- { id: "haiku", harness: "claude-code", label: "Claude Haiku (latest)", thinking: ALL },
32
- // Codex (shared between codex-sdk and codex-app-server).
33
- ...CODEX_MODELS.flatMap(([id, label]) =>
46
+ ...CLAUDE_MODELS.map(([id, label, thinking]) => ({
47
+ id,
48
+ harness: "claude-code" as const,
49
+ label,
50
+ thinking,
51
+ })),
52
+ // Shared between codex-sdk and codex-app-server.
53
+ ...CODEX_MODELS.flatMap(([id, label, thinking]) =>
34
54
  (["codex-sdk", "codex-app-server"] as const).map((harness) => ({
35
55
  id,
36
56
  harness,
37
57
  label,
38
- thinking: ALL,
58
+ thinking,
39
59
  })),
40
60
  ),
41
61
  ];
@@ -57,3 +77,11 @@ export const DEFAULT_MODELS: Record<AgentHarness, string | undefined> = {
57
77
  export function modelsForHarness(harness: AgentHarness): readonly ModelInfo[] {
58
78
  return MODEL_CATALOG.filter((m) => m.harness === harness);
59
79
  }
80
+
81
+ /** The catalog's thinking levels for a model; `undefined` when it isn't listed. */
82
+ export function modelThinkingLevels(
83
+ harness: AgentHarness,
84
+ model: string,
85
+ ): readonly ThinkingLevel[] | undefined {
86
+ return MODEL_CATALOG.find((m) => m.harness === harness && m.id === model)?.thinking;
87
+ }
@@ -3,8 +3,9 @@ import { z } from "zod";
3
3
  /**
4
4
  * A single, harness-agnostic reasoning dial. Each harness maps it to its own
5
5
  * native control: Claude -> adaptive `thinking` + `effort`; Codex ->
6
- * `ReasoningEffort`. The top levels depend on the model: Claude's ceiling is
7
- * `max` (it runs `ultra` as `max`), and not every Codex model offers `ultra`.
6
+ * `ReasoningEffort`. What runs depends on the model: Claude's ceiling is `max`
7
+ * (it runs `ultra` as `max`), and Codex runs the nearest level the model
8
+ * accepts (see `codexReasoningEffort`).
8
9
  */
9
10
  export const THINKING_LEVELS = ["off", "low", "medium", "high", "xhigh", "max", "ultra"] as const;
10
11
  export type ThinkingLevel = (typeof THINKING_LEVELS)[number];
@@ -15,8 +16,31 @@ export function isThinkingLevel(v: string): v is ThinkingLevel {
15
16
  return (THINKING_LEVELS as readonly string[]).includes(v);
16
17
  }
17
18
 
19
+ const rank = (level: ThinkingLevel) => THINKING_LEVELS.indexOf(level);
20
+
21
+ /**
22
+ * The level a model runs when it offers only `supported`: the highest one at
23
+ * or below `level`, else its lowest. Use it when switching models, so `ultra`
24
+ * on a model topping out at `max` becomes `max`, not a fixed fallback.
25
+ * `undefined` when the model offers none.
26
+ */
27
+ export function clampThinkingLevel(
28
+ level: ThinkingLevel,
29
+ supported: readonly ThinkingLevel[],
30
+ ): ThinkingLevel | undefined {
31
+ let below: ThinkingLevel | undefined;
32
+ let lowest: ThinkingLevel | undefined;
33
+ for (const candidate of supported) {
34
+ if (lowest === undefined || rank(candidate) < rank(lowest)) lowest = candidate;
35
+ if (rank(candidate) <= rank(level) && (below === undefined || rank(candidate) > rank(below)))
36
+ below = candidate;
37
+ }
38
+ return below ?? lowest;
39
+ }
40
+
18
41
  /** Codex reasoning-effort string for a level (matches the `ReasoningEffort` enum). */
19
42
  export type CodexReasoningEffort =
43
+ | "none"
20
44
  | "minimal"
21
45
  | "low"
22
46
  | "medium"
@@ -24,21 +48,20 @@ export type CodexReasoningEffort =
24
48
  | "xhigh"
25
49
  | "max"
26
50
  | "ultra";
27
- export function codexReasoningEffort(level: ThinkingLevel): CodexReasoningEffort {
28
- switch (level) {
29
- case "off":
30
- return "minimal";
31
- case "low":
32
- return "low";
33
- case "medium":
34
- return "medium";
35
- case "high":
36
- return "high";
37
- case "xhigh":
38
- return "xhigh";
39
- case "max":
40
- return "max";
41
- case "ultra":
42
- return "ultra";
43
- }
51
+
52
+ /**
53
+ * The effort Codex runs for `level`. `supported` is what the model accepts, in
54
+ * this vocabulary, where `off` stands for its least effort: `offEffort`, the
55
+ * native `none` or `minimal` the model advertises. A level it lacks becomes the
56
+ * nearest one it has. Without `supported`, `off` becomes `low`: no model the
57
+ * pinned CLI lists accepts `none` or `minimal`, and every one accepts `low`.
58
+ */
59
+ export function codexReasoningEffort<Off extends "none" | "minimal" = "minimal">(
60
+ level: ThinkingLevel,
61
+ supported?: readonly ThinkingLevel[],
62
+ offEffort?: Off,
63
+ ): Exclude<CodexReasoningEffort, "none" | "minimal"> | Off {
64
+ const clamped = supported?.length ? clampThinkingLevel(level, supported) : undefined;
65
+ const effective = clamped ?? (level === "off" ? "low" : level);
66
+ return effective === "off" ? (offEffort ?? ("minimal" as Off)) : effective;
44
67
  }