@kingsoftcloud/ksadk-web 0.3.7 → 0.3.9
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/RELEASE_PROVENANCE.json +2 -2
- package/dist-ksadk/assets/{ArtifactsPanel-CGbWlMNh.js → ArtifactsPanel-BPpNPGID.js} +1 -1
- package/dist-ksadk/assets/{CodeBlock-b4C7upmO.js → CodeBlock-Ds5vf0vb.js} +10 -7
- package/dist-ksadk/assets/MathMessageMarkdown-DiObfQyu.js +8 -0
- package/dist-ksadk/assets/{MermaidBlock-BEBN4Ksz.js → MermaidBlock-D7rbvY87.js} +9 -9
- package/dist-ksadk/assets/{NativeTerminalPanel-zvL-WpAn.js → NativeTerminalPanel-DU4dms0x.js} +1 -1
- package/dist-ksadk/assets/{abnfDiagram-VCTEODGH-BYafW7Za.js → abnfDiagram-VCTEODGH-CPEZNrp6.js} +1 -1
- package/dist-ksadk/assets/{arc-bTohInsS.js → arc-SmcBsmpk.js} +1 -1
- package/dist-ksadk/assets/architecture-7GRP2DOG-BB6Hc16V.js +1 -0
- package/dist-ksadk/assets/{architectureDiagram-5GKGNRK7-Ch5Lbzsi.js → architectureDiagram-5GKGNRK7-DczwkdRf.js} +1 -1
- package/dist-ksadk/assets/{blockDiagram-NRAW4CY4-kqF4MDOG.js → blockDiagram-NRAW4CY4-DOH-lQsK.js} +1 -1
- package/dist-ksadk/assets/{c4Diagram-UCG6FXSJ-8uSRIODv.js → c4Diagram-UCG6FXSJ-DDqa-d5a.js} +1 -1
- package/dist-ksadk/assets/channel-D_LgMO6N.js +1 -0
- package/dist-ksadk/assets/chunk-2Q5K7J3B-CzuaVSxD.js +1 -0
- package/dist-ksadk/assets/{chunk-5VM5RSS4-DkhehZDr.js → chunk-5VM5RSS4-BRbyQMbk.js} +1 -1
- package/dist-ksadk/assets/{chunk-F27PBJKO-BdXhtPe9.js → chunk-F27PBJKO-DC03vp6H.js} +1 -1
- package/dist-ksadk/assets/{chunk-G27WJ6UU-DPTpvpwi.js → chunk-G27WJ6UU-DsFJlOsn.js} +1 -1
- package/dist-ksadk/assets/{chunk-JWPE2WC7-Pqoh38el.js → chunk-JWPE2WC7-B03qL1Z_.js} +1 -1
- package/dist-ksadk/assets/{chunk-LCL6LL3I-DeU00qC-.js → chunk-LCL6LL3I-BbKJcRob.js} +1 -1
- package/dist-ksadk/assets/{chunk-POPQ4Y6H-CzxScFkr.js → chunk-POPQ4Y6H-B7_CA3-V.js} +1 -1
- package/dist-ksadk/assets/{chunk-RHFEMEQ7-DpqMx-ux.js → chunk-RHFEMEQ7-CEWTfYzF.js} +1 -1
- package/dist-ksadk/assets/{chunk-SVP7TREG-C6t0SypQ.js → chunk-SVP7TREG-C9e3delk.js} +1 -1
- package/dist-ksadk/assets/{chunk-XXDRQBXY-DVaeafZk.js → chunk-XXDRQBXY-_Ym5ccEC.js} +1 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-CZOWJyrI.js +1 -0
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-CZOWJyrI.js +1 -0
- package/dist-ksadk/assets/{cose-bilkent-JH36ORCC-Bf9D3tzJ.js → cose-bilkent-JH36ORCC-B6yMcByQ.js} +1 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-BBxC9wl_.js +1 -0
- package/dist-ksadk/assets/{cynefinDiagram-5FMLGOSQ-B9cY3iTz.js → cynefinDiagram-5FMLGOSQ-B1MVQxq-.js} +1 -1
- package/dist-ksadk/assets/{dagre-3AP2YEHR-CSwlx3CB.js → dagre-3AP2YEHR-LeImiTSm.js} +1 -1
- package/dist-ksadk/assets/{dagre-UBpgon5q.js → dagre-BUWpUaQH.js} +1 -1
- package/dist-ksadk/assets/{diagram-S7CK7UJ4-C9akhN9a.js → diagram-S7CK7UJ4-gvIKXdfF.js} +1 -1
- package/dist-ksadk/assets/{diagram-UQ7AKVKN-CgedhTPI.js → diagram-UQ7AKVKN-Bns2BbiH.js} +1 -1
- package/dist-ksadk/assets/{diagram-VSXAHHWV-Cjucz5BY.js → diagram-VSXAHHWV-OKsO2R1h.js} +1 -1
- package/dist-ksadk/assets/{diagram-VX7I27RA-Dd4Vleyn.js → diagram-VX7I27RA-pY0oKM38.js} +1 -1
- package/dist-ksadk/assets/{diagram-Z3DM3KII-CZ2jGtYW.js → diagram-Z3DM3KII-DohYTiXC.js} +1 -1
- package/dist-ksadk/assets/{dist-DFD6Qa6T.js → dist-8PQ_BKzp.js} +1 -1
- package/dist-ksadk/assets/{dist-BIr4DSRq.js → dist-BDJ_cEqg.js} +1 -1
- package/dist-ksadk/assets/{dist-ClYUxfeK.js → dist-BDZE5o1x.js} +1 -1
- package/dist-ksadk/assets/{dist-BnaTiyzN.js → dist-BFo1orBG.js} +1 -1
- package/dist-ksadk/assets/{dist-Bj730Ib4.js → dist-BHnyxINi.js} +1 -1
- package/dist-ksadk/assets/{dist-BgV_owcB.js → dist-BbwSdGXT.js} +1 -1
- package/dist-ksadk/assets/{dist-QfkEHOlb.js → dist-BoW8KUVe.js} +1 -1
- package/dist-ksadk/assets/{dist-D_ctSS2i.js → dist-CBw6QiWi.js} +1 -1
- package/dist-ksadk/assets/{dist-CB9iJrvg.js → dist-CNlBI6JB.js} +1 -1
- package/dist-ksadk/assets/{dist-C1NMAY5a.js → dist-CO7NxVj-.js} +1 -1
- package/dist-ksadk/assets/{dist-CFzsn6BG.js → dist-CR1wd2ZP.js} +1 -1
- package/dist-ksadk/assets/{dist-B3FR1SKK.js → dist-CfKVhXlF.js} +1 -1
- package/dist-ksadk/assets/{dist-DvFK7p5S.js → dist-CuGt0QN2.js} +1 -1
- package/dist-ksadk/assets/{dist-DiixqL0J.js → dist-DDzde0u0.js} +1 -1
- package/dist-ksadk/assets/{dist-DVCOWtha.js → dist-DP49CguF.js} +1 -1
- package/dist-ksadk/assets/dist-DTS11lPz.js +1 -0
- package/dist-ksadk/assets/{dist-Cf125P_m.js → dist-DUGnYv3Z.js} +1 -1
- package/dist-ksadk/assets/{dist-fBO2v5Kt.js → dist-DkIfde63.js} +1 -1
- package/dist-ksadk/assets/{dist-btbmmX5O.js → dist-JhK8apkX.js} +1 -1
- package/dist-ksadk/assets/{dist-DoVSwoDb.js → dist-XjCOh1mQ.js} +1 -1
- package/dist-ksadk/assets/{dist-ufY3F5p6.js → dist-axtMuC4Y.js} +2 -2
- package/dist-ksadk/assets/{dist-C5_ZAZsG.js → dist-vn-doe7c.js} +1 -1
- package/dist-ksadk/assets/{ebnfDiagram-PWID7BFC-Ci8NqqZu.js → ebnfDiagram-PWID7BFC-BzjnujnW.js} +1 -1
- package/dist-ksadk/assets/{erDiagram-SSCWMZ5O-CCIOhLZG.js → erDiagram-SSCWMZ5O-DdvSgpsK.js} +1 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV-Cp_KL3nY.js +1 -0
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-BPxElJOb.js +1 -0
- package/dist-ksadk/assets/{ganttDiagram-EL5Y4UJY-Cp_r9Hb6.js → ganttDiagram-EL5Y4UJY-lcb8scO2.js} +1 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-B8DHF0b5.js +1 -0
- package/dist-ksadk/assets/{gitGraphDiagram-WWUBYQGX-Dlhc8Wr8.js → gitGraphDiagram-WWUBYQGX-Cixie9K7.js} +1 -1
- package/dist-ksadk/assets/index-BumyuS0D.css +2 -0
- package/dist-ksadk/assets/index-DzVlSFGc.js +244 -0
- package/dist-ksadk/assets/info-A6RAGUB7-BDfMAVbQ.js +1 -0
- package/dist-ksadk/assets/{infoDiagram-RXCK75RN-CO0rRTRA.js → infoDiagram-RXCK75RN-CN3pHWLc.js} +1 -1
- package/dist-ksadk/assets/{ishikawaDiagram-5VMMS53U-CHiaedSS.js → ishikawaDiagram-5VMMS53U-C-Rld8v2.js} +1 -1
- package/dist-ksadk/assets/{journeyDiagram-EYS64GPL-CHcCIB09.js → journeyDiagram-EYS64GPL-BTrUK9qG.js} +1 -1
- package/dist-ksadk/assets/{kanban-definition-3QL26DDD-CJ_ebBZf.js → kanban-definition-3QL26DDD-CRf-REL4.js} +1 -1
- package/dist-ksadk/assets/{katex-B4weu383.js → katex-DBkN_1i8.js} +1 -1
- package/dist-ksadk/assets/{linear-V-MgYHW1.js → linear-DR0IfN-Q.js} +1 -1
- package/dist-ksadk/assets/{mermaid-parser.core-CBijEX_c.js → mermaid-parser.core-Ej-7BR0m.js} +2 -2
- package/dist-ksadk/assets/{mindmap-definition-FBJOCRG2-Bc-pQvpp.js → mindmap-definition-FBJOCRG2-BWL7ORVc.js} +1 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-27mP8Due.js +1 -0
- package/dist-ksadk/assets/{pegDiagram-XKGWAZYB-D7genGLl.js → pegDiagram-XKGWAZYB-CCTfQJ1W.js} +1 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-BZriQtXm.js +1 -0
- package/dist-ksadk/assets/{pieDiagram-E7YTZNPT-Bxj32zwD.js → pieDiagram-E7YTZNPT-BSOm4bnO.js} +1 -1
- package/dist-ksadk/assets/{quadrantDiagram-AXDQQJYC-BURv2mGh.js → quadrantDiagram-AXDQQJYC-BaQFiqoK.js} +1 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-DjxXwLPU.js +1 -0
- package/dist-ksadk/assets/railroad-74A4TZTK-C0dLiJCE.js +1 -0
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-CtFZAnrB.js +1 -0
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-BlqaBE1g.js +1 -0
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-xZlOtuT5.js +1 -0
- package/dist-ksadk/assets/{railroadDiagram-O6MQD6OU-CCsh3avW.js → railroadDiagram-O6MQD6OU-BzcGgAQa.js} +1 -1
- package/dist-ksadk/assets/{requirementDiagram-EFPCY7ZU-_FRRBKEd.js → requirementDiagram-EFPCY7ZU-BSW8FM0T.js} +1 -1
- package/dist-ksadk/assets/{sankeyDiagram-P5KCCOFB-C-gr2o9M.js → sankeyDiagram-P5KCCOFB-BtTDOHfw.js} +1 -1
- package/dist-ksadk/assets/{sequenceDiagram-WJ2MYXX4-D97NmfKg.js → sequenceDiagram-WJ2MYXX4-jXhWZPC6.js} +1 -1
- package/dist-ksadk/assets/{sizeCapture-X5ZJPWSS-DjrPC5FX.js → sizeCapture-X5ZJPWSS-Bi3ddJUw.js} +1 -1
- package/dist-ksadk/assets/{stateDiagram-HBIQ2CUA-DzMNg1hh.js → stateDiagram-HBIQ2CUA-BJZaCT2J.js} +1 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-De0kAogJ.js +1 -0
- package/dist-ksadk/assets/{swimlanes-XN3QIQJK-Cssf_CsU.js → swimlanes-XN3QIQJK-DnZwc2fl.js} +1 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-DY_Zfiw4.js +8 -0
- package/dist-ksadk/assets/{timeline-definition-24CTP7MA-BWTHzyS1.js → timeline-definition-24CTP7MA-BrunPeYF.js} +1 -1
- package/dist-ksadk/assets/treeView-Q6P3EWNA-Dn_GVxQ_.js +1 -0
- package/dist-ksadk/assets/treemap-WGGIJYW6-DMRNlrYS.js +1 -0
- package/dist-ksadk/assets/{vennDiagram-4TSXK5OY-BSKgJsmR.js → vennDiagram-4TSXK5OY-DGczjqRq.js} +1 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-B8DGIkoz.js +1 -0
- package/dist-ksadk/assets/{wardleyDiagram-VM6X3IG4-eflHNoaZ.js → wardleyDiagram-VM6X3IG4-B31kHkto.js} +1 -1
- package/dist-ksadk/assets/{xychartDiagram-S5SC5T6Z-eYqrQ-v4.js → xychartDiagram-S5SC5T6Z-CFGAbZRL.js} +1 -1
- package/dist-ksadk/index.html +2 -2
- package/dist-lib/{ArtifactsPanel-rz8e8OIc.js → ArtifactsPanel-DByDntRi.js} +1 -1
- package/dist-lib/{AttachmentPreview-CBpwnWxP.js → AttachmentPreview-tjd7Ufsh.js} +133 -292
- package/dist-lib/CodeBlock-DMIf4h33.js +213 -0
- package/dist-lib/{ConnectedComposer-DQ-yODJ-.js → ConnectedComposer-Cz5HKWFx.js} +322 -286
- package/dist-lib/{ConnectedMessageList-DfSvxYLL.js → ConnectedMessageList-CR6VIuLb.js} +476 -631
- package/dist-lib/ExecutionTree-v3HexvPo.js +277 -0
- package/dist-lib/FilePreviewModal-Cg8FoEGt.js +133 -0
- package/dist-lib/InteractionSchemaForm-BNoW5wzt.js +157 -0
- package/dist-lib/{MathMessageMarkdown-CBcDrAw-.js → MathMessageMarkdown-CfKpa9jm.js} +33 -33
- package/dist-lib/{MenuChip-So0XESNz.js → MenuChip-CT8v3QtQ.js} +1 -1
- package/dist-lib/MermaidBlock-H_0qzQDf.js +42 -0
- package/dist-lib/MessageMarkdown-D5yqDJ95.js +418 -0
- package/dist-lib/{NativeTerminalPanel-D2J75bIU.js → NativeTerminalPanel-beSt6mii.js} +1 -1
- package/dist-lib/{WorkspacePanelContainer-Q8Tt_oXe.js → WorkspacePanelContainer-jXNATcO4.js} +16 -16
- package/dist-lib/{a2ui-BVAet3qy.js → a2ui-BEQoW34n.js} +69 -70
- package/dist-lib/chat-composer.js +4 -4
- package/dist-lib/chat-timeline.js +4 -3
- package/dist-lib/clipboard-MB6Ru6h6.js +20 -0
- package/dist-lib/components/MessageMarkdown.d.ts.map +1 -1
- package/dist-lib/components/chat/ChatComposer.d.ts +4 -2
- package/dist-lib/components/chat/ChatComposer.d.ts.map +1 -1
- package/dist-lib/components/chat/ChatMessageList.d.ts +8 -1
- package/dist-lib/components/chat/ChatMessageList.d.ts.map +1 -1
- package/dist-lib/components/chat/ConnectedComposer.d.ts +9 -1
- package/dist-lib/components/chat/ConnectedComposer.d.ts.map +1 -1
- package/dist-lib/components/chat/ConnectedMessageList.d.ts +5 -1
- package/dist-lib/components/chat/ConnectedMessageList.d.ts.map +1 -1
- package/dist-lib/components/chat/ProcessingBlocksView.d.ts.map +1 -1
- package/dist-lib/components/chat/types.d.ts +8 -0
- package/dist-lib/components/chat/types.d.ts.map +1 -1
- package/dist-lib/components/markdown/CodeBlock.d.ts.map +1 -1
- package/dist-lib/components/markdown/MathMessageMarkdown.d.ts.map +1 -1
- package/dist-lib/components/markdown/MermaidBlock.d.ts.map +1 -1
- package/dist-lib/components/teams/CreateGroupDialog.d.ts +21 -0
- package/dist-lib/components/teams/CreateGroupDialog.d.ts.map +1 -0
- package/dist-lib/components/teams/ExecutionTree.d.ts +24 -0
- package/dist-lib/components/teams/ExecutionTree.d.ts.map +1 -0
- package/dist-lib/components/teams/InteractionMessage.d.ts +4 -0
- package/dist-lib/components/teams/InteractionMessage.d.ts.map +1 -0
- package/dist-lib/components/teams/TeamReconciliation.d.ts +9 -0
- package/dist-lib/components/teams/TeamReconciliation.d.ts.map +1 -0
- package/dist-lib/components/teams/TeamWorkspace.d.ts +110 -0
- package/dist-lib/components/teams/TeamWorkspace.d.ts.map +1 -0
- package/dist-lib/components/workspace/FilePreviewModal.d.ts +21 -0
- package/dist-lib/components/workspace/FilePreviewModal.d.ts.map +1 -0
- package/dist-lib/components.js +34 -32
- package/dist-lib/conversation.js +198 -5
- package/dist-lib/core/conversation/history-search.d.ts +33 -0
- package/dist-lib/core/conversation/history-search.d.ts.map +1 -0
- package/dist-lib/core/conversation/hosted.d.ts +1 -1
- package/dist-lib/core/conversation/hosted.d.ts.map +1 -1
- package/dist-lib/core/conversation/index.d.ts +1 -0
- package/dist-lib/core/conversation/index.d.ts.map +1 -1
- package/dist-lib/core/conversation/presentation.d.ts.map +1 -1
- package/dist-lib/core/conversation/projection-store.d.ts +25 -0
- package/dist-lib/core/conversation/projection-store.d.ts.map +1 -0
- package/dist-lib/core/conversation/session-facade.d.ts +136 -0
- package/dist-lib/core/conversation/session-facade.d.ts.map +1 -0
- package/dist-lib/core/conversation/studio-controller.d.ts +143 -0
- package/dist-lib/core/conversation/studio-controller.d.ts.map +1 -0
- package/dist-lib/core/conversation/types.d.ts +8 -0
- package/dist-lib/core/conversation/types.d.ts.map +1 -1
- package/dist-lib/core/run/blocks.d.ts +2 -0
- package/dist-lib/core/run/blocks.d.ts.map +1 -1
- package/dist-lib/core/run/dispatcher.d.ts +4 -1
- package/dist-lib/core/run/dispatcher.d.ts.map +1 -1
- package/dist-lib/core/run/engine.d.ts +22 -6
- package/dist-lib/core/run/engine.d.ts.map +1 -1
- package/dist-lib/core/run/index.d.ts +1 -1
- package/dist-lib/core/run/index.d.ts.map +1 -1
- package/dist-lib/core/run/types.d.ts +8 -3
- package/dist-lib/core/run/types.d.ts.map +1 -1
- package/dist-lib/core/teams/client.d.ts +106 -0
- package/dist-lib/core/teams/client.d.ts.map +1 -0
- package/dist-lib/core/teams/contracts.d.ts +827 -0
- package/dist-lib/core/teams/contracts.d.ts.map +1 -0
- package/dist-lib/core/teams/grouping.d.ts +5 -0
- package/dist-lib/core/teams/grouping.d.ts.map +1 -0
- package/dist-lib/core/teams/observer.d.ts +52 -0
- package/dist-lib/core/teams/observer.d.ts.map +1 -0
- package/dist-lib/core/teams/presentation.d.ts +17 -0
- package/dist-lib/core/teams/presentation.d.ts.map +1 -0
- package/dist-lib/core/teams/reducer.d.ts +13 -0
- package/dist-lib/core/teams/reducer.d.ts.map +1 -0
- package/dist-lib/core/teams/types.d.ts +362 -0
- package/dist-lib/core/teams/types.d.ts.map +1 -0
- package/dist-lib/{feedback-D256P415.js → feedback-CuC5jRi_.js} +88 -84
- package/dist-lib/file-preview.js +3 -0
- package/dist-lib/history-search-CBd9v7MY.js +58 -0
- package/dist-lib/hooks/useAgentChat.d.ts +22 -1
- package/dist-lib/hooks/useAgentChat.d.ts.map +1 -1
- package/dist-lib/hooks/useRunAgent.d.ts +9 -4
- package/dist-lib/hooks/useRunAgent.d.ts.map +1 -1
- package/dist-lib/hooks/useSessionLifecycle.d.ts +13 -2
- package/dist-lib/hooks/useSessionLifecycle.d.ts.map +1 -1
- package/dist-lib/hooks/useTeamChat.d.ts +17 -0
- package/dist-lib/hooks/useTeamChat.d.ts.map +1 -0
- package/dist-lib/hooks.js +240 -140
- package/dist-lib/{permission--lxoX90f.js → permission-CcMWqN8Y.js} +1 -1
- package/dist-lib/{persisted-session-history-Bb3ScKrL.js → persisted-session-history-ClsfDfGs.js} +365 -604
- package/dist-lib/presentation-yYw7xK60.js +53 -0
- package/dist-lib/public/components.d.ts +3 -0
- package/dist-lib/public/components.d.ts.map +1 -1
- package/dist-lib/public/conversation.d.ts +8 -0
- package/dist-lib/public/conversation.d.ts.map +1 -1
- package/dist-lib/public/file-preview.d.ts +4 -0
- package/dist-lib/public/file-preview.d.ts.map +1 -0
- package/dist-lib/public/runtime.d.ts +1 -1
- package/dist-lib/public/runtime.d.ts.map +1 -1
- package/dist-lib/public/team-components.d.ts +4 -0
- package/dist-lib/public/team-components.d.ts.map +1 -0
- package/dist-lib/public/team-execution.d.ts +3 -0
- package/dist-lib/public/team-execution.d.ts.map +1 -0
- package/dist-lib/public/teams.d.ts +8 -0
- package/dist-lib/public/teams.d.ts.map +1 -0
- package/dist-lib/reducer-BP8YVv-Q.js +270 -0
- package/dist-lib/reducer-gQmR9Qb9.js +424 -0
- package/dist-lib/runtime.js +35 -34
- package/dist-lib/stores/streaming.d.ts +3 -1
- package/dist-lib/stores/streaming.d.ts.map +1 -1
- package/dist-lib/studio-controller-jBKN9hmp.js +422 -0
- package/dist-lib/styles.css +1 -1
- package/dist-lib/team-components.js +2033 -0
- package/dist-lib/team-execution.js +2 -0
- package/dist-lib/teams.css +429 -0
- package/dist-lib/teams.js +357 -0
- package/dist-lib/types/agent-control.d.ts.map +1 -1
- package/dist-lib/types/capabilities.d.ts +6 -0
- package/dist-lib/types/capabilities.d.ts.map +1 -1
- package/dist-lib/{useSessionLifecycle-DQCw8YmE.js → useSessionLifecycle-DQXKeBm9.js} +1221 -1025
- package/dist-lib/utils/persisted-session-history.d.ts.map +1 -1
- package/dist-lib/utils/session-events.d.ts.map +1 -1
- package/dist-lib/utils/workspace-file-paths.d.ts +14 -0
- package/dist-lib/utils/workspace-file-paths.d.ts.map +1 -0
- package/dist-lib/utils/workspace-file-preview-bus.d.ts +4 -0
- package/dist-lib/utils/workspace-file-preview-bus.d.ts.map +1 -0
- package/dist-lib/utils-CX-Pz5p6.js +8 -0
- package/package.json +24 -3
- package/schemas/teams-v1-execution-snapshot.schema.json +197 -0
- package/schemas/teams-v1-group-event.schema.json +53 -0
- package/schemas/teams-v1-group-snapshot.schema.json +1464 -0
- package/schemas/teams-v1-interaction-ref.schema.json +64 -0
- package/dist-ksadk/assets/MathMessageMarkdown-DbdW5A4_.js +0 -8
- package/dist-ksadk/assets/architecture-7GRP2DOG-BW5UtSnx.js +0 -1
- package/dist-ksadk/assets/channel-CF5Up3hQ.js +0 -1
- package/dist-ksadk/assets/chunk-2Q5K7J3B-KkXX47WI.js +0 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-Cz81acRQ.js +0 -1
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-Cz81acRQ.js +0 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-DVWs8a2t.js +0 -1
- package/dist-ksadk/assets/dist-B2_CVgKv.js +0 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV-CQqR2hg3.js +0 -1
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-DDRRbGPm.js +0 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-fgWEf7UD.js +0 -1
- package/dist-ksadk/assets/index-DcTML1Up.css +0 -2
- package/dist-ksadk/assets/index-Dh2XHqPK.js +0 -244
- package/dist-ksadk/assets/info-A6RAGUB7-BUecLTdt.js +0 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-BeW-btFv.js +0 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-X0xh4SaT.js +0 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-DzRMSqjd.js +0 -1
- package/dist-ksadk/assets/railroad-74A4TZTK-Cc44icX-.js +0 -1
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-D6S4BdV-.js +0 -1
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-vD3aVE2o.js +0 -1
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-CYbW_b4T.js +0 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-BIcjKFhF.js +0 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-tq3K3Ybl.js +0 -8
- package/dist-ksadk/assets/treeView-Q6P3EWNA-DBXt3GdU.js +0 -1
- package/dist-ksadk/assets/treemap-WGGIJYW6-DrCy4E_l.js +0 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-CefhOliM.js +0 -1
- package/dist-lib/CodeBlock-DCUUY0PL.js +0 -113
- package/dist-lib/MermaidBlock-DBFTztfQ.js +0 -35
|
@@ -1,51 +1,52 @@
|
|
|
1
1
|
import { a as e, i as t, o as n, t as r } from "./capabilities-CXle1R-K.js";
|
|
2
|
-
import {
|
|
3
|
-
import { n as
|
|
4
|
-
import { a as
|
|
2
|
+
import { a as i, d as a, f as o, g as s, h as c, i as l, m as u, n as d, o as f, p, s as m, t as h } from "./a2ui-BEQoW34n.js";
|
|
3
|
+
import { n as g } from "./runtime-items-q6tMjfGU.js";
|
|
4
|
+
import { a as _, c as v, i as y, l as b, n as x, o as S, r as C, s as w, t as T, u as E } from "./feedback-CuC5jRi_.js";
|
|
5
5
|
import { n as D } from "./tool-display-DTiRdghE.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
6
|
+
import { c as O, i as k, l as A, u as j } from "./reducer-BP8YVv-Q.js";
|
|
7
|
+
import { _ as M, a as ee, b as N, c as P, d as F, f as I, g as te, h as ne, i as re, l as ie, m as ae, n as oe, o as se, p as ce, r as le, s as ue, u as de, v as fe, y as pe } from "./persisted-session-history-ClsfDfGs.js";
|
|
8
|
+
import { useCallback as L, useEffect as R, useMemo as me, useRef as z, useState as he } from "react";
|
|
9
|
+
import { create as ge } from "zustand";
|
|
10
|
+
import { z as B } from "zod";
|
|
11
|
+
import { HttpAgent as _e, buildResumeArray as ve } from "@ag-ui/client";
|
|
11
12
|
//#region src/api/client.ts
|
|
12
|
-
var
|
|
13
|
+
var V = class extends Error {
|
|
13
14
|
code;
|
|
14
15
|
detail;
|
|
15
16
|
constructor(e, t, n) {
|
|
16
17
|
super(t), this.name = "ApiError", this.code = e, this.detail = n;
|
|
17
18
|
}
|
|
18
|
-
},
|
|
19
|
+
}, H = class extends Error {
|
|
19
20
|
constructor(e = "请求已取消") {
|
|
20
21
|
super(e), this.name = "CancelledError";
|
|
21
22
|
}
|
|
22
|
-
},
|
|
23
|
-
async function
|
|
23
|
+
}, ye = "/agentengine/api/v1";
|
|
24
|
+
async function be(e) {
|
|
24
25
|
let t = await e.text(), n = {};
|
|
25
26
|
try {
|
|
26
27
|
n = t ? JSON.parse(t) : {};
|
|
27
28
|
} catch {
|
|
28
29
|
let n = e.headers.get("content-type")?.toLowerCase() || "";
|
|
29
|
-
if ((e.status === 401 || e.status === 403) && (n.includes("text/html") || t.trimStart().startsWith("<"))) throw new
|
|
30
|
+
if ((e.status === 401 || e.status === 403) && (n.includes("text/html") || t.trimStart().startsWith("<"))) throw new V(e.status, "访问会话已失效,请从 Dashboard 或 Studio 的云端会话重新打开 Agent。");
|
|
30
31
|
if (!e.ok) {
|
|
31
32
|
let n = t.trim();
|
|
32
|
-
throw new
|
|
33
|
+
throw new V(e.status, n && n.length <= 256 && !n.startsWith("<") ? n : e.statusText || `HTTP ${e.status}`, t);
|
|
33
34
|
}
|
|
34
|
-
throw new
|
|
35
|
+
throw new V(-2, "响应格式异常");
|
|
35
36
|
}
|
|
36
|
-
if (!e.ok) throw new
|
|
37
|
-
if (n?.Code !== void 0 && n.Code !== 0) throw new
|
|
37
|
+
if (!e.ok) throw new V(e.status, n?.Message || `HTTP ${e.status}`, n);
|
|
38
|
+
if (n?.Code !== void 0 && n.Code !== 0) throw new V(n.Code, n.Message || "请求失败", n);
|
|
38
39
|
return n.Data;
|
|
39
40
|
}
|
|
40
|
-
function
|
|
41
|
-
throw e instanceof DOMException && e.name === "AbortError" ? new
|
|
41
|
+
function xe(e) {
|
|
42
|
+
throw e instanceof DOMException && e.name === "AbortError" ? new H() : e;
|
|
42
43
|
}
|
|
43
|
-
var
|
|
44
|
+
var Se = class {
|
|
44
45
|
fetcher;
|
|
45
46
|
baseUrl;
|
|
46
47
|
agentId;
|
|
47
48
|
constructor(e = {}) {
|
|
48
|
-
this.fetcher = e.fetch || ((e, t) => globalThis.fetch(e, t)), this.baseUrl = String(e.baseUrl ||
|
|
49
|
+
this.fetcher = e.fetch || ((e, t) => globalThis.fetch(e, t)), this.baseUrl = String(e.baseUrl || ye).replace(/\/+$/, ""), this.agentId = String(e.agentId || "").trim();
|
|
49
50
|
}
|
|
50
51
|
actionUrl(e) {
|
|
51
52
|
return `${this.baseUrl}/${e}`;
|
|
@@ -66,9 +67,9 @@ var Ce = class {
|
|
|
66
67
|
signal: n?.signal
|
|
67
68
|
});
|
|
68
69
|
} catch (e) {
|
|
69
|
-
throw
|
|
70
|
+
throw xe(e);
|
|
70
71
|
}
|
|
71
|
-
return
|
|
72
|
+
return be(r);
|
|
72
73
|
}
|
|
73
74
|
async postFormAction(e, t, n) {
|
|
74
75
|
let r;
|
|
@@ -80,9 +81,9 @@ var Ce = class {
|
|
|
80
81
|
signal: n?.signal
|
|
81
82
|
});
|
|
82
83
|
} catch (e) {
|
|
83
|
-
throw
|
|
84
|
+
throw xe(e);
|
|
84
85
|
}
|
|
85
|
-
return
|
|
86
|
+
return be(r);
|
|
86
87
|
}
|
|
87
88
|
async getResource(e, t, n) {
|
|
88
89
|
let r = this.agentId && !t.AgentId ? {
|
|
@@ -92,13 +93,13 @@ var Ce = class {
|
|
|
92
93
|
try {
|
|
93
94
|
o = await this.fetcher(a, { signal: n?.signal });
|
|
94
95
|
} catch (e) {
|
|
95
|
-
throw
|
|
96
|
+
throw xe(e);
|
|
96
97
|
}
|
|
97
|
-
if (!o.ok) throw new
|
|
98
|
+
if (!o.ok) throw new V(o.status, `资源获取失败: ${o.statusText}`);
|
|
98
99
|
try {
|
|
99
100
|
return n?.asText ? await o.text() : await o.blob();
|
|
100
101
|
} catch {
|
|
101
|
-
throw new
|
|
102
|
+
throw new V(-3, "文件读取失败");
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
async streamAction(e, t, n) {
|
|
@@ -114,10 +115,10 @@ var Ce = class {
|
|
|
114
115
|
signal: n?.signal
|
|
115
116
|
});
|
|
116
117
|
} catch (e) {
|
|
117
|
-
throw
|
|
118
|
+
throw xe(e);
|
|
118
119
|
}
|
|
119
|
-
if (!r.ok) throw await
|
|
120
|
-
if ((r.headers.get("content-type")?.toLowerCase() || "").includes("application/json") && await
|
|
120
|
+
if (!r.ok) throw await be(r), new V(r.status, `流式请求失败: ${r.statusText}`);
|
|
121
|
+
if ((r.headers.get("content-type")?.toLowerCase() || "").includes("application/json") && await be(r.clone()), !r.body) throw new V(-1, "无法获取响应流");
|
|
121
122
|
return r.body;
|
|
122
123
|
}
|
|
123
124
|
async streamGetAction(e, t, n) {
|
|
@@ -131,17 +132,17 @@ var Ce = class {
|
|
|
131
132
|
signal: n?.signal
|
|
132
133
|
});
|
|
133
134
|
} catch (e) {
|
|
134
|
-
throw
|
|
135
|
+
throw xe(e);
|
|
135
136
|
}
|
|
136
|
-
if (!o.ok) throw new
|
|
137
|
-
if (!o.body) throw new
|
|
137
|
+
if (!o.ok) throw new V(o.status, `流式订阅失败: ${o.statusText}`);
|
|
138
|
+
if (!o.body) throw new V(-1, "无法获取响应流");
|
|
138
139
|
return o.body;
|
|
139
140
|
}
|
|
140
|
-
},
|
|
141
|
+
}, Ce = new Se(), we = (e, t, n) => Ce.streamAction(e, t, n), Te = (e, t, n) => Ce.streamGetAction(e, t, n), U = class extends Error {
|
|
141
142
|
constructor(e) {
|
|
142
143
|
super(e), this.name = "ContractMismatchError";
|
|
143
144
|
}
|
|
144
|
-
},
|
|
145
|
+
}, Ee = new Set([
|
|
145
146
|
"schema_version",
|
|
146
147
|
"command_id",
|
|
147
148
|
"status",
|
|
@@ -149,17 +150,17 @@ var Ce = class {
|
|
|
149
150
|
"run_id",
|
|
150
151
|
"accepted_seq",
|
|
151
152
|
"error"
|
|
152
|
-
]),
|
|
153
|
-
code:
|
|
154
|
-
message:
|
|
155
|
-
retryable:
|
|
156
|
-
details:
|
|
153
|
+
]), De = B.object({
|
|
154
|
+
code: B.string().min(1),
|
|
155
|
+
message: B.string(),
|
|
156
|
+
retryable: B.boolean(),
|
|
157
|
+
details: B.record(B.string(), B.unknown()).optional()
|
|
157
158
|
});
|
|
158
|
-
function
|
|
159
|
-
let t =
|
|
160
|
-
schema_version:
|
|
161
|
-
command_id:
|
|
162
|
-
status:
|
|
159
|
+
function Oe(e) {
|
|
160
|
+
let t = B.object({
|
|
161
|
+
schema_version: B.literal(1),
|
|
162
|
+
command_id: B.string().min(1),
|
|
163
|
+
status: B.enum([
|
|
163
164
|
"accepted",
|
|
164
165
|
"duplicate",
|
|
165
166
|
"rejected",
|
|
@@ -167,16 +168,16 @@ function U(e) {
|
|
|
167
168
|
"queue_full",
|
|
168
169
|
"persistence_uncertain"
|
|
169
170
|
]),
|
|
170
|
-
message_id:
|
|
171
|
-
run_id:
|
|
172
|
-
accepted_seq:
|
|
173
|
-
error:
|
|
171
|
+
message_id: B.string().min(1).nullable().optional(),
|
|
172
|
+
run_id: B.string().min(1).nullable().optional(),
|
|
173
|
+
accepted_seq: B.number().int().min(0).nullable().optional(),
|
|
174
|
+
error: De.nullable().optional()
|
|
174
175
|
}).passthrough().safeParse(e);
|
|
175
|
-
if (!t.success) throw new
|
|
176
|
+
if (!t.success) throw new U(`AgentControlReceipt/v1 mismatch: ${t.error.message}`);
|
|
176
177
|
let n = t.data;
|
|
177
|
-
if ((n.status === "rejected" || n.status === "unsupported" || n.status === "queue_full" || n.status === "persistence_uncertain") && !n.error) throw new
|
|
178
|
+
if ((n.status === "rejected" || n.status === "unsupported" || n.status === "queue_full" || n.status === "persistence_uncertain") && !n.error) throw new U(`AgentControlReceipt/v1 mismatch: status ${n.status} requires error`);
|
|
178
179
|
let r = {};
|
|
179
|
-
for (let [e, t] of Object.entries(n))
|
|
180
|
+
for (let [e, t] of Object.entries(n)) Ee.has(e) || (r[e] = t);
|
|
180
181
|
let i = n.error ? {
|
|
181
182
|
...n.error,
|
|
182
183
|
extensions: {}
|
|
@@ -196,7 +197,7 @@ function ke(e) {
|
|
|
196
197
|
try {
|
|
197
198
|
return n(e);
|
|
198
199
|
} catch (e) {
|
|
199
|
-
throw new
|
|
200
|
+
throw new U(`RuntimeCapabilityMatrix/v1 mismatch: ${e instanceof Error ? e.message : String(e)}`);
|
|
200
201
|
}
|
|
201
202
|
}
|
|
202
203
|
var Ae = new Set([
|
|
@@ -213,31 +214,62 @@ var Ae = new Set([
|
|
|
213
214
|
"causation_id",
|
|
214
215
|
"correlation_id",
|
|
215
216
|
"actor_ref"
|
|
216
|
-
]), je = new Map([["control", 1], ["runtime", 2]]), Me =
|
|
217
|
-
schema_version:
|
|
218
|
-
event_id:
|
|
219
|
-
session_id:
|
|
220
|
-
seq:
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
217
|
+
]), je = new Map([["control", 1], ["runtime", 2]]), Me = {
|
|
218
|
+
schema_version: ["schemaVersion", "SchemaVersion"],
|
|
219
|
+
event_id: ["eventId", "EventId"],
|
|
220
|
+
session_id: ["sessionId", "SessionId"],
|
|
221
|
+
seq: [
|
|
222
|
+
"seqId",
|
|
223
|
+
"SeqId",
|
|
224
|
+
"Seq"
|
|
225
|
+
],
|
|
226
|
+
timestamp: ["Timestamp"],
|
|
227
|
+
family: ["Family"],
|
|
228
|
+
family_version: ["familyVersion", "FamilyVersion"],
|
|
229
|
+
event_type: ["eventType", "EventType"],
|
|
230
|
+
payload: ["Payload"],
|
|
231
|
+
run_id: ["runId", "RunId"],
|
|
232
|
+
causation_id: ["causationId", "CausationId"],
|
|
233
|
+
correlation_id: ["correlationId", "CorrelationId"],
|
|
234
|
+
actor_ref: ["actorRef", "ActorRef"]
|
|
235
|
+
};
|
|
231
236
|
function Ne(e) {
|
|
232
|
-
|
|
237
|
+
if (!e || typeof e != "object" || Array.isArray(e)) return e;
|
|
238
|
+
let t = e, n = { ...t };
|
|
239
|
+
for (let [e, r] of Object.entries(Me)) {
|
|
240
|
+
if (n[e] === void 0) {
|
|
241
|
+
let i = r.find((e) => t[e] !== void 0);
|
|
242
|
+
i && (n[e] = t[i]);
|
|
243
|
+
}
|
|
244
|
+
for (let e of r) delete n[e];
|
|
245
|
+
}
|
|
246
|
+
return n;
|
|
247
|
+
}
|
|
248
|
+
var Pe = B.object({
|
|
249
|
+
schema_version: B.literal(1),
|
|
250
|
+
event_id: B.string().min(1),
|
|
251
|
+
session_id: B.string().min(1),
|
|
252
|
+
seq: B.number().int().min(0),
|
|
253
|
+
timestamp: B.string().min(1),
|
|
254
|
+
family: B.string().min(1),
|
|
255
|
+
family_version: B.number().int().min(1),
|
|
256
|
+
event_type: B.string().min(1),
|
|
257
|
+
payload: B.record(B.string(), B.unknown()),
|
|
258
|
+
run_id: B.string().min(1).nullable().optional(),
|
|
259
|
+
causation_id: B.string().min(1).nullable().optional(),
|
|
260
|
+
correlation_id: B.string().min(1).nullable().optional(),
|
|
261
|
+
actor_ref: B.string().min(1).nullable().optional()
|
|
262
|
+
}).passthrough();
|
|
263
|
+
function Fe(e) {
|
|
264
|
+
let t = Pe.safeParse(Ne(e));
|
|
233
265
|
if (!t.success) return {
|
|
234
266
|
ok: !1,
|
|
235
|
-
error: new
|
|
267
|
+
error: new U(`SessionEventEnvelope/v1 mismatch: ${t.error.message}`)
|
|
236
268
|
};
|
|
237
269
|
let n = t.data, r = je.get(n.family);
|
|
238
270
|
if (r !== void 0 && n.family_version !== r) return {
|
|
239
271
|
ok: !1,
|
|
240
|
-
error: new
|
|
272
|
+
error: new U(`SessionEventEnvelope/v1 mismatch: family ${n.family} requires family_version ${r}`)
|
|
241
273
|
};
|
|
242
274
|
let i = {};
|
|
243
275
|
for (let [e, t] of Object.entries(n)) Ae.has(e) || (i[e] = t);
|
|
@@ -261,29 +293,29 @@ function Ne(e) {
|
|
|
261
293
|
}
|
|
262
294
|
};
|
|
263
295
|
}
|
|
264
|
-
function
|
|
265
|
-
let t =
|
|
266
|
-
schema_version:
|
|
267
|
-
agent_instance_id:
|
|
268
|
-
instance_state:
|
|
296
|
+
function Ie(e) {
|
|
297
|
+
let t = B.object({
|
|
298
|
+
schema_version: B.literal(1),
|
|
299
|
+
agent_instance_id: B.string().min(1),
|
|
300
|
+
instance_state: B.enum([
|
|
269
301
|
"ready",
|
|
270
302
|
"degraded",
|
|
271
303
|
"unavailable"
|
|
272
304
|
]),
|
|
273
|
-
session_id:
|
|
274
|
-
active_run_id:
|
|
275
|
-
active_run_state:
|
|
305
|
+
session_id: B.string().min(1).nullable().optional(),
|
|
306
|
+
active_run_id: B.string().min(1).nullable().optional(),
|
|
307
|
+
active_run_state: B.enum([
|
|
276
308
|
"pending",
|
|
277
309
|
"running",
|
|
278
310
|
"paused",
|
|
279
311
|
"waiting"
|
|
280
312
|
]).nullable().optional(),
|
|
281
|
-
inbox_depth:
|
|
282
|
-
activation_id:
|
|
283
|
-
lease_expires_at:
|
|
284
|
-
capability:
|
|
313
|
+
inbox_depth: B.number().int().min(0),
|
|
314
|
+
activation_id: B.string().min(1).nullable().optional(),
|
|
315
|
+
lease_expires_at: B.string().min(1).nullable().optional(),
|
|
316
|
+
capability: B.unknown()
|
|
285
317
|
}).passthrough().safeParse(e);
|
|
286
|
-
if (!t.success) throw new
|
|
318
|
+
if (!t.success) throw new U(`AgentStatusSnapshot/v1 mismatch: ${t.error.message}`);
|
|
287
319
|
let n = t.data, r = {};
|
|
288
320
|
for (let e of Object.keys(n)) [
|
|
289
321
|
"schema_version",
|
|
@@ -313,10 +345,10 @@ function Pe(e) {
|
|
|
313
345
|
}
|
|
314
346
|
//#endregion
|
|
315
347
|
//#region src/core/api/facade.ts
|
|
316
|
-
var
|
|
348
|
+
var Le = class {
|
|
317
349
|
client;
|
|
318
350
|
constructor(e = {}) {
|
|
319
|
-
this.client = new
|
|
351
|
+
this.client = new Se(e);
|
|
320
352
|
}
|
|
321
353
|
async compactSession(e, t) {
|
|
322
354
|
return this.client.postJsonAction("CompactSession", {
|
|
@@ -423,14 +455,14 @@ var Fe = class {
|
|
|
423
455
|
}, t);
|
|
424
456
|
}
|
|
425
457
|
async submitControl(e, t) {
|
|
426
|
-
return
|
|
458
|
+
return Oe(await this.client.postJsonAction("SubmitAgentControl", {
|
|
427
459
|
CommandType: e.command_type,
|
|
428
460
|
IdempotencyKey: e.idempotency_key,
|
|
429
461
|
Payload: e.payload
|
|
430
462
|
}, t));
|
|
431
463
|
}
|
|
432
464
|
async submitInteraction(e, t) {
|
|
433
|
-
return
|
|
465
|
+
return Oe(await this.client.postJsonAction("SubmitInteraction", { ...e }, t));
|
|
434
466
|
}
|
|
435
467
|
async getAgentStatus(e) {
|
|
436
468
|
return this.client.postJsonAction("GetAgentStatus", {}, e);
|
|
@@ -476,7 +508,7 @@ var Fe = class {
|
|
|
476
508
|
async getWorkspaceFileContent(e, t, n) {
|
|
477
509
|
return this.client.getResource("GetWorkspaceFileContent", {
|
|
478
510
|
AgentId: e,
|
|
479
|
-
|
|
511
|
+
FilePath: t
|
|
480
512
|
}, n);
|
|
481
513
|
}
|
|
482
514
|
async listAgentModels(e, t) {
|
|
@@ -488,7 +520,7 @@ var Fe = class {
|
|
|
488
520
|
async uploadFile(e, t) {
|
|
489
521
|
return this.client.postFormAction("UploadFile", e, t);
|
|
490
522
|
}
|
|
491
|
-
}, W =
|
|
523
|
+
}, W = ge()((e) => ({
|
|
492
524
|
agentId: "default-agent",
|
|
493
525
|
agentName: "Agent",
|
|
494
526
|
agentFramework: "",
|
|
@@ -509,34 +541,34 @@ var Fe = class {
|
|
|
509
541
|
status: t,
|
|
510
542
|
errorMessage: n
|
|
511
543
|
})
|
|
512
|
-
})),
|
|
513
|
-
function
|
|
544
|
+
})), Re = "ksadk:webui:selected-session:";
|
|
545
|
+
function ze(e) {
|
|
514
546
|
return String(e || "").trim() || "default-agent";
|
|
515
547
|
}
|
|
516
|
-
function
|
|
548
|
+
function Be(e) {
|
|
517
549
|
if (e && typeof e.getItem == "function") return e;
|
|
518
550
|
try {
|
|
519
551
|
if (typeof window < "u" && window.localStorage) return window.localStorage;
|
|
520
552
|
} catch {}
|
|
521
553
|
return null;
|
|
522
554
|
}
|
|
523
|
-
function
|
|
524
|
-
return
|
|
555
|
+
function Ve(e) {
|
|
556
|
+
return p.key(`${Re}${ze(e)}`);
|
|
525
557
|
}
|
|
526
|
-
function
|
|
527
|
-
let n =
|
|
558
|
+
function He(e, t) {
|
|
559
|
+
let n = Be(t);
|
|
528
560
|
if (!n) return null;
|
|
529
561
|
try {
|
|
530
|
-
return String(n.getItem(
|
|
562
|
+
return String(n.getItem(Ve(e)) || "").trim() || null;
|
|
531
563
|
} catch {
|
|
532
564
|
return null;
|
|
533
565
|
}
|
|
534
566
|
}
|
|
535
|
-
function
|
|
536
|
-
if (!
|
|
537
|
-
let r =
|
|
567
|
+
function Ue(e, t, n) {
|
|
568
|
+
if (!p.writable) return;
|
|
569
|
+
let r = Be(n);
|
|
538
570
|
if (!r) return;
|
|
539
|
-
let i =
|
|
571
|
+
let i = Ve(e), a = String(t || "").trim();
|
|
540
572
|
try {
|
|
541
573
|
if (a) {
|
|
542
574
|
r.setItem(i, a);
|
|
@@ -545,7 +577,7 @@ function Ve(e, t, n) {
|
|
|
545
577
|
r.removeItem(i);
|
|
546
578
|
} catch {}
|
|
547
579
|
}
|
|
548
|
-
function
|
|
580
|
+
function We(e, t) {
|
|
549
581
|
if (!Array.isArray(e) || e.length === 0) return null;
|
|
550
582
|
let n = String(t || "").trim();
|
|
551
583
|
if (n && e.some((e) => String(e?.SessionId || "").trim() === n)) return n;
|
|
@@ -555,7 +587,7 @@ function He(e, t) {
|
|
|
555
587
|
}
|
|
556
588
|
return null;
|
|
557
589
|
}
|
|
558
|
-
function
|
|
590
|
+
function Ge(e, t, n) {
|
|
559
591
|
let r = Array.isArray(e) ? e : [], i = Array.isArray(t) ? t : [], a = n instanceof Set ? n : new Set(Array.isArray(n) ? n : []);
|
|
560
592
|
if (a.size === 0) return r;
|
|
561
593
|
let o = new Set(r.map((e) => String(e?.SessionId || "").trim()).filter(Boolean)), s = i.filter((e) => {
|
|
@@ -566,71 +598,71 @@ function Ue(e, t, n) {
|
|
|
566
598
|
}
|
|
567
599
|
//#endregion
|
|
568
600
|
//#region src/hooks/useBootstrap.ts
|
|
569
|
-
function
|
|
570
|
-
return e instanceof
|
|
601
|
+
function Ke(e) {
|
|
602
|
+
return e instanceof V && (e.code === 401 || e.code === 403) ? "auth-required" : "error";
|
|
571
603
|
}
|
|
572
|
-
function
|
|
604
|
+
function qe(e) {
|
|
573
605
|
if (!Array.isArray(e)) return ["responses", "chat_completions"];
|
|
574
606
|
let t = e.filter((e) => e === "responses" || e === "chat_completions");
|
|
575
607
|
return t.length > 0 ? t : ["responses", "chat_completions"];
|
|
576
608
|
}
|
|
577
|
-
var
|
|
578
|
-
async function
|
|
609
|
+
var Je = new Le();
|
|
610
|
+
async function Ye(e, t = Je) {
|
|
579
611
|
try {
|
|
580
612
|
let n = await t.listAgentModels(e), r = n?.Models;
|
|
581
|
-
Array.isArray(r) &&
|
|
613
|
+
Array.isArray(r) && u.getState().upsertModels(r);
|
|
582
614
|
let i = n;
|
|
583
|
-
i?.Current && !
|
|
615
|
+
i?.Current && !u.getState().selectedModel && u.getState().setSelectedModel(String(i.Current)), i?.Source && u.getState().setModelSource(String(i.Source));
|
|
584
616
|
} catch (e) {
|
|
585
617
|
console.error("Failed to fetch models:", e);
|
|
586
618
|
} finally {
|
|
587
|
-
|
|
619
|
+
u.getState().setModelCatalogLoaded(!0);
|
|
588
620
|
}
|
|
589
621
|
}
|
|
590
|
-
function
|
|
591
|
-
|
|
592
|
-
let
|
|
622
|
+
function Xe(e, n, i = Je, a) {
|
|
623
|
+
R(() => {
|
|
624
|
+
let o = new AbortController();
|
|
593
625
|
return (async () => {
|
|
594
626
|
W.getState().setStatus("loading");
|
|
595
627
|
try {
|
|
596
|
-
let c =
|
|
597
|
-
if (
|
|
598
|
-
let l = c,
|
|
599
|
-
if (W.getState().setAgentId(f),
|
|
600
|
-
let e = String(
|
|
628
|
+
let c = a ?? await i.getAgentUiBootstrap(n, { signal: o.signal });
|
|
629
|
+
if (o.signal.aborted) return;
|
|
630
|
+
let l = c, d = l?.Agent, f = String(d?.AgentId || "default-agent");
|
|
631
|
+
if (W.getState().setAgentId(f), d?.Name) {
|
|
632
|
+
let e = String(d.Name);
|
|
601
633
|
W.getState().setAgentName(e), document.title = e;
|
|
602
634
|
}
|
|
603
|
-
let p = String(
|
|
635
|
+
let p = String(d?.Framework || "").trim().toLowerCase();
|
|
604
636
|
W.getState().setAgentFramework(p);
|
|
605
637
|
let m = t(c);
|
|
606
|
-
W.getState().setCapabilities(m), W.getState().setApiFormats(
|
|
638
|
+
W.getState().setCapabilities(m), W.getState().setApiFormats(qe(m.HostedChat.ApiFormats)), W.getState().setAccessMode(String(l?.AccessMode || "Owner"));
|
|
607
639
|
let h = m.WorkspaceFiles && l?.WorkspaceFiles ? l.WorkspaceFiles : null;
|
|
608
|
-
W.getState().setWorkspaceFiles(h), h ||
|
|
640
|
+
W.getState().setWorkspaceFiles(h), h || s.getState().setWorkspacePanelOpen(!1), r(m) && e.fetchSessions(f, He(f));
|
|
609
641
|
let g = l?.Model;
|
|
610
|
-
g?.id && (
|
|
642
|
+
g?.id && (u.getState().setSelectedModel(g.id), u.getState().upsertModels([g]), u.getState().setModelSource(g.source || "")), Ye(f, i), W.getState().setStatus("ready");
|
|
611
643
|
} catch (e) {
|
|
612
|
-
if (
|
|
644
|
+
if (o.signal.aborted) return;
|
|
613
645
|
console.error("Failed to fetch bootstrap:", e);
|
|
614
|
-
let t =
|
|
646
|
+
let t = Ke(e);
|
|
615
647
|
W.getState().setStatus(t, t === "auth-required" ? "当前访问链接未授权或已过期。" : "无法加载 Agent 配置,请稍后重试。");
|
|
616
648
|
}
|
|
617
|
-
})(), () =>
|
|
649
|
+
})(), () => o.abort();
|
|
618
650
|
}, [
|
|
619
|
-
|
|
651
|
+
i,
|
|
620
652
|
n,
|
|
621
|
-
|
|
653
|
+
a
|
|
622
654
|
]);
|
|
623
655
|
}
|
|
624
656
|
//#endregion
|
|
625
657
|
//#region src/hooks/useFeedback.ts
|
|
626
|
-
function
|
|
658
|
+
function Ze(e) {
|
|
627
659
|
let { agentId: t, currentSessionId: n, isStreaming: r, api: i, submitDraft: a } = e;
|
|
628
660
|
return {
|
|
629
|
-
submitResponseFeedback:
|
|
661
|
+
submitResponseFeedback: L(async (e) => {
|
|
630
662
|
if (!n) return;
|
|
631
663
|
let r = null;
|
|
632
|
-
|
|
633
|
-
let n =
|
|
664
|
+
E.getState().patchMessages((t) => {
|
|
665
|
+
let n = T(t, {
|
|
634
666
|
messageId: e.message.id,
|
|
635
667
|
rating: e.rating,
|
|
636
668
|
comment: e.comment || ""
|
|
@@ -638,19 +670,19 @@ function Ye(e) {
|
|
|
638
670
|
return r = n.previousFeedback, n.nextMessages;
|
|
639
671
|
});
|
|
640
672
|
try {
|
|
641
|
-
let r =
|
|
673
|
+
let r = S((await i.upsertResponseFeedback(C({
|
|
642
674
|
agentId: t,
|
|
643
675
|
sessionId: n,
|
|
644
676
|
message: e.message,
|
|
645
677
|
rating: e.rating,
|
|
646
678
|
comment: e.comment || ""
|
|
647
679
|
})))?.Feedback);
|
|
648
|
-
r &&
|
|
680
|
+
r && E.getState().patchMessages((t) => _(t, {
|
|
649
681
|
messageId: e.message.id,
|
|
650
682
|
feedback: r
|
|
651
683
|
}));
|
|
652
684
|
} catch (t) {
|
|
653
|
-
console.error("Failed to submit response feedback:", t),
|
|
685
|
+
console.error("Failed to submit response feedback:", t), E.getState().patchMessages((t) => w(t, {
|
|
654
686
|
messageId: e.message.id,
|
|
655
687
|
previousFeedback: r
|
|
656
688
|
}));
|
|
@@ -660,18 +692,18 @@ function Ye(e) {
|
|
|
660
692
|
n,
|
|
661
693
|
i
|
|
662
694
|
]),
|
|
663
|
-
deleteResponseFeedback:
|
|
695
|
+
deleteResponseFeedback: L(async (e) => {
|
|
664
696
|
if (!n) return;
|
|
665
697
|
let r = e.feedback ? { ...e.feedback } : null;
|
|
666
|
-
|
|
698
|
+
E.getState().patchMessages((t) => y(t, { messageId: e.id }));
|
|
667
699
|
try {
|
|
668
|
-
await i.deleteResponseFeedback(
|
|
700
|
+
await i.deleteResponseFeedback(x({
|
|
669
701
|
agentId: t,
|
|
670
702
|
sessionId: n,
|
|
671
703
|
message: e
|
|
672
704
|
}));
|
|
673
705
|
} catch (t) {
|
|
674
|
-
console.error("Failed to delete response feedback:", t),
|
|
706
|
+
console.error("Failed to delete response feedback:", t), E.getState().patchMessages((t) => w(t, {
|
|
675
707
|
messageId: e.id,
|
|
676
708
|
previousFeedback: r
|
|
677
709
|
}));
|
|
@@ -681,8 +713,8 @@ function Ye(e) {
|
|
|
681
713
|
n,
|
|
682
714
|
i
|
|
683
715
|
]),
|
|
684
|
-
respondToApproval:
|
|
685
|
-
!e.approvalRequestId || r || (
|
|
716
|
+
respondToApproval: L((e) => {
|
|
717
|
+
!e.approvalRequestId || r || (E.getState().patchMessages((t) => t.map((t) => {
|
|
686
718
|
let n = e.approve ? "approved" : "rejected", r = (t) => e.approve && t === "paused" ? "running" : e.approve ? t : "completed";
|
|
687
719
|
return {
|
|
688
720
|
...t,
|
|
@@ -710,7 +742,7 @@ function Ye(e) {
|
|
|
710
742
|
}
|
|
711
743
|
//#endregion
|
|
712
744
|
//#region src/core/interaction/store.ts
|
|
713
|
-
var
|
|
745
|
+
var Qe = class {
|
|
714
746
|
records = /* @__PURE__ */ new Map();
|
|
715
747
|
terminalRuns = /* @__PURE__ */ new Set();
|
|
716
748
|
listeners = /* @__PURE__ */ new Set();
|
|
@@ -741,7 +773,7 @@ var Xe = class {
|
|
|
741
773
|
return [...this.records.values()].sort((e, t) => String(e.createdAt).localeCompare(String(t.createdAt)));
|
|
742
774
|
}
|
|
743
775
|
upsert(e) {
|
|
744
|
-
e.runId && !
|
|
776
|
+
e.runId && !f(e.status) && this.terminalRuns.has(this.runKey(e.sessionId, e.runId)) && (e = {
|
|
745
777
|
...e,
|
|
746
778
|
status: "expired",
|
|
747
779
|
outcome: "expired",
|
|
@@ -749,10 +781,10 @@ var Xe = class {
|
|
|
749
781
|
responseSummary: e.responseSummary ?? "运行已结束"
|
|
750
782
|
});
|
|
751
783
|
let t = this.get(e.sessionId, e.interactionId), n, r;
|
|
752
|
-
return t ?
|
|
784
|
+
return t ? f(t.status) && !f(e.status) || e.revision < t.revision || e.revision === t.revision && f(t.status) && !f(e.status) || t.status === "resolving" && !f(e.status) ? (n = t, r = {
|
|
753
785
|
type: "interaction_updated",
|
|
754
786
|
interaction: n
|
|
755
|
-
}) :
|
|
787
|
+
}) : f(e.status) ? (n = {
|
|
756
788
|
...t,
|
|
757
789
|
...e,
|
|
758
790
|
title: t.title || e.title,
|
|
@@ -850,7 +882,7 @@ var Xe = class {
|
|
|
850
882
|
if (!(!e || !t)) {
|
|
851
883
|
this.terminalRuns.add(this.runKey(e, t));
|
|
852
884
|
for (let n of this.listAll(e)) {
|
|
853
|
-
if (n.runId !== t ||
|
|
885
|
+
if (n.runId !== t || f(n.status)) continue;
|
|
854
886
|
let r = {
|
|
855
887
|
...n,
|
|
856
888
|
status: "expired",
|
|
@@ -867,10 +899,10 @@ var Xe = class {
|
|
|
867
899
|
}
|
|
868
900
|
markSessionTerminal(e) {
|
|
869
901
|
if (!e) return;
|
|
870
|
-
let t = new Set(this.listAll(e).filter((e) => !
|
|
902
|
+
let t = new Set(this.listAll(e).filter((e) => !f(e.status)).map((e) => e.runId).filter((e) => !!e));
|
|
871
903
|
for (let n of t) this.markRunTerminal(e, n);
|
|
872
904
|
for (let t of this.listAll(e)) {
|
|
873
|
-
if (t.runId ||
|
|
905
|
+
if (t.runId || f(t.status)) continue;
|
|
874
906
|
let n = {
|
|
875
907
|
...t,
|
|
876
908
|
status: "expired",
|
|
@@ -896,7 +928,7 @@ var Xe = class {
|
|
|
896
928
|
let t = `${e}\u0000`;
|
|
897
929
|
for (let e of this.terminalRuns) e.startsWith(t) && this.terminalRuns.delete(e);
|
|
898
930
|
}
|
|
899
|
-
},
|
|
931
|
+
}, $e = {
|
|
900
932
|
approve: "approved",
|
|
901
933
|
reject: "rejected",
|
|
902
934
|
submit: "submitted",
|
|
@@ -914,12 +946,12 @@ function G(e, t) {
|
|
|
914
946
|
extensions: {}
|
|
915
947
|
};
|
|
916
948
|
}
|
|
917
|
-
var
|
|
949
|
+
var et = class {
|
|
918
950
|
store;
|
|
919
951
|
deps;
|
|
920
952
|
inFlight = /* @__PURE__ */ new Map();
|
|
921
953
|
constructor(e) {
|
|
922
|
-
this.deps = e, this.store = e.store || new
|
|
954
|
+
this.deps = e, this.store = e.store || new Qe();
|
|
923
955
|
}
|
|
924
956
|
listPending(e) {
|
|
925
957
|
return this.store.listPending(e);
|
|
@@ -947,14 +979,14 @@ var Qe = class {
|
|
|
947
979
|
let t = this.findByInteractionId(e.interactionId);
|
|
948
980
|
if (!t) return G("rejected", e.interactionId);
|
|
949
981
|
if (t.status === "resolved" || t.status === "cancelled" || t.status === "expired" || t.status === "resolving") return G("duplicate", e.interactionId);
|
|
950
|
-
let n = e.idempotencyKey ||
|
|
982
|
+
let n = e.idempotencyKey || i(e.interactionId, e.expectedRevision), r = this.inFlight.get(e.interactionId);
|
|
951
983
|
if (r) return G(r === n ? "duplicate" : "rejected", e.interactionId);
|
|
952
984
|
this.inFlight.set(e.interactionId, n), this.store.markResolving(t.sessionId, e.interactionId);
|
|
953
|
-
let
|
|
985
|
+
let a = this.deps.interactionV1Enabled || t.source === "interaction_v1";
|
|
954
986
|
try {
|
|
955
|
-
if (!
|
|
956
|
-
if (!
|
|
957
|
-
let r =
|
|
987
|
+
if (!a && t.source === "responses" && this.deps.legacyResponsesApproval) return this.deps.legacyResponsesApproval(e.interactionId, e.action === "approve"), this.resolveLocal(t, e, n), G("accepted", e.interactionId);
|
|
988
|
+
if (!a && t.source === "agui" && this.deps.legacyAguiResume) return this.deps.legacyAguiResume(String(t.extensions.interrupt_id || e.interactionId), e.action === "cancel" ? "cancelled" : "resolved", e.response) ? (this.resolveLocal(t, e, n), G("accepted", e.interactionId)) : (this.store.revertToPending(t.sessionId, e.interactionId), G("rejected", e.interactionId));
|
|
989
|
+
let r = Oe(await this.deps.submitInteraction({
|
|
958
990
|
AgentId: this.deps.agentId,
|
|
959
991
|
SessionId: t.sessionId,
|
|
960
992
|
RunId: t.runId || "",
|
|
@@ -984,9 +1016,9 @@ var Qe = class {
|
|
|
984
1016
|
let r = t.action === "cancel" ? "cancelled" : "resolved";
|
|
985
1017
|
this.store.resolveLocally(e.sessionId, t.interactionId, {
|
|
986
1018
|
status: r,
|
|
987
|
-
outcome:
|
|
1019
|
+
outcome: $e[t.action],
|
|
988
1020
|
actor: "user",
|
|
989
|
-
responseSummary:
|
|
1021
|
+
responseSummary: m(t.action, t.response),
|
|
990
1022
|
revision: t.expectedRevision
|
|
991
1023
|
});
|
|
992
1024
|
let i = this.store.get(e.sessionId, t.interactionId);
|
|
@@ -998,53 +1030,53 @@ var Qe = class {
|
|
|
998
1030
|
}
|
|
999
1031
|
});
|
|
1000
1032
|
}
|
|
1001
|
-
},
|
|
1033
|
+
}, tt = new Set([
|
|
1002
1034
|
"approval",
|
|
1003
1035
|
"structured_input",
|
|
1004
1036
|
"plan_review",
|
|
1005
1037
|
"custom"
|
|
1006
|
-
]),
|
|
1038
|
+
]), nt = new Set([
|
|
1007
1039
|
"pending",
|
|
1008
1040
|
"resolving",
|
|
1009
1041
|
"failed",
|
|
1010
1042
|
"resolved",
|
|
1011
1043
|
"cancelled",
|
|
1012
1044
|
"expired"
|
|
1013
|
-
]),
|
|
1045
|
+
]), rt = new Set([
|
|
1014
1046
|
"approved",
|
|
1015
1047
|
"rejected",
|
|
1016
1048
|
"submitted",
|
|
1017
1049
|
"cancelled",
|
|
1018
1050
|
"expired"
|
|
1019
1051
|
]);
|
|
1020
|
-
function
|
|
1052
|
+
function it(e) {
|
|
1021
1053
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
1022
1054
|
}
|
|
1023
1055
|
function K(e) {
|
|
1024
1056
|
return typeof e == "string" && e.length > 0 ? e : null;
|
|
1025
1057
|
}
|
|
1026
|
-
function
|
|
1027
|
-
let t = String(e.kind || "approval"), n = String(e.status || "pending"), r = String(e.outcome || ""), i =
|
|
1058
|
+
function at(e) {
|
|
1059
|
+
let t = String(e.kind || "approval"), n = String(e.status || "pending"), r = String(e.outcome || ""), i = it(e.presentation), a = i ? it(i.a2ui) : null;
|
|
1028
1060
|
return {
|
|
1029
1061
|
interactionId: e.interactionId,
|
|
1030
1062
|
sessionId: e.sessionId,
|
|
1031
1063
|
runId: K(e.runId),
|
|
1032
|
-
kind:
|
|
1064
|
+
kind: tt.has(t) ? t : "custom",
|
|
1033
1065
|
title: typeof e.title == "string" && e.title ? e.title : "人工确认",
|
|
1034
1066
|
message: typeof e.message == "string" && e.message ? e.message : "本次运行需要人工处理后才能继续。",
|
|
1035
|
-
requestSchema:
|
|
1067
|
+
requestSchema: it(e.requestSchema),
|
|
1036
1068
|
presentation: a ? { a2ui: {
|
|
1037
1069
|
wireVersion: String(a.wire_version ?? a.wireVersion ?? ""),
|
|
1038
1070
|
catalogDigest: String(a.catalog_digest ?? a.catalogDigest ?? ""),
|
|
1039
1071
|
messages: Array.isArray(a.messages) ? a.messages.filter((e) => typeof e == "object") : []
|
|
1040
1072
|
} } : null,
|
|
1041
|
-
status:
|
|
1073
|
+
status: nt.has(n) ? n : "pending",
|
|
1042
1074
|
revision: Number.isFinite(Number(e.revision)) && Number(e.revision) > 0 ? Number(e.revision) : 1,
|
|
1043
1075
|
createdAt: K(e.createdAt) || (/* @__PURE__ */ new Date()).toISOString(),
|
|
1044
1076
|
expiresAt: K(e.expiresAt),
|
|
1045
1077
|
resolvedAt: K(e.resolvedAt),
|
|
1046
1078
|
actor: K(e.actor),
|
|
1047
|
-
outcome:
|
|
1079
|
+
outcome: rt.has(r) ? r : null,
|
|
1048
1080
|
responseSummary: K(e.responseSummary),
|
|
1049
1081
|
source: e.source,
|
|
1050
1082
|
extensions: e.extensions || {}
|
|
@@ -1052,14 +1084,14 @@ function rt(e) {
|
|
|
1052
1084
|
}
|
|
1053
1085
|
//#endregion
|
|
1054
1086
|
//#region src/core/interaction/adapters/session-events.ts
|
|
1055
|
-
var
|
|
1087
|
+
var ot = new Set([
|
|
1056
1088
|
"interaction.requested",
|
|
1057
1089
|
"interaction_requested",
|
|
1058
1090
|
"ksadk.interaction/v1.requested",
|
|
1059
1091
|
"InteractionRequested",
|
|
1060
1092
|
"approval.requested",
|
|
1061
1093
|
"a2ui.interaction"
|
|
1062
|
-
]),
|
|
1094
|
+
]), st = new Set([
|
|
1063
1095
|
"interaction.resolved",
|
|
1064
1096
|
"interaction_resolved",
|
|
1065
1097
|
"ksadk.interaction/v1.resolved",
|
|
@@ -1073,7 +1105,7 @@ var it = new Set([
|
|
|
1073
1105
|
function q(e) {
|
|
1074
1106
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
1075
1107
|
}
|
|
1076
|
-
function
|
|
1108
|
+
function ct(e, t) {
|
|
1077
1109
|
let n = q(e);
|
|
1078
1110
|
if (!n) return null;
|
|
1079
1111
|
let r = String(n.event_type || n.EventType || "").trim();
|
|
@@ -1082,13 +1114,13 @@ function ot(e, t) {
|
|
|
1082
1114
|
if (!o) return null;
|
|
1083
1115
|
let s = String(n.session_id || n.SessionId || a.session_id || a.sessionId || t || "");
|
|
1084
1116
|
if (!s) return null;
|
|
1085
|
-
if (
|
|
1117
|
+
if (ot.has(r)) {
|
|
1086
1118
|
let e = {
|
|
1087
1119
|
...q(a.extensions) || {},
|
|
1088
1120
|
...a.detail === void 0 ? {} : { detail: a.detail },
|
|
1089
1121
|
...(a.call_id ?? a.callId) === void 0 ? {} : { call_id: a.call_id ?? a.callId }
|
|
1090
1122
|
};
|
|
1091
|
-
return
|
|
1123
|
+
return at({
|
|
1092
1124
|
interactionId: o,
|
|
1093
1125
|
sessionId: s,
|
|
1094
1126
|
runId: a.run_id ?? a.runId ?? n.run_id ?? n.InvocationId,
|
|
@@ -1105,7 +1137,7 @@ function ot(e, t) {
|
|
|
1105
1137
|
extensions: e
|
|
1106
1138
|
});
|
|
1107
1139
|
}
|
|
1108
|
-
if (
|
|
1140
|
+
if (st.has(r)) {
|
|
1109
1141
|
let e = {
|
|
1110
1142
|
...q(a.extensions) || {},
|
|
1111
1143
|
...a.detail === void 0 ? {} : { detail: a.detail },
|
|
@@ -1113,7 +1145,7 @@ function ot(e, t) {
|
|
|
1113
1145
|
}, t = r === "interaction.cancelled" || r === "interaction.cancel" ? "cancelled" : r === "interaction.expired" ? "expired" : "resolved", c = String(i.outcome ?? a.outcome ?? a.status ?? "").toLowerCase(), l = String(i.action ?? a.action ?? i.name ?? a.name ?? "").toLowerCase(), u = c;
|
|
1114
1146
|
u ||= l === "approve" ? "approved" : l === "reject" ? "rejected" : l === "submit" ? "submitted" : l === "cancel" || t === "cancelled" ? "cancelled" : t === "expired" ? "expired" : "submitted";
|
|
1115
1147
|
let d = t === "resolved" ? "resolved" : t;
|
|
1116
|
-
return
|
|
1148
|
+
return at({
|
|
1117
1149
|
interactionId: o,
|
|
1118
1150
|
sessionId: s,
|
|
1119
1151
|
runId: a.run_id ?? a.runId ?? n.run_id ?? n.InvocationId,
|
|
@@ -1138,8 +1170,8 @@ function ot(e, t) {
|
|
|
1138
1170
|
}
|
|
1139
1171
|
//#endregion
|
|
1140
1172
|
//#region src/core/interaction/adapters/responses.ts
|
|
1141
|
-
function
|
|
1142
|
-
return !e.approvalRequestId || !e.sessionId ? null :
|
|
1173
|
+
function lt(e) {
|
|
1174
|
+
return !e.approvalRequestId || !e.sessionId ? null : at({
|
|
1143
1175
|
interactionId: e.approvalRequestId,
|
|
1144
1176
|
sessionId: e.sessionId,
|
|
1145
1177
|
runId: e.runId ?? null,
|
|
@@ -1158,8 +1190,8 @@ function st(e) {
|
|
|
1158
1190
|
}
|
|
1159
1191
|
//#endregion
|
|
1160
1192
|
//#region src/core/interaction/adapters/agui.ts
|
|
1161
|
-
function
|
|
1162
|
-
return !e.interruptId || !e.sessionId ? null :
|
|
1193
|
+
function ut(e) {
|
|
1194
|
+
return !e.interruptId || !e.sessionId ? null : at({
|
|
1163
1195
|
interactionId: e.interruptId,
|
|
1164
1196
|
sessionId: e.sessionId,
|
|
1165
1197
|
runId: e.runId ?? null,
|
|
@@ -1179,7 +1211,7 @@ function ct(e) {
|
|
|
1179
1211
|
}
|
|
1180
1212
|
//#endregion
|
|
1181
1213
|
//#region src/core/interaction/index.ts
|
|
1182
|
-
var
|
|
1214
|
+
var dt = new Set([
|
|
1183
1215
|
"completed",
|
|
1184
1216
|
"failed",
|
|
1185
1217
|
"error",
|
|
@@ -1188,27 +1220,27 @@ var lt = new Set([
|
|
|
1188
1220
|
"aborted",
|
|
1189
1221
|
"interrupted",
|
|
1190
1222
|
"resume_failed"
|
|
1191
|
-
]), J = new
|
|
1192
|
-
function
|
|
1193
|
-
let n =
|
|
1223
|
+
]), J = new Qe();
|
|
1224
|
+
function ft(e, t) {
|
|
1225
|
+
let n = ct(e, t);
|
|
1194
1226
|
n && J.upsert(n);
|
|
1195
|
-
let r = typeof e == "object" && e ? e : null, i = r ?
|
|
1196
|
-
if (i !== null &&
|
|
1227
|
+
let r = typeof e == "object" && e ? e : null, i = r ? P(r) : null;
|
|
1228
|
+
if (i !== null && dt.has(i)) {
|
|
1197
1229
|
let e = typeof r?.Content == "object" && r.Content !== null ? r.Content : {}, n = typeof e.payload == "object" && e.payload !== null ? e.payload : {}, i = String(r?.SessionId || r?.session_id || t || ""), a = String(r?.InvocationId || r?.run_id || n.run_id || n.runId || "");
|
|
1198
1230
|
J.markRunTerminal(i, a);
|
|
1199
1231
|
}
|
|
1200
1232
|
return n;
|
|
1201
1233
|
}
|
|
1202
|
-
function
|
|
1234
|
+
function pt(e) {
|
|
1203
1235
|
let t = e.sessionId || "";
|
|
1204
1236
|
if (!t || !e.approvalRequestId) return null;
|
|
1205
|
-
let n = e.protocol === "ag-ui" ?
|
|
1237
|
+
let n = e.protocol === "ag-ui" ? ut({
|
|
1206
1238
|
interruptId: e.approvalRequestId,
|
|
1207
1239
|
sessionId: t,
|
|
1208
1240
|
name: e.name,
|
|
1209
1241
|
message: e.message,
|
|
1210
1242
|
reason: e.approvalLevel
|
|
1211
|
-
}) :
|
|
1243
|
+
}) : lt({
|
|
1212
1244
|
approvalRequestId: e.approvalRequestId,
|
|
1213
1245
|
sessionId: t,
|
|
1214
1246
|
runId: e.runId,
|
|
@@ -1219,9 +1251,9 @@ function dt(e) {
|
|
|
1219
1251
|
});
|
|
1220
1252
|
return n && J.upsert(n), n;
|
|
1221
1253
|
}
|
|
1222
|
-
function
|
|
1254
|
+
function mt(e) {
|
|
1223
1255
|
let t = e.sessionId || "";
|
|
1224
|
-
return !t || !e.approvalRequestId ? null :
|
|
1256
|
+
return !t || !e.approvalRequestId ? null : ft({
|
|
1225
1257
|
EventType: "approval.resolved",
|
|
1226
1258
|
Content: {
|
|
1227
1259
|
approvalId: e.approvalRequestId,
|
|
@@ -1234,8 +1266,8 @@ function ft(e) {
|
|
|
1234
1266
|
}
|
|
1235
1267
|
//#endregion
|
|
1236
1268
|
//#region src/hooks/useInteractions.ts
|
|
1237
|
-
function
|
|
1238
|
-
let [t] =
|
|
1269
|
+
function ht(e) {
|
|
1270
|
+
let [t] = he(() => new et({
|
|
1239
1271
|
agentId: e.agentId,
|
|
1240
1272
|
store: J,
|
|
1241
1273
|
submitInteraction: (t) => e.api.submitInteraction({
|
|
@@ -1246,17 +1278,17 @@ function pt(e) {
|
|
|
1246
1278
|
legacyResponsesApproval: e.legacyResponsesApproval,
|
|
1247
1279
|
legacyAguiResume: e.legacyAguiResume
|
|
1248
1280
|
}));
|
|
1249
|
-
|
|
1281
|
+
R(() => {
|
|
1250
1282
|
t.setInteractionV1Enabled(e.interactionV1Enabled);
|
|
1251
1283
|
}, [t, e.interactionV1Enabled]);
|
|
1252
|
-
let [n, r] =
|
|
1253
|
-
|
|
1254
|
-
let i =
|
|
1284
|
+
let [n, r] = he(0);
|
|
1285
|
+
R(() => J.subscribe(() => r((e) => e + 1)), []);
|
|
1286
|
+
let i = me(() => e.currentSessionId ? J.listAll(e.currentSessionId).filter((e) => e.status === "pending" || e.status === "resolving" || e.status === "failed") : [], [n, e.currentSessionId]), a = me(() => e.currentSessionId ? J.listAll(e.currentSessionId) : [], [n, e.currentSessionId]), { currentSessionId: o, interactionV1Enabled: s, onAcceptedInteraction: c } = e;
|
|
1255
1287
|
return {
|
|
1256
1288
|
client: t,
|
|
1257
1289
|
pending: i,
|
|
1258
1290
|
records: a,
|
|
1259
|
-
respond:
|
|
1291
|
+
respond: L((e) => {
|
|
1260
1292
|
let n = o ? J.get(o, e.interactionId) : null;
|
|
1261
1293
|
return t.respond(e).then((e) => (s && n && (e.status === "accepted" || e.status === "duplicate") && c?.(n), e));
|
|
1262
1294
|
}, [
|
|
@@ -1265,46 +1297,46 @@ function pt(e) {
|
|
|
1265
1297
|
s,
|
|
1266
1298
|
c
|
|
1267
1299
|
]),
|
|
1268
|
-
localCatalog:
|
|
1300
|
+
localCatalog: d
|
|
1269
1301
|
};
|
|
1270
1302
|
}
|
|
1271
|
-
var
|
|
1272
|
-
function
|
|
1303
|
+
var gt = .28;
|
|
1304
|
+
function _t(e, t = 768) {
|
|
1273
1305
|
return Number(e) <= t;
|
|
1274
1306
|
}
|
|
1275
|
-
function
|
|
1307
|
+
function vt({ isMobile: e, desktopSidebarOpen: t, mobileSidebarOpen: n }) {
|
|
1276
1308
|
return {
|
|
1277
1309
|
desktopSidebarVisible: !e && !!t,
|
|
1278
1310
|
mobileDrawerVisible: !!(e && n)
|
|
1279
1311
|
};
|
|
1280
1312
|
}
|
|
1281
|
-
function
|
|
1313
|
+
function yt({ isMobile: e, viewportHeight: t, desktopMaxHeight: n = 160 }) {
|
|
1282
1314
|
if (!e) return n;
|
|
1283
1315
|
let r = Number(t);
|
|
1284
1316
|
if (!Number.isFinite(r) || r <= 0) return n;
|
|
1285
|
-
let i = Math.floor(r *
|
|
1317
|
+
let i = Math.floor(r * gt);
|
|
1286
1318
|
return Math.max(120, Math.min(n, i));
|
|
1287
1319
|
}
|
|
1288
1320
|
//#endregion
|
|
1289
1321
|
//#region src/hooks/useResponsiveViewport.ts
|
|
1290
|
-
function
|
|
1322
|
+
function bt() {
|
|
1291
1323
|
return typeof window > "u" ? 900 : Math.round(window.visualViewport?.height || window.innerHeight || 900);
|
|
1292
1324
|
}
|
|
1293
|
-
function
|
|
1325
|
+
function xt() {
|
|
1294
1326
|
return typeof window > "u" ? {
|
|
1295
1327
|
isMobile: !1,
|
|
1296
1328
|
viewportHeight: 900
|
|
1297
1329
|
} : {
|
|
1298
|
-
isMobile:
|
|
1299
|
-
viewportHeight:
|
|
1330
|
+
isMobile: _t(window.innerWidth, 768),
|
|
1331
|
+
viewportHeight: bt()
|
|
1300
1332
|
};
|
|
1301
1333
|
}
|
|
1302
|
-
function
|
|
1303
|
-
let [e, t] =
|
|
1304
|
-
return
|
|
1334
|
+
function St() {
|
|
1335
|
+
let [e, t] = he(() => xt());
|
|
1336
|
+
return R(() => {
|
|
1305
1337
|
if (typeof window > "u") return;
|
|
1306
1338
|
let e = window.matchMedia("(max-width: 768px)"), n = () => {
|
|
1307
|
-
t(
|
|
1339
|
+
t(xt());
|
|
1308
1340
|
};
|
|
1309
1341
|
n();
|
|
1310
1342
|
let r = typeof e.addEventListener == "function" ? (e.addEventListener("change", n), () => e.removeEventListener("change", n)) : (e.addListener(n), () => e.removeListener(n));
|
|
@@ -1315,16 +1347,16 @@ function bt() {
|
|
|
1315
1347
|
}
|
|
1316
1348
|
//#endregion
|
|
1317
1349
|
//#region src/core/stream/responses-protocol.ts
|
|
1318
|
-
var
|
|
1350
|
+
var Ct = class {
|
|
1319
1351
|
id = "responses";
|
|
1320
1352
|
createState() {
|
|
1321
|
-
return
|
|
1353
|
+
return ie();
|
|
1322
1354
|
}
|
|
1323
1355
|
parseItemOperations(e, t, n) {
|
|
1324
|
-
return
|
|
1356
|
+
return g(e.eventName, e.data, t, n);
|
|
1325
1357
|
}
|
|
1326
1358
|
parse(e, t) {
|
|
1327
|
-
return
|
|
1359
|
+
return de({
|
|
1328
1360
|
eventName: e.eventName,
|
|
1329
1361
|
data: e.data,
|
|
1330
1362
|
state: t
|
|
@@ -1347,23 +1379,23 @@ var xt = class {
|
|
|
1347
1379
|
};
|
|
1348
1380
|
//#endregion
|
|
1349
1381
|
//#region src/utils/stream-parsing.ts
|
|
1350
|
-
function
|
|
1382
|
+
function wt(e) {
|
|
1351
1383
|
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("") : "";
|
|
1352
1384
|
}
|
|
1353
|
-
function
|
|
1385
|
+
function Tt(e) {
|
|
1354
1386
|
return e && typeof e == "object" ? e : {};
|
|
1355
1387
|
}
|
|
1356
|
-
function
|
|
1357
|
-
let t =
|
|
1388
|
+
function Et(e) {
|
|
1389
|
+
let t = Tt(e).choices, n = Tt(Array.isArray(t) ? t[0] : null), r = Tt(n.delta), i = Tt(n.message);
|
|
1358
1390
|
return {
|
|
1359
|
-
content:
|
|
1360
|
-
reasoning:
|
|
1361
|
-
finalText:
|
|
1391
|
+
content: wt(r.content),
|
|
1392
|
+
reasoning: wt(r.reasoning_content),
|
|
1393
|
+
finalText: wt(i.content)
|
|
1362
1394
|
};
|
|
1363
1395
|
}
|
|
1364
1396
|
//#endregion
|
|
1365
1397
|
//#region src/core/stream/chat-completions-protocol.ts
|
|
1366
|
-
var
|
|
1398
|
+
var Dt = class {
|
|
1367
1399
|
id = "chat_completions";
|
|
1368
1400
|
createState() {
|
|
1369
1401
|
return {};
|
|
@@ -1371,7 +1403,7 @@ var Tt = class {
|
|
|
1371
1403
|
parse(e) {
|
|
1372
1404
|
let t = e.data;
|
|
1373
1405
|
if (typeof t != "object" || !t) return [];
|
|
1374
|
-
let n =
|
|
1406
|
+
let n = Et(t), r = [];
|
|
1375
1407
|
return n.reasoning && r.push({
|
|
1376
1408
|
type: "reasoning_delta",
|
|
1377
1409
|
text: n.reasoning
|
|
@@ -1383,14 +1415,14 @@ var Tt = class {
|
|
|
1383
1415
|
text: n.finalText
|
|
1384
1416
|
}), r;
|
|
1385
1417
|
}
|
|
1386
|
-
},
|
|
1387
|
-
|
|
1388
|
-
function
|
|
1389
|
-
return
|
|
1418
|
+
}, Ot = /* @__PURE__ */ new Map();
|
|
1419
|
+
Ot.set("responses", new Ct()), Ot.set("chat_completions", new Dt());
|
|
1420
|
+
function kt(e) {
|
|
1421
|
+
return Ot.get(e) || Ot.get("responses");
|
|
1390
1422
|
}
|
|
1391
1423
|
//#endregion
|
|
1392
1424
|
//#region src/utils/stream-control.js
|
|
1393
|
-
function
|
|
1425
|
+
function At(e = []) {
|
|
1394
1426
|
return e.some((e) => {
|
|
1395
1427
|
if (e?.type !== "terminal") return !1;
|
|
1396
1428
|
let t = String(e.status || "").toLowerCase();
|
|
@@ -1429,7 +1461,7 @@ function Y(e) {
|
|
|
1429
1461
|
}
|
|
1430
1462
|
return t;
|
|
1431
1463
|
}
|
|
1432
|
-
function
|
|
1464
|
+
function jt(e) {
|
|
1433
1465
|
let t = e.split("\n\n");
|
|
1434
1466
|
return {
|
|
1435
1467
|
chunks: t,
|
|
@@ -1438,60 +1470,60 @@ function X(e) {
|
|
|
1438
1470
|
}
|
|
1439
1471
|
//#endregion
|
|
1440
1472
|
//#region src/utils/error.ts
|
|
1441
|
-
function
|
|
1473
|
+
function Mt(e) {
|
|
1442
1474
|
return e instanceof Error ? e.message : String(e);
|
|
1443
1475
|
}
|
|
1444
1476
|
//#endregion
|
|
1445
1477
|
//#region src/utils/model-options.js
|
|
1446
|
-
var
|
|
1478
|
+
var Nt = new Set([
|
|
1447
1479
|
"auto",
|
|
1448
1480
|
"enabled",
|
|
1449
1481
|
"disabled"
|
|
1450
1482
|
]);
|
|
1451
|
-
function
|
|
1483
|
+
function Pt(e) {
|
|
1452
1484
|
let t = String(e || "").trim().toLowerCase();
|
|
1453
|
-
return
|
|
1485
|
+
return Nt.has(t) ? t : "auto";
|
|
1454
1486
|
}
|
|
1455
|
-
function
|
|
1456
|
-
let t =
|
|
1487
|
+
function Ft(e) {
|
|
1488
|
+
let t = Pt(e);
|
|
1457
1489
|
if (t === "disabled") return { thinking: { type: "disabled" } };
|
|
1458
1490
|
if (t === "enabled") return { thinking: { type: "enabled" } };
|
|
1459
1491
|
}
|
|
1460
|
-
var
|
|
1461
|
-
function
|
|
1492
|
+
var It = 1280;
|
|
1493
|
+
function Lt(e) {
|
|
1462
1494
|
let { apiFormats: t } = e;
|
|
1463
1495
|
return t.includes("responses") ? "responses" : t.includes("chat_completions") ? "chat_completions" : "responses";
|
|
1464
1496
|
}
|
|
1465
|
-
function
|
|
1466
|
-
let r = Math.min(
|
|
1497
|
+
function Rt(e, t, n) {
|
|
1498
|
+
let r = Math.min(It, Math.max(420, t - n - 360));
|
|
1467
1499
|
return Math.min(Math.max(e, 420), r);
|
|
1468
1500
|
}
|
|
1469
1501
|
//#endregion
|
|
1470
1502
|
//#region src/core/run/agui.ts
|
|
1471
|
-
function
|
|
1503
|
+
function zt(e) {
|
|
1472
1504
|
return String(e.type || "").toUpperCase();
|
|
1473
1505
|
}
|
|
1474
|
-
function
|
|
1506
|
+
function Bt(e, t) {
|
|
1475
1507
|
return String(e.messageId || t);
|
|
1476
1508
|
}
|
|
1477
|
-
function
|
|
1509
|
+
function Vt(e, t) {
|
|
1478
1510
|
return String(e.runId || t);
|
|
1479
1511
|
}
|
|
1480
|
-
function
|
|
1512
|
+
function Ht(e) {
|
|
1481
1513
|
return e && typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
1482
1514
|
}
|
|
1483
|
-
function
|
|
1484
|
-
if (Array.isArray(e)) return
|
|
1515
|
+
function Ut(e) {
|
|
1516
|
+
if (Array.isArray(e)) return l(e.filter((e) => !!(e && typeof e == "object")));
|
|
1485
1517
|
if (e && typeof e == "object") {
|
|
1486
1518
|
let t = e.a2ui_operations;
|
|
1487
|
-
return Array.isArray(t) ?
|
|
1519
|
+
return Array.isArray(t) ? l(t.filter((e) => !!(e && typeof e == "object"))) : [e];
|
|
1488
1520
|
}
|
|
1489
1521
|
return [];
|
|
1490
1522
|
}
|
|
1491
|
-
function
|
|
1523
|
+
function Wt(e) {
|
|
1492
1524
|
return e == null || e === "" ? "" : typeof e == "string" ? e : JSON.stringify(e, null, 2);
|
|
1493
1525
|
}
|
|
1494
|
-
var
|
|
1526
|
+
var Gt = class {
|
|
1495
1527
|
agent;
|
|
1496
1528
|
onEvent;
|
|
1497
1529
|
tools = /* @__PURE__ */ new Map();
|
|
@@ -1499,7 +1531,7 @@ var Ht = class {
|
|
|
1499
1531
|
pendingByRun = /* @__PURE__ */ new Map();
|
|
1500
1532
|
activeRunId = "";
|
|
1501
1533
|
constructor(e) {
|
|
1502
|
-
this.agent = new
|
|
1534
|
+
this.agent = new _e({
|
|
1503
1535
|
url: e.url,
|
|
1504
1536
|
agentId: e.agentId,
|
|
1505
1537
|
threadId: e.threadId,
|
|
@@ -1517,7 +1549,7 @@ var Ht = class {
|
|
|
1517
1549
|
});
|
|
1518
1550
|
}
|
|
1519
1551
|
async resume(e, t) {
|
|
1520
|
-
let n = this.agent.pendingInterrupts.length > 0 ? this.agent.pendingInterrupts : this.pendingByRun.get(this.activeRunId) || [], r =
|
|
1552
|
+
let n = this.agent.pendingInterrupts.length > 0 ? this.agent.pendingInterrupts : this.pendingByRun.get(this.activeRunId) || [], r = ve(n.length > 0 ? n : [{
|
|
1521
1553
|
id: t.interruptId,
|
|
1522
1554
|
reason: "approval"
|
|
1523
1555
|
}], { [t.interruptId]: t.status === "resolved" ? {
|
|
@@ -1541,7 +1573,7 @@ var Ht = class {
|
|
|
1541
1573
|
async execute(e) {
|
|
1542
1574
|
let t = "completed", n = await this.agent.runAgent({
|
|
1543
1575
|
runId: e.runId,
|
|
1544
|
-
context: [
|
|
1576
|
+
context: [h],
|
|
1545
1577
|
forwardedProps: { injectA2UITool: !0 },
|
|
1546
1578
|
resume: e.resume,
|
|
1547
1579
|
abortController: e.abortController
|
|
@@ -1563,7 +1595,7 @@ var Ht = class {
|
|
|
1563
1595
|
};
|
|
1564
1596
|
}
|
|
1565
1597
|
project(e, t) {
|
|
1566
|
-
let n =
|
|
1598
|
+
let n = zt(e), r = Vt(e, t), i = Bt(e, `${r}:assistant`), a = e, o = [];
|
|
1567
1599
|
if (n === "RUN_STARTED") o.push({
|
|
1568
1600
|
type: "activity",
|
|
1569
1601
|
phase: "AG-UI 运行已创建",
|
|
@@ -1625,20 +1657,20 @@ var Ht = class {
|
|
|
1625
1657
|
output: String(a.content || "")
|
|
1626
1658
|
});
|
|
1627
1659
|
} else if (n === "ACTIVITY_SNAPSHOT") {
|
|
1628
|
-
let e = a.content, t =
|
|
1660
|
+
let e = a.content, t = Ht(e), n = String(t.surfaceId || t.surface_id || a.messageId || "default");
|
|
1629
1661
|
o.push({
|
|
1630
1662
|
type: "agui_activity",
|
|
1631
1663
|
messageId: this.runMessageIds.get(r) || i,
|
|
1632
1664
|
surfaceId: n,
|
|
1633
|
-
messages:
|
|
1665
|
+
messages: Ut(t.content ?? e)
|
|
1634
1666
|
});
|
|
1635
1667
|
} else if (n === "RUN_FINISHED") {
|
|
1636
|
-
let e =
|
|
1668
|
+
let e = Ht(a.outcome);
|
|
1637
1669
|
if (String(e.type || "").toLowerCase() === "interrupt") {
|
|
1638
1670
|
let t = Array.isArray(e.interrupts) ? e.interrupts : [];
|
|
1639
1671
|
this.pendingByRun.set(r, t);
|
|
1640
1672
|
for (let e of t) {
|
|
1641
|
-
let t =
|
|
1673
|
+
let t = Ht(e.metadata), n = e.toolCallId ? this.tools.get(e.toolCallId) : void 0, i = String(t.tool_name || t.toolName || n?.name || e.reason || "人工确认"), a = Wt(t.arguments ?? t.tool_args ?? t.args ?? n?.args);
|
|
1642
1674
|
o.push({
|
|
1643
1675
|
type: "approval_requested",
|
|
1644
1676
|
messageId: this.runMessageIds.get(r) || `${r}:assistant`,
|
|
@@ -1672,7 +1704,7 @@ var Ht = class {
|
|
|
1672
1704
|
};
|
|
1673
1705
|
return { events: o };
|
|
1674
1706
|
}
|
|
1675
|
-
},
|
|
1707
|
+
}, Kt = new Set([
|
|
1676
1708
|
"completed",
|
|
1677
1709
|
"failed",
|
|
1678
1710
|
"error",
|
|
@@ -1682,12 +1714,12 @@ var Ht = class {
|
|
|
1682
1714
|
"interrupted",
|
|
1683
1715
|
"resume_failed"
|
|
1684
1716
|
]);
|
|
1685
|
-
function
|
|
1717
|
+
function qt(e) {
|
|
1686
1718
|
if (e.EventType !== "run_status") return null;
|
|
1687
1719
|
let t = String(e.Content?.status || "").trim().toLowerCase();
|
|
1688
|
-
return
|
|
1720
|
+
return Kt.has(t) ? t : null;
|
|
1689
1721
|
}
|
|
1690
|
-
function
|
|
1722
|
+
function Jt(e, t) {
|
|
1691
1723
|
let n = String(t?.type || e || "").trim();
|
|
1692
1724
|
if (n === "response.created") return {
|
|
1693
1725
|
phase: "运行已创建",
|
|
@@ -1733,11 +1765,11 @@ function Gt(e, t) {
|
|
|
1733
1765
|
status: "failed"
|
|
1734
1766
|
} : null;
|
|
1735
1767
|
}
|
|
1736
|
-
function
|
|
1768
|
+
function Yt() {
|
|
1737
1769
|
let e = globalThis.crypto;
|
|
1738
1770
|
return e && typeof e.randomUUID == "function" ? `run_${e.randomUUID()}` : `run_${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
1739
1771
|
}
|
|
1740
|
-
var
|
|
1772
|
+
var Xt = {
|
|
1741
1773
|
idle: [
|
|
1742
1774
|
"creating-session",
|
|
1743
1775
|
"uploading-files",
|
|
@@ -1775,12 +1807,17 @@ var qt = {
|
|
|
1775
1807
|
],
|
|
1776
1808
|
error: ["connecting", "idle"],
|
|
1777
1809
|
cancelled: ["idle"]
|
|
1778
|
-
},
|
|
1810
|
+
}, Zt = class {
|
|
1779
1811
|
_stage = "idle";
|
|
1780
1812
|
listeners = /* @__PURE__ */ new Set();
|
|
1781
1813
|
abortController = null;
|
|
1782
1814
|
activeCompactionId = null;
|
|
1783
1815
|
activeSessionId = null;
|
|
1816
|
+
invocationId = "";
|
|
1817
|
+
operationEpoch = 0;
|
|
1818
|
+
lastSeqId = 0;
|
|
1819
|
+
pendingConfig = null;
|
|
1820
|
+
projection;
|
|
1784
1821
|
aguiClient = null;
|
|
1785
1822
|
aguiThreadSessionId = null;
|
|
1786
1823
|
api;
|
|
@@ -1793,8 +1830,29 @@ var qt = {
|
|
|
1793
1830
|
selectedModel: "",
|
|
1794
1831
|
thinkingMode: "auto"
|
|
1795
1832
|
};
|
|
1796
|
-
constructor(e) {
|
|
1797
|
-
this.api = e;
|
|
1833
|
+
constructor(e, t = {}) {
|
|
1834
|
+
this.api = e, this.projection = t;
|
|
1835
|
+
}
|
|
1836
|
+
get activeInvocationId() {
|
|
1837
|
+
return this.invocationId;
|
|
1838
|
+
}
|
|
1839
|
+
get streamingKey() {
|
|
1840
|
+
return this.activeSessionId || this.projection.draftId || null;
|
|
1841
|
+
}
|
|
1842
|
+
publishInvocation(e) {
|
|
1843
|
+
this.invocationId = e, e && c.getState().updateActivity({
|
|
1844
|
+
sessionId: this.streamingKey,
|
|
1845
|
+
runId: e,
|
|
1846
|
+
countEvent: !1,
|
|
1847
|
+
visible: this.projection.isVisible?.()
|
|
1848
|
+
}), this.projection.isVisible?.() !== !1 && (c.getState().setCurrentRunId(e), c.getState().setActiveInvocationId(e));
|
|
1849
|
+
}
|
|
1850
|
+
recordCursor(e) {
|
|
1851
|
+
this.lastSeqId = e === 0 ? 0 : Math.max(this.lastSeqId, e), this.projection.isVisible?.() !== !1 && c.getState().setLastSeqId(this.lastSeqId);
|
|
1852
|
+
}
|
|
1853
|
+
stopActivity(e) {
|
|
1854
|
+
let t = c.getState(), n = this.projection.isVisible?.() !== !1;
|
|
1855
|
+
this.streamingKey ? t.stopSessionActivity(this.streamingKey, e, n) : n && t.stopActivity(e);
|
|
1798
1856
|
}
|
|
1799
1857
|
get stage() {
|
|
1800
1858
|
return this._stage;
|
|
@@ -1806,9 +1864,9 @@ var qt = {
|
|
|
1806
1864
|
this.lastControlCommand = e;
|
|
1807
1865
|
let t;
|
|
1808
1866
|
try {
|
|
1809
|
-
t =
|
|
1867
|
+
t = Oe(await this.api.submitControl(e));
|
|
1810
1868
|
} catch (e) {
|
|
1811
|
-
if (e instanceof
|
|
1869
|
+
if (e instanceof U) return this.controlStateValue = {
|
|
1812
1870
|
phase: "contract_mismatch",
|
|
1813
1871
|
error: null,
|
|
1814
1872
|
receipt: null
|
|
@@ -1880,12 +1938,14 @@ var qt = {
|
|
|
1880
1938
|
return this.submitControl(e);
|
|
1881
1939
|
}
|
|
1882
1940
|
updateConfig(e) {
|
|
1883
|
-
|
|
1941
|
+
let t = {
|
|
1884
1942
|
...e,
|
|
1885
1943
|
apiFormats: [...e.apiFormats]
|
|
1886
1944
|
};
|
|
1945
|
+
this._stage === "idle" ? this.config = t : this.pendingConfig = t;
|
|
1887
1946
|
}
|
|
1888
1947
|
emit(e) {
|
|
1948
|
+
e.type === "stream_event" && typeof e.event.SeqId == "number" && this.recordCursor(e.event.SeqId);
|
|
1889
1949
|
let t = "sessionId" in e ? e : {
|
|
1890
1950
|
...e,
|
|
1891
1951
|
sessionId: this.activeSessionId
|
|
@@ -1894,7 +1954,7 @@ var qt = {
|
|
|
1894
1954
|
}
|
|
1895
1955
|
getAguiClient(e) {
|
|
1896
1956
|
let t = this.config.hostedChatTransport;
|
|
1897
|
-
return t?.Protocol !== "ag-ui" || !t.Endpoint ? null : ((!this.aguiClient || this.aguiThreadSessionId !== e) && (this.aguiClient = new
|
|
1957
|
+
return t?.Protocol !== "ag-ui" || !t.Endpoint ? null : ((!this.aguiClient || this.aguiThreadSessionId !== e) && (this.aguiClient = new Gt({
|
|
1898
1958
|
url: t.Endpoint,
|
|
1899
1959
|
agentId: this.config.agentId,
|
|
1900
1960
|
threadId: e,
|
|
@@ -1902,8 +1962,9 @@ var qt = {
|
|
|
1902
1962
|
}), this.aguiThreadSessionId = e), this.aguiClient);
|
|
1903
1963
|
}
|
|
1904
1964
|
setStage(e) {
|
|
1905
|
-
|
|
1906
|
-
|
|
1965
|
+
if (this._stage === e) return;
|
|
1966
|
+
let t = Xt[this._stage];
|
|
1967
|
+
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({
|
|
1907
1968
|
type: "stage_changed",
|
|
1908
1969
|
stage: e
|
|
1909
1970
|
});
|
|
@@ -1915,17 +1976,19 @@ var qt = {
|
|
|
1915
1976
|
}
|
|
1916
1977
|
start(e) {
|
|
1917
1978
|
if (this._stage !== "idle") return !1;
|
|
1918
|
-
|
|
1919
|
-
|
|
1979
|
+
let t = ++this.operationEpoch;
|
|
1980
|
+
this.abortController = new AbortController(), this.activeSessionId = e.sessionId || null, this.invocationId = "", this.recordCursor(0), this.setStage(this.activeSessionId ? "connecting" : "creating-session");
|
|
1981
|
+
let n = e.responsesInput !== void 0;
|
|
1920
1982
|
return (async () => {
|
|
1921
|
-
let
|
|
1983
|
+
let r = e.sessionId || null, i = "unknown";
|
|
1922
1984
|
try {
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1985
|
+
if (r ||= await this.createSession(e), !r) throw Error("运行时未返回会话身份,请确认创建结果后重试。");
|
|
1986
|
+
this.activeSessionId = r;
|
|
1987
|
+
let a = Yt();
|
|
1988
|
+
this.publishInvocation(a), e.onInvocationCreated?.(a), this.recordCursor(0);
|
|
1989
|
+
let o = n ? null : await this.getConversationBootstrap(r);
|
|
1990
|
+
if (o && this.config.conversationClient) {
|
|
1991
|
+
let n = await this.buildCanonicalConversationInput(o, r, a, e);
|
|
1929
1992
|
this.setStage("connecting"), this.emit({
|
|
1930
1993
|
type: "activity",
|
|
1931
1994
|
phase: "连接会话运行时",
|
|
@@ -1937,20 +2000,22 @@ var qt = {
|
|
|
1937
2000
|
status: "waiting",
|
|
1938
2001
|
countEvent: !1
|
|
1939
2002
|
});
|
|
1940
|
-
let
|
|
1941
|
-
bootstrap:
|
|
1942
|
-
input:
|
|
2003
|
+
let s = await this.config.conversationClient.streamTurn({
|
|
2004
|
+
bootstrap: o,
|
|
2005
|
+
input: n,
|
|
1943
2006
|
signal: this.abortController?.signal,
|
|
1944
|
-
onUpdate: (
|
|
1945
|
-
|
|
2007
|
+
onUpdate: (t) => {
|
|
2008
|
+
t.runId && (this.publishInvocation(t.runId), e.onInvocationCreated?.(t.runId)), this.emit({
|
|
1946
2009
|
type: "conversation_snapshot",
|
|
1947
|
-
result:
|
|
1948
|
-
sessionId:
|
|
2010
|
+
result: t,
|
|
2011
|
+
sessionId: r,
|
|
2012
|
+
optimisticMessageId: e.optimisticMessageId
|
|
1949
2013
|
});
|
|
1950
2014
|
}
|
|
1951
2015
|
});
|
|
1952
|
-
if (
|
|
1953
|
-
|
|
2016
|
+
if (this.operationEpoch !== t) return;
|
|
2017
|
+
if (s.presentation.terminalStatus === "failed") {
|
|
2018
|
+
i = "failed", this.setStage("error"), this.emit({
|
|
1954
2019
|
type: "activity",
|
|
1955
2020
|
phase: "运行失败",
|
|
1956
2021
|
status: "failed",
|
|
@@ -1958,43 +2023,43 @@ var qt = {
|
|
|
1958
2023
|
});
|
|
1959
2024
|
return;
|
|
1960
2025
|
}
|
|
1961
|
-
this.setStage("completing"), this.emit({
|
|
2026
|
+
this.setStage("completing"), i = "completed", this.emit({
|
|
1962
2027
|
type: "activity",
|
|
1963
2028
|
phase: "运行完成",
|
|
1964
2029
|
status: "completed",
|
|
1965
2030
|
countEvent: !1
|
|
1966
2031
|
}), this.emit({
|
|
1967
2032
|
type: "stream_ended",
|
|
1968
|
-
sessionId:
|
|
1969
|
-
runId:
|
|
2033
|
+
sessionId: r,
|
|
2034
|
+
runId: s.runId
|
|
1970
2035
|
});
|
|
1971
2036
|
return;
|
|
1972
2037
|
}
|
|
1973
|
-
let
|
|
2038
|
+
let s = await this.uploadFiles(e, n);
|
|
1974
2039
|
this.setStage("connecting"), this.emit({
|
|
1975
2040
|
type: "activity",
|
|
1976
2041
|
phase: "连接运行时",
|
|
1977
2042
|
status: "connecting",
|
|
1978
2043
|
countEvent: !1
|
|
1979
2044
|
});
|
|
1980
|
-
let
|
|
2045
|
+
let c = n ? "responses" : Lt({
|
|
1981
2046
|
agentFramework: this.config.agentFramework,
|
|
1982
2047
|
apiFormats: this.config.apiFormats
|
|
1983
|
-
}),
|
|
1984
|
-
if (
|
|
2048
|
+
}), l = kt(c), u = l.createState(), d = this.config.hostedChatTransport, f = !n && !e.executionMode && e.attachments.length === 0 && d?.Protocol === "ag-ui" ? this.getAguiClient(r) : null;
|
|
2049
|
+
if (f && d) {
|
|
1985
2050
|
this.setStage("streaming"), this.emit({
|
|
1986
2051
|
type: "activity",
|
|
1987
2052
|
phase: "等待 AG-UI 输出",
|
|
1988
2053
|
status: "waiting",
|
|
1989
2054
|
countEvent: !1
|
|
1990
2055
|
});
|
|
1991
|
-
let t = await
|
|
2056
|
+
let t = await f.run(e.text, a, this.abortController?.signal);
|
|
1992
2057
|
if (t.status === "interrupted") {
|
|
1993
|
-
this.setStage("completing"), this.emit({ type: "stream_ended" });
|
|
2058
|
+
i = "cancelled", this.setStage("completing"), this.emit({ type: "stream_ended" });
|
|
1994
2059
|
return;
|
|
1995
2060
|
}
|
|
1996
2061
|
if (t.status !== "completed") {
|
|
1997
|
-
this.setStage("error"), this.emit({
|
|
2062
|
+
i = "failed", this.setStage("error"), this.emit({
|
|
1998
2063
|
type: "activity",
|
|
1999
2064
|
phase: "AG-UI 运行失败",
|
|
2000
2065
|
status: "failed",
|
|
@@ -2002,7 +2067,7 @@ var qt = {
|
|
|
2002
2067
|
});
|
|
2003
2068
|
return;
|
|
2004
2069
|
}
|
|
2005
|
-
this.setStage("completing"), this.emit({
|
|
2070
|
+
this.setStage("completing"), i = "completed", this.emit({
|
|
2006
2071
|
type: "activity",
|
|
2007
2072
|
phase: "运行完成",
|
|
2008
2073
|
status: "completed",
|
|
@@ -2010,16 +2075,17 @@ var qt = {
|
|
|
2010
2075
|
}), this.emit({ type: "stream_ended" });
|
|
2011
2076
|
return;
|
|
2012
2077
|
}
|
|
2013
|
-
let
|
|
2078
|
+
let p = this.buildRequestBody(r, c, n, e, s, a), m = await this.api.runAgent(p, { signal: this.abortController?.signal });
|
|
2014
2079
|
this.setStage("streaming"), this.emit({
|
|
2015
2080
|
type: "activity",
|
|
2016
2081
|
phase: "等待首个输出",
|
|
2017
2082
|
status: "waiting",
|
|
2018
2083
|
countEvent: !1
|
|
2019
2084
|
});
|
|
2020
|
-
let
|
|
2021
|
-
if (
|
|
2022
|
-
|
|
2085
|
+
let h = `msg-${Date.now()}`, g = await I(m), _;
|
|
2086
|
+
if (_ = g.receipt ? await this.consumeKernelRunEvents(r, a, g.receipt, h) : await this.consumeStream(g.stream, l, u, h, a), this.operationEpoch !== t) return;
|
|
2087
|
+
if (_.terminalStatus === "cancelled") {
|
|
2088
|
+
i = "cancelled", this.setStage("stopping"), this.stopActivity("运行时已取消本次执行。"), this.emit({
|
|
2023
2089
|
type: "activity",
|
|
2024
2090
|
phase: "运行已取消",
|
|
2025
2091
|
status: "stopped",
|
|
@@ -2027,66 +2093,74 @@ var qt = {
|
|
|
2027
2093
|
}), this.setStage("cancelled");
|
|
2028
2094
|
return;
|
|
2029
2095
|
}
|
|
2030
|
-
if (
|
|
2031
|
-
this.setStage("error"), this.emit({
|
|
2096
|
+
if (_.terminalStatus && _.terminalStatus !== "completed") {
|
|
2097
|
+
i = "failed", this.setStage("error"), this.emit({
|
|
2032
2098
|
type: "activity",
|
|
2033
|
-
phase:
|
|
2099
|
+
phase: _.terminalStatus === "incomplete" ? "运行中断" : "运行失败",
|
|
2034
2100
|
status: "failed",
|
|
2035
2101
|
countEvent: !1
|
|
2036
2102
|
});
|
|
2037
2103
|
return;
|
|
2038
2104
|
}
|
|
2039
|
-
this.setStage("completing"), this.emit({
|
|
2105
|
+
this.setStage("completing"), i = "completed", this.emit({
|
|
2040
2106
|
type: "activity",
|
|
2041
2107
|
phase: "运行完成",
|
|
2042
2108
|
status: "completed",
|
|
2043
2109
|
countEvent: !1
|
|
2044
2110
|
}), this.emit({ type: "stream_ended" });
|
|
2045
2111
|
} catch (e) {
|
|
2046
|
-
if (this.failCompaction(),
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
this.resumeRun({
|
|
2056
|
-
sessionId: this.activeSessionId,
|
|
2057
|
-
invocationId: t,
|
|
2058
|
-
afterSeqId: e
|
|
2112
|
+
if (this.failCompaction(), e instanceof DOMException && e.name === "AbortError" || e instanceof j && e.code === "conversation_aborted") i = "cancelled";
|
|
2113
|
+
else {
|
|
2114
|
+
let t = e instanceof TypeError;
|
|
2115
|
+
if (i = t ? "unknown" : "failed", console.error("[RunEngine] start() error:", e), t) {
|
|
2116
|
+
this.setStage("recovering"), this.emit({
|
|
2117
|
+
type: "activity",
|
|
2118
|
+
phase: "网络异常,尝试重连",
|
|
2119
|
+
status: "waiting",
|
|
2120
|
+
countEvent: !1
|
|
2059
2121
|
});
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2122
|
+
let t = this.lastSeqId, n = this.invocationId;
|
|
2123
|
+
if (t > 0 && n && this.activeSessionId) try {
|
|
2124
|
+
await this.resumeRun({
|
|
2125
|
+
sessionId: this.activeSessionId,
|
|
2126
|
+
invocationId: n,
|
|
2127
|
+
afterSeqId: t
|
|
2128
|
+
});
|
|
2129
|
+
return;
|
|
2130
|
+
} catch (e) {
|
|
2131
|
+
console.warn("[RunEngine] afterSeqId resume failed, fall back to error:", e);
|
|
2132
|
+
}
|
|
2133
|
+
this.setStage("error"), this.emit({
|
|
2134
|
+
type: "error",
|
|
2135
|
+
error: e instanceof Error ? e : Error(String(e))
|
|
2136
|
+
});
|
|
2137
|
+
} else e instanceof V && e.code === 429 ? (this.setStage("error"), this.emit({
|
|
2138
|
+
type: "rate_limited",
|
|
2139
|
+
message: e.message || "请求过于频繁,请稍后重试",
|
|
2140
|
+
sessionId: r
|
|
2141
|
+
})) : (this.setStage("error"), this.emit({
|
|
2142
|
+
type: "error",
|
|
2143
|
+
error: e instanceof Error ? e : Error(String(e))
|
|
2144
|
+
}));
|
|
2145
|
+
}
|
|
2072
2146
|
} finally {
|
|
2073
|
-
c.getState().setSessionStreaming(
|
|
2147
|
+
this.operationEpoch === t && (c.getState().setSessionStreaming(this.streamingKey, !1), this.setStage("idle"), this.activeCompactionId = null, this.activeSessionId = null, e.onSettled?.(r, i));
|
|
2074
2148
|
}
|
|
2075
2149
|
})(), !0;
|
|
2076
2150
|
}
|
|
2077
2151
|
stop() {
|
|
2078
2152
|
if (this._stage === "idle") return;
|
|
2079
2153
|
this.setStage("stopping");
|
|
2080
|
-
let e =
|
|
2154
|
+
let e = this.invocationId;
|
|
2081
2155
|
e && this.activeSessionId && this.api.cancelRun(this.config.agentId, this.activeSessionId, e).catch((e) => {
|
|
2082
2156
|
console.warn("[RunEngine] cancelRun on stop failed:", e);
|
|
2083
|
-
}), this.abortController?.abort(), this.aguiClient?.abort(),
|
|
2157
|
+
}), this.abortController?.abort(), this.aguiClient?.abort(), this.stopActivity(e ? "已向运行时发送取消请求;如果当前框架只支持协作式取消,后台可能会在下一个安全点停止。" : void 0), this.publishInvocation(""), this.setStage("cancelled"), this.emit({
|
|
2084
2158
|
type: "system_message",
|
|
2085
2159
|
content: e ? "已请求取消本次运行。" : "已停止接收本次输出;如果运行时不支持取消,后台执行可能仍会继续。"
|
|
2086
2160
|
});
|
|
2087
2161
|
}
|
|
2088
2162
|
disconnect() {
|
|
2089
|
-
this._stage !== "idle" && (this.abortController?.abort(), this.aguiClient?.abort(), c.getState().setSessionStreaming(this.
|
|
2163
|
+
this._stage !== "idle" && (this.operationEpoch += 1, this.abortController?.abort(), this.aguiClient?.abort(), c.getState().setSessionStreaming(this.streamingKey, !1), this.projection.isVisible?.() !== !1 && c.getState().clearActivity(), this._stage = "idle", this.activeCompactionId = null, this.activeSessionId = null);
|
|
2090
2164
|
}
|
|
2091
2165
|
async cancelRemote(e) {
|
|
2092
2166
|
try {
|
|
@@ -2096,84 +2170,91 @@ var qt = {
|
|
|
2096
2170
|
}
|
|
2097
2171
|
this.stop();
|
|
2098
2172
|
}
|
|
2099
|
-
resumeRun(e) {
|
|
2100
|
-
this.abortController?.abort(), this.abortController = new AbortController(), this.activeSessionId = e.sessionId,
|
|
2173
|
+
async resumeRun(e) {
|
|
2174
|
+
this.abortController?.abort(), this.abortController = new AbortController(), this.activeSessionId = e.sessionId, this.publishInvocation(e.invocationId), this.setStage("connecting"), this.emit({
|
|
2101
2175
|
type: "activity",
|
|
2102
2176
|
phase: "恢复运行事件订阅",
|
|
2103
2177
|
status: "connecting",
|
|
2104
2178
|
countEvent: !1
|
|
2105
|
-
})
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
}
|
|
2179
|
+
});
|
|
2180
|
+
let t = null;
|
|
2181
|
+
try {
|
|
2182
|
+
let n = await this.api.subscribeRunEvents({
|
|
2183
|
+
sessionId: e.sessionId,
|
|
2184
|
+
invocationId: e.invocationId,
|
|
2185
|
+
afterSeqId: e.afterSeqId
|
|
2186
|
+
}, { signal: this.abortController?.signal });
|
|
2187
|
+
this.setStage("streaming"), this.emit({
|
|
2188
|
+
type: "activity",
|
|
2189
|
+
phase: "等待恢复事件",
|
|
2190
|
+
status: "waiting",
|
|
2191
|
+
countEvent: !1
|
|
2192
|
+
});
|
|
2193
|
+
let r = n.getReader(), i = new TextDecoder(), a = "";
|
|
2194
|
+
for (;;) {
|
|
2195
|
+
let { value: e, done: n } = await r.read();
|
|
2196
|
+
if (n) break;
|
|
2197
|
+
a += i.decode(e, { stream: !0 });
|
|
2198
|
+
let { chunks: o, remainder: s } = jt(a);
|
|
2199
|
+
a = s;
|
|
2200
|
+
for (let e of o) {
|
|
2201
|
+
if (!e.trim()) continue;
|
|
2202
|
+
let n = Y(e);
|
|
2203
|
+
for (let e of n) e.eventName === "__done__" || e.eventName === "__ping__" || (this.emit({
|
|
2204
|
+
type: "activity",
|
|
2205
|
+
phase: "收到恢复事件",
|
|
2206
|
+
status: "running"
|
|
2207
|
+
}), this.emit({
|
|
2208
|
+
type: "stream_event",
|
|
2209
|
+
event: e.data
|
|
2210
|
+
}), t = qt(e.data) || t);
|
|
2138
2211
|
}
|
|
2139
|
-
this.setStage("completing"), t === "cancelled" || t === "canceled" || t === "aborted" ? this.emit({
|
|
2140
|
-
type: "activity",
|
|
2141
|
-
phase: "后台长任务已取消",
|
|
2142
|
-
status: "stopped",
|
|
2143
|
-
countEvent: !1
|
|
2144
|
-
}) : t === "interrupted" ? this.emit({
|
|
2145
|
-
type: "activity",
|
|
2146
|
-
phase: "后台长任务已中断",
|
|
2147
|
-
status: "stopped",
|
|
2148
|
-
countEvent: !1
|
|
2149
|
-
}) : t === "failed" || t === "error" ? this.emit({
|
|
2150
|
-
type: "activity",
|
|
2151
|
-
phase: "后台长任务失败",
|
|
2152
|
-
status: "failed",
|
|
2153
|
-
countEvent: !1
|
|
2154
|
-
}) : t === "resume_failed" ? this.emit({
|
|
2155
|
-
type: "activity",
|
|
2156
|
-
phase: "后台长任务恢复失败",
|
|
2157
|
-
status: "failed",
|
|
2158
|
-
countEvent: !1
|
|
2159
|
-
}) : this.emit({
|
|
2160
|
-
type: "activity",
|
|
2161
|
-
phase: "后台长任务已完成",
|
|
2162
|
-
status: "completed",
|
|
2163
|
-
countEvent: !1
|
|
2164
|
-
}), this.emit({ type: "stream_ended" }), e.onSessionReloadNeeded?.();
|
|
2165
|
-
} catch (e) {
|
|
2166
|
-
e instanceof DOMException && e.name === "AbortError" || console.error("Failed to subscribe to run events:", e);
|
|
2167
|
-
} finally {
|
|
2168
|
-
c.getState().setSessionStreaming(e.sessionId, !1), c.getState().setCurrentRunId(""), this.setStage("idle"), this.activeSessionId = null;
|
|
2169
2212
|
}
|
|
2170
|
-
|
|
2213
|
+
this.setStage("completing"), t === "cancelled" || t === "canceled" || t === "aborted" ? this.emit({
|
|
2214
|
+
type: "activity",
|
|
2215
|
+
phase: "后台长任务已取消",
|
|
2216
|
+
status: "stopped",
|
|
2217
|
+
countEvent: !1
|
|
2218
|
+
}) : t === "interrupted" ? this.emit({
|
|
2219
|
+
type: "activity",
|
|
2220
|
+
phase: "后台长任务已中断",
|
|
2221
|
+
status: "stopped",
|
|
2222
|
+
countEvent: !1
|
|
2223
|
+
}) : t === "failed" || t === "error" ? this.emit({
|
|
2224
|
+
type: "activity",
|
|
2225
|
+
phase: "后台长任务失败",
|
|
2226
|
+
status: "failed",
|
|
2227
|
+
countEvent: !1
|
|
2228
|
+
}) : t === "resume_failed" ? this.emit({
|
|
2229
|
+
type: "activity",
|
|
2230
|
+
phase: "后台长任务恢复失败",
|
|
2231
|
+
status: "failed",
|
|
2232
|
+
countEvent: !1
|
|
2233
|
+
}) : t ? this.emit({
|
|
2234
|
+
type: "activity",
|
|
2235
|
+
phase: "后台长任务已完成",
|
|
2236
|
+
status: "completed",
|
|
2237
|
+
countEvent: !1
|
|
2238
|
+
}) : this.emit({
|
|
2239
|
+
type: "activity",
|
|
2240
|
+
phase: "后台长任务状态待确认",
|
|
2241
|
+
status: "waiting",
|
|
2242
|
+
detail: "事件流已结束,但运行时尚未提供终态;正在等待会话状态对账。",
|
|
2243
|
+
countEvent: !1
|
|
2244
|
+
}), t && this.emit({ type: "stream_ended" }), e.onSessionReloadNeeded?.();
|
|
2245
|
+
} catch (e) {
|
|
2246
|
+
e instanceof DOMException && e.name === "AbortError" || console.error("Failed to subscribe to run events:", e);
|
|
2247
|
+
} finally {
|
|
2248
|
+
c.getState().setSessionStreaming(e.sessionId, !1), this.publishInvocation(""), this.setStage("idle"), this.activeSessionId = null;
|
|
2249
|
+
}
|
|
2171
2250
|
}
|
|
2172
2251
|
resumeCheckpoint(e) {
|
|
2173
2252
|
if (this._stage !== "idle") return !1;
|
|
2253
|
+
let t = ++this.operationEpoch;
|
|
2174
2254
|
this.abortController = new AbortController(), this.activeSessionId = e.sessionId;
|
|
2175
|
-
let
|
|
2176
|
-
return
|
|
2255
|
+
let n = Yt();
|
|
2256
|
+
return this.publishInvocation(n), (async () => {
|
|
2257
|
+
let r = "unknown";
|
|
2177
2258
|
try {
|
|
2178
2259
|
if (this.setStage("connecting"), this.emit({
|
|
2179
2260
|
type: "activity",
|
|
@@ -2198,14 +2279,14 @@ var qt = {
|
|
|
2198
2279
|
} catch (e) {
|
|
2199
2280
|
console.warn("[RunEngine] checkpoint resume preview failed:", e);
|
|
2200
2281
|
}
|
|
2201
|
-
let
|
|
2282
|
+
let t = await this.api.resumeRun({
|
|
2202
2283
|
agentId: this.config.agentId,
|
|
2203
2284
|
sessionId: e.sessionId,
|
|
2204
2285
|
runId: e.runId,
|
|
2205
2286
|
checkpointId: e.checkpointId,
|
|
2206
2287
|
resumeAttemptId: e.resumeAttemptId,
|
|
2207
|
-
invocationId:
|
|
2208
|
-
}, { signal: this.abortController?.signal }),
|
|
2288
|
+
invocationId: n
|
|
2289
|
+
}, { signal: this.abortController?.signal }), i = kt("responses"), a = i.createState();
|
|
2209
2290
|
this.setStage("streaming"), this.emit({
|
|
2210
2291
|
type: "activity",
|
|
2211
2292
|
source: "restore",
|
|
@@ -2213,10 +2294,10 @@ var qt = {
|
|
|
2213
2294
|
status: "waiting",
|
|
2214
2295
|
countEvent: !1
|
|
2215
2296
|
});
|
|
2216
|
-
let
|
|
2217
|
-
if (
|
|
2218
|
-
if (
|
|
2219
|
-
this.setStage("stopping"),
|
|
2297
|
+
let o = `msg-${Date.now()}`, s = await this.consumeStream(t, i, a, o, n);
|
|
2298
|
+
if (s.terminalStatus && s.terminalStatus !== "completed") {
|
|
2299
|
+
if (s.terminalStatus === "cancelled") {
|
|
2300
|
+
r = "cancelled", this.setStage("stopping"), this.stopActivity("运行时已取消本次恢复。"), this.emit({
|
|
2220
2301
|
type: "activity",
|
|
2221
2302
|
source: "restore",
|
|
2222
2303
|
phase: "恢复已取消",
|
|
@@ -2225,16 +2306,16 @@ var qt = {
|
|
|
2225
2306
|
}), this.setStage("cancelled");
|
|
2226
2307
|
return;
|
|
2227
2308
|
}
|
|
2228
|
-
this.setStage("error"), this.emit({
|
|
2309
|
+
this.setStage("error"), r = "failed", this.emit({
|
|
2229
2310
|
type: "activity",
|
|
2230
2311
|
source: "restore",
|
|
2231
|
-
phase:
|
|
2312
|
+
phase: s.terminalStatus === "incomplete" ? "恢复中断" : "恢复失败",
|
|
2232
2313
|
status: "failed",
|
|
2233
2314
|
countEvent: !1
|
|
2234
2315
|
});
|
|
2235
2316
|
return;
|
|
2236
2317
|
}
|
|
2237
|
-
this.setStage("completing"), this.emit({
|
|
2318
|
+
this.setStage("completing"), r = "completed", this.emit({
|
|
2238
2319
|
type: "activity",
|
|
2239
2320
|
source: "restore",
|
|
2240
2321
|
phase: "恢复完成",
|
|
@@ -2242,12 +2323,12 @@ var qt = {
|
|
|
2242
2323
|
countEvent: !1
|
|
2243
2324
|
}), this.emit({ type: "stream_ended" });
|
|
2244
2325
|
} catch (e) {
|
|
2245
|
-
e instanceof DOMException && e.name === "AbortError"
|
|
2326
|
+
e instanceof DOMException && e.name === "AbortError" ? r = "cancelled" : (r = "failed", console.error("[RunEngine] resumeCheckpoint() error:", e), this.setStage("error"), this.emit({
|
|
2246
2327
|
type: "error",
|
|
2247
2328
|
error: e instanceof Error ? e : Error(String(e))
|
|
2248
2329
|
}));
|
|
2249
2330
|
} finally {
|
|
2250
|
-
c.getState().setSessionStreaming(e.sessionId, !1),
|
|
2331
|
+
this.operationEpoch === t && (c.getState().setSessionStreaming(e.sessionId, !1), this.publishInvocation(""), this.setStage("idle"), this.activeSessionId = null, e.onSettled?.(e.sessionId, r));
|
|
2251
2332
|
}
|
|
2252
2333
|
})(), !0;
|
|
2253
2334
|
}
|
|
@@ -2257,31 +2338,33 @@ var qt = {
|
|
|
2257
2338
|
if (!t) return !1;
|
|
2258
2339
|
let n = this.getAguiClient(t);
|
|
2259
2340
|
if (!n) return !1;
|
|
2341
|
+
let r = ++this.operationEpoch;
|
|
2260
2342
|
this.activeSessionId = t;
|
|
2261
|
-
let
|
|
2262
|
-
return
|
|
2343
|
+
let i = Yt();
|
|
2344
|
+
return this.publishInvocation(i), this.setStage("connecting"), this.emit({
|
|
2263
2345
|
type: "activity",
|
|
2264
2346
|
phase: "提交人工确认",
|
|
2265
2347
|
status: "connecting",
|
|
2266
2348
|
countEvent: !1
|
|
2267
2349
|
}), (async () => {
|
|
2350
|
+
let a = "unknown";
|
|
2268
2351
|
try {
|
|
2269
2352
|
this.setStage("streaming");
|
|
2270
|
-
let t = await n.resume(
|
|
2353
|
+
let t = await n.resume(i, {
|
|
2271
2354
|
interruptId: e.interruptId,
|
|
2272
2355
|
status: e.status,
|
|
2273
2356
|
payload: e.payload
|
|
2274
|
-
}),
|
|
2357
|
+
}), r = e.payload && typeof e.payload == "object" ? e.payload : {}, o = String(r.decision || r.type || "").toLowerCase();
|
|
2275
2358
|
if (this.emit({
|
|
2276
2359
|
type: "approval_resolved",
|
|
2277
2360
|
approvalRequestId: e.interruptId,
|
|
2278
|
-
decision: e.status === "cancelled" ? "cancelled" :
|
|
2361
|
+
decision: e.status === "cancelled" ? "cancelled" : o === "reject" || o === "rejected" ? "rejected" : "approved"
|
|
2279
2362
|
}), t.status === "interrupted") {
|
|
2280
|
-
this.setStage("completing"), this.emit({ type: "stream_ended" });
|
|
2363
|
+
a = "cancelled", this.setStage("completing"), this.emit({ type: "stream_ended" });
|
|
2281
2364
|
return;
|
|
2282
2365
|
}
|
|
2283
2366
|
if (t.status !== "completed") {
|
|
2284
|
-
this.setStage("error"), this.emit({
|
|
2367
|
+
a = "failed", this.setStage("error"), this.emit({
|
|
2285
2368
|
type: "activity",
|
|
2286
2369
|
phase: "人工确认恢复失败",
|
|
2287
2370
|
status: "failed",
|
|
@@ -2289,30 +2372,28 @@ var qt = {
|
|
|
2289
2372
|
});
|
|
2290
2373
|
return;
|
|
2291
2374
|
}
|
|
2292
|
-
this.setStage("completing"), this.emit({
|
|
2375
|
+
this.setStage("completing"), a = "completed", this.emit({
|
|
2293
2376
|
type: "activity",
|
|
2294
2377
|
phase: "运行完成",
|
|
2295
2378
|
status: "completed",
|
|
2296
2379
|
countEvent: !1
|
|
2297
2380
|
}), this.emit({ type: "stream_ended" });
|
|
2298
2381
|
} catch (e) {
|
|
2299
|
-
this.setStage("error"), this.emit({
|
|
2382
|
+
a = e instanceof DOMException && e.name === "AbortError" ? "cancelled" : "failed", this.setStage("error"), this.emit({
|
|
2300
2383
|
type: "error",
|
|
2301
2384
|
error: e instanceof Error ? e : Error(String(e))
|
|
2302
2385
|
});
|
|
2303
2386
|
} finally {
|
|
2304
|
-
|
|
2387
|
+
this.operationEpoch === r && (this.publishInvocation(""), this.setStage("idle"), this.activeSessionId = null, e.onSettled?.(t, a));
|
|
2305
2388
|
}
|
|
2306
2389
|
})(), !0;
|
|
2307
2390
|
}
|
|
2308
2391
|
async createSession(e) {
|
|
2309
|
-
this.
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
return e instanceof DOMException && e.name === "AbortError" || console.error("Failed to create session:", e), null;
|
|
2315
|
-
}
|
|
2392
|
+
let t = await this.api.createSession(this.config.agentId, { signal: this.abortController?.signal });
|
|
2393
|
+
this.abortController?.signal.throwIfAborted();
|
|
2394
|
+
let n = t.SessionId || null;
|
|
2395
|
+
if (!n) throw Error("运行时未返回会话身份,请确认创建结果后重试。");
|
|
2396
|
+
return this.activeSessionId = n, e.onSessionCreated?.(n), e.onSessionUpsert?.(n), n;
|
|
2316
2397
|
}
|
|
2317
2398
|
async getConversationBootstrap(e) {
|
|
2318
2399
|
let t = this.config.conversationClient;
|
|
@@ -2320,7 +2401,7 @@ var qt = {
|
|
|
2320
2401
|
try {
|
|
2321
2402
|
return await t.getSurface(this.config.agentId, e, { signal: this.abortController?.signal });
|
|
2322
2403
|
} catch (e) {
|
|
2323
|
-
if (e instanceof
|
|
2404
|
+
if (e instanceof j && e.code === "conversation_http_error" && e.status === 404) return null;
|
|
2324
2405
|
throw e;
|
|
2325
2406
|
}
|
|
2326
2407
|
}
|
|
@@ -2332,39 +2413,39 @@ var qt = {
|
|
|
2332
2413
|
});
|
|
2333
2414
|
for (let t of r.attachments) {
|
|
2334
2415
|
let n = t.type.startsWith("image/") ? "attachment.image" : "attachment.file";
|
|
2335
|
-
if (!
|
|
2416
|
+
if (!A(e.surface, n)) throw new j("conversation_input_unsupported", "Conversation attachment is not declared by the active surface.", { capability: n });
|
|
2336
2417
|
}
|
|
2337
2418
|
r.attachments.length > 0 && i.push(...await this.uploadCanonicalAttachments(r.attachments));
|
|
2338
|
-
let o =
|
|
2419
|
+
let o = Pt(this.config.thinkingMode), s = k({
|
|
2339
2420
|
inputId: `input:${n}`,
|
|
2340
2421
|
sessionId: t,
|
|
2341
2422
|
idempotencyKey: `conversation:${n}`,
|
|
2342
2423
|
parts: i,
|
|
2343
|
-
...this.config.selectedModel &&
|
|
2344
|
-
...o !== "auto" &&
|
|
2424
|
+
...this.config.selectedModel && A(e.surface, "model.select") ? { modelRef: this.config.selectedModel } : {},
|
|
2425
|
+
...o !== "auto" && A(e.surface, "reasoning.effort") ? { reasoning: o } : {},
|
|
2345
2426
|
extensions: {
|
|
2346
|
-
...this.config.permissionMode &&
|
|
2427
|
+
...this.config.permissionMode && A(e.surface, "approval") ? { "ksadk.approval": this.config.permissionMode } : {},
|
|
2347
2428
|
...r.executionMode === "plan" ? { "ksadk.collaboration": "plan" } : {},
|
|
2348
2429
|
...r.executionMode === "goal" && a ? { "ksadk.goal": a } : {}
|
|
2349
2430
|
}
|
|
2350
2431
|
});
|
|
2351
|
-
return
|
|
2432
|
+
return O(e.surface, s);
|
|
2352
2433
|
}
|
|
2353
2434
|
async uploadCanonicalAttachments(e) {
|
|
2354
2435
|
this.setStage("uploading-files");
|
|
2355
2436
|
let t = [];
|
|
2356
2437
|
for (let n of e) {
|
|
2357
|
-
if (n.size > 100 * 1024 * 1024) throw new
|
|
2438
|
+
if (n.size > 100 * 1024 * 1024) throw new j("conversation_input_unsupported", "Conversation attachment exceeds the Hosted UI upload limit.", { capability: n.type.startsWith("image/") ? "attachment.image" : "attachment.file" });
|
|
2358
2439
|
let e = new FormData();
|
|
2359
2440
|
e.append("file", n), e.append("AgentId", this.config.agentId);
|
|
2360
2441
|
let r;
|
|
2361
2442
|
try {
|
|
2362
2443
|
r = await this.api.uploadFile(e, { signal: this.abortController?.signal });
|
|
2363
2444
|
} catch (e) {
|
|
2364
|
-
throw new
|
|
2445
|
+
throw new j("conversation_http_error", "Conversation attachment upload failed.", { cause: e });
|
|
2365
2446
|
}
|
|
2366
2447
|
let i = r?.FileData?.fileUri;
|
|
2367
|
-
if (!i) throw new
|
|
2448
|
+
if (!i) throw new j("conversation_contract_mismatch", "Conversation attachment upload did not return an attachment reference.");
|
|
2368
2449
|
t.push({
|
|
2369
2450
|
kind: "attachment",
|
|
2370
2451
|
attachmentRef: i,
|
|
@@ -2395,7 +2476,7 @@ var qt = {
|
|
|
2395
2476
|
} catch (e) {
|
|
2396
2477
|
this.emit({
|
|
2397
2478
|
type: "system_message",
|
|
2398
|
-
content: `【系统提示】图片 ${t.name} 读取失败,原因: ${
|
|
2479
|
+
content: `【系统提示】图片 ${t.name} 读取失败,原因: ${Mt(e)}`
|
|
2399
2480
|
});
|
|
2400
2481
|
}
|
|
2401
2482
|
continue;
|
|
@@ -2412,7 +2493,7 @@ var qt = {
|
|
|
2412
2493
|
} catch (e) {
|
|
2413
2494
|
this.emit({
|
|
2414
2495
|
type: "system_message",
|
|
2415
|
-
content: `【系统提示】文件 ${t.name} 上传失败,原因: ${
|
|
2496
|
+
content: `【系统提示】文件 ${t.name} 上传失败,原因: ${Mt(e)}`
|
|
2416
2497
|
});
|
|
2417
2498
|
}
|
|
2418
2499
|
}
|
|
@@ -2432,7 +2513,7 @@ var qt = {
|
|
|
2432
2513
|
ApiFormat: t,
|
|
2433
2514
|
Model: this.config.selectedModel || void 0,
|
|
2434
2515
|
ModelMetadata: this.config.selectedModelMetadata || void 0,
|
|
2435
|
-
ModelOptions:
|
|
2516
|
+
ModelOptions: Ft(Pt(this.config.thinkingMode)),
|
|
2436
2517
|
Metadata: { agentengine: {
|
|
2437
2518
|
tool_approval_mode: this.config.permissionMode || "risk",
|
|
2438
2519
|
...o
|
|
@@ -2491,28 +2572,28 @@ var qt = {
|
|
|
2491
2572
|
status: "running",
|
|
2492
2573
|
countEvent: !1
|
|
2493
2574
|
});
|
|
2494
|
-
let i = new
|
|
2575
|
+
let i = new F(e), a, o = 0;
|
|
2495
2576
|
for (; a === void 0 && o < 6;) try {
|
|
2496
|
-
let t =
|
|
2577
|
+
let t = this.lastSeqId, n = await this.api.subscribeSessionEvents(e, t, { signal: this.abortController?.signal });
|
|
2497
2578
|
o = 0;
|
|
2498
|
-
let r = n.getReader(), s = new TextDecoder(),
|
|
2579
|
+
let r = n.getReader(), s = new TextDecoder(), c = "";
|
|
2499
2580
|
for (; a === void 0;) {
|
|
2500
2581
|
let { value: t, done: n } = await r.read();
|
|
2501
2582
|
if (n) break;
|
|
2502
|
-
|
|
2503
|
-
let o =
|
|
2504
|
-
|
|
2583
|
+
c += s.decode(t, { stream: !0 });
|
|
2584
|
+
let o = jt(c);
|
|
2585
|
+
c = o.remainder;
|
|
2505
2586
|
for (let t of o.chunks) if (t.trim()) for (let n of Y(t)) {
|
|
2506
2587
|
let t = n.data;
|
|
2507
2588
|
if (!t || typeof t != "object") continue;
|
|
2508
2589
|
let r = i.translate(t), o = Number(t.seq);
|
|
2509
|
-
if (Number.isFinite(o) && o > 0 &&
|
|
2590
|
+
if (Number.isFinite(o) && o > 0 && this.recordCursor(o), r && (this.emit({
|
|
2510
2591
|
type: "stream_event",
|
|
2511
2592
|
event: r,
|
|
2512
2593
|
sessionId: e
|
|
2513
2594
|
}), r.EventType === "run_status")) {
|
|
2514
2595
|
let e = String(r.Content?.status || "").toLowerCase();
|
|
2515
|
-
e !== "interrupted" &&
|
|
2596
|
+
e !== "interrupted" && Kt.has(e) && (a = e);
|
|
2516
2597
|
}
|
|
2517
2598
|
}
|
|
2518
2599
|
}
|
|
@@ -2525,55 +2606,52 @@ var qt = {
|
|
|
2525
2606
|
return a === void 0 && (a = "interrupted"), { terminalStatus: a };
|
|
2526
2607
|
}
|
|
2527
2608
|
async consumeStream(e, t, n, r, i) {
|
|
2528
|
-
let a = e.getReader(), o = new TextDecoder(), s = "", c = !1, l = 0;
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2609
|
+
let a = e.getReader(), o = new TextDecoder(), s = "", c = !1, l = 0, u;
|
|
2610
|
+
for (;;) {
|
|
2611
|
+
let { value: e, done: d } = await a.read();
|
|
2612
|
+
if (d) break;
|
|
2613
|
+
l += e.byteLength, c || (c = !0, this.emit({
|
|
2614
|
+
type: "assistant_message_created",
|
|
2615
|
+
messageId: r,
|
|
2616
|
+
invocationId: i
|
|
2617
|
+
})), s += o.decode(e, { stream: !0 });
|
|
2618
|
+
let { chunks: f, remainder: p } = jt(s);
|
|
2619
|
+
s = p;
|
|
2620
|
+
for (let e of f) {
|
|
2621
|
+
if (!e.trim()) continue;
|
|
2622
|
+
if (this.isCompactionChunk(e)) {
|
|
2623
|
+
let t = Y(e);
|
|
2624
|
+
for (let e of t) e.eventName.startsWith("response.compaction") && this.upsertCompactionMessage({
|
|
2625
|
+
...e.data,
|
|
2626
|
+
phase: e.eventName.split(".").pop()
|
|
2627
|
+
});
|
|
2628
|
+
continue;
|
|
2629
|
+
}
|
|
2630
|
+
let i = Y(e), o = !1;
|
|
2631
|
+
for (let e of i) {
|
|
2632
|
+
if (e.eventName === "__done__") {
|
|
2633
|
+
o = !0;
|
|
2548
2634
|
continue;
|
|
2549
2635
|
}
|
|
2550
|
-
let i =
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
let a = t.parse(e, n);
|
|
2562
|
-
for (let e of a) this.dispatchAction(e, r);
|
|
2563
|
-
if (Ot(a)) {
|
|
2564
|
-
o = !0;
|
|
2565
|
-
let e = a.find((e) => e.type === "terminal");
|
|
2566
|
-
s = e && "status" in e ? String(e.status || "") : void 0;
|
|
2567
|
-
}
|
|
2636
|
+
let i = Jt(e.eventName, e.data);
|
|
2637
|
+
i && this.emit({
|
|
2638
|
+
type: "activity",
|
|
2639
|
+
...i
|
|
2640
|
+
});
|
|
2641
|
+
let a = t.parse(e, n);
|
|
2642
|
+
for (let e of a) this.dispatchAction(e, r), e.type === "terminal" && (u = e.status);
|
|
2643
|
+
if (At(a)) {
|
|
2644
|
+
o = !0;
|
|
2645
|
+
let e = a.find((e) => e.type === "terminal");
|
|
2646
|
+
u = e && "status" in e ? String(e.status || "") : void 0;
|
|
2568
2647
|
}
|
|
2569
|
-
if (o) return a.cancel().catch(() => {}), { terminalStatus: s };
|
|
2570
2648
|
}
|
|
2649
|
+
if (o) return a.cancel().catch(() => {}), { terminalStatus: u };
|
|
2571
2650
|
}
|
|
2572
|
-
} catch (e) {
|
|
2573
|
-
if (!(e instanceof DOMException && e.name === "AbortError")) throw e;
|
|
2574
2651
|
}
|
|
2575
2652
|
if (l === 0) throw Error("运行时返回了空响应流,请稍后重试;若问题持续,请检查运行时状态。");
|
|
2576
|
-
return {};
|
|
2653
|
+
if (u) return { terminalStatus: u };
|
|
2654
|
+
throw TypeError("运行时连接已结束,但尚未收到执行终态;请查询原任务状态。");
|
|
2577
2655
|
}
|
|
2578
2656
|
isCompactionChunk(e) {
|
|
2579
2657
|
return e.includes("response.compaction.start") || e.includes("response.compaction.done") || e.includes("response.compaction.failed");
|
|
@@ -2710,12 +2788,12 @@ var qt = {
|
|
|
2710
2788
|
};
|
|
2711
2789
|
//#endregion
|
|
2712
2790
|
//#region src/utils/recovered-run.ts
|
|
2713
|
-
function
|
|
2714
|
-
let r = e.filter((e) => e.role === "model" && e.invocationId === n), i =
|
|
2791
|
+
function Qt(e, t, n) {
|
|
2792
|
+
let r = e.filter((e) => e.role === "model" && e.invocationId === n), i = re(t).filter((e) => e.role === "model"), a = i.map((e) => ({
|
|
2715
2793
|
...e,
|
|
2716
2794
|
id: !e.itemId && i.length === 1 ? r[0]?.id || `${n}:assistant` : e.id,
|
|
2717
2795
|
invocationId: n,
|
|
2718
|
-
blocks:
|
|
2796
|
+
blocks: ne({
|
|
2719
2797
|
content: e.content,
|
|
2720
2798
|
reasoning: e.reasoning,
|
|
2721
2799
|
tools: e.tools
|
|
@@ -2731,14 +2809,14 @@ function Yt(e, t, n) {
|
|
|
2731
2809
|
}
|
|
2732
2810
|
//#endregion
|
|
2733
2811
|
//#region src/core/conversation/hosted.ts
|
|
2734
|
-
var
|
|
2735
|
-
function
|
|
2812
|
+
var $t = "conversation_item_v1";
|
|
2813
|
+
function en(e) {
|
|
2736
2814
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
2737
2815
|
}
|
|
2738
|
-
function
|
|
2816
|
+
function X(e) {
|
|
2739
2817
|
return typeof e == "string" && e.trim() ? e : null;
|
|
2740
2818
|
}
|
|
2741
|
-
function
|
|
2819
|
+
function tn(e) {
|
|
2742
2820
|
if (typeof e == "string") return e;
|
|
2743
2821
|
if (e == null) return "";
|
|
2744
2822
|
try {
|
|
@@ -2747,24 +2825,24 @@ function Qt(e) {
|
|
|
2747
2825
|
return String(e);
|
|
2748
2826
|
}
|
|
2749
2827
|
}
|
|
2750
|
-
function
|
|
2828
|
+
function Z(e) {
|
|
2751
2829
|
return {
|
|
2752
2830
|
id: `conversation:${e.runId}:${e.itemId}`,
|
|
2753
2831
|
timestamp: 0,
|
|
2754
|
-
eventType:
|
|
2832
|
+
eventType: $t,
|
|
2755
2833
|
eventId: e.sourceEventIds.at(-1),
|
|
2756
2834
|
runId: e.runId,
|
|
2757
2835
|
itemId: e.itemId,
|
|
2758
2836
|
status: e.lifecycle === "failed" ? "failed" : e.lifecycle === "completed" ? "completed" : "running"
|
|
2759
2837
|
};
|
|
2760
2838
|
}
|
|
2761
|
-
function
|
|
2839
|
+
function nn(e) {
|
|
2762
2840
|
return e.lifecycle === "failed" ? "error" : e.lifecycle === "completed" ? "done" : "streaming";
|
|
2763
2841
|
}
|
|
2764
|
-
function
|
|
2842
|
+
function rn(e) {
|
|
2765
2843
|
let t = typeof e.payload.text == "string" ? e.payload.text : "";
|
|
2766
2844
|
if (e.kind === "user_message") return {
|
|
2767
|
-
...
|
|
2845
|
+
...Z(e),
|
|
2768
2846
|
role: "user",
|
|
2769
2847
|
content: t,
|
|
2770
2848
|
eventType: "user_message"
|
|
@@ -2773,25 +2851,25 @@ function en(e) {
|
|
|
2773
2851
|
id: `conversation-block:${e.itemId}`,
|
|
2774
2852
|
type: "thinking",
|
|
2775
2853
|
content: t,
|
|
2776
|
-
status:
|
|
2854
|
+
status: nn(e)
|
|
2777
2855
|
} : {
|
|
2778
2856
|
id: `conversation-block:${e.itemId}`,
|
|
2779
2857
|
type: "text",
|
|
2780
2858
|
content: t,
|
|
2781
|
-
status:
|
|
2859
|
+
status: nn(e)
|
|
2782
2860
|
};
|
|
2783
2861
|
return {
|
|
2784
|
-
...
|
|
2862
|
+
...Z(e),
|
|
2785
2863
|
role: "model",
|
|
2786
2864
|
content: e.kind === "assistant_text" ? t : "",
|
|
2787
2865
|
reasoning: e.kind === "reasoning" ? t : void 0,
|
|
2788
2866
|
blocks: [n]
|
|
2789
2867
|
};
|
|
2790
2868
|
}
|
|
2791
|
-
function
|
|
2792
|
-
let t =
|
|
2869
|
+
function an(e) {
|
|
2870
|
+
let t = X(e.payload.tool) || "Tool", n = X(e.payload.callId), r = tn(e.payload.args), i = Object.prototype.hasOwnProperty.call(e.payload, "output") ? tn(e.payload.output) : void 0, a = e.lifecycle === "failed" || e.payload.isError === !0 ? "error" : e.lifecycle === "completed" ? "completed" : "running";
|
|
2793
2871
|
return {
|
|
2794
|
-
...
|
|
2872
|
+
...Z(e),
|
|
2795
2873
|
role: "model",
|
|
2796
2874
|
content: "",
|
|
2797
2875
|
blocks: [{
|
|
@@ -2812,28 +2890,28 @@ function tn(e) {
|
|
|
2812
2890
|
} }
|
|
2813
2891
|
};
|
|
2814
2892
|
}
|
|
2815
|
-
function
|
|
2893
|
+
function on(e) {
|
|
2816
2894
|
return e === "structured_input" ? "structured_input" : e === "plan_review" ? "plan_review" : e === "custom" ? "custom" : "approval";
|
|
2817
2895
|
}
|
|
2818
|
-
function
|
|
2819
|
-
let t =
|
|
2896
|
+
function sn(e) {
|
|
2897
|
+
let t = X(e.payload.interactionId), n = e.payload.revision;
|
|
2820
2898
|
if (!t || !Number.isInteger(n) || Number(n) < 1) return null;
|
|
2821
|
-
let r =
|
|
2899
|
+
let r = tn(e.payload.detail), i = X(e.payload.prompt) || r, a = on(e.payload.interactionKind), o = e.lifecycle === "completed";
|
|
2822
2900
|
return {
|
|
2823
2901
|
interactionId: t,
|
|
2824
2902
|
sessionId: e.sessionId,
|
|
2825
2903
|
runId: e.runId,
|
|
2826
2904
|
kind: a,
|
|
2827
|
-
title:
|
|
2905
|
+
title: X(e.payload.title) || (a === "approval" ? `审批:${X(e.payload.kind) || "操作"}` : "需要补充信息"),
|
|
2828
2906
|
message: i || "运行需要人工确认。",
|
|
2829
|
-
requestSchema:
|
|
2907
|
+
requestSchema: en(e.payload.inputSchema),
|
|
2830
2908
|
presentation: null,
|
|
2831
2909
|
status: o ? "resolved" : "pending",
|
|
2832
2910
|
revision: Number(n),
|
|
2833
|
-
createdAt:
|
|
2834
|
-
expiresAt:
|
|
2835
|
-
resolvedAt: o ?
|
|
2836
|
-
actor: o ?
|
|
2911
|
+
createdAt: X(e.payload.createdAt) || "",
|
|
2912
|
+
expiresAt: X(e.payload.expiresAt),
|
|
2913
|
+
resolvedAt: o ? X(e.payload.resolvedAt) : null,
|
|
2914
|
+
actor: o ? X(e.payload.actor) : null,
|
|
2837
2915
|
outcome: o && [
|
|
2838
2916
|
"approved",
|
|
2839
2917
|
"rejected",
|
|
@@ -2841,22 +2919,22 @@ function rn(e) {
|
|
|
2841
2919
|
"cancelled",
|
|
2842
2920
|
"expired"
|
|
2843
2921
|
].includes(String(e.payload.outcome || "")) ? e.payload.outcome : null,
|
|
2844
|
-
responseSummary: o ?
|
|
2922
|
+
responseSummary: o ? X(e.payload.responseSummary) : null,
|
|
2845
2923
|
source: "interaction_v1",
|
|
2846
2924
|
extensions: {
|
|
2847
2925
|
conversation_item_id: e.itemId,
|
|
2848
|
-
...
|
|
2926
|
+
...X(e.payload.callId) ? { call_id: X(e.payload.callId) } : {}
|
|
2849
2927
|
}
|
|
2850
2928
|
};
|
|
2851
2929
|
}
|
|
2852
|
-
function
|
|
2853
|
-
let n =
|
|
2930
|
+
function cn(e, t) {
|
|
2931
|
+
let n = X(e.payload.kind) || "approval", r = tn(e.payload.detail), i = t.status === "resolved" ? t.outcome === "rejected" ? "rejected" : t.outcome === "cancelled" || t.outcome === "expired" ? "cancelled" : "approved" : "pending", a = t.status === "pending" ? "paused" : "completed", o = {
|
|
2854
2932
|
approvalRequestId: t.interactionId,
|
|
2855
2933
|
approvalStatus: i,
|
|
2856
2934
|
approvalMessage: t.message
|
|
2857
2935
|
};
|
|
2858
2936
|
return {
|
|
2859
|
-
...
|
|
2937
|
+
...Z(e),
|
|
2860
2938
|
role: "model",
|
|
2861
2939
|
content: "",
|
|
2862
2940
|
blocks: [{
|
|
@@ -2877,26 +2955,26 @@ function an(e, t) {
|
|
|
2877
2955
|
} }
|
|
2878
2956
|
};
|
|
2879
2957
|
}
|
|
2880
|
-
function
|
|
2958
|
+
function ln(e) {
|
|
2881
2959
|
for (let t of [
|
|
2882
2960
|
"createSurface",
|
|
2883
2961
|
"updateComponents",
|
|
2884
2962
|
"updateDataModel",
|
|
2885
2963
|
"deleteSurface"
|
|
2886
2964
|
]) {
|
|
2887
|
-
let n =
|
|
2965
|
+
let n = X(en(e[t])?.surfaceId);
|
|
2888
2966
|
if (n) return n;
|
|
2889
2967
|
}
|
|
2890
2968
|
return null;
|
|
2891
2969
|
}
|
|
2892
|
-
function
|
|
2970
|
+
function un(e) {
|
|
2893
2971
|
let t = Array.isArray(e.payload.data) ? e.payload.data : Array.isArray(e.payload.operations) ? e.payload.operations : null;
|
|
2894
2972
|
if (!t) return null;
|
|
2895
|
-
let n = t.map(
|
|
2973
|
+
let n = t.map(en);
|
|
2896
2974
|
if (n.some((e) => e === null)) return null;
|
|
2897
|
-
let r = n, i =
|
|
2975
|
+
let r = n, i = X(e.payload.surfaceId) || r.map(ln).find((e) => e !== null) || null;
|
|
2898
2976
|
return i ? {
|
|
2899
|
-
...
|
|
2977
|
+
...Z(e),
|
|
2900
2978
|
role: "a2ui",
|
|
2901
2979
|
content: "",
|
|
2902
2980
|
aguiActivity: {
|
|
@@ -2905,53 +2983,72 @@ function sn(e) {
|
|
|
2905
2983
|
}
|
|
2906
2984
|
} : null;
|
|
2907
2985
|
}
|
|
2908
|
-
function
|
|
2986
|
+
function dn(e, t, n, r = !1) {
|
|
2909
2987
|
return {
|
|
2910
|
-
...
|
|
2988
|
+
...Z(e),
|
|
2911
2989
|
role: "system",
|
|
2912
2990
|
content: n ? `${t}: ${n}` : t,
|
|
2913
|
-
status: r ? "failed" :
|
|
2991
|
+
status: r ? "failed" : Z(e).status
|
|
2914
2992
|
};
|
|
2915
2993
|
}
|
|
2916
|
-
function
|
|
2994
|
+
function fn(e) {
|
|
2917
2995
|
let t = e.presentation, n = new Map(t.textItems.map((e) => [e.id, e])), r = new Set(t.toolItems.map((e) => e.itemId)), i = new Set(t.approvalItems.map((e) => e.itemId)), a = new Set(t.structuredInputItems.map((e) => e.itemId)), o = new Set(t.a2uiItems.map((e) => e.itemId)), s = new Map(t.artifacts.map((e) => [e.id, e])), c = new Map(t.fallbacks.map((e) => [e.id, e])), l = [], u = [];
|
|
2918
2996
|
for (let { item: e } of t.timeline) {
|
|
2919
2997
|
if (n.has(e.itemId)) {
|
|
2920
|
-
l.push(
|
|
2998
|
+
l.push(rn(e));
|
|
2921
2999
|
continue;
|
|
2922
3000
|
}
|
|
2923
3001
|
if (r.has(e.itemId)) {
|
|
2924
|
-
l.push(
|
|
3002
|
+
l.push(an(e));
|
|
2925
3003
|
continue;
|
|
2926
3004
|
}
|
|
2927
3005
|
if (i.has(e.itemId) || a.has(e.itemId)) {
|
|
2928
|
-
let t =
|
|
2929
|
-
t ? (u.push(t), l.push(
|
|
3006
|
+
let t = sn(e);
|
|
3007
|
+
t ? (u.push(t), l.push(cn(e, t))) : l.push(dn(e, "Interaction unavailable", "The server did not provide a durable interaction revision; this card is read-only."));
|
|
2930
3008
|
continue;
|
|
2931
3009
|
}
|
|
2932
3010
|
if (o.has(e.itemId)) {
|
|
2933
|
-
let t =
|
|
2934
|
-
l.push(t ||
|
|
3011
|
+
let t = un(e);
|
|
3012
|
+
l.push(t || dn(e, "Unsupported content", "A2UI payload is not a valid passive operation list."));
|
|
2935
3013
|
continue;
|
|
2936
3014
|
}
|
|
2937
3015
|
let t = s.get(e.itemId);
|
|
2938
3016
|
if (t) {
|
|
2939
|
-
l.push(t.
|
|
2940
|
-
...
|
|
3017
|
+
l.push(t.status === "pending" ? {
|
|
3018
|
+
...Z(e),
|
|
2941
3019
|
role: "model",
|
|
2942
3020
|
content: t.name,
|
|
2943
3021
|
attachments: [{
|
|
2944
3022
|
name: t.name,
|
|
2945
3023
|
type: t.mimeType,
|
|
2946
|
-
url:
|
|
3024
|
+
url: "",
|
|
3025
|
+
artifactId: t.artifactId,
|
|
3026
|
+
itemId: t.itemId,
|
|
3027
|
+
runId: t.runId,
|
|
3028
|
+
sizeBytes: t.sizeBytes,
|
|
3029
|
+
status: "pending"
|
|
2947
3030
|
}]
|
|
2948
|
-
} :
|
|
3031
|
+
} : t.status === "ready" && t.uri ? {
|
|
3032
|
+
...Z(e),
|
|
3033
|
+
role: "model",
|
|
3034
|
+
content: t.name,
|
|
3035
|
+
attachments: [{
|
|
3036
|
+
name: t.name,
|
|
3037
|
+
type: t.mimeType,
|
|
3038
|
+
url: t.uri,
|
|
3039
|
+
artifactId: t.artifactId,
|
|
3040
|
+
itemId: t.itemId,
|
|
3041
|
+
runId: t.runId,
|
|
3042
|
+
sizeBytes: t.sizeBytes,
|
|
3043
|
+
status: t.status
|
|
3044
|
+
}]
|
|
3045
|
+
} : dn(e, "Artifact unavailable", t.status === "failed" ? "The artifact failed to generate or its URI is not a safe HTTP(S) link." : "The artifact URI is not a safe HTTP(S) link."));
|
|
2949
3046
|
continue;
|
|
2950
3047
|
}
|
|
2951
3048
|
let d = c.get(e.itemId);
|
|
2952
3049
|
if (d) {
|
|
2953
3050
|
if (e.kind === "error" && ["cancelled", "canceled"].includes(String(e.payload.status || "").toLowerCase())) continue;
|
|
2954
|
-
l.push(
|
|
3051
|
+
l.push(dn(e, d.title, d.detail, d.failed));
|
|
2955
3052
|
}
|
|
2956
3053
|
}
|
|
2957
3054
|
return {
|
|
@@ -2959,59 +3056,38 @@ function ln(e) {
|
|
|
2959
3056
|
interactions: u
|
|
2960
3057
|
};
|
|
2961
3058
|
}
|
|
2962
|
-
function
|
|
2963
|
-
let
|
|
2964
|
-
if (!
|
|
2965
|
-
let
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
if (n.role === "user" && n.eventType === "optimistic_user_message") {
|
|
2971
|
-
e = t;
|
|
2972
|
-
break;
|
|
2973
|
-
}
|
|
2974
|
-
}
|
|
2975
|
-
if (e >= 0) {
|
|
2976
|
-
let i = r[e], a = String(i.content || "").trim();
|
|
2977
|
-
if (r = [...r.slice(0, e), ...r.slice(e + 1)], !n.some((e) => e.role === "user") && a) {
|
|
2978
|
-
let e = r.filter((e) => !(e.eventType === Xt && e.runId === t.runId || e.invocationId === t.runId)), a = r.findIndex((e) => e.eventType === Xt && e.runId === t.runId || e.invocationId === t.runId), o = a < 0 ? e.length : a;
|
|
2979
|
-
return [
|
|
2980
|
-
...e.slice(0, o),
|
|
2981
|
-
{
|
|
2982
|
-
...i,
|
|
2983
|
-
timestamp: Date.now()
|
|
2984
|
-
},
|
|
2985
|
-
...n,
|
|
2986
|
-
...e.slice(o)
|
|
2987
|
-
];
|
|
2988
|
-
}
|
|
2989
|
-
}
|
|
2990
|
-
}
|
|
2991
|
-
let i = (e) => e.eventType === Xt && e.runId === t.runId || e.invocationId === t.runId, a = r.findIndex(i), o = r.filter((e) => !i(e)), s = a < 0 ? o.length : a;
|
|
3059
|
+
function pn(e, t, n) {
|
|
3060
|
+
let r = fn(t).messages;
|
|
3061
|
+
if (!r.length) return e;
|
|
3062
|
+
let i = e.filter((e) => e.eventType !== "optimistic_assistant_placeholder"), a = (e) => e.runId === t.runId || e.invocationId === t.runId, o = i.findIndex(a), s = n ? i.findIndex((e) => e.id === n) : o < 0 ? i.findLastIndex((e) => e.role === "user" && e.eventType === "optimistic_user_message") : i.findIndex((e) => e.role === "user" && a(e)), c = i[s], l = i.filter((e, t) => t !== s && !a(e)), u = [s, o].filter((e) => e >= 0), d = u.length ? Math.min(...u) : l.length, f = c && !r.some((e) => e.role === "user") ? [{
|
|
3063
|
+
...c,
|
|
3064
|
+
invocationId: t.runId,
|
|
3065
|
+
eventType: void 0
|
|
3066
|
+
}] : [];
|
|
2992
3067
|
return [
|
|
2993
|
-
...
|
|
2994
|
-
...
|
|
2995
|
-
...
|
|
3068
|
+
...l.slice(0, d),
|
|
3069
|
+
...f,
|
|
3070
|
+
...r,
|
|
3071
|
+
...l.slice(d)
|
|
2996
3072
|
];
|
|
2997
3073
|
}
|
|
2998
3074
|
//#endregion
|
|
2999
3075
|
//#region src/core/run/dispatcher.ts
|
|
3000
|
-
var
|
|
3001
|
-
function
|
|
3076
|
+
var mn = "连接断开或生成出错,请重试";
|
|
3077
|
+
function hn(e) {
|
|
3002
3078
|
let t = String(e.message || "").trim();
|
|
3003
|
-
return /runtime agent kernel is not ready/i.test(t) ? "云端运行时尚未就绪,请检查部署状态后重试" : !t || /failed to fetch|networkerror/i.test(t) ?
|
|
3079
|
+
return /runtime agent kernel is not ready/i.test(t) ? "云端运行时尚未就绪,请检查部署状态后重试" : !t || /failed to fetch|networkerror/i.test(t) ? mn : t.length <= 240 ? t : mn;
|
|
3004
3080
|
}
|
|
3005
|
-
var
|
|
3081
|
+
var gn = new Set(["completed"]), _n = new Set([
|
|
3006
3082
|
"failed",
|
|
3007
3083
|
"error",
|
|
3008
3084
|
"cancelled",
|
|
3009
3085
|
"canceled",
|
|
3010
3086
|
"aborted",
|
|
3011
3087
|
"incomplete"
|
|
3012
|
-
]),
|
|
3013
|
-
function
|
|
3014
|
-
|
|
3088
|
+
]), vn = /* @__PURE__ */ new Map();
|
|
3089
|
+
function Q(e, t) {
|
|
3090
|
+
E.getState().patchMessages((n) => {
|
|
3015
3091
|
if (n.some((t) => t.id === e)) return t ? n.map((n) => n.id === e ? {
|
|
3016
3092
|
...n,
|
|
3017
3093
|
invocationId: t
|
|
@@ -3036,12 +3112,12 @@ function $(e, t) {
|
|
|
3036
3112
|
}];
|
|
3037
3113
|
});
|
|
3038
3114
|
}
|
|
3039
|
-
function
|
|
3115
|
+
function yn(e) {
|
|
3040
3116
|
return e.filter((e) => e.eventType !== "optimistic_assistant_placeholder");
|
|
3041
3117
|
}
|
|
3042
|
-
function
|
|
3043
|
-
let t = String(e || "").trim().toLowerCase(), n =
|
|
3044
|
-
n &&
|
|
3118
|
+
function bn(e) {
|
|
3119
|
+
let t = String(e || "").trim().toLowerCase(), n = gn.has(t) ? "completed" : _n.has(t) ? "error" : null;
|
|
3120
|
+
n && E.getState().patchMessages((e) => e.map((e) => {
|
|
3045
3121
|
if (!e.tools) return e;
|
|
3046
3122
|
let t = !1, r = Object.fromEntries(Object.entries(e.tools).map(([e, r]) => r.status === "running" ? (t = !0, [e, {
|
|
3047
3123
|
...r,
|
|
@@ -3053,23 +3129,32 @@ function _n(e) {
|
|
|
3053
3129
|
} : e;
|
|
3054
3130
|
}));
|
|
3055
3131
|
}
|
|
3056
|
-
function
|
|
3057
|
-
|
|
3058
|
-
|
|
3132
|
+
function xn(e, t) {
|
|
3133
|
+
!e.sessionId && t?.draftId && (e = {
|
|
3134
|
+
...e,
|
|
3135
|
+
sessionId: t.draftId
|
|
3136
|
+
});
|
|
3137
|
+
let n = t ? !t.visible : !!(e.sessionId && a.getState().currentSessionId !== e.sessionId);
|
|
3138
|
+
if (n && ![
|
|
3059
3139
|
"activity",
|
|
3060
3140
|
"stage_changed",
|
|
3061
3141
|
"stream_ended",
|
|
3062
3142
|
"error",
|
|
3063
3143
|
"rate_limited",
|
|
3064
|
-
"terminal"
|
|
3144
|
+
"terminal",
|
|
3145
|
+
"approval_requested",
|
|
3146
|
+
"approval_resolved",
|
|
3147
|
+
"stream_event",
|
|
3148
|
+
"conversation_snapshot"
|
|
3065
3149
|
].includes(e.type)) return;
|
|
3066
|
-
let
|
|
3150
|
+
let r = E.getState(), i = (e) => {
|
|
3067
3151
|
e && c.getState().updateActivity({ sessionId: e });
|
|
3068
3152
|
};
|
|
3069
3153
|
switch (e.type) {
|
|
3070
3154
|
case "activity":
|
|
3071
3155
|
c.getState().updateActivity({
|
|
3072
3156
|
sessionId: e.sessionId,
|
|
3157
|
+
visible: !n,
|
|
3073
3158
|
source: e.source,
|
|
3074
3159
|
status: e.status,
|
|
3075
3160
|
phase: e.phase,
|
|
@@ -3078,7 +3163,7 @@ function vn(e) {
|
|
|
3078
3163
|
});
|
|
3079
3164
|
break;
|
|
3080
3165
|
case "user_message_added":
|
|
3081
|
-
c.getState().setBanner(null),
|
|
3166
|
+
c.getState().setBanner(null), r.patchMessages((t) => [...t, {
|
|
3082
3167
|
id: e.messageId,
|
|
3083
3168
|
role: "user",
|
|
3084
3169
|
content: "",
|
|
@@ -3086,40 +3171,40 @@ function vn(e) {
|
|
|
3086
3171
|
}]);
|
|
3087
3172
|
break;
|
|
3088
3173
|
case "assistant_message_created":
|
|
3089
|
-
|
|
3174
|
+
Q(e.messageId, e.invocationId);
|
|
3090
3175
|
break;
|
|
3091
3176
|
case "text_delta":
|
|
3092
|
-
|
|
3177
|
+
Q(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => t.id === e.messageId ? {
|
|
3093
3178
|
...t,
|
|
3094
3179
|
content: t.content + e.delta,
|
|
3095
|
-
blocks:
|
|
3180
|
+
blocks: ce(t.blocks, e.delta)
|
|
3096
3181
|
} : t));
|
|
3097
3182
|
break;
|
|
3098
3183
|
case "text_final":
|
|
3099
|
-
|
|
3100
|
-
let n = !!(e.text && !t.content && t.reasoning?.endsWith(e.text)), r = n ? t.reasoning.slice(0, -e.text.length) : t.reasoning, i = n ?
|
|
3184
|
+
Q(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => t.id === e.messageId ? (() => {
|
|
3185
|
+
let n = !!(e.text && !t.content && t.reasoning?.endsWith(e.text)), r = n ? t.reasoning.slice(0, -e.text.length) : t.reasoning, i = n ? fe(t.blocks, e.text) : t.blocks;
|
|
3101
3186
|
return {
|
|
3102
3187
|
...t,
|
|
3103
3188
|
reasoning: r,
|
|
3104
3189
|
content: e.text,
|
|
3105
|
-
blocks:
|
|
3190
|
+
blocks: te(i, e.text)
|
|
3106
3191
|
};
|
|
3107
3192
|
})() : t));
|
|
3108
3193
|
break;
|
|
3109
3194
|
case "reasoning_delta":
|
|
3110
|
-
|
|
3195
|
+
Q(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => t.id === e.messageId ? {
|
|
3111
3196
|
...t,
|
|
3112
3197
|
reasoning: (t.reasoning || "") + e.delta,
|
|
3113
|
-
blocks:
|
|
3198
|
+
blocks: ae(t.blocks, e.delta)
|
|
3114
3199
|
} : t));
|
|
3115
3200
|
break;
|
|
3116
3201
|
case "tool_upsert":
|
|
3117
|
-
|
|
3202
|
+
Q(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => {
|
|
3118
3203
|
if (t.id !== e.messageId) return t;
|
|
3119
3204
|
let n = t.tools?.[e.name], r = n?.approvalStatus === "approved" || n?.approvalStatus === "rejected" || n?.approvalStatus === "cancelled", i = e.status, a = n?.approvalStatus === "rejected" || n?.approvalStatus === "cancelled" ? "completed" : n?.status === "error" && i !== "error" ? "error" : i;
|
|
3120
3205
|
return {
|
|
3121
3206
|
...t,
|
|
3122
|
-
blocks:
|
|
3207
|
+
blocks: pe(t.blocks, e.name, {
|
|
3123
3208
|
args: e.args,
|
|
3124
3209
|
status: a,
|
|
3125
3210
|
extra: e.extra
|
|
@@ -3142,12 +3227,12 @@ function vn(e) {
|
|
|
3142
3227
|
}));
|
|
3143
3228
|
break;
|
|
3144
3229
|
case "tool_result":
|
|
3145
|
-
|
|
3230
|
+
Q(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => {
|
|
3146
3231
|
if (t.id !== e.messageId) return t;
|
|
3147
3232
|
let n = D(e.output) ? "error" : "completed";
|
|
3148
3233
|
return {
|
|
3149
3234
|
...t,
|
|
3150
|
-
blocks:
|
|
3235
|
+
blocks: pe(t.blocks, e.name, {
|
|
3151
3236
|
output: e.output,
|
|
3152
3237
|
status: n
|
|
3153
3238
|
}),
|
|
@@ -3166,7 +3251,7 @@ function vn(e) {
|
|
|
3166
3251
|
}));
|
|
3167
3252
|
break;
|
|
3168
3253
|
case "approval_requested":
|
|
3169
|
-
|
|
3254
|
+
if (pt({
|
|
3170
3255
|
approvalRequestId: e.approvalRequestId,
|
|
3171
3256
|
protocol: e.protocol,
|
|
3172
3257
|
runId: e.runId,
|
|
@@ -3175,7 +3260,8 @@ function vn(e) {
|
|
|
3175
3260
|
args: e.args,
|
|
3176
3261
|
approvalLevel: e.approvalLevel,
|
|
3177
3262
|
sessionId: e.sessionId
|
|
3178
|
-
}), n
|
|
3263
|
+
}), n) break;
|
|
3264
|
+
Q(e.messageId), r.patchMessages((t) => t.map((t) => {
|
|
3179
3265
|
if (t.id !== e.messageId) return t;
|
|
3180
3266
|
let n = t.tools?.[e.approvalRequestId], r = n?.approvalStatus === "approved" || n?.approvalStatus === "rejected" || n?.approvalStatus === "cancelled", i = {
|
|
3181
3267
|
approvalRequestId: e.approvalRequestId,
|
|
@@ -3186,7 +3272,7 @@ function vn(e) {
|
|
|
3186
3272
|
}, a = r ? n.status : "paused";
|
|
3187
3273
|
return {
|
|
3188
3274
|
...t,
|
|
3189
|
-
blocks:
|
|
3275
|
+
blocks: pe(t.blocks, e.name, {
|
|
3190
3276
|
args: e.args,
|
|
3191
3277
|
status: a,
|
|
3192
3278
|
extra: i
|
|
@@ -3205,12 +3291,13 @@ function vn(e) {
|
|
|
3205
3291
|
}));
|
|
3206
3292
|
break;
|
|
3207
3293
|
case "approval_resolved":
|
|
3208
|
-
|
|
3294
|
+
if (mt({
|
|
3209
3295
|
approvalRequestId: e.approvalRequestId,
|
|
3210
3296
|
decision: e.decision,
|
|
3211
3297
|
revision: e.revision,
|
|
3212
3298
|
sessionId: e.sessionId
|
|
3213
|
-
}), n
|
|
3299
|
+
}), n) break;
|
|
3300
|
+
r.patchMessages((t) => t.map((t) => {
|
|
3214
3301
|
if (!t.tools) return t;
|
|
3215
3302
|
let n = !1, r = Object.fromEntries(Object.entries(t.tools).map(([t, r]) => {
|
|
3216
3303
|
if (r.approvalRequestId !== e.approvalRequestId) return [t, r];
|
|
@@ -3241,7 +3328,7 @@ function vn(e) {
|
|
|
3241
3328
|
}));
|
|
3242
3329
|
break;
|
|
3243
3330
|
case "system_message":
|
|
3244
|
-
|
|
3331
|
+
r.patchMessages((t) => [...t, {
|
|
3245
3332
|
id: String(Date.now() + Math.random()),
|
|
3246
3333
|
role: "system",
|
|
3247
3334
|
content: e.content,
|
|
@@ -3249,14 +3336,14 @@ function vn(e) {
|
|
|
3249
3336
|
}]);
|
|
3250
3337
|
break;
|
|
3251
3338
|
case "compaction": {
|
|
3252
|
-
let t = `compaction-${Date.now()}`,
|
|
3339
|
+
let t = `compaction-${Date.now()}`, n = e.phase === "start" ? "running" : e.phase === "failed" ? "failed" : "completed", i = le({
|
|
3253
3340
|
id: t,
|
|
3254
3341
|
timestamp: Date.now(),
|
|
3255
|
-
status:
|
|
3342
|
+
status: n,
|
|
3256
3343
|
trigger: e.trigger,
|
|
3257
3344
|
compactedUntilSeqId: e.compactedUntilSeqId
|
|
3258
3345
|
});
|
|
3259
|
-
|
|
3346
|
+
r.patchMessages((e) => e.findIndex((e) => e.id === t) < 0 ? [...e, i] : e.map((e) => e.id === t ? {
|
|
3260
3347
|
...e,
|
|
3261
3348
|
...i
|
|
3262
3349
|
} : e));
|
|
@@ -3266,9 +3353,9 @@ function vn(e) {
|
|
|
3266
3353
|
e.stage === "streaming" || e.stage === "connecting" ? c.getState().setSessionStreaming(e.sessionId, !0) : (e.stage === "completing" || e.stage === "error" || e.stage === "cancelled") && c.getState().setSessionStreaming(e.sessionId, !1);
|
|
3267
3354
|
break;
|
|
3268
3355
|
case "stream_ended":
|
|
3269
|
-
c.getState().setSessionStreaming(e.sessionId, !1),
|
|
3356
|
+
c.getState().setSessionStreaming(e.sessionId, !1), n || E.getState().patchMessages((t) => yn(t).map((t) => !(!e.runId || t.runId === e.runId || t.invocationId === e.runId) || t.role !== "model" || !t.blocks?.some((e) => e.status === "streaming") ? t : {
|
|
3270
3357
|
...t,
|
|
3271
|
-
blocks:
|
|
3358
|
+
blocks: M(t.blocks.map((e) => e.type === "text" && e.status === "streaming" ? {
|
|
3272
3359
|
...e,
|
|
3273
3360
|
status: "done"
|
|
3274
3361
|
} : e))
|
|
@@ -3278,21 +3365,22 @@ function vn(e) {
|
|
|
3278
3365
|
}, 2400);
|
|
3279
3366
|
break;
|
|
3280
3367
|
case "error": {
|
|
3281
|
-
let
|
|
3368
|
+
let t = hn(e.error);
|
|
3282
3369
|
c.getState().setSessionStreaming(e.sessionId, !1), c.getState().updateActivity({
|
|
3283
3370
|
sessionId: e.sessionId,
|
|
3371
|
+
visible: !n,
|
|
3284
3372
|
status: "failed",
|
|
3285
3373
|
phase: "运行失败",
|
|
3286
|
-
detail:
|
|
3374
|
+
detail: t,
|
|
3287
3375
|
countEvent: !1
|
|
3288
|
-
}),
|
|
3376
|
+
}), n || (c.getState().setBanner({
|
|
3289
3377
|
kind: "error",
|
|
3290
|
-
message:
|
|
3378
|
+
message: t,
|
|
3291
3379
|
sessionId: e.sessionId
|
|
3292
|
-
}),
|
|
3380
|
+
}), r.patchMessages((e) => [...yn(e), {
|
|
3293
3381
|
id: String(Date.now()),
|
|
3294
3382
|
role: "model",
|
|
3295
|
-
content: `运行失败:${
|
|
3383
|
+
content: `运行失败:${t}`,
|
|
3296
3384
|
timestamp: Date.now()
|
|
3297
3385
|
}]));
|
|
3298
3386
|
break;
|
|
@@ -3300,44 +3388,51 @@ function vn(e) {
|
|
|
3300
3388
|
case "rate_limited":
|
|
3301
3389
|
c.getState().setSessionStreaming(e.sessionId, !1), c.getState().updateActivity({
|
|
3302
3390
|
sessionId: e.sessionId,
|
|
3391
|
+
visible: !n,
|
|
3303
3392
|
status: "failed",
|
|
3304
3393
|
phase: "请求被限流",
|
|
3305
3394
|
countEvent: !1
|
|
3306
|
-
}),
|
|
3395
|
+
}), n || (c.getState().setBanner({
|
|
3307
3396
|
kind: "rate_limited",
|
|
3308
3397
|
message: e.message || "请求过于频繁,请稍后重试",
|
|
3309
3398
|
retryAfterSec: e.retryAfterSec,
|
|
3310
3399
|
sessionId: e.sessionId
|
|
3311
|
-
}),
|
|
3400
|
+
}), r.patchMessages(yn));
|
|
3312
3401
|
break;
|
|
3313
3402
|
case "terminal":
|
|
3314
|
-
e.sessionId && String(e.status || "").trim().toLowerCase() !== "incomplete" && J.markSessionTerminal(e.sessionId),
|
|
3403
|
+
e.sessionId && String(e.status || "").trim().toLowerCase() !== "incomplete" && J.markSessionTerminal(e.sessionId), n || bn(e.status);
|
|
3315
3404
|
break;
|
|
3316
3405
|
case "stream_event": {
|
|
3317
3406
|
let t = e.sessionId || e.event.SessionId;
|
|
3318
|
-
|
|
3319
|
-
let
|
|
3320
|
-
typeof
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3407
|
+
ft(e.event, t || void 0);
|
|
3408
|
+
let r = e.event.SeqId;
|
|
3409
|
+
!n && typeof r == "number" && r > 0 && c.getState().setLastSeqId(r), t && c.getState().updateActivity({
|
|
3410
|
+
sessionId: t,
|
|
3411
|
+
visible: !n
|
|
3412
|
+
});
|
|
3413
|
+
let i = String(e.event.InvocationId || "").trim();
|
|
3414
|
+
if (!n && t && i) {
|
|
3415
|
+
let n = `${t}:${i}`, r = ue(vn.get(n) || [], [e.event]);
|
|
3416
|
+
vn.set(n, r), E.getState().patchMessages((e) => e.some((e) => e.eventType === "conversation_item_v1" && e.runId === i) ? e : Qt(e, r, i)), ee(e.event) && vn.delete(n);
|
|
3325
3417
|
}
|
|
3326
|
-
e.event.EventType === "run_checkpoint" && t &&
|
|
3418
|
+
e.event.EventType === "run_checkpoint" && t && b.getState().upsertSessionCheckpoint(t, e.event);
|
|
3327
3419
|
{
|
|
3328
|
-
let
|
|
3329
|
-
|
|
3420
|
+
let r = P(e.event);
|
|
3421
|
+
r === "completed" ? c.getState().updateActivity({
|
|
3330
3422
|
sessionId: t,
|
|
3423
|
+
visible: !n,
|
|
3331
3424
|
status: "completed",
|
|
3332
3425
|
phase: "后台长任务已完成",
|
|
3333
3426
|
countEvent: !1
|
|
3334
|
-
}) :
|
|
3427
|
+
}) : r === "cancelled" || r === "canceled" || r === "aborted" ? c.getState().updateActivity({
|
|
3335
3428
|
sessionId: t,
|
|
3429
|
+
visible: !n,
|
|
3336
3430
|
status: "stopped",
|
|
3337
3431
|
phase: "后台长任务已取消",
|
|
3338
3432
|
countEvent: !1
|
|
3339
|
-
}) : (
|
|
3433
|
+
}) : (r === "failed" || r === "error") && c.getState().updateActivity({
|
|
3340
3434
|
sessionId: t,
|
|
3435
|
+
visible: !n,
|
|
3341
3436
|
status: "failed",
|
|
3342
3437
|
phase: "后台长任务失败",
|
|
3343
3438
|
countEvent: !1
|
|
@@ -3346,14 +3441,15 @@ function vn(e) {
|
|
|
3346
3441
|
break;
|
|
3347
3442
|
}
|
|
3348
3443
|
case "conversation_snapshot": {
|
|
3349
|
-
let t =
|
|
3444
|
+
let t = fn(e.result);
|
|
3350
3445
|
for (let e of t.interactions) J.upsert(e);
|
|
3351
|
-
|
|
3446
|
+
if (n) break;
|
|
3447
|
+
r.patchMessages((t) => pn(t, e.result, e.optimisticMessageId)), i(e.sessionId);
|
|
3352
3448
|
break;
|
|
3353
3449
|
}
|
|
3354
3450
|
case "a2ui_surface_begin": {
|
|
3355
3451
|
let t = `a2ui-${e.surfaceId}`;
|
|
3356
|
-
|
|
3452
|
+
E.getState().patchMessages((n) => [...n.filter((e) => e.id !== t), {
|
|
3357
3453
|
id: t,
|
|
3358
3454
|
role: "a2ui",
|
|
3359
3455
|
content: "",
|
|
@@ -3367,7 +3463,7 @@ function vn(e) {
|
|
|
3367
3463
|
}
|
|
3368
3464
|
case "a2ui_surface_update": {
|
|
3369
3465
|
let t = `a2ui-${e.surfaceId}`;
|
|
3370
|
-
|
|
3466
|
+
E.getState().patchMessages((n) => n.map((n) => n.id === t && n.a2ui ? {
|
|
3371
3467
|
...n,
|
|
3372
3468
|
a2ui: {
|
|
3373
3469
|
...n.a2ui,
|
|
@@ -3378,7 +3474,7 @@ function vn(e) {
|
|
|
3378
3474
|
}
|
|
3379
3475
|
case "a2ui_surface_end": {
|
|
3380
3476
|
let t = `a2ui-${e.surfaceId}`;
|
|
3381
|
-
|
|
3477
|
+
E.getState().patchMessages((e) => e.map((e) => e.id === t && e.a2ui ? {
|
|
3382
3478
|
...e,
|
|
3383
3479
|
a2ui: {
|
|
3384
3480
|
...e.a2ui,
|
|
@@ -3389,7 +3485,7 @@ function vn(e) {
|
|
|
3389
3485
|
}
|
|
3390
3486
|
case "a2ui_interaction": {
|
|
3391
3487
|
let t = `a2ui-${e.surfaceId}`;
|
|
3392
|
-
|
|
3488
|
+
E.getState().patchMessages((n) => n.map((n) => n.id === t && n.a2ui ? {
|
|
3393
3489
|
...n,
|
|
3394
3490
|
a2ui: {
|
|
3395
3491
|
...n.a2ui,
|
|
@@ -3404,7 +3500,7 @@ function vn(e) {
|
|
|
3404
3500
|
}
|
|
3405
3501
|
case "agui_activity": {
|
|
3406
3502
|
let t = `agui-a2ui-${e.surfaceId}`;
|
|
3407
|
-
|
|
3503
|
+
E.getState().patchMessages((n) => {
|
|
3408
3504
|
let r = {
|
|
3409
3505
|
surfaceId: e.surfaceId,
|
|
3410
3506
|
messages: e.messages
|
|
@@ -3431,46 +3527,94 @@ function vn(e) {
|
|
|
3431
3527
|
}
|
|
3432
3528
|
}
|
|
3433
3529
|
}
|
|
3434
|
-
function
|
|
3435
|
-
|
|
3530
|
+
function Sn() {
|
|
3531
|
+
vn.clear();
|
|
3436
3532
|
}
|
|
3437
3533
|
//#endregion
|
|
3438
3534
|
//#region src/hooks/useRunAgent.ts
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3535
|
+
var Cn = 64;
|
|
3536
|
+
function wn(t) {
|
|
3537
|
+
let n = z(/* @__PURE__ */ new Map()), r = z(/* @__PURE__ */ new Set()), i = L((e) => r.current.has(e), []), o = L((e) => {
|
|
3538
|
+
let t = n.current;
|
|
3539
|
+
if (!(t.size <= Cn)) for (let [n, r] of t) {
|
|
3540
|
+
if (t.size <= Cn) break;
|
|
3541
|
+
n === e || r.engine.stage !== "idle" || r.queue.length > 0 || r.isVisible() || t.delete(n);
|
|
3542
|
+
}
|
|
3543
|
+
}, []), l = me(() => new N(), []), u = t.conversationClient === void 0 ? l : t.conversationClient, { agentId: d, apiFormats: f, agentFramework: p, selectedModel: m, selectedModelMetadata: h, thinkingMode: g, permissionMode: _, currentSessionIdRef: v, queuedDraftRef: y, onRunSettled: b, onSessionCreated: x, waitForPendingSessionCreation: S, uiCapabilities: C, outbox: w } = t, T = me(() => ({
|
|
3544
|
+
agentId: d,
|
|
3545
|
+
apiFormats: f,
|
|
3546
|
+
agentFramework: p,
|
|
3547
|
+
selectedModel: m,
|
|
3548
|
+
selectedModelMetadata: h,
|
|
3549
|
+
thinkingMode: C.Thinking ? g : "auto",
|
|
3550
|
+
permissionMode: _,
|
|
3551
|
+
runtimeCapabilityMatrix: C.RuntimeCapabilityMatrix,
|
|
3552
|
+
hostedChatTransport: e(C, { requireResumableRun: !!(C.RunLifecycle?.Enabled && C.RunLifecycle.Resume) }),
|
|
3553
|
+
checkpointResumePreviewEnabled: !!C.RunLifecycle?.CheckpointResumePreview,
|
|
3554
|
+
conversationClient: u || void 0
|
|
3555
|
+
}), [
|
|
3456
3556
|
d,
|
|
3457
3557
|
f,
|
|
3458
3558
|
p,
|
|
3459
3559
|
m,
|
|
3460
3560
|
h,
|
|
3461
3561
|
g,
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3562
|
+
_,
|
|
3563
|
+
C,
|
|
3564
|
+
u
|
|
3565
|
+
]), D = L((e = v.current) => {
|
|
3566
|
+
let r = t.conversationIdRef?.current, i = JSON.stringify([d, r || e || "new-session"]), a = n.current.get(i);
|
|
3567
|
+
if (!a) {
|
|
3568
|
+
o(i);
|
|
3569
|
+
let s = () => t.agentIdRef.current === d && (t.conversationIdRef ? t.conversationIdRef.current === r : v.current === a.sessionId), c = new Zt(t.api, {
|
|
3570
|
+
isVisible: s,
|
|
3571
|
+
draftId: r
|
|
3572
|
+
});
|
|
3573
|
+
a = {
|
|
3574
|
+
key: i,
|
|
3575
|
+
agentId: d,
|
|
3576
|
+
conversationId: r,
|
|
3577
|
+
sessionId: e || null,
|
|
3578
|
+
engine: c,
|
|
3579
|
+
queue: [],
|
|
3580
|
+
isVisible: s
|
|
3581
|
+
}, c.subscribe((e) => xn(e, {
|
|
3582
|
+
visible: s(),
|
|
3583
|
+
draftId: r
|
|
3584
|
+
})), n.current.set(i, a);
|
|
3585
|
+
}
|
|
3586
|
+
return a;
|
|
3587
|
+
}, [
|
|
3588
|
+
d,
|
|
3589
|
+
t.agentIdRef,
|
|
3590
|
+
t.api,
|
|
3591
|
+
t.conversationIdRef,
|
|
3592
|
+
v,
|
|
3593
|
+
o
|
|
3594
|
+
]), O = L((e) => {
|
|
3595
|
+
let t = D(e);
|
|
3596
|
+
return t.engine.stage === "idle" && t.engine.updateConfig(T), t.engine;
|
|
3597
|
+
}, [T, D]), k = L((e) => {
|
|
3598
|
+
if (!e.isVisible()) return;
|
|
3599
|
+
let t = e.queue.map((e) => e.draft);
|
|
3600
|
+
y.current = t, s.getState().setQueuedDrafts(t);
|
|
3601
|
+
}, [y]), A = L((e) => {
|
|
3602
|
+
let t = e.queue[0];
|
|
3603
|
+
!t || e.engine.stage !== "idle" || (e.queue.shift(), k(e), queueMicrotask(() => {
|
|
3604
|
+
t.launch() || (e.queue.unshift(t), k(e));
|
|
3605
|
+
}));
|
|
3606
|
+
}, [k]);
|
|
3607
|
+
R(() => {
|
|
3608
|
+
let e = JSON.stringify([d, t.conversationIdRef?.current || t.currentSessionId || "new-session"]), r = n.current.get(e);
|
|
3609
|
+
r ? k(r) : (y.current = [], s.getState().setQueuedDrafts([]));
|
|
3610
|
+
}, [
|
|
3611
|
+
d,
|
|
3612
|
+
t.currentSessionId,
|
|
3613
|
+
t.conversationIdRef?.current,
|
|
3614
|
+
k,
|
|
3615
|
+
y
|
|
3616
|
+
]);
|
|
3617
|
+
let j = L((e) => {
|
|
3474
3618
|
let t = e.text.trim(), n = e.attachments.map((e) => ({
|
|
3475
3619
|
name: e.name,
|
|
3476
3620
|
url: URL.createObjectURL(e),
|
|
@@ -3478,7 +3622,7 @@ function bn(t) {
|
|
|
3478
3622
|
}));
|
|
3479
3623
|
if (!t && n.length === 0) return;
|
|
3480
3624
|
let r = `optimistic-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
3481
|
-
return
|
|
3625
|
+
return E.getState().patchMessages((e) => [...e, {
|
|
3482
3626
|
id: r,
|
|
3483
3627
|
role: "user",
|
|
3484
3628
|
content: t,
|
|
@@ -3486,183 +3630,198 @@ function bn(t) {
|
|
|
3486
3630
|
eventType: "optimistic_user_message",
|
|
3487
3631
|
attachments: n.length ? n : void 0
|
|
3488
3632
|
}]), r;
|
|
3489
|
-
}, []),
|
|
3490
|
-
let
|
|
3491
|
-
return
|
|
3492
|
-
id
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
b ? b(e) : (o.getState().upsertSessions([{
|
|
3512
|
-
SessionId: e,
|
|
3513
|
-
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3514
|
-
}]), _.current = e, o.getState().setCurrentSessionId(e)), Ve(u, e), t !== e && n.current.set(e, a);
|
|
3515
|
-
},
|
|
3516
|
-
onSessionUpsert: () => {},
|
|
3517
|
-
onSettled: (e) => {
|
|
3518
|
-
y?.(e), r.current();
|
|
3519
|
-
}
|
|
3520
|
-
});
|
|
3521
|
-
return s || c.getState().setSessionStreaming(t, !1), s;
|
|
3522
|
-
}, [
|
|
3523
|
-
u,
|
|
3524
|
-
D,
|
|
3525
|
-
E,
|
|
3526
|
-
_,
|
|
3527
|
-
w,
|
|
3528
|
-
y,
|
|
3529
|
-
b
|
|
3530
|
-
]);
|
|
3531
|
-
I(() => {
|
|
3532
|
-
r.current = () => {
|
|
3533
|
-
let e = v.current.shift();
|
|
3534
|
-
if (!e) {
|
|
3535
|
-
i.getState().setQueuedDrafts([]);
|
|
3536
|
-
return;
|
|
3537
|
-
}
|
|
3538
|
-
i.getState().setQueuedDrafts((e) => e.slice(1)), queueMicrotask(() => {
|
|
3539
|
-
O(e) || (v.current.unshift(e), i.getState().setQueuedDrafts((t) => [e, ...t]));
|
|
3540
|
-
});
|
|
3541
|
-
};
|
|
3542
|
-
}, [v, O]);
|
|
3543
|
-
let k = F(async (e, t, n, r, i) => {
|
|
3544
|
-
let a = {
|
|
3633
|
+
}, []), M = L((e) => {
|
|
3634
|
+
let t = `optimistic-assistant-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
3635
|
+
return E.getState().patchMessages((n) => {
|
|
3636
|
+
let r = n.findIndex((t) => t.id === e), i = r < 0 ? n.length : r + 1;
|
|
3637
|
+
return [
|
|
3638
|
+
...n.slice(0, i),
|
|
3639
|
+
{
|
|
3640
|
+
id: t,
|
|
3641
|
+
role: "model",
|
|
3642
|
+
content: "",
|
|
3643
|
+
reasoning: "",
|
|
3644
|
+
timestamp: Date.now(),
|
|
3645
|
+
eventType: "optimistic_assistant_placeholder"
|
|
3646
|
+
},
|
|
3647
|
+
...n.slice(i)
|
|
3648
|
+
];
|
|
3649
|
+
}), t;
|
|
3650
|
+
}, []), ee = L(async (e, t, i, o, l, u) => {
|
|
3651
|
+
if (u && r.current.has(u)) return;
|
|
3652
|
+
let d = D();
|
|
3653
|
+
k(d);
|
|
3654
|
+
let f = {
|
|
3545
3655
|
text: e,
|
|
3546
|
-
attachments: t,
|
|
3547
|
-
responsesInput:
|
|
3548
|
-
previousResponseId:
|
|
3549
|
-
executionMode:
|
|
3550
|
-
optimisticMessageId:
|
|
3656
|
+
attachments: [...t],
|
|
3657
|
+
responsesInput: i,
|
|
3658
|
+
previousResponseId: o,
|
|
3659
|
+
executionMode: l,
|
|
3660
|
+
optimisticMessageId: j({
|
|
3551
3661
|
text: e,
|
|
3552
3662
|
attachments: t
|
|
3553
|
-
})
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
text: e,
|
|
3559
|
-
attachments: t,
|
|
3560
|
-
executionMode: i,
|
|
3561
|
-
optimisticMessageId: a.optimisticMessageId,
|
|
3562
|
-
optimisticAssistantMessageId: a.optimisticAssistantMessageId
|
|
3563
|
-
});
|
|
3564
|
-
return;
|
|
3565
|
-
}
|
|
3566
|
-
!O(a) && n === void 0 && T({
|
|
3663
|
+
})
|
|
3664
|
+
}, p = d.conversationId && w ? w : void 0, m = d.conversationId && p ? p.enqueue({
|
|
3665
|
+
requestId: u,
|
|
3666
|
+
conversationId: d.conversationId,
|
|
3667
|
+
agentId: d.agentId,
|
|
3567
3668
|
text: e,
|
|
3568
|
-
attachments: t
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3669
|
+
attachments: t.map((e) => ({
|
|
3670
|
+
name: e.name,
|
|
3671
|
+
type: e.type,
|
|
3672
|
+
size: e.size
|
|
3673
|
+
})),
|
|
3674
|
+
executionMode: l
|
|
3675
|
+
}) : void 0;
|
|
3676
|
+
m && p && (r.current.add(m.requestId), p.setRuntimeAttachments(m.requestId, t));
|
|
3677
|
+
let h;
|
|
3678
|
+
try {
|
|
3679
|
+
h = await S?.();
|
|
3680
|
+
} catch (e) {
|
|
3681
|
+
throw m && p && (r.current.delete(m.requestId), p.update(m.requestId, {
|
|
3682
|
+
status: "unknown",
|
|
3683
|
+
error: "创建会话的结果待确认。"
|
|
3684
|
+
})), e;
|
|
3685
|
+
}
|
|
3686
|
+
!d.sessionId && h && (d.sessionId = h);
|
|
3687
|
+
let g = () => {
|
|
3688
|
+
if (d.engine.stage !== "idle") return !1;
|
|
3689
|
+
d.engine.updateConfig(T), m && p && p.markSending(m.requestId), d.isVisible() && (s.getState().setMobileActionsOpen(!1), M(f.optimisticMessageId)), c.getState().setSessionStreaming(d.sessionId || d.conversationId, !0);
|
|
3690
|
+
let e = d.engine.start({
|
|
3691
|
+
...f,
|
|
3692
|
+
sessionId: d.sessionId,
|
|
3693
|
+
onInvocationCreated: (e) => {
|
|
3694
|
+
m && p && p.update(m.requestId, { invocationId: e });
|
|
3695
|
+
},
|
|
3696
|
+
onSessionCreated: (e) => {
|
|
3697
|
+
let t = d.isVisible(), r = d.sessionId || d.conversationId;
|
|
3698
|
+
d.sessionId = e, m && p && p.update(m.requestId, { nativeSessionId: e }), c.getState().setSessionStreaming(e, !0), r !== e && c.getState().setSessionStreaming(r, !1), d.conversationId || n.current.set(JSON.stringify([d.agentId, e]), d), x?.(e, d.conversationId, d.agentId), !x && t && (a.getState().upsertSessions([{
|
|
3699
|
+
SessionId: e,
|
|
3700
|
+
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3701
|
+
}]), v.current = e, a.getState().setCurrentSessionId(e)), t && Ue(d.agentId, e);
|
|
3702
|
+
},
|
|
3703
|
+
onSessionUpsert: () => {},
|
|
3704
|
+
onSettled: (e, t = "unknown") => {
|
|
3705
|
+
m && r.current.delete(m.requestId), m && p && p.update(m.requestId, { status: t === "completed" ? "completed" : t === "cancelled" ? "cancelled" : t === "failed" ? "failed" : "unknown" }), b?.(e, d.agentId, t), t === "completed" && A(d);
|
|
3706
|
+
}
|
|
3707
|
+
});
|
|
3708
|
+
return e || c.getState().setSessionStreaming(d.sessionId || d.conversationId, !1), e;
|
|
3709
|
+
};
|
|
3710
|
+
!g() && i === void 0 && (d.queue.push({
|
|
3711
|
+
draft: f,
|
|
3712
|
+
launch: g
|
|
3713
|
+
}), k(d));
|
|
3573
3714
|
}, [
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
_,
|
|
3715
|
+
M,
|
|
3716
|
+
j,
|
|
3577
3717
|
T,
|
|
3718
|
+
v,
|
|
3719
|
+
A,
|
|
3720
|
+
D,
|
|
3721
|
+
b,
|
|
3722
|
+
x,
|
|
3578
3723
|
w,
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
]),
|
|
3582
|
-
|
|
3583
|
-
}, [
|
|
3584
|
-
|
|
3585
|
-
}, [
|
|
3586
|
-
let t =
|
|
3587
|
-
if (
|
|
3588
|
-
|
|
3589
|
-
let
|
|
3724
|
+
k,
|
|
3725
|
+
S
|
|
3726
|
+
]), P = L(() => {
|
|
3727
|
+
O(v.current).stop();
|
|
3728
|
+
}, [v, O]), F = L(() => {
|
|
3729
|
+
O(v.current).disconnect();
|
|
3730
|
+
}, [v, O]), I = L((e) => {
|
|
3731
|
+
let t = D(e.sessionId), n = O(e.sessionId);
|
|
3732
|
+
if (n.stage !== "idle") return !1;
|
|
3733
|
+
Sn(), s.getState().setMobileActionsOpen(!1), c.getState().setSessionStreaming(e.sessionId, !0);
|
|
3734
|
+
let r = n.resumeCheckpoint({
|
|
3590
3735
|
...e,
|
|
3591
3736
|
onSettled: (e) => {
|
|
3592
|
-
|
|
3737
|
+
b?.(e, t.agentId), A(t);
|
|
3593
3738
|
}
|
|
3594
3739
|
});
|
|
3595
|
-
return
|
|
3596
|
-
}, [
|
|
3597
|
-
|
|
3740
|
+
return r || c.getState().setSessionStreaming(e.sessionId, !1), r;
|
|
3741
|
+
}, [
|
|
3742
|
+
A,
|
|
3743
|
+
O,
|
|
3744
|
+
D,
|
|
3745
|
+
b
|
|
3746
|
+
]), te = L(() => {
|
|
3747
|
+
Sn();
|
|
3598
3748
|
}, []);
|
|
3599
3749
|
return {
|
|
3600
|
-
submitDraft:
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3750
|
+
submitDraft: ee,
|
|
3751
|
+
isOutboxRequestActive: i,
|
|
3752
|
+
stopGeneration: P,
|
|
3753
|
+
disconnectRun: F,
|
|
3754
|
+
resumeCheckpoint: I,
|
|
3755
|
+
submitAguiAction: L((e) => {
|
|
3605
3756
|
let t = e.userAction;
|
|
3606
3757
|
if (!t) return !1;
|
|
3607
3758
|
let n = t.context || {}, r = String(n.interruptId || n.interrupt_id || "");
|
|
3608
3759
|
if (!r) return !1;
|
|
3609
|
-
let i =
|
|
3760
|
+
let i = v.current;
|
|
3610
3761
|
if (!i) return !1;
|
|
3611
|
-
let a =
|
|
3762
|
+
let a = D(i), o = O(i), s = n.status === "cancelled" ? "cancelled" : "resolved", c = Object.prototype.hasOwnProperty.call(n, "payload") ? n.payload : {
|
|
3612
3763
|
action: t.name,
|
|
3613
3764
|
sourceComponentId: t.sourceComponentId,
|
|
3614
3765
|
context: n
|
|
3615
3766
|
};
|
|
3616
|
-
return
|
|
3767
|
+
return o.resumeAguiInterrupt({
|
|
3617
3768
|
sessionId: i,
|
|
3618
3769
|
interruptId: r,
|
|
3619
|
-
status:
|
|
3620
|
-
payload:
|
|
3621
|
-
onSettled:
|
|
3770
|
+
status: s,
|
|
3771
|
+
payload: c,
|
|
3772
|
+
onSettled: (e) => {
|
|
3773
|
+
b?.(e, a.agentId), A(a);
|
|
3774
|
+
}
|
|
3622
3775
|
});
|
|
3623
3776
|
}, [
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3777
|
+
v,
|
|
3778
|
+
A,
|
|
3779
|
+
O,
|
|
3780
|
+
D,
|
|
3781
|
+
b
|
|
3627
3782
|
]),
|
|
3628
|
-
respondToAguiApproval:
|
|
3783
|
+
respondToAguiApproval: L((e) => {
|
|
3629
3784
|
if (!e.interruptId) return !1;
|
|
3630
|
-
let t =
|
|
3785
|
+
let t = v.current;
|
|
3631
3786
|
if (!t) return !1;
|
|
3632
|
-
let n =
|
|
3633
|
-
if (
|
|
3787
|
+
let n = D(t), r = O(t);
|
|
3788
|
+
if (r.stage !== "idle") return !1;
|
|
3634
3789
|
c.getState().setSessionStreaming(t, !0);
|
|
3635
|
-
let
|
|
3790
|
+
let i = r.resumeAguiInterrupt({
|
|
3636
3791
|
sessionId: t,
|
|
3637
3792
|
interruptId: e.interruptId,
|
|
3638
3793
|
status: "resolved",
|
|
3639
3794
|
payload: { decision: e.approve ? "approve" : "reject" },
|
|
3640
|
-
onSettled:
|
|
3795
|
+
onSettled: (e) => {
|
|
3796
|
+
b?.(e, n.agentId), A(n);
|
|
3797
|
+
}
|
|
3641
3798
|
});
|
|
3642
|
-
return
|
|
3799
|
+
return i || c.getState().setSessionStreaming(t, !1), i;
|
|
3643
3800
|
}, [
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3801
|
+
v,
|
|
3802
|
+
A,
|
|
3803
|
+
O,
|
|
3804
|
+
D,
|
|
3805
|
+
b
|
|
3647
3806
|
]),
|
|
3648
|
-
resetCompaction:
|
|
3807
|
+
resetCompaction: te
|
|
3649
3808
|
};
|
|
3650
3809
|
}
|
|
3651
3810
|
//#endregion
|
|
3652
3811
|
//#region src/utils/messages.js
|
|
3653
|
-
var
|
|
3812
|
+
var Tn = {
|
|
3654
3813
|
running: "running",
|
|
3655
3814
|
completed: "completed",
|
|
3656
3815
|
failed: "error",
|
|
3657
3816
|
paused: "paused",
|
|
3658
3817
|
approved: "completed",
|
|
3659
3818
|
denied: "completed"
|
|
3660
|
-
},
|
|
3819
|
+
}, En = {
|
|
3661
3820
|
paused: "pending",
|
|
3662
3821
|
approved: "approved",
|
|
3663
3822
|
denied: "rejected"
|
|
3664
3823
|
};
|
|
3665
|
-
function
|
|
3824
|
+
function Dn(e) {
|
|
3666
3825
|
if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
|
|
3667
3826
|
if (typeof e == "string") {
|
|
3668
3827
|
let t = Number(e.trim());
|
|
@@ -3672,7 +3831,7 @@ function Cn(e) {
|
|
|
3672
3831
|
}
|
|
3673
3832
|
return Date.now();
|
|
3674
3833
|
}
|
|
3675
|
-
function
|
|
3834
|
+
function On(e) {
|
|
3676
3835
|
if (typeof e == "string") return e;
|
|
3677
3836
|
if (e && typeof e == "object") {
|
|
3678
3837
|
if (typeof e.text == "string") return e.text;
|
|
@@ -3680,23 +3839,23 @@ function wn(e) {
|
|
|
3680
3839
|
}
|
|
3681
3840
|
return "";
|
|
3682
3841
|
}
|
|
3683
|
-
function
|
|
3842
|
+
function kn(e) {
|
|
3684
3843
|
let t = {}, n = /* @__PURE__ */ new Map();
|
|
3685
3844
|
for (let t of e ?? []) t?.Name && n.set(t.Name, (n.get(t.Name) || 0) + 1);
|
|
3686
3845
|
for (let r of e ?? []) {
|
|
3687
3846
|
if (!r?.Name) continue;
|
|
3688
|
-
let e =
|
|
3847
|
+
let e = Tn[String(r.Status ?? "completed").toLowerCase()] ?? "completed", i = {
|
|
3689
3848
|
name: r.Name,
|
|
3690
3849
|
args: r.Args === void 0 ? "" : typeof r.Args == "string" ? r.Args : JSON.stringify(r.Args),
|
|
3691
3850
|
status: e
|
|
3692
3851
|
};
|
|
3693
|
-
r.Result !== void 0 && (i.output = typeof r.Result == "string" ? r.Result : JSON.stringify(r.Result)), r.ApprovalRequestId && (i.approvalRequestId = r.ApprovalRequestId, i.approvalStatus =
|
|
3852
|
+
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.Status ?? "paused").toLowerCase()] ?? "pending", 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.previousResponseId = r.ToolCallId);
|
|
3694
3853
|
let a = n.get(r.Name) > 1 && r.ToolCallId ? r.ToolCallId : r.Name;
|
|
3695
3854
|
t[a] = i;
|
|
3696
3855
|
}
|
|
3697
3856
|
return t;
|
|
3698
3857
|
}
|
|
3699
|
-
function
|
|
3858
|
+
function An(e) {
|
|
3700
3859
|
if (Array.isArray(e)) return e.map((e) => ({
|
|
3701
3860
|
name: e.name || "",
|
|
3702
3861
|
url: e.url || "",
|
|
@@ -3704,10 +3863,10 @@ function En(e) {
|
|
|
3704
3863
|
fileUri: e.file_uri
|
|
3705
3864
|
}));
|
|
3706
3865
|
}
|
|
3707
|
-
function
|
|
3866
|
+
function jn(e) {
|
|
3708
3867
|
return e == null ? "" : typeof e == "string" ? e : JSON.stringify(e);
|
|
3709
3868
|
}
|
|
3710
|
-
function
|
|
3869
|
+
function Mn(e) {
|
|
3711
3870
|
if (!(!Array.isArray(e) || !e.length)) return e.flatMap((e, t) => {
|
|
3712
3871
|
let n = String(e?.Type || "").toLowerCase(), r = e?.SeqId ?? t;
|
|
3713
3872
|
if (n === "thinking" || n === "text") {
|
|
@@ -3720,36 +3879,36 @@ function On(e) {
|
|
|
3720
3879
|
}] : [];
|
|
3721
3880
|
}
|
|
3722
3881
|
if (n !== "tool") return [];
|
|
3723
|
-
let i =
|
|
3882
|
+
let i = Tn[String(e?.Status || "completed").toLowerCase()] ?? "completed";
|
|
3724
3883
|
return [{
|
|
3725
3884
|
id: `history-tool-${r}`,
|
|
3726
3885
|
type: "tool",
|
|
3727
3886
|
toolName: String(e?.Name || "tool"),
|
|
3728
|
-
args:
|
|
3729
|
-
...e?.Result === void 0 ? {} : { output:
|
|
3887
|
+
args: jn(e?.Args),
|
|
3888
|
+
...e?.Result === void 0 ? {} : { output: jn(e.Result) },
|
|
3730
3889
|
status: i,
|
|
3731
3890
|
...e?.ToolCallId ? { extra: { previousResponseId: String(e.ToolCallId) } } : {}
|
|
3732
3891
|
}];
|
|
3733
3892
|
});
|
|
3734
3893
|
}
|
|
3735
|
-
function
|
|
3736
|
-
let t = e.Role === "assistant" ? "model" : e.Role || "user", n = e.ToolEvents?.length ?
|
|
3894
|
+
function Nn(e) {
|
|
3895
|
+
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 = {
|
|
3737
3896
|
id: e.MessageId || `msg-${e.SeqId ?? Math.random().toString(36).slice(2)}`,
|
|
3738
3897
|
role: t,
|
|
3739
|
-
content:
|
|
3740
|
-
timestamp:
|
|
3898
|
+
content: On(e.Content),
|
|
3899
|
+
timestamp: Dn(e.Timestamp),
|
|
3741
3900
|
eventType: t === "user" ? "user_message" : "assistant_message",
|
|
3742
3901
|
reasoning: a,
|
|
3743
3902
|
tools: n,
|
|
3744
3903
|
attachments: r
|
|
3745
3904
|
};
|
|
3746
|
-
return t === "model" && (o.blocks = i ??
|
|
3905
|
+
return t === "model" && (o.blocks = i ?? ne({
|
|
3747
3906
|
reasoning: a,
|
|
3748
3907
|
tools: n,
|
|
3749
3908
|
content: o.content
|
|
3750
3909
|
})), e.MessageId && (o.eventId = e.MessageId), e.InvocationId && (o.invocationId = e.InvocationId), e.ResponseId && (o.responseId = e.ResponseId), e.TraceId && (o.traceId = e.TraceId), e.RootSpanId && (o.rootSpanId = e.RootSpanId), o;
|
|
3751
3910
|
}
|
|
3752
|
-
function
|
|
3911
|
+
function Pn(e) {
|
|
3753
3912
|
return Array.isArray(e.Activities) ? e.Activities.flatMap((t, n) => {
|
|
3754
3913
|
let r = String(t?.SurfaceId || "");
|
|
3755
3914
|
if (!r) return [];
|
|
@@ -3763,37 +3922,37 @@ function An(e) {
|
|
|
3763
3922
|
id: o && o !== String(e.MessageId || "") ? o : `${o || e.MessageId || e.SeqId || "message"}:a2ui:${r}:${n}`,
|
|
3764
3923
|
role: "a2ui",
|
|
3765
3924
|
content: "",
|
|
3766
|
-
timestamp:
|
|
3925
|
+
timestamp: Dn(e.Timestamp),
|
|
3767
3926
|
aguiActivity: {
|
|
3768
3927
|
surfaceId: r,
|
|
3769
|
-
messages:
|
|
3928
|
+
messages: l(a)
|
|
3770
3929
|
}
|
|
3771
3930
|
}];
|
|
3772
3931
|
}) : [];
|
|
3773
3932
|
}
|
|
3774
|
-
function
|
|
3775
|
-
return e.flatMap((e) => [
|
|
3933
|
+
function Fn(e) {
|
|
3934
|
+
return e.flatMap((e) => [Nn(e), ...Pn(e)]);
|
|
3776
3935
|
}
|
|
3777
3936
|
//#endregion
|
|
3778
3937
|
//#region src/utils/session-event-history.ts
|
|
3779
|
-
var
|
|
3938
|
+
var In = class extends Error {
|
|
3780
3939
|
seq;
|
|
3781
3940
|
constructor(e) {
|
|
3782
3941
|
super(`Session event seq ${e} was received twice with conflicting content`), this.name = "SessionEventConflictError", this.seq = e;
|
|
3783
3942
|
}
|
|
3784
3943
|
};
|
|
3785
|
-
function
|
|
3786
|
-
return Array.isArray(e) ? `[${e.map(
|
|
3944
|
+
function Ln(e) {
|
|
3945
|
+
return Array.isArray(e) ? `[${e.map(Ln).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)}:${Ln(t)}`).join(",")}}` : JSON.stringify(e) ?? "null";
|
|
3787
3946
|
}
|
|
3788
|
-
var
|
|
3947
|
+
var Rn = new Set(["runtime"]), zn = class {
|
|
3789
3948
|
eventsBySeq = /* @__PURE__ */ new Map();
|
|
3790
3949
|
lastSeqValue = 0;
|
|
3791
3950
|
accept(e) {
|
|
3792
|
-
let t =
|
|
3951
|
+
let t = Fe(e);
|
|
3793
3952
|
if (!t.ok) throw t.error;
|
|
3794
3953
|
let n = t.value, r = this.eventsBySeq.get(n.seq);
|
|
3795
3954
|
if (r) {
|
|
3796
|
-
if (
|
|
3955
|
+
if (Ln(r) !== Ln(n)) throw new In(n.seq);
|
|
3797
3956
|
return;
|
|
3798
3957
|
}
|
|
3799
3958
|
this.eventsBySeq.set(n.seq, n), this.lastSeqValue = Math.max(this.lastSeqValue, n.seq);
|
|
@@ -3805,39 +3964,46 @@ var Pn = new Set(["runtime"]), Fn = class {
|
|
|
3805
3964
|
return this.lastSeqValue;
|
|
3806
3965
|
}
|
|
3807
3966
|
displayableEvents() {
|
|
3808
|
-
return [...this.eventsBySeq.values()].filter((e) =>
|
|
3967
|
+
return [...this.eventsBySeq.values()].filter((e) => Rn.has(e.family)).sort((e, t) => e.seq - t.seq);
|
|
3809
3968
|
}
|
|
3810
3969
|
};
|
|
3811
|
-
function
|
|
3812
|
-
return new
|
|
3970
|
+
function Bn() {
|
|
3971
|
+
return new zn();
|
|
3813
3972
|
}
|
|
3814
3973
|
//#endregion
|
|
3815
3974
|
//#region src/hooks/useSessionLifecycle.ts
|
|
3816
|
-
var
|
|
3817
|
-
function
|
|
3975
|
+
var Vn = 500, Hn = 30, Un = 50, Wn = 200, Gn = 8, Kn = 128, qn = 1800 * 1e3;
|
|
3976
|
+
function $(e, t, n, r, i = Kn) {
|
|
3977
|
+
for (e.delete(t), e.set(t, n); e.size > i;) {
|
|
3978
|
+
let t = [...e.keys()].find((e) => e !== r);
|
|
3979
|
+
if (!t) break;
|
|
3980
|
+
e.delete(t);
|
|
3981
|
+
}
|
|
3982
|
+
}
|
|
3983
|
+
function Jn(e) {
|
|
3818
3984
|
return new Promise((t) => {
|
|
3819
3985
|
if (e.aborted) {
|
|
3820
3986
|
t();
|
|
3821
3987
|
return;
|
|
3822
3988
|
}
|
|
3823
|
-
let n = globalThis.setTimeout(t,
|
|
3989
|
+
let n = globalThis.setTimeout(t, Vn);
|
|
3824
3990
|
e.addEventListener("abort", () => {
|
|
3825
3991
|
globalThis.clearTimeout(n), t();
|
|
3826
3992
|
}, { once: !0 });
|
|
3827
3993
|
});
|
|
3828
3994
|
}
|
|
3829
|
-
var
|
|
3995
|
+
var Yn = new Set([
|
|
3830
3996
|
"in_progress",
|
|
3831
3997
|
"running",
|
|
3832
3998
|
"resuming",
|
|
3833
3999
|
"starting"
|
|
3834
4000
|
]);
|
|
3835
|
-
function
|
|
4001
|
+
function Xn(e) {
|
|
3836
4002
|
let t = e.ActiveRunUpdatedAt || e.UpdatedAt, n = typeof t == "number" ? t > 1e11 ? t : t * 1e3 : Date.parse(String(t || ""));
|
|
3837
|
-
return Number.isFinite(n) && n <= Date.now() +
|
|
4003
|
+
return Number.isFinite(n) && n <= Date.now() + qn && Date.now() - n <= qn;
|
|
3838
4004
|
}
|
|
3839
|
-
function
|
|
3840
|
-
let t =
|
|
4005
|
+
function Zn(e) {
|
|
4006
|
+
let t = P(e);
|
|
3841
4007
|
return t ? t === "completed" ? {
|
|
3842
4008
|
status: "completed",
|
|
3843
4009
|
phase: "后台长任务已完成"
|
|
@@ -3855,9 +4021,9 @@ function Kn(e) {
|
|
|
3855
4021
|
phase: "后台长任务恢复失败"
|
|
3856
4022
|
} : null : null;
|
|
3857
4023
|
}
|
|
3858
|
-
function
|
|
3859
|
-
let { agentId: t, api: n, isMobile: r, resetCompaction:
|
|
3860
|
-
let i = r.filter((e) =>
|
|
4024
|
+
function Qn(e) {
|
|
4025
|
+
let { agentId: t, api: n, isMobile: r, resetCompaction: i, uiCapabilities: l, disconnectRun: u, restoreSession: d = !0 } = e, f = z(e.currentSessionId), p = z(e.agentId), m = z(null), h = z(Bn()), g = z(0), _ = z(null), y = z(null), x = z(/* @__PURE__ */ new Map()), C = z(/* @__PURE__ */ new Map()), w = z(/* @__PURE__ */ new Map()), T = z(/* @__PURE__ */ new Map()), D = z(/* @__PURE__ */ new Map()), O = z(/* @__PURE__ */ new Map()), k = z(null), A = z(null), j = z(null), M = L(async (e, t, r) => {
|
|
4026
|
+
let i = r.filter((e) => v(e, !1, !1));
|
|
3861
4027
|
if (!i.length) return;
|
|
3862
4028
|
let a = await Promise.all(i.map(async (r) => {
|
|
3863
4029
|
try {
|
|
@@ -3866,7 +4032,7 @@ function qn(e) {
|
|
|
3866
4032
|
SessionId: t,
|
|
3867
4033
|
ResponseId: r.responseId,
|
|
3868
4034
|
EventId: r.eventId
|
|
3869
|
-
}), a = i?.Feedback ?
|
|
4035
|
+
}), a = i?.Feedback ? S(i.Feedback) : null;
|
|
3870
4036
|
return a ? {
|
|
3871
4037
|
messageId: r.id,
|
|
3872
4038
|
feedback: a
|
|
@@ -3877,11 +4043,11 @@ function qn(e) {
|
|
|
3877
4043
|
}));
|
|
3878
4044
|
if (f.current !== t) return;
|
|
3879
4045
|
let o = new Map(a.filter((e) => !!e).map((e) => [e.messageId, e.feedback]));
|
|
3880
|
-
o.size &&
|
|
4046
|
+
o.size && E.getState().patchMessages((e) => e.map((e) => o.has(e.id) ? {
|
|
3881
4047
|
...e,
|
|
3882
4048
|
feedback: o.get(e.id)
|
|
3883
4049
|
} : e));
|
|
3884
|
-
}, [n]),
|
|
4050
|
+
}, [n]), N = L(async (e) => {
|
|
3885
4051
|
m.current?.abort();
|
|
3886
4052
|
let t = new AbortController();
|
|
3887
4053
|
m.current = t;
|
|
@@ -3909,7 +4075,7 @@ function qn(e) {
|
|
|
3909
4075
|
let { value: t, done: n } = await l.read();
|
|
3910
4076
|
if (n) break;
|
|
3911
4077
|
d += u.decode(t, { stream: !0 });
|
|
3912
|
-
let s =
|
|
4078
|
+
let s = jt(d);
|
|
3913
4079
|
d = s.remainder;
|
|
3914
4080
|
for (let t of s.chunks) if (t.trim()) {
|
|
3915
4081
|
for (let n of Y(t)) {
|
|
@@ -3935,12 +4101,12 @@ function qn(e) {
|
|
|
3935
4101
|
} catch (e) {
|
|
3936
4102
|
console.error("[SessionLifecycle] session event cursor conflict:", e);
|
|
3937
4103
|
}
|
|
3938
|
-
a = Math.max(a, h.current.reconnectAfterSeq()),
|
|
4104
|
+
a = Math.max(a, h.current.reconnectAfterSeq()), xn({
|
|
3939
4105
|
type: "stream_event",
|
|
3940
4106
|
sessionId: e.sessionId,
|
|
3941
4107
|
event: t
|
|
3942
4108
|
}), i ||= ee(t), r ||= i;
|
|
3943
|
-
let n =
|
|
4109
|
+
let n = Zn(t);
|
|
3944
4110
|
n && c.getState().updateActivity({
|
|
3945
4111
|
sessionId: e.sessionId,
|
|
3946
4112
|
status: n.status,
|
|
@@ -3951,12 +4117,12 @@ function qn(e) {
|
|
|
3951
4117
|
continue;
|
|
3952
4118
|
}
|
|
3953
4119
|
let s = Number(t.SeqId || 0);
|
|
3954
|
-
Number.isFinite(s) && (a = Math.max(a, s)),
|
|
4120
|
+
Number.isFinite(s) && (a = Math.max(a, s)), xn({
|
|
3955
4121
|
type: "stream_event",
|
|
3956
4122
|
sessionId: e.sessionId,
|
|
3957
4123
|
event: t
|
|
3958
4124
|
}), i ||= ee(t), r ||= i;
|
|
3959
|
-
let l =
|
|
4125
|
+
let l = Zn(t);
|
|
3960
4126
|
if (l && c.getState().updateActivity({
|
|
3961
4127
|
sessionId: e.sessionId,
|
|
3962
4128
|
status: l.status,
|
|
@@ -3979,9 +4145,9 @@ function qn(e) {
|
|
|
3979
4145
|
countEvent: !1
|
|
3980
4146
|
});
|
|
3981
4147
|
}
|
|
3982
|
-
!i && o() && await
|
|
4148
|
+
!i && o() && await Jn(t.signal);
|
|
3983
4149
|
}
|
|
3984
|
-
i && o() &&
|
|
4150
|
+
i && o() && xn({
|
|
3985
4151
|
type: "stream_ended",
|
|
3986
4152
|
sessionId: e.sessionId
|
|
3987
4153
|
});
|
|
@@ -3989,33 +4155,30 @@ function qn(e) {
|
|
|
3989
4155
|
e instanceof DOMException && e.name === "AbortError" || console.error("Failed to subscribe run events:", e);
|
|
3990
4156
|
} finally {
|
|
3991
4157
|
let n = m.current === t;
|
|
3992
|
-
n && (m.current = null), n && f.current === e.sessionId && (c.getState().setCurrentRunId(""), c.getState().setActiveInvocationId(""), r &&
|
|
4158
|
+
n && (m.current = null), n && f.current === e.sessionId && (c.getState().setCurrentRunId(""), c.getState().setActiveInvocationId(""), r && A.current?.(e.sessionId), j.current?.(p.current, e.sessionId));
|
|
3993
4159
|
}
|
|
3994
|
-
}, [n]),
|
|
3995
|
-
!
|
|
4160
|
+
}, [n]), P = L((e) => {
|
|
4161
|
+
!l.RunLifecycle.Enabled || !e.runId || p.current !== t || f.current !== e.sessionId || m.current || N({
|
|
3996
4162
|
sessionId: e.sessionId,
|
|
3997
4163
|
invocationId: e.runId,
|
|
3998
|
-
afterSeqId:
|
|
4164
|
+
afterSeqId: se(D.current.get(e.sessionId)?.events || [])
|
|
3999
4165
|
});
|
|
4000
4166
|
}, [
|
|
4001
4167
|
t,
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
]),
|
|
4005
|
-
let t = f.current,
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
t && t !== e && (d(t, l.getState().messages), l.getState().setMessages(h || []), o.getState().clearSessionMessageHistory(e), x.getState().setSessionCheckpoints(e, []), x.getState().setSessionToolReceipts(e, []), c.getState().setCurrentRunId(""), c.getState().clearActivity()), f.current = e;
|
|
4014
|
-
let _ = () => f.current === e && g.current === s;
|
|
4015
|
-
o.getState().setCurrentSessionId(e), o.getState().setSessionInitialMessageHistoryLoading(e, !h), a(), m.current?.abort(), r && i.getState().setMobileSidebarOpen(!1);
|
|
4168
|
+
N,
|
|
4169
|
+
l.RunLifecycle.Enabled
|
|
4170
|
+
]), F = L(async (e) => {
|
|
4171
|
+
let t = f.current, o = ++g.current;
|
|
4172
|
+
_.current = o, y.current = null;
|
|
4173
|
+
let u = (e, t) => {
|
|
4174
|
+
$(w.current, e, t, f.current, Gn);
|
|
4175
|
+
}, d = w.current.get(e);
|
|
4176
|
+
t && t !== e && (u(t, E.getState().messages), E.getState().setMessages(d || []), a.getState().clearSessionMessageHistory(e), b.getState().setSessionCheckpoints(e, []), b.getState().setSessionToolReceipts(e, []), c.getState().setCurrentRunId(""), c.getState().clearActivity()), f.current = e;
|
|
4177
|
+
let h = () => f.current === e && g.current === o;
|
|
4178
|
+
a.getState().setCurrentSessionId(e), a.getState().setSessionInitialMessageHistoryLoading(e, !d), i(), m.current?.abort(), r && s.getState().setMobileSidebarOpen(!1);
|
|
4016
4179
|
try {
|
|
4017
4180
|
let t = {
|
|
4018
|
-
limit:
|
|
4181
|
+
limit: Un,
|
|
4019
4182
|
includeReasoning: !0,
|
|
4020
4183
|
includeToolEvents: !0,
|
|
4021
4184
|
includeAttachments: !0
|
|
@@ -4023,237 +4186,270 @@ function qn(e) {
|
|
|
4023
4186
|
try {
|
|
4024
4187
|
r = await n.listSessionMessages(e, t);
|
|
4025
4188
|
} catch (i) {
|
|
4026
|
-
if (i instanceof
|
|
4027
|
-
if (await new Promise((e) => globalThis.setTimeout(e, 180)), !
|
|
4189
|
+
if (i instanceof H) throw i;
|
|
4190
|
+
if (await new Promise((e) => globalThis.setTimeout(e, 180)), !h()) return;
|
|
4028
4191
|
r = await n.listSessionMessages(e, t);
|
|
4029
4192
|
}
|
|
4030
|
-
if (!
|
|
4031
|
-
let i =
|
|
4032
|
-
|
|
4033
|
-
let
|
|
4034
|
-
|
|
4193
|
+
if (!h()) return;
|
|
4194
|
+
let i = Fn(r.Messages);
|
|
4195
|
+
$(T.current, e, i, f.current);
|
|
4196
|
+
let s = i, c = 0, m = [];
|
|
4197
|
+
d || (E.getState().setMessages(i), u(e, i)), a.getState().setSessionMessageHistory(e, {
|
|
4035
4198
|
nextCursor: r.NextCursor,
|
|
4036
4199
|
hasMore: r.HasMore
|
|
4037
|
-
}),
|
|
4200
|
+
}), a.getState().setSessionInitialMessageHistoryLoading(e, !1);
|
|
4038
4201
|
try {
|
|
4039
4202
|
let t = await n.listSessionEvents(e, {
|
|
4040
4203
|
offset: 0,
|
|
4041
|
-
limit:
|
|
4204
|
+
limit: Wn
|
|
4042
4205
|
});
|
|
4043
|
-
if (!
|
|
4044
|
-
let
|
|
4206
|
+
if (!h()) return;
|
|
4207
|
+
let o = {
|
|
4045
4208
|
events: t.Events || [],
|
|
4046
4209
|
loadedCount: t.Events?.length || 0,
|
|
4047
4210
|
total: Math.max(0, Number(t.Total ?? t.Events?.length ?? 0) || 0)
|
|
4048
4211
|
};
|
|
4049
|
-
if (
|
|
4212
|
+
if ($(D.current, e, o, f.current), a.getState().setSessionMessageHistory(e, {
|
|
4050
4213
|
nextCursor: r.NextCursor,
|
|
4051
|
-
hasMore: !!(r.HasMore ||
|
|
4052
|
-
}),
|
|
4053
|
-
|
|
4054
|
-
let t =
|
|
4055
|
-
|
|
4056
|
-
for (let t of
|
|
4214
|
+
hasMore: !!(r.HasMore || o.loadedCount < o.total)
|
|
4215
|
+
}), o.events.length > 0) {
|
|
4216
|
+
c = se(o.events);
|
|
4217
|
+
let t = oe(i, o.events, e);
|
|
4218
|
+
m = t.canonicalRunIds, s = t.messages;
|
|
4219
|
+
for (let t of o.events) ft(t, e);
|
|
4057
4220
|
}
|
|
4058
4221
|
} catch (e) {
|
|
4059
|
-
|
|
4222
|
+
h() && (y.current = {
|
|
4223
|
+
generation: o,
|
|
4224
|
+
message: "完整事件历史读取失败,请刷新会话后重新查找。当前结果只包含已读取的正文。"
|
|
4225
|
+
}), console.warn("[SessionLifecycle] canonical history replay failed:", e);
|
|
4060
4226
|
}
|
|
4061
|
-
if (!
|
|
4062
|
-
|
|
4063
|
-
let
|
|
4064
|
-
if (
|
|
4227
|
+
if (!h()) return;
|
|
4228
|
+
$(C.current, e, new Set(m), f.current), E.getState().setMessages(s), u(e, s), _.current = null, M(p.current, e, s);
|
|
4229
|
+
let g = Math.max(r.LatestSeqId || 0, c), v = W.getState().capabilities || l;
|
|
4230
|
+
if (v.RunLifecycle.Enabled && v.RunLifecycle.Checkpoints ? (n.listSessionCheckpoints({
|
|
4065
4231
|
agentId: p.current,
|
|
4066
4232
|
sessionId: e
|
|
4067
4233
|
}).then((t) => {
|
|
4068
|
-
|
|
4234
|
+
h() && b.getState().setSessionCheckpoints(e, t.Checkpoints || []);
|
|
4069
4235
|
}).catch((t) => {
|
|
4070
|
-
|
|
4236
|
+
h() && (console.warn("[SessionLifecycle] checkpoint load failed:", t), b.getState().setSessionCheckpoints(e, []));
|
|
4071
4237
|
}), n.listToolReceipts({
|
|
4072
4238
|
agentId: p.current,
|
|
4073
4239
|
sessionId: e
|
|
4074
4240
|
}).then((t) => {
|
|
4075
|
-
|
|
4241
|
+
h() && b.getState().setSessionToolReceipts(e, t.ToolReceipts || []);
|
|
4076
4242
|
}).catch((t) => {
|
|
4077
|
-
|
|
4078
|
-
})) :
|
|
4243
|
+
h() && (console.warn("[SessionLifecycle] tool receipt load failed:", t), b.getState().setSessionToolReceipts(e, []));
|
|
4244
|
+
})) : b.getState().clearSessionCheckpoints(e), v.RunLifecycle.Enabled && v.RunLifecycle.Resume) try {
|
|
4079
4245
|
let t = await n.getSession(e);
|
|
4080
|
-
if (!
|
|
4246
|
+
if (!h()) return;
|
|
4081
4247
|
let r = String(t.ActiveRunStatus || "").toLowerCase();
|
|
4082
|
-
t.ActiveInvocationId && (
|
|
4248
|
+
t.ActiveInvocationId && (Yn.has(r) || r === "" && Xn(t)) && N({
|
|
4083
4249
|
sessionId: e,
|
|
4084
4250
|
invocationId: t.ActiveInvocationId,
|
|
4085
|
-
afterSeqId:
|
|
4251
|
+
afterSeqId: g
|
|
4086
4252
|
});
|
|
4087
4253
|
} catch (e) {
|
|
4088
4254
|
console.warn("[SessionLifecycle] getSession for reconnect failed:", e);
|
|
4089
4255
|
}
|
|
4090
4256
|
} catch (e) {
|
|
4091
|
-
|
|
4257
|
+
h() && (y.current = {
|
|
4258
|
+
generation: o,
|
|
4259
|
+
message: "会话历史读取失败,请刷新会话后重新查找。"
|
|
4260
|
+
}), console.error("Failed to load session messages:", e);
|
|
4092
4261
|
} finally {
|
|
4093
|
-
_() &&
|
|
4262
|
+
_.current === o && (_.current = null), h() && a.getState().setSessionInitialMessageHistoryLoading(e, !1);
|
|
4094
4263
|
}
|
|
4095
4264
|
}, [
|
|
4096
4265
|
n,
|
|
4097
4266
|
r,
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
]),
|
|
4267
|
+
M,
|
|
4268
|
+
i,
|
|
4269
|
+
N,
|
|
4270
|
+
l
|
|
4271
|
+
]), I = L(async (e = "default-agent", t = null) => {
|
|
4103
4272
|
try {
|
|
4104
|
-
let r =
|
|
4105
|
-
r.sessionsAgentId && r.sessionsAgentId !== e && r.resetSessionPagination(e),
|
|
4273
|
+
let r = a.getState();
|
|
4274
|
+
r.sessionsAgentId && r.sessionsAgentId !== e && r.resetSessionPagination(e), a.getState().setLoadingSessions(!0);
|
|
4106
4275
|
let i = await n.listSessions(e, {
|
|
4107
4276
|
page: 1,
|
|
4108
|
-
pageSize:
|
|
4109
|
-
})
|
|
4110
|
-
|
|
4111
|
-
let
|
|
4112
|
-
|
|
4277
|
+
pageSize: Hn
|
|
4278
|
+
});
|
|
4279
|
+
if (W.getState().agentId !== e) return;
|
|
4280
|
+
let o = i.Sessions || [];
|
|
4281
|
+
for (let e of o) O.current.delete(e.SessionId);
|
|
4282
|
+
let s = new Set(Array.from(O.current.entries()).filter(([, t]) => t === e).map(([e]) => e)), c = Ge(o, a.getState().sessions, s);
|
|
4283
|
+
if (a.getState().upsertSessions(c, {
|
|
4113
4284
|
agentId: e,
|
|
4114
4285
|
total: Number(i.Total ?? i.Sessions?.length ?? 0),
|
|
4115
4286
|
page: Number(i.Page ?? 1),
|
|
4116
|
-
pageSize: Number(i.PageSize ??
|
|
4287
|
+
pageSize: Number(i.PageSize ?? Hn),
|
|
4117
4288
|
replace: !0
|
|
4118
|
-
}),
|
|
4119
|
-
let
|
|
4120
|
-
|
|
4289
|
+
}), k.current) return;
|
|
4290
|
+
let l = a.getState().sessions, u = f.current, p = u || (d ? We(l, t || He(e)) : null);
|
|
4291
|
+
p && p !== u && F(p);
|
|
4121
4292
|
} catch (e) {
|
|
4122
|
-
if (e instanceof
|
|
4293
|
+
if (e instanceof H) return;
|
|
4123
4294
|
console.error("Failed to fetch sessions:", e);
|
|
4124
4295
|
} finally {
|
|
4125
|
-
|
|
4296
|
+
W.getState().agentId === e && a.getState().setLoadingSessions(!1);
|
|
4126
4297
|
}
|
|
4127
4298
|
}, [
|
|
4128
4299
|
n,
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
]),
|
|
4132
|
-
let e =
|
|
4300
|
+
F,
|
|
4301
|
+
d
|
|
4302
|
+
]), te = L(async () => {
|
|
4303
|
+
let e = a.getState();
|
|
4133
4304
|
if (e.isLoadingSessions || !e.hasMoreSessions) return;
|
|
4134
|
-
let t =
|
|
4305
|
+
let t = o({
|
|
4135
4306
|
total: e.sessionsTotal,
|
|
4136
|
-
pageSize: e.sessionsPageSize ||
|
|
4307
|
+
pageSize: e.sessionsPageSize || Hn,
|
|
4137
4308
|
loadedPages: e.loadedPages
|
|
4138
4309
|
});
|
|
4139
4310
|
if (!t) return;
|
|
4140
|
-
let r = e.sessionsPageSize ||
|
|
4311
|
+
let r = e.sessionsPageSize || Hn, i = e.sessionsAgentId || p.current || "default-agent";
|
|
4141
4312
|
try {
|
|
4142
|
-
|
|
4143
|
-
let
|
|
4313
|
+
a.getState().setLoadingSessions(!0);
|
|
4314
|
+
let o = await n.listSessions(i, {
|
|
4144
4315
|
page: t,
|
|
4145
4316
|
pageSize: r
|
|
4146
4317
|
});
|
|
4147
|
-
|
|
4318
|
+
a.getState().upsertSessions(o.Sessions || [], {
|
|
4148
4319
|
agentId: i,
|
|
4149
|
-
total: Number(
|
|
4150
|
-
page: Number(
|
|
4151
|
-
pageSize: Number(
|
|
4320
|
+
total: Number(o.Total ?? e.sessionsTotal),
|
|
4321
|
+
page: Number(o.Page ?? t),
|
|
4322
|
+
pageSize: Number(o.PageSize ?? r)
|
|
4152
4323
|
});
|
|
4153
4324
|
} catch (e) {
|
|
4154
|
-
if (e instanceof
|
|
4325
|
+
if (e instanceof H) return;
|
|
4155
4326
|
console.error("Failed to load more sessions:", e);
|
|
4156
4327
|
} finally {
|
|
4157
|
-
|
|
4328
|
+
a.getState().setLoadingSessions(!1);
|
|
4158
4329
|
}
|
|
4159
4330
|
}, [n]);
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
}, [
|
|
4163
|
-
|
|
4164
|
-
}, [
|
|
4165
|
-
let
|
|
4166
|
-
g.current += 1, m.current?.abort(),
|
|
4331
|
+
R(() => {
|
|
4332
|
+
A.current = F;
|
|
4333
|
+
}, [F]), R(() => {
|
|
4334
|
+
j.current = I;
|
|
4335
|
+
}, [I]);
|
|
4336
|
+
let ne = L((e, t = !1) => {
|
|
4337
|
+
g.current += 1, m.current?.abort(), O.current.set(e, p.current), a.getState().upsertSessions([{
|
|
4167
4338
|
SessionId: e,
|
|
4168
4339
|
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4169
|
-
}]), f.current = e,
|
|
4170
|
-
}, [r]), re =
|
|
4171
|
-
g.current += 1, m.current?.abort(), f.current = null,
|
|
4340
|
+
}]), f.current = e, a.getState().setCurrentSessionId(e), t || (E.getState().setMessages([]), c.getState().setCurrentRunId(""), c.getState().clearActivity()), a.getState().clearSessionMessageHistory(e), b.getState().setSessionCheckpoints(e, []), b.getState().setSessionToolReceipts(e, []), r && (s.getState().setMobileSidebarOpen(!1), s.getState().setMobileActionsOpen(!1));
|
|
4341
|
+
}, [r]), re = L(() => {
|
|
4342
|
+
g.current += 1, m.current?.abort(), f.current = null, a.getState().setCurrentSessionId(null), E.getState().setMessages([]), c.getState().setCurrentRunId(""), c.getState().clearActivity(), r && s.getState().setMobileSidebarOpen(!1);
|
|
4343
|
+
}, [r]), ie = L(async () => {
|
|
4344
|
+
if (k.current) {
|
|
4345
|
+
await k.current;
|
|
4346
|
+
return;
|
|
4347
|
+
}
|
|
4348
|
+
g.current += 1, m.current?.abort(), f.current = null, a.getState().setCurrentSessionId(null), E.getState().setMessages([]);
|
|
4172
4349
|
let e = n.createSession(t).then((e) => {
|
|
4173
|
-
let
|
|
4174
|
-
return t &&
|
|
4175
|
-
}).catch((e) => (e instanceof
|
|
4176
|
-
|
|
4350
|
+
let n = e.SessionId || null;
|
|
4351
|
+
return n && W.getState().agentId === t && ne(n, E.getState().messages.some((e) => e.eventType === "optimistic_user_message" || e.eventType === "optimistic_assistant_placeholder")), n;
|
|
4352
|
+
}).catch((e) => (e instanceof H || console.error("Failed to create session:", e), null));
|
|
4353
|
+
k.current = e;
|
|
4177
4354
|
try {
|
|
4178
4355
|
await e;
|
|
4179
4356
|
} finally {
|
|
4180
|
-
|
|
4357
|
+
k.current === e && (k.current = null);
|
|
4181
4358
|
}
|
|
4182
4359
|
}, [
|
|
4183
|
-
|
|
4360
|
+
ne,
|
|
4184
4361
|
t,
|
|
4185
4362
|
n
|
|
4186
|
-
]),
|
|
4363
|
+
]), ae = L(async () => {
|
|
4364
|
+
let e = k.current;
|
|
4365
|
+
return e ? await e : f.current;
|
|
4366
|
+
}, []), ce = L(async (e) => {
|
|
4187
4367
|
try {
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
return;
|
|
4191
|
-
}
|
|
4192
|
-
o.getState().removeSession(e), o.getState().clearSessionMessageHistory(e), b.current.delete(e), S.current.delete(e), w.current.delete(e), v.current.delete(e), T.current.delete(e), f.current === e && (g.current += 1, m.current?.abort(), d?.(), f.current = null, l.getState().setMessages([]), x.getState().clearSessionCheckpoints(e), o.getState().setCurrentSessionId(null), c.getState().setCurrentRunId(""), c.getState().clearActivity(), M(t));
|
|
4368
|
+
let r = await n.deleteSession(e);
|
|
4369
|
+
return W.getState().agentId === t ? r.Deleted === !1 ? (s.getState().pushToast("会话暂未删除,云端运行时仍在同步,请稍后重试。", "error"), I(t, f.current ?? void 0), !1) : (a.getState().removeSession(e), a.getState().clearSessionMessageHistory(e), w.current.delete(e), T.current.delete(e), D.current.delete(e), C.current.delete(e), O.current.delete(e), f.current === e && (g.current += 1, m.current?.abort(), u?.(), f.current = null, E.getState().setMessages([]), b.getState().clearSessionCheckpoints(e), a.getState().setCurrentSessionId(null), c.getState().setCurrentRunId(""), c.getState().clearActivity(), I(t)), !0) : r.Deleted !== !1;
|
|
4193
4370
|
} catch (e) {
|
|
4194
|
-
|
|
4195
|
-
console.error("Failed to delete session", e), i.getState().pushToast("删除会话失败,请稍后重试。", "error");
|
|
4371
|
+
return e instanceof H ? !1 : (console.error("Failed to delete session", e), s.getState().pushToast("删除会话失败,请稍后重试。", "error"), !1);
|
|
4196
4372
|
}
|
|
4197
4373
|
}, [
|
|
4198
4374
|
t,
|
|
4199
4375
|
n,
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
])
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
total: T
|
|
4235
|
-
});
|
|
4236
|
-
for (let n of t) ut(n, e);
|
|
4237
|
-
}
|
|
4238
|
-
let E = ce(y, x, e), D = E.messages;
|
|
4239
|
-
v.current.set(e, new Set(E.canonicalRunIds)), l.getState().setMessages(D), b.current.delete(e), b.current.set(e, D), o.getState().setSessionMessageHistory(e, {
|
|
4240
|
-
nextCursor: u ? u.NextCursor : t.nextCursor,
|
|
4241
|
-
hasMore: !!(u && u.HasMore || C < T)
|
|
4242
|
-
}), k(p.current, e, m);
|
|
4243
|
-
} catch (e) {
|
|
4244
|
-
e instanceof B || console.error("Failed to load older session messages:", e);
|
|
4245
|
-
} finally {
|
|
4246
|
-
_.current.get(e) === c && (_.current.delete(e), o.getState().setSessionMessageHistoryLoading(e, !1));
|
|
4376
|
+
u,
|
|
4377
|
+
I
|
|
4378
|
+
]), le = L(async (e, t) => {
|
|
4379
|
+
t?.throwIfAborted();
|
|
4380
|
+
let r = a.getState().messageHistory[e], i = D.current.get(e), o = !!(r?.hasMore && r.nextCursor !== null), s = !!(i && i.loadedCount < i.total);
|
|
4381
|
+
if (!r || r.isLoadingOlder || !o && !s) return;
|
|
4382
|
+
let c = g.current, l = Symbol(e);
|
|
4383
|
+
x.current.set(e, l);
|
|
4384
|
+
try {
|
|
4385
|
+
a.getState().setSessionMessageHistoryLoading(e, !0);
|
|
4386
|
+
let [u, d] = await Promise.all([o ? n.listSessionMessages(e, {
|
|
4387
|
+
signal: t,
|
|
4388
|
+
beforeSeqId: r.nextCursor ?? void 0,
|
|
4389
|
+
limit: Un,
|
|
4390
|
+
includeReasoning: !0,
|
|
4391
|
+
includeToolEvents: !0,
|
|
4392
|
+
includeAttachments: !0
|
|
4393
|
+
}) : Promise.resolve(null), s && i ? n.listSessionEvents(e, {
|
|
4394
|
+
signal: t,
|
|
4395
|
+
offset: i.loadedCount,
|
|
4396
|
+
limit: Wn
|
|
4397
|
+
}) : Promise.resolve(null)]);
|
|
4398
|
+
if (t?.throwIfAborted(), f.current !== e || g.current !== c || x.current.get(e) !== l) return;
|
|
4399
|
+
let m = u ? Fn(u.Messages) : [], h = new Set(m.map((e) => e.id)), _ = [...m, ...(T.current.get(e) || []).filter((e) => !h.has(e.id))];
|
|
4400
|
+
$(T.current, e, _, f.current);
|
|
4401
|
+
let v = i?.events || [], y = i?.loadedCount || 0, b = i?.total || 0;
|
|
4402
|
+
if (d) {
|
|
4403
|
+
let t = d.Events || [];
|
|
4404
|
+
v = ue(t, v), b = Math.max(b, Number(d.Total ?? 0) || 0), y = t.length > 0 ? Math.min(b, y + t.length) : b, $(D.current, e, {
|
|
4405
|
+
events: v,
|
|
4406
|
+
loadedCount: y,
|
|
4407
|
+
total: b
|
|
4408
|
+
}, f.current);
|
|
4409
|
+
for (let n of t) ft(n, e);
|
|
4247
4410
|
}
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4411
|
+
let S = oe(_, v, e), O = S.messages;
|
|
4412
|
+
$(C.current, e, new Set(S.canonicalRunIds), f.current), E.getState().setMessages(O), $(w.current, e, O, f.current, Gn), a.getState().setSessionMessageHistory(e, {
|
|
4413
|
+
nextCursor: u ? u.NextCursor : r.nextCursor,
|
|
4414
|
+
hasMore: !!(u && u.HasMore || y < b)
|
|
4415
|
+
}), M(p.current, e, m);
|
|
4416
|
+
} catch (e) {
|
|
4417
|
+
if (t) throw e;
|
|
4418
|
+
e instanceof H || console.error("Failed to load older session messages:", e);
|
|
4419
|
+
} finally {
|
|
4420
|
+
x.current.get(e) === l && (x.current.delete(e), a.getState().setSessionMessageHistoryLoading(e, !1));
|
|
4421
|
+
}
|
|
4422
|
+
}, [n, M]);
|
|
4423
|
+
return {
|
|
4424
|
+
historySearchSnapshot: L(() => {
|
|
4425
|
+
let e = f.current || "", t = a.getState().messageHistory[e], n = D.current.get(e);
|
|
4426
|
+
return {
|
|
4427
|
+
owner: JSON.stringify([
|
|
4428
|
+
p.current,
|
|
4429
|
+
e,
|
|
4430
|
+
g.current
|
|
4431
|
+
]),
|
|
4432
|
+
messages: E.getState().messages,
|
|
4433
|
+
hasMore: !!t?.hasMore,
|
|
4434
|
+
loading: !!(_.current === g.current || a.getState().isLoadingSessions || t?.isLoadingInitial || t?.isLoadingOlder),
|
|
4435
|
+
checkpoint: `${t?.nextCursor}:${n?.loadedCount}`,
|
|
4436
|
+
error: y.current?.generation === g.current ? y.current.message : void 0
|
|
4437
|
+
};
|
|
4438
|
+
}, []),
|
|
4439
|
+
followAcceptedInteraction: P,
|
|
4440
|
+
fetchSessions: I,
|
|
4441
|
+
loadMoreSessions: te,
|
|
4442
|
+
loadSession: F,
|
|
4443
|
+
loadOlderSessionMessages: le,
|
|
4444
|
+
createNewSession: ie,
|
|
4445
|
+
startNewConversation: re,
|
|
4446
|
+
adoptCreatedSession: ne,
|
|
4447
|
+
waitForPendingSessionCreation: ae,
|
|
4448
|
+
deleteSession: ce,
|
|
4253
4449
|
currentSessionIdRef: f,
|
|
4254
4450
|
agentIdRef: p,
|
|
4255
4451
|
runSubscriptionAbortRef: m
|
|
4256
4452
|
};
|
|
4257
4453
|
}
|
|
4258
4454
|
//#endregion
|
|
4259
|
-
export {
|
|
4455
|
+
export { Fe as A, Ue as C, Ie as D, U as E, we as M, Te as N, ke as O, Xe as S, Le as T, lt as _, wn as a, Qe as b, Pt as c, kt as d, St as f, ut as g, ht as h, Bn as i, Se as j, Oe as k, Y as l, vt as m, In as n, Zt as o, yt as p, zn as r, Rt as s, Qn as t, jt as u, ct as v, W as w, Ze as x, et as y };
|