@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
package/dist-lib/{persisted-session-history-KtoKbLRA.js → persisted-session-history-D_1AtH5H.js}
RENAMED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { d as r, i, l as a, o, p as s, t as c, u as l } from "./reducer-mbYiX0wz.js";
|
|
1
|
+
import { f as e, n as t, p as n, r } from "./session-events-6PXUoAkP.js";
|
|
2
|
+
import { d as i, i as a, l as o, o as s, p as c, t as l, u } from "./reducer-mbYiX0wz.js";
|
|
4
3
|
//#region src/core/conversation/safe-tool-value.ts
|
|
5
|
-
var
|
|
4
|
+
var d = [
|
|
6
5
|
"authorization",
|
|
7
6
|
"credential",
|
|
8
7
|
"password",
|
|
@@ -20,14 +19,14 @@ var u = [
|
|
|
20
19
|
"stack",
|
|
21
20
|
"exception"
|
|
22
21
|
];
|
|
23
|
-
function d(e) {
|
|
24
|
-
return e.normalize("NFKC").toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
25
|
-
}
|
|
26
22
|
function f(e) {
|
|
27
|
-
|
|
28
|
-
return u.some((e) => t.includes(e));
|
|
23
|
+
return e.normalize("NFKC").toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
29
24
|
}
|
|
30
25
|
function p(e) {
|
|
26
|
+
let t = f(e);
|
|
27
|
+
return d.some((e) => t.includes(e));
|
|
28
|
+
}
|
|
29
|
+
function m(e) {
|
|
31
30
|
let t = e.split(".");
|
|
32
31
|
if (t.length > 4 || t.some((e) => e.length === 0)) return null;
|
|
33
32
|
let n = t.map((e) => {
|
|
@@ -40,10 +39,10 @@ function p(e) {
|
|
|
40
39
|
let r = n, i = 2 ** (8 * (5 - r.length));
|
|
41
40
|
return r.slice(0, -1).some((e) => e > 255) || r.at(-1) >= i ? null : r.slice(0, -1).reduce((e, t, n) => e + t * 2 ** (8 * (3 - n)), r.at(-1));
|
|
42
41
|
}
|
|
43
|
-
function
|
|
42
|
+
function h(e) {
|
|
44
43
|
return e >>> 24 == 0 || e >>> 24 == 10 || e >>> 24 == 127 || e >>> 16 == 43518 || e >>> 16 == 49320 || e >>> 20 == 2753;
|
|
45
44
|
}
|
|
46
|
-
function
|
|
45
|
+
function g(e) {
|
|
47
46
|
let t;
|
|
48
47
|
try {
|
|
49
48
|
t = decodeURIComponent(e).toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
|
|
@@ -51,44 +50,44 @@ function h(e) {
|
|
|
51
50
|
return !0;
|
|
52
51
|
}
|
|
53
52
|
if (t === "localhost" || t.endsWith(".localhost") || t.endsWith(".local") || t.endsWith(".internal")) return !0;
|
|
54
|
-
let n = t.match(/^::ffff:(\d+(?:\.\d+){0,3})$/)?.[1], r = t.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i), i = r ? Number.parseInt(r[1], 16) * 65536 + Number.parseInt(r[2], 16) :
|
|
55
|
-
if (i !== null) return
|
|
53
|
+
let n = t.match(/^::ffff:(\d+(?:\.\d+){0,3})$/)?.[1], r = t.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i), i = r ? Number.parseInt(r[1], 16) * 65536 + Number.parseInt(r[2], 16) : m(n || t);
|
|
54
|
+
if (i !== null) return h(i);
|
|
56
55
|
let a = Number.parseInt(t.split(":", 1)[0], 16);
|
|
57
56
|
return t === "::" || t === "::1" || Number.isInteger(a) && (a & 65024) == 64512 || Number.isInteger(a) && (a & 65472) == 65152;
|
|
58
57
|
}
|
|
59
|
-
function
|
|
58
|
+
function _(e) {
|
|
60
59
|
return (e.match(/https?:\/\/\[[^\]]+\](?::\d+)?[^\s<>{}"']*|https?:\/\/[^\s<>{}"'[\]()]+/gi) || []).some((e) => {
|
|
61
60
|
let t = e.replace(/[.,;:!?]+$/, "").replace(/\\/g, "/");
|
|
62
61
|
try {
|
|
63
62
|
let e = new URL(t);
|
|
64
|
-
return !!(e.username || e.password) ||
|
|
63
|
+
return !!(e.username || e.password) || g(e.hostname);
|
|
65
64
|
} catch {
|
|
66
65
|
return !0;
|
|
67
66
|
}
|
|
68
67
|
});
|
|
69
68
|
}
|
|
70
|
-
function
|
|
71
|
-
return
|
|
69
|
+
function v(e, t = 0) {
|
|
70
|
+
return b(e, t, 8192);
|
|
72
71
|
}
|
|
73
|
-
function
|
|
74
|
-
return
|
|
72
|
+
function y(e, t, n) {
|
|
73
|
+
return b(e, 0, [
|
|
75
74
|
"langgraph",
|
|
76
75
|
"adk",
|
|
77
76
|
"codex"
|
|
78
77
|
].includes(String(t)) && !String(n || "").toLowerCase().includes("a2a") ? Infinity : 8192);
|
|
79
78
|
}
|
|
80
|
-
function
|
|
81
|
-
return t > 8 ? "[truncated]" : typeof e == "string" ? /bearer\s+\S+|traceback|(?:token|authorization|api[_ .-]?key|access[_ .-]?token|refresh[_ .-]?token|secretaccesskey|accesstoken|refreshtoken|cookie|password|secret)\s*["']?\s*[=:]/i.test(e) ||
|
|
79
|
+
function b(e, t, n) {
|
|
80
|
+
return t > 8 ? "[truncated]" : typeof e == "string" ? /bearer\s+\S+|traceback|(?:token|authorization|api[_ .-]?key|access[_ .-]?token|refresh[_ .-]?token|secretaccesskey|accesstoken|refreshtoken|cookie|password|secret)\s*["']?\s*[=:]/i.test(e) || _(e) ? "[redacted]" : e.length > n ? `${e.slice(0, n)}[truncated]` : e : Array.isArray(e) ? e.slice(0, 128).map((e) => b(e, t + 1, n)) : e && typeof e == "object" ? Object.fromEntries(Object.entries(e).slice(0, 128).filter(([e]) => !p(e)).map(([e, r]) => [e, b(r, t + 1, n)])) : e;
|
|
82
81
|
}
|
|
83
82
|
//#endregion
|
|
84
83
|
//#region src/core/conversation/runtime-ingress.ts
|
|
85
|
-
var
|
|
84
|
+
var x = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, S = (e, t, n) => JSON.stringify([
|
|
86
85
|
e,
|
|
87
86
|
t,
|
|
88
87
|
n
|
|
89
|
-
]),
|
|
90
|
-
runtime = new
|
|
91
|
-
flatChildren = new
|
|
88
|
+
]), C = class {
|
|
89
|
+
runtime = new n();
|
|
90
|
+
flatChildren = new l();
|
|
92
91
|
seen = /* @__PURE__ */ new Set();
|
|
93
92
|
parents = /* @__PURE__ */ new Map();
|
|
94
93
|
descriptorItemIds = /* @__PURE__ */ new Map();
|
|
@@ -98,11 +97,11 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
|
|
|
98
97
|
sessionId;
|
|
99
98
|
conversation;
|
|
100
99
|
profile;
|
|
101
|
-
constructor(e, t = new
|
|
100
|
+
constructor(e, t = new l(), n = "flat-v1") {
|
|
102
101
|
this.sessionId = e, this.conversation = t, this.profile = n;
|
|
103
102
|
}
|
|
104
103
|
identity(e, t, n, r = !1) {
|
|
105
|
-
return this.profile === "agent-block-v1" || r ?
|
|
104
|
+
return this.profile === "agent-block-v1" || r ? S(e, t, n) : n;
|
|
106
105
|
}
|
|
107
106
|
snapshot() {
|
|
108
107
|
let e = this.conversation.snapshot();
|
|
@@ -120,21 +119,21 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
|
|
|
120
119
|
if (!t || !n || !r) throw Error("RuntimeEvent identity missing");
|
|
121
120
|
if (this.runId && this.runId !== t) throw Error("RuntimeEvent run identity changed");
|
|
122
121
|
if (this.seen.has(r)) return null;
|
|
123
|
-
let a = String(e.parent_scope_id ?? this.descriptors.get(n)?.parent_scope_id ?? this.parents.get(n) ?? ""),
|
|
122
|
+
let a = String(e.parent_scope_id ?? this.descriptors.get(n)?.parent_scope_id ?? this.parents.get(n) ?? ""), o = x(e.source), c = [
|
|
124
123
|
"adk",
|
|
125
124
|
"langgraph",
|
|
126
125
|
"codex"
|
|
127
|
-
].includes(String(
|
|
126
|
+
].includes(String(o.framework)) && !this.descriptors.has(n);
|
|
128
127
|
if (c && a && i === "run.progress") return null;
|
|
129
128
|
if (i.startsWith("run.") && (a || !c && this.rootScope && n !== this.rootScope)) throw Error("Child scope cannot transition root run");
|
|
130
129
|
if (this.parents.has(n) && this.parents.get(n) !== a) throw Error("Scope parent changed");
|
|
131
130
|
let l = String(e.item_id || ""), u = this.identity(t, n, l || r, !!a), d = Object.fromEntries(Object.entries({
|
|
132
|
-
framework:
|
|
133
|
-
protocol:
|
|
134
|
-
eventId:
|
|
135
|
-
cursor:
|
|
136
|
-
runId:
|
|
137
|
-
itemId:
|
|
131
|
+
framework: o.framework,
|
|
132
|
+
protocol: o.protocol,
|
|
133
|
+
eventId: o.native_event_id,
|
|
134
|
+
cursor: o.native_cursor,
|
|
135
|
+
runId: o.native_run_id,
|
|
136
|
+
itemId: o.native_item_id,
|
|
138
137
|
scopeId: n,
|
|
139
138
|
runtimeItemId: l || void 0,
|
|
140
139
|
parentScopeId: a || void 0,
|
|
@@ -153,7 +152,7 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
|
|
|
153
152
|
payloadSchemaRef: "conversation.item.progress/v1",
|
|
154
153
|
payload: {},
|
|
155
154
|
nativeRef: d
|
|
156
|
-
}, p =
|
|
155
|
+
}, p = x(x(e.source).metadata), m = p.conversation_visibility ?? p.visibility;
|
|
157
156
|
if ([
|
|
158
157
|
"public",
|
|
159
158
|
"internal",
|
|
@@ -168,22 +167,22 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
|
|
|
168
167
|
"run.failed",
|
|
169
168
|
"run.canceled",
|
|
170
169
|
"run.cancelled"
|
|
171
|
-
].includes(i) && (f.kind = "error", f.payloadSchemaRef = "conversation.item.error/v1", f.payload.error =
|
|
170
|
+
].includes(i) && (f.kind = "error", f.payloadSchemaRef = "conversation.item.error/v1", f.payload.error = x(e.error).message || e.reason || ""), f.lifecycle = ["run.completed", "run.interrupted"].includes(i) ? "completed" : [
|
|
172
171
|
"run.failed",
|
|
173
172
|
"run.canceled",
|
|
174
173
|
"run.cancelled"
|
|
175
174
|
].includes(i) ? "failed" : "streaming";
|
|
176
175
|
else {
|
|
177
176
|
if (!l) throw Error("RuntimeEvent item identity missing");
|
|
178
|
-
let d =
|
|
179
|
-
let t =
|
|
177
|
+
let d = x(e.snapshot || e.initial), p = i === "item.updated" ? [x(e.update)] : Array.isArray(d.parts) ? d.parts : [], h = p.map((e) => {
|
|
178
|
+
let t = x(e);
|
|
180
179
|
return {
|
|
181
180
|
partId: String(t.part_id || "part"),
|
|
182
181
|
contentType: String(t.content_type || "data"),
|
|
183
182
|
...typeof t.text == "string" ? { text: t.text } : {},
|
|
184
183
|
value: t
|
|
185
184
|
};
|
|
186
|
-
}), g = p.map((e) =>
|
|
185
|
+
}), g = p.map((e) => x(x(e).data)).find((e) => e.schema === "execution.scope/v1");
|
|
187
186
|
if (a && !g && !c) {
|
|
188
187
|
let e = this.descriptorItemIds.get(n);
|
|
189
188
|
if (!e) throw Error("Child content requires its scope descriptor first");
|
|
@@ -191,12 +190,12 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
|
|
|
191
190
|
}
|
|
192
191
|
if (g) {
|
|
193
192
|
if (this.descriptorItemIds.has(n) && this.descriptorItemIds.get(n) !== u) throw Error("Scope descriptor item identity changed");
|
|
194
|
-
let e =
|
|
193
|
+
let e = x(g.trigger_ref);
|
|
195
194
|
if (g.scope_id !== n || g.parent_scope_id !== a || e.scope_id !== a || !e.item_id || !e.call_id || !a) throw Error("Invalid scope descriptor locator");
|
|
196
195
|
let t = this.runtime.snapshot().items.find((t) => t.scopeId === e.scope_id && t.itemId === e.item_id);
|
|
197
|
-
if (t && !t.parts.some((t) =>
|
|
196
|
+
if (t && !t.parts.some((t) => x(t.value).call_id === e.call_id)) throw Error("Scope trigger call mismatch");
|
|
198
197
|
let r = this.descriptors.get(n);
|
|
199
|
-
|
|
198
|
+
s({
|
|
200
199
|
...f,
|
|
201
200
|
kind: "agent",
|
|
202
201
|
payloadSchemaRef: "conversation.item.agent/v1",
|
|
@@ -208,15 +207,15 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
|
|
|
208
207
|
} : void 0), this.descriptors.set(n, g), this.descriptorItemIds.set(n, u);
|
|
209
208
|
}
|
|
210
209
|
for (let e of this.descriptors.values()) {
|
|
211
|
-
let t =
|
|
212
|
-
if (t.scope_id === n && t.item_id === l && h.length && !h.some((e) =>
|
|
210
|
+
let t = x(e.trigger_ref);
|
|
211
|
+
if (t.scope_id === n && t.item_id === l && h.length && !h.some((e) => x(e.value).call_id === t.call_id)) throw Error("Scope trigger call mismatch");
|
|
213
212
|
}
|
|
214
|
-
let
|
|
215
|
-
if (a &&
|
|
213
|
+
let _ = this.runtime.snapshot().items.find((e) => e.scopeId === n && e.itemId === l);
|
|
214
|
+
if (a && !c && _ && _.status !== "open") {
|
|
216
215
|
if (i === "item.updated" || i === "item.started") throw Error("Remote item cannot reopen");
|
|
217
|
-
if (Array.isArray(d.parts) && JSON.stringify(
|
|
216
|
+
if (Array.isArray(d.parts) && JSON.stringify(_.parts) !== JSON.stringify(h)) throw Error("Remote terminal content conflict");
|
|
218
217
|
}
|
|
219
|
-
let
|
|
218
|
+
let b = {
|
|
220
219
|
type: i.replaceAll(".", "_"),
|
|
221
220
|
runId: t,
|
|
222
221
|
scopeId: n,
|
|
@@ -232,7 +231,7 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
|
|
|
232
231
|
op: e.op || "replace"
|
|
233
232
|
} : {}
|
|
234
233
|
};
|
|
235
|
-
this.runtime.apply(
|
|
234
|
+
this.runtime.apply(b);
|
|
236
235
|
let S = this.runtime.snapshot().items.find((e) => e.scopeId === n && e.itemId === l);
|
|
237
236
|
if (!S || a && S.itemKind === "status" && S.status === "open" && !S.parts.length) return null;
|
|
238
237
|
if (a && [
|
|
@@ -240,35 +239,35 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
|
|
|
240
239
|
"tool_call",
|
|
241
240
|
"tool_result"
|
|
242
241
|
].includes(S.itemKind) && !S.parts.length) return this.runId = t, this.parents.set(n, a), this.seen.add(r), null;
|
|
243
|
-
let C = S.parts.map((e) =>
|
|
244
|
-
if (f.lifecycle = S.status === "open" ? i === "item.started" ? "pending" : "streaming" : S.status, f.operation = ["completed", "failed"].includes(f.lifecycle) ? "completed" : i === "item.started" ? "append" : "replace", w) f.operation = ["completed", "failed"].includes(f.lifecycle) ? "completed" : "replace", f.kind = "agent", f.payloadSchemaRef = "conversation.item.agent/v1", f.payload = w, f.parentItemId = this.identity(t, String(
|
|
242
|
+
let C = S.parts.map((e) => x(e.value)), w = C.map((e) => x(e.data)).find((e) => e.schema === "execution.scope/v1");
|
|
243
|
+
if (f.lifecycle = S.status === "open" ? i === "item.started" ? "pending" : "streaming" : S.status, f.operation = ["completed", "failed"].includes(f.lifecycle) ? "completed" : i === "item.started" ? "append" : "replace", w) f.operation = ["completed", "failed"].includes(f.lifecycle) ? "completed" : "replace", f.kind = "agent", f.payloadSchemaRef = "conversation.item.agent/v1", f.payload = w, f.parentItemId = this.identity(t, String(x(w.trigger_ref).scope_id), String(x(w.trigger_ref).item_id), !!this.parents.get(String(x(w.trigger_ref).scope_id))), f.capabilityRef = "agent.block";
|
|
245
244
|
else if (S.itemKind === "tool_call" || S.itemKind === "tool_result") {
|
|
246
245
|
let e = C.find((e) => e.content_type === "tool_call"), t = C.find((e) => e.content_type === "tool_result");
|
|
247
246
|
f.kind = "tool_call", f.capabilityRef = "tool.inspect", f.payloadSchemaRef = "conversation.item.tool-call/v1", f.payload = {
|
|
248
247
|
...e ? {
|
|
249
248
|
callId: e.call_id,
|
|
250
249
|
tool: e.name,
|
|
251
|
-
args:
|
|
250
|
+
args: v(e.arguments)
|
|
252
251
|
} : {},
|
|
253
252
|
...t ? {
|
|
254
253
|
callId: t.call_id,
|
|
255
|
-
output:
|
|
254
|
+
output: y(t.result, o.framework, o.protocol),
|
|
256
255
|
isError: t.is_error
|
|
257
256
|
} : {},
|
|
258
257
|
executionStatus: S.status === "failed" ? "failed" : t && S.status !== "open" ? t.is_error ? "failed" : "completed" : S.itemKind === "tool_result" ? "unknown" : "running",
|
|
259
258
|
sourceKind: S.itemKind
|
|
260
259
|
};
|
|
261
|
-
} else if (S.itemKind === "data" &&
|
|
260
|
+
} else if (S.itemKind === "data" && o.protocol === "a2ui") {
|
|
262
261
|
let e = C.find((e) => e.content_type === "data")?.data;
|
|
263
262
|
f.kind = "a2ui", f.payloadSchemaRef = "conversation.item.a2ui/v1", f.payload = {
|
|
264
|
-
surfaceId: String(
|
|
265
|
-
...typeof
|
|
263
|
+
surfaceId: String(x(o.metadata).surface_id || ""),
|
|
264
|
+
...typeof x(o.metadata).interaction_id == "string" ? { interactionId: x(o.metadata).interaction_id } : {},
|
|
266
265
|
data: Array.isArray(e) ? e : []
|
|
267
266
|
};
|
|
268
267
|
} else if (S.itemKind === "message" || S.itemKind === "reasoning" || S.itemKind === "artifact" && S.parts.length > 0 && S.parts.every((e) => e.contentType === "text")) {
|
|
269
|
-
f.kind = S.itemKind === "reasoning" ? "reasoning" :
|
|
270
|
-
let t =
|
|
271
|
-
f.kind === "reasoning" && (t.public_summary === !0 || t.provider_reasoning === !0) && (f.payload.presentationSource = t.public_summary === !0 ? "public_summary" : "provider_reasoning"), i === "item.updated" && e.op === "append" && (f.operation = "append", f.payload.text =
|
|
268
|
+
f.kind = S.itemKind === "reasoning" ? "reasoning" : x(x(e.source).metadata).native_item_kind === "userMessage" ? "user_message" : "assistant_text", f.payloadSchemaRef = `conversation.item.${f.kind}/v1`, f.payload = { text: S.parts.map((e) => e.text || "").join("") };
|
|
269
|
+
let t = x(o.metadata);
|
|
270
|
+
f.kind === "reasoning" && (t.public_summary === !0 || t.provider_reasoning === !0) && (f.payload.presentationSource = t.public_summary === !0 ? "public_summary" : "provider_reasoning"), i === "item.updated" && e.op === "append" && (f.operation = "append", f.payload.text = x(e.update).text || "");
|
|
272
271
|
} else if (S.itemKind === "artifact") {
|
|
273
272
|
let e = C.find((e) => e.content_type === "artifact") || {};
|
|
274
273
|
f.kind = "artifact", f.payloadSchemaRef = "conversation.item.artifact/v1", f.payload = {
|
|
@@ -277,7 +276,7 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
|
|
|
277
276
|
uri: e.uri
|
|
278
277
|
};
|
|
279
278
|
} else if (S.status === "failed") {
|
|
280
|
-
let t =
|
|
279
|
+
let t = x(e.error);
|
|
281
280
|
f.kind = "error", f.payloadSchemaRef = "conversation.item.error/v1", f.payload = { error: String(t.message || t.code || "Remote call failed") };
|
|
282
281
|
} else f.visibility = m === "public" ? "public" : "hidden", f.kind = "unknown", f.payloadSchemaRef = "conversation.item.unknown/v1", f.payload = { summary: "Unsupported runtime content" };
|
|
283
282
|
}
|
|
@@ -286,11 +285,11 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
|
|
|
286
285
|
};
|
|
287
286
|
//#endregion
|
|
288
287
|
//#region src/core/a2ui/history.ts
|
|
289
|
-
function
|
|
288
|
+
function w(e, t) {
|
|
290
289
|
let n = e.map((e) => JSON.stringify(e)), r = t.map((e) => JSON.stringify(e));
|
|
291
290
|
return n.every((e, t) => r[t] === e) ? t : r.every((e, t) => n[t] === e) ? e : [...e, ...t];
|
|
292
291
|
}
|
|
293
|
-
function
|
|
292
|
+
function T(e, t, n) {
|
|
294
293
|
let r = {
|
|
295
294
|
...t.runId || e?.runId ? { runId: t.runId || e?.runId } : {},
|
|
296
295
|
...t.interactionId || e?.interactionId ? { interactionId: t.interactionId || e?.interactionId } : {},
|
|
@@ -302,7 +301,7 @@ function w(e, t, n) {
|
|
|
302
301
|
} : {
|
|
303
302
|
...t,
|
|
304
303
|
...r,
|
|
305
|
-
messages: e ?
|
|
304
|
+
messages: e ? w(e.messages, t.messages) : t.messages,
|
|
306
305
|
...n || e?.batchIds || t.batchIds ? { batchIds: [...new Set([
|
|
307
306
|
...e?.batchIds || [],
|
|
308
307
|
...t.batchIds || [],
|
|
@@ -312,28 +311,28 @@ function w(e, t, n) {
|
|
|
312
311
|
}
|
|
313
312
|
//#endregion
|
|
314
313
|
//#region src/core/a2ui/transcript.ts
|
|
315
|
-
function
|
|
314
|
+
function ee(e, t) {
|
|
316
315
|
if (e.activity.surfaceId !== t.activity.surfaceId) return !1;
|
|
317
316
|
let n = e.activity.interactionId, r = t.activity.interactionId;
|
|
318
317
|
if (n && r) return n === r;
|
|
319
318
|
let i = e.activity.runId || e.message.runId || e.message.invocationId, a = t.activity.runId || t.message.runId || t.message.invocationId;
|
|
320
319
|
return i && a ? i === a : (e.activity.originMessageId || e.message.id) === (t.activity.originMessageId || t.message.id);
|
|
321
320
|
}
|
|
322
|
-
function
|
|
323
|
-
let n = e.filter((e) =>
|
|
321
|
+
function E(e, t) {
|
|
322
|
+
let n = e.filter((e) => ee(e, t));
|
|
324
323
|
return n.length === 1 ? n[0] : void 0;
|
|
325
324
|
}
|
|
326
|
-
function
|
|
325
|
+
function D(e) {
|
|
327
326
|
if (!e.some((e) => e.aguiActivity || e.aguiActivities?.length)) return e;
|
|
328
327
|
let t = /* @__PURE__ */ new Map(), n = !1, r = e.map((e) => {
|
|
329
328
|
let r = (r) => {
|
|
330
|
-
let i = t.get(r.surfaceId) || [], a =
|
|
329
|
+
let i = t.get(r.surfaceId) || [], a = E(i, {
|
|
331
330
|
message: e,
|
|
332
331
|
activity: r
|
|
333
332
|
});
|
|
334
333
|
if (a) {
|
|
335
334
|
let t = a.activity;
|
|
336
|
-
n = !0, t.messages =
|
|
335
|
+
n = !0, t.messages = w(t.messages, r.messages), t.interactionId = r.interactionId || t.interactionId, t.runId ||= r.runId || e.runId || e.invocationId, t.batchIds = [...new Set([...t.batchIds || [], ...r.batchIds || []])];
|
|
337
336
|
return;
|
|
338
337
|
}
|
|
339
338
|
let o = r.runId || e.runId || e.invocationId, s = {
|
|
@@ -358,7 +357,7 @@ function te(e) {
|
|
|
358
357
|
}
|
|
359
358
|
//#endregion
|
|
360
359
|
//#region src/core/conversation/presentation.ts
|
|
361
|
-
var
|
|
360
|
+
var te = {
|
|
362
361
|
user_message: "conversation.item.user_message/v1",
|
|
363
362
|
assistant_text: "conversation.item.assistant_text/v1",
|
|
364
363
|
reasoning: "conversation.item.reasoning/v1",
|
|
@@ -369,10 +368,10 @@ var ne = {
|
|
|
369
368
|
a2ui: "conversation.item.a2ui/v1",
|
|
370
369
|
error: "conversation.item.error/v1"
|
|
371
370
|
};
|
|
372
|
-
function
|
|
371
|
+
function ne(e) {
|
|
373
372
|
return e.lifecycle === "completed" || e.lifecycle === "failed";
|
|
374
373
|
}
|
|
375
|
-
var
|
|
374
|
+
var re = new Set([
|
|
376
375
|
"aborted",
|
|
377
376
|
"canceled",
|
|
378
377
|
"cancelled",
|
|
@@ -380,17 +379,17 @@ var ie = new Set([
|
|
|
380
379
|
"incomplete",
|
|
381
380
|
"interrupted"
|
|
382
381
|
]);
|
|
383
|
-
function
|
|
384
|
-
if (e.parentItemId || e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || e.kind !== "progress" && e.kind !== "error" || !
|
|
382
|
+
function O(e) {
|
|
383
|
+
if (e.parentItemId || e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || e.kind !== "progress" && e.kind !== "error" || !ne(e)) return;
|
|
385
384
|
let t = typeof e.payload.status == "string" ? e.payload.status.toLowerCase() : "";
|
|
386
385
|
if (t === "completed") return "completed";
|
|
387
|
-
if (
|
|
386
|
+
if (re.has(t)) return "failed";
|
|
388
387
|
}
|
|
389
|
-
function
|
|
390
|
-
let t =
|
|
388
|
+
function ie(e) {
|
|
389
|
+
let t = te[e.kind];
|
|
391
390
|
return t === void 0 || t === e.payloadSchemaRef;
|
|
392
391
|
}
|
|
393
|
-
function
|
|
392
|
+
function ae(e) {
|
|
394
393
|
if (typeof e != "string" || e.length === 0) return null;
|
|
395
394
|
try {
|
|
396
395
|
let t = new URL(e);
|
|
@@ -399,7 +398,7 @@ function oe(e) {
|
|
|
399
398
|
return null;
|
|
400
399
|
}
|
|
401
400
|
}
|
|
402
|
-
function
|
|
401
|
+
function oe(e) {
|
|
403
402
|
return {
|
|
404
403
|
id: e.itemId,
|
|
405
404
|
parentId: e.parentItemId || null,
|
|
@@ -409,8 +408,8 @@ function se(e) {
|
|
|
409
408
|
lifecycle: e.lifecycle
|
|
410
409
|
};
|
|
411
410
|
}
|
|
412
|
-
function
|
|
413
|
-
let t = typeof e.payload.artifactId == "string" && e.payload.artifactId ? e.payload.artifactId : e.itemId, n = e.payload.sizeBytes ?? e.payload.size, r = typeof n == "number" && Number.isFinite(n) && n >= 0 ? n : null, i =
|
|
411
|
+
function se(e) {
|
|
412
|
+
let t = typeof e.payload.artifactId == "string" && e.payload.artifactId ? e.payload.artifactId : e.itemId, n = e.payload.sizeBytes ?? e.payload.size, r = typeof n == "number" && Number.isFinite(n) && n >= 0 ? n : null, i = ae(e.payload.uri);
|
|
414
413
|
return {
|
|
415
414
|
artifactId: t,
|
|
416
415
|
itemId: e.itemId,
|
|
@@ -424,31 +423,31 @@ function ce(e) {
|
|
|
424
423
|
uri: i
|
|
425
424
|
};
|
|
426
425
|
}
|
|
427
|
-
function
|
|
426
|
+
function k(e, t) {
|
|
428
427
|
let n = e.payload[t];
|
|
429
428
|
return typeof n == "string" && n ? n : null;
|
|
430
429
|
}
|
|
431
|
-
function
|
|
430
|
+
function A(e, t) {
|
|
432
431
|
if (e.kind === "tool_call") {
|
|
433
|
-
let
|
|
434
|
-
if (
|
|
432
|
+
let n = k(e, "callId");
|
|
433
|
+
if (n) return `tool:${JSON.stringify([
|
|
435
434
|
e.runId,
|
|
436
|
-
e.nativeRef.scopeId || e.nativeRef.scope_id || "",
|
|
437
|
-
|
|
435
|
+
t ?? (e.nativeRef.scopeId || e.nativeRef.scope_id || ""),
|
|
436
|
+
n
|
|
438
437
|
])}`;
|
|
439
438
|
}
|
|
440
439
|
if (e.kind === "approval") {
|
|
441
|
-
let t =
|
|
440
|
+
let t = k(e, "interactionId");
|
|
442
441
|
if (t) return `approval:${t}`;
|
|
443
442
|
}
|
|
444
443
|
if (e.kind === "a2ui") {
|
|
445
|
-
let t =
|
|
444
|
+
let t = k(e, "surfaceId");
|
|
446
445
|
if (t) return `a2ui:${JSON.stringify([e.runId, t])}`;
|
|
447
446
|
}
|
|
448
447
|
return `item:${e.itemId}`;
|
|
449
448
|
}
|
|
450
|
-
function
|
|
451
|
-
let n =
|
|
449
|
+
function ce(e, t) {
|
|
450
|
+
let n = ne(e) && !ne(t), r = e.kind === "a2ui" && t.kind === "a2ui" && Array.isArray(e.payload.data) && Array.isArray(t.payload.data) ? { data: w(e.payload.data, t.payload.data) } : {};
|
|
452
451
|
return {
|
|
453
452
|
...e,
|
|
454
453
|
...t,
|
|
@@ -474,37 +473,49 @@ function ue(e, t) {
|
|
|
474
473
|
} : {}
|
|
475
474
|
};
|
|
476
475
|
}
|
|
477
|
-
function
|
|
478
|
-
let t = [], n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map()
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
476
|
+
function le(e) {
|
|
477
|
+
let t = [], n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map(), s = (e) => {
|
|
478
|
+
let t = e.nativeRef.parentScopeId;
|
|
479
|
+
return e.nativeRef.framework === "langgraph" && e.kind === "tool_call" && e.payload.sourceKind === "tool_result" && e.payload.callId && typeof t == "string" ? A(e, t) : void 0;
|
|
480
|
+
};
|
|
481
|
+
for (let t of e) {
|
|
482
|
+
if (t.nativeRef.framework === "langgraph" && t.payload.sourceKind === "tool_call") {
|
|
483
|
+
let e = A(t);
|
|
484
|
+
i.set(e, (i.get(e) ?? 0) + 1);
|
|
485
|
+
}
|
|
486
|
+
t.kind === "tool_call" && t.payload.sourceKind === "tool_result" && a.add(A(t));
|
|
487
|
+
let e = s(t);
|
|
488
|
+
e && o.set(e, (o.get(e) ?? 0) + 1);
|
|
489
|
+
}
|
|
490
|
+
for (let c of e) {
|
|
491
|
+
let e = A(c), l = s(c), u = l && !i.has(e) && !a.has(l) && i.get(l) === 1 && o.get(l) === 1 ? l : e, d = c.kind === "a2ui" ? {
|
|
492
|
+
surfaceId: k(c, "surfaceId") || "",
|
|
482
493
|
messages: [],
|
|
483
|
-
...
|
|
484
|
-
} : null,
|
|
494
|
+
...k(c, "interactionId") ? { interactionId: k(c, "interactionId") } : {}
|
|
495
|
+
} : null, f = d ? {
|
|
485
496
|
message: {
|
|
486
|
-
id:
|
|
487
|
-
runId:
|
|
497
|
+
id: c.itemId,
|
|
498
|
+
runId: c.runId
|
|
488
499
|
},
|
|
489
|
-
activity:
|
|
490
|
-
} : null,
|
|
491
|
-
if (
|
|
492
|
-
|
|
493
|
-
...
|
|
500
|
+
activity: d
|
|
501
|
+
} : null, p = r.get(u) || [], m = f ? E(p, f) : void 0, h = f ? m?.index : n.get(u);
|
|
502
|
+
if (h === void 0) {
|
|
503
|
+
f ? r.set(u, [...p, {
|
|
504
|
+
...f,
|
|
494
505
|
index: t.length
|
|
495
|
-
}]) : n.set(
|
|
496
|
-
key:
|
|
497
|
-
item:
|
|
498
|
-
sourceItemIds: [
|
|
506
|
+
}]) : n.set(u, t.length), t.push({
|
|
507
|
+
key: f ? `${u}:${c.itemId}` : u,
|
|
508
|
+
item: c,
|
|
509
|
+
sourceItemIds: [c.itemId]
|
|
499
510
|
});
|
|
500
511
|
continue;
|
|
501
512
|
}
|
|
502
|
-
|
|
503
|
-
let
|
|
504
|
-
t[
|
|
505
|
-
key:
|
|
506
|
-
item:
|
|
507
|
-
sourceItemIds: [...new Set([...
|
|
513
|
+
m && d?.interactionId && (m.activity.interactionId = d.interactionId);
|
|
514
|
+
let g = t[h];
|
|
515
|
+
t[h] = {
|
|
516
|
+
key: g.key,
|
|
517
|
+
item: ce(g.item, c),
|
|
518
|
+
sourceItemIds: [...new Set([...g.sourceItemIds, c.itemId])]
|
|
508
519
|
};
|
|
509
520
|
}
|
|
510
521
|
return t.map((t) => t.item.kind === "tool_call" ? {
|
|
@@ -518,29 +529,29 @@ function de(e) {
|
|
|
518
529
|
}
|
|
519
530
|
} : t);
|
|
520
531
|
}
|
|
521
|
-
function
|
|
532
|
+
function j(e, t) {
|
|
522
533
|
let n = e.payload.trigger_ref;
|
|
523
534
|
return n ? t.filter((t) => t.kind === "tool_call" && t.runId === e.runId && (t.nativeRef.scopeId || t.nativeRef.scope_id) === n.scope_id && (t.payload.callId === n.call_id || t.itemId === e.parentItemId)) : [];
|
|
524
535
|
}
|
|
525
|
-
function
|
|
526
|
-
let t = e.filter((e) => e.kind === "agent"), n = (e) => String(e.nativeRef.scopeId || e.nativeRef.scope_id || ""), r = (e) => t.find((t) => t.runId === e.runId && t.itemId !== e.itemId && (e.parentItemId === t.itemId || (e.kind === "agent" ? e.payload.parent_scope_id === t.payload.scope_id : n(e) && n(e) === String(t.payload.scope_id)))), i = new Set(t.flatMap((t) =>
|
|
536
|
+
function ue(e) {
|
|
537
|
+
let t = e.filter((e) => e.kind === "agent"), n = (e) => String(e.nativeRef.scopeId || e.nativeRef.scope_id || ""), r = (e) => t.find((t) => t.runId === e.runId && t.itemId !== e.itemId && (e.parentItemId === t.itemId || (e.kind === "agent" ? e.payload.parent_scope_id === t.payload.scope_id : n(e) && n(e) === String(t.payload.scope_id)))), i = new Set(t.flatMap((t) => j(t, e).map((e) => e.itemId))), a = e.filter((e) => !r(e) && !i.has(e.itemId));
|
|
527
538
|
return a.sort((t, n) => {
|
|
528
539
|
let r = (t) => t.kind === "agent" && t.parentItemId && e.some((e) => e.itemId === t.parentItemId) ? e.findIndex((e) => e.itemId === t.parentItemId) : e.indexOf(t);
|
|
529
540
|
return r(t) - r(n);
|
|
530
|
-
}),
|
|
541
|
+
}), le(a).map((t) => {
|
|
531
542
|
if (t.item.kind !== "agent") return t;
|
|
532
|
-
let n =
|
|
543
|
+
let n = le(e.filter((e) => r(e) === t.item && !i.has(e.itemId)));
|
|
533
544
|
return {
|
|
534
545
|
...t,
|
|
535
|
-
sourceItemIds: [...new Set([...
|
|
546
|
+
sourceItemIds: [...new Set([...j(t.item, e).map((e) => e.itemId), ...t.sourceItemIds])],
|
|
536
547
|
children: n
|
|
537
548
|
};
|
|
538
549
|
});
|
|
539
550
|
}
|
|
540
|
-
function
|
|
551
|
+
function de(e, t = {}) {
|
|
541
552
|
let n = e.items.filter((e) => e.visibility === "public" || t.includeInternal === !0 && e.visibility === "internal");
|
|
542
553
|
if (t.profile === "flat-v1" && n.some((e) => e.kind === "agent")) {
|
|
543
|
-
let e = n.filter((e) => e.kind === "agent"), t = new Set(e.flatMap((e) =>
|
|
554
|
+
let e = n.filter((e) => e.kind === "agent"), t = new Set(e.flatMap((e) => j(e, n).map((e) => e.itemId))), r = (t) => e.some((e) => e.runId === t.runId && (t.parentItemId === e.itemId || typeof e.payload.scope_id == "string" && e.payload.scope_id.length > 0 && e.payload.scope_id === (t.nativeRef.scopeId || t.nativeRef.scope_id))), i = n.find((e) => O(e)), a = n.filter((e) => e.kind !== "agent" && (e.kind === "error" || !r(e) && !t.has(e.itemId))), o = i?.payload.outputRefs || i?.payload.output_refs;
|
|
544
555
|
Array.isArray(o) && o.length && (a = a.filter((e) => e.kind !== "assistant_text" || o.some((t) => e.nativeRef.scopeId === t.scope_id && e.nativeRef.runtimeItemId === t.item_id)));
|
|
545
556
|
let s = a.filter((e) => e.kind === "assistant_text");
|
|
546
557
|
if (i && !s.some((e) => e.payload.text) && Array.isArray(o)) {
|
|
@@ -556,13 +567,13 @@ function me(e, t = {}) {
|
|
|
556
567
|
}
|
|
557
568
|
n = a.filter((e) => e.kind !== "assistant_text" || !!i);
|
|
558
569
|
}
|
|
559
|
-
let r = n.filter(
|
|
570
|
+
let r = n.filter(ie), i = n.filter((e) => !ie(e)), a = new Set([
|
|
560
571
|
"user_message",
|
|
561
572
|
"assistant_text",
|
|
562
573
|
"reasoning"
|
|
563
|
-
]), o = r.filter((e) => a.has(e.kind)).map(
|
|
574
|
+
]), o = r.filter((e) => a.has(e.kind)).map(oe), s = (e) => e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || r.some((t) => t.kind === "agent" && (e.parentItemId === t.itemId || t.runId === e.runId && t.payload.scope_id === (e.nativeRef.scopeId || e.nativeRef.scope_id))), c = (e) => r.filter((t) => t.kind === e && !s(t)).map((e) => typeof e.payload.text == "string" ? e.payload.text : "").join(""), l = [...r.filter((e) => e.kind === "unknown"), ...i], u = r.filter((e) => e.kind === "error"), d = [...r].reverse().find((e) => O(e) !== void 0);
|
|
564
575
|
return {
|
|
565
|
-
timeline:
|
|
576
|
+
timeline: ue(r.filter((e) => e.kind !== "progress")),
|
|
566
577
|
output: c("assistant_text"),
|
|
567
578
|
reasoning: c("reasoning"),
|
|
568
579
|
textItems: o,
|
|
@@ -570,7 +581,7 @@ function me(e, t = {}) {
|
|
|
570
581
|
approvalItems: r.filter((e) => e.kind === "approval"),
|
|
571
582
|
structuredInputItems: r.filter((e) => e.kind === "progress" && e.payloadSchemaRef === "conversation.item.structured-input/v1"),
|
|
572
583
|
a2uiItems: r.filter((e) => e.kind === "a2ui"),
|
|
573
|
-
artifacts: r.filter((e) => e.kind === "artifact").map(
|
|
584
|
+
artifacts: r.filter((e) => e.kind === "artifact").map(se),
|
|
574
585
|
fallbacks: [...l.map((e) => ({
|
|
575
586
|
id: e.itemId,
|
|
576
587
|
title: "Unsupported content",
|
|
@@ -583,22 +594,22 @@ function me(e, t = {}) {
|
|
|
583
594
|
failed: !0
|
|
584
595
|
}))],
|
|
585
596
|
runId: n.at(-1)?.runId || "",
|
|
586
|
-
terminalStatus: d ?
|
|
597
|
+
terminalStatus: d ? O(d) : void 0
|
|
587
598
|
};
|
|
588
599
|
}
|
|
589
600
|
//#endregion
|
|
590
601
|
//#region src/core/conversation/client.ts
|
|
591
|
-
var
|
|
592
|
-
function
|
|
602
|
+
var M = 8;
|
|
603
|
+
function N(e) {
|
|
593
604
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
594
605
|
}
|
|
595
|
-
function
|
|
596
|
-
if (e?.aborted) throw new
|
|
606
|
+
function P(e) {
|
|
607
|
+
if (e?.aborted) throw new c("conversation_aborted", "Conversation request was aborted.");
|
|
597
608
|
}
|
|
598
|
-
function
|
|
609
|
+
function fe(e, t) {
|
|
599
610
|
return t?.aborted === !0 || e instanceof Error && e.name === "AbortError";
|
|
600
611
|
}
|
|
601
|
-
function
|
|
612
|
+
function pe(e) {
|
|
602
613
|
let t = e.trim().replace(/\/+$/, "");
|
|
603
614
|
if (!t) return "";
|
|
604
615
|
if (!t.includes("://")) return t.startsWith("/") ? t : `/${t}`;
|
|
@@ -607,81 +618,81 @@ function ge(e) {
|
|
|
607
618
|
if (e.protocol !== "http:" && e.protocol !== "https:" || e.username || e.password) throw Error("unsafe URL");
|
|
608
619
|
return e.toString().replace(/\/$/, "");
|
|
609
620
|
} catch (e) {
|
|
610
|
-
throw new
|
|
621
|
+
throw new c("conversation_contract_mismatch", "Conversation base URL must be an HTTP(S) URL without embedded credentials.", { cause: e });
|
|
611
622
|
}
|
|
612
623
|
}
|
|
613
|
-
function
|
|
624
|
+
function me(e) {
|
|
614
625
|
return Math.min(200 * 2 ** Math.max(0, e - 1), 2e3);
|
|
615
626
|
}
|
|
616
|
-
function
|
|
627
|
+
function he(e) {
|
|
617
628
|
return new Promise((t) => {
|
|
618
629
|
setTimeout(t, e);
|
|
619
630
|
});
|
|
620
631
|
}
|
|
621
|
-
async function
|
|
622
|
-
if (
|
|
632
|
+
async function ge(e, t, n) {
|
|
633
|
+
if (P(n), !n) {
|
|
623
634
|
await e(t);
|
|
624
635
|
return;
|
|
625
636
|
}
|
|
626
637
|
await new Promise((r, i) => {
|
|
627
|
-
let a = () => i(new
|
|
638
|
+
let a = () => i(new c("conversation_aborted", "Conversation request was aborted."));
|
|
628
639
|
n.addEventListener("abort", a, { once: !0 }), e(t).then(r, i).finally(() => {
|
|
629
640
|
n.removeEventListener("abort", a);
|
|
630
641
|
});
|
|
631
642
|
});
|
|
632
643
|
}
|
|
633
|
-
function
|
|
644
|
+
function _e(e, t, n, r, i) {
|
|
634
645
|
let a = i ? i.snapshot() : e.snapshot();
|
|
635
646
|
return {
|
|
636
647
|
cursor: t,
|
|
637
648
|
runId: n,
|
|
638
649
|
state: a,
|
|
639
|
-
presentation:
|
|
650
|
+
presentation: de(a, { profile: r })
|
|
640
651
|
};
|
|
641
652
|
}
|
|
642
|
-
function
|
|
653
|
+
function ve(e, t) {
|
|
643
654
|
let n, r = [];
|
|
644
655
|
for (let t of e.split(/\r?\n/)) {
|
|
645
656
|
let e = t.endsWith("\r") ? t.slice(0, -1) : t;
|
|
646
657
|
if (!e || e.startsWith(":")) continue;
|
|
647
|
-
let i = e.indexOf(":"), a = i < 0 ? e : e.slice(0, i), o = i < 0 ? "" : e.slice(i + 1),
|
|
658
|
+
let i = e.indexOf(":"), a = i < 0 ? e : e.slice(0, i), o = i < 0 ? "" : e.slice(i + 1), s = o.startsWith(" ") ? o.slice(1) : o;
|
|
648
659
|
if (a === "id") {
|
|
649
|
-
if (!/^\d+$/.test(
|
|
650
|
-
n = Number(
|
|
651
|
-
} else a === "data" && r.push(
|
|
660
|
+
if (!/^\d+$/.test(s) || !Number.isSafeInteger(Number(s))) throw new c("conversation_stream_error", "Conversation stream contains an invalid replay cursor.");
|
|
661
|
+
n = Number(s);
|
|
662
|
+
} else a === "data" && r.push(s);
|
|
652
663
|
}
|
|
653
664
|
if (r.length === 0) return;
|
|
654
665
|
let i = r.join("\n");
|
|
655
666
|
if (!i || i === "[DONE]") return;
|
|
656
|
-
let
|
|
667
|
+
let a;
|
|
657
668
|
try {
|
|
658
|
-
|
|
669
|
+
a = JSON.parse(i);
|
|
659
670
|
} catch (e) {
|
|
660
|
-
throw new
|
|
671
|
+
throw new c("conversation_contract_mismatch", "Conversation stream contains invalid JSON.", { cause: e });
|
|
661
672
|
}
|
|
662
|
-
let
|
|
663
|
-
if (!
|
|
673
|
+
let s = N(a), l = N(s?.runtimeEvent) || N(s?.runtime_event) || (s?.schema_version === 2 ? s : null);
|
|
674
|
+
if (!s || s.conversationItem === void 0 && !l) {
|
|
664
675
|
n !== void 0 && (t.cursor = Math.max(t.cursor, n));
|
|
665
676
|
return;
|
|
666
677
|
}
|
|
667
|
-
if (n === void 0) throw new
|
|
668
|
-
let u =
|
|
678
|
+
if (n === void 0) throw new c("conversation_stream_error", "Canonical conversation items require an SSE replay cursor.");
|
|
679
|
+
let u = s.conversationItem === void 0 ? "runtime" : "native";
|
|
669
680
|
if (t.lane && t.lane !== u) {
|
|
670
681
|
t.cursor = Math.max(t.cursor, n);
|
|
671
682
|
return;
|
|
672
683
|
}
|
|
673
684
|
let d;
|
|
674
685
|
try {
|
|
675
|
-
d = u === "native" ?
|
|
686
|
+
d = u === "native" ? o(s.conversationItem) : t.runtime.apply(l);
|
|
676
687
|
} catch (e) {
|
|
677
|
-
throw new
|
|
688
|
+
throw new c("conversation_contract_mismatch", "Runtime conversation identity or lifecycle invariant failed.", { cause: e });
|
|
678
689
|
}
|
|
679
690
|
if (u === "runtime" && !d) {
|
|
680
691
|
t.cursor = Math.max(t.cursor, n);
|
|
681
692
|
return;
|
|
682
693
|
}
|
|
683
|
-
if (!d) throw new
|
|
684
|
-
if (t.runId && t.runId !== d.runId) throw new
|
|
694
|
+
if (!d) throw new c("conversation_contract_mismatch", "Conversation stream item does not match conversation.ksadk.io/v1.");
|
|
695
|
+
if (t.runId && t.runId !== d.runId) throw new c("conversation_contract_mismatch", "Conversation stream changed canonical run identity.", {
|
|
685
696
|
runId: t.runId,
|
|
686
697
|
cursor: t.cursor
|
|
687
698
|
});
|
|
@@ -690,28 +701,28 @@ function xe(e, t) {
|
|
|
690
701
|
try {
|
|
691
702
|
f = u === "runtime" ? !0 : t.reducer.apply(d);
|
|
692
703
|
} catch (e) {
|
|
693
|
-
throw new
|
|
704
|
+
throw new c("conversation_contract_mismatch", "Conversation identity or lifecycle invariant failed.", { cause: e });
|
|
694
705
|
}
|
|
695
|
-
t.cursor = Math.max(t.cursor, n), f && !(t.profile === "flat-v1" && d.nativeRef.parentScopeId) && t.options.onItem?.(d), t.options.onUpdate?.(
|
|
706
|
+
t.cursor = Math.max(t.cursor, n), f && !(t.profile === "flat-v1" && d.nativeRef.parentScopeId) && t.options.onItem?.(d), t.options.onUpdate?.(_e(t.reducer, t.cursor, t.runId, t.profile, t.lane === "runtime" ? t.runtime : void 0));
|
|
696
707
|
}
|
|
697
|
-
async function
|
|
698
|
-
if (!e.body) throw new
|
|
708
|
+
async function ye(e, t) {
|
|
709
|
+
if (!e.body) throw new c("conversation_stream_error", "Conversation response has no event stream body.");
|
|
699
710
|
let n = e.body.getReader(), r = new TextDecoder(), i = "";
|
|
700
711
|
try {
|
|
701
712
|
for (;;) {
|
|
702
|
-
|
|
713
|
+
P(t.options.signal);
|
|
703
714
|
let { value: e, done: a } = await n.read();
|
|
704
715
|
if (a) break;
|
|
705
716
|
i += r.decode(e, { stream: !0 });
|
|
706
717
|
let o = /\r?\n\r?\n/.exec(i);
|
|
707
718
|
for (; o?.index !== void 0;) {
|
|
708
719
|
let e = o.index, n = o[0].length;
|
|
709
|
-
|
|
720
|
+
ve(i.slice(0, e), t), i = i.slice(e + n), o = /\r?\n\r?\n/.exec(i);
|
|
710
721
|
}
|
|
711
722
|
}
|
|
712
|
-
i += r.decode(), i.trim() &&
|
|
723
|
+
i += r.decode(), i.trim() && ve(i, t);
|
|
713
724
|
} catch (e) {
|
|
714
|
-
throw e instanceof
|
|
725
|
+
throw e instanceof c ? e : (fe(e, t.options.signal) && P(t.options.signal), new c("conversation_stream_error", "Conversation event stream was interrupted.", {
|
|
715
726
|
cause: e,
|
|
716
727
|
runId: t.runId || void 0,
|
|
717
728
|
cursor: t.cursor
|
|
@@ -720,10 +731,10 @@ async function Se(e, t) {
|
|
|
720
731
|
n.releaseLock();
|
|
721
732
|
}
|
|
722
733
|
}
|
|
723
|
-
function
|
|
724
|
-
return e.state.items.some((e) =>
|
|
734
|
+
function be(e) {
|
|
735
|
+
return e.state.items.some((e) => O(e) !== void 0);
|
|
725
736
|
}
|
|
726
|
-
var
|
|
737
|
+
var xe = class {
|
|
727
738
|
fetcher;
|
|
728
739
|
ingressLane;
|
|
729
740
|
rendererCatalog;
|
|
@@ -732,61 +743,61 @@ var we = class {
|
|
|
732
743
|
sleep;
|
|
733
744
|
retryDelayMs;
|
|
734
745
|
constructor(e = {}) {
|
|
735
|
-
if (!Number.isInteger(e.maxReconnects ??
|
|
736
|
-
this.fetcher = e.fetch, this.rendererCatalog = e.rendererCatalog, this.ingressLane = e.ingressLane, this.baseUrl =
|
|
746
|
+
if (!Number.isInteger(e.maxReconnects ?? M) || (e.maxReconnects ?? M) < 0 || (e.maxReconnects ?? M) > 32) throw new c("conversation_contract_mismatch", "Conversation reconnect limit must be an integer from 0 to 32.");
|
|
747
|
+
this.fetcher = e.fetch, this.rendererCatalog = e.rendererCatalog, this.ingressLane = e.ingressLane, this.baseUrl = pe(e.baseUrl || ""), this.maxReconnects = e.maxReconnects ?? M, this.sleep = e.sleep || he, this.retryDelayMs = e.retryDelayMs || me;
|
|
737
748
|
}
|
|
738
749
|
fetch() {
|
|
739
750
|
if (this.fetcher) return this.fetcher;
|
|
740
751
|
if (typeof globalThis.fetch == "function") return globalThis.fetch.bind(globalThis);
|
|
741
|
-
throw new
|
|
752
|
+
throw new c("conversation_http_error", "No fetch implementation is available for the conversation client.");
|
|
742
753
|
}
|
|
743
754
|
url(e) {
|
|
744
755
|
return `${this.baseUrl}${e}`;
|
|
745
756
|
}
|
|
746
757
|
async request(e, t, n, r = "conversation_stream_error") {
|
|
747
|
-
|
|
758
|
+
P(n);
|
|
748
759
|
try {
|
|
749
760
|
return await this.fetch()(e, t);
|
|
750
761
|
} catch (e) {
|
|
751
|
-
throw e instanceof
|
|
762
|
+
throw e instanceof c ? e : (fe(e, n) && P(n), new c(r, "Conversation network request failed.", { cause: e }));
|
|
752
763
|
}
|
|
753
764
|
}
|
|
754
765
|
assertOk(e) {
|
|
755
|
-
if (!e.ok) throw new
|
|
766
|
+
if (!e.ok) throw new c("conversation_http_error", `Conversation endpoint returned HTTP ${e.status}.`, { status: e.status });
|
|
756
767
|
}
|
|
757
768
|
async getSurface(e, t, n = {}) {
|
|
758
|
-
if (!e || !t) throw new
|
|
769
|
+
if (!e || !t) throw new c("conversation_contract_mismatch", "Agent and session identities are required to get a conversation surface.");
|
|
759
770
|
let r = n.signal ? { signal: n.signal } : void 0, i = await this.request(this.url(`/api/v1/agents/${encodeURIComponent(e)}/conversation-surface?sessionId=${encodeURIComponent(t)}`), r, n.signal, "conversation_http_error");
|
|
760
771
|
this.assertOk(i);
|
|
761
772
|
let a;
|
|
762
773
|
try {
|
|
763
774
|
a = await i.json();
|
|
764
775
|
} catch (e) {
|
|
765
|
-
throw new
|
|
776
|
+
throw new c("conversation_contract_mismatch", "Conversation surface response is not valid JSON.", { cause: e });
|
|
766
777
|
}
|
|
767
|
-
let o =
|
|
768
|
-
if (!o || typeof o.buildId != "string" || !o.buildId || !
|
|
778
|
+
let o = N(a), s = u(o?.surface);
|
|
779
|
+
if (!o || typeof o.buildId != "string" || !o.buildId || !s) throw new c("conversation_contract_mismatch", "Conversation surface response does not match conversation.ksadk.io/v1.");
|
|
769
780
|
return {
|
|
770
781
|
buildId: o.buildId,
|
|
771
|
-
surface:
|
|
782
|
+
surface: s
|
|
772
783
|
};
|
|
773
784
|
}
|
|
774
785
|
async streamTurn(e) {
|
|
775
|
-
|
|
776
|
-
let t =
|
|
786
|
+
P(e.signal);
|
|
787
|
+
let t = a(e.bootstrap.surface, this.rendererCatalog), n = {
|
|
777
788
|
...e.input,
|
|
778
789
|
...t === "agent-block-v1" || e.input.extensions?.["ksadk.presentation"] ? { extensions: {
|
|
779
790
|
...e.input.extensions,
|
|
780
791
|
"ksadk.presentation": { profile: t }
|
|
781
792
|
} } : {}
|
|
782
793
|
};
|
|
783
|
-
|
|
784
|
-
let
|
|
785
|
-
if (o && this.ingressLane && o !== this.ingressLane) throw new
|
|
786
|
-
let
|
|
794
|
+
i(e.bootstrap.surface, n);
|
|
795
|
+
let r = e.bootstrap.surface.outputs.find((e) => e.name === "agent.block"), o = r?.mode === "native" ? "native" : r?.mode === "translated" ? "runtime" : void 0;
|
|
796
|
+
if (o && this.ingressLane && o !== this.ingressLane) throw new c("conversation_contract_mismatch", "Configured ingress lane disagrees with the conversation surface.");
|
|
797
|
+
let s = o || this.ingressLane || "native", u = new l(), d = {
|
|
787
798
|
profile: t,
|
|
788
|
-
lane:
|
|
789
|
-
runtime: new
|
|
799
|
+
lane: s,
|
|
800
|
+
runtime: new C(n.sessionId, u, t),
|
|
790
801
|
cursor: 0,
|
|
791
802
|
runId: "",
|
|
792
803
|
reducer: u,
|
|
@@ -802,29 +813,29 @@ var we = class {
|
|
|
802
813
|
}, p = await this.request(this.url(`/api/v1/builds/${encodeURIComponent(e.bootstrap.buildId)}/conversation:stream`), f, e.signal);
|
|
803
814
|
this.assertOk(p);
|
|
804
815
|
try {
|
|
805
|
-
await
|
|
816
|
+
await ye(p, d);
|
|
806
817
|
} catch (e) {
|
|
807
|
-
if (!(e instanceof
|
|
818
|
+
if (!(e instanceof c) || e.code !== "conversation_stream_error" || !d.runId) throw e;
|
|
808
819
|
}
|
|
809
|
-
let m =
|
|
810
|
-
if (
|
|
811
|
-
if (!d.runId) throw new
|
|
820
|
+
let m = _e(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0);
|
|
821
|
+
if (be(m)) return m;
|
|
822
|
+
if (!d.runId) throw new c("conversation_run_identity_missing", "The stream ended before a canonical item supplied its run identity.", { cursor: d.cursor });
|
|
812
823
|
for (let t = 1; t <= this.maxReconnects; t += 1) {
|
|
813
|
-
await
|
|
824
|
+
await ge(this.sleep, this.retryDelayMs(t), e.signal), P(e.signal);
|
|
814
825
|
let n;
|
|
815
826
|
try {
|
|
816
827
|
n = await this.request(this.url(`/api/v1/runs/${encodeURIComponent(d.runId)}/events?after=${d.cursor}${d.profile === "agent-block-v1" ? "&presentationProfile=agent-block-v1" : ""}`), {
|
|
817
828
|
method: "GET",
|
|
818
829
|
headers: { "Last-Event-ID": String(d.cursor) },
|
|
819
830
|
...e.signal ? { signal: e.signal } : {}
|
|
820
|
-
}, e.signal), this.assertOk(n), await
|
|
831
|
+
}, e.signal), this.assertOk(n), await ye(n, d);
|
|
821
832
|
} catch (e) {
|
|
822
|
-
if (e instanceof
|
|
833
|
+
if (e instanceof c && e.code === "conversation_aborted" || e instanceof c && e.code === "conversation_contract_mismatch" || e instanceof c && e.code === "conversation_http_error" && e.status !== void 0 && e.status < 500) throw e;
|
|
823
834
|
continue;
|
|
824
835
|
}
|
|
825
|
-
if (m =
|
|
836
|
+
if (m = _e(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0), be(m)) return m;
|
|
826
837
|
}
|
|
827
|
-
throw new
|
|
838
|
+
throw new c("conversation_reconnect_exhausted", "Conversation replay stopped after the configured reconnect limit.", {
|
|
828
839
|
runId: d.runId,
|
|
829
840
|
cursor: d.cursor
|
|
830
841
|
});
|
|
@@ -832,13 +843,13 @@ var we = class {
|
|
|
832
843
|
};
|
|
833
844
|
//#endregion
|
|
834
845
|
//#region src/core/conversation/renderer-registry.ts
|
|
835
|
-
function
|
|
846
|
+
function Se(e, t) {
|
|
836
847
|
if (!e.trim()) throw Error(`trusted conversation renderer ${t} must not be empty`);
|
|
837
848
|
}
|
|
838
|
-
function
|
|
849
|
+
function Ce(e) {
|
|
839
850
|
let t = /* @__PURE__ */ new Map();
|
|
840
851
|
for (let n of e) {
|
|
841
|
-
if (
|
|
852
|
+
if (Se(n.id, "id"), Se(n.schemaRef, "schemaRef"), !n.kinds.length) throw Error("trusted conversation renderer kinds must not be empty");
|
|
842
853
|
if (t.has(n.schemaRef)) throw Error(`duplicate trusted conversation renderer schemaRef: ${n.schemaRef}`);
|
|
843
854
|
t.set(n.schemaRef, Object.freeze({
|
|
844
855
|
...n,
|
|
@@ -856,14 +867,14 @@ function Ee(e) {
|
|
|
856
867
|
}
|
|
857
868
|
});
|
|
858
869
|
}
|
|
859
|
-
var
|
|
870
|
+
var we = Ce([{
|
|
860
871
|
id: "ksadk.agent-block",
|
|
861
872
|
schemaRef: "conversation.item.agent/v1",
|
|
862
873
|
kinds: ["agent"]
|
|
863
874
|
}]);
|
|
864
875
|
//#endregion
|
|
865
876
|
//#region src/utils/history-tool-facts.ts
|
|
866
|
-
function
|
|
877
|
+
function F(e, t) {
|
|
867
878
|
let n = (e) => e === "completed" || e === "error", r = t.output === void 0 ? e.output : t.output;
|
|
868
879
|
return {
|
|
869
880
|
args: t.args || e.args,
|
|
@@ -871,7 +882,7 @@ function j(e, t) {
|
|
|
871
882
|
status: n(e.status) && !n(t.status) ? e.status : t.status
|
|
872
883
|
};
|
|
873
884
|
}
|
|
874
|
-
function
|
|
885
|
+
function I(e) {
|
|
875
886
|
let t = e.map((e) => ({
|
|
876
887
|
...e,
|
|
877
888
|
tools: e.tools ? { ...e.tools } : void 0
|
|
@@ -896,11 +907,11 @@ function M(e) {
|
|
|
896
907
|
let r = e.message.tools[e.key], i = n ? {
|
|
897
908
|
...t,
|
|
898
909
|
...r,
|
|
899
|
-
...
|
|
910
|
+
...F(t, r)
|
|
900
911
|
} : {
|
|
901
912
|
...r,
|
|
902
913
|
...t,
|
|
903
|
-
...
|
|
914
|
+
...F(r, t)
|
|
904
915
|
};
|
|
905
916
|
e.message.tools[e.key] = i, e.message.blocks = e.message.blocks?.map((e) => e.type === "tool" && e.extra?.callId === t.callId ? {
|
|
906
917
|
...e,
|
|
@@ -939,18 +950,18 @@ function M(e) {
|
|
|
939
950
|
}
|
|
940
951
|
//#endregion
|
|
941
952
|
//#region src/utils/transcript-order.ts
|
|
942
|
-
var
|
|
943
|
-
function
|
|
953
|
+
var L = (e) => e.runId || e.invocationId;
|
|
954
|
+
function R(e) {
|
|
944
955
|
let t = /* @__PURE__ */ new Map();
|
|
945
956
|
for (let n of e) {
|
|
946
|
-
let e =
|
|
957
|
+
let e = L(n), r = n.historyOrder?.group;
|
|
947
958
|
e && r !== void 0 && t.set(e, Math.min(r, t.get(e) ?? r));
|
|
948
959
|
}
|
|
949
960
|
let n = e.map((e, n) => ({
|
|
950
961
|
message: e,
|
|
951
962
|
index: n,
|
|
952
963
|
seq: e.historyOrder?.seq,
|
|
953
|
-
group: e.historyOrder?.group ?? t.get(
|
|
964
|
+
group: e.historyOrder?.group ?? t.get(L(e) || "") ?? e.historyOrder?.seq,
|
|
954
965
|
part: e.historyOrder?.index || 0
|
|
955
966
|
})), r, i = n.map(() => void 0);
|
|
956
967
|
for (let e = n.length - 1; e >= 0; e--) i[e] = r, n[e].group !== void 0 && (r = n[e].group);
|
|
@@ -965,13 +976,13 @@ function P(e) {
|
|
|
965
976
|
side: 0
|
|
966
977
|
})).sort((e, t) => e.anchor - t.anchor || e.side - t.side || (e.side === 0 ? (e.seq ?? e.anchor) - (t.seq ?? t.anchor) : 0) || (e.side === 0 ? e.part - t.part : 0) || e.index - t.index).map((e) => e.message);
|
|
967
978
|
}
|
|
968
|
-
function
|
|
979
|
+
function Te(e, t) {
|
|
969
980
|
if (!t) return !0;
|
|
970
981
|
let n = (n) => n === "feedback" ? !1 : n === "historyOrder" ? e.historyOrder?.seq !== t.historyOrder?.seq || e.historyOrder?.index !== t.historyOrder?.index || e.historyOrder?.group !== t.historyOrder?.group : e[n] !== t[n];
|
|
971
982
|
return Object.keys(e).some(n) || Object.keys(t).some(n);
|
|
972
983
|
}
|
|
973
|
-
function
|
|
974
|
-
let r = new Map(t.map((e) => [e.id, e])), i = n.filter((e) => r.has(e.id) && r.get(e.id)?.feedback !== e.feedback), a = new Map(i.map((e) => [e.id, e.feedback])), o = (e) => JSON.stringify([
|
|
984
|
+
function Ee(e, t, n) {
|
|
985
|
+
let r = new Map(t.map((e) => [e.id, e])), i = n.filter((e) => r.has(e.id) && r.get(e.id)?.feedback !== e.feedback), a = new Map(i.map((e) => [e.id, e.feedback])), o = (e) => JSON.stringify([L(e), e.responseId]), s = new Map(i.filter((e) => e.responseId).map((e) => [o(e), e.feedback])), c = (e) => e.map((e) => {
|
|
975
986
|
if (a.has(e.id)) return {
|
|
976
987
|
...e,
|
|
977
988
|
feedback: a.get(e.id)
|
|
@@ -981,19 +992,19 @@ function ke(e, t, n) {
|
|
|
981
992
|
...e,
|
|
982
993
|
feedback: s.get(t)
|
|
983
994
|
} : e;
|
|
984
|
-
}), l = n.filter((e) =>
|
|
985
|
-
if (!l.length) return
|
|
986
|
-
let u = new Set(l.map(
|
|
995
|
+
}), l = n.filter((e) => Te(e, r.get(e.id)));
|
|
996
|
+
if (!l.length) return D(I(c(e)));
|
|
997
|
+
let u = new Set(l.map(L).filter(Boolean)), d = new Set(l.map((e) => e.id)), f = n.filter((e) => u.has(L(e)) || d.has(e.id)), p = e;
|
|
987
998
|
for (let t of u) {
|
|
988
|
-
let n = f.filter((e) =>
|
|
989
|
-
p = p.filter((e) =>
|
|
999
|
+
let n = f.filter((e) => L(e) === t), r = e.filter((e) => L(e) === t), i = p.findIndex((e) => L(e) === t), a = n.some((e) => e.role === "user") ? [] : r.filter((e) => e.role === "user");
|
|
1000
|
+
p = p.filter((e) => L(e) !== t);
|
|
990
1001
|
let o = i < 0 ? p.length : Math.min(i, p.length);
|
|
991
1002
|
p.splice(o, 0, ...a, ...n.map((e) => ({
|
|
992
1003
|
...e,
|
|
993
1004
|
historyOrder: e.historyOrder || r.find((t) => t.id === e.id)?.historyOrder
|
|
994
1005
|
})));
|
|
995
1006
|
}
|
|
996
|
-
for (let e of f.filter((e) => !
|
|
1007
|
+
for (let e of f.filter((e) => !L(e))) {
|
|
997
1008
|
let t = p.findIndex((t) => t.id === e.id);
|
|
998
1009
|
if (t < 0) {
|
|
999
1010
|
let t = n.indexOf(e), r = n.slice(t + 1).find((e) => p.some((t) => t.id === e.id)), i = n.slice(0, t).findLast((e) => p.some((t) => t.id === e.id)), a = r ? p.findIndex((e) => e.id === r.id) : i ? p.findIndex((e) => e.id === i.id) + 1 : p.length;
|
|
@@ -1007,18 +1018,18 @@ function ke(e, t, n) {
|
|
|
1007
1018
|
historyOrder: e.historyOrder || n.historyOrder
|
|
1008
1019
|
} : n);
|
|
1009
1020
|
}
|
|
1010
|
-
return
|
|
1021
|
+
return D(I(c(R(p))));
|
|
1011
1022
|
}
|
|
1012
1023
|
//#endregion
|
|
1013
1024
|
//#region src/core/conversation/hosted.ts
|
|
1014
|
-
var
|
|
1015
|
-
function
|
|
1025
|
+
var De = "conversation_item_v1";
|
|
1026
|
+
function z(e) {
|
|
1016
1027
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
1017
1028
|
}
|
|
1018
|
-
function
|
|
1029
|
+
function B(e) {
|
|
1019
1030
|
return typeof e == "string" && e.trim() ? e : null;
|
|
1020
1031
|
}
|
|
1021
|
-
function
|
|
1032
|
+
function V(e) {
|
|
1022
1033
|
if (typeof e == "string") return e;
|
|
1023
1034
|
if (e == null) return "";
|
|
1024
1035
|
try {
|
|
@@ -1027,24 +1038,24 @@ function I(e) {
|
|
|
1027
1038
|
return String(e);
|
|
1028
1039
|
}
|
|
1029
1040
|
}
|
|
1030
|
-
function
|
|
1041
|
+
function H(e) {
|
|
1031
1042
|
return {
|
|
1032
1043
|
id: `conversation:${e.runId}:${e.itemId}`,
|
|
1033
1044
|
timestamp: 0,
|
|
1034
|
-
eventType:
|
|
1045
|
+
eventType: De,
|
|
1035
1046
|
eventId: e.sourceEventIds.at(-1),
|
|
1036
1047
|
runId: e.runId,
|
|
1037
1048
|
itemId: e.itemId,
|
|
1038
1049
|
status: e.lifecycle === "failed" ? "failed" : e.lifecycle === "completed" ? "completed" : "running"
|
|
1039
1050
|
};
|
|
1040
1051
|
}
|
|
1041
|
-
function
|
|
1052
|
+
function Oe(e) {
|
|
1042
1053
|
return e.lifecycle === "failed" ? "error" : e.lifecycle === "completed" ? "done" : "streaming";
|
|
1043
1054
|
}
|
|
1044
|
-
function
|
|
1055
|
+
function ke(e) {
|
|
1045
1056
|
let t = typeof e.payload.text == "string" ? e.payload.text : "";
|
|
1046
1057
|
if (e.kind === "user_message") return {
|
|
1047
|
-
...
|
|
1058
|
+
...H(e),
|
|
1048
1059
|
role: "user",
|
|
1049
1060
|
content: t,
|
|
1050
1061
|
eventType: "user_message"
|
|
@@ -1053,31 +1064,31 @@ function Ne(e) {
|
|
|
1053
1064
|
id: `conversation-block:${e.itemId}`,
|
|
1054
1065
|
type: "thinking",
|
|
1055
1066
|
content: t,
|
|
1056
|
-
status:
|
|
1067
|
+
status: Oe(e),
|
|
1057
1068
|
...e.payload.presentationSource === "public_summary" || e.payload.presentationSource === "provider_reasoning" ? { source: e.payload.presentationSource } : {}
|
|
1058
1069
|
} : {
|
|
1059
1070
|
id: `conversation-block:${e.itemId}`,
|
|
1060
1071
|
type: "text",
|
|
1061
1072
|
content: t,
|
|
1062
|
-
status:
|
|
1073
|
+
status: Oe(e)
|
|
1063
1074
|
};
|
|
1064
1075
|
return {
|
|
1065
|
-
...
|
|
1076
|
+
...H(e),
|
|
1066
1077
|
role: "model",
|
|
1067
1078
|
content: e.kind === "assistant_text" ? t : "",
|
|
1068
1079
|
reasoning: e.kind === "reasoning" ? t : void 0,
|
|
1069
1080
|
blocks: [n]
|
|
1070
1081
|
};
|
|
1071
1082
|
}
|
|
1072
|
-
function
|
|
1073
|
-
let n =
|
|
1083
|
+
function Ae(e, t = !1) {
|
|
1084
|
+
let n = B(e.payload.tool) || (e.payload.sourceKind === "tool_result" ? "Tool result" : "Tool"), r = B(e.payload.callId), i = V(v(e.payload.args)), a = Object.prototype.hasOwnProperty.call(e.payload, "output") ? V(y(e.payload.output, e.nativeRef.framework, e.nativeRef.protocol)) : void 0, o = {
|
|
1074
1085
|
failed: "error",
|
|
1075
1086
|
completed: "completed",
|
|
1076
1087
|
running: "running",
|
|
1077
1088
|
unknown: "unknown"
|
|
1078
1089
|
}, s = e.payload.executionStatus, c = typeof s == "string" && Object.hasOwn(o, s) ? o[s] : e.lifecycle === "failed" || e.payload.isError === !0 ? "error" : e.lifecycle === "completed" ? "completed" : "running", l = t && c === "running" ? "unknown" : c;
|
|
1079
1090
|
return {
|
|
1080
|
-
...
|
|
1091
|
+
...H(e),
|
|
1081
1092
|
role: "model",
|
|
1082
1093
|
content: "",
|
|
1083
1094
|
blocks: [{
|
|
@@ -1098,55 +1109,55 @@ function Pe(e, t = !1) {
|
|
|
1098
1109
|
} }
|
|
1099
1110
|
};
|
|
1100
1111
|
}
|
|
1101
|
-
function
|
|
1112
|
+
function je(e) {
|
|
1102
1113
|
return e === "structured_input" ? "structured_input" : e === "plan_review" ? "plan_review" : e === "custom" ? "custom" : "approval";
|
|
1103
1114
|
}
|
|
1104
|
-
function
|
|
1105
|
-
let n =
|
|
1115
|
+
function Me(t) {
|
|
1116
|
+
let n = B(t.payload.interactionId), r = t.payload.revision;
|
|
1106
1117
|
if (!n || !Number.isInteger(r) || Number(r) < 1) return null;
|
|
1107
|
-
let i =
|
|
1108
|
-
if (s && Object.hasOwn(
|
|
1109
|
-
c = { response: t
|
|
1118
|
+
let i = V(t.payload.detail), a = B(t.payload.prompt) || i, o = je(t.payload.interactionKind), s = t.lifecycle === "completed", c = {};
|
|
1119
|
+
if (s && Object.hasOwn(t.payload, "response")) try {
|
|
1120
|
+
c = { response: e(t.payload.response) };
|
|
1110
1121
|
} catch {}
|
|
1111
1122
|
return {
|
|
1112
1123
|
interactionId: n,
|
|
1113
|
-
sessionId:
|
|
1114
|
-
runId:
|
|
1124
|
+
sessionId: t.sessionId,
|
|
1125
|
+
runId: t.runId,
|
|
1115
1126
|
kind: o,
|
|
1116
|
-
title:
|
|
1127
|
+
title: B(t.payload.title) || (o === "approval" ? `审批:${B(t.payload.kind) || "操作"}` : "需要补充信息"),
|
|
1117
1128
|
message: a || "运行需要人工确认。",
|
|
1118
|
-
requestSchema:
|
|
1129
|
+
requestSchema: z(t.payload.inputSchema),
|
|
1119
1130
|
presentation: null,
|
|
1120
1131
|
status: s ? "resolved" : "pending",
|
|
1121
1132
|
revision: Number(r),
|
|
1122
|
-
createdAt:
|
|
1123
|
-
expiresAt:
|
|
1124
|
-
resolvedAt: s ?
|
|
1125
|
-
actor: s ?
|
|
1133
|
+
createdAt: B(t.payload.createdAt) || "",
|
|
1134
|
+
expiresAt: B(t.payload.expiresAt),
|
|
1135
|
+
resolvedAt: s ? B(t.payload.resolvedAt) : null,
|
|
1136
|
+
actor: s ? B(t.payload.actor) : null,
|
|
1126
1137
|
outcome: s && [
|
|
1127
1138
|
"approved",
|
|
1128
1139
|
"rejected",
|
|
1129
1140
|
"submitted",
|
|
1130
1141
|
"cancelled",
|
|
1131
1142
|
"expired"
|
|
1132
|
-
].includes(String(
|
|
1133
|
-
responseSummary: s ?
|
|
1143
|
+
].includes(String(t.payload.outcome || "")) ? t.payload.outcome : null,
|
|
1144
|
+
responseSummary: s ? B(t.payload.responseSummary) : null,
|
|
1134
1145
|
...c,
|
|
1135
1146
|
source: "interaction_v1",
|
|
1136
1147
|
extensions: {
|
|
1137
|
-
conversation_item_id:
|
|
1138
|
-
...
|
|
1148
|
+
conversation_item_id: t.itemId,
|
|
1149
|
+
...B(t.payload.callId) ? { call_id: B(t.payload.callId) } : {}
|
|
1139
1150
|
}
|
|
1140
1151
|
};
|
|
1141
1152
|
}
|
|
1142
|
-
function
|
|
1143
|
-
let n =
|
|
1153
|
+
function Ne(e, t) {
|
|
1154
|
+
let n = B(e.payload.kind) || "approval", r = V(e.payload.detail), i = t.status === "resolved" ? t.outcome === "rejected" ? "rejected" : t.outcome === "cancelled" || t.outcome === "expired" ? "cancelled" : "approved" : "pending", a = t.status === "pending" ? "paused" : "completed", o = {
|
|
1144
1155
|
approvalRequestId: t.interactionId,
|
|
1145
1156
|
approvalStatus: i,
|
|
1146
1157
|
approvalMessage: t.message
|
|
1147
1158
|
};
|
|
1148
1159
|
return {
|
|
1149
|
-
...
|
|
1160
|
+
...H(e),
|
|
1150
1161
|
role: "model",
|
|
1151
1162
|
content: "",
|
|
1152
1163
|
blocks: [{
|
|
@@ -1167,26 +1178,26 @@ function Le(e, t) {
|
|
|
1167
1178
|
} }
|
|
1168
1179
|
};
|
|
1169
1180
|
}
|
|
1170
|
-
function
|
|
1181
|
+
function Pe(e) {
|
|
1171
1182
|
for (let t of [
|
|
1172
1183
|
"createSurface",
|
|
1173
1184
|
"updateComponents",
|
|
1174
1185
|
"updateDataModel",
|
|
1175
1186
|
"deleteSurface"
|
|
1176
1187
|
]) {
|
|
1177
|
-
let n =
|
|
1188
|
+
let n = B(z(e[t])?.surfaceId);
|
|
1178
1189
|
if (n) return n;
|
|
1179
1190
|
}
|
|
1180
1191
|
return null;
|
|
1181
1192
|
}
|
|
1182
|
-
function
|
|
1193
|
+
function Fe(e) {
|
|
1183
1194
|
let t = Array.isArray(e.payload.data) ? e.payload.data : Array.isArray(e.payload.operations) ? e.payload.operations : null;
|
|
1184
1195
|
if (!t) return null;
|
|
1185
|
-
let n = t.map(
|
|
1196
|
+
let n = t.map(z);
|
|
1186
1197
|
if (n.some((e) => e === null)) return null;
|
|
1187
|
-
let r = n, i =
|
|
1198
|
+
let r = n, i = B(e.payload.surfaceId) || r.map(Pe).find((e) => e !== null) || null;
|
|
1188
1199
|
return i ? {
|
|
1189
|
-
...
|
|
1200
|
+
...H(e),
|
|
1190
1201
|
role: "a2ui",
|
|
1191
1202
|
content: "",
|
|
1192
1203
|
aguiActivity: {
|
|
@@ -1196,18 +1207,18 @@ function ze(e) {
|
|
|
1196
1207
|
}
|
|
1197
1208
|
} : null;
|
|
1198
1209
|
}
|
|
1199
|
-
function
|
|
1210
|
+
function U(e, t, n, r = !1) {
|
|
1200
1211
|
return {
|
|
1201
|
-
...
|
|
1212
|
+
...H(e),
|
|
1202
1213
|
role: "system",
|
|
1203
1214
|
content: n ? `${t}: ${n}` : t,
|
|
1204
|
-
status: r ? "failed" :
|
|
1215
|
+
status: r ? "failed" : H(e).status
|
|
1205
1216
|
};
|
|
1206
1217
|
}
|
|
1207
|
-
function
|
|
1218
|
+
function Ie(e) {
|
|
1208
1219
|
for (let { item: t } of [...e].reverse()) {
|
|
1209
1220
|
if (t.visibility !== "public" || t.kind !== "assistant_text" || t.payloadSchemaRef !== "conversation.item.assistant_text/v1" || typeof t.payload.text != "string") continue;
|
|
1210
|
-
let e =
|
|
1221
|
+
let e = v(t.payload.text);
|
|
1211
1222
|
if (typeof e != "string" || e === "[redacted]") continue;
|
|
1212
1223
|
let n = e.replace(/\s+/g, " ").trim();
|
|
1213
1224
|
if (!n) continue;
|
|
@@ -1215,16 +1226,16 @@ function Be(e) {
|
|
|
1215
1226
|
return r.length > 160 ? `${r.slice(0, 160).join("")}…` : n;
|
|
1216
1227
|
}
|
|
1217
1228
|
}
|
|
1218
|
-
function
|
|
1229
|
+
function W(e) {
|
|
1219
1230
|
let t = e.presentation, n = new Map(t.textItems.map((e) => [e.id, e])), r = new Set(t.toolItems.map((e) => e.itemId)), i = new Set(t.approvalItems.map((e) => e.itemId)), a = new Set(t.structuredInputItems.map((e) => e.itemId)), o = new Set(t.a2uiItems.map((e) => e.itemId)), s = new Map(t.artifacts.map((e) => [e.id, e])), c = new Map(t.fallbacks.map((e) => [e.id, e])), l = [], u = [];
|
|
1220
1231
|
for (let d of t.timeline) {
|
|
1221
1232
|
let { item: f } = d;
|
|
1222
1233
|
if (f.kind === "agent") {
|
|
1223
1234
|
if (!d.children) {
|
|
1224
|
-
l.push(
|
|
1235
|
+
l.push(U(f, "Remote agent", String(f.payload.status || "submitted")));
|
|
1225
1236
|
continue;
|
|
1226
1237
|
}
|
|
1227
|
-
let n =
|
|
1238
|
+
let n = W({
|
|
1228
1239
|
...e,
|
|
1229
1240
|
presentation: {
|
|
1230
1241
|
...t,
|
|
@@ -1232,40 +1243,40 @@ function z(e) {
|
|
|
1232
1243
|
}
|
|
1233
1244
|
});
|
|
1234
1245
|
l.push({
|
|
1235
|
-
...
|
|
1246
|
+
...H(f),
|
|
1236
1247
|
role: "model",
|
|
1237
1248
|
content: "",
|
|
1238
1249
|
agentBlock: {
|
|
1239
1250
|
item: f,
|
|
1240
1251
|
messages: n.messages,
|
|
1241
|
-
summary:
|
|
1252
|
+
summary: Ie(d.children || [])
|
|
1242
1253
|
},
|
|
1243
|
-
status: f.payload.status === "cancelled" ? "cancelled" :
|
|
1254
|
+
status: f.payload.status === "cancelled" ? "cancelled" : H(f).status
|
|
1244
1255
|
}), u.push(...n.interactions);
|
|
1245
1256
|
continue;
|
|
1246
1257
|
}
|
|
1247
1258
|
if (n.has(f.itemId)) {
|
|
1248
|
-
l.push(
|
|
1259
|
+
l.push(ke(f));
|
|
1249
1260
|
continue;
|
|
1250
1261
|
}
|
|
1251
1262
|
if (r.has(f.itemId)) {
|
|
1252
|
-
l.push(
|
|
1263
|
+
l.push(Ae(f, !!t.terminalStatus && f.runId === e.runId));
|
|
1253
1264
|
continue;
|
|
1254
1265
|
}
|
|
1255
1266
|
if (i.has(f.itemId) || a.has(f.itemId)) {
|
|
1256
|
-
let e =
|
|
1257
|
-
e ? (u.push(e), l.push(
|
|
1267
|
+
let e = Me(f);
|
|
1268
|
+
e ? (u.push(e), l.push(Ne(f, e))) : l.push(U(f, "Interaction unavailable", "The server did not provide a durable interaction revision; this card is read-only."));
|
|
1258
1269
|
continue;
|
|
1259
1270
|
}
|
|
1260
1271
|
if (o.has(f.itemId)) {
|
|
1261
|
-
let e =
|
|
1262
|
-
l.push(e ||
|
|
1272
|
+
let e = Fe(f);
|
|
1273
|
+
l.push(e || U(f, "Unsupported content", "A2UI payload is not a valid passive operation list."));
|
|
1263
1274
|
continue;
|
|
1264
1275
|
}
|
|
1265
1276
|
let p = s.get(f.itemId);
|
|
1266
1277
|
if (p) {
|
|
1267
1278
|
l.push(p.status === "pending" ? {
|
|
1268
|
-
...
|
|
1279
|
+
...H(f),
|
|
1269
1280
|
role: "model",
|
|
1270
1281
|
content: p.name,
|
|
1271
1282
|
attachments: [{
|
|
@@ -1279,7 +1290,7 @@ function z(e) {
|
|
|
1279
1290
|
status: "pending"
|
|
1280
1291
|
}]
|
|
1281
1292
|
} : p.status === "ready" && p.uri ? {
|
|
1282
|
-
...
|
|
1293
|
+
...H(f),
|
|
1283
1294
|
role: "model",
|
|
1284
1295
|
content: p.name,
|
|
1285
1296
|
attachments: [{
|
|
@@ -1292,13 +1303,13 @@ function z(e) {
|
|
|
1292
1303
|
sizeBytes: p.sizeBytes,
|
|
1293
1304
|
status: p.status
|
|
1294
1305
|
}]
|
|
1295
|
-
} :
|
|
1306
|
+
} : U(f, "Artifact unavailable", p.status === "failed" ? "The artifact failed to generate or its URI is not a safe HTTP(S) link." : "The artifact URI is not a safe HTTP(S) link."));
|
|
1296
1307
|
continue;
|
|
1297
1308
|
}
|
|
1298
1309
|
let m = c.get(f.itemId);
|
|
1299
1310
|
if (m) {
|
|
1300
1311
|
if (f.kind === "error" && ["cancelled", "canceled"].includes(String(f.payload.status || "").toLowerCase())) continue;
|
|
1301
|
-
l.push(
|
|
1312
|
+
l.push(U(f, m.title, m.detail, m.failed));
|
|
1302
1313
|
}
|
|
1303
1314
|
}
|
|
1304
1315
|
return {
|
|
@@ -1306,8 +1317,8 @@ function z(e) {
|
|
|
1306
1317
|
interactions: u
|
|
1307
1318
|
};
|
|
1308
1319
|
}
|
|
1309
|
-
function
|
|
1310
|
-
let r =
|
|
1320
|
+
function Le(e, t, n) {
|
|
1321
|
+
let r = W(t).messages;
|
|
1311
1322
|
if (!r.length) return e;
|
|
1312
1323
|
let i = e.filter((e) => e.eventType !== "optimistic_assistant_placeholder"), a = (e) => e.runId === t.runId || e.invocationId === t.runId, o = i.findIndex(a), s = n ? i.findIndex((e) => e.id === n) : o < 0 ? i.findLastIndex((e) => e.role === "user" && e.eventType === "optimistic_user_message") : i.findIndex((e) => e.role === "user" && a(e)), c = i[s], l = i.filter((e, t) => t !== s && !a(e)), u = [s, o].filter((e) => e >= 0), d = u.length ? Math.min(...u) : l.length, f = c && !r.some((e) => e.role === "user") ? [{
|
|
1313
1324
|
...c,
|
|
@@ -1323,46 +1334,46 @@ function Ve(e, t, n) {
|
|
|
1323
1334
|
}
|
|
1324
1335
|
//#endregion
|
|
1325
1336
|
//#region src/core/run/blocks.ts
|
|
1326
|
-
var
|
|
1327
|
-
function
|
|
1328
|
-
return
|
|
1337
|
+
var Re = 0;
|
|
1338
|
+
function G(e) {
|
|
1339
|
+
return Re += 1, `${e}-${Re}`;
|
|
1329
1340
|
}
|
|
1330
|
-
function
|
|
1341
|
+
function K(e) {
|
|
1331
1342
|
return e.map((e) => e.type === "thinking" && e.status === "streaming" ? {
|
|
1332
1343
|
...e,
|
|
1333
1344
|
status: "done"
|
|
1334
1345
|
} : e);
|
|
1335
1346
|
}
|
|
1336
|
-
function
|
|
1347
|
+
function ze(e, t) {
|
|
1337
1348
|
let n = [...e ?? []], r = n[n.length - 1];
|
|
1338
1349
|
return r?.type === "thinking" && r.status === "streaming" ? (n[n.length - 1] = {
|
|
1339
1350
|
...r,
|
|
1340
1351
|
content: r.content + t
|
|
1341
1352
|
}, n) : [...n, {
|
|
1342
|
-
id:
|
|
1353
|
+
id: G("thinking"),
|
|
1343
1354
|
type: "thinking",
|
|
1344
1355
|
content: t,
|
|
1345
1356
|
status: "streaming"
|
|
1346
1357
|
}];
|
|
1347
1358
|
}
|
|
1348
|
-
function
|
|
1349
|
-
let n = [...
|
|
1359
|
+
function Be(e, t) {
|
|
1360
|
+
let n = [...K(e ?? [])], r = n[n.length - 1];
|
|
1350
1361
|
return r?.type === "text" && r.status === "streaming" ? (n[n.length - 1] = {
|
|
1351
1362
|
...r,
|
|
1352
1363
|
content: r.content + t
|
|
1353
1364
|
}, n) : [...n, {
|
|
1354
|
-
id:
|
|
1365
|
+
id: G("text"),
|
|
1355
1366
|
type: "text",
|
|
1356
1367
|
content: t,
|
|
1357
1368
|
status: "streaming"
|
|
1358
1369
|
}];
|
|
1359
1370
|
}
|
|
1360
|
-
function
|
|
1371
|
+
function Ve(e, t) {
|
|
1361
1372
|
let n = e ?? [], r = n.filter((e) => e.type === "text").map((e) => e.content).join("");
|
|
1362
1373
|
if (r === t) return n;
|
|
1363
1374
|
let i = n.flatMap((e, t) => e.type === "text" ? [t] : []);
|
|
1364
1375
|
if (!i.length) return [...n, {
|
|
1365
|
-
id:
|
|
1376
|
+
id: G("text"),
|
|
1366
1377
|
type: "text",
|
|
1367
1378
|
content: t,
|
|
1368
1379
|
status: "streaming"
|
|
@@ -1386,8 +1397,8 @@ function Ge(e, t) {
|
|
|
1386
1397
|
};
|
|
1387
1398
|
});
|
|
1388
1399
|
}
|
|
1389
|
-
function
|
|
1390
|
-
let n =
|
|
1400
|
+
function He(e, t) {
|
|
1401
|
+
let n = K(e ?? []);
|
|
1391
1402
|
if (n.filter((e) => e.type === "text").map((e) => e.content).join("") === t) return n.map((e) => e.type === "text" && e.status === "streaming" ? {
|
|
1392
1403
|
...e,
|
|
1393
1404
|
status: "done"
|
|
@@ -1398,13 +1409,13 @@ function Ke(e, t) {
|
|
|
1398
1409
|
content: t,
|
|
1399
1410
|
status: "done"
|
|
1400
1411
|
}, r) : [...r, {
|
|
1401
|
-
id:
|
|
1412
|
+
id: G("text"),
|
|
1402
1413
|
type: "text",
|
|
1403
1414
|
content: t,
|
|
1404
1415
|
status: "done"
|
|
1405
1416
|
}];
|
|
1406
1417
|
}
|
|
1407
|
-
function
|
|
1418
|
+
function Ue(e, t) {
|
|
1408
1419
|
if (!t) return [...e ?? []];
|
|
1409
1420
|
let n = [...e ?? []], r = n[n.length - 1];
|
|
1410
1421
|
if (r?.type !== "thinking" || !r.content.endsWith(t)) return n;
|
|
@@ -1414,8 +1425,8 @@ function qe(e, t) {
|
|
|
1414
1425
|
content: i
|
|
1415
1426
|
}, n) : (n.pop(), n);
|
|
1416
1427
|
}
|
|
1417
|
-
function
|
|
1418
|
-
let r = [...
|
|
1428
|
+
function We(e, t, n) {
|
|
1429
|
+
let r = [...K(e ?? [])], i = r.findIndex((e) => e.type === "tool" && e.toolName === t);
|
|
1419
1430
|
if (i >= 0 && r[i].type === "tool") {
|
|
1420
1431
|
let e = r[i], t = e.status === "error" || e.status === "completed", a = n.output !== void 0, o = n.extra && (n.extra.approvalRequestId || n.extra.approvalStatus);
|
|
1421
1432
|
if (t && !a && !o) return r;
|
|
@@ -1427,7 +1438,7 @@ function Je(e, t, n) {
|
|
|
1427
1438
|
}, r;
|
|
1428
1439
|
}
|
|
1429
1440
|
return [...r, {
|
|
1430
|
-
id:
|
|
1441
|
+
id: G("tool"),
|
|
1431
1442
|
type: "tool",
|
|
1432
1443
|
toolName: t,
|
|
1433
1444
|
args: n.args ?? "",
|
|
@@ -1436,19 +1447,19 @@ function Je(e, t, n) {
|
|
|
1436
1447
|
extra: n.extra
|
|
1437
1448
|
}];
|
|
1438
1449
|
}
|
|
1439
|
-
function
|
|
1440
|
-
return
|
|
1450
|
+
function Ge(e) {
|
|
1451
|
+
return K(e ?? []);
|
|
1441
1452
|
}
|
|
1442
|
-
function
|
|
1453
|
+
function Ke(e) {
|
|
1443
1454
|
let t = [];
|
|
1444
1455
|
if (e.reasoning && e.reasoning.trim() && t.push({
|
|
1445
|
-
id:
|
|
1456
|
+
id: G("thinking"),
|
|
1446
1457
|
type: "thinking",
|
|
1447
1458
|
content: e.reasoning,
|
|
1448
1459
|
status: "done",
|
|
1449
1460
|
...e.reasoningSource ? { source: e.reasoningSource } : {}
|
|
1450
1461
|
}), e.tools) for (let n of Object.values(e.tools)) t.push({
|
|
1451
|
-
id:
|
|
1462
|
+
id: G("tool"),
|
|
1452
1463
|
type: "tool",
|
|
1453
1464
|
toolName: n.name,
|
|
1454
1465
|
args: n.args ?? "",
|
|
@@ -1460,7 +1471,7 @@ function Xe(e) {
|
|
|
1460
1471
|
} } : {}
|
|
1461
1472
|
});
|
|
1462
1473
|
return e.content && e.content.trim() && t.push({
|
|
1463
|
-
id:
|
|
1474
|
+
id: G("text"),
|
|
1464
1475
|
type: "text",
|
|
1465
1476
|
content: e.content,
|
|
1466
1477
|
status: "done"
|
|
@@ -1468,40 +1479,40 @@ function Xe(e) {
|
|
|
1468
1479
|
}
|
|
1469
1480
|
//#endregion
|
|
1470
1481
|
//#region src/core/stream/kernel-events.ts
|
|
1471
|
-
var
|
|
1482
|
+
var qe = {
|
|
1472
1483
|
"run.started": "in_progress",
|
|
1473
1484
|
"run.progress": "in_progress",
|
|
1474
1485
|
"run.completed": "completed",
|
|
1475
1486
|
"run.failed": "failed",
|
|
1476
1487
|
"run.canceled": "cancelled",
|
|
1477
1488
|
"run.interrupted": "interrupted"
|
|
1478
|
-
},
|
|
1489
|
+
}, Je = new Set([
|
|
1479
1490
|
"completed",
|
|
1480
1491
|
"failed",
|
|
1481
1492
|
"cancelled",
|
|
1482
1493
|
"canceled"
|
|
1483
1494
|
]);
|
|
1484
|
-
function
|
|
1495
|
+
function q(e) {
|
|
1485
1496
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
1486
1497
|
}
|
|
1487
|
-
function
|
|
1488
|
-
let t =
|
|
1498
|
+
function Ye(e) {
|
|
1499
|
+
let t = q(e.source), n = t ? q(t.metadata) : null;
|
|
1489
1500
|
return String(n?.native_item_kind || "");
|
|
1490
1501
|
}
|
|
1491
|
-
function
|
|
1492
|
-
let n =
|
|
1502
|
+
function J(e, t) {
|
|
1503
|
+
let n = q(e[t]);
|
|
1493
1504
|
if (!n) return [];
|
|
1494
1505
|
let r = n?.parts;
|
|
1495
1506
|
return Array.isArray(r) ? r : t === "update" ? [n] : [];
|
|
1496
1507
|
}
|
|
1497
|
-
function
|
|
1498
|
-
let t =
|
|
1508
|
+
function Xe(e) {
|
|
1509
|
+
let t = q(e);
|
|
1499
1510
|
if (!t) return "";
|
|
1500
1511
|
if (typeof t.text == "string") return t.text;
|
|
1501
|
-
let n =
|
|
1512
|
+
let n = q(t.data);
|
|
1502
1513
|
if (n) {
|
|
1503
1514
|
let e = n.content;
|
|
1504
|
-
if (Array.isArray(e)) return e.map((e) => String(
|
|
1515
|
+
if (Array.isArray(e)) return e.map((e) => String(q(e)?.text || "")).join("");
|
|
1505
1516
|
for (let e of [
|
|
1506
1517
|
"text",
|
|
1507
1518
|
"output",
|
|
@@ -1511,31 +1522,31 @@ function et(e) {
|
|
|
1511
1522
|
}
|
|
1512
1523
|
return "";
|
|
1513
1524
|
}
|
|
1514
|
-
function
|
|
1515
|
-
return e.map(
|
|
1525
|
+
function Y(e) {
|
|
1526
|
+
return e.map(Xe).join("");
|
|
1516
1527
|
}
|
|
1517
|
-
function
|
|
1518
|
-
return e.some((e) =>
|
|
1528
|
+
function Ze(e) {
|
|
1529
|
+
return e.some((e) => q(q(e)?.data)?.type === "userMessage");
|
|
1519
1530
|
}
|
|
1520
|
-
function
|
|
1531
|
+
function X(e) {
|
|
1521
1532
|
if (e.length === 1) {
|
|
1522
|
-
let t =
|
|
1533
|
+
let t = q(q(e[0])?.data);
|
|
1523
1534
|
if (t) return t;
|
|
1524
1535
|
}
|
|
1525
|
-
return
|
|
1536
|
+
return Y(e) || null;
|
|
1526
1537
|
}
|
|
1527
|
-
function
|
|
1528
|
-
let t =
|
|
1529
|
-
return t ?
|
|
1538
|
+
function Qe(e) {
|
|
1539
|
+
let t = q(e);
|
|
1540
|
+
return t ? q(t.data) || t : null;
|
|
1530
1541
|
}
|
|
1531
|
-
function
|
|
1532
|
-
let t =
|
|
1542
|
+
function $e(e) {
|
|
1543
|
+
let t = Qe(e);
|
|
1533
1544
|
return String(t?.content_type || t?.type || "").trim().toLowerCase();
|
|
1534
1545
|
}
|
|
1535
|
-
function
|
|
1546
|
+
function et(e) {
|
|
1536
1547
|
for (let t of e) {
|
|
1537
|
-
let e =
|
|
1538
|
-
if (!e ||
|
|
1548
|
+
let e = Qe(t);
|
|
1549
|
+
if (!e || $e(t) !== "tool_call") continue;
|
|
1539
1550
|
let n = String(e.call_id || "").trim(), r = String(e.name || e.tool_name || "").trim();
|
|
1540
1551
|
if (!(!n && !r)) return {
|
|
1541
1552
|
callId: n,
|
|
@@ -1545,10 +1556,10 @@ function it(e) {
|
|
|
1545
1556
|
}
|
|
1546
1557
|
return null;
|
|
1547
1558
|
}
|
|
1548
|
-
function
|
|
1559
|
+
function tt(e) {
|
|
1549
1560
|
for (let t of e) {
|
|
1550
|
-
let e =
|
|
1551
|
-
if (!e ||
|
|
1561
|
+
let e = Qe(t);
|
|
1562
|
+
if (!e || $e(t) !== "tool_result") continue;
|
|
1552
1563
|
let n = String(e.call_id || e.tool_call_id || "").trim(), r = e.is_error === !0 || e.error != null;
|
|
1553
1564
|
return {
|
|
1554
1565
|
callId: n,
|
|
@@ -1558,7 +1569,7 @@ function at(e) {
|
|
|
1558
1569
|
}
|
|
1559
1570
|
return null;
|
|
1560
1571
|
}
|
|
1561
|
-
function
|
|
1572
|
+
function Z(e, t, n, r) {
|
|
1562
1573
|
let i = String(e.item_id || ""), a = String(r || i);
|
|
1563
1574
|
return { RuntimeItem: {
|
|
1564
1575
|
RunId: String(e.run_id || ""),
|
|
@@ -1570,7 +1581,7 @@ function K(e, t, n, r) {
|
|
|
1570
1581
|
...i && i !== a ? { SourceItemId: i } : {}
|
|
1571
1582
|
} };
|
|
1572
1583
|
}
|
|
1573
|
-
var
|
|
1584
|
+
var nt = class {
|
|
1574
1585
|
textByPart = /* @__PURE__ */ new Map();
|
|
1575
1586
|
toolNameByCallId = /* @__PURE__ */ new Map();
|
|
1576
1587
|
toolCallByItemId = /* @__PURE__ */ new Map();
|
|
@@ -1580,7 +1591,7 @@ var ot = class {
|
|
|
1580
1591
|
this.sessionId = e;
|
|
1581
1592
|
}
|
|
1582
1593
|
translate(e) {
|
|
1583
|
-
if (!
|
|
1594
|
+
if (!q(e)) return null;
|
|
1584
1595
|
let t = Number(e.seq);
|
|
1585
1596
|
if (!Number.isFinite(t) || t <= 0) return null;
|
|
1586
1597
|
let n = String(e.family || ""), r = String(e.event_type || ""), i = String(e.run_id || ""), a = () => ({
|
|
@@ -1589,7 +1600,7 @@ var ot = class {
|
|
|
1589
1600
|
InvocationId: i || void 0,
|
|
1590
1601
|
SeqId: t
|
|
1591
1602
|
});
|
|
1592
|
-
if (n === "interaction") return {
|
|
1603
|
+
if (n === "interaction" || r.startsWith("mcp.authorization.")) return {
|
|
1593
1604
|
...a(),
|
|
1594
1605
|
EventType: r,
|
|
1595
1606
|
payload: e
|
|
@@ -1602,7 +1613,7 @@ var ot = class {
|
|
|
1602
1613
|
};
|
|
1603
1614
|
if (r === "control.run_transition") {
|
|
1604
1615
|
let t = String(e.state || "").toLowerCase();
|
|
1605
|
-
if (
|
|
1616
|
+
if (Je.has(t)) return {
|
|
1606
1617
|
...a(),
|
|
1607
1618
|
EventType: "run_status",
|
|
1608
1619
|
Content: { status: t }
|
|
@@ -1611,19 +1622,19 @@ var ot = class {
|
|
|
1611
1622
|
return null;
|
|
1612
1623
|
}
|
|
1613
1624
|
if (n !== "runtime") return null;
|
|
1614
|
-
let o =
|
|
1625
|
+
let o = q(q(e.source)?.metadata), s = o?.conversation_visibility ?? o?.visibility;
|
|
1615
1626
|
if (r.startsWith("item.") && ["internal", "hidden"].includes(String(s))) return null;
|
|
1616
|
-
let c =
|
|
1627
|
+
let c = qe[r];
|
|
1617
1628
|
if (c) return {
|
|
1618
1629
|
...a(),
|
|
1619
1630
|
EventType: "run_status",
|
|
1620
1631
|
Content: { status: c }
|
|
1621
1632
|
};
|
|
1622
|
-
let l =
|
|
1633
|
+
let l = Ye(e);
|
|
1623
1634
|
if (r === "item.started") {
|
|
1624
|
-
let t =
|
|
1635
|
+
let t = J(e, "initial");
|
|
1625
1636
|
if (e.item_kind === "tool_call") {
|
|
1626
|
-
let n =
|
|
1637
|
+
let n = et(t);
|
|
1627
1638
|
if (!n) return null;
|
|
1628
1639
|
let r = n?.callId || String(e.item_id || ""), o = n?.name || "tool";
|
|
1629
1640
|
return r && this.toolNameByCallId.set(r, o), e.item_id && this.toolCallByItemId.set(String(e.item_id), {
|
|
@@ -1633,42 +1644,42 @@ var ot = class {
|
|
|
1633
1644
|
...a(),
|
|
1634
1645
|
EventType: "tool_call",
|
|
1635
1646
|
Metadata: {
|
|
1636
|
-
...
|
|
1647
|
+
...Z(e, "replace", void 0, r),
|
|
1637
1648
|
call_id: r,
|
|
1638
1649
|
tool_name: o,
|
|
1639
1650
|
run_id: i,
|
|
1640
|
-
tool_args: n?.arguments ??
|
|
1651
|
+
tool_args: n?.arguments ?? X(t)
|
|
1641
1652
|
}
|
|
1642
1653
|
};
|
|
1643
1654
|
}
|
|
1644
|
-
return e.item_kind === "tool_result" || l === "userMessage" ||
|
|
1655
|
+
return e.item_kind === "tool_result" || l === "userMessage" || Ze(t) || l === "reasoning" || e.item_kind === "reasoning" ? null : l === "agentMessage" || !l && e.item_kind === "message" ? {
|
|
1645
1656
|
...a(),
|
|
1646
1657
|
EventType: "assistant_stream_snapshot",
|
|
1647
1658
|
Content: { parts: [{ text: "" }] },
|
|
1648
|
-
Metadata:
|
|
1659
|
+
Metadata: Z(e, "replace")
|
|
1649
1660
|
} : l && l !== "notification" ? {
|
|
1650
1661
|
...a(),
|
|
1651
1662
|
EventType: "tool_call",
|
|
1652
1663
|
Metadata: {
|
|
1653
|
-
...
|
|
1664
|
+
...Z(e, "replace"),
|
|
1654
1665
|
call_id: String(e.item_id || ""),
|
|
1655
1666
|
tool_name: l,
|
|
1656
1667
|
run_id: i,
|
|
1657
|
-
tool_args:
|
|
1668
|
+
tool_args: X(t)
|
|
1658
1669
|
}
|
|
1659
1670
|
} : null;
|
|
1660
1671
|
}
|
|
1661
1672
|
if (r === "item.updated") {
|
|
1662
|
-
let n =
|
|
1673
|
+
let n = J(e, "update");
|
|
1663
1674
|
if (e.item_kind === "tool_call") {
|
|
1664
|
-
let t =
|
|
1675
|
+
let t = tt(n);
|
|
1665
1676
|
if (!t) return null;
|
|
1666
1677
|
let r = this.toolCallByItemId.get(String(e.item_id || "")), o = t.callId || r?.callId || String(e.item_id || ""), s = r?.name || this.toolNameByCallId.get(o) || "tool", c = t.isError ? { error: t.result } : t.result;
|
|
1667
1678
|
return e.item_id && this.toolResultByItemId.set(String(e.item_id), c), {
|
|
1668
1679
|
...a(),
|
|
1669
1680
|
EventType: "tool_result",
|
|
1670
1681
|
Metadata: {
|
|
1671
|
-
...
|
|
1682
|
+
...Z(e, "completed", void 0, o),
|
|
1672
1683
|
call_id: o,
|
|
1673
1684
|
tool_name: s,
|
|
1674
1685
|
run_id: i,
|
|
@@ -1676,44 +1687,44 @@ var ot = class {
|
|
|
1676
1687
|
}
|
|
1677
1688
|
};
|
|
1678
1689
|
}
|
|
1679
|
-
let r =
|
|
1690
|
+
let r = q(n[0]), o = String(r?.part_id || e.item_id || t), s = String(e.op || "replace"), c = Y(n), u = this.textByPart.get(o) || "", d = s === "append" ? u + c : c;
|
|
1680
1691
|
return this.textByPart.set(o, d), l === "agentMessage" || !l && e.item_kind === "message" ? {
|
|
1681
1692
|
...a(),
|
|
1682
1693
|
EventType: "assistant_stream_snapshot",
|
|
1683
1694
|
Content: { parts: [{ text: d }] },
|
|
1684
|
-
Metadata:
|
|
1695
|
+
Metadata: Z(e, "replace", o)
|
|
1685
1696
|
} : l === "reasoning" || e.item_kind === "reasoning" ? {
|
|
1686
1697
|
...a(),
|
|
1687
1698
|
EventType: "reasoning",
|
|
1688
1699
|
Content: { parts: [{ text: c }] },
|
|
1689
|
-
Metadata:
|
|
1700
|
+
Metadata: Z(e, s === "append" ? "append" : "replace", o)
|
|
1690
1701
|
} : null;
|
|
1691
1702
|
}
|
|
1692
1703
|
if (r === "item.snapshot_replaced") {
|
|
1693
|
-
let n =
|
|
1704
|
+
let n = J(e, "snapshot"), r = String(q(n[0])?.part_id || e.item_id || t), i = Y(n);
|
|
1694
1705
|
return this.textByPart.set(r, i), l === "agentMessage" || !l && e.item_kind === "message" ? {
|
|
1695
1706
|
...a(),
|
|
1696
1707
|
EventType: "assistant_stream_snapshot",
|
|
1697
1708
|
Content: { parts: [{ text: i }] },
|
|
1698
|
-
Metadata:
|
|
1709
|
+
Metadata: Z(e, "replace", r)
|
|
1699
1710
|
} : l === "reasoning" || e.item_kind === "reasoning" ? {
|
|
1700
1711
|
...a(),
|
|
1701
1712
|
EventType: "reasoning",
|
|
1702
1713
|
Content: { parts: [{ text: i }] },
|
|
1703
|
-
Metadata:
|
|
1714
|
+
Metadata: Z(e, "replace", r)
|
|
1704
1715
|
} : null;
|
|
1705
1716
|
}
|
|
1706
1717
|
if (r === "item.completed") {
|
|
1707
|
-
let n =
|
|
1718
|
+
let n = J(e, "snapshot");
|
|
1708
1719
|
if (e.item_kind === "tool_call") {
|
|
1709
|
-
let t =
|
|
1720
|
+
let t = et(n), r = tt(n), o = this.toolCallByItemId.get(String(e.item_id || "")), s = r?.callId || t?.callId || o?.callId || String(e.item_id || ""), c = t?.name || o?.name || this.toolNameByCallId.get(s) || "tool";
|
|
1710
1721
|
if (s && this.toolNameByCallId.set(s, c), r) {
|
|
1711
1722
|
let t = r.isError ? { error: r.result } : r.result;
|
|
1712
1723
|
return {
|
|
1713
1724
|
...a(),
|
|
1714
1725
|
EventType: "tool_result",
|
|
1715
1726
|
Metadata: {
|
|
1716
|
-
...
|
|
1727
|
+
...Z(e, "completed", void 0, s),
|
|
1717
1728
|
call_id: s,
|
|
1718
1729
|
tool_name: c,
|
|
1719
1730
|
run_id: i,
|
|
@@ -1725,21 +1736,21 @@ var ot = class {
|
|
|
1725
1736
|
...a(),
|
|
1726
1737
|
EventType: "tool_call",
|
|
1727
1738
|
Metadata: {
|
|
1728
|
-
...
|
|
1739
|
+
...Z(e, "replace", void 0, s),
|
|
1729
1740
|
call_id: s,
|
|
1730
1741
|
tool_name: c,
|
|
1731
1742
|
run_id: i,
|
|
1732
|
-
tool_args: t?.arguments ??
|
|
1743
|
+
tool_args: t?.arguments ?? X(n)
|
|
1733
1744
|
}
|
|
1734
1745
|
};
|
|
1735
1746
|
}
|
|
1736
1747
|
if (e.item_kind === "tool_result") {
|
|
1737
|
-
let t =
|
|
1748
|
+
let t = tt(n), r = t?.callId || String(e.item_id || ""), o = this.toolNameByCallId.get(r) || l || "tool", s = t?.isError ? { error: t.result } : t?.result ?? X(n);
|
|
1738
1749
|
return {
|
|
1739
1750
|
...a(),
|
|
1740
1751
|
EventType: "tool_result",
|
|
1741
1752
|
Metadata: {
|
|
1742
|
-
...
|
|
1753
|
+
...Z(e, "completed", void 0, r),
|
|
1743
1754
|
call_id: r,
|
|
1744
1755
|
tool_name: o,
|
|
1745
1756
|
run_id: i,
|
|
@@ -1747,38 +1758,38 @@ var ot = class {
|
|
|
1747
1758
|
}
|
|
1748
1759
|
};
|
|
1749
1760
|
}
|
|
1750
|
-
if (l === "userMessage" ||
|
|
1761
|
+
if (l === "userMessage" || Ze(n)) return {
|
|
1751
1762
|
...a(),
|
|
1752
1763
|
EventType: "user_message",
|
|
1753
|
-
Content: { parts: [{ text:
|
|
1764
|
+
Content: { parts: [{ text: Y(n) }] }
|
|
1754
1765
|
};
|
|
1755
1766
|
if (l === "agentMessage" || !l && e.item_kind === "message") {
|
|
1756
|
-
let r =
|
|
1767
|
+
let r = Y(n), i = String(q(n[0])?.part_id || e.item_id || t);
|
|
1757
1768
|
return this.textByPart.set(i, r), {
|
|
1758
1769
|
...a(),
|
|
1759
1770
|
EventType: "assistant_message",
|
|
1760
1771
|
Content: { parts: [{ text: r }] },
|
|
1761
|
-
Metadata:
|
|
1772
|
+
Metadata: Z(e, "completed", i)
|
|
1762
1773
|
};
|
|
1763
1774
|
}
|
|
1764
1775
|
if (l === "reasoning" || e.item_kind === "reasoning") {
|
|
1765
|
-
let r = String(
|
|
1776
|
+
let r = String(q(n[0])?.part_id || e.item_id || t);
|
|
1766
1777
|
return {
|
|
1767
1778
|
...a(),
|
|
1768
1779
|
EventType: "reasoning",
|
|
1769
|
-
Content: { parts: [{ text:
|
|
1770
|
-
Metadata:
|
|
1780
|
+
Content: { parts: [{ text: Y(n) }] },
|
|
1781
|
+
Metadata: Z(e, "completed", r)
|
|
1771
1782
|
};
|
|
1772
1783
|
}
|
|
1773
1784
|
return l && l !== "notification" ? {
|
|
1774
1785
|
...a(),
|
|
1775
1786
|
EventType: "tool_result",
|
|
1776
1787
|
Metadata: {
|
|
1777
|
-
...
|
|
1788
|
+
...Z(e, "completed"),
|
|
1778
1789
|
call_id: String(e.item_id || ""),
|
|
1779
1790
|
tool_name: l,
|
|
1780
1791
|
run_id: i,
|
|
1781
|
-
tool_output:
|
|
1792
|
+
tool_output: X(n)
|
|
1782
1793
|
}
|
|
1783
1794
|
} : null;
|
|
1784
1795
|
}
|
|
@@ -1789,11 +1800,11 @@ var ot = class {
|
|
|
1789
1800
|
...a(),
|
|
1790
1801
|
EventType: "tool_result",
|
|
1791
1802
|
Metadata: {
|
|
1792
|
-
...
|
|
1803
|
+
...Z(e, "completed", void 0, n),
|
|
1793
1804
|
call_id: n,
|
|
1794
1805
|
tool_name: r,
|
|
1795
1806
|
run_id: i,
|
|
1796
|
-
tool_output: o ?? { error:
|
|
1807
|
+
tool_output: o ?? { error: q(e.error) || e.error || "item failed" }
|
|
1797
1808
|
}
|
|
1798
1809
|
};
|
|
1799
1810
|
}
|
|
@@ -1801,18 +1812,18 @@ var ot = class {
|
|
|
1801
1812
|
...a(),
|
|
1802
1813
|
EventType: "tool_result",
|
|
1803
1814
|
Metadata: {
|
|
1804
|
-
...
|
|
1815
|
+
...Z(e, "completed"),
|
|
1805
1816
|
call_id: String(e.item_id || ""),
|
|
1806
1817
|
tool_name: l,
|
|
1807
1818
|
run_id: i,
|
|
1808
|
-
tool_output: { error:
|
|
1819
|
+
tool_output: { error: q(e.error) || e.error || "item failed" }
|
|
1809
1820
|
}
|
|
1810
1821
|
} : null;
|
|
1811
1822
|
}
|
|
1812
1823
|
return null;
|
|
1813
1824
|
}
|
|
1814
1825
|
};
|
|
1815
|
-
async function
|
|
1826
|
+
async function rt(e) {
|
|
1816
1827
|
let t = e.getReader(), n = new TextDecoder(), r = "", i = null, a = !1, o = (e) => e.includes("data:") || e.includes("event:") || e.includes(":");
|
|
1817
1828
|
try {
|
|
1818
1829
|
for (;;) {
|
|
@@ -1822,8 +1833,8 @@ async function st(e) {
|
|
|
1822
1833
|
break;
|
|
1823
1834
|
}
|
|
1824
1835
|
if (r.trimStart().startsWith("{")) {
|
|
1825
|
-
if (
|
|
1826
|
-
i =
|
|
1836
|
+
if (it(r)) {
|
|
1837
|
+
i = at(r);
|
|
1827
1838
|
break;
|
|
1828
1839
|
}
|
|
1829
1840
|
} else if (o(r)) break;
|
|
@@ -1859,7 +1870,7 @@ async function st(e) {
|
|
|
1859
1870
|
stream: c
|
|
1860
1871
|
};
|
|
1861
1872
|
}
|
|
1862
|
-
function
|
|
1873
|
+
function it(e) {
|
|
1863
1874
|
let t = e.trim();
|
|
1864
1875
|
if (!t.endsWith("}")) return !1;
|
|
1865
1876
|
let n = 0, r = !1, i = !1;
|
|
@@ -1876,11 +1887,11 @@ function ct(e) {
|
|
|
1876
1887
|
}
|
|
1877
1888
|
return n === 0;
|
|
1878
1889
|
}
|
|
1879
|
-
function
|
|
1890
|
+
function at(e) {
|
|
1880
1891
|
try {
|
|
1881
|
-
let t =
|
|
1892
|
+
let t = q(JSON.parse(e).Data), n = String(t?.ReceiptStatus || "");
|
|
1882
1893
|
if (!n) return null;
|
|
1883
|
-
let r =
|
|
1894
|
+
let r = q(t?.Error);
|
|
1884
1895
|
return {
|
|
1885
1896
|
status: n,
|
|
1886
1897
|
presentationProfile: t?.PresentationProfile === "agent-block-v1" ? "agent-block-v1" : "flat-v1",
|
|
@@ -1898,971 +1909,40 @@ function lt(e) {
|
|
|
1898
1909
|
}
|
|
1899
1910
|
}
|
|
1900
1911
|
//#endregion
|
|
1901
|
-
//#region src/utils/
|
|
1902
|
-
function ut() {
|
|
1903
|
-
return {
|
|
1904
|
-
toolNames: /* @__PURE__ */ new Map(),
|
|
1905
|
-
toolArguments: /* @__PURE__ */ new Map(),
|
|
1906
|
-
callIds: /* @__PURE__ */ new Map(),
|
|
1907
|
-
currentResponseId: "",
|
|
1908
|
-
sawTextDelta: !1,
|
|
1909
|
-
sawReasoningDelta: !1
|
|
1910
|
-
};
|
|
1911
|
-
}
|
|
1912
|
-
function dt(e) {
|
|
1913
|
-
return typeof e == "string" ? e : Array.isArray(e) ? e.map((e) => typeof e == "string" ? e : e && typeof e == "object" && typeof e.text == "string" ? e.text : "").join("") : e && typeof e == "object" && typeof e.text == "string" ? e.text : "";
|
|
1914
|
-
}
|
|
1915
|
-
function q(e) {
|
|
1916
|
-
return e == null ? "" : typeof e == "string" ? e : typeof e == "object" ? JSON.stringify(e, null, 2) : String(e);
|
|
1917
|
-
}
|
|
1918
|
-
function J(...e) {
|
|
1919
|
-
for (let t of e) {
|
|
1920
|
-
let e = dt(t);
|
|
1921
|
-
if (e) return e;
|
|
1922
|
-
}
|
|
1923
|
-
return "";
|
|
1924
|
-
}
|
|
1925
|
-
function ft(e, t) {
|
|
1926
|
-
return String(e?.id || e?.item_id || e?.call_id || t?.item_id || t?.call_id || t?.output_index || "");
|
|
1927
|
-
}
|
|
1928
|
-
function pt(e, t, n, r, i) {
|
|
1929
|
-
t && (e.toolNames.set(t, r), e.toolArguments.set(t, i));
|
|
1930
|
-
let a = String(n?.call_id || "");
|
|
1931
|
-
a && (e.callIds.set(a, t || r), e.toolNames.set(a, r), e.toolArguments.set(a, i));
|
|
1932
|
-
}
|
|
1933
|
-
function Y(e, t, n, r = "tool") {
|
|
1934
|
-
let i = String(n?.call_id || "");
|
|
1935
|
-
return String(n?.name || n?.tool_name || (t ? e.toolNames.get(t) : "") || (i ? e.toolNames.get(i) : "") || r);
|
|
1936
|
-
}
|
|
1937
|
-
function mt(e) {
|
|
1938
|
-
if (!e || typeof e != "object") return "";
|
|
1939
|
-
let t = dt(e.content);
|
|
1940
|
-
return J(e.output_text, e.text, e.summary_text, e.summary, e.delta, t);
|
|
1941
|
-
}
|
|
1942
|
-
function ht(e) {
|
|
1943
|
-
let t = e?.response && typeof e.response == "object" ? e.response : e, n = J(t?.output_text, t?.text);
|
|
1944
|
-
if (n) return n;
|
|
1945
|
-
let r = Array.isArray(t?.output) ? t.output : [];
|
|
1946
|
-
for (let e of r) {
|
|
1947
|
-
let t = mt(e);
|
|
1948
|
-
if (t) return t;
|
|
1949
|
-
}
|
|
1950
|
-
return "";
|
|
1951
|
-
}
|
|
1952
|
-
function gt(e) {
|
|
1953
|
-
let t = e?.response && typeof e.response == "object" ? e.response : e;
|
|
1954
|
-
return Array.isArray(t?.output) ? t.output : [];
|
|
1955
|
-
}
|
|
1956
|
-
function _t(e) {
|
|
1957
|
-
let t = e;
|
|
1958
|
-
if (typeof t == "string") try {
|
|
1959
|
-
t = JSON.parse(t);
|
|
1960
|
-
} catch {
|
|
1961
|
-
return {};
|
|
1962
|
-
}
|
|
1963
|
-
return Array.isArray(t) && (t = t[0] || {}), !t || typeof t != "object" ? {} : t.value && typeof t.value == "object" && !Array.isArray(t.value) ? {
|
|
1964
|
-
...t.value,
|
|
1965
|
-
approval_request_id: t.value.approval_request_id || t.value.id || t.id
|
|
1966
|
-
} : t;
|
|
1967
|
-
}
|
|
1968
|
-
function vt({ data: e, state: t, status: n }) {
|
|
1969
|
-
let r = e?.item || e?.output_item || e || {}, i = String(r.type || "").trim(), a = ft(r, e);
|
|
1970
|
-
if (i === "function_call") {
|
|
1971
|
-
let e = Y(t, a, r), i = q(r.arguments ?? r.args ?? r.input);
|
|
1972
|
-
return pt(t, a, r, e, i), [{
|
|
1973
|
-
type: "tool_upsert",
|
|
1974
|
-
name: e,
|
|
1975
|
-
args: i,
|
|
1976
|
-
status: n
|
|
1977
|
-
}];
|
|
1978
|
-
}
|
|
1979
|
-
if (i === "function_call_output") return [{
|
|
1980
|
-
type: "tool_result",
|
|
1981
|
-
name: Y(t, a, r),
|
|
1982
|
-
output: q(r.output ?? r.result ?? r.content)
|
|
1983
|
-
}];
|
|
1984
|
-
if (i === "mcp_approval_request") {
|
|
1985
|
-
let n = String(r.name || "approval"), i = q(r.arguments ?? r.args), a = String(r.id || r.approval_request_id || ""), o = String(r.run_id || r.runId || e?.run_id || e?.runId || "");
|
|
1986
|
-
return [{
|
|
1987
|
-
type: "tool_upsert",
|
|
1988
|
-
name: n,
|
|
1989
|
-
args: i,
|
|
1990
|
-
status: "paused",
|
|
1991
|
-
approvalRequestId: a,
|
|
1992
|
-
previousResponseId: String(e?.response_id || t.currentResponseId || ""),
|
|
1993
|
-
serverLabel: String(r.server_label || "")
|
|
1994
|
-
}, {
|
|
1995
|
-
type: "approval_request",
|
|
1996
|
-
approvalRequestId: a,
|
|
1997
|
-
previousResponseId: String(e?.response_id || t.currentResponseId || ""),
|
|
1998
|
-
...o ? { runId: o } : {},
|
|
1999
|
-
name: n,
|
|
2000
|
-
args: i
|
|
2001
|
-
}];
|
|
2002
|
-
}
|
|
2003
|
-
if (i === "reasoning" || i === "reasoning_summary" || i === "reasoning_summary_text") {
|
|
2004
|
-
let e = mt(r);
|
|
2005
|
-
return e ? [{
|
|
2006
|
-
type: "reasoning_delta",
|
|
2007
|
-
text: e
|
|
2008
|
-
}] : [];
|
|
2009
|
-
}
|
|
2010
|
-
if (i === "message") {
|
|
2011
|
-
let e = mt(r);
|
|
2012
|
-
return e ? [{
|
|
2013
|
-
type: n === "completed" ? "text_final" : "text_delta",
|
|
2014
|
-
text: e
|
|
2015
|
-
}] : [];
|
|
2016
|
-
}
|
|
2017
|
-
return [];
|
|
2018
|
-
}
|
|
2019
|
-
function yt({ eventName: e, data: t, state: n }) {
|
|
2020
|
-
let r = String(t?.type || e || "").trim(), i = String(t?.id || t?.response?.id || t?.response_id || "");
|
|
2021
|
-
if (i.startsWith("resp_") && (n.currentResponseId = i), r === "response.tool_call") return [{
|
|
2022
|
-
type: "tool_upsert",
|
|
2023
|
-
name: String(t?.name || t?.tool_name || "tool"),
|
|
2024
|
-
args: q(t?.args ?? t?.arguments),
|
|
2025
|
-
status: "running"
|
|
2026
|
-
}];
|
|
2027
|
-
if (r === "response.tool_result" || r === "response.ksadk.tool_result") return [{
|
|
2028
|
-
type: "tool_result",
|
|
2029
|
-
name: String(t?.name || t?.tool_name || "tool"),
|
|
2030
|
-
output: q(t?.output ?? t?.result)
|
|
2031
|
-
}];
|
|
2032
|
-
if (r === "response.output_item.added") return vt({
|
|
2033
|
-
data: t,
|
|
2034
|
-
state: n,
|
|
2035
|
-
status: "running"
|
|
2036
|
-
});
|
|
2037
|
-
if (r === "response.output_item.done") return vt({
|
|
2038
|
-
data: t,
|
|
2039
|
-
state: n,
|
|
2040
|
-
status: "completed"
|
|
2041
|
-
});
|
|
2042
|
-
if (r === "response.function_call_arguments.delta") {
|
|
2043
|
-
let e = String(t?.item_id || t?.call_id || ""), r = Y(n, e, t), i = `${n.toolArguments.get(e) || ""}${String(t?.delta || "")}`;
|
|
2044
|
-
return n.toolArguments.set(e, i), [{
|
|
2045
|
-
type: "tool_upsert",
|
|
2046
|
-
name: r,
|
|
2047
|
-
args: i,
|
|
2048
|
-
status: "running"
|
|
2049
|
-
}];
|
|
2050
|
-
}
|
|
2051
|
-
if (r === "response.function_call_arguments.done") {
|
|
2052
|
-
let e = String(t?.item_id || t?.call_id || ""), r = Y(n, e, t), i = q(t?.arguments ?? n.toolArguments.get(e));
|
|
2053
|
-
return n.toolArguments.set(e, i), [{
|
|
2054
|
-
type: "tool_upsert",
|
|
2055
|
-
name: r,
|
|
2056
|
-
args: i,
|
|
2057
|
-
status: "running"
|
|
2058
|
-
}];
|
|
2059
|
-
}
|
|
2060
|
-
if (r === "response.reasoning.delta" || r === "response.reasoning_text.delta" || r === "response.reasoning_summary.delta" || r === "response.reasoning_summary_text.delta") {
|
|
2061
|
-
let e = J(t?.delta, t?.text);
|
|
2062
|
-
return e && (n.sawReasoningDelta = !0), e ? [{
|
|
2063
|
-
type: "reasoning_delta",
|
|
2064
|
-
text: e
|
|
2065
|
-
}] : [];
|
|
2066
|
-
}
|
|
2067
|
-
if (r === "response.output_text.delta") {
|
|
2068
|
-
if (t?.replace === !0 && (typeof t.delta == "string" || typeof t.text == "string")) return n.sawTextDelta = !0, [{
|
|
2069
|
-
type: "text_replace",
|
|
2070
|
-
text: typeof t.delta == "string" ? t.delta : t.text
|
|
2071
|
-
}];
|
|
2072
|
-
let e = J(t?.delta, t?.text);
|
|
2073
|
-
return e && (n.sawTextDelta = !0), e ? [{
|
|
2074
|
-
type: "text_delta",
|
|
2075
|
-
text: e
|
|
2076
|
-
}] : [];
|
|
2077
|
-
}
|
|
2078
|
-
if (r === "response.output_text.done") {
|
|
2079
|
-
let e = J(t?.text, t?.delta);
|
|
2080
|
-
return e ? [{
|
|
2081
|
-
type: "text_final",
|
|
2082
|
-
text: e
|
|
2083
|
-
}] : [];
|
|
2084
|
-
}
|
|
2085
|
-
if (r === "response.content_part.delta") {
|
|
2086
|
-
let e = String(t?.part?.type || t?.delta?.type || t?.content_type || ""), r = J(t?.delta?.text, t?.delta, t?.text);
|
|
2087
|
-
return r ? e.includes("reasoning") ? (n.sawReasoningDelta = !0, [{
|
|
2088
|
-
type: "reasoning_delta",
|
|
2089
|
-
text: r
|
|
2090
|
-
}]) : (n.sawTextDelta = !0, [{
|
|
2091
|
-
type: "text_delta",
|
|
2092
|
-
text: r
|
|
2093
|
-
}]) : [];
|
|
2094
|
-
}
|
|
2095
|
-
if (r === "response.completed") {
|
|
2096
|
-
let e = ht(t), r = gt(t).flatMap((e) => vt({
|
|
2097
|
-
data: {
|
|
2098
|
-
...t,
|
|
2099
|
-
item: e
|
|
2100
|
-
},
|
|
2101
|
-
state: n,
|
|
2102
|
-
status: "completed"
|
|
2103
|
-
})).filter((e) => !(n.sawTextDelta && e.type === "text_final") && !(n.sawReasoningDelta && e.type === "reasoning_delta")), i = r.some((e) => e.type === "text_final");
|
|
2104
|
-
return [
|
|
2105
|
-
...r,
|
|
2106
|
-
...e && !n.sawTextDelta && !i ? [{
|
|
2107
|
-
type: "text_final",
|
|
2108
|
-
text: e
|
|
2109
|
-
}] : [],
|
|
2110
|
-
{
|
|
2111
|
-
type: "terminal",
|
|
2112
|
-
status: "completed"
|
|
2113
|
-
}
|
|
2114
|
-
];
|
|
2115
|
-
}
|
|
2116
|
-
if (r === "response.failed") return [{
|
|
2117
|
-
type: "failed",
|
|
2118
|
-
message: t?.error?.message || "Agent 运行失败"
|
|
2119
|
-
}, {
|
|
2120
|
-
type: "terminal",
|
|
2121
|
-
status: "failed"
|
|
2122
|
-
}];
|
|
2123
|
-
if (r === "response.incomplete") return [{ type: "incomplete" }, {
|
|
2124
|
-
type: "terminal",
|
|
2125
|
-
status: "incomplete"
|
|
2126
|
-
}];
|
|
2127
|
-
if (r === "response.cancelled") return [{
|
|
2128
|
-
type: "terminal",
|
|
2129
|
-
status: "cancelled"
|
|
2130
|
-
}];
|
|
2131
|
-
if (r === "response.approval_request" || r === "response.ksadk.approval_request") {
|
|
2132
|
-
let e = _t(t?.interrupt_info), r = String(e.approval_request_id || e.id || ""), i = String(t?.response_id || n.currentResponseId || ""), a = String(t?.run_id || t?.runId || ""), o = e.approval_requests && typeof e.approval_requests == "object" ? e.approval_requests : e, s = Array.isArray(o.action_requests) ? o.action_requests : [];
|
|
2133
|
-
if (s.length > 0) {
|
|
2134
|
-
let e = s.map((e) => ({
|
|
2135
|
-
type: "tool_upsert",
|
|
2136
|
-
name: String(e?.name || "tool"),
|
|
2137
|
-
args: JSON.stringify(e?.args ?? {}),
|
|
2138
|
-
status: "paused",
|
|
2139
|
-
approvalRequestId: r,
|
|
2140
|
-
previousResponseId: i
|
|
2141
|
-
})), t = s[0] || {};
|
|
2142
|
-
return [...e, {
|
|
2143
|
-
type: "approval_request",
|
|
2144
|
-
approvalRequestId: r,
|
|
2145
|
-
previousResponseId: i,
|
|
2146
|
-
...a ? { runId: a } : {},
|
|
2147
|
-
name: String(t?.name || "人工确认"),
|
|
2148
|
-
args: JSON.stringify(t?.args ?? {})
|
|
2149
|
-
}];
|
|
2150
|
-
}
|
|
2151
|
-
return [{
|
|
2152
|
-
type: "approval_request",
|
|
2153
|
-
approvalRequestId: r,
|
|
2154
|
-
previousResponseId: i,
|
|
2155
|
-
...a ? { runId: a } : {}
|
|
2156
|
-
}];
|
|
2157
|
-
}
|
|
2158
|
-
if (r === "response.approval_resolved" || r === "response.ksadk.approval_resolved") {
|
|
2159
|
-
let e = String(t?.decision || t?.outcome || "").toLowerCase(), n = e === "reject" || e === "rejected" || e === "denied" ? "rejected" : e === "cancel" || e === "cancelled" || e === "canceled" ? "cancelled" : "approved";
|
|
2160
|
-
return [{
|
|
2161
|
-
type: "approval_resolved",
|
|
2162
|
-
approvalRequestId: String(t?.approval_request_id || t?.approvalRequestId || t?.approval_id || t?.approvalId || ""),
|
|
2163
|
-
decision: n,
|
|
2164
|
-
revision: Number(t?.revision || 2)
|
|
2165
|
-
}];
|
|
2166
|
-
}
|
|
2167
|
-
if (new Set([
|
|
2168
|
-
"response.ksadk.a2ui_surface_begin",
|
|
2169
|
-
"a2ui.surface.begin",
|
|
2170
|
-
"response.a2ui.createSurface",
|
|
2171
|
-
"a2ui.createSurface",
|
|
2172
|
-
"createSurface"
|
|
2173
|
-
]).has(r)) {
|
|
2174
|
-
let e = t?.surface && typeof t.surface == "object" ? t.surface : {};
|
|
2175
|
-
return [{
|
|
2176
|
-
type: "a2ui_surface_begin",
|
|
2177
|
-
surfaceId: String(t?.surface_id || t?.surfaceId || e.surface_id || e.surfaceId || ""),
|
|
2178
|
-
surface: e
|
|
2179
|
-
}];
|
|
2180
|
-
}
|
|
2181
|
-
if (new Set([
|
|
2182
|
-
"response.ksadk.a2ui_surface_update",
|
|
2183
|
-
"a2ui.surface.update",
|
|
2184
|
-
"response.a2ui.updateComponents",
|
|
2185
|
-
"a2ui.updateComponents",
|
|
2186
|
-
"updateComponents"
|
|
2187
|
-
]).has(r)) {
|
|
2188
|
-
let e = t?.surface && typeof t.surface == "object" ? t.surface : {};
|
|
2189
|
-
return [{
|
|
2190
|
-
type: "a2ui_surface_update",
|
|
2191
|
-
surfaceId: String(t?.surface_id || t?.surfaceId || e.surface_id || e.surfaceId || ""),
|
|
2192
|
-
surface: e
|
|
2193
|
-
}];
|
|
2194
|
-
}
|
|
2195
|
-
if (new Set([
|
|
2196
|
-
"response.ksadk.a2ui_surface_end",
|
|
2197
|
-
"a2ui.surface.end",
|
|
2198
|
-
"response.a2ui.deleteSurface",
|
|
2199
|
-
"a2ui.deleteSurface",
|
|
2200
|
-
"deleteSurface"
|
|
2201
|
-
]).has(r)) return [{
|
|
2202
|
-
type: "a2ui_surface_end",
|
|
2203
|
-
surfaceId: String(t?.surface_id || t?.surfaceId || "")
|
|
2204
|
-
}];
|
|
2205
|
-
if (new Set(["response.ksadk.a2ui_interaction", "a2ui.interaction"]).has(r)) return [{
|
|
2206
|
-
type: "a2ui_interaction",
|
|
2207
|
-
surfaceId: String(t?.surface_id || t?.surfaceId || ""),
|
|
2208
|
-
interactionId: String(t?.interaction_id || t?.interactionId || ""),
|
|
2209
|
-
kind: String(t?.kind || "input"),
|
|
2210
|
-
inputSchema: t?.input_schema && typeof t.input_schema == "object" ? t.input_schema : {}
|
|
2211
|
-
}];
|
|
2212
|
-
let a = t?.content?.parts?.[0]?.text;
|
|
2213
|
-
return a && !t?.actions?.finishReason ? [{
|
|
2214
|
-
type: "text_delta",
|
|
2215
|
-
text: String(a)
|
|
2216
|
-
}] : [];
|
|
2217
|
-
}
|
|
2218
|
-
//#endregion
|
|
2219
|
-
//#region src/utils/session-events.js
|
|
2220
|
-
var bt = new Set([
|
|
2221
|
-
"completed",
|
|
2222
|
-
"failed",
|
|
2223
|
-
"error",
|
|
2224
|
-
"cancelled",
|
|
2225
|
-
"canceled",
|
|
2226
|
-
"aborted",
|
|
2227
|
-
"interrupted",
|
|
2228
|
-
"resume_failed"
|
|
2229
|
-
]), xt = new Set([
|
|
2230
|
-
"tool_call",
|
|
2231
|
-
"tool_result",
|
|
2232
|
-
"stage_tool_call",
|
|
2233
|
-
"stage_tool_result"
|
|
2234
|
-
]), St = {
|
|
2235
|
-
"run.started": "in_progress",
|
|
2236
|
-
"run.progress": "in_progress",
|
|
2237
|
-
"run.interrupted": "interrupted",
|
|
2238
|
-
"run.completed": "completed",
|
|
2239
|
-
"run.failed": "failed",
|
|
2240
|
-
"run.canceled": "cancelled"
|
|
2241
|
-
};
|
|
2242
|
-
function X(e) {
|
|
2243
|
-
let t = e?.Content?.payload;
|
|
2244
|
-
return t && typeof t == "object" ? t : {};
|
|
2245
|
-
}
|
|
2246
|
-
function Ct(e, t) {
|
|
2247
|
-
let n = String(e || ""), r = String(t || "");
|
|
2248
|
-
return n ? !r || n.endsWith(r) ? n : r.startsWith(n) ? r : `${n}${r}` : r;
|
|
2249
|
-
}
|
|
2250
|
-
function wt(e) {
|
|
2251
|
-
let t = String(e?.EventType || ""), n = X(e);
|
|
2252
|
-
return St[t] ? {
|
|
2253
|
-
...e,
|
|
2254
|
-
EventType: "run_status",
|
|
2255
|
-
Content: {
|
|
2256
|
-
status: String(n.status || St[t]),
|
|
2257
|
-
...n.detail ? { detail: String(n.detail) } : {}
|
|
2258
|
-
}
|
|
2259
|
-
} : t === "reasoning.delta" || t === "reasoning.completed" ? {
|
|
2260
|
-
...e,
|
|
2261
|
-
EventType: "reasoning",
|
|
2262
|
-
Content: {
|
|
2263
|
-
role: "model",
|
|
2264
|
-
parts: [{ text: String(n.text || "") }]
|
|
2265
|
-
}
|
|
2266
|
-
} : t === "tool.call.begin" ? {
|
|
2267
|
-
...e,
|
|
2268
|
-
EventType: "tool_call",
|
|
2269
|
-
Metadata: {
|
|
2270
|
-
...e.Metadata || {},
|
|
2271
|
-
tool_name: n.name,
|
|
2272
|
-
tool_args: n.args,
|
|
2273
|
-
tool_call_id: n.call_id
|
|
2274
|
-
},
|
|
2275
|
-
Content: {
|
|
2276
|
-
role: "model",
|
|
2277
|
-
parts: []
|
|
2278
|
-
}
|
|
2279
|
-
} : t === "tool.call.end" ? {
|
|
2280
|
-
...e,
|
|
2281
|
-
EventType: "tool_result",
|
|
2282
|
-
Metadata: {
|
|
2283
|
-
...e.Metadata || {},
|
|
2284
|
-
tool_name: n.name,
|
|
2285
|
-
tool_output: n.error || n.result,
|
|
2286
|
-
tool_call_id: n.call_id
|
|
2287
|
-
},
|
|
2288
|
-
Content: {
|
|
2289
|
-
role: "model",
|
|
2290
|
-
parts: []
|
|
2291
|
-
}
|
|
2292
|
-
} : e;
|
|
2293
|
-
}
|
|
2294
|
-
function Tt(e) {
|
|
2295
|
-
let t = [], n = /* @__PURE__ */ new Map();
|
|
2296
|
-
for (let r of Array.isArray(e) ? e : []) {
|
|
2297
|
-
let e = String(r?.EventType || "");
|
|
2298
|
-
if (e === "text.delta" || e === "text.completed" || e === "message.delta") {
|
|
2299
|
-
let e = String(r?.InvocationId || "").trim();
|
|
2300
|
-
if (!e) continue;
|
|
2301
|
-
let t = n.get(e);
|
|
2302
|
-
n.set(e, {
|
|
2303
|
-
event: r,
|
|
2304
|
-
text: Ct(t?.text, X(r).text || r?.Content?.text)
|
|
2305
|
-
});
|
|
2306
|
-
continue;
|
|
2307
|
-
}
|
|
2308
|
-
t.push(wt(r));
|
|
2309
|
-
}
|
|
2310
|
-
for (let { event: e, text: r } of n.values()) t.push({
|
|
2311
|
-
...e,
|
|
2312
|
-
EventType: "assistant_stream_snapshot",
|
|
2313
|
-
Content: {
|
|
2314
|
-
role: "model",
|
|
2315
|
-
parts: [{ text: r }]
|
|
2316
|
-
},
|
|
2317
|
-
Metadata: {
|
|
2318
|
-
...e.Metadata || {},
|
|
2319
|
-
stream_snapshot: !0
|
|
2320
|
-
}
|
|
2321
|
-
});
|
|
2322
|
-
for (let n of Array.isArray(e) ? e : []) String(n?.EventType || "") === "message.completed" && t.push({
|
|
2323
|
-
...n,
|
|
2324
|
-
EventType: "assistant_message",
|
|
2325
|
-
Content: {
|
|
2326
|
-
role: "model",
|
|
2327
|
-
parts: [{ text: String(X(n).text || n?.Content?.text || "") }]
|
|
2328
|
-
}
|
|
2329
|
-
});
|
|
2330
|
-
return t.sort((e, t) => Q(e) - Q(t));
|
|
2331
|
-
}
|
|
2332
|
-
function Et(e) {
|
|
2333
|
-
let t = String(e?.EventType || "").trim();
|
|
2334
|
-
if (t !== "run_status" && !t.startsWith("run.")) return "";
|
|
2335
|
-
let n = X(e);
|
|
2336
|
-
return String(e?.Content?.status || n.status || St[t] || "").trim().toLowerCase();
|
|
2337
|
-
}
|
|
2338
|
-
function Dt(e) {
|
|
2339
|
-
return typeof e == "string" ? e : Array.isArray(e) ? e.map((e) => typeof e == "string" ? e : e && typeof e == "object" && typeof e.text == "string" ? e.text : "").join("") : "";
|
|
2340
|
-
}
|
|
2341
|
-
function Ot(e) {
|
|
2342
|
-
let t = String(e || "").trim();
|
|
2343
|
-
return t ? `/agentengine/api/v1/AttachmentContent?FileUri=${encodeURIComponent(t)}` : "";
|
|
2344
|
-
}
|
|
2345
|
-
function kt(e) {
|
|
2346
|
-
return String(e || "").match(/^data:([^;,]+)/)?.[1] || "";
|
|
2347
|
-
}
|
|
2348
|
-
function At(e, t) {
|
|
2349
|
-
let n = String(e || "").trim(), r = String(t || "").trim();
|
|
2350
|
-
return !n || !r || n === r ? !0 : n.endsWith("/*") ? r.startsWith(n.slice(0, -1)) : r.endsWith("/*") ? n.startsWith(r.slice(0, -1)) : !1;
|
|
2351
|
-
}
|
|
2352
|
-
function Z(e) {
|
|
2353
|
-
let t = e?.Content?.parts || [], n = [], r = /* @__PURE__ */ new Map(), i = (e) => {
|
|
2354
|
-
let t = `${e.fileUri || e.url || e.name}|${e.type}`;
|
|
2355
|
-
r.has(t) || r.set(t, e);
|
|
2356
|
-
};
|
|
2357
|
-
for (let e of t) {
|
|
2358
|
-
if (e?.type === "input_text" || e?.text) {
|
|
2359
|
-
n.push(e.text || "");
|
|
2360
|
-
continue;
|
|
2361
|
-
}
|
|
2362
|
-
if (e?.type === "input_file" && e.inlineData) {
|
|
2363
|
-
i({
|
|
2364
|
-
name: e.inlineData.displayName || "attachment",
|
|
2365
|
-
url: `data:${e.inlineData.mimeType || "application/octet-stream"};base64,${e.inlineData.data}`,
|
|
2366
|
-
type: e.inlineData.mimeType || "application/octet-stream"
|
|
2367
|
-
});
|
|
2368
|
-
continue;
|
|
2369
|
-
}
|
|
2370
|
-
if (e?.type === "input_file" && typeof e.file_data == "string" && e.file_data) {
|
|
2371
|
-
i({
|
|
2372
|
-
name: e.filename || e.displayName || e.display_name || "attachment",
|
|
2373
|
-
url: `data:${e.mime_type || e.mimeType || "application/octet-stream"};base64,${e.file_data}`,
|
|
2374
|
-
type: e.mime_type || e.mimeType || "application/octet-stream"
|
|
2375
|
-
});
|
|
2376
|
-
continue;
|
|
2377
|
-
}
|
|
2378
|
-
if (e?.type === "input_file" && typeof e.file_url == "string" && e.file_url.trim()) {
|
|
2379
|
-
let t = e.file_url.trim();
|
|
2380
|
-
i({
|
|
2381
|
-
name: e.filename || e.displayName || e.display_name || "attachment",
|
|
2382
|
-
url: Ot(t),
|
|
2383
|
-
type: e.mime_type || e.mimeType || "application/octet-stream",
|
|
2384
|
-
fileUri: t
|
|
2385
|
-
});
|
|
2386
|
-
continue;
|
|
2387
|
-
}
|
|
2388
|
-
if (e?.type === "input_image" || e?.type === "image_url") {
|
|
2389
|
-
let t = typeof e.image_url == "string" ? e.image_url : e.image_url?.url;
|
|
2390
|
-
t && i({
|
|
2391
|
-
name: e.filename || e.displayName || e.display_name || "uploaded_image",
|
|
2392
|
-
url: t,
|
|
2393
|
-
type: e.mime_type || e.mimeType || kt(t) || "image/*"
|
|
2394
|
-
});
|
|
2395
|
-
continue;
|
|
2396
|
-
}
|
|
2397
|
-
if (e?.type === "input_file" && e.fileData) {
|
|
2398
|
-
let t = String(e.fileData.fileUri || "").trim();
|
|
2399
|
-
i({
|
|
2400
|
-
name: e.fileData.displayName || "attachment",
|
|
2401
|
-
url: Ot(t),
|
|
2402
|
-
type: e.fileData.mimeType || "application/octet-stream",
|
|
2403
|
-
fileUri: t
|
|
2404
|
-
});
|
|
2405
|
-
}
|
|
2406
|
-
}
|
|
2407
|
-
let a = Array.isArray(e?.Metadata?.attachments) ? e.Metadata.attachments : [];
|
|
2408
|
-
for (let e of a) {
|
|
2409
|
-
let t = String(e.file_uri || "").trim(), n = {
|
|
2410
|
-
name: e.display_name || "attachment",
|
|
2411
|
-
url: Ot(t),
|
|
2412
|
-
type: e.mime_type || "application/octet-stream",
|
|
2413
|
-
fileUri: t
|
|
2414
|
-
};
|
|
2415
|
-
!n.url && !n.fileUri && Array.from(r.values()).some((e) => e.name === n.name && At(e.type, n.type) && (e.url || e.fileUri)) || i(n);
|
|
2416
|
-
}
|
|
2417
|
-
let o = Array.from(r.values());
|
|
2418
|
-
return {
|
|
2419
|
-
text: n.join(""),
|
|
2420
|
-
attachments: o.length > 0 ? o : void 0
|
|
2421
|
-
};
|
|
2422
|
-
}
|
|
2423
|
-
function jt(e) {
|
|
2424
|
-
let t = e?.Metadata?.responses_output;
|
|
2425
|
-
if (!Array.isArray(t)) return {};
|
|
2426
|
-
let r = ut(), i = yt({
|
|
2427
|
-
eventName: "response.completed",
|
|
2428
|
-
data: { response: {
|
|
2429
|
-
id: String(e.Metadata?.response_id || ""),
|
|
2430
|
-
output: t
|
|
2431
|
-
} },
|
|
2432
|
-
state: r
|
|
2433
|
-
}), a = "", o = {};
|
|
2434
|
-
for (let e of i) {
|
|
2435
|
-
if (e.type === "reasoning_delta") {
|
|
2436
|
-
a += e.text;
|
|
2437
|
-
continue;
|
|
2438
|
-
}
|
|
2439
|
-
if (e.type === "tool_upsert") {
|
|
2440
|
-
o[e.name] = {
|
|
2441
|
-
...o[e.name] || {
|
|
2442
|
-
name: e.name,
|
|
2443
|
-
args: ""
|
|
2444
|
-
},
|
|
2445
|
-
name: e.name,
|
|
2446
|
-
args: e.args,
|
|
2447
|
-
status: e.status,
|
|
2448
|
-
...e.approvalRequestId ? { approvalRequestId: e.approvalRequestId } : {},
|
|
2449
|
-
...e.previousResponseId ? { previousResponseId: e.previousResponseId } : {},
|
|
2450
|
-
...e.serverLabel ? { serverLabel: e.serverLabel } : {},
|
|
2451
|
-
...e.approvalRequestId ? { approvalStatus: "pending" } : {}
|
|
2452
|
-
};
|
|
2453
|
-
continue;
|
|
2454
|
-
}
|
|
2455
|
-
e.type === "tool_result" && (o[e.name] = {
|
|
2456
|
-
...o[e.name] || {
|
|
2457
|
-
name: e.name,
|
|
2458
|
-
args: ""
|
|
2459
|
-
},
|
|
2460
|
-
name: e.name,
|
|
2461
|
-
output: e.output,
|
|
2462
|
-
status: n(e.output) ? "error" : "completed"
|
|
2463
|
-
});
|
|
2464
|
-
}
|
|
2465
|
-
return {
|
|
2466
|
-
...a ? { reasoning: a } : {},
|
|
2467
|
-
...Object.keys(o).length > 0 ? { tools: o } : {}
|
|
2468
|
-
};
|
|
2469
|
-
}
|
|
2470
|
-
function Mt(e, t, n) {
|
|
2471
|
-
return t === "running" ? e === "prompt_too_long" ? "检测到上下文过长,正在自动压缩历史后重试" : "正在自动压缩上下文" : n ? e === "prompt_too_long" ? "上下文过长,系统已自动压缩历史并重试" : "系统已自动压缩较早的对话上下文" : t === "failed" ? "自动压缩上下文未完成" : e === "prompt_too_long" ? "已完成上下文压缩,并继续当前回复" : "已完成上下文压缩";
|
|
2472
|
-
}
|
|
2473
|
-
function Nt(e, t) {
|
|
2474
|
-
return t?.itemId ? [
|
|
2475
|
-
"runtime-item",
|
|
2476
|
-
t.runId || e,
|
|
2477
|
-
t.scopeId || e,
|
|
2478
|
-
t.itemId
|
|
2479
|
-
].join("\0") : [
|
|
2480
|
-
e,
|
|
2481
|
-
t.content || "",
|
|
2482
|
-
t.reasoning || ""
|
|
2483
|
-
].join("\0");
|
|
2484
|
-
}
|
|
2485
|
-
function Pt(e) {
|
|
2486
|
-
let t = String(e?.InvocationId || "").trim(), n = e?.Metadata?.RuntimeItem;
|
|
2487
|
-
return n?.ItemId ? [
|
|
2488
|
-
"runtime-item",
|
|
2489
|
-
n.RunId || t,
|
|
2490
|
-
n.ScopeId || t,
|
|
2491
|
-
n.ItemId
|
|
2492
|
-
].join("\0") : t;
|
|
2493
|
-
}
|
|
2494
|
-
function Ft(e) {
|
|
2495
|
-
let t = e?.Metadata?.RuntimeItem;
|
|
2496
|
-
return t?.ItemId ? {
|
|
2497
|
-
id: `runtime:${t.RunId || e.InvocationId || "run"}:${t.ScopeId || e.InvocationId || "scope"}:${t.ItemId}`,
|
|
2498
|
-
runId: String(t.RunId || e.InvocationId || ""),
|
|
2499
|
-
scopeId: String(t.ScopeId || e.InvocationId || ""),
|
|
2500
|
-
itemId: String(t.ItemId),
|
|
2501
|
-
partId: t.PartId ? String(t.PartId) : void 0
|
|
2502
|
-
} : null;
|
|
2503
|
-
}
|
|
2504
|
-
function It(e) {
|
|
2505
|
-
return e?.Metadata?.responses_mirror === !0 || String(e?.Metadata?.responses_mirror || "").trim().toLowerCase() === "true";
|
|
2506
|
-
}
|
|
2507
|
-
function Lt(e) {
|
|
2508
|
-
if (e?.EventType !== "user_message") return "";
|
|
2509
|
-
let t = Z(e), n = (t.attachments || []).map((e) => [
|
|
2510
|
-
e.name || "",
|
|
2511
|
-
e.fileUri || "",
|
|
2512
|
-
e.url || "",
|
|
2513
|
-
e.type || ""
|
|
2514
|
-
].join("")).sort().join("");
|
|
2515
|
-
return [String(t.text || "").trim(), n].join("\0");
|
|
2516
|
-
}
|
|
2517
|
-
function Rt(e) {
|
|
2518
|
-
return e?.EventType === "assistant_stream_snapshot";
|
|
2519
|
-
}
|
|
1912
|
+
//#region src/utils/persisted-session-history.ts
|
|
2520
1913
|
function Q(e) {
|
|
2521
|
-
|
|
2522
|
-
if (Number.isFinite(t) && t > 0) return t;
|
|
2523
|
-
let n = Number(e?.Timestamp || 0);
|
|
2524
|
-
return Number.isFinite(n) ? n : 0;
|
|
2525
|
-
}
|
|
2526
|
-
function zt(e) {
|
|
2527
|
-
if (typeof e == "string") return e;
|
|
2528
|
-
if (e == null) return "";
|
|
2529
|
-
try {
|
|
2530
|
-
return JSON.stringify(e, null, 2);
|
|
2531
|
-
} catch {
|
|
2532
|
-
return String(e);
|
|
2533
|
-
}
|
|
2534
|
-
}
|
|
2535
|
-
function Bt(e) {
|
|
2536
|
-
let t = String(e?.EventType || "");
|
|
2537
|
-
if (!xt.has(t)) return null;
|
|
2538
|
-
let r = String(e.Metadata?.tool_name || e.Metadata?.name || e.Metadata?.function_name || Dt(e.Content?.parts) || "tool").trim() || "tool", i = String(e.Metadata?.call_id || e.Metadata?.callId || e.Metadata?.RuntimeItem?.ToolCallId || "").trim(), a = {
|
|
2539
|
-
name: r,
|
|
2540
|
-
...i ? { callId: i } : {},
|
|
2541
|
-
args: "",
|
|
2542
|
-
status: "running"
|
|
2543
|
-
}, o = t === "tool_result" || t === "stage_tool_result" ? (() => {
|
|
2544
|
-
let t = zt(e.Metadata?.tool_output ?? e.Metadata?.output ?? e.Metadata?.result ?? Dt(e.Content?.parts));
|
|
2545
|
-
return {
|
|
2546
|
-
...a,
|
|
2547
|
-
output: t,
|
|
2548
|
-
status: n(t) ? "error" : "completed"
|
|
2549
|
-
};
|
|
2550
|
-
})() : {
|
|
2551
|
-
...a,
|
|
2552
|
-
args: zt(e.Metadata?.tool_args ?? e.Metadata?.arguments ?? e.Metadata?.args ?? {})
|
|
2553
|
-
}, s = Ft(e);
|
|
2554
|
-
return {
|
|
2555
|
-
id: s?.id || e.EventId || String(Date.now() + Math.random()),
|
|
2556
|
-
role: "model",
|
|
2557
|
-
content: "",
|
|
2558
|
-
timestamp: e.Timestamp || Date.now(),
|
|
2559
|
-
eventType: t,
|
|
2560
|
-
...s || {},
|
|
2561
|
-
tools: { [r]: o }
|
|
2562
|
-
};
|
|
2563
|
-
}
|
|
2564
|
-
function Vt(e = {}, t = {}) {
|
|
2565
|
-
let n = { ...e || {} };
|
|
2566
|
-
for (let [e, r] of Object.entries(t || {})) n[e] = {
|
|
2567
|
-
...n[e] || {},
|
|
2568
|
-
...r || {},
|
|
2569
|
-
name: e,
|
|
2570
|
-
args: r?.args || n[e]?.args || ""
|
|
2571
|
-
};
|
|
2572
|
-
return n;
|
|
2573
|
-
}
|
|
2574
|
-
function Ht(e = {}, t = "") {
|
|
2575
|
-
let n = String(t || "").trim().toLowerCase(), r = n === "completed" ? "completed" : bt.has(n) ? "error" : "";
|
|
2576
|
-
if (!r) return e;
|
|
2577
|
-
let i = !1, a = {};
|
|
2578
|
-
for (let [t, n] of Object.entries(e || {})) n?.status === "running" ? (i = !0, a[t] = {
|
|
2579
|
-
...n,
|
|
2580
|
-
status: r
|
|
2581
|
-
}) : a[t] = n;
|
|
2582
|
-
return i ? a : e;
|
|
2583
|
-
}
|
|
2584
|
-
function Ut(e, t) {
|
|
2585
|
-
return {
|
|
2586
|
-
...e,
|
|
2587
|
-
reasoning: Wt(e.reasoning, t.reasoning),
|
|
2588
|
-
tools: Vt(e.tools, t.tools),
|
|
2589
|
-
eventId: t.eventId || e.eventId,
|
|
2590
|
-
responseId: t.responseId || e.responseId,
|
|
2591
|
-
traceId: t.traceId || e.traceId,
|
|
2592
|
-
rootSpanId: t.rootSpanId || e.rootSpanId,
|
|
2593
|
-
timestamp: Math.max(Number(e.timestamp || 0), Number(t.timestamp || 0)) || t.timestamp || e.timestamp,
|
|
2594
|
-
id: t.responseId || t.reasoning || t.tools ? t.id : e.id
|
|
2595
|
-
};
|
|
2596
|
-
}
|
|
2597
|
-
function Wt(e = "", t = "") {
|
|
2598
|
-
let n = String(e || ""), r = String(t || "");
|
|
2599
|
-
return n ? !r || n.endsWith(r) ? n : r.startsWith(n) ? r : `${n}${r}` : r;
|
|
2600
|
-
}
|
|
2601
|
-
function Gt(e) {
|
|
2602
|
-
return {
|
|
2603
|
-
id: e.id,
|
|
2604
|
-
role: "system",
|
|
2605
|
-
eventType: "context_checkpoint",
|
|
2606
|
-
status: e.status,
|
|
2607
|
-
trigger: e.trigger,
|
|
2608
|
-
compactedUntilSeqId: e.compactedUntilSeqId,
|
|
2609
|
-
summary: e.summary,
|
|
2610
|
-
historical: e.historical,
|
|
2611
|
-
timestamp: e.timestamp,
|
|
2612
|
-
content: Mt(e.trigger, e.status, e.historical)
|
|
2613
|
-
};
|
|
2614
|
-
}
|
|
2615
|
-
function Kt(e) {
|
|
2616
|
-
let t = qt(e);
|
|
2617
|
-
return t && Number.isSafeInteger(e.SeqId) && e.SeqId > 0 && (t.historyOrder = { seq: e.SeqId }), t;
|
|
2618
|
-
}
|
|
2619
|
-
function qt(e) {
|
|
2620
|
-
let t = e?.EventType || "", n = Ft(e);
|
|
2621
|
-
if (t === "run_status") return e.Content?.status === "failed" ? {
|
|
2622
|
-
id: e.EventId || String(Date.now() + Math.random()),
|
|
2623
|
-
role: "system",
|
|
2624
|
-
content: e.Content?.detail || "本轮运行失败。",
|
|
2625
|
-
eventType: t,
|
|
2626
|
-
status: "failed",
|
|
2627
|
-
timestamp: e.Timestamp || Date.now()
|
|
2628
|
-
} : e.Content?.status === "cancelled" ? {
|
|
2629
|
-
id: e.EventId || String(Date.now() + Math.random()),
|
|
2630
|
-
role: "system",
|
|
2631
|
-
content: e.Content?.detail || "本轮输出已停止。",
|
|
2632
|
-
eventType: t,
|
|
2633
|
-
status: "cancelled",
|
|
2634
|
-
timestamp: e.Timestamp || Date.now()
|
|
2635
|
-
} : null;
|
|
2636
|
-
if (t === "context_checkpoint") {
|
|
2637
|
-
let t = Z(e);
|
|
2638
|
-
return Gt({
|
|
2639
|
-
id: e.EventId || String(Date.now() + Math.random()),
|
|
2640
|
-
timestamp: e.Timestamp || Date.now(),
|
|
2641
|
-
status: "completed",
|
|
2642
|
-
trigger: String(e.Metadata?.trigger || "auto"),
|
|
2643
|
-
compactedUntilSeqId: Number(e.Metadata?.compacted_until_seq_id || 0) || void 0,
|
|
2644
|
-
summary: t.text || void 0,
|
|
2645
|
-
historical: !0
|
|
2646
|
-
});
|
|
2647
|
-
}
|
|
2648
|
-
if (t === "reasoning") {
|
|
2649
|
-
let r = Z(e).text || Dt(e.Metadata?.reasoning);
|
|
2650
|
-
return r ? {
|
|
2651
|
-
id: n?.id || e.EventId || String(Date.now() + Math.random()),
|
|
2652
|
-
role: "model",
|
|
2653
|
-
content: "",
|
|
2654
|
-
reasoning: r,
|
|
2655
|
-
...e.Metadata?.presentation_source === "public_summary" ? { reasoningSource: "public_summary" } : e.Metadata?.presentation_source === "provider_reasoning" ? { reasoningSource: "provider_reasoning" } : {},
|
|
2656
|
-
timestamp: e.Timestamp || Date.now(),
|
|
2657
|
-
eventType: t,
|
|
2658
|
-
...n || {}
|
|
2659
|
-
} : null;
|
|
2660
|
-
}
|
|
2661
|
-
if (xt.has(t)) return Bt(e);
|
|
2662
|
-
if (t !== "user_message" && t !== "assistant_message" && t !== "assistant_stream_snapshot") return null;
|
|
2663
|
-
let r = Z(e), i = t === "assistant_message" ? jt(e) : {};
|
|
2664
|
-
if (!r.text && !r.attachments?.length && !i.reasoning && !i.tools) return null;
|
|
2665
|
-
let a = String(e.Metadata?.response_id || e.Metadata?.ResponseId || "").trim(), o = String(e.Metadata?.trace_id || e.Metadata?.TraceId || "").trim(), s = String(e.Metadata?.root_span_id || e.Metadata?.rootSpanId || e.Metadata?.RootSpanId || "").trim();
|
|
2666
|
-
return {
|
|
2667
|
-
id: n?.id || e.EventId || String(Date.now() + Math.random()),
|
|
2668
|
-
role: t === "user_message" ? "user" : "model",
|
|
2669
|
-
content: r.text,
|
|
2670
|
-
timestamp: e.Timestamp || Date.now(),
|
|
2671
|
-
eventType: t,
|
|
2672
|
-
eventId: e.EventId || void 0,
|
|
2673
|
-
responseId: a || void 0,
|
|
2674
|
-
traceId: o || void 0,
|
|
2675
|
-
rootSpanId: s || void 0,
|
|
2676
|
-
attachments: r.attachments,
|
|
2677
|
-
...n || {},
|
|
2678
|
-
...i
|
|
2679
|
-
};
|
|
1914
|
+
return e && typeof e == "object" && !Array.isArray(e) ? e : null;
|
|
2680
1915
|
}
|
|
2681
|
-
function
|
|
2682
|
-
let t =
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
t && u.add(t);
|
|
2697
|
-
}
|
|
2698
|
-
if (Rt(e)) {
|
|
2699
|
-
let t = Pt(e);
|
|
2700
|
-
if (t) {
|
|
2701
|
-
let n = d.get(t);
|
|
2702
|
-
(!n || Q(e) >= Q(n)) && d.set(t, e);
|
|
2703
|
-
}
|
|
2704
|
-
}
|
|
2705
|
-
continue;
|
|
2706
|
-
}
|
|
2707
|
-
let t = Lt(e);
|
|
2708
|
-
t && l.add(t);
|
|
2709
|
-
}
|
|
2710
|
-
let f = c.filter((e) => {
|
|
2711
|
-
if (Rt(e)) {
|
|
2712
|
-
let t = Pt(e);
|
|
2713
|
-
return t ? u.has(t) ? !1 : d.get(t) === e : !0;
|
|
2714
|
-
}
|
|
2715
|
-
if (e?.EventType !== "user_message" || !It(e)) return !0;
|
|
2716
|
-
let t = Lt(e);
|
|
2717
|
-
return !t || !l.has(t);
|
|
2718
|
-
});
|
|
2719
|
-
for (let e of f) {
|
|
2720
|
-
let a = String(e.InvocationId || "").trim();
|
|
2721
|
-
a && e.EventType === "user_message" && i.add(a), a && [
|
|
2722
|
-
"assistant_message",
|
|
2723
|
-
"assistant_stream_snapshot",
|
|
2724
|
-
"reasoning",
|
|
2725
|
-
"tool_call",
|
|
2726
|
-
"tool_result",
|
|
2727
|
-
"stage_tool_call",
|
|
2728
|
-
"stage_tool_result"
|
|
2729
|
-
].includes(String(e.EventType || "")) && r.add(a), e.EventType === "run_status" && a && (t.set(a, String(e.Content?.status || "").trim()), n.set(a, e));
|
|
2730
|
-
}
|
|
2731
|
-
let p = [], m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), g = null, _ = /* @__PURE__ */ new Map(), v = (e) => {
|
|
2732
|
-
let t = e?.itemId ? `${e.runId || e.invocationId || ""}\u0000${e.scopeId || e.invocationId || ""}\u0000${e.itemId}` : "", n = t ? h.get(t) : void 0;
|
|
2733
|
-
if (n !== void 0) {
|
|
2734
|
-
p[n] = Ut(p[n], e);
|
|
2735
|
-
return;
|
|
2736
|
-
}
|
|
2737
|
-
let r = String(e?.responseId || "").trim(), i = r ? m.get(r) : void 0;
|
|
2738
|
-
if (i !== void 0) {
|
|
2739
|
-
p[i] = Ut(p[i], e);
|
|
2740
|
-
return;
|
|
2741
|
-
}
|
|
2742
|
-
r && m.set(r, p.length), t && h.set(t, p.length), p.push(e);
|
|
2743
|
-
}, y = () => {
|
|
2744
|
-
g &&= (v(g), null);
|
|
2745
|
-
}, b = (e, n = "") => {
|
|
2746
|
-
let r = String(e || "").trim();
|
|
2747
|
-
if (!r) return {};
|
|
2748
|
-
let i = _.get(r);
|
|
2749
|
-
return i ? (_.delete(r), { tools: Ht(i.tools, t.get(r) || n) }) : {};
|
|
2750
|
-
};
|
|
2751
|
-
for (let e of f) {
|
|
2752
|
-
if (e.EventType === "run_status") continue;
|
|
2753
|
-
let t = Kt(e);
|
|
2754
|
-
if (!t) continue;
|
|
2755
|
-
let n = String(e.InvocationId || "").trim();
|
|
2756
|
-
if (n && (t.invocationId = n), xt.has(t.eventType)) {
|
|
2757
|
-
let n = String(e.InvocationId || "").trim();
|
|
2758
|
-
if (t.itemId) {
|
|
2759
|
-
y(), v(t);
|
|
2760
|
-
continue;
|
|
2761
|
-
}
|
|
2762
|
-
if (!n) {
|
|
2763
|
-
y(), v(t);
|
|
2764
|
-
continue;
|
|
2765
|
-
}
|
|
2766
|
-
let r = _.get(n);
|
|
2767
|
-
_.set(n, {
|
|
2768
|
-
...r || {
|
|
2769
|
-
id: t.id,
|
|
2770
|
-
role: "model",
|
|
2771
|
-
content: "",
|
|
2772
|
-
timestamp: t.timestamp,
|
|
2773
|
-
invocationId: n
|
|
2774
|
-
},
|
|
2775
|
-
timestamp: Math.max(Number(r?.timestamp || 0), Number(t.timestamp || 0)),
|
|
2776
|
-
tools: Vt(r?.tools, t.tools)
|
|
2777
|
-
});
|
|
2778
|
-
continue;
|
|
2779
|
-
}
|
|
2780
|
-
if (t.eventType === "reasoning") {
|
|
2781
|
-
let n = String(e.InvocationId || "").trim(), r = String(e.Metadata?.RuntimeItem?.Operation || "").toLowerCase(), i = !!(t.itemId && g?.itemId === t.itemId && g?.runId === t.runId && g?.scopeId === t.scopeId), a = !!(!t.itemId && !g?.itemId && n && g?.invocationId === n);
|
|
2782
|
-
if (g && (i || a)) {
|
|
2783
|
-
g.reasoning = r === "replace" || r === "completed" ? t.reasoning : `${g.reasoning || ""}${t.reasoning || ""}`, g.timestamp = t.timestamp;
|
|
2784
|
-
continue;
|
|
2785
|
-
}
|
|
2786
|
-
y(), g = {
|
|
2787
|
-
...t,
|
|
2788
|
-
...n ? { invocationId: n } : {}
|
|
2789
|
-
};
|
|
2790
|
-
continue;
|
|
2791
|
-
}
|
|
2792
|
-
let r = t.eventType === "assistant_message" || t.eventType === "assistant_stream_snapshot";
|
|
2793
|
-
if (r && g) {
|
|
2794
|
-
let n = String(e.InvocationId || "").trim(), r = Nt(n, t);
|
|
2795
|
-
if (t.eventType === "assistant_message" && n && a.has(r)) {
|
|
2796
|
-
g = null;
|
|
2797
|
-
continue;
|
|
2798
|
-
}
|
|
2799
|
-
t.eventType === "assistant_message" && n && a.add(r), v({
|
|
2800
|
-
...t,
|
|
2801
|
-
...b(n, t.eventType === "assistant_message" ? "completed" : ""),
|
|
2802
|
-
reasoning: Wt(g.reasoning, t.reasoning)
|
|
2803
|
-
}), g = null;
|
|
2804
|
-
continue;
|
|
2805
|
-
}
|
|
2806
|
-
if (y(), r) {
|
|
2807
|
-
let n = String(e.InvocationId || "").trim(), r = Nt(n, t);
|
|
2808
|
-
if (t.eventType === "assistant_message" && n && a.has(r)) continue;
|
|
2809
|
-
t.eventType === "assistant_message" && n && a.add(r), v({
|
|
2810
|
-
...t,
|
|
2811
|
-
...b(n, t.eventType === "assistant_message" ? "completed" : "")
|
|
2812
|
-
});
|
|
2813
|
-
continue;
|
|
2814
|
-
}
|
|
2815
|
-
v(t);
|
|
2816
|
-
}
|
|
2817
|
-
y();
|
|
2818
|
-
for (let [e, n] of _.entries()) v({
|
|
2819
|
-
...n,
|
|
2820
|
-
tools: Ht(n.tools, t.get(e))
|
|
2821
|
-
});
|
|
2822
|
-
for (let [e, a] of t.entries()) {
|
|
2823
|
-
if (a !== "in_progress" || r.has(e) || !i.has(e)) continue;
|
|
2824
|
-
let t = n.get(e) || {};
|
|
2825
|
-
v({
|
|
2826
|
-
id: `run-placeholder-${e}`,
|
|
2827
|
-
role: "model",
|
|
2828
|
-
content: "",
|
|
2829
|
-
status: "running",
|
|
2830
|
-
eventType: "run_status",
|
|
2831
|
-
timestamp: t.Timestamp || Date.now()
|
|
2832
|
-
});
|
|
2833
|
-
}
|
|
2834
|
-
return p;
|
|
2835
|
-
}
|
|
2836
|
-
function Yt(e = [], t = []) {
|
|
2837
|
-
let n = [], r = /* @__PURE__ */ new Set();
|
|
2838
|
-
for (let i of [...Array.isArray(e) ? e : [], ...Array.isArray(t) ? t : []]) {
|
|
2839
|
-
let e = String(i?.EventId || "").trim();
|
|
2840
|
-
if (e) {
|
|
2841
|
-
if (r.has(e)) continue;
|
|
2842
|
-
r.add(e);
|
|
1916
|
+
function ot(e) {
|
|
1917
|
+
let t = e.map(ct), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t, n) => JSON.stringify([
|
|
1918
|
+
e,
|
|
1919
|
+
t,
|
|
1920
|
+
n
|
|
1921
|
+
]);
|
|
1922
|
+
for (let e of t) {
|
|
1923
|
+
if (!e || Q(e.source)?.framework !== "langgraph" || e.item_kind !== "tool_call" && e.item_kind !== "tool_result") continue;
|
|
1924
|
+
let t = Q(e.snapshot ?? e.initial)?.parts;
|
|
1925
|
+
if (!Array.isArray(t)) continue;
|
|
1926
|
+
let a = t.map(Q).find((t) => t?.content_type === e.item_kind)?.call_id;
|
|
1927
|
+
if (!(typeof a != "string" || !a)) if (e.item_kind === "tool_result") r.set(i(e.run_id, e.scope_id, e.item_id), a);
|
|
1928
|
+
else {
|
|
1929
|
+
let t = i(e.run_id, e.scope_id, a);
|
|
1930
|
+
n.has(t) ? n.get(t)?.item_id !== e.item_id && n.set(t, null) : n.set(t, e);
|
|
2843
1931
|
}
|
|
2844
|
-
n.push(i);
|
|
2845
1932
|
}
|
|
2846
|
-
return
|
|
2847
|
-
|
|
2848
|
-
|
|
1933
|
+
return t.map((e) => {
|
|
1934
|
+
if (!e || e.item_kind !== "tool_result" || !e.parent_scope_id) return e;
|
|
1935
|
+
let t = r.get(i(e.run_id, e.scope_id, e.item_id));
|
|
1936
|
+
if (!t || n.has(i(e.run_id, e.scope_id, t))) return e;
|
|
1937
|
+
let a = n.get(i(e.run_id, e.parent_scope_id, t));
|
|
1938
|
+
return a ? {
|
|
1939
|
+
...e,
|
|
1940
|
+
scope_id: a.scope_id,
|
|
1941
|
+
parent_scope_id: a.parent_scope_id
|
|
1942
|
+
} : e;
|
|
2849
1943
|
});
|
|
2850
1944
|
}
|
|
2851
|
-
function
|
|
2852
|
-
return (Array.isArray(e) ? e : []).reduce((e, t) => {
|
|
2853
|
-
let n = Number(t.SeqId || 0);
|
|
2854
|
-
return Number.isFinite(n) ? Math.max(e, n) : e;
|
|
2855
|
-
}, 0);
|
|
2856
|
-
}
|
|
2857
|
-
function Zt(e) {
|
|
2858
|
-
return bt.has(Et(e));
|
|
2859
|
-
}
|
|
2860
|
-
//#endregion
|
|
2861
|
-
//#region src/utils/persisted-session-history.ts
|
|
2862
|
-
function $(e) {
|
|
2863
|
-
return e && typeof e == "object" && !Array.isArray(e) ? e : null;
|
|
2864
|
-
}
|
|
2865
|
-
function Qt(e) {
|
|
1945
|
+
function st(e) {
|
|
2866
1946
|
if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
|
|
2867
1947
|
if (typeof e == "string" && e.trim()) {
|
|
2868
1948
|
let t = Number(e.trim());
|
|
@@ -2871,17 +1951,17 @@ function Qt(e) {
|
|
|
2871
1951
|
let t = Date.parse(String(e || ""));
|
|
2872
1952
|
return Number.isFinite(t) ? t : Date.now();
|
|
2873
1953
|
}
|
|
2874
|
-
function
|
|
2875
|
-
let t =
|
|
1954
|
+
function ct(e) {
|
|
1955
|
+
let t = Q(e?.Content?.runtime_event || e?.Content?.runtimeEvent);
|
|
2876
1956
|
if (t && String(t.event_type || "")) return {
|
|
2877
1957
|
...t,
|
|
2878
1958
|
family: "runtime",
|
|
2879
1959
|
seq: Number(e.SeqId || t.seq || 0),
|
|
2880
1960
|
timestamp: e.Timestamp || t.timestamp
|
|
2881
1961
|
};
|
|
2882
|
-
let n =
|
|
1962
|
+
let n = Q(e?.Content?.session_event || e?.Content?.sessionEvent);
|
|
2883
1963
|
if (!n || String(n.family || "") !== "runtime") return null;
|
|
2884
|
-
let r =
|
|
1964
|
+
let r = Q(n.payload);
|
|
2885
1965
|
return !r || !String(r.event_type || n.event_type || "") ? null : {
|
|
2886
1966
|
...r,
|
|
2887
1967
|
family: "runtime",
|
|
@@ -2891,58 +1971,58 @@ function $t(e) {
|
|
|
2891
1971
|
timestamp: e.Timestamp || n.timestamp || r.timestamp
|
|
2892
1972
|
};
|
|
2893
1973
|
}
|
|
2894
|
-
function
|
|
2895
|
-
let
|
|
2896
|
-
for (let e of
|
|
2897
|
-
if (e.EventType !== "run_status" ||
|
|
1974
|
+
function lt(e, n, r) {
|
|
1975
|
+
let i = /* @__PURE__ */ new Map();
|
|
1976
|
+
for (let e of n) {
|
|
1977
|
+
if (e.EventType !== "run_status" || ct(e)) continue;
|
|
2898
1978
|
let t = String(e.InvocationId || e.Metadata?.run_id || "").trim();
|
|
2899
|
-
t && !
|
|
1979
|
+
t && !r.has(t) && i.set(t, e);
|
|
2900
1980
|
}
|
|
2901
|
-
let
|
|
2902
|
-
for (let [e,
|
|
2903
|
-
let
|
|
2904
|
-
...
|
|
2905
|
-
EventId:
|
|
2906
|
-
Timestamp:
|
|
1981
|
+
let a = e;
|
|
1982
|
+
for (let [e, n] of i) {
|
|
1983
|
+
let r = t({
|
|
1984
|
+
...n,
|
|
1985
|
+
EventId: n.EventId || `legacy-terminal:${e}:${n.SeqId || 0}`,
|
|
1986
|
+
Timestamp: st(n.Timestamp)
|
|
2907
1987
|
});
|
|
2908
|
-
if (!
|
|
2909
|
-
let
|
|
2910
|
-
|
|
2911
|
-
if (!
|
|
2912
|
-
let t = (e) => e === "running" || e === "paused",
|
|
1988
|
+
if (!r) continue;
|
|
1989
|
+
let i = (t) => (t.invocationId || t.runId) === e;
|
|
1990
|
+
a = a.filter((e) => !(i(e) && e.role === "system" && e.eventType === "run_status")).map((e) => {
|
|
1991
|
+
if (!i(e) || e.role !== "model") return e;
|
|
1992
|
+
let t = (e) => e === "running" || e === "paused", n = "运行已结束,未记录此工具的最终结果。";
|
|
2913
1993
|
return {
|
|
2914
1994
|
...e,
|
|
2915
|
-
tools: e.tools && Object.fromEntries(Object.entries(e.tools).map(([e,
|
|
2916
|
-
...
|
|
1995
|
+
tools: e.tools && Object.fromEntries(Object.entries(e.tools).map(([e, r]) => [e, t(r.status) ? {
|
|
1996
|
+
...r,
|
|
2917
1997
|
status: "unknown",
|
|
2918
|
-
summary:
|
|
2919
|
-
} :
|
|
1998
|
+
summary: r.summary || n
|
|
1999
|
+
} : r])),
|
|
2920
2000
|
blocks: e.blocks?.map((e) => e.type === "thinking" && e.status === "streaming" ? {
|
|
2921
2001
|
...e,
|
|
2922
2002
|
status: "done"
|
|
2923
2003
|
} : e.type !== "tool" || !t(e.status) ? e : {
|
|
2924
2004
|
...e,
|
|
2925
2005
|
status: "unknown",
|
|
2926
|
-
summary: e.summary ||
|
|
2006
|
+
summary: e.summary || n,
|
|
2927
2007
|
extra: {
|
|
2928
2008
|
...e.extra,
|
|
2929
2009
|
persistedToolStatus: e.status,
|
|
2930
|
-
terminalRunStatus:
|
|
2010
|
+
terminalRunStatus: r.status
|
|
2931
2011
|
}
|
|
2932
2012
|
})
|
|
2933
2013
|
};
|
|
2934
|
-
}),
|
|
2935
|
-
...
|
|
2014
|
+
}), a.push({
|
|
2015
|
+
...r,
|
|
2936
2016
|
invocationId: e,
|
|
2937
|
-
eventId:
|
|
2017
|
+
eventId: n.EventId
|
|
2938
2018
|
});
|
|
2939
2019
|
}
|
|
2940
|
-
return
|
|
2020
|
+
return a === e ? e : R(a);
|
|
2941
2021
|
}
|
|
2942
|
-
function
|
|
2022
|
+
function $(e) {
|
|
2943
2023
|
return e.role === "model" ? {
|
|
2944
2024
|
...e,
|
|
2945
|
-
blocks: e.blocks?.length ? e.blocks :
|
|
2025
|
+
blocks: e.blocks?.length ? e.blocks : Ke({
|
|
2946
2026
|
content: e.content,
|
|
2947
2027
|
reasoning: e.reasoning,
|
|
2948
2028
|
reasoningSource: e.reasoningSource,
|
|
@@ -2950,12 +2030,12 @@ function tn(e) {
|
|
|
2950
2030
|
})
|
|
2951
2031
|
} : e;
|
|
2952
2032
|
}
|
|
2953
|
-
function
|
|
2033
|
+
function ut(e, t) {
|
|
2954
2034
|
let n = t.find((e) => e.role === "user"), r = e.some((e) => e.role === "user"), i = t.filter((e) => e.role === "model"), a = e.filter((e) => e.role === "model").at(-1), o = i.at(-1), s = e.map((e) => e.role === "user" && n ? {
|
|
2955
2035
|
...e,
|
|
2956
2036
|
...n,
|
|
2957
2037
|
invocationId: e.invocationId || n.invocationId
|
|
2958
|
-
} :
|
|
2038
|
+
} : $(e === a && o ? {
|
|
2959
2039
|
...e,
|
|
2960
2040
|
responseId: o.responseId || e.responseId,
|
|
2961
2041
|
traceId: o.traceId || e.traceId,
|
|
@@ -2963,7 +2043,7 @@ function nn(e, t) {
|
|
|
2963
2043
|
} : e));
|
|
2964
2044
|
return n && !r ? [n, ...s] : s;
|
|
2965
2045
|
}
|
|
2966
|
-
function
|
|
2046
|
+
function dt(e, t) {
|
|
2967
2047
|
let n = t.filter((e) => e.role === "model"), r = n.flatMap((e) => Object.values(e.tools || {}).map((t) => ({
|
|
2968
2048
|
tool: t,
|
|
2969
2049
|
scope: e.scopeId
|
|
@@ -2978,7 +2058,7 @@ function rn(e, t) {
|
|
|
2978
2058
|
return [t, r ? {
|
|
2979
2059
|
...n,
|
|
2980
2060
|
...r,
|
|
2981
|
-
...
|
|
2061
|
+
...F(n, r),
|
|
2982
2062
|
name: n.name
|
|
2983
2063
|
} : n];
|
|
2984
2064
|
})), n = e === s ? a : [];
|
|
@@ -2991,10 +2071,10 @@ function rn(e, t) {
|
|
|
2991
2071
|
let n = t.extra?.callId, r = typeof n == "string" ? i(n, e.scopeId) : void 0;
|
|
2992
2072
|
return r ? {
|
|
2993
2073
|
...t,
|
|
2994
|
-
...
|
|
2074
|
+
...F(t, r)
|
|
2995
2075
|
} : t;
|
|
2996
|
-
}), c =
|
|
2997
|
-
return
|
|
2076
|
+
}), c = Ke({ tools: Object.fromEntries(n.map(({ tool: e, scope: t }) => [JSON.stringify([t || "", e.callId || e.name]), e])) }), l = r?.findIndex((e) => e.type === "text") ?? -1;
|
|
2077
|
+
return $({
|
|
2998
2078
|
...e,
|
|
2999
2079
|
...e === s ? { reasoning: e.reasoning || o || void 0 } : {},
|
|
3000
2080
|
tools: Object.keys(t).length ? t : e.tools,
|
|
@@ -3006,21 +2086,21 @@ function rn(e, t) {
|
|
|
3006
2086
|
});
|
|
3007
2087
|
});
|
|
3008
2088
|
}
|
|
3009
|
-
function
|
|
2089
|
+
function ft(e) {
|
|
3010
2090
|
return new Set(e.filter((e) => e.role === "model" && e.eventType === "assistant_message" && !!String(e.content || "").trim() && !!e.invocationId).map((e) => String(e.invocationId)));
|
|
3011
2091
|
}
|
|
3012
|
-
var
|
|
2092
|
+
var pt = new Set([
|
|
3013
2093
|
"approval.resolved",
|
|
3014
2094
|
"interaction.resolved",
|
|
3015
2095
|
"interaction.cancelled",
|
|
3016
2096
|
"interaction.canceled",
|
|
3017
2097
|
"a2ui.action"
|
|
3018
2098
|
]);
|
|
3019
|
-
function
|
|
2099
|
+
function mt(e) {
|
|
3020
2100
|
let t = /* @__PURE__ */ new Set();
|
|
3021
2101
|
for (let n of e) {
|
|
3022
|
-
let e =
|
|
3023
|
-
if (!
|
|
2102
|
+
let e = Q(n.Content) || {}, r = Q(e.runtime_event || e.runtimeEvent) || {}, i = Q(e.payload) || Q(r.payload) || {}, a = String(n.EventType || e.event_type || e.eventType || r.event_type || "").toLowerCase();
|
|
2103
|
+
if (!pt.has(a)) continue;
|
|
3024
2104
|
let o = String(e.outcome || e.action || e.name || e.status || i.outcome || i.action || i.name || i.status || "").toLowerCase();
|
|
3025
2105
|
if (![
|
|
3026
2106
|
"cancel",
|
|
@@ -3032,65 +2112,64 @@ function sn(e) {
|
|
|
3032
2112
|
}
|
|
3033
2113
|
return t;
|
|
3034
2114
|
}
|
|
3035
|
-
function
|
|
3036
|
-
e =
|
|
3037
|
-
let
|
|
3038
|
-
let t = e.Content, r =
|
|
2115
|
+
function ht(e, t, n, i = "flat-v1") {
|
|
2116
|
+
e = I(e);
|
|
2117
|
+
let a = new nt(n), o = [], s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), u = [...t || []].filter((e) => {
|
|
2118
|
+
let t = e.Content, r = Q(t?.session_event || t?.sessionEvent), i = Q(t?.runtime_event || t?.runtimeEvent);
|
|
3039
2119
|
return [
|
|
3040
2120
|
e.SessionId,
|
|
3041
2121
|
r?.session_id,
|
|
3042
2122
|
i?.session_id
|
|
3043
2123
|
].every((e) => !e || e === n);
|
|
3044
|
-
}).sort((e, t) => Number(e.SeqId || 0) - Number(t.SeqId || 0)),
|
|
3045
|
-
for (let e of
|
|
3046
|
-
let
|
|
3047
|
-
if (!
|
|
3048
|
-
let
|
|
3049
|
-
if (
|
|
3050
|
-
|
|
2124
|
+
}).sort((e, t) => Number(e.SeqId || 0) - Number(t.SeqId || 0)), d = Number(u[0]?.SeqId || 0) <= 1, f = ot(u);
|
|
2125
|
+
for (let [e, t] of u.entries()) {
|
|
2126
|
+
let n = f[e];
|
|
2127
|
+
if (!n) continue;
|
|
2128
|
+
let r = String(n.run_id || "").trim();
|
|
2129
|
+
if (r) {
|
|
2130
|
+
s.add(r), !n.parent_scope_id && [
|
|
3051
2131
|
"run.completed",
|
|
3052
2132
|
"run.failed",
|
|
3053
2133
|
"run.cancelled",
|
|
3054
2134
|
"run.canceled"
|
|
3055
|
-
].includes(String(
|
|
3056
|
-
let e =
|
|
3057
|
-
(
|
|
2135
|
+
].includes(String(n.event_type)) && c.add(r);
|
|
2136
|
+
let e = Q(Q(n.source)?.metadata), t = String(n.event_type || "") === "run.started", i = e?.native_item_kind === "userMessage";
|
|
2137
|
+
(d || t || i) && l.add(r);
|
|
3058
2138
|
}
|
|
3059
|
-
let
|
|
3060
|
-
|
|
3061
|
-
...
|
|
3062
|
-
SeqId: Number(
|
|
3063
|
-
Timestamp:
|
|
2139
|
+
let i = a.translate(n);
|
|
2140
|
+
i && o.push({
|
|
2141
|
+
...i,
|
|
2142
|
+
SeqId: Number(t.SeqId || i.SeqId || 0),
|
|
2143
|
+
Timestamp: st(t.Timestamp || i.Timestamp)
|
|
3064
2144
|
});
|
|
3065
2145
|
}
|
|
3066
|
-
let
|
|
2146
|
+
let p = r(o).filter((e) => e.invocationId && s.has(e.invocationId)), m = /* @__PURE__ */ new Map();
|
|
3067
2147
|
for (let t of e) {
|
|
3068
2148
|
let e = String(t.invocationId || "");
|
|
3069
|
-
e &&
|
|
2149
|
+
e && m.set(e, [...m.get(e) || [], t]);
|
|
3070
2150
|
}
|
|
3071
|
-
let
|
|
3072
|
-
for (let e of
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
let i = t.some((e) => e.event_type === "run.started" && !e.parent_scope_id), a = /* @__PURE__ */ new Set(), o = t.every((e) => {
|
|
2151
|
+
let h = new Set([...ft(p)].filter((e) => l.has(e))), g = /* @__PURE__ */ new Map();
|
|
2152
|
+
for (let e of f) {
|
|
2153
|
+
if (e?.schema_version !== 2 || !e.run_id) continue;
|
|
2154
|
+
let t = String(e.run_id), n = g.get(t) || [];
|
|
2155
|
+
n.push(e), g.set(t, n);
|
|
2156
|
+
}
|
|
2157
|
+
let _ = (e) => [
|
|
2158
|
+
Q(e.initial),
|
|
2159
|
+
Q(e.snapshot),
|
|
2160
|
+
Q(e.update)
|
|
2161
|
+
].some((e) => Q(e?.data)?.schema === "execution.scope/v1" || Array.isArray(e?.parts) && e.parts.some((e) => Q(Q(e)?.data)?.schema === "execution.scope/v1")), v = new Set([...g].filter(([, e]) => e.some(_)).map(([e]) => e)), y = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Set();
|
|
2162
|
+
for (let [e, t] of g) {
|
|
2163
|
+
if (!v.has(e) && !h.has(e) && !t.some((e) => ["item.failed", "run.failed"].includes(String(e.event_type)))) continue;
|
|
2164
|
+
let r = t.some((e) => e.event_type === "run.started" && !e.parent_scope_id), a = /* @__PURE__ */ new Set(), o = t.every((e) => {
|
|
3086
2165
|
let t = JSON.stringify([e.scope_id, e.item_id]);
|
|
3087
|
-
return e.event_type === "item.started" && a.add(t), !
|
|
2166
|
+
return e.event_type === "item.started" && a.add(t), !_(e) || a.has(t);
|
|
3088
2167
|
});
|
|
3089
|
-
if (!(!
|
|
3090
|
-
let
|
|
3091
|
-
t.forEach((e) =>
|
|
3092
|
-
let a =
|
|
3093
|
-
|
|
2168
|
+
if (!(!r || !o)) try {
|
|
2169
|
+
let r = new C(n, void 0, i);
|
|
2170
|
+
t.forEach((e) => r.apply(e));
|
|
2171
|
+
let a = r.snapshot(), o = de(a, { profile: i }), s = st(t[0].timestamp);
|
|
2172
|
+
y.set(e, W({
|
|
3094
2173
|
state: a,
|
|
3095
2174
|
presentation: o,
|
|
3096
2175
|
runId: e,
|
|
@@ -3108,36 +2187,36 @@ function cn(e, t, n, r = "flat-v1") {
|
|
|
3108
2187
|
};
|
|
3109
2188
|
}));
|
|
3110
2189
|
} catch (t) {
|
|
3111
|
-
|
|
2190
|
+
b.add(e), console.warn(`[SessionHistory] strict replay skipped for run ${e}:`, t instanceof Error ? t.message : "invalid runtime history");
|
|
3112
2191
|
}
|
|
3113
2192
|
}
|
|
3114
|
-
for (let e of new Set([...
|
|
3115
|
-
let
|
|
3116
|
-
for (let [e, t] of
|
|
3117
|
-
if (
|
|
3118
|
-
let n =
|
|
3119
|
-
|
|
3120
|
-
}
|
|
3121
|
-
for (let e of
|
|
3122
|
-
let
|
|
3123
|
-
...e.filter((e) => !(e.role === "model" && e.invocationId &&
|
|
3124
|
-
...
|
|
3125
|
-
...
|
|
2193
|
+
for (let e of new Set([...v, ...b])) y.has(e) || h.delete(e);
|
|
2194
|
+
let x = mt(u), S = [...h].flatMap((e) => ut(p.filter((t) => t.invocationId === e), m.get(e) || [])), w = /* @__PURE__ */ new Map(), T = [];
|
|
2195
|
+
for (let [e, t] of m) {
|
|
2196
|
+
if (h.has(e) || !s.has(e)) continue;
|
|
2197
|
+
let n = p.filter((t) => t.invocationId === e), r = t.some((e) => e.role === "model" && String(e.content || "").trim());
|
|
2198
|
+
w.set(e, r ? dt(t, n) : t), r || T.push(...n.map($));
|
|
2199
|
+
}
|
|
2200
|
+
for (let e of s) h.has(e) || m.has(e) || T.push(...p.filter((t) => t.invocationId === e).map($));
|
|
2201
|
+
let ee = new Map([...w.values()].flat().map((e) => [e.id, e])), E = R([
|
|
2202
|
+
...e.filter((e) => !(e.role === "model" && e.invocationId && x.has(e.invocationId)) && (e.role === "a2ui" || !e.invocationId || !h.has(e.invocationId))).map((e) => ee.get(e.id) || e),
|
|
2203
|
+
...S,
|
|
2204
|
+
...T
|
|
3126
2205
|
]);
|
|
3127
|
-
for (let [e, t] of
|
|
2206
|
+
for (let [e, t] of y) {
|
|
3128
2207
|
if (!t.length) continue;
|
|
3129
|
-
let n = (t) => t.invocationId === e || t.runId === e, r =
|
|
3130
|
-
|
|
2208
|
+
let n = (t) => t.invocationId === e || t.runId === e, r = E.findIndex(n), i = E.filter(n), a = i.find((e) => e.role === "user"), o = v.has(e) ? a && !t.some((e) => e.role === "user") ? [a, ...t] : t : ut(t, i), s = E.filter((e) => !n(e)), c = r < 0 ? s.length : r;
|
|
2209
|
+
E = [
|
|
3131
2210
|
...s.slice(0, c),
|
|
3132
2211
|
...o,
|
|
3133
2212
|
...s.slice(c)
|
|
3134
|
-
],
|
|
2213
|
+
], h.add(e);
|
|
3135
2214
|
}
|
|
3136
2215
|
return {
|
|
3137
|
-
messages:
|
|
3138
|
-
canonicalRunIds: [...
|
|
3139
|
-
translatedEvents:
|
|
2216
|
+
messages: I(R(lt(E, u, c))),
|
|
2217
|
+
canonicalRunIds: [...h],
|
|
2218
|
+
translatedEvents: o
|
|
3140
2219
|
};
|
|
3141
2220
|
}
|
|
3142
2221
|
//#endregion
|
|
3143
|
-
export {
|
|
2222
|
+
export { T as C, E as S, S as T, we as _, Be as a, de as b, He as c, Ue as d, We as f, I as g, Ee as h, rt as i, Ge as l, W as m, ht as n, ze as o, Le as p, nt as r, Ke as s, ct as t, Ve as u, Ce as v, C as w, D as x, xe as y };
|