@codex-app-sdk/backend 0.21.1 → 0.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{codex-CmHW3ikB.js → codex-qk7I-QSQ.js} +21 -6
- package/dist/chunks/codex-qk7I-QSQ.js.map +1 -0
- package/dist/codex/client.d.ts.map +1 -1
- package/dist/index.js +970 -894
- package/dist/index.js.map +1 -1
- package/dist/node/codex-surface-catalog-controller.d.ts +5 -0
- package/dist/node/codex-surface-catalog-controller.d.ts.map +1 -1
- package/dist/node/codex-surface-connection-controller.d.ts.map +1 -1
- package/dist/node/codex-surface-contracts.d.ts +1 -4
- package/dist/node/codex-surface-contracts.d.ts.map +1 -1
- package/dist/node/codex-surface-lifecycle-controller.d.ts.map +1 -1
- package/dist/node/codex-surface-messages-controller.d.ts +2 -0
- package/dist/node/codex-surface-messages-controller.d.ts.map +1 -1
- package/dist/node/codex-surface-notifications-controller.d.ts.map +1 -1
- package/dist/node/codex-surface.d.ts.map +1 -1
- package/dist/protocol.js +1 -1
- package/package.json +2 -2
- package/dist/chunks/codex-CmHW3ikB.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { i as e, n as t, r as n, s as r } from "./chunks/codex-
|
|
1
|
+
import { i as e, n as t, r as n, s as r } from "./chunks/codex-qk7I-QSQ.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
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
|
|
7
|
-
import { createHash as
|
|
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 { createHash as ee, randomBytes as te } from "node:crypto";
|
|
8
8
|
import { createConnection as ne } from "node:net";
|
|
9
9
|
import { chmod as re, copyFile as ie, mkdtemp as ae, open as oe, rm as se, stat as ce } from "node:fs/promises";
|
|
10
10
|
import { normalizePromptContent as le, promptContentDispatchText as ue, promptContentText as de } from "@codex-app-sdk/core/surface";
|
|
@@ -1075,7 +1075,7 @@ function nn(e = []) {
|
|
|
1075
1075
|
path: e.kind === "plugin" ? `plugin://${e.id}` : e.id
|
|
1076
1076
|
}] : []);
|
|
1077
1077
|
}
|
|
1078
|
-
function
|
|
1078
|
+
function rn(e, t) {
|
|
1079
1079
|
return e.map((e) => {
|
|
1080
1080
|
let n = t.find((t) => t.enabled && t.name === e.name && t.path === e.path);
|
|
1081
1081
|
if (!n) throw Error(`Skill '${e.name}' is not an enabled skill in the Codex catalog`);
|
|
@@ -1085,58 +1085,58 @@ function O(e, t) {
|
|
|
1085
1085
|
};
|
|
1086
1086
|
});
|
|
1087
1087
|
}
|
|
1088
|
-
function
|
|
1088
|
+
function an(...e) {
|
|
1089
1089
|
let t = /* @__PURE__ */ new Set();
|
|
1090
1090
|
return e.flatMap((e) => e.filter((e) => {
|
|
1091
1091
|
let n = `${e.name}\u0000${e.path}`;
|
|
1092
1092
|
return t.has(n) ? !1 : (t.add(n), !0);
|
|
1093
1093
|
}));
|
|
1094
1094
|
}
|
|
1095
|
-
function
|
|
1095
|
+
function on(e, t, n, r) {
|
|
1096
1096
|
let i = e.filter((e) => e.metadata?.turnId === t).flatMap((e) => e.parts).filter((e) => e.type === "tool" && e.kind === "mcp" && e.status === "running");
|
|
1097
1097
|
return i.find((e) => {
|
|
1098
|
-
let t =
|
|
1098
|
+
let t = ln(e.metadata?.server), i = ln(e.metadata?.tool);
|
|
1099
1099
|
return t === n && i === r || e.title.endsWith(`.${r}`);
|
|
1100
1100
|
}) ?? (i.length === 1 ? i[0] ?? null : null);
|
|
1101
1101
|
}
|
|
1102
|
-
function
|
|
1102
|
+
function sn(e) {
|
|
1103
1103
|
if (Array.isArray(e.tool_params_display)) {
|
|
1104
|
-
let t = e.tool_params_display.map((e) => !
|
|
1104
|
+
let t = e.tool_params_display.map((e) => !un(e) || typeof e.name != "string" ? "" : `${ln(e.display_name) ?? e.name}: ${typeof e.value == "string" ? e.value : JSON.stringify(e.value)}`).filter(Boolean);
|
|
1105
1105
|
if (t.length > 0) return t.join("\n");
|
|
1106
1106
|
}
|
|
1107
1107
|
return e.tool_params === void 0 ? "" : JSON.stringify(e.tool_params, null, 2);
|
|
1108
1108
|
}
|
|
1109
|
-
function
|
|
1109
|
+
function cn(e, t) {
|
|
1110
1110
|
return e === t || Array.isArray(e) && e.includes(t);
|
|
1111
1111
|
}
|
|
1112
|
-
function
|
|
1112
|
+
function ln(e) {
|
|
1113
1113
|
return typeof e == "string" && e.trim() ? e.trim() : null;
|
|
1114
1114
|
}
|
|
1115
|
-
function
|
|
1115
|
+
function O(e) {
|
|
1116
1116
|
let t = e.trim();
|
|
1117
1117
|
if (!t) throw Error("Conversation id cannot be empty");
|
|
1118
1118
|
return t;
|
|
1119
1119
|
}
|
|
1120
|
-
function
|
|
1120
|
+
function un(e) {
|
|
1121
1121
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
1122
1122
|
}
|
|
1123
|
-
function
|
|
1123
|
+
function k(e) {
|
|
1124
1124
|
return e instanceof Error ? e.message : String(e);
|
|
1125
1125
|
}
|
|
1126
1126
|
//#endregion
|
|
1127
1127
|
//#region src/node/codex-surface-message-state.ts
|
|
1128
|
-
function
|
|
1128
|
+
function dn(e) {
|
|
1129
1129
|
for (let t = e.length - 1; t >= 0; --t) {
|
|
1130
1130
|
let n = e[t];
|
|
1131
1131
|
if (n?.status === "inProgress") return n.id;
|
|
1132
1132
|
}
|
|
1133
1133
|
return null;
|
|
1134
1134
|
}
|
|
1135
|
-
function
|
|
1136
|
-
let i = [...e], a =
|
|
1135
|
+
function A(e, t, n, r = {}) {
|
|
1136
|
+
let i = [...e], a = N(i, (e) => e.metadata?.turnId === n), o = a >= 0 ? i[a] : void 0;
|
|
1137
1137
|
if (o?.role === "assistant" && o.kind === void 0 && o.status === "streaming") return i;
|
|
1138
1138
|
if (r.forceSegment) {
|
|
1139
|
-
let e =
|
|
1139
|
+
let e = N(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), t = e >= 0 ? i[e] : void 0;
|
|
1140
1140
|
t?.parts.length === 0 ? i.splice(e, 1) : t && i.splice(e, 1, {
|
|
1141
1141
|
...t,
|
|
1142
1142
|
status: "complete"
|
|
@@ -1156,12 +1156,12 @@ function M(e, t, n, r = {}) {
|
|
|
1156
1156
|
}
|
|
1157
1157
|
}), i;
|
|
1158
1158
|
}
|
|
1159
|
-
function
|
|
1160
|
-
return e[
|
|
1159
|
+
function fn(e, t, n) {
|
|
1160
|
+
return e[N(e, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === t && e.parts.some((e) => e.type === "text" && e.itemId === n))];
|
|
1161
1161
|
}
|
|
1162
|
-
function
|
|
1162
|
+
function pn(e, t, n, r, i, a) {
|
|
1163
1163
|
if (!i) return [...e];
|
|
1164
|
-
let o =
|
|
1164
|
+
let o = fn(e, n, r), s = o ? [...e] : A(e, t, n), c = o ? s.indexOf(o) : N(s, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), l = c >= 0 ? s[c] : void 0;
|
|
1165
1165
|
if (!l) return s;
|
|
1166
1166
|
let u = [...l.parts], d = u.at(-1);
|
|
1167
1167
|
return d?.type === "text" && d.itemId === r ? u.splice(u.length - 1, 1, {
|
|
@@ -1177,9 +1177,9 @@ function dn(e, t, n, r, i, a) {
|
|
|
1177
1177
|
...l,
|
|
1178
1178
|
status: "streaming",
|
|
1179
1179
|
parts: u
|
|
1180
|
-
}),
|
|
1180
|
+
}), M(s, t);
|
|
1181
1181
|
}
|
|
1182
|
-
function
|
|
1182
|
+
function mn(e, t, n, r, i) {
|
|
1183
1183
|
let a = i.map((e, t) => {
|
|
1184
1184
|
let n = e.trim();
|
|
1185
1185
|
return n ? {
|
|
@@ -1195,16 +1195,16 @@ function fn(e, t, n, r, i) {
|
|
|
1195
1195
|
itemId: r,
|
|
1196
1196
|
summaryIndex: 0
|
|
1197
1197
|
});
|
|
1198
|
-
let o =
|
|
1198
|
+
let o = A(e, t, n), s = N(o, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), c = s >= 0 ? o[s] : void 0;
|
|
1199
1199
|
if (!c) return o;
|
|
1200
1200
|
let l = c.parts.findIndex((e) => e.type === "reasoning" && e.itemId === r), u = c.parts.filter((e) => e.type !== "reasoning" || e.itemId !== r);
|
|
1201
1201
|
return u.splice(l >= 0 ? l : u.length, 0, ...a), o.splice(s, 1, {
|
|
1202
1202
|
...c,
|
|
1203
1203
|
status: "streaming",
|
|
1204
1204
|
parts: u
|
|
1205
|
-
}),
|
|
1205
|
+
}), M(o, t);
|
|
1206
1206
|
}
|
|
1207
|
-
function
|
|
1207
|
+
function hn(e, t, n, r, i, a) {
|
|
1208
1208
|
let o = [...e];
|
|
1209
1209
|
for (let e = o.length - 1; e >= 0; --e) {
|
|
1210
1210
|
let s = o[e];
|
|
@@ -1220,9 +1220,9 @@ function pn(e, t, n, r, i, a) {
|
|
|
1220
1220
|
}), o.splice(e, 1, {
|
|
1221
1221
|
...s,
|
|
1222
1222
|
parts: l
|
|
1223
|
-
}),
|
|
1223
|
+
}), M(o, t);
|
|
1224
1224
|
}
|
|
1225
|
-
let s =
|
|
1225
|
+
let s = A(o, t, n), c = N(s, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), l = c >= 0 ? s[c] : void 0;
|
|
1226
1226
|
if (!l) return s;
|
|
1227
1227
|
let u = {
|
|
1228
1228
|
type: "text",
|
|
@@ -1233,10 +1233,10 @@ function pn(e, t, n, r, i, a) {
|
|
|
1233
1233
|
return s.splice(c, 1, {
|
|
1234
1234
|
...l,
|
|
1235
1235
|
parts: [...l.parts, u]
|
|
1236
|
-
}),
|
|
1236
|
+
}), M(s, t);
|
|
1237
1237
|
}
|
|
1238
|
-
function
|
|
1239
|
-
return
|
|
1238
|
+
function gn(e, t, n, r) {
|
|
1239
|
+
return M(e.map((e) => {
|
|
1240
1240
|
if (e.role !== "assistant" || e.metadata?.turnId !== n) return e;
|
|
1241
1241
|
let t = e.parts.filter((e) => e.type !== "text" || e.itemId !== r);
|
|
1242
1242
|
return t.length === e.parts.length ? e : {
|
|
@@ -1245,16 +1245,16 @@ function mn(e, t, n, r) {
|
|
|
1245
1245
|
};
|
|
1246
1246
|
}), t);
|
|
1247
1247
|
}
|
|
1248
|
-
function
|
|
1248
|
+
function _n(e) {
|
|
1249
1249
|
let t = /<proposed_plan>([\s\S]*?)<\/proposed_plan>/iu.exec(e), n = t?.[1]?.trim() ?? "";
|
|
1250
1250
|
return !t || !n ? null : {
|
|
1251
1251
|
markdown: n,
|
|
1252
1252
|
visibleText: `${e.slice(0, t.index)}${e.slice(t.index + t[0].length)}`.trim()
|
|
1253
1253
|
};
|
|
1254
1254
|
}
|
|
1255
|
-
function
|
|
1255
|
+
function j(e, t, n, r) {
|
|
1256
1256
|
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));
|
|
1257
|
-
a < 0 && (i =
|
|
1257
|
+
a < 0 && (i = A(i, t, n), a = N(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n));
|
|
1258
1258
|
let o = a >= 0 ? i[a] : void 0;
|
|
1259
1259
|
if (!o) return i;
|
|
1260
1260
|
let s = [...o.parts], c = s.findIndex((e) => e.type === "tool" && e.id === r.id);
|
|
@@ -1266,7 +1266,7 @@ function N(e, t, n, r) {
|
|
|
1266
1266
|
body: r.body ?? e.body,
|
|
1267
1267
|
input: r.input ?? e.input,
|
|
1268
1268
|
output: r.output ?? e.output,
|
|
1269
|
-
statusText: r.statusText ??
|
|
1269
|
+
statusText: r.statusText ?? wn(e.statusText, r.status),
|
|
1270
1270
|
metadata: {
|
|
1271
1271
|
...e.metadata ?? {},
|
|
1272
1272
|
...r.metadata ?? {}
|
|
@@ -1276,11 +1276,11 @@ function N(e, t, n, r) {
|
|
|
1276
1276
|
return i.splice(a, 1, {
|
|
1277
1277
|
...o,
|
|
1278
1278
|
parts: s
|
|
1279
|
-
}),
|
|
1279
|
+
}), M(i, t);
|
|
1280
1280
|
}
|
|
1281
|
-
function
|
|
1281
|
+
function vn(e, t, n, r, i = r.itemId) {
|
|
1282
1282
|
let a = [...e], o = a.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "media" && e.itemId === r.itemId));
|
|
1283
|
-
o < 0 && r.itemId && (o = a.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "tool" && e.id === i))), o < 0 && (a =
|
|
1283
|
+
o < 0 && r.itemId && (o = a.findIndex((e) => e.role === "assistant" && e.metadata?.turnId === n && e.parts.some((e) => e.type === "tool" && e.id === i))), o < 0 && (a = A(a, t, n), o = N(a, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n));
|
|
1284
1284
|
let s = o >= 0 ? a[o] : void 0;
|
|
1285
1285
|
if (!s) return a;
|
|
1286
1286
|
let c = [...s.parts], l = c.findIndex((e) => e.type === "media" && e.itemId === r.itemId);
|
|
@@ -1288,25 +1288,25 @@ function gn(e, t, n, r, i = r.itemId) {
|
|
|
1288
1288
|
...s,
|
|
1289
1289
|
status: "streaming",
|
|
1290
1290
|
parts: c
|
|
1291
|
-
}),
|
|
1291
|
+
}), M(a, t);
|
|
1292
1292
|
}
|
|
1293
|
-
function
|
|
1293
|
+
function yn(e, t, n, r) {
|
|
1294
1294
|
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));
|
|
1295
|
-
a < 0 && (i =
|
|
1295
|
+
a < 0 && (i = A(i, t, n), a = N(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n));
|
|
1296
1296
|
let o = a >= 0 ? i[a] : void 0;
|
|
1297
1297
|
if (!o) return i;
|
|
1298
1298
|
let s = [...o.parts], c = s.findIndex((e) => e.type === "question" && e.request.id === r.request.id);
|
|
1299
1299
|
return c >= 0 ? s.splice(c, 1, r) : s.push(r), i.splice(a, 1, {
|
|
1300
1300
|
...o,
|
|
1301
1301
|
parts: s
|
|
1302
|
-
}),
|
|
1302
|
+
}), M(i, t);
|
|
1303
1303
|
}
|
|
1304
|
-
function
|
|
1304
|
+
function bn(e, t) {
|
|
1305
1305
|
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;
|
|
1306
1306
|
}
|
|
1307
|
-
function
|
|
1307
|
+
function xn(e, t, n, r) {
|
|
1308
1308
|
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));
|
|
1309
|
-
if (a < 0) return r.fallbackToolPart ?
|
|
1309
|
+
if (a < 0) return r.fallbackToolPart ? xn(j(i, t, n, r.fallbackToolPart), t, n, {
|
|
1310
1310
|
...r,
|
|
1311
1311
|
fallbackToolPart: void 0
|
|
1312
1312
|
}) : i;
|
|
@@ -1332,12 +1332,12 @@ function yn(e, t, n, r) {
|
|
|
1332
1332
|
parts: s
|
|
1333
1333
|
}), i) : i;
|
|
1334
1334
|
}
|
|
1335
|
-
function
|
|
1335
|
+
function Sn(e, t, n, r = "streaming") {
|
|
1336
1336
|
if (e.some((e) => e.kind === "compaction" && e.metadata?.turnId === n)) return e.map((e) => r === "complete" && e.kind === "compaction" && e.metadata?.turnId === n ? {
|
|
1337
1337
|
...e,
|
|
1338
1338
|
status: r
|
|
1339
1339
|
} : e);
|
|
1340
|
-
let i = [...e], a =
|
|
1340
|
+
let i = [...e], a = N(i, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n), o = a >= 0 ? i[a] : void 0;
|
|
1341
1341
|
return o?.parts.length === 0 ? i.splice(a, 1) : o && i.splice(a, 1, {
|
|
1342
1342
|
...o,
|
|
1343
1343
|
status: "complete"
|
|
@@ -1353,16 +1353,16 @@ function bn(e, t, n, r = "streaming") {
|
|
|
1353
1353
|
conversationId: t,
|
|
1354
1354
|
turnId: n
|
|
1355
1355
|
}
|
|
1356
|
-
}),
|
|
1356
|
+
}), M(i, t);
|
|
1357
1357
|
}
|
|
1358
|
-
function
|
|
1358
|
+
function Cn(e, t, n) {
|
|
1359
1359
|
let r = n === "completed" ? "completed" : "failed";
|
|
1360
1360
|
return e.map((e) => {
|
|
1361
1361
|
if (e.metadata?.turnId !== t) return e;
|
|
1362
1362
|
let n = !1, i = e.parts.map((e) => e.type !== "tool" || e.status !== "running" ? e : (n = !0, {
|
|
1363
1363
|
...e,
|
|
1364
1364
|
status: r,
|
|
1365
|
-
statusText:
|
|
1365
|
+
statusText: wn(e.statusText, r)
|
|
1366
1366
|
}));
|
|
1367
1367
|
return n ? {
|
|
1368
1368
|
...e,
|
|
@@ -1370,11 +1370,11 @@ function xn(e, t, n) {
|
|
|
1370
1370
|
} : e;
|
|
1371
1371
|
});
|
|
1372
1372
|
}
|
|
1373
|
-
function
|
|
1373
|
+
function wn(e, t) {
|
|
1374
1374
|
if (t === "running" || !e) return e;
|
|
1375
1375
|
try {
|
|
1376
1376
|
let n = JSON.parse(e);
|
|
1377
|
-
return
|
|
1377
|
+
return un(n) ? JSON.stringify({
|
|
1378
1378
|
...n,
|
|
1379
1379
|
phase: t
|
|
1380
1380
|
}) : e;
|
|
@@ -1382,27 +1382,27 @@ function Sn(e, t) {
|
|
|
1382
1382
|
return e;
|
|
1383
1383
|
}
|
|
1384
1384
|
}
|
|
1385
|
-
function
|
|
1385
|
+
function M(e, t) {
|
|
1386
1386
|
let n = e.map((e, t) => ({
|
|
1387
1387
|
message: e,
|
|
1388
1388
|
index: t
|
|
1389
1389
|
})).filter(({ message: e }) => e.metadata?.conversationId === t).at(-1)?.index ?? -1;
|
|
1390
1390
|
return e.filter((e, r) => e.metadata?.conversationId !== t || r === n || e.role !== "assistant" || e.kind !== void 0 || e.parts.length > 0);
|
|
1391
1391
|
}
|
|
1392
|
-
function
|
|
1392
|
+
function N(e, t) {
|
|
1393
1393
|
for (let n = e.length - 1; n >= 0; --n) {
|
|
1394
1394
|
let r = e[n];
|
|
1395
1395
|
if (r !== void 0 && t(r)) return n;
|
|
1396
1396
|
}
|
|
1397
1397
|
return -1;
|
|
1398
1398
|
}
|
|
1399
|
-
function
|
|
1399
|
+
function Tn(e, t) {
|
|
1400
1400
|
return e.includes(t) ? [...e] : [...e, t];
|
|
1401
1401
|
}
|
|
1402
|
-
function
|
|
1402
|
+
function En(e, t) {
|
|
1403
1403
|
return [e?.trim() ?? "", ...t.map((e) => `${e.status === "completed" ? "- [x]" : "- [ ]"} ${e.step}`)].filter(Boolean).join("\n");
|
|
1404
1404
|
}
|
|
1405
|
-
function
|
|
1405
|
+
function Dn(e, t, n) {
|
|
1406
1406
|
return {
|
|
1407
1407
|
type: "tool",
|
|
1408
1408
|
id: `plan-progress-${e}`,
|
|
@@ -1425,19 +1425,19 @@ function Tn(e, t, n) {
|
|
|
1425
1425
|
}
|
|
1426
1426
|
//#endregion
|
|
1427
1427
|
//#region src/node/codex-conversation-history.ts
|
|
1428
|
-
var
|
|
1428
|
+
var On = 16 * 1024 * 1024, kn = /* @__PURE__ */ new Set([
|
|
1429
1429
|
"image/avif",
|
|
1430
1430
|
"image/gif",
|
|
1431
1431
|
"image/jpeg",
|
|
1432
1432
|
"image/png",
|
|
1433
1433
|
"image/webp"
|
|
1434
1434
|
]);
|
|
1435
|
-
function
|
|
1436
|
-
return (Array.isArray(e.turns) ? e.turns : []).flatMap((t) =>
|
|
1435
|
+
function An(e) {
|
|
1436
|
+
return (Array.isArray(e.turns) ? e.turns : []).flatMap((t) => P(e.id, t));
|
|
1437
1437
|
}
|
|
1438
|
-
function
|
|
1438
|
+
function jn(e, t) {
|
|
1439
1439
|
let n = /* @__PURE__ */ new Map();
|
|
1440
|
-
for (let t of e) for (let e of t.parts) e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path ||
|
|
1440
|
+
for (let t of e) for (let e of t.parts) e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path || Kn(e.attachment.url) && n.set(e.attachment.path, e.attachment.url);
|
|
1441
1441
|
return n.size === 0 ? [...t] : t.map((e) => {
|
|
1442
1442
|
let t = !1, r = e.parts.map((e) => {
|
|
1443
1443
|
if (e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path) return e;
|
|
@@ -1456,9 +1456,9 @@ function kn(e, t) {
|
|
|
1456
1456
|
} : e;
|
|
1457
1457
|
});
|
|
1458
1458
|
}
|
|
1459
|
-
function
|
|
1459
|
+
function Mn(e, t) {
|
|
1460
1460
|
let n = new Map(e.filter((e) => e.role === "user" && e.metadata?.promptContent).map((e) => [e.id, e.metadata.promptContent]));
|
|
1461
|
-
return
|
|
1461
|
+
return jn(e, t).map((e) => {
|
|
1462
1462
|
let t = n.get(e.id);
|
|
1463
1463
|
if (!t || e.role !== "user") return e;
|
|
1464
1464
|
let r = le(t);
|
|
@@ -1475,14 +1475,14 @@ function An(e, t) {
|
|
|
1475
1475
|
};
|
|
1476
1476
|
});
|
|
1477
1477
|
}
|
|
1478
|
-
function
|
|
1479
|
-
let n = [], r = [], i =
|
|
1478
|
+
function P(e, t) {
|
|
1479
|
+
let n = [], r = [], i = Xn(t.startedAt ?? t.completedAt), a = 0, o = !1, s = !1, c = /* @__PURE__ */ new Set(), l = () => {
|
|
1480
1480
|
if (r.length === 0) return;
|
|
1481
1481
|
let o = a === 0 ? "" : `-segment-${a}`;
|
|
1482
1482
|
n.push({
|
|
1483
1483
|
id: `assistant-${t.id}${o}`,
|
|
1484
1484
|
role: "assistant",
|
|
1485
|
-
status:
|
|
1485
|
+
status: Yn(t.status),
|
|
1486
1486
|
turnId: t.id,
|
|
1487
1487
|
parts: [...r],
|
|
1488
1488
|
createdAt: i,
|
|
@@ -1494,7 +1494,7 @@ function jn(e, t) {
|
|
|
1494
1494
|
};
|
|
1495
1495
|
for (let a of Array.isArray(t.items) ? t.items : []) {
|
|
1496
1496
|
if (a.type === "userMessage") {
|
|
1497
|
-
let r =
|
|
1497
|
+
let r = Ln(a), s = zn(a);
|
|
1498
1498
|
if (r.length > 0) {
|
|
1499
1499
|
let u = o, d = u ? null : JSON.stringify(r);
|
|
1500
1500
|
if (d && c.has(d)) continue;
|
|
@@ -1511,7 +1511,7 @@ function jn(e, t) {
|
|
|
1511
1511
|
turnId: t.id,
|
|
1512
1512
|
...s.length > 0 ? {
|
|
1513
1513
|
asyncQuestionRequestIds: s,
|
|
1514
|
-
asyncQuestionAnswers:
|
|
1514
|
+
asyncQuestionAnswers: Bn(a)
|
|
1515
1515
|
} : {}
|
|
1516
1516
|
}
|
|
1517
1517
|
});
|
|
@@ -1539,7 +1539,7 @@ function jn(e, t) {
|
|
|
1539
1539
|
if (a.type === "agentMessage") {
|
|
1540
1540
|
let n = typeof a.text == "string" ? a.text : "";
|
|
1541
1541
|
a.phase === "final_answer" && n.trim() && (s = !0);
|
|
1542
|
-
let i =
|
|
1542
|
+
let i = Pn(e, t.id, a, !0), c = a.phase === "final_answer" ? _n(n) : null;
|
|
1543
1543
|
c && !i ? c.visibleText && (o = !0, r.push({
|
|
1544
1544
|
type: "text",
|
|
1545
1545
|
text: c.visibleText,
|
|
@@ -1580,13 +1580,13 @@ function jn(e, t) {
|
|
|
1580
1580
|
}
|
|
1581
1581
|
let u = w(a);
|
|
1582
1582
|
u && (o = !0, r.push(u));
|
|
1583
|
-
let d =
|
|
1583
|
+
let d = In(a);
|
|
1584
1584
|
d.length && (o = !0, r.push(...d));
|
|
1585
1585
|
}
|
|
1586
1586
|
return l(), (t.itemsView === "summary" || t.itemsView === "notLoaded") && !n.some((e) => e.role === "assistant") && n.push({
|
|
1587
1587
|
id: `assistant-${t.id}`,
|
|
1588
1588
|
role: "assistant",
|
|
1589
|
-
status:
|
|
1589
|
+
status: Yn(t.status),
|
|
1590
1590
|
turnId: t.id,
|
|
1591
1591
|
parts: [],
|
|
1592
1592
|
createdAt: i,
|
|
@@ -1594,12 +1594,12 @@ function jn(e, t) {
|
|
|
1594
1594
|
conversationId: e,
|
|
1595
1595
|
turnId: t.id
|
|
1596
1596
|
}
|
|
1597
|
-
}), t.status === "inProgress" ? n :
|
|
1597
|
+
}), t.status === "inProgress" ? n : Cn(n, t.id, t.status);
|
|
1598
1598
|
}
|
|
1599
|
-
function
|
|
1600
|
-
let r =
|
|
1599
|
+
function Nn(e, t, n) {
|
|
1600
|
+
let r = Xn(t.startedAt);
|
|
1601
1601
|
if (n.type === "userMessage") {
|
|
1602
|
-
let i =
|
|
1602
|
+
let i = Ln(n), a = zn(n);
|
|
1603
1603
|
return i.length > 0 ? {
|
|
1604
1604
|
id: n.clientId ?? `user-${e}-${t.id}-${n.id}`,
|
|
1605
1605
|
role: "user",
|
|
@@ -1613,13 +1613,13 @@ function Mn(e, t, n) {
|
|
|
1613
1613
|
itemId: n.id,
|
|
1614
1614
|
...a.length > 0 ? {
|
|
1615
1615
|
asyncQuestionRequestIds: a,
|
|
1616
|
-
asyncQuestionAnswers:
|
|
1616
|
+
asyncQuestionAnswers: Bn(n)
|
|
1617
1617
|
} : {}
|
|
1618
1618
|
}
|
|
1619
1619
|
} : null;
|
|
1620
1620
|
}
|
|
1621
1621
|
if (n.type === "agentMessage" || n.type === "exitedReviewMode") {
|
|
1622
|
-
let i = n.type === "agentMessage" ? n.text : n.review, a = n.type === "agentMessage" && n.phase === "final_answer" ?
|
|
1622
|
+
let i = n.type === "agentMessage" ? n.text : n.review, a = n.type === "agentMessage" && n.phase === "final_answer" ? _n(i) : null, o = n.type === "agentMessage" ? Pn(e, t.id, n, !0) : null, s = [...!o && (a?.visibleText || !a && i) ? [{
|
|
1623
1623
|
type: "text",
|
|
1624
1624
|
text: a?.visibleText ?? i,
|
|
1625
1625
|
itemId: n.id,
|
|
@@ -1628,7 +1628,7 @@ function Mn(e, t, n) {
|
|
|
1628
1628
|
return s.length > 0 ? {
|
|
1629
1629
|
id: `assistant-${n.id}`,
|
|
1630
1630
|
role: "assistant",
|
|
1631
|
-
status:
|
|
1631
|
+
status: Yn(t.status),
|
|
1632
1632
|
turnId: t.id,
|
|
1633
1633
|
parts: s,
|
|
1634
1634
|
createdAt: r,
|
|
@@ -1652,7 +1652,7 @@ function Mn(e, t, n) {
|
|
|
1652
1652
|
return i.length > 0 ? {
|
|
1653
1653
|
id: `assistant-${n.id}`,
|
|
1654
1654
|
role: "assistant",
|
|
1655
|
-
status:
|
|
1655
|
+
status: Yn(t.status),
|
|
1656
1656
|
turnId: t.id,
|
|
1657
1657
|
parts: i,
|
|
1658
1658
|
createdAt: r,
|
|
@@ -1664,11 +1664,11 @@ function Mn(e, t, n) {
|
|
|
1664
1664
|
} : null;
|
|
1665
1665
|
}
|
|
1666
1666
|
let i = [], a = w(n);
|
|
1667
|
-
a && i.push(a), i.push(...
|
|
1667
|
+
a && i.push(a), i.push(...In(n));
|
|
1668
1668
|
let o = i.length > 0 ? {
|
|
1669
1669
|
id: `assistant-${n.id}`,
|
|
1670
1670
|
role: "assistant",
|
|
1671
|
-
status:
|
|
1671
|
+
status: Yn(t.status),
|
|
1672
1672
|
turnId: t.id,
|
|
1673
1673
|
parts: i,
|
|
1674
1674
|
createdAt: r,
|
|
@@ -1678,9 +1678,9 @@ function Mn(e, t, n) {
|
|
|
1678
1678
|
itemId: n.id
|
|
1679
1679
|
}
|
|
1680
1680
|
} : null;
|
|
1681
|
-
return !o || t.status === "inProgress" ? o :
|
|
1681
|
+
return !o || t.status === "inProgress" ? o : Cn([o], t.id, t.status)[0] ?? null;
|
|
1682
1682
|
}
|
|
1683
|
-
function
|
|
1683
|
+
function Pn(e, t, n, r = !1) {
|
|
1684
1684
|
if (n.delivery !== "async") return null;
|
|
1685
1685
|
let i = n.questions ?? [], a = i.length > 0 ? i.map((e, t) => ({
|
|
1686
1686
|
id: JSON.stringify([
|
|
@@ -1722,9 +1722,9 @@ function Nn(e, t, n, r = !1) {
|
|
|
1722
1722
|
...r ? { historical: !0 } : {}
|
|
1723
1723
|
};
|
|
1724
1724
|
}
|
|
1725
|
-
function
|
|
1725
|
+
function Fn(e) {
|
|
1726
1726
|
if (e.type !== "imageGeneration" || w(e)?.status !== "completed") return null;
|
|
1727
|
-
let t = typeof e.savedPath == "string" && v(e.savedPath) ? e.savedPath : null, n = t ?
|
|
1727
|
+
let t = typeof e.savedPath == "string" && v(e.savedPath) ? e.savedPath : null, n = t ? Wn(t) : void 0, r = n && kn.has(n) ? t : null, i = Gn("result" in e && typeof e.result == "string" ? e.result.trim() : ""), a = i?.url ?? (r ? pe(r).href : void 0);
|
|
1728
1728
|
if (!a) return null;
|
|
1729
1729
|
let o = typeof e.revisedPrompt == "string" ? e.revisedPrompt.trim() : "";
|
|
1730
1730
|
return {
|
|
@@ -1739,11 +1739,11 @@ function Pn(e) {
|
|
|
1739
1739
|
}
|
|
1740
1740
|
};
|
|
1741
1741
|
}
|
|
1742
|
-
function
|
|
1742
|
+
function In(e) {
|
|
1743
1743
|
if (e.type === "imageView") {
|
|
1744
1744
|
if (typeof e.path != "string") return [];
|
|
1745
|
-
let t =
|
|
1746
|
-
return v(e.path) && t &&
|
|
1745
|
+
let t = Wn(e.path);
|
|
1746
|
+
return v(e.path) && t && kn.has(t) ? [{
|
|
1747
1747
|
type: "media",
|
|
1748
1748
|
phase: "commentary",
|
|
1749
1749
|
itemId: e.id,
|
|
@@ -1755,7 +1755,7 @@ function Fn(e) {
|
|
|
1755
1755
|
}
|
|
1756
1756
|
}] : [];
|
|
1757
1757
|
}
|
|
1758
|
-
let t =
|
|
1758
|
+
let t = Fn(e);
|
|
1759
1759
|
if (t) return [t];
|
|
1760
1760
|
let n = e.type === "mcpToolCall" && e.status === "completed" ? e.result?.content : e.type === "dynamicToolCall" && e.status === "completed" ? e.contentItems : void 0;
|
|
1761
1761
|
if (!Array.isArray(n)) return [];
|
|
@@ -1771,13 +1771,13 @@ function Fn(e) {
|
|
|
1771
1771
|
a -= e;
|
|
1772
1772
|
try {
|
|
1773
1773
|
let e = JSON.parse(t.text);
|
|
1774
|
-
|
|
1774
|
+
F(e) && Array.isArray(e.content) && s(e.content, n + 1);
|
|
1775
1775
|
} catch {}
|
|
1776
1776
|
continue;
|
|
1777
1777
|
}
|
|
1778
1778
|
let l = t.type === "image" && typeof t.data == "string" ? t.data : t.type === "inputImage" && typeof t.imageUrl == "string" ? t.imageUrl : "";
|
|
1779
1779
|
if (l.length > i) continue;
|
|
1780
|
-
let u =
|
|
1780
|
+
let u = Gn(l);
|
|
1781
1781
|
u && (i -= u.url.length, r.push({
|
|
1782
1782
|
type: "media",
|
|
1783
1783
|
phase: "commentary",
|
|
@@ -1793,21 +1793,21 @@ function Fn(e) {
|
|
|
1793
1793
|
};
|
|
1794
1794
|
return s(n, 0), r;
|
|
1795
1795
|
}
|
|
1796
|
-
function
|
|
1797
|
-
let t = Array.isArray(e.content) ? e.content : [], n = t.some((e) =>
|
|
1796
|
+
function Ln(e) {
|
|
1797
|
+
let t = Array.isArray(e.content) ? e.content : [], n = t.some((e) => F(e) && e.type === "text" && typeof e.text == "string" && e.text.length > 0), r = [], i = [], a = /* @__PURE__ */ new Set(), o = () => {
|
|
1798
1798
|
i.length > 0 && r.push({
|
|
1799
1799
|
type: "text",
|
|
1800
1800
|
text: i.join("\n")
|
|
1801
1801
|
}), i = [];
|
|
1802
1802
|
};
|
|
1803
1803
|
for (let e of t) {
|
|
1804
|
-
if (
|
|
1804
|
+
if (F(e) && e.type === "skill" && typeof e.name == "string") {
|
|
1805
1805
|
if (n) continue;
|
|
1806
1806
|
let t = e.name.toLowerCase();
|
|
1807
1807
|
if (a.has(t)) continue;
|
|
1808
1808
|
a.add(t);
|
|
1809
1809
|
}
|
|
1810
|
-
let t =
|
|
1810
|
+
let t = Rn(e), s = ct(t);
|
|
1811
1811
|
if (s) {
|
|
1812
1812
|
o(), r.push({
|
|
1813
1813
|
type: "attachment",
|
|
@@ -1822,7 +1822,7 @@ function In(e) {
|
|
|
1822
1822
|
i.push(t);
|
|
1823
1823
|
continue;
|
|
1824
1824
|
}
|
|
1825
|
-
let c =
|
|
1825
|
+
let c = Hn(e);
|
|
1826
1826
|
c && (o(), r.push({
|
|
1827
1827
|
type: "attachment",
|
|
1828
1828
|
attachment: c
|
|
@@ -1830,26 +1830,26 @@ function In(e) {
|
|
|
1830
1830
|
}
|
|
1831
1831
|
return o(), r;
|
|
1832
1832
|
}
|
|
1833
|
-
function Ln(e) {
|
|
1834
|
-
return !I(e) || typeof e.type != "string" ? "" : e.type === "text" && typeof e.text == "string" ? Bn(e.text)?.displayText ?? e.text : e.type === "skill" && typeof e.name == "string" ? `$${e.name}` : "";
|
|
1835
|
-
}
|
|
1836
1833
|
function Rn(e) {
|
|
1834
|
+
return !F(e) || typeof e.type != "string" ? "" : e.type === "text" && typeof e.text == "string" ? Vn(e.text)?.displayText ?? e.text : e.type === "skill" && typeof e.name == "string" ? `$${e.name}` : "";
|
|
1835
|
+
}
|
|
1836
|
+
function zn(e) {
|
|
1837
1837
|
let t = /* @__PURE__ */ new Set();
|
|
1838
|
-
for (let n of Array.isArray(e.content) ? e.content : []) if (!(!
|
|
1838
|
+
for (let n of Array.isArray(e.content) ? e.content : []) if (!(!F(n) || n.type !== "text" || typeof n.text != "string")) for (let e of Vn(n.text)?.requestIds ?? []) t.add(e);
|
|
1839
1839
|
return [...t];
|
|
1840
1840
|
}
|
|
1841
|
-
function
|
|
1841
|
+
function Bn(e) {
|
|
1842
1842
|
let t = {};
|
|
1843
|
-
for (let n of Array.isArray(e.content) ? e.content : []) !
|
|
1843
|
+
for (let n of Array.isArray(e.content) ? e.content : []) !F(n) || n.type !== "text" || typeof n.text != "string" || Object.assign(t, Vn(n.text)?.answers);
|
|
1844
1844
|
return t;
|
|
1845
1845
|
}
|
|
1846
|
-
function
|
|
1846
|
+
function Vn(e) {
|
|
1847
1847
|
let t = e.match(/^<send_user_message_question_reply>\s*([\s\S]*?)\s*<\/send_user_message_question_reply>$/);
|
|
1848
1848
|
if (!t?.[1]) return null;
|
|
1849
1849
|
try {
|
|
1850
1850
|
let e = JSON.parse(t[1]);
|
|
1851
1851
|
if (!Array.isArray(e)) return null;
|
|
1852
|
-
let n = e.filter((e) =>
|
|
1852
|
+
let n = e.filter((e) => F(e) && typeof e.questionItemId == "string" && typeof e.question == "string" && typeof e.answer == "string");
|
|
1853
1853
|
if (n.length === 0) return null;
|
|
1854
1854
|
let r = n.flatMap((e) => {
|
|
1855
1855
|
try {
|
|
@@ -1867,10 +1867,10 @@ function Bn(e) {
|
|
|
1867
1867
|
return null;
|
|
1868
1868
|
}
|
|
1869
1869
|
}
|
|
1870
|
-
function
|
|
1871
|
-
if (!
|
|
1870
|
+
function Hn(e) {
|
|
1871
|
+
if (!F(e) || typeof e.type != "string") return null;
|
|
1872
1872
|
if (e.type === "mention" && typeof e.path == "string" && !e.path.startsWith("plugin://")) {
|
|
1873
|
-
let t = typeof e.name == "string" && e.name.trim() ? e.name.trim() :
|
|
1873
|
+
let t = typeof e.name == "string" && e.name.trim() ? e.name.trim() : Un(e.path, "File"), n = Wn(e.path);
|
|
1874
1874
|
return {
|
|
1875
1875
|
kind: "file",
|
|
1876
1876
|
name: t,
|
|
@@ -1879,26 +1879,26 @@ function Vn(e) {
|
|
|
1879
1879
|
};
|
|
1880
1880
|
}
|
|
1881
1881
|
if (e.type === "image" && typeof e.url == "string") {
|
|
1882
|
-
let t =
|
|
1882
|
+
let t = Wn(e.url);
|
|
1883
1883
|
return {
|
|
1884
1884
|
kind: "image",
|
|
1885
|
-
name:
|
|
1885
|
+
name: Un(e.url, "Image"),
|
|
1886
1886
|
url: e.url,
|
|
1887
1887
|
...t ? { mimeType: t } : {}
|
|
1888
1888
|
};
|
|
1889
1889
|
}
|
|
1890
1890
|
if (e.type === "localImage" && typeof e.path == "string") {
|
|
1891
|
-
let t =
|
|
1891
|
+
let t = Wn(e.path);
|
|
1892
1892
|
return {
|
|
1893
1893
|
kind: "image",
|
|
1894
|
-
name:
|
|
1894
|
+
name: Un(e.path, "Image"),
|
|
1895
1895
|
path: e.path,
|
|
1896
1896
|
...t ? { mimeType: t } : {}
|
|
1897
1897
|
};
|
|
1898
1898
|
}
|
|
1899
1899
|
return null;
|
|
1900
1900
|
}
|
|
1901
|
-
function
|
|
1901
|
+
function Un(e, t) {
|
|
1902
1902
|
try {
|
|
1903
1903
|
let n = /^[a-z][a-z\d+.-]*:/i.test(e) ? new URL(e).pathname : e;
|
|
1904
1904
|
return g(decodeURIComponent(n)).trim() || t;
|
|
@@ -1906,7 +1906,7 @@ function Hn(e, t) {
|
|
|
1906
1906
|
return g(e).trim() || t;
|
|
1907
1907
|
}
|
|
1908
1908
|
}
|
|
1909
|
-
function
|
|
1909
|
+
function Wn(e) {
|
|
1910
1910
|
let t = /^data:([^;,]+)/i.exec(e)?.[1]?.toLowerCase();
|
|
1911
1911
|
if (t) return t;
|
|
1912
1912
|
let n = "";
|
|
@@ -1928,23 +1928,23 @@ function Un(e) {
|
|
|
1928
1928
|
webp: "image/webp"
|
|
1929
1929
|
}[n];
|
|
1930
1930
|
}
|
|
1931
|
-
function
|
|
1931
|
+
function Gn(e) {
|
|
1932
1932
|
if (!e) return null;
|
|
1933
|
-
let t = (/^data:image\/[a-z0-9.+-]+;base64,([a-z0-9+/=\s]+)$/i.exec(e)?.[1] ?? e).replace(/\s+/g, ""), n = Math.ceil(
|
|
1933
|
+
let t = (/^data:image\/[a-z0-9.+-]+;base64,([a-z0-9+/=\s]+)$/i.exec(e)?.[1] ?? e).replace(/\s+/g, ""), n = Math.ceil(On / 3) * 4 + 4;
|
|
1934
1934
|
if (!t || t.length > n || t.length % 4 != 0 || !/^[a-z0-9+/]+={0,2}$/i.test(t)) return null;
|
|
1935
1935
|
let r = Buffer.from(t, "base64");
|
|
1936
|
-
if (r.byteLength === 0 || r.byteLength >
|
|
1937
|
-
let i =
|
|
1936
|
+
if (r.byteLength === 0 || r.byteLength > On) return null;
|
|
1937
|
+
let i = qn(r);
|
|
1938
1938
|
return i ? {
|
|
1939
1939
|
url: `data:${i};base64,${t}`,
|
|
1940
1940
|
mimeType: i
|
|
1941
1941
|
} : null;
|
|
1942
1942
|
}
|
|
1943
|
-
function
|
|
1943
|
+
function Kn(e) {
|
|
1944
1944
|
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));
|
|
1945
1945
|
}
|
|
1946
|
-
function
|
|
1947
|
-
if (
|
|
1946
|
+
function qn(e) {
|
|
1947
|
+
if (Jn(e, [
|
|
1948
1948
|
137,
|
|
1949
1949
|
80,
|
|
1950
1950
|
78,
|
|
@@ -1954,7 +1954,7 @@ function Kn(e) {
|
|
|
1954
1954
|
26,
|
|
1955
1955
|
10
|
|
1956
1956
|
])) return "image/png";
|
|
1957
|
-
if (
|
|
1957
|
+
if (Jn(e, [
|
|
1958
1958
|
255,
|
|
1959
1959
|
216,
|
|
1960
1960
|
255
|
|
@@ -1962,50 +1962,50 @@ function Kn(e) {
|
|
|
1962
1962
|
let t = Buffer.from(e.subarray(0, 12)).toString("ascii");
|
|
1963
1963
|
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;
|
|
1964
1964
|
}
|
|
1965
|
-
function
|
|
1965
|
+
function Jn(e, t) {
|
|
1966
1966
|
return t.every((t, n) => e[n] === t);
|
|
1967
1967
|
}
|
|
1968
|
-
function
|
|
1968
|
+
function Yn(e) {
|
|
1969
1969
|
return e === "inProgress" ? "streaming" : e === "failed" ? "error" : "complete";
|
|
1970
1970
|
}
|
|
1971
|
-
function
|
|
1971
|
+
function Xn(e) {
|
|
1972
1972
|
return typeof e != "number" || !Number.isFinite(e) ? (/* @__PURE__ */ new Date(0)).toISOString() : (/* @__PURE__ */ new Date(e * 1e3)).toISOString();
|
|
1973
1973
|
}
|
|
1974
|
-
function
|
|
1974
|
+
function F(e) {
|
|
1975
1975
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
1976
1976
|
}
|
|
1977
1977
|
//#endregion
|
|
1978
1978
|
//#region ../../node_modules/image-size/dist/esm/types/utils.js
|
|
1979
|
-
var
|
|
1980
|
-
let n =
|
|
1979
|
+
var Zn = new TextDecoder(), I = (e, t = 0, n = e.length) => Zn.decode(e.slice(t, n)), L = (e, t = 0, n = e.length) => e.slice(t, n).reduce((e, t) => e + `0${t.toString(16)}`.slice(-2), ""), R = (e, t) => new DataView(e.buffer, e.byteOffset + t), Qn = (e, t = 0) => R(e, t).getInt16(0, !0), $n = (e, t = 0) => R(e, t).getUint16(0, !1), z = (e, t = 0) => R(e, t).getUint16(0, !0), er = (e, t = 0) => {
|
|
1980
|
+
let n = R(e, t);
|
|
1981
1981
|
return n.getUint16(0, !0) + (n.getUint8(2) << 16);
|
|
1982
|
-
},
|
|
1983
|
-
readUInt16BE:
|
|
1984
|
-
readUInt16LE:
|
|
1985
|
-
readUInt32BE:
|
|
1986
|
-
readUInt32LE:
|
|
1982
|
+
}, tr = (e, t = 0) => R(e, t).getInt32(0, !0), B = (e, t = 0) => R(e, t).getUint32(0, !1), V = (e, t = 0) => R(e, t).getUint32(0, !0), nr = (e, t, n) => R(e, t).getBigUint64(0, !n), rr = {
|
|
1983
|
+
readUInt16BE: $n,
|
|
1984
|
+
readUInt16LE: z,
|
|
1985
|
+
readUInt32BE: B,
|
|
1986
|
+
readUInt32LE: V
|
|
1987
1987
|
};
|
|
1988
|
-
function
|
|
1989
|
-
return
|
|
1988
|
+
function H(e, t, n = 0, r = !1) {
|
|
1989
|
+
return rr[`readUInt${t}${r ? "BE" : "LE"}`](e, n);
|
|
1990
1990
|
}
|
|
1991
|
-
var
|
|
1992
|
-
function
|
|
1993
|
-
if (e.length - t <
|
|
1994
|
-
let n =
|
|
1991
|
+
var ir = 8;
|
|
1992
|
+
function ar(e, t) {
|
|
1993
|
+
if (e.length - t < ir) return;
|
|
1994
|
+
let n = B(e, t);
|
|
1995
1995
|
if (!(e.length - t < n)) return {
|
|
1996
|
-
name:
|
|
1996
|
+
name: I(e, 4 + t, 8 + t),
|
|
1997
1997
|
offset: t,
|
|
1998
1998
|
size: n
|
|
1999
1999
|
};
|
|
2000
2000
|
}
|
|
2001
|
-
function
|
|
2001
|
+
function U(e, t, n) {
|
|
2002
2002
|
let r = n;
|
|
2003
2003
|
for (; r < e.length && !(e.length - r < 4);) {
|
|
2004
|
-
if (
|
|
2005
|
-
r +=
|
|
2004
|
+
if (B(e, r) < ir) {
|
|
2005
|
+
r += ir;
|
|
2006
2006
|
continue;
|
|
2007
2007
|
}
|
|
2008
|
-
let n =
|
|
2008
|
+
let n = ar(e, r);
|
|
2009
2009
|
if (!n) break;
|
|
2010
2010
|
if (n.name === t) return n;
|
|
2011
2011
|
r += n.size;
|
|
@@ -2013,61 +2013,61 @@ function W(e, t, n) {
|
|
|
2013
2013
|
}
|
|
2014
2014
|
//#endregion
|
|
2015
2015
|
//#region ../../node_modules/image-size/dist/esm/types/bmp.js
|
|
2016
|
-
var
|
|
2017
|
-
validate: (e) =>
|
|
2016
|
+
var or = {
|
|
2017
|
+
validate: (e) => I(e, 0, 2) === "BM",
|
|
2018
2018
|
calculate: (e) => ({
|
|
2019
|
-
height: Math.abs(
|
|
2020
|
-
width:
|
|
2019
|
+
height: Math.abs(tr(e, 22)),
|
|
2020
|
+
width: V(e, 18)
|
|
2021
2021
|
})
|
|
2022
|
-
},
|
|
2023
|
-
function
|
|
2022
|
+
}, sr = 1, cr = 6, lr = 16;
|
|
2023
|
+
function ur(e, t) {
|
|
2024
2024
|
let n = e[t];
|
|
2025
2025
|
return n === 0 ? 256 : n;
|
|
2026
2026
|
}
|
|
2027
|
-
function
|
|
2028
|
-
let n =
|
|
2027
|
+
function dr(e, t) {
|
|
2028
|
+
let n = cr + t * lr;
|
|
2029
2029
|
return {
|
|
2030
|
-
height:
|
|
2031
|
-
width:
|
|
2030
|
+
height: ur(e, n + 1),
|
|
2031
|
+
width: ur(e, n)
|
|
2032
2032
|
};
|
|
2033
2033
|
}
|
|
2034
|
-
var
|
|
2034
|
+
var fr = {
|
|
2035
2035
|
validate(e) {
|
|
2036
|
-
let t =
|
|
2037
|
-
return t !== 0 || n === 0 ? !1 :
|
|
2036
|
+
let t = z(e, 0), n = z(e, 4);
|
|
2037
|
+
return t !== 0 || n === 0 ? !1 : z(e, 2) === sr;
|
|
2038
2038
|
},
|
|
2039
2039
|
calculate(e) {
|
|
2040
|
-
let t =
|
|
2041
|
-
if (
|
|
2042
|
-
let n =
|
|
2040
|
+
let t = z(e, 4);
|
|
2041
|
+
if (cr + t * lr > e.length) throw TypeError("Invalid ICO");
|
|
2042
|
+
let n = dr(e, 0);
|
|
2043
2043
|
if (t === 1) return n;
|
|
2044
2044
|
let r = [];
|
|
2045
|
-
for (let n = 0; n < t; n += 1) r.push(
|
|
2045
|
+
for (let n = 0; n < t; n += 1) r.push(dr(e, n));
|
|
2046
2046
|
return {
|
|
2047
2047
|
width: n.width,
|
|
2048
2048
|
height: n.height,
|
|
2049
2049
|
images: r
|
|
2050
2050
|
};
|
|
2051
2051
|
}
|
|
2052
|
-
},
|
|
2052
|
+
}, pr = 2, mr = {
|
|
2053
2053
|
validate(e) {
|
|
2054
|
-
let t =
|
|
2055
|
-
return t !== 0 || n === 0 ? !1 :
|
|
2054
|
+
let t = z(e, 0), n = z(e, 4);
|
|
2055
|
+
return t !== 0 || n === 0 ? !1 : z(e, 2) === pr;
|
|
2056
2056
|
},
|
|
2057
|
-
calculate: (e) =>
|
|
2058
|
-
},
|
|
2059
|
-
validate: (e) =>
|
|
2057
|
+
calculate: (e) => fr.calculate(e)
|
|
2058
|
+
}, hr = {
|
|
2059
|
+
validate: (e) => V(e, 0) === 542327876,
|
|
2060
2060
|
calculate: (e) => ({
|
|
2061
|
-
height:
|
|
2062
|
-
width:
|
|
2061
|
+
height: V(e, 12),
|
|
2062
|
+
width: V(e, 16)
|
|
2063
2063
|
})
|
|
2064
|
-
},
|
|
2065
|
-
validate: (e) =>
|
|
2064
|
+
}, gr = /^GIF8[79]a/, _r = {
|
|
2065
|
+
validate: (e) => gr.test(I(e, 0, 6)),
|
|
2066
2066
|
calculate: (e) => ({
|
|
2067
|
-
height:
|
|
2068
|
-
width:
|
|
2067
|
+
height: z(e, 8),
|
|
2068
|
+
width: z(e, 6)
|
|
2069
2069
|
})
|
|
2070
|
-
},
|
|
2070
|
+
}, vr = {
|
|
2071
2071
|
avif: "avif",
|
|
2072
2072
|
mif1: "heif",
|
|
2073
2073
|
msf1: "heif",
|
|
@@ -2075,22 +2075,22 @@ var dr = {
|
|
|
2075
2075
|
heix: "heic",
|
|
2076
2076
|
hevc: "heic",
|
|
2077
2077
|
hevx: "heic"
|
|
2078
|
-
},
|
|
2078
|
+
}, yr = {
|
|
2079
2079
|
validate(e) {
|
|
2080
|
-
if (
|
|
2081
|
-
let t =
|
|
2082
|
-
return t ?
|
|
2080
|
+
if (I(e, 4, 8) !== "ftyp") return !1;
|
|
2081
|
+
let t = U(e, "ftyp", 0);
|
|
2082
|
+
return t ? I(e, t.offset + 8, t.offset + 12) in vr : !1;
|
|
2083
2083
|
},
|
|
2084
2084
|
calculate(e) {
|
|
2085
|
-
let t =
|
|
2085
|
+
let t = U(e, "meta", 0), n = t && U(e, "iprp", t.offset + 12), r = n && U(e, "ipco", n.offset + 8);
|
|
2086
2086
|
if (!r) throw TypeError("Invalid HEIF, no ipco box found");
|
|
2087
|
-
let i =
|
|
2087
|
+
let i = I(e, 8, 12), a = [], o = r.offset + 8;
|
|
2088
2088
|
for (; o < r.offset + r.size;) {
|
|
2089
|
-
let t =
|
|
2089
|
+
let t = U(e, "ispe", o);
|
|
2090
2090
|
if (!t) break;
|
|
2091
2091
|
if (t.size < 20) throw TypeError("Invalid HEIF");
|
|
2092
|
-
let n =
|
|
2093
|
-
s && s.size >= 16 && s.offset < r.offset + r.size && (c = n -
|
|
2092
|
+
let n = B(e, t.offset + 12), i = B(e, t.offset + 16), s = U(e, "clap", o), c = n, l = i;
|
|
2093
|
+
s && s.size >= 16 && s.offset < r.offset + r.size && (c = n - B(e, s.offset + 12)), a.push({
|
|
2094
2094
|
height: l,
|
|
2095
2095
|
width: c
|
|
2096
2096
|
});
|
|
@@ -2106,7 +2106,7 @@ var dr = {
|
|
|
2106
2106
|
...a.length > 1 ? { images: a } : {}
|
|
2107
2107
|
};
|
|
2108
2108
|
}
|
|
2109
|
-
},
|
|
2109
|
+
}, br = 8, xr = 4, Sr = 4, Cr = {
|
|
2110
2110
|
ICON: 32,
|
|
2111
2111
|
"ICN#": 32,
|
|
2112
2112
|
"icm#": 16,
|
|
@@ -2139,27 +2139,27 @@ var dr = {
|
|
|
2139
2139
|
ic14: 512,
|
|
2140
2140
|
ic10: 1024
|
|
2141
2141
|
};
|
|
2142
|
-
function
|
|
2143
|
-
let n = t +
|
|
2142
|
+
function wr(e, t) {
|
|
2143
|
+
let n = t + Sr;
|
|
2144
2144
|
if (n + 4 > e.length) throw TypeError("Invalid ICNS");
|
|
2145
|
-
return [
|
|
2145
|
+
return [I(e, t, n), B(e, n)];
|
|
2146
2146
|
}
|
|
2147
|
-
function
|
|
2148
|
-
let t =
|
|
2147
|
+
function Tr(e) {
|
|
2148
|
+
let t = Cr[e];
|
|
2149
2149
|
return {
|
|
2150
2150
|
width: t,
|
|
2151
2151
|
height: t,
|
|
2152
2152
|
type: e
|
|
2153
2153
|
};
|
|
2154
2154
|
}
|
|
2155
|
-
var
|
|
2156
|
-
validate: (e) =>
|
|
2155
|
+
var Er = {
|
|
2156
|
+
validate: (e) => I(e, 0, 4) === "icns",
|
|
2157
2157
|
calculate(e) {
|
|
2158
|
-
let t = e.length, n =
|
|
2158
|
+
let t = e.length, n = B(e, xr), r = br, i = [];
|
|
2159
2159
|
for (; r < n && r < t;) {
|
|
2160
|
-
let t =
|
|
2160
|
+
let t = wr(e, r), n = t[1];
|
|
2161
2161
|
if (n < 8) throw TypeError("Invalid ICNS");
|
|
2162
|
-
let a =
|
|
2162
|
+
let a = Tr(t[0]);
|
|
2163
2163
|
i.push(a), r += n;
|
|
2164
2164
|
}
|
|
2165
2165
|
if (i.length === 0) throw TypeError("Invalid ICNS, no sizes found");
|
|
@@ -2169,64 +2169,64 @@ var Tr = {
|
|
|
2169
2169
|
...i.length > 1 ? { images: i } : {}
|
|
2170
2170
|
};
|
|
2171
2171
|
}
|
|
2172
|
-
},
|
|
2173
|
-
validate: (e) =>
|
|
2172
|
+
}, Dr = {
|
|
2173
|
+
validate: (e) => B(e, 0) === 4283432785,
|
|
2174
2174
|
calculate: (e) => ({
|
|
2175
|
-
height:
|
|
2176
|
-
width:
|
|
2175
|
+
height: B(e, 12),
|
|
2176
|
+
width: B(e, 8)
|
|
2177
2177
|
})
|
|
2178
|
-
},
|
|
2178
|
+
}, Or = {
|
|
2179
2179
|
validate(e) {
|
|
2180
|
-
if (
|
|
2181
|
-
let t =
|
|
2182
|
-
return t ?
|
|
2180
|
+
if (I(e, 4, 8) !== "jP ") return !1;
|
|
2181
|
+
let t = U(e, "ftyp", 0);
|
|
2182
|
+
return t ? I(e, t.offset + 8, t.offset + 12) === "jp2 " : !1;
|
|
2183
2183
|
},
|
|
2184
2184
|
calculate(e) {
|
|
2185
|
-
let t =
|
|
2185
|
+
let t = U(e, "jp2h", 0), n = t && U(e, "ihdr", t.offset + 8);
|
|
2186
2186
|
if (n) return {
|
|
2187
|
-
height:
|
|
2188
|
-
width:
|
|
2187
|
+
height: B(e, n.offset + 8),
|
|
2188
|
+
width: B(e, n.offset + 12)
|
|
2189
2189
|
};
|
|
2190
2190
|
throw TypeError("Unsupported JPEG 2000 format");
|
|
2191
2191
|
}
|
|
2192
|
-
},
|
|
2193
|
-
function
|
|
2194
|
-
return
|
|
2192
|
+
}, kr = "45786966", Ar = 2, jr = 6, Mr = "4d4d", Nr = "4949", Pr = 12;
|
|
2193
|
+
function Fr(e) {
|
|
2194
|
+
return L(e, 2, 6) === kr;
|
|
2195
2195
|
}
|
|
2196
|
-
function
|
|
2196
|
+
function Ir(e, t) {
|
|
2197
2197
|
return {
|
|
2198
|
-
height:
|
|
2199
|
-
width:
|
|
2198
|
+
height: $n(e, t),
|
|
2199
|
+
width: $n(e, t + 2)
|
|
2200
2200
|
};
|
|
2201
2201
|
}
|
|
2202
|
-
function
|
|
2203
|
-
let n =
|
|
2202
|
+
function Lr(e, t) {
|
|
2203
|
+
let n = H(e, 16, 14, t);
|
|
2204
2204
|
for (let r = 0; r < n; r++) {
|
|
2205
|
-
let n = 16 + r *
|
|
2205
|
+
let n = 16 + r * Pr, i = n + Pr;
|
|
2206
2206
|
if (n > e.length) return;
|
|
2207
2207
|
let a = e.slice(n, i);
|
|
2208
|
-
if (
|
|
2208
|
+
if (H(a, 16, 0, t) === 274) return H(a, 16, 2, t) !== 3 || H(a, 32, 4, t) !== 1 ? void 0 : H(a, 16, 8, t);
|
|
2209
2209
|
}
|
|
2210
2210
|
}
|
|
2211
|
-
function Lr(e, t) {
|
|
2212
|
-
let n = e.slice(kr, t), r = R(n, Ar, 8), i = r === jr;
|
|
2213
|
-
if (i || r === Mr) return Ir(n, i);
|
|
2214
|
-
}
|
|
2215
2211
|
function Rr(e, t) {
|
|
2212
|
+
let n = e.slice(Ar, t), r = L(n, jr, 8), i = r === Mr;
|
|
2213
|
+
if (i || r === Nr) return Lr(n, i);
|
|
2214
|
+
}
|
|
2215
|
+
function zr(e, t) {
|
|
2216
2216
|
if (t > e.length) throw TypeError("Corrupt JPG, exceeded buffer limits");
|
|
2217
2217
|
}
|
|
2218
|
-
var
|
|
2219
|
-
validate: (e) =>
|
|
2218
|
+
var Br = {
|
|
2219
|
+
validate: (e) => L(e, 0, 2) === "ffd8",
|
|
2220
2220
|
calculate(e) {
|
|
2221
2221
|
let t = e.slice(4), n, r;
|
|
2222
2222
|
for (; t.length;) {
|
|
2223
|
-
let e =
|
|
2224
|
-
if (
|
|
2223
|
+
let e = $n(t, 0);
|
|
2224
|
+
if (zr(t, e), t[e] !== 255) {
|
|
2225
2225
|
t = t.slice(1);
|
|
2226
2226
|
continue;
|
|
2227
2227
|
}
|
|
2228
|
-
if (
|
|
2229
|
-
let r =
|
|
2228
|
+
if (Fr(t) && (n = Rr(t, e)), r = t[e + 1], r === 192 || r === 193 || r === 194) {
|
|
2229
|
+
let r = Ir(t, e + 5);
|
|
2230
2230
|
return n ? {
|
|
2231
2231
|
height: r.height,
|
|
2232
2232
|
orientation: n,
|
|
@@ -2237,7 +2237,7 @@ var zr = {
|
|
|
2237
2237
|
}
|
|
2238
2238
|
throw TypeError("Invalid JPG, no size found");
|
|
2239
2239
|
}
|
|
2240
|
-
},
|
|
2240
|
+
}, Vr = class {
|
|
2241
2241
|
input;
|
|
2242
2242
|
endianness;
|
|
2243
2243
|
byteOffset = 2;
|
|
@@ -2264,7 +2264,7 @@ var zr = {
|
|
|
2264
2264
|
};
|
|
2265
2265
|
//#endregion
|
|
2266
2266
|
//#region ../../node_modules/image-size/dist/esm/types/jxl-stream.js
|
|
2267
|
-
function
|
|
2267
|
+
function Hr(e, t) {
|
|
2268
2268
|
if (t) return 8 * (1 + e.getBits(5));
|
|
2269
2269
|
let n = [
|
|
2270
2270
|
9,
|
|
@@ -2274,8 +2274,8 @@ function Vr(e, t) {
|
|
|
2274
2274
|
][e.getBits(2)];
|
|
2275
2275
|
return 1 + e.getBits(n);
|
|
2276
2276
|
}
|
|
2277
|
-
function
|
|
2278
|
-
return t && n === 0 ? 8 * (1 + e.getBits(5)) : n === 0 ?
|
|
2277
|
+
function Ur(e, t, n, r) {
|
|
2278
|
+
return t && n === 0 ? 8 * (1 + e.getBits(5)) : n === 0 ? Hr(e, !1) : Math.floor(r * [
|
|
2279
2279
|
1,
|
|
2280
2280
|
1.2,
|
|
2281
2281
|
4 / 3,
|
|
@@ -2285,82 +2285,82 @@ function Hr(e, t, n, r) {
|
|
|
2285
2285
|
2
|
|
2286
2286
|
][n - 1]);
|
|
2287
2287
|
}
|
|
2288
|
-
var
|
|
2289
|
-
validate: (e) =>
|
|
2288
|
+
var Wr = {
|
|
2289
|
+
validate: (e) => L(e, 0, 2) === "ff0a",
|
|
2290
2290
|
calculate(e) {
|
|
2291
|
-
let t = new
|
|
2291
|
+
let t = new Vr(e, "little-endian"), n = t.getBits(1) === 1, r = Hr(t, n);
|
|
2292
2292
|
return {
|
|
2293
|
-
width:
|
|
2293
|
+
width: Ur(t, n, t.getBits(3), r),
|
|
2294
2294
|
height: r
|
|
2295
2295
|
};
|
|
2296
2296
|
}
|
|
2297
2297
|
};
|
|
2298
2298
|
//#endregion
|
|
2299
2299
|
//#region ../../node_modules/image-size/dist/esm/types/jxl.js
|
|
2300
|
-
function
|
|
2301
|
-
let t =
|
|
2300
|
+
function Gr(e) {
|
|
2301
|
+
let t = U(e, "jxlc", 0);
|
|
2302
2302
|
if (t) return e.slice(t.offset + 8, t.offset + t.size);
|
|
2303
|
-
let n =
|
|
2304
|
-
if (n.length > 0) return
|
|
2303
|
+
let n = Kr(e);
|
|
2304
|
+
if (n.length > 0) return qr(n);
|
|
2305
2305
|
}
|
|
2306
|
-
function
|
|
2306
|
+
function Kr(e) {
|
|
2307
2307
|
let t = [], n = 0;
|
|
2308
2308
|
for (; n < e.length;) {
|
|
2309
|
-
let r =
|
|
2309
|
+
let r = U(e, "jxlp", n);
|
|
2310
2310
|
if (!r) break;
|
|
2311
2311
|
if (r.size < 12) throw TypeError("Invalid JXL");
|
|
2312
2312
|
t.push(e.slice(r.offset + 12, r.offset + r.size)), n = r.offset + r.size;
|
|
2313
2313
|
}
|
|
2314
2314
|
return t;
|
|
2315
2315
|
}
|
|
2316
|
-
function
|
|
2316
|
+
function qr(e) {
|
|
2317
2317
|
let t = e.reduce((e, t) => e + t.length, 0), n = new Uint8Array(t), r = 0;
|
|
2318
2318
|
for (let t of e) n.set(t, r), r += t.length;
|
|
2319
2319
|
return n;
|
|
2320
2320
|
}
|
|
2321
|
-
var
|
|
2321
|
+
var Jr = {
|
|
2322
2322
|
validate: (e) => {
|
|
2323
|
-
if (
|
|
2324
|
-
let t =
|
|
2325
|
-
return t ?
|
|
2323
|
+
if (I(e, 4, 8) !== "JXL ") return !1;
|
|
2324
|
+
let t = U(e, "ftyp", 0);
|
|
2325
|
+
return t ? I(e, t.offset + 8, t.offset + 12) === "jxl " : !1;
|
|
2326
2326
|
},
|
|
2327
2327
|
calculate(e) {
|
|
2328
|
-
let t =
|
|
2329
|
-
if (t) return
|
|
2328
|
+
let t = Gr(e);
|
|
2329
|
+
if (t) return Wr.calculate(t);
|
|
2330
2330
|
throw TypeError("Invalid JXL");
|
|
2331
2331
|
}
|
|
2332
|
-
},
|
|
2332
|
+
}, Yr = {
|
|
2333
2333
|
validate: (e) => {
|
|
2334
|
-
let t =
|
|
2334
|
+
let t = I(e, 1, 7);
|
|
2335
2335
|
return ["KTX 11", "KTX 20"].includes(t);
|
|
2336
2336
|
},
|
|
2337
2337
|
calculate: (e) => {
|
|
2338
2338
|
let t = e[5] === 49 ? "ktx" : "ktx2", n = t === "ktx" ? 36 : 20;
|
|
2339
2339
|
return {
|
|
2340
|
-
height:
|
|
2341
|
-
width:
|
|
2340
|
+
height: V(e, n + 4),
|
|
2341
|
+
width: V(e, n),
|
|
2342
2342
|
type: t
|
|
2343
2343
|
};
|
|
2344
2344
|
}
|
|
2345
|
-
},
|
|
2345
|
+
}, Xr = "PNG\r\n\n", Zr = "IHDR", Qr = "CgBI", $r = {
|
|
2346
2346
|
validate(e) {
|
|
2347
|
-
if (
|
|
2348
|
-
let t =
|
|
2349
|
-
if (t ===
|
|
2347
|
+
if (Xr === I(e, 1, 8)) {
|
|
2348
|
+
let t = I(e, 12, 16);
|
|
2349
|
+
if (t === Qr && (t = I(e, 28, 32)), t !== Zr) throw TypeError("Invalid PNG");
|
|
2350
2350
|
return !0;
|
|
2351
2351
|
}
|
|
2352
2352
|
return !1;
|
|
2353
2353
|
},
|
|
2354
2354
|
calculate(e) {
|
|
2355
|
-
return
|
|
2356
|
-
height:
|
|
2357
|
-
width:
|
|
2355
|
+
return I(e, 12, 16) === Qr ? {
|
|
2356
|
+
height: B(e, 36),
|
|
2357
|
+
width: B(e, 32)
|
|
2358
2358
|
} : {
|
|
2359
|
-
height:
|
|
2360
|
-
width:
|
|
2359
|
+
height: B(e, 20),
|
|
2360
|
+
width: B(e, 16)
|
|
2361
2361
|
};
|
|
2362
2362
|
}
|
|
2363
|
-
},
|
|
2363
|
+
}, ei = {
|
|
2364
2364
|
P1: "pbm/ascii",
|
|
2365
2365
|
P2: "pgm/ascii",
|
|
2366
2366
|
P3: "ppm/ascii",
|
|
@@ -2369,7 +2369,7 @@ var qr = {
|
|
|
2369
2369
|
P6: "ppm",
|
|
2370
2370
|
P7: "pam",
|
|
2371
2371
|
PF: "pfm"
|
|
2372
|
-
},
|
|
2372
|
+
}, ti = {
|
|
2373
2373
|
default: (e) => {
|
|
2374
2374
|
let t = [];
|
|
2375
2375
|
for (; e.length > 0;) {
|
|
@@ -2399,60 +2399,60 @@ var qr = {
|
|
|
2399
2399
|
};
|
|
2400
2400
|
throw TypeError("Invalid PAM");
|
|
2401
2401
|
}
|
|
2402
|
-
},
|
|
2403
|
-
validate: (e) =>
|
|
2402
|
+
}, ni = {
|
|
2403
|
+
validate: (e) => I(e, 0, 2) in ei,
|
|
2404
2404
|
calculate(e) {
|
|
2405
|
-
let t =
|
|
2406
|
-
return (
|
|
2405
|
+
let t = ei[I(e, 0, 2)], n = I(e, 3).split(/[\r\n]+/);
|
|
2406
|
+
return (ti[t] || ti.default)(n);
|
|
2407
2407
|
}
|
|
2408
|
-
},
|
|
2409
|
-
validate: (e) =>
|
|
2408
|
+
}, ri = {
|
|
2409
|
+
validate: (e) => I(e, 0, 4) === "8BPS",
|
|
2410
2410
|
calculate: (e) => ({
|
|
2411
|
-
height:
|
|
2412
|
-
width:
|
|
2411
|
+
height: B(e, 14),
|
|
2412
|
+
width: B(e, 18)
|
|
2413
2413
|
})
|
|
2414
|
-
},
|
|
2414
|
+
}, ii = /<svg\s([^>"']|"[^"]*"|'[^']*')*>/, ai = {
|
|
2415
2415
|
height: /\sheight=(['"])([^%]+?)\1/,
|
|
2416
|
-
root:
|
|
2416
|
+
root: ii,
|
|
2417
2417
|
viewbox: /\sviewBox=(['"])(.+?)\1/i,
|
|
2418
2418
|
width: /\swidth=(['"])([^%]+?)\1/
|
|
2419
|
-
},
|
|
2419
|
+
}, oi = 2.54, si = {
|
|
2420
2420
|
in: 96,
|
|
2421
|
-
cm: 96 /
|
|
2421
|
+
cm: 96 / oi,
|
|
2422
2422
|
em: 16,
|
|
2423
2423
|
ex: 8,
|
|
2424
|
-
m: 96 /
|
|
2425
|
-
mm: 96 /
|
|
2424
|
+
m: 96 / oi * 100,
|
|
2425
|
+
mm: 96 / oi / 10,
|
|
2426
2426
|
pc: 96 / 72 / 12,
|
|
2427
2427
|
pt: 96 / 72,
|
|
2428
2428
|
px: 1
|
|
2429
|
-
},
|
|
2430
|
-
function ci(e) {
|
|
2431
|
-
let t = si.exec(e);
|
|
2432
|
-
if (t) return Math.round(Number(t[1]) * (oi[t[2]] || 1));
|
|
2433
|
-
}
|
|
2429
|
+
}, ci = RegExp(`^([0-9.]+(?:e\\d+)?)(${Object.keys(si).join("|")})?$`);
|
|
2434
2430
|
function li(e) {
|
|
2431
|
+
let t = ci.exec(e);
|
|
2432
|
+
if (t) return Math.round(Number(t[1]) * (si[t[2]] || 1));
|
|
2433
|
+
}
|
|
2434
|
+
function ui(e) {
|
|
2435
2435
|
let t = e.split(" ");
|
|
2436
2436
|
return {
|
|
2437
|
-
height:
|
|
2438
|
-
width:
|
|
2437
|
+
height: li(t[3]),
|
|
2438
|
+
width: li(t[2])
|
|
2439
2439
|
};
|
|
2440
2440
|
}
|
|
2441
|
-
function
|
|
2442
|
-
let t = e.match(
|
|
2441
|
+
function di(e) {
|
|
2442
|
+
let t = e.match(ai.width), n = e.match(ai.height), r = e.match(ai.viewbox);
|
|
2443
2443
|
return {
|
|
2444
|
-
height: n &&
|
|
2445
|
-
viewbox: r &&
|
|
2446
|
-
width: t &&
|
|
2444
|
+
height: n && li(n[2]),
|
|
2445
|
+
viewbox: r && ui(r[2]),
|
|
2446
|
+
width: t && li(t[2])
|
|
2447
2447
|
};
|
|
2448
2448
|
}
|
|
2449
|
-
function
|
|
2449
|
+
function fi(e) {
|
|
2450
2450
|
return {
|
|
2451
2451
|
height: e.height,
|
|
2452
2452
|
width: e.width
|
|
2453
2453
|
};
|
|
2454
2454
|
}
|
|
2455
|
-
function
|
|
2455
|
+
function pi(e, t) {
|
|
2456
2456
|
let n = t.width / t.height;
|
|
2457
2457
|
return e.width ? {
|
|
2458
2458
|
height: Math.floor(e.width / n),
|
|
@@ -2465,28 +2465,28 @@ function fi(e, t) {
|
|
|
2465
2465
|
width: t.width
|
|
2466
2466
|
};
|
|
2467
2467
|
}
|
|
2468
|
-
var
|
|
2469
|
-
validate: (e) =>
|
|
2468
|
+
var mi = {
|
|
2469
|
+
validate: (e) => ii.test(I(e, 0, 1e3)),
|
|
2470
2470
|
calculate(e) {
|
|
2471
|
-
let t =
|
|
2471
|
+
let t = I(e).match(ai.root);
|
|
2472
2472
|
if (t) {
|
|
2473
|
-
let e =
|
|
2474
|
-
if (e.width && e.height) return
|
|
2475
|
-
if (e.viewbox) return
|
|
2473
|
+
let e = di(t[0]);
|
|
2474
|
+
if (e.width && e.height) return fi(e);
|
|
2475
|
+
if (e.viewbox) return pi(e, e.viewbox);
|
|
2476
2476
|
}
|
|
2477
2477
|
throw TypeError("Invalid SVG");
|
|
2478
2478
|
}
|
|
2479
|
-
},
|
|
2479
|
+
}, hi = {
|
|
2480
2480
|
validate(e) {
|
|
2481
|
-
return
|
|
2481
|
+
return z(e, 0) === 0 && z(e, 4) === 0;
|
|
2482
2482
|
},
|
|
2483
2483
|
calculate(e) {
|
|
2484
2484
|
return {
|
|
2485
|
-
height:
|
|
2486
|
-
width:
|
|
2485
|
+
height: z(e, 14),
|
|
2486
|
+
width: z(e, 12)
|
|
2487
2487
|
};
|
|
2488
2488
|
}
|
|
2489
|
-
},
|
|
2489
|
+
}, W = {
|
|
2490
2490
|
TAG: {
|
|
2491
2491
|
WIDTH: 256,
|
|
2492
2492
|
HEIGHT: 257,
|
|
@@ -2506,129 +2506,129 @@ var pi = {
|
|
|
2506
2506
|
BIG: 8
|
|
2507
2507
|
}
|
|
2508
2508
|
};
|
|
2509
|
-
function
|
|
2510
|
-
let r = n ? Number(
|
|
2509
|
+
function gi(e, { isBigEndian: t, isBigTiff: n }) {
|
|
2510
|
+
let r = n ? Number(nr(e, 8, t)) : H(e, 32, 4, t), i = n ? W.COUNT_SIZE.BIG : W.COUNT_SIZE.STANDARD;
|
|
2511
2511
|
return e.slice(r + i);
|
|
2512
2512
|
}
|
|
2513
|
-
function
|
|
2513
|
+
function _i(e, t, n, r) {
|
|
2514
2514
|
switch (t) {
|
|
2515
|
-
case
|
|
2516
|
-
case
|
|
2517
|
-
case
|
|
2518
|
-
let t = Number(
|
|
2515
|
+
case W.TYPE.SHORT: return H(e, 16, n, r);
|
|
2516
|
+
case W.TYPE.LONG: return H(e, 32, n, r);
|
|
2517
|
+
case W.TYPE.LONG8: {
|
|
2518
|
+
let t = Number(nr(e, n, r));
|
|
2519
2519
|
if (t > 2 ** 53 - 1) throw TypeError("Value too large");
|
|
2520
2520
|
return t;
|
|
2521
2521
|
}
|
|
2522
2522
|
default: return 0;
|
|
2523
2523
|
}
|
|
2524
2524
|
}
|
|
2525
|
-
function
|
|
2526
|
-
let n = t ?
|
|
2525
|
+
function vi(e, t) {
|
|
2526
|
+
let n = t ? W.ENTRY_SIZE.BIG : W.ENTRY_SIZE.STANDARD;
|
|
2527
2527
|
if (e.length > n) return e.slice(n);
|
|
2528
2528
|
}
|
|
2529
|
-
function
|
|
2529
|
+
function yi(e, { isBigEndian: t, isBigTiff: n }) {
|
|
2530
2530
|
let r = {}, i = e;
|
|
2531
2531
|
for (; i?.length;) {
|
|
2532
|
-
let e =
|
|
2532
|
+
let e = H(i, 16, 0, t), a = H(i, 16, 2, t), o = n ? Number(nr(i, 4, t)) : H(i, 32, 4, t);
|
|
2533
2533
|
if (e === 0) break;
|
|
2534
|
-
o === 1 && (a ===
|
|
2534
|
+
o === 1 && (a === W.TYPE.SHORT || a === W.TYPE.LONG || n && a === W.TYPE.LONG8) && (r[e] = _i(i, a, n ? 12 : 8, t)), i = vi(i, n);
|
|
2535
2535
|
}
|
|
2536
2536
|
return r;
|
|
2537
2537
|
}
|
|
2538
|
-
function
|
|
2539
|
-
let t =
|
|
2538
|
+
function bi(e) {
|
|
2539
|
+
let t = I(e, 0, 2), n = H(e, 16, 2, t === "MM");
|
|
2540
2540
|
return {
|
|
2541
2541
|
isBigEndian: t === "MM",
|
|
2542
2542
|
isBigTiff: n === 43
|
|
2543
2543
|
};
|
|
2544
2544
|
}
|
|
2545
|
-
function
|
|
2546
|
-
let n =
|
|
2545
|
+
function xi(e, t) {
|
|
2546
|
+
let n = H(e, 16, 4, t), r = H(e, 16, 6, t);
|
|
2547
2547
|
if (n !== 8 || r !== 0) throw TypeError("Invalid BigTIFF header");
|
|
2548
2548
|
}
|
|
2549
|
-
var
|
|
2549
|
+
var Si = /* @__PURE__ */ new Set([
|
|
2550
2550
|
"49492a00",
|
|
2551
2551
|
"4d4d002a",
|
|
2552
2552
|
"49492b00",
|
|
2553
2553
|
"4d4d002b"
|
|
2554
|
-
]),
|
|
2554
|
+
]), Ci = {
|
|
2555
2555
|
validate: (e) => {
|
|
2556
|
-
let t =
|
|
2557
|
-
return
|
|
2556
|
+
let t = L(e, 0, 4);
|
|
2557
|
+
return Si.has(t);
|
|
2558
2558
|
},
|
|
2559
2559
|
calculate(e) {
|
|
2560
|
-
let t =
|
|
2561
|
-
t.isBigTiff &&
|
|
2562
|
-
let n =
|
|
2563
|
-
height: n[
|
|
2564
|
-
width: n[
|
|
2560
|
+
let t = bi(e);
|
|
2561
|
+
t.isBigTiff && xi(e, t.isBigEndian);
|
|
2562
|
+
let n = yi(gi(e, t), t), r = {
|
|
2563
|
+
height: n[W.TAG.HEIGHT],
|
|
2564
|
+
width: n[W.TAG.WIDTH],
|
|
2565
2565
|
type: t.isBigTiff ? "bigtiff" : "tiff"
|
|
2566
2566
|
};
|
|
2567
|
-
if (n[
|
|
2567
|
+
if (n[W.TAG.COMPRESSION] && (r.compression = n[W.TAG.COMPRESSION]), !r.width || !r.height) throw TypeError("Invalid Tiff. Missing tags");
|
|
2568
2568
|
return r;
|
|
2569
2569
|
}
|
|
2570
2570
|
};
|
|
2571
2571
|
//#endregion
|
|
2572
2572
|
//#region ../../node_modules/image-size/dist/esm/types/webp.js
|
|
2573
|
-
function
|
|
2573
|
+
function wi(e) {
|
|
2574
2574
|
return {
|
|
2575
|
-
height: 1 +
|
|
2576
|
-
width: 1 +
|
|
2575
|
+
height: 1 + er(e, 7),
|
|
2576
|
+
width: 1 + er(e, 4)
|
|
2577
2577
|
};
|
|
2578
2578
|
}
|
|
2579
|
-
function
|
|
2579
|
+
function Ti(e) {
|
|
2580
2580
|
return {
|
|
2581
2581
|
height: 1 + ((e[4] & 15) << 10 | e[3] << 2 | (e[2] & 192) >> 6),
|
|
2582
2582
|
width: 1 + ((e[2] & 63) << 8 | e[1])
|
|
2583
2583
|
};
|
|
2584
2584
|
}
|
|
2585
|
-
function
|
|
2585
|
+
function Ei(e) {
|
|
2586
2586
|
return {
|
|
2587
|
-
height:
|
|
2588
|
-
width:
|
|
2587
|
+
height: Qn(e, 8) & 16383,
|
|
2588
|
+
width: Qn(e, 6) & 16383
|
|
2589
2589
|
};
|
|
2590
2590
|
}
|
|
2591
2591
|
//#endregion
|
|
2592
2592
|
//#region ../../node_modules/image-size/dist/esm/types/index.js
|
|
2593
|
-
var
|
|
2594
|
-
["bmp",
|
|
2595
|
-
["cur",
|
|
2596
|
-
["dds",
|
|
2597
|
-
["gif",
|
|
2598
|
-
["heif",
|
|
2599
|
-
["icns",
|
|
2600
|
-
["ico",
|
|
2601
|
-
["j2c",
|
|
2602
|
-
["jp2",
|
|
2603
|
-
["jpg",
|
|
2604
|
-
["jxl",
|
|
2605
|
-
["jxl-stream",
|
|
2606
|
-
["ktx",
|
|
2607
|
-
["png",
|
|
2608
|
-
["pnm",
|
|
2609
|
-
["psd",
|
|
2610
|
-
["svg",
|
|
2611
|
-
["tga",
|
|
2612
|
-
["tiff",
|
|
2593
|
+
var Di = /* @__PURE__ */ new Map([
|
|
2594
|
+
["bmp", or],
|
|
2595
|
+
["cur", mr],
|
|
2596
|
+
["dds", hr],
|
|
2597
|
+
["gif", _r],
|
|
2598
|
+
["heif", yr],
|
|
2599
|
+
["icns", Er],
|
|
2600
|
+
["ico", fr],
|
|
2601
|
+
["j2c", Dr],
|
|
2602
|
+
["jp2", Or],
|
|
2603
|
+
["jpg", Br],
|
|
2604
|
+
["jxl", Jr],
|
|
2605
|
+
["jxl-stream", Wr],
|
|
2606
|
+
["ktx", Yr],
|
|
2607
|
+
["png", $r],
|
|
2608
|
+
["pnm", ni],
|
|
2609
|
+
["psd", ri],
|
|
2610
|
+
["svg", mi],
|
|
2611
|
+
["tga", hi],
|
|
2612
|
+
["tiff", Ci],
|
|
2613
2613
|
["webp", {
|
|
2614
2614
|
validate(e) {
|
|
2615
|
-
let t =
|
|
2615
|
+
let t = I(e, 0, 4) === "RIFF", n = I(e, 8, 12) === "WEBP", r = I(e, 12, 15) === "VP8";
|
|
2616
2616
|
return t && n && r;
|
|
2617
2617
|
},
|
|
2618
2618
|
calculate(e) {
|
|
2619
|
-
let t =
|
|
2619
|
+
let t = I(e, 12, 16), n = e.slice(20, 30);
|
|
2620
2620
|
if (t === "VP8X") {
|
|
2621
2621
|
let e = n[0], t = (e & 192) == 0, r = (e & 1) == 0;
|
|
2622
|
-
if (t && r) return
|
|
2622
|
+
if (t && r) return wi(n);
|
|
2623
2623
|
throw TypeError("Invalid WebP");
|
|
2624
2624
|
}
|
|
2625
|
-
if (t === "VP8 " && n[0] !== 47) return
|
|
2626
|
-
let r =
|
|
2627
|
-
if (t === "VP8L" && r !== "9d012a") return
|
|
2625
|
+
if (t === "VP8 " && n[0] !== 47) return Ei(n);
|
|
2626
|
+
let r = L(n, 3, 6);
|
|
2627
|
+
if (t === "VP8L" && r !== "9d012a") return Ti(n);
|
|
2628
2628
|
throw TypeError("Invalid WebP");
|
|
2629
2629
|
}
|
|
2630
2630
|
}]
|
|
2631
|
-
]),
|
|
2631
|
+
]), Oi = Array.from(Di.keys()), ki = /* @__PURE__ */ new Map([
|
|
2632
2632
|
[0, "heif"],
|
|
2633
2633
|
[56, "psd"],
|
|
2634
2634
|
[66, "bmp"],
|
|
@@ -2641,18 +2641,18 @@ var Ei = /* @__PURE__ */ new Map([
|
|
|
2641
2641
|
[137, "png"],
|
|
2642
2642
|
[255, "jpg"]
|
|
2643
2643
|
]);
|
|
2644
|
-
function
|
|
2645
|
-
let t = e[0], n =
|
|
2646
|
-
return n &&
|
|
2644
|
+
function Ai(e) {
|
|
2645
|
+
let t = e[0], n = ki.get(t);
|
|
2646
|
+
return n && Di.get(n)?.validate(e) ? n : Oi.find((t) => Di.get(t)?.validate(e));
|
|
2647
2647
|
}
|
|
2648
2648
|
//#endregion
|
|
2649
2649
|
//#region ../../node_modules/image-size/dist/esm/lookup.js
|
|
2650
|
-
var
|
|
2651
|
-
function
|
|
2652
|
-
let t =
|
|
2650
|
+
var ji = { disabledTypes: [] };
|
|
2651
|
+
function Mi(e) {
|
|
2652
|
+
let t = Ai(e);
|
|
2653
2653
|
if (t !== void 0) {
|
|
2654
|
-
if (
|
|
2655
|
-
let n =
|
|
2654
|
+
if (ji.disabledTypes.indexOf(t) > -1) throw TypeError(`disabled file type: ${t}`);
|
|
2655
|
+
let n = Di.get(t)?.calculate(e);
|
|
2656
2656
|
if (n !== void 0) {
|
|
2657
2657
|
if (n.type = n.type ?? t, n.images && n.images.length > 1) {
|
|
2658
2658
|
let e = n.images.reduce((e, t) => t.width * t.height > e.width * e.height ? t : e, n.images[0]);
|
|
@@ -2665,7 +2665,7 @@ function ji(e) {
|
|
|
2665
2665
|
}
|
|
2666
2666
|
//#endregion
|
|
2667
2667
|
//#region src/node/conversation-content-transport.ts
|
|
2668
|
-
var
|
|
2668
|
+
var Ni = class {
|
|
2669
2669
|
conversationId;
|
|
2670
2670
|
cache = /* @__PURE__ */ new WeakMap();
|
|
2671
2671
|
constructor(e) {
|
|
@@ -2680,7 +2680,7 @@ var Mi = class {
|
|
|
2680
2680
|
if (!Number.isSafeInteger(n) || n < 0 || n >= r.byteLength) throw Error("Invalid content offset.");
|
|
2681
2681
|
let i = Math.min(r.byteLength, n + 64 * 1024);
|
|
2682
2682
|
return {
|
|
2683
|
-
data:
|
|
2683
|
+
data: Pi(r, n, i).toString("base64"),
|
|
2684
2684
|
totalBytes: r.byteLength,
|
|
2685
2685
|
nextOffset: i < r.byteLength ? i : null
|
|
2686
2686
|
};
|
|
@@ -2699,13 +2699,13 @@ var Mi = class {
|
|
|
2699
2699
|
].includes(a ?? "") && /^data:image\/[a-z0-9.+-]+;base64,[a-z\d+/]+=*$/i.test(e)) {
|
|
2700
2700
|
let i = n.get(e);
|
|
2701
2701
|
if (!i) {
|
|
2702
|
-
let a =
|
|
2702
|
+
let a = Ii(e);
|
|
2703
2703
|
t.set(a, {
|
|
2704
2704
|
text: e,
|
|
2705
2705
|
byteLength: e.length,
|
|
2706
2706
|
charOffset: 0,
|
|
2707
2707
|
byteOffset: 0
|
|
2708
|
-
}), i = `conversation-image:${encodeURIComponent(this.conversationId)}:${a}`, n.set(e, i), r.set(i,
|
|
2708
|
+
}), i = `conversation-image:${encodeURIComponent(this.conversationId)}:${a}`, n.set(e, i), r.set(i, Li(e));
|
|
2709
2709
|
}
|
|
2710
2710
|
return i;
|
|
2711
2711
|
}
|
|
@@ -2716,7 +2716,7 @@ var Mi = class {
|
|
|
2716
2716
|
"update",
|
|
2717
2717
|
"delete"
|
|
2718
2718
|
].includes(String(o.kind?.type)) && typeof o.diff == "string" && o.diff.length > 0) {
|
|
2719
|
-
let n = Buffer.byteLength(o.diff), r =
|
|
2719
|
+
let n = Buffer.byteLength(o.diff), r = Ii(o.diff);
|
|
2720
2720
|
return t.set(r, {
|
|
2721
2721
|
text: o.diff,
|
|
2722
2722
|
byteLength: n,
|
|
@@ -2748,32 +2748,32 @@ var Mi = class {
|
|
|
2748
2748
|
return e && typeof e == "object" && this.cache.set(e, a), a;
|
|
2749
2749
|
}
|
|
2750
2750
|
};
|
|
2751
|
-
function
|
|
2751
|
+
function Pi(e, t, n) {
|
|
2752
2752
|
if (e.byteLength === e.text.length) return Buffer.from(e.text.slice(t, n));
|
|
2753
2753
|
t < e.byteOffset && (e.charOffset = 0, e.byteOffset = 0);
|
|
2754
2754
|
let r = [];
|
|
2755
2755
|
for (; e.byteOffset < n;) {
|
|
2756
|
-
let i =
|
|
2756
|
+
let i = Fi(e.text, e.charOffset), a = e.text.slice(e.charOffset, i), o = e.byteOffset + Buffer.byteLength(a);
|
|
2757
2757
|
if (o > t && r.push(Buffer.from(a).subarray(Math.max(0, t - e.byteOffset), Math.min(o, n) - e.byteOffset)), o >= n) break;
|
|
2758
2758
|
e.charOffset = i, e.byteOffset = o;
|
|
2759
2759
|
}
|
|
2760
2760
|
return Buffer.concat(r, n - t);
|
|
2761
2761
|
}
|
|
2762
|
-
function
|
|
2762
|
+
function Fi(e, t) {
|
|
2763
2763
|
let n = Math.min(e.length, t + 16 * 1024), r = e.charCodeAt(n - 1);
|
|
2764
2764
|
return n < e.length && r >= 55296 && r <= 56319 ? n - 1 : n;
|
|
2765
2765
|
}
|
|
2766
|
-
function
|
|
2767
|
-
let t =
|
|
2766
|
+
function Ii(e) {
|
|
2767
|
+
let t = ee("sha256");
|
|
2768
2768
|
for (let n = 0; n < e.length;) {
|
|
2769
|
-
let r =
|
|
2769
|
+
let r = Fi(e, n);
|
|
2770
2770
|
t.update(e.slice(n, r)), n = r;
|
|
2771
2771
|
}
|
|
2772
2772
|
return t.digest("hex");
|
|
2773
2773
|
}
|
|
2774
|
-
function
|
|
2774
|
+
function Li(e) {
|
|
2775
2775
|
try {
|
|
2776
|
-
let t = e.indexOf(",") + 1, { width: n, height: r, orientation: i } =
|
|
2776
|
+
let t = e.indexOf(",") + 1, { width: n, height: r, orientation: i } = Mi(Buffer.from(e.slice(t, t + 64 * 1024), "base64"));
|
|
2777
2777
|
return !Number.isSafeInteger(n) || !Number.isSafeInteger(r) || n <= 0 || r <= 0 ? void 0 : i && i >= 5 && i <= 8 ? {
|
|
2778
2778
|
width: r,
|
|
2779
2779
|
height: n
|
|
@@ -2787,7 +2787,7 @@ function Ii(e) {
|
|
|
2787
2787
|
}
|
|
2788
2788
|
//#endregion
|
|
2789
2789
|
//#region src/node/codex-original-history-images.ts
|
|
2790
|
-
var
|
|
2790
|
+
var Ri = 32 * 1024 * 1024, zi = 20 * 1024 * 1024, Bi = 2048, Vi = class {
|
|
2791
2791
|
client;
|
|
2792
2792
|
paths = /* @__PURE__ */ new Map();
|
|
2793
2793
|
indexes = /* @__PURE__ */ new Map();
|
|
@@ -2844,13 +2844,13 @@ var Li = 32 * 1024 * 1024, Ri = 20 * 1024 * 1024, zi = 2048, Bi = class {
|
|
|
2844
2844
|
let r = await this.index(e), i = r.images.get(t);
|
|
2845
2845
|
if (!i) throw Error("Original conversation image is no longer available.");
|
|
2846
2846
|
if (!Number.isSafeInteger(n) || n < 0 || n >= i.byteLength) throw Error("Invalid content offset.");
|
|
2847
|
-
let a =
|
|
2847
|
+
let a = Gi(await ce(r.path));
|
|
2848
2848
|
if (this.disposed || this.paths.get(e) !== r.path) throw Error("Conversation image reader was released.");
|
|
2849
2849
|
let o = this.images.get(t), s = o?.signature === a ? o.url : void 0;
|
|
2850
2850
|
if (this.images.delete(t), !s) {
|
|
2851
2851
|
let t = await oe(r.path, "r");
|
|
2852
2852
|
try {
|
|
2853
|
-
await
|
|
2853
|
+
await Ki(t, e);
|
|
2854
2854
|
let n = Buffer.alloc(i.length);
|
|
2855
2855
|
for (let e = 0; e < n.length;) {
|
|
2856
2856
|
let r = await t.read(n, e, Math.min(64 * 1024, n.length - e), i.offset + e);
|
|
@@ -2858,9 +2858,9 @@ var Li = 32 * 1024 * 1024, Ri = 20 * 1024 * 1024, zi = 2048, Bi = class {
|
|
|
2858
2858
|
e += r.bytesRead;
|
|
2859
2859
|
}
|
|
2860
2860
|
let a = JSON.parse(n.toString("utf8")), o = a.payload;
|
|
2861
|
-
if (a.type !== "response_item" || o?.type !== "custom_tool_call_output" || o.call_id !== i.callId ||
|
|
2862
|
-
let c = o.output[i.imageIndex], l =
|
|
2863
|
-
if (!l ||
|
|
2861
|
+
if (a.type !== "response_item" || o?.type !== "custom_tool_call_output" || o.call_id !== i.callId || Hi(o) !== i.turnId || !Array.isArray(o.output)) throw Error("Original image identity changed.");
|
|
2862
|
+
let c = o.output[i.imageIndex], l = Ui(c);
|
|
2863
|
+
if (!l || Wi(l) !== i.hash) throw Error("Original image bytes changed.");
|
|
2864
2864
|
if (s = l, this.disposed || this.paths.get(e) !== r.path) throw Error("Conversation image reader was released.");
|
|
2865
2865
|
} finally {
|
|
2866
2866
|
await t.close();
|
|
@@ -2869,7 +2869,7 @@ var Li = 32 * 1024 * 1024, Ri = 20 * 1024 * 1024, zi = 2048, Bi = class {
|
|
|
2869
2869
|
for (this.images.set(t, {
|
|
2870
2870
|
signature: a,
|
|
2871
2871
|
url: s
|
|
2872
|
-
}); this.images.size > 2 || [...this.images.values()].reduce((e, t) => e + t.url.length, 0) >
|
|
2872
|
+
}); this.images.size > 2 || [...this.images.values()].reduce((e, t) => e + t.url.length, 0) > zi;) this.images.delete(this.images.keys().next().value);
|
|
2873
2873
|
let c = Math.min(s.length, n + 64 * 1024);
|
|
2874
2874
|
return {
|
|
2875
2875
|
data: Buffer.from(s.slice(n, c)).toString("base64"),
|
|
@@ -2891,14 +2891,14 @@ var Li = 32 * 1024 * 1024, Ri = 20 * 1024 * 1024, zi = 2048, Bi = class {
|
|
|
2891
2891
|
}
|
|
2892
2892
|
let n = await ce(t);
|
|
2893
2893
|
if (!n.isFile()) throw Error("Original history is not a file.");
|
|
2894
|
-
let r =
|
|
2894
|
+
let r = Gi(n), i = this.indexes.get(e);
|
|
2895
2895
|
if (i?.signature === r) return i;
|
|
2896
2896
|
let a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = await oe(t, "r");
|
|
2897
2897
|
try {
|
|
2898
|
-
await
|
|
2898
|
+
await Ki(s, e);
|
|
2899
2899
|
let t = 0;
|
|
2900
|
-
for await (let r of
|
|
2901
|
-
if (++t > 1e5 || a.size >=
|
|
2900
|
+
for await (let r of qi(s, n.size)) {
|
|
2901
|
+
if (++t > 1e5 || a.size >= Bi) break;
|
|
2902
2902
|
let n;
|
|
2903
2903
|
try {
|
|
2904
2904
|
n = JSON.parse(r.text);
|
|
@@ -2907,7 +2907,7 @@ var Li = 32 * 1024 * 1024, Ri = 20 * 1024 * 1024, zi = 2048, Bi = class {
|
|
|
2907
2907
|
}
|
|
2908
2908
|
let i = n?.payload;
|
|
2909
2909
|
if (n?.type !== "response_item" || !i || typeof i.call_id != "string" || !i.call_id || i.call_id.length > 256) continue;
|
|
2910
|
-
let s =
|
|
2910
|
+
let s = Hi(i);
|
|
2911
2911
|
if (s) {
|
|
2912
2912
|
if (i.type === "custom_tool_call") {
|
|
2913
2913
|
o.size < 4096 && o.set(i.call_id, s);
|
|
@@ -2915,10 +2915,10 @@ var Li = 32 * 1024 * 1024, Ri = 20 * 1024 * 1024, zi = 2048, Bi = class {
|
|
|
2915
2915
|
}
|
|
2916
2916
|
if (!(i.type !== "custom_tool_call_output" || o.get(i.call_id) !== s || !Array.isArray(i.output))) {
|
|
2917
2917
|
o.delete(i.call_id);
|
|
2918
|
-
for (let t = 0; t < Math.min(i.output.length, 256) && a.size <
|
|
2919
|
-
let n =
|
|
2918
|
+
for (let t = 0; t < Math.min(i.output.length, 256) && a.size < Bi; t++) {
|
|
2919
|
+
let n = Ui(i.output[t]);
|
|
2920
2920
|
if (!n) continue;
|
|
2921
|
-
let o =
|
|
2921
|
+
let o = Wi(n), c = Wi(JSON.stringify([
|
|
2922
2922
|
e,
|
|
2923
2923
|
s,
|
|
2924
2924
|
i.call_id,
|
|
@@ -2942,7 +2942,7 @@ var Li = 32 * 1024 * 1024, Ri = 20 * 1024 * 1024, zi = 2048, Bi = class {
|
|
|
2942
2942
|
mimeType: n.slice(5, n.indexOf(";")),
|
|
2943
2943
|
title: "Recorded tool image",
|
|
2944
2944
|
alt: "Recorded tool image",
|
|
2945
|
-
...
|
|
2945
|
+
...Li(n)
|
|
2946
2946
|
}
|
|
2947
2947
|
}
|
|
2948
2948
|
});
|
|
@@ -2963,24 +2963,24 @@ var Li = 32 * 1024 * 1024, Ri = 20 * 1024 * 1024, zi = 2048, Bi = class {
|
|
|
2963
2963
|
return c;
|
|
2964
2964
|
}
|
|
2965
2965
|
};
|
|
2966
|
-
function
|
|
2966
|
+
function Hi(e) {
|
|
2967
2967
|
let t = e.internal_chat_message_metadata_passthrough;
|
|
2968
2968
|
return t && typeof t == "object" && "turn_id" in t && typeof t.turn_id == "string" && t.turn_id.length <= 256 ? t.turn_id : void 0;
|
|
2969
2969
|
}
|
|
2970
|
-
function Hi(e) {
|
|
2971
|
-
if (!(!e || typeof e != "object" || !("type" in e) || e.type !== "input_image" || !("image_url" in e) || typeof e.image_url != "string" || e.image_url.length > Ri)) return Wn(e.image_url)?.url;
|
|
2972
|
-
}
|
|
2973
2970
|
function Ui(e) {
|
|
2974
|
-
|
|
2971
|
+
if (!(!e || typeof e != "object" || !("type" in e) || e.type !== "input_image" || !("image_url" in e) || typeof e.image_url != "string" || e.image_url.length > zi)) return Gn(e.image_url)?.url;
|
|
2975
2972
|
}
|
|
2976
2973
|
function Wi(e) {
|
|
2974
|
+
return ee("sha256").update(e).digest("hex");
|
|
2975
|
+
}
|
|
2976
|
+
function Gi(e) {
|
|
2977
2977
|
return `${e.dev}:${e.ino}:${e.size}:${e.mtimeMs}`;
|
|
2978
2978
|
}
|
|
2979
|
-
async function
|
|
2979
|
+
async function Ki(e, t) {
|
|
2980
2980
|
let n = Buffer.alloc(64 * 1024), { bytesRead: r } = await e.read(n, 0, n.length, 0), i = n.subarray(0, r).toString("utf8").split("\n", 1)[0], a = JSON.parse(i);
|
|
2981
2981
|
if (a?.type !== "session_meta" || a.payload?.id !== t) throw Error("Original history belongs to a different conversation.");
|
|
2982
2982
|
}
|
|
2983
|
-
async function*
|
|
2983
|
+
async function* qi(e, t) {
|
|
2984
2984
|
let n = 0, r = 0, i = 0, a = [];
|
|
2985
2985
|
for (; n < t;) {
|
|
2986
2986
|
let o = Buffer.alloc(Math.min(64 * 1024, t - n)), { bytesRead: s } = await e.read(o, 0, o.length, n);
|
|
@@ -2988,7 +2988,7 @@ async function* Ki(e, t) {
|
|
|
2988
2988
|
let c = 0;
|
|
2989
2989
|
for (; c < s;) {
|
|
2990
2990
|
let e = o.indexOf(10, c), t = e < 0 || e >= s ? s : e, l = o.subarray(c, t);
|
|
2991
|
-
i += l.length, i <=
|
|
2991
|
+
i += l.length, i <= Ri ? a.push(l) : a = [], e >= 0 && e < s && (i <= Ri && (yield {
|
|
2992
2992
|
offset: r,
|
|
2993
2993
|
length: i,
|
|
2994
2994
|
text: Buffer.concat(a, i).toString("utf8")
|
|
@@ -2997,7 +2997,7 @@ async function* Ki(e, t) {
|
|
|
2997
2997
|
n += s;
|
|
2998
2998
|
}
|
|
2999
2999
|
}
|
|
3000
|
-
function
|
|
3000
|
+
function Ji(e) {
|
|
3001
3001
|
return e.map((e) => {
|
|
3002
3002
|
let t = new Set(e.parts.filter((e) => e.type === "tool" && e.title === "view_image").map((e) => e.type === "tool" ? e.id : ""));
|
|
3003
3003
|
return t.size ? {
|
|
@@ -3008,7 +3008,7 @@ function qi(e) {
|
|
|
3008
3008
|
}
|
|
3009
3009
|
//#endregion
|
|
3010
3010
|
//#region src/node/codex-surface-usage-controller.ts
|
|
3011
|
-
var
|
|
3011
|
+
var Yi = {
|
|
3012
3012
|
status: "unavailable",
|
|
3013
3013
|
reason: "public-runtime-request-evidence-unavailable",
|
|
3014
3014
|
unavailableFields: [
|
|
@@ -3026,7 +3026,7 @@ var Ji = {
|
|
|
3026
3026
|
"finality"
|
|
3027
3027
|
],
|
|
3028
3028
|
requests: null
|
|
3029
|
-
},
|
|
3029
|
+
}, Xi = class {
|
|
3030
3030
|
threads = /* @__PURE__ */ new Map();
|
|
3031
3031
|
clear() {
|
|
3032
3032
|
this.threads.clear();
|
|
@@ -3034,7 +3034,7 @@ var Ji = {
|
|
|
3034
3034
|
recover(e, t, n) {
|
|
3035
3035
|
let r = this.threads.get(e)?.executions.get(t);
|
|
3036
3036
|
if (!r) return;
|
|
3037
|
-
let i = r.latest ?
|
|
3037
|
+
let i = r.latest ? $i(n.total, r.latest.total) : null, a = i ? ea(n.execution, i) ?? n.execution : n.execution, o = i ? r.latest.total : n.total, s = i ? r.latest.last : n.last;
|
|
3038
3038
|
r.native = structuredClone({
|
|
3039
3039
|
total: o,
|
|
3040
3040
|
execution: a
|
|
@@ -3047,7 +3047,7 @@ var Ji = {
|
|
|
3047
3047
|
}),
|
|
3048
3048
|
observedStart: !0,
|
|
3049
3049
|
model: r.latest?.model ?? null,
|
|
3050
|
-
requestUsage: structuredClone(
|
|
3050
|
+
requestUsage: structuredClone(Yi)
|
|
3051
3051
|
};
|
|
3052
3052
|
return r.latest = structuredClone(c), c;
|
|
3053
3053
|
}
|
|
@@ -3088,16 +3088,16 @@ var Ji = {
|
|
|
3088
3088
|
let e = r.executions.get(r.activeTurnId);
|
|
3089
3089
|
e && (e.baseline = null, e.native = void 0), i && (i.baseline = null, i.native = void 0);
|
|
3090
3090
|
}
|
|
3091
|
-
i && (!
|
|
3092
|
-
let s = i?.native ?
|
|
3091
|
+
i && (!G(a.total) || i.latest && !Qi(i.latest.total, a.total)) && (i.baseline = null, i.native = void 0);
|
|
3092
|
+
let s = i?.native ? $i(i.native.total, a.total) : null, c = i?.native && s ? ea(i.native.execution, s) : i?.baseline ? $i(i.baseline, a.total) : null;
|
|
3093
3093
|
i && c === null && (i.baseline = null);
|
|
3094
3094
|
let l = {
|
|
3095
3095
|
...a,
|
|
3096
3096
|
execution: c,
|
|
3097
3097
|
observedStart: !!i,
|
|
3098
|
-
requestUsage: structuredClone(
|
|
3098
|
+
requestUsage: structuredClone(Yi)
|
|
3099
3099
|
};
|
|
3100
|
-
return i && (i.latest = structuredClone(l)), r.total = !o &&
|
|
3100
|
+
return i && (i.latest = structuredClone(l)), r.total = !o && G(a.total) ? structuredClone(a.total) : null, r.lastUsageTurnId = t.turnId, {
|
|
3101
3101
|
...t,
|
|
3102
3102
|
payload: { usage: l }
|
|
3103
3103
|
};
|
|
@@ -3111,21 +3111,21 @@ var Ji = {
|
|
|
3111
3111
|
executions: /* @__PURE__ */ new Map()
|
|
3112
3112
|
}, this.threads.set(e, t)), t;
|
|
3113
3113
|
}
|
|
3114
|
-
},
|
|
3114
|
+
}, Zi = [
|
|
3115
3115
|
"totalTokens",
|
|
3116
3116
|
"inputTokens",
|
|
3117
3117
|
"cachedInputTokens",
|
|
3118
3118
|
"outputTokens",
|
|
3119
3119
|
"reasoningOutputTokens"
|
|
3120
3120
|
];
|
|
3121
|
-
function
|
|
3122
|
-
return
|
|
3123
|
-
}
|
|
3124
|
-
function Zi(e, t) {
|
|
3125
|
-
return Xi.every((n) => t[n] >= e[n]) && (e.cacheWriteInputTokens === null || t.cacheWriteInputTokens === null || t.cacheWriteInputTokens >= e.cacheWriteInputTokens);
|
|
3121
|
+
function G(e) {
|
|
3122
|
+
return Zi.every((t) => Number.isSafeInteger(e[t]) && e[t] >= 0) && (e.cacheWriteInputTokens === null || Number.isSafeInteger(e.cacheWriteInputTokens) && e.cacheWriteInputTokens >= 0) && e.totalTokens === e.inputTokens + e.outputTokens && e.cachedInputTokens <= e.inputTokens && e.reasoningOutputTokens <= e.outputTokens;
|
|
3126
3123
|
}
|
|
3127
3124
|
function Qi(e, t) {
|
|
3128
|
-
|
|
3125
|
+
return Zi.every((n) => t[n] >= e[n]) && (e.cacheWriteInputTokens === null || t.cacheWriteInputTokens === null || t.cacheWriteInputTokens >= e.cacheWriteInputTokens);
|
|
3126
|
+
}
|
|
3127
|
+
function $i(e, t) {
|
|
3128
|
+
if (!G(e) || !G(t) || !Qi(e, t)) return null;
|
|
3129
3129
|
let n = {
|
|
3130
3130
|
totalTokens: t.totalTokens - e.totalTokens,
|
|
3131
3131
|
inputTokens: t.inputTokens - e.inputTokens,
|
|
@@ -3134,15 +3134,15 @@ function Qi(e, t) {
|
|
|
3134
3134
|
outputTokens: t.outputTokens - e.outputTokens,
|
|
3135
3135
|
reasoningOutputTokens: t.reasoningOutputTokens - e.reasoningOutputTokens
|
|
3136
3136
|
};
|
|
3137
|
-
return
|
|
3137
|
+
return G(n) ? n : null;
|
|
3138
3138
|
}
|
|
3139
|
-
function
|
|
3140
|
-
let n = Object.fromEntries(
|
|
3141
|
-
return n.cacheWriteInputTokens = e.cacheWriteInputTokens === null || t.cacheWriteInputTokens === null ? null : e.cacheWriteInputTokens + t.cacheWriteInputTokens,
|
|
3139
|
+
function ea(e, t) {
|
|
3140
|
+
let n = Object.fromEntries(Zi.map((n) => [n, e[n] + t[n]]));
|
|
3141
|
+
return n.cacheWriteInputTokens = e.cacheWriteInputTokens === null || t.cacheWriteInputTokens === null ? null : e.cacheWriteInputTokens + t.cacheWriteInputTokens, G(n) ? n : null;
|
|
3142
3142
|
}
|
|
3143
3143
|
//#endregion
|
|
3144
3144
|
//#region src/node/codex-original-history-usage.ts
|
|
3145
|
-
var
|
|
3145
|
+
var ta = 1024 * 1024, na = class {
|
|
3146
3146
|
client;
|
|
3147
3147
|
indexes = /* @__PURE__ */ new Map();
|
|
3148
3148
|
work = Promise.resolve();
|
|
@@ -3198,10 +3198,10 @@ var ea = 1024 * 1024, ta = class {
|
|
|
3198
3198
|
for (let n = 0; n < s; n++) {
|
|
3199
3199
|
if (o[n] !== 10) continue;
|
|
3200
3200
|
let r = o.subarray(c, n);
|
|
3201
|
-
!a && i.length + r.length <=
|
|
3201
|
+
!a && i.length + r.length <= ta && this.record(l, e, Buffer.concat([i, r]).toString("utf8")), i = Buffer.alloc(0), a = !1, c = n + 1, l.offset = t + c;
|
|
3202
3202
|
}
|
|
3203
3203
|
let u = o.subarray(c, s);
|
|
3204
|
-
i.length + u.length >
|
|
3204
|
+
i.length + u.length > ta ? (a = !0, i = Buffer.alloc(0)) : a || (i = Buffer.concat([i, u])), t += s;
|
|
3205
3205
|
}
|
|
3206
3206
|
l.size = r.size, l.mtimeMs = r.mtimeMs;
|
|
3207
3207
|
}
|
|
@@ -3228,7 +3228,7 @@ var ea = 1024 * 1024, ta = class {
|
|
|
3228
3228
|
return;
|
|
3229
3229
|
}
|
|
3230
3230
|
if (r?.type !== "token_usage_record" || i?.thread_id !== t || typeof i.turn_id != "string" || !i.turn_id || i.turn_id.length > 256 || typeof r.timestamp != "string" || !Number.isFinite(Date.parse(r.timestamp))) return;
|
|
3231
|
-
let a =
|
|
3231
|
+
let a = ra(i.turn_token_usage), o = ra(i.thread_token_usage), s = ra(i.usage);
|
|
3232
3232
|
!a || !o || !s || (e.turns.set(i.turn_id, {
|
|
3233
3233
|
turnId: i.turn_id,
|
|
3234
3234
|
recordedAt: r.timestamp,
|
|
@@ -3238,7 +3238,7 @@ var ea = 1024 * 1024, ta = class {
|
|
|
3238
3238
|
}), e.turns.size > 5e4 && e.turns.delete(e.turns.keys().next().value));
|
|
3239
3239
|
}
|
|
3240
3240
|
};
|
|
3241
|
-
function
|
|
3241
|
+
function ra(e) {
|
|
3242
3242
|
if (!e || typeof e != "object") return;
|
|
3243
3243
|
let t = {
|
|
3244
3244
|
totalTokens: e.total_tokens,
|
|
@@ -3248,26 +3248,26 @@ function na(e) {
|
|
|
3248
3248
|
outputTokens: e.output_tokens,
|
|
3249
3249
|
reasoningOutputTokens: e.reasoning_output_tokens
|
|
3250
3250
|
};
|
|
3251
|
-
return
|
|
3251
|
+
return G(t) ? t : void 0;
|
|
3252
3252
|
}
|
|
3253
3253
|
//#endregion
|
|
3254
3254
|
//#region src/node/codex-surface-realtime.ts
|
|
3255
|
-
function
|
|
3255
|
+
function ia(e, t) {
|
|
3256
3256
|
if (e === void 0) return;
|
|
3257
3257
|
if (typeof e != "string") throw TypeError(`Realtime ${t} must be a string`);
|
|
3258
3258
|
let n = e.trim();
|
|
3259
3259
|
if (!n) throw TypeError(`Realtime ${t} cannot be empty`);
|
|
3260
3260
|
return n;
|
|
3261
3261
|
}
|
|
3262
|
-
function
|
|
3262
|
+
function aa(e, t) {
|
|
3263
3263
|
if (typeof e != "string") throw TypeError(`Realtime ${t} must be a string`);
|
|
3264
3264
|
let n = e.trim();
|
|
3265
3265
|
if (!n) throw TypeError(`Realtime ${t} cannot be empty`);
|
|
3266
3266
|
return n;
|
|
3267
3267
|
}
|
|
3268
|
-
function
|
|
3268
|
+
function oa(e) {
|
|
3269
3269
|
if (!(e.data instanceof Uint8Array)) throw TypeError("Realtime audio data must be a Uint8Array");
|
|
3270
|
-
let t =
|
|
3270
|
+
let t = ca(e.sampleRate, "sampleRate"), n = ca(e.numChannels, "numChannels"), r = e.samplesPerChannel === void 0 ? Math.floor(e.data.byteLength / 2 / n) : la(e.samplesPerChannel, "samplesPerChannel"), i = e.itemId === void 0 ? null : e.itemId;
|
|
3271
3271
|
if (i !== null && (typeof i != "string" || !i.trim())) throw TypeError("Realtime audio itemId must be a non-empty string or null");
|
|
3272
3272
|
return {
|
|
3273
3273
|
data: Buffer.from(e.data.buffer, e.data.byteOffset, e.data.byteLength).toString("base64"),
|
|
@@ -3277,7 +3277,7 @@ function aa(e) {
|
|
|
3277
3277
|
itemId: i
|
|
3278
3278
|
};
|
|
3279
3279
|
}
|
|
3280
|
-
function
|
|
3280
|
+
function sa(e) {
|
|
3281
3281
|
return {
|
|
3282
3282
|
data: new Uint8Array(Buffer.from(e.data, "base64")),
|
|
3283
3283
|
sampleRate: e.sampleRate,
|
|
@@ -3286,28 +3286,28 @@ function oa(e) {
|
|
|
3286
3286
|
itemId: e.itemId
|
|
3287
3287
|
};
|
|
3288
3288
|
}
|
|
3289
|
-
function
|
|
3289
|
+
function ca(e, t) {
|
|
3290
3290
|
if (!Number.isSafeInteger(e) || e <= 0) throw TypeError(`Realtime audio ${t} must be a positive integer`);
|
|
3291
3291
|
return e;
|
|
3292
3292
|
}
|
|
3293
|
-
function
|
|
3293
|
+
function la(e, t) {
|
|
3294
3294
|
if (e === null) return null;
|
|
3295
3295
|
if (!Number.isSafeInteger(e) || e < 0) throw TypeError(`Realtime audio ${t} must be a non-negative integer or null`);
|
|
3296
3296
|
return e;
|
|
3297
3297
|
}
|
|
3298
3298
|
//#endregion
|
|
3299
3299
|
//#region src/node/codex-surface-realtime-session.ts
|
|
3300
|
-
async function
|
|
3300
|
+
async function ua(e) {
|
|
3301
3301
|
let { client: t, ensureThreadReady: n, onConversationEvent: r, options: i, threadId: a } = e;
|
|
3302
3302
|
await n();
|
|
3303
3303
|
let o = i.outputModality;
|
|
3304
3304
|
if (o !== "text" && o !== "audio") throw TypeError(`Invalid realtime output modality '${String(o)}'`);
|
|
3305
3305
|
let s = i.version;
|
|
3306
3306
|
if (s !== void 0 && s !== "v1" && s !== "v2" && s !== "v3") throw TypeError(`Invalid realtime version '${String(s)}'`);
|
|
3307
|
-
let c =
|
|
3307
|
+
let c = ia(i.model, "model"), l = ia(i.voice, "voice"), u = i.transport ?? { type: "websocket" };
|
|
3308
3308
|
if (u.type !== "websocket" && u.type !== "webrtc") throw TypeError(`Invalid realtime transport '${String(u.type)}'`);
|
|
3309
3309
|
if (u.type === "webrtc" && !u.sdp.trim()) throw TypeError("WebRTC realtime transport requires a non-empty SDP offer");
|
|
3310
|
-
let d = u.type === "webrtc" ?
|
|
3310
|
+
let d = u.type === "webrtc" ? da(r) : null, f;
|
|
3311
3311
|
try {
|
|
3312
3312
|
let [, e] = await Promise.all([t.request("thread/realtime/start", {
|
|
3313
3313
|
threadId: a,
|
|
@@ -3338,12 +3338,12 @@ async function la(e) {
|
|
|
3338
3338
|
if (m(), u.type === "webrtc") throw Error("WebRTC realtime audio must be sent through its negotiated media track");
|
|
3339
3339
|
await t.request("thread/realtime/appendAudio", {
|
|
3340
3340
|
threadId: a,
|
|
3341
|
-
audio:
|
|
3341
|
+
audio: oa(e)
|
|
3342
3342
|
});
|
|
3343
3343
|
},
|
|
3344
3344
|
appendText: async (e, n = "user") => {
|
|
3345
3345
|
m();
|
|
3346
|
-
let r =
|
|
3346
|
+
let r = aa(e, "text");
|
|
3347
3347
|
if (n !== "user" && n !== "developer" && n !== "assistant") throw TypeError(`Invalid realtime text role '${String(n)}'`);
|
|
3348
3348
|
await t.request("thread/realtime/appendText", {
|
|
3349
3349
|
threadId: a,
|
|
@@ -3354,7 +3354,7 @@ async function la(e) {
|
|
|
3354
3354
|
appendSpeech: async (e) => {
|
|
3355
3355
|
m(), await t.request("thread/realtime/appendSpeech", {
|
|
3356
3356
|
threadId: a,
|
|
3357
|
-
text:
|
|
3357
|
+
text: aa(e, "speech")
|
|
3358
3358
|
});
|
|
3359
3359
|
},
|
|
3360
3360
|
stop: async () => {
|
|
@@ -3365,7 +3365,7 @@ async function la(e) {
|
|
|
3365
3365
|
})
|
|
3366
3366
|
};
|
|
3367
3367
|
}
|
|
3368
|
-
function
|
|
3368
|
+
function da(e) {
|
|
3369
3369
|
let t = () => void 0, n, r = !1, i = () => {
|
|
3370
3370
|
r || (r = !0, clearTimeout(n), t());
|
|
3371
3371
|
};
|
|
@@ -3382,7 +3382,7 @@ function ua(e) {
|
|
|
3382
3382
|
}
|
|
3383
3383
|
//#endregion
|
|
3384
3384
|
//#region src/node/codex-surface-runtime.ts
|
|
3385
|
-
function
|
|
3385
|
+
function fa(e) {
|
|
3386
3386
|
return {
|
|
3387
3387
|
status: "idle",
|
|
3388
3388
|
authentication: e,
|
|
@@ -3425,7 +3425,7 @@ function da(e) {
|
|
|
3425
3425
|
error: null
|
|
3426
3426
|
};
|
|
3427
3427
|
}
|
|
3428
|
-
function
|
|
3428
|
+
function pa(e, t, n = {}) {
|
|
3429
3429
|
return {
|
|
3430
3430
|
threadId: e,
|
|
3431
3431
|
cwd: null,
|
|
@@ -3465,7 +3465,7 @@ function fa(e, t, n = {}) {
|
|
|
3465
3465
|
...n
|
|
3466
3466
|
};
|
|
3467
3467
|
}
|
|
3468
|
-
function
|
|
3468
|
+
function ma(e, t, n) {
|
|
3469
3469
|
let r = [...n], i = new Set(r.map((e) => e.id)), a = new Set(e.answeredClientRequestIds);
|
|
3470
3470
|
for (let t of e.messages) {
|
|
3471
3471
|
let e = t.metadata?.asyncQuestionRequestIds;
|
|
@@ -3508,7 +3508,7 @@ function pa(e, t, n) {
|
|
|
3508
3508
|
}
|
|
3509
3509
|
//#endregion
|
|
3510
3510
|
//#region src/node/codex-surface-authentication.ts
|
|
3511
|
-
function
|
|
3511
|
+
function ha() {
|
|
3512
3512
|
return {
|
|
3513
3513
|
status: "notLoaded",
|
|
3514
3514
|
account: null,
|
|
@@ -3522,7 +3522,7 @@ function ma() {
|
|
|
3522
3522
|
}
|
|
3523
3523
|
};
|
|
3524
3524
|
}
|
|
3525
|
-
function
|
|
3525
|
+
function ga(e) {
|
|
3526
3526
|
return e.type === "chatgpt" ? {
|
|
3527
3527
|
type: "chatgpt",
|
|
3528
3528
|
email: e.email,
|
|
@@ -3532,13 +3532,13 @@ function ha(e) {
|
|
|
3532
3532
|
credentialSource: e.usesCodexManagedCredentials ? "codexManaged" : "awsManaged"
|
|
3533
3533
|
} : { type: "apiKey" };
|
|
3534
3534
|
}
|
|
3535
|
-
function
|
|
3535
|
+
function _a(e) {
|
|
3536
3536
|
return JSON.stringify({
|
|
3537
3537
|
account: e.account,
|
|
3538
3538
|
requiresOpenaiAuth: e.requiresOpenaiAuth
|
|
3539
3539
|
});
|
|
3540
3540
|
}
|
|
3541
|
-
function
|
|
3541
|
+
function va(e) {
|
|
3542
3542
|
let t = e.account;
|
|
3543
3543
|
return t ? t.type === "chatgpt" ? JSON.stringify({
|
|
3544
3544
|
type: t.type,
|
|
@@ -3551,12 +3551,12 @@ function _a(e) {
|
|
|
3551
3551
|
requiresOpenaiAuth: e.requiresOpenaiAuth
|
|
3552
3552
|
});
|
|
3553
3553
|
}
|
|
3554
|
-
function
|
|
3554
|
+
function ya(e) {
|
|
3555
3555
|
let t = e.trim();
|
|
3556
3556
|
if (!t) throw Error("Codex login id cannot be empty");
|
|
3557
3557
|
return t;
|
|
3558
3558
|
}
|
|
3559
|
-
function
|
|
3559
|
+
function ba(e) {
|
|
3560
3560
|
let t;
|
|
3561
3561
|
try {
|
|
3562
3562
|
t = new URL(e);
|
|
@@ -3568,41 +3568,41 @@ function ya(e) {
|
|
|
3568
3568
|
}
|
|
3569
3569
|
//#endregion
|
|
3570
3570
|
//#region src/node/codex-surface-settings.ts
|
|
3571
|
-
function
|
|
3571
|
+
function K(e, t) {
|
|
3572
3572
|
return e.find((e) => e.id === t || e.model === t) ?? e.find((e) => e.isDefault) ?? e[0] ?? null;
|
|
3573
3573
|
}
|
|
3574
|
-
function
|
|
3574
|
+
function xa(e, t) {
|
|
3575
3575
|
let n = e.find((e) => e.id === t || e.model === t);
|
|
3576
3576
|
if (!n) throw Error(`Unknown model '${t}'`);
|
|
3577
3577
|
return n;
|
|
3578
3578
|
}
|
|
3579
|
-
function
|
|
3579
|
+
function Sa(e, t) {
|
|
3580
3580
|
if (!t) return;
|
|
3581
3581
|
if (!e) throw Error(`Cannot select reasoning effort '${t}' without a model`);
|
|
3582
3582
|
let n = e.supportedReasoningEfforts?.map((e) => e.reasoningEffort) ?? [];
|
|
3583
3583
|
if (n.length > 0 && !n.includes(t)) throw Error(`Reasoning effort '${t}' is not available for '${e.displayName}'`);
|
|
3584
3584
|
}
|
|
3585
|
-
function
|
|
3585
|
+
function Ca(e) {
|
|
3586
3586
|
return e.defaultReasoningEffort ?? e.supportedReasoningEfforts?.[0]?.reasoningEffort ?? null;
|
|
3587
3587
|
}
|
|
3588
|
-
function
|
|
3588
|
+
function wa(e) {
|
|
3589
3589
|
return e.defaultServiceTier ?? null;
|
|
3590
3590
|
}
|
|
3591
|
-
function
|
|
3591
|
+
function Ta(e, t) {
|
|
3592
3592
|
if (!t) return;
|
|
3593
3593
|
if (!e) throw Error(`Cannot select service tier '${t}' without a model`);
|
|
3594
3594
|
if (t === "default" || t === e.defaultServiceTier) return;
|
|
3595
3595
|
let n = e.serviceTiers?.map((e) => e.id) ?? [];
|
|
3596
3596
|
if (n.length > 0 && !n.includes(t)) throw Error(`Service tier '${t}' is not available for '${e.displayName}'`);
|
|
3597
3597
|
}
|
|
3598
|
-
function
|
|
3598
|
+
function Ea(e, t) {
|
|
3599
3599
|
let n = new Set(e.filter((e) => e.allowed).map((e) => e.id)), r = [];
|
|
3600
|
-
return n.has(":workspace") &&
|
|
3600
|
+
return n.has(":workspace") && Da(t?.allowedApprovalPolicies, "on-request") && Da(t?.allowedApprovalsReviewers, "user") && r.push("ask-for-approval"), n.has(":workspace") && Da(t?.allowedApprovalPolicies, "on-request") && Da(t?.allowedApprovalsReviewers, "auto_review") && r.push("approve-for-me"), (n.has(":danger-full-access") || n.has(":danger-no-sandbox")) && Da(t?.allowedApprovalPolicies, "never") && Da(t?.allowedApprovalsReviewers, "user") && r.push("full-access"), r;
|
|
3601
3601
|
}
|
|
3602
|
-
function
|
|
3602
|
+
function Da(e, t) {
|
|
3603
3603
|
return !Array.isArray(e) || e.length === 0 || e.includes(t);
|
|
3604
3604
|
}
|
|
3605
|
-
function
|
|
3605
|
+
function Oa(e) {
|
|
3606
3606
|
return e === "full-access" ? {
|
|
3607
3607
|
approvalPolicy: "never",
|
|
3608
3608
|
approvalsReviewer: "user",
|
|
@@ -3613,39 +3613,39 @@ function Da(e) {
|
|
|
3613
3613
|
permissions: ":workspace"
|
|
3614
3614
|
};
|
|
3615
3615
|
}
|
|
3616
|
-
function
|
|
3617
|
-
return
|
|
3616
|
+
function ka(e) {
|
|
3617
|
+
return Oa(e);
|
|
3618
3618
|
}
|
|
3619
|
-
function
|
|
3619
|
+
function Aa(e, t, n, r) {
|
|
3620
3620
|
let i = r?.id;
|
|
3621
3621
|
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;
|
|
3622
3622
|
}
|
|
3623
|
-
function
|
|
3624
|
-
let r =
|
|
3623
|
+
function ja(e, t, n) {
|
|
3624
|
+
let r = K(t, e.model);
|
|
3625
3625
|
return {
|
|
3626
|
-
approvalPreset:
|
|
3626
|
+
approvalPreset: Aa(e.approvalPolicy, e.approvalsReviewer, e.sandbox, e.activePermissionProfile) ?? n.approvalPreset,
|
|
3627
3627
|
planMode: n.planMode,
|
|
3628
3628
|
selectedModelId: r?.id ?? n.selectedModelId,
|
|
3629
|
-
selectedReasoningEffort: e.reasoningEffort ?? (r ?
|
|
3630
|
-
selectedServiceTier: e.serviceTier === void 0 ? r ?
|
|
3629
|
+
selectedReasoningEffort: e.reasoningEffort ?? (r ? Ca(r) : null),
|
|
3630
|
+
selectedServiceTier: e.serviceTier === void 0 ? r ? wa(r) : null : e.serviceTier
|
|
3631
3631
|
};
|
|
3632
3632
|
}
|
|
3633
|
-
function
|
|
3634
|
-
let r =
|
|
3633
|
+
function Ma(e, t, n) {
|
|
3634
|
+
let r = K(t, e.model);
|
|
3635
3635
|
return {
|
|
3636
|
-
approvalPreset:
|
|
3636
|
+
approvalPreset: Aa(e.approvalPolicy, e.approvalsReviewer, e.sandboxPolicy, e.activePermissionProfile) ?? n.approvalPreset,
|
|
3637
3637
|
planMode: e.collaborationMode.mode === "plan",
|
|
3638
3638
|
selectedModelId: r?.id ?? n.selectedModelId,
|
|
3639
|
-
selectedReasoningEffort: e.effort ?? (r ?
|
|
3640
|
-
selectedServiceTier: e.serviceTier === void 0 ? r ?
|
|
3639
|
+
selectedReasoningEffort: e.effort ?? (r ? Ca(r) : null),
|
|
3640
|
+
selectedServiceTier: e.serviceTier === void 0 ? r ? wa(r) : null : e.serviceTier
|
|
3641
3641
|
};
|
|
3642
3642
|
}
|
|
3643
|
-
function
|
|
3644
|
-
let n =
|
|
3643
|
+
function Na(e, t) {
|
|
3644
|
+
let n = K(e.models, e.selectedModelId);
|
|
3645
3645
|
if (t.modelId && (n = e.models.find((e) => e.id === t.modelId) ?? null, !n)) throw Error(`Unknown model '${t.modelId}'`);
|
|
3646
3646
|
let r = t.reasoningEffort ?? e.selectedReasoningEffort, i = t.serviceTier === void 0 ? e.selectedServiceTier ?? null : t.serviceTier, a = n?.supportedReasoningEfforts?.map((e) => e.reasoningEffort) ?? [];
|
|
3647
3647
|
if (t.reasoningEffort && a.length > 0 && !a.includes(t.reasoningEffort)) throw Error(`Reasoning effort '${t.reasoningEffort}' is not available for '${n.displayName}'`);
|
|
3648
|
-
return t.modelId && a.length > 0 && (!r || !a.includes(r)) && (r = n ?
|
|
3648
|
+
return t.modelId && a.length > 0 && (!r || !a.includes(r)) && (r = n ? Ca(n) : null), t.serviceTier !== void 0 && Ta(n, i), t.serviceTier === void 0 && t.modelId && i && !n.serviceTiers?.some((e) => e.id === i) && (i = n ? wa(n) : null), {
|
|
3649
3649
|
approvalPreset: t.approvalPreset ?? e.approvalPreset,
|
|
3650
3650
|
planMode: t.planMode ?? e.planMode,
|
|
3651
3651
|
selectedModelId: n?.id ?? null,
|
|
@@ -3653,7 +3653,7 @@ function Ma(e, t) {
|
|
|
3653
3653
|
selectedServiceTier: i
|
|
3654
3654
|
};
|
|
3655
3655
|
}
|
|
3656
|
-
function
|
|
3656
|
+
function Pa(e, t, n) {
|
|
3657
3657
|
return {
|
|
3658
3658
|
mode: e ? "plan" : "default",
|
|
3659
3659
|
settings: {
|
|
@@ -3663,18 +3663,18 @@ function Na(e, t, n) {
|
|
|
3663
3663
|
}
|
|
3664
3664
|
};
|
|
3665
3665
|
}
|
|
3666
|
-
function
|
|
3667
|
-
let n =
|
|
3666
|
+
function Fa(e, t) {
|
|
3667
|
+
let n = K(e.models, e.selectedModelId), r = t.model ?? n?.model, i = t.reasoningEffort ?? e.selectedReasoningEffort, a = t.planMode ?? e.planMode;
|
|
3668
3668
|
return {
|
|
3669
3669
|
...r ? { model: r } : {},
|
|
3670
3670
|
...i ? { effort: i } : {},
|
|
3671
|
-
...r ? { collaborationMode:
|
|
3671
|
+
...r ? { collaborationMode: Pa(a, r, i) } : {},
|
|
3672
3672
|
...t.serviceTier === void 0 ? e.selectedServiceTier ? { serviceTier: e.selectedServiceTier } : {} : { serviceTier: t.serviceTier }
|
|
3673
3673
|
};
|
|
3674
3674
|
}
|
|
3675
3675
|
//#endregion
|
|
3676
3676
|
//#region src/node/codex-surface-data.ts
|
|
3677
|
-
function
|
|
3677
|
+
function q(e) {
|
|
3678
3678
|
let t = e.preview.trim(), n = t.split("\n")[0];
|
|
3679
3679
|
return {
|
|
3680
3680
|
id: e.id,
|
|
@@ -3691,25 +3691,25 @@ function J(e) {
|
|
|
3691
3691
|
updatedAt: (/* @__PURE__ */ new Date((e.recencyAt ?? e.updatedAt) * 1e3)).toISOString()
|
|
3692
3692
|
};
|
|
3693
3693
|
}
|
|
3694
|
-
function
|
|
3694
|
+
function Ia(e, t) {
|
|
3695
3695
|
let n = new Map(e.map((e) => [e.id, e])), r = t.map((e) => {
|
|
3696
3696
|
let t = n.get(e.id);
|
|
3697
3697
|
return t && he(t, e) ? t : e;
|
|
3698
3698
|
});
|
|
3699
3699
|
return r.length === e.length && r.every((t, n) => t === e[n]) ? e : r;
|
|
3700
3700
|
}
|
|
3701
|
-
function
|
|
3701
|
+
function J(e, t) {
|
|
3702
3702
|
return [t, ...e.filter((e) => e.id !== t.id)].sort((e, t) => t.updatedAt.localeCompare(e.updatedAt));
|
|
3703
3703
|
}
|
|
3704
|
-
function
|
|
3705
|
-
let n = t.model ?
|
|
3706
|
-
return
|
|
3704
|
+
function La(e, t) {
|
|
3705
|
+
let n = t.model ? xa(e.models, t.model) : K(e.models, e.selectedModelId);
|
|
3706
|
+
return Sa(n, t.reasoningEffort), Ta(n, t.serviceTier), {
|
|
3707
3707
|
...t,
|
|
3708
|
-
...t.attachments ? { attachments:
|
|
3708
|
+
...t.attachments ? { attachments: Ra(t.attachments) } : {},
|
|
3709
3709
|
...t.model && n ? { model: n.model } : {}
|
|
3710
3710
|
};
|
|
3711
3711
|
}
|
|
3712
|
-
function
|
|
3712
|
+
function Ra(e) {
|
|
3713
3713
|
return e.map((e) => {
|
|
3714
3714
|
let t = e.path.trim();
|
|
3715
3715
|
if (!t) throw Error("Attachment paths cannot be empty");
|
|
@@ -3726,14 +3726,14 @@ function La(e) {
|
|
|
3726
3726
|
};
|
|
3727
3727
|
});
|
|
3728
3728
|
}
|
|
3729
|
-
function
|
|
3729
|
+
function za(e) {
|
|
3730
3730
|
return e.type === "image" ? {
|
|
3731
3731
|
type: "localImage",
|
|
3732
3732
|
path: e.path,
|
|
3733
3733
|
...e.detail === void 0 ? {} : { detail: e.detail }
|
|
3734
3734
|
} : st(e.name ?? g(e.path), e.path);
|
|
3735
3735
|
}
|
|
3736
|
-
function
|
|
3736
|
+
function Ba(e) {
|
|
3737
3737
|
let t = e.name?.trim() || g(e.path);
|
|
3738
3738
|
return e.type === "image" ? {
|
|
3739
3739
|
type: "attachment",
|
|
@@ -3754,14 +3754,14 @@ function za(e) {
|
|
|
3754
3754
|
}
|
|
3755
3755
|
};
|
|
3756
3756
|
}
|
|
3757
|
-
function
|
|
3757
|
+
function Va(e) {
|
|
3758
3758
|
let t = e.metadata?.turnId;
|
|
3759
3759
|
return e.turnId ?? (typeof t == "string" ? t : null);
|
|
3760
3760
|
}
|
|
3761
|
-
function
|
|
3761
|
+
function Ha(e) {
|
|
3762
3762
|
return e.parts.filter((e) => e.type === "text").map((e) => e.text).join("\n").trim();
|
|
3763
3763
|
}
|
|
3764
|
-
function
|
|
3764
|
+
function Ua(e) {
|
|
3765
3765
|
return e.parts.flatMap((e) => {
|
|
3766
3766
|
if (e.type !== "attachment") return [];
|
|
3767
3767
|
let t = e.attachment, n = t.path;
|
|
@@ -3779,7 +3779,7 @@ function Ha(e) {
|
|
|
3779
3779
|
}] : [];
|
|
3780
3780
|
});
|
|
3781
3781
|
}
|
|
3782
|
-
function
|
|
3782
|
+
function Wa(e) {
|
|
3783
3783
|
return {
|
|
3784
3784
|
totalTokens: e.totalTokens,
|
|
3785
3785
|
inputTokens: e.inputTokens,
|
|
@@ -3789,7 +3789,7 @@ function Ua(e) {
|
|
|
3789
3789
|
reasoningOutputTokens: e.reasoningOutputTokens
|
|
3790
3790
|
};
|
|
3791
3791
|
}
|
|
3792
|
-
function
|
|
3792
|
+
function Ga(e) {
|
|
3793
3793
|
let t = e.modelContextWindow, n = e.last.totalTokens, r = typeof t == "number" && t > 0 ? Math.min(100, Math.max(0, n / t * 100)) : null;
|
|
3794
3794
|
return {
|
|
3795
3795
|
totalTokens: e.total.totalTokens,
|
|
@@ -3802,34 +3802,34 @@ function Wa(e) {
|
|
|
3802
3802
|
usedPercent: r
|
|
3803
3803
|
};
|
|
3804
3804
|
}
|
|
3805
|
-
function
|
|
3805
|
+
function Ka(e) {
|
|
3806
3806
|
return e.type === "active" ? {
|
|
3807
3807
|
type: "active",
|
|
3808
3808
|
activeFlags: [...e.activeFlags]
|
|
3809
3809
|
} : { type: e.type };
|
|
3810
3810
|
}
|
|
3811
|
-
function
|
|
3811
|
+
function qa(e) {
|
|
3812
3812
|
return e.type === "active" ? "active" : e.type === "systemError" ? "error" : "idle";
|
|
3813
3813
|
}
|
|
3814
|
-
function
|
|
3815
|
-
let t = e.rateLimitsByLimitId ? Object.fromEntries(Object.entries(e.rateLimitsByLimitId).filter((e) => !!e[1]).map(([e, t]) => [e,
|
|
3814
|
+
function Ja(e) {
|
|
3815
|
+
let t = e.rateLimitsByLimitId ? Object.fromEntries(Object.entries(e.rateLimitsByLimitId).filter((e) => !!e[1]).map(([e, t]) => [e, Za(t)])) : null;
|
|
3816
3816
|
return {
|
|
3817
|
-
rateLimits:
|
|
3817
|
+
rateLimits: Za(e.rateLimits),
|
|
3818
3818
|
rateLimitsByLimitId: t,
|
|
3819
3819
|
rateLimitResetCredits: e.rateLimitResetCredits ? {
|
|
3820
|
-
availableCount:
|
|
3820
|
+
availableCount: Ya(e.rateLimitResetCredits.availableCount),
|
|
3821
3821
|
credits: e.rateLimitResetCredits.credits?.map((e) => ({ ...e })) ?? null
|
|
3822
3822
|
} : null
|
|
3823
3823
|
};
|
|
3824
3824
|
}
|
|
3825
|
-
function
|
|
3825
|
+
function Ya(e) {
|
|
3826
3826
|
if (typeof e == "bigint" && e >= 0n) return e.toString();
|
|
3827
3827
|
if (typeof e == "number" && Number.isSafeInteger(e) && e >= 0) return String(e);
|
|
3828
3828
|
if (typeof e == "string" && /^(0|[1-9][0-9]*)$/.test(e)) return e;
|
|
3829
3829
|
throw Error("Invalid account count: expected an exact nonnegative integer");
|
|
3830
3830
|
}
|
|
3831
|
-
function
|
|
3832
|
-
let t = (e) => e === null ? null :
|
|
3831
|
+
function Xa(e) {
|
|
3832
|
+
let t = (e) => e === null ? null : Ya(e);
|
|
3833
3833
|
return {
|
|
3834
3834
|
summary: {
|
|
3835
3835
|
lifetimeTokens: t(e.summary.lifetimeTokens),
|
|
@@ -3840,11 +3840,11 @@ function Ya(e) {
|
|
|
3840
3840
|
},
|
|
3841
3841
|
dailyUsageBuckets: e.dailyUsageBuckets?.map((e) => ({
|
|
3842
3842
|
startDate: e.startDate,
|
|
3843
|
-
tokens:
|
|
3843
|
+
tokens: Ya(e.tokens)
|
|
3844
3844
|
})) ?? null
|
|
3845
3845
|
};
|
|
3846
3846
|
}
|
|
3847
|
-
function
|
|
3847
|
+
function Za(e) {
|
|
3848
3848
|
return {
|
|
3849
3849
|
limitId: e.limitId,
|
|
3850
3850
|
limitName: e.limitName,
|
|
@@ -3856,21 +3856,21 @@ function Xa(e) {
|
|
|
3856
3856
|
rateLimitReachedType: e.rateLimitReachedType
|
|
3857
3857
|
};
|
|
3858
3858
|
}
|
|
3859
|
-
function
|
|
3860
|
-
let n =
|
|
3859
|
+
function Qa(e, t) {
|
|
3860
|
+
let n = Za(t);
|
|
3861
3861
|
if (!e) return {
|
|
3862
3862
|
rateLimits: n,
|
|
3863
3863
|
rateLimitsByLimitId: n.limitId ? { [n.limitId]: n } : null,
|
|
3864
3864
|
rateLimitResetCredits: null
|
|
3865
3865
|
};
|
|
3866
|
-
let r =
|
|
3867
|
-
return r.limitId && (i[r.limitId] =
|
|
3866
|
+
let r = $a(e.rateLimits, n), i = e.rateLimitsByLimitId ? { ...e.rateLimitsByLimitId } : {};
|
|
3867
|
+
return r.limitId && (i[r.limitId] = $a(i[r.limitId] ?? r, n)), {
|
|
3868
3868
|
...e,
|
|
3869
3869
|
rateLimits: r,
|
|
3870
3870
|
rateLimitsByLimitId: Object.keys(i).length > 0 ? i : null
|
|
3871
3871
|
};
|
|
3872
3872
|
}
|
|
3873
|
-
function
|
|
3873
|
+
function $a(e, t) {
|
|
3874
3874
|
return {
|
|
3875
3875
|
limitId: t.limitId ?? e.limitId,
|
|
3876
3876
|
limitName: t.limitName ?? e.limitName,
|
|
@@ -3896,18 +3896,18 @@ function Qa(e, t) {
|
|
|
3896
3896
|
}
|
|
3897
3897
|
//#endregion
|
|
3898
3898
|
//#region src/node/codex-surface-transport-options.ts
|
|
3899
|
-
function
|
|
3899
|
+
function eo(e) {
|
|
3900
3900
|
return "type" in e && e.type === "unixSocket";
|
|
3901
3901
|
}
|
|
3902
|
-
function
|
|
3903
|
-
let t = e.codexHome === void 0 ? void 0 :
|
|
3902
|
+
function to(e) {
|
|
3903
|
+
let t = e.codexHome === void 0 ? void 0 : no(e.codexHome), n = e.transport?.codexHome;
|
|
3904
3904
|
if (t !== void 0 && n !== void 0 && t !== n) throw Error("Codex surface codexHome conflicts with transport.codexHome");
|
|
3905
3905
|
return {
|
|
3906
3906
|
...e.transport ?? {},
|
|
3907
3907
|
...t === void 0 ? {} : { codexHome: t }
|
|
3908
3908
|
};
|
|
3909
3909
|
}
|
|
3910
|
-
function
|
|
3910
|
+
function no(e) {
|
|
3911
3911
|
let t = e.trim();
|
|
3912
3912
|
if (!t) throw Error("Codex surface codexHome cannot be empty");
|
|
3913
3913
|
if (!v(t)) throw Error("Codex surface codexHome must be an absolute path");
|
|
@@ -3915,7 +3915,7 @@ function to(e) {
|
|
|
3915
3915
|
}
|
|
3916
3916
|
//#endregion
|
|
3917
3917
|
//#region src/node/codex-surface-authentication-controller.ts
|
|
3918
|
-
var
|
|
3918
|
+
var ro = class {
|
|
3919
3919
|
client;
|
|
3920
3920
|
host;
|
|
3921
3921
|
accountRefreshPromise = null;
|
|
@@ -3949,7 +3949,7 @@ var no = class {
|
|
|
3949
3949
|
try {
|
|
3950
3950
|
let e = await this.client.request("account/login/start", { type: "chatgpt" });
|
|
3951
3951
|
if (e.type !== "chatgpt") throw Error(`Codex account/login/start returned unexpected login type '${e.type}'`);
|
|
3952
|
-
let t =
|
|
3952
|
+
let t = ya(e.loginId), n = ba(e.authUrl);
|
|
3953
3953
|
return this.host.patchAuthentication({ login: {
|
|
3954
3954
|
status: "pending",
|
|
3955
3955
|
loginId: t,
|
|
@@ -3964,7 +3964,7 @@ var no = class {
|
|
|
3964
3964
|
status: "error",
|
|
3965
3965
|
loginId: null,
|
|
3966
3966
|
authUrl: null,
|
|
3967
|
-
error:
|
|
3967
|
+
error: k(e)
|
|
3968
3968
|
} }, "action"), e;
|
|
3969
3969
|
}
|
|
3970
3970
|
})();
|
|
@@ -3986,7 +3986,7 @@ var no = class {
|
|
|
3986
3986
|
try {
|
|
3987
3987
|
let e = await this.client.request("account/login/start", { type: "chatgptDeviceCode" });
|
|
3988
3988
|
if (e.type !== "chatgptDeviceCode") throw Error(`Codex account/login/start returned unexpected login type '${e.type}'`);
|
|
3989
|
-
let t =
|
|
3989
|
+
let t = ya(e.loginId), n = ba(e.verificationUrl), r = e.userCode.trim();
|
|
3990
3990
|
if (!r) throw Error("Codex account/login/start returned an empty device user code");
|
|
3991
3991
|
this.host.patchAuthentication({ login: {
|
|
3992
3992
|
status: "pending",
|
|
@@ -4005,7 +4005,7 @@ var no = class {
|
|
|
4005
4005
|
status: "error",
|
|
4006
4006
|
loginId: null,
|
|
4007
4007
|
authUrl: null,
|
|
4008
|
-
error:
|
|
4008
|
+
error: k(e)
|
|
4009
4009
|
} }, "action"), e;
|
|
4010
4010
|
}
|
|
4011
4011
|
})();
|
|
@@ -4014,7 +4014,7 @@ var no = class {
|
|
|
4014
4014
|
}).catch(() => void 0), t;
|
|
4015
4015
|
}
|
|
4016
4016
|
async cancelLogin(e) {
|
|
4017
|
-
let t =
|
|
4017
|
+
let t = ya(e), n = await this.client.request("account/login/cancel", { loginId: t });
|
|
4018
4018
|
return this.host.patchAuthentication({ login: {
|
|
4019
4019
|
status: n.status === "canceled" ? "cancelled" : "idle",
|
|
4020
4020
|
loginId: null,
|
|
@@ -4056,7 +4056,7 @@ var no = class {
|
|
|
4056
4056
|
error: null
|
|
4057
4057
|
}, e);
|
|
4058
4058
|
try {
|
|
4059
|
-
let n = await this.client.request("account/read", { refreshToken: !1 }), r = n.account ?
|
|
4059
|
+
let n = await this.client.request("account/read", { refreshToken: !1 }), r = n.account ? ga(n.account) : null, i = va({
|
|
4060
4060
|
...this.host.getSnapshot().authentication,
|
|
4061
4061
|
account: r,
|
|
4062
4062
|
requiresOpenaiAuth: n.requiresOpenaiAuth
|
|
@@ -4070,7 +4070,7 @@ var no = class {
|
|
|
4070
4070
|
} catch (t) {
|
|
4071
4071
|
throw this.host.patchAuthentication({
|
|
4072
4072
|
status: "error",
|
|
4073
|
-
error:
|
|
4073
|
+
error: k(t)
|
|
4074
4074
|
}, e), t;
|
|
4075
4075
|
}
|
|
4076
4076
|
}
|
|
@@ -4099,7 +4099,7 @@ var no = class {
|
|
|
4099
4099
|
};
|
|
4100
4100
|
//#endregion
|
|
4101
4101
|
//#region src/node/codex-conversation-handle.ts
|
|
4102
|
-
function
|
|
4102
|
+
function io(e, t) {
|
|
4103
4103
|
let n = async (e) => (await e(), t.getSnapshot());
|
|
4104
4104
|
return {
|
|
4105
4105
|
id: e,
|
|
@@ -4144,36 +4144,36 @@ function ro(e, t) {
|
|
|
4144
4144
|
}
|
|
4145
4145
|
//#endregion
|
|
4146
4146
|
//#region src/node/codex-raw-response-item-adapter.ts
|
|
4147
|
-
function
|
|
4148
|
-
if (!
|
|
4147
|
+
function ao(e) {
|
|
4148
|
+
if (!ho(e) || typeof e.type != "string") return null;
|
|
4149
4149
|
if (e.type === "local_shell_call") {
|
|
4150
|
-
let t = w(
|
|
4150
|
+
let t = w(oo(e));
|
|
4151
4151
|
return {
|
|
4152
|
-
type:
|
|
4152
|
+
type: uo(e.status) ? "item.completed" : "item.started",
|
|
4153
4153
|
payload: { toolPart: t }
|
|
4154
4154
|
};
|
|
4155
4155
|
}
|
|
4156
4156
|
return e.type === "function_call" ? {
|
|
4157
4157
|
type: "item.started",
|
|
4158
|
-
payload: { toolPart: w(
|
|
4159
|
-
} : e.type === "function_call_output" ?
|
|
4158
|
+
payload: { toolPart: w(so(e)) }
|
|
4159
|
+
} : e.type === "function_call_output" ? co(e.call_id, e.output) : e.type === "custom_tool_call" ? {
|
|
4160
4160
|
type: "item.started",
|
|
4161
4161
|
payload: { toolPart: w({
|
|
4162
4162
|
type: "dynamicToolCall",
|
|
4163
|
-
id:
|
|
4163
|
+
id: X(e.call_id) ?? Y(e),
|
|
4164
4164
|
namespace: null,
|
|
4165
|
-
tool:
|
|
4165
|
+
tool: X(e.name) ?? "custom_tool",
|
|
4166
4166
|
status: e.status,
|
|
4167
|
-
arguments:
|
|
4167
|
+
arguments: X(e.input) ?? "",
|
|
4168
4168
|
contentItems: null,
|
|
4169
4169
|
success: null,
|
|
4170
4170
|
durationMs: null
|
|
4171
4171
|
}) }
|
|
4172
|
-
} : e.type === "custom_tool_call_output" ?
|
|
4172
|
+
} : e.type === "custom_tool_call_output" ? co(e.call_id, e.output, X(e.name) ?? void 0) : e.type === "tool_search_call" ? {
|
|
4173
4173
|
type: "item.started",
|
|
4174
4174
|
payload: { toolPart: w({
|
|
4175
4175
|
type: "dynamicToolCall",
|
|
4176
|
-
id:
|
|
4176
|
+
id: X(e.call_id) ?? Y(e),
|
|
4177
4177
|
namespace: "codex",
|
|
4178
4178
|
tool: "tool_search",
|
|
4179
4179
|
status: e.status,
|
|
@@ -4185,20 +4185,20 @@ function io(e) {
|
|
|
4185
4185
|
}) }
|
|
4186
4186
|
} : e.type === "tool_search_output" ? {
|
|
4187
4187
|
type: "item.updated",
|
|
4188
|
-
payload: bt(
|
|
4188
|
+
payload: bt(X(e.call_id) ?? Y(e), e.tools, "tool_search", e.status)
|
|
4189
4189
|
} : e.type === "web_search_call" ? {
|
|
4190
4190
|
type: "item.completed",
|
|
4191
4191
|
payload: { toolPart: w({
|
|
4192
4192
|
type: "webSearch",
|
|
4193
|
-
id:
|
|
4194
|
-
query:
|
|
4193
|
+
id: Y(e),
|
|
4194
|
+
query: po(e.action),
|
|
4195
4195
|
action: e.action
|
|
4196
4196
|
}) }
|
|
4197
4197
|
} : e.type === "image_generation_call" ? {
|
|
4198
4198
|
type: "item.completed",
|
|
4199
4199
|
payload: { toolPart: w({
|
|
4200
4200
|
type: "dynamicToolCall",
|
|
4201
|
-
id:
|
|
4201
|
+
id: X(e.id) ?? Y(e),
|
|
4202
4202
|
namespace: null,
|
|
4203
4203
|
tool: "image_generation",
|
|
4204
4204
|
status: e.status,
|
|
@@ -4209,29 +4209,29 @@ function io(e) {
|
|
|
4209
4209
|
}) }
|
|
4210
4210
|
} : null;
|
|
4211
4211
|
}
|
|
4212
|
-
function
|
|
4213
|
-
let t =
|
|
4212
|
+
function oo(e) {
|
|
4213
|
+
let t = ho(e.action) ? e.action : {}, n = Array.isArray(t.command) ? mo(t.command) : X(t.command) ?? "local shell";
|
|
4214
4214
|
return {
|
|
4215
4215
|
type: "commandExecution",
|
|
4216
|
-
id:
|
|
4216
|
+
id: X(e.call_id) ?? Y(e),
|
|
4217
4217
|
command: n,
|
|
4218
|
-
cwd:
|
|
4218
|
+
cwd: X(t.working_directory) ?? "",
|
|
4219
4219
|
processId: null,
|
|
4220
4220
|
source: "agent",
|
|
4221
|
-
status:
|
|
4221
|
+
status: lo(e.status),
|
|
4222
4222
|
commandActions: [],
|
|
4223
4223
|
aggregatedOutput: null,
|
|
4224
4224
|
exitCode: null,
|
|
4225
4225
|
durationMs: null
|
|
4226
4226
|
};
|
|
4227
4227
|
}
|
|
4228
|
-
function
|
|
4229
|
-
let t =
|
|
4230
|
-
return t === "shell_command" &&
|
|
4228
|
+
function so(e) {
|
|
4229
|
+
let t = X(e.name) ?? "function_call", n = fo(e.arguments), r = X(e.call_id) ?? Y(e);
|
|
4230
|
+
return t === "shell_command" && ho(n) ? {
|
|
4231
4231
|
type: "commandExecution",
|
|
4232
4232
|
id: r,
|
|
4233
|
-
command:
|
|
4234
|
-
cwd:
|
|
4233
|
+
command: X(n.command) ?? t,
|
|
4234
|
+
cwd: X(n.workdir) ?? X(n.cwd) ?? "",
|
|
4235
4235
|
processId: null,
|
|
4236
4236
|
source: "agent",
|
|
4237
4237
|
status: "inProgress",
|
|
@@ -4242,7 +4242,7 @@ function oo(e) {
|
|
|
4242
4242
|
} : {
|
|
4243
4243
|
type: "dynamicToolCall",
|
|
4244
4244
|
id: r,
|
|
4245
|
-
namespace:
|
|
4245
|
+
namespace: X(e.namespace),
|
|
4246
4246
|
tool: t,
|
|
4247
4247
|
status: "inProgress",
|
|
4248
4248
|
arguments: n,
|
|
@@ -4251,19 +4251,19 @@ function oo(e) {
|
|
|
4251
4251
|
durationMs: null
|
|
4252
4252
|
};
|
|
4253
4253
|
}
|
|
4254
|
-
function
|
|
4254
|
+
function co(e, t, n) {
|
|
4255
4255
|
return {
|
|
4256
4256
|
type: "item.updated",
|
|
4257
|
-
payload: bt(
|
|
4257
|
+
payload: bt(X(e) ?? "raw-response-output", t, n)
|
|
4258
4258
|
};
|
|
4259
4259
|
}
|
|
4260
|
-
function
|
|
4260
|
+
function lo(e) {
|
|
4261
4261
|
return e === "completed" ? "completed" : e === "incomplete" || e === "failed" || e === "error" ? "failed" : "inProgress";
|
|
4262
4262
|
}
|
|
4263
|
-
function
|
|
4263
|
+
function uo(e) {
|
|
4264
4264
|
return e === "completed" || e === "failed" || e === "error" || e === "incomplete";
|
|
4265
4265
|
}
|
|
4266
|
-
function
|
|
4266
|
+
function fo(e) {
|
|
4267
4267
|
if (typeof e != "string") return e;
|
|
4268
4268
|
try {
|
|
4269
4269
|
return JSON.parse(e);
|
|
@@ -4271,55 +4271,55 @@ function uo(e) {
|
|
|
4271
4271
|
return e;
|
|
4272
4272
|
}
|
|
4273
4273
|
}
|
|
4274
|
-
function fo(e) {
|
|
4275
|
-
return mo(e) ? Z(e.query) ?? Z(e.searchTerm) ?? "web search" : "web search";
|
|
4276
|
-
}
|
|
4277
4274
|
function po(e) {
|
|
4275
|
+
return ho(e) ? X(e.query) ?? X(e.searchTerm) ?? "web search" : "web search";
|
|
4276
|
+
}
|
|
4277
|
+
function mo(e) {
|
|
4278
4278
|
return e.map((e) => {
|
|
4279
4279
|
let t = String(e);
|
|
4280
4280
|
return /\s/.test(t) ? JSON.stringify(t) : t;
|
|
4281
4281
|
}).join(" ");
|
|
4282
4282
|
}
|
|
4283
|
-
function
|
|
4284
|
-
return (
|
|
4283
|
+
function Y(e) {
|
|
4284
|
+
return (X(e.call_id) ?? X(e.id)) || `raw-${e.type}`;
|
|
4285
4285
|
}
|
|
4286
|
-
function
|
|
4286
|
+
function X(e) {
|
|
4287
4287
|
return typeof e == "string" && e.length > 0 ? e : null;
|
|
4288
4288
|
}
|
|
4289
|
-
function
|
|
4289
|
+
function ho(e) {
|
|
4290
4290
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
4291
4291
|
}
|
|
4292
4292
|
//#endregion
|
|
4293
4293
|
//#region src/node/codex-surface-events.ts
|
|
4294
|
-
function
|
|
4294
|
+
function go(e, t) {
|
|
4295
4295
|
return `${e}\u0000${t}`;
|
|
4296
4296
|
}
|
|
4297
|
-
function
|
|
4297
|
+
function _o(e) {
|
|
4298
4298
|
return typeof e == "number" && Number.isFinite(e) ? (/* @__PURE__ */ new Date(e * 1e3)).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
|
|
4299
4299
|
}
|
|
4300
|
-
function
|
|
4300
|
+
function vo(e) {
|
|
4301
4301
|
return typeof e == "number" && Number.isFinite(e) ? (/* @__PURE__ */ new Date(e * 1e3)).toISOString() : null;
|
|
4302
4302
|
}
|
|
4303
|
-
function
|
|
4303
|
+
function yo(e) {
|
|
4304
4304
|
return e ? {
|
|
4305
4305
|
message: e.message,
|
|
4306
4306
|
additionalDetails: e.additionalDetails,
|
|
4307
4307
|
codexErrorInfo: e.codexErrorInfo
|
|
4308
4308
|
} : null;
|
|
4309
4309
|
}
|
|
4310
|
-
function
|
|
4310
|
+
function Z(e, t = !1) {
|
|
4311
4311
|
return {
|
|
4312
4312
|
id: e.id,
|
|
4313
4313
|
...e.itemsView === "summary" || e.itemsView === "notLoaded" ? { itemsView: "summary" } : {},
|
|
4314
4314
|
status: e.status,
|
|
4315
|
-
error:
|
|
4315
|
+
error: yo(e.error),
|
|
4316
4316
|
willRetry: t,
|
|
4317
|
-
startedAt:
|
|
4318
|
-
completedAt:
|
|
4317
|
+
startedAt: vo(e.startedAt),
|
|
4318
|
+
completedAt: vo(e.completedAt),
|
|
4319
4319
|
durationMs: e.durationMs ?? null
|
|
4320
4320
|
};
|
|
4321
4321
|
}
|
|
4322
|
-
function
|
|
4322
|
+
function Q(e, t) {
|
|
4323
4323
|
let n = e.findIndex((e) => e.id === t.id);
|
|
4324
4324
|
if (n < 0) return [...e, t];
|
|
4325
4325
|
let r = [...e];
|
|
@@ -4328,18 +4328,18 @@ function $(e, t) {
|
|
|
4328
4328
|
startedAt: t.startedAt ?? e[n].startedAt
|
|
4329
4329
|
}), r;
|
|
4330
4330
|
}
|
|
4331
|
-
function
|
|
4331
|
+
function bo(e, t) {
|
|
4332
4332
|
return JSON.stringify(e) === JSON.stringify(t);
|
|
4333
4333
|
}
|
|
4334
|
-
function
|
|
4334
|
+
function xo() {
|
|
4335
4335
|
return `user-${globalThis.crypto.randomUUID()}`;
|
|
4336
4336
|
}
|
|
4337
|
-
function
|
|
4337
|
+
function So() {
|
|
4338
4338
|
return `queued-prompt-${globalThis.crypto.randomUUID()}`;
|
|
4339
4339
|
}
|
|
4340
4340
|
//#endregion
|
|
4341
4341
|
//#region src/node/codex-surface-subagents.ts
|
|
4342
|
-
function
|
|
4342
|
+
function Co(e) {
|
|
4343
4343
|
let t = {};
|
|
4344
4344
|
for (let [n, r] of Object.entries(e.agentsStates)) r && (t[n] = {
|
|
4345
4345
|
status: r.status,
|
|
@@ -4359,7 +4359,7 @@ function So(e) {
|
|
|
4359
4359
|
}
|
|
4360
4360
|
//#endregion
|
|
4361
4361
|
//#region src/node/codex-surface-items-controller.ts
|
|
4362
|
-
var
|
|
4362
|
+
var wo = class {
|
|
4363
4363
|
host;
|
|
4364
4364
|
commandOutputForwardItemIds = /* @__PURE__ */ new Set();
|
|
4365
4365
|
fileActivityKeys = /* @__PURE__ */ new Set();
|
|
@@ -4377,14 +4377,14 @@ var Co = class {
|
|
|
4377
4377
|
for (let e of this.reviewOutputByTurn.keys()) e.startsWith(t) && this.reviewOutputByTurn.delete(e);
|
|
4378
4378
|
}
|
|
4379
4379
|
isForwardingCommandOutput(e, t) {
|
|
4380
|
-
return this.commandOutputForwardItemIds.has(
|
|
4380
|
+
return this.commandOutputForwardItemIds.has(go(e, t));
|
|
4381
4381
|
}
|
|
4382
4382
|
applyAgentDelta(e) {
|
|
4383
4383
|
let t = this.host.requireRuntime(e.threadId);
|
|
4384
4384
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
4385
|
-
let n =
|
|
4386
|
-
this.host.patchRuntime(e.threadId, { messages:
|
|
4387
|
-
let r =
|
|
4385
|
+
let n = fn(t.messages, e.turnId, e.itemId)?.parts.find((t) => t.type === "text" && t.itemId === e.itemId)?.phase;
|
|
4386
|
+
this.host.patchRuntime(e.threadId, { messages: pn(t.messages, e.threadId, e.turnId, e.itemId, e.delta, n) });
|
|
4387
|
+
let r = fn(t.messages, e.turnId, e.itemId) ?? this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
4388
4388
|
r && this.host.emitEvent("notification", {
|
|
4389
4389
|
type: "message.delta",
|
|
4390
4390
|
conversationId: e.threadId,
|
|
@@ -4401,7 +4401,7 @@ var Co = class {
|
|
|
4401
4401
|
let t = this.host.requireRuntime(e.threadId);
|
|
4402
4402
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
4403
4403
|
let n = `${t.planMarkdownByTurn.get(e.turnId) ?? ""}${e.delta}`;
|
|
4404
|
-
t.planMarkdownByTurn.set(e.turnId, n), this.host.patchRuntime(e.threadId, { messages:
|
|
4404
|
+
t.planMarkdownByTurn.set(e.turnId, n), this.host.patchRuntime(e.threadId, { messages: j(t.messages, e.threadId, e.turnId, Dn(e.turnId, n, "running")) }), this.host.emitEvent("notification", {
|
|
4405
4405
|
type: "plan.delta",
|
|
4406
4406
|
conversationId: e.threadId,
|
|
4407
4407
|
turnId: e.turnId,
|
|
@@ -4415,7 +4415,7 @@ var Co = class {
|
|
|
4415
4415
|
applyPlanUpdated(e) {
|
|
4416
4416
|
let t = this.host.requireRuntime(e.threadId);
|
|
4417
4417
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
4418
|
-
let n =
|
|
4418
|
+
let n = En(e.explanation, e.plan), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
4419
4419
|
t.planMarkdownByTurn.set(e.turnId, n), this.host.patchRuntime(e.threadId, {
|
|
4420
4420
|
executionPlan: {
|
|
4421
4421
|
turnId: e.turnId,
|
|
@@ -4424,7 +4424,7 @@ var Co = class {
|
|
|
4424
4424
|
markdown: n,
|
|
4425
4425
|
updatedAt: r
|
|
4426
4426
|
},
|
|
4427
|
-
messages:
|
|
4427
|
+
messages: j(t.messages, e.threadId, e.turnId, Dn(e.turnId, n, "completed"))
|
|
4428
4428
|
}), this.host.emitEvent("notification", {
|
|
4429
4429
|
type: "plan.updated",
|
|
4430
4430
|
conversationId: e.threadId,
|
|
@@ -4440,13 +4440,13 @@ var Co = class {
|
|
|
4440
4440
|
applyRawResponseItem(e) {
|
|
4441
4441
|
let t = this.host.requireRuntime(e.threadId);
|
|
4442
4442
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
4443
|
-
let n =
|
|
4443
|
+
let n = ao(e.item);
|
|
4444
4444
|
if (!n) return;
|
|
4445
4445
|
if (n.type === "item.updated") {
|
|
4446
4446
|
this.applyToolUpdate(e.threadId, e.turnId, n.payload);
|
|
4447
4447
|
return;
|
|
4448
4448
|
}
|
|
4449
|
-
this.host.patchRuntime(e.threadId, { messages:
|
|
4449
|
+
this.host.patchRuntime(e.threadId, { messages: j(t.messages, e.threadId, e.turnId, n.payload.toolPart) });
|
|
4450
4450
|
let r = this.host.messageContainingTool(e.threadId, e.turnId, n.payload.toolPart.id);
|
|
4451
4451
|
r && (this.host.emitEvent("notification", {
|
|
4452
4452
|
type: n.type === "item.completed" ? "tool.completed" : "tool.started",
|
|
@@ -4467,7 +4467,7 @@ var Co = class {
|
|
|
4467
4467
|
startedAt: ("startedAtMs" in e ? e.startedAtMs : e.completedAtMs) / 1e3
|
|
4468
4468
|
};
|
|
4469
4469
|
if (e.item.type === "userMessage") {
|
|
4470
|
-
let t =
|
|
4470
|
+
let t = Nn(e.threadId, i, e.item);
|
|
4471
4471
|
if (!t || n.messages.some((e) => e.id === t.id)) return;
|
|
4472
4472
|
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;
|
|
4473
4473
|
if (o >= 0) {
|
|
@@ -4493,7 +4493,7 @@ var Co = class {
|
|
|
4493
4493
|
...t,
|
|
4494
4494
|
kind: "steer"
|
|
4495
4495
|
} : t, c = [...n.messages, s];
|
|
4496
|
-
this.host.patchRuntime(e.threadId, { messages: a ?
|
|
4496
|
+
this.host.patchRuntime(e.threadId, { messages: a ? A(c, e.threadId, e.turnId, { forceSegment: !0 }) : c }), this.host.emitEvent("notification", {
|
|
4497
4497
|
type: "message.appended",
|
|
4498
4498
|
conversationId: e.threadId,
|
|
4499
4499
|
turnId: e.turnId,
|
|
@@ -4503,7 +4503,7 @@ var Co = class {
|
|
|
4503
4503
|
}
|
|
4504
4504
|
if (e.item.type === "reasoning") {
|
|
4505
4505
|
let t = this.host.assistantMessageForTurn(e.threadId, e.turnId), r = t ? JSON.stringify(t.parts) : null;
|
|
4506
|
-
this.host.patchRuntime(e.threadId, { messages:
|
|
4506
|
+
this.host.patchRuntime(e.threadId, { messages: mn(n.messages, e.threadId, e.turnId, e.item.id, e.item.summary) });
|
|
4507
4507
|
let i = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
4508
4508
|
if (!i || JSON.stringify(i.parts) === r) return;
|
|
4509
4509
|
this.host.emitEvent("notification", {
|
|
@@ -4515,10 +4515,10 @@ var Co = class {
|
|
|
4515
4515
|
return;
|
|
4516
4516
|
}
|
|
4517
4517
|
if (e.item.type === "agentMessage" && t && n.planMode && e.item.phase === "final_answer") {
|
|
4518
|
-
let t =
|
|
4518
|
+
let t = _n(e.item.text);
|
|
4519
4519
|
if (t) {
|
|
4520
|
-
let r = this.host.assistantMessageForTurn(e.threadId, e.turnId), i =
|
|
4521
|
-
t.visibleText && (i =
|
|
4520
|
+
let r = this.host.assistantMessageForTurn(e.threadId, e.turnId), i = gn(n.messages, e.threadId, e.turnId, e.item.id);
|
|
4521
|
+
t.visibleText && (i = hn(i, e.threadId, e.turnId, e.item.id, t.visibleText, e.item.phase)), i = j(i, e.threadId, e.turnId, Dn(e.turnId, t.markdown, "completed")), n.planMarkdownByTurn.set(e.turnId, t.markdown), this.host.patchRuntime(e.threadId, { messages: i });
|
|
4522
4522
|
let a = this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
4523
4523
|
a && this.host.emitEvent("notification", {
|
|
4524
4524
|
type: r ? "message.updated" : "message.appended",
|
|
@@ -4540,12 +4540,12 @@ var Co = class {
|
|
|
4540
4540
|
if (e.item.type === "agentMessage" || e.item.type === "exitedReviewMode") {
|
|
4541
4541
|
let t = e.item.type === "agentMessage" ? e.item.text : e.item.review, r = e.item.type === "agentMessage" ? e.item.phase ?? void 0 : void 0;
|
|
4542
4542
|
if (!t && e.item.type !== "agentMessage") return;
|
|
4543
|
-
let i =
|
|
4543
|
+
let i = go(e.threadId, e.turnId);
|
|
4544
4544
|
if (e.item.type === "agentMessage" && this.reviewOutputByTurn.get(i) === t) return;
|
|
4545
4545
|
e.item.type === "exitedReviewMode" && this.reviewOutputByTurn.set(i, t);
|
|
4546
|
-
let a = new Set(n.messages.map((e) => e.id)), o =
|
|
4547
|
-
if (u && (f =
|
|
4548
|
-
let p = (u ? void 0 :
|
|
4546
|
+
let a = new Set(n.messages.map((e) => e.id)), o = fn(n.messages, e.turnId, e.item.id) ?? 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 = o?.parts.find((t) => t.type === "text" && t.itemId === e.item.id)?.text ?? "", u = e.item.type === "agentMessage" ? Pn(e.threadId, e.turnId, e.item) : null, d = u ? "" : t, f = u ? gn(n.messages, e.threadId, e.turnId, e.item.id) : hn(n.messages, e.threadId, e.turnId, e.item.id, t, r);
|
|
4547
|
+
if (u && (f = yn(f, e.threadId, e.turnId, u)), this.host.patchRuntime(e.threadId, { messages: f }), !d && !u && !r) return;
|
|
4548
|
+
let p = (u ? void 0 : fn(n.messages, e.turnId, e.item.id)) ?? this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
4549
4549
|
if (p && !a.has(p.id)) this.host.emitEvent("notification", {
|
|
4550
4550
|
type: "message.appended",
|
|
4551
4551
|
conversationId: e.threadId,
|
|
@@ -4588,7 +4588,7 @@ var Co = class {
|
|
|
4588
4588
|
if (e.item.type === "plan") {
|
|
4589
4589
|
if (!t) return;
|
|
4590
4590
|
let r = e.item.text.trim() || n.planMarkdownByTurn.get(e.turnId) || "";
|
|
4591
|
-
n.planMarkdownByTurn.set(e.turnId, r), this.host.patchRuntime(e.threadId, { messages:
|
|
4591
|
+
n.planMarkdownByTurn.set(e.turnId, r), this.host.patchRuntime(e.threadId, { messages: j(n.messages, e.threadId, e.turnId, Dn(e.turnId, r, "completed")) }), this.host.emitEvent("notification", {
|
|
4592
4592
|
type: "plan.completed",
|
|
4593
4593
|
conversationId: e.threadId,
|
|
4594
4594
|
turnId: e.turnId,
|
|
@@ -4600,7 +4600,7 @@ var Co = class {
|
|
|
4600
4600
|
return;
|
|
4601
4601
|
}
|
|
4602
4602
|
if (e.item.type === "contextCompaction") {
|
|
4603
|
-
if (this.host.patchRuntime(e.threadId, { messages:
|
|
4603
|
+
if (this.host.patchRuntime(e.threadId, { messages: Sn(n.messages, e.threadId, e.turnId, t ? "complete" : "streaming") }), t) {
|
|
4604
4604
|
let t = this.host.requireRuntime(e.threadId).messages.find((t) => t.kind === "compaction" && t.metadata?.turnId === e.turnId);
|
|
4605
4605
|
t && this.host.emitEvent("notification", {
|
|
4606
4606
|
type: "context.compactionCompleted",
|
|
@@ -4626,7 +4626,7 @@ var Co = class {
|
|
|
4626
4626
|
turnId: e.turnId,
|
|
4627
4627
|
payload: {
|
|
4628
4628
|
lifecycle: t ? "completed" : "started",
|
|
4629
|
-
toolCall:
|
|
4629
|
+
toolCall: Co(e.item)
|
|
4630
4630
|
}
|
|
4631
4631
|
});
|
|
4632
4632
|
return;
|
|
@@ -4651,10 +4651,10 @@ var Co = class {
|
|
|
4651
4651
|
let a = this.shouldForwardCommandOutput(e.threadId, t, e.item), o = w(e.item, {
|
|
4652
4652
|
includeCommandOutput: a,
|
|
4653
4653
|
cwd: n.cwd
|
|
4654
|
-
}), s =
|
|
4654
|
+
}), s = In(e.item);
|
|
4655
4655
|
if (!o && !s.length) return;
|
|
4656
|
-
let c = s.some((e) => !n.messages.some((t) => t.parts.some((t) => t.type === "media" &&
|
|
4657
|
-
for (let t of s) l =
|
|
4656
|
+
let c = s.some((e) => !n.messages.some((t) => t.parts.some((t) => t.type === "media" && bn(t, e)))), l = o ? j(n.messages, e.threadId, e.turnId, o) : [...n.messages];
|
|
4657
|
+
for (let t of s) l = vn(l, e.threadId, e.turnId, t, e.item.id);
|
|
4658
4658
|
this.host.patchRuntime(e.threadId, { messages: l });
|
|
4659
4659
|
let u = o ? this.host.messageContainingTool(e.threadId, e.turnId, o.id) : this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
4660
4660
|
u && o && this.host.emitEvent("notification", {
|
|
@@ -4675,7 +4675,7 @@ var Co = class {
|
|
|
4675
4675
|
shouldForwardCommandOutput(e, t, n) {
|
|
4676
4676
|
let r = "id" in n && typeof n.id == "string" ? n.id : null;
|
|
4677
4677
|
if (!r) return !1;
|
|
4678
|
-
let i =
|
|
4678
|
+
let i = go(e, r);
|
|
4679
4679
|
if (!t) {
|
|
4680
4680
|
let e = gt(n);
|
|
4681
4681
|
return e ? this.commandOutputForwardItemIds.add(i) : this.commandOutputForwardItemIds.delete(i), e;
|
|
@@ -4686,14 +4686,14 @@ var Co = class {
|
|
|
4686
4686
|
applyToolUpdate(e, t, n) {
|
|
4687
4687
|
let r = this.host.requireRuntime(e);
|
|
4688
4688
|
this.host.markRuntimeTurnActive(r, t);
|
|
4689
|
-
let i = r.cwd &&
|
|
4689
|
+
let i = r.cwd && To(n) ? {
|
|
4690
4690
|
...n,
|
|
4691
4691
|
metadata: {
|
|
4692
4692
|
...n.metadata,
|
|
4693
4693
|
cwd: r.cwd
|
|
4694
4694
|
}
|
|
4695
4695
|
} : n;
|
|
4696
|
-
this.host.patchRuntime(e, { messages:
|
|
4696
|
+
this.host.patchRuntime(e, { messages: xn(r.messages, e, t, i) });
|
|
4697
4697
|
let a = this.host.messageContainingTool(e, t, n.itemId);
|
|
4698
4698
|
a && this.host.emitEvent("notification", {
|
|
4699
4699
|
type: "tool.updated",
|
|
@@ -4729,7 +4729,7 @@ var Co = class {
|
|
|
4729
4729
|
t.turnIds.includes(e.turn.id) || t.turnIds.push(e.turn.id);
|
|
4730
4730
|
let n = t.activeTurnId !== e.turn.id && t.turnStartPending;
|
|
4731
4731
|
t.activeTurnId === e.turn.id && (t.activeTurnId = null);
|
|
4732
|
-
let r = n || t.activeTurnId !== null, i = e.turn.status === "failed" ? "error" : "complete", a =
|
|
4732
|
+
let r = n || t.activeTurnId !== null, i = e.turn.status === "failed" ? "error" : "complete", a = Cn(t.messages, e.turn.id, e.turn.status).map((t) => t.metadata?.turnId === e.turn.id ? {
|
|
4733
4733
|
...t,
|
|
4734
4734
|
status: i
|
|
4735
4735
|
} : t).filter((t) => !(t.role === "assistant" && t.metadata?.turnId === e.turn.id && t.kind === void 0 && t.parts.length === 0));
|
|
@@ -4741,7 +4741,7 @@ var Co = class {
|
|
|
4741
4741
|
},
|
|
4742
4742
|
turnStartPending: n,
|
|
4743
4743
|
messages: a,
|
|
4744
|
-
turns:
|
|
4744
|
+
turns: Q(t.turns, Z(e.turn))
|
|
4745
4745
|
}), this.host.patch({ conversations: this.host.getState().conversations.map((n) => n.id === e.threadId ? {
|
|
4746
4746
|
...n,
|
|
4747
4747
|
status: r ? "active" : e.turn.status === "failed" ? "error" : "idle",
|
|
@@ -4755,26 +4755,26 @@ var Co = class {
|
|
|
4755
4755
|
turnId: e.turn.id,
|
|
4756
4756
|
payload: {
|
|
4757
4757
|
status: e.turn.status,
|
|
4758
|
-
error:
|
|
4758
|
+
error: yo(e.turn.error),
|
|
4759
4759
|
willRetry: !1,
|
|
4760
|
-
startedAt:
|
|
4761
|
-
completedAt:
|
|
4760
|
+
startedAt: vo(e.turn.startedAt),
|
|
4761
|
+
completedAt: vo(e.turn.completedAt),
|
|
4762
4762
|
durationMs: e.turn.durationMs ?? null
|
|
4763
4763
|
}
|
|
4764
4764
|
}), this.host.emitConversationActivity(e.threadId, "notification"), t.planMarkdownByTurn.delete(e.turn.id), this.host.sendNextQueuedPrompt(e.threadId);
|
|
4765
4765
|
}
|
|
4766
4766
|
};
|
|
4767
|
-
function
|
|
4767
|
+
function To(e) {
|
|
4768
4768
|
if (e.fallbackToolPart?.kind === "fileChange") return !0;
|
|
4769
4769
|
let t = e.input, n = e.metadata;
|
|
4770
|
-
return
|
|
4770
|
+
return Eo(t) && Array.isArray(t.changes) || Eo(n) && Array.isArray(n.changes);
|
|
4771
4771
|
}
|
|
4772
|
-
function
|
|
4772
|
+
function Eo(e) {
|
|
4773
4773
|
return typeof e == "object" && !!e;
|
|
4774
4774
|
}
|
|
4775
4775
|
//#endregion
|
|
4776
4776
|
//#region src/node/codex-surface-client-requests-controller.ts
|
|
4777
|
-
var
|
|
4777
|
+
var Do = class {
|
|
4778
4778
|
host;
|
|
4779
4779
|
pending = /* @__PURE__ */ new Map();
|
|
4780
4780
|
constructor(e) {
|
|
@@ -4823,12 +4823,12 @@ var Eo = class {
|
|
|
4823
4823
|
"deny"
|
|
4824
4824
|
].includes(r)) throw Error(`Invalid tool confirmation decision '${String(r)}'`);
|
|
4825
4825
|
this.pending.delete(t.id);
|
|
4826
|
-
let i = this.host.requireRuntime(n.threadId), a =
|
|
4826
|
+
let i = this.host.requireRuntime(n.threadId), a = Tn(i.answeredClientRequestIds, t.id);
|
|
4827
4827
|
if (n.kind === "ask_user") {
|
|
4828
4828
|
let e = t.payload?.answers ?? {};
|
|
4829
4829
|
n.responder.resolve({ answers: e }), this.host.patchRuntime(n.threadId, {
|
|
4830
4830
|
answeredClientRequestIds: a,
|
|
4831
|
-
messages:
|
|
4831
|
+
messages: xn(i.messages, n.threadId, n.turnId, {
|
|
4832
4832
|
itemId: n.itemId,
|
|
4833
4833
|
output: { answers: e }
|
|
4834
4834
|
})
|
|
@@ -4837,7 +4837,7 @@ var Eo = class {
|
|
|
4837
4837
|
let e = r;
|
|
4838
4838
|
n.responder.resolve(Yt(e)), this.host.patchRuntime(n.threadId, {
|
|
4839
4839
|
answeredClientRequestIds: a,
|
|
4840
|
-
messages:
|
|
4840
|
+
messages: xn(i.messages, n.threadId, n.displayTurnId, {
|
|
4841
4841
|
itemId: n.itemId,
|
|
4842
4842
|
output: { decision: e }
|
|
4843
4843
|
})
|
|
@@ -4855,7 +4855,7 @@ var Eo = class {
|
|
|
4855
4855
|
}), this.host.emitConversationActivity(n.threadId, "action");
|
|
4856
4856
|
}
|
|
4857
4857
|
async respondToAsyncQuestion(e, t) {
|
|
4858
|
-
let n = e ?? this.host.activeConversationId(), r = n === null ? null : this.host.requireRuntime(n), i = r &&
|
|
4858
|
+
let n = e ?? this.host.activeConversationId(), r = n === null ? null : this.host.requireRuntime(n), i = r && ma(r, [], []).clientRequests.find((e) => e.kind === "ask_user" && e.id === t.id), a = r && i ? {
|
|
4859
4859
|
request: i,
|
|
4860
4860
|
runtime: r
|
|
4861
4861
|
} : null;
|
|
@@ -4874,7 +4874,7 @@ var Eo = class {
|
|
|
4874
4874
|
${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");
|
|
4875
4875
|
await this.host.answerAsyncQuestion(a.runtime.threadId, e, t);
|
|
4876
4876
|
}
|
|
4877
|
-
this.host.patchRuntime(a.runtime.threadId, { answeredClientRequestIds:
|
|
4877
|
+
this.host.patchRuntime(a.runtime.threadId, { answeredClientRequestIds: Tn(a.runtime.answeredClientRequestIds, t.id) }), this.host.emitEvent("action", {
|
|
4878
4878
|
type: "clientRequest.resolved",
|
|
4879
4879
|
conversationId: a.runtime.threadId,
|
|
4880
4880
|
...a.request.turnId ? { turnId: a.request.turnId } : {},
|
|
@@ -4889,7 +4889,7 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
4889
4889
|
let n = this.pending.get(e);
|
|
4890
4890
|
if (this.pending.delete(e), n) {
|
|
4891
4891
|
let t = this.host.requireRuntime(n.threadId);
|
|
4892
|
-
this.host.patchRuntime(n.threadId, { answeredClientRequestIds:
|
|
4892
|
+
this.host.patchRuntime(n.threadId, { answeredClientRequestIds: Tn(t.answeredClientRequestIds, e) });
|
|
4893
4893
|
}
|
|
4894
4894
|
this.maybeClearWaitingBusy(t), n && this.host.emitEvent("notification", {
|
|
4895
4895
|
type: "clientRequest.resolved",
|
|
@@ -4937,7 +4937,7 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
4937
4937
|
responder: t
|
|
4938
4938
|
}), this.host.patchRuntime(n, {
|
|
4939
4939
|
busy: !0,
|
|
4940
|
-
messages:
|
|
4940
|
+
messages: j(o.messages, n, r, {
|
|
4941
4941
|
type: "tool",
|
|
4942
4942
|
id: i,
|
|
4943
4943
|
kind: "generic",
|
|
@@ -4979,23 +4979,23 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
4979
4979
|
let n = e.params;
|
|
4980
4980
|
if (n.mode !== "form") return !1;
|
|
4981
4981
|
let r = n._meta;
|
|
4982
|
-
if (!
|
|
4983
|
-
let i = String(e.id), a =
|
|
4982
|
+
if (!un(r) || r.codex_approval_kind !== "mcp_tool_call") return !1;
|
|
4983
|
+
let i = String(e.id), a = ln(r.tool_name) ?? ln(r.tool_title) ?? "tool", o = this.host.requireRuntime(n.threadId);
|
|
4984
4984
|
n.turnId && this.host.markRuntimeTurnActive(o, n.turnId);
|
|
4985
|
-
let s = n.turnId ?? o.activeTurnId ?? `client-request-${i}`, c =
|
|
4985
|
+
let s = n.turnId ?? o.activeTurnId ?? `client-request-${i}`, c = on(o.messages, s, n.serverName, a), l = c?.id ?? `approval-${i}`, u = n.message.trim() || `Allow ${n.serverName} to run ${a}?`, d = {
|
|
4986
4986
|
id: i,
|
|
4987
4987
|
kind: "confirm_tool",
|
|
4988
4988
|
conversationId: n.threadId,
|
|
4989
4989
|
turnId: n.turnId,
|
|
4990
4990
|
itemId: l,
|
|
4991
4991
|
payload: { confirmation: {
|
|
4992
|
-
argumentsPreview:
|
|
4992
|
+
argumentsPreview: sn(r),
|
|
4993
4993
|
integrationId: n.serverName,
|
|
4994
|
-
integrationName:
|
|
4994
|
+
integrationName: ln(r.connector_name) ?? n.serverName,
|
|
4995
4995
|
summary: u,
|
|
4996
4996
|
toolName: a,
|
|
4997
|
-
...
|
|
4998
|
-
...
|
|
4997
|
+
...cn(r.persist, "session") ? { allowConversation: !0 } : {},
|
|
4998
|
+
...cn(r.persist, "always") ? { allowAlways: !0 } : {}
|
|
4999
4999
|
} }
|
|
5000
5000
|
};
|
|
5001
5001
|
this.pending.set(i, {
|
|
@@ -5020,9 +5020,9 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
5020
5020
|
params: {
|
|
5021
5021
|
requestId: i,
|
|
5022
5022
|
confirmationSummary: u,
|
|
5023
|
-
argumentsPreview:
|
|
5024
|
-
allowConversation:
|
|
5025
|
-
allowAlways:
|
|
5023
|
+
argumentsPreview: sn(r),
|
|
5024
|
+
allowConversation: cn(r.persist, "session"),
|
|
5025
|
+
allowAlways: cn(r.persist, "always")
|
|
5026
5026
|
}
|
|
5027
5027
|
}),
|
|
5028
5028
|
input: r.tool_params,
|
|
@@ -5036,7 +5036,7 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
5036
5036
|
};
|
|
5037
5037
|
this.host.patchRuntime(n.threadId, {
|
|
5038
5038
|
busy: !0,
|
|
5039
|
-
messages:
|
|
5039
|
+
messages: j(o.messages, n.threadId, s, f)
|
|
5040
5040
|
});
|
|
5041
5041
|
let p = this.host.messageContainingTool(n.threadId, s, l);
|
|
5042
5042
|
return p && this.host.emitEvent("notification", {
|
|
@@ -5054,8 +5054,8 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
5054
5054
|
payload: { request: structuredClone(d) }
|
|
5055
5055
|
}), this.host.emitConversationActivity(n.threadId, "notification"), !0;
|
|
5056
5056
|
}
|
|
5057
|
-
},
|
|
5058
|
-
function
|
|
5057
|
+
}, Oo = 256 * 1024;
|
|
5058
|
+
function ko(e) {
|
|
5059
5059
|
return {
|
|
5060
5060
|
id: e.id,
|
|
5061
5061
|
model: e.model,
|
|
@@ -5080,11 +5080,11 @@ function Oo(e) {
|
|
|
5080
5080
|
}
|
|
5081
5081
|
};
|
|
5082
5082
|
}
|
|
5083
|
-
async function ko(e, t) {
|
|
5084
|
-
return Promise.all(e.filter((e) => e.enabled).map((e) => Ao(e, t)));
|
|
5085
|
-
}
|
|
5086
5083
|
async function Ao(e, t) {
|
|
5087
|
-
|
|
5084
|
+
return Promise.all(e.filter((e) => e.enabled).map((e) => jo(e, t)));
|
|
5085
|
+
}
|
|
5086
|
+
async function jo(e, t) {
|
|
5087
|
+
let n = $(e.interface?.brandColor), r = Lo(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]);
|
|
5088
5088
|
return {
|
|
5089
5089
|
name: e.name,
|
|
5090
5090
|
description: e.description,
|
|
@@ -5099,8 +5099,8 @@ async function Ao(e, t) {
|
|
|
5099
5099
|
enabled: e.enabled
|
|
5100
5100
|
};
|
|
5101
5101
|
}
|
|
5102
|
-
async function
|
|
5103
|
-
let n = e.interface, r =
|
|
5102
|
+
async function Mo(e, t) {
|
|
5103
|
+
let n = e.interface, r = Po(n?.composerIconUrl), i = Po(n?.logoUrl), a = Po(n?.logoUrlDark), o = $(n?.displayName) ?? e.name, s = $(n?.shortDescription), c = $(n?.longDescription), l = $(n?.brandColor), u = r ?? i ?? await No([n?.composerIcon, n?.logo], t), d = r ?? a ?? i ?? await No([
|
|
5104
5104
|
n?.composerIcon,
|
|
5105
5105
|
n?.logoDark,
|
|
5106
5106
|
n?.logo
|
|
@@ -5117,20 +5117,20 @@ async function jo(e, t) {
|
|
|
5117
5117
|
enabled: e.enabled
|
|
5118
5118
|
};
|
|
5119
5119
|
}
|
|
5120
|
-
async function
|
|
5120
|
+
async function No(e, t) {
|
|
5121
5121
|
for (let n of e) {
|
|
5122
5122
|
if (!n) continue;
|
|
5123
5123
|
let e = await t(n);
|
|
5124
5124
|
if (e) return e;
|
|
5125
5125
|
}
|
|
5126
5126
|
}
|
|
5127
|
-
function
|
|
5128
|
-
let t =
|
|
5127
|
+
function Po(e) {
|
|
5128
|
+
let t = $(e);
|
|
5129
5129
|
try {
|
|
5130
5130
|
return new URL(t).protocol === "https:" ? t : void 0;
|
|
5131
5131
|
} catch {}
|
|
5132
5132
|
}
|
|
5133
|
-
function
|
|
5133
|
+
function Fo(e) {
|
|
5134
5134
|
switch (_(e).toLowerCase()) {
|
|
5135
5135
|
case ".avif": return "image/avif";
|
|
5136
5136
|
case ".bmp": return "image/bmp";
|
|
@@ -5143,15 +5143,15 @@ function Po(e) {
|
|
|
5143
5143
|
case ".webp": return "image/webp";
|
|
5144
5144
|
}
|
|
5145
5145
|
}
|
|
5146
|
-
function
|
|
5146
|
+
function Io(e, t) {
|
|
5147
5147
|
let n = t.trim();
|
|
5148
5148
|
if (!/^[a-z\d+/]+={0,2}$/i.test(n)) return;
|
|
5149
5149
|
let r = n.replace(/=+$/, "");
|
|
5150
5150
|
if (r.length % 4 == 1) return;
|
|
5151
5151
|
let i = n.length - r.length, a = (4 - r.length % 4) % 4;
|
|
5152
|
-
if (!(i !== 0 && i !== a) && !(Math.floor(r.length * 3 / 4) >
|
|
5152
|
+
if (!(i !== 0 && i !== a) && !(Math.floor(r.length * 3 / 4) > Oo)) return `data:${e};base64,${`${r}${"=".repeat((4 - r.length % 4) % 4)}`}`;
|
|
5153
5153
|
}
|
|
5154
|
-
function
|
|
5154
|
+
function $(e) {
|
|
5155
5155
|
return (typeof e == "string" ? e.trim() : void 0) || void 0;
|
|
5156
5156
|
}
|
|
5157
5157
|
function Lo(e) {
|
|
@@ -5164,6 +5164,9 @@ var Ro = class {
|
|
|
5164
5164
|
cwd;
|
|
5165
5165
|
host;
|
|
5166
5166
|
iconDataUrls = /* @__PURE__ */ new Map();
|
|
5167
|
+
skillsByCwd = /* @__PURE__ */ new Map();
|
|
5168
|
+
skillRequests = /* @__PURE__ */ new Map();
|
|
5169
|
+
skillRevision = 0;
|
|
5167
5170
|
pluginPromise = null;
|
|
5168
5171
|
pluginLastAttemptedCwdsKey = null;
|
|
5169
5172
|
pluginRefreshRequested = !1;
|
|
@@ -5171,7 +5174,7 @@ var Ro = class {
|
|
|
5171
5174
|
this.client = e, this.cwd = t, this.host = n;
|
|
5172
5175
|
}
|
|
5173
5176
|
reset(e) {
|
|
5174
|
-
this.iconDataUrls.clear(), this.pluginLastAttemptedCwdsKey = null, this.pluginRefreshRequested = e;
|
|
5177
|
+
this.iconDataUrls.clear(), this.skillsByCwd.clear(), this.skillRequests.clear(), this.skillRevision += 1, this.pluginLastAttemptedCwdsKey = null, this.pluginRefreshRequested = e;
|
|
5175
5178
|
}
|
|
5176
5179
|
async listModels(e = {}) {
|
|
5177
5180
|
await this.host.ensureConnected();
|
|
@@ -5194,13 +5197,16 @@ var Ro = class {
|
|
|
5194
5197
|
async loadSkills(e = !1, t = "action") {
|
|
5195
5198
|
e && this.iconDataUrls.clear(), this.host.patch({ skillCatalogStatus: "loading" }), this.emitSkills(this.cwd ?? null, [], "loading", t);
|
|
5196
5199
|
try {
|
|
5197
|
-
let n = await
|
|
5200
|
+
let n = await Ao((await this.client.request("skills/list", {
|
|
5198
5201
|
...this.cwd ? { cwds: [this.cwd] } : {},
|
|
5199
5202
|
forceReload: e
|
|
5200
5203
|
})).data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e));
|
|
5201
5204
|
this.host.patch({
|
|
5202
5205
|
skills: n,
|
|
5203
5206
|
skillCatalogStatus: "loaded"
|
|
5207
|
+
}), this.skillsByCwd.set(this.cwd ?? null, {
|
|
5208
|
+
skills: n,
|
|
5209
|
+
skillCatalogStatus: "loaded"
|
|
5204
5210
|
}), this.emitSkills(this.cwd ?? null, n, "loaded", t);
|
|
5205
5211
|
} catch {
|
|
5206
5212
|
this.host.patch({
|
|
@@ -5210,20 +5216,54 @@ var Ro = class {
|
|
|
5210
5216
|
}
|
|
5211
5217
|
}
|
|
5212
5218
|
async listSkills(e = {}) {
|
|
5213
|
-
await this.host.ensureConnected()
|
|
5214
|
-
let t =
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5219
|
+
await this.host.ensureConnected();
|
|
5220
|
+
let t = e.cwd ?? null, n = this.skillRequests.get(t);
|
|
5221
|
+
if (n) return structuredClone(await n);
|
|
5222
|
+
let r = this.skillsByCwd.get(t);
|
|
5223
|
+
if (!e.forceReload && r?.skillCatalogStatus === "loaded") return structuredClone(r.skills);
|
|
5224
|
+
e.forceReload && this.iconDataUrls.clear();
|
|
5225
|
+
let i = this.skillRevision;
|
|
5226
|
+
this.publishSkills(t, [], "loading", "action");
|
|
5227
|
+
let a = (async () => {
|
|
5228
|
+
try {
|
|
5229
|
+
let n = await Ao((await this.client.request("skills/list", {
|
|
5230
|
+
...e.cwd ? { cwds: [e.cwd] } : {},
|
|
5231
|
+
forceReload: e.forceReload ?? !1
|
|
5232
|
+
})).data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e));
|
|
5233
|
+
if (i !== this.skillRevision) throw Error("Skill discovery was invalidated; retry the request");
|
|
5234
|
+
return this.skillsByCwd.set(t, {
|
|
5235
|
+
skills: n,
|
|
5236
|
+
skillCatalogStatus: "loaded"
|
|
5237
|
+
}), this.publishSkills(t, n, "loaded", "action"), n;
|
|
5238
|
+
} catch (e) {
|
|
5239
|
+
throw i === this.skillRevision && this.publishSkills(t, [], "error", "action"), e;
|
|
5240
|
+
}
|
|
5241
|
+
})();
|
|
5242
|
+
this.skillRequests.set(t, a);
|
|
5243
|
+
try {
|
|
5244
|
+
return structuredClone(await a);
|
|
5245
|
+
} finally {
|
|
5246
|
+
this.skillRequests.get(t) === a && this.skillRequests.delete(t);
|
|
5247
|
+
}
|
|
5248
|
+
}
|
|
5249
|
+
invalidateSkills() {
|
|
5250
|
+
let e = /* @__PURE__ */ new Set([...this.skillsByCwd.keys(), ...this.skillRequests.keys()]);
|
|
5251
|
+
this.skillRevision += 1, this.skillsByCwd.clear(), this.skillRequests.clear(), this.iconDataUrls.clear(), this.host.patch({
|
|
5252
|
+
skills: [],
|
|
5253
|
+
skillCatalogStatus: "notLoaded"
|
|
5254
|
+
}), this.emitSkills(this.cwd ?? null, [], "notLoaded", "notification");
|
|
5255
|
+
for (let e of this.host.runtimes()) this.host.patchRuntime(e.threadId, {
|
|
5256
|
+
skills: [],
|
|
5257
|
+
skillCatalogStatus: "notLoaded"
|
|
5258
|
+
}), this.host.emitConversationSkills(e.threadId, "notification");
|
|
5259
|
+
for (let t of e) this.listSkills({
|
|
5260
|
+
...t ? { cwd: t } : {},
|
|
5261
|
+
forceReload: !0
|
|
5262
|
+
}).catch(() => void 0);
|
|
5223
5263
|
}
|
|
5224
5264
|
async loadPermissionProfiles() {
|
|
5225
5265
|
try {
|
|
5226
|
-
let e = await this.requestPermissionProfiles(this.cwd), t = (await this.client.request("configRequirements/read", void 0)).requirements, n =
|
|
5266
|
+
let e = await this.requestPermissionProfiles(this.cwd), t = (await this.client.request("configRequirements/read", void 0)).requirements, n = Ea(e, t), r = this.host.preferredApprovalPreset();
|
|
5227
5267
|
this.host.patch({
|
|
5228
5268
|
permissionProfiles: e,
|
|
5229
5269
|
approvalPresets: n,
|
|
@@ -5239,7 +5279,7 @@ var Ro = class {
|
|
|
5239
5279
|
}
|
|
5240
5280
|
async loadRateLimits() {
|
|
5241
5281
|
try {
|
|
5242
|
-
let e =
|
|
5282
|
+
let e = Ja(await this.client.request("account/rateLimits/read", void 0));
|
|
5243
5283
|
this.host.patch({ rateLimits: e }), this.host.emitEvent("action", {
|
|
5244
5284
|
type: "rateLimits.changed",
|
|
5245
5285
|
payload: { rateLimits: structuredClone(e) }
|
|
@@ -5252,25 +5292,23 @@ var Ro = class {
|
|
|
5252
5292
|
}
|
|
5253
5293
|
}
|
|
5254
5294
|
async loadConversationCatalogs(e, t = !1) {
|
|
5255
|
-
let n = this.host.getState()
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5295
|
+
let n = this.host.getState(), r = this.skillsByCwd.get(e ?? null) ?? {
|
|
5296
|
+
skills: [],
|
|
5297
|
+
skillCatalogStatus: "notLoaded"
|
|
5298
|
+
};
|
|
5299
|
+
if (!t && e === this.cwd) return {
|
|
5300
|
+
...structuredClone(r),
|
|
5259
5301
|
permissionProfiles: [...n.permissionProfiles],
|
|
5260
5302
|
approvalPresets: [...n.approvalPresets]
|
|
5261
5303
|
};
|
|
5262
|
-
let [
|
|
5263
|
-
...e ? { cwds: [e] } : {},
|
|
5264
|
-
forceReload: t
|
|
5265
|
-
}), (async () => ({
|
|
5304
|
+
let [i] = await Promise.allSettled([(async () => ({
|
|
5266
5305
|
profiles: await this.requestPermissionProfiles(e),
|
|
5267
5306
|
requirements: (await this.client.request("configRequirements/read", void 0)).requirements
|
|
5268
|
-
}))()]), a =
|
|
5307
|
+
}))()]), a = i.status === "fulfilled" ? i.value.profiles : [];
|
|
5269
5308
|
return {
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
approvalPresets: i.status === "fulfilled" ? Ta(o, i.value.requirements) : []
|
|
5309
|
+
...structuredClone(r),
|
|
5310
|
+
permissionProfiles: a,
|
|
5311
|
+
approvalPresets: i.status === "fulfilled" ? Ea(a, i.value.requirements) : []
|
|
5274
5312
|
};
|
|
5275
5313
|
}
|
|
5276
5314
|
schedulePluginRefresh(e = !1) {
|
|
@@ -5297,18 +5335,18 @@ var Ro = class {
|
|
|
5297
5335
|
cursor: n,
|
|
5298
5336
|
includeHidden: e
|
|
5299
5337
|
});
|
|
5300
|
-
t.push(...r.data.map(
|
|
5338
|
+
t.push(...r.data.map(ko)), n = r.nextCursor;
|
|
5301
5339
|
} while (n);
|
|
5302
5340
|
return t;
|
|
5303
5341
|
}
|
|
5304
5342
|
applyModels(e, t) {
|
|
5305
|
-
let n =
|
|
5343
|
+
let n = K(e, this.host.getState().selectedModelId);
|
|
5306
5344
|
this.host.patch({
|
|
5307
5345
|
models: e,
|
|
5308
5346
|
modelCatalogStatus: "loaded",
|
|
5309
5347
|
selectedModelId: n?.id ?? null,
|
|
5310
|
-
selectedReasoningEffort: n ?
|
|
5311
|
-
selectedServiceTier: n ?
|
|
5348
|
+
selectedReasoningEffort: n ? Ca(n) : null,
|
|
5349
|
+
selectedServiceTier: n ? wa(n) : null
|
|
5312
5350
|
}), this.emitModels(e, "loaded", t);
|
|
5313
5351
|
}
|
|
5314
5352
|
emitModels(e, t, n = "action") {
|
|
@@ -5320,6 +5358,17 @@ var Ro = class {
|
|
|
5320
5358
|
}
|
|
5321
5359
|
});
|
|
5322
5360
|
}
|
|
5361
|
+
publishSkills(e, t, n, r) {
|
|
5362
|
+
this.host.getState().activeConversationId || this.host.patch({
|
|
5363
|
+
skills: t,
|
|
5364
|
+
skillCatalogStatus: n
|
|
5365
|
+
});
|
|
5366
|
+
for (let i of this.host.runtimes()) i.cwd === e && (this.host.patchRuntime(i.threadId, {
|
|
5367
|
+
skills: t,
|
|
5368
|
+
skillCatalogStatus: n
|
|
5369
|
+
}), this.host.emitConversationSkills(i.threadId, r));
|
|
5370
|
+
this.emitSkills(e, t, n, r);
|
|
5371
|
+
}
|
|
5323
5372
|
emitSkills(e, t, n, r) {
|
|
5324
5373
|
this.host.emitEvent(r, {
|
|
5325
5374
|
type: "catalog.skillsChanged",
|
|
@@ -5367,7 +5416,7 @@ var Ro = class {
|
|
|
5367
5416
|
try {
|
|
5368
5417
|
let t = await this.client.request("plugin/installed", { ...e.length > 0 ? { cwds: [...e] } : {} }), n = /* @__PURE__ */ new Map();
|
|
5369
5418
|
for (let e of t.marketplaces) for (let t of e.plugins) n.has(t.id) || n.set(t.id, t);
|
|
5370
|
-
let r =
|
|
5419
|
+
let r = Ia(this.host.getState().plugins, await Promise.all([...n.values()].map((e) => Mo(e, (e) => this.iconDataUrl(e)))));
|
|
5371
5420
|
if (this.host.isClosed() || this.host.authenticationBlocksBootstrap()) return;
|
|
5372
5421
|
this.host.patch({
|
|
5373
5422
|
plugins: r,
|
|
@@ -5398,9 +5447,9 @@ var Ro = class {
|
|
|
5398
5447
|
}
|
|
5399
5448
|
async readIconDataUrl(e) {
|
|
5400
5449
|
if (!v(e)) return;
|
|
5401
|
-
let t =
|
|
5450
|
+
let t = Fo(e);
|
|
5402
5451
|
if (t) try {
|
|
5403
|
-
return
|
|
5452
|
+
return Io(t, (await this.client.request("fs/readFile", { path: e })).dataBase64);
|
|
5404
5453
|
} catch {
|
|
5405
5454
|
return;
|
|
5406
5455
|
}
|
|
@@ -5835,7 +5884,7 @@ var es = class {
|
|
|
5835
5884
|
success: !1,
|
|
5836
5885
|
contentItems: [{
|
|
5837
5886
|
type: "inputText",
|
|
5838
|
-
text:
|
|
5887
|
+
text: k(e)
|
|
5839
5888
|
}]
|
|
5840
5889
|
});
|
|
5841
5890
|
}
|
|
@@ -5894,8 +5943,8 @@ var es = class {
|
|
|
5894
5943
|
startedAt: i.startedAt ? Date.parse(i.startedAt) / 1e3 : null,
|
|
5895
5944
|
completedAt: i.completedAt ? Date.parse(i.completedAt) / 1e3 : null,
|
|
5896
5945
|
durationMs: i.durationMs
|
|
5897
|
-
}, o =
|
|
5898
|
-
this.originalImages && (o =
|
|
5946
|
+
}, o = Mn(n.messages, P(e, a));
|
|
5947
|
+
this.originalImages && (o = Ji(o));
|
|
5899
5948
|
let s = n.messages.findIndex((e) => e.turnId === t), c = n.messages.filter((e) => e.turnId !== t);
|
|
5900
5949
|
c.splice(s < 0 ? c.length : s, 0, ...o), this.host.patchRuntime(e, { messages: c });
|
|
5901
5950
|
}
|
|
@@ -5907,7 +5956,7 @@ var es = class {
|
|
|
5907
5956
|
} catch (t) {
|
|
5908
5957
|
throw this.host.runtime(e) === n && o({
|
|
5909
5958
|
detailsLoading: !1,
|
|
5910
|
-
detailsError:
|
|
5959
|
+
detailsError: k(t)
|
|
5911
5960
|
}), t;
|
|
5912
5961
|
} finally {
|
|
5913
5962
|
this.turnLoads.get(e) === i && i.delete(t);
|
|
@@ -5938,7 +5987,7 @@ var es = class {
|
|
|
5938
5987
|
return await this.host.ensureConnected(), this.load();
|
|
5939
5988
|
}
|
|
5940
5989
|
async load() {
|
|
5941
|
-
let e =
|
|
5990
|
+
let e = Ia(this.host.getState().conversations, await this.requestConversations({ limit: this.conversationLimit }));
|
|
5942
5991
|
this.host.patch({ conversations: e }), this.host.schedulePluginRefresh(!0);
|
|
5943
5992
|
for (let t of e) this.host.emitSummaryUpserted(t, "listed", "action");
|
|
5944
5993
|
return this.host.getSnapshot();
|
|
@@ -5947,7 +5996,7 @@ var es = class {
|
|
|
5947
5996
|
return await this.host.ensureConnected(), structuredClone(await this.requestConversations(e));
|
|
5948
5997
|
}
|
|
5949
5998
|
async readSummary(e) {
|
|
5950
|
-
let t =
|
|
5999
|
+
let t = O(e);
|
|
5951
6000
|
await this.host.ensureConnected();
|
|
5952
6001
|
let n = await this.client.request("thread/read", {
|
|
5953
6002
|
threadId: t,
|
|
@@ -5958,20 +6007,20 @@ var es = class {
|
|
|
5958
6007
|
return structuredClone(r);
|
|
5959
6008
|
}
|
|
5960
6009
|
async archive(e) {
|
|
5961
|
-
let t =
|
|
6010
|
+
let t = O(e);
|
|
5962
6011
|
return await this.host.ensureConnected(), await this.client.request("thread/archive", { threadId: t }), this.host.removeThread(t, "archived", "action"), this.host.getSnapshot();
|
|
5963
6012
|
}
|
|
5964
6013
|
async delete(e) {
|
|
5965
|
-
let t =
|
|
6014
|
+
let t = O(e);
|
|
5966
6015
|
return await this.host.ensureConnected(), await this.client.request("thread/delete", { threadId: t }), this.host.removeThread(t, "deleted", "action"), this.host.getSnapshot();
|
|
5967
6016
|
}
|
|
5968
6017
|
async unarchive(e) {
|
|
5969
|
-
let t =
|
|
6018
|
+
let t = O(e);
|
|
5970
6019
|
await this.host.ensureConnected();
|
|
5971
6020
|
let n = await this.client.request("thread/unarchive", { threadId: t });
|
|
5972
6021
|
if (n.thread.id !== t) throw Error(`Codex thread/unarchive returned '${n.thread.id}' for requested thread '${t}'`);
|
|
5973
6022
|
let r = this.summaryWithKnownTurnCount(n.thread);
|
|
5974
|
-
return this.host.patch({ conversations:
|
|
6023
|
+
return this.host.patch({ conversations: J(this.host.getState().conversations, r) }), this.host.emitSummaryUpserted(r, "updated", "action"), this.host.getSnapshot();
|
|
5975
6024
|
}
|
|
5976
6025
|
hydrateCompleteHistory(e, t = {}) {
|
|
5977
6026
|
if (this.host.requireRuntime(e).fullHistoryHydrated && !t.restart) return Promise.resolve();
|
|
@@ -6008,7 +6057,7 @@ var es = class {
|
|
|
6008
6057
|
historyHasOlder: !1
|
|
6009
6058
|
});
|
|
6010
6059
|
} catch (t) {
|
|
6011
|
-
throw this.host.runtime(e) && this.host.patchRuntime(e, { error: `Could not load complete conversation history: ${
|
|
6060
|
+
throw this.host.runtime(e) && this.host.patchRuntime(e, { error: `Could not load complete conversation history: ${k(t)}` }), t;
|
|
6012
6061
|
}
|
|
6013
6062
|
})();
|
|
6014
6063
|
return this.historyHydrations.set(e, r), r.finally(() => {
|
|
@@ -6060,7 +6109,7 @@ var es = class {
|
|
|
6060
6109
|
hasOlder: this.host.requireRuntime(e).historyHasOlder
|
|
6061
6110
|
};
|
|
6062
6111
|
} catch (t) {
|
|
6063
|
-
throw this.host.runtime(e) && this.host.patchRuntime(e, { error:
|
|
6112
|
+
throw this.host.runtime(e) && this.host.patchRuntime(e, { error: k(t) }), t;
|
|
6064
6113
|
} finally {
|
|
6065
6114
|
this.host.runtime(e) && this.host.patchRuntime(e, { historyLoadingOlder: !1 });
|
|
6066
6115
|
}
|
|
@@ -6115,10 +6164,10 @@ var es = class {
|
|
|
6115
6164
|
let a = /* @__PURE__ */ new Set();
|
|
6116
6165
|
i.activeTurnId && a.add(i.activeTurnId);
|
|
6117
6166
|
for (let e of t) (e.status === "inProgress" || e.itemsView === "summary" && i.turns.find((t) => t.id === e.id)?.itemsView !== "summary") && i.turnIds.includes(e.id) && a.add(e.id);
|
|
6118
|
-
let o = new Set(t.filter((e) => !a.has(e.id)).map((e) => e.id)), s = t.filter((e) => o.has(e.id)), c = i.turnIds.filter((e) => !o.has(e)), l = i.turns.filter((e) => !o.has(e.id)), u = i.messages.filter((e) => e.turnId === void 0 || !o.has(e.turnId)), d =
|
|
6119
|
-
r ? d = r(d) : this.originalImages && (d =
|
|
6167
|
+
let o = new Set(t.filter((e) => !a.has(e.id)).map((e) => e.id)), s = t.filter((e) => o.has(e.id)), c = i.turnIds.filter((e) => !o.has(e)), l = i.turns.filter((e) => !o.has(e.id)), u = i.messages.filter((e) => e.turnId === void 0 || !o.has(e.turnId)), d = Mn(i.messages, s.flatMap((t) => P(e, t)));
|
|
6168
|
+
r ? d = r(d) : this.originalImages && (d = Ji(d)), this.host.patchRuntime(e, {
|
|
6120
6169
|
turnIds: [...s.map((e) => e.id), ...c],
|
|
6121
|
-
turns: [...s.map((e) =>
|
|
6170
|
+
turns: [...s.map((e) => Z(e)), ...l],
|
|
6122
6171
|
messages: [...d, ...u]
|
|
6123
6172
|
}), i.historyItemsView === "summary" && this.hydrateOriginalImages(e);
|
|
6124
6173
|
let f = this.host.requireRuntime(e).turnIds.length, p = this.host.getState();
|
|
@@ -6130,7 +6179,7 @@ var es = class {
|
|
|
6130
6179
|
return m && this.host.emitSummaryUpserted(m, "updated", "action"), d.filter((e) => e.turnId !== void 0 && n.has(e.turnId));
|
|
6131
6180
|
}
|
|
6132
6181
|
summaryWithKnownTurnCount(e) {
|
|
6133
|
-
let t =
|
|
6182
|
+
let t = q(e), n = this.host.runtime(e.id);
|
|
6134
6183
|
if (n?.hydrated) return {
|
|
6135
6184
|
...t,
|
|
6136
6185
|
turnCount: n.turnIds.length
|
|
@@ -6176,7 +6225,7 @@ var ss = class {
|
|
|
6176
6225
|
}
|
|
6177
6226
|
threadStartSettings(e, t) {
|
|
6178
6227
|
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);
|
|
6179
|
-
if (r) return
|
|
6228
|
+
if (r) return Oa(r);
|
|
6180
6229
|
let i = e.approvalMode ?? this.defaults.approvalMode, a = e.permissionMode ?? this.defaults.permissionMode ?? "read-only";
|
|
6181
6230
|
return {
|
|
6182
6231
|
approvalPolicy: i === "ask" ? "on-request" : "never",
|
|
@@ -6202,23 +6251,23 @@ var ss = class {
|
|
|
6202
6251
|
async update(e) {
|
|
6203
6252
|
let t = this.host.getState(), n = t.activeConversationId;
|
|
6204
6253
|
if (!n) {
|
|
6205
|
-
let n =
|
|
6254
|
+
let n = Na(t, e);
|
|
6206
6255
|
if (e.approvalPreset && !t.approvalPresets.includes(e.approvalPreset)) throw Error(`Approval preset '${e.approvalPreset}' is not available`);
|
|
6207
6256
|
return this.host.patch(n), this.host.getSnapshot();
|
|
6208
6257
|
}
|
|
6209
6258
|
return await this.updateForThread(n, e), this.host.getSnapshot();
|
|
6210
6259
|
}
|
|
6211
6260
|
async updateForThread(e, t) {
|
|
6212
|
-
let n = await this.host.ensureThreadReady(e), r = this.host.snapshotForRuntime(n), i =
|
|
6261
|
+
let n = await this.host.ensureThreadReady(e), r = this.host.snapshotForRuntime(n), i = Na(r, t), a = n.approvalPreset !== i.approvalPreset || n.selectedModelId !== i.selectedModelId || n.selectedReasoningEffort !== i.selectedReasoningEffort || n.selectedServiceTier !== i.selectedServiceTier || n.planMode !== i.planMode;
|
|
6213
6262
|
if (t.approvalPreset && !r.approvalPresets.includes(t.approvalPreset)) throw Error(`Approval preset '${t.approvalPreset}' is not available`);
|
|
6214
|
-
let o =
|
|
6263
|
+
let o = K(this.host.getState().models, i.selectedModelId);
|
|
6215
6264
|
await this.client.request("thread/settings/update", {
|
|
6216
6265
|
threadId: e,
|
|
6217
|
-
...t.approvalPreset ?
|
|
6266
|
+
...t.approvalPreset ? ka(t.approvalPreset) : {},
|
|
6218
6267
|
...t.modelId && o ? { model: o.model } : {},
|
|
6219
6268
|
...t.reasoningEffort || t.modelId ? { effort: i.selectedReasoningEffort } : {},
|
|
6220
6269
|
...t.serviceTier !== void 0 || t.modelId ? { serviceTier: i.selectedServiceTier } : {},
|
|
6221
|
-
...o && (typeof t.planMode == "boolean" || t.modelId || t.reasoningEffort) ? { collaborationMode:
|
|
6270
|
+
...o && (typeof t.planMode == "boolean" || t.modelId || t.reasoningEffort) ? { collaborationMode: Pa(i.planMode, o.model, i.selectedReasoningEffort) } : {}
|
|
6222
6271
|
}), this.host.patchRuntime(e, i), a && this.host.emitConversationSettings(e, "action");
|
|
6223
6272
|
}
|
|
6224
6273
|
async setGoal(e, t) {
|
|
@@ -6237,7 +6286,7 @@ var ss = class {
|
|
|
6237
6286
|
...n === void 0 ? {} : { tokenBudget: n }
|
|
6238
6287
|
});
|
|
6239
6288
|
if (a.goal.threadId !== e) throw Error(`Codex thread/goal/set returned a goal for '${a.goal.threadId}' instead of '${e}'`);
|
|
6240
|
-
let o = !
|
|
6289
|
+
let o = !bo(r.goal, a.goal);
|
|
6241
6290
|
this.host.patchRuntime(e, { goal: { ...a.goal } }), o && this.host.emitEvent("action", {
|
|
6242
6291
|
type: "conversation.goalChanged",
|
|
6243
6292
|
conversationId: e,
|
|
@@ -6296,7 +6345,7 @@ var ss = class {
|
|
|
6296
6345
|
if (i.reviewThreadId !== e) throw Error(`Codex review/start returned unexpected review thread '${i.reviewThreadId}' for inline review on thread '${e}'`);
|
|
6297
6346
|
let a = n.turnIds.includes(i.turn.id);
|
|
6298
6347
|
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");
|
|
6299
|
-
let o =
|
|
6348
|
+
let o = P(e, i.turn).filter((e) => !n.messages.some((t) => t.id === e.id)).map((e) => e.role === "user" ? {
|
|
6300
6349
|
...e,
|
|
6301
6350
|
parts: r.type === "uncommittedChanges" ? e.parts.map((e) => e.type === "text" && e.text === "current changes" ? {
|
|
6302
6351
|
...e,
|
|
@@ -6310,8 +6359,8 @@ var ss = class {
|
|
|
6310
6359
|
this.host.patchRuntime(e, {
|
|
6311
6360
|
busy: n.activeTurnId !== null,
|
|
6312
6361
|
turnStartPending: !1,
|
|
6313
|
-
turns:
|
|
6314
|
-
messages: n.activeTurnId ?
|
|
6362
|
+
turns: Q(n.turns, Z(i.turn)),
|
|
6363
|
+
messages: n.activeTurnId ? A(s, e, i.turn.id) : s
|
|
6315
6364
|
});
|
|
6316
6365
|
for (let t of o) this.host.emitEvent("action", {
|
|
6317
6366
|
type: "message.appended",
|
|
@@ -6323,13 +6372,13 @@ var ss = class {
|
|
|
6323
6372
|
type: "turn.started",
|
|
6324
6373
|
conversationId: e,
|
|
6325
6374
|
turnId: i.turn.id,
|
|
6326
|
-
payload: { startedAt:
|
|
6375
|
+
payload: { startedAt: _o(i.turn.startedAt) }
|
|
6327
6376
|
}), this.host.emitConversationActivity(e, "action");
|
|
6328
6377
|
} catch (t) {
|
|
6329
6378
|
throw this.host.patchRuntime(e, {
|
|
6330
6379
|
busy: !1,
|
|
6331
6380
|
turnStartPending: !1,
|
|
6332
|
-
error:
|
|
6381
|
+
error: k(t)
|
|
6333
6382
|
}), this.host.patchConversationStatus(e, "error", "action"), this.host.emitConversationActivity(e, "action"), t;
|
|
6334
6383
|
}
|
|
6335
6384
|
}
|
|
@@ -6358,11 +6407,11 @@ var ss = class {
|
|
|
6358
6407
|
async editTurnForThread(e, t, n, r) {
|
|
6359
6408
|
let i = await this.host.ensureThreadReady(e);
|
|
6360
6409
|
i.turns.find((e) => e.id === t)?.itemsView === "summary" && await this.host.loadTurnHistory?.(e, t);
|
|
6361
|
-
let a = i.messages.find((e) => e.role === "user" && e.kind !== "steer" &&
|
|
6410
|
+
let a = i.messages.find((e) => e.role === "user" && e.kind !== "steer" && Va(e) === t);
|
|
6362
6411
|
if (!a) throw Error(`Could not find the user prompt for Codex turn '${t}'`);
|
|
6363
6412
|
let o = n.trim();
|
|
6364
6413
|
if (!o) throw Error("Cannot replace a turn prompt with empty content");
|
|
6365
|
-
let s =
|
|
6414
|
+
let s = Ua(a);
|
|
6366
6415
|
await this.rollbackToTurn(e, t), await this.host.sendMessageToThread(e, o, {
|
|
6367
6416
|
...r,
|
|
6368
6417
|
...s.length > 0 ? { attachments: s } : {}
|
|
@@ -6375,11 +6424,11 @@ var ss = class {
|
|
|
6375
6424
|
async retryTurnForThread(e, t) {
|
|
6376
6425
|
let n = await this.host.ensureThreadReady(e);
|
|
6377
6426
|
n.turns.find((e) => e.id === t)?.itemsView === "summary" && await this.host.loadTurnHistory?.(e, t);
|
|
6378
|
-
let r = n.messages.find((e) => e.role === "user" && e.kind !== "steer" &&
|
|
6427
|
+
let r = n.messages.find((e) => e.role === "user" && e.kind !== "steer" && Va(e) === t);
|
|
6379
6428
|
if (!r) throw Error("Could not find the user prompt for this turn");
|
|
6380
|
-
let i =
|
|
6429
|
+
let i = Ha(r);
|
|
6381
6430
|
if (!i) throw Error("Could not find the user prompt for this turn");
|
|
6382
|
-
let a =
|
|
6431
|
+
let a = Ua(r);
|
|
6383
6432
|
await this.rollbackToTurn(e, t), await this.host.sendMessageToThread(e, i, {
|
|
6384
6433
|
...r.metadata?.promptContent ? { content: le(r.metadata.promptContent) } : {},
|
|
6385
6434
|
...a.length > 0 ? { attachments: a } : {}
|
|
@@ -6400,15 +6449,15 @@ var ss = class {
|
|
|
6400
6449
|
});
|
|
6401
6450
|
if (i.thread.id !== e) throw Error(`Codex thread/revert returned '${i.thread.id}' for requested thread '${e}'`);
|
|
6402
6451
|
let a = r.turnIds.slice(0, n), o = new Set(a), s = r.messages.filter((e) => {
|
|
6403
|
-
let t =
|
|
6452
|
+
let t = Va(e);
|
|
6404
6453
|
return t === null || o.has(t);
|
|
6405
6454
|
});
|
|
6406
6455
|
r.turnIds = a, r.turns = r.turns.filter((e) => o.has(e.id)), r.activeTurnId = null;
|
|
6407
6456
|
let c = {
|
|
6408
|
-
...
|
|
6457
|
+
...q(i.thread),
|
|
6409
6458
|
turnCount: a.length
|
|
6410
6459
|
};
|
|
6411
|
-
this.host.patch({ conversations:
|
|
6460
|
+
this.host.patch({ conversations: J(this.host.getState().conversations, c) }), this.host.patchRuntime(e, {
|
|
6412
6461
|
messages: s,
|
|
6413
6462
|
answeredClientRequestIds: [],
|
|
6414
6463
|
busy: !1,
|
|
@@ -6493,8 +6542,8 @@ var ds = class {
|
|
|
6493
6542
|
let s = Qt(i);
|
|
6494
6543
|
if (s) return this.host.startReviewForThread(e, { target: s });
|
|
6495
6544
|
n = {
|
|
6496
|
-
...
|
|
6497
|
-
...n.skills ? { skills:
|
|
6545
|
+
...La(this.host.snapshotForRuntime(r), n),
|
|
6546
|
+
...n.skills ? { skills: await this.validatedSkills(r, n.skills) } : {}
|
|
6498
6547
|
}, await this.sendPromptToThread(e, i, n);
|
|
6499
6548
|
}
|
|
6500
6549
|
async continueInterruptedTurn() {
|
|
@@ -6517,49 +6566,49 @@ var ds = class {
|
|
|
6517
6566
|
let n = await this.client.request("turn/start", {
|
|
6518
6567
|
threadId: e,
|
|
6519
6568
|
input: [],
|
|
6520
|
-
...
|
|
6569
|
+
...Fa(this.host.snapshotForRuntime(t), {})
|
|
6521
6570
|
}), r = t.turnIds.includes(n.turn.id);
|
|
6522
6571
|
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");
|
|
6523
6572
|
let i = n.turn.status === "inProgress";
|
|
6524
6573
|
this.host.patchRuntime(e, {
|
|
6525
6574
|
busy: i,
|
|
6526
6575
|
turnStartPending: !1,
|
|
6527
|
-
turns:
|
|
6528
|
-
messages: i ?
|
|
6576
|
+
turns: Q(t.turns, Z(n.turn)),
|
|
6577
|
+
messages: i ? A(t.messages, e, n.turn.id) : t.messages
|
|
6529
6578
|
}), this.host.patchConversationStatus(e, i ? "active" : "idle", "action"), i && !r && this.host.emitEvent("action", {
|
|
6530
6579
|
type: "turn.started",
|
|
6531
6580
|
conversationId: e,
|
|
6532
6581
|
turnId: n.turn.id,
|
|
6533
|
-
payload: { startedAt:
|
|
6582
|
+
payload: { startedAt: _o(n.turn.startedAt) }
|
|
6534
6583
|
}), this.host.emitConversationActivity(e, "action");
|
|
6535
6584
|
} catch (t) {
|
|
6536
6585
|
throw this.host.patchRuntime(e, {
|
|
6537
6586
|
busy: !1,
|
|
6538
6587
|
turnStartPending: !1,
|
|
6539
|
-
error:
|
|
6588
|
+
error: k(t)
|
|
6540
6589
|
}), this.host.patchConversationStatus(e, "error", "action"), this.host.emitConversationActivity(e, "action"), t;
|
|
6541
6590
|
}
|
|
6542
6591
|
}
|
|
6543
6592
|
async sendPromptToThread(e, t, n = {}, r) {
|
|
6544
|
-
let i = this.host.requireRuntime(e), a =
|
|
6593
|
+
let i = this.host.requireRuntime(e), a = La(this.host.snapshotForRuntime(i), n), o = en(a.content);
|
|
6545
6594
|
o && (a.content = o);
|
|
6546
|
-
let s = o ? de(o) : r?.trim() || t, c =
|
|
6595
|
+
let s = o ? de(o) : r?.trim() || t, c = await this.validatedSkills(i, an(tn(o), a.skills ?? [])), l = Ra(a.attachments ?? []);
|
|
6547
6596
|
if (i.busy) {
|
|
6548
6597
|
this.host.patchRuntime(e, { queuedPrompts: [...i.queuedPrompts, {
|
|
6549
|
-
id:
|
|
6598
|
+
id: So(),
|
|
6550
6599
|
text: s,
|
|
6551
6600
|
...Object.keys(a).length > 0 ? { options: a } : {}
|
|
6552
6601
|
}] }), this.emitQueuedPrompts(e);
|
|
6553
6602
|
return;
|
|
6554
6603
|
}
|
|
6555
|
-
let u =
|
|
6604
|
+
let u = xo(), d = {
|
|
6556
6605
|
id: u,
|
|
6557
6606
|
role: "user",
|
|
6558
6607
|
status: "complete",
|
|
6559
6608
|
parts: [{
|
|
6560
6609
|
type: "text",
|
|
6561
6610
|
text: s
|
|
6562
|
-
}, ...l.map(
|
|
6611
|
+
}, ...l.map(Ba)],
|
|
6563
6612
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6564
6613
|
metadata: {
|
|
6565
6614
|
conversationId: e,
|
|
@@ -6587,7 +6636,7 @@ var ds = class {
|
|
|
6587
6636
|
text: ue(o ?? [], t),
|
|
6588
6637
|
text_elements: []
|
|
6589
6638
|
},
|
|
6590
|
-
...l.map(
|
|
6639
|
+
...l.map(za),
|
|
6591
6640
|
...nn(o),
|
|
6592
6641
|
...c.map((e) => ({
|
|
6593
6642
|
type: "skill",
|
|
@@ -6595,7 +6644,7 @@ var ds = class {
|
|
|
6595
6644
|
path: e.path
|
|
6596
6645
|
}))
|
|
6597
6646
|
],
|
|
6598
|
-
...
|
|
6647
|
+
...Fa(this.host.snapshotForRuntime(i), a),
|
|
6599
6648
|
...a.outputSchema === void 0 ? {} : { outputSchema: a.outputSchema }
|
|
6600
6649
|
}), r = i.turnIds.includes(n.turn.id);
|
|
6601
6650
|
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");
|
|
@@ -6610,8 +6659,8 @@ var ds = class {
|
|
|
6610
6659
|
this.host.patchRuntime(e, {
|
|
6611
6660
|
busy: s,
|
|
6612
6661
|
turnStartPending: !1,
|
|
6613
|
-
turns:
|
|
6614
|
-
messages: s ?
|
|
6662
|
+
turns: Q(i.turns, Z(n.turn)),
|
|
6663
|
+
messages: s ? A(d, e, n.turn.id) : d
|
|
6615
6664
|
}), this.host.patchConversationStatus(e, s ? "active" : "idle", "action");
|
|
6616
6665
|
let f = d.find((e) => e.id === u);
|
|
6617
6666
|
f && this.host.emitEvent("action", {
|
|
@@ -6623,13 +6672,13 @@ var ds = class {
|
|
|
6623
6672
|
type: "turn.started",
|
|
6624
6673
|
conversationId: e,
|
|
6625
6674
|
turnId: n.turn.id,
|
|
6626
|
-
payload: { startedAt:
|
|
6675
|
+
payload: { startedAt: _o(n.turn.startedAt) }
|
|
6627
6676
|
}), this.host.emitConversationActivity(e, "action");
|
|
6628
6677
|
} catch (t) {
|
|
6629
6678
|
throw this.host.patchRuntime(e, {
|
|
6630
6679
|
busy: !1,
|
|
6631
6680
|
turnStartPending: !1,
|
|
6632
|
-
error:
|
|
6681
|
+
error: k(t)
|
|
6633
6682
|
}), this.host.patchConversationStatus(e, "error", "action"), this.host.emitConversationActivity(e, "action"), t;
|
|
6634
6683
|
}
|
|
6635
6684
|
}
|
|
@@ -6638,10 +6687,10 @@ var ds = class {
|
|
|
6638
6687
|
return await this.steerForThread(n, e, t), this.host.getSnapshot();
|
|
6639
6688
|
}
|
|
6640
6689
|
async steerForThread(e, t, n = {}, r) {
|
|
6641
|
-
let i = await this.host.ensureThreadReady(e), a = t.trim(), o = en(n.content), s =
|
|
6690
|
+
let i = await this.host.ensureThreadReady(e), a = t.trim(), o = en(n.content), s = await this.validatedSkills(i, an(tn(o), n.skills ?? [])), c = o ? de(o) : r?.trim() || a;
|
|
6642
6691
|
if (!a) throw Error("Cannot steer with an empty message");
|
|
6643
6692
|
if (!i.activeTurnId) throw Error("There is no active turn to steer");
|
|
6644
|
-
let l =
|
|
6693
|
+
let l = Ra(n.attachments ?? []), u = xo(), d = {
|
|
6645
6694
|
id: u,
|
|
6646
6695
|
kind: "steer",
|
|
6647
6696
|
role: "user",
|
|
@@ -6649,7 +6698,7 @@ var ds = class {
|
|
|
6649
6698
|
parts: [{
|
|
6650
6699
|
type: "text",
|
|
6651
6700
|
text: c
|
|
6652
|
-
}, ...l.map(
|
|
6701
|
+
}, ...l.map(Ba)],
|
|
6653
6702
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6654
6703
|
turnId: i.activeTurnId,
|
|
6655
6704
|
metadata: {
|
|
@@ -6661,7 +6710,7 @@ var ds = class {
|
|
|
6661
6710
|
};
|
|
6662
6711
|
this.host.patchRuntime(e, {
|
|
6663
6712
|
error: null,
|
|
6664
|
-
messages:
|
|
6713
|
+
messages: A([...i.messages, d], e, i.activeTurnId, { forceSegment: !0 })
|
|
6665
6714
|
}), this.host.emitEvent("action", {
|
|
6666
6715
|
type: "message.appended",
|
|
6667
6716
|
conversationId: e,
|
|
@@ -6679,7 +6728,7 @@ var ds = class {
|
|
|
6679
6728
|
text: ue(o ?? [], a),
|
|
6680
6729
|
text_elements: []
|
|
6681
6730
|
},
|
|
6682
|
-
...l.map(
|
|
6731
|
+
...l.map(za),
|
|
6683
6732
|
...nn(o),
|
|
6684
6733
|
...s.map((e) => ({
|
|
6685
6734
|
type: "skill",
|
|
@@ -6688,7 +6737,7 @@ var ds = class {
|
|
|
6688
6737
|
}))
|
|
6689
6738
|
]
|
|
6690
6739
|
}), n = i.turnIds.includes(t.turnId);
|
|
6691
|
-
i.activeTurnId = t.turnId, i.turnIds.includes(t.turnId) || i.turnIds.push(t.turnId), i.turns =
|
|
6740
|
+
i.activeTurnId = t.turnId, i.turnIds.includes(t.turnId) || i.turnIds.push(t.turnId), i.turns = Q(i.turns, {
|
|
6692
6741
|
id: t.turnId,
|
|
6693
6742
|
status: "inProgress",
|
|
6694
6743
|
error: null,
|
|
@@ -6705,14 +6754,14 @@ var ds = class {
|
|
|
6705
6754
|
turnId: t.turnId
|
|
6706
6755
|
}
|
|
6707
6756
|
} : e);
|
|
6708
|
-
this.host.patchRuntime(e, { messages:
|
|
6757
|
+
this.host.patchRuntime(e, { messages: M(A(r, e, t.turnId), e) }), n || this.host.emitEvent("action", {
|
|
6709
6758
|
type: "turn.started",
|
|
6710
6759
|
conversationId: e,
|
|
6711
6760
|
turnId: t.turnId,
|
|
6712
6761
|
payload: { startedAt: (/* @__PURE__ */ new Date()).toISOString() }
|
|
6713
6762
|
});
|
|
6714
6763
|
} catch (t) {
|
|
6715
|
-
throw this.host.patchRuntime(e, { error:
|
|
6764
|
+
throw this.host.patchRuntime(e, { error: k(t) }), t;
|
|
6716
6765
|
}
|
|
6717
6766
|
}
|
|
6718
6767
|
async answerAsyncQuestion(e, t, n) {
|
|
@@ -6738,23 +6787,23 @@ var ds = class {
|
|
|
6738
6787
|
async updateQueuedPromptForThread(e, t, n, r) {
|
|
6739
6788
|
let i = await this.host.ensureThreadReady(e), a = n.trim();
|
|
6740
6789
|
if (!a) throw Error("Cannot update a queued prompt with empty content");
|
|
6741
|
-
let o =
|
|
6790
|
+
let o = en(r?.content);
|
|
6791
|
+
i.queuedPrompts.some((e) => e.id === t) && await this.validatedSkills(i, tn(o));
|
|
6792
|
+
let s = !1, c = i.queuedPrompts.map((e) => {
|
|
6742
6793
|
if (e.id !== t) return e;
|
|
6743
|
-
|
|
6744
|
-
let n =
|
|
6745
|
-
O(tn(n), i.skills);
|
|
6746
|
-
let s = {
|
|
6794
|
+
s = !0;
|
|
6795
|
+
let n = {
|
|
6747
6796
|
...e.options,
|
|
6748
6797
|
...r
|
|
6749
6798
|
};
|
|
6750
|
-
return
|
|
6799
|
+
return o ? n.content = o : delete n.content, {
|
|
6751
6800
|
...e,
|
|
6752
6801
|
text: a,
|
|
6753
|
-
options:
|
|
6802
|
+
options: n
|
|
6754
6803
|
};
|
|
6755
6804
|
});
|
|
6756
|
-
if (!
|
|
6757
|
-
this.host.patchRuntime(i.threadId, { queuedPrompts:
|
|
6805
|
+
if (!s) throw Error(`Unknown queued prompt '${t}'`);
|
|
6806
|
+
this.host.patchRuntime(i.threadId, { queuedPrompts: c }), this.emitQueuedPrompts(i.threadId);
|
|
6758
6807
|
}
|
|
6759
6808
|
async steerQueuedPrompt(e, t, n) {
|
|
6760
6809
|
let r = this.requiredActiveConversation();
|
|
@@ -6780,7 +6829,7 @@ var ds = class {
|
|
|
6780
6829
|
await this.sendPromptToThread(e, n.text, n.options);
|
|
6781
6830
|
} catch (r) {
|
|
6782
6831
|
this.host.patchRuntime(e, {
|
|
6783
|
-
error:
|
|
6832
|
+
error: k(r),
|
|
6784
6833
|
queuedPrompts: [n, ...t.queuedPrompts]
|
|
6785
6834
|
}), this.emitQueuedPrompts(e, "notification");
|
|
6786
6835
|
}
|
|
@@ -6798,6 +6847,9 @@ var ds = class {
|
|
|
6798
6847
|
if (!e) throw Error("There is no active conversation");
|
|
6799
6848
|
return e;
|
|
6800
6849
|
}
|
|
6850
|
+
async validatedSkills(e, t) {
|
|
6851
|
+
return t.length > 0 && e.skillCatalogStatus !== "loaded" && await this.host.loadSkillsForThread(e.threadId), rn(t, e.skills);
|
|
6852
|
+
}
|
|
6801
6853
|
}, fs = 5, ps = class {
|
|
6802
6854
|
client;
|
|
6803
6855
|
options;
|
|
@@ -6837,8 +6889,8 @@ var ds = class {
|
|
|
6837
6889
|
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({
|
|
6838
6890
|
...e,
|
|
6839
6891
|
...a ? { approvalPreset: a } : {}
|
|
6840
|
-
}, r.approvalPresets), s =
|
|
6841
|
-
|
|
6892
|
+
}, r.approvalPresets), s = K(i.models, i.selectedModelId), c = e.model ? xa(i.models, e.model) : s, l = c?.model, u = e.reasoningEffort ?? (c?.id === s?.id ? i.selectedReasoningEffort : c ? Ca(c) : null) ?? void 0, d = e.serviceTier === void 0 ? c?.id === s?.id ? i.selectedServiceTier ?? null : c?.defaultServiceTier ?? null : e.serviceTier;
|
|
6893
|
+
Sa(c, u), Ta(c, d);
|
|
6842
6894
|
let f = t.mcpServers === void 0 ? this.extensions.defaultMcpServers : qo(t.mcpServers), p = await this.extensions.conversationExtension({
|
|
6843
6895
|
operation: "start",
|
|
6844
6896
|
conversationId: null,
|
|
@@ -6858,11 +6910,11 @@ var ds = class {
|
|
|
6858
6910
|
serviceName: "codex_app_sdk"
|
|
6859
6911
|
});
|
|
6860
6912
|
this.host.observeEmptyConversation(m.thread.id);
|
|
6861
|
-
let h =
|
|
6913
|
+
let h = ja(m, i.models, i);
|
|
6862
6914
|
u && (await this.client.request("thread/settings/update", {
|
|
6863
6915
|
threadId: m.thread.id,
|
|
6864
6916
|
effort: u,
|
|
6865
|
-
...c ? { collaborationMode:
|
|
6917
|
+
...c ? { collaborationMode: Pa(i.planMode, c.model, u) } : {}
|
|
6866
6918
|
}), h.selectedReasoningEffort = u), d !== void 0 && (h.selectedServiceTier = d), c && (h.selectedModelId = c.id), a && (h.approvalPreset = a);
|
|
6867
6919
|
let g = this.host.createRuntime(m.thread.id, {
|
|
6868
6920
|
hydrated: !0,
|
|
@@ -6873,7 +6925,7 @@ var ds = class {
|
|
|
6873
6925
|
turnIds: [],
|
|
6874
6926
|
messages: [],
|
|
6875
6927
|
answeredClientRequestIds: [],
|
|
6876
|
-
threadStatus:
|
|
6928
|
+
threadStatus: Ka(m.thread.status),
|
|
6877
6929
|
...r,
|
|
6878
6930
|
...h
|
|
6879
6931
|
});
|
|
@@ -6882,10 +6934,10 @@ var ds = class {
|
|
|
6882
6934
|
...t,
|
|
6883
6935
|
mcpServers: f
|
|
6884
6936
|
});
|
|
6885
|
-
let _ =
|
|
6937
|
+
let _ = q(m.thread);
|
|
6886
6938
|
return this.host.patch({
|
|
6887
6939
|
activeConversationId: m.thread.id,
|
|
6888
|
-
conversations:
|
|
6940
|
+
conversations: J(i.conversations, _),
|
|
6889
6941
|
...this.host.runtimeProjection(g)
|
|
6890
6942
|
}), this.host.emitSummaryUpserted(_, "created", "action"), this.host.emitSelected(m.thread.id), this.emitConversationState(m.thread.id), this.host.getSnapshot();
|
|
6891
6943
|
}
|
|
@@ -6941,19 +6993,19 @@ var ds = class {
|
|
|
6941
6993
|
historyLoadingOlder: !1,
|
|
6942
6994
|
fullHistoryHydrated: !0,
|
|
6943
6995
|
busy: !!n.activeTurnId,
|
|
6944
|
-
threadStatus:
|
|
6996
|
+
threadStatus: Ka(t.thread.status)
|
|
6945
6997
|
}), i = {
|
|
6946
|
-
...
|
|
6998
|
+
...q(t.thread),
|
|
6947
6999
|
turnCount: r.turnIds.length
|
|
6948
7000
|
}, a = this.host.getState();
|
|
6949
7001
|
return this.host.patch({
|
|
6950
|
-
conversations:
|
|
7002
|
+
conversations: J(a.conversations, i),
|
|
6951
7003
|
...a.activeConversationId === e ? this.host.runtimeProjection(r) : {}
|
|
6952
7004
|
}), this.host.emitSummaryUpserted(i, "updated", "action"), this.host.emitHistoryReplaced(e, "resync", "action"), this.host.emitConversationActivity(e, "action"), this.historySnapshot(e, r);
|
|
6953
7005
|
} catch (t) {
|
|
6954
7006
|
throw this.host.patchRuntime(e, {
|
|
6955
7007
|
historyLoading: !1,
|
|
6956
|
-
error:
|
|
7008
|
+
error: k(t)
|
|
6957
7009
|
}), t;
|
|
6958
7010
|
}
|
|
6959
7011
|
}
|
|
@@ -6961,21 +7013,35 @@ var ds = class {
|
|
|
6961
7013
|
let i = {
|
|
6962
7014
|
...this.hostOptionsByThread.get(e),
|
|
6963
7015
|
...n
|
|
6964
|
-
}, a = {
|
|
7016
|
+
}, a = performance.now(), o = a, s = (t) => {
|
|
7017
|
+
let n = performance.now();
|
|
7018
|
+
process.env.CODEX_APP_SDK_TRACE_CONVERSATION_LOAD === "1" && console.warn("[conversation-load] " + JSON.stringify({
|
|
7019
|
+
layer: "codex-sdk",
|
|
7020
|
+
stage: t,
|
|
7021
|
+
threadId: e,
|
|
7022
|
+
at: performance.timeOrigin + n,
|
|
7023
|
+
stageMs: n - o,
|
|
7024
|
+
elapsedMs: n - a
|
|
7025
|
+
})), o = n;
|
|
7026
|
+
};
|
|
7027
|
+
s("resume.begin");
|
|
7028
|
+
let c = {
|
|
6965
7029
|
...i,
|
|
6966
7030
|
mcpServers: i.mcpServers === void 0 ? this.extensions.defaultMcpServers : qo(i.mcpServers)
|
|
6967
7031
|
};
|
|
6968
|
-
this.hostOptionsByThread.set(e,
|
|
6969
|
-
let
|
|
7032
|
+
this.hostOptionsByThread.set(e, c);
|
|
7033
|
+
let l = await this.extensions.conversationExtension({
|
|
6970
7034
|
operation: "resume",
|
|
6971
7035
|
conversationId: e,
|
|
6972
|
-
cwd:
|
|
6973
|
-
extensionContext:
|
|
6974
|
-
}, {},
|
|
7036
|
+
cwd: c.cwd,
|
|
7037
|
+
extensionContext: c.extensionContext
|
|
7038
|
+
}, {}, c.mcpServers);
|
|
7039
|
+
s("extensions.ready");
|
|
7040
|
+
let u = c.historyItemsView ?? this.options.historyItemsView ?? "full", d = this.host.createRuntime(e, {
|
|
6975
7041
|
historyLoading: !0,
|
|
6976
7042
|
error: null
|
|
6977
|
-
}),
|
|
6978
|
-
t && this.host.activateRuntime(
|
|
7043
|
+
}), f = new Map(d.turns.map((e) => [e.id, e])), p = new Map(d.messages.map((e) => [e.id, e])), m = d.threadStatus;
|
|
7044
|
+
t && this.host.activateRuntime(d);
|
|
6979
7045
|
try {
|
|
6980
7046
|
let [t, n] = await Promise.all([this.client.request("thread/resume", {
|
|
6981
7047
|
threadId: e,
|
|
@@ -6983,72 +7049,82 @@ var ds = class {
|
|
|
6983
7049
|
initialTurnsPage: {
|
|
6984
7050
|
limit: fs,
|
|
6985
7051
|
sortDirection: "desc",
|
|
6986
|
-
itemsView:
|
|
7052
|
+
itemsView: u
|
|
6987
7053
|
},
|
|
6988
|
-
...
|
|
6989
|
-
...
|
|
6990
|
-
...
|
|
6991
|
-
...
|
|
7054
|
+
...c.cwd ? { cwd: c.cwd } : {},
|
|
7055
|
+
...l.baseInstructions === void 0 ? {} : { baseInstructions: l.baseInstructions },
|
|
7056
|
+
...l.developerInstructions === void 0 ? {} : { developerInstructions: l.developerInstructions },
|
|
7057
|
+
...l.config === void 0 ? {} : { config: l.config }
|
|
6992
7058
|
}), this.client.request("thread/goal/get", { threadId: e }).then((e) => e.goal).catch(() => null)]);
|
|
6993
|
-
if (t.thread.id !== e) throw Error(`Codex thread/resume returned '${t.thread.id}' for requested thread '${e}'`);
|
|
7059
|
+
if (s("resume-and-goal.ready"), t.thread.id !== e) throw Error(`Codex thread/resume returned '${t.thread.id}' for requested thread '${e}'`);
|
|
6994
7060
|
let i = t.initialTurnsPage ?? await this.client.request("thread/turns/list", {
|
|
6995
7061
|
threadId: t.thread.id,
|
|
6996
7062
|
cursor: null,
|
|
6997
7063
|
limit: fs,
|
|
6998
7064
|
sortDirection: "desc",
|
|
6999
|
-
itemsView:
|
|
7000
|
-
}),
|
|
7065
|
+
itemsView: u
|
|
7066
|
+
}), a = await Promise.all([...i.data].reverse().map(async (e) => e.status === "inProgress" && (e.itemsView === "summary" || e.itemsView === "notLoaded") ? {
|
|
7001
7067
|
...e,
|
|
7002
7068
|
items: await os(this.client, t.thread.id, e.id),
|
|
7003
7069
|
itemsView: "full"
|
|
7004
|
-
} : e))
|
|
7070
|
+
} : e));
|
|
7071
|
+
s("initial-page-and-active-items.ready");
|
|
7072
|
+
let o = t.cwd ?? t.thread.cwd ?? c.cwd, h = await this.catalog.loadConversationCatalogs(o);
|
|
7073
|
+
s("permission-catalog.ready");
|
|
7074
|
+
let g = u === "full" ? await this.originalImages?.prepare(t.thread.id, t.thread.path) : void 0;
|
|
7075
|
+
s("original-images.ready");
|
|
7076
|
+
let _ = d.turns.filter((e) => f.get(e.id) !== e), v = d.threadStatus !== m && d.threadStatus ? d.threadStatus : Ka(t.thread.status), y = a.map((e) => v.type === "idle" && e.status === "inProgress" ? {
|
|
7005
7077
|
...e,
|
|
7006
7078
|
status: "interrupted"
|
|
7007
|
-
} : e),
|
|
7008
|
-
...
|
|
7009
|
-
...
|
|
7079
|
+
} : e), b = new Set(d.turns.filter((e) => e.itemsView !== "summary").map((e) => e.id)), x = new Map(y.map((e) => [e.id, e.itemsView === "summary" && b.has(e.id) ? {
|
|
7080
|
+
...d.turns.find((t) => t.id === e.id),
|
|
7081
|
+
...Z(e),
|
|
7010
7082
|
itemsView: "full"
|
|
7011
|
-
} :
|
|
7012
|
-
for (let e of
|
|
7013
|
-
let
|
|
7014
|
-
for (let e of
|
|
7015
|
-
let
|
|
7016
|
-
|
|
7017
|
-
let
|
|
7083
|
+
} : Z(e)]));
|
|
7084
|
+
for (let e of _) x.set(e.id, e);
|
|
7085
|
+
let S = _.length > 0 ? d.activeTurnId : v.type === "active" ? dn(a) : null, ee = Mn(d.messages, y.flatMap((e) => e.itemsView === "summary" && b.has(e.id) ? d.messages.filter((t) => t.turnId === e.id) : P(t.thread.id, e))), te = new Map(ee.map((e) => [e.id, e]));
|
|
7086
|
+
for (let e of d.messages) p.get(e.id) !== e && te.set(e.id, e);
|
|
7087
|
+
let ne = S ? A([...te.values()], t.thread.id, S) : [...te.values()];
|
|
7088
|
+
g && (ne = g(ne)), s("messages.projected");
|
|
7089
|
+
let re = this.host.createRuntime(t.thread.id, {
|
|
7018
7090
|
hydrated: !0,
|
|
7019
7091
|
historyMode: t.thread.historyMode ?? "legacy",
|
|
7020
|
-
loadingStrategy:
|
|
7021
|
-
historyItemsView:
|
|
7092
|
+
loadingStrategy: c.loadingStrategy ?? this.options.loadingStrategy ?? "lazy",
|
|
7093
|
+
historyItemsView: u,
|
|
7022
7094
|
historyCursor: i.nextCursor,
|
|
7023
7095
|
historyHasOlder: i.nextCursor !== null,
|
|
7024
7096
|
historyLoadingOlder: !1,
|
|
7025
7097
|
fullHistoryHydrated: i.nextCursor === null,
|
|
7026
|
-
cwd:
|
|
7098
|
+
cwd: o ?? null,
|
|
7027
7099
|
historyLoading: !1,
|
|
7028
|
-
activeTurnId:
|
|
7029
|
-
turns: [...
|
|
7030
|
-
turnIds: [...
|
|
7031
|
-
messages:
|
|
7032
|
-
busy:
|
|
7100
|
+
activeTurnId: S,
|
|
7101
|
+
turns: [...x.values()],
|
|
7102
|
+
turnIds: [...x.keys()],
|
|
7103
|
+
messages: ne,
|
|
7104
|
+
busy: _.length > 0 ? d.busy : !!S || v.type === "active",
|
|
7033
7105
|
goal: n ? { ...n } : null,
|
|
7034
|
-
threadStatus:
|
|
7035
|
-
...
|
|
7036
|
-
...
|
|
7037
|
-
}),
|
|
7038
|
-
...
|
|
7039
|
-
turnCount:
|
|
7040
|
-
}
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
|
|
7044
|
-
|
|
7106
|
+
threadStatus: v,
|
|
7107
|
+
...h,
|
|
7108
|
+
...ja(t, this.host.getState().models, this.host.snapshotForRuntime(d))
|
|
7109
|
+
}), ie = {
|
|
7110
|
+
...q(t.thread),
|
|
7111
|
+
turnCount: a.length
|
|
7112
|
+
};
|
|
7113
|
+
s("runtime.created");
|
|
7114
|
+
let ae = this.host.getState();
|
|
7115
|
+
this.host.patch({
|
|
7116
|
+
conversations: J(ae.conversations, ie),
|
|
7117
|
+
...ae.activeConversationId === t.thread.id ? this.host.runtimeProjection(re) : {}
|
|
7118
|
+
}), this.host.emitSummaryUpserted(ie, "resumed", "action"), this.host.emitHistoryReplaced(t.thread.id, r, "action"), this.emitConversationState(t.thread.id), s("events.published"), u === "summary" && this.conversations.hydrateOriginalImages(t.thread.id, t.thread.path), re.loadingStrategy === "eager" && i.nextCursor !== null && this.conversations.hydrateCompleteHistory(t.thread.id, {
|
|
7045
7119
|
cursor: i.nextCursor,
|
|
7046
7120
|
initialPageLoaded: !0
|
|
7047
|
-
}).catch(() => void 0)
|
|
7121
|
+
}).catch(() => void 0);
|
|
7122
|
+
let oe = this.host.getSnapshot();
|
|
7123
|
+
return s("snapshot.cloned"), oe;
|
|
7048
7124
|
} catch (t) {
|
|
7049
|
-
throw this.host.patchRuntime(e, {
|
|
7125
|
+
throw s("resume.failed"), this.host.patchRuntime(e, {
|
|
7050
7126
|
historyLoading: !1,
|
|
7051
|
-
error:
|
|
7127
|
+
error: k(t)
|
|
7052
7128
|
}), t;
|
|
7053
7129
|
}
|
|
7054
7130
|
}
|
|
@@ -7078,16 +7154,16 @@ var ds = class {
|
|
|
7078
7154
|
case "thread/started": {
|
|
7079
7155
|
this.host.createRuntime(e.params.thread.id, {
|
|
7080
7156
|
historyMode: e.params.thread.historyMode ?? "legacy",
|
|
7081
|
-
threadStatus:
|
|
7157
|
+
threadStatus: Ka(e.params.thread.status)
|
|
7082
7158
|
});
|
|
7083
|
-
let t =
|
|
7084
|
-
this.host.patch({ conversations:
|
|
7159
|
+
let t = q(e.params.thread);
|
|
7160
|
+
this.host.patch({ conversations: J(this.host.getState().conversations, t) }), this.host.emitSummaryUpserted(t, "started", "notification"), this.host.emitConversationActivity(e.params.thread.id, "notification");
|
|
7085
7161
|
return;
|
|
7086
7162
|
}
|
|
7087
7163
|
case "thread/status/changed": {
|
|
7088
7164
|
let { threadId: t, status: n } = e.params, r = this.host.requireRuntime(t), i = n.type === "systemError";
|
|
7089
7165
|
(i || n.type === "idle" && !r.turnStartPending) && (r.activeTurnId = null), this.host.patchRuntime(t, {
|
|
7090
|
-
threadStatus:
|
|
7166
|
+
threadStatus: Ka(n),
|
|
7091
7167
|
busy: i ? !1 : r.turnStartPending || n.type === "active" || r.activeTurnId !== null,
|
|
7092
7168
|
...i ? {
|
|
7093
7169
|
turnStartPending: !1,
|
|
@@ -7097,7 +7173,7 @@ var ds = class {
|
|
|
7097
7173
|
let a = this.host.getState();
|
|
7098
7174
|
this.host.patch({ conversations: a.conversations.map((e) => e.id === t ? {
|
|
7099
7175
|
...e,
|
|
7100
|
-
status:
|
|
7176
|
+
status: qa(n)
|
|
7101
7177
|
} : e) });
|
|
7102
7178
|
let o = this.host.getState().conversations.find((e) => e.id === t);
|
|
7103
7179
|
o && this.host.emitSummaryUpserted(o, "updated", "notification"), this.host.emitConversationActivity(t, "notification"), n.type === "idle" && this.host.sendNextQueuedPrompt(t);
|
|
@@ -7109,7 +7185,7 @@ var ds = class {
|
|
|
7109
7185
|
return;
|
|
7110
7186
|
case "thread/unarchived":
|
|
7111
7187
|
this.conversations.load().catch((e) => {
|
|
7112
|
-
this.host.patch({ error:
|
|
7188
|
+
this.host.patch({ error: k(e) });
|
|
7113
7189
|
});
|
|
7114
7190
|
return;
|
|
7115
7191
|
case "thread/closed": {
|
|
@@ -7122,10 +7198,7 @@ var ds = class {
|
|
|
7122
7198
|
return;
|
|
7123
7199
|
}
|
|
7124
7200
|
case "skills/changed":
|
|
7125
|
-
this.catalog.
|
|
7126
|
-
for (let e of this.host.runtimes()) this.catalog.loadConversationCatalogs(e.cwd ?? void 0, !0).then((t) => {
|
|
7127
|
-
this.host.patchRuntime(e.threadId, t), this.host.emitConversationSkills(e.threadId, "notification"), this.host.emitConversationPermissions(e.threadId, "notification");
|
|
7128
|
-
});
|
|
7201
|
+
this.catalog.invalidateSkills();
|
|
7129
7202
|
return;
|
|
7130
7203
|
case "thread/name/updated": {
|
|
7131
7204
|
let t = this.host.getState(), n = t.conversations.find((t) => t.id === e.params.threadId), r = e.params.threadName?.trim() || n?.preview || "Untitled conversation";
|
|
@@ -7139,12 +7212,12 @@ var ds = class {
|
|
|
7139
7212
|
return;
|
|
7140
7213
|
}
|
|
7141
7214
|
case "thread/settings/updated": {
|
|
7142
|
-
let t = this.host.requireRuntime(e.params.threadId), n = this.host.getState(), r =
|
|
7215
|
+
let t = this.host.requireRuntime(e.params.threadId), n = this.host.getState(), r = Ma(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;
|
|
7143
7216
|
this.host.patchRuntime(e.params.threadId, r), i && this.host.emitConversationSettings(e.params.threadId, "notification");
|
|
7144
7217
|
return;
|
|
7145
7218
|
}
|
|
7146
7219
|
case "thread/goal/updated":
|
|
7147
|
-
if (
|
|
7220
|
+
if (bo(this.host.requireRuntime(e.params.threadId).goal, e.params.goal)) return;
|
|
7148
7221
|
this.host.patchRuntime(e.params.threadId, { goal: { ...e.params.goal } }), this.host.emitEvent("notification", {
|
|
7149
7222
|
type: "conversation.goalChanged",
|
|
7150
7223
|
conversationId: e.params.threadId,
|
|
@@ -7161,7 +7234,7 @@ var ds = class {
|
|
|
7161
7234
|
});
|
|
7162
7235
|
return;
|
|
7163
7236
|
case "thread/tokenUsage/updated": {
|
|
7164
|
-
let t =
|
|
7237
|
+
let t = Ga(e.params.tokenUsage);
|
|
7165
7238
|
this.host.patchRuntime(e.params.threadId, { contextUsage: t }), this.host.emitEvent("notification", {
|
|
7166
7239
|
type: "conversation.contextUsageChanged",
|
|
7167
7240
|
conversationId: e.params.threadId,
|
|
@@ -7172,8 +7245,8 @@ var ds = class {
|
|
|
7172
7245
|
conversationId: e.params.threadId,
|
|
7173
7246
|
turnId: e.params.turnId,
|
|
7174
7247
|
payload: { usage: {
|
|
7175
|
-
last:
|
|
7176
|
-
total:
|
|
7248
|
+
last: Wa(e.params.tokenUsage.last),
|
|
7249
|
+
total: Wa(e.params.tokenUsage.total),
|
|
7177
7250
|
execution: null,
|
|
7178
7251
|
model: null,
|
|
7179
7252
|
observedStart: !1
|
|
@@ -7200,13 +7273,13 @@ var ds = class {
|
|
|
7200
7273
|
turnStartPending: !1,
|
|
7201
7274
|
error: null,
|
|
7202
7275
|
turnGitDiff: null,
|
|
7203
|
-
turns:
|
|
7204
|
-
messages:
|
|
7276
|
+
turns: Q(t.turns, Z(e.params.turn)),
|
|
7277
|
+
messages: A(t.messages, e.params.threadId, e.params.turn.id, { createdAt: _o(e.params.turn.startedAt) })
|
|
7205
7278
|
}), this.host.patchConversationStatus(e.params.threadId, "active"), n || this.host.emitEvent("notification", {
|
|
7206
7279
|
type: "turn.started",
|
|
7207
7280
|
conversationId: e.params.threadId,
|
|
7208
7281
|
turnId: e.params.turn.id,
|
|
7209
|
-
payload: { startedAt:
|
|
7282
|
+
payload: { startedAt: _o(e.params.turn.startedAt) }
|
|
7210
7283
|
}), this.host.emitConversationActivity(e.params.threadId, "notification");
|
|
7211
7284
|
return;
|
|
7212
7285
|
}
|
|
@@ -7258,7 +7331,7 @@ var ds = class {
|
|
|
7258
7331
|
}
|
|
7259
7332
|
case "thread/compacted": {
|
|
7260
7333
|
let t = this.host.requireRuntime(e.params.threadId);
|
|
7261
|
-
this.host.patchRuntime(e.params.threadId, { messages:
|
|
7334
|
+
this.host.patchRuntime(e.params.threadId, { messages: Sn(t.messages, e.params.threadId, e.params.turnId, "complete") });
|
|
7262
7335
|
let n = this.host.requireRuntime(e.params.threadId).messages.find((t) => t.kind === "compaction" && t.metadata?.turnId === e.params.turnId);
|
|
7263
7336
|
this.host.emitEvent("notification", {
|
|
7264
7337
|
type: "context.compactionCompleted",
|
|
@@ -7278,7 +7351,7 @@ var ds = class {
|
|
|
7278
7351
|
let t = this.host.requireRuntime(e.params.threadId), n = !e.params.willRetry && t.activeTurnId === e.params.turnId;
|
|
7279
7352
|
n && (t.activeTurnId = null), this.host.patchRuntime(e.params.threadId, {
|
|
7280
7353
|
error: e.params.error.message,
|
|
7281
|
-
turns:
|
|
7354
|
+
turns: Q(t.turns, {
|
|
7282
7355
|
...t.turns.find((t) => t.id === e.params.turnId) ?? {
|
|
7283
7356
|
id: e.params.turnId,
|
|
7284
7357
|
status: "inProgress",
|
|
@@ -7287,7 +7360,7 @@ var ds = class {
|
|
|
7287
7360
|
durationMs: null
|
|
7288
7361
|
},
|
|
7289
7362
|
status: e.params.willRetry ? "inProgress" : "failed",
|
|
7290
|
-
error:
|
|
7363
|
+
error: yo(e.params.error),
|
|
7291
7364
|
willRetry: e.params.willRetry
|
|
7292
7365
|
}),
|
|
7293
7366
|
...n ? {
|
|
@@ -7299,7 +7372,7 @@ var ds = class {
|
|
|
7299
7372
|
conversationId: e.params.threadId,
|
|
7300
7373
|
turnId: e.params.turnId,
|
|
7301
7374
|
payload: {
|
|
7302
|
-
error:
|
|
7375
|
+
error: yo(e.params.error),
|
|
7303
7376
|
willRetry: e.params.willRetry
|
|
7304
7377
|
}
|
|
7305
7378
|
}), this.host.emitConversationActivity(e.params.threadId, "notification");
|
|
@@ -7307,14 +7380,14 @@ var ds = class {
|
|
|
7307
7380
|
}
|
|
7308
7381
|
case "account/rateLimits/updated": {
|
|
7309
7382
|
let t = this.host.getState();
|
|
7310
|
-
this.host.patch({ rateLimits:
|
|
7383
|
+
this.host.patch({ rateLimits: Qa(t.rateLimits, e.params.rateLimits) }), this.host.emitEvent("notification", {
|
|
7311
7384
|
type: "rateLimits.changed",
|
|
7312
7385
|
payload: { rateLimits: structuredClone(this.host.getState().rateLimits) }
|
|
7313
7386
|
});
|
|
7314
7387
|
return;
|
|
7315
7388
|
}
|
|
7316
7389
|
case "account/updated":
|
|
7317
|
-
this.authentication.refresh("notification").catch((e) => this.host.patch({ error:
|
|
7390
|
+
this.authentication.refresh("notification").catch((e) => this.host.patch({ error: k(e) }));
|
|
7318
7391
|
return;
|
|
7319
7392
|
case "account/login/completed":
|
|
7320
7393
|
this.authentication.handleLoginCompleted(e.params);
|
|
@@ -7378,7 +7451,7 @@ var ds = class {
|
|
|
7378
7451
|
this.host.emitEvent("notification", {
|
|
7379
7452
|
type: "realtime.audioDelta",
|
|
7380
7453
|
conversationId: e.params.threadId,
|
|
7381
|
-
payload: { audio:
|
|
7454
|
+
payload: { audio: sa(e.params.audio) }
|
|
7382
7455
|
});
|
|
7383
7456
|
return;
|
|
7384
7457
|
case "thread/realtime/sdp":
|
|
@@ -7469,14 +7542,14 @@ var ds = class {
|
|
|
7469
7542
|
create(e, t = {}) {
|
|
7470
7543
|
let n = this.runtimes.get(e);
|
|
7471
7544
|
if (n) return Object.assign(n, t), n;
|
|
7472
|
-
let r =
|
|
7545
|
+
let r = pa(e, this.host.getState(), t);
|
|
7473
7546
|
return this.runtimes.set(e, r), r;
|
|
7474
7547
|
}
|
|
7475
7548
|
require(e) {
|
|
7476
7549
|
return this.runtimes.get(e) ?? this.create(e);
|
|
7477
7550
|
}
|
|
7478
7551
|
projection(e) {
|
|
7479
|
-
return
|
|
7552
|
+
return ma(e, this.approvals.approvalsForThread(e.threadId), this.clientRequests.requestsForThread(e.threadId));
|
|
7480
7553
|
}
|
|
7481
7554
|
snapshot(e) {
|
|
7482
7555
|
return {
|
|
@@ -7625,7 +7698,7 @@ var ds = class {
|
|
|
7625
7698
|
}
|
|
7626
7699
|
markTurnActive(e, t) {
|
|
7627
7700
|
let n = e.turnIds.includes(t) ? [] : this.projection(e).clientRequests.filter((e) => e.kind === "ask_user" && e.payload.request.delivery === "async" && e.turnId && e.turnId !== t);
|
|
7628
|
-
if (e.activeTurnId = t, e.busy = !0, e.turnStartPending = !1, e.turnIds.includes(t) || e.turnIds.push(t), e.turns =
|
|
7701
|
+
if (e.activeTurnId = t, e.busy = !0, e.turnStartPending = !1, e.turnIds.includes(t) || e.turnIds.push(t), e.turns = Q(e.turns, {
|
|
7629
7702
|
id: t,
|
|
7630
7703
|
status: "inProgress",
|
|
7631
7704
|
error: null,
|
|
@@ -7749,7 +7822,7 @@ var ys = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
7749
7822
|
} catch (e) {
|
|
7750
7823
|
throw this.host.patch({
|
|
7751
7824
|
status: "error",
|
|
7752
|
-
error:
|
|
7825
|
+
error: k(e)
|
|
7753
7826
|
}), this.host.emitSurfaceStatus("lifecycle"), e;
|
|
7754
7827
|
} finally {
|
|
7755
7828
|
this.connectPromise = null;
|
|
@@ -7782,13 +7855,12 @@ var ys = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
7782
7855
|
}
|
|
7783
7856
|
}
|
|
7784
7857
|
bootstrapSurfaceData(e = !1) {
|
|
7785
|
-
let t =
|
|
7858
|
+
let t = _a(this.host.getState().authentication);
|
|
7786
7859
|
if (!e && this.bootstrappedAuthenticationKey === t) return Promise.resolve();
|
|
7787
7860
|
if (this.surfaceBootstrapPromise) return this.surfaceBootstrapPromise.then(() => this.bootstrapSurfaceData(e));
|
|
7788
7861
|
let n = (async () => {
|
|
7789
7862
|
await Promise.all([
|
|
7790
7863
|
this.catalog.loadModels(),
|
|
7791
|
-
this.catalog.loadSkills(e),
|
|
7792
7864
|
this.catalog.loadPermissionProfiles(),
|
|
7793
7865
|
this.catalog.loadRateLimits(),
|
|
7794
7866
|
this.conversations.load()
|
|
@@ -7912,8 +7984,8 @@ var ys = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
7912
7984
|
async fork(e, t = {}, n = {}, r = {}) {
|
|
7913
7985
|
let i = this.host.requireRuntime(e);
|
|
7914
7986
|
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");
|
|
7915
|
-
let a = t.cwd ?? i.cwd ?? n.cwd, o = await this.catalog.loadConversationCatalogs(a ?? void 0), s = this.host.getState(), c = t.model ?
|
|
7916
|
-
|
|
7987
|
+
let a = t.cwd ?? i.cwd ?? n.cwd, o = await this.catalog.loadConversationCatalogs(a ?? void 0), s = this.host.getState(), c = t.model ? xa(s.models, t.model) : K(s.models, i.selectedModelId);
|
|
7988
|
+
Sa(c, t.reasoningEffort), Ta(c, t.serviceTier);
|
|
7917
7989
|
let l = n.mcpServers === void 0 ? this.extensions.defaultMcpServers : qo(n.mcpServers), u = await this.extensions.conversationExtension({
|
|
7918
7990
|
operation: "start",
|
|
7919
7991
|
conversationId: null,
|
|
@@ -7938,7 +8010,7 @@ var ys = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
7938
8010
|
t.reasoningEffort && await this.client.request("thread/settings/update", {
|
|
7939
8011
|
threadId: d.thread.id,
|
|
7940
8012
|
effort: t.reasoningEffort,
|
|
7941
|
-
...c ? { collaborationMode:
|
|
8013
|
+
...c ? { collaborationMode: Pa(i.planMode, c.model, t.reasoningEffort) } : {}
|
|
7942
8014
|
});
|
|
7943
8015
|
let f = n.historyItemsView ?? i.historyItemsView ?? "full", [p, m] = await Promise.all([this.client.request("thread/turns/list", {
|
|
7944
8016
|
threadId: d.thread.id,
|
|
@@ -7950,10 +8022,10 @@ var ys = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
7950
8022
|
...e,
|
|
7951
8023
|
items: await os(this.client, d.thread.id, e.id),
|
|
7952
8024
|
itemsView: "full"
|
|
7953
|
-
} : e)), g = f === "full" ? await this.originalImages?.prepare(d.thread.id, d.thread.path) : void 0, _ =
|
|
8025
|
+
} : e)), g = f === "full" ? await this.originalImages?.prepare(d.thread.id, d.thread.path) : void 0, _ = dn(h), v = An({
|
|
7954
8026
|
...d.thread,
|
|
7955
8027
|
turns: h
|
|
7956
|
-
}), y = _ ?
|
|
8028
|
+
}), y = _ ? A(v, d.thread.id, _) : v;
|
|
7957
8029
|
g && (y = g(y));
|
|
7958
8030
|
let b = n.loadingStrategy ?? this.loadingStrategy ?? "lazy", x = this.host.createRuntime(d.thread.id, {
|
|
7959
8031
|
hydrated: !0,
|
|
@@ -7966,14 +8038,14 @@ var ys = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
7966
8038
|
fullHistoryHydrated: p.nextCursor === null,
|
|
7967
8039
|
cwd: d.cwd ?? d.thread.cwd ?? a ?? null,
|
|
7968
8040
|
activeTurnId: _,
|
|
7969
|
-
turns: h.map((e) =>
|
|
8041
|
+
turns: h.map((e) => Z(e)),
|
|
7970
8042
|
turnIds: h.map((e) => e.id),
|
|
7971
8043
|
messages: y,
|
|
7972
8044
|
busy: !!_,
|
|
7973
8045
|
goal: m ? { ...m } : null,
|
|
7974
|
-
threadStatus:
|
|
8046
|
+
threadStatus: Ka(d.thread.status),
|
|
7975
8047
|
...o,
|
|
7976
|
-
...
|
|
8048
|
+
...ja(d, s.models, this.host.snapshotForRuntime(i))
|
|
7977
8049
|
});
|
|
7978
8050
|
t.reasoningEffort && (x.selectedReasoningEffort = t.reasoningEffort), t.serviceTier !== void 0 && (x.selectedServiceTier = t.serviceTier), t.model && c && (x.selectedModelId = c.id), this.host.rememberHostOptions(d.thread.id, {
|
|
7979
8051
|
...n,
|
|
@@ -7982,11 +8054,11 @@ var ys = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
7982
8054
|
historyItemsView: f,
|
|
7983
8055
|
mcpServers: l
|
|
7984
8056
|
});
|
|
7985
|
-
let
|
|
7986
|
-
...
|
|
8057
|
+
let S = {
|
|
8058
|
+
...q(d.thread),
|
|
7987
8059
|
turnCount: h.length
|
|
7988
8060
|
};
|
|
7989
|
-
return this.host.patch({ conversations:
|
|
8061
|
+
return this.host.patch({ conversations: J(this.host.getState().conversations, S) }), this.host.emitSummaryUpserted(S), this.host.emitHistoryReplaced(d.thread.id), this.host.emitConversationActivity(d.thread.id), this.host.emitConversationSettings(d.thread.id), this.host.emitConversationSkills(d.thread.id), this.host.emitConversationPermissions(d.thread.id), f === "summary" && this.host.hydrateOriginalImages?.(d.thread.id, d.thread.path), b === "eager" && p.nextCursor !== null && this.host.hydrateCompleteHistory(d.thread.id).catch(() => void 0), d.thread.id;
|
|
7990
8062
|
}
|
|
7991
8063
|
async forkTurn(e, t, n = {}, r = {}) {
|
|
7992
8064
|
if (!this.host.requireRuntime(e).turnIds.includes(t)) throw Error(`Cannot fork at unknown Codex turn '${t}'`);
|
|
@@ -7996,7 +8068,7 @@ var ys = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
7996
8068
|
function Cs(e, t) {
|
|
7997
8069
|
if (e.approvalPreset) {
|
|
7998
8070
|
if (!t.includes(e.approvalPreset)) throw Error(`Approval preset '${e.approvalPreset}' is not available`);
|
|
7999
|
-
return
|
|
8071
|
+
return Oa(e.approvalPreset);
|
|
8000
8072
|
}
|
|
8001
8073
|
return {
|
|
8002
8074
|
...e.approvalMode === void 0 ? {} : { approvalPolicy: e.approvalMode === "ask" ? "on-request" : "never" },
|
|
@@ -8025,7 +8097,7 @@ var ws = /(?<!\[)!\[([^\]]*)\]\(([^)\s]+)(?:\s+["']([^"']*)["'])?\)/g, Ts = /* @
|
|
|
8025
8097
|
let i = e[2], a = Ds(i, t);
|
|
8026
8098
|
if (!a) return null;
|
|
8027
8099
|
try {
|
|
8028
|
-
let t =
|
|
8100
|
+
let t = Gn((await this.client.request("fs/readFile", { path: a })).dataBase64);
|
|
8029
8101
|
if (!t) return null;
|
|
8030
8102
|
let n = e[0].indexOf("](") + 2;
|
|
8031
8103
|
return {
|
|
@@ -8058,7 +8130,7 @@ function Ds(e, t) {
|
|
|
8058
8130
|
if (v(r)) return r;
|
|
8059
8131
|
if (!t || !v(t)) return null;
|
|
8060
8132
|
let i = x(t, r), a = b(t, i);
|
|
8061
|
-
return a === ".." || a.startsWith(`..${
|
|
8133
|
+
return a === ".." || a.startsWith(`..${S}`) || v(a) ? null : i;
|
|
8062
8134
|
}
|
|
8063
8135
|
function Os(e, t) {
|
|
8064
8136
|
let n = e;
|
|
@@ -8091,7 +8163,7 @@ function As(e, t) {
|
|
|
8091
8163
|
}
|
|
8092
8164
|
var js = /<context>[\s\S]*?<\/context>\s*/g, Ms = /<in-app-browser-context(?:\s[^>]*)?>[\s\S]*?<\/in-app-browser-context>\s*/g, Ns = /^[ \t]*## My request for Codex:[ \t]*$/m;
|
|
8093
8165
|
async function Ps(e, t) {
|
|
8094
|
-
let n =
|
|
8166
|
+
let n = O(t);
|
|
8095
8167
|
return {
|
|
8096
8168
|
conversationId: n,
|
|
8097
8169
|
prompts: Fs((await e.request("thread/turns/list", {
|
|
@@ -8137,10 +8209,10 @@ var Ls = 12e4, Rs = class {
|
|
|
8137
8209
|
if (!n) throw Error("Generation prompt cannot be empty");
|
|
8138
8210
|
if (t.signal?.aborted) throw Us();
|
|
8139
8211
|
if (t.attachments?.some((e) => e.type !== "image")) throw Error("Utility generation accepts image attachments only");
|
|
8140
|
-
let r =
|
|
8212
|
+
let r = Ra(t.attachments ?? []), i = qo(t.mcpServers ?? []);
|
|
8141
8213
|
await this.host.ensureConnected();
|
|
8142
|
-
let a = this.host.getSnapshot(), o =
|
|
8143
|
-
|
|
8214
|
+
let a = this.host.getSnapshot(), o = K(a.models, a.selectedModelId), s = t.model ? xa(a.models, t.model) : o, c = s?.model, l = t.reasoningEffort ?? (s?.id === o?.id ? a.selectedReasoningEffort : s ? Ca(s) : null) ?? void 0, u = t.serviceTier === void 0 ? s?.id === o?.id ? a.selectedServiceTier : s?.defaultServiceTier ?? null : t.serviceTier;
|
|
8215
|
+
Sa(s, l), Ta(s, u);
|
|
8144
8216
|
let d = await this.client.request("thread/start", {
|
|
8145
8217
|
approvalPolicy: "never",
|
|
8146
8218
|
approvalsReviewer: "user",
|
|
@@ -8173,7 +8245,7 @@ var Ls = 12e4, Rs = class {
|
|
|
8173
8245
|
type: "text",
|
|
8174
8246
|
text: n,
|
|
8175
8247
|
text_elements: []
|
|
8176
|
-
}, ...r.map(
|
|
8248
|
+
}, ...r.map(za)],
|
|
8177
8249
|
...t.tools === "read-only" ? {} : { environments: [] },
|
|
8178
8250
|
permissions: ":read-only",
|
|
8179
8251
|
...c ? { model: c } : {},
|
|
@@ -8306,21 +8378,21 @@ var Ws = class {
|
|
|
8306
8378
|
unsubscribeToolInputRequests;
|
|
8307
8379
|
unsubscribeMcpElicitationRequests;
|
|
8308
8380
|
eventSequence = 0;
|
|
8309
|
-
usage = new
|
|
8381
|
+
usage = new Xi();
|
|
8310
8382
|
accountGeneration = 0;
|
|
8311
8383
|
pendingMarkdownImageHydrations = /* @__PURE__ */ new Set();
|
|
8312
8384
|
closed = !1;
|
|
8313
|
-
state =
|
|
8385
|
+
state = fa(ha());
|
|
8314
8386
|
constructor(e = {}) {
|
|
8315
8387
|
this.options = e, this.extensions = new es(e.extensions ?? [], e.mcpServers ?? [], (e) => this.lifecycle.hostOptions(e));
|
|
8316
|
-
let n =
|
|
8317
|
-
this.client = e.client ?? new t(
|
|
8388
|
+
let n = to(e);
|
|
8389
|
+
this.client = e.client ?? new t(eo(n) ? new et(n) : new Ye(n), e.onListenerError ? { onListenerError: e.onListenerError } : {}), this.originalImages = e.originalHistoryImages ? new Vi(this.client) : void 0, this.originalUsage = e.originalHistoryUsage ? new na(this.client) : void 0, this.markdownImages = new Es(this.client), this.authentication = new ro(this.client, {
|
|
8318
8390
|
bootstrapSurfaceData: (e) => this.connection.bootstrapSurfaceData(e),
|
|
8319
8391
|
clearAuthenticatedSurfaceData: () => this.connection.clearAuthenticatedSurfaceData(),
|
|
8320
8392
|
getSnapshot: () => this.getSnapshot(),
|
|
8321
8393
|
patchAuthentication: (e, t) => this.connection.patchAuthentication(e, t),
|
|
8322
|
-
reportError: (e) => this.patch({ error:
|
|
8323
|
-
}), this.items = new
|
|
8394
|
+
reportError: (e) => this.patch({ error: k(e) })
|
|
8395
|
+
}), this.items = new wo({
|
|
8324
8396
|
assistantMessageForTurn: (e, t) => this.assistantMessageForTurn(e, t),
|
|
8325
8397
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
8326
8398
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
@@ -8344,7 +8416,7 @@ var Ws = class {
|
|
|
8344
8416
|
patch: (e) => this.patch(e),
|
|
8345
8417
|
patchConversationStatus: (e, t) => this.patchConversationStatus(e, t),
|
|
8346
8418
|
patchRuntime: (e, t) => this.patchRuntime(e, t)
|
|
8347
|
-
}), this.clientRequests = new
|
|
8419
|
+
}), this.clientRequests = new Do({
|
|
8348
8420
|
activeConversationId: () => this.state.activeConversationId,
|
|
8349
8421
|
answerAsyncQuestion: (e, t, n) => this.messagesController.answerAsyncQuestion(e, t, n),
|
|
8350
8422
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -8397,6 +8469,10 @@ var Ws = class {
|
|
|
8397
8469
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
8398
8470
|
sendMessageToThread: (e, t, n) => this.messagesController.sendToThread(e, t, n)
|
|
8399
8471
|
}), this.messagesController = new ds(this.client, {
|
|
8472
|
+
loadSkillsForThread: async (e) => {
|
|
8473
|
+
let t = this.requireRuntime(e);
|
|
8474
|
+
await this.catalog.listSkills({ ...t.cwd ? { cwd: t.cwd } : {} });
|
|
8475
|
+
},
|
|
8400
8476
|
clearGoalForThread: (e) => this.conversationSettings.clearGoalForThread(e),
|
|
8401
8477
|
compactForThread: (e) => this.turnActions.compactForThread(e),
|
|
8402
8478
|
createConversation: async () => {
|
|
@@ -8551,7 +8627,7 @@ var Ws = class {
|
|
|
8551
8627
|
}
|
|
8552
8628
|
async readRateLimits(e) {
|
|
8553
8629
|
return this.requestForAccount(() => this.client.request("account/rateLimits/read", e), (e) => {
|
|
8554
|
-
let t =
|
|
8630
|
+
let t = Ja(e);
|
|
8555
8631
|
return this.patch({ rateLimits: t }), this.emitEvent("action", {
|
|
8556
8632
|
type: "rateLimits.changed",
|
|
8557
8633
|
payload: { rateLimits: structuredClone(t) }
|
|
@@ -8559,7 +8635,7 @@ var Ws = class {
|
|
|
8559
8635
|
});
|
|
8560
8636
|
}
|
|
8561
8637
|
async readAccountUsage() {
|
|
8562
|
-
return this.requestForAccount(() => this.client.request("account/usage/read", {}),
|
|
8638
|
+
return this.requestForAccount(() => this.client.request("account/usage/read", {}), Xa);
|
|
8563
8639
|
}
|
|
8564
8640
|
async consumeRateLimitResetCredit(e) {
|
|
8565
8641
|
if (!e || typeof e.idempotencyKey != "string" || !e.idempotencyKey.trim() || e.creditId !== void 0 && (typeof e.creditId != "string" || !e.creditId.trim())) throw TypeError("Reset-credit options require non-empty identifiers");
|
|
@@ -8641,7 +8717,7 @@ var Ws = class {
|
|
|
8641
8717
|
return this.lifecycle.create(e, t);
|
|
8642
8718
|
}
|
|
8643
8719
|
async forkConversation(e, t = {}, n = {}) {
|
|
8644
|
-
let r =
|
|
8720
|
+
let r = O(e);
|
|
8645
8721
|
await this.ensureThreadReady(r);
|
|
8646
8722
|
let i = this.lifecycle.hostOptions(r) ?? {}, a = await this.forks.fork(r, t, {
|
|
8647
8723
|
...i,
|
|
@@ -8650,7 +8726,7 @@ var Ws = class {
|
|
|
8650
8726
|
return this.conversationForkResult(a);
|
|
8651
8727
|
}
|
|
8652
8728
|
async forkConversationAtTurn(e, t, n = {}, r = {}) {
|
|
8653
|
-
let i =
|
|
8729
|
+
let i = O(e);
|
|
8654
8730
|
await this.ensureThreadReady(i);
|
|
8655
8731
|
let a = this.lifecycle.hostOptions(i) ?? {}, o = await this.forks.forkTurn(i, t, n, {
|
|
8656
8732
|
...a,
|
|
@@ -8662,7 +8738,7 @@ var Ws = class {
|
|
|
8662
8738
|
return this.lifecycle.select(e);
|
|
8663
8739
|
}
|
|
8664
8740
|
forgetConversation(e) {
|
|
8665
|
-
let t =
|
|
8741
|
+
let t = O(e), n = this.state.activeConversationId === t;
|
|
8666
8742
|
this.runtimeState.forget(t), this.lifecycle.forget(t), this.originalImages?.forget(t), this.conversations.forget(t), this.items.forget(t), this.conversationHandles.delete(t), this.conversationListeners.delete(t), n && this.patch({
|
|
8667
8743
|
activeConversationId: null,
|
|
8668
8744
|
activeTurnId: null,
|
|
@@ -8696,7 +8772,7 @@ var Ws = class {
|
|
|
8696
8772
|
if (!a()) throw Error("Conversation content is no longer available.");
|
|
8697
8773
|
return r;
|
|
8698
8774
|
}
|
|
8699
|
-
return new
|
|
8775
|
+
return new Ni(e).read({ messages: r.messages }, t, n);
|
|
8700
8776
|
}
|
|
8701
8777
|
async readConversationHistory(e = this.state.activeConversationId ?? "") {
|
|
8702
8778
|
return this.lifecycle.readHistory(e);
|
|
@@ -8708,7 +8784,7 @@ var Ws = class {
|
|
|
8708
8784
|
return await this.ensureThreadReady(t), await this.conversations.loadTurnHistory(t, e), this.getConversationSnapshot(t);
|
|
8709
8785
|
}
|
|
8710
8786
|
async loadOlderConversationHistory(e = this.state.activeConversationId ?? "") {
|
|
8711
|
-
return this.conversations.loadOlderHistory(
|
|
8787
|
+
return this.conversations.loadOlderHistory(O(e));
|
|
8712
8788
|
}
|
|
8713
8789
|
async renameConversation(e) {
|
|
8714
8790
|
let t = this.state.activeConversationId;
|
|
@@ -8772,9 +8848,9 @@ var Ws = class {
|
|
|
8772
8848
|
return await this.approvals.resolve(void 0, e, t, n), this.getSnapshot();
|
|
8773
8849
|
}
|
|
8774
8850
|
conversation(e) {
|
|
8775
|
-
let t =
|
|
8851
|
+
let t = O(e), n = this.conversationHandles.get(t);
|
|
8776
8852
|
if (n) return n;
|
|
8777
|
-
let r =
|
|
8853
|
+
let r = io(t, {
|
|
8778
8854
|
clearGoal: () => this.conversationSettings.clearGoalForThread(t),
|
|
8779
8855
|
compact: () => this.turnActions.compactForThread(t),
|
|
8780
8856
|
continueInterruptedTurn: () => this.messagesController.continueInterruptedTurnForThread(t),
|
|
@@ -8831,7 +8907,7 @@ var Ws = class {
|
|
|
8831
8907
|
await this.client.request("thread/realtime/stop", { threadId: e });
|
|
8832
8908
|
}
|
|
8833
8909
|
startRealtimeForThread(e, t) {
|
|
8834
|
-
return
|
|
8910
|
+
return ua({
|
|
8835
8911
|
client: this.client,
|
|
8836
8912
|
ensureThreadReady: async () => {
|
|
8837
8913
|
await this.ensureThreadReady(e);
|
|
@@ -9052,8 +9128,8 @@ var Ws = class {
|
|
|
9052
9128
|
}
|
|
9053
9129
|
async requestForAccount(e, t) {
|
|
9054
9130
|
await this.ensureConnected(), await this.authentication.pendingRefresh();
|
|
9055
|
-
let n = this.accountGeneration, r =
|
|
9056
|
-
if (this.closed || n !== this.accountGeneration || r !==
|
|
9131
|
+
let n = this.accountGeneration, r = va(this.state.authentication), i = await e();
|
|
9132
|
+
if (this.closed || n !== this.accountGeneration || r !== va(this.state.authentication)) throw Error("Account changed during account operation");
|
|
9057
9133
|
return t(i);
|
|
9058
9134
|
}
|
|
9059
9135
|
emitEvent(e, t, n = !1) {
|
|
@@ -9410,7 +9486,7 @@ async function nc(e, t, n = {}) {
|
|
|
9410
9486
|
_ = e;
|
|
9411
9487
|
}), y = setTimeout(() => x("Speech recognition took too long to start."), 12e4), b = async () => {
|
|
9412
9488
|
if (a) return;
|
|
9413
|
-
a = !0, clearTimeout(y), n.signal?.removeEventListener("abort",
|
|
9489
|
+
a = !0, clearTimeout(y), n.signal?.removeEventListener("abort", ee);
|
|
9414
9490
|
let e = c ?? {
|
|
9415
9491
|
text: "",
|
|
9416
9492
|
error: d.trim() || "Speech helper stopped without a final transcript."
|
|
@@ -9429,24 +9505,24 @@ async function nc(e, t, n = {}) {
|
|
|
9429
9505
|
a || c?.error || (c = {
|
|
9430
9506
|
text: "",
|
|
9431
9507
|
error: t
|
|
9432
|
-
}, p(Error(t)),
|
|
9508
|
+
}, p(Error(t)), S({
|
|
9433
9509
|
type: "error",
|
|
9434
9510
|
sessionId: e.sessionId,
|
|
9435
9511
|
error: t
|
|
9436
9512
|
}), i.kill("SIGKILL"), b());
|
|
9437
9513
|
}
|
|
9438
|
-
function
|
|
9514
|
+
function S(e) {
|
|
9439
9515
|
try {
|
|
9440
9516
|
t(e);
|
|
9441
9517
|
} catch {}
|
|
9442
9518
|
}
|
|
9443
|
-
function
|
|
9519
|
+
function ee() {
|
|
9444
9520
|
a || (c = {
|
|
9445
9521
|
text: "",
|
|
9446
9522
|
error: "Speech recording cancelled."
|
|
9447
9523
|
}, i.kill("SIGKILL"), b());
|
|
9448
9524
|
}
|
|
9449
|
-
return n.signal?.addEventListener("abort",
|
|
9525
|
+
return n.signal?.addEventListener("abort", ee, { once: !0 }), i.stderr.on("data", (e) => {
|
|
9450
9526
|
d = (d + e.toString()).slice(-4096);
|
|
9451
9527
|
}), i.on("error", (e) => x(e.message)), i.stdin.on("error", (e) => x(e.message)), i.on("close", (e) => {
|
|
9452
9528
|
e !== 0 && !c?.error && x(d.trim() || `Speech helper exited with code ${e}.`), b();
|
|
@@ -9462,7 +9538,7 @@ async function nc(e, t, n = {}) {
|
|
|
9462
9538
|
l = l.slice(n + 1);
|
|
9463
9539
|
try {
|
|
9464
9540
|
let n = JSON.parse(t);
|
|
9465
|
-
n.type === "ready" ? (clearTimeout(y), f()) : n.type === "transcript" && typeof n.finalText == "string" && typeof n.partialText == "string" ?
|
|
9541
|
+
n.type === "ready" ? (clearTimeout(y), f()) : n.type === "transcript" && typeof n.finalText == "string" && typeof n.partialText == "string" ? S({
|
|
9466
9542
|
type: "transcript",
|
|
9467
9543
|
sessionId: e.sessionId,
|
|
9468
9544
|
finalText: n.finalText,
|
|
@@ -9472,7 +9548,7 @@ async function nc(e, t, n = {}) {
|
|
|
9472
9548
|
x("Invalid speech helper output.");
|
|
9473
9549
|
}
|
|
9474
9550
|
}
|
|
9475
|
-
}), n.signal?.aborted &&
|
|
9551
|
+
}), n.signal?.aborted && ee(), await g, {
|
|
9476
9552
|
append: (e) => new Promise((t, n) => {
|
|
9477
9553
|
if (a || s) {
|
|
9478
9554
|
n(/* @__PURE__ */ Error("Speech session is no longer recording."));
|
|
@@ -9494,6 +9570,6 @@ async function nc(e, t, n = {}) {
|
|
|
9494
9570
|
};
|
|
9495
9571
|
}
|
|
9496
9572
|
//#endregion
|
|
9497
|
-
export { Js as CodexAppBackend, qs as CodexAppBackendTtlCache, Ye as CodexAppServerStdioTransport, et as CodexAppServerUnixSocketTransport,
|
|
9573
|
+
export { Js as CodexAppBackend, qs as CodexAppBackendTtlCache, Ye as CodexAppServerStdioTransport, et as CodexAppServerUnixSocketTransport, na as CodexOriginalHistoryUsage, Ws as CodexSurface, Ni as ConversationContentTransport, Fn as codexItemToMediaPart, Nn as codexItemToSurfaceMessage, w as codexItemToToolPart, xe as codexRuntimePathEntries, An as codexThreadToSurfaceMessages, P as codexTurnToSurfaceMessages, Ys as createCodexAppBackend, Gs as createCodexSurface, be as discoverCodexExecutable, jn as preserveHistoricalAttachmentPreviews, Zs as resolveAppleSpeechAnalyzerPath, Ce as resolveCodexRuntime, nc as startAppleSpeechSession, Xs as transcribeWithAppleSpeechAnalyzer, Se as withCodexRuntimePath };
|
|
9498
9574
|
|
|
9499
9575
|
//# sourceMappingURL=index.js.map
|