@kingsoftcloud/ksadk-web 0.3.20 → 0.3.21
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/RELEASE_PROVENANCE.json +2 -2
- package/dist-ksadk/assets/{ArtifactsPanel-xJrZLoUS.js → ArtifactsPanel-BTenzy1K.js} +1 -1
- package/dist-ksadk/assets/{CodeBlock-BTA9jlFc.js → CodeBlock-CWxI359u.js} +1 -1
- package/dist-ksadk/assets/{MathMessageMarkdown-D8CLDYjs.js → MathMessageMarkdown-B15VlKfr.js} +1 -1
- package/dist-ksadk/assets/{MermaidBlock-3yYZbQx6.js → MermaidBlock-CF2HMJlR.js} +6 -6
- package/dist-ksadk/assets/{NativeTerminalPanel-D4Ndrv99.js → NativeTerminalPanel-BxxcxRm3.js} +1 -1
- package/dist-ksadk/assets/{OfficialA2uiRenderer-B8MknRNx.js → OfficialA2uiRenderer-CV3Q-e0k.js} +1 -1
- package/dist-ksadk/assets/{abnfDiagram-VCTEODGH-F1iqB6Wc.js → abnfDiagram-VCTEODGH-C17mm8XX.js} +1 -1
- package/dist-ksadk/assets/{arc-flL4n_cG.js → arc-CCLBsX1i.js} +1 -1
- package/dist-ksadk/assets/architecture-7GRP2DOG-BY2RHa5r.js +1 -0
- package/dist-ksadk/assets/{architectureDiagram-5GKGNRK7-BwmlMIkR.js → architectureDiagram-5GKGNRK7-3pYSVy-d.js} +1 -1
- package/dist-ksadk/assets/{blockDiagram-NRAW4CY4-C_BWAm_x.js → blockDiagram-NRAW4CY4-CsOB-WCp.js} +1 -1
- package/dist-ksadk/assets/{c4Diagram-UCG6FXSJ-82fRziw1.js → c4Diagram-UCG6FXSJ-CU7GynG6.js} +1 -1
- package/dist-ksadk/assets/channel-DwzgTDPP.js +1 -0
- package/dist-ksadk/assets/chunk-2Q5K7J3B-N0kjk6xb.js +1 -0
- package/dist-ksadk/assets/{chunk-5VM5RSS4-C1Ojz8Pw.js → chunk-5VM5RSS4-Cq3ikYM6.js} +1 -1
- package/dist-ksadk/assets/{chunk-F27PBJKO-BBOOiT8C.js → chunk-F27PBJKO-6qvmutbT.js} +1 -1
- package/dist-ksadk/assets/{chunk-G27WJ6UU-BhhwsUX3.js → chunk-G27WJ6UU-BPmeKaDK.js} +1 -1
- package/dist-ksadk/assets/{chunk-JWPE2WC7-iEW3AJI-.js → chunk-JWPE2WC7-zKI5bjIE.js} +1 -1
- package/dist-ksadk/assets/{chunk-LCL6LL3I-DIuXy-81.js → chunk-LCL6LL3I-DZu2N18T.js} +1 -1
- package/dist-ksadk/assets/{chunk-POPQ4Y6H-ykIsvKaZ.js → chunk-POPQ4Y6H-BGNgCFIF.js} +1 -1
- package/dist-ksadk/assets/{chunk-RHFEMEQ7-CNMnEM31.js → chunk-RHFEMEQ7-G_H04lee.js} +1 -1
- package/dist-ksadk/assets/{chunk-SVP7TREG-C1xb4D9y.js → chunk-SVP7TREG-BFQPbitJ.js} +1 -1
- package/dist-ksadk/assets/{chunk-XXDRQBXY-np-DgwXJ.js → chunk-XXDRQBXY-BbCZlhsd.js} +1 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-tbe25yqD.js +1 -0
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-tbe25yqD.js +1 -0
- package/dist-ksadk/assets/{cose-bilkent-JH36ORCC-BTnDFOg9.js → cose-bilkent-JH36ORCC-C4DjCklV.js} +1 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-CSDfrArA.js +1 -0
- package/dist-ksadk/assets/{cynefinDiagram-5FMLGOSQ-BhCQoeu0.js → cynefinDiagram-5FMLGOSQ-CT5ZGJWR.js} +1 -1
- package/dist-ksadk/assets/{dagre-3AP2YEHR-QU3SAyBp.js → dagre-3AP2YEHR-DpvhjWtg.js} +1 -1
- package/dist-ksadk/assets/{dagre-CcBuTmO1.js → dagre-DXyfwLa_.js} +1 -1
- package/dist-ksadk/assets/{diagram-S7CK7UJ4-pUqMF-N_.js → diagram-S7CK7UJ4-BFXOsPnj.js} +1 -1
- package/dist-ksadk/assets/{diagram-UQ7AKVKN-CsBd6UK1.js → diagram-UQ7AKVKN-DjknKAEr.js} +1 -1
- package/dist-ksadk/assets/{diagram-VSXAHHWV-z067B8w9.js → diagram-VSXAHHWV-BB85Ss9s.js} +1 -1
- package/dist-ksadk/assets/{diagram-VX7I27RA-Bq2OSM3W.js → diagram-VX7I27RA-BXi257cj.js} +1 -1
- package/dist-ksadk/assets/{diagram-Z3DM3KII-CGcOnXgQ.js → diagram-Z3DM3KII-DpUD78cp.js} +1 -1
- package/dist-ksadk/assets/{dist-DoI7sPXP.js → dist-B06powmG.js} +1 -1
- package/dist-ksadk/assets/{dist-29mR2j1z.js → dist-BNv0PyLr.js} +1 -1
- package/dist-ksadk/assets/{dist-BFwycVyB.js → dist-BRZbKA2x.js} +1 -1
- package/dist-ksadk/assets/{dist-DLBTehW7.js → dist-BYwMHGkY.js} +1 -1
- package/dist-ksadk/assets/{dist-CDVF37r5.js → dist-BZW9mKsK.js} +1 -1
- package/dist-ksadk/assets/{dist-DoiIiZp1.js → dist-BeVI-Kxd.js} +1 -1
- package/dist-ksadk/assets/{dist-BgNv7i6A.js → dist-Bq9DY1Dv.js} +1 -1
- package/dist-ksadk/assets/{dist-DaTlP0PP.js → dist-Bzd2QgV8.js} +1 -1
- package/dist-ksadk/assets/{dist-uTNKHquK.js → dist-CMFDdLf4.js} +1 -1
- package/dist-ksadk/assets/{dist-BBhjV2zk.js → dist-CV9d3y2j.js} +1 -1
- package/dist-ksadk/assets/{dist-D4i4A-9H.js → dist-CXVLGraS.js} +1 -1
- package/dist-ksadk/assets/{dist-DClJp8Fu.js → dist-CczefzvC.js} +1 -1
- package/dist-ksadk/assets/{dist-BCeJUhFK.js → dist-Cj2Auk2b.js} +1 -1
- package/dist-ksadk/assets/{dist-Hq4SADW4.js → dist-CnQbOxbh.js} +1 -1
- package/dist-ksadk/assets/{dist-BzzV3E1A.js → dist-DBGrMizf.js} +1 -1
- package/dist-ksadk/assets/{dist-CtBVJsc4.js → dist-DavYaJ9Q.js} +1 -1
- package/dist-ksadk/assets/{dist-B82Nq4cr.js → dist-Dycz9kOr.js} +1 -1
- package/dist-ksadk/assets/{dist-DAvQipED.js → dist-R5ApucPA.js} +1 -1
- package/dist-ksadk/assets/{dist-CldkDS2P.js → dist-TZoM3zbE.js} +1 -1
- package/dist-ksadk/assets/{dist-B7wGQtoN.js → dist-WrvDVf9t.js} +1 -1
- package/dist-ksadk/assets/{dist-D2pftL-p.js → dist-Z1yWL6bl.js} +1 -1
- package/dist-ksadk/assets/{dist-DkIK9AMC.js → dist-r1VjfiSE.js} +1 -1
- package/dist-ksadk/assets/{ebnfDiagram-PWID7BFC-B3R_tmjW.js → ebnfDiagram-PWID7BFC-lDIRqB5V.js} +1 -1
- package/dist-ksadk/assets/{erDiagram-SSCWMZ5O-J2nOSrdM.js → erDiagram-SSCWMZ5O-BiSx4WXZ.js} +1 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV-CA5gOEzT.js +1 -0
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-BEQAxSrx.js +1 -0
- package/dist-ksadk/assets/{ganttDiagram-EL5Y4UJY-C8RKSSnW.js → ganttDiagram-EL5Y4UJY-B2XMRclR.js} +1 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-DhOY6HCO.js +1 -0
- package/dist-ksadk/assets/{gitGraphDiagram-WWUBYQGX--TydsWqh.js → gitGraphDiagram-WWUBYQGX-B0Im0UQT.js} +1 -1
- package/dist-ksadk/assets/{index-BkjYckSc.js → index-DybHfQCT.js} +165 -165
- package/dist-ksadk/assets/info-A6RAGUB7-Dp4VkXgu.js +1 -0
- package/dist-ksadk/assets/{infoDiagram-RXCK75RN-D6sVWyle.js → infoDiagram-RXCK75RN-CoIIy7xO.js} +1 -1
- package/dist-ksadk/assets/{ishikawaDiagram-5VMMS53U-DrclE7fd.js → ishikawaDiagram-5VMMS53U-CdOil3Ww.js} +1 -1
- package/dist-ksadk/assets/{journeyDiagram-EYS64GPL-BRfZiBbu.js → journeyDiagram-EYS64GPL-ag6kSf5d.js} +1 -1
- package/dist-ksadk/assets/{kanban-definition-3QL26DDD-CNybbrEd.js → kanban-definition-3QL26DDD-CmIFaKQY.js} +1 -1
- package/dist-ksadk/assets/{katex-DBOw26LR.js → katex-DxefP4aZ.js} +1 -1
- package/dist-ksadk/assets/{linear-44nYnHX-.js → linear-DwipGcVt.js} +1 -1
- package/dist-ksadk/assets/{mermaid-parser.core-C_kQii2V.js → mermaid-parser.core-vshe0mzD.js} +2 -2
- package/dist-ksadk/assets/{mindmap-definition-FBJOCRG2-BVRrbrEZ.js → mindmap-definition-FBJOCRG2-Dw-6--QW.js} +1 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-CeRM6FyX.js +1 -0
- package/dist-ksadk/assets/{pegDiagram-XKGWAZYB-DegSzNRD.js → pegDiagram-XKGWAZYB-DFNebRUp.js} +1 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-Djp6ckL7.js +1 -0
- package/dist-ksadk/assets/{pieDiagram-E7YTZNPT-CxdzAjVe.js → pieDiagram-E7YTZNPT-CHxeRYAb.js} +1 -1
- package/dist-ksadk/assets/{quadrantDiagram-AXDQQJYC-CCoPOep-.js → quadrantDiagram-AXDQQJYC-B5EZIUvT.js} +1 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-D2dsze9F.js +1 -0
- package/dist-ksadk/assets/railroad-74A4TZTK-DBwQwqS4.js +1 -0
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-DkPaTgaM.js +1 -0
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-CGj2E-SZ.js +1 -0
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-DGXLjDY5.js +1 -0
- package/dist-ksadk/assets/{railroadDiagram-O6MQD6OU-c0A7TkkT.js → railroadDiagram-O6MQD6OU-D3sGYWAm.js} +1 -1
- package/dist-ksadk/assets/{requirementDiagram-EFPCY7ZU-P6gr0KYk.js → requirementDiagram-EFPCY7ZU-C-MRJ006.js} +1 -1
- package/dist-ksadk/assets/{sankeyDiagram-P5KCCOFB-DC4nZ3Da.js → sankeyDiagram-P5KCCOFB-C5Qc8Tw5.js} +1 -1
- package/dist-ksadk/assets/{sequenceDiagram-WJ2MYXX4-CZtmOwJw.js → sequenceDiagram-WJ2MYXX4-Cwt6RdFu.js} +1 -1
- package/dist-ksadk/assets/{sizeCapture-X5ZJPWSS-Co1bu09k.js → sizeCapture-X5ZJPWSS-DffXmYT6.js} +1 -1
- package/dist-ksadk/assets/{stateDiagram-HBIQ2CUA-BQVjMByH.js → stateDiagram-HBIQ2CUA-CsWi85pm.js} +1 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-DP_nPml6.js +1 -0
- package/dist-ksadk/assets/{swimlanes-XN3QIQJK-hlr6yX7f.js → swimlanes-XN3QIQJK-BFT0NQ46.js} +1 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-DOvIyrQA.js +8 -0
- package/dist-ksadk/assets/{timeline-definition-24CTP7MA-CvlFQUAe.js → timeline-definition-24CTP7MA-DXYCmjmW.js} +1 -1
- package/dist-ksadk/assets/treeView-Q6P3EWNA-Drao7JLN.js +1 -0
- package/dist-ksadk/assets/treemap-WGGIJYW6-CdCZ9GK9.js +1 -0
- package/dist-ksadk/assets/{vennDiagram-4TSXK5OY-TSlD8LZX.js → vennDiagram-4TSXK5OY-D7CAii6e.js} +1 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-BaPyAVbq.js +1 -0
- package/dist-ksadk/assets/{wardleyDiagram-VM6X3IG4-COY6_ZHj.js → wardleyDiagram-VM6X3IG4-cQzt4L9O.js} +1 -1
- package/dist-ksadk/assets/{xychartDiagram-S5SC5T6Z-DbaIT_9a.js → xychartDiagram-S5SC5T6Z-DazvdMTB.js} +1 -1
- package/dist-ksadk/index.html +1 -1
- package/dist-lib/core/api/facade.d.ts +2 -0
- package/dist-lib/core/api/facade.d.ts.map +1 -1
- package/dist-lib/core/api/types.d.ts +2 -0
- package/dist-lib/core/api/types.d.ts.map +1 -1
- package/dist-lib/hooks/useSessionLifecycle.d.ts +1 -1
- package/dist-lib/hooks/useSessionLifecycle.d.ts.map +1 -1
- package/dist-lib/hooks.js +1 -1
- package/dist-lib/runtime.js +1 -1
- package/dist-lib/{useSessionLifecycle-B0RRKS9m.js → useSessionLifecycle-DeX2s_iU.js} +1037 -972
- package/package.json +1 -1
- package/dist-ksadk/assets/architecture-7GRP2DOG-CVbS66_3.js +0 -1
- package/dist-ksadk/assets/channel-BRWZD-yc.js +0 -1
- package/dist-ksadk/assets/chunk-2Q5K7J3B-WPKdx1wk.js +0 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-B9FzdGp4.js +0 -1
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-B9FzdGp4.js +0 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-BdJIG45e.js +0 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV-DYpyM1Bl.js +0 -1
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-BTndHsf4.js +0 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-K0gsLZ8v.js +0 -1
- package/dist-ksadk/assets/info-A6RAGUB7-rivQEqA4.js +0 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-BWH3_z2P.js +0 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-YFDBqoLw.js +0 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-Dyl_dza9.js +0 -1
- package/dist-ksadk/assets/railroad-74A4TZTK-BP48ZU0l.js +0 -1
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-BLZ-Uq2U.js +0 -1
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-EZUa4Mwx.js +0 -1
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-HrWsR5Xv.js +0 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-BdDvoPqK.js +0 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-CVQOLHam.js +0 -8
- package/dist-ksadk/assets/treeView-Q6P3EWNA-B5KEc2LE.js +0 -1
- package/dist-ksadk/assets/treemap-WGGIJYW6-Ctt8lBKu.js +0 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-DVbqgmoi.js +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { a as e, i as t, o as n, t as r } from "./capabilities-CHy70QGW.js";
|
|
2
|
-
import {
|
|
3
|
-
import { C as
|
|
4
|
-
import { a as
|
|
5
|
-
import { a as
|
|
6
|
-
import { C as
|
|
7
|
-
import { useCallback as q, useEffect as J, useMemo as
|
|
8
|
-
import { HttpAgent as
|
|
2
|
+
import { A as i, E as a, I as o, J as s, K as c, L as l, M as u, N as d, O as f, V as p, W as m, X as h, Y as g, Z as _, a as v, b as y, c as b, d as x, f as S, k as C, l as ee, o as w, p as T, q as E, r as te, s as D, t as O, u as k, v as A } from "./a2ui-DmynyrCk.js";
|
|
3
|
+
import { C as j, a as M, d as N, f as P, i as ne, l as F, o as re, p as I, r as L, s as ie, t as R, u as z, x as ae } from "./session-events-COiszsgX.js";
|
|
4
|
+
import { a as B, c as oe, d as V, f as H, i as U, l as W, n as se, o as ce, p as G, r as K, s as le, u as ue } from "./session-message-history-DC89pksC.js";
|
|
5
|
+
import { a as de, d as fe, f as pe, p as me, s as he } from "./reducer-mbYiX0wz.js";
|
|
6
|
+
import { C as ge, D as _e, E as ve, S as ye, T as be, _ as xe, a as Se, b as Ce, c as we, d as Te, f as Ee, g as De, h as Oe, i as ke, l as Ae, m as je, n as Me, o as Ne, p as Pe, r as Fe, s as Ie, t as Le, u as Re, v as ze, w as Be, y as Ve } from "./persisted-session-history-B9O1vWtS.js";
|
|
7
|
+
import { useCallback as q, useEffect as J, useMemo as He, useRef as Y, useState as Ue } from "react";
|
|
8
|
+
import { HttpAgent as We, buildResumeArray as Ge } from "@ag-ui/client";
|
|
9
9
|
//#region src/api/client.ts
|
|
10
10
|
var X = class extends Error {
|
|
11
11
|
code;
|
|
@@ -21,8 +21,8 @@ var X = class extends Error {
|
|
|
21
21
|
constructor(e = "请求已取消") {
|
|
22
22
|
super(e), this.name = "CancelledError";
|
|
23
23
|
}
|
|
24
|
-
},
|
|
25
|
-
async function
|
|
24
|
+
}, Ke = "/agentengine/api/v1";
|
|
25
|
+
async function qe(e) {
|
|
26
26
|
let t = await e.text(), n = {};
|
|
27
27
|
try {
|
|
28
28
|
n = t ? JSON.parse(t) : {};
|
|
@@ -39,15 +39,15 @@ async function Ke(e) {
|
|
|
39
39
|
if (n?.Code !== void 0 && n.Code !== 0) throw new X(n.Code, n.Message || "请求失败", n, e.headers.get("retry-after"));
|
|
40
40
|
return n.Data;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function Je(e) {
|
|
43
43
|
throw e instanceof DOMException && e.name === "AbortError" ? new Z() : e;
|
|
44
44
|
}
|
|
45
|
-
var
|
|
45
|
+
var Ye = class {
|
|
46
46
|
fetcher;
|
|
47
47
|
baseUrl;
|
|
48
48
|
agentId;
|
|
49
49
|
constructor(e = {}) {
|
|
50
|
-
this.fetcher = e.fetch || ((e, t) => globalThis.fetch(e, t)), this.baseUrl = String(e.baseUrl ||
|
|
50
|
+
this.fetcher = e.fetch || ((e, t) => globalThis.fetch(e, t)), this.baseUrl = String(e.baseUrl || Ke).replace(/\/+$/, ""), this.agentId = String(e.agentId || "").trim();
|
|
51
51
|
}
|
|
52
52
|
actionUrl(e) {
|
|
53
53
|
return `${this.baseUrl}/${e}`;
|
|
@@ -68,9 +68,9 @@ var Je = class {
|
|
|
68
68
|
signal: n?.signal
|
|
69
69
|
});
|
|
70
70
|
} catch (e) {
|
|
71
|
-
throw
|
|
71
|
+
throw Je(e);
|
|
72
72
|
}
|
|
73
|
-
return
|
|
73
|
+
return qe(r);
|
|
74
74
|
}
|
|
75
75
|
async postFormAction(e, t, n) {
|
|
76
76
|
let r;
|
|
@@ -82,9 +82,9 @@ var Je = class {
|
|
|
82
82
|
signal: n?.signal
|
|
83
83
|
});
|
|
84
84
|
} catch (e) {
|
|
85
|
-
throw
|
|
85
|
+
throw Je(e);
|
|
86
86
|
}
|
|
87
|
-
return
|
|
87
|
+
return qe(r);
|
|
88
88
|
}
|
|
89
89
|
async getResource(e, t, n) {
|
|
90
90
|
let r = this.agentId && !t.AgentId ? {
|
|
@@ -94,7 +94,7 @@ var Je = class {
|
|
|
94
94
|
try {
|
|
95
95
|
o = await this.fetcher(a, { signal: n?.signal });
|
|
96
96
|
} catch (e) {
|
|
97
|
-
throw
|
|
97
|
+
throw Je(e);
|
|
98
98
|
}
|
|
99
99
|
if (!o.ok) throw new X(o.status, `资源获取失败: ${o.statusText}`);
|
|
100
100
|
try {
|
|
@@ -116,10 +116,10 @@ var Je = class {
|
|
|
116
116
|
signal: n?.signal
|
|
117
117
|
});
|
|
118
118
|
} catch (e) {
|
|
119
|
-
throw
|
|
119
|
+
throw Je(e);
|
|
120
120
|
}
|
|
121
|
-
if (!r.ok) throw await
|
|
122
|
-
if ((r.headers.get("content-type")?.toLowerCase() || "").includes("application/json") && await
|
|
121
|
+
if (!r.ok) throw await qe(r), new X(r.status, `流式请求失败: ${r.statusText}`);
|
|
122
|
+
if ((r.headers.get("content-type")?.toLowerCase() || "").includes("application/json") && await qe(r.clone()), !r.body) throw new X(-1, "无法获取响应流");
|
|
123
123
|
let i = r.headers.get("x-agentengine-command-id");
|
|
124
124
|
return i && n?.onCommandAdmitted?.(i), r.body;
|
|
125
125
|
}
|
|
@@ -134,28 +134,28 @@ var Je = class {
|
|
|
134
134
|
signal: n?.signal
|
|
135
135
|
});
|
|
136
136
|
} catch (e) {
|
|
137
|
-
throw
|
|
137
|
+
throw Je(e);
|
|
138
138
|
}
|
|
139
|
-
if (!o.ok || o.headers.get("content-type")?.toLowerCase().includes("application/json")) throw new X(502, "流式订阅未返回事件流", await
|
|
139
|
+
if (!o.ok || o.headers.get("content-type")?.toLowerCase().includes("application/json")) throw new X(502, "流式订阅未返回事件流", await qe(o));
|
|
140
140
|
if (!o.body) throw new X(-1, "无法获取响应流");
|
|
141
141
|
return o.body;
|
|
142
142
|
}
|
|
143
|
-
},
|
|
144
|
-
async function
|
|
143
|
+
}, Xe = new Ye(), Ze = (e, t, n) => Xe.streamAction(e, t, n), Qe = (e, t, n) => Xe.streamGetAction(e, t, n), $e = 50, et = 2500;
|
|
144
|
+
async function tt(e, t) {
|
|
145
145
|
let { itemCursor: n, contentSeqId: r, limit: i, signal: a } = e ?? {};
|
|
146
|
-
if (!n || r !== void 0 || !i || i <=
|
|
146
|
+
if (!n || r !== void 0 || !i || i <= $e) return t(i, a);
|
|
147
147
|
a?.throwIfAborted();
|
|
148
148
|
let o = new AbortController(), s = () => o.abort(a?.reason);
|
|
149
149
|
a?.addEventListener("abort", s, { once: !0 });
|
|
150
150
|
let c = Symbol("slow-history-page"), l;
|
|
151
151
|
try {
|
|
152
152
|
let e = t(i, o.signal), n = await Promise.race([e, new Promise((e) => {
|
|
153
|
-
l = setTimeout(() => e(c),
|
|
153
|
+
l = setTimeout(() => e(c), et);
|
|
154
154
|
})]);
|
|
155
155
|
if (n !== c) return n;
|
|
156
156
|
o.signal.throwIfAborted();
|
|
157
157
|
try {
|
|
158
|
-
return await Promise.any([e, t(
|
|
158
|
+
return await Promise.any([e, t($e, o.signal)]);
|
|
159
159
|
} catch (e) {
|
|
160
160
|
throw e instanceof AggregateError ? e.errors[0] : e;
|
|
161
161
|
}
|
|
@@ -163,7 +163,7 @@ async function et(e, t) {
|
|
|
163
163
|
clearTimeout(l), o.abort(), a?.removeEventListener("abort", s);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function nt(e) {
|
|
167
167
|
return {
|
|
168
168
|
HistoryView: e.HistoryView,
|
|
169
169
|
Items: e.Items,
|
|
@@ -188,10 +188,10 @@ function tt(e) {
|
|
|
188
188
|
}
|
|
189
189
|
//#endregion
|
|
190
190
|
//#region src/core/api/facade.ts
|
|
191
|
-
var
|
|
191
|
+
var rt = class {
|
|
192
192
|
client;
|
|
193
193
|
constructor(e = {}) {
|
|
194
|
-
this.client = new
|
|
194
|
+
this.client = new Ye(e);
|
|
195
195
|
}
|
|
196
196
|
mcpAuthorization = async (e, t, n, r) => this.client.postJsonAction(e, {
|
|
197
197
|
WaitId: t,
|
|
@@ -256,7 +256,7 @@ var nt = class {
|
|
|
256
256
|
};
|
|
257
257
|
}
|
|
258
258
|
async listSessionMessages(e, t) {
|
|
259
|
-
return
|
|
259
|
+
return nt(await tt(t, (n, r) => this.client.postJsonAction("ListSessionMessages", {
|
|
260
260
|
AgentId: t?.agentId,
|
|
261
261
|
SessionId: e,
|
|
262
262
|
HistoryView: t?.historyView,
|
|
@@ -320,17 +320,20 @@ var nt = class {
|
|
|
320
320
|
}, t);
|
|
321
321
|
}
|
|
322
322
|
async submitControl(e, t) {
|
|
323
|
-
return
|
|
323
|
+
return C(await this.client.postJsonAction("SubmitAgentControl", {
|
|
324
324
|
CommandType: e.command_type,
|
|
325
325
|
IdempotencyKey: e.idempotency_key,
|
|
326
326
|
Payload: e.payload
|
|
327
327
|
}, t));
|
|
328
328
|
}
|
|
329
329
|
async submitInteraction(e, t) {
|
|
330
|
-
return
|
|
330
|
+
return C(await this.client.postJsonAction("SubmitInteraction", { ...e }, t));
|
|
331
331
|
}
|
|
332
332
|
async getAgentStatus(e) {
|
|
333
|
-
return this.client.postJsonAction("GetAgentStatus", {
|
|
333
|
+
return this.client.postJsonAction("GetAgentStatus", {
|
|
334
|
+
AgentId: e?.agentId,
|
|
335
|
+
SessionId: e?.sessionId
|
|
336
|
+
}, e);
|
|
334
337
|
}
|
|
335
338
|
async subscribeSessionEvents(e, t, n) {
|
|
336
339
|
return this.client.streamGetAction("SubscribeSessionEvents", {
|
|
@@ -389,34 +392,34 @@ var nt = class {
|
|
|
389
392
|
async uploadFile(e, t) {
|
|
390
393
|
return this.client.postFormAction("UploadFile", e, t);
|
|
391
394
|
}
|
|
392
|
-
},
|
|
393
|
-
function
|
|
395
|
+
}, it = "ksadk:webui:selected-session:";
|
|
396
|
+
function at(e) {
|
|
394
397
|
return String(e || "").trim() || "default-agent";
|
|
395
398
|
}
|
|
396
|
-
function
|
|
399
|
+
function ot(e) {
|
|
397
400
|
if (e && typeof e.getItem == "function") return e;
|
|
398
401
|
try {
|
|
399
402
|
if (typeof window < "u" && window.localStorage) return window.localStorage;
|
|
400
403
|
} catch {}
|
|
401
404
|
return null;
|
|
402
405
|
}
|
|
403
|
-
function
|
|
404
|
-
return
|
|
406
|
+
function st(e) {
|
|
407
|
+
return s.key(`${it}${at(e)}`);
|
|
405
408
|
}
|
|
406
|
-
function
|
|
407
|
-
let n =
|
|
409
|
+
function ct(e, t) {
|
|
410
|
+
let n = ot(t);
|
|
408
411
|
if (!n) return null;
|
|
409
412
|
try {
|
|
410
|
-
return String(n.getItem(
|
|
413
|
+
return String(n.getItem(st(e)) || "").trim() || null;
|
|
411
414
|
} catch {
|
|
412
415
|
return null;
|
|
413
416
|
}
|
|
414
417
|
}
|
|
415
|
-
function
|
|
416
|
-
if (!
|
|
417
|
-
let r =
|
|
418
|
+
function lt(e, t, n) {
|
|
419
|
+
if (!s.writable) return;
|
|
420
|
+
let r = ot(n);
|
|
418
421
|
if (!r) return;
|
|
419
|
-
let i =
|
|
422
|
+
let i = st(e), a = String(t || "").trim();
|
|
420
423
|
try {
|
|
421
424
|
if (a) {
|
|
422
425
|
r.setItem(i, a);
|
|
@@ -425,7 +428,7 @@ function ct(e, t, n) {
|
|
|
425
428
|
r.removeItem(i);
|
|
426
429
|
} catch {}
|
|
427
430
|
}
|
|
428
|
-
function
|
|
431
|
+
function ut(e, t) {
|
|
429
432
|
if (!Array.isArray(e) || e.length === 0) return null;
|
|
430
433
|
let n = String(t || "").trim();
|
|
431
434
|
if (n && e.some((e) => String(e?.SessionId || "").trim() === n)) return n;
|
|
@@ -435,7 +438,7 @@ function lt(e, t) {
|
|
|
435
438
|
}
|
|
436
439
|
return null;
|
|
437
440
|
}
|
|
438
|
-
function
|
|
441
|
+
function dt(e, t, n) {
|
|
439
442
|
let r = Array.isArray(e) ? e : [], i = Array.isArray(t) ? t : [], a = n instanceof Set ? n : new Set(Array.isArray(n) ? n : []);
|
|
440
443
|
if (a.size === 0) return r;
|
|
441
444
|
let o = new Set(r.map((e) => String(e?.SessionId || "").trim()).filter(Boolean)), s = i.filter((e) => {
|
|
@@ -446,53 +449,53 @@ function ut(e, t, n) {
|
|
|
446
449
|
}
|
|
447
450
|
//#endregion
|
|
448
451
|
//#region src/hooks/useBootstrap.ts
|
|
449
|
-
function
|
|
452
|
+
function ft(e) {
|
|
450
453
|
return e instanceof X && (e.code === 401 || e.code === 403) ? "auth-required" : "error";
|
|
451
454
|
}
|
|
452
|
-
function
|
|
455
|
+
function pt(e) {
|
|
453
456
|
if (!Array.isArray(e)) return ["responses", "chat_completions"];
|
|
454
457
|
let t = e.filter((e) => e === "responses" || e === "chat_completions");
|
|
455
458
|
return t.length > 0 ? t : ["responses", "chat_completions"];
|
|
456
459
|
}
|
|
457
|
-
var
|
|
458
|
-
async function
|
|
460
|
+
var mt = new rt();
|
|
461
|
+
async function ht(e, t = mt) {
|
|
459
462
|
try {
|
|
460
463
|
let n = await t.listAgentModels(e), r = n?.Models;
|
|
461
|
-
Array.isArray(r) &&
|
|
464
|
+
Array.isArray(r) && g.getState().upsertModels(r);
|
|
462
465
|
let i = n;
|
|
463
|
-
i?.Current && !
|
|
466
|
+
i?.Current && !g.getState().selectedModel && g.getState().setSelectedModel(String(i.Current)), i?.Source && g.getState().setModelSource(String(i.Source));
|
|
464
467
|
} catch (e) {
|
|
465
468
|
console.error("Failed to fetch models:", e);
|
|
466
469
|
} finally {
|
|
467
|
-
|
|
470
|
+
g.getState().setModelCatalogLoaded(!0);
|
|
468
471
|
}
|
|
469
472
|
}
|
|
470
|
-
function
|
|
473
|
+
function gt(t, n, i = mt, a) {
|
|
471
474
|
J(() => {
|
|
472
475
|
let o = new AbortController();
|
|
473
476
|
return (async () => {
|
|
474
|
-
|
|
477
|
+
l.getState().setStatus("loading");
|
|
475
478
|
try {
|
|
476
479
|
let s = a ?? await i.getAgentUiBootstrap(n, { signal: o.signal });
|
|
477
480
|
if (o.signal.aborted) return;
|
|
478
|
-
let
|
|
479
|
-
if (
|
|
481
|
+
let c = s, u = c?.Agent, d = String(u?.AgentId || "default-agent");
|
|
482
|
+
if (l.getState().setAgentId(d), u?.Name) {
|
|
480
483
|
let e = String(u.Name);
|
|
481
|
-
|
|
484
|
+
l.getState().setAgentName(e), document.title = e;
|
|
482
485
|
}
|
|
483
486
|
let f = String(u?.Framework || "").trim().toLowerCase();
|
|
484
|
-
|
|
487
|
+
l.getState().setAgentFramework(f);
|
|
485
488
|
let p = e(s);
|
|
486
|
-
|
|
487
|
-
let m = p.WorkspaceFiles &&
|
|
488
|
-
|
|
489
|
-
let
|
|
490
|
-
|
|
489
|
+
l.getState().setCapabilities(p), l.getState().setApiFormats(pt(p.HostedChat.ApiFormats)), l.getState().setAccessMode(String(c?.AccessMode || "Owner"));
|
|
490
|
+
let m = p.WorkspaceFiles && c?.WorkspaceFiles ? c.WorkspaceFiles : null;
|
|
491
|
+
l.getState().setWorkspaceFiles(m), m || _.getState().setWorkspacePanelOpen(!1), r(p) && t.fetchSessions(d, ct(d));
|
|
492
|
+
let h = c?.Model;
|
|
493
|
+
h?.id && (g.getState().setSelectedModel(h.id), g.getState().upsertModels([h]), g.getState().setModelSource(h.source || "")), ht(d, i), l.getState().setStatus("ready");
|
|
491
494
|
} catch (e) {
|
|
492
495
|
if (o.signal.aborted) return;
|
|
493
496
|
console.error("Failed to fetch bootstrap:", e);
|
|
494
|
-
let t =
|
|
495
|
-
|
|
497
|
+
let t = ft(e);
|
|
498
|
+
l.getState().setStatus(t, t === "auth-required" ? "当前访问链接未授权或已过期。" : "无法加载 Agent 配置,请稍后重试。");
|
|
496
499
|
}
|
|
497
500
|
})(), () => o.abort();
|
|
498
501
|
}, [
|
|
@@ -503,14 +506,14 @@ function ht(t, n, i = pt, a) {
|
|
|
503
506
|
}
|
|
504
507
|
//#endregion
|
|
505
508
|
//#region src/hooks/useFeedback.ts
|
|
506
|
-
function
|
|
509
|
+
function _t(e) {
|
|
507
510
|
let { agentId: t, currentSessionId: n, isStreaming: r, api: i, submitDraft: a } = e;
|
|
508
511
|
return {
|
|
509
512
|
submitResponseFeedback: q(async (e) => {
|
|
510
513
|
if (!n) return;
|
|
511
514
|
let r = null;
|
|
512
|
-
|
|
513
|
-
let n =
|
|
515
|
+
G.getState().patchMessages((t) => {
|
|
516
|
+
let n = K(t, {
|
|
514
517
|
messageId: e.message.id,
|
|
515
518
|
rating: e.rating,
|
|
516
519
|
comment: e.comment || ""
|
|
@@ -518,19 +521,19 @@ function gt(e) {
|
|
|
518
521
|
return r = n.previousFeedback, n.nextMessages;
|
|
519
522
|
});
|
|
520
523
|
try {
|
|
521
|
-
let r =
|
|
524
|
+
let r = oe((await i.upsertResponseFeedback(B({
|
|
522
525
|
agentId: t,
|
|
523
526
|
sessionId: n,
|
|
524
527
|
message: e.message,
|
|
525
528
|
rating: e.rating,
|
|
526
529
|
comment: e.comment || ""
|
|
527
530
|
})))?.Feedback);
|
|
528
|
-
r &&
|
|
531
|
+
r && G.getState().patchMessages((t) => le(t, {
|
|
529
532
|
messageId: e.message.id,
|
|
530
533
|
feedback: r
|
|
531
534
|
}));
|
|
532
535
|
} catch (t) {
|
|
533
|
-
console.error("Failed to submit response feedback:", t),
|
|
536
|
+
console.error("Failed to submit response feedback:", t), G.getState().patchMessages((t) => W(t, {
|
|
534
537
|
messageId: e.message.id,
|
|
535
538
|
previousFeedback: r
|
|
536
539
|
}));
|
|
@@ -543,15 +546,15 @@ function gt(e) {
|
|
|
543
546
|
deleteResponseFeedback: q(async (e) => {
|
|
544
547
|
if (!n) return;
|
|
545
548
|
let r = e.feedback ? { ...e.feedback } : null;
|
|
546
|
-
|
|
549
|
+
G.getState().patchMessages((t) => ce(t, { messageId: e.id }));
|
|
547
550
|
try {
|
|
548
|
-
await i.deleteResponseFeedback(
|
|
551
|
+
await i.deleteResponseFeedback(U({
|
|
549
552
|
agentId: t,
|
|
550
553
|
sessionId: n,
|
|
551
554
|
message: e
|
|
552
555
|
}));
|
|
553
556
|
} catch (t) {
|
|
554
|
-
console.error("Failed to delete response feedback:", t),
|
|
557
|
+
console.error("Failed to delete response feedback:", t), G.getState().patchMessages((t) => W(t, {
|
|
555
558
|
messageId: e.id,
|
|
556
559
|
previousFeedback: r
|
|
557
560
|
}));
|
|
@@ -565,7 +568,7 @@ function gt(e) {
|
|
|
565
568
|
type: "mcp_approval_response",
|
|
566
569
|
approval_request_id: e.approvalRequestId,
|
|
567
570
|
approve: e.approve
|
|
568
|
-
}], e.previousResponseId) ? !1 : (
|
|
571
|
+
}], e.previousResponseId) ? !1 : (c.getState().currentSessionId === n && G.getState().patchMessages((t) => t.map((t) => {
|
|
569
572
|
let n = e.approve ? "approved" : "rejected", r = (t) => e.approve && t === "paused" ? "running" : e.approve ? t : "completed";
|
|
570
573
|
return {
|
|
571
574
|
...t,
|
|
@@ -592,7 +595,7 @@ function gt(e) {
|
|
|
592
595
|
}
|
|
593
596
|
//#endregion
|
|
594
597
|
//#region src/core/mcp-authorization/recovery.ts
|
|
595
|
-
function
|
|
598
|
+
function vt(e, t, n, r) {
|
|
596
599
|
let i = /* @__PURE__ */ new Map(), a = !1;
|
|
597
600
|
function o(e) {
|
|
598
601
|
clearTimeout(i.get(e)), i.delete(e);
|
|
@@ -600,7 +603,7 @@ function _t(e, t, n, r) {
|
|
|
600
603
|
function s(s) {
|
|
601
604
|
if (s.sessionId !== t || !s.runId) return;
|
|
602
605
|
let c = s.runId, l = s.interactionId;
|
|
603
|
-
if (s.status !== "pending" ||
|
|
606
|
+
if (s.status !== "pending" || V(s)) {
|
|
604
607
|
o(l);
|
|
605
608
|
return;
|
|
606
609
|
}
|
|
@@ -609,7 +612,7 @@ function _t(e, t, n, r) {
|
|
|
609
612
|
try {
|
|
610
613
|
let o = await n("GetMcpAuthorizationWait", l, void 0, t);
|
|
611
614
|
if (a || !i.has(l)) return;
|
|
612
|
-
let s =
|
|
615
|
+
let s = I(o, t, c), u = e.get(t, l);
|
|
613
616
|
s?.interactionId === l && u && s.revision > u.revision && (e.upsert(s), (s.status === "resolved" || s.status === "cancelled" || s.status === "expired") && r(t));
|
|
614
617
|
} catch {}
|
|
615
618
|
!a && i.has(l) && i.set(l, setTimeout(u, 3e3));
|
|
@@ -627,10 +630,10 @@ function _t(e, t, n, r) {
|
|
|
627
630
|
}
|
|
628
631
|
//#endregion
|
|
629
632
|
//#region src/hooks/useInteractions.ts
|
|
630
|
-
function
|
|
631
|
-
let t =
|
|
633
|
+
function yt(e) {
|
|
634
|
+
let t = v(), [n] = Ue(() => new a({
|
|
632
635
|
agentId: e.agentId,
|
|
633
|
-
store:
|
|
636
|
+
store: T,
|
|
634
637
|
submitInteraction: (t) => e.api.submitInteraction({
|
|
635
638
|
...t,
|
|
636
639
|
AgentId: e.getAgentId?.() ?? t.AgentId
|
|
@@ -642,19 +645,19 @@ function vt(e) {
|
|
|
642
645
|
J(() => {
|
|
643
646
|
n.setInteractionV1Enabled(e.interactionV1Enabled);
|
|
644
647
|
}, [n, e.interactionV1Enabled]);
|
|
645
|
-
let [r,
|
|
646
|
-
J(() =>
|
|
647
|
-
let o =
|
|
648
|
+
let [r, i] = Ue(0);
|
|
649
|
+
J(() => T.subscribe(() => i((e) => e + 1)), []);
|
|
650
|
+
let o = l((e) => e.accessMode === "Share"), s = He(() => {
|
|
648
651
|
if (!e.currentSessionId) return [];
|
|
649
|
-
let t =
|
|
652
|
+
let t = T.listAll(e.currentSessionId);
|
|
650
653
|
return o ? t.filter((e) => !e.extensions.mcpAuthorization) : t;
|
|
651
654
|
}, [
|
|
652
655
|
r,
|
|
653
656
|
e.currentSessionId,
|
|
654
657
|
o
|
|
655
|
-
]),
|
|
658
|
+
]), c = He(() => s.filter(V), [s]), { currentSessionId: u, interactionV1Enabled: d, onAcceptedInteraction: f } = e, p = o ? void 0 : e.api.mcpAuthorization, m = e.reloadHistory;
|
|
656
659
|
J(() => {
|
|
657
|
-
if (u && p) return
|
|
660
|
+
if (u && p) return vt(T, u, p, m);
|
|
658
661
|
}, [
|
|
659
662
|
e.agentId,
|
|
660
663
|
u,
|
|
@@ -677,10 +680,10 @@ function vt(e) {
|
|
|
677
680
|
}
|
|
678
681
|
}, [s, f]), {
|
|
679
682
|
client: n,
|
|
680
|
-
pending:
|
|
683
|
+
pending: c,
|
|
681
684
|
records: s,
|
|
682
685
|
respond: q((e) => {
|
|
683
|
-
let t = u ?
|
|
686
|
+
let t = u ? T.get(u, e.interactionId) : null;
|
|
684
687
|
return u ? n.respond({
|
|
685
688
|
...e,
|
|
686
689
|
sessionId: u
|
|
@@ -694,43 +697,43 @@ function vt(e) {
|
|
|
694
697
|
localCatalog: t
|
|
695
698
|
};
|
|
696
699
|
}
|
|
697
|
-
var
|
|
698
|
-
function
|
|
700
|
+
var bt = .28;
|
|
701
|
+
function xt(e, t = 768) {
|
|
699
702
|
return Number(e) <= t;
|
|
700
703
|
}
|
|
701
|
-
function
|
|
704
|
+
function St({ isMobile: e, desktopSidebarOpen: t, mobileSidebarOpen: n }) {
|
|
702
705
|
return {
|
|
703
706
|
desktopSidebarVisible: !e && !!t,
|
|
704
707
|
mobileDrawerVisible: !!(e && n)
|
|
705
708
|
};
|
|
706
709
|
}
|
|
707
|
-
function
|
|
710
|
+
function Ct({ isMobile: e, viewportHeight: t, desktopMaxHeight: n = 160 }) {
|
|
708
711
|
if (!e) return n;
|
|
709
712
|
let r = Number(t);
|
|
710
713
|
if (!Number.isFinite(r) || r <= 0) return n;
|
|
711
|
-
let i = Math.floor(r *
|
|
714
|
+
let i = Math.floor(r * bt);
|
|
712
715
|
return Math.max(120, Math.min(n, i));
|
|
713
716
|
}
|
|
714
717
|
//#endregion
|
|
715
718
|
//#region src/hooks/useResponsiveViewport.ts
|
|
716
|
-
function
|
|
719
|
+
function wt() {
|
|
717
720
|
return typeof window > "u" ? 900 : Math.round(window.visualViewport?.height || window.innerHeight || 900);
|
|
718
721
|
}
|
|
719
|
-
function
|
|
722
|
+
function Tt() {
|
|
720
723
|
return typeof window > "u" ? {
|
|
721
724
|
isMobile: !1,
|
|
722
725
|
viewportHeight: 900
|
|
723
726
|
} : {
|
|
724
|
-
isMobile:
|
|
725
|
-
viewportHeight:
|
|
727
|
+
isMobile: xt(window.innerWidth, 768),
|
|
728
|
+
viewportHeight: wt()
|
|
726
729
|
};
|
|
727
730
|
}
|
|
728
|
-
function
|
|
729
|
-
let [e, t] =
|
|
731
|
+
function Et() {
|
|
732
|
+
let [e, t] = Ue(() => Tt());
|
|
730
733
|
return J(() => {
|
|
731
734
|
if (typeof window > "u") return;
|
|
732
735
|
let e = window.matchMedia("(max-width: 768px)"), n = () => {
|
|
733
|
-
t(
|
|
736
|
+
t(Tt());
|
|
734
737
|
};
|
|
735
738
|
n();
|
|
736
739
|
let r = typeof e.addEventListener == "function" ? (e.addEventListener("change", n), () => e.removeEventListener("change", n)) : (e.addListener(n), () => e.removeListener(n));
|
|
@@ -741,13 +744,13 @@ function Tt() {
|
|
|
741
744
|
}
|
|
742
745
|
//#endregion
|
|
743
746
|
//#region src/core/stream/responses-protocol.ts
|
|
744
|
-
var
|
|
747
|
+
var Dt = class {
|
|
745
748
|
id = "responses";
|
|
746
749
|
createState() {
|
|
747
|
-
return
|
|
750
|
+
return z();
|
|
748
751
|
}
|
|
749
752
|
parseItemOperations(e, t, n) {
|
|
750
|
-
return
|
|
753
|
+
return j(e.eventName, e.data, t, n);
|
|
751
754
|
}
|
|
752
755
|
parse(e, t) {
|
|
753
756
|
let n = e.data;
|
|
@@ -765,7 +768,7 @@ var Et = class {
|
|
|
765
768
|
}
|
|
766
769
|
}];
|
|
767
770
|
}
|
|
768
|
-
return
|
|
771
|
+
return N({
|
|
769
772
|
eventName: e.eventName,
|
|
770
773
|
data: e.data,
|
|
771
774
|
state: t
|
|
@@ -788,23 +791,23 @@ var Et = class {
|
|
|
788
791
|
};
|
|
789
792
|
//#endregion
|
|
790
793
|
//#region src/utils/stream-parsing.ts
|
|
791
|
-
function
|
|
794
|
+
function Ot(e) {
|
|
792
795
|
return typeof e == "string" ? e : Array.isArray(e) ? e.map((e) => typeof e == "string" ? e : e && typeof e == "object" && "text" in e && typeof e.text == "string" ? e.text : "").join("") : "";
|
|
793
796
|
}
|
|
794
|
-
function
|
|
797
|
+
function kt(e) {
|
|
795
798
|
return e && typeof e == "object" ? e : {};
|
|
796
799
|
}
|
|
797
|
-
function
|
|
798
|
-
let t =
|
|
800
|
+
function At(e) {
|
|
801
|
+
let t = kt(e).choices, n = kt(Array.isArray(t) ? t[0] : null), r = kt(n.delta), i = kt(n.message);
|
|
799
802
|
return {
|
|
800
|
-
content:
|
|
801
|
-
reasoning:
|
|
802
|
-
finalText:
|
|
803
|
+
content: Ot(r.content),
|
|
804
|
+
reasoning: Ot(r.reasoning_content),
|
|
805
|
+
finalText: Ot(i.content)
|
|
803
806
|
};
|
|
804
807
|
}
|
|
805
808
|
//#endregion
|
|
806
809
|
//#region src/core/stream/chat-completions-protocol.ts
|
|
807
|
-
var
|
|
810
|
+
var jt = class {
|
|
808
811
|
id = "chat_completions";
|
|
809
812
|
createState() {
|
|
810
813
|
return {};
|
|
@@ -812,7 +815,7 @@ var At = class {
|
|
|
812
815
|
parse(e) {
|
|
813
816
|
let t = e.data;
|
|
814
817
|
if (typeof t != "object" || !t) return [];
|
|
815
|
-
let n =
|
|
818
|
+
let n = At(t), r = [];
|
|
816
819
|
return n.reasoning && r.push({
|
|
817
820
|
type: "reasoning_delta",
|
|
818
821
|
text: n.reasoning
|
|
@@ -824,14 +827,14 @@ var At = class {
|
|
|
824
827
|
text: n.finalText
|
|
825
828
|
}), r;
|
|
826
829
|
}
|
|
827
|
-
},
|
|
828
|
-
|
|
829
|
-
function
|
|
830
|
-
return
|
|
830
|
+
}, Mt = /* @__PURE__ */ new Map();
|
|
831
|
+
Mt.set("responses", new Dt()), Mt.set("chat_completions", new jt());
|
|
832
|
+
function Nt(e) {
|
|
833
|
+
return Mt.get(e) || Mt.get("responses");
|
|
831
834
|
}
|
|
832
835
|
//#endregion
|
|
833
836
|
//#region src/utils/stream-control.js
|
|
834
|
-
function
|
|
837
|
+
function Pt(e = []) {
|
|
835
838
|
return e.some((e) => {
|
|
836
839
|
if (e?.type !== "terminal") return !1;
|
|
837
840
|
let t = String(e.status || "").toLowerCase();
|
|
@@ -840,7 +843,7 @@ function Nt(e = []) {
|
|
|
840
843
|
}
|
|
841
844
|
//#endregion
|
|
842
845
|
//#region src/core/transport/sse-parser.ts
|
|
843
|
-
function
|
|
846
|
+
function Ft(e) {
|
|
844
847
|
let t = [], n = e.trim();
|
|
845
848
|
if (!n) return t;
|
|
846
849
|
let r = n.split("\n");
|
|
@@ -870,7 +873,7 @@ function Pt(e) {
|
|
|
870
873
|
}
|
|
871
874
|
return t;
|
|
872
875
|
}
|
|
873
|
-
function
|
|
876
|
+
function It(e) {
|
|
874
877
|
let t = e.split("\n\n");
|
|
875
878
|
return {
|
|
876
879
|
chunks: t,
|
|
@@ -879,60 +882,60 @@ function Ft(e) {
|
|
|
879
882
|
}
|
|
880
883
|
//#endregion
|
|
881
884
|
//#region src/utils/error.ts
|
|
882
|
-
function
|
|
885
|
+
function Lt(e) {
|
|
883
886
|
return e instanceof Error ? e.message : String(e);
|
|
884
887
|
}
|
|
885
888
|
//#endregion
|
|
886
889
|
//#region src/utils/model-options.js
|
|
887
|
-
var
|
|
890
|
+
var Rt = new Set([
|
|
888
891
|
"auto",
|
|
889
892
|
"enabled",
|
|
890
893
|
"disabled"
|
|
891
894
|
]);
|
|
892
|
-
function
|
|
895
|
+
function zt(e) {
|
|
893
896
|
let t = String(e || "").trim().toLowerCase();
|
|
894
|
-
return
|
|
897
|
+
return Rt.has(t) ? t : "auto";
|
|
895
898
|
}
|
|
896
|
-
function
|
|
897
|
-
let t =
|
|
899
|
+
function Bt(e) {
|
|
900
|
+
let t = zt(e);
|
|
898
901
|
if (t === "disabled") return { thinking: { type: "disabled" } };
|
|
899
902
|
if (t === "enabled") return { thinking: { type: "enabled" } };
|
|
900
903
|
}
|
|
901
|
-
var
|
|
902
|
-
function
|
|
904
|
+
var Vt = 1280;
|
|
905
|
+
function Ht(e) {
|
|
903
906
|
let { apiFormats: t } = e;
|
|
904
907
|
return t.includes("responses") ? "responses" : t.includes("chat_completions") ? "chat_completions" : "responses";
|
|
905
908
|
}
|
|
906
|
-
function
|
|
907
|
-
let r = Math.min(
|
|
909
|
+
function Ut(e, t, n) {
|
|
910
|
+
let r = Math.min(Vt, Math.max(420, t - n - 360));
|
|
908
911
|
return Math.min(Math.max(e, 420), r);
|
|
909
912
|
}
|
|
910
913
|
//#endregion
|
|
911
914
|
//#region src/core/run/agui.ts
|
|
912
|
-
function
|
|
915
|
+
function Wt(e) {
|
|
913
916
|
return String(e.type || "").toUpperCase();
|
|
914
917
|
}
|
|
915
|
-
function
|
|
918
|
+
function Gt(e, t) {
|
|
916
919
|
return String(e.messageId || t);
|
|
917
920
|
}
|
|
918
|
-
function
|
|
921
|
+
function Kt(e, t) {
|
|
919
922
|
return String(e.runId || t);
|
|
920
923
|
}
|
|
921
|
-
function
|
|
924
|
+
function qt(e) {
|
|
922
925
|
return e && typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
923
926
|
}
|
|
924
|
-
function
|
|
925
|
-
if (Array.isArray(e)) return
|
|
927
|
+
function Jt(e) {
|
|
928
|
+
if (Array.isArray(e)) return te(e.filter((e) => !!(e && typeof e == "object")));
|
|
926
929
|
if (e && typeof e == "object") {
|
|
927
930
|
let t = e.a2ui_operations;
|
|
928
|
-
return Array.isArray(t) ?
|
|
931
|
+
return Array.isArray(t) ? te(t.filter((e) => !!(e && typeof e == "object"))) : [e];
|
|
929
932
|
}
|
|
930
933
|
return [];
|
|
931
934
|
}
|
|
932
|
-
function
|
|
935
|
+
function Yt(e) {
|
|
933
936
|
return e == null || e === "" ? "" : typeof e == "string" ? e : JSON.stringify(e, null, 2);
|
|
934
937
|
}
|
|
935
|
-
var
|
|
938
|
+
var Xt = class {
|
|
936
939
|
agent;
|
|
937
940
|
onEvent;
|
|
938
941
|
tools = /* @__PURE__ */ new Map();
|
|
@@ -946,7 +949,7 @@ var Yt = class {
|
|
|
946
949
|
forwardedProps;
|
|
947
950
|
catalogRegistry;
|
|
948
951
|
constructor(e) {
|
|
949
|
-
this.agent = new
|
|
952
|
+
this.agent = new We({
|
|
950
953
|
url: e.url,
|
|
951
954
|
agentId: e.agentId,
|
|
952
955
|
threadId: e.threadId,
|
|
@@ -954,13 +957,13 @@ var Yt = class {
|
|
|
954
957
|
let r = this.onAdmission, i = await (e.fetch ?? globalThis.fetch)(t, n), a = i.headers.get("X-AgentEngine-AGUI-Command-Id");
|
|
955
958
|
return i.ok && r && r === this.onAdmission && a && r(a), i;
|
|
956
959
|
}
|
|
957
|
-
}), this.onEvent = e.onEvent, this.threadId = e.threadId, this.forwardedProps = e.forwardedProps || {}, this.catalogRegistry = e.a2uiCatalogRegistry ||
|
|
960
|
+
}), this.onEvent = e.onEvent, this.threadId = e.threadId, this.forwardedProps = e.forwardedProps || {}, this.catalogRegistry = e.a2uiCatalogRegistry || A;
|
|
958
961
|
}
|
|
959
|
-
configure(e, t =
|
|
962
|
+
configure(e, t = A) {
|
|
960
963
|
this.forwardedProps = e, this.catalogRegistry = t;
|
|
961
964
|
}
|
|
962
965
|
reconcileInteractions(e) {
|
|
963
|
-
let t = (t) => !e.some((e) => t.metadata?.interaction_v1 === !0 && e.source === "interaction_v1" && e.sessionId === this.threadId && e.interactionId === t.id && e.runId === t.metadata.run_id && e.revision >= Number(t.metadata.revision || 1) &&
|
|
966
|
+
let t = (t) => !e.some((e) => t.metadata?.interaction_v1 === !0 && e.source === "interaction_v1" && e.sessionId === this.threadId && e.interactionId === t.id && e.runId === t.metadata.run_id && e.revision >= Number(t.metadata.revision || 1) && o(e.status));
|
|
964
967
|
this.agent.pendingInterrupts = this.agent.pendingInterrupts.filter(t);
|
|
965
968
|
for (let [e, n] of this.pendingByRun) {
|
|
966
969
|
let r = n.filter(t);
|
|
@@ -987,7 +990,7 @@ var Yt = class {
|
|
|
987
990
|
let n = this.agent.pendingInterrupts.length > 0 ? this.agent.pendingInterrupts : this.pendingByRun.get(this.activeRunId) || [], r = n.length > 0 ? n.filter((e) => e.id === t.interruptId) : [{
|
|
988
991
|
id: t.interruptId,
|
|
989
992
|
reason: "approval"
|
|
990
|
-
}], i =
|
|
993
|
+
}], i = Ge(r, { [t.interruptId]: t.status === "resolved" ? {
|
|
991
994
|
status: "resolved",
|
|
992
995
|
payload: t.payload
|
|
993
996
|
} : { status: "cancelled" } });
|
|
@@ -1010,22 +1013,22 @@ var Yt = class {
|
|
|
1010
1013
|
let t = ++this.executionEpoch, n = this.logicalRunId || e.runId, r = !0, i = /* @__PURE__ */ new Set(), a = (n) => {
|
|
1011
1014
|
if (!r || t !== this.executionEpoch || this.activeRunId !== e.runId || e.abortController?.signal.aborted) return null;
|
|
1012
1015
|
let a = n;
|
|
1013
|
-
if (
|
|
1014
|
-
let o =
|
|
1016
|
+
if (Wt(n) !== "CUSTOM" || a.name !== "ksadk.text_message_snapshot") return null;
|
|
1017
|
+
let o = qt(a.value);
|
|
1015
1018
|
return o.version === 1 && o.threadId === this.threadId && o.runId === e.runId && typeof o.messageId == "string" && i.has(o.messageId) && typeof o.content == "string" ? {
|
|
1016
1019
|
messageId: o.messageId,
|
|
1017
1020
|
content: o.content
|
|
1018
1021
|
} : null;
|
|
1019
1022
|
}, o = "completed", s = !1, c = {
|
|
1020
1023
|
onEvent: ({ event: t, messages: r }) => {
|
|
1021
|
-
|
|
1024
|
+
Wt(t) === "TEXT_MESSAGE_START" && i.add(Gt(t, `${e.runId}:assistant`));
|
|
1022
1025
|
let c = a(t);
|
|
1023
1026
|
if (c && r.some((e) => e.id === c.messageId && e.role === "assistant") && this.onEvent({
|
|
1024
1027
|
type: "text_replace",
|
|
1025
1028
|
messageId: c.messageId,
|
|
1026
1029
|
text: c.content,
|
|
1027
1030
|
sessionId: this.threadId
|
|
1028
|
-
}),
|
|
1031
|
+
}), Wt(t) === "RUN_FINISHED" && (s = !0), Wt(t) === "RUN_ERROR" && t.code === "INPUT_RESPONSE_INVALID") for (let t of e.resume || []) this.onEvent({
|
|
1029
1032
|
type: "interaction_submit_rejected",
|
|
1030
1033
|
interactionId: t.interruptId,
|
|
1031
1034
|
message: "答案未通过 Runtime 校验,请修改后重新提交。"
|
|
@@ -1069,7 +1072,7 @@ var Yt = class {
|
|
|
1069
1072
|
};
|
|
1070
1073
|
}
|
|
1071
1074
|
project(e, t, n = !1, r = t) {
|
|
1072
|
-
let i =
|
|
1075
|
+
let i = Wt(e), a = Kt(e, t), o = Gt(e, `${a}:assistant`), s = e, c = [];
|
|
1073
1076
|
if (i === "RUN_STARTED") c.push({
|
|
1074
1077
|
type: "activity",
|
|
1075
1078
|
phase: "AG-UI 运行已创建",
|
|
@@ -1138,7 +1141,7 @@ var Yt = class {
|
|
|
1138
1141
|
output: String(s.content || "")
|
|
1139
1142
|
});
|
|
1140
1143
|
} else if (i === "CUSTOM" && s.name === "ksadk.session_event") {
|
|
1141
|
-
let e =
|
|
1144
|
+
let e = qt(s.value), t = e.family === "control" && ["mcp.authorization.requested", "mcp.authorization.updated"].includes(String(e.event_type));
|
|
1142
1145
|
(e.family === "interaction" || t) && e.family_version === 1 && e.session_id === this.threadId && typeof e.event_type == "string" && Number.isSafeInteger(e.seq) && c.push({
|
|
1143
1146
|
type: "stream_event",
|
|
1144
1147
|
sessionId: e.session_id,
|
|
@@ -1152,7 +1155,7 @@ var Yt = class {
|
|
|
1152
1155
|
}
|
|
1153
1156
|
});
|
|
1154
1157
|
} else if (i === "ACTIVITY_SNAPSHOT") {
|
|
1155
|
-
let e = s.content, t =
|
|
1158
|
+
let e = s.content, t = qt(e), n = String(t.surfaceId || t.surface_id || s.messageId || "default");
|
|
1156
1159
|
c.push({
|
|
1157
1160
|
type: "agui_activity",
|
|
1158
1161
|
runId: r,
|
|
@@ -1160,17 +1163,17 @@ var Yt = class {
|
|
|
1160
1163
|
...typeof t.interactionId == "string" ? { interactionId: t.interactionId } : {},
|
|
1161
1164
|
messageId: this.runMessageIds.get(a) || o,
|
|
1162
1165
|
surfaceId: n,
|
|
1163
|
-
messages:
|
|
1166
|
+
messages: Jt(t.content ?? e)
|
|
1164
1167
|
});
|
|
1165
1168
|
} else if (i === "RUN_FINISHED") {
|
|
1166
|
-
let e =
|
|
1169
|
+
let e = qt(s.outcome);
|
|
1167
1170
|
if (String(e.type || "").toLowerCase() === "interrupt") {
|
|
1168
1171
|
let t = Array.isArray(e.interrupts) ? e.interrupts : [];
|
|
1169
1172
|
this.pendingByRun.set(a, t);
|
|
1170
1173
|
for (let e of t) {
|
|
1171
|
-
let t =
|
|
1174
|
+
let t = qt(e.metadata);
|
|
1172
1175
|
if (t.interaction_v1 === !0) continue;
|
|
1173
|
-
let n = e.toolCallId ? this.tools.get(e.toolCallId) : void 0, r = String(t.tool_name || t.toolName || n?.name || e.reason || "人工确认"), i =
|
|
1176
|
+
let n = e.toolCallId ? this.tools.get(e.toolCallId) : void 0, r = String(t.tool_name || t.toolName || n?.name || e.reason || "人工确认"), i = Yt(t.arguments ?? t.tool_args ?? t.args ?? n?.args);
|
|
1174
1177
|
c.push({
|
|
1175
1178
|
type: "approval_requested",
|
|
1176
1179
|
messageId: this.runMessageIds.get(a) || `${a}:assistant`,
|
|
@@ -1205,7 +1208,7 @@ var Yt = class {
|
|
|
1205
1208
|
};
|
|
1206
1209
|
return { events: c };
|
|
1207
1210
|
}
|
|
1208
|
-
},
|
|
1211
|
+
}, Zt = new Set([
|
|
1209
1212
|
"completed",
|
|
1210
1213
|
"failed",
|
|
1211
1214
|
"error",
|
|
@@ -1214,7 +1217,7 @@ var Yt = class {
|
|
|
1214
1217
|
"aborted",
|
|
1215
1218
|
"interrupted",
|
|
1216
1219
|
"resume_failed"
|
|
1217
|
-
]),
|
|
1220
|
+
]), Qt = [
|
|
1218
1221
|
0,
|
|
1219
1222
|
500,
|
|
1220
1223
|
1e3,
|
|
@@ -1222,7 +1225,7 @@ var Yt = class {
|
|
|
1222
1225
|
4e3,
|
|
1223
1226
|
8e3
|
|
1224
1227
|
];
|
|
1225
|
-
function
|
|
1228
|
+
function $t(e, t) {
|
|
1226
1229
|
return !e || t.aborted ? Promise.resolve() : new Promise((n) => {
|
|
1227
1230
|
let r = () => {
|
|
1228
1231
|
clearTimeout(i), t.removeEventListener("abort", r), n();
|
|
@@ -1230,7 +1233,7 @@ function Qt(e, t) {
|
|
|
1230
1233
|
t.addEventListener("abort", r, { once: !0 });
|
|
1231
1234
|
});
|
|
1232
1235
|
}
|
|
1233
|
-
function
|
|
1236
|
+
function en(e) {
|
|
1234
1237
|
if (typeof window > "u" || window.navigator.onLine !== !1 || e.aborted) return Promise.resolve();
|
|
1235
1238
|
let t = window;
|
|
1236
1239
|
return new Promise((n) => {
|
|
@@ -1240,12 +1243,12 @@ function $t(e) {
|
|
|
1240
1243
|
t.addEventListener("online", r, { once: !0 }), e.addEventListener("abort", r, { once: !0 });
|
|
1241
1244
|
});
|
|
1242
1245
|
}
|
|
1243
|
-
function
|
|
1246
|
+
function tn(e) {
|
|
1244
1247
|
if (e.Content?.runtime_event?.parent_scope_id) return null;
|
|
1245
|
-
let t =
|
|
1246
|
-
return
|
|
1248
|
+
let t = ie(e);
|
|
1249
|
+
return Zt.has(t) ? t : null;
|
|
1247
1250
|
}
|
|
1248
|
-
function
|
|
1251
|
+
function nn(e, t) {
|
|
1249
1252
|
let n = String(t?.type || e || "").trim();
|
|
1250
1253
|
if (n === "response.created") return {
|
|
1251
1254
|
phase: "运行已创建",
|
|
@@ -1291,11 +1294,11 @@ function tn(e, t) {
|
|
|
1291
1294
|
status: "failed"
|
|
1292
1295
|
} : null;
|
|
1293
1296
|
}
|
|
1294
|
-
function
|
|
1297
|
+
function rn() {
|
|
1295
1298
|
let e = globalThis.crypto;
|
|
1296
1299
|
return e && typeof e.randomUUID == "function" ? `run_${e.randomUUID()}` : `run_${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
1297
1300
|
}
|
|
1298
|
-
var
|
|
1301
|
+
var an = {
|
|
1299
1302
|
idle: [
|
|
1300
1303
|
"creating-session",
|
|
1301
1304
|
"uploading-files",
|
|
@@ -1334,7 +1337,7 @@ var rn = {
|
|
|
1334
1337
|
],
|
|
1335
1338
|
error: ["connecting", "idle"],
|
|
1336
1339
|
cancelled: ["idle"]
|
|
1337
|
-
},
|
|
1340
|
+
}, on = class {
|
|
1338
1341
|
_stage = "idle";
|
|
1339
1342
|
listeners = /* @__PURE__ */ new Set();
|
|
1340
1343
|
abortController = null;
|
|
@@ -1367,18 +1370,18 @@ var rn = {
|
|
|
1367
1370
|
return this.activeSessionId || this.projection.draftId || null;
|
|
1368
1371
|
}
|
|
1369
1372
|
publishInvocation(e) {
|
|
1370
|
-
this.invocationId = e, e &&
|
|
1373
|
+
this.invocationId = e, e && h.getState().updateActivity({
|
|
1371
1374
|
sessionId: this.streamingKey,
|
|
1372
1375
|
runId: e,
|
|
1373
1376
|
countEvent: !1,
|
|
1374
1377
|
visible: this.projection.isVisible?.()
|
|
1375
|
-
}), this.projection.isVisible?.() !== !1 && (
|
|
1378
|
+
}), this.projection.isVisible?.() !== !1 && (h.getState().setCurrentRunId(e), h.getState().setActiveInvocationId(e));
|
|
1376
1379
|
}
|
|
1377
1380
|
recordCursor(e) {
|
|
1378
|
-
this.lastSeqId = e === 0 ? 0 : Math.max(this.lastSeqId, e), this.projection.isVisible?.() !== !1 &&
|
|
1381
|
+
this.lastSeqId = e === 0 ? 0 : Math.max(this.lastSeqId, e), this.projection.isVisible?.() !== !1 && h.getState().setLastSeqId(this.lastSeqId);
|
|
1379
1382
|
}
|
|
1380
1383
|
stopActivity(e) {
|
|
1381
|
-
let t =
|
|
1384
|
+
let t = h.getState(), n = this.projection.isVisible?.() !== !1;
|
|
1382
1385
|
this.streamingKey ? t.stopSessionActivity(this.streamingKey, e, n) : n && t.stopActivity(e);
|
|
1383
1386
|
}
|
|
1384
1387
|
get stage() {
|
|
@@ -1391,9 +1394,9 @@ var rn = {
|
|
|
1391
1394
|
this.lastControlCommand = e;
|
|
1392
1395
|
let t;
|
|
1393
1396
|
try {
|
|
1394
|
-
t =
|
|
1397
|
+
t = u(await this.api.submitControl(e));
|
|
1395
1398
|
} catch (e) {
|
|
1396
|
-
if (e instanceof
|
|
1399
|
+
if (e instanceof f) return this.controlStateValue = {
|
|
1397
1400
|
phase: "contract_mismatch",
|
|
1398
1401
|
error: null,
|
|
1399
1402
|
receipt: null
|
|
@@ -1483,7 +1486,7 @@ var rn = {
|
|
|
1483
1486
|
let t = this.config.aguiResumeTransport || this.config.hostedChatTransport;
|
|
1484
1487
|
if (t?.Protocol !== "ag-ui" || !t.Endpoint) return null;
|
|
1485
1488
|
if (!this.aguiClient || this.aguiThreadSessionId !== e) {
|
|
1486
|
-
let n = new
|
|
1489
|
+
let n = new Xt({
|
|
1487
1490
|
url: t.Endpoint,
|
|
1488
1491
|
agentId: this.config.agentId,
|
|
1489
1492
|
threadId: e,
|
|
@@ -1493,16 +1496,16 @@ var rn = {
|
|
|
1493
1496
|
});
|
|
1494
1497
|
this.aguiClient = n, this.aguiThreadSessionId = e;
|
|
1495
1498
|
}
|
|
1496
|
-
return this.aguiClient.reconcileInteractions(
|
|
1499
|
+
return this.aguiClient.reconcileInteractions(T.listAll(e)), this.aguiClient.configure({
|
|
1497
1500
|
model: this.config.selectedModel || void 0,
|
|
1498
1501
|
modelMetadata: this.config.selectedModelMetadata || void 0,
|
|
1499
|
-
modelOptions: zt(
|
|
1502
|
+
modelOptions: Bt(zt(this.config.thinkingMode)),
|
|
1500
1503
|
toolApprovalMode: this.config.permissionMode || "risk"
|
|
1501
1504
|
}, this.config.a2uiCatalogRegistry), this.aguiClient;
|
|
1502
1505
|
}
|
|
1503
1506
|
setStage(e) {
|
|
1504
1507
|
if (this._stage === e) return;
|
|
1505
|
-
let t =
|
|
1508
|
+
let t = an[this._stage];
|
|
1506
1509
|
t && !t.includes(e) && console.warn(`[RunEngine] Invalid transition: ${this._stage} → ${e}`), this._stage = e, e === "idle" && this.pendingConfig && (this.config = this.pendingConfig, this.pendingConfig = null), this.emit({
|
|
1507
1510
|
type: "stage_changed",
|
|
1508
1511
|
stage: e
|
|
@@ -1531,7 +1534,7 @@ var rn = {
|
|
|
1531
1534
|
try {
|
|
1532
1535
|
if (r ||= await this.createSession(e), !r) throw Error("运行时未返回会话身份,请确认创建结果后重试。");
|
|
1533
1536
|
this.activeSessionId = r;
|
|
1534
|
-
let s =
|
|
1537
|
+
let s = rn();
|
|
1535
1538
|
this.publishInvocation(s), e.onInvocationCreated?.(s), this.recordCursor(0);
|
|
1536
1539
|
let c = n ? null : await this.getConversationBootstrap(r);
|
|
1537
1540
|
if (c && this.config.conversationClient) {
|
|
@@ -1589,10 +1592,10 @@ var rn = {
|
|
|
1589
1592
|
status: "connecting",
|
|
1590
1593
|
countEvent: !1
|
|
1591
1594
|
});
|
|
1592
|
-
let u = n ? "responses" :
|
|
1595
|
+
let u = n ? "responses" : Ht({
|
|
1593
1596
|
agentFramework: this.config.agentFramework,
|
|
1594
1597
|
apiFormats: this.config.apiFormats
|
|
1595
|
-
}), d =
|
|
1598
|
+
}), d = Nt(u), f = d.createState(), p = this.config.hostedChatTransport, m = !n && !e.executionMode && e.attachments.length === 0 && p?.Protocol === "ag-ui" ? this.getAguiClient(r) : null;
|
|
1596
1599
|
if (m && p) {
|
|
1597
1600
|
this.setStage("streaming"), this.emit({
|
|
1598
1601
|
type: "activity",
|
|
@@ -1666,7 +1669,7 @@ var rn = {
|
|
|
1666
1669
|
status: "waiting",
|
|
1667
1670
|
countEvent: !1
|
|
1668
1671
|
});
|
|
1669
|
-
let v = `msg-${Date.now()}`, y = await
|
|
1672
|
+
let v = `msg-${Date.now()}`, y = await ke(_);
|
|
1670
1673
|
if (this.operationEpoch !== t || this.abortController?.signal.aborted) {
|
|
1671
1674
|
i(!1), await y.stream.cancel();
|
|
1672
1675
|
return;
|
|
@@ -1719,7 +1722,7 @@ var rn = {
|
|
|
1719
1722
|
}), this.emit({ type: "stream_ended" });
|
|
1720
1723
|
} catch (n) {
|
|
1721
1724
|
if (this.operationEpoch !== t) return;
|
|
1722
|
-
if (this.failCompaction(), this.abortController?.signal.aborted || n instanceof Z || n instanceof DOMException && n.name === "AbortError" || n instanceof
|
|
1725
|
+
if (this.failCompaction(), this.abortController?.signal.aborted || n instanceof Z || n instanceof DOMException && n.name === "AbortError" || n instanceof me && n.code === "conversation_aborted") a = "cancelled";
|
|
1723
1726
|
else {
|
|
1724
1727
|
let t = n instanceof TypeError;
|
|
1725
1728
|
if (a = t ? "unknown" : "failed", console.error("[RunEngine] start() error:", n), t) {
|
|
@@ -1754,7 +1757,7 @@ var rn = {
|
|
|
1754
1757
|
}));
|
|
1755
1758
|
}
|
|
1756
1759
|
} finally {
|
|
1757
|
-
i(!1), this.operationEpoch === t && (
|
|
1760
|
+
i(!1), this.operationEpoch === t && (h.getState().setSessionStreaming(this.streamingKey, !1), this.setStage("idle"), this.activeCompactionId = null, this.activeSessionId = null, e.onSettled?.(r, a));
|
|
1758
1761
|
}
|
|
1759
1762
|
})(), !0;
|
|
1760
1763
|
}
|
|
@@ -1770,7 +1773,7 @@ var rn = {
|
|
|
1770
1773
|
});
|
|
1771
1774
|
}
|
|
1772
1775
|
disconnect() {
|
|
1773
|
-
this._stage !== "idle" && (this.operationEpoch += 1, this.abortController?.abort(), this.aguiClient?.abort(),
|
|
1776
|
+
this._stage !== "idle" && (this.operationEpoch += 1, this.abortController?.abort(), this.aguiClient?.abort(), h.getState().setSessionStreaming(this.streamingKey, !1), this.projection.isVisible?.() !== !1 && h.getState().clearActivity(), this._stage = "idle", this.activeCompactionId = null, this.activeSessionId = null);
|
|
1774
1777
|
}
|
|
1775
1778
|
async cancelRemote(e) {
|
|
1776
1779
|
try {
|
|
@@ -1793,9 +1796,9 @@ var rn = {
|
|
|
1793
1796
|
});
|
|
1794
1797
|
let i = null;
|
|
1795
1798
|
try {
|
|
1796
|
-
let n = e.reconnect ?
|
|
1799
|
+
let n = e.reconnect ? Qt : [0], a = e.afterSeqId, o = !0;
|
|
1797
1800
|
for (let s of n) {
|
|
1798
|
-
if (await
|
|
1801
|
+
if (await $t(s, t.signal), e.reconnect && await en(t.signal), !r() || t.signal.aborted) return "cancelled";
|
|
1799
1802
|
try {
|
|
1800
1803
|
if (o) try {
|
|
1801
1804
|
i = await this.readRecoveredRunEvents(e, a, t.signal, r, (e) => {
|
|
@@ -1857,7 +1860,7 @@ var rn = {
|
|
|
1857
1860
|
let t = e instanceof DOMException && e.name === "AbortError";
|
|
1858
1861
|
return t || console.error("Failed to subscribe to run events:", e), t ? "cancelled" : "unknown";
|
|
1859
1862
|
} finally {
|
|
1860
|
-
r() && (
|
|
1863
|
+
r() && (h.getState().setSessionStreaming(e.sessionId, !1), this.publishInvocation(""), this.setStage("idle"), this.activeSessionId = null);
|
|
1861
1864
|
}
|
|
1862
1865
|
}
|
|
1863
1866
|
async readRecoveredRunEvents(e, t, n, r, i) {
|
|
@@ -1877,9 +1880,9 @@ var rn = {
|
|
|
1877
1880
|
let { value: u, done: d } = await s.read();
|
|
1878
1881
|
if (d || !r() || n.aborted) break;
|
|
1879
1882
|
l += c.decode(u, { stream: !0 });
|
|
1880
|
-
let { chunks: f, remainder: p } =
|
|
1883
|
+
let { chunks: f, remainder: p } = It(l);
|
|
1881
1884
|
l = p;
|
|
1882
|
-
for (let s of f) for (let { data: c } of
|
|
1885
|
+
for (let s of f) for (let { data: c } of Ft(s)) {
|
|
1883
1886
|
if (!r() || n.aborted) return null;
|
|
1884
1887
|
if (!c || typeof c != "object") continue;
|
|
1885
1888
|
let s = c;
|
|
@@ -1889,7 +1892,7 @@ var rn = {
|
|
|
1889
1892
|
event: s,
|
|
1890
1893
|
sessionId: a
|
|
1891
1894
|
}), s.SeqId && (t = s.SeqId, i(t));
|
|
1892
|
-
let l =
|
|
1895
|
+
let l = tn(s);
|
|
1893
1896
|
if (l) return l;
|
|
1894
1897
|
}
|
|
1895
1898
|
}
|
|
@@ -1900,7 +1903,7 @@ var rn = {
|
|
|
1900
1903
|
}
|
|
1901
1904
|
async readRecoveredRunStatus({ sessionId: e, invocationId: t }, n) {
|
|
1902
1905
|
let r = await this.api.getSession(e, { signal: n }), i = String(r.ActiveRunStatus || "").trim().toLowerCase();
|
|
1903
|
-
if (r.SessionId === e && r.ActiveInvocationId === t &&
|
|
1906
|
+
if (r.SessionId === e && r.ActiveInvocationId === t && Zt.has(i)) return i;
|
|
1904
1907
|
if (n.aborted) return null;
|
|
1905
1908
|
let a = await this.api.listSessionEvents(e, {
|
|
1906
1909
|
eventTypes: [
|
|
@@ -1913,7 +1916,7 @@ var rn = {
|
|
|
1913
1916
|
signal: n
|
|
1914
1917
|
});
|
|
1915
1918
|
for (let n of a.Events) if (n.SessionId === e && n.InvocationId === t) {
|
|
1916
|
-
let e =
|
|
1919
|
+
let e = tn(n);
|
|
1917
1920
|
if (e) return e;
|
|
1918
1921
|
}
|
|
1919
1922
|
return null;
|
|
@@ -1922,7 +1925,7 @@ var rn = {
|
|
|
1922
1925
|
if (this._stage !== "idle") return !1;
|
|
1923
1926
|
let t = ++this.operationEpoch;
|
|
1924
1927
|
this.abortController = new AbortController(), this.activeSessionId = e.sessionId;
|
|
1925
|
-
let n =
|
|
1928
|
+
let n = rn();
|
|
1926
1929
|
return this.publishInvocation(n), (async () => {
|
|
1927
1930
|
let r = "unknown";
|
|
1928
1931
|
try {
|
|
@@ -1956,7 +1959,7 @@ var rn = {
|
|
|
1956
1959
|
checkpointId: e.checkpointId,
|
|
1957
1960
|
resumeAttemptId: e.resumeAttemptId,
|
|
1958
1961
|
invocationId: n
|
|
1959
|
-
}, { signal: this.abortController?.signal }), i =
|
|
1962
|
+
}, { signal: this.abortController?.signal }), i = Nt("responses"), a = i.createState();
|
|
1960
1963
|
this.setStage("streaming"), this.emit({
|
|
1961
1964
|
type: "activity",
|
|
1962
1965
|
source: "restore",
|
|
@@ -2008,7 +2011,7 @@ var rn = {
|
|
|
2008
2011
|
error: e instanceof Error ? e : Error(String(e))
|
|
2009
2012
|
}));
|
|
2010
2013
|
} finally {
|
|
2011
|
-
this.operationEpoch === t && (
|
|
2014
|
+
this.operationEpoch === t && (h.getState().setSessionStreaming(e.sessionId, !1), this.publishInvocation(""), this.setStage("idle"), this.activeSessionId = null, e.onSettled?.(e.sessionId, r));
|
|
2012
2015
|
}
|
|
2013
2016
|
})(), !0;
|
|
2014
2017
|
}
|
|
@@ -2020,7 +2023,7 @@ var rn = {
|
|
|
2020
2023
|
if (!n) return !1;
|
|
2021
2024
|
let r = ++this.operationEpoch;
|
|
2022
2025
|
this.activeSessionId = t;
|
|
2023
|
-
let i =
|
|
2026
|
+
let i = rn();
|
|
2024
2027
|
return this.publishInvocation(i), this.setStage("connecting"), this.emit({
|
|
2025
2028
|
type: "activity",
|
|
2026
2029
|
phase: "提交人工确认",
|
|
@@ -2032,7 +2035,7 @@ var rn = {
|
|
|
2032
2035
|
this.setStage("streaming");
|
|
2033
2036
|
let r = await n.resume(i, {
|
|
2034
2037
|
interruptId: e.interruptId,
|
|
2035
|
-
logicalRunId:
|
|
2038
|
+
logicalRunId: T.get(t, e.interruptId)?.runId || void 0,
|
|
2036
2039
|
status: e.status,
|
|
2037
2040
|
payload: e.payload
|
|
2038
2041
|
}), o = e.payload && typeof e.payload == "object" ? e.payload : {}, s = String(o.decision || o.type || "").toLowerCase(), c = r.pendingInterruptIds?.includes(e.interruptId);
|
|
@@ -2089,7 +2092,7 @@ var rn = {
|
|
|
2089
2092
|
try {
|
|
2090
2093
|
return await t.getSurface(this.config.agentId, e, { signal: this.abortController?.signal });
|
|
2091
2094
|
} catch (e) {
|
|
2092
|
-
if (e instanceof
|
|
2095
|
+
if (e instanceof me && e.code === "conversation_http_error" && e.status === 404) return null;
|
|
2093
2096
|
throw e;
|
|
2094
2097
|
}
|
|
2095
2098
|
}
|
|
@@ -2101,39 +2104,39 @@ var rn = {
|
|
|
2101
2104
|
});
|
|
2102
2105
|
for (let t of r.attachments) {
|
|
2103
2106
|
let n = t.type.startsWith("image/") ? "attachment.image" : "attachment.file";
|
|
2104
|
-
if (!
|
|
2107
|
+
if (!pe(e.surface, n)) throw new me("conversation_input_unsupported", "Conversation attachment is not declared by the active surface.", { capability: n });
|
|
2105
2108
|
}
|
|
2106
2109
|
r.attachments.length > 0 && i.push(...await this.uploadCanonicalAttachments(r.attachments));
|
|
2107
|
-
let o =
|
|
2110
|
+
let o = zt(this.config.thinkingMode), s = he({
|
|
2108
2111
|
inputId: `input:${n}`,
|
|
2109
2112
|
sessionId: t,
|
|
2110
2113
|
idempotencyKey: `conversation:${n}`,
|
|
2111
2114
|
parts: i,
|
|
2112
|
-
...this.config.selectedModel &&
|
|
2113
|
-
...o !== "auto" &&
|
|
2115
|
+
...this.config.selectedModel && pe(e.surface, "model.select") ? { modelRef: this.config.selectedModel } : {},
|
|
2116
|
+
...o !== "auto" && pe(e.surface, "reasoning.effort") ? { reasoning: o } : {},
|
|
2114
2117
|
extensions: {
|
|
2115
|
-
...this.config.permissionMode &&
|
|
2118
|
+
...this.config.permissionMode && pe(e.surface, "approval") ? { "ksadk.approval": this.config.permissionMode } : {},
|
|
2116
2119
|
...r.executionMode === "plan" ? { "ksadk.collaboration": "plan" } : {},
|
|
2117
2120
|
...r.executionMode === "goal" && a ? { "ksadk.goal": a } : {}
|
|
2118
2121
|
}
|
|
2119
2122
|
});
|
|
2120
|
-
return
|
|
2123
|
+
return fe(e.surface, s);
|
|
2121
2124
|
}
|
|
2122
2125
|
async uploadCanonicalAttachments(e) {
|
|
2123
2126
|
this.setStage("uploading-files");
|
|
2124
2127
|
let t = [];
|
|
2125
2128
|
for (let n of e) {
|
|
2126
|
-
if (n.size > 100 * 1024 * 1024) throw new
|
|
2129
|
+
if (n.size > 100 * 1024 * 1024) throw new me("conversation_input_unsupported", "Conversation attachment exceeds the Hosted UI upload limit.", { capability: n.type.startsWith("image/") ? "attachment.image" : "attachment.file" });
|
|
2127
2130
|
let e = new FormData();
|
|
2128
2131
|
e.append("file", n), e.append("AgentId", this.config.agentId);
|
|
2129
2132
|
let r;
|
|
2130
2133
|
try {
|
|
2131
2134
|
r = await this.api.uploadFile(e, { signal: this.abortController?.signal });
|
|
2132
2135
|
} catch (e) {
|
|
2133
|
-
throw new
|
|
2136
|
+
throw new me("conversation_http_error", "Conversation attachment upload failed.", { cause: e });
|
|
2134
2137
|
}
|
|
2135
2138
|
let i = r?.FileData?.fileUri;
|
|
2136
|
-
if (!i) throw new
|
|
2139
|
+
if (!i) throw new me("conversation_contract_mismatch", "Conversation attachment upload did not return an attachment reference.");
|
|
2137
2140
|
t.push({
|
|
2138
2141
|
kind: "attachment",
|
|
2139
2142
|
attachmentRef: i,
|
|
@@ -2164,7 +2167,7 @@ var rn = {
|
|
|
2164
2167
|
} catch (e) {
|
|
2165
2168
|
this.emit({
|
|
2166
2169
|
type: "system_message",
|
|
2167
|
-
content: `【系统提示】图片 ${t.name} 读取失败,原因: ${
|
|
2170
|
+
content: `【系统提示】图片 ${t.name} 读取失败,原因: ${Lt(e)}`
|
|
2168
2171
|
});
|
|
2169
2172
|
}
|
|
2170
2173
|
continue;
|
|
@@ -2181,7 +2184,7 @@ var rn = {
|
|
|
2181
2184
|
} catch (e) {
|
|
2182
2185
|
this.emit({
|
|
2183
2186
|
type: "system_message",
|
|
2184
|
-
content: `【系统提示】文件 ${t.name} 上传失败,原因: ${
|
|
2187
|
+
content: `【系统提示】文件 ${t.name} 上传失败,原因: ${Lt(e)}`
|
|
2185
2188
|
});
|
|
2186
2189
|
}
|
|
2187
2190
|
}
|
|
@@ -2196,8 +2199,8 @@ var rn = {
|
|
|
2196
2199
|
let s = this.buildExecutionMetadata(i), c = this.config.agentFramework.trim().toLowerCase(), l = this.config.hostedChatTransport?.Runtime === "dsh" ? this.config.dshApprovalMode : this.config.permissionMode || "risk", u = {};
|
|
2197
2200
|
this.config.kernelSessionEventsEnabled && this.config.presentationProfile === "agent-block-v1" && (u["ksadk.presentation"] = { profile: "agent-block-v1" });
|
|
2198
2201
|
let d = this.config.mcpAuthorization;
|
|
2199
|
-
c === "langgraph" && d?.schema ===
|
|
2200
|
-
let
|
|
2202
|
+
c === "langgraph" && d?.schema === ae.schema && d.digest === ae.digest && (u["mcp.authorization"] = ae);
|
|
2203
|
+
let f = {
|
|
2201
2204
|
AgentId: this.config.agentId,
|
|
2202
2205
|
SessionId: e,
|
|
2203
2206
|
InvocationId: o,
|
|
@@ -2208,28 +2211,28 @@ var rn = {
|
|
|
2208
2211
|
ApiFormat: n,
|
|
2209
2212
|
Model: this.config.selectedModel || void 0,
|
|
2210
2213
|
...c !== "ksxc" && this.config.selectedModelMetadata ? { ModelMetadata: this.config.selectedModelMetadata } : {},
|
|
2211
|
-
ModelOptions: zt(
|
|
2214
|
+
ModelOptions: Bt(zt(this.config.thinkingMode)),
|
|
2212
2215
|
Metadata: { agentengine: {
|
|
2213
2216
|
...l ? { tool_approval_mode: l } : {},
|
|
2214
|
-
...
|
|
2217
|
+
...p(m.getState().modeFor(this.config.agentId)),
|
|
2215
2218
|
...s
|
|
2216
2219
|
} }
|
|
2217
2220
|
};
|
|
2218
|
-
if (r)
|
|
2221
|
+
if (r) f.ResponsesInput = i.responsesInput, f.PreviousResponseId = i.previousResponseId;
|
|
2219
2222
|
else {
|
|
2220
2223
|
let e = [{
|
|
2221
2224
|
type: "input_text",
|
|
2222
2225
|
text: i.text.trim()
|
|
2223
2226
|
}];
|
|
2224
|
-
e.push(...a), n === "responses" && (
|
|
2227
|
+
e.push(...a), n === "responses" && (f.ResponsesInput = [{
|
|
2225
2228
|
role: "user",
|
|
2226
2229
|
content: e
|
|
2227
|
-
}]),
|
|
2230
|
+
}]), f.Messages = [{
|
|
2228
2231
|
role: "user",
|
|
2229
2232
|
content: e
|
|
2230
2233
|
}];
|
|
2231
2234
|
}
|
|
2232
|
-
return
|
|
2235
|
+
return f;
|
|
2233
2236
|
}
|
|
2234
2237
|
buildExecutionMetadata(e) {
|
|
2235
2238
|
let t = e.executionMode;
|
|
@@ -2264,7 +2267,7 @@ var rn = {
|
|
|
2264
2267
|
status: "running",
|
|
2265
2268
|
countEvent: !1
|
|
2266
2269
|
});
|
|
2267
|
-
let a = new
|
|
2270
|
+
let a = new Fe(e), o = r === "agent-block-v1" && t.presentationProfile === "agent-block-v1" ? "agent-block-v1" : "flat-v1", s = new _e(e, void 0, o), c = this.config.kernelCommandEventsEnabled && t.commandId || void 0;
|
|
2268
2271
|
if (this.config.kernelCommandEventsEnabled && !c) return this.emit({
|
|
2269
2272
|
type: "error",
|
|
2270
2273
|
error: /* @__PURE__ */ Error("运行回执缺少命令身份,无法安全订阅本轮输出。")
|
|
@@ -2276,7 +2279,7 @@ var rn = {
|
|
|
2276
2279
|
let r;
|
|
2277
2280
|
try {
|
|
2278
2281
|
let h = this.abortController?.signal;
|
|
2279
|
-
if (h && i && await
|
|
2282
|
+
if (h && i && await en(h), h?.aborted) return { terminalStatus: "cancelled" };
|
|
2280
2283
|
let g = this.lastSeqId, _ = await this.api.subscribeSessionEvents(e, g, {
|
|
2281
2284
|
signal: h,
|
|
2282
2285
|
...c ? { commandId: c } : {}
|
|
@@ -2287,9 +2290,9 @@ var rn = {
|
|
|
2287
2290
|
let { value: c, done: f } = await r.read();
|
|
2288
2291
|
if (f) break;
|
|
2289
2292
|
y += v.decode(c, { stream: !0 });
|
|
2290
|
-
let h =
|
|
2293
|
+
let h = It(y);
|
|
2291
2294
|
y = h.remainder;
|
|
2292
|
-
for (let r of h.chunks) if (r.trim()) for (let c of
|
|
2295
|
+
for (let r of h.chunks) if (r.trim()) for (let c of Ft(r)) {
|
|
2293
2296
|
p && (c.eventName === "__ping__" || c.data && typeof c.data == "object") && (p = !1, this.emit({
|
|
2294
2297
|
type: "activity",
|
|
2295
2298
|
phase: "正在处理",
|
|
@@ -2325,7 +2328,7 @@ var rn = {
|
|
|
2325
2328
|
sessionId: e,
|
|
2326
2329
|
result: {
|
|
2327
2330
|
state: t,
|
|
2328
|
-
presentation:
|
|
2331
|
+
presentation: ge(t, { profile: o }),
|
|
2329
2332
|
runId: u,
|
|
2330
2333
|
cursor: this.lastSeqId
|
|
2331
2334
|
},
|
|
@@ -2340,7 +2343,7 @@ var rn = {
|
|
|
2340
2343
|
sessionId: e
|
|
2341
2344
|
}), g.EventType === "run_status")) {
|
|
2342
2345
|
let e = String(g.Content?.status || "").toLowerCase();
|
|
2343
|
-
e !== "interrupted" &&
|
|
2346
|
+
e !== "interrupted" && Zt.has(e) && (d = e);
|
|
2344
2347
|
}
|
|
2345
2348
|
}
|
|
2346
2349
|
}
|
|
@@ -2389,32 +2392,32 @@ var rn = {
|
|
|
2389
2392
|
messageId: r,
|
|
2390
2393
|
invocationId: i
|
|
2391
2394
|
})), s += o.decode(e, { stream: !0 });
|
|
2392
|
-
let { chunks: m, remainder: h } =
|
|
2395
|
+
let { chunks: m, remainder: h } = It(s);
|
|
2393
2396
|
s = h;
|
|
2394
2397
|
for (let e of m) {
|
|
2395
2398
|
if (!e.trim()) continue;
|
|
2396
2399
|
if (this.isCompactionChunk(e)) {
|
|
2397
|
-
let t =
|
|
2400
|
+
let t = Ft(e);
|
|
2398
2401
|
for (let e of t) e.eventName.startsWith("response.compaction") && this.upsertCompactionMessage({
|
|
2399
2402
|
...e.data,
|
|
2400
2403
|
phase: e.eventName.split(".").pop()
|
|
2401
2404
|
});
|
|
2402
2405
|
continue;
|
|
2403
2406
|
}
|
|
2404
|
-
let i =
|
|
2407
|
+
let i = Ft(e), o = !1;
|
|
2405
2408
|
for (let e of i) {
|
|
2406
2409
|
if (e.eventName === "__done__") {
|
|
2407
2410
|
o = !0;
|
|
2408
2411
|
continue;
|
|
2409
2412
|
}
|
|
2410
|
-
let i =
|
|
2413
|
+
let i = nn(e.eventName, e.data);
|
|
2411
2414
|
i && !(d.size > 0 && (e.eventName === "response.incomplete" || e.data?.type === "response.incomplete")) && this.emit({
|
|
2412
2415
|
type: "activity",
|
|
2413
2416
|
...i
|
|
2414
2417
|
});
|
|
2415
2418
|
let a = t.parse(e, n);
|
|
2416
2419
|
for (let e of a) e.type === "approval_request" && d.add(e.approvalRequestId), e.type === "canonical_interaction" && d.add(e.interactionId), e.type === "approval_resolved" && d.delete(e.approvalRequestId), this.dispatchAction(e, r), e.type === "terminal" && (u = e.status);
|
|
2417
|
-
if (
|
|
2420
|
+
if (Pt(a)) {
|
|
2418
2421
|
o = !0;
|
|
2419
2422
|
let e = a.find((e) => e.type === "terminal");
|
|
2420
2423
|
u = e && "status" in e ? String(e.status || "") : void 0;
|
|
@@ -2585,12 +2588,12 @@ var rn = {
|
|
|
2585
2588
|
};
|
|
2586
2589
|
//#endregion
|
|
2587
2590
|
//#region src/utils/recovered-run.ts
|
|
2588
|
-
function
|
|
2589
|
-
let r = e.filter((e) => e.role === "model" && e.invocationId === n), i =
|
|
2591
|
+
function sn(e, t, n) {
|
|
2592
|
+
let r = e.filter((e) => e.role === "model" && e.invocationId === n), i = L(t).filter((e) => e.role === "model"), a = i.map((e) => ({
|
|
2590
2593
|
...e,
|
|
2591
2594
|
id: !e.itemId && i.length === 1 ? r[0]?.id || `${n}:assistant` : e.id,
|
|
2592
2595
|
invocationId: n,
|
|
2593
|
-
blocks:
|
|
2596
|
+
blocks: Ie({
|
|
2594
2597
|
content: e.content,
|
|
2595
2598
|
reasoning: e.reasoning,
|
|
2596
2599
|
reasoningSource: e.reasoningSource,
|
|
@@ -2607,25 +2610,25 @@ function on(e, t, n) {
|
|
|
2607
2610
|
}
|
|
2608
2611
|
//#endregion
|
|
2609
2612
|
//#region src/core/run/dispatcher.ts
|
|
2610
|
-
var
|
|
2611
|
-
function
|
|
2613
|
+
var cn = "连接断开或生成出错,请重试";
|
|
2614
|
+
function ln(e, t, n) {
|
|
2612
2615
|
let r = e.tools?.[t];
|
|
2613
2616
|
return r?.callId ? n ? r.callId === n ? t : n : Object.entries(e.tools ?? {}).findLast(([, e]) => e.name === t)?.[0] ?? t : t;
|
|
2614
2617
|
}
|
|
2615
|
-
function
|
|
2618
|
+
function un(e) {
|
|
2616
2619
|
let t = String(e.message || "").trim();
|
|
2617
|
-
return /runtime agent kernel is not ready/i.test(t) ? "云端运行时尚未就绪,请检查部署状态后重试" : !t || /failed to fetch|networkerror/i.test(t) ?
|
|
2620
|
+
return /runtime agent kernel is not ready/i.test(t) ? "云端运行时尚未就绪,请检查部署状态后重试" : !t || /failed to fetch|networkerror/i.test(t) ? cn : t.length <= 240 ? t : cn;
|
|
2618
2621
|
}
|
|
2619
|
-
var
|
|
2622
|
+
var dn = new Set(["completed"]), fn = new Set([
|
|
2620
2623
|
"failed",
|
|
2621
2624
|
"error",
|
|
2622
2625
|
"cancelled",
|
|
2623
2626
|
"canceled",
|
|
2624
2627
|
"aborted",
|
|
2625
2628
|
"incomplete"
|
|
2626
|
-
]),
|
|
2627
|
-
function
|
|
2628
|
-
|
|
2629
|
+
]), pn = /* @__PURE__ */ new Map();
|
|
2630
|
+
function mn(e, t) {
|
|
2631
|
+
G.getState().patchMessages((n) => {
|
|
2629
2632
|
if (n.some((t) => t.id === e)) return t ? n.map((n) => n.id === e ? {
|
|
2630
2633
|
...n,
|
|
2631
2634
|
invocationId: t
|
|
@@ -2650,12 +2653,12 @@ function pn(e, t) {
|
|
|
2650
2653
|
}];
|
|
2651
2654
|
});
|
|
2652
2655
|
}
|
|
2653
|
-
function
|
|
2656
|
+
function hn(e) {
|
|
2654
2657
|
return e.filter((e) => e.eventType !== "optimistic_assistant_placeholder");
|
|
2655
2658
|
}
|
|
2656
|
-
function
|
|
2657
|
-
let t = String(e || "").trim().toLowerCase(), n =
|
|
2658
|
-
n &&
|
|
2659
|
+
function gn(e) {
|
|
2660
|
+
let t = String(e || "").trim().toLowerCase(), n = dn.has(t) ? "completed" : fn.has(t) ? "error" : null;
|
|
2661
|
+
n && G.getState().patchMessages((e) => e.map((e) => {
|
|
2659
2662
|
if (!e.tools) return e;
|
|
2660
2663
|
let t = !1, r = Object.fromEntries(Object.entries(e.tools).map(([e, r]) => r.status === "running" ? (t = !0, [e, {
|
|
2661
2664
|
...r,
|
|
@@ -2667,12 +2670,12 @@ function hn(e) {
|
|
|
2667
2670
|
} : e;
|
|
2668
2671
|
}));
|
|
2669
2672
|
}
|
|
2670
|
-
function
|
|
2673
|
+
function _n(e, t) {
|
|
2671
2674
|
!e.sessionId && t?.draftId && (e = {
|
|
2672
2675
|
...e,
|
|
2673
2676
|
sessionId: t.draftId
|
|
2674
2677
|
});
|
|
2675
|
-
let n = t ? !t.visible : !!(e.sessionId &&
|
|
2678
|
+
let n = t ? !t.visible : !!(e.sessionId && c.getState().currentSessionId !== e.sessionId);
|
|
2676
2679
|
if (n && ![
|
|
2677
2680
|
"activity",
|
|
2678
2681
|
"stage_changed",
|
|
@@ -2686,12 +2689,12 @@ function gn(e, t) {
|
|
|
2686
2689
|
"stream_event",
|
|
2687
2690
|
"conversation_snapshot"
|
|
2688
2691
|
].includes(e.type)) return;
|
|
2689
|
-
let r =
|
|
2690
|
-
e &&
|
|
2692
|
+
let r = G.getState(), i = (e) => {
|
|
2693
|
+
e && h.getState().updateActivity({ sessionId: e });
|
|
2691
2694
|
};
|
|
2692
2695
|
switch (e.type) {
|
|
2693
2696
|
case "activity":
|
|
2694
|
-
|
|
2697
|
+
h.getState().updateActivity({
|
|
2695
2698
|
sessionId: e.sessionId,
|
|
2696
2699
|
visible: !n,
|
|
2697
2700
|
source: e.source,
|
|
@@ -2702,7 +2705,7 @@ function gn(e, t) {
|
|
|
2702
2705
|
});
|
|
2703
2706
|
break;
|
|
2704
2707
|
case "user_message_added":
|
|
2705
|
-
|
|
2708
|
+
h.getState().setBanner(null), r.patchMessages((t) => [...t, {
|
|
2706
2709
|
id: e.messageId,
|
|
2707
2710
|
role: "user",
|
|
2708
2711
|
content: "",
|
|
@@ -2710,45 +2713,45 @@ function gn(e, t) {
|
|
|
2710
2713
|
}]);
|
|
2711
2714
|
break;
|
|
2712
2715
|
case "assistant_message_created":
|
|
2713
|
-
|
|
2716
|
+
mn(e.messageId, e.invocationId);
|
|
2714
2717
|
break;
|
|
2715
2718
|
case "text_delta":
|
|
2716
|
-
|
|
2719
|
+
mn(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => t.id === e.messageId ? {
|
|
2717
2720
|
...t,
|
|
2718
2721
|
content: t.content + e.delta,
|
|
2719
|
-
blocks:
|
|
2722
|
+
blocks: Se(t.blocks, e.delta)
|
|
2720
2723
|
} : t));
|
|
2721
2724
|
break;
|
|
2722
2725
|
case "text_replace":
|
|
2723
|
-
if (e.sessionId &&
|
|
2726
|
+
if (e.sessionId && c.getState().currentSessionId && e.sessionId !== c.getState().currentSessionId && e.sessionId !== t?.draftId) break;
|
|
2724
2727
|
r.patchMessages((t) => t.map((t) => t.id === e.messageId && t.role === "model" ? {
|
|
2725
2728
|
...t,
|
|
2726
2729
|
content: e.text,
|
|
2727
|
-
blocks:
|
|
2730
|
+
blocks: Re(t.blocks, e.text)
|
|
2728
2731
|
} : t)), i(e.sessionId);
|
|
2729
2732
|
break;
|
|
2730
2733
|
case "text_final":
|
|
2731
|
-
|
|
2732
|
-
let n = !!(e.text && !t.content && t.reasoning?.endsWith(e.text)), r = n ? t.reasoning.slice(0, -e.text.length) : t.reasoning, i = n ?
|
|
2734
|
+
mn(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => t.id === e.messageId ? (() => {
|
|
2735
|
+
let n = !!(e.text && !t.content && t.reasoning?.endsWith(e.text)), r = n ? t.reasoning.slice(0, -e.text.length) : t.reasoning, i = n ? Ee(t.blocks, e.text) : t.blocks;
|
|
2733
2736
|
return {
|
|
2734
2737
|
...t,
|
|
2735
2738
|
reasoning: r,
|
|
2736
2739
|
content: e.text,
|
|
2737
|
-
blocks:
|
|
2740
|
+
blocks: we(i, e.text)
|
|
2738
2741
|
};
|
|
2739
2742
|
})() : t));
|
|
2740
2743
|
break;
|
|
2741
2744
|
case "reasoning_delta":
|
|
2742
|
-
|
|
2745
|
+
mn(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => t.id === e.messageId ? {
|
|
2743
2746
|
...t,
|
|
2744
2747
|
reasoning: (t.reasoning || "") + e.delta,
|
|
2745
|
-
blocks:
|
|
2748
|
+
blocks: Ne(t.blocks, e.delta, e.itemId)
|
|
2746
2749
|
} : t));
|
|
2747
2750
|
break;
|
|
2748
2751
|
case "reasoning_snapshot":
|
|
2749
2752
|
r.patchMessages((t) => t.map((t) => {
|
|
2750
2753
|
if (t.id !== e.messageId || !t.blocks) return t;
|
|
2751
|
-
let n =
|
|
2754
|
+
let n = Te(t.blocks, e.itemId, e.text);
|
|
2752
2755
|
return {
|
|
2753
2756
|
...t,
|
|
2754
2757
|
blocks: n,
|
|
@@ -2757,15 +2760,15 @@ function gn(e, t) {
|
|
|
2757
2760
|
}));
|
|
2758
2761
|
break;
|
|
2759
2762
|
case "tool_upsert":
|
|
2760
|
-
|
|
2763
|
+
mn(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => {
|
|
2761
2764
|
if (t.id !== e.messageId) return t;
|
|
2762
|
-
let n =
|
|
2765
|
+
let n = ln(t, e.name, e.callId), r = t.tools?.[n], i = e.callId ? {
|
|
2763
2766
|
...e.extra,
|
|
2764
2767
|
callId: e.callId
|
|
2765
2768
|
} : e.extra, a = r?.approvalStatus === "approved" || r?.approvalStatus === "rejected" || r?.approvalStatus === "cancelled", o = e.status, s = r?.approvalStatus === "rejected" || r?.approvalStatus === "cancelled" ? "completed" : r?.status === "error" && o !== "error" ? "error" : o;
|
|
2766
2769
|
return {
|
|
2767
2770
|
...t,
|
|
2768
|
-
blocks:
|
|
2771
|
+
blocks: Pe(t.blocks, e.name, {
|
|
2769
2772
|
args: e.args,
|
|
2770
2773
|
status: s,
|
|
2771
2774
|
extra: i
|
|
@@ -2788,12 +2791,12 @@ function gn(e, t) {
|
|
|
2788
2791
|
}));
|
|
2789
2792
|
break;
|
|
2790
2793
|
case "tool_result":
|
|
2791
|
-
|
|
2794
|
+
mn(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => {
|
|
2792
2795
|
if (t.id !== e.messageId) return t;
|
|
2793
|
-
let n = F(e.output) ? "error" : "completed", r =
|
|
2796
|
+
let n = F(e.output) ? "error" : "completed", r = ln(t, e.name, e.callId);
|
|
2794
2797
|
return {
|
|
2795
2798
|
...t,
|
|
2796
|
-
blocks:
|
|
2799
|
+
blocks: Pe(t.blocks, e.name, {
|
|
2797
2800
|
output: e.output,
|
|
2798
2801
|
status: n,
|
|
2799
2802
|
...e.callId && { extra: { callId: e.callId } }
|
|
@@ -2814,7 +2817,7 @@ function gn(e, t) {
|
|
|
2814
2817
|
}));
|
|
2815
2818
|
break;
|
|
2816
2819
|
case "approval_requested":
|
|
2817
|
-
if (
|
|
2820
|
+
if (w({
|
|
2818
2821
|
approvalRequestId: e.approvalRequestId,
|
|
2819
2822
|
protocol: e.protocol,
|
|
2820
2823
|
requestSchema: e.requestSchema,
|
|
@@ -2826,7 +2829,7 @@ function gn(e, t) {
|
|
|
2826
2829
|
previousResponseId: e.previousResponseId,
|
|
2827
2830
|
sessionId: e.sessionId
|
|
2828
2831
|
}), n) break;
|
|
2829
|
-
|
|
2832
|
+
mn(e.messageId), r.patchMessages((t) => t.map((t) => {
|
|
2830
2833
|
if (t.id !== e.messageId) return t;
|
|
2831
2834
|
let n = t.tools?.[e.approvalRequestId], r = n?.approvalStatus === "approved" || n?.approvalStatus === "rejected" || n?.approvalStatus === "cancelled", i = {
|
|
2832
2835
|
approvalRequestId: e.approvalRequestId,
|
|
@@ -2838,7 +2841,7 @@ function gn(e, t) {
|
|
|
2838
2841
|
}, a = r ? n.status : "paused";
|
|
2839
2842
|
return {
|
|
2840
2843
|
...t,
|
|
2841
|
-
blocks:
|
|
2844
|
+
blocks: Pe(t.blocks, e.name, {
|
|
2842
2845
|
args: e.args,
|
|
2843
2846
|
status: a,
|
|
2844
2847
|
extra: i
|
|
@@ -2857,7 +2860,7 @@ function gn(e, t) {
|
|
|
2857
2860
|
}));
|
|
2858
2861
|
break;
|
|
2859
2862
|
case "interaction_submit_rejected":
|
|
2860
|
-
|
|
2863
|
+
b(e);
|
|
2861
2864
|
break;
|
|
2862
2865
|
case "question_requested":
|
|
2863
2866
|
k({
|
|
@@ -2868,7 +2871,7 @@ function gn(e, t) {
|
|
|
2868
2871
|
});
|
|
2869
2872
|
break;
|
|
2870
2873
|
case "question_resolved":
|
|
2871
|
-
|
|
2874
|
+
x({
|
|
2872
2875
|
questionId: e.questionId,
|
|
2873
2876
|
answers: e.answers,
|
|
2874
2877
|
revision: e.revision,
|
|
@@ -2921,7 +2924,7 @@ function gn(e, t) {
|
|
|
2921
2924
|
}]);
|
|
2922
2925
|
break;
|
|
2923
2926
|
case "compaction": {
|
|
2924
|
-
let t = `compaction-${Date.now()}`, n = e.phase === "start" ? "running" : e.phase === "failed" ? "failed" : "completed", i =
|
|
2927
|
+
let t = `compaction-${Date.now()}`, n = e.phase === "start" ? "running" : e.phase === "failed" ? "failed" : "completed", i = R({
|
|
2925
2928
|
id: t,
|
|
2926
2929
|
timestamp: Date.now(),
|
|
2927
2930
|
status: n,
|
|
@@ -2935,34 +2938,34 @@ function gn(e, t) {
|
|
|
2935
2938
|
break;
|
|
2936
2939
|
}
|
|
2937
2940
|
case "stage_changed":
|
|
2938
|
-
e.stage === "streaming" || e.stage === "connecting" ?
|
|
2941
|
+
e.stage === "streaming" || e.stage === "connecting" ? h.getState().setSessionStreaming(e.sessionId, !0) : (e.stage === "completing" || e.stage === "error" || e.stage === "cancelled") && h.getState().setSessionStreaming(e.sessionId, !1);
|
|
2939
2942
|
break;
|
|
2940
2943
|
case "stream_ended":
|
|
2941
|
-
|
|
2944
|
+
h.getState().setSessionStreaming(e.sessionId, !1), n || G.getState().patchMessages((t) => hn(t).map((t) => !(!e.runId || t.runId === e.runId || t.invocationId === e.runId) || t.role !== "model" || !t.blocks?.some((e) => e.status === "streaming") ? t : {
|
|
2942
2945
|
...t,
|
|
2943
|
-
blocks:
|
|
2946
|
+
blocks: Ae(t.blocks.map((e) => e.type === "text" && e.status === "streaming" ? {
|
|
2944
2947
|
...e,
|
|
2945
2948
|
status: "done"
|
|
2946
2949
|
} : e))
|
|
2947
2950
|
})), globalThis.setTimeout(() => {
|
|
2948
|
-
let t =
|
|
2951
|
+
let t = h.getState();
|
|
2949
2952
|
t.getSessionActivity(e.sessionId)?.status === "completed" && t.clearSessionActivity(e.sessionId);
|
|
2950
2953
|
}, 2400);
|
|
2951
2954
|
break;
|
|
2952
2955
|
case "error": {
|
|
2953
|
-
let t =
|
|
2954
|
-
|
|
2956
|
+
let t = un(e.error);
|
|
2957
|
+
h.getState().setSessionStreaming(e.sessionId, !1), h.getState().updateActivity({
|
|
2955
2958
|
sessionId: e.sessionId,
|
|
2956
2959
|
visible: !n,
|
|
2957
2960
|
status: "failed",
|
|
2958
2961
|
phase: "运行失败",
|
|
2959
2962
|
detail: t,
|
|
2960
2963
|
countEvent: !1
|
|
2961
|
-
}), n || (
|
|
2964
|
+
}), n || (h.getState().setBanner({
|
|
2962
2965
|
kind: "error",
|
|
2963
2966
|
message: t,
|
|
2964
2967
|
sessionId: e.sessionId
|
|
2965
|
-
}), r.patchMessages((e) => [...
|
|
2968
|
+
}), r.patchMessages((e) => [...hn(e), {
|
|
2966
2969
|
id: String(Date.now()),
|
|
2967
2970
|
role: "model",
|
|
2968
2971
|
content: `运行失败:${t}`,
|
|
@@ -2971,51 +2974,51 @@ function gn(e, t) {
|
|
|
2971
2974
|
break;
|
|
2972
2975
|
}
|
|
2973
2976
|
case "rate_limited":
|
|
2974
|
-
|
|
2977
|
+
h.getState().setSessionStreaming(e.sessionId, !1), h.getState().updateActivity({
|
|
2975
2978
|
sessionId: e.sessionId,
|
|
2976
2979
|
visible: !n,
|
|
2977
2980
|
status: "failed",
|
|
2978
2981
|
phase: "请求被限流",
|
|
2979
2982
|
countEvent: !1
|
|
2980
|
-
}), n || (
|
|
2983
|
+
}), n || (h.getState().setBanner({
|
|
2981
2984
|
kind: "rate_limited",
|
|
2982
2985
|
message: e.message || "请求过于频繁,请稍后重试",
|
|
2983
2986
|
retryAfterSec: e.retryAfterSec,
|
|
2984
2987
|
sessionId: e.sessionId
|
|
2985
|
-
}), r.patchMessages(
|
|
2988
|
+
}), r.patchMessages(hn));
|
|
2986
2989
|
break;
|
|
2987
2990
|
case "terminal":
|
|
2988
|
-
e.sessionId && String(e.status || "").trim().toLowerCase() !== "incomplete" &&
|
|
2991
|
+
e.sessionId && String(e.status || "").trim().toLowerCase() !== "incomplete" && T.markSessionTerminal(e.sessionId), n || gn(e.status);
|
|
2989
2992
|
break;
|
|
2990
2993
|
case "stream_event": {
|
|
2991
2994
|
let t = e.sessionId || e.event.SessionId;
|
|
2992
|
-
|
|
2995
|
+
S(e.event, t || void 0);
|
|
2993
2996
|
let r = e.event.SeqId;
|
|
2994
|
-
!n && typeof r == "number" && r > 0 &&
|
|
2997
|
+
!n && typeof r == "number" && r > 0 && h.getState().setLastSeqId(r), t && h.getState().updateActivity({
|
|
2995
2998
|
sessionId: t,
|
|
2996
2999
|
visible: !n
|
|
2997
3000
|
});
|
|
2998
3001
|
let i = String(e.event.InvocationId || "").trim();
|
|
2999
3002
|
if (!n && t && i) {
|
|
3000
|
-
let n = `${t}:${i}`, r =
|
|
3001
|
-
|
|
3003
|
+
let n = `${t}:${i}`, r = re(pn.get(n) || [], [e.event]);
|
|
3004
|
+
pn.set(n, r), G.getState().patchMessages((e) => e.some((e) => e.eventType === "conversation_item_v1" && e.runId === i) ? e : sn(e, r, i)), ne(e.event) && pn.delete(n);
|
|
3002
3005
|
}
|
|
3003
|
-
e.event.EventType === "run_checkpoint" && t &&
|
|
3006
|
+
e.event.EventType === "run_checkpoint" && t && H.getState().upsertSessionCheckpoint(t, e.event);
|
|
3004
3007
|
{
|
|
3005
|
-
let r =
|
|
3006
|
-
r === "completed" ?
|
|
3008
|
+
let r = ie(e.event);
|
|
3009
|
+
r === "completed" ? h.getState().updateActivity({
|
|
3007
3010
|
sessionId: t,
|
|
3008
3011
|
visible: !n,
|
|
3009
3012
|
status: "completed",
|
|
3010
3013
|
phase: "后台长任务已完成",
|
|
3011
3014
|
countEvent: !1
|
|
3012
|
-
}) : r === "cancelled" || r === "canceled" || r === "aborted" ?
|
|
3015
|
+
}) : r === "cancelled" || r === "canceled" || r === "aborted" ? h.getState().updateActivity({
|
|
3013
3016
|
sessionId: t,
|
|
3014
3017
|
visible: !n,
|
|
3015
3018
|
status: "stopped",
|
|
3016
3019
|
phase: "后台长任务已取消",
|
|
3017
3020
|
countEvent: !1
|
|
3018
|
-
}) : (r === "failed" || r === "error") &&
|
|
3021
|
+
}) : (r === "failed" || r === "error") && h.getState().updateActivity({
|
|
3019
3022
|
sessionId: t,
|
|
3020
3023
|
visible: !n,
|
|
3021
3024
|
status: "failed",
|
|
@@ -3026,15 +3029,15 @@ function gn(e, t) {
|
|
|
3026
3029
|
break;
|
|
3027
3030
|
}
|
|
3028
3031
|
case "conversation_snapshot": {
|
|
3029
|
-
let t =
|
|
3030
|
-
for (let e of t.interactions)
|
|
3032
|
+
let t = Oe(e.result);
|
|
3033
|
+
for (let e of t.interactions) T.upsert(e);
|
|
3031
3034
|
if (n) break;
|
|
3032
|
-
r.patchMessages((t) =>
|
|
3035
|
+
r.patchMessages((t) => je(t, e.result, e.optimisticMessageId, e.replacesInvocationId)), i(e.sessionId);
|
|
3033
3036
|
break;
|
|
3034
3037
|
}
|
|
3035
3038
|
case "a2ui_surface_begin": {
|
|
3036
3039
|
let t = `a2ui-${e.surfaceId}`;
|
|
3037
|
-
|
|
3040
|
+
G.getState().patchMessages((n) => [...n.filter((e) => e.id !== t), {
|
|
3038
3041
|
id: t,
|
|
3039
3042
|
role: "a2ui",
|
|
3040
3043
|
content: "",
|
|
@@ -3048,7 +3051,7 @@ function gn(e, t) {
|
|
|
3048
3051
|
}
|
|
3049
3052
|
case "a2ui_surface_update": {
|
|
3050
3053
|
let t = `a2ui-${e.surfaceId}`;
|
|
3051
|
-
|
|
3054
|
+
G.getState().patchMessages((n) => n.map((n) => n.id === t && n.a2ui ? {
|
|
3052
3055
|
...n,
|
|
3053
3056
|
a2ui: {
|
|
3054
3057
|
...n.a2ui,
|
|
@@ -3059,7 +3062,7 @@ function gn(e, t) {
|
|
|
3059
3062
|
}
|
|
3060
3063
|
case "a2ui_surface_end": {
|
|
3061
3064
|
let t = `a2ui-${e.surfaceId}`;
|
|
3062
|
-
|
|
3065
|
+
G.getState().patchMessages((e) => e.map((e) => e.id === t && e.a2ui ? {
|
|
3063
3066
|
...e,
|
|
3064
3067
|
a2ui: {
|
|
3065
3068
|
...e.a2ui,
|
|
@@ -3070,7 +3073,7 @@ function gn(e, t) {
|
|
|
3070
3073
|
}
|
|
3071
3074
|
case "a2ui_interaction": {
|
|
3072
3075
|
let t = `a2ui-${e.surfaceId}`;
|
|
3073
|
-
|
|
3076
|
+
G.getState().patchMessages((n) => n.map((n) => n.id === t && n.a2ui ? {
|
|
3074
3077
|
...n,
|
|
3075
3078
|
a2ui: {
|
|
3076
3079
|
...n.a2ui,
|
|
@@ -3084,7 +3087,7 @@ function gn(e, t) {
|
|
|
3084
3087
|
break;
|
|
3085
3088
|
}
|
|
3086
3089
|
case "agui_activity":
|
|
3087
|
-
|
|
3090
|
+
G.getState().patchMessages((t) => {
|
|
3088
3091
|
let n = t.find((t) => t.id === e.messageId), r = e.runId || n?.runId || n?.invocationId, i = `agui-a2ui-${JSON.stringify([
|
|
3089
3092
|
r || e.messageId,
|
|
3090
3093
|
e.interactionId || "",
|
|
@@ -3095,7 +3098,7 @@ function gn(e, t) {
|
|
|
3095
3098
|
originMessageId: e.messageId,
|
|
3096
3099
|
...r ? { runId: r } : {},
|
|
3097
3100
|
...e.interactionId ? { interactionId: e.interactionId } : {}
|
|
3098
|
-
}, o =
|
|
3101
|
+
}, o = be(t.flatMap((e) => [...e.aguiActivity ? [{
|
|
3099
3102
|
message: e,
|
|
3100
3103
|
activity: e.aguiActivity
|
|
3101
3104
|
}] : [], ...(e.aguiActivities || []).map((t) => ({
|
|
@@ -3107,12 +3110,12 @@ function gn(e, t) {
|
|
|
3107
3110
|
});
|
|
3108
3111
|
if (o) return t.map((t) => t === o.message ? {
|
|
3109
3112
|
...t,
|
|
3110
|
-
...t.aguiActivity === o.activity ? { aguiActivity:
|
|
3113
|
+
...t.aguiActivity === o.activity ? { aguiActivity: ve(o.activity, a, e.batchId) } : { aguiActivities: t.aguiActivities?.map((t) => t === o.activity ? ve(t, a, e.batchId) : t) }
|
|
3111
3114
|
} : t);
|
|
3112
3115
|
let s = !1, c = t.map((t) => {
|
|
3113
3116
|
if (t.id !== e.messageId) return t;
|
|
3114
3117
|
s = !0;
|
|
3115
|
-
let n = [...t.aguiActivities || [],
|
|
3118
|
+
let n = [...t.aguiActivities || [], ve(void 0, a, e.batchId)];
|
|
3116
3119
|
return {
|
|
3117
3120
|
...t,
|
|
3118
3121
|
aguiActivities: n
|
|
@@ -3125,67 +3128,67 @@ function gn(e, t) {
|
|
|
3125
3128
|
content: "",
|
|
3126
3129
|
timestamp: l?.timestamp || Date.now(),
|
|
3127
3130
|
...r ? { invocationId: r } : {},
|
|
3128
|
-
aguiActivity:
|
|
3131
|
+
aguiActivity: ve(l?.aguiActivity, a, e.batchId)
|
|
3129
3132
|
};
|
|
3130
3133
|
return l ? t.map((e) => e.id === i ? u : e) : [...t, u];
|
|
3131
3134
|
});
|
|
3132
3135
|
break;
|
|
3133
3136
|
}
|
|
3134
3137
|
}
|
|
3135
|
-
function
|
|
3136
|
-
|
|
3138
|
+
function vn() {
|
|
3139
|
+
pn.clear();
|
|
3137
3140
|
}
|
|
3138
3141
|
//#endregion
|
|
3139
3142
|
//#region src/hooks/useRunAgent.ts
|
|
3140
|
-
var
|
|
3141
|
-
function
|
|
3143
|
+
var yn = 64;
|
|
3144
|
+
function bn(e, t, n) {
|
|
3142
3145
|
if (t.sessionId = n, t.conversationId) return;
|
|
3143
3146
|
let r = JSON.stringify([t.agentId, n]);
|
|
3144
3147
|
e.set(r, t), t.key !== r && e.get(t.key) === t && e.delete(t.key), t.key = r;
|
|
3145
3148
|
}
|
|
3146
|
-
function
|
|
3147
|
-
let t =
|
|
3149
|
+
function xn(e) {
|
|
3150
|
+
let t = v(), r = Y(/* @__PURE__ */ new Map()), i = Y(/* @__PURE__ */ new Set()), a = q((e) => i.current.has(e), []), o = q((e) => {
|
|
3148
3151
|
let t = r.current;
|
|
3149
|
-
if (!(t.size <=
|
|
3150
|
-
if (t.size <=
|
|
3152
|
+
if (!(t.size <= yn)) for (let [n, r] of t) {
|
|
3153
|
+
if (t.size <= yn) break;
|
|
3151
3154
|
n === e || r.engine.stage !== "idle" || r.queue.length > 0 || r.isVisible() || t.delete(n);
|
|
3152
3155
|
}
|
|
3153
|
-
}, []),
|
|
3156
|
+
}, []), s = He(() => new ye({ rendererCatalog: Ce }), []), u = e.conversationClient === void 0 ? e.uiCapabilities.ConversationSurface == null ? null : s : e.conversationClient, { agentId: d, apiFormats: f, agentFramework: p, selectedModel: m, selectedModelMetadata: g, thinkingMode: y, permissionMode: b, currentSessionIdRef: x, conversationIdRef: S, queuedDraftRef: C, onRunSettled: ee, onUserInputBound: w, onRunRecovered: T, onSessionCreated: E, waitForPendingSessionCreation: te, uiCapabilities: D, outbox: O } = e, k = l((e) => e.status === "ready" && e.agentId === d && e.accessMode !== "Share" ? e.capabilities.McpAuthorization : void 0), A = He(() => ({
|
|
3154
3157
|
a2uiCatalogRegistry: t,
|
|
3155
3158
|
agentId: d,
|
|
3156
3159
|
apiFormats: f,
|
|
3157
3160
|
agentFramework: p,
|
|
3158
|
-
selectedModel:
|
|
3159
|
-
selectedModelMetadata:
|
|
3160
|
-
thinkingMode:
|
|
3161
|
+
selectedModel: m,
|
|
3162
|
+
selectedModelMetadata: g,
|
|
3163
|
+
thinkingMode: D.Thinking ? y : "auto",
|
|
3161
3164
|
permissionMode: b,
|
|
3162
|
-
mcpAuthorization:
|
|
3163
|
-
dshApprovalMode:
|
|
3164
|
-
runtimeCapabilityMatrix:
|
|
3165
|
-
aguiResumeTransport:
|
|
3166
|
-
hostedChatTransport: n(
|
|
3167
|
-
checkpointResumePreviewEnabled: !!
|
|
3168
|
-
kernelSessionEventsEnabled:
|
|
3169
|
-
kernelCommandEventsEnabled:
|
|
3170
|
-
presentationProfile:
|
|
3165
|
+
mcpAuthorization: k,
|
|
3166
|
+
dshApprovalMode: D.Approval && D.ApprovalPolicy?.RuntimeOverride ? D.ApprovalPolicy.DefaultMode : void 0,
|
|
3167
|
+
runtimeCapabilityMatrix: D.RuntimeCapabilityMatrix,
|
|
3168
|
+
aguiResumeTransport: D.HostedChat?.Transports?.find((e) => e.Protocol === "ag-ui"),
|
|
3169
|
+
hostedChatTransport: n(D, { requireResumableRun: !!(D.RunLifecycle?.Enabled && D.RunLifecycle.Resume) }),
|
|
3170
|
+
checkpointResumePreviewEnabled: !!D.RunLifecycle?.CheckpointResumePreview,
|
|
3171
|
+
kernelSessionEventsEnabled: D.KernelSessionEvents === !0 || D.KernelSessionEventsByCommand === !0,
|
|
3172
|
+
kernelCommandEventsEnabled: D.KernelSessionEventsByCommand === !0,
|
|
3173
|
+
presentationProfile: de(D.ConversationSurface, Ce),
|
|
3171
3174
|
conversationClient: u || void 0
|
|
3172
3175
|
}), [
|
|
3173
3176
|
d,
|
|
3174
3177
|
f,
|
|
3175
3178
|
p,
|
|
3176
|
-
|
|
3177
|
-
|
|
3179
|
+
m,
|
|
3180
|
+
g,
|
|
3178
3181
|
y,
|
|
3179
3182
|
b,
|
|
3180
|
-
|
|
3181
|
-
|
|
3183
|
+
D,
|
|
3184
|
+
k,
|
|
3182
3185
|
u,
|
|
3183
3186
|
t
|
|
3184
3187
|
]), j = q((t = x.current) => {
|
|
3185
3188
|
let n = e.conversationIdRef?.current, i = JSON.stringify([d, n || t || "new-session"]), a = r.current.get(i);
|
|
3186
3189
|
if (!a) {
|
|
3187
3190
|
o(i);
|
|
3188
|
-
let s = () => e.agentIdRef.current === d && (e.conversationIdRef ? e.conversationIdRef.current === n : x.current === a.sessionId), c = new
|
|
3191
|
+
let s = () => e.agentIdRef.current === d && (e.conversationIdRef ? e.conversationIdRef.current === n : x.current === a.sessionId), c = new on(e.api, {
|
|
3189
3192
|
isVisible: s,
|
|
3190
3193
|
draftId: n
|
|
3191
3194
|
});
|
|
@@ -3197,7 +3200,7 @@ function bn(e) {
|
|
|
3197
3200
|
engine: c,
|
|
3198
3201
|
queue: [],
|
|
3199
3202
|
isVisible: s
|
|
3200
|
-
}, c.subscribe((e) =>
|
|
3203
|
+
}, c.subscribe((e) => _n(e, {
|
|
3201
3204
|
visible: s(),
|
|
3202
3205
|
draftId: n
|
|
3203
3206
|
})), r.current.set(i, a);
|
|
@@ -3216,8 +3219,8 @@ function bn(e) {
|
|
|
3216
3219
|
}, [A, j]), N = q((e) => {
|
|
3217
3220
|
if (!e.isVisible()) return;
|
|
3218
3221
|
let t = e.queue.map((e) => e.draft);
|
|
3219
|
-
|
|
3220
|
-
}, [
|
|
3222
|
+
C.current = t, _.getState().setQueuedDrafts(t);
|
|
3223
|
+
}, [C]), P = q((e) => {
|
|
3221
3224
|
let t = e.queue[0];
|
|
3222
3225
|
!t || e.engine.stage !== "idle" || (e.queue.shift(), N(e), queueMicrotask(() => {
|
|
3223
3226
|
t.launch() || (e.queue.unshift(t), N(e));
|
|
@@ -3225,16 +3228,16 @@ function bn(e) {
|
|
|
3225
3228
|
}, [N]);
|
|
3226
3229
|
J(() => {
|
|
3227
3230
|
let t = JSON.stringify([d, e.conversationId || S?.current || e.currentSessionId || "new-session"]), n = r.current.get(t);
|
|
3228
|
-
n ? N(n) : (
|
|
3231
|
+
n ? N(n) : (C.current = [], _.getState().setQueuedDrafts([]));
|
|
3229
3232
|
}, [
|
|
3230
3233
|
d,
|
|
3231
3234
|
e.currentSessionId,
|
|
3232
3235
|
e.conversationId,
|
|
3233
3236
|
S,
|
|
3234
3237
|
N,
|
|
3235
|
-
|
|
3238
|
+
C
|
|
3236
3239
|
]);
|
|
3237
|
-
let
|
|
3240
|
+
let ne = q((e) => {
|
|
3238
3241
|
let t = e.text.trim(), n = e.attachments.map((e) => ({
|
|
3239
3242
|
name: e.name,
|
|
3240
3243
|
url: URL.createObjectURL(e),
|
|
@@ -3242,7 +3245,7 @@ function bn(e) {
|
|
|
3242
3245
|
}));
|
|
3243
3246
|
if (!t && n.length === 0) return;
|
|
3244
3247
|
let r = `optimistic-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
3245
|
-
return
|
|
3248
|
+
return G.getState().patchMessages((e) => [...e, {
|
|
3246
3249
|
id: r,
|
|
3247
3250
|
role: "user",
|
|
3248
3251
|
content: t,
|
|
@@ -3250,9 +3253,9 @@ function bn(e) {
|
|
|
3250
3253
|
eventType: "optimistic_user_message",
|
|
3251
3254
|
attachments: n.length ? n : void 0
|
|
3252
3255
|
}]), r;
|
|
3253
|
-
}, []),
|
|
3256
|
+
}, []), F = q((e) => {
|
|
3254
3257
|
let t = `optimistic-assistant-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
3255
|
-
return
|
|
3258
|
+
return G.getState().patchMessages((n) => {
|
|
3256
3259
|
let r = n.findIndex((t) => t.id === e), i = r < 0 ? n.length : r + 1;
|
|
3257
3260
|
return [
|
|
3258
3261
|
...n.slice(0, i),
|
|
@@ -3267,7 +3270,7 @@ function bn(e) {
|
|
|
3267
3270
|
...n.slice(i)
|
|
3268
3271
|
];
|
|
3269
3272
|
}), t;
|
|
3270
|
-
}, []),
|
|
3273
|
+
}, []), re = q(async (t, n, a, o, s, l) => {
|
|
3271
3274
|
if (l && i.current.has(l)) return !1;
|
|
3272
3275
|
let u = j();
|
|
3273
3276
|
N(u);
|
|
@@ -3276,12 +3279,12 @@ function bn(e) {
|
|
|
3276
3279
|
attachments: [...n],
|
|
3277
3280
|
responsesInput: a,
|
|
3278
3281
|
previousResponseId: o,
|
|
3279
|
-
executionMode:
|
|
3280
|
-
optimisticMessageId:
|
|
3282
|
+
executionMode: s,
|
|
3283
|
+
optimisticMessageId: ne({
|
|
3281
3284
|
text: t,
|
|
3282
3285
|
attachments: n
|
|
3283
3286
|
})
|
|
3284
|
-
}, f = a === void 0 && u.conversationId &&
|
|
3287
|
+
}, f = a === void 0 && u.conversationId && O ? O : void 0, p = u.conversationId && f ? f.enqueue({
|
|
3285
3288
|
requestId: l,
|
|
3286
3289
|
conversationId: u.conversationId,
|
|
3287
3290
|
agentId: u.agentId,
|
|
@@ -3291,30 +3294,30 @@ function bn(e) {
|
|
|
3291
3294
|
type: e.type,
|
|
3292
3295
|
size: e.size
|
|
3293
3296
|
})),
|
|
3294
|
-
executionMode:
|
|
3297
|
+
executionMode: s
|
|
3295
3298
|
}) : void 0;
|
|
3296
3299
|
p && f && (i.current.add(p.requestId), f.setRuntimeAttachments(p.requestId, n));
|
|
3297
|
-
let
|
|
3300
|
+
let m;
|
|
3298
3301
|
try {
|
|
3299
|
-
|
|
3302
|
+
m = await te?.();
|
|
3300
3303
|
} catch (e) {
|
|
3301
3304
|
throw p && f && (i.current.delete(p.requestId), f.update(p.requestId, {
|
|
3302
3305
|
status: "unknown",
|
|
3303
3306
|
error: "创建会话的结果待确认。"
|
|
3304
3307
|
})), e;
|
|
3305
3308
|
}
|
|
3306
|
-
!u.sessionId &&
|
|
3307
|
-
let
|
|
3308
|
-
|
|
3309
|
+
!u.sessionId && m && bn(r.current, u, m);
|
|
3310
|
+
let g, v = a === void 0 ? null : new Promise((e) => {
|
|
3311
|
+
g = e;
|
|
3309
3312
|
}), y = (t) => {
|
|
3310
3313
|
let n = d.optimisticMessageId;
|
|
3311
|
-
n && (u.sessionId && e.agentIdRef.current === u.agentId && w?.(u.sessionId, n, t), u.isVisible() &&
|
|
3314
|
+
n && (u.sessionId && e.agentIdRef.current === u.agentId && w?.(u.sessionId, n, t), u.isVisible() && G.getState().patchMessages((e) => e.map((e) => e.id === n ? {
|
|
3312
3315
|
...e,
|
|
3313
3316
|
...t
|
|
3314
3317
|
} : e)));
|
|
3315
3318
|
}, b = () => {
|
|
3316
3319
|
if (u.engine.stage !== "idle") return !1;
|
|
3317
|
-
u.engine.updateConfig(A), p && f && f.markSending(p.requestId), u.isVisible() && (
|
|
3320
|
+
u.engine.updateConfig(A), p && f && f.markSending(p.requestId), u.isVisible() && (_.getState().setMobileActionsOpen(!1), F(d.optimisticMessageId)), h.getState().setSessionStreaming(u.sessionId || u.conversationId, !0);
|
|
3318
3321
|
let e = u.engine.start({
|
|
3319
3322
|
...d,
|
|
3320
3323
|
sessionId: u.sessionId,
|
|
@@ -3324,70 +3327,70 @@ function bn(e) {
|
|
|
3324
3327
|
onCommandAdmitted: (e) => y({ commandId: e }),
|
|
3325
3328
|
onSessionCreated: (e) => {
|
|
3326
3329
|
let t = u.isVisible(), n = u.sessionId || u.conversationId;
|
|
3327
|
-
|
|
3330
|
+
bn(r.current, u, e), p && f && f.update(p.requestId, { nativeSessionId: e }), h.getState().setSessionStreaming(e, !0), n !== e && h.getState().setSessionStreaming(n, !1), E?.(e, u.conversationId, u.agentId), !E && t && (c.getState().upsertSessions([{
|
|
3328
3331
|
SessionId: e,
|
|
3329
3332
|
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3330
|
-
}]), x.current = e,
|
|
3333
|
+
}]), x.current = e, c.getState().setCurrentSessionId(e)), t && lt(u.agentId, e);
|
|
3331
3334
|
},
|
|
3332
3335
|
onSessionUpsert: () => {},
|
|
3333
|
-
onDispatchResult:
|
|
3336
|
+
onDispatchResult: g,
|
|
3334
3337
|
onRecovered: (e, t) => {
|
|
3335
3338
|
u.isVisible() && u.sessionId === e && T?.(e, t);
|
|
3336
3339
|
},
|
|
3337
3340
|
onSettled: (e, t = "unknown") => {
|
|
3338
|
-
p && i.current.delete(p.requestId), p && f && f.update(p.requestId, { status: t === "completed" || t === "awaiting-input" ? "completed" : t === "cancelled" ? "cancelled" : t === "failed" ? "failed" : "unknown" }),
|
|
3341
|
+
p && i.current.delete(p.requestId), p && f && f.update(p.requestId, { status: t === "completed" || t === "awaiting-input" ? "completed" : t === "cancelled" ? "cancelled" : t === "failed" ? "failed" : "unknown" }), ee?.(e, u.agentId, t), t === "completed" && P(u);
|
|
3339
3342
|
}
|
|
3340
3343
|
});
|
|
3341
|
-
return e ||
|
|
3344
|
+
return e || h.getState().setSessionStreaming(u.sessionId || u.conversationId, !1), e;
|
|
3342
3345
|
}, S = b();
|
|
3343
3346
|
return !S && a === void 0 ? (u.queue.push({
|
|
3344
3347
|
draft: d,
|
|
3345
3348
|
launch: b
|
|
3346
|
-
}), N(u), !0) : v ? (S ||
|
|
3349
|
+
}), N(u), !0) : v ? (S || g?.(!1), v) : S;
|
|
3347
3350
|
}, [
|
|
3348
|
-
I,
|
|
3349
3351
|
F,
|
|
3352
|
+
ne,
|
|
3350
3353
|
A,
|
|
3351
3354
|
e.agentIdRef,
|
|
3352
3355
|
x,
|
|
3353
3356
|
P,
|
|
3354
3357
|
j,
|
|
3355
3358
|
T,
|
|
3356
|
-
|
|
3359
|
+
ee,
|
|
3357
3360
|
E,
|
|
3358
3361
|
w,
|
|
3359
|
-
|
|
3362
|
+
O,
|
|
3360
3363
|
N,
|
|
3361
|
-
|
|
3362
|
-
]),
|
|
3364
|
+
te
|
|
3365
|
+
]), I = q(() => {
|
|
3363
3366
|
M(x.current).stop();
|
|
3364
|
-
}, [x, M]),
|
|
3367
|
+
}, [x, M]), L = q(() => {
|
|
3365
3368
|
M(x.current).disconnect();
|
|
3366
|
-
}, [x, M]),
|
|
3369
|
+
}, [x, M]), ie = q((e) => {
|
|
3367
3370
|
let t = j(e.sessionId), n = M(e.sessionId);
|
|
3368
3371
|
if (n.stage !== "idle") return !1;
|
|
3369
|
-
|
|
3372
|
+
vn(), _.getState().setMobileActionsOpen(!1), h.getState().setSessionStreaming(e.sessionId, !0);
|
|
3370
3373
|
let r = n.resumeCheckpoint({
|
|
3371
3374
|
...e,
|
|
3372
3375
|
onSettled: (e, n) => {
|
|
3373
|
-
|
|
3376
|
+
ee?.(e, t.agentId, n), n === "completed" && P(t);
|
|
3374
3377
|
}
|
|
3375
3378
|
});
|
|
3376
|
-
return r ||
|
|
3379
|
+
return r || h.getState().setSessionStreaming(e.sessionId, !1), r;
|
|
3377
3380
|
}, [
|
|
3378
3381
|
P,
|
|
3379
3382
|
M,
|
|
3380
3383
|
j,
|
|
3381
|
-
|
|
3382
|
-
]),
|
|
3383
|
-
|
|
3384
|
+
ee
|
|
3385
|
+
]), R = q(() => {
|
|
3386
|
+
vn();
|
|
3384
3387
|
}, []);
|
|
3385
3388
|
return {
|
|
3386
|
-
submitDraft:
|
|
3389
|
+
submitDraft: re,
|
|
3387
3390
|
isOutboxRequestActive: a,
|
|
3388
|
-
stopGeneration:
|
|
3389
|
-
disconnectRun:
|
|
3390
|
-
resumeCheckpoint:
|
|
3391
|
+
stopGeneration: I,
|
|
3392
|
+
disconnectRun: L,
|
|
3393
|
+
resumeCheckpoint: ie,
|
|
3391
3394
|
submitAguiAction: q((e) => {
|
|
3392
3395
|
let t = e.userAction;
|
|
3393
3396
|
if (!t) return !1;
|
|
@@ -3406,7 +3409,7 @@ function bn(e) {
|
|
|
3406
3409
|
status: s,
|
|
3407
3410
|
payload: c,
|
|
3408
3411
|
onSettled: (e) => {
|
|
3409
|
-
|
|
3412
|
+
ee?.(e, a.agentId), P(a);
|
|
3410
3413
|
}
|
|
3411
3414
|
});
|
|
3412
3415
|
}, [
|
|
@@ -3414,7 +3417,7 @@ function bn(e) {
|
|
|
3414
3417
|
P,
|
|
3415
3418
|
M,
|
|
3416
3419
|
j,
|
|
3417
|
-
|
|
3420
|
+
ee
|
|
3418
3421
|
]),
|
|
3419
3422
|
respondToAguiApproval: q((e) => {
|
|
3420
3423
|
if (!e.interruptId) return !1;
|
|
@@ -3422,40 +3425,40 @@ function bn(e) {
|
|
|
3422
3425
|
if (!t) return !1;
|
|
3423
3426
|
let n = j(t), r = M(t);
|
|
3424
3427
|
if (r.stage !== "idle") return !1;
|
|
3425
|
-
|
|
3428
|
+
h.getState().setSessionStreaming(t, !0);
|
|
3426
3429
|
let i = r.resumeAguiInterrupt({
|
|
3427
3430
|
sessionId: t,
|
|
3428
3431
|
interruptId: e.interruptId,
|
|
3429
3432
|
status: e.status || "resolved",
|
|
3430
3433
|
payload: Object.hasOwn(e, "payload") ? e.payload : { decision: e.approve ? "approve" : "reject" },
|
|
3431
3434
|
onSettled: (e) => {
|
|
3432
|
-
|
|
3435
|
+
ee?.(e, n.agentId), P(n);
|
|
3433
3436
|
}
|
|
3434
3437
|
});
|
|
3435
|
-
return i ||
|
|
3438
|
+
return i || h.getState().setSessionStreaming(t, !1), i;
|
|
3436
3439
|
}, [
|
|
3437
3440
|
x,
|
|
3438
3441
|
P,
|
|
3439
3442
|
M,
|
|
3440
3443
|
j,
|
|
3441
|
-
|
|
3444
|
+
ee
|
|
3442
3445
|
]),
|
|
3443
|
-
resetCompaction:
|
|
3446
|
+
resetCompaction: R
|
|
3444
3447
|
};
|
|
3445
3448
|
}
|
|
3446
3449
|
//#endregion
|
|
3447
3450
|
//#region src/utils/history-preparation.ts
|
|
3448
|
-
function
|
|
3451
|
+
function Sn(e) {
|
|
3449
3452
|
return e instanceof X && e.code === 503 && e.detail?.ReasonCode === "HISTORY_PREPARING";
|
|
3450
3453
|
}
|
|
3451
|
-
async function
|
|
3454
|
+
async function Cn(e, t) {
|
|
3452
3455
|
let n = Date.now();
|
|
3453
3456
|
for (let r = 0;; r += 1) {
|
|
3454
3457
|
if (!t.isCurrent() || t.signal?.aborted) throw new Z();
|
|
3455
3458
|
try {
|
|
3456
3459
|
return await e();
|
|
3457
3460
|
} catch (e) {
|
|
3458
|
-
if (!
|
|
3461
|
+
if (!Sn(e) || r >= 60 || Date.now() - n >= 3e5) throw e;
|
|
3459
3462
|
if (!t.isCurrent() || t.signal?.aborted) throw new Z();
|
|
3460
3463
|
t.onPreparing?.(), await new Promise((e) => {
|
|
3461
3464
|
let i = () => {
|
|
@@ -3468,7 +3471,7 @@ async function Sn(e, t) {
|
|
|
3468
3471
|
}
|
|
3469
3472
|
//#endregion
|
|
3470
3473
|
//#region src/utils/kernel-run-history.ts
|
|
3471
|
-
async function
|
|
3474
|
+
async function wn(e, t, n, r, i, a) {
|
|
3472
3475
|
let o = r.Events;
|
|
3473
3476
|
if (o.some((e) => e.EventType === "run.started" && e.InvocationId === n)) return o;
|
|
3474
3477
|
let s = {
|
|
@@ -3510,13 +3513,13 @@ async function Cn(e, t, n, r, i, a) {
|
|
|
3510
3513
|
c(r);
|
|
3511
3514
|
let i = r.Events;
|
|
3512
3515
|
if (!i.length || i.some((e) => !Number.isSafeInteger(e.SeqId) || Number(e.SeqId) >= n || Number(e.SeqId) < l)) throw Error("Kernel run history cursor did not advance");
|
|
3513
|
-
o =
|
|
3516
|
+
o = re(o, i);
|
|
3514
3517
|
}
|
|
3515
3518
|
return o;
|
|
3516
3519
|
}
|
|
3517
3520
|
//#endregion
|
|
3518
3521
|
//#region src/utils/interaction-history.ts
|
|
3519
|
-
var
|
|
3522
|
+
var Tn = [
|
|
3520
3523
|
"mcp.authorization.requested",
|
|
3521
3524
|
"mcp.authorization.updated",
|
|
3522
3525
|
"interaction.requested",
|
|
@@ -3534,8 +3537,8 @@ var wn = [
|
|
|
3534
3537
|
"interaction.expired",
|
|
3535
3538
|
"approval.resolved",
|
|
3536
3539
|
"a2ui.action"
|
|
3537
|
-
],
|
|
3538
|
-
async function
|
|
3540
|
+
], En = 32, Dn = 2;
|
|
3541
|
+
async function On(e, t, n, r, i, a) {
|
|
3539
3542
|
let o = /* @__PURE__ */ new Set(), s = Infinity, c = (e) => {
|
|
3540
3543
|
for (let t of e) {
|
|
3541
3544
|
t.agentBlock && c(t.agentBlock.messages);
|
|
@@ -3557,7 +3560,7 @@ async function Dn(e, t, n, r, i, a) {
|
|
|
3557
3560
|
incomplete: !1
|
|
3558
3561
|
};
|
|
3559
3562
|
let l = /* @__PURE__ */ new Set(), u = (e) => {
|
|
3560
|
-
let n =
|
|
3563
|
+
let n = P(e, t);
|
|
3561
3564
|
return !n || !o.has(n.interactionId) ? !1 : (n.status === "pending" && l.add(n.interactionId), !0);
|
|
3562
3565
|
};
|
|
3563
3566
|
if (r.Events.forEach(u), [...o].every((e) => l.has(e))) return {
|
|
@@ -3565,10 +3568,10 @@ async function Dn(e, t, n, r, i, a) {
|
|
|
3565
3568
|
incomplete: !1
|
|
3566
3569
|
};
|
|
3567
3570
|
let d = [], f = Number(r.SnapshotSeqId) + 1;
|
|
3568
|
-
for (let n = 0; n <
|
|
3571
|
+
for (let n = 0; n < Dn && i() && !a?.aborted; n += 1) {
|
|
3569
3572
|
let n = await e.listSessionEvents(t, {
|
|
3570
|
-
eventTypes:
|
|
3571
|
-
limit:
|
|
3573
|
+
eventTypes: Tn,
|
|
3574
|
+
limit: En,
|
|
3572
3575
|
afterSeqId: s,
|
|
3573
3576
|
beforeSeqId: f,
|
|
3574
3577
|
cursorSource: r.CursorSource,
|
|
@@ -3598,7 +3601,7 @@ async function Dn(e, t, n, r, i, a) {
|
|
|
3598
3601
|
}
|
|
3599
3602
|
//#endregion
|
|
3600
3603
|
//#region src/utils/messages.js
|
|
3601
|
-
var
|
|
3604
|
+
var kn = {
|
|
3602
3605
|
running: "running",
|
|
3603
3606
|
completed: "completed",
|
|
3604
3607
|
failed: "error",
|
|
@@ -3609,7 +3612,7 @@ var On = {
|
|
|
3609
3612
|
rejected: "completed",
|
|
3610
3613
|
cancelled: "completed",
|
|
3611
3614
|
expired: "completed"
|
|
3612
|
-
},
|
|
3615
|
+
}, An = {
|
|
3613
3616
|
pending: "pending",
|
|
3614
3617
|
paused: "pending",
|
|
3615
3618
|
approved: "approved",
|
|
@@ -3618,7 +3621,7 @@ var On = {
|
|
|
3618
3621
|
cancelled: "cancelled",
|
|
3619
3622
|
expired: "cancelled"
|
|
3620
3623
|
};
|
|
3621
|
-
function
|
|
3624
|
+
function jn(e) {
|
|
3622
3625
|
if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
|
|
3623
3626
|
if (typeof e == "string") {
|
|
3624
3627
|
let t = Number(e.trim());
|
|
@@ -3628,7 +3631,7 @@ function An(e) {
|
|
|
3628
3631
|
}
|
|
3629
3632
|
return Date.now();
|
|
3630
3633
|
}
|
|
3631
|
-
function
|
|
3634
|
+
function Mn(e) {
|
|
3632
3635
|
if (typeof e == "string") return e;
|
|
3633
3636
|
if (e && typeof e == "object") {
|
|
3634
3637
|
if (typeof e.text == "string") return e.text;
|
|
@@ -3636,23 +3639,23 @@ function jn(e) {
|
|
|
3636
3639
|
}
|
|
3637
3640
|
return "";
|
|
3638
3641
|
}
|
|
3639
|
-
function
|
|
3642
|
+
function Nn(e) {
|
|
3640
3643
|
let t = {}, n = /* @__PURE__ */ new Map();
|
|
3641
3644
|
for (let t of e ?? []) t?.Name && n.set(t.Name, (n.get(t.Name) || 0) + 1);
|
|
3642
3645
|
for (let r of e ?? []) {
|
|
3643
3646
|
if (!r?.Name) continue;
|
|
3644
|
-
let e =
|
|
3647
|
+
let e = kn[String(r.Status ?? "completed").toLowerCase()] ?? "completed", i = {
|
|
3645
3648
|
name: r.Name,
|
|
3646
3649
|
args: r.Args === void 0 ? "" : typeof r.Args == "string" ? r.Args : JSON.stringify(r.Args),
|
|
3647
3650
|
status: e
|
|
3648
3651
|
};
|
|
3649
|
-
r.Result !== void 0 && (i.output = typeof r.Result == "string" ? r.Result : JSON.stringify(r.Result)), r.ApprovalRequestId && (i.approvalRequestId = r.ApprovalRequestId, i.approvalStatus =
|
|
3652
|
+
r.Result !== void 0 && (i.output = typeof r.Result == "string" ? r.Result : JSON.stringify(r.Result)), r.ApprovalRequestId && (i.approvalRequestId = r.ApprovalRequestId, i.approvalStatus = An[String(r.ApprovalStatus ?? r.Status ?? "paused").toLowerCase()], i.approvalProtocol = String(r.Protocol ?? "").toLowerCase() === "ag-ui" ? "ag-ui" : "responses", r.ApprovalMessage && (i.approvalMessage = String(r.ApprovalMessage)), r.ApprovalLevel && (i.approvalLevel = String(r.ApprovalLevel))), r.ToolCallId && (i.callId = r.ToolCallId, i.previousResponseId = r.ToolCallId);
|
|
3650
3653
|
let a = n.get(r.Name) > 1 && (r.ToolCallId || r.ApprovalRequestId) || r.Name;
|
|
3651
3654
|
t[a] = i;
|
|
3652
3655
|
}
|
|
3653
3656
|
return t;
|
|
3654
3657
|
}
|
|
3655
|
-
function
|
|
3658
|
+
function Pn(e) {
|
|
3656
3659
|
if (Array.isArray(e)) return e.map((e) => ({
|
|
3657
3660
|
name: e.name || "",
|
|
3658
3661
|
url: e.url || "",
|
|
@@ -3660,10 +3663,10 @@ function Nn(e) {
|
|
|
3660
3663
|
fileUri: e.file_uri
|
|
3661
3664
|
}));
|
|
3662
3665
|
}
|
|
3663
|
-
function
|
|
3666
|
+
function Fn(e) {
|
|
3664
3667
|
return e == null ? "" : typeof e == "string" ? e : JSON.stringify(e);
|
|
3665
3668
|
}
|
|
3666
|
-
function
|
|
3669
|
+
function In(e) {
|
|
3667
3670
|
if (!(!Array.isArray(e) || !e.length)) return e.flatMap((e, t) => {
|
|
3668
3671
|
let n = String(e?.Type || "").toLowerCase(), r = e?.SeqId ?? t;
|
|
3669
3672
|
if (n === "thinking" || n === "text") {
|
|
@@ -3676,13 +3679,13 @@ function Fn(e) {
|
|
|
3676
3679
|
}] : [];
|
|
3677
3680
|
}
|
|
3678
3681
|
if (n !== "tool") return [];
|
|
3679
|
-
let i =
|
|
3682
|
+
let i = kn[String(e?.Status || "completed").toLowerCase()] ?? "completed";
|
|
3680
3683
|
return [{
|
|
3681
3684
|
id: `history-tool-${r}`,
|
|
3682
3685
|
type: "tool",
|
|
3683
3686
|
toolName: String(e?.Name || "tool"),
|
|
3684
|
-
args:
|
|
3685
|
-
...e?.Result === void 0 ? {} : { output:
|
|
3687
|
+
args: Fn(e?.Args),
|
|
3688
|
+
...e?.Result === void 0 ? {} : { output: Fn(e.Result) },
|
|
3686
3689
|
status: i,
|
|
3687
3690
|
...e?.ToolCallId ? { extra: {
|
|
3688
3691
|
callId: String(e.ToolCallId),
|
|
@@ -3691,12 +3694,12 @@ function Fn(e) {
|
|
|
3691
3694
|
}];
|
|
3692
3695
|
});
|
|
3693
3696
|
}
|
|
3694
|
-
function
|
|
3695
|
-
let t = e.Role === "assistant" ? "model" : e.Role || "user", n = e.ToolEvents?.length ?
|
|
3697
|
+
function Ln(e) {
|
|
3698
|
+
let t = e.Role === "assistant" ? "model" : e.Role || "user", n = e.ToolEvents?.length ? Nn(e.ToolEvents) : void 0, r = Pn(e.Attachments), i = In(e.Blocks), a = e.Reasoning?.length ? e.Reasoning.map((e) => e.text).join("") : void 0, o = {
|
|
3696
3699
|
id: e.MessageId || `msg-${e.SeqId ?? Math.random().toString(36).slice(2)}`,
|
|
3697
3700
|
role: t,
|
|
3698
|
-
content:
|
|
3699
|
-
timestamp:
|
|
3701
|
+
content: Mn(e.Content),
|
|
3702
|
+
timestamp: jn(e.Timestamp),
|
|
3700
3703
|
...Number.isSafeInteger(e.SeqId) && e.SeqId > 0 ? { historyOrder: {
|
|
3701
3704
|
seq: e.SeqId,
|
|
3702
3705
|
...Number.isSafeInteger(e.StartSeqId) && e.StartSeqId > 0 ? { group: e.StartSeqId } : {}
|
|
@@ -3706,13 +3709,13 @@ function In(e) {
|
|
|
3706
3709
|
tools: n,
|
|
3707
3710
|
attachments: r
|
|
3708
3711
|
};
|
|
3709
|
-
return t === "model" && (o.blocks = i ??
|
|
3712
|
+
return t === "model" && (o.blocks = i ?? Ie({
|
|
3710
3713
|
reasoning: a,
|
|
3711
3714
|
tools: n,
|
|
3712
3715
|
content: o.content
|
|
3713
3716
|
})), e.MessageId && (o.eventId = e.MessageId), e.InvocationId && (o.invocationId = e.InvocationId), e.ScopeId && (o.scopeId = e.ScopeId), e.ResponseId && (o.responseId = e.ResponseId), e.TraceId && (o.traceId = e.TraceId), e.RootSpanId && (o.rootSpanId = e.RootSpanId), o;
|
|
3714
3717
|
}
|
|
3715
|
-
function
|
|
3718
|
+
function Rn(e) {
|
|
3716
3719
|
return Array.isArray(e.Activities) ? e.Activities.flatMap((t, n) => {
|
|
3717
3720
|
let r = String(t?.SurfaceId || "");
|
|
3718
3721
|
if (!r) return [];
|
|
@@ -3726,7 +3729,7 @@ function Ln(e) {
|
|
|
3726
3729
|
id: o && o !== String(e.MessageId || "") ? o : `${o || e.MessageId || e.SeqId || "message"}:a2ui:${r}:${n}`,
|
|
3727
3730
|
role: "a2ui",
|
|
3728
3731
|
content: "",
|
|
3729
|
-
timestamp:
|
|
3732
|
+
timestamp: jn(e.Timestamp),
|
|
3730
3733
|
...e.InvocationId ? { invocationId: String(e.InvocationId) } : {},
|
|
3731
3734
|
...Number.isSafeInteger(e.SeqId) && e.SeqId > 0 ? { historyOrder: {
|
|
3732
3735
|
seq: e.SeqId,
|
|
@@ -3735,18 +3738,18 @@ function Ln(e) {
|
|
|
3735
3738
|
} } : {},
|
|
3736
3739
|
aguiActivity: {
|
|
3737
3740
|
surfaceId: r,
|
|
3738
|
-
messages:
|
|
3741
|
+
messages: te(a),
|
|
3739
3742
|
...typeof i?.interactionId == "string" ? { interactionId: i.interactionId } : {}
|
|
3740
3743
|
}
|
|
3741
3744
|
}];
|
|
3742
3745
|
}) : [];
|
|
3743
3746
|
}
|
|
3744
|
-
function
|
|
3745
|
-
return
|
|
3747
|
+
function zn(e) {
|
|
3748
|
+
return Be(Ve(e.map(Ln)).flatMap((t, n) => [t, ...Rn(e[n])]));
|
|
3746
3749
|
}
|
|
3747
3750
|
//#endregion
|
|
3748
3751
|
//#region src/utils/history-content.ts
|
|
3749
|
-
function
|
|
3752
|
+
function Bn(e, t) {
|
|
3750
3753
|
return t.throwIfAborted(), new Promise((n, r) => {
|
|
3751
3754
|
let i = () => {
|
|
3752
3755
|
clearTimeout(a), r(t.reason);
|
|
@@ -3756,7 +3759,7 @@ function zn(e, t) {
|
|
|
3756
3759
|
t.addEventListener("abort", i, { once: !0 });
|
|
3757
3760
|
});
|
|
3758
3761
|
}
|
|
3759
|
-
async function
|
|
3762
|
+
async function Vn(e, t, n, r, i, a = {}, o) {
|
|
3760
3763
|
let s = JSON.stringify([
|
|
3761
3764
|
t,
|
|
3762
3765
|
r.HistoryEpoch,
|
|
@@ -3792,7 +3795,7 @@ async function Bn(e, t, n, r, i, a = {}, o) {
|
|
|
3792
3795
|
if (e instanceof X && e.code === 429 && s < 3) {
|
|
3793
3796
|
let t = e.retryAfterMs ?? 500 * 2 ** s;
|
|
3794
3797
|
if (t <= 8e3) {
|
|
3795
|
-
s++, await
|
|
3798
|
+
s++, await Bn(t, i);
|
|
3796
3799
|
continue;
|
|
3797
3800
|
}
|
|
3798
3801
|
}
|
|
@@ -3817,7 +3820,7 @@ async function Bn(e, t, n, r, i, a = {}, o) {
|
|
|
3817
3820
|
}
|
|
3818
3821
|
//#endregion
|
|
3819
3822
|
//#region src/utils/session-items.ts
|
|
3820
|
-
function
|
|
3823
|
+
function Hn(e, t, n) {
|
|
3821
3824
|
if (e.HistoryView !== "items-v1" || !Array.isArray(e.Items) || !e.HistoryEpoch || !Number.isSafeInteger(e.SnapshotSeqId) || e.HasMore !== !!e.NextItemCursor || e.HasMore && (!e.Items.length || e.NextItemCursor === n)) throw Error("会话条目分页响应无效,请重新打开会话。");
|
|
3822
3825
|
let r = 0;
|
|
3823
3826
|
for (let n of e.Items) {
|
|
@@ -3826,21 +3829,21 @@ function Vn(e, t, n) {
|
|
|
3826
3829
|
}
|
|
3827
3830
|
return e.Items;
|
|
3828
3831
|
}
|
|
3829
|
-
async function
|
|
3830
|
-
let o = await
|
|
3832
|
+
async function Un(e, t, n, r, i, a) {
|
|
3833
|
+
let o = await Vn(e, t, n, r, i, a);
|
|
3831
3834
|
if (!Array.isArray(o) || o.length !== 2 || !o[0] || typeof o[0] != "object") throw Error("历史正文格式无效。");
|
|
3832
3835
|
return {
|
|
3833
3836
|
Content: o[0],
|
|
3834
3837
|
Metadata: o[1]
|
|
3835
3838
|
};
|
|
3836
3839
|
}
|
|
3837
|
-
function
|
|
3840
|
+
function Wn(e) {
|
|
3838
3841
|
let t = [], n = /* @__PURE__ */ new Map();
|
|
3839
3842
|
for (let r of e) {
|
|
3840
|
-
if (
|
|
3843
|
+
if (Le(r)) continue;
|
|
3841
3844
|
let e = r.Content, i = e?.parts?.map((e) => e.text || "").join("") || e?.text || e?.payload?.text || "", a = r.InvocationId || r.EventId, o = r.EventType;
|
|
3842
3845
|
if (o === "run.started" && r.Metadata?.ksadk_runtime_event && e?.payload?.source === "ag-ui") {
|
|
3843
|
-
let n =
|
|
3846
|
+
let n = Jn(e.payload.input);
|
|
3844
3847
|
n && t.push({
|
|
3845
3848
|
...r,
|
|
3846
3849
|
EventId: "input:" + r.EventId,
|
|
@@ -3886,7 +3889,7 @@ function Un(e) {
|
|
|
3886
3889
|
function Q(e) {
|
|
3887
3890
|
return e && typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
3888
3891
|
}
|
|
3889
|
-
function
|
|
3892
|
+
function Gn(e) {
|
|
3890
3893
|
let t = /* @__PURE__ */ new Map();
|
|
3891
3894
|
for (let n of e) {
|
|
3892
3895
|
if (n.EventType !== "approval_response") continue;
|
|
@@ -3901,7 +3904,7 @@ function Wn(e) {
|
|
|
3901
3904
|
}
|
|
3902
3905
|
return e.filter((e) => e.EventType === "approval_request").map((e) => {
|
|
3903
3906
|
let n = Q(e.Metadata?.interrupt_info), r = Array.isArray(n.action_requests) ? Q(n.action_requests[0]) : {}, i = String(n.approval_request_id || n.id || "");
|
|
3904
|
-
return
|
|
3907
|
+
return Ln({
|
|
3905
3908
|
MessageId: e.EventId,
|
|
3906
3909
|
Role: "assistant",
|
|
3907
3910
|
SeqId: e.SeqId,
|
|
@@ -3919,7 +3922,7 @@ function Wn(e) {
|
|
|
3919
3922
|
});
|
|
3920
3923
|
});
|
|
3921
3924
|
}
|
|
3922
|
-
function
|
|
3925
|
+
function Kn(e) {
|
|
3923
3926
|
let t = [];
|
|
3924
3927
|
function n(e) {
|
|
3925
3928
|
let r = Q(e), i = String(r.id || r.component_id || ""), a = String(r.component || r.type || "");
|
|
@@ -3934,12 +3937,12 @@ function Gn(e) {
|
|
|
3934
3937
|
}
|
|
3935
3938
|
return Array.isArray(e) && e.forEach(n), t;
|
|
3936
3939
|
}
|
|
3937
|
-
function
|
|
3938
|
-
return
|
|
3940
|
+
function qn(e) {
|
|
3941
|
+
return zn(e.flatMap((e) => {
|
|
3939
3942
|
if (!e.EventType?.startsWith("a2ui.surface.")) return [];
|
|
3940
3943
|
let t = Q(e.Content), n = Object.keys(Q(t.payload)).length ? Q(t.payload) : t, r = String(n.surfaceId || n.surface_id || "");
|
|
3941
3944
|
if (!r) return [];
|
|
3942
|
-
let i = n.operations || n.a2ui_operations, a = n.surface ? Q(n.surface) : n, o =
|
|
3945
|
+
let i = n.operations || n.a2ui_operations, a = n.surface ? Q(n.surface) : n, o = Kn(a.components), s = a.data_model ?? a.dataModel, c = Array.isArray(i) ? i : e.EventType === "a2ui.surface.end" ? [{
|
|
3943
3946
|
version: "v0.9",
|
|
3944
3947
|
deleteSurface: { surfaceId: r }
|
|
3945
3948
|
}] : [
|
|
@@ -3947,7 +3950,7 @@ function Kn(e) {
|
|
|
3947
3950
|
version: "v0.9",
|
|
3948
3951
|
createSurface: {
|
|
3949
3952
|
surfaceId: r,
|
|
3950
|
-
catalogId: a.catalog_id || a.catalogId ||
|
|
3953
|
+
catalogId: a.catalog_id || a.catalogId || y.catalog_id
|
|
3951
3954
|
}
|
|
3952
3955
|
}] : [],
|
|
3953
3956
|
...o.length ? [{
|
|
@@ -3982,13 +3985,13 @@ function Kn(e) {
|
|
|
3982
3985
|
}] : [];
|
|
3983
3986
|
})).filter((e) => e.role === "a2ui");
|
|
3984
3987
|
}
|
|
3985
|
-
function
|
|
3988
|
+
function Jn(e) {
|
|
3986
3989
|
if (typeof e == "string") return e;
|
|
3987
|
-
if (Array.isArray(e)) return e.map(
|
|
3990
|
+
if (Array.isArray(e)) return e.map(Jn).join("");
|
|
3988
3991
|
let t = Q(e), n = t.text ?? t.content ?? t.parts;
|
|
3989
|
-
return n === void 0 ? "" :
|
|
3992
|
+
return n === void 0 ? "" : Jn(n);
|
|
3990
3993
|
}
|
|
3991
|
-
var
|
|
3994
|
+
var Yn = new Set([
|
|
3992
3995
|
"user_message",
|
|
3993
3996
|
"assistant_message",
|
|
3994
3997
|
"assistant_stream_snapshot",
|
|
@@ -4015,9 +4018,9 @@ var Jn = new Set([
|
|
|
4015
4018
|
"run.failed",
|
|
4016
4019
|
"run.canceled"
|
|
4017
4020
|
]);
|
|
4018
|
-
function
|
|
4021
|
+
function Xn(e, t, n, r, i, a) {
|
|
4019
4022
|
let o = async (i, a) => {
|
|
4020
|
-
let o = await
|
|
4023
|
+
let o = await Un(t, n, e.SeqId, r, i, a), s = Q(o.Content?.session_event), c = s.family === "workflow" && Q(Q(s.payload).legacy_history_event);
|
|
4021
4024
|
return c && c.EventType ? {
|
|
4022
4025
|
...c,
|
|
4023
4026
|
SessionId: n,
|
|
@@ -4041,11 +4044,11 @@ function Yn(e, t, n, r, i, a) {
|
|
|
4041
4044
|
}, l = e.ToolRef;
|
|
4042
4045
|
if (l?.CallId && (l.Kind === "call" || l.Kind === "result")) {
|
|
4043
4046
|
let e = l.Kind === "result", t = async (t, r) => {
|
|
4044
|
-
let i = await o(t, r), a =
|
|
4047
|
+
let i = await o(t, r), a = Le(i), s = a && new Fe(n).translate(a), c = L(s ? [{
|
|
4045
4048
|
...s,
|
|
4046
4049
|
Timestamp: i.Timestamp,
|
|
4047
4050
|
SeqId: i.SeqId
|
|
4048
|
-
}] :
|
|
4051
|
+
}] : Wn([i]), { preserveDistinctEvents: !0 }).flatMap((e) => Object.values(e.tools || {})).find((e) => e.callId === l.CallId), u = e ? c?.output : c?.args;
|
|
4049
4052
|
if (u === void 0) throw Error("历史工具正文与调用标识不一致。");
|
|
4050
4053
|
return u;
|
|
4051
4054
|
}, r = l.ScopeId;
|
|
@@ -4080,7 +4083,7 @@ function Yn(e, t, n, r, i, a) {
|
|
|
4080
4083
|
content: e.EventType,
|
|
4081
4084
|
readHistoryContent: async (e, t) => {
|
|
4082
4085
|
let r = await o(e, t);
|
|
4083
|
-
return
|
|
4086
|
+
return Me(L(Wn([r])), [r], n, i).messages.flatMap((e) => [
|
|
4084
4087
|
e.content,
|
|
4085
4088
|
e.reasoning,
|
|
4086
4089
|
...Object.values(e.tools || {}).map((e) => JSON.stringify(e, null, 2))
|
|
@@ -4088,10 +4091,10 @@ function Yn(e, t, n, r, i, a) {
|
|
|
4088
4091
|
}
|
|
4089
4092
|
};
|
|
4090
4093
|
}
|
|
4091
|
-
function
|
|
4094
|
+
function Zn(e, t, n, r, i, a) {
|
|
4092
4095
|
let o = e.filter((e) => !e.ContentRef).map((e) => e.Event), s = new Set(e.filter((e) => {
|
|
4093
4096
|
if (!e.InputCommandId || e.InboxInput) return !1;
|
|
4094
|
-
let t =
|
|
4097
|
+
let t = Le(e.Event), n = Q(Q(t?.source).metadata), r = Q(t?.snapshot).parts;
|
|
4095
4098
|
return e.EventType === "user_message" || t?.event_type === "item.completed" && (n.native_item_kind === "userMessage" || Array.isArray(r) && r.some((e) => Q(Q(e).data).type === "userMessage"));
|
|
4096
4099
|
}).map((e) => e.InputCommandId).filter(Boolean)), c = e.filter((e) => e.InboxInput && !s.has(e.InboxInput.CommandId)), l = c.flatMap((e) => e.InboxInput?.Text === void 0 ? [] : [{
|
|
4097
4100
|
...e.Event,
|
|
@@ -4102,11 +4105,11 @@ function Xn(e, t, n, r, i, a) {
|
|
|
4102
4105
|
...e.Event.Metadata,
|
|
4103
4106
|
runtime_metadata: { command_id: e.InboxInput.CommandId }
|
|
4104
4107
|
}
|
|
4105
|
-
}]), u =
|
|
4106
|
-
...
|
|
4107
|
-
...
|
|
4108
|
-
...
|
|
4109
|
-
], o, n, i, a), f = e.filter((e) => e.ContentRef).map((e) =>
|
|
4108
|
+
}]), u = Wn([...o, ...l].sort((e, t) => Number(e.SeqId) - Number(t.SeqId))), d = Me([
|
|
4109
|
+
...L(u, { preserveDistinctEvents: !0 }),
|
|
4110
|
+
...Gn(u),
|
|
4111
|
+
...qn(u)
|
|
4112
|
+
], o, n, i, a), f = e.filter((e) => e.ContentRef).map((e) => Xn(e, t, n, r, i, d.messages));
|
|
4110
4113
|
for (let e of c) {
|
|
4111
4114
|
let i = e.InboxInput;
|
|
4112
4115
|
i.ContentRef && f.push({
|
|
@@ -4125,12 +4128,12 @@ function Xn(e, t, n, r, i, a) {
|
|
|
4125
4128
|
]),
|
|
4126
4129
|
invocationId: e.InvocationId,
|
|
4127
4130
|
commandId: i.CommandId,
|
|
4128
|
-
readHistoryContent: async (i, a) =>
|
|
4131
|
+
readHistoryContent: async (i, a) => Jn(await Vn(t, n, e.SeqId, r, i, a, "inbox"))
|
|
4129
4132
|
});
|
|
4130
4133
|
}
|
|
4131
4134
|
let p = /* @__PURE__ */ new Map();
|
|
4132
4135
|
for (let e of u) {
|
|
4133
|
-
if (!e.EventType ||
|
|
4136
|
+
if (!e.EventType || Yn.has(e.EventType) || e.Content?.session_event) continue;
|
|
4134
4137
|
let t = e.InvocationId || "", n = p.get(t);
|
|
4135
4138
|
n ? n.push(e) : p.set(t, [e]);
|
|
4136
4139
|
}
|
|
@@ -4142,7 +4145,7 @@ function Xn(e, t, n, r, i, a) {
|
|
|
4142
4145
|
historyOrder: { seq: t[0].SeqId },
|
|
4143
4146
|
invocationId: e,
|
|
4144
4147
|
readHistoryContent: async () => t.map((e) => {
|
|
4145
|
-
let t = e.EventType === "progress" ?
|
|
4148
|
+
let t = e.EventType === "progress" ? Jn(e.Content?.parts) : "";
|
|
4146
4149
|
return [
|
|
4147
4150
|
e.SeqId,
|
|
4148
4151
|
e.EventType,
|
|
@@ -4152,33 +4155,33 @@ function Xn(e, t, n, r, i, a) {
|
|
|
4152
4155
|
});
|
|
4153
4156
|
return {
|
|
4154
4157
|
...d,
|
|
4155
|
-
messages: f.length ?
|
|
4158
|
+
messages: f.length ? Ve(xe([...d.messages, ...f])) : d.messages
|
|
4156
4159
|
};
|
|
4157
4160
|
}
|
|
4158
|
-
function
|
|
4161
|
+
function Qn(e) {
|
|
4159
4162
|
if (!e.InvocationId || e.InvocationId !== e.Event.InvocationId || e.ContentRef || e.InboxInput || e.InputCommandId || ![
|
|
4160
4163
|
"assistant_stream_delta",
|
|
4161
4164
|
"text.delta",
|
|
4162
4165
|
"message.delta"
|
|
4163
|
-
].includes(e.Event.EventType || "") ||
|
|
4166
|
+
].includes(e.Event.EventType || "") || Le(e.Event) || e.Event.Content?.session_event) return;
|
|
4164
4167
|
let t = e.Event.Content;
|
|
4165
4168
|
return t?.parts?.map((e) => e.text || "").join("") || t?.text || t?.payload?.text || "";
|
|
4166
4169
|
}
|
|
4167
|
-
var
|
|
4170
|
+
var $n = new Set([
|
|
4168
4171
|
"user_message",
|
|
4169
4172
|
"assistant_message",
|
|
4170
4173
|
"tool_call",
|
|
4171
4174
|
"tool_result"
|
|
4172
4175
|
]);
|
|
4173
|
-
function
|
|
4176
|
+
function er(e) {
|
|
4174
4177
|
let t = e.Event;
|
|
4175
|
-
return
|
|
4178
|
+
return $n.has(e.EventType) && e.EventType === t.EventType && !!(t.EventId?.trim() && e.InvocationId && e.InvocationId === t.InvocationId?.trim()) && Number.isSafeInteger(e.SeqId) && e.SeqId > 0 && e.SeqId === t.SeqId && !e.ContentRef && !e.InboxInput && !e.InputCommandId && !t.Metadata?.RuntimeItem && !t.Metadata?.responses_mirror && Object.keys(t.Content || {}).every((e) => [
|
|
4176
4179
|
"role",
|
|
4177
4180
|
"parts",
|
|
4178
4181
|
"text"
|
|
4179
4182
|
].includes(e));
|
|
4180
4183
|
}
|
|
4181
|
-
function
|
|
4184
|
+
function tr(e, t) {
|
|
4182
4185
|
if (!t || t >= e.length || e[t - 1].SeqId >= e[t].SeqId) return e.length;
|
|
4183
4186
|
let n = new Set(e.slice(0, t).map((e) => e.InvocationId)), r = t;
|
|
4184
4187
|
for (; r < e.length && n.has(e[r].InvocationId);) r++;
|
|
@@ -4186,9 +4189,9 @@ function er(e, t) {
|
|
|
4186
4189
|
for (let t = r; t < e.length; t++) if (n.has(e[t].InvocationId) || i.has(e[t].Event.EventId.trim())) return e.length;
|
|
4187
4190
|
return r;
|
|
4188
4191
|
}
|
|
4189
|
-
function
|
|
4192
|
+
function nr(e, t, n, r, i, a) {
|
|
4190
4193
|
let o = new Map(a?.progress), s = /* @__PURE__ */ new Map(), c = [], l = (e) => {
|
|
4191
|
-
let t = c.at(-1), n =
|
|
4194
|
+
let t = c.at(-1), n = Qn(e), r = t && n !== void 0 && t.InvocationId === e.InvocationId ? Qn(t) : void 0;
|
|
4192
4195
|
r === void 0 ? c.push(e) : c[c.length - 1] = {
|
|
4193
4196
|
...e,
|
|
4194
4197
|
Event: {
|
|
@@ -4197,7 +4200,7 @@ function tr(e, t, n, r, i, a) {
|
|
|
4197
4200
|
}
|
|
4198
4201
|
};
|
|
4199
4202
|
};
|
|
4200
|
-
for (let t of e) if (t.Event.EventType === "progress" && !t.ContentRef && !t.InboxInput && !t.InputCommandId && !t.Event.Content?.session_event && !
|
|
4203
|
+
for (let t of e) if (t.Event.EventType === "progress" && !t.ContentRef && !t.InboxInput && !t.InputCommandId && !t.Event.Content?.session_event && !Le(t.Event)) {
|
|
4201
4204
|
let e = t.InvocationId || "", n = s.get(e) || [];
|
|
4202
4205
|
n.push(t.Event), s.set(e, n);
|
|
4203
4206
|
} else l(t);
|
|
@@ -4209,17 +4212,17 @@ function tr(e, t, n, r, i, a) {
|
|
|
4209
4212
|
newer: n
|
|
4210
4213
|
});
|
|
4211
4214
|
}
|
|
4212
|
-
let u = (a?.hasOnlyPlainChatItems ?? !0) && c.every((e, t) =>
|
|
4215
|
+
let u = (a?.hasOnlyPlainChatItems ?? !0) && c.every((e, t) => er(e) && (!t || c[t - 1].SeqId < e.SeqId)), d = c.length, f = a?.semanticItems || [], p = f, m = a?.semantic, h = e[0]?.SeqId ?? a?.firstSeq;
|
|
4213
4216
|
if (c.length || !m || h === 1 && a?.firstSeq !== 1) {
|
|
4214
4217
|
f.length && l(f[0]), p = c.concat(f.slice(1));
|
|
4215
|
-
let e = u && a ?
|
|
4218
|
+
let e = u && a ? tr(p, d) : p.length;
|
|
4216
4219
|
if (a && e < p.length) {
|
|
4217
|
-
let o =
|
|
4220
|
+
let o = Zn(p.slice(0, e), t, n, r, i, h), s = p[e].SeqId, c = a.semantic.messages.filter((e) => e.historyOrder.seq >= s);
|
|
4218
4221
|
m = {
|
|
4219
4222
|
...o,
|
|
4220
4223
|
messages: o.messages.concat(c)
|
|
4221
4224
|
};
|
|
4222
|
-
} else m =
|
|
4225
|
+
} else m = Zn(p, t, n, r, i, h);
|
|
4223
4226
|
}
|
|
4224
4227
|
let g = [];
|
|
4225
4228
|
for (let [e, t] of o) {
|
|
@@ -4234,7 +4237,7 @@ function tr(e, t, n, r, i, a) {
|
|
|
4234
4237
|
readHistoryContent: async () => {
|
|
4235
4238
|
let e = [];
|
|
4236
4239
|
for (let n = t; n; n = n.newer) for (let t of n.events) {
|
|
4237
|
-
let n =
|
|
4240
|
+
let n = Jn(t.Content?.parts) || Jn(t.Content) || Jn(t.Content?.payload);
|
|
4238
4241
|
e.push([
|
|
4239
4242
|
t.SeqId,
|
|
4240
4243
|
t.EventType,
|
|
@@ -4252,10 +4255,10 @@ function tr(e, t, n, r, i, a) {
|
|
|
4252
4255
|
semanticItems: p,
|
|
4253
4256
|
hasOnlyPlainChatItems: u,
|
|
4254
4257
|
canonicalRunIds: m.canonicalRunIds,
|
|
4255
|
-
messages: g.length ?
|
|
4258
|
+
messages: g.length ? xe([...m.messages, ...g]) : m.messages
|
|
4256
4259
|
};
|
|
4257
4260
|
}
|
|
4258
|
-
async function
|
|
4261
|
+
async function rr(e, t, n, r, i, a) {
|
|
4259
4262
|
let o, s = n, c;
|
|
4260
4263
|
do {
|
|
4261
4264
|
i.throwIfAborted();
|
|
@@ -4269,11 +4272,11 @@ async function nr(e, t, n, r, i, a) {
|
|
|
4269
4272
|
});
|
|
4270
4273
|
if (l.HistoryEpoch !== r || c !== void 0 && l.SnapshotSeqId !== c) throw Error("接续历史来源已变化。");
|
|
4271
4274
|
c = l.SnapshotSeqId;
|
|
4272
|
-
for (let n of
|
|
4275
|
+
for (let n of Hn(l, t, o)) {
|
|
4273
4276
|
if (n.SeqId <= s) throw Error("接续历史条目未前进。");
|
|
4274
4277
|
let r = n.ContentRef ? {
|
|
4275
4278
|
...n.Event,
|
|
4276
|
-
...await
|
|
4279
|
+
...await Un(e, t, n.SeqId, l, i)
|
|
4277
4280
|
} : n.Event;
|
|
4278
4281
|
i.throwIfAborted(), a(r), s = n.SeqId;
|
|
4279
4282
|
}
|
|
@@ -4283,7 +4286,7 @@ async function nr(e, t, n, r, i, a) {
|
|
|
4283
4286
|
}
|
|
4284
4287
|
//#endregion
|
|
4285
4288
|
//#region src/utils/session-event-history.ts
|
|
4286
|
-
async function
|
|
4289
|
+
async function ir(e, t, n, r, i, a = !1) {
|
|
4287
4290
|
if (n.CursorSource !== "runtime") return;
|
|
4288
4291
|
let o = r?.events.filter((e) => e.EventType === "run_status").sort((e, t) => Number(t.SeqId) - Number(e.SeqId))[0];
|
|
4289
4292
|
if (o || r && !r.hasMore && r.loadedCount >= r.total) return o;
|
|
@@ -4315,24 +4318,24 @@ async function rr(e, t, n, r, i, a = !1) {
|
|
|
4315
4318
|
if (e?.EventType === "run_status" && (e.SessionId === t || !a && !e.SessionId)) return e;
|
|
4316
4319
|
}
|
|
4317
4320
|
}
|
|
4318
|
-
var
|
|
4321
|
+
var ar = class extends Error {
|
|
4319
4322
|
seq;
|
|
4320
4323
|
constructor(e) {
|
|
4321
4324
|
super(`Session event seq ${e} was received twice with conflicting content`), this.name = "SessionEventConflictError", this.seq = e;
|
|
4322
4325
|
}
|
|
4323
4326
|
};
|
|
4324
|
-
function
|
|
4325
|
-
return Array.isArray(e) ? `[${e.map(
|
|
4327
|
+
function or(e) {
|
|
4328
|
+
return Array.isArray(e) ? `[${e.map(or).join(",")}]` : e && typeof e == "object" ? `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${JSON.stringify(e)}:${or(t)}`).join(",")}}` : JSON.stringify(e) ?? "null";
|
|
4326
4329
|
}
|
|
4327
|
-
var
|
|
4330
|
+
var sr = new Set(["runtime"]), cr = class {
|
|
4328
4331
|
eventsBySeq = /* @__PURE__ */ new Map();
|
|
4329
4332
|
lastSeqValue = 0;
|
|
4330
4333
|
accept(e) {
|
|
4331
|
-
let t =
|
|
4334
|
+
let t = d(e);
|
|
4332
4335
|
if (!t.ok) throw t.error;
|
|
4333
4336
|
let n = t.value, r = this.eventsBySeq.get(n.seq);
|
|
4334
4337
|
if (r) {
|
|
4335
|
-
if (
|
|
4338
|
+
if (or(r) !== or(n)) throw new ar(n.seq);
|
|
4336
4339
|
return;
|
|
4337
4340
|
}
|
|
4338
4341
|
this.eventsBySeq.set(n.seq, n), this.lastSeqValue = Math.max(this.lastSeqValue, n.seq);
|
|
@@ -4344,41 +4347,41 @@ var or = new Set(["runtime"]), sr = class {
|
|
|
4344
4347
|
return this.lastSeqValue;
|
|
4345
4348
|
}
|
|
4346
4349
|
displayableEvents() {
|
|
4347
|
-
return [...this.eventsBySeq.values()].filter((e) =>
|
|
4350
|
+
return [...this.eventsBySeq.values()].filter((e) => sr.has(e.family)).sort((e, t) => e.seq - t.seq);
|
|
4348
4351
|
}
|
|
4349
4352
|
};
|
|
4350
|
-
function
|
|
4351
|
-
return new
|
|
4353
|
+
function lr() {
|
|
4354
|
+
return new cr();
|
|
4352
4355
|
}
|
|
4353
4356
|
//#endregion
|
|
4354
4357
|
//#region src/hooks/useSessionLifecycle.ts
|
|
4355
|
-
var
|
|
4356
|
-
function
|
|
4358
|
+
var ur = 500, dr = 2e3, fr = 3, pr = 30, mr = 50, hr = 100, gr = 200, _r = 3, vr = 64, yr = 8, br = 128, xr = 1800 * 1e3;
|
|
4359
|
+
function Sr(e, t) {
|
|
4357
4360
|
return !(e.CursorSource !== t.CursorSource || e.HistoryEpoch !== t.HistoryEpoch || e.SnapshotSeqId !== void 0 && t.SnapshotSeqId !== void 0 && e.SnapshotSeqId !== t.SnapshotSeqId || !e.CursorSource && (e.CursorCompatibleWithRuntime === !1 || t.CursorCompatibleWithRuntime === !1));
|
|
4358
4361
|
}
|
|
4359
|
-
function
|
|
4362
|
+
function Cr(e) {
|
|
4360
4363
|
return {
|
|
4361
4364
|
CursorSource: e.cursorSource,
|
|
4362
4365
|
HistoryEpoch: e.historyEpoch,
|
|
4363
4366
|
SnapshotSeqId: e.snapshotSeqId
|
|
4364
4367
|
};
|
|
4365
4368
|
}
|
|
4366
|
-
function
|
|
4369
|
+
function wr(e) {
|
|
4367
4370
|
if (!(e instanceof X) || !e.detail || typeof e.detail != "object") return;
|
|
4368
4371
|
let t = e.detail;
|
|
4369
4372
|
return typeof t.ReasonCode == "string" ? t.ReasonCode : void 0;
|
|
4370
4373
|
}
|
|
4371
|
-
function
|
|
4372
|
-
return e instanceof X && e.code === 409 &&
|
|
4374
|
+
function Tr(e) {
|
|
4375
|
+
return e instanceof X && e.code === 409 && wr(e) === "HISTORY_RELOAD_REQUIRED";
|
|
4373
4376
|
}
|
|
4374
|
-
function
|
|
4377
|
+
function Er() {
|
|
4375
4378
|
return new X(409, "历史来源已变化", {
|
|
4376
4379
|
Code: 409,
|
|
4377
4380
|
ReasonCode: "HISTORY_RELOAD_REQUIRED",
|
|
4378
4381
|
Data: null
|
|
4379
4382
|
});
|
|
4380
4383
|
}
|
|
4381
|
-
function
|
|
4384
|
+
function Dr(e, t) {
|
|
4382
4385
|
return {
|
|
4383
4386
|
signal: t,
|
|
4384
4387
|
historyView: e.historyView ?? (e.cursorSource === "runtime" && e.historyEpoch && e.snapshotSeqId !== void 0 ? "items-v1" : void 0),
|
|
@@ -4387,28 +4390,28 @@ function wr(e, t) {
|
|
|
4387
4390
|
cursorSource: e.cursorSource,
|
|
4388
4391
|
historyEpoch: e.historyEpoch,
|
|
4389
4392
|
snapshotSeqId: e.snapshotSeqId,
|
|
4390
|
-
limit: e.historyView === "items-v1" ?
|
|
4393
|
+
limit: e.historyView === "items-v1" ? gr : mr,
|
|
4391
4394
|
includeReasoning: !0,
|
|
4392
4395
|
includeToolEvents: !0,
|
|
4393
4396
|
includeAttachments: !0
|
|
4394
4397
|
};
|
|
4395
4398
|
}
|
|
4396
|
-
async function
|
|
4399
|
+
async function Or(e, t, n, r, i, a, o) {
|
|
4397
4400
|
let s = new Set(r.messages.map((e) => e.id)), c = n.itemCursor, l = o, u = r.firstSeq, d = r, f = [], p = new Set([c]);
|
|
4398
4401
|
for (let r = 1;; r++) {
|
|
4399
|
-
if (!
|
|
4402
|
+
if (!Sr({
|
|
4400
4403
|
CursorSource: n.cursorSource,
|
|
4401
4404
|
HistoryEpoch: n.historyEpoch,
|
|
4402
4405
|
SnapshotSeqId: n.snapshotSeqId
|
|
4403
|
-
}, l) || l.HistoryView !== "items-v1") throw
|
|
4404
|
-
let o =
|
|
4405
|
-
if (o.length && u != null && o.at(-1).SeqId >= u) throw
|
|
4406
|
-
if (u = o[0]?.SeqId ?? u, f = o.concat(f), d =
|
|
4406
|
+
}, l) || l.HistoryView !== "items-v1") throw Er();
|
|
4407
|
+
let o = Hn(l, t, c);
|
|
4408
|
+
if (o.length && u != null && o.at(-1).SeqId >= u) throw Er();
|
|
4409
|
+
if (u = o[0]?.SeqId ?? u, f = o.concat(f), d = nr(o, e, t, l, i, d), !l.HasMore || r >= _r || d.messages.some((e) => e.role !== "system" && !s.has(e.id))) return {
|
|
4407
4410
|
page: l,
|
|
4408
4411
|
items: f,
|
|
4409
4412
|
projection: d
|
|
4410
4413
|
};
|
|
4411
|
-
if (c = l.NextItemCursor, p.has(c)) throw
|
|
4414
|
+
if (c = l.NextItemCursor, p.has(c)) throw Er();
|
|
4412
4415
|
p.add(c), l = await a({
|
|
4413
4416
|
...n,
|
|
4414
4417
|
itemCursor: c,
|
|
@@ -4416,7 +4419,7 @@ async function Tr(e, t, n, r, i, a, o) {
|
|
|
4416
4419
|
});
|
|
4417
4420
|
}
|
|
4418
4421
|
}
|
|
4419
|
-
function
|
|
4422
|
+
function kr(e) {
|
|
4420
4423
|
return {
|
|
4421
4424
|
historyView: e.HistoryView,
|
|
4422
4425
|
nextItemCursor: e.NextItemCursor,
|
|
@@ -4434,37 +4437,37 @@ function Er(e) {
|
|
|
4434
4437
|
preparing: !1
|
|
4435
4438
|
};
|
|
4436
4439
|
}
|
|
4437
|
-
function $(e, t, n, r, i =
|
|
4440
|
+
function $(e, t, n, r, i = br) {
|
|
4438
4441
|
for (e.delete(t), e.set(t, n); e.size > i;) {
|
|
4439
4442
|
let t = [...e.keys()].find((e) => e !== r);
|
|
4440
4443
|
if (!t) break;
|
|
4441
4444
|
e.delete(t);
|
|
4442
4445
|
}
|
|
4443
4446
|
}
|
|
4444
|
-
function
|
|
4445
|
-
return new Promise((
|
|
4446
|
-
if (e
|
|
4447
|
-
|
|
4447
|
+
function Ar(e, t = ur) {
|
|
4448
|
+
return new Promise((n) => {
|
|
4449
|
+
if (e?.aborted) {
|
|
4450
|
+
n();
|
|
4448
4451
|
return;
|
|
4449
4452
|
}
|
|
4450
|
-
let
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4453
|
+
let r = () => {
|
|
4454
|
+
globalThis.clearTimeout(i), e?.removeEventListener("abort", r), n();
|
|
4455
|
+
}, i = globalThis.setTimeout(r, t);
|
|
4456
|
+
e?.addEventListener("abort", r, { once: !0 });
|
|
4454
4457
|
});
|
|
4455
4458
|
}
|
|
4456
|
-
var
|
|
4459
|
+
var jr = new Set([
|
|
4457
4460
|
"in_progress",
|
|
4458
4461
|
"running",
|
|
4459
4462
|
"resuming",
|
|
4460
4463
|
"starting"
|
|
4461
4464
|
]);
|
|
4462
|
-
function
|
|
4465
|
+
function Mr(e) {
|
|
4463
4466
|
let t = e.ActiveRunUpdatedAt || e.UpdatedAt, n = typeof t == "number" ? t > 1e11 ? t : t * 1e3 : Date.parse(String(t || ""));
|
|
4464
|
-
return Number.isFinite(n) && n <= Date.now() +
|
|
4467
|
+
return Number.isFinite(n) && n <= Date.now() + xr && Date.now() - n <= xr;
|
|
4465
4468
|
}
|
|
4466
|
-
function
|
|
4467
|
-
let t =
|
|
4469
|
+
function Nr(e) {
|
|
4470
|
+
let t = ie(e);
|
|
4468
4471
|
return t ? t === "completed" ? {
|
|
4469
4472
|
status: "completed",
|
|
4470
4473
|
phase: "后台长任务已完成"
|
|
@@ -4482,76 +4485,80 @@ function Ar(e) {
|
|
|
4482
4485
|
phase: "后台长任务恢复失败"
|
|
4483
4486
|
} : null : null;
|
|
4484
4487
|
}
|
|
4485
|
-
function
|
|
4486
|
-
let { agentId: r, api:
|
|
4487
|
-
|
|
4488
|
-
let
|
|
4488
|
+
function Pr(e) {
|
|
4489
|
+
let { agentId: r, api: a, isMobile: o, resetCompaction: s, uiCapabilities: u, disconnectRun: d, restoreSession: f = !0 } = e, p = Y(e.currentSessionId), m = Y(e.agentId), g = Y(u);
|
|
4490
|
+
g.current = u;
|
|
4491
|
+
let v = Y(null), y = Y(0), b = Y(null);
|
|
4492
|
+
J(() => () => {
|
|
4493
|
+
y.current += 1, b.current?.abort();
|
|
4494
|
+
}, [a]);
|
|
4495
|
+
let x = Y(null), C = Y(null), w = Y(/* @__PURE__ */ new Map()), T = Y(null);
|
|
4489
4496
|
J(() => () => {
|
|
4490
|
-
|
|
4491
|
-
}, [e.currentSessionId,
|
|
4492
|
-
let
|
|
4493
|
-
let r = n.filter((e) =>
|
|
4497
|
+
T.current?.sessionId === e.currentSessionId && (T.current?.controller.abort(), T.current = null);
|
|
4498
|
+
}, [e.currentSessionId, a]);
|
|
4499
|
+
let te = Y(/* @__PURE__ */ new Map()), D = Y(/* @__PURE__ */ new Map()), O = Y(/* @__PURE__ */ new Map()), k = Y(/* @__PURE__ */ new Map()), A = Y(/* @__PURE__ */ new Map()), j = Y(/* @__PURE__ */ new Map()), N = Y(/* @__PURE__ */ new Map()), P = Y(/* @__PURE__ */ new Map()), F = Y(null), I = Y(null), L = Y(null), R = Y(null), z = Y(null), ae = q(async (e, t, n) => {
|
|
4500
|
+
let r = n.filter((e) => ue(e, !1, !1));
|
|
4494
4501
|
if (!r.length) return;
|
|
4495
|
-
let
|
|
4502
|
+
let i = await Promise.all(r.map(async (n) => {
|
|
4496
4503
|
try {
|
|
4497
|
-
let r = await
|
|
4504
|
+
let r = await a.getResponseFeedback({
|
|
4498
4505
|
AgentId: e,
|
|
4499
4506
|
SessionId: t,
|
|
4500
4507
|
ResponseId: n.responseId,
|
|
4501
4508
|
EventId: n.eventId
|
|
4502
|
-
}),
|
|
4503
|
-
return
|
|
4509
|
+
}), i = r?.Feedback ? oe(r.Feedback) : null;
|
|
4510
|
+
return i ? {
|
|
4504
4511
|
messageId: n.id,
|
|
4505
|
-
feedback:
|
|
4512
|
+
feedback: i
|
|
4506
4513
|
} : null;
|
|
4507
4514
|
} catch (e) {
|
|
4508
4515
|
return console.error("Failed to load response feedback:", e), null;
|
|
4509
4516
|
}
|
|
4510
4517
|
}));
|
|
4511
|
-
if (
|
|
4512
|
-
let o = new Map(
|
|
4513
|
-
o.size &&
|
|
4518
|
+
if (p.current !== t) return;
|
|
4519
|
+
let o = new Map(i.filter((e) => !!e).map((e) => [e.messageId, e.feedback]));
|
|
4520
|
+
o.size && G.getState().patchMessages((e) => e.map((e) => o.has(e.id) ? {
|
|
4514
4521
|
...e,
|
|
4515
4522
|
feedback: o.get(e.id)
|
|
4516
4523
|
} : e));
|
|
4517
|
-
}, [
|
|
4518
|
-
|
|
4524
|
+
}, [a]), B = q(async (e) => {
|
|
4525
|
+
v.current?.abort();
|
|
4519
4526
|
let t = new AbortController();
|
|
4520
|
-
|
|
4521
|
-
let n = !1, r = !1,
|
|
4527
|
+
v.current = t;
|
|
4528
|
+
let n = !1, r = !1, i = !1, o = l.getState(), s = o.agentId === m.current ? o.capabilities : g.current, u = s.KernelSessionEventsByCommand === !0, d = de(s.ConversationSurface, Ce), f = new _e(e.sessionId, void 0, d), _ = u ? 0 : e.afterSeqId, y = () => v.current === t && p.current === e.sessionId, b = lr(), x = !1, S = (t) => {
|
|
4522
4529
|
if (t.InvocationId && t.InvocationId !== e.invocationId) return;
|
|
4523
4530
|
let i = t.seq;
|
|
4524
4531
|
typeof i == "number" && b.accept(t);
|
|
4525
4532
|
let a = typeof i == "number" ? i : Number(t.SeqId || 0);
|
|
4526
|
-
if (a > 0 && a <=
|
|
4527
|
-
|
|
4533
|
+
if (a > 0 && a <= _) return;
|
|
4534
|
+
h.getState().updateActivity({
|
|
4528
4535
|
sessionId: e.sessionId,
|
|
4529
4536
|
status: "running",
|
|
4530
4537
|
phase: "正在处理",
|
|
4531
4538
|
countEvent: !1
|
|
4532
4539
|
});
|
|
4533
4540
|
let o = t.Content?.runtime_event;
|
|
4534
|
-
if (u && o?.schema_version === 2 && o.run_id === e.invocationId &&
|
|
4535
|
-
let t =
|
|
4536
|
-
|
|
4541
|
+
if (u && o?.schema_version === 2 && o.run_id === e.invocationId && f.apply(o)) {
|
|
4542
|
+
let t = f.snapshot();
|
|
4543
|
+
_n({
|
|
4537
4544
|
type: "conversation_snapshot",
|
|
4538
4545
|
sessionId: e.sessionId,
|
|
4539
4546
|
result: {
|
|
4540
4547
|
state: t,
|
|
4541
|
-
presentation:
|
|
4548
|
+
presentation: ge(t, { profile: d }),
|
|
4542
4549
|
runId: e.invocationId,
|
|
4543
|
-
cursor: a ||
|
|
4550
|
+
cursor: a || _
|
|
4544
4551
|
}
|
|
4545
4552
|
});
|
|
4546
4553
|
}
|
|
4547
|
-
if (
|
|
4554
|
+
if (_n({
|
|
4548
4555
|
type: "stream_event",
|
|
4549
4556
|
sessionId: e.sessionId,
|
|
4550
4557
|
event: t
|
|
4551
|
-
}),
|
|
4558
|
+
}), ne(t)) {
|
|
4552
4559
|
r = !0, n = !0;
|
|
4553
|
-
let i =
|
|
4554
|
-
i &&
|
|
4560
|
+
let i = Nr(t);
|
|
4561
|
+
i && h.getState().updateActivity({
|
|
4555
4562
|
sessionId: e.sessionId,
|
|
4556
4563
|
status: i.status,
|
|
4557
4564
|
phase: i.phase,
|
|
@@ -4559,10 +4566,10 @@ function jr(e) {
|
|
|
4559
4566
|
countEvent: !1
|
|
4560
4567
|
});
|
|
4561
4568
|
}
|
|
4562
|
-
a > 0 && (
|
|
4569
|
+
a > 0 && (_ = a);
|
|
4563
4570
|
};
|
|
4564
4571
|
try {
|
|
4565
|
-
for (
|
|
4572
|
+
for (h.getState().setCurrentRunId(e.invocationId), h.getState().setActiveInvocationId(e.invocationId), h.getState().setSessionStreaming(e.sessionId, !0), h.getState().updateActivity({
|
|
4566
4573
|
sessionId: e.sessionId,
|
|
4567
4574
|
runId: e.invocationId,
|
|
4568
4575
|
source: "restore",
|
|
@@ -4572,31 +4579,31 @@ function jr(e) {
|
|
|
4572
4579
|
countEvent: !1
|
|
4573
4580
|
}); !r && y();) {
|
|
4574
4581
|
try {
|
|
4575
|
-
let
|
|
4576
|
-
if (x &&
|
|
4582
|
+
let i = c.getState().messageHistory[e.sessionId];
|
|
4583
|
+
if (x && i?.historyView === "items-v1" && i.historyEpoch && (_ = await rr(a, e.sessionId, _, i.historyEpoch, t.signal, (e) => {
|
|
4577
4584
|
y() && S(e);
|
|
4578
4585
|
}), r || !y())) break;
|
|
4579
4586
|
x = !0;
|
|
4580
|
-
let o = await
|
|
4587
|
+
let o = await a.subscribeRunEvents({
|
|
4581
4588
|
sessionId: e.sessionId,
|
|
4582
4589
|
invocationId: e.invocationId,
|
|
4583
|
-
afterSeqId:
|
|
4590
|
+
afterSeqId: _
|
|
4584
4591
|
}, { signal: t.signal });
|
|
4585
4592
|
if (!y()) {
|
|
4586
4593
|
t.abort();
|
|
4587
4594
|
return;
|
|
4588
4595
|
}
|
|
4589
|
-
let
|
|
4596
|
+
let s = o.getReader(), l = new TextDecoder(), u = "";
|
|
4590
4597
|
for (; !r && y();) {
|
|
4591
|
-
let { value: t, done: i } = await
|
|
4598
|
+
let { value: t, done: i } = await s.read();
|
|
4592
4599
|
if (i) break;
|
|
4593
4600
|
u += l.decode(t, { stream: !0 });
|
|
4594
|
-
let a =
|
|
4601
|
+
let a = It(u);
|
|
4595
4602
|
u = a.remainder;
|
|
4596
4603
|
for (let t of a.chunks) if (t.trim()) {
|
|
4597
|
-
for (let i of
|
|
4604
|
+
for (let i of Ft(t)) {
|
|
4598
4605
|
if (i.eventName === "__ping__") {
|
|
4599
|
-
|
|
4606
|
+
h.getState().updateActivity({
|
|
4600
4607
|
sessionId: e.sessionId,
|
|
4601
4608
|
status: "running",
|
|
4602
4609
|
phase: "正在处理",
|
|
@@ -4615,22 +4622,22 @@ function jr(e) {
|
|
|
4615
4622
|
if (r) break;
|
|
4616
4623
|
}
|
|
4617
4624
|
}
|
|
4618
|
-
r &&
|
|
4619
|
-
} catch (
|
|
4620
|
-
if (
|
|
4621
|
-
r = !0,
|
|
4625
|
+
r && s.cancel().catch(() => {});
|
|
4626
|
+
} catch (a) {
|
|
4627
|
+
if (a instanceof DOMException && a.name === "AbortError" || a instanceof Z || t.signal.aborted) {
|
|
4628
|
+
r = !0, i = !0, y() && h.getState().stopSessionActivity(e.sessionId, "恢复事件订阅已取消。");
|
|
4622
4629
|
break;
|
|
4623
4630
|
}
|
|
4624
4631
|
if (!y()) break;
|
|
4625
|
-
if (
|
|
4626
|
-
r = !0, n =
|
|
4632
|
+
if (a instanceof X && a.code >= 400 && a.code < 500 && a.code !== 408 && a.code !== 429) {
|
|
4633
|
+
r = !0, n = Tr(a), _n({
|
|
4627
4634
|
type: "error",
|
|
4628
4635
|
sessionId: e.sessionId,
|
|
4629
|
-
error:
|
|
4636
|
+
error: a
|
|
4630
4637
|
});
|
|
4631
4638
|
break;
|
|
4632
4639
|
}
|
|
4633
|
-
console.warn("Run event subscription disconnected; retrying:",
|
|
4640
|
+
console.warn("Run event subscription disconnected; retrying:", a), h.getState().updateActivity({
|
|
4634
4641
|
sessionId: e.sessionId,
|
|
4635
4642
|
status: "waiting",
|
|
4636
4643
|
phase: "恢复连接中",
|
|
@@ -4638,20 +4645,20 @@ function jr(e) {
|
|
|
4638
4645
|
countEvent: !1
|
|
4639
4646
|
});
|
|
4640
4647
|
}
|
|
4641
|
-
!r && y() && await
|
|
4648
|
+
!r && y() && await Ar(t.signal);
|
|
4642
4649
|
}
|
|
4643
|
-
r && !
|
|
4650
|
+
r && !i && y() && _n({
|
|
4644
4651
|
type: "stream_ended",
|
|
4645
4652
|
sessionId: e.sessionId
|
|
4646
4653
|
});
|
|
4647
4654
|
} catch (e) {
|
|
4648
4655
|
e instanceof DOMException && e.name === "AbortError" || console.error("Failed to subscribe run events:", e);
|
|
4649
4656
|
} finally {
|
|
4650
|
-
let r =
|
|
4651
|
-
r && (
|
|
4657
|
+
let r = v.current === t;
|
|
4658
|
+
r && (v.current = null), r && p.current === e.sessionId && (h.getState().setCurrentRunId(""), h.getState().setActiveInvocationId(""), n && R.current?.(e.sessionId), z.current?.(m.current, e.sessionId));
|
|
4652
4659
|
}
|
|
4653
|
-
}, [
|
|
4654
|
-
if (!
|
|
4660
|
+
}, [a]), V = q((e) => {
|
|
4661
|
+
if (!g.current.RunLifecycle.Enabled || !e.runId || m.current !== r || p.current !== e.sessionId || v.current || (N.current.get(e.sessionId)?.events || []).some((t) => {
|
|
4655
4662
|
let n = t.Content?.runtime_event;
|
|
4656
4663
|
return t.InvocationId === e.runId && !n?.parent_scope_id && [
|
|
4657
4664
|
"completed",
|
|
@@ -4660,240 +4667,298 @@ function jr(e) {
|
|
|
4660
4667
|
"cancelled",
|
|
4661
4668
|
"canceled",
|
|
4662
4669
|
"aborted"
|
|
4663
|
-
].includes(
|
|
4670
|
+
].includes(ie(t));
|
|
4664
4671
|
})) return;
|
|
4665
|
-
let t =
|
|
4666
|
-
|
|
4672
|
+
let t = h.getState().getSessionActivity(e.sessionId);
|
|
4673
|
+
h.getState().isSessionStreaming(e.sessionId) && t?.source === "run" && [
|
|
4667
4674
|
"connecting",
|
|
4668
4675
|
"running",
|
|
4669
4676
|
"waiting"
|
|
4670
|
-
].includes(t.status) && (e.extensions?.mcpAuthorization ||
|
|
4677
|
+
].includes(t.status) && (e.extensions?.mcpAuthorization || g.current.KernelSessionEventsByCommand === !0 && t.runId === e.runId) || B({
|
|
4671
4678
|
sessionId: e.sessionId,
|
|
4672
4679
|
invocationId: e.runId,
|
|
4673
|
-
afterSeqId:
|
|
4680
|
+
afterSeqId: M(N.current.get(e.sessionId)?.events || [])
|
|
4674
4681
|
});
|
|
4675
|
-
}, [r, B]), U = q(async (
|
|
4676
|
-
if (
|
|
4677
|
-
L.current = null;
|
|
4678
|
-
let
|
|
4679
|
-
|
|
4680
|
-
let
|
|
4681
|
-
|
|
4682
|
-
let
|
|
4683
|
-
|
|
4684
|
-
let
|
|
4685
|
-
$(
|
|
4686
|
-
},
|
|
4687
|
-
|
|
4688
|
-
let
|
|
4689
|
-
|
|
4690
|
-
let
|
|
4691
|
-
|
|
4692
|
-
sessionId:
|
|
4682
|
+
}, [r, B]), U = q(async function e(r, d = !1, f, w, E = !0) {
|
|
4683
|
+
if (f?.aborted) return;
|
|
4684
|
+
b.current?.abort(), L.current = null;
|
|
4685
|
+
let P = l.getState(), F = P.agentId === m.current ? P.capabilities : g.current, re = de(F.ConversationSurface, Ce);
|
|
4686
|
+
A.current.set(r, re);
|
|
4687
|
+
let I = p.current;
|
|
4688
|
+
T.current?.controller.abort(), T.current = null;
|
|
4689
|
+
let z = ++y.current;
|
|
4690
|
+
x.current = z, C.current = null;
|
|
4691
|
+
let oe = (e, t) => {
|
|
4692
|
+
$(k.current, e, t, p.current, yr);
|
|
4693
|
+
}, V = k.current.get(r), U = O.current.get(r);
|
|
4694
|
+
I && I !== r && (oe(I, G.getState().messages), G.getState().setMessages(V || []), c.getState().clearSessionMessageHistory(r), H.getState().setSessionCheckpoints(r, []), H.getState().setSessionToolReceipts(r, []), h.getState().setCurrentRunId(""), h.getState().clearActivity()), p.current = r;
|
|
4695
|
+
let W = () => p.current === r && y.current === z && !f?.aborted;
|
|
4696
|
+
c.getState().setCurrentSessionId(r), c.getState().setSessionInitialMessageHistoryLoading(r, !V);
|
|
4697
|
+
let se = h.getState();
|
|
4698
|
+
se.isSessionStreaming(r) && se.updateActivity({
|
|
4699
|
+
sessionId: r,
|
|
4693
4700
|
phase: "正在同步任务进展",
|
|
4694
4701
|
countEvent: !1
|
|
4695
|
-
}),
|
|
4696
|
-
let
|
|
4697
|
-
|
|
4698
|
-
let
|
|
4699
|
-
if (!
|
|
4700
|
-
let
|
|
4701
|
-
if (
|
|
4702
|
-
let
|
|
4702
|
+
}), s();
|
|
4703
|
+
let ce = G.getState().messages;
|
|
4704
|
+
v.current?.abort();
|
|
4705
|
+
let K = F.RunLifecycle.Enabled && F.RunLifecycle.Resume, le = n(F), ue = t(le), fe = F.KernelSessionEventsByCommand === !0 && le?.Protocol === "ag-ui" && le.Capabilities.SessionEventReplay === !0, pe = (e) => {
|
|
4706
|
+
if (!W() || !e.ActiveInvocationId) return;
|
|
4707
|
+
let t = h.getState();
|
|
4708
|
+
if (t.getSessionActivity(r)?.runId !== e.ActiveInvocationId) return;
|
|
4709
|
+
let n = Nr({
|
|
4703
4710
|
EventType: "run_status",
|
|
4704
|
-
Content: { status:
|
|
4711
|
+
Content: { status: e.ActiveRunStatus }
|
|
4705
4712
|
});
|
|
4706
|
-
|
|
4707
|
-
sessionId:
|
|
4708
|
-
...
|
|
4713
|
+
n && (t.setSessionStreaming(r, !1), t.updateActivity({
|
|
4714
|
+
sessionId: r,
|
|
4715
|
+
...n,
|
|
4709
4716
|
countEvent: !1
|
|
4710
4717
|
}));
|
|
4711
4718
|
};
|
|
4712
|
-
|
|
4719
|
+
o && _.getState().setMobileSidebarOpen(!1);
|
|
4713
4720
|
try {
|
|
4714
4721
|
let t = {
|
|
4715
4722
|
historyView: "items-v1",
|
|
4716
|
-
limit:
|
|
4723
|
+
limit: hr,
|
|
4717
4724
|
includeReasoning: !0,
|
|
4718
4725
|
includeToolEvents: !0,
|
|
4719
4726
|
includeAttachments: !0,
|
|
4720
|
-
signal:
|
|
4721
|
-
}, n = await
|
|
4722
|
-
isCurrent:
|
|
4723
|
-
signal:
|
|
4727
|
+
signal: f
|
|
4728
|
+
}, n = await Cn(() => a.listSessionMessages(r, t), {
|
|
4729
|
+
isCurrent: W,
|
|
4730
|
+
signal: f,
|
|
4724
4731
|
onPreparing: () => {
|
|
4725
|
-
let
|
|
4726
|
-
|
|
4727
|
-
...
|
|
4728
|
-
nextCursor:
|
|
4729
|
-
hasMore:
|
|
4732
|
+
let e = c.getState().messageHistory[r];
|
|
4733
|
+
c.getState().setSessionMessageHistory(r, {
|
|
4734
|
+
...e,
|
|
4735
|
+
nextCursor: e?.nextCursor ?? null,
|
|
4736
|
+
hasMore: e?.hasMore ?? !1,
|
|
4730
4737
|
preparing: !0,
|
|
4731
4738
|
error: void 0
|
|
4732
|
-
}),
|
|
4739
|
+
}), c.getState().setSessionInitialMessageHistoryLoading(r, !V);
|
|
4733
4740
|
}
|
|
4734
4741
|
});
|
|
4735
|
-
if (!
|
|
4736
|
-
let
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4742
|
+
if (!W()) return;
|
|
4743
|
+
let o = ue && n.CursorSource === "runtime" && !!n.HistoryEpoch && n.HistoryEpochSource !== "server-event-anchor", s, g = fe ? new Promise((e) => {
|
|
4744
|
+
s = e;
|
|
4745
|
+
}) : void 0, _ = ue || K || fe ? (async () => {
|
|
4746
|
+
if (fe) {
|
|
4747
|
+
let e = new AbortController();
|
|
4748
|
+
b.current = e;
|
|
4749
|
+
let t = () => e.abort();
|
|
4750
|
+
f?.addEventListener("abort", t, { once: !0 });
|
|
4751
|
+
try {
|
|
4752
|
+
let t = async () => {
|
|
4753
|
+
let t = i(await a.getAgentStatus({
|
|
4754
|
+
agentId: m.current,
|
|
4755
|
+
sessionId: r,
|
|
4756
|
+
signal: e.signal
|
|
4757
|
+
}));
|
|
4758
|
+
if (t.session_id !== r || t.instance_state === "unavailable") throw Error("Kernel status is unavailable for this session");
|
|
4759
|
+
return t;
|
|
4760
|
+
}, n, o = ur, c = 0;
|
|
4761
|
+
for (; !e.signal.aborted && W();) {
|
|
4762
|
+
try {
|
|
4763
|
+
if (n = await t(), n.active_run_id || n.active_run_state !== "pending" && n.inbox_depth === 0) break;
|
|
4764
|
+
} catch (t) {
|
|
4765
|
+
if (e.signal.aborted) return { session: {} };
|
|
4766
|
+
if (!(t instanceof TypeError || t instanceof X && [
|
|
4767
|
+
408,
|
|
4768
|
+
429,
|
|
4769
|
+
500,
|
|
4770
|
+
502,
|
|
4771
|
+
503,
|
|
4772
|
+
504
|
|
4773
|
+
].includes(t.code)) || !n && c >= fr) throw t;
|
|
4774
|
+
n || (c += 1);
|
|
4775
|
+
}
|
|
4776
|
+
s?.(), await Ar(e.signal, o), o = Math.min(o * 2, dr);
|
|
4777
|
+
}
|
|
4778
|
+
if (!n || e.signal.aborted || !W()) return { session: {} };
|
|
4779
|
+
let l = n.active_run_state, u = l === "running" || l === "pending", d = n.extensions.session_event_seq;
|
|
4780
|
+
return {
|
|
4781
|
+
session: u && n.active_run_id ? {
|
|
4782
|
+
ActiveInvocationId: n.active_run_id,
|
|
4783
|
+
ActiveRunStatus: l === "pending" ? "starting" : "running"
|
|
4784
|
+
} : {},
|
|
4785
|
+
kernelSeq: typeof d == "number" && Number.isSafeInteger(d) && d >= 0 ? d : void 0
|
|
4786
|
+
};
|
|
4787
|
+
} catch (t) {
|
|
4788
|
+
if (e.signal.aborted) return { session: {} };
|
|
4789
|
+
if (!K || !W() || t instanceof Z) throw t;
|
|
4790
|
+
} finally {
|
|
4791
|
+
f?.removeEventListener("abort", t), b.current === e && (b.current = null);
|
|
4792
|
+
}
|
|
4793
|
+
}
|
|
4794
|
+
let e = K ? await a.getSession(r) : {};
|
|
4795
|
+
if (pe(e), o && W()) {
|
|
4796
|
+
let t = await ir(a, r, n, void 0, f, !0);
|
|
4797
|
+
t && (e = {
|
|
4798
|
+
ActiveInvocationId: t.InvocationId,
|
|
4799
|
+
ActiveRunStatus: ie(t)
|
|
4800
|
+
}, pe(e));
|
|
4744
4801
|
}
|
|
4745
|
-
return
|
|
4746
|
-
})().
|
|
4747
|
-
$(
|
|
4748
|
-
let
|
|
4749
|
-
if (!
|
|
4750
|
-
let
|
|
4751
|
-
|
|
4802
|
+
return { session: e };
|
|
4803
|
+
})().catch((e) => ({ error: e })) : void 0, v = n.HistoryView === "items-v1" ? Hn(n, r) : void 0, y = v && nr(v, a, r, n, re), T = zn(n.Messages);
|
|
4804
|
+
$(j.current, r, T, p.current);
|
|
4805
|
+
let O = ze(y?.messages ?? T, U), k = 0, A = y?.canonicalRunIds ?? [];
|
|
4806
|
+
if (!V) {
|
|
4807
|
+
let e = De(O, ce, G.getState().messages);
|
|
4808
|
+
G.getState().setMessages(e), ce = O, oe(r, e);
|
|
4752
4809
|
}
|
|
4753
|
-
if (
|
|
4810
|
+
if (c.getState().setSessionMessageHistory(r, {
|
|
4754
4811
|
nextCursor: n.NextCursor,
|
|
4755
4812
|
hasMore: n.HasMore,
|
|
4756
|
-
...
|
|
4757
|
-
}),
|
|
4758
|
-
let
|
|
4759
|
-
$(
|
|
4760
|
-
itemProjection:
|
|
4761
|
-
events:
|
|
4813
|
+
...kr(n)
|
|
4814
|
+
}), c.getState().setSessionInitialMessageHistoryLoading(r, !1), v) {
|
|
4815
|
+
let e = v.filter((e) => !e.ContentRef).map((e) => e.Event);
|
|
4816
|
+
$(N.current, r, {
|
|
4817
|
+
itemProjection: y,
|
|
4818
|
+
events: e,
|
|
4762
4819
|
hasMore: n.HasMore,
|
|
4763
|
-
loadedCount:
|
|
4764
|
-
total:
|
|
4820
|
+
loadedCount: v.length,
|
|
4821
|
+
total: v.length,
|
|
4765
4822
|
cursorSource: n.CursorSource,
|
|
4766
4823
|
historyEpoch: n.HistoryEpoch,
|
|
4767
4824
|
snapshotSeqId: n.SnapshotSeqId
|
|
4768
|
-
},
|
|
4769
|
-
for (let
|
|
4825
|
+
}, p.current);
|
|
4826
|
+
for (let t of e) S(t, r);
|
|
4770
4827
|
} else try {
|
|
4771
|
-
let
|
|
4828
|
+
let e = await a.listSessionEvents(r, {
|
|
4772
4829
|
offset: 0,
|
|
4773
|
-
limit:
|
|
4774
|
-
signal:
|
|
4830
|
+
limit: vr,
|
|
4831
|
+
signal: f,
|
|
4775
4832
|
historyEpoch: n.CursorSource === "runtime" ? n.HistoryEpoch : void 0,
|
|
4776
4833
|
snapshotSeqId: n.CursorSource === "runtime" ? n.SnapshotSeqId : void 0
|
|
4777
4834
|
});
|
|
4778
|
-
if (!
|
|
4779
|
-
let
|
|
4780
|
-
if (
|
|
4781
|
-
let
|
|
4782
|
-
events:
|
|
4783
|
-
loadedCount:
|
|
4784
|
-
total:
|
|
4785
|
-
cursorSource:
|
|
4786
|
-
historyEpoch:
|
|
4787
|
-
snapshotSeqId:
|
|
4835
|
+
if (!W()) return;
|
|
4836
|
+
let t = Sr(n, e), i = e.Events, o = [...T].reverse().find((e) => e.invocationId && Object.values(e.tools || {}).some((e) => e.name === "call_a2a_agent"))?.invocationId;
|
|
4837
|
+
if (t && F.KernelSessionEventsByCommand === !0 && e.CursorSource === "runtime" && o && (i = await wn(a, r, o, e, W, f), !W())) return;
|
|
4838
|
+
let s = {
|
|
4839
|
+
events: t ? i : [],
|
|
4840
|
+
loadedCount: t ? i.length : 0,
|
|
4841
|
+
total: t ? Math.max(0, Number(e.Total ?? e.Events?.length ?? 0) || 0) : 0,
|
|
4842
|
+
cursorSource: t ? e.CursorSource : void 0,
|
|
4843
|
+
historyEpoch: t ? e.HistoryEpoch : void 0,
|
|
4844
|
+
snapshotSeqId: t ? e.SnapshotSeqId : void 0
|
|
4788
4845
|
};
|
|
4789
|
-
if ($(
|
|
4846
|
+
if ($(N.current, r, s, p.current), c.getState().setSessionMessageHistory(r, {
|
|
4790
4847
|
nextCursor: n.NextCursor,
|
|
4791
|
-
hasMore: !!(n.HasMore ||
|
|
4792
|
-
}),
|
|
4793
|
-
|
|
4794
|
-
for (let
|
|
4795
|
-
let
|
|
4796
|
-
|
|
4848
|
+
hasMore: !!(n.HasMore || s.loadedCount < s.total)
|
|
4849
|
+
}), s.events.length > 0) {
|
|
4850
|
+
k = M(s.events);
|
|
4851
|
+
for (let e of s.events) S(e, r);
|
|
4852
|
+
let e = Me(T, s.events, r, re);
|
|
4853
|
+
A = e.canonicalRunIds, O = ze(e.messages, U);
|
|
4797
4854
|
}
|
|
4798
|
-
if (
|
|
4799
|
-
let
|
|
4800
|
-
if (!
|
|
4801
|
-
for (let
|
|
4802
|
-
|
|
4803
|
-
generation:
|
|
4855
|
+
if (t) {
|
|
4856
|
+
let t = await On(a, r, T, e, W, f);
|
|
4857
|
+
if (!W()) return;
|
|
4858
|
+
for (let e of t.events) S(e, r);
|
|
4859
|
+
t.incomplete && (C.current = {
|
|
4860
|
+
generation: z,
|
|
4804
4861
|
message: "部分交互历史尚未恢复完整,旧卡片保持只读。请加载较早消息后重试。"
|
|
4805
|
-
},
|
|
4806
|
-
...
|
|
4862
|
+
}, c.getState().setSessionMessageHistory(r, {
|
|
4863
|
+
...c.getState().messageHistory[r],
|
|
4807
4864
|
nextCursor: n.NextCursor,
|
|
4808
|
-
hasMore: !!(n.HasMore ||
|
|
4865
|
+
hasMore: !!(n.HasMore || s.loadedCount < s.total),
|
|
4809
4866
|
error: "部分交互历史尚未恢复完整,旧卡片保持只读。请加载较早消息后重试。"
|
|
4810
4867
|
}));
|
|
4811
4868
|
}
|
|
4812
4869
|
} catch (e) {
|
|
4813
|
-
if (
|
|
4814
|
-
|
|
4815
|
-
generation:
|
|
4870
|
+
if (Tr(e)) throw e;
|
|
4871
|
+
W() && (C.current = {
|
|
4872
|
+
generation: z,
|
|
4816
4873
|
message: "完整事件历史读取失败,请刷新会话后重新查找。当前结果只包含已读取的正文。"
|
|
4817
4874
|
}), console.warn("[SessionLifecycle] canonical history replay failed:", e);
|
|
4818
4875
|
}
|
|
4819
|
-
if (!
|
|
4820
|
-
ee(
|
|
4821
|
-
let
|
|
4822
|
-
|
|
4823
|
-
agentId:
|
|
4824
|
-
sessionId:
|
|
4825
|
-
}).then((
|
|
4826
|
-
|
|
4827
|
-
}).catch((
|
|
4828
|
-
|
|
4829
|
-
}),
|
|
4830
|
-
agentId:
|
|
4831
|
-
sessionId:
|
|
4832
|
-
}).then((
|
|
4833
|
-
|
|
4834
|
-
}).catch((
|
|
4835
|
-
|
|
4836
|
-
})) :
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
let
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
let
|
|
4851
|
-
if (
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
...
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4876
|
+
if (!W()) return;
|
|
4877
|
+
ee(O, r), $(te.current, r, new Set(A), p.current), $(D.current, r, O, p.current), O = De(O, ce, G.getState().messages), G.getState().setMessages(O), oe(r, O), x.current = null, ae(m.current, r, O);
|
|
4878
|
+
let P = Math.max(n.LatestSeqId || 0, k), I = l.getState().capabilities || u;
|
|
4879
|
+
I.RunLifecycle.Enabled && I.RunLifecycle.Checkpoints ? (a.listSessionCheckpoints({
|
|
4880
|
+
agentId: m.current,
|
|
4881
|
+
sessionId: r
|
|
4882
|
+
}).then((e) => {
|
|
4883
|
+
W() && H.getState().setSessionCheckpoints(r, e.Checkpoints || []);
|
|
4884
|
+
}).catch((e) => {
|
|
4885
|
+
W() && (console.warn("[SessionLifecycle] checkpoint load failed:", e), H.getState().setSessionCheckpoints(r, []));
|
|
4886
|
+
}), a.listToolReceipts({
|
|
4887
|
+
agentId: m.current,
|
|
4888
|
+
sessionId: r
|
|
4889
|
+
}).then((e) => {
|
|
4890
|
+
W() && H.getState().setSessionToolReceipts(r, e.ToolReceipts || []);
|
|
4891
|
+
}).catch((e) => {
|
|
4892
|
+
W() && (console.warn("[SessionLifecycle] tool receipt load failed:", e), H.getState().setSessionToolReceipts(r, []));
|
|
4893
|
+
})) : H.getState().clearSessionCheckpoints(r);
|
|
4894
|
+
let L = _ && (async () => {
|
|
4895
|
+
try {
|
|
4896
|
+
let t = await _;
|
|
4897
|
+
if ("error" in t) throw t.error;
|
|
4898
|
+
let i = t.session;
|
|
4899
|
+
if (ue && !o && !i.ActiveInvocationId && W()) {
|
|
4900
|
+
let e = N.current.get(r), t = await ir(a, r, n, e && Sr(n, Cr(e)) ? e : void 0, f);
|
|
4901
|
+
t && (i = {
|
|
4902
|
+
ActiveInvocationId: t.InvocationId,
|
|
4903
|
+
ActiveRunStatus: ie(t)
|
|
4904
|
+
});
|
|
4905
|
+
}
|
|
4906
|
+
if (!W()) return;
|
|
4907
|
+
let s = String(i.ActiveRunStatus || "").toLowerCase(), c = !!i.ActiveInvocationId && (jr.has(s) || s === "" && Mr(i));
|
|
4908
|
+
if (!c && E && t.kernelSeq !== void 0 && n.CursorSource === "runtime" && n.CursorCompatibleWithRuntime !== !1 && n.HistoryEpochSource !== "server-event-anchor" && t.kernelSeq > (n.SnapshotSeqId ?? P)) {
|
|
4909
|
+
await e(r, d, f, w, !1);
|
|
4910
|
+
return;
|
|
4911
|
+
}
|
|
4912
|
+
if (c && i.ActiveInvocationId !== w) {
|
|
4913
|
+
let e = h.getState(), t = e.getSessionActivity(r), n = e.isSessionStreaming(r);
|
|
4914
|
+
if (t?.runId && (t.runId === i.ActiveInvocationId ? [
|
|
4915
|
+
"completed",
|
|
4916
|
+
"failed",
|
|
4917
|
+
"stopped"
|
|
4918
|
+
].includes(t.status) : n && t.source === "run")) return;
|
|
4919
|
+
let a = (F.KernelSessionEventsByCommand === !0 || ue) && n && t?.source === "run" && t.runId === i.ActiveInvocationId && [
|
|
4920
|
+
"connecting",
|
|
4921
|
+
"running",
|
|
4922
|
+
"waiting"
|
|
4923
|
+
].includes(t.status);
|
|
4924
|
+
a && h.getState().updateActivity({
|
|
4925
|
+
sessionId: r,
|
|
4926
|
+
phase: "正在处理",
|
|
4927
|
+
countEvent: !1
|
|
4928
|
+
}), a || B({
|
|
4929
|
+
sessionId: r,
|
|
4930
|
+
invocationId: i.ActiveInvocationId,
|
|
4931
|
+
afterSeqId: P
|
|
4932
|
+
});
|
|
4933
|
+
} else {
|
|
4934
|
+
let e = h.getState(), t = e.getSessionActivity(r), n = i.ActiveInvocationId && t?.runId === i.ActiveInvocationId ? Nr({
|
|
4935
|
+
EventType: "run_status",
|
|
4936
|
+
Content: { status: s }
|
|
4937
|
+
}) : null, a = t?.runId ? [...N.current.get(r)?.events || []].reverse().find((e) => {
|
|
4938
|
+
let n = e.Content?.runtime_event;
|
|
4939
|
+
return e.InvocationId === t.runId && !n?.parent_scope_id && ne(e);
|
|
4940
|
+
}) : void 0, o = n || a && Nr(a);
|
|
4941
|
+
o && (e.setSessionStreaming(r, !1), e.updateActivity({
|
|
4942
|
+
sessionId: r,
|
|
4943
|
+
...o,
|
|
4944
|
+
countEvent: !1
|
|
4945
|
+
}));
|
|
4946
|
+
}
|
|
4947
|
+
} catch (e) {
|
|
4948
|
+
if (console.warn("[SessionLifecycle] getSession for reconnect failed:", e), W()) {
|
|
4949
|
+
let e = h.getState();
|
|
4950
|
+
e.isSessionStreaming(r) && e.getSessionActivity(r)?.phase === "正在同步任务进展" && e.updateActivity({
|
|
4951
|
+
sessionId: r,
|
|
4952
|
+
phase: "正在确认任务状态",
|
|
4953
|
+
countEvent: !1
|
|
4954
|
+
});
|
|
4955
|
+
}
|
|
4892
4956
|
}
|
|
4893
|
-
}
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4957
|
+
})();
|
|
4958
|
+
L && await (g ? Promise.race([L, g]) : L);
|
|
4959
|
+
} catch (e) {
|
|
4960
|
+
if (Tr(e) && !d && W()) {
|
|
4961
|
+
c.getState().setSessionMessageHistory(r, {
|
|
4897
4962
|
nextItemCursor: null,
|
|
4898
4963
|
historyView: void 0,
|
|
4899
4964
|
nextCursor: null,
|
|
@@ -4907,22 +4972,22 @@ function jr(e) {
|
|
|
4907
4972
|
cursorCompatibleWithRuntime: void 0,
|
|
4908
4973
|
sessionContractVersion: void 0
|
|
4909
4974
|
}), queueMicrotask(() => {
|
|
4910
|
-
|
|
4975
|
+
W() && R.current?.(r, !0);
|
|
4911
4976
|
});
|
|
4912
4977
|
return;
|
|
4913
4978
|
}
|
|
4914
|
-
if (
|
|
4915
|
-
let
|
|
4916
|
-
|
|
4917
|
-
generation:
|
|
4918
|
-
message:
|
|
4979
|
+
if (W() && !(e instanceof Z)) {
|
|
4980
|
+
let t = d ? "历史来源已变化,重新加载失败。原有消息已保留,请手动刷新会话。" : Sn(e) ? "历史仍在准备,请稍后重试。" : "会话历史读取失败,请重试。已有消息已保留。";
|
|
4981
|
+
C.current = {
|
|
4982
|
+
generation: z,
|
|
4983
|
+
message: t
|
|
4919
4984
|
};
|
|
4920
|
-
let
|
|
4921
|
-
|
|
4922
|
-
...
|
|
4923
|
-
nextCursor:
|
|
4924
|
-
hasMore:
|
|
4925
|
-
...
|
|
4985
|
+
let n = c.getState().messageHistory[r];
|
|
4986
|
+
c.getState().setSessionMessageHistory(r, {
|
|
4987
|
+
...n,
|
|
4988
|
+
nextCursor: n?.nextCursor ?? null,
|
|
4989
|
+
hasMore: n?.hasMore ?? !1,
|
|
4990
|
+
...d ? {
|
|
4926
4991
|
nextCursor: null,
|
|
4927
4992
|
hasMore: !1,
|
|
4928
4993
|
cursorSource: void 0,
|
|
@@ -4931,99 +4996,99 @@ function jr(e) {
|
|
|
4931
4996
|
snapshotSeqId: void 0
|
|
4932
4997
|
} : {},
|
|
4933
4998
|
preparing: !1,
|
|
4934
|
-
error:
|
|
4999
|
+
error: t,
|
|
4935
5000
|
retryOlderPage: !1
|
|
4936
|
-
}),
|
|
5001
|
+
}), d && _.getState().pushToast(t, "error");
|
|
4937
5002
|
}
|
|
4938
|
-
|
|
5003
|
+
e instanceof Z || console.error("Failed to load session messages:", e);
|
|
4939
5004
|
} finally {
|
|
4940
|
-
|
|
5005
|
+
x.current === z && (x.current = null), W() && c.getState().setSessionInitialMessageHistoryLoading(r, !1);
|
|
4941
5006
|
}
|
|
4942
5007
|
}, [
|
|
4943
|
-
i,
|
|
4944
5008
|
a,
|
|
4945
|
-
re,
|
|
4946
5009
|
o,
|
|
5010
|
+
ae,
|
|
5011
|
+
s,
|
|
4947
5012
|
B,
|
|
4948
|
-
|
|
4949
|
-
]),
|
|
4950
|
-
if (
|
|
4951
|
-
let n =
|
|
4952
|
-
n && $(
|
|
4953
|
-
}, [U]),
|
|
4954
|
-
let r =
|
|
5013
|
+
u
|
|
5014
|
+
]), W = q((e, t) => {
|
|
5015
|
+
if (p.current !== e) return;
|
|
5016
|
+
let n = G.getState().messages.find((e) => e.role === "user" && (e.runId || e.invocationId) === t);
|
|
5017
|
+
n && $(O.current, e, n, e), U(e, !1, void 0, t);
|
|
5018
|
+
}, [U]), ce = q((e, t, n) => {
|
|
5019
|
+
let r = k.current, i = r.get(e);
|
|
4955
5020
|
i?.some((e) => e.id === t) && r.set(e, i.map((e) => e.id === t ? {
|
|
4956
5021
|
...e,
|
|
4957
5022
|
...n
|
|
4958
5023
|
} : e));
|
|
4959
|
-
}, []),
|
|
4960
|
-
let n =
|
|
5024
|
+
}, []), K = q(async (e = "default-agent", t = null) => {
|
|
5025
|
+
let n = c.getState();
|
|
4961
5026
|
n.sessionsAgentId && n.sessionsAgentId !== e && n.resetSessionPagination(e);
|
|
4962
|
-
let r =
|
|
5027
|
+
let r = c.getState().sessionsGeneration, i = () => l.getState().agentId === e && c.getState().sessionsGeneration === r;
|
|
4963
5028
|
try {
|
|
4964
|
-
|
|
4965
|
-
let n = await
|
|
5029
|
+
c.getState().setLoadingSessions(!0);
|
|
5030
|
+
let n = await a.listSessions(e, {
|
|
4966
5031
|
page: 1,
|
|
4967
|
-
pageSize:
|
|
5032
|
+
pageSize: pr
|
|
4968
5033
|
});
|
|
4969
|
-
if (!
|
|
5034
|
+
if (!i()) return;
|
|
4970
5035
|
let r = n.Sessions || [];
|
|
4971
|
-
for (let e of r)
|
|
4972
|
-
let o = new Set(Array.from(
|
|
4973
|
-
if (
|
|
5036
|
+
for (let e of r) P.current.delete(e.SessionId);
|
|
5037
|
+
let o = new Set(Array.from(P.current.entries()).filter(([, t]) => t === e).map(([e]) => e)), s = dt(r, c.getState().sessions, o);
|
|
5038
|
+
if (c.getState().upsertSessions(s, {
|
|
4974
5039
|
agentId: e,
|
|
4975
5040
|
total: Number(n.Total ?? n.Sessions?.length ?? 0),
|
|
4976
5041
|
page: Number(n.Page ?? 1),
|
|
4977
|
-
pageSize: Number(n.PageSize ??
|
|
5042
|
+
pageSize: Number(n.PageSize ?? pr),
|
|
4978
5043
|
replace: !0
|
|
4979
|
-
}),
|
|
4980
|
-
let l =
|
|
4981
|
-
|
|
5044
|
+
}), I.current || L.current === e) return;
|
|
5045
|
+
let l = c.getState().sessions, u = p.current, d = u || (f ? ut(l, t || ct(e)) : null);
|
|
5046
|
+
d && d !== u && U(d);
|
|
4982
5047
|
} catch (e) {
|
|
4983
5048
|
if (e instanceof Z) return;
|
|
4984
5049
|
console.error("Failed to fetch sessions:", e);
|
|
4985
5050
|
} finally {
|
|
4986
|
-
|
|
5051
|
+
i() && c.getState().setLoadingSessions(!1);
|
|
4987
5052
|
}
|
|
4988
5053
|
}, [
|
|
4989
|
-
|
|
5054
|
+
a,
|
|
4990
5055
|
U,
|
|
4991
|
-
|
|
4992
|
-
]),
|
|
4993
|
-
|
|
4994
|
-
let n =
|
|
4995
|
-
if (
|
|
5056
|
+
f
|
|
5057
|
+
]), le = q((e, t) => {
|
|
5058
|
+
f && t && !p.current && !I.current && L.current !== e && (m.current = e, U(t));
|
|
5059
|
+
let n = K(e, t);
|
|
5060
|
+
if (f && !p.current && L.current !== e) {
|
|
4996
5061
|
let e = {
|
|
4997
5062
|
ready: n,
|
|
4998
5063
|
cancelled: !1
|
|
4999
5064
|
};
|
|
5000
|
-
|
|
5001
|
-
|
|
5065
|
+
F.current = e, n.finally(() => {
|
|
5066
|
+
F.current === e && (F.current = null);
|
|
5002
5067
|
});
|
|
5003
5068
|
}
|
|
5004
5069
|
return n;
|
|
5005
5070
|
}, [
|
|
5006
|
-
|
|
5071
|
+
K,
|
|
5007
5072
|
U,
|
|
5008
|
-
|
|
5009
|
-
]),
|
|
5010
|
-
let e =
|
|
5073
|
+
f
|
|
5074
|
+
]), fe = q((...e) => (F.current && (F.current.cancelled = !0), U(...e)), [U]), pe = q(async () => {
|
|
5075
|
+
let e = c.getState();
|
|
5011
5076
|
if (e.isLoadingSessions || !e.hasMoreSessions) return;
|
|
5012
|
-
let t =
|
|
5077
|
+
let t = E({
|
|
5013
5078
|
total: e.sessionsTotal,
|
|
5014
|
-
pageSize: e.sessionsPageSize ||
|
|
5079
|
+
pageSize: e.sessionsPageSize || pr,
|
|
5015
5080
|
loadedPages: e.loadedPages
|
|
5016
5081
|
});
|
|
5017
5082
|
if (!t) return;
|
|
5018
|
-
let n = e.sessionsPageSize ||
|
|
5083
|
+
let n = e.sessionsPageSize || pr, r = e.sessionsAgentId || m.current || "default-agent", i = () => l.getState().agentId === r && c.getState().sessionsGeneration === e.sessionsGeneration;
|
|
5019
5084
|
try {
|
|
5020
|
-
|
|
5021
|
-
let o = await
|
|
5085
|
+
c.getState().setLoadingSessions(!0);
|
|
5086
|
+
let o = await a.listSessions(r, {
|
|
5022
5087
|
page: t,
|
|
5023
5088
|
pageSize: n
|
|
5024
5089
|
});
|
|
5025
|
-
if (!
|
|
5026
|
-
|
|
5090
|
+
if (!i()) return;
|
|
5091
|
+
c.getState().upsertSessions(o.Sessions || [], {
|
|
5027
5092
|
agentId: r,
|
|
5028
5093
|
total: Number(o.Total ?? e.sessionsTotal),
|
|
5029
5094
|
page: Number(o.Page ?? t),
|
|
@@ -5033,98 +5098,98 @@ function jr(e) {
|
|
|
5033
5098
|
if (e instanceof Z) return;
|
|
5034
5099
|
console.error("Failed to load more sessions:", e);
|
|
5035
5100
|
} finally {
|
|
5036
|
-
|
|
5101
|
+
i() && c.getState().setLoadingSessions(!1);
|
|
5037
5102
|
}
|
|
5038
|
-
}, [
|
|
5103
|
+
}, [a]);
|
|
5039
5104
|
J(() => {
|
|
5040
5105
|
R.current = U;
|
|
5041
5106
|
}, [U]), J(() => {
|
|
5042
|
-
z.current =
|
|
5043
|
-
}, [
|
|
5044
|
-
let
|
|
5045
|
-
if (L.current = null, t &&
|
|
5046
|
-
|
|
5107
|
+
z.current = K;
|
|
5108
|
+
}, [K]);
|
|
5109
|
+
let me = q((e, t = !1) => {
|
|
5110
|
+
if (L.current = null, t && p.current === e) {
|
|
5111
|
+
c.getState().upsertSessions([{
|
|
5047
5112
|
SessionId: e,
|
|
5048
5113
|
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5049
5114
|
}]);
|
|
5050
5115
|
return;
|
|
5051
5116
|
}
|
|
5052
|
-
|
|
5117
|
+
y.current += 1, b.current?.abort(), v.current?.abort(), P.current.set(e, m.current), c.getState().upsertSessions([{
|
|
5053
5118
|
SessionId: e,
|
|
5054
5119
|
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5055
|
-
}]),
|
|
5056
|
-
}, [
|
|
5057
|
-
|
|
5058
|
-
}, [
|
|
5059
|
-
if (
|
|
5060
|
-
await
|
|
5120
|
+
}]), p.current = e, c.getState().setCurrentSessionId(e), t || (G.getState().setMessages([]), h.getState().setCurrentRunId(""), h.getState().clearActivity()), c.getState().clearSessionMessageHistory(e), H.getState().setSessionCheckpoints(e, []), H.getState().setSessionToolReceipts(e, []), o && (_.getState().setMobileSidebarOpen(!1), _.getState().setMobileActionsOpen(!1));
|
|
5121
|
+
}, [o]), he = q(() => {
|
|
5122
|
+
F.current && (F.current.cancelled = !0), lt(m.current, null), L.current = m.current, y.current += 1, b.current?.abort(), v.current?.abort(), p.current = null, c.getState().setCurrentSessionId(null), G.getState().setMessages([]), h.getState().setCurrentRunId(""), h.getState().clearActivity(), o && _.getState().setMobileSidebarOpen(!1);
|
|
5123
|
+
}, [o]), ve = q(async () => {
|
|
5124
|
+
if (I.current) {
|
|
5125
|
+
await I.current;
|
|
5061
5126
|
return;
|
|
5062
5127
|
}
|
|
5063
|
-
|
|
5064
|
-
let e =
|
|
5128
|
+
F.current && (F.current.cancelled = !0), lt(r, null), y.current += 1, b.current?.abort(), v.current?.abort(), p.current = null, c.getState().setCurrentSessionId(null), G.getState().setMessages([]);
|
|
5129
|
+
let e = a.createSession(r).then((e) => {
|
|
5065
5130
|
let t = e.SessionId || null;
|
|
5066
|
-
return t &&
|
|
5131
|
+
return t && l.getState().agentId === r && me(t, G.getState().messages.some((e) => e.eventType === "optimistic_user_message" || e.eventType === "optimistic_assistant_placeholder")), t;
|
|
5067
5132
|
}).catch((e) => (e instanceof Z || console.error("Failed to create session:", e), null));
|
|
5068
|
-
|
|
5133
|
+
I.current = e;
|
|
5069
5134
|
try {
|
|
5070
5135
|
await e;
|
|
5071
5136
|
} finally {
|
|
5072
|
-
|
|
5137
|
+
I.current === e && (I.current = null);
|
|
5073
5138
|
}
|
|
5074
5139
|
}, [
|
|
5075
|
-
|
|
5140
|
+
me,
|
|
5076
5141
|
r,
|
|
5077
|
-
|
|
5078
|
-
]),
|
|
5079
|
-
let e =
|
|
5142
|
+
a
|
|
5143
|
+
]), ye = q(async () => {
|
|
5144
|
+
let e = I.current;
|
|
5080
5145
|
if (e) return await e;
|
|
5081
|
-
let t =
|
|
5082
|
-
if (!
|
|
5083
|
-
return
|
|
5084
|
-
}, []),
|
|
5146
|
+
let t = F.current;
|
|
5147
|
+
if (!p.current && t && !t.cancelled && (await t.ready, t.cancelled)) throw new Z();
|
|
5148
|
+
return p.current;
|
|
5149
|
+
}, []), be = q(async (e) => {
|
|
5085
5150
|
try {
|
|
5086
|
-
let t = await
|
|
5087
|
-
return
|
|
5151
|
+
let t = await a.deleteSession(e);
|
|
5152
|
+
return l.getState().agentId === r ? t.Deleted === !1 ? (_.getState().pushToast("会话暂未删除,云端运行时仍在同步,请稍后重试。", "error"), K(r, p.current ?? void 0), !1) : (c.getState().removeSession(e), c.getState().clearSessionMessageHistory(e), k.current.delete(e), j.current.delete(e), A.current.delete(e), N.current.delete(e), te.current.delete(e), D.current.delete(e), O.current.delete(e), P.current.delete(e), p.current === e && (lt(r, null), y.current += 1, b.current?.abort(), v.current?.abort(), d?.(), p.current = null, G.getState().setMessages([]), H.getState().clearSessionCheckpoints(e), c.getState().setCurrentSessionId(null), h.getState().setCurrentRunId(""), h.getState().clearActivity(), K(r)), !0) : t.Deleted !== !1;
|
|
5088
5153
|
} catch (e) {
|
|
5089
|
-
return e instanceof Z ? !1 : (console.error("Failed to delete session", e),
|
|
5154
|
+
return e instanceof Z ? !1 : (console.error("Failed to delete session", e), _.getState().pushToast("删除会话失败,请稍后重试。", "error"), !1);
|
|
5090
5155
|
}
|
|
5091
5156
|
}, [
|
|
5092
5157
|
r,
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
]),
|
|
5097
|
-
let t =
|
|
5098
|
-
if (
|
|
5099
|
-
let
|
|
5100
|
-
if (o?.sessionId === e && o.generation ===
|
|
5158
|
+
a,
|
|
5159
|
+
d,
|
|
5160
|
+
K
|
|
5161
|
+
]), Se = q((e) => {
|
|
5162
|
+
let t = c.getState().messageHistory[e], n = N.current.get(e)?.itemProjection, r = se(t);
|
|
5163
|
+
if (p.current !== e || !t || r === null || t.isLoadingInitial || t.isLoadingOlder || t.historyView === "items-v1" && !n) return;
|
|
5164
|
+
let i = y.current, o = T.current;
|
|
5165
|
+
if (o?.sessionId === e && o.generation === i && o.cursor === r && o.projection === n) return;
|
|
5101
5166
|
o?.controller.abort();
|
|
5102
|
-
let
|
|
5103
|
-
|
|
5167
|
+
let s = new AbortController(), l = Dr(t, s.signal), u = A.current.get(e) || "flat-v1", d = (t) => (s.signal.throwIfAborted(), a.listSessionMessages(e, t));
|
|
5168
|
+
T.current = {
|
|
5104
5169
|
sessionId: e,
|
|
5105
|
-
generation:
|
|
5170
|
+
generation: i,
|
|
5106
5171
|
cursor: r,
|
|
5107
5172
|
projection: n,
|
|
5108
|
-
controller:
|
|
5173
|
+
controller: s,
|
|
5109
5174
|
result: d(l).then(async (t) => {
|
|
5110
|
-
let r = n && l.itemCursor ? await
|
|
5175
|
+
let r = n && l.itemCursor ? await Or(a, e, l, n, u, d, t) : null;
|
|
5111
5176
|
return {
|
|
5112
5177
|
page: r?.page ?? t,
|
|
5113
5178
|
batch: r
|
|
5114
5179
|
};
|
|
5115
5180
|
}).catch(() => null)
|
|
5116
5181
|
};
|
|
5117
|
-
}, [
|
|
5182
|
+
}, [a]), we = q(async (e, t) => {
|
|
5118
5183
|
t?.throwIfAborted();
|
|
5119
|
-
let n =
|
|
5120
|
-
if (!n || n.isLoadingOlder || !
|
|
5121
|
-
let
|
|
5122
|
-
|
|
5123
|
-
let d = () =>
|
|
5184
|
+
let n = c.getState().messageHistory[e], r = N.current.get(e), i = !!(n?.hasMore && (n.nextCursor !== null || n.nextItemCursor)), o = !!(r && r.loadedCount < r.total);
|
|
5185
|
+
if (!n || n.isLoadingOlder || !i && !o) return;
|
|
5186
|
+
let s = y.current, l = D.current.get(e) || G.getState().messages, u = Symbol(e);
|
|
5187
|
+
w.current.set(e, u);
|
|
5188
|
+
let d = () => p.current === e && y.current === s && w.current.get(e) === u && !t?.aborted, f = {
|
|
5124
5189
|
isCurrent: d,
|
|
5125
5190
|
signal: t,
|
|
5126
5191
|
onPreparing: () => {
|
|
5127
|
-
|
|
5192
|
+
c.getState().setSessionMessageHistory(e, {
|
|
5128
5193
|
...n,
|
|
5129
5194
|
preparing: !0,
|
|
5130
5195
|
error: void 0,
|
|
@@ -5133,136 +5198,136 @@ function jr(e) {
|
|
|
5133
5198
|
}
|
|
5134
5199
|
};
|
|
5135
5200
|
try {
|
|
5136
|
-
|
|
5137
|
-
let h =
|
|
5138
|
-
let n =
|
|
5139
|
-
if (!t && n?.sessionId === e && n.generation ===
|
|
5201
|
+
c.getState().setSessionMessageHistoryLoading(e, !0);
|
|
5202
|
+
let h = Dr(n, t), g = (t) => Cn(() => a.listSessionMessages(e, t), f), [_, v] = await Promise.allSettled([i ? (async () => {
|
|
5203
|
+
let n = T.current;
|
|
5204
|
+
if (!t && n?.sessionId === e && n.generation === s && n.cursor === (h.itemCursor ?? h.beforeSeqId) && n.projection === r?.itemProjection) {
|
|
5140
5205
|
let e = await n.result;
|
|
5141
|
-
if (
|
|
5206
|
+
if (T.current === n && (T.current = null), e) return e;
|
|
5142
5207
|
}
|
|
5143
5208
|
return {
|
|
5144
5209
|
page: await g(h),
|
|
5145
5210
|
batch: null
|
|
5146
5211
|
};
|
|
5147
|
-
})() : Promise.resolve(null), o && r ?
|
|
5212
|
+
})() : Promise.resolve(null), o && r ? Cn(() => a.listSessionEvents(e, {
|
|
5148
5213
|
signal: t,
|
|
5149
5214
|
offset: r.loadedCount,
|
|
5150
|
-
limit:
|
|
5215
|
+
limit: vr,
|
|
5151
5216
|
cursorSource: r.cursorSource,
|
|
5152
5217
|
historyEpoch: r.historyEpoch,
|
|
5153
5218
|
snapshotSeqId: r.snapshotSeqId
|
|
5154
|
-
}),
|
|
5155
|
-
if (t?.throwIfAborted(),
|
|
5156
|
-
let
|
|
5219
|
+
}), f) : Promise.resolve(null)]);
|
|
5220
|
+
if (t?.throwIfAborted(), p.current !== e || y.current !== s || w.current.get(e) !== u) return;
|
|
5221
|
+
let b = v.status === "rejected" && v.reason instanceof X && [
|
|
5157
5222
|
429,
|
|
5158
5223
|
502,
|
|
5159
5224
|
503,
|
|
5160
5225
|
504
|
|
5161
|
-
].includes(
|
|
5162
|
-
if (
|
|
5226
|
+
].includes(v.reason.code);
|
|
5227
|
+
if (v.status === "rejected" && !b) throw v.reason;
|
|
5163
5228
|
if (_.status === "rejected") throw _.reason;
|
|
5164
|
-
let
|
|
5165
|
-
if (
|
|
5229
|
+
let x = _.value?.page ?? null, E = v.status === "fulfilled" ? v.value : null, M = b ? "消息正文已加载,部分事件详情暂时读取失败,请重试加载更早记录。" : void 0;
|
|
5230
|
+
if (x && !Sr({
|
|
5166
5231
|
CursorSource: n.cursorSource,
|
|
5167
5232
|
HistoryEpoch: n.historyEpoch,
|
|
5168
5233
|
SnapshotSeqId: n.snapshotSeqId,
|
|
5169
5234
|
CursorCompatibleWithRuntime: n.cursorCompatibleWithRuntime
|
|
5170
|
-
},
|
|
5171
|
-
generation:
|
|
5172
|
-
message:
|
|
5173
|
-
} :
|
|
5174
|
-
let
|
|
5175
|
-
if (
|
|
5176
|
-
let
|
|
5235
|
+
}, x) || E && r && !Sr(Cr(r), E) || (M ? C.current = {
|
|
5236
|
+
generation: s,
|
|
5237
|
+
message: M
|
|
5238
|
+
} : E && (C.current = null), n.historyView === "items-v1" && x?.HistoryView !== "items-v1")) throw Er();
|
|
5239
|
+
let P, F;
|
|
5240
|
+
if (x?.HistoryView === "items-v1") {
|
|
5241
|
+
let i = r?.itemProjection, o = A.current.get(e) || "flat-v1", s = _.value?.batch ?? (!t && i && h.itemCursor ? await Or(a, e, h, i, o, g, x) : null);
|
|
5177
5242
|
if (!d()) return;
|
|
5178
|
-
let c = s?.page ??
|
|
5179
|
-
|
|
5180
|
-
let u = s?.items ??
|
|
5181
|
-
if (!
|
|
5182
|
-
let p =
|
|
5243
|
+
let c = s?.page ?? x;
|
|
5244
|
+
x = c;
|
|
5245
|
+
let u = s?.items ?? Hn(c, e, n.nextItemCursor), f = i?.firstSeq ?? n.nextCursor;
|
|
5246
|
+
if (!i && (n.historyView === "items-v1" || n.cursorSource !== "runtime" || !n.historyEpoch || n.snapshotSeqId !== c.SnapshotSeqId || f == null) || u.length && f != null && u.at(-1).SeqId >= f) throw Er();
|
|
5247
|
+
let p = i ? r?.legacySuffix : {
|
|
5183
5248
|
messages: l,
|
|
5184
5249
|
boundary: f,
|
|
5185
|
-
canonicalRunIds: [...
|
|
5186
|
-
}, m = s?.projection ??
|
|
5187
|
-
if (
|
|
5250
|
+
canonicalRunIds: [...te.current.get(e) || []]
|
|
5251
|
+
}, m = s?.projection ?? nr(u, a, e, c, o, i);
|
|
5252
|
+
if (P = m, p) {
|
|
5188
5253
|
let e = p.messages.filter((e) => {
|
|
5189
5254
|
let t = e.historyOrder?.seq;
|
|
5190
5255
|
return t == null || t >= p.boundary || c.HasMore && m.firstSeq != null && t < m.firstSeq;
|
|
5191
5256
|
}), t = new Set(e.map((e) => e.id));
|
|
5192
|
-
|
|
5193
|
-
messages:
|
|
5257
|
+
P = {
|
|
5258
|
+
messages: xe([...m.messages.filter((e) => !t.has(e.id)), ...e]),
|
|
5194
5259
|
canonicalRunIds: [...new Set([...m.canonicalRunIds, ...p.canonicalRunIds])]
|
|
5195
5260
|
};
|
|
5196
5261
|
}
|
|
5197
|
-
let v = u.filter((e) => !e.ContentRef).map((e) => e.Event), y = (
|
|
5198
|
-
|
|
5262
|
+
let v = u.filter((e) => !e.ContentRef).map((e) => e.Event), y = (i ? r.loadedCount : 0) + u.length;
|
|
5263
|
+
F = {
|
|
5199
5264
|
itemProjection: m,
|
|
5200
5265
|
legacySuffix: p,
|
|
5201
5266
|
hasMore: c.HasMore,
|
|
5202
|
-
events: [...v.filter((e) => e.EventType === "run_status" ||
|
|
5267
|
+
events: [...v.filter((e) => e.EventType === "run_status" || ne(e)), ...r?.events || []],
|
|
5203
5268
|
loadedCount: y,
|
|
5204
5269
|
total: y,
|
|
5205
5270
|
historyEpoch: c.HistoryEpoch,
|
|
5206
5271
|
snapshotSeqId: c.SnapshotSeqId,
|
|
5207
5272
|
cursorSource: c.CursorSource
|
|
5208
5273
|
};
|
|
5209
|
-
for (let t of v)
|
|
5210
|
-
|
|
5274
|
+
for (let t of v) S(t, e);
|
|
5275
|
+
C.current = null, M = void 0;
|
|
5211
5276
|
}
|
|
5212
|
-
let
|
|
5213
|
-
$(
|
|
5214
|
-
let
|
|
5215
|
-
if (
|
|
5216
|
-
else if (
|
|
5217
|
-
let t =
|
|
5218
|
-
|
|
5219
|
-
events:
|
|
5220
|
-
loadedCount:
|
|
5221
|
-
total:
|
|
5222
|
-
cursorSource:
|
|
5223
|
-
historyEpoch:
|
|
5224
|
-
snapshotSeqId:
|
|
5225
|
-
},
|
|
5226
|
-
for (let n of t)
|
|
5277
|
+
let I = x ? zn(x.Messages) : [], L = new Set(I.map((e) => e.id)), ie = [...I, ...(j.current.get(e) || []).filter((e) => !L.has(e.id))];
|
|
5278
|
+
$(j.current, e, ie, p.current);
|
|
5279
|
+
let R = r?.events || [], z = r?.loadedCount || 0, B = r?.total || 0;
|
|
5280
|
+
if (F) z = B = F.loadedCount;
|
|
5281
|
+
else if (E) {
|
|
5282
|
+
let t = E.Events || [];
|
|
5283
|
+
R = re(t, R), B = Math.max(B, Number(E.Total ?? 0) || 0), z = t.length > 0 ? Math.min(B, z + t.length) : B, $(N.current, e, {
|
|
5284
|
+
events: R,
|
|
5285
|
+
loadedCount: z,
|
|
5286
|
+
total: B,
|
|
5287
|
+
cursorSource: E.CursorSource ?? r?.cursorSource,
|
|
5288
|
+
historyEpoch: E.HistoryEpoch ?? r?.historyEpoch,
|
|
5289
|
+
snapshotSeqId: E.SnapshotSeqId ?? r?.snapshotSeqId
|
|
5290
|
+
}, p.current);
|
|
5291
|
+
for (let n of t) S(n, e);
|
|
5227
5292
|
}
|
|
5228
|
-
if (
|
|
5229
|
-
let n = await
|
|
5230
|
-
Events:
|
|
5293
|
+
if (I.length && r) {
|
|
5294
|
+
let n = await On(a, e, I, {
|
|
5295
|
+
Events: R,
|
|
5231
5296
|
CursorSource: r.cursorSource,
|
|
5232
5297
|
HistoryEpoch: r.historyEpoch,
|
|
5233
5298
|
SnapshotSeqId: r.snapshotSeqId
|
|
5234
5299
|
}, d, t);
|
|
5235
5300
|
if (!d()) return;
|
|
5236
|
-
for (let t of n.events)
|
|
5237
|
-
n.incomplete && (
|
|
5238
|
-
generation:
|
|
5239
|
-
message:
|
|
5301
|
+
for (let t of n.events) S(t, e);
|
|
5302
|
+
n.incomplete && (M = "部分交互历史尚未恢复完整,旧卡片保持只读。请加载较早消息后重试。", C.current = {
|
|
5303
|
+
generation: s,
|
|
5304
|
+
message: M
|
|
5240
5305
|
});
|
|
5241
5306
|
}
|
|
5242
|
-
let
|
|
5243
|
-
|
|
5244
|
-
let
|
|
5245
|
-
$(
|
|
5246
|
-
nextCursor:
|
|
5247
|
-
hasMore: !!(
|
|
5248
|
-
...
|
|
5249
|
-
...
|
|
5250
|
-
dataSource:
|
|
5251
|
-
degraded:
|
|
5252
|
-
cursorSource:
|
|
5253
|
-
cursorCompatibleWithRuntime:
|
|
5254
|
-
sessionContractVersion:
|
|
5255
|
-
historyEpoch:
|
|
5256
|
-
persistenceDegraded:
|
|
5257
|
-
snapshotSeqId:
|
|
5307
|
+
let oe = P ?? Me(ie, R, e, A.current.get(e) || "flat-v1"), V = ze(oe.messages, O.current.get(e));
|
|
5308
|
+
F && $(N.current, e, F, p.current), ee(V, e), $(D.current, e, V, p.current);
|
|
5309
|
+
let H = De(V, l, G.getState().messages, !!P);
|
|
5310
|
+
$(te.current, e, new Set(oe.canonicalRunIds), p.current), G.getState().setMessages(H), $(k.current, e, H, p.current, yr), c.getState().setSessionMessageHistory(e, {
|
|
5311
|
+
nextCursor: x ? x.NextCursor : n.nextCursor,
|
|
5312
|
+
hasMore: !!(x && x.HasMore || z < B),
|
|
5313
|
+
...x ? kr(x) : {},
|
|
5314
|
+
...x ? {
|
|
5315
|
+
dataSource: x.DataSource ?? n.dataSource,
|
|
5316
|
+
degraded: x.Degraded ?? n.degraded,
|
|
5317
|
+
cursorSource: x.CursorSource ?? n.cursorSource,
|
|
5318
|
+
cursorCompatibleWithRuntime: x.CursorCompatibleWithRuntime ?? n.cursorCompatibleWithRuntime,
|
|
5319
|
+
sessionContractVersion: x.SessionContractVersion ?? n.sessionContractVersion,
|
|
5320
|
+
historyEpoch: x.HistoryEpoch ?? n.historyEpoch,
|
|
5321
|
+
persistenceDegraded: x.PersistenceDegraded ?? n.persistenceDegraded,
|
|
5322
|
+
snapshotSeqId: x.SnapshotSeqId ?? n.snapshotSeqId
|
|
5258
5323
|
} : {},
|
|
5259
5324
|
preparing: !1,
|
|
5260
|
-
error:
|
|
5261
|
-
retryOlderPage: !!
|
|
5262
|
-
}),
|
|
5325
|
+
error: M,
|
|
5326
|
+
retryOlderPage: !!M
|
|
5327
|
+
}), ae(m.current, e, I);
|
|
5263
5328
|
} catch (r) {
|
|
5264
|
-
if (
|
|
5265
|
-
|
|
5329
|
+
if (Tr(r) && p.current === e && y.current === s && w.current.get(e) === u && !t?.aborted) {
|
|
5330
|
+
c.getState().setSessionMessageHistory(e, {
|
|
5266
5331
|
nextCursor: null,
|
|
5267
5332
|
nextItemCursor: null,
|
|
5268
5333
|
historyView: void 0,
|
|
@@ -5280,7 +5345,7 @@ function jr(e) {
|
|
|
5280
5345
|
}), await U(e, !0, t);
|
|
5281
5346
|
return;
|
|
5282
5347
|
}
|
|
5283
|
-
if (d() && !(r instanceof Z) &&
|
|
5348
|
+
if (d() && !(r instanceof Z) && c.getState().setSessionMessageHistory(e, {
|
|
5284
5349
|
...n,
|
|
5285
5350
|
preparing: !1,
|
|
5286
5351
|
retryOlderPage: !0,
|
|
@@ -5288,56 +5353,56 @@ function jr(e) {
|
|
|
5288
5353
|
}), t) throw r;
|
|
5289
5354
|
r instanceof Z || console.error("Failed to load older session messages:", r);
|
|
5290
5355
|
} finally {
|
|
5291
|
-
if (
|
|
5292
|
-
let t =
|
|
5293
|
-
|
|
5356
|
+
if (w.current.get(e) === u) if (w.current.delete(e), y.current === s) {
|
|
5357
|
+
let t = c.getState().messageHistory[e];
|
|
5358
|
+
c.getState().setSessionMessageHistory(e, {
|
|
5294
5359
|
...t,
|
|
5295
5360
|
nextCursor: t?.nextCursor ?? null,
|
|
5296
5361
|
hasMore: t?.hasMore ?? !1,
|
|
5297
5362
|
preparing: !1,
|
|
5298
5363
|
isLoadingOlder: !1
|
|
5299
5364
|
});
|
|
5300
|
-
} else
|
|
5365
|
+
} else c.getState().setSessionMessageHistoryLoading(e, !1);
|
|
5301
5366
|
}
|
|
5302
5367
|
}, [
|
|
5303
|
-
|
|
5304
|
-
|
|
5368
|
+
a,
|
|
5369
|
+
ae,
|
|
5305
5370
|
U
|
|
5306
5371
|
]);
|
|
5307
5372
|
return {
|
|
5308
5373
|
historySearchSnapshot: q(() => {
|
|
5309
|
-
let e =
|
|
5374
|
+
let e = p.current || "", t = c.getState().messageHistory[e], n = N.current.get(e);
|
|
5310
5375
|
return {
|
|
5311
5376
|
owner: JSON.stringify([
|
|
5312
|
-
|
|
5377
|
+
m.current,
|
|
5313
5378
|
e,
|
|
5314
|
-
|
|
5379
|
+
y.current
|
|
5315
5380
|
]),
|
|
5316
|
-
messages:
|
|
5381
|
+
messages: G.getState().messages,
|
|
5317
5382
|
hasMore: !!t?.hasMore,
|
|
5318
|
-
loading: !!(
|
|
5383
|
+
loading: !!(x.current === y.current || c.getState().isLoadingSessions || t?.isLoadingInitial || t?.isLoadingOlder),
|
|
5319
5384
|
checkpoint: `${t?.nextItemCursor ?? t?.nextCursor}:${n?.loadedCount}`,
|
|
5320
|
-
error:
|
|
5385
|
+
error: C.current?.generation === y.current ? C.current.message : void 0
|
|
5321
5386
|
};
|
|
5322
5387
|
}, []),
|
|
5323
5388
|
followAcceptedInteraction: V,
|
|
5324
|
-
fetchSessions:
|
|
5325
|
-
fetchInitialSessions:
|
|
5326
|
-
loadMoreSessions:
|
|
5327
|
-
loadSession:
|
|
5328
|
-
recoverSessionRun:
|
|
5329
|
-
bindCachedUserInput:
|
|
5330
|
-
loadOlderSessionMessages:
|
|
5331
|
-
prefetchOlderSessionMessages:
|
|
5332
|
-
createNewSession:
|
|
5333
|
-
startNewConversation:
|
|
5334
|
-
adoptCreatedSession:
|
|
5335
|
-
waitForPendingSessionCreation:
|
|
5336
|
-
deleteSession:
|
|
5337
|
-
currentSessionIdRef:
|
|
5338
|
-
agentIdRef:
|
|
5339
|
-
runSubscriptionAbortRef:
|
|
5389
|
+
fetchSessions: K,
|
|
5390
|
+
fetchInitialSessions: le,
|
|
5391
|
+
loadMoreSessions: pe,
|
|
5392
|
+
loadSession: fe,
|
|
5393
|
+
recoverSessionRun: W,
|
|
5394
|
+
bindCachedUserInput: ce,
|
|
5395
|
+
loadOlderSessionMessages: we,
|
|
5396
|
+
prefetchOlderSessionMessages: Se,
|
|
5397
|
+
createNewSession: ve,
|
|
5398
|
+
startNewConversation: he,
|
|
5399
|
+
adoptCreatedSession: me,
|
|
5400
|
+
waitForPendingSessionCreation: ye,
|
|
5401
|
+
deleteSession: be,
|
|
5402
|
+
currentSessionIdRef: p,
|
|
5403
|
+
agentIdRef: m,
|
|
5404
|
+
runSubscriptionAbortRef: v
|
|
5340
5405
|
};
|
|
5341
5406
|
}
|
|
5342
5407
|
//#endregion
|
|
5343
|
-
export {
|
|
5408
|
+
export { Qe as S, gt as _, xn as a, Ye as b, zt as c, Nt as d, Et as f, _t as g, yt as h, lr as i, Ft as l, St as m, ar as n, on as o, Ct as p, cr as r, Ut as s, Pr as t, It as u, lt as v, Ze as x, rt as y };
|