@kingsoftcloud/ksadk-web 0.3.18 → 0.3.19
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/CHANGELOG.md +6 -0
- package/README.md +2 -2
- package/RELEASE_PROVENANCE.json +2 -2
- package/dist-ksadk/assets/{ArtifactsPanel-Cdr5C_vM.js → ArtifactsPanel-cjsDWTLW.js} +1 -1
- package/dist-ksadk/assets/{CodeBlock-BWRafud9.js → CodeBlock-DTtT6SBI.js} +1 -1
- package/dist-ksadk/assets/{MathMessageMarkdown-CFKeJIvy.js → MathMessageMarkdown-Dap7DsE1.js} +1 -1
- package/dist-ksadk/assets/{MermaidBlock-BneAGUOd.js → MermaidBlock-C2QkLej8.js} +6 -6
- package/dist-ksadk/assets/{NativeTerminalPanel-BHI85zDO.js → NativeTerminalPanel-CeLWBCnF.js} +1 -1
- package/dist-ksadk/assets/{OfficialA2uiRenderer-BOmT36lJ.js → OfficialA2uiRenderer-BshRBsxZ.js} +1 -1
- package/dist-ksadk/assets/{abnfDiagram-VCTEODGH-DQvlOsBI.js → abnfDiagram-VCTEODGH-RvCk4kKS.js} +1 -1
- package/dist-ksadk/assets/{arc-CGx0e4pN.js → arc-R-NvbHBi.js} +1 -1
- package/dist-ksadk/assets/architecture-7GRP2DOG-BgT_ltgS.js +1 -0
- package/dist-ksadk/assets/{architectureDiagram-5GKGNRK7-WyybcNKX.js → architectureDiagram-5GKGNRK7-CWyeEVzn.js} +1 -1
- package/dist-ksadk/assets/{blockDiagram-NRAW4CY4-C9Cx_GVs.js → blockDiagram-NRAW4CY4-CHbhUWj9.js} +1 -1
- package/dist-ksadk/assets/{c4Diagram-UCG6FXSJ-Bh7X3bGr.js → c4Diagram-UCG6FXSJ-BJAftB45.js} +1 -1
- package/dist-ksadk/assets/channel-CO8jKUdU.js +1 -0
- package/dist-ksadk/assets/chunk-2Q5K7J3B-BQ7ktM_H.js +1 -0
- package/dist-ksadk/assets/{chunk-5VM5RSS4-cP9XupZj.js → chunk-5VM5RSS4-BHufOSfh.js} +1 -1
- package/dist-ksadk/assets/{chunk-F27PBJKO-Bm77fvR9.js → chunk-F27PBJKO-BNPW42o9.js} +1 -1
- package/dist-ksadk/assets/{chunk-G27WJ6UU-DDKNPesQ.js → chunk-G27WJ6UU-D_eOFZiC.js} +1 -1
- package/dist-ksadk/assets/{chunk-JWPE2WC7-BqiUDB7s.js → chunk-JWPE2WC7-DEVN_PSR.js} +1 -1
- package/dist-ksadk/assets/{chunk-LCL6LL3I-C528mMZy.js → chunk-LCL6LL3I-DjGV_Lnh.js} +1 -1
- package/dist-ksadk/assets/{chunk-POPQ4Y6H-CzZ9g_Uf.js → chunk-POPQ4Y6H-C2i8ZB07.js} +1 -1
- package/dist-ksadk/assets/{chunk-RHFEMEQ7-CXj4tUZ-.js → chunk-RHFEMEQ7-DMk7_iWC.js} +1 -1
- package/dist-ksadk/assets/{chunk-SVP7TREG-BHyd85pS.js → chunk-SVP7TREG-wHQkXddN.js} +1 -1
- package/dist-ksadk/assets/{chunk-XXDRQBXY-Qe29PHGe.js → chunk-XXDRQBXY-gvpc9yiQ.js} +1 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-HRhUD6oW.js +1 -0
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-HRhUD6oW.js +1 -0
- package/dist-ksadk/assets/{cose-bilkent-JH36ORCC-maRKgeec.js → cose-bilkent-JH36ORCC-BF-zBbK8.js} +1 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-DlLbgFtT.js +1 -0
- package/dist-ksadk/assets/{cynefinDiagram-5FMLGOSQ-CoD0bEvn.js → cynefinDiagram-5FMLGOSQ-0_hg7nkA.js} +1 -1
- package/dist-ksadk/assets/{dagre-3AP2YEHR-BkpgQqyW.js → dagre-3AP2YEHR-uSuKjV2i.js} +1 -1
- package/dist-ksadk/assets/{dagre-BUaTFrYa.js → dagre-BCQPdEAN.js} +1 -1
- package/dist-ksadk/assets/{diagram-S7CK7UJ4-25HdTbjE.js → diagram-S7CK7UJ4-ay17NfAC.js} +1 -1
- package/dist-ksadk/assets/{diagram-UQ7AKVKN-KO-WqOIg.js → diagram-UQ7AKVKN-CaUhPrNE.js} +1 -1
- package/dist-ksadk/assets/{diagram-VSXAHHWV-B360BkDQ.js → diagram-VSXAHHWV-upF8B0NL.js} +1 -1
- package/dist-ksadk/assets/{diagram-VX7I27RA-COr1Oqsg.js → diagram-VX7I27RA-B4t46LEt.js} +1 -1
- package/dist-ksadk/assets/{diagram-Z3DM3KII-CgaKrIwB.js → diagram-Z3DM3KII-BeHjswE7.js} +1 -1
- package/dist-ksadk/assets/{dist-DKG0OYnk.js → dist-58qYwY0M.js} +1 -1
- package/dist-ksadk/assets/{dist-Bsuusoi0.js → dist-AF7gi0D5.js} +1 -1
- package/dist-ksadk/assets/{dist-DgJ57sRe.js → dist-B0PMHWqd.js} +1 -1
- package/dist-ksadk/assets/{dist-DXOlCAay.js → dist-B0s4RUpo.js} +1 -1
- package/dist-ksadk/assets/{dist-_0Xgu_07.js → dist-BGzoFqM2.js} +1 -1
- package/dist-ksadk/assets/{dist-DzdXSBJb.js → dist-BLCD6xMk.js} +1 -1
- package/dist-ksadk/assets/{dist-DmWw0IXB.js → dist-Be3VXZq8.js} +1 -1
- package/dist-ksadk/assets/{dist-B3Jp5r1e.js → dist-Bt0YWq2H.js} +1 -1
- package/dist-ksadk/assets/{dist-CwnkOyDn.js → dist-Bt4Xk1Ro.js} +1 -1
- package/dist-ksadk/assets/{dist-BQ116UdZ.js → dist-Bx4az-XW.js} +1 -1
- package/dist-ksadk/assets/{dist-Brbrdmff.js → dist-C577ALLK.js} +1 -1
- package/dist-ksadk/assets/{dist-CR61WJFC.js → dist-CIZ7o8ol.js} +1 -1
- package/dist-ksadk/assets/{dist-BEbS8Bag.js → dist-COzkztpc.js} +1 -1
- package/dist-ksadk/assets/{dist-By-MVndb.js → dist-CW5ZHS5y.js} +1 -1
- package/dist-ksadk/assets/{dist-C9BTMVwS.js → dist-CdhMAiGd.js} +1 -1
- package/dist-ksadk/assets/{dist-HHvdjADB.js → dist-DIeaHG12.js} +1 -1
- package/dist-ksadk/assets/{dist-DSw5Ju6-.js → dist-DfFlb9ip.js} +1 -1
- package/dist-ksadk/assets/{dist-CBo9AHUv.js → dist-DvOmTQAV.js} +1 -1
- package/dist-ksadk/assets/{dist-BoRn8a_t.js → dist-Dze75pZq.js} +1 -1
- package/dist-ksadk/assets/{dist-Bxcu8Ca0.js → dist-h0bOCJVW.js} +1 -1
- package/dist-ksadk/assets/{dist--HftQyp9.js → dist-mkEF0-z9.js} +1 -1
- package/dist-ksadk/assets/{dist-CxIl4t92.js → dist-uAoeCAZ2.js} +1 -1
- package/dist-ksadk/assets/{ebnfDiagram-PWID7BFC-DogDP2db.js → ebnfDiagram-PWID7BFC-CZKqGdhK.js} +1 -1
- package/dist-ksadk/assets/{erDiagram-SSCWMZ5O-CeBDnUjR.js → erDiagram-SSCWMZ5O-CfQ9oOg4.js} +1 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV-BgSxiUqa.js +1 -0
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-Dcg0DKL0.js +1 -0
- package/dist-ksadk/assets/{ganttDiagram-EL5Y4UJY-oIQL3MCp.js → ganttDiagram-EL5Y4UJY-CWdRcbsA.js} +1 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-DiYbIL_1.js +1 -0
- package/dist-ksadk/assets/{gitGraphDiagram-WWUBYQGX-B7qz0cmZ.js → gitGraphDiagram-WWUBYQGX-S2TxceQ8.js} +1 -1
- package/dist-ksadk/assets/index-CK5of5EC.js +1135 -0
- package/dist-ksadk/assets/index-ofLgkIsP.css +2 -0
- package/dist-ksadk/assets/info-A6RAGUB7-CIUhUhPM.js +1 -0
- package/dist-ksadk/assets/{infoDiagram-RXCK75RN-yQRC41Ya.js → infoDiagram-RXCK75RN-7M0hPUvw.js} +1 -1
- package/dist-ksadk/assets/{ishikawaDiagram-5VMMS53U-BCu4HiwL.js → ishikawaDiagram-5VMMS53U-DApt_KC9.js} +1 -1
- package/dist-ksadk/assets/{journeyDiagram-EYS64GPL-JaqmO73K.js → journeyDiagram-EYS64GPL-03NWnwcI.js} +1 -1
- package/dist-ksadk/assets/{kanban-definition-3QL26DDD-DQo4X8NO.js → kanban-definition-3QL26DDD-CWrM-ciB.js} +1 -1
- package/dist-ksadk/assets/{katex-t_DWylQw.js → katex-CVJEnrQQ.js} +1 -1
- package/dist-ksadk/assets/{linear-DWdnI35B.js → linear-CuvdttYn.js} +1 -1
- package/dist-ksadk/assets/{mermaid-parser.core-BHrT2Pfe.js → mermaid-parser.core-CyiGaINC.js} +2 -2
- package/dist-ksadk/assets/{mindmap-definition-FBJOCRG2-PBVAhZYV.js → mindmap-definition-FBJOCRG2-Cx8x9zok.js} +1 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-CVt8vTzN.js +1 -0
- package/dist-ksadk/assets/{pegDiagram-XKGWAZYB-CU_cLfow.js → pegDiagram-XKGWAZYB-BvMeLOBU.js} +1 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-BmY8d_KC.js +1 -0
- package/dist-ksadk/assets/{pieDiagram-E7YTZNPT-B1h0-_pW.js → pieDiagram-E7YTZNPT-BTEiUEUk.js} +1 -1
- package/dist-ksadk/assets/{quadrantDiagram-AXDQQJYC-DEMoGo5a.js → quadrantDiagram-AXDQQJYC-CEMfGgSc.js} +1 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-D-vxRTHO.js +1 -0
- package/dist-ksadk/assets/railroad-74A4TZTK-hDbxS9Gl.js +1 -0
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-6j4dsPir.js +1 -0
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-f3r0amOv.js +1 -0
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-DpGM5wUK.js +1 -0
- package/dist-ksadk/assets/{railroadDiagram-O6MQD6OU-BTAob2wg.js → railroadDiagram-O6MQD6OU-DjL0Ielv.js} +1 -1
- package/dist-ksadk/assets/{requirementDiagram-EFPCY7ZU-Dl0Q2SuO.js → requirementDiagram-EFPCY7ZU-Da11svpD.js} +1 -1
- package/dist-ksadk/assets/{sankeyDiagram-P5KCCOFB-DeaTWkur.js → sankeyDiagram-P5KCCOFB-DtKGEnlF.js} +1 -1
- package/dist-ksadk/assets/{sequenceDiagram-WJ2MYXX4-gFQYrsOd.js → sequenceDiagram-WJ2MYXX4-CR6Ct1Vm.js} +1 -1
- package/dist-ksadk/assets/{sizeCapture-X5ZJPWSS-pGQzddMB.js → sizeCapture-X5ZJPWSS-DaQE2An6.js} +1 -1
- package/dist-ksadk/assets/{stateDiagram-HBIQ2CUA-DmpYOZt1.js → stateDiagram-HBIQ2CUA-Ct2KGWos.js} +1 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-IHXiAplS.js +1 -0
- package/dist-ksadk/assets/{swimlanes-XN3QIQJK-BfuSAsrr.js → swimlanes-XN3QIQJK-BpIOaZ-N.js} +1 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-ByC69bCd.js +8 -0
- package/dist-ksadk/assets/{timeline-definition-24CTP7MA-CgJwrrxf.js → timeline-definition-24CTP7MA-CdwbtpKP.js} +1 -1
- package/dist-ksadk/assets/treeView-Q6P3EWNA-Bm72pNZV.js +1 -0
- package/dist-ksadk/assets/treemap-WGGIJYW6-Dpgkdt4o.js +1 -0
- package/dist-ksadk/assets/{vennDiagram-4TSXK5OY-CBSAgXDd.js → vennDiagram-4TSXK5OY-Dr_5LEwY.js} +1 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-C9w6FZRL.js +1 -0
- package/dist-ksadk/assets/{wardleyDiagram-VM6X3IG4-013TZ2JZ.js → wardleyDiagram-VM6X3IG4-DYojPjE8.js} +1 -1
- package/dist-ksadk/assets/{xychartDiagram-S5SC5T6Z-u6Frp8xp.js → xychartDiagram-S5SC5T6Z-DV3dpSiv.js} +1 -1
- package/dist-ksadk/index.html +2 -2
- package/dist-lib/App.d.ts.map +1 -1
- package/dist-lib/{AttachmentPreview-Dhc6ulFv.js → AttachmentPreview-COS-HmHj.js} +76 -76
- package/dist-lib/{ConnectedComposer-Cc6bqJmu.js → ConnectedComposer-CB_YmxRQ.js} +47 -47
- package/dist-lib/{ConnectedMessageList-Bdd-qjs-.js → ConnectedMessageList-CJgvv-Hi.js} +357 -275
- package/dist-lib/{WorkspacePanelContainer-_PuvSz_J.js → WorkspacePanelContainer-DU6mKsi5.js} +16 -16
- package/dist-lib/{a2ui-DihCxdtQ.js → a2ui-e0gsVo7e.js} +31 -31
- package/dist-lib/api/client.d.ts +2 -1
- package/dist-lib/api/client.d.ts.map +1 -1
- package/dist-lib/api/messages.d.ts +38 -0
- package/dist-lib/api/messages.d.ts.map +1 -1
- package/dist-lib/chat-composer.js +2 -2
- package/dist-lib/chat-timeline.js +5 -5
- package/dist-lib/components/chat/ChatMessageList.d.ts.map +1 -1
- package/dist-lib/components/chat/ConnectedMessageList.d.ts.map +1 -1
- package/dist-lib/components/chat/DeferredHistoryContent.d.ts +6 -0
- package/dist-lib/components/chat/DeferredHistoryContent.d.ts.map +1 -0
- package/dist-lib/components/chat/ProcessingBlocksView.d.ts +0 -7
- package/dist-lib/components/chat/ProcessingBlocksView.d.ts.map +1 -1
- package/dist-lib/components/chat/types.d.ts +11 -0
- package/dist-lib/components/chat/types.d.ts.map +1 -1
- package/dist-lib/components.js +7 -7
- package/dist-lib/conversation.js +2 -2
- package/dist-lib/core/api/facade.d.ts +2 -14
- package/dist-lib/core/api/facade.d.ts.map +1 -1
- package/dist-lib/core/api/types.d.ts +1 -24
- package/dist-lib/core/api/types.d.ts.map +1 -1
- package/dist-lib/core/run/engine.d.ts +5 -1
- package/dist-lib/core/run/engine.d.ts.map +1 -1
- package/dist-lib/core/run/types.d.ts +1 -0
- package/dist-lib/core/run/types.d.ts.map +1 -1
- package/dist-lib/{feedback-BBJKMdF2.js → feedback-nyK8zFEK.js} +1 -1
- package/dist-lib/hooks/useAgentChat.d.ts.map +1 -1
- package/dist-lib/hooks/useRunAgent.d.ts +1 -0
- package/dist-lib/hooks/useRunAgent.d.ts.map +1 -1
- package/dist-lib/hooks/useSessionLifecycle.d.ts +3 -1
- package/dist-lib/hooks/useSessionLifecycle.d.ts.map +1 -1
- package/dist-lib/hooks.js +118 -117
- package/dist-lib/{permission-DGyt7wBj.js → permission-B9NRAmxP.js} +1 -1
- package/dist-lib/{persisted-session-history-Bh_6zSKC.js → persisted-session-history-C8S6Tl-E.js} +309 -291
- package/dist-lib/runtime.js +180 -179
- package/dist-lib/{session-events-DvFsVXpD.js → session-events-BMRjrPq2.js} +232 -220
- package/dist-lib/stores/session.d.ts +4 -0
- package/dist-lib/stores/session.d.ts.map +1 -1
- package/dist-lib/styles.css +1 -1
- package/dist-lib/{useSessionLifecycle-u7i_h_io.js → useSessionLifecycle-DPwSsODU.js} +1548 -814
- package/dist-lib/utils/history-content.d.ts +16 -0
- package/dist-lib/utils/history-content.d.ts.map +1 -0
- package/dist-lib/utils/history-tool-facts.d.ts.map +1 -1
- package/dist-lib/utils/persisted-session-history.d.ts +1 -1
- package/dist-lib/utils/persisted-session-history.d.ts.map +1 -1
- package/dist-lib/utils/session-event-history.d.ts +2 -0
- package/dist-lib/utils/session-event-history.d.ts.map +1 -1
- package/dist-lib/utils/session-events.d.ts +4 -1
- package/dist-lib/utils/session-events.d.ts.map +1 -1
- package/dist-lib/utils/session-items.d.ts +36 -0
- package/dist-lib/utils/session-items.d.ts.map +1 -0
- package/dist-lib/utils/transcript-order.d.ts +2 -1
- package/dist-lib/utils/transcript-order.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist-ksadk/assets/architecture-7GRP2DOG-CFWjFkDL.js +0 -1
- package/dist-ksadk/assets/channel-D6Dp_l74.js +0 -1
- package/dist-ksadk/assets/chunk-2Q5K7J3B-CwmjhFYK.js +0 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-DsbvkCAV.js +0 -1
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-DsbvkCAV.js +0 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-CBZRVuc4.js +0 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV-vXZWMkpn.js +0 -1
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-5LRgzKLv.js +0 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-BUWSkncI.js +0 -1
- package/dist-ksadk/assets/index-4g1ndaxW.js +0 -1132
- package/dist-ksadk/assets/index-DEVfafsU.css +0 -2
- package/dist-ksadk/assets/info-A6RAGUB7-CzJ_YrOs.js +0 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-CXoos6fx.js +0 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-CjF9NoIt.js +0 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-BQGWs9nw.js +0 -1
- package/dist-ksadk/assets/railroad-74A4TZTK-B6znvLUK.js +0 -1
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-Bzquz0As.js +0 -1
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-1IikGkb5.js +0 -1
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-BKKgHzdc.js +0 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-Dolxgkw3.js +0 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-BuI1erYj.js +0 -8
- package/dist-ksadk/assets/treeView-Q6P3EWNA-DtMdDH8N.js +0 -1
- package/dist-ksadk/assets/treemap-WGGIJYW6-VoU8QtLZ.js +0 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-YWSRB0Zm.js +0 -1
|
@@ -1,24 +1,28 @@
|
|
|
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 V, c as
|
|
5
|
-
import { a as
|
|
6
|
-
import { C as
|
|
7
|
-
import { useCallback as K, useEffect as q, useMemo as
|
|
8
|
-
import { HttpAgent as
|
|
2
|
+
import { E as i, I as a, J as o, K as s, L as c, M as l, N as u, O as d, V as f, W as p, X as m, Y as h, Z as g, a as _, b as v, c as y, d as b, f as x, k as S, l as ee, o as C, p as w, q as T, r as E, s as D, t as O, u as te, v as k } from "./a2ui-e0gsVo7e.js";
|
|
3
|
+
import { C as A, a as j, d as M, f as N, i as ne, l as P, o as F, p as I, r as L, s as R, t as re, u as z, x as B } from "./session-events-BMRjrPq2.js";
|
|
4
|
+
import { a as V, c as ie, d as H, i as ae, l as U, n as oe, o as se, r as ce, s as le, t as ue, u as W } from "./feedback-nyK8zFEK.js";
|
|
5
|
+
import { a as de, d as fe, f as pe, p as G, s as me } from "./reducer-mbYiX0wz.js";
|
|
6
|
+
import { C as he, D as ge, E as _e, S as ve, T as ye, _ as be, a as xe, b as Se, c as Ce, d as we, f as Te, g as Ee, h as De, i as Oe, l as ke, m as Ae, n as je, o as Me, p as Ne, r as Pe, s as Fe, t as Ie, u as Le, v as Re, w as ze, y as Be } from "./persisted-session-history-C8S6Tl-E.js";
|
|
7
|
+
import { useCallback as K, useEffect as q, useMemo as Ve, useRef as J, useState as He } from "react";
|
|
8
|
+
import { HttpAgent as Ue, buildResumeArray as We } from "@ag-ui/client";
|
|
9
9
|
//#region src/api/client.ts
|
|
10
10
|
var Y = class extends Error {
|
|
11
11
|
code;
|
|
12
12
|
detail;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
retryAfterMs;
|
|
14
|
+
constructor(e, t, n, r) {
|
|
15
|
+
if (super(t), this.name = "ApiError", this.code = e, this.detail = n, e === 429 && r) {
|
|
16
|
+
let e = r.trim(), t = /^\d+$/.test(e) ? Number(e) * 1e3 : Date.parse(e) - Date.now();
|
|
17
|
+
Number.isFinite(t) && (this.retryAfterMs = Math.max(0, t));
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
}, X = class extends Error {
|
|
17
21
|
constructor(e = "请求已取消") {
|
|
18
22
|
super(e), this.name = "CancelledError";
|
|
19
23
|
}
|
|
20
|
-
},
|
|
21
|
-
async function
|
|
24
|
+
}, Ge = "/agentengine/api/v1";
|
|
25
|
+
async function Ke(e) {
|
|
22
26
|
let t = await e.text(), n = {};
|
|
23
27
|
try {
|
|
24
28
|
n = t ? JSON.parse(t) : {};
|
|
@@ -27,23 +31,23 @@ async function He(e) {
|
|
|
27
31
|
if ((e.status === 401 || e.status === 403) && (n.includes("text/html") || t.trimStart().startsWith("<"))) throw new Y(e.status, "访问会话已失效,请从 Dashboard 或 Studio 的云端会话重新打开 Agent。");
|
|
28
32
|
if (!e.ok) {
|
|
29
33
|
let n = t.trim();
|
|
30
|
-
throw new Y(e.status, n && n.length <= 256 && !n.startsWith("<") ? n : e.statusText || `HTTP ${e.status}`, t);
|
|
34
|
+
throw new Y(e.status, n && n.length <= 256 && !n.startsWith("<") ? n : e.statusText || `HTTP ${e.status}`, t, e.headers.get("retry-after"));
|
|
31
35
|
}
|
|
32
36
|
throw new Y(-2, "响应格式异常");
|
|
33
37
|
}
|
|
34
|
-
if (!e.ok) throw new Y(e.status, n?.Message || `HTTP ${e.status}`, n);
|
|
35
|
-
if (n?.Code !== void 0 && n.Code !== 0) throw new Y(n.Code, n.Message || "请求失败", n);
|
|
38
|
+
if (!e.ok) throw new Y(e.status, n?.Message || `HTTP ${e.status}`, n, e.headers.get("retry-after"));
|
|
39
|
+
if (n?.Code !== void 0 && n.Code !== 0) throw new Y(n.Code, n.Message || "请求失败", n, e.headers.get("retry-after"));
|
|
36
40
|
return n.Data;
|
|
37
41
|
}
|
|
38
|
-
function
|
|
42
|
+
function qe(e) {
|
|
39
43
|
throw e instanceof DOMException && e.name === "AbortError" ? new X() : e;
|
|
40
44
|
}
|
|
41
|
-
var
|
|
45
|
+
var Je = class {
|
|
42
46
|
fetcher;
|
|
43
47
|
baseUrl;
|
|
44
48
|
agentId;
|
|
45
49
|
constructor(e = {}) {
|
|
46
|
-
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 || Ge).replace(/\/+$/, ""), this.agentId = String(e.agentId || "").trim();
|
|
47
51
|
}
|
|
48
52
|
actionUrl(e) {
|
|
49
53
|
return `${this.baseUrl}/${e}`;
|
|
@@ -64,9 +68,9 @@ var We = class {
|
|
|
64
68
|
signal: n?.signal
|
|
65
69
|
});
|
|
66
70
|
} catch (e) {
|
|
67
|
-
throw
|
|
71
|
+
throw qe(e);
|
|
68
72
|
}
|
|
69
|
-
return
|
|
73
|
+
return Ke(r);
|
|
70
74
|
}
|
|
71
75
|
async postFormAction(e, t, n) {
|
|
72
76
|
let r;
|
|
@@ -78,9 +82,9 @@ var We = class {
|
|
|
78
82
|
signal: n?.signal
|
|
79
83
|
});
|
|
80
84
|
} catch (e) {
|
|
81
|
-
throw
|
|
85
|
+
throw qe(e);
|
|
82
86
|
}
|
|
83
|
-
return
|
|
87
|
+
return Ke(r);
|
|
84
88
|
}
|
|
85
89
|
async getResource(e, t, n) {
|
|
86
90
|
let r = this.agentId && !t.AgentId ? {
|
|
@@ -90,7 +94,7 @@ var We = class {
|
|
|
90
94
|
try {
|
|
91
95
|
o = await this.fetcher(a, { signal: n?.signal });
|
|
92
96
|
} catch (e) {
|
|
93
|
-
throw
|
|
97
|
+
throw qe(e);
|
|
94
98
|
}
|
|
95
99
|
if (!o.ok) throw new Y(o.status, `资源获取失败: ${o.statusText}`);
|
|
96
100
|
try {
|
|
@@ -112,10 +116,10 @@ var We = class {
|
|
|
112
116
|
signal: n?.signal
|
|
113
117
|
});
|
|
114
118
|
} catch (e) {
|
|
115
|
-
throw
|
|
119
|
+
throw qe(e);
|
|
116
120
|
}
|
|
117
|
-
if (!r.ok) throw await
|
|
118
|
-
if ((r.headers.get("content-type")?.toLowerCase() || "").includes("application/json") && await
|
|
121
|
+
if (!r.ok) throw await Ke(r), new Y(r.status, `流式请求失败: ${r.statusText}`);
|
|
122
|
+
if ((r.headers.get("content-type")?.toLowerCase() || "").includes("application/json") && await Ke(r.clone()), !r.body) throw new Y(-1, "无法获取响应流");
|
|
119
123
|
return r.body;
|
|
120
124
|
}
|
|
121
125
|
async streamGetAction(e, t, n) {
|
|
@@ -129,17 +133,23 @@ var We = class {
|
|
|
129
133
|
signal: n?.signal
|
|
130
134
|
});
|
|
131
135
|
} catch (e) {
|
|
132
|
-
throw
|
|
136
|
+
throw qe(e);
|
|
133
137
|
}
|
|
134
|
-
if (!o.ok || o.headers.get("content-type")?.toLowerCase().includes("application/json")) throw new Y(502, "流式订阅未返回事件流", await
|
|
138
|
+
if (!o.ok || o.headers.get("content-type")?.toLowerCase().includes("application/json")) throw new Y(502, "流式订阅未返回事件流", await Ke(o));
|
|
135
139
|
if (!o.body) throw new Y(-1, "无法获取响应流");
|
|
136
140
|
return o.body;
|
|
137
141
|
}
|
|
138
|
-
},
|
|
142
|
+
}, Ye = new Je(), Xe = (e, t, n) => Ye.streamAction(e, t, n), Ze = (e, t, n) => Ye.streamGetAction(e, t, n);
|
|
139
143
|
//#endregion
|
|
140
144
|
//#region src/api/messages.ts
|
|
141
|
-
function
|
|
145
|
+
function Qe(e) {
|
|
142
146
|
return {
|
|
147
|
+
HistoryView: e.HistoryView,
|
|
148
|
+
Items: e.Items,
|
|
149
|
+
ContentSeqId: e.ContentSeqId,
|
|
150
|
+
ContentChunk: e.ContentChunk,
|
|
151
|
+
NextContentOffset: e.NextContentOffset,
|
|
152
|
+
NextItemCursor: e.NextItemCursor,
|
|
143
153
|
Messages: e.Messages ?? [],
|
|
144
154
|
LatestSeqId: Number.isFinite(Number(e.LatestSeqId)) ? Number(e.LatestSeqId) : 0,
|
|
145
155
|
HasMore: !!e.HasMore,
|
|
@@ -150,16 +160,17 @@ function Je(e) {
|
|
|
150
160
|
CursorCompatibleWithRuntime: e.CursorCompatibleWithRuntime,
|
|
151
161
|
SessionContractVersion: e.SessionContractVersion,
|
|
152
162
|
HistoryEpoch: e.HistoryEpoch,
|
|
163
|
+
HistoryEpochSource: e.HistoryEpochSource,
|
|
153
164
|
PersistenceDegraded: e.PersistenceDegraded,
|
|
154
165
|
SnapshotSeqId: ((e) => e != null && Number.isInteger(Number(e)) && Number(e) >= 0 ? Number(e) : void 0)(e.SnapshotSeqId)
|
|
155
166
|
};
|
|
156
167
|
}
|
|
157
168
|
//#endregion
|
|
158
169
|
//#region src/core/api/facade.ts
|
|
159
|
-
var
|
|
170
|
+
var $e = class {
|
|
160
171
|
client;
|
|
161
172
|
constructor(e = {}) {
|
|
162
|
-
this.client = new
|
|
173
|
+
this.client = new Je(e);
|
|
163
174
|
}
|
|
164
175
|
mcpAuthorization = async (e, t, n, r) => this.client.postJsonAction(e, {
|
|
165
176
|
WaitId: t,
|
|
@@ -224,9 +235,14 @@ var Ye = class {
|
|
|
224
235
|
};
|
|
225
236
|
}
|
|
226
237
|
async listSessionMessages(e, t) {
|
|
227
|
-
return
|
|
238
|
+
return Qe(await this.client.postJsonAction("ListSessionMessages", {
|
|
228
239
|
AgentId: t?.agentId,
|
|
229
240
|
SessionId: e,
|
|
241
|
+
HistoryView: t?.historyView,
|
|
242
|
+
ItemCursor: t?.itemCursor,
|
|
243
|
+
ContentSeqId: t?.contentSeqId,
|
|
244
|
+
ContentOffset: t?.contentOffset,
|
|
245
|
+
ContentPart: t?.contentPart,
|
|
230
246
|
AfterSeqId: t?.afterSeqId,
|
|
231
247
|
BeforeSeqId: t?.beforeSeqId,
|
|
232
248
|
CursorSource: t?.cursorSource,
|
|
@@ -283,14 +299,14 @@ var Ye = class {
|
|
|
283
299
|
}, t);
|
|
284
300
|
}
|
|
285
301
|
async submitControl(e, t) {
|
|
286
|
-
return
|
|
302
|
+
return S(await this.client.postJsonAction("SubmitAgentControl", {
|
|
287
303
|
CommandType: e.command_type,
|
|
288
304
|
IdempotencyKey: e.idempotency_key,
|
|
289
305
|
Payload: e.payload
|
|
290
306
|
}, t));
|
|
291
307
|
}
|
|
292
308
|
async submitInteraction(e, t) {
|
|
293
|
-
return
|
|
309
|
+
return S(await this.client.postJsonAction("SubmitInteraction", { ...e }, t));
|
|
294
310
|
}
|
|
295
311
|
async getAgentStatus(e) {
|
|
296
312
|
return this.client.postJsonAction("GetAgentStatus", {}, e);
|
|
@@ -352,34 +368,34 @@ var Ye = class {
|
|
|
352
368
|
async uploadFile(e, t) {
|
|
353
369
|
return this.client.postFormAction("UploadFile", e, t);
|
|
354
370
|
}
|
|
355
|
-
},
|
|
356
|
-
function
|
|
371
|
+
}, et = "ksadk:webui:selected-session:";
|
|
372
|
+
function tt(e) {
|
|
357
373
|
return String(e || "").trim() || "default-agent";
|
|
358
374
|
}
|
|
359
|
-
function
|
|
375
|
+
function nt(e) {
|
|
360
376
|
if (e && typeof e.getItem == "function") return e;
|
|
361
377
|
try {
|
|
362
378
|
if (typeof window < "u" && window.localStorage) return window.localStorage;
|
|
363
379
|
} catch {}
|
|
364
380
|
return null;
|
|
365
381
|
}
|
|
366
|
-
function
|
|
367
|
-
return
|
|
382
|
+
function rt(e) {
|
|
383
|
+
return o.key(`${et}${tt(e)}`);
|
|
368
384
|
}
|
|
369
|
-
function
|
|
370
|
-
let n =
|
|
385
|
+
function it(e, t) {
|
|
386
|
+
let n = nt(t);
|
|
371
387
|
if (!n) return null;
|
|
372
388
|
try {
|
|
373
|
-
return String(n.getItem(
|
|
389
|
+
return String(n.getItem(rt(e)) || "").trim() || null;
|
|
374
390
|
} catch {
|
|
375
391
|
return null;
|
|
376
392
|
}
|
|
377
393
|
}
|
|
378
|
-
function
|
|
379
|
-
if (!
|
|
380
|
-
let r =
|
|
394
|
+
function at(e, t, n) {
|
|
395
|
+
if (!o.writable) return;
|
|
396
|
+
let r = nt(n);
|
|
381
397
|
if (!r) return;
|
|
382
|
-
let i =
|
|
398
|
+
let i = rt(e), a = String(t || "").trim();
|
|
383
399
|
try {
|
|
384
400
|
if (a) {
|
|
385
401
|
r.setItem(i, a);
|
|
@@ -388,7 +404,7 @@ function tt(e, t, n) {
|
|
|
388
404
|
r.removeItem(i);
|
|
389
405
|
} catch {}
|
|
390
406
|
}
|
|
391
|
-
function
|
|
407
|
+
function ot(e, t) {
|
|
392
408
|
if (!Array.isArray(e) || e.length === 0) return null;
|
|
393
409
|
let n = String(t || "").trim();
|
|
394
410
|
if (n && e.some((e) => String(e?.SessionId || "").trim() === n)) return n;
|
|
@@ -398,7 +414,7 @@ function nt(e, t) {
|
|
|
398
414
|
}
|
|
399
415
|
return null;
|
|
400
416
|
}
|
|
401
|
-
function
|
|
417
|
+
function st(e, t, n) {
|
|
402
418
|
let r = Array.isArray(e) ? e : [], i = Array.isArray(t) ? t : [], a = n instanceof Set ? n : new Set(Array.isArray(n) ? n : []);
|
|
403
419
|
if (a.size === 0) return r;
|
|
404
420
|
let o = new Set(r.map((e) => String(e?.SessionId || "").trim()).filter(Boolean)), s = i.filter((e) => {
|
|
@@ -409,28 +425,28 @@ function rt(e, t, n) {
|
|
|
409
425
|
}
|
|
410
426
|
//#endregion
|
|
411
427
|
//#region src/hooks/useBootstrap.ts
|
|
412
|
-
function
|
|
428
|
+
function ct(e) {
|
|
413
429
|
return e instanceof Y && (e.code === 401 || e.code === 403) ? "auth-required" : "error";
|
|
414
430
|
}
|
|
415
|
-
function
|
|
431
|
+
function lt(e) {
|
|
416
432
|
if (!Array.isArray(e)) return ["responses", "chat_completions"];
|
|
417
433
|
let t = e.filter((e) => e === "responses" || e === "chat_completions");
|
|
418
434
|
return t.length > 0 ? t : ["responses", "chat_completions"];
|
|
419
435
|
}
|
|
420
|
-
var
|
|
421
|
-
async function
|
|
436
|
+
var ut = new $e();
|
|
437
|
+
async function dt(e, t = ut) {
|
|
422
438
|
try {
|
|
423
439
|
let n = await t.listAgentModels(e), r = n?.Models;
|
|
424
|
-
Array.isArray(r) &&
|
|
440
|
+
Array.isArray(r) && h.getState().upsertModels(r);
|
|
425
441
|
let i = n;
|
|
426
|
-
i?.Current && !
|
|
442
|
+
i?.Current && !h.getState().selectedModel && h.getState().setSelectedModel(String(i.Current)), i?.Source && h.getState().setModelSource(String(i.Source));
|
|
427
443
|
} catch (e) {
|
|
428
444
|
console.error("Failed to fetch models:", e);
|
|
429
445
|
} finally {
|
|
430
|
-
|
|
446
|
+
h.getState().setModelCatalogLoaded(!0);
|
|
431
447
|
}
|
|
432
448
|
}
|
|
433
|
-
function
|
|
449
|
+
function ft(t, n, i = ut, a) {
|
|
434
450
|
q(() => {
|
|
435
451
|
let o = new AbortController();
|
|
436
452
|
return (async () => {
|
|
@@ -438,23 +454,23 @@ function ct(t, n, i = ot, a) {
|
|
|
438
454
|
try {
|
|
439
455
|
let s = a ?? await i.getAgentUiBootstrap(n, { signal: o.signal });
|
|
440
456
|
if (o.signal.aborted) return;
|
|
441
|
-
let
|
|
442
|
-
if (c.getState().setAgentId(
|
|
443
|
-
let e = String(
|
|
457
|
+
let l = s, u = l?.Agent, d = String(u?.AgentId || "default-agent");
|
|
458
|
+
if (c.getState().setAgentId(d), u?.Name) {
|
|
459
|
+
let e = String(u.Name);
|
|
444
460
|
c.getState().setAgentName(e), document.title = e;
|
|
445
461
|
}
|
|
446
|
-
let
|
|
447
|
-
c.getState().setAgentFramework(
|
|
448
|
-
let
|
|
449
|
-
c.getState().setCapabilities(
|
|
450
|
-
let
|
|
451
|
-
c.getState().setWorkspaceFiles(
|
|
452
|
-
let _ =
|
|
453
|
-
_?.id && (
|
|
462
|
+
let f = String(u?.Framework || "").trim().toLowerCase();
|
|
463
|
+
c.getState().setAgentFramework(f);
|
|
464
|
+
let p = e(s);
|
|
465
|
+
c.getState().setCapabilities(p), c.getState().setApiFormats(lt(p.HostedChat.ApiFormats)), c.getState().setAccessMode(String(l?.AccessMode || "Owner"));
|
|
466
|
+
let m = p.WorkspaceFiles && l?.WorkspaceFiles ? l.WorkspaceFiles : null;
|
|
467
|
+
c.getState().setWorkspaceFiles(m), m || g.getState().setWorkspacePanelOpen(!1), r(p) && t.fetchSessions(d, it(d));
|
|
468
|
+
let _ = l?.Model;
|
|
469
|
+
_?.id && (h.getState().setSelectedModel(_.id), h.getState().upsertModels([_]), h.getState().setModelSource(_.source || "")), dt(d, i), c.getState().setStatus("ready");
|
|
454
470
|
} catch (e) {
|
|
455
471
|
if (o.signal.aborted) return;
|
|
456
472
|
console.error("Failed to fetch bootstrap:", e);
|
|
457
|
-
let t =
|
|
473
|
+
let t = ct(e);
|
|
458
474
|
c.getState().setStatus(t, t === "auth-required" ? "当前访问链接未授权或已过期。" : "无法加载 Agent 配置,请稍后重试。");
|
|
459
475
|
}
|
|
460
476
|
})(), () => o.abort();
|
|
@@ -466,14 +482,14 @@ function ct(t, n, i = ot, a) {
|
|
|
466
482
|
}
|
|
467
483
|
//#endregion
|
|
468
484
|
//#region src/hooks/useFeedback.ts
|
|
469
|
-
function
|
|
485
|
+
function pt(e) {
|
|
470
486
|
let { agentId: t, currentSessionId: n, isStreaming: r, api: i, submitDraft: a } = e;
|
|
471
487
|
return {
|
|
472
488
|
submitResponseFeedback: K(async (e) => {
|
|
473
489
|
if (!n) return;
|
|
474
490
|
let r = null;
|
|
475
491
|
H.getState().patchMessages((t) => {
|
|
476
|
-
let n =
|
|
492
|
+
let n = ue(t, {
|
|
477
493
|
messageId: e.message.id,
|
|
478
494
|
rating: e.rating,
|
|
479
495
|
comment: e.comment || ""
|
|
@@ -481,7 +497,7 @@ function lt(e) {
|
|
|
481
497
|
return r = n.previousFeedback, n.nextMessages;
|
|
482
498
|
});
|
|
483
499
|
try {
|
|
484
|
-
let r =
|
|
500
|
+
let r = se((await i.upsertResponseFeedback(ce({
|
|
485
501
|
agentId: t,
|
|
486
502
|
sessionId: n,
|
|
487
503
|
message: e.message,
|
|
@@ -493,7 +509,7 @@ function lt(e) {
|
|
|
493
509
|
feedback: r
|
|
494
510
|
}));
|
|
495
511
|
} catch (t) {
|
|
496
|
-
console.error("Failed to submit response feedback:", t), H.getState().patchMessages((t) =>
|
|
512
|
+
console.error("Failed to submit response feedback:", t), H.getState().patchMessages((t) => le(t, {
|
|
497
513
|
messageId: e.message.id,
|
|
498
514
|
previousFeedback: r
|
|
499
515
|
}));
|
|
@@ -506,15 +522,15 @@ function lt(e) {
|
|
|
506
522
|
deleteResponseFeedback: K(async (e) => {
|
|
507
523
|
if (!n) return;
|
|
508
524
|
let r = e.feedback ? { ...e.feedback } : null;
|
|
509
|
-
H.getState().patchMessages((t) =>
|
|
525
|
+
H.getState().patchMessages((t) => ae(t, { messageId: e.id }));
|
|
510
526
|
try {
|
|
511
|
-
await i.deleteResponseFeedback(
|
|
527
|
+
await i.deleteResponseFeedback(oe({
|
|
512
528
|
agentId: t,
|
|
513
529
|
sessionId: n,
|
|
514
530
|
message: e
|
|
515
531
|
}));
|
|
516
532
|
} catch (t) {
|
|
517
|
-
console.error("Failed to delete response feedback:", t), H.getState().patchMessages((t) =>
|
|
533
|
+
console.error("Failed to delete response feedback:", t), H.getState().patchMessages((t) => le(t, {
|
|
518
534
|
messageId: e.id,
|
|
519
535
|
previousFeedback: r
|
|
520
536
|
}));
|
|
@@ -555,7 +571,7 @@ function lt(e) {
|
|
|
555
571
|
}
|
|
556
572
|
//#endregion
|
|
557
573
|
//#region src/core/mcp-authorization/recovery.ts
|
|
558
|
-
function
|
|
574
|
+
function mt(e, t, n, r) {
|
|
559
575
|
let i = /* @__PURE__ */ new Map(), a = !1;
|
|
560
576
|
function o(e) {
|
|
561
577
|
clearTimeout(i.get(e)), i.delete(e);
|
|
@@ -563,7 +579,7 @@ function ut(e, t, n, r) {
|
|
|
563
579
|
function s(s) {
|
|
564
580
|
if (s.sessionId !== t || !s.runId) return;
|
|
565
581
|
let c = s.runId, l = s.interactionId;
|
|
566
|
-
if (s.status !== "pending" ||
|
|
582
|
+
if (s.status !== "pending" || U(s)) {
|
|
567
583
|
o(l);
|
|
568
584
|
return;
|
|
569
585
|
}
|
|
@@ -590,10 +606,10 @@ function ut(e, t, n, r) {
|
|
|
590
606
|
}
|
|
591
607
|
//#endregion
|
|
592
608
|
//#region src/hooks/useInteractions.ts
|
|
593
|
-
function
|
|
594
|
-
let t = _(), [n] =
|
|
609
|
+
function ht(e) {
|
|
610
|
+
let t = _(), [n] = He(() => new i({
|
|
595
611
|
agentId: e.agentId,
|
|
596
|
-
store:
|
|
612
|
+
store: w,
|
|
597
613
|
submitInteraction: (t) => e.api.submitInteraction({
|
|
598
614
|
...t,
|
|
599
615
|
AgentId: e.getAgentId?.() ?? t.AgentId
|
|
@@ -605,28 +621,28 @@ function dt(e) {
|
|
|
605
621
|
q(() => {
|
|
606
622
|
n.setInteractionV1Enabled(e.interactionV1Enabled);
|
|
607
623
|
}, [n, e.interactionV1Enabled]);
|
|
608
|
-
let [r,
|
|
609
|
-
q(() =>
|
|
610
|
-
let
|
|
624
|
+
let [r, a] = He(0);
|
|
625
|
+
q(() => w.subscribe(() => a((e) => e + 1)), []);
|
|
626
|
+
let o = c((e) => e.accessMode === "Share"), s = Ve(() => {
|
|
611
627
|
if (!e.currentSessionId) return [];
|
|
612
|
-
let t =
|
|
613
|
-
return
|
|
628
|
+
let t = w.listAll(e.currentSessionId);
|
|
629
|
+
return o ? t.filter((e) => !e.extensions.mcpAuthorization) : t;
|
|
614
630
|
}, [
|
|
615
631
|
r,
|
|
616
632
|
e.currentSessionId,
|
|
617
|
-
|
|
618
|
-
]),
|
|
633
|
+
o
|
|
634
|
+
]), l = Ve(() => s.filter(U), [s]), { currentSessionId: u, interactionV1Enabled: d, onAcceptedInteraction: f } = e, p = o ? void 0 : e.api.mcpAuthorization, m = e.reloadHistory;
|
|
619
635
|
q(() => {
|
|
620
|
-
if (
|
|
636
|
+
if (u && p) return mt(w, u, p, m);
|
|
621
637
|
}, [
|
|
622
638
|
e.agentId,
|
|
623
|
-
|
|
624
|
-
|
|
639
|
+
u,
|
|
640
|
+
p,
|
|
625
641
|
m
|
|
626
642
|
]);
|
|
627
643
|
let h = J(/* @__PURE__ */ new Set());
|
|
628
644
|
return q(() => {
|
|
629
|
-
for (let e of
|
|
645
|
+
for (let e of s) {
|
|
630
646
|
let t = e.extensions.mcpAuthorization;
|
|
631
647
|
if (!t || ![
|
|
632
648
|
"credential_ready",
|
|
@@ -636,64 +652,64 @@ function dt(e) {
|
|
|
636
652
|
"expired"
|
|
637
653
|
].includes(t.status || "")) continue;
|
|
638
654
|
let n = `${e.sessionId}:${e.interactionId}:${t.status}`;
|
|
639
|
-
h.current.has(n) || (h.current.add(n),
|
|
655
|
+
h.current.has(n) || (h.current.add(n), f?.(e));
|
|
640
656
|
}
|
|
641
|
-
}, [
|
|
657
|
+
}, [s, f]), {
|
|
642
658
|
client: n,
|
|
643
|
-
pending:
|
|
644
|
-
records:
|
|
659
|
+
pending: l,
|
|
660
|
+
records: s,
|
|
645
661
|
respond: K((e) => {
|
|
646
|
-
let t =
|
|
647
|
-
return
|
|
662
|
+
let t = u ? w.get(u, e.interactionId) : null;
|
|
663
|
+
return u ? n.respond({
|
|
648
664
|
...e,
|
|
649
|
-
sessionId:
|
|
650
|
-
}).then((e) => (t && (
|
|
665
|
+
sessionId: u
|
|
666
|
+
}).then((e) => (t && (d || t.source === "interaction_v1") && (e.status === "accepted" || e.status === "duplicate") && f?.(t), e)) : Promise.reject(/* @__PURE__ */ Error("请先选择会话。"));
|
|
651
667
|
}, [
|
|
652
668
|
n,
|
|
653
|
-
l,
|
|
654
669
|
u,
|
|
655
|
-
d
|
|
670
|
+
d,
|
|
671
|
+
f
|
|
656
672
|
]),
|
|
657
673
|
localCatalog: t
|
|
658
674
|
};
|
|
659
675
|
}
|
|
660
|
-
var
|
|
661
|
-
function
|
|
676
|
+
var gt = .28;
|
|
677
|
+
function _t(e, t = 768) {
|
|
662
678
|
return Number(e) <= t;
|
|
663
679
|
}
|
|
664
|
-
function
|
|
680
|
+
function vt({ isMobile: e, desktopSidebarOpen: t, mobileSidebarOpen: n }) {
|
|
665
681
|
return {
|
|
666
682
|
desktopSidebarVisible: !e && !!t,
|
|
667
683
|
mobileDrawerVisible: !!(e && n)
|
|
668
684
|
};
|
|
669
685
|
}
|
|
670
|
-
function
|
|
686
|
+
function yt({ isMobile: e, viewportHeight: t, desktopMaxHeight: n = 160 }) {
|
|
671
687
|
if (!e) return n;
|
|
672
688
|
let r = Number(t);
|
|
673
689
|
if (!Number.isFinite(r) || r <= 0) return n;
|
|
674
|
-
let i = Math.floor(r *
|
|
690
|
+
let i = Math.floor(r * gt);
|
|
675
691
|
return Math.max(120, Math.min(n, i));
|
|
676
692
|
}
|
|
677
693
|
//#endregion
|
|
678
694
|
//#region src/hooks/useResponsiveViewport.ts
|
|
679
|
-
function
|
|
695
|
+
function bt() {
|
|
680
696
|
return typeof window > "u" ? 900 : Math.round(window.visualViewport?.height || window.innerHeight || 900);
|
|
681
697
|
}
|
|
682
|
-
function
|
|
698
|
+
function xt() {
|
|
683
699
|
return typeof window > "u" ? {
|
|
684
700
|
isMobile: !1,
|
|
685
701
|
viewportHeight: 900
|
|
686
702
|
} : {
|
|
687
|
-
isMobile:
|
|
688
|
-
viewportHeight:
|
|
703
|
+
isMobile: _t(window.innerWidth, 768),
|
|
704
|
+
viewportHeight: bt()
|
|
689
705
|
};
|
|
690
706
|
}
|
|
691
|
-
function
|
|
692
|
-
let [e, t] =
|
|
707
|
+
function St() {
|
|
708
|
+
let [e, t] = He(() => xt());
|
|
693
709
|
return q(() => {
|
|
694
710
|
if (typeof window > "u") return;
|
|
695
711
|
let e = window.matchMedia("(max-width: 768px)"), n = () => {
|
|
696
|
-
t(
|
|
712
|
+
t(xt());
|
|
697
713
|
};
|
|
698
714
|
n();
|
|
699
715
|
let r = typeof e.addEventListener == "function" ? (e.addEventListener("change", n), () => e.removeEventListener("change", n)) : (e.addListener(n), () => e.removeListener(n));
|
|
@@ -704,13 +720,13 @@ function vt() {
|
|
|
704
720
|
}
|
|
705
721
|
//#endregion
|
|
706
722
|
//#region src/core/stream/responses-protocol.ts
|
|
707
|
-
var
|
|
723
|
+
var Ct = class {
|
|
708
724
|
id = "responses";
|
|
709
725
|
createState() {
|
|
710
|
-
return
|
|
726
|
+
return z();
|
|
711
727
|
}
|
|
712
728
|
parseItemOperations(e, t, n) {
|
|
713
|
-
return
|
|
729
|
+
return A(e.eventName, e.data, t, n);
|
|
714
730
|
}
|
|
715
731
|
parse(e, t) {
|
|
716
732
|
let n = e.data;
|
|
@@ -728,7 +744,7 @@ var yt = class {
|
|
|
728
744
|
}
|
|
729
745
|
}];
|
|
730
746
|
}
|
|
731
|
-
return
|
|
747
|
+
return M({
|
|
732
748
|
eventName: e.eventName,
|
|
733
749
|
data: e.data,
|
|
734
750
|
state: t
|
|
@@ -751,23 +767,23 @@ var yt = class {
|
|
|
751
767
|
};
|
|
752
768
|
//#endregion
|
|
753
769
|
//#region src/utils/stream-parsing.ts
|
|
754
|
-
function
|
|
770
|
+
function wt(e) {
|
|
755
771
|
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("") : "";
|
|
756
772
|
}
|
|
757
|
-
function
|
|
773
|
+
function Tt(e) {
|
|
758
774
|
return e && typeof e == "object" ? e : {};
|
|
759
775
|
}
|
|
760
|
-
function
|
|
761
|
-
let t =
|
|
776
|
+
function Et(e) {
|
|
777
|
+
let t = Tt(e).choices, n = Tt(Array.isArray(t) ? t[0] : null), r = Tt(n.delta), i = Tt(n.message);
|
|
762
778
|
return {
|
|
763
|
-
content:
|
|
764
|
-
reasoning:
|
|
765
|
-
finalText:
|
|
779
|
+
content: wt(r.content),
|
|
780
|
+
reasoning: wt(r.reasoning_content),
|
|
781
|
+
finalText: wt(i.content)
|
|
766
782
|
};
|
|
767
783
|
}
|
|
768
784
|
//#endregion
|
|
769
785
|
//#region src/core/stream/chat-completions-protocol.ts
|
|
770
|
-
var
|
|
786
|
+
var Dt = class {
|
|
771
787
|
id = "chat_completions";
|
|
772
788
|
createState() {
|
|
773
789
|
return {};
|
|
@@ -775,7 +791,7 @@ var Ct = class {
|
|
|
775
791
|
parse(e) {
|
|
776
792
|
let t = e.data;
|
|
777
793
|
if (typeof t != "object" || !t) return [];
|
|
778
|
-
let n =
|
|
794
|
+
let n = Et(t), r = [];
|
|
779
795
|
return n.reasoning && r.push({
|
|
780
796
|
type: "reasoning_delta",
|
|
781
797
|
text: n.reasoning
|
|
@@ -787,14 +803,14 @@ var Ct = class {
|
|
|
787
803
|
text: n.finalText
|
|
788
804
|
}), r;
|
|
789
805
|
}
|
|
790
|
-
},
|
|
791
|
-
|
|
792
|
-
function
|
|
793
|
-
return
|
|
806
|
+
}, Ot = /* @__PURE__ */ new Map();
|
|
807
|
+
Ot.set("responses", new Ct()), Ot.set("chat_completions", new Dt());
|
|
808
|
+
function kt(e) {
|
|
809
|
+
return Ot.get(e) || Ot.get("responses");
|
|
794
810
|
}
|
|
795
811
|
//#endregion
|
|
796
812
|
//#region src/utils/stream-control.js
|
|
797
|
-
function
|
|
813
|
+
function At(e = []) {
|
|
798
814
|
return e.some((e) => {
|
|
799
815
|
if (e?.type !== "terminal") return !1;
|
|
800
816
|
let t = String(e.status || "").toLowerCase();
|
|
@@ -803,7 +819,7 @@ function Et(e = []) {
|
|
|
803
819
|
}
|
|
804
820
|
//#endregion
|
|
805
821
|
//#region src/core/transport/sse-parser.ts
|
|
806
|
-
function
|
|
822
|
+
function jt(e) {
|
|
807
823
|
let t = [], n = e.trim();
|
|
808
824
|
if (!n) return t;
|
|
809
825
|
let r = n.split("\n");
|
|
@@ -833,7 +849,7 @@ function Z(e) {
|
|
|
833
849
|
}
|
|
834
850
|
return t;
|
|
835
851
|
}
|
|
836
|
-
function
|
|
852
|
+
function Mt(e) {
|
|
837
853
|
let t = e.split("\n\n");
|
|
838
854
|
return {
|
|
839
855
|
chunks: t,
|
|
@@ -842,60 +858,60 @@ function Dt(e) {
|
|
|
842
858
|
}
|
|
843
859
|
//#endregion
|
|
844
860
|
//#region src/utils/error.ts
|
|
845
|
-
function
|
|
861
|
+
function Nt(e) {
|
|
846
862
|
return e instanceof Error ? e.message : String(e);
|
|
847
863
|
}
|
|
848
864
|
//#endregion
|
|
849
865
|
//#region src/utils/model-options.js
|
|
850
|
-
var
|
|
866
|
+
var Pt = new Set([
|
|
851
867
|
"auto",
|
|
852
868
|
"enabled",
|
|
853
869
|
"disabled"
|
|
854
870
|
]);
|
|
855
|
-
function
|
|
871
|
+
function Ft(e) {
|
|
856
872
|
let t = String(e || "").trim().toLowerCase();
|
|
857
|
-
return
|
|
873
|
+
return Pt.has(t) ? t : "auto";
|
|
858
874
|
}
|
|
859
|
-
function
|
|
860
|
-
let t =
|
|
875
|
+
function It(e) {
|
|
876
|
+
let t = Ft(e);
|
|
861
877
|
if (t === "disabled") return { thinking: { type: "disabled" } };
|
|
862
878
|
if (t === "enabled") return { thinking: { type: "enabled" } };
|
|
863
879
|
}
|
|
864
|
-
var
|
|
865
|
-
function
|
|
880
|
+
var Lt = 1280;
|
|
881
|
+
function Rt(e) {
|
|
866
882
|
let { apiFormats: t } = e;
|
|
867
883
|
return t.includes("responses") ? "responses" : t.includes("chat_completions") ? "chat_completions" : "responses";
|
|
868
884
|
}
|
|
869
|
-
function
|
|
870
|
-
let r = Math.min(
|
|
885
|
+
function zt(e, t, n) {
|
|
886
|
+
let r = Math.min(Lt, Math.max(420, t - n - 360));
|
|
871
887
|
return Math.min(Math.max(e, 420), r);
|
|
872
888
|
}
|
|
873
889
|
//#endregion
|
|
874
890
|
//#region src/core/run/agui.ts
|
|
875
|
-
function
|
|
891
|
+
function Bt(e) {
|
|
876
892
|
return String(e.type || "").toUpperCase();
|
|
877
893
|
}
|
|
878
|
-
function
|
|
894
|
+
function Vt(e, t) {
|
|
879
895
|
return String(e.messageId || t);
|
|
880
896
|
}
|
|
881
|
-
function
|
|
897
|
+
function Ht(e, t) {
|
|
882
898
|
return String(e.runId || t);
|
|
883
899
|
}
|
|
884
|
-
function
|
|
900
|
+
function Ut(e) {
|
|
885
901
|
return e && typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
886
902
|
}
|
|
887
|
-
function
|
|
888
|
-
if (Array.isArray(e)) return
|
|
903
|
+
function Wt(e) {
|
|
904
|
+
if (Array.isArray(e)) return E(e.filter((e) => !!(e && typeof e == "object")));
|
|
889
905
|
if (e && typeof e == "object") {
|
|
890
906
|
let t = e.a2ui_operations;
|
|
891
|
-
return Array.isArray(t) ?
|
|
907
|
+
return Array.isArray(t) ? E(t.filter((e) => !!(e && typeof e == "object"))) : [e];
|
|
892
908
|
}
|
|
893
909
|
return [];
|
|
894
910
|
}
|
|
895
|
-
function
|
|
911
|
+
function Gt(e) {
|
|
896
912
|
return e == null || e === "" ? "" : typeof e == "string" ? e : JSON.stringify(e, null, 2);
|
|
897
913
|
}
|
|
898
|
-
var
|
|
914
|
+
var Kt = class {
|
|
899
915
|
agent;
|
|
900
916
|
onEvent;
|
|
901
917
|
tools = /* @__PURE__ */ new Map();
|
|
@@ -908,18 +924,18 @@ var Vt = class {
|
|
|
908
924
|
forwardedProps;
|
|
909
925
|
catalogRegistry;
|
|
910
926
|
constructor(e) {
|
|
911
|
-
this.agent = new
|
|
927
|
+
this.agent = new Ue({
|
|
912
928
|
url: e.url,
|
|
913
929
|
agentId: e.agentId,
|
|
914
930
|
threadId: e.threadId,
|
|
915
931
|
fetch: e.fetch
|
|
916
|
-
}), this.onEvent = e.onEvent, this.threadId = e.threadId, this.forwardedProps = e.forwardedProps || {}, this.catalogRegistry = e.a2uiCatalogRegistry ||
|
|
932
|
+
}), this.onEvent = e.onEvent, this.threadId = e.threadId, this.forwardedProps = e.forwardedProps || {}, this.catalogRegistry = e.a2uiCatalogRegistry || k;
|
|
917
933
|
}
|
|
918
|
-
configure(e, t =
|
|
934
|
+
configure(e, t = k) {
|
|
919
935
|
this.forwardedProps = e, this.catalogRegistry = t;
|
|
920
936
|
}
|
|
921
937
|
reconcileInteractions(e) {
|
|
922
|
-
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) &&
|
|
938
|
+
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) && a(e.status));
|
|
923
939
|
this.agent.pendingInterrupts = this.agent.pendingInterrupts.filter(t);
|
|
924
940
|
for (let [e, n] of this.pendingByRun) {
|
|
925
941
|
let r = n.filter(t);
|
|
@@ -941,7 +957,7 @@ var Vt = class {
|
|
|
941
957
|
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) : [{
|
|
942
958
|
id: t.interruptId,
|
|
943
959
|
reason: "approval"
|
|
944
|
-
}], i =
|
|
960
|
+
}], i = We(r, { [t.interruptId]: t.status === "resolved" ? {
|
|
945
961
|
status: "resolved",
|
|
946
962
|
payload: t.payload
|
|
947
963
|
} : { status: "cancelled" } });
|
|
@@ -964,22 +980,22 @@ var Vt = class {
|
|
|
964
980
|
let t = ++this.executionEpoch, n = this.logicalRunId || e.runId, r = !0, i = /* @__PURE__ */ new Set(), a = (n) => {
|
|
965
981
|
if (!r || t !== this.executionEpoch || this.activeRunId !== e.runId || e.abortController?.signal.aborted) return null;
|
|
966
982
|
let a = n;
|
|
967
|
-
if (
|
|
968
|
-
let o =
|
|
983
|
+
if (Bt(n) !== "CUSTOM" || a.name !== "ksadk.text_message_snapshot") return null;
|
|
984
|
+
let o = Ut(a.value);
|
|
969
985
|
return o.version === 1 && o.threadId === this.threadId && o.runId === e.runId && typeof o.messageId == "string" && i.has(o.messageId) && typeof o.content == "string" ? {
|
|
970
986
|
messageId: o.messageId,
|
|
971
987
|
content: o.content
|
|
972
988
|
} : null;
|
|
973
989
|
}, o = "completed", s = !1, c = {
|
|
974
990
|
onEvent: ({ event: t, messages: r }) => {
|
|
975
|
-
|
|
991
|
+
Bt(t) === "TEXT_MESSAGE_START" && i.add(Vt(t, `${e.runId}:assistant`));
|
|
976
992
|
let c = a(t);
|
|
977
993
|
if (c && r.some((e) => e.id === c.messageId && e.role === "assistant") && this.onEvent({
|
|
978
994
|
type: "text_replace",
|
|
979
995
|
messageId: c.messageId,
|
|
980
996
|
text: c.content,
|
|
981
997
|
sessionId: this.threadId
|
|
982
|
-
}),
|
|
998
|
+
}), Bt(t) === "RUN_FINISHED" && (s = !0), Bt(t) === "RUN_ERROR" && t.code === "INPUT_RESPONSE_INVALID") for (let t of e.resume || []) this.onEvent({
|
|
983
999
|
type: "interaction_submit_rejected",
|
|
984
1000
|
interactionId: t.interruptId,
|
|
985
1001
|
message: "答案未通过 Runtime 校验,请修改后重新提交。"
|
|
@@ -1004,7 +1020,7 @@ var Vt = class {
|
|
|
1004
1020
|
try {
|
|
1005
1021
|
l = await this.agent.runAgent({
|
|
1006
1022
|
runId: e.runId,
|
|
1007
|
-
context: [
|
|
1023
|
+
context: [O(this.catalogRegistry)],
|
|
1008
1024
|
forwardedProps: {
|
|
1009
1025
|
...this.forwardedProps,
|
|
1010
1026
|
injectA2UITool: !0
|
|
@@ -1023,7 +1039,7 @@ var Vt = class {
|
|
|
1023
1039
|
};
|
|
1024
1040
|
}
|
|
1025
1041
|
project(e, t, n = !1, r = t) {
|
|
1026
|
-
let i =
|
|
1042
|
+
let i = Bt(e), a = Ht(e, t), o = Vt(e, `${a}:assistant`), s = e, c = [];
|
|
1027
1043
|
if (i === "RUN_STARTED") c.push({
|
|
1028
1044
|
type: "activity",
|
|
1029
1045
|
phase: "AG-UI 运行已创建",
|
|
@@ -1086,7 +1102,7 @@ var Vt = class {
|
|
|
1086
1102
|
output: String(s.content || "")
|
|
1087
1103
|
});
|
|
1088
1104
|
} else if (i === "CUSTOM" && s.name === "ksadk.session_event") {
|
|
1089
|
-
let e =
|
|
1105
|
+
let e = Ut(s.value), t = e.family === "control" && ["mcp.authorization.requested", "mcp.authorization.updated"].includes(String(e.event_type));
|
|
1090
1106
|
(e.family === "interaction" || t) && e.family_version === 1 && e.session_id === this.threadId && typeof e.event_type == "string" && Number.isSafeInteger(e.seq) && c.push({
|
|
1091
1107
|
type: "stream_event",
|
|
1092
1108
|
sessionId: e.session_id,
|
|
@@ -1100,7 +1116,7 @@ var Vt = class {
|
|
|
1100
1116
|
}
|
|
1101
1117
|
});
|
|
1102
1118
|
} else if (i === "ACTIVITY_SNAPSHOT") {
|
|
1103
|
-
let e = s.content, t =
|
|
1119
|
+
let e = s.content, t = Ut(e), n = String(t.surfaceId || t.surface_id || s.messageId || "default");
|
|
1104
1120
|
c.push({
|
|
1105
1121
|
type: "agui_activity",
|
|
1106
1122
|
runId: r,
|
|
@@ -1108,17 +1124,17 @@ var Vt = class {
|
|
|
1108
1124
|
...typeof t.interactionId == "string" ? { interactionId: t.interactionId } : {},
|
|
1109
1125
|
messageId: this.runMessageIds.get(a) || o,
|
|
1110
1126
|
surfaceId: n,
|
|
1111
|
-
messages:
|
|
1127
|
+
messages: Wt(t.content ?? e)
|
|
1112
1128
|
});
|
|
1113
1129
|
} else if (i === "RUN_FINISHED") {
|
|
1114
|
-
let e =
|
|
1130
|
+
let e = Ut(s.outcome);
|
|
1115
1131
|
if (String(e.type || "").toLowerCase() === "interrupt") {
|
|
1116
1132
|
let t = Array.isArray(e.interrupts) ? e.interrupts : [];
|
|
1117
1133
|
this.pendingByRun.set(a, t);
|
|
1118
1134
|
for (let e of t) {
|
|
1119
|
-
let t =
|
|
1135
|
+
let t = Ut(e.metadata);
|
|
1120
1136
|
if (t.interaction_v1 === !0) continue;
|
|
1121
|
-
let n = e.toolCallId ? this.tools.get(e.toolCallId) : void 0, r = String(t.tool_name || t.toolName || n?.name || e.reason || "人工确认"), i =
|
|
1137
|
+
let n = e.toolCallId ? this.tools.get(e.toolCallId) : void 0, r = String(t.tool_name || t.toolName || n?.name || e.reason || "人工确认"), i = Gt(t.arguments ?? t.tool_args ?? t.args ?? n?.args);
|
|
1122
1138
|
c.push({
|
|
1123
1139
|
type: "approval_requested",
|
|
1124
1140
|
messageId: this.runMessageIds.get(a) || `${a}:assistant`,
|
|
@@ -1153,7 +1169,7 @@ var Vt = class {
|
|
|
1153
1169
|
};
|
|
1154
1170
|
return { events: c };
|
|
1155
1171
|
}
|
|
1156
|
-
},
|
|
1172
|
+
}, qt = new Set([
|
|
1157
1173
|
"completed",
|
|
1158
1174
|
"failed",
|
|
1159
1175
|
"error",
|
|
@@ -1162,13 +1178,38 @@ var Vt = class {
|
|
|
1162
1178
|
"aborted",
|
|
1163
1179
|
"interrupted",
|
|
1164
1180
|
"resume_failed"
|
|
1165
|
-
])
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1181
|
+
]), Jt = [
|
|
1182
|
+
0,
|
|
1183
|
+
500,
|
|
1184
|
+
1e3,
|
|
1185
|
+
2e3,
|
|
1186
|
+
4e3,
|
|
1187
|
+
8e3
|
|
1188
|
+
];
|
|
1189
|
+
function Yt(e, t) {
|
|
1190
|
+
return !e || t.aborted ? Promise.resolve() : new Promise((n) => {
|
|
1191
|
+
let r = () => {
|
|
1192
|
+
clearTimeout(i), t.removeEventListener("abort", r), n();
|
|
1193
|
+
}, i = setTimeout(r, e);
|
|
1194
|
+
t.addEventListener("abort", r, { once: !0 });
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
function Xt(e) {
|
|
1198
|
+
if (typeof window > "u" || window.navigator.onLine !== !1 || e.aborted) return Promise.resolve();
|
|
1199
|
+
let t = window;
|
|
1200
|
+
return new Promise((n) => {
|
|
1201
|
+
let r = () => {
|
|
1202
|
+
t.removeEventListener("online", r), e.removeEventListener("abort", r), n();
|
|
1203
|
+
};
|
|
1204
|
+
t.addEventListener("online", r, { once: !0 }), e.addEventListener("abort", r, { once: !0 });
|
|
1205
|
+
});
|
|
1170
1206
|
}
|
|
1171
|
-
function
|
|
1207
|
+
function Zt(e) {
|
|
1208
|
+
if (e.Content?.runtime_event?.parent_scope_id) return null;
|
|
1209
|
+
let t = R(e);
|
|
1210
|
+
return qt.has(t) ? t : null;
|
|
1211
|
+
}
|
|
1212
|
+
function Qt(e, t) {
|
|
1172
1213
|
let n = String(t?.type || e || "").trim();
|
|
1173
1214
|
if (n === "response.created") return {
|
|
1174
1215
|
phase: "运行已创建",
|
|
@@ -1214,11 +1255,11 @@ function Wt(e, t) {
|
|
|
1214
1255
|
status: "failed"
|
|
1215
1256
|
} : null;
|
|
1216
1257
|
}
|
|
1217
|
-
function
|
|
1258
|
+
function $t() {
|
|
1218
1259
|
let e = globalThis.crypto;
|
|
1219
1260
|
return e && typeof e.randomUUID == "function" ? `run_${e.randomUUID()}` : `run_${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
1220
1261
|
}
|
|
1221
|
-
var
|
|
1262
|
+
var en = {
|
|
1222
1263
|
idle: [
|
|
1223
1264
|
"creating-session",
|
|
1224
1265
|
"uploading-files",
|
|
@@ -1250,13 +1291,14 @@ var Kt = {
|
|
|
1250
1291
|
stopping: ["cancelled", "idle"],
|
|
1251
1292
|
completing: ["idle"],
|
|
1252
1293
|
recovering: [
|
|
1294
|
+
"connecting",
|
|
1253
1295
|
"streaming",
|
|
1254
1296
|
"error",
|
|
1255
1297
|
"idle"
|
|
1256
1298
|
],
|
|
1257
1299
|
error: ["connecting", "idle"],
|
|
1258
1300
|
cancelled: ["idle"]
|
|
1259
|
-
},
|
|
1301
|
+
}, tn = class {
|
|
1260
1302
|
_stage = "idle";
|
|
1261
1303
|
listeners = /* @__PURE__ */ new Set();
|
|
1262
1304
|
abortController = null;
|
|
@@ -1289,18 +1331,18 @@ var Kt = {
|
|
|
1289
1331
|
return this.activeSessionId || this.projection.draftId || null;
|
|
1290
1332
|
}
|
|
1291
1333
|
publishInvocation(e) {
|
|
1292
|
-
this.invocationId = e, e &&
|
|
1334
|
+
this.invocationId = e, e && m.getState().updateActivity({
|
|
1293
1335
|
sessionId: this.streamingKey,
|
|
1294
1336
|
runId: e,
|
|
1295
1337
|
countEvent: !1,
|
|
1296
1338
|
visible: this.projection.isVisible?.()
|
|
1297
|
-
}), this.projection.isVisible?.() !== !1 && (
|
|
1339
|
+
}), this.projection.isVisible?.() !== !1 && (m.getState().setCurrentRunId(e), m.getState().setActiveInvocationId(e));
|
|
1298
1340
|
}
|
|
1299
1341
|
recordCursor(e) {
|
|
1300
|
-
this.lastSeqId = e === 0 ? 0 : Math.max(this.lastSeqId, e), this.projection.isVisible?.() !== !1 &&
|
|
1342
|
+
this.lastSeqId = e === 0 ? 0 : Math.max(this.lastSeqId, e), this.projection.isVisible?.() !== !1 && m.getState().setLastSeqId(this.lastSeqId);
|
|
1301
1343
|
}
|
|
1302
1344
|
stopActivity(e) {
|
|
1303
|
-
let t =
|
|
1345
|
+
let t = m.getState(), n = this.projection.isVisible?.() !== !1;
|
|
1304
1346
|
this.streamingKey ? t.stopSessionActivity(this.streamingKey, e, n) : n && t.stopActivity(e);
|
|
1305
1347
|
}
|
|
1306
1348
|
get stage() {
|
|
@@ -1313,9 +1355,9 @@ var Kt = {
|
|
|
1313
1355
|
this.lastControlCommand = e;
|
|
1314
1356
|
let t;
|
|
1315
1357
|
try {
|
|
1316
|
-
t =
|
|
1358
|
+
t = l(await this.api.submitControl(e));
|
|
1317
1359
|
} catch (e) {
|
|
1318
|
-
if (e instanceof
|
|
1360
|
+
if (e instanceof d) return this.controlStateValue = {
|
|
1319
1361
|
phase: "contract_mismatch",
|
|
1320
1362
|
error: null,
|
|
1321
1363
|
receipt: null
|
|
@@ -1405,7 +1447,7 @@ var Kt = {
|
|
|
1405
1447
|
let t = this.config.hostedChatTransport;
|
|
1406
1448
|
if (t?.Protocol !== "ag-ui" || !t.Endpoint) return null;
|
|
1407
1449
|
if (!this.aguiClient || this.aguiThreadSessionId !== e) {
|
|
1408
|
-
let n = new
|
|
1450
|
+
let n = new Kt({
|
|
1409
1451
|
url: t.Endpoint,
|
|
1410
1452
|
agentId: this.config.agentId,
|
|
1411
1453
|
threadId: e,
|
|
@@ -1415,16 +1457,16 @@ var Kt = {
|
|
|
1415
1457
|
});
|
|
1416
1458
|
this.aguiClient = n, this.aguiThreadSessionId = e;
|
|
1417
1459
|
}
|
|
1418
|
-
return this.aguiClient.reconcileInteractions(
|
|
1460
|
+
return this.aguiClient.reconcileInteractions(w.listAll(e)), this.aguiClient.configure({
|
|
1419
1461
|
model: this.config.selectedModel || void 0,
|
|
1420
1462
|
modelMetadata: this.config.selectedModelMetadata || void 0,
|
|
1421
|
-
modelOptions:
|
|
1463
|
+
modelOptions: It(Ft(this.config.thinkingMode)),
|
|
1422
1464
|
toolApprovalMode: this.config.permissionMode || "risk"
|
|
1423
1465
|
}, this.config.a2uiCatalogRegistry), this.aguiClient;
|
|
1424
1466
|
}
|
|
1425
1467
|
setStage(e) {
|
|
1426
1468
|
if (this._stage === e) return;
|
|
1427
|
-
let t =
|
|
1469
|
+
let t = en[this._stage];
|
|
1428
1470
|
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({
|
|
1429
1471
|
type: "stage_changed",
|
|
1430
1472
|
stage: e
|
|
@@ -1449,15 +1491,15 @@ var Kt = {
|
|
|
1449
1491
|
r || (r = !0, e.onDispatchResult?.(t));
|
|
1450
1492
|
};
|
|
1451
1493
|
return (async () => {
|
|
1452
|
-
let r = e.sessionId || null, a = "unknown";
|
|
1494
|
+
let r = e.sessionId || null, a = "unknown", o = !1;
|
|
1453
1495
|
try {
|
|
1454
1496
|
if (r ||= await this.createSession(e), !r) throw Error("运行时未返回会话身份,请确认创建结果后重试。");
|
|
1455
1497
|
this.activeSessionId = r;
|
|
1456
|
-
let
|
|
1457
|
-
this.publishInvocation(
|
|
1458
|
-
let
|
|
1459
|
-
if (
|
|
1460
|
-
let n = await this.buildCanonicalConversationInput(
|
|
1498
|
+
let s = $t();
|
|
1499
|
+
this.publishInvocation(s), e.onInvocationCreated?.(s), this.recordCursor(0);
|
|
1500
|
+
let c = n ? null : await this.getConversationBootstrap(r);
|
|
1501
|
+
if (c && this.config.conversationClient) {
|
|
1502
|
+
let n = await this.buildCanonicalConversationInput(c, r, s, e);
|
|
1461
1503
|
this.setStage("connecting"), this.emit({
|
|
1462
1504
|
type: "activity",
|
|
1463
1505
|
phase: "连接会话运行时",
|
|
@@ -1470,7 +1512,7 @@ var Kt = {
|
|
|
1470
1512
|
countEvent: !1
|
|
1471
1513
|
});
|
|
1472
1514
|
let i = await this.config.conversationClient.streamTurn({
|
|
1473
|
-
bootstrap:
|
|
1515
|
+
bootstrap: c,
|
|
1474
1516
|
input: n,
|
|
1475
1517
|
signal: this.abortController?.signal,
|
|
1476
1518
|
onUpdate: (t) => {
|
|
@@ -1504,25 +1546,25 @@ var Kt = {
|
|
|
1504
1546
|
});
|
|
1505
1547
|
return;
|
|
1506
1548
|
}
|
|
1507
|
-
let
|
|
1549
|
+
let l = await this.uploadFiles(e, n);
|
|
1508
1550
|
this.setStage("connecting"), this.emit({
|
|
1509
1551
|
type: "activity",
|
|
1510
1552
|
phase: "连接运行时",
|
|
1511
1553
|
status: "connecting",
|
|
1512
1554
|
countEvent: !1
|
|
1513
1555
|
});
|
|
1514
|
-
let
|
|
1556
|
+
let u = n ? "responses" : Rt({
|
|
1515
1557
|
agentFramework: this.config.agentFramework,
|
|
1516
1558
|
apiFormats: this.config.apiFormats
|
|
1517
|
-
}),
|
|
1518
|
-
if (
|
|
1559
|
+
}), d = kt(u), f = d.createState(), p = this.config.hostedChatTransport, m = !n && !e.executionMode && e.attachments.length === 0 && p?.Protocol === "ag-ui" ? this.getAguiClient(r) : null;
|
|
1560
|
+
if (m && p) {
|
|
1519
1561
|
this.setStage("streaming"), this.emit({
|
|
1520
1562
|
type: "activity",
|
|
1521
1563
|
phase: "等待 AG-UI 输出",
|
|
1522
1564
|
status: "waiting",
|
|
1523
1565
|
countEvent: !1
|
|
1524
1566
|
});
|
|
1525
|
-
let t = await
|
|
1567
|
+
let t = await m.run(e.text, s, this.abortController?.signal);
|
|
1526
1568
|
if (t.status === "interrupted") {
|
|
1527
1569
|
a = "cancelled", this.setStage("completing"), this.emit({ type: "stream_ended" });
|
|
1528
1570
|
return;
|
|
@@ -1544,26 +1586,26 @@ var Kt = {
|
|
|
1544
1586
|
}), this.emit({ type: "stream_ended" });
|
|
1545
1587
|
return;
|
|
1546
1588
|
}
|
|
1547
|
-
let
|
|
1589
|
+
let h = this.buildRequestBody(r, u, n, e, l, s), g = this.config.kernelSessionEventsEnabled && this.config.presentationProfile === "agent-block-v1" ? "agent-block-v1" : "flat-v1", _ = await this.api.runAgent(h, { signal: this.abortController?.signal });
|
|
1548
1590
|
if (this.operationEpoch !== t || this.abortController?.signal.aborted) {
|
|
1549
|
-
i(!1), await
|
|
1591
|
+
i(!1), await _.cancel();
|
|
1550
1592
|
return;
|
|
1551
1593
|
}
|
|
1552
|
-
this.config.kernelSessionEventsEnabled || i(!0), this.setStage("streaming"), this.emit({
|
|
1594
|
+
o = u === "responses" && !this.config.kernelSessionEventsEnabled, this.config.kernelSessionEventsEnabled || i(!0), this.setStage("streaming"), this.emit({
|
|
1553
1595
|
type: "activity",
|
|
1554
1596
|
phase: "等待首个输出",
|
|
1555
1597
|
status: "waiting",
|
|
1556
1598
|
countEvent: !1
|
|
1557
1599
|
});
|
|
1558
|
-
let
|
|
1600
|
+
let v = `msg-${Date.now()}`, y = await Oe(_);
|
|
1559
1601
|
if (this.operationEpoch !== t || this.abortController?.signal.aborted) {
|
|
1560
|
-
i(!1), await
|
|
1602
|
+
i(!1), await y.stream.cancel();
|
|
1561
1603
|
return;
|
|
1562
1604
|
}
|
|
1563
|
-
this.config.kernelSessionEventsEnabled && i(!
|
|
1564
|
-
let
|
|
1565
|
-
if (
|
|
1566
|
-
if (
|
|
1605
|
+
this.config.kernelSessionEventsEnabled && i(!y.receipt || y.receipt.status === "accepted" || y.receipt.status === "duplicate");
|
|
1606
|
+
let b;
|
|
1607
|
+
if (b = y.receipt ? await this.consumeKernelRunEvents(r, y.receipt, e.onInvocationCreated, g) : await this.consumeStream(y.stream, d, f, v, s), this.operationEpoch !== t) return;
|
|
1608
|
+
if (b.awaitingInput) {
|
|
1567
1609
|
a = "awaiting-input", this.setStage("completing"), this.emit({
|
|
1568
1610
|
type: "activity",
|
|
1569
1611
|
phase: "等待人工确认",
|
|
@@ -1572,7 +1614,7 @@ var Kt = {
|
|
|
1572
1614
|
}), this.emit({ type: "stream_ended" });
|
|
1573
1615
|
return;
|
|
1574
1616
|
}
|
|
1575
|
-
if (
|
|
1617
|
+
if (b.outcomeUnknown) {
|
|
1576
1618
|
a = "unknown", this.setStage("recovering"), this.emit({
|
|
1577
1619
|
type: "activity",
|
|
1578
1620
|
phase: "运行状态待确认",
|
|
@@ -1582,7 +1624,7 @@ var Kt = {
|
|
|
1582
1624
|
});
|
|
1583
1625
|
return;
|
|
1584
1626
|
}
|
|
1585
|
-
if (
|
|
1627
|
+
if (b.terminalStatus === "cancelled") {
|
|
1586
1628
|
a = "cancelled", this.setStage("stopping"), this.stopActivity("运行时已取消本次执行。"), this.emit({
|
|
1587
1629
|
type: "activity",
|
|
1588
1630
|
phase: "运行已取消",
|
|
@@ -1591,10 +1633,10 @@ var Kt = {
|
|
|
1591
1633
|
}), this.setStage("cancelled");
|
|
1592
1634
|
return;
|
|
1593
1635
|
}
|
|
1594
|
-
if (
|
|
1636
|
+
if (b.terminalStatus && b.terminalStatus !== "completed") {
|
|
1595
1637
|
a = "failed", this.setStage("error"), this.emit({
|
|
1596
1638
|
type: "activity",
|
|
1597
|
-
phase:
|
|
1639
|
+
phase: b.terminalStatus === "incomplete" ? "运行中断" : "运行失败",
|
|
1598
1640
|
status: "failed",
|
|
1599
1641
|
countEvent: !1
|
|
1600
1642
|
});
|
|
@@ -1606,43 +1648,44 @@ var Kt = {
|
|
|
1606
1648
|
status: "completed",
|
|
1607
1649
|
countEvent: !1
|
|
1608
1650
|
}), this.emit({ type: "stream_ended" });
|
|
1609
|
-
} catch (
|
|
1610
|
-
if (this.
|
|
1651
|
+
} catch (n) {
|
|
1652
|
+
if (this.operationEpoch !== t) return;
|
|
1653
|
+
if (this.failCompaction(), this.abortController?.signal.aborted || n instanceof X || n instanceof DOMException && n.name === "AbortError" || n instanceof G && n.code === "conversation_aborted") a = "cancelled";
|
|
1611
1654
|
else {
|
|
1612
|
-
let t =
|
|
1613
|
-
if (a = t ? "unknown" : "failed", console.error("[RunEngine] start() error:",
|
|
1655
|
+
let t = n instanceof TypeError;
|
|
1656
|
+
if (a = t ? "unknown" : "failed", console.error("[RunEngine] start() error:", n), t) {
|
|
1614
1657
|
this.setStage("recovering"), this.emit({
|
|
1615
1658
|
type: "activity",
|
|
1616
1659
|
phase: "网络异常,尝试重连",
|
|
1617
1660
|
status: "waiting",
|
|
1618
1661
|
countEvent: !1
|
|
1619
1662
|
});
|
|
1620
|
-
let t = this.
|
|
1621
|
-
if (
|
|
1622
|
-
await this.resumeRun({
|
|
1623
|
-
sessionId:
|
|
1624
|
-
invocationId:
|
|
1625
|
-
afterSeqId:
|
|
1663
|
+
let t = this.invocationId, i = this.activeSessionId;
|
|
1664
|
+
if ((o || this.lastSeqId > 0) && t && i && r === i) {
|
|
1665
|
+
a = await this.resumeRun({
|
|
1666
|
+
sessionId: i,
|
|
1667
|
+
invocationId: t,
|
|
1668
|
+
afterSeqId: this.lastSeqId,
|
|
1669
|
+
reconnect: !0,
|
|
1670
|
+
onSessionReloadNeeded: () => e.onRecovered?.(i, t)
|
|
1626
1671
|
});
|
|
1627
1672
|
return;
|
|
1628
|
-
} catch (e) {
|
|
1629
|
-
console.warn("[RunEngine] afterSeqId resume failed, fall back to error:", e);
|
|
1630
1673
|
}
|
|
1631
1674
|
this.setStage("error"), this.emit({
|
|
1632
1675
|
type: "error",
|
|
1633
|
-
error:
|
|
1676
|
+
error: n instanceof Error ? n : Error(String(n))
|
|
1634
1677
|
});
|
|
1635
|
-
} else
|
|
1678
|
+
} else n instanceof Y && n.code === 429 ? (this.setStage("error"), this.emit({
|
|
1636
1679
|
type: "rate_limited",
|
|
1637
|
-
message:
|
|
1680
|
+
message: n.message || "请求过于频繁,请稍后重试",
|
|
1638
1681
|
sessionId: r
|
|
1639
1682
|
})) : (this.setStage("error"), this.emit({
|
|
1640
1683
|
type: "error",
|
|
1641
|
-
error:
|
|
1684
|
+
error: n instanceof Error ? n : Error(String(n))
|
|
1642
1685
|
}));
|
|
1643
1686
|
}
|
|
1644
1687
|
} finally {
|
|
1645
|
-
i(!1), this.operationEpoch === t && (
|
|
1688
|
+
i(!1), this.operationEpoch === t && (m.getState().setSessionStreaming(this.streamingKey, !1), this.setStage("idle"), this.activeCompactionId = null, this.activeSessionId = null, e.onSettled?.(r, a));
|
|
1646
1689
|
}
|
|
1647
1690
|
})(), !0;
|
|
1648
1691
|
}
|
|
@@ -1658,7 +1701,7 @@ var Kt = {
|
|
|
1658
1701
|
});
|
|
1659
1702
|
}
|
|
1660
1703
|
disconnect() {
|
|
1661
|
-
this._stage !== "idle" && (this.operationEpoch += 1, this.abortController?.abort(), this.aguiClient?.abort(),
|
|
1704
|
+
this._stage !== "idle" && (this.operationEpoch += 1, this.abortController?.abort(), this.aguiClient?.abort(), m.getState().setSessionStreaming(this.streamingKey, !1), this.projection.isVisible?.() !== !1 && m.getState().clearActivity(), this._stage = "idle", this.activeCompactionId = null, this.activeSessionId = null);
|
|
1662
1705
|
}
|
|
1663
1706
|
async cancelRemote(e) {
|
|
1664
1707
|
try {
|
|
@@ -1669,66 +1712,64 @@ var Kt = {
|
|
|
1669
1712
|
this.stop();
|
|
1670
1713
|
}
|
|
1671
1714
|
async resumeRun(e) {
|
|
1672
|
-
this.abortController?.abort()
|
|
1715
|
+
this.abortController?.abort();
|
|
1716
|
+
let t = new AbortController();
|
|
1717
|
+
this.abortController = t;
|
|
1718
|
+
let n = this.operationEpoch, r = () => this.operationEpoch === n && this.abortController === t;
|
|
1719
|
+
this.activeSessionId = e.sessionId, this.publishInvocation(e.invocationId), this.setStage("connecting"), this.emit({
|
|
1673
1720
|
type: "activity",
|
|
1674
1721
|
phase: "恢复运行事件订阅",
|
|
1675
1722
|
status: "connecting",
|
|
1676
1723
|
countEvent: !1
|
|
1677
1724
|
});
|
|
1678
|
-
let
|
|
1725
|
+
let i = null;
|
|
1679
1726
|
try {
|
|
1680
|
-
let n =
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
for (let e of o) {
|
|
1699
|
-
if (!e.trim()) continue;
|
|
1700
|
-
let n = Z(e);
|
|
1701
|
-
for (let e of n) e.eventName === "__done__" || e.eventName === "__ping__" || (this.emit({
|
|
1727
|
+
let n = e.reconnect ? Jt : [0], a = e.afterSeqId, o = !0;
|
|
1728
|
+
for (let s of n) {
|
|
1729
|
+
if (await Yt(s, t.signal), e.reconnect && await Xt(t.signal), !r() || t.signal.aborted) return "cancelled";
|
|
1730
|
+
try {
|
|
1731
|
+
if (o) try {
|
|
1732
|
+
i = await this.readRecoveredRunEvents(e, a, t.signal, r, (e) => {
|
|
1733
|
+
a = Math.max(a, e);
|
|
1734
|
+
});
|
|
1735
|
+
} catch (t) {
|
|
1736
|
+
if (!e.reconnect || !(t instanceof Y) || t.code !== 404) throw t;
|
|
1737
|
+
o = !1;
|
|
1738
|
+
}
|
|
1739
|
+
if (!i && e.reconnect && r() && !t.signal.aborted && (i = await this.readRecoveredRunStatus(e, t.signal)), i) break;
|
|
1740
|
+
} catch (n) {
|
|
1741
|
+
if (!r() || t.signal.aborted || n instanceof X) return "cancelled";
|
|
1742
|
+
let i = n instanceof TypeError || n instanceof Y && (n.code >= 500 || n.code === 408 || n.code === 429);
|
|
1743
|
+
if (!e.reconnect || !i) throw n;
|
|
1744
|
+
this.emit({
|
|
1702
1745
|
type: "activity",
|
|
1703
|
-
phase: "
|
|
1704
|
-
status: "
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
event: e.data
|
|
1708
|
-
}), t = Ut(e.data) || t);
|
|
1746
|
+
phase: "网络异常,尝试重连",
|
|
1747
|
+
status: "waiting",
|
|
1748
|
+
countEvent: !1
|
|
1749
|
+
});
|
|
1709
1750
|
}
|
|
1710
1751
|
}
|
|
1711
|
-
this.setStage("completing"),
|
|
1752
|
+
return !r() || t.signal.aborted ? "cancelled" : (i && this.setStage("completing"), i === "cancelled" || i === "canceled" || i === "aborted" ? this.emit({
|
|
1712
1753
|
type: "activity",
|
|
1713
1754
|
phase: "后台长任务已取消",
|
|
1714
1755
|
status: "stopped",
|
|
1715
1756
|
countEvent: !1
|
|
1716
|
-
}) :
|
|
1757
|
+
}) : i === "interrupted" ? this.emit({
|
|
1717
1758
|
type: "activity",
|
|
1718
1759
|
phase: "后台长任务已中断",
|
|
1719
1760
|
status: "stopped",
|
|
1720
1761
|
countEvent: !1
|
|
1721
|
-
}) :
|
|
1762
|
+
}) : i === "failed" || i === "error" ? this.emit({
|
|
1722
1763
|
type: "activity",
|
|
1723
1764
|
phase: "后台长任务失败",
|
|
1724
1765
|
status: "failed",
|
|
1725
1766
|
countEvent: !1
|
|
1726
|
-
}) :
|
|
1767
|
+
}) : i === "resume_failed" ? this.emit({
|
|
1727
1768
|
type: "activity",
|
|
1728
1769
|
phase: "后台长任务恢复失败",
|
|
1729
1770
|
status: "failed",
|
|
1730
1771
|
countEvent: !1
|
|
1731
|
-
}) :
|
|
1772
|
+
}) : i ? this.emit({
|
|
1732
1773
|
type: "activity",
|
|
1733
1774
|
phase: "后台长任务已完成",
|
|
1734
1775
|
status: "completed",
|
|
@@ -1739,18 +1780,80 @@ var Kt = {
|
|
|
1739
1780
|
status: "waiting",
|
|
1740
1781
|
detail: "事件流已结束,但运行时尚未提供终态;正在等待会话状态对账。",
|
|
1741
1782
|
countEvent: !1
|
|
1742
|
-
}),
|
|
1783
|
+
}), i && this.emit({
|
|
1784
|
+
type: "stream_ended",
|
|
1785
|
+
runId: e.invocationId
|
|
1786
|
+
}), (i || !e.reconnect) && e.onSessionReloadNeeded?.(), i === "completed" ? "completed" : i === "cancelled" || i === "canceled" || i === "aborted" ? "cancelled" : i ? "failed" : "unknown");
|
|
1743
1787
|
} catch (e) {
|
|
1744
|
-
e instanceof DOMException && e.name === "AbortError"
|
|
1788
|
+
let t = e instanceof DOMException && e.name === "AbortError";
|
|
1789
|
+
return t || console.error("Failed to subscribe to run events:", e), t ? "cancelled" : "unknown";
|
|
1790
|
+
} finally {
|
|
1791
|
+
r() && (m.getState().setSessionStreaming(e.sessionId, !1), this.publishInvocation(""), this.setStage("idle"), this.activeSessionId = null);
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
async readRecoveredRunEvents(e, t, n, r, i) {
|
|
1795
|
+
let { sessionId: a, invocationId: o } = e, s = (await this.api.subscribeRunEvents({
|
|
1796
|
+
sessionId: a,
|
|
1797
|
+
invocationId: o,
|
|
1798
|
+
afterSeqId: t
|
|
1799
|
+
}, { signal: n })).getReader(), c = new TextDecoder(), l = "";
|
|
1800
|
+
try {
|
|
1801
|
+
if (!r() || n.aborted) return null;
|
|
1802
|
+
for (this.setStage("streaming"), this.emit({
|
|
1803
|
+
type: "activity",
|
|
1804
|
+
phase: "等待恢复事件",
|
|
1805
|
+
status: "waiting",
|
|
1806
|
+
countEvent: !1
|
|
1807
|
+
}); r() && !n.aborted;) {
|
|
1808
|
+
let { value: u, done: d } = await s.read();
|
|
1809
|
+
if (d || !r() || n.aborted) break;
|
|
1810
|
+
l += c.decode(u, { stream: !0 });
|
|
1811
|
+
let { chunks: f, remainder: p } = Mt(l);
|
|
1812
|
+
l = p;
|
|
1813
|
+
for (let s of f) for (let { data: c } of jt(s)) {
|
|
1814
|
+
if (!r() || n.aborted) return null;
|
|
1815
|
+
if (!c || typeof c != "object") continue;
|
|
1816
|
+
let s = c;
|
|
1817
|
+
if ((s.SessionId ?? a) !== a || (s.InvocationId ?? o) !== o || e.reconnect && (!s.SessionId || !s.InvocationId) || s.SeqId && s.SeqId <= t) continue;
|
|
1818
|
+
this.emit({
|
|
1819
|
+
type: "stream_event",
|
|
1820
|
+
event: s,
|
|
1821
|
+
sessionId: a
|
|
1822
|
+
}), s.SeqId && (t = s.SeqId, i(t));
|
|
1823
|
+
let l = Zt(s);
|
|
1824
|
+
if (l) return l;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
return null;
|
|
1745
1828
|
} finally {
|
|
1746
|
-
|
|
1829
|
+
await s.cancel().catch(() => {});
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
async readRecoveredRunStatus({ sessionId: e, invocationId: t }, n) {
|
|
1833
|
+
let r = await this.api.getSession(e, { signal: n }), i = String(r.ActiveRunStatus || "").trim().toLowerCase();
|
|
1834
|
+
if (r.SessionId === e && r.ActiveInvocationId === t && qt.has(i)) return i;
|
|
1835
|
+
if (n.aborted) return null;
|
|
1836
|
+
let a = await this.api.listSessionEvents(e, {
|
|
1837
|
+
eventTypes: [
|
|
1838
|
+
"run_status",
|
|
1839
|
+
"run.completed",
|
|
1840
|
+
"run.failed",
|
|
1841
|
+
"run.cancelled"
|
|
1842
|
+
],
|
|
1843
|
+
limit: 20,
|
|
1844
|
+
signal: n
|
|
1845
|
+
});
|
|
1846
|
+
for (let n of a.Events) if (n.SessionId === e && n.InvocationId === t) {
|
|
1847
|
+
let e = Zt(n);
|
|
1848
|
+
if (e) return e;
|
|
1747
1849
|
}
|
|
1850
|
+
return null;
|
|
1748
1851
|
}
|
|
1749
1852
|
resumeCheckpoint(e) {
|
|
1750
1853
|
if (this._stage !== "idle") return !1;
|
|
1751
1854
|
let t = ++this.operationEpoch;
|
|
1752
1855
|
this.abortController = new AbortController(), this.activeSessionId = e.sessionId;
|
|
1753
|
-
let n =
|
|
1856
|
+
let n = $t();
|
|
1754
1857
|
return this.publishInvocation(n), (async () => {
|
|
1755
1858
|
let r = "unknown";
|
|
1756
1859
|
try {
|
|
@@ -1784,7 +1887,7 @@ var Kt = {
|
|
|
1784
1887
|
checkpointId: e.checkpointId,
|
|
1785
1888
|
resumeAttemptId: e.resumeAttemptId,
|
|
1786
1889
|
invocationId: n
|
|
1787
|
-
}, { signal: this.abortController?.signal }), i =
|
|
1890
|
+
}, { signal: this.abortController?.signal }), i = kt("responses"), a = i.createState();
|
|
1788
1891
|
this.setStage("streaming"), this.emit({
|
|
1789
1892
|
type: "activity",
|
|
1790
1893
|
source: "restore",
|
|
@@ -1836,7 +1939,7 @@ var Kt = {
|
|
|
1836
1939
|
error: e instanceof Error ? e : Error(String(e))
|
|
1837
1940
|
}));
|
|
1838
1941
|
} finally {
|
|
1839
|
-
this.operationEpoch === t && (
|
|
1942
|
+
this.operationEpoch === t && (m.getState().setSessionStreaming(e.sessionId, !1), this.publishInvocation(""), this.setStage("idle"), this.activeSessionId = null, e.onSettled?.(e.sessionId, r));
|
|
1840
1943
|
}
|
|
1841
1944
|
})(), !0;
|
|
1842
1945
|
}
|
|
@@ -1848,7 +1951,7 @@ var Kt = {
|
|
|
1848
1951
|
if (!n) return !1;
|
|
1849
1952
|
let r = ++this.operationEpoch;
|
|
1850
1953
|
this.activeSessionId = t;
|
|
1851
|
-
let i =
|
|
1954
|
+
let i = $t();
|
|
1852
1955
|
return this.publishInvocation(i), this.setStage("connecting"), this.emit({
|
|
1853
1956
|
type: "activity",
|
|
1854
1957
|
phase: "提交人工确认",
|
|
@@ -1860,7 +1963,7 @@ var Kt = {
|
|
|
1860
1963
|
this.setStage("streaming");
|
|
1861
1964
|
let r = await n.resume(i, {
|
|
1862
1965
|
interruptId: e.interruptId,
|
|
1863
|
-
logicalRunId:
|
|
1966
|
+
logicalRunId: w.get(t, e.interruptId)?.runId || void 0,
|
|
1864
1967
|
status: e.status,
|
|
1865
1968
|
payload: e.payload
|
|
1866
1969
|
}), o = e.payload && typeof e.payload == "object" ? e.payload : {}, s = String(o.decision || o.type || "").toLowerCase(), c = r.pendingInterruptIds?.includes(e.interruptId);
|
|
@@ -1929,23 +2032,23 @@ var Kt = {
|
|
|
1929
2032
|
});
|
|
1930
2033
|
for (let t of r.attachments) {
|
|
1931
2034
|
let n = t.type.startsWith("image/") ? "attachment.image" : "attachment.file";
|
|
1932
|
-
if (!
|
|
2035
|
+
if (!pe(e.surface, n)) throw new G("conversation_input_unsupported", "Conversation attachment is not declared by the active surface.", { capability: n });
|
|
1933
2036
|
}
|
|
1934
2037
|
r.attachments.length > 0 && i.push(...await this.uploadCanonicalAttachments(r.attachments));
|
|
1935
|
-
let o =
|
|
2038
|
+
let o = Ft(this.config.thinkingMode), s = me({
|
|
1936
2039
|
inputId: `input:${n}`,
|
|
1937
2040
|
sessionId: t,
|
|
1938
2041
|
idempotencyKey: `conversation:${n}`,
|
|
1939
2042
|
parts: i,
|
|
1940
|
-
...this.config.selectedModel &&
|
|
1941
|
-
...o !== "auto" &&
|
|
2043
|
+
...this.config.selectedModel && pe(e.surface, "model.select") ? { modelRef: this.config.selectedModel } : {},
|
|
2044
|
+
...o !== "auto" && pe(e.surface, "reasoning.effort") ? { reasoning: o } : {},
|
|
1942
2045
|
extensions: {
|
|
1943
|
-
...this.config.permissionMode &&
|
|
2046
|
+
...this.config.permissionMode && pe(e.surface, "approval") ? { "ksadk.approval": this.config.permissionMode } : {},
|
|
1944
2047
|
...r.executionMode === "plan" ? { "ksadk.collaboration": "plan" } : {},
|
|
1945
2048
|
...r.executionMode === "goal" && a ? { "ksadk.goal": a } : {}
|
|
1946
2049
|
}
|
|
1947
2050
|
});
|
|
1948
|
-
return
|
|
2051
|
+
return fe(e.surface, s);
|
|
1949
2052
|
}
|
|
1950
2053
|
async uploadCanonicalAttachments(e) {
|
|
1951
2054
|
this.setStage("uploading-files");
|
|
@@ -1992,7 +2095,7 @@ var Kt = {
|
|
|
1992
2095
|
} catch (e) {
|
|
1993
2096
|
this.emit({
|
|
1994
2097
|
type: "system_message",
|
|
1995
|
-
content: `【系统提示】图片 ${t.name} 读取失败,原因: ${
|
|
2098
|
+
content: `【系统提示】图片 ${t.name} 读取失败,原因: ${Nt(e)}`
|
|
1996
2099
|
});
|
|
1997
2100
|
}
|
|
1998
2101
|
continue;
|
|
@@ -2009,7 +2112,7 @@ var Kt = {
|
|
|
2009
2112
|
} catch (e) {
|
|
2010
2113
|
this.emit({
|
|
2011
2114
|
type: "system_message",
|
|
2012
|
-
content: `【系统提示】文件 ${t.name} 上传失败,原因: ${
|
|
2115
|
+
content: `【系统提示】文件 ${t.name} 上传失败,原因: ${Nt(e)}`
|
|
2013
2116
|
});
|
|
2014
2117
|
}
|
|
2015
2118
|
}
|
|
@@ -2020,44 +2123,44 @@ var Kt = {
|
|
|
2020
2123
|
for (let e = 0; e < t.length; e += r) n += String.fromCharCode(...t.subarray(e, e + r));
|
|
2021
2124
|
return `data:${e.type || "application/octet-stream"};base64,${btoa(n)}`;
|
|
2022
2125
|
}
|
|
2023
|
-
buildRequestBody(e, n, r, a, o
|
|
2024
|
-
let
|
|
2025
|
-
this.config.kernelSessionEventsEnabled && this.config.presentationProfile === "agent-block-v1" && (
|
|
2026
|
-
let
|
|
2027
|
-
this.config.agentFramework.trim().toLowerCase() === "langgraph" &&
|
|
2028
|
-
let
|
|
2126
|
+
buildRequestBody(e, n, r, i, a, o) {
|
|
2127
|
+
let s = this.buildExecutionMetadata(i), c = this.config.hostedChatTransport?.Runtime === "dsh" ? this.config.dshApprovalMode : this.config.permissionMode || "risk", l = {};
|
|
2128
|
+
this.config.kernelSessionEventsEnabled && this.config.presentationProfile === "agent-block-v1" && (l["ksadk.presentation"] = { profile: "agent-block-v1" });
|
|
2129
|
+
let u = this.config.mcpAuthorization;
|
|
2130
|
+
this.config.agentFramework.trim().toLowerCase() === "langgraph" && u?.schema === B.schema && u.digest === B.digest && (l["mcp.authorization"] = B);
|
|
2131
|
+
let d = {
|
|
2029
2132
|
AgentId: this.config.agentId,
|
|
2030
2133
|
SessionId: e,
|
|
2031
|
-
InvocationId:
|
|
2134
|
+
InvocationId: o,
|
|
2032
2135
|
Stream: !0,
|
|
2033
2136
|
...t(this.config.hostedChatTransport) ? { ContinueOnDisconnect: !0 } : {},
|
|
2034
2137
|
...this.config.kernelSessionEventsEnabled ? { Background: !0 } : {},
|
|
2035
|
-
...Object.keys(
|
|
2138
|
+
...Object.keys(l).length ? { Extensions: l } : {},
|
|
2036
2139
|
ApiFormat: n,
|
|
2037
2140
|
Model: this.config.selectedModel || void 0,
|
|
2038
2141
|
ModelMetadata: this.config.selectedModelMetadata || void 0,
|
|
2039
|
-
ModelOptions:
|
|
2142
|
+
ModelOptions: It(Ft(this.config.thinkingMode)),
|
|
2040
2143
|
Metadata: { agentengine: {
|
|
2041
|
-
...
|
|
2042
|
-
...
|
|
2043
|
-
...
|
|
2144
|
+
...c ? { tool_approval_mode: c } : {},
|
|
2145
|
+
...f(p.getState().modeFor(this.config.agentId)),
|
|
2146
|
+
...s
|
|
2044
2147
|
} }
|
|
2045
2148
|
};
|
|
2046
|
-
if (r)
|
|
2149
|
+
if (r) d.ResponsesInput = i.responsesInput, d.PreviousResponseId = i.previousResponseId;
|
|
2047
2150
|
else {
|
|
2048
2151
|
let e = [{
|
|
2049
2152
|
type: "input_text",
|
|
2050
|
-
text:
|
|
2153
|
+
text: i.text.trim()
|
|
2051
2154
|
}];
|
|
2052
|
-
e.push(...
|
|
2155
|
+
e.push(...a), n === "responses" && (d.ResponsesInput = [{
|
|
2053
2156
|
role: "user",
|
|
2054
2157
|
content: e
|
|
2055
|
-
}]),
|
|
2158
|
+
}]), d.Messages = [{
|
|
2056
2159
|
role: "user",
|
|
2057
2160
|
content: e
|
|
2058
2161
|
}];
|
|
2059
2162
|
}
|
|
2060
|
-
return
|
|
2163
|
+
return d;
|
|
2061
2164
|
}
|
|
2062
2165
|
buildExecutionMetadata(e) {
|
|
2063
2166
|
let t = e.executionMode;
|
|
@@ -2092,7 +2195,7 @@ var Kt = {
|
|
|
2092
2195
|
status: "running",
|
|
2093
2196
|
countEvent: !1
|
|
2094
2197
|
});
|
|
2095
|
-
let i = new
|
|
2198
|
+
let i = new Pe(e), a = r === "agent-block-v1" && t.presentationProfile === "agent-block-v1" ? "agent-block-v1" : "flat-v1", o = new ge(e, void 0, a), s = this.config.kernelCommandEventsEnabled && t.commandId || void 0;
|
|
2096
2199
|
if (this.config.kernelCommandEventsEnabled && !s) return this.emit({
|
|
2097
2200
|
type: "error",
|
|
2098
2201
|
error: /* @__PURE__ */ Error("运行回执缺少命令身份,无法安全订阅本轮输出。")
|
|
@@ -2113,9 +2216,9 @@ var Kt = {
|
|
|
2113
2216
|
let { value: s, done: d } = await r.read();
|
|
2114
2217
|
if (d) break;
|
|
2115
2218
|
_ += g.decode(s, { stream: !0 });
|
|
2116
|
-
let m =
|
|
2219
|
+
let m = Mt(_);
|
|
2117
2220
|
_ = m.remainder;
|
|
2118
|
-
for (let r of m.chunks) if (r.trim()) for (let s of
|
|
2221
|
+
for (let r of m.chunks) if (r.trim()) for (let s of jt(r)) {
|
|
2119
2222
|
f && (s.eventName === "__ping__" || s.data && typeof s.data == "object") && (f = !1, this.emit({
|
|
2120
2223
|
type: "activity",
|
|
2121
2224
|
phase: "正在处理",
|
|
@@ -2151,7 +2254,7 @@ var Kt = {
|
|
|
2151
2254
|
sessionId: e,
|
|
2152
2255
|
result: {
|
|
2153
2256
|
state: t,
|
|
2154
|
-
presentation:
|
|
2257
|
+
presentation: he(t, { profile: a }),
|
|
2155
2258
|
runId: l,
|
|
2156
2259
|
cursor: this.lastSeqId
|
|
2157
2260
|
}
|
|
@@ -2164,7 +2267,7 @@ var Kt = {
|
|
|
2164
2267
|
sessionId: e
|
|
2165
2268
|
}), h.EventType === "run_status")) {
|
|
2166
2269
|
let e = String(h.Content?.status || "").toLowerCase();
|
|
2167
|
-
e !== "interrupted" &&
|
|
2270
|
+
e !== "interrupted" && qt.has(e) && (u = e);
|
|
2168
2271
|
}
|
|
2169
2272
|
}
|
|
2170
2273
|
}
|
|
@@ -2210,32 +2313,32 @@ var Kt = {
|
|
|
2210
2313
|
messageId: r,
|
|
2211
2314
|
invocationId: i
|
|
2212
2315
|
})), s += o.decode(e, { stream: !0 });
|
|
2213
|
-
let { chunks: m, remainder: h } =
|
|
2316
|
+
let { chunks: m, remainder: h } = Mt(s);
|
|
2214
2317
|
s = h;
|
|
2215
2318
|
for (let e of m) {
|
|
2216
2319
|
if (!e.trim()) continue;
|
|
2217
2320
|
if (this.isCompactionChunk(e)) {
|
|
2218
|
-
let t =
|
|
2321
|
+
let t = jt(e);
|
|
2219
2322
|
for (let e of t) e.eventName.startsWith("response.compaction") && this.upsertCompactionMessage({
|
|
2220
2323
|
...e.data,
|
|
2221
2324
|
phase: e.eventName.split(".").pop()
|
|
2222
2325
|
});
|
|
2223
2326
|
continue;
|
|
2224
2327
|
}
|
|
2225
|
-
let i =
|
|
2328
|
+
let i = jt(e), o = !1;
|
|
2226
2329
|
for (let e of i) {
|
|
2227
2330
|
if (e.eventName === "__done__") {
|
|
2228
2331
|
o = !0;
|
|
2229
2332
|
continue;
|
|
2230
2333
|
}
|
|
2231
|
-
let i =
|
|
2334
|
+
let i = Qt(e.eventName, e.data);
|
|
2232
2335
|
i && !(d.size > 0 && (e.eventName === "response.incomplete" || e.data?.type === "response.incomplete")) && this.emit({
|
|
2233
2336
|
type: "activity",
|
|
2234
2337
|
...i
|
|
2235
2338
|
});
|
|
2236
2339
|
let a = t.parse(e, n);
|
|
2237
2340
|
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);
|
|
2238
|
-
if (
|
|
2341
|
+
if (At(a)) {
|
|
2239
2342
|
o = !0;
|
|
2240
2343
|
let e = a.find((e) => e.type === "terminal");
|
|
2241
2344
|
u = e && "status" in e ? String(e.status || "") : void 0;
|
|
@@ -2406,12 +2509,12 @@ var Kt = {
|
|
|
2406
2509
|
};
|
|
2407
2510
|
//#endregion
|
|
2408
2511
|
//#region src/utils/recovered-run.ts
|
|
2409
|
-
function
|
|
2512
|
+
function nn(e, t, n) {
|
|
2410
2513
|
let r = e.filter((e) => e.role === "model" && e.invocationId === n), i = L(t).filter((e) => e.role === "model"), a = i.map((e) => ({
|
|
2411
2514
|
...e,
|
|
2412
2515
|
id: !e.itemId && i.length === 1 ? r[0]?.id || `${n}:assistant` : e.id,
|
|
2413
2516
|
invocationId: n,
|
|
2414
|
-
blocks:
|
|
2517
|
+
blocks: Fe({
|
|
2415
2518
|
content: e.content,
|
|
2416
2519
|
reasoning: e.reasoning,
|
|
2417
2520
|
reasoningSource: e.reasoningSource,
|
|
@@ -2428,24 +2531,24 @@ function Jt(e, t, n) {
|
|
|
2428
2531
|
}
|
|
2429
2532
|
//#endregion
|
|
2430
2533
|
//#region src/core/run/dispatcher.ts
|
|
2431
|
-
var
|
|
2432
|
-
function
|
|
2534
|
+
var rn = "连接断开或生成出错,请重试";
|
|
2535
|
+
function an(e, t, n) {
|
|
2433
2536
|
let r = e.tools?.[t];
|
|
2434
2537
|
return r?.callId ? n ? r.callId === n ? t : n : Object.entries(e.tools ?? {}).findLast(([, e]) => e.name === t)?.[0] ?? t : t;
|
|
2435
2538
|
}
|
|
2436
|
-
function
|
|
2539
|
+
function on(e) {
|
|
2437
2540
|
let t = String(e.message || "").trim();
|
|
2438
|
-
return /runtime agent kernel is not ready/i.test(t) ? "云端运行时尚未就绪,请检查部署状态后重试" : !t || /failed to fetch|networkerror/i.test(t) ?
|
|
2541
|
+
return /runtime agent kernel is not ready/i.test(t) ? "云端运行时尚未就绪,请检查部署状态后重试" : !t || /failed to fetch|networkerror/i.test(t) ? rn : t.length <= 240 ? t : rn;
|
|
2439
2542
|
}
|
|
2440
|
-
var
|
|
2543
|
+
var sn = new Set(["completed"]), cn = new Set([
|
|
2441
2544
|
"failed",
|
|
2442
2545
|
"error",
|
|
2443
2546
|
"cancelled",
|
|
2444
2547
|
"canceled",
|
|
2445
2548
|
"aborted",
|
|
2446
2549
|
"incomplete"
|
|
2447
|
-
]),
|
|
2448
|
-
function
|
|
2550
|
+
]), ln = /* @__PURE__ */ new Map();
|
|
2551
|
+
function un(e, t) {
|
|
2449
2552
|
H.getState().patchMessages((n) => {
|
|
2450
2553
|
if (n.some((t) => t.id === e)) return t ? n.map((n) => n.id === e ? {
|
|
2451
2554
|
...n,
|
|
@@ -2471,11 +2574,11 @@ function Q(e, t) {
|
|
|
2471
2574
|
}];
|
|
2472
2575
|
});
|
|
2473
2576
|
}
|
|
2474
|
-
function
|
|
2577
|
+
function dn(e) {
|
|
2475
2578
|
return e.filter((e) => e.eventType !== "optimistic_assistant_placeholder");
|
|
2476
2579
|
}
|
|
2477
|
-
function
|
|
2478
|
-
let t = String(e || "").trim().toLowerCase(), n =
|
|
2580
|
+
function fn(e) {
|
|
2581
|
+
let t = String(e || "").trim().toLowerCase(), n = sn.has(t) ? "completed" : cn.has(t) ? "error" : null;
|
|
2479
2582
|
n && H.getState().patchMessages((e) => e.map((e) => {
|
|
2480
2583
|
if (!e.tools) return e;
|
|
2481
2584
|
let t = !1, r = Object.fromEntries(Object.entries(e.tools).map(([e, r]) => r.status === "running" ? (t = !0, [e, {
|
|
@@ -2488,7 +2591,7 @@ function nn(e) {
|
|
|
2488
2591
|
} : e;
|
|
2489
2592
|
}));
|
|
2490
2593
|
}
|
|
2491
|
-
function
|
|
2594
|
+
function pn(e, t) {
|
|
2492
2595
|
!e.sessionId && t?.draftId && (e = {
|
|
2493
2596
|
...e,
|
|
2494
2597
|
sessionId: t.draftId
|
|
@@ -2508,11 +2611,11 @@ function rn(e, t) {
|
|
|
2508
2611
|
"conversation_snapshot"
|
|
2509
2612
|
].includes(e.type)) return;
|
|
2510
2613
|
let r = H.getState(), i = (e) => {
|
|
2511
|
-
e &&
|
|
2614
|
+
e && m.getState().updateActivity({ sessionId: e });
|
|
2512
2615
|
};
|
|
2513
2616
|
switch (e.type) {
|
|
2514
2617
|
case "activity":
|
|
2515
|
-
|
|
2618
|
+
m.getState().updateActivity({
|
|
2516
2619
|
sessionId: e.sessionId,
|
|
2517
2620
|
visible: !n,
|
|
2518
2621
|
source: e.source,
|
|
@@ -2523,7 +2626,7 @@ function rn(e, t) {
|
|
|
2523
2626
|
});
|
|
2524
2627
|
break;
|
|
2525
2628
|
case "user_message_added":
|
|
2526
|
-
|
|
2629
|
+
m.getState().setBanner(null), r.patchMessages((t) => [...t, {
|
|
2527
2630
|
id: e.messageId,
|
|
2528
2631
|
role: "user",
|
|
2529
2632
|
content: "",
|
|
@@ -2531,13 +2634,13 @@ function rn(e, t) {
|
|
|
2531
2634
|
}]);
|
|
2532
2635
|
break;
|
|
2533
2636
|
case "assistant_message_created":
|
|
2534
|
-
|
|
2637
|
+
un(e.messageId, e.invocationId);
|
|
2535
2638
|
break;
|
|
2536
2639
|
case "text_delta":
|
|
2537
|
-
|
|
2640
|
+
un(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => t.id === e.messageId ? {
|
|
2538
2641
|
...t,
|
|
2539
2642
|
content: t.content + e.delta,
|
|
2540
|
-
blocks:
|
|
2643
|
+
blocks: xe(t.blocks, e.delta)
|
|
2541
2644
|
} : t));
|
|
2542
2645
|
break;
|
|
2543
2646
|
case "text_replace":
|
|
@@ -2545,31 +2648,31 @@ function rn(e, t) {
|
|
|
2545
2648
|
r.patchMessages((t) => t.map((t) => t.id === e.messageId && t.role === "model" ? {
|
|
2546
2649
|
...t,
|
|
2547
2650
|
content: e.text,
|
|
2548
|
-
blocks:
|
|
2651
|
+
blocks: Le(t.blocks, e.text)
|
|
2549
2652
|
} : t)), i(e.sessionId);
|
|
2550
2653
|
break;
|
|
2551
2654
|
case "text_final":
|
|
2552
|
-
|
|
2553
|
-
let n = !!(e.text && !t.content && t.reasoning?.endsWith(e.text)), r = n ? t.reasoning.slice(0, -e.text.length) : t.reasoning, i = n ?
|
|
2655
|
+
un(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => t.id === e.messageId ? (() => {
|
|
2656
|
+
let n = !!(e.text && !t.content && t.reasoning?.endsWith(e.text)), r = n ? t.reasoning.slice(0, -e.text.length) : t.reasoning, i = n ? Te(t.blocks, e.text) : t.blocks;
|
|
2554
2657
|
return {
|
|
2555
2658
|
...t,
|
|
2556
2659
|
reasoning: r,
|
|
2557
2660
|
content: e.text,
|
|
2558
|
-
blocks:
|
|
2661
|
+
blocks: Ce(i, e.text)
|
|
2559
2662
|
};
|
|
2560
2663
|
})() : t));
|
|
2561
2664
|
break;
|
|
2562
2665
|
case "reasoning_delta":
|
|
2563
|
-
|
|
2666
|
+
un(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => t.id === e.messageId ? {
|
|
2564
2667
|
...t,
|
|
2565
2668
|
reasoning: (t.reasoning || "") + e.delta,
|
|
2566
|
-
blocks:
|
|
2669
|
+
blocks: Me(t.blocks, e.delta, e.itemId)
|
|
2567
2670
|
} : t));
|
|
2568
2671
|
break;
|
|
2569
2672
|
case "reasoning_snapshot":
|
|
2570
2673
|
r.patchMessages((t) => t.map((t) => {
|
|
2571
2674
|
if (t.id !== e.messageId || !t.blocks) return t;
|
|
2572
|
-
let n =
|
|
2675
|
+
let n = we(t.blocks, e.itemId, e.text);
|
|
2573
2676
|
return {
|
|
2574
2677
|
...t,
|
|
2575
2678
|
blocks: n,
|
|
@@ -2578,15 +2681,15 @@ function rn(e, t) {
|
|
|
2578
2681
|
}));
|
|
2579
2682
|
break;
|
|
2580
2683
|
case "tool_upsert":
|
|
2581
|
-
|
|
2684
|
+
un(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => {
|
|
2582
2685
|
if (t.id !== e.messageId) return t;
|
|
2583
|
-
let n =
|
|
2686
|
+
let n = an(t, e.name, e.callId), r = t.tools?.[n], i = e.callId ? {
|
|
2584
2687
|
...e.extra,
|
|
2585
2688
|
callId: e.callId
|
|
2586
2689
|
} : 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;
|
|
2587
2690
|
return {
|
|
2588
2691
|
...t,
|
|
2589
|
-
blocks:
|
|
2692
|
+
blocks: Ne(t.blocks, e.name, {
|
|
2590
2693
|
args: e.args,
|
|
2591
2694
|
status: s,
|
|
2592
2695
|
extra: i
|
|
@@ -2609,12 +2712,12 @@ function rn(e, t) {
|
|
|
2609
2712
|
}));
|
|
2610
2713
|
break;
|
|
2611
2714
|
case "tool_result":
|
|
2612
|
-
|
|
2715
|
+
un(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => {
|
|
2613
2716
|
if (t.id !== e.messageId) return t;
|
|
2614
|
-
let n = P(e.output) ? "error" : "completed", r =
|
|
2717
|
+
let n = P(e.output) ? "error" : "completed", r = an(t, e.name, e.callId);
|
|
2615
2718
|
return {
|
|
2616
2719
|
...t,
|
|
2617
|
-
blocks:
|
|
2720
|
+
blocks: Ne(t.blocks, e.name, {
|
|
2618
2721
|
output: e.output,
|
|
2619
2722
|
status: n,
|
|
2620
2723
|
...e.callId && { extra: { callId: e.callId } }
|
|
@@ -2635,7 +2738,7 @@ function rn(e, t) {
|
|
|
2635
2738
|
}));
|
|
2636
2739
|
break;
|
|
2637
2740
|
case "approval_requested":
|
|
2638
|
-
if (
|
|
2741
|
+
if (C({
|
|
2639
2742
|
approvalRequestId: e.approvalRequestId,
|
|
2640
2743
|
protocol: e.protocol,
|
|
2641
2744
|
requestSchema: e.requestSchema,
|
|
@@ -2647,7 +2750,7 @@ function rn(e, t) {
|
|
|
2647
2750
|
previousResponseId: e.previousResponseId,
|
|
2648
2751
|
sessionId: e.sessionId
|
|
2649
2752
|
}), n) break;
|
|
2650
|
-
|
|
2753
|
+
un(e.messageId), r.patchMessages((t) => t.map((t) => {
|
|
2651
2754
|
if (t.id !== e.messageId) return t;
|
|
2652
2755
|
let n = t.tools?.[e.approvalRequestId], r = n?.approvalStatus === "approved" || n?.approvalStatus === "rejected" || n?.approvalStatus === "cancelled", i = {
|
|
2653
2756
|
approvalRequestId: e.approvalRequestId,
|
|
@@ -2659,7 +2762,7 @@ function rn(e, t) {
|
|
|
2659
2762
|
}, a = r ? n.status : "paused";
|
|
2660
2763
|
return {
|
|
2661
2764
|
...t,
|
|
2662
|
-
blocks:
|
|
2765
|
+
blocks: Ne(t.blocks, e.name, {
|
|
2663
2766
|
args: e.args,
|
|
2664
2767
|
status: a,
|
|
2665
2768
|
extra: i
|
|
@@ -2678,7 +2781,7 @@ function rn(e, t) {
|
|
|
2678
2781
|
}));
|
|
2679
2782
|
break;
|
|
2680
2783
|
case "interaction_submit_rejected":
|
|
2681
|
-
|
|
2784
|
+
y(e);
|
|
2682
2785
|
break;
|
|
2683
2786
|
case "question_requested":
|
|
2684
2787
|
te({
|
|
@@ -2689,7 +2792,7 @@ function rn(e, t) {
|
|
|
2689
2792
|
});
|
|
2690
2793
|
break;
|
|
2691
2794
|
case "question_resolved":
|
|
2692
|
-
|
|
2795
|
+
b({
|
|
2693
2796
|
questionId: e.questionId,
|
|
2694
2797
|
answers: e.answers,
|
|
2695
2798
|
revision: e.revision,
|
|
@@ -2697,7 +2800,7 @@ function rn(e, t) {
|
|
|
2697
2800
|
});
|
|
2698
2801
|
break;
|
|
2699
2802
|
case "approval_resolved":
|
|
2700
|
-
if (
|
|
2803
|
+
if (D({
|
|
2701
2804
|
approvalRequestId: e.approvalRequestId,
|
|
2702
2805
|
decision: e.decision,
|
|
2703
2806
|
revision: e.revision,
|
|
@@ -2742,7 +2845,7 @@ function rn(e, t) {
|
|
|
2742
2845
|
}]);
|
|
2743
2846
|
break;
|
|
2744
2847
|
case "compaction": {
|
|
2745
|
-
let t = `compaction-${Date.now()}`, n = e.phase === "start" ? "running" : e.phase === "failed" ? "failed" : "completed", i =
|
|
2848
|
+
let t = `compaction-${Date.now()}`, n = e.phase === "start" ? "running" : e.phase === "failed" ? "failed" : "completed", i = re({
|
|
2746
2849
|
id: t,
|
|
2747
2850
|
timestamp: Date.now(),
|
|
2748
2851
|
status: n,
|
|
@@ -2756,34 +2859,34 @@ function rn(e, t) {
|
|
|
2756
2859
|
break;
|
|
2757
2860
|
}
|
|
2758
2861
|
case "stage_changed":
|
|
2759
|
-
e.stage === "streaming" || e.stage === "connecting" ?
|
|
2862
|
+
e.stage === "streaming" || e.stage === "connecting" ? m.getState().setSessionStreaming(e.sessionId, !0) : (e.stage === "completing" || e.stage === "error" || e.stage === "cancelled") && m.getState().setSessionStreaming(e.sessionId, !1);
|
|
2760
2863
|
break;
|
|
2761
2864
|
case "stream_ended":
|
|
2762
|
-
|
|
2865
|
+
m.getState().setSessionStreaming(e.sessionId, !1), n || H.getState().patchMessages((t) => dn(t).map((t) => !(!e.runId || t.runId === e.runId || t.invocationId === e.runId) || t.role !== "model" || !t.blocks?.some((e) => e.status === "streaming") ? t : {
|
|
2763
2866
|
...t,
|
|
2764
|
-
blocks:
|
|
2867
|
+
blocks: ke(t.blocks.map((e) => e.type === "text" && e.status === "streaming" ? {
|
|
2765
2868
|
...e,
|
|
2766
2869
|
status: "done"
|
|
2767
2870
|
} : e))
|
|
2768
2871
|
})), globalThis.setTimeout(() => {
|
|
2769
|
-
let t =
|
|
2872
|
+
let t = m.getState();
|
|
2770
2873
|
t.getSessionActivity(e.sessionId)?.status === "completed" && t.clearSessionActivity(e.sessionId);
|
|
2771
2874
|
}, 2400);
|
|
2772
2875
|
break;
|
|
2773
2876
|
case "error": {
|
|
2774
|
-
let t =
|
|
2775
|
-
|
|
2877
|
+
let t = on(e.error);
|
|
2878
|
+
m.getState().setSessionStreaming(e.sessionId, !1), m.getState().updateActivity({
|
|
2776
2879
|
sessionId: e.sessionId,
|
|
2777
2880
|
visible: !n,
|
|
2778
2881
|
status: "failed",
|
|
2779
2882
|
phase: "运行失败",
|
|
2780
2883
|
detail: t,
|
|
2781
2884
|
countEvent: !1
|
|
2782
|
-
}), n || (
|
|
2885
|
+
}), n || (m.getState().setBanner({
|
|
2783
2886
|
kind: "error",
|
|
2784
2887
|
message: t,
|
|
2785
2888
|
sessionId: e.sessionId
|
|
2786
|
-
}), r.patchMessages((e) => [...
|
|
2889
|
+
}), r.patchMessages((e) => [...dn(e), {
|
|
2787
2890
|
id: String(Date.now()),
|
|
2788
2891
|
role: "model",
|
|
2789
2892
|
content: `运行失败:${t}`,
|
|
@@ -2792,51 +2895,51 @@ function rn(e, t) {
|
|
|
2792
2895
|
break;
|
|
2793
2896
|
}
|
|
2794
2897
|
case "rate_limited":
|
|
2795
|
-
|
|
2898
|
+
m.getState().setSessionStreaming(e.sessionId, !1), m.getState().updateActivity({
|
|
2796
2899
|
sessionId: e.sessionId,
|
|
2797
2900
|
visible: !n,
|
|
2798
2901
|
status: "failed",
|
|
2799
2902
|
phase: "请求被限流",
|
|
2800
2903
|
countEvent: !1
|
|
2801
|
-
}), n || (
|
|
2904
|
+
}), n || (m.getState().setBanner({
|
|
2802
2905
|
kind: "rate_limited",
|
|
2803
2906
|
message: e.message || "请求过于频繁,请稍后重试",
|
|
2804
2907
|
retryAfterSec: e.retryAfterSec,
|
|
2805
2908
|
sessionId: e.sessionId
|
|
2806
|
-
}), r.patchMessages(
|
|
2909
|
+
}), r.patchMessages(dn));
|
|
2807
2910
|
break;
|
|
2808
2911
|
case "terminal":
|
|
2809
|
-
e.sessionId && String(e.status || "").trim().toLowerCase() !== "incomplete" &&
|
|
2912
|
+
e.sessionId && String(e.status || "").trim().toLowerCase() !== "incomplete" && w.markSessionTerminal(e.sessionId), n || fn(e.status);
|
|
2810
2913
|
break;
|
|
2811
2914
|
case "stream_event": {
|
|
2812
2915
|
let t = e.sessionId || e.event.SessionId;
|
|
2813
|
-
|
|
2916
|
+
x(e.event, t || void 0);
|
|
2814
2917
|
let r = e.event.SeqId;
|
|
2815
|
-
!n && typeof r == "number" && r > 0 &&
|
|
2918
|
+
!n && typeof r == "number" && r > 0 && m.getState().setLastSeqId(r), t && m.getState().updateActivity({
|
|
2816
2919
|
sessionId: t,
|
|
2817
2920
|
visible: !n
|
|
2818
2921
|
});
|
|
2819
2922
|
let i = String(e.event.InvocationId || "").trim();
|
|
2820
2923
|
if (!n && t && i) {
|
|
2821
|
-
let n = `${t}:${i}`, r = F(
|
|
2822
|
-
|
|
2924
|
+
let n = `${t}:${i}`, r = F(ln.get(n) || [], [e.event]);
|
|
2925
|
+
ln.set(n, r), H.getState().patchMessages((e) => e.some((e) => e.eventType === "conversation_item_v1" && e.runId === i) ? e : nn(e, r, i)), ne(e.event) && ln.delete(n);
|
|
2823
2926
|
}
|
|
2824
2927
|
e.event.EventType === "run_checkpoint" && t && W.getState().upsertSessionCheckpoint(t, e.event);
|
|
2825
2928
|
{
|
|
2826
2929
|
let r = R(e.event);
|
|
2827
|
-
r === "completed" ?
|
|
2930
|
+
r === "completed" ? m.getState().updateActivity({
|
|
2828
2931
|
sessionId: t,
|
|
2829
2932
|
visible: !n,
|
|
2830
2933
|
status: "completed",
|
|
2831
2934
|
phase: "后台长任务已完成",
|
|
2832
2935
|
countEvent: !1
|
|
2833
|
-
}) : r === "cancelled" || r === "canceled" || r === "aborted" ?
|
|
2936
|
+
}) : r === "cancelled" || r === "canceled" || r === "aborted" ? m.getState().updateActivity({
|
|
2834
2937
|
sessionId: t,
|
|
2835
2938
|
visible: !n,
|
|
2836
2939
|
status: "stopped",
|
|
2837
2940
|
phase: "后台长任务已取消",
|
|
2838
2941
|
countEvent: !1
|
|
2839
|
-
}) : (r === "failed" || r === "error") &&
|
|
2942
|
+
}) : (r === "failed" || r === "error") && m.getState().updateActivity({
|
|
2840
2943
|
sessionId: t,
|
|
2841
2944
|
visible: !n,
|
|
2842
2945
|
status: "failed",
|
|
@@ -2847,10 +2950,10 @@ function rn(e, t) {
|
|
|
2847
2950
|
break;
|
|
2848
2951
|
}
|
|
2849
2952
|
case "conversation_snapshot": {
|
|
2850
|
-
let t =
|
|
2851
|
-
for (let e of t.interactions)
|
|
2953
|
+
let t = De(e.result);
|
|
2954
|
+
for (let e of t.interactions) w.upsert(e);
|
|
2852
2955
|
if (n) break;
|
|
2853
|
-
r.patchMessages((t) =>
|
|
2956
|
+
r.patchMessages((t) => Ae(t, e.result, e.optimisticMessageId)), i(e.sessionId);
|
|
2854
2957
|
break;
|
|
2855
2958
|
}
|
|
2856
2959
|
case "a2ui_surface_begin": {
|
|
@@ -2916,7 +3019,7 @@ function rn(e, t) {
|
|
|
2916
3019
|
originMessageId: e.messageId,
|
|
2917
3020
|
...r ? { runId: r } : {},
|
|
2918
3021
|
...e.interactionId ? { interactionId: e.interactionId } : {}
|
|
2919
|
-
}, o =
|
|
3022
|
+
}, o = ye(t.flatMap((e) => [...e.aguiActivity ? [{
|
|
2920
3023
|
message: e,
|
|
2921
3024
|
activity: e.aguiActivity
|
|
2922
3025
|
}] : [], ...(e.aguiActivities || []).map((t) => ({
|
|
@@ -2928,12 +3031,12 @@ function rn(e, t) {
|
|
|
2928
3031
|
});
|
|
2929
3032
|
if (o) return t.map((t) => t === o.message ? {
|
|
2930
3033
|
...t,
|
|
2931
|
-
...t.aguiActivity === o.activity ? { aguiActivity:
|
|
3034
|
+
...t.aguiActivity === o.activity ? { aguiActivity: _e(o.activity, a, e.batchId) } : { aguiActivities: t.aguiActivities?.map((t) => t === o.activity ? _e(t, a, e.batchId) : t) }
|
|
2932
3035
|
} : t);
|
|
2933
3036
|
let s = !1, c = t.map((t) => {
|
|
2934
3037
|
if (t.id !== e.messageId) return t;
|
|
2935
3038
|
s = !0;
|
|
2936
|
-
let n = [...t.aguiActivities || [],
|
|
3039
|
+
let n = [...t.aguiActivities || [], _e(void 0, a, e.batchId)];
|
|
2937
3040
|
return {
|
|
2938
3041
|
...t,
|
|
2939
3042
|
aguiActivities: n
|
|
@@ -2946,66 +3049,66 @@ function rn(e, t) {
|
|
|
2946
3049
|
content: "",
|
|
2947
3050
|
timestamp: l?.timestamp || Date.now(),
|
|
2948
3051
|
...r ? { invocationId: r } : {},
|
|
2949
|
-
aguiActivity:
|
|
3052
|
+
aguiActivity: _e(l?.aguiActivity, a, e.batchId)
|
|
2950
3053
|
};
|
|
2951
3054
|
return l ? t.map((e) => e.id === i ? u : e) : [...t, u];
|
|
2952
3055
|
});
|
|
2953
3056
|
break;
|
|
2954
3057
|
}
|
|
2955
3058
|
}
|
|
2956
|
-
function
|
|
2957
|
-
|
|
3059
|
+
function mn() {
|
|
3060
|
+
ln.clear();
|
|
2958
3061
|
}
|
|
2959
3062
|
//#endregion
|
|
2960
3063
|
//#region src/hooks/useRunAgent.ts
|
|
2961
|
-
var
|
|
2962
|
-
function
|
|
3064
|
+
var hn = 64;
|
|
3065
|
+
function gn(e, t, n) {
|
|
2963
3066
|
if (t.sessionId = n, t.conversationId) return;
|
|
2964
3067
|
let r = JSON.stringify([t.agentId, n]);
|
|
2965
3068
|
e.set(r, t), t.key !== r && e.get(t.key) === t && e.delete(t.key), t.key = r;
|
|
2966
3069
|
}
|
|
2967
|
-
function
|
|
3070
|
+
function _n(e) {
|
|
2968
3071
|
let t = _(), r = J(/* @__PURE__ */ new Map()), i = J(/* @__PURE__ */ new Set()), a = K((e) => i.current.has(e), []), o = K((e) => {
|
|
2969
3072
|
let t = r.current;
|
|
2970
|
-
if (!(t.size <=
|
|
2971
|
-
if (t.size <=
|
|
3073
|
+
if (!(t.size <= hn)) for (let [n, r] of t) {
|
|
3074
|
+
if (t.size <= hn) break;
|
|
2972
3075
|
n === e || r.engine.stage !== "idle" || r.queue.length > 0 || r.isVisible() || t.delete(n);
|
|
2973
3076
|
}
|
|
2974
|
-
}, []), l =
|
|
3077
|
+
}, []), l = Ve(() => new ve({ rendererCatalog: Se }), []), u = e.conversationClient === void 0 ? e.uiCapabilities.ConversationSurface == null ? null : l : e.conversationClient, { agentId: d, apiFormats: f, agentFramework: p, selectedModel: h, selectedModelMetadata: v, thinkingMode: y, permissionMode: b, currentSessionIdRef: x, conversationIdRef: S, queuedDraftRef: ee, onRunSettled: C, onRunRecovered: w, onSessionCreated: T, waitForPendingSessionCreation: E, uiCapabilities: D, outbox: O } = e, te = c((e) => e.status === "ready" && e.agentId === d && e.accessMode !== "Share" ? e.capabilities.McpAuthorization : void 0), k = Ve(() => ({
|
|
2975
3078
|
a2uiCatalogRegistry: t,
|
|
2976
3079
|
agentId: d,
|
|
2977
3080
|
apiFormats: f,
|
|
2978
3081
|
agentFramework: p,
|
|
2979
|
-
selectedModel:
|
|
3082
|
+
selectedModel: h,
|
|
2980
3083
|
selectedModelMetadata: v,
|
|
2981
|
-
thinkingMode:
|
|
3084
|
+
thinkingMode: D.Thinking ? y : "auto",
|
|
2982
3085
|
permissionMode: b,
|
|
2983
3086
|
mcpAuthorization: te,
|
|
2984
|
-
dshApprovalMode:
|
|
2985
|
-
runtimeCapabilityMatrix:
|
|
2986
|
-
hostedChatTransport: n(
|
|
2987
|
-
checkpointResumePreviewEnabled: !!
|
|
2988
|
-
kernelSessionEventsEnabled:
|
|
2989
|
-
kernelCommandEventsEnabled:
|
|
2990
|
-
presentationProfile:
|
|
3087
|
+
dshApprovalMode: D.Approval && D.ApprovalPolicy?.RuntimeOverride ? D.ApprovalPolicy.DefaultMode : void 0,
|
|
3088
|
+
runtimeCapabilityMatrix: D.RuntimeCapabilityMatrix,
|
|
3089
|
+
hostedChatTransport: n(D, { requireResumableRun: !!(D.RunLifecycle?.Enabled && D.RunLifecycle.Resume) }),
|
|
3090
|
+
checkpointResumePreviewEnabled: !!D.RunLifecycle?.CheckpointResumePreview,
|
|
3091
|
+
kernelSessionEventsEnabled: D.KernelSessionEvents === !0 || D.KernelSessionEventsByCommand === !0,
|
|
3092
|
+
kernelCommandEventsEnabled: D.KernelSessionEventsByCommand === !0,
|
|
3093
|
+
presentationProfile: de(D.ConversationSurface, Se),
|
|
2991
3094
|
conversationClient: u || void 0
|
|
2992
3095
|
}), [
|
|
2993
3096
|
d,
|
|
2994
3097
|
f,
|
|
2995
3098
|
p,
|
|
2996
|
-
|
|
3099
|
+
h,
|
|
2997
3100
|
v,
|
|
2998
3101
|
y,
|
|
2999
3102
|
b,
|
|
3000
|
-
|
|
3103
|
+
D,
|
|
3001
3104
|
te,
|
|
3002
3105
|
u,
|
|
3003
3106
|
t
|
|
3004
|
-
]),
|
|
3107
|
+
]), A = K((t = x.current) => {
|
|
3005
3108
|
let n = e.conversationIdRef?.current, i = JSON.stringify([d, n || t || "new-session"]), a = r.current.get(i);
|
|
3006
3109
|
if (!a) {
|
|
3007
3110
|
o(i);
|
|
3008
|
-
let s = () => e.agentIdRef.current === d && (e.conversationIdRef ? e.conversationIdRef.current === n : x.current === a.sessionId), c = new
|
|
3111
|
+
let s = () => e.agentIdRef.current === d && (e.conversationIdRef ? e.conversationIdRef.current === n : x.current === a.sessionId), c = new tn(e.api, {
|
|
3009
3112
|
isVisible: s,
|
|
3010
3113
|
draftId: n
|
|
3011
3114
|
});
|
|
@@ -3017,7 +3120,7 @@ function cn(e) {
|
|
|
3017
3120
|
engine: c,
|
|
3018
3121
|
queue: [],
|
|
3019
3122
|
isVisible: s
|
|
3020
|
-
}, c.subscribe((e) =>
|
|
3123
|
+
}, c.subscribe((e) => pn(e, {
|
|
3021
3124
|
visible: s(),
|
|
3022
3125
|
draftId: n
|
|
3023
3126
|
})), r.current.set(i, a);
|
|
@@ -3030,31 +3133,31 @@ function cn(e) {
|
|
|
3030
3133
|
e.conversationIdRef,
|
|
3031
3134
|
x,
|
|
3032
3135
|
o
|
|
3033
|
-
]),
|
|
3034
|
-
let t =
|
|
3035
|
-
return t.engine.stage === "idle" && t.engine.updateConfig(
|
|
3036
|
-
}, [
|
|
3136
|
+
]), j = K((e) => {
|
|
3137
|
+
let t = A(e);
|
|
3138
|
+
return t.engine.stage === "idle" && t.engine.updateConfig(k), t.engine;
|
|
3139
|
+
}, [k, A]), M = K((e) => {
|
|
3037
3140
|
if (!e.isVisible()) return;
|
|
3038
3141
|
let t = e.queue.map((e) => e.draft);
|
|
3039
|
-
|
|
3040
|
-
}, [
|
|
3142
|
+
ee.current = t, g.getState().setQueuedDrafts(t);
|
|
3143
|
+
}, [ee]), N = K((e) => {
|
|
3041
3144
|
let t = e.queue[0];
|
|
3042
|
-
!t || e.engine.stage !== "idle" || (e.queue.shift(),
|
|
3043
|
-
t.launch() || (e.queue.unshift(t),
|
|
3145
|
+
!t || e.engine.stage !== "idle" || (e.queue.shift(), M(e), queueMicrotask(() => {
|
|
3146
|
+
t.launch() || (e.queue.unshift(t), M(e));
|
|
3044
3147
|
}));
|
|
3045
|
-
}, [
|
|
3148
|
+
}, [M]);
|
|
3046
3149
|
q(() => {
|
|
3047
|
-
let t = JSON.stringify([d, e.conversationId ||
|
|
3048
|
-
n ?
|
|
3150
|
+
let t = JSON.stringify([d, e.conversationId || S?.current || e.currentSessionId || "new-session"]), n = r.current.get(t);
|
|
3151
|
+
n ? M(n) : (ee.current = [], g.getState().setQueuedDrafts([]));
|
|
3049
3152
|
}, [
|
|
3050
3153
|
d,
|
|
3051
3154
|
e.currentSessionId,
|
|
3052
3155
|
e.conversationId,
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3156
|
+
S,
|
|
3157
|
+
M,
|
|
3158
|
+
ee
|
|
3056
3159
|
]);
|
|
3057
|
-
let
|
|
3160
|
+
let ne = K((e) => {
|
|
3058
3161
|
let t = e.text.trim(), n = e.attachments.map((e) => ({
|
|
3059
3162
|
name: e.name,
|
|
3060
3163
|
url: URL.createObjectURL(e),
|
|
@@ -3089,19 +3192,19 @@ function cn(e) {
|
|
|
3089
3192
|
}), t;
|
|
3090
3193
|
}, []), F = K(async (e, t, n, a, o, c) => {
|
|
3091
3194
|
if (c && i.current.has(c)) return !1;
|
|
3092
|
-
let l =
|
|
3093
|
-
|
|
3195
|
+
let l = A();
|
|
3196
|
+
M(l);
|
|
3094
3197
|
let u = {
|
|
3095
3198
|
text: e,
|
|
3096
3199
|
attachments: [...t],
|
|
3097
3200
|
responsesInput: n,
|
|
3098
3201
|
previousResponseId: a,
|
|
3099
3202
|
executionMode: o,
|
|
3100
|
-
optimisticMessageId:
|
|
3203
|
+
optimisticMessageId: ne({
|
|
3101
3204
|
text: e,
|
|
3102
3205
|
attachments: t
|
|
3103
3206
|
})
|
|
3104
|
-
}, d = n === void 0 && l.conversationId &&
|
|
3207
|
+
}, d = n === void 0 && l.conversationId && O ? O : void 0, f = l.conversationId && d ? d.enqueue({
|
|
3105
3208
|
requestId: c,
|
|
3106
3209
|
conversationId: l.conversationId,
|
|
3107
3210
|
agentId: l.agentId,
|
|
@@ -3116,19 +3219,19 @@ function cn(e) {
|
|
|
3116
3219
|
f && d && (i.current.add(f.requestId), d.setRuntimeAttachments(f.requestId, t));
|
|
3117
3220
|
let p;
|
|
3118
3221
|
try {
|
|
3119
|
-
p = await
|
|
3222
|
+
p = await E?.();
|
|
3120
3223
|
} catch (e) {
|
|
3121
3224
|
throw f && d && (i.current.delete(f.requestId), d.update(f.requestId, {
|
|
3122
3225
|
status: "unknown",
|
|
3123
3226
|
error: "创建会话的结果待确认。"
|
|
3124
3227
|
})), e;
|
|
3125
3228
|
}
|
|
3126
|
-
!l.sessionId && p &&
|
|
3127
|
-
let
|
|
3128
|
-
|
|
3229
|
+
!l.sessionId && p && gn(r.current, l, p);
|
|
3230
|
+
let h, _ = n === void 0 ? null : new Promise((e) => {
|
|
3231
|
+
h = e;
|
|
3129
3232
|
}), v = () => {
|
|
3130
3233
|
if (l.engine.stage !== "idle") return !1;
|
|
3131
|
-
l.engine.updateConfig(
|
|
3234
|
+
l.engine.updateConfig(k), f && d && d.markSending(f.requestId), l.isVisible() && (g.getState().setMobileActionsOpen(!1), P(u.optimisticMessageId)), m.getState().setSessionStreaming(l.sessionId || l.conversationId, !0);
|
|
3132
3235
|
let e = l.engine.start({
|
|
3133
3236
|
...u,
|
|
3134
3237
|
sessionId: l.sessionId,
|
|
@@ -3140,57 +3243,61 @@ function cn(e) {
|
|
|
3140
3243
|
},
|
|
3141
3244
|
onSessionCreated: (e) => {
|
|
3142
3245
|
let t = l.isVisible(), n = l.sessionId || l.conversationId;
|
|
3143
|
-
|
|
3246
|
+
gn(r.current, l, e), f && d && d.update(f.requestId, { nativeSessionId: e }), m.getState().setSessionStreaming(e, !0), n !== e && m.getState().setSessionStreaming(n, !1), T?.(e, l.conversationId, l.agentId), !T && t && (s.getState().upsertSessions([{
|
|
3144
3247
|
SessionId: e,
|
|
3145
3248
|
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3146
|
-
}]), x.current = e, s.getState().setCurrentSessionId(e)), t &&
|
|
3249
|
+
}]), x.current = e, s.getState().setCurrentSessionId(e)), t && at(l.agentId, e);
|
|
3147
3250
|
},
|
|
3148
3251
|
onSessionUpsert: () => {},
|
|
3149
|
-
onDispatchResult:
|
|
3252
|
+
onDispatchResult: h,
|
|
3253
|
+
onRecovered: (e, t) => {
|
|
3254
|
+
l.isVisible() && l.sessionId === e && w?.(e, t);
|
|
3255
|
+
},
|
|
3150
3256
|
onSettled: (e, t = "unknown") => {
|
|
3151
|
-
f && i.current.delete(f.requestId), f && d && d.update(f.requestId, { status: t === "completed" || t === "awaiting-input" ? "completed" : t === "cancelled" ? "cancelled" : t === "failed" ? "failed" : "unknown" }), C?.(e, l.agentId, t), t === "completed" &&
|
|
3257
|
+
f && i.current.delete(f.requestId), f && d && d.update(f.requestId, { status: t === "completed" || t === "awaiting-input" ? "completed" : t === "cancelled" ? "cancelled" : t === "failed" ? "failed" : "unknown" }), C?.(e, l.agentId, t), t === "completed" && N(l);
|
|
3152
3258
|
}
|
|
3153
3259
|
});
|
|
3154
|
-
return e ||
|
|
3260
|
+
return e || m.getState().setSessionStreaming(l.sessionId || l.conversationId, !1), e;
|
|
3155
3261
|
}, y = v();
|
|
3156
3262
|
return !y && n === void 0 ? (l.queue.push({
|
|
3157
3263
|
draft: u,
|
|
3158
3264
|
launch: v
|
|
3159
|
-
}),
|
|
3265
|
+
}), M(l), !0) : _ ? (y || h?.(!1), _) : y;
|
|
3160
3266
|
}, [
|
|
3161
3267
|
P,
|
|
3268
|
+
ne,
|
|
3269
|
+
k,
|
|
3270
|
+
x,
|
|
3162
3271
|
N,
|
|
3272
|
+
A,
|
|
3273
|
+
w,
|
|
3274
|
+
C,
|
|
3275
|
+
T,
|
|
3163
3276
|
O,
|
|
3164
|
-
x,
|
|
3165
3277
|
M,
|
|
3166
|
-
|
|
3167
|
-
C,
|
|
3168
|
-
w,
|
|
3169
|
-
D,
|
|
3170
|
-
j,
|
|
3171
|
-
T
|
|
3278
|
+
E
|
|
3172
3279
|
]), I = K(() => {
|
|
3173
|
-
|
|
3174
|
-
}, [x,
|
|
3175
|
-
|
|
3176
|
-
}, [x,
|
|
3177
|
-
let t =
|
|
3280
|
+
j(x.current).stop();
|
|
3281
|
+
}, [x, j]), L = K(() => {
|
|
3282
|
+
j(x.current).disconnect();
|
|
3283
|
+
}, [x, j]), R = K((e) => {
|
|
3284
|
+
let t = A(e.sessionId), n = j(e.sessionId);
|
|
3178
3285
|
if (n.stage !== "idle") return !1;
|
|
3179
|
-
|
|
3286
|
+
mn(), g.getState().setMobileActionsOpen(!1), m.getState().setSessionStreaming(e.sessionId, !0);
|
|
3180
3287
|
let r = n.resumeCheckpoint({
|
|
3181
3288
|
...e,
|
|
3182
3289
|
onSettled: (e, n) => {
|
|
3183
|
-
C?.(e, t.agentId, n), n === "completed" &&
|
|
3290
|
+
C?.(e, t.agentId, n), n === "completed" && N(t);
|
|
3184
3291
|
}
|
|
3185
3292
|
});
|
|
3186
|
-
return r ||
|
|
3293
|
+
return r || m.getState().setSessionStreaming(e.sessionId, !1), r;
|
|
3187
3294
|
}, [
|
|
3188
|
-
|
|
3295
|
+
N,
|
|
3296
|
+
j,
|
|
3189
3297
|
A,
|
|
3190
|
-
k,
|
|
3191
3298
|
C
|
|
3192
|
-
]),
|
|
3193
|
-
|
|
3299
|
+
]), re = K(() => {
|
|
3300
|
+
mn();
|
|
3194
3301
|
}, []);
|
|
3195
3302
|
return {
|
|
3196
3303
|
submitDraft: F,
|
|
@@ -3205,7 +3312,7 @@ function cn(e) {
|
|
|
3205
3312
|
if (!r) return !1;
|
|
3206
3313
|
let i = x.current;
|
|
3207
3314
|
if (!i) return !1;
|
|
3208
|
-
let a =
|
|
3315
|
+
let a = A(i), o = j(i), s = n.status === "cancelled" ? "cancelled" : "resolved", c = Object.prototype.hasOwnProperty.call(n, "payload") ? n.payload : {
|
|
3209
3316
|
action: t.name,
|
|
3210
3317
|
sourceComponentId: t.sourceComponentId,
|
|
3211
3318
|
context: n
|
|
@@ -3216,56 +3323,56 @@ function cn(e) {
|
|
|
3216
3323
|
status: s,
|
|
3217
3324
|
payload: c,
|
|
3218
3325
|
onSettled: (e) => {
|
|
3219
|
-
C?.(e, a.agentId),
|
|
3326
|
+
C?.(e, a.agentId), N(a);
|
|
3220
3327
|
}
|
|
3221
3328
|
});
|
|
3222
3329
|
}, [
|
|
3223
3330
|
x,
|
|
3224
|
-
|
|
3331
|
+
N,
|
|
3332
|
+
j,
|
|
3225
3333
|
A,
|
|
3226
|
-
k,
|
|
3227
3334
|
C
|
|
3228
3335
|
]),
|
|
3229
3336
|
respondToAguiApproval: K((e) => {
|
|
3230
3337
|
if (!e.interruptId) return !1;
|
|
3231
3338
|
let t = x.current;
|
|
3232
3339
|
if (!t) return !1;
|
|
3233
|
-
let n =
|
|
3340
|
+
let n = A(t), r = j(t);
|
|
3234
3341
|
if (r.stage !== "idle") return !1;
|
|
3235
|
-
|
|
3342
|
+
m.getState().setSessionStreaming(t, !0);
|
|
3236
3343
|
let i = r.resumeAguiInterrupt({
|
|
3237
3344
|
sessionId: t,
|
|
3238
3345
|
interruptId: e.interruptId,
|
|
3239
3346
|
status: e.status || "resolved",
|
|
3240
3347
|
payload: Object.hasOwn(e, "payload") ? e.payload : { decision: e.approve ? "approve" : "reject" },
|
|
3241
3348
|
onSettled: (e) => {
|
|
3242
|
-
C?.(e, n.agentId),
|
|
3349
|
+
C?.(e, n.agentId), N(n);
|
|
3243
3350
|
}
|
|
3244
3351
|
});
|
|
3245
|
-
return i ||
|
|
3352
|
+
return i || m.getState().setSessionStreaming(t, !1), i;
|
|
3246
3353
|
}, [
|
|
3247
3354
|
x,
|
|
3248
|
-
|
|
3355
|
+
N,
|
|
3356
|
+
j,
|
|
3249
3357
|
A,
|
|
3250
|
-
k,
|
|
3251
3358
|
C
|
|
3252
3359
|
]),
|
|
3253
|
-
resetCompaction:
|
|
3360
|
+
resetCompaction: re
|
|
3254
3361
|
};
|
|
3255
3362
|
}
|
|
3256
3363
|
//#endregion
|
|
3257
3364
|
//#region src/utils/history-preparation.ts
|
|
3258
|
-
function
|
|
3365
|
+
function vn(e) {
|
|
3259
3366
|
return e instanceof Y && e.code === 503 && e.detail?.ReasonCode === "HISTORY_PREPARING";
|
|
3260
3367
|
}
|
|
3261
|
-
async function
|
|
3368
|
+
async function yn(e, t) {
|
|
3262
3369
|
let n = Date.now();
|
|
3263
3370
|
for (let r = 0;; r += 1) {
|
|
3264
3371
|
if (!t.isCurrent() || t.signal?.aborted) throw new X();
|
|
3265
3372
|
try {
|
|
3266
3373
|
return await e();
|
|
3267
3374
|
} catch (e) {
|
|
3268
|
-
if (!
|
|
3375
|
+
if (!vn(e) || r >= 60 || Date.now() - n >= 3e5) throw e;
|
|
3269
3376
|
if (!t.isCurrent() || t.signal?.aborted) throw new X();
|
|
3270
3377
|
t.onPreparing?.(), await new Promise((e) => {
|
|
3271
3378
|
let i = () => {
|
|
@@ -3278,7 +3385,7 @@ async function un(e, t) {
|
|
|
3278
3385
|
}
|
|
3279
3386
|
//#endregion
|
|
3280
3387
|
//#region src/utils/kernel-run-history.ts
|
|
3281
|
-
async function
|
|
3388
|
+
async function bn(e, t, n, r, i, a) {
|
|
3282
3389
|
let o = r.Events;
|
|
3283
3390
|
if (o.some((e) => e.EventType === "run.started" && e.InvocationId === n)) return o;
|
|
3284
3391
|
let s = {
|
|
@@ -3326,7 +3433,7 @@ async function dn(e, t, n, r, i, a) {
|
|
|
3326
3433
|
}
|
|
3327
3434
|
//#endregion
|
|
3328
3435
|
//#region src/utils/interaction-history.ts
|
|
3329
|
-
var
|
|
3436
|
+
var xn = [
|
|
3330
3437
|
"mcp.authorization.requested",
|
|
3331
3438
|
"mcp.authorization.updated",
|
|
3332
3439
|
"interaction.requested",
|
|
@@ -3344,8 +3451,8 @@ var fn = [
|
|
|
3344
3451
|
"interaction.expired",
|
|
3345
3452
|
"approval.resolved",
|
|
3346
3453
|
"a2ui.action"
|
|
3347
|
-
],
|
|
3348
|
-
async function
|
|
3454
|
+
], Sn = 32, Cn = 2;
|
|
3455
|
+
async function wn(e, t, n, r, i, a) {
|
|
3349
3456
|
let o = /* @__PURE__ */ new Set(), s = Infinity, c = (e) => {
|
|
3350
3457
|
for (let t of e) {
|
|
3351
3458
|
t.agentBlock && c(t.agentBlock.messages);
|
|
@@ -3367,7 +3474,7 @@ async function hn(e, t, n, r, i, a) {
|
|
|
3367
3474
|
incomplete: !1
|
|
3368
3475
|
};
|
|
3369
3476
|
let l = /* @__PURE__ */ new Set(), u = (e) => {
|
|
3370
|
-
let n =
|
|
3477
|
+
let n = N(e, t);
|
|
3371
3478
|
return !n || !o.has(n.interactionId) ? !1 : (n.status === "pending" && l.add(n.interactionId), !0);
|
|
3372
3479
|
};
|
|
3373
3480
|
if (r.Events.forEach(u), [...o].every((e) => l.has(e))) return {
|
|
@@ -3375,10 +3482,10 @@ async function hn(e, t, n, r, i, a) {
|
|
|
3375
3482
|
incomplete: !1
|
|
3376
3483
|
};
|
|
3377
3484
|
let d = [], f = Number(r.SnapshotSeqId) + 1;
|
|
3378
|
-
for (let n = 0; n <
|
|
3485
|
+
for (let n = 0; n < Cn && i() && !a?.aborted; n += 1) {
|
|
3379
3486
|
let n = await e.listSessionEvents(t, {
|
|
3380
|
-
eventTypes:
|
|
3381
|
-
limit:
|
|
3487
|
+
eventTypes: xn,
|
|
3488
|
+
limit: Sn,
|
|
3382
3489
|
afterSeqId: s,
|
|
3383
3490
|
beforeSeqId: f,
|
|
3384
3491
|
cursorSource: r.CursorSource,
|
|
@@ -3408,7 +3515,7 @@ async function hn(e, t, n, r, i, a) {
|
|
|
3408
3515
|
}
|
|
3409
3516
|
//#endregion
|
|
3410
3517
|
//#region src/utils/messages.js
|
|
3411
|
-
var
|
|
3518
|
+
var Tn = {
|
|
3412
3519
|
running: "running",
|
|
3413
3520
|
completed: "completed",
|
|
3414
3521
|
failed: "error",
|
|
@@ -3419,7 +3526,7 @@ var gn = {
|
|
|
3419
3526
|
rejected: "completed",
|
|
3420
3527
|
cancelled: "completed",
|
|
3421
3528
|
expired: "completed"
|
|
3422
|
-
},
|
|
3529
|
+
}, En = {
|
|
3423
3530
|
pending: "pending",
|
|
3424
3531
|
paused: "pending",
|
|
3425
3532
|
approved: "approved",
|
|
@@ -3428,7 +3535,7 @@ var gn = {
|
|
|
3428
3535
|
cancelled: "cancelled",
|
|
3429
3536
|
expired: "cancelled"
|
|
3430
3537
|
};
|
|
3431
|
-
function
|
|
3538
|
+
function Dn(e) {
|
|
3432
3539
|
if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
|
|
3433
3540
|
if (typeof e == "string") {
|
|
3434
3541
|
let t = Number(e.trim());
|
|
@@ -3438,7 +3545,7 @@ function vn(e) {
|
|
|
3438
3545
|
}
|
|
3439
3546
|
return Date.now();
|
|
3440
3547
|
}
|
|
3441
|
-
function
|
|
3548
|
+
function On(e) {
|
|
3442
3549
|
if (typeof e == "string") return e;
|
|
3443
3550
|
if (e && typeof e == "object") {
|
|
3444
3551
|
if (typeof e.text == "string") return e.text;
|
|
@@ -3446,23 +3553,23 @@ function yn(e) {
|
|
|
3446
3553
|
}
|
|
3447
3554
|
return "";
|
|
3448
3555
|
}
|
|
3449
|
-
function
|
|
3556
|
+
function kn(e) {
|
|
3450
3557
|
let t = {}, n = /* @__PURE__ */ new Map();
|
|
3451
3558
|
for (let t of e ?? []) t?.Name && n.set(t.Name, (n.get(t.Name) || 0) + 1);
|
|
3452
3559
|
for (let r of e ?? []) {
|
|
3453
3560
|
if (!r?.Name) continue;
|
|
3454
|
-
let e =
|
|
3561
|
+
let e = Tn[String(r.Status ?? "completed").toLowerCase()] ?? "completed", i = {
|
|
3455
3562
|
name: r.Name,
|
|
3456
3563
|
args: r.Args === void 0 ? "" : typeof r.Args == "string" ? r.Args : JSON.stringify(r.Args),
|
|
3457
3564
|
status: e
|
|
3458
3565
|
};
|
|
3459
|
-
r.Result !== void 0 && (i.output = typeof r.Result == "string" ? r.Result : JSON.stringify(r.Result)), r.ApprovalRequestId && (i.approvalRequestId = r.ApprovalRequestId, i.approvalStatus =
|
|
3566
|
+
r.Result !== void 0 && (i.output = typeof r.Result == "string" ? r.Result : JSON.stringify(r.Result)), r.ApprovalRequestId && (i.approvalRequestId = r.ApprovalRequestId, i.approvalStatus = En[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);
|
|
3460
3567
|
let a = n.get(r.Name) > 1 && (r.ToolCallId || r.ApprovalRequestId) || r.Name;
|
|
3461
3568
|
t[a] = i;
|
|
3462
3569
|
}
|
|
3463
3570
|
return t;
|
|
3464
3571
|
}
|
|
3465
|
-
function
|
|
3572
|
+
function An(e) {
|
|
3466
3573
|
if (Array.isArray(e)) return e.map((e) => ({
|
|
3467
3574
|
name: e.name || "",
|
|
3468
3575
|
url: e.url || "",
|
|
@@ -3470,10 +3577,10 @@ function xn(e) {
|
|
|
3470
3577
|
fileUri: e.file_uri
|
|
3471
3578
|
}));
|
|
3472
3579
|
}
|
|
3473
|
-
function
|
|
3580
|
+
function jn(e) {
|
|
3474
3581
|
return e == null ? "" : typeof e == "string" ? e : JSON.stringify(e);
|
|
3475
3582
|
}
|
|
3476
|
-
function
|
|
3583
|
+
function Mn(e) {
|
|
3477
3584
|
if (!(!Array.isArray(e) || !e.length)) return e.flatMap((e, t) => {
|
|
3478
3585
|
let n = String(e?.Type || "").toLowerCase(), r = e?.SeqId ?? t;
|
|
3479
3586
|
if (n === "thinking" || n === "text") {
|
|
@@ -3486,13 +3593,13 @@ function Cn(e) {
|
|
|
3486
3593
|
}] : [];
|
|
3487
3594
|
}
|
|
3488
3595
|
if (n !== "tool") return [];
|
|
3489
|
-
let i =
|
|
3596
|
+
let i = Tn[String(e?.Status || "completed").toLowerCase()] ?? "completed";
|
|
3490
3597
|
return [{
|
|
3491
3598
|
id: `history-tool-${r}`,
|
|
3492
3599
|
type: "tool",
|
|
3493
3600
|
toolName: String(e?.Name || "tool"),
|
|
3494
|
-
args:
|
|
3495
|
-
...e?.Result === void 0 ? {} : { output:
|
|
3601
|
+
args: jn(e?.Args),
|
|
3602
|
+
...e?.Result === void 0 ? {} : { output: jn(e.Result) },
|
|
3496
3603
|
status: i,
|
|
3497
3604
|
...e?.ToolCallId ? { extra: {
|
|
3498
3605
|
callId: String(e.ToolCallId),
|
|
@@ -3501,12 +3608,12 @@ function Cn(e) {
|
|
|
3501
3608
|
}];
|
|
3502
3609
|
});
|
|
3503
3610
|
}
|
|
3504
|
-
function
|
|
3505
|
-
let t = e.Role === "assistant" ? "model" : e.Role || "user", n = e.ToolEvents?.length ?
|
|
3611
|
+
function Nn(e) {
|
|
3612
|
+
let t = e.Role === "assistant" ? "model" : e.Role || "user", n = e.ToolEvents?.length ? kn(e.ToolEvents) : void 0, r = An(e.Attachments), i = Mn(e.Blocks), a = e.Reasoning?.length ? e.Reasoning.map((e) => e.text).join("") : void 0, o = {
|
|
3506
3613
|
id: e.MessageId || `msg-${e.SeqId ?? Math.random().toString(36).slice(2)}`,
|
|
3507
3614
|
role: t,
|
|
3508
|
-
content:
|
|
3509
|
-
timestamp:
|
|
3615
|
+
content: On(e.Content),
|
|
3616
|
+
timestamp: Dn(e.Timestamp),
|
|
3510
3617
|
...Number.isSafeInteger(e.SeqId) && e.SeqId > 0 ? { historyOrder: {
|
|
3511
3618
|
seq: e.SeqId,
|
|
3512
3619
|
...Number.isSafeInteger(e.StartSeqId) && e.StartSeqId > 0 ? { group: e.StartSeqId } : {}
|
|
@@ -3516,13 +3623,13 @@ function wn(e) {
|
|
|
3516
3623
|
tools: n,
|
|
3517
3624
|
attachments: r
|
|
3518
3625
|
};
|
|
3519
|
-
return t === "model" && (o.blocks = i ??
|
|
3626
|
+
return t === "model" && (o.blocks = i ?? Fe({
|
|
3520
3627
|
reasoning: a,
|
|
3521
3628
|
tools: n,
|
|
3522
3629
|
content: o.content
|
|
3523
3630
|
})), 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;
|
|
3524
3631
|
}
|
|
3525
|
-
function
|
|
3632
|
+
function Pn(e) {
|
|
3526
3633
|
return Array.isArray(e.Activities) ? e.Activities.flatMap((t, n) => {
|
|
3527
3634
|
let r = String(t?.SurfaceId || "");
|
|
3528
3635
|
if (!r) return [];
|
|
@@ -3536,7 +3643,7 @@ function Tn(e) {
|
|
|
3536
3643
|
id: o && o !== String(e.MessageId || "") ? o : `${o || e.MessageId || e.SeqId || "message"}:a2ui:${r}:${n}`,
|
|
3537
3644
|
role: "a2ui",
|
|
3538
3645
|
content: "",
|
|
3539
|
-
timestamp:
|
|
3646
|
+
timestamp: Dn(e.Timestamp),
|
|
3540
3647
|
...e.InvocationId ? { invocationId: String(e.InvocationId) } : {},
|
|
3541
3648
|
...Number.isSafeInteger(e.SeqId) && e.SeqId > 0 ? { historyOrder: {
|
|
3542
3649
|
seq: e.SeqId,
|
|
@@ -3545,49 +3652,596 @@ function Tn(e) {
|
|
|
3545
3652
|
} } : {},
|
|
3546
3653
|
aguiActivity: {
|
|
3547
3654
|
surfaceId: r,
|
|
3548
|
-
messages:
|
|
3655
|
+
messages: E(a),
|
|
3549
3656
|
...typeof i?.interactionId == "string" ? { interactionId: i.interactionId } : {}
|
|
3550
3657
|
}
|
|
3551
3658
|
}];
|
|
3552
3659
|
}) : [];
|
|
3553
3660
|
}
|
|
3554
|
-
function
|
|
3555
|
-
return
|
|
3661
|
+
function Fn(e) {
|
|
3662
|
+
return ze(Be(e.map(Nn)).flatMap((t, n) => [t, ...Pn(e[n])]));
|
|
3663
|
+
}
|
|
3664
|
+
//#endregion
|
|
3665
|
+
//#region src/utils/history-content.ts
|
|
3666
|
+
function In(e, t) {
|
|
3667
|
+
return t.throwIfAborted(), new Promise((n, r) => {
|
|
3668
|
+
let i = () => {
|
|
3669
|
+
clearTimeout(a), r(t.reason);
|
|
3670
|
+
}, a = setTimeout(() => {
|
|
3671
|
+
t.removeEventListener("abort", i), n();
|
|
3672
|
+
}, e);
|
|
3673
|
+
t.addEventListener("abort", i, { once: !0 });
|
|
3674
|
+
});
|
|
3675
|
+
}
|
|
3676
|
+
async function Ln(e, t, n, r, i, a = {}, o) {
|
|
3677
|
+
let s = JSON.stringify([
|
|
3678
|
+
t,
|
|
3679
|
+
r.HistoryEpoch,
|
|
3680
|
+
r.SnapshotSeqId,
|
|
3681
|
+
r.CursorSource,
|
|
3682
|
+
n,
|
|
3683
|
+
o
|
|
3684
|
+
]);
|
|
3685
|
+
(a.partial?.key !== s || a.partial.api !== e) && (a.partial = {
|
|
3686
|
+
api: e,
|
|
3687
|
+
key: s,
|
|
3688
|
+
chunks: [],
|
|
3689
|
+
offset: 0
|
|
3690
|
+
});
|
|
3691
|
+
let c = a.partial;
|
|
3692
|
+
try {
|
|
3693
|
+
let s = 0;
|
|
3694
|
+
for (;;) {
|
|
3695
|
+
i.throwIfAborted();
|
|
3696
|
+
let l;
|
|
3697
|
+
try {
|
|
3698
|
+
l = await e.listSessionMessages(t, {
|
|
3699
|
+
historyView: "items-v1",
|
|
3700
|
+
contentSeqId: n,
|
|
3701
|
+
contentOffset: c.offset,
|
|
3702
|
+
contentPart: o,
|
|
3703
|
+
cursorSource: r.CursorSource,
|
|
3704
|
+
historyEpoch: r.HistoryEpoch,
|
|
3705
|
+
snapshotSeqId: r.SnapshotSeqId,
|
|
3706
|
+
signal: i
|
|
3707
|
+
});
|
|
3708
|
+
} catch (e) {
|
|
3709
|
+
if (e instanceof Y && e.code === 429 && s < 3) {
|
|
3710
|
+
let t = e.retryAfterMs ?? 500 * 2 ** s;
|
|
3711
|
+
if (t <= 8e3) {
|
|
3712
|
+
s++, await In(t, i);
|
|
3713
|
+
continue;
|
|
3714
|
+
}
|
|
3715
|
+
}
|
|
3716
|
+
throw e instanceof Y && [
|
|
3717
|
+
400,
|
|
3718
|
+
401,
|
|
3719
|
+
403,
|
|
3720
|
+
404,
|
|
3721
|
+
409,
|
|
3722
|
+
410,
|
|
3723
|
+
422
|
|
3724
|
+
].includes(e.code) && delete a.partial, e;
|
|
3725
|
+
}
|
|
3726
|
+
if (i.throwIfAborted(), l.HistoryView !== "items-v1" || l.HistoryEpoch !== r.HistoryEpoch || l.SnapshotSeqId !== r.SnapshotSeqId || l.ContentSeqId !== n || typeof l.ContentChunk != "string") throw delete a.partial, Error("历史正文快照已变化,请重新打开会话。");
|
|
3727
|
+
if (l.NextContentOffset === null) return delete a.partial, c.chunks.push(l.ContentChunk), JSON.parse(c.chunks.join(""));
|
|
3728
|
+
if (!l.ContentChunk.length || !Number.isSafeInteger(l.NextContentOffset) || l.NextContentOffset <= c.offset) throw delete a.partial, Error("历史正文游标无效。");
|
|
3729
|
+
c.chunks.push(l.ContentChunk), c.offset = l.NextContentOffset, s = 0;
|
|
3730
|
+
}
|
|
3731
|
+
} finally {
|
|
3732
|
+
i.aborted && a.partial === c && delete a.partial;
|
|
3733
|
+
}
|
|
3734
|
+
}
|
|
3735
|
+
//#endregion
|
|
3736
|
+
//#region src/utils/session-items.ts
|
|
3737
|
+
function Rn(e, t, n) {
|
|
3738
|
+
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("会话条目分页响应无效,请重新打开会话。");
|
|
3739
|
+
let r = 0;
|
|
3740
|
+
for (let n of e.Items) {
|
|
3741
|
+
if (!n.ItemId || !n.Event || n.Event.SessionId !== t || !Number.isSafeInteger(n.SeqId) || n.SeqId <= r || n.SeqId > e.SnapshotSeqId || n.SeqId !== n.Event.SeqId || n.ContentRef && n.ContentRef.SeqId !== n.SeqId) throw Error("会话条目与当前历史快照不一致。");
|
|
3742
|
+
r = n.SeqId;
|
|
3743
|
+
}
|
|
3744
|
+
return e.Items;
|
|
3745
|
+
}
|
|
3746
|
+
async function zn(e, t, n, r, i, a) {
|
|
3747
|
+
let o = await Ln(e, t, n, r, i, a);
|
|
3748
|
+
if (!Array.isArray(o) || o.length !== 2 || !o[0] || typeof o[0] != "object") throw Error("历史正文格式无效。");
|
|
3749
|
+
return {
|
|
3750
|
+
Content: o[0],
|
|
3751
|
+
Metadata: o[1]
|
|
3752
|
+
};
|
|
3753
|
+
}
|
|
3754
|
+
function Bn(e) {
|
|
3755
|
+
let t = [], n = /* @__PURE__ */ new Map();
|
|
3756
|
+
for (let r of e) {
|
|
3757
|
+
if (Ie(r)) continue;
|
|
3758
|
+
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;
|
|
3759
|
+
if (o === "run.started" && r.Metadata?.ksadk_runtime_event && e?.payload?.source === "ag-ui") {
|
|
3760
|
+
let n = Q(e.payload.input);
|
|
3761
|
+
n && t.push({
|
|
3762
|
+
...r,
|
|
3763
|
+
EventId: "input:" + r.EventId,
|
|
3764
|
+
EventType: "user_message",
|
|
3765
|
+
Content: {
|
|
3766
|
+
role: "user",
|
|
3767
|
+
parts: [{ text: n }]
|
|
3768
|
+
}
|
|
3769
|
+
});
|
|
3770
|
+
}
|
|
3771
|
+
if (a && (o === "assistant_stream_delta" || o === "text.delta" || o === "message.delta" || o === "assistant_stream_snapshot")) {
|
|
3772
|
+
let e = n.get(a);
|
|
3773
|
+
e && o !== "assistant_stream_snapshot" ? (e.event = r, e.parts.push(i)) : n.set(a, {
|
|
3774
|
+
event: r,
|
|
3775
|
+
parts: [i]
|
|
3776
|
+
});
|
|
3777
|
+
} else o === "text.completed" || o === "message.completed" || o === "assistant_message" ? (a && n.delete(a), t.push({
|
|
3778
|
+
...r,
|
|
3779
|
+
EventType: "assistant_message",
|
|
3780
|
+
Content: e?.parts?.length ? e : {
|
|
3781
|
+
...e,
|
|
3782
|
+
parts: [{ text: i }]
|
|
3783
|
+
}
|
|
3784
|
+
})) : t.push(e?.text && !e.parts?.length ? {
|
|
3785
|
+
...r,
|
|
3786
|
+
Content: {
|
|
3787
|
+
...e,
|
|
3788
|
+
parts: [{ text: e.text }]
|
|
3789
|
+
}
|
|
3790
|
+
} : r);
|
|
3791
|
+
}
|
|
3792
|
+
for (let { event: e, parts: r } of n.values()) t.push({
|
|
3793
|
+
...e,
|
|
3794
|
+
EventType: "assistant_stream_snapshot",
|
|
3795
|
+
Metadata: {
|
|
3796
|
+
...e.Metadata,
|
|
3797
|
+
stream_snapshot: !0
|
|
3798
|
+
},
|
|
3799
|
+
Content: { parts: [{ text: r.join("") }] }
|
|
3800
|
+
});
|
|
3801
|
+
return t;
|
|
3802
|
+
}
|
|
3803
|
+
function Z(e) {
|
|
3804
|
+
return e && typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
3805
|
+
}
|
|
3806
|
+
function Vn(e) {
|
|
3807
|
+
let t = /* @__PURE__ */ new Map();
|
|
3808
|
+
for (let n of e) {
|
|
3809
|
+
if (n.EventType !== "approval_response") continue;
|
|
3810
|
+
let e = Z(n.Metadata?.resume_input), r = e.approval_request_id || e.interrupt_id || e.id;
|
|
3811
|
+
if (!r) continue;
|
|
3812
|
+
let i = Z(e.value).decisions, a = Array.isArray(i) && Z(i[0]).type, o = [
|
|
3813
|
+
"cancelled",
|
|
3814
|
+
"expired",
|
|
3815
|
+
"submitted"
|
|
3816
|
+
].includes(String(e.decision)) ? String(e.decision) : e.approve || e.approved || a === "approve" || a === "edit" ? "approved" : "denied";
|
|
3817
|
+
t.set(String(r), o === "submitted" ? "completed" : o);
|
|
3818
|
+
}
|
|
3819
|
+
return e.filter((e) => e.EventType === "approval_request").map((e) => {
|
|
3820
|
+
let n = Z(e.Metadata?.interrupt_info), r = Array.isArray(n.action_requests) ? Z(n.action_requests[0]) : {}, i = String(n.approval_request_id || n.id || "");
|
|
3821
|
+
return Nn({
|
|
3822
|
+
MessageId: e.EventId,
|
|
3823
|
+
Role: "assistant",
|
|
3824
|
+
SeqId: e.SeqId,
|
|
3825
|
+
InvocationId: e.InvocationId,
|
|
3826
|
+
Timestamp: e.Timestamp,
|
|
3827
|
+
ToolEvents: [{
|
|
3828
|
+
Type: "approval",
|
|
3829
|
+
Name: n.tool_name || r.name || "approval",
|
|
3830
|
+
ApprovalRequestId: i,
|
|
3831
|
+
Protocol: e.Metadata?.protocol,
|
|
3832
|
+
Status: t.get(i) || "paused",
|
|
3833
|
+
Args: n.arguments ?? n.tool_args ?? n.args ?? r.args ?? r.arguments,
|
|
3834
|
+
ApprovalMessage: n.approval_message || n.message || r.description
|
|
3835
|
+
}]
|
|
3836
|
+
});
|
|
3837
|
+
});
|
|
3838
|
+
}
|
|
3839
|
+
function Hn(e) {
|
|
3840
|
+
let t = [];
|
|
3841
|
+
function n(e) {
|
|
3842
|
+
let r = Z(e), i = String(r.id || r.component_id || ""), a = String(r.component || r.type || "");
|
|
3843
|
+
if (!i || !a) return "";
|
|
3844
|
+
let o = Z(r.props), s = Array.isArray(r.children) ? r.children.map(n).filter(Boolean) : [];
|
|
3845
|
+
return t.push({
|
|
3846
|
+
id: i,
|
|
3847
|
+
component: a,
|
|
3848
|
+
...o,
|
|
3849
|
+
...s.length && !o.children && !o.child ? { children: s } : {}
|
|
3850
|
+
}), i;
|
|
3851
|
+
}
|
|
3852
|
+
return Array.isArray(e) && e.forEach(n), t;
|
|
3853
|
+
}
|
|
3854
|
+
function Un(e) {
|
|
3855
|
+
return Fn(e.flatMap((e) => {
|
|
3856
|
+
if (!e.EventType?.startsWith("a2ui.surface.")) return [];
|
|
3857
|
+
let t = Z(e.Content), n = Object.keys(Z(t.payload)).length ? Z(t.payload) : t, r = String(n.surfaceId || n.surface_id || "");
|
|
3858
|
+
if (!r) return [];
|
|
3859
|
+
let i = n.operations || n.a2ui_operations, a = n.surface ? Z(n.surface) : n, o = Hn(a.components), s = a.data_model ?? a.dataModel, c = Array.isArray(i) ? i : e.EventType === "a2ui.surface.end" ? [{
|
|
3860
|
+
version: "v0.9",
|
|
3861
|
+
deleteSurface: { surfaceId: r }
|
|
3862
|
+
}] : [
|
|
3863
|
+
...e.EventType === "a2ui.surface.begin" ? [{
|
|
3864
|
+
version: "v0.9",
|
|
3865
|
+
createSurface: {
|
|
3866
|
+
surfaceId: r,
|
|
3867
|
+
catalogId: a.catalog_id || a.catalogId || v.catalog_id
|
|
3868
|
+
}
|
|
3869
|
+
}] : [],
|
|
3870
|
+
...o.length ? [{
|
|
3871
|
+
version: "v0.9",
|
|
3872
|
+
updateComponents: {
|
|
3873
|
+
surfaceId: r,
|
|
3874
|
+
components: o
|
|
3875
|
+
}
|
|
3876
|
+
}] : [],
|
|
3877
|
+
...s === void 0 ? [] : [{
|
|
3878
|
+
version: "v0.9",
|
|
3879
|
+
updateDataModel: {
|
|
3880
|
+
surfaceId: r,
|
|
3881
|
+
path: "/",
|
|
3882
|
+
value: s
|
|
3883
|
+
}
|
|
3884
|
+
}]
|
|
3885
|
+
];
|
|
3886
|
+
return c.length ? [{
|
|
3887
|
+
MessageId: e.EventId,
|
|
3888
|
+
Role: "assistant",
|
|
3889
|
+
SeqId: e.SeqId,
|
|
3890
|
+
Timestamp: e.Timestamp,
|
|
3891
|
+
InvocationId: e.InvocationId,
|
|
3892
|
+
Activities: [{
|
|
3893
|
+
SurfaceId: r,
|
|
3894
|
+
Content: {
|
|
3895
|
+
a2ui_operations: c,
|
|
3896
|
+
interactionId: n.interactionId
|
|
3897
|
+
}
|
|
3898
|
+
}]
|
|
3899
|
+
}] : [];
|
|
3900
|
+
})).filter((e) => e.role === "a2ui");
|
|
3901
|
+
}
|
|
3902
|
+
function Q(e) {
|
|
3903
|
+
if (typeof e == "string") return e;
|
|
3904
|
+
if (Array.isArray(e)) return e.map(Q).join("");
|
|
3905
|
+
let t = Z(e), n = t.text ?? t.content ?? t.parts;
|
|
3906
|
+
return n === void 0 ? "" : Q(n);
|
|
3907
|
+
}
|
|
3908
|
+
var Wn = new Set([
|
|
3909
|
+
"user_message",
|
|
3910
|
+
"assistant_message",
|
|
3911
|
+
"assistant_stream_snapshot",
|
|
3912
|
+
"reasoning",
|
|
3913
|
+
"tool_call",
|
|
3914
|
+
"tool_result",
|
|
3915
|
+
"stage_tool_call",
|
|
3916
|
+
"stage_tool_result",
|
|
3917
|
+
"tool.call.begin",
|
|
3918
|
+
"tool.call.end",
|
|
3919
|
+
"approval_request",
|
|
3920
|
+
"approval_response",
|
|
3921
|
+
"reasoning.delta",
|
|
3922
|
+
"reasoning.completed",
|
|
3923
|
+
"context_checkpoint",
|
|
3924
|
+
"a2ui.surface.begin",
|
|
3925
|
+
"a2ui.surface.update",
|
|
3926
|
+
"a2ui.surface.end",
|
|
3927
|
+
"run_status",
|
|
3928
|
+
"run.started",
|
|
3929
|
+
"run.progress",
|
|
3930
|
+
"run.completed",
|
|
3931
|
+
"run.interrupted",
|
|
3932
|
+
"run.failed",
|
|
3933
|
+
"run.canceled"
|
|
3934
|
+
]);
|
|
3935
|
+
function Gn(e, t, n, r, i, a) {
|
|
3936
|
+
let o = async (i, a) => {
|
|
3937
|
+
let o = await zn(t, n, e.SeqId, r, i, a), s = Z(o.Content?.session_event), c = s.family === "workflow" && Z(Z(s.payload).legacy_history_event);
|
|
3938
|
+
return c && c.EventType ? {
|
|
3939
|
+
...c,
|
|
3940
|
+
SessionId: n,
|
|
3941
|
+
SeqId: e.SeqId
|
|
3942
|
+
} : {
|
|
3943
|
+
...e.Event,
|
|
3944
|
+
...o
|
|
3945
|
+
};
|
|
3946
|
+
}, s = JSON.stringify([
|
|
3947
|
+
n,
|
|
3948
|
+
r.HistoryEpoch,
|
|
3949
|
+
r.SnapshotSeqId,
|
|
3950
|
+
r.CursorSource,
|
|
3951
|
+
e.ItemId,
|
|
3952
|
+
e.SeqId
|
|
3953
|
+
]), c = {
|
|
3954
|
+
id: "history-body:" + s,
|
|
3955
|
+
timestamp: Number(e.Event.Timestamp) || 0,
|
|
3956
|
+
historyOrder: { seq: e.SeqId },
|
|
3957
|
+
invocationId: e.InvocationId || e.Event.InvocationId
|
|
3958
|
+
}, l = e.ToolRef;
|
|
3959
|
+
if (l?.CallId && (l.Kind === "call" || l.Kind === "result")) {
|
|
3960
|
+
let e = l.Kind === "result", t = async (t, r) => {
|
|
3961
|
+
let i = await o(t, r), a = Ie(i), s = a && new Pe(n).translate(a), c = L(s ? [{
|
|
3962
|
+
...s,
|
|
3963
|
+
Timestamp: i.Timestamp,
|
|
3964
|
+
SeqId: i.SeqId
|
|
3965
|
+
}] : Bn([i]), { preserveDistinctEvents: !0 }).flatMap((e) => Object.values(e.tools || {})).find((e) => e.callId === l.CallId), u = e ? c?.output : c?.args;
|
|
3966
|
+
if (u === void 0) throw Error("历史工具正文与调用标识不一致。");
|
|
3967
|
+
return u;
|
|
3968
|
+
}, r = l.ScopeId;
|
|
3969
|
+
if (e && l.ParentScopeId) {
|
|
3970
|
+
let e = a.filter((e) => (e.runId || e.invocationId) === c.invocationId && Object.values(e.tools || {}).some((e) => e.callId === l.CallId));
|
|
3971
|
+
!e.some((e) => e.scopeId === l.ScopeId) && e.filter((e) => e.scopeId === l.ParentScopeId).length === 1 && (r = l.ParentScopeId);
|
|
3972
|
+
}
|
|
3973
|
+
return {
|
|
3974
|
+
...c,
|
|
3975
|
+
role: "model",
|
|
3976
|
+
content: "",
|
|
3977
|
+
scopeId: r,
|
|
3978
|
+
eventType: e ? "tool_result" : "tool_call",
|
|
3979
|
+
tools: { [l.CallId]: {
|
|
3980
|
+
callId: l.CallId,
|
|
3981
|
+
name: l.Name || "tool",
|
|
3982
|
+
args: "",
|
|
3983
|
+
status: l.Status,
|
|
3984
|
+
...e ? { deferredOutput: {
|
|
3985
|
+
key: s,
|
|
3986
|
+
read: t
|
|
3987
|
+
} } : { deferredArgs: {
|
|
3988
|
+
key: s,
|
|
3989
|
+
read: t
|
|
3990
|
+
} }
|
|
3991
|
+
} }
|
|
3992
|
+
};
|
|
3993
|
+
}
|
|
3994
|
+
return {
|
|
3995
|
+
...c,
|
|
3996
|
+
role: "system",
|
|
3997
|
+
content: e.EventType,
|
|
3998
|
+
readHistoryContent: async (e, t) => {
|
|
3999
|
+
let r = await o(e, t);
|
|
4000
|
+
return je(L(Bn([r])), [r], n, i).messages.flatMap((e) => [
|
|
4001
|
+
e.content,
|
|
4002
|
+
e.reasoning,
|
|
4003
|
+
...Object.values(e.tools || {}).map((e) => JSON.stringify(e, null, 2))
|
|
4004
|
+
]).filter(Boolean).join("\n") || "此事件没有可展示的正文。";
|
|
4005
|
+
}
|
|
4006
|
+
};
|
|
4007
|
+
}
|
|
4008
|
+
function Kn(e, t, n, r, i, a) {
|
|
4009
|
+
let o = e.filter((e) => !e.ContentRef).map((e) => e.Event), s = new Set(e.filter((e) => {
|
|
4010
|
+
if (!e.InputCommandId || e.InboxInput) return !1;
|
|
4011
|
+
let t = Ie(e.Event), n = Z(Z(t?.source).metadata), r = Z(t?.snapshot).parts;
|
|
4012
|
+
return e.EventType === "user_message" || t?.event_type === "item.completed" && (n.native_item_kind === "userMessage" || Array.isArray(r) && r.some((e) => Z(Z(e).data).type === "userMessage"));
|
|
4013
|
+
}).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 ? [] : [{
|
|
4014
|
+
...e.Event,
|
|
4015
|
+
EventId: "inbox:" + e.InboxInput.CommandId,
|
|
4016
|
+
EventType: "user_message",
|
|
4017
|
+
Content: { parts: [{ text: e.InboxInput.Text }] }
|
|
4018
|
+
}]), u = Bn([...o, ...l].sort((e, t) => Number(e.SeqId) - Number(t.SeqId))), d = je([
|
|
4019
|
+
...L(u, { preserveDistinctEvents: !0 }),
|
|
4020
|
+
...Vn(u),
|
|
4021
|
+
...Un(u)
|
|
4022
|
+
], o, n, i, a), f = e.filter((e) => e.ContentRef).map((e) => Gn(e, t, n, r, i, d.messages));
|
|
4023
|
+
for (let e of c) {
|
|
4024
|
+
let i = e.InboxInput;
|
|
4025
|
+
i.ContentRef && f.push({
|
|
4026
|
+
id: "inbox:" + i.CommandId,
|
|
4027
|
+
role: "user",
|
|
4028
|
+
content: "用户输入",
|
|
4029
|
+
timestamp: Number(e.Event.Timestamp) || 0,
|
|
4030
|
+
historyOrder: { seq: e.SeqId },
|
|
4031
|
+
historyContentKey: JSON.stringify([
|
|
4032
|
+
n,
|
|
4033
|
+
r.HistoryEpoch,
|
|
4034
|
+
r.SnapshotSeqId,
|
|
4035
|
+
r.CursorSource,
|
|
4036
|
+
e.SeqId,
|
|
4037
|
+
"inbox"
|
|
4038
|
+
]),
|
|
4039
|
+
invocationId: e.InvocationId,
|
|
4040
|
+
readHistoryContent: async (i, a) => Q(await Ln(t, n, e.SeqId, r, i, a, "inbox"))
|
|
4041
|
+
});
|
|
4042
|
+
}
|
|
4043
|
+
let p = /* @__PURE__ */ new Map();
|
|
4044
|
+
for (let e of u) {
|
|
4045
|
+
if (!e.EventType || Wn.has(e.EventType) || e.Content?.session_event) continue;
|
|
4046
|
+
let t = e.InvocationId || "", n = p.get(t);
|
|
4047
|
+
n ? n.push(e) : p.set(t, [e]);
|
|
4048
|
+
}
|
|
4049
|
+
for (let [e, t] of p) f.push({
|
|
4050
|
+
id: "history-details:" + e,
|
|
4051
|
+
role: "system",
|
|
4052
|
+
content: `历史事件(${t.length})`,
|
|
4053
|
+
timestamp: Number(t[0].Timestamp) || 0,
|
|
4054
|
+
historyOrder: { seq: t[0].SeqId },
|
|
4055
|
+
invocationId: e,
|
|
4056
|
+
readHistoryContent: async () => t.map((e) => {
|
|
4057
|
+
let t = e.EventType === "progress" ? Q(e.Content?.parts) : "";
|
|
4058
|
+
return [
|
|
4059
|
+
e.SeqId,
|
|
4060
|
+
e.EventType,
|
|
4061
|
+
t
|
|
4062
|
+
].filter(Boolean).join(" ");
|
|
4063
|
+
}).join("\n")
|
|
4064
|
+
});
|
|
4065
|
+
return {
|
|
4066
|
+
...d,
|
|
4067
|
+
messages: f.length ? Be(be([...d.messages, ...f])) : d.messages
|
|
4068
|
+
};
|
|
4069
|
+
}
|
|
4070
|
+
function qn(e) {
|
|
4071
|
+
if (!e.InvocationId || e.InvocationId !== e.Event.InvocationId || e.ContentRef || e.InboxInput || e.InputCommandId || ![
|
|
4072
|
+
"assistant_stream_delta",
|
|
4073
|
+
"text.delta",
|
|
4074
|
+
"message.delta"
|
|
4075
|
+
].includes(e.Event.EventType || "") || Ie(e.Event) || e.Event.Content?.session_event) return;
|
|
4076
|
+
let t = e.Event.Content;
|
|
4077
|
+
return t?.parts?.map((e) => e.text || "").join("") || t?.text || t?.payload?.text || "";
|
|
4078
|
+
}
|
|
4079
|
+
var Jn = new Set([
|
|
4080
|
+
"user_message",
|
|
4081
|
+
"assistant_message",
|
|
4082
|
+
"tool_call",
|
|
4083
|
+
"tool_result"
|
|
4084
|
+
]);
|
|
4085
|
+
function Yn(e) {
|
|
4086
|
+
let t = e.Event;
|
|
4087
|
+
return Jn.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) => [
|
|
4088
|
+
"role",
|
|
4089
|
+
"parts",
|
|
4090
|
+
"text"
|
|
4091
|
+
].includes(e));
|
|
4092
|
+
}
|
|
4093
|
+
function Xn(e, t) {
|
|
4094
|
+
if (!t || t >= e.length || e[t - 1].SeqId >= e[t].SeqId) return e.length;
|
|
4095
|
+
let n = new Set(e.slice(0, t).map((e) => e.InvocationId)), r = t;
|
|
4096
|
+
for (; r < e.length && n.has(e[r].InvocationId);) r++;
|
|
4097
|
+
let i = new Set(e.slice(0, r).map((e) => e.Event.EventId.trim()));
|
|
4098
|
+
for (let t = r; t < e.length; t++) if (n.has(e[t].InvocationId) || i.has(e[t].Event.EventId.trim())) return e.length;
|
|
4099
|
+
return r;
|
|
4100
|
+
}
|
|
4101
|
+
function Zn(e, t, n, r, i, a) {
|
|
4102
|
+
let o = new Map(a?.progress), s = /* @__PURE__ */ new Map(), c = [], l = (e) => {
|
|
4103
|
+
let t = c.at(-1), n = qn(e), r = t && n !== void 0 && t.InvocationId === e.InvocationId ? qn(t) : void 0;
|
|
4104
|
+
r === void 0 ? c.push(e) : c[c.length - 1] = {
|
|
4105
|
+
...e,
|
|
4106
|
+
Event: {
|
|
4107
|
+
...e.Event,
|
|
4108
|
+
Content: { parts: [{ text: r + n }] }
|
|
4109
|
+
}
|
|
4110
|
+
};
|
|
4111
|
+
};
|
|
4112
|
+
for (let t of e) if (t.Event.EventType === "progress" && !t.ContentRef && !t.InboxInput && !t.InputCommandId && !t.Event.Content?.session_event && !Ie(t.Event)) {
|
|
4113
|
+
let e = t.InvocationId || "", n = s.get(e) || [];
|
|
4114
|
+
n.push(t.Event), s.set(e, n);
|
|
4115
|
+
} else l(t);
|
|
4116
|
+
for (let [e, t] of s) {
|
|
4117
|
+
let n = o.get(e);
|
|
4118
|
+
o.set(e, {
|
|
4119
|
+
events: t,
|
|
4120
|
+
count: t.length + (n?.count || 0),
|
|
4121
|
+
newer: n
|
|
4122
|
+
});
|
|
4123
|
+
}
|
|
4124
|
+
let u = (a?.hasOnlyPlainChatItems ?? !0) && c.every((e, t) => Yn(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;
|
|
4125
|
+
if (c.length || !m || h === 1 && a?.firstSeq !== 1) {
|
|
4126
|
+
f.length && l(f[0]), p = c.concat(f.slice(1));
|
|
4127
|
+
let e = u && a ? Xn(p, d) : p.length;
|
|
4128
|
+
if (a && e < p.length) {
|
|
4129
|
+
let o = Kn(p.slice(0, e), t, n, r, i, h), s = p[e].SeqId, c = a.semantic.messages.filter((e) => e.historyOrder.seq >= s);
|
|
4130
|
+
m = {
|
|
4131
|
+
...o,
|
|
4132
|
+
messages: o.messages.concat(c)
|
|
4133
|
+
};
|
|
4134
|
+
} else m = Kn(p, t, n, r, i, h);
|
|
4135
|
+
}
|
|
4136
|
+
let g = [];
|
|
4137
|
+
for (let [e, t] of o) {
|
|
4138
|
+
let n = t.events[0];
|
|
4139
|
+
g.push({
|
|
4140
|
+
id: "history-progress:" + e,
|
|
4141
|
+
role: "system",
|
|
4142
|
+
content: `历史事件(${t.count})`,
|
|
4143
|
+
timestamp: Number(n.Timestamp) || 0,
|
|
4144
|
+
historyOrder: { seq: n.SeqId },
|
|
4145
|
+
invocationId: e,
|
|
4146
|
+
readHistoryContent: async () => {
|
|
4147
|
+
let e = [];
|
|
4148
|
+
for (let n = t; n; n = n.newer) for (let t of n.events) {
|
|
4149
|
+
let n = Q(t.Content?.parts) || Q(t.Content) || Q(t.Content?.payload);
|
|
4150
|
+
e.push([
|
|
4151
|
+
t.SeqId,
|
|
4152
|
+
t.EventType,
|
|
4153
|
+
n
|
|
4154
|
+
].filter(Boolean).join(" "));
|
|
4155
|
+
}
|
|
4156
|
+
return e.join("\n");
|
|
4157
|
+
}
|
|
4158
|
+
});
|
|
4159
|
+
}
|
|
4160
|
+
return {
|
|
4161
|
+
firstSeq: h,
|
|
4162
|
+
semantic: m,
|
|
4163
|
+
progress: o,
|
|
4164
|
+
semanticItems: p,
|
|
4165
|
+
hasOnlyPlainChatItems: u,
|
|
4166
|
+
canonicalRunIds: m.canonicalRunIds,
|
|
4167
|
+
messages: g.length ? be([...m.messages, ...g]) : m.messages
|
|
4168
|
+
};
|
|
4169
|
+
}
|
|
4170
|
+
async function Qn(e, t, n, r, i, a) {
|
|
4171
|
+
let o, s = n, c;
|
|
4172
|
+
do {
|
|
4173
|
+
i.throwIfAborted();
|
|
4174
|
+
let l = await e.listSessionMessages(t, {
|
|
4175
|
+
historyView: "items-v1",
|
|
4176
|
+
...o ? { itemCursor: o } : { afterSeqId: n },
|
|
4177
|
+
historyEpoch: r,
|
|
4178
|
+
snapshotSeqId: c,
|
|
4179
|
+
signal: i,
|
|
4180
|
+
limit: 100
|
|
4181
|
+
});
|
|
4182
|
+
if (l.HistoryEpoch !== r || c !== void 0 && l.SnapshotSeqId !== c) throw Error("接续历史来源已变化。");
|
|
4183
|
+
c = l.SnapshotSeqId;
|
|
4184
|
+
for (let n of Rn(l, t, o)) {
|
|
4185
|
+
if (n.SeqId <= s) throw Error("接续历史条目未前进。");
|
|
4186
|
+
let r = n.ContentRef ? {
|
|
4187
|
+
...n.Event,
|
|
4188
|
+
...await zn(e, t, n.SeqId, l, i)
|
|
4189
|
+
} : n.Event;
|
|
4190
|
+
i.throwIfAborted(), a(r), s = n.SeqId;
|
|
4191
|
+
}
|
|
4192
|
+
o = l.NextItemCursor || void 0;
|
|
4193
|
+
} while (o);
|
|
4194
|
+
return s;
|
|
3556
4195
|
}
|
|
3557
4196
|
//#endregion
|
|
3558
4197
|
//#region src/utils/session-event-history.ts
|
|
3559
|
-
async function
|
|
4198
|
+
async function $n(e, t, n, r, i) {
|
|
3560
4199
|
if (n.CursorSource !== "runtime") return;
|
|
3561
4200
|
let a = r?.events.filter((e) => e.EventType === "run_status").sort((e, t) => Number(t.SeqId) - Number(e.SeqId))[0];
|
|
3562
|
-
if (a || r && r.loadedCount >= r.total) return a;
|
|
3563
|
-
let o = await e.listSessionEvents(t, {
|
|
4201
|
+
if (a || r && !r.hasMore && r.loadedCount >= r.total) return a;
|
|
4202
|
+
let o = n.HistoryEpochSource === "server-event-anchor", s = await e.listSessionEvents(t, {
|
|
3564
4203
|
eventTypes: ["run_status"],
|
|
3565
4204
|
limit: 1,
|
|
3566
4205
|
cursorSource: n.CursorSource,
|
|
3567
|
-
|
|
3568
|
-
|
|
4206
|
+
...o ? { beforeSeqId: (n.SnapshotSeqId ?? 0) + 1 } : {
|
|
4207
|
+
historyEpoch: n.HistoryEpoch,
|
|
4208
|
+
snapshotSeqId: n.SnapshotSeqId
|
|
4209
|
+
},
|
|
3569
4210
|
signal: i
|
|
3570
4211
|
});
|
|
3571
|
-
if (o
|
|
4212
|
+
if (o) {
|
|
4213
|
+
let r = s.Events[0]?.SeqId;
|
|
4214
|
+
if (s.CursorSource !== "runtime" || !r || !n.SnapshotSeqId || r > n.SnapshotSeqId) return;
|
|
4215
|
+
let a = await e.listSessionMessages(t, {
|
|
4216
|
+
historyView: "items-v1",
|
|
4217
|
+
afterSeqId: r - 1,
|
|
4218
|
+
historyEpoch: n.HistoryEpoch,
|
|
4219
|
+
snapshotSeqId: n.SnapshotSeqId,
|
|
4220
|
+
limit: 1,
|
|
4221
|
+
signal: i
|
|
4222
|
+
}), o = a.Items?.[0]?.Event;
|
|
4223
|
+
return a.HistoryView === "items-v1" && a.CursorSource === n.CursorSource && a.HistoryEpoch === n.HistoryEpoch && a.SnapshotSeqId === n.SnapshotSeqId && o?.SessionId === t && o.SeqId === r && o.EventType === "run_status" ? o : void 0;
|
|
4224
|
+
}
|
|
4225
|
+
if (s.CursorSource === n.CursorSource && s.HistoryEpoch === n.HistoryEpoch && s.SnapshotSeqId === n.SnapshotSeqId) return s.Events[0];
|
|
3572
4226
|
}
|
|
3573
|
-
var
|
|
4227
|
+
var er = class extends Error {
|
|
3574
4228
|
seq;
|
|
3575
4229
|
constructor(e) {
|
|
3576
4230
|
super(`Session event seq ${e} was received twice with conflicting content`), this.name = "SessionEventConflictError", this.seq = e;
|
|
3577
4231
|
}
|
|
3578
4232
|
};
|
|
3579
|
-
function
|
|
3580
|
-
return Array.isArray(e) ? `[${e.map(
|
|
4233
|
+
function tr(e) {
|
|
4234
|
+
return Array.isArray(e) ? `[${e.map(tr).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)}:${tr(t)}`).join(",")}}` : JSON.stringify(e) ?? "null";
|
|
3581
4235
|
}
|
|
3582
|
-
var
|
|
4236
|
+
var nr = new Set(["runtime"]), rr = class {
|
|
3583
4237
|
eventsBySeq = /* @__PURE__ */ new Map();
|
|
3584
4238
|
lastSeqValue = 0;
|
|
3585
4239
|
accept(e) {
|
|
3586
|
-
let t =
|
|
4240
|
+
let t = u(e);
|
|
3587
4241
|
if (!t.ok) throw t.error;
|
|
3588
4242
|
let n = t.value, r = this.eventsBySeq.get(n.seq);
|
|
3589
4243
|
if (r) {
|
|
3590
|
-
if (
|
|
4244
|
+
if (tr(r) !== tr(n)) throw new er(n.seq);
|
|
3591
4245
|
return;
|
|
3592
4246
|
}
|
|
3593
4247
|
this.eventsBySeq.set(n.seq, n), this.lastSeqValue = Math.max(this.lastSeqValue, n.seq);
|
|
@@ -3599,84 +4253,88 @@ var An = new Set(["runtime"]), jn = class {
|
|
|
3599
4253
|
return this.lastSeqValue;
|
|
3600
4254
|
}
|
|
3601
4255
|
displayableEvents() {
|
|
3602
|
-
return [...this.eventsBySeq.values()].filter((e) =>
|
|
4256
|
+
return [...this.eventsBySeq.values()].filter((e) => nr.has(e.family)).sort((e, t) => e.seq - t.seq);
|
|
3603
4257
|
}
|
|
3604
4258
|
};
|
|
3605
|
-
function
|
|
3606
|
-
return new
|
|
4259
|
+
function ir() {
|
|
4260
|
+
return new rr();
|
|
3607
4261
|
}
|
|
3608
4262
|
//#endregion
|
|
3609
4263
|
//#region src/hooks/useSessionLifecycle.ts
|
|
3610
|
-
var
|
|
3611
|
-
function
|
|
4264
|
+
var ar = 500, or = 30, sr = 50, cr = 64, lr = 8, ur = 128, dr = 1800 * 1e3;
|
|
4265
|
+
function fr(e, t) {
|
|
3612
4266
|
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));
|
|
3613
4267
|
}
|
|
3614
|
-
function
|
|
4268
|
+
function pr(e) {
|
|
3615
4269
|
return {
|
|
3616
4270
|
CursorSource: e.cursorSource,
|
|
3617
4271
|
HistoryEpoch: e.historyEpoch,
|
|
3618
4272
|
SnapshotSeqId: e.snapshotSeqId
|
|
3619
4273
|
};
|
|
3620
4274
|
}
|
|
3621
|
-
function
|
|
4275
|
+
function mr(e) {
|
|
3622
4276
|
if (!(e instanceof Y) || !e.detail || typeof e.detail != "object") return;
|
|
3623
4277
|
let t = e.detail;
|
|
3624
4278
|
return typeof t.ReasonCode == "string" ? t.ReasonCode : void 0;
|
|
3625
4279
|
}
|
|
3626
|
-
function
|
|
3627
|
-
return e instanceof Y && e.code === 409 &&
|
|
4280
|
+
function hr(e) {
|
|
4281
|
+
return e instanceof Y && e.code === 409 && mr(e) === "HISTORY_RELOAD_REQUIRED";
|
|
3628
4282
|
}
|
|
3629
|
-
function
|
|
4283
|
+
function gr() {
|
|
3630
4284
|
return new Y(409, "历史来源已变化", {
|
|
3631
4285
|
Code: 409,
|
|
3632
4286
|
ReasonCode: "HISTORY_RELOAD_REQUIRED",
|
|
3633
4287
|
Data: null
|
|
3634
4288
|
});
|
|
3635
4289
|
}
|
|
3636
|
-
function
|
|
4290
|
+
function _r(e) {
|
|
3637
4291
|
return {
|
|
4292
|
+
historyView: e.HistoryView,
|
|
4293
|
+
nextItemCursor: e.NextItemCursor,
|
|
4294
|
+
retryOlderPage: !1,
|
|
3638
4295
|
dataSource: e.DataSource,
|
|
3639
4296
|
degraded: e.Degraded,
|
|
3640
4297
|
cursorSource: e.CursorSource,
|
|
3641
4298
|
cursorCompatibleWithRuntime: e.CursorCompatibleWithRuntime,
|
|
3642
4299
|
sessionContractVersion: e.SessionContractVersion,
|
|
3643
4300
|
historyEpoch: e.HistoryEpoch,
|
|
4301
|
+
historyEpochSource: e.HistoryEpochSource,
|
|
3644
4302
|
persistenceDegraded: e.PersistenceDegraded,
|
|
3645
4303
|
snapshotSeqId: e.SnapshotSeqId,
|
|
3646
4304
|
error: void 0,
|
|
3647
4305
|
preparing: !1
|
|
3648
4306
|
};
|
|
3649
4307
|
}
|
|
3650
|
-
function $(e, t, n, r, i =
|
|
4308
|
+
function $(e, t, n, r, i = ur) {
|
|
3651
4309
|
for (e.delete(t), e.set(t, n); e.size > i;) {
|
|
3652
4310
|
let t = [...e.keys()].find((e) => e !== r);
|
|
3653
4311
|
if (!t) break;
|
|
3654
4312
|
e.delete(t);
|
|
3655
4313
|
}
|
|
3656
4314
|
}
|
|
3657
|
-
function
|
|
4315
|
+
function vr(e) {
|
|
3658
4316
|
return new Promise((t) => {
|
|
3659
4317
|
if (e.aborted) {
|
|
3660
4318
|
t();
|
|
3661
4319
|
return;
|
|
3662
4320
|
}
|
|
3663
|
-
let n = globalThis.setTimeout(t,
|
|
4321
|
+
let n = globalThis.setTimeout(t, ar);
|
|
3664
4322
|
e.addEventListener("abort", () => {
|
|
3665
4323
|
globalThis.clearTimeout(n), t();
|
|
3666
4324
|
}, { once: !0 });
|
|
3667
4325
|
});
|
|
3668
4326
|
}
|
|
3669
|
-
var
|
|
4327
|
+
var yr = new Set([
|
|
3670
4328
|
"in_progress",
|
|
3671
4329
|
"running",
|
|
3672
4330
|
"resuming",
|
|
3673
4331
|
"starting"
|
|
3674
4332
|
]);
|
|
3675
|
-
function
|
|
4333
|
+
function br(e) {
|
|
3676
4334
|
let t = e.ActiveRunUpdatedAt || e.UpdatedAt, n = typeof t == "number" ? t > 1e11 ? t : t * 1e3 : Date.parse(String(t || ""));
|
|
3677
|
-
return Number.isFinite(n) && n <= Date.now() +
|
|
4335
|
+
return Number.isFinite(n) && n <= Date.now() + dr && Date.now() - n <= dr;
|
|
3678
4336
|
}
|
|
3679
|
-
function
|
|
4337
|
+
function xr(e) {
|
|
3680
4338
|
let t = R(e);
|
|
3681
4339
|
return t ? t === "completed" ? {
|
|
3682
4340
|
status: "completed",
|
|
@@ -3695,11 +4353,11 @@ function Yn(e) {
|
|
|
3695
4353
|
phase: "后台长任务恢复失败"
|
|
3696
4354
|
} : null : null;
|
|
3697
4355
|
}
|
|
3698
|
-
function
|
|
3699
|
-
let { agentId: r, api: i, isMobile: a, resetCompaction: o, uiCapabilities: l, disconnectRun:
|
|
3700
|
-
|
|
3701
|
-
let
|
|
3702
|
-
let r = n.filter((e) =>
|
|
4356
|
+
function Sr(e) {
|
|
4357
|
+
let { agentId: r, api: i, isMobile: a, resetCompaction: o, uiCapabilities: l, disconnectRun: u, restoreSession: d = !0 } = e, f = J(e.currentSessionId), p = J(e.agentId), h = J(l);
|
|
4358
|
+
h.current = l;
|
|
4359
|
+
let _ = J(null), v = J(0), y = J(null), b = J(null), S = J(/* @__PURE__ */ new Map()), C = J(/* @__PURE__ */ new Map()), w = J(/* @__PURE__ */ new Map()), E = J(/* @__PURE__ */ new Map()), D = J(/* @__PURE__ */ new Map()), O = J(/* @__PURE__ */ new Map()), te = J(/* @__PURE__ */ new Map()), k = J(/* @__PURE__ */ new Map()), A = J(/* @__PURE__ */ new Map()), M = J(null), N = J(null), P = J(null), I = J(null), L = J(null), re = K(async (e, t, n) => {
|
|
4360
|
+
let r = n.filter((e) => ie(e, !1, !1));
|
|
3703
4361
|
if (!r.length) return;
|
|
3704
4362
|
let a = await Promise.all(r.map(async (n) => {
|
|
3705
4363
|
try {
|
|
@@ -3708,7 +4366,7 @@ function Xn(e) {
|
|
|
3708
4366
|
SessionId: t,
|
|
3709
4367
|
ResponseId: n.responseId,
|
|
3710
4368
|
EventId: n.eventId
|
|
3711
|
-
}), a = r?.Feedback ?
|
|
4369
|
+
}), a = r?.Feedback ? se(r.Feedback) : null;
|
|
3712
4370
|
return a ? {
|
|
3713
4371
|
messageId: n.id,
|
|
3714
4372
|
feedback: a
|
|
@@ -3717,19 +4375,61 @@ function Xn(e) {
|
|
|
3717
4375
|
return console.error("Failed to load response feedback:", e), null;
|
|
3718
4376
|
}
|
|
3719
4377
|
}));
|
|
3720
|
-
if (
|
|
4378
|
+
if (f.current !== t) return;
|
|
3721
4379
|
let o = new Map(a.filter((e) => !!e).map((e) => [e.messageId, e.feedback]));
|
|
3722
4380
|
o.size && H.getState().patchMessages((e) => e.map((e) => o.has(e.id) ? {
|
|
3723
4381
|
...e,
|
|
3724
4382
|
feedback: o.get(e.id)
|
|
3725
4383
|
} : e));
|
|
3726
|
-
}, [i]),
|
|
3727
|
-
|
|
4384
|
+
}, [i]), z = K(async (e) => {
|
|
4385
|
+
_.current?.abort();
|
|
3728
4386
|
let t = new AbortController();
|
|
3729
|
-
|
|
3730
|
-
let n = !1, r = !1, a = !1, o = c.getState(),
|
|
4387
|
+
_.current = t;
|
|
4388
|
+
let n = !1, r = !1, a = !1, o = c.getState(), l = o.agentId === p.current ? o.capabilities : h.current, u = l.KernelSessionEventsByCommand === !0, d = de(l.ConversationSurface, Se), g = new ge(e.sessionId, void 0, d), v = u ? 0 : e.afterSeqId, y = () => _.current === t && f.current === e.sessionId, b = ir(), x = !1, S = (t) => {
|
|
4389
|
+
if (t.InvocationId && t.InvocationId !== e.invocationId) return;
|
|
4390
|
+
let i = t.seq;
|
|
4391
|
+
typeof i == "number" && b.accept(t);
|
|
4392
|
+
let a = typeof i == "number" ? i : Number(t.SeqId || 0);
|
|
4393
|
+
if (a > 0 && a <= v) return;
|
|
4394
|
+
m.getState().updateActivity({
|
|
4395
|
+
sessionId: e.sessionId,
|
|
4396
|
+
status: "running",
|
|
4397
|
+
phase: "正在处理",
|
|
4398
|
+
countEvent: !1
|
|
4399
|
+
});
|
|
4400
|
+
let o = t.Content?.runtime_event;
|
|
4401
|
+
if (u && o?.schema_version === 2 && o.run_id === e.invocationId && g.apply(o)) {
|
|
4402
|
+
let t = g.snapshot();
|
|
4403
|
+
pn({
|
|
4404
|
+
type: "conversation_snapshot",
|
|
4405
|
+
sessionId: e.sessionId,
|
|
4406
|
+
result: {
|
|
4407
|
+
state: t,
|
|
4408
|
+
presentation: he(t, { profile: d }),
|
|
4409
|
+
runId: e.invocationId,
|
|
4410
|
+
cursor: a || v
|
|
4411
|
+
}
|
|
4412
|
+
});
|
|
4413
|
+
}
|
|
4414
|
+
if (pn({
|
|
4415
|
+
type: "stream_event",
|
|
4416
|
+
sessionId: e.sessionId,
|
|
4417
|
+
event: t
|
|
4418
|
+
}), ne(t)) {
|
|
4419
|
+
r = !0, n = !0;
|
|
4420
|
+
let i = xr(t);
|
|
4421
|
+
i && m.getState().updateActivity({
|
|
4422
|
+
sessionId: e.sessionId,
|
|
4423
|
+
status: i.status,
|
|
4424
|
+
phase: i.phase,
|
|
4425
|
+
detail: e.invocationId,
|
|
4426
|
+
countEvent: !1
|
|
4427
|
+
});
|
|
4428
|
+
}
|
|
4429
|
+
a > 0 && (v = a);
|
|
4430
|
+
};
|
|
3731
4431
|
try {
|
|
3732
|
-
for (
|
|
4432
|
+
for (m.getState().setCurrentRunId(e.invocationId), m.getState().setActiveInvocationId(e.invocationId), m.getState().setSessionStreaming(e.sessionId, !0), m.getState().updateActivity({
|
|
3733
4433
|
sessionId: e.sessionId,
|
|
3734
4434
|
runId: e.invocationId,
|
|
3735
4435
|
source: "restore",
|
|
@@ -3737,28 +4437,33 @@ function Xn(e) {
|
|
|
3737
4437
|
phase: "正在同步任务进展",
|
|
3738
4438
|
detail: e.invocationId,
|
|
3739
4439
|
countEvent: !1
|
|
3740
|
-
}); !r &&
|
|
4440
|
+
}); !r && y();) {
|
|
3741
4441
|
try {
|
|
3742
|
-
let a =
|
|
4442
|
+
let a = s.getState().messageHistory[e.sessionId];
|
|
4443
|
+
if (x && a?.historyView === "items-v1" && a.historyEpoch && (v = await Qn(i, e.sessionId, v, a.historyEpoch, t.signal, (e) => {
|
|
4444
|
+
y() && S(e);
|
|
4445
|
+
}), r || !y())) break;
|
|
4446
|
+
x = !0;
|
|
4447
|
+
let o = await i.subscribeRunEvents({
|
|
3743
4448
|
sessionId: e.sessionId,
|
|
3744
4449
|
invocationId: e.invocationId,
|
|
3745
|
-
afterSeqId:
|
|
4450
|
+
afterSeqId: v
|
|
3746
4451
|
}, { signal: t.signal });
|
|
3747
|
-
if (!
|
|
4452
|
+
if (!y()) {
|
|
3748
4453
|
t.abort();
|
|
3749
4454
|
return;
|
|
3750
4455
|
}
|
|
3751
|
-
let
|
|
3752
|
-
for (; !r &&
|
|
3753
|
-
let { value: t, done: i } = await
|
|
4456
|
+
let c = o.getReader(), l = new TextDecoder(), u = "";
|
|
4457
|
+
for (; !r && y();) {
|
|
4458
|
+
let { value: t, done: i } = await c.read();
|
|
3754
4459
|
if (i) break;
|
|
3755
|
-
|
|
3756
|
-
let a =
|
|
3757
|
-
|
|
4460
|
+
u += l.decode(t, { stream: !0 });
|
|
4461
|
+
let a = Mt(u);
|
|
4462
|
+
u = a.remainder;
|
|
3758
4463
|
for (let t of a.chunks) if (t.trim()) {
|
|
3759
|
-
for (let i of
|
|
4464
|
+
for (let i of jt(t)) {
|
|
3760
4465
|
if (i.eventName === "__ping__") {
|
|
3761
|
-
|
|
4466
|
+
m.getState().updateActivity({
|
|
3762
4467
|
sessionId: e.sessionId,
|
|
3763
4468
|
status: "running",
|
|
3764
4469
|
phase: "正在处理",
|
|
@@ -3772,83 +4477,27 @@ function Xn(e) {
|
|
|
3772
4477
|
}
|
|
3773
4478
|
if (!i.data || typeof i.data != "object") continue;
|
|
3774
4479
|
let t = i.data;
|
|
3775
|
-
if (!
|
|
3776
|
-
if (t.InvocationId && t.InvocationId !== e.invocationId) continue;
|
|
3777
|
-
if (g.getState().updateActivity({
|
|
3778
|
-
sessionId: e.sessionId,
|
|
3779
|
-
status: "running",
|
|
3780
|
-
phase: "正在处理",
|
|
3781
|
-
countEvent: !1
|
|
3782
|
-
}), typeof t.seq == "number") {
|
|
3783
|
-
try {
|
|
3784
|
-
y.current.accept(t);
|
|
3785
|
-
} catch (e) {
|
|
3786
|
-
console.error("[SessionLifecycle] session event cursor conflict:", e);
|
|
3787
|
-
}
|
|
3788
|
-
f = Math.max(f, y.current.reconnectAfterSeq()), rn({
|
|
3789
|
-
type: "stream_event",
|
|
3790
|
-
sessionId: e.sessionId,
|
|
3791
|
-
event: t
|
|
3792
|
-
}), r ||= N(t), n ||= r;
|
|
3793
|
-
let i = Yn(t);
|
|
3794
|
-
i && g.getState().updateActivity({
|
|
3795
|
-
sessionId: e.sessionId,
|
|
3796
|
-
status: i.status,
|
|
3797
|
-
phase: i.phase,
|
|
3798
|
-
detail: e.invocationId,
|
|
3799
|
-
countEvent: !1
|
|
3800
|
-
});
|
|
3801
|
-
continue;
|
|
3802
|
-
}
|
|
3803
|
-
let a = Number(t.SeqId || 0);
|
|
3804
|
-
Number.isFinite(a) && (f = Math.max(f, a));
|
|
3805
|
-
let o = t.Content?.runtime_event;
|
|
3806
|
-
if (l && o?.schema_version === 2 && o.run_id === e.invocationId && d.apply(o)) {
|
|
3807
|
-
let t = d.snapshot();
|
|
3808
|
-
rn({
|
|
3809
|
-
type: "conversation_snapshot",
|
|
3810
|
-
sessionId: e.sessionId,
|
|
3811
|
-
result: {
|
|
3812
|
-
state: t,
|
|
3813
|
-
presentation: Ie(t, { profile: u }),
|
|
3814
|
-
runId: e.invocationId,
|
|
3815
|
-
cursor: f
|
|
3816
|
-
}
|
|
3817
|
-
});
|
|
3818
|
-
}
|
|
3819
|
-
rn({
|
|
3820
|
-
type: "stream_event",
|
|
3821
|
-
sessionId: e.sessionId,
|
|
3822
|
-
event: t
|
|
3823
|
-
}), r ||= N(t), n ||= r;
|
|
3824
|
-
let s = Yn(t);
|
|
3825
|
-
if (s && g.getState().updateActivity({
|
|
3826
|
-
sessionId: e.sessionId,
|
|
3827
|
-
status: s.status,
|
|
3828
|
-
phase: s.phase,
|
|
3829
|
-
detail: e.invocationId,
|
|
3830
|
-
countEvent: !1
|
|
3831
|
-
}), r) break;
|
|
4480
|
+
if (!y() || (S(t), r)) break;
|
|
3832
4481
|
}
|
|
3833
4482
|
if (r) break;
|
|
3834
4483
|
}
|
|
3835
4484
|
}
|
|
3836
|
-
r &&
|
|
4485
|
+
r && c.cancel().catch(() => {});
|
|
3837
4486
|
} catch (i) {
|
|
3838
4487
|
if (i instanceof DOMException && i.name === "AbortError" || i instanceof X || t.signal.aborted) {
|
|
3839
|
-
r = !0, a = !0,
|
|
4488
|
+
r = !0, a = !0, y() && m.getState().stopSessionActivity(e.sessionId, "恢复事件订阅已取消。");
|
|
3840
4489
|
break;
|
|
3841
4490
|
}
|
|
3842
|
-
if (!
|
|
4491
|
+
if (!y()) break;
|
|
3843
4492
|
if (i instanceof Y && i.code >= 400 && i.code < 500 && i.code !== 408 && i.code !== 429) {
|
|
3844
|
-
r = !0, n =
|
|
4493
|
+
r = !0, n = hr(i), pn({
|
|
3845
4494
|
type: "error",
|
|
3846
4495
|
sessionId: e.sessionId,
|
|
3847
4496
|
error: i
|
|
3848
4497
|
});
|
|
3849
4498
|
break;
|
|
3850
4499
|
}
|
|
3851
|
-
console.warn("Run event subscription disconnected; retrying:", i),
|
|
4500
|
+
console.warn("Run event subscription disconnected; retrying:", i), m.getState().updateActivity({
|
|
3852
4501
|
sessionId: e.sessionId,
|
|
3853
4502
|
status: "waiting",
|
|
3854
4503
|
phase: "恢复连接中",
|
|
@@ -3856,20 +4505,20 @@ function Xn(e) {
|
|
|
3856
4505
|
countEvent: !1
|
|
3857
4506
|
});
|
|
3858
4507
|
}
|
|
3859
|
-
!r &&
|
|
4508
|
+
!r && y() && await vr(t.signal);
|
|
3860
4509
|
}
|
|
3861
|
-
r && !a &&
|
|
4510
|
+
r && !a && y() && pn({
|
|
3862
4511
|
type: "stream_ended",
|
|
3863
4512
|
sessionId: e.sessionId
|
|
3864
4513
|
});
|
|
3865
4514
|
} catch (e) {
|
|
3866
4515
|
e instanceof DOMException && e.name === "AbortError" || console.error("Failed to subscribe run events:", e);
|
|
3867
4516
|
} finally {
|
|
3868
|
-
let r =
|
|
3869
|
-
r && (
|
|
4517
|
+
let r = _.current === t;
|
|
4518
|
+
r && (_.current = null), r && f.current === e.sessionId && (m.getState().setCurrentRunId(""), m.getState().setActiveInvocationId(""), n && I.current?.(e.sessionId), L.current?.(p.current, e.sessionId));
|
|
3870
4519
|
}
|
|
3871
4520
|
}, [i]), B = K((e) => {
|
|
3872
|
-
if (!
|
|
4521
|
+
if (!h.current.RunLifecycle.Enabled || !e.runId || p.current !== r || f.current !== e.sessionId || _.current || (k.current.get(e.sessionId)?.events || []).some((t) => {
|
|
3873
4522
|
let n = t.Content?.runtime_event;
|
|
3874
4523
|
return t.InvocationId === e.runId && !n?.parent_scope_id && [
|
|
3875
4524
|
"completed",
|
|
@@ -3880,46 +4529,47 @@ function Xn(e) {
|
|
|
3880
4529
|
"aborted"
|
|
3881
4530
|
].includes(R(t));
|
|
3882
4531
|
})) return;
|
|
3883
|
-
let t =
|
|
3884
|
-
|
|
4532
|
+
let t = m.getState().getSessionActivity(e.sessionId);
|
|
4533
|
+
m.getState().isSessionStreaming(e.sessionId) && t?.source === "run" && [
|
|
3885
4534
|
"connecting",
|
|
3886
4535
|
"running",
|
|
3887
4536
|
"waiting"
|
|
3888
|
-
].includes(t.status) && (e.extensions?.mcpAuthorization ||
|
|
4537
|
+
].includes(t.status) && (e.extensions?.mcpAuthorization || h.current.KernelSessionEventsByCommand === !0 && t.runId === e.runId) || z({
|
|
3889
4538
|
sessionId: e.sessionId,
|
|
3890
4539
|
invocationId: e.runId,
|
|
3891
|
-
afterSeqId:
|
|
4540
|
+
afterSeqId: j(k.current.get(e.sessionId)?.events || [])
|
|
3892
4541
|
});
|
|
3893
|
-
}, [r,
|
|
4542
|
+
}, [r, z]), V = K(async (e, r = !1, u, d) => {
|
|
3894
4543
|
if (u?.aborted) return;
|
|
3895
4544
|
P.current = null;
|
|
3896
|
-
let
|
|
3897
|
-
|
|
3898
|
-
let
|
|
3899
|
-
|
|
3900
|
-
let
|
|
3901
|
-
$(D.current, e, t,
|
|
3902
|
-
},
|
|
3903
|
-
|
|
3904
|
-
let
|
|
3905
|
-
s.getState().setCurrentSessionId(e), s.getState().setSessionInitialMessageHistoryLoading(e, !
|
|
3906
|
-
let
|
|
3907
|
-
|
|
4545
|
+
let S = c.getState(), T = S.agentId === p.current ? S.capabilities : h.current, A = de(T.ConversationSurface, Se);
|
|
4546
|
+
O.current.set(e, A);
|
|
4547
|
+
let M = f.current, N = ++v.current;
|
|
4548
|
+
y.current = N, b.current = null;
|
|
4549
|
+
let F = (e, t) => {
|
|
4550
|
+
$(D.current, e, t, f.current, lr);
|
|
4551
|
+
}, L = D.current.get(e), B = E.current.get(e);
|
|
4552
|
+
M && M !== e && (F(M, H.getState().messages), H.getState().setMessages(L || []), s.getState().clearSessionMessageHistory(e), W.getState().setSessionCheckpoints(e, []), W.getState().setSessionToolReceipts(e, []), m.getState().setCurrentRunId(""), m.getState().clearActivity()), f.current = e;
|
|
4553
|
+
let V = () => f.current === e && v.current === N && !u?.aborted;
|
|
4554
|
+
s.getState().setCurrentSessionId(e), s.getState().setSessionInitialMessageHistoryLoading(e, !L);
|
|
4555
|
+
let ie = m.getState();
|
|
4556
|
+
ie.isSessionStreaming(e) && ie.updateActivity({
|
|
3908
4557
|
sessionId: e,
|
|
3909
4558
|
phase: "正在同步任务进展",
|
|
3910
4559
|
countEvent: !1
|
|
3911
4560
|
}), o();
|
|
3912
|
-
let
|
|
3913
|
-
|
|
4561
|
+
let ae = H.getState().messages;
|
|
4562
|
+
_.current?.abort(), a && g.getState().setMobileSidebarOpen(!1);
|
|
3914
4563
|
try {
|
|
3915
4564
|
let r = {
|
|
3916
|
-
|
|
4565
|
+
historyView: "items-v1",
|
|
4566
|
+
limit: sr,
|
|
3917
4567
|
includeReasoning: !0,
|
|
3918
4568
|
includeToolEvents: !0,
|
|
3919
4569
|
includeAttachments: !0,
|
|
3920
4570
|
signal: u
|
|
3921
|
-
}, a = await
|
|
3922
|
-
isCurrent:
|
|
4571
|
+
}, a = await yn(() => i.listSessionMessages(e, r), {
|
|
4572
|
+
isCurrent: V,
|
|
3923
4573
|
signal: u,
|
|
3924
4574
|
onPreparing: () => {
|
|
3925
4575
|
let t = s.getState().messageHistory[e];
|
|
@@ -3929,34 +4579,46 @@ function Xn(e) {
|
|
|
3929
4579
|
hasMore: t?.hasMore ?? !1,
|
|
3930
4580
|
preparing: !0,
|
|
3931
4581
|
error: void 0
|
|
3932
|
-
}), s.getState().setSessionInitialMessageHistoryLoading(e, !
|
|
4582
|
+
}), s.getState().setSessionInitialMessageHistoryLoading(e, !L);
|
|
3933
4583
|
}
|
|
3934
4584
|
});
|
|
3935
|
-
if (!
|
|
3936
|
-
let o =
|
|
3937
|
-
$(
|
|
3938
|
-
let
|
|
3939
|
-
if (!
|
|
3940
|
-
let t =
|
|
3941
|
-
H.getState().setMessages(t),
|
|
4585
|
+
if (!V()) return;
|
|
4586
|
+
let o = a.HistoryView === "items-v1" ? Rn(a, e) : void 0, h = o && Zn(o, i, e, a, A), g = Fn(a.Messages);
|
|
4587
|
+
$(te.current, e, g, f.current);
|
|
4588
|
+
let _ = Re(h?.messages ?? g, B), v = 0, S = h?.canonicalRunIds ?? [];
|
|
4589
|
+
if (!L) {
|
|
4590
|
+
let t = Ee(_, ae, H.getState().messages);
|
|
4591
|
+
H.getState().setMessages(t), ae = _, F(e, t);
|
|
3942
4592
|
}
|
|
3943
|
-
s.getState().setSessionMessageHistory(e, {
|
|
4593
|
+
if (s.getState().setSessionMessageHistory(e, {
|
|
3944
4594
|
nextCursor: a.NextCursor,
|
|
3945
4595
|
hasMore: a.HasMore,
|
|
3946
|
-
...
|
|
3947
|
-
}), s.getState().setSessionInitialMessageHistoryLoading(e, !1)
|
|
3948
|
-
|
|
4596
|
+
..._r(a)
|
|
4597
|
+
}), s.getState().setSessionInitialMessageHistoryLoading(e, !1), o) {
|
|
4598
|
+
let t = o.filter((e) => !e.ContentRef).map((e) => e.Event);
|
|
4599
|
+
$(k.current, e, {
|
|
4600
|
+
itemProjection: h,
|
|
4601
|
+
events: t,
|
|
4602
|
+
hasMore: a.HasMore,
|
|
4603
|
+
loadedCount: o.length,
|
|
4604
|
+
total: o.length,
|
|
4605
|
+
cursorSource: a.CursorSource,
|
|
4606
|
+
historyEpoch: a.HistoryEpoch,
|
|
4607
|
+
snapshotSeqId: a.SnapshotSeqId
|
|
4608
|
+
}, f.current);
|
|
4609
|
+
for (let n of t) x(n, e);
|
|
4610
|
+
} else try {
|
|
3949
4611
|
let t = await i.listSessionEvents(e, {
|
|
3950
4612
|
offset: 0,
|
|
3951
|
-
limit:
|
|
4613
|
+
limit: cr,
|
|
3952
4614
|
signal: u,
|
|
3953
4615
|
historyEpoch: a.CursorSource === "runtime" ? a.HistoryEpoch : void 0,
|
|
3954
4616
|
snapshotSeqId: a.CursorSource === "runtime" ? a.SnapshotSeqId : void 0
|
|
3955
4617
|
});
|
|
3956
|
-
if (!
|
|
3957
|
-
let n =
|
|
3958
|
-
if (n &&
|
|
3959
|
-
let
|
|
4618
|
+
if (!V()) return;
|
|
4619
|
+
let n = fr(a, t), r = t.Events, o = [...g].reverse().find((e) => e.invocationId && Object.values(e.tools || {}).some((e) => e.name === "call_a2a_agent"))?.invocationId;
|
|
4620
|
+
if (n && T.KernelSessionEventsByCommand === !0 && t.CursorSource === "runtime" && o && (r = await bn(i, e, o, t, V, u), !V())) return;
|
|
4621
|
+
let c = {
|
|
3960
4622
|
events: n ? r : [],
|
|
3961
4623
|
loadedCount: n ? r.length : 0,
|
|
3962
4624
|
total: n ? Math.max(0, Number(t.Total ?? t.Events?.length ?? 0) || 0) : 0,
|
|
@@ -3964,89 +4626,89 @@ function Xn(e) {
|
|
|
3964
4626
|
historyEpoch: n ? t.HistoryEpoch : void 0,
|
|
3965
4627
|
snapshotSeqId: n ? t.SnapshotSeqId : void 0
|
|
3966
4628
|
};
|
|
3967
|
-
if ($(k.current, e,
|
|
4629
|
+
if ($(k.current, e, c, f.current), s.getState().setSessionMessageHistory(e, {
|
|
3968
4630
|
nextCursor: a.NextCursor,
|
|
3969
|
-
hasMore: !!(a.HasMore ||
|
|
3970
|
-
}),
|
|
3971
|
-
|
|
3972
|
-
for (let t of
|
|
3973
|
-
let t =
|
|
3974
|
-
|
|
4631
|
+
hasMore: !!(a.HasMore || c.loadedCount < c.total)
|
|
4632
|
+
}), c.events.length > 0) {
|
|
4633
|
+
v = j(c.events);
|
|
4634
|
+
for (let t of c.events) x(t, e);
|
|
4635
|
+
let t = je(g, c.events, e, A);
|
|
4636
|
+
S = t.canonicalRunIds, _ = Re(t.messages, B);
|
|
3975
4637
|
}
|
|
3976
4638
|
if (n) {
|
|
3977
|
-
let n = await
|
|
3978
|
-
if (!
|
|
3979
|
-
for (let t of n.events)
|
|
3980
|
-
n.incomplete && (
|
|
3981
|
-
generation:
|
|
4639
|
+
let n = await wn(i, e, g, t, V, u);
|
|
4640
|
+
if (!V()) return;
|
|
4641
|
+
for (let t of n.events) x(t, e);
|
|
4642
|
+
n.incomplete && (b.current = {
|
|
4643
|
+
generation: N,
|
|
3982
4644
|
message: "部分交互历史尚未恢复完整,旧卡片保持只读。请加载较早消息后重试。"
|
|
3983
4645
|
}, s.getState().setSessionMessageHistory(e, {
|
|
3984
4646
|
...s.getState().messageHistory[e],
|
|
3985
4647
|
nextCursor: a.NextCursor,
|
|
3986
|
-
hasMore: !!(a.HasMore ||
|
|
4648
|
+
hasMore: !!(a.HasMore || c.loadedCount < c.total),
|
|
3987
4649
|
error: "部分交互历史尚未恢复完整,旧卡片保持只读。请加载较早消息后重试。"
|
|
3988
4650
|
}));
|
|
3989
4651
|
}
|
|
3990
4652
|
} catch (e) {
|
|
3991
|
-
if (
|
|
3992
|
-
|
|
3993
|
-
generation:
|
|
4653
|
+
if (hr(e)) throw e;
|
|
4654
|
+
V() && (b.current = {
|
|
4655
|
+
generation: N,
|
|
3994
4656
|
message: "完整事件历史读取失败,请刷新会话后重新查找。当前结果只包含已读取的正文。"
|
|
3995
4657
|
}), console.warn("[SessionLifecycle] canonical history replay failed:", e);
|
|
3996
4658
|
}
|
|
3997
|
-
if (!
|
|
3998
|
-
ee(
|
|
3999
|
-
let
|
|
4000
|
-
|
|
4001
|
-
agentId:
|
|
4659
|
+
if (!V()) return;
|
|
4660
|
+
ee(_, e), $(C.current, e, new Set(S), f.current), $(w.current, e, _, f.current), _ = Ee(_, ae, H.getState().messages), H.getState().setMessages(_), F(e, _), y.current = null, re(p.current, e, _);
|
|
4661
|
+
let E = Math.max(a.LatestSeqId || 0, v), D = c.getState().capabilities || l, O = t(n(T));
|
|
4662
|
+
D.RunLifecycle.Enabled && D.RunLifecycle.Checkpoints ? (i.listSessionCheckpoints({
|
|
4663
|
+
agentId: p.current,
|
|
4002
4664
|
sessionId: e
|
|
4003
4665
|
}).then((t) => {
|
|
4004
|
-
|
|
4666
|
+
V() && W.getState().setSessionCheckpoints(e, t.Checkpoints || []);
|
|
4005
4667
|
}).catch((t) => {
|
|
4006
|
-
|
|
4668
|
+
V() && (console.warn("[SessionLifecycle] checkpoint load failed:", t), W.getState().setSessionCheckpoints(e, []));
|
|
4007
4669
|
}), i.listToolReceipts({
|
|
4008
|
-
agentId:
|
|
4670
|
+
agentId: p.current,
|
|
4009
4671
|
sessionId: e
|
|
4010
4672
|
}).then((t) => {
|
|
4011
|
-
|
|
4673
|
+
V() && W.getState().setSessionToolReceipts(e, t.ToolReceipts || []);
|
|
4012
4674
|
}).catch((t) => {
|
|
4013
|
-
|
|
4675
|
+
V() && (console.warn("[SessionLifecycle] tool receipt load failed:", t), W.getState().setSessionToolReceipts(e, []));
|
|
4014
4676
|
})) : W.getState().clearSessionCheckpoints(e);
|
|
4015
|
-
let
|
|
4016
|
-
if (
|
|
4017
|
-
let t =
|
|
4018
|
-
if (
|
|
4019
|
-
let n = k.current.get(e), r = await
|
|
4677
|
+
let M = D.RunLifecycle.Enabled && D.RunLifecycle.Resume;
|
|
4678
|
+
if (O || M) try {
|
|
4679
|
+
let t = M ? await i.getSession(e) : {};
|
|
4680
|
+
if (O && !t.ActiveInvocationId && V()) {
|
|
4681
|
+
let n = k.current.get(e), r = await $n(i, e, a, n && fr(a, pr(n)) ? n : void 0, u);
|
|
4020
4682
|
r && (t = {
|
|
4021
4683
|
ActiveInvocationId: r.InvocationId,
|
|
4022
4684
|
ActiveRunStatus: R(r)
|
|
4023
4685
|
});
|
|
4024
4686
|
}
|
|
4025
|
-
if (!
|
|
4687
|
+
if (!V()) return;
|
|
4026
4688
|
let n = String(t.ActiveRunStatus || "").toLowerCase();
|
|
4027
|
-
if (t.ActiveInvocationId && (
|
|
4028
|
-
let n =
|
|
4689
|
+
if (t.ActiveInvocationId && (yr.has(n) || n === "" && br(t)) && t.ActiveInvocationId !== d) {
|
|
4690
|
+
let n = m.getState().getSessionActivity(e), r = (T.KernelSessionEventsByCommand === !0 || O) && m.getState().isSessionStreaming(e) && n?.source === "run" && n.runId === t.ActiveInvocationId && [
|
|
4029
4691
|
"connecting",
|
|
4030
4692
|
"running",
|
|
4031
4693
|
"waiting"
|
|
4032
4694
|
].includes(n.status);
|
|
4033
|
-
r &&
|
|
4695
|
+
r && m.getState().updateActivity({
|
|
4034
4696
|
sessionId: e,
|
|
4035
4697
|
phase: "正在处理",
|
|
4036
4698
|
countEvent: !1
|
|
4037
|
-
}), r ||
|
|
4699
|
+
}), r || z({
|
|
4038
4700
|
sessionId: e,
|
|
4039
4701
|
invocationId: t.ActiveInvocationId,
|
|
4040
|
-
afterSeqId:
|
|
4702
|
+
afterSeqId: E
|
|
4041
4703
|
});
|
|
4042
4704
|
} else {
|
|
4043
|
-
let r =
|
|
4705
|
+
let r = m.getState(), i = r.getSessionActivity(e), a = t.ActiveInvocationId && i?.runId === t.ActiveInvocationId ? xr({
|
|
4044
4706
|
EventType: "run_status",
|
|
4045
4707
|
Content: { status: n }
|
|
4046
4708
|
}) : null, o = i?.runId ? [...k.current.get(e)?.events || []].reverse().find((e) => {
|
|
4047
4709
|
let t = e.Content?.runtime_event;
|
|
4048
|
-
return e.InvocationId === i.runId && !t?.parent_scope_id &&
|
|
4049
|
-
}) : void 0, s = a || o &&
|
|
4710
|
+
return e.InvocationId === i.runId && !t?.parent_scope_id && ne(e);
|
|
4711
|
+
}) : void 0, s = a || o && xr(o);
|
|
4050
4712
|
s && (r.setSessionStreaming(e, !1), r.updateActivity({
|
|
4051
4713
|
sessionId: e,
|
|
4052
4714
|
...s,
|
|
@@ -4054,8 +4716,8 @@ function Xn(e) {
|
|
|
4054
4716
|
}));
|
|
4055
4717
|
}
|
|
4056
4718
|
} catch (t) {
|
|
4057
|
-
if (console.warn("[SessionLifecycle] getSession for reconnect failed:", t),
|
|
4058
|
-
let t =
|
|
4719
|
+
if (console.warn("[SessionLifecycle] getSession for reconnect failed:", t), V()) {
|
|
4720
|
+
let t = m.getState();
|
|
4059
4721
|
t.isSessionStreaming(e) && t.getSessionActivity(e)?.phase === "正在同步任务进展" && t.updateActivity({
|
|
4060
4722
|
sessionId: e,
|
|
4061
4723
|
phase: "正在确认任务状态",
|
|
@@ -4064,26 +4726,29 @@ function Xn(e) {
|
|
|
4064
4726
|
}
|
|
4065
4727
|
}
|
|
4066
4728
|
} catch (t) {
|
|
4067
|
-
if (
|
|
4729
|
+
if (hr(t) && !r && V()) {
|
|
4068
4730
|
s.getState().setSessionMessageHistory(e, {
|
|
4731
|
+
nextItemCursor: null,
|
|
4732
|
+
historyView: void 0,
|
|
4069
4733
|
nextCursor: null,
|
|
4070
4734
|
hasMore: !1,
|
|
4071
4735
|
cursorSource: void 0,
|
|
4072
4736
|
historyEpoch: void 0,
|
|
4737
|
+
historyEpochSource: void 0,
|
|
4073
4738
|
snapshotSeqId: void 0,
|
|
4074
4739
|
dataSource: void 0,
|
|
4075
4740
|
degraded: void 0,
|
|
4076
4741
|
cursorCompatibleWithRuntime: void 0,
|
|
4077
4742
|
sessionContractVersion: void 0
|
|
4078
4743
|
}), queueMicrotask(() => {
|
|
4079
|
-
|
|
4744
|
+
V() && I.current?.(e, !0);
|
|
4080
4745
|
});
|
|
4081
4746
|
return;
|
|
4082
4747
|
}
|
|
4083
|
-
if (
|
|
4084
|
-
let n = r ? "历史来源已变化,重新加载失败。原有消息已保留,请手动刷新会话。" :
|
|
4085
|
-
|
|
4086
|
-
generation:
|
|
4748
|
+
if (V() && !(t instanceof X)) {
|
|
4749
|
+
let n = r ? "历史来源已变化,重新加载失败。原有消息已保留,请手动刷新会话。" : vn(t) ? "历史仍在准备,请稍后重试。" : "会话历史读取失败,请重试。已有消息已保留。";
|
|
4750
|
+
b.current = {
|
|
4751
|
+
generation: N,
|
|
4087
4752
|
message: n
|
|
4088
4753
|
};
|
|
4089
4754
|
let i = s.getState().messageHistory[e];
|
|
@@ -4096,24 +4761,30 @@ function Xn(e) {
|
|
|
4096
4761
|
hasMore: !1,
|
|
4097
4762
|
cursorSource: void 0,
|
|
4098
4763
|
historyEpoch: void 0,
|
|
4764
|
+
historyEpochSource: void 0,
|
|
4099
4765
|
snapshotSeqId: void 0
|
|
4100
4766
|
} : {},
|
|
4101
4767
|
preparing: !1,
|
|
4102
|
-
error: n
|
|
4103
|
-
|
|
4768
|
+
error: n,
|
|
4769
|
+
retryOlderPage: !1
|
|
4770
|
+
}), r && g.getState().pushToast(n, "error");
|
|
4104
4771
|
}
|
|
4105
4772
|
t instanceof X || console.error("Failed to load session messages:", t);
|
|
4106
4773
|
} finally {
|
|
4107
|
-
|
|
4774
|
+
y.current === N && (y.current = null), V() && s.getState().setSessionInitialMessageHistoryLoading(e, !1);
|
|
4108
4775
|
}
|
|
4109
4776
|
}, [
|
|
4110
4777
|
i,
|
|
4111
4778
|
a,
|
|
4112
|
-
|
|
4779
|
+
re,
|
|
4113
4780
|
o,
|
|
4114
|
-
|
|
4781
|
+
z,
|
|
4115
4782
|
l
|
|
4116
|
-
]),
|
|
4783
|
+
]), ae = K((e, t) => {
|
|
4784
|
+
if (f.current !== e) return;
|
|
4785
|
+
let n = H.getState().messages.find((e) => e.role === "user" && (e.runId || e.invocationId) === t);
|
|
4786
|
+
n && $(E.current, e, n, e), V(e, !1, void 0, t);
|
|
4787
|
+
}, [V]), U = K(async (e = "default-agent", t = null) => {
|
|
4117
4788
|
let n = s.getState();
|
|
4118
4789
|
n.sessionsAgentId && n.sessionsAgentId !== e && n.resetSessionPagination(e);
|
|
4119
4790
|
let r = s.getState().sessionsGeneration, a = () => c.getState().agentId === e && s.getState().sessionsGeneration === r;
|
|
@@ -4121,21 +4792,21 @@ function Xn(e) {
|
|
|
4121
4792
|
s.getState().setLoadingSessions(!0);
|
|
4122
4793
|
let n = await i.listSessions(e, {
|
|
4123
4794
|
page: 1,
|
|
4124
|
-
pageSize:
|
|
4795
|
+
pageSize: or
|
|
4125
4796
|
});
|
|
4126
4797
|
if (!a()) return;
|
|
4127
4798
|
let r = n.Sessions || [];
|
|
4128
|
-
for (let e of r)
|
|
4129
|
-
let o = new Set(Array.from(
|
|
4799
|
+
for (let e of r) A.current.delete(e.SessionId);
|
|
4800
|
+
let o = new Set(Array.from(A.current.entries()).filter(([, t]) => t === e).map(([e]) => e)), c = st(r, s.getState().sessions, o);
|
|
4130
4801
|
if (s.getState().upsertSessions(c, {
|
|
4131
4802
|
agentId: e,
|
|
4132
4803
|
total: Number(n.Total ?? n.Sessions?.length ?? 0),
|
|
4133
4804
|
page: Number(n.Page ?? 1),
|
|
4134
|
-
pageSize: Number(n.PageSize ??
|
|
4805
|
+
pageSize: Number(n.PageSize ?? or),
|
|
4135
4806
|
replace: !0
|
|
4136
|
-
}),
|
|
4137
|
-
let l = s.getState().sessions, u =
|
|
4138
|
-
|
|
4807
|
+
}), N.current || P.current === e) return;
|
|
4808
|
+
let l = s.getState().sessions, u = f.current, p = u || (d ? ot(l, t || it(e)) : null);
|
|
4809
|
+
p && p !== u && V(p);
|
|
4139
4810
|
} catch (e) {
|
|
4140
4811
|
if (e instanceof X) return;
|
|
4141
4812
|
console.error("Failed to fetch sessions:", e);
|
|
@@ -4145,17 +4816,34 @@ function Xn(e) {
|
|
|
4145
4816
|
}, [
|
|
4146
4817
|
i,
|
|
4147
4818
|
V,
|
|
4148
|
-
|
|
4149
|
-
]),
|
|
4819
|
+
d
|
|
4820
|
+
]), oe = K((e, t) => {
|
|
4821
|
+
d && t && !f.current && !N.current && P.current !== e && (p.current = e, V(t));
|
|
4822
|
+
let n = U(e, t);
|
|
4823
|
+
if (d && !f.current && P.current !== e) {
|
|
4824
|
+
let e = {
|
|
4825
|
+
ready: n,
|
|
4826
|
+
cancelled: !1
|
|
4827
|
+
};
|
|
4828
|
+
M.current = e, n.finally(() => {
|
|
4829
|
+
M.current === e && (M.current = null);
|
|
4830
|
+
});
|
|
4831
|
+
}
|
|
4832
|
+
return n;
|
|
4833
|
+
}, [
|
|
4834
|
+
U,
|
|
4835
|
+
V,
|
|
4836
|
+
d
|
|
4837
|
+
]), ce = K((...e) => (M.current && (M.current.cancelled = !0), V(...e)), [V]), le = K(async () => {
|
|
4150
4838
|
let e = s.getState();
|
|
4151
4839
|
if (e.isLoadingSessions || !e.hasMoreSessions) return;
|
|
4152
|
-
let t =
|
|
4840
|
+
let t = T({
|
|
4153
4841
|
total: e.sessionsTotal,
|
|
4154
|
-
pageSize: e.sessionsPageSize ||
|
|
4842
|
+
pageSize: e.sessionsPageSize || or,
|
|
4155
4843
|
loadedPages: e.loadedPages
|
|
4156
4844
|
});
|
|
4157
4845
|
if (!t) return;
|
|
4158
|
-
let n = e.sessionsPageSize ||
|
|
4846
|
+
let n = e.sessionsPageSize || or, r = e.sessionsAgentId || p.current || "default-agent", a = () => c.getState().agentId === r && s.getState().sessionsGeneration === e.sessionsGeneration;
|
|
4159
4847
|
try {
|
|
4160
4848
|
s.getState().setLoadingSessions(!0);
|
|
4161
4849
|
let o = await i.listSessions(r, {
|
|
@@ -4181,62 +4869,65 @@ function Xn(e) {
|
|
|
4181
4869
|
}, [V]), q(() => {
|
|
4182
4870
|
L.current = U;
|
|
4183
4871
|
}, [U]);
|
|
4184
|
-
let
|
|
4185
|
-
if (P.current = null, t &&
|
|
4872
|
+
let ue = K((e, t = !1) => {
|
|
4873
|
+
if (P.current = null, t && f.current === e) {
|
|
4186
4874
|
s.getState().upsertSessions([{
|
|
4187
4875
|
SessionId: e,
|
|
4188
4876
|
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4189
4877
|
}]);
|
|
4190
4878
|
return;
|
|
4191
4879
|
}
|
|
4192
|
-
|
|
4880
|
+
v.current += 1, _.current?.abort(), A.current.set(e, p.current), s.getState().upsertSessions([{
|
|
4193
4881
|
SessionId: e,
|
|
4194
4882
|
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4195
|
-
}]),
|
|
4196
|
-
}, [a]),
|
|
4197
|
-
P.current =
|
|
4198
|
-
}, [a]),
|
|
4199
|
-
if (
|
|
4200
|
-
await
|
|
4883
|
+
}]), f.current = e, s.getState().setCurrentSessionId(e), t || (H.getState().setMessages([]), m.getState().setCurrentRunId(""), m.getState().clearActivity()), s.getState().clearSessionMessageHistory(e), W.getState().setSessionCheckpoints(e, []), W.getState().setSessionToolReceipts(e, []), a && (g.getState().setMobileSidebarOpen(!1), g.getState().setMobileActionsOpen(!1));
|
|
4884
|
+
}, [a]), fe = K(() => {
|
|
4885
|
+
M.current && (M.current.cancelled = !0), at(p.current, null), P.current = p.current, v.current += 1, _.current?.abort(), f.current = null, s.getState().setCurrentSessionId(null), H.getState().setMessages([]), m.getState().setCurrentRunId(""), m.getState().clearActivity(), a && g.getState().setMobileSidebarOpen(!1);
|
|
4886
|
+
}, [a]), pe = K(async () => {
|
|
4887
|
+
if (N.current) {
|
|
4888
|
+
await N.current;
|
|
4201
4889
|
return;
|
|
4202
4890
|
}
|
|
4203
|
-
|
|
4891
|
+
M.current && (M.current.cancelled = !0), at(r, null), v.current += 1, _.current?.abort(), f.current = null, s.getState().setCurrentSessionId(null), H.getState().setMessages([]);
|
|
4204
4892
|
let e = i.createSession(r).then((e) => {
|
|
4205
4893
|
let t = e.SessionId || null;
|
|
4206
|
-
return t && c.getState().agentId === r &&
|
|
4894
|
+
return t && c.getState().agentId === r && ue(t, H.getState().messages.some((e) => e.eventType === "optimistic_user_message" || e.eventType === "optimistic_assistant_placeholder")), t;
|
|
4207
4895
|
}).catch((e) => (e instanceof X || console.error("Failed to create session:", e), null));
|
|
4208
|
-
|
|
4896
|
+
N.current = e;
|
|
4209
4897
|
try {
|
|
4210
4898
|
await e;
|
|
4211
4899
|
} finally {
|
|
4212
|
-
|
|
4900
|
+
N.current === e && (N.current = null);
|
|
4213
4901
|
}
|
|
4214
4902
|
}, [
|
|
4215
|
-
|
|
4903
|
+
ue,
|
|
4216
4904
|
r,
|
|
4217
4905
|
i
|
|
4218
|
-
]),
|
|
4219
|
-
let e =
|
|
4220
|
-
|
|
4221
|
-
|
|
4906
|
+
]), G = K(async () => {
|
|
4907
|
+
let e = N.current;
|
|
4908
|
+
if (e) return await e;
|
|
4909
|
+
let t = M.current;
|
|
4910
|
+
if (!f.current && t && !t.cancelled && (await t.ready, t.cancelled)) throw new X();
|
|
4911
|
+
return f.current;
|
|
4912
|
+
}, []), me = K(async (e) => {
|
|
4222
4913
|
try {
|
|
4223
4914
|
let t = await i.deleteSession(e);
|
|
4224
|
-
return c.getState().agentId === r ? t.Deleted === !1 ? (
|
|
4915
|
+
return c.getState().agentId === r ? t.Deleted === !1 ? (g.getState().pushToast("会话暂未删除,云端运行时仍在同步,请稍后重试。", "error"), U(r, f.current ?? void 0), !1) : (s.getState().removeSession(e), s.getState().clearSessionMessageHistory(e), D.current.delete(e), te.current.delete(e), O.current.delete(e), k.current.delete(e), C.current.delete(e), w.current.delete(e), E.current.delete(e), A.current.delete(e), f.current === e && (at(r, null), v.current += 1, _.current?.abort(), u?.(), f.current = null, H.getState().setMessages([]), W.getState().clearSessionCheckpoints(e), s.getState().setCurrentSessionId(null), m.getState().setCurrentRunId(""), m.getState().clearActivity(), U(r)), !0) : t.Deleted !== !1;
|
|
4225
4916
|
} catch (e) {
|
|
4226
|
-
return e instanceof X ? !1 : (console.error("Failed to delete session", e),
|
|
4917
|
+
return e instanceof X ? !1 : (console.error("Failed to delete session", e), g.getState().pushToast("删除会话失败,请稍后重试。", "error"), !1);
|
|
4227
4918
|
}
|
|
4228
4919
|
}, [
|
|
4229
4920
|
r,
|
|
4230
4921
|
i,
|
|
4231
|
-
|
|
4922
|
+
u,
|
|
4232
4923
|
U
|
|
4233
|
-
]),
|
|
4924
|
+
]), _e = K(async (e, t) => {
|
|
4234
4925
|
t?.throwIfAborted();
|
|
4235
|
-
let n = s.getState().messageHistory[e], r = k.current.get(e), a = !!(n?.hasMore && n.nextCursor !== null), o = !!(r && r.loadedCount < r.total);
|
|
4926
|
+
let n = s.getState().messageHistory[e], r = k.current.get(e), a = !!(n?.hasMore && (n.nextCursor !== null || n.nextItemCursor)), o = !!(r && r.loadedCount < r.total);
|
|
4236
4927
|
if (!n || n.isLoadingOlder || !a && !o) return;
|
|
4237
|
-
let c =
|
|
4238
|
-
|
|
4239
|
-
let d = () =>
|
|
4928
|
+
let c = v.current, l = w.current.get(e) || H.getState().messages, u = Symbol(e);
|
|
4929
|
+
S.current.set(e, u);
|
|
4930
|
+
let d = () => f.current === e && v.current === c && S.current.get(e) === u && !t?.aborted, m = {
|
|
4240
4931
|
isCurrent: d,
|
|
4241
4932
|
signal: t,
|
|
4242
4933
|
onPreparing: () => {
|
|
@@ -4250,25 +4941,27 @@ function Xn(e) {
|
|
|
4250
4941
|
};
|
|
4251
4942
|
try {
|
|
4252
4943
|
s.getState().setSessionMessageHistoryLoading(e, !0);
|
|
4253
|
-
let [h, g] = await Promise.allSettled([a ?
|
|
4944
|
+
let [h, g] = await Promise.allSettled([a ? yn(() => i.listSessionMessages(e, {
|
|
4254
4945
|
signal: t,
|
|
4946
|
+
historyView: n.historyView ?? (n.cursorSource === "runtime" && n.historyEpoch && n.snapshotSeqId !== void 0 ? "items-v1" : void 0),
|
|
4947
|
+
itemCursor: n.nextItemCursor ?? void 0,
|
|
4255
4948
|
beforeSeqId: n.nextCursor ?? void 0,
|
|
4256
4949
|
cursorSource: n.cursorSource,
|
|
4257
4950
|
historyEpoch: n.historyEpoch,
|
|
4258
4951
|
snapshotSeqId: n.snapshotSeqId,
|
|
4259
|
-
limit:
|
|
4952
|
+
limit: sr,
|
|
4260
4953
|
includeReasoning: !0,
|
|
4261
4954
|
includeToolEvents: !0,
|
|
4262
4955
|
includeAttachments: !0
|
|
4263
|
-
}),
|
|
4956
|
+
}), m) : Promise.resolve(null), o && r ? yn(() => i.listSessionEvents(e, {
|
|
4264
4957
|
signal: t,
|
|
4265
4958
|
offset: r.loadedCount,
|
|
4266
|
-
limit:
|
|
4959
|
+
limit: cr,
|
|
4267
4960
|
cursorSource: r.cursorSource,
|
|
4268
4961
|
historyEpoch: r.historyEpoch,
|
|
4269
4962
|
snapshotSeqId: r.snapshotSeqId
|
|
4270
|
-
}),
|
|
4271
|
-
if (t?.throwIfAborted(),
|
|
4963
|
+
}), m) : Promise.resolve(null)]);
|
|
4964
|
+
if (t?.throwIfAborted(), f.current !== e || v.current !== c || S.current.get(e) !== u) return;
|
|
4272
4965
|
let _ = g.status === "rejected" && g.reason instanceof Y && [
|
|
4273
4966
|
429,
|
|
4274
4967
|
502,
|
|
@@ -4277,73 +4970,111 @@ function Xn(e) {
|
|
|
4277
4970
|
].includes(g.reason.code);
|
|
4278
4971
|
if (g.status === "rejected" && !_) throw g.reason;
|
|
4279
4972
|
if (h.status === "rejected") throw h.reason;
|
|
4280
|
-
let
|
|
4281
|
-
if (
|
|
4973
|
+
let y = h.value, T = g.status === "fulfilled" ? g.value : null, A = _ ? "消息正文已加载,部分事件详情暂时读取失败,请重试加载更早记录。" : void 0;
|
|
4974
|
+
if (y && !fr({
|
|
4282
4975
|
CursorSource: n.cursorSource,
|
|
4283
4976
|
HistoryEpoch: n.historyEpoch,
|
|
4284
4977
|
SnapshotSeqId: n.snapshotSeqId,
|
|
4285
4978
|
CursorCompatibleWithRuntime: n.cursorCompatibleWithRuntime
|
|
4286
|
-
},
|
|
4287
|
-
S ? C.current = {
|
|
4979
|
+
}, y) || T && r && !fr(pr(r), T) || (A ? b.current = {
|
|
4288
4980
|
generation: c,
|
|
4289
|
-
message:
|
|
4290
|
-
} :
|
|
4291
|
-
let
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
let
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4981
|
+
message: A
|
|
4982
|
+
} : T && (b.current = null), n.historyView === "items-v1" && y?.HistoryView !== "items-v1")) throw gr();
|
|
4983
|
+
let j, M;
|
|
4984
|
+
if (y?.HistoryView === "items-v1") {
|
|
4985
|
+
let t = Rn(y, e, n.nextItemCursor), a = r?.itemProjection, o = a?.firstSeq ?? n.nextCursor;
|
|
4986
|
+
if (!a && (n.historyView === "items-v1" || n.cursorSource !== "runtime" || !n.historyEpoch || n.snapshotSeqId !== y.SnapshotSeqId || o == null) || t.length && o != null && t.at(-1).SeqId >= o) throw gr();
|
|
4987
|
+
let s = a ? r?.legacySuffix : {
|
|
4988
|
+
messages: l,
|
|
4989
|
+
boundary: o,
|
|
4990
|
+
canonicalRunIds: [...C.current.get(e) || []]
|
|
4991
|
+
}, c = Zn(t, i, e, y, O.current.get(e) || "flat-v1", a);
|
|
4992
|
+
if (j = c, s) {
|
|
4993
|
+
let e = s.messages.filter((e) => {
|
|
4994
|
+
let t = e.historyOrder?.seq;
|
|
4995
|
+
return t == null || t >= s.boundary || y.HasMore && c.firstSeq != null && t < c.firstSeq;
|
|
4996
|
+
}), t = new Set(e.map((e) => e.id));
|
|
4997
|
+
j = {
|
|
4998
|
+
messages: be([...c.messages.filter((e) => !t.has(e.id)), ...e]),
|
|
4999
|
+
canonicalRunIds: [...new Set([...c.canonicalRunIds, ...s.canonicalRunIds])]
|
|
5000
|
+
};
|
|
5001
|
+
}
|
|
5002
|
+
let u = t.filter((e) => !e.ContentRef).map((e) => e.Event), d = (a ? r.loadedCount : 0) + t.length;
|
|
5003
|
+
M = {
|
|
5004
|
+
itemProjection: c,
|
|
5005
|
+
legacySuffix: s,
|
|
5006
|
+
hasMore: y.HasMore,
|
|
5007
|
+
events: [...u.filter((e) => e.EventType === "run_status" || ne(e)), ...r?.events || []],
|
|
5008
|
+
loadedCount: d,
|
|
5009
|
+
total: d,
|
|
5010
|
+
historyEpoch: y.HistoryEpoch,
|
|
5011
|
+
snapshotSeqId: y.SnapshotSeqId,
|
|
5012
|
+
cursorSource: y.CursorSource
|
|
5013
|
+
};
|
|
5014
|
+
for (let t of u) x(t, e);
|
|
5015
|
+
b.current = null, A = void 0;
|
|
5016
|
+
}
|
|
5017
|
+
let N = y ? Fn(y.Messages) : [], P = new Set(N.map((e) => e.id)), I = [...N, ...(te.current.get(e) || []).filter((e) => !P.has(e.id))];
|
|
5018
|
+
$(te.current, e, I, f.current);
|
|
5019
|
+
let L = r?.events || [], R = r?.loadedCount || 0, z = r?.total || 0;
|
|
5020
|
+
if (M) R = z = M.loadedCount;
|
|
5021
|
+
else if (T) {
|
|
5022
|
+
let t = T.Events || [];
|
|
5023
|
+
L = F(t, L), z = Math.max(z, Number(T.Total ?? 0) || 0), R = t.length > 0 ? Math.min(z, R + t.length) : z, $(k.current, e, {
|
|
5024
|
+
events: L,
|
|
5025
|
+
loadedCount: R,
|
|
5026
|
+
total: z,
|
|
5027
|
+
cursorSource: T.CursorSource ?? r?.cursorSource,
|
|
5028
|
+
historyEpoch: T.HistoryEpoch ?? r?.historyEpoch,
|
|
5029
|
+
snapshotSeqId: T.SnapshotSeqId ?? r?.snapshotSeqId
|
|
5030
|
+
}, f.current);
|
|
5031
|
+
for (let n of t) x(n, e);
|
|
4305
5032
|
}
|
|
4306
|
-
if (
|
|
4307
|
-
let n = await
|
|
4308
|
-
Events:
|
|
5033
|
+
if (N.length && r) {
|
|
5034
|
+
let n = await wn(i, e, N, {
|
|
5035
|
+
Events: L,
|
|
4309
5036
|
CursorSource: r.cursorSource,
|
|
4310
5037
|
HistoryEpoch: r.historyEpoch,
|
|
4311
5038
|
SnapshotSeqId: r.snapshotSeqId
|
|
4312
5039
|
}, d, t);
|
|
4313
5040
|
if (!d()) return;
|
|
4314
|
-
for (let t of n.events)
|
|
4315
|
-
n.incomplete && (
|
|
5041
|
+
for (let t of n.events) x(t, e);
|
|
5042
|
+
n.incomplete && (A = "部分交互历史尚未恢复完整,旧卡片保持只读。请加载较早消息后重试。", b.current = {
|
|
4316
5043
|
generation: c,
|
|
4317
|
-
message:
|
|
5044
|
+
message: A
|
|
4318
5045
|
});
|
|
4319
5046
|
}
|
|
4320
|
-
let
|
|
4321
|
-
|
|
4322
|
-
let
|
|
4323
|
-
$(
|
|
4324
|
-
nextCursor:
|
|
4325
|
-
hasMore: !!(
|
|
4326
|
-
...
|
|
4327
|
-
...
|
|
4328
|
-
dataSource:
|
|
4329
|
-
degraded:
|
|
4330
|
-
cursorSource:
|
|
4331
|
-
cursorCompatibleWithRuntime:
|
|
4332
|
-
sessionContractVersion:
|
|
4333
|
-
historyEpoch:
|
|
4334
|
-
persistenceDegraded:
|
|
4335
|
-
snapshotSeqId:
|
|
5047
|
+
let B = j ?? je(I, L, e, O.current.get(e) || "flat-v1"), V = Re(B.messages, E.current.get(e));
|
|
5048
|
+
M && $(k.current, e, M, f.current), ee(V, e), $(w.current, e, V, f.current);
|
|
5049
|
+
let ie = Ee(V, l, H.getState().messages, !!j);
|
|
5050
|
+
$(C.current, e, new Set(B.canonicalRunIds), f.current), H.getState().setMessages(ie), $(D.current, e, ie, f.current, lr), s.getState().setSessionMessageHistory(e, {
|
|
5051
|
+
nextCursor: y ? y.NextCursor : n.nextCursor,
|
|
5052
|
+
hasMore: !!(y && y.HasMore || R < z),
|
|
5053
|
+
...y ? _r(y) : {},
|
|
5054
|
+
...y ? {
|
|
5055
|
+
dataSource: y.DataSource ?? n.dataSource,
|
|
5056
|
+
degraded: y.Degraded ?? n.degraded,
|
|
5057
|
+
cursorSource: y.CursorSource ?? n.cursorSource,
|
|
5058
|
+
cursorCompatibleWithRuntime: y.CursorCompatibleWithRuntime ?? n.cursorCompatibleWithRuntime,
|
|
5059
|
+
sessionContractVersion: y.SessionContractVersion ?? n.sessionContractVersion,
|
|
5060
|
+
historyEpoch: y.HistoryEpoch ?? n.historyEpoch,
|
|
5061
|
+
persistenceDegraded: y.PersistenceDegraded ?? n.persistenceDegraded,
|
|
5062
|
+
snapshotSeqId: y.SnapshotSeqId ?? n.snapshotSeqId
|
|
4336
5063
|
} : {},
|
|
4337
5064
|
preparing: !1,
|
|
4338
|
-
error:
|
|
4339
|
-
|
|
5065
|
+
error: A,
|
|
5066
|
+
retryOlderPage: !!A
|
|
5067
|
+
}), re(p.current, e, N);
|
|
4340
5068
|
} catch (r) {
|
|
4341
|
-
if (
|
|
5069
|
+
if (hr(r) && f.current === e && v.current === c && S.current.get(e) === u && !t?.aborted) {
|
|
4342
5070
|
s.getState().setSessionMessageHistory(e, {
|
|
4343
5071
|
nextCursor: null,
|
|
5072
|
+
nextItemCursor: null,
|
|
5073
|
+
historyView: void 0,
|
|
4344
5074
|
hasMore: !1,
|
|
4345
5075
|
cursorSource: void 0,
|
|
4346
5076
|
historyEpoch: void 0,
|
|
5077
|
+
historyEpochSource: void 0,
|
|
4347
5078
|
snapshotSeqId: void 0,
|
|
4348
5079
|
dataSource: void 0,
|
|
4349
5080
|
degraded: void 0,
|
|
@@ -4357,11 +5088,12 @@ function Xn(e) {
|
|
|
4357
5088
|
if (d() && !(r instanceof X) && s.getState().setSessionMessageHistory(e, {
|
|
4358
5089
|
...n,
|
|
4359
5090
|
preparing: !1,
|
|
5091
|
+
retryOlderPage: !0,
|
|
4360
5092
|
error: r instanceof Error ? r.message : "历史加载失败,请重试"
|
|
4361
5093
|
}), t) throw r;
|
|
4362
5094
|
r instanceof X || console.error("Failed to load older session messages:", r);
|
|
4363
5095
|
} finally {
|
|
4364
|
-
if (
|
|
5096
|
+
if (S.current.get(e) === u) if (S.current.delete(e), v.current === c) {
|
|
4365
5097
|
let t = s.getState().messageHistory[e];
|
|
4366
5098
|
s.getState().setSessionMessageHistory(e, {
|
|
4367
5099
|
...t,
|
|
@@ -4374,39 +5106,41 @@ function Xn(e) {
|
|
|
4374
5106
|
}
|
|
4375
5107
|
}, [
|
|
4376
5108
|
i,
|
|
4377
|
-
|
|
5109
|
+
re,
|
|
4378
5110
|
V
|
|
4379
5111
|
]);
|
|
4380
5112
|
return {
|
|
4381
5113
|
historySearchSnapshot: K(() => {
|
|
4382
|
-
let e =
|
|
5114
|
+
let e = f.current || "", t = s.getState().messageHistory[e], n = k.current.get(e);
|
|
4383
5115
|
return {
|
|
4384
5116
|
owner: JSON.stringify([
|
|
4385
|
-
|
|
5117
|
+
p.current,
|
|
4386
5118
|
e,
|
|
4387
|
-
|
|
5119
|
+
v.current
|
|
4388
5120
|
]),
|
|
4389
5121
|
messages: H.getState().messages,
|
|
4390
5122
|
hasMore: !!t?.hasMore,
|
|
4391
|
-
loading: !!(
|
|
4392
|
-
checkpoint: `${t?.nextCursor}:${n?.loadedCount}`,
|
|
4393
|
-
error:
|
|
5123
|
+
loading: !!(y.current === v.current || s.getState().isLoadingSessions || t?.isLoadingInitial || t?.isLoadingOlder),
|
|
5124
|
+
checkpoint: `${t?.nextItemCursor ?? t?.nextCursor}:${n?.loadedCount}`,
|
|
5125
|
+
error: b.current?.generation === v.current ? b.current.message : void 0
|
|
4394
5126
|
};
|
|
4395
5127
|
}, []),
|
|
4396
5128
|
followAcceptedInteraction: B,
|
|
4397
5129
|
fetchSessions: U,
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
5130
|
+
fetchInitialSessions: oe,
|
|
5131
|
+
loadMoreSessions: le,
|
|
5132
|
+
loadSession: ce,
|
|
5133
|
+
recoverSessionRun: ae,
|
|
5134
|
+
loadOlderSessionMessages: _e,
|
|
5135
|
+
createNewSession: pe,
|
|
5136
|
+
startNewConversation: fe,
|
|
5137
|
+
adoptCreatedSession: ue,
|
|
5138
|
+
waitForPendingSessionCreation: G,
|
|
5139
|
+
deleteSession: me,
|
|
5140
|
+
currentSessionIdRef: f,
|
|
5141
|
+
agentIdRef: p,
|
|
5142
|
+
runSubscriptionAbortRef: _
|
|
4409
5143
|
};
|
|
4410
5144
|
}
|
|
4411
5145
|
//#endregion
|
|
4412
|
-
export {
|
|
5146
|
+
export { Ze as S, ft as _, _n as a, Je as b, Ft as c, kt as d, St as f, pt as g, ht as h, ir as i, jt as l, vt as m, er as n, tn as o, yt as p, rr as r, zt as s, Sr as t, Mt as u, at as v, Xe as x, $e as y };
|