@kingsoftcloud/ksadk-web 0.3.17 → 0.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +2 -2
- package/RELEASE_PROVENANCE.json +2 -2
- package/dist-ksadk/assets/{ArtifactsPanel-DYzXIPnl.js → ArtifactsPanel-Cdr5C_vM.js} +1 -1
- package/dist-ksadk/assets/{CodeBlock-Dpa-tOmG.js → CodeBlock-BWRafud9.js} +1 -1
- package/dist-ksadk/assets/{MathMessageMarkdown-D8kBE9sl.js → MathMessageMarkdown-CFKeJIvy.js} +1 -1
- package/dist-ksadk/assets/{MermaidBlock-BYOoZB-_.js → MermaidBlock-BneAGUOd.js} +6 -6
- package/dist-ksadk/assets/{NativeTerminalPanel-CAeXHeo6.js → NativeTerminalPanel-BHI85zDO.js} +1 -1
- package/dist-ksadk/assets/{OfficialA2uiRenderer-yPb3s23n.js → OfficialA2uiRenderer-BOmT36lJ.js} +1 -1
- package/dist-ksadk/assets/{abnfDiagram-VCTEODGH-DdVxMn2L.js → abnfDiagram-VCTEODGH-DQvlOsBI.js} +1 -1
- package/dist-ksadk/assets/{arc-DsOMYRTm.js → arc-CGx0e4pN.js} +1 -1
- package/dist-ksadk/assets/architecture-7GRP2DOG-CFWjFkDL.js +1 -0
- package/dist-ksadk/assets/{architectureDiagram-5GKGNRK7-BCfzi23_.js → architectureDiagram-5GKGNRK7-WyybcNKX.js} +1 -1
- package/dist-ksadk/assets/{blockDiagram-NRAW4CY4-gC-Gc2Xv.js → blockDiagram-NRAW4CY4-C9Cx_GVs.js} +1 -1
- package/dist-ksadk/assets/{c4Diagram-UCG6FXSJ-BAHemGZa.js → c4Diagram-UCG6FXSJ-Bh7X3bGr.js} +1 -1
- package/dist-ksadk/assets/channel-D6Dp_l74.js +1 -0
- package/dist-ksadk/assets/chunk-2Q5K7J3B-CwmjhFYK.js +1 -0
- package/dist-ksadk/assets/{chunk-5VM5RSS4-Cthhs8Yv.js → chunk-5VM5RSS4-cP9XupZj.js} +1 -1
- package/dist-ksadk/assets/{chunk-F27PBJKO-BPV04XpW.js → chunk-F27PBJKO-Bm77fvR9.js} +1 -1
- package/dist-ksadk/assets/{chunk-G27WJ6UU-Cl1n0gHd.js → chunk-G27WJ6UU-DDKNPesQ.js} +1 -1
- package/dist-ksadk/assets/{chunk-JWPE2WC7-DqkIh_LK.js → chunk-JWPE2WC7-BqiUDB7s.js} +1 -1
- package/dist-ksadk/assets/{chunk-LCL6LL3I-DZhAKY7Z.js → chunk-LCL6LL3I-C528mMZy.js} +1 -1
- package/dist-ksadk/assets/{chunk-POPQ4Y6H-BGuhTofV.js → chunk-POPQ4Y6H-CzZ9g_Uf.js} +1 -1
- package/dist-ksadk/assets/{chunk-RHFEMEQ7-DhrRHdJ6.js → chunk-RHFEMEQ7-CXj4tUZ-.js} +1 -1
- package/dist-ksadk/assets/{chunk-SVP7TREG-CIdm5TIa.js → chunk-SVP7TREG-BHyd85pS.js} +1 -1
- package/dist-ksadk/assets/{chunk-XXDRQBXY-CNIlGK4v.js → chunk-XXDRQBXY-Qe29PHGe.js} +1 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-DsbvkCAV.js +1 -0
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-DsbvkCAV.js +1 -0
- package/dist-ksadk/assets/{cose-bilkent-JH36ORCC-BjauSFl3.js → cose-bilkent-JH36ORCC-maRKgeec.js} +1 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-CBZRVuc4.js +1 -0
- package/dist-ksadk/assets/{cynefinDiagram-5FMLGOSQ-DPszkr1j.js → cynefinDiagram-5FMLGOSQ-CoD0bEvn.js} +1 -1
- package/dist-ksadk/assets/{dagre-3AP2YEHR-Ds2xBGA0.js → dagre-3AP2YEHR-BkpgQqyW.js} +1 -1
- package/dist-ksadk/assets/{dagre-Dr0YPDPm.js → dagre-BUaTFrYa.js} +1 -1
- package/dist-ksadk/assets/{diagram-S7CK7UJ4-BOQfgaW5.js → diagram-S7CK7UJ4-25HdTbjE.js} +1 -1
- package/dist-ksadk/assets/{diagram-UQ7AKVKN-DMMyB2sa.js → diagram-UQ7AKVKN-KO-WqOIg.js} +1 -1
- package/dist-ksadk/assets/{diagram-VSXAHHWV-DZR1nzPa.js → diagram-VSXAHHWV-B360BkDQ.js} +1 -1
- package/dist-ksadk/assets/{diagram-VX7I27RA-DzAwLHuI.js → diagram-VX7I27RA-COr1Oqsg.js} +1 -1
- package/dist-ksadk/assets/{diagram-Z3DM3KII-D98d_Dgt.js → diagram-Z3DM3KII-CgaKrIwB.js} +1 -1
- package/dist-ksadk/assets/{dist-q8rONmMl.js → dist--HftQyp9.js} +1 -1
- package/dist-ksadk/assets/{dist-CpHO1CY1.js → dist-B3Jp5r1e.js} +1 -1
- package/dist-ksadk/assets/{dist-CxzBVC3N.js → dist-BEbS8Bag.js} +1 -1
- package/dist-ksadk/assets/{dist-D9GtQnvz.js → dist-BQ116UdZ.js} +1 -1
- package/dist-ksadk/assets/{dist-VLWgeZIu.js → dist-BoRn8a_t.js} +1 -1
- package/dist-ksadk/assets/{dist-DHiOUJJ-.js → dist-Brbrdmff.js} +1 -1
- package/dist-ksadk/assets/{dist-By8HbjFH.js → dist-Bsuusoi0.js} +1 -1
- package/dist-ksadk/assets/{dist-E1uwqlZY.js → dist-Bxcu8Ca0.js} +1 -1
- package/dist-ksadk/assets/{dist-CN8MSPvo.js → dist-By-MVndb.js} +1 -1
- package/dist-ksadk/assets/{dist-Du5KbDTg.js → dist-C9BTMVwS.js} +1 -1
- package/dist-ksadk/assets/{dist-C1uAMNTH.js → dist-CBo9AHUv.js} +1 -1
- package/dist-ksadk/assets/{dist-DxBl1V2_.js → dist-CR61WJFC.js} +1 -1
- package/dist-ksadk/assets/{dist-BEzIxZLq.js → dist-CwnkOyDn.js} +1 -1
- package/dist-ksadk/assets/{dist-X8Mgnqit.js → dist-CxIl4t92.js} +1 -1
- package/dist-ksadk/assets/{dist-A55dc8b7.js → dist-DKG0OYnk.js} +1 -1
- package/dist-ksadk/assets/{dist-BpZXLW0T.js → dist-DSw5Ju6-.js} +1 -1
- package/dist-ksadk/assets/{dist-U51Rn7ZW.js → dist-DXOlCAay.js} +1 -1
- package/dist-ksadk/assets/{dist-HuJDn2Nr.js → dist-DgJ57sRe.js} +1 -1
- package/dist-ksadk/assets/{dist-BIR7kFKG.js → dist-DmWw0IXB.js} +1 -1
- package/dist-ksadk/assets/{dist-BHIb3Gvv.js → dist-DzdXSBJb.js} +1 -1
- package/dist-ksadk/assets/{dist-MMIlBueM.js → dist-HHvdjADB.js} +1 -1
- package/dist-ksadk/assets/{dist-glVlUB_d.js → dist-_0Xgu_07.js} +1 -1
- package/dist-ksadk/assets/{ebnfDiagram-PWID7BFC-X4mBLaw3.js → ebnfDiagram-PWID7BFC-DogDP2db.js} +1 -1
- package/dist-ksadk/assets/{erDiagram-SSCWMZ5O-ClybQoOy.js → erDiagram-SSCWMZ5O-CeBDnUjR.js} +1 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV-vXZWMkpn.js +1 -0
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-5LRgzKLv.js +1 -0
- package/dist-ksadk/assets/{ganttDiagram-EL5Y4UJY-Dc_fWiA_.js → ganttDiagram-EL5Y4UJY-oIQL3MCp.js} +1 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-BUWSkncI.js +1 -0
- package/dist-ksadk/assets/{gitGraphDiagram-WWUBYQGX-0eEV_CEC.js → gitGraphDiagram-WWUBYQGX-B7qz0cmZ.js} +1 -1
- package/dist-ksadk/assets/{index-B0DeBpyZ.js → index-4g1ndaxW.js} +161 -161
- package/dist-ksadk/assets/info-A6RAGUB7-CzJ_YrOs.js +1 -0
- package/dist-ksadk/assets/{infoDiagram-RXCK75RN-mZoyw4Xh.js → infoDiagram-RXCK75RN-yQRC41Ya.js} +1 -1
- package/dist-ksadk/assets/{ishikawaDiagram-5VMMS53U-CO8OkxgJ.js → ishikawaDiagram-5VMMS53U-BCu4HiwL.js} +1 -1
- package/dist-ksadk/assets/{journeyDiagram-EYS64GPL-Ci8GpXLK.js → journeyDiagram-EYS64GPL-JaqmO73K.js} +1 -1
- package/dist-ksadk/assets/{kanban-definition-3QL26DDD-lgD5AYON.js → kanban-definition-3QL26DDD-DQo4X8NO.js} +1 -1
- package/dist-ksadk/assets/{katex-Chn0O-XC.js → katex-t_DWylQw.js} +1 -1
- package/dist-ksadk/assets/{linear-ffygyi0f.js → linear-DWdnI35B.js} +1 -1
- package/dist-ksadk/assets/{mermaid-parser.core-CGPz1_57.js → mermaid-parser.core-BHrT2Pfe.js} +2 -2
- package/dist-ksadk/assets/{mindmap-definition-FBJOCRG2-DRaJyZGQ.js → mindmap-definition-FBJOCRG2-PBVAhZYV.js} +1 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-CXoos6fx.js +1 -0
- package/dist-ksadk/assets/{pegDiagram-XKGWAZYB-BbQ2QDD3.js → pegDiagram-XKGWAZYB-CU_cLfow.js} +1 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-CjF9NoIt.js +1 -0
- package/dist-ksadk/assets/{pieDiagram-E7YTZNPT-BcB_c4Ka.js → pieDiagram-E7YTZNPT-B1h0-_pW.js} +1 -1
- package/dist-ksadk/assets/{quadrantDiagram-AXDQQJYC-CK3csxHk.js → quadrantDiagram-AXDQQJYC-DEMoGo5a.js} +1 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-BQGWs9nw.js +1 -0
- package/dist-ksadk/assets/railroad-74A4TZTK-B6znvLUK.js +1 -0
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-Bzquz0As.js +1 -0
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-1IikGkb5.js +1 -0
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-BKKgHzdc.js +1 -0
- package/dist-ksadk/assets/{railroadDiagram-O6MQD6OU-D1YLglVU.js → railroadDiagram-O6MQD6OU-BTAob2wg.js} +1 -1
- package/dist-ksadk/assets/{requirementDiagram-EFPCY7ZU-VeyqOcw3.js → requirementDiagram-EFPCY7ZU-Dl0Q2SuO.js} +1 -1
- package/dist-ksadk/assets/{sankeyDiagram-P5KCCOFB-uskDVCah.js → sankeyDiagram-P5KCCOFB-DeaTWkur.js} +1 -1
- package/dist-ksadk/assets/{sequenceDiagram-WJ2MYXX4-CmoPC4aR.js → sequenceDiagram-WJ2MYXX4-gFQYrsOd.js} +1 -1
- package/dist-ksadk/assets/{sizeCapture-X5ZJPWSS-DzV4X5WN.js → sizeCapture-X5ZJPWSS-pGQzddMB.js} +1 -1
- package/dist-ksadk/assets/{stateDiagram-HBIQ2CUA-BJehrZbH.js → stateDiagram-HBIQ2CUA-DmpYOZt1.js} +1 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-Dolxgkw3.js +1 -0
- package/dist-ksadk/assets/{swimlanes-XN3QIQJK-Bn4tEi27.js → swimlanes-XN3QIQJK-BfuSAsrr.js} +1 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-BuI1erYj.js +8 -0
- package/dist-ksadk/assets/{timeline-definition-24CTP7MA-bSkaKxqF.js → timeline-definition-24CTP7MA-CgJwrrxf.js} +1 -1
- package/dist-ksadk/assets/treeView-Q6P3EWNA-DtMdDH8N.js +1 -0
- package/dist-ksadk/assets/treemap-WGGIJYW6-VoU8QtLZ.js +1 -0
- package/dist-ksadk/assets/{vennDiagram-4TSXK5OY-ClO6s5iT.js → vennDiagram-4TSXK5OY-CBSAgXDd.js} +1 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-YWSRB0Zm.js +1 -0
- package/dist-ksadk/assets/{wardleyDiagram-VM6X3IG4-CcaYar33.js → wardleyDiagram-VM6X3IG4-013TZ2JZ.js} +1 -1
- package/dist-ksadk/assets/{xychartDiagram-S5SC5T6Z-DdiPl8uB.js → xychartDiagram-S5SC5T6Z-u6Frp8xp.js} +1 -1
- package/dist-ksadk/index.html +1 -1
- package/dist-lib/{AttachmentPreview-DHvWB_a-.js → AttachmentPreview-Dhc6ulFv.js} +168 -168
- package/dist-lib/{ConnectedComposer-CuN3EUnU.js → ConnectedComposer-Cc6bqJmu.js} +237 -237
- package/dist-lib/{ConnectedMessageList-CT-MJJkJ.js → ConnectedMessageList-Bdd-qjs-.js} +105 -102
- package/dist-lib/{WorkspacePanelContainer-Jg9bUmLJ.js → WorkspacePanelContainer-_PuvSz_J.js} +16 -16
- package/dist-lib/{a2ui-DridcTyF.js → a2ui-DihCxdtQ.js} +326 -517
- package/dist-lib/{capabilities-lJRDfRg9.js → capabilities-CHy70QGW.js} +5 -2
- package/dist-lib/capabilities.js +1 -1
- package/dist-lib/chat-composer.js +2 -2
- package/dist-lib/chat-timeline.js +3 -3
- package/dist-lib/components/chat/ProcessingBlocksView.d.ts +1 -1
- package/dist-lib/components/chat/ProcessingBlocksView.d.ts.map +1 -1
- package/dist-lib/components/chat/submitted-interaction-history.d.ts.map +1 -1
- package/dist-lib/components.js +13 -13
- package/dist-lib/conversation.js +2 -2
- package/dist-lib/core/api/facade.d.ts.map +1 -1
- package/dist-lib/core/run/blocks.d.ts +4 -2
- package/dist-lib/core/run/blocks.d.ts.map +1 -1
- package/dist-lib/core/run/dispatcher.d.ts.map +1 -1
- package/dist-lib/core/run/engine.d.ts.map +1 -1
- package/dist-lib/core/run/types.d.ts +12 -0
- package/dist-lib/core/run/types.d.ts.map +1 -1
- package/dist-lib/core/stream/types.d.ts +7 -0
- package/dist-lib/core/stream/types.d.ts.map +1 -1
- package/dist-lib/{feedback-CaSZOBD2.js → feedback-BBJKMdF2.js} +1 -1
- package/dist-lib/hooks/useAgentChat.d.ts +1 -1
- package/dist-lib/hooks/useInteractions.d.ts +1 -1
- package/dist-lib/hooks/useInteractions.d.ts.map +1 -1
- package/dist-lib/hooks/useRunAgent.d.ts.map +1 -1
- package/dist-lib/hooks/useSessionLifecycle.d.ts.map +1 -1
- package/dist-lib/hooks.js +13 -13
- package/dist-lib/{permission-2NpSBuq3.js → permission-DGyt7wBj.js} +1 -1
- package/dist-lib/{persisted-session-history-D_1AtH5H.js → persisted-session-history-Bh_6zSKC.js} +518 -434
- package/dist-lib/runtime.js +99 -98
- package/dist-lib/{session-events-6PXUoAkP.js → session-events-DvFsVXpD.js} +439 -201
- package/dist-lib/{useSessionLifecycle-daQg0sqQ.js → useSessionLifecycle-u7i_h_io.js} +992 -948
- package/dist-lib/utils/capabilities.d.ts +1 -0
- package/dist-lib/utils/capabilities.d.ts.map +1 -1
- package/dist-lib/utils/persisted-session-history.d.ts.map +1 -1
- package/dist-lib/utils/responses-stream.d.ts +3 -1
- package/dist-lib/utils/responses-stream.d.ts.map +1 -1
- package/dist-lib/utils/run-progress.d.ts.map +1 -1
- package/dist-lib/utils/session-event-history.d.ts +11 -0
- package/dist-lib/utils/session-event-history.d.ts.map +1 -1
- package/dist-lib/utils/session-events.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist-ksadk/assets/architecture-7GRP2DOG-Ds1NB530.js +0 -1
- package/dist-ksadk/assets/channel-B4PiWfnA.js +0 -1
- package/dist-ksadk/assets/chunk-2Q5K7J3B-CI2tn5IS.js +0 -1
- package/dist-ksadk/assets/classDiagram-DTDB5LWJ-BMQzydMm.js +0 -1
- package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-BMQzydMm.js +0 -1
- package/dist-ksadk/assets/cynefin-OW5HDTMX-DcGwq_cA.js +0 -1
- package/dist-ksadk/assets/eventmodeling-NTZA5JFV--IdqCKdV.js +0 -1
- package/dist-ksadk/assets/flowDiagram-A5DVABFB-BsidNZBX.js +0 -1
- package/dist-ksadk/assets/gitGraph-4MIJSDKK-BTqI4bBo.js +0 -1
- package/dist-ksadk/assets/info-A6RAGUB7-CXZCoW0H.js +0 -1
- package/dist-ksadk/assets/packet-AYTQ26CC-DoZlIRtk.js +0 -1
- package/dist-ksadk/assets/pie-WAS4IAKB-Dl-IyMT_.js +0 -1
- package/dist-ksadk/assets/radar-RG4KPBEZ-Bp8MemxX.js +0 -1
- package/dist-ksadk/assets/railroad-74A4TZTK-BmKyKako.js +0 -1
- package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-DhFitwOH.js +0 -1
- package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-TB8LQz8q.js +0 -1
- package/dist-ksadk/assets/railroad-peg-WCYAUIDC-B3J1Rtq9.js +0 -1
- package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-DkujIgVj.js +0 -1
- package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-Blb1TQ9Q.js +0 -8
- package/dist-ksadk/assets/treeView-Q6P3EWNA-C5Ez-6L4.js +0 -1
- package/dist-ksadk/assets/treemap-WGGIJYW6-WdNvoGQV.js +0 -1
- package/dist-ksadk/assets/wardley-WFR3VGLG-DCCceTuX.js +0 -1
package/dist-lib/{persisted-session-history-D_1AtH5H.js → persisted-session-history-Bh_6zSKC.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { d as
|
|
1
|
+
import { S as e, b as t, f as n, n as r, r as i } from "./session-events-DvFsVXpD.js";
|
|
2
|
+
import { d as a, i as o, l as s, o as c, p as l, t as u, u as d } from "./reducer-mbYiX0wz.js";
|
|
3
3
|
//#region src/core/conversation/safe-tool-value.ts
|
|
4
|
-
var
|
|
4
|
+
var f = [
|
|
5
5
|
"authorization",
|
|
6
6
|
"credential",
|
|
7
7
|
"password",
|
|
@@ -19,14 +19,14 @@ var d = [
|
|
|
19
19
|
"stack",
|
|
20
20
|
"exception"
|
|
21
21
|
];
|
|
22
|
-
function f(e) {
|
|
23
|
-
return e.normalize("NFKC").toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
24
|
-
}
|
|
25
22
|
function p(e) {
|
|
26
|
-
|
|
27
|
-
return d.some((e) => t.includes(e));
|
|
23
|
+
return e.normalize("NFKC").toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
28
24
|
}
|
|
29
25
|
function m(e) {
|
|
26
|
+
let t = p(e);
|
|
27
|
+
return f.some((e) => t.includes(e));
|
|
28
|
+
}
|
|
29
|
+
function h(e) {
|
|
30
30
|
let t = e.split(".");
|
|
31
31
|
if (t.length > 4 || t.some((e) => e.length === 0)) return null;
|
|
32
32
|
let n = t.map((e) => {
|
|
@@ -39,10 +39,10 @@ function m(e) {
|
|
|
39
39
|
let r = n, i = 2 ** (8 * (5 - r.length));
|
|
40
40
|
return r.slice(0, -1).some((e) => e > 255) || r.at(-1) >= i ? null : r.slice(0, -1).reduce((e, t, n) => e + t * 2 ** (8 * (3 - n)), r.at(-1));
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function g(e) {
|
|
43
43
|
return e >>> 24 == 0 || e >>> 24 == 10 || e >>> 24 == 127 || e >>> 16 == 43518 || e >>> 16 == 49320 || e >>> 20 == 2753;
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function _(e) {
|
|
46
46
|
let t;
|
|
47
47
|
try {
|
|
48
48
|
t = decodeURIComponent(e).toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
|
|
@@ -50,44 +50,44 @@ function g(e) {
|
|
|
50
50
|
return !0;
|
|
51
51
|
}
|
|
52
52
|
if (t === "localhost" || t.endsWith(".localhost") || t.endsWith(".local") || t.endsWith(".internal")) return !0;
|
|
53
|
-
let n = t.match(/^::ffff:(\d+(?:\.\d+){0,3})$/)?.[1], r = t.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i), i = r ? Number.parseInt(r[1], 16) * 65536 + Number.parseInt(r[2], 16) :
|
|
54
|
-
if (i !== null) return
|
|
53
|
+
let n = t.match(/^::ffff:(\d+(?:\.\d+){0,3})$/)?.[1], r = t.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i), i = r ? Number.parseInt(r[1], 16) * 65536 + Number.parseInt(r[2], 16) : h(n || t);
|
|
54
|
+
if (i !== null) return g(i);
|
|
55
55
|
let a = Number.parseInt(t.split(":", 1)[0], 16);
|
|
56
56
|
return t === "::" || t === "::1" || Number.isInteger(a) && (a & 65024) == 64512 || Number.isInteger(a) && (a & 65472) == 65152;
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function v(e) {
|
|
59
59
|
return (e.match(/https?:\/\/\[[^\]]+\](?::\d+)?[^\s<>{}"']*|https?:\/\/[^\s<>{}"'[\]()]+/gi) || []).some((e) => {
|
|
60
60
|
let t = e.replace(/[.,;:!?]+$/, "").replace(/\\/g, "/");
|
|
61
61
|
try {
|
|
62
62
|
let e = new URL(t);
|
|
63
|
-
return !!(e.username || e.password) ||
|
|
63
|
+
return !!(e.username || e.password) || _(e.hostname);
|
|
64
64
|
} catch {
|
|
65
65
|
return !0;
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
-
function
|
|
70
|
-
return
|
|
69
|
+
function y(e, t = 0) {
|
|
70
|
+
return x(e, t, 8192);
|
|
71
71
|
}
|
|
72
|
-
function
|
|
73
|
-
return
|
|
72
|
+
function b(e, t, n) {
|
|
73
|
+
return x(e, 0, [
|
|
74
74
|
"langgraph",
|
|
75
75
|
"adk",
|
|
76
76
|
"codex"
|
|
77
77
|
].includes(String(t)) && !String(n || "").toLowerCase().includes("a2a") ? Infinity : 8192);
|
|
78
78
|
}
|
|
79
|
-
function
|
|
80
|
-
return t > 8 ? "[truncated]" : typeof e == "string" ? /bearer\s+\S+|traceback|(?:token|authorization|api[_ .-]?key|access[_ .-]?token|refresh[_ .-]?token|secretaccesskey|accesstoken|refreshtoken|cookie|password|secret)\s*["']?\s*[=:]/i.test(e) ||
|
|
79
|
+
function x(e, t, n) {
|
|
80
|
+
return t > 8 ? "[truncated]" : typeof e == "string" ? /bearer\s+\S+|traceback|(?:token|authorization|api[_ .-]?key|access[_ .-]?token|refresh[_ .-]?token|secretaccesskey|accesstoken|refreshtoken|cookie|password|secret)\s*["']?\s*[=:]/i.test(e) || v(e) ? "[redacted]" : e.length > n ? `${e.slice(0, n)}[truncated]` : e : Array.isArray(e) ? e.slice(0, 128).map((e) => x(e, t + 1, n)) : e && typeof e == "object" ? Object.fromEntries(Object.entries(e).slice(0, 128).filter(([e]) => !m(e)).map(([e, r]) => [e, x(r, t + 1, n)])) : e;
|
|
81
81
|
}
|
|
82
82
|
//#endregion
|
|
83
83
|
//#region src/core/conversation/runtime-ingress.ts
|
|
84
|
-
var
|
|
84
|
+
var S = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, C = (e, t, n) => JSON.stringify([
|
|
85
85
|
e,
|
|
86
86
|
t,
|
|
87
87
|
n
|
|
88
|
-
]),
|
|
89
|
-
runtime = new
|
|
90
|
-
flatChildren = new
|
|
88
|
+
]), w = class {
|
|
89
|
+
runtime = new e();
|
|
90
|
+
flatChildren = new u();
|
|
91
91
|
seen = /* @__PURE__ */ new Set();
|
|
92
92
|
parents = /* @__PURE__ */ new Map();
|
|
93
93
|
descriptorItemIds = /* @__PURE__ */ new Map();
|
|
@@ -97,11 +97,11 @@ var x = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, S = (e,
|
|
|
97
97
|
sessionId;
|
|
98
98
|
conversation;
|
|
99
99
|
profile;
|
|
100
|
-
constructor(e, t = new
|
|
100
|
+
constructor(e, t = new u(), n = "flat-v1") {
|
|
101
101
|
this.sessionId = e, this.conversation = t, this.profile = n;
|
|
102
102
|
}
|
|
103
103
|
identity(e, t, n, r = !1) {
|
|
104
|
-
return this.profile === "agent-block-v1" || r ?
|
|
104
|
+
return this.profile === "agent-block-v1" || r ? C(e, t, n) : n;
|
|
105
105
|
}
|
|
106
106
|
snapshot() {
|
|
107
107
|
let e = this.conversation.snapshot();
|
|
@@ -119,13 +119,13 @@ var x = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, S = (e,
|
|
|
119
119
|
if (!t || !n || !r) throw Error("RuntimeEvent identity missing");
|
|
120
120
|
if (this.runId && this.runId !== t) throw Error("RuntimeEvent run identity changed");
|
|
121
121
|
if (this.seen.has(r)) return null;
|
|
122
|
-
let a = String(e.parent_scope_id ?? this.descriptors.get(n)?.parent_scope_id ?? this.parents.get(n) ?? ""), o =
|
|
122
|
+
let a = String(e.parent_scope_id ?? this.descriptors.get(n)?.parent_scope_id ?? this.parents.get(n) ?? ""), o = S(e.source), s = [
|
|
123
123
|
"adk",
|
|
124
124
|
"langgraph",
|
|
125
125
|
"codex"
|
|
126
126
|
].includes(String(o.framework)) && !this.descriptors.has(n);
|
|
127
|
-
if (
|
|
128
|
-
if (i.startsWith("run.") && (a || !
|
|
127
|
+
if (s && a && i === "run.progress") return null;
|
|
128
|
+
if (i.startsWith("run.") && (a || !s && this.rootScope && n !== this.rootScope)) throw Error("Child scope cannot transition root run");
|
|
129
129
|
if (this.parents.has(n) && this.parents.get(n) !== a) throw Error("Scope parent changed");
|
|
130
130
|
let l = String(e.item_id || ""), u = this.identity(t, n, l || r, !!a), d = Object.fromEntries(Object.entries({
|
|
131
131
|
framework: o.framework,
|
|
@@ -152,7 +152,7 @@ var x = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, S = (e,
|
|
|
152
152
|
payloadSchemaRef: "conversation.item.progress/v1",
|
|
153
153
|
payload: {},
|
|
154
154
|
nativeRef: d
|
|
155
|
-
}, p =
|
|
155
|
+
}, p = S(S(e.source).metadata), m = p.conversation_visibility ?? p.visibility;
|
|
156
156
|
if ([
|
|
157
157
|
"public",
|
|
158
158
|
"internal",
|
|
@@ -167,35 +167,35 @@ var x = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, S = (e,
|
|
|
167
167
|
"run.failed",
|
|
168
168
|
"run.canceled",
|
|
169
169
|
"run.cancelled"
|
|
170
|
-
].includes(i) && (f.kind = "error", f.payloadSchemaRef = "conversation.item.error/v1", f.payload.error =
|
|
170
|
+
].includes(i) && (f.kind = "error", f.payloadSchemaRef = "conversation.item.error/v1", f.payload.error = S(e.error).message || e.reason || ""), f.lifecycle = ["run.completed", "run.interrupted"].includes(i) ? "completed" : [
|
|
171
171
|
"run.failed",
|
|
172
172
|
"run.canceled",
|
|
173
173
|
"run.cancelled"
|
|
174
174
|
].includes(i) ? "failed" : "streaming";
|
|
175
175
|
else {
|
|
176
176
|
if (!l) throw Error("RuntimeEvent item identity missing");
|
|
177
|
-
let d =
|
|
178
|
-
let t =
|
|
177
|
+
let d = S(e.snapshot || e.initial), p = i === "item.updated" ? [S(e.update)] : Array.isArray(d.parts) ? d.parts : [], h = p.map((e) => {
|
|
178
|
+
let t = S(e);
|
|
179
179
|
return {
|
|
180
180
|
partId: String(t.part_id || "part"),
|
|
181
181
|
contentType: String(t.content_type || "data"),
|
|
182
182
|
...typeof t.text == "string" ? { text: t.text } : {},
|
|
183
183
|
value: t
|
|
184
184
|
};
|
|
185
|
-
}), g = p.map((e) =>
|
|
186
|
-
if (a && !g && !
|
|
185
|
+
}), g = p.map((e) => S(S(e).data)).find((e) => e.schema === "execution.scope/v1");
|
|
186
|
+
if (a && !g && !s) {
|
|
187
187
|
let e = this.descriptorItemIds.get(n);
|
|
188
188
|
if (!e) throw Error("Child content requires its scope descriptor first");
|
|
189
189
|
f.parentItemId = e;
|
|
190
190
|
}
|
|
191
191
|
if (g) {
|
|
192
192
|
if (this.descriptorItemIds.has(n) && this.descriptorItemIds.get(n) !== u) throw Error("Scope descriptor item identity changed");
|
|
193
|
-
let e =
|
|
193
|
+
let e = S(g.trigger_ref);
|
|
194
194
|
if (g.scope_id !== n || g.parent_scope_id !== a || e.scope_id !== a || !e.item_id || !e.call_id || !a) throw Error("Invalid scope descriptor locator");
|
|
195
195
|
let t = this.runtime.snapshot().items.find((t) => t.scopeId === e.scope_id && t.itemId === e.item_id);
|
|
196
|
-
if (t && !t.parts.some((t) =>
|
|
196
|
+
if (t && !t.parts.some((t) => S(t.value).call_id === e.call_id)) throw Error("Scope trigger call mismatch");
|
|
197
197
|
let r = this.descriptors.get(n);
|
|
198
|
-
|
|
198
|
+
c({
|
|
199
199
|
...f,
|
|
200
200
|
kind: "agent",
|
|
201
201
|
payloadSchemaRef: "conversation.item.agent/v1",
|
|
@@ -207,15 +207,15 @@ var x = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, S = (e,
|
|
|
207
207
|
} : void 0), this.descriptors.set(n, g), this.descriptorItemIds.set(n, u);
|
|
208
208
|
}
|
|
209
209
|
for (let e of this.descriptors.values()) {
|
|
210
|
-
let t =
|
|
211
|
-
if (t.scope_id === n && t.item_id === l && h.length && !h.some((e) =>
|
|
210
|
+
let t = S(e.trigger_ref);
|
|
211
|
+
if (t.scope_id === n && t.item_id === l && h.length && !h.some((e) => S(e.value).call_id === t.call_id)) throw Error("Scope trigger call mismatch");
|
|
212
212
|
}
|
|
213
213
|
let _ = this.runtime.snapshot().items.find((e) => e.scopeId === n && e.itemId === l);
|
|
214
|
-
if (a && !
|
|
214
|
+
if (a && !s && _ && _.status !== "open") {
|
|
215
215
|
if (i === "item.updated" || i === "item.started") throw Error("Remote item cannot reopen");
|
|
216
216
|
if (Array.isArray(d.parts) && JSON.stringify(_.parts) !== JSON.stringify(h)) throw Error("Remote terminal content conflict");
|
|
217
217
|
}
|
|
218
|
-
let
|
|
218
|
+
let v = {
|
|
219
219
|
type: i.replaceAll(".", "_"),
|
|
220
220
|
runId: t,
|
|
221
221
|
scopeId: n,
|
|
@@ -231,52 +231,52 @@ var x = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, S = (e,
|
|
|
231
231
|
op: e.op || "replace"
|
|
232
232
|
} : {}
|
|
233
233
|
};
|
|
234
|
-
this.runtime.apply(
|
|
235
|
-
let
|
|
236
|
-
if (!
|
|
234
|
+
this.runtime.apply(v);
|
|
235
|
+
let x = this.runtime.snapshot().items.find((e) => e.scopeId === n && e.itemId === l);
|
|
236
|
+
if (!x || a && x.itemKind === "status" && x.status === "open" && !x.parts.length) return null;
|
|
237
237
|
if (a && [
|
|
238
238
|
"artifact",
|
|
239
239
|
"tool_call",
|
|
240
240
|
"tool_result"
|
|
241
|
-
].includes(
|
|
242
|
-
let C =
|
|
243
|
-
if (f.lifecycle =
|
|
244
|
-
else if (
|
|
241
|
+
].includes(x.itemKind) && !x.parts.length) return this.runId = t, this.parents.set(n, a), this.seen.add(r), null;
|
|
242
|
+
let C = x.parts.map((e) => S(e.value)), w = C.map((e) => S(e.data)).find((e) => e.schema === "execution.scope/v1");
|
|
243
|
+
if (f.lifecycle = x.status === "open" ? i === "item.started" ? "pending" : "streaming" : x.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(S(w.trigger_ref).scope_id), String(S(w.trigger_ref).item_id), !!this.parents.get(String(S(w.trigger_ref).scope_id))), f.capabilityRef = "agent.block";
|
|
244
|
+
else if (x.itemKind === "tool_call" || x.itemKind === "tool_result") {
|
|
245
245
|
let e = C.find((e) => e.content_type === "tool_call"), t = C.find((e) => e.content_type === "tool_result");
|
|
246
246
|
f.kind = "tool_call", f.capabilityRef = "tool.inspect", f.payloadSchemaRef = "conversation.item.tool-call/v1", f.payload = {
|
|
247
247
|
...e ? {
|
|
248
248
|
callId: e.call_id,
|
|
249
249
|
tool: e.name,
|
|
250
|
-
args:
|
|
250
|
+
args: y(e.arguments)
|
|
251
251
|
} : {},
|
|
252
252
|
...t ? {
|
|
253
253
|
callId: t.call_id,
|
|
254
|
-
output:
|
|
254
|
+
output: b(t.result, o.framework, o.protocol),
|
|
255
255
|
isError: t.is_error
|
|
256
256
|
} : {},
|
|
257
|
-
executionStatus:
|
|
258
|
-
sourceKind:
|
|
257
|
+
executionStatus: x.status === "failed" ? "failed" : t && x.status !== "open" ? t.is_error ? "failed" : "completed" : x.itemKind === "tool_result" ? "unknown" : "running",
|
|
258
|
+
sourceKind: x.itemKind
|
|
259
259
|
};
|
|
260
|
-
} else if (
|
|
260
|
+
} else if (x.itemKind === "data" && o.protocol === "a2ui") {
|
|
261
261
|
let e = C.find((e) => e.content_type === "data")?.data;
|
|
262
262
|
f.kind = "a2ui", f.payloadSchemaRef = "conversation.item.a2ui/v1", f.payload = {
|
|
263
|
-
surfaceId: String(
|
|
264
|
-
...typeof
|
|
263
|
+
surfaceId: String(S(o.metadata).surface_id || ""),
|
|
264
|
+
...typeof S(o.metadata).interaction_id == "string" ? { interactionId: S(o.metadata).interaction_id } : {},
|
|
265
265
|
data: Array.isArray(e) ? e : []
|
|
266
266
|
};
|
|
267
|
-
} else if (
|
|
268
|
-
f.kind =
|
|
269
|
-
let t =
|
|
270
|
-
f.kind === "reasoning" && (t.public_summary === !0 || t.provider_reasoning === !0) && (f.payload.presentationSource = t.public_summary === !0 ? "public_summary" : "provider_reasoning"), i === "item.updated" && e.op === "append" && (f.operation = "append", f.payload.text =
|
|
271
|
-
} else if (
|
|
267
|
+
} else if (x.itemKind === "message" || x.itemKind === "reasoning" || x.itemKind === "artifact" && x.parts.length > 0 && x.parts.every((e) => e.contentType === "text")) {
|
|
268
|
+
f.kind = x.itemKind === "reasoning" ? "reasoning" : S(S(e.source).metadata).native_item_kind === "userMessage" ? "user_message" : "assistant_text", f.payloadSchemaRef = `conversation.item.${f.kind}/v1`, f.payload = { text: x.parts.map((e) => e.text || "").join("") };
|
|
269
|
+
let t = S(o.metadata);
|
|
270
|
+
f.kind === "reasoning" && (t.public_summary === !0 || t.provider_reasoning === !0) && (f.payload.presentationSource = t.public_summary === !0 ? "public_summary" : "provider_reasoning"), i === "item.updated" && e.op === "append" && (f.operation = "append", f.payload.text = S(e.update).text || "");
|
|
271
|
+
} else if (x.itemKind === "artifact") {
|
|
272
272
|
let e = C.find((e) => e.content_type === "artifact") || {};
|
|
273
273
|
f.kind = "artifact", f.payloadSchemaRef = "conversation.item.artifact/v1", f.payload = {
|
|
274
274
|
name: e.name,
|
|
275
275
|
mimeType: e.mime_type,
|
|
276
276
|
uri: e.uri
|
|
277
277
|
};
|
|
278
|
-
} else if (
|
|
279
|
-
let t =
|
|
278
|
+
} else if (x.status === "failed") {
|
|
279
|
+
let t = S(e.error);
|
|
280
280
|
f.kind = "error", f.payloadSchemaRef = "conversation.item.error/v1", f.payload = { error: String(t.message || t.code || "Remote call failed") };
|
|
281
281
|
} else f.visibility = m === "public" ? "public" : "hidden", f.kind = "unknown", f.payloadSchemaRef = "conversation.item.unknown/v1", f.payload = { summary: "Unsupported runtime content" };
|
|
282
282
|
}
|
|
@@ -285,11 +285,11 @@ var x = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, S = (e,
|
|
|
285
285
|
};
|
|
286
286
|
//#endregion
|
|
287
287
|
//#region src/core/a2ui/history.ts
|
|
288
|
-
function
|
|
288
|
+
function T(e, t) {
|
|
289
289
|
let n = e.map((e) => JSON.stringify(e)), r = t.map((e) => JSON.stringify(e));
|
|
290
290
|
return n.every((e, t) => r[t] === e) ? t : r.every((e, t) => n[t] === e) ? e : [...e, ...t];
|
|
291
291
|
}
|
|
292
|
-
function
|
|
292
|
+
function ee(e, t, n) {
|
|
293
293
|
let r = {
|
|
294
294
|
...t.runId || e?.runId ? { runId: t.runId || e?.runId } : {},
|
|
295
295
|
...t.interactionId || e?.interactionId ? { interactionId: t.interactionId || e?.interactionId } : {},
|
|
@@ -301,7 +301,7 @@ function T(e, t, n) {
|
|
|
301
301
|
} : {
|
|
302
302
|
...t,
|
|
303
303
|
...r,
|
|
304
|
-
messages: e ?
|
|
304
|
+
messages: e ? T(e.messages, t.messages) : t.messages,
|
|
305
305
|
...n || e?.batchIds || t.batchIds ? { batchIds: [...new Set([
|
|
306
306
|
...e?.batchIds || [],
|
|
307
307
|
...t.batchIds || [],
|
|
@@ -311,28 +311,28 @@ function T(e, t, n) {
|
|
|
311
311
|
}
|
|
312
312
|
//#endregion
|
|
313
313
|
//#region src/core/a2ui/transcript.ts
|
|
314
|
-
function
|
|
314
|
+
function E(e, t) {
|
|
315
315
|
if (e.activity.surfaceId !== t.activity.surfaceId) return !1;
|
|
316
316
|
let n = e.activity.interactionId, r = t.activity.interactionId;
|
|
317
317
|
if (n && r) return n === r;
|
|
318
318
|
let i = e.activity.runId || e.message.runId || e.message.invocationId, a = t.activity.runId || t.message.runId || t.message.invocationId;
|
|
319
319
|
return i && a ? i === a : (e.activity.originMessageId || e.message.id) === (t.activity.originMessageId || t.message.id);
|
|
320
320
|
}
|
|
321
|
-
function
|
|
322
|
-
let n = e.filter((e) =>
|
|
321
|
+
function te(e, t) {
|
|
322
|
+
let n = e.filter((e) => E(e, t));
|
|
323
323
|
return n.length === 1 ? n[0] : void 0;
|
|
324
324
|
}
|
|
325
|
-
function
|
|
325
|
+
function ne(e) {
|
|
326
326
|
if (!e.some((e) => e.aguiActivity || e.aguiActivities?.length)) return e;
|
|
327
327
|
let t = /* @__PURE__ */ new Map(), n = !1, r = e.map((e) => {
|
|
328
328
|
let r = (r) => {
|
|
329
|
-
let i = t.get(r.surfaceId) || [], a =
|
|
329
|
+
let i = t.get(r.surfaceId) || [], a = te(i, {
|
|
330
330
|
message: e,
|
|
331
331
|
activity: r
|
|
332
332
|
});
|
|
333
333
|
if (a) {
|
|
334
334
|
let t = a.activity;
|
|
335
|
-
n = !0, t.messages =
|
|
335
|
+
n = !0, t.messages = T(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 || []])];
|
|
336
336
|
return;
|
|
337
337
|
}
|
|
338
338
|
let o = r.runId || e.runId || e.invocationId, s = {
|
|
@@ -357,7 +357,7 @@ function D(e) {
|
|
|
357
357
|
}
|
|
358
358
|
//#endregion
|
|
359
359
|
//#region src/core/conversation/presentation.ts
|
|
360
|
-
var
|
|
360
|
+
var re = {
|
|
361
361
|
user_message: "conversation.item.user_message/v1",
|
|
362
362
|
assistant_text: "conversation.item.assistant_text/v1",
|
|
363
363
|
reasoning: "conversation.item.reasoning/v1",
|
|
@@ -368,10 +368,10 @@ var te = {
|
|
|
368
368
|
a2ui: "conversation.item.a2ui/v1",
|
|
369
369
|
error: "conversation.item.error/v1"
|
|
370
370
|
};
|
|
371
|
-
function
|
|
371
|
+
function ie(e) {
|
|
372
372
|
return e.lifecycle === "completed" || e.lifecycle === "failed";
|
|
373
373
|
}
|
|
374
|
-
var
|
|
374
|
+
var ae = new Set([
|
|
375
375
|
"aborted",
|
|
376
376
|
"canceled",
|
|
377
377
|
"cancelled",
|
|
@@ -379,17 +379,17 @@ var re = new Set([
|
|
|
379
379
|
"incomplete",
|
|
380
380
|
"interrupted"
|
|
381
381
|
]);
|
|
382
|
-
function
|
|
383
|
-
if (e.parentItemId || e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || e.kind !== "progress" && e.kind !== "error" || !
|
|
382
|
+
function D(e) {
|
|
383
|
+
if (e.parentItemId || e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || e.kind !== "progress" && e.kind !== "error" || !ie(e)) return;
|
|
384
384
|
let t = typeof e.payload.status == "string" ? e.payload.status.toLowerCase() : "";
|
|
385
385
|
if (t === "completed") return "completed";
|
|
386
|
-
if (
|
|
386
|
+
if (ae.has(t)) return "failed";
|
|
387
387
|
}
|
|
388
|
-
function
|
|
389
|
-
let t =
|
|
388
|
+
function oe(e) {
|
|
389
|
+
let t = re[e.kind];
|
|
390
390
|
return t === void 0 || t === e.payloadSchemaRef;
|
|
391
391
|
}
|
|
392
|
-
function
|
|
392
|
+
function se(e) {
|
|
393
393
|
if (typeof e != "string" || e.length === 0) return null;
|
|
394
394
|
try {
|
|
395
395
|
let t = new URL(e);
|
|
@@ -398,7 +398,7 @@ function ae(e) {
|
|
|
398
398
|
return null;
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
|
-
function
|
|
401
|
+
function ce(e) {
|
|
402
402
|
return {
|
|
403
403
|
id: e.itemId,
|
|
404
404
|
parentId: e.parentItemId || null,
|
|
@@ -408,8 +408,8 @@ function oe(e) {
|
|
|
408
408
|
lifecycle: e.lifecycle
|
|
409
409
|
};
|
|
410
410
|
}
|
|
411
|
-
function
|
|
412
|
-
let t = typeof e.payload.artifactId == "string" && e.payload.artifactId ? e.payload.artifactId : e.itemId, n = e.payload.sizeBytes ?? e.payload.size, r = typeof n == "number" && Number.isFinite(n) && n >= 0 ? n : null, i =
|
|
411
|
+
function le(e) {
|
|
412
|
+
let t = typeof e.payload.artifactId == "string" && e.payload.artifactId ? e.payload.artifactId : e.itemId, n = e.payload.sizeBytes ?? e.payload.size, r = typeof n == "number" && Number.isFinite(n) && n >= 0 ? n : null, i = se(e.payload.uri);
|
|
413
413
|
return {
|
|
414
414
|
artifactId: t,
|
|
415
415
|
itemId: e.itemId,
|
|
@@ -423,13 +423,13 @@ function se(e) {
|
|
|
423
423
|
uri: i
|
|
424
424
|
};
|
|
425
425
|
}
|
|
426
|
-
function
|
|
426
|
+
function O(e, t) {
|
|
427
427
|
let n = e.payload[t];
|
|
428
428
|
return typeof n == "string" && n ? n : null;
|
|
429
429
|
}
|
|
430
|
-
function
|
|
430
|
+
function k(e, t) {
|
|
431
431
|
if (e.kind === "tool_call") {
|
|
432
|
-
let n =
|
|
432
|
+
let n = O(e, "callId");
|
|
433
433
|
if (n) return `tool:${JSON.stringify([
|
|
434
434
|
e.runId,
|
|
435
435
|
t ?? (e.nativeRef.scopeId || e.nativeRef.scope_id || ""),
|
|
@@ -437,17 +437,17 @@ function A(e, t) {
|
|
|
437
437
|
])}`;
|
|
438
438
|
}
|
|
439
439
|
if (e.kind === "approval") {
|
|
440
|
-
let t =
|
|
440
|
+
let t = O(e, "interactionId");
|
|
441
441
|
if (t) return `approval:${t}`;
|
|
442
442
|
}
|
|
443
443
|
if (e.kind === "a2ui") {
|
|
444
|
-
let t =
|
|
444
|
+
let t = O(e, "surfaceId");
|
|
445
445
|
if (t) return `a2ui:${JSON.stringify([e.runId, t])}`;
|
|
446
446
|
}
|
|
447
447
|
return `item:${e.itemId}`;
|
|
448
448
|
}
|
|
449
|
-
function
|
|
450
|
-
let n =
|
|
449
|
+
function ue(e, t) {
|
|
450
|
+
let n = ie(e) && !ie(t), r = e.kind === "a2ui" && t.kind === "a2ui" && Array.isArray(e.payload.data) && Array.isArray(t.payload.data) ? { data: T(e.payload.data, t.payload.data) } : {};
|
|
451
451
|
return {
|
|
452
452
|
...e,
|
|
453
453
|
...t,
|
|
@@ -473,32 +473,32 @@ function ce(e, t) {
|
|
|
473
473
|
} : {}
|
|
474
474
|
};
|
|
475
475
|
}
|
|
476
|
-
function
|
|
476
|
+
function de(e) {
|
|
477
477
|
let t = [], n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map(), s = (e) => {
|
|
478
478
|
let t = e.nativeRef.parentScopeId;
|
|
479
|
-
return e.nativeRef.framework === "langgraph" && e.kind === "tool_call" && e.payload.sourceKind === "tool_result" && e.payload.callId && typeof t == "string" ?
|
|
479
|
+
return e.nativeRef.framework === "langgraph" && e.kind === "tool_call" && e.payload.sourceKind === "tool_result" && e.payload.callId && typeof t == "string" ? k(e, t) : void 0;
|
|
480
480
|
};
|
|
481
481
|
for (let t of e) {
|
|
482
482
|
if (t.nativeRef.framework === "langgraph" && t.payload.sourceKind === "tool_call") {
|
|
483
|
-
let e =
|
|
483
|
+
let e = k(t);
|
|
484
484
|
i.set(e, (i.get(e) ?? 0) + 1);
|
|
485
485
|
}
|
|
486
|
-
t.kind === "tool_call" && t.payload.sourceKind === "tool_result" && a.add(
|
|
486
|
+
t.kind === "tool_call" && t.payload.sourceKind === "tool_result" && a.add(k(t));
|
|
487
487
|
let e = s(t);
|
|
488
488
|
e && o.set(e, (o.get(e) ?? 0) + 1);
|
|
489
489
|
}
|
|
490
490
|
for (let c of e) {
|
|
491
|
-
let e =
|
|
492
|
-
surfaceId:
|
|
491
|
+
let e = k(c), l = s(c), u = l && !i.has(e) && !a.has(l) && i.get(l) === 1 && o.get(l) === 1 ? l : e, d = c.kind === "a2ui" ? {
|
|
492
|
+
surfaceId: O(c, "surfaceId") || "",
|
|
493
493
|
messages: [],
|
|
494
|
-
...
|
|
494
|
+
...O(c, "interactionId") ? { interactionId: O(c, "interactionId") } : {}
|
|
495
495
|
} : null, f = d ? {
|
|
496
496
|
message: {
|
|
497
497
|
id: c.itemId,
|
|
498
498
|
runId: c.runId
|
|
499
499
|
},
|
|
500
500
|
activity: d
|
|
501
|
-
} : null, p = r.get(u) || [], m = f ?
|
|
501
|
+
} : null, p = r.get(u) || [], m = f ? te(p, f) : void 0, h = f ? m?.index : n.get(u);
|
|
502
502
|
if (h === void 0) {
|
|
503
503
|
f ? r.set(u, [...p, {
|
|
504
504
|
...f,
|
|
@@ -514,7 +514,7 @@ function le(e) {
|
|
|
514
514
|
let g = t[h];
|
|
515
515
|
t[h] = {
|
|
516
516
|
key: g.key,
|
|
517
|
-
item:
|
|
517
|
+
item: ue(g.item, c),
|
|
518
518
|
sourceItemIds: [...new Set([...g.sourceItemIds, c.itemId])]
|
|
519
519
|
};
|
|
520
520
|
}
|
|
@@ -529,29 +529,29 @@ function le(e) {
|
|
|
529
529
|
}
|
|
530
530
|
} : t);
|
|
531
531
|
}
|
|
532
|
-
function
|
|
532
|
+
function fe(e, t) {
|
|
533
533
|
let n = e.payload.trigger_ref;
|
|
534
534
|
return n ? t.filter((t) => t.kind === "tool_call" && t.runId === e.runId && (t.nativeRef.scopeId || t.nativeRef.scope_id) === n.scope_id && (t.payload.callId === n.call_id || t.itemId === e.parentItemId)) : [];
|
|
535
535
|
}
|
|
536
|
-
function
|
|
537
|
-
let t = e.filter((e) => e.kind === "agent"), n = (e) => String(e.nativeRef.scopeId || e.nativeRef.scope_id || ""), r = (e) => t.find((t) => t.runId === e.runId && t.itemId !== e.itemId && (e.parentItemId === t.itemId || (e.kind === "agent" ? e.payload.parent_scope_id === t.payload.scope_id : n(e) && n(e) === String(t.payload.scope_id)))), i = new Set(t.flatMap((t) =>
|
|
536
|
+
function pe(e) {
|
|
537
|
+
let t = e.filter((e) => e.kind === "agent"), n = (e) => String(e.nativeRef.scopeId || e.nativeRef.scope_id || ""), r = (e) => t.find((t) => t.runId === e.runId && t.itemId !== e.itemId && (e.parentItemId === t.itemId || (e.kind === "agent" ? e.payload.parent_scope_id === t.payload.scope_id : n(e) && n(e) === String(t.payload.scope_id)))), i = new Set(t.flatMap((t) => fe(t, e).map((e) => e.itemId))), a = e.filter((e) => !r(e) && !i.has(e.itemId));
|
|
538
538
|
return a.sort((t, n) => {
|
|
539
539
|
let r = (t) => t.kind === "agent" && t.parentItemId && e.some((e) => e.itemId === t.parentItemId) ? e.findIndex((e) => e.itemId === t.parentItemId) : e.indexOf(t);
|
|
540
540
|
return r(t) - r(n);
|
|
541
|
-
}),
|
|
541
|
+
}), de(a).map((t) => {
|
|
542
542
|
if (t.item.kind !== "agent") return t;
|
|
543
|
-
let n =
|
|
543
|
+
let n = de(e.filter((e) => r(e) === t.item && !i.has(e.itemId)));
|
|
544
544
|
return {
|
|
545
545
|
...t,
|
|
546
|
-
sourceItemIds: [...new Set([...
|
|
546
|
+
sourceItemIds: [...new Set([...fe(t.item, e).map((e) => e.itemId), ...t.sourceItemIds])],
|
|
547
547
|
children: n
|
|
548
548
|
};
|
|
549
549
|
});
|
|
550
550
|
}
|
|
551
|
-
function
|
|
551
|
+
function me(e, t = {}) {
|
|
552
552
|
let n = e.items.filter((e) => e.visibility === "public" || t.includeInternal === !0 && e.visibility === "internal");
|
|
553
553
|
if (t.profile === "flat-v1" && n.some((e) => e.kind === "agent")) {
|
|
554
|
-
let e = n.filter((e) => e.kind === "agent"), t = new Set(e.flatMap((e) =>
|
|
554
|
+
let e = n.filter((e) => e.kind === "agent"), t = new Set(e.flatMap((e) => 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) => D(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;
|
|
555
555
|
Array.isArray(o) && o.length && (a = a.filter((e) => e.kind !== "assistant_text" || o.some((t) => e.nativeRef.scopeId === t.scope_id && e.nativeRef.runtimeItemId === t.item_id)));
|
|
556
556
|
let s = a.filter((e) => e.kind === "assistant_text");
|
|
557
557
|
if (i && !s.some((e) => e.payload.text) && Array.isArray(o)) {
|
|
@@ -567,13 +567,13 @@ function de(e, t = {}) {
|
|
|
567
567
|
}
|
|
568
568
|
n = a.filter((e) => e.kind !== "assistant_text" || !!i);
|
|
569
569
|
}
|
|
570
|
-
let r = n.filter(
|
|
570
|
+
let r = n.filter(oe), i = n.filter((e) => !oe(e)), a = new Set([
|
|
571
571
|
"user_message",
|
|
572
572
|
"assistant_text",
|
|
573
573
|
"reasoning"
|
|
574
|
-
]), o = r.filter((e) => a.has(e.kind)).map(
|
|
574
|
+
]), o = r.filter((e) => a.has(e.kind)).map(ce), 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) => D(e) !== void 0);
|
|
575
575
|
return {
|
|
576
|
-
timeline:
|
|
576
|
+
timeline: pe(r.filter((e) => e.kind !== "progress")),
|
|
577
577
|
output: c("assistant_text"),
|
|
578
578
|
reasoning: c("reasoning"),
|
|
579
579
|
textItems: o,
|
|
@@ -581,7 +581,7 @@ function de(e, t = {}) {
|
|
|
581
581
|
approvalItems: r.filter((e) => e.kind === "approval"),
|
|
582
582
|
structuredInputItems: r.filter((e) => e.kind === "progress" && e.payloadSchemaRef === "conversation.item.structured-input/v1"),
|
|
583
583
|
a2uiItems: r.filter((e) => e.kind === "a2ui"),
|
|
584
|
-
artifacts: r.filter((e) => e.kind === "artifact").map(
|
|
584
|
+
artifacts: r.filter((e) => e.kind === "artifact").map(le),
|
|
585
585
|
fallbacks: [...l.map((e) => ({
|
|
586
586
|
id: e.itemId,
|
|
587
587
|
title: "Unsupported content",
|
|
@@ -594,22 +594,22 @@ function de(e, t = {}) {
|
|
|
594
594
|
failed: !0
|
|
595
595
|
}))],
|
|
596
596
|
runId: n.at(-1)?.runId || "",
|
|
597
|
-
terminalStatus: d ?
|
|
597
|
+
terminalStatus: d ? D(d) : void 0
|
|
598
598
|
};
|
|
599
599
|
}
|
|
600
600
|
//#endregion
|
|
601
601
|
//#region src/core/conversation/client.ts
|
|
602
|
-
var
|
|
603
|
-
function
|
|
602
|
+
var A = 8;
|
|
603
|
+
function j(e) {
|
|
604
604
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
605
605
|
}
|
|
606
|
-
function
|
|
607
|
-
if (e?.aborted) throw new
|
|
606
|
+
function M(e) {
|
|
607
|
+
if (e?.aborted) throw new l("conversation_aborted", "Conversation request was aborted.");
|
|
608
608
|
}
|
|
609
|
-
function
|
|
609
|
+
function he(e, t) {
|
|
610
610
|
return t?.aborted === !0 || e instanceof Error && e.name === "AbortError";
|
|
611
611
|
}
|
|
612
|
-
function
|
|
612
|
+
function ge(e) {
|
|
613
613
|
let t = e.trim().replace(/\/+$/, "");
|
|
614
614
|
if (!t) return "";
|
|
615
615
|
if (!t.includes("://")) return t.startsWith("/") ? t : `/${t}`;
|
|
@@ -618,46 +618,46 @@ function pe(e) {
|
|
|
618
618
|
if (e.protocol !== "http:" && e.protocol !== "https:" || e.username || e.password) throw Error("unsafe URL");
|
|
619
619
|
return e.toString().replace(/\/$/, "");
|
|
620
620
|
} catch (e) {
|
|
621
|
-
throw new
|
|
621
|
+
throw new l("conversation_contract_mismatch", "Conversation base URL must be an HTTP(S) URL without embedded credentials.", { cause: e });
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
|
-
function
|
|
624
|
+
function _e(e) {
|
|
625
625
|
return Math.min(200 * 2 ** Math.max(0, e - 1), 2e3);
|
|
626
626
|
}
|
|
627
|
-
function
|
|
627
|
+
function ve(e) {
|
|
628
628
|
return new Promise((t) => {
|
|
629
629
|
setTimeout(t, e);
|
|
630
630
|
});
|
|
631
631
|
}
|
|
632
|
-
async function
|
|
633
|
-
if (
|
|
632
|
+
async function ye(e, t, n) {
|
|
633
|
+
if (M(n), !n) {
|
|
634
634
|
await e(t);
|
|
635
635
|
return;
|
|
636
636
|
}
|
|
637
637
|
await new Promise((r, i) => {
|
|
638
|
-
let a = () => i(new
|
|
638
|
+
let a = () => i(new l("conversation_aborted", "Conversation request was aborted."));
|
|
639
639
|
n.addEventListener("abort", a, { once: !0 }), e(t).then(r, i).finally(() => {
|
|
640
640
|
n.removeEventListener("abort", a);
|
|
641
641
|
});
|
|
642
642
|
});
|
|
643
643
|
}
|
|
644
|
-
function
|
|
644
|
+
function N(e, t, n, r, i) {
|
|
645
645
|
let a = i ? i.snapshot() : e.snapshot();
|
|
646
646
|
return {
|
|
647
647
|
cursor: t,
|
|
648
648
|
runId: n,
|
|
649
649
|
state: a,
|
|
650
|
-
presentation:
|
|
650
|
+
presentation: me(a, { profile: r })
|
|
651
651
|
};
|
|
652
652
|
}
|
|
653
|
-
function
|
|
653
|
+
function be(e, t) {
|
|
654
654
|
let n, r = [];
|
|
655
655
|
for (let t of e.split(/\r?\n/)) {
|
|
656
656
|
let e = t.endsWith("\r") ? t.slice(0, -1) : t;
|
|
657
657
|
if (!e || e.startsWith(":")) continue;
|
|
658
658
|
let i = e.indexOf(":"), a = i < 0 ? e : e.slice(0, i), o = i < 0 ? "" : e.slice(i + 1), s = o.startsWith(" ") ? o.slice(1) : o;
|
|
659
659
|
if (a === "id") {
|
|
660
|
-
if (!/^\d+$/.test(s) || !Number.isSafeInteger(Number(s))) throw new
|
|
660
|
+
if (!/^\d+$/.test(s) || !Number.isSafeInteger(Number(s))) throw new l("conversation_stream_error", "Conversation stream contains an invalid replay cursor.");
|
|
661
661
|
n = Number(s);
|
|
662
662
|
} else a === "data" && r.push(s);
|
|
663
663
|
}
|
|
@@ -668,31 +668,31 @@ function ve(e, t) {
|
|
|
668
668
|
try {
|
|
669
669
|
a = JSON.parse(i);
|
|
670
670
|
} catch (e) {
|
|
671
|
-
throw new
|
|
671
|
+
throw new l("conversation_contract_mismatch", "Conversation stream contains invalid JSON.", { cause: e });
|
|
672
672
|
}
|
|
673
|
-
let
|
|
674
|
-
if (!
|
|
673
|
+
let o = j(a), c = j(o?.runtimeEvent) || j(o?.runtime_event) || (o?.schema_version === 2 ? o : null);
|
|
674
|
+
if (!o || o.conversationItem === void 0 && !c) {
|
|
675
675
|
n !== void 0 && (t.cursor = Math.max(t.cursor, n));
|
|
676
676
|
return;
|
|
677
677
|
}
|
|
678
|
-
if (n === void 0) throw new
|
|
679
|
-
let u =
|
|
678
|
+
if (n === void 0) throw new l("conversation_stream_error", "Canonical conversation items require an SSE replay cursor.");
|
|
679
|
+
let u = o.conversationItem === void 0 ? "runtime" : "native";
|
|
680
680
|
if (t.lane && t.lane !== u) {
|
|
681
681
|
t.cursor = Math.max(t.cursor, n);
|
|
682
682
|
return;
|
|
683
683
|
}
|
|
684
684
|
let d;
|
|
685
685
|
try {
|
|
686
|
-
d = u === "native" ? o
|
|
686
|
+
d = u === "native" ? s(o.conversationItem) : t.runtime.apply(c);
|
|
687
687
|
} catch (e) {
|
|
688
|
-
throw new
|
|
688
|
+
throw new l("conversation_contract_mismatch", "Runtime conversation identity or lifecycle invariant failed.", { cause: e });
|
|
689
689
|
}
|
|
690
690
|
if (u === "runtime" && !d) {
|
|
691
691
|
t.cursor = Math.max(t.cursor, n);
|
|
692
692
|
return;
|
|
693
693
|
}
|
|
694
|
-
if (!d) throw new
|
|
695
|
-
if (t.runId && t.runId !== d.runId) throw new
|
|
694
|
+
if (!d) throw new l("conversation_contract_mismatch", "Conversation stream item does not match conversation.ksadk.io/v1.");
|
|
695
|
+
if (t.runId && t.runId !== d.runId) throw new l("conversation_contract_mismatch", "Conversation stream changed canonical run identity.", {
|
|
696
696
|
runId: t.runId,
|
|
697
697
|
cursor: t.cursor
|
|
698
698
|
});
|
|
@@ -701,28 +701,28 @@ function ve(e, t) {
|
|
|
701
701
|
try {
|
|
702
702
|
f = u === "runtime" ? !0 : t.reducer.apply(d);
|
|
703
703
|
} catch (e) {
|
|
704
|
-
throw new
|
|
704
|
+
throw new l("conversation_contract_mismatch", "Conversation identity or lifecycle invariant failed.", { cause: e });
|
|
705
705
|
}
|
|
706
|
-
t.cursor = Math.max(t.cursor, n), f && !(t.profile === "flat-v1" && d.nativeRef.parentScopeId) && t.options.onItem?.(d), t.options.onUpdate?.(
|
|
706
|
+
t.cursor = Math.max(t.cursor, n), f && !(t.profile === "flat-v1" && d.nativeRef.parentScopeId) && t.options.onItem?.(d), t.options.onUpdate?.(N(t.reducer, t.cursor, t.runId, t.profile, t.lane === "runtime" ? t.runtime : void 0));
|
|
707
707
|
}
|
|
708
|
-
async function
|
|
709
|
-
if (!e.body) throw new
|
|
708
|
+
async function xe(e, t) {
|
|
709
|
+
if (!e.body) throw new l("conversation_stream_error", "Conversation response has no event stream body.");
|
|
710
710
|
let n = e.body.getReader(), r = new TextDecoder(), i = "";
|
|
711
711
|
try {
|
|
712
712
|
for (;;) {
|
|
713
|
-
|
|
713
|
+
M(t.options.signal);
|
|
714
714
|
let { value: e, done: a } = await n.read();
|
|
715
715
|
if (a) break;
|
|
716
716
|
i += r.decode(e, { stream: !0 });
|
|
717
717
|
let o = /\r?\n\r?\n/.exec(i);
|
|
718
718
|
for (; o?.index !== void 0;) {
|
|
719
719
|
let e = o.index, n = o[0].length;
|
|
720
|
-
|
|
720
|
+
be(i.slice(0, e), t), i = i.slice(e + n), o = /\r?\n\r?\n/.exec(i);
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
|
-
i += r.decode(), i.trim() &&
|
|
723
|
+
i += r.decode(), i.trim() && be(i, t);
|
|
724
724
|
} catch (e) {
|
|
725
|
-
throw e instanceof
|
|
725
|
+
throw e instanceof l ? e : (he(e, t.options.signal) && M(t.options.signal), new l("conversation_stream_error", "Conversation event stream was interrupted.", {
|
|
726
726
|
cause: e,
|
|
727
727
|
runId: t.runId || void 0,
|
|
728
728
|
cursor: t.cursor
|
|
@@ -731,10 +731,10 @@ async function ye(e, t) {
|
|
|
731
731
|
n.releaseLock();
|
|
732
732
|
}
|
|
733
733
|
}
|
|
734
|
-
function
|
|
735
|
-
return e.state.items.some((e) =>
|
|
734
|
+
function Se(e) {
|
|
735
|
+
return e.state.items.some((e) => D(e) !== void 0);
|
|
736
736
|
}
|
|
737
|
-
var
|
|
737
|
+
var Ce = class {
|
|
738
738
|
fetcher;
|
|
739
739
|
ingressLane;
|
|
740
740
|
rendererCatalog;
|
|
@@ -743,64 +743,64 @@ var xe = class {
|
|
|
743
743
|
sleep;
|
|
744
744
|
retryDelayMs;
|
|
745
745
|
constructor(e = {}) {
|
|
746
|
-
if (!Number.isInteger(e.maxReconnects ??
|
|
747
|
-
this.fetcher = e.fetch, this.rendererCatalog = e.rendererCatalog, this.ingressLane = e.ingressLane, this.baseUrl =
|
|
746
|
+
if (!Number.isInteger(e.maxReconnects ?? A) || (e.maxReconnects ?? A) < 0 || (e.maxReconnects ?? A) > 32) throw new l("conversation_contract_mismatch", "Conversation reconnect limit must be an integer from 0 to 32.");
|
|
747
|
+
this.fetcher = e.fetch, this.rendererCatalog = e.rendererCatalog, this.ingressLane = e.ingressLane, this.baseUrl = ge(e.baseUrl || ""), this.maxReconnects = e.maxReconnects ?? A, this.sleep = e.sleep || ve, this.retryDelayMs = e.retryDelayMs || _e;
|
|
748
748
|
}
|
|
749
749
|
fetch() {
|
|
750
750
|
if (this.fetcher) return this.fetcher;
|
|
751
751
|
if (typeof globalThis.fetch == "function") return globalThis.fetch.bind(globalThis);
|
|
752
|
-
throw new
|
|
752
|
+
throw new l("conversation_http_error", "No fetch implementation is available for the conversation client.");
|
|
753
753
|
}
|
|
754
754
|
url(e) {
|
|
755
755
|
return `${this.baseUrl}${e}`;
|
|
756
756
|
}
|
|
757
757
|
async request(e, t, n, r = "conversation_stream_error") {
|
|
758
|
-
|
|
758
|
+
M(n);
|
|
759
759
|
try {
|
|
760
760
|
return await this.fetch()(e, t);
|
|
761
761
|
} catch (e) {
|
|
762
|
-
throw e instanceof
|
|
762
|
+
throw e instanceof l ? e : (he(e, n) && M(n), new l(r, "Conversation network request failed.", { cause: e }));
|
|
763
763
|
}
|
|
764
764
|
}
|
|
765
765
|
assertOk(e) {
|
|
766
|
-
if (!e.ok) throw new
|
|
766
|
+
if (!e.ok) throw new l("conversation_http_error", `Conversation endpoint returned HTTP ${e.status}.`, { status: e.status });
|
|
767
767
|
}
|
|
768
768
|
async getSurface(e, t, n = {}) {
|
|
769
|
-
if (!e || !t) throw new
|
|
769
|
+
if (!e || !t) throw new l("conversation_contract_mismatch", "Agent and session identities are required to get a conversation surface.");
|
|
770
770
|
let r = n.signal ? { signal: n.signal } : void 0, i = await this.request(this.url(`/api/v1/agents/${encodeURIComponent(e)}/conversation-surface?sessionId=${encodeURIComponent(t)}`), r, n.signal, "conversation_http_error");
|
|
771
771
|
this.assertOk(i);
|
|
772
772
|
let a;
|
|
773
773
|
try {
|
|
774
774
|
a = await i.json();
|
|
775
775
|
} catch (e) {
|
|
776
|
-
throw new
|
|
776
|
+
throw new l("conversation_contract_mismatch", "Conversation surface response is not valid JSON.", { cause: e });
|
|
777
777
|
}
|
|
778
|
-
let o =
|
|
779
|
-
if (!o || typeof o.buildId != "string" || !o.buildId || !s) throw new
|
|
778
|
+
let o = j(a), s = d(o?.surface);
|
|
779
|
+
if (!o || typeof o.buildId != "string" || !o.buildId || !s) throw new l("conversation_contract_mismatch", "Conversation surface response does not match conversation.ksadk.io/v1.");
|
|
780
780
|
return {
|
|
781
781
|
buildId: o.buildId,
|
|
782
782
|
surface: s
|
|
783
783
|
};
|
|
784
784
|
}
|
|
785
785
|
async streamTurn(e) {
|
|
786
|
-
|
|
787
|
-
let t =
|
|
786
|
+
M(e.signal);
|
|
787
|
+
let t = o(e.bootstrap.surface, this.rendererCatalog), n = {
|
|
788
788
|
...e.input,
|
|
789
789
|
...t === "agent-block-v1" || e.input.extensions?.["ksadk.presentation"] ? { extensions: {
|
|
790
790
|
...e.input.extensions,
|
|
791
791
|
"ksadk.presentation": { profile: t }
|
|
792
792
|
} } : {}
|
|
793
793
|
};
|
|
794
|
-
|
|
795
|
-
let r = e.bootstrap.surface.outputs.find((e) => e.name === "agent.block"),
|
|
796
|
-
if (
|
|
797
|
-
let s =
|
|
794
|
+
a(e.bootstrap.surface, n);
|
|
795
|
+
let r = e.bootstrap.surface.outputs.find((e) => e.name === "agent.block"), i = r?.mode === "native" ? "native" : r?.mode === "translated" ? "runtime" : void 0;
|
|
796
|
+
if (i && this.ingressLane && i !== this.ingressLane) throw new l("conversation_contract_mismatch", "Configured ingress lane disagrees with the conversation surface.");
|
|
797
|
+
let s = i || this.ingressLane || "native", c = new u(), d = {
|
|
798
798
|
profile: t,
|
|
799
799
|
lane: s,
|
|
800
|
-
runtime: new
|
|
800
|
+
runtime: new w(n.sessionId, c, t),
|
|
801
801
|
cursor: 0,
|
|
802
802
|
runId: "",
|
|
803
|
-
reducer:
|
|
803
|
+
reducer: c,
|
|
804
804
|
options: e
|
|
805
805
|
}, f = {
|
|
806
806
|
method: "POST",
|
|
@@ -813,29 +813,29 @@ var xe = class {
|
|
|
813
813
|
}, p = await this.request(this.url(`/api/v1/builds/${encodeURIComponent(e.bootstrap.buildId)}/conversation:stream`), f, e.signal);
|
|
814
814
|
this.assertOk(p);
|
|
815
815
|
try {
|
|
816
|
-
await
|
|
816
|
+
await xe(p, d);
|
|
817
817
|
} catch (e) {
|
|
818
|
-
if (!(e instanceof
|
|
818
|
+
if (!(e instanceof l) || e.code !== "conversation_stream_error" || !d.runId) throw e;
|
|
819
819
|
}
|
|
820
|
-
let m =
|
|
821
|
-
if (
|
|
822
|
-
if (!d.runId) throw new
|
|
820
|
+
let m = N(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0);
|
|
821
|
+
if (Se(m)) return m;
|
|
822
|
+
if (!d.runId) throw new l("conversation_run_identity_missing", "The stream ended before a canonical item supplied its run identity.", { cursor: d.cursor });
|
|
823
823
|
for (let t = 1; t <= this.maxReconnects; t += 1) {
|
|
824
|
-
await
|
|
824
|
+
await ye(this.sleep, this.retryDelayMs(t), e.signal), M(e.signal);
|
|
825
825
|
let n;
|
|
826
826
|
try {
|
|
827
827
|
n = await this.request(this.url(`/api/v1/runs/${encodeURIComponent(d.runId)}/events?after=${d.cursor}${d.profile === "agent-block-v1" ? "&presentationProfile=agent-block-v1" : ""}`), {
|
|
828
828
|
method: "GET",
|
|
829
829
|
headers: { "Last-Event-ID": String(d.cursor) },
|
|
830
830
|
...e.signal ? { signal: e.signal } : {}
|
|
831
|
-
}, e.signal), this.assertOk(n), await
|
|
831
|
+
}, e.signal), this.assertOk(n), await xe(n, d);
|
|
832
832
|
} catch (e) {
|
|
833
|
-
if (e instanceof
|
|
833
|
+
if (e instanceof l && e.code === "conversation_aborted" || e instanceof l && e.code === "conversation_contract_mismatch" || e instanceof l && e.code === "conversation_http_error" && e.status !== void 0 && e.status < 500) throw e;
|
|
834
834
|
continue;
|
|
835
835
|
}
|
|
836
|
-
if (m =
|
|
836
|
+
if (m = N(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0), Se(m)) return m;
|
|
837
837
|
}
|
|
838
|
-
throw new
|
|
838
|
+
throw new l("conversation_reconnect_exhausted", "Conversation replay stopped after the configured reconnect limit.", {
|
|
839
839
|
runId: d.runId,
|
|
840
840
|
cursor: d.cursor
|
|
841
841
|
});
|
|
@@ -843,13 +843,13 @@ var xe = class {
|
|
|
843
843
|
};
|
|
844
844
|
//#endregion
|
|
845
845
|
//#region src/core/conversation/renderer-registry.ts
|
|
846
|
-
function
|
|
846
|
+
function we(e, t) {
|
|
847
847
|
if (!e.trim()) throw Error(`trusted conversation renderer ${t} must not be empty`);
|
|
848
848
|
}
|
|
849
|
-
function
|
|
849
|
+
function Te(e) {
|
|
850
850
|
let t = /* @__PURE__ */ new Map();
|
|
851
851
|
for (let n of e) {
|
|
852
|
-
if (
|
|
852
|
+
if (we(n.id, "id"), we(n.schemaRef, "schemaRef"), !n.kinds.length) throw Error("trusted conversation renderer kinds must not be empty");
|
|
853
853
|
if (t.has(n.schemaRef)) throw Error(`duplicate trusted conversation renderer schemaRef: ${n.schemaRef}`);
|
|
854
854
|
t.set(n.schemaRef, Object.freeze({
|
|
855
855
|
...n,
|
|
@@ -867,14 +867,14 @@ function Ce(e) {
|
|
|
867
867
|
}
|
|
868
868
|
});
|
|
869
869
|
}
|
|
870
|
-
var
|
|
870
|
+
var Ee = Te([{
|
|
871
871
|
id: "ksadk.agent-block",
|
|
872
872
|
schemaRef: "conversation.item.agent/v1",
|
|
873
873
|
kinds: ["agent"]
|
|
874
874
|
}]);
|
|
875
875
|
//#endregion
|
|
876
876
|
//#region src/utils/history-tool-facts.ts
|
|
877
|
-
function
|
|
877
|
+
function P(e, t) {
|
|
878
878
|
let n = (e) => e === "completed" || e === "error", r = t.output === void 0 ? e.output : t.output;
|
|
879
879
|
return {
|
|
880
880
|
args: t.args || e.args,
|
|
@@ -882,7 +882,7 @@ function F(e, t) {
|
|
|
882
882
|
status: n(e.status) && !n(t.status) ? e.status : t.status
|
|
883
883
|
};
|
|
884
884
|
}
|
|
885
|
-
function
|
|
885
|
+
function F(e) {
|
|
886
886
|
let t = e.map((e) => ({
|
|
887
887
|
...e,
|
|
888
888
|
tools: e.tools ? { ...e.tools } : void 0
|
|
@@ -907,11 +907,11 @@ function I(e) {
|
|
|
907
907
|
let r = e.message.tools[e.key], i = n ? {
|
|
908
908
|
...t,
|
|
909
909
|
...r,
|
|
910
|
-
...
|
|
910
|
+
...P(t, r)
|
|
911
911
|
} : {
|
|
912
912
|
...r,
|
|
913
913
|
...t,
|
|
914
|
-
...
|
|
914
|
+
...P(r, t)
|
|
915
915
|
};
|
|
916
916
|
e.message.tools[e.key] = i, e.message.blocks = e.message.blocks?.map((e) => e.type === "tool" && e.extra?.callId === t.callId ? {
|
|
917
917
|
...e,
|
|
@@ -950,18 +950,18 @@ function I(e) {
|
|
|
950
950
|
}
|
|
951
951
|
//#endregion
|
|
952
952
|
//#region src/utils/transcript-order.ts
|
|
953
|
-
var
|
|
954
|
-
function
|
|
953
|
+
var I = (e) => e.runId || e.invocationId;
|
|
954
|
+
function L(e) {
|
|
955
955
|
let t = /* @__PURE__ */ new Map();
|
|
956
956
|
for (let n of e) {
|
|
957
|
-
let e =
|
|
957
|
+
let e = I(n), r = n.historyOrder?.group;
|
|
958
958
|
e && r !== void 0 && t.set(e, Math.min(r, t.get(e) ?? r));
|
|
959
959
|
}
|
|
960
960
|
let n = e.map((e, n) => ({
|
|
961
961
|
message: e,
|
|
962
962
|
index: n,
|
|
963
963
|
seq: e.historyOrder?.seq,
|
|
964
|
-
group: e.historyOrder?.group ?? t.get(
|
|
964
|
+
group: e.historyOrder?.group ?? t.get(I(e) || "") ?? e.historyOrder?.seq,
|
|
965
965
|
part: e.historyOrder?.index || 0
|
|
966
966
|
})), r, i = n.map(() => void 0);
|
|
967
967
|
for (let e = n.length - 1; e >= 0; e--) i[e] = r, n[e].group !== void 0 && (r = n[e].group);
|
|
@@ -976,13 +976,13 @@ function R(e) {
|
|
|
976
976
|
side: 0
|
|
977
977
|
})).sort((e, t) => e.anchor - t.anchor || e.side - t.side || (e.side === 0 ? (e.seq ?? e.anchor) - (t.seq ?? t.anchor) : 0) || (e.side === 0 ? e.part - t.part : 0) || e.index - t.index).map((e) => e.message);
|
|
978
978
|
}
|
|
979
|
-
function
|
|
979
|
+
function De(e, t) {
|
|
980
980
|
if (!t) return !0;
|
|
981
981
|
let n = (n) => n === "feedback" ? !1 : n === "historyOrder" ? e.historyOrder?.seq !== t.historyOrder?.seq || e.historyOrder?.index !== t.historyOrder?.index || e.historyOrder?.group !== t.historyOrder?.group : e[n] !== t[n];
|
|
982
982
|
return Object.keys(e).some(n) || Object.keys(t).some(n);
|
|
983
983
|
}
|
|
984
|
-
function
|
|
985
|
-
let r = new Map(t.map((e) => [e.id, e])), i = n.filter((e) => r.has(e.id) && r.get(e.id)?.feedback !== e.feedback), a = new Map(i.map((e) => [e.id, e.feedback])), o = (e) => JSON.stringify([
|
|
984
|
+
function Oe(e, t, n) {
|
|
985
|
+
let r = new Map(t.map((e) => [e.id, e])), i = n.filter((e) => r.has(e.id) && r.get(e.id)?.feedback !== e.feedback), a = new Map(i.map((e) => [e.id, e.feedback])), o = (e) => JSON.stringify([I(e), e.responseId]), s = new Map(i.filter((e) => e.responseId).map((e) => [o(e), e.feedback])), c = (e) => e.map((e) => {
|
|
986
986
|
if (a.has(e.id)) return {
|
|
987
987
|
...e,
|
|
988
988
|
feedback: a.get(e.id)
|
|
@@ -992,19 +992,19 @@ function Ee(e, t, n) {
|
|
|
992
992
|
...e,
|
|
993
993
|
feedback: s.get(t)
|
|
994
994
|
} : e;
|
|
995
|
-
}), l = n.filter((e) =>
|
|
996
|
-
if (!l.length) return
|
|
997
|
-
let u = new Set(l.map(
|
|
995
|
+
}), l = n.filter((e) => De(e, r.get(e.id)));
|
|
996
|
+
if (!l.length) return ne(F(c(e)));
|
|
997
|
+
let u = new Set(l.map(I).filter(Boolean)), d = new Set(l.map((e) => e.id)), f = n.filter((e) => u.has(I(e)) || d.has(e.id)), p = e;
|
|
998
998
|
for (let t of u) {
|
|
999
|
-
let n = f.filter((e) =>
|
|
1000
|
-
p = p.filter((e) =>
|
|
999
|
+
let n = f.filter((e) => I(e) === t), r = e.filter((e) => I(e) === t), i = p.findIndex((e) => I(e) === t), a = n.some((e) => e.role === "user") ? [] : r.filter((e) => e.role === "user");
|
|
1000
|
+
p = p.filter((e) => I(e) !== t);
|
|
1001
1001
|
let o = i < 0 ? p.length : Math.min(i, p.length);
|
|
1002
1002
|
p.splice(o, 0, ...a, ...n.map((e) => ({
|
|
1003
1003
|
...e,
|
|
1004
1004
|
historyOrder: e.historyOrder || r.find((t) => t.id === e.id)?.historyOrder
|
|
1005
1005
|
})));
|
|
1006
1006
|
}
|
|
1007
|
-
for (let e of f.filter((e) => !
|
|
1007
|
+
for (let e of f.filter((e) => !I(e))) {
|
|
1008
1008
|
let t = p.findIndex((t) => t.id === e.id);
|
|
1009
1009
|
if (t < 0) {
|
|
1010
1010
|
let t = n.indexOf(e), r = n.slice(t + 1).find((e) => p.some((t) => t.id === e.id)), i = n.slice(0, t).findLast((e) => p.some((t) => t.id === e.id)), a = r ? p.findIndex((e) => e.id === r.id) : i ? p.findIndex((e) => e.id === i.id) + 1 : p.length;
|
|
@@ -1018,18 +1018,18 @@ function Ee(e, t, n) {
|
|
|
1018
1018
|
historyOrder: e.historyOrder || n.historyOrder
|
|
1019
1019
|
} : n);
|
|
1020
1020
|
}
|
|
1021
|
-
return
|
|
1021
|
+
return ne(F(c(L(p))));
|
|
1022
1022
|
}
|
|
1023
1023
|
//#endregion
|
|
1024
1024
|
//#region src/core/conversation/hosted.ts
|
|
1025
|
-
var
|
|
1026
|
-
function
|
|
1025
|
+
var ke = "conversation_item_v1";
|
|
1026
|
+
function R(e) {
|
|
1027
1027
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
1028
1028
|
}
|
|
1029
|
-
function
|
|
1029
|
+
function z(e) {
|
|
1030
1030
|
return typeof e == "string" && e.trim() ? e : null;
|
|
1031
1031
|
}
|
|
1032
|
-
function
|
|
1032
|
+
function B(e) {
|
|
1033
1033
|
if (typeof e == "string") return e;
|
|
1034
1034
|
if (e == null) return "";
|
|
1035
1035
|
try {
|
|
@@ -1038,24 +1038,24 @@ function V(e) {
|
|
|
1038
1038
|
return String(e);
|
|
1039
1039
|
}
|
|
1040
1040
|
}
|
|
1041
|
-
function
|
|
1041
|
+
function V(e) {
|
|
1042
1042
|
return {
|
|
1043
1043
|
id: `conversation:${e.runId}:${e.itemId}`,
|
|
1044
1044
|
timestamp: 0,
|
|
1045
|
-
eventType:
|
|
1045
|
+
eventType: ke,
|
|
1046
1046
|
eventId: e.sourceEventIds.at(-1),
|
|
1047
1047
|
runId: e.runId,
|
|
1048
1048
|
itemId: e.itemId,
|
|
1049
1049
|
status: e.lifecycle === "failed" ? "failed" : e.lifecycle === "completed" ? "completed" : "running"
|
|
1050
1050
|
};
|
|
1051
1051
|
}
|
|
1052
|
-
function
|
|
1052
|
+
function Ae(e) {
|
|
1053
1053
|
return e.lifecycle === "failed" ? "error" : e.lifecycle === "completed" ? "done" : "streaming";
|
|
1054
1054
|
}
|
|
1055
|
-
function
|
|
1055
|
+
function je(e) {
|
|
1056
1056
|
let t = typeof e.payload.text == "string" ? e.payload.text : "";
|
|
1057
1057
|
if (e.kind === "user_message") return {
|
|
1058
|
-
...
|
|
1058
|
+
...V(e),
|
|
1059
1059
|
role: "user",
|
|
1060
1060
|
content: t,
|
|
1061
1061
|
eventType: "user_message"
|
|
@@ -1064,31 +1064,31 @@ function ke(e) {
|
|
|
1064
1064
|
id: `conversation-block:${e.itemId}`,
|
|
1065
1065
|
type: "thinking",
|
|
1066
1066
|
content: t,
|
|
1067
|
-
status:
|
|
1067
|
+
status: Ae(e),
|
|
1068
1068
|
...e.payload.presentationSource === "public_summary" || e.payload.presentationSource === "provider_reasoning" ? { source: e.payload.presentationSource } : {}
|
|
1069
1069
|
} : {
|
|
1070
1070
|
id: `conversation-block:${e.itemId}`,
|
|
1071
1071
|
type: "text",
|
|
1072
1072
|
content: t,
|
|
1073
|
-
status:
|
|
1073
|
+
status: Ae(e)
|
|
1074
1074
|
};
|
|
1075
1075
|
return {
|
|
1076
|
-
...
|
|
1076
|
+
...V(e),
|
|
1077
1077
|
role: "model",
|
|
1078
1078
|
content: e.kind === "assistant_text" ? t : "",
|
|
1079
1079
|
reasoning: e.kind === "reasoning" ? t : void 0,
|
|
1080
1080
|
blocks: [n]
|
|
1081
1081
|
};
|
|
1082
1082
|
}
|
|
1083
|
-
function
|
|
1084
|
-
let n =
|
|
1083
|
+
function Me(e, t = !1) {
|
|
1084
|
+
let n = z(e.payload.tool) || (e.payload.sourceKind === "tool_result" ? "Tool result" : "Tool"), r = z(e.payload.callId), i = B(y(e.payload.args)), a = Object.prototype.hasOwnProperty.call(e.payload, "output") ? B(b(e.payload.output, e.nativeRef.framework, e.nativeRef.protocol)) : void 0, o = {
|
|
1085
1085
|
failed: "error",
|
|
1086
1086
|
completed: "completed",
|
|
1087
1087
|
running: "running",
|
|
1088
1088
|
unknown: "unknown"
|
|
1089
1089
|
}, s = e.payload.executionStatus, c = typeof s == "string" && Object.hasOwn(o, s) ? o[s] : e.lifecycle === "failed" || e.payload.isError === !0 ? "error" : e.lifecycle === "completed" ? "completed" : "running", l = t && c === "running" ? "unknown" : c;
|
|
1090
1090
|
return {
|
|
1091
|
-
...
|
|
1091
|
+
...V(e),
|
|
1092
1092
|
role: "model",
|
|
1093
1093
|
content: "",
|
|
1094
1094
|
blocks: [{
|
|
@@ -1109,55 +1109,55 @@ function Ae(e, t = !1) {
|
|
|
1109
1109
|
} }
|
|
1110
1110
|
};
|
|
1111
1111
|
}
|
|
1112
|
-
function
|
|
1112
|
+
function Ne(e) {
|
|
1113
1113
|
return e === "structured_input" ? "structured_input" : e === "plan_review" ? "plan_review" : e === "custom" ? "custom" : "approval";
|
|
1114
1114
|
}
|
|
1115
|
-
function
|
|
1116
|
-
let n =
|
|
1115
|
+
function Pe(e) {
|
|
1116
|
+
let n = z(e.payload.interactionId), r = e.payload.revision;
|
|
1117
1117
|
if (!n || !Number.isInteger(r) || Number(r) < 1) return null;
|
|
1118
|
-
let i =
|
|
1119
|
-
if (s && Object.hasOwn(
|
|
1120
|
-
c = { response: e
|
|
1118
|
+
let i = B(e.payload.detail), a = z(e.payload.prompt) || i, o = Ne(e.payload.interactionKind), s = e.lifecycle === "completed", c = {};
|
|
1119
|
+
if (s && Object.hasOwn(e.payload, "response")) try {
|
|
1120
|
+
c = { response: t(e.payload.response) };
|
|
1121
1121
|
} catch {}
|
|
1122
1122
|
return {
|
|
1123
1123
|
interactionId: n,
|
|
1124
|
-
sessionId:
|
|
1125
|
-
runId:
|
|
1124
|
+
sessionId: e.sessionId,
|
|
1125
|
+
runId: e.runId,
|
|
1126
1126
|
kind: o,
|
|
1127
|
-
title:
|
|
1127
|
+
title: z(e.payload.title) || (o === "approval" ? `审批:${z(e.payload.kind) || "操作"}` : "需要补充信息"),
|
|
1128
1128
|
message: a || "运行需要人工确认。",
|
|
1129
|
-
requestSchema:
|
|
1129
|
+
requestSchema: R(e.payload.inputSchema),
|
|
1130
1130
|
presentation: null,
|
|
1131
1131
|
status: s ? "resolved" : "pending",
|
|
1132
1132
|
revision: Number(r),
|
|
1133
|
-
createdAt:
|
|
1134
|
-
expiresAt:
|
|
1135
|
-
resolvedAt: s ?
|
|
1136
|
-
actor: s ?
|
|
1133
|
+
createdAt: z(e.payload.createdAt) || "",
|
|
1134
|
+
expiresAt: z(e.payload.expiresAt),
|
|
1135
|
+
resolvedAt: s ? z(e.payload.resolvedAt) : null,
|
|
1136
|
+
actor: s ? z(e.payload.actor) : null,
|
|
1137
1137
|
outcome: s && [
|
|
1138
1138
|
"approved",
|
|
1139
1139
|
"rejected",
|
|
1140
1140
|
"submitted",
|
|
1141
1141
|
"cancelled",
|
|
1142
1142
|
"expired"
|
|
1143
|
-
].includes(String(
|
|
1144
|
-
responseSummary: s ?
|
|
1143
|
+
].includes(String(e.payload.outcome || "")) ? e.payload.outcome : null,
|
|
1144
|
+
responseSummary: s ? z(e.payload.responseSummary) : null,
|
|
1145
1145
|
...c,
|
|
1146
1146
|
source: "interaction_v1",
|
|
1147
1147
|
extensions: {
|
|
1148
|
-
conversation_item_id:
|
|
1149
|
-
...
|
|
1148
|
+
conversation_item_id: e.itemId,
|
|
1149
|
+
...z(e.payload.callId) ? { call_id: z(e.payload.callId) } : {}
|
|
1150
1150
|
}
|
|
1151
1151
|
};
|
|
1152
1152
|
}
|
|
1153
|
-
function
|
|
1154
|
-
let n =
|
|
1153
|
+
function Fe(e, t) {
|
|
1154
|
+
let n = z(e.payload.kind) || "approval", r = B(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 = {
|
|
1155
1155
|
approvalRequestId: t.interactionId,
|
|
1156
1156
|
approvalStatus: i,
|
|
1157
1157
|
approvalMessage: t.message
|
|
1158
1158
|
};
|
|
1159
1159
|
return {
|
|
1160
|
-
...
|
|
1160
|
+
...V(e),
|
|
1161
1161
|
role: "model",
|
|
1162
1162
|
content: "",
|
|
1163
1163
|
blocks: [{
|
|
@@ -1178,26 +1178,26 @@ function Ne(e, t) {
|
|
|
1178
1178
|
} }
|
|
1179
1179
|
};
|
|
1180
1180
|
}
|
|
1181
|
-
function
|
|
1181
|
+
function Ie(e) {
|
|
1182
1182
|
for (let t of [
|
|
1183
1183
|
"createSurface",
|
|
1184
1184
|
"updateComponents",
|
|
1185
1185
|
"updateDataModel",
|
|
1186
1186
|
"deleteSurface"
|
|
1187
1187
|
]) {
|
|
1188
|
-
let n =
|
|
1188
|
+
let n = z(R(e[t])?.surfaceId);
|
|
1189
1189
|
if (n) return n;
|
|
1190
1190
|
}
|
|
1191
1191
|
return null;
|
|
1192
1192
|
}
|
|
1193
|
-
function
|
|
1193
|
+
function Le(e) {
|
|
1194
1194
|
let t = Array.isArray(e.payload.data) ? e.payload.data : Array.isArray(e.payload.operations) ? e.payload.operations : null;
|
|
1195
1195
|
if (!t) return null;
|
|
1196
|
-
let n = t.map(
|
|
1196
|
+
let n = t.map(R);
|
|
1197
1197
|
if (n.some((e) => e === null)) return null;
|
|
1198
|
-
let r = n, i =
|
|
1198
|
+
let r = n, i = z(e.payload.surfaceId) || r.map(Ie).find((e) => e !== null) || null;
|
|
1199
1199
|
return i ? {
|
|
1200
|
-
...
|
|
1200
|
+
...V(e),
|
|
1201
1201
|
role: "a2ui",
|
|
1202
1202
|
content: "",
|
|
1203
1203
|
aguiActivity: {
|
|
@@ -1207,18 +1207,18 @@ function Fe(e) {
|
|
|
1207
1207
|
}
|
|
1208
1208
|
} : null;
|
|
1209
1209
|
}
|
|
1210
|
-
function
|
|
1210
|
+
function H(e, t, n, r = !1) {
|
|
1211
1211
|
return {
|
|
1212
|
-
...
|
|
1212
|
+
...V(e),
|
|
1213
1213
|
role: "system",
|
|
1214
1214
|
content: n ? `${t}: ${n}` : t,
|
|
1215
|
-
status: r ? "failed" :
|
|
1215
|
+
status: r ? "failed" : V(e).status
|
|
1216
1216
|
};
|
|
1217
1217
|
}
|
|
1218
|
-
function
|
|
1218
|
+
function Re(e) {
|
|
1219
1219
|
for (let { item: t } of [...e].reverse()) {
|
|
1220
1220
|
if (t.visibility !== "public" || t.kind !== "assistant_text" || t.payloadSchemaRef !== "conversation.item.assistant_text/v1" || typeof t.payload.text != "string") continue;
|
|
1221
|
-
let e =
|
|
1221
|
+
let e = y(t.payload.text);
|
|
1222
1222
|
if (typeof e != "string" || e === "[redacted]") continue;
|
|
1223
1223
|
let n = e.replace(/\s+/g, " ").trim();
|
|
1224
1224
|
if (!n) continue;
|
|
@@ -1226,16 +1226,16 @@ function Ie(e) {
|
|
|
1226
1226
|
return r.length > 160 ? `${r.slice(0, 160).join("")}…` : n;
|
|
1227
1227
|
}
|
|
1228
1228
|
}
|
|
1229
|
-
function
|
|
1229
|
+
function U(e) {
|
|
1230
1230
|
let t = e.presentation, n = new Map(t.textItems.map((e) => [e.id, e])), r = new Set(t.toolItems.map((e) => e.itemId)), i = new Set(t.approvalItems.map((e) => e.itemId)), a = new Set(t.structuredInputItems.map((e) => e.itemId)), o = new Set(t.a2uiItems.map((e) => e.itemId)), s = new Map(t.artifacts.map((e) => [e.id, e])), c = new Map(t.fallbacks.map((e) => [e.id, e])), l = [], u = [];
|
|
1231
1231
|
for (let d of t.timeline) {
|
|
1232
1232
|
let { item: f } = d;
|
|
1233
1233
|
if (f.kind === "agent") {
|
|
1234
1234
|
if (!d.children) {
|
|
1235
|
-
l.push(
|
|
1235
|
+
l.push(H(f, "Remote agent", String(f.payload.status || "submitted")));
|
|
1236
1236
|
continue;
|
|
1237
1237
|
}
|
|
1238
|
-
let n =
|
|
1238
|
+
let n = U({
|
|
1239
1239
|
...e,
|
|
1240
1240
|
presentation: {
|
|
1241
1241
|
...t,
|
|
@@ -1243,40 +1243,40 @@ function W(e) {
|
|
|
1243
1243
|
}
|
|
1244
1244
|
});
|
|
1245
1245
|
l.push({
|
|
1246
|
-
...
|
|
1246
|
+
...V(f),
|
|
1247
1247
|
role: "model",
|
|
1248
1248
|
content: "",
|
|
1249
1249
|
agentBlock: {
|
|
1250
1250
|
item: f,
|
|
1251
1251
|
messages: n.messages,
|
|
1252
|
-
summary:
|
|
1252
|
+
summary: Re(d.children || [])
|
|
1253
1253
|
},
|
|
1254
|
-
status: f.payload.status === "cancelled" ? "cancelled" :
|
|
1254
|
+
status: f.payload.status === "cancelled" ? "cancelled" : V(f).status
|
|
1255
1255
|
}), u.push(...n.interactions);
|
|
1256
1256
|
continue;
|
|
1257
1257
|
}
|
|
1258
1258
|
if (n.has(f.itemId)) {
|
|
1259
|
-
l.push(
|
|
1259
|
+
l.push(je(f));
|
|
1260
1260
|
continue;
|
|
1261
1261
|
}
|
|
1262
1262
|
if (r.has(f.itemId)) {
|
|
1263
|
-
l.push(
|
|
1263
|
+
l.push(Me(f, !!t.terminalStatus && f.runId === e.runId));
|
|
1264
1264
|
continue;
|
|
1265
1265
|
}
|
|
1266
1266
|
if (i.has(f.itemId) || a.has(f.itemId)) {
|
|
1267
|
-
let e =
|
|
1268
|
-
e ? (u.push(e), l.push(
|
|
1267
|
+
let e = Pe(f);
|
|
1268
|
+
e ? (u.push(e), l.push(Fe(f, e))) : l.push(H(f, "Interaction unavailable", "The server did not provide a durable interaction revision; this card is read-only."));
|
|
1269
1269
|
continue;
|
|
1270
1270
|
}
|
|
1271
1271
|
if (o.has(f.itemId)) {
|
|
1272
|
-
let e =
|
|
1273
|
-
l.push(e ||
|
|
1272
|
+
let e = Le(f);
|
|
1273
|
+
l.push(e || H(f, "Unsupported content", "A2UI payload is not a valid passive operation list."));
|
|
1274
1274
|
continue;
|
|
1275
1275
|
}
|
|
1276
1276
|
let p = s.get(f.itemId);
|
|
1277
1277
|
if (p) {
|
|
1278
1278
|
l.push(p.status === "pending" ? {
|
|
1279
|
-
...
|
|
1279
|
+
...V(f),
|
|
1280
1280
|
role: "model",
|
|
1281
1281
|
content: p.name,
|
|
1282
1282
|
attachments: [{
|
|
@@ -1290,7 +1290,7 @@ function W(e) {
|
|
|
1290
1290
|
status: "pending"
|
|
1291
1291
|
}]
|
|
1292
1292
|
} : p.status === "ready" && p.uri ? {
|
|
1293
|
-
...
|
|
1293
|
+
...V(f),
|
|
1294
1294
|
role: "model",
|
|
1295
1295
|
content: p.name,
|
|
1296
1296
|
attachments: [{
|
|
@@ -1303,13 +1303,13 @@ function W(e) {
|
|
|
1303
1303
|
sizeBytes: p.sizeBytes,
|
|
1304
1304
|
status: p.status
|
|
1305
1305
|
}]
|
|
1306
|
-
} :
|
|
1306
|
+
} : H(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."));
|
|
1307
1307
|
continue;
|
|
1308
1308
|
}
|
|
1309
1309
|
let m = c.get(f.itemId);
|
|
1310
1310
|
if (m) {
|
|
1311
1311
|
if (f.kind === "error" && ["cancelled", "canceled"].includes(String(f.payload.status || "").toLowerCase())) continue;
|
|
1312
|
-
l.push(
|
|
1312
|
+
l.push(H(f, m.title, m.detail, m.failed));
|
|
1313
1313
|
}
|
|
1314
1314
|
}
|
|
1315
1315
|
return {
|
|
@@ -1317,8 +1317,8 @@ function W(e) {
|
|
|
1317
1317
|
interactions: u
|
|
1318
1318
|
};
|
|
1319
1319
|
}
|
|
1320
|
-
function
|
|
1321
|
-
let r =
|
|
1320
|
+
function ze(e, t, n) {
|
|
1321
|
+
let r = U(t).messages;
|
|
1322
1322
|
if (!r.length) return e;
|
|
1323
1323
|
let i = e.filter((e) => e.eventType !== "optimistic_assistant_placeholder"), a = (e) => e.runId === t.runId || e.invocationId === t.runId, o = i.findIndex(a), s = n ? i.findIndex((e) => e.id === n) : o < 0 ? i.findLastIndex((e) => e.role === "user" && e.eventType === "optimistic_user_message") : i.findIndex((e) => e.role === "user" && a(e)), c = i[s], l = i.filter((e, t) => t !== s && !a(e)), u = [s, o].filter((e) => e >= 0), d = u.length ? Math.min(...u) : l.length, f = c && !r.some((e) => e.role === "user") ? [{
|
|
1324
1324
|
...c,
|
|
@@ -1334,51 +1334,57 @@ function Le(e, t, n) {
|
|
|
1334
1334
|
}
|
|
1335
1335
|
//#endregion
|
|
1336
1336
|
//#region src/core/run/blocks.ts
|
|
1337
|
-
var
|
|
1338
|
-
function
|
|
1339
|
-
return
|
|
1337
|
+
var Be = 0;
|
|
1338
|
+
function W(e) {
|
|
1339
|
+
return Be += 1, `${e}-${Be}`;
|
|
1340
1340
|
}
|
|
1341
|
-
function
|
|
1341
|
+
function G(e) {
|
|
1342
1342
|
return e.map((e) => e.type === "thinking" && e.status === "streaming" ? {
|
|
1343
1343
|
...e,
|
|
1344
1344
|
status: "done"
|
|
1345
1345
|
} : e);
|
|
1346
1346
|
}
|
|
1347
|
-
function
|
|
1348
|
-
let
|
|
1349
|
-
return
|
|
1350
|
-
...
|
|
1351
|
-
content:
|
|
1352
|
-
},
|
|
1353
|
-
id:
|
|
1347
|
+
function Ve(e, t, n) {
|
|
1348
|
+
let r = [...e ?? []], i = r[r.length - 1];
|
|
1349
|
+
return i?.type === "thinking" && i.status === "streaming" && i.itemId === n ? (r[r.length - 1] = {
|
|
1350
|
+
...i,
|
|
1351
|
+
content: i.content + t
|
|
1352
|
+
}, r) : [...G(r), {
|
|
1353
|
+
id: W("thinking"),
|
|
1354
1354
|
type: "thinking",
|
|
1355
1355
|
content: t,
|
|
1356
|
-
status: "streaming"
|
|
1356
|
+
status: "streaming",
|
|
1357
|
+
...n && { itemId: n }
|
|
1357
1358
|
}];
|
|
1358
1359
|
}
|
|
1359
|
-
function
|
|
1360
|
-
let
|
|
1360
|
+
function He(e, t, n) {
|
|
1361
|
+
let r = (e) => e.type === "thinking" && e.itemId === t, i = e.findLastIndex(r), a = 0;
|
|
1362
|
+
return e.flatMap((e, t) => {
|
|
1363
|
+
if (!r(e)) return [e];
|
|
1364
|
+
let o = t === i ? n.length : a + e.content.length, s = n.slice(a, o);
|
|
1365
|
+
return a = o, s ? [{
|
|
1366
|
+
...e,
|
|
1367
|
+
content: s
|
|
1368
|
+
}] : [];
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
function Ue(e, t) {
|
|
1372
|
+
let n = [...G(e ?? [])], r = n[n.length - 1];
|
|
1361
1373
|
return r?.type === "text" && r.status === "streaming" ? (n[n.length - 1] = {
|
|
1362
1374
|
...r,
|
|
1363
1375
|
content: r.content + t
|
|
1364
1376
|
}, n) : [...n, {
|
|
1365
|
-
id:
|
|
1377
|
+
id: W("text"),
|
|
1366
1378
|
type: "text",
|
|
1367
1379
|
content: t,
|
|
1368
1380
|
status: "streaming"
|
|
1369
1381
|
}];
|
|
1370
1382
|
}
|
|
1371
|
-
function
|
|
1383
|
+
function We(e, t) {
|
|
1372
1384
|
let n = e ?? [], r = n.filter((e) => e.type === "text").map((e) => e.content).join("");
|
|
1373
1385
|
if (r === t) return n;
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
id: G("text"),
|
|
1377
|
-
type: "text",
|
|
1378
|
-
content: t,
|
|
1379
|
-
status: "streaming"
|
|
1380
|
-
}];
|
|
1381
|
-
let a = 0;
|
|
1386
|
+
if (t.startsWith(r) && n.at(-1)?.type !== "text") return Ue(n, t.slice(r.length));
|
|
1387
|
+
let i = n.flatMap((e, t) => e.type === "text" ? [t] : []), a = 0;
|
|
1382
1388
|
for (; a < r.length && a < t.length && r[a] === t[a];) a++;
|
|
1383
1389
|
let o = 0;
|
|
1384
1390
|
for (; o < r.length - a && o < t.length - a && r[r.length - o - 1] === t[t.length - o - 1];) o++;
|
|
@@ -1397,25 +1403,29 @@ function Ve(e, t) {
|
|
|
1397
1403
|
};
|
|
1398
1404
|
});
|
|
1399
1405
|
}
|
|
1400
|
-
function
|
|
1401
|
-
let n =
|
|
1402
|
-
if (
|
|
1406
|
+
function Ge(e, t) {
|
|
1407
|
+
let n = G(e ?? []), r = n.flatMap((e) => e.type === "text" ? [e.content] : []).join(""), i = n.at(-1), a = n;
|
|
1408
|
+
if (t !== r && i?.type !== "text") {
|
|
1409
|
+
let e = t.startsWith(r) ? t.slice(r.length) : t;
|
|
1410
|
+
e && (a = [...n, {
|
|
1411
|
+
id: W("text"),
|
|
1412
|
+
type: "text",
|
|
1413
|
+
content: e,
|
|
1414
|
+
status: "done"
|
|
1415
|
+
}]);
|
|
1416
|
+
} else if (i?.type === "text" && t !== r && t !== i.content) {
|
|
1417
|
+
let e = r.slice(0, r.length - i.content.length), o = t.startsWith(e) ? t.slice(e.length) : t;
|
|
1418
|
+
a = [...n.slice(0, -1), {
|
|
1419
|
+
...i,
|
|
1420
|
+
content: o
|
|
1421
|
+
}];
|
|
1422
|
+
}
|
|
1423
|
+
return a.map((e) => e.type === "text" && e.status === "streaming" ? {
|
|
1403
1424
|
...e,
|
|
1404
1425
|
status: "done"
|
|
1405
1426
|
} : e);
|
|
1406
|
-
let r = [...n], i = r.map((e) => e.type).lastIndexOf("text");
|
|
1407
|
-
return i >= 0 && r[i].type === "text" ? (r[i] = {
|
|
1408
|
-
...r[i],
|
|
1409
|
-
content: t,
|
|
1410
|
-
status: "done"
|
|
1411
|
-
}, r) : [...r, {
|
|
1412
|
-
id: G("text"),
|
|
1413
|
-
type: "text",
|
|
1414
|
-
content: t,
|
|
1415
|
-
status: "done"
|
|
1416
|
-
}];
|
|
1417
1427
|
}
|
|
1418
|
-
function
|
|
1428
|
+
function Ke(e, t) {
|
|
1419
1429
|
if (!t) return [...e ?? []];
|
|
1420
1430
|
let n = [...e ?? []], r = n[n.length - 1];
|
|
1421
1431
|
if (r?.type !== "thinking" || !r.content.endsWith(t)) return n;
|
|
@@ -1425,20 +1435,23 @@ function Ue(e, t) {
|
|
|
1425
1435
|
content: i
|
|
1426
1436
|
}, n) : (n.pop(), n);
|
|
1427
1437
|
}
|
|
1428
|
-
function
|
|
1429
|
-
let r = [...
|
|
1430
|
-
if (i >= 0 && r[
|
|
1431
|
-
let e = r[
|
|
1432
|
-
if (t && !
|
|
1433
|
-
let s = n.extra
|
|
1434
|
-
|
|
1438
|
+
function qe(e, t, n) {
|
|
1439
|
+
let r = [...e ?? []], i = n.extra?.callId, a = i ? r.findIndex((e) => e.type === "tool" && e.extra?.callId === i && e.toolName === t) : -1;
|
|
1440
|
+
if (a < 0 && (a = r.findLastIndex((e) => e.type === "tool" && e.toolName === t && (!i || !e.extra?.callId && (e.status === "running" || e.status === "paused")))), a >= 0 && r[a].type === "tool") {
|
|
1441
|
+
let e = r[a], t = e.status === "error" || e.status === "completed", i = n.output !== void 0, o = n.extra && (n.extra.approvalRequestId || n.extra.approvalStatus);
|
|
1442
|
+
if (t && !i && !o) return r;
|
|
1443
|
+
let s = n.extra ? {
|
|
1444
|
+
...e.extra,
|
|
1445
|
+
...n.extra
|
|
1446
|
+
} : e.extra;
|
|
1447
|
+
return r[a] = {
|
|
1435
1448
|
...e,
|
|
1436
1449
|
...n,
|
|
1437
1450
|
extra: s
|
|
1438
1451
|
}, r;
|
|
1439
1452
|
}
|
|
1440
|
-
return [...r, {
|
|
1441
|
-
id:
|
|
1453
|
+
return [...G(r), {
|
|
1454
|
+
id: W("tool"),
|
|
1442
1455
|
type: "tool",
|
|
1443
1456
|
toolName: t,
|
|
1444
1457
|
args: n.args ?? "",
|
|
@@ -1447,19 +1460,19 @@ function We(e, t, n) {
|
|
|
1447
1460
|
extra: n.extra
|
|
1448
1461
|
}];
|
|
1449
1462
|
}
|
|
1450
|
-
function
|
|
1451
|
-
return
|
|
1463
|
+
function Je(e) {
|
|
1464
|
+
return G(e ?? []);
|
|
1452
1465
|
}
|
|
1453
|
-
function
|
|
1466
|
+
function Ye(e) {
|
|
1454
1467
|
let t = [];
|
|
1455
1468
|
if (e.reasoning && e.reasoning.trim() && t.push({
|
|
1456
|
-
id:
|
|
1469
|
+
id: W("thinking"),
|
|
1457
1470
|
type: "thinking",
|
|
1458
1471
|
content: e.reasoning,
|
|
1459
1472
|
status: "done",
|
|
1460
1473
|
...e.reasoningSource ? { source: e.reasoningSource } : {}
|
|
1461
1474
|
}), e.tools) for (let n of Object.values(e.tools)) t.push({
|
|
1462
|
-
id:
|
|
1475
|
+
id: W("tool"),
|
|
1463
1476
|
type: "tool",
|
|
1464
1477
|
toolName: n.name,
|
|
1465
1478
|
args: n.args ?? "",
|
|
@@ -1471,7 +1484,7 @@ function Ke(e) {
|
|
|
1471
1484
|
} } : {}
|
|
1472
1485
|
});
|
|
1473
1486
|
return e.content && e.content.trim() && t.push({
|
|
1474
|
-
id:
|
|
1487
|
+
id: W("text"),
|
|
1475
1488
|
type: "text",
|
|
1476
1489
|
content: e.content,
|
|
1477
1490
|
status: "done"
|
|
@@ -1479,40 +1492,40 @@ function Ke(e) {
|
|
|
1479
1492
|
}
|
|
1480
1493
|
//#endregion
|
|
1481
1494
|
//#region src/core/stream/kernel-events.ts
|
|
1482
|
-
var
|
|
1495
|
+
var Xe = {
|
|
1483
1496
|
"run.started": "in_progress",
|
|
1484
1497
|
"run.progress": "in_progress",
|
|
1485
1498
|
"run.completed": "completed",
|
|
1486
1499
|
"run.failed": "failed",
|
|
1487
1500
|
"run.canceled": "cancelled",
|
|
1488
1501
|
"run.interrupted": "interrupted"
|
|
1489
|
-
},
|
|
1502
|
+
}, Ze = new Set([
|
|
1490
1503
|
"completed",
|
|
1491
1504
|
"failed",
|
|
1492
1505
|
"cancelled",
|
|
1493
1506
|
"canceled"
|
|
1494
1507
|
]);
|
|
1495
|
-
function
|
|
1508
|
+
function K(e) {
|
|
1496
1509
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
1497
1510
|
}
|
|
1498
|
-
function
|
|
1499
|
-
let t =
|
|
1511
|
+
function Qe(e) {
|
|
1512
|
+
let t = K(e.source), n = t ? K(t.metadata) : null;
|
|
1500
1513
|
return String(n?.native_item_kind || "");
|
|
1501
1514
|
}
|
|
1502
|
-
function
|
|
1503
|
-
let n =
|
|
1515
|
+
function q(e, t) {
|
|
1516
|
+
let n = K(e[t]);
|
|
1504
1517
|
if (!n) return [];
|
|
1505
1518
|
let r = n?.parts;
|
|
1506
1519
|
return Array.isArray(r) ? r : t === "update" ? [n] : [];
|
|
1507
1520
|
}
|
|
1508
|
-
function
|
|
1509
|
-
let t =
|
|
1521
|
+
function $e(e) {
|
|
1522
|
+
let t = K(e);
|
|
1510
1523
|
if (!t) return "";
|
|
1511
1524
|
if (typeof t.text == "string") return t.text;
|
|
1512
|
-
let n =
|
|
1525
|
+
let n = K(t.data);
|
|
1513
1526
|
if (n) {
|
|
1514
1527
|
let e = n.content;
|
|
1515
|
-
if (Array.isArray(e)) return e.map((e) => String(
|
|
1528
|
+
if (Array.isArray(e)) return e.map((e) => String(K(e)?.text || "")).join("");
|
|
1516
1529
|
for (let e of [
|
|
1517
1530
|
"text",
|
|
1518
1531
|
"output",
|
|
@@ -1522,31 +1535,31 @@ function Xe(e) {
|
|
|
1522
1535
|
}
|
|
1523
1536
|
return "";
|
|
1524
1537
|
}
|
|
1525
|
-
function
|
|
1526
|
-
return e.map(
|
|
1538
|
+
function J(e) {
|
|
1539
|
+
return e.map($e).join("");
|
|
1527
1540
|
}
|
|
1528
|
-
function
|
|
1529
|
-
return e.some((e) =>
|
|
1541
|
+
function et(e) {
|
|
1542
|
+
return e.some((e) => K(K(e)?.data)?.type === "userMessage");
|
|
1530
1543
|
}
|
|
1531
|
-
function
|
|
1544
|
+
function Y(e) {
|
|
1532
1545
|
if (e.length === 1) {
|
|
1533
|
-
let t =
|
|
1546
|
+
let t = K(K(e[0])?.data);
|
|
1534
1547
|
if (t) return t;
|
|
1535
1548
|
}
|
|
1536
|
-
return
|
|
1549
|
+
return J(e) || null;
|
|
1537
1550
|
}
|
|
1538
|
-
function
|
|
1539
|
-
let t =
|
|
1540
|
-
return t ?
|
|
1551
|
+
function X(e) {
|
|
1552
|
+
let t = K(e);
|
|
1553
|
+
return t ? K(t.data) || t : null;
|
|
1541
1554
|
}
|
|
1542
|
-
function
|
|
1543
|
-
let t =
|
|
1555
|
+
function tt(e) {
|
|
1556
|
+
let t = X(e);
|
|
1544
1557
|
return String(t?.content_type || t?.type || "").trim().toLowerCase();
|
|
1545
1558
|
}
|
|
1546
|
-
function
|
|
1559
|
+
function nt(e) {
|
|
1547
1560
|
for (let t of e) {
|
|
1548
|
-
let e =
|
|
1549
|
-
if (!e ||
|
|
1561
|
+
let e = X(t);
|
|
1562
|
+
if (!e || tt(t) !== "tool_call") continue;
|
|
1550
1563
|
let n = String(e.call_id || "").trim(), r = String(e.name || e.tool_name || "").trim();
|
|
1551
1564
|
if (!(!n && !r)) return {
|
|
1552
1565
|
callId: n,
|
|
@@ -1556,10 +1569,10 @@ function et(e) {
|
|
|
1556
1569
|
}
|
|
1557
1570
|
return null;
|
|
1558
1571
|
}
|
|
1559
|
-
function
|
|
1572
|
+
function rt(e) {
|
|
1560
1573
|
for (let t of e) {
|
|
1561
|
-
let e =
|
|
1562
|
-
if (!e ||
|
|
1574
|
+
let e = X(t);
|
|
1575
|
+
if (!e || tt(t) !== "tool_result") continue;
|
|
1563
1576
|
let n = String(e.call_id || e.tool_call_id || "").trim(), r = e.is_error === !0 || e.error != null;
|
|
1564
1577
|
return {
|
|
1565
1578
|
callId: n,
|
|
@@ -1581,7 +1594,7 @@ function Z(e, t, n, r) {
|
|
|
1581
1594
|
...i && i !== a ? { SourceItemId: i } : {}
|
|
1582
1595
|
} };
|
|
1583
1596
|
}
|
|
1584
|
-
var
|
|
1597
|
+
var it = class {
|
|
1585
1598
|
textByPart = /* @__PURE__ */ new Map();
|
|
1586
1599
|
toolNameByCallId = /* @__PURE__ */ new Map();
|
|
1587
1600
|
toolCallByItemId = /* @__PURE__ */ new Map();
|
|
@@ -1591,7 +1604,7 @@ var nt = class {
|
|
|
1591
1604
|
this.sessionId = e;
|
|
1592
1605
|
}
|
|
1593
1606
|
translate(e) {
|
|
1594
|
-
if (!
|
|
1607
|
+
if (!K(e)) return null;
|
|
1595
1608
|
let t = Number(e.seq);
|
|
1596
1609
|
if (!Number.isFinite(t) || t <= 0) return null;
|
|
1597
1610
|
let n = String(e.family || ""), r = String(e.event_type || ""), i = String(e.run_id || ""), a = () => ({
|
|
@@ -1613,7 +1626,7 @@ var nt = class {
|
|
|
1613
1626
|
};
|
|
1614
1627
|
if (r === "control.run_transition") {
|
|
1615
1628
|
let t = String(e.state || "").toLowerCase();
|
|
1616
|
-
if (
|
|
1629
|
+
if (Ze.has(t)) return {
|
|
1617
1630
|
...a(),
|
|
1618
1631
|
EventType: "run_status",
|
|
1619
1632
|
Content: { status: t }
|
|
@@ -1622,19 +1635,19 @@ var nt = class {
|
|
|
1622
1635
|
return null;
|
|
1623
1636
|
}
|
|
1624
1637
|
if (n !== "runtime") return null;
|
|
1625
|
-
let o =
|
|
1638
|
+
let o = K(K(e.source)?.metadata), s = o?.conversation_visibility ?? o?.visibility;
|
|
1626
1639
|
if (r.startsWith("item.") && ["internal", "hidden"].includes(String(s))) return null;
|
|
1627
|
-
let c =
|
|
1640
|
+
let c = Xe[r];
|
|
1628
1641
|
if (c) return {
|
|
1629
1642
|
...a(),
|
|
1630
1643
|
EventType: "run_status",
|
|
1631
1644
|
Content: { status: c }
|
|
1632
1645
|
};
|
|
1633
|
-
let l =
|
|
1646
|
+
let l = Qe(e);
|
|
1634
1647
|
if (r === "item.started") {
|
|
1635
|
-
let t =
|
|
1648
|
+
let t = q(e, "initial");
|
|
1636
1649
|
if (e.item_kind === "tool_call") {
|
|
1637
|
-
let n =
|
|
1650
|
+
let n = nt(t);
|
|
1638
1651
|
if (!n) return null;
|
|
1639
1652
|
let r = n?.callId || String(e.item_id || ""), o = n?.name || "tool";
|
|
1640
1653
|
return r && this.toolNameByCallId.set(r, o), e.item_id && this.toolCallByItemId.set(String(e.item_id), {
|
|
@@ -1648,11 +1661,11 @@ var nt = class {
|
|
|
1648
1661
|
call_id: r,
|
|
1649
1662
|
tool_name: o,
|
|
1650
1663
|
run_id: i,
|
|
1651
|
-
tool_args: n?.arguments ??
|
|
1664
|
+
tool_args: n?.arguments ?? Y(t)
|
|
1652
1665
|
}
|
|
1653
1666
|
};
|
|
1654
1667
|
}
|
|
1655
|
-
return e.item_kind === "tool_result" || l === "userMessage" ||
|
|
1668
|
+
return e.item_kind === "tool_result" || l === "userMessage" || et(t) || l === "reasoning" || e.item_kind === "reasoning" ? null : l === "agentMessage" || !l && e.item_kind === "message" ? {
|
|
1656
1669
|
...a(),
|
|
1657
1670
|
EventType: "assistant_stream_snapshot",
|
|
1658
1671
|
Content: { parts: [{ text: "" }] },
|
|
@@ -1665,14 +1678,14 @@ var nt = class {
|
|
|
1665
1678
|
call_id: String(e.item_id || ""),
|
|
1666
1679
|
tool_name: l,
|
|
1667
1680
|
run_id: i,
|
|
1668
|
-
tool_args:
|
|
1681
|
+
tool_args: Y(t)
|
|
1669
1682
|
}
|
|
1670
1683
|
} : null;
|
|
1671
1684
|
}
|
|
1672
1685
|
if (r === "item.updated") {
|
|
1673
|
-
let n =
|
|
1686
|
+
let n = q(e, "update");
|
|
1674
1687
|
if (e.item_kind === "tool_call") {
|
|
1675
|
-
let t =
|
|
1688
|
+
let t = rt(n);
|
|
1676
1689
|
if (!t) return null;
|
|
1677
1690
|
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;
|
|
1678
1691
|
return e.item_id && this.toolResultByItemId.set(String(e.item_id), c), {
|
|
@@ -1687,7 +1700,7 @@ var nt = class {
|
|
|
1687
1700
|
}
|
|
1688
1701
|
};
|
|
1689
1702
|
}
|
|
1690
|
-
let r =
|
|
1703
|
+
let r = K(n[0]), o = String(r?.part_id || e.item_id || t), s = String(e.op || "replace"), c = J(n), u = this.textByPart.get(o) || "", d = s === "append" ? u + c : c;
|
|
1691
1704
|
return this.textByPart.set(o, d), l === "agentMessage" || !l && e.item_kind === "message" ? {
|
|
1692
1705
|
...a(),
|
|
1693
1706
|
EventType: "assistant_stream_snapshot",
|
|
@@ -1701,7 +1714,7 @@ var nt = class {
|
|
|
1701
1714
|
} : null;
|
|
1702
1715
|
}
|
|
1703
1716
|
if (r === "item.snapshot_replaced") {
|
|
1704
|
-
let n =
|
|
1717
|
+
let n = q(e, "snapshot"), r = String(K(n[0])?.part_id || e.item_id || t), i = J(n);
|
|
1705
1718
|
return this.textByPart.set(r, i), l === "agentMessage" || !l && e.item_kind === "message" ? {
|
|
1706
1719
|
...a(),
|
|
1707
1720
|
EventType: "assistant_stream_snapshot",
|
|
@@ -1715,9 +1728,9 @@ var nt = class {
|
|
|
1715
1728
|
} : null;
|
|
1716
1729
|
}
|
|
1717
1730
|
if (r === "item.completed") {
|
|
1718
|
-
let n =
|
|
1731
|
+
let n = q(e, "snapshot");
|
|
1719
1732
|
if (e.item_kind === "tool_call") {
|
|
1720
|
-
let t =
|
|
1733
|
+
let t = nt(n), r = rt(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";
|
|
1721
1734
|
if (s && this.toolNameByCallId.set(s, c), r) {
|
|
1722
1735
|
let t = r.isError ? { error: r.result } : r.result;
|
|
1723
1736
|
return {
|
|
@@ -1740,12 +1753,12 @@ var nt = class {
|
|
|
1740
1753
|
call_id: s,
|
|
1741
1754
|
tool_name: c,
|
|
1742
1755
|
run_id: i,
|
|
1743
|
-
tool_args: t?.arguments ??
|
|
1756
|
+
tool_args: t?.arguments ?? Y(n)
|
|
1744
1757
|
}
|
|
1745
1758
|
};
|
|
1746
1759
|
}
|
|
1747
1760
|
if (e.item_kind === "tool_result") {
|
|
1748
|
-
let t =
|
|
1761
|
+
let t = rt(n), r = t?.callId || String(e.item_id || ""), o = this.toolNameByCallId.get(r) || l || "tool", s = t?.isError ? { error: t.result } : t?.result ?? Y(n);
|
|
1749
1762
|
return {
|
|
1750
1763
|
...a(),
|
|
1751
1764
|
EventType: "tool_result",
|
|
@@ -1758,13 +1771,13 @@ var nt = class {
|
|
|
1758
1771
|
}
|
|
1759
1772
|
};
|
|
1760
1773
|
}
|
|
1761
|
-
if (l === "userMessage" ||
|
|
1774
|
+
if (l === "userMessage" || et(n)) return {
|
|
1762
1775
|
...a(),
|
|
1763
1776
|
EventType: "user_message",
|
|
1764
|
-
Content: { parts: [{ text:
|
|
1777
|
+
Content: { parts: [{ text: J(n) }] }
|
|
1765
1778
|
};
|
|
1766
1779
|
if (l === "agentMessage" || !l && e.item_kind === "message") {
|
|
1767
|
-
let r =
|
|
1780
|
+
let r = J(n), i = String(K(n[0])?.part_id || e.item_id || t);
|
|
1768
1781
|
return this.textByPart.set(i, r), {
|
|
1769
1782
|
...a(),
|
|
1770
1783
|
EventType: "assistant_message",
|
|
@@ -1773,11 +1786,11 @@ var nt = class {
|
|
|
1773
1786
|
};
|
|
1774
1787
|
}
|
|
1775
1788
|
if (l === "reasoning" || e.item_kind === "reasoning") {
|
|
1776
|
-
let r = String(
|
|
1789
|
+
let r = String(K(n[0])?.part_id || e.item_id || t);
|
|
1777
1790
|
return {
|
|
1778
1791
|
...a(),
|
|
1779
1792
|
EventType: "reasoning",
|
|
1780
|
-
Content: { parts: [{ text:
|
|
1793
|
+
Content: { parts: [{ text: J(n) }] },
|
|
1781
1794
|
Metadata: Z(e, "completed", r)
|
|
1782
1795
|
};
|
|
1783
1796
|
}
|
|
@@ -1789,7 +1802,7 @@ var nt = class {
|
|
|
1789
1802
|
call_id: String(e.item_id || ""),
|
|
1790
1803
|
tool_name: l,
|
|
1791
1804
|
run_id: i,
|
|
1792
|
-
tool_output:
|
|
1805
|
+
tool_output: Y(n)
|
|
1793
1806
|
}
|
|
1794
1807
|
} : null;
|
|
1795
1808
|
}
|
|
@@ -1804,7 +1817,7 @@ var nt = class {
|
|
|
1804
1817
|
call_id: n,
|
|
1805
1818
|
tool_name: r,
|
|
1806
1819
|
run_id: i,
|
|
1807
|
-
tool_output: o ?? { error:
|
|
1820
|
+
tool_output: o ?? { error: K(e.error) || e.error || "item failed" }
|
|
1808
1821
|
}
|
|
1809
1822
|
};
|
|
1810
1823
|
}
|
|
@@ -1816,14 +1829,14 @@ var nt = class {
|
|
|
1816
1829
|
call_id: String(e.item_id || ""),
|
|
1817
1830
|
tool_name: l,
|
|
1818
1831
|
run_id: i,
|
|
1819
|
-
tool_output: { error:
|
|
1832
|
+
tool_output: { error: K(e.error) || e.error || "item failed" }
|
|
1820
1833
|
}
|
|
1821
1834
|
} : null;
|
|
1822
1835
|
}
|
|
1823
1836
|
return null;
|
|
1824
1837
|
}
|
|
1825
1838
|
};
|
|
1826
|
-
async function
|
|
1839
|
+
async function at(e) {
|
|
1827
1840
|
let t = e.getReader(), n = new TextDecoder(), r = "", i = null, a = !1, o = (e) => e.includes("data:") || e.includes("event:") || e.includes(":");
|
|
1828
1841
|
try {
|
|
1829
1842
|
for (;;) {
|
|
@@ -1833,8 +1846,8 @@ async function rt(e) {
|
|
|
1833
1846
|
break;
|
|
1834
1847
|
}
|
|
1835
1848
|
if (r.trimStart().startsWith("{")) {
|
|
1836
|
-
if (
|
|
1837
|
-
i =
|
|
1849
|
+
if (ot(r)) {
|
|
1850
|
+
i = st(r);
|
|
1838
1851
|
break;
|
|
1839
1852
|
}
|
|
1840
1853
|
} else if (o(r)) break;
|
|
@@ -1870,7 +1883,7 @@ async function rt(e) {
|
|
|
1870
1883
|
stream: c
|
|
1871
1884
|
};
|
|
1872
1885
|
}
|
|
1873
|
-
function
|
|
1886
|
+
function ot(e) {
|
|
1874
1887
|
let t = e.trim();
|
|
1875
1888
|
if (!t.endsWith("}")) return !1;
|
|
1876
1889
|
let n = 0, r = !1, i = !1;
|
|
@@ -1887,11 +1900,11 @@ function it(e) {
|
|
|
1887
1900
|
}
|
|
1888
1901
|
return n === 0;
|
|
1889
1902
|
}
|
|
1890
|
-
function
|
|
1903
|
+
function st(e) {
|
|
1891
1904
|
try {
|
|
1892
|
-
let t =
|
|
1905
|
+
let t = K(JSON.parse(e).Data), n = String(t?.ReceiptStatus || "");
|
|
1893
1906
|
if (!n) return null;
|
|
1894
|
-
let r =
|
|
1907
|
+
let r = K(t?.Error);
|
|
1895
1908
|
return {
|
|
1896
1909
|
status: n,
|
|
1897
1910
|
presentationProfile: t?.PresentationProfile === "agent-block-v1" ? "agent-block-v1" : "flat-v1",
|
|
@@ -1913,8 +1926,8 @@ function at(e) {
|
|
|
1913
1926
|
function Q(e) {
|
|
1914
1927
|
return e && typeof e == "object" && !Array.isArray(e) ? e : null;
|
|
1915
1928
|
}
|
|
1916
|
-
function
|
|
1917
|
-
let t = e.map(
|
|
1929
|
+
function ct(e) {
|
|
1930
|
+
let t = e.map(dt), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t, n) => JSON.stringify([
|
|
1918
1931
|
e,
|
|
1919
1932
|
t,
|
|
1920
1933
|
n
|
|
@@ -1942,7 +1955,7 @@ function ot(e) {
|
|
|
1942
1955
|
} : e;
|
|
1943
1956
|
});
|
|
1944
1957
|
}
|
|
1945
|
-
function
|
|
1958
|
+
function lt(e) {
|
|
1946
1959
|
if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
|
|
1947
1960
|
if (typeof e == "string" && e.trim()) {
|
|
1948
1961
|
let t = Number(e.trim());
|
|
@@ -1951,7 +1964,78 @@ function st(e) {
|
|
|
1951
1964
|
let t = Date.parse(String(e || ""));
|
|
1952
1965
|
return Number.isFinite(t) ? t : Date.now();
|
|
1953
1966
|
}
|
|
1954
|
-
function
|
|
1967
|
+
function ut(e, t, r, i, a) {
|
|
1968
|
+
let o = /* @__PURE__ */ new Set(), s = (e, t) => JSON.stringify([e, t]), c = /* @__PURE__ */ new Set();
|
|
1969
|
+
for (let e of t) {
|
|
1970
|
+
let t = n(e, i);
|
|
1971
|
+
t?.kind === "approval" && t.outcome === "rejected" && t.runId && (o.add(t.runId), c.add(s(t.runId, t.interactionId)));
|
|
1972
|
+
}
|
|
1973
|
+
let l = /* @__PURE__ */ new Map();
|
|
1974
|
+
for (let e of r) {
|
|
1975
|
+
if (e?.item_kind !== "data" || e.event_type !== "item.completed" || typeof e.run_id != "string" || typeof e.scope_id != "string" || Q(e.source)?.framework !== "langgraph") continue;
|
|
1976
|
+
let t = Q(e.snapshot)?.parts;
|
|
1977
|
+
if (Array.isArray(t)) for (let n of t) {
|
|
1978
|
+
let t = Q(Q(Q(n)?.data)?.["HumanInTheLoopMiddleware.after_model"]);
|
|
1979
|
+
if (Array.isArray(t?.messages)) for (let n of t.messages.map(Q)) {
|
|
1980
|
+
if (n?.type !== "tool" || n.status !== "error" || typeof n.tool_call_id != "string") continue;
|
|
1981
|
+
o.add(e.run_id);
|
|
1982
|
+
let t = s(e.run_id, n.tool_call_id), r = l.get(t) ?? /* @__PURE__ */ new Set();
|
|
1983
|
+
r.add(e.scope_id), l.set(t, r);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
if (!o.size) return e;
|
|
1988
|
+
let u = /* @__PURE__ */ new Set();
|
|
1989
|
+
for (let t of e) {
|
|
1990
|
+
let e = t.invocationId || t.runId;
|
|
1991
|
+
if (!(!t.scopeId || !e || !o.has(e))) for (let n of Object.values(t.tools || {})) n.callId && u.add(s(e, n.callId));
|
|
1992
|
+
}
|
|
1993
|
+
let d = (e) => {
|
|
1994
|
+
if (e.agentBlock) return {
|
|
1995
|
+
...e,
|
|
1996
|
+
agentBlock: {
|
|
1997
|
+
...e.agentBlock,
|
|
1998
|
+
messages: e.agentBlock.messages.map(d)
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
2001
|
+
let t = e.invocationId || e.runId;
|
|
2002
|
+
if (!t || !o.has(t) || e.role !== "model") return e;
|
|
2003
|
+
let n = (n, r, i) => {
|
|
2004
|
+
if (![
|
|
2005
|
+
"running",
|
|
2006
|
+
"paused",
|
|
2007
|
+
"unknown"
|
|
2008
|
+
].includes(i)) return;
|
|
2009
|
+
let o = typeof n == "string" ? s(t, n) : "", d = l.get(o);
|
|
2010
|
+
if (typeof r == "string" && c.has(s(t, r)) || d && (e.scopeId ? d.has(e.scopeId) : d.size === 1 && !u.has(o))) return {
|
|
2011
|
+
status: "completed",
|
|
2012
|
+
approvalStatus: "rejected"
|
|
2013
|
+
};
|
|
2014
|
+
if (i !== "unknown" && a.has(t)) return { status: "unknown" };
|
|
2015
|
+
};
|
|
2016
|
+
return {
|
|
2017
|
+
...e,
|
|
2018
|
+
tools: e.tools && Object.fromEntries(Object.entries(e.tools).map(([e, t]) => [e, {
|
|
2019
|
+
...t,
|
|
2020
|
+
...n(t.callId, t.approvalRequestId, t.status)
|
|
2021
|
+
}])),
|
|
2022
|
+
blocks: e.blocks?.map((e) => {
|
|
2023
|
+
if (e.type !== "tool") return e;
|
|
2024
|
+
let t = n(e.extra?.callId, e.extra?.approvalRequestId, e.status);
|
|
2025
|
+
return t ? {
|
|
2026
|
+
...e,
|
|
2027
|
+
status: t.status,
|
|
2028
|
+
extra: {
|
|
2029
|
+
...e.extra,
|
|
2030
|
+
...t.approvalStatus ? { approvalStatus: t.approvalStatus } : {}
|
|
2031
|
+
}
|
|
2032
|
+
} : e;
|
|
2033
|
+
})
|
|
2034
|
+
};
|
|
2035
|
+
};
|
|
2036
|
+
return e.map(d);
|
|
2037
|
+
}
|
|
2038
|
+
function dt(e) {
|
|
1955
2039
|
let t = Q(e?.Content?.runtime_event || e?.Content?.runtimeEvent);
|
|
1956
2040
|
if (t && String(t.event_type || "")) return {
|
|
1957
2041
|
...t,
|
|
@@ -1971,58 +2055,58 @@ function ct(e) {
|
|
|
1971
2055
|
timestamp: e.Timestamp || n.timestamp || r.timestamp
|
|
1972
2056
|
};
|
|
1973
2057
|
}
|
|
1974
|
-
function
|
|
2058
|
+
function ft(e, t, n) {
|
|
1975
2059
|
let i = /* @__PURE__ */ new Map();
|
|
1976
|
-
for (let e of
|
|
1977
|
-
if (e.EventType !== "run_status" ||
|
|
2060
|
+
for (let e of t) {
|
|
2061
|
+
if (e.EventType !== "run_status" || dt(e)) continue;
|
|
1978
2062
|
let t = String(e.InvocationId || e.Metadata?.run_id || "").trim();
|
|
1979
|
-
t && !
|
|
2063
|
+
t && !n.has(t) && i.set(t, e);
|
|
1980
2064
|
}
|
|
1981
2065
|
let a = e;
|
|
1982
|
-
for (let [e,
|
|
1983
|
-
let
|
|
1984
|
-
...
|
|
1985
|
-
EventId:
|
|
1986
|
-
Timestamp:
|
|
2066
|
+
for (let [e, t] of i) {
|
|
2067
|
+
let n = r({
|
|
2068
|
+
...t,
|
|
2069
|
+
EventId: t.EventId || `legacy-terminal:${e}:${t.SeqId || 0}`,
|
|
2070
|
+
Timestamp: lt(t.Timestamp)
|
|
1987
2071
|
});
|
|
1988
|
-
if (!
|
|
2072
|
+
if (!n) continue;
|
|
1989
2073
|
let i = (t) => (t.invocationId || t.runId) === e;
|
|
1990
2074
|
a = a.filter((e) => !(i(e) && e.role === "system" && e.eventType === "run_status")).map((e) => {
|
|
1991
2075
|
if (!i(e) || e.role !== "model") return e;
|
|
1992
|
-
let t = (e) => e === "running" || e === "paused",
|
|
2076
|
+
let t = (e) => e === "running" || e === "paused", r = "运行已结束,未记录此工具的最终结果。";
|
|
1993
2077
|
return {
|
|
1994
2078
|
...e,
|
|
1995
|
-
tools: e.tools && Object.fromEntries(Object.entries(e.tools).map(([e,
|
|
1996
|
-
...
|
|
2079
|
+
tools: e.tools && Object.fromEntries(Object.entries(e.tools).map(([e, n]) => [e, t(n.status) ? {
|
|
2080
|
+
...n,
|
|
1997
2081
|
status: "unknown",
|
|
1998
|
-
summary:
|
|
1999
|
-
} :
|
|
2082
|
+
summary: n.summary || r
|
|
2083
|
+
} : n])),
|
|
2000
2084
|
blocks: e.blocks?.map((e) => e.type === "thinking" && e.status === "streaming" ? {
|
|
2001
2085
|
...e,
|
|
2002
2086
|
status: "done"
|
|
2003
2087
|
} : e.type !== "tool" || !t(e.status) ? e : {
|
|
2004
2088
|
...e,
|
|
2005
2089
|
status: "unknown",
|
|
2006
|
-
summary: e.summary ||
|
|
2090
|
+
summary: e.summary || r,
|
|
2007
2091
|
extra: {
|
|
2008
2092
|
...e.extra,
|
|
2009
2093
|
persistedToolStatus: e.status,
|
|
2010
|
-
terminalRunStatus:
|
|
2094
|
+
terminalRunStatus: n.status
|
|
2011
2095
|
}
|
|
2012
2096
|
})
|
|
2013
2097
|
};
|
|
2014
2098
|
}), a.push({
|
|
2015
|
-
...
|
|
2099
|
+
...n,
|
|
2016
2100
|
invocationId: e,
|
|
2017
|
-
eventId:
|
|
2101
|
+
eventId: t.EventId
|
|
2018
2102
|
});
|
|
2019
2103
|
}
|
|
2020
|
-
return a === e ? e :
|
|
2104
|
+
return a === e ? e : L(a);
|
|
2021
2105
|
}
|
|
2022
2106
|
function $(e) {
|
|
2023
2107
|
return e.role === "model" ? {
|
|
2024
2108
|
...e,
|
|
2025
|
-
blocks: e.blocks?.length ? e.blocks :
|
|
2109
|
+
blocks: e.blocks?.length ? e.blocks : Ye({
|
|
2026
2110
|
content: e.content,
|
|
2027
2111
|
reasoning: e.reasoning,
|
|
2028
2112
|
reasoningSource: e.reasoningSource,
|
|
@@ -2030,7 +2114,7 @@ function $(e) {
|
|
|
2030
2114
|
})
|
|
2031
2115
|
} : e;
|
|
2032
2116
|
}
|
|
2033
|
-
function
|
|
2117
|
+
function pt(e, t) {
|
|
2034
2118
|
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 ? {
|
|
2035
2119
|
...e,
|
|
2036
2120
|
...n,
|
|
@@ -2043,7 +2127,7 @@ function ut(e, t) {
|
|
|
2043
2127
|
} : e));
|
|
2044
2128
|
return n && !r ? [n, ...s] : s;
|
|
2045
2129
|
}
|
|
2046
|
-
function
|
|
2130
|
+
function mt(e, t) {
|
|
2047
2131
|
let n = t.filter((e) => e.role === "model"), r = n.flatMap((e) => Object.values(e.tools || {}).map((t) => ({
|
|
2048
2132
|
tool: t,
|
|
2049
2133
|
scope: e.scopeId
|
|
@@ -2058,7 +2142,7 @@ function dt(e, t) {
|
|
|
2058
2142
|
return [t, r ? {
|
|
2059
2143
|
...n,
|
|
2060
2144
|
...r,
|
|
2061
|
-
...
|
|
2145
|
+
...P(n, r),
|
|
2062
2146
|
name: n.name
|
|
2063
2147
|
} : n];
|
|
2064
2148
|
})), n = e === s ? a : [];
|
|
@@ -2071,9 +2155,9 @@ function dt(e, t) {
|
|
|
2071
2155
|
let n = t.extra?.callId, r = typeof n == "string" ? i(n, e.scopeId) : void 0;
|
|
2072
2156
|
return r ? {
|
|
2073
2157
|
...t,
|
|
2074
|
-
...
|
|
2158
|
+
...P(t, r)
|
|
2075
2159
|
} : t;
|
|
2076
|
-
}), c =
|
|
2160
|
+
}), c = Ye({ tools: Object.fromEntries(n.map(({ tool: e, scope: t }) => [JSON.stringify([t || "", e.callId || e.name]), e])) }), l = r?.findIndex((e) => e.type === "text") ?? -1;
|
|
2077
2161
|
return $({
|
|
2078
2162
|
...e,
|
|
2079
2163
|
...e === s ? { reasoning: e.reasoning || o || void 0 } : {},
|
|
@@ -2086,21 +2170,21 @@ function dt(e, t) {
|
|
|
2086
2170
|
});
|
|
2087
2171
|
});
|
|
2088
2172
|
}
|
|
2089
|
-
function
|
|
2173
|
+
function ht(e) {
|
|
2090
2174
|
return new Set(e.filter((e) => e.role === "model" && e.eventType === "assistant_message" && !!String(e.content || "").trim() && !!e.invocationId).map((e) => String(e.invocationId)));
|
|
2091
2175
|
}
|
|
2092
|
-
var
|
|
2176
|
+
var gt = new Set([
|
|
2093
2177
|
"approval.resolved",
|
|
2094
2178
|
"interaction.resolved",
|
|
2095
2179
|
"interaction.cancelled",
|
|
2096
2180
|
"interaction.canceled",
|
|
2097
2181
|
"a2ui.action"
|
|
2098
2182
|
]);
|
|
2099
|
-
function
|
|
2183
|
+
function _t(e) {
|
|
2100
2184
|
let t = /* @__PURE__ */ new Set();
|
|
2101
2185
|
for (let n of e) {
|
|
2102
2186
|
let e = Q(n.Content) || {}, r = Q(e.runtime_event || e.runtimeEvent) || {}, i = Q(e.payload) || Q(r.payload) || {}, a = String(n.EventType || e.event_type || e.eventType || r.event_type || "").toLowerCase();
|
|
2103
|
-
if (!
|
|
2187
|
+
if (!gt.has(a)) continue;
|
|
2104
2188
|
let o = String(e.outcome || e.action || e.name || e.status || i.outcome || i.action || i.name || i.status || "").toLowerCase();
|
|
2105
2189
|
if (![
|
|
2106
2190
|
"cancel",
|
|
@@ -2112,16 +2196,16 @@ function mt(e) {
|
|
|
2112
2196
|
}
|
|
2113
2197
|
return t;
|
|
2114
2198
|
}
|
|
2115
|
-
function
|
|
2116
|
-
e =
|
|
2117
|
-
let a = new
|
|
2199
|
+
function vt(e, t, n, r = "flat-v1") {
|
|
2200
|
+
e = F(e);
|
|
2201
|
+
let a = new it(n), o = [], s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), u = [...t || []].filter((e) => {
|
|
2118
2202
|
let t = e.Content, r = Q(t?.session_event || t?.sessionEvent), i = Q(t?.runtime_event || t?.runtimeEvent);
|
|
2119
2203
|
return [
|
|
2120
2204
|
e.SessionId,
|
|
2121
2205
|
r?.session_id,
|
|
2122
2206
|
i?.session_id
|
|
2123
2207
|
].every((e) => !e || e === n);
|
|
2124
|
-
}).sort((e, t) => Number(e.SeqId || 0) - Number(t.SeqId || 0)), d = Number(u[0]?.SeqId || 0) <= 1, f =
|
|
2208
|
+
}).sort((e, t) => Number(e.SeqId || 0) - Number(t.SeqId || 0)), d = Number(u[0]?.SeqId || 0) <= 1, f = ct(u);
|
|
2125
2209
|
for (let [e, t] of u.entries()) {
|
|
2126
2210
|
let n = f[e];
|
|
2127
2211
|
if (!n) continue;
|
|
@@ -2140,15 +2224,15 @@ function ht(e, t, n, i = "flat-v1") {
|
|
|
2140
2224
|
i && o.push({
|
|
2141
2225
|
...i,
|
|
2142
2226
|
SeqId: Number(t.SeqId || i.SeqId || 0),
|
|
2143
|
-
Timestamp:
|
|
2227
|
+
Timestamp: lt(t.Timestamp || i.Timestamp)
|
|
2144
2228
|
});
|
|
2145
2229
|
}
|
|
2146
|
-
let p =
|
|
2230
|
+
let p = i(o).filter((e) => e.invocationId && s.has(e.invocationId)), m = /* @__PURE__ */ new Map();
|
|
2147
2231
|
for (let t of e) {
|
|
2148
2232
|
let e = String(t.invocationId || "");
|
|
2149
2233
|
e && m.set(e, [...m.get(e) || [], t]);
|
|
2150
2234
|
}
|
|
2151
|
-
let h = new Set([...
|
|
2235
|
+
let h = new Set([...ht(p)].filter((e) => l.has(e))), g = /* @__PURE__ */ new Map();
|
|
2152
2236
|
for (let e of f) {
|
|
2153
2237
|
if (e?.schema_version !== 2 || !e.run_id) continue;
|
|
2154
2238
|
let t = String(e.run_id), n = g.get(t) || [];
|
|
@@ -2161,15 +2245,15 @@ function ht(e, t, n, i = "flat-v1") {
|
|
|
2161
2245
|
].some((e) => Q(e?.data)?.schema === "execution.scope/v1" || Array.isArray(e?.parts) && e.parts.some((e) => Q(Q(e)?.data)?.schema === "execution.scope/v1")), v = new Set([...g].filter(([, e]) => e.some(_)).map(([e]) => e)), y = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Set();
|
|
2162
2246
|
for (let [e, t] of g) {
|
|
2163
2247
|
if (!v.has(e) && !h.has(e) && !t.some((e) => ["item.failed", "run.failed"].includes(String(e.event_type)))) continue;
|
|
2164
|
-
let
|
|
2248
|
+
let i = t.some((e) => e.event_type === "run.started" && !e.parent_scope_id), a = /* @__PURE__ */ new Set(), o = t.every((e) => {
|
|
2165
2249
|
let t = JSON.stringify([e.scope_id, e.item_id]);
|
|
2166
2250
|
return e.event_type === "item.started" && a.add(t), !_(e) || a.has(t);
|
|
2167
2251
|
});
|
|
2168
|
-
if (!(!
|
|
2169
|
-
let
|
|
2170
|
-
t.forEach((e) =>
|
|
2171
|
-
let a =
|
|
2172
|
-
y.set(e,
|
|
2252
|
+
if (!(!i || !o)) try {
|
|
2253
|
+
let i = new w(n, void 0, r);
|
|
2254
|
+
t.forEach((e) => i.apply(e));
|
|
2255
|
+
let a = i.snapshot(), o = me(a, { profile: r }), s = lt(t[0].timestamp);
|
|
2256
|
+
y.set(e, U({
|
|
2173
2257
|
state: a,
|
|
2174
2258
|
presentation: o,
|
|
2175
2259
|
runId: e,
|
|
@@ -2191,21 +2275,21 @@ function ht(e, t, n, i = "flat-v1") {
|
|
|
2191
2275
|
}
|
|
2192
2276
|
}
|
|
2193
2277
|
for (let e of new Set([...v, ...b])) y.has(e) || h.delete(e);
|
|
2194
|
-
let x =
|
|
2278
|
+
let x = _t(u), S = [...h].flatMap((e) => pt(p.filter((t) => t.invocationId === e), m.get(e) || [])), C = /* @__PURE__ */ new Map(), T = [];
|
|
2195
2279
|
for (let [e, t] of m) {
|
|
2196
2280
|
if (h.has(e) || !s.has(e)) continue;
|
|
2197
2281
|
let n = p.filter((t) => t.invocationId === e), r = t.some((e) => e.role === "model" && String(e.content || "").trim());
|
|
2198
|
-
|
|
2282
|
+
C.set(e, r ? mt(t, n) : t), r || T.push(...n.map($));
|
|
2199
2283
|
}
|
|
2200
2284
|
for (let e of s) h.has(e) || m.has(e) || T.push(...p.filter((t) => t.invocationId === e).map($));
|
|
2201
|
-
let ee = new Map([...
|
|
2285
|
+
let ee = new Map([...C.values()].flat().map((e) => [e.id, e])), E = L([
|
|
2202
2286
|
...e.filter((e) => !(e.role === "model" && e.invocationId && x.has(e.invocationId)) && (e.role === "a2ui" || !e.invocationId || !h.has(e.invocationId))).map((e) => ee.get(e.id) || e),
|
|
2203
2287
|
...S,
|
|
2204
2288
|
...T
|
|
2205
2289
|
]);
|
|
2206
2290
|
for (let [e, t] of y) {
|
|
2207
2291
|
if (!t.length) continue;
|
|
2208
|
-
let n = (t) => t.invocationId === e || t.runId === e, r = E.findIndex(n), i = E.filter(n), a = i.find((e) => e.role === "user"), o = v.has(e) ? a && !t.some((e) => e.role === "user") ? [a, ...t] : t :
|
|
2292
|
+
let n = (t) => t.invocationId === e || t.runId === e, r = E.findIndex(n), i = E.filter(n), a = i.find((e) => e.role === "user"), o = v.has(e) ? a && !t.some((e) => e.role === "user") ? [a, ...t] : t : pt(t, i), s = E.filter((e) => !n(e)), c = r < 0 ? s.length : r;
|
|
2209
2293
|
E = [
|
|
2210
2294
|
...s.slice(0, c),
|
|
2211
2295
|
...o,
|
|
@@ -2213,10 +2297,10 @@ function ht(e, t, n, i = "flat-v1") {
|
|
|
2213
2297
|
], h.add(e);
|
|
2214
2298
|
}
|
|
2215
2299
|
return {
|
|
2216
|
-
messages:
|
|
2300
|
+
messages: ut(F(L(ft(E, u, c))), u, f, n, c),
|
|
2217
2301
|
canonicalRunIds: [...h],
|
|
2218
2302
|
translatedEvents: o
|
|
2219
2303
|
};
|
|
2220
2304
|
}
|
|
2221
2305
|
//#endregion
|
|
2222
|
-
export {
|
|
2306
|
+
export { te as C, C as E, ne as S, w as T, F as _, Ue as a, Ce as b, Ge as c, He as d, Ke as f, Oe as g, U as h, at as i, Je as l, ze as m, vt as n, Ve as o, qe as p, it as r, Ye as s, dt as t, We as u, Ee as v, ee as w, me as x, Te as y };
|