@agimon-ai/po-cloudflare 0.0.2-alpha.7 → 0.0.2-alpha.71
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/README.md +64 -241
- package/container/Dockerfile +27 -0
- package/dist/{BrowserWebSocketTransport-C2SC2VeJ.js → BrowserWebSocketTransport-B4heNdrp.js} +1 -1
- package/dist/{NodeWebSocketTransport-CKilJesa.js → NodeWebSocketTransport-BCiOXUEz.js} +2 -2
- package/dist/{abort-signals-Bkmp_euQ.js → abort-signals-C8CttjsR.js} +1 -1
- package/dist/agent-CEqvgRl6.js +3878 -0
- package/dist/{anthropic-messages-CkYm8M3V.js → anthropic-messages-DCLLLNuM.js} +292 -64
- package/dist/apiContracts-DaOpUHnu.js +1719 -0
- package/dist/{approval-CQ3ZuoTy.js → approval-DXPV7Vm5.js} +15 -2
- package/dist/{approvalPrompt-CylV3C84.js → approvalPrompt-CBaxjb_g.js} +1 -2
- package/dist/approvalSession-C9bg7tPo.js +132 -0
- package/dist/artifactFiles-5KwXIxYf.js +1 -0
- package/dist/artifactsApi-bg2wMYWg.js +200 -0
- package/dist/assets/assets/{CodeEditorView-D4q94XH-.js → CodeEditorView-CfrVwzvL.js} +2 -2
- package/dist/assets/assets/{abnfDiagram-WEYOIA3C-C85p4OYZ.js → abnfDiagram-WEYOIA3C-B80H4Cm4.js} +2 -2
- package/dist/assets/assets/{architecture-WOLXFQ4H-Bt_NOdwE.js → architecture-WOLXFQ4H-Dr4hXaql.js} +1 -1
- package/dist/assets/assets/{architectureDiagram-ZHVYKT53-DzH1GKMm.js → architectureDiagram-ZHVYKT53-DWyt7oXu.js} +2 -2
- package/dist/assets/assets/{blockDiagram-RJAE7QA3-BmWU34j3.js → blockDiagram-RJAE7QA3-OxNTLdmi.js} +2 -2
- package/dist/assets/assets/{c4Diagram-XDPPPE54-BpGOdOuo.js → c4Diagram-XDPPPE54-B4YtcH0s.js} +2 -2
- package/dist/assets/assets/channel-bXj00dGj.js +2 -0
- package/dist/assets/assets/{chunk-2E7WHVMD-AycP1cXU.js → chunk-2E7WHVMD-CD6FFMOX.js} +2 -2
- package/dist/assets/assets/{chunk-4EMNKR2T-DX-DrZzc.js → chunk-4EMNKR2T-CEIoX5oo.js} +2 -2
- package/dist/assets/assets/{chunk-55XCU76K-BdwnLWzI.js → chunk-55XCU76K-CD3t0IJi.js} +2 -2
- package/dist/assets/assets/{chunk-7S6XSTFO-D-RBAwAn.js → chunk-7S6XSTFO-Cyt75UCF.js} +2 -2
- package/dist/assets/assets/{chunk-AQDTSKZB-CCxNNhKs.js → chunk-AQDTSKZB-DRtqYBj9.js} +2 -2
- package/dist/assets/assets/{chunk-DSNLSHJZ-D2hGwWm1.js → chunk-DSNLSHJZ-C8Fx2F8s.js} +2 -2
- package/dist/assets/assets/{chunk-HAGFOTED-BPi-cqGh.js → chunk-HAGFOTED-wOLWRRnd.js} +2 -2
- package/dist/assets/assets/{chunk-HNE4Q36P-D-r1ChHT.js → chunk-HNE4Q36P-CurJg4Hf.js} +2 -2
- package/dist/assets/assets/{chunk-NQOKRVIF-RgmZCAdn.js → chunk-NQOKRVIF-Dzcc5nOG.js} +2 -2
- package/dist/assets/assets/{chunk-UHW7PFBP-B-Hul-rZ.js → chunk-UHW7PFBP-B_ULFf2h.js} +2 -2
- package/dist/assets/assets/{chunk-VQ5W62QI-D1zlXCt8.js → chunk-VQ5W62QI-DH0VY4_p.js} +2 -2
- package/dist/assets/assets/{chunk-WQQL4CDK-CtjIbVJn.js → chunk-WQQL4CDK-DNxfLyXM.js} +2 -2
- package/dist/assets/assets/chunk-XXDRQBXY-B2bMWgN9.js +2 -0
- package/dist/assets/assets/{chunk-YZO67HFG-BQOgXG99.js → chunk-YZO67HFG-COuMUh9U.js} +2 -2
- package/dist/assets/assets/{chunk-ZAUX2LTX-CsDDxmqv.js → chunk-ZAUX2LTX-BJrCnubF.js} +2 -2
- package/dist/assets/assets/{chunk-ZCHMQSOR-deyEYMjx.js → chunk-ZCHMQSOR-D1lFKPtk.js} +2 -2
- package/dist/assets/assets/{classDiagram-v2-4MYWR3UA-DVJHeFlq.js → classDiagram-v2-4MYWR3UA-DfZIbyVL.js} +2 -2
- package/dist/assets/assets/{cose-bilkent-JH36ORCC-ipcN28Fw.js → cose-bilkent-JH36ORCC-CpGhv9_S.js} +2 -2
- package/dist/assets/assets/{cynefin-EF2NZ3EQ-s9ZkPF55.js → cynefin-EF2NZ3EQ-Cxdc6nQl.js} +1 -1
- package/dist/assets/assets/{cynefinDiagram-WF24UDRP-Ksr2qjsS.js → cynefinDiagram-WF24UDRP-qoj0w3lp.js} +2 -2
- package/dist/assets/assets/{dagre-NK4GIZVX-2_Wl-XEW.js → dagre-NK4GIZVX-DL6QbNDS.js} +2 -2
- package/dist/assets/assets/{diagram-CBK3MWTC-C7PeyT7l.js → diagram-CBK3MWTC-CJB3jq1_.js} +2 -2
- package/dist/assets/assets/{diagram-I5XIIV2D-DPYzeKdj.js → diagram-I5XIIV2D-4cPOxCxF.js} +2 -2
- package/dist/assets/assets/{diagram-ODIL2UCW-DHw1cAmn.js → diagram-ODIL2UCW-BG3-jAxE.js} +2 -2
- package/dist/assets/assets/{diagram-PFBEJUXE-C2wA8i-1.js → diagram-PFBEJUXE-Bx8dFaXj.js} +2 -2
- package/dist/assets/assets/{diagram-RJA3I4VV-tM3moCIs.js → diagram-RJA3I4VV-CUUHND91.js} +2 -2
- package/dist/assets/assets/{diagram-TYUNFSNR-CInyJxF7.js → diagram-TYUNFSNR-BDMoN-kr.js} +2 -2
- package/dist/assets/assets/{dist-BDqjNLTC.js → dist-5AxNm-uy.js} +2 -2
- package/dist/assets/assets/{dist-hpZIQBl4.js → dist-9_Rmyj2I.js} +2 -2
- package/dist/assets/assets/{dist-DSLprmec.js → dist-BE3CLKv4.js} +2 -2
- package/dist/assets/assets/{dist-BASEd5LC.js → dist-BfNCu-7x.js} +2 -2
- package/dist/assets/assets/{dist-BuYBvf4F.js → dist-BjI0b36Z.js} +2 -2
- package/dist/assets/assets/{dist-DUS0U_ge.js → dist-CM7b5P9a.js} +2 -2
- package/dist/assets/assets/{dist-CeOy6PjJ.js → dist-Ccxb9U1G.js} +2 -2
- package/dist/assets/assets/{dist-ChXoRSS6.js → dist-CjCWP21A.js} +2 -2
- package/dist/assets/assets/{dist-07dRlnp1.js → dist-DSTAktnR.js} +2 -2
- package/dist/assets/assets/{ebnfDiagram-V4P3TTPT-4nZgqaSt.js → ebnfDiagram-V4P3TTPT-BivOMXZb.js} +2 -2
- package/dist/assets/assets/{elk-QONTBCTQ-nFh54c1Q.js → elk-QONTBCTQ-CrJ1Qpy_.js} +2 -2
- package/dist/assets/assets/{erDiagram-KYQIGQAA-CIQ0_IgZ.js → erDiagram-KYQIGQAA-w9Bqp4sV.js} +2 -2
- package/dist/assets/assets/{eventmodeling-K75KTNOO-Cw4BlbYP.js → eventmodeling-K75KTNOO-CBjFM3kV.js} +1 -1
- package/dist/assets/assets/flowDiagram-IUGLLWBU-C6Fnfgm0.js +1 -0
- package/dist/assets/assets/{ganttDiagram-R7GPNTJY-C97qoUpX.js → ganttDiagram-R7GPNTJY-CsWtGaqD.js} +2 -2
- package/dist/assets/assets/{gitGraph-VSP46ZUC-B8HWVkEX.js → gitGraph-VSP46ZUC-DsBSV9_h.js} +1 -1
- package/dist/assets/assets/{gitGraphDiagram-PDYL7XHY-B4Js56_8.js → gitGraphDiagram-PDYL7XHY-D5GxuYHW.js} +2 -2
- package/dist/assets/assets/index-CNDyKUDF.css +1 -0
- package/dist/assets/assets/index-DWDYnZsq.js +256 -0
- package/dist/assets/assets/{info-OHQRW6UA-A4qythhA.js → info-OHQRW6UA-C7x5dSJu.js} +1 -1
- package/dist/assets/assets/{infoDiagram-MVDRKAX5-BSNwG9yI.js → infoDiagram-MVDRKAX5-CwpI-uAa.js} +2 -2
- package/dist/assets/assets/{ishikawaDiagram-HPEHV2GE-D4gU-3RA.js → ishikawaDiagram-HPEHV2GE-DAa7J5G6.js} +2 -2
- package/dist/assets/assets/{journeyDiagram-BOSHW7O7-CxxDrw7o.js → journeyDiagram-BOSHW7O7-BmiZnxE_.js} +2 -2
- package/dist/assets/assets/{kanban-definition-FNSA4HC5-DUxQv3v0.js → kanban-definition-FNSA4HC5-DUR_mA3L.js} +2 -2
- package/dist/assets/assets/{line-BKODXUmk.js → line-DHY49wSg.js} +2 -2
- package/dist/assets/assets/{linear-Cm5uyUun.js → linear-pTo-a9xT.js} +2 -2
- package/dist/assets/assets/{mermaid-parser.core-CYst2kCg.js → mermaid-parser.core-DMg3hN3T.js} +4 -4
- package/dist/assets/assets/{mermaid.core-B4Qq8SMa.js → mermaid.core-DKtPCltA.js} +5 -5
- package/dist/assets/assets/{mindmap-definition-6OY57UG3-CZFvUTIM.js → mindmap-definition-6OY57UG3-DwTkFbnV.js} +2 -2
- package/dist/assets/assets/{packet-JDAUHWVQ-DZMlaiuy.js → packet-JDAUHWVQ-Tu9TrQ1x.js} +1 -1
- package/dist/assets/assets/{pegDiagram-ECIUJNBX-BjM668dT.js → pegDiagram-ECIUJNBX-B7My4tsz.js} +2 -2
- package/dist/assets/assets/{pie-XZMESJXO-CmpJ6vb8.js → pie-XZMESJXO-QPQm5Gdx.js} +1 -1
- package/dist/assets/assets/{pieDiagram-GNMPY74T-BCA9DCDe.js → pieDiagram-GNMPY74T-Bv-zAD_z.js} +2 -2
- package/dist/assets/assets/{quadrantDiagram-D57K4MC3-CUnpC-Rl.js → quadrantDiagram-D57K4MC3-HTjoGQPd.js} +2 -2
- package/dist/assets/assets/{radar-ABXABTNO-C9x42-KP.js → radar-ABXABTNO-LDBlEoFo.js} +1 -1
- package/dist/assets/assets/{railroad-I3PHUGI6-CLvHKrsC.js → railroad-I3PHUGI6-Dy3_ymgZ.js} +1 -1
- package/dist/assets/assets/{railroad-abnf-LNEFI6M7-B0LGF3gx.js → railroad-abnf-LNEFI6M7-QLVvYs6e.js} +1 -1
- package/dist/assets/assets/{railroad-ebnf-DWYD2UWJ-SKnYapAj.js → railroad-ebnf-DWYD2UWJ-CFRlv9a8.js} +1 -1
- package/dist/assets/assets/{railroad-peg-JR7BVNR7-wsUpPloN.js → railroad-peg-JR7BVNR7-BOlq3d9c.js} +1 -1
- package/dist/assets/assets/{railroadDiagram-Y72NRBL7-BYJtosKO.js → railroadDiagram-Y72NRBL7-Chg32HoU.js} +2 -2
- package/dist/assets/assets/{requirementDiagram-EQYSW5RA-YYdoWMnl.js → requirementDiagram-EQYSW5RA-VenIs_eg.js} +2 -2
- package/dist/assets/assets/{sankeyDiagram-SY24JHO5-DtZyCTdM.js → sankeyDiagram-SY24JHO5-BdByqMKF.js} +2 -2
- package/dist/assets/assets/{sequenceDiagram-BLEHNHQU-BPE8f413.js → sequenceDiagram-BLEHNHQU-D3Do4GJE.js} +2 -2
- package/dist/assets/assets/{src-BNTOLq2G.js → src-DmfN-DA-.js} +2 -2
- package/dist/assets/assets/{stateDiagram-v2-A6IESKWZ-9f8Ow4Fl.js → stateDiagram-v2-A6IESKWZ-CZkRbPlf.js} +2 -2
- package/dist/assets/assets/{swimlanes-B3ENRKFQ-DdAEbxGp.js → swimlanes-B3ENRKFQ-DRTdF9AF.js} +2 -2
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-BYr_4JUb.js +9 -0
- package/dist/assets/assets/{timeline-definition-JXYKGLGB-DJNGd2mU.js → timeline-definition-JXYKGLGB-BVcuws_M.js} +2 -2
- package/dist/assets/assets/{treeView-D4JQ5SDB-BHONoCCw.js → treeView-D4JQ5SDB-BLtOJGqO.js} +1 -1
- package/dist/assets/assets/{treemap-SAJKECNS-pOaYkxq7.js → treemap-SAJKECNS-Dn3BWJ4v.js} +1 -1
- package/dist/assets/assets/{usecaseDiagram-WPOLBNNX-C3eDYL9v.js → usecaseDiagram-WPOLBNNX-CBExIKDY.js} +2 -2
- package/dist/assets/assets/{vennDiagram-Q3Y3IDCW-CJi1xfsR.js → vennDiagram-Q3Y3IDCW-C6FIx2L4.js} +2 -2
- package/dist/assets/assets/{wardley-7MLQ67FV-CEy4w7Ir.js → wardley-7MLQ67FV-Cjj2xSBp.js} +1 -1
- package/dist/assets/assets/{wardleyDiagram-IVAIDKWA-DfdLMMpN.js → wardleyDiagram-IVAIDKWA-sQPCBCFK.js} +2 -2
- package/dist/assets/assets/{webpack-v8XGbQTa.js → webpack-DDCA0aDL.js} +2 -2
- package/dist/assets/assets/{xychartDiagram-4URNHDU4-Aw-Ix4uC.js → xychartDiagram-4URNHDU4-bZ4rifSw.js} +2 -2
- package/dist/assets/bundle-asset-policy.json +1 -1
- package/dist/assets/index.html +8 -2
- package/dist/assets/mascot/cta-provider.png +0 -0
- package/dist/assets/mascot/cta-sign-in.png +0 -0
- package/dist/assets/plugins/assets/base-GzIOAd-t.css +2 -0
- package/dist/assets/plugins/assets/browserCaptureWorklet-Droj0fW0-Droj0fW0.js +13 -0
- package/dist/assets/plugins/assets/day-bottom-left-5um-x02r-5um-x02r.webp +0 -0
- package/dist/assets/plugins/assets/day-grain-CvEuNhlI-CvEuNhlI.webp +0 -0
- package/dist/assets/plugins/assets/day-right-C9W-XtjV-C9W-XtjV.webp +0 -0
- package/dist/assets/plugins/assets/day-top-left-B544Eq9J-B544Eq9J.webp +0 -0
- package/dist/assets/plugins/assets/night-bottom-left-N03ST5Uz-N03ST5Uz.webp +0 -0
- package/dist/assets/plugins/assets/night-grain-BY9q-tNN-BY9q-tNN.webp +0 -0
- package/dist/assets/plugins/assets/night-right-C6Denrqj-C6Denrqj.webp +0 -0
- package/dist/assets/plugins/assets/night-top-left-KOou6UxY-KOou6UxY.webp +0 -0
- package/dist/assets/plugins/assets/sileroVadWorker-D894njUe-DjN_BMWf.mjs +110 -0
- package/dist/assets/plugins/assets/silero_vad_v6.2.1-SjbCxFXk-SjbCxFXk.onnx +0 -0
- package/dist/assets/plugins/chunks/po-web-runtime-D8FIos2q.js +1 -0
- package/dist/assets/plugins/chunks/schemas-DVQ8BvvP.js +55 -0
- package/dist/assets/plugins/compositions.json +1 -1
- package/dist/assets/plugins/slots/approval.09e72f36-DxS_uibk.js +2 -0
- package/dist/assets/plugins/slots/artifacts.50b639bb-Cp37TAkd.js +1 -0
- package/dist/assets/plugins/slots/author.ea449ace-Ds9Y-tjN.js +93 -0
- package/dist/assets/plugins/slots/autocompact.6f428144-CDZpN7I7.js +1 -0
- package/dist/assets/plugins/slots/backdrop-bamboo.6e4c928d-qbifuMc6.js +1 -0
- package/dist/assets/plugins/slots/browse.fa1f1a50-CVYvo1M5.js +1 -0
- package/dist/assets/plugins/slots/builtin-tools.75108f21-Cq1ljoL-.js +7 -0
- package/dist/assets/plugins/slots/calendar.d8b70190-BBjpOs1v.js +2 -0
- package/dist/assets/plugins/slots/codemode.c58fb583-DOR6OR7R.js +11 -0
- package/dist/assets/plugins/slots/domain.753f9f92-CJrXxig9.js +1 -0
- package/dist/assets/plugins/slots/edit.804fec90-BFF7_xN9.js +7 -0
- package/dist/assets/plugins/slots/files.66ffc636-CzOlZrRm.js +2 -0
- package/dist/assets/plugins/slots/goal.45dffa01-BtQBp3sw.js +1 -0
- package/dist/assets/plugins/slots/grep.98262cff-9bUDfjyT.js +1 -0
- package/dist/assets/plugins/slots/help.5fbd20f7-B4-y6gYK.js +3 -0
- package/dist/assets/plugins/slots/log.cb964209-BRPa3cVs.js +4 -0
- package/dist/assets/plugins/slots/mcp.82cc1ff5-CFtzPkPC.js +55 -0
- package/dist/assets/plugins/slots/plan.3852ba52-CH59Ff49.js +3 -0
- package/dist/assets/plugins/slots/profile.ab16dcec-0e9fWWyE.js +1 -0
- package/dist/assets/plugins/slots/prompts.ae48c07a-BTqYnBX5.js +38 -0
- package/dist/assets/plugins/slots/read.4560591a-C7fMXDEH.js +1 -0
- package/dist/assets/plugins/slots/runner.6e494d59-CqrpqhW9.js +9 -0
- package/dist/assets/plugins/slots/scaffold.d87a6ee0-9qY5gkYW.js +1 -0
- package/dist/assets/plugins/slots/session-mcp.2be84084-Cf0cqopp.js +2 -0
- package/dist/assets/plugins/slots/sessions.6f47cb4c-B1_eqPJQ.js +1 -0
- package/dist/assets/plugins/slots/skill.62a0a1b3-D-SKX8iw.js +4 -0
- package/dist/assets/plugins/slots/space.65a27e5a-fbLHc-DX.js +1 -0
- package/dist/assets/plugins/slots/subagents.8bb9992c-Cm_YMEnn.js +7 -0
- package/dist/assets/plugins/slots/template-advanced.59f3f98a-L0WOM4JT.js +1 -0
- package/dist/assets/plugins/slots/template-desktop.0f0b8491-By9BZlaL.js +7 -0
- package/dist/assets/plugins/slots/template-elegant.0e3b0acf-El05x7HK.js +1 -0
- package/dist/assets/plugins/slots/vault.3cbfcdc3-DpU_65Wy.js +1 -0
- package/dist/assets/plugins/slots/voice.a952113d-CvcuL__m.js +1 -0
- package/dist/assets/plugins/slots/web-search.65013836-NVh9fdvE.js +1 -0
- package/dist/assets/plugins/slots/workflows.cbc5c5c0-OLKSY9PE.js +16 -0
- package/dist/assets/pwa/pwa.js +12 -12
- package/dist/assets/pwa/sw.js +58 -4
- package/dist/{atomicJson-wczZBXQP.js → atomicJson-XYtxz032.js} +2 -3
- package/dist/{azure-openai-config-DHMgdIa-.js → azure-openai-config-S-quxzTC.js} +2 -2
- package/dist/{azure-openai-responses-CTgRdQ4m.js → azure-openai-responses-DdpV5zh7.js} +13 -13
- package/dist/backgroundWork-Bv0ib_lY.js +49 -0
- package/dist/{layeredConfig-xmTHGrw8.js → browser-DwY5dXHX.js} +21 -983
- package/dist/{browser-EJ5_ffnN.js → browser-IsHIcvFg.js} +1 -1
- package/dist/browser-ks_k-6KA.js +36 -0
- package/dist/calendarSetup-CI3AACVo.js +3892 -0
- package/dist/childProcess-Cv8rJuUf.js +32 -0
- package/dist/childSession-BrDCrNtL.js +25 -0
- package/dist/{classifier-shared-jXm-plIK.js → classifier-shared-DFprgrML.js} +5 -5
- package/dist/{cloudflare-workers-ai-system-one-B0wH6HU5.js → cloudflare-workers-ai-system-one-B0MD19yZ.js} +3 -3
- package/dist/{codemode-CFVDmyGm.js → codemode-LpcMFMYM.js} +1 -1
- package/dist/coerce-DM9YrILC.js +13 -0
- package/dist/config-DeWkdjj7.js +1372 -0
- package/dist/contextContributions-C1bsEJef.js +13 -0
- package/dist/contracts-CW8o6Xyi.js +19 -0
- package/dist/contracts-WRa9e98H.js +40 -0
- package/dist/cordisHost-_-jtkneB.js +25 -0
- package/dist/delegation-B2rBgv8A.js +100 -0
- package/dist/{diagnostics-DPTP-yrt.js → diagnostics-BY5LXbHJ.js} +2 -2
- package/dist/{dist-BVBi6VMV.js → dist-B2ArMqge.js} +1 -1
- package/dist/{server-Cg07O2W6.js → dist-C6IqjC-m.js} +1 -546
- package/dist/{dist-PDDFdqDX.js → dist-CDz5dYMj.js} +1 -1
- package/dist/{dist-Dvx5mlIR.js → dist-kgi2Ix1y.js} +16 -3
- package/dist/{emscripten-module.cloudflare-D4Bc9Ykz.js → emscripten-module.cloudflare-B4fhfquU.js} +1 -1
- package/dist/{env-api-keys-CAnjjnsR.js → env-api-keys-BgCPpU9t.js} +1 -1
- package/dist/{error-body-DQZRsyL5.js → error-body-CeumezyR.js} +26 -4
- package/dist/esm-BKJy3O9-.js +1553 -0
- package/dist/{remoteMcp-DqE2xFWS.js → exports-BEEgtkya.js} +1588 -714
- package/dist/{exports-LjvSY7Y6.js → exports-CBp_9dVk.js} +47 -28
- package/dist/exports-CRjRvvX0.js +34 -0
- package/dist/exports-Cg0wxflf.js +1 -0
- package/dist/exports-Ct56PRB9.js +46 -0
- package/dist/extensionFile-B940JOEn.js +121 -0
- package/dist/{factory-Cs8iaUtc.js → factory-BU0cZY0I.js} +1 -1
- package/dist/{github-copilot-headers-DpQQAh-s.js → github-copilot-headers-Cq9pnpl2.js} +1 -1
- package/dist/{google-generative-ai-BTTOo5RQ.js → google-generative-ai-DmbUlCGv.js} +9 -9
- package/dist/{google-shared-S7bqOccz.js → google-shared-Diz2uk39.js} +6 -6
- package/dist/{google-vertex-BcMU_DMb.js → google-vertex-CGCpI9Po.js} +10 -10
- package/dist/{domains-B6Ae4swm.js → harnessState-Df--jB5z.js} +162 -42
- package/dist/{harnessStore-Ccbia9_u.js → harnessStore-DInwiLYb.js} +4 -5
- package/dist/{hash-B3RRpLS2.js → hash-IQBoLxOB.js} +1 -1
- package/dist/{headers-BEuxFxDI.js → headers-Dkgiqogr.js} +1 -1
- package/dist/help-C9UGKetC.js +100 -0
- package/dist/home-kwZFHqOx.js +60 -0
- package/dist/http-BekstF5S.js +64 -0
- package/dist/hubChannel-Dldv3EEb.js +32 -0
- package/dist/hubRevisions-BPoC6quI.js +364 -0
- package/dist/{identity-BIeAyilV.js → identity-BzB1N-Sn.js} +3 -3
- package/dist/index.edge-BiVQ9LoZ.js +198 -0
- package/dist/index.edge-CSGx6QOL.js +56 -0
- package/dist/index.edge-ClLTmPFz.js +191 -0
- package/dist/index.edge-CzoLWbyl.js +238 -0
- package/dist/index.edge-D1biKw71.js +946 -0
- package/dist/index.edge-D2RirEwK.js +14 -0
- package/dist/iso-BGFmgtky.js +27 -0
- package/dist/{kysely-adapter-D51abb3q.js → kysely-adapter-D8KUrWxm.js} +1 -1
- package/dist/liquid.browser-1BcykmIN.js +4596 -0
- package/dist/manualTranscription-DN56fzgj.js +96 -0
- package/dist/{mcpProjection-BXiECnW0.js → mcpProjection-D2U50Pel.js} +1 -2
- package/dist/meta-CVgfTHQP.js +1030 -0
- package/dist/migrations-DJBPDwSR.js +32 -0
- package/dist/{mistral-conversations-DN8VSERk.js → mistral-conversations-Bv_m1MRF.js} +12 -12
- package/dist/modeDefinition-Di95_IiU.js +44 -0
- package/dist/{models-D6d73jcW.js → models-D50yN8Ag.js} +41 -46
- package/dist/{node-UuMT2C3q.js → node-B4kSjHeD.js} +2 -2
- package/dist/{node-DytJOfYf.js → node-CBLSc-YH.js} +1 -1
- package/dist/notification-DjxbNoMR.js +143 -0
- package/dist/{openai-bt3ZRBZv.js → openai-D6Q-l6hT.js} +187 -187
- package/dist/{openai-codex-responses-cL36x0ml.js → openai-codex-responses-BnoiTqYV.js} +21 -25
- package/dist/{openai-completions-BWsTNYyT.js → openai-completions-C68qs5rI.js} +26 -19
- package/dist/{openai-decisions-Dfn_KgQd.js → openai-decisions-BSxU_aoV.js} +3 -3
- package/dist/{openai-responses-aa0LoyCJ.js → openai-responses-D6hXen-k.js} +17 -15
- package/dist/{openai-responses-shared-H-jH5SlM.js → openai-responses-shared-BD8K7FAC.js} +7 -7
- package/dist/{openrouter-cost-D99Qqcs6.js → openrouter-cost-BPam8wyW.js} +1 -1
- package/dist/{openrouter-images-BpwVpALC.js → openrouter-images-DylXiHy7.js} +7 -7
- package/dist/{hubChannel-Dn5NMpvu.js → packageApi-DYkaxP59.js} +33 -42
- package/dist/photon_rs_bg.wasm +0 -0
- package/dist/{pi-messages-BHAIkYBj.js → pi-messages-DaIlYYlO.js} +6 -6
- package/dist/piConfig-5tRPD0ov.js +126 -0
- package/dist/piSettings-ekBG5OeF.js +1 -0
- package/dist/platform-CQahdzpG.js +138 -0
- package/dist/pluginCatalog-BAALyedS.js +30 -0
- package/dist/pluginContributions-Be9EnCAW.js +16 -0
- package/dist/pluginProtocol-7_gVUeM9.js +1 -0
- package/dist/pluginProtocol-DVIfJnav.js +135 -0
- package/dist/portableConfig-0tnk9anb.js +49 -0
- package/dist/presetConfig-n-oiNd3h.js +541 -0
- package/dist/profileSources-D1rymC97.js +537 -0
- package/dist/{protocol-DUeE0Q8z.js → protocol-Cri0GpZR.js} +1 -2
- package/dist/{provider-env-DgfpjgTa.js → provider-env-DJb40UF7.js} +2 -2
- package/dist/{provider-retry-ChD-K2Gv.js → provider-retry-jpvs7ixx.js} +1 -1
- package/dist/{puppeteer-cloudflare-B-GHrPGO.js → puppeteer-cloudflare-D4l8smMS.js} +3 -3
- package/dist/{server-BWJmxCrm.js → readiness-Ydw5zrKy.js} +4 -169
- package/dist/{rolldown-runtime-B-lAHAz2.js → rolldown-runtime-DbVrKiKs.js} +1 -1
- package/dist/{sanitize-unicode-Dl4ROF7y.js → sanitize-unicode-B1ZFaEtf.js} +1 -1
- package/dist/scaffoldRegistry-CeFe3Pf0.js +1240 -0
- package/dist/{schemas-Vj8-rCR4.js → schemas-D2dRon18.js} +1901 -53
- package/dist/server-AKM07WcM.js +466 -0
- package/dist/server-B0tM5Ygf.js +1300 -0
- package/dist/server-B8-vStCx.js +1116 -0
- package/dist/server-BAbdiL38.js +15108 -0
- package/dist/server-BCZ_R3kX.js +3326 -0
- package/dist/server-BGKAeB3M.js +492 -0
- package/dist/server-BIQhg1jS.js +26985 -0
- package/dist/server-BcPD_6a2.js +1533 -0
- package/dist/server-BeoA0QB-.js +580 -0
- package/dist/server-BsgvOpBF.js +24 -0
- package/dist/server-BtnOqSB5.js +156 -0
- package/dist/server-C-HBjWRo.js +2800 -0
- package/dist/{server-CWg0m_wq.js → server-C0Lt6nTt.js} +269 -1062
- package/dist/server-C8NPfG1H.js +148 -0
- package/dist/server-CKkaxOc0.js +978 -0
- package/dist/server-CMaWF5UA.js +1379 -0
- package/dist/server-CQPI6jIa.js +295 -0
- package/dist/{server-BhYE7Vqk.js → server-CQmb0lYL.js} +114 -176
- package/dist/server-CWR34Vx6.js +1884 -0
- package/dist/server-CZiAy2v5.js +641 -0
- package/dist/server-Cjtr0oVJ.js +584 -0
- package/dist/server-CkJQJ3Oo.js +571 -0
- package/dist/server-ClQQGtsI.js +679 -0
- package/dist/server-Cy2FhGBm.js +1744 -0
- package/dist/server-D8yEblCB.js +24 -0
- package/dist/server-DF0YIUeI.js +9603 -0
- package/dist/server-DRFESCq1.js +1527 -0
- package/dist/{server-zkcrP99W.js → server-Df1defzp.js} +89 -87
- package/dist/server-DgZd_TuT.js +189 -0
- package/dist/server-Dkc9Kth2.js +1830 -0
- package/dist/server-DlRePYOB.js +343 -0
- package/dist/{server-BpPEzRes.js → server-_HZm8wEC.js} +654 -745
- package/dist/{server-yABhJa2K.js → server-_jWkMESg.js} +60 -39
- package/dist/server-lgV6liTt.js +140 -0
- package/dist/server-nHPXbRDA.js +742 -0
- package/dist/server-p7qANgrf.js +877 -0
- package/dist/server-vhmQi3co.js +112 -0
- package/dist/{server-SA0dsIJ2.js → server-w1aKMZOs.js} +3 -10
- package/dist/serverPlugin-4nI5J6Zt.js +39622 -0
- package/dist/session-resources-BvR3cwiH.js +10 -0
- package/dist/{sessionConfig-DgnPcGBu.js → sessionConfig-UMlgu98q.js} +926 -844
- package/dist/{simple-options-DWrW31_K.js → simple-options-Cp5p46f9.js} +13 -6
- package/dist/space-C3Wnli1l.js +92 -0
- package/dist/sse-XlzXs1es.js +151 -0
- package/dist/{streaming-json-t4rzNHEp.js → streaming-json-CZyrX_Ux.js} +6 -6
- package/dist/{system-one-shared-DLVLdzYL.js → system-one-shared-Du6bka0h.js} +3 -3
- package/dist/{notification-valMY1zH.js → telemetry-CrTcxeA5.js} +2 -93
- package/dist/{transform-messages-CjTSwW9q.js → transform-messages-CBj9g2mx.js} +3 -16
- package/dist/truncate-M3KbFyVj.js +89 -0
- package/dist/{server-BXjfQYeU.js → type-DppaYz6F.js} +955 -1187
- package/dist/type-yokaDI_F.js +7 -0
- package/dist/{typesafe-system-one-DBVcjcUQ.js → typesafe-system-one-C7YFgvrX.js} +3 -3
- package/dist/{uuid-mkNGilLv.js → uuid-BVI0BZsx.js} +1 -1
- package/dist/{validation-BLnxgJU_.js → validation-QWuk6kwJ.js} +79 -74
- package/dist/vaultSettings-Bq8wkbDv.js +292 -0
- package/dist/voiceTools-BdJyfzwB.js +246 -0
- package/dist/web-B2sdV-F2.js +4 -0
- package/dist/worker.js +97821 -72579
- package/dist/workflow-DTCt4n6k.js +171 -0
- package/dist/workflowServices-RlswfHWp.js +300 -0
- package/package.json +55 -25
- package/wrangler.jsonc +16 -3
- package/dist/apiContracts-sG5b90Qa.js +0 -4451
- package/dist/assets/assets/channel-BOT7In0s.js +0 -2
- package/dist/assets/assets/chunk-XXDRQBXY-Dp9-QbR6.js +0 -2
- package/dist/assets/assets/flowDiagram-IUGLLWBU-B9D9uWwn.js +0 -1
- package/dist/assets/assets/index-BlPEYpuN.css +0 -1
- package/dist/assets/assets/index-DS9w_Q1B.js +0 -155
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-CyUKtW7v.js +0 -9
- package/dist/assets/plugins/assets/base-DyDpY0zD.css +0 -2
- package/dist/assets/plugins/chunks/po-web-runtime-4JiBsb_c.js +0 -1
- package/dist/assets/plugins/slots/approval.09e72f36-DwFz-UMh.js +0 -2
- package/dist/assets/plugins/slots/artifacts.50b639bb-CUtFC806.js +0 -1
- package/dist/assets/plugins/slots/builtin-tools.75108f21-B69GLfY_.js +0 -7
- package/dist/assets/plugins/slots/codemode.c58fb583-C0Gmb7_s.js +0 -9
- package/dist/assets/plugins/slots/domain.753f9f92-BTBYRLkE.js +0 -1
- package/dist/assets/plugins/slots/mcp.82cc1ff5-Ecacjn0a.js +0 -109
- package/dist/assets/plugins/slots/profile.ab16dcec-DIVXNHmh.js +0 -1
- package/dist/assets/plugins/slots/skill.62a0a1b3-BNr7DmPH.js +0 -4
- package/dist/backgroundWork-CSpsJ-Rg.js +0 -25
- package/dist/contextProjection-DDIQRgN4.js +0 -188
- package/dist/extensionFile-CacKVegY.js +0 -409
- package/dist/harnessState-gmzJcPGt.js +0 -88
- package/dist/harnessStore-Ch6hdYYe.js +0 -1
- package/dist/index.edge-BgSx_gRO.js +0 -45
- package/dist/majorModes-CCnwAjfF.js +0 -333
- package/dist/majorModes-DNQbxkpt.js +0 -1
- package/dist/piSettings-B6fsgIBA.js +0 -1
- package/dist/platform-Bs2_X_dK.js +0 -16
- package/dist/platformFiles-CCGujP9o.js +0 -39
- package/dist/server-5hLs7M43.js +0 -656
- package/dist/server-B3iqBHOP.js +0 -118
- package/dist/server-Dv0EKLwc.js +0 -108
- package/dist/server-Y5A21sJf.js +0 -591
- package/dist/server-a1K226XK.js +0 -279
- package/dist/serverPlugin-DUc4gGep.js +0 -7279
- package/dist/value-Bd477RDX.js +0 -2247
|
@@ -0,0 +1,1744 @@
|
|
|
1
|
+
import { Dt as defineServerMethod, Et as composeServerProviderOverrides, Jt as String$1, Nt as PO_SQLITE_SERVICE, Vt as requirePoSqlite, _t as BACKGROUND_CONTEXT, c as poHomeDirectory, jt as PO_FS_SERVICE, ln as requirePoServerScope, on as PO_SERVER_SCOPE_SERVICE, rn as _Object_, sn as defineServiceContract, t as defineServerPlugin, ut as isPoHeadlessPromptAdmissionError, zt as requirePoFs } from "./serverPlugin-4nI5J6Zt.js";
|
|
2
|
+
import { u as poApiCallerFrom } from "./packageApi-DYkaxP59.js";
|
|
3
|
+
import "./platform-CQahdzpG.js";
|
|
4
|
+
import { n as readPackageResource, t as packageResourcePath } from "./index.edge-BiVQ9LoZ.js";
|
|
5
|
+
import { n as APPROVAL_ROOT_SERVICE } from "./approvalSession-C9bg7tPo.js";
|
|
6
|
+
import "./piSettings-ekBG5OeF.js";
|
|
7
|
+
import { i as definePoPluginMethod } from "./pluginProtocol-DVIfJnav.js";
|
|
8
|
+
import { c as defineRoot, l as defineRoute, n as composeRootInjects, s as defineResource, t as composeRootHooks, u as defineRoutedContribution } from "./extensionFile-B940JOEn.js";
|
|
9
|
+
import { i as PO_SESSION_ATTENTION_EVENT, s as WORKFLOW_STEP_SESSION_PROVENANCE, t as PO_AGENT_RUN_CONTRACT } from "./hubChannel-Dldv3EEb.js";
|
|
10
|
+
import "./pluginProtocol-7_gVUeM9.js";
|
|
11
|
+
import { l as readPoBackgroundWorkService, s as holdsSettledSession } from "./backgroundWork-Bv0ib_lY.js";
|
|
12
|
+
import { i as readPoCodemode, n as PO_CODEMODE_SERVICE, r as assertCodemodeNamespaceName } from "./codemode-LpcMFMYM.js";
|
|
13
|
+
import { n as readPoContextContributions } from "./contextContributions-C1bsEJef.js";
|
|
14
|
+
import { A as createSealedPeerChannels, B as STOP_REPORT_DELAY_MS, C as parseRemoteSessionReference, D as readSessionPeerConfigAsync, E as peerSessionReference, F as SESSION_DIGEST_KIND, G as parseLogInput, H as createLogbookWake, I as readPoSessionDelivery, J as createSessionsNamespace, K as parseLogbookQuery, L as INBOX_DIGEST_DELAY_MS, M as sessionPeerConfigPath, O as verifyPeerRequest, P as PO_SESSION_DELIVERY_SERVICE, Q as createStartSessionTool, R as LOGBOOK_WAKE_DELAY_MS, S as ensurePrivateDirectory, T as peerRequestHeaders, U as createStopReport, V as createInboxDigest, W as lastAssistantText, X as fields, Y as detach, Z as START_SESSION_TOOL_NAME, _ as createSessionGroupBridge, a as createSessionPeers, b as createPeerCommunication, c as INTERCOM_MESSAGE_TYPE, d as intercomDetails, et as provideBackgroundWorkService, f as rearmAskReminders, g as PO_SESSION_GROUP_BRIDGE_SERVICE, h as PO_SESSION_GROUP_BRIDGE_CONTRACT, i as PO_SESSION_PEERS_SERVICE, j as PEER_REPLAY_DATABASE_FILE, k as authenticatedPeerPost, m as undeliveredNotice, n as createPeerLink, o as requireSessionPeers, q as parseMarkReadInput, r as PO_SESSION_PEERS_CONTRACT, s as createSessionDirectory, t as PO_ROSTER_PEER_SERVICE, u as createNodeSessionOperations, v as namedSessionGroupId, w as parseSessionPeerEnvelope, x as createPeerReplayGuardAsync, y as readSessionGroupBridge, z as STOP_LEVEL } from "./type-DppaYz6F.js";
|
|
15
|
+
import { n as readSessionOperations } from "./type-yokaDI_F.js";
|
|
16
|
+
import "./worker.js";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import { clearInterval as clearInterval$1, clearTimeout as clearTimeout$1, setInterval as setInterval$1, setTimeout as setTimeout$1 } from "node:timers";
|
|
19
|
+
//#region ../../foundations/po-session/src/services/sessionDelivery/index.ts
|
|
20
|
+
const DELIVERY_EVENT = "po/session-delivery/envelope";
|
|
21
|
+
const ACK_EVENT = "po/session-delivery/ack";
|
|
22
|
+
const DEFAULT_DELIVERY = "prompt";
|
|
23
|
+
const DEFAULT_ADMISSION_RETRY = {
|
|
24
|
+
everyMs: 5e3,
|
|
25
|
+
forMs: 12e4
|
|
26
|
+
};
|
|
27
|
+
const INBOX_STATES = /* @__PURE__ */ new Set([
|
|
28
|
+
"accepted",
|
|
29
|
+
"admitting",
|
|
30
|
+
"admitted",
|
|
31
|
+
"recovery_required",
|
|
32
|
+
"revoked"
|
|
33
|
+
]);
|
|
34
|
+
function isRecord(value) {
|
|
35
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36
|
+
}
|
|
37
|
+
function isMode(value) {
|
|
38
|
+
return value === "prompt" || value === "steer" || value === "followUp";
|
|
39
|
+
}
|
|
40
|
+
function metadataOf(value) {
|
|
41
|
+
if (!isRecord(value)) return void 0;
|
|
42
|
+
const metadata = {};
|
|
43
|
+
for (const [key, item] of Object.entries(value)) {
|
|
44
|
+
if (typeof item !== "string") return void 0;
|
|
45
|
+
metadata[key] = item;
|
|
46
|
+
}
|
|
47
|
+
return metadata;
|
|
48
|
+
}
|
|
49
|
+
function envelopeOf(value) {
|
|
50
|
+
if (!isRecord(value)) return void 0;
|
|
51
|
+
const metadata = metadataOf(value.metadata);
|
|
52
|
+
if (typeof value.deliveryId !== "string" || !value.deliveryId || typeof value.kind !== "string" || !value.kind || typeof value.prompt !== "string" || !isMode(value.delivery) || metadata === void 0) return;
|
|
53
|
+
return {
|
|
54
|
+
deliveryId: value.deliveryId,
|
|
55
|
+
kind: value.kind,
|
|
56
|
+
prompt: value.prompt,
|
|
57
|
+
delivery: value.delivery,
|
|
58
|
+
metadata
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function ackOf(value) {
|
|
62
|
+
if (!isRecord(value)) return void 0;
|
|
63
|
+
if (typeof value.deliveryId !== "string" || typeof value.state !== "string" || !INBOX_STATES.has(value.state)) return;
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
function normalizedMetadata(metadata) {
|
|
67
|
+
const normalized = {};
|
|
68
|
+
for (const [key, value] of Object.entries(metadata ?? {})) if (value !== void 0) normalized[key] = value;
|
|
69
|
+
return normalized;
|
|
70
|
+
}
|
|
71
|
+
function matchesMetadata(entry, query) {
|
|
72
|
+
return Object.entries(query ?? {}).every(([key, value]) => value === void 0 || entry[key] === value);
|
|
73
|
+
}
|
|
74
|
+
function sameMetadata(left, right) {
|
|
75
|
+
return matchesMetadata(left, right) && matchesMetadata(right, left);
|
|
76
|
+
}
|
|
77
|
+
function inboxEntryOf(row) {
|
|
78
|
+
return {
|
|
79
|
+
deliveryId: row.delivery_id,
|
|
80
|
+
senderKey: row.sender_key,
|
|
81
|
+
recipientKey: row.recipient_key,
|
|
82
|
+
kind: row.kind,
|
|
83
|
+
prompt: row.prompt,
|
|
84
|
+
delivery: row.delivery_mode,
|
|
85
|
+
metadata: JSON.parse(row.metadata_json),
|
|
86
|
+
state: row.state,
|
|
87
|
+
consumed: row.consumed_at !== null
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function outboxEntryOf(row) {
|
|
91
|
+
return {
|
|
92
|
+
deliveryId: row.delivery_id,
|
|
93
|
+
recipientKey: row.recipient_key,
|
|
94
|
+
kind: row.kind,
|
|
95
|
+
metadata: JSON.parse(row.metadata_json),
|
|
96
|
+
state: row.state,
|
|
97
|
+
...row.recipient_state === null ? {} : { recipientState: row.recipient_state }
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const SCHEMA$1 = `
|
|
101
|
+
CREATE TABLE IF NOT EXISTS session_delivery_outbox (
|
|
102
|
+
delivery_id TEXT PRIMARY KEY,
|
|
103
|
+
recipient_key TEXT NOT NULL,
|
|
104
|
+
kind TEXT NOT NULL,
|
|
105
|
+
prompt TEXT NOT NULL,
|
|
106
|
+
delivery_mode TEXT NOT NULL,
|
|
107
|
+
metadata_json TEXT NOT NULL,
|
|
108
|
+
state TEXT NOT NULL,
|
|
109
|
+
recipient_state TEXT,
|
|
110
|
+
created_at INTEGER NOT NULL,
|
|
111
|
+
acknowledged_at INTEGER
|
|
112
|
+
);
|
|
113
|
+
CREATE TABLE IF NOT EXISTS session_delivery_inbox (
|
|
114
|
+
delivery_id TEXT PRIMARY KEY,
|
|
115
|
+
sender_key TEXT NOT NULL,
|
|
116
|
+
recipient_key TEXT NOT NULL,
|
|
117
|
+
kind TEXT NOT NULL,
|
|
118
|
+
prompt TEXT NOT NULL,
|
|
119
|
+
delivery_mode TEXT NOT NULL,
|
|
120
|
+
metadata_json TEXT NOT NULL,
|
|
121
|
+
state TEXT NOT NULL,
|
|
122
|
+
created_at INTEGER NOT NULL,
|
|
123
|
+
updated_at INTEGER NOT NULL,
|
|
124
|
+
consumed_at INTEGER
|
|
125
|
+
);
|
|
126
|
+
`;
|
|
127
|
+
const SET_INBOX_STATE = "UPDATE session_delivery_inbox SET state = ?, updated_at = ? WHERE delivery_id = ?";
|
|
128
|
+
const UNSETTLED_OUTBOX = "state != 'revoked' AND (recipient_state IS NULL OR recipient_state NOT IN ('admitted', 'recovery_required', 'revoked'))";
|
|
129
|
+
/** Opens and starts one durable delivery endpoint. */
|
|
130
|
+
async function createSessionDeliveryService(options) {
|
|
131
|
+
if (!options.recipientKey.trim() || options.recipientKey !== options.recipientKey.trim()) throw new TypeError("Session delivery requires a trimmed, non-empty recipient key.");
|
|
132
|
+
const database = options.database;
|
|
133
|
+
try {
|
|
134
|
+
await database.exec(SCHEMA$1);
|
|
135
|
+
await database.run("UPDATE session_delivery_inbox SET state = 'accepted', updated_at = ? WHERE state = 'admitting'", Date.now());
|
|
136
|
+
} catch (error) {
|
|
137
|
+
await database.close();
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
let closed = false;
|
|
141
|
+
const scheduled = /* @__PURE__ */ new Set();
|
|
142
|
+
let admissionQueue = Promise.resolve();
|
|
143
|
+
const pending = /* @__PURE__ */ new Set();
|
|
144
|
+
/** Reports a failure the service absorbed. Shutdown noise after close() is not one. */
|
|
145
|
+
const report = (error) => {
|
|
146
|
+
if (!closed) options.onError(error);
|
|
147
|
+
};
|
|
148
|
+
/** Tracks fire-and-forget work so close() can wait for it before the database closes. */
|
|
149
|
+
const track = (work) => {
|
|
150
|
+
const settled = work.catch(report);
|
|
151
|
+
pending.add(settled);
|
|
152
|
+
settled.finally(() => pending.delete(settled));
|
|
153
|
+
};
|
|
154
|
+
const authorized = async (peerKey, metadata) => await options.authorizePeer(peerKey, metadata) === true;
|
|
155
|
+
const publishAck = (deliveryId, senderKey, state) => {
|
|
156
|
+
options.communication.publish(senderKey, ACK_EVENT, {
|
|
157
|
+
deliveryId,
|
|
158
|
+
state
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
const readInboxRow = (deliveryId) => database.get("SELECT * FROM session_delivery_inbox WHERE delivery_id = ?", deliveryId);
|
|
162
|
+
/** Tells the host a delivery was not read. The durable state is authoritative; an observer cannot change it. */
|
|
163
|
+
const undeliverable = (row, error) => {
|
|
164
|
+
try {
|
|
165
|
+
options.onUndeliverable?.(inboxEntryOf(row), error);
|
|
166
|
+
} catch (failure) {
|
|
167
|
+
report(failure);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
/** The first member from each sender of a digest, in the digest's order. */
|
|
171
|
+
const digestSenders = async (digest) => {
|
|
172
|
+
const { members } = JSON.parse(digest.metadata_json);
|
|
173
|
+
const seen = /* @__PURE__ */ new Set();
|
|
174
|
+
const first = [];
|
|
175
|
+
for (const id of JSON.parse(members ?? "[]")) {
|
|
176
|
+
const member = await readInboxRow(id);
|
|
177
|
+
if (!member || seen.has(member.sender_key)) continue;
|
|
178
|
+
seen.add(member.sender_key);
|
|
179
|
+
first.push(member);
|
|
180
|
+
}
|
|
181
|
+
return first;
|
|
182
|
+
};
|
|
183
|
+
const retry = options.admissionRetry ?? DEFAULT_ADMISSION_RETRY;
|
|
184
|
+
/** When each refused admission stops being retried. In memory, so a restart grants a fresh window. */
|
|
185
|
+
const retryUntil = /* @__PURE__ */ new Map();
|
|
186
|
+
const retryTimers = /* @__PURE__ */ new Set();
|
|
187
|
+
const scheduleAdmission = (deliveryId, from = "accepted") => {
|
|
188
|
+
if (closed || scheduled.has(deliveryId)) return;
|
|
189
|
+
scheduled.add(deliveryId);
|
|
190
|
+
admissionQueue = admissionQueue.then(async () => {
|
|
191
|
+
try {
|
|
192
|
+
if (closed) return;
|
|
193
|
+
const row = await database.get("UPDATE session_delivery_inbox SET state = 'admitting', updated_at = ? WHERE delivery_id = ? AND state = ? RETURNING *", Date.now(), deliveryId, from);
|
|
194
|
+
if (!row) return;
|
|
195
|
+
const digest = row.kind === SESSION_DIGEST_KIND;
|
|
196
|
+
if (from === "accepted" && !digest) publishAck(deliveryId, row.sender_key, "admitting");
|
|
197
|
+
try {
|
|
198
|
+
if (!digest && !await authorized(row.sender_key, JSON.parse(row.metadata_json))) {
|
|
199
|
+
retryUntil.delete(deliveryId);
|
|
200
|
+
await database.run(SET_INBOX_STATE, "revoked", Date.now(), deliveryId);
|
|
201
|
+
publishAck(deliveryId, row.sender_key, "revoked");
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
await options.admitPrompt(row.prompt, row.delivery_mode, deliveryId, JSON.parse(row.metadata_json));
|
|
205
|
+
} catch (error) {
|
|
206
|
+
const until = retryUntil.get(deliveryId) ?? Date.now() + retry.forMs;
|
|
207
|
+
if (isPoHeadlessPromptAdmissionError(error) && Date.now() < until) {
|
|
208
|
+
retryUntil.set(deliveryId, until);
|
|
209
|
+
const timer = setTimeout$1(() => {
|
|
210
|
+
retryTimers.delete(timer);
|
|
211
|
+
scheduleAdmission(deliveryId, "admitting");
|
|
212
|
+
}, retry.everyMs);
|
|
213
|
+
timer.unref?.();
|
|
214
|
+
retryTimers.add(timer);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
retryUntil.delete(deliveryId);
|
|
218
|
+
if (digest) {
|
|
219
|
+
await database.run(SET_INBOX_STATE, "accepted", Date.now(), deliveryId);
|
|
220
|
+
for (const member of await digestSenders(row)) undeliverable(member, error);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
await database.run(SET_INBOX_STATE, "recovery_required", Date.now(), deliveryId);
|
|
224
|
+
publishAck(deliveryId, row.sender_key, "recovery_required");
|
|
225
|
+
undeliverable({
|
|
226
|
+
...row,
|
|
227
|
+
state: "recovery_required"
|
|
228
|
+
}, error);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
retryUntil.delete(deliveryId);
|
|
232
|
+
await database.run(SET_INBOX_STATE, "admitted", Date.now(), deliveryId);
|
|
233
|
+
if (!digest) publishAck(deliveryId, row.sender_key, "admitted");
|
|
234
|
+
} finally {
|
|
235
|
+
scheduled.delete(deliveryId);
|
|
236
|
+
}
|
|
237
|
+
}).catch(async (error) => {
|
|
238
|
+
scheduled.delete(deliveryId);
|
|
239
|
+
report(error);
|
|
240
|
+
try {
|
|
241
|
+
const row = await readInboxRow(deliveryId);
|
|
242
|
+
if (row?.state !== "admitting") return;
|
|
243
|
+
if (row.kind === "session-digest") {
|
|
244
|
+
await database.run(SET_INBOX_STATE, "accepted", Date.now(), deliveryId);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
await database.run(SET_INBOX_STATE, "recovery_required", Date.now(), deliveryId);
|
|
248
|
+
try {
|
|
249
|
+
publishAck(deliveryId, row.sender_key, "recovery_required");
|
|
250
|
+
} catch (failure) {
|
|
251
|
+
report(failure);
|
|
252
|
+
}
|
|
253
|
+
} catch (failure) {
|
|
254
|
+
report(failure);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
const receiveEnvelope = async (senderKey, value) => {
|
|
259
|
+
if (closed) return void 0;
|
|
260
|
+
const envelope = envelopeOf(value);
|
|
261
|
+
if (!envelope || envelope.kind === "session-digest" || !await authorized(senderKey, envelope.metadata) || closed) return void 0;
|
|
262
|
+
await database.run(`INSERT OR IGNORE INTO session_delivery_inbox
|
|
263
|
+
(delivery_id, sender_key, recipient_key, kind, prompt, delivery_mode, metadata_json, state, created_at, updated_at)
|
|
264
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, 'accepted', ?, ?)`, envelope.deliveryId, senderKey, options.recipientKey, envelope.kind, envelope.prompt, envelope.delivery, JSON.stringify(envelope.metadata), Date.now(), Date.now());
|
|
265
|
+
const current = await readInboxRow(envelope.deliveryId);
|
|
266
|
+
if (!current) return void 0;
|
|
267
|
+
if (!(current.sender_key === senderKey && current.recipient_key === options.recipientKey && current.kind === envelope.kind && current.prompt === envelope.prompt && current.delivery_mode === envelope.delivery && sameMetadata(JSON.parse(current.metadata_json), envelope.metadata))) return void 0;
|
|
268
|
+
publishAck(envelope.deliveryId, current.sender_key, current.state);
|
|
269
|
+
if (current.state === "accepted") scheduleAdmission(envelope.deliveryId);
|
|
270
|
+
return current.state;
|
|
271
|
+
};
|
|
272
|
+
const receiveAck = async (recipientKey, value) => {
|
|
273
|
+
const ack = ackOf(value);
|
|
274
|
+
if (closed || !ack) return;
|
|
275
|
+
await database.run(`UPDATE session_delivery_outbox
|
|
276
|
+
SET state = CASE WHEN ? = 'revoked' THEN 'revoked' ELSE 'acknowledged' END, recipient_state = ?, acknowledged_at = ?
|
|
277
|
+
WHERE delivery_id = ? AND recipient_key = ? AND state != 'revoked'
|
|
278
|
+
AND (recipient_state IS NULL
|
|
279
|
+
OR (recipient_state = 'accepted' AND ? != 'accepted')
|
|
280
|
+
OR (recipient_state = 'admitting' AND ? IN ('admitted', 'recovery_required', 'revoked')))`, ack.state, ack.state, Date.now(), ack.deliveryId, recipientKey, ack.state, ack.state);
|
|
281
|
+
};
|
|
282
|
+
const publishOutbox = async (deliveryId) => {
|
|
283
|
+
if (closed) return;
|
|
284
|
+
const row = await database.get(`SELECT * FROM session_delivery_outbox WHERE delivery_id = ? AND ${UNSETTLED_OUTBOX}`, deliveryId);
|
|
285
|
+
if (!row) return;
|
|
286
|
+
const metadata = JSON.parse(row.metadata_json);
|
|
287
|
+
if (!await authorized(row.recipient_key, metadata)) {
|
|
288
|
+
await database.run("UPDATE session_delivery_outbox SET state = 'revoked', recipient_state = 'revoked' WHERE delivery_id = ? AND " + UNSETTLED_OUTBOX, deliveryId);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (closed) return;
|
|
292
|
+
options.communication.publish(row.recipient_key, DELIVERY_EVENT, {
|
|
293
|
+
deliveryId: row.delivery_id,
|
|
294
|
+
kind: row.kind,
|
|
295
|
+
prompt: row.prompt,
|
|
296
|
+
delivery: row.delivery_mode,
|
|
297
|
+
metadata
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
const publishQueued = async (recipientKey) => {
|
|
301
|
+
if (closed) return;
|
|
302
|
+
for (const row of await database.all(`SELECT delivery_id FROM session_delivery_outbox WHERE recipient_key = ? AND ${UNSETTLED_OUTBOX}`, recipientKey)) await publishOutbox(row.delivery_id);
|
|
303
|
+
};
|
|
304
|
+
let retryTimer;
|
|
305
|
+
const startRetry = () => {
|
|
306
|
+
if (closed || retryTimer) return;
|
|
307
|
+
retryTimer = setInterval$1(() => track(publishAllQueued()), 1e3);
|
|
308
|
+
retryTimer.unref?.();
|
|
309
|
+
};
|
|
310
|
+
const stopRetry = () => {
|
|
311
|
+
if (retryTimer) clearInterval$1(retryTimer);
|
|
312
|
+
retryTimer = void 0;
|
|
313
|
+
};
|
|
314
|
+
let retrying;
|
|
315
|
+
const publishAllQueued = () => {
|
|
316
|
+
retrying ??= (async () => {
|
|
317
|
+
try {
|
|
318
|
+
if (closed) return;
|
|
319
|
+
const rows = await database.all(`SELECT delivery_id FROM session_delivery_outbox WHERE ${UNSETTLED_OUTBOX}`);
|
|
320
|
+
if (rows.length === 0) stopRetry();
|
|
321
|
+
else startRetry();
|
|
322
|
+
for (const row of rows) await publishOutbox(row.delivery_id);
|
|
323
|
+
} finally {
|
|
324
|
+
retrying = void 0;
|
|
325
|
+
}
|
|
326
|
+
})();
|
|
327
|
+
return retrying;
|
|
328
|
+
};
|
|
329
|
+
const releaseEnvelope = options.communication.subscribe(DELIVERY_EVENT, (senderKey, payload) => {
|
|
330
|
+
track(receiveEnvelope(senderKey, payload));
|
|
331
|
+
});
|
|
332
|
+
const releaseAck = options.communication.subscribe(ACK_EVENT, (recipientKey, payload) => {
|
|
333
|
+
track(receiveAck(recipientKey, payload));
|
|
334
|
+
});
|
|
335
|
+
const releaseReady = options.communication.onPeerReady((recipientKey) => {
|
|
336
|
+
track(publishQueued(recipientKey));
|
|
337
|
+
});
|
|
338
|
+
for (const row of await database.all("SELECT delivery_id, sender_key FROM session_delivery_inbox WHERE state = 'recovery_required'")) publishAck(row.delivery_id, row.sender_key, "recovery_required");
|
|
339
|
+
/** Schedules every stored delivery that still waits to be admitted. */
|
|
340
|
+
const admitAccepted = async () => {
|
|
341
|
+
if (closed) return;
|
|
342
|
+
for (const row of await database.all("SELECT delivery_id FROM session_delivery_inbox WHERE state = 'accepted'")) scheduleAdmission(row.delivery_id);
|
|
343
|
+
};
|
|
344
|
+
await admitAccepted();
|
|
345
|
+
track(publishAllQueued());
|
|
346
|
+
return Object.freeze({
|
|
347
|
+
recipientKey: options.recipientKey,
|
|
348
|
+
async deliver(request) {
|
|
349
|
+
if (closed) throw new Error("Session delivery service is closed.");
|
|
350
|
+
if (request.kind === "session-digest") throw new TypeError(`Delivery kind '${request.kind}' is reserved.`);
|
|
351
|
+
const deliveryId = request.deliveryId ?? crypto.randomUUID();
|
|
352
|
+
const mode = request.delivery ?? DEFAULT_DELIVERY;
|
|
353
|
+
if (!deliveryId.trim() || !request.recipientKey.trim() || !request.kind.trim() || !isMode(mode)) throw new TypeError("Delivery id, recipient key, kind, and mode must be valid.");
|
|
354
|
+
if (!await authorized(request.recipientKey, request.metadata)) throw new Error(`Session '${request.recipientKey}' is not an authorized communication peer.`);
|
|
355
|
+
if (closed) throw new Error("Session delivery service is closed.");
|
|
356
|
+
const metadata = normalizedMetadata(request.metadata);
|
|
357
|
+
await database.run(`INSERT OR IGNORE INTO session_delivery_outbox
|
|
358
|
+
(delivery_id, recipient_key, kind, prompt, delivery_mode, metadata_json, state, created_at)
|
|
359
|
+
VALUES (?, ?, ?, ?, ?, ?, 'queued', ?)`, deliveryId, request.recipientKey, request.kind, request.prompt, mode, JSON.stringify(metadata), Date.now());
|
|
360
|
+
const current = await database.get("SELECT * FROM session_delivery_outbox WHERE delivery_id = ?", deliveryId);
|
|
361
|
+
if (!current || current.recipient_key !== request.recipientKey || current.kind !== request.kind || current.prompt !== request.prompt || current.delivery_mode !== mode || !sameMetadata(JSON.parse(current.metadata_json), metadata)) throw new TypeError(`Delivery id '${deliveryId}' is already bound to another envelope.`);
|
|
362
|
+
startRetry();
|
|
363
|
+
await publishOutbox(deliveryId);
|
|
364
|
+
return { deliveryId };
|
|
365
|
+
},
|
|
366
|
+
async waitForAdmission(deliveryId, timeoutMs = 5e3) {
|
|
367
|
+
const deadline = Date.now() + Math.max(0, timeoutMs);
|
|
368
|
+
let state;
|
|
369
|
+
do {
|
|
370
|
+
state = (await database.get("SELECT recipient_state FROM session_delivery_outbox WHERE delivery_id = ?", deliveryId))?.recipient_state ?? void 0;
|
|
371
|
+
if (state === "admitted" || state === "recovery_required" || state === "revoked") return state;
|
|
372
|
+
if (Date.now() >= deadline) return state;
|
|
373
|
+
await new Promise((resolve) => setTimeout$1(resolve, Math.min(10, deadline - Date.now())));
|
|
374
|
+
} while (!closed);
|
|
375
|
+
return state;
|
|
376
|
+
},
|
|
377
|
+
async receive(senderKey, kind, payload) {
|
|
378
|
+
if (kind === DELIVERY_EVENT) return receiveEnvelope(senderKey, payload);
|
|
379
|
+
if (kind === ACK_EVENT) {
|
|
380
|
+
await receiveAck(senderKey, payload);
|
|
381
|
+
return "accepted";
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
async inbox(query = {}) {
|
|
385
|
+
return (await database.all("SELECT * FROM session_delivery_inbox ORDER BY created_at, delivery_id")).map(inboxEntryOf).filter((entry) => (query.kind === void 0 || entry.kind === query.kind) && (query.state === void 0 || entry.state === query.state) && (query.consumed === void 0 || entry.consumed === query.consumed) && matchesMetadata(entry.metadata, query.metadata));
|
|
386
|
+
},
|
|
387
|
+
async consume(deliveryId) {
|
|
388
|
+
return await database.get("UPDATE session_delivery_inbox SET consumed_at = ? WHERE delivery_id = ? AND state IN ('admitted', 'recovery_required') AND consumed_at IS NULL RETURNING delivery_id", Date.now(), deliveryId) !== void 0;
|
|
389
|
+
},
|
|
390
|
+
async outbox(deliveryId) {
|
|
391
|
+
const row = await database.get("SELECT delivery_id, recipient_key, kind, metadata_json, state, recipient_state FROM session_delivery_outbox WHERE delivery_id = ?", deliveryId);
|
|
392
|
+
return row && outboxEntryOf(row);
|
|
393
|
+
},
|
|
394
|
+
async sent(query) {
|
|
395
|
+
return (await database.all(`SELECT delivery_id, recipient_key, kind, metadata_json, state, recipient_state, created_at
|
|
396
|
+
FROM session_delivery_outbox
|
|
397
|
+
WHERE created_at >= ?${query.recipientKey === void 0 ? "" : " AND recipient_key = ?"}
|
|
398
|
+
ORDER BY created_at, delivery_id`, ...query.recipientKey === void 0 ? [query.since] : [query.since, query.recipientKey])).map((row) => ({
|
|
399
|
+
...outboxEntryOf(row),
|
|
400
|
+
createdAt: row.created_at
|
|
401
|
+
}));
|
|
402
|
+
},
|
|
403
|
+
async stageDigest(request) {
|
|
404
|
+
if (closed) throw new Error("Session delivery service is closed.");
|
|
405
|
+
if (!request.deliveryId.trim() || request.memberIds.length === 0) throw new TypeError("A digest needs a delivery id and at least one member.");
|
|
406
|
+
const now = Date.now();
|
|
407
|
+
const metadata = {
|
|
408
|
+
...normalizedMetadata(request.metadata),
|
|
409
|
+
members: JSON.stringify(request.memberIds)
|
|
410
|
+
};
|
|
411
|
+
await database.transaction(async (transaction) => {
|
|
412
|
+
await transaction.run(`INSERT INTO session_delivery_inbox
|
|
413
|
+
(delivery_id, sender_key, recipient_key, kind, prompt, delivery_mode, metadata_json, state, created_at, updated_at)
|
|
414
|
+
VALUES (?, ?, ?, ?, ?, 'followUp', ?, 'accepted', ?, ?)`, request.deliveryId, options.recipientKey, options.recipientKey, SESSION_DIGEST_KIND, request.prompt, JSON.stringify(metadata), now, now);
|
|
415
|
+
for (const id of request.memberIds) await transaction.run("UPDATE session_delivery_inbox SET consumed_at = ? WHERE delivery_id = ? AND consumed_at IS NULL", now, id);
|
|
416
|
+
});
|
|
417
|
+
scheduleAdmission(request.deliveryId);
|
|
418
|
+
return { deliveryId: request.deliveryId };
|
|
419
|
+
},
|
|
420
|
+
readmit: admitAccepted,
|
|
421
|
+
async record(entry) {
|
|
422
|
+
if (closed) throw new Error("Session delivery service is closed.");
|
|
423
|
+
if (!entry.recipientKey.trim() || !entry.kind.trim()) throw new TypeError("A record needs a recipient key and a kind.");
|
|
424
|
+
const now = Date.now();
|
|
425
|
+
await database.run(`INSERT INTO session_delivery_outbox
|
|
426
|
+
(delivery_id, recipient_key, kind, prompt, delivery_mode, metadata_json, state, recipient_state, created_at, acknowledged_at)
|
|
427
|
+
VALUES (?, ?, ?, '', 'followUp', '{}', 'acknowledged', 'admitted', ?, ?)`, `${entry.kind}:${crypto.randomUUID()}`, entry.recipientKey, entry.kind, now, now);
|
|
428
|
+
},
|
|
429
|
+
reauthorize: publishAllQueued,
|
|
430
|
+
async close() {
|
|
431
|
+
if (closed) return;
|
|
432
|
+
closed = true;
|
|
433
|
+
stopRetry();
|
|
434
|
+
for (const timer of retryTimers) clearTimeout$1(timer);
|
|
435
|
+
retryTimers.clear();
|
|
436
|
+
releaseEnvelope();
|
|
437
|
+
releaseAck();
|
|
438
|
+
releaseReady();
|
|
439
|
+
try {
|
|
440
|
+
await admissionQueue;
|
|
441
|
+
await Promise.all(pending);
|
|
442
|
+
} finally {
|
|
443
|
+
await database.close();
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Installs a provider-owned endpoint in the current Cordis context.
|
|
450
|
+
*
|
|
451
|
+
* Returns the instance because a provider cannot read its own service back out:
|
|
452
|
+
* `ctx.get` is strict and hides an implementation while its providing fiber is
|
|
453
|
+
* LOADING, which is the whole of that fiber's own callback.
|
|
454
|
+
*/
|
|
455
|
+
async function provideSessionDeliveryService(context, options) {
|
|
456
|
+
const service = await createSessionDeliveryService(options);
|
|
457
|
+
const unprovide = context.provide(PO_SESSION_DELIVERY_SERVICE, service);
|
|
458
|
+
context.effect(() => () => service.close(), "session delivery database");
|
|
459
|
+
return {
|
|
460
|
+
service,
|
|
461
|
+
close: async () => {
|
|
462
|
+
unprovide();
|
|
463
|
+
await service.close();
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region ../../foundations/po-session/src/services/sessionGroups/type.ts
|
|
469
|
+
var SessionGroupRevisionError = class extends Error {
|
|
470
|
+
constructor(groupId, expected, actual) {
|
|
471
|
+
super(`Session group '${groupId}' revision conflict: expected ${expected}, current ${actual}.`);
|
|
472
|
+
this.name = "SessionGroupRevisionError";
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region ../../foundations/po-session/src/services/sessionGroups/index.ts
|
|
477
|
+
const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u;
|
|
478
|
+
const REFERENCE_PATTERN = /^peer\/[A-Za-z0-9][A-Za-z0-9._-]{0,127}\/[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u;
|
|
479
|
+
function validateGroupId(value) {
|
|
480
|
+
if (!ID_PATTERN.test(value)) throw new TypeError("Session group IDs must be safe opaque IDs.");
|
|
481
|
+
}
|
|
482
|
+
function validateReference(value) {
|
|
483
|
+
if (!REFERENCE_PATTERN.test(value)) throw new TypeError(`Session group member '${value}' is not a qualified reference.`);
|
|
484
|
+
}
|
|
485
|
+
const SCHEMA = `
|
|
486
|
+
CREATE TABLE IF NOT EXISTS session_groups (
|
|
487
|
+
group_id TEXT PRIMARY KEY,
|
|
488
|
+
owner_authority TEXT NOT NULL,
|
|
489
|
+
revision INTEGER NOT NULL
|
|
490
|
+
);
|
|
491
|
+
CREATE TABLE IF NOT EXISTS session_group_members (
|
|
492
|
+
group_id TEXT NOT NULL REFERENCES session_groups(group_id) ON DELETE CASCADE,
|
|
493
|
+
member_reference TEXT NOT NULL,
|
|
494
|
+
PRIMARY KEY (group_id, member_reference)
|
|
495
|
+
);
|
|
496
|
+
`;
|
|
497
|
+
async function readGroup(database, groupId) {
|
|
498
|
+
const row = await database.get("SELECT * FROM session_groups WHERE group_id = ?", groupId);
|
|
499
|
+
if (!row) return void 0;
|
|
500
|
+
const members = await database.all("SELECT member_reference FROM session_group_members WHERE group_id = ? ORDER BY member_reference", groupId);
|
|
501
|
+
return Object.freeze({
|
|
502
|
+
id: row.group_id,
|
|
503
|
+
ownerAuthority: row.owner_authority,
|
|
504
|
+
revision: Number(row.revision),
|
|
505
|
+
members: Object.freeze(members.map((member) => member.member_reference))
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
/** Opens a revisioned SQLite registry for communication-only group membership. */
|
|
509
|
+
async function createSessionGroupStore(options) {
|
|
510
|
+
const { database } = options;
|
|
511
|
+
try {
|
|
512
|
+
await database.exec("PRAGMA foreign_keys = ON");
|
|
513
|
+
} catch {}
|
|
514
|
+
await database.exec(SCHEMA);
|
|
515
|
+
const enroll = async (transaction, groupId, members) => {
|
|
516
|
+
for (const member of new Set(members)) {
|
|
517
|
+
validateReference(member);
|
|
518
|
+
if (options.validateEnrollment?.(groupId, member) === false) throw new Error(`Session group enrollment policy rejected '${member}'.`);
|
|
519
|
+
await transaction.run("INSERT OR IGNORE INTO session_group_members (group_id, member_reference) VALUES (?, ?)", groupId, member);
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
return {
|
|
523
|
+
async create(groupId, ownerAuthority, members) {
|
|
524
|
+
validateGroupId(groupId);
|
|
525
|
+
if (!ownerAuthority.trim()) throw new TypeError("Session group owner authority is required.");
|
|
526
|
+
return database.transaction(async (transaction) => {
|
|
527
|
+
await transaction.run("INSERT INTO session_groups (group_id, owner_authority, revision) VALUES (?, ?, 1)", groupId, ownerAuthority);
|
|
528
|
+
await enroll(transaction, groupId, members);
|
|
529
|
+
return await readGroup(transaction, groupId);
|
|
530
|
+
});
|
|
531
|
+
},
|
|
532
|
+
async mutate(mutation) {
|
|
533
|
+
return database.transaction(async (transaction) => {
|
|
534
|
+
const current = await readGroup(transaction, mutation.groupId);
|
|
535
|
+
if (!current) throw new Error(`Session group '${mutation.groupId}' does not exist.`);
|
|
536
|
+
if (mutation.authority !== current.ownerAuthority && options.authorizeManagement?.(mutation.authority, current) !== true) throw new Error(`Authority '${mutation.authority}' cannot manage Session group '${mutation.groupId}'.`);
|
|
537
|
+
if (mutation.expectedRevision !== current.revision) throw new SessionGroupRevisionError(mutation.groupId, mutation.expectedRevision, current.revision);
|
|
538
|
+
await enroll(transaction, mutation.groupId, mutation.add ?? []);
|
|
539
|
+
for (const member of new Set(mutation.remove ?? [])) {
|
|
540
|
+
validateReference(member);
|
|
541
|
+
await transaction.run("DELETE FROM session_group_members WHERE group_id = ? AND member_reference = ?", mutation.groupId, member);
|
|
542
|
+
}
|
|
543
|
+
await transaction.run("UPDATE session_groups SET revision = revision + 1 WHERE group_id = ? AND revision = ?", mutation.groupId, current.revision);
|
|
544
|
+
return await readGroup(transaction, mutation.groupId);
|
|
545
|
+
});
|
|
546
|
+
},
|
|
547
|
+
get: (groupId) => readGroup(database, groupId),
|
|
548
|
+
async groupsFor(memberReference) {
|
|
549
|
+
validateReference(memberReference);
|
|
550
|
+
const rows = await database.all(`SELECT g.group_id FROM session_groups g
|
|
551
|
+
INNER JOIN session_group_members m ON m.group_id = g.group_id
|
|
552
|
+
WHERE m.member_reference = ? ORDER BY g.group_id`, memberReference);
|
|
553
|
+
const groups = [];
|
|
554
|
+
for (const row of rows) {
|
|
555
|
+
const group = await readGroup(database, row.group_id);
|
|
556
|
+
if (group) groups.push(group);
|
|
557
|
+
}
|
|
558
|
+
return groups;
|
|
559
|
+
},
|
|
560
|
+
async canMessage(groupId, sourceReference, targetReference) {
|
|
561
|
+
validateReference(sourceReference);
|
|
562
|
+
validateReference(targetReference);
|
|
563
|
+
const row = await database.get(`SELECT COUNT(*) AS count FROM session_group_members
|
|
564
|
+
WHERE group_id = ? AND member_reference IN (?, ?)`, groupId, sourceReference, targetReference);
|
|
565
|
+
return Number(row?.count ?? 0) === (sourceReference === targetReference ? 1 : 2);
|
|
566
|
+
},
|
|
567
|
+
close: () => database.close()
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
//#endregion
|
|
571
|
+
//#region ../../foundations/po-session/src/services/sessionIntercom/type.ts
|
|
572
|
+
const PO_SESSION_INTERCOM_SERVICE = "po/session-intercom";
|
|
573
|
+
//#endregion
|
|
574
|
+
//#region ../../foundations/po-session/src/services/sessionIntercom/index.ts
|
|
575
|
+
const MESSAGE_KIND = "session-message";
|
|
576
|
+
const REPORT_KIND = "session-report";
|
|
577
|
+
async function metadataFor(options, request, reportStatus) {
|
|
578
|
+
const group = await options.groups.get(request.groupId);
|
|
579
|
+
if (!group || !await options.groups.canMessage(request.groupId, options.selfReference, request.targetReference)) throw new Error(`Session group '${request.groupId}' does not authorize this message.`);
|
|
580
|
+
return {
|
|
581
|
+
sourceReference: options.selfReference,
|
|
582
|
+
targetReference: request.targetReference,
|
|
583
|
+
groupId: request.groupId,
|
|
584
|
+
groupRevision: String(group.revision),
|
|
585
|
+
...request.correlationId === void 0 ? {} : { correlationId: request.correlationId },
|
|
586
|
+
...reportStatus === void 0 ? {} : { reportStatus }
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
/** The group IDs, among those given, whose current membership includes this session. */
|
|
590
|
+
async function groupMembership(options, groupIds) {
|
|
591
|
+
const memberOf = /* @__PURE__ */ new Set();
|
|
592
|
+
for (const groupId of new Set(groupIds)) {
|
|
593
|
+
if (groupId === void 0) continue;
|
|
594
|
+
if ((await options.groups.get(groupId))?.members.includes(options.selfReference) === true) memberOf.add(groupId);
|
|
595
|
+
}
|
|
596
|
+
return memberOf;
|
|
597
|
+
}
|
|
598
|
+
/** Agent-facing intercom operations. A composition may acquire this service without gaining session controls. */
|
|
599
|
+
function createSessionIntercom(options) {
|
|
600
|
+
const deliver = async (request, kind, status) => {
|
|
601
|
+
const recipientKey = await options.directory.resolveDeliveryTarget(options.selfReference, request.targetReference);
|
|
602
|
+
if (!recipientKey) throw new Error(`Session '${request.targetReference}' is not discoverable.`);
|
|
603
|
+
const metadata = await metadataFor(options, request, status);
|
|
604
|
+
return options.delivery.deliver({
|
|
605
|
+
...request.deliveryId === void 0 ? {} : { deliveryId: request.deliveryId },
|
|
606
|
+
recipientKey,
|
|
607
|
+
kind,
|
|
608
|
+
prompt: `[Session ${status === void 0 ? "message" : `report: ${status}`} from ${options.selfReference}] ${request.text}`,
|
|
609
|
+
metadata
|
|
610
|
+
});
|
|
611
|
+
};
|
|
612
|
+
return Object.freeze({
|
|
613
|
+
async discover() {
|
|
614
|
+
const members = new Set((await options.groups.groupsFor(options.selfReference)).flatMap((group) => group.members).filter((reference) => reference !== options.selfReference));
|
|
615
|
+
return options.directory.discover(options.selfReference, members);
|
|
616
|
+
},
|
|
617
|
+
send: (request) => deliver(request, MESSAGE_KIND),
|
|
618
|
+
report: (request) => deliver(request, REPORT_KIND, request.status),
|
|
619
|
+
async messages() {
|
|
620
|
+
const entries = (await options.delivery.inbox()).filter((entry) => entry.kind === MESSAGE_KIND || entry.kind === REPORT_KIND);
|
|
621
|
+
const memberOf = await groupMembership(options, entries.map((entry) => entry.metadata.groupId));
|
|
622
|
+
return entries.filter((entry) => {
|
|
623
|
+
const groupId = entry.metadata.groupId;
|
|
624
|
+
return groupId !== void 0 && memberOf.has(groupId);
|
|
625
|
+
}).flatMap((entry) => {
|
|
626
|
+
const sourceReference = entry.metadata.sourceReference;
|
|
627
|
+
const targetReference = entry.metadata.targetReference;
|
|
628
|
+
const groupId = entry.metadata.groupId;
|
|
629
|
+
if (!sourceReference || !targetReference || !groupId) return [];
|
|
630
|
+
const reportStatus = entry.metadata.reportStatus;
|
|
631
|
+
return [{
|
|
632
|
+
deliveryId: entry.deliveryId,
|
|
633
|
+
sourceReference,
|
|
634
|
+
targetReference,
|
|
635
|
+
groupId,
|
|
636
|
+
...entry.metadata.correlationId === void 0 ? {} : { correlationId: entry.metadata.correlationId },
|
|
637
|
+
text: entry.prompt,
|
|
638
|
+
...reportStatus === "done" || reportStatus === "blocked" || reportStatus === "failed" ? { reportStatus } : {},
|
|
639
|
+
state: entry.state,
|
|
640
|
+
consumed: entry.consumed
|
|
641
|
+
}];
|
|
642
|
+
});
|
|
643
|
+
},
|
|
644
|
+
async delivery(deliveryId) {
|
|
645
|
+
const entry = await options.delivery.outbox(deliveryId);
|
|
646
|
+
const groupId = entry?.metadata.groupId;
|
|
647
|
+
return entry && groupId !== void 0 && (await groupMembership(options, [groupId])).has(groupId) ? entry : void 0;
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
/** Builds the dynamic delivery check used before every send, retry, and recipient acceptance. */
|
|
652
|
+
function createSessionGroupDeliveryAuthorizer(options) {
|
|
653
|
+
return async (peerKey, metadata) => {
|
|
654
|
+
const sourceReference = metadata?.sourceReference;
|
|
655
|
+
const targetReference = metadata?.targetReference;
|
|
656
|
+
const groupId = metadata?.groupId;
|
|
657
|
+
if (sourceReference && targetReference && groupId) {
|
|
658
|
+
const peerReference = options.peerReference(peerKey);
|
|
659
|
+
if (!peerReference) return false;
|
|
660
|
+
return (sourceReference === options.selfReference && targetReference === peerReference || targetReference === options.selfReference && sourceReference === peerReference) && await options.groups.canMessage(groupId, sourceReference, targetReference);
|
|
661
|
+
}
|
|
662
|
+
return await options.fallback?.(peerKey, metadata) === true;
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
//#endregion
|
|
666
|
+
//#region ../../foundations/po-session/src/extensions/(backend)/root.server.ts
|
|
667
|
+
var root_server_default$1 = defineRoot((plugin) => ({
|
|
668
|
+
value: void 0,
|
|
669
|
+
services: [async (context) => {
|
|
670
|
+
await context.inject([
|
|
671
|
+
PO_FS_SERVICE,
|
|
672
|
+
PO_SQLITE_SERVICE,
|
|
673
|
+
PO_SERVER_SCOPE_SERVICE
|
|
674
|
+
], async (scoped) => {
|
|
675
|
+
const homeDirectory = plugin.host.context.homeDirectory;
|
|
676
|
+
if (!homeDirectory) throw new Error("Host links require an explicit host home directory.");
|
|
677
|
+
const peers = await createSessionPeers({
|
|
678
|
+
fs: requirePoFs(scoped),
|
|
679
|
+
homeDirectory
|
|
680
|
+
});
|
|
681
|
+
await peers.identity();
|
|
682
|
+
const directory = path.join(poHomeDirectory(homeDirectory), "session");
|
|
683
|
+
await ensurePrivateDirectory(requirePoFs(scoped), directory, BACKGROUND_CONTEXT);
|
|
684
|
+
const database = await requirePoSqlite(scoped).open(path.join(directory, "groups.sqlite"), BACKGROUND_CONTEXT);
|
|
685
|
+
const groups = await createSessionGroupStore({ database });
|
|
686
|
+
await database.run("DELETE FROM session_group_members WHERE group_id IN (SELECT group_id FROM session_groups WHERE owner_authority = 'session-group-bridge')");
|
|
687
|
+
await database.run("DELETE FROM session_groups WHERE owner_authority = 'session-group-bridge'");
|
|
688
|
+
const bridge = createSessionGroupBridge({
|
|
689
|
+
groups,
|
|
690
|
+
peers,
|
|
691
|
+
onError: (error) => plugin.host.context.onNotice(`Group bridge failed: ${String(error)}`),
|
|
692
|
+
send: async (hostId, advert) => {
|
|
693
|
+
const config = peers.current();
|
|
694
|
+
const peer = config?.peers.find((entry) => entry.hostId === hostId);
|
|
695
|
+
if (!config || !peer) return;
|
|
696
|
+
await authenticatedPeerPost({
|
|
697
|
+
config,
|
|
698
|
+
peer,
|
|
699
|
+
path: "/api/plugins/session-peer/control",
|
|
700
|
+
value: {
|
|
701
|
+
type: "groups",
|
|
702
|
+
groups: advert
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
const scope = requirePoServerScope(scoped);
|
|
708
|
+
const releasePeers = plugin.host.scope === "host" ? await scope.provide(PO_SESSION_PEERS_CONTRACT, peers) : scoped.provide(PO_SESSION_PEERS_SERVICE, peers);
|
|
709
|
+
let releaseBridge;
|
|
710
|
+
try {
|
|
711
|
+
releaseBridge = plugin.host.scope === "host" ? await scope.provide(PO_SESSION_GROUP_BRIDGE_CONTRACT, bridge) : scoped.provide(PO_SESSION_GROUP_BRIDGE_SERVICE, bridge);
|
|
712
|
+
} catch (error) {
|
|
713
|
+
await Promise.resolve(releasePeers());
|
|
714
|
+
await bridge.close();
|
|
715
|
+
throw error;
|
|
716
|
+
}
|
|
717
|
+
return async () => {
|
|
718
|
+
await releaseBridge();
|
|
719
|
+
await Promise.resolve(releasePeers());
|
|
720
|
+
await bridge.close();
|
|
721
|
+
};
|
|
722
|
+
});
|
|
723
|
+
}]
|
|
724
|
+
}));
|
|
725
|
+
const MAX_AGENT_RUN_TIMEOUT_MS = 72e5;
|
|
726
|
+
const POLL_MS = 1e3;
|
|
727
|
+
const NAME_MAX = 60;
|
|
728
|
+
const INPUT_KEYS = /* @__PURE__ */ new Set([
|
|
729
|
+
"task",
|
|
730
|
+
"systemPrompt",
|
|
731
|
+
"preset",
|
|
732
|
+
"modes",
|
|
733
|
+
"profile",
|
|
734
|
+
"domains",
|
|
735
|
+
"model",
|
|
736
|
+
"thinking",
|
|
737
|
+
"cwd",
|
|
738
|
+
"timeoutMs"
|
|
739
|
+
]);
|
|
740
|
+
const LAST_CONTROL_CODE = 31;
|
|
741
|
+
const DELETE_CODE = 127;
|
|
742
|
+
function hasControl(text) {
|
|
743
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
744
|
+
const code = text.charCodeAt(index);
|
|
745
|
+
if (code <= LAST_CONTROL_CODE || code === DELETE_CODE) return true;
|
|
746
|
+
}
|
|
747
|
+
return false;
|
|
748
|
+
}
|
|
749
|
+
/** A turn ended by these never produced a reply the caller can use. */
|
|
750
|
+
const UNFINISHED_STOPS = /* @__PURE__ */ new Set([
|
|
751
|
+
"error",
|
|
752
|
+
"aborted",
|
|
753
|
+
"toolUse"
|
|
754
|
+
]);
|
|
755
|
+
/** A value that becomes a harness flag argument on Node: no leading dash, no control characters, bounded. */
|
|
756
|
+
function name(field, value, list = false) {
|
|
757
|
+
if (typeof value !== "string") throw new TypeError(`agent: ${field} must be a string.`);
|
|
758
|
+
const text = value.trim();
|
|
759
|
+
if (text === "" || text.length > 200 || text.startsWith("-") || hasControl(text) || list && text.includes(",")) throw new TypeError(`agent: ${field} '${value.slice(0, 40)}' is not a valid name.`);
|
|
760
|
+
return text;
|
|
761
|
+
}
|
|
762
|
+
function names(field, value) {
|
|
763
|
+
if (!Array.isArray(value)) throw new TypeError(`agent: ${field} must be an array of names.`);
|
|
764
|
+
return [...new Set(value.map((entry) => name(field, entry, true)))];
|
|
765
|
+
}
|
|
766
|
+
/** Validates an agent run request at the trust boundary. Throws a TypeError naming the bad field. */
|
|
767
|
+
function parseAgentRunInput(value) {
|
|
768
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError("agent: input must be an object with a task.");
|
|
769
|
+
const record = value;
|
|
770
|
+
for (const key of Object.keys(record)) {
|
|
771
|
+
if (key === "majorMode" || key === "minorModes") throw new TypeError(`agent: '${key}' is retired; use modes.`);
|
|
772
|
+
if (!INPUT_KEYS.has(key)) throw new TypeError(`agent: unknown field '${key}'.`);
|
|
773
|
+
}
|
|
774
|
+
const { task, systemPrompt, cwd, timeoutMs, profile } = record;
|
|
775
|
+
if (typeof task !== "string" || task.trim() === "") throw new TypeError("agent: task must be a non-empty string.");
|
|
776
|
+
if (systemPrompt !== void 0 && typeof systemPrompt !== "string") throw new TypeError("agent: systemPrompt must be a string.");
|
|
777
|
+
if (cwd !== void 0 && (typeof cwd !== "string" || !cwd.startsWith("/") || hasControl(cwd))) throw new TypeError("agent: cwd must be an absolute path.");
|
|
778
|
+
if (timeoutMs !== void 0 && (typeof timeoutMs !== "number" || !Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 72e5)) throw new TypeError(`agent: timeoutMs must be an integer from 1 to ${MAX_AGENT_RUN_TIMEOUT_MS}.`);
|
|
779
|
+
return {
|
|
780
|
+
task,
|
|
781
|
+
...systemPrompt === void 0 || systemPrompt === "" ? {} : { systemPrompt },
|
|
782
|
+
...record.preset === void 0 ? {} : { preset: name("preset", record.preset) },
|
|
783
|
+
...record.modes === void 0 ? {} : { modes: names("modes", record.modes) },
|
|
784
|
+
...profile === void 0 ? {} : { profile: profile === null ? null : name("profile", profile) },
|
|
785
|
+
...record.domains === void 0 ? {} : { domains: names("domains", record.domains) },
|
|
786
|
+
...record.model === void 0 ? {} : { model: name("model", record.model) },
|
|
787
|
+
...record.thinking === void 0 ? {} : { thinking: name("thinking", record.thinking) },
|
|
788
|
+
...cwd === void 0 ? {} : { cwd },
|
|
789
|
+
timeoutMs: timeoutMs ?? 6e5
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
/** Same request, same hash: the parsed input with its keys in a fixed order, so `profile: null` and unset differ. */
|
|
793
|
+
async function agentRunHash(input) {
|
|
794
|
+
const ordered = Object.fromEntries([...INPUT_KEYS].filter((key) => key in input).map((key) => [key, input[key]]));
|
|
795
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(ordered)));
|
|
796
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
797
|
+
}
|
|
798
|
+
/** Over message entries newest first, the newest assistant message decides: a finished reply, an error or abort, or nothing usable. */
|
|
799
|
+
function finalReply(entries) {
|
|
800
|
+
for (const item of entries) {
|
|
801
|
+
const entry = item;
|
|
802
|
+
const message = entry?.type === "message" ? entry.message : void 0;
|
|
803
|
+
if (message?.role !== "assistant") continue;
|
|
804
|
+
const stop = typeof message.stopReason === "string" ? message.stopReason : "";
|
|
805
|
+
if (stop === "error") return {
|
|
806
|
+
status: "failed",
|
|
807
|
+
error: typeof message.errorMessage === "string" ? message.errorMessage : "The agent run failed."
|
|
808
|
+
};
|
|
809
|
+
if (stop === "aborted") return {
|
|
810
|
+
status: "stopped",
|
|
811
|
+
error: "The agent run was stopped."
|
|
812
|
+
};
|
|
813
|
+
if (UNFINISHED_STOPS.has(stop)) return void 0;
|
|
814
|
+
const content = message.content;
|
|
815
|
+
const text = (typeof content === "string" ? content : Array.isArray(content) ? content.filter((part) => part?.type === "text" && typeof part.text === "string").map((part) => part.text).join("") : "").trim();
|
|
816
|
+
return text === "" ? void 0 : {
|
|
817
|
+
status: "completed",
|
|
818
|
+
text
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
function selectionOf(input) {
|
|
823
|
+
const selection = {
|
|
824
|
+
...input.preset === void 0 ? {} : { preset: input.preset },
|
|
825
|
+
...input.modes === void 0 ? {} : { modes: input.modes },
|
|
826
|
+
...input.profile === void 0 ? {} : { profile: input.profile },
|
|
827
|
+
...input.domains === void 0 ? {} : { domains: input.domains }
|
|
828
|
+
};
|
|
829
|
+
return Object.keys(selection).length === 0 ? void 0 : selection;
|
|
830
|
+
}
|
|
831
|
+
function errorText(error) {
|
|
832
|
+
return error instanceof Error ? error.message : String(error);
|
|
833
|
+
}
|
|
834
|
+
/** Settles with `work`, or rejects once `signal` aborts; no timer or listener outlives it. */
|
|
835
|
+
function until(work, signal) {
|
|
836
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
837
|
+
let stop = () => void 0;
|
|
838
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
839
|
+
stop = () => reject(signal.reason);
|
|
840
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
841
|
+
});
|
|
842
|
+
return Promise.race([work, aborted]).finally(() => signal.removeEventListener("abort", stop));
|
|
843
|
+
}
|
|
844
|
+
function pause(ms, signal) {
|
|
845
|
+
let timer;
|
|
846
|
+
return until(new Promise((resolve) => {
|
|
847
|
+
timer = setTimeout(resolve, ms);
|
|
848
|
+
}), signal).finally(() => clearTimeout(timer));
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Runs tasks in unattended child sessions of one owning session. A child keeps the workflow-step provenance, so it
|
|
852
|
+
* stays out of the rail and reads like a step session once released.
|
|
853
|
+
*/
|
|
854
|
+
function createAgentRunService(dependencies) {
|
|
855
|
+
const { sessionId: parentSessionId, sessions } = dependencies;
|
|
856
|
+
const pollMs = dependencies.pollMs ?? POLL_MS;
|
|
857
|
+
return { async run(raw, options = {}) {
|
|
858
|
+
const input = parseAgentRunInput(raw);
|
|
859
|
+
const hash = await agentRunHash(input);
|
|
860
|
+
const cwd = input.cwd ?? dependencies.cwd;
|
|
861
|
+
if (!sessions?.prompt || !sessions.readExecutionState || !sessions.readMessages || cwd === void 0) return {
|
|
862
|
+
status: "failed",
|
|
863
|
+
output: "",
|
|
864
|
+
error: "This host cannot run agent sessions."
|
|
865
|
+
};
|
|
866
|
+
const timeout = AbortSignal.timeout(input.timeoutMs);
|
|
867
|
+
const signal = AbortSignal.any([
|
|
868
|
+
dependencies.lifetime,
|
|
869
|
+
timeout,
|
|
870
|
+
...options.signal === void 0 ? [] : [options.signal]
|
|
871
|
+
]);
|
|
872
|
+
const owned = { parentSessionId };
|
|
873
|
+
let sessionId;
|
|
874
|
+
let result;
|
|
875
|
+
try {
|
|
876
|
+
const selection = selectionOf(input);
|
|
877
|
+
sessionId = (await sessions.create({
|
|
878
|
+
cwd,
|
|
879
|
+
name: `Agent: ${input.task.trim().split("\n", 1)[0].slice(0, NAME_MAX)}`,
|
|
880
|
+
parentSessionId,
|
|
881
|
+
sessionProvenance: WORKFLOW_STEP_SESSION_PROVENANCE,
|
|
882
|
+
interaction: "unattended",
|
|
883
|
+
...selection === void 0 ? {} : { selection },
|
|
884
|
+
...input.model === void 0 ? {} : { model: input.model },
|
|
885
|
+
...input.thinking === void 0 ? {} : { thinking: input.thinking },
|
|
886
|
+
...input.systemPrompt === void 0 ? {} : { appendSystemPrompt: input.systemPrompt },
|
|
887
|
+
signal
|
|
888
|
+
})).sessionId;
|
|
889
|
+
options.onStarted?.(sessionId, hash);
|
|
890
|
+
await until((await sessions.prompt(sessionId, input.task, {
|
|
891
|
+
...owned,
|
|
892
|
+
signal
|
|
893
|
+
})).settled, signal);
|
|
894
|
+
for (;;) {
|
|
895
|
+
const state = await sessions.readExecutionState(sessionId, owned);
|
|
896
|
+
if (state.isIdle && !state.hasPendingMessages && !(state.backgroundWork?.items.some(holdsSettledSession) ?? false) && ((await dependencies.approvals()?.unsettled(sessionId))?.length ?? 0) === 0) break;
|
|
897
|
+
await pause(pollMs, signal);
|
|
898
|
+
}
|
|
899
|
+
const reply = finalReply(await sessions.readMessages(sessionId, {
|
|
900
|
+
...owned,
|
|
901
|
+
limit: 20
|
|
902
|
+
}));
|
|
903
|
+
result = reply === void 0 ? {
|
|
904
|
+
sessionId,
|
|
905
|
+
status: "failed",
|
|
906
|
+
output: "",
|
|
907
|
+
error: "The agent ended without a reply."
|
|
908
|
+
} : reply.status === "completed" ? {
|
|
909
|
+
sessionId,
|
|
910
|
+
status: "completed",
|
|
911
|
+
output: reply.text
|
|
912
|
+
} : {
|
|
913
|
+
sessionId,
|
|
914
|
+
status: reply.status,
|
|
915
|
+
output: "",
|
|
916
|
+
error: reply.error
|
|
917
|
+
};
|
|
918
|
+
} catch (error) {
|
|
919
|
+
result = {
|
|
920
|
+
...sessionId === void 0 ? {} : { sessionId },
|
|
921
|
+
status: signal.aborted && !timeout.aborted ? "stopped" : "failed",
|
|
922
|
+
output: "",
|
|
923
|
+
error: timeout.aborted ? `The agent did not finish within ${input.timeoutMs}ms.` : errorText(error)
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
if (sessionId !== void 0) {
|
|
927
|
+
const child = sessionId;
|
|
928
|
+
const cleanup = async (step) => {
|
|
929
|
+
try {
|
|
930
|
+
await step();
|
|
931
|
+
} catch (error) {
|
|
932
|
+
dependencies.onError?.(error);
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
if (signal.aborted) await cleanup(() => sessions.abort?.(child, owned));
|
|
936
|
+
await cleanup(() => dependencies.approvals()?.abandon(child));
|
|
937
|
+
await cleanup(() => sessions.release?.(child, owned));
|
|
938
|
+
}
|
|
939
|
+
return result;
|
|
940
|
+
} };
|
|
941
|
+
}
|
|
942
|
+
//#endregion
|
|
943
|
+
//#region ../../foundations/po-session/src/services/networkNamespace/index.ts
|
|
944
|
+
/** `{ to, text, urgent? }`, validated at the namespace boundary. `urgent` exists only where the host has lanes. */
|
|
945
|
+
function parseSend(raw, lanes) {
|
|
946
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new Error("Expected an object.");
|
|
947
|
+
const { urgent, ...rest } = raw;
|
|
948
|
+
if (urgent !== void 0 && !lanes) throw new Error("Unknown operation field.");
|
|
949
|
+
if (urgent !== void 0 && typeof urgent !== "boolean") throw new Error("urgent must be a boolean.");
|
|
950
|
+
const { to, text } = fields(rest, ["to", "text"]);
|
|
951
|
+
return {
|
|
952
|
+
to,
|
|
953
|
+
text,
|
|
954
|
+
urgent: urgent === true
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
/** Messaging between sessions on this host and linked hosts, with Team intercom's send, ask, reply and pending. */
|
|
958
|
+
function createNetworkNamespace(options) {
|
|
959
|
+
assertCodemodeNamespaceName("network");
|
|
960
|
+
const { operations } = options;
|
|
961
|
+
return {
|
|
962
|
+
name: "network",
|
|
963
|
+
summary: "Message sessions on this host and linked hosts: send, ask with a tracked reply, answer questions, and keep a coordinator logbook.",
|
|
964
|
+
portable: true,
|
|
965
|
+
declarations: `declare const network: {
|
|
966
|
+
list(): Promise<unknown>;
|
|
967
|
+
${operations.lanes ? `/** Queued: arrives in one digest when the recipient's run ends. urgent joins its running turn. Both are budgeted per session. */
|
|
968
|
+
send(input: { to: string; text: string; urgent?: boolean }): Promise<unknown>;` : "send(input: { to: string; text: string }): Promise<unknown>;"}
|
|
969
|
+
${operations.ask ? `/** Joins the recipient's running turn, so it spends the interrupt budget. The reply arrives later as a message. */
|
|
970
|
+
ask(input: { to: string; text: string }): Promise<{ requestId: string }>;` : ""}
|
|
971
|
+
${operations.reply ? "reply(input: { requestId: string; text: string }): Promise<unknown>;" : ""}
|
|
972
|
+
${operations.pending ? "pending(): Promise<{ requestId: string; from: string }[]>;" : ""}
|
|
973
|
+
${operations.log ? `/** Append to your coordinator's logbook (hierarchy only, never a group). 'blocked' wakes it, batched; the host files your stop report itself. Empty to: no coordinator. */
|
|
974
|
+
log(input: { text: string; level?: 'info' | 'blocked' }): Promise<{ to: string[] }>;` : ""}
|
|
975
|
+
${operations.logbook ? `/** Your own logbook as a coordinator, newest first. limit defaults to 20, at most 100. */
|
|
976
|
+
logbook(input?: { unread?: boolean; sessionId?: string; offset?: number; limit?: number }): Promise<{
|
|
977
|
+
entries: { id: string; from: string; name?: string; level: 'info' | 'blocked'; text: string; at?: string; read: boolean }[];
|
|
978
|
+
total: number;
|
|
979
|
+
nextOffset?: number;
|
|
980
|
+
}>;` : ""}
|
|
981
|
+
${operations.markRead ? "markRead(input: { ids: string[] }): Promise<{ marked: number }>;" : ""}
|
|
982
|
+
};`,
|
|
983
|
+
bind(run) {
|
|
984
|
+
if (run.sessionId !== options.sessionId) throw new Error("Network namespace belongs to another session.");
|
|
985
|
+
const lifetime = new AbortController();
|
|
986
|
+
const signal = AbortSignal.any([run.signal, lifetime.signal]);
|
|
987
|
+
run.onDispose(() => lifetime.abort(/* @__PURE__ */ new Error("Network code-mode run is disposed.")));
|
|
988
|
+
const check = () => {
|
|
989
|
+
if (run.caller !== "main") throw new Error("Network operations require the main agent.");
|
|
990
|
+
signal.throwIfAborted();
|
|
991
|
+
options.assertAvailable();
|
|
992
|
+
};
|
|
993
|
+
const methods = Object.create(null);
|
|
994
|
+
methods.list = async () => {
|
|
995
|
+
check();
|
|
996
|
+
const result = await operations.list(signal);
|
|
997
|
+
check();
|
|
998
|
+
return detach(result);
|
|
999
|
+
};
|
|
1000
|
+
methods.send = async (raw) => {
|
|
1001
|
+
check();
|
|
1002
|
+
const { to, text, urgent } = parseSend(raw, operations.lanes === true);
|
|
1003
|
+
return detach(await (urgent ? operations.send(to, text, signal, { urgent }) : operations.send(to, text, signal)));
|
|
1004
|
+
};
|
|
1005
|
+
if (operations.ask) methods.ask = async (raw) => {
|
|
1006
|
+
check();
|
|
1007
|
+
const { to, text } = fields(raw, ["to", "text"]);
|
|
1008
|
+
return detach(await operations.ask(to, text, signal));
|
|
1009
|
+
};
|
|
1010
|
+
if (operations.reply) methods.reply = async (raw) => {
|
|
1011
|
+
check();
|
|
1012
|
+
const { requestId, text } = fields(raw, ["requestId", "text"]);
|
|
1013
|
+
return detach(await operations.reply(requestId, text, signal));
|
|
1014
|
+
};
|
|
1015
|
+
if (operations.pending) methods.pending = async () => {
|
|
1016
|
+
check();
|
|
1017
|
+
const result = await operations.pending(signal);
|
|
1018
|
+
check();
|
|
1019
|
+
return detach(result);
|
|
1020
|
+
};
|
|
1021
|
+
if (operations.log) methods.log = async (raw) => {
|
|
1022
|
+
check();
|
|
1023
|
+
const { text, level } = parseLogInput(raw);
|
|
1024
|
+
return detach(await operations.log(text, level, signal));
|
|
1025
|
+
};
|
|
1026
|
+
if (operations.logbook) methods.logbook = async (raw) => {
|
|
1027
|
+
check();
|
|
1028
|
+
const result = await operations.logbook(parseLogbookQuery(raw), signal);
|
|
1029
|
+
check();
|
|
1030
|
+
return detach(result);
|
|
1031
|
+
};
|
|
1032
|
+
if (operations.markRead) methods.markRead = async (raw) => {
|
|
1033
|
+
check();
|
|
1034
|
+
return detach(await operations.markRead(parseMarkReadInput(raw), signal));
|
|
1035
|
+
};
|
|
1036
|
+
return methods;
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
//#endregion
|
|
1041
|
+
//#region ../../foundations/po-session/src/services/peerInbox/index.ts
|
|
1042
|
+
const inboxes = /* @__PURE__ */ new Map();
|
|
1043
|
+
/**
|
|
1044
|
+
* Registers one live session-owned peer inbox. This registry is reachable only by the Session route.
|
|
1045
|
+
* The newest registration wins: a Durable Object evicted without disposal leaves its entry in the
|
|
1046
|
+
* isolate's module state, and the restarted session must replace it. The hub still rejects two live
|
|
1047
|
+
* sessions with one id, and an older unregister cannot remove a newer inbox.
|
|
1048
|
+
*/
|
|
1049
|
+
function registerSessionPeerInbox(sessionId, inbox) {
|
|
1050
|
+
inboxes.set(sessionId, inbox);
|
|
1051
|
+
return () => {
|
|
1052
|
+
if (inboxes.get(sessionId) === inbox) inboxes.delete(sessionId);
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
async function deliverSessionPeerEnvelope(targetSessionId, sourceKey, type, payload) {
|
|
1056
|
+
return inboxes.get(targetSessionId)?.(sourceKey, type, payload);
|
|
1057
|
+
}
|
|
1058
|
+
//#endregion
|
|
1059
|
+
//#region ../../foundations/po-session/src/extensions/workspaces/sessions/(backend)/root.server.ts
|
|
1060
|
+
/** How much of its own work a session is reminded of at the end of a peer's message. */
|
|
1061
|
+
const WORK_ANCHOR_MAX = 800;
|
|
1062
|
+
/** The outbox record of a session this one started, so it counts as engaged with it. */
|
|
1063
|
+
const ENGAGE_KIND = "session-engage";
|
|
1064
|
+
/** Admits an intercom notice into the session itself, to be read when its run ends. */
|
|
1065
|
+
async function remindSession(agent, text, requestId, details) {
|
|
1066
|
+
const session = agent.context.session;
|
|
1067
|
+
if (session?.admitMessage) await session.admitMessage({
|
|
1068
|
+
type: INTERCOM_MESSAGE_TYPE,
|
|
1069
|
+
text,
|
|
1070
|
+
display: true,
|
|
1071
|
+
details
|
|
1072
|
+
}, "followUp", requestId);
|
|
1073
|
+
else await session?.admitPrompt?.(text, "followUp", void 0, requestId);
|
|
1074
|
+
}
|
|
1075
|
+
var root_server_default = defineRoot((pluginContext) => ({
|
|
1076
|
+
value: void 0,
|
|
1077
|
+
services: [
|
|
1078
|
+
provideBackgroundWorkService,
|
|
1079
|
+
(owner) => {
|
|
1080
|
+
const agent = pluginContext.agent;
|
|
1081
|
+
if (!agent) return;
|
|
1082
|
+
const options = {
|
|
1083
|
+
sessionId: agent.context.sessionId,
|
|
1084
|
+
provenance: () => pluginContext.host.context.sessionContext?.provenance,
|
|
1085
|
+
coordination: () => pluginContext.host.context.coordination,
|
|
1086
|
+
started: async (sessionId) => {
|
|
1087
|
+
try {
|
|
1088
|
+
await readPoSessionDelivery(owner)?.record({
|
|
1089
|
+
recipientKey: sessionId,
|
|
1090
|
+
kind: ENGAGE_KIND
|
|
1091
|
+
});
|
|
1092
|
+
} catch (error) {
|
|
1093
|
+
pluginContext.host.context.onNotice(`Engage record failed: ${String(error)}`);
|
|
1094
|
+
}
|
|
1095
|
+
},
|
|
1096
|
+
operations: readSessionOperations(owner) ?? createNodeSessionOperations(pluginContext.host, owner, agent.context.sessionId, (text, requestId, details) => remindSession(agent, text, requestId, details)),
|
|
1097
|
+
assertAvailable: () => pluginContext.signal.throwIfAborted()
|
|
1098
|
+
};
|
|
1099
|
+
const tool = agent.registerTool(createStartSessionTool(options));
|
|
1100
|
+
let session = agent.context.session;
|
|
1101
|
+
const stop = createStopReport({
|
|
1102
|
+
delayMs: STOP_REPORT_DELAY_MS,
|
|
1103
|
+
activity: async () => await session?.activity() ?? {
|
|
1104
|
+
isIdle: false,
|
|
1105
|
+
hasPendingMessages: false
|
|
1106
|
+
},
|
|
1107
|
+
holding: () => readPoBackgroundWorkService(owner)?.snapshot().items.some(holdsSettledSession) === true,
|
|
1108
|
+
report: async () => {
|
|
1109
|
+
if (!session || !options.operations.log) return;
|
|
1110
|
+
const text = await lastAssistantText(session) ?? "No reply yet.";
|
|
1111
|
+
await options.operations.log(text, STOP_LEVEL, pluginContext.signal);
|
|
1112
|
+
},
|
|
1113
|
+
onError: (error) => pluginContext.host.context.onNotice(`Stop report failed: ${String(error)}`)
|
|
1114
|
+
});
|
|
1115
|
+
const settled = agent.registerHook({
|
|
1116
|
+
event: "agent_settled",
|
|
1117
|
+
handle: (_event, execution) => {
|
|
1118
|
+
session = execution.session;
|
|
1119
|
+
stop.settled();
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
const eligibility = options.provenance() === "coordinator" ? void 0 : agent.registerToolRestriction({ excludedTools: [START_SESSION_TOOL_NAME] });
|
|
1123
|
+
const injection = owner.inject([PO_CODEMODE_SERVICE], (context) => {
|
|
1124
|
+
const codemode = readPoCodemode(context);
|
|
1125
|
+
const registration = codemode?.register("@agimon-ai/po-session", createSessionsNamespace(options));
|
|
1126
|
+
const network = codemode?.register("@agimon-ai/po-session", createNetworkNamespace(options));
|
|
1127
|
+
const restriction = registration ? agent.registerToolRestriction({ excludedTools: [START_SESSION_TOOL_NAME, ...options.operations.fallbackToolName ? [options.operations.fallbackToolName] : []] }) : void 0;
|
|
1128
|
+
return () => {
|
|
1129
|
+
restriction?.dispose();
|
|
1130
|
+
network?.dispose();
|
|
1131
|
+
registration?.dispose();
|
|
1132
|
+
};
|
|
1133
|
+
});
|
|
1134
|
+
return async () => {
|
|
1135
|
+
await injection.dispose();
|
|
1136
|
+
eligibility?.dispose();
|
|
1137
|
+
settled.dispose();
|
|
1138
|
+
stop.close();
|
|
1139
|
+
tool.dispose();
|
|
1140
|
+
};
|
|
1141
|
+
},
|
|
1142
|
+
(owner) => {
|
|
1143
|
+
owner.inject([
|
|
1144
|
+
PO_SESSION_PEERS_SERVICE,
|
|
1145
|
+
PO_SESSION_GROUP_BRIDGE_SERVICE,
|
|
1146
|
+
PO_FS_SERVICE,
|
|
1147
|
+
PO_SQLITE_SERVICE
|
|
1148
|
+
], async (context) => {
|
|
1149
|
+
const agent = pluginContext.agent;
|
|
1150
|
+
const session = agent?.context.session;
|
|
1151
|
+
const communication = pluginContext.host.context.sessionCommunication;
|
|
1152
|
+
const homeDirectory = pluginContext.host.context.homeDirectory;
|
|
1153
|
+
const sessionService = pluginContext.host.context.sessionService;
|
|
1154
|
+
if (!agent || !session?.admitPrompt || !communication || !homeDirectory || !sessionService?.canCommunicate) throw new Error("Session delivery requires the headless agent, authenticated session communication, host home directory, and communication policy.");
|
|
1155
|
+
const fs = requirePoFs(context);
|
|
1156
|
+
const sqlite = requirePoSqlite(context);
|
|
1157
|
+
const io = BACKGROUND_CONTEXT;
|
|
1158
|
+
const sessionDirectory = path.join(poHomeDirectory(homeDirectory), "session");
|
|
1159
|
+
const deliveryDirectory = path.join(sessionDirectory, "delivery");
|
|
1160
|
+
await ensurePrivateDirectory(fs, deliveryDirectory, io);
|
|
1161
|
+
const peers = requireSessionPeers(context);
|
|
1162
|
+
const peerConfig = peers.current();
|
|
1163
|
+
const peerCommunication = createPeerCommunication({
|
|
1164
|
+
local: communication,
|
|
1165
|
+
config: () => peers.current(),
|
|
1166
|
+
canPublish: (target, type, payload) => {
|
|
1167
|
+
if (type === "po/session-delivery/ack") return true;
|
|
1168
|
+
const metadata = payload?.metadata;
|
|
1169
|
+
return bridge?.peersFor(agent.context.sessionId).some((peer) => peer.sessionId === target && peer.sharedGroups.some((name) => namedSessionGroupId(name) === metadata?.groupId)) === true;
|
|
1170
|
+
},
|
|
1171
|
+
onError: (error) => pluginContext.host.context.onNotice(`Peer delivery failed: ${String(error)}`)
|
|
1172
|
+
});
|
|
1173
|
+
const remotePeerIsGranted = (peerKey) => {
|
|
1174
|
+
const peer = parseRemoteSessionReference(peerKey);
|
|
1175
|
+
return peer !== void 0 && peers.current()?.peers.some((candidate) => candidate.hostId === peer.hostId && candidate.allowedSessionIds.includes(agent.context.sessionId)) === true;
|
|
1176
|
+
};
|
|
1177
|
+
const fallbackAuthorization = (peerKey) => sessionService.canCommunicate?.(agent.context.sessionId, peerKey) === true || remotePeerIsGranted(peerKey);
|
|
1178
|
+
const bridge = readSessionGroupBridge(context);
|
|
1179
|
+
const groups = bridge?.groups;
|
|
1180
|
+
await bridge?.updateLocal(agent.context.sessionId, communication.sessionName ?? agent.context.sessionId, communication.groups ?? []);
|
|
1181
|
+
const localHostId = peerConfig?.hostId;
|
|
1182
|
+
const selfReference = localHostId ? peerSessionReference(localHostId, agent.context.sessionId) : void 0;
|
|
1183
|
+
const groupAuthorization = groups && selfReference && localHostId ? createSessionGroupDeliveryAuthorizer({
|
|
1184
|
+
selfReference,
|
|
1185
|
+
groups,
|
|
1186
|
+
peerReference: (peerKey) => parseRemoteSessionReference(peerKey) === void 0 ? peerSessionReference(localHostId, peerKey) : peerKey,
|
|
1187
|
+
fallback: fallbackAuthorization
|
|
1188
|
+
}) : void 0;
|
|
1189
|
+
const authorizePeer = (peerKey, metadata) => {
|
|
1190
|
+
if (metadata?.logbook !== void 0) {
|
|
1191
|
+
const peer = communication.describePeer?.(peerKey);
|
|
1192
|
+
if (peer?.coordinator !== true && peer?.coordinated !== true) return false;
|
|
1193
|
+
}
|
|
1194
|
+
const remote = parseRemoteSessionReference(peerKey);
|
|
1195
|
+
if (remote && !peers.current()?.peers.some((peer) => peer.hostId === remote.hostId)) return false;
|
|
1196
|
+
if (remote) {
|
|
1197
|
+
if (!bridge?.metadataFor(agent.context.sessionId, peerKey) || !metadata?.groupId || !bridge?.peersFor(agent.context.sessionId).find((peer) => peer.sessionId === peerKey)?.sharedGroups.some((name) => namedSessionGroupId(name) === metadata.groupId)) return false;
|
|
1198
|
+
return groupAuthorization ? groupAuthorization(peerKey, metadata) : false;
|
|
1199
|
+
}
|
|
1200
|
+
return groupAuthorization ? groupAuthorization(peerKey, metadata) : fallbackAuthorization(peerKey);
|
|
1201
|
+
};
|
|
1202
|
+
/** What this session was working on, so a peer's message ends by pointing back at it. */
|
|
1203
|
+
const workAnchor = () => {
|
|
1204
|
+
const work = (readPoContextContributions(context)?.snapshot().entries ?? []).map((entry) => entry.text).join("\n").slice(0, WORK_ANCHOR_MAX).trim();
|
|
1205
|
+
return work === "" ? "" : `\n\nBack to your work:\n${work}`;
|
|
1206
|
+
};
|
|
1207
|
+
/** How the chat shows a digest this session receives, under the name of what gathered it. */
|
|
1208
|
+
const digestMetadata = (name) => (prompt, deliveryId) => ({
|
|
1209
|
+
customType: INTERCOM_MESSAGE_TYPE,
|
|
1210
|
+
customDetails: JSON.stringify(intercomDetails("send", name, agent.context.sessionId, prompt, deliveryId))
|
|
1211
|
+
});
|
|
1212
|
+
let digest;
|
|
1213
|
+
let logbookWake;
|
|
1214
|
+
let delivery;
|
|
1215
|
+
try {
|
|
1216
|
+
delivery = await provideSessionDeliveryService(context, {
|
|
1217
|
+
database: await sqlite.open(path.join(deliveryDirectory, `${agent.context.sessionId}.sqlite`), io),
|
|
1218
|
+
recipientKey: agent.context.sessionId,
|
|
1219
|
+
communication: peerCommunication,
|
|
1220
|
+
authorizePeer,
|
|
1221
|
+
admitPrompt: async (prompt, admission, requestId, metadata) => {
|
|
1222
|
+
if (metadata.logbook !== void 0) {
|
|
1223
|
+
if (metadata.logbook === "blocked" || metadata.logbook === "settled") logbookWake?.note();
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
if (metadata.lane === "queue") {
|
|
1227
|
+
digest?.note();
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
if (!metadata.customType) {
|
|
1231
|
+
await session.admitPrompt(prompt, admission, void 0, requestId);
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
if (!session.admitMessage) throw new Error("The session cannot admit a custom delivery.");
|
|
1235
|
+
await session.admitMessage({
|
|
1236
|
+
type: metadata.customType,
|
|
1237
|
+
text: prompt + workAnchor(),
|
|
1238
|
+
display: true,
|
|
1239
|
+
details: metadata.customDetails === void 0 ? void 0 : JSON.parse(metadata.customDetails)
|
|
1240
|
+
}, admission === "steer" ? "steer" : "followUp", requestId);
|
|
1241
|
+
},
|
|
1242
|
+
onUndeliverable: (entry, error) => {
|
|
1243
|
+
pluginContext.host.context.onNotice(`Session delivery ${entry.kind} from ${entry.senderKey} was not admitted: ${error instanceof Error ? error.message : String(error)}`);
|
|
1244
|
+
if (entry.kind === "session-undelivered" || entry.metadata.logbook !== void 0) return;
|
|
1245
|
+
const group = bridge?.metadataFor(agent.context.sessionId, entry.senderKey);
|
|
1246
|
+
delivery.service.deliver(undeliveredNotice(entry, communication.sessionName ?? agent.context.sessionId, group?.sourceReference ?? agent.context.sessionId, group)).catch((failure) => pluginContext.host.context.onNotice(`Undelivered notice failed: ${String(failure)}`));
|
|
1247
|
+
},
|
|
1248
|
+
onError: (error) => pluginContext.host.context.onNotice(`Session delivery failed: ${String(error)}`)
|
|
1249
|
+
});
|
|
1250
|
+
} catch (error) {
|
|
1251
|
+
await bridge?.removeLocal(agent.context.sessionId);
|
|
1252
|
+
throw error;
|
|
1253
|
+
}
|
|
1254
|
+
const { service, close: closeDelivery } = delivery;
|
|
1255
|
+
const inbox = createInboxDigest({
|
|
1256
|
+
delayMs: INBOX_DIGEST_DELAY_MS,
|
|
1257
|
+
delivery: service,
|
|
1258
|
+
sessionId: agent.context.sessionId,
|
|
1259
|
+
idle: async () => (await session.activity()).isIdle,
|
|
1260
|
+
authorized: (entry) => authorizePeer(entry.senderKey, entry.metadata),
|
|
1261
|
+
metadata: digestMetadata("Inbox"),
|
|
1262
|
+
onError: (error) => pluginContext.host.context.onNotice(`Inbox digest failed: ${String(error)}`)
|
|
1263
|
+
});
|
|
1264
|
+
digest = inbox;
|
|
1265
|
+
const settledInbox = agent.registerHook({
|
|
1266
|
+
event: "agent_settled",
|
|
1267
|
+
handle: async (event) => {
|
|
1268
|
+
if (event.aborted !== true) await inbox.settled();
|
|
1269
|
+
}
|
|
1270
|
+
});
|
|
1271
|
+
inbox.note();
|
|
1272
|
+
await rearmAskReminders(service, (text, requestId, details) => remindSession(agent, text, requestId, details), (error) => pluginContext.host.context.onNotice(`Ask reminder failed: ${String(error)}`));
|
|
1273
|
+
logbookWake = createLogbookWake({
|
|
1274
|
+
delayMs: LOGBOOK_WAKE_DELAY_MS,
|
|
1275
|
+
delivery: service,
|
|
1276
|
+
sessionId: agent.context.sessionId,
|
|
1277
|
+
peer: (sessionId) => communication.describePeer?.(sessionId),
|
|
1278
|
+
metadata: digestMetadata("Logbook"),
|
|
1279
|
+
onError: (error) => pluginContext.host.context.onNotice(`Logbook wake failed: ${String(error)}`)
|
|
1280
|
+
});
|
|
1281
|
+
logbookWake.note();
|
|
1282
|
+
const unprovide = [];
|
|
1283
|
+
if (groups && selfReference && peerConfig) {
|
|
1284
|
+
const directory = createSessionDirectory({ authorizeDiscovery: (_caller, subject) => {
|
|
1285
|
+
const reference = peerSessionReference(subject.hostId, subject.sessionId);
|
|
1286
|
+
return bridge?.peersFor(agent.context.sessionId).some((peer) => peer.sessionId === reference) ? { capabilities: ["message"] } : void 0;
|
|
1287
|
+
} });
|
|
1288
|
+
const observedHosts = /* @__PURE__ */ new Set();
|
|
1289
|
+
let sequence = 0;
|
|
1290
|
+
const observeRemote = () => {
|
|
1291
|
+
const remotePeers = bridge?.peersFor(agent.context.sessionId) ?? [];
|
|
1292
|
+
for (const peer of remotePeers) observedHosts.add(parseRemoteSessionReference(peer.sessionId).hostId);
|
|
1293
|
+
sequence += 1;
|
|
1294
|
+
for (const hostId of observedHosts) directory.replaceHostSnapshot(hostId, "linked", remotePeers.flatMap((peer) => {
|
|
1295
|
+
const remote = parseRemoteSessionReference(peer.sessionId);
|
|
1296
|
+
return remote.hostId !== hostId ? [] : [{
|
|
1297
|
+
hostId,
|
|
1298
|
+
sessionId: remote.sessionId,
|
|
1299
|
+
label: peer.name,
|
|
1300
|
+
hostIncarnation: "linked",
|
|
1301
|
+
sessionIncarnation: "live",
|
|
1302
|
+
sequence,
|
|
1303
|
+
observedAt: Date.now(),
|
|
1304
|
+
staleAfterMs: 12e4,
|
|
1305
|
+
deliveryTarget: peer.sessionId,
|
|
1306
|
+
reachability: "unknown",
|
|
1307
|
+
runtime: "unknown",
|
|
1308
|
+
activity: "unknown",
|
|
1309
|
+
voice: {
|
|
1310
|
+
eligible: "unknown",
|
|
1311
|
+
readiness: "unknown"
|
|
1312
|
+
}
|
|
1313
|
+
}];
|
|
1314
|
+
}));
|
|
1315
|
+
};
|
|
1316
|
+
observeRemote();
|
|
1317
|
+
unprovide.push(bridge.subscribe(() => {
|
|
1318
|
+
observeRemote();
|
|
1319
|
+
service.reauthorize?.().catch((error) => pluginContext.host.context.onNotice(`Delivery reauthorization failed: ${String(error)}`));
|
|
1320
|
+
}));
|
|
1321
|
+
unprovide.push(context.provide(PO_SESSION_INTERCOM_SERVICE, createSessionIntercom({
|
|
1322
|
+
selfReference,
|
|
1323
|
+
directory,
|
|
1324
|
+
groups,
|
|
1325
|
+
delivery: service
|
|
1326
|
+
})));
|
|
1327
|
+
}
|
|
1328
|
+
const releaseGroups = pluginContext.host.context.directEvents?.subscribe(PO_SESSION_ATTENTION_EVENT, agent.context.sessionId, () => {
|
|
1329
|
+
bridge?.updateLocal(agent.context.sessionId, communication.sessionName ?? agent.context.sessionId, communication.groups ?? []).catch((error) => pluginContext.host.context.onNotice(`Group update failed: ${String(error)}`));
|
|
1330
|
+
});
|
|
1331
|
+
const unregister = registerSessionPeerInbox(agent.context.sessionId, (sourceKey, kind, payload) => service.receive?.(sourceKey, kind, payload));
|
|
1332
|
+
return async () => {
|
|
1333
|
+
unregister();
|
|
1334
|
+
settledInbox.dispose();
|
|
1335
|
+
inbox.close();
|
|
1336
|
+
logbookWake?.close();
|
|
1337
|
+
releaseGroups?.();
|
|
1338
|
+
await bridge?.removeLocal(agent.context.sessionId);
|
|
1339
|
+
for (const release of unprovide.reverse()) release();
|
|
1340
|
+
await closeDelivery();
|
|
1341
|
+
};
|
|
1342
|
+
});
|
|
1343
|
+
},
|
|
1344
|
+
(owner) => {
|
|
1345
|
+
const sessionId = pluginContext.host.context.sessionId;
|
|
1346
|
+
if (sessionId === void 0) return;
|
|
1347
|
+
const lifetime = new AbortController();
|
|
1348
|
+
const binding = owner.inject([PO_SERVER_SCOPE_SERVICE], async (context) => {
|
|
1349
|
+
const scope = requirePoServerScope(context);
|
|
1350
|
+
const service = createAgentRunService({
|
|
1351
|
+
sessionId,
|
|
1352
|
+
cwd: pluginContext.host.context.cwd,
|
|
1353
|
+
sessions: pluginContext.host.context.sessionService,
|
|
1354
|
+
approvals: () => scope.resolve(APPROVAL_ROOT_SERVICE),
|
|
1355
|
+
lifetime: lifetime.signal,
|
|
1356
|
+
onError: (error) => pluginContext.host.context.onNotice(`Agent run cleanup failed: ${String(error)}`)
|
|
1357
|
+
});
|
|
1358
|
+
return await scope.provide(PO_AGENT_RUN_CONTRACT, service);
|
|
1359
|
+
});
|
|
1360
|
+
return async () => {
|
|
1361
|
+
lifetime.abort(/* @__PURE__ */ new Error("The session that started this agent run closed."));
|
|
1362
|
+
await binding.dispose();
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
]
|
|
1366
|
+
}));
|
|
1367
|
+
//#endregion
|
|
1368
|
+
//#region ../../foundations/po-session/src/extensions/workspaces/sessions/(backend)/contract/agentRun.server.ts
|
|
1369
|
+
var agentRun_server_default = defineServiceContract(PO_AGENT_RUN_CONTRACT.name, PO_AGENT_RUN_CONTRACT);
|
|
1370
|
+
//#endregion
|
|
1371
|
+
//#region ../../core/po-core/src/schemas/remoteOrigin.ts
|
|
1372
|
+
const PO_REMOTE_ORIGIN_SERVICE = "po/remote-origin";
|
|
1373
|
+
defineServiceContract(PO_REMOTE_ORIGIN_SERVICE, { scope: "host" });
|
|
1374
|
+
//#endregion
|
|
1375
|
+
//#region ../../foundations/po-session/src/services/peerInboxApi/index.ts
|
|
1376
|
+
const MAX_BODY_BYTES = 65536;
|
|
1377
|
+
const DELIVERY_TYPES = /* @__PURE__ */ new Set(["po/session-delivery/envelope", "po/session-delivery/ack"]);
|
|
1378
|
+
function response(status, error) {
|
|
1379
|
+
return Response.json({ error }, { status });
|
|
1380
|
+
}
|
|
1381
|
+
/** Narrow HMAC-authenticated endpoint that a trusted tunnel may forward without device authentication. */
|
|
1382
|
+
function createPeerInboxApi(platform) {
|
|
1383
|
+
return {
|
|
1384
|
+
basePath: "session-peer",
|
|
1385
|
+
start(context) {
|
|
1386
|
+
const homeDirectory = context.homeDirectory;
|
|
1387
|
+
let opened;
|
|
1388
|
+
const channels = createSealedPeerChannels();
|
|
1389
|
+
let link;
|
|
1390
|
+
let announcing = false;
|
|
1391
|
+
const announce = () => {
|
|
1392
|
+
if (!link || announcing) return;
|
|
1393
|
+
announcing = true;
|
|
1394
|
+
link.announce().catch((error) => context.onNotice(`Peer URL announcement failed: ${String(error)}`)).finally(() => {
|
|
1395
|
+
announcing = false;
|
|
1396
|
+
});
|
|
1397
|
+
};
|
|
1398
|
+
let linking = false;
|
|
1399
|
+
const autoLink = () => {
|
|
1400
|
+
if (!link || linking) return;
|
|
1401
|
+
linking = true;
|
|
1402
|
+
link.auto().catch((error) => context.onNotice(`Automatic host link failed: ${String(error)}`)).finally(() => {
|
|
1403
|
+
linking = false;
|
|
1404
|
+
});
|
|
1405
|
+
};
|
|
1406
|
+
const timer = platform.peers && platform.origin ? setInterval(() => {
|
|
1407
|
+
open().then(announce).catch((error) => context.onNotice(`Host links could not start: ${String(error)}`));
|
|
1408
|
+
}, 1e3) : void 0;
|
|
1409
|
+
timer?.unref?.();
|
|
1410
|
+
const autoTimer = platform.peers && platform.origin && platform.hosts ? setInterval(() => {
|
|
1411
|
+
open().then(autoLink).catch((error) => context.onNotice(`Host links could not start: ${String(error)}`));
|
|
1412
|
+
}, 6e4) : void 0;
|
|
1413
|
+
autoTimer?.unref?.();
|
|
1414
|
+
const open = () => opened ??= (async () => {
|
|
1415
|
+
if (homeDirectory === void 0) return {
|
|
1416
|
+
config: void 0,
|
|
1417
|
+
replay: void 0
|
|
1418
|
+
};
|
|
1419
|
+
const config = platform.peers ? platform.peers.current() : await readSessionPeerConfigAsync(platform.fs, homeDirectory, BACKGROUND_CONTEXT);
|
|
1420
|
+
const file = path.join(path.dirname(sessionPeerConfigPath(homeDirectory)), PEER_REPLAY_DATABASE_FILE);
|
|
1421
|
+
await ensurePrivateDirectory(platform.fs, path.dirname(file), BACKGROUND_CONTEXT);
|
|
1422
|
+
const replay = await createPeerReplayGuardAsync(await platform.sqlite.open(file, BACKGROUND_CONTEXT));
|
|
1423
|
+
if (platform.peers) link = createPeerLink({
|
|
1424
|
+
peers: platform.peers,
|
|
1425
|
+
network: platform.network,
|
|
1426
|
+
hosts: platform.hosts,
|
|
1427
|
+
groups: platform.groups,
|
|
1428
|
+
replay,
|
|
1429
|
+
channels,
|
|
1430
|
+
origin: platform.origin ?? (() => void 0),
|
|
1431
|
+
fetch: platform.fetch
|
|
1432
|
+
});
|
|
1433
|
+
announce();
|
|
1434
|
+
autoLink();
|
|
1435
|
+
return {
|
|
1436
|
+
config,
|
|
1437
|
+
replay
|
|
1438
|
+
};
|
|
1439
|
+
})().catch((error) => {
|
|
1440
|
+
opened = void 0;
|
|
1441
|
+
throw error;
|
|
1442
|
+
});
|
|
1443
|
+
if (platform.peers) open().catch((error) => context.onNotice(`Host links could not start: ${String(error)}`));
|
|
1444
|
+
return {
|
|
1445
|
+
async fetch(request) {
|
|
1446
|
+
const pathname = new URL(request.url).pathname;
|
|
1447
|
+
const openedState = await open();
|
|
1448
|
+
const config = platform.peers ? platform.peers.current() : openedState.config;
|
|
1449
|
+
const replay = openedState.replay;
|
|
1450
|
+
if (request.method === "GET" && pathname === "/links" && platform.peers) {
|
|
1451
|
+
if (!poApiCallerFrom(request.headers)) return response(403, "An authenticated caller is required.");
|
|
1452
|
+
return Response.json({
|
|
1453
|
+
hostId: config?.hostId,
|
|
1454
|
+
peers: config?.peers.map(({ hostId, url, urlGeneration }) => ({
|
|
1455
|
+
hostId,
|
|
1456
|
+
url,
|
|
1457
|
+
urlGeneration
|
|
1458
|
+
})) ?? []
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
if (request.method !== "POST" || ![
|
|
1462
|
+
"/inbox",
|
|
1463
|
+
"/control",
|
|
1464
|
+
"/link/prepare",
|
|
1465
|
+
"/link/accept",
|
|
1466
|
+
"/link/unlink",
|
|
1467
|
+
"/link/hint"
|
|
1468
|
+
].includes(pathname)) return response(404, "Not found.");
|
|
1469
|
+
const length = request.headers.get("content-length");
|
|
1470
|
+
if (length !== null && (!/^\d+$/u.test(length) || Number(length) > MAX_BODY_BYTES)) return response(413, "Request body is too large.");
|
|
1471
|
+
const body = await request.text();
|
|
1472
|
+
if (Buffer.byteLength(body) > MAX_BODY_BYTES) return response(413, "Request body is too large.");
|
|
1473
|
+
if (pathname.startsWith("/link/")) {
|
|
1474
|
+
const caller = poApiCallerFrom(request.headers);
|
|
1475
|
+
if (!caller || caller.locality === "remote" && pathname !== "/link/hint" && caller.stepUp !== "verified") return response(403, "Linking hosts needs a fresh peer.link step-up.");
|
|
1476
|
+
if (!link) return response(503, "Host links are unavailable.");
|
|
1477
|
+
try {
|
|
1478
|
+
const input = body === "" ? {} : JSON.parse(body);
|
|
1479
|
+
if (pathname === "/link/prepare") return Response.json(await link.prepare());
|
|
1480
|
+
if (pathname === "/link/accept") {
|
|
1481
|
+
await link.accept(input.invite);
|
|
1482
|
+
return Response.json({ linked: true });
|
|
1483
|
+
}
|
|
1484
|
+
if (typeof input.hostId !== "string") return response(400, "A host identity is required.");
|
|
1485
|
+
if (pathname === "/link/unlink") {
|
|
1486
|
+
await link.unlink(input.hostId);
|
|
1487
|
+
return Response.json({ unlinked: true });
|
|
1488
|
+
}
|
|
1489
|
+
if (typeof input.url !== "string") return response(400, "A URL hint is required.");
|
|
1490
|
+
return Response.json({ rebound: await link.hint(input.hostId, input.url) });
|
|
1491
|
+
} catch (error) {
|
|
1492
|
+
return response(400, error instanceof Error ? error.message : "Host link failed.");
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
if (pathname === "/control") {
|
|
1496
|
+
if (!link) return response(503, "Host links are unavailable.");
|
|
1497
|
+
try {
|
|
1498
|
+
return await link.control(request, body);
|
|
1499
|
+
} catch (error) {
|
|
1500
|
+
return response(400, error instanceof Error ? error.message : "Invalid peer control.");
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
if (!config) return response(503, "Paired Session delivery is not configured.");
|
|
1504
|
+
const peer = verifyPeerRequest(config, request, body);
|
|
1505
|
+
if (!peer) return response(401, "Paired Session request is unauthorized.");
|
|
1506
|
+
if (!await replay?.admit(request)) return response(409, "Paired Session request was already received.");
|
|
1507
|
+
let parsed;
|
|
1508
|
+
try {
|
|
1509
|
+
parsed = JSON.parse(body);
|
|
1510
|
+
} catch {
|
|
1511
|
+
return response(400, "Paired Session request is malformed.");
|
|
1512
|
+
}
|
|
1513
|
+
let peerChannel;
|
|
1514
|
+
if (peer.linkGeneration) {
|
|
1515
|
+
const sealed = parsed;
|
|
1516
|
+
peerChannel = typeof sealed?.epochId === "string" ? channels.take(peer, sealed.epochId) : void 0;
|
|
1517
|
+
const opened = peerChannel?.open(sealed?.envelope);
|
|
1518
|
+
if (!opened?.ok) return response(401, "A fresh sealed peer channel is required.");
|
|
1519
|
+
try {
|
|
1520
|
+
parsed = JSON.parse(Buffer.from(opened.plaintext).toString("utf8"));
|
|
1521
|
+
} catch {
|
|
1522
|
+
return response(400, "Invalid sealed peer envelope.");
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
const envelope = parseSessionPeerEnvelope(parsed);
|
|
1526
|
+
if (!envelope || !DELIVERY_TYPES.has(envelope.type)) return response(400, "Paired Session envelope is invalid.");
|
|
1527
|
+
if (!peer.linkGeneration && !peer.allowedSessionIds.includes(envelope.targetSessionId)) return response(403, "Peer is not granted this session.");
|
|
1528
|
+
const state = await deliverSessionPeerEnvelope(envelope.targetSessionId, peerSessionReference(peer.hostId, envelope.sourceSessionId), envelope.type, envelope.payload);
|
|
1529
|
+
if (state !== void 0 && peerChannel) {
|
|
1530
|
+
const sealed = peerChannel.seal(Buffer.from(JSON.stringify({
|
|
1531
|
+
accepted: true,
|
|
1532
|
+
state
|
|
1533
|
+
})));
|
|
1534
|
+
if (!sealed.ok) return response(503, "Peer acknowledgement could not be sealed.");
|
|
1535
|
+
const text = JSON.stringify(sealed.envelope);
|
|
1536
|
+
return new Response(text, { headers: peerRequestHeaders(config.hostId, peer, "RESPONSE", "/inbox", text) });
|
|
1537
|
+
}
|
|
1538
|
+
return state === void 0 ? response(404, "Target Session is unavailable.") : Response.json({
|
|
1539
|
+
accepted: true,
|
|
1540
|
+
state
|
|
1541
|
+
}, { status: 202 });
|
|
1542
|
+
},
|
|
1543
|
+
async close() {
|
|
1544
|
+
if (timer) clearInterval(timer);
|
|
1545
|
+
if (autoTimer) clearInterval(autoTimer);
|
|
1546
|
+
const state = await opened?.catch(() => void 0);
|
|
1547
|
+
link?.close();
|
|
1548
|
+
await state?.replay?.close();
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
//#endregion
|
|
1555
|
+
//#region ../../foundations/po-session/src/extensions/(backend)/api/session-peer/route.server.ts
|
|
1556
|
+
var route_server_default = defineRoute(({ context }) => {
|
|
1557
|
+
let origin;
|
|
1558
|
+
let network;
|
|
1559
|
+
let hosts;
|
|
1560
|
+
context.inject(["po/host-requests"], (scoped) => {
|
|
1561
|
+
hosts = scoped.get("po/host-requests");
|
|
1562
|
+
return () => {
|
|
1563
|
+
hosts = void 0;
|
|
1564
|
+
};
|
|
1565
|
+
});
|
|
1566
|
+
context.inject([PO_ROSTER_PEER_SERVICE], (scoped) => {
|
|
1567
|
+
network = scoped.get(PO_ROSTER_PEER_SERVICE);
|
|
1568
|
+
return () => {
|
|
1569
|
+
network = void 0;
|
|
1570
|
+
};
|
|
1571
|
+
});
|
|
1572
|
+
context.inject([PO_REMOTE_ORIGIN_SERVICE], (scoped) => {
|
|
1573
|
+
origin = scoped.get(PO_REMOTE_ORIGIN_SERVICE);
|
|
1574
|
+
return () => {
|
|
1575
|
+
origin = void 0;
|
|
1576
|
+
};
|
|
1577
|
+
});
|
|
1578
|
+
const hasOrigin = origin !== void 0;
|
|
1579
|
+
return createPeerInboxApi({
|
|
1580
|
+
fs: requirePoFs(context),
|
|
1581
|
+
sqlite: requirePoSqlite(context),
|
|
1582
|
+
peers: requireSessionPeers(context),
|
|
1583
|
+
network,
|
|
1584
|
+
hosts: () => hosts,
|
|
1585
|
+
groups: () => readSessionGroupBridge(context),
|
|
1586
|
+
...hasOrigin ? { origin: () => origin?.current() } : {}
|
|
1587
|
+
});
|
|
1588
|
+
});
|
|
1589
|
+
//#endregion
|
|
1590
|
+
//#region ../../foundations/po-session/src/schemas/sendToSession.ts
|
|
1591
|
+
/** The person's own words, steered into another live session and shown there as "From you, via <from>". */
|
|
1592
|
+
const sendToSessionMethod = definePoPluginMethod({
|
|
1593
|
+
service: "sessions",
|
|
1594
|
+
method: "sendToSession",
|
|
1595
|
+
scope: "host",
|
|
1596
|
+
direction: "client-to-server",
|
|
1597
|
+
input: _Object_({
|
|
1598
|
+
/** The session whose composer the person typed in; it names the message, nothing more. */
|
|
1599
|
+
from: String$1({ minLength: 1 }),
|
|
1600
|
+
to: String$1({ minLength: 1 }),
|
|
1601
|
+
text: String$1({
|
|
1602
|
+
minLength: 1,
|
|
1603
|
+
maxLength: 1e5
|
|
1604
|
+
})
|
|
1605
|
+
}, { additionalProperties: false }),
|
|
1606
|
+
output: _Object_({
|
|
1607
|
+
to: String$1(),
|
|
1608
|
+
name: String$1()
|
|
1609
|
+
})
|
|
1610
|
+
});
|
|
1611
|
+
//#endregion
|
|
1612
|
+
//#region ../../foundations/po-session/src/extensions/(backend)/_lib/sendToSession.server.ts
|
|
1613
|
+
/**
|
|
1614
|
+
* Steers the person's text into another live session, attributed to them. Each refusal reads as the
|
|
1615
|
+
* reason the dialog shows, because the text stays there for another try.
|
|
1616
|
+
*/
|
|
1617
|
+
async function sendToSession(service, input) {
|
|
1618
|
+
const text = input.text.trim();
|
|
1619
|
+
if (text === "") throw new Error("Write something to send.");
|
|
1620
|
+
if (input.to === input.from) throw new Error("That is this session. Pick another one.");
|
|
1621
|
+
if (!service?.steer || !service.scopes) throw new Error("This host cannot deliver to another session.");
|
|
1622
|
+
const scopes = service.scopes();
|
|
1623
|
+
const target = scopes.find((scope) => scope.sessionId === input.to);
|
|
1624
|
+
if (target === void 0) throw new Error("That session is not running. Open it to wake it, then send again.");
|
|
1625
|
+
const name = target.name?.trim() || input.to;
|
|
1626
|
+
const via = scopes.find((scope) => scope.sessionId === input.from)?.name?.trim() || "another session";
|
|
1627
|
+
try {
|
|
1628
|
+
await service.steer(input.to, {
|
|
1629
|
+
text,
|
|
1630
|
+
sender: {
|
|
1631
|
+
kind: "human",
|
|
1632
|
+
name: `From you, via ${via}`
|
|
1633
|
+
}
|
|
1634
|
+
});
|
|
1635
|
+
} catch (error) {
|
|
1636
|
+
throw new Error(`${name} could not take the message: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
1637
|
+
}
|
|
1638
|
+
return {
|
|
1639
|
+
to: input.to,
|
|
1640
|
+
name
|
|
1641
|
+
};
|
|
1642
|
+
}
|
|
1643
|
+
//#endregion
|
|
1644
|
+
//#region ../../foundations/po-session/src/extensions/(backend)/method/send-to-session.server.ts
|
|
1645
|
+
var send_to_session_server_default = defineRoutedContribution(({ host }) => host.scope === "host" ? defineServerMethod(sendToSessionMethod, (input) => sendToSession(host.context.sessionService, input)) : void 0, { cardinality: "optional" });
|
|
1646
|
+
//#endregion
|
|
1647
|
+
//#region ../../foundations/po-session/src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-network.server.ts
|
|
1648
|
+
var codemode_how_to_network_server_default = defineResource({
|
|
1649
|
+
name: "codemode-how-to-network",
|
|
1650
|
+
description: "Message sessions on this host and on linked hosts through the network namespace: send, ask with a tracked reply, and answer questions. Use for any message to another session.",
|
|
1651
|
+
kind: "skill",
|
|
1652
|
+
pinned: true,
|
|
1653
|
+
path: packageResourcePath("bundle:///po-session/src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-network.server.ts", "src/prompts/codemode-how-to-network/SKILL.md"),
|
|
1654
|
+
read: () => readPackageResource("bundle:///po-session/src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-network.server.ts", "src/prompts/codemode-how-to-network/SKILL.md")
|
|
1655
|
+
});
|
|
1656
|
+
//#endregion
|
|
1657
|
+
//#region ../../foundations/po-session/src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-session.server.ts
|
|
1658
|
+
var codemode_how_to_session_server_default = defineResource({
|
|
1659
|
+
name: "codemode-how-to-session",
|
|
1660
|
+
description: "List related sessions and start briefed independent work as a coordinator through the sessions namespace. No stop or delete capability.",
|
|
1661
|
+
kind: "skill",
|
|
1662
|
+
pinned: true,
|
|
1663
|
+
path: packageResourcePath("bundle:///po-session/src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-session.server.ts", "src/prompts/codemode-how-to-session/SKILL.md"),
|
|
1664
|
+
read: () => readPackageResource("bundle:///po-session/src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-session.server.ts", "src/prompts/codemode-how-to-session/SKILL.md")
|
|
1665
|
+
});
|
|
1666
|
+
//#endregion
|
|
1667
|
+
//#region ../../foundations/po-session/generated/server.ts
|
|
1668
|
+
const at = (value, context) => typeof value === "function" ? value(context) : value;
|
|
1669
|
+
/* v8 ignore next -- generated normalization branch */
|
|
1670
|
+
const defined = (values) => values.filter((value) => value !== void 0);
|
|
1671
|
+
const serverPlugin = defineServerPlugin({
|
|
1672
|
+
name: "@agimon-ai/po-session",
|
|
1673
|
+
providerOverrides: composeServerProviderOverrides(root_server_default$1, root_server_default),
|
|
1674
|
+
provides: { session: [agentRun_server_default] },
|
|
1675
|
+
injects: composeRootInjects({
|
|
1676
|
+
host: [root_server_default$1],
|
|
1677
|
+
workspace: [root_server_default$1],
|
|
1678
|
+
session: [root_server_default$1, root_server_default]
|
|
1679
|
+
}),
|
|
1680
|
+
host: async (context) => {
|
|
1681
|
+
const scopeHost = await context.scopeRoot("host", root_server_default$1, context);
|
|
1682
|
+
const contextHost = {
|
|
1683
|
+
...context,
|
|
1684
|
+
root: scopeHost.value
|
|
1685
|
+
};
|
|
1686
|
+
return {
|
|
1687
|
+
...composeRootHooks(scopeHost),
|
|
1688
|
+
get api() {
|
|
1689
|
+
return [at(route_server_default, contextHost)];
|
|
1690
|
+
},
|
|
1691
|
+
get methods() {
|
|
1692
|
+
return defined([at(send_to_session_server_default, contextHost)]);
|
|
1693
|
+
},
|
|
1694
|
+
services: [...scopeHost.services ?? []]
|
|
1695
|
+
};
|
|
1696
|
+
},
|
|
1697
|
+
workspace: async (context) => {
|
|
1698
|
+
const scopeHost = await context.scopeRoot("host", root_server_default$1, context);
|
|
1699
|
+
const contextHost = {
|
|
1700
|
+
...context,
|
|
1701
|
+
root: scopeHost.value
|
|
1702
|
+
};
|
|
1703
|
+
return {
|
|
1704
|
+
...composeRootHooks(scopeHost),
|
|
1705
|
+
get api() {
|
|
1706
|
+
return defined([context.hosted("host") ? void 0 : at(route_server_default, contextHost)]);
|
|
1707
|
+
},
|
|
1708
|
+
get methods() {
|
|
1709
|
+
return defined([context.hosted("host") ? void 0 : at(send_to_session_server_default, contextHost)]);
|
|
1710
|
+
},
|
|
1711
|
+
services: [...scopeHost.services ?? []]
|
|
1712
|
+
};
|
|
1713
|
+
},
|
|
1714
|
+
session: async (context) => {
|
|
1715
|
+
const scopeHost = await context.scopeRoot("host", root_server_default$1, context);
|
|
1716
|
+
const contextHost = {
|
|
1717
|
+
...context,
|
|
1718
|
+
root: scopeHost.value
|
|
1719
|
+
};
|
|
1720
|
+
const scopeSession = await context.scopeRoot("session", root_server_default, contextHost);
|
|
1721
|
+
const contextSession = {
|
|
1722
|
+
...contextHost,
|
|
1723
|
+
root: scopeSession.value
|
|
1724
|
+
};
|
|
1725
|
+
return {
|
|
1726
|
+
...composeRootHooks(scopeHost, scopeSession),
|
|
1727
|
+
get api() {
|
|
1728
|
+
return defined([context.hosted("host") ? void 0 : at(route_server_default, contextHost)]);
|
|
1729
|
+
},
|
|
1730
|
+
get methods() {
|
|
1731
|
+
return defined([context.hosted("host") ? void 0 : at(send_to_session_server_default, contextHost)]);
|
|
1732
|
+
},
|
|
1733
|
+
get resources() {
|
|
1734
|
+
return [at(codemode_how_to_network_server_default, contextSession), at(codemode_how_to_session_server_default, contextSession)];
|
|
1735
|
+
},
|
|
1736
|
+
services: [...scopeHost.services ?? [], ...scopeSession.services ?? []],
|
|
1737
|
+
get activities() {
|
|
1738
|
+
return [...scopeHost.activities ?? [], ...scopeSession.activities ?? []];
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1743
|
+
//#endregion
|
|
1744
|
+
export { serverPlugin as default, serverPlugin };
|