@kodelyth/codex 2026.5.42 → 2026.6.2

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 (138) hide show
  1. package/package.json +17 -2
  2. package/doctor-contract-api.test.ts +0 -44
  3. package/doctor-contract-api.ts +0 -68
  4. package/harness.ts +0 -72
  5. package/index.test.ts +0 -230
  6. package/index.ts +0 -66
  7. package/media-understanding-provider.test.ts +0 -486
  8. package/media-understanding-provider.ts +0 -521
  9. package/prompt-overlay-runtime-contract.test.ts +0 -48
  10. package/prompt-overlay.ts +0 -21
  11. package/provider-catalog.ts +0 -83
  12. package/provider-discovery.ts +0 -45
  13. package/provider.test.ts +0 -384
  14. package/provider.ts +0 -243
  15. package/src/app-server/app-inventory-cache.test.ts +0 -176
  16. package/src/app-server/app-inventory-cache.ts +0 -324
  17. package/src/app-server/approval-bridge.test.ts +0 -1471
  18. package/src/app-server/approval-bridge.ts +0 -1211
  19. package/src/app-server/auth-bridge.test.ts +0 -1449
  20. package/src/app-server/auth-bridge.ts +0 -614
  21. package/src/app-server/auth-profile-runtime-contract.test.ts +0 -239
  22. package/src/app-server/capabilities.ts +0 -27
  23. package/src/app-server/client-factory.ts +0 -24
  24. package/src/app-server/client.test.ts +0 -563
  25. package/src/app-server/client.ts +0 -715
  26. package/src/app-server/compact.test.ts +0 -710
  27. package/src/app-server/compact.ts +0 -500
  28. package/src/app-server/computer-use.test.ts +0 -788
  29. package/src/app-server/computer-use.ts +0 -683
  30. package/src/app-server/config.test.ts +0 -879
  31. package/src/app-server/config.ts +0 -1038
  32. package/src/app-server/context-engine-projection.test.ts +0 -252
  33. package/src/app-server/context-engine-projection.ts +0 -403
  34. package/src/app-server/delivery-no-reply-runtime-contract.test.ts +0 -80
  35. package/src/app-server/dynamic-tool-diagnostics.ts +0 -73
  36. package/src/app-server/dynamic-tool-profile.ts +0 -69
  37. package/src/app-server/dynamic-tools.test.ts +0 -1302
  38. package/src/app-server/dynamic-tools.ts +0 -623
  39. package/src/app-server/elicitation-bridge.test.ts +0 -1056
  40. package/src/app-server/elicitation-bridge.ts +0 -783
  41. package/src/app-server/event-projector.test.ts +0 -2668
  42. package/src/app-server/event-projector.ts +0 -2057
  43. package/src/app-server/image-payload-sanitizer.test.ts +0 -49
  44. package/src/app-server/image-payload-sanitizer.ts +0 -167
  45. package/src/app-server/klaw-owned-tool-runtime-contract.test.ts +0 -456
  46. package/src/app-server/local-runtime-attribution.ts +0 -39
  47. package/src/app-server/managed-binary.test.ts +0 -139
  48. package/src/app-server/managed-binary.ts +0 -193
  49. package/src/app-server/models.test.ts +0 -246
  50. package/src/app-server/models.ts +0 -172
  51. package/src/app-server/native-hook-relay.test.ts +0 -271
  52. package/src/app-server/native-hook-relay.ts +0 -150
  53. package/src/app-server/native-subagent-task-mirror.test.ts +0 -573
  54. package/src/app-server/native-subagent-task-mirror.ts +0 -497
  55. package/src/app-server/outcome-fallback-runtime-contract.test.ts +0 -404
  56. package/src/app-server/plugin-activation.test.ts +0 -336
  57. package/src/app-server/plugin-activation.ts +0 -283
  58. package/src/app-server/plugin-app-cache-key.ts +0 -74
  59. package/src/app-server/plugin-approval-roundtrip.ts +0 -122
  60. package/src/app-server/plugin-inventory.test.ts +0 -355
  61. package/src/app-server/plugin-inventory.ts +0 -357
  62. package/src/app-server/plugin-thread-config.test.ts +0 -865
  63. package/src/app-server/plugin-thread-config.ts +0 -455
  64. package/src/app-server/protocol-generated/json/DynamicToolCallParams.json +0 -33
  65. package/src/app-server/protocol-generated/json/v2/ErrorNotification.json +0 -199
  66. package/src/app-server/protocol-generated/json/v2/GetAccountResponse.json +0 -102
  67. package/src/app-server/protocol-generated/json/v2/ModelListResponse.json +0 -227
  68. package/src/app-server/protocol-generated/json/v2/ThreadResumeResponse.json +0 -2630
  69. package/src/app-server/protocol-generated/json/v2/ThreadStartResponse.json +0 -2630
  70. package/src/app-server/protocol-generated/json/v2/TurnCompletedNotification.json +0 -1659
  71. package/src/app-server/protocol-generated/json/v2/TurnStartResponse.json +0 -1655
  72. package/src/app-server/protocol-validators.test.ts +0 -75
  73. package/src/app-server/protocol-validators.ts +0 -203
  74. package/src/app-server/protocol.ts +0 -520
  75. package/src/app-server/rate-limit-cache.ts +0 -48
  76. package/src/app-server/rate-limits.test.ts +0 -202
  77. package/src/app-server/rate-limits.ts +0 -583
  78. package/src/app-server/request.ts +0 -73
  79. package/src/app-server/run-attempt.context-engine.test.ts +0 -1004
  80. package/src/app-server/run-attempt.test.ts +0 -9477
  81. package/src/app-server/run-attempt.ts +0 -4683
  82. package/src/app-server/run-attempt.vision-tools.test.ts +0 -35
  83. package/src/app-server/schema-normalization-runtime-contract.test.ts +0 -206
  84. package/src/app-server/session-binding.test.ts +0 -303
  85. package/src/app-server/session-binding.ts +0 -398
  86. package/src/app-server/session-history.ts +0 -44
  87. package/src/app-server/shared-client.test.ts +0 -589
  88. package/src/app-server/shared-client.ts +0 -289
  89. package/src/app-server/side-question.test.ts +0 -1175
  90. package/src/app-server/side-question.ts +0 -1007
  91. package/src/app-server/test-support.ts +0 -48
  92. package/src/app-server/thread-lifecycle.test.ts +0 -447
  93. package/src/app-server/thread-lifecycle.ts +0 -939
  94. package/src/app-server/thread-lifecycle.user-mcp-servers.test.ts +0 -442
  95. package/src/app-server/timeout.ts +0 -9
  96. package/src/app-server/tool-progress-normalization.ts +0 -77
  97. package/src/app-server/trajectory.test.ts +0 -205
  98. package/src/app-server/trajectory.ts +0 -365
  99. package/src/app-server/transcript-mirror.test.ts +0 -524
  100. package/src/app-server/transcript-mirror.ts +0 -208
  101. package/src/app-server/transcript-repair-runtime-contract.test.ts +0 -44
  102. package/src/app-server/transport-stdio.test.ts +0 -171
  103. package/src/app-server/transport-stdio.ts +0 -107
  104. package/src/app-server/transport-websocket.test.ts +0 -69
  105. package/src/app-server/transport-websocket.ts +0 -90
  106. package/src/app-server/transport.ts +0 -117
  107. package/src/app-server/user-input-bridge.test.ts +0 -249
  108. package/src/app-server/user-input-bridge.ts +0 -316
  109. package/src/app-server/version.ts +0 -4
  110. package/src/app-server/vision-tools.ts +0 -12
  111. package/src/command-account.ts +0 -544
  112. package/src/command-formatters.ts +0 -425
  113. package/src/command-handlers.ts +0 -2004
  114. package/src/command-rpc.test.ts +0 -16
  115. package/src/command-rpc.ts +0 -142
  116. package/src/commands.test.ts +0 -3312
  117. package/src/commands.ts +0 -65
  118. package/src/conversation-binding-data.ts +0 -124
  119. package/src/conversation-binding.test.ts +0 -599
  120. package/src/conversation-binding.ts +0 -561
  121. package/src/conversation-control.test.ts +0 -126
  122. package/src/conversation-control.ts +0 -303
  123. package/src/conversation-turn-collector.test.ts +0 -191
  124. package/src/conversation-turn-collector.ts +0 -186
  125. package/src/conversation-turn-input.test.ts +0 -141
  126. package/src/conversation-turn-input.ts +0 -106
  127. package/src/manifest.test.ts +0 -20
  128. package/src/migration/apply.ts +0 -501
  129. package/src/migration/helpers.ts +0 -55
  130. package/src/migration/plan.ts +0 -461
  131. package/src/migration/provider.test.ts +0 -1741
  132. package/src/migration/provider.ts +0 -41
  133. package/src/migration/source.ts +0 -643
  134. package/src/migration/targets.ts +0 -25
  135. package/src/node-cli-sessions.test.ts +0 -180
  136. package/src/node-cli-sessions.ts +0 -711
  137. package/test-api.ts +0 -82
  138. package/tsconfig.json +0 -16
@@ -1,39 +0,0 @@
1
- import type { EmbeddedRunAttemptParams } from "klaw/plugin-sdk/agent-harness-runtime";
2
-
3
- const OPENAI_PROVIDER_ID = "openai";
4
- const OPENAI_RESPONSES_API = "openai-responses";
5
- const OPENAI_CODEX_PROVIDER_ID = "openai-codex";
6
- const OPENAI_CODEX_RESPONSES_API = "openai-codex-responses";
7
-
8
- export type CodexLocalRuntimeAttribution = {
9
- provider: string;
10
- api?: string;
11
- };
12
-
13
- function normalizeRuntimeId(value: string | undefined): string {
14
- return value?.trim().toLowerCase() ?? "";
15
- }
16
-
17
- export function resolveCodexLocalRuntimeAttribution(
18
- params: EmbeddedRunAttemptParams,
19
- ): CodexLocalRuntimeAttribution {
20
- const authProfileProvider = normalizeRuntimeId(
21
- params.runtimePlan?.auth?.authProfileProviderForAuth,
22
- );
23
- if (
24
- normalizeRuntimeId(params.runtimePlan?.observability.harnessId) === "codex" &&
25
- authProfileProvider !== OPENAI_PROVIDER_ID &&
26
- normalizeRuntimeId(params.model.provider) === OPENAI_PROVIDER_ID &&
27
- normalizeRuntimeId(params.model.api) === OPENAI_RESPONSES_API
28
- ) {
29
- return {
30
- provider: OPENAI_CODEX_PROVIDER_ID,
31
- api: OPENAI_CODEX_RESPONSES_API,
32
- };
33
- }
34
-
35
- return {
36
- provider: params.provider,
37
- api: params.model.api,
38
- };
39
- }
@@ -1,139 +0,0 @@
1
- import { mkdir, mkdtemp, realpath, writeFile } from "node:fs/promises";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import { describe, expect, it, vi } from "vitest";
5
- import type { CodexAppServerStartOptions } from "./config.js";
6
- import {
7
- testing,
8
- resolveManagedCodexAppServerPaths,
9
- resolveManagedCodexAppServerStartOptions,
10
- } from "./managed-binary.js";
11
-
12
- function startOptions(
13
- commandSource: CodexAppServerStartOptions["commandSource"],
14
- ): CodexAppServerStartOptions {
15
- return {
16
- transport: "stdio",
17
- command: "codex",
18
- commandSource,
19
- args: ["app-server", "--listen", "stdio://"],
20
- headers: {},
21
- };
22
- }
23
-
24
- function managedCommandPath(root: string, platform: NodeJS.Platform): string {
25
- return path.join(root, "node_modules", ".bin", platform === "win32" ? "codex.cmd" : "codex");
26
- }
27
-
28
- describe("managed Codex app-server binary", () => {
29
- it("leaves explicit command overrides unchanged", async () => {
30
- const explicitOptions = startOptions("config");
31
- const pathExists = vi.fn(async () => false);
32
-
33
- await expect(
34
- resolveManagedCodexAppServerStartOptions(explicitOptions, {
35
- platform: "darwin",
36
- pathExists,
37
- }),
38
- ).resolves.toBe(explicitOptions);
39
- expect(pathExists).not.toHaveBeenCalled();
40
- });
41
-
42
- it("resolves the plugin-local bundled Codex binary", async () => {
43
- const pluginRoot = path.join("/tmp", "klaw", "extensions", "codex");
44
- const paths = resolveManagedCodexAppServerPaths({ platform: "darwin", pluginRoot });
45
- const pathExists = vi.fn(async (filePath: string) => filePath === paths.commandPath);
46
-
47
- await expect(
48
- resolveManagedCodexAppServerStartOptions(startOptions("managed"), {
49
- platform: "darwin",
50
- pluginRoot,
51
- pathExists,
52
- }),
53
- ).resolves.toEqual({
54
- ...startOptions("managed"),
55
- command: paths.commandPath,
56
- commandSource: "resolved-managed",
57
- });
58
- expect(paths.commandPath).toBe(managedCommandPath(pluginRoot, "darwin"));
59
- });
60
-
61
- it("resolves Windows Codex command shims", () => {
62
- const pluginRoot = path.win32.join("C:\\", "Klaw", "dist", "extensions", "codex");
63
- const paths = resolveManagedCodexAppServerPaths({ platform: "win32", pluginRoot });
64
-
65
- expect(paths.commandPath.endsWith(path.win32.join("node_modules", ".bin", "codex.cmd"))).toBe(
66
- true,
67
- );
68
- });
69
-
70
- it("uses the package root when the resolver is bundled into a dist chunk", () => {
71
- expect(testing.resolveDefaultCodexPluginRoot("/repo/klaw/dist")).toBe("/repo/klaw");
72
- expect(testing.resolveDefaultCodexPluginRoot("/repo/klaw/dist-runtime")).toBe("/repo/klaw");
73
- expect(
74
- testing.resolveDefaultCodexPluginRoot("/repo/klaw/extensions/codex/src/app-server"),
75
- ).toBe("/repo/klaw/extensions/codex");
76
- });
77
-
78
- it("finds Codex in the package install root used by packaged plugins", async () => {
79
- const installRoot = path.join("/tmp", "klaw-plugin-package", "codex");
80
- const pluginRoot = path.join(installRoot, "dist", "extensions", "codex");
81
- const installedCommand = managedCommandPath(installRoot, "linux");
82
- const pathExists = vi.fn(async (filePath: string) => filePath === installedCommand);
83
-
84
- await expect(
85
- resolveManagedCodexAppServerStartOptions(startOptions("managed"), {
86
- platform: "linux",
87
- pluginRoot,
88
- pathExists,
89
- }),
90
- ).resolves.toEqual({
91
- ...startOptions("managed"),
92
- command: installedCommand,
93
- commandSource: "resolved-managed",
94
- });
95
- });
96
-
97
- it("falls back to the resolved Codex package bin when no command shim exists", async () => {
98
- const installRoot = await mkdtemp(path.join(os.tmpdir(), "klaw-codex-package-"));
99
- const pluginRoot = path.join(installRoot, "dist", "extensions", "codex");
100
- const packageRoot = path.join(installRoot, "node_modules", "@openai", "codex");
101
- const packageBin = path.join(packageRoot, "bin", "codex.js");
102
- await mkdir(path.dirname(packageBin), { recursive: true });
103
- await writeFile(
104
- path.join(packageRoot, "package.json"),
105
- JSON.stringify({
106
- name: "@openai/codex",
107
- bin: {
108
- codex: "bin/codex.js",
109
- },
110
- }),
111
- );
112
- await writeFile(packageBin, "#!/usr/bin/env node\n");
113
- const resolvedPackageBin = await realpath(packageBin);
114
-
115
- const pathExists = vi.fn(async (filePath: string) => filePath === resolvedPackageBin);
116
-
117
- await expect(
118
- resolveManagedCodexAppServerStartOptions(startOptions("managed"), {
119
- platform: "linux",
120
- pluginRoot,
121
- pathExists,
122
- }),
123
- ).resolves.toEqual({
124
- ...startOptions("managed"),
125
- command: resolvedPackageBin,
126
- commandSource: "resolved-managed",
127
- });
128
- });
129
-
130
- it("fails clearly when the managed Codex binary is missing", async () => {
131
- await expect(
132
- resolveManagedCodexAppServerStartOptions(startOptions("managed"), {
133
- platform: "darwin",
134
- pluginRoot: path.join("/tmp", "klaw", "extensions", "codex"),
135
- pathExists: vi.fn(async () => false),
136
- }),
137
- ).rejects.toThrow("Managed Codex app-server binary was not found");
138
- });
139
- });
@@ -1,193 +0,0 @@
1
- import { constants as fsConstants, readFileSync } from "node:fs";
2
- import { access } from "node:fs/promises";
3
- import { createRequire } from "node:module";
4
- import path from "node:path";
5
- import { fileURLToPath } from "node:url";
6
- import type { CodexAppServerStartOptions } from "./config.js";
7
- import { MANAGED_CODEX_APP_SERVER_PACKAGE } from "./version.js";
8
-
9
- const CODEX_APP_SERVER_MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
10
- const CODEX_PLUGIN_ROOT = resolveDefaultCodexPluginRoot(CODEX_APP_SERVER_MODULE_DIR);
11
-
12
- type ManagedCodexAppServerPaths = {
13
- commandPath: string;
14
- candidateCommandPaths: string[];
15
- };
16
-
17
- type ResolveManagedCodexAppServerOptions = {
18
- platform?: NodeJS.Platform;
19
- pluginRoot?: string;
20
- pathExists?: (filePath: string, platform: NodeJS.Platform) => Promise<boolean>;
21
- };
22
-
23
- export async function resolveManagedCodexAppServerStartOptions(
24
- startOptions: CodexAppServerStartOptions,
25
- options: ResolveManagedCodexAppServerOptions = {},
26
- ): Promise<CodexAppServerStartOptions> {
27
- if (startOptions.transport !== "stdio" || startOptions.commandSource !== "managed") {
28
- return startOptions;
29
- }
30
-
31
- const platform = options.platform ?? process.platform;
32
- const paths = resolveManagedCodexAppServerPaths({
33
- platform,
34
- pluginRoot: options.pluginRoot,
35
- });
36
- const pathExists = options.pathExists ?? commandPathExists;
37
- const commandPath = await findManagedCodexAppServerCommandPath({
38
- candidateCommandPaths: paths.candidateCommandPaths,
39
- pathExists,
40
- platform,
41
- });
42
-
43
- return {
44
- ...startOptions,
45
- command: commandPath,
46
- commandSource: "resolved-managed",
47
- };
48
- }
49
-
50
- export function resolveManagedCodexAppServerPaths(params: {
51
- platform?: NodeJS.Platform;
52
- pluginRoot?: string;
53
- }): ManagedCodexAppServerPaths {
54
- const platform = params.platform ?? process.platform;
55
- const candidateCommandPaths = resolveManagedCodexAppServerCommandCandidates(
56
- params.pluginRoot ?? CODEX_PLUGIN_ROOT,
57
- platform,
58
- );
59
- return {
60
- commandPath: candidateCommandPaths[0] ?? "",
61
- candidateCommandPaths,
62
- };
63
- }
64
-
65
- function resolveManagedCodexAppServerCommandCandidates(
66
- pluginRoot: string,
67
- platform: NodeJS.Platform,
68
- ): string[] {
69
- const pathApi = pathForPlatform(platform);
70
- const commandName = platform === "win32" ? "codex.cmd" : "codex";
71
- const roots = resolveManagedCodexAppServerCandidateRoots(pluginRoot, platform);
72
- return [
73
- ...new Set([
74
- ...roots.map((root) => pathApi.join(root, "node_modules", ".bin", commandName)),
75
- ...resolveManagedCodexPackageBinCandidates(roots, platform),
76
- ]),
77
- ];
78
- }
79
-
80
- function resolveDefaultCodexPluginRoot(moduleDir: string): string {
81
- const moduleBaseName = path.basename(moduleDir);
82
- if (moduleBaseName === "dist" || moduleBaseName === "dist-runtime") {
83
- return path.dirname(moduleDir);
84
- }
85
- return path.resolve(moduleDir, "..", "..");
86
- }
87
-
88
- function resolveManagedCodexAppServerCandidateRoots(
89
- pluginRoot: string,
90
- platform: NodeJS.Platform,
91
- ): string[] {
92
- const pathApi = pathForPlatform(platform);
93
- return [
94
- pluginRoot,
95
- pathApi.dirname(pluginRoot),
96
- pathApi.dirname(pathApi.dirname(pluginRoot)),
97
- isDistExtensionRoot(pluginRoot, platform)
98
- ? pathApi.dirname(pathApi.dirname(pathApi.dirname(pluginRoot)))
99
- : null,
100
- ].filter((root): root is string => Boolean(root));
101
- }
102
-
103
- function resolveManagedCodexPackageBinCandidates(
104
- roots: readonly string[],
105
- platform: NodeJS.Platform,
106
- ): string[] {
107
- if (platform === "win32") {
108
- return [];
109
- }
110
-
111
- const candidates: string[] = [];
112
- for (const root of roots) {
113
- const candidate = resolveManagedCodexPackageBinCandidate(root);
114
- if (candidate) {
115
- candidates.push(candidate);
116
- }
117
- }
118
- return candidates;
119
- }
120
-
121
- function resolveManagedCodexPackageBinCandidate(root: string): string | null {
122
- try {
123
- const requireFromRoot = createRequire(path.join(root, "package.json"));
124
- const packageJsonPath = requireFromRoot.resolve(
125
- `${MANAGED_CODEX_APP_SERVER_PACKAGE}/package.json`,
126
- );
127
- const packageRoot = path.dirname(packageJsonPath);
128
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8")) as {
129
- bin?: unknown;
130
- };
131
- const binPath =
132
- typeof packageJson.bin === "string"
133
- ? packageJson.bin
134
- : isRecord(packageJson.bin) && typeof packageJson.bin.codex === "string"
135
- ? packageJson.bin.codex
136
- : null;
137
- return binPath ? path.resolve(packageRoot, binPath) : null;
138
- } catch {
139
- return null;
140
- }
141
- }
142
-
143
- function isRecord(value: unknown): value is Record<string, unknown> {
144
- return typeof value === "object" && value !== null;
145
- }
146
-
147
- export const testing = {
148
- resolveDefaultCodexPluginRoot,
149
- };
150
-
151
- function isDistExtensionRoot(pluginRoot: string, platform: NodeJS.Platform): boolean {
152
- const pathApi = pathForPlatform(platform);
153
- const extensionsDir = pathApi.dirname(pluginRoot);
154
- const distDir = pathApi.dirname(extensionsDir);
155
- return (
156
- pathApi.basename(extensionsDir) === "extensions" &&
157
- (pathApi.basename(distDir) === "dist" || pathApi.basename(distDir) === "dist-runtime")
158
- );
159
- }
160
-
161
- function pathForPlatform(platform: NodeJS.Platform): typeof path {
162
- return platform === "win32" ? path.win32 : path.posix;
163
- }
164
-
165
- async function findManagedCodexAppServerCommandPath(params: {
166
- candidateCommandPaths: readonly string[];
167
- pathExists: (filePath: string, platform: NodeJS.Platform) => Promise<boolean>;
168
- platform: NodeJS.Platform;
169
- }): Promise<string> {
170
- for (const commandPath of params.candidateCommandPaths) {
171
- if (await params.pathExists(commandPath, params.platform)) {
172
- return commandPath;
173
- }
174
- }
175
-
176
- throw new Error(
177
- [
178
- `Managed Codex app-server binary was not found for ${MANAGED_CODEX_APP_SERVER_PACKAGE}.`,
179
- "Reinstall or update Klaw, or run pnpm install in a source checkout.",
180
- "Set plugins.entries.codex.config.appServer.command or KLAW_CODEX_APP_SERVER_BIN to use a custom Codex binary.",
181
- ].join(" "),
182
- );
183
- }
184
-
185
- async function commandPathExists(filePath: string, platform: NodeJS.Platform): Promise<boolean> {
186
- try {
187
- await access(filePath, platform === "win32" ? fsConstants.F_OK : fsConstants.X_OK);
188
- return true;
189
- } catch {
190
- return false;
191
- }
192
- }
193
- export { testing as __testing };
@@ -1,246 +0,0 @@
1
- import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
2
- import { CodexAppServerClient } from "./client.js";
3
- import { createClientHarness } from "./test-support.js";
4
-
5
- const mocks = vi.hoisted(() => {
6
- const authBridge = {
7
- applyAuthProfile: vi.fn(async () => undefined),
8
- authProfileId: vi.fn((params?: { authProfileId?: string }) => params?.authProfileId),
9
- startOptions: vi.fn(async ({ startOptions }) => startOptions),
10
- };
11
- const managedBinary = {
12
- startOptions: vi.fn(async (startOptions) => startOptions),
13
- };
14
- const providerAuth = {
15
- agentDir: vi.fn(() => "/tmp/klaw-agent"),
16
- };
17
- return { authBridge, managedBinary, providerAuth };
18
- });
19
-
20
- vi.mock("./auth-bridge.js", () => ({
21
- applyCodexAppServerAuthProfile: mocks.authBridge.applyAuthProfile,
22
- bridgeCodexAppServerStartOptions: mocks.authBridge.startOptions,
23
- resolveCodexAppServerAuthProfileIdForAgent: mocks.authBridge.authProfileId,
24
- }));
25
-
26
- vi.mock("./managed-binary.js", () => ({
27
- resolveManagedCodexAppServerStartOptions: mocks.managedBinary.startOptions,
28
- }));
29
-
30
- vi.mock("klaw/plugin-sdk/agent-runtime", () => ({
31
- resolveDefaultAgentDir: mocks.providerAuth.agentDir,
32
- }));
33
-
34
- let listCodexAppServerModels: typeof import("./models.js").listCodexAppServerModels;
35
- let listAllCodexAppServerModels: typeof import("./models.js").listAllCodexAppServerModels;
36
- let resetSharedCodexAppServerClientForTests: typeof import("./shared-client.js").resetSharedCodexAppServerClientForTests;
37
-
38
- describe("listCodexAppServerModels", () => {
39
- beforeAll(async () => {
40
- ({ listCodexAppServerModels } = await import("./models.js"));
41
- ({ listAllCodexAppServerModels } = await import("./models.js"));
42
- ({ resetSharedCodexAppServerClientForTests } = await import("./shared-client.js"));
43
- });
44
-
45
- afterEach(() => {
46
- resetSharedCodexAppServerClientForTests();
47
- vi.restoreAllMocks();
48
- mocks.authBridge.applyAuthProfile.mockClear();
49
- mocks.authBridge.authProfileId.mockClear();
50
- mocks.authBridge.authProfileId.mockImplementation(
51
- (params?: { authProfileId?: string }) => params?.authProfileId,
52
- );
53
- mocks.authBridge.startOptions.mockClear();
54
- mocks.managedBinary.startOptions.mockClear();
55
- mocks.managedBinary.startOptions.mockImplementation(async (startOptions) => startOptions);
56
- mocks.providerAuth.agentDir.mockClear();
57
- });
58
-
59
- it("lists app-server models through the typed helper", async () => {
60
- const harness = createClientHarness();
61
- const startSpy = vi.spyOn(CodexAppServerClient, "start").mockReturnValue(harness.client);
62
-
63
- const listPromise = listCodexAppServerModels({ limit: 12, timeoutMs: 1000 });
64
- await vi.waitFor(() => expect(harness.writes.length).toBeGreaterThanOrEqual(1));
65
- const initialize = JSON.parse(harness.writes[0] ?? "{}") as { id?: number };
66
- harness.send({
67
- id: initialize.id,
68
- result: { userAgent: "klaw/0.125.0 (macOS; test)" },
69
- });
70
- await vi.waitFor(() => expect(harness.writes.length).toBeGreaterThanOrEqual(3));
71
- const list = JSON.parse(harness.writes[2] ?? "{}") as { id?: number; method?: string };
72
- expect(list.method).toBe("model/list");
73
-
74
- harness.send({
75
- id: list.id,
76
- result: {
77
- data: [
78
- {
79
- id: "gpt-5.4",
80
- model: "gpt-5.4",
81
- upgrade: null,
82
- upgradeInfo: null,
83
- availabilityNux: null,
84
- displayName: "gpt-5.4",
85
- description: "GPT-5.4",
86
- hidden: false,
87
- inputModalities: ["text", "image"],
88
- supportedReasoningEfforts: [
89
- { reasoningEffort: "low", description: "fast" },
90
- { reasoningEffort: "xhigh", description: "deep" },
91
- ],
92
- defaultReasoningEffort: "medium",
93
- supportsPersonality: false,
94
- additionalSpeedTiers: [],
95
- isDefault: true,
96
- },
97
- ],
98
- nextCursor: null,
99
- },
100
- });
101
-
102
- await expect(listPromise).resolves.toEqual({
103
- models: [
104
- {
105
- id: "gpt-5.4",
106
- model: "gpt-5.4",
107
- displayName: "gpt-5.4",
108
- description: "GPT-5.4",
109
- hidden: false,
110
- inputModalities: ["text", "image"],
111
- supportedReasoningEfforts: ["low", "xhigh"],
112
- defaultReasoningEffort: "medium",
113
- isDefault: true,
114
- },
115
- ],
116
- });
117
- harness.client.close();
118
- startSpy.mockRestore();
119
- });
120
-
121
- it("lists all app-server model pages through one client", async () => {
122
- const harness = createClientHarness();
123
- const startSpy = vi.spyOn(CodexAppServerClient, "start").mockReturnValue(harness.client);
124
-
125
- const listPromise = listAllCodexAppServerModels({ limit: 1, timeoutMs: 1000 });
126
- await vi.waitFor(() => expect(harness.writes.length).toBeGreaterThanOrEqual(1));
127
- const initialize = JSON.parse(harness.writes[0] ?? "{}") as { id?: number };
128
- harness.send({
129
- id: initialize.id,
130
- result: { userAgent: "klaw/0.125.0 (macOS; test)" },
131
- });
132
- await vi.waitFor(() => expect(harness.writes.length).toBeGreaterThanOrEqual(3));
133
- const firstList = JSON.parse(harness.writes[2] ?? "{}") as {
134
- id?: number;
135
- params?: { cursor?: string | null };
136
- };
137
- expect(firstList.params?.cursor).toBeNull();
138
-
139
- harness.send({
140
- id: firstList.id,
141
- result: {
142
- data: [
143
- {
144
- id: "gpt-5.4",
145
- model: "gpt-5.4",
146
- upgrade: null,
147
- upgradeInfo: null,
148
- availabilityNux: null,
149
- displayName: "gpt-5.4",
150
- description: "GPT-5.4",
151
- hidden: false,
152
- inputModalities: ["text"],
153
- supportedReasoningEfforts: [],
154
- defaultReasoningEffort: "medium",
155
- supportsPersonality: false,
156
- additionalSpeedTiers: [],
157
- isDefault: false,
158
- },
159
- ],
160
- nextCursor: "page-2",
161
- },
162
- });
163
- await vi.waitFor(() => expect(harness.writes.length).toBeGreaterThanOrEqual(4));
164
- const secondList = JSON.parse(harness.writes[3] ?? "{}") as {
165
- id?: number;
166
- params?: { cursor?: string | null };
167
- };
168
- expect(secondList.params?.cursor).toBe("page-2");
169
-
170
- harness.send({
171
- id: secondList.id,
172
- result: {
173
- data: [
174
- {
175
- id: "gpt-5.2",
176
- model: "gpt-5.2",
177
- upgrade: null,
178
- upgradeInfo: null,
179
- availabilityNux: null,
180
- displayName: "gpt-5.2",
181
- description: "GPT-5.2",
182
- hidden: false,
183
- inputModalities: ["text", "image"],
184
- supportedReasoningEfforts: [],
185
- defaultReasoningEffort: "medium",
186
- supportsPersonality: false,
187
- additionalSpeedTiers: [],
188
- isDefault: false,
189
- },
190
- ],
191
- nextCursor: null,
192
- },
193
- });
194
-
195
- const list = await listPromise;
196
- expect(list.models.map((model) => model.id)).toEqual(["gpt-5.4", "gpt-5.2"]);
197
- harness.client.close();
198
- startSpy.mockRestore();
199
- });
200
-
201
- it("marks all-model listing truncated after the page cap", async () => {
202
- const harness = createClientHarness();
203
- const startSpy = vi.spyOn(CodexAppServerClient, "start").mockReturnValue(harness.client);
204
-
205
- const listPromise = listAllCodexAppServerModels({ limit: 1, timeoutMs: 1000, maxPages: 1 });
206
- await vi.waitFor(() => expect(harness.writes.length).toBeGreaterThanOrEqual(1));
207
- const initialize = JSON.parse(harness.writes[0] ?? "{}") as { id?: number };
208
- harness.send({
209
- id: initialize.id,
210
- result: { userAgent: "klaw/0.125.0 (macOS; test)" },
211
- });
212
- await vi.waitFor(() => expect(harness.writes.length).toBeGreaterThanOrEqual(3));
213
- const firstList = JSON.parse(harness.writes[2] ?? "{}") as { id?: number };
214
- harness.send({
215
- id: firstList.id,
216
- result: {
217
- data: [
218
- {
219
- id: "gpt-5.4",
220
- model: "gpt-5.4",
221
- upgrade: null,
222
- upgradeInfo: null,
223
- availabilityNux: null,
224
- displayName: "gpt-5.4",
225
- description: "GPT-5.4",
226
- hidden: false,
227
- inputModalities: ["text"],
228
- supportedReasoningEfforts: [],
229
- defaultReasoningEffort: "medium",
230
- supportsPersonality: false,
231
- additionalSpeedTiers: [],
232
- isDefault: false,
233
- },
234
- ],
235
- nextCursor: "page-2",
236
- },
237
- });
238
-
239
- const list = await listPromise;
240
- expect(list.models.map((model) => model.id)).toEqual(["gpt-5.4"]);
241
- expect(list.nextCursor).toBe("page-2");
242
- expect(list.truncated).toBe(true);
243
- harness.client.close();
244
- startSpy.mockRestore();
245
- });
246
- });