@agimon-ai/po-cloudflare 0.0.2-alpha.89 → 0.0.2-alpha.90
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/dist/{abort-signals-C8CttjsR.js → abort-signals-BnnznNpX.js} +1 -1
- package/dist/{agent-BWIWLAhM.js → agent-CefHdEUG.js} +11 -11
- package/dist/agentModel-FdC5v4_o.js +53 -0
- package/dist/{anthropic-messages-DCLLLNuM.js → anthropic-messages-Ch9dw77_.js} +19 -19
- package/dist/{apiContracts-DanHcd9L.js → apiContracts-rCupAn71.js} +2 -2
- package/dist/{approval-B1SXNXl7.js → approval-DPfVKdrQ.js} +2 -2
- package/dist/{approvalPrompt-CqecWrcN.js → approvalPrompt-JOKBomqq.js} +6 -2
- package/dist/{approvalSession-CMRrfHud.js → approvalSession-BNPyEeuh.js} +1 -1
- package/dist/{artifactAdmin-DXz5ZRIY.js → artifactAdmin-D-nFJjJh.js} +14 -9
- package/dist/artifactFiles-Df0ESfTx.js +1 -0
- package/dist/{artifactsApi-CHvWs__I.js → artifactsApi-CGqkonxW.js} +2 -2
- package/dist/assets/assets/{CodeEditorView-CW3hHs3S.js → CodeEditorView-5BYhRvtv.js} +2 -2
- package/dist/assets/assets/{abnfDiagram-WEYOIA3C-BtBaM-_g.js → abnfDiagram-WEYOIA3C-xKxEMuoO.js} +2 -2
- package/dist/assets/assets/{architecture-WOLXFQ4H-B4A5qae_.js → architecture-WOLXFQ4H-alYiRzyY.js} +1 -1
- package/dist/assets/assets/{architectureDiagram-ZHVYKT53-BSz2WzM1.js → architectureDiagram-ZHVYKT53-hEwIBOxE.js} +2 -2
- package/dist/assets/assets/{blockDiagram-RJAE7QA3-qxHidWJG.js → blockDiagram-RJAE7QA3-BcPNuHf5.js} +2 -2
- package/dist/assets/assets/{c4Diagram-XDPPPE54-CLM13eay.js → c4Diagram-XDPPPE54-CNtQyvi_.js} +2 -2
- package/dist/assets/assets/channel-6BXASx4m.js +2 -0
- package/dist/assets/assets/{chunk-2E7WHVMD-BJH2wm-6.js → chunk-2E7WHVMD-BbTgRlEn.js} +2 -2
- package/dist/assets/assets/{chunk-4EMNKR2T-pesVd8hp.js → chunk-4EMNKR2T-B9nSF_8d.js} +2 -2
- package/dist/assets/assets/{chunk-55XCU76K-DsfPRxnz.js → chunk-55XCU76K-BrQ8fxs3.js} +2 -2
- package/dist/assets/assets/{chunk-7S6XSTFO-CAmlppVO.js → chunk-7S6XSTFO-Dy3GI9GJ.js} +2 -2
- package/dist/assets/assets/{chunk-AQDTSKZB-DfDPgxjv.js → chunk-AQDTSKZB-DLm-JB7k.js} +2 -2
- package/dist/assets/assets/{chunk-DSNLSHJZ-B6P3fE0X.js → chunk-DSNLSHJZ-CbBYhmgX.js} +2 -2
- package/dist/assets/assets/{chunk-HAGFOTED-05FLcP6h.js → chunk-HAGFOTED-Cc3Vx9Zq.js} +2 -2
- package/dist/assets/assets/{chunk-HNE4Q36P-FaG01JCD.js → chunk-HNE4Q36P-DDePgYJJ.js} +2 -2
- package/dist/assets/assets/{chunk-NQOKRVIF-Bn2jqesy.js → chunk-NQOKRVIF-Cpmaxo6O.js} +2 -2
- package/dist/assets/assets/{chunk-UHW7PFBP-oV6ndUkg.js → chunk-UHW7PFBP-6KF_miJm.js} +2 -2
- package/dist/assets/assets/{chunk-VQ5W62QI-7ggN-xrc.js → chunk-VQ5W62QI-DQTEnQ5n.js} +2 -2
- package/dist/assets/assets/{chunk-WQQL4CDK-C_D8f7b2.js → chunk-WQQL4CDK-CaBPdBja.js} +2 -2
- package/dist/assets/assets/chunk-XXDRQBXY--PCe54R1.js +2 -0
- package/dist/assets/assets/{chunk-YZO67HFG-cnCoJfb3.js → chunk-YZO67HFG-DhaByAzR.js} +2 -2
- package/dist/assets/assets/{chunk-ZAUX2LTX-DuETshVQ.js → chunk-ZAUX2LTX-DsoO9u_Q.js} +2 -2
- package/dist/assets/assets/{chunk-ZCHMQSOR-mt61E1__.js → chunk-ZCHMQSOR-D0u1uMU6.js} +2 -2
- package/dist/assets/assets/{classDiagram-v2-4MYWR3UA-CpIs2f5O.js → classDiagram-v2-4MYWR3UA-CsD0Gmcl.js} +2 -2
- package/dist/assets/assets/{cose-bilkent-JH36ORCC-lXEiHQoA.js → cose-bilkent-JH36ORCC-euppjQ1O.js} +2 -2
- package/dist/assets/assets/{cynefin-EF2NZ3EQ-C_jKeOfe.js → cynefin-EF2NZ3EQ-DI3wz9Om.js} +1 -1
- package/dist/assets/assets/{cynefinDiagram-WF24UDRP-DAvBxbt2.js → cynefinDiagram-WF24UDRP-D6u1IP8A.js} +2 -2
- package/dist/assets/assets/{dagre-NK4GIZVX-DxwisUpa.js → dagre-NK4GIZVX-C04QzrCD.js} +2 -2
- package/dist/assets/assets/{diagram-CBK3MWTC-CnqCbXJg.js → diagram-CBK3MWTC-k02JwBrY.js} +2 -2
- package/dist/assets/assets/{diagram-I5XIIV2D-9VnFDWtc.js → diagram-I5XIIV2D-D_0fSSQP.js} +2 -2
- package/dist/assets/assets/{diagram-ODIL2UCW-DFd2s1el.js → diagram-ODIL2UCW-DyabmLxk.js} +2 -2
- package/dist/assets/assets/{diagram-PFBEJUXE-BCgDltzi.js → diagram-PFBEJUXE-BaEM-aKw.js} +2 -2
- package/dist/assets/assets/{diagram-RJA3I4VV-C5s1kY-s.js → diagram-RJA3I4VV-Co490tC5.js} +2 -2
- package/dist/assets/assets/{diagram-TYUNFSNR-BiICpvBv.js → diagram-TYUNFSNR-ZHgnk8hB.js} +2 -2
- package/dist/assets/assets/{dist-Vku6RbCO.js → dist-B7_cQFOz.js} +2 -2
- package/dist/assets/assets/{dist-BzkleKK5.js → dist-Bd8HJNOX.js} +2 -2
- package/dist/assets/assets/{dist-D_86nYSf.js → dist-BsOPjOpm.js} +2 -2
- package/dist/assets/assets/{dist-TY6BVgkk.js → dist-CHd0ThVU.js} +2 -2
- package/dist/assets/assets/{dist-DlK7dgKU.js → dist-CxXGWriw.js} +2 -2
- package/dist/assets/assets/{dist-BJGRvAZo.js → dist-Cy1PIIRW.js} +2 -2
- package/dist/assets/assets/{dist-B3TdPEkn.js → dist-CzBMAyJ_.js} +2 -2
- package/dist/assets/assets/{dist-OthXBZJL.js → dist-DtVZN4Fd.js} +2 -2
- package/dist/assets/assets/{dist-CgSecG4Y.js → dist-kJjVkYl3.js} +2 -2
- package/dist/assets/assets/{ebnfDiagram-V4P3TTPT-AwsFv0o1.js → ebnfDiagram-V4P3TTPT-CS5jSli2.js} +2 -2
- package/dist/assets/assets/{elk-QONTBCTQ-CGk5p5p_.js → elk-QONTBCTQ-DOsk3GIN.js} +2 -2
- package/dist/assets/assets/{erDiagram-KYQIGQAA-NLDHNG4a.js → erDiagram-KYQIGQAA-LEON7Q2D.js} +2 -2
- package/dist/assets/assets/{eventmodeling-K75KTNOO-BL3BoM19.js → eventmodeling-K75KTNOO-DVk8BF9P.js} +1 -1
- package/dist/assets/assets/flowDiagram-IUGLLWBU-CBJO7P9U.js +1 -0
- package/dist/assets/assets/{ganttDiagram-R7GPNTJY-0rmTYSNp.js → ganttDiagram-R7GPNTJY-CXwmpedW.js} +2 -2
- package/dist/assets/assets/{gitGraph-VSP46ZUC-DO4p57Qn.js → gitGraph-VSP46ZUC-upqhz-wR.js} +1 -1
- package/dist/assets/assets/{gitGraphDiagram-PDYL7XHY-i9Bgsm2Y.js → gitGraphDiagram-PDYL7XHY-yC_3jHbg.js} +2 -2
- package/dist/assets/assets/index-Bqx-t02e.js +385 -0
- package/dist/assets/assets/index-Qg_cUlio.css +1 -0
- package/dist/assets/assets/{info-OHQRW6UA-Bjs0ocq5.js → info-OHQRW6UA-DTvDFjYm.js} +1 -1
- package/dist/assets/assets/{infoDiagram-MVDRKAX5-B0rS5Q2E.js → infoDiagram-MVDRKAX5-WlAyEzbZ.js} +2 -2
- package/dist/assets/assets/{ishikawaDiagram-HPEHV2GE-iPGkxWYV.js → ishikawaDiagram-HPEHV2GE-CFDL97mG.js} +2 -2
- package/dist/assets/assets/{journeyDiagram-BOSHW7O7-CPNkpwIx.js → journeyDiagram-BOSHW7O7-BTbeZtL2.js} +2 -2
- package/dist/assets/assets/{kanban-definition-FNSA4HC5-BLYacWml.js → kanban-definition-FNSA4HC5-DqQouF8g.js} +2 -2
- package/dist/assets/assets/{line-D4azBUKE.js → line-CCNkEuBp.js} +2 -2
- package/dist/assets/assets/{linear-DKwJkT72.js → linear-CvX0xcV3.js} +2 -2
- package/dist/assets/assets/{mermaid-parser.core-C8XqsUnz.js → mermaid-parser.core-BnjRZBUy.js} +4 -4
- package/dist/assets/assets/{mermaid.core-ChKy70TT.js → mermaid.core-DPd_ycg5.js} +5 -5
- package/dist/assets/assets/{mindmap-definition-6OY57UG3-Dz-Lt8X9.js → mindmap-definition-6OY57UG3-B3NVhUOd.js} +2 -2
- package/dist/assets/assets/{packet-JDAUHWVQ-DkKOvx2x.js → packet-JDAUHWVQ-BFRdcMnY.js} +1 -1
- package/dist/assets/assets/{pegDiagram-ECIUJNBX-sGY-Vh0R.js → pegDiagram-ECIUJNBX-CfeXQ8ge.js} +2 -2
- package/dist/assets/assets/{pie-XZMESJXO-DxWdPqN1.js → pie-XZMESJXO-xkkt1vIR.js} +1 -1
- package/dist/assets/assets/{pieDiagram-GNMPY74T-SUk9CxaP.js → pieDiagram-GNMPY74T-Blj0xxaY.js} +2 -2
- package/dist/assets/assets/{quadrantDiagram-D57K4MC3-BBEIls5H.js → quadrantDiagram-D57K4MC3-hFQu5yDz.js} +2 -2
- package/dist/assets/assets/{radar-ABXABTNO-xCve6zgH.js → radar-ABXABTNO-reGLyNYp.js} +1 -1
- package/dist/assets/assets/{railroad-I3PHUGI6-D8Cn-Gjj.js → railroad-I3PHUGI6-ChN0LGpH.js} +1 -1
- package/dist/assets/assets/{railroad-abnf-LNEFI6M7-C4eesp06.js → railroad-abnf-LNEFI6M7-BXqX4mwm.js} +1 -1
- package/dist/assets/assets/{railroad-ebnf-DWYD2UWJ-CqWgjcE9.js → railroad-ebnf-DWYD2UWJ-CGPEcGIX.js} +1 -1
- package/dist/assets/assets/{railroad-peg-JR7BVNR7-DKUcTKa_.js → railroad-peg-JR7BVNR7-DAULWk5A.js} +1 -1
- package/dist/assets/assets/{railroadDiagram-Y72NRBL7-DSmDdEJh.js → railroadDiagram-Y72NRBL7-DuZKZR7W.js} +2 -2
- package/dist/assets/assets/{requirementDiagram-EQYSW5RA-DuLxpgUq.js → requirementDiagram-EQYSW5RA-CvhmcGL8.js} +2 -2
- package/dist/assets/assets/{sankeyDiagram-SY24JHO5-iQ54Bgcy.js → sankeyDiagram-SY24JHO5-B8lD8QR3.js} +2 -2
- package/dist/assets/assets/{sequenceDiagram-BLEHNHQU-DfmPW_7x.js → sequenceDiagram-BLEHNHQU-XKsGkXym.js} +2 -2
- package/dist/assets/assets/{src-MS9Dw5-V.js → src-B_HDCdWW.js} +2 -2
- package/dist/assets/assets/{stateDiagram-v2-A6IESKWZ-D1G541TZ.js → stateDiagram-v2-A6IESKWZ-Tw3cQ9bI.js} +2 -2
- package/dist/assets/assets/{swimlanes-B3ENRKFQ-CadOFAsm.js → swimlanes-B3ENRKFQ-JRDJpyMO.js} +2 -2
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-kUtYM3P_.js +9 -0
- package/dist/assets/assets/{timeline-definition-JXYKGLGB-J4k-3osw.js → timeline-definition-JXYKGLGB-xCagEiXK.js} +2 -2
- package/dist/assets/assets/{treeView-D4JQ5SDB-btFOG4oD.js → treeView-D4JQ5SDB-De1pUSE8.js} +1 -1
- package/dist/assets/assets/{treemap-SAJKECNS-PIqUGjY3.js → treemap-SAJKECNS-CQmHc8RC.js} +1 -1
- package/dist/assets/assets/{usecaseDiagram-WPOLBNNX-4iej2oKb.js → usecaseDiagram-WPOLBNNX-D5Keco3I.js} +2 -2
- package/dist/assets/assets/{vennDiagram-Q3Y3IDCW-NP_TkFNo.js → vennDiagram-Q3Y3IDCW-Cjed3osH.js} +2 -2
- package/dist/assets/assets/{wardley-7MLQ67FV-l8ArqMwv.js → wardley-7MLQ67FV-CqwkE9Jl.js} +1 -1
- package/dist/assets/assets/{wardleyDiagram-IVAIDKWA-BmAK4IPL.js → wardleyDiagram-IVAIDKWA-BgVXmIA3.js} +2 -2
- package/dist/assets/assets/{webpack-DR7BBdvf.js → webpack-xI4KSDEE.js} +2 -2
- package/dist/assets/assets/{xychartDiagram-4URNHDU4-B0yp6N96.js → xychartDiagram-4URNHDU4-CxHyqMAr.js} +2 -2
- package/dist/assets/bundle-asset-policy.json +1 -1
- package/dist/assets/index.html +2 -2
- package/dist/assets/plugins/assets/base-vjsPIPmn.css +2 -0
- package/dist/assets/plugins/chunks/po-web-runtime-DLkneZYe.js +1 -0
- package/dist/assets/plugins/compositions.json +1 -1
- package/dist/assets/plugins/slots/approval.3e4ea6e4-DZYbAWgc.js +3 -0
- package/dist/assets/plugins/slots/artifacts.84980c32-No6w785t.js +1 -0
- package/dist/assets/plugins/slots/author.8eca1a3d-AUDvoBCJ.js +25 -0
- package/dist/assets/plugins/slots/autocompact.ec8f713f-BwG22R1T.js +1 -0
- package/dist/assets/plugins/slots/{backdrop-bamboo.6e4c928d-FUik19uP.js → backdrop-bamboo.1a4d85e9-02UHAXb4.js} +1 -1
- package/dist/assets/plugins/slots/browse.61a8907a-hYvVfajQ.js +1 -0
- package/dist/assets/plugins/slots/builtin-tools.16ef5e25-D70wkmF4.js +7 -0
- package/dist/assets/plugins/slots/calendar.d337fc49-fzptu3O7.js +2 -0
- package/dist/assets/plugins/slots/{codemode.c58fb583-Bf0-3hc3.js → codemode.5f359b9c-CVziegY_.js} +5 -5
- package/dist/assets/plugins/slots/domain.832848c8-CfWhIzvv.js +1 -0
- package/dist/assets/plugins/slots/edit.7c802139-CAb5BL-6.js +7 -0
- package/dist/assets/plugins/slots/files.364f16c9-OazdKHPm.js +2 -0
- package/dist/assets/plugins/slots/goal.a97b169d-tEbMswFu.js +1 -0
- package/dist/assets/plugins/slots/grep.d8bf9f57-BXR0ieof.js +1 -0
- package/dist/assets/plugins/slots/help.5c78c071-D5V4LAIq.js +3 -0
- package/dist/assets/plugins/slots/infinite-canvas.235e97ea-Idcg2Dbl.js +3 -0
- package/dist/assets/plugins/slots/log.07fd59a4-DUwHgZwz.js +4 -0
- package/dist/assets/plugins/slots/mcp.ea8b6aa2-U-QFsj7b.js +55 -0
- package/dist/assets/plugins/slots/plan.7b30f8d8-Dzt43or-.js +3 -0
- package/dist/assets/plugins/slots/profile.63bc3ae6-BBU87V2I.js +20 -0
- package/dist/assets/plugins/slots/prompts.9d9b47cc-BjR6boX0.js +38 -0
- package/dist/assets/plugins/slots/read.926c024f-DyZj2W97.js +1 -0
- package/dist/assets/plugins/slots/runner.5393fa6c-kwfOuluF.js +9 -0
- package/dist/assets/plugins/slots/scaffold.686222eb-DHk8mNQh.js +1 -0
- package/dist/assets/plugins/slots/session-mcp.8eb68fc9-BEJcdAll.js +2 -0
- package/dist/assets/plugins/slots/sessions.8e378a3b-DWl93_qu.js +1 -0
- package/dist/assets/plugins/slots/skill.56c1cc07-DD5Yf7JN.js +4 -0
- package/dist/assets/plugins/slots/space.056e8bbc-VOc7N7eX.js +1 -0
- package/dist/assets/plugins/slots/subagents.31fc045b-DzZ0C21N.js +7 -0
- package/dist/assets/plugins/slots/template-advanced.9e8350fe-Dy6kJRbG.js +1 -0
- package/dist/assets/plugins/slots/template-desktop.69a46f62-rLhtw1K4.js +7 -0
- package/dist/assets/plugins/slots/template-elegant.381f6acb-BT9gJpTg.js +1 -0
- package/dist/assets/plugins/slots/vault.587549ba-B05zBFzd.js +1 -0
- package/dist/assets/plugins/slots/voice.9c687181-DNoMAG3B.js +1 -0
- package/dist/assets/plugins/slots/{web-search.65013836-B5dgJ7-B.js → web-search.f6292793-B6JfFLRJ.js} +1 -1
- package/dist/assets/plugins/slots/workflows.8a13baad-Dr_-leoo.js +17 -0
- package/dist/assets/pwa/sw.js +1 -1
- package/dist/{atomicJson-B1hsVHDZ.js → atomicJson-C6hOVhww.js} +2 -2
- package/dist/{server-BIvGoW9h.js → authorCommand-CPJZ9GuY.js} +396 -2124
- package/dist/{azure-openai-config-S-quxzTC.js → azure-openai-config-BbiFITgH.js} +2 -2
- package/dist/{azure-openai-responses-DdpV5zh7.js → azure-openai-responses-CE-uwaPU.js} +12 -12
- package/dist/{backgroundWork-CYBMV12z.js → backgroundWork-QAPv-1bt.js} +1 -1
- package/dist/{childProcess-CRTzaAtc.js → childProcess-LEdOKslA.js} +1 -1
- package/dist/{classifier-shared-DFprgrML.js → classifier-shared-BcCvF3Tk.js} +5 -5
- package/dist/{cloudflare-workers-ai-system-one-B0MD19yZ.js → cloudflare-workers-ai-system-one-6Okmz5BA.js} +3 -3
- package/dist/{codemode-BN6V5uUH.js → codemode-DeR5_BN5.js} +1 -1
- package/dist/{config-aNAhyOSx.js → config-BUdt8mdC.js} +3 -3
- package/dist/config-DGbkeoEl.js +2 -0
- package/dist/{contracts-a8BIPZ0o.js → contracts-DcjCSnMi.js} +1 -1
- package/dist/{contracts-Bo9JAdyQ.js → contracts-jqXknpyb.js} +1 -1
- package/dist/{delegation-CxPbZ6QD.js → delegation-wcPYLsPT.js} +1 -1
- package/dist/{diagnostics-BY5LXbHJ.js → diagnostics-C6BV7SgE.js} +2 -2
- package/dist/{env-api-keys-BgCPpU9t.js → env-api-keys-PPG5WnGL.js} +1 -1
- package/dist/{error-body-CeumezyR.js → error-body-CY27POuO.js} +2 -2
- package/dist/{exports-DP8usRS7.js → exports-C3vsMSys.js} +5 -5
- package/dist/{exports-BKNYDCgp.js → exports-CzTrY7_m.js} +2 -2
- package/dist/exports-DAdKfPw_.js +1 -0
- package/dist/{exports-CuqSZu6s.js → exports-DwnG7QxF.js} +2 -2
- package/dist/{exports-KnPwtbR-.js → exports-Dze0sNPp.js} +11 -11
- package/dist/{extensionFile-CMyJ654C.js → extensionFile-CKSACKng.js} +1 -1
- package/dist/{github-copilot-headers-Cq9pnpl2.js → github-copilot-headers-B3aZyzHG.js} +1 -1
- package/dist/{google-generative-ai-DmbUlCGv.js → google-generative-ai-BcIIHr2S.js} +9 -9
- package/dist/{google-shared-Diz2uk39.js → google-shared-CJoY1MZv.js} +5 -5
- package/dist/{google-vertex-CGCpI9Po.js → google-vertex-Bux9hkCz.js} +10 -10
- package/dist/{harnessState-Dbn9set1.js → harnessState-C-NUHmkb.js} +4 -4
- package/dist/{harnessStore-DHjDhGTw.js → harnessStore-C5fv-k9p.js} +4 -4
- package/dist/{hash-IQBoLxOB.js → hash-CMzyoJ1p.js} +1 -1
- package/dist/{headers-Dkgiqogr.js → headers-D2cTuA09.js} +1 -1
- package/dist/{help-B29rvu1F.js → help-PXJwGTPI.js} +1 -1
- package/dist/{hubRevisions-CF8mNSPB.js → htmlInspect-IC04FLx5.js} +13 -1
- package/dist/{http-BZTIF06D.js → http-BAZWb7fO.js} +1 -1
- package/dist/{hubChannel-wzjPBLAw.js → hubChannel-D0SdNcwX.js} +26 -2
- package/dist/{identity-BzB1N-Sn.js → identity-MhOjRxQe.js} +2 -2
- package/dist/{index.edge-D1biKw71.js → index.edge-CJraGSJg.js} +4 -4
- package/dist/{index.edge-BsaqO6YE.js → index.edge-DJi1WW4w.js} +8 -6
- package/dist/{index.edge-9-BIpQCR.js → index.edge-qw8RWTyE.js} +1 -1
- package/dist/{layeredConfig-P_cU6wVP.js → layeredConfig-DQGOMDeR.js} +23 -6
- package/dist/{mcpProjection-BSZsJdkt.js → mcpProjection-rLKZ8d4q.js} +1 -1
- package/dist/{migrations-DJBPDwSR.js → migrations-DMfOMhPE.js} +2 -2
- package/dist/{mistral-conversations-Bv_m1MRF.js → mistral-conversations-DKHpeIk9.js} +12 -12
- package/dist/{models-D50yN8Ag.js → models-CpOiq0Dv.js} +13 -13
- package/dist/{node-B4kSjHeD.js → node-PNZ9g6wy.js} +1 -1
- package/dist/{notification-og58SmVr.js → notification-DlNVIcKt.js} +1 -1
- package/dist/{openai-D6Q-l6hT.js → openai-69NOv-G_.js} +186 -186
- package/dist/{openai-codex-responses-BnoiTqYV.js → openai-codex-responses-D3OpoahM.js} +14 -14
- package/dist/{openai-completions-C68qs5rI.js → openai-completions-DCbbWPnd.js} +16 -16
- package/dist/{openai-decisions-BSxU_aoV.js → openai-decisions-B4N34iTY.js} +3 -3
- package/dist/{openai-responses-D6hXen-k.js → openai-responses-By-qww_Y.js} +13 -13
- package/dist/{openai-responses-shared-BD8K7FAC.js → openai-responses-shared-CZpaHLkq.js} +7 -7
- package/dist/{openrouter-cost-BPam8wyW.js → openrouter-cost-s2mizc_r.js} +1 -1
- package/dist/{openrouter-images-DylXiHy7.js → openrouter-images-CwGaTi2T.js} +7 -7
- package/dist/{packageApi-BPVncFwI.js → packageApi-DlKM70zC.js} +1 -1
- package/dist/{pi-messages-DaIlYYlO.js → pi-messages-DhiSKnLA.js} +6 -6
- package/dist/{piConfig-6FoD2mq9.js → piConfig-BzGL0C2z.js} +4 -4
- package/dist/piSettings-VxZttOsG.js +1 -0
- package/dist/{platform-BCUKNvhU.js → platform-DoiVBuND.js} +1 -1
- package/dist/{pluginProtocol-Hzd80Kiv.js → pluginProtocol-Dsl-hYtA.js} +1 -1
- package/dist/pluginProtocol-TIdoxuZw.js +1 -0
- package/dist/{presetConfig-DLUqd3VN.js → presetConfig-B832-Zha.js} +4 -4
- package/dist/{profileSources-D2xyo_A5.js → profileSources-L6K8sMyI.js} +2 -2
- package/dist/{profiles-DZxVXK_h.js → profiles-D1qo-3-R.js} +3 -3
- package/dist/{protocol-ByvFPSki.js → protocol-D5DBhfxE.js} +1 -1
- package/dist/{provider-env-DJb40UF7.js → provider-env-xyi8_nIF.js} +1 -1
- package/dist/{provider-retry-jpvs7ixx.js → provider-retry-VcOOOYby.js} +1 -1
- package/dist/{sanitize-unicode-B1ZFaEtf.js → sanitize-unicode-CMvnlu8P.js} +1 -1
- package/dist/{scaffoldRegistry-ZeDSU1AR.js → scaffoldRegistry-Bhgb73AX.js} +2 -2
- package/dist/{server-CaRuhZge.js → server-0KWpMaVY.js} +72 -16
- package/dist/{server-CcNcg2PP.js → server-6spyTi1O.js} +14 -14
- package/dist/{server-Hv7hUu1N.js → server-9Oftjytt.js} +8 -8
- package/dist/{server-DIJNaHLy.js → server-B4aW9tFv.js} +6 -6
- package/dist/{server-Cwo7gbi6.js → server-BBXbbS3c.js} +8 -8
- package/dist/{server-Ba4HwWdc.js → server-BLA-uFvh.js} +2 -2
- package/dist/{server-BuoYj5Kj.js → server-BLUskeV2.js} +9 -9
- package/dist/{server-DTT-TUzH.js → server-BQMKfzGP.js} +3 -3
- package/dist/{server-DMU94F4x.js → server-BjvfDB5q.js} +5 -5
- package/dist/{server-Ci4k8RHc.js → server-Bpg5EwKs.js} +4 -4
- package/dist/{server-DjePJ1lJ.js → server-BsvvbP9U.js} +6 -6
- package/dist/server-Bw-w_sHR.js +1375 -0
- package/dist/{server-Bmv9KUA4.js → server-C4cpECf4.js} +10 -10
- package/dist/{server-CJe-GHtn.js → server-CIhRxOKc.js} +10 -10
- package/dist/{server-jxbANgez.js → server-CPGaBYLg.js} +81 -101
- package/dist/{server-CWCwVP3_.js → server-CVdVwC8n.js} +7 -7
- package/dist/{server-Dy6qSebd.js → server-CY7M3aqb.js} +25 -19
- package/dist/{server-bYmG_MM_.js → server-D5oT18XI.js} +4 -4
- package/dist/{server-SCUmHF_w.js → server-DC5Im7Qw.js} +4 -4
- package/dist/{server-CeFOzCN3.js → server-DIJekipS.js} +8 -8
- package/dist/{server-lcDVE3cE.js → server-DLVSrl1x.js} +3 -3
- package/dist/{server-CXspFx3g.js → server-DRBOU40_.js} +6 -6
- package/dist/{server-DAh6drR2.js → server-DSyITpKz.js} +6 -6
- package/dist/{server-VaN7oNJB.js → server-DUU6zjQT.js} +9 -9
- package/dist/{server-DiK7811Q.js → server-DZqfZ7f6.js} +7 -7
- package/dist/server-D_ewD_jq.js +2006 -0
- package/dist/{server-BxLUB5Ou.js → server-DgBsJmk7.js} +9 -9
- package/dist/{server-o5bx1iFc.js → server-DipN0QoY.js} +6 -6
- package/dist/{server-BKZqYHGG.js → server-DojfPNEY.js} +62 -39
- package/dist/{server-Cqj87nQ-.js → server-Dr-fQwcV.js} +3 -3
- package/dist/{server-BTFc9Df5.js → server-DrL356i0.js} +71 -34
- package/dist/{server-CiICC-B8.js → server-DwnhnGUw.js} +8 -8
- package/dist/{server-CTTuomfr.js → server-WyWG_zMx.js} +18 -17
- package/dist/{server-C5wOVHJv.js → server-YT1ymDVi.js} +13 -13
- package/dist/{server-CL_9ixSF.js → server-YuZTDXAy.js} +6 -6
- package/dist/{server-B0CVzuN6.js → server-gYLwMCgF.js} +3 -3
- package/dist/{server-Bfuf0Rmq.js → server-h2ts3mMq.js} +4 -4
- package/dist/{server-TDKYW7sp.js → server-lbI8Erk4.js} +79 -14
- package/dist/{server-9RAW17C2.js → server-qHKCvuue.js} +126 -26
- package/dist/{server-DfZR0UEc.js → server-t2gNrqTY.js} +7 -7
- package/dist/{serverPlugin-COQJWpep.js → serverPlugin-wPqQhDmS.js} +126 -122
- package/dist/{session-resources-BvR3cwiH.js → session-resources-CfytrwP_.js} +1 -1
- package/dist/{sessionConfig-DiGdN3gI.js → sessionConfig-DMa9AdDI.js} +12 -12
- package/dist/{simple-options-Cp5p46f9.js → simple-options-Bwi6AFF6.js} +4 -4
- package/dist/{space-8i6I3fUd.js → space-xh5HBK-c.js} +5 -5
- package/dist/{streaming-json-CZyrX_Ux.js → streaming-json-BgQiuZOb.js} +1 -1
- package/dist/{system-one-shared-Du6bka0h.js → system-one-shared-BXskYzVf.js} +3 -3
- package/dist/{transform-messages-CBj9g2mx.js → transform-messages-UQNXxbJd.js} +2 -2
- package/dist/{type-fPaiVK0V.js → type-CFrzIZRB.js} +73 -14
- package/dist/{calendarSetup-DcEufHWp.js → type-c-ODYlaZ.js} +60 -44
- package/dist/{typesafe-system-one-C7YFgvrX.js → typesafe-system-one-C6X0i9dw.js} +3 -3
- package/dist/{uuid-BVI0BZsx.js → uuid-CdK_wcYv.js} +1 -1
- package/dist/{validation-Do1Y1TFc.js → validation-nXPKTuW6.js} +2 -2
- package/dist/{vaultSettings-CAek2DF5.js → vaultSettings-BKoJd3WF.js} +1 -1
- package/dist/{voiceTools-1XZg4RTL.js → voiceTools-LtqVxykP.js} +1 -1
- package/dist/web-AWdkpv3P.js +4 -0
- package/dist/worker.js +1148 -639
- package/dist/{workflow-DXJI9fpC.js → workflow-DEDCjAJw.js} +1 -1
- package/dist/{workflowServices-QQ2g7SME.js → workflowServices-CB8qFTiL.js} +2 -2
- package/package.json +51 -50
- package/dist/artifactFiles-DrNLglCB.js +0 -1
- package/dist/assets/assets/channel-CBsStcE2.js +0 -2
- package/dist/assets/assets/chunk-XXDRQBXY-DTlLOyWw.js +0 -2
- package/dist/assets/assets/flowDiagram-IUGLLWBU-JEORBv3K.js +0 -1
- package/dist/assets/assets/index-CFxbF4MM.js +0 -256
- package/dist/assets/assets/index-D5RTn0D8.css +0 -1
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-CJa3dc5g.js +0 -9
- package/dist/assets/plugins/assets/base-BA_Fi-IN.css +0 -2
- package/dist/assets/plugins/chunks/po-web-runtime-DxgrKik6.js +0 -1
- package/dist/assets/plugins/slots/approval.09e72f36-DUh6fya8.js +0 -3
- package/dist/assets/plugins/slots/artifacts.50b639bb-DLYdkycz.js +0 -1
- package/dist/assets/plugins/slots/author.ea449ace-upSGMrCz.js +0 -93
- package/dist/assets/plugins/slots/autocompact.6f428144-DfgeAD14.js +0 -1
- package/dist/assets/plugins/slots/browse.fa1f1a50-BlYKmOSO.js +0 -1
- package/dist/assets/plugins/slots/builtin-tools.75108f21-B_AcDjpb.js +0 -7
- package/dist/assets/plugins/slots/calendar.d8b70190-R3dh8PXo.js +0 -2
- package/dist/assets/plugins/slots/domain.753f9f92-IJUs5dGv.js +0 -1
- package/dist/assets/plugins/slots/edit.804fec90-DvkDDRLU.js +0 -7
- package/dist/assets/plugins/slots/files.66ffc636-CvBDItLt.js +0 -2
- package/dist/assets/plugins/slots/goal.45dffa01-Lbnm_JdF.js +0 -1
- package/dist/assets/plugins/slots/grep.98262cff-Bj3I4T55.js +0 -1
- package/dist/assets/plugins/slots/help.5fbd20f7-D3r4ax78.js +0 -3
- package/dist/assets/plugins/slots/log.cb964209-DyDosKYK.js +0 -4
- package/dist/assets/plugins/slots/mcp.82cc1ff5-Bc9-HLhT.js +0 -55
- package/dist/assets/plugins/slots/plan.3852ba52-DG7XdQxI.js +0 -3
- package/dist/assets/plugins/slots/profile.ab16dcec-BM6VXyAs.js +0 -20
- package/dist/assets/plugins/slots/prompts.ae48c07a-BSQbt_VK.js +0 -38
- package/dist/assets/plugins/slots/read.4560591a-tfu0nxsl.js +0 -1
- package/dist/assets/plugins/slots/runner.6e494d59-DF9v07Wa.js +0 -9
- package/dist/assets/plugins/slots/scaffold.d87a6ee0-DCc7nMR5.js +0 -1
- package/dist/assets/plugins/slots/session-mcp.2be84084-NhKuyCfo.js +0 -2
- package/dist/assets/plugins/slots/sessions.6f47cb4c-vUgB9HmB.js +0 -1
- package/dist/assets/plugins/slots/skill.62a0a1b3-DIrtjrmN.js +0 -4
- package/dist/assets/plugins/slots/space.65a27e5a-C_MPhVO5.js +0 -1
- package/dist/assets/plugins/slots/subagents.8bb9992c-DVEp-S5L.js +0 -7
- package/dist/assets/plugins/slots/template-advanced.59f3f98a-BpkPWTsV.js +0 -1
- package/dist/assets/plugins/slots/template-desktop.0f0b8491-CqF1C5wf.js +0 -7
- package/dist/assets/plugins/slots/template-elegant.0e3b0acf-W_1hmUUj.js +0 -1
- package/dist/assets/plugins/slots/vault.3cbfcdc3-CWvGQRnI.js +0 -1
- package/dist/assets/plugins/slots/voice.a952113d-Bh75xCmK.js +0 -1
- package/dist/assets/plugins/slots/workflows.cbc5c5c0-DlHnecLJ.js +0 -17
- package/dist/config-CVXDWPf6.js +0 -2
- package/dist/cordisHost-4o4-k3mw.js +0 -25
- package/dist/exports-DlQgT_4j.js +0 -1
- package/dist/piSettings-D0K8xTXh.js +0 -1
- package/dist/pluginProtocol-tN2K6_TF.js +0 -1
- package/dist/web-Cu4UJwaV.js +0 -4
|
@@ -0,0 +1,2006 @@
|
|
|
1
|
+
import { At as composeServerProviderOverrides, Ht as readPoFs, gn as requirePoServerScope, jt as defineServerMethod, mn as defineServiceContract, pn as PO_SERVER_SCOPE_SERVICE, t as defineServerPlugin } from "./serverPlugin-wPqQhDmS.js";
|
|
2
|
+
import { n as RootBoundReplaceError, r as replaceRootBoundFile } from "./platform-DoiVBuND.js";
|
|
3
|
+
import { n as readPackageResource, t as packageResourcePath } from "./index.edge-DJi1WW4w.js";
|
|
4
|
+
import { p as validateArtifactRead } from "./artifactAdmin-D-nFJjJh.js";
|
|
5
|
+
import { n as defineApiRoutes, t as apiResponse } from "./htmlInspect-IC04FLx5.js";
|
|
6
|
+
import "./web-AWdkpv3P.js";
|
|
7
|
+
import "./artifactFiles-Df0ESfTx.js";
|
|
8
|
+
import { c as defineRoot, i as defineCommand, l as defineRoute, n as composeRootInjects, o as defineMethod, p as defineTool, r as defineChannel, s as defineResource, t as composeRootHooks } from "./extensionFile-CKSACKng.js";
|
|
9
|
+
import { i as readPoCodemode, n as PO_CODEMODE_SERVICE } from "./codemode-DeR5_BN5.js";
|
|
10
|
+
import { t as PO_HELP_WHEN } from "./help-PXJwGTPI.js";
|
|
11
|
+
import { t as Hono } from "./dist-C6IqjC-m.js";
|
|
12
|
+
import { C as serializeStructuredDocument, D as digestOf, E as DocumentRequestError, O as parse, S as readOoxmlArchive, T as detectDialect, _ as AUTHOR_DESCRIBE_TOOL_NAME, a as AUTHOR_ALIAS_PATTERN, b as parseXlsx, c as parseUseAuthorToolInput, g as resolveDocument, h as readSource, i as OPEN_AUTHORING_FILE_TOOL_NAME, l as authorBridgeMethod, m as readDocument, n as AUTHOR_DIRECT_TOOL_NAMES, o as parseDescribeAuthorToolsInput, p as AUTHOR_DOCUMENT_MAX_BYTES, r as createAuthorTools, s as parseOpenAuthoringFileInput, t as createAuthorCommand, u as PO_AUTHOR_CONTRACT, v as AUTHOR_USE_TOOL_NAME, w as parseMarkdownSlides, x as preflightStructuredDocument, y as parseStructuredDocument } from "./authorCommand-CPJZ9GuY.js";
|
|
13
|
+
import { randomUUID } from "node:crypto";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
//#region ../../foundations/po-author/src/services/authorCatalog/index.ts
|
|
16
|
+
var UnavailableAuthorCatalog = class {
|
|
17
|
+
open() {
|
|
18
|
+
return Promise.reject(/* @__PURE__ */ new Error("The Author session service is unavailable."));
|
|
19
|
+
}
|
|
20
|
+
describe() {
|
|
21
|
+
return Promise.reject(/* @__PURE__ */ new Error("The Author session service is unavailable."));
|
|
22
|
+
}
|
|
23
|
+
execute() {
|
|
24
|
+
return Promise.reject(/* @__PURE__ */ new Error("The Author session service is unavailable."));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/** Uses an injected typed service directly. No internal transport is discovered here. */
|
|
28
|
+
function createAuthorCatalog(host) {
|
|
29
|
+
return host ?? new UnavailableAuthorCatalog();
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region ../../foundations/po-author/src/services/authorGuides/index.ts
|
|
33
|
+
const BASE_GUIDE = "codemode-how-to-author";
|
|
34
|
+
const BASE_DESCRIPTION = "Open a file as a canvas the person sees, then read and change it through the tools that canvas offers. Use to review or edit a document, image or sheet together with the person from exec.";
|
|
35
|
+
/** A guide shipped in this package at `src/prompts/<name>/SKILL.md`. */
|
|
36
|
+
function packageGuide(name, description, pinned) {
|
|
37
|
+
const file = `src/prompts/${name}/SKILL.md`;
|
|
38
|
+
const path = packageResourcePath("bundle:///po-author/src/services/authorGuides/index.ts", file);
|
|
39
|
+
return {
|
|
40
|
+
name,
|
|
41
|
+
get description() {
|
|
42
|
+
return typeof description === "string" ? description : description();
|
|
43
|
+
},
|
|
44
|
+
kind: "skill",
|
|
45
|
+
...pinned ? { pinned: true } : {},
|
|
46
|
+
...path === void 0 ? {} : { path },
|
|
47
|
+
read: () => readPackageResource("bundle:///po-author/src/services/authorGuides/index.ts", file)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Synchronous, unlike the guide's own frontmatter; the base guide's description names the guide to load per type. */
|
|
51
|
+
const typeDescription = (type) => `Review and edit an open ${type} canvas through webmcp: its tools, ordering and refusals. Load before calling its tools.`;
|
|
52
|
+
/**
|
|
53
|
+
* Discloses Author guides while canvases are open: the pinned base guide while any canvas is open,
|
|
54
|
+
* and one unpinned guide per open type that has one, so type guides stay loadable but out of the prompt.
|
|
55
|
+
*
|
|
56
|
+
* Changes coalesce in a microtask and only the differences are registered or disposed. A change
|
|
57
|
+
* during a turn waits for `agent_end`: a registration while the host prepares the system prompt or
|
|
58
|
+
* dispatches a turn hook fails that turn, so a canvas opened mid-turn is disclosed on the next one.
|
|
59
|
+
*/
|
|
60
|
+
function createAuthorGuides(agent, service) {
|
|
61
|
+
const base = packageGuide(BASE_GUIDE, () => {
|
|
62
|
+
const types = [...new Set(service.openCanvases().map((canvas) => canvas.type))];
|
|
63
|
+
if (types.length === 0) return BASE_DESCRIPTION;
|
|
64
|
+
const named = types.map((type) => {
|
|
65
|
+
const guide = service.guide(type)?.name;
|
|
66
|
+
return guide === void 0 ? type : `${type} (load ${guide})`;
|
|
67
|
+
});
|
|
68
|
+
return `${BASE_DESCRIPTION} Open now: ${named.join(", ")}.`;
|
|
69
|
+
}, true);
|
|
70
|
+
const builtIn = /* @__PURE__ */ new Map();
|
|
71
|
+
const registered = /* @__PURE__ */ new Map();
|
|
72
|
+
let disposed = false;
|
|
73
|
+
let scheduled = false;
|
|
74
|
+
let inTurn = false;
|
|
75
|
+
let flushTimer;
|
|
76
|
+
const wanted = () => {
|
|
77
|
+
const next = /* @__PURE__ */ new Map();
|
|
78
|
+
const canvases = service.openCanvases();
|
|
79
|
+
if (canvases.length === 0) return next;
|
|
80
|
+
next.set(BASE_GUIDE, base);
|
|
81
|
+
for (const { type } of canvases) {
|
|
82
|
+
const guide = service.guide(type);
|
|
83
|
+
if (guide === void 0 || next.has(guide.name)) continue;
|
|
84
|
+
let resource = guide.resource ?? builtIn.get(guide.name);
|
|
85
|
+
if (resource === void 0) {
|
|
86
|
+
resource = packageGuide(guide.name, typeDescription(type), false);
|
|
87
|
+
builtIn.set(guide.name, resource);
|
|
88
|
+
}
|
|
89
|
+
next.set(guide.name, resource);
|
|
90
|
+
}
|
|
91
|
+
return next;
|
|
92
|
+
};
|
|
93
|
+
const apply = () => {
|
|
94
|
+
scheduled = false;
|
|
95
|
+
if (disposed || inTurn) return;
|
|
96
|
+
const next = wanted();
|
|
97
|
+
for (const [name, entry] of registered) {
|
|
98
|
+
if (next.get(name) === entry.resource) continue;
|
|
99
|
+
registered.delete(name);
|
|
100
|
+
entry.registration.dispose();
|
|
101
|
+
}
|
|
102
|
+
for (const [name, resource] of next) {
|
|
103
|
+
if (registered.has(name)) continue;
|
|
104
|
+
try {
|
|
105
|
+
registered.set(name, {
|
|
106
|
+
resource,
|
|
107
|
+
registration: agent.registerResource(resource)
|
|
108
|
+
});
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.warn(`Author stopped disclosing canvas guides: ${error instanceof Error ? error.message : String(error)}`);
|
|
111
|
+
stop();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const schedule = () => {
|
|
117
|
+
if (scheduled || disposed) return;
|
|
118
|
+
scheduled = true;
|
|
119
|
+
queueMicrotask(apply);
|
|
120
|
+
};
|
|
121
|
+
const startTurn = () => {
|
|
122
|
+
inTurn = true;
|
|
123
|
+
};
|
|
124
|
+
const endTurn = () => {
|
|
125
|
+
inTurn = false;
|
|
126
|
+
if (flushTimer !== void 0 || disposed) return;
|
|
127
|
+
flushTimer = setTimeout(() => {
|
|
128
|
+
flushTimer = void 0;
|
|
129
|
+
schedule();
|
|
130
|
+
}, 0);
|
|
131
|
+
};
|
|
132
|
+
const hooks = [
|
|
133
|
+
agent.registerHook({
|
|
134
|
+
event: "agent_start",
|
|
135
|
+
handle: startTurn
|
|
136
|
+
}),
|
|
137
|
+
agent.registerHook({
|
|
138
|
+
event: "before_agent_start",
|
|
139
|
+
handle: startTurn
|
|
140
|
+
}),
|
|
141
|
+
agent.registerHook({
|
|
142
|
+
event: "agent_end",
|
|
143
|
+
handle: endTurn
|
|
144
|
+
})
|
|
145
|
+
];
|
|
146
|
+
const unsubscribe = service.subscribe(schedule);
|
|
147
|
+
schedule();
|
|
148
|
+
function stop() {
|
|
149
|
+
if (disposed) return;
|
|
150
|
+
disposed = true;
|
|
151
|
+
unsubscribe();
|
|
152
|
+
if (flushTimer !== void 0) clearTimeout(flushTimer);
|
|
153
|
+
for (const entry of registered.values()) entry.registration.dispose();
|
|
154
|
+
registered.clear();
|
|
155
|
+
for (const hook of hooks) hook.dispose();
|
|
156
|
+
}
|
|
157
|
+
return { dispose: stop };
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region ../../foundations/po-author/src/types/authorKind.ts
|
|
161
|
+
const IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
162
|
+
"avif",
|
|
163
|
+
"bmp",
|
|
164
|
+
"gif",
|
|
165
|
+
"jpeg",
|
|
166
|
+
"jpg",
|
|
167
|
+
"png",
|
|
168
|
+
"svg",
|
|
169
|
+
"webp"
|
|
170
|
+
]);
|
|
171
|
+
const VIDEO_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
172
|
+
"m4v",
|
|
173
|
+
"mov",
|
|
174
|
+
"mp4",
|
|
175
|
+
"webm"
|
|
176
|
+
]);
|
|
177
|
+
function structuredFormat(path) {
|
|
178
|
+
const lower = path.toLowerCase();
|
|
179
|
+
if (lower.endsWith(".slides.md")) return "markdown-slides";
|
|
180
|
+
if (lower.endsWith(".csv")) return "csv";
|
|
181
|
+
if (lower.endsWith(".pptx")) return "pptx";
|
|
182
|
+
if (lower.endsWith(".xlsx")) return "xlsx";
|
|
183
|
+
}
|
|
184
|
+
/** A Mermaid source file: edited as text, previewed as the diagram it draws. */
|
|
185
|
+
function isMermaidPath(path) {
|
|
186
|
+
return /\.(?:mmd|mermaid)$/iu.test(path);
|
|
187
|
+
}
|
|
188
|
+
function authorKindForPath(path) {
|
|
189
|
+
const lower = path.toLowerCase();
|
|
190
|
+
if (/\.stories\.(?:js|jsx|ts|tsx)$/u.test(lower)) return "story-preview";
|
|
191
|
+
const format = structuredFormat(path);
|
|
192
|
+
if (format === "markdown-slides") return "slides";
|
|
193
|
+
if (format !== void 0) return format;
|
|
194
|
+
const extension = lower.split(".").at(-1) ?? "";
|
|
195
|
+
if (extension === "md" || isMermaidPath(lower)) return "markdown";
|
|
196
|
+
if (IMAGE_EXTENSIONS.has(extension)) return "image";
|
|
197
|
+
if (VIDEO_EXTENSIONS.has(extension)) return "video";
|
|
198
|
+
if (extension === "pdf") return "pdf";
|
|
199
|
+
if (extension === "html" || extension === "htm") return "html";
|
|
200
|
+
if ([
|
|
201
|
+
"txt",
|
|
202
|
+
"json",
|
|
203
|
+
"yaml",
|
|
204
|
+
"yml",
|
|
205
|
+
"xml",
|
|
206
|
+
"css",
|
|
207
|
+
"js",
|
|
208
|
+
"ts",
|
|
209
|
+
"tsx",
|
|
210
|
+
"jsx"
|
|
211
|
+
].includes(extension)) return "text";
|
|
212
|
+
return "opaque";
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region ../../foundations/po-author/src/services/structuredDocuments/xmlText.ts
|
|
216
|
+
function decodeXmlText(value) {
|
|
217
|
+
return value.replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", "\"").replaceAll("'", "'").replaceAll("&", "&");
|
|
218
|
+
}
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region ../../foundations/po-author/src/services/authorPreviewRender/index.ts
|
|
221
|
+
const ID_PATTERN = /^[a-z][a-z0-9-]{0,31}$/u;
|
|
222
|
+
const AUTHOR_PREVIEW_TEXT_MAX_BYTES = 4096;
|
|
223
|
+
const AUTHOR_PREVIEW_HTML_MAX_BYTES = 65536;
|
|
224
|
+
/** The media types for every extension `authorKindForPath` reads as image, video, or PDF. */
|
|
225
|
+
const MEDIA_TYPES = {
|
|
226
|
+
avif: "image/avif",
|
|
227
|
+
bmp: "image/bmp",
|
|
228
|
+
gif: "image/gif",
|
|
229
|
+
jpeg: "image/jpeg",
|
|
230
|
+
jpg: "image/jpeg",
|
|
231
|
+
png: "image/png",
|
|
232
|
+
svg: "image/svg+xml",
|
|
233
|
+
webp: "image/webp",
|
|
234
|
+
m4v: "video/mp4",
|
|
235
|
+
mov: "video/quicktime",
|
|
236
|
+
mp4: "video/mp4",
|
|
237
|
+
webm: "video/webm",
|
|
238
|
+
pdf: "application/pdf"
|
|
239
|
+
};
|
|
240
|
+
const unavailable = (reason) => ({
|
|
241
|
+
kind: "unavailable",
|
|
242
|
+
reason
|
|
243
|
+
});
|
|
244
|
+
/** Cuts at most `limit` bytes without splitting a UTF-8 sequence. */
|
|
245
|
+
function excerpt(bytes, limit) {
|
|
246
|
+
if (bytes.byteLength <= limit) return {
|
|
247
|
+
text: new TextDecoder().decode(bytes),
|
|
248
|
+
truncated: false
|
|
249
|
+
};
|
|
250
|
+
let end = limit;
|
|
251
|
+
while (end > 0 && ((bytes[end] ?? 0) & 192) === 128) end -= 1;
|
|
252
|
+
return {
|
|
253
|
+
text: new TextDecoder().decode(bytes.subarray(0, end)),
|
|
254
|
+
truncated: true
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
const capOf = (request, cap) => request.maxBytes === void 0 ? cap : Math.min(request.maxBytes, cap);
|
|
258
|
+
function languageOf(path, kind) {
|
|
259
|
+
if (isMermaidPath(path)) return "mermaid";
|
|
260
|
+
if (kind === "markdown") return "markdown";
|
|
261
|
+
return path.toLowerCase().split(".").at(-1);
|
|
262
|
+
}
|
|
263
|
+
function csvTable(bytes) {
|
|
264
|
+
const text = new TextDecoder().decode(bytes);
|
|
265
|
+
const dialect = detectDialect(text);
|
|
266
|
+
const records = parse(text, {
|
|
267
|
+
bom: true,
|
|
268
|
+
delimiter: dialect.delimiter,
|
|
269
|
+
quote: dialect.quote,
|
|
270
|
+
record_delimiter: [dialect.recordDelimiter],
|
|
271
|
+
relax_column_count: true,
|
|
272
|
+
relax_quotes: true,
|
|
273
|
+
skip_empty_lines: false,
|
|
274
|
+
to: 21
|
|
275
|
+
});
|
|
276
|
+
const rows = records.slice(0, 20);
|
|
277
|
+
return {
|
|
278
|
+
kind: "table",
|
|
279
|
+
rows: rows.map((row) => row.slice(0, 10)),
|
|
280
|
+
truncated: records.length > 20 || rows.some((row) => row.length > 10)
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function cellPosition(reference) {
|
|
284
|
+
const match = /^([A-Z]+)(\d+)$/u.exec(reference);
|
|
285
|
+
if (!match) return void 0;
|
|
286
|
+
const column = (match[1] ?? "").split("").reduce((total, letter) => total * 26 + letter.charCodeAt(0) - 64, 0);
|
|
287
|
+
return {
|
|
288
|
+
row: Number(match[2]),
|
|
289
|
+
column
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
async function xlsxTable(bytes) {
|
|
293
|
+
const document = await parseXlsx(bytes);
|
|
294
|
+
const sheets = /* @__PURE__ */ new Map();
|
|
295
|
+
for (const fragment of document.fragments) {
|
|
296
|
+
const separator = fragment.location.lastIndexOf("!");
|
|
297
|
+
const position = cellPosition(fragment.location.slice(separator + 1));
|
|
298
|
+
if (separator === -1 || position === void 0) continue;
|
|
299
|
+
const entry = fragment.location.slice(0, separator);
|
|
300
|
+
sheets.set(entry, [...sheets.get(entry) ?? [], {
|
|
301
|
+
...position,
|
|
302
|
+
text: fragment.text
|
|
303
|
+
}]);
|
|
304
|
+
}
|
|
305
|
+
const first = [...sheets.keys()].sort((left, right) => left.localeCompare(right, void 0, { numeric: true }))[0];
|
|
306
|
+
if (first === void 0) return {
|
|
307
|
+
kind: "table",
|
|
308
|
+
rows: [],
|
|
309
|
+
truncated: false
|
|
310
|
+
};
|
|
311
|
+
const cells = sheets.get(first) ?? [];
|
|
312
|
+
const height = Math.max(0, ...cells.map((cell) => cell.row));
|
|
313
|
+
const width = Math.max(0, ...cells.map((cell) => cell.column));
|
|
314
|
+
const rows = Array.from({ length: Math.min(height, 20) }, () => Array.from({ length: Math.min(width, 10) }, () => ""));
|
|
315
|
+
for (const cell of cells) {
|
|
316
|
+
const row = rows[cell.row - 1];
|
|
317
|
+
if (row !== void 0 && cell.column <= row.length) row[cell.column - 1] = cell.text;
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
kind: "table",
|
|
321
|
+
sheet: first.split("/").at(-1)?.replace(/\.xml$/iu, ""),
|
|
322
|
+
rows,
|
|
323
|
+
truncated: height > 20 || width > 10
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
/** Each slide's first text paragraph, read from the archive so styled runs never refuse the preview. */
|
|
327
|
+
async function pptxTitles(bytes) {
|
|
328
|
+
const slides = (await readOoxmlArchive(bytes)).entries.filter((entry) => /^ppt\/slides\/slide\d+\.xml$/iu.test(entry.name)).sort((left, right) => left.name.localeCompare(right.name, void 0, { numeric: true }));
|
|
329
|
+
return {
|
|
330
|
+
kind: "slides",
|
|
331
|
+
titles: slides.slice(0, 12).map((entry) => {
|
|
332
|
+
const xml = entry.data.toString("utf8");
|
|
333
|
+
for (const paragraph of xml.matchAll(/<a:p(?:\s[^>]*)?>([\s\S]*?)<\/a:p>/gu)) {
|
|
334
|
+
const text = [...(paragraph[1] ?? "").matchAll(/<a:t(?:\s[^>]*)?>([\s\S]*?)<\/a:t>/gu)].map((run) => decodeXmlText(run[1] ?? "")).join("").trim();
|
|
335
|
+
if (text) return text;
|
|
336
|
+
}
|
|
337
|
+
return "";
|
|
338
|
+
}),
|
|
339
|
+
truncated: slides.length > 12
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function markdownTitles(bytes) {
|
|
343
|
+
const slides = parseMarkdownSlides(bytes).fragments;
|
|
344
|
+
return {
|
|
345
|
+
kind: "slides",
|
|
346
|
+
titles: slides.slice(0, 12).map((slide) => {
|
|
347
|
+
const lines = slide.text.split(/\r?\n/u).map((line) => line.trim());
|
|
348
|
+
return (lines.find((line) => /^#{1,6}\s/u.test(line)) ?? lines.find((line) => line !== "") ?? "").replace(/^#{1,6}\s+/u, "");
|
|
349
|
+
}),
|
|
350
|
+
truncated: slides.length > 12
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function mediaPreview(kind, source, access, request) {
|
|
354
|
+
if (source.kind === "artifact") validateArtifactRead(source.relative, access.workflowVisible);
|
|
355
|
+
const relative = source.kind === "artifact" ? source.relative : source.path;
|
|
356
|
+
return {
|
|
357
|
+
kind,
|
|
358
|
+
src: {
|
|
359
|
+
scope: source.kind === "artifact" ? "artifacts" : "workspace",
|
|
360
|
+
path: relative
|
|
361
|
+
},
|
|
362
|
+
mimeType: MEDIA_TYPES[relative.toLowerCase().split(".").at(-1) ?? ""] ?? "application/octet-stream",
|
|
363
|
+
...kind === "video" && request.timeSeconds !== void 0 ? { timeSeconds: request.timeSeconds } : {}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/** The built-in preview for a path, admitted and read exactly as Author's document routes do. */
|
|
367
|
+
async function renderBuiltInPreview(access, request, signal) {
|
|
368
|
+
const kind = authorKindForPath(request.path);
|
|
369
|
+
if (kind === "story-preview" || kind === "opaque") return unavailable(`No preview renders '${kind}' files yet.`);
|
|
370
|
+
if (access === void 0) return unavailable("Author previews need a session.");
|
|
371
|
+
try {
|
|
372
|
+
const source = await resolveDocument(access.cwd, request.path, access.sessionId, access.environment, access.fileSystem);
|
|
373
|
+
signal.throwIfAborted();
|
|
374
|
+
if (kind === "image" || kind === "video" || kind === "pdf") return mediaPreview(kind, source, access, request);
|
|
375
|
+
const bytes = await readSource(source, access.workflowVisible, access.fileSystem);
|
|
376
|
+
signal.throwIfAborted();
|
|
377
|
+
if (kind === "text" || kind === "markdown") {
|
|
378
|
+
const language = languageOf(request.path, kind);
|
|
379
|
+
return {
|
|
380
|
+
kind: "text",
|
|
381
|
+
...excerpt(bytes, capOf(request, AUTHOR_PREVIEW_TEXT_MAX_BYTES)),
|
|
382
|
+
...language === void 0 ? {} : { language }
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
if (kind === "html") {
|
|
386
|
+
const { text, truncated } = excerpt(bytes, capOf(request, AUTHOR_PREVIEW_HTML_MAX_BYTES));
|
|
387
|
+
return {
|
|
388
|
+
kind: "html",
|
|
389
|
+
html: text,
|
|
390
|
+
truncated
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
if (kind === "csv") return csvTable(bytes);
|
|
394
|
+
if (kind === "xlsx") return await xlsxTable(bytes);
|
|
395
|
+
if (kind === "pptx") return await pptxTitles(bytes);
|
|
396
|
+
return markdownTitles(bytes);
|
|
397
|
+
} catch (error) {
|
|
398
|
+
if (signal.aborted) throw signal.reason;
|
|
399
|
+
return unavailable(error instanceof Error ? error.message : String(error));
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function assertRequest(request) {
|
|
403
|
+
if (typeof request !== "object" || request === null) throw new Error("A preview request is required.");
|
|
404
|
+
if (typeof request.path !== "string" || request.path.length === 0) throw new Error("A preview request needs a path.");
|
|
405
|
+
if (request.maxBytes !== void 0 && (!Number.isInteger(request.maxBytes) || request.maxBytes < 1)) throw new Error("Preview maxBytes must be a positive integer.");
|
|
406
|
+
if (request.timeSeconds !== void 0 && (!Number.isFinite(request.timeSeconds) || request.timeSeconds < 0)) throw new Error("Preview timeSeconds must be a finite, non-negative number.");
|
|
407
|
+
}
|
|
408
|
+
const isPreview = (value) => typeof value === "object" && value !== null && typeof value.kind === "string";
|
|
409
|
+
/** Plugin providers, newest first, ahead of the built-in renderer. */
|
|
410
|
+
function createAuthorPreviewRenderer(options) {
|
|
411
|
+
const providers = [];
|
|
412
|
+
const warned = /* @__PURE__ */ new Set();
|
|
413
|
+
const warnOnce = (id, message) => {
|
|
414
|
+
if (warned.has(id)) return;
|
|
415
|
+
warned.add(id);
|
|
416
|
+
options.warn(message);
|
|
417
|
+
};
|
|
418
|
+
const matches = (provider, path, type) => {
|
|
419
|
+
try {
|
|
420
|
+
return provider.match(path, type) === true;
|
|
421
|
+
} catch (error) {
|
|
422
|
+
warnOnce(provider.id, `Author preview provider '${provider.id}' failed to match a path: ${String(error)}`);
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
return {
|
|
427
|
+
async render(request, signal = new AbortController().signal) {
|
|
428
|
+
assertRequest(request);
|
|
429
|
+
signal.throwIfAborted();
|
|
430
|
+
const detached = { ...request };
|
|
431
|
+
const type = options.typeForPath(request.path);
|
|
432
|
+
for (const provider of [...providers].reverse()) {
|
|
433
|
+
if (!matches(provider, request.path, type)) continue;
|
|
434
|
+
try {
|
|
435
|
+
const preview = await provider.render({ ...detached }, signal);
|
|
436
|
+
if (isPreview(preview)) return preview;
|
|
437
|
+
if (preview !== void 0) warnOnce(provider.id, `Author preview provider '${provider.id}' returned an invalid preview.`);
|
|
438
|
+
} catch (error) {
|
|
439
|
+
if (signal.aborted) throw signal.reason;
|
|
440
|
+
warnOnce(provider.id, `Author preview provider '${provider.id}' failed to render: ${String(error)}`);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return await renderBuiltInPreview(options.access, detached, signal);
|
|
444
|
+
},
|
|
445
|
+
register(provider) {
|
|
446
|
+
if (typeof provider !== "object" || provider === null || !ID_PATTERN.test(String(provider.id))) throw new Error(`Invalid Author preview provider id '${String(provider?.id)}'.`);
|
|
447
|
+
if (providers.some((existing) => existing.id === provider.id)) throw new Error(`Author preview provider '${provider.id}' is already registered.`);
|
|
448
|
+
if (typeof provider.match !== "function" || typeof provider.render !== "function") throw new Error(`Author preview provider '${provider.id}' needs match and render functions.`);
|
|
449
|
+
const registered = {
|
|
450
|
+
id: provider.id,
|
|
451
|
+
match: (path, type) => provider.match(path, type),
|
|
452
|
+
render: (request, signal) => provider.render(request, signal)
|
|
453
|
+
};
|
|
454
|
+
providers.push(registered);
|
|
455
|
+
return { dispose() {
|
|
456
|
+
const index = providers.indexOf(registered);
|
|
457
|
+
if (index === -1) return;
|
|
458
|
+
providers.splice(index, 1);
|
|
459
|
+
warned.delete(registered.id);
|
|
460
|
+
} };
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region ../../foundations/po-author/src/services/authorService/index.ts
|
|
466
|
+
const TYPE_PATTERN = /^[a-z][a-z0-9-]{0,31}$/u;
|
|
467
|
+
const GUIDE_PREFIX = "codemode-how-to-author-";
|
|
468
|
+
/** Built-in kinds, and whether each ships a guide; kinds without capabilities of their own have none. */
|
|
469
|
+
const BUILT_IN_GUIDES = {
|
|
470
|
+
text: true,
|
|
471
|
+
markdown: true,
|
|
472
|
+
html: true,
|
|
473
|
+
slides: true,
|
|
474
|
+
csv: true,
|
|
475
|
+
xlsx: true,
|
|
476
|
+
pptx: true,
|
|
477
|
+
image: true,
|
|
478
|
+
"story-preview": true,
|
|
479
|
+
video: false,
|
|
480
|
+
pdf: false,
|
|
481
|
+
opaque: false
|
|
482
|
+
};
|
|
483
|
+
const isBuiltIn = (type) => Object.hasOwn(BUILT_IN_GUIDES, type);
|
|
484
|
+
/** Wraps the session catalog with the open canvases and the canvas types other plugins add. */
|
|
485
|
+
function createAuthorService(catalog, options = {}) {
|
|
486
|
+
const warn = options.warn ?? ((message) => console.warn(message));
|
|
487
|
+
const types = [];
|
|
488
|
+
const warned = /* @__PURE__ */ new Set();
|
|
489
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
490
|
+
let canvases = [];
|
|
491
|
+
const notify = () => {
|
|
492
|
+
for (const listener of listeners) listener();
|
|
493
|
+
};
|
|
494
|
+
const matches = (entry, path) => {
|
|
495
|
+
try {
|
|
496
|
+
return entry.match(path) === true;
|
|
497
|
+
} catch (error) {
|
|
498
|
+
if (!warned.has(entry.type)) {
|
|
499
|
+
warned.add(entry.type);
|
|
500
|
+
warn(`Author canvas type '${entry.type}' failed to match a path: ${String(error)}`);
|
|
501
|
+
}
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
const typeForPath = (path) => types.find((entry) => matches(entry, path))?.type ?? authorKindForPath(path);
|
|
506
|
+
const guideFor = (type) => {
|
|
507
|
+
const plugin = types.find((entry) => entry.type === type);
|
|
508
|
+
if (plugin !== void 0) return plugin.guide && {
|
|
509
|
+
name: plugin.guide.name,
|
|
510
|
+
resource: plugin.guide
|
|
511
|
+
};
|
|
512
|
+
return isBuiltIn(type) && BUILT_IN_GUIDES[type] ? { name: `${GUIDE_PREFIX}${type}` } : void 0;
|
|
513
|
+
};
|
|
514
|
+
const previews = createAuthorPreviewRenderer({
|
|
515
|
+
...options.preview === void 0 ? {} : { access: options.preview },
|
|
516
|
+
typeForPath,
|
|
517
|
+
warn
|
|
518
|
+
});
|
|
519
|
+
const withType = (view) => {
|
|
520
|
+
const type = typeForPath(view.path);
|
|
521
|
+
const guide = guideFor(type)?.name;
|
|
522
|
+
return {
|
|
523
|
+
...view,
|
|
524
|
+
type,
|
|
525
|
+
...guide === void 0 ? {} : { guide }
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
return {
|
|
529
|
+
open: (path, signal, alias) => catalog.open(path, signal, alias),
|
|
530
|
+
async describe(signal, alias) {
|
|
531
|
+
const snapshot = await catalog.describe(signal, alias);
|
|
532
|
+
return snapshot.canvases === void 0 ? snapshot : {
|
|
533
|
+
...snapshot,
|
|
534
|
+
canvases: snapshot.canvases.map(withType)
|
|
535
|
+
};
|
|
536
|
+
},
|
|
537
|
+
execute: (input, signal) => catalog.execute(input, signal),
|
|
538
|
+
openCanvases: () => canvases.map(({ alias, path }) => ({
|
|
539
|
+
alias,
|
|
540
|
+
path,
|
|
541
|
+
type: typeForPath(path)
|
|
542
|
+
})),
|
|
543
|
+
subscribe(listener) {
|
|
544
|
+
listeners.add(listener);
|
|
545
|
+
return () => {
|
|
546
|
+
listeners.delete(listener);
|
|
547
|
+
};
|
|
548
|
+
},
|
|
549
|
+
registerCanvasType(entry) {
|
|
550
|
+
if (!TYPE_PATTERN.test(entry.type)) throw new Error(`Invalid Author canvas type '${entry.type}'.`);
|
|
551
|
+
if (isBuiltIn(entry.type) || types.some((existing) => existing.type === entry.type)) throw new Error(`Author canvas type '${entry.type}' is already registered.`);
|
|
552
|
+
if (typeof entry.match !== "function") throw new Error(`Author canvas type '${entry.type}' needs a match function.`);
|
|
553
|
+
if (entry.guide !== void 0 && (entry.guide.name !== `${GUIDE_PREFIX}${entry.type}` || entry.guide.kind !== "skill")) throw new Error(`Author canvas type '${entry.type}' needs a 'skill' guide named '${GUIDE_PREFIX}${entry.type}'.`);
|
|
554
|
+
const registered = {
|
|
555
|
+
type: entry.type,
|
|
556
|
+
match: (path) => entry.match(path),
|
|
557
|
+
...entry.guide === void 0 ? {} : { guide: entry.guide }
|
|
558
|
+
};
|
|
559
|
+
types.push(registered);
|
|
560
|
+
notify();
|
|
561
|
+
return { dispose() {
|
|
562
|
+
const index = types.indexOf(registered);
|
|
563
|
+
if (index === -1) return;
|
|
564
|
+
types.splice(index, 1);
|
|
565
|
+
warned.delete(registered.type);
|
|
566
|
+
notify();
|
|
567
|
+
} };
|
|
568
|
+
},
|
|
569
|
+
typeForPath,
|
|
570
|
+
renderPreview: (request, signal) => previews.render(request, signal),
|
|
571
|
+
registerPreviewProvider: (provider) => previews.register(provider),
|
|
572
|
+
guide: guideFor,
|
|
573
|
+
changed(next) {
|
|
574
|
+
canvases = next.map(({ alias, path }) => ({
|
|
575
|
+
alias,
|
|
576
|
+
path
|
|
577
|
+
}));
|
|
578
|
+
notify();
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
//#endregion
|
|
583
|
+
//#region ../../foundations/po-author/src/services/webmcpNamespace/index.ts
|
|
584
|
+
const DECLARATIONS = `interface AuthorViewportCatalogSnapshot {
|
|
585
|
+
catalogToken: string;
|
|
586
|
+
tools: { name: string; label: string; description: string; inputSchema: Readonly<Record<string, unknown>> }[];
|
|
587
|
+
canvases?: { alias: string; path: string; status: 'opening' | 'ready' | 'unavailable' }[];
|
|
588
|
+
alias?: string;
|
|
589
|
+
path?: string;
|
|
590
|
+
status?: 'opening' | 'ready' | 'unavailable';
|
|
591
|
+
nextStep?: string;
|
|
592
|
+
}
|
|
593
|
+
declare const webmcp: {
|
|
594
|
+
/** Open or reuse a canvas for a relative repository file or a session artifact. The returned alias is canonical; its catalog may still be opening. */
|
|
595
|
+
open(input: { path: string; alias?: string }): Promise<{ path: string; byteLength: number; alias?: string; status?: 'opening' | 'ready' | 'unavailable'; reused?: boolean }>;
|
|
596
|
+
/** Ready canvases, or one canvas's tools and its catalog token. */
|
|
597
|
+
describe(input?: { alias?: string }): Promise<AuthorViewportCatalogSnapshot>;
|
|
598
|
+
/** Call one tool with an explicit current token. Await same-canvas calls sequentially. */
|
|
599
|
+
call(input: { alias?: string; catalogToken: string; name: string; arguments: Record<string, unknown> }): Promise<unknown>;
|
|
600
|
+
};`;
|
|
601
|
+
function copy(value) {
|
|
602
|
+
return value === void 0 ? value : JSON.parse(JSON.stringify(value));
|
|
603
|
+
}
|
|
604
|
+
function createWebmcpNamespace(catalog, sessionId, assertAvailable) {
|
|
605
|
+
return {
|
|
606
|
+
name: "webmcp",
|
|
607
|
+
summary: "Author canvases: open a file the person sees, then call its tools.",
|
|
608
|
+
declarations: DECLARATIONS,
|
|
609
|
+
bind(run) {
|
|
610
|
+
if (run.sessionId !== sessionId) throw new Error("Author WebMCP namespace belongs to another session.");
|
|
611
|
+
let disposed = false;
|
|
612
|
+
run.onDispose(() => {
|
|
613
|
+
disposed = true;
|
|
614
|
+
});
|
|
615
|
+
const check = () => {
|
|
616
|
+
run.signal.throwIfAborted();
|
|
617
|
+
if (disposed) throw new Error("Author WebMCP run is disposed.");
|
|
618
|
+
assertAvailable();
|
|
619
|
+
};
|
|
620
|
+
const recorded = async (member, tool, input, work) => {
|
|
621
|
+
const started = Date.now();
|
|
622
|
+
let args = {};
|
|
623
|
+
try {
|
|
624
|
+
if (typeof input === "object" && input !== null && !Array.isArray(input)) args = copy(input);
|
|
625
|
+
} catch {}
|
|
626
|
+
const base = {
|
|
627
|
+
name: `webmcp.${member}`,
|
|
628
|
+
tool,
|
|
629
|
+
args
|
|
630
|
+
};
|
|
631
|
+
let outcome;
|
|
632
|
+
try {
|
|
633
|
+
outcome = await work();
|
|
634
|
+
} catch (error) {
|
|
635
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
636
|
+
run.record?.({
|
|
637
|
+
...base,
|
|
638
|
+
ok: false,
|
|
639
|
+
ms: Date.now() - started,
|
|
640
|
+
error: message,
|
|
641
|
+
result: { content: [{
|
|
642
|
+
type: "text",
|
|
643
|
+
text: message
|
|
644
|
+
}] }
|
|
645
|
+
});
|
|
646
|
+
throw error;
|
|
647
|
+
}
|
|
648
|
+
run.record?.({
|
|
649
|
+
...base,
|
|
650
|
+
ok: true,
|
|
651
|
+
ms: Date.now() - started,
|
|
652
|
+
result: {
|
|
653
|
+
content: [{
|
|
654
|
+
type: "text",
|
|
655
|
+
text: JSON.stringify(outcome.details ?? null, null, 2)
|
|
656
|
+
}],
|
|
657
|
+
details: outcome.details
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
return outcome.value;
|
|
661
|
+
};
|
|
662
|
+
const members = Object.create(null);
|
|
663
|
+
members.open = (input) => recorded("open", OPEN_AUTHORING_FILE_TOOL_NAME, input, async () => {
|
|
664
|
+
check();
|
|
665
|
+
const { path, alias } = parseOpenAuthoringFileInput(copy(input));
|
|
666
|
+
const result = copy(await catalog.open(path, run.signal, alias));
|
|
667
|
+
check();
|
|
668
|
+
return {
|
|
669
|
+
details: result,
|
|
670
|
+
value: result
|
|
671
|
+
};
|
|
672
|
+
});
|
|
673
|
+
members.describe = (input) => recorded("describe", AUTHOR_DESCRIBE_TOOL_NAME, input, async () => {
|
|
674
|
+
check();
|
|
675
|
+
const { alias } = parseDescribeAuthorToolsInput(copy(input === void 0 ? {} : input));
|
|
676
|
+
const result = copy(await catalog.describe(run.signal, alias));
|
|
677
|
+
check();
|
|
678
|
+
return {
|
|
679
|
+
details: result,
|
|
680
|
+
value: result
|
|
681
|
+
};
|
|
682
|
+
});
|
|
683
|
+
members.call = (input) => recorded("call", AUTHOR_USE_TOOL_NAME, input, async () => {
|
|
684
|
+
check();
|
|
685
|
+
const parsed = parseUseAuthorToolInput(copy(input));
|
|
686
|
+
const result = copy(await catalog.execute(parsed, run.signal));
|
|
687
|
+
check();
|
|
688
|
+
return {
|
|
689
|
+
details: result,
|
|
690
|
+
value: result.result
|
|
691
|
+
};
|
|
692
|
+
});
|
|
693
|
+
return members;
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
//#endregion
|
|
698
|
+
//#region ../../foundations/po-author/src/types/webAuthor.ts
|
|
699
|
+
const authorChannelType = "author_webmcp";
|
|
700
|
+
/** Direct-event frame carrying a session's open canvases from the API to the channel. */
|
|
701
|
+
const authorCanvasesFrame = "author_canvases";
|
|
702
|
+
var AuthorBridgeError = class extends Error {
|
|
703
|
+
status;
|
|
704
|
+
constructor(message, status = 409) {
|
|
705
|
+
super(message);
|
|
706
|
+
this.status = status;
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
function createAuthorBridgeState(options) {
|
|
710
|
+
const { now, issueToken, scheduleTimeout } = options;
|
|
711
|
+
const timeoutMs = options.requestTimeoutMs ?? 15e3;
|
|
712
|
+
const leaseMs = options.leaseMs ?? 1e4;
|
|
713
|
+
let owner;
|
|
714
|
+
let pending;
|
|
715
|
+
let delivery;
|
|
716
|
+
let deliveryWaiter;
|
|
717
|
+
const tombstones = /* @__PURE__ */ new Set();
|
|
718
|
+
const rememberCancellation = (requestId) => {
|
|
719
|
+
tombstones.add(requestId);
|
|
720
|
+
if (tombstones.size > 100) tombstones.delete(tombstones.values().next().value);
|
|
721
|
+
};
|
|
722
|
+
const publishDelivery = (value) => {
|
|
723
|
+
if (deliveryWaiter === void 0) delivery = value;
|
|
724
|
+
else {
|
|
725
|
+
const waiter = deliveryWaiter;
|
|
726
|
+
deliveryWaiter = void 0;
|
|
727
|
+
waiter.resolve(value);
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
const rejectPending = (reason, sendCancel) => {
|
|
731
|
+
const current = pending;
|
|
732
|
+
if (current === void 0) return;
|
|
733
|
+
pending = void 0;
|
|
734
|
+
current.cancelTimer();
|
|
735
|
+
current.removeAbort?.();
|
|
736
|
+
rememberCancellation(current.request.requestId);
|
|
737
|
+
if (sendCancel) publishDelivery({
|
|
738
|
+
...current.request,
|
|
739
|
+
kind: "cancel"
|
|
740
|
+
});
|
|
741
|
+
current.reject(new AuthorBridgeError(reason, 503));
|
|
742
|
+
};
|
|
743
|
+
const liveOwner = () => {
|
|
744
|
+
if (owner === void 0) throw new AuthorBridgeError("No Author viewport is registered.", 503);
|
|
745
|
+
if (owner.expiresAt <= now()) {
|
|
746
|
+
rejectPending("The Author viewport lease expired.", false);
|
|
747
|
+
owner = void 0;
|
|
748
|
+
throw new AuthorBridgeError("The Author viewport lease expired.", 503);
|
|
749
|
+
}
|
|
750
|
+
return owner;
|
|
751
|
+
};
|
|
752
|
+
const assertOwner = (bindingId, generation, ownerToken) => {
|
|
753
|
+
const current = liveOwner();
|
|
754
|
+
if (current.bindingId !== bindingId || current.generation !== generation || current.ownerToken !== ownerToken) throw new AuthorBridgeError("Stale Author viewport binding.");
|
|
755
|
+
return current;
|
|
756
|
+
};
|
|
757
|
+
const assertRequest = (bindingId, generation, ownerToken, catalogToken, requestId) => {
|
|
758
|
+
if (assertOwner(bindingId, generation, ownerToken).catalogToken !== catalogToken) throw new AuthorBridgeError("Stale Author catalog token.");
|
|
759
|
+
if (tombstones.has(requestId)) throw new AuthorBridgeError("The Author request was already cancelled.");
|
|
760
|
+
if (pending?.request.requestId !== requestId) throw new AuthorBridgeError("Stale Author request.");
|
|
761
|
+
return pending;
|
|
762
|
+
};
|
|
763
|
+
return {
|
|
764
|
+
register(bindingId, generation) {
|
|
765
|
+
if (bindingId === "" || !Number.isSafeInteger(generation) || generation < 0) throw new AuthorBridgeError("Invalid Author registration.", 400);
|
|
766
|
+
if (owner !== void 0 && owner.expiresAt > now()) {
|
|
767
|
+
if (owner.bindingId !== bindingId) throw new AuthorBridgeError("Another Author viewport owns the lease.");
|
|
768
|
+
if (generation < owner.generation) throw new AuthorBridgeError("Stale Author generation.");
|
|
769
|
+
if (generation === owner.generation) {
|
|
770
|
+
owner.expiresAt = now() + leaseMs;
|
|
771
|
+
return {
|
|
772
|
+
kind: "accepted",
|
|
773
|
+
generation,
|
|
774
|
+
ownerToken: owner.ownerToken,
|
|
775
|
+
...owner.catalogToken === void 0 ? {} : { catalogToken: owner.catalogToken },
|
|
776
|
+
leaseMs
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
rejectPending("The Author viewport generation changed.", false);
|
|
781
|
+
delivery = void 0;
|
|
782
|
+
const current = {
|
|
783
|
+
bindingId,
|
|
784
|
+
generation,
|
|
785
|
+
ownerToken: issueToken(),
|
|
786
|
+
expiresAt: now() + leaseMs,
|
|
787
|
+
tools: []
|
|
788
|
+
};
|
|
789
|
+
owner = current;
|
|
790
|
+
return {
|
|
791
|
+
kind: "accepted",
|
|
792
|
+
generation,
|
|
793
|
+
ownerToken: current.ownerToken,
|
|
794
|
+
leaseMs
|
|
795
|
+
};
|
|
796
|
+
},
|
|
797
|
+
catalog(bindingId, generation, ownerToken, tools) {
|
|
798
|
+
const current = assertOwner(bindingId, generation, ownerToken);
|
|
799
|
+
if (!Array.isArray(tools) || tools.length > 15) throw new AuthorBridgeError("Invalid Author catalog.", 400);
|
|
800
|
+
const names = /* @__PURE__ */ new Set();
|
|
801
|
+
for (const tool of tools) {
|
|
802
|
+
if (typeof tool !== "object" || tool === null || typeof tool.name !== "string" || !/^[a-z][a-z0-9_]{0,29}$/.test(tool.name) || typeof tool.label !== "string" || typeof tool.description !== "string" || typeof tool.inputSchema !== "object" || tool.inputSchema === null || Array.isArray(tool.inputSchema) || names.has(tool.name)) throw new AuthorBridgeError("Invalid Author catalog.", 400);
|
|
803
|
+
names.add(tool.name);
|
|
804
|
+
}
|
|
805
|
+
if (pending !== void 0) throw new AuthorBridgeError("Cannot replace the Author catalog during a request.");
|
|
806
|
+
current.tools = tools.map((tool) => ({
|
|
807
|
+
...tool,
|
|
808
|
+
inputSchema: { ...tool.inputSchema }
|
|
809
|
+
}));
|
|
810
|
+
current.catalogToken = issueToken();
|
|
811
|
+
current.expiresAt = now() + leaseMs;
|
|
812
|
+
return {
|
|
813
|
+
kind: "accepted",
|
|
814
|
+
generation,
|
|
815
|
+
ownerToken,
|
|
816
|
+
catalogToken: current.catalogToken,
|
|
817
|
+
leaseMs
|
|
818
|
+
};
|
|
819
|
+
},
|
|
820
|
+
describe() {
|
|
821
|
+
const current = liveOwner();
|
|
822
|
+
if (current.catalogToken === void 0) throw new AuthorBridgeError("The Author viewport has no catalog.", 503);
|
|
823
|
+
return {
|
|
824
|
+
catalogToken: current.catalogToken,
|
|
825
|
+
tools: current.tools
|
|
826
|
+
};
|
|
827
|
+
},
|
|
828
|
+
invoke(input, signal) {
|
|
829
|
+
let current;
|
|
830
|
+
try {
|
|
831
|
+
current = liveOwner();
|
|
832
|
+
if (current.catalogToken !== input.catalogToken) throw new AuthorBridgeError("The Author capability catalog changed.");
|
|
833
|
+
if (!current.tools.some((tool) => tool.name === input.name)) throw new AuthorBridgeError(`Unknown Author capability: ${input.name}`, 404);
|
|
834
|
+
if (pending !== void 0) throw new AuthorBridgeError("Another Author request is already pending.");
|
|
835
|
+
if (signal?.aborted) throw signal.reason instanceof Error ? signal.reason : /* @__PURE__ */ new Error("Author request cancelled.");
|
|
836
|
+
} catch (error) {
|
|
837
|
+
return Promise.reject(error);
|
|
838
|
+
}
|
|
839
|
+
const request = {
|
|
840
|
+
kind: "request",
|
|
841
|
+
generation: current.generation,
|
|
842
|
+
ownerToken: current.ownerToken,
|
|
843
|
+
catalogToken: current.catalogToken,
|
|
844
|
+
requestId: issueToken(),
|
|
845
|
+
name: input.name,
|
|
846
|
+
arguments: input.arguments
|
|
847
|
+
};
|
|
848
|
+
return new Promise((resolve, reject) => {
|
|
849
|
+
const cancel = (reason) => rejectPending(reason, true);
|
|
850
|
+
const cancelTimer = scheduleTimeout(() => cancel("The Author request timed out."), Math.min(timeoutMs, current.expiresAt - now()));
|
|
851
|
+
pending = {
|
|
852
|
+
request,
|
|
853
|
+
resolve,
|
|
854
|
+
reject,
|
|
855
|
+
cancelTimer
|
|
856
|
+
};
|
|
857
|
+
if (signal !== void 0) {
|
|
858
|
+
const onAbort = () => cancel("The Author request was cancelled.");
|
|
859
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
860
|
+
pending.removeAbort = () => signal.removeEventListener("abort", onAbort);
|
|
861
|
+
}
|
|
862
|
+
publishDelivery(request);
|
|
863
|
+
});
|
|
864
|
+
},
|
|
865
|
+
async next(bindingId, generation, ownerToken, signal) {
|
|
866
|
+
assertOwner(bindingId, generation, ownerToken);
|
|
867
|
+
if (delivery !== void 0) {
|
|
868
|
+
const value = delivery;
|
|
869
|
+
delivery = void 0;
|
|
870
|
+
return value;
|
|
871
|
+
}
|
|
872
|
+
if (deliveryWaiter !== void 0) throw new AuthorBridgeError("An Author delivery poll is already active.");
|
|
873
|
+
return await new Promise((resolve, reject) => {
|
|
874
|
+
let waiter;
|
|
875
|
+
const onAbort = () => {
|
|
876
|
+
if (deliveryWaiter === waiter) deliveryWaiter = void 0;
|
|
877
|
+
reject(signal?.reason ?? /* @__PURE__ */ new Error("Author delivery poll cancelled."));
|
|
878
|
+
};
|
|
879
|
+
waiter = {
|
|
880
|
+
resolve(value) {
|
|
881
|
+
signal?.removeEventListener("abort", onAbort);
|
|
882
|
+
resolve(value);
|
|
883
|
+
},
|
|
884
|
+
reject
|
|
885
|
+
};
|
|
886
|
+
deliveryWaiter = waiter;
|
|
887
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
888
|
+
});
|
|
889
|
+
},
|
|
890
|
+
result(bindingId, generation, ownerToken, catalogToken, requestId, result) {
|
|
891
|
+
const current = assertRequest(bindingId, generation, ownerToken, catalogToken, requestId);
|
|
892
|
+
pending = void 0;
|
|
893
|
+
current.cancelTimer();
|
|
894
|
+
current.removeAbort?.();
|
|
895
|
+
current.resolve({
|
|
896
|
+
catalogToken,
|
|
897
|
+
name: current.request.name,
|
|
898
|
+
result
|
|
899
|
+
});
|
|
900
|
+
},
|
|
901
|
+
cancelled(bindingId, generation, ownerToken, catalogToken, requestId) {
|
|
902
|
+
const current = assertRequest(bindingId, generation, ownerToken, catalogToken, requestId);
|
|
903
|
+
pending = void 0;
|
|
904
|
+
current.cancelTimer();
|
|
905
|
+
current.removeAbort?.();
|
|
906
|
+
rememberCancellation(requestId);
|
|
907
|
+
current.reject(new AuthorBridgeError("The Author viewport cancelled the request."));
|
|
908
|
+
},
|
|
909
|
+
disconnect(bindingId, generation) {
|
|
910
|
+
if (owner?.bindingId !== bindingId || owner.generation !== generation) return;
|
|
911
|
+
rejectPending("The Author viewport disconnected.", false);
|
|
912
|
+
owner = void 0;
|
|
913
|
+
delivery = void 0;
|
|
914
|
+
},
|
|
915
|
+
close() {
|
|
916
|
+
rejectPending("The Author bridge closed.", false);
|
|
917
|
+
owner = void 0;
|
|
918
|
+
delivery = void 0;
|
|
919
|
+
deliveryWaiter?.reject(/* @__PURE__ */ new Error("The Author bridge closed."));
|
|
920
|
+
deliveryWaiter = void 0;
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
//#endregion
|
|
925
|
+
//#region ../../foundations/po-author/src/services/authorCanvasRegistry/index.ts
|
|
926
|
+
function createAuthorCanvasRegistry(cwd, createBridge, sessionId, environment, workflowVisible, fileSystem) {
|
|
927
|
+
const byAlias = /* @__PURE__ */ new Map();
|
|
928
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
929
|
+
const retired = /* @__PURE__ */ new Map();
|
|
930
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
931
|
+
const changed = () => {
|
|
932
|
+
for (const listener of listeners) listener();
|
|
933
|
+
};
|
|
934
|
+
const select = (alias) => {
|
|
935
|
+
if (alias !== void 0) {
|
|
936
|
+
if (!AUTHOR_ALIAS_PATTERN.test(alias)) throw new AuthorBridgeError("Invalid Author canvas alias.", 400);
|
|
937
|
+
const canvas = byAlias.get(alias);
|
|
938
|
+
const retiredPath = retired.get(alias);
|
|
939
|
+
if (canvas === void 0 && retiredPath !== void 0) throw new AuthorBridgeError(`Author canvas '${alias}' was closed to make room for newer canvases. Reopen ${retiredPath} with webmcp.open (or open_authoring_file).`, 404);
|
|
940
|
+
if (canvas === void 0) throw new AuthorBridgeError(`Unknown Author canvas '${alias}'. Call webmcp.describe() (or describe_author_tools({})) for available aliases.`, 404);
|
|
941
|
+
return canvas;
|
|
942
|
+
}
|
|
943
|
+
const canvases = [...byAlias.values()].filter((canvas) => !canvas.closed);
|
|
944
|
+
if (canvases.length !== 1) throw new AuthorBridgeError("Specify a canvas alias. Call webmcp.describe() (or describe_author_tools({})) to list canvases.", 409);
|
|
945
|
+
return canvases[0];
|
|
946
|
+
};
|
|
947
|
+
const view = (canvas) => {
|
|
948
|
+
if (canvas.closed) return {
|
|
949
|
+
alias: canvas.alias,
|
|
950
|
+
path: canvas.path,
|
|
951
|
+
status: "unavailable"
|
|
952
|
+
};
|
|
953
|
+
try {
|
|
954
|
+
canvas.bridge.describe();
|
|
955
|
+
canvas.readyOnce = true;
|
|
956
|
+
return {
|
|
957
|
+
alias: canvas.alias,
|
|
958
|
+
path: canvas.path,
|
|
959
|
+
status: "ready"
|
|
960
|
+
};
|
|
961
|
+
} catch {
|
|
962
|
+
return {
|
|
963
|
+
alias: canvas.alias,
|
|
964
|
+
path: canvas.path,
|
|
965
|
+
status: canvas.readyOnce ? "unavailable" : "opening"
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
return {
|
|
970
|
+
async open(requestedPath, signal, requestedAlias) {
|
|
971
|
+
signal?.throwIfAborted();
|
|
972
|
+
if (requestedAlias !== void 0 && !AUTHOR_ALIAS_PATTERN.test(requestedAlias)) throw new AuthorBridgeError("Invalid Author canvas alias.", 400);
|
|
973
|
+
const source = await resolveDocument(cwd, requestedPath, sessionId, environment, fileSystem);
|
|
974
|
+
const bytes = await readSource(source, workflowVisible, fileSystem);
|
|
975
|
+
signal?.throwIfAborted();
|
|
976
|
+
const sourceSha256 = digestOf(bytes);
|
|
977
|
+
const { realPath, path: canonicalPath } = source;
|
|
978
|
+
const occupied = requestedAlias === void 0 ? void 0 : byAlias.get(requestedAlias);
|
|
979
|
+
if (occupied !== void 0 && occupied.realPath !== realPath) throw new AuthorBridgeError(`Author canvas alias '${requestedAlias}' already names ${occupied.path}.`, 409);
|
|
980
|
+
const existing = byPath.get(realPath);
|
|
981
|
+
if (existing !== void 0) {
|
|
982
|
+
if (existing.closed) existing.readyOnce = false;
|
|
983
|
+
existing.closed = false;
|
|
984
|
+
byAlias.delete(existing.alias);
|
|
985
|
+
byAlias.set(existing.alias, existing);
|
|
986
|
+
changed();
|
|
987
|
+
return {
|
|
988
|
+
path: existing.path,
|
|
989
|
+
byteLength: bytes.byteLength,
|
|
990
|
+
sourceSha256,
|
|
991
|
+
alias: existing.alias,
|
|
992
|
+
status: view(existing).status,
|
|
993
|
+
reused: true
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
if (byAlias.size >= 32) {
|
|
997
|
+
const values = [...byAlias.values()];
|
|
998
|
+
const reclaimed = values.find((canvas) => canvas.closed);
|
|
999
|
+
const evicted = reclaimed ?? values[0];
|
|
1000
|
+
evicted.bridge.close();
|
|
1001
|
+
byAlias.delete(evicted.alias);
|
|
1002
|
+
byPath.delete(evicted.realPath);
|
|
1003
|
+
if (reclaimed === void 0) retired.set(evicted.alias, evicted.path);
|
|
1004
|
+
}
|
|
1005
|
+
const base = path.basename(realPath).replace(/\.[^.]*$/u, "").toLowerCase().replace(/[^a-z0-9_-]+/gu, "-").replace(/^[^a-z]+/u, "canvas-").slice(0, 48) || "canvas";
|
|
1006
|
+
const revived = [...retired].find(([, retiredPath]) => retiredPath === canonicalPath)?.[0];
|
|
1007
|
+
if (revived !== void 0) retired.delete(revived);
|
|
1008
|
+
if (requestedAlias !== void 0) retired.delete(requestedAlias);
|
|
1009
|
+
let alias = requestedAlias ?? revived ?? base;
|
|
1010
|
+
for (let suffix = 2; byAlias.has(alias) || retired.has(alias); suffix++) alias = `${base.slice(0, 56)}-${suffix}`;
|
|
1011
|
+
const canvas = {
|
|
1012
|
+
alias,
|
|
1013
|
+
path: canonicalPath,
|
|
1014
|
+
realPath,
|
|
1015
|
+
bridge: createBridge(),
|
|
1016
|
+
closed: false,
|
|
1017
|
+
readyOnce: false
|
|
1018
|
+
};
|
|
1019
|
+
byAlias.set(alias, canvas);
|
|
1020
|
+
byPath.set(realPath, canvas);
|
|
1021
|
+
changed();
|
|
1022
|
+
return {
|
|
1023
|
+
path: canonicalPath,
|
|
1024
|
+
byteLength: bytes.byteLength,
|
|
1025
|
+
sourceSha256,
|
|
1026
|
+
alias,
|
|
1027
|
+
status: "opening",
|
|
1028
|
+
reused: false
|
|
1029
|
+
};
|
|
1030
|
+
},
|
|
1031
|
+
describe(alias) {
|
|
1032
|
+
const canvases = [...byAlias.values()].map(view);
|
|
1033
|
+
const live = canvases.filter((canvas) => canvas.status !== "unavailable");
|
|
1034
|
+
const target = alias !== void 0 ? select(alias) : live.length === 1 ? byAlias.get(live[0].alias) : void 0;
|
|
1035
|
+
if (target === void 0) return {
|
|
1036
|
+
catalogToken: "",
|
|
1037
|
+
tools: [],
|
|
1038
|
+
canvases,
|
|
1039
|
+
nextStep: "Open a file with webmcp.open (or open_authoring_file), then describe it with webmcp.describe({\"alias\":\"canvas-name\"}) (or describe_author_tools)."
|
|
1040
|
+
};
|
|
1041
|
+
const status = view(target).status;
|
|
1042
|
+
const base = {
|
|
1043
|
+
alias: target.alias,
|
|
1044
|
+
path: target.path,
|
|
1045
|
+
status,
|
|
1046
|
+
canvases
|
|
1047
|
+
};
|
|
1048
|
+
if (status !== "ready") return {
|
|
1049
|
+
...base,
|
|
1050
|
+
catalogToken: "",
|
|
1051
|
+
tools: [],
|
|
1052
|
+
nextStep: status === "opening" ? `Wait for ${target.alias} to be ready, then call webmcp.describe({"alias":"${target.alias}"}) (or describe_author_tools).` : `Reopen ${target.path} with webmcp.open({"path":"${target.path}","alias":"${target.alias}"}) (or open_authoring_file).`
|
|
1053
|
+
};
|
|
1054
|
+
return {
|
|
1055
|
+
...base,
|
|
1056
|
+
...target.bridge.describe()
|
|
1057
|
+
};
|
|
1058
|
+
},
|
|
1059
|
+
invoke(input, signal) {
|
|
1060
|
+
const target = select(input.alias);
|
|
1061
|
+
if (target.closed) throw new AuthorBridgeError(`Canvas '${target.alias}' is closed. Reopen its file.`, 503);
|
|
1062
|
+
return target.bridge.invoke(input, signal).then((result) => ({
|
|
1063
|
+
...result,
|
|
1064
|
+
alias: target.alias
|
|
1065
|
+
}));
|
|
1066
|
+
},
|
|
1067
|
+
bridge(alias) {
|
|
1068
|
+
const canvas = select(alias);
|
|
1069
|
+
if (canvas.closed) throw new AuthorBridgeError(`Canvas '${alias}' is closed. Reopen its file.`, 503);
|
|
1070
|
+
return canvas.bridge;
|
|
1071
|
+
},
|
|
1072
|
+
close(alias) {
|
|
1073
|
+
if (!byAlias.has(alias) && retired.has(alias)) return;
|
|
1074
|
+
const canvas = select(alias);
|
|
1075
|
+
canvas.closed = true;
|
|
1076
|
+
canvas.bridge.close();
|
|
1077
|
+
canvas.bridge = createBridge();
|
|
1078
|
+
changed();
|
|
1079
|
+
},
|
|
1080
|
+
/** Canvases still open, oldest first; a canvas whose browser disconnected still counts. `po/author` adds the type. */
|
|
1081
|
+
openCanvases() {
|
|
1082
|
+
return [...byAlias.values()].filter((canvas) => !canvas.closed).map((canvas) => ({
|
|
1083
|
+
alias: canvas.alias,
|
|
1084
|
+
path: canvas.path
|
|
1085
|
+
}));
|
|
1086
|
+
},
|
|
1087
|
+
onChange(listener) {
|
|
1088
|
+
listeners.add(listener);
|
|
1089
|
+
return () => listeners.delete(listener);
|
|
1090
|
+
},
|
|
1091
|
+
dispose() {
|
|
1092
|
+
for (const canvas of byAlias.values()) canvas.bridge.close();
|
|
1093
|
+
byAlias.clear();
|
|
1094
|
+
byPath.clear();
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
//#endregion
|
|
1099
|
+
//#region ../../foundations/po-author/src/types/apiRoutes.ts
|
|
1100
|
+
/**
|
|
1101
|
+
* This package's routes, as data.
|
|
1102
|
+
*
|
|
1103
|
+
* No scope and no base path. The build reads both off
|
|
1104
|
+
* `src/extensions/workspaces/sessions/(backend)/api/author/`, so the mount is
|
|
1105
|
+
* stated once, by the folder that creates it. The browser used to restate it:
|
|
1106
|
+
* `authorStateUrl` built one URL from `API_BASE_PATH` and the document helper
|
|
1107
|
+
* two files away spelled `author` out again as a literal, so the two could
|
|
1108
|
+
* disagree and nothing would say so.
|
|
1109
|
+
*
|
|
1110
|
+
* The order below is the order the three Hono apps register in: `/state` in
|
|
1111
|
+
* `authorApi`, the eight bridge routes in `authorBridgeApi`, the three document
|
|
1112
|
+
* routes in `authorDocumentApi`. A reviewer can read the two side by side.
|
|
1113
|
+
*
|
|
1114
|
+
* Response types are named only where a caller reads the body. The bridge
|
|
1115
|
+
* routes are called by the hub's author channel over `requestSessionApi`, which
|
|
1116
|
+
* has its own message vocabulary and never sees this client.
|
|
1117
|
+
*/
|
|
1118
|
+
const routes = defineApiRoutes({
|
|
1119
|
+
state: {
|
|
1120
|
+
method: "GET",
|
|
1121
|
+
path: "/state",
|
|
1122
|
+
response: /* @__PURE__ */ apiResponse()
|
|
1123
|
+
},
|
|
1124
|
+
bridgeRegister: {
|
|
1125
|
+
method: "POST",
|
|
1126
|
+
path: "/bridge/register"
|
|
1127
|
+
},
|
|
1128
|
+
bridgeCatalog: {
|
|
1129
|
+
method: "POST",
|
|
1130
|
+
path: "/bridge/catalog"
|
|
1131
|
+
},
|
|
1132
|
+
/** Long-polls for the next capability request, so it settles when one arrives. */
|
|
1133
|
+
bridgeNext: {
|
|
1134
|
+
method: "POST",
|
|
1135
|
+
path: "/bridge/next"
|
|
1136
|
+
},
|
|
1137
|
+
bridgeResult: {
|
|
1138
|
+
method: "POST",
|
|
1139
|
+
path: "/bridge/result"
|
|
1140
|
+
},
|
|
1141
|
+
bridgeCancelled: {
|
|
1142
|
+
method: "POST",
|
|
1143
|
+
path: "/bridge/cancelled"
|
|
1144
|
+
},
|
|
1145
|
+
bridgeDisconnect: {
|
|
1146
|
+
method: "POST",
|
|
1147
|
+
path: "/bridge/disconnect"
|
|
1148
|
+
},
|
|
1149
|
+
bridgeClose: {
|
|
1150
|
+
method: "POST",
|
|
1151
|
+
path: "/bridge/close"
|
|
1152
|
+
},
|
|
1153
|
+
bridgeDescribe: {
|
|
1154
|
+
method: "GET",
|
|
1155
|
+
path: "/bridge/describe",
|
|
1156
|
+
query: ["alias"]
|
|
1157
|
+
},
|
|
1158
|
+
bridgeInvoke: {
|
|
1159
|
+
method: "POST",
|
|
1160
|
+
path: "/bridge/invoke"
|
|
1161
|
+
},
|
|
1162
|
+
/**
|
|
1163
|
+
* Parses one structured document.
|
|
1164
|
+
*
|
|
1165
|
+
* Answers a byte-length summary instead when the request names no format,
|
|
1166
|
+
* which is the agent-side tool path; the page always names one.
|
|
1167
|
+
*/
|
|
1168
|
+
documentsOpen: {
|
|
1169
|
+
method: "POST",
|
|
1170
|
+
path: "/documents/open",
|
|
1171
|
+
query: ["session"],
|
|
1172
|
+
response: /* @__PURE__ */ apiResponse()
|
|
1173
|
+
},
|
|
1174
|
+
documentsPreflight: {
|
|
1175
|
+
method: "POST",
|
|
1176
|
+
path: "/documents/preflight",
|
|
1177
|
+
query: ["session"],
|
|
1178
|
+
response: /* @__PURE__ */ apiResponse()
|
|
1179
|
+
},
|
|
1180
|
+
documentsSerialize: {
|
|
1181
|
+
method: "POST",
|
|
1182
|
+
path: "/documents/serialize",
|
|
1183
|
+
query: ["session"],
|
|
1184
|
+
response: /* @__PURE__ */ apiResponse()
|
|
1185
|
+
},
|
|
1186
|
+
/** Exact source bytes and conditional replacement, scoped to this Author session. */
|
|
1187
|
+
file: {
|
|
1188
|
+
method: "GET",
|
|
1189
|
+
path: "/file",
|
|
1190
|
+
query: ["path"],
|
|
1191
|
+
raw: true
|
|
1192
|
+
},
|
|
1193
|
+
fileWrite: {
|
|
1194
|
+
method: "PUT",
|
|
1195
|
+
path: "/file",
|
|
1196
|
+
query: ["path"],
|
|
1197
|
+
raw: true
|
|
1198
|
+
}
|
|
1199
|
+
});
|
|
1200
|
+
//#endregion
|
|
1201
|
+
//#region ../../foundations/po-author/src/types/authorApi.ts
|
|
1202
|
+
/**
|
|
1203
|
+
* The wire vocabulary this package's API shares with whatever calls it.
|
|
1204
|
+
*
|
|
1205
|
+
* Paths live in `./apiRoutes`, which the Hono apps register from and the
|
|
1206
|
+
* generated client addresses, so neither half can move alone. What stays here
|
|
1207
|
+
* is the mount segment the server registers under and the shape the state
|
|
1208
|
+
* route answers with.
|
|
1209
|
+
*/
|
|
1210
|
+
/** Where a host mounts this package's API; the segment after /api/plugins/. */
|
|
1211
|
+
const API_BASE_PATH = "author";
|
|
1212
|
+
//#endregion
|
|
1213
|
+
//#region ../../foundations/po-author/src/extensions/workspaces/sessions/(backend)/api/author/_lib/authorBridgeApi.ts
|
|
1214
|
+
function record(value) {
|
|
1215
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new AuthorBridgeError("Invalid request.", 400);
|
|
1216
|
+
return value;
|
|
1217
|
+
}
|
|
1218
|
+
function text(value, key) {
|
|
1219
|
+
const result = record(value)[key];
|
|
1220
|
+
if (typeof result !== "string" || result === "") throw new AuthorBridgeError(`Invalid ${key}.`, 400);
|
|
1221
|
+
return result;
|
|
1222
|
+
}
|
|
1223
|
+
function generation(value) {
|
|
1224
|
+
const result = record(value).generation;
|
|
1225
|
+
if (!Number.isSafeInteger(result) || result < 0) throw new AuthorBridgeError("Invalid generation.", 400);
|
|
1226
|
+
return result;
|
|
1227
|
+
}
|
|
1228
|
+
async function body(request) {
|
|
1229
|
+
return record(await request.json());
|
|
1230
|
+
}
|
|
1231
|
+
function createAuthorBridgeApi(registry) {
|
|
1232
|
+
const app = new Hono();
|
|
1233
|
+
app.onError((error, context) => context.json({ error: error instanceof Error ? error.message : String(error) }, error instanceof AuthorBridgeError ? error.status : 500));
|
|
1234
|
+
app.post(routes.bridgeRegister.path, async (context) => {
|
|
1235
|
+
const value = await body(context.req.raw);
|
|
1236
|
+
const alias = text(value, "alias");
|
|
1237
|
+
return context.json({
|
|
1238
|
+
...registry.bridge(alias).register(text(value, "bindingId"), generation(value)),
|
|
1239
|
+
alias
|
|
1240
|
+
});
|
|
1241
|
+
});
|
|
1242
|
+
app.post(routes.bridgeCatalog.path, async (context) => {
|
|
1243
|
+
const value = await body(context.req.raw);
|
|
1244
|
+
const tools = value.tools;
|
|
1245
|
+
if (!Array.isArray(tools)) throw new AuthorBridgeError("Invalid Author catalog.", 400);
|
|
1246
|
+
const alias = text(value, "alias");
|
|
1247
|
+
return context.json({
|
|
1248
|
+
...registry.bridge(alias).catalog(text(value, "bindingId"), generation(value), text(value, "ownerToken"), tools),
|
|
1249
|
+
alias
|
|
1250
|
+
});
|
|
1251
|
+
});
|
|
1252
|
+
app.post(routes.bridgeNext.path, async (context) => {
|
|
1253
|
+
const value = await body(context.req.raw);
|
|
1254
|
+
const alias = text(value, "alias");
|
|
1255
|
+
return context.json({
|
|
1256
|
+
...await registry.bridge(alias).next(text(value, "bindingId"), generation(value), text(value, "ownerToken"), context.req.raw.signal),
|
|
1257
|
+
alias
|
|
1258
|
+
});
|
|
1259
|
+
});
|
|
1260
|
+
app.post(routes.bridgeResult.path, async (context) => {
|
|
1261
|
+
const value = await body(context.req.raw);
|
|
1262
|
+
registry.bridge(text(value, "alias")).result(text(value, "bindingId"), generation(value), text(value, "ownerToken"), text(value, "catalogToken"), text(value, "requestId"), value.result);
|
|
1263
|
+
return context.json({ accepted: true });
|
|
1264
|
+
});
|
|
1265
|
+
app.post(routes.bridgeCancelled.path, async (context) => {
|
|
1266
|
+
const value = await body(context.req.raw);
|
|
1267
|
+
registry.bridge(text(value, "alias")).cancelled(text(value, "bindingId"), generation(value), text(value, "ownerToken"), text(value, "catalogToken"), text(value, "requestId"));
|
|
1268
|
+
return context.json({ accepted: true });
|
|
1269
|
+
});
|
|
1270
|
+
app.post(routes.bridgeDisconnect.path, async (context) => {
|
|
1271
|
+
const value = await body(context.req.raw);
|
|
1272
|
+
registry.bridge(text(value, "alias")).disconnect(text(value, "bindingId"), generation(value));
|
|
1273
|
+
return context.json({ accepted: true });
|
|
1274
|
+
});
|
|
1275
|
+
app.post(routes.bridgeClose.path, async (context) => {
|
|
1276
|
+
const value = await body(context.req.raw);
|
|
1277
|
+
registry.close(text(value, "alias"));
|
|
1278
|
+
return context.json({ accepted: true });
|
|
1279
|
+
});
|
|
1280
|
+
app.get(routes.bridgeDescribe.path, (context) => context.json(registry.describe(context.req.query("alias"))));
|
|
1281
|
+
app.post(routes.bridgeInvoke.path, async (context) => {
|
|
1282
|
+
const value = parseUseAuthorToolInput(await context.req.raw.json());
|
|
1283
|
+
return context.json(await registry.invoke(value, context.req.raw.signal));
|
|
1284
|
+
});
|
|
1285
|
+
return app;
|
|
1286
|
+
}
|
|
1287
|
+
//#endregion
|
|
1288
|
+
//#region ../../../node_modules/.pnpm/hono@4.13.13/node_modules/hono/dist/utils/mime.js
|
|
1289
|
+
/**
|
|
1290
|
+
* @module
|
|
1291
|
+
* MIME utility.
|
|
1292
|
+
*/
|
|
1293
|
+
const getMimeType = (filename, mimes = baseMimes) => {
|
|
1294
|
+
const match = filename.match(/\.([a-zA-Z0-9]+?)$/);
|
|
1295
|
+
if (!match) return;
|
|
1296
|
+
return mimes[match[1].toLowerCase()];
|
|
1297
|
+
};
|
|
1298
|
+
const baseMimes = {
|
|
1299
|
+
aac: "audio/aac",
|
|
1300
|
+
avi: "video/x-msvideo",
|
|
1301
|
+
avif: "image/avif",
|
|
1302
|
+
av1: "video/av1",
|
|
1303
|
+
bin: "application/octet-stream",
|
|
1304
|
+
bmp: "image/bmp",
|
|
1305
|
+
css: "text/css; charset=utf-8",
|
|
1306
|
+
csv: "text/csv; charset=utf-8",
|
|
1307
|
+
eot: "application/vnd.ms-fontobject",
|
|
1308
|
+
epub: "application/epub+zip",
|
|
1309
|
+
gif: "image/gif",
|
|
1310
|
+
gz: "application/gzip",
|
|
1311
|
+
htm: "text/html; charset=utf-8",
|
|
1312
|
+
html: "text/html; charset=utf-8",
|
|
1313
|
+
ico: "image/x-icon",
|
|
1314
|
+
ics: "text/calendar; charset=utf-8",
|
|
1315
|
+
jpeg: "image/jpeg",
|
|
1316
|
+
jpg: "image/jpeg",
|
|
1317
|
+
js: "text/javascript; charset=utf-8",
|
|
1318
|
+
json: "application/json",
|
|
1319
|
+
jsonld: "application/ld+json",
|
|
1320
|
+
map: "application/json",
|
|
1321
|
+
mid: "audio/x-midi",
|
|
1322
|
+
midi: "audio/x-midi",
|
|
1323
|
+
mjs: "text/javascript; charset=utf-8",
|
|
1324
|
+
mp3: "audio/mpeg",
|
|
1325
|
+
mp4: "video/mp4",
|
|
1326
|
+
mpeg: "video/mpeg",
|
|
1327
|
+
oga: "audio/ogg",
|
|
1328
|
+
ogv: "video/ogg",
|
|
1329
|
+
ogx: "application/ogg",
|
|
1330
|
+
opus: "audio/opus",
|
|
1331
|
+
otf: "font/otf",
|
|
1332
|
+
pdf: "application/pdf",
|
|
1333
|
+
png: "image/png",
|
|
1334
|
+
rtf: "application/rtf",
|
|
1335
|
+
svg: "image/svg+xml; charset=utf-8",
|
|
1336
|
+
tif: "image/tiff",
|
|
1337
|
+
tiff: "image/tiff",
|
|
1338
|
+
ts: "video/mp2t",
|
|
1339
|
+
ttf: "font/ttf",
|
|
1340
|
+
txt: "text/plain; charset=utf-8",
|
|
1341
|
+
wasm: "application/wasm",
|
|
1342
|
+
webm: "video/webm",
|
|
1343
|
+
weba: "audio/webm",
|
|
1344
|
+
webmanifest: "application/manifest+json",
|
|
1345
|
+
webp: "image/webp",
|
|
1346
|
+
woff: "font/woff",
|
|
1347
|
+
woff2: "font/woff2",
|
|
1348
|
+
xhtml: "application/xhtml+xml; charset=utf-8",
|
|
1349
|
+
xml: "application/xml; charset=utf-8",
|
|
1350
|
+
zip: "application/zip",
|
|
1351
|
+
"3gp": "video/3gpp",
|
|
1352
|
+
"3g2": "video/3gpp2",
|
|
1353
|
+
gltf: "model/gltf+json",
|
|
1354
|
+
glb: "model/gltf-binary"
|
|
1355
|
+
};
|
|
1356
|
+
//#endregion
|
|
1357
|
+
//#region ../../foundations/po-author/src/extensions/workspaces/sessions/(backend)/api/author/_lib/authorDocumentApi.ts
|
|
1358
|
+
const FORMATS = /* @__PURE__ */ new Set([
|
|
1359
|
+
"markdown-slides",
|
|
1360
|
+
"csv",
|
|
1361
|
+
"pptx",
|
|
1362
|
+
"xlsx"
|
|
1363
|
+
]);
|
|
1364
|
+
function errorResponse(context, error) {
|
|
1365
|
+
const message = error instanceof Error ? error.message : "Document operation failed.";
|
|
1366
|
+
return context.json({ error: message }, error instanceof DocumentRequestError || error instanceof RootBoundReplaceError ? error.status : 422);
|
|
1367
|
+
}
|
|
1368
|
+
function requestFormat(value) {
|
|
1369
|
+
if (typeof value !== "string" || !FORMATS.has(value)) throw new Error("A supported format is required.");
|
|
1370
|
+
return value;
|
|
1371
|
+
}
|
|
1372
|
+
function requestOperations(value) {
|
|
1373
|
+
if (value === void 0) return [];
|
|
1374
|
+
if (!Array.isArray(value) || value.length > 1e5) throw new Error("A bounded operations array is required.");
|
|
1375
|
+
return value.map((operation) => {
|
|
1376
|
+
if (typeof operation !== "object" || operation === null || typeof operation.fragmentId !== "string" || typeof operation.replacement !== "string") throw new Error("Each operation requires string fragmentId and replacement fields.");
|
|
1377
|
+
return operation;
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
async function bodyOf(request) {
|
|
1381
|
+
const body = await request.json();
|
|
1382
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) throw new Error("A JSON object is required.");
|
|
1383
|
+
return body;
|
|
1384
|
+
}
|
|
1385
|
+
function createAuthorDocumentApi(options = {}) {
|
|
1386
|
+
const app = new Hono();
|
|
1387
|
+
const admittedCwd = () => {
|
|
1388
|
+
if (options.cwd === void 0) throw new DocumentRequestError("Author requires the session working directory.", 403);
|
|
1389
|
+
return options.cwd;
|
|
1390
|
+
};
|
|
1391
|
+
app.get(routes.file.path, async (context) => {
|
|
1392
|
+
try {
|
|
1393
|
+
const source = await resolveDocument(admittedCwd(), context.req.query("path"), options.sessionId, options.environment, options.fileSystem);
|
|
1394
|
+
const bytes = await readSource(source, options.workflowVisible, options.fileSystem);
|
|
1395
|
+
const digest = digestOf(bytes);
|
|
1396
|
+
const version = `"${digest}"`;
|
|
1397
|
+
const headers = new Headers({
|
|
1398
|
+
"Content-Type": getMimeType(source.path) ?? "application/octet-stream",
|
|
1399
|
+
"X-File-SHA256": digest,
|
|
1400
|
+
"Cache-Control": "no-store",
|
|
1401
|
+
"Accept-Ranges": "bytes",
|
|
1402
|
+
ETag: version
|
|
1403
|
+
});
|
|
1404
|
+
const expected = context.req.header("if-match");
|
|
1405
|
+
if (expected !== void 0 && expected !== version) return new Response(null, {
|
|
1406
|
+
status: 412,
|
|
1407
|
+
headers
|
|
1408
|
+
});
|
|
1409
|
+
const range = context.req.header("range");
|
|
1410
|
+
let start = 0;
|
|
1411
|
+
let end = bytes.byteLength - 1;
|
|
1412
|
+
if (range !== void 0) {
|
|
1413
|
+
const match = /^bytes=(\d*)-(\d*)$/.exec(range);
|
|
1414
|
+
if (!match || !match[1] && !match[2] || bytes.byteLength === 0 || [match[1], match[2]].some((value) => value !== "" && !Number.isSafeInteger(Number(value)))) {
|
|
1415
|
+
headers.set("Content-Range", `bytes */${bytes.byteLength}`);
|
|
1416
|
+
return new Response(null, {
|
|
1417
|
+
status: 416,
|
|
1418
|
+
headers
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
if (match[1] === "") {
|
|
1422
|
+
const suffix = Number(match[2]);
|
|
1423
|
+
start = suffix > 0 ? Math.max(0, bytes.byteLength - suffix) : bytes.byteLength;
|
|
1424
|
+
} else {
|
|
1425
|
+
start = Number(match[1]);
|
|
1426
|
+
end = match[2] === "" ? end : Math.min(end, Number(match[2]));
|
|
1427
|
+
}
|
|
1428
|
+
if (start > end || start >= bytes.byteLength) {
|
|
1429
|
+
headers.set("Content-Range", `bytes */${bytes.byteLength}`);
|
|
1430
|
+
return new Response(null, {
|
|
1431
|
+
status: 416,
|
|
1432
|
+
headers
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
headers.set("Content-Range", `bytes ${start}-${end}/${bytes.byteLength}`);
|
|
1436
|
+
}
|
|
1437
|
+
const body = bytes.subarray(start, Math.max(start, end + 1));
|
|
1438
|
+
headers.set("Content-Length", String(body.byteLength));
|
|
1439
|
+
return new Response(body, {
|
|
1440
|
+
status: range === void 0 ? 200 : 206,
|
|
1441
|
+
headers
|
|
1442
|
+
});
|
|
1443
|
+
} catch (error) {
|
|
1444
|
+
return errorResponse(context, error);
|
|
1445
|
+
}
|
|
1446
|
+
});
|
|
1447
|
+
app.put(routes.fileWrite.path, async (context) => {
|
|
1448
|
+
try {
|
|
1449
|
+
const requested = context.req.query("path");
|
|
1450
|
+
const source = await resolveDocument(admittedCwd(), requested, options.sessionId, options.environment, options.fileSystem);
|
|
1451
|
+
if (source.kind === "artifact") throw new DocumentRequestError("Artifacts are read-only.", 403);
|
|
1452
|
+
const expectedSha256 = context.req.header("X-Expected-SHA256");
|
|
1453
|
+
if (expectedSha256 === void 0 || !/^[a-f0-9]{64}$/.test(expectedSha256)) throw new DocumentRequestError("X-Expected-SHA256 is required.", 400);
|
|
1454
|
+
const chunks = [];
|
|
1455
|
+
let length = 0;
|
|
1456
|
+
const reader = context.req.raw.body?.getReader();
|
|
1457
|
+
if (reader !== void 0) try {
|
|
1458
|
+
while (true) {
|
|
1459
|
+
const part = await reader.read();
|
|
1460
|
+
if (part.done) break;
|
|
1461
|
+
length += part.value.byteLength;
|
|
1462
|
+
if (length > 1048576) {
|
|
1463
|
+
await reader.cancel();
|
|
1464
|
+
throw new DocumentRequestError("File exceeds the save limit.", 413);
|
|
1465
|
+
}
|
|
1466
|
+
chunks.push(part.value);
|
|
1467
|
+
}
|
|
1468
|
+
} finally {
|
|
1469
|
+
reader.releaseLock();
|
|
1470
|
+
}
|
|
1471
|
+
const bytes = new Uint8Array(length);
|
|
1472
|
+
let offset = 0;
|
|
1473
|
+
for (const chunk of chunks) {
|
|
1474
|
+
bytes.set(chunk, offset);
|
|
1475
|
+
offset += chunk.byteLength;
|
|
1476
|
+
}
|
|
1477
|
+
const sha256 = await replaceRootBoundFile({
|
|
1478
|
+
root: source.root,
|
|
1479
|
+
relativePath: requested,
|
|
1480
|
+
expectedSha256,
|
|
1481
|
+
bytes,
|
|
1482
|
+
maxBytes: AUTHOR_DOCUMENT_MAX_BYTES,
|
|
1483
|
+
signal: context.req.raw.signal,
|
|
1484
|
+
fileSystem: options.fileSystem
|
|
1485
|
+
});
|
|
1486
|
+
return new Response(null, {
|
|
1487
|
+
status: 204,
|
|
1488
|
+
headers: { "X-File-SHA256": sha256 }
|
|
1489
|
+
});
|
|
1490
|
+
} catch (error) {
|
|
1491
|
+
return errorResponse(context, error);
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
app.post(routes.documentsOpen.path, async (context) => {
|
|
1495
|
+
try {
|
|
1496
|
+
const body = await bodyOf(context.req.raw);
|
|
1497
|
+
if (body.format === void 0 && options.open !== void 0) return context.json(await options.open(body.path, context.req.raw.signal, body.alias));
|
|
1498
|
+
const bytes = await readDocument(admittedCwd(), body.path, options.sessionId, options.environment, options.workflowVisible, options.fileSystem);
|
|
1499
|
+
if (body.format === void 0) return context.json({
|
|
1500
|
+
path: body.path,
|
|
1501
|
+
byteLength: bytes.byteLength
|
|
1502
|
+
});
|
|
1503
|
+
return context.json(await parseStructuredDocument(requestFormat(body.format), bytes, body.csvDialect));
|
|
1504
|
+
} catch (error) {
|
|
1505
|
+
return errorResponse(context, error);
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
app.post(routes.documentsPreflight.path, async (context) => {
|
|
1509
|
+
try {
|
|
1510
|
+
const body = await bodyOf(context.req.raw);
|
|
1511
|
+
const bytes = await readDocument(admittedCwd(), body.path, options.sessionId, options.environment, options.workflowVisible, options.fileSystem);
|
|
1512
|
+
return context.json(await preflightStructuredDocument(requestFormat(body.format), bytes, requestOperations(body.operations), body.csvDialect));
|
|
1513
|
+
} catch (error) {
|
|
1514
|
+
return errorResponse(context, error);
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
app.post(routes.documentsSerialize.path, async (context) => {
|
|
1518
|
+
try {
|
|
1519
|
+
const body = await bodyOf(context.req.raw);
|
|
1520
|
+
if (typeof body.preflightDigest !== "string") throw new Error("A preflight report digest is required.");
|
|
1521
|
+
const bytes = await readDocument(admittedCwd(), body.path, options.sessionId, options.environment, options.workflowVisible, options.fileSystem);
|
|
1522
|
+
const serialized = await serializeStructuredDocument(requestFormat(body.format), bytes, requestOperations(body.operations), body.preflightDigest, body.csvDialect);
|
|
1523
|
+
return context.json({
|
|
1524
|
+
bytes: Buffer.from(serialized.bytes).toString("base64"),
|
|
1525
|
+
encoding: "base64",
|
|
1526
|
+
manifest: serialized.manifest,
|
|
1527
|
+
operationLog: serialized.operationLog
|
|
1528
|
+
});
|
|
1529
|
+
} catch (error) {
|
|
1530
|
+
return errorResponse(context, error);
|
|
1531
|
+
}
|
|
1532
|
+
});
|
|
1533
|
+
return app;
|
|
1534
|
+
}
|
|
1535
|
+
//#endregion
|
|
1536
|
+
//#region ../../foundations/po-author/src/extensions/workspaces/sessions/(backend)/api/author/_lib/authorApi.ts
|
|
1537
|
+
const inactiveState = () => ({
|
|
1538
|
+
activation: "inactive",
|
|
1539
|
+
capabilityCount: 0
|
|
1540
|
+
});
|
|
1541
|
+
const createBridge = () => createAuthorBridgeState({
|
|
1542
|
+
now: Date.now,
|
|
1543
|
+
issueToken: randomUUID,
|
|
1544
|
+
scheduleTimeout(callback, delayMs) {
|
|
1545
|
+
const timer = setTimeout(callback, delayMs);
|
|
1546
|
+
timer.unref?.();
|
|
1547
|
+
return () => clearTimeout(timer);
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
function createAuthorApi(options = {}) {
|
|
1551
|
+
if (options.cwd === void 0) throw new Error("Author requires the session working directory.");
|
|
1552
|
+
const app = new Hono();
|
|
1553
|
+
const registry = options.registry ?? createAuthorCanvasRegistry(options.cwd, createBridge, options.sessionId, options.environment, options.workflowVisible, options.fileSystem);
|
|
1554
|
+
app.get(routes.state.path, (context) => context.json({
|
|
1555
|
+
sessionId: options.sessionId ?? null,
|
|
1556
|
+
...(options.readState ?? inactiveState)()
|
|
1557
|
+
}));
|
|
1558
|
+
app.route("/", createAuthorBridgeApi(registry));
|
|
1559
|
+
app.route("/", createAuthorDocumentApi({
|
|
1560
|
+
...options.cwd === void 0 ? {} : { cwd: options.cwd },
|
|
1561
|
+
...options.sessionId === void 0 ? {} : { sessionId: options.sessionId },
|
|
1562
|
+
...options.environment === void 0 ? {} : { environment: options.environment },
|
|
1563
|
+
workflowVisible: options.workflowVisible,
|
|
1564
|
+
fileSystem: options.fileSystem,
|
|
1565
|
+
open: (path, signal, alias) => registry.open(path, signal, alias)
|
|
1566
|
+
}));
|
|
1567
|
+
return app;
|
|
1568
|
+
}
|
|
1569
|
+
const api = {
|
|
1570
|
+
basePath: API_BASE_PATH,
|
|
1571
|
+
start(context) {
|
|
1572
|
+
if (context.cwd === void 0) throw new Error("Author requires the session working directory.");
|
|
1573
|
+
const registry = createAuthorCanvasRegistry(context.cwd, createBridge, context.sessionId, context.environment);
|
|
1574
|
+
const app = createAuthorApi({
|
|
1575
|
+
...context.sessionId === void 0 ? {} : { sessionId: context.sessionId },
|
|
1576
|
+
cwd: context.cwd,
|
|
1577
|
+
...context.environment === void 0 ? {} : { environment: context.environment },
|
|
1578
|
+
registry
|
|
1579
|
+
});
|
|
1580
|
+
return {
|
|
1581
|
+
fetch: (request) => app.fetch(request),
|
|
1582
|
+
close: () => registry.dispose()
|
|
1583
|
+
};
|
|
1584
|
+
}
|
|
1585
|
+
};
|
|
1586
|
+
/** The session API and tools share the same browser ownership and pending requests. */
|
|
1587
|
+
function createAuthorSessionApi(cwd, sessionId, environment, publishCanvases, workflowVisible, fileSystem) {
|
|
1588
|
+
const registry = createAuthorCanvasRegistry(cwd, createBridge, sessionId, environment, workflowVisible, fileSystem);
|
|
1589
|
+
if (publishCanvases !== void 0) {
|
|
1590
|
+
registry.onChange(() => publishCanvases(registry.openCanvases()));
|
|
1591
|
+
publishCanvases([]);
|
|
1592
|
+
}
|
|
1593
|
+
return {
|
|
1594
|
+
catalog: {
|
|
1595
|
+
open: (path, signal, alias) => registry.open(path, signal, alias),
|
|
1596
|
+
async describe(signal, alias) {
|
|
1597
|
+
signal?.throwIfAborted();
|
|
1598
|
+
return registry.describe(alias);
|
|
1599
|
+
},
|
|
1600
|
+
execute: (input, signal) => registry.invoke(input, signal)
|
|
1601
|
+
},
|
|
1602
|
+
api: {
|
|
1603
|
+
basePath: API_BASE_PATH,
|
|
1604
|
+
start() {
|
|
1605
|
+
const app = createAuthorApi({
|
|
1606
|
+
cwd,
|
|
1607
|
+
sessionId,
|
|
1608
|
+
environment,
|
|
1609
|
+
registry,
|
|
1610
|
+
workflowVisible,
|
|
1611
|
+
fileSystem
|
|
1612
|
+
});
|
|
1613
|
+
return {
|
|
1614
|
+
fetch: (request) => app.fetch(request),
|
|
1615
|
+
close: () => registry.dispose()
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
//#endregion
|
|
1622
|
+
//#region ../../foundations/po-author/src/extensions/workspaces/sessions/(backend)/root.server.ts
|
|
1623
|
+
var root_server_default = defineRoot(({ agent, host, context, signal }) => {
|
|
1624
|
+
const { environment, directEvents } = host.context;
|
|
1625
|
+
if (agent && environment === void 0) throw new Error("Author requires an admitted session environment.");
|
|
1626
|
+
const workflowVisible = (relativePath, kind) => !signal.aborted && context.get("po/artifacts")?.workflowVisible(relativePath, kind) === true;
|
|
1627
|
+
const cwd = agent?.context.cwd ?? host.context.cwd;
|
|
1628
|
+
const sessionId = agent?.context.sessionId ?? host.context.sessionId;
|
|
1629
|
+
let service;
|
|
1630
|
+
const fileSystem = readPoFs(context);
|
|
1631
|
+
const session = cwd && sessionId && environment ? createAuthorSessionApi(cwd, sessionId, environment, (canvases) => service?.changed(canvases), workflowVisible, fileSystem) : void 0;
|
|
1632
|
+
let disposed = false;
|
|
1633
|
+
const authorService = createAuthorService(createAuthorCatalog(session?.catalog), session !== void 0 && cwd && sessionId && environment ? { preview: {
|
|
1634
|
+
cwd,
|
|
1635
|
+
sessionId,
|
|
1636
|
+
environment,
|
|
1637
|
+
workflowVisible,
|
|
1638
|
+
...fileSystem ? { fileSystem } : {}
|
|
1639
|
+
} } : {});
|
|
1640
|
+
service = authorService;
|
|
1641
|
+
if (session !== void 0 && sessionId !== void 0) {
|
|
1642
|
+
const publish = () => directEvents?.publish(authorCanvasesFrame, sessionId, { canvases: [...authorService.openCanvases()] });
|
|
1643
|
+
authorService.subscribe(publish);
|
|
1644
|
+
publish();
|
|
1645
|
+
}
|
|
1646
|
+
const provideService = (context) => {
|
|
1647
|
+
context.inject([PO_SERVER_SCOPE_SERVICE], async (scoped) => {
|
|
1648
|
+
const withdraw = await requirePoServerScope(scoped).provide(PO_AUTHOR_CONTRACT, authorService);
|
|
1649
|
+
return () => withdraw();
|
|
1650
|
+
});
|
|
1651
|
+
};
|
|
1652
|
+
const assertAlive = () => {
|
|
1653
|
+
signal.throwIfAborted();
|
|
1654
|
+
if (disposed) throw new Error("Author session is disposed.");
|
|
1655
|
+
};
|
|
1656
|
+
const mountNamespace = (context) => {
|
|
1657
|
+
if (!agent) return;
|
|
1658
|
+
const namespace = createWebmcpNamespace(authorService, agent.context.sessionId, assertAlive);
|
|
1659
|
+
context.inject([PO_CODEMODE_SERVICE], (scoped) => {
|
|
1660
|
+
const codemode = readPoCodemode(scoped);
|
|
1661
|
+
if (!codemode) return void 0;
|
|
1662
|
+
const registration = codemode.register("@agimon-ai/po-author", namespace);
|
|
1663
|
+
const withdrawn = agent.registerToolRestriction({ excludedTools: [...AUTHOR_DIRECT_TOOL_NAMES] });
|
|
1664
|
+
const guides = createAuthorGuides(agent, authorService);
|
|
1665
|
+
return () => {
|
|
1666
|
+
guides.dispose();
|
|
1667
|
+
withdrawn.dispose();
|
|
1668
|
+
registration.dispose();
|
|
1669
|
+
};
|
|
1670
|
+
});
|
|
1671
|
+
};
|
|
1672
|
+
return {
|
|
1673
|
+
onDispose: () => {
|
|
1674
|
+
disposed = true;
|
|
1675
|
+
},
|
|
1676
|
+
value: {
|
|
1677
|
+
api: session?.api ?? api,
|
|
1678
|
+
catalog: authorService,
|
|
1679
|
+
assertAlive,
|
|
1680
|
+
service: authorService
|
|
1681
|
+
},
|
|
1682
|
+
services: [provideService, mountNamespace]
|
|
1683
|
+
};
|
|
1684
|
+
});
|
|
1685
|
+
//#endregion
|
|
1686
|
+
//#region ../../foundations/po-author/src/extensions/workspaces/sessions/(backend)/contract/author.server.ts
|
|
1687
|
+
var author_server_default$1 = defineServiceContract(PO_AUTHOR_CONTRACT.name, PO_AUTHOR_CONTRACT);
|
|
1688
|
+
//#endregion
|
|
1689
|
+
//#region ../../foundations/po-author/src/services/webAuthorChannel/index.ts
|
|
1690
|
+
/**
|
|
1691
|
+
* Which route carries each message the browser sends.
|
|
1692
|
+
*
|
|
1693
|
+
* The paths come from the package's one route table, so the hub cannot address
|
|
1694
|
+
* a bridge route the session no longer serves. `release` is absent because it
|
|
1695
|
+
* is answered by the disconnect route rather than one of its own.
|
|
1696
|
+
*/
|
|
1697
|
+
const BRIDGE_ROUTE = {
|
|
1698
|
+
register: routes.bridgeRegister.path,
|
|
1699
|
+
catalog: routes.bridgeCatalog.path,
|
|
1700
|
+
result: routes.bridgeResult.path,
|
|
1701
|
+
cancelled: routes.bridgeCancelled.path
|
|
1702
|
+
};
|
|
1703
|
+
function isRecord(value) {
|
|
1704
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1705
|
+
}
|
|
1706
|
+
function browserMessage(value) {
|
|
1707
|
+
if (!isRecord(value) || typeof value.kind !== "string" || typeof value.alias !== "string" || !AUTHOR_ALIAS_PATTERN.test(value.alias)) return void 0;
|
|
1708
|
+
if (![
|
|
1709
|
+
"register",
|
|
1710
|
+
"release",
|
|
1711
|
+
"catalog",
|
|
1712
|
+
"result",
|
|
1713
|
+
"cancelled"
|
|
1714
|
+
].includes(value.kind)) return void 0;
|
|
1715
|
+
return value;
|
|
1716
|
+
}
|
|
1717
|
+
/** The session's open canvases, or undefined when the frame is not a bounded list of valid aliases, paths and types. */
|
|
1718
|
+
function openCanvases(value) {
|
|
1719
|
+
if (!isRecord(value) || !Array.isArray(value.canvases) || value.canvases.length > 32) return void 0;
|
|
1720
|
+
const canvases = [];
|
|
1721
|
+
for (const entry of value.canvases) {
|
|
1722
|
+
if (!isRecord(entry) || typeof entry.alias !== "string" || !AUTHOR_ALIAS_PATTERN.test(entry.alias) || typeof entry.path !== "string" || entry.path === "" || typeof entry.type !== "string" || entry.type === "") return void 0;
|
|
1723
|
+
canvases.push({
|
|
1724
|
+
alias: entry.alias,
|
|
1725
|
+
path: entry.path,
|
|
1726
|
+
type: entry.type
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
return canvases;
|
|
1730
|
+
}
|
|
1731
|
+
async function responsePayload(response) {
|
|
1732
|
+
const value = await response.json();
|
|
1733
|
+
if (response.ok) return value;
|
|
1734
|
+
return {
|
|
1735
|
+
kind: "rejected",
|
|
1736
|
+
reason: isRecord(value) && typeof value.error === "string" ? value.error : `Author bridge HTTP ${response.status}`
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
function createAuthorChannel() {
|
|
1740
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
1741
|
+
let host;
|
|
1742
|
+
let closed = false;
|
|
1743
|
+
const keyOf = (sessionId, connectionId, alias) => `${sessionId}\0${connectionId}\0${alias}`;
|
|
1744
|
+
const send = async (scope, path, value, signal) => await host.requestSessionApi(scope, {
|
|
1745
|
+
basePath: API_BASE_PATH,
|
|
1746
|
+
path,
|
|
1747
|
+
method: "POST",
|
|
1748
|
+
body: JSON.stringify(value),
|
|
1749
|
+
...signal === void 0 ? {} : { signal }
|
|
1750
|
+
});
|
|
1751
|
+
let sequence = 0;
|
|
1752
|
+
const publish = (binding, payload) => host?.publishToConnection?.(binding.connectionId, binding.scope.sessionId, {
|
|
1753
|
+
...payload,
|
|
1754
|
+
alias: binding.alias,
|
|
1755
|
+
seq: ++sequence
|
|
1756
|
+
}) ?? false;
|
|
1757
|
+
const poll = async (binding) => {
|
|
1758
|
+
binding.poll?.abort();
|
|
1759
|
+
const controller = new AbortController();
|
|
1760
|
+
binding.poll = controller;
|
|
1761
|
+
while (!closed && bindings.get(keyOf(binding.scope.sessionId, binding.connectionId, binding.alias)) === binding) try {
|
|
1762
|
+
const payload = await responsePayload(await send(binding.scope, routes.bridgeNext.path, {
|
|
1763
|
+
alias: binding.alias,
|
|
1764
|
+
bindingId: binding.connectionId,
|
|
1765
|
+
generation: binding.generation,
|
|
1766
|
+
ownerToken: binding.ownerToken
|
|
1767
|
+
}, controller.signal));
|
|
1768
|
+
if (controller.signal.aborted) break;
|
|
1769
|
+
if (!publish(binding, payload) || payload.kind === "rejected") break;
|
|
1770
|
+
} catch (error) {
|
|
1771
|
+
if (!controller.signal.aborted) host?.onNotice(error instanceof Error ? error.message : String(error));
|
|
1772
|
+
break;
|
|
1773
|
+
}
|
|
1774
|
+
if (binding.poll === controller) binding.poll = void 0;
|
|
1775
|
+
};
|
|
1776
|
+
return {
|
|
1777
|
+
frameType: authorChannelType,
|
|
1778
|
+
lifecycle: "hub",
|
|
1779
|
+
receiveWithoutSubscription: true,
|
|
1780
|
+
start(channelHost) {
|
|
1781
|
+
host = channelHost;
|
|
1782
|
+
const latest = /* @__PURE__ */ new Map();
|
|
1783
|
+
const subscriptions = /* @__PURE__ */ new Map();
|
|
1784
|
+
return {
|
|
1785
|
+
payloadFor: (scope) => latest.get(scope.sessionId),
|
|
1786
|
+
sessionAdded(scope) {
|
|
1787
|
+
subscriptions.get(scope.sessionId)?.();
|
|
1788
|
+
latest.delete(scope.sessionId);
|
|
1789
|
+
const unsubscribe = channelHost.directEvents.subscribe(authorCanvasesFrame, scope.sessionId, (payload) => {
|
|
1790
|
+
const canvases = openCanvases(payload);
|
|
1791
|
+
if (canvases === void 0) return;
|
|
1792
|
+
const message = {
|
|
1793
|
+
kind: "canvases",
|
|
1794
|
+
canvases
|
|
1795
|
+
};
|
|
1796
|
+
latest.set(scope.sessionId, message);
|
|
1797
|
+
channelHost.publish(scope.sessionId, message);
|
|
1798
|
+
}, { replayLatest: true });
|
|
1799
|
+
subscriptions.set(scope.sessionId, unsubscribe);
|
|
1800
|
+
},
|
|
1801
|
+
sessionRemoved(sessionId) {
|
|
1802
|
+
subscriptions.get(sessionId)?.();
|
|
1803
|
+
subscriptions.delete(sessionId);
|
|
1804
|
+
latest.delete(sessionId);
|
|
1805
|
+
for (const [key, binding] of bindings) {
|
|
1806
|
+
if (binding.scope.sessionId !== sessionId) continue;
|
|
1807
|
+
binding.poll?.abort();
|
|
1808
|
+
bindings.delete(key);
|
|
1809
|
+
send(binding.scope, routes.bridgeDisconnect.path, {
|
|
1810
|
+
alias: binding.alias,
|
|
1811
|
+
bindingId: binding.connectionId,
|
|
1812
|
+
generation: binding.generation
|
|
1813
|
+
}).catch((error) => host?.onNotice(error instanceof Error ? error.message : String(error)));
|
|
1814
|
+
}
|
|
1815
|
+
},
|
|
1816
|
+
close() {
|
|
1817
|
+
closed = true;
|
|
1818
|
+
for (const unsubscribe of subscriptions.values()) unsubscribe();
|
|
1819
|
+
subscriptions.clear();
|
|
1820
|
+
latest.clear();
|
|
1821
|
+
for (const binding of bindings.values()) {
|
|
1822
|
+
binding.poll?.abort();
|
|
1823
|
+
send(binding.scope, routes.bridgeDisconnect.path, {
|
|
1824
|
+
alias: binding.alias,
|
|
1825
|
+
bindingId: binding.connectionId,
|
|
1826
|
+
generation: binding.generation
|
|
1827
|
+
}).catch((error) => host?.onNotice(error instanceof Error ? error.message : String(error)));
|
|
1828
|
+
}
|
|
1829
|
+
bindings.clear();
|
|
1830
|
+
}
|
|
1831
|
+
};
|
|
1832
|
+
},
|
|
1833
|
+
receive(scope, payload, connection) {
|
|
1834
|
+
const message = browserMessage(payload);
|
|
1835
|
+
if (message === void 0 || host === void 0 || closed) return;
|
|
1836
|
+
(async () => {
|
|
1837
|
+
const key = keyOf(scope.sessionId, connection.connectionId, message.alias);
|
|
1838
|
+
const previous = bindings.get(key);
|
|
1839
|
+
if (message.kind === "release") {
|
|
1840
|
+
if (previous === void 0 || previous.generation !== message.generation) return;
|
|
1841
|
+
previous.poll?.abort();
|
|
1842
|
+
bindings.delete(key);
|
|
1843
|
+
await send(scope, routes.bridgeDisconnect.path, {
|
|
1844
|
+
alias: message.alias,
|
|
1845
|
+
bindingId: connection.connectionId,
|
|
1846
|
+
generation: message.generation
|
|
1847
|
+
});
|
|
1848
|
+
return;
|
|
1849
|
+
}
|
|
1850
|
+
const route = BRIDGE_ROUTE[message.kind];
|
|
1851
|
+
const reply = await responsePayload(await send(scope, route, {
|
|
1852
|
+
...message,
|
|
1853
|
+
bindingId: connection.connectionId
|
|
1854
|
+
}));
|
|
1855
|
+
if (reply.kind === "accepted") {
|
|
1856
|
+
const current = bindings.get(key);
|
|
1857
|
+
if (current?.generation === reply.generation && current.ownerToken === reply.ownerToken) {
|
|
1858
|
+
publish(current, reply);
|
|
1859
|
+
if (current.poll === void 0) poll(current);
|
|
1860
|
+
return;
|
|
1861
|
+
}
|
|
1862
|
+
const binding = {
|
|
1863
|
+
alias: message.alias,
|
|
1864
|
+
scope,
|
|
1865
|
+
connectionId: connection.connectionId,
|
|
1866
|
+
generation: reply.generation,
|
|
1867
|
+
ownerToken: reply.ownerToken
|
|
1868
|
+
};
|
|
1869
|
+
current?.poll?.abort();
|
|
1870
|
+
bindings.set(key, binding);
|
|
1871
|
+
publish(binding, reply);
|
|
1872
|
+
poll(binding);
|
|
1873
|
+
} else if (reply.kind === "rejected") {
|
|
1874
|
+
if (previous !== void 0) publish(previous, reply);
|
|
1875
|
+
else host?.publishToConnection?.(connection.connectionId, scope.sessionId, {
|
|
1876
|
+
...reply,
|
|
1877
|
+
alias: message.alias,
|
|
1878
|
+
seq: ++sequence
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
})().catch((error) => host?.onNotice(error instanceof Error ? error.message : String(error)));
|
|
1882
|
+
},
|
|
1883
|
+
disconnected(connection) {
|
|
1884
|
+
for (const [key, binding] of bindings) {
|
|
1885
|
+
if (binding.connectionId !== connection.connectionId) continue;
|
|
1886
|
+
binding.poll?.abort();
|
|
1887
|
+
bindings.delete(key);
|
|
1888
|
+
send(binding.scope, routes.bridgeDisconnect.path, {
|
|
1889
|
+
alias: binding.alias,
|
|
1890
|
+
bindingId: binding.connectionId,
|
|
1891
|
+
generation: binding.generation
|
|
1892
|
+
}).catch((error) => host?.onNotice(error instanceof Error ? error.message : String(error)));
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
};
|
|
1896
|
+
}
|
|
1897
|
+
//#endregion
|
|
1898
|
+
//#region ../../foundations/po-author/src/extensions/(backend)/channel/author-webmcp.server.ts
|
|
1899
|
+
var author_webmcp_server_default = defineChannel(createAuthorChannel);
|
|
1900
|
+
//#endregion
|
|
1901
|
+
//#region ../../foundations/po-author/src/services/authorBridgeMethod/index.ts
|
|
1902
|
+
function createAuthorBridgeMethod(scope, host) {
|
|
1903
|
+
return defineServerMethod(authorBridgeMethod(scope), ({ sessionId, message }, caller) => {
|
|
1904
|
+
if (!caller.connectionId) throw new Error("Author bridge requires an authenticated browser connection.");
|
|
1905
|
+
if (!host.context.receiveChannel?.(sessionId, "author_webmcp", message, caller.connectionId)) throw new Error("Author bridge session is outside this mount.");
|
|
1906
|
+
return {};
|
|
1907
|
+
});
|
|
1908
|
+
}
|
|
1909
|
+
//#endregion
|
|
1910
|
+
//#region ../../foundations/po-author/src/extensions/(backend)/method/bridge.server.ts
|
|
1911
|
+
var bridge_server_default = defineMethod(({ host }) => host.scope === "session" ? { register: () => ({ dispose: () => void 0 }) } : createAuthorBridgeMethod(host.scope, host));
|
|
1912
|
+
//#endregion
|
|
1913
|
+
//#region ../../foundations/po-author/src/extensions/workspaces/sessions/(backend)/api/author/route.server.ts
|
|
1914
|
+
var route_server_default = defineRoute((context) => context.root.api);
|
|
1915
|
+
//#endregion
|
|
1916
|
+
//#region ../../foundations/po-author/src/extensions/workspaces/sessions/(backend)/command/author.server.ts
|
|
1917
|
+
var author_server_default = defineCommand(() => createAuthorCommand());
|
|
1918
|
+
//#endregion
|
|
1919
|
+
//#region ../../foundations/po-author/src/extensions/workspaces/sessions/(backend)/resource/help-how-to-author.server.ts
|
|
1920
|
+
const skillFile = "src/prompts/help-how-to-author/SKILL.md";
|
|
1921
|
+
var help_how_to_author_server_default = defineResource({
|
|
1922
|
+
name: "help-how-to-author",
|
|
1923
|
+
description: "Extend Po Author from another package: register a canvas type and its guide through the po/author session service, add its browser tools through the author.canvas-type slot, and fill the existing Author slots. Use when a plugin should open its own file type as a canvas.",
|
|
1924
|
+
when: PO_HELP_WHEN,
|
|
1925
|
+
kind: "skill",
|
|
1926
|
+
path: packageResourcePath("bundle:///po-author/src/extensions/workspaces/sessions/(backend)/resource/help-how-to-author.server.ts", skillFile),
|
|
1927
|
+
read: () => readPackageResource("bundle:///po-author/src/extensions/workspaces/sessions/(backend)/resource/help-how-to-author.server.ts", skillFile)
|
|
1928
|
+
});
|
|
1929
|
+
//#endregion
|
|
1930
|
+
//#region ../../foundations/po-author/src/extensions/workspaces/sessions/(backend)/tool/describe-author-tools.server.ts
|
|
1931
|
+
var describe_author_tools_server_default = defineTool((context) => createAuthorTools(context.root.catalog, context.root.assertAlive)[1]);
|
|
1932
|
+
//#endregion
|
|
1933
|
+
//#region ../../foundations/po-author/src/extensions/workspaces/sessions/(backend)/tool/open-authoring-file.server.ts
|
|
1934
|
+
var open_authoring_file_server_default = defineTool((context) => createAuthorTools(context.root.catalog, context.root.assertAlive)[0]);
|
|
1935
|
+
//#endregion
|
|
1936
|
+
//#region ../../foundations/po-author/src/extensions/workspaces/sessions/(backend)/tool/use-author-tools.server.ts
|
|
1937
|
+
var use_author_tools_server_default = defineTool((context) => createAuthorTools(context.root.catalog, context.root.assertAlive)[2]);
|
|
1938
|
+
//#endregion
|
|
1939
|
+
//#region ../../foundations/po-author/generated/server.ts
|
|
1940
|
+
const at = (value, context) => typeof value === "function" ? value(context) : value;
|
|
1941
|
+
/* v8 ignore next -- generated normalization branch */
|
|
1942
|
+
const defined = (values) => values.filter((value) => value !== void 0);
|
|
1943
|
+
const via = (identity, value) => value === void 0 ? void 0 : {
|
|
1944
|
+
...identity,
|
|
1945
|
+
...value
|
|
1946
|
+
};
|
|
1947
|
+
const serverPlugin = defineServerPlugin({
|
|
1948
|
+
name: "@agimon-ai/po-author",
|
|
1949
|
+
providerOverrides: composeServerProviderOverrides(root_server_default),
|
|
1950
|
+
provides: { session: [author_server_default$1] },
|
|
1951
|
+
injects: composeRootInjects({ session: [root_server_default] }),
|
|
1952
|
+
host: (context) => ({
|
|
1953
|
+
get channels() {
|
|
1954
|
+
return [() => via({ frameType: "author_webmcp" }, at(author_webmcp_server_default, context))];
|
|
1955
|
+
},
|
|
1956
|
+
get methods() {
|
|
1957
|
+
return [at(bridge_server_default, context)];
|
|
1958
|
+
}
|
|
1959
|
+
}),
|
|
1960
|
+
workspace: (context) => ({
|
|
1961
|
+
get channels() {
|
|
1962
|
+
return defined([context.hosted("host") ? void 0 : () => via({ frameType: "author_webmcp" }, at(author_webmcp_server_default, context))]);
|
|
1963
|
+
},
|
|
1964
|
+
get methods() {
|
|
1965
|
+
return [at(bridge_server_default, context)];
|
|
1966
|
+
}
|
|
1967
|
+
}),
|
|
1968
|
+
session: async (context) => {
|
|
1969
|
+
const scopeSession = await context.scopeRoot("session", root_server_default, context);
|
|
1970
|
+
const contextSession = {
|
|
1971
|
+
...context,
|
|
1972
|
+
root: scopeSession.value
|
|
1973
|
+
};
|
|
1974
|
+
return {
|
|
1975
|
+
...composeRootHooks(scopeSession),
|
|
1976
|
+
get api() {
|
|
1977
|
+
return [at(route_server_default, contextSession)];
|
|
1978
|
+
},
|
|
1979
|
+
get channels() {
|
|
1980
|
+
return defined([context.hosted("host") ? void 0 : () => via({ frameType: "author_webmcp" }, at(author_webmcp_server_default, context))]);
|
|
1981
|
+
},
|
|
1982
|
+
get commands() {
|
|
1983
|
+
return [via({ name: "author" }, at(author_server_default, contextSession))];
|
|
1984
|
+
},
|
|
1985
|
+
get methods() {
|
|
1986
|
+
return [at(bridge_server_default, context)];
|
|
1987
|
+
},
|
|
1988
|
+
get resources() {
|
|
1989
|
+
return [at(help_how_to_author_server_default, contextSession)];
|
|
1990
|
+
},
|
|
1991
|
+
get tools() {
|
|
1992
|
+
return [
|
|
1993
|
+
via({ name: "describe_author_tools" }, at(describe_author_tools_server_default, contextSession)),
|
|
1994
|
+
via({ name: "open_authoring_file" }, at(open_authoring_file_server_default, contextSession)),
|
|
1995
|
+
via({ name: "use_author_tools" }, at(use_author_tools_server_default, contextSession))
|
|
1996
|
+
];
|
|
1997
|
+
},
|
|
1998
|
+
services: [...scopeSession.services ?? []],
|
|
1999
|
+
get activities() {
|
|
2000
|
+
return [...scopeSession.activities ?? []];
|
|
2001
|
+
}
|
|
2002
|
+
};
|
|
2003
|
+
}
|
|
2004
|
+
});
|
|
2005
|
+
//#endregion
|
|
2006
|
+
export { serverPlugin as default, serverPlugin };
|