@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,1884 @@
|
|
|
1
|
+
import { $t as Boolean, Dt as defineServerMethod, Et as composeServerProviderOverrides, Gt as Record, It as readPoFs, Jt as String$1, V as Check, Zt as Literal, _t as BACKGROUND_CONTEXT, an as _Array_, cn as readPoServerScope, in as Optional, ln as requirePoServerScope, nn as Unknown, on as PO_SERVER_SCOPE_SERVICE, qt as Union, rn as _Object_, sn as defineServiceContract, t as defineServerPlugin, tt as PO_HEADLESS_HOST_SERVICE } from "./serverPlugin-4nI5J6Zt.js";
|
|
2
|
+
import { A as isSecretValue, B as mcpToolApproval, C as PO_MCP_REMOTE_SERVERS_CONTRACT, D as connectRemoteMcpServers, E as REMOTE_MCP_TIMEOUT_MS, F as isAppVisibleMcpTool, H as StreamableHTTPClientTransport, I as isModelVisibleMcpTool, L as normalizeMcpAppMetadata, M as writeSecrets, N as USER_MCP_SCOPE, O as isUnauthorized, P as modelInputSchema, R as createMcpApprovalState, S as createMcpHostSettings, T as REMOTE_MCP_MAX_BYTES, V as Client, _ as MCP_FLOW_ID_PARAM, a as parseMcpServerAddition, b as SERVER_COMMAND_DESCRIPTION, c as handleSettings, d as json, f as mcpScopeFromWire, g as routes, gi as outboundHostRefusal, hi as guardedFetch, i as mutateMcpServer, j as prepareSecretAddition, k as readPoMcpRemoteServers, l as isRecord, m as userConfigPath, mi as OutboundRefusedError, n as listManagedMcpServers, p as serverNameOf, s as bodyOf, t as addMcpServer, u as isVaultUnavailable, v as mcpScopeToWire, w as PO_MCP_REMOTE_SERVERS_SERVICE, x as VAULT_UNAVAILABLE$1, y as MCP_APP_CLIENT_CAPABILITIES, z as isDestructiveMcpTool } from "./exports-BEEgtkya.js";
|
|
3
|
+
import { f as readTextIfExists, h as writeFileAtomic } from "./platform-CQahdzpG.js";
|
|
4
|
+
import { n as readPackageResource, t as packageResourcePath } from "./index.edge-BiVQ9LoZ.js";
|
|
5
|
+
import { i as definePoPluginMethod } from "./pluginProtocol-DVIfJnav.js";
|
|
6
|
+
import { c as defineRoot, d as defineServerCommand, f as defineServerTool, l as defineRoute, n as composeRootInjects, s as defineResource, t as composeRootHooks, u as defineRoutedContribution } from "./extensionFile-B940JOEn.js";
|
|
7
|
+
import "./pluginProtocol-7_gVUeM9.js";
|
|
8
|
+
import { i as readPoCodemode, n as PO_CODEMODE_SERVICE } from "./codemode-LpcMFMYM.js";
|
|
9
|
+
import { t as PO_HELP_WHEN } from "./help-C9UGKetC.js";
|
|
10
|
+
import { t as PO_VAULT_CONTRACT } from "./contracts-WRa9e98H.js";
|
|
11
|
+
//#region ../../default/po-mcp/src/services/mcpHostServers/index.ts
|
|
12
|
+
/** The parsed file, `undefined` when it does not exist, or `null` when it is not JSON. Any other read failure throws. */
|
|
13
|
+
async function readDocument(fs, filePath) {
|
|
14
|
+
const text = await readTextIfExists(fs, filePath, BACKGROUND_CONTEXT);
|
|
15
|
+
if (text === void 0) return { document: void 0 };
|
|
16
|
+
try {
|
|
17
|
+
return { document: JSON.parse(text) };
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const notJson = (fileLabel) => ({
|
|
23
|
+
ok: false,
|
|
24
|
+
status: 409,
|
|
25
|
+
error: `${fileLabel} isn't valid JSON, so Po left it alone.`
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* The personal server list over the host's own filesystem, so it runs wherever Po has a `po/fs`.
|
|
29
|
+
* It is the file half of the Node settings manager's host scope: the same checks and the same
|
|
30
|
+
* add, edit and remove rules, without repositories, plugins or any process to run.
|
|
31
|
+
*/
|
|
32
|
+
function createMcpHostServers(options) {
|
|
33
|
+
let writes = Promise.resolve();
|
|
34
|
+
const requireFs = () => {
|
|
35
|
+
const fs = options.fs();
|
|
36
|
+
if (!fs) throw new Error("MCP settings need the host filesystem.");
|
|
37
|
+
return fs;
|
|
38
|
+
};
|
|
39
|
+
const queued = (work) => {
|
|
40
|
+
const run = writes.then(work);
|
|
41
|
+
writes = run.catch(() => void 0);
|
|
42
|
+
return run;
|
|
43
|
+
};
|
|
44
|
+
const save = (fs, filePath, document) => writeFileAtomic(fs, filePath, `${JSON.stringify(document, null, 2)}\n`, BACKGROUND_CONTEXT);
|
|
45
|
+
return {
|
|
46
|
+
async list(filePath, fileLabel) {
|
|
47
|
+
const read = await readDocument(requireFs(), filePath);
|
|
48
|
+
if (read === null) return {
|
|
49
|
+
ok: false,
|
|
50
|
+
status: 409,
|
|
51
|
+
error: `${fileLabel} isn't valid JSON.`
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
ok: true,
|
|
55
|
+
value: listManagedMcpServers(read.document)
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
add(filePath, fileLabel, addition, secrets) {
|
|
59
|
+
return queued(async () => {
|
|
60
|
+
const fs = requireFs();
|
|
61
|
+
const read = await readDocument(fs, filePath);
|
|
62
|
+
if (read === null) return notJson(fileLabel);
|
|
63
|
+
const next = addMcpServer(read.document, addition, fileLabel);
|
|
64
|
+
if (!next.ok) return next;
|
|
65
|
+
let rollback;
|
|
66
|
+
if (secrets && secrets.writes.length > 0) {
|
|
67
|
+
const vault = options.vault();
|
|
68
|
+
if (!vault) throw new Error(VAULT_UNAVAILABLE$1);
|
|
69
|
+
rollback = await writeSecrets(vault, secrets.scope, secrets.writes);
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
await save(fs, filePath, next.value);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
await rollback?.();
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
ok: true,
|
|
79
|
+
value: void 0
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
mutate(filePath, fileLabel, name, revision, addition) {
|
|
84
|
+
return queued(async () => {
|
|
85
|
+
const fs = requireFs();
|
|
86
|
+
const read = await readDocument(fs, filePath);
|
|
87
|
+
if (read === null) return notJson(fileLabel);
|
|
88
|
+
const next = mutateMcpServer(read.document, name, revision, addition);
|
|
89
|
+
if (!next.ok) return next;
|
|
90
|
+
await save(fs, filePath, next.value);
|
|
91
|
+
return {
|
|
92
|
+
ok: true,
|
|
93
|
+
value: addition ? "none" : "possible"
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region ../../default/po-mcp/src/services/mcpHostHubApi/index.ts
|
|
101
|
+
const USER_CONFIG_LABEL = "your personal MCP config";
|
|
102
|
+
const NO_HOME = "Po couldn't find your home directory on this hub.";
|
|
103
|
+
const REPOSITORY_UNAVAILABLE = "Repository MCP management is not available on this host. Manage your own servers instead.";
|
|
104
|
+
const LOCAL_UNAVAILABLE = "Local command servers cannot run on this host. Add a remote server by URL instead.";
|
|
105
|
+
const MUTATION_FIELDS = /* @__PURE__ */ new Set([
|
|
106
|
+
"scope",
|
|
107
|
+
"repositoryId",
|
|
108
|
+
"target",
|
|
109
|
+
"name",
|
|
110
|
+
"revision",
|
|
111
|
+
"entry",
|
|
112
|
+
"trusted"
|
|
113
|
+
]);
|
|
114
|
+
const REVISION = /^[a-f0-9]{64}$/u;
|
|
115
|
+
const AUTHORIZATION_FLOW_PREFIX = routes.readAuthorization.path.replace(`:${MCP_FLOW_ID_PARAM}`, "");
|
|
116
|
+
/** A server entry that runs a command, which a host without processes cannot start. */
|
|
117
|
+
function isLocalEntry(entry) {
|
|
118
|
+
return isRecord(entry) && "command" in entry;
|
|
119
|
+
}
|
|
120
|
+
async function handleAddServer(servers, request, context) {
|
|
121
|
+
const body = await bodyOf(request);
|
|
122
|
+
if (body?.scope === "global") return json({ error: "The 'global' scope was renamed to 'host'. Update this client." }, 400);
|
|
123
|
+
const scope = mcpScopeFromWire(body?.scope);
|
|
124
|
+
if (!body || !scope) return json({ error: "Choose where to add the server." }, 400);
|
|
125
|
+
if (scope === "repository") return json({ error: REPOSITORY_UNAVAILABLE }, 501);
|
|
126
|
+
if (isLocalEntry(body.entry)) return json({ error: LOCAL_UNAVAILABLE }, 501);
|
|
127
|
+
const addition = parseMcpServerAddition(body.name, body.entry, body.trusted);
|
|
128
|
+
if (!addition.ok) return json({ error: addition.error }, addition.status);
|
|
129
|
+
const prepared = prepareSecretAddition(addition.value, body.secretFields);
|
|
130
|
+
if (!prepared.ok) return json({ error: prepared.error }, prepared.status);
|
|
131
|
+
if (body.target !== void 0) return json({ error: "Choose this workspace or one of its plugins." }, 400);
|
|
132
|
+
const filePath = userConfigPath(context);
|
|
133
|
+
if (!filePath) return json({ error: NO_HOME }, 503);
|
|
134
|
+
const { secrets } = prepared.value;
|
|
135
|
+
try {
|
|
136
|
+
const result = await servers.add(filePath, USER_CONFIG_LABEL, prepared.value.addition, secrets.length === 0 ? void 0 : {
|
|
137
|
+
scope: USER_MCP_SCOPE,
|
|
138
|
+
writes: secrets
|
|
139
|
+
});
|
|
140
|
+
return result.ok ? json({
|
|
141
|
+
scope: mcpScopeToWire("host"),
|
|
142
|
+
name: addition.value.name
|
|
143
|
+
}, 201) : json({ error: result.error }, result.status);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (isVaultUnavailable(error)) return json({ error: VAULT_UNAVAILABLE$1 }, 503);
|
|
146
|
+
return json({ error: `Po couldn't save ${USER_CONFIG_LABEL}.` }, 500);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async function handleMutateServer(servers, request, context) {
|
|
150
|
+
const body = await bodyOf(request);
|
|
151
|
+
if (body?.scope === "global") return json({ error: "The 'global' scope was renamed to 'host'. Update this client." }, 400);
|
|
152
|
+
const scope = mcpScopeFromWire(body?.scope);
|
|
153
|
+
if (!body || Object.keys(body).some((key) => !MUTATION_FIELDS.has(key)) || !scope || typeof body.revision !== "string" || !REVISION.test(body.revision)) return json({ error: "A saved scope, name and current revision are required." }, 400);
|
|
154
|
+
const name = serverNameOf(body.name);
|
|
155
|
+
if (!name) return json({ error: "A valid name is required." }, 400);
|
|
156
|
+
if (scope === "repository" || body.repositoryId !== void 0) return json({ error: REPOSITORY_UNAVAILABLE }, 501);
|
|
157
|
+
if (body.target !== void 0) return json({ error: "A saved scope, name and current revision are required." }, 400);
|
|
158
|
+
const editing = request.method === routes.editServer.method;
|
|
159
|
+
if (editing && isLocalEntry(body.entry)) return json({ error: LOCAL_UNAVAILABLE }, 501);
|
|
160
|
+
const parsed = editing ? parseMcpServerAddition(name, body.entry, body.trusted) : void 0;
|
|
161
|
+
if (parsed && !parsed.ok) return json({ error: parsed.error }, parsed.status);
|
|
162
|
+
if (!editing && body.entry !== void 0) return json({ error: "Remove does not accept an entry." }, 400);
|
|
163
|
+
const filePath = userConfigPath(context);
|
|
164
|
+
if (!filePath) return json({ error: NO_HOME }, 503);
|
|
165
|
+
try {
|
|
166
|
+
const result = await servers.mutate(filePath, USER_CONFIG_LABEL, name, body.revision, parsed?.ok ? parsed.value : void 0);
|
|
167
|
+
if (!result.ok) return json({ error: result.error }, result.status);
|
|
168
|
+
return json({
|
|
169
|
+
scope: mcpScopeToWire("host"),
|
|
170
|
+
name,
|
|
171
|
+
credentialsPreserved: true,
|
|
172
|
+
liveSessionsChanged: false,
|
|
173
|
+
syncRequired: false,
|
|
174
|
+
shadowedDefinition: result.value
|
|
175
|
+
});
|
|
176
|
+
} catch {
|
|
177
|
+
return json({ error: `Po couldn't save ${USER_CONFIG_LABEL}.` }, 500);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async function handleHostServers(servers, context) {
|
|
181
|
+
const filePath = userConfigPath(context);
|
|
182
|
+
if (!filePath) return json({ error: NO_HOME }, 503);
|
|
183
|
+
try {
|
|
184
|
+
const result = await servers.list(filePath, USER_CONFIG_LABEL);
|
|
185
|
+
return result.ok ? json({ servers: result.value }) : json({ error: result.error }, result.status);
|
|
186
|
+
} catch {
|
|
187
|
+
return json({ error: `Po couldn't read ${USER_CONFIG_LABEL}.` }, 500);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/** Catalogs, discovery and sign-in need a repository checkout and local processes; this host has neither. */
|
|
191
|
+
function isRepositoryRoute(request, path) {
|
|
192
|
+
const flow = request.method === routes.readAuthorization.method || request.method === routes.cancelAuthorization.method;
|
|
193
|
+
return [
|
|
194
|
+
routes.catalog,
|
|
195
|
+
routes.discover,
|
|
196
|
+
routes.authorize
|
|
197
|
+
].some((route) => request.method === route.method && path === route.path) || flow && path.startsWith(AUTHORIZATION_FLOW_PREFIX);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* The hub's MCP settings API for a host that has a filesystem but no repository checkout and no processes:
|
|
201
|
+
* approval, and the person's own remote servers. A repository route, or a command server, is answered 501,
|
|
202
|
+
* so the settings page says what this host cannot do instead of showing an empty catalog.
|
|
203
|
+
*/
|
|
204
|
+
function createMcpHostHubApi(options) {
|
|
205
|
+
const servers = createMcpHostServers({
|
|
206
|
+
fs: options.fs,
|
|
207
|
+
vault: options.vault
|
|
208
|
+
});
|
|
209
|
+
return {
|
|
210
|
+
basePath: "mcp",
|
|
211
|
+
start(context) {
|
|
212
|
+
return {
|
|
213
|
+
async fetch(request) {
|
|
214
|
+
const path = new URL(request.url).pathname;
|
|
215
|
+
if (request.method === routes.hostServers.method && path === routes.hostServers.path) return await handleHostServers(servers, context);
|
|
216
|
+
if ((request.method === routes.readSettings.method || request.method === routes.saveSettings.method) && path === routes.readSettings.path) return await handleSettings(options.settings, request, context);
|
|
217
|
+
if (request.method === routes.addServer.method && path === routes.addServer.path) return await handleAddServer(servers, request, context);
|
|
218
|
+
if ((request.method === routes.editServer.method || request.method === routes.removeServer.method) && path === routes.editServer.path) return await handleMutateServer(servers, request, context);
|
|
219
|
+
if (isRepositoryRoute(request, path)) return json({ error: REPOSITORY_UNAVAILABLE }, 501);
|
|
220
|
+
return json({ error: "Not found." }, 404);
|
|
221
|
+
},
|
|
222
|
+
close: () => void 0
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region ../../default/po-mcp/src/extensions/(backend)/_lib/root.server.edge.ts
|
|
229
|
+
/**
|
|
230
|
+
* Builds the hub MCP settings API at the host and workspace levels, reaching the vault through
|
|
231
|
+
* the server scope. The vault is resolved per request rather than injected, so a host without
|
|
232
|
+
* `po/vault` still mounts the API and answers 503 where a credential is needed.
|
|
233
|
+
*/
|
|
234
|
+
async function createMcpHostRoot(plugin) {
|
|
235
|
+
const settings = createMcpHostSettings(() => readPoFs(plugin.context));
|
|
236
|
+
if (plugin.host.scope === "session") return { value: {
|
|
237
|
+
hubApi: void 0,
|
|
238
|
+
settings
|
|
239
|
+
} };
|
|
240
|
+
let scope;
|
|
241
|
+
const fiber = plugin.context.inject([PO_SERVER_SCOPE_SERVICE], (injected) => {
|
|
242
|
+
scope = requirePoServerScope(injected);
|
|
243
|
+
return () => {
|
|
244
|
+
scope = void 0;
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
await fiber.await();
|
|
248
|
+
return {
|
|
249
|
+
value: {
|
|
250
|
+
hubApi: createMcpHostHubApi({
|
|
251
|
+
fs: () => readPoFs(plugin.context),
|
|
252
|
+
vault: () => scope?.resolve(PO_VAULT_CONTRACT),
|
|
253
|
+
settings
|
|
254
|
+
}),
|
|
255
|
+
settings
|
|
256
|
+
},
|
|
257
|
+
onDispose: async () => {
|
|
258
|
+
await fiber.dispose();
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region ../../default/po-mcp/src/extensions/(backend)/root.server.ts
|
|
264
|
+
var root_server_default$1 = defineRoot(createMcpHostRoot);
|
|
265
|
+
defineServiceContract("po/mcp", { scope: "session" });
|
|
266
|
+
const PO_MCP_CONNECTIONS_CONTRACT = defineServiceContract("po/mcp-connections", { scope: "session" });
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region ../../default/po-mcp/src/schemas/mcpTestServer.ts
|
|
269
|
+
const Name = String$1({ pattern: "^[A-Za-z0-9_-]{1,64}$" });
|
|
270
|
+
const McpTestServerInput = _Object_({
|
|
271
|
+
name: Name,
|
|
272
|
+
url: String$1({ minLength: 1 }),
|
|
273
|
+
type: Optional(Union([Literal("http"), Literal("sse")])),
|
|
274
|
+
headers: Optional(Record(String$1(), String$1())),
|
|
275
|
+
oauth: Optional(_Object_({
|
|
276
|
+
clientId: Optional(String$1()),
|
|
277
|
+
clientSecret: Optional(String$1()),
|
|
278
|
+
scope: Optional(String$1()),
|
|
279
|
+
clientName: Optional(String$1())
|
|
280
|
+
}, { additionalProperties: false }))
|
|
281
|
+
}, { additionalProperties: false });
|
|
282
|
+
const KeySource = [{ value: String$1({
|
|
283
|
+
minLength: 1,
|
|
284
|
+
maxLength: 8192,
|
|
285
|
+
pattern: "^[\\x21-\\x7e\\x80-\\xff]+$"
|
|
286
|
+
}) }, { environmentVariable: String$1({ pattern: "^[A-Za-z_][A-Za-z0-9_]*$" }) }];
|
|
287
|
+
const McpSessionServerRegistration = _Object_({
|
|
288
|
+
name: Name,
|
|
289
|
+
url: String$1({ minLength: 1 }),
|
|
290
|
+
type: Optional(Union([Literal("http"), Literal("sse")])),
|
|
291
|
+
apiKey: Union(KeySource.flatMap((source) => [_Object_({
|
|
292
|
+
...source,
|
|
293
|
+
mode: Literal("bearer")
|
|
294
|
+
}, { additionalProperties: false }), _Object_({
|
|
295
|
+
...source,
|
|
296
|
+
mode: Literal("header"),
|
|
297
|
+
name: String$1({
|
|
298
|
+
pattern: "^[!#$%&'*+.^_`|~0-9A-Za-z-]+$",
|
|
299
|
+
maxLength: 128
|
|
300
|
+
})
|
|
301
|
+
}, { additionalProperties: false })]))
|
|
302
|
+
}, { additionalProperties: false });
|
|
303
|
+
_Object_({
|
|
304
|
+
...McpSessionServerRegistration.properties,
|
|
305
|
+
apiKey: Optional(McpSessionServerRegistration.properties.apiKey)
|
|
306
|
+
}, { additionalProperties: false });
|
|
307
|
+
const McpTestServerParameters = Union([
|
|
308
|
+
_Object_({
|
|
309
|
+
action: Literal("add"),
|
|
310
|
+
server: McpTestServerInput
|
|
311
|
+
}, { additionalProperties: false }),
|
|
312
|
+
_Object_({
|
|
313
|
+
action: Literal("remove"),
|
|
314
|
+
name: Name
|
|
315
|
+
}, { additionalProperties: false }),
|
|
316
|
+
_Object_({ action: Literal("list") }, { additionalProperties: false })
|
|
317
|
+
]);
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region ../../default/po-mcp/src/schemas/mcpApps.ts
|
|
320
|
+
const Lease = String$1({
|
|
321
|
+
minLength: 1,
|
|
322
|
+
maxLength: 128
|
|
323
|
+
});
|
|
324
|
+
const JsonObject = Record(String$1(), Unknown());
|
|
325
|
+
const Empty = _Object_({}, { additionalProperties: false });
|
|
326
|
+
const Result = _Object_({
|
|
327
|
+
content: _Array_(Unknown()),
|
|
328
|
+
structuredContent: Optional(Unknown()),
|
|
329
|
+
_meta: Optional(JsonObject),
|
|
330
|
+
isError: Optional(Boolean())
|
|
331
|
+
});
|
|
332
|
+
const Address = {
|
|
333
|
+
service: "mcp.apps",
|
|
334
|
+
scope: "session",
|
|
335
|
+
direction: "client-to-server"
|
|
336
|
+
};
|
|
337
|
+
const mcpAppOpenMethod = definePoPluginMethod({
|
|
338
|
+
...Address,
|
|
339
|
+
method: "open",
|
|
340
|
+
input: _Object_({ toolCallId: String$1({
|
|
341
|
+
minLength: 1,
|
|
342
|
+
maxLength: 512
|
|
343
|
+
}) }, { additionalProperties: false }),
|
|
344
|
+
output: _Object_({
|
|
345
|
+
leaseId: Lease,
|
|
346
|
+
html: String$1(),
|
|
347
|
+
resourceUri: String$1(),
|
|
348
|
+
protocol: Union([Literal("mcp"), Literal("openai")]),
|
|
349
|
+
resourceMeta: JsonObject,
|
|
350
|
+
tool: _Object_({
|
|
351
|
+
name: String$1(),
|
|
352
|
+
description: String$1(),
|
|
353
|
+
inputSchema: _Object_({ type: Literal("object") }, { additionalProperties: true }),
|
|
354
|
+
_meta: JsonObject
|
|
355
|
+
}),
|
|
356
|
+
args: JsonObject,
|
|
357
|
+
result: Result,
|
|
358
|
+
state: Unknown(),
|
|
359
|
+
readOnly: Boolean()
|
|
360
|
+
})
|
|
361
|
+
});
|
|
362
|
+
const mcpAppActivateMethod = definePoPluginMethod({
|
|
363
|
+
...Address,
|
|
364
|
+
method: "activate",
|
|
365
|
+
input: _Object_({ leaseId: Lease }, { additionalProperties: false }),
|
|
366
|
+
output: _Object_({ readOnly: Literal(false) })
|
|
367
|
+
});
|
|
368
|
+
const mcpAppCallToolMethod = definePoPluginMethod({
|
|
369
|
+
...Address,
|
|
370
|
+
method: "callTool",
|
|
371
|
+
input: _Object_({
|
|
372
|
+
leaseId: Lease,
|
|
373
|
+
name: String$1({
|
|
374
|
+
minLength: 1,
|
|
375
|
+
maxLength: 256
|
|
376
|
+
}),
|
|
377
|
+
arguments: JsonObject
|
|
378
|
+
}, { additionalProperties: false }),
|
|
379
|
+
output: Result
|
|
380
|
+
});
|
|
381
|
+
const mcpAppSetStateMethod = definePoPluginMethod({
|
|
382
|
+
...Address,
|
|
383
|
+
method: "setState",
|
|
384
|
+
input: _Object_({
|
|
385
|
+
leaseId: Lease,
|
|
386
|
+
state: Unknown()
|
|
387
|
+
}, { additionalProperties: false }),
|
|
388
|
+
output: Empty
|
|
389
|
+
});
|
|
390
|
+
const mcpAppFollowUpMethod = definePoPluginMethod({
|
|
391
|
+
...Address,
|
|
392
|
+
method: "followUp",
|
|
393
|
+
input: _Object_({
|
|
394
|
+
leaseId: Lease,
|
|
395
|
+
prompt: String$1({
|
|
396
|
+
minLength: 1,
|
|
397
|
+
maxLength: 16e3
|
|
398
|
+
})
|
|
399
|
+
}, { additionalProperties: false }),
|
|
400
|
+
output: Empty
|
|
401
|
+
});
|
|
402
|
+
const mcpAppCloseMethod = definePoPluginMethod({
|
|
403
|
+
...Address,
|
|
404
|
+
method: "close",
|
|
405
|
+
input: _Object_({ leaseId: Lease }, { additionalProperties: false }),
|
|
406
|
+
output: Empty
|
|
407
|
+
});
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region ../../default/po-mcp/src/services/mcpTools/index.ts
|
|
410
|
+
const MAX_APP_RESULT_BYTES = 1048576;
|
|
411
|
+
const appSnapshots = /* @__PURE__ */ new WeakMap();
|
|
412
|
+
/** Clone before output guards can replace structured data or mutate the source. */
|
|
413
|
+
function captureMcpAppResult(tool, result) {
|
|
414
|
+
const app = normalizeMcpAppMetadata(tool._meta);
|
|
415
|
+
if (!app.appVisible && !app.resourceUri) return void 0;
|
|
416
|
+
try {
|
|
417
|
+
const json = JSON.stringify(result);
|
|
418
|
+
if (new TextEncoder().encode(json).byteLength > MAX_APP_RESULT_BYTES) return void 0;
|
|
419
|
+
return {
|
|
420
|
+
version: 1,
|
|
421
|
+
...app.resourceUri === void 0 ? {} : {
|
|
422
|
+
resourceUri: app.resourceUri,
|
|
423
|
+
protocol: app.protocol
|
|
424
|
+
},
|
|
425
|
+
result: JSON.parse(json)
|
|
426
|
+
};
|
|
427
|
+
} catch {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
/** Historical details are untrusted JSON; reject malformed or unbounded snapshots. */
|
|
432
|
+
function parseMcpAppSnapshot(value) {
|
|
433
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
434
|
+
const record = value;
|
|
435
|
+
if (record.version !== 1 || typeof record.result !== "object" || record.result === null || Array.isArray(record.result)) return void 0;
|
|
436
|
+
if (record.resourceUri !== void 0 && (typeof record.resourceUri !== "string" || !record.resourceUri.startsWith("ui://") || record.resourceUri.length > 8192)) return void 0;
|
|
437
|
+
if (record.protocol !== void 0 && record.protocol !== "mcp" && record.protocol !== "openai") return void 0;
|
|
438
|
+
if (record.resourceUri === void 0 !== (record.protocol === void 0)) return void 0;
|
|
439
|
+
const result = record.result;
|
|
440
|
+
if (!Array.isArray(result.content) || result.isError !== void 0 && typeof result.isError !== "boolean") return void 0;
|
|
441
|
+
if (result.content.some((block) => typeof block !== "object" || block === null || !("type" in block) || typeof block.type !== "string")) return void 0;
|
|
442
|
+
try {
|
|
443
|
+
const json = JSON.stringify(value);
|
|
444
|
+
if (new TextEncoder().encode(json).byteLength > MAX_APP_RESULT_BYTES) return void 0;
|
|
445
|
+
return JSON.parse(json);
|
|
446
|
+
} catch {
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/** The text of a downstream result: its text blocks joined, which is what the model reads. */
|
|
451
|
+
function resultText(result) {
|
|
452
|
+
return (result.content ?? []).flatMap((block) => block.type === "text" ? [block.text] : []).join("\n").trim();
|
|
453
|
+
}
|
|
454
|
+
/** The image blocks, re-emitted as Pi's own image content so the model and the cockpit both see them. */
|
|
455
|
+
function resultImages(result) {
|
|
456
|
+
return (result.content ?? []).flatMap((block) => block.type === "image" ? [{
|
|
457
|
+
type: "image",
|
|
458
|
+
data: block.data,
|
|
459
|
+
mimeType: block.mimeType
|
|
460
|
+
}] : []);
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Everything else a downstream result carried: audio, resource links, embedded
|
|
464
|
+
* resources, and the structured content. Pi's content cannot hold them, so
|
|
465
|
+
* they ride the result's details for the cockpit's MCP message to render.
|
|
466
|
+
*/
|
|
467
|
+
function resultBlocks(result) {
|
|
468
|
+
const blocks = [];
|
|
469
|
+
for (const block of result.content ?? []) if (block.type === "audio") blocks.push({
|
|
470
|
+
type: "audio",
|
|
471
|
+
data: block.data,
|
|
472
|
+
mimeType: block.mimeType
|
|
473
|
+
});
|
|
474
|
+
else if (block.type === "resource_link") blocks.push({
|
|
475
|
+
type: "resource_link",
|
|
476
|
+
uri: block.uri,
|
|
477
|
+
name: block.name,
|
|
478
|
+
...block.title === void 0 ? {} : { title: block.title },
|
|
479
|
+
...block.description === void 0 ? {} : { description: block.description },
|
|
480
|
+
...block.mimeType === void 0 ? {} : { mimeType: block.mimeType }
|
|
481
|
+
});
|
|
482
|
+
else if (block.type === "resource") {
|
|
483
|
+
const resource = block.resource;
|
|
484
|
+
blocks.push({
|
|
485
|
+
type: "resource",
|
|
486
|
+
uri: resource.uri,
|
|
487
|
+
...resource.mimeType === void 0 ? {} : { mimeType: resource.mimeType },
|
|
488
|
+
..."text" in resource && typeof resource.text === "string" ? { text: resource.text } : {},
|
|
489
|
+
..."blob" in resource && typeof resource.blob === "string" ? { blob: resource.blob } : {}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
const structured = structuredRecord(result);
|
|
493
|
+
if (structured !== void 0) blocks.push({
|
|
494
|
+
type: "structured",
|
|
495
|
+
value: structured
|
|
496
|
+
});
|
|
497
|
+
return blocks;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* MCP v2 allows any JSON value as structured content; Po's contract carries an object, which
|
|
501
|
+
* is all v1 permitted. Any other value still reaches the model through the text fallback.
|
|
502
|
+
*/
|
|
503
|
+
function structuredRecord(result) {
|
|
504
|
+
const value = result.structuredContent;
|
|
505
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
506
|
+
}
|
|
507
|
+
/** Remote MCP preserves error flags and public structured results instead of Pi's thrown-error convention. */
|
|
508
|
+
function toHeadlessToolResult(tool, result) {
|
|
509
|
+
const text = resultText(result) || (result.structuredContent === void 0 ? "No output." : JSON.stringify(result.structuredContent));
|
|
510
|
+
const blocks = resultBlocks(result);
|
|
511
|
+
const structured = structuredRecord(result);
|
|
512
|
+
const app = appSnapshots.get(result) ?? (normalizeMcpAppMetadata(tool._meta).resourceUri === void 0 ? void 0 : captureMcpAppResult(tool, result));
|
|
513
|
+
return {
|
|
514
|
+
content: [{
|
|
515
|
+
type: "text",
|
|
516
|
+
text
|
|
517
|
+
}, ...resultImages(result)],
|
|
518
|
+
...structured === void 0 ? {} : { structuredContent: structured },
|
|
519
|
+
...result.isError === void 0 ? {} : { isError: result.isError },
|
|
520
|
+
...result._meta === void 0 ? {} : { _meta: result._meta },
|
|
521
|
+
details: {
|
|
522
|
+
server: tool.serverName,
|
|
523
|
+
tool: tool.toolName,
|
|
524
|
+
...blocks.length > 0 ? { blocks } : {},
|
|
525
|
+
...app === void 0 ? {} : { app }
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
//#endregion
|
|
530
|
+
//#region ../../default/po-mcp/src/services/mcpApps/index.ts
|
|
531
|
+
const STATE_ENTRY = "mcp.app.state";
|
|
532
|
+
/** An App result from a code-mode `mcp` call, which has no tool call of its own in the transcript. */
|
|
533
|
+
const CODEMODE_ENTRY = "mcp.app.codemode";
|
|
534
|
+
/** Code-mode invocation ids are `<exec tool call id>:mcp:<n>`; a model-issued tool call id never has this shape. */
|
|
535
|
+
const CODEMODE_INVOCATION = /:mcp:\d+$/u;
|
|
536
|
+
const MAX_HTML_BYTES = 2097152;
|
|
537
|
+
const MAX_RESULT_BYTES$1 = 1048576;
|
|
538
|
+
const MAX_STATE_BYTES = 65536;
|
|
539
|
+
const MAX_LEASES = 64;
|
|
540
|
+
function record$1(value) {
|
|
541
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
542
|
+
}
|
|
543
|
+
function boundedJson(value, limit, label) {
|
|
544
|
+
const encoded = JSON.stringify(value);
|
|
545
|
+
if (encoded === void 0 || new TextEncoder().encode(encoded).byteLength > limit) throw new Error(`${label} exceeds its size limit.`);
|
|
546
|
+
return JSON.parse(encoded);
|
|
547
|
+
}
|
|
548
|
+
/** Browser inputs identify a persisted invocation, never an upstream server or resource. */
|
|
549
|
+
function createMcpAppsService(tools, getHost, lifetime, connections, covered = () => /* @__PURE__ */ new Set()) {
|
|
550
|
+
const leases = /* @__PURE__ */ new Map();
|
|
551
|
+
let disposed = false;
|
|
552
|
+
let opening = 0;
|
|
553
|
+
const revoke = (lease) => {
|
|
554
|
+
leases.delete(lease.id);
|
|
555
|
+
lease.controller.abort();
|
|
556
|
+
};
|
|
557
|
+
const check = (lease) => {
|
|
558
|
+
lease.signal.throwIfAborted();
|
|
559
|
+
if (disposed || getHost() !== lease.host) throw new Error("App session is no longer available.");
|
|
560
|
+
lease.host.assertActive();
|
|
561
|
+
const surface = lease.host.toolSurface;
|
|
562
|
+
const current = surface?.readSurface();
|
|
563
|
+
if (!surface || current?.revision !== lease.revision || tools.runtimeRevision() !== lease.runtimeRevision) throw new Error("App permissions changed. Reopen the App.");
|
|
564
|
+
if (lease.privateInvocation) {
|
|
565
|
+
const retained = connections?.invocation(lease.privateInvocation.id);
|
|
566
|
+
if (retained !== lease.privateInvocation || !connections?.isLive(retained.connection) || retained.owner !== lease.server || retained.toolCallId !== lease.toolCallId) throw new Error("Private App connection is no longer available.");
|
|
567
|
+
lease.host.assertActive(retained.owner);
|
|
568
|
+
if (!current.tools.some((tool) => tool.name === retained.toolName)) throw new Error("The wrapper App tool is not admitted in this session.");
|
|
569
|
+
return surface;
|
|
570
|
+
}
|
|
571
|
+
const source = tools.snapshot().find((tool) => tool.serverName === lease.server && tool.toolName === lease.tool);
|
|
572
|
+
if (!source || normalizeMcpAppMetadata(source._meta).resourceUri !== lease.resourceUri) throw new Error("App resource is no longer available.");
|
|
573
|
+
if (!covered().has(source.piName) && !current.tools.some((tool) => tool.name === source.piName || tool.name === "mcp")) throw new Error("The original App tool is not admitted in this session.");
|
|
574
|
+
return surface;
|
|
575
|
+
};
|
|
576
|
+
const owned = (id, caller) => {
|
|
577
|
+
caller.signal?.throwIfAborted();
|
|
578
|
+
const lease = leases.get(id);
|
|
579
|
+
if (!lease || !caller.connectionId || lease.connectionId !== caller.connectionId) throw new Error("App lease is not owned by this connection.");
|
|
580
|
+
try {
|
|
581
|
+
check(lease);
|
|
582
|
+
} catch (error) {
|
|
583
|
+
revoke(lease);
|
|
584
|
+
throw error;
|
|
585
|
+
}
|
|
586
|
+
return lease;
|
|
587
|
+
};
|
|
588
|
+
const operation = async (id, caller, write, run) => {
|
|
589
|
+
const lease = owned(id, caller);
|
|
590
|
+
if (write && lease.readOnly) throw new Error("Enable App interactions before performing this action.");
|
|
591
|
+
if (lease.busy) throw new Error("An App action is already in progress.");
|
|
592
|
+
if (++lease.actions > 256) throw new Error("App action limit reached. Reopen the App.");
|
|
593
|
+
lease.busy = true;
|
|
594
|
+
try {
|
|
595
|
+
return await run(lease);
|
|
596
|
+
} finally {
|
|
597
|
+
lease.busy = false;
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
const confirm = async (lease, title, message) => {
|
|
601
|
+
check(lease);
|
|
602
|
+
const accepted = await lease.host.context.client.request({
|
|
603
|
+
kind: "confirm",
|
|
604
|
+
title,
|
|
605
|
+
message
|
|
606
|
+
}, AbortSignal.any([lease.signal, AbortSignal.timeout(12e4)]));
|
|
607
|
+
check(lease);
|
|
608
|
+
if (accepted !== true) throw new Error("App action was not approved.");
|
|
609
|
+
};
|
|
610
|
+
const invocation = async (host, toolCallId) => {
|
|
611
|
+
let call;
|
|
612
|
+
let result;
|
|
613
|
+
if (CODEMODE_INVOCATION.test(toolCallId)) for await (const entry of host.context.session.entriesNewestFirst({
|
|
614
|
+
type: "custom",
|
|
615
|
+
customType: CODEMODE_ENTRY
|
|
616
|
+
})) {
|
|
617
|
+
const data = record$1(entry.data);
|
|
618
|
+
if (data?.version !== 1 || data.id !== toolCallId || typeof data.piName !== "string") continue;
|
|
619
|
+
call = {
|
|
620
|
+
type: "toolCall",
|
|
621
|
+
id: toolCallId,
|
|
622
|
+
name: data.piName,
|
|
623
|
+
arguments: record$1(data.args) ?? {}
|
|
624
|
+
};
|
|
625
|
+
result = { details: {
|
|
626
|
+
server: data.server,
|
|
627
|
+
tool: data.tool,
|
|
628
|
+
app: data.app
|
|
629
|
+
} };
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
else for await (const entry of host.context.session.entriesNewestFirst({ type: "message" })) {
|
|
633
|
+
const message = record$1(entry.message);
|
|
634
|
+
if (!call && message?.role === "assistant" && Array.isArray(message.content)) for (const block of message.content) {
|
|
635
|
+
const candidate = record$1(block);
|
|
636
|
+
if (candidate?.type === "toolCall" && candidate.id === toolCallId) call = candidate;
|
|
637
|
+
}
|
|
638
|
+
if (!result && message?.role === "toolResult" && message.toolCallId === toolCallId) result = message;
|
|
639
|
+
if (call && result) break;
|
|
640
|
+
}
|
|
641
|
+
const details = record$1(result?.details);
|
|
642
|
+
const app = parseMcpAppSnapshot(details?.app);
|
|
643
|
+
if (!call || !app?.resourceUri || !app.protocol || typeof details?.server !== "string" || typeof details.tool !== "string") throw new Error("This invocation has no retained App result.");
|
|
644
|
+
const privateId = record$1(details.privateMcp)?.invocationId;
|
|
645
|
+
let privateInvocation;
|
|
646
|
+
if (details.privateMcp !== void 0) {
|
|
647
|
+
privateInvocation = typeof privateId === "string" ? connections?.invocation(privateId) : void 0;
|
|
648
|
+
if (!privateInvocation || !connections?.isLive(privateInvocation.connection) || privateInvocation.toolCallId !== toolCallId || privateInvocation.toolName !== call.name || details.server !== privateInvocation.owner || details.tool !== privateInvocation.toolName) throw new Error("Private App invocation identity does not match a live connection.");
|
|
649
|
+
const declared = normalizeMcpAppMetadata(privateInvocation.source._meta);
|
|
650
|
+
if (declared.resourceUri !== app.resourceUri || declared.protocol !== app.protocol) throw new Error("Private App resource identity does not match its invocation.");
|
|
651
|
+
}
|
|
652
|
+
return {
|
|
653
|
+
call,
|
|
654
|
+
details,
|
|
655
|
+
app,
|
|
656
|
+
privateInvocation
|
|
657
|
+
};
|
|
658
|
+
};
|
|
659
|
+
const revokeChanged = () => {
|
|
660
|
+
for (const lease of leases.values()) try {
|
|
661
|
+
check(lease);
|
|
662
|
+
} catch {
|
|
663
|
+
revoke(lease);
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
const stopTools = tools.onChange(revokeChanged);
|
|
667
|
+
const stopConnections = connections?.onChange(revokeChanged);
|
|
668
|
+
const dispose = () => {
|
|
669
|
+
disposed = true;
|
|
670
|
+
stopTools();
|
|
671
|
+
stopConnections?.();
|
|
672
|
+
for (const lease of leases.values()) revoke(lease);
|
|
673
|
+
};
|
|
674
|
+
lifetime?.addEventListener("abort", dispose, { once: true });
|
|
675
|
+
return {
|
|
676
|
+
dispose,
|
|
677
|
+
/** Persists an App result from a code-mode call, so its card can open the App by the returned invocation id. */
|
|
678
|
+
retainCodemodeApp: (async ({ id, piName, server, tool, args, app }) => {
|
|
679
|
+
const host = getHost();
|
|
680
|
+
if (disposed || !host || !CODEMODE_INVOCATION.test(id)) return false;
|
|
681
|
+
await host.context.session.appendCustomEntry(CODEMODE_ENTRY, {
|
|
682
|
+
version: 1,
|
|
683
|
+
id,
|
|
684
|
+
piName,
|
|
685
|
+
server,
|
|
686
|
+
tool,
|
|
687
|
+
args,
|
|
688
|
+
app
|
|
689
|
+
});
|
|
690
|
+
return true;
|
|
691
|
+
}),
|
|
692
|
+
methods: [
|
|
693
|
+
defineServerMethod(mcpAppOpenMethod, async ({ toolCallId }, caller) => {
|
|
694
|
+
if (!caller.connectionId || !caller.signal) throw new Error("An authenticated live connection is required.");
|
|
695
|
+
caller.signal.throwIfAborted();
|
|
696
|
+
if (disposed || lifetime?.aborted) throw new Error("App session is no longer available.");
|
|
697
|
+
if (leases.size + opening >= MAX_LEASES) throw new Error("Too many open Apps. Close an App before opening another.");
|
|
698
|
+
opening++;
|
|
699
|
+
try {
|
|
700
|
+
const host = getHost();
|
|
701
|
+
if (!host?.toolSurface) throw new Error("App execution is unavailable in this session.");
|
|
702
|
+
host.assertActive();
|
|
703
|
+
const revision = host.toolSurface.readSurface().revision;
|
|
704
|
+
const runtimeRevision = tools.runtimeRevision();
|
|
705
|
+
const { call, details, app, privateInvocation } = await invocation(host, toolCallId);
|
|
706
|
+
const source = privateInvocation ? {
|
|
707
|
+
...privateInvocation.source,
|
|
708
|
+
piName: privateInvocation.toolName,
|
|
709
|
+
serverName: privateInvocation.owner,
|
|
710
|
+
toolName: privateInvocation.source.name,
|
|
711
|
+
inputSchema: privateInvocation.source.inputSchema
|
|
712
|
+
} : tools.snapshot().find((tool) => tool.serverName === details.server && tool.toolName === details.tool);
|
|
713
|
+
const declared = normalizeMcpAppMetadata(source?._meta);
|
|
714
|
+
if (!source || declared.resourceUri !== app.resourceUri || declared.protocol !== app.protocol) throw new Error("The original App resource is no longer declared.");
|
|
715
|
+
const args = privateInvocation?.args ?? record$1(call.arguments) ?? {};
|
|
716
|
+
const generic = !privateInvocation && call.name === "mcp" && args.server === source.serverName && args.tool === source.toolName;
|
|
717
|
+
if (!privateInvocation && call.name !== source.piName && !generic) throw new Error("App invocation identity does not match its tool.");
|
|
718
|
+
const controller = new AbortController();
|
|
719
|
+
const lease = {
|
|
720
|
+
id: crypto.randomUUID(),
|
|
721
|
+
connectionId: caller.connectionId,
|
|
722
|
+
host,
|
|
723
|
+
toolCallId,
|
|
724
|
+
server: source.serverName,
|
|
725
|
+
tool: source.toolName,
|
|
726
|
+
resourceUri: app.resourceUri,
|
|
727
|
+
revision,
|
|
728
|
+
runtimeRevision,
|
|
729
|
+
controller,
|
|
730
|
+
signal: AbortSignal.any([
|
|
731
|
+
controller.signal,
|
|
732
|
+
caller.signal,
|
|
733
|
+
...lifetime ? [lifetime] : []
|
|
734
|
+
]),
|
|
735
|
+
readOnly: true,
|
|
736
|
+
busy: false,
|
|
737
|
+
actions: 0,
|
|
738
|
+
...privateInvocation ? { privateInvocation } : {}
|
|
739
|
+
};
|
|
740
|
+
check(lease);
|
|
741
|
+
const resource = privateInvocation ? await privateInvocation.connection.readAppResource(privateInvocation.source.name, lease.signal) : await tools.readAppResource(lease.server, lease.tool, lease.resourceUri, lease.signal);
|
|
742
|
+
check(lease);
|
|
743
|
+
const content = resource.contents.find((item) => item.uri === lease.resourceUri && "text" in item);
|
|
744
|
+
if (!content || !("text" in content) || typeof content.text !== "string") throw new Error("App resource must contain HTML text.");
|
|
745
|
+
if (content.mimeType !== "text/html;profile=mcp-app" && content.mimeType !== "text/html+skybridge") throw new Error("Unsupported App resource MIME type.");
|
|
746
|
+
if (new TextEncoder().encode(content.text).byteLength > MAX_HTML_BYTES) throw new Error("App HTML exceeds its size limit.");
|
|
747
|
+
let state = null;
|
|
748
|
+
for await (const entry of host.context.session.entriesNewestFirst({
|
|
749
|
+
type: "custom",
|
|
750
|
+
customType: STATE_ENTRY
|
|
751
|
+
})) {
|
|
752
|
+
const data = record$1(entry.data);
|
|
753
|
+
if (data?.version === 1 && data.toolCallId === toolCallId && data.server === lease.server && data.tool === lease.tool && data.resourceUri === lease.resourceUri) {
|
|
754
|
+
state = data.state ?? null;
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
check(lease);
|
|
759
|
+
if (leases.size >= MAX_LEASES) throw new Error("Too many open Apps.");
|
|
760
|
+
const opened = {
|
|
761
|
+
leaseId: lease.id,
|
|
762
|
+
html: content.text,
|
|
763
|
+
resourceUri: lease.resourceUri,
|
|
764
|
+
protocol: app.protocol,
|
|
765
|
+
resourceMeta: boundedJson(record$1(content._meta) ?? record$1(resource._meta) ?? {}, MAX_STATE_BYTES, "Resource metadata"),
|
|
766
|
+
tool: {
|
|
767
|
+
name: source.toolName,
|
|
768
|
+
description: source.description ?? "",
|
|
769
|
+
inputSchema: boundedJson({
|
|
770
|
+
...source.inputSchema,
|
|
771
|
+
type: "object"
|
|
772
|
+
}, MAX_STATE_BYTES, "Tool schema"),
|
|
773
|
+
_meta: boundedJson(source._meta ?? {}, MAX_STATE_BYTES, "Tool metadata")
|
|
774
|
+
},
|
|
775
|
+
args: boundedJson(generic ? record$1(args.arguments) ?? {} : args, MAX_STATE_BYTES, "Tool input"),
|
|
776
|
+
result: app.result,
|
|
777
|
+
state: boundedJson(state, MAX_STATE_BYTES, "App state"),
|
|
778
|
+
readOnly: true
|
|
779
|
+
};
|
|
780
|
+
leases.set(lease.id, lease);
|
|
781
|
+
lease.signal.addEventListener("abort", () => leases.delete(lease.id), { once: true });
|
|
782
|
+
return opened;
|
|
783
|
+
} finally {
|
|
784
|
+
opening--;
|
|
785
|
+
}
|
|
786
|
+
}),
|
|
787
|
+
defineServerMethod(mcpAppActivateMethod, ({ leaseId }, caller) => operation(leaseId, caller, false, async (lease) => {
|
|
788
|
+
await confirm(lease, `Enable ${lease.server} App interactions?`, "This App may request tool calls and follow-up messages. Each action still requires approval.");
|
|
789
|
+
lease.readOnly = false;
|
|
790
|
+
return { readOnly: false };
|
|
791
|
+
})),
|
|
792
|
+
defineServerMethod(mcpAppCallToolMethod, ({ leaseId, name, arguments: args }, caller) => operation(leaseId, caller, true, async (lease) => {
|
|
793
|
+
boundedJson(args, MAX_STATE_BYTES, "Tool arguments");
|
|
794
|
+
if (lease.privateInvocation) {
|
|
795
|
+
const retained = lease.privateInvocation;
|
|
796
|
+
const authorize = async () => {
|
|
797
|
+
check(lease);
|
|
798
|
+
if (!retained.appTools.includes(name)) throw new Error("This tool is not available to this App.");
|
|
799
|
+
const definitions = await retained.connection.listTools(lease.signal);
|
|
800
|
+
check(lease);
|
|
801
|
+
const target = definitions.find((tool) => tool.name === name);
|
|
802
|
+
if (!target || !isAppVisibleMcpTool(target)) throw new Error("This tool is not available to this App.");
|
|
803
|
+
};
|
|
804
|
+
await authorize();
|
|
805
|
+
await confirm(lease, `Allow ${lease.server} App to call ${name}?`, JSON.stringify(args, null, 2));
|
|
806
|
+
await authorize();
|
|
807
|
+
const result = await retained.connection.callTool(name, args, { signal: lease.signal });
|
|
808
|
+
check(lease);
|
|
809
|
+
const raw = connections?.appResult(result);
|
|
810
|
+
if (!raw) throw new Error("Private App tool result is unavailable.");
|
|
811
|
+
return boundedJson(raw, MAX_RESULT_BYTES$1, "Tool result");
|
|
812
|
+
}
|
|
813
|
+
const target = tools.snapshot().find((tool) => tool.serverName === lease.server && tool.toolName === name && isAppVisibleMcpTool(tool));
|
|
814
|
+
if (!target) throw new Error("This tool is not available to this App.");
|
|
815
|
+
const surface = check(lease);
|
|
816
|
+
const exposed = surface.readSurface().tools;
|
|
817
|
+
const direct = exposed.some((tool) => tool.name === target.piName);
|
|
818
|
+
const generic = !direct && exposed.some((tool) => tool.name === "mcp");
|
|
819
|
+
const wrapper = direct || generic || !covered().has(target.piName) ? void 0 : tools.project().find((candidate) => candidate.name === target.piName);
|
|
820
|
+
if (!direct && !generic && !wrapper) throw new Error("This tool is not admitted in this session.");
|
|
821
|
+
await confirm(lease, `Allow ${lease.server} App to call ${name}?`, JSON.stringify(args, null, 2));
|
|
822
|
+
const release = tools.approval?.grant(target.piName, args);
|
|
823
|
+
const signal = AbortSignal.any([lease.signal, AbortSignal.timeout(12e4)]);
|
|
824
|
+
let result;
|
|
825
|
+
try {
|
|
826
|
+
result = wrapper ? await wrapper.execute(lease.toolCallId, args, signal) : await surface.invokeTool({
|
|
827
|
+
revision: lease.revision,
|
|
828
|
+
name: direct ? target.piName : "mcp",
|
|
829
|
+
arguments: direct ? args : {
|
|
830
|
+
server: lease.server,
|
|
831
|
+
tool: name,
|
|
832
|
+
arguments: args
|
|
833
|
+
},
|
|
834
|
+
signal,
|
|
835
|
+
authorize: () => {
|
|
836
|
+
check(lease);
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
} finally {
|
|
840
|
+
release?.();
|
|
841
|
+
}
|
|
842
|
+
check(lease);
|
|
843
|
+
return parseMcpAppSnapshot(record$1(result.details)?.app)?.result ?? boundedJson({
|
|
844
|
+
content: result.content,
|
|
845
|
+
...result.structuredContent === void 0 ? {} : { structuredContent: result.structuredContent },
|
|
846
|
+
...result._meta === void 0 ? {} : { _meta: result._meta },
|
|
847
|
+
...result.isError === void 0 ? {} : { isError: result.isError }
|
|
848
|
+
}, MAX_RESULT_BYTES$1, "Tool result");
|
|
849
|
+
})),
|
|
850
|
+
defineServerMethod(mcpAppSetStateMethod, ({ leaseId, state }, caller) => operation(leaseId, caller, false, async (lease) => {
|
|
851
|
+
const saved = boundedJson(state, MAX_STATE_BYTES, "App state");
|
|
852
|
+
await lease.host.context.session.appendCustomEntry(STATE_ENTRY, {
|
|
853
|
+
version: 1,
|
|
854
|
+
toolCallId: lease.toolCallId,
|
|
855
|
+
server: lease.server,
|
|
856
|
+
tool: lease.tool,
|
|
857
|
+
resourceUri: lease.resourceUri,
|
|
858
|
+
state: saved
|
|
859
|
+
});
|
|
860
|
+
check(lease);
|
|
861
|
+
return {};
|
|
862
|
+
})),
|
|
863
|
+
defineServerMethod(mcpAppFollowUpMethod, ({ leaseId, prompt }, caller) => operation(leaseId, caller, true, async (lease) => {
|
|
864
|
+
const session = lease.host.context.session;
|
|
865
|
+
if (!session.admitPrompt) throw new Error("App follow-up messages are unavailable in this session.");
|
|
866
|
+
await confirm(lease, `Send a follow-up from ${lease.server}?`, prompt);
|
|
867
|
+
await session.admitPrompt(`[MCP App ${lease.server}/${lease.tool}, invocation ${lease.toolCallId}]\n${prompt}`, "followUp");
|
|
868
|
+
check(lease);
|
|
869
|
+
return {};
|
|
870
|
+
})),
|
|
871
|
+
defineServerMethod(mcpAppCloseMethod, ({ leaseId }, caller) => {
|
|
872
|
+
const lease = leases.get(leaseId);
|
|
873
|
+
if (lease && lease.connectionId !== caller.connectionId) throw new Error("App lease is not owned by this connection.");
|
|
874
|
+
if (lease) revoke(lease);
|
|
875
|
+
return {};
|
|
876
|
+
})
|
|
877
|
+
]
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
//#endregion
|
|
881
|
+
//#region ../../default/po-mcp/src/services/mcpConnections/index.ts
|
|
882
|
+
const NAMESPACE = "mcp.private";
|
|
883
|
+
const MAX_TOOLS = 512;
|
|
884
|
+
const MAX_RESULT_BYTES = 1048576;
|
|
885
|
+
const AUTHORIZATION_REFUSED = "Private MCP authorization failed.";
|
|
886
|
+
const VAULT_UNAVAILABLE = "MCP credential vault is unavailable.";
|
|
887
|
+
const HTTPS_PROTOCOL = "https:";
|
|
888
|
+
const MAX_INVOCATION_FIELD_LENGTH = 512;
|
|
889
|
+
const LIST_TOOLS_METHOD = "tools/list";
|
|
890
|
+
var PrivateMcpLimitError = class extends Error {};
|
|
891
|
+
const RESERVED = /* @__PURE__ */ new Set([
|
|
892
|
+
"host",
|
|
893
|
+
"content-length",
|
|
894
|
+
"content-type",
|
|
895
|
+
"accept",
|
|
896
|
+
"connection",
|
|
897
|
+
"transfer-encoding",
|
|
898
|
+
"cookie",
|
|
899
|
+
"mcp-session-id",
|
|
900
|
+
"mcp-protocol-version"
|
|
901
|
+
]);
|
|
902
|
+
function ownerKey(owner, id) {
|
|
903
|
+
if (typeof owner !== "string" || !/^[a-z0-9@][a-z0-9@/._-]{0,127}$/u.test(owner)) throw new Error("Invalid MCP owner.");
|
|
904
|
+
if (typeof id !== "string" || !id.length || id.length > 128) throw new Error("Invalid credential id.");
|
|
905
|
+
return `${encodeURIComponent(owner)}/${encodeURIComponent(id)}`;
|
|
906
|
+
}
|
|
907
|
+
function credentialHeaders(value) {
|
|
908
|
+
if (value?.kind === "bearer" && isSecretValue(value.token)) return { Authorization: `Bearer ${value.token}` };
|
|
909
|
+
if (value?.kind === "header" && /^[A-Za-z0-9-]{1,64}$/u.test(value.name) && !RESERVED.has(value.name.toLowerCase()) && isSecretValue(value.value)) return { [value.name]: value.value };
|
|
910
|
+
throw new Error("Invalid MCP credential.");
|
|
911
|
+
}
|
|
912
|
+
/** Private SDK clients never register tools or write session configuration. */
|
|
913
|
+
function createMcpConnectionsService(options) {
|
|
914
|
+
const connections = /* @__PURE__ */ new Set();
|
|
915
|
+
const records = /* @__PURE__ */ new Map();
|
|
916
|
+
const appResults = /* @__PURE__ */ new WeakMap();
|
|
917
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
918
|
+
const pending = new AbortController();
|
|
919
|
+
let retired = false;
|
|
920
|
+
const changed = () => {
|
|
921
|
+
for (const listener of listeners) listener();
|
|
922
|
+
};
|
|
923
|
+
return {
|
|
924
|
+
supportsAuthorization: true,
|
|
925
|
+
appResult: (result) => {
|
|
926
|
+
const raw = appResults.get(result);
|
|
927
|
+
return raw === void 0 ? void 0 : structuredClone(raw);
|
|
928
|
+
},
|
|
929
|
+
invocation: (id) => records.get(id),
|
|
930
|
+
isLive: (connection) => connections.has(connection),
|
|
931
|
+
onChange(listener) {
|
|
932
|
+
listeners.add(listener);
|
|
933
|
+
return () => {
|
|
934
|
+
listeners.delete(listener);
|
|
935
|
+
};
|
|
936
|
+
},
|
|
937
|
+
async forgetCredential(owner, id) {
|
|
938
|
+
const key = ownerKey(owner, id);
|
|
939
|
+
const vault = options.vault();
|
|
940
|
+
if (!vault) throw new Error(VAULT_UNAVAILABLE);
|
|
941
|
+
await vault.delete(NAMESPACE, key);
|
|
942
|
+
},
|
|
943
|
+
async dispose() {
|
|
944
|
+
retired = true;
|
|
945
|
+
const closing = [...connections].map((connection) => connection.dispose());
|
|
946
|
+
pending.abort();
|
|
947
|
+
await Promise.allSettled(closing);
|
|
948
|
+
listeners.clear();
|
|
949
|
+
},
|
|
950
|
+
async connect(input, signal) {
|
|
951
|
+
input = {
|
|
952
|
+
...input,
|
|
953
|
+
...input.auth ? { auth: structuredClone(input.auth) } : {},
|
|
954
|
+
...input.appTools ? { appTools: [...input.appTools] } : {}
|
|
955
|
+
};
|
|
956
|
+
ownerKey(input.owner, "validate");
|
|
957
|
+
const authorize = input.authorize;
|
|
958
|
+
if (authorize !== void 0 && typeof authorize !== "function") throw new Error("Invalid MCP authorization guard.");
|
|
959
|
+
if (retired) throw new Error("MCP connections service is retired.");
|
|
960
|
+
const policy = options.policy();
|
|
961
|
+
if (!policy) throw new Error("Private MCP connections are not enabled on this host.");
|
|
962
|
+
const url = new URL(input.url);
|
|
963
|
+
if (url.protocol !== HTTPS_PROTOCOL || url.username || url.password) throw new Error("MCP requires HTTPS without user info.");
|
|
964
|
+
const refusal = outboundHostRefusal(url.href, {
|
|
965
|
+
protocols: [HTTPS_PROTOCOL],
|
|
966
|
+
blockedHosts: policy.blockedHosts
|
|
967
|
+
});
|
|
968
|
+
if (refusal) throw new Error(refusal);
|
|
969
|
+
if (!input.lifetime || typeof input.lifetime.throwIfAborted !== "function") throw new Error("MCP connection lifetime is required.");
|
|
970
|
+
if (input.appTools && (!Array.isArray(input.appTools) || input.appTools.length > MAX_TOOLS || input.appTools.some((name) => typeof name !== "string" || !name.length))) throw new Error("Invalid App tool allowlist.");
|
|
971
|
+
const appTools = [...input.appTools ?? []];
|
|
972
|
+
let credential;
|
|
973
|
+
const auth = input.auth;
|
|
974
|
+
if (auth && "credentialId" in auth) {
|
|
975
|
+
const key = ownerKey(input.owner, auth.credentialId);
|
|
976
|
+
const vault = options.vault();
|
|
977
|
+
if (!vault) throw new Error(VAULT_UNAVAILABLE);
|
|
978
|
+
const stored = (await vault.get(NAMESPACE, key))?.value;
|
|
979
|
+
if (!stored || typeof stored !== "object" || Array.isArray(stored) || stored.version !== 1 || stored.origin !== url.origin || !stored.credential) throw new Error("Saved MCP credential is unavailable for this origin.");
|
|
980
|
+
credential = stored.credential;
|
|
981
|
+
} else if (auth) {
|
|
982
|
+
credential = structuredClone(auth.credential);
|
|
983
|
+
if (auth.saveAs !== void 0) ownerKey(input.owner, auth.saveAs);
|
|
984
|
+
}
|
|
985
|
+
const headers = credential ? credentialHeaders(credential) : {};
|
|
986
|
+
const controller = new AbortController();
|
|
987
|
+
const lifetime = AbortSignal.any([
|
|
988
|
+
controller.signal,
|
|
989
|
+
pending.signal,
|
|
990
|
+
input.lifetime
|
|
991
|
+
]);
|
|
992
|
+
const work = (callSignal) => AbortSignal.any([lifetime, ...callSignal ? [callSignal] : []]);
|
|
993
|
+
const connectSignal = work(signal);
|
|
994
|
+
connectSignal.throwIfAborted();
|
|
995
|
+
const fetcher = guardedFetch({
|
|
996
|
+
protocols: [HTTPS_PROTOCOL],
|
|
997
|
+
blockedHosts: policy.blockedHosts,
|
|
998
|
+
maxBytes: REMOTE_MCP_MAX_BYTES,
|
|
999
|
+
timeoutMs: REMOTE_MCP_TIMEOUT_MS,
|
|
1000
|
+
...policy.fetch ? { fetch: policy.fetch } : {}
|
|
1001
|
+
});
|
|
1002
|
+
const pinned = async (request, init) => {
|
|
1003
|
+
if (new URL(request instanceof Request ? request.url : String(request)).origin !== url.origin) throw new Error("MCP request origin changed.");
|
|
1004
|
+
return fetcher(request, {
|
|
1005
|
+
...init,
|
|
1006
|
+
signal: work(init?.signal ?? void 0)
|
|
1007
|
+
});
|
|
1008
|
+
};
|
|
1009
|
+
const client = new Client({
|
|
1010
|
+
name: "po-private",
|
|
1011
|
+
version: "1.0.0"
|
|
1012
|
+
}, { capabilities: MCP_APP_CLIENT_CAPABILITIES });
|
|
1013
|
+
let tools = [];
|
|
1014
|
+
let closed = false;
|
|
1015
|
+
const assertLive = () => {
|
|
1016
|
+
lifetime.throwIfAborted();
|
|
1017
|
+
if (closed) throw new Error("MCP connection is retired.");
|
|
1018
|
+
};
|
|
1019
|
+
const guard = async (phase, descriptor, callSignal) => {
|
|
1020
|
+
if (!authorize) return;
|
|
1021
|
+
const guardSignal = work(callSignal);
|
|
1022
|
+
try {
|
|
1023
|
+
await authorize(guardSignal, {
|
|
1024
|
+
phase,
|
|
1025
|
+
...descriptor,
|
|
1026
|
+
...descriptor.arguments ? { arguments: structuredClone(descriptor.arguments) } : {}
|
|
1027
|
+
});
|
|
1028
|
+
} catch {
|
|
1029
|
+
guardSignal.throwIfAborted();
|
|
1030
|
+
await connection.dispose().catch(() => void 0);
|
|
1031
|
+
throw new Error(AUTHORIZATION_REFUSED);
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
const request = async (run, descriptor, callSignal) => {
|
|
1035
|
+
assertLive();
|
|
1036
|
+
await guard("before", descriptor, callSignal);
|
|
1037
|
+
assertLive();
|
|
1038
|
+
let result;
|
|
1039
|
+
try {
|
|
1040
|
+
result = await run();
|
|
1041
|
+
assertLive();
|
|
1042
|
+
} catch (error) {
|
|
1043
|
+
work(callSignal).throwIfAborted();
|
|
1044
|
+
if (isUnauthorized(error)) throw new Error("MCP credentials rejected.");
|
|
1045
|
+
if (error instanceof PrivateMcpLimitError || error instanceof OutboundRefusedError) throw error;
|
|
1046
|
+
throw new Error("Private MCP request failed.");
|
|
1047
|
+
}
|
|
1048
|
+
await guard("after", descriptor, callSignal);
|
|
1049
|
+
assertLive();
|
|
1050
|
+
return result;
|
|
1051
|
+
};
|
|
1052
|
+
const connection = {
|
|
1053
|
+
id: crypto.randomUUID(),
|
|
1054
|
+
async listTools(callSignal) {
|
|
1055
|
+
const next = [];
|
|
1056
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1057
|
+
let cursor;
|
|
1058
|
+
let pages = 0;
|
|
1059
|
+
do {
|
|
1060
|
+
if (++pages > MAX_TOOLS) throw new PrivateMcpLimitError("Too many MCP tool pages.");
|
|
1061
|
+
await request(async () => {
|
|
1062
|
+
const page = await client.request({
|
|
1063
|
+
method: LIST_TOOLS_METHOD,
|
|
1064
|
+
...cursor === void 0 ? {} : { params: { cursor } }
|
|
1065
|
+
}, {
|
|
1066
|
+
signal: work(callSignal),
|
|
1067
|
+
timeout: REMOTE_MCP_TIMEOUT_MS
|
|
1068
|
+
});
|
|
1069
|
+
next.push(...page.tools);
|
|
1070
|
+
if (next.length > MAX_TOOLS) throw new PrivateMcpLimitError("Too many MCP tools.");
|
|
1071
|
+
cursor = page.nextCursor;
|
|
1072
|
+
if (cursor !== void 0) {
|
|
1073
|
+
if (seen.has(cursor)) throw new PrivateMcpLimitError("Repeated MCP tool cursor.");
|
|
1074
|
+
seen.add(cursor);
|
|
1075
|
+
}
|
|
1076
|
+
}, { method: LIST_TOOLS_METHOD }, callSignal);
|
|
1077
|
+
} while (cursor !== void 0);
|
|
1078
|
+
assertLive();
|
|
1079
|
+
tools = structuredClone(next);
|
|
1080
|
+
for (const [id, retained] of records) if (retained.connection === connection && JSON.stringify(tools.find((tool) => tool.name === retained.source.name)) !== JSON.stringify(retained.source)) records.delete(id);
|
|
1081
|
+
changed();
|
|
1082
|
+
assertLive();
|
|
1083
|
+
return structuredClone(tools);
|
|
1084
|
+
},
|
|
1085
|
+
async callTool(name, args, callOptions) {
|
|
1086
|
+
callOptions = callOptions ? {
|
|
1087
|
+
...callOptions,
|
|
1088
|
+
...callOptions.invocation ? { invocation: { ...callOptions.invocation } } : {}
|
|
1089
|
+
} : void 0;
|
|
1090
|
+
assertLive();
|
|
1091
|
+
const invocation = callOptions?.invocation;
|
|
1092
|
+
if (invocation !== void 0 && (!invocation || typeof invocation.toolCallId !== "string" || !invocation.toolCallId || invocation.toolCallId.length > MAX_INVOCATION_FIELD_LENGTH || typeof invocation.toolName !== "string" || !invocation.toolName || invocation.toolName.length > MAX_INVOCATION_FIELD_LENGTH)) throw new Error("Invalid App invocation.");
|
|
1093
|
+
const source = tools.find((tool) => tool.name === name);
|
|
1094
|
+
if (!source) throw new Error("Unknown private MCP tool.");
|
|
1095
|
+
const parameters = structuredClone(args);
|
|
1096
|
+
if (!Check(source.inputSchema, parameters)) throw new Error("Invalid MCP tool arguments.");
|
|
1097
|
+
const result = await request(() => client.callTool({
|
|
1098
|
+
name,
|
|
1099
|
+
arguments: parameters
|
|
1100
|
+
}, {
|
|
1101
|
+
signal: work(callOptions?.signal),
|
|
1102
|
+
timeout: REMOTE_MCP_TIMEOUT_MS,
|
|
1103
|
+
toolDefinition: source
|
|
1104
|
+
}), {
|
|
1105
|
+
method: "tools/call",
|
|
1106
|
+
name,
|
|
1107
|
+
arguments: parameters
|
|
1108
|
+
}, callOptions?.signal);
|
|
1109
|
+
const json = JSON.stringify(result);
|
|
1110
|
+
if (new TextEncoder().encode(json).byteLength > MAX_RESULT_BYTES) throw new Error("MCP tool result exceeds its size limit.");
|
|
1111
|
+
const detached = JSON.parse(json);
|
|
1112
|
+
const app = normalizeMcpAppMetadata(source._meta);
|
|
1113
|
+
let details;
|
|
1114
|
+
if (invocation && app.resourceUri && app.protocol) {
|
|
1115
|
+
const id = crypto.randomUUID();
|
|
1116
|
+
const owned = [...records.values()].filter((record) => record.connection === connection);
|
|
1117
|
+
if (owned.length >= 256) records.delete(owned[0].id);
|
|
1118
|
+
records.set(id, {
|
|
1119
|
+
id,
|
|
1120
|
+
connection,
|
|
1121
|
+
owner: input.owner,
|
|
1122
|
+
...invocation,
|
|
1123
|
+
source: structuredClone(source),
|
|
1124
|
+
args: parameters,
|
|
1125
|
+
appTools
|
|
1126
|
+
});
|
|
1127
|
+
details = {
|
|
1128
|
+
server: input.owner,
|
|
1129
|
+
tool: invocation.toolName,
|
|
1130
|
+
app: {
|
|
1131
|
+
version: 1,
|
|
1132
|
+
resourceUri: app.resourceUri,
|
|
1133
|
+
protocol: app.protocol,
|
|
1134
|
+
result: detached
|
|
1135
|
+
},
|
|
1136
|
+
privateMcp: { invocationId: id }
|
|
1137
|
+
};
|
|
1138
|
+
changed();
|
|
1139
|
+
}
|
|
1140
|
+
const converted = toHeadlessToolResult({
|
|
1141
|
+
...source,
|
|
1142
|
+
piName: name,
|
|
1143
|
+
serverName: input.owner,
|
|
1144
|
+
toolName: name,
|
|
1145
|
+
inputSchema: source.inputSchema
|
|
1146
|
+
}, detached);
|
|
1147
|
+
const output = {
|
|
1148
|
+
...converted,
|
|
1149
|
+
details: details ? {
|
|
1150
|
+
...converted.details,
|
|
1151
|
+
...details
|
|
1152
|
+
} : {
|
|
1153
|
+
...converted.details,
|
|
1154
|
+
app: void 0
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
appResults.set(output, structuredClone(detached));
|
|
1158
|
+
return output;
|
|
1159
|
+
},
|
|
1160
|
+
async readAppResource(name, callSignal) {
|
|
1161
|
+
const source = tools.find((tool) => tool.name === name);
|
|
1162
|
+
const uri = normalizeMcpAppMetadata(source?._meta).resourceUri;
|
|
1163
|
+
if (!uri) throw new Error("Tool declares no App resource.");
|
|
1164
|
+
return request(() => client.readResource({ uri }, {
|
|
1165
|
+
signal: work(callSignal),
|
|
1166
|
+
timeout: REMOTE_MCP_TIMEOUT_MS
|
|
1167
|
+
}), {
|
|
1168
|
+
method: "resources/read",
|
|
1169
|
+
name
|
|
1170
|
+
}, callSignal);
|
|
1171
|
+
},
|
|
1172
|
+
async dispose() {
|
|
1173
|
+
if (closed) return;
|
|
1174
|
+
closed = true;
|
|
1175
|
+
connections.delete(connection);
|
|
1176
|
+
for (const [id, record] of records) if (record.connection === connection) records.delete(id);
|
|
1177
|
+
changed();
|
|
1178
|
+
controller.abort();
|
|
1179
|
+
input.lifetime.removeEventListener("abort", abort);
|
|
1180
|
+
await client.close();
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
const abort = () => {
|
|
1184
|
+
connection.dispose().catch(() => void 0);
|
|
1185
|
+
};
|
|
1186
|
+
input.lifetime.addEventListener("abort", abort, { once: true });
|
|
1187
|
+
try {
|
|
1188
|
+
await request(() => client.connect(new StreamableHTTPClientTransport(url, {
|
|
1189
|
+
fetch: pinned,
|
|
1190
|
+
requestInit: { headers }
|
|
1191
|
+
}), {
|
|
1192
|
+
signal: connectSignal,
|
|
1193
|
+
timeout: REMOTE_MCP_TIMEOUT_MS
|
|
1194
|
+
}), { method: "initialize" }, connectSignal);
|
|
1195
|
+
await connection.listTools(connectSignal);
|
|
1196
|
+
connectSignal.throwIfAborted();
|
|
1197
|
+
if (auth && "credential" in auth && auth.saveAs !== void 0) {
|
|
1198
|
+
const vault = options.vault();
|
|
1199
|
+
if (!vault) throw new Error(VAULT_UNAVAILABLE);
|
|
1200
|
+
await vault.put(NAMESPACE, ownerKey(input.owner, auth.saveAs), {
|
|
1201
|
+
version: 1,
|
|
1202
|
+
origin: url.origin,
|
|
1203
|
+
credential: JSON.parse(JSON.stringify(credential))
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
connectSignal.throwIfAborted();
|
|
1207
|
+
assertLive();
|
|
1208
|
+
connections.add(connection);
|
|
1209
|
+
client.onclose = abort;
|
|
1210
|
+
return connection;
|
|
1211
|
+
} catch (error) {
|
|
1212
|
+
await connection.dispose();
|
|
1213
|
+
throw error;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
//#endregion
|
|
1219
|
+
//#region ../../default/po-mcp/src/services/mcpNamespace/index.ts
|
|
1220
|
+
const HIDDEN = /* @__PURE__ */ new Set([
|
|
1221
|
+
"constructor",
|
|
1222
|
+
"__proto__",
|
|
1223
|
+
"prototype"
|
|
1224
|
+
]);
|
|
1225
|
+
const RESULT_TYPES = `declare namespace Mcp {
|
|
1226
|
+
interface Result<T = unknown> {
|
|
1227
|
+
text: string;
|
|
1228
|
+
images: { data: string; mimeType: string }[];
|
|
1229
|
+
structuredContent?: T;
|
|
1230
|
+
/** Audio, resource links and embedded resources returned by the tool. */
|
|
1231
|
+
blocks?: unknown[];
|
|
1232
|
+
}
|
|
1233
|
+
}`;
|
|
1234
|
+
function record(value) {
|
|
1235
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1236
|
+
}
|
|
1237
|
+
function key(name) {
|
|
1238
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(name) ? name : JSON.stringify(name);
|
|
1239
|
+
}
|
|
1240
|
+
function comment(text) {
|
|
1241
|
+
return text.split(/[\r\n\u2028\u2029]/u)[0].replaceAll("*/", "").slice(0, 160);
|
|
1242
|
+
}
|
|
1243
|
+
function tsType(value, depth = 0) {
|
|
1244
|
+
const schema = record(value);
|
|
1245
|
+
if (!schema || schema.$ref !== void 0 || depth > 20) return "unknown";
|
|
1246
|
+
const convert = (part) => tsType(part, depth + 1);
|
|
1247
|
+
const union = (parts) => [...new Set(parts.map(convert))].join(" | ") || "unknown";
|
|
1248
|
+
if (schema.nullable === true) return `(${convert({
|
|
1249
|
+
...schema,
|
|
1250
|
+
nullable: false
|
|
1251
|
+
})}) | null`;
|
|
1252
|
+
if (Array.isArray(schema.enum)) return schema.enum.map((item) => JSON.stringify(item)).join(" | ") || "never";
|
|
1253
|
+
if (schema.const !== void 0) return JSON.stringify(schema.const);
|
|
1254
|
+
const variants = schema.anyOf ?? schema.oneOf;
|
|
1255
|
+
if (Array.isArray(variants)) return union(variants);
|
|
1256
|
+
if (Array.isArray(schema.allOf)) return schema.allOf.map((part) => `(${convert(part)})`).join(" & ") || "unknown";
|
|
1257
|
+
if (Array.isArray(schema.type)) return union(schema.type.map((type) => ({
|
|
1258
|
+
...schema,
|
|
1259
|
+
type
|
|
1260
|
+
})));
|
|
1261
|
+
switch (schema.type) {
|
|
1262
|
+
case "string":
|
|
1263
|
+
case "boolean":
|
|
1264
|
+
case "null": return schema.type;
|
|
1265
|
+
case "integer":
|
|
1266
|
+
case "number": return "number";
|
|
1267
|
+
case "array": return `(${convert(schema.items)})[]`;
|
|
1268
|
+
case "object": {
|
|
1269
|
+
const properties = record(schema.properties);
|
|
1270
|
+
const additional = schema.additionalProperties;
|
|
1271
|
+
if (!properties) return `Record<string, ${convert(additional)}>`;
|
|
1272
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
1273
|
+
const fields = Object.entries(properties).map(([name, part]) => `${key(name)}${required.has(name) ? "" : "?"}: ${convert(part)}`);
|
|
1274
|
+
const own = fields.length ? `{ ${fields.join("; ")} }` : "{}";
|
|
1275
|
+
return record(additional) ? `${own} & Record<string, ${convert(additional)}>` : own;
|
|
1276
|
+
}
|
|
1277
|
+
default: return "unknown";
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
function typed(tool) {
|
|
1281
|
+
return tool.serverName !== "call" && !HIDDEN.has(tool.serverName) && !HIDDEN.has(tool.toolName);
|
|
1282
|
+
}
|
|
1283
|
+
/** Code mode keys approval by member path, so a name with a dot or whitespace cannot carry its own prompt. */
|
|
1284
|
+
function approvalPath(tool) {
|
|
1285
|
+
const part = /^[^.\s]+$/u;
|
|
1286
|
+
return typed(tool) && part.test(tool.serverName) && part.test(tool.toolName) ? `${tool.serverName}.${tool.toolName}` : void 0;
|
|
1287
|
+
}
|
|
1288
|
+
function groupByServer(tools) {
|
|
1289
|
+
const servers = /* @__PURE__ */ new Map();
|
|
1290
|
+
for (const tool of tools.filter(typed)) {
|
|
1291
|
+
const group = servers.get(tool.serverName) ?? [];
|
|
1292
|
+
group.push(tool);
|
|
1293
|
+
servers.set(tool.serverName, group);
|
|
1294
|
+
}
|
|
1295
|
+
return servers;
|
|
1296
|
+
}
|
|
1297
|
+
const CATALOG_SERVERS = 40;
|
|
1298
|
+
const CATALOG_TOOLS = 20;
|
|
1299
|
+
/** Names reach the skill text from external servers, so keep them to identifier-like characters. */
|
|
1300
|
+
function nameText(value) {
|
|
1301
|
+
return value.replace(/[^\w.:/ -]/gu, "").slice(0, 64);
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* The direct tools the namespace makes redundant: every model-visible tool, an MCP App's included, since its card
|
|
1305
|
+
* opens the App from the code-mode call too. Withdrawn from the model while code mode is bound, so their
|
|
1306
|
+
* declarations stop costing context.
|
|
1307
|
+
*/
|
|
1308
|
+
function mcpToolsCoveredByNamespace(tools) {
|
|
1309
|
+
return tools.filter(isModelVisibleMcpTool).map((tool) => tool.piName);
|
|
1310
|
+
}
|
|
1311
|
+
/** The servers and tool names code mode can call, for the skill. Names only: `discover` has the signatures. */
|
|
1312
|
+
function mcpCatalogText(tools) {
|
|
1313
|
+
const servers = [...groupByServer(tools.filter(isModelVisibleMcpTool))];
|
|
1314
|
+
if (servers.length === 0) return "No MCP server exposes tools in this session. Run `/mcp status` to see why.";
|
|
1315
|
+
const lines = servers.slice(0, CATALOG_SERVERS).map(([server, group]) => {
|
|
1316
|
+
const names = group.slice(0, CATALOG_TOOLS).map((tool) => `\`${nameText(tool.toolName)}\``);
|
|
1317
|
+
const more = group.length > CATALOG_TOOLS ? `, and ${group.length - CATALOG_TOOLS} more` : "";
|
|
1318
|
+
return `- \`${nameText(server)}\` (${group.length}): ${names.join(", ")}${more}`;
|
|
1319
|
+
});
|
|
1320
|
+
if (servers.length > CATALOG_SERVERS) lines.push(`- and ${servers.length - CATALOG_SERVERS} more servers`);
|
|
1321
|
+
return lines.join("\n");
|
|
1322
|
+
}
|
|
1323
|
+
const SUMMARY_SERVERS = 8;
|
|
1324
|
+
const SUMMARY_TOOLS = 5;
|
|
1325
|
+
/**
|
|
1326
|
+
* One line naming the servers and a few tools each, for the skill description the agent sees every turn.
|
|
1327
|
+
* Bounded so a large catalog stays a hint, not a listing; the loaded skill and `discover` carry the rest.
|
|
1328
|
+
*/
|
|
1329
|
+
function mcpCatalogSummary(tools) {
|
|
1330
|
+
const servers = [...groupByServer(tools.filter(isModelVisibleMcpTool))];
|
|
1331
|
+
if (servers.length === 0) return void 0;
|
|
1332
|
+
const parts = servers.slice(0, SUMMARY_SERVERS).map(([server, group]) => {
|
|
1333
|
+
const names = group.slice(0, SUMMARY_TOOLS).map((tool) => nameText(tool.toolName));
|
|
1334
|
+
const more = group.length > SUMMARY_TOOLS ? `, +${group.length - SUMMARY_TOOLS} more` : "";
|
|
1335
|
+
return `${nameText(server)} (${names.join(", ")}${more})`;
|
|
1336
|
+
});
|
|
1337
|
+
if (servers.length > SUMMARY_SERVERS) parts.push(`+${servers.length - SUMMARY_SERVERS} more servers`);
|
|
1338
|
+
return parts.join("; ");
|
|
1339
|
+
}
|
|
1340
|
+
function declarations(tools) {
|
|
1341
|
+
const servers = groupByServer(tools);
|
|
1342
|
+
return [
|
|
1343
|
+
RESULT_TYPES,
|
|
1344
|
+
"/** Exact session MCP names. Tool errors reject with their text. */",
|
|
1345
|
+
"declare const mcp: {",
|
|
1346
|
+
" call(server: string, tool: string, args?: Record<string, unknown>): Promise<Mcp.Result>;",
|
|
1347
|
+
...Array.from(servers, ([server, group]) => [
|
|
1348
|
+
` readonly ${key(server)}: {`,
|
|
1349
|
+
...group.map((tool) => {
|
|
1350
|
+
const input = modelInputSchema(tool);
|
|
1351
|
+
const required = Array.isArray(input.required) && input.required.length > 0;
|
|
1352
|
+
const output = tool.outputSchema === void 0 ? "" : `<${tsType(tool.outputSchema)}>`;
|
|
1353
|
+
return ` /** ${comment(`${server}/${tool.toolName}: ${tool.description ?? ""}`)} */ ${key(tool.toolName)}(args${required ? "" : "?"}: ${tsType(input)}): Promise<Mcp.Result${output}>;`;
|
|
1354
|
+
}),
|
|
1355
|
+
" };"
|
|
1356
|
+
]).flat(),
|
|
1357
|
+
"};"
|
|
1358
|
+
].join("\n");
|
|
1359
|
+
}
|
|
1360
|
+
function resultValue(result) {
|
|
1361
|
+
const text = result.content.filter((block) => block.type === "text").map((block) => block.text).join("\n");
|
|
1362
|
+
if (result.isError) throw new Error(text || "MCP tool failed.");
|
|
1363
|
+
const blocks = record(result.details)?.blocks;
|
|
1364
|
+
return {
|
|
1365
|
+
text,
|
|
1366
|
+
images: result.content.filter((block) => block.type === "image").map(({ data, mimeType }) => ({
|
|
1367
|
+
data,
|
|
1368
|
+
mimeType
|
|
1369
|
+
})),
|
|
1370
|
+
...result.structuredContent === void 0 ? {} : { structuredContent: result.structuredContent },
|
|
1371
|
+
...Array.isArray(blocks) ? { blocks } : {}
|
|
1372
|
+
};
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* One namespace per session, backed by its existing validated and consented direct tools. `retainApp` persists an
|
|
1376
|
+
* App result so the call's card can open the App; without it, a code-mode call shows its result without the App.
|
|
1377
|
+
*/
|
|
1378
|
+
function createMcpNamespace(sessionTools, sessionId, retainApp) {
|
|
1379
|
+
let cached;
|
|
1380
|
+
sessionTools.onChange(() => {
|
|
1381
|
+
cached = void 0;
|
|
1382
|
+
});
|
|
1383
|
+
const visibleTools = () => sessionTools.snapshot().filter(isModelVisibleMcpTool);
|
|
1384
|
+
const gated = (tool) => sessionTools.approval !== void 0 && isDestructiveMcpTool(tool.annotations);
|
|
1385
|
+
return {
|
|
1386
|
+
name: "mcp",
|
|
1387
|
+
portable: true,
|
|
1388
|
+
summary: "Session MCP tools by exact server and tool name: mcp.server.tool(args), or mcp.call(server, tool, args). Pass results to image() for images. A tool with an MCP App shows its App on the call.",
|
|
1389
|
+
get declarations() {
|
|
1390
|
+
return cached ??= declarations(visibleTools());
|
|
1391
|
+
},
|
|
1392
|
+
get approval() {
|
|
1393
|
+
const state = sessionTools.approval;
|
|
1394
|
+
if (state === void 0) return void 0;
|
|
1395
|
+
const policies = {};
|
|
1396
|
+
for (const tool of visibleTools()) {
|
|
1397
|
+
const path = approvalPath(tool);
|
|
1398
|
+
if (path !== void 0 && gated(tool)) policies[path] = mcpToolApproval(tool, state);
|
|
1399
|
+
}
|
|
1400
|
+
return policies;
|
|
1401
|
+
},
|
|
1402
|
+
bind(run) {
|
|
1403
|
+
if (sessionId !== void 0 && run.sessionId !== sessionId) throw new Error("MCP namespace belongs to another session.");
|
|
1404
|
+
const revision = sessionTools.runtimeRevision();
|
|
1405
|
+
const tools = visibleTools();
|
|
1406
|
+
const catalog = /* @__PURE__ */ new Map();
|
|
1407
|
+
for (const tool of tools) {
|
|
1408
|
+
const server = catalog.get(tool.serverName) ?? /* @__PURE__ */ new Map();
|
|
1409
|
+
server.set(tool.toolName, tool);
|
|
1410
|
+
catalog.set(tool.serverName, server);
|
|
1411
|
+
}
|
|
1412
|
+
let wrappers;
|
|
1413
|
+
let appCalls = 0;
|
|
1414
|
+
const retain = async (definition, args, result) => {
|
|
1415
|
+
const details = record(result.details);
|
|
1416
|
+
const app = parseMcpAppSnapshot(details?.app);
|
|
1417
|
+
if (!retainApp || !run.toolCallId || run.background || !app?.resourceUri || details?.privateMcp !== void 0) return void 0;
|
|
1418
|
+
const id = `${run.toolCallId}:mcp:${String(++appCalls)}`;
|
|
1419
|
+
try {
|
|
1420
|
+
return await retainApp({
|
|
1421
|
+
id,
|
|
1422
|
+
piName: definition.piName,
|
|
1423
|
+
server: definition.serverName,
|
|
1424
|
+
tool: definition.toolName,
|
|
1425
|
+
args,
|
|
1426
|
+
app
|
|
1427
|
+
}) ? {
|
|
1428
|
+
id,
|
|
1429
|
+
app
|
|
1430
|
+
} : void 0;
|
|
1431
|
+
} catch {
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
const invoke = async (server, tool, args, approved) => {
|
|
1436
|
+
run.signal.throwIfAborted();
|
|
1437
|
+
const definition = catalog.get(server)?.get(tool);
|
|
1438
|
+
if (!definition) throw new Error(`MCP tool ${server}/${tool} is not available in this session.`);
|
|
1439
|
+
if (sessionTools.runtimeRevision() !== revision) throw new Error("MCP tools changed. Discover and retry in a new exec.");
|
|
1440
|
+
if (!approved && gated(definition) && sessionTools.approval?.autoApproved() !== true) throw new Error(approvalPath(definition) === void 0 ? `MCP tool ${server}/${tool} changes data and its name cannot carry an approval prompt in code mode. Call its direct tool so the person can approve it.` : `MCP tool ${server}/${tool} changes data. Use mcp.${server}.${tool}(args) so the person can approve it.`);
|
|
1441
|
+
const input = JSON.parse(JSON.stringify(args === void 0 ? {} : args));
|
|
1442
|
+
const callArgs = record(input);
|
|
1443
|
+
if (callArgs === void 0) throw new Error("MCP tool arguments must be an object.");
|
|
1444
|
+
wrappers ??= new Map(sessionTools.project().map((wrapper) => [wrapper.name, wrapper]));
|
|
1445
|
+
const wrapper = wrappers.get(definition.piName);
|
|
1446
|
+
if (!wrapper) throw new Error(`MCP tool ${server}/${tool} is not available in this session.`);
|
|
1447
|
+
const started = Date.now();
|
|
1448
|
+
let result;
|
|
1449
|
+
const recorded = (failure, kept) => {
|
|
1450
|
+
const { app: _app, ...details } = record(result?.details) ?? {};
|
|
1451
|
+
const shown = kept === void 0 ? details : {
|
|
1452
|
+
...details,
|
|
1453
|
+
app: {
|
|
1454
|
+
version: 1,
|
|
1455
|
+
resourceUri: kept.app.resourceUri,
|
|
1456
|
+
protocol: kept.app.protocol
|
|
1457
|
+
},
|
|
1458
|
+
appInvocation: kept.id
|
|
1459
|
+
};
|
|
1460
|
+
run.record?.({
|
|
1461
|
+
name: `mcp.${server}.${tool}`,
|
|
1462
|
+
tool: definition.piName,
|
|
1463
|
+
args: callArgs,
|
|
1464
|
+
ok: failure === void 0,
|
|
1465
|
+
ms: Date.now() - started,
|
|
1466
|
+
...failure === void 0 ? {} : { error: failure },
|
|
1467
|
+
...result === void 0 ? {} : { result: {
|
|
1468
|
+
content: result.content,
|
|
1469
|
+
details: shown
|
|
1470
|
+
} }
|
|
1471
|
+
});
|
|
1472
|
+
};
|
|
1473
|
+
try {
|
|
1474
|
+
result = await wrapper.execute("codemode", input, run.signal);
|
|
1475
|
+
const value = resultValue(result);
|
|
1476
|
+
recorded(void 0, await retain(definition, callArgs, result));
|
|
1477
|
+
return value;
|
|
1478
|
+
} catch (error) {
|
|
1479
|
+
recorded(error instanceof Error ? error.message : String(error));
|
|
1480
|
+
throw error;
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
const members = Object.create(null);
|
|
1484
|
+
members.call = (server, tool, args) => invoke(server, tool, args, false);
|
|
1485
|
+
for (const tool of tools.filter(typed)) {
|
|
1486
|
+
const server = members[tool.serverName] ??= Object.create(null);
|
|
1487
|
+
const approved = approvalPath(tool) !== void 0;
|
|
1488
|
+
server[tool.toolName] = (args) => invoke(tool.serverName, tool.toolName, args, approved);
|
|
1489
|
+
}
|
|
1490
|
+
return members;
|
|
1491
|
+
}
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
//#endregion
|
|
1495
|
+
//#region ../../default/po-mcp/src/extensions/workspaces/sessions/(backend)/_lib/serverRoot.edge.ts
|
|
1496
|
+
const NODE_ONLY = "Session-only MCP test servers need a Node host.";
|
|
1497
|
+
const MAX_NOTICE_LENGTH = 300;
|
|
1498
|
+
const describeError = (error) => (error instanceof Error ? error.message : String(error)).slice(0, MAX_NOTICE_LENGTH);
|
|
1499
|
+
const createMcpServerRoot = (context) => {
|
|
1500
|
+
let connection;
|
|
1501
|
+
let privateScope;
|
|
1502
|
+
let appHost = context?.agent;
|
|
1503
|
+
const privateConnections = createMcpConnectionsService({
|
|
1504
|
+
vault: () => privateScope?.resolve(PO_VAULT_CONTRACT),
|
|
1505
|
+
policy: () => privateScope?.resolve(PO_MCP_REMOTE_SERVERS_CONTRACT)
|
|
1506
|
+
});
|
|
1507
|
+
let serversStatus = "Remote MCP is off on this host.";
|
|
1508
|
+
let approvalStatus;
|
|
1509
|
+
const statusText = () => approvalStatus ? `${serversStatus}\n${approvalStatus}` : serversStatus;
|
|
1510
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1511
|
+
const changed = () => {
|
|
1512
|
+
for (const listener of listeners) listener();
|
|
1513
|
+
};
|
|
1514
|
+
let savedAutoApprove = false;
|
|
1515
|
+
const approvalListeners = /* @__PURE__ */ new Set();
|
|
1516
|
+
const setSavedAutoApprove = (enabled) => {
|
|
1517
|
+
if (savedAutoApprove === enabled) return;
|
|
1518
|
+
savedAutoApprove = enabled;
|
|
1519
|
+
for (const listener of approvalListeners) listener();
|
|
1520
|
+
};
|
|
1521
|
+
const approval = createMcpApprovalState({
|
|
1522
|
+
hostAutoApprove: () => savedAutoApprove,
|
|
1523
|
+
onHostChange: (listener) => {
|
|
1524
|
+
approvalListeners.add(listener);
|
|
1525
|
+
return () => {
|
|
1526
|
+
approvalListeners.delete(listener);
|
|
1527
|
+
};
|
|
1528
|
+
}
|
|
1529
|
+
});
|
|
1530
|
+
const sessionTools = {
|
|
1531
|
+
get generation() {
|
|
1532
|
+
return connection?.sessionTools.generation ?? "remote:none";
|
|
1533
|
+
},
|
|
1534
|
+
approval,
|
|
1535
|
+
runtimeRevision: () => connection?.sessionTools.runtimeRevision() ?? 0,
|
|
1536
|
+
readAppResource: async () => {
|
|
1537
|
+
throw new Error("MCP Apps are not available on this host.");
|
|
1538
|
+
},
|
|
1539
|
+
snapshot: () => connection?.sessionTools.snapshot() ?? [],
|
|
1540
|
+
project: () => connection?.sessionTools.project() ?? [],
|
|
1541
|
+
refresh: changed,
|
|
1542
|
+
dispose: () => listeners.clear(),
|
|
1543
|
+
resolveSelectors: (selectors) => connection?.sessionTools.resolveSelectors(selectors) ?? [],
|
|
1544
|
+
onChange: (listener) => {
|
|
1545
|
+
listeners.add(listener);
|
|
1546
|
+
return () => {
|
|
1547
|
+
listeners.delete(listener);
|
|
1548
|
+
};
|
|
1549
|
+
},
|
|
1550
|
+
invoke: async (name, parameters, signal) => {
|
|
1551
|
+
if (!connection) throw new Error(`MCP tool ${name} is not available in this session.`);
|
|
1552
|
+
return connection.sessionTools.invoke(name, parameters, signal);
|
|
1553
|
+
}
|
|
1554
|
+
};
|
|
1555
|
+
let covered = /* @__PURE__ */ new Set();
|
|
1556
|
+
const apps = createMcpAppsService(sessionTools, () => appHost, context?.signal, privateConnections, () => covered);
|
|
1557
|
+
const namespace = createMcpNamespace(sessionTools, context?.host.context.sessionId, apps.retainCodemodeApp);
|
|
1558
|
+
const command = {
|
|
1559
|
+
name: "mcp",
|
|
1560
|
+
description: SERVER_COMMAND_DESCRIPTION,
|
|
1561
|
+
async execute(_args, execution) {
|
|
1562
|
+
await execution.client.notify({
|
|
1563
|
+
title: "Po MCP",
|
|
1564
|
+
body: statusText(),
|
|
1565
|
+
level: "info"
|
|
1566
|
+
});
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
const testServerTool = {
|
|
1570
|
+
name: "mcp_test_server",
|
|
1571
|
+
label: "Test MCP server",
|
|
1572
|
+
description: NODE_ONLY,
|
|
1573
|
+
parameters: McpTestServerParameters,
|
|
1574
|
+
when: PO_HELP_WHEN,
|
|
1575
|
+
mainAgentOnly: true,
|
|
1576
|
+
async execute() {
|
|
1577
|
+
throw new Error(NODE_ONLY);
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1580
|
+
const mountSession = (cordis) => {
|
|
1581
|
+
cordis.inject([PO_SERVER_SCOPE_SERVICE], async (scoped) => {
|
|
1582
|
+
privateScope = requirePoServerScope(scoped);
|
|
1583
|
+
const withdraw = await privateScope.provide(PO_MCP_CONNECTIONS_CONTRACT, privateConnections);
|
|
1584
|
+
return async () => {
|
|
1585
|
+
try {
|
|
1586
|
+
await withdraw();
|
|
1587
|
+
} finally {
|
|
1588
|
+
await privateConnections.dispose();
|
|
1589
|
+
privateScope = void 0;
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
});
|
|
1593
|
+
cordis.inject([PO_HEADLESS_HOST_SERVICE], (scoped) => {
|
|
1594
|
+
const host = scoped.get(PO_HEADLESS_HOST_SERVICE);
|
|
1595
|
+
appHost = host;
|
|
1596
|
+
return () => {
|
|
1597
|
+
if (appHost === host) appHost = void 0;
|
|
1598
|
+
};
|
|
1599
|
+
});
|
|
1600
|
+
cordis.inject([PO_MCP_REMOTE_SERVERS_SERVICE], (scoped) => {
|
|
1601
|
+
const service = readPoMcpRemoteServers(scoped);
|
|
1602
|
+
const serverScope = readPoServerScope(scoped);
|
|
1603
|
+
const reads = /* @__PURE__ */ new Set();
|
|
1604
|
+
let current = new AbortController();
|
|
1605
|
+
let ended = false;
|
|
1606
|
+
const readApproval = async (signal) => {
|
|
1607
|
+
if (!service.loadAutoApprove) return;
|
|
1608
|
+
try {
|
|
1609
|
+
const enabled = await service.loadAutoApprove(signal);
|
|
1610
|
+
if (signal.aborted) return;
|
|
1611
|
+
setSavedAutoApprove(enabled === true);
|
|
1612
|
+
approvalStatus = void 0;
|
|
1613
|
+
} catch (error) {
|
|
1614
|
+
if (signal.aborted) return;
|
|
1615
|
+
setSavedAutoApprove(false);
|
|
1616
|
+
approvalStatus = `Saved MCP approval could not load, so destructive tools ask: ${describeError(error)}`;
|
|
1617
|
+
}
|
|
1618
|
+
};
|
|
1619
|
+
const connectServers = async (signal) => {
|
|
1620
|
+
try {
|
|
1621
|
+
const connected = await connectRemoteMcpServers(service, signal, approval, () => serverScope?.resolve(PO_VAULT_CONTRACT));
|
|
1622
|
+
if (signal.aborted) return await connected.close();
|
|
1623
|
+
connection = connected;
|
|
1624
|
+
const describe = () => {
|
|
1625
|
+
const names = [...new Set(connected.sessionTools.snapshot().map((tool) => tool.serverName))];
|
|
1626
|
+
serversStatus = [names.length ? `Connected: ${names.join(", ")}.` : "No remote MCP server is connected.", ...connected.failures.map((failure) => `${failure.name} failed: ${failure.message}`)].join("\n");
|
|
1627
|
+
};
|
|
1628
|
+
describe();
|
|
1629
|
+
connected.sessionTools.onChange(() => {
|
|
1630
|
+
if (connection !== connected) return;
|
|
1631
|
+
describe();
|
|
1632
|
+
changed();
|
|
1633
|
+
});
|
|
1634
|
+
changed();
|
|
1635
|
+
return;
|
|
1636
|
+
} catch (error) {
|
|
1637
|
+
if (signal.aborted) return void 0;
|
|
1638
|
+
serversStatus = `Remote MCP servers could not load: ${describeError(error)}`;
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
};
|
|
1642
|
+
const refresh = () => {
|
|
1643
|
+
current.abort();
|
|
1644
|
+
current = new AbortController();
|
|
1645
|
+
const { signal } = current;
|
|
1646
|
+
setSavedAutoApprove(false);
|
|
1647
|
+
approvalStatus = void 0;
|
|
1648
|
+
const previous = connection;
|
|
1649
|
+
connection = void 0;
|
|
1650
|
+
serversStatus = previous ? "Remote MCP servers are reloading." : "Remote MCP servers are connecting.";
|
|
1651
|
+
if (previous) changed();
|
|
1652
|
+
const tracked = Promise.allSettled([
|
|
1653
|
+
previous?.close(),
|
|
1654
|
+
readApproval(signal),
|
|
1655
|
+
connectServers(signal)
|
|
1656
|
+
]).then(() => {
|
|
1657
|
+
reads.delete(tracked);
|
|
1658
|
+
});
|
|
1659
|
+
reads.add(tracked);
|
|
1660
|
+
return tracked;
|
|
1661
|
+
};
|
|
1662
|
+
const stopListening = service.onChange?.(() => {
|
|
1663
|
+
if (!ended) refresh();
|
|
1664
|
+
});
|
|
1665
|
+
refresh();
|
|
1666
|
+
return async () => {
|
|
1667
|
+
ended = true;
|
|
1668
|
+
stopListening?.();
|
|
1669
|
+
current.abort();
|
|
1670
|
+
await Promise.allSettled(reads);
|
|
1671
|
+
const closing = connection;
|
|
1672
|
+
connection = void 0;
|
|
1673
|
+
serversStatus = "Remote MCP is off on this host.";
|
|
1674
|
+
approvalStatus = void 0;
|
|
1675
|
+
setSavedAutoApprove(false);
|
|
1676
|
+
changed();
|
|
1677
|
+
await closing?.close();
|
|
1678
|
+
};
|
|
1679
|
+
});
|
|
1680
|
+
cordis.inject([PO_CODEMODE_SERVICE, PO_MCP_REMOTE_SERVERS_SERVICE], (scoped) => {
|
|
1681
|
+
const codemode = readPoCodemode(scoped);
|
|
1682
|
+
if (!codemode) return void 0;
|
|
1683
|
+
const registration = codemode.register("@agimon-ai/po-mcp", namespace);
|
|
1684
|
+
const host = scoped.get(PO_HEADLESS_HOST_SERVICE);
|
|
1685
|
+
let restriction;
|
|
1686
|
+
const withdraw = () => {
|
|
1687
|
+
restriction?.dispose();
|
|
1688
|
+
const excludedTools = mcpToolsCoveredByNamespace(sessionTools.snapshot());
|
|
1689
|
+
restriction = host?.registerToolRestriction({ excludedTools });
|
|
1690
|
+
covered = restriction ? new Set(excludedTools) : /* @__PURE__ */ new Set();
|
|
1691
|
+
};
|
|
1692
|
+
withdraw();
|
|
1693
|
+
const stopWatching = sessionTools.onChange(withdraw);
|
|
1694
|
+
return () => {
|
|
1695
|
+
stopWatching();
|
|
1696
|
+
restriction?.dispose();
|
|
1697
|
+
covered = /* @__PURE__ */ new Set();
|
|
1698
|
+
registration.dispose();
|
|
1699
|
+
};
|
|
1700
|
+
});
|
|
1701
|
+
cordis.inject([PO_HEADLESS_HOST_SERVICE, PO_MCP_REMOTE_SERVERS_SERVICE], (scoped) => {
|
|
1702
|
+
const host = scoped.get(PO_HEADLESS_HOST_SERVICE);
|
|
1703
|
+
const registrations = /* @__PURE__ */ new Map();
|
|
1704
|
+
const reconcile = () => {
|
|
1705
|
+
const tools = sessionTools.project();
|
|
1706
|
+
const names = new Set(tools.map((tool) => tool.name));
|
|
1707
|
+
for (const [name, registration] of registrations) {
|
|
1708
|
+
if (names.has(name)) continue;
|
|
1709
|
+
registration.dispose();
|
|
1710
|
+
registrations.delete(name);
|
|
1711
|
+
}
|
|
1712
|
+
for (const tool of tools) if (!registrations.has(tool.name)) registrations.set(tool.name, host.registerTool(tool));
|
|
1713
|
+
};
|
|
1714
|
+
const stop = sessionTools.onChange(reconcile);
|
|
1715
|
+
reconcile();
|
|
1716
|
+
return () => {
|
|
1717
|
+
stop();
|
|
1718
|
+
for (const registration of registrations.values()) registration.dispose();
|
|
1719
|
+
registrations.clear();
|
|
1720
|
+
};
|
|
1721
|
+
});
|
|
1722
|
+
};
|
|
1723
|
+
return {
|
|
1724
|
+
value: {
|
|
1725
|
+
sessionTools,
|
|
1726
|
+
api: [],
|
|
1727
|
+
commands: [command],
|
|
1728
|
+
appMethods: apps.methods,
|
|
1729
|
+
testServerTool,
|
|
1730
|
+
activities: []
|
|
1731
|
+
},
|
|
1732
|
+
services: [mountSession],
|
|
1733
|
+
onDispose: async () => {
|
|
1734
|
+
try {
|
|
1735
|
+
await privateConnections.dispose();
|
|
1736
|
+
const closing = connection;
|
|
1737
|
+
connection = void 0;
|
|
1738
|
+
await closing?.close();
|
|
1739
|
+
} finally {
|
|
1740
|
+
apps.dispose();
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
};
|
|
1744
|
+
};
|
|
1745
|
+
//#endregion
|
|
1746
|
+
//#region ../../default/po-mcp/src/extensions/workspaces/sessions/(backend)/root.server.ts
|
|
1747
|
+
var root_server_default = defineRoot(createMcpServerRoot);
|
|
1748
|
+
//#endregion
|
|
1749
|
+
//#region ../../default/po-mcp/src/extensions/(backend)/api/mcp/route.server.ts
|
|
1750
|
+
/**
|
|
1751
|
+
* Mounts this package's HTTP API at `mcp`, which the folder names.
|
|
1752
|
+
*
|
|
1753
|
+
* The folder is the declaration: the build reads the base path off it and hands
|
|
1754
|
+
* the browser a client bound to the same segment, so the settings panel can no
|
|
1755
|
+
* longer spell a workspace mount by hand. The root builds it at the host and
|
|
1756
|
+
* workspace levels only.
|
|
1757
|
+
*/
|
|
1758
|
+
var route_server_default$1 = defineRoutedContribution((context) => context.root?.hubApi, { cardinality: "optional" });
|
|
1759
|
+
//#endregion
|
|
1760
|
+
//#region ../../default/po-mcp/src/extensions/workspaces/sessions/(backend)/api/mcp-session/route.server.ts
|
|
1761
|
+
/** Mounts the session's `mcp-session` API: the reachable tool detail the context panel opens. */
|
|
1762
|
+
var route_server_default = defineRoute((context) => context.root.api[0]);
|
|
1763
|
+
//#endregion
|
|
1764
|
+
//#region ../../default/po-mcp/src/extensions/workspaces/sessions/(backend)/command/mcp.server.ts
|
|
1765
|
+
var mcp_server_default = defineServerCommand((context) => context.root.commands[0]);
|
|
1766
|
+
//#endregion
|
|
1767
|
+
//#region ../../default/po-mcp/src/extensions/workspaces/sessions/(backend)/method/apps.server.ts
|
|
1768
|
+
var apps_server_default = defineRoutedContribution((context) => context.root.appMethods, { cardinality: "many" });
|
|
1769
|
+
//#endregion
|
|
1770
|
+
//#region ../../default/po-mcp/src/extensions/workspaces/sessions/(backend)/resource/_lib/codemode-how-to-mcp.server.ts
|
|
1771
|
+
const SKILL = "src/prompts/codemode-how-to-mcp/SKILL.md";
|
|
1772
|
+
/** Always active: code mode is always available, so its guidance is not Help-gated. */
|
|
1773
|
+
var codemode_how_to_mcp_server_default$1 = (context) => ({
|
|
1774
|
+
name: "codemode-how-to-mcp",
|
|
1775
|
+
get description() {
|
|
1776
|
+
const summary = mcpCatalogSummary(context.root.sessionTools.snapshot());
|
|
1777
|
+
return summary === void 0 ? "Call tools on the MCP servers the person configured. No MCP server exposes tools in this session yet." : `Call the person's MCP servers from exec. Connected: ${summary}. Use when a task involves one of these services.`;
|
|
1778
|
+
},
|
|
1779
|
+
kind: "skill",
|
|
1780
|
+
pinned: true,
|
|
1781
|
+
path: packageResourcePath("bundle:///po-mcp/src/extensions/workspaces/sessions/(backend)/resource/_lib/codemode-how-to-mcp.server.ts", SKILL),
|
|
1782
|
+
read: async () => `${(await readPackageResource("bundle:///po-mcp/src/extensions/workspaces/sessions/(backend)/resource/_lib/codemode-how-to-mcp.server.ts", SKILL)).trimEnd()}\n\n## Servers and tools in this session\n\n${mcpCatalogText(context.root.sessionTools.snapshot())}\n`
|
|
1783
|
+
});
|
|
1784
|
+
//#endregion
|
|
1785
|
+
//#region ../../default/po-mcp/src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-mcp.server.ts
|
|
1786
|
+
var codemode_how_to_mcp_server_default = defineResource(codemode_how_to_mcp_server_default$1);
|
|
1787
|
+
//#endregion
|
|
1788
|
+
//#region ../../default/po-mcp/src/extensions/workspaces/sessions/(backend)/resource/help-how-to-mcp.server.ts
|
|
1789
|
+
var help_how_to_mcp_server_default = defineResource({
|
|
1790
|
+
name: "help-how-to-mcp",
|
|
1791
|
+
description: "Inspect domain-scoped MCP servers, authenticate, reload configuration, and troubleshoot tool availability.",
|
|
1792
|
+
when: PO_HELP_WHEN,
|
|
1793
|
+
kind: "skill",
|
|
1794
|
+
read: () => readPackageResource("bundle:///po-mcp/src/extensions/workspaces/sessions/(backend)/resource/help-how-to-mcp.server.ts", "src/prompts/help-how-to-mcp/SKILL.md")
|
|
1795
|
+
});
|
|
1796
|
+
//#endregion
|
|
1797
|
+
//#region ../../default/po-mcp/src/extensions/workspaces/sessions/(backend)/tool/mcp_test_server.server.ts
|
|
1798
|
+
var mcp_test_server_server_default = defineServerTool((context) => context.root.testServerTool);
|
|
1799
|
+
//#endregion
|
|
1800
|
+
//#region ../../default/po-mcp/generated/server.ts
|
|
1801
|
+
const at = (value, context) => typeof value === "function" ? value(context) : value;
|
|
1802
|
+
const many = (value, context) => {
|
|
1803
|
+
const resolved = typeof value === "function" ? value(context) : value;
|
|
1804
|
+
return Array.isArray(resolved) ? resolved : [resolved];
|
|
1805
|
+
};
|
|
1806
|
+
/* v8 ignore next -- generated normalization branch */
|
|
1807
|
+
const defined = (values) => values.filter((value) => value !== void 0);
|
|
1808
|
+
const via = (identity, value) => value === void 0 ? void 0 : {
|
|
1809
|
+
...identity,
|
|
1810
|
+
...value
|
|
1811
|
+
};
|
|
1812
|
+
const serverPlugin = defineServerPlugin({
|
|
1813
|
+
name: "@agimon-ai/po-mcp",
|
|
1814
|
+
providerOverrides: composeServerProviderOverrides(root_server_default$1, root_server_default),
|
|
1815
|
+
injects: composeRootInjects({
|
|
1816
|
+
host: [root_server_default$1],
|
|
1817
|
+
workspace: [root_server_default$1],
|
|
1818
|
+
session: [root_server_default$1, root_server_default]
|
|
1819
|
+
}),
|
|
1820
|
+
host: async (context) => {
|
|
1821
|
+
const scopeHost = await context.scopeRoot("host", root_server_default$1, context);
|
|
1822
|
+
const contextHost = {
|
|
1823
|
+
...context,
|
|
1824
|
+
root: scopeHost.value
|
|
1825
|
+
};
|
|
1826
|
+
return {
|
|
1827
|
+
...composeRootHooks(scopeHost),
|
|
1828
|
+
get api() {
|
|
1829
|
+
return defined([at(route_server_default$1, contextHost)]);
|
|
1830
|
+
},
|
|
1831
|
+
services: [...scopeHost.services ?? []]
|
|
1832
|
+
};
|
|
1833
|
+
},
|
|
1834
|
+
workspace: async (context) => {
|
|
1835
|
+
const scopeHost = await context.scopeRoot("host", root_server_default$1, context);
|
|
1836
|
+
const contextHost = {
|
|
1837
|
+
...context,
|
|
1838
|
+
root: scopeHost.value
|
|
1839
|
+
};
|
|
1840
|
+
return {
|
|
1841
|
+
...composeRootHooks(scopeHost),
|
|
1842
|
+
get api() {
|
|
1843
|
+
return defined([context.hosted("host") ? void 0 : at(route_server_default$1, contextHost)]);
|
|
1844
|
+
},
|
|
1845
|
+
services: [...scopeHost.services ?? []]
|
|
1846
|
+
};
|
|
1847
|
+
},
|
|
1848
|
+
session: async (context) => {
|
|
1849
|
+
const scopeHost = await context.scopeRoot("host", root_server_default$1, context);
|
|
1850
|
+
const contextHost = {
|
|
1851
|
+
...context,
|
|
1852
|
+
root: scopeHost.value
|
|
1853
|
+
};
|
|
1854
|
+
const scopeSession = await context.scopeRoot("session", root_server_default, contextHost);
|
|
1855
|
+
const contextSession = {
|
|
1856
|
+
...contextHost,
|
|
1857
|
+
root: scopeSession.value
|
|
1858
|
+
};
|
|
1859
|
+
return {
|
|
1860
|
+
...composeRootHooks(scopeHost, scopeSession),
|
|
1861
|
+
get api() {
|
|
1862
|
+
return defined([context.hosted("host") ? void 0 : at(route_server_default$1, contextHost), at(route_server_default, contextSession)]);
|
|
1863
|
+
},
|
|
1864
|
+
get commands() {
|
|
1865
|
+
return [via({ name: "mcp" }, at(mcp_server_default, contextSession))];
|
|
1866
|
+
},
|
|
1867
|
+
get methods() {
|
|
1868
|
+
return [...many(apps_server_default, contextSession)];
|
|
1869
|
+
},
|
|
1870
|
+
get resources() {
|
|
1871
|
+
return [at(codemode_how_to_mcp_server_default, contextSession), at(help_how_to_mcp_server_default, contextSession)];
|
|
1872
|
+
},
|
|
1873
|
+
get tools() {
|
|
1874
|
+
return [via({ name: "mcp_test_server" }, at(mcp_test_server_server_default, contextSession))];
|
|
1875
|
+
},
|
|
1876
|
+
services: [...scopeHost.services ?? [], ...scopeSession.services ?? []],
|
|
1877
|
+
get activities() {
|
|
1878
|
+
return [...scopeHost.activities ?? [], ...scopeSession.activities ?? []];
|
|
1879
|
+
}
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
//#endregion
|
|
1884
|
+
export { serverPlugin as default, serverPlugin };
|