@codex-app-sdk/backend 0.14.4 → 0.15.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.
- package/assets/apple-speechanalyzer-cli +0 -0
- package/dist/index.js +934 -824
- package/dist/index.js.map +1 -1
- package/dist/node/apple-speech-session.d.ts +13 -0
- package/dist/node/apple-speech-session.d.ts.map +1 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/native/apple-speech.swift +128 -0
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -2,82 +2,84 @@ import { i as e, n as t, r as n, s as r } from "./chunks/codex-DzX6RrF2.js";
|
|
|
2
2
|
import { execFile as i, execFileSync as a, spawn as o } from "node:child_process";
|
|
3
3
|
import { constants as s } from "node:buffer";
|
|
4
4
|
import { existsSync as c, promises as l, readFileSync as u, readdirSync as d } from "node:fs";
|
|
5
|
-
import f, { homedir as p } from "node:os";
|
|
6
|
-
import
|
|
7
|
-
import { randomBytes as
|
|
8
|
-
import { createConnection as
|
|
9
|
-
import { diffCodexSurfaceState as
|
|
10
|
-
import { fileURLToPath as
|
|
11
|
-
import { isDeepStrictEqual as
|
|
5
|
+
import f, { homedir as p, tmpdir as m } from "node:os";
|
|
6
|
+
import h, { basename as g, extname as _, isAbsolute as v, join as y, relative as b, resolve as x, sep as S } from "node:path";
|
|
7
|
+
import { randomBytes as C } from "node:crypto";
|
|
8
|
+
import { createConnection as ee } from "node:net";
|
|
9
|
+
import { diffCodexSurfaceState as te } from "@codex-app-sdk/core/surface-bridge";
|
|
10
|
+
import { fileURLToPath as ne, pathToFileURL as re } from "node:url";
|
|
11
|
+
import { isDeepStrictEqual as ie } from "node:util";
|
|
12
|
+
import { chmod as ae, copyFile as oe, mkdtemp as se, rm as ce } from "node:fs/promises";
|
|
13
|
+
import { StringDecoder as le } from "node:string_decoder";
|
|
12
14
|
//#region src/node/codex-executable.ts
|
|
13
|
-
var
|
|
15
|
+
var ue = 5e3, de = {
|
|
14
16
|
path: null,
|
|
15
17
|
nvmNodePath: null
|
|
16
|
-
},
|
|
17
|
-
function
|
|
18
|
-
return
|
|
18
|
+
}, fe = /* @__PURE__ */ new Map();
|
|
19
|
+
function pe(e = {}) {
|
|
20
|
+
return be("codex", me(e), e);
|
|
19
21
|
}
|
|
20
|
-
function
|
|
21
|
-
return
|
|
22
|
+
function me(e = {}) {
|
|
23
|
+
return _e(xe(e), e);
|
|
22
24
|
}
|
|
23
|
-
function
|
|
25
|
+
function he(e, t = {}) {
|
|
24
26
|
let n = {
|
|
25
27
|
...process.env,
|
|
26
28
|
...e
|
|
27
29
|
};
|
|
28
|
-
return
|
|
30
|
+
return ve(n, me({
|
|
29
31
|
...t,
|
|
30
32
|
env: n
|
|
31
33
|
}), t);
|
|
32
34
|
}
|
|
33
|
-
async function
|
|
35
|
+
async function ge(e = {}) {
|
|
34
36
|
let t = {
|
|
35
37
|
...process.env,
|
|
36
38
|
...e.env
|
|
37
39
|
}, n = {
|
|
38
40
|
...e.discovery,
|
|
39
41
|
env: t
|
|
40
|
-
}, r =
|
|
42
|
+
}, r = _e(await Se(n), n);
|
|
41
43
|
return {
|
|
42
|
-
command: e.command?.trim() ||
|
|
43
|
-
env:
|
|
44
|
+
command: e.command?.trim() || be("codex", r, n) || "codex",
|
|
45
|
+
env: ve(t, r, n)
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
|
-
function
|
|
47
|
-
let n =
|
|
48
|
-
return
|
|
49
|
-
...
|
|
50
|
-
...
|
|
51
|
-
...
|
|
52
|
-
...
|
|
53
|
-
...
|
|
48
|
+
function _e(e, t) {
|
|
49
|
+
let n = Ie(t), r = t.env ?? process.env;
|
|
50
|
+
return Pe([
|
|
51
|
+
...ye(t),
|
|
52
|
+
...Ne(r.PATH, n),
|
|
53
|
+
...Ne(e.path, n),
|
|
54
|
+
...ke(t),
|
|
55
|
+
...Ae(e, t)
|
|
54
56
|
]);
|
|
55
57
|
}
|
|
56
|
-
function
|
|
58
|
+
function ve(e, t, n) {
|
|
57
59
|
return {
|
|
58
60
|
...e,
|
|
59
|
-
PATH: t.join(
|
|
61
|
+
PATH: t.join(Ie(n))
|
|
60
62
|
};
|
|
61
63
|
}
|
|
62
|
-
function
|
|
63
|
-
return (e.platform ?? process.platform) === "darwin" ? ["/Applications/ChatGPT.app/Contents/Resources", "/Applications/Codex.app/Contents/Resources"].filter((t) =>
|
|
64
|
+
function ye(e) {
|
|
65
|
+
return (e.platform ?? process.platform) === "darwin" ? ["/Applications/ChatGPT.app/Contents/Resources", "/Applications/Codex.app/Contents/Resources"].filter((t) => T(h.join(t, "codex"), e)) : [];
|
|
64
66
|
}
|
|
65
|
-
function
|
|
66
|
-
for (let r of t) for (let t of
|
|
67
|
-
let e =
|
|
68
|
-
if (
|
|
67
|
+
function be(e, t, n) {
|
|
68
|
+
for (let r of t) for (let t of Me(e, n)) {
|
|
69
|
+
let e = h.join(r, t);
|
|
70
|
+
if (T(e, n)) return e;
|
|
69
71
|
}
|
|
70
72
|
return null;
|
|
71
73
|
}
|
|
72
|
-
function
|
|
73
|
-
if (
|
|
74
|
+
function xe(e) {
|
|
75
|
+
if (w(e)) return de;
|
|
74
76
|
let t = (t) => {
|
|
75
77
|
try {
|
|
76
|
-
return (e.execFileSync ?? a)(
|
|
78
|
+
return (e.execFileSync ?? a)(De(e), t, {
|
|
77
79
|
encoding: "utf8",
|
|
78
80
|
env: e.env ?? process.env,
|
|
79
81
|
stdio: "pipe",
|
|
80
|
-
timeout:
|
|
82
|
+
timeout: Oe(e)
|
|
81
83
|
}).toString();
|
|
82
84
|
} catch {
|
|
83
85
|
return null;
|
|
@@ -87,7 +89,7 @@ function _e(e) {
|
|
|
87
89
|
path: t([
|
|
88
90
|
"-l",
|
|
89
91
|
"-c",
|
|
90
|
-
|
|
92
|
+
Ee(e)
|
|
91
93
|
]),
|
|
92
94
|
nvmNodePath: t([
|
|
93
95
|
"-l",
|
|
@@ -96,22 +98,22 @@ function _e(e) {
|
|
|
96
98
|
])?.trim() || null
|
|
97
99
|
};
|
|
98
100
|
}
|
|
99
|
-
function
|
|
100
|
-
if (
|
|
101
|
-
if (e.execFile || e.execFileSync) return
|
|
101
|
+
function Se(e) {
|
|
102
|
+
if (w(e)) return Promise.resolve(de);
|
|
103
|
+
if (e.execFile || e.execFileSync) return Ce(e);
|
|
102
104
|
let t = e.env ?? process.env, n = [
|
|
103
|
-
|
|
105
|
+
De(e),
|
|
104
106
|
t.PATH ?? "",
|
|
105
|
-
|
|
106
|
-
].join("\0"), r =
|
|
107
|
-
return r || (r =
|
|
107
|
+
Fe(e)
|
|
108
|
+
].join("\0"), r = fe.get(n);
|
|
109
|
+
return r || (r = Ce(e), fe.set(n, r)), r;
|
|
108
110
|
}
|
|
109
|
-
async function
|
|
110
|
-
if (!e.execFile && e.execFileSync) return
|
|
111
|
-
let t =
|
|
111
|
+
async function Ce(e) {
|
|
112
|
+
if (!e.execFile && e.execFileSync) return xe(e);
|
|
113
|
+
let t = we(e), [n, r] = await Promise.all([t([
|
|
112
114
|
"-l",
|
|
113
115
|
"-c",
|
|
114
|
-
|
|
116
|
+
Ee(e)
|
|
115
117
|
]), t([
|
|
116
118
|
"-l",
|
|
117
119
|
"-c",
|
|
@@ -122,17 +124,17 @@ async function ye(e) {
|
|
|
122
124
|
nvmNodePath: r?.trim() || null
|
|
123
125
|
};
|
|
124
126
|
}
|
|
125
|
-
function
|
|
126
|
-
let t =
|
|
127
|
+
function we(e) {
|
|
128
|
+
let t = De(e), n = e.env ?? process.env, r = Oe(e);
|
|
127
129
|
if (e.execFile) {
|
|
128
130
|
let i = e.execFile;
|
|
129
|
-
return (e) =>
|
|
131
|
+
return (e) => Te(i(t, e, {
|
|
130
132
|
encoding: "utf8",
|
|
131
133
|
env: n,
|
|
132
134
|
timeout: r
|
|
133
135
|
}), r);
|
|
134
136
|
}
|
|
135
|
-
return (e) =>
|
|
137
|
+
return (e) => Te(new Promise((a, o) => {
|
|
136
138
|
i(t, e, {
|
|
137
139
|
encoding: "utf8",
|
|
138
140
|
env: n,
|
|
@@ -143,7 +145,7 @@ function be(e) {
|
|
|
143
145
|
});
|
|
144
146
|
}), r);
|
|
145
147
|
}
|
|
146
|
-
function
|
|
148
|
+
function Te(e, t) {
|
|
147
149
|
return new Promise((n) => {
|
|
148
150
|
let r = setTimeout(() => n(null), t + 100);
|
|
149
151
|
r.unref?.(), e.then((e) => {
|
|
@@ -153,65 +155,65 @@ function xe(e, t) {
|
|
|
153
155
|
});
|
|
154
156
|
});
|
|
155
157
|
}
|
|
156
|
-
function
|
|
157
|
-
let t =
|
|
158
|
+
function Ee(e) {
|
|
159
|
+
let t = De(e);
|
|
158
160
|
return t.endsWith("/nu") || t === "nu" ? "print $env.PATH" : "printf \"%s\" \"$PATH\"";
|
|
159
161
|
}
|
|
160
|
-
function
|
|
162
|
+
function De(e) {
|
|
161
163
|
return e.shell ?? e.env?.SHELL ?? process.env.SHELL ?? "/bin/bash";
|
|
162
164
|
}
|
|
163
|
-
function
|
|
164
|
-
return e.shellTimeoutMs ??
|
|
165
|
+
function Oe(e) {
|
|
166
|
+
return e.shellTimeoutMs ?? ue;
|
|
165
167
|
}
|
|
166
|
-
function
|
|
167
|
-
if (
|
|
168
|
-
let t =
|
|
168
|
+
function ke(e) {
|
|
169
|
+
if (w(e)) return [];
|
|
170
|
+
let t = Fe(e);
|
|
169
171
|
return [
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
h.join(t, ".local/bin"),
|
|
173
|
+
h.join(t, "bin"),
|
|
172
174
|
"/opt/homebrew/bin",
|
|
173
175
|
"/usr/local/bin"
|
|
174
|
-
].filter((t) =>
|
|
176
|
+
].filter((t) => T(t, e));
|
|
175
177
|
}
|
|
176
|
-
function
|
|
177
|
-
return
|
|
178
|
+
function Ae(e, t) {
|
|
179
|
+
return w(t) ? [] : Pe([e.nvmNodePath && T(e.nvmNodePath, t) ? h.dirname(e.nvmNodePath) : null, je(t)]);
|
|
178
180
|
}
|
|
179
|
-
function
|
|
180
|
-
let t =
|
|
181
|
-
if (!
|
|
181
|
+
function je(e) {
|
|
182
|
+
let t = Fe(e), n = h.join(t, ".nvm/alias/default"), r = h.join(t, ".nvm/versions/node");
|
|
183
|
+
if (!T(n, e) || !T(r, e)) return null;
|
|
182
184
|
try {
|
|
183
185
|
let t = (e.readFileSync ?? u)(n, "utf8").trim();
|
|
184
186
|
if (!t) return null;
|
|
185
187
|
t.startsWith("v") || (t = `v${t}`);
|
|
186
188
|
let i = (e.readdirSync ?? d)(r).filter((e) => e.startsWith(t)).sort().at(-1);
|
|
187
|
-
return i ?
|
|
189
|
+
return i ? h.join(r, i, "bin") : null;
|
|
188
190
|
} catch {}
|
|
189
191
|
return null;
|
|
190
192
|
}
|
|
191
|
-
function
|
|
192
|
-
return !
|
|
193
|
+
function Me(e, t) {
|
|
194
|
+
return !w(t) || h.extname(e) ? [e] : [e, ...(t.env?.PATHEXT ?? process.env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter(Boolean).map((t) => `${e}${t.toLowerCase()}`)];
|
|
193
195
|
}
|
|
194
|
-
function
|
|
196
|
+
function w(e) {
|
|
195
197
|
return (e.platform ?? process.platform) === "win32";
|
|
196
198
|
}
|
|
197
|
-
function
|
|
199
|
+
function Ne(e, t) {
|
|
198
200
|
return e ? e.split(t).map((e) => e.trim()) : [];
|
|
199
201
|
}
|
|
200
|
-
function
|
|
202
|
+
function Pe(e) {
|
|
201
203
|
return [...new Set(e.filter((e) => !!e))];
|
|
202
204
|
}
|
|
203
|
-
function
|
|
205
|
+
function T(e, t) {
|
|
204
206
|
return (t.existsSync ?? c)(e);
|
|
205
207
|
}
|
|
206
|
-
function
|
|
208
|
+
function Fe(e) {
|
|
207
209
|
return e.homedir?.() ?? e.env?.HOME ?? process.env.HOME ?? p();
|
|
208
210
|
}
|
|
209
|
-
function
|
|
210
|
-
return e.pathDelimiter ??
|
|
211
|
+
function Ie(e) {
|
|
212
|
+
return e.pathDelimiter ?? h.delimiter;
|
|
211
213
|
}
|
|
212
214
|
//#endregion
|
|
213
215
|
//#region src/node/codex-stdio-transport.ts
|
|
214
|
-
var
|
|
216
|
+
var Le = 64 * 1024, Re = ["features.default_mode_request_user_input=true"], ze = Math.min(256 * 1024 * 1024, Math.floor(s.MAX_STRING_LENGTH / 2)), Be = 12e3, Ve = class {
|
|
215
217
|
options;
|
|
216
218
|
child = null;
|
|
217
219
|
expectedExits = /* @__PURE__ */ new WeakSet();
|
|
@@ -228,14 +230,14 @@ var Ne = 64 * 1024, Pe = ["features.default_mode_request_user_input=true"], Fe =
|
|
|
228
230
|
}), this.starting);
|
|
229
231
|
}
|
|
230
232
|
async spawnAppServer() {
|
|
231
|
-
let t = this.generation, { command: n, env: r } = await
|
|
233
|
+
let t = this.generation, { command: n, env: r } = await ge({
|
|
232
234
|
command: this.options.command,
|
|
233
235
|
env: this.options.env,
|
|
234
236
|
discovery: this.options.executableDiscovery
|
|
235
237
|
});
|
|
236
238
|
if (t !== this.generation) throw Error("Codex app-server transport was closed while starting");
|
|
237
239
|
let i = [
|
|
238
|
-
...[...
|
|
240
|
+
...[...Re, ...this.options.configOverrides ?? []].flatMap((e) => ["-c", e]),
|
|
239
241
|
"app-server",
|
|
240
242
|
"--listen",
|
|
241
243
|
"stdio://"
|
|
@@ -248,7 +250,7 @@ var Ne = 64 * 1024, Pe = ["features.default_mode_request_user_input=true"], Fe =
|
|
|
248
250
|
stdio: "pipe"
|
|
249
251
|
}, c = (this.options.spawnProcess ?? o)(n, i, s);
|
|
250
252
|
this.child = c;
|
|
251
|
-
let l = "", u = !1, d = "", f = Math.max(1, this.options.maxDiagnosticBufferChars ??
|
|
253
|
+
let l = "", u = !1, d = "", f = Math.max(1, this.options.maxDiagnosticBufferChars ?? Le), p = Math.max(1, this.options.maxOutputLineChars ?? ze);
|
|
252
254
|
c.stdout.setEncoding("utf8"), c.stderr.setEncoding("utf8"), c.stdout.on("data", (t) => {
|
|
253
255
|
let n = t.toString();
|
|
254
256
|
if (u) {
|
|
@@ -260,15 +262,15 @@ var Ne = 64 * 1024, Pe = ["features.default_mode_request_user_input=true"], Fe =
|
|
|
260
262
|
let r = l.indexOf("\n");
|
|
261
263
|
for (; r >= 0;) {
|
|
262
264
|
let t = l.slice(0, r).trim();
|
|
263
|
-
l = l.slice(r + 1), r = l.indexOf("\n"), t && (t.length > p ? this.emitError(new e("Codex app-server output line exceeded the configured limit", { requestId:
|
|
265
|
+
l = l.slice(r + 1), r = l.indexOf("\n"), t && (t.length > p ? this.emitError(new e("Codex app-server output line exceeded the configured limit", { requestId: Ue(t) })) : this.parseLine(t));
|
|
264
266
|
}
|
|
265
267
|
if (l.length > p) {
|
|
266
|
-
let t =
|
|
268
|
+
let t = Ue(l);
|
|
267
269
|
l = "", u = !0, this.emitError(new e("Codex app-server output line exceeded the configured limit", { requestId: t }));
|
|
268
270
|
}
|
|
269
271
|
}), c.stderr.on("data", (e) => {
|
|
270
272
|
let t = e.toString();
|
|
271
|
-
d =
|
|
273
|
+
d = He(d, t, f), this.options.onStderr?.(t);
|
|
272
274
|
}), c.stdin.on("error", (e) => {
|
|
273
275
|
this.child !== c || this.expectedExits.has(c) || (this.child = null, this.expectedExits.add(c), c.kill(), this.emitError(e));
|
|
274
276
|
}), c.once("error", (e) => {
|
|
@@ -295,11 +297,11 @@ var Ne = 64 * 1024, Pe = ["features.default_mode_request_user_input=true"], Fe =
|
|
|
295
297
|
let e = this.child;
|
|
296
298
|
if (this.child = null, !e) return;
|
|
297
299
|
this.expectedExits.add(e);
|
|
298
|
-
let t = this.options.shutdownTimeoutMs ??
|
|
300
|
+
let t = this.options.shutdownTimeoutMs ?? Be, n = We(e, t);
|
|
299
301
|
if (e.stdin.end(), await n) return;
|
|
300
|
-
let r = Math.min(t, 1e3), i =
|
|
302
|
+
let r = Math.min(t, 1e3), i = We(e, r);
|
|
301
303
|
if (e.kill(), await i) return;
|
|
302
|
-
let a =
|
|
304
|
+
let a = We(e, r);
|
|
303
305
|
if (e.kill("SIGKILL"), !await a) throw Error("Codex app-server did not exit after SIGKILL");
|
|
304
306
|
}
|
|
305
307
|
onMessage(e) {
|
|
@@ -322,10 +324,10 @@ var Ne = 64 * 1024, Pe = ["features.default_mode_request_user_input=true"], Fe =
|
|
|
322
324
|
for (let t of this.errorListeners) t(e);
|
|
323
325
|
}
|
|
324
326
|
};
|
|
325
|
-
function
|
|
327
|
+
function He(e, t, n) {
|
|
326
328
|
return (e + t).slice(-n);
|
|
327
329
|
}
|
|
328
|
-
function
|
|
330
|
+
function Ue(e) {
|
|
329
331
|
let t = /^\s*\{\s*"id"\s*:\s*(?:(-?\d+)|("(?:\\.|[^"\\])*"))/.exec(e);
|
|
330
332
|
if (t) {
|
|
331
333
|
if (t[1] !== void 0) {
|
|
@@ -337,7 +339,7 @@ function ze(e) {
|
|
|
337
339
|
} catch {}
|
|
338
340
|
}
|
|
339
341
|
}
|
|
340
|
-
function
|
|
342
|
+
function We(e, t) {
|
|
341
343
|
return e.exitCode !== null || e.signalCode !== null ? Promise.resolve(!0) : new Promise((n) => {
|
|
342
344
|
let r = () => {
|
|
343
345
|
clearTimeout(i), n(!0);
|
|
@@ -349,7 +351,7 @@ function Be(e, t) {
|
|
|
349
351
|
}
|
|
350
352
|
//#endregion
|
|
351
353
|
//#region src/node/codex-unix-socket-transport.ts
|
|
352
|
-
var
|
|
354
|
+
var Ge = 64 * 1024 * 1024, Ke = class {
|
|
353
355
|
options;
|
|
354
356
|
socket = null;
|
|
355
357
|
messageListeners = /* @__PURE__ */ new Set();
|
|
@@ -366,12 +368,12 @@ var Ve = 64 * 1024 * 1024, He = class {
|
|
|
366
368
|
async start() {
|
|
367
369
|
if (this.started) return;
|
|
368
370
|
this.closed = !1;
|
|
369
|
-
let e =
|
|
371
|
+
let e = ee(this.socketPath());
|
|
370
372
|
this.socket = e, await new Promise((t, n) => {
|
|
371
373
|
let r = (t) => {
|
|
372
374
|
o(), this.socket = null, e.destroy(), n(t);
|
|
373
375
|
}, i = () => {
|
|
374
|
-
e.write(
|
|
376
|
+
e.write(qe());
|
|
375
377
|
}, a = (n) => {
|
|
376
378
|
this.handshakeBuffer = Buffer.concat([this.handshakeBuffer, n]);
|
|
377
379
|
let i = this.handshakeBuffer.indexOf("\r\n\r\n");
|
|
@@ -408,13 +410,13 @@ var Ve = 64 * 1024 * 1024, He = class {
|
|
|
408
410
|
return this.errorListeners.add(e), () => this.errorListeners.delete(e);
|
|
409
411
|
}
|
|
410
412
|
socketPath() {
|
|
411
|
-
return this.options.socketPath?.trim() ||
|
|
413
|
+
return this.options.socketPath?.trim() || y(this.options.codexHome?.trim() || process.env.CODEX_HOME?.trim() || y(p(), ".codex"), "app-server-control", "app-server-control.sock");
|
|
412
414
|
}
|
|
413
415
|
handleFrameData(e) {
|
|
414
416
|
this.frameBuffer = Buffer.concat([this.frameBuffer, e]);
|
|
415
417
|
try {
|
|
416
418
|
for (;;) {
|
|
417
|
-
let e =
|
|
419
|
+
let e = Xe(this.frameBuffer, this.options.maxFrameBytes ?? Ge);
|
|
418
420
|
if (!e) return;
|
|
419
421
|
this.frameBuffer = this.frameBuffer.subarray(e.bytesRead), this.handleFrame(e.fin, e.opcode, e.payload);
|
|
420
422
|
}
|
|
@@ -453,7 +455,7 @@ var Ve = 64 * 1024 * 1024, He = class {
|
|
|
453
455
|
r(this.messageListeners, a);
|
|
454
456
|
}
|
|
455
457
|
writeFrame(e, t, n) {
|
|
456
|
-
n.write(
|
|
458
|
+
n.write(Je(e, t));
|
|
457
459
|
}
|
|
458
460
|
handleSocketError(e) {
|
|
459
461
|
this.closed || this.emitError(e);
|
|
@@ -465,20 +467,20 @@ var Ve = 64 * 1024 * 1024, He = class {
|
|
|
465
467
|
for (let t of this.errorListeners) t(e);
|
|
466
468
|
}
|
|
467
469
|
};
|
|
468
|
-
function
|
|
470
|
+
function qe() {
|
|
469
471
|
return [
|
|
470
472
|
"GET /rpc HTTP/1.1",
|
|
471
473
|
"Host: localhost",
|
|
472
474
|
"Upgrade: websocket",
|
|
473
475
|
"Connection: Upgrade",
|
|
474
|
-
`Sec-WebSocket-Key: ${
|
|
476
|
+
`Sec-WebSocket-Key: ${C(16).toString("base64")}`,
|
|
475
477
|
"Sec-WebSocket-Version: 13",
|
|
476
478
|
"",
|
|
477
479
|
""
|
|
478
480
|
].join("\r\n");
|
|
479
481
|
}
|
|
480
|
-
function
|
|
481
|
-
let n =
|
|
482
|
+
function Je(e, t) {
|
|
483
|
+
let n = C(4), r = Ye(e, t.length, !0), i = Buffer.from(t);
|
|
482
484
|
for (let e = 0; e < i.length; e += 1) i[e] = (i[e] ?? 0) ^ (n[e % 4] ?? 0);
|
|
483
485
|
return Buffer.concat([
|
|
484
486
|
r,
|
|
@@ -486,7 +488,7 @@ function We(e, t) {
|
|
|
486
488
|
i
|
|
487
489
|
]);
|
|
488
490
|
}
|
|
489
|
-
function
|
|
491
|
+
function Ye(e, t, n) {
|
|
490
492
|
let r = n ? 128 : 0;
|
|
491
493
|
if (t < 126) return Buffer.from([128 | e, r | t]);
|
|
492
494
|
if (t <= 65535) {
|
|
@@ -496,7 +498,7 @@ function Ge(e, t, n) {
|
|
|
496
498
|
let i = Buffer.alloc(10);
|
|
497
499
|
return i[0] = 128 | e, i[1] = r | 127, i.writeBigUInt64BE(BigInt(t), 2), i;
|
|
498
500
|
}
|
|
499
|
-
function
|
|
501
|
+
function Xe(t, n) {
|
|
500
502
|
if (t.length < 2) return null;
|
|
501
503
|
let r = t[0] ?? 0, i = t[1] ?? 0, a = (r & 128) != 0, o = r & 15, s = (i & 128) != 0, c = i & 127, l = 2;
|
|
502
504
|
if (c === 126) {
|
|
@@ -524,7 +526,7 @@ function Ke(t, n) {
|
|
|
524
526
|
}
|
|
525
527
|
//#endregion
|
|
526
528
|
//#region src/node/codex-surface-prompts.ts
|
|
527
|
-
function
|
|
529
|
+
function Ze(e) {
|
|
528
530
|
switch (e) {
|
|
529
531
|
case "allow": return {
|
|
530
532
|
action: "accept",
|
|
@@ -548,11 +550,11 @@ function qe(e) {
|
|
|
548
550
|
};
|
|
549
551
|
}
|
|
550
552
|
}
|
|
551
|
-
function
|
|
553
|
+
function Qe(e) {
|
|
552
554
|
let t = /^\/plan(?:\s(.*))?$/s.exec(e.trim());
|
|
553
555
|
return t ? { prompt: (t[1]?.trim() ?? "") || null } : null;
|
|
554
556
|
}
|
|
555
|
-
function
|
|
557
|
+
function $e(e) {
|
|
556
558
|
let t = /^\/goal(?:\s(.*))?$/s.exec(e.trim());
|
|
557
559
|
if (!t) return null;
|
|
558
560
|
let n = t[1]?.trim() ?? "";
|
|
@@ -561,7 +563,7 @@ function Ye(e) {
|
|
|
561
563
|
objective: n
|
|
562
564
|
} : { action: "show" };
|
|
563
565
|
}
|
|
564
|
-
function
|
|
566
|
+
function et(e) {
|
|
565
567
|
let t = /^\/review(?:\s(.*))?$/s.exec(e.trim());
|
|
566
568
|
if (!t) return null;
|
|
567
569
|
let n = t[1]?.trim() ?? "";
|
|
@@ -570,13 +572,13 @@ function Xe(e) {
|
|
|
570
572
|
instructions: n
|
|
571
573
|
} : { type: "uncommittedChanges" };
|
|
572
574
|
}
|
|
573
|
-
function
|
|
575
|
+
function tt(e) {
|
|
574
576
|
return e.type === "commit" ? {
|
|
575
577
|
...e,
|
|
576
578
|
title: e.title ?? null
|
|
577
579
|
} : { ...e };
|
|
578
580
|
}
|
|
579
|
-
function
|
|
581
|
+
function nt(e, t) {
|
|
580
582
|
let n = /* @__PURE__ */ new Set(), r = /(?:^|[^\w.%+-])[$/]([A-Za-z0-9_.-]+)/g, i;
|
|
581
583
|
for (; (i = r.exec(e)) !== null;) n.add(i[1]);
|
|
582
584
|
return t.filter((e) => e.enabled && n.has(e.name) && !!e.path).map((e) => ({
|
|
@@ -584,7 +586,7 @@ function Qe(e, t) {
|
|
|
584
586
|
path: e.path
|
|
585
587
|
}));
|
|
586
588
|
}
|
|
587
|
-
function
|
|
589
|
+
function rt(e, t) {
|
|
588
590
|
return e.map((e) => {
|
|
589
591
|
let n = t.find((t) => t.enabled && t.name === e.name && t.path === e.path);
|
|
590
592
|
if (!n) throw Error(`Skill '${e.name}' is not an enabled skill in the Codex catalog`);
|
|
@@ -594,62 +596,62 @@ function $e(e, t) {
|
|
|
594
596
|
};
|
|
595
597
|
});
|
|
596
598
|
}
|
|
597
|
-
function
|
|
599
|
+
function it(...e) {
|
|
598
600
|
let t = /* @__PURE__ */ new Set();
|
|
599
601
|
return e.flatMap((e) => e.filter((e) => {
|
|
600
602
|
let n = `${e.name}\u0000${e.path}`;
|
|
601
603
|
return t.has(n) ? !1 : (t.add(n), !0);
|
|
602
604
|
}));
|
|
603
605
|
}
|
|
604
|
-
function
|
|
606
|
+
function at(e, t, n, r) {
|
|
605
607
|
let i = e.filter((e) => e.metadata?.turnId === t).flatMap((e) => e.parts).filter((e) => e.type === "tool" && e.kind === "mcp" && e.status === "running");
|
|
606
608
|
return i.find((e) => {
|
|
607
|
-
let t =
|
|
609
|
+
let t = E(e.metadata?.server), i = E(e.metadata?.tool);
|
|
608
610
|
return t === n && i === r || e.title.endsWith(`.${r}`);
|
|
609
611
|
}) ?? (i.length === 1 ? i[0] ?? null : null);
|
|
610
612
|
}
|
|
611
|
-
function
|
|
613
|
+
function ot(e) {
|
|
612
614
|
if (Array.isArray(e.tool_params_display)) {
|
|
613
|
-
let t = e.tool_params_display.map((e) => !
|
|
615
|
+
let t = e.tool_params_display.map((e) => !ct(e) || typeof e.name != "string" ? "" : `${E(e.display_name) ?? e.name}: ${typeof e.value == "string" ? e.value : JSON.stringify(e.value)}`).filter(Boolean);
|
|
614
616
|
if (t.length > 0) return t.join("\n");
|
|
615
617
|
}
|
|
616
618
|
return e.tool_params === void 0 ? "" : JSON.stringify(e.tool_params, null, 2);
|
|
617
619
|
}
|
|
618
|
-
function
|
|
620
|
+
function st(e, t) {
|
|
619
621
|
return e === t || Array.isArray(e) && e.includes(t);
|
|
620
622
|
}
|
|
621
|
-
function
|
|
623
|
+
function E(e) {
|
|
622
624
|
return typeof e == "string" && e.trim() ? e.trim() : null;
|
|
623
625
|
}
|
|
624
|
-
function
|
|
626
|
+
function D(e) {
|
|
625
627
|
let t = e.trim();
|
|
626
628
|
if (!t) throw Error("Conversation id cannot be empty");
|
|
627
629
|
return t;
|
|
628
630
|
}
|
|
629
|
-
function
|
|
631
|
+
function ct(e) {
|
|
630
632
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
631
633
|
}
|
|
632
|
-
function
|
|
634
|
+
function O(e) {
|
|
633
635
|
return e instanceof Error ? e.message : String(e);
|
|
634
636
|
}
|
|
635
637
|
//#endregion
|
|
636
638
|
//#region src/node/codex-surface-realtime.ts
|
|
637
|
-
function
|
|
639
|
+
function lt(e, t) {
|
|
638
640
|
if (e === void 0) return;
|
|
639
641
|
if (typeof e != "string") throw TypeError(`Realtime ${t} must be a string`);
|
|
640
642
|
let n = e.trim();
|
|
641
643
|
if (!n) throw TypeError(`Realtime ${t} cannot be empty`);
|
|
642
644
|
return n;
|
|
643
645
|
}
|
|
644
|
-
function
|
|
646
|
+
function ut(e, t) {
|
|
645
647
|
if (typeof e != "string") throw TypeError(`Realtime ${t} must be a string`);
|
|
646
648
|
let n = e.trim();
|
|
647
649
|
if (!n) throw TypeError(`Realtime ${t} cannot be empty`);
|
|
648
650
|
return n;
|
|
649
651
|
}
|
|
650
|
-
function
|
|
652
|
+
function dt(e) {
|
|
651
653
|
if (!(e.data instanceof Uint8Array)) throw TypeError("Realtime audio data must be a Uint8Array");
|
|
652
|
-
let t =
|
|
654
|
+
let t = pt(e.sampleRate, "sampleRate"), n = pt(e.numChannels, "numChannels"), r = e.samplesPerChannel === void 0 ? Math.floor(e.data.byteLength / 2 / n) : mt(e.samplesPerChannel, "samplesPerChannel"), i = e.itemId === void 0 ? null : e.itemId;
|
|
653
655
|
if (i !== null && (typeof i != "string" || !i.trim())) throw TypeError("Realtime audio itemId must be a non-empty string or null");
|
|
654
656
|
return {
|
|
655
657
|
data: Buffer.from(e.data.buffer, e.data.byteOffset, e.data.byteLength).toString("base64"),
|
|
@@ -659,7 +661,7 @@ function st(e) {
|
|
|
659
661
|
itemId: i
|
|
660
662
|
};
|
|
661
663
|
}
|
|
662
|
-
function
|
|
664
|
+
function ft(e) {
|
|
663
665
|
return {
|
|
664
666
|
data: new Uint8Array(Buffer.from(e.data, "base64")),
|
|
665
667
|
sampleRate: e.sampleRate,
|
|
@@ -668,28 +670,28 @@ function ct(e) {
|
|
|
668
670
|
itemId: e.itemId
|
|
669
671
|
};
|
|
670
672
|
}
|
|
671
|
-
function
|
|
673
|
+
function pt(e, t) {
|
|
672
674
|
if (!Number.isSafeInteger(e) || e <= 0) throw TypeError(`Realtime audio ${t} must be a positive integer`);
|
|
673
675
|
return e;
|
|
674
676
|
}
|
|
675
|
-
function
|
|
677
|
+
function mt(e, t) {
|
|
676
678
|
if (e === null) return null;
|
|
677
679
|
if (!Number.isSafeInteger(e) || e < 0) throw TypeError(`Realtime audio ${t} must be a non-negative integer or null`);
|
|
678
680
|
return e;
|
|
679
681
|
}
|
|
680
682
|
//#endregion
|
|
681
683
|
//#region src/node/codex-surface-realtime-session.ts
|
|
682
|
-
async function
|
|
684
|
+
async function ht(e) {
|
|
683
685
|
let { client: t, ensureThreadReady: n, onConversationEvent: r, options: i, threadId: a } = e;
|
|
684
686
|
await n();
|
|
685
687
|
let o = i.outputModality;
|
|
686
688
|
if (o !== "text" && o !== "audio") throw TypeError(`Invalid realtime output modality '${String(o)}'`);
|
|
687
689
|
let s = i.version;
|
|
688
690
|
if (s !== void 0 && s !== "v1" && s !== "v2" && s !== "v3") throw TypeError(`Invalid realtime version '${String(s)}'`);
|
|
689
|
-
let c =
|
|
691
|
+
let c = lt(i.model, "model"), l = lt(i.voice, "voice"), u = i.transport ?? { type: "websocket" };
|
|
690
692
|
if (u.type !== "websocket" && u.type !== "webrtc") throw TypeError(`Invalid realtime transport '${String(u.type)}'`);
|
|
691
693
|
if (u.type === "webrtc" && !u.sdp.trim()) throw TypeError("WebRTC realtime transport requires a non-empty SDP offer");
|
|
692
|
-
let d = u.type === "webrtc" ?
|
|
694
|
+
let d = u.type === "webrtc" ? gt(r) : null, f;
|
|
693
695
|
try {
|
|
694
696
|
let [, e] = await Promise.all([t.request("thread/realtime/start", {
|
|
695
697
|
threadId: a,
|
|
@@ -720,12 +722,12 @@ async function dt(e) {
|
|
|
720
722
|
if (m(), u.type === "webrtc") throw Error("WebRTC realtime audio must be sent through its negotiated media track");
|
|
721
723
|
await t.request("thread/realtime/appendAudio", {
|
|
722
724
|
threadId: a,
|
|
723
|
-
audio:
|
|
725
|
+
audio: dt(e)
|
|
724
726
|
});
|
|
725
727
|
},
|
|
726
728
|
appendText: async (e, n = "user") => {
|
|
727
729
|
m();
|
|
728
|
-
let r =
|
|
730
|
+
let r = ut(e, "text");
|
|
729
731
|
if (n !== "user" && n !== "developer" && n !== "assistant") throw TypeError(`Invalid realtime text role '${String(n)}'`);
|
|
730
732
|
await t.request("thread/realtime/appendText", {
|
|
731
733
|
threadId: a,
|
|
@@ -736,7 +738,7 @@ async function dt(e) {
|
|
|
736
738
|
appendSpeech: async (e) => {
|
|
737
739
|
m(), await t.request("thread/realtime/appendSpeech", {
|
|
738
740
|
threadId: a,
|
|
739
|
-
text:
|
|
741
|
+
text: ut(e, "speech")
|
|
740
742
|
});
|
|
741
743
|
},
|
|
742
744
|
stop: async () => {
|
|
@@ -747,7 +749,7 @@ async function dt(e) {
|
|
|
747
749
|
})
|
|
748
750
|
};
|
|
749
751
|
}
|
|
750
|
-
function
|
|
752
|
+
function gt(e) {
|
|
751
753
|
let t = () => void 0, n, r = !1, i = () => {
|
|
752
754
|
r || (r = !0, clearTimeout(n), t());
|
|
753
755
|
};
|
|
@@ -764,7 +766,7 @@ function ft(e) {
|
|
|
764
766
|
}
|
|
765
767
|
//#endregion
|
|
766
768
|
//#region src/node/codex-surface-runtime.ts
|
|
767
|
-
function
|
|
769
|
+
function _t(e) {
|
|
768
770
|
return {
|
|
769
771
|
status: "idle",
|
|
770
772
|
authentication: e,
|
|
@@ -807,7 +809,7 @@ function pt(e) {
|
|
|
807
809
|
error: null
|
|
808
810
|
};
|
|
809
811
|
}
|
|
810
|
-
function
|
|
812
|
+
function vt(e, t, n = {}) {
|
|
811
813
|
return {
|
|
812
814
|
threadId: e,
|
|
813
815
|
cwd: null,
|
|
@@ -846,7 +848,7 @@ function mt(e, t, n = {}) {
|
|
|
846
848
|
...n
|
|
847
849
|
};
|
|
848
850
|
}
|
|
849
|
-
function
|
|
851
|
+
function yt(e, t, n) {
|
|
850
852
|
let r = [...n], i = new Set(r.map((e) => e.id)), a = new Set(e.answeredClientRequestIds);
|
|
851
853
|
for (let t of e.messages) {
|
|
852
854
|
let e = t.metadata?.asyncQuestionRequestIds;
|
|
@@ -888,7 +890,7 @@ function ht(e, t, n) {
|
|
|
888
890
|
}
|
|
889
891
|
//#endregion
|
|
890
892
|
//#region src/node/codex-surface-authentication.ts
|
|
891
|
-
function
|
|
893
|
+
function bt() {
|
|
892
894
|
return {
|
|
893
895
|
status: "notLoaded",
|
|
894
896
|
account: null,
|
|
@@ -902,7 +904,7 @@ function gt() {
|
|
|
902
904
|
}
|
|
903
905
|
};
|
|
904
906
|
}
|
|
905
|
-
function
|
|
907
|
+
function xt(e) {
|
|
906
908
|
return e.type === "chatgpt" ? {
|
|
907
909
|
type: "chatgpt",
|
|
908
910
|
email: e.email,
|
|
@@ -912,13 +914,13 @@ function _t(e) {
|
|
|
912
914
|
credentialSource: e.usesCodexManagedCredentials ? "codexManaged" : "awsManaged"
|
|
913
915
|
} : { type: "apiKey" };
|
|
914
916
|
}
|
|
915
|
-
function
|
|
917
|
+
function St(e) {
|
|
916
918
|
return JSON.stringify({
|
|
917
919
|
account: e.account,
|
|
918
920
|
requiresOpenaiAuth: e.requiresOpenaiAuth
|
|
919
921
|
});
|
|
920
922
|
}
|
|
921
|
-
function
|
|
923
|
+
function Ct(e) {
|
|
922
924
|
let t = e.account;
|
|
923
925
|
return t ? t.type === "chatgpt" ? JSON.stringify({
|
|
924
926
|
type: t.type,
|
|
@@ -931,12 +933,12 @@ function yt(e) {
|
|
|
931
933
|
requiresOpenaiAuth: e.requiresOpenaiAuth
|
|
932
934
|
});
|
|
933
935
|
}
|
|
934
|
-
function
|
|
936
|
+
function wt(e) {
|
|
935
937
|
let t = e.trim();
|
|
936
938
|
if (!t) throw Error("Codex login id cannot be empty");
|
|
937
939
|
return t;
|
|
938
940
|
}
|
|
939
|
-
function
|
|
941
|
+
function Tt(e) {
|
|
940
942
|
let t;
|
|
941
943
|
try {
|
|
942
944
|
t = new URL(e);
|
|
@@ -948,26 +950,26 @@ function xt(e) {
|
|
|
948
950
|
}
|
|
949
951
|
//#endregion
|
|
950
952
|
//#region src/node/codex-surface-transport-options.ts
|
|
951
|
-
function
|
|
953
|
+
function Et(e) {
|
|
952
954
|
return "type" in e && e.type === "unixSocket";
|
|
953
955
|
}
|
|
954
|
-
function
|
|
955
|
-
let t = e.codexHome === void 0 ? void 0 :
|
|
956
|
+
function Dt(e) {
|
|
957
|
+
let t = e.codexHome === void 0 ? void 0 : Ot(e.codexHome), n = e.transport?.codexHome;
|
|
956
958
|
if (t !== void 0 && n !== void 0 && t !== n) throw Error("Codex surface codexHome conflicts with transport.codexHome");
|
|
957
959
|
return {
|
|
958
960
|
...e.transport ?? {},
|
|
959
961
|
...t === void 0 ? {} : { codexHome: t }
|
|
960
962
|
};
|
|
961
963
|
}
|
|
962
|
-
function
|
|
964
|
+
function Ot(e) {
|
|
963
965
|
let t = e.trim();
|
|
964
966
|
if (!t) throw Error("Codex surface codexHome cannot be empty");
|
|
965
|
-
if (!
|
|
967
|
+
if (!v(t)) throw Error("Codex surface codexHome must be an absolute path");
|
|
966
968
|
return t;
|
|
967
969
|
}
|
|
968
970
|
//#endregion
|
|
969
971
|
//#region src/node/codex-surface-authentication-controller.ts
|
|
970
|
-
var
|
|
972
|
+
var kt = class {
|
|
971
973
|
client;
|
|
972
974
|
host;
|
|
973
975
|
accountRefreshPromise = null;
|
|
@@ -1001,7 +1003,7 @@ var Tt = class {
|
|
|
1001
1003
|
try {
|
|
1002
1004
|
let e = await this.client.request("account/login/start", { type: "chatgpt" });
|
|
1003
1005
|
if (e.type !== "chatgpt") throw Error(`Codex account/login/start returned unexpected login type '${e.type}'`);
|
|
1004
|
-
let t =
|
|
1006
|
+
let t = wt(e.loginId), n = Tt(e.authUrl);
|
|
1005
1007
|
return this.host.patchAuthentication({ login: {
|
|
1006
1008
|
status: "pending",
|
|
1007
1009
|
loginId: t,
|
|
@@ -1016,7 +1018,7 @@ var Tt = class {
|
|
|
1016
1018
|
status: "error",
|
|
1017
1019
|
loginId: null,
|
|
1018
1020
|
authUrl: null,
|
|
1019
|
-
error:
|
|
1021
|
+
error: O(e)
|
|
1020
1022
|
} }, "action"), e;
|
|
1021
1023
|
}
|
|
1022
1024
|
})();
|
|
@@ -1038,7 +1040,7 @@ var Tt = class {
|
|
|
1038
1040
|
try {
|
|
1039
1041
|
let e = await this.client.request("account/login/start", { type: "chatgptDeviceCode" });
|
|
1040
1042
|
if (e.type !== "chatgptDeviceCode") throw Error(`Codex account/login/start returned unexpected login type '${e.type}'`);
|
|
1041
|
-
let t =
|
|
1043
|
+
let t = wt(e.loginId), n = Tt(e.verificationUrl), r = e.userCode.trim();
|
|
1042
1044
|
if (!r) throw Error("Codex account/login/start returned an empty device user code");
|
|
1043
1045
|
this.host.patchAuthentication({ login: {
|
|
1044
1046
|
status: "pending",
|
|
@@ -1057,7 +1059,7 @@ var Tt = class {
|
|
|
1057
1059
|
status: "error",
|
|
1058
1060
|
loginId: null,
|
|
1059
1061
|
authUrl: null,
|
|
1060
|
-
error:
|
|
1062
|
+
error: O(e)
|
|
1061
1063
|
} }, "action"), e;
|
|
1062
1064
|
}
|
|
1063
1065
|
})();
|
|
@@ -1066,7 +1068,7 @@ var Tt = class {
|
|
|
1066
1068
|
}).catch(() => void 0), t;
|
|
1067
1069
|
}
|
|
1068
1070
|
async cancelLogin(e) {
|
|
1069
|
-
let t =
|
|
1071
|
+
let t = wt(e), n = await this.client.request("account/login/cancel", { loginId: t });
|
|
1070
1072
|
return this.host.patchAuthentication({ login: {
|
|
1071
1073
|
status: n.status === "canceled" ? "cancelled" : "idle",
|
|
1072
1074
|
loginId: null,
|
|
@@ -1108,7 +1110,7 @@ var Tt = class {
|
|
|
1108
1110
|
error: null
|
|
1109
1111
|
}, e);
|
|
1110
1112
|
try {
|
|
1111
|
-
let n = await this.client.request("account/read", { refreshToken: !1 }), r = n.account ?
|
|
1113
|
+
let n = await this.client.request("account/read", { refreshToken: !1 }), r = n.account ? xt(n.account) : null, i = Ct({
|
|
1112
1114
|
...this.host.getSnapshot().authentication,
|
|
1113
1115
|
account: r,
|
|
1114
1116
|
requiresOpenaiAuth: n.requiresOpenaiAuth
|
|
@@ -1122,7 +1124,7 @@ var Tt = class {
|
|
|
1122
1124
|
} catch (t) {
|
|
1123
1125
|
throw this.host.patchAuthentication({
|
|
1124
1126
|
status: "error",
|
|
1125
|
-
error:
|
|
1127
|
+
error: O(t)
|
|
1126
1128
|
}, e), t;
|
|
1127
1129
|
}
|
|
1128
1130
|
}
|
|
@@ -1151,7 +1153,7 @@ var Tt = class {
|
|
|
1151
1153
|
};
|
|
1152
1154
|
//#endregion
|
|
1153
1155
|
//#region src/node/codex-conversation-handle.ts
|
|
1154
|
-
function
|
|
1156
|
+
function At(e, t) {
|
|
1155
1157
|
let n = async (e) => (await e(), t.getSnapshot());
|
|
1156
1158
|
return {
|
|
1157
1159
|
id: e,
|
|
@@ -1192,19 +1194,19 @@ function Et(e, t) {
|
|
|
1192
1194
|
}
|
|
1193
1195
|
//#endregion
|
|
1194
1196
|
//#region src/node/codex-file-attachment.ts
|
|
1195
|
-
var
|
|
1196
|
-
function
|
|
1197
|
+
var jt = "<attached_file>\n", Mt = "\n</attached_file>";
|
|
1198
|
+
function Nt(e, t) {
|
|
1197
1199
|
return {
|
|
1198
1200
|
type: "text",
|
|
1199
|
-
text: `${
|
|
1201
|
+
text: `${jt}${JSON.stringify({
|
|
1200
1202
|
name: e,
|
|
1201
1203
|
path: t
|
|
1202
|
-
}).replaceAll("<", "\\u003c")}${
|
|
1204
|
+
}).replaceAll("<", "\\u003c")}${Mt}`,
|
|
1203
1205
|
text_elements: []
|
|
1204
1206
|
};
|
|
1205
1207
|
}
|
|
1206
|
-
function
|
|
1207
|
-
if (!e.startsWith(
|
|
1208
|
+
function Pt(e) {
|
|
1209
|
+
if (!e.startsWith(jt) || !e.endsWith(Mt)) return null;
|
|
1208
1210
|
try {
|
|
1209
1211
|
let t = JSON.parse(e.slice(16, -17));
|
|
1210
1212
|
if (typeof t != "object" || !t || Array.isArray(t)) return null;
|
|
@@ -1219,36 +1221,36 @@ function At(e) {
|
|
|
1219
1221
|
}
|
|
1220
1222
|
//#endregion
|
|
1221
1223
|
//#region src/node/tool-output.ts
|
|
1222
|
-
var
|
|
1223
|
-
function
|
|
1224
|
+
var Ft = "Result returned in structuredContent.";
|
|
1225
|
+
function k(e) {
|
|
1224
1226
|
if (typeof e == "string") return e;
|
|
1225
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
1226
|
-
if (!
|
|
1227
|
-
let t = "structuredContent" in e ?
|
|
1227
|
+
if (Array.isArray(e)) return e.map((e) => k(e)).filter(Boolean).join("\n\n") || void 0;
|
|
1228
|
+
if (!Lt(e)) return JSON.stringify(e);
|
|
1229
|
+
let t = "structuredContent" in e ? k(e.structuredContent) : void 0;
|
|
1228
1230
|
if (t) {
|
|
1229
|
-
let n =
|
|
1230
|
-
return !n || n.trim() ===
|
|
1231
|
+
let n = It(e);
|
|
1232
|
+
return !n || n.trim() === Ft ? t : `${n}\n\n${t}`;
|
|
1231
1233
|
}
|
|
1232
|
-
return
|
|
1234
|
+
return It(e) ?? JSON.stringify(e);
|
|
1233
1235
|
}
|
|
1234
|
-
function
|
|
1236
|
+
function It(e) {
|
|
1235
1237
|
if (typeof e.text == "string") return e.text;
|
|
1236
1238
|
if (typeof e.content == "string") return e.content;
|
|
1237
|
-
if (Array.isArray(e.content)) return
|
|
1239
|
+
if (Array.isArray(e.content)) return k(e.content);
|
|
1238
1240
|
}
|
|
1239
|
-
function
|
|
1241
|
+
function Lt(e) {
|
|
1240
1242
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
1241
1243
|
}
|
|
1242
1244
|
//#endregion
|
|
1243
1245
|
//#region src/node/codex-tool-part-adapter.ts
|
|
1244
|
-
var
|
|
1245
|
-
function
|
|
1246
|
+
var Rt = "Result returned in structuredContent.", zt = 32 * 1024;
|
|
1247
|
+
function Bt(e, t) {
|
|
1246
1248
|
let n = e.status;
|
|
1247
1249
|
if (e.kind === "command") {
|
|
1248
|
-
let r =
|
|
1249
|
-
return
|
|
1250
|
+
let r = P(e.input) ? e.input : {}, i = typeof r.cwd == "string" ? r.cwd : t ?? void 0;
|
|
1251
|
+
return Yt(r.commandActions).flatMap((e) => {
|
|
1250
1252
|
if (e.type !== "read") return [];
|
|
1251
|
-
let t =
|
|
1253
|
+
let t = cn(e.path ?? e.name, i);
|
|
1252
1254
|
return t ? [{
|
|
1253
1255
|
action: "read",
|
|
1254
1256
|
path: t,
|
|
@@ -1257,12 +1259,12 @@ function It(e, t) {
|
|
|
1257
1259
|
});
|
|
1258
1260
|
}
|
|
1259
1261
|
if (e.kind !== "fileChange") return [];
|
|
1260
|
-
let r =
|
|
1262
|
+
let r = P(e.input) ? e.input : {}, i = e.metadata ?? {};
|
|
1261
1263
|
return (Array.isArray(i.changes) ? i.changes : Array.isArray(r.changes) ? r.changes : []).flatMap((e) => {
|
|
1262
|
-
if (!
|
|
1263
|
-
let r =
|
|
1264
|
+
if (!P(e) || typeof e.path != "string") return [];
|
|
1265
|
+
let r = N(e.kind);
|
|
1264
1266
|
if (r === "delete") return [];
|
|
1265
|
-
let i =
|
|
1267
|
+
let i = cn(e.path, t ?? void 0);
|
|
1266
1268
|
return i ? [{
|
|
1267
1269
|
action: r === "add" ? "create" : "edit",
|
|
1268
1270
|
path: i,
|
|
@@ -1270,10 +1272,10 @@ function It(e, t) {
|
|
|
1270
1272
|
}] : [];
|
|
1271
1273
|
});
|
|
1272
1274
|
}
|
|
1273
|
-
function
|
|
1274
|
-
if (!
|
|
1275
|
+
function A(e, t = {}) {
|
|
1276
|
+
if (!P(e) || typeof e.id != "string") return null;
|
|
1275
1277
|
if (e.type === "commandExecution") {
|
|
1276
|
-
let n = typeof e.command == "string" ? e.command : "command", r =
|
|
1278
|
+
let n = typeof e.command == "string" ? e.command : "command", r = j(e.status), i = Kt(r, e.commandActions, n), a = t.includeCommandOutput && typeof e.aggregatedOutput == "string" ? e.aggregatedOutput : void 0;
|
|
1277
1279
|
return {
|
|
1278
1280
|
type: "tool",
|
|
1279
1281
|
id: e.id,
|
|
@@ -1298,14 +1300,14 @@ function O(e, t = {}) {
|
|
|
1298
1300
|
};
|
|
1299
1301
|
}
|
|
1300
1302
|
if (e.type === "mcpToolCall") {
|
|
1301
|
-
let t = typeof e.server == "string" ? e.server : "mcp", n = typeof e.tool == "string" ? e.tool : "tool", r =
|
|
1303
|
+
let t = typeof e.server == "string" ? e.server : "mcp", n = typeof e.tool == "string" ? e.tool : "tool", r = gn(dn(e.error)), i = F(e.arguments), a = F(e.result);
|
|
1302
1304
|
return {
|
|
1303
1305
|
type: "tool",
|
|
1304
1306
|
id: e.id,
|
|
1305
1307
|
kind: "mcp",
|
|
1306
1308
|
title: `${t}.${n}`,
|
|
1307
|
-
status:
|
|
1308
|
-
body: r ?? fn(
|
|
1309
|
+
status: j(e.status),
|
|
1310
|
+
body: r ?? gn(fn(a)),
|
|
1309
1311
|
...i === void 0 ? {} : { input: i },
|
|
1310
1312
|
...a === void 0 ? {} : { output: a },
|
|
1311
1313
|
metadata: {
|
|
@@ -1318,14 +1320,14 @@ function O(e, t = {}) {
|
|
|
1318
1320
|
};
|
|
1319
1321
|
}
|
|
1320
1322
|
if (e.type === "dynamicToolCall") {
|
|
1321
|
-
let t = typeof e.tool == "string" ? e.tool : "tool", n = typeof e.namespace == "string" ? e.namespace : null, r =
|
|
1323
|
+
let t = typeof e.tool == "string" ? e.tool : "tool", n = typeof e.namespace == "string" ? e.namespace : null, r = F(e.arguments), i = F(e.contentItems);
|
|
1322
1324
|
return {
|
|
1323
1325
|
type: "tool",
|
|
1324
1326
|
id: e.id,
|
|
1325
1327
|
kind: "dynamic",
|
|
1326
1328
|
title: n ? `${n}.${t}` : t,
|
|
1327
|
-
status:
|
|
1328
|
-
body:
|
|
1329
|
+
status: j(e.status),
|
|
1330
|
+
body: gn(mn(i)),
|
|
1329
1331
|
...r === void 0 ? {} : { input: r },
|
|
1330
1332
|
...i === void 0 ? {} : { output: i },
|
|
1331
1333
|
metadata: {
|
|
@@ -1337,7 +1339,7 @@ function O(e, t = {}) {
|
|
|
1337
1339
|
};
|
|
1338
1340
|
}
|
|
1339
1341
|
if (e.type === "fileChange") {
|
|
1340
|
-
let n = Array.isArray(e.changes) ? e.changes : [], r =
|
|
1342
|
+
let n = Array.isArray(e.changes) ? e.changes : [], r = j(e.status), i = nn(r, n);
|
|
1341
1343
|
return {
|
|
1342
1344
|
type: "tool",
|
|
1343
1345
|
id: e.id,
|
|
@@ -1345,7 +1347,7 @@ function O(e, t = {}) {
|
|
|
1345
1347
|
title: n.length === 1 ? "1 file change" : `${n.length} file changes`,
|
|
1346
1348
|
status: r,
|
|
1347
1349
|
...i ? { statusText: i } : {},
|
|
1348
|
-
body:
|
|
1350
|
+
body: hn(n),
|
|
1349
1351
|
input: { changes: n },
|
|
1350
1352
|
metadata: {
|
|
1351
1353
|
changes: n,
|
|
@@ -1374,19 +1376,19 @@ function O(e, t = {}) {
|
|
|
1374
1376
|
id: e.id,
|
|
1375
1377
|
kind: "dynamic",
|
|
1376
1378
|
title: "image_generation",
|
|
1377
|
-
status:
|
|
1379
|
+
status: j(e.status),
|
|
1378
1380
|
body: typeof e.revisedPrompt == "string" ? e.revisedPrompt : void 0,
|
|
1379
1381
|
input: { revisedPrompt: e.revisedPrompt },
|
|
1380
1382
|
output: e.savedPath,
|
|
1381
1383
|
metadata: { savedPath: e.savedPath }
|
|
1382
1384
|
} : null;
|
|
1383
1385
|
}
|
|
1384
|
-
function
|
|
1385
|
-
if (!
|
|
1386
|
+
function Vt(e) {
|
|
1387
|
+
if (!P(e) || e.type !== "commandExecution" || typeof e.command != "string") return !1;
|
|
1386
1388
|
let t = e.command;
|
|
1387
|
-
return
|
|
1389
|
+
return Xt(t) || Zt(t) || Qt(t);
|
|
1388
1390
|
}
|
|
1389
|
-
function
|
|
1391
|
+
function Ht(e, t) {
|
|
1390
1392
|
return {
|
|
1391
1393
|
itemId: e,
|
|
1392
1394
|
bodyDelta: t,
|
|
@@ -1399,11 +1401,11 @@ function Rt(e, t) {
|
|
|
1399
1401
|
}
|
|
1400
1402
|
};
|
|
1401
1403
|
}
|
|
1402
|
-
function
|
|
1403
|
-
let n =
|
|
1404
|
+
function Ut(e, t) {
|
|
1405
|
+
let n = nn("running", t);
|
|
1404
1406
|
return {
|
|
1405
1407
|
itemId: e,
|
|
1406
|
-
body:
|
|
1408
|
+
body: hn(t),
|
|
1407
1409
|
...n ? { statusText: n } : {},
|
|
1408
1410
|
input: { changes: t },
|
|
1409
1411
|
metadata: { changes: t },
|
|
@@ -1414,13 +1416,13 @@ function zt(e, t) {
|
|
|
1414
1416
|
title: t.length === 1 ? "1 file change" : `${t.length} file changes`,
|
|
1415
1417
|
status: "running",
|
|
1416
1418
|
...n ? { statusText: n } : {},
|
|
1417
|
-
body:
|
|
1419
|
+
body: hn(t),
|
|
1418
1420
|
input: { changes: t },
|
|
1419
1421
|
metadata: { changes: t }
|
|
1420
1422
|
}
|
|
1421
1423
|
};
|
|
1422
1424
|
}
|
|
1423
|
-
function
|
|
1425
|
+
function Wt(e, t) {
|
|
1424
1426
|
return {
|
|
1425
1427
|
itemId: e,
|
|
1426
1428
|
bodyAppend: t,
|
|
@@ -1433,12 +1435,12 @@ function Bt(e, t) {
|
|
|
1433
1435
|
}
|
|
1434
1436
|
};
|
|
1435
1437
|
}
|
|
1436
|
-
function
|
|
1437
|
-
let i =
|
|
1438
|
+
function Gt(e, t, n, r = "completed") {
|
|
1439
|
+
let i = F(t), a = gn(k(i));
|
|
1438
1440
|
return {
|
|
1439
1441
|
itemId: e,
|
|
1440
1442
|
title: n && n.trim() ? n : void 0,
|
|
1441
|
-
status:
|
|
1443
|
+
status: j(r),
|
|
1442
1444
|
body: a,
|
|
1443
1445
|
...i === void 0 ? {} : { output: i },
|
|
1444
1446
|
fallbackToolPart: {
|
|
@@ -1446,21 +1448,21 @@ function Vt(e, t, n, r = "completed") {
|
|
|
1446
1448
|
id: e,
|
|
1447
1449
|
kind: "generic",
|
|
1448
1450
|
title: n && n.trim() ? n : "Tool output",
|
|
1449
|
-
status:
|
|
1451
|
+
status: j(r),
|
|
1450
1452
|
body: a,
|
|
1451
1453
|
...i === void 0 ? {} : { output: i }
|
|
1452
1454
|
}
|
|
1453
1455
|
};
|
|
1454
1456
|
}
|
|
1455
|
-
function
|
|
1457
|
+
function j(e) {
|
|
1456
1458
|
return e === "completed" || e === "succeeded" || e === "success" ? "completed" : e === "failed" || e === "error" || e === "declined" || e === "incomplete" || e === "canceled" || e === "cancelled" ? "failed" : "running";
|
|
1457
1459
|
}
|
|
1458
|
-
function
|
|
1459
|
-
let r =
|
|
1460
|
+
function Kt(e, t, n) {
|
|
1461
|
+
let r = qt(e, t, n);
|
|
1460
1462
|
return r ? JSON.stringify(r) : void 0;
|
|
1461
1463
|
}
|
|
1462
|
-
function
|
|
1463
|
-
let r =
|
|
1464
|
+
function qt(e, t, n) {
|
|
1465
|
+
let r = Yt(t), i = new Set(r.map((e) => e.type));
|
|
1464
1466
|
if (r.length === 0) return {
|
|
1465
1467
|
action: "run",
|
|
1466
1468
|
phase: e,
|
|
@@ -1468,37 +1470,37 @@ function Ut(e, t, n) {
|
|
|
1468
1470
|
source: "codex"
|
|
1469
1471
|
};
|
|
1470
1472
|
if (i.size === 1 && i.has("read")) {
|
|
1471
|
-
let t =
|
|
1473
|
+
let t = M(r.map((e) => e.name ?? e.path));
|
|
1472
1474
|
return {
|
|
1473
1475
|
action: "read",
|
|
1474
1476
|
phase: e,
|
|
1475
1477
|
params: {
|
|
1476
1478
|
names: t,
|
|
1477
|
-
target:
|
|
1479
|
+
target: en(t, n)
|
|
1478
1480
|
},
|
|
1479
1481
|
source: "codex"
|
|
1480
1482
|
};
|
|
1481
1483
|
}
|
|
1482
1484
|
if (i.size === 1 && i.has("listFiles")) {
|
|
1483
|
-
let t =
|
|
1485
|
+
let t = M(r.map((e) => e.path ?? e.command));
|
|
1484
1486
|
return {
|
|
1485
1487
|
action: "list",
|
|
1486
1488
|
phase: e,
|
|
1487
1489
|
params: {
|
|
1488
1490
|
targets: t,
|
|
1489
|
-
target:
|
|
1491
|
+
target: $t(t, n)
|
|
1490
1492
|
},
|
|
1491
1493
|
source: "codex"
|
|
1492
1494
|
};
|
|
1493
1495
|
}
|
|
1494
1496
|
if (i.size === 1 && i.has("search")) {
|
|
1495
|
-
let t =
|
|
1497
|
+
let t = M(r.map((e) => e.query && e.path ? `"${e.query}" in ${e.path}` : e.query ?? e.path ?? e.command));
|
|
1496
1498
|
return {
|
|
1497
1499
|
action: "search",
|
|
1498
1500
|
phase: e,
|
|
1499
1501
|
params: {
|
|
1500
1502
|
targets: t,
|
|
1501
|
-
target:
|
|
1503
|
+
target: $t(t, n)
|
|
1502
1504
|
},
|
|
1503
1505
|
source: "codex"
|
|
1504
1506
|
};
|
|
@@ -1508,16 +1510,16 @@ function Ut(e, t, n) {
|
|
|
1508
1510
|
phase: e,
|
|
1509
1511
|
params: {
|
|
1510
1512
|
actions: r.map((e) => e.type),
|
|
1511
|
-
target:
|
|
1513
|
+
target: $t(M(r.map(Jt)), n)
|
|
1512
1514
|
},
|
|
1513
1515
|
source: "codex"
|
|
1514
1516
|
};
|
|
1515
1517
|
}
|
|
1516
|
-
function
|
|
1518
|
+
function Jt(e) {
|
|
1517
1519
|
return e.path ?? e.name ?? e.query ?? e.command;
|
|
1518
1520
|
}
|
|
1519
|
-
function
|
|
1520
|
-
return Array.isArray(e) ? e.flatMap((e) => !
|
|
1521
|
+
function Yt(e) {
|
|
1522
|
+
return Array.isArray(e) ? e.flatMap((e) => !P(e) || e.type !== "read" && e.type !== "listFiles" && e.type !== "search" ? [] : [{
|
|
1521
1523
|
command: typeof e.command == "string" ? e.command : void 0,
|
|
1522
1524
|
name: typeof e.name == "string" ? e.name : void 0,
|
|
1523
1525
|
path: typeof e.path == "string" ? e.path : void 0,
|
|
@@ -1525,35 +1527,35 @@ function Gt(e) {
|
|
|
1525
1527
|
type: e.type
|
|
1526
1528
|
}]) : [];
|
|
1527
1529
|
}
|
|
1528
|
-
function
|
|
1530
|
+
function Xt(e) {
|
|
1529
1531
|
return /(?:^|[\s;"'(|&])apply_patch(?:\s|$)/u.test(e);
|
|
1530
1532
|
}
|
|
1531
|
-
function
|
|
1533
|
+
function Zt(e) {
|
|
1532
1534
|
return /(?:^|[\s;"'(|&])(?:cat|printf|echo)\b[\s\S]*>>?\s*(?:"[^"]+"|'[^']+'|[^\s;"'&|]+)(?=$|[\s;&|])/u.test(e);
|
|
1533
1535
|
}
|
|
1534
|
-
function
|
|
1536
|
+
function Qt(e) {
|
|
1535
1537
|
return /(?:^|[\s;"'(|&])tee(?:\s+-a)?\s+(?!-)(?:"[^"]+"|'[^']+'|[^\s;"'&|]+)(?=$|[\s;&|])/u.test(e);
|
|
1536
1538
|
}
|
|
1537
|
-
function
|
|
1539
|
+
function M(e) {
|
|
1538
1540
|
return [...new Set(e.map((e) => e?.trim()).filter((e) => !!e))];
|
|
1539
1541
|
}
|
|
1540
|
-
function
|
|
1542
|
+
function $t(e, t) {
|
|
1541
1543
|
return e.length === 0 ? t : e.length <= 3 ? e.join(", ") : `${e.slice(0, 3).join(", ")} and ${e.length - 3} more`;
|
|
1542
1544
|
}
|
|
1543
|
-
function
|
|
1544
|
-
return
|
|
1545
|
+
function en(e, t) {
|
|
1546
|
+
return tn(e, t);
|
|
1545
1547
|
}
|
|
1546
|
-
function
|
|
1547
|
-
return
|
|
1548
|
+
function tn(e, t) {
|
|
1549
|
+
return $t(M(e.map(un)), t);
|
|
1548
1550
|
}
|
|
1549
|
-
function
|
|
1550
|
-
let n =
|
|
1551
|
+
function nn(e, t) {
|
|
1552
|
+
let n = rn(e, t);
|
|
1551
1553
|
return n ? JSON.stringify(n) : void 0;
|
|
1552
1554
|
}
|
|
1553
|
-
function
|
|
1555
|
+
function rn(e, t) {
|
|
1554
1556
|
let n = t.flatMap((e) => {
|
|
1555
|
-
if (!
|
|
1556
|
-
let t = typeof e.path == "string" ? e.path : void 0, n =
|
|
1557
|
+
if (!P(e)) return [];
|
|
1558
|
+
let t = typeof e.path == "string" ? e.path : void 0, n = N(e.kind), r = on(e);
|
|
1557
1559
|
return [{
|
|
1558
1560
|
addedLines: r.addedLines,
|
|
1559
1561
|
kind: n,
|
|
@@ -1562,9 +1564,9 @@ function $t(e, t) {
|
|
|
1562
1564
|
}];
|
|
1563
1565
|
});
|
|
1564
1566
|
if (!n.length) return;
|
|
1565
|
-
let r = n.reduce((e, t) => e + t.addedLines, 0), i = n.reduce((e, t) => e + t.removedLines, 0), a =
|
|
1567
|
+
let r = n.reduce((e, t) => e + t.addedLines, 0), i = n.reduce((e, t) => e + t.removedLines, 0), a = M(n.map((e) => e.path)), o = tn(a, `${n.length} files`);
|
|
1566
1568
|
return {
|
|
1567
|
-
action:
|
|
1569
|
+
action: an(n.map((e) => e.kind)),
|
|
1568
1570
|
phase: e,
|
|
1569
1571
|
params: {
|
|
1570
1572
|
addedLines: r,
|
|
@@ -1575,20 +1577,20 @@ function $t(e, t) {
|
|
|
1575
1577
|
source: "codex"
|
|
1576
1578
|
};
|
|
1577
1579
|
}
|
|
1578
|
-
function
|
|
1580
|
+
function an(e) {
|
|
1579
1581
|
return e.every((e) => e === "add") ? "create" : e.every((e) => e === "delete") ? "delete" : "edit";
|
|
1580
1582
|
}
|
|
1581
|
-
function
|
|
1582
|
-
let t = typeof e.diff == "string" ? e.diff : void 0, n =
|
|
1583
|
+
function on(e) {
|
|
1584
|
+
let t = typeof e.diff == "string" ? e.diff : void 0, n = N(e.kind);
|
|
1583
1585
|
return n === "add" ? {
|
|
1584
|
-
addedLines:
|
|
1586
|
+
addedLines: ln(t),
|
|
1585
1587
|
removedLines: 0
|
|
1586
1588
|
} : n === "delete" ? {
|
|
1587
1589
|
addedLines: 0,
|
|
1588
|
-
removedLines:
|
|
1589
|
-
} :
|
|
1590
|
+
removedLines: ln(t)
|
|
1591
|
+
} : sn(t);
|
|
1590
1592
|
}
|
|
1591
|
-
function
|
|
1593
|
+
function sn(e) {
|
|
1592
1594
|
if (!e) return {
|
|
1593
1595
|
addedLines: 0,
|
|
1594
1596
|
removedLines: 0
|
|
@@ -1600,54 +1602,54 @@ function nn(e) {
|
|
|
1600
1602
|
removedLines: n
|
|
1601
1603
|
};
|
|
1602
1604
|
}
|
|
1603
|
-
function
|
|
1605
|
+
function N(e) {
|
|
1604
1606
|
if (e === "add" || e === "delete") return e;
|
|
1605
|
-
if (
|
|
1607
|
+
if (P(e) && typeof e.type == "string") return N(e.type);
|
|
1606
1608
|
}
|
|
1607
|
-
function
|
|
1609
|
+
function cn(e, t) {
|
|
1608
1610
|
let n = e?.trim();
|
|
1609
1611
|
if (n) {
|
|
1610
|
-
if (
|
|
1611
|
-
if (!(!t || !
|
|
1612
|
+
if (v(n)) return n;
|
|
1613
|
+
if (!(!t || !v(t))) return x(t, n);
|
|
1612
1614
|
}
|
|
1613
1615
|
}
|
|
1614
|
-
function
|
|
1616
|
+
function ln(e) {
|
|
1615
1617
|
if (!e) return 0;
|
|
1616
1618
|
let t = e.split(/\r\n|\r|\n/);
|
|
1617
1619
|
for (; t.at(-1) === "";) t.pop();
|
|
1618
1620
|
return t.length;
|
|
1619
1621
|
}
|
|
1620
|
-
function
|
|
1622
|
+
function un(e) {
|
|
1621
1623
|
return e.split(/[\\/]/).filter(Boolean).at(-1) ?? e;
|
|
1622
1624
|
}
|
|
1623
|
-
function
|
|
1624
|
-
if (
|
|
1625
|
+
function dn(e) {
|
|
1626
|
+
if (P(e)) return typeof e.message == "string" ? e.message : void 0;
|
|
1625
1627
|
}
|
|
1626
|
-
function
|
|
1627
|
-
if (!
|
|
1628
|
-
let t =
|
|
1629
|
-
return n ? !t || t.trim() ===
|
|
1628
|
+
function fn(e) {
|
|
1629
|
+
if (!P(e)) return;
|
|
1630
|
+
let t = pn(e.content), n = "structuredContent" in e ? k(e.structuredContent) : void 0;
|
|
1631
|
+
return n ? !t || t.trim() === Rt ? n : `${t}\n\n${n}` : t;
|
|
1630
1632
|
}
|
|
1631
|
-
function
|
|
1632
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
1633
|
+
function pn(e) {
|
|
1634
|
+
if (Array.isArray(e)) return e.map((e) => P(e) ? typeof e.text == "string" ? e.text : JSON.stringify(e) : "").filter(Boolean).join("\n\n") || void 0;
|
|
1633
1635
|
}
|
|
1634
|
-
function
|
|
1635
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
1636
|
+
function mn(e) {
|
|
1637
|
+
if (Array.isArray(e)) return e.map((e) => P(e) && typeof e.text == "string" ? e.text : JSON.stringify(e)).filter(Boolean).join("\n\n") || void 0;
|
|
1636
1638
|
}
|
|
1637
|
-
function
|
|
1638
|
-
return e.map((e) =>
|
|
1639
|
+
function hn(e) {
|
|
1640
|
+
return e.map((e) => P(e) ? `${N(e.kind) ?? "update"} ${typeof e.path == "string" ? e.path : "unknown"}` : JSON.stringify(e)).join("\n") || void 0;
|
|
1639
1641
|
}
|
|
1640
|
-
function
|
|
1642
|
+
function P(e) {
|
|
1641
1643
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
1642
1644
|
}
|
|
1643
|
-
function
|
|
1644
|
-
return e !== void 0 && Buffer.byteLength(e) <=
|
|
1645
|
+
function gn(e) {
|
|
1646
|
+
return e !== void 0 && Buffer.byteLength(e) <= zt ? e : void 0;
|
|
1645
1647
|
}
|
|
1646
|
-
function
|
|
1647
|
-
if (!(e === void 0 || !
|
|
1648
|
+
function F(e) {
|
|
1649
|
+
if (!(e === void 0 || !_n(e, zt))) return e;
|
|
1648
1650
|
}
|
|
1649
|
-
function
|
|
1650
|
-
if (
|
|
1651
|
+
function _n(e, t) {
|
|
1652
|
+
if (vn(e, t, /* @__PURE__ */ new Set())) return !1;
|
|
1651
1653
|
try {
|
|
1652
1654
|
let n = JSON.stringify(e);
|
|
1653
1655
|
return n !== void 0 && Buffer.byteLength(n) <= t;
|
|
@@ -1655,28 +1657,28 @@ function pn(e, t) {
|
|
|
1655
1657
|
return !1;
|
|
1656
1658
|
}
|
|
1657
1659
|
}
|
|
1658
|
-
function
|
|
1660
|
+
function vn(e, t, n) {
|
|
1659
1661
|
if (typeof e == "string") return Buffer.byteLength(e) > t;
|
|
1660
1662
|
if (typeof e != "object" || !e) return !1;
|
|
1661
1663
|
if (n.has(e)) return !0;
|
|
1662
1664
|
n.add(e);
|
|
1663
|
-
let r = (Array.isArray(e) ? e : Object.values(e)).some((e) =>
|
|
1665
|
+
let r = (Array.isArray(e) ? e : Object.values(e)).some((e) => vn(e, t, n));
|
|
1664
1666
|
return n.delete(e), r;
|
|
1665
1667
|
}
|
|
1666
1668
|
//#endregion
|
|
1667
1669
|
//#region src/node/codex-surface-message-state.ts
|
|
1668
|
-
function
|
|
1670
|
+
function yn(e) {
|
|
1669
1671
|
for (let t = e.length - 1; t >= 0; --t) {
|
|
1670
1672
|
let n = e[t];
|
|
1671
1673
|
if (n?.status === "inProgress") return n.id;
|
|
1672
1674
|
}
|
|
1673
1675
|
return null;
|
|
1674
1676
|
}
|
|
1675
|
-
function
|
|
1676
|
-
let i = [...e], a =
|
|
1677
|
+
function I(e, t, n, r = {}) {
|
|
1678
|
+
let i = [...e], a = z(i, (e) => e.metadata?.turnId === n), o = a >= 0 ? i[a] : void 0;
|
|
1677
1679
|
if (o?.role === "assistant" && o.kind === void 0 && o.status === "streaming") return i;
|
|
1678
1680
|
if (r.forceSegment) {
|
|
1679
|
-
let e =
|
|
1681
|
+
let e = z(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), t = e >= 0 ? i[e] : void 0;
|
|
1680
1682
|
t?.parts.length === 0 ? i.splice(e, 1) : t && i.splice(e, 1, {
|
|
1681
1683
|
...t,
|
|
1682
1684
|
status: "complete"
|
|
@@ -1696,9 +1698,9 @@ function P(e, t, n, r = {}) {
|
|
|
1696
1698
|
}
|
|
1697
1699
|
}), i;
|
|
1698
1700
|
}
|
|
1699
|
-
function
|
|
1701
|
+
function bn(e, t, n, r, i, a) {
|
|
1700
1702
|
if (!i) return [...e];
|
|
1701
|
-
let o =
|
|
1703
|
+
let o = I(e, t, n), s = z(o, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), c = s >= 0 ? o[s] : void 0;
|
|
1702
1704
|
if (!c) return o;
|
|
1703
1705
|
let l = [...c.parts], u = l.at(-1);
|
|
1704
1706
|
return u?.type === "text" && u.itemId === r ? l.splice(l.length - 1, 1, {
|
|
@@ -1714,9 +1716,9 @@ function gn(e, t, n, r, i, a) {
|
|
|
1714
1716
|
...c,
|
|
1715
1717
|
status: "streaming",
|
|
1716
1718
|
parts: l
|
|
1717
|
-
}),
|
|
1719
|
+
}), R(o, t);
|
|
1718
1720
|
}
|
|
1719
|
-
function
|
|
1721
|
+
function xn(e, t, n, r, i) {
|
|
1720
1722
|
let a = i.map((e, t) => {
|
|
1721
1723
|
let n = e.trim();
|
|
1722
1724
|
return n ? {
|
|
@@ -1727,16 +1729,16 @@ function _n(e, t, n, r, i) {
|
|
|
1727
1729
|
} : null;
|
|
1728
1730
|
}).filter((e) => e !== null);
|
|
1729
1731
|
if (a.length === 0) return [...e];
|
|
1730
|
-
let o =
|
|
1732
|
+
let o = I(e, t, n), s = z(o, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), c = s >= 0 ? o[s] : void 0;
|
|
1731
1733
|
if (!c) return o;
|
|
1732
1734
|
let l = c.parts.findIndex((e) => e.type === "reasoning" && e.itemId === r), u = c.parts.filter((e) => e.type !== "reasoning" || e.itemId !== r);
|
|
1733
1735
|
return u.splice(l >= 0 ? l : u.length, 0, ...a), o.splice(s, 1, {
|
|
1734
1736
|
...c,
|
|
1735
1737
|
status: "streaming",
|
|
1736
1738
|
parts: u
|
|
1737
|
-
}),
|
|
1739
|
+
}), R(o, t);
|
|
1738
1740
|
}
|
|
1739
|
-
function
|
|
1741
|
+
function Sn(e, t, n, r, i, a) {
|
|
1740
1742
|
let o = [...e];
|
|
1741
1743
|
for (let e = o.length - 1; e >= 0; --e) {
|
|
1742
1744
|
let s = o[e];
|
|
@@ -1752,9 +1754,9 @@ function vn(e, t, n, r, i, a) {
|
|
|
1752
1754
|
}), o.splice(e, 1, {
|
|
1753
1755
|
...s,
|
|
1754
1756
|
parts: l
|
|
1755
|
-
}),
|
|
1757
|
+
}), R(o, t);
|
|
1756
1758
|
}
|
|
1757
|
-
let s =
|
|
1759
|
+
let s = I(o, t, n), c = z(s, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), l = c >= 0 ? s[c] : void 0;
|
|
1758
1760
|
if (!l) return s;
|
|
1759
1761
|
let u = {
|
|
1760
1762
|
type: "text",
|
|
@@ -1765,10 +1767,10 @@ function vn(e, t, n, r, i, a) {
|
|
|
1765
1767
|
return s.splice(c, 1, {
|
|
1766
1768
|
...l,
|
|
1767
1769
|
parts: [...l.parts, u]
|
|
1768
|
-
}),
|
|
1770
|
+
}), R(s, t);
|
|
1769
1771
|
}
|
|
1770
|
-
function
|
|
1771
|
-
return
|
|
1772
|
+
function Cn(e, t, n, r) {
|
|
1773
|
+
return R(e.map((e) => {
|
|
1772
1774
|
if (e.role !== "assistant" || e.metadata?.turnId !== n) return e;
|
|
1773
1775
|
let t = e.parts.filter((e) => e.type !== "text" || e.itemId !== r);
|
|
1774
1776
|
return t.length === e.parts.length ? e : {
|
|
@@ -1777,16 +1779,16 @@ function yn(e, t, n, r) {
|
|
|
1777
1779
|
};
|
|
1778
1780
|
}), t);
|
|
1779
1781
|
}
|
|
1780
|
-
function
|
|
1782
|
+
function wn(e) {
|
|
1781
1783
|
let t = /<proposed_plan>([\s\S]*?)<\/proposed_plan>/iu.exec(e), n = t?.[1]?.trim() ?? "";
|
|
1782
1784
|
return !t || !n ? null : {
|
|
1783
1785
|
markdown: n,
|
|
1784
1786
|
visibleText: `${e.slice(0, t.index)}${e.slice(t.index + t[0].length)}`.trim()
|
|
1785
1787
|
};
|
|
1786
1788
|
}
|
|
1787
|
-
function
|
|
1789
|
+
function L(e, t, n, r) {
|
|
1788
1790
|
let i = [...e], a = i.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "tool" && e.id === r.id));
|
|
1789
|
-
a < 0 && (i =
|
|
1791
|
+
a < 0 && (i = I(i, t, n), a = z(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n));
|
|
1790
1792
|
let o = a >= 0 ? i[a] : void 0;
|
|
1791
1793
|
if (!o) return i;
|
|
1792
1794
|
let s = [...o.parts], c = s.findIndex((e) => e.type === "tool" && e.id === r.id);
|
|
@@ -1798,7 +1800,7 @@ function F(e, t, n, r) {
|
|
|
1798
1800
|
body: r.body ?? e.body,
|
|
1799
1801
|
input: r.input ?? e.input,
|
|
1800
1802
|
output: r.output ?? e.output,
|
|
1801
|
-
statusText: r.statusText ??
|
|
1803
|
+
statusText: r.statusText ?? jn(e.statusText, r.status),
|
|
1802
1804
|
metadata: {
|
|
1803
1805
|
...e.metadata ?? {},
|
|
1804
1806
|
...r.metadata ?? {}
|
|
@@ -1808,11 +1810,11 @@ function F(e, t, n, r) {
|
|
|
1808
1810
|
return i.splice(a, 1, {
|
|
1809
1811
|
...o,
|
|
1810
1812
|
parts: s
|
|
1811
|
-
}),
|
|
1813
|
+
}), R(i, t);
|
|
1812
1814
|
}
|
|
1813
|
-
function
|
|
1815
|
+
function Tn(e, t, n, r) {
|
|
1814
1816
|
let i = [...e], a = i.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "media" && e.itemId === r.itemId));
|
|
1815
|
-
a < 0 && r.itemId && (a = i.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "tool" && e.id === r.itemId))), a < 0 && (i =
|
|
1817
|
+
a < 0 && r.itemId && (a = i.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "tool" && e.id === r.itemId))), a < 0 && (i = I(i, t, n), a = z(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n));
|
|
1816
1818
|
let o = a >= 0 ? i[a] : void 0;
|
|
1817
1819
|
if (!o) return i;
|
|
1818
1820
|
let s = [...o.parts], c = s.findIndex((e) => e.type === "media" && e.itemId === r.itemId);
|
|
@@ -1820,25 +1822,25 @@ function xn(e, t, n, r) {
|
|
|
1820
1822
|
...o,
|
|
1821
1823
|
status: "streaming",
|
|
1822
1824
|
parts: s
|
|
1823
|
-
}),
|
|
1825
|
+
}), R(i, t);
|
|
1824
1826
|
}
|
|
1825
|
-
function
|
|
1827
|
+
function En(e, t, n, r) {
|
|
1826
1828
|
let i = [...e], a = i.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "question" && e.request.id === r.request.id));
|
|
1827
|
-
a < 0 && (i =
|
|
1829
|
+
a < 0 && (i = I(i, t, n), a = z(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n));
|
|
1828
1830
|
let o = a >= 0 ? i[a] : void 0;
|
|
1829
1831
|
if (!o) return i;
|
|
1830
1832
|
let s = [...o.parts], c = s.findIndex((e) => e.type === "question" && e.request.id === r.request.id);
|
|
1831
1833
|
return c >= 0 ? s.splice(c, 1, r) : s.push(r), i.splice(a, 1, {
|
|
1832
1834
|
...o,
|
|
1833
1835
|
parts: s
|
|
1834
|
-
}),
|
|
1836
|
+
}), R(i, t);
|
|
1835
1837
|
}
|
|
1836
|
-
function
|
|
1838
|
+
function Dn(e, t) {
|
|
1837
1839
|
return e.itemId === t.itemId && e.media.url === t.media.url && e.media.alt === t.media.alt && e.media.mimeType === t.media.mimeType && e.media.prompt === t.media.prompt && e.media.title === t.media.title;
|
|
1838
1840
|
}
|
|
1839
|
-
function
|
|
1841
|
+
function On(e, t, n, r) {
|
|
1840
1842
|
let i = [...e], a = i.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "tool" && e.id === r.itemId));
|
|
1841
|
-
if (a < 0) return r.fallbackToolPart ?
|
|
1843
|
+
if (a < 0) return r.fallbackToolPart ? On(L(i, t, n, r.fallbackToolPart), t, n, {
|
|
1842
1844
|
...r,
|
|
1843
1845
|
fallbackToolPart: void 0
|
|
1844
1846
|
}) : i;
|
|
@@ -1864,12 +1866,12 @@ function wn(e, t, n, r) {
|
|
|
1864
1866
|
parts: s
|
|
1865
1867
|
}), i) : i;
|
|
1866
1868
|
}
|
|
1867
|
-
function
|
|
1869
|
+
function kn(e, t, n, r = "streaming") {
|
|
1868
1870
|
if (e.some((e) => e.kind === "compaction" && e.metadata?.turnId === n)) return e.map((e) => r === "complete" && e.kind === "compaction" && e.metadata?.turnId === n ? {
|
|
1869
1871
|
...e,
|
|
1870
1872
|
status: r
|
|
1871
1873
|
} : e);
|
|
1872
|
-
let i = [...e], a =
|
|
1874
|
+
let i = [...e], a = z(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), o = a >= 0 ? i[a] : void 0;
|
|
1873
1875
|
return o?.parts.length === 0 ? i.splice(a, 1) : o && i.splice(a, 1, {
|
|
1874
1876
|
...o,
|
|
1875
1877
|
status: "complete"
|
|
@@ -1885,16 +1887,16 @@ function Tn(e, t, n, r = "streaming") {
|
|
|
1885
1887
|
conversationId: t,
|
|
1886
1888
|
turnId: n
|
|
1887
1889
|
}
|
|
1888
|
-
}),
|
|
1890
|
+
}), R(i, t);
|
|
1889
1891
|
}
|
|
1890
|
-
function
|
|
1892
|
+
function An(e, t, n) {
|
|
1891
1893
|
let r = n === "completed" ? "completed" : "failed";
|
|
1892
1894
|
return e.map((e) => {
|
|
1893
1895
|
if (e.metadata?.turnId !== t) return e;
|
|
1894
1896
|
let n = !1, i = e.parts.map((e) => e.type !== "tool" || e.status !== "running" ? e : (n = !0, {
|
|
1895
1897
|
...e,
|
|
1896
1898
|
status: r,
|
|
1897
|
-
statusText:
|
|
1899
|
+
statusText: jn(e.statusText, r)
|
|
1898
1900
|
}));
|
|
1899
1901
|
return n ? {
|
|
1900
1902
|
...e,
|
|
@@ -1902,11 +1904,11 @@ function En(e, t, n) {
|
|
|
1902
1904
|
} : e;
|
|
1903
1905
|
});
|
|
1904
1906
|
}
|
|
1905
|
-
function
|
|
1907
|
+
function jn(e, t) {
|
|
1906
1908
|
if (t === "running" || !e) return e;
|
|
1907
1909
|
try {
|
|
1908
1910
|
let n = JSON.parse(e);
|
|
1909
|
-
return
|
|
1911
|
+
return ct(n) ? JSON.stringify({
|
|
1910
1912
|
...n,
|
|
1911
1913
|
phase: t
|
|
1912
1914
|
}) : e;
|
|
@@ -1914,27 +1916,27 @@ function Dn(e, t) {
|
|
|
1914
1916
|
return e;
|
|
1915
1917
|
}
|
|
1916
1918
|
}
|
|
1917
|
-
function
|
|
1919
|
+
function R(e, t) {
|
|
1918
1920
|
let n = e.map((e, t) => ({
|
|
1919
1921
|
message: e,
|
|
1920
1922
|
index: t
|
|
1921
1923
|
})).filter(({ message: e }) => e.metadata?.conversationId === t).at(-1)?.index ?? -1;
|
|
1922
1924
|
return e.filter((e, r) => e.metadata?.conversationId !== t || r === n || e.role !== "assistant" || e.kind !== void 0 || e.parts.length > 0);
|
|
1923
1925
|
}
|
|
1924
|
-
function
|
|
1926
|
+
function z(e, t) {
|
|
1925
1927
|
for (let n = e.length - 1; n >= 0; --n) {
|
|
1926
1928
|
let r = e[n];
|
|
1927
1929
|
if (r !== void 0 && t(r)) return n;
|
|
1928
1930
|
}
|
|
1929
1931
|
return -1;
|
|
1930
1932
|
}
|
|
1931
|
-
function
|
|
1933
|
+
function Mn(e, t) {
|
|
1932
1934
|
return e.includes(t) ? [...e] : [...e, t];
|
|
1933
1935
|
}
|
|
1934
|
-
function
|
|
1936
|
+
function Nn(e, t) {
|
|
1935
1937
|
return [e?.trim() ?? "", ...t.map((e) => `${e.status === "completed" ? "- [x]" : "- [ ]"} ${e.step}`)].filter(Boolean).join("\n");
|
|
1936
1938
|
}
|
|
1937
|
-
function
|
|
1939
|
+
function Pn(e, t, n) {
|
|
1938
1940
|
return {
|
|
1939
1941
|
type: "tool",
|
|
1940
1942
|
id: `plan-progress-${e}`,
|
|
@@ -1957,19 +1959,19 @@ function An(e, t, n) {
|
|
|
1957
1959
|
}
|
|
1958
1960
|
//#endregion
|
|
1959
1961
|
//#region src/node/codex-conversation-history.ts
|
|
1960
|
-
var
|
|
1962
|
+
var Fn = 16 * 1024 * 1024, In = /* @__PURE__ */ new Set([
|
|
1961
1963
|
"image/avif",
|
|
1962
1964
|
"image/gif",
|
|
1963
1965
|
"image/jpeg",
|
|
1964
1966
|
"image/png",
|
|
1965
1967
|
"image/webp"
|
|
1966
1968
|
]);
|
|
1967
|
-
function
|
|
1968
|
-
return (Array.isArray(e.turns) ? e.turns : []).flatMap((t) =>
|
|
1969
|
+
function Ln(e) {
|
|
1970
|
+
return (Array.isArray(e.turns) ? e.turns : []).flatMap((t) => zn(e.id, t));
|
|
1969
1971
|
}
|
|
1970
|
-
function
|
|
1972
|
+
function Rn(e, t) {
|
|
1971
1973
|
let n = /* @__PURE__ */ new Map();
|
|
1972
|
-
for (let t of e) for (let e of t.parts) e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path ||
|
|
1974
|
+
for (let t of e) for (let e of t.parts) e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path || Qn(e.attachment.url) && n.set(e.attachment.path, e.attachment.url);
|
|
1973
1975
|
return n.size === 0 ? [...t] : t.map((e) => {
|
|
1974
1976
|
let t = !1, r = e.parts.map((e) => {
|
|
1975
1977
|
if (e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path) return e;
|
|
@@ -1988,14 +1990,14 @@ function Pn(e, t) {
|
|
|
1988
1990
|
} : e;
|
|
1989
1991
|
});
|
|
1990
1992
|
}
|
|
1991
|
-
function
|
|
1992
|
-
let n = [], r = [], i =
|
|
1993
|
+
function zn(e, t) {
|
|
1994
|
+
let n = [], r = [], i = nr(t.startedAt ?? t.completedAt), a = 0, o = !1, s = /* @__PURE__ */ new Set(), c = () => {
|
|
1993
1995
|
if (r.length === 0) return;
|
|
1994
1996
|
let o = a === 0 ? "" : `-segment-${a}`;
|
|
1995
1997
|
n.push({
|
|
1996
1998
|
id: `assistant-${t.id}${o}`,
|
|
1997
1999
|
role: "assistant",
|
|
1998
|
-
status:
|
|
2000
|
+
status: tr(t.status),
|
|
1999
2001
|
turnId: t.id,
|
|
2000
2002
|
parts: [...r],
|
|
2001
2003
|
createdAt: i,
|
|
@@ -2007,7 +2009,7 @@ function Fn(e, t) {
|
|
|
2007
2009
|
};
|
|
2008
2010
|
for (let a of Array.isArray(t.items) ? t.items : []) {
|
|
2009
2011
|
if (a.type === "userMessage") {
|
|
2010
|
-
let r =
|
|
2012
|
+
let r = Un(a), l = Gn(a);
|
|
2011
2013
|
if (r.length > 0) {
|
|
2012
2014
|
let u = o, d = u ? null : JSON.stringify(r);
|
|
2013
2015
|
if (d && s.has(d)) continue;
|
|
@@ -2024,7 +2026,7 @@ function Fn(e, t) {
|
|
|
2024
2026
|
turnId: t.id,
|
|
2025
2027
|
...l.length > 0 ? {
|
|
2026
2028
|
asyncQuestionRequestIds: l,
|
|
2027
|
-
asyncQuestionAnswers:
|
|
2029
|
+
asyncQuestionAnswers: Kn(a)
|
|
2028
2030
|
} : {}
|
|
2029
2031
|
}
|
|
2030
2032
|
});
|
|
@@ -2050,7 +2052,7 @@ function Fn(e, t) {
|
|
|
2050
2052
|
continue;
|
|
2051
2053
|
}
|
|
2052
2054
|
if (a.type === "agentMessage") {
|
|
2053
|
-
let n = typeof a.text == "string" ? a.text : "", i =
|
|
2055
|
+
let n = typeof a.text == "string" ? a.text : "", i = Vn(e, t.id, a, !0), s = a.phase === "final_answer" ? wn(n) : null;
|
|
2054
2056
|
s && !i ? s.visibleText && (o = !0, r.push({
|
|
2055
2057
|
type: "text",
|
|
2056
2058
|
text: s.visibleText,
|
|
@@ -2086,17 +2088,17 @@ function Fn(e, t) {
|
|
|
2086
2088
|
}));
|
|
2087
2089
|
continue;
|
|
2088
2090
|
}
|
|
2089
|
-
let l =
|
|
2091
|
+
let l = A(a);
|
|
2090
2092
|
l && (o = !0, r.push(l));
|
|
2091
|
-
let u =
|
|
2093
|
+
let u = Hn(a);
|
|
2092
2094
|
u && (o = !0, r.push(u));
|
|
2093
2095
|
}
|
|
2094
|
-
return c(), t.status === "inProgress" ? n :
|
|
2096
|
+
return c(), t.status === "inProgress" ? n : An(n, t.id, t.status);
|
|
2095
2097
|
}
|
|
2096
|
-
function
|
|
2097
|
-
let r =
|
|
2098
|
+
function Bn(e, t, n) {
|
|
2099
|
+
let r = nr(t.startedAt);
|
|
2098
2100
|
if (n.type === "userMessage") {
|
|
2099
|
-
let i =
|
|
2101
|
+
let i = Un(n), a = Gn(n);
|
|
2100
2102
|
return i.length > 0 ? {
|
|
2101
2103
|
id: n.clientId ?? `user-${e}-${t.id}-${n.id}`,
|
|
2102
2104
|
role: "user",
|
|
@@ -2110,13 +2112,13 @@ function In(e, t, n) {
|
|
|
2110
2112
|
itemId: n.id,
|
|
2111
2113
|
...a.length > 0 ? {
|
|
2112
2114
|
asyncQuestionRequestIds: a,
|
|
2113
|
-
asyncQuestionAnswers:
|
|
2115
|
+
asyncQuestionAnswers: Kn(n)
|
|
2114
2116
|
} : {}
|
|
2115
2117
|
}
|
|
2116
2118
|
} : null;
|
|
2117
2119
|
}
|
|
2118
2120
|
if (n.type === "agentMessage" || n.type === "exitedReviewMode") {
|
|
2119
|
-
let i = n.type === "agentMessage" ? n.text : n.review, a = n.type === "agentMessage" && n.phase === "final_answer" ?
|
|
2121
|
+
let i = n.type === "agentMessage" ? n.text : n.review, a = n.type === "agentMessage" && n.phase === "final_answer" ? wn(i) : null, o = n.type === "agentMessage" ? Vn(e, t.id, n, !0) : null, s = [...!o && (a?.visibleText || !a && i) ? [{
|
|
2120
2122
|
type: "text",
|
|
2121
2123
|
text: a?.visibleText ?? i,
|
|
2122
2124
|
itemId: n.id,
|
|
@@ -2125,7 +2127,7 @@ function In(e, t, n) {
|
|
|
2125
2127
|
return s.length > 0 ? {
|
|
2126
2128
|
id: `assistant-${n.id}`,
|
|
2127
2129
|
role: "assistant",
|
|
2128
|
-
status:
|
|
2130
|
+
status: tr(t.status),
|
|
2129
2131
|
turnId: t.id,
|
|
2130
2132
|
parts: s,
|
|
2131
2133
|
createdAt: r,
|
|
@@ -2149,7 +2151,7 @@ function In(e, t, n) {
|
|
|
2149
2151
|
return i.length > 0 ? {
|
|
2150
2152
|
id: `assistant-${n.id}`,
|
|
2151
2153
|
role: "assistant",
|
|
2152
|
-
status:
|
|
2154
|
+
status: tr(t.status),
|
|
2153
2155
|
turnId: t.id,
|
|
2154
2156
|
parts: i,
|
|
2155
2157
|
createdAt: r,
|
|
@@ -2160,14 +2162,14 @@ function In(e, t, n) {
|
|
|
2160
2162
|
}
|
|
2161
2163
|
} : null;
|
|
2162
2164
|
}
|
|
2163
|
-
let i = [], a =
|
|
2165
|
+
let i = [], a = A(n);
|
|
2164
2166
|
a && i.push(a);
|
|
2165
|
-
let o =
|
|
2167
|
+
let o = Hn(n);
|
|
2166
2168
|
o && i.push(o);
|
|
2167
2169
|
let s = i.length > 0 ? {
|
|
2168
2170
|
id: `assistant-${n.id}`,
|
|
2169
2171
|
role: "assistant",
|
|
2170
|
-
status:
|
|
2172
|
+
status: tr(t.status),
|
|
2171
2173
|
turnId: t.id,
|
|
2172
2174
|
parts: i,
|
|
2173
2175
|
createdAt: r,
|
|
@@ -2177,9 +2179,9 @@ function In(e, t, n) {
|
|
|
2177
2179
|
itemId: n.id
|
|
2178
2180
|
}
|
|
2179
2181
|
} : null;
|
|
2180
|
-
return !s || t.status === "inProgress" ? s :
|
|
2182
|
+
return !s || t.status === "inProgress" ? s : An([s], t.id, t.status)[0] ?? null;
|
|
2181
2183
|
}
|
|
2182
|
-
function
|
|
2184
|
+
function Vn(e, t, n, r = !1) {
|
|
2183
2185
|
if (n.delivery !== "async") return null;
|
|
2184
2186
|
let i = n.questions ?? [], a = i.length > 0 ? i.map((e, t) => ({
|
|
2185
2187
|
id: JSON.stringify([
|
|
@@ -2221,9 +2223,9 @@ function Ln(e, t, n, r = !1) {
|
|
|
2221
2223
|
...r ? { historical: !0 } : {}
|
|
2222
2224
|
};
|
|
2223
2225
|
}
|
|
2224
|
-
function
|
|
2225
|
-
if (e.type !== "imageGeneration" ||
|
|
2226
|
-
let t = typeof e.savedPath == "string" &&
|
|
2226
|
+
function Hn(e) {
|
|
2227
|
+
if (e.type !== "imageGeneration" || A(e)?.status !== "completed") return null;
|
|
2228
|
+
let t = typeof e.savedPath == "string" && v(e.savedPath) ? e.savedPath : null, n = t ? Xn(t) : void 0, r = n && In.has(n) ? t : null, i = Zn(typeof e.result == "string" ? e.result.trim() : ""), a = i?.url ?? (r ? re(r).href : void 0);
|
|
2227
2229
|
if (!a) return null;
|
|
2228
2230
|
let o = typeof e.revisedPrompt == "string" ? e.revisedPrompt.trim() : "";
|
|
2229
2231
|
return {
|
|
@@ -2238,7 +2240,7 @@ function Rn(e) {
|
|
|
2238
2240
|
}
|
|
2239
2241
|
};
|
|
2240
2242
|
}
|
|
2241
|
-
function
|
|
2243
|
+
function Un(e) {
|
|
2242
2244
|
let t = Array.isArray(e.content) ? e.content : [], n = t.some((e) => B(e) && e.type === "text" && typeof e.text == "string" && e.text.length > 0), r = [], i = [], a = /* @__PURE__ */ new Set(), o = () => {
|
|
2243
2245
|
i.length > 0 && r.push({
|
|
2244
2246
|
type: "text",
|
|
@@ -2252,7 +2254,7 @@ function zn(e) {
|
|
|
2252
2254
|
if (a.has(t)) continue;
|
|
2253
2255
|
a.add(t);
|
|
2254
2256
|
}
|
|
2255
|
-
let t =
|
|
2257
|
+
let t = Wn(e), s = Pt(t);
|
|
2256
2258
|
if (s) {
|
|
2257
2259
|
o(), r.push({
|
|
2258
2260
|
type: "attachment",
|
|
@@ -2267,7 +2269,7 @@ function zn(e) {
|
|
|
2267
2269
|
i.push(t);
|
|
2268
2270
|
continue;
|
|
2269
2271
|
}
|
|
2270
|
-
let c =
|
|
2272
|
+
let c = Jn(e);
|
|
2271
2273
|
c && (o(), r.push({
|
|
2272
2274
|
type: "attachment",
|
|
2273
2275
|
attachment: c
|
|
@@ -2275,20 +2277,20 @@ function zn(e) {
|
|
|
2275
2277
|
}
|
|
2276
2278
|
return o(), r;
|
|
2277
2279
|
}
|
|
2278
|
-
function
|
|
2279
|
-
return !B(e) || typeof e.type != "string" ? "" : e.type === "text" && typeof e.text == "string" ?
|
|
2280
|
+
function Wn(e) {
|
|
2281
|
+
return !B(e) || typeof e.type != "string" ? "" : e.type === "text" && typeof e.text == "string" ? qn(e.text)?.displayText ?? e.text : e.type === "skill" && typeof e.name == "string" ? `$${e.name}` : "";
|
|
2280
2282
|
}
|
|
2281
|
-
function
|
|
2283
|
+
function Gn(e) {
|
|
2282
2284
|
let t = /* @__PURE__ */ new Set();
|
|
2283
|
-
for (let n of Array.isArray(e.content) ? e.content : []) if (!(!B(n) || n.type !== "text" || typeof n.text != "string")) for (let e of
|
|
2285
|
+
for (let n of Array.isArray(e.content) ? e.content : []) if (!(!B(n) || n.type !== "text" || typeof n.text != "string")) for (let e of qn(n.text)?.requestIds ?? []) t.add(e);
|
|
2284
2286
|
return [...t];
|
|
2285
2287
|
}
|
|
2286
|
-
function
|
|
2288
|
+
function Kn(e) {
|
|
2287
2289
|
let t = {};
|
|
2288
|
-
for (let n of Array.isArray(e.content) ? e.content : []) !B(n) || n.type !== "text" || typeof n.text != "string" || Object.assign(t,
|
|
2290
|
+
for (let n of Array.isArray(e.content) ? e.content : []) !B(n) || n.type !== "text" || typeof n.text != "string" || Object.assign(t, qn(n.text)?.answers);
|
|
2289
2291
|
return t;
|
|
2290
2292
|
}
|
|
2291
|
-
function
|
|
2293
|
+
function qn(e) {
|
|
2292
2294
|
let t = e.match(/^<send_user_message_question_reply>\s*([\s\S]*?)\s*<\/send_user_message_question_reply>$/);
|
|
2293
2295
|
if (!t?.[1]) return null;
|
|
2294
2296
|
try {
|
|
@@ -2312,10 +2314,10 @@ function Un(e) {
|
|
|
2312
2314
|
return null;
|
|
2313
2315
|
}
|
|
2314
2316
|
}
|
|
2315
|
-
function
|
|
2317
|
+
function Jn(e) {
|
|
2316
2318
|
if (!B(e) || typeof e.type != "string") return null;
|
|
2317
2319
|
if (e.type === "mention" && typeof e.path == "string") {
|
|
2318
|
-
let t = typeof e.name == "string" && e.name.trim() ? e.name.trim() :
|
|
2320
|
+
let t = typeof e.name == "string" && e.name.trim() ? e.name.trim() : Yn(e.path, "File"), n = Xn(e.path);
|
|
2319
2321
|
return {
|
|
2320
2322
|
kind: "file",
|
|
2321
2323
|
name: t,
|
|
@@ -2324,41 +2326,41 @@ function Wn(e) {
|
|
|
2324
2326
|
};
|
|
2325
2327
|
}
|
|
2326
2328
|
if (e.type === "image" && typeof e.url == "string") {
|
|
2327
|
-
let t =
|
|
2329
|
+
let t = Xn(e.url);
|
|
2328
2330
|
return {
|
|
2329
2331
|
kind: "image",
|
|
2330
|
-
name:
|
|
2332
|
+
name: Yn(e.url, "Image"),
|
|
2331
2333
|
url: e.url,
|
|
2332
2334
|
...t ? { mimeType: t } : {}
|
|
2333
2335
|
};
|
|
2334
2336
|
}
|
|
2335
2337
|
if (e.type === "localImage" && typeof e.path == "string") {
|
|
2336
|
-
let t =
|
|
2338
|
+
let t = Xn(e.path);
|
|
2337
2339
|
return {
|
|
2338
2340
|
kind: "image",
|
|
2339
|
-
name:
|
|
2341
|
+
name: Yn(e.path, "Image"),
|
|
2340
2342
|
path: e.path,
|
|
2341
2343
|
...t ? { mimeType: t } : {}
|
|
2342
2344
|
};
|
|
2343
2345
|
}
|
|
2344
2346
|
return null;
|
|
2345
2347
|
}
|
|
2346
|
-
function
|
|
2348
|
+
function Yn(e, t) {
|
|
2347
2349
|
try {
|
|
2348
2350
|
let n = /^[a-z][a-z\d+.-]*:/i.test(e) ? new URL(e).pathname : e;
|
|
2349
|
-
return
|
|
2351
|
+
return g(decodeURIComponent(n)).trim() || t;
|
|
2350
2352
|
} catch {
|
|
2351
|
-
return
|
|
2353
|
+
return g(e).trim() || t;
|
|
2352
2354
|
}
|
|
2353
2355
|
}
|
|
2354
|
-
function
|
|
2356
|
+
function Xn(e) {
|
|
2355
2357
|
let t = /^data:([^;,]+)/i.exec(e)?.[1]?.toLowerCase();
|
|
2356
2358
|
if (t) return t;
|
|
2357
2359
|
let n = "";
|
|
2358
2360
|
try {
|
|
2359
|
-
n =
|
|
2361
|
+
n = _(/^[a-z][a-z\d+.-]*:/i.test(e) ? new URL(e).pathname : e).slice(1).toLowerCase();
|
|
2360
2362
|
} catch {
|
|
2361
|
-
n =
|
|
2363
|
+
n = _(e).slice(1).toLowerCase();
|
|
2362
2364
|
}
|
|
2363
2365
|
return {
|
|
2364
2366
|
avif: "image/avif",
|
|
@@ -2373,23 +2375,23 @@ function R(e) {
|
|
|
2373
2375
|
webp: "image/webp"
|
|
2374
2376
|
}[n];
|
|
2375
2377
|
}
|
|
2376
|
-
function
|
|
2378
|
+
function Zn(e) {
|
|
2377
2379
|
if (!e) return null;
|
|
2378
|
-
let t = (/^data:image\/[a-z0-9.+-]+;base64,([a-z0-9+/=\s]+)$/i.exec(e)?.[1] ?? e).replace(/\s+/g, ""), n = Math.ceil(
|
|
2380
|
+
let t = (/^data:image\/[a-z0-9.+-]+;base64,([a-z0-9+/=\s]+)$/i.exec(e)?.[1] ?? e).replace(/\s+/g, ""), n = Math.ceil(Fn / 3) * 4 + 4;
|
|
2379
2381
|
if (!t || t.length > n || t.length % 4 != 0 || !/^[a-z0-9+/]+={0,2}$/i.test(t)) return null;
|
|
2380
2382
|
let r = Buffer.from(t, "base64");
|
|
2381
|
-
if (r.byteLength === 0 || r.byteLength >
|
|
2382
|
-
let i =
|
|
2383
|
+
if (r.byteLength === 0 || r.byteLength > Fn) return null;
|
|
2384
|
+
let i = $n(r);
|
|
2383
2385
|
return i ? {
|
|
2384
2386
|
url: `data:${i};base64,${t}`,
|
|
2385
2387
|
mimeType: i
|
|
2386
2388
|
} : null;
|
|
2387
2389
|
}
|
|
2388
|
-
function
|
|
2390
|
+
function Qn(e) {
|
|
2389
2391
|
return !!(e && e.length <= 16 * 1024 * 1024 && /^data:image\/(?:avif|bmp|gif|heic|heif|jpe?g|png|webp);base64,[a-z\d+/]+={0,2}$/i.test(e));
|
|
2390
2392
|
}
|
|
2391
|
-
function
|
|
2392
|
-
if (
|
|
2393
|
+
function $n(e) {
|
|
2394
|
+
if (er(e, [
|
|
2393
2395
|
137,
|
|
2394
2396
|
80,
|
|
2395
2397
|
78,
|
|
@@ -2399,7 +2401,7 @@ function Jn(e) {
|
|
|
2399
2401
|
26,
|
|
2400
2402
|
10
|
|
2401
2403
|
])) return "image/png";
|
|
2402
|
-
if (
|
|
2404
|
+
if (er(e, [
|
|
2403
2405
|
255,
|
|
2404
2406
|
216,
|
|
2405
2407
|
255
|
|
@@ -2407,13 +2409,13 @@ function Jn(e) {
|
|
|
2407
2409
|
let t = Buffer.from(e.subarray(0, 12)).toString("ascii");
|
|
2408
2410
|
return t.startsWith("GIF87a") || t.startsWith("GIF89a") ? "image/gif" : t.startsWith("RIFF") && t.slice(8, 12) === "WEBP" ? "image/webp" : e.byteLength >= 12 && t.slice(4, 12) === "ftypavif" ? "image/avif" : null;
|
|
2409
2411
|
}
|
|
2410
|
-
function
|
|
2412
|
+
function er(e, t) {
|
|
2411
2413
|
return t.every((t, n) => e[n] === t);
|
|
2412
2414
|
}
|
|
2413
|
-
function
|
|
2415
|
+
function tr(e) {
|
|
2414
2416
|
return e === "inProgress" ? "streaming" : e === "failed" ? "error" : "complete";
|
|
2415
2417
|
}
|
|
2416
|
-
function
|
|
2418
|
+
function nr(e) {
|
|
2417
2419
|
return typeof e != "number" || !Number.isFinite(e) ? (/* @__PURE__ */ new Date(0)).toISOString() : (/* @__PURE__ */ new Date(e * 1e3)).toISOString();
|
|
2418
2420
|
}
|
|
2419
2421
|
function B(e) {
|
|
@@ -2421,21 +2423,21 @@ function B(e) {
|
|
|
2421
2423
|
}
|
|
2422
2424
|
//#endregion
|
|
2423
2425
|
//#region src/node/codex-raw-response-item-adapter.ts
|
|
2424
|
-
function
|
|
2425
|
-
if (!
|
|
2426
|
+
function rr(e) {
|
|
2427
|
+
if (!fr(e) || typeof e.type != "string") return null;
|
|
2426
2428
|
if (e.type === "local_shell_call") {
|
|
2427
|
-
let t =
|
|
2429
|
+
let t = A(ir(e));
|
|
2428
2430
|
return {
|
|
2429
|
-
type:
|
|
2431
|
+
type: cr(e.status) ? "item.completed" : "item.started",
|
|
2430
2432
|
payload: { toolPart: t }
|
|
2431
2433
|
};
|
|
2432
2434
|
}
|
|
2433
2435
|
return e.type === "function_call" ? {
|
|
2434
2436
|
type: "item.started",
|
|
2435
|
-
payload: { toolPart:
|
|
2436
|
-
} : e.type === "function_call_output" ?
|
|
2437
|
+
payload: { toolPart: A(ar(e)) }
|
|
2438
|
+
} : e.type === "function_call_output" ? or(e.call_id, e.output) : e.type === "custom_tool_call" ? {
|
|
2437
2439
|
type: "item.started",
|
|
2438
|
-
payload: { toolPart:
|
|
2440
|
+
payload: { toolPart: A({
|
|
2439
2441
|
type: "dynamicToolCall",
|
|
2440
2442
|
id: H(e.call_id) ?? V(e),
|
|
2441
2443
|
namespace: null,
|
|
@@ -2446,9 +2448,9 @@ function Zn(e) {
|
|
|
2446
2448
|
success: null,
|
|
2447
2449
|
durationMs: null
|
|
2448
2450
|
}) }
|
|
2449
|
-
} : e.type === "custom_tool_call_output" ?
|
|
2451
|
+
} : e.type === "custom_tool_call_output" ? or(e.call_id, e.output, H(e.name) ?? void 0) : e.type === "tool_search_call" ? {
|
|
2450
2452
|
type: "item.started",
|
|
2451
|
-
payload: { toolPart:
|
|
2453
|
+
payload: { toolPart: A({
|
|
2452
2454
|
type: "dynamicToolCall",
|
|
2453
2455
|
id: H(e.call_id) ?? V(e),
|
|
2454
2456
|
namespace: "codex",
|
|
@@ -2462,18 +2464,18 @@ function Zn(e) {
|
|
|
2462
2464
|
}) }
|
|
2463
2465
|
} : e.type === "tool_search_output" ? {
|
|
2464
2466
|
type: "item.updated",
|
|
2465
|
-
payload:
|
|
2467
|
+
payload: Gt(H(e.call_id) ?? V(e), e.tools, "tool_search", e.status)
|
|
2466
2468
|
} : e.type === "web_search_call" ? {
|
|
2467
2469
|
type: "item.completed",
|
|
2468
|
-
payload: { toolPart:
|
|
2470
|
+
payload: { toolPart: A({
|
|
2469
2471
|
type: "webSearch",
|
|
2470
2472
|
id: V(e),
|
|
2471
|
-
query:
|
|
2473
|
+
query: ur(e.action),
|
|
2472
2474
|
action: e.action
|
|
2473
2475
|
}) }
|
|
2474
2476
|
} : e.type === "image_generation_call" ? {
|
|
2475
2477
|
type: "item.completed",
|
|
2476
|
-
payload: { toolPart:
|
|
2478
|
+
payload: { toolPart: A({
|
|
2477
2479
|
type: "dynamicToolCall",
|
|
2478
2480
|
id: H(e.id) ?? V(e),
|
|
2479
2481
|
namespace: null,
|
|
@@ -2486,8 +2488,8 @@ function Zn(e) {
|
|
|
2486
2488
|
}) }
|
|
2487
2489
|
} : null;
|
|
2488
2490
|
}
|
|
2489
|
-
function
|
|
2490
|
-
let t =
|
|
2491
|
+
function ir(e) {
|
|
2492
|
+
let t = fr(e.action) ? e.action : {}, n = Array.isArray(t.command) ? dr(t.command) : H(t.command) ?? "local shell";
|
|
2491
2493
|
return {
|
|
2492
2494
|
type: "commandExecution",
|
|
2493
2495
|
id: H(e.call_id) ?? V(e),
|
|
@@ -2495,16 +2497,16 @@ function Qn(e) {
|
|
|
2495
2497
|
cwd: H(t.working_directory) ?? "",
|
|
2496
2498
|
processId: null,
|
|
2497
2499
|
source: "agent",
|
|
2498
|
-
status:
|
|
2500
|
+
status: sr(e.status),
|
|
2499
2501
|
commandActions: [],
|
|
2500
2502
|
aggregatedOutput: null,
|
|
2501
2503
|
exitCode: null,
|
|
2502
2504
|
durationMs: null
|
|
2503
2505
|
};
|
|
2504
2506
|
}
|
|
2505
|
-
function
|
|
2506
|
-
let t = H(e.name) ?? "function_call", n =
|
|
2507
|
-
return t === "shell_command" &&
|
|
2507
|
+
function ar(e) {
|
|
2508
|
+
let t = H(e.name) ?? "function_call", n = lr(e.arguments), r = H(e.call_id) ?? V(e);
|
|
2509
|
+
return t === "shell_command" && fr(n) ? {
|
|
2508
2510
|
type: "commandExecution",
|
|
2509
2511
|
id: r,
|
|
2510
2512
|
command: H(n.command) ?? t,
|
|
@@ -2528,19 +2530,19 @@ function $n(e) {
|
|
|
2528
2530
|
durationMs: null
|
|
2529
2531
|
};
|
|
2530
2532
|
}
|
|
2531
|
-
function
|
|
2533
|
+
function or(e, t, n) {
|
|
2532
2534
|
return {
|
|
2533
2535
|
type: "item.updated",
|
|
2534
|
-
payload:
|
|
2536
|
+
payload: Gt(H(e) ?? "raw-response-output", t, n)
|
|
2535
2537
|
};
|
|
2536
2538
|
}
|
|
2537
|
-
function
|
|
2539
|
+
function sr(e) {
|
|
2538
2540
|
return e === "completed" ? "completed" : e === "incomplete" || e === "failed" || e === "error" ? "failed" : "inProgress";
|
|
2539
2541
|
}
|
|
2540
|
-
function
|
|
2542
|
+
function cr(e) {
|
|
2541
2543
|
return e === "completed" || e === "failed" || e === "error" || e === "incomplete";
|
|
2542
2544
|
}
|
|
2543
|
-
function
|
|
2545
|
+
function lr(e) {
|
|
2544
2546
|
if (typeof e != "string") return e;
|
|
2545
2547
|
try {
|
|
2546
2548
|
return JSON.parse(e);
|
|
@@ -2548,10 +2550,10 @@ function rr(e) {
|
|
|
2548
2550
|
return e;
|
|
2549
2551
|
}
|
|
2550
2552
|
}
|
|
2551
|
-
function
|
|
2552
|
-
return
|
|
2553
|
+
function ur(e) {
|
|
2554
|
+
return fr(e) ? H(e.query) ?? H(e.searchTerm) ?? "web search" : "web search";
|
|
2553
2555
|
}
|
|
2554
|
-
function
|
|
2556
|
+
function dr(e) {
|
|
2555
2557
|
return e.map((e) => {
|
|
2556
2558
|
let t = String(e);
|
|
2557
2559
|
return /\s/.test(t) ? JSON.stringify(t) : t;
|
|
@@ -2563,21 +2565,21 @@ function V(e) {
|
|
|
2563
2565
|
function H(e) {
|
|
2564
2566
|
return typeof e == "string" && e.length > 0 ? e : null;
|
|
2565
2567
|
}
|
|
2566
|
-
function
|
|
2568
|
+
function fr(e) {
|
|
2567
2569
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
2568
2570
|
}
|
|
2569
2571
|
//#endregion
|
|
2570
2572
|
//#region src/node/codex-surface-events.ts
|
|
2571
|
-
function
|
|
2573
|
+
function pr(e, t) {
|
|
2572
2574
|
return `${e}\u0000${t}`;
|
|
2573
2575
|
}
|
|
2574
2576
|
function U(e) {
|
|
2575
2577
|
return typeof e == "number" && Number.isFinite(e) ? (/* @__PURE__ */ new Date(e * 1e3)).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
|
|
2576
2578
|
}
|
|
2577
|
-
function
|
|
2579
|
+
function mr(e) {
|
|
2578
2580
|
return typeof e == "number" && Number.isFinite(e) ? (/* @__PURE__ */ new Date(e * 1e3)).toISOString() : null;
|
|
2579
2581
|
}
|
|
2580
|
-
function
|
|
2582
|
+
function hr(e) {
|
|
2581
2583
|
return e ? {
|
|
2582
2584
|
message: e.message,
|
|
2583
2585
|
additionalDetails: e.additionalDetails,
|
|
@@ -2588,10 +2590,10 @@ function W(e, t = !1) {
|
|
|
2588
2590
|
return {
|
|
2589
2591
|
id: e.id,
|
|
2590
2592
|
status: e.status,
|
|
2591
|
-
error:
|
|
2593
|
+
error: hr(e.error),
|
|
2592
2594
|
willRetry: t,
|
|
2593
|
-
startedAt:
|
|
2594
|
-
completedAt:
|
|
2595
|
+
startedAt: mr(e.startedAt),
|
|
2596
|
+
completedAt: mr(e.completedAt),
|
|
2595
2597
|
durationMs: e.durationMs ?? null
|
|
2596
2598
|
};
|
|
2597
2599
|
}
|
|
@@ -2601,18 +2603,18 @@ function G(e, t) {
|
|
|
2601
2603
|
let r = [...e];
|
|
2602
2604
|
return r.splice(n, 1, t), r;
|
|
2603
2605
|
}
|
|
2604
|
-
function
|
|
2606
|
+
function gr(e, t) {
|
|
2605
2607
|
return JSON.stringify(e) === JSON.stringify(t);
|
|
2606
2608
|
}
|
|
2607
|
-
function
|
|
2609
|
+
function _r() {
|
|
2608
2610
|
return `user-${globalThis.crypto.randomUUID()}`;
|
|
2609
2611
|
}
|
|
2610
|
-
function
|
|
2612
|
+
function vr() {
|
|
2611
2613
|
return `queued-prompt-${globalThis.crypto.randomUUID()}`;
|
|
2612
2614
|
}
|
|
2613
2615
|
//#endregion
|
|
2614
2616
|
//#region src/node/codex-surface-subagents.ts
|
|
2615
|
-
function
|
|
2617
|
+
function yr(e) {
|
|
2616
2618
|
let t = {};
|
|
2617
2619
|
for (let [n, r] of Object.entries(e.agentsStates)) r && (t[n] = {
|
|
2618
2620
|
status: r.status,
|
|
@@ -2632,7 +2634,7 @@ function pr(e) {
|
|
|
2632
2634
|
}
|
|
2633
2635
|
//#endregion
|
|
2634
2636
|
//#region src/node/codex-surface-items-controller.ts
|
|
2635
|
-
var
|
|
2637
|
+
var br = class {
|
|
2636
2638
|
host;
|
|
2637
2639
|
commandOutputForwardItemIds = /* @__PURE__ */ new Set();
|
|
2638
2640
|
fileActivityKeys = /* @__PURE__ */ new Set();
|
|
@@ -2650,13 +2652,13 @@ var mr = class {
|
|
|
2650
2652
|
for (let e of this.reviewOutputByTurn.keys()) e.startsWith(t) && this.reviewOutputByTurn.delete(e);
|
|
2651
2653
|
}
|
|
2652
2654
|
isForwardingCommandOutput(e, t) {
|
|
2653
|
-
return this.commandOutputForwardItemIds.has(
|
|
2655
|
+
return this.commandOutputForwardItemIds.has(pr(e, t));
|
|
2654
2656
|
}
|
|
2655
2657
|
applyAgentDelta(e) {
|
|
2656
2658
|
let t = this.host.requireRuntime(e.threadId);
|
|
2657
2659
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
2658
2660
|
let n = t.messages.flatMap((e) => e.parts).find((t) => t.type === "text" && t.itemId === e.itemId)?.phase;
|
|
2659
|
-
this.host.patchRuntime(e.threadId, { messages:
|
|
2661
|
+
this.host.patchRuntime(e.threadId, { messages: bn(t.messages, e.threadId, e.turnId, e.itemId, e.delta, n) });
|
|
2660
2662
|
let r = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2661
2663
|
r && this.host.emitEvent("notification", {
|
|
2662
2664
|
type: "message.delta",
|
|
@@ -2674,7 +2676,7 @@ var mr = class {
|
|
|
2674
2676
|
let t = this.host.requireRuntime(e.threadId);
|
|
2675
2677
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
2676
2678
|
let n = `${t.planMarkdownByTurn.get(e.turnId) ?? ""}${e.delta}`;
|
|
2677
|
-
t.planMarkdownByTurn.set(e.turnId, n), this.host.patchRuntime(e.threadId, { messages:
|
|
2679
|
+
t.planMarkdownByTurn.set(e.turnId, n), this.host.patchRuntime(e.threadId, { messages: L(t.messages, e.threadId, e.turnId, Pn(e.turnId, n, "running")) }), this.host.emitEvent("notification", {
|
|
2678
2680
|
type: "plan.delta",
|
|
2679
2681
|
conversationId: e.threadId,
|
|
2680
2682
|
turnId: e.turnId,
|
|
@@ -2688,7 +2690,7 @@ var mr = class {
|
|
|
2688
2690
|
applyPlanUpdated(e) {
|
|
2689
2691
|
let t = this.host.requireRuntime(e.threadId);
|
|
2690
2692
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
2691
|
-
let n =
|
|
2693
|
+
let n = Nn(e.explanation, e.plan), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
2692
2694
|
t.planMarkdownByTurn.set(e.turnId, n), this.host.patchRuntime(e.threadId, {
|
|
2693
2695
|
executionPlan: {
|
|
2694
2696
|
turnId: e.turnId,
|
|
@@ -2697,7 +2699,7 @@ var mr = class {
|
|
|
2697
2699
|
markdown: n,
|
|
2698
2700
|
updatedAt: r
|
|
2699
2701
|
},
|
|
2700
|
-
messages:
|
|
2702
|
+
messages: L(t.messages, e.threadId, e.turnId, Pn(e.turnId, n, "completed"))
|
|
2701
2703
|
}), this.host.emitEvent("notification", {
|
|
2702
2704
|
type: "plan.updated",
|
|
2703
2705
|
conversationId: e.threadId,
|
|
@@ -2713,13 +2715,13 @@ var mr = class {
|
|
|
2713
2715
|
applyRawResponseItem(e) {
|
|
2714
2716
|
let t = this.host.requireRuntime(e.threadId);
|
|
2715
2717
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
2716
|
-
let n =
|
|
2718
|
+
let n = rr(e.item);
|
|
2717
2719
|
if (!n) return;
|
|
2718
2720
|
if (n.type === "item.updated") {
|
|
2719
2721
|
this.applyToolUpdate(e.threadId, e.turnId, n.payload);
|
|
2720
2722
|
return;
|
|
2721
2723
|
}
|
|
2722
|
-
this.host.patchRuntime(e.threadId, { messages:
|
|
2724
|
+
this.host.patchRuntime(e.threadId, { messages: L(t.messages, e.threadId, e.turnId, n.payload.toolPart) });
|
|
2723
2725
|
let r = this.host.messageContainingTool(e.threadId, e.turnId, n.payload.toolPart.id);
|
|
2724
2726
|
r && (this.host.emitEvent("notification", {
|
|
2725
2727
|
type: n.type === "item.completed" ? "tool.completed" : "tool.started",
|
|
@@ -2740,7 +2742,7 @@ var mr = class {
|
|
|
2740
2742
|
startedAt: ("startedAtMs" in e ? e.startedAtMs : e.completedAtMs) / 1e3
|
|
2741
2743
|
};
|
|
2742
2744
|
if (e.item.type === "userMessage") {
|
|
2743
|
-
let t =
|
|
2745
|
+
let t = Bn(e.threadId, i, e.item);
|
|
2744
2746
|
if (!t || n.messages.some((e) => e.id === t.id)) return;
|
|
2745
2747
|
let a = n.messages.some((t) => t.role === "assistant" && t.metadata?.turnId === e.turnId && t.parts.length > 0), o = !a && r ? n.messages.map((e) => e.role === "user" && e.kind !== "steer" && !e.turnId && JSON.stringify(e.parts) === JSON.stringify(t.parts)).lastIndexOf(!0) : -1;
|
|
2746
2748
|
if (o >= 0) {
|
|
@@ -2766,7 +2768,7 @@ var mr = class {
|
|
|
2766
2768
|
...t,
|
|
2767
2769
|
kind: "steer"
|
|
2768
2770
|
} : t, c = [...n.messages, s];
|
|
2769
|
-
this.host.patchRuntime(e.threadId, { messages: a ?
|
|
2771
|
+
this.host.patchRuntime(e.threadId, { messages: a ? I(c, e.threadId, e.turnId, { forceSegment: !0 }) : c }), this.host.emitEvent("notification", {
|
|
2770
2772
|
type: "message.appended",
|
|
2771
2773
|
conversationId: e.threadId,
|
|
2772
2774
|
turnId: e.turnId,
|
|
@@ -2777,7 +2779,7 @@ var mr = class {
|
|
|
2777
2779
|
if (e.item.type === "reasoning") {
|
|
2778
2780
|
if (e.item.summary.filter((e) => e.trim().length > 0).length === 0) return;
|
|
2779
2781
|
let t = this.host.assistantMessageForTurn(e.threadId, e.turnId), r = t ? JSON.stringify(t.parts) : null;
|
|
2780
|
-
this.host.patchRuntime(e.threadId, { messages:
|
|
2782
|
+
this.host.patchRuntime(e.threadId, { messages: xn(n.messages, e.threadId, e.turnId, e.item.id, e.item.summary) });
|
|
2781
2783
|
let i = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2782
2784
|
if (!i || JSON.stringify(i.parts) === r) return;
|
|
2783
2785
|
this.host.emitEvent("notification", {
|
|
@@ -2789,10 +2791,10 @@ var mr = class {
|
|
|
2789
2791
|
return;
|
|
2790
2792
|
}
|
|
2791
2793
|
if (e.item.type === "agentMessage" && t && n.planMode && e.item.phase === "final_answer") {
|
|
2792
|
-
let t =
|
|
2794
|
+
let t = wn(e.item.text);
|
|
2793
2795
|
if (t) {
|
|
2794
|
-
let r = this.host.assistantMessageForTurn(e.threadId, e.turnId), i =
|
|
2795
|
-
t.visibleText && (i =
|
|
2796
|
+
let r = this.host.assistantMessageForTurn(e.threadId, e.turnId), i = Cn(n.messages, e.threadId, e.turnId, e.item.id);
|
|
2797
|
+
t.visibleText && (i = Sn(i, e.threadId, e.turnId, e.item.id, t.visibleText, e.item.phase)), i = L(i, e.threadId, e.turnId, Pn(e.turnId, t.markdown, "completed")), n.planMarkdownByTurn.set(e.turnId, t.markdown), this.host.patchRuntime(e.threadId, { messages: i });
|
|
2796
2798
|
let a = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2797
2799
|
a && this.host.emitEvent("notification", {
|
|
2798
2800
|
type: r ? "message.updated" : "message.appended",
|
|
@@ -2814,11 +2816,11 @@ var mr = class {
|
|
|
2814
2816
|
if (e.item.type === "agentMessage" || e.item.type === "exitedReviewMode") {
|
|
2815
2817
|
let t = e.item.type === "agentMessage" ? e.item.text : e.item.review, r = e.item.type === "agentMessage" ? e.item.phase ?? void 0 : void 0;
|
|
2816
2818
|
if (!t && e.item.type !== "agentMessage") return;
|
|
2817
|
-
let i =
|
|
2819
|
+
let i = pr(e.threadId, e.turnId);
|
|
2818
2820
|
if (e.item.type === "agentMessage" && this.reviewOutputByTurn.get(i) === t) return;
|
|
2819
2821
|
e.item.type === "exitedReviewMode" && this.reviewOutputByTurn.set(i, t);
|
|
2820
|
-
let a = new Set(n.messages.map((e) => e.id)), o = this.host.assistantMessageForTurn(e.threadId, e.turnId), s = o ? JSON.stringify(o.parts) : null, c = new Set(o?.parts.flatMap((e) => e.type === "question" ? [e.request.id] : []) ?? []), l = n.messages.flatMap((e) => e.parts).find((t) => t.type === "text" && t.itemId === e.item.id)?.text ?? "", u = e.item.type === "agentMessage" ?
|
|
2821
|
-
if (u && (f =
|
|
2822
|
+
let a = new Set(n.messages.map((e) => e.id)), o = this.host.assistantMessageForTurn(e.threadId, e.turnId), s = o ? JSON.stringify(o.parts) : null, c = new Set(o?.parts.flatMap((e) => e.type === "question" ? [e.request.id] : []) ?? []), l = n.messages.flatMap((e) => e.parts).find((t) => t.type === "text" && t.itemId === e.item.id)?.text ?? "", u = e.item.type === "agentMessage" ? Vn(e.threadId, e.turnId, e.item) : null, d = u ? "" : t, f = u ? Cn(n.messages, e.threadId, e.turnId, e.item.id) : Sn(n.messages, e.threadId, e.turnId, e.item.id, t, r);
|
|
2823
|
+
if (u && (f = En(f, e.threadId, e.turnId, u)), this.host.patchRuntime(e.threadId, { messages: f }), !d && !u) return;
|
|
2822
2824
|
let p = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2823
2825
|
if (p && !a.has(p.id)) this.host.emitEvent("notification", {
|
|
2824
2826
|
type: "message.appended",
|
|
@@ -2862,7 +2864,7 @@ var mr = class {
|
|
|
2862
2864
|
if (e.item.type === "plan") {
|
|
2863
2865
|
if (!t) return;
|
|
2864
2866
|
let r = e.item.text.trim() || n.planMarkdownByTurn.get(e.turnId) || "";
|
|
2865
|
-
n.planMarkdownByTurn.set(e.turnId, r), this.host.patchRuntime(e.threadId, { messages:
|
|
2867
|
+
n.planMarkdownByTurn.set(e.turnId, r), this.host.patchRuntime(e.threadId, { messages: L(n.messages, e.threadId, e.turnId, Pn(e.turnId, r, "completed")) }), this.host.emitEvent("notification", {
|
|
2866
2868
|
type: "plan.completed",
|
|
2867
2869
|
conversationId: e.threadId,
|
|
2868
2870
|
turnId: e.turnId,
|
|
@@ -2874,7 +2876,7 @@ var mr = class {
|
|
|
2874
2876
|
return;
|
|
2875
2877
|
}
|
|
2876
2878
|
if (e.item.type === "contextCompaction") {
|
|
2877
|
-
if (this.host.patchRuntime(e.threadId, { messages:
|
|
2879
|
+
if (this.host.patchRuntime(e.threadId, { messages: kn(n.messages, e.threadId, e.turnId, t ? "complete" : "streaming") }), t) {
|
|
2878
2880
|
let t = this.host.requireRuntime(e.threadId).messages.find((t) => t.kind === "compaction" && t.metadata?.turnId === e.turnId);
|
|
2879
2881
|
t && this.host.emitEvent("notification", {
|
|
2880
2882
|
type: "context.compactionCompleted",
|
|
@@ -2900,7 +2902,7 @@ var mr = class {
|
|
|
2900
2902
|
turnId: e.turnId,
|
|
2901
2903
|
payload: {
|
|
2902
2904
|
lifecycle: t ? "completed" : "started",
|
|
2903
|
-
toolCall:
|
|
2905
|
+
toolCall: yr(e.item)
|
|
2904
2906
|
}
|
|
2905
2907
|
});
|
|
2906
2908
|
return;
|
|
@@ -2922,13 +2924,13 @@ var mr = class {
|
|
|
2922
2924
|
});
|
|
2923
2925
|
return;
|
|
2924
2926
|
}
|
|
2925
|
-
let a = this.shouldForwardCommandOutput(e.threadId, t, e.item), o =
|
|
2927
|
+
let a = this.shouldForwardCommandOutput(e.threadId, t, e.item), o = A(e.item, {
|
|
2926
2928
|
includeCommandOutput: a,
|
|
2927
2929
|
cwd: n.cwd
|
|
2928
|
-
}), s =
|
|
2930
|
+
}), s = Hn(e.item);
|
|
2929
2931
|
if (!o && !s) return;
|
|
2930
|
-
let c = s ? !n.messages.some((e) => e.parts.some((e) => e.type === "media" &&
|
|
2931
|
-
s && (l =
|
|
2932
|
+
let c = s ? !n.messages.some((e) => e.parts.some((e) => e.type === "media" && Dn(e, s))) : !1, l = o ? L(n.messages, e.threadId, e.turnId, o) : [...n.messages];
|
|
2933
|
+
s && (l = Tn(l, e.threadId, e.turnId, s)), this.host.patchRuntime(e.threadId, { messages: l });
|
|
2932
2934
|
let u = o ? this.host.messageContainingTool(e.threadId, e.turnId, o.id) : this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2933
2935
|
u && o && this.host.emitEvent("notification", {
|
|
2934
2936
|
type: t ? "tool.completed" : "tool.started",
|
|
@@ -2948,25 +2950,25 @@ var mr = class {
|
|
|
2948
2950
|
shouldForwardCommandOutput(e, t, n) {
|
|
2949
2951
|
let r = "id" in n && typeof n.id == "string" ? n.id : null;
|
|
2950
2952
|
if (!r) return !1;
|
|
2951
|
-
let i =
|
|
2953
|
+
let i = pr(e, r);
|
|
2952
2954
|
if (!t) {
|
|
2953
|
-
let e =
|
|
2955
|
+
let e = Vt(n);
|
|
2954
2956
|
return e ? this.commandOutputForwardItemIds.add(i) : this.commandOutputForwardItemIds.delete(i), e;
|
|
2955
2957
|
}
|
|
2956
|
-
let a = this.commandOutputForwardItemIds.has(i) ||
|
|
2958
|
+
let a = this.commandOutputForwardItemIds.has(i) || Vt(n);
|
|
2957
2959
|
return this.commandOutputForwardItemIds.delete(i), a;
|
|
2958
2960
|
}
|
|
2959
2961
|
applyToolUpdate(e, t, n) {
|
|
2960
2962
|
let r = this.host.requireRuntime(e);
|
|
2961
2963
|
this.host.markRuntimeTurnActive(r, t);
|
|
2962
|
-
let i = r.cwd &&
|
|
2964
|
+
let i = r.cwd && xr(n) ? {
|
|
2963
2965
|
...n,
|
|
2964
2966
|
metadata: {
|
|
2965
2967
|
...n.metadata,
|
|
2966
2968
|
cwd: r.cwd
|
|
2967
2969
|
}
|
|
2968
2970
|
} : n;
|
|
2969
|
-
this.host.patchRuntime(e, { messages:
|
|
2971
|
+
this.host.patchRuntime(e, { messages: On(r.messages, e, t, i) });
|
|
2970
2972
|
let a = this.host.messageContainingTool(e, t, n.itemId);
|
|
2971
2973
|
a && this.host.emitEvent("notification", {
|
|
2972
2974
|
type: "tool.updated",
|
|
@@ -2981,7 +2983,7 @@ var mr = class {
|
|
|
2981
2983
|
a && o && this.emitFileActivities(e, t, a.id, o.id, o, r.cwd);
|
|
2982
2984
|
}
|
|
2983
2985
|
emitFileActivities(e, t, n, r, i, a) {
|
|
2984
|
-
for (let o of
|
|
2986
|
+
for (let o of Bt(i, a)) {
|
|
2985
2987
|
let i = `${e}\u0000${r}\u0000${o.action}\u0000${o.path}\u0000${o.status}`;
|
|
2986
2988
|
this.fileActivityKeys.has(i) || (this.fileActivityKeys.add(i), this.host.emitEvent("notification", {
|
|
2987
2989
|
type: "file.activity",
|
|
@@ -3002,7 +3004,7 @@ var mr = class {
|
|
|
3002
3004
|
t.turnIds.includes(e.turn.id) || t.turnIds.push(e.turn.id);
|
|
3003
3005
|
let n = t.activeTurnId !== e.turn.id && t.turnStartPending;
|
|
3004
3006
|
t.activeTurnId === e.turn.id && (t.activeTurnId = null);
|
|
3005
|
-
let r = n || t.activeTurnId !== null, i = e.turn.status === "failed" ? "error" : "complete", a =
|
|
3007
|
+
let r = n || t.activeTurnId !== null, i = e.turn.status === "failed" ? "error" : "complete", a = An(t.messages, e.turn.id, e.turn.status).map((t) => t.metadata?.turnId === e.turn.id ? {
|
|
3006
3008
|
...t,
|
|
3007
3009
|
status: i
|
|
3008
3010
|
} : t).filter((t) => !(t.role === "assistant" && t.metadata?.turnId === e.turn.id && t.kind === void 0 && t.parts.length === 0));
|
|
@@ -3028,26 +3030,26 @@ var mr = class {
|
|
|
3028
3030
|
turnId: e.turn.id,
|
|
3029
3031
|
payload: {
|
|
3030
3032
|
status: e.turn.status,
|
|
3031
|
-
error:
|
|
3033
|
+
error: hr(e.turn.error),
|
|
3032
3034
|
willRetry: !1,
|
|
3033
|
-
startedAt:
|
|
3034
|
-
completedAt:
|
|
3035
|
+
startedAt: mr(e.turn.startedAt),
|
|
3036
|
+
completedAt: mr(e.turn.completedAt),
|
|
3035
3037
|
durationMs: e.turn.durationMs ?? null
|
|
3036
3038
|
}
|
|
3037
3039
|
}), this.host.emitConversationActivity(e.threadId, "notification"), t.planMarkdownByTurn.delete(e.turn.id), this.host.sendNextQueuedPrompt(e.threadId);
|
|
3038
3040
|
}
|
|
3039
3041
|
};
|
|
3040
|
-
function
|
|
3042
|
+
function xr(e) {
|
|
3041
3043
|
if (e.fallbackToolPart?.kind === "fileChange") return !0;
|
|
3042
3044
|
let t = e.input, n = e.metadata;
|
|
3043
|
-
return
|
|
3045
|
+
return Sr(t) && Array.isArray(t.changes) || Sr(n) && Array.isArray(n.changes);
|
|
3044
3046
|
}
|
|
3045
|
-
function
|
|
3047
|
+
function Sr(e) {
|
|
3046
3048
|
return typeof e == "object" && !!e;
|
|
3047
3049
|
}
|
|
3048
3050
|
//#endregion
|
|
3049
3051
|
//#region src/node/codex-surface-client-requests-controller.ts
|
|
3050
|
-
var
|
|
3052
|
+
var Cr = class {
|
|
3051
3053
|
host;
|
|
3052
3054
|
pending = /* @__PURE__ */ new Map();
|
|
3053
3055
|
constructor(e) {
|
|
@@ -3096,21 +3098,21 @@ var _r = class {
|
|
|
3096
3098
|
"deny"
|
|
3097
3099
|
].includes(r)) throw Error(`Invalid tool confirmation decision '${String(r)}'`);
|
|
3098
3100
|
this.pending.delete(t.id);
|
|
3099
|
-
let i = this.host.requireRuntime(n.threadId), a =
|
|
3101
|
+
let i = this.host.requireRuntime(n.threadId), a = Mn(i.answeredClientRequestIds, t.id);
|
|
3100
3102
|
if (n.kind === "ask_user") {
|
|
3101
3103
|
let e = t.payload?.answers ?? {};
|
|
3102
3104
|
n.responder.resolve({ answers: e }), this.host.patchRuntime(n.threadId, {
|
|
3103
3105
|
answeredClientRequestIds: a,
|
|
3104
|
-
messages:
|
|
3106
|
+
messages: On(i.messages, n.threadId, n.turnId, {
|
|
3105
3107
|
itemId: n.itemId,
|
|
3106
3108
|
output: { answers: e }
|
|
3107
3109
|
})
|
|
3108
3110
|
});
|
|
3109
3111
|
} else {
|
|
3110
3112
|
let e = r;
|
|
3111
|
-
n.responder.resolve(
|
|
3113
|
+
n.responder.resolve(Ze(e)), this.host.patchRuntime(n.threadId, {
|
|
3112
3114
|
answeredClientRequestIds: a,
|
|
3113
|
-
messages:
|
|
3115
|
+
messages: On(i.messages, n.threadId, n.displayTurnId, {
|
|
3114
3116
|
itemId: n.itemId,
|
|
3115
3117
|
output: { decision: e }
|
|
3116
3118
|
})
|
|
@@ -3149,7 +3151,7 @@ var _r = class {
|
|
|
3149
3151
|
${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ? s[0].answer : s.map((e) => `${e.question}: ${e.answer}`).join("\n");
|
|
3150
3152
|
await this.host.answerAsyncQuestion(a.runtime.threadId, e, t);
|
|
3151
3153
|
}
|
|
3152
|
-
this.host.patchRuntime(a.runtime.threadId, { answeredClientRequestIds:
|
|
3154
|
+
this.host.patchRuntime(a.runtime.threadId, { answeredClientRequestIds: Mn(a.runtime.answeredClientRequestIds, t.id) }), this.host.emitEvent("action", {
|
|
3153
3155
|
type: "clientRequest.resolved",
|
|
3154
3156
|
conversationId: a.runtime.threadId,
|
|
3155
3157
|
...a.request.turnId ? { turnId: a.request.turnId } : {},
|
|
@@ -3164,7 +3166,7 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3164
3166
|
let n = this.pending.get(e);
|
|
3165
3167
|
if (this.pending.delete(e), n) {
|
|
3166
3168
|
let t = this.host.requireRuntime(n.threadId);
|
|
3167
|
-
this.host.patchRuntime(n.threadId, { answeredClientRequestIds:
|
|
3169
|
+
this.host.patchRuntime(n.threadId, { answeredClientRequestIds: Mn(t.answeredClientRequestIds, e) });
|
|
3168
3170
|
}
|
|
3169
3171
|
this.maybeClearWaitingBusy(t), n && this.host.emitEvent("notification", {
|
|
3170
3172
|
type: "clientRequest.resolved",
|
|
@@ -3212,7 +3214,7 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3212
3214
|
responder: t
|
|
3213
3215
|
}), this.host.patchRuntime(n, {
|
|
3214
3216
|
busy: !0,
|
|
3215
|
-
messages:
|
|
3217
|
+
messages: L(o.messages, n, r, {
|
|
3216
3218
|
type: "tool",
|
|
3217
3219
|
id: i,
|
|
3218
3220
|
kind: "generic",
|
|
@@ -3254,23 +3256,23 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3254
3256
|
let n = e.params;
|
|
3255
3257
|
if (n.mode !== "form") return !1;
|
|
3256
3258
|
let r = n._meta;
|
|
3257
|
-
if (!
|
|
3258
|
-
let i = String(e.id), a =
|
|
3259
|
+
if (!ct(r) || r.codex_approval_kind !== "mcp_tool_call") return !1;
|
|
3260
|
+
let i = String(e.id), a = E(r.tool_name) ?? E(r.tool_title) ?? "tool", o = this.host.requireRuntime(n.threadId);
|
|
3259
3261
|
n.turnId && this.host.markRuntimeTurnActive(o, n.turnId);
|
|
3260
|
-
let s = n.turnId ?? o.activeTurnId ?? `client-request-${i}`, c =
|
|
3262
|
+
let s = n.turnId ?? o.activeTurnId ?? `client-request-${i}`, c = at(o.messages, s, n.serverName, a), l = c?.id ?? `approval-${i}`, u = n.message.trim() || `Allow ${n.serverName} to run ${a}?`, d = {
|
|
3261
3263
|
id: i,
|
|
3262
3264
|
kind: "confirm_tool",
|
|
3263
3265
|
conversationId: n.threadId,
|
|
3264
3266
|
turnId: n.turnId,
|
|
3265
3267
|
itemId: l,
|
|
3266
3268
|
payload: { confirmation: {
|
|
3267
|
-
argumentsPreview:
|
|
3269
|
+
argumentsPreview: ot(r),
|
|
3268
3270
|
integrationId: n.serverName,
|
|
3269
|
-
integrationName:
|
|
3271
|
+
integrationName: E(r.connector_name) ?? n.serverName,
|
|
3270
3272
|
summary: u,
|
|
3271
3273
|
toolName: a,
|
|
3272
|
-
...
|
|
3273
|
-
...
|
|
3274
|
+
...st(r.persist, "session") ? { allowConversation: !0 } : {},
|
|
3275
|
+
...st(r.persist, "always") ? { allowAlways: !0 } : {}
|
|
3274
3276
|
} }
|
|
3275
3277
|
};
|
|
3276
3278
|
this.pending.set(i, {
|
|
@@ -3295,9 +3297,9 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3295
3297
|
params: {
|
|
3296
3298
|
requestId: i,
|
|
3297
3299
|
confirmationSummary: u,
|
|
3298
|
-
argumentsPreview:
|
|
3299
|
-
allowConversation:
|
|
3300
|
-
allowAlways:
|
|
3300
|
+
argumentsPreview: ot(r),
|
|
3301
|
+
allowConversation: st(r.persist, "session"),
|
|
3302
|
+
allowAlways: st(r.persist, "always")
|
|
3301
3303
|
}
|
|
3302
3304
|
}),
|
|
3303
3305
|
input: r.tool_params,
|
|
@@ -3311,7 +3313,7 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3311
3313
|
};
|
|
3312
3314
|
this.host.patchRuntime(n.threadId, {
|
|
3313
3315
|
busy: !0,
|
|
3314
|
-
messages:
|
|
3316
|
+
messages: L(o.messages, n.threadId, s, f)
|
|
3315
3317
|
});
|
|
3316
3318
|
let p = this.host.messageContainingTool(n.threadId, s, l);
|
|
3317
3319
|
return p && this.host.emitEvent("notification", {
|
|
@@ -3329,8 +3331,8 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3329
3331
|
payload: { request: structuredClone(d) }
|
|
3330
3332
|
}), this.host.emitConversationActivity(n.threadId, "notification"), !0;
|
|
3331
3333
|
}
|
|
3332
|
-
},
|
|
3333
|
-
function
|
|
3334
|
+
}, wr = 256 * 1024;
|
|
3335
|
+
function Tr(e) {
|
|
3334
3336
|
return {
|
|
3335
3337
|
id: e.id,
|
|
3336
3338
|
model: e.model,
|
|
@@ -3355,11 +3357,11 @@ function yr(e) {
|
|
|
3355
3357
|
}
|
|
3356
3358
|
};
|
|
3357
3359
|
}
|
|
3358
|
-
async function
|
|
3359
|
-
return Promise.all(e.filter((e) => e.enabled).map((e) =>
|
|
3360
|
+
async function Er(e, t) {
|
|
3361
|
+
return Promise.all(e.filter((e) => e.enabled).map((e) => Dr(e, t)));
|
|
3360
3362
|
}
|
|
3361
|
-
async function
|
|
3362
|
-
let n = K(e.interface?.brandColor), r =
|
|
3363
|
+
async function Dr(e, t) {
|
|
3364
|
+
let n = K(e.interface?.brandColor), r = Nr(e.interface?.defaultPrompt), [i, a] = await Promise.all([e.interface?.iconSmall ? t(e.interface.iconSmall) : void 0, e.interface?.iconLarge ? t(e.interface.iconLarge) : void 0]);
|
|
3363
3365
|
return {
|
|
3364
3366
|
name: e.name,
|
|
3365
3367
|
description: e.description,
|
|
@@ -3374,8 +3376,8 @@ async function xr(e, t) {
|
|
|
3374
3376
|
enabled: e.enabled
|
|
3375
3377
|
};
|
|
3376
3378
|
}
|
|
3377
|
-
async function
|
|
3378
|
-
let n = e.interface, r =
|
|
3379
|
+
async function Or(e, t) {
|
|
3380
|
+
let n = e.interface, r = Ar(n?.composerIconUrl), i = Ar(n?.logoUrl), a = Ar(n?.logoUrlDark), o = K(n?.displayName) ?? e.name, s = K(n?.shortDescription), c = K(n?.longDescription), l = K(n?.brandColor), u = r ?? i ?? await kr([n?.composerIcon, n?.logo], t), d = r ?? a ?? i ?? await kr([
|
|
3379
3381
|
n?.composerIcon,
|
|
3380
3382
|
n?.logoDark,
|
|
3381
3383
|
n?.logo
|
|
@@ -3392,21 +3394,21 @@ async function Sr(e, t) {
|
|
|
3392
3394
|
enabled: e.enabled
|
|
3393
3395
|
};
|
|
3394
3396
|
}
|
|
3395
|
-
async function
|
|
3397
|
+
async function kr(e, t) {
|
|
3396
3398
|
for (let n of e) {
|
|
3397
3399
|
if (!n) continue;
|
|
3398
3400
|
let e = await t(n);
|
|
3399
3401
|
if (e) return e;
|
|
3400
3402
|
}
|
|
3401
3403
|
}
|
|
3402
|
-
function
|
|
3404
|
+
function Ar(e) {
|
|
3403
3405
|
let t = K(e);
|
|
3404
3406
|
try {
|
|
3405
3407
|
return new URL(t).protocol === "https:" ? t : void 0;
|
|
3406
3408
|
} catch {}
|
|
3407
3409
|
}
|
|
3408
|
-
function
|
|
3409
|
-
switch (
|
|
3410
|
+
function jr(e) {
|
|
3411
|
+
switch (_(e).toLowerCase()) {
|
|
3410
3412
|
case ".avif": return "image/avif";
|
|
3411
3413
|
case ".bmp": return "image/bmp";
|
|
3412
3414
|
case ".gif": return "image/gif";
|
|
@@ -3418,18 +3420,18 @@ function Tr(e) {
|
|
|
3418
3420
|
case ".webp": return "image/webp";
|
|
3419
3421
|
}
|
|
3420
3422
|
}
|
|
3421
|
-
function
|
|
3423
|
+
function Mr(e, t) {
|
|
3422
3424
|
let n = t.trim();
|
|
3423
3425
|
if (!/^[a-z\d+/]+={0,2}$/i.test(n)) return;
|
|
3424
3426
|
let r = n.replace(/=+$/, "");
|
|
3425
3427
|
if (r.length % 4 == 1) return;
|
|
3426
3428
|
let i = n.length - r.length, a = (4 - r.length % 4) % 4;
|
|
3427
|
-
if (!(i !== 0 && i !== a) && !(Math.floor(r.length * 3 / 4) >
|
|
3429
|
+
if (!(i !== 0 && i !== a) && !(Math.floor(r.length * 3 / 4) > wr)) return `data:${e};base64,${`${r}${"=".repeat((4 - r.length % 4) % 4)}`}`;
|
|
3428
3430
|
}
|
|
3429
3431
|
function K(e) {
|
|
3430
3432
|
return (typeof e == "string" ? e.trim() : void 0) || void 0;
|
|
3431
3433
|
}
|
|
3432
|
-
function
|
|
3434
|
+
function Nr(e) {
|
|
3433
3435
|
return typeof e == "string" ? e : void 0;
|
|
3434
3436
|
}
|
|
3435
3437
|
//#endregion
|
|
@@ -3437,12 +3439,12 @@ function Dr(e) {
|
|
|
3437
3439
|
function q(e, t) {
|
|
3438
3440
|
return e.find((e) => e.id === t || e.model === t) ?? e.find((e) => e.isDefault) ?? e[0] ?? null;
|
|
3439
3441
|
}
|
|
3440
|
-
function
|
|
3442
|
+
function Pr(e, t) {
|
|
3441
3443
|
let n = e.find((e) => e.id === t || e.model === t);
|
|
3442
3444
|
if (!n) throw Error(`Unknown model '${t}'`);
|
|
3443
3445
|
return n;
|
|
3444
3446
|
}
|
|
3445
|
-
function
|
|
3447
|
+
function Fr(e, t) {
|
|
3446
3448
|
if (!t) return;
|
|
3447
3449
|
if (!e) throw Error(`Cannot select reasoning effort '${t}' without a model`);
|
|
3448
3450
|
let n = e.supportedReasoningEfforts?.map((e) => e.reasoningEffort) ?? [];
|
|
@@ -3451,7 +3453,7 @@ function kr(e, t) {
|
|
|
3451
3453
|
function J(e) {
|
|
3452
3454
|
return e.defaultReasoningEffort ?? e.supportedReasoningEfforts?.[0]?.reasoningEffort ?? null;
|
|
3453
3455
|
}
|
|
3454
|
-
function
|
|
3456
|
+
function Ir(e) {
|
|
3455
3457
|
return e.defaultServiceTier ?? null;
|
|
3456
3458
|
}
|
|
3457
3459
|
function Y(e, t) {
|
|
@@ -3461,14 +3463,14 @@ function Y(e, t) {
|
|
|
3461
3463
|
let n = e.serviceTiers?.map((e) => e.id) ?? [];
|
|
3462
3464
|
if (n.length > 0 && !n.includes(t)) throw Error(`Service tier '${t}' is not available for '${e.displayName}'`);
|
|
3463
3465
|
}
|
|
3464
|
-
function
|
|
3466
|
+
function Lr(e, t) {
|
|
3465
3467
|
let n = new Set(e.filter((e) => e.allowed).map((e) => e.id)), r = [];
|
|
3466
3468
|
return n.has(":workspace") && X(t?.allowedApprovalPolicies, "on-request") && X(t?.allowedApprovalsReviewers, "user") && r.push("ask-for-approval"), n.has(":workspace") && X(t?.allowedApprovalPolicies, "on-request") && X(t?.allowedApprovalsReviewers, "auto_review") && r.push("approve-for-me"), (n.has(":danger-full-access") || n.has(":danger-no-sandbox")) && X(t?.allowedApprovalPolicies, "never") && X(t?.allowedApprovalsReviewers, "user") && r.push("full-access"), r;
|
|
3467
3469
|
}
|
|
3468
3470
|
function X(e, t) {
|
|
3469
3471
|
return !Array.isArray(e) || e.length === 0 || e.includes(t);
|
|
3470
3472
|
}
|
|
3471
|
-
function
|
|
3473
|
+
function Rr(e) {
|
|
3472
3474
|
return e === "full-access" ? {
|
|
3473
3475
|
approvalPolicy: "never",
|
|
3474
3476
|
approvalsReviewer: "user",
|
|
@@ -3479,39 +3481,39 @@ function Mr(e) {
|
|
|
3479
3481
|
permissions: ":workspace"
|
|
3480
3482
|
};
|
|
3481
3483
|
}
|
|
3482
|
-
function
|
|
3483
|
-
return
|
|
3484
|
+
function zr(e) {
|
|
3485
|
+
return Rr(e);
|
|
3484
3486
|
}
|
|
3485
|
-
function
|
|
3487
|
+
function Br(e, t, n, r) {
|
|
3486
3488
|
let i = r?.id;
|
|
3487
3489
|
return e === "never" && (n.type === "dangerFullAccess" || i === ":danger-full-access" || i === ":danger-no-sandbox") ? "full-access" : e === "on-request" && (t === "auto_review" || t === "guardian_subagent") ? "approve-for-me" : e === "on-request" ? "ask-for-approval" : null;
|
|
3488
3490
|
}
|
|
3489
|
-
function
|
|
3491
|
+
function Vr(e, t, n) {
|
|
3490
3492
|
let r = q(t, e.model);
|
|
3491
3493
|
return {
|
|
3492
|
-
approvalPreset:
|
|
3494
|
+
approvalPreset: Br(e.approvalPolicy, e.approvalsReviewer, e.sandbox, e.activePermissionProfile) ?? n.approvalPreset,
|
|
3493
3495
|
planMode: n.planMode,
|
|
3494
3496
|
selectedModelId: r?.id ?? n.selectedModelId,
|
|
3495
3497
|
selectedReasoningEffort: e.reasoningEffort ?? (r ? J(r) : null),
|
|
3496
|
-
selectedServiceTier: e.serviceTier === void 0 ? r ?
|
|
3498
|
+
selectedServiceTier: e.serviceTier === void 0 ? r ? Ir(r) : null : e.serviceTier
|
|
3497
3499
|
};
|
|
3498
3500
|
}
|
|
3499
|
-
function
|
|
3501
|
+
function Hr(e, t, n) {
|
|
3500
3502
|
let r = q(t, e.model);
|
|
3501
3503
|
return {
|
|
3502
|
-
approvalPreset:
|
|
3504
|
+
approvalPreset: Br(e.approvalPolicy, e.approvalsReviewer, e.sandboxPolicy, e.activePermissionProfile) ?? n.approvalPreset,
|
|
3503
3505
|
planMode: e.collaborationMode.mode === "plan",
|
|
3504
3506
|
selectedModelId: r?.id ?? n.selectedModelId,
|
|
3505
3507
|
selectedReasoningEffort: e.effort ?? (r ? J(r) : null),
|
|
3506
|
-
selectedServiceTier: e.serviceTier === void 0 ? r ?
|
|
3508
|
+
selectedServiceTier: e.serviceTier === void 0 ? r ? Ir(r) : null : e.serviceTier
|
|
3507
3509
|
};
|
|
3508
3510
|
}
|
|
3509
|
-
function
|
|
3511
|
+
function Ur(e, t) {
|
|
3510
3512
|
let n = q(e.models, e.selectedModelId);
|
|
3511
3513
|
if (t.modelId && (n = e.models.find((e) => e.id === t.modelId) ?? null, !n)) throw Error(`Unknown model '${t.modelId}'`);
|
|
3512
3514
|
let r = t.reasoningEffort ?? e.selectedReasoningEffort, i = t.serviceTier === void 0 ? e.selectedServiceTier ?? null : t.serviceTier, a = n?.supportedReasoningEfforts?.map((e) => e.reasoningEffort) ?? [];
|
|
3513
3515
|
if (t.reasoningEffort && a.length > 0 && !a.includes(t.reasoningEffort)) throw Error(`Reasoning effort '${t.reasoningEffort}' is not available for '${n.displayName}'`);
|
|
3514
|
-
return t.modelId && a.length > 0 && (!r || !a.includes(r)) && (r = n ? J(n) : null), t.serviceTier !== void 0 && Y(n, i), t.serviceTier === void 0 && t.modelId && i && !n.serviceTiers?.some((e) => e.id === i) && (i = n ?
|
|
3516
|
+
return t.modelId && a.length > 0 && (!r || !a.includes(r)) && (r = n ? J(n) : null), t.serviceTier !== void 0 && Y(n, i), t.serviceTier === void 0 && t.modelId && i && !n.serviceTiers?.some((e) => e.id === i) && (i = n ? Ir(n) : null), {
|
|
3515
3517
|
approvalPreset: t.approvalPreset ?? e.approvalPreset,
|
|
3516
3518
|
planMode: t.planMode ?? e.planMode,
|
|
3517
3519
|
selectedModelId: n?.id ?? null,
|
|
@@ -3519,7 +3521,7 @@ function Lr(e, t) {
|
|
|
3519
3521
|
selectedServiceTier: i
|
|
3520
3522
|
};
|
|
3521
3523
|
}
|
|
3522
|
-
function
|
|
3524
|
+
function Wr(e, t, n) {
|
|
3523
3525
|
return {
|
|
3524
3526
|
mode: e ? "plan" : "default",
|
|
3525
3527
|
settings: {
|
|
@@ -3529,12 +3531,12 @@ function Rr(e, t, n) {
|
|
|
3529
3531
|
}
|
|
3530
3532
|
};
|
|
3531
3533
|
}
|
|
3532
|
-
function
|
|
3534
|
+
function Gr(e, t) {
|
|
3533
3535
|
let n = q(e.models, e.selectedModelId), r = t.model ?? n?.model, i = t.reasoningEffort ?? e.selectedReasoningEffort, a = t.planMode ?? e.planMode;
|
|
3534
3536
|
return {
|
|
3535
3537
|
...r ? { model: r } : {},
|
|
3536
3538
|
...i ? { effort: i } : {},
|
|
3537
|
-
...r ? { collaborationMode:
|
|
3539
|
+
...r ? { collaborationMode: Wr(a, r, i) } : {},
|
|
3538
3540
|
...t.serviceTier === void 0 ? e.selectedServiceTier ? { serviceTier: e.selectedServiceTier } : {} : { serviceTier: t.serviceTier }
|
|
3539
3541
|
};
|
|
3540
3542
|
}
|
|
@@ -3557,29 +3559,29 @@ function Z(e) {
|
|
|
3557
3559
|
updatedAt: (/* @__PURE__ */ new Date((e.recencyAt ?? e.updatedAt) * 1e3)).toISOString()
|
|
3558
3560
|
};
|
|
3559
3561
|
}
|
|
3560
|
-
function
|
|
3562
|
+
function Kr(e, t) {
|
|
3561
3563
|
let n = new Map(e.map((e) => [e.id, e])), r = t.map((e) => {
|
|
3562
3564
|
let t = n.get(e.id);
|
|
3563
|
-
return t &&
|
|
3565
|
+
return t && ie(t, e) ? t : e;
|
|
3564
3566
|
});
|
|
3565
3567
|
return r.length === e.length && r.every((t, n) => t === e[n]) ? e : r;
|
|
3566
3568
|
}
|
|
3567
3569
|
function Q(e, t) {
|
|
3568
3570
|
return [t, ...e.filter((e) => e.id !== t.id)].sort((e, t) => t.updatedAt.localeCompare(e.updatedAt));
|
|
3569
3571
|
}
|
|
3570
|
-
function
|
|
3571
|
-
let n = t.model ?
|
|
3572
|
-
return
|
|
3572
|
+
function qr(e, t) {
|
|
3573
|
+
let n = t.model ? Pr(e.models, t.model) : q(e.models, e.selectedModelId);
|
|
3574
|
+
return Fr(n, t.reasoningEffort), Y(n, t.serviceTier), {
|
|
3573
3575
|
...t,
|
|
3574
|
-
...t.attachments ? { attachments:
|
|
3576
|
+
...t.attachments ? { attachments: Jr(t.attachments) } : {},
|
|
3575
3577
|
...t.model && n ? { model: n.model } : {}
|
|
3576
3578
|
};
|
|
3577
3579
|
}
|
|
3578
|
-
function
|
|
3580
|
+
function Jr(e) {
|
|
3579
3581
|
return e.map((e) => {
|
|
3580
3582
|
let t = e.path.trim();
|
|
3581
3583
|
if (!t) throw Error("Attachment paths cannot be empty");
|
|
3582
|
-
if (!
|
|
3584
|
+
if (!v(t)) throw Error(`Attachment path must be absolute: '${t}'`);
|
|
3583
3585
|
if (e.type === "image") return {
|
|
3584
3586
|
...e,
|
|
3585
3587
|
path: t
|
|
@@ -3592,22 +3594,22 @@ function Hr(e) {
|
|
|
3592
3594
|
};
|
|
3593
3595
|
});
|
|
3594
3596
|
}
|
|
3595
|
-
function
|
|
3597
|
+
function Yr(e) {
|
|
3596
3598
|
return e.type === "image" ? {
|
|
3597
3599
|
type: "localImage",
|
|
3598
3600
|
path: e.path,
|
|
3599
3601
|
...e.detail === void 0 ? {} : { detail: e.detail }
|
|
3600
|
-
} :
|
|
3602
|
+
} : Nt(e.name ?? g(e.path), e.path);
|
|
3601
3603
|
}
|
|
3602
|
-
function
|
|
3603
|
-
let t = e.name?.trim() ||
|
|
3604
|
+
function Xr(e) {
|
|
3605
|
+
let t = e.name?.trim() || g(e.path);
|
|
3604
3606
|
return e.type === "image" ? {
|
|
3605
3607
|
type: "attachment",
|
|
3606
3608
|
attachment: {
|
|
3607
3609
|
kind: "image",
|
|
3608
3610
|
name: t,
|
|
3609
3611
|
path: e.path,
|
|
3610
|
-
url: e.previewUrl ??
|
|
3612
|
+
url: e.previewUrl ?? re(e.path).href,
|
|
3611
3613
|
...e.mimeType ? { mimeType: e.mimeType } : {}
|
|
3612
3614
|
}
|
|
3613
3615
|
} : {
|
|
@@ -3620,14 +3622,14 @@ function Wr(e) {
|
|
|
3620
3622
|
}
|
|
3621
3623
|
};
|
|
3622
3624
|
}
|
|
3623
|
-
function
|
|
3625
|
+
function Zr(e) {
|
|
3624
3626
|
let t = e.metadata?.turnId;
|
|
3625
3627
|
return e.turnId ?? (typeof t == "string" ? t : null);
|
|
3626
3628
|
}
|
|
3627
|
-
function
|
|
3629
|
+
function Qr(e) {
|
|
3628
3630
|
return e.parts.filter((e) => e.type === "text").map((e) => e.text).join("\n").trim();
|
|
3629
3631
|
}
|
|
3630
|
-
function
|
|
3632
|
+
function $r(e) {
|
|
3631
3633
|
return e.parts.flatMap((e) => {
|
|
3632
3634
|
if (e.type !== "attachment") return [];
|
|
3633
3635
|
let t = e.attachment, n = t.path;
|
|
@@ -3645,7 +3647,7 @@ function qr(e) {
|
|
|
3645
3647
|
}] : [];
|
|
3646
3648
|
});
|
|
3647
3649
|
}
|
|
3648
|
-
function
|
|
3650
|
+
function ei(e) {
|
|
3649
3651
|
let t = e.modelContextWindow, n = e.last.totalTokens, r = typeof t == "number" && t > 0 ? Math.min(100, Math.max(0, n / t * 100)) : null;
|
|
3650
3652
|
return {
|
|
3651
3653
|
totalTokens: e.total.totalTokens,
|
|
@@ -3664,13 +3666,13 @@ function $(e) {
|
|
|
3664
3666
|
activeFlags: [...e.activeFlags]
|
|
3665
3667
|
} : { type: e.type };
|
|
3666
3668
|
}
|
|
3667
|
-
function
|
|
3669
|
+
function ti(e) {
|
|
3668
3670
|
return e.type === "active" ? "active" : e.type === "systemError" ? "error" : "idle";
|
|
3669
3671
|
}
|
|
3670
|
-
function
|
|
3671
|
-
let t = e.rateLimitsByLimitId ? Object.fromEntries(Object.entries(e.rateLimitsByLimitId).filter((e) => !!e[1]).map(([e, t]) => [e,
|
|
3672
|
+
function ni(e) {
|
|
3673
|
+
let t = e.rateLimitsByLimitId ? Object.fromEntries(Object.entries(e.rateLimitsByLimitId).filter((e) => !!e[1]).map(([e, t]) => [e, ri(t)])) : null;
|
|
3672
3674
|
return {
|
|
3673
|
-
rateLimits:
|
|
3675
|
+
rateLimits: ri(e.rateLimits),
|
|
3674
3676
|
rateLimitsByLimitId: t,
|
|
3675
3677
|
rateLimitResetCredits: e.rateLimitResetCredits ? {
|
|
3676
3678
|
availableCount: String(e.rateLimitResetCredits.availableCount),
|
|
@@ -3678,7 +3680,7 @@ function Xr(e) {
|
|
|
3678
3680
|
} : null
|
|
3679
3681
|
};
|
|
3680
3682
|
}
|
|
3681
|
-
function
|
|
3683
|
+
function ri(e) {
|
|
3682
3684
|
return {
|
|
3683
3685
|
limitId: e.limitId,
|
|
3684
3686
|
limitName: e.limitName,
|
|
@@ -3690,21 +3692,21 @@ function Zr(e) {
|
|
|
3690
3692
|
rateLimitReachedType: e.rateLimitReachedType
|
|
3691
3693
|
};
|
|
3692
3694
|
}
|
|
3693
|
-
function
|
|
3694
|
-
let n =
|
|
3695
|
+
function ii(e, t) {
|
|
3696
|
+
let n = ri(t);
|
|
3695
3697
|
if (!e) return {
|
|
3696
3698
|
rateLimits: n,
|
|
3697
3699
|
rateLimitsByLimitId: n.limitId ? { [n.limitId]: n } : null,
|
|
3698
3700
|
rateLimitResetCredits: null
|
|
3699
3701
|
};
|
|
3700
|
-
let r =
|
|
3701
|
-
return r.limitId && (i[r.limitId] =
|
|
3702
|
+
let r = ai(e.rateLimits, n), i = e.rateLimitsByLimitId ? { ...e.rateLimitsByLimitId } : {};
|
|
3703
|
+
return r.limitId && (i[r.limitId] = ai(i[r.limitId] ?? r, n)), {
|
|
3702
3704
|
...e,
|
|
3703
3705
|
rateLimits: r,
|
|
3704
3706
|
rateLimitsByLimitId: Object.keys(i).length > 0 ? i : null
|
|
3705
3707
|
};
|
|
3706
3708
|
}
|
|
3707
|
-
function
|
|
3709
|
+
function ai(e, t) {
|
|
3708
3710
|
return {
|
|
3709
3711
|
limitId: t.limitId ?? e.limitId,
|
|
3710
3712
|
limitName: t.limitName ?? e.limitName,
|
|
@@ -3730,7 +3732,7 @@ function $r(e, t) {
|
|
|
3730
3732
|
}
|
|
3731
3733
|
//#endregion
|
|
3732
3734
|
//#region src/node/codex-surface-catalog-controller.ts
|
|
3733
|
-
var
|
|
3735
|
+
var oi = class {
|
|
3734
3736
|
client;
|
|
3735
3737
|
cwd;
|
|
3736
3738
|
host;
|
|
@@ -3765,7 +3767,7 @@ var ei = class {
|
|
|
3765
3767
|
async loadSkills(e = !1, t = "action") {
|
|
3766
3768
|
e && this.iconDataUrls.clear(), this.host.patch({ skillCatalogStatus: "loading" }), this.emitSkills(this.cwd ?? null, [], "loading", t);
|
|
3767
3769
|
try {
|
|
3768
|
-
let n = await
|
|
3770
|
+
let n = await Er((await this.client.request("skills/list", {
|
|
3769
3771
|
...this.cwd ? { cwds: [this.cwd] } : {},
|
|
3770
3772
|
forceReload: e
|
|
3771
3773
|
})).data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e));
|
|
@@ -3782,7 +3784,7 @@ var ei = class {
|
|
|
3782
3784
|
}
|
|
3783
3785
|
async listSkills(e = {}) {
|
|
3784
3786
|
await this.host.ensureConnected(), e.forceReload && this.iconDataUrls.clear();
|
|
3785
|
-
let t = await
|
|
3787
|
+
let t = await Er((await this.client.request("skills/list", {
|
|
3786
3788
|
...e.cwd ? { cwds: [e.cwd] } : {},
|
|
3787
3789
|
forceReload: e.forceReload ?? !1
|
|
3788
3790
|
})).data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e));
|
|
@@ -3794,7 +3796,7 @@ var ei = class {
|
|
|
3794
3796
|
}
|
|
3795
3797
|
async loadPermissionProfiles() {
|
|
3796
3798
|
try {
|
|
3797
|
-
let e = await this.requestPermissionProfiles(this.cwd), t = (await this.client.request("configRequirements/read", void 0)).requirements, n =
|
|
3799
|
+
let e = await this.requestPermissionProfiles(this.cwd), t = (await this.client.request("configRequirements/read", void 0)).requirements, n = Lr(e, t), r = this.host.preferredApprovalPreset();
|
|
3798
3800
|
this.host.patch({
|
|
3799
3801
|
permissionProfiles: e,
|
|
3800
3802
|
approvalPresets: n,
|
|
@@ -3810,7 +3812,7 @@ var ei = class {
|
|
|
3810
3812
|
}
|
|
3811
3813
|
async loadRateLimits() {
|
|
3812
3814
|
try {
|
|
3813
|
-
let e =
|
|
3815
|
+
let e = ni(await this.client.request("account/rateLimits/read", void 0));
|
|
3814
3816
|
this.host.patch({ rateLimits: e }), this.host.emitEvent("action", {
|
|
3815
3817
|
type: "rateLimits.changed",
|
|
3816
3818
|
payload: { rateLimits: structuredClone(e) }
|
|
@@ -3836,12 +3838,12 @@ var ei = class {
|
|
|
3836
3838
|
}), (async () => ({
|
|
3837
3839
|
profiles: await this.requestPermissionProfiles(e),
|
|
3838
3840
|
requirements: (await this.client.request("configRequirements/read", void 0)).requirements
|
|
3839
|
-
}))()]), a = r.status === "fulfilled" ? await
|
|
3841
|
+
}))()]), a = r.status === "fulfilled" ? await Er(r.value.data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e)) : [], o = i.status === "fulfilled" ? i.value.profiles : [];
|
|
3840
3842
|
return {
|
|
3841
3843
|
skills: a,
|
|
3842
3844
|
skillCatalogStatus: r.status === "fulfilled" ? "loaded" : "error",
|
|
3843
3845
|
permissionProfiles: o,
|
|
3844
|
-
approvalPresets: i.status === "fulfilled" ?
|
|
3846
|
+
approvalPresets: i.status === "fulfilled" ? Lr(o, i.value.requirements) : []
|
|
3845
3847
|
};
|
|
3846
3848
|
}
|
|
3847
3849
|
schedulePluginRefresh(e = !1) {
|
|
@@ -3868,7 +3870,7 @@ var ei = class {
|
|
|
3868
3870
|
cursor: n,
|
|
3869
3871
|
includeHidden: e
|
|
3870
3872
|
});
|
|
3871
|
-
t.push(...r.data.map(
|
|
3873
|
+
t.push(...r.data.map(Tr)), n = r.nextCursor;
|
|
3872
3874
|
} while (n);
|
|
3873
3875
|
return t;
|
|
3874
3876
|
}
|
|
@@ -3879,7 +3881,7 @@ var ei = class {
|
|
|
3879
3881
|
modelCatalogStatus: "loaded",
|
|
3880
3882
|
selectedModelId: n?.id ?? null,
|
|
3881
3883
|
selectedReasoningEffort: n ? J(n) : null,
|
|
3882
|
-
selectedServiceTier: n ?
|
|
3884
|
+
selectedServiceTier: n ? Ir(n) : null
|
|
3883
3885
|
}), this.emitModels(e, "loaded", t);
|
|
3884
3886
|
}
|
|
3885
3887
|
emitModels(e, t, n = "action") {
|
|
@@ -3938,7 +3940,7 @@ var ei = class {
|
|
|
3938
3940
|
try {
|
|
3939
3941
|
let t = await this.client.request("plugin/installed", { ...e.length > 0 ? { cwds: [...e] } : {} }), n = /* @__PURE__ */ new Map();
|
|
3940
3942
|
for (let e of t.marketplaces) for (let t of e.plugins) n.has(t.id) || n.set(t.id, t);
|
|
3941
|
-
let r =
|
|
3943
|
+
let r = Kr(this.host.getState().plugins, await Promise.all([...n.values()].map((e) => Or(e, (e) => this.iconDataUrl(e)))));
|
|
3942
3944
|
if (this.host.isClosed() || this.host.authenticationBlocksBootstrap()) return;
|
|
3943
3945
|
this.host.patch({
|
|
3944
3946
|
plugins: r,
|
|
@@ -3968,10 +3970,10 @@ var ei = class {
|
|
|
3968
3970
|
return this.iconDataUrls.set(e, n), n;
|
|
3969
3971
|
}
|
|
3970
3972
|
async readIconDataUrl(e) {
|
|
3971
|
-
if (!
|
|
3972
|
-
let t =
|
|
3973
|
+
if (!v(e)) return;
|
|
3974
|
+
let t = jr(e);
|
|
3973
3975
|
if (t) try {
|
|
3974
|
-
return
|
|
3976
|
+
return Mr(t, (await this.client.request("fs/readFile", { path: e })).dataBase64);
|
|
3975
3977
|
} catch {
|
|
3976
3978
|
return;
|
|
3977
3979
|
}
|
|
@@ -3979,18 +3981,18 @@ var ei = class {
|
|
|
3979
3981
|
};
|
|
3980
3982
|
//#endregion
|
|
3981
3983
|
//#region src/node/codex-approvals.ts
|
|
3982
|
-
function
|
|
3984
|
+
function si(e, t) {
|
|
3983
3985
|
let n = [
|
|
3984
3986
|
e.onServerRequest("item/commandExecution/requestApproval", (e, n) => (t({
|
|
3985
|
-
approval:
|
|
3986
|
-
resolve: (t, r) => n.resolve({ decision:
|
|
3987
|
+
approval: ci(e.id, e.params),
|
|
3988
|
+
resolve: (t, r) => n.resolve({ decision: di(e.params, t, r) })
|
|
3987
3989
|
}), !0)),
|
|
3988
3990
|
e.onServerRequest("item/fileChange/requestApproval", (e, n) => (t({
|
|
3989
|
-
approval:
|
|
3991
|
+
approval: li(e.id, e.params),
|
|
3990
3992
|
resolve: (e, t) => n.resolve({ decision: e === "deny" ? "decline" : t === "session" ? "acceptForSession" : "accept" })
|
|
3991
3993
|
}), !0)),
|
|
3992
3994
|
e.onServerRequest("item/permissions/requestApproval", (e, n) => (t({
|
|
3993
|
-
approval:
|
|
3995
|
+
approval: ui(e.id, e.params),
|
|
3994
3996
|
resolve: (t, r) => n.resolve({
|
|
3995
3997
|
permissions: t === "deny" ? {} : {
|
|
3996
3998
|
...e.params.permissions.fileSystem ? { fileSystem: e.params.permissions.fileSystem } : {},
|
|
@@ -4028,8 +4030,8 @@ function ti(e, t) {
|
|
|
4028
4030
|
for (let e of n) e();
|
|
4029
4031
|
};
|
|
4030
4032
|
}
|
|
4031
|
-
function
|
|
4032
|
-
let n = t.availableDecisions, r =
|
|
4033
|
+
function ci(e, t) {
|
|
4034
|
+
let n = t.availableDecisions, r = fi(t.additionalPermissions), i = [...t.networkApprovalContext ? [{
|
|
4033
4035
|
kind: "network",
|
|
4034
4036
|
enabled: !0,
|
|
4035
4037
|
host: t.networkApprovalContext.host,
|
|
@@ -4052,7 +4054,7 @@ function ni(e, t) {
|
|
|
4052
4054
|
} : {}
|
|
4053
4055
|
};
|
|
4054
4056
|
}
|
|
4055
|
-
function
|
|
4057
|
+
function li(e, t) {
|
|
4056
4058
|
return {
|
|
4057
4059
|
id: String(e),
|
|
4058
4060
|
kind: "file-change",
|
|
@@ -4063,8 +4065,8 @@ function ri(e, t) {
|
|
|
4063
4065
|
...t.reason || t.grantRoot ? { description: t.reason ?? `Write under ${t.grantRoot}` } : {}
|
|
4064
4066
|
};
|
|
4065
4067
|
}
|
|
4066
|
-
function
|
|
4067
|
-
let n =
|
|
4068
|
+
function ui(e, t) {
|
|
4069
|
+
let n = fi(t.permissions);
|
|
4068
4070
|
return {
|
|
4069
4071
|
id: String(e),
|
|
4070
4072
|
kind: "permissions",
|
|
@@ -4077,13 +4079,13 @@ function ii(e, t) {
|
|
|
4077
4079
|
...n.length ? { requestedPermissions: n } : {}
|
|
4078
4080
|
};
|
|
4079
4081
|
}
|
|
4080
|
-
function
|
|
4082
|
+
function di(e, t, n) {
|
|
4081
4083
|
let r = e.availableDecisions, i = t === "deny" ? "decline" : n === "session" ? "acceptForSession" : "accept";
|
|
4082
4084
|
if (!r || r.includes(i)) return i;
|
|
4083
4085
|
if (t === "deny" && r.includes("cancel")) return "cancel";
|
|
4084
4086
|
throw Error(`Approval decision '${t}:${n}' is not available for this command`);
|
|
4085
4087
|
}
|
|
4086
|
-
function
|
|
4088
|
+
function fi(e) {
|
|
4087
4089
|
if (!e) return [];
|
|
4088
4090
|
let t = [];
|
|
4089
4091
|
if (e.network && t.push({
|
|
@@ -4103,12 +4105,12 @@ function oi(e) {
|
|
|
4103
4105
|
for (let n of e.fileSystem.entries ?? []) t.push({
|
|
4104
4106
|
kind: "filesystem",
|
|
4105
4107
|
access: n.access,
|
|
4106
|
-
path:
|
|
4108
|
+
path: pi(n.path)
|
|
4107
4109
|
});
|
|
4108
4110
|
}
|
|
4109
4111
|
return t;
|
|
4110
4112
|
}
|
|
4111
|
-
function
|
|
4113
|
+
function pi(e) {
|
|
4112
4114
|
if (e.type === "path") return e.path;
|
|
4113
4115
|
if (e.type === "glob_pattern") return e.pattern;
|
|
4114
4116
|
let t = e.value;
|
|
@@ -4123,12 +4125,12 @@ function si(e) {
|
|
|
4123
4125
|
}
|
|
4124
4126
|
//#endregion
|
|
4125
4127
|
//#region src/node/codex-surface-approvals-controller.ts
|
|
4126
|
-
var
|
|
4128
|
+
var mi = class {
|
|
4127
4129
|
host;
|
|
4128
4130
|
pending = /* @__PURE__ */ new Map();
|
|
4129
4131
|
unsubscribeHandler;
|
|
4130
4132
|
constructor(e, t) {
|
|
4131
|
-
this.host = t, this.unsubscribeHandler =
|
|
4133
|
+
this.host = t, this.unsubscribeHandler = si(e, (e) => this.add(e));
|
|
4132
4134
|
}
|
|
4133
4135
|
close() {
|
|
4134
4136
|
this.unsubscribeHandler(), this.pending.clear();
|
|
@@ -4209,7 +4211,7 @@ var ci = class {
|
|
|
4209
4211
|
};
|
|
4210
4212
|
//#endregion
|
|
4211
4213
|
//#region src/node/codex-surface-mcp.ts
|
|
4212
|
-
function
|
|
4214
|
+
function hi(e) {
|
|
4213
4215
|
if (!Array.isArray(e)) throw TypeError("Codex MCP servers must be an array");
|
|
4214
4216
|
let t = /* @__PURE__ */ new Set();
|
|
4215
4217
|
return e.map((e, n) => {
|
|
@@ -4218,10 +4220,10 @@ function li(e) {
|
|
|
4218
4220
|
if (!r || !/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(r)) throw TypeError(`Codex MCP server ${n + 1} name must match ^[A-Za-z0-9][A-Za-z0-9_-]*$`);
|
|
4219
4221
|
if (t.has(r)) throw Error(`Duplicate Codex MCP server '${r}'`);
|
|
4220
4222
|
t.add(r);
|
|
4221
|
-
let i =
|
|
4223
|
+
let i = gi(e.transport, r), a = e.toolApprovalMode;
|
|
4222
4224
|
if (a !== void 0 && a !== "auto" && a !== "prompt" && a !== "writes" && a !== "approve") throw TypeError(`Codex MCP server '${r}' tool approval mode is invalid`);
|
|
4223
4225
|
if (e.required !== void 0 && typeof e.required != "boolean") throw TypeError(`Codex MCP server '${r}' required flag must be a boolean`);
|
|
4224
|
-
let o = e.enabledTools === void 0 ? void 0 :
|
|
4226
|
+
let o = e.enabledTools === void 0 ? void 0 : _i(e.enabledTools, `Codex MCP server '${r}' enabled tool`), s = yi(e.startupTimeoutMs, `Codex MCP server '${r}' startup timeout`), c = yi(e.toolTimeoutMs, `Codex MCP server '${r}' tool timeout`);
|
|
4225
4227
|
return {
|
|
4226
4228
|
name: r,
|
|
4227
4229
|
transport: i,
|
|
@@ -4233,7 +4235,7 @@ function li(e) {
|
|
|
4233
4235
|
};
|
|
4234
4236
|
});
|
|
4235
4237
|
}
|
|
4236
|
-
function
|
|
4238
|
+
function gi(e, t) {
|
|
4237
4239
|
if (!e || typeof e != "object" || Array.isArray(e)) throw TypeError(`Codex MCP server '${t}' transport must be an object`);
|
|
4238
4240
|
if (e.type === "http") {
|
|
4239
4241
|
let n = e.url?.trim(), r;
|
|
@@ -4251,8 +4253,8 @@ function ui(e, t) {
|
|
|
4251
4253
|
if (e.type !== "stdio") throw TypeError(`Codex MCP server '${t}' transport type is invalid`);
|
|
4252
4254
|
let n = e.command?.trim();
|
|
4253
4255
|
if (!n) throw TypeError(`Codex MCP server '${t}' command cannot be empty`);
|
|
4254
|
-
let r = e.args === void 0 ? void 0 :
|
|
4255
|
-
if (i !== void 0 && (!i || !
|
|
4256
|
+
let r = e.args === void 0 ? void 0 : _i(e.args, `Codex MCP server '${t}' argument`), i = e.cwd?.trim();
|
|
4257
|
+
if (i !== void 0 && (!i || !v(i))) throw TypeError(`Codex MCP server '${t}' cwd must be an absolute path`);
|
|
4256
4258
|
let a;
|
|
4257
4259
|
if (e.env !== void 0) {
|
|
4258
4260
|
if (!e.env || typeof e.env != "object" || Array.isArray(e.env)) throw TypeError(`Codex MCP server '${t}' env must be an object`);
|
|
@@ -4262,7 +4264,7 @@ function ui(e, t) {
|
|
|
4262
4264
|
a[n] = r;
|
|
4263
4265
|
}
|
|
4264
4266
|
}
|
|
4265
|
-
let o = e.envVars === void 0 ? void 0 :
|
|
4267
|
+
let o = e.envVars === void 0 ? void 0 : vi(e.envVars, t);
|
|
4266
4268
|
return {
|
|
4267
4269
|
type: "stdio",
|
|
4268
4270
|
command: n,
|
|
@@ -4272,7 +4274,7 @@ function ui(e, t) {
|
|
|
4272
4274
|
...o === void 0 ? {} : { envVars: o }
|
|
4273
4275
|
};
|
|
4274
4276
|
}
|
|
4275
|
-
function
|
|
4277
|
+
function _i(e, t) {
|
|
4276
4278
|
if (!Array.isArray(e)) throw TypeError(`${t}s must be an array`);
|
|
4277
4279
|
let n = e.map((e) => {
|
|
4278
4280
|
if (typeof e != "string" || !e.trim()) throw TypeError(`${t} cannot be empty`);
|
|
@@ -4280,18 +4282,18 @@ function di(e, t) {
|
|
|
4280
4282
|
});
|
|
4281
4283
|
return [...new Set(n)];
|
|
4282
4284
|
}
|
|
4283
|
-
function
|
|
4284
|
-
let n =
|
|
4285
|
+
function vi(e, t) {
|
|
4286
|
+
let n = _i(e, `Codex MCP server '${t}' environment variable`);
|
|
4285
4287
|
for (let e of n) if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)) throw TypeError(`Codex MCP server '${t}' environment variable '${e}' is invalid`);
|
|
4286
4288
|
return n;
|
|
4287
4289
|
}
|
|
4288
|
-
function
|
|
4290
|
+
function yi(e, t) {
|
|
4289
4291
|
if (e !== void 0) {
|
|
4290
4292
|
if (!Number.isFinite(e) || e <= 0) throw TypeError(`${t} must be a positive finite number`);
|
|
4291
4293
|
return e;
|
|
4292
4294
|
}
|
|
4293
4295
|
}
|
|
4294
|
-
function
|
|
4296
|
+
function bi(e) {
|
|
4295
4297
|
let t = {};
|
|
4296
4298
|
for (let n of e) {
|
|
4297
4299
|
let e = n.transport.type === "http" ? { url: n.transport.url } : {
|
|
@@ -4305,7 +4307,7 @@ function mi(e) {
|
|
|
4305
4307
|
}
|
|
4306
4308
|
return t;
|
|
4307
4309
|
}
|
|
4308
|
-
function
|
|
4310
|
+
function xi(e, t) {
|
|
4309
4311
|
if (t.length !== 0) for (let n of Object.keys(e)) {
|
|
4310
4312
|
if (n === "mcp_servers") throw Error("Raw mcp_servers config cannot be combined with typed Codex MCP servers");
|
|
4311
4313
|
for (let e of t) {
|
|
@@ -4316,13 +4318,13 @@ function hi(e, t) {
|
|
|
4316
4318
|
}
|
|
4317
4319
|
//#endregion
|
|
4318
4320
|
//#region src/node/codex-surface-extensions-controller.ts
|
|
4319
|
-
var
|
|
4321
|
+
var Si = class {
|
|
4320
4322
|
extensions;
|
|
4321
4323
|
hostOptionsForThread;
|
|
4322
4324
|
dynamicTools = /* @__PURE__ */ new Map();
|
|
4323
4325
|
defaultMcpServers;
|
|
4324
4326
|
constructor(e, t, n) {
|
|
4325
|
-
this.extensions = e, this.hostOptionsForThread = n, this.defaultMcpServers =
|
|
4327
|
+
this.extensions = e, this.hostOptionsForThread = n, this.defaultMcpServers = hi(t);
|
|
4326
4328
|
for (let t of e) for (let e of t.dynamicTools ?? []) {
|
|
4327
4329
|
let t = e.name.trim();
|
|
4328
4330
|
if (!t) throw Error("Dynamic tool names cannot be empty");
|
|
@@ -4346,13 +4348,13 @@ var gi = class {
|
|
|
4346
4348
|
}));
|
|
4347
4349
|
}
|
|
4348
4350
|
async conversationExtension(e, t = {}, n = this.defaultMcpServers) {
|
|
4349
|
-
let r =
|
|
4351
|
+
let r = bi(n), i = [], a;
|
|
4350
4352
|
for (let t of this.extensions) {
|
|
4351
4353
|
if (!t.configureConversation) continue;
|
|
4352
4354
|
let o = await t.configureConversation(e);
|
|
4353
|
-
o.config && (
|
|
4355
|
+
o.config && (xi(o.config, n), Object.assign(r, o.config)), o.baseInstructions !== void 0 && (a = o.baseInstructions), o.developerInstructions?.trim() && i.push(o.developerInstructions.trim());
|
|
4354
4356
|
}
|
|
4355
|
-
return t.config && (
|
|
4357
|
+
return t.config && (xi(t.config, n), Object.assign(r, t.config)), t.baseInstructions !== void 0 && (a = t.baseInstructions), t.developerInstructions?.trim() && i.push(t.developerInstructions.trim()), {
|
|
4356
4358
|
...a === void 0 ? {} : { baseInstructions: a },
|
|
4357
4359
|
...Object.keys(r).length === 0 ? {} : { config: r },
|
|
4358
4360
|
...i.length === 0 ? {} : { developerInstructions: i.join("\n\n") }
|
|
@@ -4406,12 +4408,12 @@ var gi = class {
|
|
|
4406
4408
|
success: !1,
|
|
4407
4409
|
contentItems: [{
|
|
4408
4410
|
type: "inputText",
|
|
4409
|
-
text:
|
|
4411
|
+
text: O(e)
|
|
4410
4412
|
}]
|
|
4411
4413
|
});
|
|
4412
4414
|
}
|
|
4413
4415
|
}
|
|
4414
|
-
},
|
|
4416
|
+
}, Ci = 50, wi = 25, Ti = 25, Ei = class {
|
|
4415
4417
|
client;
|
|
4416
4418
|
conversationLimit;
|
|
4417
4419
|
host;
|
|
@@ -4430,7 +4432,7 @@ var gi = class {
|
|
|
4430
4432
|
return await this.host.ensureConnected(), this.load();
|
|
4431
4433
|
}
|
|
4432
4434
|
async load() {
|
|
4433
|
-
let e =
|
|
4435
|
+
let e = Kr(this.host.getState().conversations, await this.requestConversations({ limit: this.conversationLimit }));
|
|
4434
4436
|
this.host.patch({ conversations: e }), this.host.schedulePluginRefresh(!0);
|
|
4435
4437
|
for (let t of e) this.host.emitSummaryUpserted(t, "listed", "action");
|
|
4436
4438
|
return this.host.getSnapshot();
|
|
@@ -4439,7 +4441,7 @@ var gi = class {
|
|
|
4439
4441
|
return await this.host.ensureConnected(), structuredClone(await this.requestConversations(e));
|
|
4440
4442
|
}
|
|
4441
4443
|
async readSummary(e) {
|
|
4442
|
-
let t =
|
|
4444
|
+
let t = D(e);
|
|
4443
4445
|
await this.host.ensureConnected();
|
|
4444
4446
|
let n = await this.client.request("thread/read", {
|
|
4445
4447
|
threadId: t,
|
|
@@ -4450,15 +4452,15 @@ var gi = class {
|
|
|
4450
4452
|
return structuredClone(r);
|
|
4451
4453
|
}
|
|
4452
4454
|
async archive(e) {
|
|
4453
|
-
let t =
|
|
4455
|
+
let t = D(e);
|
|
4454
4456
|
return await this.host.ensureConnected(), await this.client.request("thread/archive", { threadId: t }), this.host.removeThread(t, "archived", "action"), this.host.getSnapshot();
|
|
4455
4457
|
}
|
|
4456
4458
|
async delete(e) {
|
|
4457
|
-
let t =
|
|
4459
|
+
let t = D(e);
|
|
4458
4460
|
return await this.host.ensureConnected(), await this.client.request("thread/delete", { threadId: t }), this.host.removeThread(t, "deleted", "action"), this.host.getSnapshot();
|
|
4459
4461
|
}
|
|
4460
4462
|
async unarchive(e) {
|
|
4461
|
-
let t =
|
|
4463
|
+
let t = D(e);
|
|
4462
4464
|
await this.host.ensureConnected();
|
|
4463
4465
|
let n = await this.client.request("thread/unarchive", { threadId: t });
|
|
4464
4466
|
if (n.thread.id !== t) throw Error(`Codex thread/unarchive returned '${n.thread.id}' for requested thread '${t}'`);
|
|
@@ -4480,7 +4482,7 @@ var gi = class {
|
|
|
4480
4482
|
let t = await this.client.request("thread/turns/list", {
|
|
4481
4483
|
threadId: e,
|
|
4482
4484
|
cursor: null,
|
|
4483
|
-
limit:
|
|
4485
|
+
limit: Ci,
|
|
4484
4486
|
sortDirection: "desc",
|
|
4485
4487
|
itemsView: "full"
|
|
4486
4488
|
});
|
|
@@ -4500,7 +4502,7 @@ var gi = class {
|
|
|
4500
4502
|
historyHasOlder: !1
|
|
4501
4503
|
});
|
|
4502
4504
|
} catch (t) {
|
|
4503
|
-
throw this.host.runtime(e) && this.host.patchRuntime(e, { error: `Could not load complete conversation history: ${
|
|
4505
|
+
throw this.host.runtime(e) && this.host.patchRuntime(e, { error: `Could not load complete conversation history: ${O(t)}` }), t;
|
|
4504
4506
|
}
|
|
4505
4507
|
})();
|
|
4506
4508
|
return this.historyHydrations.set(e, r), r.finally(() => {
|
|
@@ -4528,7 +4530,7 @@ var gi = class {
|
|
|
4528
4530
|
let i = new Set(this.host.requireRuntime(e).turnIds), a = await this.client.request("thread/turns/list", {
|
|
4529
4531
|
threadId: e,
|
|
4530
4532
|
cursor: t,
|
|
4531
|
-
limit:
|
|
4533
|
+
limit: wi,
|
|
4532
4534
|
sortDirection: "desc",
|
|
4533
4535
|
itemsView: "full"
|
|
4534
4536
|
}), o = [...a.data].reverse(), s = new Set(o.map((e) => e.id).filter((e) => !i.has(e)));
|
|
@@ -4544,7 +4546,7 @@ var gi = class {
|
|
|
4544
4546
|
hasOlder: this.host.requireRuntime(e).historyHasOlder
|
|
4545
4547
|
};
|
|
4546
4548
|
} catch (t) {
|
|
4547
|
-
throw this.host.runtime(e) && this.host.patchRuntime(e, { error:
|
|
4549
|
+
throw this.host.runtime(e) && this.host.patchRuntime(e, { error: O(t) }), t;
|
|
4548
4550
|
} finally {
|
|
4549
4551
|
this.host.runtime(e) && this.host.patchRuntime(e, { historyLoadingOlder: !1 });
|
|
4550
4552
|
}
|
|
@@ -4559,8 +4561,8 @@ var gi = class {
|
|
|
4559
4561
|
}
|
|
4560
4562
|
async emitHistoryChunks(e, t) {
|
|
4561
4563
|
for (let n = t.length; n > 0;) {
|
|
4562
|
-
let r = Math.max(0, n -
|
|
4563
|
-
this.host.emitHistoryPrepended(e, t.slice(r, n), "lifecycle"), await
|
|
4564
|
+
let r = Math.max(0, n - Ti);
|
|
4565
|
+
this.host.emitHistoryPrepended(e, t.slice(r, n), "lifecycle"), await Di(), n = r;
|
|
4564
4566
|
}
|
|
4565
4567
|
}
|
|
4566
4568
|
async refreshCompleteHistory(e) {
|
|
@@ -4596,7 +4598,7 @@ var gi = class {
|
|
|
4596
4598
|
let i = /* @__PURE__ */ new Set();
|
|
4597
4599
|
r.activeTurnId && i.add(r.activeTurnId);
|
|
4598
4600
|
for (let e of t) e.status === "inProgress" && r.turnIds.includes(e.id) && i.add(e.id);
|
|
4599
|
-
let a = new Set(t.filter((e) => !i.has(e.id)).map((e) => e.id)), o = t.filter((e) => a.has(e.id)), s = r.turnIds.filter((e) => !a.has(e)), c = r.turns.filter((e) => !a.has(e.id)), l = r.messages.filter((e) => e.turnId === void 0 || !a.has(e.turnId)), u =
|
|
4601
|
+
let a = new Set(t.filter((e) => !i.has(e.id)).map((e) => e.id)), o = t.filter((e) => a.has(e.id)), s = r.turnIds.filter((e) => !a.has(e)), c = r.turns.filter((e) => !a.has(e.id)), l = r.messages.filter((e) => e.turnId === void 0 || !a.has(e.turnId)), u = Rn(r.messages, o.flatMap((t) => zn(e, t)));
|
|
4600
4602
|
this.host.patchRuntime(e, {
|
|
4601
4603
|
turnIds: [...o.map((e) => e.id), ...s],
|
|
4602
4604
|
turns: [...o.map((e) => W(e)), ...c],
|
|
@@ -4623,12 +4625,12 @@ var gi = class {
|
|
|
4623
4625
|
} : t;
|
|
4624
4626
|
}
|
|
4625
4627
|
};
|
|
4626
|
-
function
|
|
4628
|
+
function Di() {
|
|
4627
4629
|
return new Promise((e) => setTimeout(e, 0));
|
|
4628
4630
|
}
|
|
4629
4631
|
//#endregion
|
|
4630
4632
|
//#region src/node/codex-surface-conversation-settings-controller.ts
|
|
4631
|
-
var
|
|
4633
|
+
var Oi = class {
|
|
4632
4634
|
client;
|
|
4633
4635
|
defaults;
|
|
4634
4636
|
host;
|
|
@@ -4640,7 +4642,7 @@ var Si = class {
|
|
|
4640
4642
|
}
|
|
4641
4643
|
threadStartSettings(e, t) {
|
|
4642
4644
|
let n = this.preferredApprovalPreset(), r = e.approvalPreset ?? (e.approvalMode === void 0 && e.permissionMode === void 0 ? t.includes(n ?? "ask-for-approval") ? n : t[0] ?? null : null);
|
|
4643
|
-
if (r) return
|
|
4645
|
+
if (r) return Rr(r);
|
|
4644
4646
|
let i = e.approvalMode ?? this.defaults.approvalMode, a = e.permissionMode ?? this.defaults.permissionMode ?? "read-only";
|
|
4645
4647
|
return {
|
|
4646
4648
|
approvalPolicy: i === "ask" ? "on-request" : "never",
|
|
@@ -4666,23 +4668,23 @@ var Si = class {
|
|
|
4666
4668
|
async update(e) {
|
|
4667
4669
|
let t = this.host.getState(), n = t.activeConversationId;
|
|
4668
4670
|
if (!n) {
|
|
4669
|
-
let n =
|
|
4671
|
+
let n = Ur(t, e);
|
|
4670
4672
|
if (e.approvalPreset && !t.approvalPresets.includes(e.approvalPreset)) throw Error(`Approval preset '${e.approvalPreset}' is not available`);
|
|
4671
4673
|
return this.host.patch(n), this.host.getSnapshot();
|
|
4672
4674
|
}
|
|
4673
4675
|
return await this.updateForThread(n, e), this.host.getSnapshot();
|
|
4674
4676
|
}
|
|
4675
4677
|
async updateForThread(e, t) {
|
|
4676
|
-
let n = await this.host.ensureThreadReady(e), r = this.host.snapshotForRuntime(n), i =
|
|
4678
|
+
let n = await this.host.ensureThreadReady(e), r = this.host.snapshotForRuntime(n), i = Ur(r, t), a = n.approvalPreset !== i.approvalPreset || n.selectedModelId !== i.selectedModelId || n.selectedReasoningEffort !== i.selectedReasoningEffort || n.selectedServiceTier !== i.selectedServiceTier || n.planMode !== i.planMode;
|
|
4677
4679
|
if (t.approvalPreset && !r.approvalPresets.includes(t.approvalPreset)) throw Error(`Approval preset '${t.approvalPreset}' is not available`);
|
|
4678
4680
|
let o = q(this.host.getState().models, i.selectedModelId);
|
|
4679
4681
|
await this.client.request("thread/settings/update", {
|
|
4680
4682
|
threadId: e,
|
|
4681
|
-
...t.approvalPreset ?
|
|
4683
|
+
...t.approvalPreset ? zr(t.approvalPreset) : {},
|
|
4682
4684
|
...t.modelId && o ? { model: o.model } : {},
|
|
4683
4685
|
...t.reasoningEffort || t.modelId ? { effort: i.selectedReasoningEffort } : {},
|
|
4684
4686
|
...t.serviceTier !== void 0 || t.modelId ? { serviceTier: i.selectedServiceTier } : {},
|
|
4685
|
-
...o && (typeof t.planMode == "boolean" || t.modelId || t.reasoningEffort) ? { collaborationMode:
|
|
4687
|
+
...o && (typeof t.planMode == "boolean" || t.modelId || t.reasoningEffort) ? { collaborationMode: Wr(i.planMode, o.model, i.selectedReasoningEffort) } : {}
|
|
4686
4688
|
}), this.host.patchRuntime(e, i), a && this.host.emitConversationSettings(e, "action");
|
|
4687
4689
|
}
|
|
4688
4690
|
async setGoal(e, t) {
|
|
@@ -4701,7 +4703,7 @@ var Si = class {
|
|
|
4701
4703
|
...n === void 0 ? {} : { tokenBudget: n }
|
|
4702
4704
|
});
|
|
4703
4705
|
if (a.goal.threadId !== e) throw Error(`Codex thread/goal/set returned a goal for '${a.goal.threadId}' instead of '${e}'`);
|
|
4704
|
-
let o = !
|
|
4706
|
+
let o = !gr(r.goal, a.goal);
|
|
4705
4707
|
this.host.patchRuntime(e, { goal: { ...a.goal } }), o && this.host.emitEvent("action", {
|
|
4706
4708
|
type: "conversation.goalChanged",
|
|
4707
4709
|
conversationId: e,
|
|
@@ -4723,7 +4725,7 @@ var Si = class {
|
|
|
4723
4725
|
payload: { goal: null }
|
|
4724
4726
|
});
|
|
4725
4727
|
}
|
|
4726
|
-
},
|
|
4728
|
+
}, ki = "Review the current code changes (staged, unstaged, and untracked files) and provide prioritized findings.", Ai = class {
|
|
4727
4729
|
client;
|
|
4728
4730
|
host;
|
|
4729
4731
|
constructor(e, t) {
|
|
@@ -4752,7 +4754,7 @@ var Si = class {
|
|
|
4752
4754
|
error: null
|
|
4753
4755
|
}), this.host.patchConversationStatus(e, "active", "action"), this.host.emitConversationActivity(e, "action");
|
|
4754
4756
|
try {
|
|
4755
|
-
let r =
|
|
4757
|
+
let r = tt(t.target ?? { type: "uncommittedChanges" }), i = await this.client.request("review/start", {
|
|
4756
4758
|
threadId: e,
|
|
4757
4759
|
target: r,
|
|
4758
4760
|
delivery: "inline"
|
|
@@ -4760,22 +4762,22 @@ var Si = class {
|
|
|
4760
4762
|
if (i.reviewThreadId !== e) throw Error(`Codex review/start returned unexpected review thread '${i.reviewThreadId}' for inline review on thread '${e}'`);
|
|
4761
4763
|
let a = n.turnIds.includes(i.turn.id);
|
|
4762
4764
|
n.activeTurnId = i.turn.status === "inProgress" ? i.turn.id : null, n.turnIds.includes(i.turn.id) || n.turnIds.push(i.turn.id), this.host.patchConversationTurnCount(e, n.turnIds.length, "action");
|
|
4763
|
-
let o =
|
|
4765
|
+
let o = zn(e, i.turn).filter((e) => !n.messages.some((t) => t.id === e.id)).map((e) => e.role === "user" ? {
|
|
4764
4766
|
...e,
|
|
4765
4767
|
parts: r.type === "uncommittedChanges" ? e.parts.map((e) => e.type === "text" && e.text === "current changes" ? {
|
|
4766
4768
|
...e,
|
|
4767
|
-
text:
|
|
4769
|
+
text: ki
|
|
4768
4770
|
} : e) : e.parts,
|
|
4769
4771
|
metadata: {
|
|
4770
4772
|
...e.metadata,
|
|
4771
4773
|
reviewPrompt: !0
|
|
4772
4774
|
}
|
|
4773
|
-
} : e), s =
|
|
4775
|
+
} : e), s = ji(n.messages, i.turn.id, o);
|
|
4774
4776
|
this.host.patchRuntime(e, {
|
|
4775
4777
|
busy: n.activeTurnId !== null,
|
|
4776
4778
|
turnStartPending: !1,
|
|
4777
4779
|
turns: G(n.turns, W(i.turn)),
|
|
4778
|
-
messages: n.activeTurnId ?
|
|
4780
|
+
messages: n.activeTurnId ? I(s, e, i.turn.id) : s
|
|
4779
4781
|
});
|
|
4780
4782
|
for (let t of o) this.host.emitEvent("action", {
|
|
4781
4783
|
type: "message.appended",
|
|
@@ -4793,7 +4795,7 @@ var Si = class {
|
|
|
4793
4795
|
throw this.host.patchRuntime(e, {
|
|
4794
4796
|
busy: !1,
|
|
4795
4797
|
turnStartPending: !1,
|
|
4796
|
-
error:
|
|
4798
|
+
error: O(t)
|
|
4797
4799
|
}), this.host.patchConversationStatus(e, "error", "action"), this.host.emitConversationActivity(e, "action"), t;
|
|
4798
4800
|
}
|
|
4799
4801
|
}
|
|
@@ -4820,11 +4822,11 @@ var Si = class {
|
|
|
4820
4822
|
return await this.editTurnForThread(n, e, t), this.host.getSnapshot();
|
|
4821
4823
|
}
|
|
4822
4824
|
async editTurnForThread(e, t, n) {
|
|
4823
|
-
let r = (await this.host.ensureThreadReady(e)).messages.find((e) => e.role === "user" && e.kind !== "steer" &&
|
|
4825
|
+
let r = (await this.host.ensureThreadReady(e)).messages.find((e) => e.role === "user" && e.kind !== "steer" && Zr(e) === t);
|
|
4824
4826
|
if (!r) throw Error(`Could not find the user prompt for Codex turn '${t}'`);
|
|
4825
4827
|
let i = n.trim();
|
|
4826
4828
|
if (!i) throw Error("Cannot replace a turn prompt with empty content");
|
|
4827
|
-
let a =
|
|
4829
|
+
let a = $r(r);
|
|
4828
4830
|
await this.rollbackToTurn(e, t), await this.host.sendMessageToThread(e, i, a.length > 0 ? { attachments: a } : {});
|
|
4829
4831
|
}
|
|
4830
4832
|
async retryTurn(e) {
|
|
@@ -4832,11 +4834,11 @@ var Si = class {
|
|
|
4832
4834
|
return await this.retryTurnForThread(t, e), this.host.getSnapshot();
|
|
4833
4835
|
}
|
|
4834
4836
|
async retryTurnForThread(e, t) {
|
|
4835
|
-
let n = (await this.host.ensureThreadReady(e)).messages.find((e) => e.role === "user" && e.kind !== "steer" &&
|
|
4837
|
+
let n = (await this.host.ensureThreadReady(e)).messages.find((e) => e.role === "user" && e.kind !== "steer" && Zr(e) === t);
|
|
4836
4838
|
if (!n) throw Error("Could not find the user prompt for this turn");
|
|
4837
|
-
let r =
|
|
4839
|
+
let r = Qr(n);
|
|
4838
4840
|
if (!r) throw Error("Could not find the user prompt for this turn");
|
|
4839
|
-
let i =
|
|
4841
|
+
let i = $r(n);
|
|
4840
4842
|
await this.rollbackToTurn(e, t), await this.host.sendMessageToThread(e, r, i.length > 0 ? { attachments: i } : {});
|
|
4841
4843
|
}
|
|
4842
4844
|
async rollbackToTurn(e, t) {
|
|
@@ -4856,7 +4858,7 @@ var Si = class {
|
|
|
4856
4858
|
n.turnIds = i.thread.turns.map((e) => e.id), n.turns = i.thread.turns.map((e) => W(e)), n.activeTurnId = null;
|
|
4857
4859
|
let a = Z(i.thread);
|
|
4858
4860
|
this.host.patch({ conversations: Q(this.host.getState().conversations, a) }), this.host.patchRuntime(e, {
|
|
4859
|
-
messages:
|
|
4861
|
+
messages: Ln(i.thread),
|
|
4860
4862
|
answeredClientRequestIds: [],
|
|
4861
4863
|
busy: !1,
|
|
4862
4864
|
turnStartPending: !1,
|
|
@@ -4872,7 +4874,7 @@ var Si = class {
|
|
|
4872
4874
|
});
|
|
4873
4875
|
if (i.thread.id !== e) throw Error(`Codex thread/revert returned '${i.thread.id}' for requested thread '${e}'`);
|
|
4874
4876
|
let a = r.turnIds.slice(0, n), o = new Set(a), s = r.messages.filter((e) => {
|
|
4875
|
-
let t =
|
|
4877
|
+
let t = Zr(e);
|
|
4876
4878
|
return t === null || o.has(t);
|
|
4877
4879
|
});
|
|
4878
4880
|
r.turnIds = a, r.turns = r.turns.filter((e) => o.has(e.id)), r.activeTurnId = null;
|
|
@@ -4899,7 +4901,7 @@ var Si = class {
|
|
|
4899
4901
|
return e;
|
|
4900
4902
|
}
|
|
4901
4903
|
};
|
|
4902
|
-
function
|
|
4904
|
+
function ji(e, t, n) {
|
|
4903
4905
|
let r = e.findIndex((e) => e.turnId === t);
|
|
4904
4906
|
return r < 0 ? [...e, ...n] : [
|
|
4905
4907
|
...e.slice(0, r),
|
|
@@ -4909,7 +4911,7 @@ function Ti(e, t, n) {
|
|
|
4909
4911
|
}
|
|
4910
4912
|
//#endregion
|
|
4911
4913
|
//#region src/node/codex-surface-messages-controller.ts
|
|
4912
|
-
var
|
|
4914
|
+
var Mi = class {
|
|
4913
4915
|
client;
|
|
4914
4916
|
host;
|
|
4915
4917
|
constructor(e, t) {
|
|
@@ -4920,7 +4922,7 @@ var Ei = class {
|
|
|
4920
4922
|
let n = e.trim();
|
|
4921
4923
|
if (!n) throw Error("Cannot send an empty message");
|
|
4922
4924
|
if (!this.host.getState().activeConversationId) {
|
|
4923
|
-
let e =
|
|
4925
|
+
let e = Qe(n);
|
|
4924
4926
|
if (e) {
|
|
4925
4927
|
if (await this.host.createConversation(), await this.host.updateSettings({ planMode: !0 }), !e.prompt) return this.host.getSnapshot();
|
|
4926
4928
|
n = e.prompt, t = {
|
|
@@ -4928,14 +4930,14 @@ var Ei = class {
|
|
|
4928
4930
|
planMode: !0
|
|
4929
4931
|
};
|
|
4930
4932
|
}
|
|
4931
|
-
let r =
|
|
4933
|
+
let r = $e(n);
|
|
4932
4934
|
if (r) {
|
|
4933
4935
|
if (r.action === "clear" || r.action === "show" || r.action === "edit") return this.host.getSnapshot();
|
|
4934
4936
|
if (r.action === "set") return this.host.setGoal(r.objective);
|
|
4935
4937
|
throw Error("Pausing and resuming goals is not supported by Codex app-server");
|
|
4936
4938
|
}
|
|
4937
4939
|
if (n === "/compact") return this.host.getSnapshot();
|
|
4938
|
-
let i =
|
|
4940
|
+
let i = et(n);
|
|
4939
4941
|
if (i) return await this.host.createConversation(), this.host.startReview({ target: i });
|
|
4940
4942
|
this.host.getState().activeConversationId || await this.host.createConversation();
|
|
4941
4943
|
}
|
|
@@ -4946,7 +4948,7 @@ var Ei = class {
|
|
|
4946
4948
|
async sendToThread(e, t, n = {}) {
|
|
4947
4949
|
let r = await this.host.ensureThreadReady(e), i = t.trim();
|
|
4948
4950
|
if (!i) throw Error("Cannot send an empty message");
|
|
4949
|
-
let a =
|
|
4951
|
+
let a = Qe(i);
|
|
4950
4952
|
if (a) {
|
|
4951
4953
|
if (await this.host.updateSettingsForThread(e, { planMode: !0 }), !a.prompt) return;
|
|
4952
4954
|
i = a.prompt, n = {
|
|
@@ -4954,7 +4956,7 @@ var Ei = class {
|
|
|
4954
4956
|
planMode: !0
|
|
4955
4957
|
};
|
|
4956
4958
|
}
|
|
4957
|
-
let o =
|
|
4959
|
+
let o = $e(i);
|
|
4958
4960
|
if (o) {
|
|
4959
4961
|
if (o.action === "clear") return this.host.clearGoalForThread(e);
|
|
4960
4962
|
if (o.action === "set") return this.host.setGoalForThread(e, o.objective);
|
|
@@ -4962,11 +4964,11 @@ var Ei = class {
|
|
|
4962
4964
|
return;
|
|
4963
4965
|
}
|
|
4964
4966
|
if (i === "/compact") return this.host.compactForThread(e);
|
|
4965
|
-
let s =
|
|
4967
|
+
let s = et(i);
|
|
4966
4968
|
if (s) return this.host.startReviewForThread(e, { target: s });
|
|
4967
4969
|
n = {
|
|
4968
|
-
...
|
|
4969
|
-
...n.skills ? { skills:
|
|
4970
|
+
...qr(this.host.snapshotForRuntime(r), n),
|
|
4971
|
+
...n.skills ? { skills: rt(n.skills, r.skills) } : {}
|
|
4970
4972
|
}, await this.sendPromptToThread(e, i, n);
|
|
4971
4973
|
}
|
|
4972
4974
|
async continueInterruptedTurn() {
|
|
@@ -4989,7 +4991,7 @@ var Ei = class {
|
|
|
4989
4991
|
let n = await this.client.request("turn/start", {
|
|
4990
4992
|
threadId: e,
|
|
4991
4993
|
input: [],
|
|
4992
|
-
...
|
|
4994
|
+
...Gr(this.host.snapshotForRuntime(t), {})
|
|
4993
4995
|
}), r = t.turnIds.includes(n.turn.id);
|
|
4994
4996
|
t.activeTurnId = n.turn.status === "inProgress" ? n.turn.id : null, r || t.turnIds.push(n.turn.id), this.host.patchConversationTurnCount(e, t.turnIds.length, "action");
|
|
4995
4997
|
let i = n.turn.status === "inProgress";
|
|
@@ -4997,7 +4999,7 @@ var Ei = class {
|
|
|
4997
4999
|
busy: i,
|
|
4998
5000
|
turnStartPending: !1,
|
|
4999
5001
|
turns: G(t.turns, W(n.turn)),
|
|
5000
|
-
messages: i ?
|
|
5002
|
+
messages: i ? I(t.messages, e, n.turn.id) : t.messages
|
|
5001
5003
|
}), this.host.patchConversationStatus(e, i ? "active" : "idle", "action"), i && !r && this.host.emitEvent("action", {
|
|
5002
5004
|
type: "turn.started",
|
|
5003
5005
|
conversationId: e,
|
|
@@ -5008,28 +5010,28 @@ var Ei = class {
|
|
|
5008
5010
|
throw this.host.patchRuntime(e, {
|
|
5009
5011
|
busy: !1,
|
|
5010
5012
|
turnStartPending: !1,
|
|
5011
|
-
error:
|
|
5013
|
+
error: O(t)
|
|
5012
5014
|
}), this.host.patchConversationStatus(e, "error", "action"), this.host.emitConversationActivity(e, "action"), t;
|
|
5013
5015
|
}
|
|
5014
5016
|
}
|
|
5015
5017
|
async sendPromptToThread(e, t, n = {}, r) {
|
|
5016
|
-
let i = this.host.requireRuntime(e), a =
|
|
5018
|
+
let i = this.host.requireRuntime(e), a = qr(this.host.snapshotForRuntime(i), n), o = r?.trim() || t, s = it(nt(t, i.skills), rt(a.skills ?? [], i.skills)), c = Jr(a.attachments ?? []);
|
|
5017
5019
|
if (i.busy) {
|
|
5018
5020
|
this.host.patchRuntime(e, { queuedPrompts: [...i.queuedPrompts, {
|
|
5019
|
-
id:
|
|
5021
|
+
id: vr(),
|
|
5020
5022
|
text: o,
|
|
5021
5023
|
...Object.keys(a).length > 0 ? { options: a } : {}
|
|
5022
5024
|
}] }), this.emitQueuedPrompts(e);
|
|
5023
5025
|
return;
|
|
5024
5026
|
}
|
|
5025
|
-
let l =
|
|
5027
|
+
let l = _r(), u = {
|
|
5026
5028
|
id: l,
|
|
5027
5029
|
role: "user",
|
|
5028
5030
|
status: "complete",
|
|
5029
5031
|
parts: [{
|
|
5030
5032
|
type: "text",
|
|
5031
5033
|
text: o
|
|
5032
|
-
}, ...c.map(
|
|
5034
|
+
}, ...c.map(Xr)],
|
|
5033
5035
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5034
5036
|
metadata: {
|
|
5035
5037
|
conversationId: e,
|
|
@@ -5056,14 +5058,14 @@ var Ei = class {
|
|
|
5056
5058
|
text: t,
|
|
5057
5059
|
text_elements: []
|
|
5058
5060
|
},
|
|
5059
|
-
...c.map(
|
|
5061
|
+
...c.map(Yr),
|
|
5060
5062
|
...s.map((e) => ({
|
|
5061
5063
|
type: "skill",
|
|
5062
5064
|
name: e.name,
|
|
5063
5065
|
path: e.path
|
|
5064
5066
|
}))
|
|
5065
5067
|
],
|
|
5066
|
-
...
|
|
5068
|
+
...Gr(this.host.snapshotForRuntime(i), a),
|
|
5067
5069
|
...a.outputSchema === void 0 ? {} : { outputSchema: a.outputSchema }
|
|
5068
5070
|
}), r = i.turnIds.includes(n.turn.id);
|
|
5069
5071
|
i.activeTurnId = n.turn.status === "inProgress" ? n.turn.id : null, i.turnIds.includes(n.turn.id) || i.turnIds.push(n.turn.id), this.host.patchConversationTurnCount(e, i.turnIds.length, "action");
|
|
@@ -5079,7 +5081,7 @@ var Ei = class {
|
|
|
5079
5081
|
busy: o,
|
|
5080
5082
|
turnStartPending: !1,
|
|
5081
5083
|
turns: G(i.turns, W(n.turn)),
|
|
5082
|
-
messages: o ?
|
|
5084
|
+
messages: o ? I(u, e, n.turn.id) : u
|
|
5083
5085
|
}), this.host.patchConversationStatus(e, o ? "active" : "idle", "action");
|
|
5084
5086
|
let d = u.find((e) => e.id === l);
|
|
5085
5087
|
d && this.host.emitEvent("action", {
|
|
@@ -5097,7 +5099,7 @@ var Ei = class {
|
|
|
5097
5099
|
throw this.host.patchRuntime(e, {
|
|
5098
5100
|
busy: !1,
|
|
5099
5101
|
turnStartPending: !1,
|
|
5100
|
-
error:
|
|
5102
|
+
error: O(t)
|
|
5101
5103
|
}), this.host.patchConversationStatus(e, "error", "action"), this.host.emitConversationActivity(e, "action"), t;
|
|
5102
5104
|
}
|
|
5103
5105
|
}
|
|
@@ -5109,7 +5111,7 @@ var Ei = class {
|
|
|
5109
5111
|
let i = await this.host.ensureThreadReady(e), a = t.trim(), o = r?.trim() || a;
|
|
5110
5112
|
if (!a) throw Error("Cannot steer with an empty message");
|
|
5111
5113
|
if (!i.activeTurnId) throw Error("There is no active turn to steer");
|
|
5112
|
-
let s =
|
|
5114
|
+
let s = Jr(n.attachments ?? []), c = _r(), l = {
|
|
5113
5115
|
id: c,
|
|
5114
5116
|
kind: "steer",
|
|
5115
5117
|
role: "user",
|
|
@@ -5117,7 +5119,7 @@ var Ei = class {
|
|
|
5117
5119
|
parts: [{
|
|
5118
5120
|
type: "text",
|
|
5119
5121
|
text: o
|
|
5120
|
-
}, ...s.map(
|
|
5122
|
+
}, ...s.map(Xr)],
|
|
5121
5123
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5122
5124
|
turnId: i.activeTurnId,
|
|
5123
5125
|
metadata: {
|
|
@@ -5128,7 +5130,7 @@ var Ei = class {
|
|
|
5128
5130
|
};
|
|
5129
5131
|
this.host.patchRuntime(e, {
|
|
5130
5132
|
error: null,
|
|
5131
|
-
messages:
|
|
5133
|
+
messages: I([...i.messages, l], e, i.activeTurnId, { forceSegment: !0 })
|
|
5132
5134
|
}), this.host.emitEvent("action", {
|
|
5133
5135
|
type: "message.appended",
|
|
5134
5136
|
conversationId: e,
|
|
@@ -5144,7 +5146,7 @@ var Ei = class {
|
|
|
5144
5146
|
type: "text",
|
|
5145
5147
|
text: a,
|
|
5146
5148
|
text_elements: []
|
|
5147
|
-
}, ...s.map(
|
|
5149
|
+
}, ...s.map(Yr)]
|
|
5148
5150
|
}), n = i.turnIds.includes(t.turnId);
|
|
5149
5151
|
i.activeTurnId = t.turnId, i.turnIds.includes(t.turnId) || i.turnIds.push(t.turnId), i.turns = G(i.turns, {
|
|
5150
5152
|
id: t.turnId,
|
|
@@ -5163,14 +5165,14 @@ var Ei = class {
|
|
|
5163
5165
|
turnId: t.turnId
|
|
5164
5166
|
}
|
|
5165
5167
|
} : e);
|
|
5166
|
-
this.host.patchRuntime(e, { messages: I(
|
|
5168
|
+
this.host.patchRuntime(e, { messages: R(I(r, e, t.turnId), e) }), n || this.host.emitEvent("action", {
|
|
5167
5169
|
type: "turn.started",
|
|
5168
5170
|
conversationId: e,
|
|
5169
5171
|
turnId: t.turnId,
|
|
5170
5172
|
payload: { startedAt: (/* @__PURE__ */ new Date()).toISOString() }
|
|
5171
5173
|
});
|
|
5172
5174
|
} catch (t) {
|
|
5173
|
-
throw this.host.patchRuntime(e, { error:
|
|
5175
|
+
throw this.host.patchRuntime(e, { error: O(t) }), t;
|
|
5174
5176
|
}
|
|
5175
5177
|
}
|
|
5176
5178
|
async answerAsyncQuestion(e, t, n) {
|
|
@@ -5223,7 +5225,7 @@ var Ei = class {
|
|
|
5223
5225
|
await this.sendPromptToThread(e, n.text, n.options);
|
|
5224
5226
|
} catch (r) {
|
|
5225
5227
|
this.host.patchRuntime(e, {
|
|
5226
|
-
error:
|
|
5228
|
+
error: O(r),
|
|
5227
5229
|
queuedPrompts: [n, ...t.queuedPrompts]
|
|
5228
5230
|
}), this.emitQueuedPrompts(e, "notification");
|
|
5229
5231
|
}
|
|
@@ -5241,7 +5243,7 @@ var Ei = class {
|
|
|
5241
5243
|
if (!e) throw Error("There is no active conversation");
|
|
5242
5244
|
return e;
|
|
5243
5245
|
}
|
|
5244
|
-
},
|
|
5246
|
+
}, Ni = 5, Pi = class {
|
|
5245
5247
|
client;
|
|
5246
5248
|
options;
|
|
5247
5249
|
catalog;
|
|
@@ -5279,9 +5281,9 @@ var Ei = class {
|
|
|
5279
5281
|
let i = this.host.getState(), a = e.approvalPreset ?? (e.approvalMode === void 0 && e.permissionMode === void 0 && i.approvalPreset && r.approvalPresets.includes(i.approvalPreset) ? i.approvalPreset : void 0), o = this.settings.threadStartSettings({
|
|
5280
5282
|
...e,
|
|
5281
5283
|
...a ? { approvalPreset: a } : {}
|
|
5282
|
-
}, r.approvalPresets), s = q(i.models, i.selectedModelId), c = e.model ?
|
|
5283
|
-
|
|
5284
|
-
let f = t.mcpServers === void 0 ? this.extensions.defaultMcpServers :
|
|
5284
|
+
}, r.approvalPresets), s = q(i.models, i.selectedModelId), c = e.model ? Pr(i.models, e.model) : s, l = c?.model, u = e.reasoningEffort ?? (c?.id === s?.id ? i.selectedReasoningEffort : c ? J(c) : null) ?? void 0, d = e.serviceTier === void 0 ? c?.id === s?.id ? i.selectedServiceTier ?? null : c?.defaultServiceTier ?? null : e.serviceTier;
|
|
5285
|
+
Fr(c, u), Y(c, d);
|
|
5286
|
+
let f = t.mcpServers === void 0 ? this.extensions.defaultMcpServers : hi(t.mcpServers), p = await this.extensions.conversationExtension({
|
|
5285
5287
|
operation: "start",
|
|
5286
5288
|
conversationId: null,
|
|
5287
5289
|
cwd: n,
|
|
@@ -5298,11 +5300,11 @@ var Ei = class {
|
|
|
5298
5300
|
...d === void 0 ? {} : { serviceTier: d },
|
|
5299
5301
|
...e.threadSource === void 0 ? {} : { threadSource: e.threadSource },
|
|
5300
5302
|
serviceName: "codex_app_sdk"
|
|
5301
|
-
}), h =
|
|
5303
|
+
}), h = Vr(m, i.models, i);
|
|
5302
5304
|
u && (await this.client.request("thread/settings/update", {
|
|
5303
5305
|
threadId: m.thread.id,
|
|
5304
5306
|
effort: u,
|
|
5305
|
-
...c ? { collaborationMode:
|
|
5307
|
+
...c ? { collaborationMode: Wr(i.planMode, c.model, u) } : {}
|
|
5306
5308
|
}), h.selectedReasoningEffort = u), d !== void 0 && (h.selectedServiceTier = d), c && (h.selectedModelId = c.id), a && (h.approvalPreset = a);
|
|
5307
5309
|
let g = this.host.createRuntime(m.thread.id, {
|
|
5308
5310
|
hydrated: !0,
|
|
@@ -5386,7 +5388,7 @@ var Ei = class {
|
|
|
5386
5388
|
} catch (t) {
|
|
5387
5389
|
throw this.host.patchRuntime(e, {
|
|
5388
5390
|
historyLoading: !1,
|
|
5389
|
-
error:
|
|
5391
|
+
error: O(t)
|
|
5390
5392
|
}), t;
|
|
5391
5393
|
}
|
|
5392
5394
|
}
|
|
@@ -5396,7 +5398,7 @@ var Ei = class {
|
|
|
5396
5398
|
...n
|
|
5397
5399
|
}, a = {
|
|
5398
5400
|
...i,
|
|
5399
|
-
mcpServers: i.mcpServers === void 0 ? this.extensions.defaultMcpServers :
|
|
5401
|
+
mcpServers: i.mcpServers === void 0 ? this.extensions.defaultMcpServers : hi(i.mcpServers)
|
|
5400
5402
|
};
|
|
5401
5403
|
this.hostOptionsByThread.set(e, a);
|
|
5402
5404
|
let o = await this.extensions.conversationExtension({
|
|
@@ -5414,7 +5416,7 @@ var Ei = class {
|
|
|
5414
5416
|
threadId: e,
|
|
5415
5417
|
excludeTurns: !0,
|
|
5416
5418
|
initialTurnsPage: {
|
|
5417
|
-
limit:
|
|
5419
|
+
limit: Ni,
|
|
5418
5420
|
sortDirection: "desc",
|
|
5419
5421
|
itemsView: "full"
|
|
5420
5422
|
},
|
|
@@ -5427,7 +5429,7 @@ var Ei = class {
|
|
|
5427
5429
|
let i = t.initialTurnsPage ?? await this.client.request("thread/turns/list", {
|
|
5428
5430
|
threadId: t.thread.id,
|
|
5429
5431
|
cursor: null,
|
|
5430
|
-
limit:
|
|
5432
|
+
limit: Ni,
|
|
5431
5433
|
sortDirection: "desc",
|
|
5432
5434
|
itemsView: "full"
|
|
5433
5435
|
}), d = [...i.data].reverse(), f = t.cwd ?? t.thread.cwd ?? a.cwd, p = await this.catalog.loadConversationCatalogs(f), m = s.turns.filter((e) => c.get(e.id) !== e), h = s.threadStatus !== u && s.threadStatus ? s.threadStatus : $(t.thread.status), g = d.map((e) => h.type === "idle" && e.status === "inProgress" ? {
|
|
@@ -5435,12 +5437,12 @@ var Ei = class {
|
|
|
5435
5437
|
status: "interrupted"
|
|
5436
5438
|
} : e), _ = new Map(g.map((e) => [e.id, W(e)]));
|
|
5437
5439
|
for (let e of m) _.set(e.id, e);
|
|
5438
|
-
let v = m.length > 0 ? s.activeTurnId : h.type === "active" ?
|
|
5440
|
+
let v = m.length > 0 ? s.activeTurnId : h.type === "active" ? yn(d) : null, y = Rn(s.messages, Ln({
|
|
5439
5441
|
...t.thread,
|
|
5440
5442
|
turns: g
|
|
5441
5443
|
})), b = new Map(y.map((e) => [e.id, e]));
|
|
5442
5444
|
for (let e of s.messages) l.get(e.id) !== e && b.set(e.id, e);
|
|
5443
|
-
let
|
|
5445
|
+
let x = v ? I([...b.values()], t.thread.id, v) : [...b.values()], S = this.host.createRuntime(t.thread.id, {
|
|
5444
5446
|
hydrated: !0,
|
|
5445
5447
|
historyMode: t.thread.historyMode ?? "legacy",
|
|
5446
5448
|
loadingStrategy: a.loadingStrategy ?? this.options.loadingStrategy ?? "lazy",
|
|
@@ -5453,27 +5455,27 @@ var Ei = class {
|
|
|
5453
5455
|
activeTurnId: v,
|
|
5454
5456
|
turns: [..._.values()],
|
|
5455
5457
|
turnIds: [..._.keys()],
|
|
5456
|
-
messages:
|
|
5458
|
+
messages: x,
|
|
5457
5459
|
busy: m.length > 0 ? s.busy : !!v || h.type === "active",
|
|
5458
5460
|
goal: n ? { ...n } : null,
|
|
5459
5461
|
threadStatus: h,
|
|
5460
5462
|
...p,
|
|
5461
|
-
...
|
|
5462
|
-
}),
|
|
5463
|
+
...Vr(t, this.host.getState().models, this.host.snapshotForRuntime(s))
|
|
5464
|
+
}), C = {
|
|
5463
5465
|
...Z(t.thread),
|
|
5464
5466
|
turnCount: d.length
|
|
5465
|
-
},
|
|
5467
|
+
}, ee = this.host.getState();
|
|
5466
5468
|
return this.host.patch({
|
|
5467
|
-
conversations: Q(
|
|
5468
|
-
...
|
|
5469
|
-
}), this.host.emitSummaryUpserted(
|
|
5469
|
+
conversations: Q(ee.conversations, C),
|
|
5470
|
+
...ee.activeConversationId === t.thread.id ? this.host.runtimeProjection(S) : {}
|
|
5471
|
+
}), this.host.emitSummaryUpserted(C, "resumed", "action"), this.host.emitHistoryReplaced(t.thread.id, r, "action"), this.emitConversationState(t.thread.id), S.loadingStrategy === "eager" && i.nextCursor !== null && this.conversations.hydrateCompleteHistory(t.thread.id, {
|
|
5470
5472
|
cursor: i.nextCursor,
|
|
5471
5473
|
initialPageLoaded: !0
|
|
5472
5474
|
}).catch(() => void 0), this.host.getSnapshot();
|
|
5473
5475
|
} catch (t) {
|
|
5474
5476
|
throw this.host.patchRuntime(e, {
|
|
5475
5477
|
historyLoading: !1,
|
|
5476
|
-
error:
|
|
5478
|
+
error: O(t)
|
|
5477
5479
|
}), t;
|
|
5478
5480
|
}
|
|
5479
5481
|
}
|
|
@@ -5487,7 +5489,7 @@ var Ei = class {
|
|
|
5487
5489
|
threadStatus: structuredClone(t.threadStatus)
|
|
5488
5490
|
};
|
|
5489
5491
|
}
|
|
5490
|
-
},
|
|
5492
|
+
}, Fi = class {
|
|
5491
5493
|
authentication;
|
|
5492
5494
|
approvals;
|
|
5493
5495
|
catalog;
|
|
@@ -5522,7 +5524,7 @@ var Ei = class {
|
|
|
5522
5524
|
let a = this.host.getState();
|
|
5523
5525
|
this.host.patch({ conversations: a.conversations.map((e) => e.id === t ? {
|
|
5524
5526
|
...e,
|
|
5525
|
-
status:
|
|
5527
|
+
status: ti(n)
|
|
5526
5528
|
} : e) });
|
|
5527
5529
|
let o = this.host.getState().conversations.find((e) => e.id === t);
|
|
5528
5530
|
o && this.host.emitSummaryUpserted(o, "updated", "notification"), this.host.emitConversationActivity(t, "notification"), n.type === "idle" && this.host.sendNextQueuedPrompt(t);
|
|
@@ -5534,7 +5536,7 @@ var Ei = class {
|
|
|
5534
5536
|
return;
|
|
5535
5537
|
case "thread/unarchived":
|
|
5536
5538
|
this.conversations.load().catch((e) => {
|
|
5537
|
-
this.host.patch({ error:
|
|
5539
|
+
this.host.patch({ error: O(e) });
|
|
5538
5540
|
});
|
|
5539
5541
|
return;
|
|
5540
5542
|
case "thread/closed": {
|
|
@@ -5564,12 +5566,12 @@ var Ei = class {
|
|
|
5564
5566
|
return;
|
|
5565
5567
|
}
|
|
5566
5568
|
case "thread/settings/updated": {
|
|
5567
|
-
let t = this.host.requireRuntime(e.params.threadId), n = this.host.getState(), r =
|
|
5569
|
+
let t = this.host.requireRuntime(e.params.threadId), n = this.host.getState(), r = Hr(e.params.threadSettings, n.models, this.host.snapshotForRuntime(t)), i = t.approvalPreset !== r.approvalPreset || t.selectedModelId !== r.selectedModelId || t.selectedReasoningEffort !== r.selectedReasoningEffort || t.selectedServiceTier !== r.selectedServiceTier || t.planMode !== r.planMode;
|
|
5568
5570
|
this.host.patchRuntime(e.params.threadId, r), i && this.host.emitConversationSettings(e.params.threadId, "notification");
|
|
5569
5571
|
return;
|
|
5570
5572
|
}
|
|
5571
5573
|
case "thread/goal/updated":
|
|
5572
|
-
if (
|
|
5574
|
+
if (gr(this.host.requireRuntime(e.params.threadId).goal, e.params.goal)) return;
|
|
5573
5575
|
this.host.patchRuntime(e.params.threadId, { goal: { ...e.params.goal } }), this.host.emitEvent("notification", {
|
|
5574
5576
|
type: "conversation.goalChanged",
|
|
5575
5577
|
conversationId: e.params.threadId,
|
|
@@ -5586,7 +5588,7 @@ var Ei = class {
|
|
|
5586
5588
|
});
|
|
5587
5589
|
return;
|
|
5588
5590
|
case "thread/tokenUsage/updated": {
|
|
5589
|
-
let t =
|
|
5591
|
+
let t = ei(e.params.tokenUsage);
|
|
5590
5592
|
this.host.patchRuntime(e.params.threadId, { contextUsage: t }), this.host.emitEvent("notification", {
|
|
5591
5593
|
type: "conversation.contextUsageChanged",
|
|
5592
5594
|
conversationId: e.params.threadId,
|
|
@@ -5603,7 +5605,7 @@ var Ei = class {
|
|
|
5603
5605
|
error: null,
|
|
5604
5606
|
turnGitDiff: null,
|
|
5605
5607
|
turns: G(t.turns, W(e.params.turn)),
|
|
5606
|
-
messages:
|
|
5608
|
+
messages: I(t.messages, e.params.threadId, e.params.turn.id, { createdAt: U(e.params.turn.startedAt) })
|
|
5607
5609
|
}), this.host.patchConversationStatus(e.params.threadId, "active"), n || this.host.emitEvent("notification", {
|
|
5608
5610
|
type: "turn.started",
|
|
5609
5611
|
conversationId: e.params.threadId,
|
|
@@ -5624,13 +5626,13 @@ var Ei = class {
|
|
|
5624
5626
|
return;
|
|
5625
5627
|
case "item/commandExecution/outputDelta":
|
|
5626
5628
|
if (!this.items.isForwardingCommandOutput(e.params.threadId, e.params.itemId)) return;
|
|
5627
|
-
this.items.applyToolUpdate(e.params.threadId, e.params.turnId,
|
|
5629
|
+
this.items.applyToolUpdate(e.params.threadId, e.params.turnId, Ht(e.params.itemId, e.params.delta));
|
|
5628
5630
|
return;
|
|
5629
5631
|
case "item/fileChange/patchUpdated":
|
|
5630
|
-
this.items.applyToolUpdate(e.params.threadId, e.params.turnId,
|
|
5632
|
+
this.items.applyToolUpdate(e.params.threadId, e.params.turnId, Ut(e.params.itemId, e.params.changes));
|
|
5631
5633
|
return;
|
|
5632
5634
|
case "item/mcpToolCall/progress":
|
|
5633
|
-
this.items.applyToolUpdate(e.params.threadId, e.params.turnId,
|
|
5635
|
+
this.items.applyToolUpdate(e.params.threadId, e.params.turnId, Wt(e.params.itemId, e.params.message));
|
|
5634
5636
|
return;
|
|
5635
5637
|
case "rawResponseItem/completed":
|
|
5636
5638
|
this.items.applyRawResponseItem(e.params);
|
|
@@ -5644,7 +5646,7 @@ var Ei = class {
|
|
|
5644
5646
|
return;
|
|
5645
5647
|
}
|
|
5646
5648
|
case "turn/diff/updated": {
|
|
5647
|
-
let t =
|
|
5649
|
+
let t = sn(e.params.diff);
|
|
5648
5650
|
this.host.patchRuntime(e.params.threadId, { turnGitDiff: {
|
|
5649
5651
|
turnId: e.params.turnId,
|
|
5650
5652
|
addedLines: t.addedLines,
|
|
@@ -5660,7 +5662,7 @@ var Ei = class {
|
|
|
5660
5662
|
}
|
|
5661
5663
|
case "thread/compacted": {
|
|
5662
5664
|
let t = this.host.requireRuntime(e.params.threadId);
|
|
5663
|
-
this.host.patchRuntime(e.params.threadId, { messages:
|
|
5665
|
+
this.host.patchRuntime(e.params.threadId, { messages: kn(t.messages, e.params.threadId, e.params.turnId, "complete") });
|
|
5664
5666
|
let n = this.host.requireRuntime(e.params.threadId).messages.find((t) => t.kind === "compaction" && t.metadata?.turnId === e.params.turnId);
|
|
5665
5667
|
this.host.emitEvent("notification", {
|
|
5666
5668
|
type: "context.compactionCompleted",
|
|
@@ -5689,7 +5691,7 @@ var Ei = class {
|
|
|
5689
5691
|
durationMs: null
|
|
5690
5692
|
},
|
|
5691
5693
|
status: e.params.willRetry ? "inProgress" : "failed",
|
|
5692
|
-
error:
|
|
5694
|
+
error: hr(e.params.error),
|
|
5693
5695
|
willRetry: e.params.willRetry
|
|
5694
5696
|
}),
|
|
5695
5697
|
...n ? {
|
|
@@ -5701,7 +5703,7 @@ var Ei = class {
|
|
|
5701
5703
|
conversationId: e.params.threadId,
|
|
5702
5704
|
turnId: e.params.turnId,
|
|
5703
5705
|
payload: {
|
|
5704
|
-
error:
|
|
5706
|
+
error: hr(e.params.error),
|
|
5705
5707
|
willRetry: e.params.willRetry
|
|
5706
5708
|
}
|
|
5707
5709
|
}), this.host.emitConversationActivity(e.params.threadId, "notification");
|
|
@@ -5709,14 +5711,14 @@ var Ei = class {
|
|
|
5709
5711
|
}
|
|
5710
5712
|
case "account/rateLimits/updated": {
|
|
5711
5713
|
let t = this.host.getState();
|
|
5712
|
-
this.host.patch({ rateLimits:
|
|
5714
|
+
this.host.patch({ rateLimits: ii(t.rateLimits, e.params.rateLimits) }), this.host.emitEvent("notification", {
|
|
5713
5715
|
type: "rateLimits.changed",
|
|
5714
5716
|
payload: { rateLimits: structuredClone(this.host.getState().rateLimits) }
|
|
5715
5717
|
});
|
|
5716
5718
|
return;
|
|
5717
5719
|
}
|
|
5718
5720
|
case "account/updated":
|
|
5719
|
-
this.authentication.refresh("notification").catch((e) => this.host.patch({ error:
|
|
5721
|
+
this.authentication.refresh("notification").catch((e) => this.host.patch({ error: O(e) }));
|
|
5720
5722
|
return;
|
|
5721
5723
|
case "account/login/completed":
|
|
5722
5724
|
this.authentication.handleLoginCompleted(e.params);
|
|
@@ -5780,7 +5782,7 @@ var Ei = class {
|
|
|
5780
5782
|
this.host.emitEvent("notification", {
|
|
5781
5783
|
type: "realtime.audioDelta",
|
|
5782
5784
|
conversationId: e.params.threadId,
|
|
5783
|
-
payload: { audio:
|
|
5785
|
+
payload: { audio: ft(e.params.audio) }
|
|
5784
5786
|
});
|
|
5785
5787
|
return;
|
|
5786
5788
|
case "thread/realtime/sdp":
|
|
@@ -5848,7 +5850,7 @@ var Ei = class {
|
|
|
5848
5850
|
default: return this.host.unknownNotification(e);
|
|
5849
5851
|
}
|
|
5850
5852
|
}
|
|
5851
|
-
},
|
|
5853
|
+
}, Ii = class {
|
|
5852
5854
|
approvals;
|
|
5853
5855
|
clientRequests;
|
|
5854
5856
|
host;
|
|
@@ -5872,14 +5874,14 @@ var Ei = class {
|
|
|
5872
5874
|
create(e, t = {}) {
|
|
5873
5875
|
let n = this.runtimes.get(e);
|
|
5874
5876
|
if (n) return Object.assign(n, t), n;
|
|
5875
|
-
let r =
|
|
5877
|
+
let r = vt(e, this.host.getState(), t);
|
|
5876
5878
|
return this.runtimes.set(e, r), r;
|
|
5877
5879
|
}
|
|
5878
5880
|
require(e) {
|
|
5879
5881
|
return this.runtimes.get(e) ?? this.create(e);
|
|
5880
5882
|
}
|
|
5881
5883
|
projection(e) {
|
|
5882
|
-
return
|
|
5884
|
+
return yt(e, this.approvals.approvalsForThread(e.threadId), this.clientRequests.requestsForThread(e.threadId));
|
|
5883
5885
|
}
|
|
5884
5886
|
snapshot(e) {
|
|
5885
5887
|
return {
|
|
@@ -5909,7 +5911,7 @@ var Ei = class {
|
|
|
5909
5911
|
conversationId: e,
|
|
5910
5912
|
payload: {
|
|
5911
5913
|
historyLoading: n.historyLoading,
|
|
5912
|
-
historyState:
|
|
5914
|
+
historyState: zi(n),
|
|
5913
5915
|
error: n.error
|
|
5914
5916
|
}
|
|
5915
5917
|
});
|
|
@@ -6003,7 +6005,7 @@ var Ei = class {
|
|
|
6003
6005
|
reason: t,
|
|
6004
6006
|
messages: structuredClone(r.messages),
|
|
6005
6007
|
threadStatus: structuredClone(r.threadStatus),
|
|
6006
|
-
state:
|
|
6008
|
+
state: Li(r)
|
|
6007
6009
|
}
|
|
6008
6010
|
});
|
|
6009
6011
|
}
|
|
@@ -6015,7 +6017,7 @@ var Ei = class {
|
|
|
6015
6017
|
conversationId: e,
|
|
6016
6018
|
payload: {
|
|
6017
6019
|
messages: structuredClone(t.map((e) => r.get(e.id) ?? e)),
|
|
6018
|
-
state:
|
|
6020
|
+
state: Ri(this.require(e))
|
|
6019
6021
|
}
|
|
6020
6022
|
});
|
|
6021
6023
|
}
|
|
@@ -6057,7 +6059,7 @@ var Ei = class {
|
|
|
6057
6059
|
i && this.emitSummaryUpserted(i, "updated", n);
|
|
6058
6060
|
}
|
|
6059
6061
|
};
|
|
6060
|
-
function
|
|
6062
|
+
function Li(e) {
|
|
6061
6063
|
return structuredClone({
|
|
6062
6064
|
activeTurnId: e.activeTurnId,
|
|
6063
6065
|
answeredClientRequestIds: e.answeredClientRequestIds,
|
|
@@ -6066,21 +6068,21 @@ function ji(e) {
|
|
|
6066
6068
|
error: e.error,
|
|
6067
6069
|
executionPlan: e.executionPlan,
|
|
6068
6070
|
historyLoading: e.historyLoading,
|
|
6069
|
-
historyState:
|
|
6071
|
+
historyState: zi(e),
|
|
6070
6072
|
turnGitDiff: e.turnGitDiff,
|
|
6071
6073
|
turnIds: e.turnIds,
|
|
6072
6074
|
turns: e.turns
|
|
6073
6075
|
});
|
|
6074
6076
|
}
|
|
6075
|
-
function
|
|
6077
|
+
function Ri(e) {
|
|
6076
6078
|
return structuredClone({
|
|
6077
6079
|
historyLoading: e.historyLoading,
|
|
6078
|
-
historyState:
|
|
6080
|
+
historyState: zi(e),
|
|
6079
6081
|
turnIds: e.turnIds,
|
|
6080
6082
|
turns: e.turns
|
|
6081
6083
|
});
|
|
6082
6084
|
}
|
|
6083
|
-
function
|
|
6085
|
+
function zi(e) {
|
|
6084
6086
|
return {
|
|
6085
6087
|
loadingStrategy: e.loadingStrategy,
|
|
6086
6088
|
hasOlder: e.historyHasOlder,
|
|
@@ -6090,7 +6092,7 @@ function Ni(e) {
|
|
|
6090
6092
|
}
|
|
6091
6093
|
//#endregion
|
|
6092
6094
|
//#region src/node/codex-surface-connection-controller.ts
|
|
6093
|
-
var
|
|
6095
|
+
var Bi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_request_user_input"]), Vi = class {
|
|
6094
6096
|
client;
|
|
6095
6097
|
options;
|
|
6096
6098
|
authentication;
|
|
@@ -6137,7 +6139,7 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6137
6139
|
} catch (e) {
|
|
6138
6140
|
throw this.host.patch({
|
|
6139
6141
|
status: "error",
|
|
6140
|
-
error:
|
|
6142
|
+
error: O(e)
|
|
6141
6143
|
}), this.host.emitSurfaceStatus("lifecycle"), e;
|
|
6142
6144
|
} finally {
|
|
6143
6145
|
this.connectPromise = null;
|
|
@@ -6153,7 +6155,7 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6153
6155
|
limit: 100,
|
|
6154
6156
|
threadId: null
|
|
6155
6157
|
});
|
|
6156
|
-
for (let e of n.data)
|
|
6158
|
+
for (let e of n.data) Bi.has(e.name) && !e.enabled && (t[e.name] = !0);
|
|
6157
6159
|
e = n.nextCursor;
|
|
6158
6160
|
} while (e);
|
|
6159
6161
|
Object.keys(t).length > 0 && await this.client.request("experimentalFeature/enablement/set", { enablement: t });
|
|
@@ -6170,7 +6172,7 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6170
6172
|
}
|
|
6171
6173
|
}
|
|
6172
6174
|
bootstrapSurfaceData(e = !1) {
|
|
6173
|
-
let t =
|
|
6175
|
+
let t = St(this.host.getState().authentication);
|
|
6174
6176
|
if (!e && this.bootstrappedAuthenticationKey === t) return Promise.resolve();
|
|
6175
6177
|
if (this.surfaceBootstrapPromise) return this.surfaceBootstrapPromise.then(() => this.bootstrapSurfaceData(e));
|
|
6176
6178
|
let n = (async () => {
|
|
@@ -6287,7 +6289,7 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6287
6289
|
error: null
|
|
6288
6290
|
});
|
|
6289
6291
|
}
|
|
6290
|
-
},
|
|
6292
|
+
}, Hi = 5, Ui = class {
|
|
6291
6293
|
client;
|
|
6292
6294
|
loadingStrategy;
|
|
6293
6295
|
catalog;
|
|
@@ -6299,9 +6301,9 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6299
6301
|
async fork(e, t = {}, n = {}, r = {}) {
|
|
6300
6302
|
let i = this.host.requireRuntime(e);
|
|
6301
6303
|
if ((i.busy || i.activeTurnId) && !r.beforeTurnId && (!r.lastTurnId || r.lastTurnId === i.activeTurnId)) throw Error("Cannot fork a conversation while its current turn is still active");
|
|
6302
|
-
let a = t.cwd ?? i.cwd ?? n.cwd, o = await this.catalog.loadConversationCatalogs(a ?? void 0), s = this.host.getState(), c = t.model ?
|
|
6303
|
-
|
|
6304
|
-
let l = n.mcpServers === void 0 ? this.extensions.defaultMcpServers :
|
|
6304
|
+
let a = t.cwd ?? i.cwd ?? n.cwd, o = await this.catalog.loadConversationCatalogs(a ?? void 0), s = this.host.getState(), c = t.model ? Pr(s.models, t.model) : q(s.models, i.selectedModelId);
|
|
6305
|
+
Fr(c, t.reasoningEffort), Y(c, t.serviceTier);
|
|
6306
|
+
let l = n.mcpServers === void 0 ? this.extensions.defaultMcpServers : hi(n.mcpServers), u = await this.extensions.conversationExtension({
|
|
6305
6307
|
operation: "start",
|
|
6306
6308
|
conversationId: null,
|
|
6307
6309
|
cwd: a ?? void 0,
|
|
@@ -6319,24 +6321,24 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6319
6321
|
...u.baseInstructions === void 0 ? {} : { baseInstructions: u.baseInstructions },
|
|
6320
6322
|
...u.developerInstructions === void 0 ? {} : { developerInstructions: u.developerInstructions },
|
|
6321
6323
|
...u.config === void 0 ? {} : { config: u.config },
|
|
6322
|
-
...
|
|
6324
|
+
...Wi(t, o.approvalPresets)
|
|
6323
6325
|
});
|
|
6324
6326
|
if (!d.thread.id || d.thread.id === e) throw Error(`Codex thread/fork returned an invalid new thread id '${d.thread.id}'`);
|
|
6325
6327
|
t.reasoningEffort && await this.client.request("thread/settings/update", {
|
|
6326
6328
|
threadId: d.thread.id,
|
|
6327
6329
|
effort: t.reasoningEffort,
|
|
6328
|
-
...c ? { collaborationMode:
|
|
6330
|
+
...c ? { collaborationMode: Wr(i.planMode, c.model, t.reasoningEffort) } : {}
|
|
6329
6331
|
});
|
|
6330
6332
|
let [f, p] = await Promise.all([this.client.request("thread/turns/list", {
|
|
6331
6333
|
threadId: d.thread.id,
|
|
6332
6334
|
cursor: null,
|
|
6333
|
-
limit:
|
|
6335
|
+
limit: Hi,
|
|
6334
6336
|
sortDirection: "desc",
|
|
6335
6337
|
itemsView: "full"
|
|
6336
|
-
}), this.client.request("thread/goal/get", { threadId: d.thread.id }).then((e) => e.goal).catch(() => null)]), m = [...f.data].reverse(), h =
|
|
6338
|
+
}), this.client.request("thread/goal/get", { threadId: d.thread.id }).then((e) => e.goal).catch(() => null)]), m = [...f.data].reverse(), h = yn(m), g = Ln({
|
|
6337
6339
|
...d.thread,
|
|
6338
6340
|
turns: m
|
|
6339
|
-
}), _ = h ?
|
|
6341
|
+
}), _ = h ? I(g, d.thread.id, h) : g, v = n.loadingStrategy ?? this.loadingStrategy ?? "lazy", y = this.host.createRuntime(d.thread.id, {
|
|
6340
6342
|
hydrated: !0,
|
|
6341
6343
|
historyMode: d.thread.historyMode ?? "legacy",
|
|
6342
6344
|
loadingStrategy: v,
|
|
@@ -6353,7 +6355,7 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6353
6355
|
goal: p ? { ...p } : null,
|
|
6354
6356
|
threadStatus: $(d.thread.status),
|
|
6355
6357
|
...o,
|
|
6356
|
-
...
|
|
6358
|
+
...Vr(d, s.models, this.host.snapshotForRuntime(i))
|
|
6357
6359
|
});
|
|
6358
6360
|
t.reasoningEffort && (y.selectedReasoningEffort = t.reasoningEffort), t.serviceTier !== void 0 && (y.selectedServiceTier = t.serviceTier), t.model && c && (y.selectedModelId = c.id), this.host.rememberHostOptions(d.thread.id, {
|
|
6359
6361
|
...n,
|
|
@@ -6372,10 +6374,10 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6372
6374
|
return this.fork(e, n, r, { lastTurnId: t });
|
|
6373
6375
|
}
|
|
6374
6376
|
};
|
|
6375
|
-
function
|
|
6377
|
+
function Wi(e, t) {
|
|
6376
6378
|
if (e.approvalPreset) {
|
|
6377
6379
|
if (!t.includes(e.approvalPreset)) throw Error(`Approval preset '${e.approvalPreset}' is not available`);
|
|
6378
|
-
return
|
|
6380
|
+
return Rr(e.approvalPreset);
|
|
6379
6381
|
}
|
|
6380
6382
|
return {
|
|
6381
6383
|
...e.approvalMode === void 0 ? {} : { approvalPolicy: e.approvalMode === "ask" ? "on-request" : "never" },
|
|
@@ -6384,27 +6386,27 @@ function Ri(e, t) {
|
|
|
6384
6386
|
}
|
|
6385
6387
|
//#endregion
|
|
6386
6388
|
//#region src/node/codex-markdown-images.ts
|
|
6387
|
-
var
|
|
6389
|
+
var Gi = /(?<!\[)!\[([^\]]*)\]\(([^)\s]+)(?:\s+["']([^"']*)["'])?\)/g, Ki = /* @__PURE__ */ new Set([
|
|
6388
6390
|
".avif",
|
|
6389
6391
|
".gif",
|
|
6390
6392
|
".jpeg",
|
|
6391
6393
|
".jpg",
|
|
6392
6394
|
".png",
|
|
6393
6395
|
".webp"
|
|
6394
|
-
]),
|
|
6396
|
+
]), qi = class {
|
|
6395
6397
|
client;
|
|
6396
6398
|
constructor(e) {
|
|
6397
6399
|
this.client = e;
|
|
6398
6400
|
}
|
|
6399
6401
|
async hydrate(e, t) {
|
|
6400
|
-
let n =
|
|
6401
|
-
return
|
|
6402
|
+
let n = Xi(e);
|
|
6403
|
+
return Yi(e, (await Promise.all(Array.from(e.matchAll(Gi), async (e) => {
|
|
6402
6404
|
let r = e.index ?? 0;
|
|
6403
|
-
if (
|
|
6404
|
-
let i = e[2], a =
|
|
6405
|
+
if (Zi(r, n)) return null;
|
|
6406
|
+
let i = e[2], a = Ji(i, t);
|
|
6405
6407
|
if (!a) return null;
|
|
6406
6408
|
try {
|
|
6407
|
-
let t =
|
|
6409
|
+
let t = Zn((await this.client.request("fs/readFile", { path: a })).dataBase64);
|
|
6408
6410
|
if (!t) return null;
|
|
6409
6411
|
let n = e[0].indexOf("](") + 2;
|
|
6410
6412
|
return {
|
|
@@ -6418,12 +6420,12 @@ var zi = /(?<!\[)!\[([^\]]*)\]\(([^)\s]+)(?:\s+["']([^"']*)["'])?\)/g, Bi = /* @
|
|
|
6418
6420
|
}))).filter((e) => e !== null));
|
|
6419
6421
|
}
|
|
6420
6422
|
};
|
|
6421
|
-
function
|
|
6423
|
+
function Ji(e, t) {
|
|
6422
6424
|
let n = e.trim();
|
|
6423
6425
|
if (!n || /[\u0000-\u001f\u007f]/.test(n)) return null;
|
|
6424
6426
|
let r;
|
|
6425
6427
|
if (n.startsWith("file://")) try {
|
|
6426
|
-
r =
|
|
6428
|
+
r = ne(n);
|
|
6427
6429
|
} catch {
|
|
6428
6430
|
return null;
|
|
6429
6431
|
}
|
|
@@ -6433,18 +6435,18 @@ function Hi(e, t) {
|
|
|
6433
6435
|
} catch {
|
|
6434
6436
|
return null;
|
|
6435
6437
|
}
|
|
6436
|
-
if (!
|
|
6437
|
-
if (
|
|
6438
|
-
if (!t || !
|
|
6439
|
-
let i =
|
|
6440
|
-
return a === ".." || a.startsWith(`..${
|
|
6438
|
+
if (!Ki.has(_(r).toLowerCase())) return null;
|
|
6439
|
+
if (v(r)) return r;
|
|
6440
|
+
if (!t || !v(t)) return null;
|
|
6441
|
+
let i = x(t, r), a = b(t, i);
|
|
6442
|
+
return a === ".." || a.startsWith(`..${S}`) || v(a) ? null : i;
|
|
6441
6443
|
}
|
|
6442
|
-
function
|
|
6444
|
+
function Yi(e, t) {
|
|
6443
6445
|
let n = e;
|
|
6444
6446
|
for (let e of t.sort((e, t) => t.start - e.start)) n = `${n.slice(0, e.start)}${e.value}${n.slice(e.end)}`;
|
|
6445
6447
|
return n;
|
|
6446
6448
|
}
|
|
6447
|
-
function
|
|
6449
|
+
function Xi(e) {
|
|
6448
6450
|
let t = [], n = /(^|\n)(```|~~~)/g, r;
|
|
6449
6451
|
for (; (r = n.exec(e)) !== null;) {
|
|
6450
6452
|
let i = r[2], a = r[1], o = r.index + a.length, s = RegExp(`(^|\\n)${i}`, "g");
|
|
@@ -6465,15 +6467,15 @@ function Wi(e) {
|
|
|
6465
6467
|
}
|
|
6466
6468
|
return t;
|
|
6467
6469
|
}
|
|
6468
|
-
function
|
|
6470
|
+
function Zi(e, t) {
|
|
6469
6471
|
return t.some((t) => e >= t.start && e <= t.end);
|
|
6470
6472
|
}
|
|
6471
|
-
var
|
|
6472
|
-
async function
|
|
6473
|
-
let n =
|
|
6473
|
+
var Qi = /<context>[\s\S]*?<\/context>\s*/g, $i = /<in-app-browser-context(?:\s[^>]*)?>[\s\S]*?<\/in-app-browser-context>\s*/g, ea = /^[ \t]*## My request for Codex:[ \t]*$/m;
|
|
6474
|
+
async function ta(e, t) {
|
|
6475
|
+
let n = D(t);
|
|
6474
6476
|
return {
|
|
6475
6477
|
conversationId: n,
|
|
6476
|
-
prompts:
|
|
6478
|
+
prompts: na((await e.request("thread/turns/list", {
|
|
6477
6479
|
threadId: n,
|
|
6478
6480
|
cursor: null,
|
|
6479
6481
|
limit: 100,
|
|
@@ -6482,20 +6484,20 @@ async function Yi(e, t) {
|
|
|
6482
6484
|
})).data)
|
|
6483
6485
|
};
|
|
6484
6486
|
}
|
|
6485
|
-
function
|
|
6487
|
+
function na(e) {
|
|
6486
6488
|
return [...e].reverse().flatMap((e) => e.items.flatMap((e) => {
|
|
6487
6489
|
if (e.type !== "userMessage") return [];
|
|
6488
|
-
let t =
|
|
6490
|
+
let t = ra(e.content.flatMap((e) => e.type === "text" ? [e.text] : []).join(""));
|
|
6489
6491
|
return t && t !== "(no user instructions)" ? [t] : [];
|
|
6490
6492
|
}));
|
|
6491
6493
|
}
|
|
6492
|
-
function
|
|
6493
|
-
let t = e.replace(
|
|
6494
|
-
return (n === t ? n : n.replace(
|
|
6494
|
+
function ra(e) {
|
|
6495
|
+
let t = e.replace(Qi, ""), n = t.replace($i, "");
|
|
6496
|
+
return (n === t ? n : n.replace(ea, "")).trim();
|
|
6495
6497
|
}
|
|
6496
6498
|
//#endregion
|
|
6497
6499
|
//#region src/node/codex-surface-text-generation-controller.ts
|
|
6498
|
-
var
|
|
6500
|
+
var ia = 12e4, aa = class {
|
|
6499
6501
|
client;
|
|
6500
6502
|
defaultCwd;
|
|
6501
6503
|
host;
|
|
@@ -6506,7 +6508,7 @@ var Qi = 12e4, $i = class {
|
|
|
6506
6508
|
}
|
|
6507
6509
|
handleNotification(e) {
|
|
6508
6510
|
e.method === "thread/started" && e.params.thread.ephemeral && this.hiddenThreadIds.add(e.params.thread.id);
|
|
6509
|
-
let t =
|
|
6511
|
+
let t = la(e);
|
|
6510
6512
|
if (!t || !this.hiddenThreadIds.has(t)) return !1;
|
|
6511
6513
|
let n = this.pendingByThread.get(t);
|
|
6512
6514
|
return n && this.consumeNotification(n, e), (e.method === "thread/closed" || e.method === "thread/deleted") && this.hiddenThreadIds.delete(t), !0;
|
|
@@ -6514,10 +6516,10 @@ var Qi = 12e4, $i = class {
|
|
|
6514
6516
|
async generate(e, t = {}) {
|
|
6515
6517
|
let n = e.trim();
|
|
6516
6518
|
if (!n) throw Error("Generation prompt cannot be empty");
|
|
6517
|
-
if (t.signal?.aborted) throw
|
|
6519
|
+
if (t.signal?.aborted) throw ua();
|
|
6518
6520
|
await this.host.ensureConnected();
|
|
6519
|
-
let r = this.host.getSnapshot(), i = q(r.models, r.selectedModelId), a = t.model ?
|
|
6520
|
-
|
|
6521
|
+
let r = this.host.getSnapshot(), i = q(r.models, r.selectedModelId), a = t.model ? Pr(r.models, t.model) : i, o = a?.model, s = t.reasoningEffort ?? (a?.id === i?.id ? r.selectedReasoningEffort : a ? J(a) : null) ?? void 0, c = t.serviceTier === void 0 ? a?.id === i?.id ? r.selectedServiceTier : a?.defaultServiceTier ?? null : t.serviceTier;
|
|
6522
|
+
Fr(a, s), Y(a, c);
|
|
6521
6523
|
let l = await this.client.request("thread/start", {
|
|
6522
6524
|
approvalPolicy: "never",
|
|
6523
6525
|
approvalsReviewer: "user",
|
|
@@ -6533,15 +6535,15 @@ var Qi = 12e4, $i = class {
|
|
|
6533
6535
|
serviceName: "codex_app_sdk",
|
|
6534
6536
|
threadSource: "sdk_ephemeral_generation"
|
|
6535
6537
|
}), u = l.thread.id;
|
|
6536
|
-
if (!l.thread.ephemeral) throw await
|
|
6537
|
-
if (this.hiddenThreadIds.add(u), t.signal?.aborted) throw await
|
|
6538
|
-
let d =
|
|
6538
|
+
if (!l.thread.ephemeral) throw await oa(() => this.client.request("thread/delete", { threadId: u })), Error("Codex app-server did not create an ephemeral generation thread");
|
|
6539
|
+
if (this.hiddenThreadIds.add(u), t.signal?.aborted) throw await oa(() => this.client.request("thread/unsubscribe", { threadId: u })), this.hiddenThreadIds.delete(u), ua();
|
|
6540
|
+
let d = sa();
|
|
6539
6541
|
this.pendingByThread.set(u, d);
|
|
6540
|
-
let f = null, p = !1, m = () => d.reject(
|
|
6542
|
+
let f = null, p = !1, m = () => d.reject(ua());
|
|
6541
6543
|
t.signal?.addEventListener("abort", m);
|
|
6542
6544
|
let h = setTimeout(() => {
|
|
6543
6545
|
d.reject(/* @__PURE__ */ Error("Codex ephemeral generation timed out"));
|
|
6544
|
-
}, t.timeoutMs ??
|
|
6546
|
+
}, t.timeoutMs ?? ia);
|
|
6545
6547
|
try {
|
|
6546
6548
|
let e = await this.client.request("turn/start", {
|
|
6547
6549
|
threadId: u,
|
|
@@ -6557,18 +6559,18 @@ var Qi = 12e4, $i = class {
|
|
|
6557
6559
|
serviceTier: c,
|
|
6558
6560
|
...t.outputSchema === void 0 ? {} : { outputSchema: t.outputSchema }
|
|
6559
6561
|
});
|
|
6560
|
-
f = e.turn.id, d.turnId = f,
|
|
6562
|
+
f = e.turn.id, d.turnId = f, ca(d, e.turn);
|
|
6561
6563
|
let r = await d.promise;
|
|
6562
6564
|
return p = !0, r;
|
|
6563
6565
|
} finally {
|
|
6564
6566
|
if (clearTimeout(h), t.signal?.removeEventListener("abort", m), this.pendingByThread.delete(u), !p && f) {
|
|
6565
6567
|
let e = f;
|
|
6566
|
-
await
|
|
6568
|
+
await oa(() => this.client.request("turn/interrupt", {
|
|
6567
6569
|
threadId: u,
|
|
6568
6570
|
turnId: e
|
|
6569
6571
|
}));
|
|
6570
6572
|
}
|
|
6571
|
-
await
|
|
6573
|
+
await oa(() => this.client.request("thread/unsubscribe", { threadId: u })), this.hiddenThreadIds.delete(u);
|
|
6572
6574
|
}
|
|
6573
6575
|
}
|
|
6574
6576
|
close(e = /* @__PURE__ */ Error("Codex surface closed")) {
|
|
@@ -6591,16 +6593,16 @@ var Qi = 12e4, $i = class {
|
|
|
6591
6593
|
}
|
|
6592
6594
|
if (t.method === "turn/completed") {
|
|
6593
6595
|
if (e.turnId && t.params.turn.id !== e.turnId) return;
|
|
6594
|
-
|
|
6596
|
+
ca(e, t.params.turn);
|
|
6595
6597
|
}
|
|
6596
6598
|
}
|
|
6597
6599
|
};
|
|
6598
|
-
async function
|
|
6600
|
+
async function oa(e) {
|
|
6599
6601
|
try {
|
|
6600
6602
|
await e();
|
|
6601
6603
|
} catch {}
|
|
6602
6604
|
}
|
|
6603
|
-
function
|
|
6605
|
+
function sa() {
|
|
6604
6606
|
let e, t, n = {
|
|
6605
6607
|
promise: new Promise((n, r) => {
|
|
6606
6608
|
e = n, t = r;
|
|
@@ -6616,7 +6618,7 @@ function ta() {
|
|
|
6616
6618
|
};
|
|
6617
6619
|
return n.promise.catch(() => void 0), n;
|
|
6618
6620
|
}
|
|
6619
|
-
function
|
|
6621
|
+
function ca(e, t) {
|
|
6620
6622
|
for (let n of t.items) {
|
|
6621
6623
|
if (n.type !== "agentMessage") continue;
|
|
6622
6624
|
let t = n.text.trim();
|
|
@@ -6638,17 +6640,17 @@ function na(e, t) {
|
|
|
6638
6640
|
}
|
|
6639
6641
|
e.resolve({ text: n });
|
|
6640
6642
|
}
|
|
6641
|
-
function
|
|
6643
|
+
function la(e) {
|
|
6642
6644
|
if (e.method === "thread/started") return e.params.thread.id;
|
|
6643
6645
|
let t = e.params;
|
|
6644
6646
|
return typeof t.threadId == "string" ? t.threadId : null;
|
|
6645
6647
|
}
|
|
6646
|
-
function
|
|
6648
|
+
function ua() {
|
|
6647
6649
|
return /* @__PURE__ */ Error("Codex ephemeral generation was aborted");
|
|
6648
6650
|
}
|
|
6649
6651
|
//#endregion
|
|
6650
6652
|
//#region src/node/codex-surface.ts
|
|
6651
|
-
var
|
|
6653
|
+
var da = class {
|
|
6652
6654
|
options;
|
|
6653
6655
|
client;
|
|
6654
6656
|
listeners = /* @__PURE__ */ new Set();
|
|
@@ -6681,17 +6683,17 @@ var aa = class {
|
|
|
6681
6683
|
eventSequence = 0;
|
|
6682
6684
|
pendingMarkdownImageHydrations = /* @__PURE__ */ new Set();
|
|
6683
6685
|
closed = !1;
|
|
6684
|
-
state =
|
|
6686
|
+
state = _t(bt());
|
|
6685
6687
|
constructor(e = {}) {
|
|
6686
|
-
this.options = e, this.extensions = new
|
|
6687
|
-
let n =
|
|
6688
|
-
this.client = e.client ?? new t(
|
|
6688
|
+
this.options = e, this.extensions = new Si(e.extensions ?? [], e.mcpServers ?? [], (e) => this.lifecycle.hostOptions(e));
|
|
6689
|
+
let n = Dt(e);
|
|
6690
|
+
this.client = e.client ?? new t(Et(n) ? new Ke(n) : new Ve(n), e.onListenerError ? { onListenerError: e.onListenerError } : {}), this.markdownImages = new qi(this.client), this.authentication = new kt(this.client, {
|
|
6689
6691
|
bootstrapSurfaceData: (e) => this.connection.bootstrapSurfaceData(e),
|
|
6690
6692
|
clearAuthenticatedSurfaceData: () => this.connection.clearAuthenticatedSurfaceData(),
|
|
6691
6693
|
getSnapshot: () => this.getSnapshot(),
|
|
6692
6694
|
patchAuthentication: (e, t) => this.connection.patchAuthentication(e, t),
|
|
6693
|
-
reportError: (e) => this.patch({ error:
|
|
6694
|
-
}), this.items = new
|
|
6695
|
+
reportError: (e) => this.patch({ error: O(e) })
|
|
6696
|
+
}), this.items = new br({
|
|
6695
6697
|
assistantMessageForTurn: (e, t) => this.assistantMessageForTurn(e, t),
|
|
6696
6698
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
6697
6699
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
@@ -6705,7 +6707,7 @@ var aa = class {
|
|
|
6705
6707
|
sendNextQueuedPrompt: (e) => {
|
|
6706
6708
|
this.messagesController.sendNextQueuedPrompt(e);
|
|
6707
6709
|
}
|
|
6708
|
-
}), this.approvals = new
|
|
6710
|
+
}), this.approvals = new mi(this.client, {
|
|
6709
6711
|
activeConversationId: () => this.state.activeConversationId,
|
|
6710
6712
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6711
6713
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6715,7 +6717,7 @@ var aa = class {
|
|
|
6715
6717
|
patch: (e) => this.patch(e),
|
|
6716
6718
|
patchConversationStatus: (e, t) => this.patchConversationStatus(e, t),
|
|
6717
6719
|
patchRuntime: (e, t) => this.patchRuntime(e, t)
|
|
6718
|
-
}), this.clientRequests = new
|
|
6720
|
+
}), this.clientRequests = new Cr({
|
|
6719
6721
|
activeConversationId: () => this.state.activeConversationId,
|
|
6720
6722
|
answerAsyncQuestion: (e, t, n) => this.messagesController.answerAsyncQuestion(e, t, n),
|
|
6721
6723
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6725,13 +6727,13 @@ var aa = class {
|
|
|
6725
6727
|
messageContainingTool: (e, t, n) => this.messageContainingTool(e, t, n),
|
|
6726
6728
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6727
6729
|
requireRuntime: (e) => this.requireRuntime(e)
|
|
6728
|
-
}), this.runtimeState = new
|
|
6730
|
+
}), this.runtimeState = new Ii(this.approvals, this.clientRequests, {
|
|
6729
6731
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
6730
6732
|
getState: () => this.state,
|
|
6731
6733
|
notifyConversationListeners: (e) => this.notifyConversationListeners(e),
|
|
6732
6734
|
patch: (e, t) => this.patch(e, t),
|
|
6733
6735
|
schedulePluginRefresh: () => this.catalog.schedulePluginRefresh()
|
|
6734
|
-
}), this.conversationSettings = new
|
|
6736
|
+
}), this.conversationSettings = new Oi(this.client, {
|
|
6735
6737
|
approvalMode: e.approvalMode,
|
|
6736
6738
|
approvalPreset: e.approvalPreset,
|
|
6737
6739
|
permissionMode: e.permissionMode
|
|
@@ -6749,7 +6751,7 @@ var aa = class {
|
|
|
6749
6751
|
patch: (e) => this.patch(e),
|
|
6750
6752
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6751
6753
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e)
|
|
6752
|
-
}), this.turnActions = new
|
|
6754
|
+
}), this.turnActions = new Ai(this.client, {
|
|
6753
6755
|
createConversation: async () => {
|
|
6754
6756
|
await this.createConversation();
|
|
6755
6757
|
},
|
|
@@ -6766,7 +6768,7 @@ var aa = class {
|
|
|
6766
6768
|
patchConversationTurnCount: (e, t, n) => this.patchConversationTurnCount(e, t, n),
|
|
6767
6769
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6768
6770
|
sendMessageToThread: (e, t, n) => this.messagesController.sendToThread(e, t, n)
|
|
6769
|
-
}), this.messagesController = new
|
|
6771
|
+
}), this.messagesController = new Mi(this.client, {
|
|
6770
6772
|
clearGoalForThread: (e) => this.conversationSettings.clearGoalForThread(e),
|
|
6771
6773
|
compactForThread: (e) => this.turnActions.compactForThread(e),
|
|
6772
6774
|
createConversation: async () => {
|
|
@@ -6789,7 +6791,7 @@ var aa = class {
|
|
|
6789
6791
|
startReviewForThread: (e, t) => this.turnActions.startReviewForThread(e, t),
|
|
6790
6792
|
updateSettings: (e) => this.conversationSettings.update(e),
|
|
6791
6793
|
updateSettingsForThread: (e, t) => this.conversationSettings.updateForThread(e, t)
|
|
6792
|
-
}), this.catalog = new
|
|
6794
|
+
}), this.catalog = new oi(this.client, e.cwd, {
|
|
6793
6795
|
authenticationBlocksBootstrap: () => this.authentication.blocksBootstrap(),
|
|
6794
6796
|
emitConversationSkills: (e, t) => this.emitConversationSkills(e, t),
|
|
6795
6797
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
@@ -6800,7 +6802,7 @@ var aa = class {
|
|
|
6800
6802
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6801
6803
|
preferredApprovalPreset: () => this.conversationSettings.preferredApprovalPreset(),
|
|
6802
6804
|
runtimes: () => this.runtimeState.values()
|
|
6803
|
-
}), this.conversations = new
|
|
6805
|
+
}), this.conversations = new Ei(this.client, e.conversationLimit, {
|
|
6804
6806
|
emitHistoryPrepended: (e, t, n) => this.emitHistoryPrepended(e, t, n),
|
|
6805
6807
|
emitSummaryUpserted: (e, t, n) => this.emitSummaryUpserted(e, t, n),
|
|
6806
6808
|
ensureConnected: () => this.ensureConnected(),
|
|
@@ -6812,7 +6814,7 @@ var aa = class {
|
|
|
6812
6814
|
requireRuntime: (e) => this.requireRuntime(e),
|
|
6813
6815
|
runtime: (e) => this.runtimeState.get(e),
|
|
6814
6816
|
schedulePluginRefresh: (e) => this.catalog.schedulePluginRefresh(e)
|
|
6815
|
-
}), this.lifecycle = new
|
|
6817
|
+
}), this.lifecycle = new Pi(this.client, e, this.catalog, this.extensions, this.conversationSettings, this.conversations, {
|
|
6816
6818
|
activateRuntime: (e) => this.activateRuntime(e),
|
|
6817
6819
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6818
6820
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6834,7 +6836,7 @@ var aa = class {
|
|
|
6834
6836
|
runtime: (e) => this.runtimeState.get(e),
|
|
6835
6837
|
runtimeProjection: (e) => this.runtimeProjection(e),
|
|
6836
6838
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e)
|
|
6837
|
-
}), this.forks = new
|
|
6839
|
+
}), this.forks = new Ui(this.client, e.loadingStrategy, this.catalog, this.extensions, {
|
|
6838
6840
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6839
6841
|
emitConversationActivity: (e) => this.emitConversationActivity(e, "action"),
|
|
6840
6842
|
emitConversationPermissions: (e) => this.emitConversationPermissions(e, "action"),
|
|
@@ -6848,7 +6850,7 @@ var aa = class {
|
|
|
6848
6850
|
rememberHostOptions: (e, t) => this.lifecycle.rememberHostOptions(e, t),
|
|
6849
6851
|
requireRuntime: (e) => this.requireRuntime(e),
|
|
6850
6852
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e)
|
|
6851
|
-
}), this.connection = new
|
|
6853
|
+
}), this.connection = new Vi(this.client, e, this.authentication, this.approvals, this.catalog, this.clientRequests, this.conversations, this.items, this.lifecycle, this.runtimeState, {
|
|
6852
6854
|
clearConversationHandles: () => this.conversationHandles.clear(),
|
|
6853
6855
|
clearPendingForThread: (e, t, n) => this.clearPendingForThread(e, t, n),
|
|
6854
6856
|
closed: () => this.closed,
|
|
@@ -6860,7 +6862,7 @@ var aa = class {
|
|
|
6860
6862
|
getSnapshot: () => this.getSnapshot(),
|
|
6861
6863
|
getState: () => this.state,
|
|
6862
6864
|
patch: (e) => this.patch(e)
|
|
6863
|
-
}), this.notifications = new
|
|
6865
|
+
}), this.notifications = new Fi(this.authentication, this.approvals, this.catalog, this.clientRequests, this.conversations, this.items, {
|
|
6864
6866
|
clearPendingForThread: (e, t, n) => this.clearPendingForThread(e, t, n),
|
|
6865
6867
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6866
6868
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6884,7 +6886,7 @@ var aa = class {
|
|
|
6884
6886
|
},
|
|
6885
6887
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e),
|
|
6886
6888
|
unknownNotification: (e) => this.handleUnknownNotification(e)
|
|
6887
|
-
}), this.textGeneration = new
|
|
6889
|
+
}), this.textGeneration = new aa(this.client, e.cwd, {
|
|
6888
6890
|
ensureConnected: () => this.ensureConnected(),
|
|
6889
6891
|
getSnapshot: () => this.getSnapshot()
|
|
6890
6892
|
}), this.unsubscribeNotification = this.client.onNotification((e) => {
|
|
@@ -6980,7 +6982,7 @@ var aa = class {
|
|
|
6980
6982
|
return this.lifecycle.create(e, t);
|
|
6981
6983
|
}
|
|
6982
6984
|
async forkConversation(e, t = {}, n = {}) {
|
|
6983
|
-
let r =
|
|
6985
|
+
let r = D(e);
|
|
6984
6986
|
await this.ensureThreadReady(r);
|
|
6985
6987
|
let i = this.lifecycle.hostOptions(r) ?? {}, a = await this.forks.fork(r, t, {
|
|
6986
6988
|
...i,
|
|
@@ -6989,7 +6991,7 @@ var aa = class {
|
|
|
6989
6991
|
return this.conversationForkResult(a);
|
|
6990
6992
|
}
|
|
6991
6993
|
async forkConversationAtTurn(e, t, n = {}, r = {}) {
|
|
6992
|
-
let i =
|
|
6994
|
+
let i = D(e);
|
|
6993
6995
|
await this.ensureThreadReady(i);
|
|
6994
6996
|
let a = this.lifecycle.hostOptions(i) ?? {}, o = await this.forks.forkTurn(i, t, n, {
|
|
6995
6997
|
...a,
|
|
@@ -7001,7 +7003,7 @@ var aa = class {
|
|
|
7001
7003
|
return this.lifecycle.select(e);
|
|
7002
7004
|
}
|
|
7003
7005
|
forgetConversation(e) {
|
|
7004
|
-
let t =
|
|
7006
|
+
let t = D(e), n = this.state.activeConversationId === t;
|
|
7005
7007
|
this.runtimeState.forget(t), this.lifecycle.forget(t), this.conversations.forget(t), this.items.forget(t), this.conversationHandles.delete(t), this.conversationListeners.delete(t), n && this.patch({
|
|
7006
7008
|
activeConversationId: null,
|
|
7007
7009
|
activeTurnId: null,
|
|
@@ -7029,10 +7031,10 @@ var aa = class {
|
|
|
7029
7031
|
return this.lifecycle.readHistory(e);
|
|
7030
7032
|
}
|
|
7031
7033
|
async readConversationPromptHistory(e = this.state.activeConversationId ?? "") {
|
|
7032
|
-
return await this.ensureConnected(),
|
|
7034
|
+
return await this.ensureConnected(), ta(this.client, e);
|
|
7033
7035
|
}
|
|
7034
7036
|
async loadOlderConversationHistory(e = this.state.activeConversationId ?? "") {
|
|
7035
|
-
return this.conversations.loadOlderHistory(
|
|
7037
|
+
return this.conversations.loadOlderHistory(D(e));
|
|
7036
7038
|
}
|
|
7037
7039
|
async renameConversation(e) {
|
|
7038
7040
|
let t = this.state.activeConversationId;
|
|
@@ -7096,9 +7098,9 @@ var aa = class {
|
|
|
7096
7098
|
return await this.approvals.resolve(void 0, e, t, n), this.getSnapshot();
|
|
7097
7099
|
}
|
|
7098
7100
|
conversation(e) {
|
|
7099
|
-
let t =
|
|
7101
|
+
let t = D(e), n = this.conversationHandles.get(t);
|
|
7100
7102
|
if (n) return n;
|
|
7101
|
-
let r =
|
|
7103
|
+
let r = At(t, {
|
|
7102
7104
|
clearGoal: () => this.conversationSettings.clearGoalForThread(t),
|
|
7103
7105
|
compact: () => this.turnActions.compactForThread(t),
|
|
7104
7106
|
continueInterruptedTurn: () => this.messagesController.continueInterruptedTurnForThread(t),
|
|
@@ -7151,7 +7153,7 @@ var aa = class {
|
|
|
7151
7153
|
await this.client.request("thread/realtime/stop", { threadId: e });
|
|
7152
7154
|
}
|
|
7153
7155
|
startRealtimeForThread(e, t) {
|
|
7154
|
-
return
|
|
7156
|
+
return ht({
|
|
7155
7157
|
client: this.client,
|
|
7156
7158
|
ensureThreadReady: async () => {
|
|
7157
7159
|
await this.ensureThreadReady(e);
|
|
@@ -7385,7 +7387,7 @@ var aa = class {
|
|
|
7385
7387
|
...this.state,
|
|
7386
7388
|
...e
|
|
7387
7389
|
};
|
|
7388
|
-
let i =
|
|
7390
|
+
let i = te(n, this.state);
|
|
7389
7391
|
if (i.length > 0 && (this.stateVersion += 1, this.patchListeners.size > 0)) {
|
|
7390
7392
|
let e = structuredClone({
|
|
7391
7393
|
version: this.stateVersion,
|
|
@@ -7404,19 +7406,19 @@ var aa = class {
|
|
|
7404
7406
|
for (let e of this.conversationListeners.keys()) this.notifyConversationListeners(e);
|
|
7405
7407
|
}
|
|
7406
7408
|
};
|
|
7407
|
-
function
|
|
7408
|
-
return new
|
|
7409
|
+
function fa(e = {}) {
|
|
7410
|
+
return new da(e);
|
|
7409
7411
|
}
|
|
7410
7412
|
//#endregion
|
|
7411
7413
|
//#region src/node/codex-app-backend-cache.ts
|
|
7412
|
-
var
|
|
7414
|
+
var pa = {
|
|
7413
7415
|
set(e, t) {
|
|
7414
7416
|
return setTimeout(e, t);
|
|
7415
7417
|
},
|
|
7416
7418
|
clear(e) {
|
|
7417
7419
|
clearTimeout(e);
|
|
7418
7420
|
}
|
|
7419
|
-
},
|
|
7421
|
+
}, ma = class {
|
|
7420
7422
|
options;
|
|
7421
7423
|
records = /* @__PURE__ */ new Map();
|
|
7422
7424
|
now;
|
|
@@ -7429,7 +7431,7 @@ var sa = {
|
|
|
7429
7431
|
constructor(e) {
|
|
7430
7432
|
if (this.options = e, !Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error("Codex backend cache ttlMs must be greater than zero");
|
|
7431
7433
|
if (e.sweepIntervalMs !== void 0 && e.sweepIntervalMs !== null && (!Number.isFinite(e.sweepIntervalMs) || e.sweepIntervalMs <= 0)) throw Error("Codex backend cache sweepIntervalMs must be greater than zero");
|
|
7432
|
-
this.now = e.now ?? Date.now, this.scheduler = e.scheduler ??
|
|
7434
|
+
this.now = e.now ?? Date.now, this.scheduler = e.scheduler ?? pa, this.sweepIntervalMs = e.sweepIntervalMs ?? null;
|
|
7433
7435
|
}
|
|
7434
7436
|
get size() {
|
|
7435
7437
|
return this.records.size;
|
|
@@ -7527,7 +7529,7 @@ var sa = {
|
|
|
7527
7529
|
assertOpen() {
|
|
7528
7530
|
if (this.closed) throw Error("Codex backend cache is closed");
|
|
7529
7531
|
}
|
|
7530
|
-
},
|
|
7532
|
+
}, ha = class {
|
|
7531
7533
|
surface;
|
|
7532
7534
|
moduleServices = /* @__PURE__ */ new Map();
|
|
7533
7535
|
ttlCaches = /* @__PURE__ */ new Set();
|
|
@@ -7543,7 +7545,7 @@ var sa = {
|
|
|
7543
7545
|
if (n.has(e)) throw Error(`Duplicate Codex backend module '${e}'`);
|
|
7544
7546
|
n.add(e);
|
|
7545
7547
|
}
|
|
7546
|
-
this.surface = e.surface ?? new
|
|
7548
|
+
this.surface = e.surface ?? new da(e.surfaceOptions);
|
|
7547
7549
|
for (let { id: e, module: n } of t) this.moduleServices.set(e, n.create({
|
|
7548
7550
|
surface: this.surface,
|
|
7549
7551
|
closeBackend: () => this.close(),
|
|
@@ -7557,7 +7559,7 @@ var sa = {
|
|
|
7557
7559
|
}
|
|
7558
7560
|
createTtlCache(e) {
|
|
7559
7561
|
if (this.closePromise) throw Error("Cannot create a cache after the Codex backend is closed");
|
|
7560
|
-
let t = new
|
|
7562
|
+
let t = new ma(e);
|
|
7561
7563
|
return this.ttlCaches.add(t), t;
|
|
7562
7564
|
}
|
|
7563
7565
|
close() {
|
|
@@ -7567,16 +7569,16 @@ var sa = {
|
|
|
7567
7569
|
await Promise.all([...this.ttlCaches].map((e) => e.close())), await this.surface.close();
|
|
7568
7570
|
}
|
|
7569
7571
|
};
|
|
7570
|
-
function
|
|
7571
|
-
return new
|
|
7572
|
+
function ga(e = {}) {
|
|
7573
|
+
return new ha(e);
|
|
7572
7574
|
}
|
|
7573
7575
|
//#endregion
|
|
7574
7576
|
//#region src/node/apple-speech-transcription.ts
|
|
7575
|
-
async function
|
|
7576
|
-
let r = n.fs ?? l, i = n.spawn ?? o, a = n.tmpdir ?? f.tmpdir, s = await r.mkdtemp(
|
|
7577
|
+
async function _a(e, t = {}, n = {}) {
|
|
7578
|
+
let r = n.fs ?? l, i = n.spawn ?? o, a = n.tmpdir ?? f.tmpdir, s = await r.mkdtemp(h.join(a(), "codex-app-sdk-apple-stt-")), c = h.join(s, "input.wav"), u = h.join(s, "output.txt");
|
|
7577
7579
|
try {
|
|
7578
|
-
let a = await
|
|
7579
|
-
return await r.writeFile(c, e), await
|
|
7580
|
+
let a = await Sa(va(n.assetsPath), s, r);
|
|
7581
|
+
return await r.writeFile(c, e), await ba(i, a, ya(c, u, t)), { text: (await r.readFile(u, "utf8")).trim() };
|
|
7580
7582
|
} catch (e) {
|
|
7581
7583
|
return {
|
|
7582
7584
|
text: "",
|
|
@@ -7589,10 +7591,10 @@ async function da(e, t = {}, n = {}) {
|
|
|
7589
7591
|
});
|
|
7590
7592
|
}
|
|
7591
7593
|
}
|
|
7592
|
-
function
|
|
7593
|
-
return
|
|
7594
|
+
function va(e, t = {}) {
|
|
7595
|
+
return h.join(e ?? xa(t), "apple-speechanalyzer-cli");
|
|
7594
7596
|
}
|
|
7595
|
-
function
|
|
7597
|
+
function ya(e, t, n) {
|
|
7596
7598
|
let r = [
|
|
7597
7599
|
"--input-audio-path",
|
|
7598
7600
|
e,
|
|
@@ -7601,7 +7603,7 @@ function pa(e, t, n) {
|
|
|
7601
7603
|
], i = n.locale?.trim();
|
|
7602
7604
|
return i && r.push("--locale", i), n.live && r.push("--live"), r;
|
|
7603
7605
|
}
|
|
7604
|
-
function
|
|
7606
|
+
function ba(e, t, n) {
|
|
7605
7607
|
return new Promise((r, i) => {
|
|
7606
7608
|
let a = e(t, n), o = "";
|
|
7607
7609
|
a.stderr?.on("data", (e) => {
|
|
@@ -7617,42 +7619,150 @@ function ma(e, t, n) {
|
|
|
7617
7619
|
});
|
|
7618
7620
|
});
|
|
7619
7621
|
}
|
|
7620
|
-
function
|
|
7622
|
+
function xa(e) {
|
|
7621
7623
|
let t = (e.env ?? process.env).CODEX_APP_SDK_ASSETS_PATH?.trim();
|
|
7622
7624
|
if (t) return t;
|
|
7623
7625
|
let n = process.resourcesPath, r = e.resourcesPath === void 0 ? n : e.resourcesPath ?? void 0, i = e.existsSync ?? c;
|
|
7624
7626
|
if (r && !r.endsWith(".vite/build")) {
|
|
7625
7627
|
let e = [
|
|
7626
7628
|
r,
|
|
7627
|
-
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
|
|
7632
|
-
].find((e) => i(
|
|
7629
|
+
h.join(r, "assets"),
|
|
7630
|
+
h.join(r, "app.asar.unpacked/node_modules/@codex-app-sdk/backend/assets"),
|
|
7631
|
+
h.join(r, "app.asar/node_modules/@codex-app-sdk/backend/assets"),
|
|
7632
|
+
h.join(r, "app.asar.unpacked/node_modules/codex-app-sdk/assets"),
|
|
7633
|
+
h.join(r, "app.asar/node_modules/codex-app-sdk/assets")
|
|
7634
|
+
].find((e) => i(h.join(e, "apple-speechanalyzer-cli")));
|
|
7633
7635
|
if (e) return e;
|
|
7634
7636
|
}
|
|
7635
7637
|
let a = import.meta.resolve, o = e.packageResolve === void 0 ? a : e.packageResolve ?? void 0;
|
|
7636
7638
|
if (o) try {
|
|
7637
|
-
let e =
|
|
7638
|
-
if (i(
|
|
7639
|
+
let e = ne(o("@codex-app-sdk/backend")), t = h.resolve(h.dirname(e), "../assets");
|
|
7640
|
+
if (i(h.join(t, "apple-speechanalyzer-cli"))) return t;
|
|
7639
7641
|
} catch {}
|
|
7640
7642
|
let s = (e.cwd ?? process.cwd)(), l = [
|
|
7641
|
-
|
|
7642
|
-
|
|
7643
|
-
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
].find((e) => i(
|
|
7643
|
+
h.resolve(s, "node_modules/@codex-app-sdk/backend/assets"),
|
|
7644
|
+
h.resolve(s, "../node_modules/@codex-app-sdk/backend/assets"),
|
|
7645
|
+
h.resolve(s, "node_modules/codex-app-sdk/assets"),
|
|
7646
|
+
h.resolve(s, "../node_modules/codex-app-sdk/assets"),
|
|
7647
|
+
h.resolve(s, "../codex-app-sdk/assets")
|
|
7648
|
+
].find((e) => i(h.join(e, "apple-speechanalyzer-cli")));
|
|
7647
7649
|
if (l) return l;
|
|
7648
|
-
let u = import.meta.url, d = e.moduleUrl === void 0 ? u : e.moduleUrl ?? void 0, f = d ?
|
|
7649
|
-
return p.find((e) => i(
|
|
7650
|
+
let u = import.meta.url, d = e.moduleUrl === void 0 ? u : e.moduleUrl ?? void 0, f = d ? h.dirname(ne(d)) : s, p = [h.resolve(f, "../assets"), h.resolve(f, "../../assets")];
|
|
7651
|
+
return p.find((e) => i(h.join(e, "apple-speechanalyzer-cli"))) ?? p[0];
|
|
7650
7652
|
}
|
|
7651
|
-
async function
|
|
7652
|
-
let r =
|
|
7653
|
+
async function Sa(e, t, n) {
|
|
7654
|
+
let r = h.join(t, "apple-speechanalyzer-cli");
|
|
7653
7655
|
return await n.copyFile(e, r), await n.chmod(r, 448), r;
|
|
7654
7656
|
}
|
|
7655
7657
|
//#endregion
|
|
7656
|
-
|
|
7658
|
+
//#region src/node/apple-speech-session.ts
|
|
7659
|
+
async function Ca(e, t, n = {}) {
|
|
7660
|
+
if (n.signal?.throwIfAborted(), !Number.isInteger(e.sampleRate) || e.sampleRate < 8e3 || e.sampleRate > 96e3) throw Error("Unsupported speech sample rate.");
|
|
7661
|
+
let r = await se(h.join(m(), "codex-sdk-live-speech-")), i;
|
|
7662
|
+
try {
|
|
7663
|
+
let t = h.join(r, "apple-speechanalyzer-cli");
|
|
7664
|
+
await oe(va(n.assetsPath), t), await ae(t, 448), n.signal?.throwIfAborted(), i = (n.spawn ?? o)(t, [
|
|
7665
|
+
"--stream",
|
|
7666
|
+
"--sample-rate",
|
|
7667
|
+
String(e.sampleRate),
|
|
7668
|
+
...e.locale ? ["--locale", e.locale] : []
|
|
7669
|
+
]);
|
|
7670
|
+
} catch (e) {
|
|
7671
|
+
throw await ce(r, {
|
|
7672
|
+
recursive: !0,
|
|
7673
|
+
force: !0
|
|
7674
|
+
}), e;
|
|
7675
|
+
}
|
|
7676
|
+
let a = !1, s = !1, c, l = "", u = new le("utf8"), d = "", f, p, g = new Promise((e, t) => {
|
|
7677
|
+
f = e, p = t;
|
|
7678
|
+
}), _, v = new Promise((e) => {
|
|
7679
|
+
_ = e;
|
|
7680
|
+
}), y = setTimeout(() => x("Speech recognition took too long to start."), 12e4), b = async () => {
|
|
7681
|
+
if (a) return;
|
|
7682
|
+
a = !0, clearTimeout(y), n.signal?.removeEventListener("abort", C);
|
|
7683
|
+
let e = c ?? {
|
|
7684
|
+
text: "",
|
|
7685
|
+
error: d.trim() || "Speech helper stopped without a final transcript."
|
|
7686
|
+
};
|
|
7687
|
+
p(Error(e.error ?? "Speech session closed."));
|
|
7688
|
+
try {
|
|
7689
|
+
await ce(r, {
|
|
7690
|
+
recursive: !0,
|
|
7691
|
+
force: !0
|
|
7692
|
+
});
|
|
7693
|
+
} finally {
|
|
7694
|
+
_(e);
|
|
7695
|
+
}
|
|
7696
|
+
};
|
|
7697
|
+
function x(t) {
|
|
7698
|
+
a || c?.error || (c = {
|
|
7699
|
+
text: "",
|
|
7700
|
+
error: t
|
|
7701
|
+
}, p(Error(t)), S({
|
|
7702
|
+
type: "error",
|
|
7703
|
+
sessionId: e.sessionId,
|
|
7704
|
+
error: t
|
|
7705
|
+
}), i.kill("SIGKILL"), b());
|
|
7706
|
+
}
|
|
7707
|
+
function S(e) {
|
|
7708
|
+
try {
|
|
7709
|
+
t(e);
|
|
7710
|
+
} catch {}
|
|
7711
|
+
}
|
|
7712
|
+
function C() {
|
|
7713
|
+
a || (c = {
|
|
7714
|
+
text: "",
|
|
7715
|
+
error: "Speech recording cancelled."
|
|
7716
|
+
}, i.kill("SIGKILL"), b());
|
|
7717
|
+
}
|
|
7718
|
+
return n.signal?.addEventListener("abort", C, { once: !0 }), i.stderr.on("data", (e) => {
|
|
7719
|
+
d = (d + e.toString()).slice(-4096);
|
|
7720
|
+
}), i.on("error", (e) => x(e.message)), i.stdin.on("error", (e) => x(e.message)), i.on("close", (e) => {
|
|
7721
|
+
e !== 0 && !c?.error && x(d.trim() || `Speech helper exited with code ${e}.`), b();
|
|
7722
|
+
}), i.stdout.on("data", (t) => {
|
|
7723
|
+
if (a) return;
|
|
7724
|
+
if (l += u.write(t), l.length > 1024 * 1024) {
|
|
7725
|
+
x("Speech helper result exceeds the size limit.");
|
|
7726
|
+
return;
|
|
7727
|
+
}
|
|
7728
|
+
let n;
|
|
7729
|
+
for (; (n = l.indexOf("\n")) >= 0 && !a;) {
|
|
7730
|
+
let t = l.slice(0, n);
|
|
7731
|
+
l = l.slice(n + 1);
|
|
7732
|
+
try {
|
|
7733
|
+
let n = JSON.parse(t);
|
|
7734
|
+
n.type === "ready" ? (clearTimeout(y), f()) : n.type === "transcript" && typeof n.finalText == "string" && typeof n.partialText == "string" ? S({
|
|
7735
|
+
type: "transcript",
|
|
7736
|
+
sessionId: e.sessionId,
|
|
7737
|
+
finalText: n.finalText,
|
|
7738
|
+
partialText: n.partialText
|
|
7739
|
+
}) : n.type === "done" && typeof n.text == "string" ? c = { text: n.text } : n.type === "error" && typeof n.message == "string" ? x(n.message) : x("Invalid speech helper event.");
|
|
7740
|
+
} catch {
|
|
7741
|
+
x("Invalid speech helper output.");
|
|
7742
|
+
}
|
|
7743
|
+
}
|
|
7744
|
+
}), n.signal?.aborted && C(), await g, {
|
|
7745
|
+
append: (e) => new Promise((t, n) => {
|
|
7746
|
+
if (a || s) {
|
|
7747
|
+
n(/* @__PURE__ */ Error("Speech session is no longer recording."));
|
|
7748
|
+
return;
|
|
7749
|
+
}
|
|
7750
|
+
if (e.byteLength % 4 || e.byteLength > 256 * 1024) {
|
|
7751
|
+
n(/* @__PURE__ */ Error("Invalid PCM audio chunk."));
|
|
7752
|
+
return;
|
|
7753
|
+
}
|
|
7754
|
+
i.stdin.write(Buffer.from(e), (e) => e ? n(e) : t());
|
|
7755
|
+
}),
|
|
7756
|
+
stop: () => (!a && !s && (s = !0, y = setTimeout(() => x("Speech recognition took too long to finalize."), 3e4), i.stdin.end()), v),
|
|
7757
|
+
cancel: async () => {
|
|
7758
|
+
a || (c = {
|
|
7759
|
+
text: "",
|
|
7760
|
+
error: "Speech recording cancelled."
|
|
7761
|
+
}, i.kill("SIGKILL"), await b());
|
|
7762
|
+
}
|
|
7763
|
+
};
|
|
7764
|
+
}
|
|
7765
|
+
//#endregion
|
|
7766
|
+
export { ha as CodexAppBackend, ma as CodexAppBackendTtlCache, Ve as CodexAppServerStdioTransport, Ke as CodexAppServerUnixSocketTransport, da as CodexSurface, Hn as codexItemToMediaPart, Bn as codexItemToSurfaceMessage, A as codexItemToToolPart, me as codexRuntimePathEntries, Ln as codexThreadToSurfaceMessages, zn as codexTurnToSurfaceMessages, ga as createCodexAppBackend, fa as createCodexSurface, pe as discoverCodexExecutable, Rn as preserveHistoricalAttachmentPreviews, va as resolveAppleSpeechAnalyzerPath, ge as resolveCodexRuntime, Ca as startAppleSpeechSession, _a as transcribeWithAppleSpeechAnalyzer, he as withCodexRuntimePath };
|
|
7657
7767
|
|
|
7658
7768
|
//# sourceMappingURL=index.js.map
|