@kingsoftcloud/ksadk-web 0.3.11 → 0.3.13
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 +23 -0
- package/README.md +7 -4
- package/RELEASE_PROVENANCE.json +2 -2
- package/dist-ksadk/assets/{ArtifactsPanel-C1YoaKhx.js → ArtifactsPanel-CILaW-fC.js} +1 -1
- package/dist-ksadk/assets/{CodeBlock-DHuAWfr5.js → CodeBlock-BVrNVtJC.js} +1 -1
- package/dist-ksadk/assets/{MathMessageMarkdown-cvdrBwYr.js → MathMessageMarkdown-Dp7c4wWD.js} +1 -1
- package/dist-ksadk/assets/{MermaidBlock-DeBkbJvI.js → MermaidBlock-Dxop8Rd7.js} +6 -6
- package/dist-ksadk/assets/{NativeTerminalPanel-oJj44_sV.js → NativeTerminalPanel-Cjjz8B30.js} +1 -1
- package/dist-ksadk/assets/{abnfDiagram-VCTEODGH-Dhfv25o2.js → abnfDiagram-VCTEODGH-ckWDmOzw.js} +1 -1
- package/dist-ksadk/assets/{arc-C35w-pn1.js → arc-DqxJede-.js} +1 -1
- package/dist-ksadk/assets/architecture-7GRP2DOG-pn_DuLy6.js +1 -0
- package/dist-ksadk/assets/{architectureDiagram-5GKGNRK7-FoMY_u6D.js → architectureDiagram-5GKGNRK7-SEQA4bVi.js} +1 -1
- package/dist-ksadk/assets/{blockDiagram-NRAW4CY4-zD4Rt7oE.js → blockDiagram-NRAW4CY4-pM0B-6NJ.js} +1 -1
- package/dist-ksadk/assets/{c4Diagram-UCG6FXSJ-BCtGGkhN.js → c4Diagram-UCG6FXSJ-m2tuCNVq.js} +1 -1
- package/dist-ksadk/assets/channel-fySsnkft.js +1 -0
- package/dist-ksadk/assets/chunk-2Q5K7J3B-BheGxKRQ.js +1 -0
- package/dist-ksadk/assets/{chunk-5VM5RSS4-C2Ms13_k.js → chunk-5VM5RSS4-GJHDr9Ww.js} +1 -1
- package/dist-ksadk/assets/{chunk-F27PBJKO-BoTj-qgx.js → chunk-F27PBJKO-CbAN45AV.js} +1 -1
- package/dist-ksadk/assets/{chunk-G27WJ6UU-DOMyyjHH.js → chunk-G27WJ6UU-D5ngbbzF.js} +1 -1
- package/dist-ksadk/assets/{chunk-JWPE2WC7-DbJJqDli.js → chunk-JWPE2WC7-Cc5IwuYC.js} +1 -1
- package/dist-ksadk/assets/{chunk-LCL6LL3I-CLuRCt_W.js → chunk-LCL6LL3I-CprgDDdJ.js} +1 -1
- package/dist-ksadk/assets/{chunk-POPQ4Y6H-D0Dz847e.js → chunk-POPQ4Y6H-CDZhSy82.js} +1 -1
- package/dist-ksadk/assets/{chunk-RHFEMEQ7-BWSRzEcd.js → chunk-RHFEMEQ7-CZchUNro.js} +1 -1
- package/dist-ksadk/assets/{chunk-SVP7TREG-CPoHqkCY.js → chunk-SVP7TREG-BVruqk6T.js} +1 -1
- package/dist-ksadk/assets/{chunk-XXDRQBXY-Bx1jS-X-.js → chunk-XXDRQBXY-4ld9SxPN.js} +1 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-DSfLtNYm.js +1 -0
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-DSfLtNYm.js +1 -0
- package/dist-ksadk/assets/{cose-bilkent-JH36ORCC-LzyWm4m0.js → cose-bilkent-JH36ORCC-Dmyyk_Vp.js} +1 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-PFWIGtvA.js +1 -0
- package/dist-ksadk/assets/{cynefinDiagram-5FMLGOSQ-BlW_bHED.js → cynefinDiagram-5FMLGOSQ-BIyq3EJb.js} +1 -1
- package/dist-ksadk/assets/{dagre-3AP2YEHR-Bu_S86_i.js → dagre-3AP2YEHR-eBw08Qdk.js} +1 -1
- package/dist-ksadk/assets/{dagre-B7nCawed.js → dagre-DfvnEf45.js} +1 -1
- package/dist-ksadk/assets/{diagram-S7CK7UJ4-W_Zow2Km.js → diagram-S7CK7UJ4-CUSrE3Mg.js} +1 -1
- package/dist-ksadk/assets/{diagram-UQ7AKVKN-CLIKAHON.js → diagram-UQ7AKVKN-Dq5Zw2gy.js} +1 -1
- package/dist-ksadk/assets/{diagram-VSXAHHWV-Dv6_QAlN.js → diagram-VSXAHHWV-DyUHfNwT.js} +1 -1
- package/dist-ksadk/assets/{diagram-VX7I27RA-BWAWRDtZ.js → diagram-VX7I27RA-CREmM89O.js} +1 -1
- package/dist-ksadk/assets/{diagram-Z3DM3KII-XA_rWMss.js → diagram-Z3DM3KII-Dw9zhHUK.js} +1 -1
- package/dist-ksadk/assets/{dist-CGt_UGeO.js → dist-0uJ4tdx6.js} +1 -1
- package/dist-ksadk/assets/{dist-C0J5_3qM.js → dist-AEv-vXf-.js} +1 -1
- package/dist-ksadk/assets/{dist-CIpWk_5f.js → dist-B49GzZDb.js} +1 -1
- package/dist-ksadk/assets/{dist-B3bA05-e.js → dist-B8Myiet9.js} +1 -1
- package/dist-ksadk/assets/{dist-DWfdmz9s.js → dist-BBsYarrI.js} +1 -1
- package/dist-ksadk/assets/{dist-BLpRy_Yx.js → dist-BQMrUwdI.js} +1 -1
- package/dist-ksadk/assets/{dist-CIRMvUM4.js → dist-BX_-FENW.js} +1 -1
- package/dist-ksadk/assets/{dist-BdNFAney.js → dist-CD4L6ymH.js} +1 -1
- package/dist-ksadk/assets/{dist-n3n6t_FO.js → dist-CHpW1BHj.js} +1 -1
- package/dist-ksadk/assets/{dist-DppE_r-D.js → dist-CVPau3tn.js} +1 -1
- package/dist-ksadk/assets/{dist-qe8xjesy.js → dist-C_qdxcSH.js} +1 -1
- package/dist-ksadk/assets/{dist-2vL2sAdF.js → dist-Co68Apq4.js} +1 -1
- package/dist-ksadk/assets/{dist-1nXCdsej.js → dist-Cp2PaOMY.js} +1 -1
- package/dist-ksadk/assets/{dist-DNKuMzWc.js → dist-CuR5Bgme.js} +1 -1
- package/dist-ksadk/assets/{dist-t6MzE0jU.js → dist-DDSyLEOX.js} +1 -1
- package/dist-ksadk/assets/{dist-CPyieXEf.js → dist-DUxO0R99.js} +1 -1
- package/dist-ksadk/assets/{dist-DyG6Ya-z.js → dist-QzbGrED_.js} +1 -1
- package/dist-ksadk/assets/{dist-0X_j2Rcc.js → dist-bupkyEBZ.js} +1 -1
- package/dist-ksadk/assets/{dist-mqD5TZup.js → dist-cxTGfdqx.js} +1 -1
- package/dist-ksadk/assets/{dist-M-SrdhhZ.js → dist-hL5p1til.js} +1 -1
- package/dist-ksadk/assets/{dist-D-92S-Fd.js → dist-lOy23y43.js} +1 -1
- package/dist-ksadk/assets/{dist-BO_UwatH.js → dist-pq-nD33R.js} +1 -1
- package/dist-ksadk/assets/{ebnfDiagram-PWID7BFC-BfCzF1Xi.js → ebnfDiagram-PWID7BFC-BS5LdNoR.js} +1 -1
- package/dist-ksadk/assets/{erDiagram-SSCWMZ5O-Dpz9_0zn.js → erDiagram-SSCWMZ5O-Bv1QtiY-.js} +1 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV-DsM4upQX.js +1 -0
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-D5NA16k9.js +1 -0
- package/dist-ksadk/assets/{ganttDiagram-EL5Y4UJY-DDaG1f4_.js → ganttDiagram-EL5Y4UJY-musi-e0G.js} +1 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-DUCVz-ih.js +1 -0
- package/dist-ksadk/assets/{gitGraphDiagram-WWUBYQGX-DcxzRwYC.js → gitGraphDiagram-WWUBYQGX-DH37EGkG.js} +1 -1
- package/dist-ksadk/assets/index-CZdkAvsv.js +244 -0
- package/dist-ksadk/assets/index-CvXdHgF3.css +2 -0
- package/dist-ksadk/assets/info-A6RAGUB7-rw0ZNHZp.js +1 -0
- package/dist-ksadk/assets/{infoDiagram-RXCK75RN-CYMdn6lQ.js → infoDiagram-RXCK75RN-C1kEtv2y.js} +1 -1
- package/dist-ksadk/assets/{ishikawaDiagram-5VMMS53U-CLHFAD6c.js → ishikawaDiagram-5VMMS53U-BCNPyMka.js} +1 -1
- package/dist-ksadk/assets/{journeyDiagram-EYS64GPL-BHSKQGAl.js → journeyDiagram-EYS64GPL--cDbKnjP.js} +1 -1
- package/dist-ksadk/assets/{kanban-definition-3QL26DDD-D5W3tjTT.js → kanban-definition-3QL26DDD-R1rAVw2f.js} +1 -1
- package/dist-ksadk/assets/{katex-mtjOi4KM.js → katex-BT-X-V7U.js} +1 -1
- package/dist-ksadk/assets/{linear-BETqsxE_.js → linear-DTR631iG.js} +1 -1
- package/dist-ksadk/assets/{mermaid-parser.core-DPWrvs90.js → mermaid-parser.core-DfFzJhX8.js} +2 -2
- package/dist-ksadk/assets/{mindmap-definition-FBJOCRG2-CJG2mfBP.js → mindmap-definition-FBJOCRG2-D4by_rmk.js} +1 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-Ca4Hvki9.js +1 -0
- package/dist-ksadk/assets/{pegDiagram-XKGWAZYB-GjAPNaqn.js → pegDiagram-XKGWAZYB-xWXPEh0c.js} +1 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-hwiz6fbw.js +1 -0
- package/dist-ksadk/assets/{pieDiagram-E7YTZNPT-ToIewrqr.js → pieDiagram-E7YTZNPT-BudBDlCI.js} +1 -1
- package/dist-ksadk/assets/{quadrantDiagram-AXDQQJYC-4d78KiEY.js → quadrantDiagram-AXDQQJYC-DXZ0PCJF.js} +1 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-BR1oZXLM.js +1 -0
- package/dist-ksadk/assets/railroad-74A4TZTK-DfgEISfX.js +1 -0
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-CWOC3rdk.js +1 -0
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-CiRvHCLY.js +1 -0
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-DSDDyJ2f.js +1 -0
- package/dist-ksadk/assets/{railroadDiagram-O6MQD6OU-DKzx4xfv.js → railroadDiagram-O6MQD6OU-BdAYRYB8.js} +1 -1
- package/dist-ksadk/assets/{requirementDiagram-EFPCY7ZU-CJYljxQS.js → requirementDiagram-EFPCY7ZU-CBBmaL70.js} +1 -1
- package/dist-ksadk/assets/{sankeyDiagram-P5KCCOFB-DLU2fV1w.js → sankeyDiagram-P5KCCOFB-Doc3rdwp.js} +1 -1
- package/dist-ksadk/assets/{sequenceDiagram-WJ2MYXX4-CVqysrA9.js → sequenceDiagram-WJ2MYXX4-0J8R8hWW.js} +1 -1
- package/dist-ksadk/assets/{sizeCapture-X5ZJPWSS-BUxfmTHc.js → sizeCapture-X5ZJPWSS-CfFLlWsK.js} +1 -1
- package/dist-ksadk/assets/{stateDiagram-HBIQ2CUA-CNFgYI9E.js → stateDiagram-HBIQ2CUA-jBwkjtTy.js} +1 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-Cw1fPb5w.js +1 -0
- package/dist-ksadk/assets/{swimlanes-XN3QIQJK-B6qCMe8N.js → swimlanes-XN3QIQJK-B0WxTQf8.js} +1 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-Cc3JMBAF.js +8 -0
- package/dist-ksadk/assets/{timeline-definition-24CTP7MA-CMD3x_U_.js → timeline-definition-24CTP7MA-BfCT_75A.js} +1 -1
- package/dist-ksadk/assets/treeView-Q6P3EWNA-C05SJHxo.js +1 -0
- package/dist-ksadk/assets/treemap-WGGIJYW6-BqNLAhc3.js +1 -0
- package/dist-ksadk/assets/{vennDiagram-4TSXK5OY-BqtUqvXM.js → vennDiagram-4TSXK5OY-9gX1VMDC.js} +1 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-DokNktqB.js +1 -0
- package/dist-ksadk/assets/{wardleyDiagram-VM6X3IG4-B5KfDjI-.js → wardleyDiagram-VM6X3IG4-sEs_BP6O.js} +1 -1
- package/dist-ksadk/assets/{xychartDiagram-S5SC5T6Z-BaUlSZrn.js → xychartDiagram-S5SC5T6Z-Ll4jvUN9.js} +1 -1
- package/dist-ksadk/index.html +2 -2
- package/dist-lib/App.d.ts.map +1 -1
- package/dist-lib/{AttachmentPreview-tjd7Ufsh.js → AttachmentPreview-lufx89xJ.js} +174 -174
- package/dist-lib/{ConnectedComposer-BaRxxvhk.js → ConnectedComposer-Dd8ZFhfL.js} +214 -213
- package/dist-lib/{ConnectedMessageList-XLBootgU.js → ConnectedMessageList-CzTOJbZU.js} +582 -510
- package/dist-lib/{InteractionSchemaForm-BNoW5wzt.js → InteractionSchemaForm-ChYkHPop.js} +88 -71
- package/dist-lib/{WorkspacePanelContainer-B2mk7udj.js → WorkspacePanelContainer-BDbgHg1_.js} +2 -2
- package/dist-lib/{a2ui-BEQoW34n.js → a2ui-DfAshhMK.js} +8 -3
- package/dist-lib/api/messages.d.ts +88 -0
- package/dist-lib/api/messages.d.ts.map +1 -0
- package/dist-lib/chat-composer.js +2 -2
- package/dist-lib/chat-timeline.js +3 -3
- package/dist-lib/cloudMaterials-D75jTrkQ.js +2686 -0
- package/dist-lib/components/chat/AgentBlockView.d.ts +9 -0
- package/dist-lib/components/chat/AgentBlockView.d.ts.map +1 -0
- package/dist-lib/components/chat/ChatComposer.d.ts.map +1 -1
- package/dist-lib/components/chat/ChatMessageList.d.ts +4 -2
- package/dist-lib/components/chat/ChatMessageList.d.ts.map +1 -1
- package/dist-lib/components/chat/ConnectedComposer.d.ts +1 -1
- package/dist-lib/components/chat/ConnectedComposer.d.ts.map +1 -1
- package/dist-lib/components/chat/ConnectedMessageList.d.ts +4 -1
- package/dist-lib/components/chat/ConnectedMessageList.d.ts.map +1 -1
- package/dist-lib/components/chat/InteractionSchemaForm.d.ts.map +1 -1
- package/dist-lib/components/chat/InteractionTray.d.ts.map +1 -1
- package/dist-lib/components/chat/ProcessingBlocksView.d.ts +2 -2
- package/dist-lib/components/chat/ProcessingBlocksView.d.ts.map +1 -1
- package/dist-lib/components/chat/StatusBanner.d.ts.map +1 -1
- package/dist-lib/components/chat/approval-status.d.ts +5 -0
- package/dist-lib/components/chat/approval-status.d.ts.map +1 -0
- package/dist-lib/components/chat/types.d.ts +13 -1
- package/dist-lib/components/chat/types.d.ts.map +1 -1
- package/dist-lib/components/teams/CloudEffectsPanel.d.ts +15 -0
- package/dist-lib/components/teams/CloudEffectsPanel.d.ts.map +1 -0
- package/dist-lib/components/teams/CloudTeamWorkspace.d.ts +38 -0
- package/dist-lib/components/teams/CloudTeamWorkspace.d.ts.map +1 -0
- package/dist-lib/components/teams/CreateGroupDialog.d.ts +3 -1
- package/dist-lib/components/teams/CreateGroupDialog.d.ts.map +1 -1
- package/dist-lib/components/teams/TeamWorkspace.d.ts.map +1 -1
- package/dist-lib/components.js +6 -6
- package/dist-lib/conversation.js +8 -34
- package/dist-lib/core/api/facade.d.ts +18 -10
- package/dist-lib/core/api/facade.d.ts.map +1 -1
- package/dist-lib/core/api/types.d.ts +28 -3
- package/dist-lib/core/api/types.d.ts.map +1 -1
- package/dist-lib/core/conversation/agent.d.ts +49 -0
- package/dist-lib/core/conversation/agent.d.ts.map +1 -0
- package/dist-lib/core/conversation/client.d.ts +2 -0
- package/dist-lib/core/conversation/client.d.ts.map +1 -1
- package/dist-lib/core/conversation/contracts.d.ts.map +1 -1
- package/dist-lib/core/conversation/hosted.d.ts.map +1 -1
- package/dist-lib/core/conversation/index.d.ts +4 -1
- package/dist-lib/core/conversation/index.d.ts.map +1 -1
- package/dist-lib/core/conversation/presentation.d.ts.map +1 -1
- package/dist-lib/core/conversation/reducer.d.ts.map +1 -1
- package/dist-lib/core/conversation/renderer-registry.d.ts +1 -0
- package/dist-lib/core/conversation/renderer-registry.d.ts.map +1 -1
- package/dist-lib/core/conversation/runtime-ingress.d.ts +22 -0
- package/dist-lib/core/conversation/runtime-ingress.d.ts.map +1 -0
- package/dist-lib/core/conversation/safe-tool-value.d.ts +8 -0
- package/dist-lib/core/conversation/safe-tool-value.d.ts.map +1 -0
- package/dist-lib/core/conversation/scoped-cancel.d.ts +16 -0
- package/dist-lib/core/conversation/scoped-cancel.d.ts.map +1 -0
- package/dist-lib/core/conversation/types.d.ts +6 -1
- package/dist-lib/core/conversation/types.d.ts.map +1 -1
- package/dist-lib/core/interaction/adapters/legacy-runtime-events.d.ts +8 -0
- package/dist-lib/core/interaction/adapters/legacy-runtime-events.d.ts.map +1 -0
- package/dist-lib/core/interaction/adapters/responses.d.ts +1 -0
- package/dist-lib/core/interaction/adapters/responses.d.ts.map +1 -1
- package/dist-lib/core/interaction/adapters/session-events.d.ts.map +1 -1
- package/dist-lib/core/interaction/client.d.ts +3 -2
- package/dist-lib/core/interaction/client.d.ts.map +1 -1
- package/dist-lib/core/interaction/index.d.ts +4 -0
- package/dist-lib/core/interaction/index.d.ts.map +1 -1
- package/dist-lib/core/interaction/legacy-history.d.ts +5 -0
- package/dist-lib/core/interaction/legacy-history.d.ts.map +1 -0
- package/dist-lib/core/interaction/store.d.ts +4 -0
- package/dist-lib/core/interaction/store.d.ts.map +1 -1
- package/dist-lib/core/interaction/types.d.ts +2 -0
- package/dist-lib/core/interaction/types.d.ts.map +1 -1
- package/dist-lib/core/run/blocks.d.ts +2 -1
- package/dist-lib/core/run/blocks.d.ts.map +1 -1
- package/dist-lib/core/run/dispatcher.d.ts.map +1 -1
- package/dist-lib/core/run/engine.d.ts +2 -0
- package/dist-lib/core/run/engine.d.ts.map +1 -1
- package/dist-lib/core/run/types.d.ts +7 -1
- package/dist-lib/core/run/types.d.ts.map +1 -1
- package/dist-lib/core/stream/kernel-events.d.ts +2 -0
- package/dist-lib/core/stream/kernel-events.d.ts.map +1 -1
- package/dist-lib/core/stream/responses-protocol.d.ts.map +1 -1
- package/dist-lib/core/stream/runtime-items.d.ts +2 -2
- package/dist-lib/core/stream/runtime-items.d.ts.map +1 -1
- package/dist-lib/core/stream/types.d.ts +4 -0
- package/dist-lib/core/stream/types.d.ts.map +1 -1
- package/dist-lib/core/teams/cloudCanonical.d.ts +11 -0
- package/dist-lib/core/teams/cloudCanonical.d.ts.map +1 -0
- package/dist-lib/core/teams/cloudClient.d.ts +30 -0
- package/dist-lib/core/teams/cloudClient.d.ts.map +1 -0
- package/dist-lib/core/teams/cloudContracts.d.ts +1499 -0
- package/dist-lib/core/teams/cloudContracts.d.ts.map +1 -0
- package/dist-lib/core/teams/cloudEffects.d.ts +167 -0
- package/dist-lib/core/teams/cloudEffects.d.ts.map +1 -0
- package/dist-lib/core/teams/cloudExtendedContracts.d.ts +1014 -0
- package/dist-lib/core/teams/cloudExtendedContracts.d.ts.map +1 -0
- package/dist-lib/core/teams/cloudMaterials.d.ts +83 -0
- package/dist-lib/core/teams/cloudMaterials.d.ts.map +1 -0
- package/dist-lib/core/teams/cloudOperations.d.ts +30 -0
- package/dist-lib/core/teams/cloudOperations.d.ts.map +1 -0
- package/dist-lib/core/teams/cloudProductClient.d.ts +177 -0
- package/dist-lib/core/teams/cloudProductClient.d.ts.map +1 -0
- package/dist-lib/core/teams/cloudScope.d.ts +6 -0
- package/dist-lib/core/teams/cloudScope.d.ts.map +1 -0
- package/dist-lib/core/teams/operationOutbox.d.ts +138 -0
- package/dist-lib/core/teams/operationOutbox.d.ts.map +1 -0
- package/dist-lib/core/teams/workspaceContracts.d.ts +1696 -0
- package/dist-lib/core/teams/workspaceContracts.d.ts.map +1 -0
- package/dist-lib/core/teams/workspaceObserver.d.ts +49 -0
- package/dist-lib/core/teams/workspaceObserver.d.ts.map +1 -0
- package/dist-lib/core/teams/workspaceReducer.d.ts +37 -0
- package/dist-lib/core/teams/workspaceReducer.d.ts.map +1 -0
- package/dist-lib/hooks/useAgentChat.d.ts +2 -7
- package/dist-lib/hooks/useAgentChat.d.ts.map +1 -1
- package/dist-lib/hooks/useFeedback.d.ts +2 -2
- package/dist-lib/hooks/useFeedback.d.ts.map +1 -1
- package/dist-lib/hooks/useImeComposition.d.ts +21 -0
- package/dist-lib/hooks/useImeComposition.d.ts.map +1 -0
- package/dist-lib/hooks/useInteractions.d.ts +1 -1
- package/dist-lib/hooks/useInteractions.d.ts.map +1 -1
- package/dist-lib/hooks/useRunAgent.d.ts +3 -1
- package/dist-lib/hooks/useRunAgent.d.ts.map +1 -1
- package/dist-lib/hooks/useSessionLifecycle.d.ts +1 -1
- package/dist-lib/hooks/useSessionLifecycle.d.ts.map +1 -1
- package/dist-lib/hooks.js +9 -9
- package/dist-lib/{permission-CcMWqN8Y.js → permission-B2MuVypC.js} +1 -1
- package/dist-lib/persisted-session-history-CBk_ypXo.js +2888 -0
- package/dist-lib/public/chat-timeline.d.ts +2 -0
- package/dist-lib/public/chat-timeline.d.ts.map +1 -1
- package/dist-lib/public/conversation.d.ts +3 -1
- package/dist-lib/public/conversation.d.ts.map +1 -1
- package/dist-lib/public/team-components.d.ts +1 -0
- package/dist-lib/public/team-components.d.ts.map +1 -1
- package/dist-lib/public/teams.d.ts +11 -0
- package/dist-lib/public/teams.d.ts.map +1 -1
- package/dist-lib/{reducer-BP8YVv-Q.js → reducer-mbYiX0wz.js} +81 -13
- package/dist-lib/{runtime-items-q6tMjfGU.js → runtime-items-VPq7711E.js} +0 -0
- package/dist-lib/runtime.js +287 -226
- package/dist-lib/stores/session.d.ts +20 -11
- package/dist-lib/stores/session.d.ts.map +1 -1
- package/dist-lib/styles.css +1 -1
- package/dist-lib/team-components.js +1877 -752
- package/dist-lib/teams.css +54 -0
- package/dist-lib/teams.js +677 -215
- package/dist-lib/types/agent-control.d.ts +2 -0
- package/dist-lib/types/agent-control.d.ts.map +1 -1
- package/dist-lib/types/capabilities.d.ts +6 -0
- package/dist-lib/types/capabilities.d.ts.map +1 -1
- package/dist-lib/types/session-events.d.ts +1 -0
- package/dist-lib/types/session-events.d.ts.map +1 -1
- package/dist-lib/{useSessionLifecycle-DQXKeBm9.js → useSessionLifecycle-DS3PPoWK.js} +1316 -1041
- package/dist-lib/utils/history-preparation.d.ts +8 -0
- package/dist-lib/utils/history-preparation.d.ts.map +1 -0
- package/dist-lib/utils/messages.d.ts +8 -4
- package/dist-lib/utils/messages.d.ts.map +1 -1
- package/dist-lib/utils/persisted-session-history.d.ts +1 -1
- package/dist-lib/utils/persisted-session-history.d.ts.map +1 -1
- package/dist-lib/utils/session-events.d.ts.map +1 -1
- package/dist-lib/utils/transcript-order.d.ts +10 -0
- package/dist-lib/utils/transcript-order.d.ts.map +1 -0
- package/package.json +4 -2
- package/schemas/teams-cloud/v1/binding-probe-permit.schema.json +1 -0
- package/schemas/teams-cloud/v1/build-artifact-lookup-input.schema.json +1 -0
- package/schemas/teams-cloud/v1/build-artifact-lookup-result.schema.json +1 -0
- package/schemas/teams-cloud/v1/build-artifact-receipt.schema.json +1 -0
- package/schemas/teams-cloud/v1/build-manifest.schema.json +1 -0
- package/schemas/teams-cloud/v1/callback-permit.schema.json +1 -0
- package/schemas/teams-cloud/v1/canonical-event-batch.schema.json +1 -0
- package/schemas/teams-cloud/v1/deployment-artifact-receipt.schema.json +1 -0
- package/schemas/teams-cloud/v1/effect-outcome.schema.json +1 -0
- package/schemas/teams-cloud/v1/effect-prepared-receipt.schema.json +1 -0
- package/schemas/teams-cloud/v1/effect-projection-page.schema.json +1 -0
- package/schemas/teams-cloud/v1/effect-projection.schema.json +1 -0
- package/schemas/teams-cloud/v1/effect-reconcile-input.schema.json +1 -0
- package/schemas/teams-cloud/v1/effect-record.schema.json +1 -0
- package/schemas/teams-cloud/v1/effect-report-receipt.schema.json +1 -0
- package/schemas/teams-cloud/v1/effect-request.schema.json +1 -0
- package/schemas/teams-cloud/v1/execution-effects-page.schema.json +1 -0
- package/schemas/teams-cloud/v1/execution-effects-request.schema.json +1 -0
- package/schemas/teams-cloud/v1/execution-permit.schema.json +1 -0
- package/schemas/teams-cloud/v1/execution-reference.schema.json +1 -0
- package/schemas/teams-cloud/v1/execution-result.schema.json +1 -0
- package/schemas/teams-cloud/v1/host-operation-result.schema.json +1 -0
- package/schemas/teams-cloud/v1/host-receipt.schema.json +1 -0
- package/schemas/teams-cloud/v1/loaded-build-evidence.schema.json +1 -0
- package/schemas/teams-cloud/v1/manifest.json +43 -0
- package/schemas/teams-cloud/v1/material-create.schema.json +1 -0
- package/schemas/teams-cloud/v1/material-manifest.schema.json +1 -0
- package/schemas/teams-cloud/v1/node-command.schema.json +1 -0
- package/schemas/teams-cloud/v1/node-probe-command.schema.json +1 -0
- package/schemas/teams-cloud/v1/node-probe-report.schema.json +1 -0
- package/schemas/teams-cloud/v1/node-report.schema.json +1 -0
- package/schemas/teams-cloud/v1/release-verification-receipt.schema.json +1 -0
- package/schemas/teams-cloud/v1/release-verify-input.schema.json +1 -0
- package/dist-ksadk/assets/architecture-7GRP2DOG-BCsa26zi.js +0 -1
- package/dist-ksadk/assets/channel-_KDifNys.js +0 -1
- package/dist-ksadk/assets/chunk-2Q5K7J3B-HdVkJ9F0.js +0 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-BVCW3ZqZ.js +0 -1
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-BVCW3ZqZ.js +0 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-CNXjFctL.js +0 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV-B5-8RH9c.js +0 -1
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-BppFxEKw.js +0 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-B-AhYj4C.js +0 -1
- package/dist-ksadk/assets/index-BMd2mucF.css +0 -2
- package/dist-ksadk/assets/index-D5qyyhTH.js +0 -244
- package/dist-ksadk/assets/info-A6RAGUB7-0uiKrC35.js +0 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-BVTmZ_cw.js +0 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-DyfxBU7V.js +0 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-FFontjL2.js +0 -1
- package/dist-ksadk/assets/railroad-74A4TZTK-D0Uidzen.js +0 -1
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-BOo_9T2h.js +0 -1
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-D6-BjW7Z.js +0 -1
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-CXx__yMm.js +0 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-BXAFScz8.js +0 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-uIQ2lJKH.js +0 -8
- package/dist-ksadk/assets/treeView-Q6P3EWNA-CK5GgucZ.js +0 -1
- package/dist-ksadk/assets/treemap-WGGIJYW6-Bq1u1SpG.js +0 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-QAt06uEz.js +0 -1
- package/dist-lib/persisted-session-history-ClsfDfGs.js +0 -1991
- package/dist-lib/reducer-gQmR9Qb9.js +0 -424
|
@@ -0,0 +1,2888 @@
|
|
|
1
|
+
import { t as e } from "./runtime-items-VPq7711E.js";
|
|
2
|
+
import { n as t } from "./tool-display-DTiRdghE.js";
|
|
3
|
+
import { d as n, i as r, l as i, o as a, p as o, t as s, u as c } from "./reducer-mbYiX0wz.js";
|
|
4
|
+
//#region src/core/conversation/safe-tool-value.ts
|
|
5
|
+
var l = [
|
|
6
|
+
"authorization",
|
|
7
|
+
"credential",
|
|
8
|
+
"password",
|
|
9
|
+
"secret",
|
|
10
|
+
"token",
|
|
11
|
+
"cookie",
|
|
12
|
+
"apikey",
|
|
13
|
+
"accesskey",
|
|
14
|
+
"secretaccesskey",
|
|
15
|
+
"clientsecret",
|
|
16
|
+
"refreshtoken",
|
|
17
|
+
"accesstoken",
|
|
18
|
+
"setcookie",
|
|
19
|
+
"traceback",
|
|
20
|
+
"stack",
|
|
21
|
+
"exception"
|
|
22
|
+
];
|
|
23
|
+
function u(e) {
|
|
24
|
+
return e.normalize("NFKC").toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
25
|
+
}
|
|
26
|
+
function d(e) {
|
|
27
|
+
let t = u(e);
|
|
28
|
+
return l.some((e) => t.includes(e));
|
|
29
|
+
}
|
|
30
|
+
function f(e) {
|
|
31
|
+
let t = e.split(".");
|
|
32
|
+
if (t.length > 4 || t.some((e) => e.length === 0)) return null;
|
|
33
|
+
let n = t.map((e) => {
|
|
34
|
+
let t = /^0x/i.test(e) ? 16 : e.length > 1 && e.startsWith("0") ? 8 : 10, n = t === 16 ? e.slice(2) : e;
|
|
35
|
+
if (!n || !RegExp("^[0-9a-f]+$", "i").test(n)) return null;
|
|
36
|
+
let r = Number.parseInt(n, t);
|
|
37
|
+
return Number.isSafeInteger(r) ? r : null;
|
|
38
|
+
});
|
|
39
|
+
if (n.some((e) => e === null)) return null;
|
|
40
|
+
let r = n, i = 2 ** (8 * (5 - r.length));
|
|
41
|
+
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
|
+
}
|
|
43
|
+
function p(e) {
|
|
44
|
+
return e >>> 24 == 0 || e >>> 24 == 10 || e >>> 24 == 127 || e >>> 16 == 43518 || e >>> 16 == 49320 || e >>> 20 == 2753;
|
|
45
|
+
}
|
|
46
|
+
function m(e) {
|
|
47
|
+
let t;
|
|
48
|
+
try {
|
|
49
|
+
t = decodeURIComponent(e).toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
|
|
50
|
+
} catch {
|
|
51
|
+
return !0;
|
|
52
|
+
}
|
|
53
|
+
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) : f(n || t);
|
|
55
|
+
if (i !== null) return p(i);
|
|
56
|
+
let a = Number.parseInt(t.split(":", 1)[0], 16);
|
|
57
|
+
return t === "::" || t === "::1" || Number.isInteger(a) && (a & 65024) == 64512 || Number.isInteger(a) && (a & 65472) == 65152;
|
|
58
|
+
}
|
|
59
|
+
function h(e) {
|
|
60
|
+
return (e.match(/https?:\/\/\[[^\]]+\](?::\d+)?[^\s<>{}"']*|https?:\/\/[^\s<>{}"'[\]()]+/gi) || []).some((e) => {
|
|
61
|
+
let t = e.replace(/[.,;:!?]+$/, "").replace(/\\/g, "/");
|
|
62
|
+
try {
|
|
63
|
+
let e = new URL(t);
|
|
64
|
+
return !!(e.username || e.password) || m(e.hostname);
|
|
65
|
+
} catch {
|
|
66
|
+
return !0;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function g(e, t = 0) {
|
|
71
|
+
return v(e, t, 8192);
|
|
72
|
+
}
|
|
73
|
+
function _(e, t, n) {
|
|
74
|
+
return v(e, 0, [
|
|
75
|
+
"langgraph",
|
|
76
|
+
"adk",
|
|
77
|
+
"codex"
|
|
78
|
+
].includes(String(t)) && !String(n || "").toLowerCase().includes("a2a") ? Infinity : 8192);
|
|
79
|
+
}
|
|
80
|
+
function v(e, t, n) {
|
|
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) || h(e) ? "[redacted]" : e.length > n ? `${e.slice(0, n)}[truncated]` : e : Array.isArray(e) ? e.slice(0, 128).map((e) => v(e, t + 1, n)) : e && typeof e == "object" ? Object.fromEntries(Object.entries(e).slice(0, 128).filter(([e]) => !d(e)).map(([e, r]) => [e, v(r, t + 1, n)])) : e;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/core/conversation/runtime-ingress.ts
|
|
85
|
+
var y = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, b = (e, t, n) => JSON.stringify([
|
|
86
|
+
e,
|
|
87
|
+
t,
|
|
88
|
+
n
|
|
89
|
+
]), x = class {
|
|
90
|
+
runtime = new e();
|
|
91
|
+
flatChildren = new s();
|
|
92
|
+
seen = /* @__PURE__ */ new Set();
|
|
93
|
+
parents = /* @__PURE__ */ new Map();
|
|
94
|
+
descriptorItemIds = /* @__PURE__ */ new Map();
|
|
95
|
+
descriptors = /* @__PURE__ */ new Map();
|
|
96
|
+
rootScope = "";
|
|
97
|
+
runId = "";
|
|
98
|
+
sessionId;
|
|
99
|
+
conversation;
|
|
100
|
+
profile;
|
|
101
|
+
constructor(e, t = new s(), n = "flat-v1") {
|
|
102
|
+
this.sessionId = e, this.conversation = t, this.profile = n;
|
|
103
|
+
}
|
|
104
|
+
identity(e, t, n, r = !1) {
|
|
105
|
+
return this.profile === "agent-block-v1" || r ? b(e, t, n) : n;
|
|
106
|
+
}
|
|
107
|
+
snapshot() {
|
|
108
|
+
let e = this.conversation.snapshot();
|
|
109
|
+
if (this.profile !== "flat-v1") return e;
|
|
110
|
+
let t = this.flatChildren.snapshot();
|
|
111
|
+
return {
|
|
112
|
+
items: [...e.items, ...t.items],
|
|
113
|
+
appliedSources: [...e.appliedSources, ...t.appliedSources]
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
apply(e) {
|
|
117
|
+
if (e.schema_version !== 2) return null;
|
|
118
|
+
let t = String(e.run_id || ""), n = String(e.scope_id || ""), r = String(e.event_id || ""), i = String(e.event_type || "");
|
|
119
|
+
if (!i.startsWith("item.") && !i.startsWith("run.")) return null;
|
|
120
|
+
if (!t || !n || !r) throw Error("RuntimeEvent identity missing");
|
|
121
|
+
if (this.runId && this.runId !== t) throw Error("RuntimeEvent run identity changed");
|
|
122
|
+
if (this.seen.has(r)) return null;
|
|
123
|
+
let o = String(e.parent_scope_id ?? this.descriptors.get(n)?.parent_scope_id ?? this.parents.get(n) ?? ""), s = y(e.source), c = [
|
|
124
|
+
"adk",
|
|
125
|
+
"langgraph",
|
|
126
|
+
"codex"
|
|
127
|
+
].includes(String(s.framework)) && !this.descriptors.has(n);
|
|
128
|
+
if (c && o && i === "run.progress") return null;
|
|
129
|
+
if (i.startsWith("run.") && (o || !c && this.rootScope && n !== this.rootScope)) throw Error("Child scope cannot transition root run");
|
|
130
|
+
if (this.parents.has(n) && this.parents.get(n) !== o) throw Error("Scope parent changed");
|
|
131
|
+
let l = String(e.item_id || ""), u = this.identity(t, n, l || r, !!o), d = Object.fromEntries(Object.entries({
|
|
132
|
+
framework: s.framework,
|
|
133
|
+
protocol: s.protocol,
|
|
134
|
+
eventId: s.native_event_id,
|
|
135
|
+
cursor: s.native_cursor,
|
|
136
|
+
runId: s.native_run_id,
|
|
137
|
+
itemId: s.native_item_id,
|
|
138
|
+
scopeId: n,
|
|
139
|
+
runtimeItemId: l || void 0,
|
|
140
|
+
parentScopeId: o || void 0,
|
|
141
|
+
phase: e.phase
|
|
142
|
+
}).filter(([, e]) => e != null)), f = {
|
|
143
|
+
apiVersion: "conversation.ksadk.io/v1",
|
|
144
|
+
kindVersion: 1,
|
|
145
|
+
itemId: u,
|
|
146
|
+
sessionId: this.sessionId,
|
|
147
|
+
runId: t,
|
|
148
|
+
sourceEventIds: [r],
|
|
149
|
+
kind: "progress",
|
|
150
|
+
operation: "replace",
|
|
151
|
+
lifecycle: "streaming",
|
|
152
|
+
visibility: "public",
|
|
153
|
+
payloadSchemaRef: "conversation.item.progress/v1",
|
|
154
|
+
payload: {},
|
|
155
|
+
nativeRef: d
|
|
156
|
+
}, p = y(y(e.source).metadata).conversation_visibility;
|
|
157
|
+
if ([
|
|
158
|
+
"public",
|
|
159
|
+
"internal",
|
|
160
|
+
"hidden"
|
|
161
|
+
].includes(String(p)) ? f.visibility = p : o && e.item_kind === "reasoning" && (f.visibility = "hidden"), i.startsWith("run.")) this.rootScope = n, f.payload = {
|
|
162
|
+
status: ["run.started", "run.progress"].includes(i) ? "running" : i.slice(4),
|
|
163
|
+
...e.output_refs ? { outputRefs: e.output_refs } : {}
|
|
164
|
+
}, i === "run.progress" && Object.assign(f.payload, {
|
|
165
|
+
progress: e.progress,
|
|
166
|
+
message: e.message
|
|
167
|
+
}), i === "run.interrupted" && (f.payload.reason = e.reason || ""), f.operation = ["run.started", "run.progress"].includes(i) ? "append" : "completed", [
|
|
168
|
+
"run.failed",
|
|
169
|
+
"run.canceled",
|
|
170
|
+
"run.cancelled"
|
|
171
|
+
].includes(i) && (f.kind = "error", f.payloadSchemaRef = "conversation.item.error/v1", f.payload.error = y(e.error).message || e.reason || ""), f.lifecycle = ["run.completed", "run.interrupted"].includes(i) ? "completed" : [
|
|
172
|
+
"run.failed",
|
|
173
|
+
"run.canceled",
|
|
174
|
+
"run.cancelled"
|
|
175
|
+
].includes(i) ? "failed" : "streaming";
|
|
176
|
+
else {
|
|
177
|
+
if (!l) throw Error("RuntimeEvent item identity missing");
|
|
178
|
+
let d = y(e.snapshot || e.initial), m = i === "item.updated" ? [y(e.update)] : Array.isArray(d.parts) ? d.parts : [], h = m.map((e) => {
|
|
179
|
+
let t = y(e);
|
|
180
|
+
return {
|
|
181
|
+
partId: String(t.part_id || "part"),
|
|
182
|
+
contentType: String(t.content_type || "data"),
|
|
183
|
+
...typeof t.text == "string" ? { text: t.text } : {},
|
|
184
|
+
value: t
|
|
185
|
+
};
|
|
186
|
+
}), v = m.map((e) => y(y(e).data)).find((e) => e.schema === "execution.scope/v1");
|
|
187
|
+
if (o && !v && !c) {
|
|
188
|
+
let e = this.descriptorItemIds.get(n);
|
|
189
|
+
if (!e) throw Error("Child content requires its scope descriptor first");
|
|
190
|
+
f.parentItemId = e;
|
|
191
|
+
}
|
|
192
|
+
if (v) {
|
|
193
|
+
if (this.descriptorItemIds.has(n) && this.descriptorItemIds.get(n) !== u) throw Error("Scope descriptor item identity changed");
|
|
194
|
+
let e = y(v.trigger_ref);
|
|
195
|
+
if (v.scope_id !== n || v.parent_scope_id !== o || e.scope_id !== o || !e.item_id || !e.call_id || !o) throw Error("Invalid scope descriptor locator");
|
|
196
|
+
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) => y(t.value).call_id === e.call_id)) throw Error("Scope trigger call mismatch");
|
|
198
|
+
let r = this.descriptors.get(n);
|
|
199
|
+
a({
|
|
200
|
+
...f,
|
|
201
|
+
kind: "agent",
|
|
202
|
+
payloadSchemaRef: "conversation.item.agent/v1",
|
|
203
|
+
payload: v
|
|
204
|
+
}, r ? {
|
|
205
|
+
...f,
|
|
206
|
+
kind: "agent",
|
|
207
|
+
payload: r
|
|
208
|
+
} : void 0), this.descriptors.set(n, v), this.descriptorItemIds.set(n, u);
|
|
209
|
+
}
|
|
210
|
+
for (let e of this.descriptors.values()) {
|
|
211
|
+
let t = y(e.trigger_ref);
|
|
212
|
+
if (t.scope_id === n && t.item_id === l && h.length && !h.some((e) => y(e.value).call_id === t.call_id)) throw Error("Scope trigger call mismatch");
|
|
213
|
+
}
|
|
214
|
+
let b = this.runtime.snapshot().items.find((e) => e.scopeId === n && e.itemId === l);
|
|
215
|
+
if (o && b && b.status !== "open") {
|
|
216
|
+
if (i === "item.updated" || i === "item.started") throw Error("Remote item cannot reopen");
|
|
217
|
+
if (Array.isArray(d.parts) && JSON.stringify(b.parts) !== JSON.stringify(h)) throw Error("Remote terminal content conflict");
|
|
218
|
+
}
|
|
219
|
+
let x = {
|
|
220
|
+
type: i.replaceAll(".", "_"),
|
|
221
|
+
runId: t,
|
|
222
|
+
scopeId: n,
|
|
223
|
+
itemId: l,
|
|
224
|
+
itemKind: e.item_kind,
|
|
225
|
+
eventId: r,
|
|
226
|
+
initialParts: h,
|
|
227
|
+
phase: e.phase,
|
|
228
|
+
...Array.isArray(d.parts) ? { parts: h } : {},
|
|
229
|
+
...i === "item.updated" ? {
|
|
230
|
+
partId: h[0]?.partId,
|
|
231
|
+
part: h[0],
|
|
232
|
+
op: e.op || "replace"
|
|
233
|
+
} : {}
|
|
234
|
+
};
|
|
235
|
+
this.runtime.apply(x);
|
|
236
|
+
let S = this.runtime.snapshot().items.find((e) => e.scopeId === n && e.itemId === l);
|
|
237
|
+
if (!S || o && S.itemKind === "status" && S.status === "open" && !S.parts.length) return null;
|
|
238
|
+
if (o && [
|
|
239
|
+
"artifact",
|
|
240
|
+
"tool_call",
|
|
241
|
+
"tool_result"
|
|
242
|
+
].includes(S.itemKind) && !S.parts.length) return this.runId = t, this.parents.set(n, o), this.seen.add(r), null;
|
|
243
|
+
let C = S.parts.map((e) => y(e.value)), w = C.map((e) => y(e.data)).find((e) => e.schema === "execution.scope/v1");
|
|
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(y(w.trigger_ref).scope_id), String(y(w.trigger_ref).item_id), !!this.parents.get(String(y(w.trigger_ref).scope_id))), f.capabilityRef = "agent.block";
|
|
245
|
+
else if (S.itemKind === "tool_call" || S.itemKind === "tool_result") {
|
|
246
|
+
let e = C.find((e) => e.content_type === "tool_call"), t = C.find((e) => e.content_type === "tool_result");
|
|
247
|
+
f.kind = "tool_call", f.capabilityRef = "tool.inspect", f.payloadSchemaRef = "conversation.item.tool-call/v1", f.payload = {
|
|
248
|
+
...e ? {
|
|
249
|
+
callId: e.call_id,
|
|
250
|
+
tool: e.name,
|
|
251
|
+
args: g(e.arguments)
|
|
252
|
+
} : {},
|
|
253
|
+
...t ? {
|
|
254
|
+
callId: t.call_id,
|
|
255
|
+
output: _(t.result, s.framework, s.protocol),
|
|
256
|
+
isError: t.is_error
|
|
257
|
+
} : {},
|
|
258
|
+
executionStatus: S.status === "failed" ? "failed" : t && S.status !== "open" ? t.is_error ? "failed" : "completed" : S.itemKind === "tool_result" ? "unknown" : "running",
|
|
259
|
+
sourceKind: S.itemKind
|
|
260
|
+
};
|
|
261
|
+
} else if (S.itemKind === "message" || S.itemKind === "reasoning" || S.itemKind === "artifact" && S.parts.length > 0 && S.parts.every((e) => e.contentType === "text")) f.kind = S.itemKind === "reasoning" ? "reasoning" : y(y(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("") }, i === "item.updated" && e.op === "append" && (f.operation = "append", f.payload.text = y(e.update).text || "");
|
|
262
|
+
else if (S.itemKind === "artifact") {
|
|
263
|
+
let e = C.find((e) => e.content_type === "artifact") || {};
|
|
264
|
+
f.kind = "artifact", f.payloadSchemaRef = "conversation.item.artifact/v1", f.payload = {
|
|
265
|
+
name: e.name,
|
|
266
|
+
mimeType: e.mime_type,
|
|
267
|
+
uri: e.uri
|
|
268
|
+
};
|
|
269
|
+
} else if (S.status === "failed") {
|
|
270
|
+
let t = y(e.error);
|
|
271
|
+
f.kind = "error", f.payloadSchemaRef = "conversation.item.error/v1", f.payload = { error: String(t.message || t.code || "Remote call failed") };
|
|
272
|
+
} else f.visibility = p === "public" ? "public" : "hidden", f.kind = "unknown", f.payloadSchemaRef = "conversation.item.unknown/v1", f.payload = { summary: "Unsupported runtime content" };
|
|
273
|
+
}
|
|
274
|
+
return this.runId = t, this.parents.set(n, o), this.seen.add(r), (this.profile === "flat-v1" && o ? this.flatChildren : this.conversation).apply(f), f;
|
|
275
|
+
}
|
|
276
|
+
}, S = {
|
|
277
|
+
user_message: "conversation.item.user_message/v1",
|
|
278
|
+
assistant_text: "conversation.item.assistant_text/v1",
|
|
279
|
+
reasoning: "conversation.item.reasoning/v1",
|
|
280
|
+
tool_call: "conversation.item.tool-call/v1",
|
|
281
|
+
agent: "conversation.item.agent/v1",
|
|
282
|
+
approval: "conversation.item.approval/v1",
|
|
283
|
+
artifact: "conversation.item.artifact/v1",
|
|
284
|
+
a2ui: "conversation.item.a2ui/v1",
|
|
285
|
+
error: "conversation.item.error/v1"
|
|
286
|
+
};
|
|
287
|
+
function C(e) {
|
|
288
|
+
return e.lifecycle === "completed" || e.lifecycle === "failed";
|
|
289
|
+
}
|
|
290
|
+
var w = new Set([
|
|
291
|
+
"aborted",
|
|
292
|
+
"canceled",
|
|
293
|
+
"cancelled",
|
|
294
|
+
"failed",
|
|
295
|
+
"incomplete",
|
|
296
|
+
"interrupted"
|
|
297
|
+
]);
|
|
298
|
+
function T(e) {
|
|
299
|
+
if (e.parentItemId || e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || e.kind !== "progress" && e.kind !== "error" || !C(e)) return;
|
|
300
|
+
let t = typeof e.payload.status == "string" ? e.payload.status.toLowerCase() : "";
|
|
301
|
+
if (t === "completed") return "completed";
|
|
302
|
+
if (w.has(t)) return "failed";
|
|
303
|
+
}
|
|
304
|
+
function ee(e) {
|
|
305
|
+
let t = S[e.kind];
|
|
306
|
+
return t === void 0 || t === e.payloadSchemaRef;
|
|
307
|
+
}
|
|
308
|
+
function te(e) {
|
|
309
|
+
if (typeof e != "string" || e.length === 0) return null;
|
|
310
|
+
try {
|
|
311
|
+
let t = new URL(e);
|
|
312
|
+
return t.protocol !== "http:" && t.protocol !== "https:" || t.username || t.password ? null : t.toString();
|
|
313
|
+
} catch {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function ne(e) {
|
|
318
|
+
return {
|
|
319
|
+
id: e.itemId,
|
|
320
|
+
parentId: e.parentItemId || null,
|
|
321
|
+
runId: e.runId,
|
|
322
|
+
kind: e.kind,
|
|
323
|
+
text: typeof e.payload.text == "string" ? e.payload.text : "",
|
|
324
|
+
lifecycle: e.lifecycle
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function re(e) {
|
|
328
|
+
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 = te(e.payload.uri);
|
|
329
|
+
return {
|
|
330
|
+
artifactId: t,
|
|
331
|
+
itemId: e.itemId,
|
|
332
|
+
runId: e.runId,
|
|
333
|
+
sourceEventIds: [...e.sourceEventIds],
|
|
334
|
+
id: e.itemId,
|
|
335
|
+
name: typeof e.payload.name == "string" && e.payload.name ? e.payload.name : "Artifact",
|
|
336
|
+
mimeType: typeof e.payload.mimeType == "string" && e.payload.mimeType ? e.payload.mimeType : "application/octet-stream",
|
|
337
|
+
sizeBytes: r,
|
|
338
|
+
status: e.lifecycle === "failed" ? "failed" : e.lifecycle === "completed" ? i ? "ready" : "failed" : "pending",
|
|
339
|
+
uri: i
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function E(e, t) {
|
|
343
|
+
let n = e.payload[t];
|
|
344
|
+
return typeof n == "string" && n ? n : null;
|
|
345
|
+
}
|
|
346
|
+
function ie(e) {
|
|
347
|
+
if (e.kind === "tool_call") {
|
|
348
|
+
let t = E(e, "callId");
|
|
349
|
+
if (t) return `tool:${JSON.stringify([
|
|
350
|
+
e.runId,
|
|
351
|
+
e.nativeRef.scopeId || e.nativeRef.scope_id || "",
|
|
352
|
+
t
|
|
353
|
+
])}`;
|
|
354
|
+
}
|
|
355
|
+
if (e.kind === "approval") {
|
|
356
|
+
let t = E(e, "interactionId");
|
|
357
|
+
if (t) return `approval:${t}`;
|
|
358
|
+
}
|
|
359
|
+
if (e.kind === "a2ui") {
|
|
360
|
+
let t = E(e, "surfaceId");
|
|
361
|
+
if (t) return `a2ui:${t}`;
|
|
362
|
+
}
|
|
363
|
+
return `item:${e.itemId}`;
|
|
364
|
+
}
|
|
365
|
+
function ae(e, t) {
|
|
366
|
+
let n = C(e) && !C(t);
|
|
367
|
+
return {
|
|
368
|
+
...e,
|
|
369
|
+
...t,
|
|
370
|
+
itemId: e.itemId,
|
|
371
|
+
parentItemId: e.parentItemId,
|
|
372
|
+
sourceEventIds: [...new Set([...e.sourceEventIds, ...t.sourceEventIds])],
|
|
373
|
+
payload: {
|
|
374
|
+
...e.payload,
|
|
375
|
+
...t.payload,
|
|
376
|
+
...e.payload.sourceKind === "tool_result" && t.payload.sourceKind === "tool_call" ? {
|
|
377
|
+
executionStatus: e.payload.executionStatus,
|
|
378
|
+
sourceKind: "tool_result"
|
|
379
|
+
} : {}
|
|
380
|
+
},
|
|
381
|
+
nativeRef: {
|
|
382
|
+
...e.nativeRef,
|
|
383
|
+
...t.nativeRef
|
|
384
|
+
},
|
|
385
|
+
...n ? {
|
|
386
|
+
lifecycle: e.lifecycle,
|
|
387
|
+
operation: e.operation
|
|
388
|
+
} : {}
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
function oe(e) {
|
|
392
|
+
let t = [], n = /* @__PURE__ */ new Map();
|
|
393
|
+
for (let r of e) {
|
|
394
|
+
let e = ie(r), i = n.get(e);
|
|
395
|
+
if (i === void 0) {
|
|
396
|
+
n.set(e, t.length), t.push({
|
|
397
|
+
key: e,
|
|
398
|
+
item: r,
|
|
399
|
+
sourceItemIds: [r.itemId]
|
|
400
|
+
});
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
let a = t[i];
|
|
404
|
+
t[i] = {
|
|
405
|
+
key: e,
|
|
406
|
+
item: ae(a.item, r),
|
|
407
|
+
sourceItemIds: [...new Set([...a.sourceItemIds, r.itemId])]
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
return t.map((t) => t.item.kind === "tool_call" ? {
|
|
411
|
+
...t,
|
|
412
|
+
item: {
|
|
413
|
+
...t.item,
|
|
414
|
+
payload: {
|
|
415
|
+
...t.item.payload,
|
|
416
|
+
...t.item.payload.sourceKind === "tool_result" ? { orphan: !e.some((e) => t.sourceItemIds.includes(e.itemId) && e.payload.sourceKind === "tool_call") } : {}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
} : t);
|
|
420
|
+
}
|
|
421
|
+
function se(e, t) {
|
|
422
|
+
let n = e.payload.trigger_ref;
|
|
423
|
+
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)) : [];
|
|
424
|
+
}
|
|
425
|
+
function ce(e) {
|
|
426
|
+
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) => se(t, e).map((e) => e.itemId))), a = e.filter((e) => !r(e) && !i.has(e.itemId));
|
|
427
|
+
return a.sort((t, n) => {
|
|
428
|
+
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);
|
|
429
|
+
return r(t) - r(n);
|
|
430
|
+
}), oe(a).map((t) => {
|
|
431
|
+
if (t.item.kind !== "agent") return t;
|
|
432
|
+
let n = oe(e.filter((e) => r(e) === t.item && !i.has(e.itemId)));
|
|
433
|
+
return {
|
|
434
|
+
...t,
|
|
435
|
+
sourceItemIds: [...new Set([...se(t.item, e).map((e) => e.itemId), ...t.sourceItemIds])],
|
|
436
|
+
children: n
|
|
437
|
+
};
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
function le(e, t = {}) {
|
|
441
|
+
let n = e.items.filter((e) => e.visibility === "public" || t.includeInternal === !0 && e.visibility === "internal");
|
|
442
|
+
if (t.profile === "flat-v1" && n.some((e) => e.kind === "agent")) {
|
|
443
|
+
let e = n.filter((e) => e.kind === "agent"), t = new Set(e.flatMap((e) => se(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) => T(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;
|
|
444
|
+
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)));
|
|
445
|
+
let s = a.filter((e) => e.kind === "assistant_text");
|
|
446
|
+
if (i && !s.some((e) => e.payload.text) && Array.isArray(o)) {
|
|
447
|
+
let e = o.flatMap((e) => n.filter((t) => t.runId === i.runId && t.nativeRef.scopeId === e.scope_id && t.nativeRef.runtimeItemId === e.item_id && t.kind === "assistant_text"));
|
|
448
|
+
e.length && a.push({
|
|
449
|
+
...e[0],
|
|
450
|
+
itemId: `${i.runId}:delegated-final`,
|
|
451
|
+
parentItemId: null,
|
|
452
|
+
nativeRef: {},
|
|
453
|
+
payload: { text: e.map((e) => e.payload.text).join("") },
|
|
454
|
+
lifecycle: "completed"
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
n = a.filter((e) => e.kind !== "assistant_text" || !!i);
|
|
458
|
+
}
|
|
459
|
+
let r = n.filter(ee), i = n.filter((e) => !ee(e)), a = new Set([
|
|
460
|
+
"user_message",
|
|
461
|
+
"assistant_text",
|
|
462
|
+
"reasoning"
|
|
463
|
+
]), o = r.filter((e) => a.has(e.kind)).map(ne), 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) => T(e) !== void 0);
|
|
464
|
+
return {
|
|
465
|
+
timeline: ce(r.filter((e) => e.kind !== "progress")),
|
|
466
|
+
output: c("assistant_text"),
|
|
467
|
+
reasoning: c("reasoning"),
|
|
468
|
+
textItems: o,
|
|
469
|
+
toolItems: r.filter((e) => e.kind === "tool_call"),
|
|
470
|
+
approvalItems: r.filter((e) => e.kind === "approval"),
|
|
471
|
+
structuredInputItems: r.filter((e) => e.kind === "progress" && e.payloadSchemaRef === "conversation.item.structured-input/v1"),
|
|
472
|
+
a2uiItems: r.filter((e) => e.kind === "a2ui"),
|
|
473
|
+
artifacts: r.filter((e) => e.kind === "artifact").map(re),
|
|
474
|
+
fallbacks: [...l.map((e) => ({
|
|
475
|
+
id: e.itemId,
|
|
476
|
+
title: "Unsupported content",
|
|
477
|
+
detail: String(e.payload.summary || e.payload.originalKind || e.payloadSchemaRef),
|
|
478
|
+
failed: e.lifecycle === "failed"
|
|
479
|
+
})), ...u.map((e) => ({
|
|
480
|
+
id: e.itemId,
|
|
481
|
+
title: "Run failed",
|
|
482
|
+
detail: String(e.payload.error || "The agent run failed."),
|
|
483
|
+
failed: !0
|
|
484
|
+
}))],
|
|
485
|
+
runId: n.at(-1)?.runId || "",
|
|
486
|
+
terminalStatus: d ? T(d) : void 0
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region src/core/conversation/client.ts
|
|
491
|
+
var D = 8;
|
|
492
|
+
function O(e) {
|
|
493
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
494
|
+
}
|
|
495
|
+
function k(e) {
|
|
496
|
+
if (e?.aborted) throw new o("conversation_aborted", "Conversation request was aborted.");
|
|
497
|
+
}
|
|
498
|
+
function ue(e, t) {
|
|
499
|
+
return t?.aborted === !0 || e instanceof Error && e.name === "AbortError";
|
|
500
|
+
}
|
|
501
|
+
function de(e) {
|
|
502
|
+
let t = e.trim().replace(/\/+$/, "");
|
|
503
|
+
if (!t) return "";
|
|
504
|
+
if (!t.includes("://")) return t.startsWith("/") ? t : `/${t}`;
|
|
505
|
+
try {
|
|
506
|
+
let e = new URL(t);
|
|
507
|
+
if (e.protocol !== "http:" && e.protocol !== "https:" || e.username || e.password) throw Error("unsafe URL");
|
|
508
|
+
return e.toString().replace(/\/$/, "");
|
|
509
|
+
} catch (e) {
|
|
510
|
+
throw new o("conversation_contract_mismatch", "Conversation base URL must be an HTTP(S) URL without embedded credentials.", { cause: e });
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function fe(e) {
|
|
514
|
+
return Math.min(200 * 2 ** Math.max(0, e - 1), 2e3);
|
|
515
|
+
}
|
|
516
|
+
function pe(e) {
|
|
517
|
+
return new Promise((t) => {
|
|
518
|
+
setTimeout(t, e);
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
async function me(e, t, n) {
|
|
522
|
+
if (k(n), !n) {
|
|
523
|
+
await e(t);
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
await new Promise((r, i) => {
|
|
527
|
+
let a = () => i(new o("conversation_aborted", "Conversation request was aborted."));
|
|
528
|
+
n.addEventListener("abort", a, { once: !0 }), e(t).then(r, i).finally(() => {
|
|
529
|
+
n.removeEventListener("abort", a);
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
function A(e, t, n, r, i) {
|
|
534
|
+
let a = i ? i.snapshot() : e.snapshot();
|
|
535
|
+
return {
|
|
536
|
+
cursor: t,
|
|
537
|
+
runId: n,
|
|
538
|
+
state: a,
|
|
539
|
+
presentation: le(a, { profile: r })
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
function he(e, t) {
|
|
543
|
+
let n, r = [];
|
|
544
|
+
for (let t of e.split(/\r?\n/)) {
|
|
545
|
+
let e = t.endsWith("\r") ? t.slice(0, -1) : t;
|
|
546
|
+
if (!e || e.startsWith(":")) continue;
|
|
547
|
+
let i = e.indexOf(":"), a = i < 0 ? e : e.slice(0, i), s = i < 0 ? "" : e.slice(i + 1), c = s.startsWith(" ") ? s.slice(1) : s;
|
|
548
|
+
if (a === "id") {
|
|
549
|
+
if (!/^\d+$/.test(c) || !Number.isSafeInteger(Number(c))) throw new o("conversation_stream_error", "Conversation stream contains an invalid replay cursor.");
|
|
550
|
+
n = Number(c);
|
|
551
|
+
} else a === "data" && r.push(c);
|
|
552
|
+
}
|
|
553
|
+
if (r.length === 0) return;
|
|
554
|
+
let a = r.join("\n");
|
|
555
|
+
if (!a || a === "[DONE]") return;
|
|
556
|
+
let s;
|
|
557
|
+
try {
|
|
558
|
+
s = JSON.parse(a);
|
|
559
|
+
} catch (e) {
|
|
560
|
+
throw new o("conversation_contract_mismatch", "Conversation stream contains invalid JSON.", { cause: e });
|
|
561
|
+
}
|
|
562
|
+
let c = O(s), l = O(c?.runtimeEvent) || O(c?.runtime_event) || (c?.schema_version === 2 ? c : null);
|
|
563
|
+
if (!c || c.conversationItem === void 0 && !l) {
|
|
564
|
+
n !== void 0 && (t.cursor = Math.max(t.cursor, n));
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
if (n === void 0) throw new o("conversation_stream_error", "Canonical conversation items require an SSE replay cursor.");
|
|
568
|
+
let u = c.conversationItem === void 0 ? "runtime" : "native";
|
|
569
|
+
if (t.lane && t.lane !== u) {
|
|
570
|
+
t.cursor = Math.max(t.cursor, n);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
let d;
|
|
574
|
+
try {
|
|
575
|
+
d = u === "native" ? i(c.conversationItem) : t.runtime.apply(l);
|
|
576
|
+
} catch (e) {
|
|
577
|
+
throw new o("conversation_contract_mismatch", "Runtime conversation identity or lifecycle invariant failed.", { cause: e });
|
|
578
|
+
}
|
|
579
|
+
if (u === "runtime" && !d) {
|
|
580
|
+
t.cursor = Math.max(t.cursor, n);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
if (!d) throw new o("conversation_contract_mismatch", "Conversation stream item does not match conversation.ksadk.io/v1.");
|
|
584
|
+
if (t.runId && t.runId !== d.runId) throw new o("conversation_contract_mismatch", "Conversation stream changed canonical run identity.", {
|
|
585
|
+
runId: t.runId,
|
|
586
|
+
cursor: t.cursor
|
|
587
|
+
});
|
|
588
|
+
t.runId = d.runId;
|
|
589
|
+
let f;
|
|
590
|
+
try {
|
|
591
|
+
f = u === "runtime" ? !0 : t.reducer.apply(d);
|
|
592
|
+
} catch (e) {
|
|
593
|
+
throw new o("conversation_contract_mismatch", "Conversation identity or lifecycle invariant failed.", { cause: e });
|
|
594
|
+
}
|
|
595
|
+
t.cursor = Math.max(t.cursor, n), f && !(t.profile === "flat-v1" && d.nativeRef.parentScopeId) && t.options.onItem?.(d), t.options.onUpdate?.(A(t.reducer, t.cursor, t.runId, t.profile, t.lane === "runtime" ? t.runtime : void 0));
|
|
596
|
+
}
|
|
597
|
+
async function ge(e, t) {
|
|
598
|
+
if (!e.body) throw new o("conversation_stream_error", "Conversation response has no event stream body.");
|
|
599
|
+
let n = e.body.getReader(), r = new TextDecoder(), i = "";
|
|
600
|
+
try {
|
|
601
|
+
for (;;) {
|
|
602
|
+
k(t.options.signal);
|
|
603
|
+
let { value: e, done: a } = await n.read();
|
|
604
|
+
if (a) break;
|
|
605
|
+
i += r.decode(e, { stream: !0 });
|
|
606
|
+
let o = /\r?\n\r?\n/.exec(i);
|
|
607
|
+
for (; o?.index !== void 0;) {
|
|
608
|
+
let e = o.index, n = o[0].length;
|
|
609
|
+
he(i.slice(0, e), t), i = i.slice(e + n), o = /\r?\n\r?\n/.exec(i);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
i += r.decode(), i.trim() && he(i, t);
|
|
613
|
+
} catch (e) {
|
|
614
|
+
throw e instanceof o ? e : (ue(e, t.options.signal) && k(t.options.signal), new o("conversation_stream_error", "Conversation event stream was interrupted.", {
|
|
615
|
+
cause: e,
|
|
616
|
+
runId: t.runId || void 0,
|
|
617
|
+
cursor: t.cursor
|
|
618
|
+
}));
|
|
619
|
+
} finally {
|
|
620
|
+
n.releaseLock();
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function _e(e) {
|
|
624
|
+
return e.state.items.some((e) => T(e) !== void 0);
|
|
625
|
+
}
|
|
626
|
+
var ve = class {
|
|
627
|
+
fetcher;
|
|
628
|
+
ingressLane;
|
|
629
|
+
rendererCatalog;
|
|
630
|
+
baseUrl;
|
|
631
|
+
maxReconnects;
|
|
632
|
+
sleep;
|
|
633
|
+
retryDelayMs;
|
|
634
|
+
constructor(e = {}) {
|
|
635
|
+
if (!Number.isInteger(e.maxReconnects ?? D) || (e.maxReconnects ?? D) < 0 || (e.maxReconnects ?? D) > 32) throw new o("conversation_contract_mismatch", "Conversation reconnect limit must be an integer from 0 to 32.");
|
|
636
|
+
this.fetcher = e.fetch, this.rendererCatalog = e.rendererCatalog, this.ingressLane = e.ingressLane, this.baseUrl = de(e.baseUrl || ""), this.maxReconnects = e.maxReconnects ?? D, this.sleep = e.sleep || pe, this.retryDelayMs = e.retryDelayMs || fe;
|
|
637
|
+
}
|
|
638
|
+
fetch() {
|
|
639
|
+
if (this.fetcher) return this.fetcher;
|
|
640
|
+
if (typeof globalThis.fetch == "function") return globalThis.fetch.bind(globalThis);
|
|
641
|
+
throw new o("conversation_http_error", "No fetch implementation is available for the conversation client.");
|
|
642
|
+
}
|
|
643
|
+
url(e) {
|
|
644
|
+
return `${this.baseUrl}${e}`;
|
|
645
|
+
}
|
|
646
|
+
async request(e, t, n, r = "conversation_stream_error") {
|
|
647
|
+
k(n);
|
|
648
|
+
try {
|
|
649
|
+
return await this.fetch()(e, t);
|
|
650
|
+
} catch (e) {
|
|
651
|
+
throw e instanceof o ? e : (ue(e, n) && k(n), new o(r, "Conversation network request failed.", { cause: e }));
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
assertOk(e) {
|
|
655
|
+
if (!e.ok) throw new o("conversation_http_error", `Conversation endpoint returned HTTP ${e.status}.`, { status: e.status });
|
|
656
|
+
}
|
|
657
|
+
async getSurface(e, t, n = {}) {
|
|
658
|
+
if (!e || !t) throw new o("conversation_contract_mismatch", "Agent and session identities are required to get a conversation surface.");
|
|
659
|
+
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");
|
|
660
|
+
this.assertOk(i);
|
|
661
|
+
let a;
|
|
662
|
+
try {
|
|
663
|
+
a = await i.json();
|
|
664
|
+
} catch (e) {
|
|
665
|
+
throw new o("conversation_contract_mismatch", "Conversation surface response is not valid JSON.", { cause: e });
|
|
666
|
+
}
|
|
667
|
+
let s = O(a), l = c(s?.surface);
|
|
668
|
+
if (!s || typeof s.buildId != "string" || !s.buildId || !l) throw new o("conversation_contract_mismatch", "Conversation surface response does not match conversation.ksadk.io/v1.");
|
|
669
|
+
return {
|
|
670
|
+
buildId: s.buildId,
|
|
671
|
+
surface: l
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
async streamTurn(e) {
|
|
675
|
+
k(e.signal);
|
|
676
|
+
let t = r(e.bootstrap.surface, this.rendererCatalog), i = {
|
|
677
|
+
...e.input,
|
|
678
|
+
...t === "agent-block-v1" || e.input.extensions?.["ksadk.presentation"] ? { extensions: {
|
|
679
|
+
...e.input.extensions,
|
|
680
|
+
"ksadk.presentation": { profile: t }
|
|
681
|
+
} } : {}
|
|
682
|
+
};
|
|
683
|
+
n(e.bootstrap.surface, i);
|
|
684
|
+
let a = e.bootstrap.surface.outputs.find((e) => e.name === "agent.block"), c = a?.mode === "native" ? "native" : a?.mode === "translated" ? "runtime" : void 0;
|
|
685
|
+
if (c && this.ingressLane && c !== this.ingressLane) throw new o("conversation_contract_mismatch", "Configured ingress lane disagrees with the conversation surface.");
|
|
686
|
+
let l = c || this.ingressLane || "native", u = new s(), d = {
|
|
687
|
+
profile: t,
|
|
688
|
+
lane: l,
|
|
689
|
+
runtime: new x(i.sessionId, u, t),
|
|
690
|
+
cursor: 0,
|
|
691
|
+
runId: "",
|
|
692
|
+
reducer: u,
|
|
693
|
+
options: e
|
|
694
|
+
}, f = {
|
|
695
|
+
method: "POST",
|
|
696
|
+
headers: {
|
|
697
|
+
"Content-Type": "application/json",
|
|
698
|
+
"Idempotency-Key": e.input.idempotencyKey
|
|
699
|
+
},
|
|
700
|
+
body: JSON.stringify({ input: i }),
|
|
701
|
+
...e.signal ? { signal: e.signal } : {}
|
|
702
|
+
}, p = await this.request(this.url(`/api/v1/builds/${encodeURIComponent(e.bootstrap.buildId)}/conversation:stream`), f, e.signal);
|
|
703
|
+
this.assertOk(p);
|
|
704
|
+
try {
|
|
705
|
+
await ge(p, d);
|
|
706
|
+
} catch (e) {
|
|
707
|
+
if (!(e instanceof o) || e.code !== "conversation_stream_error" || !d.runId) throw e;
|
|
708
|
+
}
|
|
709
|
+
let m = A(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0);
|
|
710
|
+
if (_e(m)) return m;
|
|
711
|
+
if (!d.runId) throw new o("conversation_run_identity_missing", "The stream ended before a canonical item supplied its run identity.", { cursor: d.cursor });
|
|
712
|
+
for (let t = 1; t <= this.maxReconnects; t += 1) {
|
|
713
|
+
await me(this.sleep, this.retryDelayMs(t), e.signal), k(e.signal);
|
|
714
|
+
let n;
|
|
715
|
+
try {
|
|
716
|
+
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" : ""}`), {
|
|
717
|
+
method: "GET",
|
|
718
|
+
headers: { "Last-Event-ID": String(d.cursor) },
|
|
719
|
+
...e.signal ? { signal: e.signal } : {}
|
|
720
|
+
}, e.signal), this.assertOk(n), await ge(n, d);
|
|
721
|
+
} catch (e) {
|
|
722
|
+
if (e instanceof o && e.code === "conversation_aborted" || e instanceof o && e.code === "conversation_contract_mismatch" || e instanceof o && e.code === "conversation_http_error" && e.status !== void 0 && e.status < 500) throw e;
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
if (m = A(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0), _e(m)) return m;
|
|
726
|
+
}
|
|
727
|
+
throw new o("conversation_reconnect_exhausted", "Conversation replay stopped after the configured reconnect limit.", {
|
|
728
|
+
runId: d.runId,
|
|
729
|
+
cursor: d.cursor
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
//#endregion
|
|
734
|
+
//#region src/core/conversation/renderer-registry.ts
|
|
735
|
+
function ye(e, t) {
|
|
736
|
+
if (!e.trim()) throw Error(`trusted conversation renderer ${t} must not be empty`);
|
|
737
|
+
}
|
|
738
|
+
function be(e) {
|
|
739
|
+
let t = /* @__PURE__ */ new Map();
|
|
740
|
+
for (let n of e) {
|
|
741
|
+
if (ye(n.id, "id"), ye(n.schemaRef, "schemaRef"), !n.kinds.length) throw Error("trusted conversation renderer kinds must not be empty");
|
|
742
|
+
if (t.has(n.schemaRef)) throw Error(`duplicate trusted conversation renderer schemaRef: ${n.schemaRef}`);
|
|
743
|
+
t.set(n.schemaRef, Object.freeze({
|
|
744
|
+
...n,
|
|
745
|
+
kinds: Object.freeze([...n.kinds])
|
|
746
|
+
}));
|
|
747
|
+
}
|
|
748
|
+
let n = Object.freeze([...t.values()]);
|
|
749
|
+
return Object.freeze({
|
|
750
|
+
resolve(e) {
|
|
751
|
+
let n = t.get(e.payloadSchemaRef);
|
|
752
|
+
return n?.kinds.includes(e.kind) ? n : void 0;
|
|
753
|
+
},
|
|
754
|
+
entries() {
|
|
755
|
+
return n;
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
var xe = be([{
|
|
760
|
+
id: "ksadk.agent-block",
|
|
761
|
+
schemaRef: "conversation.item.agent/v1",
|
|
762
|
+
kinds: ["agent"]
|
|
763
|
+
}]), j = (e) => e.runId || e.invocationId;
|
|
764
|
+
function M(e) {
|
|
765
|
+
let t = /* @__PURE__ */ new Map();
|
|
766
|
+
for (let n of e) {
|
|
767
|
+
let e = j(n), r = n.historyOrder?.group;
|
|
768
|
+
e && r !== void 0 && t.set(e, Math.min(r, t.get(e) ?? r));
|
|
769
|
+
}
|
|
770
|
+
let n = e.map((e, n) => ({
|
|
771
|
+
message: e,
|
|
772
|
+
index: n,
|
|
773
|
+
seq: e.historyOrder?.seq,
|
|
774
|
+
group: e.historyOrder?.group ?? t.get(j(e) || "") ?? e.historyOrder?.seq,
|
|
775
|
+
part: e.historyOrder?.index || 0
|
|
776
|
+
})), r, i = n.map(() => void 0);
|
|
777
|
+
for (let e = n.length - 1; e >= 0; e--) i[e] = r, n[e].group !== void 0 && (r = n[e].group);
|
|
778
|
+
let a;
|
|
779
|
+
return n.map((e) => e.group === void 0 ? {
|
|
780
|
+
...e,
|
|
781
|
+
anchor: a ?? i[e.index] ?? 0,
|
|
782
|
+
side: a === void 0 && i[e.index] !== void 0 ? -1 : 1
|
|
783
|
+
} : (a = e.group, {
|
|
784
|
+
...e,
|
|
785
|
+
anchor: e.group,
|
|
786
|
+
side: 0
|
|
787
|
+
})).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);
|
|
788
|
+
}
|
|
789
|
+
function Se(e, t) {
|
|
790
|
+
if (!t) return !0;
|
|
791
|
+
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];
|
|
792
|
+
return Object.keys(e).some(n) || Object.keys(t).some(n);
|
|
793
|
+
}
|
|
794
|
+
function Ce(e, t, n) {
|
|
795
|
+
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([j(e), e.responseId]), s = new Map(i.filter((e) => e.responseId).map((e) => [o(e), e.feedback])), c = (e) => e.map((e) => {
|
|
796
|
+
if (a.has(e.id)) return {
|
|
797
|
+
...e,
|
|
798
|
+
feedback: a.get(e.id)
|
|
799
|
+
};
|
|
800
|
+
let t = o(e);
|
|
801
|
+
return e.responseId && s.has(t) ? {
|
|
802
|
+
...e,
|
|
803
|
+
feedback: s.get(t)
|
|
804
|
+
} : e;
|
|
805
|
+
}), l = n.filter((e) => Se(e, r.get(e.id)));
|
|
806
|
+
if (!l.length) return c(e);
|
|
807
|
+
let u = new Set(l.map(j).filter(Boolean)), d = new Set(l.map((e) => e.id)), f = n.filter((e) => u.has(j(e)) || d.has(e.id)), p = e;
|
|
808
|
+
for (let t of u) {
|
|
809
|
+
let n = f.filter((e) => j(e) === t), r = e.filter((e) => j(e) === t), i = p.findIndex((e) => j(e) === t), a = n.some((e) => e.role === "user") ? [] : r.filter((e) => e.role === "user");
|
|
810
|
+
p = p.filter((e) => j(e) !== t);
|
|
811
|
+
let o = i < 0 ? p.length : Math.min(i, p.length);
|
|
812
|
+
p.splice(o, 0, ...a, ...n.map((e) => ({
|
|
813
|
+
...e,
|
|
814
|
+
historyOrder: e.historyOrder || r.find((t) => t.id === e.id)?.historyOrder
|
|
815
|
+
})));
|
|
816
|
+
}
|
|
817
|
+
for (let e of f.filter((e) => !j(e))) {
|
|
818
|
+
let t = p.findIndex((t) => t.id === e.id);
|
|
819
|
+
if (t < 0) {
|
|
820
|
+
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;
|
|
821
|
+
p = [
|
|
822
|
+
...p.slice(0, a),
|
|
823
|
+
e,
|
|
824
|
+
...p.slice(a)
|
|
825
|
+
];
|
|
826
|
+
} else p = p.map((n, r) => r === t ? {
|
|
827
|
+
...e,
|
|
828
|
+
historyOrder: e.historyOrder || n.historyOrder
|
|
829
|
+
} : n);
|
|
830
|
+
}
|
|
831
|
+
return c(M(p));
|
|
832
|
+
}
|
|
833
|
+
//#endregion
|
|
834
|
+
//#region src/core/conversation/hosted.ts
|
|
835
|
+
var we = "conversation_item_v1";
|
|
836
|
+
function Te(e) {
|
|
837
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
838
|
+
}
|
|
839
|
+
function N(e) {
|
|
840
|
+
return typeof e == "string" && e.trim() ? e : null;
|
|
841
|
+
}
|
|
842
|
+
function P(e) {
|
|
843
|
+
if (typeof e == "string") return e;
|
|
844
|
+
if (e == null) return "";
|
|
845
|
+
try {
|
|
846
|
+
return JSON.stringify(e, null, 2);
|
|
847
|
+
} catch {
|
|
848
|
+
return String(e);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
function F(e) {
|
|
852
|
+
return {
|
|
853
|
+
id: `conversation:${e.runId}:${e.itemId}`,
|
|
854
|
+
timestamp: 0,
|
|
855
|
+
eventType: we,
|
|
856
|
+
eventId: e.sourceEventIds.at(-1),
|
|
857
|
+
runId: e.runId,
|
|
858
|
+
itemId: e.itemId,
|
|
859
|
+
status: e.lifecycle === "failed" ? "failed" : e.lifecycle === "completed" ? "completed" : "running"
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
function Ee(e) {
|
|
863
|
+
return e.lifecycle === "failed" ? "error" : e.lifecycle === "completed" ? "done" : "streaming";
|
|
864
|
+
}
|
|
865
|
+
function De(e) {
|
|
866
|
+
let t = typeof e.payload.text == "string" ? e.payload.text : "";
|
|
867
|
+
if (e.kind === "user_message") return {
|
|
868
|
+
...F(e),
|
|
869
|
+
role: "user",
|
|
870
|
+
content: t,
|
|
871
|
+
eventType: "user_message"
|
|
872
|
+
};
|
|
873
|
+
let n = e.kind === "reasoning" ? {
|
|
874
|
+
id: `conversation-block:${e.itemId}`,
|
|
875
|
+
type: "thinking",
|
|
876
|
+
content: t,
|
|
877
|
+
status: Ee(e)
|
|
878
|
+
} : {
|
|
879
|
+
id: `conversation-block:${e.itemId}`,
|
|
880
|
+
type: "text",
|
|
881
|
+
content: t,
|
|
882
|
+
status: Ee(e)
|
|
883
|
+
};
|
|
884
|
+
return {
|
|
885
|
+
...F(e),
|
|
886
|
+
role: "model",
|
|
887
|
+
content: e.kind === "assistant_text" ? t : "",
|
|
888
|
+
reasoning: e.kind === "reasoning" ? t : void 0,
|
|
889
|
+
blocks: [n]
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
function Oe(e) {
|
|
893
|
+
let t = N(e.payload.tool) || (e.payload.sourceKind === "tool_result" ? "Tool result" : "Tool"), n = N(e.payload.callId), r = P(g(e.payload.args)), i = Object.prototype.hasOwnProperty.call(e.payload, "output") ? P(_(e.payload.output, e.nativeRef.framework, e.nativeRef.protocol)) : void 0, a = {
|
|
894
|
+
failed: "error",
|
|
895
|
+
completed: "completed",
|
|
896
|
+
running: "running",
|
|
897
|
+
unknown: "unknown"
|
|
898
|
+
}, o = e.payload.executionStatus, s = typeof o == "string" && Object.hasOwn(a, o) ? a[o] : e.lifecycle === "failed" || e.payload.isError === !0 ? "error" : e.lifecycle === "completed" ? "completed" : "running";
|
|
899
|
+
return {
|
|
900
|
+
...F(e),
|
|
901
|
+
role: "model",
|
|
902
|
+
content: "",
|
|
903
|
+
blocks: [{
|
|
904
|
+
id: `conversation-block:${e.itemId}`,
|
|
905
|
+
type: "tool",
|
|
906
|
+
toolName: t,
|
|
907
|
+
args: r,
|
|
908
|
+
output: i,
|
|
909
|
+
status: s,
|
|
910
|
+
...n ? { extra: { callId: n } } : {}
|
|
911
|
+
}],
|
|
912
|
+
tools: { [t]: {
|
|
913
|
+
name: t,
|
|
914
|
+
...n ? { callId: n } : {},
|
|
915
|
+
args: r,
|
|
916
|
+
output: i,
|
|
917
|
+
status: s
|
|
918
|
+
} }
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
function ke(e) {
|
|
922
|
+
return e === "structured_input" ? "structured_input" : e === "plan_review" ? "plan_review" : e === "custom" ? "custom" : "approval";
|
|
923
|
+
}
|
|
924
|
+
function Ae(e) {
|
|
925
|
+
let t = N(e.payload.interactionId), n = e.payload.revision;
|
|
926
|
+
if (!t || !Number.isInteger(n) || Number(n) < 1) return null;
|
|
927
|
+
let r = P(e.payload.detail), i = N(e.payload.prompt) || r, a = ke(e.payload.interactionKind), o = e.lifecycle === "completed";
|
|
928
|
+
return {
|
|
929
|
+
interactionId: t,
|
|
930
|
+
sessionId: e.sessionId,
|
|
931
|
+
runId: e.runId,
|
|
932
|
+
kind: a,
|
|
933
|
+
title: N(e.payload.title) || (a === "approval" ? `审批:${N(e.payload.kind) || "操作"}` : "需要补充信息"),
|
|
934
|
+
message: i || "运行需要人工确认。",
|
|
935
|
+
requestSchema: Te(e.payload.inputSchema),
|
|
936
|
+
presentation: null,
|
|
937
|
+
status: o ? "resolved" : "pending",
|
|
938
|
+
revision: Number(n),
|
|
939
|
+
createdAt: N(e.payload.createdAt) || "",
|
|
940
|
+
expiresAt: N(e.payload.expiresAt),
|
|
941
|
+
resolvedAt: o ? N(e.payload.resolvedAt) : null,
|
|
942
|
+
actor: o ? N(e.payload.actor) : null,
|
|
943
|
+
outcome: o && [
|
|
944
|
+
"approved",
|
|
945
|
+
"rejected",
|
|
946
|
+
"submitted",
|
|
947
|
+
"cancelled",
|
|
948
|
+
"expired"
|
|
949
|
+
].includes(String(e.payload.outcome || "")) ? e.payload.outcome : null,
|
|
950
|
+
responseSummary: o ? N(e.payload.responseSummary) : null,
|
|
951
|
+
source: "interaction_v1",
|
|
952
|
+
extensions: {
|
|
953
|
+
conversation_item_id: e.itemId,
|
|
954
|
+
...N(e.payload.callId) ? { call_id: N(e.payload.callId) } : {}
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
function je(e, t) {
|
|
959
|
+
let n = N(e.payload.kind) || "approval", r = P(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 = {
|
|
960
|
+
approvalRequestId: t.interactionId,
|
|
961
|
+
approvalStatus: i,
|
|
962
|
+
approvalMessage: t.message
|
|
963
|
+
};
|
|
964
|
+
return {
|
|
965
|
+
...F(e),
|
|
966
|
+
role: "model",
|
|
967
|
+
content: "",
|
|
968
|
+
blocks: [{
|
|
969
|
+
id: `conversation-block:${e.itemId}`,
|
|
970
|
+
type: "tool",
|
|
971
|
+
toolName: n,
|
|
972
|
+
args: r,
|
|
973
|
+
status: a,
|
|
974
|
+
extra: o
|
|
975
|
+
}],
|
|
976
|
+
tools: { [n]: {
|
|
977
|
+
name: n,
|
|
978
|
+
args: r,
|
|
979
|
+
status: a,
|
|
980
|
+
approvalRequestId: t.interactionId,
|
|
981
|
+
approvalStatus: i,
|
|
982
|
+
approvalMessage: t.message
|
|
983
|
+
} }
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
function Me(e) {
|
|
987
|
+
for (let t of [
|
|
988
|
+
"createSurface",
|
|
989
|
+
"updateComponents",
|
|
990
|
+
"updateDataModel",
|
|
991
|
+
"deleteSurface"
|
|
992
|
+
]) {
|
|
993
|
+
let n = N(Te(e[t])?.surfaceId);
|
|
994
|
+
if (n) return n;
|
|
995
|
+
}
|
|
996
|
+
return null;
|
|
997
|
+
}
|
|
998
|
+
function Ne(e) {
|
|
999
|
+
let t = Array.isArray(e.payload.data) ? e.payload.data : Array.isArray(e.payload.operations) ? e.payload.operations : null;
|
|
1000
|
+
if (!t) return null;
|
|
1001
|
+
let n = t.map(Te);
|
|
1002
|
+
if (n.some((e) => e === null)) return null;
|
|
1003
|
+
let r = n, i = N(e.payload.surfaceId) || r.map(Me).find((e) => e !== null) || null;
|
|
1004
|
+
return i ? {
|
|
1005
|
+
...F(e),
|
|
1006
|
+
role: "a2ui",
|
|
1007
|
+
content: "",
|
|
1008
|
+
aguiActivity: {
|
|
1009
|
+
surfaceId: i,
|
|
1010
|
+
messages: r
|
|
1011
|
+
}
|
|
1012
|
+
} : null;
|
|
1013
|
+
}
|
|
1014
|
+
function I(e, t, n, r = !1) {
|
|
1015
|
+
return {
|
|
1016
|
+
...F(e),
|
|
1017
|
+
role: "system",
|
|
1018
|
+
content: n ? `${t}: ${n}` : t,
|
|
1019
|
+
status: r ? "failed" : F(e).status
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
function Pe(e) {
|
|
1023
|
+
for (let { item: t } of [...e].reverse()) {
|
|
1024
|
+
if (t.visibility !== "public" || t.kind !== "assistant_text" || t.payloadSchemaRef !== "conversation.item.assistant_text/v1" || typeof t.payload.text != "string") continue;
|
|
1025
|
+
let e = g(t.payload.text);
|
|
1026
|
+
if (typeof e != "string" || e === "[redacted]") continue;
|
|
1027
|
+
let n = e.replace(/\s+/g, " ").trim();
|
|
1028
|
+
if (!n) continue;
|
|
1029
|
+
let r = Array.from(n);
|
|
1030
|
+
return r.length > 160 ? `${r.slice(0, 160).join("")}…` : n;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
function L(e) {
|
|
1034
|
+
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 = [];
|
|
1035
|
+
for (let d of t.timeline) {
|
|
1036
|
+
let { item: f } = d;
|
|
1037
|
+
if (f.kind === "agent") {
|
|
1038
|
+
if (!d.children) {
|
|
1039
|
+
l.push(I(f, "Remote agent", String(f.payload.status || "submitted")));
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
let n = L({
|
|
1043
|
+
...e,
|
|
1044
|
+
presentation: {
|
|
1045
|
+
...t,
|
|
1046
|
+
timeline: d.children || []
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1049
|
+
l.push({
|
|
1050
|
+
...F(f),
|
|
1051
|
+
role: "model",
|
|
1052
|
+
content: "",
|
|
1053
|
+
agentBlock: {
|
|
1054
|
+
item: f,
|
|
1055
|
+
messages: n.messages,
|
|
1056
|
+
summary: Pe(d.children || [])
|
|
1057
|
+
},
|
|
1058
|
+
status: f.payload.status === "cancelled" ? "cancelled" : F(f).status
|
|
1059
|
+
}), u.push(...n.interactions);
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
if (n.has(f.itemId)) {
|
|
1063
|
+
l.push(De(f));
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1066
|
+
if (r.has(f.itemId)) {
|
|
1067
|
+
l.push(Oe(f));
|
|
1068
|
+
continue;
|
|
1069
|
+
}
|
|
1070
|
+
if (i.has(f.itemId) || a.has(f.itemId)) {
|
|
1071
|
+
let e = Ae(f);
|
|
1072
|
+
e ? (u.push(e), l.push(je(f, e))) : l.push(I(f, "Interaction unavailable", "The server did not provide a durable interaction revision; this card is read-only."));
|
|
1073
|
+
continue;
|
|
1074
|
+
}
|
|
1075
|
+
if (o.has(f.itemId)) {
|
|
1076
|
+
let e = Ne(f);
|
|
1077
|
+
l.push(e || I(f, "Unsupported content", "A2UI payload is not a valid passive operation list."));
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
let p = s.get(f.itemId);
|
|
1081
|
+
if (p) {
|
|
1082
|
+
l.push(p.status === "pending" ? {
|
|
1083
|
+
...F(f),
|
|
1084
|
+
role: "model",
|
|
1085
|
+
content: p.name,
|
|
1086
|
+
attachments: [{
|
|
1087
|
+
name: p.name,
|
|
1088
|
+
type: p.mimeType,
|
|
1089
|
+
url: "",
|
|
1090
|
+
artifactId: p.artifactId,
|
|
1091
|
+
itemId: p.itemId,
|
|
1092
|
+
runId: p.runId,
|
|
1093
|
+
sizeBytes: p.sizeBytes,
|
|
1094
|
+
status: "pending"
|
|
1095
|
+
}]
|
|
1096
|
+
} : p.status === "ready" && p.uri ? {
|
|
1097
|
+
...F(f),
|
|
1098
|
+
role: "model",
|
|
1099
|
+
content: p.name,
|
|
1100
|
+
attachments: [{
|
|
1101
|
+
name: p.name,
|
|
1102
|
+
type: p.mimeType,
|
|
1103
|
+
url: p.uri,
|
|
1104
|
+
artifactId: p.artifactId,
|
|
1105
|
+
itemId: p.itemId,
|
|
1106
|
+
runId: p.runId,
|
|
1107
|
+
sizeBytes: p.sizeBytes,
|
|
1108
|
+
status: p.status
|
|
1109
|
+
}]
|
|
1110
|
+
} : I(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."));
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1113
|
+
let m = c.get(f.itemId);
|
|
1114
|
+
if (m) {
|
|
1115
|
+
if (f.kind === "error" && ["cancelled", "canceled"].includes(String(f.payload.status || "").toLowerCase())) continue;
|
|
1116
|
+
l.push(I(f, m.title, m.detail, m.failed));
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
return {
|
|
1120
|
+
messages: l,
|
|
1121
|
+
interactions: u
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
function Fe(e, t, n) {
|
|
1125
|
+
let r = L(t).messages;
|
|
1126
|
+
if (!r.length) return e;
|
|
1127
|
+
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") ? [{
|
|
1128
|
+
...c,
|
|
1129
|
+
invocationId: t.runId,
|
|
1130
|
+
eventType: void 0
|
|
1131
|
+
}] : [];
|
|
1132
|
+
return [
|
|
1133
|
+
...l.slice(0, d),
|
|
1134
|
+
...f,
|
|
1135
|
+
...r,
|
|
1136
|
+
...l.slice(d)
|
|
1137
|
+
];
|
|
1138
|
+
}
|
|
1139
|
+
//#endregion
|
|
1140
|
+
//#region src/core/run/blocks.ts
|
|
1141
|
+
var Ie = 0;
|
|
1142
|
+
function R(e) {
|
|
1143
|
+
return Ie += 1, `${e}-${Ie}`;
|
|
1144
|
+
}
|
|
1145
|
+
function z(e) {
|
|
1146
|
+
return e.map((e) => e.type === "thinking" && e.status === "streaming" ? {
|
|
1147
|
+
...e,
|
|
1148
|
+
status: "done"
|
|
1149
|
+
} : e);
|
|
1150
|
+
}
|
|
1151
|
+
function Le(e, t) {
|
|
1152
|
+
let n = [...e ?? []], r = n[n.length - 1];
|
|
1153
|
+
return r?.type === "thinking" && r.status === "streaming" ? (n[n.length - 1] = {
|
|
1154
|
+
...r,
|
|
1155
|
+
content: r.content + t
|
|
1156
|
+
}, n) : [...n, {
|
|
1157
|
+
id: R("thinking"),
|
|
1158
|
+
type: "thinking",
|
|
1159
|
+
content: t,
|
|
1160
|
+
status: "streaming"
|
|
1161
|
+
}];
|
|
1162
|
+
}
|
|
1163
|
+
function Re(e, t) {
|
|
1164
|
+
let n = [...z(e ?? [])], r = n[n.length - 1];
|
|
1165
|
+
return r?.type === "text" && r.status === "streaming" ? (n[n.length - 1] = {
|
|
1166
|
+
...r,
|
|
1167
|
+
content: r.content + t
|
|
1168
|
+
}, n) : [...n, {
|
|
1169
|
+
id: R("text"),
|
|
1170
|
+
type: "text",
|
|
1171
|
+
content: t,
|
|
1172
|
+
status: "streaming"
|
|
1173
|
+
}];
|
|
1174
|
+
}
|
|
1175
|
+
function ze(e, t) {
|
|
1176
|
+
let n = z(e ?? []);
|
|
1177
|
+
if (n.filter((e) => e.type === "text").map((e) => e.content).join("") === t) return n.map((e) => e.type === "text" && e.status === "streaming" ? {
|
|
1178
|
+
...e,
|
|
1179
|
+
status: "done"
|
|
1180
|
+
} : e);
|
|
1181
|
+
let r = [...n], i = r.map((e) => e.type).lastIndexOf("text");
|
|
1182
|
+
return i >= 0 && r[i].type === "text" ? (r[i] = {
|
|
1183
|
+
...r[i],
|
|
1184
|
+
content: t,
|
|
1185
|
+
status: "done"
|
|
1186
|
+
}, r) : [...r, {
|
|
1187
|
+
id: R("text"),
|
|
1188
|
+
type: "text",
|
|
1189
|
+
content: t,
|
|
1190
|
+
status: "done"
|
|
1191
|
+
}];
|
|
1192
|
+
}
|
|
1193
|
+
function Be(e, t) {
|
|
1194
|
+
if (!t) return [...e ?? []];
|
|
1195
|
+
let n = [...e ?? []], r = n[n.length - 1];
|
|
1196
|
+
if (r?.type !== "thinking" || !r.content.endsWith(t)) return n;
|
|
1197
|
+
let i = r.content.slice(0, -t.length);
|
|
1198
|
+
return i ? (n[n.length - 1] = {
|
|
1199
|
+
...r,
|
|
1200
|
+
content: i
|
|
1201
|
+
}, n) : (n.pop(), n);
|
|
1202
|
+
}
|
|
1203
|
+
function Ve(e, t, n) {
|
|
1204
|
+
let r = [...z(e ?? [])], i = r.findIndex((e) => e.type === "tool" && e.toolName === t);
|
|
1205
|
+
if (i >= 0 && r[i].type === "tool") {
|
|
1206
|
+
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);
|
|
1207
|
+
if (t && !a && !o) return r;
|
|
1208
|
+
let s = n.extra ?? e.extra;
|
|
1209
|
+
return r[i] = {
|
|
1210
|
+
...e,
|
|
1211
|
+
...n,
|
|
1212
|
+
extra: s
|
|
1213
|
+
}, r;
|
|
1214
|
+
}
|
|
1215
|
+
return [...r, {
|
|
1216
|
+
id: R("tool"),
|
|
1217
|
+
type: "tool",
|
|
1218
|
+
toolName: t,
|
|
1219
|
+
args: n.args ?? "",
|
|
1220
|
+
output: n.output,
|
|
1221
|
+
status: n.status ?? "running",
|
|
1222
|
+
extra: n.extra
|
|
1223
|
+
}];
|
|
1224
|
+
}
|
|
1225
|
+
function He(e) {
|
|
1226
|
+
return z(e ?? []);
|
|
1227
|
+
}
|
|
1228
|
+
function Ue(e) {
|
|
1229
|
+
let t = [];
|
|
1230
|
+
if (e.reasoning && e.reasoning.trim() && t.push({
|
|
1231
|
+
id: R("thinking"),
|
|
1232
|
+
type: "thinking",
|
|
1233
|
+
content: e.reasoning,
|
|
1234
|
+
status: "done"
|
|
1235
|
+
}), e.tools) for (let n of Object.values(e.tools)) t.push({
|
|
1236
|
+
id: R("tool"),
|
|
1237
|
+
type: "tool",
|
|
1238
|
+
toolName: n.name,
|
|
1239
|
+
args: n.args ?? "",
|
|
1240
|
+
output: n.output,
|
|
1241
|
+
status: n.status ?? "completed",
|
|
1242
|
+
...n.callId || n.approvalRequestId ? { extra: {
|
|
1243
|
+
...n.callId ? { callId: n.callId } : {},
|
|
1244
|
+
...n.approvalRequestId ? { approvalRequestId: n.approvalRequestId } : {}
|
|
1245
|
+
} } : {}
|
|
1246
|
+
});
|
|
1247
|
+
return e.content && e.content.trim() && t.push({
|
|
1248
|
+
id: R("text"),
|
|
1249
|
+
type: "text",
|
|
1250
|
+
content: e.content,
|
|
1251
|
+
status: "done"
|
|
1252
|
+
}), t;
|
|
1253
|
+
}
|
|
1254
|
+
//#endregion
|
|
1255
|
+
//#region src/core/stream/kernel-events.ts
|
|
1256
|
+
var We = {
|
|
1257
|
+
"run.started": "in_progress",
|
|
1258
|
+
"run.progress": "in_progress",
|
|
1259
|
+
"run.completed": "completed",
|
|
1260
|
+
"run.failed": "failed",
|
|
1261
|
+
"run.canceled": "cancelled",
|
|
1262
|
+
"run.interrupted": "interrupted"
|
|
1263
|
+
}, Ge = new Set([
|
|
1264
|
+
"completed",
|
|
1265
|
+
"failed",
|
|
1266
|
+
"cancelled",
|
|
1267
|
+
"canceled"
|
|
1268
|
+
]);
|
|
1269
|
+
function B(e) {
|
|
1270
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
1271
|
+
}
|
|
1272
|
+
function Ke(e) {
|
|
1273
|
+
let t = B(e.source), n = t ? B(t.metadata) : null;
|
|
1274
|
+
return String(n?.native_item_kind || "");
|
|
1275
|
+
}
|
|
1276
|
+
function V(e, t) {
|
|
1277
|
+
let n = B(e[t]);
|
|
1278
|
+
if (!n) return [];
|
|
1279
|
+
let r = n?.parts;
|
|
1280
|
+
return Array.isArray(r) ? r : t === "update" ? [n] : [];
|
|
1281
|
+
}
|
|
1282
|
+
function qe(e) {
|
|
1283
|
+
let t = B(e);
|
|
1284
|
+
if (!t) return "";
|
|
1285
|
+
if (typeof t.text == "string") return t.text;
|
|
1286
|
+
let n = B(t.data);
|
|
1287
|
+
if (n) {
|
|
1288
|
+
let e = n.content;
|
|
1289
|
+
if (Array.isArray(e)) return e.map((e) => String(B(e)?.text || "")).join("");
|
|
1290
|
+
for (let e of [
|
|
1291
|
+
"text",
|
|
1292
|
+
"output",
|
|
1293
|
+
"stdout",
|
|
1294
|
+
"stderr"
|
|
1295
|
+
]) if (n[e] != null) return String(n[e]);
|
|
1296
|
+
}
|
|
1297
|
+
return "";
|
|
1298
|
+
}
|
|
1299
|
+
function H(e) {
|
|
1300
|
+
return e.map(qe).join("");
|
|
1301
|
+
}
|
|
1302
|
+
function Je(e) {
|
|
1303
|
+
return e.some((e) => B(B(e)?.data)?.type === "userMessage");
|
|
1304
|
+
}
|
|
1305
|
+
function U(e) {
|
|
1306
|
+
if (e.length === 1) {
|
|
1307
|
+
let t = B(B(e[0])?.data);
|
|
1308
|
+
if (t) return t;
|
|
1309
|
+
}
|
|
1310
|
+
return H(e) || null;
|
|
1311
|
+
}
|
|
1312
|
+
function Ye(e) {
|
|
1313
|
+
let t = B(e);
|
|
1314
|
+
return t ? B(t.data) || t : null;
|
|
1315
|
+
}
|
|
1316
|
+
function Xe(e) {
|
|
1317
|
+
let t = Ye(e);
|
|
1318
|
+
return String(t?.content_type || t?.type || "").trim().toLowerCase();
|
|
1319
|
+
}
|
|
1320
|
+
function Ze(e) {
|
|
1321
|
+
for (let t of e) {
|
|
1322
|
+
let e = Ye(t);
|
|
1323
|
+
if (!e || Xe(t) !== "tool_call") continue;
|
|
1324
|
+
let n = String(e.call_id || "").trim(), r = String(e.name || e.tool_name || "").trim();
|
|
1325
|
+
if (!(!n && !r)) return {
|
|
1326
|
+
callId: n,
|
|
1327
|
+
name: r,
|
|
1328
|
+
arguments: e.arguments ?? e.args ?? {}
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
return null;
|
|
1332
|
+
}
|
|
1333
|
+
function Qe(e) {
|
|
1334
|
+
for (let t of e) {
|
|
1335
|
+
let e = Ye(t);
|
|
1336
|
+
if (!e || Xe(t) !== "tool_result") continue;
|
|
1337
|
+
let n = String(e.call_id || e.tool_call_id || "").trim(), r = e.is_error === !0 || e.error != null;
|
|
1338
|
+
return {
|
|
1339
|
+
callId: n,
|
|
1340
|
+
result: e.result ?? e.output ?? e.error ?? null,
|
|
1341
|
+
isError: r
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
return null;
|
|
1345
|
+
}
|
|
1346
|
+
function W(e, t, n, r) {
|
|
1347
|
+
let i = String(e.item_id || ""), a = String(r || i);
|
|
1348
|
+
return { RuntimeItem: {
|
|
1349
|
+
RunId: String(e.run_id || ""),
|
|
1350
|
+
ScopeId: String(e.scope_id || e.run_id || ""),
|
|
1351
|
+
ItemId: a,
|
|
1352
|
+
...n ? { PartId: n } : {},
|
|
1353
|
+
Operation: t,
|
|
1354
|
+
SourceEventId: String(e.event_id || ""),
|
|
1355
|
+
...i && i !== a ? { SourceItemId: i } : {}
|
|
1356
|
+
} };
|
|
1357
|
+
}
|
|
1358
|
+
var $e = class {
|
|
1359
|
+
textByPart = /* @__PURE__ */ new Map();
|
|
1360
|
+
toolNameByCallId = /* @__PURE__ */ new Map();
|
|
1361
|
+
toolCallByItemId = /* @__PURE__ */ new Map();
|
|
1362
|
+
toolResultByItemId = /* @__PURE__ */ new Map();
|
|
1363
|
+
sessionId;
|
|
1364
|
+
constructor(e) {
|
|
1365
|
+
this.sessionId = e;
|
|
1366
|
+
}
|
|
1367
|
+
translate(e) {
|
|
1368
|
+
if (!B(e)) return null;
|
|
1369
|
+
let t = Number(e.seq);
|
|
1370
|
+
if (!Number.isFinite(t) || t <= 0) return null;
|
|
1371
|
+
let n = String(e.family || ""), r = String(e.event_type || ""), i = String(e.run_id || ""), a = () => ({
|
|
1372
|
+
EventId: e.event_id ? String(e.event_id) : `kernel-${t}`,
|
|
1373
|
+
SessionId: this.sessionId,
|
|
1374
|
+
InvocationId: i || void 0,
|
|
1375
|
+
SeqId: t
|
|
1376
|
+
});
|
|
1377
|
+
if (n === "interaction") return {
|
|
1378
|
+
...a(),
|
|
1379
|
+
EventType: r,
|
|
1380
|
+
payload: e
|
|
1381
|
+
};
|
|
1382
|
+
if (n === "control") {
|
|
1383
|
+
if (r === "control.command_rejected") return {
|
|
1384
|
+
...a(),
|
|
1385
|
+
EventType: r,
|
|
1386
|
+
Content: e
|
|
1387
|
+
};
|
|
1388
|
+
if (r === "control.run_transition") {
|
|
1389
|
+
let t = String(e.state || "").toLowerCase();
|
|
1390
|
+
if (Ge.has(t)) return {
|
|
1391
|
+
...a(),
|
|
1392
|
+
EventType: "run_status",
|
|
1393
|
+
Content: { status: t }
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
return null;
|
|
1397
|
+
}
|
|
1398
|
+
if (n !== "runtime") return null;
|
|
1399
|
+
let o = We[r];
|
|
1400
|
+
if (o) return {
|
|
1401
|
+
...a(),
|
|
1402
|
+
EventType: "run_status",
|
|
1403
|
+
Content: { status: o }
|
|
1404
|
+
};
|
|
1405
|
+
let s = Ke(e);
|
|
1406
|
+
if (r === "item.started") {
|
|
1407
|
+
let t = V(e, "initial");
|
|
1408
|
+
if (e.item_kind === "tool_call") {
|
|
1409
|
+
let n = Ze(t), r = n?.callId || String(e.item_id || ""), o = n?.name || "tool";
|
|
1410
|
+
return r && this.toolNameByCallId.set(r, o), e.item_id && this.toolCallByItemId.set(String(e.item_id), {
|
|
1411
|
+
callId: r,
|
|
1412
|
+
name: o
|
|
1413
|
+
}), {
|
|
1414
|
+
...a(),
|
|
1415
|
+
EventType: "tool_call",
|
|
1416
|
+
Metadata: {
|
|
1417
|
+
...W(e, "replace", void 0, r),
|
|
1418
|
+
call_id: r,
|
|
1419
|
+
tool_name: o,
|
|
1420
|
+
run_id: i,
|
|
1421
|
+
tool_args: n?.arguments ?? U(t)
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
return e.item_kind === "tool_result" || s === "userMessage" || Je(t) || s === "reasoning" || e.item_kind === "reasoning" ? null : s === "agentMessage" || !s && e.item_kind === "message" ? {
|
|
1426
|
+
...a(),
|
|
1427
|
+
EventType: "assistant_stream_snapshot",
|
|
1428
|
+
Content: { parts: [{ text: "" }] },
|
|
1429
|
+
Metadata: W(e, "replace")
|
|
1430
|
+
} : s && s !== "notification" ? {
|
|
1431
|
+
...a(),
|
|
1432
|
+
EventType: "tool_call",
|
|
1433
|
+
Metadata: {
|
|
1434
|
+
...W(e, "replace"),
|
|
1435
|
+
call_id: String(e.item_id || ""),
|
|
1436
|
+
tool_name: s,
|
|
1437
|
+
run_id: i,
|
|
1438
|
+
tool_args: U(t)
|
|
1439
|
+
}
|
|
1440
|
+
} : null;
|
|
1441
|
+
}
|
|
1442
|
+
if (r === "item.updated") {
|
|
1443
|
+
let n = V(e, "update");
|
|
1444
|
+
if (e.item_kind === "tool_call") {
|
|
1445
|
+
let t = Qe(n);
|
|
1446
|
+
if (!t) return null;
|
|
1447
|
+
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;
|
|
1448
|
+
return e.item_id && this.toolResultByItemId.set(String(e.item_id), c), {
|
|
1449
|
+
...a(),
|
|
1450
|
+
EventType: "tool_result",
|
|
1451
|
+
Metadata: {
|
|
1452
|
+
...W(e, "completed", void 0, o),
|
|
1453
|
+
call_id: o,
|
|
1454
|
+
tool_name: s,
|
|
1455
|
+
run_id: i,
|
|
1456
|
+
tool_output: c
|
|
1457
|
+
}
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
let r = B(n[0]), o = String(r?.part_id || e.item_id || t), c = String(e.op || "replace"), l = H(n), u = this.textByPart.get(o) || "", d = c === "append" ? u + l : l;
|
|
1461
|
+
return this.textByPart.set(o, d), s === "agentMessage" || !s && e.item_kind === "message" ? {
|
|
1462
|
+
...a(),
|
|
1463
|
+
EventType: "assistant_stream_snapshot",
|
|
1464
|
+
Content: { parts: [{ text: d }] },
|
|
1465
|
+
Metadata: W(e, "replace", o)
|
|
1466
|
+
} : s === "reasoning" || e.item_kind === "reasoning" ? {
|
|
1467
|
+
...a(),
|
|
1468
|
+
EventType: "reasoning",
|
|
1469
|
+
Content: { parts: [{ text: l }] },
|
|
1470
|
+
Metadata: W(e, c === "append" ? "append" : "replace", o)
|
|
1471
|
+
} : null;
|
|
1472
|
+
}
|
|
1473
|
+
if (r === "item.snapshot_replaced") {
|
|
1474
|
+
let n = V(e, "snapshot"), r = String(B(n[0])?.part_id || e.item_id || t), i = H(n);
|
|
1475
|
+
return this.textByPart.set(r, i), s === "agentMessage" || !s && e.item_kind === "message" ? {
|
|
1476
|
+
...a(),
|
|
1477
|
+
EventType: "assistant_stream_snapshot",
|
|
1478
|
+
Content: { parts: [{ text: i }] },
|
|
1479
|
+
Metadata: W(e, "replace", r)
|
|
1480
|
+
} : s === "reasoning" || e.item_kind === "reasoning" ? {
|
|
1481
|
+
...a(),
|
|
1482
|
+
EventType: "reasoning",
|
|
1483
|
+
Content: { parts: [{ text: i }] },
|
|
1484
|
+
Metadata: W(e, "replace", r)
|
|
1485
|
+
} : null;
|
|
1486
|
+
}
|
|
1487
|
+
if (r === "item.completed") {
|
|
1488
|
+
let n = V(e, "snapshot");
|
|
1489
|
+
if (e.item_kind === "tool_call") {
|
|
1490
|
+
let t = Ze(n), r = Qe(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";
|
|
1491
|
+
if (s && this.toolNameByCallId.set(s, c), r) {
|
|
1492
|
+
let t = r.isError ? { error: r.result } : r.result;
|
|
1493
|
+
return {
|
|
1494
|
+
...a(),
|
|
1495
|
+
EventType: "tool_result",
|
|
1496
|
+
Metadata: {
|
|
1497
|
+
...W(e, "completed", void 0, s),
|
|
1498
|
+
call_id: s,
|
|
1499
|
+
tool_name: c,
|
|
1500
|
+
run_id: i,
|
|
1501
|
+
tool_output: t
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
return {
|
|
1506
|
+
...a(),
|
|
1507
|
+
EventType: "tool_call",
|
|
1508
|
+
Metadata: {
|
|
1509
|
+
...W(e, "replace", void 0, s),
|
|
1510
|
+
call_id: s,
|
|
1511
|
+
tool_name: c,
|
|
1512
|
+
run_id: i,
|
|
1513
|
+
tool_args: t?.arguments ?? U(n)
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
if (e.item_kind === "tool_result") {
|
|
1518
|
+
let t = Qe(n), r = t?.callId || String(e.item_id || ""), o = this.toolNameByCallId.get(r) || s || "tool", c = t?.isError ? { error: t.result } : t?.result ?? U(n);
|
|
1519
|
+
return {
|
|
1520
|
+
...a(),
|
|
1521
|
+
EventType: "tool_result",
|
|
1522
|
+
Metadata: {
|
|
1523
|
+
...W(e, "completed", void 0, r),
|
|
1524
|
+
call_id: r,
|
|
1525
|
+
tool_name: o,
|
|
1526
|
+
run_id: i,
|
|
1527
|
+
tool_output: c
|
|
1528
|
+
}
|
|
1529
|
+
};
|
|
1530
|
+
}
|
|
1531
|
+
if (s === "userMessage" || Je(n)) return {
|
|
1532
|
+
...a(),
|
|
1533
|
+
EventType: "user_message",
|
|
1534
|
+
Content: { parts: [{ text: H(n) }] }
|
|
1535
|
+
};
|
|
1536
|
+
if (s === "agentMessage" || !s && e.item_kind === "message") {
|
|
1537
|
+
let r = H(n), i = String(B(n[0])?.part_id || e.item_id || t);
|
|
1538
|
+
return this.textByPart.set(i, r), {
|
|
1539
|
+
...a(),
|
|
1540
|
+
EventType: "assistant_message",
|
|
1541
|
+
Content: { parts: [{ text: r }] },
|
|
1542
|
+
Metadata: W(e, "completed", i)
|
|
1543
|
+
};
|
|
1544
|
+
}
|
|
1545
|
+
if (s === "reasoning" || e.item_kind === "reasoning") {
|
|
1546
|
+
let r = String(B(n[0])?.part_id || e.item_id || t);
|
|
1547
|
+
return {
|
|
1548
|
+
...a(),
|
|
1549
|
+
EventType: "reasoning",
|
|
1550
|
+
Content: { parts: [{ text: H(n) }] },
|
|
1551
|
+
Metadata: W(e, "completed", r)
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
return s && s !== "notification" ? {
|
|
1555
|
+
...a(),
|
|
1556
|
+
EventType: "tool_result",
|
|
1557
|
+
Metadata: {
|
|
1558
|
+
...W(e, "completed"),
|
|
1559
|
+
call_id: String(e.item_id || ""),
|
|
1560
|
+
tool_name: s,
|
|
1561
|
+
run_id: i,
|
|
1562
|
+
tool_output: U(n)
|
|
1563
|
+
}
|
|
1564
|
+
} : null;
|
|
1565
|
+
}
|
|
1566
|
+
if (r === "item.failed") {
|
|
1567
|
+
if (e.item_kind === "tool_call") {
|
|
1568
|
+
let t = this.toolCallByItemId.get(String(e.item_id || "")), n = t?.callId || String(e.item_id || ""), r = t?.name || this.toolNameByCallId.get(n) || "tool", o = this.toolResultByItemId.get(String(e.item_id || ""));
|
|
1569
|
+
return {
|
|
1570
|
+
...a(),
|
|
1571
|
+
EventType: "tool_result",
|
|
1572
|
+
Metadata: {
|
|
1573
|
+
...W(e, "completed", void 0, n),
|
|
1574
|
+
call_id: n,
|
|
1575
|
+
tool_name: r,
|
|
1576
|
+
run_id: i,
|
|
1577
|
+
tool_output: o ?? { error: B(e.error) || e.error || "item failed" }
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
return s && s !== "notification" && s !== "agentMessage" && s !== "reasoning" ? {
|
|
1582
|
+
...a(),
|
|
1583
|
+
EventType: "tool_result",
|
|
1584
|
+
Metadata: {
|
|
1585
|
+
...W(e, "completed"),
|
|
1586
|
+
call_id: String(e.item_id || ""),
|
|
1587
|
+
tool_name: s,
|
|
1588
|
+
run_id: i,
|
|
1589
|
+
tool_output: { error: B(e.error) || e.error || "item failed" }
|
|
1590
|
+
}
|
|
1591
|
+
} : null;
|
|
1592
|
+
}
|
|
1593
|
+
return null;
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
async function et(e) {
|
|
1597
|
+
let t = e.getReader(), n = new TextDecoder(), r = "", i = null, a = !1, o = (e) => e.includes("data:") || e.includes("event:") || e.includes(":");
|
|
1598
|
+
try {
|
|
1599
|
+
for (;;) {
|
|
1600
|
+
let { value: e, done: s } = await t.read();
|
|
1601
|
+
if (e && (r += n.decode(e, { stream: !0 })), s) {
|
|
1602
|
+
a = !0;
|
|
1603
|
+
break;
|
|
1604
|
+
}
|
|
1605
|
+
if (r.trimStart().startsWith("{")) {
|
|
1606
|
+
if (tt(r)) {
|
|
1607
|
+
i = nt(r);
|
|
1608
|
+
break;
|
|
1609
|
+
}
|
|
1610
|
+
} else if (o(r)) break;
|
|
1611
|
+
}
|
|
1612
|
+
} catch (e) {
|
|
1613
|
+
throw t.releaseLock(), e;
|
|
1614
|
+
}
|
|
1615
|
+
let s = new TextEncoder().encode(r), c = new ReadableStream({
|
|
1616
|
+
start(e) {
|
|
1617
|
+
if (s.length > 0 && e.enqueue(s), a || i) {
|
|
1618
|
+
e.close();
|
|
1619
|
+
return;
|
|
1620
|
+
}
|
|
1621
|
+
let n = () => t.read().then(({ value: t, done: r }) => {
|
|
1622
|
+
if (t && e.enqueue(t), r) {
|
|
1623
|
+
e.close();
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1626
|
+
return n();
|
|
1627
|
+
}).catch((t) => {
|
|
1628
|
+
try {
|
|
1629
|
+
e.error(t);
|
|
1630
|
+
} catch {}
|
|
1631
|
+
});
|
|
1632
|
+
n();
|
|
1633
|
+
},
|
|
1634
|
+
cancel() {
|
|
1635
|
+
t.cancel().catch(() => {});
|
|
1636
|
+
}
|
|
1637
|
+
});
|
|
1638
|
+
return {
|
|
1639
|
+
receipt: i,
|
|
1640
|
+
stream: c
|
|
1641
|
+
};
|
|
1642
|
+
}
|
|
1643
|
+
function tt(e) {
|
|
1644
|
+
let t = e.trim();
|
|
1645
|
+
if (!t.endsWith("}")) return !1;
|
|
1646
|
+
let n = 0, r = !1, i = !1;
|
|
1647
|
+
for (let e of t) {
|
|
1648
|
+
if (i) {
|
|
1649
|
+
i = !1;
|
|
1650
|
+
continue;
|
|
1651
|
+
}
|
|
1652
|
+
if (e === "\\") {
|
|
1653
|
+
i = !0;
|
|
1654
|
+
continue;
|
|
1655
|
+
}
|
|
1656
|
+
e === "\"" && (r = !r), !r && ((e === "{" || e === "[") && (n += 1), (e === "}" || e === "]") && --n);
|
|
1657
|
+
}
|
|
1658
|
+
return n === 0;
|
|
1659
|
+
}
|
|
1660
|
+
function nt(e) {
|
|
1661
|
+
try {
|
|
1662
|
+
let t = B(JSON.parse(e).Data), n = String(t?.ReceiptStatus || "");
|
|
1663
|
+
if (!n) return null;
|
|
1664
|
+
let r = B(t?.Error);
|
|
1665
|
+
return {
|
|
1666
|
+
status: n,
|
|
1667
|
+
presentationProfile: t?.PresentationProfile === "agent-block-v1" ? "agent-block-v1" : "flat-v1",
|
|
1668
|
+
commandId: t?.CommandId ?? null,
|
|
1669
|
+
messageId: t?.MessageId ?? null,
|
|
1670
|
+
runId: t?.RunId ?? null,
|
|
1671
|
+
acceptedSeq: t?.AcceptedSeq ?? null,
|
|
1672
|
+
error: r ? {
|
|
1673
|
+
code: String(r.code || ""),
|
|
1674
|
+
message: String(r.message || "")
|
|
1675
|
+
} : null
|
|
1676
|
+
};
|
|
1677
|
+
} catch {
|
|
1678
|
+
return null;
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
//#endregion
|
|
1682
|
+
//#region src/utils/responses-stream.js
|
|
1683
|
+
function rt() {
|
|
1684
|
+
return {
|
|
1685
|
+
toolNames: /* @__PURE__ */ new Map(),
|
|
1686
|
+
toolArguments: /* @__PURE__ */ new Map(),
|
|
1687
|
+
callIds: /* @__PURE__ */ new Map(),
|
|
1688
|
+
currentResponseId: "",
|
|
1689
|
+
sawTextDelta: !1,
|
|
1690
|
+
sawReasoningDelta: !1
|
|
1691
|
+
};
|
|
1692
|
+
}
|
|
1693
|
+
function it(e) {
|
|
1694
|
+
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 : "";
|
|
1695
|
+
}
|
|
1696
|
+
function G(e) {
|
|
1697
|
+
return e == null ? "" : typeof e == "string" ? e : typeof e == "object" ? JSON.stringify(e, null, 2) : String(e);
|
|
1698
|
+
}
|
|
1699
|
+
function K(...e) {
|
|
1700
|
+
for (let t of e) {
|
|
1701
|
+
let e = it(t);
|
|
1702
|
+
if (e) return e;
|
|
1703
|
+
}
|
|
1704
|
+
return "";
|
|
1705
|
+
}
|
|
1706
|
+
function at(e, t) {
|
|
1707
|
+
return String(e?.id || e?.item_id || e?.call_id || t?.item_id || t?.call_id || t?.output_index || "");
|
|
1708
|
+
}
|
|
1709
|
+
function ot(e, t, n, r, i) {
|
|
1710
|
+
t && (e.toolNames.set(t, r), e.toolArguments.set(t, i));
|
|
1711
|
+
let a = String(n?.call_id || "");
|
|
1712
|
+
a && (e.callIds.set(a, t || r), e.toolNames.set(a, r), e.toolArguments.set(a, i));
|
|
1713
|
+
}
|
|
1714
|
+
function q(e, t, n, r = "tool") {
|
|
1715
|
+
let i = String(n?.call_id || "");
|
|
1716
|
+
return String(n?.name || n?.tool_name || (t ? e.toolNames.get(t) : "") || (i ? e.toolNames.get(i) : "") || r);
|
|
1717
|
+
}
|
|
1718
|
+
function st(e) {
|
|
1719
|
+
if (!e || typeof e != "object") return "";
|
|
1720
|
+
let t = it(e.content);
|
|
1721
|
+
return K(e.output_text, e.text, e.summary_text, e.summary, e.delta, t);
|
|
1722
|
+
}
|
|
1723
|
+
function ct(e) {
|
|
1724
|
+
let t = e?.response && typeof e.response == "object" ? e.response : e, n = K(t?.output_text, t?.text);
|
|
1725
|
+
if (n) return n;
|
|
1726
|
+
let r = Array.isArray(t?.output) ? t.output : [];
|
|
1727
|
+
for (let e of r) {
|
|
1728
|
+
let t = st(e);
|
|
1729
|
+
if (t) return t;
|
|
1730
|
+
}
|
|
1731
|
+
return "";
|
|
1732
|
+
}
|
|
1733
|
+
function lt(e) {
|
|
1734
|
+
let t = e?.response && typeof e.response == "object" ? e.response : e;
|
|
1735
|
+
return Array.isArray(t?.output) ? t.output : [];
|
|
1736
|
+
}
|
|
1737
|
+
function ut(e) {
|
|
1738
|
+
let t = e;
|
|
1739
|
+
if (typeof t == "string") try {
|
|
1740
|
+
t = JSON.parse(t);
|
|
1741
|
+
} catch {
|
|
1742
|
+
return {};
|
|
1743
|
+
}
|
|
1744
|
+
return Array.isArray(t) && (t = t[0] || {}), !t || typeof t != "object" ? {} : t.value && typeof t.value == "object" && !Array.isArray(t.value) ? {
|
|
1745
|
+
...t.value,
|
|
1746
|
+
approval_request_id: t.value.approval_request_id || t.value.id || t.id
|
|
1747
|
+
} : t;
|
|
1748
|
+
}
|
|
1749
|
+
function dt({ data: e, state: t, status: n }) {
|
|
1750
|
+
let r = e?.item || e?.output_item || e || {}, i = String(r.type || "").trim(), a = at(r, e);
|
|
1751
|
+
if (i === "function_call") {
|
|
1752
|
+
let e = q(t, a, r), i = G(r.arguments ?? r.args ?? r.input);
|
|
1753
|
+
return ot(t, a, r, e, i), [{
|
|
1754
|
+
type: "tool_upsert",
|
|
1755
|
+
name: e,
|
|
1756
|
+
args: i,
|
|
1757
|
+
status: n
|
|
1758
|
+
}];
|
|
1759
|
+
}
|
|
1760
|
+
if (i === "function_call_output") return [{
|
|
1761
|
+
type: "tool_result",
|
|
1762
|
+
name: q(t, a, r),
|
|
1763
|
+
output: G(r.output ?? r.result ?? r.content)
|
|
1764
|
+
}];
|
|
1765
|
+
if (i === "mcp_approval_request") {
|
|
1766
|
+
let n = String(r.name || "approval"), i = G(r.arguments ?? r.args), a = String(r.id || r.approval_request_id || ""), o = String(r.run_id || r.runId || e?.run_id || e?.runId || "");
|
|
1767
|
+
return [{
|
|
1768
|
+
type: "tool_upsert",
|
|
1769
|
+
name: n,
|
|
1770
|
+
args: i,
|
|
1771
|
+
status: "paused",
|
|
1772
|
+
approvalRequestId: a,
|
|
1773
|
+
previousResponseId: String(e?.response_id || t.currentResponseId || ""),
|
|
1774
|
+
serverLabel: String(r.server_label || "")
|
|
1775
|
+
}, {
|
|
1776
|
+
type: "approval_request",
|
|
1777
|
+
approvalRequestId: a,
|
|
1778
|
+
previousResponseId: String(e?.response_id || t.currentResponseId || ""),
|
|
1779
|
+
...o ? { runId: o } : {},
|
|
1780
|
+
name: n,
|
|
1781
|
+
args: i
|
|
1782
|
+
}];
|
|
1783
|
+
}
|
|
1784
|
+
if (i === "reasoning" || i === "reasoning_summary" || i === "reasoning_summary_text") {
|
|
1785
|
+
let e = st(r);
|
|
1786
|
+
return e ? [{
|
|
1787
|
+
type: "reasoning_delta",
|
|
1788
|
+
text: e
|
|
1789
|
+
}] : [];
|
|
1790
|
+
}
|
|
1791
|
+
if (i === "message") {
|
|
1792
|
+
let e = st(r);
|
|
1793
|
+
return e ? [{
|
|
1794
|
+
type: n === "completed" ? "text_final" : "text_delta",
|
|
1795
|
+
text: e
|
|
1796
|
+
}] : [];
|
|
1797
|
+
}
|
|
1798
|
+
return [];
|
|
1799
|
+
}
|
|
1800
|
+
function ft({ eventName: e, data: t, state: n }) {
|
|
1801
|
+
let r = String(t?.type || e || "").trim(), i = String(t?.id || t?.response?.id || t?.response_id || "");
|
|
1802
|
+
if (i.startsWith("resp_") && (n.currentResponseId = i), r === "response.tool_call") return [{
|
|
1803
|
+
type: "tool_upsert",
|
|
1804
|
+
name: String(t?.name || t?.tool_name || "tool"),
|
|
1805
|
+
args: G(t?.args ?? t?.arguments),
|
|
1806
|
+
status: "running"
|
|
1807
|
+
}];
|
|
1808
|
+
if (r === "response.tool_result" || r === "response.ksadk.tool_result") return [{
|
|
1809
|
+
type: "tool_result",
|
|
1810
|
+
name: String(t?.name || t?.tool_name || "tool"),
|
|
1811
|
+
output: G(t?.output ?? t?.result)
|
|
1812
|
+
}];
|
|
1813
|
+
if (r === "response.output_item.added") return dt({
|
|
1814
|
+
data: t,
|
|
1815
|
+
state: n,
|
|
1816
|
+
status: "running"
|
|
1817
|
+
});
|
|
1818
|
+
if (r === "response.output_item.done") return dt({
|
|
1819
|
+
data: t,
|
|
1820
|
+
state: n,
|
|
1821
|
+
status: "completed"
|
|
1822
|
+
});
|
|
1823
|
+
if (r === "response.function_call_arguments.delta") {
|
|
1824
|
+
let e = String(t?.item_id || t?.call_id || ""), r = q(n, e, t), i = `${n.toolArguments.get(e) || ""}${String(t?.delta || "")}`;
|
|
1825
|
+
return n.toolArguments.set(e, i), [{
|
|
1826
|
+
type: "tool_upsert",
|
|
1827
|
+
name: r,
|
|
1828
|
+
args: i,
|
|
1829
|
+
status: "running"
|
|
1830
|
+
}];
|
|
1831
|
+
}
|
|
1832
|
+
if (r === "response.function_call_arguments.done") {
|
|
1833
|
+
let e = String(t?.item_id || t?.call_id || ""), r = q(n, e, t), i = G(t?.arguments ?? n.toolArguments.get(e));
|
|
1834
|
+
return n.toolArguments.set(e, i), [{
|
|
1835
|
+
type: "tool_upsert",
|
|
1836
|
+
name: r,
|
|
1837
|
+
args: i,
|
|
1838
|
+
status: "running"
|
|
1839
|
+
}];
|
|
1840
|
+
}
|
|
1841
|
+
if (r === "response.reasoning.delta" || r === "response.reasoning_text.delta" || r === "response.reasoning_summary.delta" || r === "response.reasoning_summary_text.delta") {
|
|
1842
|
+
let e = K(t?.delta, t?.text);
|
|
1843
|
+
return e && (n.sawReasoningDelta = !0), e ? [{
|
|
1844
|
+
type: "reasoning_delta",
|
|
1845
|
+
text: e
|
|
1846
|
+
}] : [];
|
|
1847
|
+
}
|
|
1848
|
+
if (r === "response.output_text.delta") {
|
|
1849
|
+
let e = K(t?.delta, t?.text);
|
|
1850
|
+
return e && (n.sawTextDelta = !0), e ? [{
|
|
1851
|
+
type: "text_delta",
|
|
1852
|
+
text: e
|
|
1853
|
+
}] : [];
|
|
1854
|
+
}
|
|
1855
|
+
if (r === "response.output_text.done") {
|
|
1856
|
+
let e = K(t?.text, t?.delta);
|
|
1857
|
+
return e ? [{
|
|
1858
|
+
type: "text_final",
|
|
1859
|
+
text: e
|
|
1860
|
+
}] : [];
|
|
1861
|
+
}
|
|
1862
|
+
if (r === "response.content_part.delta") {
|
|
1863
|
+
let e = String(t?.part?.type || t?.delta?.type || t?.content_type || ""), r = K(t?.delta?.text, t?.delta, t?.text);
|
|
1864
|
+
return r ? e.includes("reasoning") ? (n.sawReasoningDelta = !0, [{
|
|
1865
|
+
type: "reasoning_delta",
|
|
1866
|
+
text: r
|
|
1867
|
+
}]) : (n.sawTextDelta = !0, [{
|
|
1868
|
+
type: "text_delta",
|
|
1869
|
+
text: r
|
|
1870
|
+
}]) : [];
|
|
1871
|
+
}
|
|
1872
|
+
if (r === "response.completed") {
|
|
1873
|
+
let e = ct(t), r = lt(t).flatMap((e) => dt({
|
|
1874
|
+
data: {
|
|
1875
|
+
...t,
|
|
1876
|
+
item: e
|
|
1877
|
+
},
|
|
1878
|
+
state: n,
|
|
1879
|
+
status: "completed"
|
|
1880
|
+
})).filter((e) => !(n.sawTextDelta && e.type === "text_final") && !(n.sawReasoningDelta && e.type === "reasoning_delta")), i = r.some((e) => e.type === "text_final");
|
|
1881
|
+
return [
|
|
1882
|
+
...r,
|
|
1883
|
+
...e && !n.sawTextDelta && !i ? [{
|
|
1884
|
+
type: "text_final",
|
|
1885
|
+
text: e
|
|
1886
|
+
}] : [],
|
|
1887
|
+
{
|
|
1888
|
+
type: "terminal",
|
|
1889
|
+
status: "completed"
|
|
1890
|
+
}
|
|
1891
|
+
];
|
|
1892
|
+
}
|
|
1893
|
+
if (r === "response.failed") return [{
|
|
1894
|
+
type: "failed",
|
|
1895
|
+
message: t?.error?.message || "Agent 运行失败"
|
|
1896
|
+
}, {
|
|
1897
|
+
type: "terminal",
|
|
1898
|
+
status: "failed"
|
|
1899
|
+
}];
|
|
1900
|
+
if (r === "response.incomplete") return [{ type: "incomplete" }, {
|
|
1901
|
+
type: "terminal",
|
|
1902
|
+
status: "incomplete"
|
|
1903
|
+
}];
|
|
1904
|
+
if (r === "response.cancelled") return [{
|
|
1905
|
+
type: "terminal",
|
|
1906
|
+
status: "cancelled"
|
|
1907
|
+
}];
|
|
1908
|
+
if (r === "response.approval_request" || r === "response.ksadk.approval_request") {
|
|
1909
|
+
let e = ut(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 : [];
|
|
1910
|
+
if (s.length > 0) {
|
|
1911
|
+
let e = s.map((e) => ({
|
|
1912
|
+
type: "tool_upsert",
|
|
1913
|
+
name: String(e?.name || "tool"),
|
|
1914
|
+
args: JSON.stringify(e?.args ?? {}),
|
|
1915
|
+
status: "paused",
|
|
1916
|
+
approvalRequestId: r,
|
|
1917
|
+
previousResponseId: i
|
|
1918
|
+
})), t = s[0] || {};
|
|
1919
|
+
return [...e, {
|
|
1920
|
+
type: "approval_request",
|
|
1921
|
+
approvalRequestId: r,
|
|
1922
|
+
previousResponseId: i,
|
|
1923
|
+
...a ? { runId: a } : {},
|
|
1924
|
+
name: String(t?.name || "人工确认"),
|
|
1925
|
+
args: JSON.stringify(t?.args ?? {})
|
|
1926
|
+
}];
|
|
1927
|
+
}
|
|
1928
|
+
return [{
|
|
1929
|
+
type: "approval_request",
|
|
1930
|
+
approvalRequestId: r,
|
|
1931
|
+
previousResponseId: i,
|
|
1932
|
+
...a ? { runId: a } : {}
|
|
1933
|
+
}];
|
|
1934
|
+
}
|
|
1935
|
+
if (r === "response.approval_resolved" || r === "response.ksadk.approval_resolved") {
|
|
1936
|
+
let e = String(t?.decision || t?.outcome || "").toLowerCase(), n = e === "reject" || e === "rejected" || e === "denied" ? "rejected" : e === "cancel" || e === "cancelled" || e === "canceled" ? "cancelled" : "approved";
|
|
1937
|
+
return [{
|
|
1938
|
+
type: "approval_resolved",
|
|
1939
|
+
approvalRequestId: String(t?.approval_request_id || t?.approvalRequestId || t?.approval_id || t?.approvalId || ""),
|
|
1940
|
+
decision: n,
|
|
1941
|
+
revision: Number(t?.revision || 2)
|
|
1942
|
+
}];
|
|
1943
|
+
}
|
|
1944
|
+
if (new Set([
|
|
1945
|
+
"response.ksadk.a2ui_surface_begin",
|
|
1946
|
+
"a2ui.surface.begin",
|
|
1947
|
+
"response.a2ui.createSurface",
|
|
1948
|
+
"a2ui.createSurface",
|
|
1949
|
+
"createSurface"
|
|
1950
|
+
]).has(r)) {
|
|
1951
|
+
let e = t?.surface && typeof t.surface == "object" ? t.surface : {};
|
|
1952
|
+
return [{
|
|
1953
|
+
type: "a2ui_surface_begin",
|
|
1954
|
+
surfaceId: String(t?.surface_id || t?.surfaceId || e.surface_id || e.surfaceId || ""),
|
|
1955
|
+
surface: e
|
|
1956
|
+
}];
|
|
1957
|
+
}
|
|
1958
|
+
if (new Set([
|
|
1959
|
+
"response.ksadk.a2ui_surface_update",
|
|
1960
|
+
"a2ui.surface.update",
|
|
1961
|
+
"response.a2ui.updateComponents",
|
|
1962
|
+
"a2ui.updateComponents",
|
|
1963
|
+
"updateComponents"
|
|
1964
|
+
]).has(r)) {
|
|
1965
|
+
let e = t?.surface && typeof t.surface == "object" ? t.surface : {};
|
|
1966
|
+
return [{
|
|
1967
|
+
type: "a2ui_surface_update",
|
|
1968
|
+
surfaceId: String(t?.surface_id || t?.surfaceId || e.surface_id || e.surfaceId || ""),
|
|
1969
|
+
surface: e
|
|
1970
|
+
}];
|
|
1971
|
+
}
|
|
1972
|
+
if (new Set([
|
|
1973
|
+
"response.ksadk.a2ui_surface_end",
|
|
1974
|
+
"a2ui.surface.end",
|
|
1975
|
+
"response.a2ui.deleteSurface",
|
|
1976
|
+
"a2ui.deleteSurface",
|
|
1977
|
+
"deleteSurface"
|
|
1978
|
+
]).has(r)) return [{
|
|
1979
|
+
type: "a2ui_surface_end",
|
|
1980
|
+
surfaceId: String(t?.surface_id || t?.surfaceId || "")
|
|
1981
|
+
}];
|
|
1982
|
+
if (new Set(["response.ksadk.a2ui_interaction", "a2ui.interaction"]).has(r)) return [{
|
|
1983
|
+
type: "a2ui_interaction",
|
|
1984
|
+
surfaceId: String(t?.surface_id || t?.surfaceId || ""),
|
|
1985
|
+
interactionId: String(t?.interaction_id || t?.interactionId || ""),
|
|
1986
|
+
kind: String(t?.kind || "input"),
|
|
1987
|
+
inputSchema: t?.input_schema && typeof t.input_schema == "object" ? t.input_schema : {}
|
|
1988
|
+
}];
|
|
1989
|
+
let a = t?.content?.parts?.[0]?.text;
|
|
1990
|
+
return a && !t?.actions?.finishReason ? [{
|
|
1991
|
+
type: "text_delta",
|
|
1992
|
+
text: String(a)
|
|
1993
|
+
}] : [];
|
|
1994
|
+
}
|
|
1995
|
+
//#endregion
|
|
1996
|
+
//#region src/utils/session-events.js
|
|
1997
|
+
var pt = new Set([
|
|
1998
|
+
"completed",
|
|
1999
|
+
"failed",
|
|
2000
|
+
"error",
|
|
2001
|
+
"cancelled",
|
|
2002
|
+
"canceled",
|
|
2003
|
+
"aborted",
|
|
2004
|
+
"interrupted",
|
|
2005
|
+
"resume_failed"
|
|
2006
|
+
]), mt = new Set([
|
|
2007
|
+
"tool_call",
|
|
2008
|
+
"tool_result",
|
|
2009
|
+
"stage_tool_call",
|
|
2010
|
+
"stage_tool_result"
|
|
2011
|
+
]), ht = {
|
|
2012
|
+
"run.started": "in_progress",
|
|
2013
|
+
"run.progress": "in_progress",
|
|
2014
|
+
"run.interrupted": "interrupted",
|
|
2015
|
+
"run.completed": "completed",
|
|
2016
|
+
"run.failed": "failed",
|
|
2017
|
+
"run.canceled": "cancelled"
|
|
2018
|
+
};
|
|
2019
|
+
function J(e) {
|
|
2020
|
+
let t = e?.Content?.payload;
|
|
2021
|
+
return t && typeof t == "object" ? t : {};
|
|
2022
|
+
}
|
|
2023
|
+
function gt(e, t) {
|
|
2024
|
+
let n = String(e || ""), r = String(t || "");
|
|
2025
|
+
return n ? !r || n.endsWith(r) ? n : r.startsWith(n) ? r : `${n}${r}` : r;
|
|
2026
|
+
}
|
|
2027
|
+
function _t(e) {
|
|
2028
|
+
let t = String(e?.EventType || ""), n = J(e);
|
|
2029
|
+
return ht[t] ? {
|
|
2030
|
+
...e,
|
|
2031
|
+
EventType: "run_status",
|
|
2032
|
+
Content: {
|
|
2033
|
+
status: String(n.status || ht[t]),
|
|
2034
|
+
...n.detail ? { detail: String(n.detail) } : {}
|
|
2035
|
+
}
|
|
2036
|
+
} : t === "reasoning.delta" || t === "reasoning.completed" ? {
|
|
2037
|
+
...e,
|
|
2038
|
+
EventType: "reasoning",
|
|
2039
|
+
Content: {
|
|
2040
|
+
role: "model",
|
|
2041
|
+
parts: [{ text: String(n.text || "") }]
|
|
2042
|
+
}
|
|
2043
|
+
} : t === "tool.call.begin" ? {
|
|
2044
|
+
...e,
|
|
2045
|
+
EventType: "tool_call",
|
|
2046
|
+
Metadata: {
|
|
2047
|
+
...e.Metadata || {},
|
|
2048
|
+
tool_name: n.name,
|
|
2049
|
+
tool_args: n.args,
|
|
2050
|
+
tool_call_id: n.call_id
|
|
2051
|
+
},
|
|
2052
|
+
Content: {
|
|
2053
|
+
role: "model",
|
|
2054
|
+
parts: []
|
|
2055
|
+
}
|
|
2056
|
+
} : t === "tool.call.end" ? {
|
|
2057
|
+
...e,
|
|
2058
|
+
EventType: "tool_result",
|
|
2059
|
+
Metadata: {
|
|
2060
|
+
...e.Metadata || {},
|
|
2061
|
+
tool_name: n.name,
|
|
2062
|
+
tool_output: n.error || n.result,
|
|
2063
|
+
tool_call_id: n.call_id
|
|
2064
|
+
},
|
|
2065
|
+
Content: {
|
|
2066
|
+
role: "model",
|
|
2067
|
+
parts: []
|
|
2068
|
+
}
|
|
2069
|
+
} : e;
|
|
2070
|
+
}
|
|
2071
|
+
function vt(e) {
|
|
2072
|
+
let t = [], n = /* @__PURE__ */ new Map();
|
|
2073
|
+
for (let r of Array.isArray(e) ? e : []) {
|
|
2074
|
+
let e = String(r?.EventType || "");
|
|
2075
|
+
if (e === "text.delta" || e === "text.completed" || e === "message.delta") {
|
|
2076
|
+
let e = String(r?.InvocationId || "").trim();
|
|
2077
|
+
if (!e) continue;
|
|
2078
|
+
let t = n.get(e);
|
|
2079
|
+
n.set(e, {
|
|
2080
|
+
event: r,
|
|
2081
|
+
text: gt(t?.text, J(r).text || r?.Content?.text)
|
|
2082
|
+
});
|
|
2083
|
+
continue;
|
|
2084
|
+
}
|
|
2085
|
+
t.push(_t(r));
|
|
2086
|
+
}
|
|
2087
|
+
for (let { event: e, text: r } of n.values()) t.push({
|
|
2088
|
+
...e,
|
|
2089
|
+
EventType: "assistant_stream_snapshot",
|
|
2090
|
+
Content: {
|
|
2091
|
+
role: "model",
|
|
2092
|
+
parts: [{ text: r }]
|
|
2093
|
+
},
|
|
2094
|
+
Metadata: {
|
|
2095
|
+
...e.Metadata || {},
|
|
2096
|
+
stream_snapshot: !0
|
|
2097
|
+
}
|
|
2098
|
+
});
|
|
2099
|
+
for (let n of Array.isArray(e) ? e : []) String(n?.EventType || "") === "message.completed" && t.push({
|
|
2100
|
+
...n,
|
|
2101
|
+
EventType: "assistant_message",
|
|
2102
|
+
Content: {
|
|
2103
|
+
role: "model",
|
|
2104
|
+
parts: [{ text: String(J(n).text || n?.Content?.text || "") }]
|
|
2105
|
+
}
|
|
2106
|
+
});
|
|
2107
|
+
return t.sort((e, t) => X(e) - X(t));
|
|
2108
|
+
}
|
|
2109
|
+
function yt(e) {
|
|
2110
|
+
let t = String(e?.EventType || "").trim();
|
|
2111
|
+
if (t !== "run_status" && !t.startsWith("run.")) return "";
|
|
2112
|
+
let n = J(e);
|
|
2113
|
+
return String(e?.Content?.status || n.status || ht[t] || "").trim().toLowerCase();
|
|
2114
|
+
}
|
|
2115
|
+
function bt(e) {
|
|
2116
|
+
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("") : "";
|
|
2117
|
+
}
|
|
2118
|
+
function xt(e) {
|
|
2119
|
+
let t = String(e || "").trim();
|
|
2120
|
+
return t ? `/agentengine/api/v1/AttachmentContent?FileUri=${encodeURIComponent(t)}` : "";
|
|
2121
|
+
}
|
|
2122
|
+
function St(e) {
|
|
2123
|
+
return String(e || "").match(/^data:([^;,]+)/)?.[1] || "";
|
|
2124
|
+
}
|
|
2125
|
+
function Ct(e, t) {
|
|
2126
|
+
let n = String(e || "").trim(), r = String(t || "").trim();
|
|
2127
|
+
return !n || !r || n === r ? !0 : n.endsWith("/*") ? r.startsWith(n.slice(0, -1)) : r.endsWith("/*") ? n.startsWith(r.slice(0, -1)) : !1;
|
|
2128
|
+
}
|
|
2129
|
+
function Y(e) {
|
|
2130
|
+
let t = e?.Content?.parts || [], n = [], r = /* @__PURE__ */ new Map(), i = (e) => {
|
|
2131
|
+
let t = `${e.fileUri || e.url || e.name}|${e.type}`;
|
|
2132
|
+
r.has(t) || r.set(t, e);
|
|
2133
|
+
};
|
|
2134
|
+
for (let e of t) {
|
|
2135
|
+
if (e?.type === "input_text" || e?.text) {
|
|
2136
|
+
n.push(e.text || "");
|
|
2137
|
+
continue;
|
|
2138
|
+
}
|
|
2139
|
+
if (e?.type === "input_file" && e.inlineData) {
|
|
2140
|
+
i({
|
|
2141
|
+
name: e.inlineData.displayName || "attachment",
|
|
2142
|
+
url: `data:${e.inlineData.mimeType || "application/octet-stream"};base64,${e.inlineData.data}`,
|
|
2143
|
+
type: e.inlineData.mimeType || "application/octet-stream"
|
|
2144
|
+
});
|
|
2145
|
+
continue;
|
|
2146
|
+
}
|
|
2147
|
+
if (e?.type === "input_file" && typeof e.file_data == "string" && e.file_data) {
|
|
2148
|
+
i({
|
|
2149
|
+
name: e.filename || e.displayName || e.display_name || "attachment",
|
|
2150
|
+
url: `data:${e.mime_type || e.mimeType || "application/octet-stream"};base64,${e.file_data}`,
|
|
2151
|
+
type: e.mime_type || e.mimeType || "application/octet-stream"
|
|
2152
|
+
});
|
|
2153
|
+
continue;
|
|
2154
|
+
}
|
|
2155
|
+
if (e?.type === "input_file" && typeof e.file_url == "string" && e.file_url.trim()) {
|
|
2156
|
+
let t = e.file_url.trim();
|
|
2157
|
+
i({
|
|
2158
|
+
name: e.filename || e.displayName || e.display_name || "attachment",
|
|
2159
|
+
url: xt(t),
|
|
2160
|
+
type: e.mime_type || e.mimeType || "application/octet-stream",
|
|
2161
|
+
fileUri: t
|
|
2162
|
+
});
|
|
2163
|
+
continue;
|
|
2164
|
+
}
|
|
2165
|
+
if (e?.type === "input_image" || e?.type === "image_url") {
|
|
2166
|
+
let t = typeof e.image_url == "string" ? e.image_url : e.image_url?.url;
|
|
2167
|
+
t && i({
|
|
2168
|
+
name: e.filename || e.displayName || e.display_name || "uploaded_image",
|
|
2169
|
+
url: t,
|
|
2170
|
+
type: e.mime_type || e.mimeType || St(t) || "image/*"
|
|
2171
|
+
});
|
|
2172
|
+
continue;
|
|
2173
|
+
}
|
|
2174
|
+
if (e?.type === "input_file" && e.fileData) {
|
|
2175
|
+
let t = String(e.fileData.fileUri || "").trim();
|
|
2176
|
+
i({
|
|
2177
|
+
name: e.fileData.displayName || "attachment",
|
|
2178
|
+
url: xt(t),
|
|
2179
|
+
type: e.fileData.mimeType || "application/octet-stream",
|
|
2180
|
+
fileUri: t
|
|
2181
|
+
});
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
let a = Array.isArray(e?.Metadata?.attachments) ? e.Metadata.attachments : [];
|
|
2185
|
+
for (let e of a) {
|
|
2186
|
+
let t = String(e.file_uri || "").trim(), n = {
|
|
2187
|
+
name: e.display_name || "attachment",
|
|
2188
|
+
url: xt(t),
|
|
2189
|
+
type: e.mime_type || "application/octet-stream",
|
|
2190
|
+
fileUri: t
|
|
2191
|
+
};
|
|
2192
|
+
!n.url && !n.fileUri && Array.from(r.values()).some((e) => e.name === n.name && Ct(e.type, n.type) && (e.url || e.fileUri)) || i(n);
|
|
2193
|
+
}
|
|
2194
|
+
let o = Array.from(r.values());
|
|
2195
|
+
return {
|
|
2196
|
+
text: n.join(""),
|
|
2197
|
+
attachments: o.length > 0 ? o : void 0
|
|
2198
|
+
};
|
|
2199
|
+
}
|
|
2200
|
+
function wt(e) {
|
|
2201
|
+
let n = e?.Metadata?.responses_output;
|
|
2202
|
+
if (!Array.isArray(n)) return {};
|
|
2203
|
+
let r = rt(), i = ft({
|
|
2204
|
+
eventName: "response.completed",
|
|
2205
|
+
data: { response: {
|
|
2206
|
+
id: String(e.Metadata?.response_id || ""),
|
|
2207
|
+
output: n
|
|
2208
|
+
} },
|
|
2209
|
+
state: r
|
|
2210
|
+
}), a = "", o = {};
|
|
2211
|
+
for (let e of i) {
|
|
2212
|
+
if (e.type === "reasoning_delta") {
|
|
2213
|
+
a += e.text;
|
|
2214
|
+
continue;
|
|
2215
|
+
}
|
|
2216
|
+
if (e.type === "tool_upsert") {
|
|
2217
|
+
o[e.name] = {
|
|
2218
|
+
...o[e.name] || {
|
|
2219
|
+
name: e.name,
|
|
2220
|
+
args: ""
|
|
2221
|
+
},
|
|
2222
|
+
name: e.name,
|
|
2223
|
+
args: e.args,
|
|
2224
|
+
status: e.status,
|
|
2225
|
+
...e.approvalRequestId ? { approvalRequestId: e.approvalRequestId } : {},
|
|
2226
|
+
...e.previousResponseId ? { previousResponseId: e.previousResponseId } : {},
|
|
2227
|
+
...e.serverLabel ? { serverLabel: e.serverLabel } : {},
|
|
2228
|
+
...e.approvalRequestId ? { approvalStatus: "pending" } : {}
|
|
2229
|
+
};
|
|
2230
|
+
continue;
|
|
2231
|
+
}
|
|
2232
|
+
e.type === "tool_result" && (o[e.name] = {
|
|
2233
|
+
...o[e.name] || {
|
|
2234
|
+
name: e.name,
|
|
2235
|
+
args: ""
|
|
2236
|
+
},
|
|
2237
|
+
name: e.name,
|
|
2238
|
+
output: e.output,
|
|
2239
|
+
status: t(e.output) ? "error" : "completed"
|
|
2240
|
+
});
|
|
2241
|
+
}
|
|
2242
|
+
return {
|
|
2243
|
+
...a ? { reasoning: a } : {},
|
|
2244
|
+
...Object.keys(o).length > 0 ? { tools: o } : {}
|
|
2245
|
+
};
|
|
2246
|
+
}
|
|
2247
|
+
function Tt(e, t, n) {
|
|
2248
|
+
return t === "running" ? e === "prompt_too_long" ? "检测到上下文过长,正在自动压缩历史后重试" : "正在自动压缩上下文" : n ? e === "prompt_too_long" ? "上下文过长,系统已自动压缩历史并重试" : "系统已自动压缩较早的对话上下文" : t === "failed" ? "自动压缩上下文未完成" : e === "prompt_too_long" ? "已完成上下文压缩,并继续当前回复" : "已完成上下文压缩";
|
|
2249
|
+
}
|
|
2250
|
+
function Et(e, t) {
|
|
2251
|
+
return t?.itemId ? [
|
|
2252
|
+
"runtime-item",
|
|
2253
|
+
t.runId || e,
|
|
2254
|
+
t.scopeId || e,
|
|
2255
|
+
t.itemId
|
|
2256
|
+
].join("\0") : [
|
|
2257
|
+
e,
|
|
2258
|
+
t.content || "",
|
|
2259
|
+
t.reasoning || ""
|
|
2260
|
+
].join("\0");
|
|
2261
|
+
}
|
|
2262
|
+
function Dt(e) {
|
|
2263
|
+
let t = String(e?.InvocationId || "").trim(), n = e?.Metadata?.RuntimeItem;
|
|
2264
|
+
return n?.ItemId ? [
|
|
2265
|
+
"runtime-item",
|
|
2266
|
+
n.RunId || t,
|
|
2267
|
+
n.ScopeId || t,
|
|
2268
|
+
n.ItemId
|
|
2269
|
+
].join("\0") : t;
|
|
2270
|
+
}
|
|
2271
|
+
function Ot(e) {
|
|
2272
|
+
let t = e?.Metadata?.RuntimeItem;
|
|
2273
|
+
return t?.ItemId ? {
|
|
2274
|
+
id: `runtime:${t.RunId || e.InvocationId || "run"}:${t.ScopeId || e.InvocationId || "scope"}:${t.ItemId}`,
|
|
2275
|
+
runId: String(t.RunId || e.InvocationId || ""),
|
|
2276
|
+
scopeId: String(t.ScopeId || e.InvocationId || ""),
|
|
2277
|
+
itemId: String(t.ItemId),
|
|
2278
|
+
partId: t.PartId ? String(t.PartId) : void 0
|
|
2279
|
+
} : null;
|
|
2280
|
+
}
|
|
2281
|
+
function kt(e) {
|
|
2282
|
+
return e?.Metadata?.responses_mirror === !0 || String(e?.Metadata?.responses_mirror || "").trim().toLowerCase() === "true";
|
|
2283
|
+
}
|
|
2284
|
+
function At(e) {
|
|
2285
|
+
if (e?.EventType !== "user_message") return "";
|
|
2286
|
+
let t = Y(e), n = (t.attachments || []).map((e) => [
|
|
2287
|
+
e.name || "",
|
|
2288
|
+
e.fileUri || "",
|
|
2289
|
+
e.url || "",
|
|
2290
|
+
e.type || ""
|
|
2291
|
+
].join("")).sort().join("");
|
|
2292
|
+
return [String(t.text || "").trim(), n].join("\0");
|
|
2293
|
+
}
|
|
2294
|
+
function jt(e) {
|
|
2295
|
+
return e?.EventType === "assistant_stream_snapshot";
|
|
2296
|
+
}
|
|
2297
|
+
function X(e) {
|
|
2298
|
+
let t = Number(e?.SeqId || 0);
|
|
2299
|
+
if (Number.isFinite(t) && t > 0) return t;
|
|
2300
|
+
let n = Number(e?.Timestamp || 0);
|
|
2301
|
+
return Number.isFinite(n) ? n : 0;
|
|
2302
|
+
}
|
|
2303
|
+
function Mt(e) {
|
|
2304
|
+
if (typeof e == "string") return e;
|
|
2305
|
+
if (e == null) return "";
|
|
2306
|
+
try {
|
|
2307
|
+
return JSON.stringify(e, null, 2);
|
|
2308
|
+
} catch {
|
|
2309
|
+
return String(e);
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
function Nt(e) {
|
|
2313
|
+
let n = String(e?.EventType || "");
|
|
2314
|
+
if (!mt.has(n)) return null;
|
|
2315
|
+
let r = String(e.Metadata?.tool_name || e.Metadata?.name || e.Metadata?.function_name || bt(e.Content?.parts) || "tool").trim() || "tool", i = String(e.Metadata?.call_id || e.Metadata?.callId || e.Metadata?.RuntimeItem?.ToolCallId || "").trim(), a = {
|
|
2316
|
+
name: r,
|
|
2317
|
+
...i ? { callId: i } : {},
|
|
2318
|
+
args: "",
|
|
2319
|
+
status: "running"
|
|
2320
|
+
}, o = n === "tool_result" || n === "stage_tool_result" ? (() => {
|
|
2321
|
+
let n = Mt(e.Metadata?.tool_output ?? e.Metadata?.output ?? e.Metadata?.result ?? bt(e.Content?.parts));
|
|
2322
|
+
return {
|
|
2323
|
+
...a,
|
|
2324
|
+
output: n,
|
|
2325
|
+
status: t(n) ? "error" : "completed"
|
|
2326
|
+
};
|
|
2327
|
+
})() : {
|
|
2328
|
+
...a,
|
|
2329
|
+
args: Mt(e.Metadata?.tool_args ?? e.Metadata?.arguments ?? e.Metadata?.args ?? {})
|
|
2330
|
+
}, s = Ot(e);
|
|
2331
|
+
return {
|
|
2332
|
+
id: s?.id || e.EventId || String(Date.now() + Math.random()),
|
|
2333
|
+
role: "model",
|
|
2334
|
+
content: "",
|
|
2335
|
+
timestamp: e.Timestamp || Date.now(),
|
|
2336
|
+
eventType: n,
|
|
2337
|
+
...s || {},
|
|
2338
|
+
tools: { [r]: o }
|
|
2339
|
+
};
|
|
2340
|
+
}
|
|
2341
|
+
function Pt(e = {}, t = {}) {
|
|
2342
|
+
let n = { ...e || {} };
|
|
2343
|
+
for (let [e, r] of Object.entries(t || {})) n[e] = {
|
|
2344
|
+
...n[e] || {},
|
|
2345
|
+
...r || {},
|
|
2346
|
+
name: e,
|
|
2347
|
+
args: r?.args || n[e]?.args || ""
|
|
2348
|
+
};
|
|
2349
|
+
return n;
|
|
2350
|
+
}
|
|
2351
|
+
function Ft(e = {}, t = "") {
|
|
2352
|
+
let n = String(t || "").trim().toLowerCase(), r = n === "completed" ? "completed" : pt.has(n) ? "error" : "";
|
|
2353
|
+
if (!r) return e;
|
|
2354
|
+
let i = !1, a = {};
|
|
2355
|
+
for (let [t, n] of Object.entries(e || {})) n?.status === "running" ? (i = !0, a[t] = {
|
|
2356
|
+
...n,
|
|
2357
|
+
status: r
|
|
2358
|
+
}) : a[t] = n;
|
|
2359
|
+
return i ? a : e;
|
|
2360
|
+
}
|
|
2361
|
+
function It(e, t) {
|
|
2362
|
+
return {
|
|
2363
|
+
...e,
|
|
2364
|
+
reasoning: Lt(e.reasoning, t.reasoning),
|
|
2365
|
+
tools: Pt(e.tools, t.tools),
|
|
2366
|
+
eventId: t.eventId || e.eventId,
|
|
2367
|
+
responseId: t.responseId || e.responseId,
|
|
2368
|
+
traceId: t.traceId || e.traceId,
|
|
2369
|
+
rootSpanId: t.rootSpanId || e.rootSpanId,
|
|
2370
|
+
timestamp: Math.max(Number(e.timestamp || 0), Number(t.timestamp || 0)) || t.timestamp || e.timestamp,
|
|
2371
|
+
id: t.responseId || t.reasoning || t.tools ? t.id : e.id
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
function Lt(e = "", t = "") {
|
|
2375
|
+
let n = String(e || ""), r = String(t || "");
|
|
2376
|
+
return n ? !r || n.endsWith(r) ? n : r.startsWith(n) ? r : `${n}${r}` : r;
|
|
2377
|
+
}
|
|
2378
|
+
function Rt(e) {
|
|
2379
|
+
return {
|
|
2380
|
+
id: e.id,
|
|
2381
|
+
role: "system",
|
|
2382
|
+
eventType: "context_checkpoint",
|
|
2383
|
+
status: e.status,
|
|
2384
|
+
trigger: e.trigger,
|
|
2385
|
+
compactedUntilSeqId: e.compactedUntilSeqId,
|
|
2386
|
+
summary: e.summary,
|
|
2387
|
+
historical: e.historical,
|
|
2388
|
+
timestamp: e.timestamp,
|
|
2389
|
+
content: Tt(e.trigger, e.status, e.historical)
|
|
2390
|
+
};
|
|
2391
|
+
}
|
|
2392
|
+
function zt(e) {
|
|
2393
|
+
let t = Bt(e);
|
|
2394
|
+
return t && Number.isSafeInteger(e.SeqId) && e.SeqId > 0 && (t.historyOrder = { seq: e.SeqId }), t;
|
|
2395
|
+
}
|
|
2396
|
+
function Bt(e) {
|
|
2397
|
+
let t = e?.EventType || "", n = Ot(e);
|
|
2398
|
+
if (t === "run_status") return e.Content?.status === "failed" ? {
|
|
2399
|
+
id: e.EventId || String(Date.now() + Math.random()),
|
|
2400
|
+
role: "system",
|
|
2401
|
+
content: e.Content?.detail || "本轮运行失败。",
|
|
2402
|
+
eventType: t,
|
|
2403
|
+
status: "failed",
|
|
2404
|
+
timestamp: e.Timestamp || Date.now()
|
|
2405
|
+
} : e.Content?.status === "cancelled" ? {
|
|
2406
|
+
id: e.EventId || String(Date.now() + Math.random()),
|
|
2407
|
+
role: "system",
|
|
2408
|
+
content: e.Content?.detail || "本轮输出已停止。",
|
|
2409
|
+
eventType: t,
|
|
2410
|
+
status: "cancelled",
|
|
2411
|
+
timestamp: e.Timestamp || Date.now()
|
|
2412
|
+
} : null;
|
|
2413
|
+
if (t === "context_checkpoint") {
|
|
2414
|
+
let t = Y(e);
|
|
2415
|
+
return Rt({
|
|
2416
|
+
id: e.EventId || String(Date.now() + Math.random()),
|
|
2417
|
+
timestamp: e.Timestamp || Date.now(),
|
|
2418
|
+
status: "completed",
|
|
2419
|
+
trigger: String(e.Metadata?.trigger || "auto"),
|
|
2420
|
+
compactedUntilSeqId: Number(e.Metadata?.compacted_until_seq_id || 0) || void 0,
|
|
2421
|
+
summary: t.text || void 0,
|
|
2422
|
+
historical: !0
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
2425
|
+
if (t === "reasoning") {
|
|
2426
|
+
let r = Y(e).text || bt(e.Metadata?.reasoning);
|
|
2427
|
+
return r ? {
|
|
2428
|
+
id: n?.id || e.EventId || String(Date.now() + Math.random()),
|
|
2429
|
+
role: "model",
|
|
2430
|
+
content: "",
|
|
2431
|
+
reasoning: r,
|
|
2432
|
+
timestamp: e.Timestamp || Date.now(),
|
|
2433
|
+
eventType: t,
|
|
2434
|
+
...n || {}
|
|
2435
|
+
} : null;
|
|
2436
|
+
}
|
|
2437
|
+
if (mt.has(t)) return Nt(e);
|
|
2438
|
+
if (t !== "user_message" && t !== "assistant_message" && t !== "assistant_stream_snapshot") return null;
|
|
2439
|
+
let r = Y(e), i = t === "assistant_message" ? wt(e) : {};
|
|
2440
|
+
if (!r.text && !r.attachments?.length && !i.reasoning && !i.tools) return null;
|
|
2441
|
+
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();
|
|
2442
|
+
return {
|
|
2443
|
+
id: n?.id || e.EventId || String(Date.now() + Math.random()),
|
|
2444
|
+
role: t === "user_message" ? "user" : "model",
|
|
2445
|
+
content: r.text,
|
|
2446
|
+
timestamp: e.Timestamp || Date.now(),
|
|
2447
|
+
eventType: t,
|
|
2448
|
+
eventId: e.EventId || void 0,
|
|
2449
|
+
responseId: a || void 0,
|
|
2450
|
+
traceId: o || void 0,
|
|
2451
|
+
rootSpanId: s || void 0,
|
|
2452
|
+
attachments: r.attachments,
|
|
2453
|
+
...n || {},
|
|
2454
|
+
...i
|
|
2455
|
+
};
|
|
2456
|
+
}
|
|
2457
|
+
function Vt(e = []) {
|
|
2458
|
+
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = vt(e), c = [];
|
|
2459
|
+
for (let e of s) {
|
|
2460
|
+
let t = String(e?.EventId || "").trim();
|
|
2461
|
+
if (t) {
|
|
2462
|
+
if (o.has(t)) continue;
|
|
2463
|
+
o.add(t);
|
|
2464
|
+
}
|
|
2465
|
+
c.push(e);
|
|
2466
|
+
}
|
|
2467
|
+
let l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Map();
|
|
2468
|
+
for (let e of c) {
|
|
2469
|
+
if (e?.EventType !== "user_message" || kt(e)) {
|
|
2470
|
+
if (e?.EventType === "assistant_message") {
|
|
2471
|
+
let t = Dt(e);
|
|
2472
|
+
t && u.add(t);
|
|
2473
|
+
}
|
|
2474
|
+
if (jt(e)) {
|
|
2475
|
+
let t = Dt(e);
|
|
2476
|
+
if (t) {
|
|
2477
|
+
let n = d.get(t);
|
|
2478
|
+
(!n || X(e) >= X(n)) && d.set(t, e);
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
continue;
|
|
2482
|
+
}
|
|
2483
|
+
let t = At(e);
|
|
2484
|
+
t && l.add(t);
|
|
2485
|
+
}
|
|
2486
|
+
let f = c.filter((e) => {
|
|
2487
|
+
if (jt(e)) {
|
|
2488
|
+
let t = Dt(e);
|
|
2489
|
+
return t ? u.has(t) ? !1 : d.get(t) === e : !0;
|
|
2490
|
+
}
|
|
2491
|
+
if (e?.EventType !== "user_message" || !kt(e)) return !0;
|
|
2492
|
+
let t = At(e);
|
|
2493
|
+
return !t || !l.has(t);
|
|
2494
|
+
});
|
|
2495
|
+
for (let e of f) {
|
|
2496
|
+
let a = String(e.InvocationId || "").trim();
|
|
2497
|
+
a && e.EventType === "user_message" && i.add(a), a && [
|
|
2498
|
+
"assistant_message",
|
|
2499
|
+
"assistant_stream_snapshot",
|
|
2500
|
+
"reasoning",
|
|
2501
|
+
"tool_call",
|
|
2502
|
+
"tool_result",
|
|
2503
|
+
"stage_tool_call",
|
|
2504
|
+
"stage_tool_result"
|
|
2505
|
+
].includes(String(e.EventType || "")) && r.add(a), e.EventType === "run_status" && a && (t.set(a, String(e.Content?.status || "").trim()), n.set(a, e));
|
|
2506
|
+
}
|
|
2507
|
+
let p = [], m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), g = null, _ = /* @__PURE__ */ new Map(), v = (e) => {
|
|
2508
|
+
let t = e?.itemId ? `${e.runId || e.invocationId || ""}\u0000${e.scopeId || e.invocationId || ""}\u0000${e.itemId}` : "", n = t ? h.get(t) : void 0;
|
|
2509
|
+
if (n !== void 0) {
|
|
2510
|
+
p[n] = It(p[n], e);
|
|
2511
|
+
return;
|
|
2512
|
+
}
|
|
2513
|
+
let r = String(e?.responseId || "").trim(), i = r ? m.get(r) : void 0;
|
|
2514
|
+
if (i !== void 0) {
|
|
2515
|
+
p[i] = It(p[i], e);
|
|
2516
|
+
return;
|
|
2517
|
+
}
|
|
2518
|
+
r && m.set(r, p.length), t && h.set(t, p.length), p.push(e);
|
|
2519
|
+
}, y = () => {
|
|
2520
|
+
g &&= (v(g), null);
|
|
2521
|
+
}, b = (e, n = "") => {
|
|
2522
|
+
let r = String(e || "").trim();
|
|
2523
|
+
if (!r) return {};
|
|
2524
|
+
let i = _.get(r);
|
|
2525
|
+
return i ? (_.delete(r), { tools: Ft(i.tools, t.get(r) || n) }) : {};
|
|
2526
|
+
};
|
|
2527
|
+
for (let e of f) {
|
|
2528
|
+
if (e.EventType === "run_status") continue;
|
|
2529
|
+
let t = zt(e);
|
|
2530
|
+
if (!t) continue;
|
|
2531
|
+
let n = String(e.InvocationId || "").trim();
|
|
2532
|
+
if (n && (t.invocationId = n), mt.has(t.eventType)) {
|
|
2533
|
+
let n = String(e.InvocationId || "").trim();
|
|
2534
|
+
if (t.itemId) {
|
|
2535
|
+
y(), v(t);
|
|
2536
|
+
continue;
|
|
2537
|
+
}
|
|
2538
|
+
if (!n) {
|
|
2539
|
+
y(), v(t);
|
|
2540
|
+
continue;
|
|
2541
|
+
}
|
|
2542
|
+
let r = _.get(n);
|
|
2543
|
+
_.set(n, {
|
|
2544
|
+
...r || {
|
|
2545
|
+
id: t.id,
|
|
2546
|
+
role: "model",
|
|
2547
|
+
content: "",
|
|
2548
|
+
timestamp: t.timestamp,
|
|
2549
|
+
invocationId: n
|
|
2550
|
+
},
|
|
2551
|
+
timestamp: Math.max(Number(r?.timestamp || 0), Number(t.timestamp || 0)),
|
|
2552
|
+
tools: Pt(r?.tools, t.tools)
|
|
2553
|
+
});
|
|
2554
|
+
continue;
|
|
2555
|
+
}
|
|
2556
|
+
if (t.eventType === "reasoning") {
|
|
2557
|
+
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);
|
|
2558
|
+
if (g && (i || a)) {
|
|
2559
|
+
g.reasoning = r === "replace" || r === "completed" ? t.reasoning : `${g.reasoning || ""}${t.reasoning || ""}`, g.timestamp = t.timestamp;
|
|
2560
|
+
continue;
|
|
2561
|
+
}
|
|
2562
|
+
y(), g = {
|
|
2563
|
+
...t,
|
|
2564
|
+
...n ? { invocationId: n } : {}
|
|
2565
|
+
};
|
|
2566
|
+
continue;
|
|
2567
|
+
}
|
|
2568
|
+
let r = t.eventType === "assistant_message" || t.eventType === "assistant_stream_snapshot";
|
|
2569
|
+
if (r && g) {
|
|
2570
|
+
let n = String(e.InvocationId || "").trim(), r = Et(n, t);
|
|
2571
|
+
if (t.eventType === "assistant_message" && n && a.has(r)) {
|
|
2572
|
+
g = null;
|
|
2573
|
+
continue;
|
|
2574
|
+
}
|
|
2575
|
+
t.eventType === "assistant_message" && n && a.add(r), v({
|
|
2576
|
+
...t,
|
|
2577
|
+
...b(n, t.eventType === "assistant_message" ? "completed" : ""),
|
|
2578
|
+
reasoning: Lt(g.reasoning, t.reasoning)
|
|
2579
|
+
}), g = null;
|
|
2580
|
+
continue;
|
|
2581
|
+
}
|
|
2582
|
+
if (y(), r) {
|
|
2583
|
+
let n = String(e.InvocationId || "").trim(), r = Et(n, t);
|
|
2584
|
+
if (t.eventType === "assistant_message" && n && a.has(r)) continue;
|
|
2585
|
+
t.eventType === "assistant_message" && n && a.add(r), v({
|
|
2586
|
+
...t,
|
|
2587
|
+
...b(n, t.eventType === "assistant_message" ? "completed" : "")
|
|
2588
|
+
});
|
|
2589
|
+
continue;
|
|
2590
|
+
}
|
|
2591
|
+
v(t);
|
|
2592
|
+
}
|
|
2593
|
+
y();
|
|
2594
|
+
for (let [e, n] of _.entries()) v({
|
|
2595
|
+
...n,
|
|
2596
|
+
tools: Ft(n.tools, t.get(e))
|
|
2597
|
+
});
|
|
2598
|
+
for (let [e, a] of t.entries()) {
|
|
2599
|
+
if (a !== "in_progress" || r.has(e) || !i.has(e)) continue;
|
|
2600
|
+
let t = n.get(e) || {};
|
|
2601
|
+
v({
|
|
2602
|
+
id: `run-placeholder-${e}`,
|
|
2603
|
+
role: "model",
|
|
2604
|
+
content: "",
|
|
2605
|
+
status: "running",
|
|
2606
|
+
eventType: "run_status",
|
|
2607
|
+
timestamp: t.Timestamp || Date.now()
|
|
2608
|
+
});
|
|
2609
|
+
}
|
|
2610
|
+
return p;
|
|
2611
|
+
}
|
|
2612
|
+
function Ht(e = [], t = []) {
|
|
2613
|
+
let n = [], r = /* @__PURE__ */ new Set();
|
|
2614
|
+
for (let i of [...Array.isArray(e) ? e : [], ...Array.isArray(t) ? t : []]) {
|
|
2615
|
+
let e = String(i?.EventId || "").trim();
|
|
2616
|
+
if (e) {
|
|
2617
|
+
if (r.has(e)) continue;
|
|
2618
|
+
r.add(e);
|
|
2619
|
+
}
|
|
2620
|
+
n.push(i);
|
|
2621
|
+
}
|
|
2622
|
+
return n.sort((e, t) => {
|
|
2623
|
+
let n = Number(e?.SeqId || 0), r = Number(t?.SeqId || 0);
|
|
2624
|
+
return Number.isFinite(n) && Number.isFinite(r) && n !== r ? n - r : Number(e?.Timestamp || 0) - Number(t?.Timestamp || 0);
|
|
2625
|
+
});
|
|
2626
|
+
}
|
|
2627
|
+
function Ut(e = []) {
|
|
2628
|
+
return (Array.isArray(e) ? e : []).reduce((e, t) => {
|
|
2629
|
+
let n = Number(t.SeqId || 0);
|
|
2630
|
+
return Number.isFinite(n) ? Math.max(e, n) : e;
|
|
2631
|
+
}, 0);
|
|
2632
|
+
}
|
|
2633
|
+
function Wt(e) {
|
|
2634
|
+
return pt.has(yt(e));
|
|
2635
|
+
}
|
|
2636
|
+
//#endregion
|
|
2637
|
+
//#region src/utils/persisted-session-history.ts
|
|
2638
|
+
function Z(e) {
|
|
2639
|
+
return e && typeof e == "object" && !Array.isArray(e) ? e : null;
|
|
2640
|
+
}
|
|
2641
|
+
function Gt(e) {
|
|
2642
|
+
if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
|
|
2643
|
+
if (typeof e == "string" && e.trim()) {
|
|
2644
|
+
let t = Number(e.trim());
|
|
2645
|
+
if (Number.isFinite(t)) return t > 0 && t < 1e11 ? t * 1e3 : t;
|
|
2646
|
+
}
|
|
2647
|
+
let t = Date.parse(String(e || ""));
|
|
2648
|
+
return Number.isFinite(t) ? t : Date.now();
|
|
2649
|
+
}
|
|
2650
|
+
function Q(e) {
|
|
2651
|
+
let t = Z(e?.Content?.runtime_event || e?.Content?.runtimeEvent);
|
|
2652
|
+
if (t && String(t.event_type || "")) return {
|
|
2653
|
+
...t,
|
|
2654
|
+
family: "runtime",
|
|
2655
|
+
seq: Number(e.SeqId || t.seq || 0),
|
|
2656
|
+
timestamp: e.Timestamp || t.timestamp
|
|
2657
|
+
};
|
|
2658
|
+
let n = Z(e?.Content?.session_event || e?.Content?.sessionEvent);
|
|
2659
|
+
if (!n || String(n.family || "") !== "runtime") return null;
|
|
2660
|
+
let r = Z(n.payload);
|
|
2661
|
+
return !r || !String(r.event_type || n.event_type || "") ? null : {
|
|
2662
|
+
...r,
|
|
2663
|
+
family: "runtime",
|
|
2664
|
+
event_type: r.event_type || n.event_type,
|
|
2665
|
+
run_id: r.run_id || n.run_id,
|
|
2666
|
+
seq: Number(e.SeqId || n.seq || r.seq || 0),
|
|
2667
|
+
timestamp: e.Timestamp || n.timestamp || r.timestamp
|
|
2668
|
+
};
|
|
2669
|
+
}
|
|
2670
|
+
function Kt(e, t, n) {
|
|
2671
|
+
let r = /* @__PURE__ */ new Map();
|
|
2672
|
+
for (let e of t) {
|
|
2673
|
+
if (e.EventType !== "run_status" || Q(e)) continue;
|
|
2674
|
+
let t = String(e.InvocationId || e.Metadata?.run_id || "").trim();
|
|
2675
|
+
t && !n.has(t) && r.set(t, e);
|
|
2676
|
+
}
|
|
2677
|
+
let i = e;
|
|
2678
|
+
for (let [e, t] of r) {
|
|
2679
|
+
let n = zt({
|
|
2680
|
+
...t,
|
|
2681
|
+
EventId: t.EventId || `legacy-terminal:${e}:${t.SeqId || 0}`,
|
|
2682
|
+
Timestamp: Gt(t.Timestamp)
|
|
2683
|
+
});
|
|
2684
|
+
if (!n) continue;
|
|
2685
|
+
let r = (t) => (t.invocationId || t.runId) === e;
|
|
2686
|
+
i = i.filter((e) => !(r(e) && e.role === "system" && e.eventType === "run_status")).map((e) => {
|
|
2687
|
+
if (!r(e) || e.role !== "model") return e;
|
|
2688
|
+
let t = (e) => e === "running" || e === "paused", i = "运行已结束,未记录此工具的最终结果。";
|
|
2689
|
+
return {
|
|
2690
|
+
...e,
|
|
2691
|
+
tools: e.tools && Object.fromEntries(Object.entries(e.tools).map(([e, n]) => [e, t(n.status) ? {
|
|
2692
|
+
...n,
|
|
2693
|
+
status: "unknown",
|
|
2694
|
+
summary: n.summary || i
|
|
2695
|
+
} : n])),
|
|
2696
|
+
blocks: e.blocks?.map((e) => e.type === "thinking" && e.status === "streaming" ? {
|
|
2697
|
+
...e,
|
|
2698
|
+
status: "done"
|
|
2699
|
+
} : e.type !== "tool" || !t(e.status) ? e : {
|
|
2700
|
+
...e,
|
|
2701
|
+
status: "unknown",
|
|
2702
|
+
summary: e.summary || i,
|
|
2703
|
+
extra: {
|
|
2704
|
+
...e.extra,
|
|
2705
|
+
persistedToolStatus: e.status,
|
|
2706
|
+
terminalRunStatus: n.status
|
|
2707
|
+
}
|
|
2708
|
+
})
|
|
2709
|
+
};
|
|
2710
|
+
}), i.push({
|
|
2711
|
+
...n,
|
|
2712
|
+
invocationId: e,
|
|
2713
|
+
eventId: t.EventId
|
|
2714
|
+
});
|
|
2715
|
+
}
|
|
2716
|
+
return i === e ? e : M(i);
|
|
2717
|
+
}
|
|
2718
|
+
function $(e) {
|
|
2719
|
+
return e.role === "model" ? {
|
|
2720
|
+
...e,
|
|
2721
|
+
blocks: e.blocks?.length ? e.blocks : Ue({
|
|
2722
|
+
content: e.content,
|
|
2723
|
+
reasoning: e.reasoning,
|
|
2724
|
+
tools: e.tools
|
|
2725
|
+
})
|
|
2726
|
+
} : e;
|
|
2727
|
+
}
|
|
2728
|
+
function qt(e, t) {
|
|
2729
|
+
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 ? {
|
|
2730
|
+
...e,
|
|
2731
|
+
...n,
|
|
2732
|
+
invocationId: e.invocationId || n.invocationId
|
|
2733
|
+
} : $(e === a && o ? {
|
|
2734
|
+
...e,
|
|
2735
|
+
responseId: o.responseId || e.responseId,
|
|
2736
|
+
traceId: o.traceId || e.traceId,
|
|
2737
|
+
rootSpanId: o.rootSpanId || e.rootSpanId
|
|
2738
|
+
} : e));
|
|
2739
|
+
return n && !r ? [n, ...s] : s;
|
|
2740
|
+
}
|
|
2741
|
+
function Jt(e, t) {
|
|
2742
|
+
let n = t.filter((e) => e.role === "model"), r = n.reduce((e, t) => ({
|
|
2743
|
+
...e,
|
|
2744
|
+
...t.tools || {}
|
|
2745
|
+
}), {}), i = n.map((e) => String(e.reasoning || "").trim()).filter(Boolean).join("\n\n"), a = [...e].reverse().find((e) => e.role === "model");
|
|
2746
|
+
return !a || Object.keys(r).length === 0 && !i ? e : e.map((e) => e === a ? $({
|
|
2747
|
+
...e,
|
|
2748
|
+
reasoning: e.reasoning || i || void 0,
|
|
2749
|
+
tools: Object.keys(r).length > 0 ? {
|
|
2750
|
+
...e.tools || {},
|
|
2751
|
+
...r
|
|
2752
|
+
} : e.tools
|
|
2753
|
+
}) : e);
|
|
2754
|
+
}
|
|
2755
|
+
function Yt(e) {
|
|
2756
|
+
return new Set(e.filter((e) => e.role === "model" && e.eventType === "assistant_message" && !!String(e.content || "").trim() && !!e.invocationId).map((e) => String(e.invocationId)));
|
|
2757
|
+
}
|
|
2758
|
+
var Xt = new Set([
|
|
2759
|
+
"approval.resolved",
|
|
2760
|
+
"interaction.resolved",
|
|
2761
|
+
"interaction.cancelled",
|
|
2762
|
+
"interaction.canceled",
|
|
2763
|
+
"a2ui.action"
|
|
2764
|
+
]);
|
|
2765
|
+
function Zt(e) {
|
|
2766
|
+
let t = /* @__PURE__ */ new Set();
|
|
2767
|
+
for (let n of e) {
|
|
2768
|
+
let e = Z(n.Content) || {}, r = Z(e.runtime_event || e.runtimeEvent) || {}, i = Z(e.payload) || Z(r.payload) || {}, a = String(n.EventType || e.event_type || e.eventType || r.event_type || "").toLowerCase();
|
|
2769
|
+
if (!Xt.has(a)) continue;
|
|
2770
|
+
let o = String(e.outcome || e.action || e.name || e.status || i.outcome || i.action || i.name || i.status || "").toLowerCase();
|
|
2771
|
+
if (![
|
|
2772
|
+
"cancel",
|
|
2773
|
+
"cancelled",
|
|
2774
|
+
"canceled"
|
|
2775
|
+
].includes(o)) continue;
|
|
2776
|
+
let s = String(n.InvocationId || e.runId || e.run_id || i.runId || i.run_id || r.run_id || "").trim();
|
|
2777
|
+
s && t.add(s);
|
|
2778
|
+
}
|
|
2779
|
+
return t;
|
|
2780
|
+
}
|
|
2781
|
+
function Qt(e, t, n, r = "flat-v1") {
|
|
2782
|
+
let i = new $e(n), a = [], o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = [...t || []].filter((e) => {
|
|
2783
|
+
let t = e.Content, r = Z(t?.session_event || t?.sessionEvent), i = Z(t?.runtime_event || t?.runtimeEvent);
|
|
2784
|
+
return [
|
|
2785
|
+
e.SessionId,
|
|
2786
|
+
r?.session_id,
|
|
2787
|
+
i?.session_id
|
|
2788
|
+
].every((e) => !e || e === n);
|
|
2789
|
+
}).sort((e, t) => Number(e.SeqId || 0) - Number(t.SeqId || 0)), u = Number(l[0]?.SeqId || 0) <= 1;
|
|
2790
|
+
for (let e of l) {
|
|
2791
|
+
let t = Q(e);
|
|
2792
|
+
if (!t) continue;
|
|
2793
|
+
let n = String(t.run_id || "").trim();
|
|
2794
|
+
if (n) {
|
|
2795
|
+
o.add(n), !t.parent_scope_id && [
|
|
2796
|
+
"run.completed",
|
|
2797
|
+
"run.failed",
|
|
2798
|
+
"run.cancelled",
|
|
2799
|
+
"run.canceled"
|
|
2800
|
+
].includes(String(t.event_type)) && s.add(n);
|
|
2801
|
+
let e = Z(Z(t.source)?.metadata), r = String(t.event_type || "") === "run.started", i = e?.native_item_kind === "userMessage";
|
|
2802
|
+
(u || r || i) && c.add(n);
|
|
2803
|
+
}
|
|
2804
|
+
let r = i.translate(t);
|
|
2805
|
+
r && a.push({
|
|
2806
|
+
...r,
|
|
2807
|
+
SeqId: Number(e.SeqId || r.SeqId || 0),
|
|
2808
|
+
Timestamp: Gt(e.Timestamp || r.Timestamp)
|
|
2809
|
+
});
|
|
2810
|
+
}
|
|
2811
|
+
let d = Vt(a).filter((e) => e.invocationId && o.has(e.invocationId)), f = /* @__PURE__ */ new Map();
|
|
2812
|
+
for (let t of e) {
|
|
2813
|
+
let e = String(t.invocationId || "");
|
|
2814
|
+
e && f.set(e, [...f.get(e) || [], t]);
|
|
2815
|
+
}
|
|
2816
|
+
let p = new Set([...Yt(d)].filter((e) => c.has(e))), m = /* @__PURE__ */ new Map();
|
|
2817
|
+
for (let e of l) {
|
|
2818
|
+
let t = Q(e);
|
|
2819
|
+
if (t?.schema_version !== 2 || !t.run_id) continue;
|
|
2820
|
+
let n = String(t.run_id), r = m.get(n) || [];
|
|
2821
|
+
r.push(t), m.set(n, r);
|
|
2822
|
+
}
|
|
2823
|
+
let h = (e) => [
|
|
2824
|
+
Z(e.initial),
|
|
2825
|
+
Z(e.snapshot),
|
|
2826
|
+
Z(e.update)
|
|
2827
|
+
].some((e) => Z(e?.data)?.schema === "execution.scope/v1" || Array.isArray(e?.parts) && e.parts.some((e) => Z(Z(e)?.data)?.schema === "execution.scope/v1")), g = new Set([...m].filter(([, e]) => e.some(h)).map(([e]) => e)), _ = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Set();
|
|
2828
|
+
for (let [e, t] of m) {
|
|
2829
|
+
if (!g.has(e) && !p.has(e) && !t.some((e) => ["item.failed", "run.failed"].includes(String(e.event_type)))) continue;
|
|
2830
|
+
let i = t.some((e) => e.event_type === "run.started" && !e.parent_scope_id), a = /* @__PURE__ */ new Set(), o = t.every((e) => {
|
|
2831
|
+
let t = JSON.stringify([e.scope_id, e.item_id]);
|
|
2832
|
+
return e.event_type === "item.started" && a.add(t), !h(e) || a.has(t);
|
|
2833
|
+
});
|
|
2834
|
+
if (!(!i || !o)) try {
|
|
2835
|
+
let i = new x(n, void 0, r);
|
|
2836
|
+
t.forEach((e) => i.apply(e));
|
|
2837
|
+
let a = i.snapshot(), o = le(a, { profile: r }), s = Gt(t[0].timestamp);
|
|
2838
|
+
_.set(e, L({
|
|
2839
|
+
state: a,
|
|
2840
|
+
presentation: o,
|
|
2841
|
+
runId: e,
|
|
2842
|
+
cursor: Math.max(...t.map((e) => Number(e.seq || 0)))
|
|
2843
|
+
}).messages.map((n, r) => {
|
|
2844
|
+
let i = t.find((e) => e.item_id === n.itemId && (!n.scopeId || e.scope_id === n.scopeId)) || t[0];
|
|
2845
|
+
return {
|
|
2846
|
+
...n,
|
|
2847
|
+
invocationId: e,
|
|
2848
|
+
timestamp: s + r,
|
|
2849
|
+
historyOrder: {
|
|
2850
|
+
seq: Number(i.seq),
|
|
2851
|
+
index: r
|
|
2852
|
+
}
|
|
2853
|
+
};
|
|
2854
|
+
}));
|
|
2855
|
+
} catch (t) {
|
|
2856
|
+
v.add(e), console.warn(`[SessionHistory] strict replay skipped for run ${e}:`, t instanceof Error ? t.message : "invalid runtime history");
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
for (let e of new Set([...g, ...v])) _.has(e) || p.delete(e);
|
|
2860
|
+
let y = Zt(l), b = [...p].flatMap((e) => qt(d.filter((t) => t.invocationId === e), f.get(e) || [])), S = /* @__PURE__ */ new Map(), C = [];
|
|
2861
|
+
for (let [e, t] of f) {
|
|
2862
|
+
if (p.has(e) || !o.has(e)) continue;
|
|
2863
|
+
let n = d.filter((t) => t.invocationId === e);
|
|
2864
|
+
S.set(e, Jt(t, n)), t.some((e) => e.role === "model" && String(e.content || "").trim()) || C.push(...n.map($));
|
|
2865
|
+
}
|
|
2866
|
+
for (let e of o) p.has(e) || f.has(e) || C.push(...d.filter((t) => t.invocationId === e).map($));
|
|
2867
|
+
let w = new Map([...S.values()].flat().map((e) => [e.id, e])), T = M([
|
|
2868
|
+
...e.filter((e) => !(e.role === "model" && e.invocationId && y.has(e.invocationId)) && (e.role === "a2ui" || !e.invocationId || !p.has(e.invocationId))).map((e) => w.get(e.id) || e),
|
|
2869
|
+
...b,
|
|
2870
|
+
...C
|
|
2871
|
+
]);
|
|
2872
|
+
for (let [e, t] of _) {
|
|
2873
|
+
if (!t.length) continue;
|
|
2874
|
+
let n = (t) => t.invocationId === e || t.runId === e, r = T.findIndex(n), i = T.filter(n), a = i.find((e) => e.role === "user"), o = g.has(e) ? a && !t.some((e) => e.role === "user") ? [a, ...t] : t : qt(t, i), s = T.filter((e) => !n(e)), c = r < 0 ? s.length : r;
|
|
2875
|
+
T = [
|
|
2876
|
+
...s.slice(0, c),
|
|
2877
|
+
...o,
|
|
2878
|
+
...s.slice(c)
|
|
2879
|
+
], p.add(e);
|
|
2880
|
+
}
|
|
2881
|
+
return {
|
|
2882
|
+
messages: M(Kt(T, l, s)),
|
|
2883
|
+
canonicalRunIds: [...p],
|
|
2884
|
+
translatedEvents: a
|
|
2885
|
+
};
|
|
2886
|
+
}
|
|
2887
|
+
//#endregion
|
|
2888
|
+
export { xe as C, x as D, le as E, b as O, Ce as S, ve as T, He as _, Wt as a, Fe as b, yt as c, $e as d, et as f, ze as g, Ue as h, Vt as i, rt as l, Le as m, Qt as n, Ut as o, Re as p, Rt as r, Ht as s, Q as t, ft as u, Be as v, be as w, L as x, Ve as y };
|