@kingsoftcloud/ksadk-web 0.3.15 → 0.3.17
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 +13 -0
- package/README.md +2 -2
- package/RELEASE_PROVENANCE.json +2 -2
- package/dist-ksadk/assets/{ArtifactsPanel-ND1ni01O.js → ArtifactsPanel-DYzXIPnl.js} +1 -1
- package/dist-ksadk/assets/{CodeBlock-Bm987IV9.js → CodeBlock-Dpa-tOmG.js} +1 -1
- package/dist-ksadk/assets/{MathMessageMarkdown-m289SxEv.js → MathMessageMarkdown-D8kBE9sl.js} +1 -1
- package/dist-ksadk/assets/{MermaidBlock-Draq-3W4.js → MermaidBlock-BYOoZB-_.js} +6 -6
- package/dist-ksadk/assets/{NativeTerminalPanel-BPKj9OEV.js → NativeTerminalPanel-CAeXHeo6.js} +1 -1
- package/dist-ksadk/assets/{OfficialA2uiRenderer-Buvy4tjx.js → OfficialA2uiRenderer-yPb3s23n.js} +1 -1
- package/dist-ksadk/assets/{abnfDiagram-VCTEODGH-DSkvfGF3.js → abnfDiagram-VCTEODGH-DdVxMn2L.js} +1 -1
- package/dist-ksadk/assets/{arc-D2OD6TRH.js → arc-DsOMYRTm.js} +1 -1
- package/dist-ksadk/assets/architecture-7GRP2DOG-Ds1NB530.js +1 -0
- package/dist-ksadk/assets/{architectureDiagram-5GKGNRK7-BAGaNeP_.js → architectureDiagram-5GKGNRK7-BCfzi23_.js} +1 -1
- package/dist-ksadk/assets/{blockDiagram-NRAW4CY4-CE77-fsa.js → blockDiagram-NRAW4CY4-gC-Gc2Xv.js} +1 -1
- package/dist-ksadk/assets/{c4Diagram-UCG6FXSJ-QM8LLt8e.js → c4Diagram-UCG6FXSJ-BAHemGZa.js} +1 -1
- package/dist-ksadk/assets/channel-B4PiWfnA.js +1 -0
- package/dist-ksadk/assets/chunk-2Q5K7J3B-CI2tn5IS.js +1 -0
- package/dist-ksadk/assets/{chunk-5VM5RSS4-NBYbb28t.js → chunk-5VM5RSS4-Cthhs8Yv.js} +1 -1
- package/dist-ksadk/assets/{chunk-F27PBJKO-xaO4b0PR.js → chunk-F27PBJKO-BPV04XpW.js} +1 -1
- package/dist-ksadk/assets/{chunk-G27WJ6UU-Bi73NhBu.js → chunk-G27WJ6UU-Cl1n0gHd.js} +1 -1
- package/dist-ksadk/assets/{chunk-JWPE2WC7-CngFBp9d.js → chunk-JWPE2WC7-DqkIh_LK.js} +1 -1
- package/dist-ksadk/assets/{chunk-LCL6LL3I-BsunO5Rx.js → chunk-LCL6LL3I-DZhAKY7Z.js} +1 -1
- package/dist-ksadk/assets/{chunk-POPQ4Y6H-ImP4Ew8y.js → chunk-POPQ4Y6H-BGuhTofV.js} +1 -1
- package/dist-ksadk/assets/{chunk-RHFEMEQ7-CdQmbok4.js → chunk-RHFEMEQ7-DhrRHdJ6.js} +1 -1
- package/dist-ksadk/assets/{chunk-SVP7TREG-ExibL7Ea.js → chunk-SVP7TREG-CIdm5TIa.js} +1 -1
- package/dist-ksadk/assets/{chunk-XXDRQBXY-Bz850mDu.js → chunk-XXDRQBXY-CNIlGK4v.js} +1 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-BMQzydMm.js +1 -0
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-BMQzydMm.js +1 -0
- package/dist-ksadk/assets/{cose-bilkent-JH36ORCC-C0xUJvyH.js → cose-bilkent-JH36ORCC-BjauSFl3.js} +1 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-DcGwq_cA.js +1 -0
- package/dist-ksadk/assets/{cynefinDiagram-5FMLGOSQ-DV2coA_s.js → cynefinDiagram-5FMLGOSQ-DPszkr1j.js} +1 -1
- package/dist-ksadk/assets/{dagre-3AP2YEHR-jEooZQ_X.js → dagre-3AP2YEHR-Ds2xBGA0.js} +1 -1
- package/dist-ksadk/assets/{dagre-ljD7-f9M.js → dagre-Dr0YPDPm.js} +1 -1
- package/dist-ksadk/assets/{diagram-S7CK7UJ4-B5BoTuaY.js → diagram-S7CK7UJ4-BOQfgaW5.js} +1 -1
- package/dist-ksadk/assets/{diagram-UQ7AKVKN-Cvxn92tK.js → diagram-UQ7AKVKN-DMMyB2sa.js} +1 -1
- package/dist-ksadk/assets/{diagram-VSXAHHWV-CI86Na4n.js → diagram-VSXAHHWV-DZR1nzPa.js} +1 -1
- package/dist-ksadk/assets/{diagram-VX7I27RA-CeZud7ml.js → diagram-VX7I27RA-DzAwLHuI.js} +1 -1
- package/dist-ksadk/assets/{diagram-Z3DM3KII-GeJxYdqI.js → diagram-Z3DM3KII-D98d_Dgt.js} +1 -1
- package/dist-ksadk/assets/{dist-CJuVeKiz.js → dist-A55dc8b7.js} +1 -1
- package/dist-ksadk/assets/{dist-BtermLVk.js → dist-BEzIxZLq.js} +1 -1
- package/dist-ksadk/assets/{dist-BxicrSj5.js → dist-BHIb3Gvv.js} +1 -1
- package/dist-ksadk/assets/{dist-Dk6TLega.js → dist-BIR7kFKG.js} +1 -1
- package/dist-ksadk/assets/{dist-Dig9D26k.js → dist-BpZXLW0T.js} +1 -1
- package/dist-ksadk/assets/{dist-lHe3BnLM.js → dist-By8HbjFH.js} +1 -1
- package/dist-ksadk/assets/{dist-ubZkVDhc.js → dist-C1uAMNTH.js} +1 -1
- package/dist-ksadk/assets/{dist-C7H9f-JT.js → dist-CN8MSPvo.js} +1 -1
- package/dist-ksadk/assets/{dist-eYoWaedR.js → dist-CpHO1CY1.js} +1 -1
- package/dist-ksadk/assets/{dist-BcNp5ouu.js → dist-CxzBVC3N.js} +1 -1
- package/dist-ksadk/assets/{dist-D2IRjZmI.js → dist-D9GtQnvz.js} +1 -1
- package/dist-ksadk/assets/{dist-CmWGM_T9.js → dist-DHiOUJJ-.js} +1 -1
- package/dist-ksadk/assets/{dist-Cgh3LKbI.js → dist-Du5KbDTg.js} +1 -1
- package/dist-ksadk/assets/{dist-CXo9VOuF.js → dist-DxBl1V2_.js} +1 -1
- package/dist-ksadk/assets/{dist-BiarszCa.js → dist-E1uwqlZY.js} +1 -1
- package/dist-ksadk/assets/{dist-BOBeN4EW.js → dist-HuJDn2Nr.js} +1 -1
- package/dist-ksadk/assets/{dist-BgCDfLfr.js → dist-MMIlBueM.js} +1 -1
- package/dist-ksadk/assets/{dist-IuOndGF_.js → dist-U51Rn7ZW.js} +1 -1
- package/dist-ksadk/assets/{dist-nOyq5Gq7.js → dist-VLWgeZIu.js} +1 -1
- package/dist-ksadk/assets/{dist-XaciJNLw.js → dist-X8Mgnqit.js} +1 -1
- package/dist-ksadk/assets/{dist-B_y4v6Vh.js → dist-glVlUB_d.js} +1 -1
- package/dist-ksadk/assets/{dist-CWaqQiTL.js → dist-q8rONmMl.js} +1 -1
- package/dist-ksadk/assets/{ebnfDiagram-PWID7BFC-CVnEnD_Y.js → ebnfDiagram-PWID7BFC-X4mBLaw3.js} +1 -1
- package/dist-ksadk/assets/{erDiagram-SSCWMZ5O-gaG6xmRn.js → erDiagram-SSCWMZ5O-ClybQoOy.js} +1 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV--IdqCKdV.js +1 -0
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-BsidNZBX.js +1 -0
- package/dist-ksadk/assets/{ganttDiagram-EL5Y4UJY-Yov_MdHm.js → ganttDiagram-EL5Y4UJY-Dc_fWiA_.js} +1 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-BTqI4bBo.js +1 -0
- package/dist-ksadk/assets/{gitGraphDiagram-WWUBYQGX-pCt6JiWp.js → gitGraphDiagram-WWUBYQGX-0eEV_CEC.js} +1 -1
- package/dist-ksadk/assets/index-B0DeBpyZ.js +1132 -0
- package/dist-ksadk/assets/index-DEVfafsU.css +2 -0
- package/dist-ksadk/assets/info-A6RAGUB7-CXZCoW0H.js +1 -0
- package/dist-ksadk/assets/{infoDiagram-RXCK75RN-Df7QB9IZ.js → infoDiagram-RXCK75RN-mZoyw4Xh.js} +1 -1
- package/dist-ksadk/assets/{ishikawaDiagram-5VMMS53U-BxZM8H3E.js → ishikawaDiagram-5VMMS53U-CO8OkxgJ.js} +1 -1
- package/dist-ksadk/assets/{journeyDiagram-EYS64GPL-DXJc7vNQ.js → journeyDiagram-EYS64GPL-Ci8GpXLK.js} +1 -1
- package/dist-ksadk/assets/{kanban-definition-3QL26DDD-uGr_y_n5.js → kanban-definition-3QL26DDD-lgD5AYON.js} +1 -1
- package/dist-ksadk/assets/{katex-C34HoTrL.js → katex-Chn0O-XC.js} +1 -1
- package/dist-ksadk/assets/{linear-C7-Mijzq.js → linear-ffygyi0f.js} +1 -1
- package/dist-ksadk/assets/{mermaid-parser.core-DH4-hsMU.js → mermaid-parser.core-CGPz1_57.js} +2 -2
- package/dist-ksadk/assets/{mindmap-definition-FBJOCRG2-5UJYSEer.js → mindmap-definition-FBJOCRG2-DRaJyZGQ.js} +1 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-DoZlIRtk.js +1 -0
- package/dist-ksadk/assets/{pegDiagram-XKGWAZYB-BPdl55Nd.js → pegDiagram-XKGWAZYB-BbQ2QDD3.js} +1 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-Dl-IyMT_.js +1 -0
- package/dist-ksadk/assets/{pieDiagram-E7YTZNPT-cDC3mpF_.js → pieDiagram-E7YTZNPT-BcB_c4Ka.js} +1 -1
- package/dist-ksadk/assets/{quadrantDiagram-AXDQQJYC-7jhGjy86.js → quadrantDiagram-AXDQQJYC-CK3csxHk.js} +1 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-Bp8MemxX.js +1 -0
- package/dist-ksadk/assets/railroad-74A4TZTK-BmKyKako.js +1 -0
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-DhFitwOH.js +1 -0
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-TB8LQz8q.js +1 -0
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-B3J1Rtq9.js +1 -0
- package/dist-ksadk/assets/{railroadDiagram-O6MQD6OU-DdTXYjCz.js → railroadDiagram-O6MQD6OU-D1YLglVU.js} +1 -1
- package/dist-ksadk/assets/{requirementDiagram-EFPCY7ZU-BxH5im9j.js → requirementDiagram-EFPCY7ZU-VeyqOcw3.js} +1 -1
- package/dist-ksadk/assets/{sankeyDiagram-P5KCCOFB-BrTs-PhV.js → sankeyDiagram-P5KCCOFB-uskDVCah.js} +1 -1
- package/dist-ksadk/assets/{sequenceDiagram-WJ2MYXX4-B-GvSk9Z.js → sequenceDiagram-WJ2MYXX4-CmoPC4aR.js} +1 -1
- package/dist-ksadk/assets/{sizeCapture-X5ZJPWSS-CxP3dmNT.js → sizeCapture-X5ZJPWSS-DzV4X5WN.js} +1 -1
- package/dist-ksadk/assets/{stateDiagram-HBIQ2CUA-CIw-mH34.js → stateDiagram-HBIQ2CUA-BJehrZbH.js} +1 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-DkujIgVj.js +1 -0
- package/dist-ksadk/assets/{swimlanes-XN3QIQJK-YZIWfS0x.js → swimlanes-XN3QIQJK-Bn4tEi27.js} +1 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-Blb1TQ9Q.js +8 -0
- package/dist-ksadk/assets/{timeline-definition-24CTP7MA-CJ63qwLI.js → timeline-definition-24CTP7MA-bSkaKxqF.js} +1 -1
- package/dist-ksadk/assets/treeView-Q6P3EWNA-C5Ez-6L4.js +1 -0
- package/dist-ksadk/assets/treemap-WGGIJYW6-WdNvoGQV.js +1 -0
- package/dist-ksadk/assets/{vennDiagram-4TSXK5OY-DimJA1nS.js → vennDiagram-4TSXK5OY-ClO6s5iT.js} +1 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-DCCceTuX.js +1 -0
- package/dist-ksadk/assets/{wardleyDiagram-VM6X3IG4-Wf93ZvjN.js → wardleyDiagram-VM6X3IG4-CcaYar33.js} +1 -1
- package/dist-ksadk/assets/{xychartDiagram-S5SC5T6Z-B2A1aC7t.js → xychartDiagram-S5SC5T6Z-DdiPl8uB.js} +1 -1
- package/dist-ksadk/index.html +2 -2
- package/dist-lib/App.d.ts.map +1 -1
- package/dist-lib/AttachmentPreview-DHvWB_a-.js +1956 -0
- package/dist-lib/ConnectedComposer-CuN3EUnU.js +872 -0
- package/dist-lib/{ConnectedMessageList-Dhudkynn.js → ConnectedMessageList-CT-MJJkJ.js} +444 -442
- package/dist-lib/{WorkspacePanelContainer-CA59c9AQ.js → WorkspacePanelContainer-Jg9bUmLJ.js} +321 -321
- package/dist-lib/{a2ui-D2QH7eTV.js → a2ui-DridcTyF.js} +1717 -447
- package/dist-lib/{capabilities-DAeBY-WO.js → capabilities-lJRDfRg9.js} +46 -33
- package/dist-lib/capabilities.js +1 -1
- package/dist-lib/chat-composer.js +2 -2
- package/dist-lib/chat-timeline.js +3 -3
- package/dist-lib/components/chat/A2UIActivityMessage.d.ts +1 -0
- package/dist-lib/components/chat/A2UIActivityMessage.d.ts.map +1 -1
- package/dist-lib/components/chat/ChatComposer.d.ts +4 -2
- package/dist-lib/components/chat/ChatComposer.d.ts.map +1 -1
- package/dist-lib/components/chat/ChatMessageList.d.ts.map +1 -1
- package/dist-lib/components/chat/ConnectedComposer.d.ts +4 -2
- package/dist-lib/components/chat/ConnectedComposer.d.ts.map +1 -1
- package/dist-lib/components/chat/ExecutionPermissionMenu.d.ts +11 -0
- package/dist-lib/components/chat/ExecutionPermissionMenu.d.ts.map +1 -0
- package/dist-lib/components/chat/InteractionA2uiSurface.d.ts +6 -1
- package/dist-lib/components/chat/InteractionA2uiSurface.d.ts.map +1 -1
- package/dist-lib/components/chat/InteractionTray.d.ts +3 -1
- package/dist-lib/components/chat/InteractionTray.d.ts.map +1 -1
- package/dist-lib/components/chat/JsonSchemaInputForm.d.ts.map +1 -1
- package/dist-lib/components/chat/McpAuthorizationCard.d.ts +8 -0
- package/dist-lib/components/chat/McpAuthorizationCard.d.ts.map +1 -0
- package/dist-lib/components/chat/permission-menu-visibility.d.ts +7 -0
- package/dist-lib/components/chat/permission-menu-visibility.d.ts.map +1 -0
- package/dist-lib/components/ui/button.d.ts +12 -0
- package/dist-lib/components/ui/button.d.ts.map +1 -0
- package/dist-lib/components.js +13 -13
- package/dist-lib/conversation.js +2 -2
- package/dist-lib/core/api/facade.d.ts +1 -0
- package/dist-lib/core/api/facade.d.ts.map +1 -1
- package/dist-lib/core/api/types.d.ts +1 -0
- package/dist-lib/core/api/types.d.ts.map +1 -1
- package/dist-lib/core/conversation/presentation.d.ts.map +1 -1
- package/dist-lib/core/conversation/runtime-ingress.d.ts.map +1 -1
- package/dist-lib/core/interaction/a2ui-approval.d.ts +20 -0
- package/dist-lib/core/interaction/a2ui-approval.d.ts.map +1 -0
- package/dist-lib/core/interaction/adapters/agui.d.ts.map +1 -1
- package/dist-lib/core/interaction/adapters/normalize.d.ts +2 -0
- package/dist-lib/core/interaction/adapters/normalize.d.ts.map +1 -1
- package/dist-lib/core/interaction/adapters/responses.d.ts +14 -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.map +1 -1
- package/dist-lib/core/interaction/index.d.ts +16 -2
- package/dist-lib/core/interaction/index.d.ts.map +1 -1
- package/dist-lib/core/interaction/legacy-a2ui.d.ts +5 -0
- package/dist-lib/core/interaction/legacy-a2ui.d.ts.map +1 -0
- package/dist-lib/core/interaction/pending.d.ts +4 -0
- package/dist-lib/core/interaction/pending.d.ts.map +1 -0
- package/dist-lib/core/mcp-authorization/contract.d.ts +5 -0
- package/dist-lib/core/mcp-authorization/contract.d.ts.map +1 -0
- package/dist-lib/core/mcp-authorization/normalize.d.ts +4 -0
- package/dist-lib/core/mcp-authorization/normalize.d.ts.map +1 -0
- package/dist-lib/core/mcp-authorization/recovery.d.ts +5 -0
- package/dist-lib/core/mcp-authorization/recovery.d.ts.map +1 -0
- package/dist-lib/core/mcp-authorization/types.d.ts +20 -0
- package/dist-lib/core/mcp-authorization/types.d.ts.map +1 -0
- package/dist-lib/core/run/agui.d.ts.map +1 -1
- package/dist-lib/core/run/dispatcher.d.ts.map +1 -1
- package/dist-lib/core/run/engine.d.ts.map +1 -1
- package/dist-lib/core/run/types.d.ts +13 -0
- package/dist-lib/core/run/types.d.ts.map +1 -1
- package/dist-lib/core/stream/types.d.ts +11 -0
- package/dist-lib/core/stream/types.d.ts.map +1 -1
- package/dist-lib/core/teams/cloudContracts.d.ts +15 -15
- package/dist-lib/{feedback-DRgW061h.js → feedback-CaSZOBD2.js} +12 -22
- package/dist-lib/hooks/useAgentChat.d.ts.map +1 -1
- package/dist-lib/hooks/useInteractions.d.ts +1 -0
- package/dist-lib/hooks/useInteractions.d.ts.map +1 -1
- package/dist-lib/hooks/useSessionLifecycle.d.ts.map +1 -1
- package/dist-lib/hooks.js +58 -57
- package/dist-lib/{permission-CHy_uZD0.js → permission-2NpSBuq3.js} +1 -1
- package/dist-lib/{persisted-session-history-KtoKbLRA.js → persisted-session-history-D_1AtH5H.js} +536 -1457
- package/dist-lib/runtime.js +279 -276
- package/dist-lib/session-events-6PXUoAkP.js +1225 -0
- package/dist-lib/stores/bootstrap.d.ts.map +1 -1
- package/dist-lib/stores/execution-permission.d.ts +21 -0
- package/dist-lib/stores/execution-permission.d.ts.map +1 -0
- package/dist-lib/styles.css +1 -1
- package/dist-lib/types/capabilities.d.ts +14 -0
- package/dist-lib/types/capabilities.d.ts.map +1 -1
- package/dist-lib/{useSessionLifecycle-DNG3Yks2.js → useSessionLifecycle-daQg0sqQ.js} +1032 -1946
- package/dist-lib/utils/capabilities.d.ts.map +1 -1
- package/dist-lib/utils/persisted-session-history.d.ts.map +1 -1
- package/dist-lib/utils/responses-stream.d.ts.map +1 -1
- package/dist-lib/utils/run-progress.d.ts.map +1 -1
- package/dist-lib/utils/workspace.d.ts +1 -1
- package/package.json +1 -1
- package/dist-ksadk/assets/architecture-7GRP2DOG-vaJx2f97.js +0 -1
- package/dist-ksadk/assets/channel-qoLBikeO.js +0 -1
- package/dist-ksadk/assets/chunk-2Q5K7J3B-OLdkjA_5.js +0 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-DqbkClnv.js +0 -1
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-DqbkClnv.js +0 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-BnPp48kV.js +0 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV-BHS_Svvs.js +0 -1
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-BkQ0O0Ft.js +0 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-CSW-TIsw.js +0 -1
- package/dist-ksadk/assets/index-DMqhW2cV.css +0 -2
- package/dist-ksadk/assets/index-DcQSCIw4.js +0 -1132
- package/dist-ksadk/assets/info-A6RAGUB7-2r962Zht.js +0 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-C8AN0vyj.js +0 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-D8iGFt9t.js +0 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-BFDLv34s.js +0 -1
- package/dist-ksadk/assets/railroad-74A4TZTK-BCF2fZR0.js +0 -1
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-Ban_fK3c.js +0 -1
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-DKxLpd8o.js +0 -1
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-n_o0pjRU.js +0 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-CFLSAbtQ.js +0 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-CNHXQSl-.js +0 -8
- package/dist-ksadk/assets/treeView-Q6P3EWNA-B1wKifn0.js +0 -1
- package/dist-ksadk/assets/treemap-WGGIJYW6-DECztlF0.js +0 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-BSQgLjrP.js +0 -1
- package/dist-lib/AttachmentPreview-CPRjbiqd.js +0 -1545
- package/dist-lib/ConnectedComposer-CKnKpokV.js +0 -781
- package/dist-lib/json-value-DnHp0582.js +0 -186
- package/dist-lib/tool-display-DTiRdghE.js +0 -64
|
@@ -1,51 +1,49 @@
|
|
|
1
|
-
import { a as e, i as t,
|
|
2
|
-
import {
|
|
3
|
-
import { r as
|
|
4
|
-
import { a as
|
|
5
|
-
import {
|
|
6
|
-
import { a as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { z as W } from "zod";
|
|
10
|
-
import { HttpAgent as ke, buildResumeArray as Ae } from "@ag-ui/client";
|
|
1
|
+
import { a as e, i as t, t as n } from "./capabilities-lJRDfRg9.js";
|
|
2
|
+
import { $ as r, B as i, E as a, I as o, L as s, M as c, N as l, O as u, Q as d, S as f, W as p, X as m, Y as h, Z as g, a as _, c as v, d as y, et as b, f as x, k as S, l as C, o as w, p as T, q as E, r as D, s as O, t as k, u as A, v as j, z as M } from "./a2ui-DridcTyF.js";
|
|
3
|
+
import { a as ee, d as N, i as P, l as F, m as I, o as L, r as R, s as z, t as B, u as V } from "./session-events-6PXUoAkP.js";
|
|
4
|
+
import { a as H, c as te, d as U, i as ne, l as re, n as ie, o as ae, r as oe, s as se, t as ce, u as W } from "./feedback-CaSZOBD2.js";
|
|
5
|
+
import { a as le, d as ue, f as de, p as G, s as fe } from "./reducer-mbYiX0wz.js";
|
|
6
|
+
import { C as pe, S as me, _ as he, a as ge, b as _e, c as ve, d as ye, f as be, g as xe, h as Se, i as Ce, l as we, m as Te, n as Ee, o as De, p as Oe, r as ke, s as Ae, u as je, w as Me, x as Ne, y as Pe } from "./persisted-session-history-D_1AtH5H.js";
|
|
7
|
+
import { useCallback as K, useEffect as q, useMemo as Fe, useRef as J, useState as Ie } from "react";
|
|
8
|
+
import { HttpAgent as Le, buildResumeArray as Re } from "@ag-ui/client";
|
|
11
9
|
//#region src/api/client.ts
|
|
12
|
-
var
|
|
10
|
+
var Y = class extends Error {
|
|
13
11
|
code;
|
|
14
12
|
detail;
|
|
15
13
|
constructor(e, t, n) {
|
|
16
14
|
super(t), this.name = "ApiError", this.code = e, this.detail = n;
|
|
17
15
|
}
|
|
18
|
-
},
|
|
16
|
+
}, X = class extends Error {
|
|
19
17
|
constructor(e = "请求已取消") {
|
|
20
18
|
super(e), this.name = "CancelledError";
|
|
21
19
|
}
|
|
22
|
-
},
|
|
23
|
-
async function
|
|
20
|
+
}, ze = "/agentengine/api/v1";
|
|
21
|
+
async function Be(e) {
|
|
24
22
|
let t = await e.text(), n = {};
|
|
25
23
|
try {
|
|
26
24
|
n = t ? JSON.parse(t) : {};
|
|
27
25
|
} catch {
|
|
28
26
|
let n = e.headers.get("content-type")?.toLowerCase() || "";
|
|
29
|
-
if ((e.status === 401 || e.status === 403) && (n.includes("text/html") || t.trimStart().startsWith("<"))) throw new
|
|
27
|
+
if ((e.status === 401 || e.status === 403) && (n.includes("text/html") || t.trimStart().startsWith("<"))) throw new Y(e.status, "访问会话已失效,请从 Dashboard 或 Studio 的云端会话重新打开 Agent。");
|
|
30
28
|
if (!e.ok) {
|
|
31
29
|
let n = t.trim();
|
|
32
|
-
throw new
|
|
30
|
+
throw new Y(e.status, n && n.length <= 256 && !n.startsWith("<") ? n : e.statusText || `HTTP ${e.status}`, t);
|
|
33
31
|
}
|
|
34
|
-
throw new
|
|
32
|
+
throw new Y(-2, "响应格式异常");
|
|
35
33
|
}
|
|
36
|
-
if (!e.ok) throw new
|
|
37
|
-
if (n?.Code !== void 0 && n.Code !== 0) throw new
|
|
34
|
+
if (!e.ok) throw new Y(e.status, n?.Message || `HTTP ${e.status}`, n);
|
|
35
|
+
if (n?.Code !== void 0 && n.Code !== 0) throw new Y(n.Code, n.Message || "请求失败", n);
|
|
38
36
|
return n.Data;
|
|
39
37
|
}
|
|
40
|
-
function
|
|
41
|
-
throw e instanceof DOMException && e.name === "AbortError" ? new
|
|
38
|
+
function Ve(e) {
|
|
39
|
+
throw e instanceof DOMException && e.name === "AbortError" ? new X() : e;
|
|
42
40
|
}
|
|
43
|
-
var
|
|
41
|
+
var He = class {
|
|
44
42
|
fetcher;
|
|
45
43
|
baseUrl;
|
|
46
44
|
agentId;
|
|
47
45
|
constructor(e = {}) {
|
|
48
|
-
this.fetcher = e.fetch || ((e, t) => globalThis.fetch(e, t)), this.baseUrl = String(e.baseUrl ||
|
|
46
|
+
this.fetcher = e.fetch || ((e, t) => globalThis.fetch(e, t)), this.baseUrl = String(e.baseUrl || ze).replace(/\/+$/, ""), this.agentId = String(e.agentId || "").trim();
|
|
49
47
|
}
|
|
50
48
|
actionUrl(e) {
|
|
51
49
|
return `${this.baseUrl}/${e}`;
|
|
@@ -66,9 +64,9 @@ var Pe = class {
|
|
|
66
64
|
signal: n?.signal
|
|
67
65
|
});
|
|
68
66
|
} catch (e) {
|
|
69
|
-
throw
|
|
67
|
+
throw Ve(e);
|
|
70
68
|
}
|
|
71
|
-
return
|
|
69
|
+
return Be(r);
|
|
72
70
|
}
|
|
73
71
|
async postFormAction(e, t, n) {
|
|
74
72
|
let r;
|
|
@@ -80,9 +78,9 @@ var Pe = class {
|
|
|
80
78
|
signal: n?.signal
|
|
81
79
|
});
|
|
82
80
|
} catch (e) {
|
|
83
|
-
throw
|
|
81
|
+
throw Ve(e);
|
|
84
82
|
}
|
|
85
|
-
return
|
|
83
|
+
return Be(r);
|
|
86
84
|
}
|
|
87
85
|
async getResource(e, t, n) {
|
|
88
86
|
let r = this.agentId && !t.AgentId ? {
|
|
@@ -92,13 +90,13 @@ var Pe = class {
|
|
|
92
90
|
try {
|
|
93
91
|
o = await this.fetcher(a, { signal: n?.signal });
|
|
94
92
|
} catch (e) {
|
|
95
|
-
throw
|
|
93
|
+
throw Ve(e);
|
|
96
94
|
}
|
|
97
|
-
if (!o.ok) throw new
|
|
95
|
+
if (!o.ok) throw new Y(o.status, `资源获取失败: ${o.statusText}`);
|
|
98
96
|
try {
|
|
99
97
|
return n?.asText ? await o.text() : await o.blob();
|
|
100
98
|
} catch {
|
|
101
|
-
throw new
|
|
99
|
+
throw new Y(-3, "文件读取失败");
|
|
102
100
|
}
|
|
103
101
|
}
|
|
104
102
|
async streamAction(e, t, n) {
|
|
@@ -114,10 +112,10 @@ var Pe = class {
|
|
|
114
112
|
signal: n?.signal
|
|
115
113
|
});
|
|
116
114
|
} catch (e) {
|
|
117
|
-
throw
|
|
115
|
+
throw Ve(e);
|
|
118
116
|
}
|
|
119
|
-
if (!r.ok) throw await
|
|
120
|
-
if ((r.headers.get("content-type")?.toLowerCase() || "").includes("application/json") && await
|
|
117
|
+
if (!r.ok) throw await Be(r), new Y(r.status, `流式请求失败: ${r.statusText}`);
|
|
118
|
+
if ((r.headers.get("content-type")?.toLowerCase() || "").includes("application/json") && await Be(r.clone()), !r.body) throw new Y(-1, "无法获取响应流");
|
|
121
119
|
return r.body;
|
|
122
120
|
}
|
|
123
121
|
async streamGetAction(e, t, n) {
|
|
@@ -131,235 +129,16 @@ var Pe = class {
|
|
|
131
129
|
signal: n?.signal
|
|
132
130
|
});
|
|
133
131
|
} catch (e) {
|
|
134
|
-
throw
|
|
132
|
+
throw Ve(e);
|
|
135
133
|
}
|
|
136
|
-
if (!o.ok || o.headers.get("content-type")?.toLowerCase().includes("application/json")) throw new
|
|
137
|
-
if (!o.body) throw new
|
|
134
|
+
if (!o.ok || o.headers.get("content-type")?.toLowerCase().includes("application/json")) throw new Y(502, "流式订阅未返回事件流", await Be(o));
|
|
135
|
+
if (!o.body) throw new Y(-1, "无法获取响应流");
|
|
138
136
|
return o.body;
|
|
139
137
|
}
|
|
140
|
-
},
|
|
141
|
-
constructor(e) {
|
|
142
|
-
super(e), this.name = "ContractMismatchError";
|
|
143
|
-
}
|
|
144
|
-
}, Re = new Set([
|
|
145
|
-
"schema_version",
|
|
146
|
-
"command_id",
|
|
147
|
-
"status",
|
|
148
|
-
"message_id",
|
|
149
|
-
"run_id",
|
|
150
|
-
"accepted_seq",
|
|
151
|
-
"error"
|
|
152
|
-
]), ze = W.object({
|
|
153
|
-
code: W.string().min(1),
|
|
154
|
-
message: W.string(),
|
|
155
|
-
retryable: W.boolean(),
|
|
156
|
-
details: W.record(W.string(), W.unknown()).optional()
|
|
157
|
-
});
|
|
158
|
-
function Be(e) {
|
|
159
|
-
if (typeof e != "object" || !e || Array.isArray(e)) return Ve(e);
|
|
160
|
-
let t = e;
|
|
161
|
-
if ("schema_version" in t || !("SchemaVersion" in t)) return Ve(e);
|
|
162
|
-
let n = {
|
|
163
|
-
SchemaVersion: "schema_version",
|
|
164
|
-
CommandId: "command_id",
|
|
165
|
-
Status: "status",
|
|
166
|
-
MessageId: "message_id",
|
|
167
|
-
RunId: "run_id",
|
|
168
|
-
AcceptedSeq: "accepted_seq",
|
|
169
|
-
Error: "error"
|
|
170
|
-
};
|
|
171
|
-
return Ve(Object.fromEntries(Object.entries(t).map(([e, t]) => [n[e] ?? e, t])));
|
|
172
|
-
}
|
|
173
|
-
function Ve(e) {
|
|
174
|
-
let t = W.object({
|
|
175
|
-
schema_version: W.literal(1),
|
|
176
|
-
command_id: W.string().min(1),
|
|
177
|
-
status: W.enum([
|
|
178
|
-
"accepted",
|
|
179
|
-
"duplicate",
|
|
180
|
-
"rejected",
|
|
181
|
-
"unsupported",
|
|
182
|
-
"queue_full",
|
|
183
|
-
"persistence_uncertain"
|
|
184
|
-
]),
|
|
185
|
-
message_id: W.string().min(1).nullable().optional(),
|
|
186
|
-
run_id: W.string().min(1).nullable().optional(),
|
|
187
|
-
accepted_seq: W.number().int().min(0).nullable().optional(),
|
|
188
|
-
error: ze.nullable().optional()
|
|
189
|
-
}).passthrough().safeParse(e);
|
|
190
|
-
if (!t.success) throw new q(`AgentControlReceipt/v1 mismatch: ${t.error.message}`);
|
|
191
|
-
let n = t.data;
|
|
192
|
-
if ((n.status === "rejected" || n.status === "unsupported" || n.status === "queue_full" || n.status === "persistence_uncertain") && !n.error) throw new q(`AgentControlReceipt/v1 mismatch: status ${n.status} requires error`);
|
|
193
|
-
let r = {};
|
|
194
|
-
for (let [e, t] of Object.entries(n)) Re.has(e) || (r[e] = t);
|
|
195
|
-
let i = n.error ? {
|
|
196
|
-
...n.error,
|
|
197
|
-
extensions: {}
|
|
198
|
-
} : null;
|
|
199
|
-
return {
|
|
200
|
-
schema_version: 1,
|
|
201
|
-
command_id: n.command_id,
|
|
202
|
-
status: n.status,
|
|
203
|
-
message_id: n.message_id ?? null,
|
|
204
|
-
run_id: n.run_id ?? null,
|
|
205
|
-
accepted_seq: n.accepted_seq ?? null,
|
|
206
|
-
error: i,
|
|
207
|
-
extensions: r
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
function He(e) {
|
|
211
|
-
try {
|
|
212
|
-
return n(e);
|
|
213
|
-
} catch (e) {
|
|
214
|
-
throw new q(`RuntimeCapabilityMatrix/v1 mismatch: ${e instanceof Error ? e.message : String(e)}`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
var Ue = new Set([
|
|
218
|
-
"schema_version",
|
|
219
|
-
"event_id",
|
|
220
|
-
"session_id",
|
|
221
|
-
"seq",
|
|
222
|
-
"timestamp",
|
|
223
|
-
"family",
|
|
224
|
-
"family_version",
|
|
225
|
-
"event_type",
|
|
226
|
-
"payload",
|
|
227
|
-
"run_id",
|
|
228
|
-
"causation_id",
|
|
229
|
-
"correlation_id",
|
|
230
|
-
"actor_ref"
|
|
231
|
-
]), We = new Map([["control", 1], ["runtime", 2]]), Ge = {
|
|
232
|
-
schema_version: ["schemaVersion", "SchemaVersion"],
|
|
233
|
-
event_id: ["eventId", "EventId"],
|
|
234
|
-
session_id: ["sessionId", "SessionId"],
|
|
235
|
-
seq: [
|
|
236
|
-
"seqId",
|
|
237
|
-
"SeqId",
|
|
238
|
-
"Seq"
|
|
239
|
-
],
|
|
240
|
-
timestamp: ["Timestamp"],
|
|
241
|
-
family: ["Family"],
|
|
242
|
-
family_version: ["familyVersion", "FamilyVersion"],
|
|
243
|
-
event_type: ["eventType", "EventType"],
|
|
244
|
-
payload: ["Payload"],
|
|
245
|
-
run_id: ["runId", "RunId"],
|
|
246
|
-
causation_id: ["causationId", "CausationId"],
|
|
247
|
-
correlation_id: ["correlationId", "CorrelationId"],
|
|
248
|
-
actor_ref: ["actorRef", "ActorRef"]
|
|
249
|
-
};
|
|
250
|
-
function Ke(e) {
|
|
251
|
-
if (!e || typeof e != "object" || Array.isArray(e)) return e;
|
|
252
|
-
let t = e, n = { ...t };
|
|
253
|
-
for (let [e, r] of Object.entries(Ge)) {
|
|
254
|
-
if (n[e] === void 0) {
|
|
255
|
-
let i = r.find((e) => t[e] !== void 0);
|
|
256
|
-
i && (n[e] = t[i]);
|
|
257
|
-
}
|
|
258
|
-
for (let e of r) delete n[e];
|
|
259
|
-
}
|
|
260
|
-
return n;
|
|
261
|
-
}
|
|
262
|
-
var qe = W.object({
|
|
263
|
-
schema_version: W.literal(1),
|
|
264
|
-
event_id: W.string().min(1),
|
|
265
|
-
session_id: W.string().min(1),
|
|
266
|
-
seq: W.number().int().min(0),
|
|
267
|
-
timestamp: W.string().min(1),
|
|
268
|
-
family: W.string().min(1),
|
|
269
|
-
family_version: W.number().int().min(1),
|
|
270
|
-
event_type: W.string().min(1),
|
|
271
|
-
payload: W.record(W.string(), W.unknown()),
|
|
272
|
-
run_id: W.string().min(1).nullable().optional(),
|
|
273
|
-
causation_id: W.string().min(1).nullable().optional(),
|
|
274
|
-
correlation_id: W.string().min(1).nullable().optional(),
|
|
275
|
-
actor_ref: W.string().min(1).nullable().optional()
|
|
276
|
-
}).passthrough();
|
|
277
|
-
function Je(e) {
|
|
278
|
-
let t = qe.safeParse(Ke(e));
|
|
279
|
-
if (!t.success) return {
|
|
280
|
-
ok: !1,
|
|
281
|
-
error: new q(`SessionEventEnvelope/v1 mismatch: ${t.error.message}`)
|
|
282
|
-
};
|
|
283
|
-
let n = t.data, r = We.get(n.family);
|
|
284
|
-
if (r !== void 0 && n.family_version !== r) return {
|
|
285
|
-
ok: !1,
|
|
286
|
-
error: new q(`SessionEventEnvelope/v1 mismatch: family ${n.family} requires family_version ${r}`)
|
|
287
|
-
};
|
|
288
|
-
let i = {};
|
|
289
|
-
for (let [e, t] of Object.entries(n)) Ue.has(e) || (i[e] = t);
|
|
290
|
-
return {
|
|
291
|
-
ok: !0,
|
|
292
|
-
value: {
|
|
293
|
-
schema_version: 1,
|
|
294
|
-
event_id: n.event_id,
|
|
295
|
-
session_id: n.session_id,
|
|
296
|
-
seq: n.seq,
|
|
297
|
-
timestamp: n.timestamp,
|
|
298
|
-
family: n.family,
|
|
299
|
-
family_version: n.family_version,
|
|
300
|
-
event_type: n.event_type,
|
|
301
|
-
payload: n.payload,
|
|
302
|
-
run_id: n.run_id ?? null,
|
|
303
|
-
causation_id: n.causation_id ?? null,
|
|
304
|
-
correlation_id: n.correlation_id ?? null,
|
|
305
|
-
actor_ref: n.actor_ref ?? null,
|
|
306
|
-
extensions: i
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
function Ye(e) {
|
|
311
|
-
let t = W.object({
|
|
312
|
-
schema_version: W.literal(1),
|
|
313
|
-
agent_instance_id: W.string().min(1),
|
|
314
|
-
instance_state: W.enum([
|
|
315
|
-
"ready",
|
|
316
|
-
"degraded",
|
|
317
|
-
"unavailable"
|
|
318
|
-
]),
|
|
319
|
-
session_id: W.string().min(1).nullable().optional(),
|
|
320
|
-
active_run_id: W.string().min(1).nullable().optional(),
|
|
321
|
-
active_run_state: W.enum([
|
|
322
|
-
"pending",
|
|
323
|
-
"running",
|
|
324
|
-
"paused",
|
|
325
|
-
"waiting"
|
|
326
|
-
]).nullable().optional(),
|
|
327
|
-
inbox_depth: W.number().int().min(0),
|
|
328
|
-
activation_id: W.string().min(1).nullable().optional(),
|
|
329
|
-
lease_expires_at: W.string().min(1).nullable().optional(),
|
|
330
|
-
capability: W.unknown()
|
|
331
|
-
}).passthrough().safeParse(e);
|
|
332
|
-
if (!t.success) throw new q(`AgentStatusSnapshot/v1 mismatch: ${t.error.message}`);
|
|
333
|
-
let n = t.data, r = {};
|
|
334
|
-
for (let e of Object.keys(n)) [
|
|
335
|
-
"schema_version",
|
|
336
|
-
"agent_instance_id",
|
|
337
|
-
"instance_state",
|
|
338
|
-
"session_id",
|
|
339
|
-
"active_run_id",
|
|
340
|
-
"active_run_state",
|
|
341
|
-
"inbox_depth",
|
|
342
|
-
"activation_id",
|
|
343
|
-
"lease_expires_at",
|
|
344
|
-
"capability"
|
|
345
|
-
].includes(e) || (r[e] = n[e]);
|
|
346
|
-
return {
|
|
347
|
-
schema_version: 1,
|
|
348
|
-
agent_instance_id: n.agent_instance_id,
|
|
349
|
-
instance_state: n.instance_state,
|
|
350
|
-
session_id: n.session_id ?? null,
|
|
351
|
-
active_run_id: n.active_run_id ?? null,
|
|
352
|
-
active_run_state: n.active_run_state ?? null,
|
|
353
|
-
inbox_depth: n.inbox_depth,
|
|
354
|
-
activation_id: n.activation_id ?? null,
|
|
355
|
-
lease_expires_at: n.lease_expires_at ?? null,
|
|
356
|
-
capability: He(n.capability),
|
|
357
|
-
extensions: r
|
|
358
|
-
};
|
|
359
|
-
}
|
|
138
|
+
}, Ue = new He(), We = (e, t, n) => Ue.streamAction(e, t, n), Ge = (e, t, n) => Ue.streamGetAction(e, t, n);
|
|
360
139
|
//#endregion
|
|
361
140
|
//#region src/api/messages.ts
|
|
362
|
-
function
|
|
141
|
+
function Ke(e) {
|
|
363
142
|
return {
|
|
364
143
|
Messages: e.Messages ?? [],
|
|
365
144
|
LatestSeqId: Number.isFinite(Number(e.LatestSeqId)) ? Number(e.LatestSeqId) : 0,
|
|
@@ -377,11 +156,16 @@ function Xe(e) {
|
|
|
377
156
|
}
|
|
378
157
|
//#endregion
|
|
379
158
|
//#region src/core/api/facade.ts
|
|
380
|
-
var
|
|
159
|
+
var qe = class {
|
|
381
160
|
client;
|
|
382
161
|
constructor(e = {}) {
|
|
383
|
-
this.client = new
|
|
162
|
+
this.client = new He(e);
|
|
384
163
|
}
|
|
164
|
+
mcpAuthorization = async (e, t, n, r) => this.client.postJsonAction(e, {
|
|
165
|
+
WaitId: t,
|
|
166
|
+
...r ? { SessionId: r } : {},
|
|
167
|
+
...n ? { ExpectedRevision: n } : {}
|
|
168
|
+
});
|
|
385
169
|
async compactSession(e, t) {
|
|
386
170
|
return this.client.postJsonAction("CompactSession", {
|
|
387
171
|
AgentId: e,
|
|
@@ -440,7 +224,7 @@ var Ze = class {
|
|
|
440
224
|
};
|
|
441
225
|
}
|
|
442
226
|
async listSessionMessages(e, t) {
|
|
443
|
-
return
|
|
227
|
+
return Ke(await this.client.postJsonAction("ListSessionMessages", {
|
|
444
228
|
AgentId: t?.agentId,
|
|
445
229
|
SessionId: e,
|
|
446
230
|
AfterSeqId: t?.afterSeqId,
|
|
@@ -478,7 +262,13 @@ var Ze = class {
|
|
|
478
262
|
}, t);
|
|
479
263
|
}
|
|
480
264
|
async runAgent(e, t) {
|
|
481
|
-
return this.client.streamAction("RunAgent",
|
|
265
|
+
return this.client.streamAction("RunAgent", {
|
|
266
|
+
...e,
|
|
267
|
+
Extensions: {
|
|
268
|
+
...e.Extensions,
|
|
269
|
+
"mcp.authorization": M
|
|
270
|
+
}
|
|
271
|
+
}, t);
|
|
482
272
|
}
|
|
483
273
|
async resumeRun(e, t) {
|
|
484
274
|
return this.client.streamAction("ResumeRun", {
|
|
@@ -499,14 +289,14 @@ var Ze = class {
|
|
|
499
289
|
}, t);
|
|
500
290
|
}
|
|
501
291
|
async submitControl(e, t) {
|
|
502
|
-
return
|
|
292
|
+
return S(await this.client.postJsonAction("SubmitAgentControl", {
|
|
503
293
|
CommandType: e.command_type,
|
|
504
294
|
IdempotencyKey: e.idempotency_key,
|
|
505
295
|
Payload: e.payload
|
|
506
296
|
}, t));
|
|
507
297
|
}
|
|
508
298
|
async submitInteraction(e, t) {
|
|
509
|
-
return
|
|
299
|
+
return S(await this.client.postJsonAction("SubmitInteraction", { ...e }, t));
|
|
510
300
|
}
|
|
511
301
|
async getAgentStatus(e) {
|
|
512
302
|
return this.client.postJsonAction("GetAgentStatus", {}, e);
|
|
@@ -568,43 +358,43 @@ var Ze = class {
|
|
|
568
358
|
async uploadFile(e, t) {
|
|
569
359
|
return this.client.postFormAction("UploadFile", e, t);
|
|
570
360
|
}
|
|
571
|
-
},
|
|
572
|
-
function
|
|
361
|
+
}, Je = "ksadk:webui:selected-session:";
|
|
362
|
+
function Ye(e) {
|
|
573
363
|
return String(e || "").trim() || "default-agent";
|
|
574
364
|
}
|
|
575
|
-
function
|
|
365
|
+
function Xe(e) {
|
|
576
366
|
if (e && typeof e.getItem == "function") return e;
|
|
577
367
|
try {
|
|
578
368
|
if (typeof window < "u" && window.localStorage) return window.localStorage;
|
|
579
369
|
} catch {}
|
|
580
370
|
return null;
|
|
581
371
|
}
|
|
582
|
-
function
|
|
583
|
-
return
|
|
372
|
+
function Ze(e) {
|
|
373
|
+
return g.key(`${Je}${Ye(e)}`);
|
|
584
374
|
}
|
|
585
|
-
function
|
|
586
|
-
let n =
|
|
375
|
+
function Qe(e, t) {
|
|
376
|
+
let n = Xe(t);
|
|
587
377
|
if (!n) return null;
|
|
588
378
|
try {
|
|
589
|
-
return String(n.getItem(
|
|
379
|
+
return String(n.getItem(Ze(e)) || "").trim() || null;
|
|
590
380
|
} catch {
|
|
591
381
|
return null;
|
|
592
382
|
}
|
|
593
383
|
}
|
|
594
|
-
function
|
|
595
|
-
if (!
|
|
596
|
-
let r =
|
|
384
|
+
function $e(e, t, n) {
|
|
385
|
+
if (!g.writable) return;
|
|
386
|
+
let r = Xe(n);
|
|
597
387
|
if (!r) return;
|
|
598
|
-
let
|
|
388
|
+
let i = Ze(e), a = String(t || "").trim();
|
|
599
389
|
try {
|
|
600
|
-
if (
|
|
601
|
-
r.setItem(
|
|
390
|
+
if (a) {
|
|
391
|
+
r.setItem(i, a);
|
|
602
392
|
return;
|
|
603
393
|
}
|
|
604
|
-
r.removeItem(
|
|
394
|
+
r.removeItem(i);
|
|
605
395
|
} catch {}
|
|
606
396
|
}
|
|
607
|
-
function
|
|
397
|
+
function et(e, t) {
|
|
608
398
|
if (!Array.isArray(e) || e.length === 0) return null;
|
|
609
399
|
let n = String(t || "").trim();
|
|
610
400
|
if (n && e.some((e) => String(e?.SessionId || "").trim() === n)) return n;
|
|
@@ -614,7 +404,7 @@ function it(e, t) {
|
|
|
614
404
|
}
|
|
615
405
|
return null;
|
|
616
406
|
}
|
|
617
|
-
function
|
|
407
|
+
function tt(e, t, n) {
|
|
618
408
|
let r = Array.isArray(e) ? e : [], i = Array.isArray(t) ? t : [], a = n instanceof Set ? n : new Set(Array.isArray(n) ? n : []);
|
|
619
409
|
if (a.size === 0) return r;
|
|
620
410
|
let o = new Set(r.map((e) => String(e?.SessionId || "").trim()).filter(Boolean)), s = i.filter((e) => {
|
|
@@ -625,71 +415,71 @@ function at(e, t, n) {
|
|
|
625
415
|
}
|
|
626
416
|
//#endregion
|
|
627
417
|
//#region src/hooks/useBootstrap.ts
|
|
628
|
-
function
|
|
629
|
-
return e instanceof
|
|
418
|
+
function nt(e) {
|
|
419
|
+
return e instanceof Y && (e.code === 401 || e.code === 403) ? "auth-required" : "error";
|
|
630
420
|
}
|
|
631
|
-
function
|
|
421
|
+
function rt(e) {
|
|
632
422
|
if (!Array.isArray(e)) return ["responses", "chat_completions"];
|
|
633
423
|
let t = e.filter((e) => e === "responses" || e === "chat_completions");
|
|
634
424
|
return t.length > 0 ? t : ["responses", "chat_completions"];
|
|
635
425
|
}
|
|
636
|
-
var
|
|
637
|
-
async function
|
|
426
|
+
var it = new qe();
|
|
427
|
+
async function at(e, t = it) {
|
|
638
428
|
try {
|
|
639
429
|
let n = await t.listAgentModels(e), r = n?.Models;
|
|
640
|
-
Array.isArray(r) &&
|
|
430
|
+
Array.isArray(r) && d.getState().upsertModels(r);
|
|
641
431
|
let i = n;
|
|
642
|
-
i?.Current && !
|
|
432
|
+
i?.Current && !d.getState().selectedModel && d.getState().setSelectedModel(String(i.Current)), i?.Source && d.getState().setModelSource(String(i.Source));
|
|
643
433
|
} catch (e) {
|
|
644
434
|
console.error("Failed to fetch models:", e);
|
|
645
435
|
} finally {
|
|
646
|
-
|
|
436
|
+
d.getState().setModelCatalogLoaded(!0);
|
|
647
437
|
}
|
|
648
438
|
}
|
|
649
|
-
function
|
|
650
|
-
|
|
439
|
+
function ot(e, r, a = it, o) {
|
|
440
|
+
q(() => {
|
|
651
441
|
let s = new AbortController();
|
|
652
442
|
return (async () => {
|
|
653
|
-
|
|
443
|
+
i.getState().setStatus("loading");
|
|
654
444
|
try {
|
|
655
|
-
let c = o ?? await
|
|
445
|
+
let c = o ?? await a.getAgentUiBootstrap(r, { signal: s.signal });
|
|
656
446
|
if (s.signal.aborted) return;
|
|
657
|
-
let l = c, u = l?.Agent,
|
|
658
|
-
if (
|
|
447
|
+
let l = c, u = l?.Agent, f = String(u?.AgentId || "default-agent");
|
|
448
|
+
if (i.getState().setAgentId(f), u?.Name) {
|
|
659
449
|
let e = String(u.Name);
|
|
660
|
-
|
|
450
|
+
i.getState().setAgentName(e), document.title = e;
|
|
661
451
|
}
|
|
662
|
-
let
|
|
663
|
-
|
|
664
|
-
let
|
|
665
|
-
|
|
666
|
-
let
|
|
667
|
-
|
|
668
|
-
let
|
|
669
|
-
|
|
452
|
+
let p = String(u?.Framework || "").trim().toLowerCase();
|
|
453
|
+
i.getState().setAgentFramework(p);
|
|
454
|
+
let m = t(c);
|
|
455
|
+
i.getState().setCapabilities(m), i.getState().setApiFormats(rt(m.HostedChat.ApiFormats)), i.getState().setAccessMode(String(l?.AccessMode || "Owner"));
|
|
456
|
+
let h = m.WorkspaceFiles && l?.WorkspaceFiles ? l.WorkspaceFiles : null;
|
|
457
|
+
i.getState().setWorkspaceFiles(h), h || b.getState().setWorkspacePanelOpen(!1), n(m) && e.fetchSessions(f, Qe(f));
|
|
458
|
+
let g = l?.Model;
|
|
459
|
+
g?.id && (d.getState().setSelectedModel(g.id), d.getState().upsertModels([g]), d.getState().setModelSource(g.source || "")), at(f, a), i.getState().setStatus("ready");
|
|
670
460
|
} catch (e) {
|
|
671
461
|
if (s.signal.aborted) return;
|
|
672
462
|
console.error("Failed to fetch bootstrap:", e);
|
|
673
|
-
let t =
|
|
674
|
-
|
|
463
|
+
let t = nt(e);
|
|
464
|
+
i.getState().setStatus(t, t === "auth-required" ? "当前访问链接未授权或已过期。" : "无法加载 Agent 配置,请稍后重试。");
|
|
675
465
|
}
|
|
676
466
|
})(), () => s.abort();
|
|
677
467
|
}, [
|
|
678
|
-
|
|
679
|
-
|
|
468
|
+
a,
|
|
469
|
+
r,
|
|
680
470
|
o
|
|
681
471
|
]);
|
|
682
472
|
}
|
|
683
473
|
//#endregion
|
|
684
474
|
//#region src/hooks/useFeedback.ts
|
|
685
|
-
function
|
|
475
|
+
function st(e) {
|
|
686
476
|
let { agentId: t, currentSessionId: n, isStreaming: r, api: i, submitDraft: a } = e;
|
|
687
477
|
return {
|
|
688
|
-
submitResponseFeedback:
|
|
478
|
+
submitResponseFeedback: K(async (e) => {
|
|
689
479
|
if (!n) return;
|
|
690
480
|
let r = null;
|
|
691
|
-
|
|
692
|
-
let n =
|
|
481
|
+
U.getState().patchMessages((t) => {
|
|
482
|
+
let n = ce(t, {
|
|
693
483
|
messageId: e.message.id,
|
|
694
484
|
rating: e.rating,
|
|
695
485
|
comment: e.comment || ""
|
|
@@ -697,19 +487,19 @@ function dt(e) {
|
|
|
697
487
|
return r = n.previousFeedback, n.nextMessages;
|
|
698
488
|
});
|
|
699
489
|
try {
|
|
700
|
-
let r =
|
|
490
|
+
let r = ae((await i.upsertResponseFeedback(oe({
|
|
701
491
|
agentId: t,
|
|
702
492
|
sessionId: n,
|
|
703
493
|
message: e.message,
|
|
704
494
|
rating: e.rating,
|
|
705
495
|
comment: e.comment || ""
|
|
706
496
|
})))?.Feedback);
|
|
707
|
-
r &&
|
|
497
|
+
r && U.getState().patchMessages((t) => H(t, {
|
|
708
498
|
messageId: e.message.id,
|
|
709
499
|
feedback: r
|
|
710
500
|
}));
|
|
711
501
|
} catch (t) {
|
|
712
|
-
console.error("Failed to submit response feedback:", t),
|
|
502
|
+
console.error("Failed to submit response feedback:", t), U.getState().patchMessages((t) => se(t, {
|
|
713
503
|
messageId: e.message.id,
|
|
714
504
|
previousFeedback: r
|
|
715
505
|
}));
|
|
@@ -719,18 +509,18 @@ function dt(e) {
|
|
|
719
509
|
n,
|
|
720
510
|
i
|
|
721
511
|
]),
|
|
722
|
-
deleteResponseFeedback:
|
|
512
|
+
deleteResponseFeedback: K(async (e) => {
|
|
723
513
|
if (!n) return;
|
|
724
514
|
let r = e.feedback ? { ...e.feedback } : null;
|
|
725
|
-
|
|
515
|
+
U.getState().patchMessages((t) => ne(t, { messageId: e.id }));
|
|
726
516
|
try {
|
|
727
|
-
await i.deleteResponseFeedback(
|
|
517
|
+
await i.deleteResponseFeedback(ie({
|
|
728
518
|
agentId: t,
|
|
729
519
|
sessionId: n,
|
|
730
520
|
message: e
|
|
731
521
|
}));
|
|
732
522
|
} catch (t) {
|
|
733
|
-
console.error("Failed to delete response feedback:", t),
|
|
523
|
+
console.error("Failed to delete response feedback:", t), U.getState().patchMessages((t) => se(t, {
|
|
734
524
|
messageId: e.id,
|
|
735
525
|
previousFeedback: r
|
|
736
526
|
}));
|
|
@@ -740,11 +530,11 @@ function dt(e) {
|
|
|
740
530
|
n,
|
|
741
531
|
i
|
|
742
532
|
]),
|
|
743
|
-
respondToApproval:
|
|
533
|
+
respondToApproval: K(async (e) => !e.approvalRequestId || r || !await a("", [], [{
|
|
744
534
|
type: "mcp_approval_response",
|
|
745
535
|
approval_request_id: e.approvalRequestId,
|
|
746
536
|
approve: e.approve
|
|
747
|
-
}], e.previousResponseId) ? !1 : (
|
|
537
|
+
}], e.previousResponseId) ? !1 : (h.getState().currentSessionId === n && U.getState().patchMessages((t) => t.map((t) => {
|
|
748
538
|
let n = e.approve ? "approved" : "rejected", r = (t) => e.approve && t === "paused" ? "running" : e.approve ? t : "completed";
|
|
749
539
|
return {
|
|
750
540
|
...t,
|
|
@@ -770,827 +560,46 @@ function dt(e) {
|
|
|
770
560
|
};
|
|
771
561
|
}
|
|
772
562
|
//#endregion
|
|
773
|
-
//#region src/core/
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
"cancelled",
|
|
785
|
-
"expired"
|
|
786
|
-
]), mt = new Set([
|
|
787
|
-
"approved",
|
|
788
|
-
"rejected",
|
|
789
|
-
"submitted",
|
|
790
|
-
"cancelled",
|
|
791
|
-
"expired"
|
|
792
|
-
]);
|
|
793
|
-
function ht(e) {
|
|
794
|
-
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
795
|
-
}
|
|
796
|
-
function gt(e) {
|
|
797
|
-
return typeof e == "string" && e.length > 0 ? e : null;
|
|
798
|
-
}
|
|
799
|
-
var _t = "人工确认", vt = "本次运行需要人工处理后才能继续。";
|
|
800
|
-
function yt(e) {
|
|
801
|
-
let t = String(e.kind || "approval"), n = String(e.status || "pending"), r = String(e.outcome || ""), i = ht(e.presentation), a = i ? ht(i.a2ui) : null, o;
|
|
802
|
-
if (n === "resolved" && Object.hasOwn(e, "response")) try {
|
|
803
|
-
o = { response: b(e.response) };
|
|
804
|
-
} catch {}
|
|
805
|
-
return {
|
|
806
|
-
interactionId: e.interactionId,
|
|
807
|
-
sessionId: e.sessionId,
|
|
808
|
-
runId: gt(e.runId),
|
|
809
|
-
kind: ft.has(t) ? t : "custom",
|
|
810
|
-
title: typeof e.title == "string" && e.title ? e.title : _t,
|
|
811
|
-
message: typeof e.message == "string" && e.message ? e.message : vt,
|
|
812
|
-
requestSchema: ht(e.requestSchema),
|
|
813
|
-
presentation: a ? { a2ui: {
|
|
814
|
-
wireVersion: String(a.wire_version ?? a.wireVersion ?? ""),
|
|
815
|
-
catalogDigest: String(a.catalog_digest ?? a.catalogDigest ?? ""),
|
|
816
|
-
messages: Array.isArray(a.messages) ? a.messages.filter((e) => typeof e == "object") : []
|
|
817
|
-
} } : null,
|
|
818
|
-
status: pt.has(n) ? n : "pending",
|
|
819
|
-
revision: Number.isFinite(Number(e.revision)) && Number(e.revision) > 0 ? Number(e.revision) : 1,
|
|
820
|
-
createdAt: gt(e.createdAt) || (/* @__PURE__ */ new Date()).toISOString(),
|
|
821
|
-
expiresAt: gt(e.expiresAt),
|
|
822
|
-
resolvedAt: gt(e.resolvedAt),
|
|
823
|
-
actor: gt(e.actor),
|
|
824
|
-
outcome: mt.has(r) ? r : null,
|
|
825
|
-
responseSummary: gt(e.responseSummary),
|
|
826
|
-
...o,
|
|
827
|
-
source: e.source,
|
|
828
|
-
extensions: e.extensions || {}
|
|
829
|
-
};
|
|
830
|
-
}
|
|
831
|
-
//#endregion
|
|
832
|
-
//#region src/core/interaction/store.ts
|
|
833
|
-
var bt = class {
|
|
834
|
-
records = /* @__PURE__ */ new Map();
|
|
835
|
-
terminalRuns = /* @__PURE__ */ new Set();
|
|
836
|
-
rejectedCommands = /* @__PURE__ */ new Map();
|
|
837
|
-
listeners = /* @__PURE__ */ new Set();
|
|
838
|
-
key(e, t) {
|
|
839
|
-
return `${e}\u0000${t}`;
|
|
840
|
-
}
|
|
841
|
-
runKey(e, t) {
|
|
842
|
-
return `${e}\u0000${t}`;
|
|
843
|
-
}
|
|
844
|
-
subscribe(e) {
|
|
845
|
-
return this.listeners.add(e), () => {
|
|
846
|
-
this.listeners.delete(e);
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
emit(e) {
|
|
850
|
-
for (let t of this.listeners) t(e);
|
|
851
|
-
}
|
|
852
|
-
get(e, t) {
|
|
853
|
-
return this.records.get(this.key(e, t)) || null;
|
|
854
|
-
}
|
|
855
|
-
listPending(e) {
|
|
856
|
-
return this.listAll(e).filter((e) => e.status === "pending");
|
|
857
|
-
}
|
|
858
|
-
listAll(e) {
|
|
859
|
-
return this.all().filter((t) => t.sessionId === e);
|
|
860
|
-
}
|
|
861
|
-
all() {
|
|
862
|
-
return [...this.records.values()].sort((e, t) => String(e.createdAt).localeCompare(String(t.createdAt)));
|
|
863
|
-
}
|
|
864
|
-
upsert(e) {
|
|
865
|
-
let t = this.get(e.sessionId, e.interactionId);
|
|
866
|
-
e.runId && !h(e.status) && !h(t?.status ?? "pending") && this.terminalRuns.has(this.runKey(e.sessionId, e.runId)) && (e = {
|
|
867
|
-
...e,
|
|
868
|
-
status: "expired",
|
|
869
|
-
outcome: "expired",
|
|
870
|
-
resolvedAt: e.resolvedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
871
|
-
responseSummary: e.responseSummary ?? "运行已结束"
|
|
872
|
-
});
|
|
873
|
-
let n, r;
|
|
874
|
-
return t ? h(t.status) && !h(e.status) ? (n = {
|
|
875
|
-
...t,
|
|
876
|
-
title: t.title === "人工确认" ? e.title : t.title,
|
|
877
|
-
message: t.message === "本次运行需要人工处理后才能继续。" ? e.message : t.message,
|
|
878
|
-
kind: t.kind === "approval" && !t.requestSchema ? e.kind : t.kind,
|
|
879
|
-
requestSchema: t.requestSchema ?? e.requestSchema,
|
|
880
|
-
presentation: t.presentation ?? e.presentation
|
|
881
|
-
}, r = {
|
|
882
|
-
type: "interaction_updated",
|
|
883
|
-
interaction: n
|
|
884
|
-
}) : e.revision < t.revision || e.revision === t.revision && h(t.status) && !h(e.status) || t.status === "failed" && t.extensions.rejected_command_id && e.revision === t.revision && !h(e.status) || t.status === "resolving" && !h(e.status) ? (n = t, r = {
|
|
885
|
-
type: "interaction_updated",
|
|
886
|
-
interaction: n
|
|
887
|
-
}) : h(e.status) ? (n = {
|
|
888
|
-
...t,
|
|
889
|
-
...e,
|
|
890
|
-
title: t.title || e.title,
|
|
891
|
-
kind: t.kind || e.kind,
|
|
892
|
-
message: t.message || e.message,
|
|
893
|
-
runId: e.runId ?? t.runId,
|
|
894
|
-
requestSchema: t.requestSchema ?? e.requestSchema,
|
|
895
|
-
presentation: t.presentation ?? e.presentation,
|
|
896
|
-
actor: e.actor ?? t.actor,
|
|
897
|
-
outcome: e.outcome ?? t.outcome,
|
|
898
|
-
resolvedAt: e.resolvedAt ?? t.resolvedAt,
|
|
899
|
-
responseSummary: e.responseSummary ?? t.responseSummary,
|
|
900
|
-
...Object.hasOwn(t, "response") ? { response: t.response } : {}
|
|
901
|
-
}, r = {
|
|
902
|
-
type: "interaction_resolved",
|
|
903
|
-
interaction: n
|
|
904
|
-
}) : (n = {
|
|
905
|
-
...t,
|
|
906
|
-
...e
|
|
907
|
-
}, r = {
|
|
908
|
-
type: "interaction_updated",
|
|
909
|
-
interaction: n
|
|
910
|
-
}) : (n = e, r = {
|
|
911
|
-
type: "interaction_requested",
|
|
912
|
-
interaction: n
|
|
913
|
-
}), this.records.set(this.key(n.sessionId, n.interactionId), n), this.emit(r), r;
|
|
914
|
-
}
|
|
915
|
-
markResolving(e, t) {
|
|
916
|
-
let n = this.get(e, t);
|
|
917
|
-
if (!n || !["pending", "failed"].includes(n.status)) return;
|
|
918
|
-
let r = { ...n.extensions };
|
|
919
|
-
delete r.submit_error, delete r.submit_command_id, this.records.set(this.key(e, t), {
|
|
920
|
-
...n,
|
|
921
|
-
status: "resolving",
|
|
922
|
-
extensions: r
|
|
923
|
-
}), this.emit({
|
|
924
|
-
type: "interaction_updated",
|
|
925
|
-
interaction: this.get(e, t)
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
resolveLocally(e, t, n) {
|
|
929
|
-
let r = this.get(e, t);
|
|
930
|
-
if (!r) return;
|
|
931
|
-
let i = {
|
|
932
|
-
...r,
|
|
933
|
-
...n,
|
|
934
|
-
resolvedAt: n.resolvedAt ?? r.resolvedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
935
|
-
revision: n.revision ?? r.revision
|
|
936
|
-
};
|
|
937
|
-
this.records.set(this.key(e, t), i), this.emit({
|
|
938
|
-
type: "interaction_resolved",
|
|
939
|
-
interaction: i
|
|
940
|
-
});
|
|
941
|
-
}
|
|
942
|
-
recordCommand(e, t, n) {
|
|
943
|
-
let r = this.get(e, t);
|
|
944
|
-
if (!r || !n || h(r.status)) return;
|
|
945
|
-
this.records.set(this.key(e, t), {
|
|
946
|
-
...r,
|
|
947
|
-
extensions: {
|
|
948
|
-
...r.extensions,
|
|
949
|
-
submit_command_id: n
|
|
950
|
-
}
|
|
951
|
-
});
|
|
952
|
-
let i = this.rejectedCommands.get(this.key(e, n));
|
|
953
|
-
i && this.rejectCommand(e, n, i);
|
|
954
|
-
}
|
|
955
|
-
rejectCommand(e, t, n) {
|
|
956
|
-
if (!(!e || !t)) {
|
|
957
|
-
this.rejectedCommands.set(this.key(e, t), n);
|
|
958
|
-
for (let r of this.listAll(e)) {
|
|
959
|
-
if (r.extensions.submit_command_id !== t) continue;
|
|
960
|
-
this.markFailed(e, r.interactionId, {
|
|
961
|
-
code: n,
|
|
962
|
-
message: `提交未执行(${n}),请重试`,
|
|
963
|
-
retryable: !0
|
|
964
|
-
});
|
|
965
|
-
let i = this.get(e, r.interactionId);
|
|
966
|
-
i?.status === "failed" && this.records.set(this.key(e, r.interactionId), {
|
|
967
|
-
...i,
|
|
968
|
-
extensions: {
|
|
969
|
-
...i.extensions,
|
|
970
|
-
rejected_command_id: t
|
|
971
|
-
}
|
|
972
|
-
});
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
recordIdempotencyKey(e, t, n) {
|
|
977
|
-
let r = this.get(e, t);
|
|
978
|
-
if (!r) return;
|
|
979
|
-
let i = {
|
|
980
|
-
...r,
|
|
981
|
-
extensions: {
|
|
982
|
-
...r.extensions,
|
|
983
|
-
idempotency_key: n
|
|
984
|
-
}
|
|
985
|
-
};
|
|
986
|
-
this.records.set(this.key(e, t), i), this.emit({
|
|
987
|
-
type: "interaction_updated",
|
|
988
|
-
interaction: i
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
markFailed(e, t, n) {
|
|
992
|
-
let r = this.get(e, t);
|
|
993
|
-
if (!r || h(r.status)) return;
|
|
994
|
-
let i = {
|
|
995
|
-
...r,
|
|
996
|
-
status: "failed",
|
|
997
|
-
extensions: {
|
|
998
|
-
...r.extensions,
|
|
999
|
-
submit_error: n
|
|
1000
|
-
}
|
|
1001
|
-
};
|
|
1002
|
-
this.records.set(this.key(e, t), i), this.emit({
|
|
1003
|
-
type: "interaction_updated",
|
|
1004
|
-
interaction: i
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
revertToPending(e, t) {
|
|
1008
|
-
let n = this.get(e, t);
|
|
1009
|
-
if (!n || n.status !== "resolving") return;
|
|
1010
|
-
let r = {
|
|
1011
|
-
...n,
|
|
1012
|
-
status: "pending"
|
|
1013
|
-
};
|
|
1014
|
-
this.records.set(this.key(e, t), r), this.emit({
|
|
1015
|
-
type: "interaction_updated",
|
|
1016
|
-
interaction: r
|
|
1017
|
-
});
|
|
1018
|
-
}
|
|
1019
|
-
markRunTerminal(e, t) {
|
|
1020
|
-
if (!(!e || !t)) {
|
|
1021
|
-
this.terminalRuns.add(this.runKey(e, t));
|
|
1022
|
-
for (let n of this.listAll(e)) {
|
|
1023
|
-
if (n.runId !== t || h(n.status)) continue;
|
|
1024
|
-
let r = {
|
|
1025
|
-
...n,
|
|
1026
|
-
status: "expired",
|
|
1027
|
-
outcome: "expired",
|
|
1028
|
-
resolvedAt: n.resolvedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1029
|
-
responseSummary: n.responseSummary ?? "运行已结束"
|
|
1030
|
-
};
|
|
1031
|
-
this.records.set(this.key(e, n.interactionId), r), this.emit({
|
|
1032
|
-
type: "interaction_resolved",
|
|
1033
|
-
interaction: r
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
markSessionTerminal(e) {
|
|
1039
|
-
if (!e) return;
|
|
1040
|
-
let t = new Set(this.listAll(e).filter((e) => !h(e.status)).map((e) => e.runId).filter((e) => !!e));
|
|
1041
|
-
for (let n of t) this.markRunTerminal(e, n);
|
|
1042
|
-
for (let t of this.listAll(e)) {
|
|
1043
|
-
if (t.runId || h(t.status)) continue;
|
|
1044
|
-
let n = {
|
|
1045
|
-
...t,
|
|
1046
|
-
status: "expired",
|
|
1047
|
-
outcome: "expired",
|
|
1048
|
-
resolvedAt: t.resolvedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1049
|
-
responseSummary: t.responseSummary ?? "运行已结束"
|
|
1050
|
-
};
|
|
1051
|
-
this.records.set(this.key(e, t.interactionId), n), this.emit({
|
|
1052
|
-
type: "interaction_resolved",
|
|
1053
|
-
interaction: n
|
|
1054
|
-
});
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
remove(e, t) {
|
|
1058
|
-
let n = this.key(e, t);
|
|
1059
|
-
this.records.has(n) && (this.records.delete(n), this.emit({
|
|
1060
|
-
type: "interaction_removed",
|
|
1061
|
-
interactionId: t
|
|
1062
|
-
}));
|
|
1063
|
-
}
|
|
1064
|
-
clearSession(e) {
|
|
1065
|
-
for (let t of this.listAll(e)) this.remove(e, t.interactionId);
|
|
1066
|
-
let t = `${e}\u0000`;
|
|
1067
|
-
for (let e of this.rejectedCommands.keys()) e.startsWith(t) && this.rejectedCommands.delete(e);
|
|
1068
|
-
for (let e of this.terminalRuns) e.startsWith(t) && this.terminalRuns.delete(e);
|
|
1069
|
-
}
|
|
1070
|
-
}, xt = (e) => typeof e == "object" && e && !Array.isArray(e) ? e : void 0, St = (e, t) => Object.hasOwn(e, t) ? e[t] : void 0, Ct = (e) => e.replace(/~/g, "~0").replace(/\//g, "~1"), wt = /^-?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?$/u;
|
|
1071
|
-
function Tt(e) {
|
|
1072
|
-
let [t, n = "0"] = e.toLowerCase().split("e"), [r, i = ""] = t.replace(/^-/, "").split("."), a = (r + i).replace(/^0+/, "").replace(/0+$/, "");
|
|
1073
|
-
if (!a) return "0";
|
|
1074
|
-
let o = (r + i).length - (r + i).replace(/0+$/, "").length;
|
|
1075
|
-
return `${e.startsWith("-") ? "-" : ""}${a}e${Number(n) - i.length + o}`;
|
|
1076
|
-
}
|
|
1077
|
-
function Et(e, t) {
|
|
1078
|
-
if (typeof e != "string") return e;
|
|
1079
|
-
if (t.includes("boolean") && (e === "true" || e === "false")) return e === "true";
|
|
1080
|
-
if (!t.some((e) => e === "number" || e === "integer") || e.length > 1024 || !wt.test(e)) return e;
|
|
1081
|
-
let n = Number(e);
|
|
1082
|
-
return !Number.isFinite(n) || Tt(e) !== Tt(JSON.stringify(n)) || !t.includes("number") && !Number.isSafeInteger(n) ? e : n === 0 ? 0 : n;
|
|
1083
|
-
}
|
|
1084
|
-
function Dt(e, t) {
|
|
1085
|
-
let n = b(t), r = p(e), i = 0, a = (e, t) => {
|
|
1086
|
-
try {
|
|
1087
|
-
return r(e, t);
|
|
1088
|
-
} catch {
|
|
1089
|
-
return !1;
|
|
1090
|
-
}
|
|
1091
|
-
}, o = (t) => {
|
|
1092
|
-
if (typeof t != "string" || !t.startsWith("#")) return;
|
|
1093
|
-
let n;
|
|
1094
|
-
try {
|
|
1095
|
-
n = decodeURIComponent(t.slice(1));
|
|
1096
|
-
} catch {
|
|
563
|
+
//#region src/core/mcp-authorization/recovery.ts
|
|
564
|
+
function ct(e, t, n, r) {
|
|
565
|
+
let i = /* @__PURE__ */ new Map(), a = !1;
|
|
566
|
+
function o(e) {
|
|
567
|
+
clearTimeout(i.get(e)), i.delete(e);
|
|
568
|
+
}
|
|
569
|
+
function c(c) {
|
|
570
|
+
if (c.sessionId !== t || !c.runId) return;
|
|
571
|
+
let l = c.runId, u = c.interactionId;
|
|
572
|
+
if (c.status !== "pending" || re(c)) {
|
|
573
|
+
o(u);
|
|
1097
574
|
return;
|
|
1098
575
|
}
|
|
1099
|
-
if (
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
};
|
|
1109
|
-
}, s = (e, t, n, r = 0) => {
|
|
1110
|
-
let c = xt(e);
|
|
1111
|
-
if (++i > 8192 || r > 48 || !c || a(t, n)) return n;
|
|
1112
|
-
let l = n, u = o(c.$ref);
|
|
1113
|
-
u && (n = s(u.node, u.path, n, r + 1)), Array.isArray(c.allOf) && c.allOf.forEach((e, i) => {
|
|
1114
|
-
n = s(e, `${t}/allOf/${i}`, n, r + 1);
|
|
1115
|
-
});
|
|
1116
|
-
let d = Array.isArray(c.oneOf) ? "oneOf" : "anyOf", f = c[d];
|
|
1117
|
-
if (Array.isArray(f)) {
|
|
1118
|
-
let e = f.map((e, i) => s(e, `${t}/${d}/${i}`, n, r + 1)).filter((e) => a(t, e)), i = new Map(e.map((e) => [JSON.stringify(e), e]));
|
|
1119
|
-
return i.size === 1 ? [...i.values()][0] : l;
|
|
1120
|
-
}
|
|
1121
|
-
if (Array.isArray(n)) {
|
|
1122
|
-
let e = Array.isArray(c.items), i = e ? c.items : Array.isArray(c.prefixItems) ? c.prefixItems : [], a = e ? c.additionalItems : c.items;
|
|
1123
|
-
return n.map((n, o) => s(o < i.length ? i[o] : a, o < i.length ? `${t}/${e ? "items" : "prefixItems"}/${o}` : `${t}/${e ? "additionalItems" : "items"}`, n, r + 1));
|
|
1124
|
-
}
|
|
1125
|
-
let p = xt(n);
|
|
1126
|
-
if (p) {
|
|
1127
|
-
let e = {}, n = xt(c.properties) || {}, i = xt(c.patternProperties) || {};
|
|
1128
|
-
for (let [a, o] of Object.entries(p)) {
|
|
1129
|
-
let l = o, u = !1;
|
|
1130
|
-
Object.hasOwn(n, a) && (l = s(n[a], `${t}/properties/${Ct(a)}`, l, r + 1), u = !0);
|
|
1131
|
-
for (let [e, n] of Object.entries(i)) new RegExp(e, "u").test(a) && (l = s(n, `${t}/patternProperties/${Ct(e)}`, l, r + 1), u = !0);
|
|
1132
|
-
!u && xt(c.additionalProperties) && (l = s(c.additionalProperties, `${t}/additionalProperties`, l, r + 1)), Object.defineProperty(e, a, {
|
|
1133
|
-
value: l,
|
|
1134
|
-
enumerable: !0,
|
|
1135
|
-
configurable: !0,
|
|
1136
|
-
writable: !0
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
return e;
|
|
1140
|
-
}
|
|
1141
|
-
return Et(n, Array.isArray(c.type) ? c.type : [c.type]);
|
|
1142
|
-
}, l = s(e, "", n), u = c(e, l);
|
|
1143
|
-
if (!u.valid) throw TypeError(u.issues.join(";"));
|
|
1144
|
-
return l;
|
|
1145
|
-
}
|
|
1146
|
-
//#endregion
|
|
1147
|
-
//#region src/core/interaction/client.ts
|
|
1148
|
-
var Ot = {
|
|
1149
|
-
approve: "approved",
|
|
1150
|
-
reject: "rejected",
|
|
1151
|
-
submit: "submitted",
|
|
1152
|
-
cancel: "cancelled"
|
|
1153
|
-
};
|
|
1154
|
-
function J(e, t) {
|
|
1155
|
-
return {
|
|
1156
|
-
schema_version: 1,
|
|
1157
|
-
command_id: `local-${t}`,
|
|
1158
|
-
status: e,
|
|
1159
|
-
message_id: null,
|
|
1160
|
-
run_id: null,
|
|
1161
|
-
accepted_seq: null,
|
|
1162
|
-
error: null,
|
|
1163
|
-
extensions: {}
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
var kt = class {
|
|
1167
|
-
store;
|
|
1168
|
-
deps;
|
|
1169
|
-
inFlight = /* @__PURE__ */ new Map();
|
|
1170
|
-
constructor(e) {
|
|
1171
|
-
this.deps = e, this.store = e.store || new bt();
|
|
1172
|
-
}
|
|
1173
|
-
listPending(e) {
|
|
1174
|
-
return this.store.listPending(e);
|
|
1175
|
-
}
|
|
1176
|
-
setInteractionV1Enabled(e) {
|
|
1177
|
-
this.deps.interactionV1Enabled = e;
|
|
1178
|
-
}
|
|
1179
|
-
subscribe(e) {
|
|
1180
|
-
return this.store.subscribe(e);
|
|
1181
|
-
}
|
|
1182
|
-
ingest(e) {
|
|
1183
|
-
this.store.upsert(e);
|
|
1184
|
-
}
|
|
1185
|
-
ingestHistory(e) {
|
|
1186
|
-
for (let t of e) this.store.upsert(t);
|
|
1187
|
-
for (let [e] of this.inFlight) {
|
|
1188
|
-
let t = this.store.all().find((t) => this.recordKey(t) === e);
|
|
1189
|
-
t && t.status !== "pending" && t.status !== "resolving" && this.inFlight.delete(e);
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
recordKey(e) {
|
|
1193
|
-
return JSON.stringify([e.sessionId, e.interactionId]);
|
|
1194
|
-
}
|
|
1195
|
-
findByInteractionId(e, t) {
|
|
1196
|
-
if (t) return this.store.get(t, e);
|
|
1197
|
-
let n = this.store.all().filter((t) => t.interactionId === e);
|
|
1198
|
-
return n.length === 1 ? n[0] : null;
|
|
1199
|
-
}
|
|
1200
|
-
async respond(e) {
|
|
1201
|
-
let t = this.findByInteractionId(e.interactionId, e.sessionId);
|
|
1202
|
-
if (!t) return J("rejected", e.interactionId);
|
|
1203
|
-
if (t.status === "resolved" || t.status === "cancelled" || t.status === "expired" || t.status === "resolving") return J("duplicate", e.interactionId);
|
|
1204
|
-
try {
|
|
1205
|
-
b(e.response);
|
|
1206
|
-
} catch {
|
|
1207
|
-
return this.store.markFailed(t.sessionId, e.interactionId, {
|
|
1208
|
-
code: "input_response_invalid",
|
|
1209
|
-
message: "答案必须是合法 JSON 值。",
|
|
1210
|
-
retryable: !0
|
|
1211
|
-
}), J("rejected", e.interactionId);
|
|
1212
|
-
}
|
|
1213
|
-
if (t.kind === "structured_input" && e.action === "submit" && t.requestSchema) try {
|
|
1214
|
-
e = {
|
|
1215
|
-
...e,
|
|
1216
|
-
response: Dt(t.requestSchema, e.response)
|
|
1217
|
-
};
|
|
1218
|
-
} catch (n) {
|
|
1219
|
-
return this.store.markFailed(t.sessionId, e.interactionId, {
|
|
1220
|
-
code: "input_response_invalid",
|
|
1221
|
-
message: n instanceof Error ? n.message : "答案不符合表单约束。",
|
|
1222
|
-
retryable: !0
|
|
1223
|
-
}), J("rejected", e.interactionId);
|
|
1224
|
-
}
|
|
1225
|
-
if (t.source === "agui" && !this.deps.interactionV1Enabled && e.action !== "cancel" && e.response === null) return this.store.markFailed(t.sessionId, e.interactionId, {
|
|
1226
|
-
code: "input_transport_unsupported",
|
|
1227
|
-
message: "当前 AG-UI 传输不能提交根 null,请使用 Interaction/v1。",
|
|
1228
|
-
retryable: !1
|
|
1229
|
-
}), J("rejected", e.interactionId);
|
|
1230
|
-
let n = e.idempotencyKey || d(e.interactionId, e.expectedRevision), r = t.extensions.rejected_command_id, i = r ? `${n}:retry-${r}` : n, a = this.recordKey(t), o = this.inFlight.get(a);
|
|
1231
|
-
if (o) return J(o === i ? "duplicate" : "rejected", e.interactionId);
|
|
1232
|
-
this.inFlight.set(a, i), this.store.markResolving(t.sessionId, e.interactionId);
|
|
1233
|
-
let s = this.deps.interactionV1Enabled || t.source === "interaction_v1";
|
|
1234
|
-
try {
|
|
1235
|
-
if (!s && t.source === "responses" && this.deps.legacyResponsesApproval) {
|
|
1236
|
-
let n = t.extensions.previous_response_id;
|
|
1237
|
-
return await this.deps.legacyResponsesApproval(e.interactionId, e.action === "approve", ...typeof n == "string" && n ? [n] : []) === !1 ? (this.store.markFailed(t.sessionId, e.interactionId, {
|
|
1238
|
-
code: "interaction_not_dispatched",
|
|
1239
|
-
message: "交互尚未提交,请稍后重试。",
|
|
1240
|
-
retryable: !0
|
|
1241
|
-
}), J("rejected", e.interactionId)) : (this.resolveLocal(t, e, i), J("accepted", e.interactionId));
|
|
1242
|
-
}
|
|
1243
|
-
if (!s && 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.store.recordIdempotencyKey(t.sessionId, e.interactionId, i), J("accepted", e.interactionId)) : (this.store.revertToPending(t.sessionId, e.interactionId), J("rejected", e.interactionId));
|
|
1244
|
-
let n = Ve(await this.deps.submitInteraction({
|
|
1245
|
-
AgentId: this.deps.agentId,
|
|
1246
|
-
SessionId: t.sessionId,
|
|
1247
|
-
RunId: t.runId || "",
|
|
1248
|
-
InteractionId: e.interactionId,
|
|
1249
|
-
ExpectedRevision: e.expectedRevision,
|
|
1250
|
-
Action: e.action,
|
|
1251
|
-
Response: e.response,
|
|
1252
|
-
IdempotencyKey: i
|
|
1253
|
-
}));
|
|
1254
|
-
return n.status === "accepted" || n.status === "duplicate" ? (this.store.recordCommand(t.sessionId, e.interactionId, n.command_id), this.store.recordIdempotencyKey(t.sessionId, e.interactionId, i)) : n.status === "queue_full" ? this.store.revertToPending(t.sessionId, e.interactionId) : this.store.markFailed(t.sessionId, e.interactionId, {
|
|
1255
|
-
code: n.error?.code ?? String(n.status),
|
|
1256
|
-
message: n.error?.message ?? `提交未通过(${n.status})`,
|
|
1257
|
-
retryable: n.error?.retryable ?? !1
|
|
1258
|
-
}), n;
|
|
1259
|
-
} catch (n) {
|
|
1260
|
-
let r = n instanceof Error ? n.message : String(n || "交互提交失败");
|
|
1261
|
-
throw this.store.markFailed(t.sessionId, e.interactionId, {
|
|
1262
|
-
code: "interaction_submit_failed",
|
|
1263
|
-
message: r,
|
|
1264
|
-
retryable: !0
|
|
1265
|
-
}), n;
|
|
1266
|
-
} finally {
|
|
1267
|
-
this.inFlight.delete(a);
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
resolveLocal(e, t, n) {
|
|
1271
|
-
let r = this.store.get(e.sessionId, t.interactionId);
|
|
1272
|
-
if (!r || h(r.status)) return;
|
|
1273
|
-
let i = t.action === "cancel" ? "cancelled" : "resolved";
|
|
1274
|
-
this.store.resolveLocally(e.sessionId, t.interactionId, {
|
|
1275
|
-
status: i,
|
|
1276
|
-
outcome: Ot[t.action],
|
|
1277
|
-
actor: "user",
|
|
1278
|
-
responseSummary: e.kind === "structured_input" ? t.action === "cancel" ? "已取消" : "已提交" : l(t.action, t.response),
|
|
1279
|
-
revision: t.expectedRevision
|
|
1280
|
-
});
|
|
1281
|
-
let a = this.store.get(e.sessionId, t.interactionId);
|
|
1282
|
-
a && this.store.upsert({
|
|
1283
|
-
...a,
|
|
1284
|
-
extensions: {
|
|
1285
|
-
...a.extensions,
|
|
1286
|
-
idempotency_key: n
|
|
1287
|
-
}
|
|
1288
|
-
});
|
|
1289
|
-
}
|
|
1290
|
-
}, At = new Set([
|
|
1291
|
-
"interaction.requested",
|
|
1292
|
-
"interaction_requested",
|
|
1293
|
-
"ksadk.interaction/v1.requested",
|
|
1294
|
-
"InteractionRequested",
|
|
1295
|
-
"approval.requested",
|
|
1296
|
-
"a2ui.interaction"
|
|
1297
|
-
]), jt = new Set([
|
|
1298
|
-
"interaction.resolved",
|
|
1299
|
-
"interaction_resolved",
|
|
1300
|
-
"ksadk.interaction/v1.resolved",
|
|
1301
|
-
"InteractionResolved",
|
|
1302
|
-
"interaction.cancelled",
|
|
1303
|
-
"interaction.cancel",
|
|
1304
|
-
"interaction.expired",
|
|
1305
|
-
"approval.resolved",
|
|
1306
|
-
"a2ui.action"
|
|
1307
|
-
]);
|
|
1308
|
-
function Y(e) {
|
|
1309
|
-
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
1310
|
-
}
|
|
1311
|
-
function Mt(e, t) {
|
|
1312
|
-
let n = Y(e);
|
|
1313
|
-
if (!n) return null;
|
|
1314
|
-
let r = Y(n.Content ?? n.content), i = Y(r?.session_event ?? r?.sessionEvent), a = Y(n.payload), o = i ?? (a?.family === "interaction" ? a : null) ?? (n.family === "interaction" ? n : null);
|
|
1315
|
-
if (o && o.family !== "interaction") return null;
|
|
1316
|
-
let s = o ?? n, c = String(s.event_type || s.EventType || "").trim();
|
|
1317
|
-
if (!c) return null;
|
|
1318
|
-
let l = Y(s.payload ?? s.Content) ?? (o || {}), u = Y(l.interaction) || Y(l.Interaction) || Y(l.interaction_request) || l, d = String(u.interaction_id || u.interactionId || u.InteractionId || u.approval_id || u.approvalId || l.interaction_id || l.interactionId || l.InteractionId || l.approval_id || l.approvalId || "");
|
|
1319
|
-
if (!d) return null;
|
|
1320
|
-
let f = String(s.session_id || s.SessionId || u.session_id || u.sessionId || t || "");
|
|
1321
|
-
if (!f) return null;
|
|
1322
|
-
if (At.has(c)) {
|
|
1323
|
-
let e = Y(u.request) || {}, t = Y(u.presentation ?? e.presentation), n = {
|
|
1324
|
-
...Y(u.extensions) || {},
|
|
1325
|
-
...u.detail === void 0 ? {} : { detail: u.detail },
|
|
1326
|
-
...(u.call_id ?? u.callId) === void 0 ? {} : { call_id: u.call_id ?? u.callId }
|
|
1327
|
-
};
|
|
1328
|
-
return yt({
|
|
1329
|
-
interactionId: d,
|
|
1330
|
-
sessionId: f,
|
|
1331
|
-
runId: u.run_id ?? u.runId ?? s.run_id ?? s.InvocationId,
|
|
1332
|
-
kind: c === "approval.requested" ? "approval" : u.kind === "form" ? "structured_input" : u.kind ?? e.kind ?? "approval",
|
|
1333
|
-
title: u.title ?? t?.title,
|
|
1334
|
-
message: u.message ?? u.description ?? Y(u.detail)?.command ?? t?.description,
|
|
1335
|
-
requestSchema: u.request_schema ?? u.requestSchema ?? u.input_schema ?? u.inputSchema ?? u.RequestSchema ?? e.request_schema,
|
|
1336
|
-
presentation: t,
|
|
1337
|
-
status: "pending",
|
|
1338
|
-
revision: u.revision ?? 1,
|
|
1339
|
-
createdAt: u.created_at ?? u.createdAt ?? s.timestamp ?? s.Timestamp,
|
|
1340
|
-
expiresAt: u.expires_at ?? e.expires_at,
|
|
1341
|
-
source: "interaction_v1",
|
|
1342
|
-
extensions: n
|
|
1343
|
-
});
|
|
1344
|
-
}
|
|
1345
|
-
if (jt.has(c)) {
|
|
1346
|
-
let e = {
|
|
1347
|
-
...Y(u.extensions) || {},
|
|
1348
|
-
...u.detail === void 0 ? {} : { detail: u.detail },
|
|
1349
|
-
...(u.call_id ?? u.callId) === void 0 ? {} : { call_id: u.call_id ?? u.callId }
|
|
1350
|
-
}, t = c === "interaction.cancelled" || c === "interaction.cancel" ? "cancelled" : c === "interaction.expired" ? "expired" : "resolved", n = String(l.outcome ?? u.outcome ?? u.status ?? "").toLowerCase(), r = String(l.action ?? u.action ?? l.name ?? u.name ?? "").toLowerCase(), i = n;
|
|
1351
|
-
i ||= r === "approve" ? "approved" : r === "reject" ? "rejected" : r === "submit" ? "submitted" : r === "cancel" || t === "cancelled" ? "cancelled" : t === "expired" ? "expired" : "submitted";
|
|
1352
|
-
let a = t === "resolved" ? "resolved" : t;
|
|
1353
|
-
return yt({
|
|
1354
|
-
interactionId: d,
|
|
1355
|
-
sessionId: f,
|
|
1356
|
-
runId: u.run_id ?? u.runId ?? s.run_id ?? s.InvocationId,
|
|
1357
|
-
kind: u.kind,
|
|
1358
|
-
title: u.title,
|
|
1359
|
-
message: u.message,
|
|
1360
|
-
requestSchema: u.request_schema,
|
|
1361
|
-
presentation: u.presentation,
|
|
1362
|
-
status: a,
|
|
1363
|
-
revision: u.revision,
|
|
1364
|
-
createdAt: u.created_at ?? s.timestamp,
|
|
1365
|
-
expiresAt: u.expires_at,
|
|
1366
|
-
resolvedAt: l.resolved_at ?? l.resolvedAt ?? u.resolved_at ?? u.resolvedAt ?? s.timestamp ?? s.Timestamp,
|
|
1367
|
-
actor: l.actor ?? u.actor ?? s.actor_ref,
|
|
1368
|
-
outcome: i,
|
|
1369
|
-
responseSummary: l.response_summary ?? u.response_summary ?? (r ? `${r}` : void 0),
|
|
1370
|
-
...Object.hasOwn(u, "response") ? { response: u.response } : Object.hasOwn(l, "response") ? { response: l.response } : !o && ["a2ui.action", "interaction.resolved"].includes(c) && Object.hasOwn(u, "data") ? { response: u.data } : {},
|
|
1371
|
-
source: "interaction_v1",
|
|
1372
|
-
extensions: e
|
|
1373
|
-
});
|
|
1374
|
-
}
|
|
1375
|
-
return null;
|
|
1376
|
-
}
|
|
1377
|
-
//#endregion
|
|
1378
|
-
//#region src/core/interaction/adapters/responses.ts
|
|
1379
|
-
function Nt(e) {
|
|
1380
|
-
return !e.approvalRequestId || !e.sessionId ? null : yt({
|
|
1381
|
-
interactionId: e.approvalRequestId,
|
|
1382
|
-
sessionId: e.sessionId,
|
|
1383
|
-
runId: e.runId ?? null,
|
|
1384
|
-
kind: "approval",
|
|
1385
|
-
title: e.name ? `审批:${e.name}` : "人工确认",
|
|
1386
|
-
message: e.message || "本次运行需要人工审批后才能继续。",
|
|
1387
|
-
requestSchema: e.requestSchema ?? null,
|
|
1388
|
-
status: "pending",
|
|
1389
|
-
revision: 1,
|
|
1390
|
-
source: "responses",
|
|
1391
|
-
extensions: {
|
|
1392
|
-
...e.previousResponseId ? { previous_response_id: e.previousResponseId } : {},
|
|
1393
|
-
...e.approvalLevel ? { approval_level: e.approvalLevel } : {},
|
|
1394
|
-
...e.args ? { arguments: e.args } : {}
|
|
1395
|
-
}
|
|
1396
|
-
});
|
|
1397
|
-
}
|
|
1398
|
-
//#endregion
|
|
1399
|
-
//#region src/core/interaction/adapters/agui.ts
|
|
1400
|
-
function Pt(e) {
|
|
1401
|
-
return !e.interruptId || !e.sessionId ? null : yt({
|
|
1402
|
-
interactionId: e.interruptId,
|
|
1403
|
-
sessionId: e.sessionId,
|
|
1404
|
-
runId: e.runId ?? null,
|
|
1405
|
-
kind: e.requestSchema ? "structured_input" : "approval",
|
|
1406
|
-
title: e.name ? `确认:${e.name}` : "人工确认",
|
|
1407
|
-
message: e.message || "本次运行需要人工确认后才能继续。",
|
|
1408
|
-
requestSchema: e.requestSchema ?? null,
|
|
1409
|
-
status: "pending",
|
|
1410
|
-
revision: 1,
|
|
1411
|
-
source: "agui",
|
|
1412
|
-
extensions: {
|
|
1413
|
-
interrupt_id: e.interruptId,
|
|
1414
|
-
...e.toolCallId ? { tool_call_id: e.toolCallId } : {},
|
|
1415
|
-
...e.reason ? { reason: e.reason } : {}
|
|
1416
|
-
}
|
|
1417
|
-
});
|
|
1418
|
-
}
|
|
1419
|
-
//#endregion
|
|
1420
|
-
//#region src/core/interaction/legacy-history.ts
|
|
1421
|
-
var Ft = (e) => typeof e == "string" && e ? e : void 0;
|
|
1422
|
-
function It(e, t, n) {
|
|
1423
|
-
for (let r of n) {
|
|
1424
|
-
if (r.agentBlock && It(e, t, r.agentBlock.messages), r.eventType === "conversation_item_v1") continue;
|
|
1425
|
-
let n = Object.values(r.tools || {}), i = [...n];
|
|
1426
|
-
for (let e of r.blocks || []) {
|
|
1427
|
-
if (e.type !== "tool" || !Ft(e.extra?.approvalRequestId)) continue;
|
|
1428
|
-
let t = e.extra || {}, r = n.find((e) => e.approvalRequestId === t.approvalRequestId);
|
|
1429
|
-
i.push({
|
|
1430
|
-
...r,
|
|
1431
|
-
name: e.toolName,
|
|
1432
|
-
args: e.args,
|
|
1433
|
-
status: e.status,
|
|
1434
|
-
approvalRequestId: Ft(t.approvalRequestId),
|
|
1435
|
-
approvalStatus: Ft(t.approvalStatus) || r?.approvalStatus,
|
|
1436
|
-
approvalProtocol: Ft(t.approvalProtocol) || r?.approvalProtocol,
|
|
1437
|
-
approvalMessage: Ft(t.approvalMessage) || r?.approvalMessage,
|
|
1438
|
-
previousResponseId: Ft(t.previousResponseId) || r?.previousResponseId
|
|
1439
|
-
});
|
|
1440
|
-
}
|
|
1441
|
-
for (let n of i) {
|
|
1442
|
-
let i = n.approvalRequestId, a = n.approvalProtocol, o = n.approvalStatus || (n.status === "paused" ? "pending" : void 0);
|
|
1443
|
-
if (!i || !o || ![
|
|
1444
|
-
"pending",
|
|
1445
|
-
"approved",
|
|
1446
|
-
"rejected",
|
|
1447
|
-
"cancelled"
|
|
1448
|
-
].includes(o) || a !== "responses" && a !== "ag-ui") continue;
|
|
1449
|
-
let s = e.get(t, i);
|
|
1450
|
-
if (s && (s.source === "interaction_v1" || h(s.status))) continue;
|
|
1451
|
-
let c = {
|
|
1452
|
-
sessionId: t,
|
|
1453
|
-
runId: r.runId || r.invocationId,
|
|
1454
|
-
name: n.name,
|
|
1455
|
-
message: n.approvalMessage,
|
|
1456
|
-
args: n.args,
|
|
1457
|
-
previousResponseId: n.previousResponseId || r.responseId
|
|
1458
|
-
}, l = a === "ag-ui" ? Pt({
|
|
1459
|
-
...c,
|
|
1460
|
-
interruptId: i,
|
|
1461
|
-
toolCallId: n.callId
|
|
1462
|
-
}) : Nt({
|
|
1463
|
-
...c,
|
|
1464
|
-
approvalRequestId: i
|
|
1465
|
-
});
|
|
1466
|
-
l && (l.revision = s?.revision || l.revision, l.createdAt = s?.createdAt || l.createdAt, l.runId = s?.runId || l.runId, l.extensions = {
|
|
1467
|
-
...l.extensions,
|
|
1468
|
-
...s?.extensions
|
|
1469
|
-
}, o !== "pending" && (l.status = o === "cancelled" ? "cancelled" : "resolved", l.outcome = o), e.upsert(l));
|
|
576
|
+
if (i.has(u)) return;
|
|
577
|
+
async function d() {
|
|
578
|
+
try {
|
|
579
|
+
let o = await n("GetMcpAuthorizationWait", u, void 0, t);
|
|
580
|
+
if (a || !i.has(u)) return;
|
|
581
|
+
let c = s(o, t, l), d = e.get(t, u);
|
|
582
|
+
c?.interactionId === u && d && c.revision > d.revision && (e.upsert(c), (c.status === "resolved" || c.status === "cancelled" || c.status === "expired") && r(t));
|
|
583
|
+
} catch {}
|
|
584
|
+
!a && i.has(u) && i.set(u, setTimeout(d, 3e3));
|
|
1470
585
|
}
|
|
586
|
+
i.set(u, setTimeout(d, 3e3));
|
|
1471
587
|
}
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
function X(e) {
|
|
1476
|
-
return e && typeof e == "object" && !Array.isArray(e) ? e : null;
|
|
1477
|
-
}
|
|
1478
|
-
function Lt(e, t) {
|
|
1479
|
-
let n = X(e), r = X(X(n?.Content)?.runtime_event);
|
|
1480
|
-
if (!r || r.schema_version !== 2 || r.interaction_kind !== "approval") return null;
|
|
1481
|
-
let i = X(r.source);
|
|
1482
|
-
if (![
|
|
1483
|
-
"langgraph",
|
|
1484
|
-
"langchain",
|
|
1485
|
-
"deepagents"
|
|
1486
|
-
].includes(String(i?.framework))) return null;
|
|
1487
|
-
let a = String(n?.SessionId || t || ""), o = typeof r.interaction_id == "string" ? r.interaction_id : "";
|
|
1488
|
-
if (!a || !o) return null;
|
|
1489
|
-
let s = X(r.request), c = X(s?.detail), l = X(r.response), u = r.event_type === "interaction.requested", d = r.event_type === "interaction.resolved";
|
|
1490
|
-
if (u && (s?.request_type !== "approval" || c?.approval_request_id !== o) || !u && (!d || l?.response_type !== "approval")) return null;
|
|
1491
|
-
let f = X((Array.isArray(c?.action_requests) ? c.action_requests : [])[0]), p = c?.arguments ?? f?.args, m = X(i?.metadata), h = Nt({
|
|
1492
|
-
approvalRequestId: o,
|
|
1493
|
-
sessionId: a,
|
|
1494
|
-
runId: String(r.run_id || n?.InvocationId || "") || void 0,
|
|
1495
|
-
name: String(c?.tool_name || f?.name || "") || void 0,
|
|
1496
|
-
message: typeof c?.description == "string" ? c.description : void 0,
|
|
1497
|
-
args: p === void 0 ? void 0 : typeof p == "string" ? p : JSON.stringify(p),
|
|
1498
|
-
previousResponseId: typeof m?.response_id == "string" ? m.response_id : void 0
|
|
1499
|
-
});
|
|
1500
|
-
if (!h) return null;
|
|
1501
|
-
if (h.createdAt = String(r.timestamp ?? n?.Timestamp ?? h.createdAt), d) {
|
|
1502
|
-
let e = l?.decision;
|
|
1503
|
-
if (e !== "approved" && e !== "rejected" && e !== "canceled") return null;
|
|
1504
|
-
h.status = e === "canceled" ? "cancelled" : "resolved", h.outcome = e === "canceled" ? "cancelled" : e, h.resolvedAt = h.createdAt;
|
|
1505
|
-
}
|
|
1506
|
-
return h;
|
|
1507
|
-
}
|
|
1508
|
-
//#endregion
|
|
1509
|
-
//#region src/core/interaction/index.ts
|
|
1510
|
-
var Rt = new Set([
|
|
1511
|
-
"completed",
|
|
1512
|
-
"failed",
|
|
1513
|
-
"error",
|
|
1514
|
-
"cancelled",
|
|
1515
|
-
"canceled",
|
|
1516
|
-
"aborted",
|
|
1517
|
-
"resume_failed"
|
|
1518
|
-
]), Z = new bt();
|
|
1519
|
-
function zt(e, t) {
|
|
1520
|
-
It(Z, t, e);
|
|
1521
|
-
}
|
|
1522
|
-
function Bt(e, t) {
|
|
1523
|
-
let n = Mt(e, t) ?? Lt(e, t);
|
|
1524
|
-
n && Z.upsert(n);
|
|
1525
|
-
let r = typeof e == "object" && e ? e : null;
|
|
1526
|
-
if (r?.EventType === "control.command_rejected") {
|
|
1527
|
-
let e = r.Content;
|
|
1528
|
-
Z.rejectCommand(String(r.SessionId || t || ""), String(e?.command_id || ""), String(e?.reason || "command_rejected"));
|
|
1529
|
-
}
|
|
1530
|
-
let i = r ? se(r) : null;
|
|
1531
|
-
if (i !== null && Rt.has(i)) {
|
|
1532
|
-
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 || "");
|
|
1533
|
-
Z.markRunTerminal(i, a);
|
|
1534
|
-
}
|
|
1535
|
-
return n;
|
|
1536
|
-
}
|
|
1537
|
-
function Vt(e) {
|
|
1538
|
-
let t = e.sessionId || "";
|
|
1539
|
-
if (!t || !e.approvalRequestId) return null;
|
|
1540
|
-
let n = e.protocol === "ag-ui" ? Pt({
|
|
1541
|
-
interruptId: e.approvalRequestId,
|
|
1542
|
-
sessionId: t,
|
|
1543
|
-
runId: e.runId,
|
|
1544
|
-
name: e.name,
|
|
1545
|
-
message: e.message,
|
|
1546
|
-
reason: e.approvalLevel,
|
|
1547
|
-
requestSchema: e.requestSchema
|
|
1548
|
-
}) : Nt({
|
|
1549
|
-
approvalRequestId: e.approvalRequestId,
|
|
1550
|
-
sessionId: t,
|
|
1551
|
-
runId: e.runId,
|
|
1552
|
-
name: e.name,
|
|
1553
|
-
message: e.message,
|
|
1554
|
-
args: e.args,
|
|
1555
|
-
approvalLevel: e.approvalLevel,
|
|
1556
|
-
previousResponseId: e.previousResponseId
|
|
1557
|
-
});
|
|
1558
|
-
return n && Z.upsert(n), n;
|
|
1559
|
-
}
|
|
1560
|
-
function Ht(e) {
|
|
1561
|
-
let t = e.sessionId || "";
|
|
1562
|
-
if (!t || !e.approvalRequestId) return null;
|
|
1563
|
-
let n = Z.get(t, e.approvalRequestId);
|
|
1564
|
-
return n?.source === "agui" && n.kind === "structured_input" ? h(n.status) ? n : (Z.resolveLocally(t, n.interactionId, {
|
|
1565
|
-
status: e.decision === "cancelled" ? "cancelled" : "resolved",
|
|
1566
|
-
outcome: e.decision === "cancelled" ? "cancelled" : "submitted",
|
|
1567
|
-
revision: e.revision || 2,
|
|
1568
|
-
actor: "user"
|
|
1569
|
-
}), Z.get(t, n.interactionId)) : Bt({
|
|
1570
|
-
EventType: "approval.resolved",
|
|
1571
|
-
Content: {
|
|
1572
|
-
approvalId: e.approvalRequestId,
|
|
1573
|
-
revision: e.revision || 2,
|
|
1574
|
-
outcome: e.decision,
|
|
1575
|
-
actor: "user",
|
|
1576
|
-
resolvedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1577
|
-
}
|
|
1578
|
-
}, t);
|
|
1579
|
-
}
|
|
1580
|
-
function Ut(e) {
|
|
1581
|
-
let t = Z.get(e.sessionId || "", e.interactionId);
|
|
1582
|
-
!t || t.source !== "agui" || h(t.status) || Z.markFailed(t.sessionId, t.interactionId, {
|
|
1583
|
-
code: "input_response_invalid",
|
|
1584
|
-
message: e.message,
|
|
1585
|
-
retryable: !0
|
|
588
|
+
e.listAll(t).forEach(c);
|
|
589
|
+
let l = e.subscribe((e) => {
|
|
590
|
+
e.type === "interaction_removed" ? o(e.interactionId) : c(e.interaction);
|
|
1586
591
|
});
|
|
592
|
+
return () => {
|
|
593
|
+
a = !0, l();
|
|
594
|
+
for (let e of i.keys()) o(e);
|
|
595
|
+
};
|
|
1587
596
|
}
|
|
1588
597
|
//#endregion
|
|
1589
598
|
//#region src/hooks/useInteractions.ts
|
|
1590
|
-
function
|
|
1591
|
-
let t =
|
|
599
|
+
function lt(e) {
|
|
600
|
+
let t = _(), [n] = Ie(() => new a({
|
|
1592
601
|
agentId: e.agentId,
|
|
1593
|
-
store:
|
|
602
|
+
store: T,
|
|
1594
603
|
submitInteraction: (t) => e.api.submitInteraction({
|
|
1595
604
|
...t,
|
|
1596
605
|
AgentId: e.getAgentId?.() ?? t.AgentId
|
|
@@ -1599,68 +608,90 @@ function Wt(e) {
|
|
|
1599
608
|
legacyResponsesApproval: e.legacyResponsesApproval,
|
|
1600
609
|
legacyAguiResume: e.legacyAguiResume
|
|
1601
610
|
}));
|
|
1602
|
-
|
|
611
|
+
q(() => {
|
|
1603
612
|
n.setInteractionV1Enabled(e.interactionV1Enabled);
|
|
1604
613
|
}, [n, e.interactionV1Enabled]);
|
|
1605
|
-
let [r, i] =
|
|
1606
|
-
|
|
1607
|
-
let
|
|
1608
|
-
|
|
614
|
+
let [r, i] = Ie(0);
|
|
615
|
+
q(() => T.subscribe(() => i((e) => e + 1)), []);
|
|
616
|
+
let o = Fe(() => e.currentSessionId ? T.listAll(e.currentSessionId).filter(re) : [], [r, e.currentSessionId]), s = Fe(() => e.currentSessionId ? T.listAll(e.currentSessionId) : [], [r, e.currentSessionId]), { currentSessionId: c, interactionV1Enabled: l, onAcceptedInteraction: u } = e, d = e.api.mcpAuthorization, f = e.reloadHistory;
|
|
617
|
+
q(() => {
|
|
618
|
+
if (c && d) return ct(T, c, d, f);
|
|
619
|
+
}, [
|
|
620
|
+
e.agentId,
|
|
621
|
+
c,
|
|
622
|
+
d,
|
|
623
|
+
f
|
|
624
|
+
]);
|
|
625
|
+
let p = J(/* @__PURE__ */ new Set());
|
|
626
|
+
return q(() => {
|
|
627
|
+
for (let e of s) {
|
|
628
|
+
let t = e.extensions.mcpAuthorization;
|
|
629
|
+
if (!t || ![
|
|
630
|
+
"credential_ready",
|
|
631
|
+
"connecting",
|
|
632
|
+
"resumed",
|
|
633
|
+
"cancelled",
|
|
634
|
+
"expired"
|
|
635
|
+
].includes(t.status || "")) continue;
|
|
636
|
+
let n = `${e.sessionId}:${e.interactionId}:${t.status}`;
|
|
637
|
+
p.current.has(n) || (p.current.add(n), u?.(e));
|
|
638
|
+
}
|
|
639
|
+
}, [s, u]), {
|
|
1609
640
|
client: n,
|
|
1610
|
-
pending:
|
|
1611
|
-
records:
|
|
1612
|
-
respond:
|
|
1613
|
-
let t =
|
|
1614
|
-
return
|
|
641
|
+
pending: o,
|
|
642
|
+
records: s,
|
|
643
|
+
respond: K((e) => {
|
|
644
|
+
let t = c ? T.get(c, e.interactionId) : null;
|
|
645
|
+
return c ? n.respond({
|
|
1615
646
|
...e,
|
|
1616
|
-
sessionId:
|
|
1617
|
-
}).then((e) => (t && (
|
|
647
|
+
sessionId: c
|
|
648
|
+
}).then((e) => (t && (l || t.source === "interaction_v1") && (e.status === "accepted" || e.status === "duplicate") && u?.(t), e)) : Promise.reject(/* @__PURE__ */ Error("请先选择会话。"));
|
|
1618
649
|
}, [
|
|
1619
650
|
n,
|
|
1620
|
-
s,
|
|
1621
651
|
c,
|
|
1622
|
-
l
|
|
652
|
+
l,
|
|
653
|
+
u
|
|
1623
654
|
]),
|
|
1624
655
|
localCatalog: t
|
|
1625
656
|
};
|
|
1626
657
|
}
|
|
1627
|
-
var
|
|
1628
|
-
function
|
|
658
|
+
var ut = .28;
|
|
659
|
+
function dt(e, t = 768) {
|
|
1629
660
|
return Number(e) <= t;
|
|
1630
661
|
}
|
|
1631
|
-
function
|
|
662
|
+
function ft({ isMobile: e, desktopSidebarOpen: t, mobileSidebarOpen: n }) {
|
|
1632
663
|
return {
|
|
1633
664
|
desktopSidebarVisible: !e && !!t,
|
|
1634
665
|
mobileDrawerVisible: !!(e && n)
|
|
1635
666
|
};
|
|
1636
667
|
}
|
|
1637
|
-
function
|
|
668
|
+
function pt({ isMobile: e, viewportHeight: t, desktopMaxHeight: n = 160 }) {
|
|
1638
669
|
if (!e) return n;
|
|
1639
670
|
let r = Number(t);
|
|
1640
671
|
if (!Number.isFinite(r) || r <= 0) return n;
|
|
1641
|
-
let i = Math.floor(r *
|
|
672
|
+
let i = Math.floor(r * ut);
|
|
1642
673
|
return Math.max(120, Math.min(n, i));
|
|
1643
674
|
}
|
|
1644
675
|
//#endregion
|
|
1645
676
|
//#region src/hooks/useResponsiveViewport.ts
|
|
1646
|
-
function
|
|
677
|
+
function mt() {
|
|
1647
678
|
return typeof window > "u" ? 900 : Math.round(window.visualViewport?.height || window.innerHeight || 900);
|
|
1648
679
|
}
|
|
1649
|
-
function
|
|
680
|
+
function ht() {
|
|
1650
681
|
return typeof window > "u" ? {
|
|
1651
682
|
isMobile: !1,
|
|
1652
683
|
viewportHeight: 900
|
|
1653
684
|
} : {
|
|
1654
|
-
isMobile:
|
|
1655
|
-
viewportHeight:
|
|
685
|
+
isMobile: dt(window.innerWidth, 768),
|
|
686
|
+
viewportHeight: mt()
|
|
1656
687
|
};
|
|
1657
688
|
}
|
|
1658
|
-
function
|
|
1659
|
-
let [e, t] =
|
|
1660
|
-
return
|
|
689
|
+
function gt() {
|
|
690
|
+
let [e, t] = Ie(() => ht());
|
|
691
|
+
return q(() => {
|
|
1661
692
|
if (typeof window > "u") return;
|
|
1662
693
|
let e = window.matchMedia("(max-width: 768px)"), n = () => {
|
|
1663
|
-
t(
|
|
694
|
+
t(ht());
|
|
1664
695
|
};
|
|
1665
696
|
n();
|
|
1666
697
|
let r = typeof e.addEventListener == "function" ? (e.addEventListener("change", n), () => e.removeEventListener("change", n)) : (e.addListener(n), () => e.removeListener(n));
|
|
@@ -1671,23 +702,23 @@ function Zt() {
|
|
|
1671
702
|
}
|
|
1672
703
|
//#endregion
|
|
1673
704
|
//#region src/core/stream/responses-protocol.ts
|
|
1674
|
-
var
|
|
705
|
+
var _t = class {
|
|
1675
706
|
id = "responses";
|
|
1676
707
|
createState() {
|
|
1677
|
-
return
|
|
708
|
+
return V();
|
|
1678
709
|
}
|
|
1679
710
|
parseItemOperations(e, t, n) {
|
|
1680
|
-
return
|
|
711
|
+
return I(e.eventName, e.data, t, n);
|
|
1681
712
|
}
|
|
1682
713
|
parse(e, t) {
|
|
1683
714
|
let n = e.data;
|
|
1684
|
-
if (e.eventName === "interaction.requested" && n
|
|
1685
|
-
let
|
|
1686
|
-
if (
|
|
715
|
+
if (n && (e.eventName === "interaction.requested" && n.family === "interaction" || e.eventName?.startsWith("mcp.authorization."))) {
|
|
716
|
+
let t = n.payload, r = String(t?.interaction_id || t?.wait_id || "");
|
|
717
|
+
if (r && n.session_id && n.run_id) return [{
|
|
1687
718
|
type: "canonical_interaction",
|
|
1688
|
-
interactionId:
|
|
719
|
+
interactionId: r,
|
|
1689
720
|
event: {
|
|
1690
|
-
EventType:
|
|
721
|
+
EventType: e.eventName,
|
|
1691
722
|
SessionId: String(n.session_id),
|
|
1692
723
|
InvocationId: String(n.run_id),
|
|
1693
724
|
SeqId: Number(n.seq || 0),
|
|
@@ -1695,7 +726,7 @@ var Qt = class {
|
|
|
1695
726
|
}
|
|
1696
727
|
}];
|
|
1697
728
|
}
|
|
1698
|
-
return
|
|
729
|
+
return N({
|
|
1699
730
|
eventName: e.eventName,
|
|
1700
731
|
data: e.data,
|
|
1701
732
|
state: t
|
|
@@ -1718,23 +749,23 @@ var Qt = class {
|
|
|
1718
749
|
};
|
|
1719
750
|
//#endregion
|
|
1720
751
|
//#region src/utils/stream-parsing.ts
|
|
1721
|
-
function
|
|
752
|
+
function vt(e) {
|
|
1722
753
|
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("") : "";
|
|
1723
754
|
}
|
|
1724
|
-
function
|
|
755
|
+
function yt(e) {
|
|
1725
756
|
return e && typeof e == "object" ? e : {};
|
|
1726
757
|
}
|
|
1727
|
-
function
|
|
1728
|
-
let t =
|
|
758
|
+
function bt(e) {
|
|
759
|
+
let t = yt(e).choices, n = yt(Array.isArray(t) ? t[0] : null), r = yt(n.delta), i = yt(n.message);
|
|
1729
760
|
return {
|
|
1730
|
-
content:
|
|
1731
|
-
reasoning:
|
|
1732
|
-
finalText:
|
|
761
|
+
content: vt(r.content),
|
|
762
|
+
reasoning: vt(r.reasoning_content),
|
|
763
|
+
finalText: vt(i.content)
|
|
1733
764
|
};
|
|
1734
765
|
}
|
|
1735
766
|
//#endregion
|
|
1736
767
|
//#region src/core/stream/chat-completions-protocol.ts
|
|
1737
|
-
var
|
|
768
|
+
var xt = class {
|
|
1738
769
|
id = "chat_completions";
|
|
1739
770
|
createState() {
|
|
1740
771
|
return {};
|
|
@@ -1742,7 +773,7 @@ var nn = class {
|
|
|
1742
773
|
parse(e) {
|
|
1743
774
|
let t = e.data;
|
|
1744
775
|
if (typeof t != "object" || !t) return [];
|
|
1745
|
-
let n =
|
|
776
|
+
let n = bt(t), r = [];
|
|
1746
777
|
return n.reasoning && r.push({
|
|
1747
778
|
type: "reasoning_delta",
|
|
1748
779
|
text: n.reasoning
|
|
@@ -1754,14 +785,14 @@ var nn = class {
|
|
|
1754
785
|
text: n.finalText
|
|
1755
786
|
}), r;
|
|
1756
787
|
}
|
|
1757
|
-
},
|
|
1758
|
-
|
|
1759
|
-
function
|
|
1760
|
-
return
|
|
788
|
+
}, St = /* @__PURE__ */ new Map();
|
|
789
|
+
St.set("responses", new _t()), St.set("chat_completions", new xt());
|
|
790
|
+
function Ct(e) {
|
|
791
|
+
return St.get(e) || St.get("responses");
|
|
1761
792
|
}
|
|
1762
793
|
//#endregion
|
|
1763
794
|
//#region src/utils/stream-control.js
|
|
1764
|
-
function
|
|
795
|
+
function wt(e = []) {
|
|
1765
796
|
return e.some((e) => {
|
|
1766
797
|
if (e?.type !== "terminal") return !1;
|
|
1767
798
|
let t = String(e.status || "").toLowerCase();
|
|
@@ -1770,7 +801,7 @@ function on(e = []) {
|
|
|
1770
801
|
}
|
|
1771
802
|
//#endregion
|
|
1772
803
|
//#region src/core/transport/sse-parser.ts
|
|
1773
|
-
function
|
|
804
|
+
function Tt(e) {
|
|
1774
805
|
let t = [], n = e.trim();
|
|
1775
806
|
if (!n) return t;
|
|
1776
807
|
let r = n.split("\n");
|
|
@@ -1800,7 +831,7 @@ function sn(e) {
|
|
|
1800
831
|
}
|
|
1801
832
|
return t;
|
|
1802
833
|
}
|
|
1803
|
-
function
|
|
834
|
+
function Et(e) {
|
|
1804
835
|
let t = e.split("\n\n");
|
|
1805
836
|
return {
|
|
1806
837
|
chunks: t,
|
|
@@ -1809,60 +840,60 @@ function cn(e) {
|
|
|
1809
840
|
}
|
|
1810
841
|
//#endregion
|
|
1811
842
|
//#region src/utils/error.ts
|
|
1812
|
-
function
|
|
843
|
+
function Dt(e) {
|
|
1813
844
|
return e instanceof Error ? e.message : String(e);
|
|
1814
845
|
}
|
|
1815
846
|
//#endregion
|
|
1816
847
|
//#region src/utils/model-options.js
|
|
1817
|
-
var
|
|
848
|
+
var Ot = new Set([
|
|
1818
849
|
"auto",
|
|
1819
850
|
"enabled",
|
|
1820
851
|
"disabled"
|
|
1821
852
|
]);
|
|
1822
|
-
function
|
|
853
|
+
function kt(e) {
|
|
1823
854
|
let t = String(e || "").trim().toLowerCase();
|
|
1824
|
-
return
|
|
855
|
+
return Ot.has(t) ? t : "auto";
|
|
1825
856
|
}
|
|
1826
|
-
function
|
|
1827
|
-
let t =
|
|
857
|
+
function At(e) {
|
|
858
|
+
let t = kt(e);
|
|
1828
859
|
if (t === "disabled") return { thinking: { type: "disabled" } };
|
|
1829
860
|
if (t === "enabled") return { thinking: { type: "enabled" } };
|
|
1830
861
|
}
|
|
1831
|
-
var
|
|
1832
|
-
function
|
|
862
|
+
var jt = 1280;
|
|
863
|
+
function Mt(e) {
|
|
1833
864
|
let { apiFormats: t } = e;
|
|
1834
865
|
return t.includes("responses") ? "responses" : t.includes("chat_completions") ? "chat_completions" : "responses";
|
|
1835
866
|
}
|
|
1836
|
-
function
|
|
1837
|
-
let r = Math.min(
|
|
867
|
+
function Nt(e, t, n) {
|
|
868
|
+
let r = Math.min(jt, Math.max(420, t - n - 360));
|
|
1838
869
|
return Math.min(Math.max(e, 420), r);
|
|
1839
870
|
}
|
|
1840
871
|
//#endregion
|
|
1841
872
|
//#region src/core/run/agui.ts
|
|
1842
|
-
function
|
|
873
|
+
function Pt(e) {
|
|
1843
874
|
return String(e.type || "").toUpperCase();
|
|
1844
875
|
}
|
|
1845
|
-
function
|
|
876
|
+
function Ft(e, t) {
|
|
1846
877
|
return String(e.messageId || t);
|
|
1847
878
|
}
|
|
1848
|
-
function
|
|
879
|
+
function It(e, t) {
|
|
1849
880
|
return String(e.runId || t);
|
|
1850
881
|
}
|
|
1851
|
-
function
|
|
882
|
+
function Lt(e) {
|
|
1852
883
|
return e && typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
1853
884
|
}
|
|
1854
|
-
function
|
|
1855
|
-
if (Array.isArray(e)) return
|
|
885
|
+
function Rt(e) {
|
|
886
|
+
if (Array.isArray(e)) return D(e.filter((e) => !!(e && typeof e == "object")));
|
|
1856
887
|
if (e && typeof e == "object") {
|
|
1857
888
|
let t = e.a2ui_operations;
|
|
1858
|
-
return Array.isArray(t) ?
|
|
889
|
+
return Array.isArray(t) ? D(t.filter((e) => !!(e && typeof e == "object"))) : [e];
|
|
1859
890
|
}
|
|
1860
891
|
return [];
|
|
1861
892
|
}
|
|
1862
|
-
function
|
|
893
|
+
function zt(e) {
|
|
1863
894
|
return e == null || e === "" ? "" : typeof e == "string" ? e : JSON.stringify(e, null, 2);
|
|
1864
895
|
}
|
|
1865
|
-
var
|
|
896
|
+
var Bt = class {
|
|
1866
897
|
agent;
|
|
1867
898
|
onEvent;
|
|
1868
899
|
tools = /* @__PURE__ */ new Map();
|
|
@@ -1875,18 +906,18 @@ var Sn = class {
|
|
|
1875
906
|
forwardedProps;
|
|
1876
907
|
catalogRegistry;
|
|
1877
908
|
constructor(e) {
|
|
1878
|
-
this.agent = new
|
|
909
|
+
this.agent = new Le({
|
|
1879
910
|
url: e.url,
|
|
1880
911
|
agentId: e.agentId,
|
|
1881
912
|
threadId: e.threadId,
|
|
1882
913
|
fetch: e.fetch
|
|
1883
|
-
}), this.onEvent = e.onEvent, this.threadId = e.threadId, this.forwardedProps = e.forwardedProps || {}, this.catalogRegistry = e.a2uiCatalogRegistry ||
|
|
914
|
+
}), this.onEvent = e.onEvent, this.threadId = e.threadId, this.forwardedProps = e.forwardedProps || {}, this.catalogRegistry = e.a2uiCatalogRegistry || j;
|
|
1884
915
|
}
|
|
1885
|
-
configure(e, t =
|
|
916
|
+
configure(e, t = j) {
|
|
1886
917
|
this.forwardedProps = e, this.catalogRegistry = t;
|
|
1887
918
|
}
|
|
1888
919
|
reconcileInteractions(e) {
|
|
1889
|
-
let t = (t) => !e.some((e) => t.metadata?.interaction_v1 === !0 && e.source === "interaction_v1" && e.sessionId === this.threadId && e.interactionId === t.id && e.runId === t.metadata.run_id && e.revision >= Number(t.metadata.revision || 1) &&
|
|
920
|
+
let t = (t) => !e.some((e) => t.metadata?.interaction_v1 === !0 && e.source === "interaction_v1" && e.sessionId === this.threadId && e.interactionId === t.id && e.runId === t.metadata.run_id && e.revision >= Number(t.metadata.revision || 1) && o(e.status));
|
|
1890
921
|
this.agent.pendingInterrupts = this.agent.pendingInterrupts.filter(t);
|
|
1891
922
|
for (let [e, n] of this.pendingByRun) {
|
|
1892
923
|
let r = n.filter(t);
|
|
@@ -1908,7 +939,7 @@ var Sn = class {
|
|
|
1908
939
|
let n = this.agent.pendingInterrupts.length > 0 ? this.agent.pendingInterrupts : this.pendingByRun.get(this.activeRunId) || [], r = n.length > 0 ? n.filter((e) => e.id === t.interruptId) : [{
|
|
1909
940
|
id: t.interruptId,
|
|
1910
941
|
reason: "approval"
|
|
1911
|
-
}], i =
|
|
942
|
+
}], i = Re(r, { [t.interruptId]: t.status === "resolved" ? {
|
|
1912
943
|
status: "resolved",
|
|
1913
944
|
payload: t.payload
|
|
1914
945
|
} : { status: "cancelled" } });
|
|
@@ -1931,22 +962,22 @@ var Sn = class {
|
|
|
1931
962
|
let t = ++this.executionEpoch, n = this.logicalRunId || e.runId, r = !0, i = /* @__PURE__ */ new Set(), a = (n) => {
|
|
1932
963
|
if (!r || t !== this.executionEpoch || this.activeRunId !== e.runId || e.abortController?.signal.aborted) return null;
|
|
1933
964
|
let a = n;
|
|
1934
|
-
if (
|
|
1935
|
-
let o =
|
|
965
|
+
if (Pt(n) !== "CUSTOM" || a.name !== "ksadk.text_message_snapshot") return null;
|
|
966
|
+
let o = Lt(a.value);
|
|
1936
967
|
return o.version === 1 && o.threadId === this.threadId && o.runId === e.runId && typeof o.messageId == "string" && i.has(o.messageId) && typeof o.content == "string" ? {
|
|
1937
968
|
messageId: o.messageId,
|
|
1938
969
|
content: o.content
|
|
1939
970
|
} : null;
|
|
1940
971
|
}, o = "completed", s = !1, c = {
|
|
1941
972
|
onEvent: ({ event: t, messages: r }) => {
|
|
1942
|
-
|
|
973
|
+
Pt(t) === "TEXT_MESSAGE_START" && i.add(Ft(t, `${e.runId}:assistant`));
|
|
1943
974
|
let c = a(t);
|
|
1944
975
|
if (c && r.some((e) => e.id === c.messageId && e.role === "assistant") && this.onEvent({
|
|
1945
976
|
type: "text_replace",
|
|
1946
977
|
messageId: c.messageId,
|
|
1947
978
|
text: c.content,
|
|
1948
979
|
sessionId: this.threadId
|
|
1949
|
-
}),
|
|
980
|
+
}), Pt(t) === "RUN_FINISHED" && (s = !0), Pt(t) === "RUN_ERROR" && t.code === "INPUT_RESPONSE_INVALID") for (let t of e.resume || []) this.onEvent({
|
|
1950
981
|
type: "interaction_submit_rejected",
|
|
1951
982
|
interactionId: t.interruptId,
|
|
1952
983
|
message: "答案未通过 Runtime 校验,请修改后重新提交。"
|
|
@@ -1971,7 +1002,7 @@ var Sn = class {
|
|
|
1971
1002
|
try {
|
|
1972
1003
|
l = await this.agent.runAgent({
|
|
1973
1004
|
runId: e.runId,
|
|
1974
|
-
context: [
|
|
1005
|
+
context: [k(this.catalogRegistry)],
|
|
1975
1006
|
forwardedProps: {
|
|
1976
1007
|
...this.forwardedProps,
|
|
1977
1008
|
injectA2UITool: !0
|
|
@@ -1990,7 +1021,7 @@ var Sn = class {
|
|
|
1990
1021
|
};
|
|
1991
1022
|
}
|
|
1992
1023
|
project(e, t, n = !1, r = t) {
|
|
1993
|
-
let i =
|
|
1024
|
+
let i = Pt(e), a = It(e, t), o = Ft(e, `${a}:assistant`), s = e, c = [];
|
|
1994
1025
|
if (i === "RUN_STARTED") c.push({
|
|
1995
1026
|
type: "activity",
|
|
1996
1027
|
phase: "AG-UI 运行已创建",
|
|
@@ -2053,8 +1084,8 @@ var Sn = class {
|
|
|
2053
1084
|
output: String(s.content || "")
|
|
2054
1085
|
});
|
|
2055
1086
|
} else if (i === "CUSTOM" && s.name === "ksadk.session_event") {
|
|
2056
|
-
let e =
|
|
2057
|
-
e.family === "interaction" && e.family_version === 1 && e.session_id === this.threadId && typeof e.event_type == "string" && Number.isSafeInteger(e.seq) && c.push({
|
|
1087
|
+
let e = Lt(s.value), t = e.family === "control" && ["mcp.authorization.requested", "mcp.authorization.updated"].includes(String(e.event_type));
|
|
1088
|
+
(e.family === "interaction" || t) && e.family_version === 1 && e.session_id === this.threadId && typeof e.event_type == "string" && Number.isSafeInteger(e.seq) && c.push({
|
|
2058
1089
|
type: "stream_event",
|
|
2059
1090
|
sessionId: e.session_id,
|
|
2060
1091
|
event: {
|
|
@@ -2067,7 +1098,7 @@ var Sn = class {
|
|
|
2067
1098
|
}
|
|
2068
1099
|
});
|
|
2069
1100
|
} else if (i === "ACTIVITY_SNAPSHOT") {
|
|
2070
|
-
let e = s.content, t =
|
|
1101
|
+
let e = s.content, t = Lt(e), n = String(t.surfaceId || t.surface_id || s.messageId || "default");
|
|
2071
1102
|
c.push({
|
|
2072
1103
|
type: "agui_activity",
|
|
2073
1104
|
runId: r,
|
|
@@ -2075,17 +1106,17 @@ var Sn = class {
|
|
|
2075
1106
|
...typeof t.interactionId == "string" ? { interactionId: t.interactionId } : {},
|
|
2076
1107
|
messageId: this.runMessageIds.get(a) || o,
|
|
2077
1108
|
surfaceId: n,
|
|
2078
|
-
messages:
|
|
1109
|
+
messages: Rt(t.content ?? e)
|
|
2079
1110
|
});
|
|
2080
1111
|
} else if (i === "RUN_FINISHED") {
|
|
2081
|
-
let e =
|
|
1112
|
+
let e = Lt(s.outcome);
|
|
2082
1113
|
if (String(e.type || "").toLowerCase() === "interrupt") {
|
|
2083
1114
|
let t = Array.isArray(e.interrupts) ? e.interrupts : [];
|
|
2084
1115
|
this.pendingByRun.set(a, t);
|
|
2085
1116
|
for (let e of t) {
|
|
2086
|
-
let t =
|
|
1117
|
+
let t = Lt(e.metadata);
|
|
2087
1118
|
if (t.interaction_v1 === !0) continue;
|
|
2088
|
-
let n = e.toolCallId ? this.tools.get(e.toolCallId) : void 0, r = String(t.tool_name || t.toolName || n?.name || e.reason || "人工确认"), i =
|
|
1119
|
+
let n = e.toolCallId ? this.tools.get(e.toolCallId) : void 0, r = String(t.tool_name || t.toolName || n?.name || e.reason || "人工确认"), i = zt(t.arguments ?? t.tool_args ?? t.args ?? n?.args);
|
|
2089
1120
|
c.push({
|
|
2090
1121
|
type: "approval_requested",
|
|
2091
1122
|
messageId: this.runMessageIds.get(a) || `${a}:assistant`,
|
|
@@ -2120,7 +1151,7 @@ var Sn = class {
|
|
|
2120
1151
|
};
|
|
2121
1152
|
return { events: c };
|
|
2122
1153
|
}
|
|
2123
|
-
},
|
|
1154
|
+
}, Vt = new Set([
|
|
2124
1155
|
"completed",
|
|
2125
1156
|
"failed",
|
|
2126
1157
|
"error",
|
|
@@ -2130,12 +1161,12 @@ var Sn = class {
|
|
|
2130
1161
|
"interrupted",
|
|
2131
1162
|
"resume_failed"
|
|
2132
1163
|
]);
|
|
2133
|
-
function
|
|
1164
|
+
function Ht(e) {
|
|
2134
1165
|
if (e.EventType !== "run_status") return null;
|
|
2135
1166
|
let t = String(e.Content?.status || "").trim().toLowerCase();
|
|
2136
|
-
return
|
|
1167
|
+
return Vt.has(t) ? t : null;
|
|
2137
1168
|
}
|
|
2138
|
-
function
|
|
1169
|
+
function Ut(e, t) {
|
|
2139
1170
|
let n = String(t?.type || e || "").trim();
|
|
2140
1171
|
if (n === "response.created") return {
|
|
2141
1172
|
phase: "运行已创建",
|
|
@@ -2181,11 +1212,11 @@ function Tn(e, t) {
|
|
|
2181
1212
|
status: "failed"
|
|
2182
1213
|
} : null;
|
|
2183
1214
|
}
|
|
2184
|
-
function
|
|
1215
|
+
function Wt() {
|
|
2185
1216
|
let e = globalThis.crypto;
|
|
2186
1217
|
return e && typeof e.randomUUID == "function" ? `run_${e.randomUUID()}` : `run_${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
2187
1218
|
}
|
|
2188
|
-
var
|
|
1219
|
+
var Gt = {
|
|
2189
1220
|
idle: [
|
|
2190
1221
|
"creating-session",
|
|
2191
1222
|
"uploading-files",
|
|
@@ -2223,7 +1254,7 @@ var Dn = {
|
|
|
2223
1254
|
],
|
|
2224
1255
|
error: ["connecting", "idle"],
|
|
2225
1256
|
cancelled: ["idle"]
|
|
2226
|
-
},
|
|
1257
|
+
}, Kt = class {
|
|
2227
1258
|
_stage = "idle";
|
|
2228
1259
|
listeners = /* @__PURE__ */ new Set();
|
|
2229
1260
|
abortController = null;
|
|
@@ -2256,18 +1287,18 @@ var Dn = {
|
|
|
2256
1287
|
return this.activeSessionId || this.projection.draftId || null;
|
|
2257
1288
|
}
|
|
2258
1289
|
publishInvocation(e) {
|
|
2259
|
-
this.invocationId = e, e &&
|
|
1290
|
+
this.invocationId = e, e && r.getState().updateActivity({
|
|
2260
1291
|
sessionId: this.streamingKey,
|
|
2261
1292
|
runId: e,
|
|
2262
1293
|
countEvent: !1,
|
|
2263
1294
|
visible: this.projection.isVisible?.()
|
|
2264
|
-
}), this.projection.isVisible?.() !== !1 && (
|
|
1295
|
+
}), this.projection.isVisible?.() !== !1 && (r.getState().setCurrentRunId(e), r.getState().setActiveInvocationId(e));
|
|
2265
1296
|
}
|
|
2266
1297
|
recordCursor(e) {
|
|
2267
|
-
this.lastSeqId = e === 0 ? 0 : Math.max(this.lastSeqId, e), this.projection.isVisible?.() !== !1 &&
|
|
1298
|
+
this.lastSeqId = e === 0 ? 0 : Math.max(this.lastSeqId, e), this.projection.isVisible?.() !== !1 && r.getState().setLastSeqId(this.lastSeqId);
|
|
2268
1299
|
}
|
|
2269
1300
|
stopActivity(e) {
|
|
2270
|
-
let t =
|
|
1301
|
+
let t = r.getState(), n = this.projection.isVisible?.() !== !1;
|
|
2271
1302
|
this.streamingKey ? t.stopSessionActivity(this.streamingKey, e, n) : n && t.stopActivity(e);
|
|
2272
1303
|
}
|
|
2273
1304
|
get stage() {
|
|
@@ -2280,9 +1311,9 @@ var Dn = {
|
|
|
2280
1311
|
this.lastControlCommand = e;
|
|
2281
1312
|
let t;
|
|
2282
1313
|
try {
|
|
2283
|
-
t =
|
|
1314
|
+
t = c(await this.api.submitControl(e));
|
|
2284
1315
|
} catch (e) {
|
|
2285
|
-
if (e instanceof
|
|
1316
|
+
if (e instanceof u) return this.controlStateValue = {
|
|
2286
1317
|
phase: "contract_mismatch",
|
|
2287
1318
|
error: null,
|
|
2288
1319
|
receipt: null
|
|
@@ -2372,7 +1403,7 @@ var Dn = {
|
|
|
2372
1403
|
let t = this.config.hostedChatTransport;
|
|
2373
1404
|
if (t?.Protocol !== "ag-ui" || !t.Endpoint) return null;
|
|
2374
1405
|
if (!this.aguiClient || this.aguiThreadSessionId !== e) {
|
|
2375
|
-
let n = new
|
|
1406
|
+
let n = new Bt({
|
|
2376
1407
|
url: t.Endpoint,
|
|
2377
1408
|
agentId: this.config.agentId,
|
|
2378
1409
|
threadId: e,
|
|
@@ -2382,16 +1413,16 @@ var Dn = {
|
|
|
2382
1413
|
});
|
|
2383
1414
|
this.aguiClient = n, this.aguiThreadSessionId = e;
|
|
2384
1415
|
}
|
|
2385
|
-
return this.aguiClient.reconcileInteractions(
|
|
1416
|
+
return this.aguiClient.reconcileInteractions(T.listAll(e)), this.aguiClient.configure({
|
|
2386
1417
|
model: this.config.selectedModel || void 0,
|
|
2387
1418
|
modelMetadata: this.config.selectedModelMetadata || void 0,
|
|
2388
|
-
modelOptions:
|
|
1419
|
+
modelOptions: At(kt(this.config.thinkingMode)),
|
|
2389
1420
|
toolApprovalMode: this.config.permissionMode || "risk"
|
|
2390
1421
|
}, this.config.a2uiCatalogRegistry), this.aguiClient;
|
|
2391
1422
|
}
|
|
2392
1423
|
setStage(e) {
|
|
2393
1424
|
if (this._stage === e) return;
|
|
2394
|
-
let t =
|
|
1425
|
+
let t = Gt[this._stage];
|
|
2395
1426
|
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({
|
|
2396
1427
|
type: "stage_changed",
|
|
2397
1428
|
stage: e
|
|
@@ -2412,19 +1443,19 @@ var Dn = {
|
|
|
2412
1443
|
phase: this.activeSessionId ? "连接运行时" : "创建会话",
|
|
2413
1444
|
countEvent: !1
|
|
2414
1445
|
});
|
|
2415
|
-
let n = e.responsesInput !== void 0,
|
|
2416
|
-
|
|
1446
|
+
let n = e.responsesInput !== void 0, i = !1, a = (t) => {
|
|
1447
|
+
i || (i = !0, e.onDispatchResult?.(t));
|
|
2417
1448
|
};
|
|
2418
1449
|
return (async () => {
|
|
2419
|
-
let
|
|
1450
|
+
let i = e.sessionId || null, o = "unknown";
|
|
2420
1451
|
try {
|
|
2421
|
-
if (
|
|
2422
|
-
this.activeSessionId =
|
|
2423
|
-
let
|
|
2424
|
-
this.publishInvocation(
|
|
2425
|
-
let s = n ? null : await this.getConversationBootstrap(
|
|
1452
|
+
if (i ||= await this.createSession(e), !i) throw Error("运行时未返回会话身份,请确认创建结果后重试。");
|
|
1453
|
+
this.activeSessionId = i;
|
|
1454
|
+
let r = Wt();
|
|
1455
|
+
this.publishInvocation(r), e.onInvocationCreated?.(r), this.recordCursor(0);
|
|
1456
|
+
let s = n ? null : await this.getConversationBootstrap(i);
|
|
2426
1457
|
if (s && this.config.conversationClient) {
|
|
2427
|
-
let n = await this.buildCanonicalConversationInput(s,
|
|
1458
|
+
let n = await this.buildCanonicalConversationInput(s, i, r, e);
|
|
2428
1459
|
this.setStage("connecting"), this.emit({
|
|
2429
1460
|
type: "activity",
|
|
2430
1461
|
phase: "连接会话运行时",
|
|
@@ -2436,7 +1467,7 @@ var Dn = {
|
|
|
2436
1467
|
status: "waiting",
|
|
2437
1468
|
countEvent: !1
|
|
2438
1469
|
});
|
|
2439
|
-
let
|
|
1470
|
+
let a = await this.config.conversationClient.streamTurn({
|
|
2440
1471
|
bootstrap: s,
|
|
2441
1472
|
input: n,
|
|
2442
1473
|
signal: this.abortController?.signal,
|
|
@@ -2444,14 +1475,14 @@ var Dn = {
|
|
|
2444
1475
|
t.runId && (this.publishInvocation(t.runId), e.onInvocationCreated?.(t.runId)), this.emit({
|
|
2445
1476
|
type: "conversation_snapshot",
|
|
2446
1477
|
result: t,
|
|
2447
|
-
sessionId:
|
|
1478
|
+
sessionId: i,
|
|
2448
1479
|
optimisticMessageId: e.optimisticMessageId
|
|
2449
1480
|
});
|
|
2450
1481
|
}
|
|
2451
1482
|
});
|
|
2452
1483
|
if (this.operationEpoch !== t) return;
|
|
2453
|
-
if (
|
|
2454
|
-
|
|
1484
|
+
if (a.presentation.terminalStatus === "failed") {
|
|
1485
|
+
o = "failed", this.setStage("error"), this.emit({
|
|
2455
1486
|
type: "activity",
|
|
2456
1487
|
phase: "运行失败",
|
|
2457
1488
|
status: "failed",
|
|
@@ -2459,15 +1490,15 @@ var Dn = {
|
|
|
2459
1490
|
});
|
|
2460
1491
|
return;
|
|
2461
1492
|
}
|
|
2462
|
-
this.setStage("completing"),
|
|
1493
|
+
this.setStage("completing"), o = "completed", this.emit({
|
|
2463
1494
|
type: "activity",
|
|
2464
1495
|
phase: "运行完成",
|
|
2465
1496
|
status: "completed",
|
|
2466
1497
|
countEvent: !1
|
|
2467
1498
|
}), this.emit({
|
|
2468
1499
|
type: "stream_ended",
|
|
2469
|
-
sessionId:
|
|
2470
|
-
runId:
|
|
1500
|
+
sessionId: i,
|
|
1501
|
+
runId: a.runId
|
|
2471
1502
|
});
|
|
2472
1503
|
return;
|
|
2473
1504
|
}
|
|
@@ -2478,10 +1509,10 @@ var Dn = {
|
|
|
2478
1509
|
status: "connecting",
|
|
2479
1510
|
countEvent: !1
|
|
2480
1511
|
});
|
|
2481
|
-
let l = n ? "responses" :
|
|
1512
|
+
let l = n ? "responses" : Mt({
|
|
2482
1513
|
agentFramework: this.config.agentFramework,
|
|
2483
1514
|
apiFormats: this.config.apiFormats
|
|
2484
|
-
}), u =
|
|
1515
|
+
}), u = Ct(l), d = u.createState(), f = this.config.hostedChatTransport, p = !n && !e.executionMode && e.attachments.length === 0 && f?.Protocol === "ag-ui" ? this.getAguiClient(i) : null;
|
|
2485
1516
|
if (p && f) {
|
|
2486
1517
|
this.setStage("streaming"), this.emit({
|
|
2487
1518
|
type: "activity",
|
|
@@ -2489,13 +1520,13 @@ var Dn = {
|
|
|
2489
1520
|
status: "waiting",
|
|
2490
1521
|
countEvent: !1
|
|
2491
1522
|
});
|
|
2492
|
-
let t = await p.run(e.text,
|
|
1523
|
+
let t = await p.run(e.text, r, this.abortController?.signal);
|
|
2493
1524
|
if (t.status === "interrupted") {
|
|
2494
|
-
|
|
1525
|
+
o = "cancelled", this.setStage("completing"), this.emit({ type: "stream_ended" });
|
|
2495
1526
|
return;
|
|
2496
1527
|
}
|
|
2497
1528
|
if (t.status !== "completed") {
|
|
2498
|
-
|
|
1529
|
+
o = "failed", this.setStage("error"), this.emit({
|
|
2499
1530
|
type: "activity",
|
|
2500
1531
|
phase: "AG-UI 运行失败",
|
|
2501
1532
|
status: "failed",
|
|
@@ -2503,7 +1534,7 @@ var Dn = {
|
|
|
2503
1534
|
});
|
|
2504
1535
|
return;
|
|
2505
1536
|
}
|
|
2506
|
-
this.setStage("completing"),
|
|
1537
|
+
this.setStage("completing"), o = "completed", this.emit({
|
|
2507
1538
|
type: "activity",
|
|
2508
1539
|
phase: "运行完成",
|
|
2509
1540
|
status: "completed",
|
|
@@ -2511,27 +1542,27 @@ var Dn = {
|
|
|
2511
1542
|
}), this.emit({ type: "stream_ended" });
|
|
2512
1543
|
return;
|
|
2513
1544
|
}
|
|
2514
|
-
let m = this.buildRequestBody(
|
|
1545
|
+
let m = this.buildRequestBody(i, l, n, e, c, r), h = this.config.kernelSessionEventsEnabled && this.config.presentationProfile === "agent-block-v1" ? "agent-block-v1" : "flat-v1", g = await this.api.runAgent(m, { signal: this.abortController?.signal });
|
|
2515
1546
|
if (this.operationEpoch !== t || this.abortController?.signal.aborted) {
|
|
2516
|
-
|
|
1547
|
+
a(!1), await g.cancel();
|
|
2517
1548
|
return;
|
|
2518
1549
|
}
|
|
2519
|
-
this.config.kernelSessionEventsEnabled ||
|
|
1550
|
+
this.config.kernelSessionEventsEnabled || a(!0), this.setStage("streaming"), this.emit({
|
|
2520
1551
|
type: "activity",
|
|
2521
1552
|
phase: "等待首个输出",
|
|
2522
1553
|
status: "waiting",
|
|
2523
1554
|
countEvent: !1
|
|
2524
1555
|
});
|
|
2525
|
-
let _ = `msg-${Date.now()}`, v = await
|
|
1556
|
+
let _ = `msg-${Date.now()}`, v = await Ce(g);
|
|
2526
1557
|
if (this.operationEpoch !== t || this.abortController?.signal.aborted) {
|
|
2527
|
-
|
|
1558
|
+
a(!1), await v.stream.cancel();
|
|
2528
1559
|
return;
|
|
2529
1560
|
}
|
|
2530
|
-
this.config.kernelSessionEventsEnabled &&
|
|
1561
|
+
this.config.kernelSessionEventsEnabled && a(!v.receipt || v.receipt.status === "accepted" || v.receipt.status === "duplicate");
|
|
2531
1562
|
let y;
|
|
2532
|
-
if (y = v.receipt ? await this.consumeKernelRunEvents(
|
|
1563
|
+
if (y = v.receipt ? await this.consumeKernelRunEvents(i, v.receipt, e.onInvocationCreated, h) : await this.consumeStream(v.stream, u, d, _, r), this.operationEpoch !== t) return;
|
|
2533
1564
|
if (y.awaitingInput) {
|
|
2534
|
-
|
|
1565
|
+
o = "awaiting-input", this.setStage("completing"), this.emit({
|
|
2535
1566
|
type: "activity",
|
|
2536
1567
|
phase: "等待人工确认",
|
|
2537
1568
|
status: "waiting",
|
|
@@ -2540,7 +1571,7 @@ var Dn = {
|
|
|
2540
1571
|
return;
|
|
2541
1572
|
}
|
|
2542
1573
|
if (y.outcomeUnknown) {
|
|
2543
|
-
|
|
1574
|
+
o = "unknown", this.setStage("recovering"), this.emit({
|
|
2544
1575
|
type: "activity",
|
|
2545
1576
|
phase: "运行状态待确认",
|
|
2546
1577
|
status: "waiting",
|
|
@@ -2550,7 +1581,7 @@ var Dn = {
|
|
|
2550
1581
|
return;
|
|
2551
1582
|
}
|
|
2552
1583
|
if (y.terminalStatus === "cancelled") {
|
|
2553
|
-
|
|
1584
|
+
o = "cancelled", this.setStage("stopping"), this.stopActivity("运行时已取消本次执行。"), this.emit({
|
|
2554
1585
|
type: "activity",
|
|
2555
1586
|
phase: "运行已取消",
|
|
2556
1587
|
status: "stopped",
|
|
@@ -2559,7 +1590,7 @@ var Dn = {
|
|
|
2559
1590
|
return;
|
|
2560
1591
|
}
|
|
2561
1592
|
if (y.terminalStatus && y.terminalStatus !== "completed") {
|
|
2562
|
-
|
|
1593
|
+
o = "failed", this.setStage("error"), this.emit({
|
|
2563
1594
|
type: "activity",
|
|
2564
1595
|
phase: y.terminalStatus === "incomplete" ? "运行中断" : "运行失败",
|
|
2565
1596
|
status: "failed",
|
|
@@ -2567,17 +1598,17 @@ var Dn = {
|
|
|
2567
1598
|
});
|
|
2568
1599
|
return;
|
|
2569
1600
|
}
|
|
2570
|
-
this.setStage("completing"),
|
|
1601
|
+
this.setStage("completing"), o = "completed", this.emit({
|
|
2571
1602
|
type: "activity",
|
|
2572
1603
|
phase: "运行完成",
|
|
2573
1604
|
status: "completed",
|
|
2574
1605
|
countEvent: !1
|
|
2575
1606
|
}), this.emit({ type: "stream_ended" });
|
|
2576
1607
|
} catch (e) {
|
|
2577
|
-
if (this.failCompaction(), e instanceof DOMException && e.name === "AbortError" || e instanceof
|
|
1608
|
+
if (this.failCompaction(), e instanceof DOMException && e.name === "AbortError" || e instanceof G && e.code === "conversation_aborted") o = "cancelled";
|
|
2578
1609
|
else {
|
|
2579
1610
|
let t = e instanceof TypeError;
|
|
2580
|
-
if (
|
|
1611
|
+
if (o = t ? "unknown" : "failed", console.error("[RunEngine] start() error:", e), t) {
|
|
2581
1612
|
this.setStage("recovering"), this.emit({
|
|
2582
1613
|
type: "activity",
|
|
2583
1614
|
phase: "网络异常,尝试重连",
|
|
@@ -2599,17 +1630,17 @@ var Dn = {
|
|
|
2599
1630
|
type: "error",
|
|
2600
1631
|
error: e instanceof Error ? e : Error(String(e))
|
|
2601
1632
|
});
|
|
2602
|
-
} else e instanceof
|
|
1633
|
+
} else e instanceof Y && e.code === 429 ? (this.setStage("error"), this.emit({
|
|
2603
1634
|
type: "rate_limited",
|
|
2604
1635
|
message: e.message || "请求过于频繁,请稍后重试",
|
|
2605
|
-
sessionId:
|
|
1636
|
+
sessionId: i
|
|
2606
1637
|
})) : (this.setStage("error"), this.emit({
|
|
2607
1638
|
type: "error",
|
|
2608
1639
|
error: e instanceof Error ? e : Error(String(e))
|
|
2609
1640
|
}));
|
|
2610
1641
|
}
|
|
2611
1642
|
} finally {
|
|
2612
|
-
|
|
1643
|
+
a(!1), this.operationEpoch === t && (r.getState().setSessionStreaming(this.streamingKey, !1), this.setStage("idle"), this.activeCompactionId = null, this.activeSessionId = null, e.onSettled?.(i, o));
|
|
2613
1644
|
}
|
|
2614
1645
|
})(), !0;
|
|
2615
1646
|
}
|
|
@@ -2625,7 +1656,7 @@ var Dn = {
|
|
|
2625
1656
|
});
|
|
2626
1657
|
}
|
|
2627
1658
|
disconnect() {
|
|
2628
|
-
this._stage !== "idle" && (this.operationEpoch += 1, this.abortController?.abort(), this.aguiClient?.abort(),
|
|
1659
|
+
this._stage !== "idle" && (this.operationEpoch += 1, this.abortController?.abort(), this.aguiClient?.abort(), r.getState().setSessionStreaming(this.streamingKey, !1), this.projection.isVisible?.() !== !1 && r.getState().clearActivity(), this._stage = "idle", this.activeCompactionId = null, this.activeSessionId = null);
|
|
2629
1660
|
}
|
|
2630
1661
|
async cancelRemote(e) {
|
|
2631
1662
|
try {
|
|
@@ -2660,11 +1691,11 @@ var Dn = {
|
|
|
2660
1691
|
let { value: e, done: n } = await r.read();
|
|
2661
1692
|
if (n) break;
|
|
2662
1693
|
a += i.decode(e, { stream: !0 });
|
|
2663
|
-
let { chunks: o, remainder: s } =
|
|
1694
|
+
let { chunks: o, remainder: s } = Et(a);
|
|
2664
1695
|
a = s;
|
|
2665
1696
|
for (let e of o) {
|
|
2666
1697
|
if (!e.trim()) continue;
|
|
2667
|
-
let n =
|
|
1698
|
+
let n = Tt(e);
|
|
2668
1699
|
for (let e of n) e.eventName === "__done__" || e.eventName === "__ping__" || (this.emit({
|
|
2669
1700
|
type: "activity",
|
|
2670
1701
|
phase: "收到恢复事件",
|
|
@@ -2672,7 +1703,7 @@ var Dn = {
|
|
|
2672
1703
|
}), this.emit({
|
|
2673
1704
|
type: "stream_event",
|
|
2674
1705
|
event: e.data
|
|
2675
|
-
}), t =
|
|
1706
|
+
}), t = Ht(e.data) || t);
|
|
2676
1707
|
}
|
|
2677
1708
|
}
|
|
2678
1709
|
this.setStage("completing"), t === "cancelled" || t === "canceled" || t === "aborted" ? this.emit({
|
|
@@ -2710,16 +1741,16 @@ var Dn = {
|
|
|
2710
1741
|
} catch (e) {
|
|
2711
1742
|
e instanceof DOMException && e.name === "AbortError" || console.error("Failed to subscribe to run events:", e);
|
|
2712
1743
|
} finally {
|
|
2713
|
-
|
|
1744
|
+
r.getState().setSessionStreaming(e.sessionId, !1), this.publishInvocation(""), this.setStage("idle"), this.activeSessionId = null;
|
|
2714
1745
|
}
|
|
2715
1746
|
}
|
|
2716
1747
|
resumeCheckpoint(e) {
|
|
2717
1748
|
if (this._stage !== "idle") return !1;
|
|
2718
1749
|
let t = ++this.operationEpoch;
|
|
2719
1750
|
this.abortController = new AbortController(), this.activeSessionId = e.sessionId;
|
|
2720
|
-
let n =
|
|
1751
|
+
let n = Wt();
|
|
2721
1752
|
return this.publishInvocation(n), (async () => {
|
|
2722
|
-
let
|
|
1753
|
+
let i = "unknown";
|
|
2723
1754
|
try {
|
|
2724
1755
|
if (this.setStage("connecting"), this.emit({
|
|
2725
1756
|
type: "activity",
|
|
@@ -2751,7 +1782,7 @@ var Dn = {
|
|
|
2751
1782
|
checkpointId: e.checkpointId,
|
|
2752
1783
|
resumeAttemptId: e.resumeAttemptId,
|
|
2753
1784
|
invocationId: n
|
|
2754
|
-
}, { signal: this.abortController?.signal }),
|
|
1785
|
+
}, { signal: this.abortController?.signal }), r = Ct("responses"), a = r.createState();
|
|
2755
1786
|
this.setStage("streaming"), this.emit({
|
|
2756
1787
|
type: "activity",
|
|
2757
1788
|
source: "restore",
|
|
@@ -2759,9 +1790,9 @@ var Dn = {
|
|
|
2759
1790
|
status: "waiting",
|
|
2760
1791
|
countEvent: !1
|
|
2761
1792
|
});
|
|
2762
|
-
let o = `msg-${Date.now()}`, s = await this.consumeStream(t,
|
|
1793
|
+
let o = `msg-${Date.now()}`, s = await this.consumeStream(t, r, a, o, n);
|
|
2763
1794
|
if (s.awaitingInput) {
|
|
2764
|
-
|
|
1795
|
+
i = "awaiting-input", this.setStage("completing"), this.emit({
|
|
2765
1796
|
type: "activity",
|
|
2766
1797
|
source: "restore",
|
|
2767
1798
|
phase: "等待人工确认",
|
|
@@ -2772,7 +1803,7 @@ var Dn = {
|
|
|
2772
1803
|
}
|
|
2773
1804
|
if (s.terminalStatus && s.terminalStatus !== "completed") {
|
|
2774
1805
|
if (s.terminalStatus === "cancelled") {
|
|
2775
|
-
|
|
1806
|
+
i = "cancelled", this.setStage("stopping"), this.stopActivity("运行时已取消本次恢复。"), this.emit({
|
|
2776
1807
|
type: "activity",
|
|
2777
1808
|
source: "restore",
|
|
2778
1809
|
phase: "恢复已取消",
|
|
@@ -2781,7 +1812,7 @@ var Dn = {
|
|
|
2781
1812
|
}), this.setStage("cancelled");
|
|
2782
1813
|
return;
|
|
2783
1814
|
}
|
|
2784
|
-
this.setStage("error"),
|
|
1815
|
+
this.setStage("error"), i = "failed", this.emit({
|
|
2785
1816
|
type: "activity",
|
|
2786
1817
|
source: "restore",
|
|
2787
1818
|
phase: s.terminalStatus === "incomplete" ? "恢复中断" : "恢复失败",
|
|
@@ -2790,7 +1821,7 @@ var Dn = {
|
|
|
2790
1821
|
});
|
|
2791
1822
|
return;
|
|
2792
1823
|
}
|
|
2793
|
-
this.setStage("completing"),
|
|
1824
|
+
this.setStage("completing"), i = "completed", this.emit({
|
|
2794
1825
|
type: "activity",
|
|
2795
1826
|
source: "restore",
|
|
2796
1827
|
phase: "恢复完成",
|
|
@@ -2798,12 +1829,12 @@ var Dn = {
|
|
|
2798
1829
|
countEvent: !1
|
|
2799
1830
|
}), this.emit({ type: "stream_ended" });
|
|
2800
1831
|
} catch (e) {
|
|
2801
|
-
e instanceof DOMException && e.name === "AbortError" ?
|
|
1832
|
+
e instanceof DOMException && e.name === "AbortError" ? i = "cancelled" : (i = "failed", console.error("[RunEngine] resumeCheckpoint() error:", e), this.setStage("error"), this.emit({
|
|
2802
1833
|
type: "error",
|
|
2803
1834
|
error: e instanceof Error ? e : Error(String(e))
|
|
2804
1835
|
}));
|
|
2805
1836
|
} finally {
|
|
2806
|
-
this.operationEpoch === t && (
|
|
1837
|
+
this.operationEpoch === t && (r.getState().setSessionStreaming(e.sessionId, !1), this.publishInvocation(""), this.setStage("idle"), this.activeSessionId = null, e.onSettled?.(e.sessionId, i));
|
|
2807
1838
|
}
|
|
2808
1839
|
})(), !0;
|
|
2809
1840
|
}
|
|
@@ -2815,7 +1846,7 @@ var Dn = {
|
|
|
2815
1846
|
if (!n) return !1;
|
|
2816
1847
|
let r = ++this.operationEpoch;
|
|
2817
1848
|
this.activeSessionId = t;
|
|
2818
|
-
let i =
|
|
1849
|
+
let i = Wt();
|
|
2819
1850
|
return this.publishInvocation(i), this.setStage("connecting"), this.emit({
|
|
2820
1851
|
type: "activity",
|
|
2821
1852
|
phase: "提交人工确认",
|
|
@@ -2827,7 +1858,7 @@ var Dn = {
|
|
|
2827
1858
|
this.setStage("streaming");
|
|
2828
1859
|
let r = await n.resume(i, {
|
|
2829
1860
|
interruptId: e.interruptId,
|
|
2830
|
-
logicalRunId:
|
|
1861
|
+
logicalRunId: T.get(t, e.interruptId)?.runId || void 0,
|
|
2831
1862
|
status: e.status,
|
|
2832
1863
|
payload: e.payload
|
|
2833
1864
|
}), o = e.payload && typeof e.payload == "object" ? e.payload : {}, s = String(o.decision || o.type || "").toLowerCase(), c = r.pendingInterruptIds?.includes(e.interruptId);
|
|
@@ -2884,7 +1915,7 @@ var Dn = {
|
|
|
2884
1915
|
try {
|
|
2885
1916
|
return await t.getSurface(this.config.agentId, e, { signal: this.abortController?.signal });
|
|
2886
1917
|
} catch (e) {
|
|
2887
|
-
if (e instanceof
|
|
1918
|
+
if (e instanceof G && e.code === "conversation_http_error" && e.status === 404) return null;
|
|
2888
1919
|
throw e;
|
|
2889
1920
|
}
|
|
2890
1921
|
}
|
|
@@ -2896,39 +1927,39 @@ var Dn = {
|
|
|
2896
1927
|
});
|
|
2897
1928
|
for (let t of r.attachments) {
|
|
2898
1929
|
let n = t.type.startsWith("image/") ? "attachment.image" : "attachment.file";
|
|
2899
|
-
if (!
|
|
1930
|
+
if (!de(e.surface, n)) throw new G("conversation_input_unsupported", "Conversation attachment is not declared by the active surface.", { capability: n });
|
|
2900
1931
|
}
|
|
2901
1932
|
r.attachments.length > 0 && i.push(...await this.uploadCanonicalAttachments(r.attachments));
|
|
2902
|
-
let o =
|
|
1933
|
+
let o = kt(this.config.thinkingMode), s = fe({
|
|
2903
1934
|
inputId: `input:${n}`,
|
|
2904
1935
|
sessionId: t,
|
|
2905
1936
|
idempotencyKey: `conversation:${n}`,
|
|
2906
1937
|
parts: i,
|
|
2907
|
-
...this.config.selectedModel &&
|
|
2908
|
-
...o !== "auto" &&
|
|
1938
|
+
...this.config.selectedModel && de(e.surface, "model.select") ? { modelRef: this.config.selectedModel } : {},
|
|
1939
|
+
...o !== "auto" && de(e.surface, "reasoning.effort") ? { reasoning: o } : {},
|
|
2909
1940
|
extensions: {
|
|
2910
|
-
...this.config.permissionMode &&
|
|
1941
|
+
...this.config.permissionMode && de(e.surface, "approval") ? { "ksadk.approval": this.config.permissionMode } : {},
|
|
2911
1942
|
...r.executionMode === "plan" ? { "ksadk.collaboration": "plan" } : {},
|
|
2912
1943
|
...r.executionMode === "goal" && a ? { "ksadk.goal": a } : {}
|
|
2913
1944
|
}
|
|
2914
1945
|
});
|
|
2915
|
-
return
|
|
1946
|
+
return ue(e.surface, s);
|
|
2916
1947
|
}
|
|
2917
1948
|
async uploadCanonicalAttachments(e) {
|
|
2918
1949
|
this.setStage("uploading-files");
|
|
2919
1950
|
let t = [];
|
|
2920
1951
|
for (let n of e) {
|
|
2921
|
-
if (n.size > 100 * 1024 * 1024) throw new
|
|
1952
|
+
if (n.size > 100 * 1024 * 1024) throw new G("conversation_input_unsupported", "Conversation attachment exceeds the Hosted UI upload limit.", { capability: n.type.startsWith("image/") ? "attachment.image" : "attachment.file" });
|
|
2922
1953
|
let e = new FormData();
|
|
2923
1954
|
e.append("file", n), e.append("AgentId", this.config.agentId);
|
|
2924
1955
|
let r;
|
|
2925
1956
|
try {
|
|
2926
1957
|
r = await this.api.uploadFile(e, { signal: this.abortController?.signal });
|
|
2927
1958
|
} catch (e) {
|
|
2928
|
-
throw new
|
|
1959
|
+
throw new G("conversation_http_error", "Conversation attachment upload failed.", { cause: e });
|
|
2929
1960
|
}
|
|
2930
1961
|
let i = r?.FileData?.fileUri;
|
|
2931
|
-
if (!i) throw new
|
|
1962
|
+
if (!i) throw new G("conversation_contract_mismatch", "Conversation attachment upload did not return an attachment reference.");
|
|
2932
1963
|
t.push({
|
|
2933
1964
|
kind: "attachment",
|
|
2934
1965
|
attachmentRef: i,
|
|
@@ -2959,7 +1990,7 @@ var Dn = {
|
|
|
2959
1990
|
} catch (e) {
|
|
2960
1991
|
this.emit({
|
|
2961
1992
|
type: "system_message",
|
|
2962
|
-
content: `【系统提示】图片 ${t.name} 读取失败,原因: ${
|
|
1993
|
+
content: `【系统提示】图片 ${t.name} 读取失败,原因: ${Dt(e)}`
|
|
2963
1994
|
});
|
|
2964
1995
|
}
|
|
2965
1996
|
continue;
|
|
@@ -2976,7 +2007,7 @@ var Dn = {
|
|
|
2976
2007
|
} catch (e) {
|
|
2977
2008
|
this.emit({
|
|
2978
2009
|
type: "system_message",
|
|
2979
|
-
content: `【系统提示】文件 ${t.name} 上传失败,原因: ${
|
|
2010
|
+
content: `【系统提示】文件 ${t.name} 上传失败,原因: ${Dt(e)}`
|
|
2980
2011
|
});
|
|
2981
2012
|
}
|
|
2982
2013
|
}
|
|
@@ -2998,9 +2029,10 @@ var Dn = {
|
|
|
2998
2029
|
ApiFormat: t,
|
|
2999
2030
|
Model: this.config.selectedModel || void 0,
|
|
3000
2031
|
ModelMetadata: this.config.selectedModelMetadata || void 0,
|
|
3001
|
-
ModelOptions:
|
|
2032
|
+
ModelOptions: At(kt(this.config.thinkingMode)),
|
|
3002
2033
|
Metadata: { agentengine: {
|
|
3003
2034
|
tool_approval_mode: this.config.permissionMode || "risk",
|
|
2035
|
+
...p(E.getState().modeFor(this.config.agentId)),
|
|
3004
2036
|
...o
|
|
3005
2037
|
} }
|
|
3006
2038
|
};
|
|
@@ -3053,7 +2085,7 @@ var Dn = {
|
|
|
3053
2085
|
status: "running",
|
|
3054
2086
|
countEvent: !1
|
|
3055
2087
|
});
|
|
3056
|
-
let i = new
|
|
2088
|
+
let i = new ke(e), a = r === "agent-block-v1" && t.presentationProfile === "agent-block-v1" ? "agent-block-v1" : "flat-v1", o = new Me(e, void 0, a), s = this.config.kernelCommandEventsEnabled && t.commandId || void 0;
|
|
3057
2089
|
if (this.config.kernelCommandEventsEnabled && !s) return this.emit({
|
|
3058
2090
|
type: "error",
|
|
3059
2091
|
error: /* @__PURE__ */ Error("运行回执缺少命令身份,无法安全订阅本轮输出。")
|
|
@@ -3074,9 +2106,9 @@ var Dn = {
|
|
|
3074
2106
|
let { value: s, done: d } = await r.read();
|
|
3075
2107
|
if (d) break;
|
|
3076
2108
|
_ += g.decode(s, { stream: !0 });
|
|
3077
|
-
let m =
|
|
2109
|
+
let m = Et(_);
|
|
3078
2110
|
_ = m.remainder;
|
|
3079
|
-
for (let r of m.chunks) if (r.trim()) for (let s of
|
|
2111
|
+
for (let r of m.chunks) if (r.trim()) for (let s of Tt(r)) {
|
|
3080
2112
|
f && (s.eventName === "__ping__" || s.data && typeof s.data == "object") && (f = !1, this.emit({
|
|
3081
2113
|
type: "activity",
|
|
3082
2114
|
phase: "正在处理",
|
|
@@ -3092,6 +2124,15 @@ var Dn = {
|
|
|
3092
2124
|
}
|
|
3093
2125
|
let m = String(r.run_id || "");
|
|
3094
2126
|
if (!l && m && (l = m, this.publishInvocation(l), n?.(l)), m && l !== m) continue;
|
|
2127
|
+
if (String(r.event_type).startsWith("mcp.authorization.")) {
|
|
2128
|
+
let e = r.payload ?? r, t = String(e.wait_id || "");
|
|
2129
|
+
t && [
|
|
2130
|
+
"resumed",
|
|
2131
|
+
"cancelled",
|
|
2132
|
+
"expired",
|
|
2133
|
+
"failed"
|
|
2134
|
+
].includes(String(e.status)) ? p.delete(t) : t && p.add(t);
|
|
2135
|
+
}
|
|
3095
2136
|
if (r.family === "interaction" && typeof r.interaction_id == "string" && (r.event_type === "interaction.requested" ? p.add(r.interaction_id) : [
|
|
3096
2137
|
"interaction.resolved",
|
|
3097
2138
|
"interaction.cancelled",
|
|
@@ -3103,7 +2144,7 @@ var Dn = {
|
|
|
3103
2144
|
sessionId: e,
|
|
3104
2145
|
result: {
|
|
3105
2146
|
state: t,
|
|
3106
|
-
presentation:
|
|
2147
|
+
presentation: _e(t, { profile: a }),
|
|
3107
2148
|
runId: l,
|
|
3108
2149
|
cursor: this.lastSeqId
|
|
3109
2150
|
}
|
|
@@ -3116,14 +2157,14 @@ var Dn = {
|
|
|
3116
2157
|
sessionId: e
|
|
3117
2158
|
}), h.EventType === "run_status")) {
|
|
3118
2159
|
let e = String(h.Content?.status || "").toLowerCase();
|
|
3119
|
-
e !== "interrupted" &&
|
|
2160
|
+
e !== "interrupted" && Vt.has(e) && (u = e);
|
|
3120
2161
|
}
|
|
3121
2162
|
}
|
|
3122
2163
|
}
|
|
3123
2164
|
u === void 0 && await new Promise((e) => setTimeout(e, 3e3));
|
|
3124
2165
|
} catch (e) {
|
|
3125
|
-
if (e instanceof
|
|
3126
|
-
if (s && e instanceof
|
|
2166
|
+
if (e instanceof X || this.abortController?.signal.aborted || e instanceof DOMException && e.name === "AbortError") return { terminalStatus: "cancelled" };
|
|
2167
|
+
if (s && e instanceof Y && e.code === 409 && e.detail?.Data?.ReasonCode === "KERNEL_COMMAND_PENDING") {
|
|
3127
2168
|
if (f = !0, this.emit({
|
|
3128
2169
|
type: "activity",
|
|
3129
2170
|
phase: "运行已入队,等待执行",
|
|
@@ -3132,7 +2173,7 @@ var Dn = {
|
|
|
3132
2173
|
}), await new Promise((e) => setTimeout(e, 1e3)), this.abortController?.signal.aborted) return { terminalStatus: "cancelled" };
|
|
3133
2174
|
continue;
|
|
3134
2175
|
}
|
|
3135
|
-
if (e instanceof
|
|
2176
|
+
if (e instanceof Y && e.code >= 400 && e.code < 500 && e.code !== 429) return this.emit({
|
|
3136
2177
|
type: "error",
|
|
3137
2178
|
error: e
|
|
3138
2179
|
}), { terminalStatus: "failed" };
|
|
@@ -3162,32 +2203,32 @@ var Dn = {
|
|
|
3162
2203
|
messageId: r,
|
|
3163
2204
|
invocationId: i
|
|
3164
2205
|
})), s += o.decode(e, { stream: !0 });
|
|
3165
|
-
let { chunks: m, remainder: h } =
|
|
2206
|
+
let { chunks: m, remainder: h } = Et(s);
|
|
3166
2207
|
s = h;
|
|
3167
2208
|
for (let e of m) {
|
|
3168
2209
|
if (!e.trim()) continue;
|
|
3169
2210
|
if (this.isCompactionChunk(e)) {
|
|
3170
|
-
let t =
|
|
2211
|
+
let t = Tt(e);
|
|
3171
2212
|
for (let e of t) e.eventName.startsWith("response.compaction") && this.upsertCompactionMessage({
|
|
3172
2213
|
...e.data,
|
|
3173
2214
|
phase: e.eventName.split(".").pop()
|
|
3174
2215
|
});
|
|
3175
2216
|
continue;
|
|
3176
2217
|
}
|
|
3177
|
-
let i =
|
|
2218
|
+
let i = Tt(e), o = !1;
|
|
3178
2219
|
for (let e of i) {
|
|
3179
2220
|
if (e.eventName === "__done__") {
|
|
3180
2221
|
o = !0;
|
|
3181
2222
|
continue;
|
|
3182
2223
|
}
|
|
3183
|
-
let i =
|
|
2224
|
+
let i = Ut(e.eventName, e.data);
|
|
3184
2225
|
i && !(d.size > 0 && (e.eventName === "response.incomplete" || e.data?.type === "response.incomplete")) && this.emit({
|
|
3185
2226
|
type: "activity",
|
|
3186
2227
|
...i
|
|
3187
2228
|
});
|
|
3188
2229
|
let a = t.parse(e, n);
|
|
3189
2230
|
for (let e of a) e.type === "approval_request" && d.add(e.approvalRequestId), e.type === "canonical_interaction" && d.add(e.interactionId), e.type === "approval_resolved" && d.delete(e.approvalRequestId), this.dispatchAction(e, r), e.type === "terminal" && (u = e.status);
|
|
3190
|
-
if (
|
|
2231
|
+
if (wt(a)) {
|
|
3191
2232
|
o = !0;
|
|
3192
2233
|
let e = a.find((e) => e.type === "terminal");
|
|
3193
2234
|
u = e && "status" in e ? String(e.status || "") : void 0;
|
|
@@ -3279,6 +2320,23 @@ var Dn = {
|
|
|
3279
2320
|
revision: e.revision
|
|
3280
2321
|
});
|
|
3281
2322
|
break;
|
|
2323
|
+
case "question_request":
|
|
2324
|
+
this.emit({
|
|
2325
|
+
type: "question_requested",
|
|
2326
|
+
messageId: t,
|
|
2327
|
+
questionId: e.questionId,
|
|
2328
|
+
questions: e.questions,
|
|
2329
|
+
runId: e.runId
|
|
2330
|
+
});
|
|
2331
|
+
break;
|
|
2332
|
+
case "question_resolved":
|
|
2333
|
+
this.emit({
|
|
2334
|
+
type: "question_resolved",
|
|
2335
|
+
questionId: e.questionId,
|
|
2336
|
+
answers: e.answers,
|
|
2337
|
+
revision: e.revision
|
|
2338
|
+
});
|
|
2339
|
+
break;
|
|
3282
2340
|
case "incomplete": break;
|
|
3283
2341
|
case "failed":
|
|
3284
2342
|
this.emit({
|
|
@@ -3350,12 +2408,12 @@ var Dn = {
|
|
|
3350
2408
|
};
|
|
3351
2409
|
//#endregion
|
|
3352
2410
|
//#region src/utils/recovered-run.ts
|
|
3353
|
-
function
|
|
3354
|
-
let r = e.filter((e) => e.role === "model" && e.invocationId === n), i =
|
|
2411
|
+
function qt(e, t, n) {
|
|
2412
|
+
let r = e.filter((e) => e.role === "model" && e.invocationId === n), i = R(t).filter((e) => e.role === "model"), a = i.map((e) => ({
|
|
3355
2413
|
...e,
|
|
3356
2414
|
id: !e.itemId && i.length === 1 ? r[0]?.id || `${n}:assistant` : e.id,
|
|
3357
2415
|
invocationId: n,
|
|
3358
|
-
blocks:
|
|
2416
|
+
blocks: Ae({
|
|
3359
2417
|
content: e.content,
|
|
3360
2418
|
reasoning: e.reasoning,
|
|
3361
2419
|
reasoningSource: e.reasoningSource,
|
|
@@ -3372,21 +2430,21 @@ function kn(e, t, n) {
|
|
|
3372
2430
|
}
|
|
3373
2431
|
//#endregion
|
|
3374
2432
|
//#region src/core/run/dispatcher.ts
|
|
3375
|
-
var
|
|
3376
|
-
function
|
|
2433
|
+
var Jt = "连接断开或生成出错,请重试";
|
|
2434
|
+
function Yt(e) {
|
|
3377
2435
|
let t = String(e.message || "").trim();
|
|
3378
|
-
return /runtime agent kernel is not ready/i.test(t) ? "云端运行时尚未就绪,请检查部署状态后重试" : !t || /failed to fetch|networkerror/i.test(t) ?
|
|
2436
|
+
return /runtime agent kernel is not ready/i.test(t) ? "云端运行时尚未就绪,请检查部署状态后重试" : !t || /failed to fetch|networkerror/i.test(t) ? Jt : t.length <= 240 ? t : Jt;
|
|
3379
2437
|
}
|
|
3380
|
-
var
|
|
2438
|
+
var Xt = new Set(["completed"]), Zt = new Set([
|
|
3381
2439
|
"failed",
|
|
3382
2440
|
"error",
|
|
3383
2441
|
"cancelled",
|
|
3384
2442
|
"canceled",
|
|
3385
2443
|
"aborted",
|
|
3386
2444
|
"incomplete"
|
|
3387
|
-
]),
|
|
3388
|
-
function
|
|
3389
|
-
|
|
2445
|
+
]), Qt = /* @__PURE__ */ new Map();
|
|
2446
|
+
function Z(e, t) {
|
|
2447
|
+
U.getState().patchMessages((n) => {
|
|
3390
2448
|
if (n.some((t) => t.id === e)) return t ? n.map((n) => n.id === e ? {
|
|
3391
2449
|
...n,
|
|
3392
2450
|
invocationId: t
|
|
@@ -3411,12 +2469,12 @@ function Q(e, t) {
|
|
|
3411
2469
|
}];
|
|
3412
2470
|
});
|
|
3413
2471
|
}
|
|
3414
|
-
function
|
|
2472
|
+
function $t(e) {
|
|
3415
2473
|
return e.filter((e) => e.eventType !== "optimistic_assistant_placeholder");
|
|
3416
2474
|
}
|
|
3417
|
-
function
|
|
3418
|
-
let t = String(e || "").trim().toLowerCase(), n =
|
|
3419
|
-
n &&
|
|
2475
|
+
function en(e) {
|
|
2476
|
+
let t = String(e || "").trim().toLowerCase(), n = Xt.has(t) ? "completed" : Zt.has(t) ? "error" : null;
|
|
2477
|
+
n && U.getState().patchMessages((e) => e.map((e) => {
|
|
3420
2478
|
if (!e.tools) return e;
|
|
3421
2479
|
let t = !1, r = Object.fromEntries(Object.entries(e.tools).map(([e, r]) => r.status === "running" ? (t = !0, [e, {
|
|
3422
2480
|
...r,
|
|
@@ -3428,12 +2486,12 @@ function In(e) {
|
|
|
3428
2486
|
} : e;
|
|
3429
2487
|
}));
|
|
3430
2488
|
}
|
|
3431
|
-
function
|
|
2489
|
+
function Q(e, t) {
|
|
3432
2490
|
!e.sessionId && t?.draftId && (e = {
|
|
3433
2491
|
...e,
|
|
3434
2492
|
sessionId: t.draftId
|
|
3435
2493
|
});
|
|
3436
|
-
let n = t ? !t.visible : !!(e.sessionId &&
|
|
2494
|
+
let n = t ? !t.visible : !!(e.sessionId && h.getState().currentSessionId !== e.sessionId);
|
|
3437
2495
|
if (n && ![
|
|
3438
2496
|
"activity",
|
|
3439
2497
|
"stage_changed",
|
|
@@ -3447,12 +2505,12 @@ function Ln(e, t) {
|
|
|
3447
2505
|
"stream_event",
|
|
3448
2506
|
"conversation_snapshot"
|
|
3449
2507
|
].includes(e.type)) return;
|
|
3450
|
-
let
|
|
3451
|
-
e &&
|
|
2508
|
+
let i = U.getState(), a = (e) => {
|
|
2509
|
+
e && r.getState().updateActivity({ sessionId: e });
|
|
3452
2510
|
};
|
|
3453
2511
|
switch (e.type) {
|
|
3454
2512
|
case "activity":
|
|
3455
|
-
|
|
2513
|
+
r.getState().updateActivity({
|
|
3456
2514
|
sessionId: e.sessionId,
|
|
3457
2515
|
visible: !n,
|
|
3458
2516
|
source: e.source,
|
|
@@ -3463,7 +2521,7 @@ function Ln(e, t) {
|
|
|
3463
2521
|
});
|
|
3464
2522
|
break;
|
|
3465
2523
|
case "user_message_added":
|
|
3466
|
-
|
|
2524
|
+
r.getState().setBanner(null), i.patchMessages((t) => [...t, {
|
|
3467
2525
|
id: e.messageId,
|
|
3468
2526
|
role: "user",
|
|
3469
2527
|
content: "",
|
|
@@ -3471,48 +2529,48 @@ function Ln(e, t) {
|
|
|
3471
2529
|
}]);
|
|
3472
2530
|
break;
|
|
3473
2531
|
case "assistant_message_created":
|
|
3474
|
-
|
|
2532
|
+
Z(e.messageId, e.invocationId);
|
|
3475
2533
|
break;
|
|
3476
2534
|
case "text_delta":
|
|
3477
|
-
|
|
2535
|
+
Z(e.messageId), a(e.sessionId), i.patchMessages((t) => t.map((t) => t.id === e.messageId ? {
|
|
3478
2536
|
...t,
|
|
3479
2537
|
content: t.content + e.delta,
|
|
3480
|
-
blocks:
|
|
2538
|
+
blocks: ge(t.blocks, e.delta)
|
|
3481
2539
|
} : t));
|
|
3482
2540
|
break;
|
|
3483
2541
|
case "text_replace":
|
|
3484
|
-
if (e.sessionId &&
|
|
3485
|
-
|
|
2542
|
+
if (e.sessionId && h.getState().currentSessionId && e.sessionId !== h.getState().currentSessionId && e.sessionId !== t?.draftId) break;
|
|
2543
|
+
i.patchMessages((t) => t.map((t) => t.id === e.messageId && t.role === "model" ? {
|
|
3486
2544
|
...t,
|
|
3487
2545
|
content: e.text,
|
|
3488
|
-
blocks:
|
|
3489
|
-
} : t)),
|
|
2546
|
+
blocks: je(t.blocks, e.text)
|
|
2547
|
+
} : t)), a(e.sessionId);
|
|
3490
2548
|
break;
|
|
3491
2549
|
case "text_final":
|
|
3492
|
-
|
|
3493
|
-
let n = !!(e.text && !t.content && t.reasoning?.endsWith(e.text)), r = n ? t.reasoning.slice(0, -e.text.length) : t.reasoning, i = n ?
|
|
2550
|
+
Z(e.messageId), a(e.sessionId), i.patchMessages((t) => t.map((t) => t.id === e.messageId ? (() => {
|
|
2551
|
+
let n = !!(e.text && !t.content && t.reasoning?.endsWith(e.text)), r = n ? t.reasoning.slice(0, -e.text.length) : t.reasoning, i = n ? ye(t.blocks, e.text) : t.blocks;
|
|
3494
2552
|
return {
|
|
3495
2553
|
...t,
|
|
3496
2554
|
reasoning: r,
|
|
3497
2555
|
content: e.text,
|
|
3498
|
-
blocks:
|
|
2556
|
+
blocks: ve(i, e.text)
|
|
3499
2557
|
};
|
|
3500
2558
|
})() : t));
|
|
3501
2559
|
break;
|
|
3502
2560
|
case "reasoning_delta":
|
|
3503
|
-
|
|
2561
|
+
Z(e.messageId), a(e.sessionId), i.patchMessages((t) => t.map((t) => t.id === e.messageId ? {
|
|
3504
2562
|
...t,
|
|
3505
2563
|
reasoning: (t.reasoning || "") + e.delta,
|
|
3506
|
-
blocks:
|
|
2564
|
+
blocks: De(t.blocks, e.delta)
|
|
3507
2565
|
} : t));
|
|
3508
2566
|
break;
|
|
3509
2567
|
case "tool_upsert":
|
|
3510
|
-
|
|
2568
|
+
Z(e.messageId), a(e.sessionId), i.patchMessages((t) => t.map((t) => {
|
|
3511
2569
|
if (t.id !== e.messageId) return t;
|
|
3512
2570
|
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;
|
|
3513
2571
|
return {
|
|
3514
2572
|
...t,
|
|
3515
|
-
blocks:
|
|
2573
|
+
blocks: be(t.blocks, e.name, {
|
|
3516
2574
|
args: e.args,
|
|
3517
2575
|
status: a,
|
|
3518
2576
|
extra: e.extra
|
|
@@ -3535,12 +2593,12 @@ function Ln(e, t) {
|
|
|
3535
2593
|
}));
|
|
3536
2594
|
break;
|
|
3537
2595
|
case "tool_result":
|
|
3538
|
-
|
|
2596
|
+
Z(e.messageId), a(e.sessionId), i.patchMessages((t) => t.map((t) => {
|
|
3539
2597
|
if (t.id !== e.messageId) return t;
|
|
3540
|
-
let n =
|
|
2598
|
+
let n = F(e.output) ? "error" : "completed";
|
|
3541
2599
|
return {
|
|
3542
2600
|
...t,
|
|
3543
|
-
blocks:
|
|
2601
|
+
blocks: be(t.blocks, e.name, {
|
|
3544
2602
|
output: e.output,
|
|
3545
2603
|
status: n
|
|
3546
2604
|
}),
|
|
@@ -3559,7 +2617,7 @@ function Ln(e, t) {
|
|
|
3559
2617
|
}));
|
|
3560
2618
|
break;
|
|
3561
2619
|
case "approval_requested":
|
|
3562
|
-
if (
|
|
2620
|
+
if (w({
|
|
3563
2621
|
approvalRequestId: e.approvalRequestId,
|
|
3564
2622
|
protocol: e.protocol,
|
|
3565
2623
|
requestSchema: e.requestSchema,
|
|
@@ -3571,7 +2629,7 @@ function Ln(e, t) {
|
|
|
3571
2629
|
previousResponseId: e.previousResponseId,
|
|
3572
2630
|
sessionId: e.sessionId
|
|
3573
2631
|
}), n) break;
|
|
3574
|
-
|
|
2632
|
+
Z(e.messageId), i.patchMessages((t) => t.map((t) => {
|
|
3575
2633
|
if (t.id !== e.messageId) return t;
|
|
3576
2634
|
let n = t.tools?.[e.approvalRequestId], r = n?.approvalStatus === "approved" || n?.approvalStatus === "rejected" || n?.approvalStatus === "cancelled", i = {
|
|
3577
2635
|
approvalRequestId: e.approvalRequestId,
|
|
@@ -3583,7 +2641,7 @@ function Ln(e, t) {
|
|
|
3583
2641
|
}, a = r ? n.status : "paused";
|
|
3584
2642
|
return {
|
|
3585
2643
|
...t,
|
|
3586
|
-
blocks:
|
|
2644
|
+
blocks: be(t.blocks, e.name, {
|
|
3587
2645
|
args: e.args,
|
|
3588
2646
|
status: a,
|
|
3589
2647
|
extra: i
|
|
@@ -3602,16 +2660,32 @@ function Ln(e, t) {
|
|
|
3602
2660
|
}));
|
|
3603
2661
|
break;
|
|
3604
2662
|
case "interaction_submit_rejected":
|
|
3605
|
-
|
|
2663
|
+
v(e);
|
|
2664
|
+
break;
|
|
2665
|
+
case "question_requested":
|
|
2666
|
+
A({
|
|
2667
|
+
questionId: e.questionId,
|
|
2668
|
+
questions: e.questions,
|
|
2669
|
+
runId: e.runId,
|
|
2670
|
+
sessionId: e.sessionId
|
|
2671
|
+
});
|
|
2672
|
+
break;
|
|
2673
|
+
case "question_resolved":
|
|
2674
|
+
y({
|
|
2675
|
+
questionId: e.questionId,
|
|
2676
|
+
answers: e.answers,
|
|
2677
|
+
revision: e.revision,
|
|
2678
|
+
sessionId: e.sessionId
|
|
2679
|
+
});
|
|
3606
2680
|
break;
|
|
3607
2681
|
case "approval_resolved":
|
|
3608
|
-
if (
|
|
2682
|
+
if (O({
|
|
3609
2683
|
approvalRequestId: e.approvalRequestId,
|
|
3610
2684
|
decision: e.decision,
|
|
3611
2685
|
revision: e.revision,
|
|
3612
2686
|
sessionId: e.sessionId
|
|
3613
2687
|
}), n) break;
|
|
3614
|
-
|
|
2688
|
+
i.patchMessages((t) => t.map((t) => {
|
|
3615
2689
|
if (!t.tools) return t;
|
|
3616
2690
|
let n = !1, r = Object.fromEntries(Object.entries(t.tools).map(([t, r]) => {
|
|
3617
2691
|
if (r.approvalRequestId !== e.approvalRequestId) return [t, r];
|
|
@@ -3642,7 +2716,7 @@ function Ln(e, t) {
|
|
|
3642
2716
|
}));
|
|
3643
2717
|
break;
|
|
3644
2718
|
case "system_message":
|
|
3645
|
-
|
|
2719
|
+
i.patchMessages((t) => [...t, {
|
|
3646
2720
|
id: String(Date.now() + Math.random()),
|
|
3647
2721
|
role: "system",
|
|
3648
2722
|
content: e.content,
|
|
@@ -3650,48 +2724,48 @@ function Ln(e, t) {
|
|
|
3650
2724
|
}]);
|
|
3651
2725
|
break;
|
|
3652
2726
|
case "compaction": {
|
|
3653
|
-
let t = `compaction-${Date.now()}`, n = e.phase === "start" ? "running" : e.phase === "failed" ? "failed" : "completed",
|
|
2727
|
+
let t = `compaction-${Date.now()}`, n = e.phase === "start" ? "running" : e.phase === "failed" ? "failed" : "completed", r = B({
|
|
3654
2728
|
id: t,
|
|
3655
2729
|
timestamp: Date.now(),
|
|
3656
2730
|
status: n,
|
|
3657
2731
|
trigger: e.trigger,
|
|
3658
2732
|
compactedUntilSeqId: e.compactedUntilSeqId
|
|
3659
2733
|
});
|
|
3660
|
-
|
|
2734
|
+
i.patchMessages((e) => e.findIndex((e) => e.id === t) < 0 ? [...e, r] : e.map((e) => e.id === t ? {
|
|
3661
2735
|
...e,
|
|
3662
|
-
...
|
|
2736
|
+
...r
|
|
3663
2737
|
} : e));
|
|
3664
2738
|
break;
|
|
3665
2739
|
}
|
|
3666
2740
|
case "stage_changed":
|
|
3667
|
-
e.stage === "streaming" || e.stage === "connecting" ?
|
|
2741
|
+
e.stage === "streaming" || e.stage === "connecting" ? r.getState().setSessionStreaming(e.sessionId, !0) : (e.stage === "completing" || e.stage === "error" || e.stage === "cancelled") && r.getState().setSessionStreaming(e.sessionId, !1);
|
|
3668
2742
|
break;
|
|
3669
2743
|
case "stream_ended":
|
|
3670
|
-
|
|
2744
|
+
r.getState().setSessionStreaming(e.sessionId, !1), n || U.getState().patchMessages((t) => $t(t).map((t) => !(!e.runId || t.runId === e.runId || t.invocationId === e.runId) || t.role !== "model" || !t.blocks?.some((e) => e.status === "streaming") ? t : {
|
|
3671
2745
|
...t,
|
|
3672
|
-
blocks:
|
|
2746
|
+
blocks: we(t.blocks.map((e) => e.type === "text" && e.status === "streaming" ? {
|
|
3673
2747
|
...e,
|
|
3674
2748
|
status: "done"
|
|
3675
2749
|
} : e))
|
|
3676
2750
|
})), globalThis.setTimeout(() => {
|
|
3677
|
-
let t =
|
|
2751
|
+
let t = r.getState();
|
|
3678
2752
|
t.getSessionActivity(e.sessionId)?.status === "completed" && t.clearSessionActivity(e.sessionId);
|
|
3679
2753
|
}, 2400);
|
|
3680
2754
|
break;
|
|
3681
2755
|
case "error": {
|
|
3682
|
-
let t =
|
|
3683
|
-
|
|
2756
|
+
let t = Yt(e.error);
|
|
2757
|
+
r.getState().setSessionStreaming(e.sessionId, !1), r.getState().updateActivity({
|
|
3684
2758
|
sessionId: e.sessionId,
|
|
3685
2759
|
visible: !n,
|
|
3686
2760
|
status: "failed",
|
|
3687
2761
|
phase: "运行失败",
|
|
3688
2762
|
detail: t,
|
|
3689
2763
|
countEvent: !1
|
|
3690
|
-
}), n || (
|
|
2764
|
+
}), n || (r.getState().setBanner({
|
|
3691
2765
|
kind: "error",
|
|
3692
2766
|
message: t,
|
|
3693
2767
|
sessionId: e.sessionId
|
|
3694
|
-
}),
|
|
2768
|
+
}), i.patchMessages((e) => [...$t(e), {
|
|
3695
2769
|
id: String(Date.now()),
|
|
3696
2770
|
role: "model",
|
|
3697
2771
|
content: `运行失败:${t}`,
|
|
@@ -3700,51 +2774,51 @@ function Ln(e, t) {
|
|
|
3700
2774
|
break;
|
|
3701
2775
|
}
|
|
3702
2776
|
case "rate_limited":
|
|
3703
|
-
|
|
2777
|
+
r.getState().setSessionStreaming(e.sessionId, !1), r.getState().updateActivity({
|
|
3704
2778
|
sessionId: e.sessionId,
|
|
3705
2779
|
visible: !n,
|
|
3706
2780
|
status: "failed",
|
|
3707
2781
|
phase: "请求被限流",
|
|
3708
2782
|
countEvent: !1
|
|
3709
|
-
}), n || (
|
|
2783
|
+
}), n || (r.getState().setBanner({
|
|
3710
2784
|
kind: "rate_limited",
|
|
3711
2785
|
message: e.message || "请求过于频繁,请稍后重试",
|
|
3712
2786
|
retryAfterSec: e.retryAfterSec,
|
|
3713
2787
|
sessionId: e.sessionId
|
|
3714
|
-
}),
|
|
2788
|
+
}), i.patchMessages($t));
|
|
3715
2789
|
break;
|
|
3716
2790
|
case "terminal":
|
|
3717
|
-
e.sessionId && String(e.status || "").trim().toLowerCase() !== "incomplete" &&
|
|
2791
|
+
e.sessionId && String(e.status || "").trim().toLowerCase() !== "incomplete" && T.markSessionTerminal(e.sessionId), n || en(e.status);
|
|
3718
2792
|
break;
|
|
3719
2793
|
case "stream_event": {
|
|
3720
2794
|
let t = e.sessionId || e.event.SessionId;
|
|
3721
|
-
|
|
3722
|
-
let
|
|
3723
|
-
!n && typeof
|
|
2795
|
+
x(e.event, t || void 0);
|
|
2796
|
+
let i = e.event.SeqId;
|
|
2797
|
+
!n && typeof i == "number" && i > 0 && r.getState().setLastSeqId(i), t && r.getState().updateActivity({
|
|
3724
2798
|
sessionId: t,
|
|
3725
2799
|
visible: !n
|
|
3726
2800
|
});
|
|
3727
|
-
let
|
|
3728
|
-
if (!n && t &&
|
|
3729
|
-
let n = `${t}:${
|
|
3730
|
-
|
|
2801
|
+
let a = String(e.event.InvocationId || "").trim();
|
|
2802
|
+
if (!n && t && a) {
|
|
2803
|
+
let n = `${t}:${a}`, r = L(Qt.get(n) || [], [e.event]);
|
|
2804
|
+
Qt.set(n, r), U.getState().patchMessages((e) => e.some((e) => e.eventType === "conversation_item_v1" && e.runId === a) ? e : qt(e, r, a)), P(e.event) && Qt.delete(n);
|
|
3731
2805
|
}
|
|
3732
|
-
e.event.EventType === "run_checkpoint" && t &&
|
|
2806
|
+
e.event.EventType === "run_checkpoint" && t && W.getState().upsertSessionCheckpoint(t, e.event);
|
|
3733
2807
|
{
|
|
3734
|
-
let
|
|
3735
|
-
|
|
2808
|
+
let i = z(e.event);
|
|
2809
|
+
i === "completed" ? r.getState().updateActivity({
|
|
3736
2810
|
sessionId: t,
|
|
3737
2811
|
visible: !n,
|
|
3738
2812
|
status: "completed",
|
|
3739
2813
|
phase: "后台长任务已完成",
|
|
3740
2814
|
countEvent: !1
|
|
3741
|
-
}) :
|
|
2815
|
+
}) : i === "cancelled" || i === "canceled" || i === "aborted" ? r.getState().updateActivity({
|
|
3742
2816
|
sessionId: t,
|
|
3743
2817
|
visible: !n,
|
|
3744
2818
|
status: "stopped",
|
|
3745
2819
|
phase: "后台长任务已取消",
|
|
3746
2820
|
countEvent: !1
|
|
3747
|
-
}) : (
|
|
2821
|
+
}) : (i === "failed" || i === "error") && r.getState().updateActivity({
|
|
3748
2822
|
sessionId: t,
|
|
3749
2823
|
visible: !n,
|
|
3750
2824
|
status: "failed",
|
|
@@ -3755,15 +2829,15 @@ function Ln(e, t) {
|
|
|
3755
2829
|
break;
|
|
3756
2830
|
}
|
|
3757
2831
|
case "conversation_snapshot": {
|
|
3758
|
-
let t =
|
|
3759
|
-
for (let e of t.interactions)
|
|
2832
|
+
let t = Te(e.result);
|
|
2833
|
+
for (let e of t.interactions) T.upsert(e);
|
|
3760
2834
|
if (n) break;
|
|
3761
|
-
|
|
2835
|
+
i.patchMessages((t) => Oe(t, e.result, e.optimisticMessageId)), a(e.sessionId);
|
|
3762
2836
|
break;
|
|
3763
2837
|
}
|
|
3764
2838
|
case "a2ui_surface_begin": {
|
|
3765
2839
|
let t = `a2ui-${e.surfaceId}`;
|
|
3766
|
-
|
|
2840
|
+
U.getState().patchMessages((n) => [...n.filter((e) => e.id !== t), {
|
|
3767
2841
|
id: t,
|
|
3768
2842
|
role: "a2ui",
|
|
3769
2843
|
content: "",
|
|
@@ -3777,7 +2851,7 @@ function Ln(e, t) {
|
|
|
3777
2851
|
}
|
|
3778
2852
|
case "a2ui_surface_update": {
|
|
3779
2853
|
let t = `a2ui-${e.surfaceId}`;
|
|
3780
|
-
|
|
2854
|
+
U.getState().patchMessages((n) => n.map((n) => n.id === t && n.a2ui ? {
|
|
3781
2855
|
...n,
|
|
3782
2856
|
a2ui: {
|
|
3783
2857
|
...n.a2ui,
|
|
@@ -3788,7 +2862,7 @@ function Ln(e, t) {
|
|
|
3788
2862
|
}
|
|
3789
2863
|
case "a2ui_surface_end": {
|
|
3790
2864
|
let t = `a2ui-${e.surfaceId}`;
|
|
3791
|
-
|
|
2865
|
+
U.getState().patchMessages((e) => e.map((e) => e.id === t && e.a2ui ? {
|
|
3792
2866
|
...e,
|
|
3793
2867
|
a2ui: {
|
|
3794
2868
|
...e.a2ui,
|
|
@@ -3799,7 +2873,7 @@ function Ln(e, t) {
|
|
|
3799
2873
|
}
|
|
3800
2874
|
case "a2ui_interaction": {
|
|
3801
2875
|
let t = `a2ui-${e.surfaceId}`;
|
|
3802
|
-
|
|
2876
|
+
U.getState().patchMessages((n) => n.map((n) => n.id === t && n.a2ui ? {
|
|
3803
2877
|
...n,
|
|
3804
2878
|
a2ui: {
|
|
3805
2879
|
...n.a2ui,
|
|
@@ -3813,7 +2887,7 @@ function Ln(e, t) {
|
|
|
3813
2887
|
break;
|
|
3814
2888
|
}
|
|
3815
2889
|
case "agui_activity":
|
|
3816
|
-
|
|
2890
|
+
U.getState().patchMessages((t) => {
|
|
3817
2891
|
let n = t.find((t) => t.id === e.messageId), r = e.runId || n?.runId || n?.invocationId, i = `agui-a2ui-${JSON.stringify([
|
|
3818
2892
|
r || e.messageId,
|
|
3819
2893
|
e.interactionId || "",
|
|
@@ -3824,7 +2898,7 @@ function Ln(e, t) {
|
|
|
3824
2898
|
originMessageId: e.messageId,
|
|
3825
2899
|
...r ? { runId: r } : {},
|
|
3826
2900
|
...e.interactionId ? { interactionId: e.interactionId } : {}
|
|
3827
|
-
}, o =
|
|
2901
|
+
}, o = me(t.flatMap((e) => [...e.aguiActivity ? [{
|
|
3828
2902
|
message: e,
|
|
3829
2903
|
activity: e.aguiActivity
|
|
3830
2904
|
}] : [], ...(e.aguiActivities || []).map((t) => ({
|
|
@@ -3861,105 +2935,105 @@ function Ln(e, t) {
|
|
|
3861
2935
|
break;
|
|
3862
2936
|
}
|
|
3863
2937
|
}
|
|
3864
|
-
function
|
|
3865
|
-
|
|
2938
|
+
function tn() {
|
|
2939
|
+
Qt.clear();
|
|
3866
2940
|
}
|
|
3867
2941
|
//#endregion
|
|
3868
2942
|
//#region src/hooks/useRunAgent.ts
|
|
3869
|
-
var
|
|
3870
|
-
function
|
|
2943
|
+
var nn = 64;
|
|
2944
|
+
function rn(e, t, n) {
|
|
3871
2945
|
if (t.sessionId = n, t.conversationId) return;
|
|
3872
2946
|
let r = JSON.stringify([t.agentId, n]);
|
|
3873
2947
|
e.set(r, t), t.key !== r && e.get(t.key) === t && e.delete(t.key), t.key = r;
|
|
3874
2948
|
}
|
|
3875
|
-
function
|
|
3876
|
-
let n =
|
|
3877
|
-
let t =
|
|
3878
|
-
if (!(t.size <=
|
|
3879
|
-
if (t.size <=
|
|
2949
|
+
function an(t) {
|
|
2950
|
+
let n = _(), i = J(/* @__PURE__ */ new Map()), a = J(/* @__PURE__ */ new Set()), o = K((e) => a.current.has(e), []), s = K((e) => {
|
|
2951
|
+
let t = i.current;
|
|
2952
|
+
if (!(t.size <= nn)) for (let [n, r] of t) {
|
|
2953
|
+
if (t.size <= nn) break;
|
|
3880
2954
|
n === e || r.engine.stage !== "idle" || r.queue.length > 0 || r.isVisible() || t.delete(n);
|
|
3881
2955
|
}
|
|
3882
|
-
}, []),
|
|
2956
|
+
}, []), c = Fe(() => new Pe({ rendererCatalog: he }), []), l = t.conversationClient === void 0 ? t.uiCapabilities.ConversationSurface == null ? null : c : t.conversationClient, { agentId: u, apiFormats: d, agentFramework: f, selectedModel: p, selectedModelMetadata: m, thinkingMode: g, permissionMode: v, currentSessionIdRef: y, conversationIdRef: x, queuedDraftRef: S, onRunSettled: C, onSessionCreated: w, waitForPendingSessionCreation: T, uiCapabilities: E, outbox: D } = t, O = Fe(() => ({
|
|
3883
2957
|
a2uiCatalogRegistry: n,
|
|
3884
|
-
agentId:
|
|
3885
|
-
apiFormats:
|
|
3886
|
-
agentFramework:
|
|
3887
|
-
selectedModel:
|
|
3888
|
-
selectedModelMetadata:
|
|
3889
|
-
thinkingMode:
|
|
3890
|
-
permissionMode:
|
|
3891
|
-
runtimeCapabilityMatrix:
|
|
3892
|
-
hostedChatTransport: e(
|
|
3893
|
-
checkpointResumePreviewEnabled: !!
|
|
3894
|
-
kernelSessionEventsEnabled:
|
|
3895
|
-
kernelCommandEventsEnabled:
|
|
3896
|
-
presentationProfile:
|
|
3897
|
-
conversationClient:
|
|
2958
|
+
agentId: u,
|
|
2959
|
+
apiFormats: d,
|
|
2960
|
+
agentFramework: f,
|
|
2961
|
+
selectedModel: p,
|
|
2962
|
+
selectedModelMetadata: m,
|
|
2963
|
+
thinkingMode: E.Thinking ? g : "auto",
|
|
2964
|
+
permissionMode: v,
|
|
2965
|
+
runtimeCapabilityMatrix: E.RuntimeCapabilityMatrix,
|
|
2966
|
+
hostedChatTransport: e(E, { requireResumableRun: !!(E.RunLifecycle?.Enabled && E.RunLifecycle.Resume) }),
|
|
2967
|
+
checkpointResumePreviewEnabled: !!E.RunLifecycle?.CheckpointResumePreview,
|
|
2968
|
+
kernelSessionEventsEnabled: E.KernelSessionEvents === !0 || E.KernelSessionEventsByCommand === !0,
|
|
2969
|
+
kernelCommandEventsEnabled: E.KernelSessionEventsByCommand === !0,
|
|
2970
|
+
presentationProfile: le(E.ConversationSurface, he),
|
|
2971
|
+
conversationClient: l || void 0
|
|
3898
2972
|
}), [
|
|
2973
|
+
u,
|
|
2974
|
+
d,
|
|
3899
2975
|
f,
|
|
3900
2976
|
p,
|
|
3901
2977
|
m,
|
|
3902
|
-
h,
|
|
3903
2978
|
g,
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
d,
|
|
2979
|
+
v,
|
|
2980
|
+
E,
|
|
2981
|
+
l,
|
|
3908
2982
|
n
|
|
3909
|
-
]),
|
|
3910
|
-
let n = t.conversationIdRef?.current,
|
|
2983
|
+
]), k = K((e = y.current) => {
|
|
2984
|
+
let n = t.conversationIdRef?.current, r = JSON.stringify([u, n || e || "new-session"]), a = i.current.get(r);
|
|
3911
2985
|
if (!a) {
|
|
3912
|
-
|
|
3913
|
-
let o = () => t.agentIdRef.current ===
|
|
2986
|
+
s(r);
|
|
2987
|
+
let o = () => t.agentIdRef.current === u && (t.conversationIdRef ? t.conversationIdRef.current === n : y.current === a.sessionId), c = new Kt(t.api, {
|
|
3914
2988
|
isVisible: o,
|
|
3915
2989
|
draftId: n
|
|
3916
2990
|
});
|
|
3917
2991
|
a = {
|
|
3918
|
-
key:
|
|
3919
|
-
agentId:
|
|
2992
|
+
key: r,
|
|
2993
|
+
agentId: u,
|
|
3920
2994
|
conversationId: n,
|
|
3921
2995
|
sessionId: e || null,
|
|
3922
|
-
engine:
|
|
2996
|
+
engine: c,
|
|
3923
2997
|
queue: [],
|
|
3924
2998
|
isVisible: o
|
|
3925
|
-
},
|
|
2999
|
+
}, c.subscribe((e) => Q(e, {
|
|
3926
3000
|
visible: o(),
|
|
3927
3001
|
draftId: n
|
|
3928
|
-
})),
|
|
3002
|
+
})), i.current.set(r, a);
|
|
3929
3003
|
}
|
|
3930
3004
|
return a;
|
|
3931
3005
|
}, [
|
|
3932
|
-
|
|
3006
|
+
u,
|
|
3933
3007
|
t.agentIdRef,
|
|
3934
3008
|
t.api,
|
|
3935
3009
|
t.conversationIdRef,
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
]),
|
|
3939
|
-
let t =
|
|
3940
|
-
return t.engine.stage === "idle" && t.engine.updateConfig(
|
|
3941
|
-
}, [
|
|
3010
|
+
y,
|
|
3011
|
+
s
|
|
3012
|
+
]), A = K((e) => {
|
|
3013
|
+
let t = k(e);
|
|
3014
|
+
return t.engine.stage === "idle" && t.engine.updateConfig(O), t.engine;
|
|
3015
|
+
}, [O, k]), j = K((e) => {
|
|
3942
3016
|
if (!e.isVisible()) return;
|
|
3943
3017
|
let t = e.queue.map((e) => e.draft);
|
|
3944
|
-
S.current = t,
|
|
3945
|
-
}, [S]),
|
|
3018
|
+
S.current = t, b.getState().setQueuedDrafts(t);
|
|
3019
|
+
}, [S]), M = K((e) => {
|
|
3946
3020
|
let t = e.queue[0];
|
|
3947
|
-
!t || e.engine.stage !== "idle" || (e.queue.shift(),
|
|
3948
|
-
t.launch() || (e.queue.unshift(t),
|
|
3021
|
+
!t || e.engine.stage !== "idle" || (e.queue.shift(), j(e), queueMicrotask(() => {
|
|
3022
|
+
t.launch() || (e.queue.unshift(t), j(e));
|
|
3949
3023
|
}));
|
|
3950
|
-
}, [
|
|
3951
|
-
|
|
3952
|
-
let e = JSON.stringify([
|
|
3953
|
-
n ?
|
|
3024
|
+
}, [j]);
|
|
3025
|
+
q(() => {
|
|
3026
|
+
let e = JSON.stringify([u, t.conversationId || x?.current || t.currentSessionId || "new-session"]), n = i.current.get(e);
|
|
3027
|
+
n ? j(n) : (S.current = [], b.getState().setQueuedDrafts([]));
|
|
3954
3028
|
}, [
|
|
3955
|
-
|
|
3029
|
+
u,
|
|
3956
3030
|
t.currentSessionId,
|
|
3957
3031
|
t.conversationId,
|
|
3958
3032
|
x,
|
|
3959
|
-
|
|
3033
|
+
j,
|
|
3960
3034
|
S
|
|
3961
3035
|
]);
|
|
3962
|
-
let
|
|
3036
|
+
let ee = K((e) => {
|
|
3963
3037
|
let t = e.text.trim(), n = e.attachments.map((e) => ({
|
|
3964
3038
|
name: e.name,
|
|
3965
3039
|
url: URL.createObjectURL(e),
|
|
@@ -3967,7 +3041,7 @@ function Vn(t) {
|
|
|
3967
3041
|
}));
|
|
3968
3042
|
if (!t && n.length === 0) return;
|
|
3969
3043
|
let r = `optimistic-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
3970
|
-
return
|
|
3044
|
+
return U.getState().patchMessages((e) => [...e, {
|
|
3971
3045
|
id: r,
|
|
3972
3046
|
role: "user",
|
|
3973
3047
|
content: t,
|
|
@@ -3975,9 +3049,9 @@ function Vn(t) {
|
|
|
3975
3049
|
eventType: "optimistic_user_message",
|
|
3976
3050
|
attachments: n.length ? n : void 0
|
|
3977
3051
|
}]), r;
|
|
3978
|
-
}, []),
|
|
3052
|
+
}, []), N = K((e) => {
|
|
3979
3053
|
let t = `optimistic-assistant-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
3980
|
-
return
|
|
3054
|
+
return U.getState().patchMessages((n) => {
|
|
3981
3055
|
let r = n.findIndex((t) => t.id === e), i = r < 0 ? n.length : r + 1;
|
|
3982
3056
|
return [
|
|
3983
3057
|
...n.slice(0, i),
|
|
@@ -3992,125 +3066,125 @@ function Vn(t) {
|
|
|
3992
3066
|
...n.slice(i)
|
|
3993
3067
|
];
|
|
3994
3068
|
}), t;
|
|
3995
|
-
}, []),
|
|
3996
|
-
if (
|
|
3997
|
-
let
|
|
3998
|
-
|
|
3999
|
-
let
|
|
3069
|
+
}, []), P = K(async (e, t, n, o, s, c) => {
|
|
3070
|
+
if (c && a.current.has(c)) return !1;
|
|
3071
|
+
let l = k();
|
|
3072
|
+
j(l);
|
|
3073
|
+
let u = {
|
|
4000
3074
|
text: e,
|
|
4001
3075
|
attachments: [...t],
|
|
4002
3076
|
responsesInput: n,
|
|
4003
3077
|
previousResponseId: o,
|
|
4004
|
-
executionMode:
|
|
4005
|
-
optimisticMessageId:
|
|
3078
|
+
executionMode: s,
|
|
3079
|
+
optimisticMessageId: ee({
|
|
4006
3080
|
text: e,
|
|
4007
3081
|
attachments: t
|
|
4008
3082
|
})
|
|
4009
|
-
},
|
|
4010
|
-
requestId:
|
|
4011
|
-
conversationId:
|
|
4012
|
-
agentId:
|
|
3083
|
+
}, d = n === void 0 && l.conversationId && D ? D : void 0, f = l.conversationId && d ? d.enqueue({
|
|
3084
|
+
requestId: c,
|
|
3085
|
+
conversationId: l.conversationId,
|
|
3086
|
+
agentId: l.agentId,
|
|
4013
3087
|
text: e,
|
|
4014
3088
|
attachments: t.map((e) => ({
|
|
4015
3089
|
name: e.name,
|
|
4016
3090
|
type: e.type,
|
|
4017
3091
|
size: e.size
|
|
4018
3092
|
})),
|
|
4019
|
-
executionMode:
|
|
3093
|
+
executionMode: s
|
|
4020
3094
|
}) : void 0;
|
|
4021
|
-
|
|
4022
|
-
let
|
|
3095
|
+
f && d && (a.current.add(f.requestId), d.setRuntimeAttachments(f.requestId, t));
|
|
3096
|
+
let p;
|
|
4023
3097
|
try {
|
|
4024
|
-
|
|
3098
|
+
p = await T?.();
|
|
4025
3099
|
} catch (e) {
|
|
4026
|
-
throw
|
|
3100
|
+
throw f && d && (a.current.delete(f.requestId), d.update(f.requestId, {
|
|
4027
3101
|
status: "unknown",
|
|
4028
3102
|
error: "创建会话的结果待确认。"
|
|
4029
3103
|
})), e;
|
|
4030
3104
|
}
|
|
4031
|
-
!
|
|
4032
|
-
let
|
|
4033
|
-
|
|
3105
|
+
!l.sessionId && p && rn(i.current, l, p);
|
|
3106
|
+
let m, g = n === void 0 ? null : new Promise((e) => {
|
|
3107
|
+
m = e;
|
|
4034
3108
|
}), _ = () => {
|
|
4035
|
-
if (
|
|
4036
|
-
|
|
4037
|
-
let e =
|
|
4038
|
-
...
|
|
4039
|
-
sessionId:
|
|
3109
|
+
if (l.engine.stage !== "idle") return !1;
|
|
3110
|
+
l.engine.updateConfig(O), f && d && d.markSending(f.requestId), l.isVisible() && (b.getState().setMobileActionsOpen(!1), N(u.optimisticMessageId)), r.getState().setSessionStreaming(l.sessionId || l.conversationId, !0);
|
|
3111
|
+
let e = l.engine.start({
|
|
3112
|
+
...u,
|
|
3113
|
+
sessionId: l.sessionId,
|
|
4040
3114
|
onInvocationCreated: (e) => {
|
|
4041
|
-
|
|
3115
|
+
f && d && d.update(f.requestId, { invocationId: e }), l.isVisible() && U.getState().patchMessages((t) => t.map((t) => t.id === u.optimisticMessageId ? {
|
|
4042
3116
|
...t,
|
|
4043
3117
|
invocationId: e
|
|
4044
3118
|
} : t));
|
|
4045
3119
|
},
|
|
4046
3120
|
onSessionCreated: (e) => {
|
|
4047
|
-
let t =
|
|
4048
|
-
|
|
3121
|
+
let t = l.isVisible(), n = l.sessionId || l.conversationId;
|
|
3122
|
+
rn(i.current, l, e), f && d && d.update(f.requestId, { nativeSessionId: e }), r.getState().setSessionStreaming(e, !0), n !== e && r.getState().setSessionStreaming(n, !1), w?.(e, l.conversationId, l.agentId), !w && t && (h.getState().upsertSessions([{
|
|
4049
3123
|
SessionId: e,
|
|
4050
3124
|
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4051
|
-
}]),
|
|
3125
|
+
}]), y.current = e, h.getState().setCurrentSessionId(e)), t && $e(l.agentId, e);
|
|
4052
3126
|
},
|
|
4053
3127
|
onSessionUpsert: () => {},
|
|
4054
|
-
onDispatchResult:
|
|
3128
|
+
onDispatchResult: m,
|
|
4055
3129
|
onSettled: (e, t = "unknown") => {
|
|
4056
|
-
|
|
3130
|
+
f && a.current.delete(f.requestId), f && d && d.update(f.requestId, { status: t === "completed" || t === "awaiting-input" ? "completed" : t === "cancelled" ? "cancelled" : t === "failed" ? "failed" : "unknown" }), C?.(e, l.agentId, t), t === "completed" && M(l);
|
|
4057
3131
|
}
|
|
4058
3132
|
});
|
|
4059
|
-
return e ||
|
|
4060
|
-
},
|
|
4061
|
-
return !
|
|
4062
|
-
draft:
|
|
3133
|
+
return e || r.getState().setSessionStreaming(l.sessionId || l.conversationId, !1), e;
|
|
3134
|
+
}, v = _();
|
|
3135
|
+
return !v && n === void 0 ? (l.queue.push({
|
|
3136
|
+
draft: u,
|
|
4063
3137
|
launch: _
|
|
4064
|
-
}),
|
|
3138
|
+
}), j(l), !0) : g ? (v || m?.(!1), g) : v;
|
|
4065
3139
|
}, [
|
|
4066
|
-
F,
|
|
4067
|
-
P,
|
|
4068
|
-
k,
|
|
4069
|
-
b,
|
|
4070
3140
|
N,
|
|
4071
|
-
|
|
4072
|
-
w,
|
|
4073
|
-
T,
|
|
3141
|
+
ee,
|
|
4074
3142
|
O,
|
|
3143
|
+
y,
|
|
4075
3144
|
M,
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
j
|
|
4081
|
-
|
|
4082
|
-
|
|
3145
|
+
k,
|
|
3146
|
+
C,
|
|
3147
|
+
w,
|
|
3148
|
+
D,
|
|
3149
|
+
j,
|
|
3150
|
+
T
|
|
3151
|
+
]), F = K(() => {
|
|
3152
|
+
A(y.current).stop();
|
|
3153
|
+
}, [y, A]), I = K(() => {
|
|
3154
|
+
A(y.current).disconnect();
|
|
3155
|
+
}, [y, A]), L = K((e) => {
|
|
3156
|
+
let t = k(e.sessionId), n = A(e.sessionId);
|
|
4083
3157
|
if (n.stage !== "idle") return !1;
|
|
4084
|
-
|
|
4085
|
-
let
|
|
3158
|
+
tn(), b.getState().setMobileActionsOpen(!1), r.getState().setSessionStreaming(e.sessionId, !0);
|
|
3159
|
+
let i = n.resumeCheckpoint({
|
|
4086
3160
|
...e,
|
|
4087
3161
|
onSettled: (e, n) => {
|
|
4088
|
-
|
|
3162
|
+
C?.(e, t.agentId, n), n === "completed" && M(t);
|
|
4089
3163
|
}
|
|
4090
3164
|
});
|
|
4091
|
-
return
|
|
3165
|
+
return i || r.getState().setSessionStreaming(e.sessionId, !1), i;
|
|
4092
3166
|
}, [
|
|
4093
|
-
|
|
4094
|
-
j,
|
|
3167
|
+
M,
|
|
4095
3168
|
A,
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
3169
|
+
k,
|
|
3170
|
+
C
|
|
3171
|
+
]), R = K(() => {
|
|
3172
|
+
tn();
|
|
4099
3173
|
}, []);
|
|
4100
3174
|
return {
|
|
4101
|
-
submitDraft:
|
|
3175
|
+
submitDraft: P,
|
|
4102
3176
|
isOutboxRequestActive: o,
|
|
4103
|
-
stopGeneration:
|
|
4104
|
-
disconnectRun:
|
|
4105
|
-
resumeCheckpoint:
|
|
4106
|
-
submitAguiAction:
|
|
3177
|
+
stopGeneration: F,
|
|
3178
|
+
disconnectRun: I,
|
|
3179
|
+
resumeCheckpoint: L,
|
|
3180
|
+
submitAguiAction: K((e) => {
|
|
4107
3181
|
let t = e.userAction;
|
|
4108
3182
|
if (!t) return !1;
|
|
4109
3183
|
let n = t.context || {}, r = String(n.interruptId || n.interrupt_id || "");
|
|
4110
3184
|
if (!r) return !1;
|
|
4111
|
-
let i =
|
|
3185
|
+
let i = y.current;
|
|
4112
3186
|
if (!i) return !1;
|
|
4113
|
-
let a =
|
|
3187
|
+
let a = k(i), o = A(i), s = n.status === "cancelled" ? "cancelled" : "resolved", c = Object.prototype.hasOwnProperty.call(n, "payload") ? n.payload : {
|
|
4114
3188
|
action: t.name,
|
|
4115
3189
|
sourceComponentId: t.sourceComponentId,
|
|
4116
3190
|
context: n
|
|
@@ -4121,57 +3195,57 @@ function Vn(t) {
|
|
|
4121
3195
|
status: s,
|
|
4122
3196
|
payload: c,
|
|
4123
3197
|
onSettled: (e) => {
|
|
4124
|
-
|
|
3198
|
+
C?.(e, a.agentId), M(a);
|
|
4125
3199
|
}
|
|
4126
3200
|
});
|
|
4127
3201
|
}, [
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
j,
|
|
3202
|
+
y,
|
|
3203
|
+
M,
|
|
4131
3204
|
A,
|
|
4132
|
-
|
|
3205
|
+
k,
|
|
3206
|
+
C
|
|
4133
3207
|
]),
|
|
4134
|
-
respondToAguiApproval:
|
|
3208
|
+
respondToAguiApproval: K((e) => {
|
|
4135
3209
|
if (!e.interruptId) return !1;
|
|
4136
|
-
let t =
|
|
3210
|
+
let t = y.current;
|
|
4137
3211
|
if (!t) return !1;
|
|
4138
|
-
let n =
|
|
4139
|
-
if (
|
|
4140
|
-
|
|
4141
|
-
let
|
|
3212
|
+
let n = k(t), i = A(t);
|
|
3213
|
+
if (i.stage !== "idle") return !1;
|
|
3214
|
+
r.getState().setSessionStreaming(t, !0);
|
|
3215
|
+
let a = i.resumeAguiInterrupt({
|
|
4142
3216
|
sessionId: t,
|
|
4143
3217
|
interruptId: e.interruptId,
|
|
4144
3218
|
status: e.status || "resolved",
|
|
4145
3219
|
payload: Object.hasOwn(e, "payload") ? e.payload : { decision: e.approve ? "approve" : "reject" },
|
|
4146
3220
|
onSettled: (e) => {
|
|
4147
|
-
|
|
3221
|
+
C?.(e, n.agentId), M(n);
|
|
4148
3222
|
}
|
|
4149
3223
|
});
|
|
4150
|
-
return
|
|
3224
|
+
return a || r.getState().setSessionStreaming(t, !1), a;
|
|
4151
3225
|
}, [
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
j,
|
|
3226
|
+
y,
|
|
3227
|
+
M,
|
|
4155
3228
|
A,
|
|
4156
|
-
|
|
3229
|
+
k,
|
|
3230
|
+
C
|
|
4157
3231
|
]),
|
|
4158
|
-
resetCompaction:
|
|
3232
|
+
resetCompaction: R
|
|
4159
3233
|
};
|
|
4160
3234
|
}
|
|
4161
3235
|
//#endregion
|
|
4162
3236
|
//#region src/utils/history-preparation.ts
|
|
4163
|
-
function
|
|
4164
|
-
return e instanceof
|
|
3237
|
+
function on(e) {
|
|
3238
|
+
return e instanceof Y && e.code === 503 && e.detail?.ReasonCode === "HISTORY_PREPARING";
|
|
4165
3239
|
}
|
|
4166
|
-
async function
|
|
3240
|
+
async function sn(e, t) {
|
|
4167
3241
|
let n = Date.now();
|
|
4168
3242
|
for (let r = 0;; r += 1) {
|
|
4169
|
-
if (!t.isCurrent() || t.signal?.aborted) throw new
|
|
3243
|
+
if (!t.isCurrent() || t.signal?.aborted) throw new X();
|
|
4170
3244
|
try {
|
|
4171
3245
|
return await e();
|
|
4172
3246
|
} catch (e) {
|
|
4173
|
-
if (!
|
|
4174
|
-
if (!t.isCurrent() || t.signal?.aborted) throw new
|
|
3247
|
+
if (!on(e) || r >= 60 || Date.now() - n >= 3e5) throw e;
|
|
3248
|
+
if (!t.isCurrent() || t.signal?.aborted) throw new X();
|
|
4175
3249
|
t.onPreparing?.(), await new Promise((e) => {
|
|
4176
3250
|
let i = () => {
|
|
4177
3251
|
clearTimeout(a), t.signal?.removeEventListener("abort", i), e();
|
|
@@ -4183,7 +3257,7 @@ async function Un(e, t) {
|
|
|
4183
3257
|
}
|
|
4184
3258
|
//#endregion
|
|
4185
3259
|
//#region src/utils/kernel-run-history.ts
|
|
4186
|
-
async function
|
|
3260
|
+
async function cn(e, t, n, r, i, a) {
|
|
4187
3261
|
let o = r.Events;
|
|
4188
3262
|
if (o.some((e) => e.EventType === "run.started" && e.InvocationId === n)) return o;
|
|
4189
3263
|
let s = {
|
|
@@ -4225,13 +3299,15 @@ async function Wn(e, t, n, r, i, a) {
|
|
|
4225
3299
|
c(r);
|
|
4226
3300
|
let i = r.Events;
|
|
4227
3301
|
if (!i.length || i.some((e) => !Number.isSafeInteger(e.SeqId) || Number(e.SeqId) >= n || Number(e.SeqId) < l)) throw Error("Kernel run history cursor did not advance");
|
|
4228
|
-
o =
|
|
3302
|
+
o = L(o, i);
|
|
4229
3303
|
}
|
|
4230
3304
|
return o;
|
|
4231
3305
|
}
|
|
4232
3306
|
//#endregion
|
|
4233
3307
|
//#region src/utils/interaction-history.ts
|
|
4234
|
-
var
|
|
3308
|
+
var ln = [
|
|
3309
|
+
"mcp.authorization.requested",
|
|
3310
|
+
"mcp.authorization.updated",
|
|
4235
3311
|
"interaction.requested",
|
|
4236
3312
|
"interaction_requested",
|
|
4237
3313
|
"ksadk.interaction/v1.requested",
|
|
@@ -4247,8 +3323,8 @@ var Gn = [
|
|
|
4247
3323
|
"interaction.expired",
|
|
4248
3324
|
"approval.resolved",
|
|
4249
3325
|
"a2ui.action"
|
|
4250
|
-
],
|
|
4251
|
-
async function
|
|
3326
|
+
], un = 32, dn = 2;
|
|
3327
|
+
async function fn(e, t, n, r, i, a) {
|
|
4252
3328
|
let o = /* @__PURE__ */ new Set(), s = Infinity, c = (e) => {
|
|
4253
3329
|
for (let t of e) {
|
|
4254
3330
|
t.agentBlock && c(t.agentBlock.messages);
|
|
@@ -4270,20 +3346,20 @@ async function Jn(e, t, n, r, i, a) {
|
|
|
4270
3346
|
incomplete: !1
|
|
4271
3347
|
};
|
|
4272
3348
|
let l = /* @__PURE__ */ new Set(), u = (e) => {
|
|
4273
|
-
let n =
|
|
3349
|
+
let n = f(e, t);
|
|
4274
3350
|
return !n || !o.has(n.interactionId) ? !1 : (n.status === "pending" && l.add(n.interactionId), !0);
|
|
4275
3351
|
};
|
|
4276
3352
|
if (r.Events.forEach(u), [...o].every((e) => l.has(e))) return {
|
|
4277
3353
|
events: [],
|
|
4278
3354
|
incomplete: !1
|
|
4279
3355
|
};
|
|
4280
|
-
let d = [],
|
|
4281
|
-
for (let n = 0; n <
|
|
3356
|
+
let d = [], p = Number(r.SnapshotSeqId) + 1;
|
|
3357
|
+
for (let n = 0; n < dn && i() && !a?.aborted; n += 1) {
|
|
4282
3358
|
let n = await e.listSessionEvents(t, {
|
|
4283
|
-
eventTypes:
|
|
4284
|
-
limit:
|
|
3359
|
+
eventTypes: ln,
|
|
3360
|
+
limit: un,
|
|
4285
3361
|
afterSeqId: s,
|
|
4286
|
-
beforeSeqId:
|
|
3362
|
+
beforeSeqId: p,
|
|
4287
3363
|
cursorSource: r.CursorSource,
|
|
4288
3364
|
historyEpoch: r.HistoryEpoch,
|
|
4289
3365
|
snapshotSeqId: r.SnapshotSeqId,
|
|
@@ -4300,9 +3376,9 @@ async function Jn(e, t, n, r, i, a) {
|
|
|
4300
3376
|
events: d,
|
|
4301
3377
|
incomplete: [...o].some((e) => !l.has(e))
|
|
4302
3378
|
};
|
|
4303
|
-
let
|
|
4304
|
-
if (!Number.isSafeInteger(
|
|
4305
|
-
|
|
3379
|
+
let f = Math.min(...c.map((e) => Number(e.SeqId)));
|
|
3380
|
+
if (!Number.isSafeInteger(f) || f <= s || f >= p) throw Error("Interaction history cursor did not advance");
|
|
3381
|
+
p = f;
|
|
4306
3382
|
}
|
|
4307
3383
|
return {
|
|
4308
3384
|
events: d,
|
|
@@ -4311,7 +3387,7 @@ async function Jn(e, t, n, r, i, a) {
|
|
|
4311
3387
|
}
|
|
4312
3388
|
//#endregion
|
|
4313
3389
|
//#region src/utils/messages.js
|
|
4314
|
-
var
|
|
3390
|
+
var pn = {
|
|
4315
3391
|
running: "running",
|
|
4316
3392
|
completed: "completed",
|
|
4317
3393
|
failed: "error",
|
|
@@ -4322,7 +3398,7 @@ var Yn = {
|
|
|
4322
3398
|
rejected: "completed",
|
|
4323
3399
|
cancelled: "completed",
|
|
4324
3400
|
expired: "completed"
|
|
4325
|
-
},
|
|
3401
|
+
}, mn = {
|
|
4326
3402
|
pending: "pending",
|
|
4327
3403
|
paused: "pending",
|
|
4328
3404
|
approved: "approved",
|
|
@@ -4331,7 +3407,7 @@ var Yn = {
|
|
|
4331
3407
|
cancelled: "cancelled",
|
|
4332
3408
|
expired: "cancelled"
|
|
4333
3409
|
};
|
|
4334
|
-
function
|
|
3410
|
+
function hn(e) {
|
|
4335
3411
|
if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
|
|
4336
3412
|
if (typeof e == "string") {
|
|
4337
3413
|
let t = Number(e.trim());
|
|
@@ -4341,7 +3417,7 @@ function Zn(e) {
|
|
|
4341
3417
|
}
|
|
4342
3418
|
return Date.now();
|
|
4343
3419
|
}
|
|
4344
|
-
function
|
|
3420
|
+
function gn(e) {
|
|
4345
3421
|
if (typeof e == "string") return e;
|
|
4346
3422
|
if (e && typeof e == "object") {
|
|
4347
3423
|
if (typeof e.text == "string") return e.text;
|
|
@@ -4349,23 +3425,23 @@ function Qn(e) {
|
|
|
4349
3425
|
}
|
|
4350
3426
|
return "";
|
|
4351
3427
|
}
|
|
4352
|
-
function
|
|
3428
|
+
function _n(e) {
|
|
4353
3429
|
let t = {}, n = /* @__PURE__ */ new Map();
|
|
4354
3430
|
for (let t of e ?? []) t?.Name && n.set(t.Name, (n.get(t.Name) || 0) + 1);
|
|
4355
3431
|
for (let r of e ?? []) {
|
|
4356
3432
|
if (!r?.Name) continue;
|
|
4357
|
-
let e =
|
|
3433
|
+
let e = pn[String(r.Status ?? "completed").toLowerCase()] ?? "completed", i = {
|
|
4358
3434
|
name: r.Name,
|
|
4359
3435
|
args: r.Args === void 0 ? "" : typeof r.Args == "string" ? r.Args : JSON.stringify(r.Args),
|
|
4360
3436
|
status: e
|
|
4361
3437
|
};
|
|
4362
|
-
r.Result !== void 0 && (i.output = typeof r.Result == "string" ? r.Result : JSON.stringify(r.Result)), r.ApprovalRequestId && (i.approvalRequestId = r.ApprovalRequestId, i.approvalStatus =
|
|
3438
|
+
r.Result !== void 0 && (i.output = typeof r.Result == "string" ? r.Result : JSON.stringify(r.Result)), r.ApprovalRequestId && (i.approvalRequestId = r.ApprovalRequestId, i.approvalStatus = mn[String(r.ApprovalStatus ?? r.Status ?? "paused").toLowerCase()], i.approvalProtocol = String(r.Protocol ?? "").toLowerCase() === "ag-ui" ? "ag-ui" : "responses", r.ApprovalMessage && (i.approvalMessage = String(r.ApprovalMessage)), r.ApprovalLevel && (i.approvalLevel = String(r.ApprovalLevel))), r.ToolCallId && (i.callId = r.ToolCallId, i.previousResponseId = r.ToolCallId);
|
|
4363
3439
|
let a = n.get(r.Name) > 1 && (r.ToolCallId || r.ApprovalRequestId) || r.Name;
|
|
4364
3440
|
t[a] = i;
|
|
4365
3441
|
}
|
|
4366
3442
|
return t;
|
|
4367
3443
|
}
|
|
4368
|
-
function
|
|
3444
|
+
function vn(e) {
|
|
4369
3445
|
if (Array.isArray(e)) return e.map((e) => ({
|
|
4370
3446
|
name: e.name || "",
|
|
4371
3447
|
url: e.url || "",
|
|
@@ -4373,10 +3449,10 @@ function er(e) {
|
|
|
4373
3449
|
fileUri: e.file_uri
|
|
4374
3450
|
}));
|
|
4375
3451
|
}
|
|
4376
|
-
function
|
|
3452
|
+
function yn(e) {
|
|
4377
3453
|
return e == null ? "" : typeof e == "string" ? e : JSON.stringify(e);
|
|
4378
3454
|
}
|
|
4379
|
-
function
|
|
3455
|
+
function bn(e) {
|
|
4380
3456
|
if (!(!Array.isArray(e) || !e.length)) return e.flatMap((e, t) => {
|
|
4381
3457
|
let n = String(e?.Type || "").toLowerCase(), r = e?.SeqId ?? t;
|
|
4382
3458
|
if (n === "thinking" || n === "text") {
|
|
@@ -4389,13 +3465,13 @@ function nr(e) {
|
|
|
4389
3465
|
}] : [];
|
|
4390
3466
|
}
|
|
4391
3467
|
if (n !== "tool") return [];
|
|
4392
|
-
let i =
|
|
3468
|
+
let i = pn[String(e?.Status || "completed").toLowerCase()] ?? "completed";
|
|
4393
3469
|
return [{
|
|
4394
3470
|
id: `history-tool-${r}`,
|
|
4395
3471
|
type: "tool",
|
|
4396
3472
|
toolName: String(e?.Name || "tool"),
|
|
4397
|
-
args:
|
|
4398
|
-
...e?.Result === void 0 ? {} : { output:
|
|
3473
|
+
args: yn(e?.Args),
|
|
3474
|
+
...e?.Result === void 0 ? {} : { output: yn(e.Result) },
|
|
4399
3475
|
status: i,
|
|
4400
3476
|
...e?.ToolCallId ? { extra: {
|
|
4401
3477
|
callId: String(e.ToolCallId),
|
|
@@ -4404,12 +3480,12 @@ function nr(e) {
|
|
|
4404
3480
|
}];
|
|
4405
3481
|
});
|
|
4406
3482
|
}
|
|
4407
|
-
function
|
|
4408
|
-
let t = e.Role === "assistant" ? "model" : e.Role || "user", n = e.ToolEvents?.length ?
|
|
3483
|
+
function xn(e) {
|
|
3484
|
+
let t = e.Role === "assistant" ? "model" : e.Role || "user", n = e.ToolEvents?.length ? _n(e.ToolEvents) : void 0, r = vn(e.Attachments), i = bn(e.Blocks), a = e.Reasoning?.length ? e.Reasoning.map((e) => e.text).join("") : void 0, o = {
|
|
4409
3485
|
id: e.MessageId || `msg-${e.SeqId ?? Math.random().toString(36).slice(2)}`,
|
|
4410
3486
|
role: t,
|
|
4411
|
-
content:
|
|
4412
|
-
timestamp:
|
|
3487
|
+
content: gn(e.Content),
|
|
3488
|
+
timestamp: hn(e.Timestamp),
|
|
4413
3489
|
...Number.isSafeInteger(e.SeqId) && e.SeqId > 0 ? { historyOrder: {
|
|
4414
3490
|
seq: e.SeqId,
|
|
4415
3491
|
...Number.isSafeInteger(e.StartSeqId) && e.StartSeqId > 0 ? { group: e.StartSeqId } : {}
|
|
@@ -4419,13 +3495,13 @@ function rr(e) {
|
|
|
4419
3495
|
tools: n,
|
|
4420
3496
|
attachments: r
|
|
4421
3497
|
};
|
|
4422
|
-
return t === "model" && (o.blocks = i ??
|
|
3498
|
+
return t === "model" && (o.blocks = i ?? Ae({
|
|
4423
3499
|
reasoning: a,
|
|
4424
3500
|
tools: n,
|
|
4425
3501
|
content: o.content
|
|
4426
3502
|
})), e.MessageId && (o.eventId = e.MessageId), e.InvocationId && (o.invocationId = e.InvocationId), e.ScopeId && (o.scopeId = e.ScopeId), e.ResponseId && (o.responseId = e.ResponseId), e.TraceId && (o.traceId = e.TraceId), e.RootSpanId && (o.rootSpanId = e.RootSpanId), o;
|
|
4427
3503
|
}
|
|
4428
|
-
function
|
|
3504
|
+
function Sn(e) {
|
|
4429
3505
|
return Array.isArray(e.Activities) ? e.Activities.flatMap((t, n) => {
|
|
4430
3506
|
let r = String(t?.SurfaceId || "");
|
|
4431
3507
|
if (!r) return [];
|
|
@@ -4439,7 +3515,7 @@ function ir(e) {
|
|
|
4439
3515
|
id: o && o !== String(e.MessageId || "") ? o : `${o || e.MessageId || e.SeqId || "message"}:a2ui:${r}:${n}`,
|
|
4440
3516
|
role: "a2ui",
|
|
4441
3517
|
content: "",
|
|
4442
|
-
timestamp:
|
|
3518
|
+
timestamp: hn(e.Timestamp),
|
|
4443
3519
|
...e.InvocationId ? { invocationId: String(e.InvocationId) } : {},
|
|
4444
3520
|
...Number.isSafeInteger(e.SeqId) && e.SeqId > 0 ? { historyOrder: {
|
|
4445
3521
|
seq: e.SeqId,
|
|
@@ -4448,35 +3524,35 @@ function ir(e) {
|
|
|
4448
3524
|
} } : {},
|
|
4449
3525
|
aguiActivity: {
|
|
4450
3526
|
surfaceId: r,
|
|
4451
|
-
messages:
|
|
3527
|
+
messages: D(a),
|
|
4452
3528
|
...typeof i?.interactionId == "string" ? { interactionId: i.interactionId } : {}
|
|
4453
3529
|
}
|
|
4454
3530
|
}];
|
|
4455
3531
|
}) : [];
|
|
4456
3532
|
}
|
|
4457
|
-
function
|
|
4458
|
-
return
|
|
3533
|
+
function Cn(e) {
|
|
3534
|
+
return Ne(xe(e.map(xn)).flatMap((t, n) => [t, ...Sn(e[n])]));
|
|
4459
3535
|
}
|
|
4460
3536
|
//#endregion
|
|
4461
3537
|
//#region src/utils/session-event-history.ts
|
|
4462
|
-
var
|
|
3538
|
+
var wn = class extends Error {
|
|
4463
3539
|
seq;
|
|
4464
3540
|
constructor(e) {
|
|
4465
3541
|
super(`Session event seq ${e} was received twice with conflicting content`), this.name = "SessionEventConflictError", this.seq = e;
|
|
4466
3542
|
}
|
|
4467
3543
|
};
|
|
4468
|
-
function
|
|
4469
|
-
return Array.isArray(e) ? `[${e.map(
|
|
3544
|
+
function Tn(e) {
|
|
3545
|
+
return Array.isArray(e) ? `[${e.map(Tn).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)}:${Tn(t)}`).join(",")}}` : JSON.stringify(e) ?? "null";
|
|
4470
3546
|
}
|
|
4471
|
-
var
|
|
3547
|
+
var En = new Set(["runtime"]), Dn = class {
|
|
4472
3548
|
eventsBySeq = /* @__PURE__ */ new Map();
|
|
4473
3549
|
lastSeqValue = 0;
|
|
4474
3550
|
accept(e) {
|
|
4475
|
-
let t =
|
|
3551
|
+
let t = l(e);
|
|
4476
3552
|
if (!t.ok) throw t.error;
|
|
4477
3553
|
let n = t.value, r = this.eventsBySeq.get(n.seq);
|
|
4478
3554
|
if (r) {
|
|
4479
|
-
if (
|
|
3555
|
+
if (Tn(r) !== Tn(n)) throw new wn(n.seq);
|
|
4480
3556
|
return;
|
|
4481
3557
|
}
|
|
4482
3558
|
this.eventsBySeq.set(n.seq, n), this.lastSeqValue = Math.max(this.lastSeqValue, n.seq);
|
|
@@ -4488,41 +3564,41 @@ var cr = new Set(["runtime"]), lr = class {
|
|
|
4488
3564
|
return this.lastSeqValue;
|
|
4489
3565
|
}
|
|
4490
3566
|
displayableEvents() {
|
|
4491
|
-
return [...this.eventsBySeq.values()].filter((e) =>
|
|
3567
|
+
return [...this.eventsBySeq.values()].filter((e) => En.has(e.family)).sort((e, t) => e.seq - t.seq);
|
|
4492
3568
|
}
|
|
4493
3569
|
};
|
|
4494
|
-
function
|
|
4495
|
-
return new
|
|
3570
|
+
function On() {
|
|
3571
|
+
return new Dn();
|
|
4496
3572
|
}
|
|
4497
3573
|
//#endregion
|
|
4498
3574
|
//#region src/hooks/useSessionLifecycle.ts
|
|
4499
|
-
var
|
|
4500
|
-
function
|
|
3575
|
+
var kn = 500, An = 30, jn = 50, Mn = 64, Nn = 8, Pn = 128, Fn = 1800 * 1e3;
|
|
3576
|
+
function In(e, t) {
|
|
4501
3577
|
return !(e.CursorSource !== t.CursorSource || e.HistoryEpoch !== t.HistoryEpoch || e.SnapshotSeqId !== void 0 && t.SnapshotSeqId !== void 0 && e.SnapshotSeqId !== t.SnapshotSeqId || !e.CursorSource && (e.CursorCompatibleWithRuntime === !1 || t.CursorCompatibleWithRuntime === !1));
|
|
4502
3578
|
}
|
|
4503
|
-
function
|
|
3579
|
+
function Ln(e) {
|
|
4504
3580
|
return {
|
|
4505
3581
|
CursorSource: e.cursorSource,
|
|
4506
3582
|
HistoryEpoch: e.historyEpoch,
|
|
4507
3583
|
SnapshotSeqId: e.snapshotSeqId
|
|
4508
3584
|
};
|
|
4509
3585
|
}
|
|
4510
|
-
function
|
|
4511
|
-
if (!(e instanceof
|
|
3586
|
+
function Rn(e) {
|
|
3587
|
+
if (!(e instanceof Y) || !e.detail || typeof e.detail != "object") return;
|
|
4512
3588
|
let t = e.detail;
|
|
4513
3589
|
return typeof t.ReasonCode == "string" ? t.ReasonCode : void 0;
|
|
4514
3590
|
}
|
|
4515
|
-
function
|
|
4516
|
-
return e instanceof
|
|
3591
|
+
function zn(e) {
|
|
3592
|
+
return e instanceof Y && e.code === 409 && Rn(e) === "HISTORY_RELOAD_REQUIRED";
|
|
4517
3593
|
}
|
|
4518
|
-
function
|
|
4519
|
-
return new
|
|
3594
|
+
function Bn() {
|
|
3595
|
+
return new Y(409, "历史来源已变化", {
|
|
4520
3596
|
Code: 409,
|
|
4521
3597
|
ReasonCode: "HISTORY_RELOAD_REQUIRED",
|
|
4522
3598
|
Data: null
|
|
4523
3599
|
});
|
|
4524
3600
|
}
|
|
4525
|
-
function
|
|
3601
|
+
function Vn(e) {
|
|
4526
3602
|
return {
|
|
4527
3603
|
dataSource: e.DataSource,
|
|
4528
3604
|
degraded: e.Degraded,
|
|
@@ -4536,37 +3612,37 @@ function Cr(e) {
|
|
|
4536
3612
|
preparing: !1
|
|
4537
3613
|
};
|
|
4538
3614
|
}
|
|
4539
|
-
function $(e, t, n, r, i =
|
|
3615
|
+
function $(e, t, n, r, i = Pn) {
|
|
4540
3616
|
for (e.delete(t), e.set(t, n); e.size > i;) {
|
|
4541
3617
|
let t = [...e.keys()].find((e) => e !== r);
|
|
4542
3618
|
if (!t) break;
|
|
4543
3619
|
e.delete(t);
|
|
4544
3620
|
}
|
|
4545
3621
|
}
|
|
4546
|
-
function
|
|
3622
|
+
function Hn(e) {
|
|
4547
3623
|
return new Promise((t) => {
|
|
4548
3624
|
if (e.aborted) {
|
|
4549
3625
|
t();
|
|
4550
3626
|
return;
|
|
4551
3627
|
}
|
|
4552
|
-
let n = globalThis.setTimeout(t,
|
|
3628
|
+
let n = globalThis.setTimeout(t, kn);
|
|
4553
3629
|
e.addEventListener("abort", () => {
|
|
4554
3630
|
globalThis.clearTimeout(n), t();
|
|
4555
3631
|
}, { once: !0 });
|
|
4556
3632
|
});
|
|
4557
3633
|
}
|
|
4558
|
-
var
|
|
3634
|
+
var Un = new Set([
|
|
4559
3635
|
"in_progress",
|
|
4560
3636
|
"running",
|
|
4561
3637
|
"resuming",
|
|
4562
3638
|
"starting"
|
|
4563
3639
|
]);
|
|
4564
|
-
function
|
|
3640
|
+
function Wn(e) {
|
|
4565
3641
|
let t = e.ActiveRunUpdatedAt || e.UpdatedAt, n = typeof t == "number" ? t > 1e11 ? t : t * 1e3 : Date.parse(String(t || ""));
|
|
4566
|
-
return Number.isFinite(n) && n <= Date.now() +
|
|
3642
|
+
return Number.isFinite(n) && n <= Date.now() + Fn && Date.now() - n <= Fn;
|
|
4567
3643
|
}
|
|
4568
|
-
function
|
|
4569
|
-
let t =
|
|
3644
|
+
function Gn(e) {
|
|
3645
|
+
let t = z(e);
|
|
4570
3646
|
return t ? t === "completed" ? {
|
|
4571
3647
|
status: "completed",
|
|
4572
3648
|
phase: "后台长任务已完成"
|
|
@@ -4584,11 +3660,11 @@ function Dr(e) {
|
|
|
4584
3660
|
phase: "后台长任务恢复失败"
|
|
4585
3661
|
} : null : null;
|
|
4586
3662
|
}
|
|
4587
|
-
function
|
|
4588
|
-
let { agentId: t, api: n, isMobile:
|
|
4589
|
-
|
|
4590
|
-
let
|
|
4591
|
-
let i = r.filter((e) =>
|
|
3663
|
+
function Kn(e) {
|
|
3664
|
+
let { agentId: t, api: n, isMobile: a, resetCompaction: o, uiCapabilities: s, disconnectRun: c, restoreSession: l = !0 } = e, u = J(e.currentSessionId), d = J(e.agentId), f = J(s);
|
|
3665
|
+
f.current = s;
|
|
3666
|
+
let p = J(null), g = J(On()), _ = J(0), v = J(null), y = J(null), S = J(/* @__PURE__ */ new Map()), w = J(/* @__PURE__ */ new Map()), T = J(/* @__PURE__ */ new Map()), E = J(/* @__PURE__ */ new Map()), D = J(/* @__PURE__ */ new Map()), O = J(/* @__PURE__ */ new Map()), k = J(/* @__PURE__ */ new Map()), A = J(/* @__PURE__ */ new Map()), j = J(null), M = J(null), N = J(null), F = J(null), I = K(async (e, t, r) => {
|
|
3667
|
+
let i = r.filter((e) => te(e, !1, !1));
|
|
4592
3668
|
if (!i.length) return;
|
|
4593
3669
|
let a = await Promise.all(i.map(async (r) => {
|
|
4594
3670
|
try {
|
|
@@ -4597,7 +3673,7 @@ function Or(e) {
|
|
|
4597
3673
|
SessionId: t,
|
|
4598
3674
|
ResponseId: r.responseId,
|
|
4599
3675
|
EventId: r.eventId
|
|
4600
|
-
}), a = i?.Feedback ?
|
|
3676
|
+
}), a = i?.Feedback ? ae(i.Feedback) : null;
|
|
4601
3677
|
return a ? {
|
|
4602
3678
|
messageId: r.id,
|
|
4603
3679
|
feedback: a
|
|
@@ -4606,19 +3682,19 @@ function Or(e) {
|
|
|
4606
3682
|
return console.error("Failed to load response feedback:", e), null;
|
|
4607
3683
|
}
|
|
4608
3684
|
}));
|
|
4609
|
-
if (
|
|
3685
|
+
if (u.current !== t) return;
|
|
4610
3686
|
let o = new Map(a.filter((e) => !!e).map((e) => [e.messageId, e.feedback]));
|
|
4611
|
-
o.size &&
|
|
3687
|
+
o.size && U.getState().patchMessages((e) => e.map((e) => o.has(e.id) ? {
|
|
4612
3688
|
...e,
|
|
4613
3689
|
feedback: o.get(e.id)
|
|
4614
3690
|
} : e));
|
|
4615
|
-
}, [n]), R =
|
|
4616
|
-
|
|
3691
|
+
}, [n]), R = K(async (e) => {
|
|
3692
|
+
p.current?.abort();
|
|
4617
3693
|
let t = new AbortController();
|
|
4618
|
-
|
|
4619
|
-
let
|
|
3694
|
+
p.current = t;
|
|
3695
|
+
let a = !1, o = !1, s = !1, c = i.getState(), l = c.agentId === d.current ? c.capabilities : f.current, m = l.KernelSessionEventsByCommand === !0, h = le(l.ConversationSurface, he), _ = new Me(e.sessionId, void 0, h), v = m ? 0 : e.afterSeqId, y = () => p.current === t && u.current === e.sessionId;
|
|
4620
3696
|
try {
|
|
4621
|
-
for (
|
|
3697
|
+
for (r.getState().setCurrentRunId(e.invocationId), r.getState().setActiveInvocationId(e.invocationId), r.getState().setSessionStreaming(e.sessionId, !0), r.getState().updateActivity({
|
|
4622
3698
|
sessionId: e.sessionId,
|
|
4623
3699
|
runId: e.invocationId,
|
|
4624
3700
|
source: "restore",
|
|
@@ -4626,28 +3702,28 @@ function Or(e) {
|
|
|
4626
3702
|
phase: "正在同步任务进展",
|
|
4627
3703
|
detail: e.invocationId,
|
|
4628
3704
|
countEvent: !1
|
|
4629
|
-
}); !
|
|
3705
|
+
}); !o && y();) {
|
|
4630
3706
|
try {
|
|
4631
|
-
let
|
|
3707
|
+
let i = await n.subscribeRunEvents({
|
|
4632
3708
|
sessionId: e.sessionId,
|
|
4633
3709
|
invocationId: e.invocationId,
|
|
4634
|
-
afterSeqId:
|
|
3710
|
+
afterSeqId: v
|
|
4635
3711
|
}, { signal: t.signal });
|
|
4636
|
-
if (!
|
|
3712
|
+
if (!y()) {
|
|
4637
3713
|
t.abort();
|
|
4638
3714
|
return;
|
|
4639
3715
|
}
|
|
4640
|
-
let
|
|
4641
|
-
for (; !
|
|
4642
|
-
let { value: t, done: n } = await
|
|
3716
|
+
let s = i.getReader(), c = new TextDecoder(), l = "";
|
|
3717
|
+
for (; !o && y();) {
|
|
3718
|
+
let { value: t, done: n } = await s.read();
|
|
4643
3719
|
if (n) break;
|
|
4644
|
-
|
|
4645
|
-
let
|
|
4646
|
-
|
|
4647
|
-
for (let t of
|
|
4648
|
-
for (let n of
|
|
3720
|
+
l += c.decode(t, { stream: !0 });
|
|
3721
|
+
let i = Et(l);
|
|
3722
|
+
l = i.remainder;
|
|
3723
|
+
for (let t of i.chunks) if (t.trim()) {
|
|
3724
|
+
for (let n of Tt(t)) {
|
|
4649
3725
|
if (n.eventName === "__ping__") {
|
|
4650
|
-
|
|
3726
|
+
r.getState().updateActivity({
|
|
4651
3727
|
sessionId: e.sessionId,
|
|
4652
3728
|
status: "running",
|
|
4653
3729
|
phase: "正在处理",
|
|
@@ -4656,31 +3732,31 @@ function Or(e) {
|
|
|
4656
3732
|
continue;
|
|
4657
3733
|
}
|
|
4658
3734
|
if (n.eventName === "__done__") {
|
|
4659
|
-
|
|
3735
|
+
o = !0, a = !0;
|
|
4660
3736
|
break;
|
|
4661
3737
|
}
|
|
4662
3738
|
if (!n.data || typeof n.data != "object") continue;
|
|
4663
3739
|
let t = n.data;
|
|
4664
|
-
if (!
|
|
3740
|
+
if (!y()) break;
|
|
4665
3741
|
if (t.InvocationId && t.InvocationId !== e.invocationId) continue;
|
|
4666
|
-
if (
|
|
3742
|
+
if (r.getState().updateActivity({
|
|
4667
3743
|
sessionId: e.sessionId,
|
|
4668
3744
|
status: "running",
|
|
4669
3745
|
phase: "正在处理",
|
|
4670
3746
|
countEvent: !1
|
|
4671
3747
|
}), typeof t.seq == "number") {
|
|
4672
3748
|
try {
|
|
4673
|
-
|
|
3749
|
+
g.current.accept(t);
|
|
4674
3750
|
} catch (e) {
|
|
4675
3751
|
console.error("[SessionLifecycle] session event cursor conflict:", e);
|
|
4676
3752
|
}
|
|
4677
|
-
|
|
3753
|
+
v = Math.max(v, g.current.reconnectAfterSeq()), Q({
|
|
4678
3754
|
type: "stream_event",
|
|
4679
3755
|
sessionId: e.sessionId,
|
|
4680
3756
|
event: t
|
|
4681
|
-
}),
|
|
4682
|
-
let n =
|
|
4683
|
-
n &&
|
|
3757
|
+
}), o ||= P(t), a ||= o;
|
|
3758
|
+
let n = Gn(t);
|
|
3759
|
+
n && r.getState().updateActivity({
|
|
4684
3760
|
sessionId: e.sessionId,
|
|
4685
3761
|
status: n.status,
|
|
4686
3762
|
phase: n.phase,
|
|
@@ -4689,55 +3765,55 @@ function Or(e) {
|
|
|
4689
3765
|
});
|
|
4690
3766
|
continue;
|
|
4691
3767
|
}
|
|
4692
|
-
let
|
|
4693
|
-
Number.isFinite(
|
|
4694
|
-
let
|
|
4695
|
-
if (
|
|
4696
|
-
let t =
|
|
4697
|
-
|
|
3768
|
+
let i = Number(t.SeqId || 0);
|
|
3769
|
+
Number.isFinite(i) && (v = Math.max(v, i));
|
|
3770
|
+
let s = t.Content?.runtime_event;
|
|
3771
|
+
if (m && s?.schema_version === 2 && s.run_id === e.invocationId && _.apply(s)) {
|
|
3772
|
+
let t = _.snapshot();
|
|
3773
|
+
Q({
|
|
4698
3774
|
type: "conversation_snapshot",
|
|
4699
3775
|
sessionId: e.sessionId,
|
|
4700
3776
|
result: {
|
|
4701
3777
|
state: t,
|
|
4702
|
-
presentation:
|
|
3778
|
+
presentation: _e(t, { profile: h }),
|
|
4703
3779
|
runId: e.invocationId,
|
|
4704
|
-
cursor:
|
|
3780
|
+
cursor: v
|
|
4705
3781
|
}
|
|
4706
3782
|
});
|
|
4707
3783
|
}
|
|
4708
|
-
|
|
3784
|
+
Q({
|
|
4709
3785
|
type: "stream_event",
|
|
4710
3786
|
sessionId: e.sessionId,
|
|
4711
3787
|
event: t
|
|
4712
|
-
}),
|
|
4713
|
-
let c =
|
|
4714
|
-
if (c &&
|
|
3788
|
+
}), o ||= P(t), a ||= o;
|
|
3789
|
+
let c = Gn(t);
|
|
3790
|
+
if (c && r.getState().updateActivity({
|
|
4715
3791
|
sessionId: e.sessionId,
|
|
4716
3792
|
status: c.status,
|
|
4717
3793
|
phase: c.phase,
|
|
4718
3794
|
detail: e.invocationId,
|
|
4719
3795
|
countEvent: !1
|
|
4720
|
-
}),
|
|
3796
|
+
}), o) break;
|
|
4721
3797
|
}
|
|
4722
|
-
if (
|
|
3798
|
+
if (o) break;
|
|
4723
3799
|
}
|
|
4724
3800
|
}
|
|
4725
|
-
|
|
3801
|
+
o && s.cancel().catch(() => {});
|
|
4726
3802
|
} catch (n) {
|
|
4727
|
-
if (n instanceof DOMException && n.name === "AbortError" || n instanceof
|
|
4728
|
-
|
|
3803
|
+
if (n instanceof DOMException && n.name === "AbortError" || n instanceof X || t.signal.aborted) {
|
|
3804
|
+
o = !0, s = !0, y() && r.getState().stopSessionActivity(e.sessionId, "恢复事件订阅已取消。");
|
|
4729
3805
|
break;
|
|
4730
3806
|
}
|
|
4731
|
-
if (!
|
|
4732
|
-
if (n instanceof
|
|
4733
|
-
|
|
3807
|
+
if (!y()) break;
|
|
3808
|
+
if (n instanceof Y && n.code >= 400 && n.code < 500 && n.code !== 408 && n.code !== 429) {
|
|
3809
|
+
o = !0, a = !1, Q({
|
|
4734
3810
|
type: "error",
|
|
4735
3811
|
sessionId: e.sessionId,
|
|
4736
3812
|
error: n
|
|
4737
3813
|
});
|
|
4738
3814
|
break;
|
|
4739
3815
|
}
|
|
4740
|
-
console.warn("Run event subscription disconnected; retrying:", n),
|
|
3816
|
+
console.warn("Run event subscription disconnected; retrying:", n), r.getState().updateActivity({
|
|
4741
3817
|
sessionId: e.sessionId,
|
|
4742
3818
|
status: "waiting",
|
|
4743
3819
|
phase: "恢复连接中",
|
|
@@ -4745,178 +3821,188 @@ function Or(e) {
|
|
|
4745
3821
|
countEvent: !1
|
|
4746
3822
|
});
|
|
4747
3823
|
}
|
|
4748
|
-
!
|
|
3824
|
+
!o && y() && await Hn(t.signal);
|
|
4749
3825
|
}
|
|
4750
|
-
|
|
3826
|
+
o && !s && y() && Q({
|
|
4751
3827
|
type: "stream_ended",
|
|
4752
3828
|
sessionId: e.sessionId
|
|
4753
3829
|
});
|
|
4754
3830
|
} catch (e) {
|
|
4755
3831
|
e instanceof DOMException && e.name === "AbortError" || console.error("Failed to subscribe run events:", e);
|
|
4756
3832
|
} finally {
|
|
4757
|
-
let n =
|
|
4758
|
-
n && (
|
|
3833
|
+
let n = p.current === t;
|
|
3834
|
+
n && (p.current = null), n && u.current === e.sessionId && (r.getState().setCurrentRunId(""), r.getState().setActiveInvocationId(""), a && N.current?.(e.sessionId), F.current?.(d.current, e.sessionId));
|
|
4759
3835
|
}
|
|
4760
|
-
}, [n]),
|
|
4761
|
-
if (!
|
|
4762
|
-
|
|
4763
|
-
|
|
3836
|
+
}, [n]), B = K((e) => {
|
|
3837
|
+
if (!f.current.RunLifecycle.Enabled || !e.runId || d.current !== t || u.current !== e.sessionId || p.current || (k.current.get(e.sessionId)?.events || []).some((t) => {
|
|
3838
|
+
let n = t.Content?.runtime_event;
|
|
3839
|
+
return t.InvocationId === e.runId && !n?.parent_scope_id && [
|
|
3840
|
+
"completed",
|
|
3841
|
+
"failed",
|
|
3842
|
+
"error",
|
|
3843
|
+
"cancelled",
|
|
3844
|
+
"canceled",
|
|
3845
|
+
"aborted"
|
|
3846
|
+
].includes(z(t));
|
|
3847
|
+
})) return;
|
|
3848
|
+
let n = r.getState().getSessionActivity(e.sessionId);
|
|
3849
|
+
r.getState().isSessionStreaming(e.sessionId) && n?.source === "run" && [
|
|
4764
3850
|
"connecting",
|
|
4765
3851
|
"running",
|
|
4766
3852
|
"waiting"
|
|
4767
|
-
].includes(n.status) || R({
|
|
3853
|
+
].includes(n.status) && (e.extensions?.mcpAuthorization || f.current.KernelSessionEventsByCommand === !0 && n.runId === e.runId) || R({
|
|
4768
3854
|
sessionId: e.sessionId,
|
|
4769
3855
|
invocationId: e.runId,
|
|
4770
|
-
afterSeqId:
|
|
3856
|
+
afterSeqId: ee(k.current.get(e.sessionId)?.events || [])
|
|
4771
3857
|
});
|
|
4772
|
-
}, [t, R]),
|
|
4773
|
-
if (
|
|
4774
|
-
|
|
4775
|
-
let l =
|
|
4776
|
-
|
|
4777
|
-
let
|
|
4778
|
-
|
|
4779
|
-
let
|
|
4780
|
-
$(E.current, e, t,
|
|
4781
|
-
},
|
|
4782
|
-
|
|
4783
|
-
let
|
|
4784
|
-
|
|
4785
|
-
let
|
|
4786
|
-
|
|
3858
|
+
}, [t, R]), V = K(async (e, t = !1, c) => {
|
|
3859
|
+
if (c?.aborted) return;
|
|
3860
|
+
M.current = null;
|
|
3861
|
+
let l = i.getState(), m = l.agentId === d.current ? l.capabilities : f.current, g = le(m.ConversationSurface, he);
|
|
3862
|
+
D.current.set(e, g);
|
|
3863
|
+
let S = u.current, A = ++_.current;
|
|
3864
|
+
v.current = A, y.current = null;
|
|
3865
|
+
let j = (e, t) => {
|
|
3866
|
+
$(E.current, e, t, u.current, Nn);
|
|
3867
|
+
}, F = E.current.get(e);
|
|
3868
|
+
S && S !== e && (j(S, U.getState().messages), U.getState().setMessages(F || []), h.getState().clearSessionMessageHistory(e), W.getState().setSessionCheckpoints(e, []), W.getState().setSessionToolReceipts(e, []), r.getState().setCurrentRunId(""), r.getState().clearActivity()), u.current = e;
|
|
3869
|
+
let L = () => u.current === e && _.current === A && !c?.aborted;
|
|
3870
|
+
h.getState().setCurrentSessionId(e), h.getState().setSessionInitialMessageHistoryLoading(e, !F);
|
|
3871
|
+
let z = r.getState();
|
|
3872
|
+
z.isSessionStreaming(e) && z.updateActivity({
|
|
4787
3873
|
sessionId: e,
|
|
4788
3874
|
phase: "正在同步任务进展",
|
|
4789
3875
|
countEvent: !1
|
|
4790
|
-
}),
|
|
4791
|
-
let
|
|
4792
|
-
|
|
3876
|
+
}), o();
|
|
3877
|
+
let B = U.getState().messages;
|
|
3878
|
+
p.current?.abort(), a && b.getState().setMobileSidebarOpen(!1);
|
|
4793
3879
|
try {
|
|
4794
3880
|
let t = {
|
|
4795
|
-
limit:
|
|
3881
|
+
limit: jn,
|
|
4796
3882
|
includeReasoning: !0,
|
|
4797
3883
|
includeToolEvents: !0,
|
|
4798
3884
|
includeAttachments: !0,
|
|
4799
|
-
signal:
|
|
4800
|
-
},
|
|
4801
|
-
isCurrent:
|
|
4802
|
-
signal:
|
|
3885
|
+
signal: c
|
|
3886
|
+
}, a = await sn(() => n.listSessionMessages(e, t), {
|
|
3887
|
+
isCurrent: L,
|
|
3888
|
+
signal: c,
|
|
4803
3889
|
onPreparing: () => {
|
|
4804
|
-
let t =
|
|
4805
|
-
|
|
3890
|
+
let t = h.getState().messageHistory[e];
|
|
3891
|
+
h.getState().setSessionMessageHistory(e, {
|
|
4806
3892
|
...t,
|
|
4807
3893
|
nextCursor: t?.nextCursor ?? null,
|
|
4808
3894
|
hasMore: t?.hasMore ?? !1,
|
|
4809
3895
|
preparing: !0,
|
|
4810
3896
|
error: void 0
|
|
4811
|
-
}),
|
|
3897
|
+
}), h.getState().setSessionInitialMessageHistoryLoading(e, !F);
|
|
4812
3898
|
}
|
|
4813
3899
|
});
|
|
4814
|
-
if (!
|
|
4815
|
-
let
|
|
4816
|
-
$(
|
|
4817
|
-
let
|
|
4818
|
-
if (!
|
|
4819
|
-
let t =
|
|
4820
|
-
|
|
3900
|
+
if (!L()) return;
|
|
3901
|
+
let o = Cn(a.Messages);
|
|
3902
|
+
$(O.current, e, o, u.current);
|
|
3903
|
+
let l = o, f = 0, p = [];
|
|
3904
|
+
if (!F) {
|
|
3905
|
+
let t = Se(o, B, U.getState().messages);
|
|
3906
|
+
U.getState().setMessages(t), B = o, j(e, t);
|
|
4821
3907
|
}
|
|
4822
|
-
|
|
4823
|
-
nextCursor:
|
|
4824
|
-
hasMore:
|
|
4825
|
-
...
|
|
4826
|
-
}),
|
|
3908
|
+
h.getState().setSessionMessageHistory(e, {
|
|
3909
|
+
nextCursor: a.NextCursor,
|
|
3910
|
+
hasMore: a.HasMore,
|
|
3911
|
+
...Vn(a)
|
|
3912
|
+
}), h.getState().setSessionInitialMessageHistoryLoading(e, !1);
|
|
4827
3913
|
try {
|
|
4828
3914
|
let t = await n.listSessionEvents(e, {
|
|
4829
3915
|
offset: 0,
|
|
4830
|
-
limit:
|
|
4831
|
-
signal:
|
|
4832
|
-
historyEpoch:
|
|
4833
|
-
snapshotSeqId:
|
|
3916
|
+
limit: Mn,
|
|
3917
|
+
signal: c,
|
|
3918
|
+
historyEpoch: a.CursorSource === "runtime" ? a.HistoryEpoch : void 0,
|
|
3919
|
+
snapshotSeqId: a.CursorSource === "runtime" ? a.SnapshotSeqId : void 0
|
|
4834
3920
|
});
|
|
4835
|
-
if (!
|
|
4836
|
-
let
|
|
4837
|
-
if (
|
|
4838
|
-
let
|
|
4839
|
-
events:
|
|
4840
|
-
loadedCount:
|
|
4841
|
-
total:
|
|
4842
|
-
cursorSource:
|
|
4843
|
-
historyEpoch:
|
|
4844
|
-
snapshotSeqId:
|
|
3921
|
+
if (!L()) return;
|
|
3922
|
+
let r = In(a, t), i = t.Events, s = [...o].reverse().find((e) => e.invocationId && Object.values(e.tools || {}).some((e) => e.name === "call_a2a_agent"))?.invocationId;
|
|
3923
|
+
if (r && m.KernelSessionEventsByCommand === !0 && t.CursorSource === "runtime" && s && (i = await cn(n, e, s, t, L, c), !L())) return;
|
|
3924
|
+
let d = {
|
|
3925
|
+
events: r ? i : [],
|
|
3926
|
+
loadedCount: r ? i.length : 0,
|
|
3927
|
+
total: r ? Math.max(0, Number(t.Total ?? t.Events?.length ?? 0) || 0) : 0,
|
|
3928
|
+
cursorSource: r ? t.CursorSource : void 0,
|
|
3929
|
+
historyEpoch: r ? t.HistoryEpoch : void 0,
|
|
3930
|
+
snapshotSeqId: r ? t.SnapshotSeqId : void 0
|
|
4845
3931
|
};
|
|
4846
|
-
if ($(
|
|
4847
|
-
nextCursor:
|
|
4848
|
-
hasMore: !!(
|
|
4849
|
-
}),
|
|
4850
|
-
|
|
4851
|
-
for (let t of
|
|
4852
|
-
let t =
|
|
4853
|
-
p = t.canonicalRunIds,
|
|
3932
|
+
if ($(k.current, e, d, u.current), h.getState().setSessionMessageHistory(e, {
|
|
3933
|
+
nextCursor: a.NextCursor,
|
|
3934
|
+
hasMore: !!(a.HasMore || d.loadedCount < d.total)
|
|
3935
|
+
}), d.events.length > 0) {
|
|
3936
|
+
f = ee(d.events);
|
|
3937
|
+
for (let t of d.events) x(t, e);
|
|
3938
|
+
let t = Ee(o, d.events, e, g);
|
|
3939
|
+
p = t.canonicalRunIds, l = t.messages;
|
|
4854
3940
|
}
|
|
4855
|
-
if (
|
|
4856
|
-
let
|
|
4857
|
-
if (!
|
|
4858
|
-
for (let t of
|
|
4859
|
-
|
|
4860
|
-
generation:
|
|
3941
|
+
if (r) {
|
|
3942
|
+
let r = await fn(n, e, o, t, L, c);
|
|
3943
|
+
if (!L()) return;
|
|
3944
|
+
for (let t of r.events) x(t, e);
|
|
3945
|
+
r.incomplete && (y.current = {
|
|
3946
|
+
generation: A,
|
|
4861
3947
|
message: "部分交互历史尚未恢复完整,旧卡片保持只读。请加载较早消息后重试。"
|
|
4862
|
-
},
|
|
4863
|
-
...
|
|
4864
|
-
nextCursor:
|
|
4865
|
-
hasMore: !!(
|
|
3948
|
+
}, h.getState().setSessionMessageHistory(e, {
|
|
3949
|
+
...h.getState().messageHistory[e],
|
|
3950
|
+
nextCursor: a.NextCursor,
|
|
3951
|
+
hasMore: !!(a.HasMore || d.loadedCount < d.total),
|
|
4866
3952
|
error: "部分交互历史尚未恢复完整,旧卡片保持只读。请加载较早消息后重试。"
|
|
4867
3953
|
}));
|
|
4868
3954
|
}
|
|
4869
3955
|
} catch (e) {
|
|
4870
|
-
if (
|
|
4871
|
-
|
|
4872
|
-
generation:
|
|
3956
|
+
if (zn(e)) throw e;
|
|
3957
|
+
L() && (y.current = {
|
|
3958
|
+
generation: A,
|
|
4873
3959
|
message: "完整事件历史读取失败,请刷新会话后重新查找。当前结果只包含已读取的正文。"
|
|
4874
3960
|
}), console.warn("[SessionLifecycle] canonical history replay failed:", e);
|
|
4875
3961
|
}
|
|
4876
|
-
if (!
|
|
4877
|
-
|
|
4878
|
-
let
|
|
4879
|
-
if (
|
|
4880
|
-
agentId:
|
|
3962
|
+
if (!L()) return;
|
|
3963
|
+
C(l, e), $(w.current, e, new Set(p), u.current), $(T.current, e, l, u.current), l = Se(l, B, U.getState().messages), U.getState().setMessages(l), j(e, l), v.current = null, I(d.current, e, l);
|
|
3964
|
+
let _ = Math.max(a.LatestSeqId || 0, f), b = i.getState().capabilities || s;
|
|
3965
|
+
if (b.RunLifecycle.Enabled && b.RunLifecycle.Checkpoints ? (n.listSessionCheckpoints({
|
|
3966
|
+
agentId: d.current,
|
|
4881
3967
|
sessionId: e
|
|
4882
3968
|
}).then((t) => {
|
|
4883
|
-
|
|
3969
|
+
L() && W.getState().setSessionCheckpoints(e, t.Checkpoints || []);
|
|
4884
3970
|
}).catch((t) => {
|
|
4885
|
-
|
|
3971
|
+
L() && (console.warn("[SessionLifecycle] checkpoint load failed:", t), W.getState().setSessionCheckpoints(e, []));
|
|
4886
3972
|
}), n.listToolReceipts({
|
|
4887
|
-
agentId:
|
|
3973
|
+
agentId: d.current,
|
|
4888
3974
|
sessionId: e
|
|
4889
3975
|
}).then((t) => {
|
|
4890
|
-
|
|
3976
|
+
L() && W.getState().setSessionToolReceipts(e, t.ToolReceipts || []);
|
|
4891
3977
|
}).catch((t) => {
|
|
4892
|
-
|
|
4893
|
-
})) :
|
|
3978
|
+
L() && (console.warn("[SessionLifecycle] tool receipt load failed:", t), W.getState().setSessionToolReceipts(e, []));
|
|
3979
|
+
})) : W.getState().clearSessionCheckpoints(e), b.RunLifecycle.Enabled && b.RunLifecycle.Resume) try {
|
|
4894
3980
|
let t = await n.getSession(e);
|
|
4895
|
-
if (!
|
|
4896
|
-
let
|
|
4897
|
-
if (t.ActiveInvocationId && (
|
|
4898
|
-
let n =
|
|
3981
|
+
if (!L()) return;
|
|
3982
|
+
let i = String(t.ActiveRunStatus || "").toLowerCase();
|
|
3983
|
+
if (t.ActiveInvocationId && (Un.has(i) || i === "" && Wn(t))) {
|
|
3984
|
+
let n = r.getState().getSessionActivity(e), i = m.KernelSessionEventsByCommand === !0 && r.getState().isSessionStreaming(e) && n?.source === "run" && n.runId === t.ActiveInvocationId && [
|
|
4899
3985
|
"connecting",
|
|
4900
3986
|
"running",
|
|
4901
3987
|
"waiting"
|
|
4902
3988
|
].includes(n.status);
|
|
4903
|
-
|
|
3989
|
+
i && r.getState().updateActivity({
|
|
4904
3990
|
sessionId: e,
|
|
4905
3991
|
phase: "正在处理",
|
|
4906
3992
|
countEvent: !1
|
|
4907
|
-
}),
|
|
3993
|
+
}), i || R({
|
|
4908
3994
|
sessionId: e,
|
|
4909
3995
|
invocationId: t.ActiveInvocationId,
|
|
4910
|
-
afterSeqId:
|
|
3996
|
+
afterSeqId: _
|
|
4911
3997
|
});
|
|
4912
3998
|
} else {
|
|
4913
|
-
let n =
|
|
3999
|
+
let n = r.getState(), a = n.getSessionActivity(e), o = t.ActiveInvocationId && a?.runId === t.ActiveInvocationId ? Gn({
|
|
4914
4000
|
EventType: "run_status",
|
|
4915
|
-
Content: { status:
|
|
4916
|
-
}) : null,
|
|
4001
|
+
Content: { status: i }
|
|
4002
|
+
}) : null, s = a?.runId ? [...k.current.get(e)?.events || []].reverse().find((e) => {
|
|
4917
4003
|
let t = e.Content?.runtime_event;
|
|
4918
|
-
return e.InvocationId ===
|
|
4919
|
-
}) : void 0, c =
|
|
4004
|
+
return e.InvocationId === a.runId && !t?.parent_scope_id && P(e);
|
|
4005
|
+
}) : void 0, c = o || s && Gn(s);
|
|
4920
4006
|
c && (n.setSessionStreaming(e, !1), n.updateActivity({
|
|
4921
4007
|
sessionId: e,
|
|
4922
4008
|
...c,
|
|
@@ -4924,8 +4010,8 @@ function Or(e) {
|
|
|
4924
4010
|
}));
|
|
4925
4011
|
}
|
|
4926
4012
|
} catch (t) {
|
|
4927
|
-
if (console.warn("[SessionLifecycle] getSession for reconnect failed:", t),
|
|
4928
|
-
let t =
|
|
4013
|
+
if (console.warn("[SessionLifecycle] getSession for reconnect failed:", t), L()) {
|
|
4014
|
+
let t = r.getState();
|
|
4929
4015
|
t.isSessionStreaming(e) && t.getSessionActivity(e)?.phase === "正在同步任务进展" && t.updateActivity({
|
|
4930
4016
|
sessionId: e,
|
|
4931
4017
|
phase: "正在确认任务状态",
|
|
@@ -4934,8 +4020,8 @@ function Or(e) {
|
|
|
4934
4020
|
}
|
|
4935
4021
|
}
|
|
4936
4022
|
} catch (n) {
|
|
4937
|
-
if (
|
|
4938
|
-
|
|
4023
|
+
if (zn(n) && !t && L()) {
|
|
4024
|
+
h.getState().setSessionMessageHistory(e, {
|
|
4939
4025
|
nextCursor: null,
|
|
4940
4026
|
hasMore: !1,
|
|
4941
4027
|
cursorSource: void 0,
|
|
@@ -4946,18 +4032,18 @@ function Or(e) {
|
|
|
4946
4032
|
cursorCompatibleWithRuntime: void 0,
|
|
4947
4033
|
sessionContractVersion: void 0
|
|
4948
4034
|
}), queueMicrotask(() => {
|
|
4949
|
-
|
|
4035
|
+
L() && N.current?.(e, !0);
|
|
4950
4036
|
});
|
|
4951
4037
|
return;
|
|
4952
4038
|
}
|
|
4953
|
-
if (
|
|
4954
|
-
let r = t ? "历史来源已变化,重新加载失败。原有消息已保留,请手动刷新会话。" :
|
|
4039
|
+
if (L() && !(n instanceof X)) {
|
|
4040
|
+
let r = t ? "历史来源已变化,重新加载失败。原有消息已保留,请手动刷新会话。" : on(n) ? "历史仍在准备,请稍后重试。" : "会话历史读取失败,请重试。已有消息已保留。";
|
|
4955
4041
|
y.current = {
|
|
4956
|
-
generation:
|
|
4042
|
+
generation: A,
|
|
4957
4043
|
message: r
|
|
4958
4044
|
};
|
|
4959
|
-
let i =
|
|
4960
|
-
|
|
4045
|
+
let i = h.getState().messageHistory[e];
|
|
4046
|
+
h.getState().setSessionMessageHistory(e, {
|
|
4961
4047
|
...i,
|
|
4962
4048
|
nextCursor: i?.nextCursor ?? null,
|
|
4963
4049
|
hasMore: i?.hasMore ?? !1,
|
|
@@ -4970,147 +4056,147 @@ function Or(e) {
|
|
|
4970
4056
|
} : {},
|
|
4971
4057
|
preparing: !1,
|
|
4972
4058
|
error: r
|
|
4973
|
-
}), t &&
|
|
4059
|
+
}), t && b.getState().pushToast(r, "error");
|
|
4974
4060
|
}
|
|
4975
|
-
n instanceof
|
|
4061
|
+
n instanceof X || console.error("Failed to load session messages:", n);
|
|
4976
4062
|
} finally {
|
|
4977
|
-
|
|
4063
|
+
v.current === A && (v.current = null), L() && h.getState().setSessionInitialMessageHistoryLoading(e, !1);
|
|
4978
4064
|
}
|
|
4979
4065
|
}, [
|
|
4980
4066
|
n,
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4067
|
+
a,
|
|
4068
|
+
I,
|
|
4069
|
+
o,
|
|
4984
4070
|
R,
|
|
4985
|
-
|
|
4986
|
-
]),
|
|
4987
|
-
let r =
|
|
4071
|
+
s
|
|
4072
|
+
]), H = K(async (e = "default-agent", t = null) => {
|
|
4073
|
+
let r = h.getState();
|
|
4988
4074
|
r.sessionsAgentId && r.sessionsAgentId !== e && r.resetSessionPagination(e);
|
|
4989
|
-
let
|
|
4075
|
+
let a = h.getState().sessionsGeneration, o = () => i.getState().agentId === e && h.getState().sessionsGeneration === a;
|
|
4990
4076
|
try {
|
|
4991
|
-
|
|
4077
|
+
h.getState().setLoadingSessions(!0);
|
|
4992
4078
|
let r = await n.listSessions(e, {
|
|
4993
4079
|
page: 1,
|
|
4994
|
-
pageSize:
|
|
4080
|
+
pageSize: An
|
|
4995
4081
|
});
|
|
4996
|
-
if (!
|
|
4082
|
+
if (!o()) return;
|
|
4997
4083
|
let i = r.Sessions || [];
|
|
4998
|
-
for (let e of i)
|
|
4999
|
-
let
|
|
5000
|
-
if (
|
|
4084
|
+
for (let e of i) A.current.delete(e.SessionId);
|
|
4085
|
+
let a = new Set(Array.from(A.current.entries()).filter(([, t]) => t === e).map(([e]) => e)), s = tt(i, h.getState().sessions, a);
|
|
4086
|
+
if (h.getState().upsertSessions(s, {
|
|
5001
4087
|
agentId: e,
|
|
5002
4088
|
total: Number(r.Total ?? r.Sessions?.length ?? 0),
|
|
5003
4089
|
page: Number(r.Page ?? 1),
|
|
5004
|
-
pageSize: Number(r.PageSize ??
|
|
4090
|
+
pageSize: Number(r.PageSize ?? An),
|
|
5005
4091
|
replace: !0
|
|
5006
|
-
}),
|
|
5007
|
-
let c =
|
|
5008
|
-
f && f !==
|
|
4092
|
+
}), j.current || M.current === e) return;
|
|
4093
|
+
let c = h.getState().sessions, d = u.current, f = d || (l ? et(c, t || Qe(e)) : null);
|
|
4094
|
+
f && f !== d && V(f);
|
|
5009
4095
|
} catch (e) {
|
|
5010
|
-
if (e instanceof
|
|
4096
|
+
if (e instanceof X) return;
|
|
5011
4097
|
console.error("Failed to fetch sessions:", e);
|
|
5012
4098
|
} finally {
|
|
5013
|
-
|
|
4099
|
+
o() && h.getState().setLoadingSessions(!1);
|
|
5014
4100
|
}
|
|
5015
4101
|
}, [
|
|
5016
4102
|
n,
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
]),
|
|
5020
|
-
let e =
|
|
4103
|
+
V,
|
|
4104
|
+
l
|
|
4105
|
+
]), ne = K(async () => {
|
|
4106
|
+
let e = h.getState();
|
|
5021
4107
|
if (e.isLoadingSessions || !e.hasMoreSessions) return;
|
|
5022
|
-
let t =
|
|
4108
|
+
let t = m({
|
|
5023
4109
|
total: e.sessionsTotal,
|
|
5024
|
-
pageSize: e.sessionsPageSize ||
|
|
4110
|
+
pageSize: e.sessionsPageSize || An,
|
|
5025
4111
|
loadedPages: e.loadedPages
|
|
5026
4112
|
});
|
|
5027
4113
|
if (!t) return;
|
|
5028
|
-
let r = e.sessionsPageSize ||
|
|
4114
|
+
let r = e.sessionsPageSize || An, a = e.sessionsAgentId || d.current || "default-agent", o = () => i.getState().agentId === a && h.getState().sessionsGeneration === e.sessionsGeneration;
|
|
5029
4115
|
try {
|
|
5030
|
-
|
|
5031
|
-
let
|
|
4116
|
+
h.getState().setLoadingSessions(!0);
|
|
4117
|
+
let i = await n.listSessions(a, {
|
|
5032
4118
|
page: t,
|
|
5033
4119
|
pageSize: r
|
|
5034
4120
|
});
|
|
5035
|
-
if (!
|
|
5036
|
-
|
|
5037
|
-
agentId:
|
|
5038
|
-
total: Number(
|
|
5039
|
-
page: Number(
|
|
5040
|
-
pageSize: Number(
|
|
4121
|
+
if (!o()) return;
|
|
4122
|
+
h.getState().upsertSessions(i.Sessions || [], {
|
|
4123
|
+
agentId: a,
|
|
4124
|
+
total: Number(i.Total ?? e.sessionsTotal),
|
|
4125
|
+
page: Number(i.Page ?? t),
|
|
4126
|
+
pageSize: Number(i.PageSize ?? r)
|
|
5041
4127
|
});
|
|
5042
4128
|
} catch (e) {
|
|
5043
|
-
if (e instanceof
|
|
4129
|
+
if (e instanceof X) return;
|
|
5044
4130
|
console.error("Failed to load more sessions:", e);
|
|
5045
4131
|
} finally {
|
|
5046
|
-
|
|
4132
|
+
o() && h.getState().setLoadingSessions(!1);
|
|
5047
4133
|
}
|
|
5048
4134
|
}, [n]);
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
}, [
|
|
5052
|
-
|
|
5053
|
-
}, [
|
|
5054
|
-
let
|
|
5055
|
-
if (
|
|
5056
|
-
|
|
4135
|
+
q(() => {
|
|
4136
|
+
N.current = V;
|
|
4137
|
+
}, [V]), q(() => {
|
|
4138
|
+
F.current = H;
|
|
4139
|
+
}, [H]);
|
|
4140
|
+
let re = K((e, t = !1) => {
|
|
4141
|
+
if (M.current = null, t && u.current === e) {
|
|
4142
|
+
h.getState().upsertSessions([{
|
|
5057
4143
|
SessionId: e,
|
|
5058
4144
|
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5059
4145
|
}]);
|
|
5060
4146
|
return;
|
|
5061
4147
|
}
|
|
5062
|
-
|
|
4148
|
+
_.current += 1, p.current?.abort(), A.current.set(e, d.current), h.getState().upsertSessions([{
|
|
5063
4149
|
SessionId: e,
|
|
5064
4150
|
UpdatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5065
|
-
}]),
|
|
5066
|
-
}, [
|
|
5067
|
-
|
|
5068
|
-
}, [
|
|
5069
|
-
if (
|
|
5070
|
-
await
|
|
4151
|
+
}]), u.current = e, h.getState().setCurrentSessionId(e), t || (U.getState().setMessages([]), r.getState().setCurrentRunId(""), r.getState().clearActivity()), h.getState().clearSessionMessageHistory(e), W.getState().setSessionCheckpoints(e, []), W.getState().setSessionToolReceipts(e, []), a && (b.getState().setMobileSidebarOpen(!1), b.getState().setMobileActionsOpen(!1));
|
|
4152
|
+
}, [a]), ie = K(() => {
|
|
4153
|
+
M.current = d.current, _.current += 1, p.current?.abort(), u.current = null, h.getState().setCurrentSessionId(null), U.getState().setMessages([]), r.getState().setCurrentRunId(""), r.getState().clearActivity(), a && b.getState().setMobileSidebarOpen(!1);
|
|
4154
|
+
}, [a]), oe = K(async () => {
|
|
4155
|
+
if (j.current) {
|
|
4156
|
+
await j.current;
|
|
5071
4157
|
return;
|
|
5072
4158
|
}
|
|
5073
|
-
|
|
4159
|
+
_.current += 1, p.current?.abort(), u.current = null, h.getState().setCurrentSessionId(null), U.getState().setMessages([]);
|
|
5074
4160
|
let e = n.createSession(t).then((e) => {
|
|
5075
4161
|
let n = e.SessionId || null;
|
|
5076
|
-
return n &&
|
|
5077
|
-
}).catch((e) => (e instanceof
|
|
5078
|
-
|
|
4162
|
+
return n && i.getState().agentId === t && re(n, U.getState().messages.some((e) => e.eventType === "optimistic_user_message" || e.eventType === "optimistic_assistant_placeholder")), n;
|
|
4163
|
+
}).catch((e) => (e instanceof X || console.error("Failed to create session:", e), null));
|
|
4164
|
+
j.current = e;
|
|
5079
4165
|
try {
|
|
5080
4166
|
await e;
|
|
5081
4167
|
} finally {
|
|
5082
|
-
|
|
4168
|
+
j.current === e && (j.current = null);
|
|
5083
4169
|
}
|
|
5084
4170
|
}, [
|
|
5085
|
-
|
|
4171
|
+
re,
|
|
5086
4172
|
t,
|
|
5087
4173
|
n
|
|
5088
|
-
]),
|
|
5089
|
-
let e =
|
|
5090
|
-
return e ? await e :
|
|
5091
|
-
}, []),
|
|
4174
|
+
]), se = K(async () => {
|
|
4175
|
+
let e = j.current;
|
|
4176
|
+
return e ? await e : u.current;
|
|
4177
|
+
}, []), ce = K(async (e) => {
|
|
5092
4178
|
try {
|
|
5093
|
-
let
|
|
5094
|
-
return
|
|
4179
|
+
let a = await n.deleteSession(e);
|
|
4180
|
+
return i.getState().agentId === t ? a.Deleted === !1 ? (b.getState().pushToast("会话暂未删除,云端运行时仍在同步,请稍后重试。", "error"), H(t, u.current ?? void 0), !1) : (h.getState().removeSession(e), h.getState().clearSessionMessageHistory(e), E.current.delete(e), O.current.delete(e), D.current.delete(e), k.current.delete(e), w.current.delete(e), T.current.delete(e), A.current.delete(e), u.current === e && (_.current += 1, p.current?.abort(), c?.(), u.current = null, U.getState().setMessages([]), W.getState().clearSessionCheckpoints(e), h.getState().setCurrentSessionId(null), r.getState().setCurrentRunId(""), r.getState().clearActivity(), H(t)), !0) : a.Deleted !== !1;
|
|
5095
4181
|
} catch (e) {
|
|
5096
|
-
return e instanceof
|
|
4182
|
+
return e instanceof X ? !1 : (console.error("Failed to delete session", e), b.getState().pushToast("删除会话失败,请稍后重试。", "error"), !1);
|
|
5097
4183
|
}
|
|
5098
4184
|
}, [
|
|
5099
4185
|
t,
|
|
5100
4186
|
n,
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
]),
|
|
4187
|
+
c,
|
|
4188
|
+
H
|
|
4189
|
+
]), ue = K(async (e, t) => {
|
|
5104
4190
|
t?.throwIfAborted();
|
|
5105
|
-
let r =
|
|
4191
|
+
let r = h.getState().messageHistory[e], i = k.current.get(e), a = !!(r?.hasMore && r.nextCursor !== null), o = !!(i && i.loadedCount < i.total);
|
|
5106
4192
|
if (!r || r.isLoadingOlder || !a && !o) return;
|
|
5107
|
-
let s =
|
|
5108
|
-
|
|
5109
|
-
let
|
|
5110
|
-
isCurrent:
|
|
4193
|
+
let s = _.current, c = T.current.get(e) || U.getState().messages, l = Symbol(e);
|
|
4194
|
+
S.current.set(e, l);
|
|
4195
|
+
let f = () => u.current === e && _.current === s && S.current.get(e) === l && !t?.aborted, p = {
|
|
4196
|
+
isCurrent: f,
|
|
5111
4197
|
signal: t,
|
|
5112
4198
|
onPreparing: () => {
|
|
5113
|
-
|
|
4199
|
+
h.getState().setSessionMessageHistory(e, {
|
|
5114
4200
|
...r,
|
|
5115
4201
|
preparing: !0,
|
|
5116
4202
|
error: void 0,
|
|
@@ -5119,97 +4205,97 @@ function Or(e) {
|
|
|
5119
4205
|
}
|
|
5120
4206
|
};
|
|
5121
4207
|
try {
|
|
5122
|
-
|
|
5123
|
-
let [m,
|
|
4208
|
+
h.getState().setSessionMessageHistoryLoading(e, !0);
|
|
4209
|
+
let [m, g] = await Promise.allSettled([a ? sn(() => n.listSessionMessages(e, {
|
|
5124
4210
|
signal: t,
|
|
5125
4211
|
beforeSeqId: r.nextCursor ?? void 0,
|
|
5126
4212
|
cursorSource: r.cursorSource,
|
|
5127
4213
|
historyEpoch: r.historyEpoch,
|
|
5128
4214
|
snapshotSeqId: r.snapshotSeqId,
|
|
5129
|
-
limit:
|
|
4215
|
+
limit: jn,
|
|
5130
4216
|
includeReasoning: !0,
|
|
5131
4217
|
includeToolEvents: !0,
|
|
5132
4218
|
includeAttachments: !0
|
|
5133
|
-
}), p) : Promise.resolve(null), o && i ?
|
|
4219
|
+
}), p) : Promise.resolve(null), o && i ? sn(() => n.listSessionEvents(e, {
|
|
5134
4220
|
signal: t,
|
|
5135
4221
|
offset: i.loadedCount,
|
|
5136
|
-
limit:
|
|
4222
|
+
limit: Mn,
|
|
5137
4223
|
cursorSource: i.cursorSource,
|
|
5138
4224
|
historyEpoch: i.historyEpoch,
|
|
5139
4225
|
snapshotSeqId: i.snapshotSeqId
|
|
5140
4226
|
}), p) : Promise.resolve(null)]);
|
|
5141
|
-
if (t?.throwIfAborted(),
|
|
5142
|
-
let
|
|
4227
|
+
if (t?.throwIfAborted(), u.current !== e || _.current !== s || S.current.get(e) !== l) return;
|
|
4228
|
+
let v = g.status === "rejected" && g.reason instanceof Y && [
|
|
5143
4229
|
429,
|
|
5144
4230
|
502,
|
|
5145
4231
|
503,
|
|
5146
4232
|
504
|
|
5147
|
-
].includes(
|
|
5148
|
-
if (
|
|
4233
|
+
].includes(g.reason.code);
|
|
4234
|
+
if (g.status === "rejected" && !v) throw g.reason;
|
|
5149
4235
|
if (m.status === "rejected") throw m.reason;
|
|
5150
|
-
let
|
|
5151
|
-
if (
|
|
4236
|
+
let b = m.value, A = g.status === "fulfilled" ? g.value : null, j = v ? "消息正文已加载,部分事件详情暂时读取失败,请重试加载更早记录。" : void 0;
|
|
4237
|
+
if (b && !In({
|
|
5152
4238
|
CursorSource: r.cursorSource,
|
|
5153
4239
|
HistoryEpoch: r.historyEpoch,
|
|
5154
4240
|
SnapshotSeqId: r.snapshotSeqId,
|
|
5155
4241
|
CursorCompatibleWithRuntime: r.cursorCompatibleWithRuntime
|
|
5156
|
-
},
|
|
5157
|
-
|
|
4242
|
+
}, b) || A && i && !In(Ln(i), A)) throw Bn();
|
|
4243
|
+
j ? y.current = {
|
|
5158
4244
|
generation: s,
|
|
5159
|
-
message:
|
|
5160
|
-
} :
|
|
5161
|
-
let
|
|
5162
|
-
$(
|
|
5163
|
-
let
|
|
5164
|
-
if (
|
|
5165
|
-
let t =
|
|
5166
|
-
|
|
5167
|
-
events:
|
|
5168
|
-
loadedCount:
|
|
5169
|
-
total:
|
|
5170
|
-
cursorSource:
|
|
5171
|
-
historyEpoch:
|
|
5172
|
-
snapshotSeqId:
|
|
5173
|
-
},
|
|
5174
|
-
for (let n of t)
|
|
4245
|
+
message: j
|
|
4246
|
+
} : A && (y.current = null);
|
|
4247
|
+
let M = b ? Cn(b.Messages) : [], ee = new Set(M.map((e) => e.id)), N = [...M, ...(O.current.get(e) || []).filter((e) => !ee.has(e.id))];
|
|
4248
|
+
$(O.current, e, N, u.current);
|
|
4249
|
+
let P = i?.events || [], F = i?.loadedCount || 0, R = i?.total || 0;
|
|
4250
|
+
if (A) {
|
|
4251
|
+
let t = A.Events || [];
|
|
4252
|
+
P = L(t, P), R = Math.max(R, Number(A.Total ?? 0) || 0), F = t.length > 0 ? Math.min(R, F + t.length) : R, $(k.current, e, {
|
|
4253
|
+
events: P,
|
|
4254
|
+
loadedCount: F,
|
|
4255
|
+
total: R,
|
|
4256
|
+
cursorSource: A.CursorSource ?? i?.cursorSource,
|
|
4257
|
+
historyEpoch: A.HistoryEpoch ?? i?.historyEpoch,
|
|
4258
|
+
snapshotSeqId: A.SnapshotSeqId ?? i?.snapshotSeqId
|
|
4259
|
+
}, u.current);
|
|
4260
|
+
for (let n of t) x(n, e);
|
|
5175
4261
|
}
|
|
5176
|
-
if (
|
|
5177
|
-
let r = await
|
|
5178
|
-
Events:
|
|
4262
|
+
if (M.length && i) {
|
|
4263
|
+
let r = await fn(n, e, M, {
|
|
4264
|
+
Events: P,
|
|
5179
4265
|
CursorSource: i.cursorSource,
|
|
5180
4266
|
HistoryEpoch: i.historyEpoch,
|
|
5181
4267
|
SnapshotSeqId: i.snapshotSeqId
|
|
5182
|
-
},
|
|
5183
|
-
if (!
|
|
5184
|
-
for (let t of r.events)
|
|
5185
|
-
r.incomplete && (
|
|
4268
|
+
}, f, t);
|
|
4269
|
+
if (!f()) return;
|
|
4270
|
+
for (let t of r.events) x(t, e);
|
|
4271
|
+
r.incomplete && (j = "部分交互历史尚未恢复完整,旧卡片保持只读。请加载较早消息后重试。", y.current = {
|
|
5186
4272
|
generation: s,
|
|
5187
|
-
message:
|
|
4273
|
+
message: j
|
|
5188
4274
|
});
|
|
5189
4275
|
}
|
|
5190
|
-
let
|
|
5191
|
-
|
|
5192
|
-
let
|
|
5193
|
-
$(
|
|
5194
|
-
nextCursor:
|
|
5195
|
-
hasMore: !!(
|
|
5196
|
-
...
|
|
5197
|
-
...
|
|
5198
|
-
dataSource:
|
|
5199
|
-
degraded:
|
|
5200
|
-
cursorSource:
|
|
5201
|
-
cursorCompatibleWithRuntime:
|
|
5202
|
-
sessionContractVersion:
|
|
5203
|
-
historyEpoch:
|
|
5204
|
-
persistenceDegraded:
|
|
5205
|
-
snapshotSeqId:
|
|
4276
|
+
let z = Ee(N, P, e, D.current.get(e) || "flat-v1");
|
|
4277
|
+
C(z.messages, e), $(T.current, e, z.messages, u.current);
|
|
4278
|
+
let B = Se(z.messages, c, U.getState().messages);
|
|
4279
|
+
$(w.current, e, new Set(z.canonicalRunIds), u.current), U.getState().setMessages(B), $(E.current, e, B, u.current, Nn), h.getState().setSessionMessageHistory(e, {
|
|
4280
|
+
nextCursor: b ? b.NextCursor : r.nextCursor,
|
|
4281
|
+
hasMore: !!(b && b.HasMore || F < R),
|
|
4282
|
+
...b ? Vn(b) : {},
|
|
4283
|
+
...b ? {
|
|
4284
|
+
dataSource: b.DataSource ?? r.dataSource,
|
|
4285
|
+
degraded: b.Degraded ?? r.degraded,
|
|
4286
|
+
cursorSource: b.CursorSource ?? r.cursorSource,
|
|
4287
|
+
cursorCompatibleWithRuntime: b.CursorCompatibleWithRuntime ?? r.cursorCompatibleWithRuntime,
|
|
4288
|
+
sessionContractVersion: b.SessionContractVersion ?? r.sessionContractVersion,
|
|
4289
|
+
historyEpoch: b.HistoryEpoch ?? r.historyEpoch,
|
|
4290
|
+
persistenceDegraded: b.PersistenceDegraded ?? r.persistenceDegraded,
|
|
4291
|
+
snapshotSeqId: b.SnapshotSeqId ?? r.snapshotSeqId
|
|
5206
4292
|
} : {},
|
|
5207
4293
|
preparing: !1,
|
|
5208
|
-
error:
|
|
5209
|
-
}),
|
|
4294
|
+
error: j
|
|
4295
|
+
}), I(d.current, e, M);
|
|
5210
4296
|
} catch (n) {
|
|
5211
|
-
if (
|
|
5212
|
-
|
|
4297
|
+
if (zn(n) && u.current === e && _.current === s && S.current.get(e) === l && !t?.aborted) {
|
|
4298
|
+
h.getState().setSessionMessageHistory(e, {
|
|
5213
4299
|
nextCursor: null,
|
|
5214
4300
|
hasMore: !1,
|
|
5215
4301
|
cursorSource: void 0,
|
|
@@ -5221,62 +4307,62 @@ function Or(e) {
|
|
|
5221
4307
|
sessionContractVersion: void 0,
|
|
5222
4308
|
persistenceDegraded: void 0,
|
|
5223
4309
|
error: void 0
|
|
5224
|
-
}), await
|
|
4310
|
+
}), await V(e, !0, t);
|
|
5225
4311
|
return;
|
|
5226
4312
|
}
|
|
5227
|
-
if (
|
|
4313
|
+
if (f() && !(n instanceof X) && h.getState().setSessionMessageHistory(e, {
|
|
5228
4314
|
...r,
|
|
5229
4315
|
preparing: !1,
|
|
5230
4316
|
error: n instanceof Error ? n.message : "历史加载失败,请重试"
|
|
5231
4317
|
}), t) throw n;
|
|
5232
|
-
n instanceof
|
|
4318
|
+
n instanceof X || console.error("Failed to load older session messages:", n);
|
|
5233
4319
|
} finally {
|
|
5234
|
-
if (
|
|
5235
|
-
let t =
|
|
5236
|
-
|
|
4320
|
+
if (S.current.get(e) === l) if (S.current.delete(e), _.current === s) {
|
|
4321
|
+
let t = h.getState().messageHistory[e];
|
|
4322
|
+
h.getState().setSessionMessageHistory(e, {
|
|
5237
4323
|
...t,
|
|
5238
4324
|
nextCursor: t?.nextCursor ?? null,
|
|
5239
4325
|
hasMore: t?.hasMore ?? !1,
|
|
5240
4326
|
preparing: !1,
|
|
5241
4327
|
isLoadingOlder: !1
|
|
5242
4328
|
});
|
|
5243
|
-
} else
|
|
4329
|
+
} else h.getState().setSessionMessageHistoryLoading(e, !1);
|
|
5244
4330
|
}
|
|
5245
4331
|
}, [
|
|
5246
4332
|
n,
|
|
5247
|
-
|
|
5248
|
-
|
|
4333
|
+
I,
|
|
4334
|
+
V
|
|
5249
4335
|
]);
|
|
5250
4336
|
return {
|
|
5251
|
-
historySearchSnapshot:
|
|
5252
|
-
let e =
|
|
4337
|
+
historySearchSnapshot: K(() => {
|
|
4338
|
+
let e = u.current || "", t = h.getState().messageHistory[e], n = k.current.get(e);
|
|
5253
4339
|
return {
|
|
5254
4340
|
owner: JSON.stringify([
|
|
5255
|
-
|
|
4341
|
+
d.current,
|
|
5256
4342
|
e,
|
|
5257
|
-
|
|
4343
|
+
_.current
|
|
5258
4344
|
]),
|
|
5259
|
-
messages:
|
|
4345
|
+
messages: U.getState().messages,
|
|
5260
4346
|
hasMore: !!t?.hasMore,
|
|
5261
|
-
loading: !!(
|
|
4347
|
+
loading: !!(v.current === _.current || h.getState().isLoadingSessions || t?.isLoadingInitial || t?.isLoadingOlder),
|
|
5262
4348
|
checkpoint: `${t?.nextCursor}:${n?.loadedCount}`,
|
|
5263
|
-
error: y.current?.generation ===
|
|
4349
|
+
error: y.current?.generation === _.current ? y.current.message : void 0
|
|
5264
4350
|
};
|
|
5265
4351
|
}, []),
|
|
5266
|
-
followAcceptedInteraction:
|
|
5267
|
-
fetchSessions:
|
|
5268
|
-
loadMoreSessions:
|
|
5269
|
-
loadSession:
|
|
5270
|
-
loadOlderSessionMessages:
|
|
5271
|
-
createNewSession:
|
|
5272
|
-
startNewConversation:
|
|
5273
|
-
adoptCreatedSession:
|
|
5274
|
-
waitForPendingSessionCreation:
|
|
5275
|
-
deleteSession:
|
|
5276
|
-
currentSessionIdRef:
|
|
5277
|
-
agentIdRef:
|
|
5278
|
-
runSubscriptionAbortRef:
|
|
4352
|
+
followAcceptedInteraction: B,
|
|
4353
|
+
fetchSessions: H,
|
|
4354
|
+
loadMoreSessions: ne,
|
|
4355
|
+
loadSession: V,
|
|
4356
|
+
loadOlderSessionMessages: ue,
|
|
4357
|
+
createNewSession: oe,
|
|
4358
|
+
startNewConversation: ie,
|
|
4359
|
+
adoptCreatedSession: re,
|
|
4360
|
+
waitForPendingSessionCreation: se,
|
|
4361
|
+
deleteSession: ce,
|
|
4362
|
+
currentSessionIdRef: u,
|
|
4363
|
+
agentIdRef: d,
|
|
4364
|
+
runSubscriptionAbortRef: p
|
|
5279
4365
|
};
|
|
5280
4366
|
}
|
|
5281
4367
|
//#endregion
|
|
5282
|
-
export {
|
|
4368
|
+
export { Ge as S, ot as _, an as a, He as b, kt as c, Ct as d, gt as f, st as g, lt as h, On as i, Tt as l, ft as m, wn as n, Kt as o, pt as p, Dn as r, Nt as s, Kn as t, Et as u, $e as v, We as x, qe as y };
|