@kingsoftcloud/ksadk-web 0.3.13 → 0.3.14

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