@codex-app-sdk/backend 0.14.3 → 0.15.0
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 -825
- 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/codex-surface-message-state.d.ts.map +1 -1
- 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 ?? {}
|
|
@@ -1807,13 +1809,12 @@ function F(e, t, n, r) {
|
|
|
1807
1809
|
} else s.push(r);
|
|
1808
1810
|
return i.splice(a, 1, {
|
|
1809
1811
|
...o,
|
|
1810
|
-
status: "streaming",
|
|
1811
1812
|
parts: s
|
|
1812
|
-
}),
|
|
1813
|
+
}), R(i, t);
|
|
1813
1814
|
}
|
|
1814
|
-
function
|
|
1815
|
+
function Tn(e, t, n, r) {
|
|
1815
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));
|
|
1816
|
-
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));
|
|
1817
1818
|
let o = a >= 0 ? i[a] : void 0;
|
|
1818
1819
|
if (!o) return i;
|
|
1819
1820
|
let s = [...o.parts], c = s.findIndex((e) => e.type === "media" && e.itemId === r.itemId);
|
|
@@ -1821,25 +1822,25 @@ function xn(e, t, n, r) {
|
|
|
1821
1822
|
...o,
|
|
1822
1823
|
status: "streaming",
|
|
1823
1824
|
parts: s
|
|
1824
|
-
}),
|
|
1825
|
+
}), R(i, t);
|
|
1825
1826
|
}
|
|
1826
|
-
function
|
|
1827
|
+
function En(e, t, n, r) {
|
|
1827
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));
|
|
1828
|
-
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));
|
|
1829
1830
|
let o = a >= 0 ? i[a] : void 0;
|
|
1830
1831
|
if (!o) return i;
|
|
1831
1832
|
let s = [...o.parts], c = s.findIndex((e) => e.type === "question" && e.request.id === r.request.id);
|
|
1832
1833
|
return c >= 0 ? s.splice(c, 1, r) : s.push(r), i.splice(a, 1, {
|
|
1833
1834
|
...o,
|
|
1834
1835
|
parts: s
|
|
1835
|
-
}),
|
|
1836
|
+
}), R(i, t);
|
|
1836
1837
|
}
|
|
1837
|
-
function
|
|
1838
|
+
function Dn(e, t) {
|
|
1838
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;
|
|
1839
1840
|
}
|
|
1840
|
-
function
|
|
1841
|
+
function On(e, t, n, r) {
|
|
1841
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));
|
|
1842
|
-
if (a < 0) return r.fallbackToolPart ?
|
|
1843
|
+
if (a < 0) return r.fallbackToolPart ? On(L(i, t, n, r.fallbackToolPart), t, n, {
|
|
1843
1844
|
...r,
|
|
1844
1845
|
fallbackToolPart: void 0
|
|
1845
1846
|
}) : i;
|
|
@@ -1865,12 +1866,12 @@ function wn(e, t, n, r) {
|
|
|
1865
1866
|
parts: s
|
|
1866
1867
|
}), i) : i;
|
|
1867
1868
|
}
|
|
1868
|
-
function
|
|
1869
|
+
function kn(e, t, n, r = "streaming") {
|
|
1869
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 ? {
|
|
1870
1871
|
...e,
|
|
1871
1872
|
status: r
|
|
1872
1873
|
} : e);
|
|
1873
|
-
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;
|
|
1874
1875
|
return o?.parts.length === 0 ? i.splice(a, 1) : o && i.splice(a, 1, {
|
|
1875
1876
|
...o,
|
|
1876
1877
|
status: "complete"
|
|
@@ -1886,16 +1887,16 @@ function Tn(e, t, n, r = "streaming") {
|
|
|
1886
1887
|
conversationId: t,
|
|
1887
1888
|
turnId: n
|
|
1888
1889
|
}
|
|
1889
|
-
}),
|
|
1890
|
+
}), R(i, t);
|
|
1890
1891
|
}
|
|
1891
|
-
function
|
|
1892
|
+
function An(e, t, n) {
|
|
1892
1893
|
let r = n === "completed" ? "completed" : "failed";
|
|
1893
1894
|
return e.map((e) => {
|
|
1894
1895
|
if (e.metadata?.turnId !== t) return e;
|
|
1895
1896
|
let n = !1, i = e.parts.map((e) => e.type !== "tool" || e.status !== "running" ? e : (n = !0, {
|
|
1896
1897
|
...e,
|
|
1897
1898
|
status: r,
|
|
1898
|
-
statusText:
|
|
1899
|
+
statusText: jn(e.statusText, r)
|
|
1899
1900
|
}));
|
|
1900
1901
|
return n ? {
|
|
1901
1902
|
...e,
|
|
@@ -1903,11 +1904,11 @@ function En(e, t, n) {
|
|
|
1903
1904
|
} : e;
|
|
1904
1905
|
});
|
|
1905
1906
|
}
|
|
1906
|
-
function
|
|
1907
|
+
function jn(e, t) {
|
|
1907
1908
|
if (t === "running" || !e) return e;
|
|
1908
1909
|
try {
|
|
1909
1910
|
let n = JSON.parse(e);
|
|
1910
|
-
return
|
|
1911
|
+
return ct(n) ? JSON.stringify({
|
|
1911
1912
|
...n,
|
|
1912
1913
|
phase: t
|
|
1913
1914
|
}) : e;
|
|
@@ -1915,27 +1916,27 @@ function Dn(e, t) {
|
|
|
1915
1916
|
return e;
|
|
1916
1917
|
}
|
|
1917
1918
|
}
|
|
1918
|
-
function
|
|
1919
|
+
function R(e, t) {
|
|
1919
1920
|
let n = e.map((e, t) => ({
|
|
1920
1921
|
message: e,
|
|
1921
1922
|
index: t
|
|
1922
1923
|
})).filter(({ message: e }) => e.metadata?.conversationId === t).at(-1)?.index ?? -1;
|
|
1923
1924
|
return e.filter((e, r) => e.metadata?.conversationId !== t || r === n || e.role !== "assistant" || e.kind !== void 0 || e.parts.length > 0);
|
|
1924
1925
|
}
|
|
1925
|
-
function
|
|
1926
|
+
function z(e, t) {
|
|
1926
1927
|
for (let n = e.length - 1; n >= 0; --n) {
|
|
1927
1928
|
let r = e[n];
|
|
1928
1929
|
if (r !== void 0 && t(r)) return n;
|
|
1929
1930
|
}
|
|
1930
1931
|
return -1;
|
|
1931
1932
|
}
|
|
1932
|
-
function
|
|
1933
|
+
function Mn(e, t) {
|
|
1933
1934
|
return e.includes(t) ? [...e] : [...e, t];
|
|
1934
1935
|
}
|
|
1935
|
-
function
|
|
1936
|
+
function Nn(e, t) {
|
|
1936
1937
|
return [e?.trim() ?? "", ...t.map((e) => `${e.status === "completed" ? "- [x]" : "- [ ]"} ${e.step}`)].filter(Boolean).join("\n");
|
|
1937
1938
|
}
|
|
1938
|
-
function
|
|
1939
|
+
function Pn(e, t, n) {
|
|
1939
1940
|
return {
|
|
1940
1941
|
type: "tool",
|
|
1941
1942
|
id: `plan-progress-${e}`,
|
|
@@ -1958,19 +1959,19 @@ function An(e, t, n) {
|
|
|
1958
1959
|
}
|
|
1959
1960
|
//#endregion
|
|
1960
1961
|
//#region src/node/codex-conversation-history.ts
|
|
1961
|
-
var
|
|
1962
|
+
var Fn = 16 * 1024 * 1024, In = /* @__PURE__ */ new Set([
|
|
1962
1963
|
"image/avif",
|
|
1963
1964
|
"image/gif",
|
|
1964
1965
|
"image/jpeg",
|
|
1965
1966
|
"image/png",
|
|
1966
1967
|
"image/webp"
|
|
1967
1968
|
]);
|
|
1968
|
-
function
|
|
1969
|
-
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));
|
|
1970
1971
|
}
|
|
1971
|
-
function
|
|
1972
|
+
function Rn(e, t) {
|
|
1972
1973
|
let n = /* @__PURE__ */ new Map();
|
|
1973
|
-
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);
|
|
1974
1975
|
return n.size === 0 ? [...t] : t.map((e) => {
|
|
1975
1976
|
let t = !1, r = e.parts.map((e) => {
|
|
1976
1977
|
if (e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path) return e;
|
|
@@ -1989,14 +1990,14 @@ function Pn(e, t) {
|
|
|
1989
1990
|
} : e;
|
|
1990
1991
|
});
|
|
1991
1992
|
}
|
|
1992
|
-
function
|
|
1993
|
-
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 = () => {
|
|
1994
1995
|
if (r.length === 0) return;
|
|
1995
1996
|
let o = a === 0 ? "" : `-segment-${a}`;
|
|
1996
1997
|
n.push({
|
|
1997
1998
|
id: `assistant-${t.id}${o}`,
|
|
1998
1999
|
role: "assistant",
|
|
1999
|
-
status:
|
|
2000
|
+
status: tr(t.status),
|
|
2000
2001
|
turnId: t.id,
|
|
2001
2002
|
parts: [...r],
|
|
2002
2003
|
createdAt: i,
|
|
@@ -2008,7 +2009,7 @@ function Fn(e, t) {
|
|
|
2008
2009
|
};
|
|
2009
2010
|
for (let a of Array.isArray(t.items) ? t.items : []) {
|
|
2010
2011
|
if (a.type === "userMessage") {
|
|
2011
|
-
let r =
|
|
2012
|
+
let r = Un(a), l = Gn(a);
|
|
2012
2013
|
if (r.length > 0) {
|
|
2013
2014
|
let u = o, d = u ? null : JSON.stringify(r);
|
|
2014
2015
|
if (d && s.has(d)) continue;
|
|
@@ -2025,7 +2026,7 @@ function Fn(e, t) {
|
|
|
2025
2026
|
turnId: t.id,
|
|
2026
2027
|
...l.length > 0 ? {
|
|
2027
2028
|
asyncQuestionRequestIds: l,
|
|
2028
|
-
asyncQuestionAnswers:
|
|
2029
|
+
asyncQuestionAnswers: Kn(a)
|
|
2029
2030
|
} : {}
|
|
2030
2031
|
}
|
|
2031
2032
|
});
|
|
@@ -2051,7 +2052,7 @@ function Fn(e, t) {
|
|
|
2051
2052
|
continue;
|
|
2052
2053
|
}
|
|
2053
2054
|
if (a.type === "agentMessage") {
|
|
2054
|
-
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;
|
|
2055
2056
|
s && !i ? s.visibleText && (o = !0, r.push({
|
|
2056
2057
|
type: "text",
|
|
2057
2058
|
text: s.visibleText,
|
|
@@ -2087,17 +2088,17 @@ function Fn(e, t) {
|
|
|
2087
2088
|
}));
|
|
2088
2089
|
continue;
|
|
2089
2090
|
}
|
|
2090
|
-
let l =
|
|
2091
|
+
let l = A(a);
|
|
2091
2092
|
l && (o = !0, r.push(l));
|
|
2092
|
-
let u =
|
|
2093
|
+
let u = Hn(a);
|
|
2093
2094
|
u && (o = !0, r.push(u));
|
|
2094
2095
|
}
|
|
2095
|
-
return c(), t.status === "inProgress" ? n :
|
|
2096
|
+
return c(), t.status === "inProgress" ? n : An(n, t.id, t.status);
|
|
2096
2097
|
}
|
|
2097
|
-
function
|
|
2098
|
-
let r =
|
|
2098
|
+
function Bn(e, t, n) {
|
|
2099
|
+
let r = nr(t.startedAt);
|
|
2099
2100
|
if (n.type === "userMessage") {
|
|
2100
|
-
let i =
|
|
2101
|
+
let i = Un(n), a = Gn(n);
|
|
2101
2102
|
return i.length > 0 ? {
|
|
2102
2103
|
id: n.clientId ?? `user-${e}-${t.id}-${n.id}`,
|
|
2103
2104
|
role: "user",
|
|
@@ -2111,13 +2112,13 @@ function In(e, t, n) {
|
|
|
2111
2112
|
itemId: n.id,
|
|
2112
2113
|
...a.length > 0 ? {
|
|
2113
2114
|
asyncQuestionRequestIds: a,
|
|
2114
|
-
asyncQuestionAnswers:
|
|
2115
|
+
asyncQuestionAnswers: Kn(n)
|
|
2115
2116
|
} : {}
|
|
2116
2117
|
}
|
|
2117
2118
|
} : null;
|
|
2118
2119
|
}
|
|
2119
2120
|
if (n.type === "agentMessage" || n.type === "exitedReviewMode") {
|
|
2120
|
-
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) ? [{
|
|
2121
2122
|
type: "text",
|
|
2122
2123
|
text: a?.visibleText ?? i,
|
|
2123
2124
|
itemId: n.id,
|
|
@@ -2126,7 +2127,7 @@ function In(e, t, n) {
|
|
|
2126
2127
|
return s.length > 0 ? {
|
|
2127
2128
|
id: `assistant-${n.id}`,
|
|
2128
2129
|
role: "assistant",
|
|
2129
|
-
status:
|
|
2130
|
+
status: tr(t.status),
|
|
2130
2131
|
turnId: t.id,
|
|
2131
2132
|
parts: s,
|
|
2132
2133
|
createdAt: r,
|
|
@@ -2150,7 +2151,7 @@ function In(e, t, n) {
|
|
|
2150
2151
|
return i.length > 0 ? {
|
|
2151
2152
|
id: `assistant-${n.id}`,
|
|
2152
2153
|
role: "assistant",
|
|
2153
|
-
status:
|
|
2154
|
+
status: tr(t.status),
|
|
2154
2155
|
turnId: t.id,
|
|
2155
2156
|
parts: i,
|
|
2156
2157
|
createdAt: r,
|
|
@@ -2161,14 +2162,14 @@ function In(e, t, n) {
|
|
|
2161
2162
|
}
|
|
2162
2163
|
} : null;
|
|
2163
2164
|
}
|
|
2164
|
-
let i = [], a =
|
|
2165
|
+
let i = [], a = A(n);
|
|
2165
2166
|
a && i.push(a);
|
|
2166
|
-
let o =
|
|
2167
|
+
let o = Hn(n);
|
|
2167
2168
|
o && i.push(o);
|
|
2168
2169
|
let s = i.length > 0 ? {
|
|
2169
2170
|
id: `assistant-${n.id}`,
|
|
2170
2171
|
role: "assistant",
|
|
2171
|
-
status:
|
|
2172
|
+
status: tr(t.status),
|
|
2172
2173
|
turnId: t.id,
|
|
2173
2174
|
parts: i,
|
|
2174
2175
|
createdAt: r,
|
|
@@ -2178,9 +2179,9 @@ function In(e, t, n) {
|
|
|
2178
2179
|
itemId: n.id
|
|
2179
2180
|
}
|
|
2180
2181
|
} : null;
|
|
2181
|
-
return !s || t.status === "inProgress" ? s :
|
|
2182
|
+
return !s || t.status === "inProgress" ? s : An([s], t.id, t.status)[0] ?? null;
|
|
2182
2183
|
}
|
|
2183
|
-
function
|
|
2184
|
+
function Vn(e, t, n, r = !1) {
|
|
2184
2185
|
if (n.delivery !== "async") return null;
|
|
2185
2186
|
let i = n.questions ?? [], a = i.length > 0 ? i.map((e, t) => ({
|
|
2186
2187
|
id: JSON.stringify([
|
|
@@ -2222,9 +2223,9 @@ function Ln(e, t, n, r = !1) {
|
|
|
2222
2223
|
...r ? { historical: !0 } : {}
|
|
2223
2224
|
};
|
|
2224
2225
|
}
|
|
2225
|
-
function
|
|
2226
|
-
if (e.type !== "imageGeneration" ||
|
|
2227
|
-
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);
|
|
2228
2229
|
if (!a) return null;
|
|
2229
2230
|
let o = typeof e.revisedPrompt == "string" ? e.revisedPrompt.trim() : "";
|
|
2230
2231
|
return {
|
|
@@ -2239,7 +2240,7 @@ function Rn(e) {
|
|
|
2239
2240
|
}
|
|
2240
2241
|
};
|
|
2241
2242
|
}
|
|
2242
|
-
function
|
|
2243
|
+
function Un(e) {
|
|
2243
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 = () => {
|
|
2244
2245
|
i.length > 0 && r.push({
|
|
2245
2246
|
type: "text",
|
|
@@ -2253,7 +2254,7 @@ function zn(e) {
|
|
|
2253
2254
|
if (a.has(t)) continue;
|
|
2254
2255
|
a.add(t);
|
|
2255
2256
|
}
|
|
2256
|
-
let t =
|
|
2257
|
+
let t = Wn(e), s = Pt(t);
|
|
2257
2258
|
if (s) {
|
|
2258
2259
|
o(), r.push({
|
|
2259
2260
|
type: "attachment",
|
|
@@ -2268,7 +2269,7 @@ function zn(e) {
|
|
|
2268
2269
|
i.push(t);
|
|
2269
2270
|
continue;
|
|
2270
2271
|
}
|
|
2271
|
-
let c =
|
|
2272
|
+
let c = Jn(e);
|
|
2272
2273
|
c && (o(), r.push({
|
|
2273
2274
|
type: "attachment",
|
|
2274
2275
|
attachment: c
|
|
@@ -2276,20 +2277,20 @@ function zn(e) {
|
|
|
2276
2277
|
}
|
|
2277
2278
|
return o(), r;
|
|
2278
2279
|
}
|
|
2279
|
-
function
|
|
2280
|
-
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}` : "";
|
|
2281
2282
|
}
|
|
2282
|
-
function
|
|
2283
|
+
function Gn(e) {
|
|
2283
2284
|
let t = /* @__PURE__ */ new Set();
|
|
2284
|
-
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);
|
|
2285
2286
|
return [...t];
|
|
2286
2287
|
}
|
|
2287
|
-
function
|
|
2288
|
+
function Kn(e) {
|
|
2288
2289
|
let t = {};
|
|
2289
|
-
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);
|
|
2290
2291
|
return t;
|
|
2291
2292
|
}
|
|
2292
|
-
function
|
|
2293
|
+
function qn(e) {
|
|
2293
2294
|
let t = e.match(/^<send_user_message_question_reply>\s*([\s\S]*?)\s*<\/send_user_message_question_reply>$/);
|
|
2294
2295
|
if (!t?.[1]) return null;
|
|
2295
2296
|
try {
|
|
@@ -2313,10 +2314,10 @@ function Un(e) {
|
|
|
2313
2314
|
return null;
|
|
2314
2315
|
}
|
|
2315
2316
|
}
|
|
2316
|
-
function
|
|
2317
|
+
function Jn(e) {
|
|
2317
2318
|
if (!B(e) || typeof e.type != "string") return null;
|
|
2318
2319
|
if (e.type === "mention" && typeof e.path == "string") {
|
|
2319
|
-
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);
|
|
2320
2321
|
return {
|
|
2321
2322
|
kind: "file",
|
|
2322
2323
|
name: t,
|
|
@@ -2325,41 +2326,41 @@ function Wn(e) {
|
|
|
2325
2326
|
};
|
|
2326
2327
|
}
|
|
2327
2328
|
if (e.type === "image" && typeof e.url == "string") {
|
|
2328
|
-
let t =
|
|
2329
|
+
let t = Xn(e.url);
|
|
2329
2330
|
return {
|
|
2330
2331
|
kind: "image",
|
|
2331
|
-
name:
|
|
2332
|
+
name: Yn(e.url, "Image"),
|
|
2332
2333
|
url: e.url,
|
|
2333
2334
|
...t ? { mimeType: t } : {}
|
|
2334
2335
|
};
|
|
2335
2336
|
}
|
|
2336
2337
|
if (e.type === "localImage" && typeof e.path == "string") {
|
|
2337
|
-
let t =
|
|
2338
|
+
let t = Xn(e.path);
|
|
2338
2339
|
return {
|
|
2339
2340
|
kind: "image",
|
|
2340
|
-
name:
|
|
2341
|
+
name: Yn(e.path, "Image"),
|
|
2341
2342
|
path: e.path,
|
|
2342
2343
|
...t ? { mimeType: t } : {}
|
|
2343
2344
|
};
|
|
2344
2345
|
}
|
|
2345
2346
|
return null;
|
|
2346
2347
|
}
|
|
2347
|
-
function
|
|
2348
|
+
function Yn(e, t) {
|
|
2348
2349
|
try {
|
|
2349
2350
|
let n = /^[a-z][a-z\d+.-]*:/i.test(e) ? new URL(e).pathname : e;
|
|
2350
|
-
return
|
|
2351
|
+
return g(decodeURIComponent(n)).trim() || t;
|
|
2351
2352
|
} catch {
|
|
2352
|
-
return
|
|
2353
|
+
return g(e).trim() || t;
|
|
2353
2354
|
}
|
|
2354
2355
|
}
|
|
2355
|
-
function
|
|
2356
|
+
function Xn(e) {
|
|
2356
2357
|
let t = /^data:([^;,]+)/i.exec(e)?.[1]?.toLowerCase();
|
|
2357
2358
|
if (t) return t;
|
|
2358
2359
|
let n = "";
|
|
2359
2360
|
try {
|
|
2360
|
-
n =
|
|
2361
|
+
n = _(/^[a-z][a-z\d+.-]*:/i.test(e) ? new URL(e).pathname : e).slice(1).toLowerCase();
|
|
2361
2362
|
} catch {
|
|
2362
|
-
n =
|
|
2363
|
+
n = _(e).slice(1).toLowerCase();
|
|
2363
2364
|
}
|
|
2364
2365
|
return {
|
|
2365
2366
|
avif: "image/avif",
|
|
@@ -2374,23 +2375,23 @@ function R(e) {
|
|
|
2374
2375
|
webp: "image/webp"
|
|
2375
2376
|
}[n];
|
|
2376
2377
|
}
|
|
2377
|
-
function
|
|
2378
|
+
function Zn(e) {
|
|
2378
2379
|
if (!e) return null;
|
|
2379
|
-
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;
|
|
2380
2381
|
if (!t || t.length > n || t.length % 4 != 0 || !/^[a-z0-9+/]+={0,2}$/i.test(t)) return null;
|
|
2381
2382
|
let r = Buffer.from(t, "base64");
|
|
2382
|
-
if (r.byteLength === 0 || r.byteLength >
|
|
2383
|
-
let i =
|
|
2383
|
+
if (r.byteLength === 0 || r.byteLength > Fn) return null;
|
|
2384
|
+
let i = $n(r);
|
|
2384
2385
|
return i ? {
|
|
2385
2386
|
url: `data:${i};base64,${t}`,
|
|
2386
2387
|
mimeType: i
|
|
2387
2388
|
} : null;
|
|
2388
2389
|
}
|
|
2389
|
-
function
|
|
2390
|
+
function Qn(e) {
|
|
2390
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));
|
|
2391
2392
|
}
|
|
2392
|
-
function
|
|
2393
|
-
if (
|
|
2393
|
+
function $n(e) {
|
|
2394
|
+
if (er(e, [
|
|
2394
2395
|
137,
|
|
2395
2396
|
80,
|
|
2396
2397
|
78,
|
|
@@ -2400,7 +2401,7 @@ function Jn(e) {
|
|
|
2400
2401
|
26,
|
|
2401
2402
|
10
|
|
2402
2403
|
])) return "image/png";
|
|
2403
|
-
if (
|
|
2404
|
+
if (er(e, [
|
|
2404
2405
|
255,
|
|
2405
2406
|
216,
|
|
2406
2407
|
255
|
|
@@ -2408,13 +2409,13 @@ function Jn(e) {
|
|
|
2408
2409
|
let t = Buffer.from(e.subarray(0, 12)).toString("ascii");
|
|
2409
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;
|
|
2410
2411
|
}
|
|
2411
|
-
function
|
|
2412
|
+
function er(e, t) {
|
|
2412
2413
|
return t.every((t, n) => e[n] === t);
|
|
2413
2414
|
}
|
|
2414
|
-
function
|
|
2415
|
+
function tr(e) {
|
|
2415
2416
|
return e === "inProgress" ? "streaming" : e === "failed" ? "error" : "complete";
|
|
2416
2417
|
}
|
|
2417
|
-
function
|
|
2418
|
+
function nr(e) {
|
|
2418
2419
|
return typeof e != "number" || !Number.isFinite(e) ? (/* @__PURE__ */ new Date(0)).toISOString() : (/* @__PURE__ */ new Date(e * 1e3)).toISOString();
|
|
2419
2420
|
}
|
|
2420
2421
|
function B(e) {
|
|
@@ -2422,21 +2423,21 @@ function B(e) {
|
|
|
2422
2423
|
}
|
|
2423
2424
|
//#endregion
|
|
2424
2425
|
//#region src/node/codex-raw-response-item-adapter.ts
|
|
2425
|
-
function
|
|
2426
|
-
if (!
|
|
2426
|
+
function rr(e) {
|
|
2427
|
+
if (!fr(e) || typeof e.type != "string") return null;
|
|
2427
2428
|
if (e.type === "local_shell_call") {
|
|
2428
|
-
let t =
|
|
2429
|
+
let t = A(ir(e));
|
|
2429
2430
|
return {
|
|
2430
|
-
type:
|
|
2431
|
+
type: cr(e.status) ? "item.completed" : "item.started",
|
|
2431
2432
|
payload: { toolPart: t }
|
|
2432
2433
|
};
|
|
2433
2434
|
}
|
|
2434
2435
|
return e.type === "function_call" ? {
|
|
2435
2436
|
type: "item.started",
|
|
2436
|
-
payload: { toolPart:
|
|
2437
|
-
} : 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" ? {
|
|
2438
2439
|
type: "item.started",
|
|
2439
|
-
payload: { toolPart:
|
|
2440
|
+
payload: { toolPart: A({
|
|
2440
2441
|
type: "dynamicToolCall",
|
|
2441
2442
|
id: H(e.call_id) ?? V(e),
|
|
2442
2443
|
namespace: null,
|
|
@@ -2447,9 +2448,9 @@ function Zn(e) {
|
|
|
2447
2448
|
success: null,
|
|
2448
2449
|
durationMs: null
|
|
2449
2450
|
}) }
|
|
2450
|
-
} : 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" ? {
|
|
2451
2452
|
type: "item.started",
|
|
2452
|
-
payload: { toolPart:
|
|
2453
|
+
payload: { toolPart: A({
|
|
2453
2454
|
type: "dynamicToolCall",
|
|
2454
2455
|
id: H(e.call_id) ?? V(e),
|
|
2455
2456
|
namespace: "codex",
|
|
@@ -2463,18 +2464,18 @@ function Zn(e) {
|
|
|
2463
2464
|
}) }
|
|
2464
2465
|
} : e.type === "tool_search_output" ? {
|
|
2465
2466
|
type: "item.updated",
|
|
2466
|
-
payload:
|
|
2467
|
+
payload: Gt(H(e.call_id) ?? V(e), e.tools, "tool_search", e.status)
|
|
2467
2468
|
} : e.type === "web_search_call" ? {
|
|
2468
2469
|
type: "item.completed",
|
|
2469
|
-
payload: { toolPart:
|
|
2470
|
+
payload: { toolPart: A({
|
|
2470
2471
|
type: "webSearch",
|
|
2471
2472
|
id: V(e),
|
|
2472
|
-
query:
|
|
2473
|
+
query: ur(e.action),
|
|
2473
2474
|
action: e.action
|
|
2474
2475
|
}) }
|
|
2475
2476
|
} : e.type === "image_generation_call" ? {
|
|
2476
2477
|
type: "item.completed",
|
|
2477
|
-
payload: { toolPart:
|
|
2478
|
+
payload: { toolPart: A({
|
|
2478
2479
|
type: "dynamicToolCall",
|
|
2479
2480
|
id: H(e.id) ?? V(e),
|
|
2480
2481
|
namespace: null,
|
|
@@ -2487,8 +2488,8 @@ function Zn(e) {
|
|
|
2487
2488
|
}) }
|
|
2488
2489
|
} : null;
|
|
2489
2490
|
}
|
|
2490
|
-
function
|
|
2491
|
-
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";
|
|
2492
2493
|
return {
|
|
2493
2494
|
type: "commandExecution",
|
|
2494
2495
|
id: H(e.call_id) ?? V(e),
|
|
@@ -2496,16 +2497,16 @@ function Qn(e) {
|
|
|
2496
2497
|
cwd: H(t.working_directory) ?? "",
|
|
2497
2498
|
processId: null,
|
|
2498
2499
|
source: "agent",
|
|
2499
|
-
status:
|
|
2500
|
+
status: sr(e.status),
|
|
2500
2501
|
commandActions: [],
|
|
2501
2502
|
aggregatedOutput: null,
|
|
2502
2503
|
exitCode: null,
|
|
2503
2504
|
durationMs: null
|
|
2504
2505
|
};
|
|
2505
2506
|
}
|
|
2506
|
-
function
|
|
2507
|
-
let t = H(e.name) ?? "function_call", n =
|
|
2508
|
-
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) ? {
|
|
2509
2510
|
type: "commandExecution",
|
|
2510
2511
|
id: r,
|
|
2511
2512
|
command: H(n.command) ?? t,
|
|
@@ -2529,19 +2530,19 @@ function $n(e) {
|
|
|
2529
2530
|
durationMs: null
|
|
2530
2531
|
};
|
|
2531
2532
|
}
|
|
2532
|
-
function
|
|
2533
|
+
function or(e, t, n) {
|
|
2533
2534
|
return {
|
|
2534
2535
|
type: "item.updated",
|
|
2535
|
-
payload:
|
|
2536
|
+
payload: Gt(H(e) ?? "raw-response-output", t, n)
|
|
2536
2537
|
};
|
|
2537
2538
|
}
|
|
2538
|
-
function
|
|
2539
|
+
function sr(e) {
|
|
2539
2540
|
return e === "completed" ? "completed" : e === "incomplete" || e === "failed" || e === "error" ? "failed" : "inProgress";
|
|
2540
2541
|
}
|
|
2541
|
-
function
|
|
2542
|
+
function cr(e) {
|
|
2542
2543
|
return e === "completed" || e === "failed" || e === "error" || e === "incomplete";
|
|
2543
2544
|
}
|
|
2544
|
-
function
|
|
2545
|
+
function lr(e) {
|
|
2545
2546
|
if (typeof e != "string") return e;
|
|
2546
2547
|
try {
|
|
2547
2548
|
return JSON.parse(e);
|
|
@@ -2549,10 +2550,10 @@ function rr(e) {
|
|
|
2549
2550
|
return e;
|
|
2550
2551
|
}
|
|
2551
2552
|
}
|
|
2552
|
-
function
|
|
2553
|
-
return
|
|
2553
|
+
function ur(e) {
|
|
2554
|
+
return fr(e) ? H(e.query) ?? H(e.searchTerm) ?? "web search" : "web search";
|
|
2554
2555
|
}
|
|
2555
|
-
function
|
|
2556
|
+
function dr(e) {
|
|
2556
2557
|
return e.map((e) => {
|
|
2557
2558
|
let t = String(e);
|
|
2558
2559
|
return /\s/.test(t) ? JSON.stringify(t) : t;
|
|
@@ -2564,21 +2565,21 @@ function V(e) {
|
|
|
2564
2565
|
function H(e) {
|
|
2565
2566
|
return typeof e == "string" && e.length > 0 ? e : null;
|
|
2566
2567
|
}
|
|
2567
|
-
function
|
|
2568
|
+
function fr(e) {
|
|
2568
2569
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
2569
2570
|
}
|
|
2570
2571
|
//#endregion
|
|
2571
2572
|
//#region src/node/codex-surface-events.ts
|
|
2572
|
-
function
|
|
2573
|
+
function pr(e, t) {
|
|
2573
2574
|
return `${e}\u0000${t}`;
|
|
2574
2575
|
}
|
|
2575
2576
|
function U(e) {
|
|
2576
2577
|
return typeof e == "number" && Number.isFinite(e) ? (/* @__PURE__ */ new Date(e * 1e3)).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
|
|
2577
2578
|
}
|
|
2578
|
-
function
|
|
2579
|
+
function mr(e) {
|
|
2579
2580
|
return typeof e == "number" && Number.isFinite(e) ? (/* @__PURE__ */ new Date(e * 1e3)).toISOString() : null;
|
|
2580
2581
|
}
|
|
2581
|
-
function
|
|
2582
|
+
function hr(e) {
|
|
2582
2583
|
return e ? {
|
|
2583
2584
|
message: e.message,
|
|
2584
2585
|
additionalDetails: e.additionalDetails,
|
|
@@ -2589,10 +2590,10 @@ function W(e, t = !1) {
|
|
|
2589
2590
|
return {
|
|
2590
2591
|
id: e.id,
|
|
2591
2592
|
status: e.status,
|
|
2592
|
-
error:
|
|
2593
|
+
error: hr(e.error),
|
|
2593
2594
|
willRetry: t,
|
|
2594
|
-
startedAt:
|
|
2595
|
-
completedAt:
|
|
2595
|
+
startedAt: mr(e.startedAt),
|
|
2596
|
+
completedAt: mr(e.completedAt),
|
|
2596
2597
|
durationMs: e.durationMs ?? null
|
|
2597
2598
|
};
|
|
2598
2599
|
}
|
|
@@ -2602,18 +2603,18 @@ function G(e, t) {
|
|
|
2602
2603
|
let r = [...e];
|
|
2603
2604
|
return r.splice(n, 1, t), r;
|
|
2604
2605
|
}
|
|
2605
|
-
function
|
|
2606
|
+
function gr(e, t) {
|
|
2606
2607
|
return JSON.stringify(e) === JSON.stringify(t);
|
|
2607
2608
|
}
|
|
2608
|
-
function
|
|
2609
|
+
function _r() {
|
|
2609
2610
|
return `user-${globalThis.crypto.randomUUID()}`;
|
|
2610
2611
|
}
|
|
2611
|
-
function
|
|
2612
|
+
function vr() {
|
|
2612
2613
|
return `queued-prompt-${globalThis.crypto.randomUUID()}`;
|
|
2613
2614
|
}
|
|
2614
2615
|
//#endregion
|
|
2615
2616
|
//#region src/node/codex-surface-subagents.ts
|
|
2616
|
-
function
|
|
2617
|
+
function yr(e) {
|
|
2617
2618
|
let t = {};
|
|
2618
2619
|
for (let [n, r] of Object.entries(e.agentsStates)) r && (t[n] = {
|
|
2619
2620
|
status: r.status,
|
|
@@ -2633,7 +2634,7 @@ function pr(e) {
|
|
|
2633
2634
|
}
|
|
2634
2635
|
//#endregion
|
|
2635
2636
|
//#region src/node/codex-surface-items-controller.ts
|
|
2636
|
-
var
|
|
2637
|
+
var br = class {
|
|
2637
2638
|
host;
|
|
2638
2639
|
commandOutputForwardItemIds = /* @__PURE__ */ new Set();
|
|
2639
2640
|
fileActivityKeys = /* @__PURE__ */ new Set();
|
|
@@ -2651,13 +2652,13 @@ var mr = class {
|
|
|
2651
2652
|
for (let e of this.reviewOutputByTurn.keys()) e.startsWith(t) && this.reviewOutputByTurn.delete(e);
|
|
2652
2653
|
}
|
|
2653
2654
|
isForwardingCommandOutput(e, t) {
|
|
2654
|
-
return this.commandOutputForwardItemIds.has(
|
|
2655
|
+
return this.commandOutputForwardItemIds.has(pr(e, t));
|
|
2655
2656
|
}
|
|
2656
2657
|
applyAgentDelta(e) {
|
|
2657
2658
|
let t = this.host.requireRuntime(e.threadId);
|
|
2658
2659
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
2659
2660
|
let n = t.messages.flatMap((e) => e.parts).find((t) => t.type === "text" && t.itemId === e.itemId)?.phase;
|
|
2660
|
-
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) });
|
|
2661
2662
|
let r = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2662
2663
|
r && this.host.emitEvent("notification", {
|
|
2663
2664
|
type: "message.delta",
|
|
@@ -2675,7 +2676,7 @@ var mr = class {
|
|
|
2675
2676
|
let t = this.host.requireRuntime(e.threadId);
|
|
2676
2677
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
2677
2678
|
let n = `${t.planMarkdownByTurn.get(e.turnId) ?? ""}${e.delta}`;
|
|
2678
|
-
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", {
|
|
2679
2680
|
type: "plan.delta",
|
|
2680
2681
|
conversationId: e.threadId,
|
|
2681
2682
|
turnId: e.turnId,
|
|
@@ -2689,7 +2690,7 @@ var mr = class {
|
|
|
2689
2690
|
applyPlanUpdated(e) {
|
|
2690
2691
|
let t = this.host.requireRuntime(e.threadId);
|
|
2691
2692
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
2692
|
-
let n =
|
|
2693
|
+
let n = Nn(e.explanation, e.plan), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
2693
2694
|
t.planMarkdownByTurn.set(e.turnId, n), this.host.patchRuntime(e.threadId, {
|
|
2694
2695
|
executionPlan: {
|
|
2695
2696
|
turnId: e.turnId,
|
|
@@ -2698,7 +2699,7 @@ var mr = class {
|
|
|
2698
2699
|
markdown: n,
|
|
2699
2700
|
updatedAt: r
|
|
2700
2701
|
},
|
|
2701
|
-
messages:
|
|
2702
|
+
messages: L(t.messages, e.threadId, e.turnId, Pn(e.turnId, n, "completed"))
|
|
2702
2703
|
}), this.host.emitEvent("notification", {
|
|
2703
2704
|
type: "plan.updated",
|
|
2704
2705
|
conversationId: e.threadId,
|
|
@@ -2714,13 +2715,13 @@ var mr = class {
|
|
|
2714
2715
|
applyRawResponseItem(e) {
|
|
2715
2716
|
let t = this.host.requireRuntime(e.threadId);
|
|
2716
2717
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
2717
|
-
let n =
|
|
2718
|
+
let n = rr(e.item);
|
|
2718
2719
|
if (!n) return;
|
|
2719
2720
|
if (n.type === "item.updated") {
|
|
2720
2721
|
this.applyToolUpdate(e.threadId, e.turnId, n.payload);
|
|
2721
2722
|
return;
|
|
2722
2723
|
}
|
|
2723
|
-
this.host.patchRuntime(e.threadId, { messages:
|
|
2724
|
+
this.host.patchRuntime(e.threadId, { messages: L(t.messages, e.threadId, e.turnId, n.payload.toolPart) });
|
|
2724
2725
|
let r = this.host.messageContainingTool(e.threadId, e.turnId, n.payload.toolPart.id);
|
|
2725
2726
|
r && (this.host.emitEvent("notification", {
|
|
2726
2727
|
type: n.type === "item.completed" ? "tool.completed" : "tool.started",
|
|
@@ -2741,7 +2742,7 @@ var mr = class {
|
|
|
2741
2742
|
startedAt: ("startedAtMs" in e ? e.startedAtMs : e.completedAtMs) / 1e3
|
|
2742
2743
|
};
|
|
2743
2744
|
if (e.item.type === "userMessage") {
|
|
2744
|
-
let t =
|
|
2745
|
+
let t = Bn(e.threadId, i, e.item);
|
|
2745
2746
|
if (!t || n.messages.some((e) => e.id === t.id)) return;
|
|
2746
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;
|
|
2747
2748
|
if (o >= 0) {
|
|
@@ -2767,7 +2768,7 @@ var mr = class {
|
|
|
2767
2768
|
...t,
|
|
2768
2769
|
kind: "steer"
|
|
2769
2770
|
} : t, c = [...n.messages, s];
|
|
2770
|
-
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", {
|
|
2771
2772
|
type: "message.appended",
|
|
2772
2773
|
conversationId: e.threadId,
|
|
2773
2774
|
turnId: e.turnId,
|
|
@@ -2778,7 +2779,7 @@ var mr = class {
|
|
|
2778
2779
|
if (e.item.type === "reasoning") {
|
|
2779
2780
|
if (e.item.summary.filter((e) => e.trim().length > 0).length === 0) return;
|
|
2780
2781
|
let t = this.host.assistantMessageForTurn(e.threadId, e.turnId), r = t ? JSON.stringify(t.parts) : null;
|
|
2781
|
-
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) });
|
|
2782
2783
|
let i = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2783
2784
|
if (!i || JSON.stringify(i.parts) === r) return;
|
|
2784
2785
|
this.host.emitEvent("notification", {
|
|
@@ -2790,10 +2791,10 @@ var mr = class {
|
|
|
2790
2791
|
return;
|
|
2791
2792
|
}
|
|
2792
2793
|
if (e.item.type === "agentMessage" && t && n.planMode && e.item.phase === "final_answer") {
|
|
2793
|
-
let t =
|
|
2794
|
+
let t = wn(e.item.text);
|
|
2794
2795
|
if (t) {
|
|
2795
|
-
let r = this.host.assistantMessageForTurn(e.threadId, e.turnId), i =
|
|
2796
|
-
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 });
|
|
2797
2798
|
let a = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2798
2799
|
a && this.host.emitEvent("notification", {
|
|
2799
2800
|
type: r ? "message.updated" : "message.appended",
|
|
@@ -2815,11 +2816,11 @@ var mr = class {
|
|
|
2815
2816
|
if (e.item.type === "agentMessage" || e.item.type === "exitedReviewMode") {
|
|
2816
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;
|
|
2817
2818
|
if (!t && e.item.type !== "agentMessage") return;
|
|
2818
|
-
let i =
|
|
2819
|
+
let i = pr(e.threadId, e.turnId);
|
|
2819
2820
|
if (e.item.type === "agentMessage" && this.reviewOutputByTurn.get(i) === t) return;
|
|
2820
2821
|
e.item.type === "exitedReviewMode" && this.reviewOutputByTurn.set(i, t);
|
|
2821
|
-
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" ?
|
|
2822
|
-
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;
|
|
2823
2824
|
let p = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2824
2825
|
if (p && !a.has(p.id)) this.host.emitEvent("notification", {
|
|
2825
2826
|
type: "message.appended",
|
|
@@ -2863,7 +2864,7 @@ var mr = class {
|
|
|
2863
2864
|
if (e.item.type === "plan") {
|
|
2864
2865
|
if (!t) return;
|
|
2865
2866
|
let r = e.item.text.trim() || n.planMarkdownByTurn.get(e.turnId) || "";
|
|
2866
|
-
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", {
|
|
2867
2868
|
type: "plan.completed",
|
|
2868
2869
|
conversationId: e.threadId,
|
|
2869
2870
|
turnId: e.turnId,
|
|
@@ -2875,7 +2876,7 @@ var mr = class {
|
|
|
2875
2876
|
return;
|
|
2876
2877
|
}
|
|
2877
2878
|
if (e.item.type === "contextCompaction") {
|
|
2878
|
-
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) {
|
|
2879
2880
|
let t = this.host.requireRuntime(e.threadId).messages.find((t) => t.kind === "compaction" && t.metadata?.turnId === e.turnId);
|
|
2880
2881
|
t && this.host.emitEvent("notification", {
|
|
2881
2882
|
type: "context.compactionCompleted",
|
|
@@ -2901,7 +2902,7 @@ var mr = class {
|
|
|
2901
2902
|
turnId: e.turnId,
|
|
2902
2903
|
payload: {
|
|
2903
2904
|
lifecycle: t ? "completed" : "started",
|
|
2904
|
-
toolCall:
|
|
2905
|
+
toolCall: yr(e.item)
|
|
2905
2906
|
}
|
|
2906
2907
|
});
|
|
2907
2908
|
return;
|
|
@@ -2923,13 +2924,13 @@ var mr = class {
|
|
|
2923
2924
|
});
|
|
2924
2925
|
return;
|
|
2925
2926
|
}
|
|
2926
|
-
let a = this.shouldForwardCommandOutput(e.threadId, t, e.item), o =
|
|
2927
|
+
let a = this.shouldForwardCommandOutput(e.threadId, t, e.item), o = A(e.item, {
|
|
2927
2928
|
includeCommandOutput: a,
|
|
2928
2929
|
cwd: n.cwd
|
|
2929
|
-
}), s =
|
|
2930
|
+
}), s = Hn(e.item);
|
|
2930
2931
|
if (!o && !s) return;
|
|
2931
|
-
let c = s ? !n.messages.some((e) => e.parts.some((e) => e.type === "media" &&
|
|
2932
|
-
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 });
|
|
2933
2934
|
let u = o ? this.host.messageContainingTool(e.threadId, e.turnId, o.id) : this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
2934
2935
|
u && o && this.host.emitEvent("notification", {
|
|
2935
2936
|
type: t ? "tool.completed" : "tool.started",
|
|
@@ -2949,25 +2950,25 @@ var mr = class {
|
|
|
2949
2950
|
shouldForwardCommandOutput(e, t, n) {
|
|
2950
2951
|
let r = "id" in n && typeof n.id == "string" ? n.id : null;
|
|
2951
2952
|
if (!r) return !1;
|
|
2952
|
-
let i =
|
|
2953
|
+
let i = pr(e, r);
|
|
2953
2954
|
if (!t) {
|
|
2954
|
-
let e =
|
|
2955
|
+
let e = Vt(n);
|
|
2955
2956
|
return e ? this.commandOutputForwardItemIds.add(i) : this.commandOutputForwardItemIds.delete(i), e;
|
|
2956
2957
|
}
|
|
2957
|
-
let a = this.commandOutputForwardItemIds.has(i) ||
|
|
2958
|
+
let a = this.commandOutputForwardItemIds.has(i) || Vt(n);
|
|
2958
2959
|
return this.commandOutputForwardItemIds.delete(i), a;
|
|
2959
2960
|
}
|
|
2960
2961
|
applyToolUpdate(e, t, n) {
|
|
2961
2962
|
let r = this.host.requireRuntime(e);
|
|
2962
2963
|
this.host.markRuntimeTurnActive(r, t);
|
|
2963
|
-
let i = r.cwd &&
|
|
2964
|
+
let i = r.cwd && xr(n) ? {
|
|
2964
2965
|
...n,
|
|
2965
2966
|
metadata: {
|
|
2966
2967
|
...n.metadata,
|
|
2967
2968
|
cwd: r.cwd
|
|
2968
2969
|
}
|
|
2969
2970
|
} : n;
|
|
2970
|
-
this.host.patchRuntime(e, { messages:
|
|
2971
|
+
this.host.patchRuntime(e, { messages: On(r.messages, e, t, i) });
|
|
2971
2972
|
let a = this.host.messageContainingTool(e, t, n.itemId);
|
|
2972
2973
|
a && this.host.emitEvent("notification", {
|
|
2973
2974
|
type: "tool.updated",
|
|
@@ -2982,7 +2983,7 @@ var mr = class {
|
|
|
2982
2983
|
a && o && this.emitFileActivities(e, t, a.id, o.id, o, r.cwd);
|
|
2983
2984
|
}
|
|
2984
2985
|
emitFileActivities(e, t, n, r, i, a) {
|
|
2985
|
-
for (let o of
|
|
2986
|
+
for (let o of Bt(i, a)) {
|
|
2986
2987
|
let i = `${e}\u0000${r}\u0000${o.action}\u0000${o.path}\u0000${o.status}`;
|
|
2987
2988
|
this.fileActivityKeys.has(i) || (this.fileActivityKeys.add(i), this.host.emitEvent("notification", {
|
|
2988
2989
|
type: "file.activity",
|
|
@@ -3003,7 +3004,7 @@ var mr = class {
|
|
|
3003
3004
|
t.turnIds.includes(e.turn.id) || t.turnIds.push(e.turn.id);
|
|
3004
3005
|
let n = t.activeTurnId !== e.turn.id && t.turnStartPending;
|
|
3005
3006
|
t.activeTurnId === e.turn.id && (t.activeTurnId = null);
|
|
3006
|
-
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 ? {
|
|
3007
3008
|
...t,
|
|
3008
3009
|
status: i
|
|
3009
3010
|
} : t).filter((t) => !(t.role === "assistant" && t.metadata?.turnId === e.turn.id && t.kind === void 0 && t.parts.length === 0));
|
|
@@ -3029,26 +3030,26 @@ var mr = class {
|
|
|
3029
3030
|
turnId: e.turn.id,
|
|
3030
3031
|
payload: {
|
|
3031
3032
|
status: e.turn.status,
|
|
3032
|
-
error:
|
|
3033
|
+
error: hr(e.turn.error),
|
|
3033
3034
|
willRetry: !1,
|
|
3034
|
-
startedAt:
|
|
3035
|
-
completedAt:
|
|
3035
|
+
startedAt: mr(e.turn.startedAt),
|
|
3036
|
+
completedAt: mr(e.turn.completedAt),
|
|
3036
3037
|
durationMs: e.turn.durationMs ?? null
|
|
3037
3038
|
}
|
|
3038
3039
|
}), this.host.emitConversationActivity(e.threadId, "notification"), t.planMarkdownByTurn.delete(e.turn.id), this.host.sendNextQueuedPrompt(e.threadId);
|
|
3039
3040
|
}
|
|
3040
3041
|
};
|
|
3041
|
-
function
|
|
3042
|
+
function xr(e) {
|
|
3042
3043
|
if (e.fallbackToolPart?.kind === "fileChange") return !0;
|
|
3043
3044
|
let t = e.input, n = e.metadata;
|
|
3044
|
-
return
|
|
3045
|
+
return Sr(t) && Array.isArray(t.changes) || Sr(n) && Array.isArray(n.changes);
|
|
3045
3046
|
}
|
|
3046
|
-
function
|
|
3047
|
+
function Sr(e) {
|
|
3047
3048
|
return typeof e == "object" && !!e;
|
|
3048
3049
|
}
|
|
3049
3050
|
//#endregion
|
|
3050
3051
|
//#region src/node/codex-surface-client-requests-controller.ts
|
|
3051
|
-
var
|
|
3052
|
+
var Cr = class {
|
|
3052
3053
|
host;
|
|
3053
3054
|
pending = /* @__PURE__ */ new Map();
|
|
3054
3055
|
constructor(e) {
|
|
@@ -3097,21 +3098,21 @@ var _r = class {
|
|
|
3097
3098
|
"deny"
|
|
3098
3099
|
].includes(r)) throw Error(`Invalid tool confirmation decision '${String(r)}'`);
|
|
3099
3100
|
this.pending.delete(t.id);
|
|
3100
|
-
let i = this.host.requireRuntime(n.threadId), a =
|
|
3101
|
+
let i = this.host.requireRuntime(n.threadId), a = Mn(i.answeredClientRequestIds, t.id);
|
|
3101
3102
|
if (n.kind === "ask_user") {
|
|
3102
3103
|
let e = t.payload?.answers ?? {};
|
|
3103
3104
|
n.responder.resolve({ answers: e }), this.host.patchRuntime(n.threadId, {
|
|
3104
3105
|
answeredClientRequestIds: a,
|
|
3105
|
-
messages:
|
|
3106
|
+
messages: On(i.messages, n.threadId, n.turnId, {
|
|
3106
3107
|
itemId: n.itemId,
|
|
3107
3108
|
output: { answers: e }
|
|
3108
3109
|
})
|
|
3109
3110
|
});
|
|
3110
3111
|
} else {
|
|
3111
3112
|
let e = r;
|
|
3112
|
-
n.responder.resolve(
|
|
3113
|
+
n.responder.resolve(Ze(e)), this.host.patchRuntime(n.threadId, {
|
|
3113
3114
|
answeredClientRequestIds: a,
|
|
3114
|
-
messages:
|
|
3115
|
+
messages: On(i.messages, n.threadId, n.displayTurnId, {
|
|
3115
3116
|
itemId: n.itemId,
|
|
3116
3117
|
output: { decision: e }
|
|
3117
3118
|
})
|
|
@@ -3150,7 +3151,7 @@ var _r = class {
|
|
|
3150
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");
|
|
3151
3152
|
await this.host.answerAsyncQuestion(a.runtime.threadId, e, t);
|
|
3152
3153
|
}
|
|
3153
|
-
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", {
|
|
3154
3155
|
type: "clientRequest.resolved",
|
|
3155
3156
|
conversationId: a.runtime.threadId,
|
|
3156
3157
|
...a.request.turnId ? { turnId: a.request.turnId } : {},
|
|
@@ -3165,7 +3166,7 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3165
3166
|
let n = this.pending.get(e);
|
|
3166
3167
|
if (this.pending.delete(e), n) {
|
|
3167
3168
|
let t = this.host.requireRuntime(n.threadId);
|
|
3168
|
-
this.host.patchRuntime(n.threadId, { answeredClientRequestIds:
|
|
3169
|
+
this.host.patchRuntime(n.threadId, { answeredClientRequestIds: Mn(t.answeredClientRequestIds, e) });
|
|
3169
3170
|
}
|
|
3170
3171
|
this.maybeClearWaitingBusy(t), n && this.host.emitEvent("notification", {
|
|
3171
3172
|
type: "clientRequest.resolved",
|
|
@@ -3213,7 +3214,7 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3213
3214
|
responder: t
|
|
3214
3215
|
}), this.host.patchRuntime(n, {
|
|
3215
3216
|
busy: !0,
|
|
3216
|
-
messages:
|
|
3217
|
+
messages: L(o.messages, n, r, {
|
|
3217
3218
|
type: "tool",
|
|
3218
3219
|
id: i,
|
|
3219
3220
|
kind: "generic",
|
|
@@ -3255,23 +3256,23 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3255
3256
|
let n = e.params;
|
|
3256
3257
|
if (n.mode !== "form") return !1;
|
|
3257
3258
|
let r = n._meta;
|
|
3258
|
-
if (!
|
|
3259
|
-
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);
|
|
3260
3261
|
n.turnId && this.host.markRuntimeTurnActive(o, n.turnId);
|
|
3261
|
-
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 = {
|
|
3262
3263
|
id: i,
|
|
3263
3264
|
kind: "confirm_tool",
|
|
3264
3265
|
conversationId: n.threadId,
|
|
3265
3266
|
turnId: n.turnId,
|
|
3266
3267
|
itemId: l,
|
|
3267
3268
|
payload: { confirmation: {
|
|
3268
|
-
argumentsPreview:
|
|
3269
|
+
argumentsPreview: ot(r),
|
|
3269
3270
|
integrationId: n.serverName,
|
|
3270
|
-
integrationName:
|
|
3271
|
+
integrationName: E(r.connector_name) ?? n.serverName,
|
|
3271
3272
|
summary: u,
|
|
3272
3273
|
toolName: a,
|
|
3273
|
-
...
|
|
3274
|
-
...
|
|
3274
|
+
...st(r.persist, "session") ? { allowConversation: !0 } : {},
|
|
3275
|
+
...st(r.persist, "always") ? { allowAlways: !0 } : {}
|
|
3275
3276
|
} }
|
|
3276
3277
|
};
|
|
3277
3278
|
this.pending.set(i, {
|
|
@@ -3296,9 +3297,9 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3296
3297
|
params: {
|
|
3297
3298
|
requestId: i,
|
|
3298
3299
|
confirmationSummary: u,
|
|
3299
|
-
argumentsPreview:
|
|
3300
|
-
allowConversation:
|
|
3301
|
-
allowAlways:
|
|
3300
|
+
argumentsPreview: ot(r),
|
|
3301
|
+
allowConversation: st(r.persist, "session"),
|
|
3302
|
+
allowAlways: st(r.persist, "always")
|
|
3302
3303
|
}
|
|
3303
3304
|
}),
|
|
3304
3305
|
input: r.tool_params,
|
|
@@ -3312,7 +3313,7 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3312
3313
|
};
|
|
3313
3314
|
this.host.patchRuntime(n.threadId, {
|
|
3314
3315
|
busy: !0,
|
|
3315
|
-
messages:
|
|
3316
|
+
messages: L(o.messages, n.threadId, s, f)
|
|
3316
3317
|
});
|
|
3317
3318
|
let p = this.host.messageContainingTool(n.threadId, s, l);
|
|
3318
3319
|
return p && this.host.emitEvent("notification", {
|
|
@@ -3330,8 +3331,8 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3330
3331
|
payload: { request: structuredClone(d) }
|
|
3331
3332
|
}), this.host.emitConversationActivity(n.threadId, "notification"), !0;
|
|
3332
3333
|
}
|
|
3333
|
-
},
|
|
3334
|
-
function
|
|
3334
|
+
}, wr = 256 * 1024;
|
|
3335
|
+
function Tr(e) {
|
|
3335
3336
|
return {
|
|
3336
3337
|
id: e.id,
|
|
3337
3338
|
model: e.model,
|
|
@@ -3356,11 +3357,11 @@ function yr(e) {
|
|
|
3356
3357
|
}
|
|
3357
3358
|
};
|
|
3358
3359
|
}
|
|
3359
|
-
async function
|
|
3360
|
-
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)));
|
|
3361
3362
|
}
|
|
3362
|
-
async function
|
|
3363
|
-
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]);
|
|
3364
3365
|
return {
|
|
3365
3366
|
name: e.name,
|
|
3366
3367
|
description: e.description,
|
|
@@ -3375,8 +3376,8 @@ async function xr(e, t) {
|
|
|
3375
3376
|
enabled: e.enabled
|
|
3376
3377
|
};
|
|
3377
3378
|
}
|
|
3378
|
-
async function
|
|
3379
|
-
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([
|
|
3380
3381
|
n?.composerIcon,
|
|
3381
3382
|
n?.logoDark,
|
|
3382
3383
|
n?.logo
|
|
@@ -3393,21 +3394,21 @@ async function Sr(e, t) {
|
|
|
3393
3394
|
enabled: e.enabled
|
|
3394
3395
|
};
|
|
3395
3396
|
}
|
|
3396
|
-
async function
|
|
3397
|
+
async function kr(e, t) {
|
|
3397
3398
|
for (let n of e) {
|
|
3398
3399
|
if (!n) continue;
|
|
3399
3400
|
let e = await t(n);
|
|
3400
3401
|
if (e) return e;
|
|
3401
3402
|
}
|
|
3402
3403
|
}
|
|
3403
|
-
function
|
|
3404
|
+
function Ar(e) {
|
|
3404
3405
|
let t = K(e);
|
|
3405
3406
|
try {
|
|
3406
3407
|
return new URL(t).protocol === "https:" ? t : void 0;
|
|
3407
3408
|
} catch {}
|
|
3408
3409
|
}
|
|
3409
|
-
function
|
|
3410
|
-
switch (
|
|
3410
|
+
function jr(e) {
|
|
3411
|
+
switch (_(e).toLowerCase()) {
|
|
3411
3412
|
case ".avif": return "image/avif";
|
|
3412
3413
|
case ".bmp": return "image/bmp";
|
|
3413
3414
|
case ".gif": return "image/gif";
|
|
@@ -3419,18 +3420,18 @@ function Tr(e) {
|
|
|
3419
3420
|
case ".webp": return "image/webp";
|
|
3420
3421
|
}
|
|
3421
3422
|
}
|
|
3422
|
-
function
|
|
3423
|
+
function Mr(e, t) {
|
|
3423
3424
|
let n = t.trim();
|
|
3424
3425
|
if (!/^[a-z\d+/]+={0,2}$/i.test(n)) return;
|
|
3425
3426
|
let r = n.replace(/=+$/, "");
|
|
3426
3427
|
if (r.length % 4 == 1) return;
|
|
3427
3428
|
let i = n.length - r.length, a = (4 - r.length % 4) % 4;
|
|
3428
|
-
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)}`}`;
|
|
3429
3430
|
}
|
|
3430
3431
|
function K(e) {
|
|
3431
3432
|
return (typeof e == "string" ? e.trim() : void 0) || void 0;
|
|
3432
3433
|
}
|
|
3433
|
-
function
|
|
3434
|
+
function Nr(e) {
|
|
3434
3435
|
return typeof e == "string" ? e : void 0;
|
|
3435
3436
|
}
|
|
3436
3437
|
//#endregion
|
|
@@ -3438,12 +3439,12 @@ function Dr(e) {
|
|
|
3438
3439
|
function q(e, t) {
|
|
3439
3440
|
return e.find((e) => e.id === t || e.model === t) ?? e.find((e) => e.isDefault) ?? e[0] ?? null;
|
|
3440
3441
|
}
|
|
3441
|
-
function
|
|
3442
|
+
function Pr(e, t) {
|
|
3442
3443
|
let n = e.find((e) => e.id === t || e.model === t);
|
|
3443
3444
|
if (!n) throw Error(`Unknown model '${t}'`);
|
|
3444
3445
|
return n;
|
|
3445
3446
|
}
|
|
3446
|
-
function
|
|
3447
|
+
function Fr(e, t) {
|
|
3447
3448
|
if (!t) return;
|
|
3448
3449
|
if (!e) throw Error(`Cannot select reasoning effort '${t}' without a model`);
|
|
3449
3450
|
let n = e.supportedReasoningEfforts?.map((e) => e.reasoningEffort) ?? [];
|
|
@@ -3452,7 +3453,7 @@ function kr(e, t) {
|
|
|
3452
3453
|
function J(e) {
|
|
3453
3454
|
return e.defaultReasoningEffort ?? e.supportedReasoningEfforts?.[0]?.reasoningEffort ?? null;
|
|
3454
3455
|
}
|
|
3455
|
-
function
|
|
3456
|
+
function Ir(e) {
|
|
3456
3457
|
return e.defaultServiceTier ?? null;
|
|
3457
3458
|
}
|
|
3458
3459
|
function Y(e, t) {
|
|
@@ -3462,14 +3463,14 @@ function Y(e, t) {
|
|
|
3462
3463
|
let n = e.serviceTiers?.map((e) => e.id) ?? [];
|
|
3463
3464
|
if (n.length > 0 && !n.includes(t)) throw Error(`Service tier '${t}' is not available for '${e.displayName}'`);
|
|
3464
3465
|
}
|
|
3465
|
-
function
|
|
3466
|
+
function Lr(e, t) {
|
|
3466
3467
|
let n = new Set(e.filter((e) => e.allowed).map((e) => e.id)), r = [];
|
|
3467
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;
|
|
3468
3469
|
}
|
|
3469
3470
|
function X(e, t) {
|
|
3470
3471
|
return !Array.isArray(e) || e.length === 0 || e.includes(t);
|
|
3471
3472
|
}
|
|
3472
|
-
function
|
|
3473
|
+
function Rr(e) {
|
|
3473
3474
|
return e === "full-access" ? {
|
|
3474
3475
|
approvalPolicy: "never",
|
|
3475
3476
|
approvalsReviewer: "user",
|
|
@@ -3480,39 +3481,39 @@ function Mr(e) {
|
|
|
3480
3481
|
permissions: ":workspace"
|
|
3481
3482
|
};
|
|
3482
3483
|
}
|
|
3483
|
-
function
|
|
3484
|
-
return
|
|
3484
|
+
function zr(e) {
|
|
3485
|
+
return Rr(e);
|
|
3485
3486
|
}
|
|
3486
|
-
function
|
|
3487
|
+
function Br(e, t, n, r) {
|
|
3487
3488
|
let i = r?.id;
|
|
3488
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;
|
|
3489
3490
|
}
|
|
3490
|
-
function
|
|
3491
|
+
function Vr(e, t, n) {
|
|
3491
3492
|
let r = q(t, e.model);
|
|
3492
3493
|
return {
|
|
3493
|
-
approvalPreset:
|
|
3494
|
+
approvalPreset: Br(e.approvalPolicy, e.approvalsReviewer, e.sandbox, e.activePermissionProfile) ?? n.approvalPreset,
|
|
3494
3495
|
planMode: n.planMode,
|
|
3495
3496
|
selectedModelId: r?.id ?? n.selectedModelId,
|
|
3496
3497
|
selectedReasoningEffort: e.reasoningEffort ?? (r ? J(r) : null),
|
|
3497
|
-
selectedServiceTier: e.serviceTier === void 0 ? r ?
|
|
3498
|
+
selectedServiceTier: e.serviceTier === void 0 ? r ? Ir(r) : null : e.serviceTier
|
|
3498
3499
|
};
|
|
3499
3500
|
}
|
|
3500
|
-
function
|
|
3501
|
+
function Hr(e, t, n) {
|
|
3501
3502
|
let r = q(t, e.model);
|
|
3502
3503
|
return {
|
|
3503
|
-
approvalPreset:
|
|
3504
|
+
approvalPreset: Br(e.approvalPolicy, e.approvalsReviewer, e.sandboxPolicy, e.activePermissionProfile) ?? n.approvalPreset,
|
|
3504
3505
|
planMode: e.collaborationMode.mode === "plan",
|
|
3505
3506
|
selectedModelId: r?.id ?? n.selectedModelId,
|
|
3506
3507
|
selectedReasoningEffort: e.effort ?? (r ? J(r) : null),
|
|
3507
|
-
selectedServiceTier: e.serviceTier === void 0 ? r ?
|
|
3508
|
+
selectedServiceTier: e.serviceTier === void 0 ? r ? Ir(r) : null : e.serviceTier
|
|
3508
3509
|
};
|
|
3509
3510
|
}
|
|
3510
|
-
function
|
|
3511
|
+
function Ur(e, t) {
|
|
3511
3512
|
let n = q(e.models, e.selectedModelId);
|
|
3512
3513
|
if (t.modelId && (n = e.models.find((e) => e.id === t.modelId) ?? null, !n)) throw Error(`Unknown model '${t.modelId}'`);
|
|
3513
3514
|
let r = t.reasoningEffort ?? e.selectedReasoningEffort, i = t.serviceTier === void 0 ? e.selectedServiceTier ?? null : t.serviceTier, a = n?.supportedReasoningEfforts?.map((e) => e.reasoningEffort) ?? [];
|
|
3514
3515
|
if (t.reasoningEffort && a.length > 0 && !a.includes(t.reasoningEffort)) throw Error(`Reasoning effort '${t.reasoningEffort}' is not available for '${n.displayName}'`);
|
|
3515
|
-
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), {
|
|
3516
3517
|
approvalPreset: t.approvalPreset ?? e.approvalPreset,
|
|
3517
3518
|
planMode: t.planMode ?? e.planMode,
|
|
3518
3519
|
selectedModelId: n?.id ?? null,
|
|
@@ -3520,7 +3521,7 @@ function Lr(e, t) {
|
|
|
3520
3521
|
selectedServiceTier: i
|
|
3521
3522
|
};
|
|
3522
3523
|
}
|
|
3523
|
-
function
|
|
3524
|
+
function Wr(e, t, n) {
|
|
3524
3525
|
return {
|
|
3525
3526
|
mode: e ? "plan" : "default",
|
|
3526
3527
|
settings: {
|
|
@@ -3530,12 +3531,12 @@ function Rr(e, t, n) {
|
|
|
3530
3531
|
}
|
|
3531
3532
|
};
|
|
3532
3533
|
}
|
|
3533
|
-
function
|
|
3534
|
+
function Gr(e, t) {
|
|
3534
3535
|
let n = q(e.models, e.selectedModelId), r = t.model ?? n?.model, i = t.reasoningEffort ?? e.selectedReasoningEffort, a = t.planMode ?? e.planMode;
|
|
3535
3536
|
return {
|
|
3536
3537
|
...r ? { model: r } : {},
|
|
3537
3538
|
...i ? { effort: i } : {},
|
|
3538
|
-
...r ? { collaborationMode:
|
|
3539
|
+
...r ? { collaborationMode: Wr(a, r, i) } : {},
|
|
3539
3540
|
...t.serviceTier === void 0 ? e.selectedServiceTier ? { serviceTier: e.selectedServiceTier } : {} : { serviceTier: t.serviceTier }
|
|
3540
3541
|
};
|
|
3541
3542
|
}
|
|
@@ -3558,29 +3559,29 @@ function Z(e) {
|
|
|
3558
3559
|
updatedAt: (/* @__PURE__ */ new Date((e.recencyAt ?? e.updatedAt) * 1e3)).toISOString()
|
|
3559
3560
|
};
|
|
3560
3561
|
}
|
|
3561
|
-
function
|
|
3562
|
+
function Kr(e, t) {
|
|
3562
3563
|
let n = new Map(e.map((e) => [e.id, e])), r = t.map((e) => {
|
|
3563
3564
|
let t = n.get(e.id);
|
|
3564
|
-
return t &&
|
|
3565
|
+
return t && ie(t, e) ? t : e;
|
|
3565
3566
|
});
|
|
3566
3567
|
return r.length === e.length && r.every((t, n) => t === e[n]) ? e : r;
|
|
3567
3568
|
}
|
|
3568
3569
|
function Q(e, t) {
|
|
3569
3570
|
return [t, ...e.filter((e) => e.id !== t.id)].sort((e, t) => t.updatedAt.localeCompare(e.updatedAt));
|
|
3570
3571
|
}
|
|
3571
|
-
function
|
|
3572
|
-
let n = t.model ?
|
|
3573
|
-
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), {
|
|
3574
3575
|
...t,
|
|
3575
|
-
...t.attachments ? { attachments:
|
|
3576
|
+
...t.attachments ? { attachments: Jr(t.attachments) } : {},
|
|
3576
3577
|
...t.model && n ? { model: n.model } : {}
|
|
3577
3578
|
};
|
|
3578
3579
|
}
|
|
3579
|
-
function
|
|
3580
|
+
function Jr(e) {
|
|
3580
3581
|
return e.map((e) => {
|
|
3581
3582
|
let t = e.path.trim();
|
|
3582
3583
|
if (!t) throw Error("Attachment paths cannot be empty");
|
|
3583
|
-
if (!
|
|
3584
|
+
if (!v(t)) throw Error(`Attachment path must be absolute: '${t}'`);
|
|
3584
3585
|
if (e.type === "image") return {
|
|
3585
3586
|
...e,
|
|
3586
3587
|
path: t
|
|
@@ -3593,22 +3594,22 @@ function Hr(e) {
|
|
|
3593
3594
|
};
|
|
3594
3595
|
});
|
|
3595
3596
|
}
|
|
3596
|
-
function
|
|
3597
|
+
function Yr(e) {
|
|
3597
3598
|
return e.type === "image" ? {
|
|
3598
3599
|
type: "localImage",
|
|
3599
3600
|
path: e.path,
|
|
3600
3601
|
...e.detail === void 0 ? {} : { detail: e.detail }
|
|
3601
|
-
} :
|
|
3602
|
+
} : Nt(e.name ?? g(e.path), e.path);
|
|
3602
3603
|
}
|
|
3603
|
-
function
|
|
3604
|
-
let t = e.name?.trim() ||
|
|
3604
|
+
function Xr(e) {
|
|
3605
|
+
let t = e.name?.trim() || g(e.path);
|
|
3605
3606
|
return e.type === "image" ? {
|
|
3606
3607
|
type: "attachment",
|
|
3607
3608
|
attachment: {
|
|
3608
3609
|
kind: "image",
|
|
3609
3610
|
name: t,
|
|
3610
3611
|
path: e.path,
|
|
3611
|
-
url: e.previewUrl ??
|
|
3612
|
+
url: e.previewUrl ?? re(e.path).href,
|
|
3612
3613
|
...e.mimeType ? { mimeType: e.mimeType } : {}
|
|
3613
3614
|
}
|
|
3614
3615
|
} : {
|
|
@@ -3621,14 +3622,14 @@ function Wr(e) {
|
|
|
3621
3622
|
}
|
|
3622
3623
|
};
|
|
3623
3624
|
}
|
|
3624
|
-
function
|
|
3625
|
+
function Zr(e) {
|
|
3625
3626
|
let t = e.metadata?.turnId;
|
|
3626
3627
|
return e.turnId ?? (typeof t == "string" ? t : null);
|
|
3627
3628
|
}
|
|
3628
|
-
function
|
|
3629
|
+
function Qr(e) {
|
|
3629
3630
|
return e.parts.filter((e) => e.type === "text").map((e) => e.text).join("\n").trim();
|
|
3630
3631
|
}
|
|
3631
|
-
function
|
|
3632
|
+
function $r(e) {
|
|
3632
3633
|
return e.parts.flatMap((e) => {
|
|
3633
3634
|
if (e.type !== "attachment") return [];
|
|
3634
3635
|
let t = e.attachment, n = t.path;
|
|
@@ -3646,7 +3647,7 @@ function qr(e) {
|
|
|
3646
3647
|
}] : [];
|
|
3647
3648
|
});
|
|
3648
3649
|
}
|
|
3649
|
-
function
|
|
3650
|
+
function ei(e) {
|
|
3650
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;
|
|
3651
3652
|
return {
|
|
3652
3653
|
totalTokens: e.total.totalTokens,
|
|
@@ -3665,13 +3666,13 @@ function $(e) {
|
|
|
3665
3666
|
activeFlags: [...e.activeFlags]
|
|
3666
3667
|
} : { type: e.type };
|
|
3667
3668
|
}
|
|
3668
|
-
function
|
|
3669
|
+
function ti(e) {
|
|
3669
3670
|
return e.type === "active" ? "active" : e.type === "systemError" ? "error" : "idle";
|
|
3670
3671
|
}
|
|
3671
|
-
function
|
|
3672
|
-
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;
|
|
3673
3674
|
return {
|
|
3674
|
-
rateLimits:
|
|
3675
|
+
rateLimits: ri(e.rateLimits),
|
|
3675
3676
|
rateLimitsByLimitId: t,
|
|
3676
3677
|
rateLimitResetCredits: e.rateLimitResetCredits ? {
|
|
3677
3678
|
availableCount: String(e.rateLimitResetCredits.availableCount),
|
|
@@ -3679,7 +3680,7 @@ function Xr(e) {
|
|
|
3679
3680
|
} : null
|
|
3680
3681
|
};
|
|
3681
3682
|
}
|
|
3682
|
-
function
|
|
3683
|
+
function ri(e) {
|
|
3683
3684
|
return {
|
|
3684
3685
|
limitId: e.limitId,
|
|
3685
3686
|
limitName: e.limitName,
|
|
@@ -3691,21 +3692,21 @@ function Zr(e) {
|
|
|
3691
3692
|
rateLimitReachedType: e.rateLimitReachedType
|
|
3692
3693
|
};
|
|
3693
3694
|
}
|
|
3694
|
-
function
|
|
3695
|
-
let n =
|
|
3695
|
+
function ii(e, t) {
|
|
3696
|
+
let n = ri(t);
|
|
3696
3697
|
if (!e) return {
|
|
3697
3698
|
rateLimits: n,
|
|
3698
3699
|
rateLimitsByLimitId: n.limitId ? { [n.limitId]: n } : null,
|
|
3699
3700
|
rateLimitResetCredits: null
|
|
3700
3701
|
};
|
|
3701
|
-
let r =
|
|
3702
|
-
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)), {
|
|
3703
3704
|
...e,
|
|
3704
3705
|
rateLimits: r,
|
|
3705
3706
|
rateLimitsByLimitId: Object.keys(i).length > 0 ? i : null
|
|
3706
3707
|
};
|
|
3707
3708
|
}
|
|
3708
|
-
function
|
|
3709
|
+
function ai(e, t) {
|
|
3709
3710
|
return {
|
|
3710
3711
|
limitId: t.limitId ?? e.limitId,
|
|
3711
3712
|
limitName: t.limitName ?? e.limitName,
|
|
@@ -3731,7 +3732,7 @@ function $r(e, t) {
|
|
|
3731
3732
|
}
|
|
3732
3733
|
//#endregion
|
|
3733
3734
|
//#region src/node/codex-surface-catalog-controller.ts
|
|
3734
|
-
var
|
|
3735
|
+
var oi = class {
|
|
3735
3736
|
client;
|
|
3736
3737
|
cwd;
|
|
3737
3738
|
host;
|
|
@@ -3766,7 +3767,7 @@ var ei = class {
|
|
|
3766
3767
|
async loadSkills(e = !1, t = "action") {
|
|
3767
3768
|
e && this.iconDataUrls.clear(), this.host.patch({ skillCatalogStatus: "loading" }), this.emitSkills(this.cwd ?? null, [], "loading", t);
|
|
3768
3769
|
try {
|
|
3769
|
-
let n = await
|
|
3770
|
+
let n = await Er((await this.client.request("skills/list", {
|
|
3770
3771
|
...this.cwd ? { cwds: [this.cwd] } : {},
|
|
3771
3772
|
forceReload: e
|
|
3772
3773
|
})).data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e));
|
|
@@ -3783,7 +3784,7 @@ var ei = class {
|
|
|
3783
3784
|
}
|
|
3784
3785
|
async listSkills(e = {}) {
|
|
3785
3786
|
await this.host.ensureConnected(), e.forceReload && this.iconDataUrls.clear();
|
|
3786
|
-
let t = await
|
|
3787
|
+
let t = await Er((await this.client.request("skills/list", {
|
|
3787
3788
|
...e.cwd ? { cwds: [e.cwd] } : {},
|
|
3788
3789
|
forceReload: e.forceReload ?? !1
|
|
3789
3790
|
})).data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e));
|
|
@@ -3795,7 +3796,7 @@ var ei = class {
|
|
|
3795
3796
|
}
|
|
3796
3797
|
async loadPermissionProfiles() {
|
|
3797
3798
|
try {
|
|
3798
|
-
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();
|
|
3799
3800
|
this.host.patch({
|
|
3800
3801
|
permissionProfiles: e,
|
|
3801
3802
|
approvalPresets: n,
|
|
@@ -3811,7 +3812,7 @@ var ei = class {
|
|
|
3811
3812
|
}
|
|
3812
3813
|
async loadRateLimits() {
|
|
3813
3814
|
try {
|
|
3814
|
-
let e =
|
|
3815
|
+
let e = ni(await this.client.request("account/rateLimits/read", void 0));
|
|
3815
3816
|
this.host.patch({ rateLimits: e }), this.host.emitEvent("action", {
|
|
3816
3817
|
type: "rateLimits.changed",
|
|
3817
3818
|
payload: { rateLimits: structuredClone(e) }
|
|
@@ -3837,12 +3838,12 @@ var ei = class {
|
|
|
3837
3838
|
}), (async () => ({
|
|
3838
3839
|
profiles: await this.requestPermissionProfiles(e),
|
|
3839
3840
|
requirements: (await this.client.request("configRequirements/read", void 0)).requirements
|
|
3840
|
-
}))()]), 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 : [];
|
|
3841
3842
|
return {
|
|
3842
3843
|
skills: a,
|
|
3843
3844
|
skillCatalogStatus: r.status === "fulfilled" ? "loaded" : "error",
|
|
3844
3845
|
permissionProfiles: o,
|
|
3845
|
-
approvalPresets: i.status === "fulfilled" ?
|
|
3846
|
+
approvalPresets: i.status === "fulfilled" ? Lr(o, i.value.requirements) : []
|
|
3846
3847
|
};
|
|
3847
3848
|
}
|
|
3848
3849
|
schedulePluginRefresh(e = !1) {
|
|
@@ -3869,7 +3870,7 @@ var ei = class {
|
|
|
3869
3870
|
cursor: n,
|
|
3870
3871
|
includeHidden: e
|
|
3871
3872
|
});
|
|
3872
|
-
t.push(...r.data.map(
|
|
3873
|
+
t.push(...r.data.map(Tr)), n = r.nextCursor;
|
|
3873
3874
|
} while (n);
|
|
3874
3875
|
return t;
|
|
3875
3876
|
}
|
|
@@ -3880,7 +3881,7 @@ var ei = class {
|
|
|
3880
3881
|
modelCatalogStatus: "loaded",
|
|
3881
3882
|
selectedModelId: n?.id ?? null,
|
|
3882
3883
|
selectedReasoningEffort: n ? J(n) : null,
|
|
3883
|
-
selectedServiceTier: n ?
|
|
3884
|
+
selectedServiceTier: n ? Ir(n) : null
|
|
3884
3885
|
}), this.emitModels(e, "loaded", t);
|
|
3885
3886
|
}
|
|
3886
3887
|
emitModels(e, t, n = "action") {
|
|
@@ -3939,7 +3940,7 @@ var ei = class {
|
|
|
3939
3940
|
try {
|
|
3940
3941
|
let t = await this.client.request("plugin/installed", { ...e.length > 0 ? { cwds: [...e] } : {} }), n = /* @__PURE__ */ new Map();
|
|
3941
3942
|
for (let e of t.marketplaces) for (let t of e.plugins) n.has(t.id) || n.set(t.id, t);
|
|
3942
|
-
let r =
|
|
3943
|
+
let r = Kr(this.host.getState().plugins, await Promise.all([...n.values()].map((e) => Or(e, (e) => this.iconDataUrl(e)))));
|
|
3943
3944
|
if (this.host.isClosed() || this.host.authenticationBlocksBootstrap()) return;
|
|
3944
3945
|
this.host.patch({
|
|
3945
3946
|
plugins: r,
|
|
@@ -3969,10 +3970,10 @@ var ei = class {
|
|
|
3969
3970
|
return this.iconDataUrls.set(e, n), n;
|
|
3970
3971
|
}
|
|
3971
3972
|
async readIconDataUrl(e) {
|
|
3972
|
-
if (!
|
|
3973
|
-
let t =
|
|
3973
|
+
if (!v(e)) return;
|
|
3974
|
+
let t = jr(e);
|
|
3974
3975
|
if (t) try {
|
|
3975
|
-
return
|
|
3976
|
+
return Mr(t, (await this.client.request("fs/readFile", { path: e })).dataBase64);
|
|
3976
3977
|
} catch {
|
|
3977
3978
|
return;
|
|
3978
3979
|
}
|
|
@@ -3980,18 +3981,18 @@ var ei = class {
|
|
|
3980
3981
|
};
|
|
3981
3982
|
//#endregion
|
|
3982
3983
|
//#region src/node/codex-approvals.ts
|
|
3983
|
-
function
|
|
3984
|
+
function si(e, t) {
|
|
3984
3985
|
let n = [
|
|
3985
3986
|
e.onServerRequest("item/commandExecution/requestApproval", (e, n) => (t({
|
|
3986
|
-
approval:
|
|
3987
|
-
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) })
|
|
3988
3989
|
}), !0)),
|
|
3989
3990
|
e.onServerRequest("item/fileChange/requestApproval", (e, n) => (t({
|
|
3990
|
-
approval:
|
|
3991
|
+
approval: li(e.id, e.params),
|
|
3991
3992
|
resolve: (e, t) => n.resolve({ decision: e === "deny" ? "decline" : t === "session" ? "acceptForSession" : "accept" })
|
|
3992
3993
|
}), !0)),
|
|
3993
3994
|
e.onServerRequest("item/permissions/requestApproval", (e, n) => (t({
|
|
3994
|
-
approval:
|
|
3995
|
+
approval: ui(e.id, e.params),
|
|
3995
3996
|
resolve: (t, r) => n.resolve({
|
|
3996
3997
|
permissions: t === "deny" ? {} : {
|
|
3997
3998
|
...e.params.permissions.fileSystem ? { fileSystem: e.params.permissions.fileSystem } : {},
|
|
@@ -4029,8 +4030,8 @@ function ti(e, t) {
|
|
|
4029
4030
|
for (let e of n) e();
|
|
4030
4031
|
};
|
|
4031
4032
|
}
|
|
4032
|
-
function
|
|
4033
|
-
let n = t.availableDecisions, r =
|
|
4033
|
+
function ci(e, t) {
|
|
4034
|
+
let n = t.availableDecisions, r = fi(t.additionalPermissions), i = [...t.networkApprovalContext ? [{
|
|
4034
4035
|
kind: "network",
|
|
4035
4036
|
enabled: !0,
|
|
4036
4037
|
host: t.networkApprovalContext.host,
|
|
@@ -4053,7 +4054,7 @@ function ni(e, t) {
|
|
|
4053
4054
|
} : {}
|
|
4054
4055
|
};
|
|
4055
4056
|
}
|
|
4056
|
-
function
|
|
4057
|
+
function li(e, t) {
|
|
4057
4058
|
return {
|
|
4058
4059
|
id: String(e),
|
|
4059
4060
|
kind: "file-change",
|
|
@@ -4064,8 +4065,8 @@ function ri(e, t) {
|
|
|
4064
4065
|
...t.reason || t.grantRoot ? { description: t.reason ?? `Write under ${t.grantRoot}` } : {}
|
|
4065
4066
|
};
|
|
4066
4067
|
}
|
|
4067
|
-
function
|
|
4068
|
-
let n =
|
|
4068
|
+
function ui(e, t) {
|
|
4069
|
+
let n = fi(t.permissions);
|
|
4069
4070
|
return {
|
|
4070
4071
|
id: String(e),
|
|
4071
4072
|
kind: "permissions",
|
|
@@ -4078,13 +4079,13 @@ function ii(e, t) {
|
|
|
4078
4079
|
...n.length ? { requestedPermissions: n } : {}
|
|
4079
4080
|
};
|
|
4080
4081
|
}
|
|
4081
|
-
function
|
|
4082
|
+
function di(e, t, n) {
|
|
4082
4083
|
let r = e.availableDecisions, i = t === "deny" ? "decline" : n === "session" ? "acceptForSession" : "accept";
|
|
4083
4084
|
if (!r || r.includes(i)) return i;
|
|
4084
4085
|
if (t === "deny" && r.includes("cancel")) return "cancel";
|
|
4085
4086
|
throw Error(`Approval decision '${t}:${n}' is not available for this command`);
|
|
4086
4087
|
}
|
|
4087
|
-
function
|
|
4088
|
+
function fi(e) {
|
|
4088
4089
|
if (!e) return [];
|
|
4089
4090
|
let t = [];
|
|
4090
4091
|
if (e.network && t.push({
|
|
@@ -4104,12 +4105,12 @@ function oi(e) {
|
|
|
4104
4105
|
for (let n of e.fileSystem.entries ?? []) t.push({
|
|
4105
4106
|
kind: "filesystem",
|
|
4106
4107
|
access: n.access,
|
|
4107
|
-
path:
|
|
4108
|
+
path: pi(n.path)
|
|
4108
4109
|
});
|
|
4109
4110
|
}
|
|
4110
4111
|
return t;
|
|
4111
4112
|
}
|
|
4112
|
-
function
|
|
4113
|
+
function pi(e) {
|
|
4113
4114
|
if (e.type === "path") return e.path;
|
|
4114
4115
|
if (e.type === "glob_pattern") return e.pattern;
|
|
4115
4116
|
let t = e.value;
|
|
@@ -4124,12 +4125,12 @@ function si(e) {
|
|
|
4124
4125
|
}
|
|
4125
4126
|
//#endregion
|
|
4126
4127
|
//#region src/node/codex-surface-approvals-controller.ts
|
|
4127
|
-
var
|
|
4128
|
+
var mi = class {
|
|
4128
4129
|
host;
|
|
4129
4130
|
pending = /* @__PURE__ */ new Map();
|
|
4130
4131
|
unsubscribeHandler;
|
|
4131
4132
|
constructor(e, t) {
|
|
4132
|
-
this.host = t, this.unsubscribeHandler =
|
|
4133
|
+
this.host = t, this.unsubscribeHandler = si(e, (e) => this.add(e));
|
|
4133
4134
|
}
|
|
4134
4135
|
close() {
|
|
4135
4136
|
this.unsubscribeHandler(), this.pending.clear();
|
|
@@ -4210,7 +4211,7 @@ var ci = class {
|
|
|
4210
4211
|
};
|
|
4211
4212
|
//#endregion
|
|
4212
4213
|
//#region src/node/codex-surface-mcp.ts
|
|
4213
|
-
function
|
|
4214
|
+
function hi(e) {
|
|
4214
4215
|
if (!Array.isArray(e)) throw TypeError("Codex MCP servers must be an array");
|
|
4215
4216
|
let t = /* @__PURE__ */ new Set();
|
|
4216
4217
|
return e.map((e, n) => {
|
|
@@ -4219,10 +4220,10 @@ function li(e) {
|
|
|
4219
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_-]*$`);
|
|
4220
4221
|
if (t.has(r)) throw Error(`Duplicate Codex MCP server '${r}'`);
|
|
4221
4222
|
t.add(r);
|
|
4222
|
-
let i =
|
|
4223
|
+
let i = gi(e.transport, r), a = e.toolApprovalMode;
|
|
4223
4224
|
if (a !== void 0 && a !== "auto" && a !== "prompt" && a !== "writes" && a !== "approve") throw TypeError(`Codex MCP server '${r}' tool approval mode is invalid`);
|
|
4224
4225
|
if (e.required !== void 0 && typeof e.required != "boolean") throw TypeError(`Codex MCP server '${r}' required flag must be a boolean`);
|
|
4225
|
-
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`);
|
|
4226
4227
|
return {
|
|
4227
4228
|
name: r,
|
|
4228
4229
|
transport: i,
|
|
@@ -4234,7 +4235,7 @@ function li(e) {
|
|
|
4234
4235
|
};
|
|
4235
4236
|
});
|
|
4236
4237
|
}
|
|
4237
|
-
function
|
|
4238
|
+
function gi(e, t) {
|
|
4238
4239
|
if (!e || typeof e != "object" || Array.isArray(e)) throw TypeError(`Codex MCP server '${t}' transport must be an object`);
|
|
4239
4240
|
if (e.type === "http") {
|
|
4240
4241
|
let n = e.url?.trim(), r;
|
|
@@ -4252,8 +4253,8 @@ function ui(e, t) {
|
|
|
4252
4253
|
if (e.type !== "stdio") throw TypeError(`Codex MCP server '${t}' transport type is invalid`);
|
|
4253
4254
|
let n = e.command?.trim();
|
|
4254
4255
|
if (!n) throw TypeError(`Codex MCP server '${t}' command cannot be empty`);
|
|
4255
|
-
let r = e.args === void 0 ? void 0 :
|
|
4256
|
-
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`);
|
|
4257
4258
|
let a;
|
|
4258
4259
|
if (e.env !== void 0) {
|
|
4259
4260
|
if (!e.env || typeof e.env != "object" || Array.isArray(e.env)) throw TypeError(`Codex MCP server '${t}' env must be an object`);
|
|
@@ -4263,7 +4264,7 @@ function ui(e, t) {
|
|
|
4263
4264
|
a[n] = r;
|
|
4264
4265
|
}
|
|
4265
4266
|
}
|
|
4266
|
-
let o = e.envVars === void 0 ? void 0 :
|
|
4267
|
+
let o = e.envVars === void 0 ? void 0 : vi(e.envVars, t);
|
|
4267
4268
|
return {
|
|
4268
4269
|
type: "stdio",
|
|
4269
4270
|
command: n,
|
|
@@ -4273,7 +4274,7 @@ function ui(e, t) {
|
|
|
4273
4274
|
...o === void 0 ? {} : { envVars: o }
|
|
4274
4275
|
};
|
|
4275
4276
|
}
|
|
4276
|
-
function
|
|
4277
|
+
function _i(e, t) {
|
|
4277
4278
|
if (!Array.isArray(e)) throw TypeError(`${t}s must be an array`);
|
|
4278
4279
|
let n = e.map((e) => {
|
|
4279
4280
|
if (typeof e != "string" || !e.trim()) throw TypeError(`${t} cannot be empty`);
|
|
@@ -4281,18 +4282,18 @@ function di(e, t) {
|
|
|
4281
4282
|
});
|
|
4282
4283
|
return [...new Set(n)];
|
|
4283
4284
|
}
|
|
4284
|
-
function
|
|
4285
|
-
let n =
|
|
4285
|
+
function vi(e, t) {
|
|
4286
|
+
let n = _i(e, `Codex MCP server '${t}' environment variable`);
|
|
4286
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`);
|
|
4287
4288
|
return n;
|
|
4288
4289
|
}
|
|
4289
|
-
function
|
|
4290
|
+
function yi(e, t) {
|
|
4290
4291
|
if (e !== void 0) {
|
|
4291
4292
|
if (!Number.isFinite(e) || e <= 0) throw TypeError(`${t} must be a positive finite number`);
|
|
4292
4293
|
return e;
|
|
4293
4294
|
}
|
|
4294
4295
|
}
|
|
4295
|
-
function
|
|
4296
|
+
function bi(e) {
|
|
4296
4297
|
let t = {};
|
|
4297
4298
|
for (let n of e) {
|
|
4298
4299
|
let e = n.transport.type === "http" ? { url: n.transport.url } : {
|
|
@@ -4306,7 +4307,7 @@ function mi(e) {
|
|
|
4306
4307
|
}
|
|
4307
4308
|
return t;
|
|
4308
4309
|
}
|
|
4309
|
-
function
|
|
4310
|
+
function xi(e, t) {
|
|
4310
4311
|
if (t.length !== 0) for (let n of Object.keys(e)) {
|
|
4311
4312
|
if (n === "mcp_servers") throw Error("Raw mcp_servers config cannot be combined with typed Codex MCP servers");
|
|
4312
4313
|
for (let e of t) {
|
|
@@ -4317,13 +4318,13 @@ function hi(e, t) {
|
|
|
4317
4318
|
}
|
|
4318
4319
|
//#endregion
|
|
4319
4320
|
//#region src/node/codex-surface-extensions-controller.ts
|
|
4320
|
-
var
|
|
4321
|
+
var Si = class {
|
|
4321
4322
|
extensions;
|
|
4322
4323
|
hostOptionsForThread;
|
|
4323
4324
|
dynamicTools = /* @__PURE__ */ new Map();
|
|
4324
4325
|
defaultMcpServers;
|
|
4325
4326
|
constructor(e, t, n) {
|
|
4326
|
-
this.extensions = e, this.hostOptionsForThread = n, this.defaultMcpServers =
|
|
4327
|
+
this.extensions = e, this.hostOptionsForThread = n, this.defaultMcpServers = hi(t);
|
|
4327
4328
|
for (let t of e) for (let e of t.dynamicTools ?? []) {
|
|
4328
4329
|
let t = e.name.trim();
|
|
4329
4330
|
if (!t) throw Error("Dynamic tool names cannot be empty");
|
|
@@ -4347,13 +4348,13 @@ var gi = class {
|
|
|
4347
4348
|
}));
|
|
4348
4349
|
}
|
|
4349
4350
|
async conversationExtension(e, t = {}, n = this.defaultMcpServers) {
|
|
4350
|
-
let r =
|
|
4351
|
+
let r = bi(n), i = [], a;
|
|
4351
4352
|
for (let t of this.extensions) {
|
|
4352
4353
|
if (!t.configureConversation) continue;
|
|
4353
4354
|
let o = await t.configureConversation(e);
|
|
4354
|
-
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());
|
|
4355
4356
|
}
|
|
4356
|
-
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()), {
|
|
4357
4358
|
...a === void 0 ? {} : { baseInstructions: a },
|
|
4358
4359
|
...Object.keys(r).length === 0 ? {} : { config: r },
|
|
4359
4360
|
...i.length === 0 ? {} : { developerInstructions: i.join("\n\n") }
|
|
@@ -4407,12 +4408,12 @@ var gi = class {
|
|
|
4407
4408
|
success: !1,
|
|
4408
4409
|
contentItems: [{
|
|
4409
4410
|
type: "inputText",
|
|
4410
|
-
text:
|
|
4411
|
+
text: O(e)
|
|
4411
4412
|
}]
|
|
4412
4413
|
});
|
|
4413
4414
|
}
|
|
4414
4415
|
}
|
|
4415
|
-
},
|
|
4416
|
+
}, Ci = 50, wi = 25, Ti = 25, Ei = class {
|
|
4416
4417
|
client;
|
|
4417
4418
|
conversationLimit;
|
|
4418
4419
|
host;
|
|
@@ -4431,7 +4432,7 @@ var gi = class {
|
|
|
4431
4432
|
return await this.host.ensureConnected(), this.load();
|
|
4432
4433
|
}
|
|
4433
4434
|
async load() {
|
|
4434
|
-
let e =
|
|
4435
|
+
let e = Kr(this.host.getState().conversations, await this.requestConversations({ limit: this.conversationLimit }));
|
|
4435
4436
|
this.host.patch({ conversations: e }), this.host.schedulePluginRefresh(!0);
|
|
4436
4437
|
for (let t of e) this.host.emitSummaryUpserted(t, "listed", "action");
|
|
4437
4438
|
return this.host.getSnapshot();
|
|
@@ -4440,7 +4441,7 @@ var gi = class {
|
|
|
4440
4441
|
return await this.host.ensureConnected(), structuredClone(await this.requestConversations(e));
|
|
4441
4442
|
}
|
|
4442
4443
|
async readSummary(e) {
|
|
4443
|
-
let t =
|
|
4444
|
+
let t = D(e);
|
|
4444
4445
|
await this.host.ensureConnected();
|
|
4445
4446
|
let n = await this.client.request("thread/read", {
|
|
4446
4447
|
threadId: t,
|
|
@@ -4451,15 +4452,15 @@ var gi = class {
|
|
|
4451
4452
|
return structuredClone(r);
|
|
4452
4453
|
}
|
|
4453
4454
|
async archive(e) {
|
|
4454
|
-
let t =
|
|
4455
|
+
let t = D(e);
|
|
4455
4456
|
return await this.host.ensureConnected(), await this.client.request("thread/archive", { threadId: t }), this.host.removeThread(t, "archived", "action"), this.host.getSnapshot();
|
|
4456
4457
|
}
|
|
4457
4458
|
async delete(e) {
|
|
4458
|
-
let t =
|
|
4459
|
+
let t = D(e);
|
|
4459
4460
|
return await this.host.ensureConnected(), await this.client.request("thread/delete", { threadId: t }), this.host.removeThread(t, "deleted", "action"), this.host.getSnapshot();
|
|
4460
4461
|
}
|
|
4461
4462
|
async unarchive(e) {
|
|
4462
|
-
let t =
|
|
4463
|
+
let t = D(e);
|
|
4463
4464
|
await this.host.ensureConnected();
|
|
4464
4465
|
let n = await this.client.request("thread/unarchive", { threadId: t });
|
|
4465
4466
|
if (n.thread.id !== t) throw Error(`Codex thread/unarchive returned '${n.thread.id}' for requested thread '${t}'`);
|
|
@@ -4481,7 +4482,7 @@ var gi = class {
|
|
|
4481
4482
|
let t = await this.client.request("thread/turns/list", {
|
|
4482
4483
|
threadId: e,
|
|
4483
4484
|
cursor: null,
|
|
4484
|
-
limit:
|
|
4485
|
+
limit: Ci,
|
|
4485
4486
|
sortDirection: "desc",
|
|
4486
4487
|
itemsView: "full"
|
|
4487
4488
|
});
|
|
@@ -4501,7 +4502,7 @@ var gi = class {
|
|
|
4501
4502
|
historyHasOlder: !1
|
|
4502
4503
|
});
|
|
4503
4504
|
} catch (t) {
|
|
4504
|
-
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;
|
|
4505
4506
|
}
|
|
4506
4507
|
})();
|
|
4507
4508
|
return this.historyHydrations.set(e, r), r.finally(() => {
|
|
@@ -4529,7 +4530,7 @@ var gi = class {
|
|
|
4529
4530
|
let i = new Set(this.host.requireRuntime(e).turnIds), a = await this.client.request("thread/turns/list", {
|
|
4530
4531
|
threadId: e,
|
|
4531
4532
|
cursor: t,
|
|
4532
|
-
limit:
|
|
4533
|
+
limit: wi,
|
|
4533
4534
|
sortDirection: "desc",
|
|
4534
4535
|
itemsView: "full"
|
|
4535
4536
|
}), o = [...a.data].reverse(), s = new Set(o.map((e) => e.id).filter((e) => !i.has(e)));
|
|
@@ -4545,7 +4546,7 @@ var gi = class {
|
|
|
4545
4546
|
hasOlder: this.host.requireRuntime(e).historyHasOlder
|
|
4546
4547
|
};
|
|
4547
4548
|
} catch (t) {
|
|
4548
|
-
throw this.host.runtime(e) && this.host.patchRuntime(e, { error:
|
|
4549
|
+
throw this.host.runtime(e) && this.host.patchRuntime(e, { error: O(t) }), t;
|
|
4549
4550
|
} finally {
|
|
4550
4551
|
this.host.runtime(e) && this.host.patchRuntime(e, { historyLoadingOlder: !1 });
|
|
4551
4552
|
}
|
|
@@ -4560,8 +4561,8 @@ var gi = class {
|
|
|
4560
4561
|
}
|
|
4561
4562
|
async emitHistoryChunks(e, t) {
|
|
4562
4563
|
for (let n = t.length; n > 0;) {
|
|
4563
|
-
let r = Math.max(0, n -
|
|
4564
|
-
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;
|
|
4565
4566
|
}
|
|
4566
4567
|
}
|
|
4567
4568
|
async refreshCompleteHistory(e) {
|
|
@@ -4597,7 +4598,7 @@ var gi = class {
|
|
|
4597
4598
|
let i = /* @__PURE__ */ new Set();
|
|
4598
4599
|
r.activeTurnId && i.add(r.activeTurnId);
|
|
4599
4600
|
for (let e of t) e.status === "inProgress" && r.turnIds.includes(e.id) && i.add(e.id);
|
|
4600
|
-
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)));
|
|
4601
4602
|
this.host.patchRuntime(e, {
|
|
4602
4603
|
turnIds: [...o.map((e) => e.id), ...s],
|
|
4603
4604
|
turns: [...o.map((e) => W(e)), ...c],
|
|
@@ -4624,12 +4625,12 @@ var gi = class {
|
|
|
4624
4625
|
} : t;
|
|
4625
4626
|
}
|
|
4626
4627
|
};
|
|
4627
|
-
function
|
|
4628
|
+
function Di() {
|
|
4628
4629
|
return new Promise((e) => setTimeout(e, 0));
|
|
4629
4630
|
}
|
|
4630
4631
|
//#endregion
|
|
4631
4632
|
//#region src/node/codex-surface-conversation-settings-controller.ts
|
|
4632
|
-
var
|
|
4633
|
+
var Oi = class {
|
|
4633
4634
|
client;
|
|
4634
4635
|
defaults;
|
|
4635
4636
|
host;
|
|
@@ -4641,7 +4642,7 @@ var Si = class {
|
|
|
4641
4642
|
}
|
|
4642
4643
|
threadStartSettings(e, t) {
|
|
4643
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);
|
|
4644
|
-
if (r) return
|
|
4645
|
+
if (r) return Rr(r);
|
|
4645
4646
|
let i = e.approvalMode ?? this.defaults.approvalMode, a = e.permissionMode ?? this.defaults.permissionMode ?? "read-only";
|
|
4646
4647
|
return {
|
|
4647
4648
|
approvalPolicy: i === "ask" ? "on-request" : "never",
|
|
@@ -4667,23 +4668,23 @@ var Si = class {
|
|
|
4667
4668
|
async update(e) {
|
|
4668
4669
|
let t = this.host.getState(), n = t.activeConversationId;
|
|
4669
4670
|
if (!n) {
|
|
4670
|
-
let n =
|
|
4671
|
+
let n = Ur(t, e);
|
|
4671
4672
|
if (e.approvalPreset && !t.approvalPresets.includes(e.approvalPreset)) throw Error(`Approval preset '${e.approvalPreset}' is not available`);
|
|
4672
4673
|
return this.host.patch(n), this.host.getSnapshot();
|
|
4673
4674
|
}
|
|
4674
4675
|
return await this.updateForThread(n, e), this.host.getSnapshot();
|
|
4675
4676
|
}
|
|
4676
4677
|
async updateForThread(e, t) {
|
|
4677
|
-
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;
|
|
4678
4679
|
if (t.approvalPreset && !r.approvalPresets.includes(t.approvalPreset)) throw Error(`Approval preset '${t.approvalPreset}' is not available`);
|
|
4679
4680
|
let o = q(this.host.getState().models, i.selectedModelId);
|
|
4680
4681
|
await this.client.request("thread/settings/update", {
|
|
4681
4682
|
threadId: e,
|
|
4682
|
-
...t.approvalPreset ?
|
|
4683
|
+
...t.approvalPreset ? zr(t.approvalPreset) : {},
|
|
4683
4684
|
...t.modelId && o ? { model: o.model } : {},
|
|
4684
4685
|
...t.reasoningEffort || t.modelId ? { effort: i.selectedReasoningEffort } : {},
|
|
4685
4686
|
...t.serviceTier !== void 0 || t.modelId ? { serviceTier: i.selectedServiceTier } : {},
|
|
4686
|
-
...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) } : {}
|
|
4687
4688
|
}), this.host.patchRuntime(e, i), a && this.host.emitConversationSettings(e, "action");
|
|
4688
4689
|
}
|
|
4689
4690
|
async setGoal(e, t) {
|
|
@@ -4702,7 +4703,7 @@ var Si = class {
|
|
|
4702
4703
|
...n === void 0 ? {} : { tokenBudget: n }
|
|
4703
4704
|
});
|
|
4704
4705
|
if (a.goal.threadId !== e) throw Error(`Codex thread/goal/set returned a goal for '${a.goal.threadId}' instead of '${e}'`);
|
|
4705
|
-
let o = !
|
|
4706
|
+
let o = !gr(r.goal, a.goal);
|
|
4706
4707
|
this.host.patchRuntime(e, { goal: { ...a.goal } }), o && this.host.emitEvent("action", {
|
|
4707
4708
|
type: "conversation.goalChanged",
|
|
4708
4709
|
conversationId: e,
|
|
@@ -4724,7 +4725,7 @@ var Si = class {
|
|
|
4724
4725
|
payload: { goal: null }
|
|
4725
4726
|
});
|
|
4726
4727
|
}
|
|
4727
|
-
},
|
|
4728
|
+
}, ki = "Review the current code changes (staged, unstaged, and untracked files) and provide prioritized findings.", Ai = class {
|
|
4728
4729
|
client;
|
|
4729
4730
|
host;
|
|
4730
4731
|
constructor(e, t) {
|
|
@@ -4753,7 +4754,7 @@ var Si = class {
|
|
|
4753
4754
|
error: null
|
|
4754
4755
|
}), this.host.patchConversationStatus(e, "active", "action"), this.host.emitConversationActivity(e, "action");
|
|
4755
4756
|
try {
|
|
4756
|
-
let r =
|
|
4757
|
+
let r = tt(t.target ?? { type: "uncommittedChanges" }), i = await this.client.request("review/start", {
|
|
4757
4758
|
threadId: e,
|
|
4758
4759
|
target: r,
|
|
4759
4760
|
delivery: "inline"
|
|
@@ -4761,22 +4762,22 @@ var Si = class {
|
|
|
4761
4762
|
if (i.reviewThreadId !== e) throw Error(`Codex review/start returned unexpected review thread '${i.reviewThreadId}' for inline review on thread '${e}'`);
|
|
4762
4763
|
let a = n.turnIds.includes(i.turn.id);
|
|
4763
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");
|
|
4764
|
-
let o =
|
|
4765
|
+
let o = zn(e, i.turn).filter((e) => !n.messages.some((t) => t.id === e.id)).map((e) => e.role === "user" ? {
|
|
4765
4766
|
...e,
|
|
4766
4767
|
parts: r.type === "uncommittedChanges" ? e.parts.map((e) => e.type === "text" && e.text === "current changes" ? {
|
|
4767
4768
|
...e,
|
|
4768
|
-
text:
|
|
4769
|
+
text: ki
|
|
4769
4770
|
} : e) : e.parts,
|
|
4770
4771
|
metadata: {
|
|
4771
4772
|
...e.metadata,
|
|
4772
4773
|
reviewPrompt: !0
|
|
4773
4774
|
}
|
|
4774
|
-
} : e), s =
|
|
4775
|
+
} : e), s = ji(n.messages, i.turn.id, o);
|
|
4775
4776
|
this.host.patchRuntime(e, {
|
|
4776
4777
|
busy: n.activeTurnId !== null,
|
|
4777
4778
|
turnStartPending: !1,
|
|
4778
4779
|
turns: G(n.turns, W(i.turn)),
|
|
4779
|
-
messages: n.activeTurnId ?
|
|
4780
|
+
messages: n.activeTurnId ? I(s, e, i.turn.id) : s
|
|
4780
4781
|
});
|
|
4781
4782
|
for (let t of o) this.host.emitEvent("action", {
|
|
4782
4783
|
type: "message.appended",
|
|
@@ -4794,7 +4795,7 @@ var Si = class {
|
|
|
4794
4795
|
throw this.host.patchRuntime(e, {
|
|
4795
4796
|
busy: !1,
|
|
4796
4797
|
turnStartPending: !1,
|
|
4797
|
-
error:
|
|
4798
|
+
error: O(t)
|
|
4798
4799
|
}), this.host.patchConversationStatus(e, "error", "action"), this.host.emitConversationActivity(e, "action"), t;
|
|
4799
4800
|
}
|
|
4800
4801
|
}
|
|
@@ -4821,11 +4822,11 @@ var Si = class {
|
|
|
4821
4822
|
return await this.editTurnForThread(n, e, t), this.host.getSnapshot();
|
|
4822
4823
|
}
|
|
4823
4824
|
async editTurnForThread(e, t, n) {
|
|
4824
|
-
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);
|
|
4825
4826
|
if (!r) throw Error(`Could not find the user prompt for Codex turn '${t}'`);
|
|
4826
4827
|
let i = n.trim();
|
|
4827
4828
|
if (!i) throw Error("Cannot replace a turn prompt with empty content");
|
|
4828
|
-
let a =
|
|
4829
|
+
let a = $r(r);
|
|
4829
4830
|
await this.rollbackToTurn(e, t), await this.host.sendMessageToThread(e, i, a.length > 0 ? { attachments: a } : {});
|
|
4830
4831
|
}
|
|
4831
4832
|
async retryTurn(e) {
|
|
@@ -4833,11 +4834,11 @@ var Si = class {
|
|
|
4833
4834
|
return await this.retryTurnForThread(t, e), this.host.getSnapshot();
|
|
4834
4835
|
}
|
|
4835
4836
|
async retryTurnForThread(e, t) {
|
|
4836
|
-
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);
|
|
4837
4838
|
if (!n) throw Error("Could not find the user prompt for this turn");
|
|
4838
|
-
let r =
|
|
4839
|
+
let r = Qr(n);
|
|
4839
4840
|
if (!r) throw Error("Could not find the user prompt for this turn");
|
|
4840
|
-
let i =
|
|
4841
|
+
let i = $r(n);
|
|
4841
4842
|
await this.rollbackToTurn(e, t), await this.host.sendMessageToThread(e, r, i.length > 0 ? { attachments: i } : {});
|
|
4842
4843
|
}
|
|
4843
4844
|
async rollbackToTurn(e, t) {
|
|
@@ -4857,7 +4858,7 @@ var Si = class {
|
|
|
4857
4858
|
n.turnIds = i.thread.turns.map((e) => e.id), n.turns = i.thread.turns.map((e) => W(e)), n.activeTurnId = null;
|
|
4858
4859
|
let a = Z(i.thread);
|
|
4859
4860
|
this.host.patch({ conversations: Q(this.host.getState().conversations, a) }), this.host.patchRuntime(e, {
|
|
4860
|
-
messages:
|
|
4861
|
+
messages: Ln(i.thread),
|
|
4861
4862
|
answeredClientRequestIds: [],
|
|
4862
4863
|
busy: !1,
|
|
4863
4864
|
turnStartPending: !1,
|
|
@@ -4873,7 +4874,7 @@ var Si = class {
|
|
|
4873
4874
|
});
|
|
4874
4875
|
if (i.thread.id !== e) throw Error(`Codex thread/revert returned '${i.thread.id}' for requested thread '${e}'`);
|
|
4875
4876
|
let a = r.turnIds.slice(0, n), o = new Set(a), s = r.messages.filter((e) => {
|
|
4876
|
-
let t =
|
|
4877
|
+
let t = Zr(e);
|
|
4877
4878
|
return t === null || o.has(t);
|
|
4878
4879
|
});
|
|
4879
4880
|
r.turnIds = a, r.turns = r.turns.filter((e) => o.has(e.id)), r.activeTurnId = null;
|
|
@@ -4900,7 +4901,7 @@ var Si = class {
|
|
|
4900
4901
|
return e;
|
|
4901
4902
|
}
|
|
4902
4903
|
};
|
|
4903
|
-
function
|
|
4904
|
+
function ji(e, t, n) {
|
|
4904
4905
|
let r = e.findIndex((e) => e.turnId === t);
|
|
4905
4906
|
return r < 0 ? [...e, ...n] : [
|
|
4906
4907
|
...e.slice(0, r),
|
|
@@ -4910,7 +4911,7 @@ function Ti(e, t, n) {
|
|
|
4910
4911
|
}
|
|
4911
4912
|
//#endregion
|
|
4912
4913
|
//#region src/node/codex-surface-messages-controller.ts
|
|
4913
|
-
var
|
|
4914
|
+
var Mi = class {
|
|
4914
4915
|
client;
|
|
4915
4916
|
host;
|
|
4916
4917
|
constructor(e, t) {
|
|
@@ -4921,7 +4922,7 @@ var Ei = class {
|
|
|
4921
4922
|
let n = e.trim();
|
|
4922
4923
|
if (!n) throw Error("Cannot send an empty message");
|
|
4923
4924
|
if (!this.host.getState().activeConversationId) {
|
|
4924
|
-
let e =
|
|
4925
|
+
let e = Qe(n);
|
|
4925
4926
|
if (e) {
|
|
4926
4927
|
if (await this.host.createConversation(), await this.host.updateSettings({ planMode: !0 }), !e.prompt) return this.host.getSnapshot();
|
|
4927
4928
|
n = e.prompt, t = {
|
|
@@ -4929,14 +4930,14 @@ var Ei = class {
|
|
|
4929
4930
|
planMode: !0
|
|
4930
4931
|
};
|
|
4931
4932
|
}
|
|
4932
|
-
let r =
|
|
4933
|
+
let r = $e(n);
|
|
4933
4934
|
if (r) {
|
|
4934
4935
|
if (r.action === "clear" || r.action === "show" || r.action === "edit") return this.host.getSnapshot();
|
|
4935
4936
|
if (r.action === "set") return this.host.setGoal(r.objective);
|
|
4936
4937
|
throw Error("Pausing and resuming goals is not supported by Codex app-server");
|
|
4937
4938
|
}
|
|
4938
4939
|
if (n === "/compact") return this.host.getSnapshot();
|
|
4939
|
-
let i =
|
|
4940
|
+
let i = et(n);
|
|
4940
4941
|
if (i) return await this.host.createConversation(), this.host.startReview({ target: i });
|
|
4941
4942
|
this.host.getState().activeConversationId || await this.host.createConversation();
|
|
4942
4943
|
}
|
|
@@ -4947,7 +4948,7 @@ var Ei = class {
|
|
|
4947
4948
|
async sendToThread(e, t, n = {}) {
|
|
4948
4949
|
let r = await this.host.ensureThreadReady(e), i = t.trim();
|
|
4949
4950
|
if (!i) throw Error("Cannot send an empty message");
|
|
4950
|
-
let a =
|
|
4951
|
+
let a = Qe(i);
|
|
4951
4952
|
if (a) {
|
|
4952
4953
|
if (await this.host.updateSettingsForThread(e, { planMode: !0 }), !a.prompt) return;
|
|
4953
4954
|
i = a.prompt, n = {
|
|
@@ -4955,7 +4956,7 @@ var Ei = class {
|
|
|
4955
4956
|
planMode: !0
|
|
4956
4957
|
};
|
|
4957
4958
|
}
|
|
4958
|
-
let o =
|
|
4959
|
+
let o = $e(i);
|
|
4959
4960
|
if (o) {
|
|
4960
4961
|
if (o.action === "clear") return this.host.clearGoalForThread(e);
|
|
4961
4962
|
if (o.action === "set") return this.host.setGoalForThread(e, o.objective);
|
|
@@ -4963,11 +4964,11 @@ var Ei = class {
|
|
|
4963
4964
|
return;
|
|
4964
4965
|
}
|
|
4965
4966
|
if (i === "/compact") return this.host.compactForThread(e);
|
|
4966
|
-
let s =
|
|
4967
|
+
let s = et(i);
|
|
4967
4968
|
if (s) return this.host.startReviewForThread(e, { target: s });
|
|
4968
4969
|
n = {
|
|
4969
|
-
...
|
|
4970
|
-
...n.skills ? { skills:
|
|
4970
|
+
...qr(this.host.snapshotForRuntime(r), n),
|
|
4971
|
+
...n.skills ? { skills: rt(n.skills, r.skills) } : {}
|
|
4971
4972
|
}, await this.sendPromptToThread(e, i, n);
|
|
4972
4973
|
}
|
|
4973
4974
|
async continueInterruptedTurn() {
|
|
@@ -4990,7 +4991,7 @@ var Ei = class {
|
|
|
4990
4991
|
let n = await this.client.request("turn/start", {
|
|
4991
4992
|
threadId: e,
|
|
4992
4993
|
input: [],
|
|
4993
|
-
...
|
|
4994
|
+
...Gr(this.host.snapshotForRuntime(t), {})
|
|
4994
4995
|
}), r = t.turnIds.includes(n.turn.id);
|
|
4995
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");
|
|
4996
4997
|
let i = n.turn.status === "inProgress";
|
|
@@ -4998,7 +4999,7 @@ var Ei = class {
|
|
|
4998
4999
|
busy: i,
|
|
4999
5000
|
turnStartPending: !1,
|
|
5000
5001
|
turns: G(t.turns, W(n.turn)),
|
|
5001
|
-
messages: i ?
|
|
5002
|
+
messages: i ? I(t.messages, e, n.turn.id) : t.messages
|
|
5002
5003
|
}), this.host.patchConversationStatus(e, i ? "active" : "idle", "action"), i && !r && this.host.emitEvent("action", {
|
|
5003
5004
|
type: "turn.started",
|
|
5004
5005
|
conversationId: e,
|
|
@@ -5009,28 +5010,28 @@ var Ei = class {
|
|
|
5009
5010
|
throw this.host.patchRuntime(e, {
|
|
5010
5011
|
busy: !1,
|
|
5011
5012
|
turnStartPending: !1,
|
|
5012
|
-
error:
|
|
5013
|
+
error: O(t)
|
|
5013
5014
|
}), this.host.patchConversationStatus(e, "error", "action"), this.host.emitConversationActivity(e, "action"), t;
|
|
5014
5015
|
}
|
|
5015
5016
|
}
|
|
5016
5017
|
async sendPromptToThread(e, t, n = {}, r) {
|
|
5017
|
-
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 ?? []);
|
|
5018
5019
|
if (i.busy) {
|
|
5019
5020
|
this.host.patchRuntime(e, { queuedPrompts: [...i.queuedPrompts, {
|
|
5020
|
-
id:
|
|
5021
|
+
id: vr(),
|
|
5021
5022
|
text: o,
|
|
5022
5023
|
...Object.keys(a).length > 0 ? { options: a } : {}
|
|
5023
5024
|
}] }), this.emitQueuedPrompts(e);
|
|
5024
5025
|
return;
|
|
5025
5026
|
}
|
|
5026
|
-
let l =
|
|
5027
|
+
let l = _r(), u = {
|
|
5027
5028
|
id: l,
|
|
5028
5029
|
role: "user",
|
|
5029
5030
|
status: "complete",
|
|
5030
5031
|
parts: [{
|
|
5031
5032
|
type: "text",
|
|
5032
5033
|
text: o
|
|
5033
|
-
}, ...c.map(
|
|
5034
|
+
}, ...c.map(Xr)],
|
|
5034
5035
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5035
5036
|
metadata: {
|
|
5036
5037
|
conversationId: e,
|
|
@@ -5057,14 +5058,14 @@ var Ei = class {
|
|
|
5057
5058
|
text: t,
|
|
5058
5059
|
text_elements: []
|
|
5059
5060
|
},
|
|
5060
|
-
...c.map(
|
|
5061
|
+
...c.map(Yr),
|
|
5061
5062
|
...s.map((e) => ({
|
|
5062
5063
|
type: "skill",
|
|
5063
5064
|
name: e.name,
|
|
5064
5065
|
path: e.path
|
|
5065
5066
|
}))
|
|
5066
5067
|
],
|
|
5067
|
-
...
|
|
5068
|
+
...Gr(this.host.snapshotForRuntime(i), a),
|
|
5068
5069
|
...a.outputSchema === void 0 ? {} : { outputSchema: a.outputSchema }
|
|
5069
5070
|
}), r = i.turnIds.includes(n.turn.id);
|
|
5070
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");
|
|
@@ -5080,7 +5081,7 @@ var Ei = class {
|
|
|
5080
5081
|
busy: o,
|
|
5081
5082
|
turnStartPending: !1,
|
|
5082
5083
|
turns: G(i.turns, W(n.turn)),
|
|
5083
|
-
messages: o ?
|
|
5084
|
+
messages: o ? I(u, e, n.turn.id) : u
|
|
5084
5085
|
}), this.host.patchConversationStatus(e, o ? "active" : "idle", "action");
|
|
5085
5086
|
let d = u.find((e) => e.id === l);
|
|
5086
5087
|
d && this.host.emitEvent("action", {
|
|
@@ -5098,7 +5099,7 @@ var Ei = class {
|
|
|
5098
5099
|
throw this.host.patchRuntime(e, {
|
|
5099
5100
|
busy: !1,
|
|
5100
5101
|
turnStartPending: !1,
|
|
5101
|
-
error:
|
|
5102
|
+
error: O(t)
|
|
5102
5103
|
}), this.host.patchConversationStatus(e, "error", "action"), this.host.emitConversationActivity(e, "action"), t;
|
|
5103
5104
|
}
|
|
5104
5105
|
}
|
|
@@ -5110,7 +5111,7 @@ var Ei = class {
|
|
|
5110
5111
|
let i = await this.host.ensureThreadReady(e), a = t.trim(), o = r?.trim() || a;
|
|
5111
5112
|
if (!a) throw Error("Cannot steer with an empty message");
|
|
5112
5113
|
if (!i.activeTurnId) throw Error("There is no active turn to steer");
|
|
5113
|
-
let s =
|
|
5114
|
+
let s = Jr(n.attachments ?? []), c = _r(), l = {
|
|
5114
5115
|
id: c,
|
|
5115
5116
|
kind: "steer",
|
|
5116
5117
|
role: "user",
|
|
@@ -5118,7 +5119,7 @@ var Ei = class {
|
|
|
5118
5119
|
parts: [{
|
|
5119
5120
|
type: "text",
|
|
5120
5121
|
text: o
|
|
5121
|
-
}, ...s.map(
|
|
5122
|
+
}, ...s.map(Xr)],
|
|
5122
5123
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5123
5124
|
turnId: i.activeTurnId,
|
|
5124
5125
|
metadata: {
|
|
@@ -5129,7 +5130,7 @@ var Ei = class {
|
|
|
5129
5130
|
};
|
|
5130
5131
|
this.host.patchRuntime(e, {
|
|
5131
5132
|
error: null,
|
|
5132
|
-
messages:
|
|
5133
|
+
messages: I([...i.messages, l], e, i.activeTurnId, { forceSegment: !0 })
|
|
5133
5134
|
}), this.host.emitEvent("action", {
|
|
5134
5135
|
type: "message.appended",
|
|
5135
5136
|
conversationId: e,
|
|
@@ -5145,7 +5146,7 @@ var Ei = class {
|
|
|
5145
5146
|
type: "text",
|
|
5146
5147
|
text: a,
|
|
5147
5148
|
text_elements: []
|
|
5148
|
-
}, ...s.map(
|
|
5149
|
+
}, ...s.map(Yr)]
|
|
5149
5150
|
}), n = i.turnIds.includes(t.turnId);
|
|
5150
5151
|
i.activeTurnId = t.turnId, i.turnIds.includes(t.turnId) || i.turnIds.push(t.turnId), i.turns = G(i.turns, {
|
|
5151
5152
|
id: t.turnId,
|
|
@@ -5164,14 +5165,14 @@ var Ei = class {
|
|
|
5164
5165
|
turnId: t.turnId
|
|
5165
5166
|
}
|
|
5166
5167
|
} : e);
|
|
5167
|
-
this.host.patchRuntime(e, { messages: I(
|
|
5168
|
+
this.host.patchRuntime(e, { messages: R(I(r, e, t.turnId), e) }), n || this.host.emitEvent("action", {
|
|
5168
5169
|
type: "turn.started",
|
|
5169
5170
|
conversationId: e,
|
|
5170
5171
|
turnId: t.turnId,
|
|
5171
5172
|
payload: { startedAt: (/* @__PURE__ */ new Date()).toISOString() }
|
|
5172
5173
|
});
|
|
5173
5174
|
} catch (t) {
|
|
5174
|
-
throw this.host.patchRuntime(e, { error:
|
|
5175
|
+
throw this.host.patchRuntime(e, { error: O(t) }), t;
|
|
5175
5176
|
}
|
|
5176
5177
|
}
|
|
5177
5178
|
async answerAsyncQuestion(e, t, n) {
|
|
@@ -5224,7 +5225,7 @@ var Ei = class {
|
|
|
5224
5225
|
await this.sendPromptToThread(e, n.text, n.options);
|
|
5225
5226
|
} catch (r) {
|
|
5226
5227
|
this.host.patchRuntime(e, {
|
|
5227
|
-
error:
|
|
5228
|
+
error: O(r),
|
|
5228
5229
|
queuedPrompts: [n, ...t.queuedPrompts]
|
|
5229
5230
|
}), this.emitQueuedPrompts(e, "notification");
|
|
5230
5231
|
}
|
|
@@ -5242,7 +5243,7 @@ var Ei = class {
|
|
|
5242
5243
|
if (!e) throw Error("There is no active conversation");
|
|
5243
5244
|
return e;
|
|
5244
5245
|
}
|
|
5245
|
-
},
|
|
5246
|
+
}, Ni = 5, Pi = class {
|
|
5246
5247
|
client;
|
|
5247
5248
|
options;
|
|
5248
5249
|
catalog;
|
|
@@ -5280,9 +5281,9 @@ var Ei = class {
|
|
|
5280
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({
|
|
5281
5282
|
...e,
|
|
5282
5283
|
...a ? { approvalPreset: a } : {}
|
|
5283
|
-
}, r.approvalPresets), s = q(i.models, i.selectedModelId), c = e.model ?
|
|
5284
|
-
|
|
5285
|
-
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({
|
|
5286
5287
|
operation: "start",
|
|
5287
5288
|
conversationId: null,
|
|
5288
5289
|
cwd: n,
|
|
@@ -5299,11 +5300,11 @@ var Ei = class {
|
|
|
5299
5300
|
...d === void 0 ? {} : { serviceTier: d },
|
|
5300
5301
|
...e.threadSource === void 0 ? {} : { threadSource: e.threadSource },
|
|
5301
5302
|
serviceName: "codex_app_sdk"
|
|
5302
|
-
}), h =
|
|
5303
|
+
}), h = Vr(m, i.models, i);
|
|
5303
5304
|
u && (await this.client.request("thread/settings/update", {
|
|
5304
5305
|
threadId: m.thread.id,
|
|
5305
5306
|
effort: u,
|
|
5306
|
-
...c ? { collaborationMode:
|
|
5307
|
+
...c ? { collaborationMode: Wr(i.planMode, c.model, u) } : {}
|
|
5307
5308
|
}), h.selectedReasoningEffort = u), d !== void 0 && (h.selectedServiceTier = d), c && (h.selectedModelId = c.id), a && (h.approvalPreset = a);
|
|
5308
5309
|
let g = this.host.createRuntime(m.thread.id, {
|
|
5309
5310
|
hydrated: !0,
|
|
@@ -5387,7 +5388,7 @@ var Ei = class {
|
|
|
5387
5388
|
} catch (t) {
|
|
5388
5389
|
throw this.host.patchRuntime(e, {
|
|
5389
5390
|
historyLoading: !1,
|
|
5390
|
-
error:
|
|
5391
|
+
error: O(t)
|
|
5391
5392
|
}), t;
|
|
5392
5393
|
}
|
|
5393
5394
|
}
|
|
@@ -5397,7 +5398,7 @@ var Ei = class {
|
|
|
5397
5398
|
...n
|
|
5398
5399
|
}, a = {
|
|
5399
5400
|
...i,
|
|
5400
|
-
mcpServers: i.mcpServers === void 0 ? this.extensions.defaultMcpServers :
|
|
5401
|
+
mcpServers: i.mcpServers === void 0 ? this.extensions.defaultMcpServers : hi(i.mcpServers)
|
|
5401
5402
|
};
|
|
5402
5403
|
this.hostOptionsByThread.set(e, a);
|
|
5403
5404
|
let o = await this.extensions.conversationExtension({
|
|
@@ -5415,7 +5416,7 @@ var Ei = class {
|
|
|
5415
5416
|
threadId: e,
|
|
5416
5417
|
excludeTurns: !0,
|
|
5417
5418
|
initialTurnsPage: {
|
|
5418
|
-
limit:
|
|
5419
|
+
limit: Ni,
|
|
5419
5420
|
sortDirection: "desc",
|
|
5420
5421
|
itemsView: "full"
|
|
5421
5422
|
},
|
|
@@ -5428,7 +5429,7 @@ var Ei = class {
|
|
|
5428
5429
|
let i = t.initialTurnsPage ?? await this.client.request("thread/turns/list", {
|
|
5429
5430
|
threadId: t.thread.id,
|
|
5430
5431
|
cursor: null,
|
|
5431
|
-
limit:
|
|
5432
|
+
limit: Ni,
|
|
5432
5433
|
sortDirection: "desc",
|
|
5433
5434
|
itemsView: "full"
|
|
5434
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" ? {
|
|
@@ -5436,12 +5437,12 @@ var Ei = class {
|
|
|
5436
5437
|
status: "interrupted"
|
|
5437
5438
|
} : e), _ = new Map(g.map((e) => [e.id, W(e)]));
|
|
5438
5439
|
for (let e of m) _.set(e.id, e);
|
|
5439
|
-
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({
|
|
5440
5441
|
...t.thread,
|
|
5441
5442
|
turns: g
|
|
5442
5443
|
})), b = new Map(y.map((e) => [e.id, e]));
|
|
5443
5444
|
for (let e of s.messages) l.get(e.id) !== e && b.set(e.id, e);
|
|
5444
|
-
let
|
|
5445
|
+
let x = v ? I([...b.values()], t.thread.id, v) : [...b.values()], S = this.host.createRuntime(t.thread.id, {
|
|
5445
5446
|
hydrated: !0,
|
|
5446
5447
|
historyMode: t.thread.historyMode ?? "legacy",
|
|
5447
5448
|
loadingStrategy: a.loadingStrategy ?? this.options.loadingStrategy ?? "lazy",
|
|
@@ -5454,27 +5455,27 @@ var Ei = class {
|
|
|
5454
5455
|
activeTurnId: v,
|
|
5455
5456
|
turns: [..._.values()],
|
|
5456
5457
|
turnIds: [..._.keys()],
|
|
5457
|
-
messages:
|
|
5458
|
+
messages: x,
|
|
5458
5459
|
busy: m.length > 0 ? s.busy : !!v || h.type === "active",
|
|
5459
5460
|
goal: n ? { ...n } : null,
|
|
5460
5461
|
threadStatus: h,
|
|
5461
5462
|
...p,
|
|
5462
|
-
...
|
|
5463
|
-
}),
|
|
5463
|
+
...Vr(t, this.host.getState().models, this.host.snapshotForRuntime(s))
|
|
5464
|
+
}), C = {
|
|
5464
5465
|
...Z(t.thread),
|
|
5465
5466
|
turnCount: d.length
|
|
5466
|
-
},
|
|
5467
|
+
}, ee = this.host.getState();
|
|
5467
5468
|
return this.host.patch({
|
|
5468
|
-
conversations: Q(
|
|
5469
|
-
...
|
|
5470
|
-
}), 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, {
|
|
5471
5472
|
cursor: i.nextCursor,
|
|
5472
5473
|
initialPageLoaded: !0
|
|
5473
5474
|
}).catch(() => void 0), this.host.getSnapshot();
|
|
5474
5475
|
} catch (t) {
|
|
5475
5476
|
throw this.host.patchRuntime(e, {
|
|
5476
5477
|
historyLoading: !1,
|
|
5477
|
-
error:
|
|
5478
|
+
error: O(t)
|
|
5478
5479
|
}), t;
|
|
5479
5480
|
}
|
|
5480
5481
|
}
|
|
@@ -5488,7 +5489,7 @@ var Ei = class {
|
|
|
5488
5489
|
threadStatus: structuredClone(t.threadStatus)
|
|
5489
5490
|
};
|
|
5490
5491
|
}
|
|
5491
|
-
},
|
|
5492
|
+
}, Fi = class {
|
|
5492
5493
|
authentication;
|
|
5493
5494
|
approvals;
|
|
5494
5495
|
catalog;
|
|
@@ -5523,7 +5524,7 @@ var Ei = class {
|
|
|
5523
5524
|
let a = this.host.getState();
|
|
5524
5525
|
this.host.patch({ conversations: a.conversations.map((e) => e.id === t ? {
|
|
5525
5526
|
...e,
|
|
5526
|
-
status:
|
|
5527
|
+
status: ti(n)
|
|
5527
5528
|
} : e) });
|
|
5528
5529
|
let o = this.host.getState().conversations.find((e) => e.id === t);
|
|
5529
5530
|
o && this.host.emitSummaryUpserted(o, "updated", "notification"), this.host.emitConversationActivity(t, "notification"), n.type === "idle" && this.host.sendNextQueuedPrompt(t);
|
|
@@ -5535,7 +5536,7 @@ var Ei = class {
|
|
|
5535
5536
|
return;
|
|
5536
5537
|
case "thread/unarchived":
|
|
5537
5538
|
this.conversations.load().catch((e) => {
|
|
5538
|
-
this.host.patch({ error:
|
|
5539
|
+
this.host.patch({ error: O(e) });
|
|
5539
5540
|
});
|
|
5540
5541
|
return;
|
|
5541
5542
|
case "thread/closed": {
|
|
@@ -5565,12 +5566,12 @@ var Ei = class {
|
|
|
5565
5566
|
return;
|
|
5566
5567
|
}
|
|
5567
5568
|
case "thread/settings/updated": {
|
|
5568
|
-
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;
|
|
5569
5570
|
this.host.patchRuntime(e.params.threadId, r), i && this.host.emitConversationSettings(e.params.threadId, "notification");
|
|
5570
5571
|
return;
|
|
5571
5572
|
}
|
|
5572
5573
|
case "thread/goal/updated":
|
|
5573
|
-
if (
|
|
5574
|
+
if (gr(this.host.requireRuntime(e.params.threadId).goal, e.params.goal)) return;
|
|
5574
5575
|
this.host.patchRuntime(e.params.threadId, { goal: { ...e.params.goal } }), this.host.emitEvent("notification", {
|
|
5575
5576
|
type: "conversation.goalChanged",
|
|
5576
5577
|
conversationId: e.params.threadId,
|
|
@@ -5587,7 +5588,7 @@ var Ei = class {
|
|
|
5587
5588
|
});
|
|
5588
5589
|
return;
|
|
5589
5590
|
case "thread/tokenUsage/updated": {
|
|
5590
|
-
let t =
|
|
5591
|
+
let t = ei(e.params.tokenUsage);
|
|
5591
5592
|
this.host.patchRuntime(e.params.threadId, { contextUsage: t }), this.host.emitEvent("notification", {
|
|
5592
5593
|
type: "conversation.contextUsageChanged",
|
|
5593
5594
|
conversationId: e.params.threadId,
|
|
@@ -5604,7 +5605,7 @@ var Ei = class {
|
|
|
5604
5605
|
error: null,
|
|
5605
5606
|
turnGitDiff: null,
|
|
5606
5607
|
turns: G(t.turns, W(e.params.turn)),
|
|
5607
|
-
messages:
|
|
5608
|
+
messages: I(t.messages, e.params.threadId, e.params.turn.id, { createdAt: U(e.params.turn.startedAt) })
|
|
5608
5609
|
}), this.host.patchConversationStatus(e.params.threadId, "active"), n || this.host.emitEvent("notification", {
|
|
5609
5610
|
type: "turn.started",
|
|
5610
5611
|
conversationId: e.params.threadId,
|
|
@@ -5625,13 +5626,13 @@ var Ei = class {
|
|
|
5625
5626
|
return;
|
|
5626
5627
|
case "item/commandExecution/outputDelta":
|
|
5627
5628
|
if (!this.items.isForwardingCommandOutput(e.params.threadId, e.params.itemId)) return;
|
|
5628
|
-
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));
|
|
5629
5630
|
return;
|
|
5630
5631
|
case "item/fileChange/patchUpdated":
|
|
5631
|
-
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));
|
|
5632
5633
|
return;
|
|
5633
5634
|
case "item/mcpToolCall/progress":
|
|
5634
|
-
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));
|
|
5635
5636
|
return;
|
|
5636
5637
|
case "rawResponseItem/completed":
|
|
5637
5638
|
this.items.applyRawResponseItem(e.params);
|
|
@@ -5645,7 +5646,7 @@ var Ei = class {
|
|
|
5645
5646
|
return;
|
|
5646
5647
|
}
|
|
5647
5648
|
case "turn/diff/updated": {
|
|
5648
|
-
let t =
|
|
5649
|
+
let t = sn(e.params.diff);
|
|
5649
5650
|
this.host.patchRuntime(e.params.threadId, { turnGitDiff: {
|
|
5650
5651
|
turnId: e.params.turnId,
|
|
5651
5652
|
addedLines: t.addedLines,
|
|
@@ -5661,7 +5662,7 @@ var Ei = class {
|
|
|
5661
5662
|
}
|
|
5662
5663
|
case "thread/compacted": {
|
|
5663
5664
|
let t = this.host.requireRuntime(e.params.threadId);
|
|
5664
|
-
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") });
|
|
5665
5666
|
let n = this.host.requireRuntime(e.params.threadId).messages.find((t) => t.kind === "compaction" && t.metadata?.turnId === e.params.turnId);
|
|
5666
5667
|
this.host.emitEvent("notification", {
|
|
5667
5668
|
type: "context.compactionCompleted",
|
|
@@ -5690,7 +5691,7 @@ var Ei = class {
|
|
|
5690
5691
|
durationMs: null
|
|
5691
5692
|
},
|
|
5692
5693
|
status: e.params.willRetry ? "inProgress" : "failed",
|
|
5693
|
-
error:
|
|
5694
|
+
error: hr(e.params.error),
|
|
5694
5695
|
willRetry: e.params.willRetry
|
|
5695
5696
|
}),
|
|
5696
5697
|
...n ? {
|
|
@@ -5702,7 +5703,7 @@ var Ei = class {
|
|
|
5702
5703
|
conversationId: e.params.threadId,
|
|
5703
5704
|
turnId: e.params.turnId,
|
|
5704
5705
|
payload: {
|
|
5705
|
-
error:
|
|
5706
|
+
error: hr(e.params.error),
|
|
5706
5707
|
willRetry: e.params.willRetry
|
|
5707
5708
|
}
|
|
5708
5709
|
}), this.host.emitConversationActivity(e.params.threadId, "notification");
|
|
@@ -5710,14 +5711,14 @@ var Ei = class {
|
|
|
5710
5711
|
}
|
|
5711
5712
|
case "account/rateLimits/updated": {
|
|
5712
5713
|
let t = this.host.getState();
|
|
5713
|
-
this.host.patch({ rateLimits:
|
|
5714
|
+
this.host.patch({ rateLimits: ii(t.rateLimits, e.params.rateLimits) }), this.host.emitEvent("notification", {
|
|
5714
5715
|
type: "rateLimits.changed",
|
|
5715
5716
|
payload: { rateLimits: structuredClone(this.host.getState().rateLimits) }
|
|
5716
5717
|
});
|
|
5717
5718
|
return;
|
|
5718
5719
|
}
|
|
5719
5720
|
case "account/updated":
|
|
5720
|
-
this.authentication.refresh("notification").catch((e) => this.host.patch({ error:
|
|
5721
|
+
this.authentication.refresh("notification").catch((e) => this.host.patch({ error: O(e) }));
|
|
5721
5722
|
return;
|
|
5722
5723
|
case "account/login/completed":
|
|
5723
5724
|
this.authentication.handleLoginCompleted(e.params);
|
|
@@ -5781,7 +5782,7 @@ var Ei = class {
|
|
|
5781
5782
|
this.host.emitEvent("notification", {
|
|
5782
5783
|
type: "realtime.audioDelta",
|
|
5783
5784
|
conversationId: e.params.threadId,
|
|
5784
|
-
payload: { audio:
|
|
5785
|
+
payload: { audio: ft(e.params.audio) }
|
|
5785
5786
|
});
|
|
5786
5787
|
return;
|
|
5787
5788
|
case "thread/realtime/sdp":
|
|
@@ -5849,7 +5850,7 @@ var Ei = class {
|
|
|
5849
5850
|
default: return this.host.unknownNotification(e);
|
|
5850
5851
|
}
|
|
5851
5852
|
}
|
|
5852
|
-
},
|
|
5853
|
+
}, Ii = class {
|
|
5853
5854
|
approvals;
|
|
5854
5855
|
clientRequests;
|
|
5855
5856
|
host;
|
|
@@ -5873,14 +5874,14 @@ var Ei = class {
|
|
|
5873
5874
|
create(e, t = {}) {
|
|
5874
5875
|
let n = this.runtimes.get(e);
|
|
5875
5876
|
if (n) return Object.assign(n, t), n;
|
|
5876
|
-
let r =
|
|
5877
|
+
let r = vt(e, this.host.getState(), t);
|
|
5877
5878
|
return this.runtimes.set(e, r), r;
|
|
5878
5879
|
}
|
|
5879
5880
|
require(e) {
|
|
5880
5881
|
return this.runtimes.get(e) ?? this.create(e);
|
|
5881
5882
|
}
|
|
5882
5883
|
projection(e) {
|
|
5883
|
-
return
|
|
5884
|
+
return yt(e, this.approvals.approvalsForThread(e.threadId), this.clientRequests.requestsForThread(e.threadId));
|
|
5884
5885
|
}
|
|
5885
5886
|
snapshot(e) {
|
|
5886
5887
|
return {
|
|
@@ -5910,7 +5911,7 @@ var Ei = class {
|
|
|
5910
5911
|
conversationId: e,
|
|
5911
5912
|
payload: {
|
|
5912
5913
|
historyLoading: n.historyLoading,
|
|
5913
|
-
historyState:
|
|
5914
|
+
historyState: zi(n),
|
|
5914
5915
|
error: n.error
|
|
5915
5916
|
}
|
|
5916
5917
|
});
|
|
@@ -6004,7 +6005,7 @@ var Ei = class {
|
|
|
6004
6005
|
reason: t,
|
|
6005
6006
|
messages: structuredClone(r.messages),
|
|
6006
6007
|
threadStatus: structuredClone(r.threadStatus),
|
|
6007
|
-
state:
|
|
6008
|
+
state: Li(r)
|
|
6008
6009
|
}
|
|
6009
6010
|
});
|
|
6010
6011
|
}
|
|
@@ -6016,7 +6017,7 @@ var Ei = class {
|
|
|
6016
6017
|
conversationId: e,
|
|
6017
6018
|
payload: {
|
|
6018
6019
|
messages: structuredClone(t.map((e) => r.get(e.id) ?? e)),
|
|
6019
|
-
state:
|
|
6020
|
+
state: Ri(this.require(e))
|
|
6020
6021
|
}
|
|
6021
6022
|
});
|
|
6022
6023
|
}
|
|
@@ -6058,7 +6059,7 @@ var Ei = class {
|
|
|
6058
6059
|
i && this.emitSummaryUpserted(i, "updated", n);
|
|
6059
6060
|
}
|
|
6060
6061
|
};
|
|
6061
|
-
function
|
|
6062
|
+
function Li(e) {
|
|
6062
6063
|
return structuredClone({
|
|
6063
6064
|
activeTurnId: e.activeTurnId,
|
|
6064
6065
|
answeredClientRequestIds: e.answeredClientRequestIds,
|
|
@@ -6067,21 +6068,21 @@ function ji(e) {
|
|
|
6067
6068
|
error: e.error,
|
|
6068
6069
|
executionPlan: e.executionPlan,
|
|
6069
6070
|
historyLoading: e.historyLoading,
|
|
6070
|
-
historyState:
|
|
6071
|
+
historyState: zi(e),
|
|
6071
6072
|
turnGitDiff: e.turnGitDiff,
|
|
6072
6073
|
turnIds: e.turnIds,
|
|
6073
6074
|
turns: e.turns
|
|
6074
6075
|
});
|
|
6075
6076
|
}
|
|
6076
|
-
function
|
|
6077
|
+
function Ri(e) {
|
|
6077
6078
|
return structuredClone({
|
|
6078
6079
|
historyLoading: e.historyLoading,
|
|
6079
|
-
historyState:
|
|
6080
|
+
historyState: zi(e),
|
|
6080
6081
|
turnIds: e.turnIds,
|
|
6081
6082
|
turns: e.turns
|
|
6082
6083
|
});
|
|
6083
6084
|
}
|
|
6084
|
-
function
|
|
6085
|
+
function zi(e) {
|
|
6085
6086
|
return {
|
|
6086
6087
|
loadingStrategy: e.loadingStrategy,
|
|
6087
6088
|
hasOlder: e.historyHasOlder,
|
|
@@ -6091,7 +6092,7 @@ function Ni(e) {
|
|
|
6091
6092
|
}
|
|
6092
6093
|
//#endregion
|
|
6093
6094
|
//#region src/node/codex-surface-connection-controller.ts
|
|
6094
|
-
var
|
|
6095
|
+
var Bi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_request_user_input"]), Vi = class {
|
|
6095
6096
|
client;
|
|
6096
6097
|
options;
|
|
6097
6098
|
authentication;
|
|
@@ -6138,7 +6139,7 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6138
6139
|
} catch (e) {
|
|
6139
6140
|
throw this.host.patch({
|
|
6140
6141
|
status: "error",
|
|
6141
|
-
error:
|
|
6142
|
+
error: O(e)
|
|
6142
6143
|
}), this.host.emitSurfaceStatus("lifecycle"), e;
|
|
6143
6144
|
} finally {
|
|
6144
6145
|
this.connectPromise = null;
|
|
@@ -6154,7 +6155,7 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6154
6155
|
limit: 100,
|
|
6155
6156
|
threadId: null
|
|
6156
6157
|
});
|
|
6157
|
-
for (let e of n.data)
|
|
6158
|
+
for (let e of n.data) Bi.has(e.name) && !e.enabled && (t[e.name] = !0);
|
|
6158
6159
|
e = n.nextCursor;
|
|
6159
6160
|
} while (e);
|
|
6160
6161
|
Object.keys(t).length > 0 && await this.client.request("experimentalFeature/enablement/set", { enablement: t });
|
|
@@ -6171,7 +6172,7 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6171
6172
|
}
|
|
6172
6173
|
}
|
|
6173
6174
|
bootstrapSurfaceData(e = !1) {
|
|
6174
|
-
let t =
|
|
6175
|
+
let t = St(this.host.getState().authentication);
|
|
6175
6176
|
if (!e && this.bootstrappedAuthenticationKey === t) return Promise.resolve();
|
|
6176
6177
|
if (this.surfaceBootstrapPromise) return this.surfaceBootstrapPromise.then(() => this.bootstrapSurfaceData(e));
|
|
6177
6178
|
let n = (async () => {
|
|
@@ -6288,7 +6289,7 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6288
6289
|
error: null
|
|
6289
6290
|
});
|
|
6290
6291
|
}
|
|
6291
|
-
},
|
|
6292
|
+
}, Hi = 5, Ui = class {
|
|
6292
6293
|
client;
|
|
6293
6294
|
loadingStrategy;
|
|
6294
6295
|
catalog;
|
|
@@ -6300,9 +6301,9 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6300
6301
|
async fork(e, t = {}, n = {}, r = {}) {
|
|
6301
6302
|
let i = this.host.requireRuntime(e);
|
|
6302
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");
|
|
6303
|
-
let a = t.cwd ?? i.cwd ?? n.cwd, o = await this.catalog.loadConversationCatalogs(a ?? void 0), s = this.host.getState(), c = t.model ?
|
|
6304
|
-
|
|
6305
|
-
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({
|
|
6306
6307
|
operation: "start",
|
|
6307
6308
|
conversationId: null,
|
|
6308
6309
|
cwd: a ?? void 0,
|
|
@@ -6320,24 +6321,24 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6320
6321
|
...u.baseInstructions === void 0 ? {} : { baseInstructions: u.baseInstructions },
|
|
6321
6322
|
...u.developerInstructions === void 0 ? {} : { developerInstructions: u.developerInstructions },
|
|
6322
6323
|
...u.config === void 0 ? {} : { config: u.config },
|
|
6323
|
-
...
|
|
6324
|
+
...Wi(t, o.approvalPresets)
|
|
6324
6325
|
});
|
|
6325
6326
|
if (!d.thread.id || d.thread.id === e) throw Error(`Codex thread/fork returned an invalid new thread id '${d.thread.id}'`);
|
|
6326
6327
|
t.reasoningEffort && await this.client.request("thread/settings/update", {
|
|
6327
6328
|
threadId: d.thread.id,
|
|
6328
6329
|
effort: t.reasoningEffort,
|
|
6329
|
-
...c ? { collaborationMode:
|
|
6330
|
+
...c ? { collaborationMode: Wr(i.planMode, c.model, t.reasoningEffort) } : {}
|
|
6330
6331
|
});
|
|
6331
6332
|
let [f, p] = await Promise.all([this.client.request("thread/turns/list", {
|
|
6332
6333
|
threadId: d.thread.id,
|
|
6333
6334
|
cursor: null,
|
|
6334
|
-
limit:
|
|
6335
|
+
limit: Hi,
|
|
6335
6336
|
sortDirection: "desc",
|
|
6336
6337
|
itemsView: "full"
|
|
6337
|
-
}), 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({
|
|
6338
6339
|
...d.thread,
|
|
6339
6340
|
turns: m
|
|
6340
|
-
}), _ = h ?
|
|
6341
|
+
}), _ = h ? I(g, d.thread.id, h) : g, v = n.loadingStrategy ?? this.loadingStrategy ?? "lazy", y = this.host.createRuntime(d.thread.id, {
|
|
6341
6342
|
hydrated: !0,
|
|
6342
6343
|
historyMode: d.thread.historyMode ?? "legacy",
|
|
6343
6344
|
loadingStrategy: v,
|
|
@@ -6354,7 +6355,7 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6354
6355
|
goal: p ? { ...p } : null,
|
|
6355
6356
|
threadStatus: $(d.thread.status),
|
|
6356
6357
|
...o,
|
|
6357
|
-
...
|
|
6358
|
+
...Vr(d, s.models, this.host.snapshotForRuntime(i))
|
|
6358
6359
|
});
|
|
6359
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, {
|
|
6360
6361
|
...n,
|
|
@@ -6373,10 +6374,10 @@ var Pi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6373
6374
|
return this.fork(e, n, r, { lastTurnId: t });
|
|
6374
6375
|
}
|
|
6375
6376
|
};
|
|
6376
|
-
function
|
|
6377
|
+
function Wi(e, t) {
|
|
6377
6378
|
if (e.approvalPreset) {
|
|
6378
6379
|
if (!t.includes(e.approvalPreset)) throw Error(`Approval preset '${e.approvalPreset}' is not available`);
|
|
6379
|
-
return
|
|
6380
|
+
return Rr(e.approvalPreset);
|
|
6380
6381
|
}
|
|
6381
6382
|
return {
|
|
6382
6383
|
...e.approvalMode === void 0 ? {} : { approvalPolicy: e.approvalMode === "ask" ? "on-request" : "never" },
|
|
@@ -6385,27 +6386,27 @@ function Ri(e, t) {
|
|
|
6385
6386
|
}
|
|
6386
6387
|
//#endregion
|
|
6387
6388
|
//#region src/node/codex-markdown-images.ts
|
|
6388
|
-
var
|
|
6389
|
+
var Gi = /(?<!\[)!\[([^\]]*)\]\(([^)\s]+)(?:\s+["']([^"']*)["'])?\)/g, Ki = /* @__PURE__ */ new Set([
|
|
6389
6390
|
".avif",
|
|
6390
6391
|
".gif",
|
|
6391
6392
|
".jpeg",
|
|
6392
6393
|
".jpg",
|
|
6393
6394
|
".png",
|
|
6394
6395
|
".webp"
|
|
6395
|
-
]),
|
|
6396
|
+
]), qi = class {
|
|
6396
6397
|
client;
|
|
6397
6398
|
constructor(e) {
|
|
6398
6399
|
this.client = e;
|
|
6399
6400
|
}
|
|
6400
6401
|
async hydrate(e, t) {
|
|
6401
|
-
let n =
|
|
6402
|
-
return
|
|
6402
|
+
let n = Xi(e);
|
|
6403
|
+
return Yi(e, (await Promise.all(Array.from(e.matchAll(Gi), async (e) => {
|
|
6403
6404
|
let r = e.index ?? 0;
|
|
6404
|
-
if (
|
|
6405
|
-
let i = e[2], a =
|
|
6405
|
+
if (Zi(r, n)) return null;
|
|
6406
|
+
let i = e[2], a = Ji(i, t);
|
|
6406
6407
|
if (!a) return null;
|
|
6407
6408
|
try {
|
|
6408
|
-
let t =
|
|
6409
|
+
let t = Zn((await this.client.request("fs/readFile", { path: a })).dataBase64);
|
|
6409
6410
|
if (!t) return null;
|
|
6410
6411
|
let n = e[0].indexOf("](") + 2;
|
|
6411
6412
|
return {
|
|
@@ -6419,12 +6420,12 @@ var zi = /(?<!\[)!\[([^\]]*)\]\(([^)\s]+)(?:\s+["']([^"']*)["'])?\)/g, Bi = /* @
|
|
|
6419
6420
|
}))).filter((e) => e !== null));
|
|
6420
6421
|
}
|
|
6421
6422
|
};
|
|
6422
|
-
function
|
|
6423
|
+
function Ji(e, t) {
|
|
6423
6424
|
let n = e.trim();
|
|
6424
6425
|
if (!n || /[\u0000-\u001f\u007f]/.test(n)) return null;
|
|
6425
6426
|
let r;
|
|
6426
6427
|
if (n.startsWith("file://")) try {
|
|
6427
|
-
r =
|
|
6428
|
+
r = ne(n);
|
|
6428
6429
|
} catch {
|
|
6429
6430
|
return null;
|
|
6430
6431
|
}
|
|
@@ -6434,18 +6435,18 @@ function Hi(e, t) {
|
|
|
6434
6435
|
} catch {
|
|
6435
6436
|
return null;
|
|
6436
6437
|
}
|
|
6437
|
-
if (!
|
|
6438
|
-
if (
|
|
6439
|
-
if (!t || !
|
|
6440
|
-
let i =
|
|
6441
|
-
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;
|
|
6442
6443
|
}
|
|
6443
|
-
function
|
|
6444
|
+
function Yi(e, t) {
|
|
6444
6445
|
let n = e;
|
|
6445
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)}`;
|
|
6446
6447
|
return n;
|
|
6447
6448
|
}
|
|
6448
|
-
function
|
|
6449
|
+
function Xi(e) {
|
|
6449
6450
|
let t = [], n = /(^|\n)(```|~~~)/g, r;
|
|
6450
6451
|
for (; (r = n.exec(e)) !== null;) {
|
|
6451
6452
|
let i = r[2], a = r[1], o = r.index + a.length, s = RegExp(`(^|\\n)${i}`, "g");
|
|
@@ -6466,15 +6467,15 @@ function Wi(e) {
|
|
|
6466
6467
|
}
|
|
6467
6468
|
return t;
|
|
6468
6469
|
}
|
|
6469
|
-
function
|
|
6470
|
+
function Zi(e, t) {
|
|
6470
6471
|
return t.some((t) => e >= t.start && e <= t.end);
|
|
6471
6472
|
}
|
|
6472
|
-
var
|
|
6473
|
-
async function
|
|
6474
|
-
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);
|
|
6475
6476
|
return {
|
|
6476
6477
|
conversationId: n,
|
|
6477
|
-
prompts:
|
|
6478
|
+
prompts: na((await e.request("thread/turns/list", {
|
|
6478
6479
|
threadId: n,
|
|
6479
6480
|
cursor: null,
|
|
6480
6481
|
limit: 100,
|
|
@@ -6483,20 +6484,20 @@ async function Yi(e, t) {
|
|
|
6483
6484
|
})).data)
|
|
6484
6485
|
};
|
|
6485
6486
|
}
|
|
6486
|
-
function
|
|
6487
|
+
function na(e) {
|
|
6487
6488
|
return [...e].reverse().flatMap((e) => e.items.flatMap((e) => {
|
|
6488
6489
|
if (e.type !== "userMessage") return [];
|
|
6489
|
-
let t =
|
|
6490
|
+
let t = ra(e.content.flatMap((e) => e.type === "text" ? [e.text] : []).join(""));
|
|
6490
6491
|
return t && t !== "(no user instructions)" ? [t] : [];
|
|
6491
6492
|
}));
|
|
6492
6493
|
}
|
|
6493
|
-
function
|
|
6494
|
-
let t = e.replace(
|
|
6495
|
-
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();
|
|
6496
6497
|
}
|
|
6497
6498
|
//#endregion
|
|
6498
6499
|
//#region src/node/codex-surface-text-generation-controller.ts
|
|
6499
|
-
var
|
|
6500
|
+
var ia = 12e4, aa = class {
|
|
6500
6501
|
client;
|
|
6501
6502
|
defaultCwd;
|
|
6502
6503
|
host;
|
|
@@ -6507,7 +6508,7 @@ var Qi = 12e4, $i = class {
|
|
|
6507
6508
|
}
|
|
6508
6509
|
handleNotification(e) {
|
|
6509
6510
|
e.method === "thread/started" && e.params.thread.ephemeral && this.hiddenThreadIds.add(e.params.thread.id);
|
|
6510
|
-
let t =
|
|
6511
|
+
let t = la(e);
|
|
6511
6512
|
if (!t || !this.hiddenThreadIds.has(t)) return !1;
|
|
6512
6513
|
let n = this.pendingByThread.get(t);
|
|
6513
6514
|
return n && this.consumeNotification(n, e), (e.method === "thread/closed" || e.method === "thread/deleted") && this.hiddenThreadIds.delete(t), !0;
|
|
@@ -6515,10 +6516,10 @@ var Qi = 12e4, $i = class {
|
|
|
6515
6516
|
async generate(e, t = {}) {
|
|
6516
6517
|
let n = e.trim();
|
|
6517
6518
|
if (!n) throw Error("Generation prompt cannot be empty");
|
|
6518
|
-
if (t.signal?.aborted) throw
|
|
6519
|
+
if (t.signal?.aborted) throw ua();
|
|
6519
6520
|
await this.host.ensureConnected();
|
|
6520
|
-
let r = this.host.getSnapshot(), i = q(r.models, r.selectedModelId), a = t.model ?
|
|
6521
|
-
|
|
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);
|
|
6522
6523
|
let l = await this.client.request("thread/start", {
|
|
6523
6524
|
approvalPolicy: "never",
|
|
6524
6525
|
approvalsReviewer: "user",
|
|
@@ -6534,15 +6535,15 @@ var Qi = 12e4, $i = class {
|
|
|
6534
6535
|
serviceName: "codex_app_sdk",
|
|
6535
6536
|
threadSource: "sdk_ephemeral_generation"
|
|
6536
6537
|
}), u = l.thread.id;
|
|
6537
|
-
if (!l.thread.ephemeral) throw await
|
|
6538
|
-
if (this.hiddenThreadIds.add(u), t.signal?.aborted) throw await
|
|
6539
|
-
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();
|
|
6540
6541
|
this.pendingByThread.set(u, d);
|
|
6541
|
-
let f = null, p = !1, m = () => d.reject(
|
|
6542
|
+
let f = null, p = !1, m = () => d.reject(ua());
|
|
6542
6543
|
t.signal?.addEventListener("abort", m);
|
|
6543
6544
|
let h = setTimeout(() => {
|
|
6544
6545
|
d.reject(/* @__PURE__ */ Error("Codex ephemeral generation timed out"));
|
|
6545
|
-
}, t.timeoutMs ??
|
|
6546
|
+
}, t.timeoutMs ?? ia);
|
|
6546
6547
|
try {
|
|
6547
6548
|
let e = await this.client.request("turn/start", {
|
|
6548
6549
|
threadId: u,
|
|
@@ -6558,18 +6559,18 @@ var Qi = 12e4, $i = class {
|
|
|
6558
6559
|
serviceTier: c,
|
|
6559
6560
|
...t.outputSchema === void 0 ? {} : { outputSchema: t.outputSchema }
|
|
6560
6561
|
});
|
|
6561
|
-
f = e.turn.id, d.turnId = f,
|
|
6562
|
+
f = e.turn.id, d.turnId = f, ca(d, e.turn);
|
|
6562
6563
|
let r = await d.promise;
|
|
6563
6564
|
return p = !0, r;
|
|
6564
6565
|
} finally {
|
|
6565
6566
|
if (clearTimeout(h), t.signal?.removeEventListener("abort", m), this.pendingByThread.delete(u), !p && f) {
|
|
6566
6567
|
let e = f;
|
|
6567
|
-
await
|
|
6568
|
+
await oa(() => this.client.request("turn/interrupt", {
|
|
6568
6569
|
threadId: u,
|
|
6569
6570
|
turnId: e
|
|
6570
6571
|
}));
|
|
6571
6572
|
}
|
|
6572
|
-
await
|
|
6573
|
+
await oa(() => this.client.request("thread/unsubscribe", { threadId: u })), this.hiddenThreadIds.delete(u);
|
|
6573
6574
|
}
|
|
6574
6575
|
}
|
|
6575
6576
|
close(e = /* @__PURE__ */ Error("Codex surface closed")) {
|
|
@@ -6592,16 +6593,16 @@ var Qi = 12e4, $i = class {
|
|
|
6592
6593
|
}
|
|
6593
6594
|
if (t.method === "turn/completed") {
|
|
6594
6595
|
if (e.turnId && t.params.turn.id !== e.turnId) return;
|
|
6595
|
-
|
|
6596
|
+
ca(e, t.params.turn);
|
|
6596
6597
|
}
|
|
6597
6598
|
}
|
|
6598
6599
|
};
|
|
6599
|
-
async function
|
|
6600
|
+
async function oa(e) {
|
|
6600
6601
|
try {
|
|
6601
6602
|
await e();
|
|
6602
6603
|
} catch {}
|
|
6603
6604
|
}
|
|
6604
|
-
function
|
|
6605
|
+
function sa() {
|
|
6605
6606
|
let e, t, n = {
|
|
6606
6607
|
promise: new Promise((n, r) => {
|
|
6607
6608
|
e = n, t = r;
|
|
@@ -6617,7 +6618,7 @@ function ta() {
|
|
|
6617
6618
|
};
|
|
6618
6619
|
return n.promise.catch(() => void 0), n;
|
|
6619
6620
|
}
|
|
6620
|
-
function
|
|
6621
|
+
function ca(e, t) {
|
|
6621
6622
|
for (let n of t.items) {
|
|
6622
6623
|
if (n.type !== "agentMessage") continue;
|
|
6623
6624
|
let t = n.text.trim();
|
|
@@ -6639,17 +6640,17 @@ function na(e, t) {
|
|
|
6639
6640
|
}
|
|
6640
6641
|
e.resolve({ text: n });
|
|
6641
6642
|
}
|
|
6642
|
-
function
|
|
6643
|
+
function la(e) {
|
|
6643
6644
|
if (e.method === "thread/started") return e.params.thread.id;
|
|
6644
6645
|
let t = e.params;
|
|
6645
6646
|
return typeof t.threadId == "string" ? t.threadId : null;
|
|
6646
6647
|
}
|
|
6647
|
-
function
|
|
6648
|
+
function ua() {
|
|
6648
6649
|
return /* @__PURE__ */ Error("Codex ephemeral generation was aborted");
|
|
6649
6650
|
}
|
|
6650
6651
|
//#endregion
|
|
6651
6652
|
//#region src/node/codex-surface.ts
|
|
6652
|
-
var
|
|
6653
|
+
var da = class {
|
|
6653
6654
|
options;
|
|
6654
6655
|
client;
|
|
6655
6656
|
listeners = /* @__PURE__ */ new Set();
|
|
@@ -6682,17 +6683,17 @@ var aa = class {
|
|
|
6682
6683
|
eventSequence = 0;
|
|
6683
6684
|
pendingMarkdownImageHydrations = /* @__PURE__ */ new Set();
|
|
6684
6685
|
closed = !1;
|
|
6685
|
-
state =
|
|
6686
|
+
state = _t(bt());
|
|
6686
6687
|
constructor(e = {}) {
|
|
6687
|
-
this.options = e, this.extensions = new
|
|
6688
|
-
let n =
|
|
6689
|
-
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, {
|
|
6690
6691
|
bootstrapSurfaceData: (e) => this.connection.bootstrapSurfaceData(e),
|
|
6691
6692
|
clearAuthenticatedSurfaceData: () => this.connection.clearAuthenticatedSurfaceData(),
|
|
6692
6693
|
getSnapshot: () => this.getSnapshot(),
|
|
6693
6694
|
patchAuthentication: (e, t) => this.connection.patchAuthentication(e, t),
|
|
6694
|
-
reportError: (e) => this.patch({ error:
|
|
6695
|
-
}), this.items = new
|
|
6695
|
+
reportError: (e) => this.patch({ error: O(e) })
|
|
6696
|
+
}), this.items = new br({
|
|
6696
6697
|
assistantMessageForTurn: (e, t) => this.assistantMessageForTurn(e, t),
|
|
6697
6698
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
6698
6699
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
@@ -6706,7 +6707,7 @@ var aa = class {
|
|
|
6706
6707
|
sendNextQueuedPrompt: (e) => {
|
|
6707
6708
|
this.messagesController.sendNextQueuedPrompt(e);
|
|
6708
6709
|
}
|
|
6709
|
-
}), this.approvals = new
|
|
6710
|
+
}), this.approvals = new mi(this.client, {
|
|
6710
6711
|
activeConversationId: () => this.state.activeConversationId,
|
|
6711
6712
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6712
6713
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6716,7 +6717,7 @@ var aa = class {
|
|
|
6716
6717
|
patch: (e) => this.patch(e),
|
|
6717
6718
|
patchConversationStatus: (e, t) => this.patchConversationStatus(e, t),
|
|
6718
6719
|
patchRuntime: (e, t) => this.patchRuntime(e, t)
|
|
6719
|
-
}), this.clientRequests = new
|
|
6720
|
+
}), this.clientRequests = new Cr({
|
|
6720
6721
|
activeConversationId: () => this.state.activeConversationId,
|
|
6721
6722
|
answerAsyncQuestion: (e, t, n) => this.messagesController.answerAsyncQuestion(e, t, n),
|
|
6722
6723
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6726,13 +6727,13 @@ var aa = class {
|
|
|
6726
6727
|
messageContainingTool: (e, t, n) => this.messageContainingTool(e, t, n),
|
|
6727
6728
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6728
6729
|
requireRuntime: (e) => this.requireRuntime(e)
|
|
6729
|
-
}), this.runtimeState = new
|
|
6730
|
+
}), this.runtimeState = new Ii(this.approvals, this.clientRequests, {
|
|
6730
6731
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
6731
6732
|
getState: () => this.state,
|
|
6732
6733
|
notifyConversationListeners: (e) => this.notifyConversationListeners(e),
|
|
6733
6734
|
patch: (e, t) => this.patch(e, t),
|
|
6734
6735
|
schedulePluginRefresh: () => this.catalog.schedulePluginRefresh()
|
|
6735
|
-
}), this.conversationSettings = new
|
|
6736
|
+
}), this.conversationSettings = new Oi(this.client, {
|
|
6736
6737
|
approvalMode: e.approvalMode,
|
|
6737
6738
|
approvalPreset: e.approvalPreset,
|
|
6738
6739
|
permissionMode: e.permissionMode
|
|
@@ -6750,7 +6751,7 @@ var aa = class {
|
|
|
6750
6751
|
patch: (e) => this.patch(e),
|
|
6751
6752
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6752
6753
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e)
|
|
6753
|
-
}), this.turnActions = new
|
|
6754
|
+
}), this.turnActions = new Ai(this.client, {
|
|
6754
6755
|
createConversation: async () => {
|
|
6755
6756
|
await this.createConversation();
|
|
6756
6757
|
},
|
|
@@ -6767,7 +6768,7 @@ var aa = class {
|
|
|
6767
6768
|
patchConversationTurnCount: (e, t, n) => this.patchConversationTurnCount(e, t, n),
|
|
6768
6769
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6769
6770
|
sendMessageToThread: (e, t, n) => this.messagesController.sendToThread(e, t, n)
|
|
6770
|
-
}), this.messagesController = new
|
|
6771
|
+
}), this.messagesController = new Mi(this.client, {
|
|
6771
6772
|
clearGoalForThread: (e) => this.conversationSettings.clearGoalForThread(e),
|
|
6772
6773
|
compactForThread: (e) => this.turnActions.compactForThread(e),
|
|
6773
6774
|
createConversation: async () => {
|
|
@@ -6790,7 +6791,7 @@ var aa = class {
|
|
|
6790
6791
|
startReviewForThread: (e, t) => this.turnActions.startReviewForThread(e, t),
|
|
6791
6792
|
updateSettings: (e) => this.conversationSettings.update(e),
|
|
6792
6793
|
updateSettingsForThread: (e, t) => this.conversationSettings.updateForThread(e, t)
|
|
6793
|
-
}), this.catalog = new
|
|
6794
|
+
}), this.catalog = new oi(this.client, e.cwd, {
|
|
6794
6795
|
authenticationBlocksBootstrap: () => this.authentication.blocksBootstrap(),
|
|
6795
6796
|
emitConversationSkills: (e, t) => this.emitConversationSkills(e, t),
|
|
6796
6797
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
@@ -6801,7 +6802,7 @@ var aa = class {
|
|
|
6801
6802
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6802
6803
|
preferredApprovalPreset: () => this.conversationSettings.preferredApprovalPreset(),
|
|
6803
6804
|
runtimes: () => this.runtimeState.values()
|
|
6804
|
-
}), this.conversations = new
|
|
6805
|
+
}), this.conversations = new Ei(this.client, e.conversationLimit, {
|
|
6805
6806
|
emitHistoryPrepended: (e, t, n) => this.emitHistoryPrepended(e, t, n),
|
|
6806
6807
|
emitSummaryUpserted: (e, t, n) => this.emitSummaryUpserted(e, t, n),
|
|
6807
6808
|
ensureConnected: () => this.ensureConnected(),
|
|
@@ -6813,7 +6814,7 @@ var aa = class {
|
|
|
6813
6814
|
requireRuntime: (e) => this.requireRuntime(e),
|
|
6814
6815
|
runtime: (e) => this.runtimeState.get(e),
|
|
6815
6816
|
schedulePluginRefresh: (e) => this.catalog.schedulePluginRefresh(e)
|
|
6816
|
-
}), this.lifecycle = new
|
|
6817
|
+
}), this.lifecycle = new Pi(this.client, e, this.catalog, this.extensions, this.conversationSettings, this.conversations, {
|
|
6817
6818
|
activateRuntime: (e) => this.activateRuntime(e),
|
|
6818
6819
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6819
6820
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6835,7 +6836,7 @@ var aa = class {
|
|
|
6835
6836
|
runtime: (e) => this.runtimeState.get(e),
|
|
6836
6837
|
runtimeProjection: (e) => this.runtimeProjection(e),
|
|
6837
6838
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e)
|
|
6838
|
-
}), this.forks = new
|
|
6839
|
+
}), this.forks = new Ui(this.client, e.loadingStrategy, this.catalog, this.extensions, {
|
|
6839
6840
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6840
6841
|
emitConversationActivity: (e) => this.emitConversationActivity(e, "action"),
|
|
6841
6842
|
emitConversationPermissions: (e) => this.emitConversationPermissions(e, "action"),
|
|
@@ -6849,7 +6850,7 @@ var aa = class {
|
|
|
6849
6850
|
rememberHostOptions: (e, t) => this.lifecycle.rememberHostOptions(e, t),
|
|
6850
6851
|
requireRuntime: (e) => this.requireRuntime(e),
|
|
6851
6852
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e)
|
|
6852
|
-
}), 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, {
|
|
6853
6854
|
clearConversationHandles: () => this.conversationHandles.clear(),
|
|
6854
6855
|
clearPendingForThread: (e, t, n) => this.clearPendingForThread(e, t, n),
|
|
6855
6856
|
closed: () => this.closed,
|
|
@@ -6861,7 +6862,7 @@ var aa = class {
|
|
|
6861
6862
|
getSnapshot: () => this.getSnapshot(),
|
|
6862
6863
|
getState: () => this.state,
|
|
6863
6864
|
patch: (e) => this.patch(e)
|
|
6864
|
-
}), this.notifications = new
|
|
6865
|
+
}), this.notifications = new Fi(this.authentication, this.approvals, this.catalog, this.clientRequests, this.conversations, this.items, {
|
|
6865
6866
|
clearPendingForThread: (e, t, n) => this.clearPendingForThread(e, t, n),
|
|
6866
6867
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6867
6868
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6885,7 +6886,7 @@ var aa = class {
|
|
|
6885
6886
|
},
|
|
6886
6887
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e),
|
|
6887
6888
|
unknownNotification: (e) => this.handleUnknownNotification(e)
|
|
6888
|
-
}), this.textGeneration = new
|
|
6889
|
+
}), this.textGeneration = new aa(this.client, e.cwd, {
|
|
6889
6890
|
ensureConnected: () => this.ensureConnected(),
|
|
6890
6891
|
getSnapshot: () => this.getSnapshot()
|
|
6891
6892
|
}), this.unsubscribeNotification = this.client.onNotification((e) => {
|
|
@@ -6981,7 +6982,7 @@ var aa = class {
|
|
|
6981
6982
|
return this.lifecycle.create(e, t);
|
|
6982
6983
|
}
|
|
6983
6984
|
async forkConversation(e, t = {}, n = {}) {
|
|
6984
|
-
let r =
|
|
6985
|
+
let r = D(e);
|
|
6985
6986
|
await this.ensureThreadReady(r);
|
|
6986
6987
|
let i = this.lifecycle.hostOptions(r) ?? {}, a = await this.forks.fork(r, t, {
|
|
6987
6988
|
...i,
|
|
@@ -6990,7 +6991,7 @@ var aa = class {
|
|
|
6990
6991
|
return this.conversationForkResult(a);
|
|
6991
6992
|
}
|
|
6992
6993
|
async forkConversationAtTurn(e, t, n = {}, r = {}) {
|
|
6993
|
-
let i =
|
|
6994
|
+
let i = D(e);
|
|
6994
6995
|
await this.ensureThreadReady(i);
|
|
6995
6996
|
let a = this.lifecycle.hostOptions(i) ?? {}, o = await this.forks.forkTurn(i, t, n, {
|
|
6996
6997
|
...a,
|
|
@@ -7002,7 +7003,7 @@ var aa = class {
|
|
|
7002
7003
|
return this.lifecycle.select(e);
|
|
7003
7004
|
}
|
|
7004
7005
|
forgetConversation(e) {
|
|
7005
|
-
let t =
|
|
7006
|
+
let t = D(e), n = this.state.activeConversationId === t;
|
|
7006
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({
|
|
7007
7008
|
activeConversationId: null,
|
|
7008
7009
|
activeTurnId: null,
|
|
@@ -7030,10 +7031,10 @@ var aa = class {
|
|
|
7030
7031
|
return this.lifecycle.readHistory(e);
|
|
7031
7032
|
}
|
|
7032
7033
|
async readConversationPromptHistory(e = this.state.activeConversationId ?? "") {
|
|
7033
|
-
return await this.ensureConnected(),
|
|
7034
|
+
return await this.ensureConnected(), ta(this.client, e);
|
|
7034
7035
|
}
|
|
7035
7036
|
async loadOlderConversationHistory(e = this.state.activeConversationId ?? "") {
|
|
7036
|
-
return this.conversations.loadOlderHistory(
|
|
7037
|
+
return this.conversations.loadOlderHistory(D(e));
|
|
7037
7038
|
}
|
|
7038
7039
|
async renameConversation(e) {
|
|
7039
7040
|
let t = this.state.activeConversationId;
|
|
@@ -7097,9 +7098,9 @@ var aa = class {
|
|
|
7097
7098
|
return await this.approvals.resolve(void 0, e, t, n), this.getSnapshot();
|
|
7098
7099
|
}
|
|
7099
7100
|
conversation(e) {
|
|
7100
|
-
let t =
|
|
7101
|
+
let t = D(e), n = this.conversationHandles.get(t);
|
|
7101
7102
|
if (n) return n;
|
|
7102
|
-
let r =
|
|
7103
|
+
let r = At(t, {
|
|
7103
7104
|
clearGoal: () => this.conversationSettings.clearGoalForThread(t),
|
|
7104
7105
|
compact: () => this.turnActions.compactForThread(t),
|
|
7105
7106
|
continueInterruptedTurn: () => this.messagesController.continueInterruptedTurnForThread(t),
|
|
@@ -7152,7 +7153,7 @@ var aa = class {
|
|
|
7152
7153
|
await this.client.request("thread/realtime/stop", { threadId: e });
|
|
7153
7154
|
}
|
|
7154
7155
|
startRealtimeForThread(e, t) {
|
|
7155
|
-
return
|
|
7156
|
+
return ht({
|
|
7156
7157
|
client: this.client,
|
|
7157
7158
|
ensureThreadReady: async () => {
|
|
7158
7159
|
await this.ensureThreadReady(e);
|
|
@@ -7386,7 +7387,7 @@ var aa = class {
|
|
|
7386
7387
|
...this.state,
|
|
7387
7388
|
...e
|
|
7388
7389
|
};
|
|
7389
|
-
let i =
|
|
7390
|
+
let i = te(n, this.state);
|
|
7390
7391
|
if (i.length > 0 && (this.stateVersion += 1, this.patchListeners.size > 0)) {
|
|
7391
7392
|
let e = structuredClone({
|
|
7392
7393
|
version: this.stateVersion,
|
|
@@ -7405,19 +7406,19 @@ var aa = class {
|
|
|
7405
7406
|
for (let e of this.conversationListeners.keys()) this.notifyConversationListeners(e);
|
|
7406
7407
|
}
|
|
7407
7408
|
};
|
|
7408
|
-
function
|
|
7409
|
-
return new
|
|
7409
|
+
function fa(e = {}) {
|
|
7410
|
+
return new da(e);
|
|
7410
7411
|
}
|
|
7411
7412
|
//#endregion
|
|
7412
7413
|
//#region src/node/codex-app-backend-cache.ts
|
|
7413
|
-
var
|
|
7414
|
+
var pa = {
|
|
7414
7415
|
set(e, t) {
|
|
7415
7416
|
return setTimeout(e, t);
|
|
7416
7417
|
},
|
|
7417
7418
|
clear(e) {
|
|
7418
7419
|
clearTimeout(e);
|
|
7419
7420
|
}
|
|
7420
|
-
},
|
|
7421
|
+
}, ma = class {
|
|
7421
7422
|
options;
|
|
7422
7423
|
records = /* @__PURE__ */ new Map();
|
|
7423
7424
|
now;
|
|
@@ -7430,7 +7431,7 @@ var sa = {
|
|
|
7430
7431
|
constructor(e) {
|
|
7431
7432
|
if (this.options = e, !Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error("Codex backend cache ttlMs must be greater than zero");
|
|
7432
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");
|
|
7433
|
-
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;
|
|
7434
7435
|
}
|
|
7435
7436
|
get size() {
|
|
7436
7437
|
return this.records.size;
|
|
@@ -7528,7 +7529,7 @@ var sa = {
|
|
|
7528
7529
|
assertOpen() {
|
|
7529
7530
|
if (this.closed) throw Error("Codex backend cache is closed");
|
|
7530
7531
|
}
|
|
7531
|
-
},
|
|
7532
|
+
}, ha = class {
|
|
7532
7533
|
surface;
|
|
7533
7534
|
moduleServices = /* @__PURE__ */ new Map();
|
|
7534
7535
|
ttlCaches = /* @__PURE__ */ new Set();
|
|
@@ -7544,7 +7545,7 @@ var sa = {
|
|
|
7544
7545
|
if (n.has(e)) throw Error(`Duplicate Codex backend module '${e}'`);
|
|
7545
7546
|
n.add(e);
|
|
7546
7547
|
}
|
|
7547
|
-
this.surface = e.surface ?? new
|
|
7548
|
+
this.surface = e.surface ?? new da(e.surfaceOptions);
|
|
7548
7549
|
for (let { id: e, module: n } of t) this.moduleServices.set(e, n.create({
|
|
7549
7550
|
surface: this.surface,
|
|
7550
7551
|
closeBackend: () => this.close(),
|
|
@@ -7558,7 +7559,7 @@ var sa = {
|
|
|
7558
7559
|
}
|
|
7559
7560
|
createTtlCache(e) {
|
|
7560
7561
|
if (this.closePromise) throw Error("Cannot create a cache after the Codex backend is closed");
|
|
7561
|
-
let t = new
|
|
7562
|
+
let t = new ma(e);
|
|
7562
7563
|
return this.ttlCaches.add(t), t;
|
|
7563
7564
|
}
|
|
7564
7565
|
close() {
|
|
@@ -7568,16 +7569,16 @@ var sa = {
|
|
|
7568
7569
|
await Promise.all([...this.ttlCaches].map((e) => e.close())), await this.surface.close();
|
|
7569
7570
|
}
|
|
7570
7571
|
};
|
|
7571
|
-
function
|
|
7572
|
-
return new
|
|
7572
|
+
function ga(e = {}) {
|
|
7573
|
+
return new ha(e);
|
|
7573
7574
|
}
|
|
7574
7575
|
//#endregion
|
|
7575
7576
|
//#region src/node/apple-speech-transcription.ts
|
|
7576
|
-
async function
|
|
7577
|
-
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");
|
|
7578
7579
|
try {
|
|
7579
|
-
let a = await
|
|
7580
|
-
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() };
|
|
7581
7582
|
} catch (e) {
|
|
7582
7583
|
return {
|
|
7583
7584
|
text: "",
|
|
@@ -7590,10 +7591,10 @@ async function da(e, t = {}, n = {}) {
|
|
|
7590
7591
|
});
|
|
7591
7592
|
}
|
|
7592
7593
|
}
|
|
7593
|
-
function
|
|
7594
|
-
return
|
|
7594
|
+
function va(e, t = {}) {
|
|
7595
|
+
return h.join(e ?? xa(t), "apple-speechanalyzer-cli");
|
|
7595
7596
|
}
|
|
7596
|
-
function
|
|
7597
|
+
function ya(e, t, n) {
|
|
7597
7598
|
let r = [
|
|
7598
7599
|
"--input-audio-path",
|
|
7599
7600
|
e,
|
|
@@ -7602,7 +7603,7 @@ function pa(e, t, n) {
|
|
|
7602
7603
|
], i = n.locale?.trim();
|
|
7603
7604
|
return i && r.push("--locale", i), n.live && r.push("--live"), r;
|
|
7604
7605
|
}
|
|
7605
|
-
function
|
|
7606
|
+
function ba(e, t, n) {
|
|
7606
7607
|
return new Promise((r, i) => {
|
|
7607
7608
|
let a = e(t, n), o = "";
|
|
7608
7609
|
a.stderr?.on("data", (e) => {
|
|
@@ -7618,42 +7619,150 @@ function ma(e, t, n) {
|
|
|
7618
7619
|
});
|
|
7619
7620
|
});
|
|
7620
7621
|
}
|
|
7621
|
-
function
|
|
7622
|
+
function xa(e) {
|
|
7622
7623
|
let t = (e.env ?? process.env).CODEX_APP_SDK_ASSETS_PATH?.trim();
|
|
7623
7624
|
if (t) return t;
|
|
7624
7625
|
let n = process.resourcesPath, r = e.resourcesPath === void 0 ? n : e.resourcesPath ?? void 0, i = e.existsSync ?? c;
|
|
7625
7626
|
if (r && !r.endsWith(".vite/build")) {
|
|
7626
7627
|
let e = [
|
|
7627
7628
|
r,
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
|
|
7632
|
-
|
|
7633
|
-
].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")));
|
|
7634
7635
|
if (e) return e;
|
|
7635
7636
|
}
|
|
7636
7637
|
let a = import.meta.resolve, o = e.packageResolve === void 0 ? a : e.packageResolve ?? void 0;
|
|
7637
7638
|
if (o) try {
|
|
7638
|
-
let e =
|
|
7639
|
-
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;
|
|
7640
7641
|
} catch {}
|
|
7641
7642
|
let s = (e.cwd ?? process.cwd)(), l = [
|
|
7642
|
-
|
|
7643
|
-
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
|
|
7647
|
-
].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")));
|
|
7648
7649
|
if (l) return l;
|
|
7649
|
-
let u = import.meta.url, d = e.moduleUrl === void 0 ? u : e.moduleUrl ?? void 0, f = d ?
|
|
7650
|
-
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];
|
|
7651
7652
|
}
|
|
7652
|
-
async function
|
|
7653
|
-
let r =
|
|
7653
|
+
async function Sa(e, t, n) {
|
|
7654
|
+
let r = h.join(t, "apple-speechanalyzer-cli");
|
|
7654
7655
|
return await n.copyFile(e, r), await n.chmod(r, 448), r;
|
|
7655
7656
|
}
|
|
7656
7657
|
//#endregion
|
|
7657
|
-
|
|
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 };
|
|
7658
7767
|
|
|
7659
7768
|
//# sourceMappingURL=index.js.map
|