@kingsoftcloud/ksadk-web 0.3.12 → 0.3.14
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 +37 -0
- package/README.md +7 -4
- package/RELEASE_PROVENANCE.json +2 -2
- package/dist-ksadk/a2ui/basic-v0_9_1.json +1383 -0
- package/dist-ksadk/a2ui/common-types-v0_9.json +305 -0
- package/dist-ksadk/a2ui/legacy-seven-components.json +230 -0
- package/dist-ksadk/a2ui/manifest.json +86 -0
- package/dist-ksadk/a2ui/material-icons-OFL-1.1.txt +93 -0
- package/dist-ksadk/assets/{ArtifactsPanel-C1YoaKhx.js → ArtifactsPanel-D6LwZ4tH.js} +1 -1
- package/dist-ksadk/assets/{CodeBlock-DHuAWfr5.js → CodeBlock-CVzuVnaN.js} +6 -6
- package/dist-ksadk/assets/{MathMessageMarkdown-cvdrBwYr.js → MathMessageMarkdown-BV0Wpi0w.js} +7 -7
- package/dist-ksadk/assets/{MermaidBlock-DeBkbJvI.js → MermaidBlock-CnBUrMcm.js} +9 -9
- package/dist-ksadk/assets/NativeTerminalPanel-JqWiX3NG.js +1 -0
- package/dist-ksadk/assets/OfficialA2uiRenderer-jre8Zxwn.js +16 -0
- package/dist-ksadk/assets/{abnfDiagram-VCTEODGH-Dhfv25o2.js → abnfDiagram-VCTEODGH-5klLGLXu.js} +1 -1
- package/dist-ksadk/assets/{arc-C35w-pn1.js → arc-BZZ76X9T.js} +1 -1
- package/dist-ksadk/assets/architecture-7GRP2DOG-HtHCKaib.js +1 -0
- package/dist-ksadk/assets/{architectureDiagram-5GKGNRK7-FoMY_u6D.js → architectureDiagram-5GKGNRK7-Z8sis19K.js} +1 -1
- package/dist-ksadk/assets/{blockDiagram-NRAW4CY4-zD4Rt7oE.js → blockDiagram-NRAW4CY4-CbvtJUlp.js} +1 -1
- package/dist-ksadk/assets/{c4Diagram-UCG6FXSJ-BCtGGkhN.js → c4Diagram-UCG6FXSJ-DRDFUFRO.js} +1 -1
- package/dist-ksadk/assets/channel-kuCeovvA.js +1 -0
- package/dist-ksadk/assets/chunk-2Q5K7J3B-DW3fGlBY.js +1 -0
- package/dist-ksadk/assets/{chunk-5VM5RSS4-C2Ms13_k.js → chunk-5VM5RSS4-DgtggYEo.js} +1 -1
- package/dist-ksadk/assets/{chunk-F27PBJKO-BoTj-qgx.js → chunk-F27PBJKO-DBbGWzCA.js} +1 -1
- package/dist-ksadk/assets/{chunk-G27WJ6UU-DOMyyjHH.js → chunk-G27WJ6UU-DN3d7UAB.js} +1 -1
- package/dist-ksadk/assets/{chunk-JWPE2WC7-DbJJqDli.js → chunk-JWPE2WC7-Bx1EEStb.js} +1 -1
- package/dist-ksadk/assets/{chunk-LCL6LL3I-CLuRCt_W.js → chunk-LCL6LL3I-WtVZVwRo.js} +1 -1
- package/dist-ksadk/assets/{chunk-POPQ4Y6H-D0Dz847e.js → chunk-POPQ4Y6H-Bws5AdxJ.js} +1 -1
- package/dist-ksadk/assets/{chunk-RHFEMEQ7-BWSRzEcd.js → chunk-RHFEMEQ7-XkUQsrvs.js} +1 -1
- package/dist-ksadk/assets/{chunk-SVP7TREG-CPoHqkCY.js → chunk-SVP7TREG-Bsl7M9AM.js} +1 -1
- package/dist-ksadk/assets/{chunk-XXDRQBXY-Bx1jS-X-.js → chunk-XXDRQBXY-CgtLH0fF.js} +1 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-2ASNdnzY.js +1 -0
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-2ASNdnzY.js +1 -0
- package/dist-ksadk/assets/{cose-bilkent-JH36ORCC-LzyWm4m0.js → cose-bilkent-JH36ORCC-CeWoENhZ.js} +1 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-1bdXRZZW.js +1 -0
- package/dist-ksadk/assets/{cynefinDiagram-5FMLGOSQ-BlW_bHED.js → cynefinDiagram-5FMLGOSQ-20tItmQc.js} +1 -1
- package/dist-ksadk/assets/{dagre-3AP2YEHR-Bu_S86_i.js → dagre-3AP2YEHR-Dbq7kvPA.js} +1 -1
- package/dist-ksadk/assets/{dagre-B7nCawed.js → dagre-CDn7V_FV.js} +1 -1
- package/dist-ksadk/assets/{diagram-S7CK7UJ4-W_Zow2Km.js → diagram-S7CK7UJ4-BZmC9O9H.js} +1 -1
- package/dist-ksadk/assets/{diagram-UQ7AKVKN-CLIKAHON.js → diagram-UQ7AKVKN-Du6_H3qW.js} +1 -1
- package/dist-ksadk/assets/{diagram-VSXAHHWV-Dv6_QAlN.js → diagram-VSXAHHWV-C-yzAkOw.js} +1 -1
- package/dist-ksadk/assets/{diagram-VX7I27RA-BWAWRDtZ.js → diagram-VX7I27RA-D9uvDFOT.js} +1 -1
- package/dist-ksadk/assets/{diagram-Z3DM3KII-XA_rWMss.js → diagram-Z3DM3KII-CU7oDxrX.js} +1 -1
- package/dist-ksadk/assets/{dist-BO_UwatH.js → dist--hkDI36a.js} +1 -1
- package/dist-ksadk/assets/{dist-BLpRy_Yx.js → dist-A93qMRIG.js} +1 -1
- package/dist-ksadk/assets/{dist-2vL2sAdF.js → dist-BAQdZ6nL.js} +1 -1
- package/dist-ksadk/assets/{dist-0X_j2Rcc.js → dist-BMr3B20m.js} +1 -1
- package/dist-ksadk/assets/{dist-M-SrdhhZ.js → dist-BzJ7YZSp.js} +1 -1
- package/dist-ksadk/assets/{dist-CPyieXEf.js → dist-C27hii8p.js} +1 -1
- package/dist-ksadk/assets/{dist-CIRMvUM4.js → dist-C6_6Bds1.js} +1 -1
- package/dist-ksadk/assets/{dist-D-92S-Fd.js → dist-CCsMtFWS.js} +1 -1
- package/dist-ksadk/assets/{dist-B3bA05-e.js → dist-CJWOBYYA.js} +1 -1
- package/dist-ksadk/assets/{dist-DyG6Ya-z.js → dist-CKdx7EBd.js} +1 -1
- package/dist-ksadk/assets/{dist-t6MzE0jU.js → dist-CYZpFnLj.js} +1 -1
- package/dist-ksadk/assets/{dist-C0J5_3qM.js → dist-CicTOm8l.js} +1 -1
- package/dist-ksadk/assets/{dist-DppE_r-D.js → dist-D5UMz8J2.js} +1 -1
- package/dist-ksadk/assets/{dist-1nXCdsej.js → dist-DGF16E1K.js} +1 -1
- package/dist-ksadk/assets/{dist-mqD5TZup.js → dist-DIDBisGY.js} +1 -1
- package/dist-ksadk/assets/{dist-qe8xjesy.js → dist-DLUtqcff.js} +1 -1
- package/dist-ksadk/assets/{dist-CGt_UGeO.js → dist-DNKlYhx0.js} +1 -1
- package/dist-ksadk/assets/{dist-DNKuMzWc.js → dist-DXQ4VAxh.js} +1 -1
- package/dist-ksadk/assets/{dist-n3n6t_FO.js → dist-DlTRB6vC.js} +1 -1
- package/dist-ksadk/assets/{dist-BdNFAney.js → dist-KZg0gTHo.js} +1 -1
- package/dist-ksadk/assets/{dist-DWfdmz9s.js → dist-di2puApf.js} +1 -1
- package/dist-ksadk/assets/{dist-CIpWk_5f.js → dist-raxPVjNv.js} +1 -1
- package/dist-ksadk/assets/{ebnfDiagram-PWID7BFC-BfCzF1Xi.js → ebnfDiagram-PWID7BFC-DuZG2dXs.js} +1 -1
- package/dist-ksadk/assets/{erDiagram-SSCWMZ5O-Dpz9_0zn.js → erDiagram-SSCWMZ5O-BL8xNTj7.js} +1 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV-CJmDiSBW.js +1 -0
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-CQeF2mVM.js +1 -0
- package/dist-ksadk/assets/{ganttDiagram-EL5Y4UJY-DDaG1f4_.js → ganttDiagram-EL5Y4UJY-CrlgL4uW.js} +1 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-nZDWMnv0.js +1 -0
- package/dist-ksadk/assets/{gitGraphDiagram-WWUBYQGX-DcxzRwYC.js → gitGraphDiagram-WWUBYQGX-rSzorCYl.js} +1 -1
- package/dist-ksadk/assets/index-Bdrdzuun.js +1132 -0
- package/dist-ksadk/assets/index-DMqhW2cV.css +2 -0
- package/dist-ksadk/assets/info-A6RAGUB7-De1Iwui5.js +1 -0
- package/dist-ksadk/assets/{infoDiagram-RXCK75RN-CYMdn6lQ.js → infoDiagram-RXCK75RN-CAt8qVFg.js} +1 -1
- package/dist-ksadk/assets/{ishikawaDiagram-5VMMS53U-CLHFAD6c.js → ishikawaDiagram-5VMMS53U-VhqJKMYj.js} +1 -1
- package/dist-ksadk/assets/{journeyDiagram-EYS64GPL-BHSKQGAl.js → journeyDiagram-EYS64GPL-Bhfu6YF7.js} +1 -1
- package/dist-ksadk/assets/{kanban-definition-3QL26DDD-D5W3tjTT.js → kanban-definition-3QL26DDD-7OI9pMVn.js} +1 -1
- package/dist-ksadk/assets/{katex-mtjOi4KM.js → katex-Dg-M8r12.js} +1 -1
- package/dist-ksadk/assets/{linear-BETqsxE_.js → linear-NMml7t9_.js} +1 -1
- package/dist-ksadk/assets/material-icons-latin-400-normal-kAwBdRge.woff2 +0 -0
- package/dist-ksadk/assets/{mermaid-parser.core-DPWrvs90.js → mermaid-parser.core-BEmZbnyI.js} +2 -2
- package/dist-ksadk/assets/{mindmap-definition-FBJOCRG2-CJG2mfBP.js → mindmap-definition-FBJOCRG2-B0xwWHMG.js} +1 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-D1e-X1k6.js +1 -0
- package/dist-ksadk/assets/{pegDiagram-XKGWAZYB-GjAPNaqn.js → pegDiagram-XKGWAZYB-Cu7QgjWh.js} +1 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-Lxivx4QM.js +1 -0
- package/dist-ksadk/assets/{pieDiagram-E7YTZNPT-ToIewrqr.js → pieDiagram-E7YTZNPT-DkoIrDma.js} +1 -1
- package/dist-ksadk/assets/{quadrantDiagram-AXDQQJYC-4d78KiEY.js → quadrantDiagram-AXDQQJYC-BNlrjzzI.js} +1 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-BQSVqVrb.js +1 -0
- package/dist-ksadk/assets/railroad-74A4TZTK-Cbnh6XZs.js +1 -0
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-2ECgbBti.js +1 -0
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-BfFn9JLY.js +1 -0
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-DyICMM5z.js +1 -0
- package/dist-ksadk/assets/{railroadDiagram-O6MQD6OU-DKzx4xfv.js → railroadDiagram-O6MQD6OU-BK0bi_rd.js} +1 -1
- package/dist-ksadk/assets/{requirementDiagram-EFPCY7ZU-CJYljxQS.js → requirementDiagram-EFPCY7ZU-B7OeRQPt.js} +1 -1
- package/dist-ksadk/assets/{sankeyDiagram-P5KCCOFB-DLU2fV1w.js → sankeyDiagram-P5KCCOFB-dE-_Jk7C.js} +1 -1
- package/dist-ksadk/assets/{sequenceDiagram-WJ2MYXX4-CVqysrA9.js → sequenceDiagram-WJ2MYXX4-y0THlktZ.js} +1 -1
- package/dist-ksadk/assets/{sizeCapture-X5ZJPWSS-BUxfmTHc.js → sizeCapture-X5ZJPWSS-CROa4oek.js} +1 -1
- package/dist-ksadk/assets/{stateDiagram-HBIQ2CUA-CNFgYI9E.js → stateDiagram-HBIQ2CUA-Bz1m4ALw.js} +1 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-D1bq-RBG.js +1 -0
- package/dist-ksadk/assets/{swimlanes-XN3QIQJK-B6qCMe8N.js → swimlanes-XN3QIQJK-CvTFLiud.js} +1 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-BoqEqfqH.js +8 -0
- package/dist-ksadk/assets/{timeline-definition-24CTP7MA-CMD3x_U_.js → timeline-definition-24CTP7MA-1uvXxAPl.js} +1 -1
- package/dist-ksadk/assets/treeView-Q6P3EWNA-BS4HVbiU.js +1 -0
- package/dist-ksadk/assets/treemap-WGGIJYW6-D9_U1F01.js +1 -0
- package/dist-ksadk/assets/{vennDiagram-4TSXK5OY-BqtUqvXM.js → vennDiagram-4TSXK5OY-ruwLjPyJ.js} +1 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-DAiztg_B.js +1 -0
- package/dist-ksadk/assets/{wardleyDiagram-VM6X3IG4-B5KfDjI-.js → wardleyDiagram-VM6X3IG4-DlwZFHFD.js} +1 -1
- package/dist-ksadk/assets/{xychartDiagram-S5SC5T6Z-BaUlSZrn.js → xychartDiagram-S5SC5T6Z-pouF3HpF.js} +1 -1
- package/dist-ksadk/index.html +2 -2
- package/dist-lib/App.d.ts +2 -0
- package/dist-lib/App.d.ts.map +1 -1
- package/dist-lib/AttachmentPreview-C5ruk44B.js +1545 -0
- package/dist-lib/{ConnectedComposer-CeWPgOn2.js → ConnectedComposer-D6eV5hd8.js} +217 -216
- package/dist-lib/ConnectedMessageList-YRps8tha.js +1616 -0
- package/dist-lib/OfficialA2uiRenderer-DI49Kpxu.js +8 -0
- package/dist-lib/{WorkspacePanelContainer-B2mk7udj.js → WorkspacePanelContainer-cAypD1ss.js} +5 -5
- package/dist-lib/a2ui/basic-v0_9_1.json +1383 -0
- package/dist-lib/a2ui/common-types-v0_9.json +305 -0
- package/dist-lib/a2ui/legacy-seven-components.json +230 -0
- package/dist-lib/a2ui/manifest.json +86 -0
- package/dist-lib/a2ui/material-icons-OFL-1.1.txt +93 -0
- package/dist-lib/a2ui-DVGulxKb.js +1547 -0
- package/dist-lib/api/client.d.ts.map +1 -1
- package/dist-lib/api/messages.d.ts +89 -0
- package/dist-lib/api/messages.d.ts.map +1 -0
- package/dist-lib/{capabilities-CXle1R-K.js → capabilities-DAeBY-WO.js} +3 -2
- package/dist-lib/capabilities.js +1 -1
- package/dist-lib/chat-composer.js +2 -2
- package/dist-lib/chat-timeline.js +5 -4
- package/dist-lib/{cloudMaterials-BlIAT-PA.js → cloudMaterials-D75jTrkQ.js} +823 -628
- package/dist-lib/components/chat/A2UIActivityMessage.d.ts +10 -3
- package/dist-lib/components/chat/A2UIActivityMessage.d.ts.map +1 -1
- package/dist-lib/components/chat/AgentBlockView.d.ts +9 -0
- package/dist-lib/components/chat/AgentBlockView.d.ts.map +1 -0
- package/dist-lib/components/chat/ChatComposer.d.ts.map +1 -1
- package/dist-lib/components/chat/ChatMessageList.d.ts +9 -3
- package/dist-lib/components/chat/ChatMessageList.d.ts.map +1 -1
- package/dist-lib/components/chat/ConnectedComposer.d.ts +1 -1
- package/dist-lib/components/chat/ConnectedComposer.d.ts.map +1 -1
- package/dist-lib/components/chat/ConnectedMessageList.d.ts +5 -2
- package/dist-lib/components/chat/ConnectedMessageList.d.ts.map +1 -1
- package/dist-lib/components/chat/InteractionA2uiSurface.d.ts +2 -1
- package/dist-lib/components/chat/InteractionA2uiSurface.d.ts.map +1 -1
- package/dist-lib/components/chat/InteractionHistoryAnchor.d.ts.map +1 -1
- package/dist-lib/components/chat/InteractionSchemaForm.d.ts.map +1 -1
- package/dist-lib/components/chat/InteractionTray.d.ts +2 -1
- package/dist-lib/components/chat/InteractionTray.d.ts.map +1 -1
- package/dist-lib/components/chat/JsonSchemaInputForm.d.ts +16 -0
- package/dist-lib/components/chat/JsonSchemaInputForm.d.ts.map +1 -0
- package/dist-lib/components/chat/LegacyA2UISurface.d.ts +14 -0
- package/dist-lib/components/chat/LegacyA2UISurface.d.ts.map +1 -0
- package/dist-lib/components/chat/OfficialA2uiRenderer.d.ts +3 -0
- package/dist-lib/components/chat/OfficialA2uiRenderer.d.ts.map +1 -0
- package/dist-lib/components/chat/ProcessingBlocksView.d.ts +6 -2
- package/dist-lib/components/chat/ProcessingBlocksView.d.ts.map +1 -1
- package/dist-lib/components/chat/RunProgressIndicator.d.ts +4 -0
- package/dist-lib/components/chat/RunProgressIndicator.d.ts.map +1 -0
- package/dist-lib/components/chat/StatusBanner.d.ts.map +1 -1
- package/dist-lib/components/chat/a2ui-response-snapshot.d.ts +25 -0
- package/dist-lib/components/chat/a2ui-response-snapshot.d.ts.map +1 -0
- package/dist-lib/components/chat/approval-status.d.ts +7 -0
- package/dist-lib/components/chat/approval-status.d.ts.map +1 -0
- package/dist-lib/components/chat/submitted-interaction-history.d.ts +16 -0
- package/dist-lib/components/chat/submitted-interaction-history.d.ts.map +1 -0
- package/dist-lib/components/chat/types.d.ts +30 -1
- package/dist-lib/components/chat/types.d.ts.map +1 -1
- package/dist-lib/components/teams/CloudTeamWorkspace.d.ts.map +1 -1
- package/dist-lib/components/teams/TeamWorkspace.d.ts.map +1 -1
- package/dist-lib/components.js +34 -34
- package/dist-lib/conversation.js +8 -34
- package/dist-lib/core/a2ui/catalog.d.ts +250 -0
- package/dist-lib/core/a2ui/catalog.d.ts.map +1 -0
- package/dist-lib/core/a2ui/history.d.ts +13 -0
- package/dist-lib/core/a2ui/history.d.ts.map +1 -0
- package/dist-lib/core/a2ui/linking.d.ts +7 -0
- package/dist-lib/core/a2ui/linking.d.ts.map +1 -0
- package/dist-lib/core/a2ui/provider.d.ts +8 -0
- package/dist-lib/core/a2ui/provider.d.ts.map +1 -0
- package/dist-lib/core/a2ui/registry.d.ts +45 -0
- package/dist-lib/core/a2ui/registry.d.ts.map +1 -0
- package/dist-lib/core/a2ui/snapshot.d.ts +4 -0
- package/dist-lib/core/a2ui/snapshot.d.ts.map +1 -0
- package/dist-lib/core/a2ui/surfaces.d.ts +23 -0
- package/dist-lib/core/a2ui/surfaces.d.ts.map +1 -0
- package/dist-lib/core/a2ui/transcript.d.ts +14 -0
- package/dist-lib/core/a2ui/transcript.d.ts.map +1 -0
- package/dist-lib/core/api/facade.d.ts +25 -11
- package/dist-lib/core/api/facade.d.ts.map +1 -1
- package/dist-lib/core/api/types.d.ts +35 -4
- package/dist-lib/core/api/types.d.ts.map +1 -1
- package/dist-lib/core/conversation/agent.d.ts +49 -0
- package/dist-lib/core/conversation/agent.d.ts.map +1 -0
- package/dist-lib/core/conversation/client.d.ts +2 -0
- package/dist-lib/core/conversation/client.d.ts.map +1 -1
- package/dist-lib/core/conversation/contracts.d.ts.map +1 -1
- package/dist-lib/core/conversation/hosted.d.ts.map +1 -1
- package/dist-lib/core/conversation/index.d.ts +4 -1
- 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/reducer.d.ts.map +1 -1
- package/dist-lib/core/conversation/renderer-registry.d.ts +1 -0
- package/dist-lib/core/conversation/renderer-registry.d.ts.map +1 -1
- package/dist-lib/core/conversation/runtime-ingress.d.ts +22 -0
- package/dist-lib/core/conversation/runtime-ingress.d.ts.map +1 -0
- package/dist-lib/core/conversation/safe-tool-value.d.ts +8 -0
- package/dist-lib/core/conversation/safe-tool-value.d.ts.map +1 -0
- package/dist-lib/core/conversation/scoped-cancel.d.ts +16 -0
- package/dist-lib/core/conversation/scoped-cancel.d.ts.map +1 -0
- package/dist-lib/core/conversation/types.d.ts +6 -1
- package/dist-lib/core/conversation/types.d.ts.map +1 -1
- package/dist-lib/core/interaction/a2ui-validate.d.ts +6 -3
- package/dist-lib/core/interaction/a2ui-validate.d.ts.map +1 -1
- package/dist-lib/core/interaction/adapters/legacy-runtime-events.d.ts +8 -0
- package/dist-lib/core/interaction/adapters/legacy-runtime-events.d.ts.map +1 -0
- package/dist-lib/core/interaction/adapters/normalize.d.ts +3 -0
- package/dist-lib/core/interaction/adapters/normalize.d.ts.map +1 -1
- package/dist-lib/core/interaction/adapters/responses.d.ts +1 -0
- package/dist-lib/core/interaction/adapters/responses.d.ts.map +1 -1
- package/dist-lib/core/interaction/adapters/session-events.d.ts.map +1 -1
- package/dist-lib/core/interaction/client.d.ts +5 -3
- package/dist-lib/core/interaction/client.d.ts.map +1 -1
- package/dist-lib/core/interaction/index.d.ts +12 -0
- package/dist-lib/core/interaction/index.d.ts.map +1 -1
- package/dist-lib/core/interaction/legacy-history.d.ts +5 -0
- package/dist-lib/core/interaction/legacy-history.d.ts.map +1 -0
- package/dist-lib/core/interaction/response-snapshot.d.ts +13 -0
- package/dist-lib/core/interaction/response-snapshot.d.ts.map +1 -0
- package/dist-lib/core/interaction/schema.d.ts +7 -0
- package/dist-lib/core/interaction/schema.d.ts.map +1 -0
- package/dist-lib/core/interaction/store.d.ts +4 -0
- package/dist-lib/core/interaction/store.d.ts.map +1 -1
- package/dist-lib/core/interaction/types.d.ts +7 -2
- package/dist-lib/core/interaction/types.d.ts.map +1 -1
- package/dist-lib/core/run/a2ui.d.ts +6 -1
- package/dist-lib/core/run/a2ui.d.ts.map +1 -1
- package/dist-lib/core/run/agui.d.ts +14 -0
- package/dist-lib/core/run/agui.d.ts.map +1 -1
- package/dist-lib/core/run/blocks.d.ts +7 -1
- package/dist-lib/core/run/blocks.d.ts.map +1 -1
- package/dist-lib/core/run/dispatcher.d.ts.map +1 -1
- package/dist-lib/core/run/engine.d.ts +2 -0
- package/dist-lib/core/run/engine.d.ts.map +1 -1
- package/dist-lib/core/run/types.d.ts +24 -1
- package/dist-lib/core/run/types.d.ts.map +1 -1
- package/dist-lib/core/stream/kernel-events.d.ts +2 -0
- package/dist-lib/core/stream/kernel-events.d.ts.map +1 -1
- package/dist-lib/core/stream/responses-protocol.d.ts.map +1 -1
- package/dist-lib/core/stream/runtime-items.d.ts +2 -2
- package/dist-lib/core/stream/runtime-items.d.ts.map +1 -1
- package/dist-lib/core/stream/types.d.ts +7 -0
- package/dist-lib/core/stream/types.d.ts.map +1 -1
- package/dist-lib/core/teams/cloudContracts.d.ts +40 -40
- package/dist-lib/core/teams/cloudEffects.d.ts +8 -8
- package/dist-lib/core/teams/cloudExtendedContracts.d.ts +74 -74
- package/dist-lib/core/teams/cloudExtendedContracts.d.ts.map +1 -1
- package/dist-lib/core/teams/cloudMaterials.d.ts +3 -3
- package/dist-lib/core/teams/cloudMaterials.d.ts.map +1 -1
- package/dist-lib/core/teams/contracts.d.ts +12 -12
- package/dist-lib/core/teams/workspaceContracts.d.ts +27 -27
- package/dist-lib/{feedback-CuC5jRi_.js → feedback-DRgW061h.js} +108 -86
- package/dist-lib/hooks/useAgentChat.d.ts +5 -10
- package/dist-lib/hooks/useAgentChat.d.ts.map +1 -1
- package/dist-lib/hooks/useFeedback.d.ts +2 -2
- package/dist-lib/hooks/useFeedback.d.ts.map +1 -1
- package/dist-lib/hooks/useImeComposition.d.ts +21 -0
- package/dist-lib/hooks/useImeComposition.d.ts.map +1 -0
- package/dist-lib/hooks/useInteractions.d.ts +4 -3
- package/dist-lib/hooks/useInteractions.d.ts.map +1 -1
- package/dist-lib/hooks/useRunAgent.d.ts +6 -2
- package/dist-lib/hooks/useRunAgent.d.ts.map +1 -1
- package/dist-lib/hooks/useSessionLifecycle.d.ts +1 -1
- package/dist-lib/hooks/useSessionLifecycle.d.ts.map +1 -1
- package/dist-lib/hooks.js +27 -25
- package/dist-lib/{runtime-items-q6tMjfGU.js → json-value-DnHp0582.js} +0 -0
- package/dist-lib/{permission-CcMWqN8Y.js → permission-BT1f0PIC.js} +1 -1
- package/dist-lib/persisted-session-history-KtoKbLRA.js +3143 -0
- package/dist-lib/public/chat-timeline.d.ts +5 -0
- package/dist-lib/public/chat-timeline.d.ts.map +1 -1
- 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 +3 -1
- package/dist-lib/public/conversation.d.ts.map +1 -1
- package/dist-lib/public/runtime.d.ts +3 -0
- package/dist-lib/public/runtime.d.ts.map +1 -1
- package/dist-lib/public/types.d.ts +1 -0
- package/dist-lib/public/types.d.ts.map +1 -1
- package/dist-lib/{reducer-BP8YVv-Q.js → reducer-mbYiX0wz.js} +81 -13
- package/dist-lib/runtime.js +320 -254
- package/dist-lib/schema-fields-CUpDl1NB.js +41 -0
- package/dist-lib/stores/session.d.ts +20 -11
- package/dist-lib/stores/session.d.ts.map +1 -1
- package/dist-lib/styles.css +1 -1
- package/dist-lib/team-components.js +580 -448
- package/dist-lib/teams.js +363 -555
- package/dist-lib/types/agent-control.d.ts +2 -0
- package/dist-lib/types/agent-control.d.ts.map +1 -1
- package/dist-lib/types/api.d.ts +2 -0
- package/dist-lib/types/api.d.ts.map +1 -1
- package/dist-lib/types/capabilities.d.ts +8 -0
- package/dist-lib/types/capabilities.d.ts.map +1 -1
- package/dist-lib/types/json-value.d.ts +6 -0
- package/dist-lib/types/json-value.d.ts.map +1 -0
- package/dist-lib/types/session-events.d.ts +1 -0
- package/dist-lib/types/session-events.d.ts.map +1 -1
- package/dist-lib/useSessionLifecycle-CUf3hB30.js +5200 -0
- package/dist-lib/utils/capabilities.d.ts.map +1 -1
- package/dist-lib/utils/history-preparation.d.ts +8 -0
- package/dist-lib/utils/history-preparation.d.ts.map +1 -0
- package/dist-lib/utils/history-tool-facts.d.ts +8 -0
- package/dist-lib/utils/history-tool-facts.d.ts.map +1 -0
- package/dist-lib/utils/interaction-history.d.ts +11 -0
- package/dist-lib/utils/interaction-history.d.ts.map +1 -0
- package/dist-lib/utils/kernel-run-history.d.ts +9 -0
- package/dist-lib/utils/kernel-run-history.d.ts.map +1 -0
- package/dist-lib/utils/messages.d.ts +9 -5
- package/dist-lib/utils/messages.d.ts.map +1 -1
- package/dist-lib/utils/persisted-session-history.d.ts +1 -1
- package/dist-lib/utils/persisted-session-history.d.ts.map +1 -1
- package/dist-lib/utils/recovered-run.d.ts.map +1 -1
- package/dist-lib/utils/responses-stream.d.ts.map +1 -1
- package/dist-lib/utils/run-progress.d.ts +11 -0
- package/dist-lib/utils/run-progress.d.ts.map +1 -0
- package/dist-lib/utils/session-events.d.ts.map +1 -1
- package/dist-lib/utils/transcript-order.d.ts +10 -0
- package/dist-lib/utils/transcript-order.d.ts.map +1 -0
- package/dist-lib/utils/workspace.d.ts +1 -1
- package/package.json +15 -5
- package/dist-ksadk/assets/NativeTerminalPanel-oJj44_sV.js +0 -1
- package/dist-ksadk/assets/architecture-7GRP2DOG-BCsa26zi.js +0 -1
- package/dist-ksadk/assets/channel-_KDifNys.js +0 -1
- package/dist-ksadk/assets/chunk-2Q5K7J3B-HdVkJ9F0.js +0 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-BVCW3ZqZ.js +0 -1
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-BVCW3ZqZ.js +0 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-CNXjFctL.js +0 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV-B5-8RH9c.js +0 -1
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-BppFxEKw.js +0 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-B-AhYj4C.js +0 -1
- package/dist-ksadk/assets/index-BMd2mucF.css +0 -2
- package/dist-ksadk/assets/index-D5qyyhTH.js +0 -244
- package/dist-ksadk/assets/info-A6RAGUB7-0uiKrC35.js +0 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-BVTmZ_cw.js +0 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-DyfxBU7V.js +0 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-FFontjL2.js +0 -1
- package/dist-ksadk/assets/railroad-74A4TZTK-D0Uidzen.js +0 -1
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-BOo_9T2h.js +0 -1
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-D6-BjW7Z.js +0 -1
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-CXx__yMm.js +0 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-BXAFScz8.js +0 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-uIQ2lJKH.js +0 -8
- package/dist-ksadk/assets/treeView-Q6P3EWNA-CK5GgucZ.js +0 -1
- package/dist-ksadk/assets/treemap-WGGIJYW6-Bq1u1SpG.js +0 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-QAt06uEz.js +0 -1
- package/dist-lib/AttachmentPreview-HLpbjOnQ.js +0 -535
- package/dist-lib/ConnectedMessageList-D3HWHCh2.js +0 -1361
- package/dist-lib/InteractionSchemaForm-Du9NT4E8.js +0 -157
- package/dist-lib/a2ui-BEQoW34n.js +0 -502
- package/dist-lib/persisted-session-history-ClsfDfGs.js +0 -1991
- package/dist-lib/useSessionLifecycle-DQXKeBm9.js +0 -4455
|
@@ -1,4455 +0,0 @@
|
|
|
1
|
-
import { a as e, i as t, o as n, t as r } from "./capabilities-CXle1R-K.js";
|
|
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
|
-
import { n as D } from "./tool-display-DTiRdghE.js";
|
|
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";
|
|
12
|
-
//#region src/api/client.ts
|
|
13
|
-
var V = class extends Error {
|
|
14
|
-
code;
|
|
15
|
-
detail;
|
|
16
|
-
constructor(e, t, n) {
|
|
17
|
-
super(t), this.name = "ApiError", this.code = e, this.detail = n;
|
|
18
|
-
}
|
|
19
|
-
}, H = class extends Error {
|
|
20
|
-
constructor(e = "请求已取消") {
|
|
21
|
-
super(e), this.name = "CancelledError";
|
|
22
|
-
}
|
|
23
|
-
}, ye = "/agentengine/api/v1";
|
|
24
|
-
async function be(e) {
|
|
25
|
-
let t = await e.text(), n = {};
|
|
26
|
-
try {
|
|
27
|
-
n = t ? JSON.parse(t) : {};
|
|
28
|
-
} catch {
|
|
29
|
-
let n = e.headers.get("content-type")?.toLowerCase() || "";
|
|
30
|
-
if ((e.status === 401 || e.status === 403) && (n.includes("text/html") || t.trimStart().startsWith("<"))) throw new V(e.status, "访问会话已失效,请从 Dashboard 或 Studio 的云端会话重新打开 Agent。");
|
|
31
|
-
if (!e.ok) {
|
|
32
|
-
let n = t.trim();
|
|
33
|
-
throw new V(e.status, n && n.length <= 256 && !n.startsWith("<") ? n : e.statusText || `HTTP ${e.status}`, t);
|
|
34
|
-
}
|
|
35
|
-
throw new V(-2, "响应格式异常");
|
|
36
|
-
}
|
|
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);
|
|
39
|
-
return n.Data;
|
|
40
|
-
}
|
|
41
|
-
function xe(e) {
|
|
42
|
-
throw e instanceof DOMException && e.name === "AbortError" ? new H() : e;
|
|
43
|
-
}
|
|
44
|
-
var Se = class {
|
|
45
|
-
fetcher;
|
|
46
|
-
baseUrl;
|
|
47
|
-
agentId;
|
|
48
|
-
constructor(e = {}) {
|
|
49
|
-
this.fetcher = e.fetch || ((e, t) => globalThis.fetch(e, t)), this.baseUrl = String(e.baseUrl || ye).replace(/\/+$/, ""), this.agentId = String(e.agentId || "").trim();
|
|
50
|
-
}
|
|
51
|
-
actionUrl(e) {
|
|
52
|
-
return `${this.baseUrl}/${e}`;
|
|
53
|
-
}
|
|
54
|
-
scopedBody(e) {
|
|
55
|
-
return this.agentId && !e.AgentId ? {
|
|
56
|
-
...e,
|
|
57
|
-
AgentId: this.agentId
|
|
58
|
-
} : e;
|
|
59
|
-
}
|
|
60
|
-
async postJsonAction(e, t, n) {
|
|
61
|
-
let r;
|
|
62
|
-
try {
|
|
63
|
-
r = await this.fetcher(this.actionUrl(e), {
|
|
64
|
-
method: "POST",
|
|
65
|
-
headers: { "Content-Type": "application/json" },
|
|
66
|
-
body: JSON.stringify(this.scopedBody(t)),
|
|
67
|
-
signal: n?.signal
|
|
68
|
-
});
|
|
69
|
-
} catch (e) {
|
|
70
|
-
throw xe(e);
|
|
71
|
-
}
|
|
72
|
-
return be(r);
|
|
73
|
-
}
|
|
74
|
-
async postFormAction(e, t, n) {
|
|
75
|
-
let r;
|
|
76
|
-
this.agentId && !t.has("AgentId") && t.append("AgentId", this.agentId);
|
|
77
|
-
try {
|
|
78
|
-
r = await this.fetcher(this.actionUrl(e), {
|
|
79
|
-
method: "POST",
|
|
80
|
-
body: t,
|
|
81
|
-
signal: n?.signal
|
|
82
|
-
});
|
|
83
|
-
} catch (e) {
|
|
84
|
-
throw xe(e);
|
|
85
|
-
}
|
|
86
|
-
return be(r);
|
|
87
|
-
}
|
|
88
|
-
async getResource(e, t, n) {
|
|
89
|
-
let r = this.agentId && !t.AgentId ? {
|
|
90
|
-
AgentId: this.agentId,
|
|
91
|
-
...t
|
|
92
|
-
} : t, i = new URLSearchParams(r).toString(), a = i ? `${this.actionUrl(e)}?${i}` : this.actionUrl(e), o;
|
|
93
|
-
try {
|
|
94
|
-
o = await this.fetcher(a, { signal: n?.signal });
|
|
95
|
-
} catch (e) {
|
|
96
|
-
throw xe(e);
|
|
97
|
-
}
|
|
98
|
-
if (!o.ok) throw new V(o.status, `资源获取失败: ${o.statusText}`);
|
|
99
|
-
try {
|
|
100
|
-
return n?.asText ? await o.text() : await o.blob();
|
|
101
|
-
} catch {
|
|
102
|
-
throw new V(-3, "文件读取失败");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
async streamAction(e, t, n) {
|
|
106
|
-
let r;
|
|
107
|
-
try {
|
|
108
|
-
r = await this.fetcher(this.actionUrl(e), {
|
|
109
|
-
method: "POST",
|
|
110
|
-
headers: {
|
|
111
|
-
"Content-Type": "application/json",
|
|
112
|
-
Accept: "text/event-stream"
|
|
113
|
-
},
|
|
114
|
-
body: JSON.stringify(this.scopedBody(t)),
|
|
115
|
-
signal: n?.signal
|
|
116
|
-
});
|
|
117
|
-
} catch (e) {
|
|
118
|
-
throw xe(e);
|
|
119
|
-
}
|
|
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, "无法获取响应流");
|
|
122
|
-
return r.body;
|
|
123
|
-
}
|
|
124
|
-
async streamGetAction(e, t, n) {
|
|
125
|
-
let r = this.agentId && !t.AgentId ? {
|
|
126
|
-
AgentId: this.agentId,
|
|
127
|
-
...t
|
|
128
|
-
} : t, i = new URLSearchParams(r).toString(), a = i ? `${this.actionUrl(e)}?${i}` : this.actionUrl(e), o;
|
|
129
|
-
try {
|
|
130
|
-
o = await this.fetcher(a, {
|
|
131
|
-
headers: { Accept: "text/event-stream" },
|
|
132
|
-
signal: n?.signal
|
|
133
|
-
});
|
|
134
|
-
} catch (e) {
|
|
135
|
-
throw xe(e);
|
|
136
|
-
}
|
|
137
|
-
if (!o.ok) throw new V(o.status, `流式订阅失败: ${o.statusText}`);
|
|
138
|
-
if (!o.body) throw new V(-1, "无法获取响应流");
|
|
139
|
-
return o.body;
|
|
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 {
|
|
142
|
-
constructor(e) {
|
|
143
|
-
super(e), this.name = "ContractMismatchError";
|
|
144
|
-
}
|
|
145
|
-
}, Ee = new Set([
|
|
146
|
-
"schema_version",
|
|
147
|
-
"command_id",
|
|
148
|
-
"status",
|
|
149
|
-
"message_id",
|
|
150
|
-
"run_id",
|
|
151
|
-
"accepted_seq",
|
|
152
|
-
"error"
|
|
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()
|
|
158
|
-
});
|
|
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([
|
|
164
|
-
"accepted",
|
|
165
|
-
"duplicate",
|
|
166
|
-
"rejected",
|
|
167
|
-
"unsupported",
|
|
168
|
-
"queue_full",
|
|
169
|
-
"persistence_uncertain"
|
|
170
|
-
]),
|
|
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()
|
|
175
|
-
}).passthrough().safeParse(e);
|
|
176
|
-
if (!t.success) throw new U(`AgentControlReceipt/v1 mismatch: ${t.error.message}`);
|
|
177
|
-
let n = t.data;
|
|
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`);
|
|
179
|
-
let r = {};
|
|
180
|
-
for (let [e, t] of Object.entries(n)) Ee.has(e) || (r[e] = t);
|
|
181
|
-
let i = n.error ? {
|
|
182
|
-
...n.error,
|
|
183
|
-
extensions: {}
|
|
184
|
-
} : null;
|
|
185
|
-
return {
|
|
186
|
-
schema_version: 1,
|
|
187
|
-
command_id: n.command_id,
|
|
188
|
-
status: n.status,
|
|
189
|
-
message_id: n.message_id ?? null,
|
|
190
|
-
run_id: n.run_id ?? null,
|
|
191
|
-
accepted_seq: n.accepted_seq ?? null,
|
|
192
|
-
error: i,
|
|
193
|
-
extensions: r
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
function ke(e) {
|
|
197
|
-
try {
|
|
198
|
-
return n(e);
|
|
199
|
-
} catch (e) {
|
|
200
|
-
throw new U(`RuntimeCapabilityMatrix/v1 mismatch: ${e instanceof Error ? e.message : String(e)}`);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
var Ae = new Set([
|
|
204
|
-
"schema_version",
|
|
205
|
-
"event_id",
|
|
206
|
-
"session_id",
|
|
207
|
-
"seq",
|
|
208
|
-
"timestamp",
|
|
209
|
-
"family",
|
|
210
|
-
"family_version",
|
|
211
|
-
"event_type",
|
|
212
|
-
"payload",
|
|
213
|
-
"run_id",
|
|
214
|
-
"causation_id",
|
|
215
|
-
"correlation_id",
|
|
216
|
-
"actor_ref"
|
|
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
|
-
};
|
|
236
|
-
function Ne(e) {
|
|
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));
|
|
265
|
-
if (!t.success) return {
|
|
266
|
-
ok: !1,
|
|
267
|
-
error: new U(`SessionEventEnvelope/v1 mismatch: ${t.error.message}`)
|
|
268
|
-
};
|
|
269
|
-
let n = t.data, r = je.get(n.family);
|
|
270
|
-
if (r !== void 0 && n.family_version !== r) return {
|
|
271
|
-
ok: !1,
|
|
272
|
-
error: new U(`SessionEventEnvelope/v1 mismatch: family ${n.family} requires family_version ${r}`)
|
|
273
|
-
};
|
|
274
|
-
let i = {};
|
|
275
|
-
for (let [e, t] of Object.entries(n)) Ae.has(e) || (i[e] = t);
|
|
276
|
-
return {
|
|
277
|
-
ok: !0,
|
|
278
|
-
value: {
|
|
279
|
-
schema_version: 1,
|
|
280
|
-
event_id: n.event_id,
|
|
281
|
-
session_id: n.session_id,
|
|
282
|
-
seq: n.seq,
|
|
283
|
-
timestamp: n.timestamp,
|
|
284
|
-
family: n.family,
|
|
285
|
-
family_version: n.family_version,
|
|
286
|
-
event_type: n.event_type,
|
|
287
|
-
payload: n.payload,
|
|
288
|
-
run_id: n.run_id ?? null,
|
|
289
|
-
causation_id: n.causation_id ?? null,
|
|
290
|
-
correlation_id: n.correlation_id ?? null,
|
|
291
|
-
actor_ref: n.actor_ref ?? null,
|
|
292
|
-
extensions: i
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
}
|
|
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([
|
|
301
|
-
"ready",
|
|
302
|
-
"degraded",
|
|
303
|
-
"unavailable"
|
|
304
|
-
]),
|
|
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([
|
|
308
|
-
"pending",
|
|
309
|
-
"running",
|
|
310
|
-
"paused",
|
|
311
|
-
"waiting"
|
|
312
|
-
]).nullable().optional(),
|
|
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()
|
|
317
|
-
}).passthrough().safeParse(e);
|
|
318
|
-
if (!t.success) throw new U(`AgentStatusSnapshot/v1 mismatch: ${t.error.message}`);
|
|
319
|
-
let n = t.data, r = {};
|
|
320
|
-
for (let e of Object.keys(n)) [
|
|
321
|
-
"schema_version",
|
|
322
|
-
"agent_instance_id",
|
|
323
|
-
"instance_state",
|
|
324
|
-
"session_id",
|
|
325
|
-
"active_run_id",
|
|
326
|
-
"active_run_state",
|
|
327
|
-
"inbox_depth",
|
|
328
|
-
"activation_id",
|
|
329
|
-
"lease_expires_at",
|
|
330
|
-
"capability"
|
|
331
|
-
].includes(e) || (r[e] = n[e]);
|
|
332
|
-
return {
|
|
333
|
-
schema_version: 1,
|
|
334
|
-
agent_instance_id: n.agent_instance_id,
|
|
335
|
-
instance_state: n.instance_state,
|
|
336
|
-
session_id: n.session_id ?? null,
|
|
337
|
-
active_run_id: n.active_run_id ?? null,
|
|
338
|
-
active_run_state: n.active_run_state ?? null,
|
|
339
|
-
inbox_depth: n.inbox_depth,
|
|
340
|
-
activation_id: n.activation_id ?? null,
|
|
341
|
-
lease_expires_at: n.lease_expires_at ?? null,
|
|
342
|
-
capability: ke(n.capability),
|
|
343
|
-
extensions: r
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
//#endregion
|
|
347
|
-
//#region src/core/api/facade.ts
|
|
348
|
-
var Le = class {
|
|
349
|
-
client;
|
|
350
|
-
constructor(e = {}) {
|
|
351
|
-
this.client = new Se(e);
|
|
352
|
-
}
|
|
353
|
-
async compactSession(e, t) {
|
|
354
|
-
return this.client.postJsonAction("CompactSession", {
|
|
355
|
-
AgentId: e,
|
|
356
|
-
SessionId: t
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
async listSessions(e, t) {
|
|
360
|
-
let n = await this.client.postJsonAction("ListSessions", {
|
|
361
|
-
AgentId: e,
|
|
362
|
-
Page: t?.page,
|
|
363
|
-
PageSize: t?.pageSize
|
|
364
|
-
}, t), r = n.Sessions ?? [];
|
|
365
|
-
return {
|
|
366
|
-
Sessions: r,
|
|
367
|
-
Total: Number.isFinite(Number(n.Total)) ? Number(n.Total) : r.length,
|
|
368
|
-
Page: Number.isFinite(Number(n.Page)) ? Number(n.Page) : t?.page ?? 1,
|
|
369
|
-
PageSize: Number.isFinite(Number(n.PageSize)) ? Number(n.PageSize) : t?.pageSize ?? r.length
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
async createSession(e, t) {
|
|
373
|
-
let n = await this.client.postJsonAction("CreateSession", { AgentId: e }, t);
|
|
374
|
-
return { SessionId: String(n.Session?.SessionId || "") };
|
|
375
|
-
}
|
|
376
|
-
async deleteSession(e, t) {
|
|
377
|
-
return this.client.postJsonAction("DeleteSession", { SessionId: e }, t);
|
|
378
|
-
}
|
|
379
|
-
async getSession(e, t) {
|
|
380
|
-
return (await this.client.postJsonAction("GetSession", { SessionId: e }, t)).Session;
|
|
381
|
-
}
|
|
382
|
-
async listSessionEvents(e, t) {
|
|
383
|
-
let n = await this.client.postJsonAction("ListSessionEvents", {
|
|
384
|
-
SessionId: e,
|
|
385
|
-
Offset: t?.offset,
|
|
386
|
-
Limit: t?.limit
|
|
387
|
-
}, t), r = n.Events ?? [];
|
|
388
|
-
return {
|
|
389
|
-
Events: r,
|
|
390
|
-
Total: Number.isFinite(Number(n.Total)) ? Number(n.Total) : r.length,
|
|
391
|
-
Offset: Number.isFinite(Number(n.Offset)) ? Number(n.Offset) : t?.offset ?? 0,
|
|
392
|
-
Limit: Number.isFinite(Number(n.Limit)) ? Number(n.Limit) : t?.limit ?? r.length
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
async listSessionMessages(e, t) {
|
|
396
|
-
let n = await this.client.postJsonAction("ListSessionMessages", {
|
|
397
|
-
AgentId: t?.agentId,
|
|
398
|
-
SessionId: e,
|
|
399
|
-
AfterSeqId: t?.afterSeqId,
|
|
400
|
-
BeforeSeqId: t?.beforeSeqId,
|
|
401
|
-
Limit: t?.limit,
|
|
402
|
-
IncludeReasoning: t?.includeReasoning,
|
|
403
|
-
IncludeToolEvents: t?.includeToolEvents,
|
|
404
|
-
IncludeAttachments: t?.includeAttachments
|
|
405
|
-
}, t);
|
|
406
|
-
return {
|
|
407
|
-
Messages: n.Messages ?? [],
|
|
408
|
-
LatestSeqId: Number.isFinite(Number(n.LatestSeqId)) ? Number(n.LatestSeqId) : 0,
|
|
409
|
-
HasMore: !!n.HasMore,
|
|
410
|
-
NextCursor: n.NextCursor === null || n.NextCursor === void 0 ? null : Number.isFinite(Number(n.NextCursor)) ? Number(n.NextCursor) : null
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
async listSessionCheckpoints(e, t) {
|
|
414
|
-
return this.client.postJsonAction("ListSessionCheckpoints", {
|
|
415
|
-
AgentId: e.agentId,
|
|
416
|
-
SessionId: e.sessionId,
|
|
417
|
-
...e.runId ? { RunId: e.runId } : {}
|
|
418
|
-
}, t);
|
|
419
|
-
}
|
|
420
|
-
async previewCheckpointResume(e, t) {
|
|
421
|
-
return this.client.postJsonAction("GetCheckpointResumePreview", {
|
|
422
|
-
AgentId: e.agentId,
|
|
423
|
-
SessionId: e.sessionId,
|
|
424
|
-
RunId: e.runId,
|
|
425
|
-
CheckpointId: e.checkpointId
|
|
426
|
-
}, t);
|
|
427
|
-
}
|
|
428
|
-
async listToolReceipts(e, t) {
|
|
429
|
-
return this.client.postJsonAction("ListToolReceipts", {
|
|
430
|
-
AgentId: e.agentId,
|
|
431
|
-
SessionId: e.sessionId,
|
|
432
|
-
...e.runId ? { RunId: e.runId } : {},
|
|
433
|
-
...e.checkpointId ? { CheckpointId: e.checkpointId } : {}
|
|
434
|
-
}, t);
|
|
435
|
-
}
|
|
436
|
-
async runAgent(e, t) {
|
|
437
|
-
return this.client.streamAction("RunAgent", e, t);
|
|
438
|
-
}
|
|
439
|
-
async resumeRun(e, t) {
|
|
440
|
-
return this.client.streamAction("ResumeRun", {
|
|
441
|
-
AgentId: e.agentId,
|
|
442
|
-
SessionId: e.sessionId,
|
|
443
|
-
RunId: e.runId,
|
|
444
|
-
CheckpointId: e.checkpointId,
|
|
445
|
-
Stream: !0,
|
|
446
|
-
...e.resumeAttemptId ? { ResumeAttemptId: e.resumeAttemptId } : {},
|
|
447
|
-
...e.invocationId ? { InvocationId: e.invocationId } : {}
|
|
448
|
-
}, t);
|
|
449
|
-
}
|
|
450
|
-
async subscribeRunEvents(e, t) {
|
|
451
|
-
return this.client.streamGetAction("SubscribeRunEvents", {
|
|
452
|
-
SessionId: e.sessionId,
|
|
453
|
-
InvocationId: e.invocationId,
|
|
454
|
-
AfterSeqId: String(e.afterSeqId)
|
|
455
|
-
}, t);
|
|
456
|
-
}
|
|
457
|
-
async submitControl(e, t) {
|
|
458
|
-
return Oe(await this.client.postJsonAction("SubmitAgentControl", {
|
|
459
|
-
CommandType: e.command_type,
|
|
460
|
-
IdempotencyKey: e.idempotency_key,
|
|
461
|
-
Payload: e.payload
|
|
462
|
-
}, t));
|
|
463
|
-
}
|
|
464
|
-
async submitInteraction(e, t) {
|
|
465
|
-
return Oe(await this.client.postJsonAction("SubmitInteraction", { ...e }, t));
|
|
466
|
-
}
|
|
467
|
-
async getAgentStatus(e) {
|
|
468
|
-
return this.client.postJsonAction("GetAgentStatus", {}, e);
|
|
469
|
-
}
|
|
470
|
-
async subscribeSessionEvents(e, t, n) {
|
|
471
|
-
return this.client.streamGetAction("SubscribeSessionEvents", {
|
|
472
|
-
SessionId: e,
|
|
473
|
-
after_seq: String(t)
|
|
474
|
-
}, n);
|
|
475
|
-
}
|
|
476
|
-
async cancelRun(e, t, n, r) {
|
|
477
|
-
return this.client.postJsonAction("CancelRun", {
|
|
478
|
-
AgentId: e,
|
|
479
|
-
SessionId: t,
|
|
480
|
-
InvocationId: n
|
|
481
|
-
}, r);
|
|
482
|
-
}
|
|
483
|
-
async getResponseFeedback(e, t) {
|
|
484
|
-
return this.client.postJsonAction("GetResponseFeedback", e, t);
|
|
485
|
-
}
|
|
486
|
-
async upsertResponseFeedback(e, t) {
|
|
487
|
-
return this.client.postJsonAction("UpsertResponseFeedback", e, t);
|
|
488
|
-
}
|
|
489
|
-
async deleteResponseFeedback(e, t) {
|
|
490
|
-
await this.client.postJsonAction("DeleteResponseFeedback", e, t);
|
|
491
|
-
}
|
|
492
|
-
async listWorkspaceFiles(e, t, n, r) {
|
|
493
|
-
return this.client.postJsonAction("ListWorkspaceFiles", {
|
|
494
|
-
AgentId: e,
|
|
495
|
-
Path: t,
|
|
496
|
-
Recursive: n
|
|
497
|
-
}, r);
|
|
498
|
-
}
|
|
499
|
-
async addWorkspaceFile(e, t) {
|
|
500
|
-
return this.client.postFormAction("AddWorkspaceFile", e, t);
|
|
501
|
-
}
|
|
502
|
-
async deleteWorkspaceFile(e, t, n) {
|
|
503
|
-
await this.client.postJsonAction("DeleteWorkspaceFile", {
|
|
504
|
-
AgentId: e,
|
|
505
|
-
Path: t
|
|
506
|
-
}, n);
|
|
507
|
-
}
|
|
508
|
-
async getWorkspaceFileContent(e, t, n) {
|
|
509
|
-
return this.client.getResource("GetWorkspaceFileContent", {
|
|
510
|
-
AgentId: e,
|
|
511
|
-
FilePath: t
|
|
512
|
-
}, n);
|
|
513
|
-
}
|
|
514
|
-
async listAgentModels(e, t) {
|
|
515
|
-
return this.client.postJsonAction("ListAgentModels", { AgentId: e }, t);
|
|
516
|
-
}
|
|
517
|
-
async getAgentUiBootstrap(e, t) {
|
|
518
|
-
return this.client.postJsonAction("GetAgentUiBootstrap", e ? { AgentId: e } : {}, t);
|
|
519
|
-
}
|
|
520
|
-
async uploadFile(e, t) {
|
|
521
|
-
return this.client.postFormAction("UploadFile", e, t);
|
|
522
|
-
}
|
|
523
|
-
}, W = ge()((e) => ({
|
|
524
|
-
agentId: "default-agent",
|
|
525
|
-
agentName: "Agent",
|
|
526
|
-
agentFramework: "",
|
|
527
|
-
capabilities: t({}),
|
|
528
|
-
apiFormats: ["responses", "chat_completions"],
|
|
529
|
-
accessMode: "Owner",
|
|
530
|
-
workspaceFiles: null,
|
|
531
|
-
status: "loading",
|
|
532
|
-
errorMessage: "",
|
|
533
|
-
setAgentId: (t) => e({ agentId: t }),
|
|
534
|
-
setAgentName: (t) => e({ agentName: t }),
|
|
535
|
-
setAgentFramework: (t) => e({ agentFramework: t }),
|
|
536
|
-
setCapabilities: (t) => e({ capabilities: t }),
|
|
537
|
-
setApiFormats: (t) => e({ apiFormats: t }),
|
|
538
|
-
setAccessMode: (t) => e({ accessMode: t }),
|
|
539
|
-
setWorkspaceFiles: (t) => e({ workspaceFiles: t }),
|
|
540
|
-
setStatus: (t, n = "") => e({
|
|
541
|
-
status: t,
|
|
542
|
-
errorMessage: n
|
|
543
|
-
})
|
|
544
|
-
})), Re = "ksadk:webui:selected-session:";
|
|
545
|
-
function ze(e) {
|
|
546
|
-
return String(e || "").trim() || "default-agent";
|
|
547
|
-
}
|
|
548
|
-
function Be(e) {
|
|
549
|
-
if (e && typeof e.getItem == "function") return e;
|
|
550
|
-
try {
|
|
551
|
-
if (typeof window < "u" && window.localStorage) return window.localStorage;
|
|
552
|
-
} catch {}
|
|
553
|
-
return null;
|
|
554
|
-
}
|
|
555
|
-
function Ve(e) {
|
|
556
|
-
return p.key(`${Re}${ze(e)}`);
|
|
557
|
-
}
|
|
558
|
-
function He(e, t) {
|
|
559
|
-
let n = Be(t);
|
|
560
|
-
if (!n) return null;
|
|
561
|
-
try {
|
|
562
|
-
return String(n.getItem(Ve(e)) || "").trim() || null;
|
|
563
|
-
} catch {
|
|
564
|
-
return null;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
function Ue(e, t, n) {
|
|
568
|
-
if (!p.writable) return;
|
|
569
|
-
let r = Be(n);
|
|
570
|
-
if (!r) return;
|
|
571
|
-
let i = Ve(e), a = String(t || "").trim();
|
|
572
|
-
try {
|
|
573
|
-
if (a) {
|
|
574
|
-
r.setItem(i, a);
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
r.removeItem(i);
|
|
578
|
-
} catch {}
|
|
579
|
-
}
|
|
580
|
-
function We(e, t) {
|
|
581
|
-
if (!Array.isArray(e) || e.length === 0) return null;
|
|
582
|
-
let n = String(t || "").trim();
|
|
583
|
-
if (n && e.some((e) => String(e?.SessionId || "").trim() === n)) return n;
|
|
584
|
-
for (let t of e) {
|
|
585
|
-
let e = String(t?.SessionId || "").trim();
|
|
586
|
-
if (e) return e;
|
|
587
|
-
}
|
|
588
|
-
return null;
|
|
589
|
-
}
|
|
590
|
-
function Ge(e, t, n) {
|
|
591
|
-
let r = Array.isArray(e) ? e : [], i = Array.isArray(t) ? t : [], a = n instanceof Set ? n : new Set(Array.isArray(n) ? n : []);
|
|
592
|
-
if (a.size === 0) return r;
|
|
593
|
-
let o = new Set(r.map((e) => String(e?.SessionId || "").trim()).filter(Boolean)), s = i.filter((e) => {
|
|
594
|
-
let t = String(e?.SessionId || "").trim();
|
|
595
|
-
return t && a.has(t) && !o.has(t);
|
|
596
|
-
});
|
|
597
|
-
return s.length > 0 ? [...r, ...s] : r;
|
|
598
|
-
}
|
|
599
|
-
//#endregion
|
|
600
|
-
//#region src/hooks/useBootstrap.ts
|
|
601
|
-
function Ke(e) {
|
|
602
|
-
return e instanceof V && (e.code === 401 || e.code === 403) ? "auth-required" : "error";
|
|
603
|
-
}
|
|
604
|
-
function qe(e) {
|
|
605
|
-
if (!Array.isArray(e)) return ["responses", "chat_completions"];
|
|
606
|
-
let t = e.filter((e) => e === "responses" || e === "chat_completions");
|
|
607
|
-
return t.length > 0 ? t : ["responses", "chat_completions"];
|
|
608
|
-
}
|
|
609
|
-
var Je = new Le();
|
|
610
|
-
async function Ye(e, t = Je) {
|
|
611
|
-
try {
|
|
612
|
-
let n = await t.listAgentModels(e), r = n?.Models;
|
|
613
|
-
Array.isArray(r) && u.getState().upsertModels(r);
|
|
614
|
-
let i = n;
|
|
615
|
-
i?.Current && !u.getState().selectedModel && u.getState().setSelectedModel(String(i.Current)), i?.Source && u.getState().setModelSource(String(i.Source));
|
|
616
|
-
} catch (e) {
|
|
617
|
-
console.error("Failed to fetch models:", e);
|
|
618
|
-
} finally {
|
|
619
|
-
u.getState().setModelCatalogLoaded(!0);
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
function Xe(e, n, i = Je, a) {
|
|
623
|
-
R(() => {
|
|
624
|
-
let o = new AbortController();
|
|
625
|
-
return (async () => {
|
|
626
|
-
W.getState().setStatus("loading");
|
|
627
|
-
try {
|
|
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);
|
|
633
|
-
W.getState().setAgentName(e), document.title = e;
|
|
634
|
-
}
|
|
635
|
-
let p = String(d?.Framework || "").trim().toLowerCase();
|
|
636
|
-
W.getState().setAgentFramework(p);
|
|
637
|
-
let m = t(c);
|
|
638
|
-
W.getState().setCapabilities(m), W.getState().setApiFormats(qe(m.HostedChat.ApiFormats)), W.getState().setAccessMode(String(l?.AccessMode || "Owner"));
|
|
639
|
-
let h = m.WorkspaceFiles && l?.WorkspaceFiles ? l.WorkspaceFiles : null;
|
|
640
|
-
W.getState().setWorkspaceFiles(h), h || s.getState().setWorkspacePanelOpen(!1), r(m) && e.fetchSessions(f, He(f));
|
|
641
|
-
let g = l?.Model;
|
|
642
|
-
g?.id && (u.getState().setSelectedModel(g.id), u.getState().upsertModels([g]), u.getState().setModelSource(g.source || "")), Ye(f, i), W.getState().setStatus("ready");
|
|
643
|
-
} catch (e) {
|
|
644
|
-
if (o.signal.aborted) return;
|
|
645
|
-
console.error("Failed to fetch bootstrap:", e);
|
|
646
|
-
let t = Ke(e);
|
|
647
|
-
W.getState().setStatus(t, t === "auth-required" ? "当前访问链接未授权或已过期。" : "无法加载 Agent 配置,请稍后重试。");
|
|
648
|
-
}
|
|
649
|
-
})(), () => o.abort();
|
|
650
|
-
}, [
|
|
651
|
-
i,
|
|
652
|
-
n,
|
|
653
|
-
a
|
|
654
|
-
]);
|
|
655
|
-
}
|
|
656
|
-
//#endregion
|
|
657
|
-
//#region src/hooks/useFeedback.ts
|
|
658
|
-
function Ze(e) {
|
|
659
|
-
let { agentId: t, currentSessionId: n, isStreaming: r, api: i, submitDraft: a } = e;
|
|
660
|
-
return {
|
|
661
|
-
submitResponseFeedback: L(async (e) => {
|
|
662
|
-
if (!n) return;
|
|
663
|
-
let r = null;
|
|
664
|
-
E.getState().patchMessages((t) => {
|
|
665
|
-
let n = T(t, {
|
|
666
|
-
messageId: e.message.id,
|
|
667
|
-
rating: e.rating,
|
|
668
|
-
comment: e.comment || ""
|
|
669
|
-
});
|
|
670
|
-
return r = n.previousFeedback, n.nextMessages;
|
|
671
|
-
});
|
|
672
|
-
try {
|
|
673
|
-
let r = S((await i.upsertResponseFeedback(C({
|
|
674
|
-
agentId: t,
|
|
675
|
-
sessionId: n,
|
|
676
|
-
message: e.message,
|
|
677
|
-
rating: e.rating,
|
|
678
|
-
comment: e.comment || ""
|
|
679
|
-
})))?.Feedback);
|
|
680
|
-
r && E.getState().patchMessages((t) => _(t, {
|
|
681
|
-
messageId: e.message.id,
|
|
682
|
-
feedback: r
|
|
683
|
-
}));
|
|
684
|
-
} catch (t) {
|
|
685
|
-
console.error("Failed to submit response feedback:", t), E.getState().patchMessages((t) => w(t, {
|
|
686
|
-
messageId: e.message.id,
|
|
687
|
-
previousFeedback: r
|
|
688
|
-
}));
|
|
689
|
-
}
|
|
690
|
-
}, [
|
|
691
|
-
t,
|
|
692
|
-
n,
|
|
693
|
-
i
|
|
694
|
-
]),
|
|
695
|
-
deleteResponseFeedback: L(async (e) => {
|
|
696
|
-
if (!n) return;
|
|
697
|
-
let r = e.feedback ? { ...e.feedback } : null;
|
|
698
|
-
E.getState().patchMessages((t) => y(t, { messageId: e.id }));
|
|
699
|
-
try {
|
|
700
|
-
await i.deleteResponseFeedback(x({
|
|
701
|
-
agentId: t,
|
|
702
|
-
sessionId: n,
|
|
703
|
-
message: e
|
|
704
|
-
}));
|
|
705
|
-
} catch (t) {
|
|
706
|
-
console.error("Failed to delete response feedback:", t), E.getState().patchMessages((t) => w(t, {
|
|
707
|
-
messageId: e.id,
|
|
708
|
-
previousFeedback: r
|
|
709
|
-
}));
|
|
710
|
-
}
|
|
711
|
-
}, [
|
|
712
|
-
t,
|
|
713
|
-
n,
|
|
714
|
-
i
|
|
715
|
-
]),
|
|
716
|
-
respondToApproval: L((e) => {
|
|
717
|
-
!e.approvalRequestId || r || (E.getState().patchMessages((t) => t.map((t) => {
|
|
718
|
-
let n = e.approve ? "approved" : "rejected", r = (t) => e.approve && t === "paused" ? "running" : e.approve ? t : "completed";
|
|
719
|
-
return {
|
|
720
|
-
...t,
|
|
721
|
-
tools: t.tools ? Object.fromEntries(Object.entries(t.tools).map(([t, i]) => [t, i.approvalRequestId === e.approvalRequestId ? {
|
|
722
|
-
...i,
|
|
723
|
-
status: r(i.status),
|
|
724
|
-
approvalStatus: n
|
|
725
|
-
} : i])) : t.tools,
|
|
726
|
-
blocks: t.blocks?.map((t) => t.type === "tool" && t.extra?.approvalRequestId === e.approvalRequestId ? {
|
|
727
|
-
...t,
|
|
728
|
-
status: r(t.status),
|
|
729
|
-
extra: {
|
|
730
|
-
...t.extra,
|
|
731
|
-
approvalStatus: n
|
|
732
|
-
}
|
|
733
|
-
} : t)
|
|
734
|
-
};
|
|
735
|
-
})), a("", [], [{
|
|
736
|
-
type: "mcp_approval_response",
|
|
737
|
-
approval_request_id: e.approvalRequestId,
|
|
738
|
-
approve: e.approve
|
|
739
|
-
}], e.previousResponseId));
|
|
740
|
-
}, [r, a])
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
//#endregion
|
|
744
|
-
//#region src/core/interaction/store.ts
|
|
745
|
-
var Qe = class {
|
|
746
|
-
records = /* @__PURE__ */ new Map();
|
|
747
|
-
terminalRuns = /* @__PURE__ */ new Set();
|
|
748
|
-
listeners = /* @__PURE__ */ new Set();
|
|
749
|
-
key(e, t) {
|
|
750
|
-
return `${e}\u0000${t}`;
|
|
751
|
-
}
|
|
752
|
-
runKey(e, t) {
|
|
753
|
-
return `${e}\u0000${t}`;
|
|
754
|
-
}
|
|
755
|
-
subscribe(e) {
|
|
756
|
-
return this.listeners.add(e), () => {
|
|
757
|
-
this.listeners.delete(e);
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
emit(e) {
|
|
761
|
-
for (let t of this.listeners) t(e);
|
|
762
|
-
}
|
|
763
|
-
get(e, t) {
|
|
764
|
-
return this.records.get(this.key(e, t)) || null;
|
|
765
|
-
}
|
|
766
|
-
listPending(e) {
|
|
767
|
-
return this.listAll(e).filter((e) => e.status === "pending");
|
|
768
|
-
}
|
|
769
|
-
listAll(e) {
|
|
770
|
-
return this.all().filter((t) => t.sessionId === e);
|
|
771
|
-
}
|
|
772
|
-
all() {
|
|
773
|
-
return [...this.records.values()].sort((e, t) => String(e.createdAt).localeCompare(String(t.createdAt)));
|
|
774
|
-
}
|
|
775
|
-
upsert(e) {
|
|
776
|
-
e.runId && !f(e.status) && this.terminalRuns.has(this.runKey(e.sessionId, e.runId)) && (e = {
|
|
777
|
-
...e,
|
|
778
|
-
status: "expired",
|
|
779
|
-
outcome: "expired",
|
|
780
|
-
resolvedAt: e.resolvedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
781
|
-
responseSummary: e.responseSummary ?? "运行已结束"
|
|
782
|
-
});
|
|
783
|
-
let t = this.get(e.sessionId, e.interactionId), n, r;
|
|
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 = {
|
|
785
|
-
type: "interaction_updated",
|
|
786
|
-
interaction: n
|
|
787
|
-
}) : f(e.status) ? (n = {
|
|
788
|
-
...t,
|
|
789
|
-
...e,
|
|
790
|
-
title: t.title || e.title,
|
|
791
|
-
kind: t.kind || e.kind,
|
|
792
|
-
message: t.message || e.message,
|
|
793
|
-
runId: e.runId ?? t.runId,
|
|
794
|
-
requestSchema: t.requestSchema ?? e.requestSchema,
|
|
795
|
-
presentation: t.presentation ?? e.presentation,
|
|
796
|
-
actor: e.actor ?? t.actor,
|
|
797
|
-
outcome: e.outcome ?? t.outcome,
|
|
798
|
-
resolvedAt: e.resolvedAt ?? t.resolvedAt,
|
|
799
|
-
responseSummary: e.responseSummary ?? t.responseSummary
|
|
800
|
-
}, r = {
|
|
801
|
-
type: "interaction_resolved",
|
|
802
|
-
interaction: n
|
|
803
|
-
}) : (n = {
|
|
804
|
-
...t,
|
|
805
|
-
...e
|
|
806
|
-
}, r = {
|
|
807
|
-
type: "interaction_updated",
|
|
808
|
-
interaction: n
|
|
809
|
-
}) : (n = e, r = {
|
|
810
|
-
type: "interaction_requested",
|
|
811
|
-
interaction: n
|
|
812
|
-
}), this.records.set(this.key(n.sessionId, n.interactionId), n), this.emit(r), r;
|
|
813
|
-
}
|
|
814
|
-
markResolving(e, t) {
|
|
815
|
-
let n = this.get(e, t);
|
|
816
|
-
!n || n.status !== "pending" || (this.records.set(this.key(e, t), {
|
|
817
|
-
...n,
|
|
818
|
-
status: "resolving"
|
|
819
|
-
}), this.emit({
|
|
820
|
-
type: "interaction_updated",
|
|
821
|
-
interaction: this.get(e, t)
|
|
822
|
-
}));
|
|
823
|
-
}
|
|
824
|
-
resolveLocally(e, t, n) {
|
|
825
|
-
let r = this.get(e, t);
|
|
826
|
-
if (!r) return;
|
|
827
|
-
let i = {
|
|
828
|
-
...r,
|
|
829
|
-
...n,
|
|
830
|
-
resolvedAt: n.resolvedAt ?? r.resolvedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
831
|
-
revision: n.revision ?? r.revision
|
|
832
|
-
};
|
|
833
|
-
this.records.set(this.key(e, t), i), this.emit({
|
|
834
|
-
type: "interaction_resolved",
|
|
835
|
-
interaction: i
|
|
836
|
-
});
|
|
837
|
-
}
|
|
838
|
-
recordIdempotencyKey(e, t, n) {
|
|
839
|
-
let r = this.get(e, t);
|
|
840
|
-
if (!r) return;
|
|
841
|
-
let i = {
|
|
842
|
-
...r,
|
|
843
|
-
extensions: {
|
|
844
|
-
...r.extensions,
|
|
845
|
-
idempotency_key: n
|
|
846
|
-
}
|
|
847
|
-
};
|
|
848
|
-
this.records.set(this.key(e, t), i), this.emit({
|
|
849
|
-
type: "interaction_updated",
|
|
850
|
-
interaction: i
|
|
851
|
-
});
|
|
852
|
-
}
|
|
853
|
-
markFailed(e, t, n) {
|
|
854
|
-
let r = this.get(e, t);
|
|
855
|
-
if (!r || r.status !== "resolving") return;
|
|
856
|
-
let i = {
|
|
857
|
-
...r,
|
|
858
|
-
status: "failed",
|
|
859
|
-
extensions: {
|
|
860
|
-
...r.extensions,
|
|
861
|
-
submit_error: n
|
|
862
|
-
}
|
|
863
|
-
};
|
|
864
|
-
this.records.set(this.key(e, t), i), this.emit({
|
|
865
|
-
type: "interaction_updated",
|
|
866
|
-
interaction: i
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
revertToPending(e, t) {
|
|
870
|
-
let n = this.get(e, t);
|
|
871
|
-
if (!n || n.status !== "resolving") return;
|
|
872
|
-
let r = {
|
|
873
|
-
...n,
|
|
874
|
-
status: "pending"
|
|
875
|
-
};
|
|
876
|
-
this.records.set(this.key(e, t), r), this.emit({
|
|
877
|
-
type: "interaction_updated",
|
|
878
|
-
interaction: r
|
|
879
|
-
});
|
|
880
|
-
}
|
|
881
|
-
markRunTerminal(e, t) {
|
|
882
|
-
if (!(!e || !t)) {
|
|
883
|
-
this.terminalRuns.add(this.runKey(e, t));
|
|
884
|
-
for (let n of this.listAll(e)) {
|
|
885
|
-
if (n.runId !== t || f(n.status)) continue;
|
|
886
|
-
let r = {
|
|
887
|
-
...n,
|
|
888
|
-
status: "expired",
|
|
889
|
-
outcome: "expired",
|
|
890
|
-
resolvedAt: n.resolvedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
891
|
-
responseSummary: n.responseSummary ?? "运行已结束"
|
|
892
|
-
};
|
|
893
|
-
this.records.set(this.key(e, n.interactionId), r), this.emit({
|
|
894
|
-
type: "interaction_resolved",
|
|
895
|
-
interaction: r
|
|
896
|
-
});
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
markSessionTerminal(e) {
|
|
901
|
-
if (!e) return;
|
|
902
|
-
let t = new Set(this.listAll(e).filter((e) => !f(e.status)).map((e) => e.runId).filter((e) => !!e));
|
|
903
|
-
for (let n of t) this.markRunTerminal(e, n);
|
|
904
|
-
for (let t of this.listAll(e)) {
|
|
905
|
-
if (t.runId || f(t.status)) continue;
|
|
906
|
-
let n = {
|
|
907
|
-
...t,
|
|
908
|
-
status: "expired",
|
|
909
|
-
outcome: "expired",
|
|
910
|
-
resolvedAt: t.resolvedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
911
|
-
responseSummary: t.responseSummary ?? "运行已结束"
|
|
912
|
-
};
|
|
913
|
-
this.records.set(this.key(e, t.interactionId), n), this.emit({
|
|
914
|
-
type: "interaction_resolved",
|
|
915
|
-
interaction: n
|
|
916
|
-
});
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
remove(e, t) {
|
|
920
|
-
let n = this.key(e, t);
|
|
921
|
-
this.records.has(n) && (this.records.delete(n), this.emit({
|
|
922
|
-
type: "interaction_removed",
|
|
923
|
-
interactionId: t
|
|
924
|
-
}));
|
|
925
|
-
}
|
|
926
|
-
clearSession(e) {
|
|
927
|
-
for (let t of this.listAll(e)) this.remove(e, t.interactionId);
|
|
928
|
-
let t = `${e}\u0000`;
|
|
929
|
-
for (let e of this.terminalRuns) e.startsWith(t) && this.terminalRuns.delete(e);
|
|
930
|
-
}
|
|
931
|
-
}, $e = {
|
|
932
|
-
approve: "approved",
|
|
933
|
-
reject: "rejected",
|
|
934
|
-
submit: "submitted",
|
|
935
|
-
cancel: "cancelled"
|
|
936
|
-
};
|
|
937
|
-
function G(e, t) {
|
|
938
|
-
return {
|
|
939
|
-
schema_version: 1,
|
|
940
|
-
command_id: `local-${t}`,
|
|
941
|
-
status: e,
|
|
942
|
-
message_id: null,
|
|
943
|
-
run_id: null,
|
|
944
|
-
accepted_seq: null,
|
|
945
|
-
error: null,
|
|
946
|
-
extensions: {}
|
|
947
|
-
};
|
|
948
|
-
}
|
|
949
|
-
var et = class {
|
|
950
|
-
store;
|
|
951
|
-
deps;
|
|
952
|
-
inFlight = /* @__PURE__ */ new Map();
|
|
953
|
-
constructor(e) {
|
|
954
|
-
this.deps = e, this.store = e.store || new Qe();
|
|
955
|
-
}
|
|
956
|
-
listPending(e) {
|
|
957
|
-
return this.store.listPending(e);
|
|
958
|
-
}
|
|
959
|
-
setInteractionV1Enabled(e) {
|
|
960
|
-
this.deps.interactionV1Enabled = e;
|
|
961
|
-
}
|
|
962
|
-
subscribe(e) {
|
|
963
|
-
return this.store.subscribe(e);
|
|
964
|
-
}
|
|
965
|
-
ingest(e) {
|
|
966
|
-
this.store.upsert(e);
|
|
967
|
-
}
|
|
968
|
-
ingestHistory(e) {
|
|
969
|
-
for (let t of e) this.store.upsert(t);
|
|
970
|
-
for (let [e] of this.inFlight) {
|
|
971
|
-
let t = this.findByInteractionId(e);
|
|
972
|
-
t && t.status !== "pending" && t.status !== "resolving" && this.inFlight.delete(e);
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
findByInteractionId(e) {
|
|
976
|
-
return this.store.all().find((t) => t.interactionId === e) || null;
|
|
977
|
-
}
|
|
978
|
-
async respond(e) {
|
|
979
|
-
let t = this.findByInteractionId(e.interactionId);
|
|
980
|
-
if (!t) return G("rejected", e.interactionId);
|
|
981
|
-
if (t.status === "resolved" || t.status === "cancelled" || t.status === "expired" || t.status === "resolving") return G("duplicate", e.interactionId);
|
|
982
|
-
let n = e.idempotencyKey || i(e.interactionId, e.expectedRevision), r = this.inFlight.get(e.interactionId);
|
|
983
|
-
if (r) return G(r === n ? "duplicate" : "rejected", e.interactionId);
|
|
984
|
-
this.inFlight.set(e.interactionId, n), this.store.markResolving(t.sessionId, e.interactionId);
|
|
985
|
-
let a = this.deps.interactionV1Enabled || t.source === "interaction_v1";
|
|
986
|
-
try {
|
|
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({
|
|
990
|
-
AgentId: this.deps.agentId,
|
|
991
|
-
SessionId: t.sessionId,
|
|
992
|
-
RunId: t.runId || "",
|
|
993
|
-
InteractionId: e.interactionId,
|
|
994
|
-
ExpectedRevision: e.expectedRevision,
|
|
995
|
-
Action: e.action,
|
|
996
|
-
Response: e.response,
|
|
997
|
-
IdempotencyKey: n
|
|
998
|
-
}));
|
|
999
|
-
return r.status === "accepted" || r.status === "duplicate" ? this.store.recordIdempotencyKey(t.sessionId, e.interactionId, n) : r.status === "queue_full" ? this.store.revertToPending(t.sessionId, e.interactionId) : this.store.markFailed(t.sessionId, e.interactionId, {
|
|
1000
|
-
code: r.error?.code ?? String(r.status),
|
|
1001
|
-
message: r.error?.message ?? `提交未通过(${r.status})`,
|
|
1002
|
-
retryable: r.error?.retryable ?? !1
|
|
1003
|
-
}), r;
|
|
1004
|
-
} catch (n) {
|
|
1005
|
-
let r = n instanceof Error ? n.message : String(n || "交互提交失败");
|
|
1006
|
-
throw this.store.markFailed(t.sessionId, e.interactionId, {
|
|
1007
|
-
code: "interaction_submit_failed",
|
|
1008
|
-
message: r,
|
|
1009
|
-
retryable: !0
|
|
1010
|
-
}), n;
|
|
1011
|
-
} finally {
|
|
1012
|
-
this.inFlight.delete(e.interactionId);
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
resolveLocal(e, t, n) {
|
|
1016
|
-
let r = t.action === "cancel" ? "cancelled" : "resolved";
|
|
1017
|
-
this.store.resolveLocally(e.sessionId, t.interactionId, {
|
|
1018
|
-
status: r,
|
|
1019
|
-
outcome: $e[t.action],
|
|
1020
|
-
actor: "user",
|
|
1021
|
-
responseSummary: m(t.action, t.response),
|
|
1022
|
-
revision: t.expectedRevision
|
|
1023
|
-
});
|
|
1024
|
-
let i = this.store.get(e.sessionId, t.interactionId);
|
|
1025
|
-
i && this.store.upsert({
|
|
1026
|
-
...i,
|
|
1027
|
-
extensions: {
|
|
1028
|
-
...i.extensions,
|
|
1029
|
-
idempotency_key: n
|
|
1030
|
-
}
|
|
1031
|
-
});
|
|
1032
|
-
}
|
|
1033
|
-
}, tt = new Set([
|
|
1034
|
-
"approval",
|
|
1035
|
-
"structured_input",
|
|
1036
|
-
"plan_review",
|
|
1037
|
-
"custom"
|
|
1038
|
-
]), nt = new Set([
|
|
1039
|
-
"pending",
|
|
1040
|
-
"resolving",
|
|
1041
|
-
"failed",
|
|
1042
|
-
"resolved",
|
|
1043
|
-
"cancelled",
|
|
1044
|
-
"expired"
|
|
1045
|
-
]), rt = new Set([
|
|
1046
|
-
"approved",
|
|
1047
|
-
"rejected",
|
|
1048
|
-
"submitted",
|
|
1049
|
-
"cancelled",
|
|
1050
|
-
"expired"
|
|
1051
|
-
]);
|
|
1052
|
-
function it(e) {
|
|
1053
|
-
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
1054
|
-
}
|
|
1055
|
-
function K(e) {
|
|
1056
|
-
return typeof e == "string" && e.length > 0 ? e : null;
|
|
1057
|
-
}
|
|
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;
|
|
1060
|
-
return {
|
|
1061
|
-
interactionId: e.interactionId,
|
|
1062
|
-
sessionId: e.sessionId,
|
|
1063
|
-
runId: K(e.runId),
|
|
1064
|
-
kind: tt.has(t) ? t : "custom",
|
|
1065
|
-
title: typeof e.title == "string" && e.title ? e.title : "人工确认",
|
|
1066
|
-
message: typeof e.message == "string" && e.message ? e.message : "本次运行需要人工处理后才能继续。",
|
|
1067
|
-
requestSchema: it(e.requestSchema),
|
|
1068
|
-
presentation: a ? { a2ui: {
|
|
1069
|
-
wireVersion: String(a.wire_version ?? a.wireVersion ?? ""),
|
|
1070
|
-
catalogDigest: String(a.catalog_digest ?? a.catalogDigest ?? ""),
|
|
1071
|
-
messages: Array.isArray(a.messages) ? a.messages.filter((e) => typeof e == "object") : []
|
|
1072
|
-
} } : null,
|
|
1073
|
-
status: nt.has(n) ? n : "pending",
|
|
1074
|
-
revision: Number.isFinite(Number(e.revision)) && Number(e.revision) > 0 ? Number(e.revision) : 1,
|
|
1075
|
-
createdAt: K(e.createdAt) || (/* @__PURE__ */ new Date()).toISOString(),
|
|
1076
|
-
expiresAt: K(e.expiresAt),
|
|
1077
|
-
resolvedAt: K(e.resolvedAt),
|
|
1078
|
-
actor: K(e.actor),
|
|
1079
|
-
outcome: rt.has(r) ? r : null,
|
|
1080
|
-
responseSummary: K(e.responseSummary),
|
|
1081
|
-
source: e.source,
|
|
1082
|
-
extensions: e.extensions || {}
|
|
1083
|
-
};
|
|
1084
|
-
}
|
|
1085
|
-
//#endregion
|
|
1086
|
-
//#region src/core/interaction/adapters/session-events.ts
|
|
1087
|
-
var ot = new Set([
|
|
1088
|
-
"interaction.requested",
|
|
1089
|
-
"interaction_requested",
|
|
1090
|
-
"ksadk.interaction/v1.requested",
|
|
1091
|
-
"InteractionRequested",
|
|
1092
|
-
"approval.requested",
|
|
1093
|
-
"a2ui.interaction"
|
|
1094
|
-
]), st = new Set([
|
|
1095
|
-
"interaction.resolved",
|
|
1096
|
-
"interaction_resolved",
|
|
1097
|
-
"ksadk.interaction/v1.resolved",
|
|
1098
|
-
"InteractionResolved",
|
|
1099
|
-
"interaction.cancelled",
|
|
1100
|
-
"interaction.cancel",
|
|
1101
|
-
"interaction.expired",
|
|
1102
|
-
"approval.resolved",
|
|
1103
|
-
"a2ui.action"
|
|
1104
|
-
]);
|
|
1105
|
-
function q(e) {
|
|
1106
|
-
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
1107
|
-
}
|
|
1108
|
-
function ct(e, t) {
|
|
1109
|
-
let n = q(e);
|
|
1110
|
-
if (!n) return null;
|
|
1111
|
-
let r = String(n.event_type || n.EventType || "").trim();
|
|
1112
|
-
if (!r) return null;
|
|
1113
|
-
let i = q(n.payload ?? n.Content) || {}, a = q(i.interaction) || q(i.Interaction) || q(i.interaction_request) || i, o = String(a.interaction_id || a.interactionId || a.InteractionId || a.approval_id || a.approvalId || i.interaction_id || i.interactionId || i.InteractionId || i.approval_id || i.approvalId || "");
|
|
1114
|
-
if (!o) return null;
|
|
1115
|
-
let s = String(n.session_id || n.SessionId || a.session_id || a.sessionId || t || "");
|
|
1116
|
-
if (!s) return null;
|
|
1117
|
-
if (ot.has(r)) {
|
|
1118
|
-
let e = {
|
|
1119
|
-
...q(a.extensions) || {},
|
|
1120
|
-
...a.detail === void 0 ? {} : { detail: a.detail },
|
|
1121
|
-
...(a.call_id ?? a.callId) === void 0 ? {} : { call_id: a.call_id ?? a.callId }
|
|
1122
|
-
};
|
|
1123
|
-
return at({
|
|
1124
|
-
interactionId: o,
|
|
1125
|
-
sessionId: s,
|
|
1126
|
-
runId: a.run_id ?? a.runId ?? n.run_id ?? n.InvocationId,
|
|
1127
|
-
kind: r === "approval.requested" ? "approval" : a.kind ?? "approval",
|
|
1128
|
-
title: a.title,
|
|
1129
|
-
message: a.message ?? a.description ?? q(a.detail)?.command,
|
|
1130
|
-
requestSchema: a.request_schema ?? a.requestSchema ?? a.input_schema ?? a.inputSchema ?? a.RequestSchema,
|
|
1131
|
-
presentation: a.presentation,
|
|
1132
|
-
status: "pending",
|
|
1133
|
-
revision: a.revision ?? 1,
|
|
1134
|
-
createdAt: a.created_at ?? a.createdAt ?? n.timestamp ?? n.Timestamp,
|
|
1135
|
-
expiresAt: a.expires_at,
|
|
1136
|
-
source: "interaction_v1",
|
|
1137
|
-
extensions: e
|
|
1138
|
-
});
|
|
1139
|
-
}
|
|
1140
|
-
if (st.has(r)) {
|
|
1141
|
-
let e = {
|
|
1142
|
-
...q(a.extensions) || {},
|
|
1143
|
-
...a.detail === void 0 ? {} : { detail: a.detail },
|
|
1144
|
-
...(a.call_id ?? a.callId) === void 0 ? {} : { call_id: a.call_id ?? a.callId }
|
|
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;
|
|
1146
|
-
u ||= l === "approve" ? "approved" : l === "reject" ? "rejected" : l === "submit" ? "submitted" : l === "cancel" || t === "cancelled" ? "cancelled" : t === "expired" ? "expired" : "submitted";
|
|
1147
|
-
let d = t === "resolved" ? "resolved" : t;
|
|
1148
|
-
return at({
|
|
1149
|
-
interactionId: o,
|
|
1150
|
-
sessionId: s,
|
|
1151
|
-
runId: a.run_id ?? a.runId ?? n.run_id ?? n.InvocationId,
|
|
1152
|
-
kind: a.kind,
|
|
1153
|
-
title: a.title,
|
|
1154
|
-
message: a.message,
|
|
1155
|
-
requestSchema: a.request_schema,
|
|
1156
|
-
presentation: a.presentation,
|
|
1157
|
-
status: d,
|
|
1158
|
-
revision: a.revision,
|
|
1159
|
-
createdAt: a.created_at ?? n.timestamp,
|
|
1160
|
-
expiresAt: a.expires_at,
|
|
1161
|
-
resolvedAt: i.resolved_at ?? i.resolvedAt ?? a.resolved_at ?? a.resolvedAt ?? n.timestamp ?? n.Timestamp,
|
|
1162
|
-
actor: i.actor ?? a.actor ?? n.actor_ref,
|
|
1163
|
-
outcome: u,
|
|
1164
|
-
responseSummary: i.response_summary ?? a.response_summary ?? (l ? `${l}` : void 0),
|
|
1165
|
-
source: "interaction_v1",
|
|
1166
|
-
extensions: e
|
|
1167
|
-
});
|
|
1168
|
-
}
|
|
1169
|
-
return null;
|
|
1170
|
-
}
|
|
1171
|
-
//#endregion
|
|
1172
|
-
//#region src/core/interaction/adapters/responses.ts
|
|
1173
|
-
function lt(e) {
|
|
1174
|
-
return !e.approvalRequestId || !e.sessionId ? null : at({
|
|
1175
|
-
interactionId: e.approvalRequestId,
|
|
1176
|
-
sessionId: e.sessionId,
|
|
1177
|
-
runId: e.runId ?? null,
|
|
1178
|
-
kind: "approval",
|
|
1179
|
-
title: e.name ? `审批:${e.name}` : "人工确认",
|
|
1180
|
-
message: e.message || "本次运行需要人工审批后才能继续。",
|
|
1181
|
-
requestSchema: e.requestSchema ?? null,
|
|
1182
|
-
status: "pending",
|
|
1183
|
-
revision: 1,
|
|
1184
|
-
source: "responses",
|
|
1185
|
-
extensions: {
|
|
1186
|
-
...e.approvalLevel ? { approval_level: e.approvalLevel } : {},
|
|
1187
|
-
...e.args ? { arguments: e.args } : {}
|
|
1188
|
-
}
|
|
1189
|
-
});
|
|
1190
|
-
}
|
|
1191
|
-
//#endregion
|
|
1192
|
-
//#region src/core/interaction/adapters/agui.ts
|
|
1193
|
-
function ut(e) {
|
|
1194
|
-
return !e.interruptId || !e.sessionId ? null : at({
|
|
1195
|
-
interactionId: e.interruptId,
|
|
1196
|
-
sessionId: e.sessionId,
|
|
1197
|
-
runId: e.runId ?? null,
|
|
1198
|
-
kind: "approval",
|
|
1199
|
-
title: e.name ? `确认:${e.name}` : "人工确认",
|
|
1200
|
-
message: e.message || "本次运行需要人工确认后才能继续。",
|
|
1201
|
-
requestSchema: e.requestSchema ?? null,
|
|
1202
|
-
status: "pending",
|
|
1203
|
-
revision: 1,
|
|
1204
|
-
source: "agui",
|
|
1205
|
-
extensions: {
|
|
1206
|
-
interrupt_id: e.interruptId,
|
|
1207
|
-
...e.toolCallId ? { tool_call_id: e.toolCallId } : {},
|
|
1208
|
-
...e.reason ? { reason: e.reason } : {}
|
|
1209
|
-
}
|
|
1210
|
-
});
|
|
1211
|
-
}
|
|
1212
|
-
//#endregion
|
|
1213
|
-
//#region src/core/interaction/index.ts
|
|
1214
|
-
var dt = new Set([
|
|
1215
|
-
"completed",
|
|
1216
|
-
"failed",
|
|
1217
|
-
"error",
|
|
1218
|
-
"cancelled",
|
|
1219
|
-
"canceled",
|
|
1220
|
-
"aborted",
|
|
1221
|
-
"interrupted",
|
|
1222
|
-
"resume_failed"
|
|
1223
|
-
]), J = new Qe();
|
|
1224
|
-
function ft(e, t) {
|
|
1225
|
-
let n = ct(e, t);
|
|
1226
|
-
n && J.upsert(n);
|
|
1227
|
-
let r = typeof e == "object" && e ? e : null, i = r ? P(r) : null;
|
|
1228
|
-
if (i !== null && dt.has(i)) {
|
|
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 || "");
|
|
1230
|
-
J.markRunTerminal(i, a);
|
|
1231
|
-
}
|
|
1232
|
-
return n;
|
|
1233
|
-
}
|
|
1234
|
-
function pt(e) {
|
|
1235
|
-
let t = e.sessionId || "";
|
|
1236
|
-
if (!t || !e.approvalRequestId) return null;
|
|
1237
|
-
let n = e.protocol === "ag-ui" ? ut({
|
|
1238
|
-
interruptId: e.approvalRequestId,
|
|
1239
|
-
sessionId: t,
|
|
1240
|
-
name: e.name,
|
|
1241
|
-
message: e.message,
|
|
1242
|
-
reason: e.approvalLevel
|
|
1243
|
-
}) : lt({
|
|
1244
|
-
approvalRequestId: e.approvalRequestId,
|
|
1245
|
-
sessionId: t,
|
|
1246
|
-
runId: e.runId,
|
|
1247
|
-
name: e.name,
|
|
1248
|
-
message: e.message,
|
|
1249
|
-
args: e.args,
|
|
1250
|
-
approvalLevel: e.approvalLevel
|
|
1251
|
-
});
|
|
1252
|
-
return n && J.upsert(n), n;
|
|
1253
|
-
}
|
|
1254
|
-
function mt(e) {
|
|
1255
|
-
let t = e.sessionId || "";
|
|
1256
|
-
return !t || !e.approvalRequestId ? null : ft({
|
|
1257
|
-
EventType: "approval.resolved",
|
|
1258
|
-
Content: {
|
|
1259
|
-
approvalId: e.approvalRequestId,
|
|
1260
|
-
revision: e.revision || 2,
|
|
1261
|
-
outcome: e.decision,
|
|
1262
|
-
actor: "user",
|
|
1263
|
-
resolvedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1264
|
-
}
|
|
1265
|
-
}, t);
|
|
1266
|
-
}
|
|
1267
|
-
//#endregion
|
|
1268
|
-
//#region src/hooks/useInteractions.ts
|
|
1269
|
-
function ht(e) {
|
|
1270
|
-
let [t] = he(() => new et({
|
|
1271
|
-
agentId: e.agentId,
|
|
1272
|
-
store: J,
|
|
1273
|
-
submitInteraction: (t) => e.api.submitInteraction({
|
|
1274
|
-
...t,
|
|
1275
|
-
AgentId: e.getAgentId?.() ?? t.AgentId
|
|
1276
|
-
}),
|
|
1277
|
-
interactionV1Enabled: e.interactionV1Enabled,
|
|
1278
|
-
legacyResponsesApproval: e.legacyResponsesApproval,
|
|
1279
|
-
legacyAguiResume: e.legacyAguiResume
|
|
1280
|
-
}));
|
|
1281
|
-
R(() => {
|
|
1282
|
-
t.setInteractionV1Enabled(e.interactionV1Enabled);
|
|
1283
|
-
}, [t, e.interactionV1Enabled]);
|
|
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;
|
|
1287
|
-
return {
|
|
1288
|
-
client: t,
|
|
1289
|
-
pending: i,
|
|
1290
|
-
records: a,
|
|
1291
|
-
respond: L((e) => {
|
|
1292
|
-
let n = o ? J.get(o, e.interactionId) : null;
|
|
1293
|
-
return t.respond(e).then((e) => (s && n && (e.status === "accepted" || e.status === "duplicate") && c?.(n), e));
|
|
1294
|
-
}, [
|
|
1295
|
-
t,
|
|
1296
|
-
o,
|
|
1297
|
-
s,
|
|
1298
|
-
c
|
|
1299
|
-
]),
|
|
1300
|
-
localCatalog: d
|
|
1301
|
-
};
|
|
1302
|
-
}
|
|
1303
|
-
var gt = .28;
|
|
1304
|
-
function _t(e, t = 768) {
|
|
1305
|
-
return Number(e) <= t;
|
|
1306
|
-
}
|
|
1307
|
-
function vt({ isMobile: e, desktopSidebarOpen: t, mobileSidebarOpen: n }) {
|
|
1308
|
-
return {
|
|
1309
|
-
desktopSidebarVisible: !e && !!t,
|
|
1310
|
-
mobileDrawerVisible: !!(e && n)
|
|
1311
|
-
};
|
|
1312
|
-
}
|
|
1313
|
-
function yt({ isMobile: e, viewportHeight: t, desktopMaxHeight: n = 160 }) {
|
|
1314
|
-
if (!e) return n;
|
|
1315
|
-
let r = Number(t);
|
|
1316
|
-
if (!Number.isFinite(r) || r <= 0) return n;
|
|
1317
|
-
let i = Math.floor(r * gt);
|
|
1318
|
-
return Math.max(120, Math.min(n, i));
|
|
1319
|
-
}
|
|
1320
|
-
//#endregion
|
|
1321
|
-
//#region src/hooks/useResponsiveViewport.ts
|
|
1322
|
-
function bt() {
|
|
1323
|
-
return typeof window > "u" ? 900 : Math.round(window.visualViewport?.height || window.innerHeight || 900);
|
|
1324
|
-
}
|
|
1325
|
-
function xt() {
|
|
1326
|
-
return typeof window > "u" ? {
|
|
1327
|
-
isMobile: !1,
|
|
1328
|
-
viewportHeight: 900
|
|
1329
|
-
} : {
|
|
1330
|
-
isMobile: _t(window.innerWidth, 768),
|
|
1331
|
-
viewportHeight: bt()
|
|
1332
|
-
};
|
|
1333
|
-
}
|
|
1334
|
-
function St() {
|
|
1335
|
-
let [e, t] = he(() => xt());
|
|
1336
|
-
return R(() => {
|
|
1337
|
-
if (typeof window > "u") return;
|
|
1338
|
-
let e = window.matchMedia("(max-width: 768px)"), n = () => {
|
|
1339
|
-
t(xt());
|
|
1340
|
-
};
|
|
1341
|
-
n();
|
|
1342
|
-
let r = typeof e.addEventListener == "function" ? (e.addEventListener("change", n), () => e.removeEventListener("change", n)) : (e.addListener(n), () => e.removeListener(n));
|
|
1343
|
-
return window.addEventListener("resize", n), window.visualViewport?.addEventListener("resize", n), () => {
|
|
1344
|
-
r(), window.removeEventListener("resize", n), window.visualViewport?.removeEventListener("resize", n);
|
|
1345
|
-
};
|
|
1346
|
-
}, []), e;
|
|
1347
|
-
}
|
|
1348
|
-
//#endregion
|
|
1349
|
-
//#region src/core/stream/responses-protocol.ts
|
|
1350
|
-
var Ct = class {
|
|
1351
|
-
id = "responses";
|
|
1352
|
-
createState() {
|
|
1353
|
-
return ie();
|
|
1354
|
-
}
|
|
1355
|
-
parseItemOperations(e, t, n) {
|
|
1356
|
-
return g(e.eventName, e.data, t, n);
|
|
1357
|
-
}
|
|
1358
|
-
parse(e, t) {
|
|
1359
|
-
return de({
|
|
1360
|
-
eventName: e.eventName,
|
|
1361
|
-
data: e.data,
|
|
1362
|
-
state: t
|
|
1363
|
-
}).map((e) => {
|
|
1364
|
-
if (e.type === "tool_upsert") {
|
|
1365
|
-
let { approvalRequestId: t, previousResponseId: n, serverLabel: r, ...i } = e;
|
|
1366
|
-
return {
|
|
1367
|
-
...i,
|
|
1368
|
-
extra: {
|
|
1369
|
-
...t ? { approvalRequestId: t } : {},
|
|
1370
|
-
...n ? { previousResponseId: n } : {},
|
|
1371
|
-
...r ? { serverLabel: r } : {},
|
|
1372
|
-
...t ? { approvalProtocol: "responses" } : {}
|
|
1373
|
-
}
|
|
1374
|
-
};
|
|
1375
|
-
}
|
|
1376
|
-
return e;
|
|
1377
|
-
});
|
|
1378
|
-
}
|
|
1379
|
-
};
|
|
1380
|
-
//#endregion
|
|
1381
|
-
//#region src/utils/stream-parsing.ts
|
|
1382
|
-
function wt(e) {
|
|
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("") : "";
|
|
1384
|
-
}
|
|
1385
|
-
function Tt(e) {
|
|
1386
|
-
return e && typeof e == "object" ? e : {};
|
|
1387
|
-
}
|
|
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);
|
|
1390
|
-
return {
|
|
1391
|
-
content: wt(r.content),
|
|
1392
|
-
reasoning: wt(r.reasoning_content),
|
|
1393
|
-
finalText: wt(i.content)
|
|
1394
|
-
};
|
|
1395
|
-
}
|
|
1396
|
-
//#endregion
|
|
1397
|
-
//#region src/core/stream/chat-completions-protocol.ts
|
|
1398
|
-
var Dt = class {
|
|
1399
|
-
id = "chat_completions";
|
|
1400
|
-
createState() {
|
|
1401
|
-
return {};
|
|
1402
|
-
}
|
|
1403
|
-
parse(e) {
|
|
1404
|
-
let t = e.data;
|
|
1405
|
-
if (typeof t != "object" || !t) return [];
|
|
1406
|
-
let n = Et(t), r = [];
|
|
1407
|
-
return n.reasoning && r.push({
|
|
1408
|
-
type: "reasoning_delta",
|
|
1409
|
-
text: n.reasoning
|
|
1410
|
-
}), n.content && r.push({
|
|
1411
|
-
type: "text_delta",
|
|
1412
|
-
text: n.content
|
|
1413
|
-
}), n.finalText && r.push({
|
|
1414
|
-
type: "text_final",
|
|
1415
|
-
text: n.finalText
|
|
1416
|
-
}), r;
|
|
1417
|
-
}
|
|
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");
|
|
1422
|
-
}
|
|
1423
|
-
//#endregion
|
|
1424
|
-
//#region src/utils/stream-control.js
|
|
1425
|
-
function At(e = []) {
|
|
1426
|
-
return e.some((e) => {
|
|
1427
|
-
if (e?.type !== "terminal") return !1;
|
|
1428
|
-
let t = String(e.status || "").toLowerCase();
|
|
1429
|
-
return t === "failed" || t === "incomplete" || t === "cancelled";
|
|
1430
|
-
});
|
|
1431
|
-
}
|
|
1432
|
-
//#endregion
|
|
1433
|
-
//#region src/core/transport/sse-parser.ts
|
|
1434
|
-
function Y(e) {
|
|
1435
|
-
let t = [], n = e.trim();
|
|
1436
|
-
if (!n) return t;
|
|
1437
|
-
let r = n.split("\n");
|
|
1438
|
-
if (r.every((e) => e.startsWith(":"))) return t.push({
|
|
1439
|
-
eventName: "__ping__",
|
|
1440
|
-
data: null
|
|
1441
|
-
}), t;
|
|
1442
|
-
let i = "message", a = [];
|
|
1443
|
-
for (let e of r) e.startsWith(":") || (e.startsWith("event:") ? i = e.substring(6).trim() || "message" : e.startsWith("data:") && a.push(e.substring(5).trim()));
|
|
1444
|
-
let o = a.join("\n").trim();
|
|
1445
|
-
if (o === "[DONE]") return t.push({
|
|
1446
|
-
eventName: "__done__",
|
|
1447
|
-
data: null
|
|
1448
|
-
}), t;
|
|
1449
|
-
if (!o) return t;
|
|
1450
|
-
try {
|
|
1451
|
-
let e = JSON.parse(o);
|
|
1452
|
-
t.push({
|
|
1453
|
-
eventName: i,
|
|
1454
|
-
data: e
|
|
1455
|
-
});
|
|
1456
|
-
} catch {
|
|
1457
|
-
t.push({
|
|
1458
|
-
eventName: i,
|
|
1459
|
-
data: o
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
return t;
|
|
1463
|
-
}
|
|
1464
|
-
function jt(e) {
|
|
1465
|
-
let t = e.split("\n\n");
|
|
1466
|
-
return {
|
|
1467
|
-
chunks: t,
|
|
1468
|
-
remainder: t.pop() || ""
|
|
1469
|
-
};
|
|
1470
|
-
}
|
|
1471
|
-
//#endregion
|
|
1472
|
-
//#region src/utils/error.ts
|
|
1473
|
-
function Mt(e) {
|
|
1474
|
-
return e instanceof Error ? e.message : String(e);
|
|
1475
|
-
}
|
|
1476
|
-
//#endregion
|
|
1477
|
-
//#region src/utils/model-options.js
|
|
1478
|
-
var Nt = new Set([
|
|
1479
|
-
"auto",
|
|
1480
|
-
"enabled",
|
|
1481
|
-
"disabled"
|
|
1482
|
-
]);
|
|
1483
|
-
function Pt(e) {
|
|
1484
|
-
let t = String(e || "").trim().toLowerCase();
|
|
1485
|
-
return Nt.has(t) ? t : "auto";
|
|
1486
|
-
}
|
|
1487
|
-
function Ft(e) {
|
|
1488
|
-
let t = Pt(e);
|
|
1489
|
-
if (t === "disabled") return { thinking: { type: "disabled" } };
|
|
1490
|
-
if (t === "enabled") return { thinking: { type: "enabled" } };
|
|
1491
|
-
}
|
|
1492
|
-
var It = 1280;
|
|
1493
|
-
function Lt(e) {
|
|
1494
|
-
let { apiFormats: t } = e;
|
|
1495
|
-
return t.includes("responses") ? "responses" : t.includes("chat_completions") ? "chat_completions" : "responses";
|
|
1496
|
-
}
|
|
1497
|
-
function Rt(e, t, n) {
|
|
1498
|
-
let r = Math.min(It, Math.max(420, t - n - 360));
|
|
1499
|
-
return Math.min(Math.max(e, 420), r);
|
|
1500
|
-
}
|
|
1501
|
-
//#endregion
|
|
1502
|
-
//#region src/core/run/agui.ts
|
|
1503
|
-
function zt(e) {
|
|
1504
|
-
return String(e.type || "").toUpperCase();
|
|
1505
|
-
}
|
|
1506
|
-
function Bt(e, t) {
|
|
1507
|
-
return String(e.messageId || t);
|
|
1508
|
-
}
|
|
1509
|
-
function Vt(e, t) {
|
|
1510
|
-
return String(e.runId || t);
|
|
1511
|
-
}
|
|
1512
|
-
function Ht(e) {
|
|
1513
|
-
return e && typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
1514
|
-
}
|
|
1515
|
-
function Ut(e) {
|
|
1516
|
-
if (Array.isArray(e)) return l(e.filter((e) => !!(e && typeof e == "object")));
|
|
1517
|
-
if (e && typeof e == "object") {
|
|
1518
|
-
let t = e.a2ui_operations;
|
|
1519
|
-
return Array.isArray(t) ? l(t.filter((e) => !!(e && typeof e == "object"))) : [e];
|
|
1520
|
-
}
|
|
1521
|
-
return [];
|
|
1522
|
-
}
|
|
1523
|
-
function Wt(e) {
|
|
1524
|
-
return e == null || e === "" ? "" : typeof e == "string" ? e : JSON.stringify(e, null, 2);
|
|
1525
|
-
}
|
|
1526
|
-
var Gt = class {
|
|
1527
|
-
agent;
|
|
1528
|
-
onEvent;
|
|
1529
|
-
tools = /* @__PURE__ */ new Map();
|
|
1530
|
-
runMessageIds = /* @__PURE__ */ new Map();
|
|
1531
|
-
pendingByRun = /* @__PURE__ */ new Map();
|
|
1532
|
-
activeRunId = "";
|
|
1533
|
-
constructor(e) {
|
|
1534
|
-
this.agent = new _e({
|
|
1535
|
-
url: e.url,
|
|
1536
|
-
agentId: e.agentId,
|
|
1537
|
-
threadId: e.threadId,
|
|
1538
|
-
fetch: e.fetch
|
|
1539
|
-
}), this.onEvent = e.onEvent;
|
|
1540
|
-
}
|
|
1541
|
-
async run(e, t, n) {
|
|
1542
|
-
return this.activeRunId = t, this.agent.addMessage({
|
|
1543
|
-
id: `${t}:user`,
|
|
1544
|
-
role: "user",
|
|
1545
|
-
content: e
|
|
1546
|
-
}), this.execute({
|
|
1547
|
-
runId: t,
|
|
1548
|
-
abortController: this.controllerFor(n)
|
|
1549
|
-
});
|
|
1550
|
-
}
|
|
1551
|
-
async resume(e, t) {
|
|
1552
|
-
let n = this.agent.pendingInterrupts.length > 0 ? this.agent.pendingInterrupts : this.pendingByRun.get(this.activeRunId) || [], r = ve(n.length > 0 ? n : [{
|
|
1553
|
-
id: t.interruptId,
|
|
1554
|
-
reason: "approval"
|
|
1555
|
-
}], { [t.interruptId]: t.status === "resolved" ? {
|
|
1556
|
-
status: "resolved",
|
|
1557
|
-
payload: t.payload
|
|
1558
|
-
} : { status: "cancelled" } });
|
|
1559
|
-
if (!r.some((e) => e.interruptId === t.interruptId)) throw Error(`AG-UI interrupt ${t.interruptId} is not pending`);
|
|
1560
|
-
return this.activeRunId = e, this.execute({
|
|
1561
|
-
runId: e,
|
|
1562
|
-
resume: r
|
|
1563
|
-
});
|
|
1564
|
-
}
|
|
1565
|
-
abort() {
|
|
1566
|
-
this.agent.abortRun();
|
|
1567
|
-
}
|
|
1568
|
-
controllerFor(e) {
|
|
1569
|
-
if (!e) return;
|
|
1570
|
-
let t = new AbortController();
|
|
1571
|
-
return e.aborted && t.abort(e.reason), e.addEventListener("abort", () => t.abort(e.reason), { once: !0 }), t;
|
|
1572
|
-
}
|
|
1573
|
-
async execute(e) {
|
|
1574
|
-
let t = "completed", n = await this.agent.runAgent({
|
|
1575
|
-
runId: e.runId,
|
|
1576
|
-
context: [h],
|
|
1577
|
-
forwardedProps: { injectA2UITool: !0 },
|
|
1578
|
-
resume: e.resume,
|
|
1579
|
-
abortController: e.abortController
|
|
1580
|
-
}, {
|
|
1581
|
-
onEvent: ({ event: n }) => {
|
|
1582
|
-
let r = this.project(n, e.runId);
|
|
1583
|
-
r.status && (t = r.status), r.events.forEach((e) => this.onEvent(e));
|
|
1584
|
-
},
|
|
1585
|
-
onRunFinishedEvent: ({ outcome: e }) => {
|
|
1586
|
-
t = e === "interrupt" ? "interrupted" : "completed";
|
|
1587
|
-
},
|
|
1588
|
-
onRunErrorEvent: () => {
|
|
1589
|
-
t = "failed";
|
|
1590
|
-
}
|
|
1591
|
-
}), r = this.agent.pendingInterrupts.slice();
|
|
1592
|
-
return r.length > 0 && (this.pendingByRun.set(e.runId, r), t = "interrupted"), {
|
|
1593
|
-
status: t,
|
|
1594
|
-
result: n
|
|
1595
|
-
};
|
|
1596
|
-
}
|
|
1597
|
-
project(e, t) {
|
|
1598
|
-
let n = zt(e), r = Vt(e, t), i = Bt(e, `${r}:assistant`), a = e, o = [];
|
|
1599
|
-
if (n === "RUN_STARTED") o.push({
|
|
1600
|
-
type: "activity",
|
|
1601
|
-
phase: "AG-UI 运行已创建",
|
|
1602
|
-
status: "running",
|
|
1603
|
-
countEvent: !1
|
|
1604
|
-
});
|
|
1605
|
-
else if (n === "TEXT_MESSAGE_START") this.runMessageIds.set(r, i), o.push({
|
|
1606
|
-
type: "assistant_message_created",
|
|
1607
|
-
messageId: i
|
|
1608
|
-
});
|
|
1609
|
-
else if (n === "TEXT_MESSAGE_CONTENT") o.push({
|
|
1610
|
-
type: "text_delta",
|
|
1611
|
-
messageId: this.runMessageIds.get(r) || i,
|
|
1612
|
-
delta: String(a.delta || "")
|
|
1613
|
-
});
|
|
1614
|
-
else if (n === "TEXT_MESSAGE_END") o.push({
|
|
1615
|
-
type: "activity",
|
|
1616
|
-
phase: "生成回复内容",
|
|
1617
|
-
status: "running"
|
|
1618
|
-
});
|
|
1619
|
-
else if (n === "REASONING_MESSAGE_CONTENT") o.push({
|
|
1620
|
-
type: "reasoning_delta",
|
|
1621
|
-
messageId: this.runMessageIds.get(r) || i,
|
|
1622
|
-
delta: String(a.delta || "")
|
|
1623
|
-
});
|
|
1624
|
-
else if (n === "TOOL_CALL_START") {
|
|
1625
|
-
let e = String(a.toolCallId || "tool");
|
|
1626
|
-
this.tools.set(e, {
|
|
1627
|
-
name: String(a.toolCallName || "tool"),
|
|
1628
|
-
args: ""
|
|
1629
|
-
}), o.push({
|
|
1630
|
-
type: "tool_upsert",
|
|
1631
|
-
messageId: this.runMessageIds.get(r) || `${r}:assistant`,
|
|
1632
|
-
name: String(a.toolCallName || "tool"),
|
|
1633
|
-
args: "",
|
|
1634
|
-
status: "running"
|
|
1635
|
-
});
|
|
1636
|
-
} else if (n === "TOOL_CALL_ARGS") {
|
|
1637
|
-
let e = String(a.toolCallId || "tool"), t = this.tools.get(e) || {
|
|
1638
|
-
name: "tool",
|
|
1639
|
-
args: ""
|
|
1640
|
-
};
|
|
1641
|
-
t.args += String(a.delta || ""), this.tools.set(e, t), o.push({
|
|
1642
|
-
type: "tool_upsert",
|
|
1643
|
-
messageId: this.runMessageIds.get(r) || `${r}:assistant`,
|
|
1644
|
-
name: t.name,
|
|
1645
|
-
args: t.args,
|
|
1646
|
-
status: "running"
|
|
1647
|
-
});
|
|
1648
|
-
} else if (n === "TOOL_CALL_RESULT") {
|
|
1649
|
-
let e = String(a.toolCallId || "tool"), t = this.tools.get(e) || {
|
|
1650
|
-
name: "tool",
|
|
1651
|
-
args: ""
|
|
1652
|
-
};
|
|
1653
|
-
o.push({
|
|
1654
|
-
type: "tool_result",
|
|
1655
|
-
messageId: this.runMessageIds.get(r) || `${r}:assistant`,
|
|
1656
|
-
name: t.name,
|
|
1657
|
-
output: String(a.content || "")
|
|
1658
|
-
});
|
|
1659
|
-
} else if (n === "ACTIVITY_SNAPSHOT") {
|
|
1660
|
-
let e = a.content, t = Ht(e), n = String(t.surfaceId || t.surface_id || a.messageId || "default");
|
|
1661
|
-
o.push({
|
|
1662
|
-
type: "agui_activity",
|
|
1663
|
-
messageId: this.runMessageIds.get(r) || i,
|
|
1664
|
-
surfaceId: n,
|
|
1665
|
-
messages: Ut(t.content ?? e)
|
|
1666
|
-
});
|
|
1667
|
-
} else if (n === "RUN_FINISHED") {
|
|
1668
|
-
let e = Ht(a.outcome);
|
|
1669
|
-
if (String(e.type || "").toLowerCase() === "interrupt") {
|
|
1670
|
-
let t = Array.isArray(e.interrupts) ? e.interrupts : [];
|
|
1671
|
-
this.pendingByRun.set(r, t);
|
|
1672
|
-
for (let e of 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);
|
|
1674
|
-
o.push({
|
|
1675
|
-
type: "approval_requested",
|
|
1676
|
-
messageId: this.runMessageIds.get(r) || `${r}:assistant`,
|
|
1677
|
-
approvalRequestId: e.id,
|
|
1678
|
-
protocol: "ag-ui",
|
|
1679
|
-
name: i,
|
|
1680
|
-
args: a,
|
|
1681
|
-
...e.message ? { message: e.message } : {},
|
|
1682
|
-
...t.approval_level ? { approvalLevel: String(t.approval_level) } : {}
|
|
1683
|
-
});
|
|
1684
|
-
}
|
|
1685
|
-
return o.push({
|
|
1686
|
-
type: "activity",
|
|
1687
|
-
phase: "等待人工确认",
|
|
1688
|
-
status: "waiting"
|
|
1689
|
-
}), {
|
|
1690
|
-
events: o,
|
|
1691
|
-
status: "interrupted"
|
|
1692
|
-
};
|
|
1693
|
-
}
|
|
1694
|
-
o.push({
|
|
1695
|
-
type: "terminal",
|
|
1696
|
-
status: "completed"
|
|
1697
|
-
});
|
|
1698
|
-
} else if (n === "RUN_ERROR") return o.push({
|
|
1699
|
-
type: "error",
|
|
1700
|
-
error: /* @__PURE__ */ Error("AG-UI 运行失败")
|
|
1701
|
-
}), {
|
|
1702
|
-
events: o,
|
|
1703
|
-
status: "failed"
|
|
1704
|
-
};
|
|
1705
|
-
return { events: o };
|
|
1706
|
-
}
|
|
1707
|
-
}, Kt = new Set([
|
|
1708
|
-
"completed",
|
|
1709
|
-
"failed",
|
|
1710
|
-
"error",
|
|
1711
|
-
"cancelled",
|
|
1712
|
-
"canceled",
|
|
1713
|
-
"aborted",
|
|
1714
|
-
"interrupted",
|
|
1715
|
-
"resume_failed"
|
|
1716
|
-
]);
|
|
1717
|
-
function qt(e) {
|
|
1718
|
-
if (e.EventType !== "run_status") return null;
|
|
1719
|
-
let t = String(e.Content?.status || "").trim().toLowerCase();
|
|
1720
|
-
return Kt.has(t) ? t : null;
|
|
1721
|
-
}
|
|
1722
|
-
function Jt(e, t) {
|
|
1723
|
-
let n = String(t?.type || e || "").trim();
|
|
1724
|
-
if (n === "response.created") return {
|
|
1725
|
-
phase: "运行已创建",
|
|
1726
|
-
status: "running"
|
|
1727
|
-
};
|
|
1728
|
-
if (n === "response.in_progress") return {
|
|
1729
|
-
phase: "等待运行时输出",
|
|
1730
|
-
status: "waiting"
|
|
1731
|
-
};
|
|
1732
|
-
if (n === "response.output_item.added") {
|
|
1733
|
-
let e = t?.item;
|
|
1734
|
-
return e?.type === "function_call" ? {
|
|
1735
|
-
phase: `调用工具 ${e.name || "tool"}`,
|
|
1736
|
-
status: "running"
|
|
1737
|
-
} : String(e?.type || "").includes("reasoning") ? {
|
|
1738
|
-
phase: "生成思考过程",
|
|
1739
|
-
status: "running"
|
|
1740
|
-
} : {
|
|
1741
|
-
phase: "生成回复内容",
|
|
1742
|
-
status: "running"
|
|
1743
|
-
};
|
|
1744
|
-
}
|
|
1745
|
-
return n.includes("reasoning") ? {
|
|
1746
|
-
phase: "生成思考过程",
|
|
1747
|
-
status: "running"
|
|
1748
|
-
} : n.includes("function_call") || n === "response.tool_call" ? {
|
|
1749
|
-
phase: "调用工具",
|
|
1750
|
-
status: "running"
|
|
1751
|
-
} : n.includes("tool_result") ? {
|
|
1752
|
-
phase: "收到工具结果",
|
|
1753
|
-
status: "running"
|
|
1754
|
-
} : n.includes("output_text") || n.includes("content_part") ? {
|
|
1755
|
-
phase: "生成回复内容",
|
|
1756
|
-
status: "running"
|
|
1757
|
-
} : n === "response.completed" ? {
|
|
1758
|
-
phase: "运行完成",
|
|
1759
|
-
status: "completed"
|
|
1760
|
-
} : n === "response.failed" ? {
|
|
1761
|
-
phase: "运行失败",
|
|
1762
|
-
status: "failed"
|
|
1763
|
-
} : n === "response.incomplete" ? {
|
|
1764
|
-
phase: "运行中断",
|
|
1765
|
-
status: "failed"
|
|
1766
|
-
} : null;
|
|
1767
|
-
}
|
|
1768
|
-
function Yt() {
|
|
1769
|
-
let e = globalThis.crypto;
|
|
1770
|
-
return e && typeof e.randomUUID == "function" ? `run_${e.randomUUID()}` : `run_${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
1771
|
-
}
|
|
1772
|
-
var Xt = {
|
|
1773
|
-
idle: [
|
|
1774
|
-
"creating-session",
|
|
1775
|
-
"uploading-files",
|
|
1776
|
-
"connecting",
|
|
1777
|
-
"error"
|
|
1778
|
-
],
|
|
1779
|
-
"creating-session": [
|
|
1780
|
-
"uploading-files",
|
|
1781
|
-
"connecting",
|
|
1782
|
-
"error",
|
|
1783
|
-
"idle"
|
|
1784
|
-
],
|
|
1785
|
-
"uploading-files": [
|
|
1786
|
-
"connecting",
|
|
1787
|
-
"error",
|
|
1788
|
-
"idle"
|
|
1789
|
-
],
|
|
1790
|
-
connecting: [
|
|
1791
|
-
"streaming",
|
|
1792
|
-
"error",
|
|
1793
|
-
"idle"
|
|
1794
|
-
],
|
|
1795
|
-
streaming: [
|
|
1796
|
-
"completing",
|
|
1797
|
-
"stopping",
|
|
1798
|
-
"recovering",
|
|
1799
|
-
"error"
|
|
1800
|
-
],
|
|
1801
|
-
stopping: ["cancelled", "idle"],
|
|
1802
|
-
completing: ["idle"],
|
|
1803
|
-
recovering: [
|
|
1804
|
-
"streaming",
|
|
1805
|
-
"error",
|
|
1806
|
-
"idle"
|
|
1807
|
-
],
|
|
1808
|
-
error: ["connecting", "idle"],
|
|
1809
|
-
cancelled: ["idle"]
|
|
1810
|
-
}, Zt = class {
|
|
1811
|
-
_stage = "idle";
|
|
1812
|
-
listeners = /* @__PURE__ */ new Set();
|
|
1813
|
-
abortController = null;
|
|
1814
|
-
activeCompactionId = null;
|
|
1815
|
-
activeSessionId = null;
|
|
1816
|
-
invocationId = "";
|
|
1817
|
-
operationEpoch = 0;
|
|
1818
|
-
lastSeqId = 0;
|
|
1819
|
-
pendingConfig = null;
|
|
1820
|
-
projection;
|
|
1821
|
-
aguiClient = null;
|
|
1822
|
-
aguiThreadSessionId = null;
|
|
1823
|
-
api;
|
|
1824
|
-
controlStateValue = { phase: "idle" };
|
|
1825
|
-
lastControlCommand = null;
|
|
1826
|
-
config = {
|
|
1827
|
-
agentId: "default-agent",
|
|
1828
|
-
apiFormats: ["responses"],
|
|
1829
|
-
agentFramework: "",
|
|
1830
|
-
selectedModel: "",
|
|
1831
|
-
thinkingMode: "auto"
|
|
1832
|
-
};
|
|
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);
|
|
1856
|
-
}
|
|
1857
|
-
get stage() {
|
|
1858
|
-
return this._stage;
|
|
1859
|
-
}
|
|
1860
|
-
get controlState() {
|
|
1861
|
-
return this.controlStateValue;
|
|
1862
|
-
}
|
|
1863
|
-
async submitControl(e) {
|
|
1864
|
-
this.lastControlCommand = e;
|
|
1865
|
-
let t;
|
|
1866
|
-
try {
|
|
1867
|
-
t = Oe(await this.api.submitControl(e));
|
|
1868
|
-
} catch (e) {
|
|
1869
|
-
if (e instanceof U) return this.controlStateValue = {
|
|
1870
|
-
phase: "contract_mismatch",
|
|
1871
|
-
error: null,
|
|
1872
|
-
receipt: null
|
|
1873
|
-
}, this.emit({
|
|
1874
|
-
type: "system_message",
|
|
1875
|
-
content: "【系统提示】控制指令响应不符合 agent-kernel/v1 合同,已停止变更本地状态。"
|
|
1876
|
-
}), this.controlStateValue;
|
|
1877
|
-
throw e;
|
|
1878
|
-
}
|
|
1879
|
-
return this.controlStateValue = this.controlStateFor(t, e), t.status === "accepted" || t.status === "duplicate" ? this.emit({
|
|
1880
|
-
type: "activity",
|
|
1881
|
-
phase: "指令已入队,等待运行时处理",
|
|
1882
|
-
status: "waiting",
|
|
1883
|
-
countEvent: !1
|
|
1884
|
-
}) : t.status === "queue_full" ? this.emit({
|
|
1885
|
-
type: "system_message",
|
|
1886
|
-
content: "【系统提示】指令队列已满,可点击重试;重试将复用同一幂等键。"
|
|
1887
|
-
}) : t.status === "unsupported" ? this.emit({
|
|
1888
|
-
type: "system_message",
|
|
1889
|
-
content: `【系统提示】运行时不支持该操作:${t.error?.message || ""}`
|
|
1890
|
-
}) : t.status === "persistence_uncertain" ? this.emit({
|
|
1891
|
-
type: "system_message",
|
|
1892
|
-
content: "【系统提示】指令提交结果待确认,正在查询状态…"
|
|
1893
|
-
}) : t.status === "rejected" && this.emit({
|
|
1894
|
-
type: "system_message",
|
|
1895
|
-
content: `【系统提示】指令被拒绝:${t.error?.message || ""}`
|
|
1896
|
-
}), this.controlStateValue;
|
|
1897
|
-
}
|
|
1898
|
-
controlStateFor(e, t) {
|
|
1899
|
-
switch (e.status) {
|
|
1900
|
-
case "accepted":
|
|
1901
|
-
case "duplicate": return {
|
|
1902
|
-
phase: "queued",
|
|
1903
|
-
receipt: e,
|
|
1904
|
-
error: null
|
|
1905
|
-
};
|
|
1906
|
-
case "queue_full": return {
|
|
1907
|
-
phase: "retryable",
|
|
1908
|
-
retryKey: t.idempotency_key,
|
|
1909
|
-
receipt: e,
|
|
1910
|
-
error: e.error
|
|
1911
|
-
};
|
|
1912
|
-
case "unsupported": return {
|
|
1913
|
-
phase: "unsupported",
|
|
1914
|
-
receipt: e,
|
|
1915
|
-
error: e.error
|
|
1916
|
-
};
|
|
1917
|
-
case "persistence_uncertain": return {
|
|
1918
|
-
phase: "confirming",
|
|
1919
|
-
retryKey: t.idempotency_key,
|
|
1920
|
-
receipt: e,
|
|
1921
|
-
error: e.error
|
|
1922
|
-
};
|
|
1923
|
-
default: return {
|
|
1924
|
-
phase: "rejected",
|
|
1925
|
-
receipt: e,
|
|
1926
|
-
error: e.error
|
|
1927
|
-
};
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
async retryControl() {
|
|
1931
|
-
let e = this.lastControlCommand;
|
|
1932
|
-
if (!e || this.controlStateValue.phase !== "retryable" && this.controlStateValue.phase !== "confirming") return this.controlStateValue;
|
|
1933
|
-
if (this.controlStateValue.phase === "confirming") try {
|
|
1934
|
-
await this.api.getAgentStatus();
|
|
1935
|
-
} catch (e) {
|
|
1936
|
-
console.warn("[RunEngine] status query after persistence_uncertain failed:", e);
|
|
1937
|
-
}
|
|
1938
|
-
return this.submitControl(e);
|
|
1939
|
-
}
|
|
1940
|
-
updateConfig(e) {
|
|
1941
|
-
let t = {
|
|
1942
|
-
...e,
|
|
1943
|
-
apiFormats: [...e.apiFormats]
|
|
1944
|
-
};
|
|
1945
|
-
this._stage === "idle" ? this.config = t : this.pendingConfig = t;
|
|
1946
|
-
}
|
|
1947
|
-
emit(e) {
|
|
1948
|
-
e.type === "stream_event" && typeof e.event.SeqId == "number" && this.recordCursor(e.event.SeqId);
|
|
1949
|
-
let t = "sessionId" in e ? e : {
|
|
1950
|
-
...e,
|
|
1951
|
-
sessionId: this.activeSessionId
|
|
1952
|
-
};
|
|
1953
|
-
for (let e of this.listeners) e(t);
|
|
1954
|
-
}
|
|
1955
|
-
getAguiClient(e) {
|
|
1956
|
-
let t = this.config.hostedChatTransport;
|
|
1957
|
-
return t?.Protocol !== "ag-ui" || !t.Endpoint ? null : ((!this.aguiClient || this.aguiThreadSessionId !== e) && (this.aguiClient = new Gt({
|
|
1958
|
-
url: t.Endpoint,
|
|
1959
|
-
agentId: this.config.agentId,
|
|
1960
|
-
threadId: e,
|
|
1961
|
-
onEvent: (e) => this.emit(e)
|
|
1962
|
-
}), this.aguiThreadSessionId = e), this.aguiClient);
|
|
1963
|
-
}
|
|
1964
|
-
setStage(e) {
|
|
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({
|
|
1968
|
-
type: "stage_changed",
|
|
1969
|
-
stage: e
|
|
1970
|
-
});
|
|
1971
|
-
}
|
|
1972
|
-
subscribe(e) {
|
|
1973
|
-
return this.listeners.add(e), () => {
|
|
1974
|
-
this.listeners.delete(e);
|
|
1975
|
-
};
|
|
1976
|
-
}
|
|
1977
|
-
start(e) {
|
|
1978
|
-
if (this._stage !== "idle") return !1;
|
|
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;
|
|
1982
|
-
return (async () => {
|
|
1983
|
-
let r = e.sessionId || null, i = "unknown";
|
|
1984
|
-
try {
|
|
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);
|
|
1992
|
-
this.setStage("connecting"), this.emit({
|
|
1993
|
-
type: "activity",
|
|
1994
|
-
phase: "连接会话运行时",
|
|
1995
|
-
status: "connecting",
|
|
1996
|
-
countEvent: !1
|
|
1997
|
-
}), this.setStage("streaming"), this.emit({
|
|
1998
|
-
type: "activity",
|
|
1999
|
-
phase: "等待会话输出",
|
|
2000
|
-
status: "waiting",
|
|
2001
|
-
countEvent: !1
|
|
2002
|
-
});
|
|
2003
|
-
let s = await this.config.conversationClient.streamTurn({
|
|
2004
|
-
bootstrap: o,
|
|
2005
|
-
input: n,
|
|
2006
|
-
signal: this.abortController?.signal,
|
|
2007
|
-
onUpdate: (t) => {
|
|
2008
|
-
t.runId && (this.publishInvocation(t.runId), e.onInvocationCreated?.(t.runId)), this.emit({
|
|
2009
|
-
type: "conversation_snapshot",
|
|
2010
|
-
result: t,
|
|
2011
|
-
sessionId: r,
|
|
2012
|
-
optimisticMessageId: e.optimisticMessageId
|
|
2013
|
-
});
|
|
2014
|
-
}
|
|
2015
|
-
});
|
|
2016
|
-
if (this.operationEpoch !== t) return;
|
|
2017
|
-
if (s.presentation.terminalStatus === "failed") {
|
|
2018
|
-
i = "failed", this.setStage("error"), this.emit({
|
|
2019
|
-
type: "activity",
|
|
2020
|
-
phase: "运行失败",
|
|
2021
|
-
status: "failed",
|
|
2022
|
-
countEvent: !1
|
|
2023
|
-
});
|
|
2024
|
-
return;
|
|
2025
|
-
}
|
|
2026
|
-
this.setStage("completing"), i = "completed", this.emit({
|
|
2027
|
-
type: "activity",
|
|
2028
|
-
phase: "运行完成",
|
|
2029
|
-
status: "completed",
|
|
2030
|
-
countEvent: !1
|
|
2031
|
-
}), this.emit({
|
|
2032
|
-
type: "stream_ended",
|
|
2033
|
-
sessionId: r,
|
|
2034
|
-
runId: s.runId
|
|
2035
|
-
});
|
|
2036
|
-
return;
|
|
2037
|
-
}
|
|
2038
|
-
let s = await this.uploadFiles(e, n);
|
|
2039
|
-
this.setStage("connecting"), this.emit({
|
|
2040
|
-
type: "activity",
|
|
2041
|
-
phase: "连接运行时",
|
|
2042
|
-
status: "connecting",
|
|
2043
|
-
countEvent: !1
|
|
2044
|
-
});
|
|
2045
|
-
let c = n ? "responses" : Lt({
|
|
2046
|
-
agentFramework: this.config.agentFramework,
|
|
2047
|
-
apiFormats: this.config.apiFormats
|
|
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) {
|
|
2050
|
-
this.setStage("streaming"), this.emit({
|
|
2051
|
-
type: "activity",
|
|
2052
|
-
phase: "等待 AG-UI 输出",
|
|
2053
|
-
status: "waiting",
|
|
2054
|
-
countEvent: !1
|
|
2055
|
-
});
|
|
2056
|
-
let t = await f.run(e.text, a, this.abortController?.signal);
|
|
2057
|
-
if (t.status === "interrupted") {
|
|
2058
|
-
i = "cancelled", this.setStage("completing"), this.emit({ type: "stream_ended" });
|
|
2059
|
-
return;
|
|
2060
|
-
}
|
|
2061
|
-
if (t.status !== "completed") {
|
|
2062
|
-
i = "failed", this.setStage("error"), this.emit({
|
|
2063
|
-
type: "activity",
|
|
2064
|
-
phase: "AG-UI 运行失败",
|
|
2065
|
-
status: "failed",
|
|
2066
|
-
countEvent: !1
|
|
2067
|
-
});
|
|
2068
|
-
return;
|
|
2069
|
-
}
|
|
2070
|
-
this.setStage("completing"), i = "completed", this.emit({
|
|
2071
|
-
type: "activity",
|
|
2072
|
-
phase: "运行完成",
|
|
2073
|
-
status: "completed",
|
|
2074
|
-
countEvent: !1
|
|
2075
|
-
}), this.emit({ type: "stream_ended" });
|
|
2076
|
-
return;
|
|
2077
|
-
}
|
|
2078
|
-
let p = this.buildRequestBody(r, c, n, e, s, a), m = await this.api.runAgent(p, { signal: this.abortController?.signal });
|
|
2079
|
-
this.setStage("streaming"), this.emit({
|
|
2080
|
-
type: "activity",
|
|
2081
|
-
phase: "等待首个输出",
|
|
2082
|
-
status: "waiting",
|
|
2083
|
-
countEvent: !1
|
|
2084
|
-
});
|
|
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({
|
|
2089
|
-
type: "activity",
|
|
2090
|
-
phase: "运行已取消",
|
|
2091
|
-
status: "stopped",
|
|
2092
|
-
countEvent: !1
|
|
2093
|
-
}), this.setStage("cancelled");
|
|
2094
|
-
return;
|
|
2095
|
-
}
|
|
2096
|
-
if (_.terminalStatus && _.terminalStatus !== "completed") {
|
|
2097
|
-
i = "failed", this.setStage("error"), this.emit({
|
|
2098
|
-
type: "activity",
|
|
2099
|
-
phase: _.terminalStatus === "incomplete" ? "运行中断" : "运行失败",
|
|
2100
|
-
status: "failed",
|
|
2101
|
-
countEvent: !1
|
|
2102
|
-
});
|
|
2103
|
-
return;
|
|
2104
|
-
}
|
|
2105
|
-
this.setStage("completing"), i = "completed", this.emit({
|
|
2106
|
-
type: "activity",
|
|
2107
|
-
phase: "运行完成",
|
|
2108
|
-
status: "completed",
|
|
2109
|
-
countEvent: !1
|
|
2110
|
-
}), this.emit({ type: "stream_ended" });
|
|
2111
|
-
} catch (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
|
|
2121
|
-
});
|
|
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
|
-
}
|
|
2146
|
-
} finally {
|
|
2147
|
-
this.operationEpoch === t && (c.getState().setSessionStreaming(this.streamingKey, !1), this.setStage("idle"), this.activeCompactionId = null, this.activeSessionId = null, e.onSettled?.(r, i));
|
|
2148
|
-
}
|
|
2149
|
-
})(), !0;
|
|
2150
|
-
}
|
|
2151
|
-
stop() {
|
|
2152
|
-
if (this._stage === "idle") return;
|
|
2153
|
-
this.setStage("stopping");
|
|
2154
|
-
let e = this.invocationId;
|
|
2155
|
-
e && this.activeSessionId && this.api.cancelRun(this.config.agentId, this.activeSessionId, e).catch((e) => {
|
|
2156
|
-
console.warn("[RunEngine] cancelRun on stop failed:", e);
|
|
2157
|
-
}), this.abortController?.abort(), this.aguiClient?.abort(), this.stopActivity(e ? "已向运行时发送取消请求;如果当前框架只支持协作式取消,后台可能会在下一个安全点停止。" : void 0), this.publishInvocation(""), this.setStage("cancelled"), this.emit({
|
|
2158
|
-
type: "system_message",
|
|
2159
|
-
content: e ? "已请求取消本次运行。" : "已停止接收本次输出;如果运行时不支持取消,后台执行可能仍会继续。"
|
|
2160
|
-
});
|
|
2161
|
-
}
|
|
2162
|
-
disconnect() {
|
|
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);
|
|
2164
|
-
}
|
|
2165
|
-
async cancelRemote(e) {
|
|
2166
|
-
try {
|
|
2167
|
-
this.activeSessionId && await this.api.cancelRun(this.config.agentId, this.activeSessionId, e);
|
|
2168
|
-
} catch (e) {
|
|
2169
|
-
console.warn("[RunEngine] cancelRemote failed:", e);
|
|
2170
|
-
}
|
|
2171
|
-
this.stop();
|
|
2172
|
-
}
|
|
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({
|
|
2175
|
-
type: "activity",
|
|
2176
|
-
phase: "恢复运行事件订阅",
|
|
2177
|
-
status: "connecting",
|
|
2178
|
-
countEvent: !1
|
|
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);
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
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
|
-
}
|
|
2250
|
-
}
|
|
2251
|
-
resumeCheckpoint(e) {
|
|
2252
|
-
if (this._stage !== "idle") return !1;
|
|
2253
|
-
let t = ++this.operationEpoch;
|
|
2254
|
-
this.abortController = new AbortController(), this.activeSessionId = e.sessionId;
|
|
2255
|
-
let n = Yt();
|
|
2256
|
-
return this.publishInvocation(n), (async () => {
|
|
2257
|
-
let r = "unknown";
|
|
2258
|
-
try {
|
|
2259
|
-
if (this.setStage("connecting"), this.emit({
|
|
2260
|
-
type: "activity",
|
|
2261
|
-
source: "restore",
|
|
2262
|
-
phase: "从 checkpoint 恢复运行",
|
|
2263
|
-
status: "connecting",
|
|
2264
|
-
countEvent: !1
|
|
2265
|
-
}), this.config.checkpointResumePreviewEnabled) try {
|
|
2266
|
-
let t = (await this.api.previewCheckpointResume({
|
|
2267
|
-
agentId: this.config.agentId,
|
|
2268
|
-
sessionId: e.sessionId,
|
|
2269
|
-
runId: e.runId,
|
|
2270
|
-
checkpointId: e.checkpointId
|
|
2271
|
-
}, { signal: this.abortController?.signal })).Preview?.Risk?.Level || "unknown";
|
|
2272
|
-
this.emit({
|
|
2273
|
-
type: "activity",
|
|
2274
|
-
source: "restore",
|
|
2275
|
-
phase: `恢复预览完成:${String(t)} 风险`,
|
|
2276
|
-
status: "waiting",
|
|
2277
|
-
countEvent: !1
|
|
2278
|
-
});
|
|
2279
|
-
} catch (e) {
|
|
2280
|
-
console.warn("[RunEngine] checkpoint resume preview failed:", e);
|
|
2281
|
-
}
|
|
2282
|
-
let t = await this.api.resumeRun({
|
|
2283
|
-
agentId: this.config.agentId,
|
|
2284
|
-
sessionId: e.sessionId,
|
|
2285
|
-
runId: e.runId,
|
|
2286
|
-
checkpointId: e.checkpointId,
|
|
2287
|
-
resumeAttemptId: e.resumeAttemptId,
|
|
2288
|
-
invocationId: n
|
|
2289
|
-
}, { signal: this.abortController?.signal }), i = kt("responses"), a = i.createState();
|
|
2290
|
-
this.setStage("streaming"), this.emit({
|
|
2291
|
-
type: "activity",
|
|
2292
|
-
source: "restore",
|
|
2293
|
-
phase: "等待恢复输出",
|
|
2294
|
-
status: "waiting",
|
|
2295
|
-
countEvent: !1
|
|
2296
|
-
});
|
|
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({
|
|
2301
|
-
type: "activity",
|
|
2302
|
-
source: "restore",
|
|
2303
|
-
phase: "恢复已取消",
|
|
2304
|
-
status: "stopped",
|
|
2305
|
-
countEvent: !1
|
|
2306
|
-
}), this.setStage("cancelled");
|
|
2307
|
-
return;
|
|
2308
|
-
}
|
|
2309
|
-
this.setStage("error"), r = "failed", this.emit({
|
|
2310
|
-
type: "activity",
|
|
2311
|
-
source: "restore",
|
|
2312
|
-
phase: s.terminalStatus === "incomplete" ? "恢复中断" : "恢复失败",
|
|
2313
|
-
status: "failed",
|
|
2314
|
-
countEvent: !1
|
|
2315
|
-
});
|
|
2316
|
-
return;
|
|
2317
|
-
}
|
|
2318
|
-
this.setStage("completing"), r = "completed", this.emit({
|
|
2319
|
-
type: "activity",
|
|
2320
|
-
source: "restore",
|
|
2321
|
-
phase: "恢复完成",
|
|
2322
|
-
status: "completed",
|
|
2323
|
-
countEvent: !1
|
|
2324
|
-
}), this.emit({ type: "stream_ended" });
|
|
2325
|
-
} catch (e) {
|
|
2326
|
-
e instanceof DOMException && e.name === "AbortError" ? r = "cancelled" : (r = "failed", console.error("[RunEngine] resumeCheckpoint() error:", e), this.setStage("error"), this.emit({
|
|
2327
|
-
type: "error",
|
|
2328
|
-
error: e instanceof Error ? e : Error(String(e))
|
|
2329
|
-
}));
|
|
2330
|
-
} finally {
|
|
2331
|
-
this.operationEpoch === t && (c.getState().setSessionStreaming(e.sessionId, !1), this.publishInvocation(""), this.setStage("idle"), this.activeSessionId = null, e.onSettled?.(e.sessionId, r));
|
|
2332
|
-
}
|
|
2333
|
-
})(), !0;
|
|
2334
|
-
}
|
|
2335
|
-
resumeAguiInterrupt(e) {
|
|
2336
|
-
if (this._stage !== "idle") return !1;
|
|
2337
|
-
let t = e.sessionId || this.aguiThreadSessionId;
|
|
2338
|
-
if (!t) return !1;
|
|
2339
|
-
let n = this.getAguiClient(t);
|
|
2340
|
-
if (!n) return !1;
|
|
2341
|
-
let r = ++this.operationEpoch;
|
|
2342
|
-
this.activeSessionId = t;
|
|
2343
|
-
let i = Yt();
|
|
2344
|
-
return this.publishInvocation(i), this.setStage("connecting"), this.emit({
|
|
2345
|
-
type: "activity",
|
|
2346
|
-
phase: "提交人工确认",
|
|
2347
|
-
status: "connecting",
|
|
2348
|
-
countEvent: !1
|
|
2349
|
-
}), (async () => {
|
|
2350
|
-
let a = "unknown";
|
|
2351
|
-
try {
|
|
2352
|
-
this.setStage("streaming");
|
|
2353
|
-
let t = await n.resume(i, {
|
|
2354
|
-
interruptId: e.interruptId,
|
|
2355
|
-
status: e.status,
|
|
2356
|
-
payload: e.payload
|
|
2357
|
-
}), r = e.payload && typeof e.payload == "object" ? e.payload : {}, o = String(r.decision || r.type || "").toLowerCase();
|
|
2358
|
-
if (this.emit({
|
|
2359
|
-
type: "approval_resolved",
|
|
2360
|
-
approvalRequestId: e.interruptId,
|
|
2361
|
-
decision: e.status === "cancelled" ? "cancelled" : o === "reject" || o === "rejected" ? "rejected" : "approved"
|
|
2362
|
-
}), t.status === "interrupted") {
|
|
2363
|
-
a = "cancelled", this.setStage("completing"), this.emit({ type: "stream_ended" });
|
|
2364
|
-
return;
|
|
2365
|
-
}
|
|
2366
|
-
if (t.status !== "completed") {
|
|
2367
|
-
a = "failed", this.setStage("error"), this.emit({
|
|
2368
|
-
type: "activity",
|
|
2369
|
-
phase: "人工确认恢复失败",
|
|
2370
|
-
status: "failed",
|
|
2371
|
-
countEvent: !1
|
|
2372
|
-
});
|
|
2373
|
-
return;
|
|
2374
|
-
}
|
|
2375
|
-
this.setStage("completing"), a = "completed", this.emit({
|
|
2376
|
-
type: "activity",
|
|
2377
|
-
phase: "运行完成",
|
|
2378
|
-
status: "completed",
|
|
2379
|
-
countEvent: !1
|
|
2380
|
-
}), this.emit({ type: "stream_ended" });
|
|
2381
|
-
} catch (e) {
|
|
2382
|
-
a = e instanceof DOMException && e.name === "AbortError" ? "cancelled" : "failed", this.setStage("error"), this.emit({
|
|
2383
|
-
type: "error",
|
|
2384
|
-
error: e instanceof Error ? e : Error(String(e))
|
|
2385
|
-
});
|
|
2386
|
-
} finally {
|
|
2387
|
-
this.operationEpoch === r && (this.publishInvocation(""), this.setStage("idle"), this.activeSessionId = null, e.onSettled?.(t, a));
|
|
2388
|
-
}
|
|
2389
|
-
})(), !0;
|
|
2390
|
-
}
|
|
2391
|
-
async createSession(e) {
|
|
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;
|
|
2397
|
-
}
|
|
2398
|
-
async getConversationBootstrap(e) {
|
|
2399
|
-
let t = this.config.conversationClient;
|
|
2400
|
-
if (!t) return null;
|
|
2401
|
-
try {
|
|
2402
|
-
return await t.getSurface(this.config.agentId, e, { signal: this.abortController?.signal });
|
|
2403
|
-
} catch (e) {
|
|
2404
|
-
if (e instanceof j && e.code === "conversation_http_error" && e.status === 404) return null;
|
|
2405
|
-
throw e;
|
|
2406
|
-
}
|
|
2407
|
-
}
|
|
2408
|
-
async buildCanonicalConversationInput(e, t, n, r) {
|
|
2409
|
-
let i = [], a = r.text.trim();
|
|
2410
|
-
a && i.push({
|
|
2411
|
-
kind: "text",
|
|
2412
|
-
text: a
|
|
2413
|
-
});
|
|
2414
|
-
for (let t of r.attachments) {
|
|
2415
|
-
let n = t.type.startsWith("image/") ? "attachment.image" : "attachment.file";
|
|
2416
|
-
if (!A(e.surface, n)) throw new j("conversation_input_unsupported", "Conversation attachment is not declared by the active surface.", { capability: n });
|
|
2417
|
-
}
|
|
2418
|
-
r.attachments.length > 0 && i.push(...await this.uploadCanonicalAttachments(r.attachments));
|
|
2419
|
-
let o = Pt(this.config.thinkingMode), s = k({
|
|
2420
|
-
inputId: `input:${n}`,
|
|
2421
|
-
sessionId: t,
|
|
2422
|
-
idempotencyKey: `conversation:${n}`,
|
|
2423
|
-
parts: i,
|
|
2424
|
-
...this.config.selectedModel && A(e.surface, "model.select") ? { modelRef: this.config.selectedModel } : {},
|
|
2425
|
-
...o !== "auto" && A(e.surface, "reasoning.effort") ? { reasoning: o } : {},
|
|
2426
|
-
extensions: {
|
|
2427
|
-
...this.config.permissionMode && A(e.surface, "approval") ? { "ksadk.approval": this.config.permissionMode } : {},
|
|
2428
|
-
...r.executionMode === "plan" ? { "ksadk.collaboration": "plan" } : {},
|
|
2429
|
-
...r.executionMode === "goal" && a ? { "ksadk.goal": a } : {}
|
|
2430
|
-
}
|
|
2431
|
-
});
|
|
2432
|
-
return O(e.surface, s);
|
|
2433
|
-
}
|
|
2434
|
-
async uploadCanonicalAttachments(e) {
|
|
2435
|
-
this.setStage("uploading-files");
|
|
2436
|
-
let t = [];
|
|
2437
|
-
for (let n of e) {
|
|
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" });
|
|
2439
|
-
let e = new FormData();
|
|
2440
|
-
e.append("file", n), e.append("AgentId", this.config.agentId);
|
|
2441
|
-
let r;
|
|
2442
|
-
try {
|
|
2443
|
-
r = await this.api.uploadFile(e, { signal: this.abortController?.signal });
|
|
2444
|
-
} catch (e) {
|
|
2445
|
-
throw new j("conversation_http_error", "Conversation attachment upload failed.", { cause: e });
|
|
2446
|
-
}
|
|
2447
|
-
let i = r?.FileData?.fileUri;
|
|
2448
|
-
if (!i) throw new j("conversation_contract_mismatch", "Conversation attachment upload did not return an attachment reference.");
|
|
2449
|
-
t.push({
|
|
2450
|
-
kind: "attachment",
|
|
2451
|
-
attachmentRef: i,
|
|
2452
|
-
mediaType: r.FileData.mimeType || n.type || "application/octet-stream",
|
|
2453
|
-
name: r.FileData.displayName || n.name
|
|
2454
|
-
});
|
|
2455
|
-
}
|
|
2456
|
-
return t;
|
|
2457
|
-
}
|
|
2458
|
-
async uploadFiles(e, t) {
|
|
2459
|
-
let n = [];
|
|
2460
|
-
if (t || e.attachments.length === 0) return n;
|
|
2461
|
-
this.setStage("uploading-files");
|
|
2462
|
-
for (let t of e.attachments) {
|
|
2463
|
-
if (t.size > 100 * 1024 * 1024) {
|
|
2464
|
-
this.emit({
|
|
2465
|
-
type: "system_message",
|
|
2466
|
-
content: `【系统提示】文件 ${t.name} 超过 100MB 限制,未发送。`
|
|
2467
|
-
});
|
|
2468
|
-
continue;
|
|
2469
|
-
}
|
|
2470
|
-
if (t.type.startsWith("image/")) {
|
|
2471
|
-
try {
|
|
2472
|
-
n.push({
|
|
2473
|
-
type: "input_image",
|
|
2474
|
-
image_url: await this.imageFileToDataUrl(t)
|
|
2475
|
-
});
|
|
2476
|
-
} catch (e) {
|
|
2477
|
-
this.emit({
|
|
2478
|
-
type: "system_message",
|
|
2479
|
-
content: `【系统提示】图片 ${t.name} 读取失败,原因: ${Mt(e)}`
|
|
2480
|
-
});
|
|
2481
|
-
}
|
|
2482
|
-
continue;
|
|
2483
|
-
}
|
|
2484
|
-
let e = new FormData();
|
|
2485
|
-
e.append("file", t), e.append("AgentId", this.config.agentId);
|
|
2486
|
-
try {
|
|
2487
|
-
let r = await this.api.uploadFile(e, { signal: this.abortController?.signal });
|
|
2488
|
-
r?.FileData?.fileUri && n.push({
|
|
2489
|
-
type: "input_file",
|
|
2490
|
-
filename: r.FileData.displayName || t.name,
|
|
2491
|
-
file_url: r.FileData.fileUri
|
|
2492
|
-
});
|
|
2493
|
-
} catch (e) {
|
|
2494
|
-
this.emit({
|
|
2495
|
-
type: "system_message",
|
|
2496
|
-
content: `【系统提示】文件 ${t.name} 上传失败,原因: ${Mt(e)}`
|
|
2497
|
-
});
|
|
2498
|
-
}
|
|
2499
|
-
}
|
|
2500
|
-
return n;
|
|
2501
|
-
}
|
|
2502
|
-
async imageFileToDataUrl(e) {
|
|
2503
|
-
let t = new Uint8Array(await e.arrayBuffer()), n = "", r = 32768;
|
|
2504
|
-
for (let e = 0; e < t.length; e += r) n += String.fromCharCode(...t.subarray(e, e + r));
|
|
2505
|
-
return `data:${e.type || "application/octet-stream"};base64,${btoa(n)}`;
|
|
2506
|
-
}
|
|
2507
|
-
buildRequestBody(e, t, n, r, i, a) {
|
|
2508
|
-
let o = this.buildExecutionMetadata(r), s = {
|
|
2509
|
-
AgentId: this.config.agentId,
|
|
2510
|
-
SessionId: e,
|
|
2511
|
-
InvocationId: a,
|
|
2512
|
-
Stream: !0,
|
|
2513
|
-
ApiFormat: t,
|
|
2514
|
-
Model: this.config.selectedModel || void 0,
|
|
2515
|
-
ModelMetadata: this.config.selectedModelMetadata || void 0,
|
|
2516
|
-
ModelOptions: Ft(Pt(this.config.thinkingMode)),
|
|
2517
|
-
Metadata: { agentengine: {
|
|
2518
|
-
tool_approval_mode: this.config.permissionMode || "risk",
|
|
2519
|
-
...o
|
|
2520
|
-
} }
|
|
2521
|
-
};
|
|
2522
|
-
if (n) s.ResponsesInput = r.responsesInput, s.PreviousResponseId = r.previousResponseId;
|
|
2523
|
-
else {
|
|
2524
|
-
let e = [{
|
|
2525
|
-
type: "input_text",
|
|
2526
|
-
text: r.text.trim()
|
|
2527
|
-
}];
|
|
2528
|
-
e.push(...i), t === "responses" && (s.ResponsesInput = [{
|
|
2529
|
-
role: "user",
|
|
2530
|
-
content: e
|
|
2531
|
-
}]), s.Messages = [{
|
|
2532
|
-
role: "user",
|
|
2533
|
-
content: e
|
|
2534
|
-
}];
|
|
2535
|
-
}
|
|
2536
|
-
return s;
|
|
2537
|
-
}
|
|
2538
|
-
buildExecutionMetadata(e) {
|
|
2539
|
-
let t = e.executionMode;
|
|
2540
|
-
if (!t) return {};
|
|
2541
|
-
let n = this.config.runtimeCapabilityMatrix?.[t];
|
|
2542
|
-
if (!n?.supported || n.mode === "unavailable") return {};
|
|
2543
|
-
if (t === "plan") return { collaboration_mode: "plan" };
|
|
2544
|
-
if (t === "goal") {
|
|
2545
|
-
let t = e.text.trim();
|
|
2546
|
-
return t ? {
|
|
2547
|
-
collaboration_mode: "default",
|
|
2548
|
-
goal_objective: t
|
|
2549
|
-
} : {};
|
|
2550
|
-
}
|
|
2551
|
-
return {};
|
|
2552
|
-
}
|
|
2553
|
-
async consumeKernelRunEvents(e, t, n, r) {
|
|
2554
|
-
if (n.status === "rejected" || n.status === "unsupported") return this.setStage("error"), this.emit({
|
|
2555
|
-
type: "error",
|
|
2556
|
-
error: Error(n.error?.message || `运行提交被拒绝(${n.status})`)
|
|
2557
|
-
}), { terminalStatus: "failed" };
|
|
2558
|
-
if (n.status === "queue_full") return this.setStage("error"), this.emit({
|
|
2559
|
-
type: "rate_limited",
|
|
2560
|
-
message: "运行队列已满,请稍后重试"
|
|
2561
|
-
}), { terminalStatus: "failed" };
|
|
2562
|
-
n.status === "persistence_uncertain" && this.emit({
|
|
2563
|
-
type: "system_message",
|
|
2564
|
-
content: "提交结果未知,正在从事件流确认运行状态…"
|
|
2565
|
-
}), this.emit({
|
|
2566
|
-
type: "assistant_message_created",
|
|
2567
|
-
messageId: r,
|
|
2568
|
-
invocationId: t
|
|
2569
|
-
}), this.emit({
|
|
2570
|
-
type: "activity",
|
|
2571
|
-
phase: "已提交运行,订阅事件流",
|
|
2572
|
-
status: "running",
|
|
2573
|
-
countEvent: !1
|
|
2574
|
-
});
|
|
2575
|
-
let i = new F(e), a, o = 0;
|
|
2576
|
-
for (; a === void 0 && o < 6;) try {
|
|
2577
|
-
let t = this.lastSeqId, n = await this.api.subscribeSessionEvents(e, t, { signal: this.abortController?.signal });
|
|
2578
|
-
o = 0;
|
|
2579
|
-
let r = n.getReader(), s = new TextDecoder(), c = "";
|
|
2580
|
-
for (; a === void 0;) {
|
|
2581
|
-
let { value: t, done: n } = await r.read();
|
|
2582
|
-
if (n) break;
|
|
2583
|
-
c += s.decode(t, { stream: !0 });
|
|
2584
|
-
let o = jt(c);
|
|
2585
|
-
c = o.remainder;
|
|
2586
|
-
for (let t of o.chunks) if (t.trim()) for (let n of Y(t)) {
|
|
2587
|
-
let t = n.data;
|
|
2588
|
-
if (!t || typeof t != "object") continue;
|
|
2589
|
-
let r = i.translate(t), o = Number(t.seq);
|
|
2590
|
-
if (Number.isFinite(o) && o > 0 && this.recordCursor(o), r && (this.emit({
|
|
2591
|
-
type: "stream_event",
|
|
2592
|
-
event: r,
|
|
2593
|
-
sessionId: e
|
|
2594
|
-
}), r.EventType === "run_status")) {
|
|
2595
|
-
let e = String(r.Content?.status || "").toLowerCase();
|
|
2596
|
-
e !== "interrupted" && Kt.has(e) && (a = e);
|
|
2597
|
-
}
|
|
2598
|
-
}
|
|
2599
|
-
}
|
|
2600
|
-
a === void 0 && await new Promise((e) => setTimeout(e, 3e3));
|
|
2601
|
-
} catch (e) {
|
|
2602
|
-
if (e instanceof DOMException && e.name === "AbortError") return { terminalStatus: "cancelled" };
|
|
2603
|
-
if (o += 1, o >= 6) break;
|
|
2604
|
-
await new Promise((e) => setTimeout(e, 800 * o));
|
|
2605
|
-
}
|
|
2606
|
-
return a === void 0 && (a = "interrupted"), { terminalStatus: a };
|
|
2607
|
-
}
|
|
2608
|
-
async consumeStream(e, t, n, r, i) {
|
|
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;
|
|
2634
|
-
continue;
|
|
2635
|
-
}
|
|
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;
|
|
2647
|
-
}
|
|
2648
|
-
}
|
|
2649
|
-
if (o) return a.cancel().catch(() => {}), { terminalStatus: u };
|
|
2650
|
-
}
|
|
2651
|
-
}
|
|
2652
|
-
if (l === 0) throw Error("运行时返回了空响应流,请稍后重试;若问题持续,请检查运行时状态。");
|
|
2653
|
-
if (u) return { terminalStatus: u };
|
|
2654
|
-
throw TypeError("运行时连接已结束,但尚未收到执行终态;请查询原任务状态。");
|
|
2655
|
-
}
|
|
2656
|
-
isCompactionChunk(e) {
|
|
2657
|
-
return e.includes("response.compaction.start") || e.includes("response.compaction.done") || e.includes("response.compaction.failed");
|
|
2658
|
-
}
|
|
2659
|
-
dispatchAction(e, t) {
|
|
2660
|
-
switch (e.type) {
|
|
2661
|
-
case "text_delta":
|
|
2662
|
-
this.emit({
|
|
2663
|
-
type: "text_delta",
|
|
2664
|
-
messageId: t,
|
|
2665
|
-
delta: e.text
|
|
2666
|
-
});
|
|
2667
|
-
break;
|
|
2668
|
-
case "text_final":
|
|
2669
|
-
this.emit({
|
|
2670
|
-
type: "text_final",
|
|
2671
|
-
messageId: t,
|
|
2672
|
-
text: e.text
|
|
2673
|
-
});
|
|
2674
|
-
break;
|
|
2675
|
-
case "reasoning_delta":
|
|
2676
|
-
this.emit({
|
|
2677
|
-
type: "reasoning_delta",
|
|
2678
|
-
messageId: t,
|
|
2679
|
-
delta: e.text
|
|
2680
|
-
});
|
|
2681
|
-
break;
|
|
2682
|
-
case "tool_upsert":
|
|
2683
|
-
this.emit({
|
|
2684
|
-
type: "tool_upsert",
|
|
2685
|
-
messageId: t,
|
|
2686
|
-
name: e.name,
|
|
2687
|
-
args: e.args,
|
|
2688
|
-
status: e.status,
|
|
2689
|
-
extra: e.extra
|
|
2690
|
-
});
|
|
2691
|
-
break;
|
|
2692
|
-
case "tool_result":
|
|
2693
|
-
this.emit({
|
|
2694
|
-
type: "tool_result",
|
|
2695
|
-
messageId: t,
|
|
2696
|
-
name: e.name,
|
|
2697
|
-
output: e.output
|
|
2698
|
-
});
|
|
2699
|
-
break;
|
|
2700
|
-
case "approval_request":
|
|
2701
|
-
this.emit({
|
|
2702
|
-
type: "approval_requested",
|
|
2703
|
-
messageId: t,
|
|
2704
|
-
approvalRequestId: e.approvalRequestId,
|
|
2705
|
-
protocol: "responses",
|
|
2706
|
-
runId: e.runId,
|
|
2707
|
-
name: e.name || "人工确认",
|
|
2708
|
-
args: e.args || "",
|
|
2709
|
-
message: e.message || "本次运行需要人工审批后才能继续。"
|
|
2710
|
-
});
|
|
2711
|
-
break;
|
|
2712
|
-
case "approval_resolved":
|
|
2713
|
-
this.emit({
|
|
2714
|
-
type: "approval_resolved",
|
|
2715
|
-
approvalRequestId: e.approvalRequestId,
|
|
2716
|
-
decision: e.decision,
|
|
2717
|
-
revision: e.revision
|
|
2718
|
-
});
|
|
2719
|
-
break;
|
|
2720
|
-
case "incomplete": break;
|
|
2721
|
-
case "failed":
|
|
2722
|
-
this.emit({
|
|
2723
|
-
type: "text_final",
|
|
2724
|
-
messageId: t,
|
|
2725
|
-
text: `生成失败:${e.message}`
|
|
2726
|
-
});
|
|
2727
|
-
break;
|
|
2728
|
-
case "terminal":
|
|
2729
|
-
this.emit({
|
|
2730
|
-
type: "terminal",
|
|
2731
|
-
status: e.status
|
|
2732
|
-
});
|
|
2733
|
-
break;
|
|
2734
|
-
case "compaction":
|
|
2735
|
-
this.emit({
|
|
2736
|
-
type: "compaction",
|
|
2737
|
-
phase: e.phase,
|
|
2738
|
-
trigger: e.trigger,
|
|
2739
|
-
compactedUntilSeqId: e.compactedUntilSeqId
|
|
2740
|
-
});
|
|
2741
|
-
break;
|
|
2742
|
-
case "a2ui_surface_begin":
|
|
2743
|
-
this.emit({
|
|
2744
|
-
type: "a2ui_surface_begin",
|
|
2745
|
-
surfaceId: e.surfaceId,
|
|
2746
|
-
surface: e.surface
|
|
2747
|
-
});
|
|
2748
|
-
break;
|
|
2749
|
-
case "a2ui_surface_update":
|
|
2750
|
-
this.emit({
|
|
2751
|
-
type: "a2ui_surface_update",
|
|
2752
|
-
surfaceId: e.surfaceId,
|
|
2753
|
-
surface: e.surface
|
|
2754
|
-
});
|
|
2755
|
-
break;
|
|
2756
|
-
case "a2ui_surface_end":
|
|
2757
|
-
this.emit({
|
|
2758
|
-
type: "a2ui_surface_end",
|
|
2759
|
-
surfaceId: e.surfaceId
|
|
2760
|
-
});
|
|
2761
|
-
break;
|
|
2762
|
-
case "a2ui_interaction":
|
|
2763
|
-
this.emit({
|
|
2764
|
-
type: "a2ui_interaction",
|
|
2765
|
-
surfaceId: e.surfaceId,
|
|
2766
|
-
interactionId: e.interactionId,
|
|
2767
|
-
kind: e.kind,
|
|
2768
|
-
inputSchema: e.inputSchema
|
|
2769
|
-
});
|
|
2770
|
-
break;
|
|
2771
|
-
}
|
|
2772
|
-
}
|
|
2773
|
-
upsertCompactionMessage(e) {
|
|
2774
|
-
let t = typeof e.eventName == "string" ? e.eventName.split(".").pop() : void 0, n = String(e.phase || t || "start");
|
|
2775
|
-
this.emit({
|
|
2776
|
-
type: "compaction",
|
|
2777
|
-
phase: n,
|
|
2778
|
-
trigger: e.trigger ? String(e.trigger) : void 0,
|
|
2779
|
-
compactedUntilSeqId: e.compacted_until_seq_id ? Number(e.compacted_until_seq_id) : void 0
|
|
2780
|
-
}), n !== "start" && (this.activeCompactionId = null);
|
|
2781
|
-
}
|
|
2782
|
-
failCompaction() {
|
|
2783
|
-
this.activeCompactionId &&= (this.emit({
|
|
2784
|
-
type: "compaction",
|
|
2785
|
-
phase: "failed"
|
|
2786
|
-
}), null);
|
|
2787
|
-
}
|
|
2788
|
-
};
|
|
2789
|
-
//#endregion
|
|
2790
|
-
//#region src/utils/recovered-run.ts
|
|
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) => ({
|
|
2793
|
-
...e,
|
|
2794
|
-
id: !e.itemId && i.length === 1 ? r[0]?.id || `${n}:assistant` : e.id,
|
|
2795
|
-
invocationId: n,
|
|
2796
|
-
blocks: ne({
|
|
2797
|
-
content: e.content,
|
|
2798
|
-
reasoning: e.reasoning,
|
|
2799
|
-
tools: e.tools
|
|
2800
|
-
})
|
|
2801
|
-
}));
|
|
2802
|
-
if (a.length === 0) return e;
|
|
2803
|
-
let o = e.findIndex((e) => e.role === "model" && e.invocationId === n), s = e.filter((e) => !(e.role === "model" && e.invocationId === n)), c = o < 0 ? s.length : Math.min(o, s.length);
|
|
2804
|
-
return [
|
|
2805
|
-
...s.slice(0, c),
|
|
2806
|
-
...a,
|
|
2807
|
-
...s.slice(c)
|
|
2808
|
-
];
|
|
2809
|
-
}
|
|
2810
|
-
//#endregion
|
|
2811
|
-
//#region src/core/conversation/hosted.ts
|
|
2812
|
-
var $t = "conversation_item_v1";
|
|
2813
|
-
function en(e) {
|
|
2814
|
-
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
2815
|
-
}
|
|
2816
|
-
function X(e) {
|
|
2817
|
-
return typeof e == "string" && e.trim() ? e : null;
|
|
2818
|
-
}
|
|
2819
|
-
function tn(e) {
|
|
2820
|
-
if (typeof e == "string") return e;
|
|
2821
|
-
if (e == null) return "";
|
|
2822
|
-
try {
|
|
2823
|
-
return JSON.stringify(e, null, 2);
|
|
2824
|
-
} catch {
|
|
2825
|
-
return String(e);
|
|
2826
|
-
}
|
|
2827
|
-
}
|
|
2828
|
-
function Z(e) {
|
|
2829
|
-
return {
|
|
2830
|
-
id: `conversation:${e.runId}:${e.itemId}`,
|
|
2831
|
-
timestamp: 0,
|
|
2832
|
-
eventType: $t,
|
|
2833
|
-
eventId: e.sourceEventIds.at(-1),
|
|
2834
|
-
runId: e.runId,
|
|
2835
|
-
itemId: e.itemId,
|
|
2836
|
-
status: e.lifecycle === "failed" ? "failed" : e.lifecycle === "completed" ? "completed" : "running"
|
|
2837
|
-
};
|
|
2838
|
-
}
|
|
2839
|
-
function nn(e) {
|
|
2840
|
-
return e.lifecycle === "failed" ? "error" : e.lifecycle === "completed" ? "done" : "streaming";
|
|
2841
|
-
}
|
|
2842
|
-
function rn(e) {
|
|
2843
|
-
let t = typeof e.payload.text == "string" ? e.payload.text : "";
|
|
2844
|
-
if (e.kind === "user_message") return {
|
|
2845
|
-
...Z(e),
|
|
2846
|
-
role: "user",
|
|
2847
|
-
content: t,
|
|
2848
|
-
eventType: "user_message"
|
|
2849
|
-
};
|
|
2850
|
-
let n = e.kind === "reasoning" ? {
|
|
2851
|
-
id: `conversation-block:${e.itemId}`,
|
|
2852
|
-
type: "thinking",
|
|
2853
|
-
content: t,
|
|
2854
|
-
status: nn(e)
|
|
2855
|
-
} : {
|
|
2856
|
-
id: `conversation-block:${e.itemId}`,
|
|
2857
|
-
type: "text",
|
|
2858
|
-
content: t,
|
|
2859
|
-
status: nn(e)
|
|
2860
|
-
};
|
|
2861
|
-
return {
|
|
2862
|
-
...Z(e),
|
|
2863
|
-
role: "model",
|
|
2864
|
-
content: e.kind === "assistant_text" ? t : "",
|
|
2865
|
-
reasoning: e.kind === "reasoning" ? t : void 0,
|
|
2866
|
-
blocks: [n]
|
|
2867
|
-
};
|
|
2868
|
-
}
|
|
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";
|
|
2871
|
-
return {
|
|
2872
|
-
...Z(e),
|
|
2873
|
-
role: "model",
|
|
2874
|
-
content: "",
|
|
2875
|
-
blocks: [{
|
|
2876
|
-
id: `conversation-block:${e.itemId}`,
|
|
2877
|
-
type: "tool",
|
|
2878
|
-
toolName: t,
|
|
2879
|
-
args: r,
|
|
2880
|
-
output: i,
|
|
2881
|
-
status: a,
|
|
2882
|
-
...n ? { extra: { callId: n } } : {}
|
|
2883
|
-
}],
|
|
2884
|
-
tools: { [t]: {
|
|
2885
|
-
name: t,
|
|
2886
|
-
...n ? { callId: n } : {},
|
|
2887
|
-
args: r,
|
|
2888
|
-
output: i,
|
|
2889
|
-
status: a
|
|
2890
|
-
} }
|
|
2891
|
-
};
|
|
2892
|
-
}
|
|
2893
|
-
function on(e) {
|
|
2894
|
-
return e === "structured_input" ? "structured_input" : e === "plan_review" ? "plan_review" : e === "custom" ? "custom" : "approval";
|
|
2895
|
-
}
|
|
2896
|
-
function sn(e) {
|
|
2897
|
-
let t = X(e.payload.interactionId), n = e.payload.revision;
|
|
2898
|
-
if (!t || !Number.isInteger(n) || Number(n) < 1) return null;
|
|
2899
|
-
let r = tn(e.payload.detail), i = X(e.payload.prompt) || r, a = on(e.payload.interactionKind), o = e.lifecycle === "completed";
|
|
2900
|
-
return {
|
|
2901
|
-
interactionId: t,
|
|
2902
|
-
sessionId: e.sessionId,
|
|
2903
|
-
runId: e.runId,
|
|
2904
|
-
kind: a,
|
|
2905
|
-
title: X(e.payload.title) || (a === "approval" ? `审批:${X(e.payload.kind) || "操作"}` : "需要补充信息"),
|
|
2906
|
-
message: i || "运行需要人工确认。",
|
|
2907
|
-
requestSchema: en(e.payload.inputSchema),
|
|
2908
|
-
presentation: null,
|
|
2909
|
-
status: o ? "resolved" : "pending",
|
|
2910
|
-
revision: Number(n),
|
|
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,
|
|
2915
|
-
outcome: o && [
|
|
2916
|
-
"approved",
|
|
2917
|
-
"rejected",
|
|
2918
|
-
"submitted",
|
|
2919
|
-
"cancelled",
|
|
2920
|
-
"expired"
|
|
2921
|
-
].includes(String(e.payload.outcome || "")) ? e.payload.outcome : null,
|
|
2922
|
-
responseSummary: o ? X(e.payload.responseSummary) : null,
|
|
2923
|
-
source: "interaction_v1",
|
|
2924
|
-
extensions: {
|
|
2925
|
-
conversation_item_id: e.itemId,
|
|
2926
|
-
...X(e.payload.callId) ? { call_id: X(e.payload.callId) } : {}
|
|
2927
|
-
}
|
|
2928
|
-
};
|
|
2929
|
-
}
|
|
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 = {
|
|
2932
|
-
approvalRequestId: t.interactionId,
|
|
2933
|
-
approvalStatus: i,
|
|
2934
|
-
approvalMessage: t.message
|
|
2935
|
-
};
|
|
2936
|
-
return {
|
|
2937
|
-
...Z(e),
|
|
2938
|
-
role: "model",
|
|
2939
|
-
content: "",
|
|
2940
|
-
blocks: [{
|
|
2941
|
-
id: `conversation-block:${e.itemId}`,
|
|
2942
|
-
type: "tool",
|
|
2943
|
-
toolName: n,
|
|
2944
|
-
args: r,
|
|
2945
|
-
status: a,
|
|
2946
|
-
extra: o
|
|
2947
|
-
}],
|
|
2948
|
-
tools: { [n]: {
|
|
2949
|
-
name: n,
|
|
2950
|
-
args: r,
|
|
2951
|
-
status: a,
|
|
2952
|
-
approvalRequestId: t.interactionId,
|
|
2953
|
-
approvalStatus: i,
|
|
2954
|
-
approvalMessage: t.message
|
|
2955
|
-
} }
|
|
2956
|
-
};
|
|
2957
|
-
}
|
|
2958
|
-
function ln(e) {
|
|
2959
|
-
for (let t of [
|
|
2960
|
-
"createSurface",
|
|
2961
|
-
"updateComponents",
|
|
2962
|
-
"updateDataModel",
|
|
2963
|
-
"deleteSurface"
|
|
2964
|
-
]) {
|
|
2965
|
-
let n = X(en(e[t])?.surfaceId);
|
|
2966
|
-
if (n) return n;
|
|
2967
|
-
}
|
|
2968
|
-
return null;
|
|
2969
|
-
}
|
|
2970
|
-
function un(e) {
|
|
2971
|
-
let t = Array.isArray(e.payload.data) ? e.payload.data : Array.isArray(e.payload.operations) ? e.payload.operations : null;
|
|
2972
|
-
if (!t) return null;
|
|
2973
|
-
let n = t.map(en);
|
|
2974
|
-
if (n.some((e) => e === null)) return null;
|
|
2975
|
-
let r = n, i = X(e.payload.surfaceId) || r.map(ln).find((e) => e !== null) || null;
|
|
2976
|
-
return i ? {
|
|
2977
|
-
...Z(e),
|
|
2978
|
-
role: "a2ui",
|
|
2979
|
-
content: "",
|
|
2980
|
-
aguiActivity: {
|
|
2981
|
-
surfaceId: i,
|
|
2982
|
-
messages: r
|
|
2983
|
-
}
|
|
2984
|
-
} : null;
|
|
2985
|
-
}
|
|
2986
|
-
function dn(e, t, n, r = !1) {
|
|
2987
|
-
return {
|
|
2988
|
-
...Z(e),
|
|
2989
|
-
role: "system",
|
|
2990
|
-
content: n ? `${t}: ${n}` : t,
|
|
2991
|
-
status: r ? "failed" : Z(e).status
|
|
2992
|
-
};
|
|
2993
|
-
}
|
|
2994
|
-
function fn(e) {
|
|
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 = [];
|
|
2996
|
-
for (let { item: e } of t.timeline) {
|
|
2997
|
-
if (n.has(e.itemId)) {
|
|
2998
|
-
l.push(rn(e));
|
|
2999
|
-
continue;
|
|
3000
|
-
}
|
|
3001
|
-
if (r.has(e.itemId)) {
|
|
3002
|
-
l.push(an(e));
|
|
3003
|
-
continue;
|
|
3004
|
-
}
|
|
3005
|
-
if (i.has(e.itemId) || a.has(e.itemId)) {
|
|
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."));
|
|
3008
|
-
continue;
|
|
3009
|
-
}
|
|
3010
|
-
if (o.has(e.itemId)) {
|
|
3011
|
-
let t = un(e);
|
|
3012
|
-
l.push(t || dn(e, "Unsupported content", "A2UI payload is not a valid passive operation list."));
|
|
3013
|
-
continue;
|
|
3014
|
-
}
|
|
3015
|
-
let t = s.get(e.itemId);
|
|
3016
|
-
if (t) {
|
|
3017
|
-
l.push(t.status === "pending" ? {
|
|
3018
|
-
...Z(e),
|
|
3019
|
-
role: "model",
|
|
3020
|
-
content: t.name,
|
|
3021
|
-
attachments: [{
|
|
3022
|
-
name: t.name,
|
|
3023
|
-
type: t.mimeType,
|
|
3024
|
-
url: "",
|
|
3025
|
-
artifactId: t.artifactId,
|
|
3026
|
-
itemId: t.itemId,
|
|
3027
|
-
runId: t.runId,
|
|
3028
|
-
sizeBytes: t.sizeBytes,
|
|
3029
|
-
status: "pending"
|
|
3030
|
-
}]
|
|
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."));
|
|
3046
|
-
continue;
|
|
3047
|
-
}
|
|
3048
|
-
let d = c.get(e.itemId);
|
|
3049
|
-
if (d) {
|
|
3050
|
-
if (e.kind === "error" && ["cancelled", "canceled"].includes(String(e.payload.status || "").toLowerCase())) continue;
|
|
3051
|
-
l.push(dn(e, d.title, d.detail, d.failed));
|
|
3052
|
-
}
|
|
3053
|
-
}
|
|
3054
|
-
return {
|
|
3055
|
-
messages: l,
|
|
3056
|
-
interactions: u
|
|
3057
|
-
};
|
|
3058
|
-
}
|
|
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
|
-
}] : [];
|
|
3067
|
-
return [
|
|
3068
|
-
...l.slice(0, d),
|
|
3069
|
-
...f,
|
|
3070
|
-
...r,
|
|
3071
|
-
...l.slice(d)
|
|
3072
|
-
];
|
|
3073
|
-
}
|
|
3074
|
-
//#endregion
|
|
3075
|
-
//#region src/core/run/dispatcher.ts
|
|
3076
|
-
var mn = "连接断开或生成出错,请重试";
|
|
3077
|
-
function hn(e) {
|
|
3078
|
-
let t = String(e.message || "").trim();
|
|
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;
|
|
3080
|
-
}
|
|
3081
|
-
var gn = new Set(["completed"]), _n = new Set([
|
|
3082
|
-
"failed",
|
|
3083
|
-
"error",
|
|
3084
|
-
"cancelled",
|
|
3085
|
-
"canceled",
|
|
3086
|
-
"aborted",
|
|
3087
|
-
"incomplete"
|
|
3088
|
-
]), vn = /* @__PURE__ */ new Map();
|
|
3089
|
-
function Q(e, t) {
|
|
3090
|
-
E.getState().patchMessages((n) => {
|
|
3091
|
-
if (n.some((t) => t.id === e)) return t ? n.map((n) => n.id === e ? {
|
|
3092
|
-
...n,
|
|
3093
|
-
invocationId: t
|
|
3094
|
-
} : n) : n;
|
|
3095
|
-
let r = -1;
|
|
3096
|
-
for (let e = n.length - 1; e >= 0; --e) if (n[e]?.eventType === "optimistic_assistant_placeholder") {
|
|
3097
|
-
r = e;
|
|
3098
|
-
break;
|
|
3099
|
-
}
|
|
3100
|
-
return r >= 0 ? n.map((n, i) => i === r ? {
|
|
3101
|
-
...n,
|
|
3102
|
-
id: e,
|
|
3103
|
-
eventType: void 0,
|
|
3104
|
-
invocationId: t
|
|
3105
|
-
} : n) : [...n, {
|
|
3106
|
-
id: e,
|
|
3107
|
-
role: "model",
|
|
3108
|
-
content: "",
|
|
3109
|
-
timestamp: Date.now(),
|
|
3110
|
-
reasoning: "",
|
|
3111
|
-
invocationId: t
|
|
3112
|
-
}];
|
|
3113
|
-
});
|
|
3114
|
-
}
|
|
3115
|
-
function yn(e) {
|
|
3116
|
-
return e.filter((e) => e.eventType !== "optimistic_assistant_placeholder");
|
|
3117
|
-
}
|
|
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) => {
|
|
3121
|
-
if (!e.tools) return e;
|
|
3122
|
-
let t = !1, r = Object.fromEntries(Object.entries(e.tools).map(([e, r]) => r.status === "running" ? (t = !0, [e, {
|
|
3123
|
-
...r,
|
|
3124
|
-
status: n
|
|
3125
|
-
}]) : [e, r]));
|
|
3126
|
-
return t ? {
|
|
3127
|
-
...e,
|
|
3128
|
-
tools: r
|
|
3129
|
-
} : e;
|
|
3130
|
-
}));
|
|
3131
|
-
}
|
|
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 && ![
|
|
3139
|
-
"activity",
|
|
3140
|
-
"stage_changed",
|
|
3141
|
-
"stream_ended",
|
|
3142
|
-
"error",
|
|
3143
|
-
"rate_limited",
|
|
3144
|
-
"terminal",
|
|
3145
|
-
"approval_requested",
|
|
3146
|
-
"approval_resolved",
|
|
3147
|
-
"stream_event",
|
|
3148
|
-
"conversation_snapshot"
|
|
3149
|
-
].includes(e.type)) return;
|
|
3150
|
-
let r = E.getState(), i = (e) => {
|
|
3151
|
-
e && c.getState().updateActivity({ sessionId: e });
|
|
3152
|
-
};
|
|
3153
|
-
switch (e.type) {
|
|
3154
|
-
case "activity":
|
|
3155
|
-
c.getState().updateActivity({
|
|
3156
|
-
sessionId: e.sessionId,
|
|
3157
|
-
visible: !n,
|
|
3158
|
-
source: e.source,
|
|
3159
|
-
status: e.status,
|
|
3160
|
-
phase: e.phase,
|
|
3161
|
-
detail: e.detail,
|
|
3162
|
-
countEvent: e.countEvent
|
|
3163
|
-
});
|
|
3164
|
-
break;
|
|
3165
|
-
case "user_message_added":
|
|
3166
|
-
c.getState().setBanner(null), r.patchMessages((t) => [...t, {
|
|
3167
|
-
id: e.messageId,
|
|
3168
|
-
role: "user",
|
|
3169
|
-
content: "",
|
|
3170
|
-
timestamp: Date.now()
|
|
3171
|
-
}]);
|
|
3172
|
-
break;
|
|
3173
|
-
case "assistant_message_created":
|
|
3174
|
-
Q(e.messageId, e.invocationId);
|
|
3175
|
-
break;
|
|
3176
|
-
case "text_delta":
|
|
3177
|
-
Q(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => t.id === e.messageId ? {
|
|
3178
|
-
...t,
|
|
3179
|
-
content: t.content + e.delta,
|
|
3180
|
-
blocks: ce(t.blocks, e.delta)
|
|
3181
|
-
} : t));
|
|
3182
|
-
break;
|
|
3183
|
-
case "text_final":
|
|
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;
|
|
3186
|
-
return {
|
|
3187
|
-
...t,
|
|
3188
|
-
reasoning: r,
|
|
3189
|
-
content: e.text,
|
|
3190
|
-
blocks: te(i, e.text)
|
|
3191
|
-
};
|
|
3192
|
-
})() : t));
|
|
3193
|
-
break;
|
|
3194
|
-
case "reasoning_delta":
|
|
3195
|
-
Q(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => t.id === e.messageId ? {
|
|
3196
|
-
...t,
|
|
3197
|
-
reasoning: (t.reasoning || "") + e.delta,
|
|
3198
|
-
blocks: ae(t.blocks, e.delta)
|
|
3199
|
-
} : t));
|
|
3200
|
-
break;
|
|
3201
|
-
case "tool_upsert":
|
|
3202
|
-
Q(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => {
|
|
3203
|
-
if (t.id !== e.messageId) return t;
|
|
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;
|
|
3205
|
-
return {
|
|
3206
|
-
...t,
|
|
3207
|
-
blocks: pe(t.blocks, e.name, {
|
|
3208
|
-
args: e.args,
|
|
3209
|
-
status: a,
|
|
3210
|
-
extra: e.extra
|
|
3211
|
-
}),
|
|
3212
|
-
tools: {
|
|
3213
|
-
...t.tools || {},
|
|
3214
|
-
[e.name]: {
|
|
3215
|
-
...n || {
|
|
3216
|
-
name: e.name,
|
|
3217
|
-
args: ""
|
|
3218
|
-
},
|
|
3219
|
-
name: e.name,
|
|
3220
|
-
args: e.args,
|
|
3221
|
-
status: a,
|
|
3222
|
-
...e.extra || {},
|
|
3223
|
-
...e.extra?.approvalRequestId && !r ? { approvalStatus: "pending" } : {}
|
|
3224
|
-
}
|
|
3225
|
-
}
|
|
3226
|
-
};
|
|
3227
|
-
}));
|
|
3228
|
-
break;
|
|
3229
|
-
case "tool_result":
|
|
3230
|
-
Q(e.messageId), i(e.sessionId), r.patchMessages((t) => t.map((t) => {
|
|
3231
|
-
if (t.id !== e.messageId) return t;
|
|
3232
|
-
let n = D(e.output) ? "error" : "completed";
|
|
3233
|
-
return {
|
|
3234
|
-
...t,
|
|
3235
|
-
blocks: pe(t.blocks, e.name, {
|
|
3236
|
-
output: e.output,
|
|
3237
|
-
status: n
|
|
3238
|
-
}),
|
|
3239
|
-
tools: {
|
|
3240
|
-
...t.tools || {},
|
|
3241
|
-
[e.name]: {
|
|
3242
|
-
...t.tools?.[e.name] || {
|
|
3243
|
-
name: e.name,
|
|
3244
|
-
args: ""
|
|
3245
|
-
},
|
|
3246
|
-
output: e.output,
|
|
3247
|
-
status: n
|
|
3248
|
-
}
|
|
3249
|
-
}
|
|
3250
|
-
};
|
|
3251
|
-
}));
|
|
3252
|
-
break;
|
|
3253
|
-
case "approval_requested":
|
|
3254
|
-
if (pt({
|
|
3255
|
-
approvalRequestId: e.approvalRequestId,
|
|
3256
|
-
protocol: e.protocol,
|
|
3257
|
-
runId: e.runId,
|
|
3258
|
-
name: e.name,
|
|
3259
|
-
message: e.message,
|
|
3260
|
-
args: e.args,
|
|
3261
|
-
approvalLevel: e.approvalLevel,
|
|
3262
|
-
sessionId: e.sessionId
|
|
3263
|
-
}), n) break;
|
|
3264
|
-
Q(e.messageId), r.patchMessages((t) => t.map((t) => {
|
|
3265
|
-
if (t.id !== e.messageId) return t;
|
|
3266
|
-
let n = t.tools?.[e.approvalRequestId], r = n?.approvalStatus === "approved" || n?.approvalStatus === "rejected" || n?.approvalStatus === "cancelled", i = {
|
|
3267
|
-
approvalRequestId: e.approvalRequestId,
|
|
3268
|
-
approvalProtocol: e.protocol,
|
|
3269
|
-
approvalStatus: r ? n.approvalStatus : "pending",
|
|
3270
|
-
...e.message ? { approvalMessage: e.message } : {},
|
|
3271
|
-
...e.approvalLevel ? { approvalLevel: e.approvalLevel } : {}
|
|
3272
|
-
}, a = r ? n.status : "paused";
|
|
3273
|
-
return {
|
|
3274
|
-
...t,
|
|
3275
|
-
blocks: pe(t.blocks, e.name, {
|
|
3276
|
-
args: e.args,
|
|
3277
|
-
status: a,
|
|
3278
|
-
extra: i
|
|
3279
|
-
}),
|
|
3280
|
-
tools: {
|
|
3281
|
-
...t.tools || {},
|
|
3282
|
-
[e.approvalRequestId]: {
|
|
3283
|
-
...n || {},
|
|
3284
|
-
name: e.name,
|
|
3285
|
-
args: e.args,
|
|
3286
|
-
status: a,
|
|
3287
|
-
...i
|
|
3288
|
-
}
|
|
3289
|
-
}
|
|
3290
|
-
};
|
|
3291
|
-
}));
|
|
3292
|
-
break;
|
|
3293
|
-
case "approval_resolved":
|
|
3294
|
-
if (mt({
|
|
3295
|
-
approvalRequestId: e.approvalRequestId,
|
|
3296
|
-
decision: e.decision,
|
|
3297
|
-
revision: e.revision,
|
|
3298
|
-
sessionId: e.sessionId
|
|
3299
|
-
}), n) break;
|
|
3300
|
-
r.patchMessages((t) => t.map((t) => {
|
|
3301
|
-
if (!t.tools) return t;
|
|
3302
|
-
let n = !1, r = Object.fromEntries(Object.entries(t.tools).map(([t, r]) => {
|
|
3303
|
-
if (r.approvalRequestId !== e.approvalRequestId) return [t, r];
|
|
3304
|
-
n = !0;
|
|
3305
|
-
let i = e.decision === "rejected" || e.decision === "cancelled" ? "completed" : r.status === "paused" ? "running" : r.status;
|
|
3306
|
-
return [t, {
|
|
3307
|
-
...r,
|
|
3308
|
-
status: i,
|
|
3309
|
-
approvalStatus: e.decision
|
|
3310
|
-
}];
|
|
3311
|
-
}));
|
|
3312
|
-
return n ? {
|
|
3313
|
-
...t,
|
|
3314
|
-
tools: r,
|
|
3315
|
-
blocks: t.blocks?.map((t) => {
|
|
3316
|
-
if (t.type !== "tool" || t.extra?.approvalRequestId !== e.approvalRequestId) return t;
|
|
3317
|
-
let n = e.decision === "rejected" || e.decision === "cancelled" ? "completed" : t.status === "paused" ? "running" : t.status;
|
|
3318
|
-
return {
|
|
3319
|
-
...t,
|
|
3320
|
-
status: n,
|
|
3321
|
-
extra: {
|
|
3322
|
-
...t.extra,
|
|
3323
|
-
approvalStatus: e.decision
|
|
3324
|
-
}
|
|
3325
|
-
};
|
|
3326
|
-
})
|
|
3327
|
-
} : t;
|
|
3328
|
-
}));
|
|
3329
|
-
break;
|
|
3330
|
-
case "system_message":
|
|
3331
|
-
r.patchMessages((t) => [...t, {
|
|
3332
|
-
id: String(Date.now() + Math.random()),
|
|
3333
|
-
role: "system",
|
|
3334
|
-
content: e.content,
|
|
3335
|
-
timestamp: Date.now()
|
|
3336
|
-
}]);
|
|
3337
|
-
break;
|
|
3338
|
-
case "compaction": {
|
|
3339
|
-
let t = `compaction-${Date.now()}`, n = e.phase === "start" ? "running" : e.phase === "failed" ? "failed" : "completed", i = le({
|
|
3340
|
-
id: t,
|
|
3341
|
-
timestamp: Date.now(),
|
|
3342
|
-
status: n,
|
|
3343
|
-
trigger: e.trigger,
|
|
3344
|
-
compactedUntilSeqId: e.compactedUntilSeqId
|
|
3345
|
-
});
|
|
3346
|
-
r.patchMessages((e) => e.findIndex((e) => e.id === t) < 0 ? [...e, i] : e.map((e) => e.id === t ? {
|
|
3347
|
-
...e,
|
|
3348
|
-
...i
|
|
3349
|
-
} : e));
|
|
3350
|
-
break;
|
|
3351
|
-
}
|
|
3352
|
-
case "stage_changed":
|
|
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);
|
|
3354
|
-
break;
|
|
3355
|
-
case "stream_ended":
|
|
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 : {
|
|
3357
|
-
...t,
|
|
3358
|
-
blocks: M(t.blocks.map((e) => e.type === "text" && e.status === "streaming" ? {
|
|
3359
|
-
...e,
|
|
3360
|
-
status: "done"
|
|
3361
|
-
} : e))
|
|
3362
|
-
})), globalThis.setTimeout(() => {
|
|
3363
|
-
let t = c.getState();
|
|
3364
|
-
t.getSessionActivity(e.sessionId)?.status === "completed" && t.clearSessionActivity(e.sessionId);
|
|
3365
|
-
}, 2400);
|
|
3366
|
-
break;
|
|
3367
|
-
case "error": {
|
|
3368
|
-
let t = hn(e.error);
|
|
3369
|
-
c.getState().setSessionStreaming(e.sessionId, !1), c.getState().updateActivity({
|
|
3370
|
-
sessionId: e.sessionId,
|
|
3371
|
-
visible: !n,
|
|
3372
|
-
status: "failed",
|
|
3373
|
-
phase: "运行失败",
|
|
3374
|
-
detail: t,
|
|
3375
|
-
countEvent: !1
|
|
3376
|
-
}), n || (c.getState().setBanner({
|
|
3377
|
-
kind: "error",
|
|
3378
|
-
message: t,
|
|
3379
|
-
sessionId: e.sessionId
|
|
3380
|
-
}), r.patchMessages((e) => [...yn(e), {
|
|
3381
|
-
id: String(Date.now()),
|
|
3382
|
-
role: "model",
|
|
3383
|
-
content: `运行失败:${t}`,
|
|
3384
|
-
timestamp: Date.now()
|
|
3385
|
-
}]));
|
|
3386
|
-
break;
|
|
3387
|
-
}
|
|
3388
|
-
case "rate_limited":
|
|
3389
|
-
c.getState().setSessionStreaming(e.sessionId, !1), c.getState().updateActivity({
|
|
3390
|
-
sessionId: e.sessionId,
|
|
3391
|
-
visible: !n,
|
|
3392
|
-
status: "failed",
|
|
3393
|
-
phase: "请求被限流",
|
|
3394
|
-
countEvent: !1
|
|
3395
|
-
}), n || (c.getState().setBanner({
|
|
3396
|
-
kind: "rate_limited",
|
|
3397
|
-
message: e.message || "请求过于频繁,请稍后重试",
|
|
3398
|
-
retryAfterSec: e.retryAfterSec,
|
|
3399
|
-
sessionId: e.sessionId
|
|
3400
|
-
}), r.patchMessages(yn));
|
|
3401
|
-
break;
|
|
3402
|
-
case "terminal":
|
|
3403
|
-
e.sessionId && String(e.status || "").trim().toLowerCase() !== "incomplete" && J.markSessionTerminal(e.sessionId), n || bn(e.status);
|
|
3404
|
-
break;
|
|
3405
|
-
case "stream_event": {
|
|
3406
|
-
let t = e.sessionId || e.event.SessionId;
|
|
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);
|
|
3417
|
-
}
|
|
3418
|
-
e.event.EventType === "run_checkpoint" && t && b.getState().upsertSessionCheckpoint(t, e.event);
|
|
3419
|
-
{
|
|
3420
|
-
let r = P(e.event);
|
|
3421
|
-
r === "completed" ? c.getState().updateActivity({
|
|
3422
|
-
sessionId: t,
|
|
3423
|
-
visible: !n,
|
|
3424
|
-
status: "completed",
|
|
3425
|
-
phase: "后台长任务已完成",
|
|
3426
|
-
countEvent: !1
|
|
3427
|
-
}) : r === "cancelled" || r === "canceled" || r === "aborted" ? c.getState().updateActivity({
|
|
3428
|
-
sessionId: t,
|
|
3429
|
-
visible: !n,
|
|
3430
|
-
status: "stopped",
|
|
3431
|
-
phase: "后台长任务已取消",
|
|
3432
|
-
countEvent: !1
|
|
3433
|
-
}) : (r === "failed" || r === "error") && c.getState().updateActivity({
|
|
3434
|
-
sessionId: t,
|
|
3435
|
-
visible: !n,
|
|
3436
|
-
status: "failed",
|
|
3437
|
-
phase: "后台长任务失败",
|
|
3438
|
-
countEvent: !1
|
|
3439
|
-
});
|
|
3440
|
-
}
|
|
3441
|
-
break;
|
|
3442
|
-
}
|
|
3443
|
-
case "conversation_snapshot": {
|
|
3444
|
-
let t = fn(e.result);
|
|
3445
|
-
for (let e of t.interactions) J.upsert(e);
|
|
3446
|
-
if (n) break;
|
|
3447
|
-
r.patchMessages((t) => pn(t, e.result, e.optimisticMessageId)), i(e.sessionId);
|
|
3448
|
-
break;
|
|
3449
|
-
}
|
|
3450
|
-
case "a2ui_surface_begin": {
|
|
3451
|
-
let t = `a2ui-${e.surfaceId}`;
|
|
3452
|
-
E.getState().patchMessages((n) => [...n.filter((e) => e.id !== t), {
|
|
3453
|
-
id: t,
|
|
3454
|
-
role: "a2ui",
|
|
3455
|
-
content: "",
|
|
3456
|
-
timestamp: Date.now(),
|
|
3457
|
-
a2ui: {
|
|
3458
|
-
surfaceId: e.surfaceId,
|
|
3459
|
-
surface: e.surface
|
|
3460
|
-
}
|
|
3461
|
-
}]);
|
|
3462
|
-
break;
|
|
3463
|
-
}
|
|
3464
|
-
case "a2ui_surface_update": {
|
|
3465
|
-
let t = `a2ui-${e.surfaceId}`;
|
|
3466
|
-
E.getState().patchMessages((n) => n.map((n) => n.id === t && n.a2ui ? {
|
|
3467
|
-
...n,
|
|
3468
|
-
a2ui: {
|
|
3469
|
-
...n.a2ui,
|
|
3470
|
-
surface: e.surface
|
|
3471
|
-
}
|
|
3472
|
-
} : n));
|
|
3473
|
-
break;
|
|
3474
|
-
}
|
|
3475
|
-
case "a2ui_surface_end": {
|
|
3476
|
-
let t = `a2ui-${e.surfaceId}`;
|
|
3477
|
-
E.getState().patchMessages((e) => e.map((e) => e.id === t && e.a2ui ? {
|
|
3478
|
-
...e,
|
|
3479
|
-
a2ui: {
|
|
3480
|
-
...e.a2ui,
|
|
3481
|
-
ended: !0
|
|
3482
|
-
}
|
|
3483
|
-
} : e));
|
|
3484
|
-
break;
|
|
3485
|
-
}
|
|
3486
|
-
case "a2ui_interaction": {
|
|
3487
|
-
let t = `a2ui-${e.surfaceId}`;
|
|
3488
|
-
E.getState().patchMessages((n) => n.map((n) => n.id === t && n.a2ui ? {
|
|
3489
|
-
...n,
|
|
3490
|
-
a2ui: {
|
|
3491
|
-
...n.a2ui,
|
|
3492
|
-
pendingInteraction: {
|
|
3493
|
-
interactionId: e.interactionId,
|
|
3494
|
-
kind: e.kind,
|
|
3495
|
-
inputSchema: e.inputSchema
|
|
3496
|
-
}
|
|
3497
|
-
}
|
|
3498
|
-
} : n));
|
|
3499
|
-
break;
|
|
3500
|
-
}
|
|
3501
|
-
case "agui_activity": {
|
|
3502
|
-
let t = `agui-a2ui-${e.surfaceId}`;
|
|
3503
|
-
E.getState().patchMessages((n) => {
|
|
3504
|
-
let r = {
|
|
3505
|
-
surfaceId: e.surfaceId,
|
|
3506
|
-
messages: e.messages
|
|
3507
|
-
}, i = !1, a = n.map((t) => {
|
|
3508
|
-
if (t.id !== e.messageId) return t;
|
|
3509
|
-
i = !0;
|
|
3510
|
-
let n = [...(t.aguiActivities || []).filter((t) => t.surfaceId !== e.surfaceId), r];
|
|
3511
|
-
return {
|
|
3512
|
-
...t,
|
|
3513
|
-
aguiActivities: n
|
|
3514
|
-
};
|
|
3515
|
-
});
|
|
3516
|
-
if (i) return a;
|
|
3517
|
-
let o = n.find((e) => e.id === t), s = {
|
|
3518
|
-
id: t,
|
|
3519
|
-
role: "a2ui",
|
|
3520
|
-
content: "",
|
|
3521
|
-
timestamp: o?.timestamp || Date.now(),
|
|
3522
|
-
aguiActivity: r
|
|
3523
|
-
};
|
|
3524
|
-
return o ? n.map((e) => e.id === t ? s : e) : [...n, s];
|
|
3525
|
-
});
|
|
3526
|
-
break;
|
|
3527
|
-
}
|
|
3528
|
-
}
|
|
3529
|
-
}
|
|
3530
|
-
function Sn() {
|
|
3531
|
-
vn.clear();
|
|
3532
|
-
}
|
|
3533
|
-
//#endregion
|
|
3534
|
-
//#region src/hooks/useRunAgent.ts
|
|
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
|
-
}), [
|
|
3556
|
-
d,
|
|
3557
|
-
f,
|
|
3558
|
-
p,
|
|
3559
|
-
m,
|
|
3560
|
-
h,
|
|
3561
|
-
g,
|
|
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) => {
|
|
3618
|
-
let t = e.text.trim(), n = e.attachments.map((e) => ({
|
|
3619
|
-
name: e.name,
|
|
3620
|
-
url: URL.createObjectURL(e),
|
|
3621
|
-
type: e.type || "application/octet-stream"
|
|
3622
|
-
}));
|
|
3623
|
-
if (!t && n.length === 0) return;
|
|
3624
|
-
let r = `optimistic-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
3625
|
-
return E.getState().patchMessages((e) => [...e, {
|
|
3626
|
-
id: r,
|
|
3627
|
-
role: "user",
|
|
3628
|
-
content: t,
|
|
3629
|
-
timestamp: Date.now(),
|
|
3630
|
-
eventType: "optimistic_user_message",
|
|
3631
|
-
attachments: n.length ? n : void 0
|
|
3632
|
-
}]), r;
|
|
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 = {
|
|
3655
|
-
text: e,
|
|
3656
|
-
attachments: [...t],
|
|
3657
|
-
responsesInput: i,
|
|
3658
|
-
previousResponseId: o,
|
|
3659
|
-
executionMode: l,
|
|
3660
|
-
optimisticMessageId: j({
|
|
3661
|
-
text: e,
|
|
3662
|
-
attachments: 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,
|
|
3668
|
-
text: e,
|
|
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));
|
|
3714
|
-
}, [
|
|
3715
|
-
M,
|
|
3716
|
-
j,
|
|
3717
|
-
T,
|
|
3718
|
-
v,
|
|
3719
|
-
A,
|
|
3720
|
-
D,
|
|
3721
|
-
b,
|
|
3722
|
-
x,
|
|
3723
|
-
w,
|
|
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({
|
|
3735
|
-
...e,
|
|
3736
|
-
onSettled: (e) => {
|
|
3737
|
-
b?.(e, t.agentId), A(t);
|
|
3738
|
-
}
|
|
3739
|
-
});
|
|
3740
|
-
return r || c.getState().setSessionStreaming(e.sessionId, !1), r;
|
|
3741
|
-
}, [
|
|
3742
|
-
A,
|
|
3743
|
-
O,
|
|
3744
|
-
D,
|
|
3745
|
-
b
|
|
3746
|
-
]), te = L(() => {
|
|
3747
|
-
Sn();
|
|
3748
|
-
}, []);
|
|
3749
|
-
return {
|
|
3750
|
-
submitDraft: ee,
|
|
3751
|
-
isOutboxRequestActive: i,
|
|
3752
|
-
stopGeneration: P,
|
|
3753
|
-
disconnectRun: F,
|
|
3754
|
-
resumeCheckpoint: I,
|
|
3755
|
-
submitAguiAction: L((e) => {
|
|
3756
|
-
let t = e.userAction;
|
|
3757
|
-
if (!t) return !1;
|
|
3758
|
-
let n = t.context || {}, r = String(n.interruptId || n.interrupt_id || "");
|
|
3759
|
-
if (!r) return !1;
|
|
3760
|
-
let i = v.current;
|
|
3761
|
-
if (!i) return !1;
|
|
3762
|
-
let a = D(i), o = O(i), s = n.status === "cancelled" ? "cancelled" : "resolved", c = Object.prototype.hasOwnProperty.call(n, "payload") ? n.payload : {
|
|
3763
|
-
action: t.name,
|
|
3764
|
-
sourceComponentId: t.sourceComponentId,
|
|
3765
|
-
context: n
|
|
3766
|
-
};
|
|
3767
|
-
return o.resumeAguiInterrupt({
|
|
3768
|
-
sessionId: i,
|
|
3769
|
-
interruptId: r,
|
|
3770
|
-
status: s,
|
|
3771
|
-
payload: c,
|
|
3772
|
-
onSettled: (e) => {
|
|
3773
|
-
b?.(e, a.agentId), A(a);
|
|
3774
|
-
}
|
|
3775
|
-
});
|
|
3776
|
-
}, [
|
|
3777
|
-
v,
|
|
3778
|
-
A,
|
|
3779
|
-
O,
|
|
3780
|
-
D,
|
|
3781
|
-
b
|
|
3782
|
-
]),
|
|
3783
|
-
respondToAguiApproval: L((e) => {
|
|
3784
|
-
if (!e.interruptId) return !1;
|
|
3785
|
-
let t = v.current;
|
|
3786
|
-
if (!t) return !1;
|
|
3787
|
-
let n = D(t), r = O(t);
|
|
3788
|
-
if (r.stage !== "idle") return !1;
|
|
3789
|
-
c.getState().setSessionStreaming(t, !0);
|
|
3790
|
-
let i = r.resumeAguiInterrupt({
|
|
3791
|
-
sessionId: t,
|
|
3792
|
-
interruptId: e.interruptId,
|
|
3793
|
-
status: "resolved",
|
|
3794
|
-
payload: { decision: e.approve ? "approve" : "reject" },
|
|
3795
|
-
onSettled: (e) => {
|
|
3796
|
-
b?.(e, n.agentId), A(n);
|
|
3797
|
-
}
|
|
3798
|
-
});
|
|
3799
|
-
return i || c.getState().setSessionStreaming(t, !1), i;
|
|
3800
|
-
}, [
|
|
3801
|
-
v,
|
|
3802
|
-
A,
|
|
3803
|
-
O,
|
|
3804
|
-
D,
|
|
3805
|
-
b
|
|
3806
|
-
]),
|
|
3807
|
-
resetCompaction: te
|
|
3808
|
-
};
|
|
3809
|
-
}
|
|
3810
|
-
//#endregion
|
|
3811
|
-
//#region src/utils/messages.js
|
|
3812
|
-
var Tn = {
|
|
3813
|
-
running: "running",
|
|
3814
|
-
completed: "completed",
|
|
3815
|
-
failed: "error",
|
|
3816
|
-
paused: "paused",
|
|
3817
|
-
approved: "completed",
|
|
3818
|
-
denied: "completed"
|
|
3819
|
-
}, En = {
|
|
3820
|
-
paused: "pending",
|
|
3821
|
-
approved: "approved",
|
|
3822
|
-
denied: "rejected"
|
|
3823
|
-
};
|
|
3824
|
-
function Dn(e) {
|
|
3825
|
-
if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
|
|
3826
|
-
if (typeof e == "string") {
|
|
3827
|
-
let t = Number(e.trim());
|
|
3828
|
-
if (e.trim() && Number.isFinite(t)) return t > 0 && t < 1e11 ? t * 1e3 : t;
|
|
3829
|
-
let n = Date.parse(e);
|
|
3830
|
-
if (Number.isFinite(n)) return n;
|
|
3831
|
-
}
|
|
3832
|
-
return Date.now();
|
|
3833
|
-
}
|
|
3834
|
-
function On(e) {
|
|
3835
|
-
if (typeof e == "string") return e;
|
|
3836
|
-
if (e && typeof e == "object") {
|
|
3837
|
-
if (typeof e.text == "string") return e.text;
|
|
3838
|
-
if (Array.isArray(e.parts)) return e.parts.map((e) => e && typeof e == "object" && typeof e.text == "string" ? e.text : "").join("");
|
|
3839
|
-
}
|
|
3840
|
-
return "";
|
|
3841
|
-
}
|
|
3842
|
-
function kn(e) {
|
|
3843
|
-
let t = {}, n = /* @__PURE__ */ new Map();
|
|
3844
|
-
for (let t of e ?? []) t?.Name && n.set(t.Name, (n.get(t.Name) || 0) + 1);
|
|
3845
|
-
for (let r of e ?? []) {
|
|
3846
|
-
if (!r?.Name) continue;
|
|
3847
|
-
let e = Tn[String(r.Status ?? "completed").toLowerCase()] ?? "completed", i = {
|
|
3848
|
-
name: r.Name,
|
|
3849
|
-
args: r.Args === void 0 ? "" : typeof r.Args == "string" ? r.Args : JSON.stringify(r.Args),
|
|
3850
|
-
status: e
|
|
3851
|
-
};
|
|
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);
|
|
3853
|
-
let a = n.get(r.Name) > 1 && r.ToolCallId ? r.ToolCallId : r.Name;
|
|
3854
|
-
t[a] = i;
|
|
3855
|
-
}
|
|
3856
|
-
return t;
|
|
3857
|
-
}
|
|
3858
|
-
function An(e) {
|
|
3859
|
-
if (Array.isArray(e)) return e.map((e) => ({
|
|
3860
|
-
name: e.name || "",
|
|
3861
|
-
url: e.url || "",
|
|
3862
|
-
type: e.mime || "",
|
|
3863
|
-
fileUri: e.file_uri
|
|
3864
|
-
}));
|
|
3865
|
-
}
|
|
3866
|
-
function jn(e) {
|
|
3867
|
-
return e == null ? "" : typeof e == "string" ? e : JSON.stringify(e);
|
|
3868
|
-
}
|
|
3869
|
-
function Mn(e) {
|
|
3870
|
-
if (!(!Array.isArray(e) || !e.length)) return e.flatMap((e, t) => {
|
|
3871
|
-
let n = String(e?.Type || "").toLowerCase(), r = e?.SeqId ?? t;
|
|
3872
|
-
if (n === "thinking" || n === "text") {
|
|
3873
|
-
let t = String(e?.Content || "");
|
|
3874
|
-
return t ? [{
|
|
3875
|
-
id: `history-${n}-${r}`,
|
|
3876
|
-
type: n,
|
|
3877
|
-
content: t,
|
|
3878
|
-
status: "done"
|
|
3879
|
-
}] : [];
|
|
3880
|
-
}
|
|
3881
|
-
if (n !== "tool") return [];
|
|
3882
|
-
let i = Tn[String(e?.Status || "completed").toLowerCase()] ?? "completed";
|
|
3883
|
-
return [{
|
|
3884
|
-
id: `history-tool-${r}`,
|
|
3885
|
-
type: "tool",
|
|
3886
|
-
toolName: String(e?.Name || "tool"),
|
|
3887
|
-
args: jn(e?.Args),
|
|
3888
|
-
...e?.Result === void 0 ? {} : { output: jn(e.Result) },
|
|
3889
|
-
status: i,
|
|
3890
|
-
...e?.ToolCallId ? { extra: { previousResponseId: String(e.ToolCallId) } } : {}
|
|
3891
|
-
}];
|
|
3892
|
-
});
|
|
3893
|
-
}
|
|
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 = {
|
|
3896
|
-
id: e.MessageId || `msg-${e.SeqId ?? Math.random().toString(36).slice(2)}`,
|
|
3897
|
-
role: t,
|
|
3898
|
-
content: On(e.Content),
|
|
3899
|
-
timestamp: Dn(e.Timestamp),
|
|
3900
|
-
eventType: t === "user" ? "user_message" : "assistant_message",
|
|
3901
|
-
reasoning: a,
|
|
3902
|
-
tools: n,
|
|
3903
|
-
attachments: r
|
|
3904
|
-
};
|
|
3905
|
-
return t === "model" && (o.blocks = i ?? ne({
|
|
3906
|
-
reasoning: a,
|
|
3907
|
-
tools: n,
|
|
3908
|
-
content: o.content
|
|
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;
|
|
3910
|
-
}
|
|
3911
|
-
function Pn(e) {
|
|
3912
|
-
return Array.isArray(e.Activities) ? e.Activities.flatMap((t, n) => {
|
|
3913
|
-
let r = String(t?.SurfaceId || "");
|
|
3914
|
-
if (!r) return [];
|
|
3915
|
-
let i = t?.Content, a = Array.isArray(i?.a2ui_operations) ? i.a2ui_operations : Array.isArray(i) ? i : [];
|
|
3916
|
-
if (!a.length || r.startsWith("approval-") && a.some((e) => {
|
|
3917
|
-
let t = e?.updateComponents?.components || e?.update_components?.components;
|
|
3918
|
-
return Array.isArray(t) && t.some((e) => e?.component === "ApprovalBar");
|
|
3919
|
-
})) return [];
|
|
3920
|
-
let o = String(t.MessageId || "");
|
|
3921
|
-
return [{
|
|
3922
|
-
id: o && o !== String(e.MessageId || "") ? o : `${o || e.MessageId || e.SeqId || "message"}:a2ui:${r}:${n}`,
|
|
3923
|
-
role: "a2ui",
|
|
3924
|
-
content: "",
|
|
3925
|
-
timestamp: Dn(e.Timestamp),
|
|
3926
|
-
aguiActivity: {
|
|
3927
|
-
surfaceId: r,
|
|
3928
|
-
messages: l(a)
|
|
3929
|
-
}
|
|
3930
|
-
}];
|
|
3931
|
-
}) : [];
|
|
3932
|
-
}
|
|
3933
|
-
function Fn(e) {
|
|
3934
|
-
return e.flatMap((e) => [Nn(e), ...Pn(e)]);
|
|
3935
|
-
}
|
|
3936
|
-
//#endregion
|
|
3937
|
-
//#region src/utils/session-event-history.ts
|
|
3938
|
-
var In = class extends Error {
|
|
3939
|
-
seq;
|
|
3940
|
-
constructor(e) {
|
|
3941
|
-
super(`Session event seq ${e} was received twice with conflicting content`), this.name = "SessionEventConflictError", this.seq = e;
|
|
3942
|
-
}
|
|
3943
|
-
};
|
|
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";
|
|
3946
|
-
}
|
|
3947
|
-
var Rn = new Set(["runtime"]), zn = class {
|
|
3948
|
-
eventsBySeq = /* @__PURE__ */ new Map();
|
|
3949
|
-
lastSeqValue = 0;
|
|
3950
|
-
accept(e) {
|
|
3951
|
-
let t = Fe(e);
|
|
3952
|
-
if (!t.ok) throw t.error;
|
|
3953
|
-
let n = t.value, r = this.eventsBySeq.get(n.seq);
|
|
3954
|
-
if (r) {
|
|
3955
|
-
if (Ln(r) !== Ln(n)) throw new In(n.seq);
|
|
3956
|
-
return;
|
|
3957
|
-
}
|
|
3958
|
-
this.eventsBySeq.set(n.seq, n), this.lastSeqValue = Math.max(this.lastSeqValue, n.seq);
|
|
3959
|
-
}
|
|
3960
|
-
get lastSeq() {
|
|
3961
|
-
return this.lastSeqValue;
|
|
3962
|
-
}
|
|
3963
|
-
reconnectAfterSeq() {
|
|
3964
|
-
return this.lastSeqValue;
|
|
3965
|
-
}
|
|
3966
|
-
displayableEvents() {
|
|
3967
|
-
return [...this.eventsBySeq.values()].filter((e) => Rn.has(e.family)).sort((e, t) => e.seq - t.seq);
|
|
3968
|
-
}
|
|
3969
|
-
};
|
|
3970
|
-
function Bn() {
|
|
3971
|
-
return new zn();
|
|
3972
|
-
}
|
|
3973
|
-
//#endregion
|
|
3974
|
-
//#region src/hooks/useSessionLifecycle.ts
|
|
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) {
|
|
3984
|
-
return new Promise((t) => {
|
|
3985
|
-
if (e.aborted) {
|
|
3986
|
-
t();
|
|
3987
|
-
return;
|
|
3988
|
-
}
|
|
3989
|
-
let n = globalThis.setTimeout(t, Vn);
|
|
3990
|
-
e.addEventListener("abort", () => {
|
|
3991
|
-
globalThis.clearTimeout(n), t();
|
|
3992
|
-
}, { once: !0 });
|
|
3993
|
-
});
|
|
3994
|
-
}
|
|
3995
|
-
var Yn = new Set([
|
|
3996
|
-
"in_progress",
|
|
3997
|
-
"running",
|
|
3998
|
-
"resuming",
|
|
3999
|
-
"starting"
|
|
4000
|
-
]);
|
|
4001
|
-
function Xn(e) {
|
|
4002
|
-
let t = e.ActiveRunUpdatedAt || e.UpdatedAt, n = typeof t == "number" ? t > 1e11 ? t : t * 1e3 : Date.parse(String(t || ""));
|
|
4003
|
-
return Number.isFinite(n) && n <= Date.now() + qn && Date.now() - n <= qn;
|
|
4004
|
-
}
|
|
4005
|
-
function Zn(e) {
|
|
4006
|
-
let t = P(e);
|
|
4007
|
-
return t ? t === "completed" ? {
|
|
4008
|
-
status: "completed",
|
|
4009
|
-
phase: "后台长任务已完成"
|
|
4010
|
-
} : t === "cancelled" || t === "canceled" || t === "aborted" ? {
|
|
4011
|
-
status: "stopped",
|
|
4012
|
-
phase: "后台长任务已取消"
|
|
4013
|
-
} : t === "interrupted" ? {
|
|
4014
|
-
status: "stopped",
|
|
4015
|
-
phase: "后台长任务已中断"
|
|
4016
|
-
} : t === "failed" || t === "error" ? {
|
|
4017
|
-
status: "failed",
|
|
4018
|
-
phase: "后台长任务失败"
|
|
4019
|
-
} : t === "resume_failed" ? {
|
|
4020
|
-
status: "failed",
|
|
4021
|
-
phase: "后台长任务恢复失败"
|
|
4022
|
-
} : null : null;
|
|
4023
|
-
}
|
|
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));
|
|
4027
|
-
if (!i.length) return;
|
|
4028
|
-
let a = await Promise.all(i.map(async (r) => {
|
|
4029
|
-
try {
|
|
4030
|
-
let i = await n.getResponseFeedback({
|
|
4031
|
-
AgentId: e,
|
|
4032
|
-
SessionId: t,
|
|
4033
|
-
ResponseId: r.responseId,
|
|
4034
|
-
EventId: r.eventId
|
|
4035
|
-
}), a = i?.Feedback ? S(i.Feedback) : null;
|
|
4036
|
-
return a ? {
|
|
4037
|
-
messageId: r.id,
|
|
4038
|
-
feedback: a
|
|
4039
|
-
} : null;
|
|
4040
|
-
} catch (e) {
|
|
4041
|
-
return console.error("Failed to load response feedback:", e), null;
|
|
4042
|
-
}
|
|
4043
|
-
}));
|
|
4044
|
-
if (f.current !== t) return;
|
|
4045
|
-
let o = new Map(a.filter((e) => !!e).map((e) => [e.messageId, e.feedback]));
|
|
4046
|
-
o.size && E.getState().patchMessages((e) => e.map((e) => o.has(e.id) ? {
|
|
4047
|
-
...e,
|
|
4048
|
-
feedback: o.get(e.id)
|
|
4049
|
-
} : e));
|
|
4050
|
-
}, [n]), N = L(async (e) => {
|
|
4051
|
-
m.current?.abort();
|
|
4052
|
-
let t = new AbortController();
|
|
4053
|
-
m.current = t;
|
|
4054
|
-
let r = !1, i = !1, a = e.afterSeqId, o = () => m.current === t && f.current === e.sessionId;
|
|
4055
|
-
try {
|
|
4056
|
-
for (c.getState().setCurrentRunId(e.invocationId), c.getState().setActiveInvocationId(e.invocationId), c.getState().setSessionStreaming(e.sessionId, !0), c.getState().updateActivity({
|
|
4057
|
-
sessionId: e.sessionId,
|
|
4058
|
-
status: "running",
|
|
4059
|
-
phase: "后台长任务运行中",
|
|
4060
|
-
detail: e.invocationId,
|
|
4061
|
-
countEvent: !1
|
|
4062
|
-
}); !i && o();) {
|
|
4063
|
-
try {
|
|
4064
|
-
let s = await n.subscribeRunEvents({
|
|
4065
|
-
sessionId: e.sessionId,
|
|
4066
|
-
invocationId: e.invocationId,
|
|
4067
|
-
afterSeqId: a
|
|
4068
|
-
}, { signal: t.signal });
|
|
4069
|
-
if (!o()) {
|
|
4070
|
-
t.abort();
|
|
4071
|
-
return;
|
|
4072
|
-
}
|
|
4073
|
-
let l = s.getReader(), u = new TextDecoder(), d = "";
|
|
4074
|
-
for (; !i && o();) {
|
|
4075
|
-
let { value: t, done: n } = await l.read();
|
|
4076
|
-
if (n) break;
|
|
4077
|
-
d += u.decode(t, { stream: !0 });
|
|
4078
|
-
let s = jt(d);
|
|
4079
|
-
d = s.remainder;
|
|
4080
|
-
for (let t of s.chunks) if (t.trim()) {
|
|
4081
|
-
for (let n of Y(t)) {
|
|
4082
|
-
if (n.eventName === "__ping__") {
|
|
4083
|
-
c.getState().updateActivity({
|
|
4084
|
-
sessionId: e.sessionId,
|
|
4085
|
-
status: "running",
|
|
4086
|
-
countEvent: !1
|
|
4087
|
-
});
|
|
4088
|
-
continue;
|
|
4089
|
-
}
|
|
4090
|
-
if (n.eventName === "__done__") {
|
|
4091
|
-
i = !0, r = !0;
|
|
4092
|
-
break;
|
|
4093
|
-
}
|
|
4094
|
-
if (!n.data || typeof n.data != "object") continue;
|
|
4095
|
-
let t = n.data;
|
|
4096
|
-
if (!o()) break;
|
|
4097
|
-
if (t.InvocationId && t.InvocationId !== e.invocationId) continue;
|
|
4098
|
-
if (typeof t.seq == "number") {
|
|
4099
|
-
try {
|
|
4100
|
-
h.current.accept(t);
|
|
4101
|
-
} catch (e) {
|
|
4102
|
-
console.error("[SessionLifecycle] session event cursor conflict:", e);
|
|
4103
|
-
}
|
|
4104
|
-
a = Math.max(a, h.current.reconnectAfterSeq()), xn({
|
|
4105
|
-
type: "stream_event",
|
|
4106
|
-
sessionId: e.sessionId,
|
|
4107
|
-
event: t
|
|
4108
|
-
}), i ||= ee(t), r ||= i;
|
|
4109
|
-
let n = Zn(t);
|
|
4110
|
-
n && c.getState().updateActivity({
|
|
4111
|
-
sessionId: e.sessionId,
|
|
4112
|
-
status: n.status,
|
|
4113
|
-
phase: n.phase,
|
|
4114
|
-
detail: e.invocationId,
|
|
4115
|
-
countEvent: !1
|
|
4116
|
-
});
|
|
4117
|
-
continue;
|
|
4118
|
-
}
|
|
4119
|
-
let s = Number(t.SeqId || 0);
|
|
4120
|
-
Number.isFinite(s) && (a = Math.max(a, s)), xn({
|
|
4121
|
-
type: "stream_event",
|
|
4122
|
-
sessionId: e.sessionId,
|
|
4123
|
-
event: t
|
|
4124
|
-
}), i ||= ee(t), r ||= i;
|
|
4125
|
-
let l = Zn(t);
|
|
4126
|
-
if (l && c.getState().updateActivity({
|
|
4127
|
-
sessionId: e.sessionId,
|
|
4128
|
-
status: l.status,
|
|
4129
|
-
phase: l.phase,
|
|
4130
|
-
detail: e.invocationId,
|
|
4131
|
-
countEvent: !1
|
|
4132
|
-
}), i) break;
|
|
4133
|
-
}
|
|
4134
|
-
if (i) break;
|
|
4135
|
-
}
|
|
4136
|
-
}
|
|
4137
|
-
i && l.cancel().catch(() => {});
|
|
4138
|
-
} catch (t) {
|
|
4139
|
-
if (t instanceof DOMException && t.name === "AbortError" || !o()) break;
|
|
4140
|
-
console.warn("Run event subscription disconnected; retrying:", t), c.getState().updateActivity({
|
|
4141
|
-
sessionId: e.sessionId,
|
|
4142
|
-
status: "waiting",
|
|
4143
|
-
phase: "恢复连接中",
|
|
4144
|
-
detail: e.invocationId,
|
|
4145
|
-
countEvent: !1
|
|
4146
|
-
});
|
|
4147
|
-
}
|
|
4148
|
-
!i && o() && await Jn(t.signal);
|
|
4149
|
-
}
|
|
4150
|
-
i && o() && xn({
|
|
4151
|
-
type: "stream_ended",
|
|
4152
|
-
sessionId: e.sessionId
|
|
4153
|
-
});
|
|
4154
|
-
} catch (e) {
|
|
4155
|
-
e instanceof DOMException && e.name === "AbortError" || console.error("Failed to subscribe run events:", e);
|
|
4156
|
-
} finally {
|
|
4157
|
-
let n = m.current === t;
|
|
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));
|
|
4159
|
-
}
|
|
4160
|
-
}, [n]), P = L((e) => {
|
|
4161
|
-
!l.RunLifecycle.Enabled || !e.runId || p.current !== t || f.current !== e.sessionId || m.current || N({
|
|
4162
|
-
sessionId: e.sessionId,
|
|
4163
|
-
invocationId: e.runId,
|
|
4164
|
-
afterSeqId: se(D.current.get(e.sessionId)?.events || [])
|
|
4165
|
-
});
|
|
4166
|
-
}, [
|
|
4167
|
-
t,
|
|
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);
|
|
4179
|
-
try {
|
|
4180
|
-
let t = {
|
|
4181
|
-
limit: Un,
|
|
4182
|
-
includeReasoning: !0,
|
|
4183
|
-
includeToolEvents: !0,
|
|
4184
|
-
includeAttachments: !0
|
|
4185
|
-
}, r;
|
|
4186
|
-
try {
|
|
4187
|
-
r = await n.listSessionMessages(e, t);
|
|
4188
|
-
} catch (i) {
|
|
4189
|
-
if (i instanceof H) throw i;
|
|
4190
|
-
if (await new Promise((e) => globalThis.setTimeout(e, 180)), !h()) return;
|
|
4191
|
-
r = await n.listSessionMessages(e, t);
|
|
4192
|
-
}
|
|
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, {
|
|
4198
|
-
nextCursor: r.NextCursor,
|
|
4199
|
-
hasMore: r.HasMore
|
|
4200
|
-
}), a.getState().setSessionInitialMessageHistoryLoading(e, !1);
|
|
4201
|
-
try {
|
|
4202
|
-
let t = await n.listSessionEvents(e, {
|
|
4203
|
-
offset: 0,
|
|
4204
|
-
limit: Wn
|
|
4205
|
-
});
|
|
4206
|
-
if (!h()) return;
|
|
4207
|
-
let o = {
|
|
4208
|
-
events: t.Events || [],
|
|
4209
|
-
loadedCount: t.Events?.length || 0,
|
|
4210
|
-
total: Math.max(0, Number(t.Total ?? t.Events?.length ?? 0) || 0)
|
|
4211
|
-
};
|
|
4212
|
-
if ($(D.current, e, o, f.current), a.getState().setSessionMessageHistory(e, {
|
|
4213
|
-
nextCursor: r.NextCursor,
|
|
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);
|
|
4220
|
-
}
|
|
4221
|
-
} catch (e) {
|
|
4222
|
-
h() && (y.current = {
|
|
4223
|
-
generation: o,
|
|
4224
|
-
message: "完整事件历史读取失败,请刷新会话后重新查找。当前结果只包含已读取的正文。"
|
|
4225
|
-
}), console.warn("[SessionLifecycle] canonical history replay failed:", e);
|
|
4226
|
-
}
|
|
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({
|
|
4231
|
-
agentId: p.current,
|
|
4232
|
-
sessionId: e
|
|
4233
|
-
}).then((t) => {
|
|
4234
|
-
h() && b.getState().setSessionCheckpoints(e, t.Checkpoints || []);
|
|
4235
|
-
}).catch((t) => {
|
|
4236
|
-
h() && (console.warn("[SessionLifecycle] checkpoint load failed:", t), b.getState().setSessionCheckpoints(e, []));
|
|
4237
|
-
}), n.listToolReceipts({
|
|
4238
|
-
agentId: p.current,
|
|
4239
|
-
sessionId: e
|
|
4240
|
-
}).then((t) => {
|
|
4241
|
-
h() && b.getState().setSessionToolReceipts(e, t.ToolReceipts || []);
|
|
4242
|
-
}).catch((t) => {
|
|
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 {
|
|
4245
|
-
let t = await n.getSession(e);
|
|
4246
|
-
if (!h()) return;
|
|
4247
|
-
let r = String(t.ActiveRunStatus || "").toLowerCase();
|
|
4248
|
-
t.ActiveInvocationId && (Yn.has(r) || r === "" && Xn(t)) && N({
|
|
4249
|
-
sessionId: e,
|
|
4250
|
-
invocationId: t.ActiveInvocationId,
|
|
4251
|
-
afterSeqId: g
|
|
4252
|
-
});
|
|
4253
|
-
} catch (e) {
|
|
4254
|
-
console.warn("[SessionLifecycle] getSession for reconnect failed:", e);
|
|
4255
|
-
}
|
|
4256
|
-
} catch (e) {
|
|
4257
|
-
h() && (y.current = {
|
|
4258
|
-
generation: o,
|
|
4259
|
-
message: "会话历史读取失败,请刷新会话后重新查找。"
|
|
4260
|
-
}), console.error("Failed to load session messages:", e);
|
|
4261
|
-
} finally {
|
|
4262
|
-
_.current === o && (_.current = null), h() && a.getState().setSessionInitialMessageHistoryLoading(e, !1);
|
|
4263
|
-
}
|
|
4264
|
-
}, [
|
|
4265
|
-
n,
|
|
4266
|
-
r,
|
|
4267
|
-
M,
|
|
4268
|
-
i,
|
|
4269
|
-
N,
|
|
4270
|
-
l
|
|
4271
|
-
]), I = L(async (e = "default-agent", t = null) => {
|
|
4272
|
-
try {
|
|
4273
|
-
let r = a.getState();
|
|
4274
|
-
r.sessionsAgentId && r.sessionsAgentId !== e && r.resetSessionPagination(e), a.getState().setLoadingSessions(!0);
|
|
4275
|
-
let i = await n.listSessions(e, {
|
|
4276
|
-
page: 1,
|
|
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, {
|
|
4284
|
-
agentId: e,
|
|
4285
|
-
total: Number(i.Total ?? i.Sessions?.length ?? 0),
|
|
4286
|
-
page: Number(i.Page ?? 1),
|
|
4287
|
-
pageSize: Number(i.PageSize ?? Hn),
|
|
4288
|
-
replace: !0
|
|
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);
|
|
4292
|
-
} catch (e) {
|
|
4293
|
-
if (e instanceof H) return;
|
|
4294
|
-
console.error("Failed to fetch sessions:", e);
|
|
4295
|
-
} finally {
|
|
4296
|
-
W.getState().agentId === e && a.getState().setLoadingSessions(!1);
|
|
4297
|
-
}
|
|
4298
|
-
}, [
|
|
4299
|
-
n,
|
|
4300
|
-
F,
|
|
4301
|
-
d
|
|
4302
|
-
]), te = L(async () => {
|
|
4303
|
-
let e = a.getState();
|
|
4304
|
-
if (e.isLoadingSessions || !e.hasMoreSessions) return;
|
|
4305
|
-
let t = o({
|
|
4306
|
-
total: e.sessionsTotal,
|
|
4307
|
-
pageSize: e.sessionsPageSize || Hn,
|
|
4308
|
-
loadedPages: e.loadedPages
|
|
4309
|
-
});
|
|
4310
|
-
if (!t) return;
|
|
4311
|
-
let r = e.sessionsPageSize || Hn, i = e.sessionsAgentId || p.current || "default-agent";
|
|
4312
|
-
try {
|
|
4313
|
-
a.getState().setLoadingSessions(!0);
|
|
4314
|
-
let o = await n.listSessions(i, {
|
|
4315
|
-
page: t,
|
|
4316
|
-
pageSize: r
|
|
4317
|
-
});
|
|
4318
|
-
a.getState().upsertSessions(o.Sessions || [], {
|
|
4319
|
-
agentId: i,
|
|
4320
|
-
total: Number(o.Total ?? e.sessionsTotal),
|
|
4321
|
-
page: Number(o.Page ?? t),
|
|
4322
|
-
pageSize: Number(o.PageSize ?? r)
|
|
4323
|
-
});
|
|
4324
|
-
} catch (e) {
|
|
4325
|
-
if (e instanceof H) return;
|
|
4326
|
-
console.error("Failed to load more sessions:", e);
|
|
4327
|
-
} finally {
|
|
4328
|
-
a.getState().setLoadingSessions(!1);
|
|
4329
|
-
}
|
|
4330
|
-
}, [n]);
|
|
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([{
|
|
4338
|
-
SessionId: e,
|
|
4339
|
-
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
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([]);
|
|
4349
|
-
let e = n.createSession(t).then((e) => {
|
|
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;
|
|
4354
|
-
try {
|
|
4355
|
-
await e;
|
|
4356
|
-
} finally {
|
|
4357
|
-
k.current === e && (k.current = null);
|
|
4358
|
-
}
|
|
4359
|
-
}, [
|
|
4360
|
-
ne,
|
|
4361
|
-
t,
|
|
4362
|
-
n
|
|
4363
|
-
]), ae = L(async () => {
|
|
4364
|
-
let e = k.current;
|
|
4365
|
-
return e ? await e : f.current;
|
|
4366
|
-
}, []), ce = L(async (e) => {
|
|
4367
|
-
try {
|
|
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;
|
|
4370
|
-
} catch (e) {
|
|
4371
|
-
return e instanceof H ? !1 : (console.error("Failed to delete session", e), s.getState().pushToast("删除会话失败,请稍后重试。", "error"), !1);
|
|
4372
|
-
}
|
|
4373
|
-
}, [
|
|
4374
|
-
t,
|
|
4375
|
-
n,
|
|
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);
|
|
4410
|
-
}
|
|
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,
|
|
4449
|
-
currentSessionIdRef: f,
|
|
4450
|
-
agentIdRef: p,
|
|
4451
|
-
runSubscriptionAbortRef: m
|
|
4452
|
-
};
|
|
4453
|
-
}
|
|
4454
|
-
//#endregion
|
|
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 };
|