@kodelyth/codex 2026.5.42 → 2026.6.1

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 +16 -1
  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,176 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import {
3
- CodexAppInventoryCache,
4
- buildCodexAppInventoryCacheKey,
5
- serializeCodexAppInventoryError,
6
- } from "./app-inventory-cache.js";
7
- import type { v2 } from "./protocol.js";
8
-
9
- describe("Codex app inventory cache", () => {
10
- it("returns missing while scheduling one coalesced app/list refresh", async () => {
11
- const cache = new CodexAppInventoryCache({ ttlMs: 100 });
12
- const request = vi.fn(async (_method: "app/list", params: v2.AppsListParams) => {
13
- return {
14
- data: [app(params.cursor ? "app-2" : "app-1")],
15
- nextCursor: params.cursor ? null : "next",
16
- } satisfies v2.AppsListResponse;
17
- });
18
-
19
- const key = buildCodexAppInventoryCacheKey({ codexHome: "/codex", authProfileId: "work" });
20
- const read = cache.read({ key, request, nowMs: 0 });
21
- expect(read.state).toBe("missing");
22
- expect(read.refreshScheduled).toBe(true);
23
-
24
- const snapshot = await cache.refreshNow({ key, request, nowMs: 0 });
25
- expect(snapshot.apps.map((item) => item.id)).toEqual(["app-1", "app-2"]);
26
- expect(request).toHaveBeenCalledTimes(2);
27
-
28
- const fresh = cache.read({ key, request, nowMs: 50 });
29
- expect(fresh.state).toBe("fresh");
30
- expect(fresh.refreshScheduled).toBe(false);
31
- expect(fresh.snapshot?.apps.map((item) => item.id)).toEqual(["app-1", "app-2"]);
32
- });
33
-
34
- it("can read missing inventory without scheduling app/list", async () => {
35
- const cache = new CodexAppInventoryCache({ ttlMs: 100 });
36
- const request = vi.fn(async () => {
37
- return {
38
- data: [app("app-1")],
39
- nextCursor: null,
40
- } satisfies v2.AppsListResponse;
41
- });
42
-
43
- const read = cache.read({
44
- key: "runtime",
45
- request,
46
- suppressRefresh: true,
47
- });
48
-
49
- expect(read.state).toBe("missing");
50
- expect(read.refreshScheduled).toBe(false);
51
- expect(request).not.toHaveBeenCalled();
52
- });
53
-
54
- it("uses stale inventory for the current read while still refreshing asynchronously", async () => {
55
- const cache = new CodexAppInventoryCache({ ttlMs: 10 });
56
- const request = vi.fn(async () => {
57
- return {
58
- data: [app(`app-${request.mock.calls.length}`)],
59
- nextCursor: null,
60
- } satisfies v2.AppsListResponse;
61
- });
62
- const key = "runtime";
63
- await cache.refreshNow({ key, request, nowMs: 0 });
64
-
65
- const stale = cache.read({ key, request, nowMs: 11, suppressRefresh: true });
66
- expect(stale.state).toBe("stale");
67
- expect(stale.snapshot?.apps.map((item) => item.id)).toEqual(["app-1"]);
68
- expect(stale.refreshScheduled).toBe(true);
69
-
70
- const refreshed = await cache.refreshNow({ key, request, nowMs: 11 });
71
- expect(refreshed.apps.map((item) => item.id)).toEqual(["app-2"]);
72
- });
73
-
74
- it("records refresh errors without discarding the last successful snapshot", async () => {
75
- const cache = new CodexAppInventoryCache({ ttlMs: 1 });
76
- const key = "runtime";
77
- await cache.refreshNow({
78
- key,
79
- nowMs: 0,
80
- request: async () => ({ data: [app("app-1")], nextCursor: null }),
81
- });
82
-
83
- await expect(
84
- cache.refreshNow({
85
- key,
86
- nowMs: 2,
87
- request: async () => {
88
- throw new Error("app list failed");
89
- },
90
- }),
91
- ).rejects.toThrow("app list failed");
92
-
93
- const read = cache.read({
94
- key,
95
- nowMs: 2,
96
- request: async () => ({ data: [app("app-2")], nextCursor: null }),
97
- });
98
- expect(read.snapshot?.apps.map((item) => item.id)).toEqual(["app-1"]);
99
- expect(read.diagnostic?.message).toBe("app list failed");
100
- });
101
-
102
- it("omits challenge HTML when serializing app/list errors", () => {
103
- const error = new Error(
104
- 'failed to list apps: Request failed with status 403 Forbidden: <html><script src="/backend-api/connectors/directory/list?__cf_chl_tk=secret-token"></script></html>',
105
- );
106
- const serialized = serializeCodexAppInventoryError(error);
107
-
108
- expect(serialized.message).toBe(
109
- "failed to list apps: Request failed with status 403 Forbidden: [HTML response body omitted]",
110
- );
111
- });
112
-
113
- it("forces a post-install refresh past an older in-flight app/list", async () => {
114
- const cache = new CodexAppInventoryCache({ ttlMs: 1_000 });
115
- const key = "runtime";
116
- let resolveStale: ((response: v2.AppsListResponse) => void) | undefined;
117
- let resolveFresh: ((response: v2.AppsListResponse) => void) | undefined;
118
- const request = vi.fn(
119
- async (_method: "app/list", params: v2.AppsListParams): Promise<v2.AppsListResponse> => {
120
- expect(params.forceRefetch).toBe(request.mock.calls.length === 2);
121
- return await new Promise((resolve) => {
122
- if (request.mock.calls.length === 1) {
123
- resolveStale = resolve;
124
- } else {
125
- resolveFresh = resolve;
126
- }
127
- });
128
- },
129
- );
130
-
131
- const staleRead = cache.read({ key, request, nowMs: 0 });
132
- expect(staleRead.state).toBe("missing");
133
- expect(staleRead.refreshScheduled).toBe(true);
134
-
135
- cache.invalidate(key, "plugin installed", 1);
136
- const forcedRead = cache.read({ key, request, nowMs: 1, forceRefetch: true });
137
- expect(forcedRead.state).toBe("missing");
138
- expect(forcedRead.refreshScheduled).toBe(true);
139
- expect(request).toHaveBeenCalledTimes(2);
140
-
141
- const forced = cache.refreshNow({ key, request, nowMs: 1 });
142
- resolveFresh?.({ data: [app("fresh-app")], nextCursor: null });
143
- await expect(forced).resolves.toStrictEqual({
144
- key,
145
- apps: [app("fresh-app")],
146
- fetchedAtMs: 1,
147
- expiresAtMs: 1_001,
148
- revision: 2,
149
- });
150
-
151
- resolveStale?.({ data: [app("stale-app")], nextCursor: null });
152
- await Promise.resolve();
153
-
154
- const freshRead = cache.read({ key, request, nowMs: 2 });
155
- expect(freshRead.state).toBe("fresh");
156
- expect(freshRead.snapshot?.apps.map((item) => item.id)).toEqual(["fresh-app"]);
157
- });
158
- });
159
-
160
- function app(id: string): v2.AppInfo {
161
- return {
162
- id,
163
- name: id,
164
- description: null,
165
- logoUrl: null,
166
- logoUrlDark: null,
167
- distributionChannel: null,
168
- branding: null,
169
- appMetadata: null,
170
- labels: null,
171
- installUrl: null,
172
- isAccessible: true,
173
- isEnabled: true,
174
- pluginDisplayNames: [],
175
- };
176
- }
@@ -1,324 +0,0 @@
1
- import { embeddedAgentLog } from "klaw/plugin-sdk/agent-harness-runtime";
2
- import type { JsonValue, v2 } from "./protocol.js";
3
-
4
- export const CODEX_APP_INVENTORY_CACHE_TTL_MS = 60 * 60 * 1_000;
5
- const MAX_SERIALIZED_ERROR_MESSAGE_LENGTH = 500;
6
-
7
- export type CodexAppInventoryRequest = (
8
- method: "app/list",
9
- params: v2.AppsListParams,
10
- ) => Promise<v2.AppsListResponse>;
11
-
12
- export type CodexAppInventoryCacheKeyInput = {
13
- codexHome?: string;
14
- endpoint?: string;
15
- authProfileId?: string;
16
- accountId?: string;
17
- envApiKeyFingerprint?: string;
18
- appServerVersion?: string;
19
- };
20
-
21
- export type CodexAppInventoryCacheDiagnostic = {
22
- message: string;
23
- atMs: number;
24
- };
25
-
26
- export type CodexAppInventorySnapshot = {
27
- key: string;
28
- apps: v2.AppInfo[];
29
- fetchedAtMs: number;
30
- expiresAtMs: number;
31
- revision: number;
32
- lastError?: CodexAppInventoryCacheDiagnostic;
33
- };
34
-
35
- export type CodexAppInventoryReadState = "fresh" | "stale" | "missing";
36
-
37
- export type CodexAppInventoryCacheRead = {
38
- state: CodexAppInventoryReadState;
39
- key: string;
40
- revision: number;
41
- snapshot?: CodexAppInventorySnapshot;
42
- refreshScheduled: boolean;
43
- diagnostic?: CodexAppInventoryCacheDiagnostic;
44
- };
45
-
46
- type CacheEntry = CodexAppInventorySnapshot & {
47
- invalidated: boolean;
48
- };
49
-
50
- type RefreshParams = {
51
- key: string;
52
- request: CodexAppInventoryRequest;
53
- nowMs?: number;
54
- forceRefetch?: boolean;
55
- suppressRefresh?: boolean;
56
- };
57
-
58
- export class CodexAppInventoryCache {
59
- private readonly ttlMs: number;
60
- private readonly entries = new Map<string, CacheEntry>();
61
- private readonly inFlight = new Map<string, Promise<CodexAppInventorySnapshot>>();
62
- // Per-key refresh generation. Each refresh attempt claims the next token so
63
- // an older request that finishes late cannot overwrite a newer snapshot.
64
- private readonly refreshTokens = new Map<string, number>();
65
- private readonly diagnostics = new Map<string, CodexAppInventoryCacheDiagnostic>();
66
- private revision = 0;
67
-
68
- constructor(options: { ttlMs?: number } = {}) {
69
- this.ttlMs = options.ttlMs ?? CODEX_APP_INVENTORY_CACHE_TTL_MS;
70
- }
71
-
72
- read(params: RefreshParams): CodexAppInventoryCacheRead {
73
- const nowMs = params.nowMs ?? Date.now();
74
- const entry = this.entries.get(params.key);
75
- if (!entry) {
76
- const refreshScheduled = params.suppressRefresh ? false : this.scheduleRefresh(params);
77
- return {
78
- state: "missing",
79
- key: params.key,
80
- revision: this.revision,
81
- refreshScheduled,
82
- ...(this.diagnostics.get(params.key)
83
- ? { diagnostic: this.diagnostics.get(params.key) }
84
- : {}),
85
- };
86
- }
87
-
88
- const state: CodexAppInventoryReadState =
89
- entry.invalidated || entry.expiresAtMs <= nowMs ? "stale" : "fresh";
90
- const refreshScheduled =
91
- state === "fresh" && !params.forceRefetch ? false : this.scheduleRefresh(params);
92
- return {
93
- state,
94
- key: params.key,
95
- revision: entry.revision,
96
- snapshot: stripEntryState(entry),
97
- refreshScheduled,
98
- ...(entry.lastError ? { diagnostic: entry.lastError } : {}),
99
- };
100
- }
101
-
102
- refreshNow(params: RefreshParams): Promise<CodexAppInventorySnapshot> {
103
- return this.refresh(params);
104
- }
105
-
106
- invalidate(key: string, reason: string, nowMs = Date.now()): number {
107
- this.revision += 1;
108
- const diagnostic = { message: reason, atMs: nowMs };
109
- const entry = this.entries.get(key);
110
- if (entry) {
111
- entry.invalidated = true;
112
- entry.lastError = diagnostic;
113
- entry.revision = this.revision;
114
- } else {
115
- this.diagnostics.set(key, diagnostic);
116
- }
117
- return this.revision;
118
- }
119
-
120
- clear(): void {
121
- this.entries.clear();
122
- this.inFlight.clear();
123
- this.refreshTokens.clear();
124
- this.diagnostics.clear();
125
- this.revision = 0;
126
- }
127
-
128
- getRevision(): number {
129
- return this.revision;
130
- }
131
-
132
- private scheduleRefresh(params: RefreshParams): boolean {
133
- if (this.inFlight.has(params.key) && !params.forceRefetch) {
134
- return true;
135
- }
136
- const promise = this.refresh(params);
137
- this.inFlight.set(params.key, promise);
138
- promise.catch(() => undefined);
139
- return true;
140
- }
141
-
142
- private async refresh(params: RefreshParams): Promise<CodexAppInventorySnapshot> {
143
- const existing = this.inFlight.get(params.key);
144
- if (existing && !params.forceRefetch) {
145
- return existing;
146
- }
147
-
148
- const refreshToken = (this.refreshTokens.get(params.key) ?? 0) + 1;
149
- this.refreshTokens.set(params.key, refreshToken);
150
- const promise = this.refreshUncoalesced(params, refreshToken);
151
- this.inFlight.set(params.key, promise);
152
- try {
153
- return await promise;
154
- } finally {
155
- if (this.inFlight.get(params.key) === promise) {
156
- this.inFlight.delete(params.key);
157
- }
158
- }
159
- }
160
-
161
- private async refreshUncoalesced(
162
- params: RefreshParams,
163
- refreshToken: number,
164
- ): Promise<CodexAppInventorySnapshot> {
165
- const nowMs = params.nowMs ?? Date.now();
166
- try {
167
- const apps = await listAllApps(params.request, params.forceRefetch ?? false);
168
- this.revision += 1;
169
- const snapshot: CodexAppInventorySnapshot = {
170
- key: params.key,
171
- apps,
172
- fetchedAtMs: nowMs,
173
- expiresAtMs: nowMs + this.ttlMs,
174
- revision: this.revision,
175
- };
176
- // Only publish this snapshot if no newer refresh started for the same key
177
- // while this request was in flight.
178
- if (this.refreshTokens.get(params.key) === refreshToken) {
179
- this.entries.set(params.key, { ...snapshot, invalidated: false });
180
- this.diagnostics.delete(params.key);
181
- }
182
- return snapshot;
183
- } catch (error) {
184
- const diagnostic = {
185
- message: sanitizeErrorMessage(error instanceof Error ? error.message : String(error)),
186
- atMs: nowMs,
187
- };
188
- this.diagnostics.set(params.key, diagnostic);
189
- const entry = this.entries.get(params.key);
190
- if (entry) {
191
- entry.lastError = diagnostic;
192
- }
193
- embeddedAgentLog.warn("codex app inventory refresh failed", {
194
- forceRefetch: params.forceRefetch === true,
195
- keyFingerprint: fingerprintInventoryCacheKey(params.key),
196
- error: serializeCodexAppInventoryError(error),
197
- });
198
- throw error;
199
- }
200
- }
201
- }
202
-
203
- export function serializeCodexAppInventoryError(error: unknown): Record<string, unknown> {
204
- const record = isRecord(error) ? error : undefined;
205
- const data = record && "data" in record ? redactErrorData(record.data) : undefined;
206
- return {
207
- name:
208
- error instanceof Error
209
- ? error.name
210
- : typeof record?.name === "string"
211
- ? record.name
212
- : undefined,
213
- message: sanitizeErrorMessage(error instanceof Error ? error.message : String(error)),
214
- ...(typeof record?.code === "number" ? { code: record.code } : {}),
215
- ...(data !== undefined ? { data } : {}),
216
- };
217
- }
218
-
219
- export const defaultCodexAppInventoryCache = new CodexAppInventoryCache();
220
-
221
- export function buildCodexAppInventoryCacheKey(input: CodexAppInventoryCacheKeyInput): string {
222
- return JSON.stringify({
223
- codexHome: input.codexHome ?? null,
224
- endpoint: input.endpoint ?? null,
225
- authProfileId: input.authProfileId ?? null,
226
- accountId: input.accountId ?? null,
227
- envApiKeyFingerprint: input.envApiKeyFingerprint ?? null,
228
- appServerVersion: input.appServerVersion ?? null,
229
- });
230
- }
231
-
232
- async function listAllApps(
233
- request: CodexAppInventoryRequest,
234
- forceRefetch: boolean,
235
- ): Promise<v2.AppInfo[]> {
236
- const apps: v2.AppInfo[] = [];
237
- let cursor: string | null | undefined;
238
- do {
239
- const response = await request("app/list", {
240
- cursor,
241
- limit: 100,
242
- forceRefetch,
243
- });
244
- apps.push(...response.data);
245
- cursor = response.nextCursor;
246
- } while (cursor);
247
- return apps;
248
- }
249
-
250
- function stripEntryState(entry: CacheEntry): CodexAppInventorySnapshot {
251
- const { invalidated: _invalidated, ...snapshot } = entry;
252
- return snapshot;
253
- }
254
-
255
- function fingerprintInventoryCacheKey(key: string): string {
256
- let hash = 0;
257
- for (let index = 0; index < key.length; index += 1) {
258
- hash = (hash * 31 + key.charCodeAt(index)) >>> 0;
259
- }
260
- return hash.toString(16).padStart(8, "0");
261
- }
262
-
263
- function isRecord(value: unknown): value is Record<string, unknown> {
264
- return Boolean(value && typeof value === "object" && !Array.isArray(value));
265
- }
266
-
267
- function redactErrorData(value: unknown, depth = 0): JsonValue | undefined {
268
- if (value === undefined) {
269
- return undefined;
270
- }
271
- if (value === null || typeof value === "boolean" || typeof value === "number") {
272
- return value;
273
- }
274
- if (depth > 6) {
275
- return "[truncated]";
276
- }
277
- if (Array.isArray(value)) {
278
- return value.map((entry) => redactErrorData(entry, depth + 1) ?? null);
279
- }
280
- if (isRecord(value)) {
281
- const redacted: Record<string, JsonValue> = {};
282
- for (const [key, entry] of Object.entries(value)) {
283
- redacted[key] = isSensitiveErrorDataKey(key)
284
- ? "<redacted>"
285
- : (redactErrorData(entry, depth + 1) ?? null);
286
- }
287
- return redacted;
288
- }
289
- if (typeof value === "string" && value.length > 500) {
290
- return `${value.slice(0, 500)}...`;
291
- }
292
- if (typeof value === "string") {
293
- return value;
294
- }
295
- if (typeof value === "bigint") {
296
- return value.toString();
297
- }
298
- if (typeof value === "symbol") {
299
- return value.description ? `Symbol(${value.description})` : "Symbol()";
300
- }
301
- if (typeof value === "function") {
302
- return value.name ? `[function ${value.name}]` : "[function]";
303
- }
304
- return "[unserializable]";
305
- }
306
-
307
- function sanitizeErrorMessage(message: string): string {
308
- const htmlStart = message.search(/<html[\s>]/i);
309
- const withoutHtml =
310
- htmlStart >= 0
311
- ? `${message.slice(0, htmlStart).trimEnd()} [HTML response body omitted]`
312
- : message;
313
- const redacted = withoutHtml.replace(
314
- /([?&][^=\s"'<>]*(?:api[_-]?key|authorization|cookie|credential|password|secret|token|tk)[^=\s"'<>]*=)[^&\s"'<>]+/gi,
315
- "$1<redacted>",
316
- );
317
- return redacted.length > MAX_SERIALIZED_ERROR_MESSAGE_LENGTH
318
- ? `${redacted.slice(0, MAX_SERIALIZED_ERROR_MESSAGE_LENGTH)}...`
319
- : redacted;
320
- }
321
-
322
- function isSensitiveErrorDataKey(key: string): boolean {
323
- return /api[_-]?key|authorization|cookie|credential|password|secret|token/i.test(key);
324
- }