@codex-app-sdk/backend 0.16.1 → 0.16.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/index.js +315 -292
- package/dist/index.js.map +1 -1
- package/dist/node/codex-conversation-history.d.ts +2 -0
- package/dist/node/codex-conversation-history.d.ts.map +1 -1
- package/dist/node/codex-surface-message-state.d.ts +1 -1
- package/dist/node/codex-surface-message-state.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2140,17 +2140,17 @@ function W(e, t, n, r) {
|
|
|
2140
2140
|
parts: s
|
|
2141
2141
|
}), G(i, t);
|
|
2142
2142
|
}
|
|
2143
|
-
function er(e, t, n, r) {
|
|
2144
|
-
let
|
|
2145
|
-
|
|
2146
|
-
let
|
|
2147
|
-
if (!
|
|
2148
|
-
let
|
|
2149
|
-
return
|
|
2150
|
-
...
|
|
2143
|
+
function er(e, t, n, r, i = r.itemId) {
|
|
2144
|
+
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));
|
|
2145
|
+
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 = U(a, t, n), o = K(a, (e) => e.role === "assistant" && e.kind === void 0 && e.metadata?.turnId === n));
|
|
2146
|
+
let s = o >= 0 ? a[o] : void 0;
|
|
2147
|
+
if (!s) return a;
|
|
2148
|
+
let c = [...s.parts], l = c.findIndex((e) => e.type === "media" && e.itemId === r.itemId);
|
|
2149
|
+
return l >= 0 ? c.splice(l, 1, r) : c.push(r), a.splice(o, 1, {
|
|
2150
|
+
...s,
|
|
2151
2151
|
status: "streaming",
|
|
2152
|
-
parts:
|
|
2153
|
-
}), G(
|
|
2152
|
+
parts: c
|
|
2153
|
+
}), G(a, t);
|
|
2154
2154
|
}
|
|
2155
2155
|
function tr(e, t, n, r) {
|
|
2156
2156
|
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));
|
|
@@ -2299,7 +2299,7 @@ function fr(e) {
|
|
|
2299
2299
|
}
|
|
2300
2300
|
function pr(e, t) {
|
|
2301
2301
|
let n = /* @__PURE__ */ new Map();
|
|
2302
|
-
for (let t of e) for (let e of t.parts) e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path ||
|
|
2302
|
+
for (let t of e) for (let e of t.parts) e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path || Or(e.attachment.url) && n.set(e.attachment.path, e.attachment.url);
|
|
2303
2303
|
return n.size === 0 ? [...t] : t.map((e) => {
|
|
2304
2304
|
let t = !1, r = e.parts.map((e) => {
|
|
2305
2305
|
if (e.type !== "attachment" || e.attachment.kind !== "image" || !e.attachment.path) return e;
|
|
@@ -2319,13 +2319,13 @@ function pr(e, t) {
|
|
|
2319
2319
|
});
|
|
2320
2320
|
}
|
|
2321
2321
|
function mr(e, t) {
|
|
2322
|
-
let n = [], r = [], i =
|
|
2322
|
+
let n = [], r = [], i = Mr(t.startedAt ?? t.completedAt), a = 0, o = !1, s = /* @__PURE__ */ new Set(), c = () => {
|
|
2323
2323
|
if (r.length === 0) return;
|
|
2324
2324
|
let o = a === 0 ? "" : `-segment-${a}`;
|
|
2325
2325
|
n.push({
|
|
2326
2326
|
id: `assistant-${t.id}${o}`,
|
|
2327
2327
|
role: "assistant",
|
|
2328
|
-
status:
|
|
2328
|
+
status: jr(t.status),
|
|
2329
2329
|
turnId: t.id,
|
|
2330
2330
|
parts: [...r],
|
|
2331
2331
|
createdAt: i,
|
|
@@ -2337,7 +2337,7 @@ function mr(e, t) {
|
|
|
2337
2337
|
};
|
|
2338
2338
|
for (let a of Array.isArray(t.items) ? t.items : []) {
|
|
2339
2339
|
if (a.type === "userMessage") {
|
|
2340
|
-
let r =
|
|
2340
|
+
let r = yr(a), l = xr(a);
|
|
2341
2341
|
if (r.length > 0) {
|
|
2342
2342
|
let u = o, d = u ? null : JSON.stringify(r);
|
|
2343
2343
|
if (d && s.has(d)) continue;
|
|
@@ -2354,7 +2354,7 @@ function mr(e, t) {
|
|
|
2354
2354
|
turnId: t.id,
|
|
2355
2355
|
...l.length > 0 ? {
|
|
2356
2356
|
asyncQuestionRequestIds: l,
|
|
2357
|
-
asyncQuestionAnswers:
|
|
2357
|
+
asyncQuestionAnswers: Sr(a)
|
|
2358
2358
|
} : {}
|
|
2359
2359
|
}
|
|
2360
2360
|
});
|
|
@@ -2418,15 +2418,15 @@ function mr(e, t) {
|
|
|
2418
2418
|
}
|
|
2419
2419
|
let l = L(a);
|
|
2420
2420
|
l && (o = !0, r.push(l));
|
|
2421
|
-
let u =
|
|
2422
|
-
u && (o = !0, r.push(u));
|
|
2421
|
+
let u = vr(a);
|
|
2422
|
+
u.length && (o = !0, r.push(...u));
|
|
2423
2423
|
}
|
|
2424
2424
|
return c(), t.status === "inProgress" ? n : ar(n, t.id, t.status);
|
|
2425
2425
|
}
|
|
2426
2426
|
function hr(e, t, n) {
|
|
2427
|
-
let r =
|
|
2427
|
+
let r = Mr(t.startedAt);
|
|
2428
2428
|
if (n.type === "userMessage") {
|
|
2429
|
-
let i =
|
|
2429
|
+
let i = yr(n), a = xr(n);
|
|
2430
2430
|
return i.length > 0 ? {
|
|
2431
2431
|
id: n.clientId ?? `user-${e}-${t.id}-${n.id}`,
|
|
2432
2432
|
role: "user",
|
|
@@ -2440,7 +2440,7 @@ function hr(e, t, n) {
|
|
|
2440
2440
|
itemId: n.id,
|
|
2441
2441
|
...a.length > 0 ? {
|
|
2442
2442
|
asyncQuestionRequestIds: a,
|
|
2443
|
-
asyncQuestionAnswers:
|
|
2443
|
+
asyncQuestionAnswers: Sr(n)
|
|
2444
2444
|
} : {}
|
|
2445
2445
|
}
|
|
2446
2446
|
} : null;
|
|
@@ -2455,7 +2455,7 @@ function hr(e, t, n) {
|
|
|
2455
2455
|
return s.length > 0 ? {
|
|
2456
2456
|
id: `assistant-${n.id}`,
|
|
2457
2457
|
role: "assistant",
|
|
2458
|
-
status:
|
|
2458
|
+
status: jr(t.status),
|
|
2459
2459
|
turnId: t.id,
|
|
2460
2460
|
parts: s,
|
|
2461
2461
|
createdAt: r,
|
|
@@ -2479,7 +2479,7 @@ function hr(e, t, n) {
|
|
|
2479
2479
|
return i.length > 0 ? {
|
|
2480
2480
|
id: `assistant-${n.id}`,
|
|
2481
2481
|
role: "assistant",
|
|
2482
|
-
status:
|
|
2482
|
+
status: jr(t.status),
|
|
2483
2483
|
turnId: t.id,
|
|
2484
2484
|
parts: i,
|
|
2485
2485
|
createdAt: r,
|
|
@@ -2491,13 +2491,11 @@ function hr(e, t, n) {
|
|
|
2491
2491
|
} : null;
|
|
2492
2492
|
}
|
|
2493
2493
|
let i = [], a = L(n);
|
|
2494
|
-
a && i.push(a);
|
|
2495
|
-
let o =
|
|
2496
|
-
o && i.push(o);
|
|
2497
|
-
let s = i.length > 0 ? {
|
|
2494
|
+
a && i.push(a), i.push(...vr(n));
|
|
2495
|
+
let o = i.length > 0 ? {
|
|
2498
2496
|
id: `assistant-${n.id}`,
|
|
2499
2497
|
role: "assistant",
|
|
2500
|
-
status:
|
|
2498
|
+
status: jr(t.status),
|
|
2501
2499
|
turnId: t.id,
|
|
2502
2500
|
parts: i,
|
|
2503
2501
|
createdAt: r,
|
|
@@ -2507,7 +2505,7 @@ function hr(e, t, n) {
|
|
|
2507
2505
|
itemId: n.id
|
|
2508
2506
|
}
|
|
2509
2507
|
} : null;
|
|
2510
|
-
return !
|
|
2508
|
+
return !o || t.status === "inProgress" ? o : ar([o], t.id, t.status)[0] ?? null;
|
|
2511
2509
|
}
|
|
2512
2510
|
function gr(e, t, n, r = !1) {
|
|
2513
2511
|
if (n.delivery !== "async") return null;
|
|
@@ -2553,7 +2551,7 @@ function gr(e, t, n, r = !1) {
|
|
|
2553
2551
|
}
|
|
2554
2552
|
function _r(e) {
|
|
2555
2553
|
if (e.type !== "imageGeneration" || L(e)?.status !== "completed") return null;
|
|
2556
|
-
let t = typeof e.savedPath == "string" && v(e.savedPath) ? e.savedPath : null, n = t ?
|
|
2554
|
+
let t = typeof e.savedPath == "string" && v(e.savedPath) ? e.savedPath : null, n = t ? Er(t) : void 0, r = n && dr.has(n) ? t : null, i = Dr(typeof e.result == "string" ? e.result.trim() : ""), a = i?.url ?? (r ? re(r).href : void 0);
|
|
2557
2555
|
if (!a) return null;
|
|
2558
2556
|
let o = typeof e.revisedPrompt == "string" ? e.revisedPrompt.trim() : "";
|
|
2559
2557
|
return {
|
|
@@ -2569,6 +2567,30 @@ function _r(e) {
|
|
|
2569
2567
|
};
|
|
2570
2568
|
}
|
|
2571
2569
|
function vr(e) {
|
|
2570
|
+
let t = _r(e);
|
|
2571
|
+
if (t) return [t];
|
|
2572
|
+
let n = e.type === "mcpToolCall" && e.status === "completed" ? e.result?.content : e.type === "dynamicToolCall" && e.status === "completed" ? e.contentItems : void 0;
|
|
2573
|
+
if (!Array.isArray(n)) return [];
|
|
2574
|
+
let r = [], i = 20 * 1024 * 1024;
|
|
2575
|
+
for (let t of n) {
|
|
2576
|
+
if (!t || typeof t != "object" || Array.isArray(t) || r.length >= 8) continue;
|
|
2577
|
+
let n = t, a = n.type === "image" && typeof n.data == "string" ? n.data : n.type === "inputImage" && typeof n.imageUrl == "string" ? n.imageUrl : "";
|
|
2578
|
+
if (a.length > i) continue;
|
|
2579
|
+
let o = Dr(a);
|
|
2580
|
+
o && (i -= o.url.length, r.push({
|
|
2581
|
+
type: "media",
|
|
2582
|
+
itemId: r.length ? `${e.id}:image:${r.length}` : e.id,
|
|
2583
|
+
media: {
|
|
2584
|
+
url: o.url,
|
|
2585
|
+
mimeType: o.mimeType,
|
|
2586
|
+
alt: "Tool image",
|
|
2587
|
+
title: "Tool image"
|
|
2588
|
+
}
|
|
2589
|
+
}));
|
|
2590
|
+
}
|
|
2591
|
+
return r;
|
|
2592
|
+
}
|
|
2593
|
+
function yr(e) {
|
|
2572
2594
|
let t = Array.isArray(e.content) ? e.content : [], n = t.some((e) => q(e) && e.type === "text" && typeof e.text == "string" && e.text.length > 0), r = [], i = [], a = /* @__PURE__ */ new Set(), o = () => {
|
|
2573
2595
|
i.length > 0 && r.push({
|
|
2574
2596
|
type: "text",
|
|
@@ -2582,7 +2604,7 @@ function vr(e) {
|
|
|
2582
2604
|
if (a.has(t)) continue;
|
|
2583
2605
|
a.add(t);
|
|
2584
2606
|
}
|
|
2585
|
-
let t =
|
|
2607
|
+
let t = br(e), s = kt(t);
|
|
2586
2608
|
if (s) {
|
|
2587
2609
|
o(), r.push({
|
|
2588
2610
|
type: "attachment",
|
|
@@ -2597,7 +2619,7 @@ function vr(e) {
|
|
|
2597
2619
|
i.push(t);
|
|
2598
2620
|
continue;
|
|
2599
2621
|
}
|
|
2600
|
-
let c =
|
|
2622
|
+
let c = wr(e);
|
|
2601
2623
|
c && (o(), r.push({
|
|
2602
2624
|
type: "attachment",
|
|
2603
2625
|
attachment: c
|
|
@@ -2605,20 +2627,20 @@ function vr(e) {
|
|
|
2605
2627
|
}
|
|
2606
2628
|
return o(), r;
|
|
2607
2629
|
}
|
|
2608
|
-
function yr(e) {
|
|
2609
|
-
return !q(e) || typeof e.type != "string" ? "" : e.type === "text" && typeof e.text == "string" ? Sr(e.text)?.displayText ?? e.text : e.type === "skill" && typeof e.name == "string" ? `$${e.name}` : "";
|
|
2610
|
-
}
|
|
2611
2630
|
function br(e) {
|
|
2631
|
+
return !q(e) || typeof e.type != "string" ? "" : e.type === "text" && typeof e.text == "string" ? Cr(e.text)?.displayText ?? e.text : e.type === "skill" && typeof e.name == "string" ? `$${e.name}` : "";
|
|
2632
|
+
}
|
|
2633
|
+
function xr(e) {
|
|
2612
2634
|
let t = /* @__PURE__ */ new Set();
|
|
2613
|
-
for (let n of Array.isArray(e.content) ? e.content : []) if (!(!q(n) || n.type !== "text" || typeof n.text != "string")) for (let e of
|
|
2635
|
+
for (let n of Array.isArray(e.content) ? e.content : []) if (!(!q(n) || n.type !== "text" || typeof n.text != "string")) for (let e of Cr(n.text)?.requestIds ?? []) t.add(e);
|
|
2614
2636
|
return [...t];
|
|
2615
2637
|
}
|
|
2616
|
-
function
|
|
2638
|
+
function Sr(e) {
|
|
2617
2639
|
let t = {};
|
|
2618
|
-
for (let n of Array.isArray(e.content) ? e.content : []) !q(n) || n.type !== "text" || typeof n.text != "string" || Object.assign(t,
|
|
2640
|
+
for (let n of Array.isArray(e.content) ? e.content : []) !q(n) || n.type !== "text" || typeof n.text != "string" || Object.assign(t, Cr(n.text)?.answers);
|
|
2619
2641
|
return t;
|
|
2620
2642
|
}
|
|
2621
|
-
function
|
|
2643
|
+
function Cr(e) {
|
|
2622
2644
|
let t = e.match(/^<send_user_message_question_reply>\s*([\s\S]*?)\s*<\/send_user_message_question_reply>$/);
|
|
2623
2645
|
if (!t?.[1]) return null;
|
|
2624
2646
|
try {
|
|
@@ -2642,10 +2664,10 @@ function Sr(e) {
|
|
|
2642
2664
|
return null;
|
|
2643
2665
|
}
|
|
2644
2666
|
}
|
|
2645
|
-
function
|
|
2667
|
+
function wr(e) {
|
|
2646
2668
|
if (!q(e) || typeof e.type != "string") return null;
|
|
2647
2669
|
if (e.type === "mention" && typeof e.path == "string") {
|
|
2648
|
-
let t = typeof e.name == "string" && e.name.trim() ? e.name.trim() :
|
|
2670
|
+
let t = typeof e.name == "string" && e.name.trim() ? e.name.trim() : Tr(e.path, "File"), n = Er(e.path);
|
|
2649
2671
|
return {
|
|
2650
2672
|
kind: "file",
|
|
2651
2673
|
name: t,
|
|
@@ -2654,26 +2676,26 @@ function Cr(e) {
|
|
|
2654
2676
|
};
|
|
2655
2677
|
}
|
|
2656
2678
|
if (e.type === "image" && typeof e.url == "string") {
|
|
2657
|
-
let t =
|
|
2679
|
+
let t = Er(e.url);
|
|
2658
2680
|
return {
|
|
2659
2681
|
kind: "image",
|
|
2660
|
-
name:
|
|
2682
|
+
name: Tr(e.url, "Image"),
|
|
2661
2683
|
url: e.url,
|
|
2662
2684
|
...t ? { mimeType: t } : {}
|
|
2663
2685
|
};
|
|
2664
2686
|
}
|
|
2665
2687
|
if (e.type === "localImage" && typeof e.path == "string") {
|
|
2666
|
-
let t =
|
|
2688
|
+
let t = Er(e.path);
|
|
2667
2689
|
return {
|
|
2668
2690
|
kind: "image",
|
|
2669
|
-
name:
|
|
2691
|
+
name: Tr(e.path, "Image"),
|
|
2670
2692
|
path: e.path,
|
|
2671
2693
|
...t ? { mimeType: t } : {}
|
|
2672
2694
|
};
|
|
2673
2695
|
}
|
|
2674
2696
|
return null;
|
|
2675
2697
|
}
|
|
2676
|
-
function
|
|
2698
|
+
function Tr(e, t) {
|
|
2677
2699
|
try {
|
|
2678
2700
|
let n = /^[a-z][a-z\d+.-]*:/i.test(e) ? new URL(e).pathname : e;
|
|
2679
2701
|
return g(decodeURIComponent(n)).trim() || t;
|
|
@@ -2681,7 +2703,7 @@ function wr(e, t) {
|
|
|
2681
2703
|
return g(e).trim() || t;
|
|
2682
2704
|
}
|
|
2683
2705
|
}
|
|
2684
|
-
function
|
|
2706
|
+
function Er(e) {
|
|
2685
2707
|
let t = /^data:([^;,]+)/i.exec(e)?.[1]?.toLowerCase();
|
|
2686
2708
|
if (t) return t;
|
|
2687
2709
|
let n = "";
|
|
@@ -2703,23 +2725,23 @@ function Tr(e) {
|
|
|
2703
2725
|
webp: "image/webp"
|
|
2704
2726
|
}[n];
|
|
2705
2727
|
}
|
|
2706
|
-
function
|
|
2728
|
+
function Dr(e) {
|
|
2707
2729
|
if (!e) return null;
|
|
2708
2730
|
let t = (/^data:image\/[a-z0-9.+-]+;base64,([a-z0-9+/=\s]+)$/i.exec(e)?.[1] ?? e).replace(/\s+/g, ""), n = Math.ceil(ur / 3) * 4 + 4;
|
|
2709
2731
|
if (!t || t.length > n || t.length % 4 != 0 || !/^[a-z0-9+/]+={0,2}$/i.test(t)) return null;
|
|
2710
2732
|
let r = Buffer.from(t, "base64");
|
|
2711
2733
|
if (r.byteLength === 0 || r.byteLength > ur) return null;
|
|
2712
|
-
let i =
|
|
2734
|
+
let i = kr(r);
|
|
2713
2735
|
return i ? {
|
|
2714
2736
|
url: `data:${i};base64,${t}`,
|
|
2715
2737
|
mimeType: i
|
|
2716
2738
|
} : null;
|
|
2717
2739
|
}
|
|
2718
|
-
function
|
|
2740
|
+
function Or(e) {
|
|
2719
2741
|
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));
|
|
2720
2742
|
}
|
|
2721
|
-
function
|
|
2722
|
-
if (
|
|
2743
|
+
function kr(e) {
|
|
2744
|
+
if (Ar(e, [
|
|
2723
2745
|
137,
|
|
2724
2746
|
80,
|
|
2725
2747
|
78,
|
|
@@ -2729,7 +2751,7 @@ function Or(e) {
|
|
|
2729
2751
|
26,
|
|
2730
2752
|
10
|
|
2731
2753
|
])) return "image/png";
|
|
2732
|
-
if (
|
|
2754
|
+
if (Ar(e, [
|
|
2733
2755
|
255,
|
|
2734
2756
|
216,
|
|
2735
2757
|
255
|
|
@@ -2737,13 +2759,13 @@ function Or(e) {
|
|
|
2737
2759
|
let t = Buffer.from(e.subarray(0, 12)).toString("ascii");
|
|
2738
2760
|
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;
|
|
2739
2761
|
}
|
|
2740
|
-
function
|
|
2762
|
+
function Ar(e, t) {
|
|
2741
2763
|
return t.every((t, n) => e[n] === t);
|
|
2742
2764
|
}
|
|
2743
|
-
function
|
|
2765
|
+
function jr(e) {
|
|
2744
2766
|
return e === "inProgress" ? "streaming" : e === "failed" ? "error" : "complete";
|
|
2745
2767
|
}
|
|
2746
|
-
function
|
|
2768
|
+
function Mr(e) {
|
|
2747
2769
|
return typeof e != "number" || !Number.isFinite(e) ? (/* @__PURE__ */ new Date(0)).toISOString() : (/* @__PURE__ */ new Date(e * 1e3)).toISOString();
|
|
2748
2770
|
}
|
|
2749
2771
|
function q(e) {
|
|
@@ -2751,19 +2773,19 @@ function q(e) {
|
|
|
2751
2773
|
}
|
|
2752
2774
|
//#endregion
|
|
2753
2775
|
//#region src/node/codex-raw-response-item-adapter.ts
|
|
2754
|
-
function
|
|
2755
|
-
if (!
|
|
2776
|
+
function Nr(e) {
|
|
2777
|
+
if (!Hr(e) || typeof e.type != "string") return null;
|
|
2756
2778
|
if (e.type === "local_shell_call") {
|
|
2757
|
-
let t = L(
|
|
2779
|
+
let t = L(Pr(e));
|
|
2758
2780
|
return {
|
|
2759
|
-
type:
|
|
2781
|
+
type: Rr(e.status) ? "item.completed" : "item.started",
|
|
2760
2782
|
payload: { toolPart: t }
|
|
2761
2783
|
};
|
|
2762
2784
|
}
|
|
2763
2785
|
return e.type === "function_call" ? {
|
|
2764
2786
|
type: "item.started",
|
|
2765
|
-
payload: { toolPart: L(
|
|
2766
|
-
} : e.type === "function_call_output" ?
|
|
2787
|
+
payload: { toolPart: L(Fr(e)) }
|
|
2788
|
+
} : e.type === "function_call_output" ? Ir(e.call_id, e.output) : e.type === "custom_tool_call" ? {
|
|
2767
2789
|
type: "item.started",
|
|
2768
2790
|
payload: { toolPart: L({
|
|
2769
2791
|
type: "dynamicToolCall",
|
|
@@ -2776,7 +2798,7 @@ function Mr(e) {
|
|
|
2776
2798
|
success: null,
|
|
2777
2799
|
durationMs: null
|
|
2778
2800
|
}) }
|
|
2779
|
-
} : e.type === "custom_tool_call_output" ?
|
|
2801
|
+
} : e.type === "custom_tool_call_output" ? Ir(e.call_id, e.output, Y(e.name) ?? void 0) : e.type === "tool_search_call" ? {
|
|
2780
2802
|
type: "item.started",
|
|
2781
2803
|
payload: { toolPart: L({
|
|
2782
2804
|
type: "dynamicToolCall",
|
|
@@ -2798,7 +2820,7 @@ function Mr(e) {
|
|
|
2798
2820
|
payload: { toolPart: L({
|
|
2799
2821
|
type: "webSearch",
|
|
2800
2822
|
id: J(e),
|
|
2801
|
-
query:
|
|
2823
|
+
query: Br(e.action),
|
|
2802
2824
|
action: e.action
|
|
2803
2825
|
}) }
|
|
2804
2826
|
} : e.type === "image_generation_call" ? {
|
|
@@ -2816,8 +2838,8 @@ function Mr(e) {
|
|
|
2816
2838
|
}) }
|
|
2817
2839
|
} : null;
|
|
2818
2840
|
}
|
|
2819
|
-
function
|
|
2820
|
-
let t =
|
|
2841
|
+
function Pr(e) {
|
|
2842
|
+
let t = Hr(e.action) ? e.action : {}, n = Array.isArray(t.command) ? Vr(t.command) : Y(t.command) ?? "local shell";
|
|
2821
2843
|
return {
|
|
2822
2844
|
type: "commandExecution",
|
|
2823
2845
|
id: Y(e.call_id) ?? J(e),
|
|
@@ -2825,16 +2847,16 @@ function Nr(e) {
|
|
|
2825
2847
|
cwd: Y(t.working_directory) ?? "",
|
|
2826
2848
|
processId: null,
|
|
2827
2849
|
source: "agent",
|
|
2828
|
-
status:
|
|
2850
|
+
status: Lr(e.status),
|
|
2829
2851
|
commandActions: [],
|
|
2830
2852
|
aggregatedOutput: null,
|
|
2831
2853
|
exitCode: null,
|
|
2832
2854
|
durationMs: null
|
|
2833
2855
|
};
|
|
2834
2856
|
}
|
|
2835
|
-
function
|
|
2836
|
-
let t = Y(e.name) ?? "function_call", n =
|
|
2837
|
-
return t === "shell_command" &&
|
|
2857
|
+
function Fr(e) {
|
|
2858
|
+
let t = Y(e.name) ?? "function_call", n = zr(e.arguments), r = Y(e.call_id) ?? J(e);
|
|
2859
|
+
return t === "shell_command" && Hr(n) ? {
|
|
2838
2860
|
type: "commandExecution",
|
|
2839
2861
|
id: r,
|
|
2840
2862
|
command: Y(n.command) ?? t,
|
|
@@ -2858,19 +2880,19 @@ function Pr(e) {
|
|
|
2858
2880
|
durationMs: null
|
|
2859
2881
|
};
|
|
2860
2882
|
}
|
|
2861
|
-
function
|
|
2883
|
+
function Ir(e, t, n) {
|
|
2862
2884
|
return {
|
|
2863
2885
|
type: "item.updated",
|
|
2864
2886
|
payload: xn(Y(e) ?? "raw-response-output", t, n)
|
|
2865
2887
|
};
|
|
2866
2888
|
}
|
|
2867
|
-
function
|
|
2889
|
+
function Lr(e) {
|
|
2868
2890
|
return e === "completed" ? "completed" : e === "incomplete" || e === "failed" || e === "error" ? "failed" : "inProgress";
|
|
2869
2891
|
}
|
|
2870
|
-
function
|
|
2892
|
+
function Rr(e) {
|
|
2871
2893
|
return e === "completed" || e === "failed" || e === "error" || e === "incomplete";
|
|
2872
2894
|
}
|
|
2873
|
-
function
|
|
2895
|
+
function zr(e) {
|
|
2874
2896
|
if (typeof e != "string") return e;
|
|
2875
2897
|
try {
|
|
2876
2898
|
return JSON.parse(e);
|
|
@@ -2878,10 +2900,10 @@ function Rr(e) {
|
|
|
2878
2900
|
return e;
|
|
2879
2901
|
}
|
|
2880
2902
|
}
|
|
2881
|
-
function zr(e) {
|
|
2882
|
-
return Vr(e) ? Y(e.query) ?? Y(e.searchTerm) ?? "web search" : "web search";
|
|
2883
|
-
}
|
|
2884
2903
|
function Br(e) {
|
|
2904
|
+
return Hr(e) ? Y(e.query) ?? Y(e.searchTerm) ?? "web search" : "web search";
|
|
2905
|
+
}
|
|
2906
|
+
function Vr(e) {
|
|
2885
2907
|
return e.map((e) => {
|
|
2886
2908
|
let t = String(e);
|
|
2887
2909
|
return /\s/.test(t) ? JSON.stringify(t) : t;
|
|
@@ -2893,21 +2915,21 @@ function J(e) {
|
|
|
2893
2915
|
function Y(e) {
|
|
2894
2916
|
return typeof e == "string" && e.length > 0 ? e : null;
|
|
2895
2917
|
}
|
|
2896
|
-
function
|
|
2918
|
+
function Hr(e) {
|
|
2897
2919
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
2898
2920
|
}
|
|
2899
2921
|
//#endregion
|
|
2900
2922
|
//#region src/node/codex-surface-events.ts
|
|
2901
|
-
function
|
|
2923
|
+
function Ur(e, t) {
|
|
2902
2924
|
return `${e}\u0000${t}`;
|
|
2903
2925
|
}
|
|
2904
2926
|
function X(e) {
|
|
2905
2927
|
return typeof e == "number" && Number.isFinite(e) ? (/* @__PURE__ */ new Date(e * 1e3)).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
|
|
2906
2928
|
}
|
|
2907
|
-
function
|
|
2929
|
+
function Wr(e) {
|
|
2908
2930
|
return typeof e == "number" && Number.isFinite(e) ? (/* @__PURE__ */ new Date(e * 1e3)).toISOString() : null;
|
|
2909
2931
|
}
|
|
2910
|
-
function
|
|
2932
|
+
function Gr(e) {
|
|
2911
2933
|
return e ? {
|
|
2912
2934
|
message: e.message,
|
|
2913
2935
|
additionalDetails: e.additionalDetails,
|
|
@@ -2918,10 +2940,10 @@ function Z(e, t = !1) {
|
|
|
2918
2940
|
return {
|
|
2919
2941
|
id: e.id,
|
|
2920
2942
|
status: e.status,
|
|
2921
|
-
error:
|
|
2943
|
+
error: Gr(e.error),
|
|
2922
2944
|
willRetry: t,
|
|
2923
|
-
startedAt:
|
|
2924
|
-
completedAt:
|
|
2945
|
+
startedAt: Wr(e.startedAt),
|
|
2946
|
+
completedAt: Wr(e.completedAt),
|
|
2925
2947
|
durationMs: e.durationMs ?? null
|
|
2926
2948
|
};
|
|
2927
2949
|
}
|
|
@@ -2931,18 +2953,18 @@ function Q(e, t) {
|
|
|
2931
2953
|
let r = [...e];
|
|
2932
2954
|
return r.splice(n, 1, t), r;
|
|
2933
2955
|
}
|
|
2934
|
-
function
|
|
2956
|
+
function Kr(e, t) {
|
|
2935
2957
|
return JSON.stringify(e) === JSON.stringify(t);
|
|
2936
2958
|
}
|
|
2937
|
-
function
|
|
2959
|
+
function qr() {
|
|
2938
2960
|
return `user-${globalThis.crypto.randomUUID()}`;
|
|
2939
2961
|
}
|
|
2940
|
-
function
|
|
2962
|
+
function Jr() {
|
|
2941
2963
|
return `queued-prompt-${globalThis.crypto.randomUUID()}`;
|
|
2942
2964
|
}
|
|
2943
2965
|
//#endregion
|
|
2944
2966
|
//#region src/node/codex-surface-subagents.ts
|
|
2945
|
-
function
|
|
2967
|
+
function Yr(e) {
|
|
2946
2968
|
let t = {};
|
|
2947
2969
|
for (let [n, r] of Object.entries(e.agentsStates)) r && (t[n] = {
|
|
2948
2970
|
status: r.status,
|
|
@@ -2962,7 +2984,7 @@ function Jr(e) {
|
|
|
2962
2984
|
}
|
|
2963
2985
|
//#endregion
|
|
2964
2986
|
//#region src/node/codex-surface-items-controller.ts
|
|
2965
|
-
var
|
|
2987
|
+
var Xr = class {
|
|
2966
2988
|
host;
|
|
2967
2989
|
commandOutputForwardItemIds = /* @__PURE__ */ new Set();
|
|
2968
2990
|
fileActivityKeys = /* @__PURE__ */ new Set();
|
|
@@ -2980,7 +3002,7 @@ var Yr = class {
|
|
|
2980
3002
|
for (let e of this.reviewOutputByTurn.keys()) e.startsWith(t) && this.reviewOutputByTurn.delete(e);
|
|
2981
3003
|
}
|
|
2982
3004
|
isForwardingCommandOutput(e, t) {
|
|
2983
|
-
return this.commandOutputForwardItemIds.has(
|
|
3005
|
+
return this.commandOutputForwardItemIds.has(Ur(e, t));
|
|
2984
3006
|
}
|
|
2985
3007
|
applyAgentDelta(e) {
|
|
2986
3008
|
let t = this.host.requireRuntime(e.threadId);
|
|
@@ -3043,7 +3065,7 @@ var Yr = class {
|
|
|
3043
3065
|
applyRawResponseItem(e) {
|
|
3044
3066
|
let t = this.host.requireRuntime(e.threadId);
|
|
3045
3067
|
this.host.markRuntimeTurnActive(t, e.turnId);
|
|
3046
|
-
let n =
|
|
3068
|
+
let n = Nr(e.item);
|
|
3047
3069
|
if (!n) return;
|
|
3048
3070
|
if (n.type === "item.updated") {
|
|
3049
3071
|
this.applyToolUpdate(e.threadId, e.turnId, n.payload);
|
|
@@ -3144,7 +3166,7 @@ var Yr = class {
|
|
|
3144
3166
|
if (e.item.type === "agentMessage" || e.item.type === "exitedReviewMode") {
|
|
3145
3167
|
let t = e.item.type === "agentMessage" ? e.item.text : e.item.review, r = e.item.type === "agentMessage" ? e.item.phase ?? void 0 : void 0;
|
|
3146
3168
|
if (!t && e.item.type !== "agentMessage") return;
|
|
3147
|
-
let i =
|
|
3169
|
+
let i = Ur(e.threadId, e.turnId);
|
|
3148
3170
|
if (e.item.type === "agentMessage" && this.reviewOutputByTurn.get(i) === t) return;
|
|
3149
3171
|
e.item.type === "exitedReviewMode" && this.reviewOutputByTurn.set(i, t);
|
|
3150
3172
|
let a = new Set(n.messages.map((e) => e.id)), o = this.host.assistantMessageForTurn(e.threadId, e.turnId), s = o ? JSON.stringify(o.parts) : null, c = new Set(o?.parts.flatMap((e) => e.type === "question" ? [e.request.id] : []) ?? []), l = n.messages.flatMap((e) => e.parts).find((t) => t.type === "text" && t.itemId === e.item.id)?.text ?? "", u = e.item.type === "agentMessage" ? gr(e.threadId, e.turnId, e.item) : null, d = u ? "" : t, f = u ? Qn(n.messages, e.threadId, e.turnId, e.item.id) : Zn(n.messages, e.threadId, e.turnId, e.item.id, t, r);
|
|
@@ -3230,7 +3252,7 @@ var Yr = class {
|
|
|
3230
3252
|
turnId: e.turnId,
|
|
3231
3253
|
payload: {
|
|
3232
3254
|
lifecycle: t ? "completed" : "started",
|
|
3233
|
-
toolCall:
|
|
3255
|
+
toolCall: Yr(e.item)
|
|
3234
3256
|
}
|
|
3235
3257
|
});
|
|
3236
3258
|
return;
|
|
@@ -3255,10 +3277,11 @@ var Yr = class {
|
|
|
3255
3277
|
let a = this.shouldForwardCommandOutput(e.threadId, t, e.item), o = L(e.item, {
|
|
3256
3278
|
includeCommandOutput: a,
|
|
3257
3279
|
cwd: n.cwd
|
|
3258
|
-
}), s =
|
|
3259
|
-
if (!o && !s) return;
|
|
3260
|
-
let c = s
|
|
3261
|
-
s
|
|
3280
|
+
}), s = vr(e.item);
|
|
3281
|
+
if (!o && !s.length) return;
|
|
3282
|
+
let c = s.some((e) => !n.messages.some((t) => t.parts.some((t) => t.type === "media" && nr(t, e)))), l = o ? W(n.messages, e.threadId, e.turnId, o) : [...n.messages];
|
|
3283
|
+
for (let t of s) l = er(l, e.threadId, e.turnId, t, e.item.id);
|
|
3284
|
+
this.host.patchRuntime(e.threadId, { messages: l });
|
|
3262
3285
|
let u = o ? this.host.messageContainingTool(e.threadId, e.turnId, o.id) : this.host.assistantMessageForTurn(e.threadId, e.turnId);
|
|
3263
3286
|
u && o && this.host.emitEvent("notification", {
|
|
3264
3287
|
type: t ? "tool.completed" : "tool.started",
|
|
@@ -3268,7 +3291,7 @@ var Yr = class {
|
|
|
3268
3291
|
messageId: u.id,
|
|
3269
3292
|
toolPart: structuredClone(o)
|
|
3270
3293
|
}
|
|
3271
|
-
}), u && o && this.emitFileActivities(e.threadId, e.turnId, u.id, o.id, o, n.cwd), u &&
|
|
3294
|
+
}), u && o && this.emitFileActivities(e.threadId, e.turnId, u.id, o.id, o, n.cwd), u && c && this.host.emitEvent("notification", {
|
|
3272
3295
|
type: "message.updated",
|
|
3273
3296
|
conversationId: e.threadId,
|
|
3274
3297
|
turnId: e.turnId,
|
|
@@ -3278,7 +3301,7 @@ var Yr = class {
|
|
|
3278
3301
|
shouldForwardCommandOutput(e, t, n) {
|
|
3279
3302
|
let r = "id" in n && typeof n.id == "string" ? n.id : null;
|
|
3280
3303
|
if (!r) return !1;
|
|
3281
|
-
let i =
|
|
3304
|
+
let i = Ur(e, r);
|
|
3282
3305
|
if (!t) {
|
|
3283
3306
|
let e = _n(n);
|
|
3284
3307
|
return e ? this.commandOutputForwardItemIds.add(i) : this.commandOutputForwardItemIds.delete(i), e;
|
|
@@ -3289,7 +3312,7 @@ var Yr = class {
|
|
|
3289
3312
|
applyToolUpdate(e, t, n) {
|
|
3290
3313
|
let r = this.host.requireRuntime(e);
|
|
3291
3314
|
this.host.markRuntimeTurnActive(r, t);
|
|
3292
|
-
let i = r.cwd &&
|
|
3315
|
+
let i = r.cwd && Zr(n) ? {
|
|
3293
3316
|
...n,
|
|
3294
3317
|
metadata: {
|
|
3295
3318
|
...n.metadata,
|
|
@@ -3358,26 +3381,26 @@ var Yr = class {
|
|
|
3358
3381
|
turnId: e.turn.id,
|
|
3359
3382
|
payload: {
|
|
3360
3383
|
status: e.turn.status,
|
|
3361
|
-
error:
|
|
3384
|
+
error: Gr(e.turn.error),
|
|
3362
3385
|
willRetry: !1,
|
|
3363
|
-
startedAt:
|
|
3364
|
-
completedAt:
|
|
3386
|
+
startedAt: Wr(e.turn.startedAt),
|
|
3387
|
+
completedAt: Wr(e.turn.completedAt),
|
|
3365
3388
|
durationMs: e.turn.durationMs ?? null
|
|
3366
3389
|
}
|
|
3367
3390
|
}), this.host.emitConversationActivity(e.threadId, "notification"), t.planMarkdownByTurn.delete(e.turn.id), this.host.sendNextQueuedPrompt(e.threadId);
|
|
3368
3391
|
}
|
|
3369
3392
|
};
|
|
3370
|
-
function
|
|
3393
|
+
function Zr(e) {
|
|
3371
3394
|
if (e.fallbackToolPart?.kind === "fileChange") return !0;
|
|
3372
3395
|
let t = e.input, n = e.metadata;
|
|
3373
|
-
return
|
|
3396
|
+
return Qr(t) && Array.isArray(t.changes) || Qr(n) && Array.isArray(n.changes);
|
|
3374
3397
|
}
|
|
3375
|
-
function
|
|
3398
|
+
function Qr(e) {
|
|
3376
3399
|
return typeof e == "object" && !!e;
|
|
3377
3400
|
}
|
|
3378
3401
|
//#endregion
|
|
3379
3402
|
//#region src/node/codex-surface-client-requests-controller.ts
|
|
3380
|
-
var
|
|
3403
|
+
var $r = class {
|
|
3381
3404
|
host;
|
|
3382
3405
|
pending = /* @__PURE__ */ new Map();
|
|
3383
3406
|
constructor(e) {
|
|
@@ -3659,8 +3682,8 @@ ${JSON.stringify(s)}\n</send_user_message_question_reply>`, t = s.length === 1 ?
|
|
|
3659
3682
|
payload: { request: structuredClone(d) }
|
|
3660
3683
|
}), this.host.emitConversationActivity(n.threadId, "notification"), !0;
|
|
3661
3684
|
}
|
|
3662
|
-
},
|
|
3663
|
-
function
|
|
3685
|
+
}, ei = 256 * 1024;
|
|
3686
|
+
function ti(e) {
|
|
3664
3687
|
return {
|
|
3665
3688
|
id: e.id,
|
|
3666
3689
|
model: e.model,
|
|
@@ -3685,11 +3708,11 @@ function ei(e) {
|
|
|
3685
3708
|
}
|
|
3686
3709
|
};
|
|
3687
3710
|
}
|
|
3688
|
-
async function ti(e, t) {
|
|
3689
|
-
return Promise.all(e.filter((e) => e.enabled).map((e) => ni(e, t)));
|
|
3690
|
-
}
|
|
3691
3711
|
async function ni(e, t) {
|
|
3692
|
-
|
|
3712
|
+
return Promise.all(e.filter((e) => e.enabled).map((e) => ri(e, t)));
|
|
3713
|
+
}
|
|
3714
|
+
async function ri(e, t) {
|
|
3715
|
+
let n = $(e.interface?.brandColor), r = li(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]);
|
|
3693
3716
|
return {
|
|
3694
3717
|
name: e.name,
|
|
3695
3718
|
description: e.description,
|
|
@@ -3704,8 +3727,8 @@ async function ni(e, t) {
|
|
|
3704
3727
|
enabled: e.enabled
|
|
3705
3728
|
};
|
|
3706
3729
|
}
|
|
3707
|
-
async function
|
|
3708
|
-
let n = e.interface, r =
|
|
3730
|
+
async function ii(e, t) {
|
|
3731
|
+
let n = e.interface, r = oi(n?.composerIconUrl), i = oi(n?.logoUrl), a = oi(n?.logoUrlDark), o = $(n?.displayName) ?? e.name, s = $(n?.shortDescription), c = $(n?.longDescription), l = $(n?.brandColor), u = r ?? i ?? await ai([n?.composerIcon, n?.logo], t), d = r ?? a ?? i ?? await ai([
|
|
3709
3732
|
n?.composerIcon,
|
|
3710
3733
|
n?.logoDark,
|
|
3711
3734
|
n?.logo
|
|
@@ -3722,20 +3745,20 @@ async function ri(e, t) {
|
|
|
3722
3745
|
enabled: e.enabled
|
|
3723
3746
|
};
|
|
3724
3747
|
}
|
|
3725
|
-
async function
|
|
3748
|
+
async function ai(e, t) {
|
|
3726
3749
|
for (let n of e) {
|
|
3727
3750
|
if (!n) continue;
|
|
3728
3751
|
let e = await t(n);
|
|
3729
3752
|
if (e) return e;
|
|
3730
3753
|
}
|
|
3731
3754
|
}
|
|
3732
|
-
function
|
|
3755
|
+
function oi(e) {
|
|
3733
3756
|
let t = $(e);
|
|
3734
3757
|
try {
|
|
3735
3758
|
return new URL(t).protocol === "https:" ? t : void 0;
|
|
3736
3759
|
} catch {}
|
|
3737
3760
|
}
|
|
3738
|
-
function
|
|
3761
|
+
function si(e) {
|
|
3739
3762
|
switch (_(e).toLowerCase()) {
|
|
3740
3763
|
case ".avif": return "image/avif";
|
|
3741
3764
|
case ".bmp": return "image/bmp";
|
|
@@ -3748,23 +3771,23 @@ function oi(e) {
|
|
|
3748
3771
|
case ".webp": return "image/webp";
|
|
3749
3772
|
}
|
|
3750
3773
|
}
|
|
3751
|
-
function
|
|
3774
|
+
function ci(e, t) {
|
|
3752
3775
|
let n = t.trim();
|
|
3753
3776
|
if (!/^[a-z\d+/]+={0,2}$/i.test(n)) return;
|
|
3754
3777
|
let r = n.replace(/=+$/, "");
|
|
3755
3778
|
if (r.length % 4 == 1) return;
|
|
3756
3779
|
let i = n.length - r.length, a = (4 - r.length % 4) % 4;
|
|
3757
|
-
if (!(i !== 0 && i !== a) && !(Math.floor(r.length * 3 / 4) >
|
|
3780
|
+
if (!(i !== 0 && i !== a) && !(Math.floor(r.length * 3 / 4) > ei)) return `data:${e};base64,${`${r}${"=".repeat((4 - r.length % 4) % 4)}`}`;
|
|
3758
3781
|
}
|
|
3759
3782
|
function $(e) {
|
|
3760
3783
|
return (typeof e == "string" ? e.trim() : void 0) || void 0;
|
|
3761
3784
|
}
|
|
3762
|
-
function
|
|
3785
|
+
function li(e) {
|
|
3763
3786
|
return typeof e == "string" ? e : void 0;
|
|
3764
3787
|
}
|
|
3765
3788
|
//#endregion
|
|
3766
3789
|
//#region src/node/codex-surface-catalog-controller.ts
|
|
3767
|
-
var
|
|
3790
|
+
var ui = class {
|
|
3768
3791
|
client;
|
|
3769
3792
|
cwd;
|
|
3770
3793
|
host;
|
|
@@ -3799,7 +3822,7 @@ var li = class {
|
|
|
3799
3822
|
async loadSkills(e = !1, t = "action") {
|
|
3800
3823
|
e && this.iconDataUrls.clear(), this.host.patch({ skillCatalogStatus: "loading" }), this.emitSkills(this.cwd ?? null, [], "loading", t);
|
|
3801
3824
|
try {
|
|
3802
|
-
let n = await
|
|
3825
|
+
let n = await ni((await this.client.request("skills/list", {
|
|
3803
3826
|
...this.cwd ? { cwds: [this.cwd] } : {},
|
|
3804
3827
|
forceReload: e
|
|
3805
3828
|
})).data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e));
|
|
@@ -3816,7 +3839,7 @@ var li = class {
|
|
|
3816
3839
|
}
|
|
3817
3840
|
async listSkills(e = {}) {
|
|
3818
3841
|
await this.host.ensureConnected(), e.forceReload && this.iconDataUrls.clear();
|
|
3819
|
-
let t = await
|
|
3842
|
+
let t = await ni((await this.client.request("skills/list", {
|
|
3820
3843
|
...e.cwd ? { cwds: [e.cwd] } : {},
|
|
3821
3844
|
forceReload: e.forceReload ?? !1
|
|
3822
3845
|
})).data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e));
|
|
@@ -3870,7 +3893,7 @@ var li = class {
|
|
|
3870
3893
|
}), (async () => ({
|
|
3871
3894
|
profiles: await this.requestPermissionProfiles(e),
|
|
3872
3895
|
requirements: (await this.client.request("configRequirements/read", void 0)).requirements
|
|
3873
|
-
}))()]), a = r.status === "fulfilled" ? await
|
|
3896
|
+
}))()]), a = r.status === "fulfilled" ? await ni(r.value.data.flatMap((e) => e.skills), (e) => this.iconDataUrl(e)) : [], o = i.status === "fulfilled" ? i.value.profiles : [];
|
|
3874
3897
|
return {
|
|
3875
3898
|
skills: a,
|
|
3876
3899
|
skillCatalogStatus: r.status === "fulfilled" ? "loaded" : "error",
|
|
@@ -3902,7 +3925,7 @@ var li = class {
|
|
|
3902
3925
|
cursor: n,
|
|
3903
3926
|
includeHidden: e
|
|
3904
3927
|
});
|
|
3905
|
-
t.push(...r.data.map(
|
|
3928
|
+
t.push(...r.data.map(ti)), n = r.nextCursor;
|
|
3906
3929
|
} while (n);
|
|
3907
3930
|
return t;
|
|
3908
3931
|
}
|
|
@@ -3972,7 +3995,7 @@ var li = class {
|
|
|
3972
3995
|
try {
|
|
3973
3996
|
let t = await this.client.request("plugin/installed", { ...e.length > 0 ? { cwds: [...e] } : {} }), n = /* @__PURE__ */ new Map();
|
|
3974
3997
|
for (let e of t.marketplaces) for (let t of e.plugins) n.has(t.id) || n.set(t.id, t);
|
|
3975
|
-
let r = Ht(this.host.getState().plugins, await Promise.all([...n.values()].map((e) =>
|
|
3998
|
+
let r = Ht(this.host.getState().plugins, await Promise.all([...n.values()].map((e) => ii(e, (e) => this.iconDataUrl(e)))));
|
|
3976
3999
|
if (this.host.isClosed() || this.host.authenticationBlocksBootstrap()) return;
|
|
3977
4000
|
this.host.patch({
|
|
3978
4001
|
plugins: r,
|
|
@@ -4003,9 +4026,9 @@ var li = class {
|
|
|
4003
4026
|
}
|
|
4004
4027
|
async readIconDataUrl(e) {
|
|
4005
4028
|
if (!v(e)) return;
|
|
4006
|
-
let t =
|
|
4029
|
+
let t = si(e);
|
|
4007
4030
|
if (t) try {
|
|
4008
|
-
return
|
|
4031
|
+
return ci(t, (await this.client.request("fs/readFile", { path: e })).dataBase64);
|
|
4009
4032
|
} catch {
|
|
4010
4033
|
return;
|
|
4011
4034
|
}
|
|
@@ -4013,18 +4036,18 @@ var li = class {
|
|
|
4013
4036
|
};
|
|
4014
4037
|
//#endregion
|
|
4015
4038
|
//#region src/node/codex-approvals.ts
|
|
4016
|
-
function
|
|
4039
|
+
function di(e, t) {
|
|
4017
4040
|
let n = [
|
|
4018
4041
|
e.onServerRequest("item/commandExecution/requestApproval", (e, n) => (t({
|
|
4019
|
-
approval:
|
|
4020
|
-
resolve: (t, r) => n.resolve({ decision:
|
|
4042
|
+
approval: fi(e.id, e.params),
|
|
4043
|
+
resolve: (t, r) => n.resolve({ decision: hi(e.params, t, r) })
|
|
4021
4044
|
}), !0)),
|
|
4022
4045
|
e.onServerRequest("item/fileChange/requestApproval", (e, n) => (t({
|
|
4023
|
-
approval:
|
|
4046
|
+
approval: pi(e.id, e.params),
|
|
4024
4047
|
resolve: (e, t) => n.resolve({ decision: e === "deny" ? "decline" : t === "session" ? "acceptForSession" : "accept" })
|
|
4025
4048
|
}), !0)),
|
|
4026
4049
|
e.onServerRequest("item/permissions/requestApproval", (e, n) => (t({
|
|
4027
|
-
approval:
|
|
4050
|
+
approval: mi(e.id, e.params),
|
|
4028
4051
|
resolve: (t, r) => n.resolve({
|
|
4029
4052
|
permissions: t === "deny" ? {} : {
|
|
4030
4053
|
...e.params.permissions.fileSystem ? { fileSystem: e.params.permissions.fileSystem } : {},
|
|
@@ -4062,8 +4085,8 @@ function ui(e, t) {
|
|
|
4062
4085
|
for (let e of n) e();
|
|
4063
4086
|
};
|
|
4064
4087
|
}
|
|
4065
|
-
function
|
|
4066
|
-
let n = t.availableDecisions, r =
|
|
4088
|
+
function fi(e, t) {
|
|
4089
|
+
let n = t.availableDecisions, r = gi(t.additionalPermissions), i = [...t.networkApprovalContext ? [{
|
|
4067
4090
|
kind: "network",
|
|
4068
4091
|
enabled: !0,
|
|
4069
4092
|
host: t.networkApprovalContext.host,
|
|
@@ -4086,7 +4109,7 @@ function di(e, t) {
|
|
|
4086
4109
|
} : {}
|
|
4087
4110
|
};
|
|
4088
4111
|
}
|
|
4089
|
-
function
|
|
4112
|
+
function pi(e, t) {
|
|
4090
4113
|
return {
|
|
4091
4114
|
id: String(e),
|
|
4092
4115
|
kind: "file-change",
|
|
@@ -4097,8 +4120,8 @@ function fi(e, t) {
|
|
|
4097
4120
|
...t.reason || t.grantRoot ? { description: t.reason ?? `Write under ${t.grantRoot}` } : {}
|
|
4098
4121
|
};
|
|
4099
4122
|
}
|
|
4100
|
-
function
|
|
4101
|
-
let n =
|
|
4123
|
+
function mi(e, t) {
|
|
4124
|
+
let n = gi(t.permissions);
|
|
4102
4125
|
return {
|
|
4103
4126
|
id: String(e),
|
|
4104
4127
|
kind: "permissions",
|
|
@@ -4111,13 +4134,13 @@ function pi(e, t) {
|
|
|
4111
4134
|
...n.length ? { requestedPermissions: n } : {}
|
|
4112
4135
|
};
|
|
4113
4136
|
}
|
|
4114
|
-
function
|
|
4137
|
+
function hi(e, t, n) {
|
|
4115
4138
|
let r = e.availableDecisions, i = t === "deny" ? "decline" : n === "session" ? "acceptForSession" : "accept";
|
|
4116
4139
|
if (!r || r.includes(i)) return i;
|
|
4117
4140
|
if (t === "deny" && r.includes("cancel")) return "cancel";
|
|
4118
4141
|
throw Error(`Approval decision '${t}:${n}' is not available for this command`);
|
|
4119
4142
|
}
|
|
4120
|
-
function
|
|
4143
|
+
function gi(e) {
|
|
4121
4144
|
if (!e) return [];
|
|
4122
4145
|
let t = [];
|
|
4123
4146
|
if (e.network && t.push({
|
|
@@ -4137,12 +4160,12 @@ function hi(e) {
|
|
|
4137
4160
|
for (let n of e.fileSystem.entries ?? []) t.push({
|
|
4138
4161
|
kind: "filesystem",
|
|
4139
4162
|
access: n.access,
|
|
4140
|
-
path:
|
|
4163
|
+
path: _i(n.path)
|
|
4141
4164
|
});
|
|
4142
4165
|
}
|
|
4143
4166
|
return t;
|
|
4144
4167
|
}
|
|
4145
|
-
function
|
|
4168
|
+
function _i(e) {
|
|
4146
4169
|
if (e.type === "path") return e.path;
|
|
4147
4170
|
if (e.type === "glob_pattern") return e.pattern;
|
|
4148
4171
|
let t = e.value;
|
|
@@ -4157,12 +4180,12 @@ function gi(e) {
|
|
|
4157
4180
|
}
|
|
4158
4181
|
//#endregion
|
|
4159
4182
|
//#region src/node/codex-surface-approvals-controller.ts
|
|
4160
|
-
var
|
|
4183
|
+
var vi = class {
|
|
4161
4184
|
host;
|
|
4162
4185
|
pending = /* @__PURE__ */ new Map();
|
|
4163
4186
|
unsubscribeHandler;
|
|
4164
4187
|
constructor(e, t) {
|
|
4165
|
-
this.host = t, this.unsubscribeHandler =
|
|
4188
|
+
this.host = t, this.unsubscribeHandler = di(e, (e) => this.add(e));
|
|
4166
4189
|
}
|
|
4167
4190
|
close() {
|
|
4168
4191
|
this.unsubscribeHandler(), this.pending.clear();
|
|
@@ -4243,7 +4266,7 @@ var _i = class {
|
|
|
4243
4266
|
};
|
|
4244
4267
|
//#endregion
|
|
4245
4268
|
//#region src/node/codex-surface-mcp.ts
|
|
4246
|
-
function
|
|
4269
|
+
function yi(e) {
|
|
4247
4270
|
if (!Array.isArray(e)) throw TypeError("Codex MCP servers must be an array");
|
|
4248
4271
|
let t = /* @__PURE__ */ new Set();
|
|
4249
4272
|
return e.map((e, n) => {
|
|
@@ -4252,10 +4275,10 @@ function vi(e) {
|
|
|
4252
4275
|
if (!r || !/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(r)) throw TypeError(`Codex MCP server ${n + 1} name must match ^[A-Za-z0-9][A-Za-z0-9_-]*$`);
|
|
4253
4276
|
if (t.has(r)) throw Error(`Duplicate Codex MCP server '${r}'`);
|
|
4254
4277
|
t.add(r);
|
|
4255
|
-
let i =
|
|
4278
|
+
let i = bi(e.transport, r), a = e.toolApprovalMode;
|
|
4256
4279
|
if (a !== void 0 && a !== "auto" && a !== "prompt" && a !== "writes" && a !== "approve") throw TypeError(`Codex MCP server '${r}' tool approval mode is invalid`);
|
|
4257
4280
|
if (e.required !== void 0 && typeof e.required != "boolean") throw TypeError(`Codex MCP server '${r}' required flag must be a boolean`);
|
|
4258
|
-
let o = e.enabledTools === void 0 ? void 0 :
|
|
4281
|
+
let o = e.enabledTools === void 0 ? void 0 : xi(e.enabledTools, `Codex MCP server '${r}' enabled tool`), s = Ci(e.startupTimeoutMs, `Codex MCP server '${r}' startup timeout`), c = Ci(e.toolTimeoutMs, `Codex MCP server '${r}' tool timeout`);
|
|
4259
4282
|
return {
|
|
4260
4283
|
name: r,
|
|
4261
4284
|
transport: i,
|
|
@@ -4267,7 +4290,7 @@ function vi(e) {
|
|
|
4267
4290
|
};
|
|
4268
4291
|
});
|
|
4269
4292
|
}
|
|
4270
|
-
function
|
|
4293
|
+
function bi(e, t) {
|
|
4271
4294
|
if (!e || typeof e != "object" || Array.isArray(e)) throw TypeError(`Codex MCP server '${t}' transport must be an object`);
|
|
4272
4295
|
if (e.type === "http") {
|
|
4273
4296
|
let n = e.url?.trim(), r;
|
|
@@ -4285,7 +4308,7 @@ function yi(e, t) {
|
|
|
4285
4308
|
if (e.type !== "stdio") throw TypeError(`Codex MCP server '${t}' transport type is invalid`);
|
|
4286
4309
|
let n = e.command?.trim();
|
|
4287
4310
|
if (!n) throw TypeError(`Codex MCP server '${t}' command cannot be empty`);
|
|
4288
|
-
let r = e.args === void 0 ? void 0 :
|
|
4311
|
+
let r = e.args === void 0 ? void 0 : xi(e.args, `Codex MCP server '${t}' argument`), i = e.cwd?.trim();
|
|
4289
4312
|
if (i !== void 0 && (!i || !v(i))) throw TypeError(`Codex MCP server '${t}' cwd must be an absolute path`);
|
|
4290
4313
|
let a;
|
|
4291
4314
|
if (e.env !== void 0) {
|
|
@@ -4296,7 +4319,7 @@ function yi(e, t) {
|
|
|
4296
4319
|
a[n] = r;
|
|
4297
4320
|
}
|
|
4298
4321
|
}
|
|
4299
|
-
let o = e.envVars === void 0 ? void 0 :
|
|
4322
|
+
let o = e.envVars === void 0 ? void 0 : Si(e.envVars, t);
|
|
4300
4323
|
return {
|
|
4301
4324
|
type: "stdio",
|
|
4302
4325
|
command: n,
|
|
@@ -4306,7 +4329,7 @@ function yi(e, t) {
|
|
|
4306
4329
|
...o === void 0 ? {} : { envVars: o }
|
|
4307
4330
|
};
|
|
4308
4331
|
}
|
|
4309
|
-
function
|
|
4332
|
+
function xi(e, t) {
|
|
4310
4333
|
if (!Array.isArray(e)) throw TypeError(`${t}s must be an array`);
|
|
4311
4334
|
let n = e.map((e) => {
|
|
4312
4335
|
if (typeof e != "string" || !e.trim()) throw TypeError(`${t} cannot be empty`);
|
|
@@ -4314,18 +4337,18 @@ function bi(e, t) {
|
|
|
4314
4337
|
});
|
|
4315
4338
|
return [...new Set(n)];
|
|
4316
4339
|
}
|
|
4317
|
-
function
|
|
4318
|
-
let n =
|
|
4340
|
+
function Si(e, t) {
|
|
4341
|
+
let n = xi(e, `Codex MCP server '${t}' environment variable`);
|
|
4319
4342
|
for (let e of n) if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)) throw TypeError(`Codex MCP server '${t}' environment variable '${e}' is invalid`);
|
|
4320
4343
|
return n;
|
|
4321
4344
|
}
|
|
4322
|
-
function
|
|
4345
|
+
function Ci(e, t) {
|
|
4323
4346
|
if (e !== void 0) {
|
|
4324
4347
|
if (!Number.isFinite(e) || e <= 0) throw TypeError(`${t} must be a positive finite number`);
|
|
4325
4348
|
return e;
|
|
4326
4349
|
}
|
|
4327
4350
|
}
|
|
4328
|
-
function
|
|
4351
|
+
function wi(e) {
|
|
4329
4352
|
let t = {};
|
|
4330
4353
|
for (let n of e) {
|
|
4331
4354
|
let e = n.transport.type === "http" ? { url: n.transport.url } : {
|
|
@@ -4339,7 +4362,7 @@ function Ci(e) {
|
|
|
4339
4362
|
}
|
|
4340
4363
|
return t;
|
|
4341
4364
|
}
|
|
4342
|
-
function
|
|
4365
|
+
function Ti(e, t) {
|
|
4343
4366
|
if (t.length !== 0) for (let n of Object.keys(e)) {
|
|
4344
4367
|
if (n === "mcp_servers") throw Error("Raw mcp_servers config cannot be combined with typed Codex MCP servers");
|
|
4345
4368
|
for (let e of t) {
|
|
@@ -4350,13 +4373,13 @@ function wi(e, t) {
|
|
|
4350
4373
|
}
|
|
4351
4374
|
//#endregion
|
|
4352
4375
|
//#region src/node/codex-surface-extensions-controller.ts
|
|
4353
|
-
var
|
|
4376
|
+
var Ei = class {
|
|
4354
4377
|
extensions;
|
|
4355
4378
|
hostOptionsForThread;
|
|
4356
4379
|
dynamicTools = /* @__PURE__ */ new Map();
|
|
4357
4380
|
defaultMcpServers;
|
|
4358
4381
|
constructor(e, t, n) {
|
|
4359
|
-
this.extensions = e, this.hostOptionsForThread = n, this.defaultMcpServers =
|
|
4382
|
+
this.extensions = e, this.hostOptionsForThread = n, this.defaultMcpServers = yi(t);
|
|
4360
4383
|
for (let t of e) for (let e of t.dynamicTools ?? []) {
|
|
4361
4384
|
let t = e.name.trim();
|
|
4362
4385
|
if (!t) throw Error("Dynamic tool names cannot be empty");
|
|
@@ -4380,13 +4403,13 @@ var Ti = class {
|
|
|
4380
4403
|
}));
|
|
4381
4404
|
}
|
|
4382
4405
|
async conversationExtension(e, t = {}, n = this.defaultMcpServers) {
|
|
4383
|
-
let r =
|
|
4406
|
+
let r = wi(n), i = [], a;
|
|
4384
4407
|
for (let t of this.extensions) {
|
|
4385
4408
|
if (!t.configureConversation) continue;
|
|
4386
4409
|
let o = await t.configureConversation(e);
|
|
4387
|
-
o.config && (
|
|
4410
|
+
o.config && (Ti(o.config, n), Object.assign(r, o.config)), o.baseInstructions !== void 0 && (a = o.baseInstructions), o.developerInstructions?.trim() && i.push(o.developerInstructions.trim());
|
|
4388
4411
|
}
|
|
4389
|
-
return t.config && (
|
|
4412
|
+
return t.config && (Ti(t.config, n), Object.assign(r, t.config)), t.baseInstructions !== void 0 && (a = t.baseInstructions), t.developerInstructions?.trim() && i.push(t.developerInstructions.trim()), {
|
|
4390
4413
|
...a === void 0 ? {} : { baseInstructions: a },
|
|
4391
4414
|
...Object.keys(r).length === 0 ? {} : { config: r },
|
|
4392
4415
|
...i.length === 0 ? {} : { developerInstructions: i.join("\n\n") }
|
|
@@ -4445,7 +4468,7 @@ var Ti = class {
|
|
|
4445
4468
|
});
|
|
4446
4469
|
}
|
|
4447
4470
|
}
|
|
4448
|
-
},
|
|
4471
|
+
}, Di = 50, Oi = 25, ki = 25, Ai = class {
|
|
4449
4472
|
client;
|
|
4450
4473
|
conversationLimit;
|
|
4451
4474
|
host;
|
|
@@ -4514,7 +4537,7 @@ var Ti = class {
|
|
|
4514
4537
|
let t = await this.client.request("thread/turns/list", {
|
|
4515
4538
|
threadId: e,
|
|
4516
4539
|
cursor: null,
|
|
4517
|
-
limit:
|
|
4540
|
+
limit: Di,
|
|
4518
4541
|
sortDirection: "desc",
|
|
4519
4542
|
itemsView: "full"
|
|
4520
4543
|
});
|
|
@@ -4562,7 +4585,7 @@ var Ti = class {
|
|
|
4562
4585
|
let i = new Set(this.host.requireRuntime(e).turnIds), a = await this.client.request("thread/turns/list", {
|
|
4563
4586
|
threadId: e,
|
|
4564
4587
|
cursor: t,
|
|
4565
|
-
limit:
|
|
4588
|
+
limit: Oi,
|
|
4566
4589
|
sortDirection: "desc",
|
|
4567
4590
|
itemsView: "full"
|
|
4568
4591
|
}), o = [...a.data].reverse(), s = new Set(o.map((e) => e.id).filter((e) => !i.has(e)));
|
|
@@ -4593,8 +4616,8 @@ var Ti = class {
|
|
|
4593
4616
|
}
|
|
4594
4617
|
async emitHistoryChunks(e, t) {
|
|
4595
4618
|
for (let n = t.length; n > 0;) {
|
|
4596
|
-
let r = Math.max(0, n -
|
|
4597
|
-
this.host.emitHistoryPrepended(e, t.slice(r, n), "lifecycle"), await
|
|
4619
|
+
let r = Math.max(0, n - ki);
|
|
4620
|
+
this.host.emitHistoryPrepended(e, t.slice(r, n), "lifecycle"), await ji(), n = r;
|
|
4598
4621
|
}
|
|
4599
4622
|
}
|
|
4600
4623
|
async refreshCompleteHistory(e) {
|
|
@@ -4657,12 +4680,12 @@ var Ti = class {
|
|
|
4657
4680
|
} : t;
|
|
4658
4681
|
}
|
|
4659
4682
|
};
|
|
4660
|
-
function
|
|
4683
|
+
function ji() {
|
|
4661
4684
|
return new Promise((e) => setTimeout(e, 0));
|
|
4662
4685
|
}
|
|
4663
4686
|
//#endregion
|
|
4664
4687
|
//#region src/node/codex-surface-conversation-settings-controller.ts
|
|
4665
|
-
var
|
|
4688
|
+
var Mi = class {
|
|
4666
4689
|
client;
|
|
4667
4690
|
defaults;
|
|
4668
4691
|
host;
|
|
@@ -4735,7 +4758,7 @@ var ji = class {
|
|
|
4735
4758
|
...n === void 0 ? {} : { tokenBudget: n }
|
|
4736
4759
|
});
|
|
4737
4760
|
if (a.goal.threadId !== e) throw Error(`Codex thread/goal/set returned a goal for '${a.goal.threadId}' instead of '${e}'`);
|
|
4738
|
-
let o = !
|
|
4761
|
+
let o = !Kr(r.goal, a.goal);
|
|
4739
4762
|
this.host.patchRuntime(e, { goal: { ...a.goal } }), o && this.host.emitEvent("action", {
|
|
4740
4763
|
type: "conversation.goalChanged",
|
|
4741
4764
|
conversationId: e,
|
|
@@ -4757,7 +4780,7 @@ var ji = class {
|
|
|
4757
4780
|
payload: { goal: null }
|
|
4758
4781
|
});
|
|
4759
4782
|
}
|
|
4760
|
-
},
|
|
4783
|
+
}, Ni = "Review the current code changes (staged, unstaged, and untracked files) and provide prioritized findings.", Pi = class {
|
|
4761
4784
|
client;
|
|
4762
4785
|
host;
|
|
4763
4786
|
constructor(e, t) {
|
|
@@ -4798,13 +4821,13 @@ var ji = class {
|
|
|
4798
4821
|
...e,
|
|
4799
4822
|
parts: r.type === "uncommittedChanges" ? e.parts.map((e) => e.type === "text" && e.text === "current changes" ? {
|
|
4800
4823
|
...e,
|
|
4801
|
-
text:
|
|
4824
|
+
text: Ni
|
|
4802
4825
|
} : e) : e.parts,
|
|
4803
4826
|
metadata: {
|
|
4804
4827
|
...e.metadata,
|
|
4805
4828
|
reviewPrompt: !0
|
|
4806
4829
|
}
|
|
4807
|
-
} : e), s =
|
|
4830
|
+
} : e), s = Fi(n.messages, i.turn.id, o);
|
|
4808
4831
|
this.host.patchRuntime(e, {
|
|
4809
4832
|
busy: n.activeTurnId !== null,
|
|
4810
4833
|
turnStartPending: !1,
|
|
@@ -4933,7 +4956,7 @@ var ji = class {
|
|
|
4933
4956
|
return e;
|
|
4934
4957
|
}
|
|
4935
4958
|
};
|
|
4936
|
-
function
|
|
4959
|
+
function Fi(e, t, n) {
|
|
4937
4960
|
let r = e.findIndex((e) => e.turnId === t);
|
|
4938
4961
|
return r < 0 ? [...e, ...n] : [
|
|
4939
4962
|
...e.slice(0, r),
|
|
@@ -4943,7 +4966,7 @@ function Pi(e, t, n) {
|
|
|
4943
4966
|
}
|
|
4944
4967
|
//#endregion
|
|
4945
4968
|
//#region src/node/codex-surface-messages-controller.ts
|
|
4946
|
-
var
|
|
4969
|
+
var Ii = class {
|
|
4947
4970
|
client;
|
|
4948
4971
|
host;
|
|
4949
4972
|
constructor(e, t) {
|
|
@@ -5050,13 +5073,13 @@ var Fi = class {
|
|
|
5050
5073
|
let i = this.host.requireRuntime(e), a = Ut(this.host.snapshotForRuntime(i), n), o = r?.trim() || t, s = it(nt(t, i.skills), rt(a.skills ?? [], i.skills)), c = Wt(a.attachments ?? []);
|
|
5051
5074
|
if (i.busy) {
|
|
5052
5075
|
this.host.patchRuntime(e, { queuedPrompts: [...i.queuedPrompts, {
|
|
5053
|
-
id:
|
|
5076
|
+
id: Jr(),
|
|
5054
5077
|
text: o,
|
|
5055
5078
|
...Object.keys(a).length > 0 ? { options: a } : {}
|
|
5056
5079
|
}] }), this.emitQueuedPrompts(e);
|
|
5057
5080
|
return;
|
|
5058
5081
|
}
|
|
5059
|
-
let l =
|
|
5082
|
+
let l = qr(), u = {
|
|
5060
5083
|
id: l,
|
|
5061
5084
|
role: "user",
|
|
5062
5085
|
status: "complete",
|
|
@@ -5143,7 +5166,7 @@ var Fi = class {
|
|
|
5143
5166
|
let i = await this.host.ensureThreadReady(e), a = t.trim(), o = r?.trim() || a;
|
|
5144
5167
|
if (!a) throw Error("Cannot steer with an empty message");
|
|
5145
5168
|
if (!i.activeTurnId) throw Error("There is no active turn to steer");
|
|
5146
|
-
let s = Wt(n.attachments ?? []), c =
|
|
5169
|
+
let s = Wt(n.attachments ?? []), c = qr(), l = {
|
|
5147
5170
|
id: c,
|
|
5148
5171
|
kind: "steer",
|
|
5149
5172
|
role: "user",
|
|
@@ -5275,7 +5298,7 @@ var Fi = class {
|
|
|
5275
5298
|
if (!e) throw Error("There is no active conversation");
|
|
5276
5299
|
return e;
|
|
5277
5300
|
}
|
|
5278
|
-
},
|
|
5301
|
+
}, Li = 5, Ri = class {
|
|
5279
5302
|
client;
|
|
5280
5303
|
options;
|
|
5281
5304
|
catalog;
|
|
@@ -5315,7 +5338,7 @@ var Fi = class {
|
|
|
5315
5338
|
...a ? { approvalPreset: a } : {}
|
|
5316
5339
|
}, r.approvalPresets), s = k(i.models, i.selectedModelId), c = e.model ? At(i.models, e.model) : s, l = c?.model, u = e.reasoningEffort ?? (c?.id === s?.id ? i.selectedReasoningEffort : c ? A(c) : null) ?? void 0, d = e.serviceTier === void 0 ? c?.id === s?.id ? i.selectedServiceTier ?? null : c?.defaultServiceTier ?? null : e.serviceTier;
|
|
5317
5340
|
jt(c, u), j(c, d);
|
|
5318
|
-
let f = t.mcpServers === void 0 ? this.extensions.defaultMcpServers :
|
|
5341
|
+
let f = t.mcpServers === void 0 ? this.extensions.defaultMcpServers : yi(t.mcpServers), p = await this.extensions.conversationExtension({
|
|
5319
5342
|
operation: "start",
|
|
5320
5343
|
conversationId: null,
|
|
5321
5344
|
cwd: n,
|
|
@@ -5430,7 +5453,7 @@ var Fi = class {
|
|
|
5430
5453
|
...n
|
|
5431
5454
|
}, a = {
|
|
5432
5455
|
...i,
|
|
5433
|
-
mcpServers: i.mcpServers === void 0 ? this.extensions.defaultMcpServers :
|
|
5456
|
+
mcpServers: i.mcpServers === void 0 ? this.extensions.defaultMcpServers : yi(i.mcpServers)
|
|
5434
5457
|
};
|
|
5435
5458
|
this.hostOptionsByThread.set(e, a);
|
|
5436
5459
|
let o = await this.extensions.conversationExtension({
|
|
@@ -5448,7 +5471,7 @@ var Fi = class {
|
|
|
5448
5471
|
threadId: e,
|
|
5449
5472
|
excludeTurns: !0,
|
|
5450
5473
|
initialTurnsPage: {
|
|
5451
|
-
limit:
|
|
5474
|
+
limit: Li,
|
|
5452
5475
|
sortDirection: "desc",
|
|
5453
5476
|
itemsView: "full"
|
|
5454
5477
|
},
|
|
@@ -5461,7 +5484,7 @@ var Fi = class {
|
|
|
5461
5484
|
let i = t.initialTurnsPage ?? await this.client.request("thread/turns/list", {
|
|
5462
5485
|
threadId: t.thread.id,
|
|
5463
5486
|
cursor: null,
|
|
5464
|
-
limit:
|
|
5487
|
+
limit: Li,
|
|
5465
5488
|
sortDirection: "desc",
|
|
5466
5489
|
itemsView: "full"
|
|
5467
5490
|
}), d = [...i.data].reverse(), f = t.cwd ?? t.thread.cwd ?? a.cwd, p = await this.catalog.loadConversationCatalogs(f), m = s.turns.filter((e) => c.get(e.id) !== e), h = s.threadStatus !== u && s.threadStatus ? s.threadStatus : F(t.thread.status), g = d.map((e) => h.type === "idle" && e.status === "inProgress" ? {
|
|
@@ -5521,7 +5544,7 @@ var Fi = class {
|
|
|
5521
5544
|
threadStatus: structuredClone(t.threadStatus)
|
|
5522
5545
|
};
|
|
5523
5546
|
}
|
|
5524
|
-
},
|
|
5547
|
+
}, zi = class {
|
|
5525
5548
|
authentication;
|
|
5526
5549
|
approvals;
|
|
5527
5550
|
catalog;
|
|
@@ -5603,7 +5626,7 @@ var Fi = class {
|
|
|
5603
5626
|
return;
|
|
5604
5627
|
}
|
|
5605
5628
|
case "thread/goal/updated":
|
|
5606
|
-
if (
|
|
5629
|
+
if (Kr(this.host.requireRuntime(e.params.threadId).goal, e.params.goal)) return;
|
|
5607
5630
|
this.host.patchRuntime(e.params.threadId, { goal: { ...e.params.goal } }), this.host.emitEvent("notification", {
|
|
5608
5631
|
type: "conversation.goalChanged",
|
|
5609
5632
|
conversationId: e.params.threadId,
|
|
@@ -5746,7 +5769,7 @@ var Fi = class {
|
|
|
5746
5769
|
durationMs: null
|
|
5747
5770
|
},
|
|
5748
5771
|
status: e.params.willRetry ? "inProgress" : "failed",
|
|
5749
|
-
error:
|
|
5772
|
+
error: Gr(e.params.error),
|
|
5750
5773
|
willRetry: e.params.willRetry
|
|
5751
5774
|
}),
|
|
5752
5775
|
...n ? {
|
|
@@ -5758,7 +5781,7 @@ var Fi = class {
|
|
|
5758
5781
|
conversationId: e.params.threadId,
|
|
5759
5782
|
turnId: e.params.turnId,
|
|
5760
5783
|
payload: {
|
|
5761
|
-
error:
|
|
5784
|
+
error: Gr(e.params.error),
|
|
5762
5785
|
willRetry: e.params.willRetry
|
|
5763
5786
|
}
|
|
5764
5787
|
}), this.host.emitConversationActivity(e.params.threadId, "notification");
|
|
@@ -5904,7 +5927,7 @@ var Fi = class {
|
|
|
5904
5927
|
default: return this.host.unknownNotification(e);
|
|
5905
5928
|
}
|
|
5906
5929
|
}
|
|
5907
|
-
},
|
|
5930
|
+
}, Bi = class {
|
|
5908
5931
|
approvals;
|
|
5909
5932
|
clientRequests;
|
|
5910
5933
|
host;
|
|
@@ -5965,7 +5988,7 @@ var Fi = class {
|
|
|
5965
5988
|
conversationId: e,
|
|
5966
5989
|
payload: {
|
|
5967
5990
|
historyLoading: n.historyLoading,
|
|
5968
|
-
historyState:
|
|
5991
|
+
historyState: Ui(n),
|
|
5969
5992
|
error: n.error
|
|
5970
5993
|
}
|
|
5971
5994
|
});
|
|
@@ -6059,7 +6082,7 @@ var Fi = class {
|
|
|
6059
6082
|
reason: t,
|
|
6060
6083
|
messages: structuredClone(r.messages),
|
|
6061
6084
|
threadStatus: structuredClone(r.threadStatus),
|
|
6062
|
-
state:
|
|
6085
|
+
state: Vi(r)
|
|
6063
6086
|
}
|
|
6064
6087
|
});
|
|
6065
6088
|
}
|
|
@@ -6071,7 +6094,7 @@ var Fi = class {
|
|
|
6071
6094
|
conversationId: e,
|
|
6072
6095
|
payload: {
|
|
6073
6096
|
messages: structuredClone(t.map((e) => r.get(e.id) ?? e)),
|
|
6074
|
-
state:
|
|
6097
|
+
state: Hi(this.require(e))
|
|
6075
6098
|
}
|
|
6076
6099
|
});
|
|
6077
6100
|
}
|
|
@@ -6113,7 +6136,7 @@ var Fi = class {
|
|
|
6113
6136
|
i && this.emitSummaryUpserted(i, "updated", n);
|
|
6114
6137
|
}
|
|
6115
6138
|
};
|
|
6116
|
-
function
|
|
6139
|
+
function Vi(e) {
|
|
6117
6140
|
return structuredClone({
|
|
6118
6141
|
activeTurnId: e.activeTurnId,
|
|
6119
6142
|
answeredClientRequestIds: e.answeredClientRequestIds,
|
|
@@ -6122,21 +6145,21 @@ function Bi(e) {
|
|
|
6122
6145
|
error: e.error,
|
|
6123
6146
|
executionPlan: e.executionPlan,
|
|
6124
6147
|
historyLoading: e.historyLoading,
|
|
6125
|
-
historyState:
|
|
6148
|
+
historyState: Ui(e),
|
|
6126
6149
|
turnGitDiff: e.turnGitDiff,
|
|
6127
6150
|
turnIds: e.turnIds,
|
|
6128
6151
|
turns: e.turns
|
|
6129
6152
|
});
|
|
6130
6153
|
}
|
|
6131
|
-
function
|
|
6154
|
+
function Hi(e) {
|
|
6132
6155
|
return structuredClone({
|
|
6133
6156
|
historyLoading: e.historyLoading,
|
|
6134
|
-
historyState:
|
|
6157
|
+
historyState: Ui(e),
|
|
6135
6158
|
turnIds: e.turnIds,
|
|
6136
6159
|
turns: e.turns
|
|
6137
6160
|
});
|
|
6138
6161
|
}
|
|
6139
|
-
function
|
|
6162
|
+
function Ui(e) {
|
|
6140
6163
|
return {
|
|
6141
6164
|
loadingStrategy: e.loadingStrategy,
|
|
6142
6165
|
hasOlder: e.historyHasOlder,
|
|
@@ -6146,7 +6169,7 @@ function Hi(e) {
|
|
|
6146
6169
|
}
|
|
6147
6170
|
//#endregion
|
|
6148
6171
|
//#region src/node/codex-surface-connection-controller.ts
|
|
6149
|
-
var
|
|
6172
|
+
var Wi = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_request_user_input"]), Gi = class {
|
|
6150
6173
|
client;
|
|
6151
6174
|
options;
|
|
6152
6175
|
authentication;
|
|
@@ -6209,7 +6232,7 @@ var Ui = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6209
6232
|
limit: 100,
|
|
6210
6233
|
threadId: null
|
|
6211
6234
|
});
|
|
6212
|
-
for (let e of n.data)
|
|
6235
|
+
for (let e of n.data) Wi.has(e.name) && !e.enabled && (t[e.name] = !0);
|
|
6213
6236
|
e = n.nextCursor;
|
|
6214
6237
|
} while (e);
|
|
6215
6238
|
Object.keys(t).length > 0 && await this.client.request("experimentalFeature/enablement/set", { enablement: t });
|
|
@@ -6343,7 +6366,7 @@ var Ui = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6343
6366
|
error: null
|
|
6344
6367
|
});
|
|
6345
6368
|
}
|
|
6346
|
-
},
|
|
6369
|
+
}, Ki = 5, qi = class {
|
|
6347
6370
|
client;
|
|
6348
6371
|
loadingStrategy;
|
|
6349
6372
|
catalog;
|
|
@@ -6357,7 +6380,7 @@ var Ui = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6357
6380
|
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");
|
|
6358
6381
|
let a = t.cwd ?? i.cwd ?? n.cwd, o = await this.catalog.loadConversationCatalogs(a ?? void 0), s = this.host.getState(), c = t.model ? At(s.models, t.model) : k(s.models, i.selectedModelId);
|
|
6359
6382
|
jt(c, t.reasoningEffort), j(c, t.serviceTier);
|
|
6360
|
-
let l = n.mcpServers === void 0 ? this.extensions.defaultMcpServers :
|
|
6383
|
+
let l = n.mcpServers === void 0 ? this.extensions.defaultMcpServers : yi(n.mcpServers), u = await this.extensions.conversationExtension({
|
|
6361
6384
|
operation: "start",
|
|
6362
6385
|
conversationId: null,
|
|
6363
6386
|
cwd: a ?? void 0,
|
|
@@ -6375,7 +6398,7 @@ var Ui = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6375
6398
|
...u.baseInstructions === void 0 ? {} : { baseInstructions: u.baseInstructions },
|
|
6376
6399
|
...u.developerInstructions === void 0 ? {} : { developerInstructions: u.developerInstructions },
|
|
6377
6400
|
...u.config === void 0 ? {} : { config: u.config },
|
|
6378
|
-
...
|
|
6401
|
+
...Ji(t, o.approvalPresets)
|
|
6379
6402
|
});
|
|
6380
6403
|
if (!d.thread.id || d.thread.id === e) throw Error(`Codex thread/fork returned an invalid new thread id '${d.thread.id}'`);
|
|
6381
6404
|
t.reasoningEffort && await this.client.request("thread/settings/update", {
|
|
@@ -6386,7 +6409,7 @@ var Ui = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6386
6409
|
let [f, p] = await Promise.all([this.client.request("thread/turns/list", {
|
|
6387
6410
|
threadId: d.thread.id,
|
|
6388
6411
|
cursor: null,
|
|
6389
|
-
limit:
|
|
6412
|
+
limit: Ki,
|
|
6390
6413
|
sortDirection: "desc",
|
|
6391
6414
|
itemsView: "full"
|
|
6392
6415
|
}), this.client.request("thread/goal/get", { threadId: d.thread.id }).then((e) => e.goal).catch(() => null)]), m = [...f.data].reverse(), h = Jn(m), g = fr({
|
|
@@ -6428,7 +6451,7 @@ var Ui = /* @__PURE__ */ new Set(["compaction_image_budget", "default_mode_reque
|
|
|
6428
6451
|
return this.fork(e, n, r, { lastTurnId: t });
|
|
6429
6452
|
}
|
|
6430
6453
|
};
|
|
6431
|
-
function
|
|
6454
|
+
function Ji(e, t) {
|
|
6432
6455
|
if (e.approvalPreset) {
|
|
6433
6456
|
if (!t.includes(e.approvalPreset)) throw Error(`Approval preset '${e.approvalPreset}' is not available`);
|
|
6434
6457
|
return Pt(e.approvalPreset);
|
|
@@ -6440,27 +6463,27 @@ function qi(e, t) {
|
|
|
6440
6463
|
}
|
|
6441
6464
|
//#endregion
|
|
6442
6465
|
//#region src/node/codex-markdown-images.ts
|
|
6443
|
-
var
|
|
6466
|
+
var Yi = /(?<!\[)!\[([^\]]*)\]\(([^)\s]+)(?:\s+["']([^"']*)["'])?\)/g, Xi = /* @__PURE__ */ new Set([
|
|
6444
6467
|
".avif",
|
|
6445
6468
|
".gif",
|
|
6446
6469
|
".jpeg",
|
|
6447
6470
|
".jpg",
|
|
6448
6471
|
".png",
|
|
6449
6472
|
".webp"
|
|
6450
|
-
]),
|
|
6473
|
+
]), Zi = class {
|
|
6451
6474
|
client;
|
|
6452
6475
|
constructor(e) {
|
|
6453
6476
|
this.client = e;
|
|
6454
6477
|
}
|
|
6455
6478
|
async hydrate(e, t) {
|
|
6456
|
-
let n =
|
|
6457
|
-
return
|
|
6479
|
+
let n = ea(e);
|
|
6480
|
+
return $i(e, (await Promise.all(Array.from(e.matchAll(Yi), async (e) => {
|
|
6458
6481
|
let r = e.index ?? 0;
|
|
6459
|
-
if (
|
|
6460
|
-
let i = e[2], a =
|
|
6482
|
+
if (ta(r, n)) return null;
|
|
6483
|
+
let i = e[2], a = Qi(i, t);
|
|
6461
6484
|
if (!a) return null;
|
|
6462
6485
|
try {
|
|
6463
|
-
let t =
|
|
6486
|
+
let t = Dr((await this.client.request("fs/readFile", { path: a })).dataBase64);
|
|
6464
6487
|
if (!t) return null;
|
|
6465
6488
|
let n = e[0].indexOf("](") + 2;
|
|
6466
6489
|
return {
|
|
@@ -6474,7 +6497,7 @@ var Ji = /(?<!\[)!\[([^\]]*)\]\(([^)\s]+)(?:\s+["']([^"']*)["'])?\)/g, Yi = /* @
|
|
|
6474
6497
|
}))).filter((e) => e !== null));
|
|
6475
6498
|
}
|
|
6476
6499
|
};
|
|
6477
|
-
function
|
|
6500
|
+
function Qi(e, t) {
|
|
6478
6501
|
let n = e.trim();
|
|
6479
6502
|
if (!n || /[\u0000-\u001f\u007f]/.test(n)) return null;
|
|
6480
6503
|
let r;
|
|
@@ -6489,18 +6512,18 @@ function Zi(e, t) {
|
|
|
6489
6512
|
} catch {
|
|
6490
6513
|
return null;
|
|
6491
6514
|
}
|
|
6492
|
-
if (!
|
|
6515
|
+
if (!Xi.has(_(r).toLowerCase())) return null;
|
|
6493
6516
|
if (v(r)) return r;
|
|
6494
6517
|
if (!t || !v(t)) return null;
|
|
6495
6518
|
let i = x(t, r), a = b(t, i);
|
|
6496
6519
|
return a === ".." || a.startsWith(`..${S}`) || v(a) ? null : i;
|
|
6497
6520
|
}
|
|
6498
|
-
function
|
|
6521
|
+
function $i(e, t) {
|
|
6499
6522
|
let n = e;
|
|
6500
6523
|
for (let e of t.sort((e, t) => t.start - e.start)) n = `${n.slice(0, e.start)}${e.value}${n.slice(e.end)}`;
|
|
6501
6524
|
return n;
|
|
6502
6525
|
}
|
|
6503
|
-
function
|
|
6526
|
+
function ea(e) {
|
|
6504
6527
|
let t = [], n = /(^|\n)(```|~~~)/g, r;
|
|
6505
6528
|
for (; (r = n.exec(e)) !== null;) {
|
|
6506
6529
|
let i = r[2], a = r[1], o = r.index + a.length, s = RegExp(`(^|\\n)${i}`, "g");
|
|
@@ -6521,15 +6544,15 @@ function $i(e) {
|
|
|
6521
6544
|
}
|
|
6522
6545
|
return t;
|
|
6523
6546
|
}
|
|
6524
|
-
function
|
|
6547
|
+
function ta(e, t) {
|
|
6525
6548
|
return t.some((t) => e >= t.start && e <= t.end);
|
|
6526
6549
|
}
|
|
6527
|
-
var
|
|
6528
|
-
async function
|
|
6550
|
+
var na = /<context>[\s\S]*?<\/context>\s*/g, ra = /<in-app-browser-context(?:\s[^>]*)?>[\s\S]*?<\/in-app-browser-context>\s*/g, ia = /^[ \t]*## My request for Codex:[ \t]*$/m;
|
|
6551
|
+
async function aa(e, t) {
|
|
6529
6552
|
let n = D(t);
|
|
6530
6553
|
return {
|
|
6531
6554
|
conversationId: n,
|
|
6532
|
-
prompts:
|
|
6555
|
+
prompts: oa((await e.request("thread/turns/list", {
|
|
6533
6556
|
threadId: n,
|
|
6534
6557
|
cursor: null,
|
|
6535
6558
|
limit: 100,
|
|
@@ -6538,20 +6561,20 @@ async function ia(e, t) {
|
|
|
6538
6561
|
})).data)
|
|
6539
6562
|
};
|
|
6540
6563
|
}
|
|
6541
|
-
function
|
|
6564
|
+
function oa(e) {
|
|
6542
6565
|
return [...e].reverse().flatMap((e) => e.items.flatMap((e) => {
|
|
6543
6566
|
if (e.type !== "userMessage") return [];
|
|
6544
|
-
let t =
|
|
6567
|
+
let t = sa(e.content.flatMap((e) => e.type === "text" ? [e.text] : []).join(""));
|
|
6545
6568
|
return t && t !== "(no user instructions)" ? [t] : [];
|
|
6546
6569
|
}));
|
|
6547
6570
|
}
|
|
6548
|
-
function
|
|
6549
|
-
let t = e.replace(
|
|
6550
|
-
return (n === t ? n : n.replace(
|
|
6571
|
+
function sa(e) {
|
|
6572
|
+
let t = e.replace(na, ""), n = t.replace(ra, "");
|
|
6573
|
+
return (n === t ? n : n.replace(ia, "")).trim();
|
|
6551
6574
|
}
|
|
6552
6575
|
//#endregion
|
|
6553
6576
|
//#region src/node/codex-surface-text-generation-controller.ts
|
|
6554
|
-
var
|
|
6577
|
+
var ca = 12e4, la = class {
|
|
6555
6578
|
client;
|
|
6556
6579
|
defaultCwd;
|
|
6557
6580
|
host;
|
|
@@ -6562,7 +6585,7 @@ var sa = 12e4, ca = class {
|
|
|
6562
6585
|
}
|
|
6563
6586
|
handleNotification(e) {
|
|
6564
6587
|
e.method === "thread/started" && e.params.thread.ephemeral && this.hiddenThreadIds.add(e.params.thread.id);
|
|
6565
|
-
let t =
|
|
6588
|
+
let t = pa(e);
|
|
6566
6589
|
if (!t || !this.hiddenThreadIds.has(t)) return !1;
|
|
6567
6590
|
let n = this.pendingByThread.get(t);
|
|
6568
6591
|
return n && this.consumeNotification(n, e), (e.method === "thread/closed" || e.method === "thread/deleted") && this.hiddenThreadIds.delete(t), !0;
|
|
@@ -6570,7 +6593,7 @@ var sa = 12e4, ca = class {
|
|
|
6570
6593
|
async generate(e, t = {}) {
|
|
6571
6594
|
let n = e.trim();
|
|
6572
6595
|
if (!n) throw Error("Generation prompt cannot be empty");
|
|
6573
|
-
if (t.signal?.aborted) throw
|
|
6596
|
+
if (t.signal?.aborted) throw ma();
|
|
6574
6597
|
await this.host.ensureConnected();
|
|
6575
6598
|
let r = this.host.getSnapshot(), i = k(r.models, r.selectedModelId), a = t.model ? At(r.models, t.model) : i, o = a?.model, s = t.reasoningEffort ?? (a?.id === i?.id ? r.selectedReasoningEffort : a ? A(a) : null) ?? void 0, c = t.serviceTier === void 0 ? a?.id === i?.id ? r.selectedServiceTier : a?.defaultServiceTier ?? null : t.serviceTier;
|
|
6576
6599
|
jt(a, s), j(a, c);
|
|
@@ -6589,15 +6612,15 @@ var sa = 12e4, ca = class {
|
|
|
6589
6612
|
serviceName: "codex_app_sdk",
|
|
6590
6613
|
threadSource: "sdk_ephemeral_generation"
|
|
6591
6614
|
}), u = l.thread.id;
|
|
6592
|
-
if (!l.thread.ephemeral) throw await
|
|
6593
|
-
if (this.hiddenThreadIds.add(u), t.signal?.aborted) throw await
|
|
6594
|
-
let d =
|
|
6615
|
+
if (!l.thread.ephemeral) throw await ua(() => this.client.request("thread/delete", { threadId: u })), Error("Codex app-server did not create an ephemeral generation thread");
|
|
6616
|
+
if (this.hiddenThreadIds.add(u), t.signal?.aborted) throw await ua(() => this.client.request("thread/unsubscribe", { threadId: u })), this.hiddenThreadIds.delete(u), ma();
|
|
6617
|
+
let d = da();
|
|
6595
6618
|
this.pendingByThread.set(u, d);
|
|
6596
|
-
let f = null, p = !1, m = () => d.reject(
|
|
6619
|
+
let f = null, p = !1, m = () => d.reject(ma());
|
|
6597
6620
|
t.signal?.addEventListener("abort", m);
|
|
6598
6621
|
let h = setTimeout(() => {
|
|
6599
6622
|
d.reject(/* @__PURE__ */ Error("Codex ephemeral generation timed out"));
|
|
6600
|
-
}, t.timeoutMs ??
|
|
6623
|
+
}, t.timeoutMs ?? ca);
|
|
6601
6624
|
try {
|
|
6602
6625
|
let e = await this.client.request("turn/start", {
|
|
6603
6626
|
threadId: u,
|
|
@@ -6613,18 +6636,18 @@ var sa = 12e4, ca = class {
|
|
|
6613
6636
|
serviceTier: c,
|
|
6614
6637
|
...t.outputSchema === void 0 ? {} : { outputSchema: t.outputSchema }
|
|
6615
6638
|
});
|
|
6616
|
-
f = e.turn.id, d.turnId = f,
|
|
6639
|
+
f = e.turn.id, d.turnId = f, fa(d, e.turn);
|
|
6617
6640
|
let r = await d.promise;
|
|
6618
6641
|
return p = !0, r;
|
|
6619
6642
|
} finally {
|
|
6620
6643
|
if (clearTimeout(h), t.signal?.removeEventListener("abort", m), this.pendingByThread.delete(u), !p && f) {
|
|
6621
6644
|
let e = f;
|
|
6622
|
-
await
|
|
6645
|
+
await ua(() => this.client.request("turn/interrupt", {
|
|
6623
6646
|
threadId: u,
|
|
6624
6647
|
turnId: e
|
|
6625
6648
|
}));
|
|
6626
6649
|
}
|
|
6627
|
-
await
|
|
6650
|
+
await ua(() => this.client.request("thread/unsubscribe", { threadId: u })), this.hiddenThreadIds.delete(u);
|
|
6628
6651
|
}
|
|
6629
6652
|
}
|
|
6630
6653
|
close(e = /* @__PURE__ */ Error("Codex surface closed")) {
|
|
@@ -6647,16 +6670,16 @@ var sa = 12e4, ca = class {
|
|
|
6647
6670
|
}
|
|
6648
6671
|
if (t.method === "turn/completed") {
|
|
6649
6672
|
if (e.turnId && t.params.turn.id !== e.turnId) return;
|
|
6650
|
-
|
|
6673
|
+
fa(e, t.params.turn);
|
|
6651
6674
|
}
|
|
6652
6675
|
}
|
|
6653
6676
|
};
|
|
6654
|
-
async function
|
|
6677
|
+
async function ua(e) {
|
|
6655
6678
|
try {
|
|
6656
6679
|
await e();
|
|
6657
6680
|
} catch {}
|
|
6658
6681
|
}
|
|
6659
|
-
function
|
|
6682
|
+
function da() {
|
|
6660
6683
|
let e, t, n = {
|
|
6661
6684
|
promise: new Promise((n, r) => {
|
|
6662
6685
|
e = n, t = r;
|
|
@@ -6672,7 +6695,7 @@ function ua() {
|
|
|
6672
6695
|
};
|
|
6673
6696
|
return n.promise.catch(() => void 0), n;
|
|
6674
6697
|
}
|
|
6675
|
-
function
|
|
6698
|
+
function fa(e, t) {
|
|
6676
6699
|
for (let n of t.items) {
|
|
6677
6700
|
if (n.type !== "agentMessage") continue;
|
|
6678
6701
|
let t = n.text.trim();
|
|
@@ -6694,17 +6717,17 @@ function da(e, t) {
|
|
|
6694
6717
|
}
|
|
6695
6718
|
e.resolve({ text: n });
|
|
6696
6719
|
}
|
|
6697
|
-
function
|
|
6720
|
+
function pa(e) {
|
|
6698
6721
|
if (e.method === "thread/started") return e.params.thread.id;
|
|
6699
6722
|
let t = e.params;
|
|
6700
6723
|
return typeof t.threadId == "string" ? t.threadId : null;
|
|
6701
6724
|
}
|
|
6702
|
-
function
|
|
6725
|
+
function ma() {
|
|
6703
6726
|
return /* @__PURE__ */ Error("Codex ephemeral generation was aborted");
|
|
6704
6727
|
}
|
|
6705
6728
|
//#endregion
|
|
6706
6729
|
//#region src/node/codex-surface-usage-controller.ts
|
|
6707
|
-
var
|
|
6730
|
+
var ha = class {
|
|
6708
6731
|
threads = /* @__PURE__ */ new Map();
|
|
6709
6732
|
clear() {
|
|
6710
6733
|
this.threads.clear();
|
|
@@ -6736,15 +6759,15 @@ var ma = class {
|
|
|
6736
6759
|
let e = r.executions.get(r.activeTurnId);
|
|
6737
6760
|
e && (e.baseline = null), i && (i.baseline = null);
|
|
6738
6761
|
}
|
|
6739
|
-
i && (!
|
|
6740
|
-
let s = i?.baseline ?
|
|
6762
|
+
i && (!_a(a.total) || i.latest && !va(i.latest.total, a.total)) && (i.baseline = null);
|
|
6763
|
+
let s = i?.baseline ? ya(i.baseline, a.total) : null;
|
|
6741
6764
|
i && s === null && (i.baseline = null);
|
|
6742
6765
|
let c = {
|
|
6743
6766
|
...a,
|
|
6744
6767
|
execution: s,
|
|
6745
6768
|
observedStart: !!i
|
|
6746
6769
|
};
|
|
6747
|
-
return i && (i.latest = structuredClone(c)), r.total = !o &&
|
|
6770
|
+
return i && (i.latest = structuredClone(c)), r.total = !o && _a(a.total) ? structuredClone(a.total) : null, r.lastUsageTurnId = t.turnId, {
|
|
6748
6771
|
...t,
|
|
6749
6772
|
payload: { usage: c }
|
|
6750
6773
|
};
|
|
@@ -6758,21 +6781,21 @@ var ma = class {
|
|
|
6758
6781
|
executions: /* @__PURE__ */ new Map()
|
|
6759
6782
|
}, this.threads.set(e, t)), t;
|
|
6760
6783
|
}
|
|
6761
|
-
},
|
|
6784
|
+
}, ga = [
|
|
6762
6785
|
"totalTokens",
|
|
6763
6786
|
"inputTokens",
|
|
6764
6787
|
"cachedInputTokens",
|
|
6765
6788
|
"outputTokens",
|
|
6766
6789
|
"reasoningOutputTokens"
|
|
6767
6790
|
];
|
|
6768
|
-
function
|
|
6769
|
-
return
|
|
6770
|
-
}
|
|
6771
|
-
function _a(e, t) {
|
|
6772
|
-
return ha.every((n) => t[n] >= e[n]) && (e.cacheWriteInputTokens === null || t.cacheWriteInputTokens === null || t.cacheWriteInputTokens >= e.cacheWriteInputTokens);
|
|
6791
|
+
function _a(e) {
|
|
6792
|
+
return ga.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;
|
|
6773
6793
|
}
|
|
6774
6794
|
function va(e, t) {
|
|
6775
|
-
|
|
6795
|
+
return ga.every((n) => t[n] >= e[n]) && (e.cacheWriteInputTokens === null || t.cacheWriteInputTokens === null || t.cacheWriteInputTokens >= e.cacheWriteInputTokens);
|
|
6796
|
+
}
|
|
6797
|
+
function ya(e, t) {
|
|
6798
|
+
if (!_a(e) || !_a(t) || !va(e, t)) return null;
|
|
6776
6799
|
let n = {
|
|
6777
6800
|
totalTokens: t.totalTokens - e.totalTokens,
|
|
6778
6801
|
inputTokens: t.inputTokens - e.inputTokens,
|
|
@@ -6781,11 +6804,11 @@ function va(e, t) {
|
|
|
6781
6804
|
outputTokens: t.outputTokens - e.outputTokens,
|
|
6782
6805
|
reasoningOutputTokens: t.reasoningOutputTokens - e.reasoningOutputTokens
|
|
6783
6806
|
};
|
|
6784
|
-
return
|
|
6807
|
+
return _a(n) ? n : null;
|
|
6785
6808
|
}
|
|
6786
6809
|
//#endregion
|
|
6787
6810
|
//#region src/node/codex-surface.ts
|
|
6788
|
-
var
|
|
6811
|
+
var ba = class {
|
|
6789
6812
|
options;
|
|
6790
6813
|
client;
|
|
6791
6814
|
listeners = /* @__PURE__ */ new Set();
|
|
@@ -6816,21 +6839,21 @@ var ya = class {
|
|
|
6816
6839
|
unsubscribeToolInputRequests;
|
|
6817
6840
|
unsubscribeMcpElicitationRequests;
|
|
6818
6841
|
eventSequence = 0;
|
|
6819
|
-
usage = new
|
|
6842
|
+
usage = new ha();
|
|
6820
6843
|
accountGeneration = 0;
|
|
6821
6844
|
pendingMarkdownImageHydrations = /* @__PURE__ */ new Set();
|
|
6822
6845
|
closed = !1;
|
|
6823
6846
|
state = _t(bt());
|
|
6824
6847
|
constructor(e = {}) {
|
|
6825
|
-
this.options = e, this.extensions = new
|
|
6848
|
+
this.options = e, this.extensions = new Ei(e.extensions ?? [], e.mcpServers ?? [], (e) => this.lifecycle.hostOptions(e));
|
|
6826
6849
|
let n = sn(e);
|
|
6827
|
-
this.client = e.client ?? new t(on(n) ? new Ke(n) : new Ve(n), e.onListenerError ? { onListenerError: e.onListenerError } : {}), this.markdownImages = new
|
|
6850
|
+
this.client = e.client ?? new t(on(n) ? new Ke(n) : new Ve(n), e.onListenerError ? { onListenerError: e.onListenerError } : {}), this.markdownImages = new Zi(this.client), this.authentication = new ln(this.client, {
|
|
6828
6851
|
bootstrapSurfaceData: (e) => this.connection.bootstrapSurfaceData(e),
|
|
6829
6852
|
clearAuthenticatedSurfaceData: () => this.connection.clearAuthenticatedSurfaceData(),
|
|
6830
6853
|
getSnapshot: () => this.getSnapshot(),
|
|
6831
6854
|
patchAuthentication: (e, t) => this.connection.patchAuthentication(e, t),
|
|
6832
6855
|
reportError: (e) => this.patch({ error: O(e) })
|
|
6833
|
-
}), this.items = new
|
|
6856
|
+
}), this.items = new Xr({
|
|
6834
6857
|
assistantMessageForTurn: (e, t) => this.assistantMessageForTurn(e, t),
|
|
6835
6858
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
6836
6859
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
@@ -6844,7 +6867,7 @@ var ya = class {
|
|
|
6844
6867
|
sendNextQueuedPrompt: (e) => {
|
|
6845
6868
|
this.messagesController.sendNextQueuedPrompt(e);
|
|
6846
6869
|
}
|
|
6847
|
-
}), this.approvals = new
|
|
6870
|
+
}), this.approvals = new vi(this.client, {
|
|
6848
6871
|
activeConversationId: () => this.state.activeConversationId,
|
|
6849
6872
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6850
6873
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6854,7 +6877,7 @@ var ya = class {
|
|
|
6854
6877
|
patch: (e) => this.patch(e),
|
|
6855
6878
|
patchConversationStatus: (e, t) => this.patchConversationStatus(e, t),
|
|
6856
6879
|
patchRuntime: (e, t) => this.patchRuntime(e, t)
|
|
6857
|
-
}), this.clientRequests = new
|
|
6880
|
+
}), this.clientRequests = new $r({
|
|
6858
6881
|
activeConversationId: () => this.state.activeConversationId,
|
|
6859
6882
|
answerAsyncQuestion: (e, t, n) => this.messagesController.answerAsyncQuestion(e, t, n),
|
|
6860
6883
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6864,13 +6887,13 @@ var ya = class {
|
|
|
6864
6887
|
messageContainingTool: (e, t, n) => this.messageContainingTool(e, t, n),
|
|
6865
6888
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6866
6889
|
requireRuntime: (e) => this.requireRuntime(e)
|
|
6867
|
-
}), this.runtimeState = new
|
|
6890
|
+
}), this.runtimeState = new Bi(this.approvals, this.clientRequests, {
|
|
6868
6891
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
6869
6892
|
getState: () => this.state,
|
|
6870
6893
|
notifyConversationListeners: (e) => this.notifyConversationListeners(e),
|
|
6871
6894
|
patch: (e, t) => this.patch(e, t),
|
|
6872
6895
|
schedulePluginRefresh: () => this.catalog.schedulePluginRefresh()
|
|
6873
|
-
}), this.conversationSettings = new
|
|
6896
|
+
}), this.conversationSettings = new Mi(this.client, {
|
|
6874
6897
|
approvalMode: e.approvalMode,
|
|
6875
6898
|
approvalPreset: e.approvalPreset,
|
|
6876
6899
|
permissionMode: e.permissionMode
|
|
@@ -6888,7 +6911,7 @@ var ya = class {
|
|
|
6888
6911
|
patch: (e) => this.patch(e),
|
|
6889
6912
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6890
6913
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e)
|
|
6891
|
-
}), this.turnActions = new
|
|
6914
|
+
}), this.turnActions = new Pi(this.client, {
|
|
6892
6915
|
createConversation: async () => {
|
|
6893
6916
|
await this.createConversation();
|
|
6894
6917
|
},
|
|
@@ -6905,7 +6928,7 @@ var ya = class {
|
|
|
6905
6928
|
patchConversationTurnCount: (e, t, n) => this.patchConversationTurnCount(e, t, n),
|
|
6906
6929
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6907
6930
|
sendMessageToThread: (e, t, n) => this.messagesController.sendToThread(e, t, n)
|
|
6908
|
-
}), this.messagesController = new
|
|
6931
|
+
}), this.messagesController = new Ii(this.client, {
|
|
6909
6932
|
clearGoalForThread: (e) => this.conversationSettings.clearGoalForThread(e),
|
|
6910
6933
|
compactForThread: (e) => this.turnActions.compactForThread(e),
|
|
6911
6934
|
createConversation: async () => {
|
|
@@ -6928,7 +6951,7 @@ var ya = class {
|
|
|
6928
6951
|
startReviewForThread: (e, t) => this.turnActions.startReviewForThread(e, t),
|
|
6929
6952
|
updateSettings: (e) => this.conversationSettings.update(e),
|
|
6930
6953
|
updateSettingsForThread: (e, t) => this.conversationSettings.updateForThread(e, t)
|
|
6931
|
-
}), this.catalog = new
|
|
6954
|
+
}), this.catalog = new ui(this.client, e.cwd, {
|
|
6932
6955
|
authenticationBlocksBootstrap: () => this.authentication.blocksBootstrap(),
|
|
6933
6956
|
emitConversationSkills: (e, t) => this.emitConversationSkills(e, t),
|
|
6934
6957
|
emitEvent: (e, t) => this.emitEvent(e, t),
|
|
@@ -6939,7 +6962,7 @@ var ya = class {
|
|
|
6939
6962
|
patchRuntime: (e, t) => this.patchRuntime(e, t),
|
|
6940
6963
|
preferredApprovalPreset: () => this.conversationSettings.preferredApprovalPreset(),
|
|
6941
6964
|
runtimes: () => this.runtimeState.values()
|
|
6942
|
-
}), this.conversations = new
|
|
6965
|
+
}), this.conversations = new Ai(this.client, e.conversationLimit, {
|
|
6943
6966
|
emitHistoryPrepended: (e, t, n) => this.emitHistoryPrepended(e, t, n),
|
|
6944
6967
|
emitSummaryUpserted: (e, t, n) => this.emitSummaryUpserted(e, t, n),
|
|
6945
6968
|
ensureConnected: () => this.ensureConnected(),
|
|
@@ -6951,7 +6974,7 @@ var ya = class {
|
|
|
6951
6974
|
requireRuntime: (e) => this.requireRuntime(e),
|
|
6952
6975
|
runtime: (e) => this.runtimeState.get(e),
|
|
6953
6976
|
schedulePluginRefresh: (e) => this.catalog.schedulePluginRefresh(e)
|
|
6954
|
-
}), this.lifecycle = new
|
|
6977
|
+
}), this.lifecycle = new Ri(this.client, e, this.catalog, this.extensions, this.conversationSettings, this.conversations, {
|
|
6955
6978
|
activateRuntime: (e) => this.activateRuntime(e),
|
|
6956
6979
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6957
6980
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -6973,7 +6996,7 @@ var ya = class {
|
|
|
6973
6996
|
runtime: (e) => this.runtimeState.get(e),
|
|
6974
6997
|
runtimeProjection: (e) => this.runtimeProjection(e),
|
|
6975
6998
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e)
|
|
6976
|
-
}), this.forks = new
|
|
6999
|
+
}), this.forks = new qi(this.client, e.loadingStrategy, this.catalog, this.extensions, {
|
|
6977
7000
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
6978
7001
|
emitConversationActivity: (e) => this.emitConversationActivity(e, "action"),
|
|
6979
7002
|
emitConversationPermissions: (e) => this.emitConversationPermissions(e, "action"),
|
|
@@ -6987,7 +7010,7 @@ var ya = class {
|
|
|
6987
7010
|
rememberHostOptions: (e, t) => this.lifecycle.rememberHostOptions(e, t),
|
|
6988
7011
|
requireRuntime: (e) => this.requireRuntime(e),
|
|
6989
7012
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e)
|
|
6990
|
-
}), this.connection = new
|
|
7013
|
+
}), this.connection = new Gi(this.client, e, this.authentication, this.approvals, this.catalog, this.clientRequests, this.conversations, this.items, this.lifecycle, this.runtimeState, {
|
|
6991
7014
|
clearConversationHandles: () => this.conversationHandles.clear(),
|
|
6992
7015
|
clearPendingForThread: (e, t, n) => this.clearPendingForThread(e, t, n),
|
|
6993
7016
|
closed: () => this.closed,
|
|
@@ -6999,7 +7022,7 @@ var ya = class {
|
|
|
6999
7022
|
getSnapshot: () => this.getSnapshot(),
|
|
7000
7023
|
getState: () => this.state,
|
|
7001
7024
|
patch: (e) => this.patch(e)
|
|
7002
|
-
}), this.notifications = new
|
|
7025
|
+
}), this.notifications = new zi(this.authentication, this.approvals, this.catalog, this.clientRequests, this.conversations, this.items, {
|
|
7003
7026
|
clearPendingForThread: (e, t, n) => this.clearPendingForThread(e, t, n),
|
|
7004
7027
|
createRuntime: (e, t) => this.createRuntime(e, t),
|
|
7005
7028
|
emitConversationActivity: (e, t) => this.emitConversationActivity(e, t),
|
|
@@ -7023,7 +7046,7 @@ var ya = class {
|
|
|
7023
7046
|
},
|
|
7024
7047
|
snapshotForRuntime: (e) => this.snapshotForRuntime(e),
|
|
7025
7048
|
unknownNotification: (e) => this.handleUnknownNotification(e)
|
|
7026
|
-
}), this.textGeneration = new
|
|
7049
|
+
}), this.textGeneration = new la(this.client, e.cwd, {
|
|
7027
7050
|
ensureConnected: () => this.ensureConnected(),
|
|
7028
7051
|
getSnapshot: () => this.getSnapshot()
|
|
7029
7052
|
}), this.unsubscribeNotification = this.client.onNotification((e) => {
|
|
@@ -7196,7 +7219,7 @@ var ya = class {
|
|
|
7196
7219
|
return this.lifecycle.readHistory(e);
|
|
7197
7220
|
}
|
|
7198
7221
|
async readConversationPromptHistory(e = this.state.activeConversationId ?? "") {
|
|
7199
|
-
return await this.ensureConnected(),
|
|
7222
|
+
return await this.ensureConnected(), aa(this.client, e);
|
|
7200
7223
|
}
|
|
7201
7224
|
async loadOlderConversationHistory(e = this.state.activeConversationId ?? "") {
|
|
7202
7225
|
return this.conversations.loadOlderHistory(D(e));
|
|
@@ -7584,19 +7607,19 @@ var ya = class {
|
|
|
7584
7607
|
for (let e of this.conversationListeners.keys()) this.notifyConversationListeners(e);
|
|
7585
7608
|
}
|
|
7586
7609
|
};
|
|
7587
|
-
function
|
|
7588
|
-
return new
|
|
7610
|
+
function xa(e = {}) {
|
|
7611
|
+
return new ba(e);
|
|
7589
7612
|
}
|
|
7590
7613
|
//#endregion
|
|
7591
7614
|
//#region src/node/codex-app-backend-cache.ts
|
|
7592
|
-
var
|
|
7615
|
+
var Sa = {
|
|
7593
7616
|
set(e, t) {
|
|
7594
7617
|
return setTimeout(e, t);
|
|
7595
7618
|
},
|
|
7596
7619
|
clear(e) {
|
|
7597
7620
|
clearTimeout(e);
|
|
7598
7621
|
}
|
|
7599
|
-
},
|
|
7622
|
+
}, Ca = class {
|
|
7600
7623
|
options;
|
|
7601
7624
|
records = /* @__PURE__ */ new Map();
|
|
7602
7625
|
now;
|
|
@@ -7609,7 +7632,7 @@ var xa = {
|
|
|
7609
7632
|
constructor(e) {
|
|
7610
7633
|
if (this.options = e, !Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error("Codex backend cache ttlMs must be greater than zero");
|
|
7611
7634
|
if (e.sweepIntervalMs !== void 0 && e.sweepIntervalMs !== null && (!Number.isFinite(e.sweepIntervalMs) || e.sweepIntervalMs <= 0)) throw Error("Codex backend cache sweepIntervalMs must be greater than zero");
|
|
7612
|
-
this.now = e.now ?? Date.now, this.scheduler = e.scheduler ??
|
|
7635
|
+
this.now = e.now ?? Date.now, this.scheduler = e.scheduler ?? Sa, this.sweepIntervalMs = e.sweepIntervalMs ?? null;
|
|
7613
7636
|
}
|
|
7614
7637
|
get size() {
|
|
7615
7638
|
return this.records.size;
|
|
@@ -7707,7 +7730,7 @@ var xa = {
|
|
|
7707
7730
|
assertOpen() {
|
|
7708
7731
|
if (this.closed) throw Error("Codex backend cache is closed");
|
|
7709
7732
|
}
|
|
7710
|
-
},
|
|
7733
|
+
}, wa = class {
|
|
7711
7734
|
surface;
|
|
7712
7735
|
moduleServices = /* @__PURE__ */ new Map();
|
|
7713
7736
|
ttlCaches = /* @__PURE__ */ new Set();
|
|
@@ -7723,7 +7746,7 @@ var xa = {
|
|
|
7723
7746
|
if (n.has(e)) throw Error(`Duplicate Codex backend module '${e}'`);
|
|
7724
7747
|
n.add(e);
|
|
7725
7748
|
}
|
|
7726
|
-
this.surface = e.surface ?? new
|
|
7749
|
+
this.surface = e.surface ?? new ba(e.surfaceOptions);
|
|
7727
7750
|
for (let { id: e, module: n } of t) this.moduleServices.set(e, n.create({
|
|
7728
7751
|
surface: this.surface,
|
|
7729
7752
|
closeBackend: () => this.close(),
|
|
@@ -7737,7 +7760,7 @@ var xa = {
|
|
|
7737
7760
|
}
|
|
7738
7761
|
createTtlCache(e) {
|
|
7739
7762
|
if (this.closePromise) throw Error("Cannot create a cache after the Codex backend is closed");
|
|
7740
|
-
let t = new
|
|
7763
|
+
let t = new Ca(e);
|
|
7741
7764
|
return this.ttlCaches.add(t), t;
|
|
7742
7765
|
}
|
|
7743
7766
|
close() {
|
|
@@ -7747,16 +7770,16 @@ var xa = {
|
|
|
7747
7770
|
await Promise.all([...this.ttlCaches].map((e) => e.close())), await this.surface.close();
|
|
7748
7771
|
}
|
|
7749
7772
|
};
|
|
7750
|
-
function
|
|
7751
|
-
return new
|
|
7773
|
+
function Ta(e = {}) {
|
|
7774
|
+
return new wa(e);
|
|
7752
7775
|
}
|
|
7753
7776
|
//#endregion
|
|
7754
7777
|
//#region src/node/apple-speech-transcription.ts
|
|
7755
|
-
async function
|
|
7778
|
+
async function Ea(e, t = {}, n = {}) {
|
|
7756
7779
|
let r = n.fs ?? l, i = n.spawn ?? o, a = n.tmpdir ?? f.tmpdir, s = await r.mkdtemp(h.join(a(), "codex-app-sdk-apple-stt-")), c = h.join(s, "input.wav"), u = h.join(s, "output.txt");
|
|
7757
7780
|
try {
|
|
7758
|
-
let a = await
|
|
7759
|
-
return await r.writeFile(c, e), await
|
|
7781
|
+
let a = await ja(Da(n.assetsPath), s, r);
|
|
7782
|
+
return await r.writeFile(c, e), await ka(i, a, Oa(c, u, t)), { text: (await r.readFile(u, "utf8")).trim() };
|
|
7760
7783
|
} catch (e) {
|
|
7761
7784
|
return {
|
|
7762
7785
|
text: "",
|
|
@@ -7769,10 +7792,10 @@ async function Ta(e, t = {}, n = {}) {
|
|
|
7769
7792
|
});
|
|
7770
7793
|
}
|
|
7771
7794
|
}
|
|
7772
|
-
function
|
|
7773
|
-
return h.join(e ??
|
|
7795
|
+
function Da(e, t = {}) {
|
|
7796
|
+
return h.join(e ?? Aa(t), "apple-speechanalyzer-cli");
|
|
7774
7797
|
}
|
|
7775
|
-
function
|
|
7798
|
+
function Oa(e, t, n) {
|
|
7776
7799
|
let r = [
|
|
7777
7800
|
"--input-audio-path",
|
|
7778
7801
|
e,
|
|
@@ -7781,7 +7804,7 @@ function Da(e, t, n) {
|
|
|
7781
7804
|
], i = n.locale?.trim();
|
|
7782
7805
|
return i && r.push("--locale", i), n.live && r.push("--live"), r;
|
|
7783
7806
|
}
|
|
7784
|
-
function
|
|
7807
|
+
function ka(e, t, n) {
|
|
7785
7808
|
return new Promise((r, i) => {
|
|
7786
7809
|
let a = e(t, n), o = "";
|
|
7787
7810
|
a.stderr?.on("data", (e) => {
|
|
@@ -7797,7 +7820,7 @@ function Oa(e, t, n) {
|
|
|
7797
7820
|
});
|
|
7798
7821
|
});
|
|
7799
7822
|
}
|
|
7800
|
-
function
|
|
7823
|
+
function Aa(e) {
|
|
7801
7824
|
let t = (e.env ?? process.env).CODEX_APP_SDK_ASSETS_PATH?.trim();
|
|
7802
7825
|
if (t) return t;
|
|
7803
7826
|
let n = process.resourcesPath, r = e.resourcesPath === void 0 ? n : e.resourcesPath ?? void 0, i = e.existsSync ?? c;
|
|
@@ -7828,18 +7851,18 @@ function ka(e) {
|
|
|
7828
7851
|
let u = import.meta.url, d = e.moduleUrl === void 0 ? u : e.moduleUrl ?? void 0, f = d ? h.dirname(ne(d)) : s, p = [h.resolve(f, "../assets"), h.resolve(f, "../../assets")];
|
|
7829
7852
|
return p.find((e) => i(h.join(e, "apple-speechanalyzer-cli"))) ?? p[0];
|
|
7830
7853
|
}
|
|
7831
|
-
async function
|
|
7854
|
+
async function ja(e, t, n) {
|
|
7832
7855
|
let r = h.join(t, "apple-speechanalyzer-cli");
|
|
7833
7856
|
return await n.copyFile(e, r), await n.chmod(r, 448), r;
|
|
7834
7857
|
}
|
|
7835
7858
|
//#endregion
|
|
7836
7859
|
//#region src/node/apple-speech-session.ts
|
|
7837
|
-
async function
|
|
7860
|
+
async function Ma(e, t, n = {}) {
|
|
7838
7861
|
if (n.signal?.throwIfAborted(), !Number.isInteger(e.sampleRate) || e.sampleRate < 8e3 || e.sampleRate > 96e3) throw Error("Unsupported speech sample rate.");
|
|
7839
7862
|
let r = await se(h.join(m(), "codex-sdk-live-speech-")), i;
|
|
7840
7863
|
try {
|
|
7841
7864
|
let t = h.join(r, "apple-speechanalyzer-cli");
|
|
7842
|
-
await oe(
|
|
7865
|
+
await oe(Da(n.assetsPath), t), await ae(t, 448), n.signal?.throwIfAborted(), i = (n.spawn ?? o)(t, [
|
|
7843
7866
|
"--stream",
|
|
7844
7867
|
"--sample-rate",
|
|
7845
7868
|
String(e.sampleRate),
|
|
@@ -7941,6 +7964,6 @@ async function ja(e, t, n = {}) {
|
|
|
7941
7964
|
};
|
|
7942
7965
|
}
|
|
7943
7966
|
//#endregion
|
|
7944
|
-
export {
|
|
7967
|
+
export { wa as CodexAppBackend, Ca as CodexAppBackendTtlCache, Ve as CodexAppServerStdioTransport, Ke as CodexAppServerUnixSocketTransport, ba as CodexSurface, _r as codexItemToMediaPart, hr as codexItemToSurfaceMessage, L as codexItemToToolPart, me as codexRuntimePathEntries, fr as codexThreadToSurfaceMessages, mr as codexTurnToSurfaceMessages, Ta as createCodexAppBackend, xa as createCodexSurface, pe as discoverCodexExecutable, pr as preserveHistoricalAttachmentPreviews, Da as resolveAppleSpeechAnalyzerPath, ge as resolveCodexRuntime, Ma as startAppleSpeechSession, Ea as transcribeWithAppleSpeechAnalyzer, he as withCodexRuntimePath };
|
|
7945
7968
|
|
|
7946
7969
|
//# sourceMappingURL=index.js.map
|