@agimon-ai/po-cloudflare 0.0.2-alpha.20 → 0.0.2-alpha.21
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/{agent-DTjnYFAN.js → agent-DZ-OKOHn.js} +1 -1
- package/dist/{apiContracts-DepyzMNr.js → apiContracts-b33nSAAI.js} +4 -80
- package/dist/{approval-Biq3NCWj.js → approval-r3NnI1VC.js} +2 -2
- package/dist/{approvalPrompt-DoHlIPkU.js → approvalPrompt-DWoXxu3S.js} +2 -2
- package/dist/artifactFiles-DLCReI0-.js +1 -0
- package/dist/assets/assets/{CodeEditorView-BU8DeV_G.js → CodeEditorView-XeNS0L9M.js} +2 -2
- package/dist/assets/assets/{abnfDiagram-WEYOIA3C-BkzARjqu.js → abnfDiagram-WEYOIA3C-B6ZW0nkR.js} +2 -2
- package/dist/assets/assets/{architecture-WOLXFQ4H-B_dgnlXa.js → architecture-WOLXFQ4H-bVR64sHO.js} +1 -1
- package/dist/assets/assets/{architectureDiagram-ZHVYKT53-DMGAifk0.js → architectureDiagram-ZHVYKT53-D7tZz3io.js} +2 -2
- package/dist/assets/assets/{blockDiagram-RJAE7QA3-DwTSK4lj.js → blockDiagram-RJAE7QA3-DdwScfiX.js} +2 -2
- package/dist/assets/assets/{c4Diagram-XDPPPE54-IRaOcC_u.js → c4Diagram-XDPPPE54-DgSxZJCV.js} +2 -2
- package/dist/assets/assets/channel-TPcVvp_3.js +2 -0
- package/dist/assets/assets/{chunk-2E7WHVMD-BvS46crW.js → chunk-2E7WHVMD-D5TXC2SM.js} +2 -2
- package/dist/assets/assets/{chunk-4EMNKR2T--n96Xbj0.js → chunk-4EMNKR2T-BWhOSvo1.js} +2 -2
- package/dist/assets/assets/{chunk-55XCU76K-D3h_hFRi.js → chunk-55XCU76K-HkkBzLtZ.js} +2 -2
- package/dist/assets/assets/{chunk-7S6XSTFO-Cj18feJl.js → chunk-7S6XSTFO-CBnjycLU.js} +2 -2
- package/dist/assets/assets/{chunk-AQDTSKZB-DXsT43bg.js → chunk-AQDTSKZB-75lIIq8T.js} +2 -2
- package/dist/assets/assets/{chunk-DSNLSHJZ-Br7dX7yf.js → chunk-DSNLSHJZ-D8PpnXMk.js} +2 -2
- package/dist/assets/assets/{chunk-HAGFOTED-BcozAtPo.js → chunk-HAGFOTED-CXRS2NIN.js} +2 -2
- package/dist/assets/assets/{chunk-HNE4Q36P-B8kgXgRq.js → chunk-HNE4Q36P-BocUqS94.js} +2 -2
- package/dist/assets/assets/{chunk-NQOKRVIF-Dn7UnsqE.js → chunk-NQOKRVIF-CHf_ogYT.js} +2 -2
- package/dist/assets/assets/{chunk-UHW7PFBP-BSJot0vi.js → chunk-UHW7PFBP-DrW1PaIv.js} +2 -2
- package/dist/assets/assets/{chunk-VQ5W62QI-Cpf1EfZK.js → chunk-VQ5W62QI-CLoA7bFm.js} +2 -2
- package/dist/assets/assets/{chunk-WQQL4CDK-Dnc36uZR.js → chunk-WQQL4CDK-BmBsrj9I.js} +2 -2
- package/dist/assets/assets/chunk-XXDRQBXY-iFE4Tl8c.js +2 -0
- package/dist/assets/assets/{chunk-YZO67HFG-BV8_A7x3.js → chunk-YZO67HFG-DShE_cgv.js} +2 -2
- package/dist/assets/assets/{chunk-ZAUX2LTX-C4Ne_31B.js → chunk-ZAUX2LTX-B3oLvSXy.js} +2 -2
- package/dist/assets/assets/{chunk-ZCHMQSOR-Dq9ModsA.js → chunk-ZCHMQSOR-B14vKK7C.js} +2 -2
- package/dist/assets/assets/{classDiagram-v2-4MYWR3UA-1BWEjXP9.js → classDiagram-v2-4MYWR3UA-Da8elIW2.js} +2 -2
- package/dist/assets/assets/{cose-bilkent-JH36ORCC-DREkvC_x.js → cose-bilkent-JH36ORCC-Du4tGtiJ.js} +2 -2
- package/dist/assets/assets/{cynefin-EF2NZ3EQ-CWziP8nx.js → cynefin-EF2NZ3EQ-Cyj6i_WI.js} +1 -1
- package/dist/assets/assets/{cynefinDiagram-WF24UDRP-DOoYmcvz.js → cynefinDiagram-WF24UDRP-DFWXwO7A.js} +2 -2
- package/dist/assets/assets/{dagre-NK4GIZVX-OoAtEico.js → dagre-NK4GIZVX-C1wB_cf-.js} +2 -2
- package/dist/assets/assets/{diagram-CBK3MWTC-B-pl2-iR.js → diagram-CBK3MWTC-MYCOBYl6.js} +2 -2
- package/dist/assets/assets/{diagram-I5XIIV2D-uKzNJSZ2.js → diagram-I5XIIV2D-BFYbKUFf.js} +2 -2
- package/dist/assets/assets/{diagram-ODIL2UCW-CEXY_Tzu.js → diagram-ODIL2UCW-6siqTpv_.js} +2 -2
- package/dist/assets/assets/{diagram-PFBEJUXE-MKlRQo-g.js → diagram-PFBEJUXE-CaBr9CoB.js} +2 -2
- package/dist/assets/assets/{diagram-RJA3I4VV-c2qlCEVs.js → diagram-RJA3I4VV-DAvmuDpc.js} +2 -2
- package/dist/assets/assets/{diagram-TYUNFSNR-DTdqLA6J.js → diagram-TYUNFSNR-CJnhgCpo.js} +2 -2
- package/dist/assets/assets/{dist-qZHwVT1x.js → dist-BQ4W1R18.js} +2 -2
- package/dist/assets/assets/{dist-DvZCwSZ8.js → dist-BnzFckPF.js} +2 -2
- package/dist/assets/assets/{dist-DCKskbBE.js → dist-CFtBpcYL.js} +2 -2
- package/dist/assets/assets/{dist-mQUN8X3n.js → dist-CIQX1z4W.js} +2 -2
- package/dist/assets/assets/{dist-D9lacOpq.js → dist-ChHYoe9_.js} +2 -2
- package/dist/assets/assets/{dist-BzTxJnSR.js → dist-DKxZO8d9.js} +2 -2
- package/dist/assets/assets/{dist-DCc8tQ7G.js → dist-DL6z28wl.js} +2 -2
- package/dist/assets/assets/{dist-4TUOlkyl.js → dist-DNyn1p9Z.js} +2 -2
- package/dist/assets/assets/{dist-DXlts_H5.js → dist-qYlLXIa8.js} +2 -2
- package/dist/assets/assets/{ebnfDiagram-V4P3TTPT-C89wxfCd.js → ebnfDiagram-V4P3TTPT-AUcqDTM3.js} +2 -2
- package/dist/assets/assets/{elk-QONTBCTQ-BMBgLOae.js → elk-QONTBCTQ-aA10PEHJ.js} +2 -2
- package/dist/assets/assets/{erDiagram-KYQIGQAA-Bb04CRa4.js → erDiagram-KYQIGQAA-hhYiqA-x.js} +2 -2
- package/dist/assets/assets/{eventmodeling-K75KTNOO-DSyNf2MV.js → eventmodeling-K75KTNOO-BQZqbRo5.js} +1 -1
- package/dist/assets/assets/flowDiagram-IUGLLWBU-BuyysPYC.js +1 -0
- package/dist/assets/assets/{ganttDiagram-R7GPNTJY-sB7-pF_t.js → ganttDiagram-R7GPNTJY-CLON1GpW.js} +2 -2
- package/dist/assets/assets/{gitGraph-VSP46ZUC-pWPBCmdT.js → gitGraph-VSP46ZUC-DbmvNwR2.js} +1 -1
- package/dist/assets/assets/{gitGraphDiagram-PDYL7XHY-DronDRed.js → gitGraphDiagram-PDYL7XHY-DJVO0WlL.js} +2 -2
- package/dist/assets/assets/index-BiTVAj5E.js +155 -0
- package/dist/assets/assets/{info-OHQRW6UA-B375mT1i.js → info-OHQRW6UA-CAt3Nt3g.js} +1 -1
- package/dist/assets/assets/{infoDiagram-MVDRKAX5-9Hw3wWP7.js → infoDiagram-MVDRKAX5-DTuqH-Zb.js} +2 -2
- package/dist/assets/assets/{ishikawaDiagram-HPEHV2GE-CdPAuupk.js → ishikawaDiagram-HPEHV2GE-BnWvdonT.js} +2 -2
- package/dist/assets/assets/{journeyDiagram-BOSHW7O7-hqmaHM9u.js → journeyDiagram-BOSHW7O7-Btxtcgvl.js} +2 -2
- package/dist/assets/assets/{kanban-definition-FNSA4HC5-BdOHplX4.js → kanban-definition-FNSA4HC5-q7ek9o_H.js} +2 -2
- package/dist/assets/assets/{line-BCSC3Bu2.js → line-B7yLilmC.js} +2 -2
- package/dist/assets/assets/{linear-D5ddQU3r.js → linear-y8aSKEli.js} +2 -2
- package/dist/assets/assets/{mermaid-parser.core-BaSUi_Ph.js → mermaid-parser.core-B4rH50nD.js} +4 -4
- package/dist/assets/assets/{mermaid.core-CUUsU9Ou.js → mermaid.core-DnRVHTjE.js} +5 -5
- package/dist/assets/assets/{mindmap-definition-6OY57UG3-BtVkhvIZ.js → mindmap-definition-6OY57UG3-DT9Afs2v.js} +2 -2
- package/dist/assets/assets/{packet-JDAUHWVQ-CQ3OUDwI.js → packet-JDAUHWVQ-CnqNbu4p.js} +1 -1
- package/dist/assets/assets/{pegDiagram-ECIUJNBX-DDnq-Kn3.js → pegDiagram-ECIUJNBX-cvxdBBFq.js} +2 -2
- package/dist/assets/assets/{pie-XZMESJXO-BvOFTkQB.js → pie-XZMESJXO-etXMNsaL.js} +1 -1
- package/dist/assets/assets/{pieDiagram-GNMPY74T-Bdwhl9jD.js → pieDiagram-GNMPY74T-CBN-R3_j.js} +2 -2
- package/dist/assets/assets/{quadrantDiagram-D57K4MC3-GHKoDEeT.js → quadrantDiagram-D57K4MC3-C5jjVPIH.js} +2 -2
- package/dist/assets/assets/{radar-ABXABTNO-Yk9rKkKW.js → radar-ABXABTNO-CAMd_mrV.js} +1 -1
- package/dist/assets/assets/{railroad-I3PHUGI6-Crr2QEwm.js → railroad-I3PHUGI6-DIs3auoe.js} +1 -1
- package/dist/assets/assets/{railroad-abnf-LNEFI6M7-CLrgwBog.js → railroad-abnf-LNEFI6M7-CJXr1qWy.js} +1 -1
- package/dist/assets/assets/{railroad-ebnf-DWYD2UWJ-zWReI6MC.js → railroad-ebnf-DWYD2UWJ-DfwtykqI.js} +1 -1
- package/dist/assets/assets/{railroad-peg-JR7BVNR7-CnVnlaHi.js → railroad-peg-JR7BVNR7-B8beAhTs.js} +1 -1
- package/dist/assets/assets/{railroadDiagram-Y72NRBL7-MJ68mMla.js → railroadDiagram-Y72NRBL7-BDcQE-EL.js} +2 -2
- package/dist/assets/assets/{requirementDiagram-EQYSW5RA-BYb-mTCH.js → requirementDiagram-EQYSW5RA-KJ4-QjZM.js} +2 -2
- package/dist/assets/assets/{sankeyDiagram-SY24JHO5-DzONJsqQ.js → sankeyDiagram-SY24JHO5-VjIB-Ybr.js} +2 -2
- package/dist/assets/assets/{sequenceDiagram-BLEHNHQU-0vav9YWV.js → sequenceDiagram-BLEHNHQU-MfMuWq1M.js} +2 -2
- package/dist/assets/assets/{src-DZJUnjaM.js → src-BAxIj8GJ.js} +2 -2
- package/dist/assets/assets/{stateDiagram-v2-A6IESKWZ-B0M8THPh.js → stateDiagram-v2-A6IESKWZ-mHwLRRCY.js} +2 -2
- package/dist/assets/assets/{swimlanes-B3ENRKFQ-5YJZCHIB.js → swimlanes-B3ENRKFQ-PArlYoqV.js} +2 -2
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-The09-5S.js +9 -0
- package/dist/assets/assets/{timeline-definition-JXYKGLGB-us1LwUHo.js → timeline-definition-JXYKGLGB-B2nKiNFU.js} +2 -2
- package/dist/assets/assets/{treeView-D4JQ5SDB-BSLlcDre.js → treeView-D4JQ5SDB-gU23_RuI.js} +1 -1
- package/dist/assets/assets/{treemap-SAJKECNS-DZ2SwLmk.js → treemap-SAJKECNS-CiqoMvZa.js} +1 -1
- package/dist/assets/assets/{usecaseDiagram-WPOLBNNX-BrmvO_6k.js → usecaseDiagram-WPOLBNNX-DpeoWpMK.js} +2 -2
- package/dist/assets/assets/{vennDiagram-Q3Y3IDCW-FKXSeKp5.js → vennDiagram-Q3Y3IDCW-C31iGKvM.js} +2 -2
- package/dist/assets/assets/{wardley-7MLQ67FV-DZ_vIMp2.js → wardley-7MLQ67FV-CIzHhzNw.js} +1 -1
- package/dist/assets/assets/{wardleyDiagram-IVAIDKWA-CfLYNckm.js → wardleyDiagram-IVAIDKWA-DIIkoezc.js} +2 -2
- package/dist/assets/assets/{webpack-CiS_BB3R.js → webpack-RFseiMZW.js} +2 -2
- package/dist/assets/assets/{xychartDiagram-4URNHDU4-DBucwhQh.js → xychartDiagram-4URNHDU4-QiHL91kC.js} +2 -2
- package/dist/assets/bundle-asset-policy.json +1 -1
- package/dist/assets/index.html +1 -1
- package/dist/assets/plugins/assets/base-CKKRZ7-h.css +2 -0
- package/dist/assets/plugins/assets/browserCaptureWorklet-Droj0fW0-Droj0fW0.js +13 -0
- package/dist/assets/plugins/assets/sileroVadWorker-D894njUe-DjN_BMWf.mjs +110 -0
- package/dist/assets/plugins/assets/silero_vad_v6.2.1-SjbCxFXk-SjbCxFXk.onnx +0 -0
- package/dist/assets/plugins/chunks/po-web-runtime-BJDT6Lbw.js +1 -0
- package/dist/assets/plugins/compositions.json +1 -1
- package/dist/assets/plugins/slots/approval.293d9a00-BXIhaPlQ.js +2 -0
- package/dist/assets/plugins/slots/artifacts.24567664-ZzR0gbvy.js +1 -0
- package/dist/assets/plugins/slots/author.0998a880-DAbA-7rb.js +93 -0
- package/dist/assets/plugins/slots/{autocompact.ec8f713f-B3KTYwW1.js → autocompact.dd97d013-IVq4Z6qm.js} +1 -1
- package/dist/assets/plugins/slots/builtin-tools.36d7400b-CpCLjRRN.js +7 -0
- package/dist/assets/plugins/slots/codemode.8eaee717-VWt9PqsU.js +10 -0
- package/dist/assets/plugins/slots/domain.5e95fc37-5PIUBqDe.js +1 -0
- package/dist/assets/plugins/slots/edit.385c9aa9-DNAjPNG5.js +7 -0
- package/dist/assets/plugins/slots/files.daf34ed8-CQaTz0i1.js +2 -0
- package/dist/assets/plugins/slots/goal.77ec9930-B8EkarBq.js +1 -0
- package/dist/assets/plugins/slots/grep.02052cdc-CIRhO2gY.js +1 -0
- package/dist/assets/plugins/slots/help.ecd4c0f9-naMF9NN1.js +3 -0
- package/dist/assets/plugins/slots/log.a86eb6d0-D5__rAZJ.js +4 -0
- package/dist/assets/plugins/slots/{mcp.ea8b6aa2-D0CkHnIw.js → mcp.974af249-DPNHn9XH.js} +10 -10
- package/dist/assets/plugins/slots/plan.bafb8f68-C5GEpybF.js +3 -0
- package/dist/assets/plugins/slots/{profile.63bc3ae6-BSY3iYfJ.js → profile.48851a1d-yX6tzV3x.js} +1 -1
- package/dist/assets/plugins/slots/prompts.723d7748-B7zpPeoF.js +3 -0
- package/dist/assets/plugins/slots/read.46bf6536-Cw5Z5z5T.js +1 -0
- package/dist/assets/plugins/slots/runner.53e9bd76-CiQR_FPX.js +8 -0
- package/dist/assets/plugins/slots/skill.086701a4-CL6h_F-x.js +4 -0
- package/dist/assets/plugins/slots/vault.ac9935c8-DKERQYg4.js +1 -0
- package/dist/assets/plugins/slots/voice.e85ca7f9-DEgb-U9m.js +1 -0
- package/dist/{atomicJson-DCIsEywH.js → atomicJson-C_7F2zD1.js} +2 -3
- package/dist/{backgroundWork-Bswjs1av.js → backgroundWork-B1mPDYlf.js} +1 -1
- package/dist/{codemode-CgVosRtU.js → codemode-DQFmrosw.js} +1 -1
- package/dist/{contracts-CylyLZC8.js → contracts-DD3f1Lpn.js} +1 -1
- package/dist/exports-B0WMEXCP.js +34 -0
- package/dist/{exports-DERO0cQf.js → exports-D09VsUk-.js} +6 -7
- package/dist/{exports-C_dclnKs.js → exports-nV43ShA7.js} +10 -9
- package/dist/{extensionFile-Ds7RCpnb.js → extensionFile-DNM4xsje.js} +16 -2
- package/dist/{domains-BqChtBLN.js → harnessState-Dwrk3lfv.js} +90 -5
- package/dist/{harnessStore-BectazJQ.js → harnessStore-Z7yDLO45.js} +4 -5
- package/dist/{help-Dpm82qDr.js → help-w6vVEZGL.js} +15 -5
- package/dist/hubChannel-Cm-sxOvU.js +21 -0
- package/dist/{index.edge-b0z7PQ6b.js → index.edge-DyYmurS7.js} +14 -2
- package/dist/{index.edge-B0D_Lgbx.js → index.edge-K0w5auwG.js} +2 -2
- package/dist/{index.edge-BLmsRNW8.js → index.edge-Xa5LLtxz.js} +13 -3
- package/dist/{layeredConfig-pQGjhAks.js → layeredConfig-CUkYUs1f.js} +74 -5
- package/dist/{majorModes-BrL4EtzH.js → majorModes-BB0PXgFn.js} +3 -4
- package/dist/majorModes-C7vtBs4D.js +1 -0
- package/dist/{mcpProjection-pbPBBuvs.js → mcpProjection-BtKzB6oK.js} +2 -2
- package/dist/modeDefinition-C3Zbrw48.js +44 -0
- package/dist/narration-CpRurWLO.js +127 -0
- package/dist/{notification-CINsJWDL.js → notification-kckG3leF.js} +2 -2
- package/dist/{hubChannel-COvmdWGO.js → packageApi-t1oCjNDU.js} +2 -22
- package/dist/{piConfig-BDUpA6w0.js → piConfig-DQzlbPY4.js} +4 -5
- package/dist/piSettings-Cf1QofNe.js +1 -0
- package/dist/platform-BIEiM4TG.js +113 -0
- package/dist/pluginProtocol-BqXXyI4z.js +80 -0
- package/dist/{protocol-B6LbEIe6.js → protocol-DDL8geoS.js} +2 -2
- package/dist/{server-DRcCuj6P.js → server-AbXyhXlY.js} +4 -4
- package/dist/{server-Re1VNk9s.js → server-B6dqQoh2.js} +7 -6
- package/dist/{server-cStfn1Yv.js → server-BIHo9TFu.js} +4 -4
- package/dist/{server-1O3JEYO0.js → server-BJ7DNzCp.js} +7 -7
- package/dist/server-BO-j_GbD.js +15106 -0
- package/dist/{server-Cgym-G0a.js → server-BQzAiMns.js} +11 -11
- package/dist/server-BR7SZtj7.js +3125 -0
- package/dist/{server-DL6UyXfJ.js → server-BT2ORK83.js} +9 -8
- package/dist/{server-CzJjYgVk.js → server-BbSHYRnY.js} +3 -3
- package/dist/{server-DFCXmDed.js → server-BqoKlEGk.js} +8 -8
- package/dist/{server-BXFDsLgm.js → server-Busl0pQI.js} +8 -9
- package/dist/server-CIHM4jqu.js +1116 -0
- package/dist/{server-DhkR6ugd.js → server-CgWSSdvd.js} +6 -7
- package/dist/{server-B8P-UkxF.js → server-Co_UWKrR.js} +5 -5
- package/dist/{server-Bt6Zsqo8.js → server-CuEPb7u-.js} +2 -2
- package/dist/{server-V8W5mcGu.js → server-D40q2Jpx.js} +47 -27
- package/dist/{server-OerXqXJT.js → server-DCyf2Asb.js} +3 -4
- package/dist/{server-CCwwnpH0.js → server-DH7PfLln.js} +5 -5
- package/dist/{server-_0288DYR.js → server-DJ8bc89M.js} +3 -4
- package/dist/{server-GIQIpf33.js → server-DYdp0W9v.js} +7 -7
- package/dist/{server-B2G-c0hg.js → server-DsdPEYGu.js} +5 -5
- package/dist/{server-Dgn4el5K.js → server-DymH4Ucq.js} +4 -5
- package/dist/{server-pY027myK.js → server-IqECnUrb.js} +13 -236
- package/dist/{server-Ci_BGVwd.js → server-KBgW77zh.js} +3 -3
- package/dist/server-RW_9R3R3.js +1522 -0
- package/dist/server-aUit8j6r.js +1028 -0
- package/dist/{server-Ci3ls6LL.js → server-gifRriZK.js} +10 -11
- package/dist/{server-BR9yl54i.js → server-nkUlqnAL.js} +10 -10
- package/dist/server-oxyEbv1a.js +1256 -0
- package/dist/{server-DPTp6GXS.js → server-ub3s16Mc.js} +4 -4
- package/dist/{serverPlugin-OOfjB8tm.js → serverPlugin-CELT6P0Q.js} +12 -3
- package/dist/{sessionConfig-DfwcUKO2.js → sessionConfig-RQGvfm6E.js} +9 -10
- package/dist/{server-CyYesT-G.js → type-ASYnCGVW.js} +9 -1031
- package/dist/{validation-DuOGOKEi.js → validation-BJxVSAwx.js} +8 -3
- package/dist/{value-DyVsxCwZ.js → value-_W31So3B.js} +1 -1
- package/dist/{vaultSettings-BFCRCBM3.js → vaultSettings-Di3n5YIg.js} +1 -1
- package/dist/voiceTools-RMn4HvWo.js +246 -0
- package/dist/web-DCP7ELJj.js +3 -0
- package/dist/worker.js +345 -244
- package/dist/{workflow-BgwWq0nq.js → workflow-B7qx0Vv9.js} +1 -1
- package/package.json +37 -32
- package/wrangler.jsonc +2 -0
- package/dist/assets/assets/channel-BXwM62E-.js +0 -2
- package/dist/assets/assets/chunk-XXDRQBXY-C9Ka5KSI.js +0 -2
- package/dist/assets/assets/flowDiagram-IUGLLWBU-DXuTqLUd.js +0 -1
- package/dist/assets/assets/index-DdAdCxGc.js +0 -155
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-aJTRXiIU.js +0 -9
- package/dist/assets/plugins/assets/base-C3j1WCCq.css +0 -2
- package/dist/assets/plugins/chunks/po-web-runtime-Czm_C4SJ.js +0 -1
- package/dist/assets/plugins/slots/approval.3e4ea6e4-CqQk6XG_.js +0 -2
- package/dist/assets/plugins/slots/artifacts.84980c32-DQlO5IFk.js +0 -1
- package/dist/assets/plugins/slots/builtin-tools.16ef5e25-CZRYQVIP.js +0 -7
- package/dist/assets/plugins/slots/codemode.5f359b9c-Bzl_K_vt.js +0 -10
- package/dist/assets/plugins/slots/domain.832848c8-CvnpuKCY.js +0 -1
- package/dist/assets/plugins/slots/edit.7c802139-kaxIknZ-.js +0 -7
- package/dist/assets/plugins/slots/files.364f16c9-wuB8gcQA.js +0 -2
- package/dist/assets/plugins/slots/grep.d8bf9f57-3FnU8p-d.js +0 -1
- package/dist/assets/plugins/slots/log.07fd59a4-C0PXQ0O1.js +0 -4
- package/dist/assets/plugins/slots/prompts.9d9b47cc-xdCkNkoA.js +0 -3
- package/dist/assets/plugins/slots/read.926c024f-qqaxVlEX.js +0 -1
- package/dist/assets/plugins/slots/runner.5393fa6c-DfO2Z9HG.js +0 -8
- package/dist/assets/plugins/slots/skill.56c1cc07-CL_n-l4h.js +0 -4
- package/dist/assets/plugins/slots/vault.587549ba-DbG3F_on.js +0 -1
- package/dist/harnessState-gmzJcPGt.js +0 -88
- package/dist/harnessStore-C0Zwvny8.js +0 -1
- package/dist/majorModes-WXt22_km.js +0 -1
- package/dist/piSettings-tdui0CZI.js +0 -1
- package/dist/platform-yhQXrrM_.js +0 -16
- package/dist/platformFiles-DB3Cw1l_.js +0 -64
- package/dist/web-cN41ySs9.js +0 -3
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{C as e,D as t,N as n,T as r,_r as i,a,br as o,c as s,cn as c,cr as l,g as u,gr as d,h as f,ir as p,nr as m,o as h,p as g,pr as _,s as v,sr as y,tt as ee,w as b,x,xr as S,xt as C,yr as w,zt as T}from"../chunks/po-web-runtime-BJDT6Lbw.js";var te=`approval_activity`,E=`approval`,D=600,O=200;function ne(e,t){let n=t(e);if(n===void 0)return null;let{revision:r,state:i,reason:a,sessionGone:o,sessionName:s,workspaceName:c}=e;return typeof r!=`number`||!Number.isSafeInteger(r)||r<1||i!==`pending`&&i!==`approved`&&i!==`running`&&i!==`interrupted`?null:{...n,revision:r,state:i,...(i===`pending`||i===`approved`)&&o===!0?{sessionGone:!0}:{},...typeof a==`string`?{reason:a.slice(0,D)}:{},...typeof s==`string`&&s!==``?{sessionName:s.slice(0,O)}:{},...typeof c==`string`&&c!==``?{workspaceName:c.slice(0,O)}:{}}}function k(e,t){let n=e?.approvals;return Array.isArray(n)?{approvals:n.map(e=>ne(e,t)).filter(e=>e!==null)}:null}function A(e){let t=e;if(t?.ok!==!0)return typeof t?.message==`string`&&t.message!==``?t.message:`Po could not record that answer. The card shows where things stand now.`}function j(e){return{pending:`Your approval`,approved:`Approved`,running:`Running…`,interrupted:`Outcome uncertain`}[e]}function M(e){let t=e.filter(e=>e.sessionGone!==!0),n=t.filter(e=>e.state===`pending`).length;return e.length>0&&t.length===0?`This session is gone. Nothing will run.`:n===0&&t.some(e=>e.state===`interrupted`)?`Outcome uncertain. Check before retrying.`:n===0&&t.some(e=>e.state===`running`)?`Po is running an approved call.`:n===0?t.length===1?`Approved. It runs when the session can.`:`Approved. They run when the session can.`:n===1?`One thing would like your eye, whenever you are ready.`:`${n} things would like your eye, whenever you are ready.`}function N(e){return[e.sessionName??`A session`,e.workspaceName].filter(Boolean).join(` · `)}function P(e,t){return t===void 0||Object.keys(t).length===0?e:e.flatMap(e=>{let n=t[e.id];return n===void 0?[e]:n===`approve`?[e.state===`pending`?{...e,state:`approved`}:e]:[]})}function F(e,t){let n=new Map(e.map(e=>[e.id,e]));return Object.fromEntries(Object.entries(t).filter(([e,t])=>{let r=n.get(e);return r!==void 0&&(t===`dismiss`||r.state===`pending`)}))}function I(e,t){let n=e=>t(e).state===`pending`&&t(e).sessionGone!==!0;return[...e.filter(n),...e.filter(e=>!n(e))]}function re(e){return Object.entries(e).flatMap(([e,t])=>t===void 0?[]:P(t.approvals,t.answers).map(n=>({sessionId:e,card:n,...t.error===void 0?{}:{error:t.error}})))}var L=_({approvals:[],answers:{}});function R(e){let t=s(e=>{let t=L.store.subscribe(e);return()=>t.unsubscribe()},[]),n=()=>L.select(L.store.state,e);return u(t,n,n)}var z={subscribe(e){let t=L.store.subscribe(e);return()=>t.unsubscribe()},isActive(e){let t=L.select(L.store.state,e);return P(t.approvals,t.answers).length>0}};function B(){let e=()=>L.store.state,t=u(z.subscribe,e,e);return g(()=>re(t),[t])}var V=L.channel({channel:te,parse:e=>k(e,S),reduce:(e,{approvals:t})=>({...e,approvals:t,answers:F(t,e.answers)})}),H=l(void 0),U=l(void 0),W=5e3;function G(e){let t=t=>e.invokeServerMethod(t),n=!1,r,i=!1,a=()=>(i=!0,r===void 0&&(r=(async()=>{for(;i&&!n;){i=!1;try{let e=new Map,r=0;for(;r!==null&&!n;){let n=await t({mount:{scope:`global`},service:E,method:`snapshot`,input:{offset:r}});if(!Array.isArray(n.cards)||n.nextOffset!==null&&(!Number.isSafeInteger(n.nextOffset)||n.nextOffset<=r))throw Error(`Invalid approval snapshot.`);for(let t of n.cards){if(typeof t.sessionId!=`string`)continue;let n=k({approvals:[t]},S)?.approvals[0];if(n===void 0)continue;let r=e.get(t.sessionId)??[];r.push(n),e.set(t.sessionId,r)}r=n.nextOffset}if(n)return;for(let t of new Set([...Object.keys(L.store.state),...e.keys()])){let n=e.get(t)??[];L.update(t,e=>({...e,approvals:n,answers:F(n,e.answers),snapshotError:void 0}))}}catch(e){if(n)return;for(let t of Object.keys(L.store.state))L.update(t,t=>({...t,snapshotError:e instanceof Error?e.message:String(e)}))}}})().finally(()=>{r=void 0})),r);H.update(()=>t),U.update(()=>a);let o=e.onHubConnected(()=>void a()),s=setInterval(()=>void a(),W);return a(),()=>{n=!0,clearInterval(s),o(),H.update(e=>e===t?void 0:e),U.update(e=>e===a?void 0:e)}}async function K(e,t,n,r){let i=n===`dismiss`?`dismiss`:r.decision===`approve`?`approve`:`deny`;L.update(e,e=>({...e,answers:{...e.answers,[t]:i},error:void 0}));let a;try{let i=H.store.state;if(!i)throw Error(`Approvals are not connected yet.`);a=await i({mount:{scope:`global`},service:E,method:n,input:{...r,sessionId:e,id:t}})}catch(e){a={ok:!1,message:e instanceof Error?e.message:String(e)}}let o=A(a);return o!==void 0&&L.update(e,e=>{let{[t]:n,...r}=e.answers;return{...e,answers:r,error:o}}),await U.store.state?.(),o}var q=m({keys:`g a`,icon:C,activeSource:z,marksBackgroundWork:!1,hideWhenEmpty:!0,order:5});function J(e){let t=e;return typeof t?.subscribe==`function`&&typeof t.isActive==`function`?t:null}var Y={slot:`approval.voice-hint`,description:`Provide a reactive source indicating when spoken approval or denial is available for a session.`,parse:J};function ie({approvals:e,error:n,voiceHint:r,onDecide:i,onDismiss:a}){let[o,s]=f(0);if(e.length===0)return h(`p`,{"data-testid":`activity-summary-approval`,className:`px-1 text-sm text-po-dim`,children:`Nothing is waiting for your approval.`});let c=I(e,e=>e),l=Math.min(o,c.length-1),u=c[l];return v(`div`,{"data-testid":`activity-approvals`,className:`flex flex-col gap-2`,children:[h(`p`,{"data-testid":`activity-summary-approval`,className:`px-1 text-sm text-po-dim`,children:M(e)}),n?h(`p`,{role:`alert`,className:`px-1 text-sm text-po-red`,children:n}):null,c.length>1?v(`div`,{className:`flex items-center justify-between gap-2`,children:[h(T,{size:`icon-md`,variant:`ghost`,"aria-label":`Previous request`,disabled:l===0,onClick:()=>s(l-1),children:h(x,{"aria-hidden":!0,className:`size-4`})}),v(`span`,{"data-testid":`activity-approval-position`,"aria-live":`polite`,className:`text-sm text-po-dim`,children:[l+1,` of `,c.length]}),h(T,{size:`icon-md`,variant:`ghost`,"aria-label":`Next request`,disabled:l===c.length-1,onClick:()=>s(l+1),children:h(t,{"aria-hidden":!0,className:`size-4`})})]}):null,h(X,{card:u,primary:!0,voiceHint:r,onDecide:i,onDismiss:a},u.id)]})}function X({card:e,primary:n,voiceHint:r,origin:i,onOpenSession:o,onDecide:s,onDismiss:c}){let l=e.sessionGone===!0&&(e.state===`pending`||e.state===`approved`),u=e.state===`pending`&&!l,d=l?`Nothing will run. Dismiss this request to clear it.`:u?e.requirement===`human`?`Only you can approve this in the app.`:r??`Po keeps working while it waits.`:e.reason??(e.state===`running`?`Po is running this approved call.`:e.state===`interrupted`?`Check what happened before retrying. This will not run again automatically.`:`It runs when the session can.`);return v(`section`,{"aria-label":e.title,"aria-busy":e.state===`running`||void 0,"data-testid":`activity-approval-${e.id}`,"data-state":e.state,className:`flex flex-col gap-2 rounded-md border border-po-border bg-po-panel p-3`,children:[v(`div`,{className:`flex flex-col gap-0.5`,children:[h(`span`,{className:`text-sm font-medium ${u?`text-po-magenta`:l||e.state===`interrupted`?`text-po-dim`:`text-po-green`}`,children:l?`This session is gone`:j(e.state)}),h(`h3`,{className:`text-base font-semibold break-words text-po-hi`,children:e.title}),e.summary?h(`p`,{className:`text-base break-words text-po-text`,children:e.summary}):null]}),e.details&&e.details.length>0?h(`dl`,{className:`flex flex-col gap-1 text-sm`,children:e.details.map(({label:e,value:t})=>v(`div`,{className:`flex flex-col`,children:[h(`dt`,{className:`text-po-dim`,children:e}),h(`dd`,{className:`break-words text-po-hi`,children:t})]},e))}):null,h(`p`,{className:`text-sm text-po-dim`,children:d}),i?v(`p`,{className:`text-sm break-words text-po-dim`,children:[`From session `,h(`span`,{className:`text-po-text`,children:i})]}):null,v(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u?v(a,{children:[h(T,{size:`sm`,variant:n?`primary`:`outline`,onClick:()=>s(e,`approve`),children:`Approve`}),h(T,{size:`sm`,variant:`ghost`,onClick:()=>s(e,`deny`),children:`Deny`})]}):l?h(T,{size:`sm`,variant:`ghost`,onClick:()=>c(e),children:`Dismiss`}):null,o?v(T,{size:`sm`,variant:`ghost`,className:`ml-auto text-po-green`,onClick:o,children:[`Open session`,h(t,{"aria-hidden":!0,className:`size-4`})]}):null]})]})}var ae=`Or say “approve” or “deny”.`,oe=()=>()=>void 0;function se(e,t){let n=e.length===0?oe:t=>{let n=e.map(e=>e.subscribe(t));return()=>{for(let e of n)e()}},r=()=>e.some(e=>e.isActive(t));return u(n,r,r)}function ce({sessionId:e,slotData:t}){let n=R(e),r=se(t(Y).map(e=>e.data),e);return h(ie,{approvals:P(n.approvals,n.answers),error:n.error??n.snapshotError,...r&&!n.approvals.some(e=>e.sessionGone===!0)?{voiceHint:ae}:{},onDecide:(t,n)=>e&&t.sessionGone!==!0&&void K(e,t.id,`decide`,{id:t.id,revision:t.revision,decision:n}),onDismiss:t=>e&&void K(e,t.id,`dismiss`,{id:t.id,revision:t.revision})})}var le=y({component:ce}),Z=5;function ue({approvals:e,onDecide:r,onDismiss:i,onOpenSession:a}){let[o,s]=f(0);if(e.length===0)return null;let c=e.map(({card:e})=>e),l=I(e,({card:e})=>e),u=Math.ceil(l.length/Z),d=Math.min(o,u-1),p=d*Z,m=l.slice(p,p+Z),g=m.find(({card:e})=>e.state===`pending`&&e.sessionGone!==!0),_=e.find(e=>e.error!==void 0)?.error;return v(n,{"data-testid":`home-approvals`,"aria-label":`Approvals`,className:`flex min-w-0 flex-col gap-3 p-4`,children:[v(`div`,{className:`flex flex-col gap-1`,children:[v(`div`,{className:`flex items-center gap-2`,children:[h(C,{"aria-hidden":!0,className:`size-5 shrink-0 text-po-dim`}),h(`h2`,{className:`text-base font-semibold text-po-hi`,children:`Approvals`}),h(ee,{children:e.length})]}),h(`p`,{className:`text-sm text-po-dim`,children:M(c)})]}),_?h(`p`,{role:`alert`,className:`text-sm text-po-red`,children:_}):null,h(`ul`,{className:`flex flex-col gap-2`,children:m.map(e=>h(`li`,{children:h(X,{card:e.card,primary:e===g,origin:N(e.card),...a&&e.card.sessionGone!==!0?{onOpenSession:()=>a(e.sessionId)}:{},onDecide:(t,n)=>r(e,n),onDismiss:()=>i(e)})},`${e.sessionId}:${e.card.id}`))}),u>1?v(`nav`,{"aria-label":`Approval pages`,className:`flex items-center justify-between gap-2`,children:[v(T,{size:`sm`,variant:`ghost`,disabled:d===0,onClick:()=>s(d-1),children:[h(x,{"aria-hidden":!0,className:`size-4`}),`Previous`]}),v(`span`,{"data-testid":`home-approvals-range`,"aria-live":`polite`,className:`text-sm text-po-dim`,children:[p+1,`–`,p+m.length,` of `,l.length]}),v(T,{size:`sm`,variant:`ghost`,disabled:d===u-1,onClick:()=>s(d+1),children:[`Next`,h(t,{"aria-hidden":!0,className:`size-4`})]})]}):null]})}function de({openSession:e}){return h(ue,{approvals:B(),onDecide:({sessionId:e,card:t},n)=>void K(e,t.id,`decide`,{id:t.id,revision:t.revision,decision:n}),onDismiss:({sessionId:e,card:t})=>void K(e,t.id,`dismiss`,{id:t.id,revision:t.revision}),...e?{onOpenSession:e}:{}})}var fe=y({component:de}),pe=w(G),me=p(V),Q=d(Y);function he(e,t,n){let r=typeof e.id==`string`?e.id:``,i=typeof t?.details==`object`&&t.details!==null?t.details:{};return{approvalId:r,outcome:typeof i.withdrawn==`boolean`?i.withdrawn?`withdrawn`:`not pending`:void 0,message:t===null?n:t.content.flatMap(e=>{let t=typeof e==`object`&&e?e:{};return t.type===`text`&&typeof t.text==`string`?[t.text]:[]}).join(`
|
|
2
|
+
`)}}function ge({args:t,result:n,output:i,running:o,isError:s}){let l=he(t,n,i);return h(e,{tone:c({running:o,isError:s}),expandable:!0,children:({expanded:e})=>v(a,{children:[h(r,{title:`approval_withdraw`,children:v(`span`,{"data-testid":`tool-call-approval_withdraw`,className:`flex min-w-0 flex-1 items-center gap-2`,children:[h(`span`,{className:`shrink-0 font-mono text-po-text`,children:l.approvalId}),l.outcome===void 0?null:v(`span`,{className:`truncate text-po-faint`,children:[`· `,l.outcome]})]})}),e?s?h(b,{"data-testid":`tool-result-approval_withdraw`,className:`flex flex-col`,children:h(`span`,{className:`whitespace-pre-wrap break-words text-po-red`,children:l.message})}):n===null||l.message.length===0?null:h(b,{"data-testid":`tool-result-approval_withdraw`,children:h(`span`,{className:`whitespace-pre-wrap break-words text-po-text`,children:l.message})}):null]})})}var _e=i({message:ge}),$=(e,t)=>t===void 0?void 0:{...e,...t},ve=o({id:`approval`,global:{get activityGroups(){return[$({name:`approval`},q)]},get fills(){return[$({slot:`activity.approval`,id:`approval`},le),$({slot:`home-attention`,id:`approval`},fe)]},get start(){return pe}},session:{get channels(){return[$({channel:`approval_activity`},me)]},get slots(){return[$({slot:`approval.voice-hint`},Q)]},get toolRenderers(){return[$({tools:[`approval_withdraw`]},_e)]}}});export{ve as webPlugin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$t as e,An as t,Bn as n,Cr as r,Ct as i,Fn as a,Ft as o,Gn as s,In as c,K as l,Ln as u,Mn as d,Nn as f,On as ee,Rn as te,S as p,Un as ne,Wn as re,Xn as ie,Yn as ae,a as oe,ar as se,b as m,br as h,c as g,cr as _,en as v,h as y,i as b,ir as x,jn as ce,kn as le,m as S,mn as C,n as w,o as T,or as E,pr as ue,rn as de,s as D,sn as fe,sr as pe,tr as me,tt as O,u as k,un as he,zt as A}from"../chunks/po-web-runtime-BJDT6Lbw.js";var j=`artifacts`,ge=26214400;function _e(e){return e===`tree`||e===`list`||e===`grid`}function ve(e){return/\.(?:md|markdown)$/iu.test(e)?`Markdown`:/\.(?:png|jpe?g|gif|webp|avif|bmp|svg|ico|tiff?)$/iu.test(e)?`Image`:/\.(?:jsonl?|csv|tsv|ya?ml|xml|toml|parquet|sqlite|db)$/iu.test(e)?`Data`:/\.(?:[cm]?[jt]sx?|html?|css|scss|sass|less|py|sh|bash|go|rs|rb|java|c|cpp|cc|h|hpp|sql|swift|kt|kts|php|vue|svelte)$/iu.test(e)?`Code`:/\.(?:pdf|txt|rtf|docx?|xlsx?|pptx?|odt|ods|odp)$/iu.test(e)?`Document`:`Other`}function ye(e,t,n){let r=(t.query??``).trim().toLowerCase(),i=t.modified??`any`,a=new Date(n);a.setHours(0,0,0,0);let o=i===`today`?a.getTime():n-(i===`7days`?7:30)*864e5;return e.filter(e=>e.path.toLowerCase().includes(r)&&(!t.type||t.type===`any`||ve(e.path)===t.type)&&(i===`any`||e.modifiedAt>=o&&e.modifiedAt<=n))}function be(e,t,n){return[...e].sort((e,r)=>(t===`name`?M(e.name.toLowerCase(),r.name.toLowerCase()):t===`size`?e.size-r.size:e.modifiedAt-r.modifiedAt)*(n===`asc`?1:-1)||M(e.path,r.path))}function M(e,t){return e<t?-1:+(e>t)}function xe(e,t){let n={path:``,dirs:new Map,files:[],count:0};for(let t of e){let e=n;e.count++;for(let n of t.path.split(`/`).slice(0,-1)){let t=e.dirs.get(n);t||(t={path:e.path?`${e.path}/${n}`:n,dirs:new Map,files:[],count:0},e.dirs.set(n,t)),e=t,e.count++}e.files.push(t)}let r=[],i=(e,n)=>{for(let[a,o]of[...e.dirs].sort(([e],[t])=>M(e,t))){let e=a,s=o;for(;s.files.length===0&&s.dirs.size===1;){let[[t,n]]=[...s.dirs];e=`${e}/${t}`,s=n}let c=t(s.path);r.push({kind:`dir`,path:s.path,name:e,depth:n,open:c,count:s.count}),c&&i(s,n+1)}for(let t of e.files)r.push({kind:`file`,item:t,depth:n})};return i(n,0),r}function N(e,t){if(t===void 0)return`viewed`;let n=t.seen[e.path];return n===void 0?e.modifiedAt>t.baseline?`new`:`viewed`:e.modifiedAt>n?`edited`:`viewed`}var Se={status:`all`,type:`any`,modified:`any`,location:`artifacts`};function P(e,t){let n=Math.floor(Math.max(0,t-e)/6e4);return n<1?`now`:n<60?`${n}m`:n<1440?`${Math.floor(n/60)}h`:n<10080?`${Math.floor(n/1440)}d`:new Date(e).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}function F(e){return[...e].sort((e,t)=>t.modifiedAt-e.modifiedAt||(e.path<t.path?-1:+(e.path>t.path)))}function I(e,t){return`artifact:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function L(e,t){if(!t||t.startsWith(`/`)||t.includes(`\\`)||/^[a-z][a-z0-9+.-]*:/iu.test(t))throw Error(`Artifact images must use a relative path.`);let n=e.split(`/`).slice(0,-1);for(let e of t.split(`/`))if(e!==``&&e!==`.`){if(e===`..`){if(n.length===0)throw Error(`The image is outside this artifact folder.`);n.pop()}else n.push(e)}if(n.length===0)throw Error(`The image path is empty.`);return n.join(`/`)}function R(e){return/\.(?:png|jpe?g|gif|webp|avif|bmp|svg|ico|mp3|wav|m4a|ogg|m4v|mp4|mov|webm|pdf)$/iu.test(e)?`media`:/\.(?:md|markdown)$/iu.test(e)?`markdown`:/\.html?$/iu.test(e)?`html`:/\.(?:[cm]?[jt]sx?|json|ya?ml|css|scss|py|sh|bash|go|rs|rb|java|c|cpp|h|sql|xml|toml)$/iu.test(e)?`code`:`text`}function z(e){if(typeof e!=`object`||!e||!(`items`in e)||!Array.isArray(e.items)||`error`in e&&e.error!==void 0&&typeof e.error!=`string`)return null;let t=[];for(let n of e.items){if(typeof n!=`object`||!n||typeof n.path!=`string`||!n.path||n.path.startsWith(`/`)||n.path.includes(`\\`)||n.path.split(`/`).some(e=>e===`..`||e===`.`)||typeof n.name!=`string`||!n.name||typeof n.size!=`number`||!Number.isFinite(n.size)||n.size<0||typeof n.modifiedAt!=`number`||!Number.isFinite(n.modifiedAt)||n.modifiedAt<0)return null;t.push({path:n.path,name:n.name,size:n.size,modifiedAt:n.modifiedAt})}return{items:F(t),...`temporaryRoot`in e&&typeof e.temporaryRoot==`string`?{temporaryRoot:e.temporaryRoot}:{},...`error`in e&&typeof e.error==`string`?{error:e.error}:{}}}var B=ue({items:[],loaded:!1}),V=B.channel({channel:j,parse:z,reduce:(e,t)=>({...t,loaded:!0})}),H=`po.artifacts.layout.v1`;function Ce(){try{let e=globalThis.localStorage.getItem(H);return _e(e)?e:`tree`}catch{return`tree`}}var we=_(Ce());function Te(e){we.update(()=>e);try{globalThis.localStorage.setItem(H,e)}catch{}}var U=`po.artifacts.seen.v1`,W=`po.artifacts.browse.v1`,G=200;function K(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ee(e,t){try{let n=JSON.parse(globalThis.localStorage.getItem(e)??`{}`);return K(n)?Object.fromEntries(Object.entries(n).flatMap(([e,n])=>{let r=t(n);return r===void 0?[]:[[e,r]]})):{}}catch{return{}}}function De(e,t,n){return Object.fromEntries([...Object.entries(e).filter(([e])=>e!==t),[t,n]].slice(-50))}function Oe(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}function ke(e){if(!K(e)||typeof e.baseline!=`number`||!K(e.seen))return;let t=Object.fromEntries(Object.entries(e.seen).filter(e=>typeof e[1]==`number`));return{baseline:e.baseline,seen:t}}var q=_(Ee(U,ke));function Ae(e){let t=B.select(B.store.state,e);if(t.loaded&&t.error===void 0)return{baseline:Math.max(0,...t.items.map(e=>e.modifiedAt)),seen:{}}}function je(e,t){let n=q.store.state[e]??Ae(e);if(n===void 0)return;let r=t(n);r!==n&&(q.update(t=>De(t,e,r)),Oe(U,q.store.state))}function Me(e,t){je(e,e=>{if(e.seen[t.path]===t.modifiedAt)return e;let n=[...Object.entries(e.seen).filter(([e])=>e!==t.path),[t.path,t.modifiedAt]].slice(-1e3);return{...e,seen:Object.fromEntries(n)}})}function Ne(e,t){je(e,()=>({baseline:Math.max(0,...t.map(e=>e.modifiedAt)),seen:{}}))}function Pe(e){if(e===null)return 0;let t=q.store.state[e];return B.select(B.store.state,e).items.filter(e=>N(e,t)!==`viewed`).length}function Fe(){for(let e of Object.keys(B.store.state)){if(q.store.state[e]!==void 0)continue;let t=Ae(e);t!==void 0&&je(e,()=>t)}}B.store.subscribe(Fe);var J={filters:Se,sort:`modified`,direction:`desc`,expanded:[],query:``,searchOpen:!1};function Y(e,t,n){return t.includes(e)?e:n}function Ie(e){if(!K(e))return;let t=K(e.filters)?e.filters:{};return{filters:{status:Y(t.status,[`all`,`new`,`edited`,`viewed`],`all`),type:Y(t.type,[`any`,`Markdown`,`Image`,`Code`,`Data`,`Document`,`Other`],`any`),modified:Y(t.modified,[`any`,`today`,`7days`,`30days`],`any`),location:Y(t.location,[`artifacts`,`temporary`],`artifacts`)},sort:Y(e.sort,[`name`,`size`,`modified`],`modified`),direction:Y(e.direction,[`asc`,`desc`],`desc`),expanded:Array.isArray(e.expanded)?e.expanded.filter(e=>typeof e==`string`).slice(0,G):[],...typeof e.openPath==`string`?{openPath:e.openPath}:{},query:``,searchOpen:!1}}var X=_(Ee(W,Ie));function Le(e,t){let n=t(X.store.state[e]??J);X.update(t=>De(t,e,n)),Oe(W,Object.fromEntries(Object.entries(X.store.state).map(([e,t])=>[e,{...t,query:``,searchOpen:!1,expanded:t.expanded.slice(0,G)}])))}var Re=x(V),Z=me({list:{method:`GET`,path:`/`,query:[`scope`],response:void 0},preview:{method:`GET`,path:`/preview`,query:[`path`,`scope`],response:void 0},content:{method:`GET`,path:`/content`,query:[`path`,`scope`],raw:!0}},{scopes:[`session`],basePath:`artifacts`,transport:(e,t)=>w.fetch(e,t),sessionAddress:r});async function ze(e,t){let n=B.select(B.store.state,e);try{let r=await Z.session(e).list({signal:t});if(t.aborted||B.select(B.store.state,e)!==n)return;let i=r.ok?z(r.data):null;B.update(e,()=>i?{...i,loaded:!0}:{...n,loaded:!0,error:r.ok?`The session answered with no artifact list.`:r.error||`Artifacts could not be loaded.`})}catch(r){!t.aborted&&B.select(B.store.state,e)===n&&B.update(e,()=>({...n,loaded:!0,error:r instanceof Error?r.message:String(r)}))}}async function Be(e,t,n=`artifacts`){let r=await Z.session(e).list({...n===`temporary`?{query:{scope:n}}:{},signal:t});if(!r.ok)throw Error(r.error||`Files could not be loaded.`);let i=z(r.data);if(!i)throw Error(`The session returned an invalid file list.`);return i}async function Ve(e,t,n,r=`artifacts`){let i=await Z.session(e).preview({query:{path:t,...r===`temporary`?{scope:r}:{}},signal:n});if(!i.ok)throw Error(i.error||`This artifact could not be read.`);let a=i.data;if(!a||typeof a.path!=`string`||typeof a.content!=`string`||typeof a.mimeType!=`string`)throw Error(`The session answered with no artifact.`);return a}async function He(e,t,n,r=`artifacts`){let i=Z.session(e),a={path:t,...r===`temporary`?{scope:r}:{}},o=await i.content({query:a,...n?{signal:n}:{}});if(o.ok)return o.response.blob();if(o.status!==413)throw Error(o.error||`This artifact could not be loaded.`);let s=[],c=0,l=1,u,d=``;for(;c<l;){let e=await i.content({query:a,headers:{range:`bytes=${c}-${c+ge-1}`,...u?{"if-match":u}:{}},...n?{signal:n}:{}}),t=e.ok?/^bytes (\d+)-(\d+)\/(\d+)$/u.exec(e.response.headers.get(`content-range`)??``):null;if(!e.ok||e.status!==206||!t||Number(t[1])!==c)throw Error(e.ok?`This artifact changed while loading.`:e.error||`This artifact could not be loaded.`);if(l=Number(t[3]),l>134217728)throw Error(`This artifact is too large to load.`);u??=e.response.headers.get(`etag`)??void 0,d||=e.response.headers.get(`content-type`)??``;let r=await e.response.blob();if(r.size!==Number(t[2])-c+1)throw Error(`This artifact changed while loading.`);s.push(r),c+=r.size}return new Blob(s,{type:d})}async function Ue(e,t,n,r=`artifacts`){let i=L(t,n),a=await He(e,i,void 0,r);if(!a.type.startsWith(`image/`))throw Error(`This artifact asset is not an image.`);let o=URL.createObjectURL(a);return{url:o,dispose:()=>URL.revokeObjectURL(o),path:i}}var We={slot:`author.open-source`,parse(e){if(typeof e!=`object`||!e)return null;let t=e;return t.watchFocusedPath!==void 0&&typeof t.watchFocusedPath!=`function`?null:t.version===1&&typeof t.createTab==`function`?t:null}};function Ge(e){return e.sessionId===null?void 0:e.slotData?.(We)?.[0]?.data}function Ke({path:e,preview:t,error:n,media:r,loadImage:i,documentPath:a,renderMediaReview:s}){let c=R(e);return D(`div`,{"data-testid":`artifact-preview`,"data-artifact-path":e,className:`flex min-h-0 flex-1 flex-col bg-po-bg text-po-text`,children:[D(`header`,{className:`flex shrink-0 items-center gap-2 border-b border-po-border px-4 py-3`,children:[T(o,{path:e,className:`min-w-0 flex-1`}),T(`span`,{className:`text-sm text-po-dim`,children:`Artifact`})]}),T(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:n?T(`p`,{role:`alert`,className:`text-sm text-po-red`,children:n}):t?c===`media`?r:t.unavailable?T(`p`,{className:`text-sm text-po-dim`,children:t.reason??`This artifact cannot be previewed.`}):c===`markdown`?T(m,{text:t.content,loadImage:i,documentPath:a,renderMediaReview:s}):c===`html`?T(`iframe`,{title:e,sandbox:``,srcDoc:t.content,className:`h-96 w-full rounded-md border border-po-border bg-po-deep`}):c===`code`?T(C,{value:t.content,path:e,readOnly:!0,className:`min-h-64 rounded-md border border-po-border`}):T(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-sm text-po-text`,children:t.content}):T(`p`,{role:`status`,className:`text-sm text-po-dim`,children:`Reading this artifact...`})})]})}function qe({sessionId:e,path:t,revision:n,scope:r}){let[i,a]=y(),o=`${r}:${e}:${t}:${n}`;k(()=>{let n=new AbortController,i;return He(e,t,n.signal,r).then(e=>{n.signal.aborted||(i=URL.createObjectURL(e),a({source:o,url:i,mimeType:e.type}))}).catch(e=>{n.signal.aborted||a({source:o,error:e instanceof Error?e.message:String(e)})}),()=>{n.abort(),i!==void 0&&URL.revokeObjectURL(i)}},[e,t,o,r]);let s=i?.source===o?i:void 0;return s?.url?T(p,{src:s.url,path:t,contentType:s.mimeType}):T(`p`,{role:s?.error?`alert`:`status`,className:s?.error?`text-sm text-po-red`:`text-sm text-po-dim`,children:s?.error??`Loading artifact media...`})}function Je(e,t){return e===`artifacts`?`artifact:${t}`:t}function Ye(t){let{path:n,sessionId:r,scope:i=`artifacts`}=t,a=b(B.store,e=>B.select(e,r)),o=a.items.find(e=>e.path===n),s=i===`temporary`?`temporary`:o?`${o.modifiedAt}:${o.size}`:a.loaded?`missing`:`initial`,[c,l]=y();k(()=>{if(r===null||s===`missing`)return;let e=new AbortController;return Ve(r,n,e.signal,i).then(t=>{e.signal.aborted||l({sessionId:r,path:n,revision:s,preview:t})}).catch(t=>{e.signal.aborted||l({sessionId:r,path:n,revision:s,error:t instanceof Error?t.message:String(t)})}),()=>e.abort()},[r,n,s,i]);let u=c?.sessionId===r&&c.path===n&&c.revision===s?c:void 0,d=g(e=>r===null?Promise.reject(Error(`The session is unavailable.`)):Ue(r,n,e,i).then(e=>({...e,path:Je(i,e.path)})),[r,n,i]);return T(Ke,{path:n,preview:u?.preview,error:r===null?`The session is unavailable.`:s===`missing`?`This artifact no longer exists.`:u?.error,loadImage:d,documentPath:Je(i,n),renderMediaReview:e(t),media:r===null?void 0:T(qe,{sessionId:r,path:n,revision:s,scope:i})})}function Q(e,t,n=`artifacts`){return{id:`${n===`temporary`?`temporary:`:``}${I(e,t)}`,label:t.split(`/`).at(-1)??t,panel:r=>T(Ye,{...r,sessionId:e,path:t,scope:n}),...n===`artifacts`?{onOpen:e=>{let n=B.select(B.store.state,e).items.find(e=>e.path===t);n!==void 0&&Me(e,n)}}:{}}}function Xe(e,t,n=`artifacts`){if(e.sessionId===null)return;let r=B.select(B.store.state,e.sessionId).items.find(e=>e.path===t);if(n===`temporary`||v(t)===`video`&&(r?.size??0)>26214400){e.openTransientTab(Q(e.sessionId,t,n));return}let i=Ge(e);e.openTransientTab(i?.createTab({sessionId:e.sessionId,path:`artifact:${t}`})??Q(e.sessionId,t))}function Ze(e,t){let n=b(B.store,t=>B.select(t,e)),[r,i]=y();return k(()=>{if(e===null||!t)return;let n=new AbortController;return(async()=>{try{let t=await Be(e,n.signal,`temporary`);n.signal.aborted||i({...t,sessionId:e})}catch(t){n.signal.aborted||i(n=>({sessionId:e,items:n?.sessionId===e?n.items:[],error:t instanceof Error?t.message:String(t)}))}})(),()=>{n.abort()}},[e,t,n]),r?.sessionId===e?r:void 0}function Qe({sessionId:e,item:t}){let n=S(null),[r,i]=y(),a=`${e}:${t.path}:${t.modifiedAt}:${t.size}`;return k(()=>{let r=n.current;if(!r)return;let o=new AbortController,s,c=()=>{He(e,t.path,o.signal).then(e=>{o.signal.aborted||e.size>5242880||!e.type.startsWith(`image/`)||(s=URL.createObjectURL(e),i({revision:a,url:s}))}).catch(()=>{})},l=typeof IntersectionObserver>`u`?void 0:new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(l?.disconnect(),c())});return l?l.observe(r):c(),()=>{l?.disconnect(),o.abort(),s&&URL.revokeObjectURL(s)}},[e,t.path,a]),T(`span`,{ref:n,className:`flex h-full w-full items-center justify-center`,children:r?.revision===a?T(`img`,{src:r.url,alt:``,className:`h-full w-full object-cover`}):T(ae,{"aria-hidden":!0,className:`size-8`})})}var $e={all:`All`,new:`New`,edited:`Edited`,viewed:`Viewed`},et=[`any`,`Markdown`,`Image`,`Code`,`Data`,`Document`,`Other`],tt={any:`Any time`,today:`Today`,"7days":`Past 7 days`,"30days":`Past 30 days`},nt={artifacts:`Artifacts`,temporary:`Temporary files`},rt={"modified:desc":`Recently changed`,"modified:asc":`Oldest first`,"name:asc":`Name A to Z`,"name:desc":`Name Z to A`,"size:desc":`Largest first`,"size:asc":`Smallest first`};function it({status:e}){return e===`new`?T(O,{tone:`green`,size:`xs`,className:`shrink-0 bg-po-tint-green`,children:`New`}):e===`edited`?T(O,{tone:`green`,size:`xs`,className:`shrink-0`,children:`Edited`}):e===`viewed`?T(`span`,{className:`sr-only`,children:`, viewed`}):null}function at(e){let{items:r,loading:o,error:p,onRetry:se,now:m,statusOf:h,layout:g,onLayoutChange:_,query:v,onQueryChange:y,searchOpen:b,onSearchOpenChange:x,filters:C,onFiltersChange:w,sort:E,direction:ue,onSortChange:pe,expanded:me,onToggleFolder:O,openPath:j,onOpen:ge,onMarkAllViewed:_e,renderThumbnail:M,defaultMenuOpen:N}=e,P=S(null),F=S(void 0),I=new Map(r.map(e=>[e.path,h?.(e)])),L=r.filter(e=>I.get(e.path)===`new`).length,R=r.filter(e=>I.get(e.path)===`edited`).length,z=e=>ye(r,{query:v,type:e.type,modified:e.modified},m).filter(t=>e.status===`all`||I.get(t.path)===e.status),B=e=>T(u,{className:`pl-4 tabular-nums`,children:z({...C,...e}).length}),V=be(z(C),E,ue),H=v!==``||C.status!==`all`||C.type!==`any`||C.modified!==`any`,Ce=g===`tree`?xe(V,e=>H||me.has(e)):V.map(e=>({kind:`file`,item:e,depth:0}));k(()=>{let e=`${g}:${j}`;if(o||j===void 0||F.current===e)return;let t=P.current?.querySelector(`[aria-current="true"]`);t!=null&&(t.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:`instant`}),F.current=e)},[g,o,j,Ce]);let we=e=>V.filter(t=>t.path.startsWith(`${e}/`)&&I.get(t.path)!==`viewed`&&h).length,Te=`${E}:${ue}`,U=()=>{y(``),w({...Se,location:C.location})},W=e=>w({...C,status:C.status===e?`all`:e}),G=e=>{if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=[...e.currentTarget.closest(`[data-testid="artifacts-grid"]`)?.querySelectorAll(`[data-artifact-row]`)??[]],n=t.indexOf(e.currentTarget);n<0||(e.preventDefault(),t[Math.max(0,Math.min(t.length-1,n+(e.key===`ArrowDown`?1:-1)))]?.focus())};return D(`section`,{"data-testid":`artifacts-grid`,"aria-label":`Artifacts`,className:`flex min-h-0 flex-1 flex-col bg-po-rail text-po-text`,children:[D(`div`,{role:`toolbar`,"aria-label":`Artifact view`,className:`flex shrink-0 items-center gap-1 px-3 pt-3 pb-2`,children:[D(le,{defaultOpen:N===`filter`,children:[T(te,{asChild:!0,children:D(A,{variant:`ghost`,size:`sm`,className:`text-po-text`,children:[T(i,{"aria-hidden":!0,className:`size-3.5`}),`Filter`,C.status!==`all`||C.type!==`any`||C.modified!==`any`||C.location!==`artifacts`?T(ee,{tone:`green`,"aria-label":`Filters on`}):null]})}),D(t,{align:`start`,className:`w-56`,children:[h?D(oe,{children:[T(d,{children:`Status`}),T(f,{value:C.status,onValueChange:e=>w({...C,status:e}),children:Object.keys($e).map(e=>D(a,{value:e,children:[$e[e],B({status:e})]},e))}),T(c,{})]}):null,T(d,{children:`Type`}),T(f,{value:C.type,onValueChange:e=>w({...C,type:e}),children:et.map(e=>D(a,{value:e,children:[e===`any`?`All types`:e,B({type:e})]},e))}),T(c,{}),T(d,{children:`Modified`}),T(f,{value:C.modified,onValueChange:e=>w({...C,modified:e}),children:Object.keys(tt).map(e=>D(a,{value:e,children:[tt[e],B({modified:e})]},e))}),T(c,{}),T(d,{children:`Location`}),T(f,{value:C.location,onValueChange:e=>w({...C,location:e}),children:Object.keys(nt).map(e=>T(a,{value:e,children:nt[e]},e))}),H?D(oe,{children:[T(c,{}),T(ce,{onSelect:U,children:`Reset filters`})]}):null]})]}),D(le,{defaultOpen:N===`sort`,children:[T(te,{asChild:!0,children:D(A,{variant:`ghost`,size:`sm`,className:`text-po-text`,children:[`Sort`,T(de,{"aria-hidden":!0,className:`size-3`})]})}),T(t,{align:`start`,className:`w-48`,children:T(f,{value:Te,onValueChange:e=>{let[t,n]=e.split(`:`);pe(t,n)},children:Object.keys(rt).map(e=>T(a,{value:e,children:rt[e]},e))})})]}),T(`span`,{className:`flex-1`}),T(`fieldset`,{"aria-label":`Artifact view`,className:`flex shrink-0 gap-0.5`,children:[[`tree`,re,`Tree view`],[`grid`,s,`Preview view`]].map(([e,t,n])=>T(`button`,{type:`button`,"aria-label":n,title:n,"aria-pressed":g===e,onClick:()=>_(e),className:`${fe({active:g===e})} focus-visible:ring-2 focus-visible:ring-po-green`,children:T(t,{"aria-hidden":!0,className:`size-4`})},e))}),T(`button`,{type:`button`,"aria-label":`Search artifacts`,title:`Search artifacts`,"aria-expanded":b,onClick:()=>x(!b),className:`${fe({active:b||v!==``})} focus-visible:ring-2 focus-visible:ring-po-green`,children:T(l,{"aria-hidden":!0,className:`size-4`})})]}),b?D(`div`,{className:`relative shrink-0 px-3 pb-2`,children:[T(l,{"aria-hidden":!0,className:`absolute top-2 left-5 size-4 text-po-dim`}),T(ie,{"aria-label":`Search artifacts`,autoFocus:!0,placeholder:`Search by name or folder`,value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),y(``),x(!1))},className:`w-full pl-8`})]}):null,h&&L+R>0?D(`div`,{className:`flex shrink-0 items-center gap-1 border-b border-po-border-soft px-3 pb-2`,children:[L>0?D(A,{variant:`ghost`,size:`xs`,"aria-pressed":C.status===`new`,onClick:()=>W(`new`),className:C.status===`new`?`bg-po-tint-green text-po-green`:`text-po-text`,children:[L,` new`]}):null,R>0?D(A,{variant:`ghost`,size:`xs`,"aria-pressed":C.status===`edited`,onClick:()=>W(`edited`),className:C.status===`edited`?`bg-po-tint-green text-po-green`:`text-po-text`,children:[R,` edited`]}):null,T(`span`,{className:`flex-1`}),_e?T(A,{variant:`ghost`,size:`xs`,onClick:_e,className:`text-po-dim`,children:`Mark all viewed`}):null]}):T(`div`,{className:`shrink-0 border-b border-po-border-soft`}),D(`div`,{ref:P,className:`min-h-0 flex-1 overflow-auto`,children:[p?D(`div`,{role:`alert`,className:`flex items-center gap-2 px-4 py-3`,children:[T(`p`,{className:`flex-1 text-sm text-po-red`,children:p}),se?T(A,{variant:`outline`,size:`xs`,onClick:se,children:`Try again`}):null]}):null,o?T(`output`,{className:`block px-4 py-3 text-sm text-po-dim`,children:`Loading files...`}):null,!o&&!p&&r.length===0?T(n,{title:`Nothing here yet`,description:`Files Po makes in this session show up here.`,className:`px-4 py-8`}):null,!o&&r.length>0&&V.length===0?T(n,{title:`No files match`,className:`px-4 py-8`,children:T(A,{variant:`ghost`,onClick:U,children:`Clear filters`})}):null,T(`div`,{className:g===`grid`?`grid grid-cols-2 gap-2 p-3`:`flex flex-col py-1`,children:Ce.map(e=>{if(e.kind===`dir`){let t=we(e.path);return D(`button`,{type:`button`,"data-artifact-row":!0,"aria-expanded":e.open,onClick:()=>O(e.path),onKeyDown:t=>{G(t),(t.key===`ArrowRight`&&!e.open||t.key===`ArrowLeft`&&e.open)&&(t.preventDefault(),O(e.path))},className:`flex min-h-9 items-center gap-2 px-3 py-1.5 text-left hover:bg-po-panel focus-visible:ring-2 focus-visible:ring-po-green focus-visible:ring-inset`,children:[Array.from({length:e.depth},(e,t)=>T(`span`,{className:`w-3 shrink-0`},t)),e.open?T(de,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-po-dim`}):T(he,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-po-dim`}),T(re,{"aria-hidden":!0,className:`size-4 shrink-0 text-po-dim`}),T(`span`,{className:`min-w-0 flex-1 truncate text-base font-medium`,children:e.name}),t>0?D(`span`,{className:`shrink-0 text-sm font-semibold text-po-green`,children:[t,` unviewed`]}):D(`span`,{className:`shrink-0 text-sm text-po-dim`,children:[e.count,` `,e.count===1?`file`:`files`]})]},e.path)}let t=I.get(e.item.path),n=t===`new`||t===`edited`,r=j===e.item.path,i=ve(e.item.path)===`Image`?ae:ne;return D(`button`,{type:`button`,"data-artifact-row":!0,"data-artifact-path":e.item.path,"data-status":t,"aria-current":r?`true`:void 0,title:e.item.path,onClick:()=>ge(e.item),onKeyDown:G,className:`${g===`grid`?`flex min-w-0 flex-col gap-1.5 rounded-md border p-2 text-left`:`flex min-h-9 items-center gap-2 border-l-2 px-3 py-1.5 text-left`} ${r?`border-po-green bg-po-panel`:g===`grid`?`border-po-border-soft hover:bg-po-panel`:`border-transparent hover:bg-po-panel`} focus-visible:ring-2 focus-visible:ring-po-green focus-visible:ring-inset`,children:[g===`grid`?D(`span`,{className:`relative flex h-24 w-full items-center justify-center overflow-hidden rounded-sm bg-po-deep text-po-dim`,children:[M?.(e.item)??T(i,{"aria-hidden":!0,className:`size-8`}),T(`span`,{className:`absolute top-1 left-1`,children:T(it,{status:t})})]}):D(oe,{children:[Array.from({length:e.depth},(e,t)=>T(`span`,{className:`w-3 shrink-0`},t)),T(`span`,{className:`w-3.5 shrink-0`}),T(i,{"aria-hidden":!0,className:`size-4 shrink-0 text-po-dim`})]}),D(`span`,{className:`flex w-full min-w-0 flex-1 items-center gap-2`,children:[T(`span`,{className:`min-w-0 flex-1 truncate text-base ${n?`font-semibold text-po-hi`:`text-po-text`}`,children:e.item.name}),g===`grid`?T(`span`,{className:`sr-only`,children:T(it,{status:t===`viewed`?t:void 0})}):T(it,{status:t}),T(ot,{modifiedAt:e.item.modifiedAt,now:m})]})]},e.item.path)})})]}),D(`footer`,{"data-testid":`artifacts-count`,"aria-live":`polite`,className:`shrink-0 border-t border-po-border-soft px-4 py-2 text-sm text-po-dim`,children:[H?`${V.length} of ${r.length}`:r.length,` `,r.length===1?`file`:`files`]})]})}function ot({modifiedAt:e,now:t}){let n=S(null);return k(()=>{let t=setInterval(()=>{let t=n.current?.firstChild;t&&(t.nodeValue=P(e,Date.now()))},6e4);return()=>clearInterval(t)},[e]),T(`time`,{ref:n,dateTime:new Date(e).toISOString(),className:`shrink-0 text-sm text-po-dim`,children:P(e,t)})}var st=5242880,ct=`artifact:`;function lt(e){let{sessionId:t}=e,n=b(B.store,e=>B.select(e,t)),r=b(q.store,e=>t===null?void 0:e[t]),i=b(X.store,e=>t===null?J:e[t]??J),a=b(we.store),o=i.filters.location===`temporary`,s=Ze(t,o),[c,l]=y(Date.now);k(()=>{let e=B.store.subscribe(()=>l(Date.now()));return()=>e.unsubscribe()},[]);let u=Ge(e);k(()=>{if(t!==null)return u?.watchFocusedPath?.(t,e=>{if(typeof e!=`string`||!e.startsWith(ct))return;let n=e.slice(9),r=n.split(`/`).slice(0,-1).map((e,t,n)=>n.slice(0,t+1).join(`/`)),i=X.store.state[t]??J;if(i.filters.location!==`artifacts`)return;let a=r.filter(e=>!i.expanded.includes(e));(i.openPath!==n||a.length!==0)&&Le(t,e=>({...e,openPath:n,expanded:[...e.expanded,...a]}))})},[u,t]),k(()=>{if(t===null||n.loaded)return;let e=new AbortController;return ze(t,e.signal),()=>e.abort()},[t,n.loaded]);let d=e=>{t!==null&&Le(t,t=>({...t,...e}))},f=o?s?.items??[]:n.items;return T(at,{items:f,loading:t!==null&&(o?s===void 0:!n.loaded),error:t===null?`The session is unavailable.`:o?s?.error:n.error,onRetry:t===null||o?void 0:()=>void ze(t,new AbortController().signal),now:c,statusOf:o?void 0:e=>N(e,r),layout:a===`grid`?`grid`:`tree`,onLayoutChange:Te,query:i.query,onQueryChange:e=>d({query:e}),searchOpen:i.searchOpen,onSearchOpenChange:e=>d({searchOpen:e}),filters:i.filters,onFiltersChange:e=>{d({filters:e}),l(Date.now())},sort:i.sort,direction:i.direction,onSortChange:(e,t)=>d({sort:e,direction:t}),expanded:new Set(i.expanded),onToggleFolder:e=>d({expanded:i.expanded.includes(e)?i.expanded.filter(t=>t!==e):[...i.expanded,e]}),openPath:i.openPath,onOpen:n=>{if(t===null)return;Xe(e,n.path,i.filters.location),o||Me(t,n);let r=n.path.split(`/`).slice(0,-1).map((e,t,n)=>n.slice(0,t+1).join(`/`));d({openPath:n.path,expanded:[...i.expanded,...r.filter(e=>!i.expanded.includes(e))]})},onMarkAllViewed:t===null?void 0:()=>Ne(t,n.items),renderThumbnail:e=>t!==null&&ve(e.path)===`Image`&&e.size<=st?T(Qe,{sessionId:t,item:e},e.path):void 0},t)}var ut=se({id:`artifacts`,label:`Artifacts`,icon:ne,order:10,panel:lt,badge:{subscribe(e){let t=B.store.subscribe(e),n=q.store.subscribe(e);return()=>{t.unsubscribe(),n.unsubscribe()}},count:Pe}});function dt(e,t){let n=e.trim(),r;if(n.startsWith(`temporary:`))r=n.slice(10);else{if(!t||!t.startsWith(`/`))return;let e=t.replace(/\/+$/u,``);if(!n.startsWith(`${e}/`))return;r=n.slice(e.length+1)}if(!(!r||r.includes(`\\`)||r.includes(`\0`)||r.split(`/`).some(e=>!e||e===`.`||e===`..`)))return r}var ft=5,pt=E({subscribe(e){let t=B.store.subscribe(e);return()=>t.unsubscribe()},fingerprint:e=>B.select(B.store.state,e).temporaryRoot??``,resolve(e,t){let n=t.trim();if(e===null)return;let r=dt(n,B.select(B.store.state,e).temporaryRoot);if(r)return Q(e,r,`temporary`);if(!n.startsWith(`artifact:`))return;let i=n.slice(9);return i===``?void 0:Q(e,i)},mentions(e,t){let n=t.toLowerCase();return B.select(B.store.state,e).items.map(e=>`artifact:${e.path}`).filter(e=>e.toLowerCase().includes(n)).slice(0,ft).map(e=>({path:e,detail:`Artifact`}))}}),mt=pe({slot:`help.guides`,id:`Artifacts`,order:10,data:{version:1,label:`Artifacts`,guides:[{id:`about`,question:`What are artifacts?`,order:0,answer:`Artifacts are important deliverables saved in this session’s durable artifact folder. Ordinary source edits stay in your project.`},{id:`find`,question:`Where do I find files Po made?`,order:1,answer:`The Artifacts activity section shows the three most recently changed files. Open its heading to see all this session’s artifacts. Previews are read-only.`}]}}),$=(e,t)=>t===void 0?void 0:{...e,...t},ht=h({id:`artifacts`,session:{get channels(){return[$({channel:`artifacts`},Re)]},get dockFaces(){return[$({id:`artifacts`},ut)]},get fileLinks(){return pt},get fills(){return[$({slot:`help.guides`,id:`artifacts`},mt)]}}});export{ht as webPlugin};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import{$t as e,C as t,Cr as n,E as r,Et as i,Jt as a,O as o,On as s,S as c,T as l,Un as u,Vt as d,_r as f,_t as p,a as m,ar as h,b as g,br as _,bt as v,c as y,cn as b,cr as x,er as S,f as C,gr as w,gt as T,h as E,ht as ee,i as D,ir as te,lr as O,m as k,mn as ne,mt as re,n as A,o as j,on as ie,or as M,pr as ae,pt as oe,qt as N,rr as se,s as P,sr as ce,t as F,tr as le,u as I,ur as ue,w as de,wr as fe,wt as pe,yr as me,zn as he,zt as L}from"../chunks/po-web-runtime-BJDT6Lbw.js";var ge={slot:`author.media-review`,description:`Provide an annotation and feedback panel for an image or diagram opened from Markdown.`,parse:e=>{if(typeof e!=`object`||!e)return null;let t=e;return t.version===1&&typeof t.panel==`function`?t:null}},_e=`author_webmcp`,ve=`author`,ye={text:`author.viewport.text`,media:`author.viewport.media`},be=new F(0);function xe(){return be.setState(e=>e+1),`a${be.state.toString(36)}_`}function Se(e){if(e.id.trim()===``)throw Error(`Author profile id must not be empty`);if(e.tools.length>15)throw Error(`Author profiles may expose at most 15 tools`);let t=new Set;for(let n of e.tools){if(!/^[a-z][a-z0-9_]{0,29}$/.test(n.name))throw Error(`Invalid Author tool name: ${n.name}`);if(t.has(n.name))throw Error(`Duplicate Author tool name: ${n.name}`);t.add(n.name)}}function Ce(e,t){return e.name===t.name&&e.description===t.description&&JSON.stringify(e.inputSchema)===JSON.stringify(t.inputSchema)}function we(){return Error(`Author viewport catalog is stale`)}function Te(e,t){let n=new AbortController,r=()=>n.abort(e.reason),i=()=>n.abort(t.reason);return e.aborted?r():t.aborted?i():(e.addEventListener(`abort`,r,{once:!0}),t.addEventListener(`abort`,i,{once:!0})),{signal:n.signal,release:()=>{e.removeEventListener(`abort`,r),t.removeEventListener(`abort`,i)}}}var Ee=class{#e;#t=xe();#n;#r;#i;#a=0;#o=!1;constructor(e){this.#e=e}async replaceProfiles(e){if(this.#o)throw Error(`Author runtime is disposed`);for(let t of e)Se(t);let t=new Map(e.map(e=>[e.id,e])),n=e.flatMap(e=>e.tools);if(new Set(n.map(e=>e.name)).size!==n.length)throw Error(`Author tool names must be unique across trusted profiles`);let r=this.#n??(await this.#e.acquireModelContext?.())?.modelContext;if(r===void 0)throw Error(`Model Context is unavailable`);this.#n=r;let i=new Map(n.map((e,t)=>[e.name,`${this.#t}${t.toString(36)}`])),a=++this.#a,o=new AbortController,s={generation:a,controller:o,profiles:t,registrations:i},c=we();this.#i?.controller.abort(c),this.#r?.controller.abort(c),this.#i=s,this.#r=void 0;let l=()=>{if(o.signal.aborted||this.#o||this.#r?.generation!==a)throw we()};try{await Promise.all(n.map(async e=>r.registerTool({name:i.get(e.name),description:e.description,inputSchema:e.inputSchema,execute:async(t,n)=>{l();let r=JSON.parse(t);l();let i=Te(o.signal,n.signal);try{let t=await e.execute(r,i.signal);return l(),t}finally{i.release()}}},{signal:o.signal})));let e=await r.getTools();if(!n.every(t=>e.some(e=>Ce(e,{...t,name:i.get(t.name)}))))throw Error(`Model Context did not confirm the Author catalog`);if(this.#o||a!==this.#a||this.#i!==s)throw we();this.#i=void 0,this.#r=s}catch(e){throw o.abort(e),this.#i===s&&(this.#i=void 0),e}return()=>{this.#r?.generation===a&&(o.abort(we()),this.#r=void 0,this.#a+=1)}}async execute(e,t,n){let r=this.#n;if(r===void 0||this.#r===void 0)throw Error(`Author catalog is not registered`);let i=this.#r.registrations.get(e);if(i===void 0)throw Error(`Unknown Author capability: ${e}`);return r.executeTool(i,JSON.stringify(t),{signal:n})}dispose(){this.#o||(this.#o=!0,this.#a+=1,this.#i?.controller.abort(Error(`Author runtime disposed`)),this.#r?.controller.abort(Error(`Author runtime disposed`)),this.#i=void 0,this.#r=void 0)}},R=(e,t)=>`${e}\n${t}`,De=1e4,Oe=new F({}),ke=(e,t)=>{Oe.state[e]!==t&&Oe.setState(n=>{let r={...n};return t===void 0?delete r[e]:r[e]=t,r})},Ae=new Set([`author_describe_grid`,`author_resolve_grid_cell`,`author_add_grid_note`]),je=e=>e.map(e=>({...e,tools:e.tools.filter(e=>!Ae.has(e.name))})),Me=class{#e;#t;#n=new Map;#r=new Map;#i=new Map;#a=new Map;#o=0;#s=!1;#c;constructor(e,t){this.#e=e,this.#t=t,this.#c=e.onHubConnected(()=>{for(let e of this.#n.values())e.ownerToken=void 0,e.catalogToken=void 0,this.#h(e)})}async open(e,t,n){if(this.#s)throw Error(`Author browser bridge is disposed`);this.#d(e);let r=R(e,t);if(this.#n.has(r))return;let i=this.#r.get(r);if(i!==void 0){this.#u(e)&&await this.#l(i);return}let a=this.#i.get(r);if(a!==void 0)return await a.promise;let o={sessionId:e,alias:t,profiles:je(n)};this.#u(e)?await this.#l(o):this.#r.set(r,o)}async#l(e){let{sessionId:t,alias:n}=e,r=e.focus?.profiles??e.profiles,i=R(t,n);if(this.#s||this.#n.has(i))return;let a=this.#i.get(i);if(a!==void 0)return await a.promise;if(!this.#u(t)){this.#r.set(i,e);return}this.#r.delete(i);let o=new Ee(this.#e),s=++this.#o,c;c=(async()=>{let a;try{a=await o.replaceProfiles(r)}catch(e){if(this.#s||!this.#u(t)||this.#i.get(i)?.promise!==c)return;throw e}if(this.#s||!this.#u(t)||this.#n.has(i)||this.#i.get(i)?.promise!==c){a(),o.dispose(),!this.#s&&!this.#u(t)&&this.#r.set(i,e);return}let l={sessionId:t,alias:n,generation:s,profiles:r,intent:e,runtime:o,release:a,pending:new Map,replacementId:0};this.#n.set(i,l);let u=e.focus?.profiles??e.profiles;u===r?this.#h(l):await this.#m(l,u)})(),this.#i.set(i,{promise:c,runtime:o,parked:e});try{await c}finally{this.#i.get(i)?.promise===c&&this.#i.delete(i)}}async focus(e,t,n){await this.open(e,t,n);let r=R(e,t),i=this.#n.get(r),a=i?.intent??this.#r.get(r)??this.#i.get(r)?.parked;if(a===void 0)return()=>void 0;let o={profiles:n};return a.focus=o,i!==void 0&&await this.#m(i,n),()=>{if(a.focus!==o)return;a.focus=void 0;let e=this.#n.get(r);e?.intent===a&&this.#m(e,a.profiles)}}drop(e,t){for(let[n,r]of this.#i)r.parked.sessionId!==e||t!==void 0&&r.parked.alias!==t||(this.#i.delete(n),r.runtime.dispose());for(let[n,r]of this.#r)r.sessionId!==e||t!==void 0&&r.alias!==t||this.#r.delete(n);for(let n of this.#n.values())n.sessionId!==e||t!==void 0&&n.alias!==t||this.#p(n)}canvases(e,t){this.#t?.(this.#e,e,t);let n=new Set(t.map(e=>e.alias)),r=new Set;for(let t of[...this.#i.values(),...this.#r.values(),...this.#n.values()]){let i=`parked`in t?t.parked:t;i.sessionId===e&&!n.has(i.alias)&&r.add(i.alias)}for(let t of r)this.drop(e,t)}apply(e,t){if(!this.#u(e)||t.alias===void 0)return;let n=this.#n.get(R(e,t.alias));if(n===void 0)return;if(t.kind===`rejected`){ke(R(e,t.alias),t.reason),clearTimeout(n.leaseTimer),n.leaseTimer=setTimeout(()=>this.#h(n),De);return}if(t.generation!==n.generation||t.ownerToken!==n.ownerToken&&n.ownerToken!==void 0)return;if(t.kind===`accepted`){ke(R(e,t.alias),void 0),n.ownerToken=t.ownerToken,clearTimeout(n.leaseTimer),n.leaseTimer=setTimeout(()=>this.#h(n),Math.max(1e3,Math.floor(t.leaseMs/2))),t.catalogToken===void 0?this.#g(n):n.catalogToken=t.catalogToken;return}if(t.catalogToken!==n.catalogToken)return;if(t.kind===`cancel`){n.pending.get(t.requestId)?.abort(Error(`Author tool request cancelled`));return}if(t.kind!==`request`||n.pending.has(t.requestId))return;let r=new AbortController;n.pending.set(t.requestId,r),n.runtime.execute(t.name,t.arguments,r.signal).then(e=>{this.#y(n,t.requestId,r)&&(r.signal.aborted?this.#_(n,t.requestId):this.#v(n,{kind:`result`,alias:n.alias,generation:n.generation,ownerToken:n.ownerToken,catalogToken:n.catalogToken,requestId:t.requestId,result:e}))}).catch(e=>{if(this.#y(n,t.requestId,r)){if(r.signal.aborted)this.#_(n,t.requestId);else{let r=e instanceof Error?e.message:String(e),i=/^([A-Z][A-Z_]+):/u.exec(r)?.[1]??`AUTHOR_TOOL_ERROR`;this.#v(n,{kind:`result`,alias:n.alias,generation:n.generation,ownerToken:n.ownerToken,catalogToken:n.catalogToken,requestId:t.requestId,result:{error:{code:i,message:r}}})}}}).finally(()=>{n.pending.get(t.requestId)===r&&n.pending.delete(t.requestId)})}activeView(e){let t=[...this.#n.values()].filter(t=>t.sessionId===e&&t.catalogToken);return t.length>0?{activation:`active`,capabilityCount:t.reduce((e,t)=>e+t.profiles.reduce((e,t)=>e+t.tools.length,0),0)}:{activation:`inactive`,capabilityCount:0}}dispose(){if(!this.#s){this.#s=!0,this.#c();for(let e of this.#a.values())e();this.#a.clear();for(let e of this.#n.values())this.#p(e);this.#r.clear();for(let e of this.#i.values())e.runtime.dispose();this.#i.clear()}}#u(e){return this.#e.minorModes?.active(e).includes(ve)===!0}#d(e){if(this.#a.has(e)||this.#e.minorModes===void 0)return;let t=this.#e.minorModes.subscribe(e,()=>this.#f(e));this.#a.set(e,t)}#f(e){if(!this.#s){if(this.#u(e))for(let t of this.#r.values())t.sessionId===e&&this.#l(t).catch(e=>console.warn(`Author canvas '${t.alias}' could not enable browser tools: ${e instanceof Error?e.message:String(e)}`));else{for(let[t,n]of this.#i)n.parked.sessionId===e&&(this.#i.delete(t),this.#r.set(t,n.parked),n.runtime.dispose());for(let t of this.#n.values())t.sessionId===e&&(this.#r.set(R(t.sessionId,t.alias),t.intent),this.#p(t))}}}#p(e){this.#n.delete(R(e.sessionId,e.alias)),ke(R(e.sessionId,e.alias),void 0),this.#b(e),e.runtime.dispose()}async#m(e,t){let n=R(e.sessionId,e.alias);if(this.#s||!this.#u(e.sessionId)||this.#n.get(n)!==e)return;this.#b(e);let r=e.generation,i=++e.replacementId,a;try{a=await e.runtime.replaceProfiles(t)}catch(t){if(e.replacementId!==i||this.#n.get(n)!==e)return;throw t}this.#s||this.#n.get(n)!==e||e.generation!==r||e.replacementId!==i?a():(e.release=a,e.profiles=t,this.#h(e))}#h(e){this.#u(e.sessionId)&&this.#n.get(R(e.sessionId,e.alias))===e&&this.#v(e,{kind:`register`,alias:e.alias,generation:e.generation})}#g(e){this.#v(e,{kind:`catalog`,alias:e.alias,generation:e.generation,ownerToken:e.ownerToken,tools:e.profiles.flatMap(e=>e.tools.map(e=>({name:e.name,label:e.label??e.name,description:e.description,inputSchema:e.inputSchema})))})}#_(e,t){this.#v(e,{kind:`cancelled`,alias:e.alias,generation:e.generation,ownerToken:e.ownerToken,catalogToken:e.catalogToken,requestId:t})}#v(e,t){let n=this.#e.mount?.scope===`session`?this.#e.mount.workspaceId:void 0,r=n?{scope:`workspace`,workspaceId:n}:{scope:`global`};this.#e.invokeServerMethod({mount:r,service:`author.bridge`,method:`send`,input:{sessionId:e.sessionId.slice(e.sessionId.indexOf(`/`)+1),message:t}}).catch(n=>console.warn(`Author canvas '${e.alias}' could not send '${t.kind}': ${n instanceof Error?n.message:String(n)}`))}#y(e,t,n){return this.#n.get(R(e.sessionId,e.alias))===e&&e.pending.get(t)===n}#b(e){clearTimeout(e.leaseTimer),e.leaseTimer=void 0,this.#v(e,{kind:`release`,alias:e.alias,generation:e.generation}),e.release();for(let t of e.pending.values())t.abort(Error(`Author viewport changed`));e.pending.clear(),e.ownerToken=void 0,e.catalogToken=void 0,e.generation=++this.#o}},Ne=`global`,Pe=new F(new Map),Fe=new F(new Map),Ie=e=>Pe.state.get(e)??Pe.state.get(Ne);function Le(e,t){let n=e.mount?.scope===`session`?e.mount.sessionId:Ne;Pe.state.get(n)?.dispose();let r=new Me(e,t);Pe.setState(e=>new Map(e).set(n,r));for(let[e,t]of Fe.state)(n===Ne||n===e)&&r.canvases(e,t);return()=>{Pe.state.get(n)===r&&(r.dispose(),Pe.setState(e=>{let t=new Map(e);return t.delete(n),t}))}}async function Re(e,t,n){await Ie(e)?.open(e,t,n)}async function ze(e,t,n=`default`){return await Ie(e)?.focus(e,n,t)??(()=>void 0)}function Be(e,t){t.kind===`canvases`?(Fe.setState(n=>new Map(n).set(e,t.canvases)),Ie(e)?.canvases(e,t.canvases)):Ie(e)?.apply(e,t)}function Ve(e,t){t===void 0&&Fe.state.has(e)&&Fe.setState(t=>{let n=new Map(t);return n.delete(e),n}),Ie(e)?.drop(e,t)}function He(e){return Ie(e)?.activeView(e)??{activation:`inactive`,capabilityCount:0}}var Ue=`ABCDEFGH`;function We(e){let t=e.trim().toUpperCase();if(!/^[A-H][1-8]$/u.test(t))throw Error(`Invalid Author grid cell '${e}'. Expected A1 through H8.`);return{cell:t,column:Ue.indexOf(t[0]),row:Number(t[1])-1}}var Ge=new Map,Ke=x({sessions:{}});function qe(e,t){let n=Ke.store.state.sessions[e],r={...t,geometryToken:crypto.randomUUID(),snapshotId:n?.documentPath===t.documentPath&&n.revision===t.revision&&n.sourceSha256===t.sourceSha256?n.snapshotId:crypto.randomUUID(),updatedAt:Date.now()};return Ke.update(t=>({...t,sessions:{...t.sessions,[e]:r}})),r}function Je(e){return Ke.store.state.sessions[e]}function Ye(e){Ke.update(t=>{if(t.sessions[e]===void 0)return t;let n={...t.sessions};return delete n[e],{...t,sessions:n}})}function Xe(e,t){return Ge.set(e,t),()=>{Ge.get(e)===t&&Ge.delete(e)}}function Ze(e,t){let n=Je(e),r=n===void 0?void 0:Ge.get(e)?.(t,n);if(r===void 0)throw Error(`AMBIGUOUS_GRID: The grid cell does not resolve to one visible native document target.`);return r}function Qe(e,t,n){let r=Je(e);if(r===void 0||r.geometryToken!==n)throw Error(`STALE_GRID: The Author grid geometry changed. Describe the grid again.`);let i=We(t),a=1/8,o=1/8,s={x:i.column*a,y:i.row*o,width:a,height:o};return{...i,rect:s,center:{x:s.x+a/2,y:s.y+o/2},evidence:{cell:i.cell,geometryToken:r.geometryToken,snapshotId:r.snapshotId}}}var $e=[{format:`bold`,label:`Bold`,glyph:`B`},{format:`heading`,label:`Heading`,glyph:`H`},{format:`link`,label:`Link`,glyph:`↗`},{format:`list`,label:`List`,glyph:`≡`}],et=/^#{1,6} /,tt=/^(?:[-*+]|\d+[.)]) /;function nt(e,t,n,r){if(r===`bold`){let r=e.slice(t,n);if(r.length>=4&&r.startsWith(`**`)&&r.endsWith(`**`))return{from:t,to:n,insert:r.slice(2,-2),select:{from:t,to:n-4}};if(t>=2&&e.slice(t-2,t)===`**`&&e.slice(n,n+2)===`**`)return{from:t-2,to:n+2,insert:r,select:{from:t-2,to:n-2}};let i=r||`bold text`;return{from:t,to:n,insert:`**${i}**`,select:{from:t+2,to:t+2+i.length}}}if(r===`link`){let r=e.slice(t,n)||`link text`,i=t+r.length+3;return{from:t,to:n,insert:`[${r}](https://)`,select:{from:i,to:i+8}}}let i=e.lastIndexOf(`
|
|
2
|
+
`,t-1)+1,a=n>t&&e[n-1]===`
|
|
3
|
+
`?n-1:n,o=e.indexOf(`
|
|
4
|
+
`,Math.max(a,i)),s=o===-1?e.length:o,c=r===`heading`?et:tt,l=r===`heading`?`## `:`- `,u=e.slice(i,s).split(`
|
|
5
|
+
`),d=u.filter(e=>e.trim()!==``),f=d.length>0&&d.every(e=>c.test(e)),p=u.map(e=>e.trim()===``?e:f?e.replace(c,``):l+e.replace(et,``).replace(tt,``)).join(`
|
|
6
|
+
`);return{from:i,to:s,insert:p,select:{from:i,to:i+p.length}}}function rt(e,t,n,r){let i=Math.min(e.length,t.length),a=0;for(;a<i&&e[a]===t[a];)a+=1;let o=0;for(;o<i-a&&e[e.length-1-o]===t[t.length-1-o];)o+=1;let s=e.length-o,c=t.length-e.length,l=n<a?n:n>=s?n+c:a,u=r<=a?r:r>=s?r+c:t.length-o;return{start:l,end:Math.max(l,u)}}function it(e,t){let n=0;return t.map(t=>{if(t.trim()===``)return;let r=e.indexOf(t,n),i=t.trimStart().split(`
|
|
7
|
+
`)[0],a=r===-1?e.indexOf(i,n):r;if(a!==-1)return n=a+(r===-1?i.length:t.length),a})}function at(e,t){return e.slice(0,t).split(`
|
|
8
|
+
`).length}var ot=new Set([`COMPLETE`,`FAILED`,`CANCELLED`,`UNTRACKED`]),st={generation:0,annotationsByDocument:{},toolsByDocument:{},requests:[]};function z(e){let t=[],n=e.trim().replaceAll(`\\`,`/`);for(let e of n.split(`/`))e!==``&&e!==`.`&&(e===`..`?t.pop():t.push(e));return`${n.startsWith(`/`)?`/`:``}${t.join(`/`)}`}function B(e,t){return`${e}\n${z(t)}`}var V=x({documents:{},sessions:{}});function H(e,t){if(e!==null)return V.store.state.documents[B(e,t)]}function U(e){return e===null?st:V.store.state.sessions[e]??st}var ct=Object.freeze({revision:0,stale:!1,candidate:void 0,candidateText:``,annotations:Object.freeze([]),updatedAt:0});function W(e,t,n=V.store.state){if(e===null)return ct;let r=n.documents[B(e,t)],i=n.sessions[e]?.annotationsByDocument[z(t)];return r!==void 0&&i!==void 0&&!i.stale&&i.revision===r.version&&i.sourceSha256===r.sourceSha256?i:ct}function lt(e){V.update(t=>{let n=t.sessions;for(let r of e){let e=z(r.documentPath);if(e===``)continue;let i=n[r.sessionId]??st,a=i.annotationsByDocument[e];if(a!==void 0&&a.updatedAt>=r.collection.updatedAt)continue;let o=t.documents[B(r.sessionId,e)],s=r.collection.stale||o!==void 0&&(o.version!==r.collection.revision||o.sourceSha256!==r.collection.sourceSha256),c=Bt({...r.collection,stale:s});n={...n,[r.sessionId]:{...i,annotationsByDocument:{...i.annotationsByDocument,[e]:c}}}}return n===t.sessions?t:{...t,sessions:n}})}function ut(e,t){let n=z(t.path);if(n===``)throw Error(`Author document path must not be empty`);let r=B(e,n),i=[],a;return V.update(o=>{let s=o.documents[r],c=s?.sourceSha256!==void 0&&t.sourceSha256!==void 0&&s.sourceSha256!==t.sourceSha256,l=c?s.version+1:s?.version??0;a={...t,path:n,annotations:c?[]:s?.annotations??[],revisions:c?[]:s?.revisions??[],saveRequest:s?.saveRequest??0,version:l,savedVersion:c?l:s?.savedVersion??0,...c||s?.crop===void 0?{}:{crop:s.crop}};let u=o.sessions[e],d=o.sessions;if(c&&u!==void 0){let r=u.annotationsByDocument[n];r?.candidate?.thumbnailUrl!==void 0&&i.push(r.candidate.thumbnailUrl),i.push(...(r?.annotations??[]).flatMap(e=>e.thumbnailUrl===void 0?[]:[e.thumbnailUrl]));let a=Date.now(),o=Pt(r,a);d={...d,[e]:{...u,annotationsByDocument:{...u.annotationsByDocument,...o&&{[n]:o}},requests:u.requests.map(e=>t.kind!==`story-preview`&&e.documentPath===n&&[`REQUESTED`,`CHANGING`,`CHANGED`].includes(e.status)?{...e,status:`FAILED`,currentOperation:void 0,error:`The document source changed before the request completed.`,updatedAt:a}:e)}}}return{documents:{...o.documents,[r]:a},sessions:d}}),i.forEach(Vt),a}function dt(e,t){let n=0;return q(e,e=>{n=e.generation+1;let r={path:z(t),generation:n,focusedAt:Date.now()};return{...e,generation:n,focusedDocument:r,focusClaims:[...e.focusClaims??[],r]}}),n}function ft(e,t){q(e,e=>{let n=e.focusClaims??[];if(!n.some(e=>e.generation===t))return e;let r=n.filter(e=>e.generation!==t);return{...e,focusedDocument:r.at(-1),focusClaims:r}})}function pt(e,t,n){let r=z(t),i=U(e).focusedDocument;return i?.path!==r||W(e,r).candidate||!Number.isFinite(n)||n<0||H(e,r)?.kind!==`video`?!1:(G(e,r,`select`),q(e,e=>({...e,videoSeekRequest:{path:r,generation:i.generation,timeSeconds:n,sequence:(e.videoSeekRequest?.sequence??0)+1}})),!0)}function mt(e,t,n){let r=z(t);q(e,e=>{let t={...e.previewSelections};return n===void 0?delete t[r]:t[r]={...n},{...e,previewSelections:t}})}function G(e,t,n){let r=z(t);q(e,e=>({...e,toolsByDocument:{...e.toolsByDocument,[r]:n}}))}function ht(e,t,n){let r=H(e,t);if(r===void 0||z(n.documentPath)!==z(t))throw Error(`The Author selection does not belong to the document.`);if(r.version!==n.revision||r.sourceSha256!==n.sourceSha256)throw Error(`The Author selection is stale for the document.`)}function gt(e,t,n){n!==void 0&&ht(e,t,n);let r=W(e,t).candidate?.thumbnailUrl;It(e,t,e=>({...e,candidate:n&&Mt(n)})),r!==void 0&&r!==n?.thumbnailUrl&&Vt(r)}function _t(e,t,n){if(new TextEncoder().encode(n).byteLength>2048)throw Error(`Author candidate text must not exceed 2 KiB.`);It(e,t,e=>({...e,candidateText:n}))}function vt(e,t,n){let r=W(e,t).candidate;if(r===void 0)throw Error(`Select a document annotation before adding a comment.`);let i=crypto.randomUUID();return yt(e,{...r,id:i,comment:n,version:1}),It(e,t,e=>({...e,candidate:void 0,candidateText:``})),i}function yt(e,t){if(t.comment.trim()===``)throw Error(`Every Author annotation requires a comment.`);ht(e,t.documentPath,t),It(e,t.documentPath,e=>{if(e.annotations.length>=16)throw Error(`Author requests support at most 16 annotations.`);if(e.annotations.some(e=>e.id===t.id))throw Error(`Author annotation '${t.id}' already exists.`);return{...e,annotations:[...e.annotations,Nt({...t,version:t.version??1})]}})}function bt(e,t,n,r){let i;It(e,t,e=>{let t=e.annotations.find(e=>e.id===n);return t===void 0||r!==void 0&&(t.version??1)!==r?e:(i=t.thumbnailUrl,{...e,annotations:e.annotations.filter(e=>e.id!==n)})}),i!==void 0&&Vt(i)}function xt(e,t){if(t.requestText.trim()===``)throw Error(`An Author request requires verbatim request text.`);if(t.regions.length===0||t.regions.some(e=>e.comment.trim()===``))throw Error(`An Author request requires at least one commented region.`);q(e,e=>{if(e.requests.some(e=>e.id===t.id))throw Error(`Author request '${t.id}' already exists.`);return{...e,requests:zt([...e.requests,Rt(t)])}})}function St(e,t,n){q(e,e=>({...e,requests:zt(e.requests.map(e=>e.id===t?Rt(n(e)):e))}))}function Ct(e,t,n){K(e,t,e=>{if(e.content===n)return e;let t=e.version+1;return{...e,content:n,version:t,revisions:[...e.revisions,{revision:t,content:n}]}})}function wt(e,t,n,r){K(e,t,e=>{let t=e.fragments?.find(e=>e.id===n);if(t===void 0||t.text===r)return e;let i=e.version+1;return{...e,fragments:e.fragments?.map(e=>e.id===n?{...e,text:r}:e),version:i,revisions:[...e.revisions,{revision:i,content:r}]}})}function Tt(e,t,n){K(e,t,e=>({...e,annotations:[...e.annotations,n]}))}function Et(e,t,n){K(e,t,e=>{let t=e.version+1;return{...e,...n===void 0?{crop:void 0}:{crop:n},version:t,revisions:[...e.revisions,{revision:t,content:JSON.stringify(n??null)}]}})}function Dt(e,t){K(e,t,e=>({...e,saveRequest:e.saveRequest+1,savingVersion:e.version}))}function Ot(e,t,n){K(e,t,e=>e.savingVersion===n?{...e,savingVersion:void 0}:e)}function kt(e,t,n,r,i){K(e,t,e=>r<e.savedVersion?e:{...e,sourceSha256:n,savedVersion:r,savingVersion:e.savingVersion===r?void 0:e.savingVersion,originalFragments:i?.map(e=>({...e})),...e.version===r?{crop:void 0}:{},revisions:e.revisions.filter(e=>e.revision>r)});let a=Date.now();q(e,e=>({...e,requests:zt(e.requests.map(e=>e.documentPath===z(t)&&e.status===`CHANGED`&&e.revision<=r?{...e,status:`COMPLETE`,currentOperation:void 0,updatedAt:a}:e))}))}function At(e){let t=`${e}\n`,n=V.store.state.sessions[e];for(let e of Object.values(n?.annotationsByDocument??{}))e.candidate?.thumbnailUrl!==void 0&&Vt(e.candidate.thumbnailUrl),e.annotations.forEach(e=>{e.thumbnailUrl!==void 0&&Vt(e.thumbnailUrl)});V.update(n=>{let r={...n.sessions};return delete r[e],{documents:Object.fromEntries(Object.entries(n.documents).filter(([e])=>!e.startsWith(t))),sessions:r}})}function jt(e,t,n){K(e,t,e=>({...e,storyPreview:structuredClone(n)}))}function K(e,t,n){let r=B(e,t),i=[];V.update(t=>{let a=t.documents[r];if(a===void 0)return t;let o=n(a),s=t.sessions[e],c=a.version!==o.version||a.sourceSha256!==o.sourceSha256,l=c?s?.annotationsByDocument[a.path]:void 0,u=l&&Ft(l,a,o),d=u===void 0?l:void 0;d!==void 0&&(d.candidate?.thumbnailUrl!==void 0&&i.push(d.candidate.thumbnailUrl),i.push(...d.annotations.flatMap(e=>e.thumbnailUrl===void 0?[]:[e.thumbnailUrl])));let f=u??(c?Pt(d,Date.now()):void 0),p=c&&s!==void 0?{...t.sessions,[e]:{...s,annotationsByDocument:{...s.annotationsByDocument,...f&&{[a.path]:f}}}}:t.sessions;return{documents:{...t.documents,[r]:o},sessions:p}}),i.forEach(Vt)}function q(e,t){V.update(n=>{let r=n.sessions[e]??st,i=t(r);return i===r?n:{...n,sessions:{...n.sessions,[e]:i}}})}function Mt(e){let t=`rect`in e.anchor?{...e.anchor,rect:{...e.anchor.rect}}:`point`in e.anchor?{...e.anchor,point:{...e.anchor.point}}:{...e.anchor};return{...e,anchor:t,viewport:{...e.viewport},stroke:e.stroke?.map(e=>({...e})),voiceGrid:e.voiceGrid&&{...e.voiceGrid}}}function Nt(e){return Mt(e)}function Pt(e,t){if(e!==void 0)return{...e,stale:!0,candidate:e.candidate&&{...Mt(e.candidate),thumbnailUrl:void 0},annotations:e.annotations.map(e=>({...Nt(e),thumbnailUrl:void 0})),updatedAt:t}}function Ft(e,t,n){if(e.stale||e.revision!==t.version||e.sourceSha256!==t.sourceSha256||t.content===void 0||n.content===void 0||[...e.annotations,...e.candidate?[e.candidate]:[]].some(e=>e.anchor.kind!==`text-range`))return;let r=n.content,i=e=>{let i=e.anchor,{start:a,end:o}=rt(t.content,r,i.startOffset,i.endOffset);return{...Mt(e),revision:n.version,sourceSha256:n.sourceSha256,quote:r.slice(a,o),anchor:{...i,startOffset:a,endOffset:o,startLine:at(r,a),endLine:at(r,o)}}};return{...e,revision:n.version,sourceSha256:n.sourceSha256,candidate:e.candidate&&i(e.candidate),annotations:e.annotations.map(i),updatedAt:Date.now()}}function It(e,t,n){let r=z(t),i=H(e,r);i!==void 0&&q(e,t=>{let a=W(e,r),o=a===ct?{...ct,revision:i.version,sourceSha256:i.sourceSha256}:a,s=n(o);return s===o?t:{...t,annotationsByDocument:{...t.annotationsByDocument,[r]:{...s,stale:!1,updatedAt:Date.now()}}}})}function Lt(e){if(e===void 0)return;let t=new TextEncoder;if(t.encode(e).byteLength<=16384)return e;let n=e.length;for(;n>0&&t.encode(e.slice(0,n)).byteLength>16384;)n-=256;return e.slice(0,n)}function Rt(e){return{...e,before:Lt(e.before),after:Lt(e.after),regions:e.regions.map(Nt),pendingRegions:e.pendingRegions?.map(Nt)}}function zt(e){let t=[...e],n=()=>new TextEncoder().encode(JSON.stringify(t)).byteLength;for(;t.length>100||n()>524288;){let e=t.findIndex(e=>ot.has(e.status));if(e<0)throw Error(`Author request history is full while active requests are still running.`);t.splice(e,1)}return t}function Bt(e){let t=e=>{let t=Mt(e),n=Reflect.get(t,`version`),r=`id`in t?{...t,version:typeof n==`number`?n:1}:t;if(r.thumbnailUrl!==void 0||r.evidence===void 0)return r;try{return{...r,thumbnailUrl:URL.createObjectURL(r.evidence)}}catch{return r}};return{...e,candidate:e.candidate&&t(e.candidate),annotations:e.annotations.map(t)}}function Vt(e){if(e.startsWith(`blob:`))try{URL.revokeObjectURL(e)}catch(e){console.warn(`Author could not release a thumbnail: ${e instanceof Error?e.message:String(e)}`)}}function Ht(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ut(e){return Ht(e)?(e.activation===`active`||e.activation===`inactive`)&&Number.isSafeInteger(e.capabilityCount)&&e.capabilityCount>=0?e:typeof e.kind==`string`?e.kind===`rejected`?typeof e.reason==`string`?e:null:e.kind===`canvases`?Array.isArray(e.canvases)&&e.canvases.every(e=>Ht(e)&&typeof e.alias==`string`&&typeof e.path==`string`)?e:null:!Number.isSafeInteger(e.generation)||typeof e.ownerToken!=`string`?null:e.kind===`accepted`?typeof e.leaseMs==`number`&&(e.catalogToken===void 0||typeof e.catalogToken==`string`)?e:null:(e.kind===`request`||e.kind===`cancel`)&&typeof e.catalogToken==`string`&&typeof e.requestId==`string`&&(e.kind===`cancel`||typeof e.name==`string`&&Ht(e.arguments))?e:null:null:null}var Wt=ae({activation:`inactive`,capabilityCount:0}),Gt=te({channel:_e,parse:Ut,apply(e,t){`activation`in t?Wt.update(e,()=>t):(Be(e,t),Wt.update(e,()=>He(e)))},drop(e){Ye(e),Ve(e),At(e),Wt.drop(e)}});function Kt(e){return e[`po-voice`]?.trimStart().startsWith(`voice auto:`)===!0}function qt({sessionId:e,document:t,visible:n}){let r=k(null);return I(()=>{let i=r.current?.parentElement;if(!n||i==null){Ye(e);return}let a=()=>{let n=i.getBoundingClientRect();qe(e,{documentPath:t.path,revision:t.version,sourceSha256:t.sourceSha256,viewport:{width:n.width,height:n.height,originX:n.left,originY:n.top,scrollX:i.scrollLeft,scrollY:i.scrollTop,zoom:window.devicePixelRatio}})};a();let o=new ResizeObserver(a);return o.observe(i),i.addEventListener(`scroll`,a,{passive:!0,capture:!0}),window.addEventListener(`focus`,a),()=>{o.disconnect(),i.removeEventListener(`scroll`,a,!0),window.removeEventListener(`focus`,a),Ye(e)}},[t.path,t.sourceSha256,t.version,e,n]),n?j(`div`,{ref:r,"data-testid":`author-grid`,"aria-hidden":`true`,className:`pointer-events-none absolute inset-0 z-20 grid grid-cols-8 grid-rows-8`,children:Array.from({length:64},(e,t)=>{let n=t%8,r=Math.floor(t/8);return j(`div`,{className:`relative border border-po-red/25`,children:P(`span`,{className:`absolute left-1 top-0.5 rounded bg-po-deep/80 px-1 text-2xs font-semibold text-po-red`,children:[Ue[n],r+1]})},t)})}):null}var J=new F({}),Jt=new F({}),Yt=new F({}),Xt=(e,t)=>J.state[B(e,t)];function Zt(e){return Array.isArray(e)&&e.length>=2&&e.length<=128&&e.every(e=>typeof e==`object`&&!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&e.x>=0&&e.x<=1&&e.y>=0&&e.y<=1)&&e.some(t=>t.x!==e[0]?.x||t.y!==e[0]?.y)}function Qt(e){if(!Zt(e))return null;let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y)),r=Math.max(...e.map(e=>e.x)),i=Math.max(...e.map(e=>e.y)),a=Math.max(0,Math.min(t,.999)),o=Math.max(0,Math.min(n,.999));return{x:a,y:o,width:Math.min(1-a,Math.max(r-a,.001)),height:Math.min(1-o,Math.max(i-o,.001))}}function $t(e,t){if(!Number.isFinite(t.x)||!Number.isFinite(t.y))return e;let n={x:Math.max(0,Math.min(1,t.x)),y:Math.max(0,Math.min(1,t.y))};if(e.length>=128)return e;let r=e.at(-1);return r?.x===n.x&&r.y===n.y?e:[...e,n]}function en(e,t){let n=e.right-e.left,r=e.bottom-e.top;if(![...Object.values(e),...Object.values(t)].every(Number.isFinite)||n<=0||r<=0)return null;let i=Math.max(e.left,Math.min(t.left,t.right)),a=Math.min(e.right,Math.max(t.left,t.right)),o=Math.max(e.top,Math.min(t.top,t.bottom)),s=Math.min(e.bottom,Math.max(t.top,t.bottom));return a<=i||s<=o?null:{x:(i-e.left)/n,y:(o-e.top)/r,width:(a-i)/n,height:(s-o)/r}}var tn=1600,nn=65536,rn=4096,an=[`#ff5f57`,`#00c2ff`,`#ffd166`,`#b388ff`,`#4ade80`,`#ff8c42`,`#f472b6`,`#2dd4bf`,`#a3e635`,`#60a5fa`,`#e879f9`,`#facc15`,`#34d399`,`#fb7185`,`#818cf8`,`#22d3ee`];function on(e){let t=0;for(let n of e){let e=n.codePointAt(0);t+=e<128?1:e<2048?2:e<65536?3:4}return t}function sn(e){return JSON.parse(JSON.stringify(e))}function cn(e,t){if(on(e)<=t)return e;let n=0,r=e.length;for(;n<r;){let i=Math.ceil((n+r)/2);on(e.slice(0,i))<=t?n=i:r=i-1}return e.slice(0,n)}function ln(e,t,n,r,i){if(r.length===0||r.length>16)throw Error(`Capture requires between 1 and 16 regions.`);if(n.kind===`story-preview`&&n.storyPreview===void 0)throw Error(`Story preview capture requires source provenance.`);let a={version:1,captureId:e,capturedAt:t,document:{path:n.path,...i===void 0?{}:{alias:i},kind:n.kind,revision:n.version,...n.sourceSha256===void 0?{}:{sourceSha256:n.sourceSha256},...n.storyPreview===void 0?{}:{storyPreview:sn(n.storyPreview)},...n.imageArtifact===void 0?{}:{imageArtifact:{...n.imageArtifact}},...n.markdownMedia===void 0?{}:{markdownMedia:{...n.markdownMedia}}},regions:r.map((e,t)=>{if(e.documentPath!==n.path||e.revision!==n.version||e.sourceSha256!==n.sourceSha256)throw Error(`Region ${String(t+1)} is stale for the focused document.`);if(e.stroke!==void 0&&(!Zt(e.stroke)||!(`rect`in e.anchor)||e.mode!==`region`))throw Error(`Region ${String(t+1)} has invalid feedback stroke geometry.`);if(e.comment.trim()===``)throw Error(`Region ${String(t+1)} requires a comment.`);if(on(e.comment)>2048)throw Error(`Region ${String(t+1)} comment exceeds 2 KiB.`);return{id:e.id,ordinal:t+1,comment:e.comment,version:e.version??1,mode:e.mode??(`point`in e.anchor?`point`:`region`),...e.quote===void 0?{}:{quote:cn(e.quote,rn)},anchor:sn(e.anchor),...e.stroke===void 0?{}:{stroke:e.stroke.map(e=>({...e}))},viewport:{...e.viewport},...e.voiceGrid===void 0?{}:{voiceGrid:{...e.voiceGrid}}}})};if(on(JSON.stringify(a))>65536)throw Error(`Author capture packet exceeds 64 KiB.`);return a}function Y(e){return`${String(Math.round(e*1e3)/10)}%`}function un(e){return`x ${Y(e.x)}, y ${Y(e.y)}, w ${Y(e.width)}, h ${Y(e.height)}`}function dn(e,t,n){let r=`Author document: ${e}${t===void 0?``:` (canvas ${t})`}`,i=n.map((e,t)=>`(${t+1}) ${e.comment.slice(0,1e3)} [${fn(e.anchor)}]`);return cn([r,...i.length===0?[]:[`Unsent annotations (not yet submitted):`,...i]].join(`
|
|
9
|
+
`),nn)}function fn(e){switch(e.kind){case`text-range`:return e.startLine===e.endLine?`line ${String(e.startLine)}`:`lines ${String(e.startLine)}-${String(e.endLine)}`;case`cell`:return`${e.sheet===void 0?``:`${e.sheet}!`}${e.location}`;case`slide-element`:return`slide ${String(e.slide)}: ${e.location}`;case`image-rect`:return`image ${un(e.rect)}`;case`pdf-page-rect`:return`page ${String(e.page)}, ${un(e.rect)}`;case`video-time-rect`:return`time ${e.timeSeconds.toFixed(3)}s${e.frame===void 0?``:`, frame ${String(e.frame)}`}, ${un(e.rect)}`;case`story-preview-rect`:return`story preview ${un(e.rect)}`;case`image-point`:return`image point x ${Y(e.point.x)}, y ${Y(e.point.y)}`;case`pdf-page-point`:return`page ${String(e.page)}, point x ${Y(e.point.x)}, y ${Y(e.point.y)}`;case`video-time-point`:return`time ${e.timeSeconds.toFixed(3)}s, point x ${Y(e.point.x)}, y ${Y(e.point.y)}`;case`story-preview-point`:return`story preview point x ${Y(e.point.x)}, y ${Y(e.point.y)}`;case`html-rect`:return`rendered page ${e.element===void 0?``:`${e.element.selector}, `}${un(e.rect)}`;case`html-point`:return`rendered page ${e.element===void 0?``:`${e.element.selector}, `}point x ${Y(e.point.x)}, y ${Y(e.point.y)}`}}function pn(e){let t=e.document.storyPreview;if(t===void 0)return;let n=t.sources.map(e=>`- ${e.path} (sha256 ${e.sha256})`).join(`
|
|
10
|
+
`);return[`Story preview source (edit these sources, never the generated preview artifact):`,`Project: ${t.projectPath}`,`Story: ${t.storyPath}#${t.storyExport}`,`Build revision: ${t.buildRevision}`,`Viewport: ${String(t.viewport.width)}x${String(t.viewport.height)}`,`Sources:`,n,`After editing the underlying story or component source, rebuild the preview before treating it as visually verified.`].join(`
|
|
11
|
+
`)}function mn(e){return e.startsWith(`artifact:`)?`${e} (relative to the session artifact folder)`:e}function hn(e){let t=e.document.markdownMedia;if(t===void 0)return;let n=[t.kind===`mermaid`?`Reviewed a mermaid diagram rendered from Markdown. Change the diagram by editing its source.`:`Reviewed an image shown in rendered Markdown. Change it by editing or regenerating its source file.`];return t.sourcePath!==void 0&&n.push(`Source image: ${mn(t.sourcePath)}`),t.documentPath!==void 0&&n.push(`Embedded in document: ${mn(t.documentPath)}`),t.documentPath===void 0&&t.sourcePath===void 0&&n.push(`Embedded in a conversation message, not a file.`),t.mermaidSource!==void 0&&n.push(`Mermaid source:`,"```mermaid",t.mermaidSource,"```"),n.join(`
|
|
12
|
+
`)}function gn(e){let t=JSON.stringify(e);if(on(t)>65536)throw Error(`Author capture packet exceeds 64 KiB.`);let n=e.regions.map(e=>`(${String(e.ordinal)}) ${e.comment} [${fn(e.anchor)}]\nregionId: ${JSON.stringify(e.id)}${e.quote?`\nQuoted text: ${e.quote}`:``}`).join(`
|
|
13
|
+
|
|
14
|
+
`),r=e.document.imageArtifact,i=r===void 0?hn(e)??pn(e)??(e.document.kind===`html`?`Annotations mark the rendered page. Locations are relative to the visible frame; the selector and quoted text name the marked element. Change the page by editing this HTML source.`:void 0):[`Generated image feedback: preserve the original image; generate a new refinement only when requested.`,`Original artifact: ${r.id} (session ${r.sessionId})`,`Original canonical path: ${r.originalPath}`,`Original SHA-256: ${r.sourceSha256}`,`For imagegen refinement use referenced_image_paths: ${JSON.stringify([r.originalPath])}`].join(`
|
|
15
|
+
`),a=i===void 0?n:`${i}\n\nAnnotations:\n${n}`,o=JSON.stringify({expectedRevision:e.document.revision,expectedSourceSha256:e.document.sourceSha256});return{kind:`author-capture`,source:`author`,id:e.captureId,label:`${e.regions.length} annotation${e.regions.length===1?``:`s`} · ${e.document.path}`,content:`Author document: ${e.document.path}${e.document.alias===void 0?``:` (canvas ${e.document.alias})`}\nMutation fences: ${o}\n${a}`,metadata:t}}function _n(e){let t=Number.parseInt(e.slice(1,3),16),n=Number.parseInt(e.slice(3,5),16),r=Number.parseInt(e.slice(5,7),16);return t*299+n*587+r*114>=15e4?`#101216`:`#ffffff`}function vn(e,t,n){return new Promise((r,i)=>{e.toBlob(e=>e===null?i(Error(`Unable to capture viewport`)):r(e),t,n)})}async function yn(e){let t=new Uint8Array(await e.arrayBuffer()),n=``;for(let e=0;e<t.length;e+=32768)n+=String.fromCharCode(...t.subarray(e,e+32768));return btoa(n)}function bn(e){if(e?.aborted===!0)throw e.reason}async function xn(e){let t=`image/png`,n=await vn(e,t);for(let r of[.9,.75,.6,.45,.3]){if(n.size<=2097152)break;t=`image/jpeg`,n=await vn(e,t,r)}if(n.size>2097152)throw Error(`Viewport capture exceeds 2 MiB`);return{data:await yn(n),mimeType:t}}function Sn(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=()=>n(Error(`Unable to load a region capture.`)),r.src=e})}function Cn(e){return{async capture(t){if(bn(t),e.length===0||e.length>16)throw Error(`Capture requires between 1 and 16 regions.`);let n=[];for(let r of e){let e=r.thumbnailUrl===void 0?void 0:await Sn(r.thumbnailUrl);bn(t);let i=e?.naturalWidth??r.viewport.width,a=e?.naturalHeight??r.viewport.height;if(!Number.isFinite(i)||!Number.isFinite(a)||i<=0||a<=0)throw Error(`Image is not ready to capture`);n.push({region:r,image:e,width:i,height:a})}let r=Math.min(tn,Math.max(...n.map(e=>e.width))),i=n.reduce((e,t)=>e+t.height*r/t.width,0),a=Math.min(1,tn/Math.max(r,i)),o=document.createElement(`canvas`);o.width=Math.max(1,Math.round(r*a)),o.height=Math.max(1,Math.round(i*a));let s=o.getContext(`2d`);if(s===null)throw Error(`Canvas is unavailable`);s.scale(a,a),s.fillStyle=`#101216`,s.fillRect(0,0,r,i);let c=0;for(let[e,{region:i,image:o,width:l,height:u}]of n.entries()){let n=an[e%an.length];bn(t);let d=u*r/l,f=r,p=d,m=c,h=0,g=m;if(o!==void 0){if(s.drawImage(o,0,m,f,p),i.stroke!==void 0){if(!Zt(i.stroke))throw Error(`Invalid feedback stroke geometry.`);s.beginPath(),i.stroke.forEach((e,t)=>{let n=0+e.x*f,r=m+e.y*p;t===0?s.moveTo(n,r):s.lineTo(n,r)}),s.strokeStyle=n,s.lineWidth=Math.max(3,Math.min(f,p)/150),s.lineCap=`round`,s.lineJoin=`round`,s.stroke(),h=0+i.stroke[0].x*f,g=m+i.stroke[0].y*p}else if(`rect`in i.anchor){let e=i.anchor.rect,t=0+e.x*f,r=m+e.y*p,a=e.width*f,o=e.height*p;s.fillStyle=`rgba(8,10,13,0.62)`,s.fillRect(0,m,f,Math.max(0,r-m)),s.fillRect(0,r+o,f,Math.max(0,m+p-r-o)),s.fillRect(0,r,Math.max(0,t-0),o),s.fillRect(t+a,r,Math.max(0,0+f-t-a),o),s.strokeStyle=n,s.lineWidth=3,s.strokeRect(t,r,a,o),h=t,g=r}else if(`point`in i.anchor){let e=0+i.anchor.point.x*f,t=m+i.anchor.point.y*p,r=Math.max(6,Math.min(14,Math.min(f,p)/12));s.beginPath(),s.arc(e,t,r,0,Math.PI*2),s.fillStyle=n,s.fill(),s.strokeStyle=_n(n),s.lineWidth=2,s.stroke(),h=e+r,g=t-r}}let _=String(e+1),v=Math.min(1/a,p/36);s.font=`bold ${String(24*v)}px monospace`;let y=s.measureText(_).width+12*v;y>f&&(v*=f/y),s.font=`bold ${String(24*v)}px monospace`,s.textBaseline=`top`;let b=6*v,x=Math.min(f,s.measureText(_).width+b*2),S=36*v;h=Math.max(0,Math.min(h,0+f-x)),g=Math.max(m,Math.min(g,m+p-S)),s.fillStyle=n,s.fillRect(h,g,x,S),s.fillStyle=_n(n),s.fillText(_,h+b,g+b),c+=d}return bn(t),xn(o)}}}function wn({sessionId:e,path:t,drafts:n}){let[r,i]=E(),a=()=>{try{vt(e,t,n.candidateText),i(void 0)}catch(e){i(e instanceof Error?e.message:String(e))}};if(!n.candidate&&n.annotations.length===0)return null;let o=n.candidate?.mode===`point`?`point`:`region`;return P(`section`,{className:`space-y-2`,"data-testid":`author-region-drafts`,children:[n.candidate?P(m,{children:[P(`h3`,{className:`text-base font-semibold text-po-hi`,children:[`Current `,o]}),P(`p`,{className:`text-base text-po-dim sm:text-sm`,children:[`Add feedback to keep this `,o,` as an unsent annotation.`]}),n.candidate.quote?j(`blockquote`,{className:`line-clamp-3 border-l-2 border-po-edge-magenta pl-2 text-base text-po-text sm:text-sm`,children:n.candidate.quote}):null,n.candidate.anchor.kind===`video-time-rect`||n.candidate.anchor.kind===`video-time-point`?P(`p`,{className:`text-base text-po-dim sm:text-sm`,children:[`Frame at `,n.candidate.anchor.timeSeconds.toFixed(3),`s`]}):null,j(`textarea`,{"aria-label":`Annotation comment`,value:n.candidateText,onChange:n=>_t(e,t,n.target.value),placeholder:`What should change here?`,rows:3,className:`min-h-24 w-full resize-y rounded-md border border-po-border-soft bg-po-panel p-3 text-lg leading-normal text-po-text placeholder:text-po-dim focus:border-po-green focus:outline-none sm:text-base`}),P(`div`,{className:`flex flex-wrap gap-2`,children:[j(L,{className:`min-h-11 min-w-11 text-base [@media(pointer:fine)]:min-h-8 sm:text-sm`,variant:`outline`,onClick:a,disabled:!n.candidate||!n.candidateText.trim()||n.annotations.length>=16,children:`add annotation`}),j(L,{variant:`ghost`,className:`min-h-11 min-w-11 text-base [@media(pointer:fine)]:min-h-8 sm:text-sm`,onClick:()=>{gt(e,t,void 0),_t(e,t,``),i(void 0)},children:`Discard annotation`})]})]}):null,r?j(`output`,{className:`block text-base text-po-red`,children:r}):null,n.annotations.length>0?P(`h3`,{className:`text-sm text-po-dim`,children:[`Unsent annotations (`,n.annotations.length,`)`]}):null,j(`ol`,{className:`space-y-2`,children:n.annotations.map((r,i)=>P(`li`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 rounded-md border border-po-border-soft bg-po-panel py-1 pl-3 pr-1 text-base leading-normal text-po-text`,children:[j(`span`,{"aria-hidden":`true`,className:`flex h-6 min-w-6 shrink-0 items-center justify-center rounded-full bg-po-magenta px-1 text-sm font-semibold text-po-rail`,children:i+1}),P(`span`,{className:`min-w-0 flex-1 break-words py-1`,children:[P(`span`,{className:`sr-only`,children:[`(`,i+1,`) `]}),r.comment,j(`span`,{className:`line-clamp-2 block text-sm text-po-dim`,children:r.quote?`“${r.quote}”`:r.mode===`point`?`Point`:`Region`})]}),r.anchor.kind===`video-time-rect`||r.anchor.kind===`video-time-point`?P(L,{variant:`outline`,className:`min-h-11 min-w-11 text-base [@media(pointer:fine)]:min-h-8 sm:text-sm`,disabled:n.candidate!==void 0,onClick:()=>{(r.anchor.kind===`video-time-rect`||r.anchor.kind===`video-time-point`)&&pt(e,t,r.anchor.timeSeconds)},children:[`Go to `,r.anchor.timeSeconds.toFixed(3),`s`]}):null,j(L,{className:`min-h-11 min-w-11 text-base [@media(pointer:fine)]:min-h-8 sm:text-sm`,variant:`ghost`,"aria-label":`Remove annotation ${i+1}`,onClick:()=>bt(e,t,r.id),children:j(d,{"aria-hidden":`true`,className:`size-4`})})]},r.id))})]})}function Tn({sessionId:e,document:t,drafts:n,submitCapture:r}){let[i,a]=E(),[o,s]=E(!1);return P(`div`,{className:`space-y-3`,children:[j(wn,{sessionId:e,path:t.path,drafts:n}),n.annotations.length>0?j(L,{className:`min-h-11 min-w-11 w-full text-base`,size:`lg`,variant:`primary`,"data-testid":`author-attach-capture`,disabled:o||n.candidate!==void 0||r===void 0,onClick:async()=>{if(!(o||n.candidate||r===void 0)){s(!0),a(`Submitting annotations…`);try{let i=ln(crypto.randomUUID(),Date.now(),t,n.annotations,Xt(e,t.path));await r({...await Cn(n.annotations).capture(),context:gn(i)}),a(`Request submitted. You can keep annotating here.`)}catch(e){a(e instanceof Error?e.message:String(e))}finally{s(!1)}}},children:o?`Submitting…`:`Submit ${n.annotations.length} annotation${n.annotations.length===1?``:`s`}`}):null,r===void 0?j(`output`,{className:`text-sm text-po-red`,children:`Submission unavailable. Reload to update the app.`}):null,i?j(`output`,{className:`block text-sm text-po-dim`,children:i}):null]})}var En={REQUESTED:`Request queued`,CHANGING:`Agent working`,CHANGED:`Change ready`,COMPLETE:`Request completed`,FAILED:`Request failed`,CANCELLED:`Request cancelled`,UNTRACKED:`Sent, not tracked`};function Dn(e){let t=e.search(/(?:^|\s+)Referenced context "/u);return e.slice(0,t<0?void 0:t).replace(/^Please address the attached feedback\.\s*Request ID: \S+\s*/u,``).trim()}function On(e){return e.replaceAll(`\\`,`/`).split(`/`).at(-1)||e}function kn(e){switch(e.kind){case`text-range`:return e.startLine===e.endLine?`Line ${e.startLine}`:`Lines ${e.startLine}–${e.endLine}`;case`cell`:return[e.sheet,e.location].filter(Boolean).join(` · `);case`slide-element`:return`Slide ${e.slide} · ${e.location}`;case`image-rect`:return`Image region`;case`pdf-page-rect`:return`Page ${e.page}`;case`video-time-rect`:return`Video ${Math.floor(e.timeSeconds/60)}:${Math.floor(e.timeSeconds%60).toString().padStart(2,`0`)}`;case`story-preview-rect`:return`${e.preview.storyPath}#${e.preview.storyExport}`;case`image-point`:return`Image point`;case`pdf-page-point`:return`Page ${e.page} point`;case`video-time-point`:return`Video ${Math.floor(e.timeSeconds/60)}:${Math.floor(e.timeSeconds%60).toString().padStart(2,`0`)} point`;case`story-preview-point`:return`${e.preview.storyPath}#${e.preview.storyExport} point`;case`html-rect`:return e.element===void 0?`Page region`:`Page · ${e.element.tag}`;case`html-point`:return e.element===void 0?`Page point`:`Page · ${e.element.tag} point`}}function An(e){let t=e.regions.length,n=e.pendingRegions?.length;return e.status===`CHANGING`&&e.currentOperation===`Agent is working on this request`?`Processing request`:e.status===`CHANGING`&&n!==void 0?`${t-n} of ${t} annotations applied`:e.status===`CHANGED`?`Changes applied · awaiting save`:e.status===`COMPLETE`?`Agent finished processing this request`:e.status===`FAILED`?`Stopped with an error`:e.status===`CANCELLED`?`Stopped before completion`:e.status===`UNTRACKED`?`Sent to the agent · see its session for the outcome`:`${t} annotation${t===1?``:`s`} queued`}var jn={REQUESTED:`border-po-border-soft bg-po-bg text-po-dim`,CHANGING:`border-po-edge-green bg-po-tint-green text-po-green`,CHANGED:`border-po-edge-green bg-po-tint-green text-po-green`,COMPLETE:`border-po-edge-green bg-po-tint-green text-po-green`,FAILED:`border-po-edge-red bg-po-tint-red text-po-red`,CANCELLED:`border-po-border-soft bg-po-bg text-po-dim`,UNTRACKED:`border-po-border-soft bg-po-bg text-po-dim`},Mn={REQUESTED:`neutral`,CHANGING:`ok`,CHANGED:`ok`,COMPLETE:`ok`,FAILED:`error`,CANCELLED:`neutral`,UNTRACKED:`neutral`};function Nn({request:e,prominent:t=!1}){let n=Dn(e.requestText);return P(`article`,{"data-testid":t?`author-active-request`:void 0,className:`space-y-3 rounded-md border border-po-border-soft bg-po-panel p-3`,children:[P(`header`,{className:`flex gap-3 border-b border-po-border-soft pb-3`,children:[j(pe,{"aria-hidden":`true`,className:`mt-1 size-4 shrink-0 text-po-green`}),P(`div`,{className:`min-w-0 flex-1`,children:[j(`p`,{className:`text-lg font-semibold text-po-hi`,children:`Document context`}),j(`p`,{className:`mt-1 truncate text-base font-semibold text-po-hi`,children:On(e.documentPath)}),j(i,{tone:Mn[e.status],className:`mt-2 whitespace-normal`,children:An(e)})]})]}),j(`section`,{"aria-label":`Request locations`,className:`rounded-md border border-po-border-soft bg-po-bg p-3`,children:j(`ol`,{className:`space-y-3`,children:e.regions.map((t,n)=>P(`li`,{className:`space-y-2`,children:[P(`p`,{className:`text-sm font-medium text-po-magenta`,children:[`Where · `,e.regions.length>1?`${n+1} · `:``,On(e.documentPath),` / `,kn(t.anchor),` · rev `,e.revision]}),t.quote?P(`blockquote`,{className:`line-clamp-3 text-base italic leading-relaxed text-po-text`,children:[`“`,t.quote,`”`]}):null,j(`p`,{className:`text-base leading-relaxed text-po-dim`,children:t.comment})]},t.id))})}),P(`section`,{"data-testid":t?`author-operation-card`:void 0,className:`rounded-md border p-3 ${jn[e.status]}`,children:[P(`p`,{className:`text-sm font-semibold`,children:[`●`,` `,e.status===`CHANGING`?`Working`:e.status===`COMPLETE`?`Completed`:e.status===`FAILED`?`Error`:En[e.status]]}),j(`p`,{className:`mt-2 text-base leading-relaxed text-po-hi`,children:e.currentOperation||En[e.status]}),e.error?j(`p`,{className:`mt-2 text-sm leading-relaxed text-po-red`,children:e.error}):null,e.before!==void 0||e.after!==void 0?P(`details`,{className:`mt-2 border-t border-current/20 pt-2 text-base text-po-dim`,children:[j(`summary`,{className:`cursor-pointer select-none`,children:`change preview`}),e.before===void 0?null:P(`pre`,{className:`mt-2 max-h-28 overflow-auto whitespace-pre-wrap break-words font-mono`,children:[`before: `,e.before]}),e.after===void 0?null:P(`pre`,{className:`mt-2 max-h-28 overflow-auto whitespace-pre-wrap break-words font-mono`,children:[`after: `,e.after]})]}):null]}),P(`section`,{className:`space-y-2`,children:[j(`p`,{className:`text-base font-semibold text-po-hi`,children:`Request · how to change`}),j(`div`,{className:`rounded-md border border-po-border-soft bg-po-bg p-3`,children:j(`p`,{className:`whitespace-pre-wrap text-base leading-relaxed text-po-text`,children:n||`No additional instruction.`})})]})]})}function Pn({requests:e}){let t=e.at(-1),n=e.slice(0,-1).reverse();return P(`section`,{"data-testid":`author-request-history`,className:`space-y-3`,children:[j(`h3`,{className:`text-lg font-semibold text-po-hi`,children:`Author`}),t===void 0?j(`p`,{className:`text-sm leading-relaxed text-po-dim`,children:`No requests or changes yet.`}):j(Nn,{request:t,prominent:!0}),n.length>0?P(`details`,{className:`border-t border-po-border-soft pt-3`,"data-testid":`author-earlier-requests`,children:[P(`summary`,{className:`cursor-pointer select-none text-base font-medium text-po-dim`,children:[`Earlier requests (`,n.length,`)`]}),j(`ol`,{className:`mt-3 space-y-5`,children:n.map(e=>j(`li`,{children:j(Nn,{request:e})},e.id))})]}):null]})}function Fn(e,t){return`h-auto min-h-11 min-w-11 flex-col gap-1 rounded-md px-1 py-2 text-base [@media(pointer:fine)]:min-h-8 ${e?t?`border-po-edge-magenta bg-po-tint-magenta font-semibold text-po-magenta hover:text-po-magenta`:`border-po-edge-green bg-po-tint-green font-semibold text-po-green hover:text-po-green`:`border-po-border-soft bg-po-panel text-po-dim`}`}function In({sessionId:e,path:t,kind:n,activeTool:r}){let i=n===`markdown`||n===`text`,a=[...[`image`,`pdf`,`video`,`story-preview`].includes(n)?[{label:`Pan`,glyph:`✋`,action:()=>G(e,t,r===`pan`?`select`:`pan`),active:r===`pan`,annotates:!1}]:[],...[`image`,`pdf`,`video`,`story-preview`,`html`].includes(n)?[{label:`Draw`,glyph:`✎`,action:()=>G(e,t,r===`draw`?`select`:`draw`),active:r===`draw`,annotates:!0}]:[],{label:`Region`,glyph:`⌗`,action:()=>G(e,t,r===`mark`?`select`:`mark`),active:r===`mark`,annotates:!0},{label:`Comment`,glyph:`●`,action:()=>G(e,t,r===`comment`?`select`:`comment`),active:r===`comment`,annotates:!0}];return P(`section`,{"data-testid":`author-tool-palette`,className:`space-y-2`,children:[j(`h3`,{className:`sr-only`,children:`Tools`}),j(`div`,{className:`grid grid-cols-4 gap-1.5`,children:a.map(e=>P(L,{size:`md`,variant:`outline`,"aria-label":e.label===`Region`?`mark region`:e.label,"aria-pressed":e.active,onClick:e.action,className:Fn(e.active===!0,e.annotates===!0),children:[j(`span`,{"aria-hidden":`true`,className:`text-lg leading-none`,children:e.glyph}),j(`span`,{className:`text-sm`,children:e.label})]},e.label))}),j(`p`,{className:`text-base leading-normal text-po-dim sm:text-sm`,children:r===`draw`?`Draw a location mark, then enter feedback text. Marks never edit the source.`:r===`pan`?P(m,{children:[j(`span`,{className:`[@media(pointer:coarse)]:hidden`,children:`Drag to pan; pinch to zoom. Use Fit to reset the view.`}),j(`span`,{className:`hidden [@media(pointer:coarse)]:inline`,children:`Pinch to zoom. Drag to move. Double-tap to reset.`})]}):r===`mark`?i?`Drag over the passage you want to mark. Choose Region again to stop.`:`Drag over the document to mark a region.`:r===`comment`?i?`Click a paragraph or line to comment on it. Choose Comment again to stop.`:`Click the document to place a comment pin.`:i?`Select text to comment on it, or choose Region or Comment.`:`Choose Region to drag an area, or Comment to place a point.`})]})}function Ln({sessionId:e,submitCapture:t,statuses:n,renderSlot:r,renderSessionActivity:i}){let a=D(V.store,t=>{if(e===null)return[];let n=`${e}\n`;return Object.entries(t.documents).filter(([e])=>e.startsWith(n)).map(([,e])=>e)}),o=D(V.store,t=>e===null?void 0:t.sessions[e]),s=D(Ke.store,t=>e===null?void 0:t.sessions[e]),c=a.find(e=>e.path===o?.focusedDocument?.path),l=o?.focusedDocument?.path,u=(o?.requests??[]).filter(e=>l===void 0||e.documentPath===l),d=D(V.store,t=>W(e,l??``,t)),f=e!==null&&l!==void 0&&u.some(e=>e.status===`REQUESTED`||e.status===`CHANGING`)?i?.()??null:null;return P(`section`,{"data-testid":`author-panel`,className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[j(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-3`,children:P(`div`,{className:`flex flex-col gap-3`,children:[j(`div`,{"data-testid":`author-preview-providers`,className:`empty:hidden`,children:r(`author.preview-provider`)}),e!==null&&o!==void 0&&c!==void 0?P(m,{children:[j(In,{sessionId:e,path:c.path,kind:c.kind,activeTool:o.toolsByDocument[z(c.path)]??`select`}),j(`h2`,{className:`border-t border-po-border-soft pt-3 text-lg font-semibold text-po-hi`,children:`Annotations`}),P(`p`,{className:`text-base leading-normal text-po-dim sm:text-sm`,children:[c.kind===`markdown`||c.kind===`text`?`Select text or mark a passage, add feedback, then submit here.`:`Drag a region or place a point, add feedback, then submit here.`,` `,`Requests queue while the agent is working.`]}),c.kind===`video`?j(`p`,{className:`text-base text-po-dim sm:text-sm`,children:`Annotations reference video frames. They do not save changes to the source video.`}):null,Kt(n)&&s!==void 0?P(`div`,{"data-testid":`author-grid-snapshot`,className:`rounded border border-po-red/40 bg-po-red/5 p-2 text-base text-po-dim`,children:[j(`strong`,{className:`text-po-red`,children:`VOICE GRID A1–H8`}),P(`p`,{className:`mt-1 truncate`,children:[`token `,s.geometryToken]})]}):null,j(`div`,{className:`max-sm:hidden`,children:j(Tn,{sessionId:e,document:c,drafts:d,submitCapture:t},c.path)})]}):null,j(`div`,{className:c===void 0?void 0:`border-t border-po-border-soft pt-3`,children:j(Pn,{requests:u})})]})}),f===null?null:j(`footer`,{"data-testid":`author-session-activity`,className:`shrink-0 border-t border-po-border bg-po-rail p-3`,children:f})]})}var Rn=h({id:`authoring`,label:`Author`,icon:he,order:30,panel:Ln,visibility:{subscribe(e){let t=V.store.subscribe(e);return()=>t.unsubscribe()},isVisible(e){return e!==null&&V.store.state.sessions[e]?.focusedDocument!==void 0}}}),zn=se({state:{method:`GET`,path:`/state`,response:S()},bridgeRegister:{method:`POST`,path:`/bridge/register`},bridgeCatalog:{method:`POST`,path:`/bridge/catalog`},bridgeNext:{method:`POST`,path:`/bridge/next`},bridgeResult:{method:`POST`,path:`/bridge/result`},bridgeCancelled:{method:`POST`,path:`/bridge/cancelled`},bridgeDisconnect:{method:`POST`,path:`/bridge/disconnect`},bridgeClose:{method:`POST`,path:`/bridge/close`},bridgeDescribe:{method:`GET`,path:`/bridge/describe`,query:[`alias`]},bridgeInvoke:{method:`POST`,path:`/bridge/invoke`},documentsOpen:{method:`POST`,path:`/documents/open`,query:[`session`],response:S()},documentsPreflight:{method:`POST`,path:`/documents/preflight`,query:[`session`],response:S()},documentsSerialize:{method:`POST`,path:`/documents/serialize`,query:[`session`],response:S()},file:{method:`GET`,path:`/file`,query:[`path`],raw:!0},fileWrite:{method:`PUT`,path:`/file`,query:[`path`],raw:!0}}),Bn=le(zn,{scopes:[`session`],basePath:`author`,transport:(e,t)=>A.fetch(e,t),sessionAddress:n}),Vn=`author-file-`,Hn=`artifact:`;function Un(e){if(typeof e!=`object`||!e)return null;let t=e;return t.watchFocusedPath!==void 0&&typeof t.watchFocusedPath!=`function`||t.createImageTab!==void 0&&typeof t.createImageTab!=`function`?null:t.version===1&&typeof t.createTab==`function`?t:null}function Wn(e){if(typeof e!=`object`||!e)return null;let t=e;return t.version!==1||typeof t.label!=`string`||t.label.trim()===``||t.detail!==void 0&&typeof t.detail!=`string`||typeof t.createTab!=`function`||t.supportsSource!==void 0&&typeof t.supportsSource!=`function`||t.embeddedPanel!==void 0&&typeof t.embeddedPanel!=`function`?null:t}var Gn={slot:`author.preview-action`,description:`Offer preview launchers or embedded preview panels for Author's focused source.`,parse:Wn},Kn=`session`;async function qn(e,t,n,r,i,a){if(n.startsWith(`artifact:`))throw Error(`Artifacts are read-only.`);if(!/^[a-f0-9]{64}$/.test(i))throw Error(`This Author view has no valid source digest.`);let o=await e(t,{method:`PUT`,headers:{"Content-Type":`application/octet-stream`,"X-Expected-SHA256":i},body:r,signal:a});if(o.status===409)throw Error(`This file changed elsewhere. Keep your edits and reopen it before saving.`);if(!o.ok)throw Error(`Author save failed (${String(o.status)})`);let s=o.headers.get(`X-File-SHA256`);if(s===null||!/^[a-f0-9]{64}$/.test(s))throw Error(`Author save returned an invalid digest.`);return s}var Jn=new Set([`avif`,`bmp`,`gif`,`jpeg`,`jpg`,`png`,`svg`,`webp`]),Yn=new Set([`m4v`,`mov`,`mp4`,`webm`]);function Xn(e){let t=e.toLowerCase();if(t.endsWith(`.slides.md`))return`markdown-slides`;if(t.endsWith(`.csv`))return`csv`;if(t.endsWith(`.pptx`))return`pptx`;if(t.endsWith(`.xlsx`))return`xlsx`}function Zn(e){return/\.(?:mmd|mermaid)$/iu.test(e)}function Qn(e){let t=e.toLowerCase();if(/\.stories\.(?:js|jsx|ts|tsx)$/u.test(t))return`story-preview`;let n=Xn(e);if(n===`markdown-slides`)return`slides`;if(n!==void 0)return n;let r=t.split(`.`).at(-1)??``;return r===`md`||Zn(t)?`markdown`:Jn.has(r)?`image`:Yn.has(r)?`video`:r===`pdf`?`pdf`:r===`html`||r===`htm`?`html`:[`txt`,`json`,`yaml`,`yml`,`xml`,`css`,`js`,`ts`,`tsx`,`jsx`].includes(r)?`text`:`opaque`}function $n(e,t){return t.startsWith(`artifact:`)?nr.session(e).content.url({query:{path:t.slice(9)}}):Bn.session(e).file.url({query:{path:t}})}function er(e,t){let n=e.startsWith(Hn),r=n?e.slice(9):e;if(t.startsWith(`/`)){if(n)throw Error(`Artifact images must use a relative path.`);return t}let i=r.split(`/`).slice(0,-1);for(let e of t.split(`/`))if(e!==``&&e!==`.`){if(e!==`..`)i.push(e);else if(i.length===0||i.at(-1)===``)throw Error(`The image is outside this folder.`);else i.pop()}return`${n?Hn:``}${i.join(`/`)}`}function tr(e){let t=e.startsWith(`artifact:`)?e.slice(9):e;return t.split(`/`).at(-1)??t}var nr=le({content:{method:`GET`,path:`/content`,query:[`path`],raw:!0}},{scopes:[`session`],basePath:`artifacts`,transport:(e,t)=>A.fetch(e,t),sessionAddress:n});async function rr(e,t,n,r){let i=await e({body:n,query:{[Kn]:t},...r===void 0?{}:{signal:r}});if(!i.ok)throw Error(i.error===``?`Author document API failed (${i.status})`:i.error);return i.data}async function ir(e,t,n){let r=Qn(t),i=$n(e,t),a=await A.fetch(i,{signal:n});if(!a.ok)throw Error(`Author could not open ${t} (${a.status})`);let o=a.headers.get(`X-File-SHA256`)??void 0,s=Xn(t);if(s!==void 0){let i=await rr(Bn.session(e).documentsOpen,e,{path:t,format:s},n);if(!(`fragments`in i)||!Array.isArray(i.fragments))throw Error(`Author returned an invalid structured document.`);let a=i.manifest?.sourceDigest;if(o!==void 0&&a!==void 0&&o!==a)throw Error(`Document source changed while opening. Reopen the document.`);let c=s===`csv`?dr(i.manifest?.metadata):void 0;return{path:t,kind:r,title:tr(t),structuredFormat:s,fragments:i.fragments,...c===void 0?{}:{csvDialect:c},originalFragments:i.fragments.map(e=>({...e})),...o===void 0?{}:{sourceSha256:o}}}let c=r===`image`||r===`video`||r===`pdf`||r===`opaque`?i:void 0,l=r===`text`||r===`markdown`||r===`story-preview`||r===`html`?await a.text():void 0;return{path:t,kind:r,title:tr(t),...l===void 0?{}:{content:l},...c===void 0?{}:{mediaUrl:c},...o===void 0?{}:{sourceSha256:o}}}function ar(e){let t=new Map((e.originalFragments??[]).map(e=>[e.id,e.text]));return(e.fragments??[]).filter(e=>!e.readOnly&&t.get(e.id)!==e.text).map(e=>({fragmentId:e.id,replacement:e.text}))}function or(e){if(!/^(?:[A-Za-z\d+/]{4})*(?:[A-Za-z\d+/]{2}==|[A-Za-z\d+/]{3}=)?$/.test(e))throw Error(`Invalid serialized document bytes.`);let t=atob(e);return Uint8Array.from(t,e=>e.charCodeAt(0))}function sr(e){let t=e.split(`.`).at(-1)?.toLowerCase();if(t===`png`)return`image/png`;if(t===`jpg`||t===`jpeg`)return`image/jpeg`;if(t===`webp`)return`image/webp`}async function cr(e,t){let{crop:n,mediaUrl:r}=e;if(n===void 0||r===void 0)throw Error(`This Author image has no crop source.`);let i=sr(e.path);if(i===void 0)throw Error(`This image format cannot preserve its encoding after crop.`);let a=await A.fetch(r,{signal:t,cache:`no-store`});if(!a.ok)throw Error(`Author could not read the image before saving (${a.status})`);let o=await createImageBitmap(await a.blob());try{let e=Math.round(n.x*o.width),t=Math.round(n.y*o.height),r=Math.max(1,Math.round(n.width*o.width)),a=Math.max(1,Math.round(n.height*o.height)),s=window.document.createElement(`canvas`);s.width=r,s.height=a;let c=s.getContext(`2d`);if(c===null)throw Error(`Canvas is unavailable for image crop.`);c.drawImage(o,e,t,r,a,0,0,r,a);let l=await new Promise(e=>s.toBlob(e,i));if(l===null||l.type!==i)throw Error(`The browser cannot encode this cropped image format.`);return l}finally{o.close()}}async function lr(e,t,n){if(t.kind===`text`||t.kind===`markdown`||t.kind===`story-preview`||t.kind===`html`)return t.content??``;if(t.kind===`image`&&t.crop!==void 0)return await cr(t,n);if(t.structuredFormat===void 0)throw Error(`This Author view cannot be saved.`);let r=ar(t),i={path:t.path,format:t.structuredFormat,operations:r,...t.csvDialect===void 0?{}:{csvDialect:t.csvDialect}},a=await rr(Bn.session(e).documentsPreflight,e,i,n);if(a.sourceDigest!==void 0&&a.sourceDigest!==t.sourceSha256)throw Error(`Document source changed before saving. Reopen the document.`);if(!a.accepted)throw Error(a.issues.map(e=>e.message).join(`
|
|
16
|
+
`)||`Author preflight rejected the edit.`);let o=await rr(Bn.session(e).documentsSerialize,e,{...i,preflightDigest:a.digest},n);if(o.encoding!==`base64`)throw Error(`Author serialize returned an unsupported encoding.`);let s=or(o.bytes);return s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength)}async function ur(e,t,n){if(t.path.startsWith(`artifact:`))throw Error(`Artifacts are read-only.`);if(t.sourceSha256===void 0)throw Error(`This Author view has no source digest.`);return await qn((e,t)=>A.fetch(e,t),Bn.session(e).fileWrite.url({query:{path:t.path}}),t.path,await lr(e,t,n),t.sourceSha256,n)}function dr(e){if(e===void 0)return;let{delimiter:t,quote:n,recordDelimiter:r}=e;if(t!==`,`&&t!==`;`&&t!==` `&&t!==`|`||n!==`"`&&n!==`'`||r!==`
|
|
17
|
+
`&&r!==`\r
|
|
18
|
+
`)throw Error(`Author document API returned an invalid CSV dialect.`);return{delimiter:t,quote:n,recordDelimiter:r}}var fr={type:`string`,minLength:1};function pr(e){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Expected an object.`);return e}function mr(e,t){if(typeof e[t]!=`string`||e[t]===``)throw Error(`${t} must be a non-empty string.`);return e[t]}function hr(e,t,n,r){if(H(e,t)===void 0)throw Error(`STALE_DOCUMENT: The focused Author document is no longer open.`);if(n===`pdf`||n===`video`||n===`opaque`)throw Error(`UNSUPPORTED_GRID: PDF and video coordinates are capture-only and require a visible native selection.`);return Ze(e,r)}function gr(e,t,n){let r=H(e,t);if(r===void 0)throw Error(`STALE_DOCUMENT: The Author document is no longer open.`);if(r.savingVersion!==void 0)throw Error(`SAVE_IN_PROGRESS: Wait for the current Author save to finish.`);let i=n.expectedRevision,a=mr(n,`expectedSourceSha256`);if(i!==r.version||a!==r.sourceSha256)throw Error(`STALE_DOCUMENT: The Author revision or source digest changed.`);let o=mr(n,`regionId`),s=U(e),c=W(e,t)?.annotations.find(e=>e.id===o)??s.requests.filter(e=>e.documentPath===t&&(e.status===`REQUESTED`||e.status===`CHANGING`)).flatMap(e=>e.pendingRegions??e.regions).find(e=>e.id===o);if(c===void 0||c.documentPath!==t)throw Error(`STALE_REGION: The resolved Author region is unavailable.`);if(c.stroke!==void 0)throw Error(`UNSUPPORTED_REGION: Freehand feedback cannot authorize a document mutation.`);if(c.revision!==r.version||c.sourceSha256!==r.sourceSha256)throw Error(`STALE_REGION: The resolved Author region no longer matches the document.`);return{document:r,region:c}}function _r(e,t,n){return[{name:`author_describe_grid`,label:`Describe grid`,description:`Describe the current A1 through H8 grid and return its geometry token.`,inputSchema:{type:`object`,additionalProperties:!1,properties:{}},execute:async()=>{let n=Je(e),r=H(e,t);if(n===void 0||r===void 0||n.documentPath!==t||n.revision!==r.version)throw Error(`STALE_GRID: The visible Author grid is unavailable.`);return{columns:`A-H`,rows:`1-8`,...n}}},{name:`author_resolve_grid_cell`,label:`Resolve grid cell`,description:`Resolve one current grid cell to a native document anchor before mutation.`,inputSchema:{type:`object`,additionalProperties:!1,required:[`cell`,`geometryToken`,`instruction`],properties:{cell:fr,geometryToken:fr,instruction:fr}},execute:async r=>{let i=pr(r),a=mr(i,`instruction`),o=Qe(e,mr(i,`cell`),mr(i,`geometryToken`)),s=Je(e),c=hr(e,t,n,o),l=crypto.randomUUID(),u=Date.now(),d={id:l,documentPath:t,revision:s.revision,sourceSha256:s.sourceSha256,comment:a,...c,viewport:{...s.viewport},voiceGrid:o.evidence,createdAt:u};return yt(e,d),xt(e,{id:`voice:${l}`,documentPath:t,requestText:a,regions:[d],pendingRegions:[d],status:`REQUESTED`,createdAt:u,updatedAt:u,revision:s.revision,sourceSha256:s.sourceSha256}),{regionId:l,anchor:c.anchor,quote:c.quote,evidence:o.evidence}}}]}function vr(e,t){let n=e.filter(e=>e.id!==t.id);if(t.anchor.kind===`image-rect`&&n.length>0)throw Error(`UNSUPPORTED_REGION: A multi-region image request cannot apply more than one crop.`);if(t.anchor.kind===`text-range`){for(let e of n)if(e.anchor.kind===`text-range`&&!(e.anchor.endOffset<=t.anchor.startOffset||e.anchor.startOffset>=t.anchor.endOffset))throw Error(`AMBIGUOUS_REGION: Submitted text regions overlap and cannot be safely rebased.`)}}function yr(e,t){return e.slice(0,Math.max(0,t)).split(`
|
|
19
|
+
`).length}function br(e,t,n,r){return e.filter(e=>e.id!==t.id).map(e=>{if(t.anchor.kind!==`text-range`||e.anchor.kind!==`text-range`||r===void 0)return{...e,revision:n.revision};let i=(n.after?.length??0)-(n.before?.length??0),a=e.anchor.startOffset>=t.anchor.endOffset?i:0,o=e.anchor.startOffset+a,s=e.anchor.endOffset+a;return{...e,revision:n.revision,anchor:{...e.anchor,startOffset:o,endOffset:s,startLine:yr(r,o),endLine:yr(r,s)}}})}function xr(e,t,n){if(n===`pdf`||n===`video`||n===`opaque`)return;let r=n!==`image`;return{name:`author_apply_region`,label:`Apply region change`,description:`Apply a fenced mutation through a previously resolved native Author region.`,inputSchema:{type:`object`,additionalProperties:!1,required:[`regionId`,`expectedRevision`,`expectedSourceSha256`,...r?[`replacement`]:[]],properties:{regionId:fr,expectedRevision:{type:`integer`,minimum:0},expectedSourceSha256:fr,...r?{replacement:{type:`string`}}:{}}},execute:async(n,r)=>{let i=pr(n),a=mr(i,`regionId`),o=U(e).requests.find(e=>e.documentPath===t&&e.status===`REQUESTED`&&(e.pendingRegions??e.regions).some(e=>e.id===a));o!==void 0&&St(e,o.id,e=>({...e,status:`CHANGING`,currentOperation:`validating native anchor`,updatedAt:Date.now()}));try{if(r.aborted)throw r.reason instanceof Error?r.reason:Error(`Author mutation cancelled.`);let{document:n,region:a}=gr(e,t,i),s=o?.pendingRegions??o?.regions??[a];vr(s,a),o!==void 0&&St(e,o.id,e=>({...e,currentOperation:`mutating ${a.anchor.kind}`,updatedAt:Date.now()}));let c,l;if(a.anchor.kind===`text-range`){let r=typeof i.replacement==`string`?i.replacement:``,{startOffset:o,endOffset:s}=a.anchor,u=n.content??``,d=u.slice(o,s);l=u.slice(0,o)+r+u.slice(s),Ct(e,t,l),c={changed:!0,before:d,after:r,revision:n.version+1}}else if(a.anchor.kind===`cell`||a.anchor.kind===`slide-element`){let r=a.anchor.fragmentId,o=n.fragments?.find(e=>e.id===r);if(o===void 0||o.readOnly===!0)throw Error(`UNSUPPORTED_REGION: The native fragment is not editable.`);let s=typeof i.replacement==`string`?i.replacement:``;wt(e,t,o.id,s),c={changed:!0,before:o.text,after:s,revision:n.version+1}}else if(a.anchor.kind===`image-rect`)Et(e,t,a.anchor.rect),c={changed:!0,crop:a.anchor.rect,revision:n.version+1};else throw Error(`UNSUPPORTED_REGION: PDF, video and rendered HTML regions are capture-only.`);if(bt(e,t,a.id),o!==void 0){let t=br(s,a,c,l);St(e,o.id,e=>({...e,status:t.length===0?`CHANGED`:`REQUESTED`,currentOperation:void 0,before:[e.before,c.before].filter(e=>e!==void 0).join(`
|
|
20
|
+
`)||void 0,after:[e.after,c.after??(c.crop===void 0?void 0:JSON.stringify(c.crop))].filter(e=>e!==void 0).join(`
|
|
21
|
+
`)||void 0,pendingRegions:t,revision:c.revision,updatedAt:Date.now()}))}return c}catch(t){throw o!==void 0&&St(e,o.id,e=>({...e,status:r.aborted?`CANCELLED`:`FAILED`,currentOperation:void 0,error:r.aborted?`Author mutation cancelled.`:t instanceof Error?t.message:String(t),updatedAt:Date.now()})),t}}}}function Sr(e,t,n){let r=xr(e,t,n);return[..._r(e,t,n),...r===void 0?[]:[r]]}function Cr(e){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Expected an object`);return e}function wr(e,t){if(typeof e!=`string`)throw Error(`${t} must be a string`);return e}function Tr(e){let t=Cr(e);return{sessionId:wr(t.sessionId,`sessionId`),path:wr(t.path,`path`),value:t}}var Er={sessionId:{type:`string`,minLength:1},path:{type:`string`,minLength:1}},Dr={id:ye.text,tools:[{name:`author_add_comment`,label:`Add comment`,description:`Add a local review comment to one open Author document.`,inputSchema:{type:`object`,additionalProperties:!1,required:[`sessionId`,`path`,`body`],properties:{...Er,body:{type:`string`},quote:{type:`string`}}},execute:async e=>{let{sessionId:t,path:n,value:r}=Tr(e),i=wr(r.body,`body`);return Tt(t,n,{id:`${Date.now()}:${i.length}`,kind:`comment`,body:i,...typeof r.quote==`string`?{quote:r.quote}:{}}),{added:!0}}},{name:`author_add_highlight`,label:`Add highlight`,description:`Highlight a line range in one open Author text document.`,inputSchema:{type:`object`,additionalProperties:!1,required:[`sessionId`,`path`,`startLine`,`endLine`],properties:{...Er,startLine:{type:`integer`,minimum:1},endLine:{type:`integer`,minimum:1}}},execute:async e=>{let{sessionId:t,path:n,value:r}=Tr(e);if(!Number.isSafeInteger(r.startLine)||!Number.isSafeInteger(r.endLine))throw Error(`Highlight lines must be integers`);let i=r.startLine,a=r.endLine;if(i<1||a<i)throw Error(`Invalid highlight range`);return Tt(t,n,{id:`${Date.now()}:${i}:${a}`,kind:`highlight`,body:``,startLine:i,endLine:a}),{added:!0}}}]},Or={id:ye.media,tools:[]};function kr(e,t,n){return{id:e.id,tools:e.tools.map(e=>{let r=e.inputSchema,{sessionId:i,path:a,...o}=Cr(r.properties),s=Array.isArray(r.required)?r.required.filter(e=>e!==`sessionId`&&e!==`path`):[];return{...e,inputSchema:{...r,properties:o,required:s},execute:async(r,i)=>await e.execute({...Cr(r),sessionId:t,path:n},i)}})}}function Ar(e,t,n){let r=n===`image`?[kr(Or,e,t)]:n===`text`||n===`markdown`||n===`html`?[kr(Dr,e,t)]:[],i=Sr(e,t,n);return i.length===0?r:r.length===0?[{id:ye.media,tools:i}]:[{...r[0],tools:[...r[0].tools,...i]}]}var jr=`po-author-html:`,Mr=512,Nr=600,Pr=/^(?:[a-z][a-z\d+.-]*:|\/\/|#)/iu,Fr=/url\(\s*(['"]?)([^'")]+)\1\s*\)/gu,Ir=`(() => {
|
|
22
|
+
const prefix = ${JSON.stringify(jr)};
|
|
23
|
+
const post = (message) => parent.postMessage(message, '*');
|
|
24
|
+
const view = () => ({ scrollX, scrollY, width: innerWidth, height: innerHeight });
|
|
25
|
+
const report = () => post({ type: prefix + 'view', ...view() });
|
|
26
|
+
addEventListener('scroll', report, { passive: true, capture: true });
|
|
27
|
+
addEventListener('resize', report);
|
|
28
|
+
addEventListener('load', report);
|
|
29
|
+
const selector = (element) => {
|
|
30
|
+
const parts = [];
|
|
31
|
+
for (let node = element; node && node.nodeType === 1 && parts.length < 6; node = node.parentElement) {
|
|
32
|
+
const tag = node.tagName.toLowerCase();
|
|
33
|
+
if (node.id) { parts.unshift(tag + '#' + CSS.escape(node.id)); break; }
|
|
34
|
+
const siblings = node.parentElement ? [...node.parentElement.children].filter((child) => child.tagName === node.tagName) : [];
|
|
35
|
+
parts.unshift(siblings.length > 1 ? tag + ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')' : tag);
|
|
36
|
+
if (tag === 'body') break;
|
|
37
|
+
}
|
|
38
|
+
return parts.join(' > ');
|
|
39
|
+
};
|
|
40
|
+
const pick = (rect) => {
|
|
41
|
+
let element = document.elementFromPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
|
|
42
|
+
if (rect.width > 0 && rect.height > 0) {
|
|
43
|
+
while (element && element.parentElement && element !== document.body) {
|
|
44
|
+
const box = element.getBoundingClientRect();
|
|
45
|
+
if (box.left <= rect.x + 1 && box.top <= rect.y + 1 && box.right >= rect.x + rect.width - 1 && box.bottom >= rect.y + rect.height - 1) break;
|
|
46
|
+
element = element.parentElement;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return element;
|
|
50
|
+
};
|
|
51
|
+
const capture = async () => {
|
|
52
|
+
const width = innerWidth;
|
|
53
|
+
const height = innerHeight;
|
|
54
|
+
const root = document.documentElement;
|
|
55
|
+
const clone = root.cloneNode(true);
|
|
56
|
+
clone.querySelectorAll('script').forEach((script) => script.remove());
|
|
57
|
+
const markup = new XMLSerializer().serializeToString(clone);
|
|
58
|
+
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="' + width + '" height="' + height + '">' +
|
|
59
|
+
'<foreignObject x="' + -scrollX + '" y="' + -scrollY + '" width="' + Math.max(width, root.scrollWidth) + '" height="' + Math.max(height, root.scrollHeight) + '">' +
|
|
60
|
+
markup + '</foreignObject></svg>';
|
|
61
|
+
const image = new Image();
|
|
62
|
+
image.src = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg);
|
|
63
|
+
await image.decode();
|
|
64
|
+
const scale = Math.min(1, 1600 / Math.max(width, height));
|
|
65
|
+
const canvas = document.createElement('canvas');
|
|
66
|
+
canvas.width = Math.max(1, Math.round(width * scale));
|
|
67
|
+
canvas.height = Math.max(1, Math.round(height * scale));
|
|
68
|
+
const context = canvas.getContext('2d');
|
|
69
|
+
context.fillStyle = getComputedStyle(document.body).backgroundColor || '#ffffff';
|
|
70
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
71
|
+
context.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
72
|
+
return canvas.toDataURL('image/png');
|
|
73
|
+
};
|
|
74
|
+
addEventListener('message', async (event) => {
|
|
75
|
+
const data = event.data;
|
|
76
|
+
if (event.source !== parent || !data || data.type !== prefix + 'inspect') return;
|
|
77
|
+
const element = pick(data.rect);
|
|
78
|
+
let image;
|
|
79
|
+
try { image = await capture(); } catch {}
|
|
80
|
+
post({
|
|
81
|
+
type: prefix + 'inspected',
|
|
82
|
+
id: data.id,
|
|
83
|
+
view: view(),
|
|
84
|
+
element: element ? { selector: selector(element), tag: element.tagName.toLowerCase() } : undefined,
|
|
85
|
+
quote: element ? (element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim() : undefined,
|
|
86
|
+
image,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
})();`;function Lr(e){return typeof e==`number`&&Number.isFinite(e)}function Rr(e){if(typeof e!=`object`||!e)return;let{scrollX:t,scrollY:n,width:r,height:i}=e;if(!(!Lr(t)||!Lr(n)||!Lr(r)||!Lr(i)||r<=0||i<=0))return{scrollX:t,scrollY:n,width:r,height:i}}function zr(e){if(typeof e!=`object`||!e)return;let t=e;if(t.type===`${jr}view`){let e=Rr(t);return e===void 0?void 0:{type:`view`,...e}}if(t.type!==`${jr}inspected`||!Lr(t.id))return;let n=Rr(t.view);if(n===void 0)return;let r=typeof t.element==`object`&&t.element!==null&&typeof t.element.selector==`string`&&typeof t.element.tag==`string`?{selector:t.element.selector.slice(0,Mr),tag:t.element.tag.slice(0,64)}:void 0,i=typeof t.quote==`string`&&t.quote!==``?t.quote.slice(0,Nr):void 0,a=typeof t.image==`string`&&t.image.length<=4194304&&/^data:image\/png;base64,[A-Za-z\d+/]+=*$/u.test(t.image)?t.image:void 0;return{type:`inspected`,id:t.id,view:n,...r===void 0?{}:{element:r},...i===void 0?{}:{quote:i},...a===void 0?{}:{image:a}}}function Br(e,t){return{type:`${jr}inspect`,id:e,rect:t}}function Vr(e){let t=atob(e.slice(e.indexOf(`,`)+1));return new Blob([Uint8Array.from(t,e=>e.charCodeAt(0))],{type:`image/png`})}function Hr(e,t){let n=t.trim();if(n===``||Pr.test(n))return;let r=n.split(/[?#]/u)[0];if(r!==``)try{return er(e,decodeURIComponent(r))}catch{return}}async function Ur(e){let t=new Uint8Array(await e.arrayBuffer()),n=``;for(let e=0;e<t.length;e+=32768)n+=String.fromCharCode(...t.subarray(e,e+32768));return`data:${e.type||`application/octet-stream`};base64,${btoa(n)}`}function Wr(e,t){let n=new Map,r=[],i=0,a=a=>{let o=n.get(a);return o===void 0&&(o=Promise.resolve().then(()=>A.fetch($n(e,a),{signal:t,cache:`no-store`})).then(async e=>{if(!e.ok)return;let t=await e.blob();if(!(t.size>8388608||i+t.size>25165824))return i+=t.size,t}).catch(()=>{t.throwIfAborted()}),n.set(a,o)),o.then(e=>(e===void 0&&!r.includes(a)&&r.push(a),e))};return{load:a,inlineCss:async(e,t)=>(await Promise.all([...e.matchAll(Fr)].map(async e=>{let n=Hr(t,e[2]),r=n===void 0?void 0:await a(n);return[e[0],r===void 0?void 0:`url("${await Ur(r)}")`]}))).reduce((e,[t,n])=>n===void 0?e:e.replace(t,n),e),missing:r}}async function Gr(e,t,n,r){let i=new DOMParser().parseFromString(n,`text/html`),{load:a,inlineCss:o,missing:s}=Wr(e,r),c=[];for(let e of i.querySelectorAll(`img[src], source[src], video[src], audio[src], track[src], video[poster], input[src], image[href]`))for(let n of[`src`,`poster`,`href`]){let r=e.getAttribute(n),i=r===null?void 0:Hr(t,r);i!==void 0&&c.push(a(i).then(async t=>{t!==void 0&&e.setAttribute(n,await Ur(t))}))}for(let e of i.querySelectorAll(`link[href]`)){let n=Hr(t,e.getAttribute(`href`)??``);if(n===void 0)continue;let r=e.relList.contains(`stylesheet`);c.push(a(n).then(async t=>{if(t===void 0)return;if(!r){e.setAttribute(`href`,await Ur(t));return}let a=i.createElement(`style`);a.textContent=await o(await t.text(),n),e.replaceWith(a)}))}for(let e of i.querySelectorAll(`script[src]`)){let n=Hr(t,e.getAttribute(`src`)??``);n!==void 0&&c.push(a(n).then(async t=>{t!==void 0&&(e.removeAttribute(`src`),e.textContent=await t.text())}))}for(let e of i.querySelectorAll(`style`))c.push(o(e.textContent??``,t).then(t=>{e.textContent=t}));await Promise.all(c),r.throwIfAborted();let l=i.createElement(`script`);return l.textContent=Ir,i.head.prepend(l),{html:`${i.doctype===null?``:`<!doctype ${i.doctype.name}>`}${i.documentElement.outerHTML}`,missing:s}}async function Kr(e,t,n){let r;if(n!==void 0)r=new Blob([Uint8Array.from(atob(n),e=>e.charCodeAt(0))],{type:`image/png`});else{let n=await A.fetch(e,{signal:t,cache:`no-store`});if(!n.ok)throw Error(`Author media could not be loaded (${n.status}).`);if(r=await n.blob(),r.type.startsWith(`image/svg+xml`)){let e=ie(await r.text());return t.throwIfAborted(),{url:e,dispose(){}}}}t.throwIfAborted();let i=URL.createObjectURL(r),a=!1;return{url:i,dispose(){a||(a=!0,URL.revokeObjectURL(i))}}}function qr(e){let t=Math.max(0,Math.round((Number.isFinite(e)?e:0)*1e3));return`${String(Math.floor(t/6e4)).padStart(2,`0`)}:${String(Math.floor(t/1e3)%60).padStart(2,`0`)}.${String(t%1e3).padStart(3,`0`)}`}function Jr({playback:e,ready:t,locked:n,marking:r,onSeek:i,onToggle:a,onAnnotate:o}){let[s,c]=E(``),l=e.duration,u=s.trim()===``||!Number.isFinite(Number(s))||Number(s)<0||Number(s)>l,d=`min-h-11 px-3 text-base [@media(pointer:fine)]:min-h-8 sm:text-sm`;return P(`section`,{"aria-label":`Video annotation controls`,className:`mt-2 space-y-2 rounded border border-po-border bg-po-panel p-2.5 text-base text-po-text sm:text-sm`,children:[P(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[P(`output`,{"aria-label":`Playback position`,className:`font-mono text-base tabular-nums`,children:[qr(e.currentTime),` / `,qr(l)]}),j(`span`,{className:`text-po-dim`,children:n?`Annotation draft: add or discard it before seeking.`:r?`Frame paused. Drag a region on the video.`:`Seek to a moment, then choose Annotate this frame.`})]}),j(`input`,{"aria-label":`Video timeline`,type:`range`,min:0,max:l||0,step:.001,value:Math.min(e.currentTime,l),disabled:n||l<=0,onChange:e=>i(Number(e.target.value)),className:`h-11 w-full cursor-pointer accent-po-blue [@media(pointer:fine)]:h-6`}),P(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(L,{className:d,disabled:n||l<=0,onClick:a,children:e.playing?`Pause`:`Play`}),j(L,{className:d,disabled:n||l<=0,onClick:()=>i(Math.max(0,e.currentTime-.1)),"aria-label":`Seek back 0.1 seconds`,children:`−0.1s`}),j(L,{className:d,disabled:n||l<=0,onClick:()=>i(Math.min(l,e.currentTime+.1)),"aria-label":`Seek forward 0.1 seconds`,children:`+0.1s`}),j(L,{variant:`primary`,className:d,disabled:n||!t,onClick:o,children:`Annotate this frame`}),P(`form`,{className:`flex flex-wrap items-center gap-2 sm:ml-auto`,onSubmit:e=>{e.preventDefault(),!u&&!n&&i(Number(s))},children:[j(`label`,{htmlFor:`author-video-seconds`,className:`text-po-dim`,children:`Go to seconds`}),j(`input`,{id:`author-video-seconds`,type:`number`,min:0,max:l,step:.001,value:s,onChange:e=>c(e.target.value),disabled:n||l<=0,placeholder:`1.250`,className:`h-11 w-24 rounded border border-po-border bg-po-deep px-2 text-lg [@media(pointer:fine)]:h-8 sm:text-sm`}),j(L,{type:`submit`,className:d,disabled:n||l<=0||u,children:`Go`})]})]})]})}var Yr=`pointer-events-none absolute border-2 border-po-magenta bg-po-magenta/10`,Xr=`absolute -left-3 -top-3 flex h-6 min-w-6 items-center justify-center rounded-full border-2 border-po-panel bg-po-magenta px-1 text-sm font-semibold text-po-rail`,Zr=300,Qr=12,$r=1.5,ei=.1;function ti({sessionId:e,document:t,activeTool:n,displayedRegions:r,pendingCandidate:i=!1,seekRequest:a}){let o=k(null),s=k(null),l=k(null),u=k(null),d=k(void 0),f=k(new Map),p=k(void 0),m=k(void 0),h=k(null),g=k(void 0),_=k(void 0),[v,y]=E(1),b=(e,t)=>{let n=Math.min(8,Math.max(.25,e));if(n===v)return;let r=o.current?.getBoundingClientRect(),i=h.current?.getBoundingClientRect();if(r&&i&&i.width>0&&i.height>0){let e=t?.x??r.left+r.width/2,n=t?.y??r.top+r.height/2;g.current={x:e,y:n,fx:(e-i.left)/i.width,fy:(n-i.top)/i.height}}y(n)},x=()=>{g.current=void 0,y(1),o.current&&(o.current.scrollLeft=0,o.current.scrollTop=0)};C(()=>{let e=g.current;g.current=void 0;let t=o.current,n=h.current?.getBoundingClientRect();e&&t&&n&&(t.scrollLeft+=n.left+e.fx*n.width-e.x,t.scrollTop+=n.top+e.fy*n.height-e.y)},[v]);let[S,w]=E(),[T,ee]=E(),[D,te]=E({playing:!1,currentTime:0,duration:0}),[O,ne]=E(!1),[re,A]=E(),[ie,M]=E(),[ae,oe]=E();I(()=>{d.current=void 0,f.current.clear(),m.current=void 0,p.current=void 0,_.current=void 0,w(void 0),A(void 0),g.current=void 0,y(1)},[t.path,t.version,t.sourceSha256,t.mediaUrl]),I(()=>{d.current=void 0,w(void 0),f.current.clear(),m.current=void 0,p.current=void 0,_.current=void 0},[n]);let N=ae?.source===t.mediaUrl?ae?.url:void 0;I(()=>{if(t.kind!==`pdf`||N===void 0)return;let e=o.current;if(e===null)return;let n=()=>{let t=e.querySelector(`canvas`),n=e.querySelector(`[data-testid="author-media"]`);if(!t||!n)return;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),a={left:(r.left-i.left)/v,top:(r.top-i.top)/v,width:r.width/v,height:r.height/v};ee(e=>e&&Object.keys(a).every(t=>Math.abs(e[t]-a[t])<.01)?e:a)},r=new ResizeObserver(n),i=new MutationObserver(()=>{let t=e.querySelector(`canvas`);t&&r.observe(t),n()});i.observe(e,{childList:!0,subtree:!0});let a=e.querySelector(`canvas`);return a&&r.observe(a),n(),()=>{r.disconnect(),i.disconnect()}},[t.kind,N,v]),I(()=>{if(t.mediaUrl===void 0)return;let e=t.mediaUrl,n=new AbortController,r;return M(void 0),Kr(e,n.signal,t.imageData).then(t=>{n.signal.aborted?t.dispose():(r=()=>t.dispose(),oe({source:e,url:t.url}))}).catch(e=>{n.signal.aborted||M(e instanceof Error?e.message:String(e))}),()=>{n.abort(),r?.()}},[t.mediaUrl,t.imageData]);let se=n=>{if(W(e,t.path).candidate||!Number.isFinite(n))return;let r=l.current;r&&(r.pause(),G(e,t.path,`select`),A(void 0),r.getState().currentTime!==n&&(ne(!1),r.seek(n)))};I(()=>{a?.path===t.path&&a.generation===U(e).focusedDocument?.generation&&se(a.timeSeconds)},[a]),I(()=>{!i&&d.current===void 0&&A(void 0)},[i]),I(()=>Xe(e,(e,n)=>{let r=s.current;if(t.kind!==`image`||r===null||r.naturalWidth===0||r.naturalHeight===0)return;let{originX:i=0,originY:a=0,width:o,height:c}=n.viewport,l={left:i+e.rect.x*o,top:a+e.rect.y*c,right:i+(e.rect.x+e.rect.width)*o,bottom:a+(e.rect.y+e.rect.height)*c},u=r.getBoundingClientRect(),d=Math.max(u.left,l.left),f=Math.max(u.top,l.top),p=Math.min(u.right,l.right),m=Math.min(u.bottom,l.bottom);if(!(p<=d||m<=f||u.width<=0||u.height<=0))return{anchor:{kind:`image-rect`,rect:{x:(d-u.left)/u.width,y:(f-u.top)/u.height,width:(p-d)/u.width,height:(m-f)/u.height},naturalWidth:r.naturalWidth,naturalHeight:r.naturalHeight}}}),[e,t.kind,t.path,t.version]);let ce=async n=>{let r=d.current;if(!r||r.pointerId!==n.pointerId||m.current!==void 0)return;d.current=void 0;let i=r.element.getBoundingClientRect();if(i.width<=0||i.height<=0)return;let a={x:Math.min(1,Math.max(0,(n.clientX-i.left)/i.width)),y:Math.min(1,Math.max(0,(n.clientY-i.top)/i.height))},o=r.mode===`draw`?$t(r.points,a):void 0,s=r.mode===`draw`?Qt(o??[]):r.mode===`mark`?en(i,{left:r.x,top:r.y,right:n.clientX,bottom:n.clientY}):void 0;if(r.mode!==`comment`&&!s)return;w(void 0),A(r.mode===`draw`?void 0:r.mode===`mark`?{path:t.path,rect:s}:{path:t.path,point:a});let c=U(e).focusedDocument;if(!c||c.path!==t.path)return;let f,p=null,h;try{if(r.element instanceof HTMLImageElement){let e=r.element;if(!e.naturalWidth||!e.naturalHeight)throw Error(`Image is not ready.`);f=r.mode===`comment`?{kind:`image-point`,point:a,naturalWidth:e.naturalWidth,naturalHeight:e.naturalHeight}:{kind:`image-rect`,rect:s,naturalWidth:e.naturalWidth,naturalHeight:e.naturalHeight};let t=document.createElement(`canvas`),n=Math.min(1,1600/Math.max(e.naturalWidth,e.naturalHeight));t.width=Math.max(1,Math.round(e.naturalWidth*n)),t.height=Math.max(1,Math.round(e.naturalHeight*n));let i=t.getContext(`2d`);if(!i)throw Error(`Canvas is unavailable.`);i.drawImage(e,0,0,t.width,t.height),p=await new Promise(e=>t.toBlob(e,`image/png`))}else if(t.kind===`pdf`){let e=u.current?.getState();if(!e?.sourceWidth)throw Error(`PDF page is not ready.`);if(f=r.mode===`comment`?{kind:`pdf-page-point`,page:e.page,point:a}:{kind:`pdf-page-rect`,page:e.page,rect:s},p=await u.current.capturePage(),u.current?.getState().page!==e.page)return}else{let e=await l.current?.captureFrame();if(!e)throw Error(`Video frame is not ready.`);if(f=r.mode===`comment`?{kind:`video-time-point`,point:a,timeSeconds:e.timeSeconds,intrinsicWidth:e.width,intrinsicHeight:e.height}:{kind:`video-time-rect`,rect:s,timeSeconds:e.timeSeconds,intrinsicWidth:e.width,intrinsicHeight:e.height},p=e.blob,Math.abs((l.current?.getState().currentTime??-1)-e.timeSeconds)>ei||l.current?.isFrameReady()===!1)return}if(!p)throw Error(`Unable to capture selected media.`);if(U(e).focusedDocument?.generation!==c.generation)return;h=URL.createObjectURL(p),gt(e,t.path,{documentPath:t.path,revision:t.version,sourceSha256:t.sourceSha256,mode:r.mode===`comment`?`point`:`region`,anchor:f,...o===void 0?{}:{stroke:o},viewport:{width:i.width,height:i.height},thumbnailUrl:h,evidence:p,createdAt:Date.now()}),M(void 0)}catch(e){h&&URL.revokeObjectURL(h),M(e instanceof Error?e.message:String(e))}},F=(e,t)=>e===void 0?null:j(`svg`,{"data-testid":t===void 0?`author-media-stroke-selection`:`author-media-stroke`,"data-author-stroke":t,"aria-hidden":`true`,className:`pointer-events-none absolute inset-0 h-full w-full overflow-visible`,viewBox:`0 0 1000 1000`,preserveAspectRatio:`none`,children:j(`polyline`,{points:e.map(e=>`${String(e.x*1e3)},${String(e.y*1e3)}`).join(` `),fill:`none`,stroke:`currentColor`,strokeWidth:`5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`text-po-magenta`})}),le=re?.path===t.path?re.rect:void 0,ue=re?.path===t.path?re.point:void 0,de=le===void 0?null:j(`div`,{"data-testid":`author-media-selection`,className:`pointer-events-none absolute border-2 border-dashed border-po-magenta bg-po-magenta/10`,style:{left:`${le.x*100}%`,top:`${le.y*100}%`,width:`${le.width*100}%`,height:`${le.height*100}%`}}),fe=(e,t,n)=>j(`span`,{"data-author-point":e,"data-testid":e===void 0?`author-media-point-selection`:void 0,className:`pointer-events-none absolute z-10 flex h-6 min-w-6 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full border-2 px-1 text-sm font-semibold ${e===void 0?`border-po-magenta bg-po-panel text-po-magenta`:`border-po-panel bg-po-magenta text-po-rail`}`,style:{left:`${String(t.x*100)}%`,top:`${String(t.y*100)}%`},children:e??`•`},n),pe=ue===void 0?null:fe(void 0,ue,`selection`);return P(`div`,{className:`flex min-h-0 flex-1 flex-col`,style:{cursor:n===`draw`||n===`mark`?`crosshair`:void 0},onPointerMove:e=>{if(f.current.has(e.pointerId)&&f.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),m.current!==void 0&&f.current.size>=2){let[e,t]=[...f.current.values()],n=Math.hypot(e.x-t.x,e.y-t.y);m.current.distance>0&&b(m.current.zoom*n/m.current.distance,{x:(e.x+t.x)/2,y:(e.y+t.y)/2});return}if(p.current!==void 0){Math.hypot(e.clientX-p.current.x,e.clientY-p.current.y)>Qr&&(p.current.moved=!0,_.current=void 0);let t=o.current;t&&(t.scrollLeft=p.current.left+p.current.x-e.clientX,t.scrollTop=p.current.top+p.current.y-e.clientY);return}let n=d.current;if(n?.pointerId!==e.pointerId)return;if(n.mode===`draw`){let t=n.element.getBoundingClientRect();if(t.width<=0||t.height<=0)return;n.points=$t(n.points,{x:(e.clientX-t.left)/t.width,y:(e.clientY-t.top)/t.height}),w(n.points);return}if(n.mode!==`mark`)return;let r=en(n.element.getBoundingClientRect(),{left:n.x,top:n.y,right:e.clientX,bottom:e.clientY});A(r===null?void 0:{path:t.path,rect:r})},onPointerDownCapture:e=>{if(e.button!==0)return;e.pointerType!==`touch`&&(_.current=void 0);let t=e.target;if(!(t instanceof HTMLImageElement||t instanceof HTMLVideoElement||t instanceof HTMLCanvasElement))return;if(f.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),f.current.size===2){d.current=void 0,w(void 0),A(void 0),p.current=void 0,_.current=void 0;let[t,n]=[...f.current.values()];m.current={distance:Math.hypot(t.x-n.x,t.y-n.y),zoom:v},e.currentTarget.setPointerCapture(e.pointerId);return}if(n===`pan`||n===`select`&&e.pointerType===`touch`){let t=o.current;t&&(p.current={x:e.clientX,y:e.clientY,left:t.scrollLeft,top:t.scrollTop,pointerId:e.pointerId,at:performance.now(),moved:!1}),e.currentTarget.setPointerCapture(e.pointerId);return}if(n!==`mark`&&n!==`comment`&&n!==`draw`||i)return;if(e.preventDefault(),A(void 0),t instanceof HTMLVideoElement){if(l.current?.isFrameReady?.()===!1){M(`Wait for the selected frame to finish loading.`);return}l.current?.pause()}let r=t.getBoundingClientRect();d.current={x:e.clientX,y:e.clientY,pointerId:e.pointerId,mode:n,element:t,points:n===`draw`?[{x:(e.clientX-r.left)/r.width,y:(e.clientY-r.top)/r.height}]:[]},e.currentTarget.setPointerCapture(e.pointerId)},onPointerUp:e=>{let t=p.current;if(e.pointerType===`touch`&&t?.pointerId===e.pointerId&&m.current===void 0&&f.current.size===1){let n=performance.now(),r=!t.moved&&n-t.at<=Zr&&Math.hypot(e.clientX-t.x,e.clientY-t.y)<=Qr,i=_.current;r&&i&&n-i.at<=Zr&&Math.hypot(e.clientX-i.x,e.clientY-i.y)<=24?(x(),_.current=void 0):_.current=r?{x:e.clientX,y:e.clientY,at:n}:void 0}m.current===void 0&&p.current===void 0&&ce(e),f.current.delete(e.pointerId),p.current=void 0,f.current.size<2&&(m.current=void 0)},onPointerCancel:e=>{f.current.delete(e.pointerId),m.current=void 0,p.current=void 0,_.current=void 0,d.current=void 0,w(void 0),A(void 0)},onLostPointerCapture:()=>{(p.current!==void 0||m.current!==void 0)&&(_.current=void 0),d.current=void 0,p.current=void 0,w(void 0)},children:[j(`div`,{ref:o,className:`@container flex min-h-0 flex-1 flex-col overflow-auto bg-po-deep/50 p-6`,children:P(`div`,{className:`m-auto flex max-w-full flex-col items-center-safe gap-3`,children:[N===void 0?j(`p`,{className:`text-po-dim`,children:ie===void 0?`Loading media...`:`Media unavailable.`}):t.kind===`image`?P(`div`,{ref:h,className:`relative w-max max-w-[100cqw] touch-auto shadow-sm ring-1 ring-po-border-soft [@media(pointer:coarse)]:touch-none`,style:{zoom:v,touchAction:n===`select`?void 0:`none`},children:[j(`img`,{ref:s,src:N,alt:t.path,draggable:!1,className:`block max-w-full`}),de,pe,F(S),r.flatMap(({ordinal:e,region:t})=>{if(t.stroke!==void 0)return[P(`div`,{className:`pointer-events-none absolute inset-0`,children:[F(t.stroke,e),fe(e,t.stroke[0],`label:${t.id}`)]},t.id)];if(t.anchor.kind===`image-point`)return[fe(e,t.anchor.point,t.id)];if(t.anchor.kind!==`image-rect`)return[];let{rect:n}=t.anchor;return[j(`div`,{"data-author-region":e,className:Yr,style:{left:`${String(n.x*100)}%`,top:`${String(n.y*100)}%`,width:`${String(n.width*100)}%`,height:`${String(n.height*100)}%`},children:j(`span`,{className:Xr,children:e})},t.id)]})]}):P(`div`,{ref:h,className:`relative w-max max-w-[100cqw] touch-auto shadow-sm ring-1 ring-po-border-soft [@media(pointer:coarse)]:touch-none`,style:{zoom:v,touchAction:n===`select`?void 0:`none`},children:[j(c,{src:N,path:t.path,kind:t.kind===`pdf`?`pdf`:t.kind===`video`?`video`:`download`,controllerRef:l,pdfControllerRef:u,"data-testid":`author-media`,videoControls:!1,onPlaybackStateChange:e=>{te(e),ne(l.current?.isFrameReady()??!1),e.playing&&A(void 0)}}),P(`div`,{className:`pointer-events-none absolute`,style:t.kind===`pdf`?T===void 0?{display:`none`}:{left:T.left,top:T.top,width:T.width,height:T.height}:{inset:0},children:[de,pe,F(S),r.map(({ordinal:e,region:n})=>{if(n.stroke!==void 0){let r=n.anchor;return t.kind===`pdf`&&(r.kind!==`pdf-page-rect`||r.page!==u.current?.getState().page)||t.kind===`video`&&(r.kind!==`video-time-rect`||D.playing||Math.abs(r.timeSeconds-D.currentTime)>ei)?null:P(`div`,{className:`pointer-events-none absolute inset-0`,children:[F(n.stroke,e),fe(e,n.stroke[0],`label:${n.id}`)]},n.id)}if(t.kind===`pdf`){if(n.anchor.kind!==`pdf-page-point`&&n.anchor.kind!==`pdf-page-rect`||n.anchor.page!==u.current?.getState().page)return null;if(n.anchor.kind===`pdf-page-point`)return fe(e,n.anchor.point,n.id);let{rect:t}=n.anchor;return j(`div`,{"data-author-region":e,className:Yr,style:{left:`${String(t.x*100)}%`,top:`${String(t.y*100)}%`,width:`${String(t.width*100)}%`,height:`${String(t.height*100)}%`},children:j(`span`,{className:Xr,children:e})},n.id)}if(t.kind!==`video`||D.playing)return null;if(n.anchor.kind===`video-time-point`&&Math.abs(n.anchor.timeSeconds-D.currentTime)<=ei)return fe(e,n.anchor.point,n.id);if(n.anchor.kind!==`video-time-rect`||Math.abs(n.anchor.timeSeconds-D.currentTime)>ei)return null;let{rect:r}=n.anchor;return j(`div`,{"data-author-region":e,className:Yr,style:{left:`${r.x*100}%`,top:`${r.y*100}%`,width:`${r.width*100}%`,height:`${r.height*100}%`},children:j(`span`,{className:Xr,children:e})},n.id)})]})]}),t.kind===`video`?j(Jr,{playback:D,ready:O,locked:i,marking:n===`mark`,onSeek:se,onToggle:()=>{G(e,t.path,`select`),A(void 0),D.playing?l.current?.pause():l.current?.play().catch(e=>M(String(e)))},onAnnotate:()=>{l.current?.pause(),G(e,t.path,`mark`)}}):null,ie?j(`output`,{className:`text-base text-po-red`,children:ie}):null]})}),P(`footer`,{className:`flex shrink-0 items-center gap-2 border-t border-po-border bg-po-bg px-3 py-1.5 [@media(pointer:coarse)]:sr-only [@media(pointer:coarse)]:focus-within:not-sr-only`,children:[P(`div`,{role:`group`,"aria-label":`Canvas zoom`,className:`flex items-center gap-2`,children:[P(`div`,{className:`flex items-center rounded-md border border-po-border`,children:[j(L,{size:`md`,variant:`ghost`,"aria-label":`Zoom out`,className:`min-h-11 min-w-11 rounded-r-none [@media(pointer:fine)]:min-h-8`,onClick:()=>b(v/$r),children:`−`}),P(`output`,{className:`flex min-w-14 items-center justify-center self-stretch border-x border-po-border-soft text-sm tabular-nums text-po-text`,children:[Math.round(v*100),`%`]}),j(L,{size:`md`,variant:`ghost`,"aria-label":`Zoom in`,className:`min-h-11 min-w-11 rounded-l-none [@media(pointer:fine)]:min-h-8`,onClick:()=>b(v*$r),children:`+`})]}),j(L,{size:`md`,variant:`outline`,"aria-label":`Fit canvas`,className:`min-h-11 [@media(pointer:fine)]:min-h-8`,onClick:x,children:`Fit`})]}),j(`span`,{className:`ml-auto text-sm text-po-dim first-letter:uppercase`,children:t.kind})]})]})}var ni=4e3;function ri({points:e,testId:t}){return j(`svg`,{"data-testid":t,"aria-hidden":`true`,className:`pointer-events-none absolute inset-0 h-full w-full overflow-visible`,viewBox:`0 0 1000 1000`,preserveAspectRatio:`none`,children:j(`polyline`,{points:e.map(e=>`${String(e.x*1e3)},${String(e.y*1e3)}`).join(` `),fill:`none`,stroke:`currentColor`,strokeWidth:`5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`text-po-magenta`})})}function ii({ordinal:e,left:t,top:n}){return j(`span`,{"data-author-point":e,"data-testid":e===void 0?`author-html-point-selection`:void 0,className:`pointer-events-none absolute z-10 flex h-6 min-w-6 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full border-2 px-1 text-sm font-semibold ${e===void 0?`border-po-magenta bg-po-panel text-po-magenta`:`border-po-panel bg-po-magenta text-po-rail`}`,style:{left:t,top:n},children:e??`•`})}var X=e=>`${String(e*100)}%`;function ai({sessionId:e,document:t,activeTool:n,displayedRegions:r,pendingCandidate:i=!1}){let a=k(null),o=k(void 0),s=k(1),c=k(new Map),[l,u]=E(),[d,f]=E(),[p,m]=E(),[h,g]=E(),[_,v]=E(),y=(n===`mark`||n===`comment`||n===`draw`)&&!i;I(()=>{let n=new AbortController;return f(void 0),Gr(e,t.path,t.content??``,n.signal).then(e=>{n.signal.aborted||u(e)}).catch(e=>{n.signal.aborted||f(e instanceof Error?e.message:String(e))}),()=>n.abort()},[e,t.path,t.content]),I(()=>{let e=c.current,t=t=>{if(a.current===null||t.source!==a.current.contentWindow)return;let n=zr(t.data);if(n===void 0)return;if(n.type===`view`){let{type:e,...t}=n;m(t);return}let{type:r,...i}=n;m(i.view),e.get(i.id)?.(i),e.delete(i.id)};return window.addEventListener(`message`,t),()=>{window.removeEventListener(`message`,t);for(let t of e.values())t(void 0);e.clear()}},[]),I(()=>{o.current=void 0,v(void 0),i||g(void 0)},[n,i,t.version]);let b=e=>new Promise(t=>{let n=a.current?.contentWindow;if(n==null){t(void 0);return}let r=s.current++,i=setTimeout(()=>{c.current.delete(r),t(void 0)},ni);c.current.set(r,e=>{clearTimeout(i),t(e)}),n.postMessage(Br(r,e),`*`)}),x=(e,t)=>({x:Math.min(1,Math.max(0,(e.clientX-t.left)/t.width)),y:Math.min(1,Math.max(0,(e.clientY-t.top)/t.height))}),S=async n=>{let r=o.current;if(r===void 0||r.pointerId!==n.pointerId)return;o.current=void 0;let i=n.currentTarget.getBoundingClientRect();if(i.width<=0||i.height<=0)return;let a=x(n,i),s=r.mode===`draw`?$t(r.points,a):void 0,c=r.mode===`draw`?Qt(s??[]):r.mode===`mark`?en(i,{left:r.x,top:r.y,right:n.clientX,bottom:n.clientY}):void 0;if(v(void 0),r.mode!==`comment`&&!c)return;g(r.mode===`draw`?void 0:r.mode===`mark`?{rect:c}:{point:a});let l=U(e).focusedDocument;if(!l||l.path!==t.path)return;let u=c??{...a,width:0,height:0},d=await b({x:u.x*i.width,y:u.y*i.height,width:u.width*i.width,height:u.height*i.height});if(U(e).focusedDocument?.generation!==l.generation)return;let f=d?.view??p??{scrollX:0,scrollY:0,width:i.width,height:i.height},m=d?.image===void 0?void 0:Vr(d.image),h=d?.element;gt(e,t.path,{documentPath:t.path,revision:t.version,sourceSha256:t.sourceSha256,mode:r.mode===`comment`?`point`:`region`,anchor:r.mode===`comment`?{kind:`html-point`,point:a,...h===void 0?{}:{element:h}}:{kind:`html-rect`,rect:c,...h===void 0?{}:{element:h}},...d?.quote===void 0?{}:{quote:d.quote},...s===void 0?{}:{stroke:s},viewport:f,...m===void 0?{}:{evidence:m,thumbnailUrl:URL.createObjectURL(m)},createdAt:Date.now()})},C=e=>{let t=e.viewport,n=p?.width??t.width,r=p?.height??t.height;return{dx:((t.scrollX??0)-(p?.scrollX??t.scrollX??0))/n,dy:((t.scrollY??0)-(p?.scrollY??t.scrollY??0))/r,sx:t.width/n,sy:t.height/r}};return P(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[P(`div`,{className:`relative flex min-h-0 flex-1 bg-po-deep/50`,children:[l===void 0?j(`p`,{className:`m-auto text-po-dim`,children:d===void 0?`Loading page...`:`Page unavailable.`}):j(`iframe`,{ref:a,"data-testid":`author-html-frame`,title:`Rendered ${t.path}`,sandbox:`allow-scripts`,srcDoc:l.html,className:`h-full w-full flex-1 border-0 bg-white`}),P(`div`,{"data-testid":`author-html-overlay`,className:`absolute inset-0 overflow-hidden`,style:{pointerEvents:y?`auto`:`none`,cursor:n===`mark`||n===`draw`?`crosshair`:void 0,touchAction:y?`none`:`auto`},onPointerDown:e=>{if(e.button!==0||!y||l===void 0)return;e.preventDefault(),g(void 0);let t=e.currentTarget.getBoundingClientRect();o.current={x:e.clientX,y:e.clientY,pointerId:e.pointerId,mode:n,points:n===`draw`?[x(e,t)]:[]},e.currentTarget.setPointerCapture(e.pointerId)},onPointerMove:e=>{let t=o.current;if(t?.pointerId!==e.pointerId)return;let n=e.currentTarget.getBoundingClientRect();if(t.mode===`draw`)t.points=$t(t.points,x(e,n)),v(t.points);else if(t.mode===`mark`){let r=en(n,{left:t.x,top:t.y,right:e.clientX,bottom:e.clientY});g(r===null?void 0:{rect:r})}},onPointerUp:e=>void S(e),onPointerCancel:()=>{o.current=void 0,v(void 0),g(void 0)},children:[h?.rect===void 0?null:j(`div`,{"data-testid":`author-html-selection`,className:`pointer-events-none absolute border-2 border-dashed border-po-magenta bg-po-magenta/10`,style:{left:X(h.rect.x),top:X(h.rect.y),width:X(h.rect.width),height:X(h.rect.height)}}),h?.point===void 0?null:j(ii,{left:X(h.point.x),top:X(h.point.y)}),_===void 0?null:j(ri,{points:_,testId:`author-html-stroke-selection`}),r.map(({ordinal:e,region:t})=>{let{anchor:n}=t;if(n.kind!==`html-rect`&&n.kind!==`html-point`)return null;let{dx:r,dy:i,sx:a,sy:o}=C(t);return t.stroke===void 0?n.kind===`html-point`?j(ii,{ordinal:e,left:X(r+n.point.x*a),top:X(i+n.point.y*o)},t.id):j(`div`,{"data-author-region":e,className:Yr,style:{left:X(r+n.rect.x*a),top:X(i+n.rect.y*o),width:X(n.rect.width*a),height:X(n.rect.height*o)},children:j(`span`,{className:Xr,children:e})},t.id):P(`div`,{className:`pointer-events-none absolute`,style:{left:X(r),top:X(i),width:X(a),height:X(o)},children:[j(ri,{points:t.stroke,testId:`author-html-stroke`}),j(ii,{ordinal:e,left:X(t.stroke[0].x),top:X(t.stroke[0].y)})]},t.id)})]})]}),d!==void 0||(l?.missing.length??0)>0?j(`footer`,{className:`shrink-0 border-t border-po-border bg-po-bg px-3 py-1.5 text-sm`,children:d===void 0?P(`span`,{className:`text-po-dim`,children:[`Not found: `,l?.missing.join(`, `)]}):j(`output`,{className:`text-po-red`,children:d})}):null]})}function oi({sessionId:e,document:t,displayedRegions:n}){I(()=>Xe(e,(e,n)=>{let{originX:r=0,originY:i=0,width:a,height:o}=n.viewport,s=window.document.elementFromPoint(r+e.center.x*a,i+e.center.y*o)?.closest(`[data-author-fragment]`)?.dataset.authorFragment,c=t.fragments?.find(e=>e.id===s);if(c===void 0||c.readOnly===!0)return;if(t.kind===`csv`||t.kind===`xlsx`)return{anchor:{kind:`cell`,fragmentId:c.id,location:c.location},quote:c.text};let l=Number(c.location.match(/(?:slide\s*|slides\/slide)(\d+)/u)?.[1]);if(Number.isSafeInteger(l))return{anchor:{kind:`slide-element`,fragmentId:c.id,location:c.location,slide:l},quote:c.text}}),[t.fragments,t.kind,t.version,e]);let r=new Map(n.flatMap(({ordinal:e,region:t})=>t.anchor.kind===`cell`||t.anchor.kind===`slide-element`?[[t.anchor.fragmentId,e]]:[])),i=t.kind===`csv`||t.kind===`xlsx`,a=new Map;for(let e of t.fragments??[]){let n=i?t.kind===`csv`?e.location.split(`,`)[0]:e.location.replace(/![A-Z]+(\d+)$/,`!row $1`):e.location,r=a.get(n)??[];r.push(e),a.set(n,r)}return P(`div`,{"data-testid":`author-structured`,className:`min-h-0 flex-1 space-y-3 overflow-auto p-4`,children:[i?null:j(`p`,{className:`text-sm text-po-dim`,children:`Slide text view, not a layout-faithful rendering.`}),[...a].map(([n,a])=>P(`section`,{className:`space-y-1`,children:[j(`h3`,{className:`text-sm text-po-dim`,children:n}),j(`div`,{className:i?`flex gap-1`:`space-y-2`,children:a.map(n=>P(`div`,{"data-author-fragment":n.id,"data-author-region":r.get(n.id),className:`${i?`w-40 shrink-0`:``} relative rounded ${r.has(n.id)?`ring-1 ring-po-yellow`:``}`,children:[r.has(n.id)?j(`span`,{className:`absolute -left-1 -top-1 z-10 flex h-4 min-w-4 items-center justify-center rounded-full bg-po-yellow px-1 text-2xs font-semibold text-po-deep`,children:r.get(n.id)}):null,P(L,{size:`xs`,variant:`ghost`,onClick:r=>{let a=r.currentTarget.getBoundingClientRect(),o=Number(n.location.match(/(?:slide\s*|slides\/slide)(\d+)/)?.[1]);(i||Number.isSafeInteger(o))&>(e,t.path,{documentPath:t.path,revision:t.version,sourceSha256:t.sourceSha256,quote:n.text,anchor:i?{kind:`cell`,fragmentId:n.id,location:n.location}:{kind:`slide-element`,fragmentId:n.id,location:n.location,slide:o},viewport:{width:a.width,height:a.height},createdAt:Date.now()})},children:[`mark `,n.location]}),j(`textarea`,{"aria-label":n.location,value:n.text,readOnly:n.readOnly===!0,className:`w-full rounded border border-po-border bg-po-deep p-2 text-base text-po-text`,onChange:r=>wt(e,t.path,n.id,r.target.value)})]},n.id))})]},n))]})}function si({open:e,onOpenChange:t,onFormat:n,onCloseAutoFocus:r,disabled:i=!1}){return j(oe,{open:e,onOpenChange:t,children:P(ee,{className:`inset-x-0 bottom-0 top-auto max-h-[70dvh] w-full max-w-none rounded-t-lg border-t data-[state=open]:animate-none!`,onCloseAutoFocus:r,children:[j(p,{closeLabel:`Close formatting`,className:`[&_button]:relative [&_button]:before:absolute [&_button]:before:-inset-3`,children:j(v,{children:`Formatting`})}),P(re,{className:`pb-6`,children:[j(T,{children:`Choose how to format the selected text.`}),$e.map(({format:e,label:t})=>j(L,{variant:`ghost`,className:`min-h-11 w-full justify-start text-base`,disabled:i,onClick:()=>n(e),children:t},e))]})]})})}var ci=`p,li,h1,h2,h3,h4,h5,h6,pre,blockquote,td,th`,li=`po-author-note`,ui=`•`;function di(e){let t=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode:e=>e.parentElement?.closest(`svg,button,[aria-hidden="true"]`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}),n=[];for(let e=t.nextNode();e!==null;e=t.nextNode())n.push(e);return n}function fi(e,t,n){let r=di(e),i=it(t,r.map(e=>e.data)),a,o;return r.forEach((e,r)=>{let s=i[r];s!==void 0&&n.intersectsNode(e)&&(a??=s+(e===n.startContainer?n.startOffset:0),o=Math.min(t.length,s+(e===n.endContainer?n.endOffset:e.data.length)))}),a===void 0||o===void 0||o<=a?void 0:{from:a,to:o}}function pi(e,t,n,r){let i=di(e),a=it(t,i.map(e=>e.data)),o,s;if(i.forEach((e,t)=>{let i=a[t];i===void 0||i+e.data.length<=n||i>=r||(o??={run:e,offset:Math.max(0,n-i)},s={run:e,offset:Math.min(e.data.length,r-i)})}),o===void 0||s===void 0)return;let c=e.ownerDocument.createRange();return c.setStart(o.run,o.offset),c.setEnd(s.run,s.offset),c}function mi(e,t){let n=e.ownerDocument.createRange(),r=di(e).filter(e=>(n.selectNodeContents(e),[...n.getClientRects()].some(e=>e.right>t.left&&e.left<t.right&&e.bottom>t.top&&e.top<t.bottom))),i=r[0],a=r.at(-1);if(i!==void 0&&a!==void 0)return n.setStart(i,0),n.setEnd(a,a.data.length),n}function hi({sessionId:e,document:t,preview:n,activeTool:r=`select`,displayedRegions:i,candidate:a,renderMediaReview:o}){let s=k(null),c=k(null),l=k(null),u=k({from:0,to:0}),[d,f]=E(),[p,m]=E(),[h,_]=E([]),[v,b]=E(!1),x=k(void 0),S=k(void 0),C=!n&&t.kind===`markdown`&&!Zn(t.path);I(()=>{x.current=void 0,S.current=void 0,b(!1)},[e,t.path,C]);let w=[...i.flatMap(({ordinal:e,region:t})=>t.anchor.kind===`text-range`?[{label:String(e),from:t.anchor.startOffset,to:t.anchor.endOffset}]:[]),...a?.anchor.kind===`text-range`?[{label:ui,from:a.anchor.startOffset,to:a.anchor.endOffset}]:[]],T=JSON.stringify(w);I(()=>Xe(e,(e,t)=>{if(n||c.current===null)return;let{originX:r=0,originY:i=0,width:a,height:o}=t.viewport,s=c.current.resolveViewportRegion({left:r+e.rect.x*a,top:i+e.rect.y*o,right:r+(e.rect.x+e.rect.width)*a,bottom:i+(e.rect.y+e.rect.height)*o});if(s!==null&&s.from!==s.to)return{anchor:{kind:`text-range`,startOffset:s.from,endOffset:s.to,startLine:s.startLine,endLine:s.endLine},quote:s.text}}),[n,e]),I(()=>{c.current?.setMarkedRanges(JSON.parse(T))},[T]),I(()=>{let e=l.current,r=e?.parentElement;if(!n||!e||!r)return;let i=()=>{let n=t.content??``,i=JSON.parse(T).flatMap(t=>{let r=pi(e,n,t.from,t.to);return r===void 0?[]:[{label:t.label,range:r}]});typeof CSS<`u`&&`highlights`in CSS&&CSS.highlights.set(li,new Highlight(...i.map(({range:e})=>e)));let a=r.getBoundingClientRect();_(i.map(({label:e,range:t})=>{let n=t.getClientRects()[0]??t.getBoundingClientRect();return{label:e,left:n.left-a.left,top:n.top-a.top}}))};i();let a=typeof ResizeObserver>`u`?void 0:new ResizeObserver(i);return a?.observe(e),()=>{a?.disconnect(),typeof CSS<`u`&&`highlights`in CSS&&CSS.highlights.delete(li)}},[n,T,t.content]);let ee=(t.content??``).split(`
|
|
90
|
+
`).length,D=y(async n=>{let r=er(t.path,n);return{...await Kr($n(e,r),new AbortController().signal),path:r}},[e,t.path]),te=(n,r=u.current)=>{let i=H(e,t.path);if(!i||c.current===null)return;let{from:a,to:o}=r,s=nt(i.content??``,a,o,n);c.current.applyEdits([{from:s.from,to:s.to,insert:s.insert}]),c.current.revealAndSelect(s.select),c.current.focus()},O=()=>{let n=H(e,t.path);!n||c.current===null?m(`The editor is still loading. Try formatting again.`):x.current={...u.current,content:n.content??``,path:n.path,sessionId:e}},re=n=>{n.preventDefault();let r=x.current,i=S.current;if(x.current=void 0,S.current=void 0,!r||r.sessionId!==e||r.path!==t.path)return;let a=H(e,t.path);if(i!==void 0){if((a?.content??``)!==r.content){m(`Text changed while formatting was open. Select it again.`),c.current?.focus();return}te(i,r)}else(a?.content??``)===r.content&&c.current?.revealAndSelect(r),c.current?.focus()},A=(n,r,i)=>{let a=H(e,t.path),o=s.current?.getBoundingClientRect();if(!a||!o)return;if(n===void 0||n.to<=n.from){m(i);return}let c=a.content??``;m(void 0),gt(e,t.path,{documentPath:a.path,revision:a.version,sourceSha256:a.sourceSha256,mode:r,quote:c.slice(n.from,n.to),anchor:{kind:`text-range`,startOffset:n.from,endOffset:n.to,startLine:at(c,n.from),endLine:at(c,n.to)},viewport:{width:o.width,height:o.height},createdAt:Date.now()})},ie=(n,r)=>{l.current!==null&&A(fi(l.current,H(e,t.path)?.content??``,n),r,`That part of the page has no source text to mark. Press Edit to select it in the source.`)},M=()=>{if(r!==`select`||l.current===null)return;let e=window.getSelection();if(e===null||e.isCollapsed||e.rangeCount===0)return;let t=e.getRangeAt(0);l.current.contains(t.commonAncestorContainer)&&ie(t,`region`)},ae=r===`mark`||r===`comment`,oe=(e,t)=>{let n=e.currentTarget.getBoundingClientRect(),r=e.clientX-n.left,i=e.clientY-n.top;return{...t,left:Math.min(t.x,r),top:Math.min(t.y,i),width:Math.abs(r-t.x),height:Math.abs(i-t.y)}},N=(n,i)=>{let a=H(e,t.path)?.content??``;if(c.current===null)return;if(r===`comment`){let e=c.current.resolveViewportRegion({left:n.clientX,top:n.clientY,right:n.clientX,bottom:n.clientY}),t=e===null?0:a.lastIndexOf(`
|
|
91
|
+
`,e.from-1)+1,r=e===null?-1:a.indexOf(`
|
|
92
|
+
`,e.from);A(e===null?void 0:{from:t,to:r===-1?a.length:r},`point`,`Click a line with text to comment on it.`);return}let o=oe(n,i);if(o.width<4&&o.height<4)return;let s=n.currentTarget.getBoundingClientRect(),l=c.current.resolveViewportRegion({left:s.left+o.left,top:s.top+o.top,right:s.left+o.left+o.width,bottom:s.top+o.top+o.height});A(l===null?void 0:{from:l.from,to:l.to},`region`,`Drag over some text to mark it.`)},se=ae?j(`div`,{"data-testid":`author-text-overlay`,className:`absolute inset-0 z-10 touch-none ${r===`mark`?`cursor-crosshair`:`cursor-pointer`}`,onPointerDown:e=>{if(e.button!==0)return;e.preventDefault();let t=e.currentTarget.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top;f({pointerId:e.pointerId,x:n,y:r,left:n,top:r,width:0,height:0}),e.currentTarget.setPointerCapture(e.pointerId)},onPointerMove:e=>{r===`mark`&&d?.pointerId===e.pointerId&&f(oe(e,d))},onPointerUp:e=>{let t=d;if(f(void 0),t===void 0||t.pointerId!==e.pointerId)return;if(!n){N(e,t);return}if(l.current===null)return;if(r===`comment`){let t=window.document.elementsFromPoint(e.clientX,e.clientY).find(e=>l.current?.contains(e)&&e.closest(ci)!==null)?.closest(ci);if(!t)return;let n=window.document.createRange();n.selectNodeContents(t),ie(n,`point`);return}let i=oe(e,t);if(i.width<4||i.height<4)return;let a=e.currentTarget.getBoundingClientRect(),o=mi(l.current,new DOMRect(a.left+i.left,a.top+i.top,i.width,i.height));o===void 0?m(`Drag over some text to mark it.`):ie(o,`region`)},onPointerCancel:()=>f(void 0),onWheel:e=>n?void 0:s.current?.querySelector(`.cm-scroller`)?.scrollBy({left:e.deltaX,top:e.deltaY}),children:d===void 0||r!==`mark`?null:j(`div`,{"data-testid":`author-text-selection`,className:`pointer-events-none absolute border-2 border-dashed border-po-magenta bg-po-magenta/10`,style:{left:d.left,top:d.top,width:d.width,height:d.height}})}):null;return P(`div`,{ref:s,className:`flex min-h-0 flex-1 flex-col`,children:[C?P(`div`,{role:`toolbar`,"aria-label":`Format Markdown`,"data-testid":`author-format-toolbar`,className:`hidden shrink-0 items-center gap-1 border-b border-po-border bg-po-bg px-3 py-1.5 [@media(pointer:fine)]:flex`,children:[$e.map(({format:e,label:t,glyph:n})=>P(L,{size:`sm`,variant:`ghost`,"aria-label":t,title:t,className:`min-h-11 gap-1.5 [@media(pointer:fine)]:min-h-8`,onMouseDown:e=>e.preventDefault(),onClick:()=>te(e),children:[j(`span`,{"aria-hidden":`true`,className:`font-semibold`,children:n}),j(`span`,{className:`text-sm`,children:t})]},e)),j(`span`,{className:`ml-auto truncate text-sm text-po-dim`,children:`Select text, then format it.`})]}):null,C?P(`div`,{className:`shrink-0 border-b border-po-border bg-po-bg px-3 py-1.5 [@media(pointer:fine)]:hidden`,children:[j(L,{variant:`outline`,className:`min-h-11`,"aria-label":`Formatting`,"aria-haspopup":`dialog`,"aria-expanded":v,onPointerDown:O,onClick:()=>{x.current||O(),x.current&&b(!0)},children:`Formatting`}),j(si,{open:v,onOpenChange:b,onFormat:e=>{S.current===void 0&&(S.current=e,b(!1))},onCloseAutoFocus:re})]}):null,n?j(`div`,{"data-testid":`author-markdown`,className:`min-h-0 flex-1 overflow-auto bg-po-deep/50 p-6`,children:P(`div`,{className:`relative mx-auto min-h-full max-w-3xl`,children:[j(`article`,{ref:l,onPointerUp:M,onKeyUp:M,className:`min-h-full rounded-md bg-po-panel px-6 py-8 sm:px-10 text-lg leading-relaxed text-po-text shadow-sm ring-1 ring-po-border-soft [&::highlight(po-author-note)]:bg-po-tint-magenta [&_*::highlight(po-author-note)]:bg-po-tint-magenta`,children:j(g,{text:Zn(t.path)?`\`\`\`\`mermaid\n${t.content??``}\n\`\`\`\``:t.content??``,loadImage:D,documentPath:t.path,renderMediaReview:o})}),h.map((e,t)=>j(`span`,{"aria-hidden":`true`,"data-author-region":e.label,className:`pointer-events-none absolute z-10 flex h-6 min-w-6 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full border-2 px-1 text-sm font-semibold ${e.label===ui?`border-po-magenta bg-po-panel text-po-magenta`:`border-po-panel bg-po-magenta text-po-rail`}`,style:{left:e.left,top:e.top},children:e.label},`${e.label}-${String(t)}`)),se]})}):P(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,children:[j(ne,{value:t.content??``,path:t.path,"data-testid":`author-editor`,controllerRef:c,className:`min-h-0 flex-1`,onChange:n=>Ct(e,t.path,n),onSelect:n=>{u.current={from:n.from,to:n.to};let r=H(e,t.path),i=s.current?.getBoundingClientRect();r&&i&&n.from!==n.to&>(e,t.path,{documentPath:r.path,revision:r.version,sourceSha256:r.sourceSha256,quote:n.text,anchor:{kind:`text-range`,startOffset:n.from,endOffset:n.to,startLine:n.startLine,endLine:n.endLine},viewport:{width:i.width,height:i.height},createdAt:Date.now()})}}),se]}),p===void 0?null:j(`output`,{className:`shrink-0 border-t border-po-border bg-po-bg px-4 py-1.5 text-sm text-po-dim`,children:p}),P(`footer`,{className:`flex shrink-0 items-center gap-2 border-t border-po-border bg-po-bg px-4 py-1.5 text-sm text-po-dim`,children:[j(`span`,{className:`first-letter:uppercase`,children:t.kind}),j(`span`,{"aria-hidden":`true`,children:`·`}),P(`span`,{children:[ee,` line`,ee===1?``:`s`]})]})]})}var gi={select:`↖`,pan:`✋`,mark:`⌗`,comment:`●`,draw:`✎`},_i=new Map,vi=new Map,yi=new Map,bi=e=>e instanceof Error?e.message:String(e);function xi(e,t){Bn.session(e).bridgeClose({body:{alias:t}}).then(e=>{e.ok||console.warn(`Author canvas '${t}' did not close: ${e.error}`)}).catch(e=>console.warn(`Author canvas '${t}' did not close: ${bi(e)}`))}function Si(e){let t=2166136261;for(let n of z(e))t=Math.imul(t^n.charCodeAt(0),16777619);return`${Vn}${(t>>>0).toString(36)}`}function Ci(e){return(e?.annotations??[]).map((e,t)=>({ordinal:t+1,region:e}))}function wi(t){let{sessionId:n,statuses:r}=t,i=t.activeMinorModes?.includes(ve)===!0,a=D(Jt,e=>n===null?t.path:e[B(n,t.path)]??t.path),o=D(J,e=>t.alias??(n===null?void 0:e[B(n,t.path)])),c=D(Yt,e=>n===null?void 0:e[B(n,t.path)]),l=D(V.store,e=>n===null?void 0:e.documents[B(n,a)]),d=D(V.store,e=>n===null?void 0:e.sessions[n]),f=D(V.store,e=>W(n,a,e)),p=d?.toolsByDocument[z(a)]??`select`,[m,h]=E(!0),[g,_]=E(),v=d?.previewSelections?.[z(t.path)]??d?.previewSelections?.[z(a)],[y,b]=E(v!==void 0),[x,S]=E(!1);I(()=>{v!==void 0&&b(!0)},[v]);let C=l?.kind,w=l===void 0?void 0:{path:l.path,kind:l.kind,hasUnsavedChanges:l.version!==l.savedVersion,revision:l.savedVersion,sourceSha256:l.sourceSha256,...v===void 0?{}:{preview:v}},T=(w===void 0?void 0:(t.slotData?.(Gn)??[]).find(({data:e})=>e.embeddedPanel!==void 0&&(e.supportsSource===void 0||e.supportsSource(w))))?.data.embeddedPanel;if(I(()=>{if(n===null)return;let e=dt(n,a);return()=>ft(n,e)},[a,n]),I(()=>{if(!i||C===void 0||n===null||o===void 0)return;let e=Ar(n,a,C),t,r=!1;return ze(n,e,o).then(e=>{r?e():t=e}),()=>{r=!0,t?.()}},[i,o,C,a,n]),I(()=>{C===`html`&&p===`draw`&&S(!1)},[p,C]),l===void 0||n===null)return j(`p`,{className:`p-4 text-sm text-po-dim`,children:c??g??`Loading document...`});let ee=async()=>{let e=l.version,t=l.fragments;Dt(n,a),_(`saving`);try{let r=await ur(n,l);kt(n,a,r,e,t),_(`saved`)}catch(t){Ot(n,a,e),_(t instanceof Error?t.message:String(t))}},te=Kt(r),O=Ci(f),k=O.flatMap(({ordinal:e,region:t})=>t.anchor.kind===`story-preview-rect`?[{ordinal:e,mode:`region`,point:t.anchor.rect,rect:t.anchor.rect,stroke:t.stroke}]:t.anchor.kind===`story-preview-point`?[{ordinal:e,mode:`point`,point:t.anchor.point}]:[]),ne=j(hi,{sessionId:n,document:l,preview:l.kind===`markdown`&&m&&!te,activeTool:p,displayedRegions:O,candidate:f.candidate,renderMediaReview:e(t)}),re=l.kind===`html`&&!x?j(ai,{sessionId:n,document:l,activeTool:p,displayedRegions:O,pendingCandidate:f.candidate!==void 0},l.path):l.kind===`text`||l.kind===`markdown`||l.kind===`story-preview`||l.kind===`html`?ne:l.structuredFormat===void 0?j(ti,{sessionId:n,document:l,activeTool:p,displayedRegions:O,pendingCandidate:f.candidate!==void 0,seekRequest:d?.videoSeekRequest},l.path):j(oi,{sessionId:n,document:l,displayedRegions:O});return P(`section`,{"data-testid":`author-document`,className:`flex min-h-0 flex-1 flex-col`,children:[P(`header`,{className:`flex items-center gap-2 border-b border-po-border bg-po-bg px-4 py-2`,children:[j(u,{"aria-hidden":`true`,className:`size-4 shrink-0 text-po-dim`}),P(`strong`,{className:`min-w-0 truncate text-base font-medium text-po-hi`,children:[o===void 0?``:`${o} · `,l.title??j(`span`,{className:`font-mono`,children:l.path})]}),j(`span`,{className:`min-w-0 flex-1`,children:l.version===l.savedVersion?null:P(`span`,{className:`inline-flex items-center gap-1.5 text-sm text-po-dim`,children:[j(s,{tone:`green`,size:`md`}),`unsaved`]})}),T!==void 0&&w!==void 0?j(L,{size:`xs`,variant:y?`primary`:`outline`,"data-testid":`author-story-preview-toggle`,"aria-pressed":y,"aria-label":y?`show story source`:`show story preview`,onClick:()=>b(!y),children:y?`Source`:`Preview`}):null,l.kind===`markdown`?j(L,{size:`sm`,variant:`outline`,className:`min-h-11 [@media(pointer:fine)]:min-h-8`,"data-testid":`author-markdown-toggle`,onClick:()=>h(!m),children:j(`span`,{className:`first-letter:uppercase`,children:m?`edit`:`preview`})}):null,l.kind===`html`?j(L,{size:`sm`,variant:`outline`,className:`min-h-11 [@media(pointer:fine)]:min-h-8`,"data-testid":`author-html-toggle`,"aria-pressed":x,onClick:()=>S(!x),children:x?`Preview`:`Source`}):null,l.kind===`video`?j(`span`,{className:`text-base text-po-dim`,children:`Video feedback`}):j(L,{className:`min-h-11 px-4 text-base [@media(pointer:fine)]:min-h-8`,variant:`outline`,"data-testid":`author-save`,disabled:l.revisions.length===0||l.savingVersion!==void 0,onClick:()=>void ee(),children:y&&w?.hasUnsavedChanges?`Save & refresh`:`Save`})]}),g===void 0?null:j(`output`,{className:`px-4 py-1 text-sm text-po-dim`,children:g}),[`image`,`pdf`,`video`,`story-preview`,`html`].includes(l.kind)?j(`nav`,{"aria-label":`Author canvas tools`,className:`flex shrink-0 gap-1.5 overflow-x-auto border-b border-po-border bg-po-bg px-3 py-2 sm:hidden`,children:[`select`,`pan`,`mark`,`comment`,`draw`].map(e=>P(L,{size:`md`,variant:`outline`,className:`min-w-16 shrink-0 ${Fn(p===e,e!==`select`&&e!==`pan`)}`,"aria-label":`${e} tool`,"aria-pressed":p===e,onClick:()=>G(n,l.path,e),children:[j(`span`,{"aria-hidden":`true`,className:`text-lg leading-none`,children:gi[e]}),j(`span`,{className:`text-sm first-letter:uppercase`,children:e})]},e))}):null,P(`div`,{className:`relative flex min-h-0 flex-1 overflow-hidden`,children:[y&&T!==void 0&&w!==void 0?j(T,{...t,source:w,activeTool:p===`crop`?`select`:p,displayedAnnotations:k,pendingCandidate:f.candidate!==void 0,onAnnotationCandidate:e=>{jt(n,l.path,e.preview),gt(n,l.path,{documentPath:l.path,revision:l.version,sourceSha256:l.sourceSha256,mode:e.mode,stroke:e.stroke,anchor:e.mode===`region`&&e.rect!==void 0?{kind:`story-preview-rect`,rect:e.rect,preview:e.preview}:{kind:`story-preview-point`,point:e.point,preview:e.preview},viewport:e.preview.viewport,evidence:e.evidence,thumbnailUrl:e.thumbnailUrl,createdAt:Date.now()})}}):re,y&&T!==void 0&&w!==void 0?null:j(qt,{sessionId:n,document:l,visible:te})]}),[`image`,`pdf`,`video`,`story-preview`,`html`].includes(l.kind)?j(`div`,{className:`max-h-56 shrink-0 overflow-y-auto border-t border-po-border bg-po-bg p-3 sm:hidden`,children:j(Tn,{sessionId:n,document:l,drafts:f,submitCapture:t.submitCapture})}):null]})}var Ti={version:1,watchFocusedPath(e,t){let n=V.store.state.sessions[e]?.focusedDocument?.path;t(n);let r=V.store.subscribe(()=>{let r=V.store.state.sessions[e]?.focusedDocument?.path;r!==n&&(n=r,t(n))});return()=>r.unsubscribe()},createTab({sessionId:e,path:t,preview:n}){let r=z(t);if(e.trim()===``||r===``||t.startsWith(`/`)||/^[A-Za-z]:/.test(t)||t.replaceAll(`\\`,`/`).split(`/`).includes(`..`))throw Error(`Author source opening requires a session and a repository-relative path.`);if(n!==void 0&&(typeof n.appPath!=`string`||n.appPath.trim()===``||typeof n.storyExport!=`string`||!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(n.storyExport)||n.snapshot!==void 0&&typeof n.snapshot!=`boolean`))throw Error(`Author preview requires a project and an exact story export.`);let i=Jt.state[B(e,r)]??r,a=`${e}\n`,o=(Object.entries(Jt.state).find(([e,t])=>e.startsWith(a)&&t===i)?.[0])?.slice(a.length)??r;return mt(e,o,n),i!==o&&mt(e,i,n),Ei(o,J.state[B(e,o)])}};function Ei(e,t){let n=z(e);return{id:Si(n),label:t===void 0?tr(n):`${t} · ${tr(n)}`,retainComposer:!0,composerContext(e){let t=B(e,n),r=Jt.state[t]??n,i=J.state[t],a=tr(r);return{kind:`author-document`,source:`author`,id:r,label:i===void 0?a:`${i} · ${a}`,content:dn(r,i,W(e,r).annotations)}},onOpen(e){let r=B(e,n),i=new AbortController;_i.set(r,i),yi.delete(r),Yt.setState(e=>{let t={...e};return delete t[r],t}),(async()=>{let a=await Bn.session(e).documentsOpen({body:{path:n,...t===void 0?{}:{alias:t}},query:{session:e},signal:i.signal});if(!a.ok)throw Error(a.error);if(!(`alias`in a.data)||typeof a.data.alias!=`string`)throw Error(`The Author canvas did not return an alias. Reopen the document.`);let o=a.data,s=o.alias;if(i.signal.aborted||_i.get(r)!==i){(vi.get(`${e}\n${s}`)?.size??0)===0&&xi(e,s);return}J.setState(t=>({...t,[r]:s,[B(e,o.path)]:s})),Jt.setState(e=>({...e,[r]:o.path}));let c=`${e}\n${s}`,l=vi.get(c)??new Set;l.add(r),vi.set(c,l);let u=B(e,o.path);if(V.store.state.documents[u]===void 0){let t=await ir(e,o.path,i.signal);if(i.signal.aborted||_i.get(r)!==i)return;ut(e,t)}let d=V.store.state.documents[u];d!==void 0&&!i.signal.aborted&&await Re(e,s,Ar(e,o.path,d.kind))})().catch(e=>{!i.signal.aborted&&_i.get(r)===i&&Yt.setState(t=>({...t,[r]:e instanceof Error?e.message:String(e)}))}).finally(()=>{_i.get(r)===i&&_i.delete(r),yi.get(r)===i&&yi.delete(r)})},onClose(e){let r=B(e,n),i=Jt.state[r]??n;G(e,i,`select`),mt(e,n,void 0),i!==n&&mt(e,i,void 0);let a=_i.get(r);_i.delete(r);let o=J.state[r]??(a===void 0?t:void 0);if(o===void 0){a!==void 0&&yi.set(r,a);return}a?.abort();let s=vi.get(`${e}\n${o}`);s?.delete(r),s!==void 0&&s.size===0&&vi.delete(`${e}\n${o}`);let c=s===void 0||s.size===0;c&&Ve(e,o),J.setState(e=>{let t={...e};return delete t[r],t}),Jt.setState(e=>{let t={...e};return delete t[r],t}),Yt.setState(e=>{let t={...e};return delete t[r],t}),c&&xi(e,o)},panel:e=>j(wi,{...e,path:n})}}var Di=(e,t,n)=>{if(e.openSessionTab===void 0||e.closeSessionTab===void 0)return;let r=`${t}\n`,i=new Set(n.map(e=>e.alias));for(let[n,a]of vi)if(n.startsWith(r)&&!i.has(n.slice(r.length)))for(let n of a)e.closeSessionTab(t,Si(n.slice(r.length)));for(let{alias:i,path:a}of n)(vi.get(`${r}${i}`)?.size??0)>0||yi.has(B(t,z(a)))||e.openSessionTab(t,Ei(a,i))},Oi=M({requiredMinorMode:`author`,subscribe(e){let t=V.store.subscribe(e);return()=>t.unsubscribe()},fingerprint(e){if(e===null)return``;let t=`${e}\n`;return Object.keys(V.store.state.documents).filter(e=>e.startsWith(t)).sort().join(`
|
|
93
|
+
`)},resolve(e,t){if(e===null)return;let n=z(t.replace(/:\d+(?::\d+)?$/,``));return V.store.state.documents[B(e,n)]===void 0?void 0:Ei(n,J.state[B(e,n)])},openPath(e,t){if(e===null)return;let n=z(t);return n===``?void 0:Ei(n,J.state[B(e,n)])}}),ki=ce({slot:`author.open-source`,id:`author`,data:Ti}),Ai=ce({slot:`help.guides`,id:`Author`,order:40,data:{version:1,label:`Author`,guides:[{id:`review`,question:`How do I review a document with Po?`,order:0,answer:`Open a document in an Author canvas to annotate it or give image feedback. Messages from its file tab include the document as context.`},{id:`mode`,question:`Do I need Author mode to open a document?`,order:1,answer:`Manual document tabs and annotation controls remain available with Author mode off. Turn the mode on to let the agent open and use a document’s canvas tools.`}]}}),ji=20971520,Mi=[137,80,78,71,13,10,26,10];async function Ni(e,t,n){if(e.sessionId!==t||e.mimeType!==`image/png`||!/^[a-zA-Z0-9_-]+$/u.test(t)||e.id.length===0||e.originalPath.length===0||!/^[a-f0-9]{64}$/u.test(e.sourceSha256))throw Error(`Image feedback requires a verified artifact from the active session.`);if(e.data.length>Math.ceil(ji/3)*4||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u.test(e.data))throw Error(`Image feedback PNG exceeds the size limit or is invalid.`);let r=atob(e.data),i=Uint8Array.from(r,e=>e.charCodeAt(0));if(i.length>ji||Mi.some((e,t)=>i[t]!==e))throw Error(`Image feedback requires PNG bytes.`);n.throwIfAborted();let a=new Uint8Array(await crypto.subtle.digest(`SHA-256`,i)),o=Array.from(a,e=>e.toString(16).padStart(2,`0`)).join(``);if(n.throwIfAborted(),o!==e.sourceSha256)throw Error(`Image feedback source digest does not match.`);return{path:`image-artifact/${encodeURIComponent(e.id)}/${o}.png`,kind:`image`,title:`Generated image feedback`,sourceSha256:o,imageData:e.data,mediaUrl:`image-artifact:${o}`,imageArtifact:{id:e.id,sessionId:t,originalPath:e.originalPath,sourceSha256:o}}}function Pi({target:e,sessionId:t,submitCapture:n}){let r=t===e.sessionId,[i,a]=E(),[o,s]=E();I(()=>{if(a(void 0),s(void 0),!r||t===null)return;let n=new AbortController,i;return Ni(e,t,n.signal).then(e=>{n.signal.aborted||(a(ut(t,e)),i=dt(t,e.path))}).catch(e=>{n.signal.aborted||s(e instanceof Error?e.message:String(e))}),()=>{n.abort(),i!==void 0&&ft(t,i)}},[r,t,e]);let c=D(V.store,e=>W(t,i?.path??``,e)),l=D(V.store,e=>t===null?`select`:e.sessions[t]?.toolsByDocument[i?.path??``]??`select`);if(!r||t===null)return null;if(o)return j(`output`,{children:o});if(!i||i.imageArtifact?.id!==e.id||i.sourceSha256!==e.sourceSha256)return j(`output`,{children:`Loading image feedback…`});let u=c.annotations.map((e,t)=>({ordinal:t+1,region:e}));return P(`section`,{className:`flex min-h-0 flex-col gap-3`,"data-testid":`author-image-feedback`,children:[j(`p`,{className:`text-sm text-po-dim`,children:`Original preserved. Submit annotations to request a new refinement.`}),j(`div`,{className:`sm:hidden`,children:j(In,{sessionId:t,path:i.path,kind:`image`,activeTool:l})}),j(ti,{sessionId:t,document:i,activeTool:l,displayedRegions:u,pendingCandidate:c.candidate!==void 0}),j(`div`,{className:`sm:hidden`,children:j(Tn,{sessionId:t,document:i,drafts:c,submitCapture:n})})]})}var Fi=ce({slot:`author.image-feedback`,id:`image-feedback`,data:{version:1,panel:Pi}}),Ii=4096,Li=8192;function Ri(e){let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)}async function zi(e,t){let n=new Image;if(n.src=await a(e.url,t),await n.decode(),t.throwIfAborted(),n.naturalWidth===0||n.naturalHeight===0)throw Error(`This picture has no size to annotate.`);let r=Math.min(1,Ii/Math.max(n.naturalWidth,n.naturalHeight)),i=document.createElement(`canvas`);i.width=Math.max(1,Math.round(n.naturalWidth*r)),i.height=Math.max(1,Math.round(n.naturalHeight*r));let o=i.getContext(`2d`);if(o===null)throw Error(`Canvas is unavailable.`);o.drawImage(n,0,0,i.width,i.height);let s;try{s=await new Promise(e=>i.toBlob(e,`image/png`))}catch{throw Error(`This picture comes from another site and cannot be annotated.`)}if(s===null)throw Error(`This picture could not be prepared for annotation.`);let c=new Uint8Array(await s.arrayBuffer()),l=new Uint8Array(await crypto.subtle.digest(`SHA-256`,c));t.throwIfAborted();let u=Array.from(l,e=>e.toString(16).padStart(2,`0`)).join(``);return{path:`markdown-media/${u}.png`,kind:`image`,title:e.title,sourceSha256:u,imageData:Ri(c),mediaUrl:`markdown-media:${u}`,markdownMedia:{kind:e.kind,...e.sourcePath===void 0?{}:{sourcePath:e.sourcePath},...e.documentPath===void 0?{}:{documentPath:e.documentPath},...e.mermaidSource===void 0?{}:{mermaidSource:e.mermaidSource.slice(0,Li)}}}}function Bi({media:e,sessionId:t,submitCapture:n}){let[r,i]=E(),[a,o]=E();I(()=>{if(i(void 0),o(void 0),t===null)return;let n=new AbortController,r;return zi(e,n.signal).then(e=>{n.signal.aborted||(i(ut(t,e)),r=dt(t,e.path))}).catch(e=>{n.signal.aborted||o(e instanceof Error?e.message:String(e))}),()=>{n.abort(),r!==void 0&&ft(t,r)}},[e,t]);let s=D(V.store,e=>W(t,r?.path??``,e)),c=D(V.store,e=>t===null?`select`:e.sessions[t]?.toolsByDocument[r?.path??``]??`select`);if(t===null)return j(`output`,{className:`p-4 text-po-dim`,children:`Open a session to review this picture.`});if(a)return j(`output`,{className:`p-4 text-po-red`,children:a});if(!r)return j(`output`,{className:`p-4 text-po-dim`,children:`Preparing the picture for review…`});let l=s.annotations.map((e,t)=>({ordinal:t+1,region:e}));return P(`section`,{"data-testid":`author-media-review`,className:`flex min-h-0 flex-1 flex-col sm:flex-row`,children:[j(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:j(ti,{sessionId:t,document:r,activeTool:c,displayedRegions:l,pendingCandidate:s.candidate!==void 0})}),P(`aside`,{className:`flex max-h-[45dvh] shrink-0 flex-col gap-4 overflow-y-auto border-t border-po-border bg-po-bg p-4 sm:max-h-none sm:w-80 sm:border-t-0 sm:border-l`,children:[j(In,{sessionId:t,path:r.path,kind:`image`,activeTool:c}),j(Tn,{sessionId:t,document:r,drafts:s,submitCapture:n})]})]})}var Vi=ce({slot:`author.media-review`,id:`media-review`,data:{version:1,panel:Bi}}),Hi=O({id:`author.toggle`,path:[{key:`o`,label:`other`,detail:`optional modes and tools`},{key:`a`,label:`author`,detail:`enable or disable focused document authoring`}],command:`minor author`}),Ui=`po-author-annotations`,Wi=`documents`,Gi=1;function Z(e){return typeof e==`object`&&!!e}function Q(e){return typeof e==`number`&&Number.isFinite(e)}function Ki(e){return Z(e)&&Q(e.x)&&Q(e.y)&&e.x>=0&&e.x<=1&&e.y>=0&&e.y<=1}function qi(e){return Ki(e)&&Z(e)&&Q(e.width)&&Q(e.height)&&e.width>0&&e.height>0&&Q(e.x)&&Q(e.y)&&e.x+e.width<=1&&e.y+e.height<=1}function Ji(e){return e===void 0||Z(e)&&typeof e.selector==`string`&&typeof e.tag==`string`}function Yi(e){if(!Z(e)||typeof e.kind!=`string`)return!1;switch(e.kind){case`text-range`:return Q(e.startOffset)&&Q(e.endOffset)&&Q(e.startLine)&&Q(e.endLine);case`cell`:return typeof e.fragmentId==`string`&&typeof e.location==`string`;case`slide-element`:return typeof e.fragmentId==`string`&&Q(e.slide)&&typeof e.location==`string`;case`image-rect`:return qi(e.rect)&&Q(e.naturalWidth)&&Q(e.naturalHeight);case`pdf-page-rect`:return Q(e.page)&&qi(e.rect);case`video-time-rect`:return Q(e.timeSeconds)&&qi(e.rect);case`story-preview-rect`:return qi(e.rect)&&Z(e.preview);case`image-point`:return Ki(e.point)&&Q(e.naturalWidth)&&Q(e.naturalHeight);case`pdf-page-point`:return Q(e.page)&&Ki(e.point);case`video-time-point`:return Q(e.timeSeconds)&&Ki(e.point);case`story-preview-point`:return Ki(e.point)&&Z(e.preview);case`html-rect`:return qi(e.rect)&&Ji(e.element);case`html-point`:return Ki(e.point)&&Ji(e.element);default:return!1}}function Xi(e){return e===void 0||typeof Blob<`u`&&e instanceof Blob&&e.size<=8388608}function Zi(e){return Z(e)?typeof e.documentPath==`string`&&z(e.documentPath)!==``&&Q(e.revision)&&(e.sourceSha256===void 0||typeof e.sourceSha256==`string`)&&(e.mode===void 0||e.mode===`region`||e.mode===`point`)&&Yi(e.anchor)&&(e.stroke===void 0||Zt(e.stroke)&&`rect`in e.anchor&&e.mode===`region`)&&Z(e.viewport)&&Q(e.viewport.width)&&Q(e.viewport.height)&&Q(e.createdAt)&&Xi(e.evidence):!1}function Qi(e){return Zi(e)&&Z(e)&&typeof e.id==`string`&&e.id!==``&&typeof e.comment==`string`&&e.comment.trim()!==``&&(e.version===void 0||Number.isInteger(e.version)&&e.version>=1)}function $i(e){return new TextEncoder().encode(e).byteLength}function ea(e){if(!Z(e)||e.version!==Gi||typeof e.key!=`string`||typeof e.sessionId!=`string`||e.sessionId===``||typeof e.documentPath!=`string`)return;let t=z(e.documentPath);if(t===``||e.key!==`${e.sessionId}\n${t}`||!Z(e.collection))return;let n=e.collection;if(!(!Q(n.revision)||n.sourceSha256!==void 0&&typeof n.sourceSha256!=`string`||typeof n.stale!=`boolean`||typeof n.candidateText!=`string`||$i(n.candidateText)>2048||!Array.isArray(n.annotations)||n.annotations.length>16||!n.annotations.every(Qi)||n.candidate!==void 0&&!Zi(n.candidate)||!Q(n.updatedAt)))return e}function ta(e){let{thumbnailUrl:t,...n}=e;return{...n,...e.stroke===void 0?{}:{stroke:e.stroke.map(e=>({...e}))}}}function na(){let e=[];for(let[t,n]of Object.entries(V.store.state.sessions))for(let[r,i]of Object.entries(n.annotationsByDocument))(i.annotations.length!==0||i.candidate!==void 0||i.candidateText!==``)&&e.push({key:`${t}\n${r}`,version:Gi,sessionId:t,documentPath:r,collection:{...i,candidate:i.candidate&&ta(i.candidate),annotations:i.annotations.map(ta)}});return e.sort((e,t)=>t.collection.updatedAt-e.collection.updatedAt).slice(0,100)}var ra=class{#e;#t=Promise.resolve();constructor(e){this.#e=new Promise((t,n)=>{let r=e.open(Ui,1);r.onupgradeneeded=()=>{r.result.objectStoreNames.contains(Wi)||r.result.createObjectStore(Wi,{keyPath:`key`})},r.onsuccess=()=>t(r.result),r.onerror=()=>n(r.error??Error(`Unable to open Author annotation storage.`))})}async load(){let e=await this.#e;return await new Promise((t,n)=>{let r=e.transaction(Wi,`readonly`).objectStore(Wi).getAll();r.onsuccess=()=>t(r.result),r.onerror=()=>n(r.error??Error(`Unable to read Author annotations.`))})}replace(e){let t=async()=>{let t=await this.#e;await new Promise((n,r)=>{let i=t.transaction(Wi,`readwrite`),a=i.objectStore(Wi);a.clear(),e.forEach(e=>a.put(e)),i.oncomplete=()=>n(),i.onerror=()=>r(i.error??Error(`Unable to write Author annotations.`)),i.onabort=()=>r(i.error??Error(`Author annotation write was aborted.`))})};return this.#t=this.#t.catch(()=>void 0).then(t),this.#t}async close(){try{await this.#t}finally{(await this.#e).close()}}};function ia(e){let t=typeof indexedDB>`u`?void 0:indexedDB;if(e===void 0&&t===void 0)return async()=>void 0;let n=e??new ra(t),r=!1,i=!1,a=!1,o=V.store.subscribe(()=>{i?n.replace(na()).catch(()=>void 0):a=!0});return n.load().then(e=>{if(r)return;let t=e.map(ea).filter(e=>e!==void 0).sort((e,t)=>t.collection.updatedAt-e.collection.updatedAt).slice(0,100);lt(t),i=!0,(a||t.length>0)&&n.replace(na()).catch(()=>void 0)}).catch(()=>{r||(i=!0,a&&n.replace(na()).catch(()=>void 0))}),async()=>{r=!0,o.unsubscribe(),await n.close()}}function aa(e){try{let t=JSON.parse(e);return t.version!==1||typeof t.captureId!=`string`||typeof t.capturedAt!=`number`||typeof t.document?.path!=`string`||typeof t.document.revision!=`number`||!Array.isArray(t.regions)||t.regions.length===0||t.regions.length>16||t.regions.some(e=>e.stroke!==void 0&&(!Zt(e.stroke)||e.mode!==`region`||!(`rect`in e.anchor)))?void 0:t}catch{return}}function oa(e){for(let t of e.contextItems){if(t.source!==`author`||t.kind!==`author-capture`)continue;let n=aa(t.metadata??t.content);if(n===void 0||n.captureId!==t.id||U(e.sessionId).requests.some(e=>e.captureId===n.captureId))continue;let r=n.regions.map(e=>({id:e.id,documentPath:n.document.path,revision:n.document.revision,sourceSha256:n.document.sourceSha256,comment:e.comment,version:e.version??1,mode:e.mode,quote:e.quote,anchor:structuredClone(e.anchor),...e.stroke===void 0?{}:{stroke:e.stroke.map(e=>({...e}))},viewport:{...e.viewport},voiceGrid:e.voiceGrid&&{...e.voiceGrid},createdAt:n.capturedAt}));xt(e.sessionId,{id:crypto.randomUUID(),captureId:n.captureId,documentPath:n.document.path,requestText:e.message,regions:r,pendingRegions:r,status:`REQUESTED`,createdAt:e.submittedAt,updatedAt:e.submittedAt,revision:n.document.revision,sourceSha256:n.document.sourceSha256});for(let t of n.regions)bt(e.sessionId,n.document.path,t.id,t.version??1)}}function sa(e){let t=U(e.sessionId).requests.find(t=>t.captureId===e.captureId);t===void 0||[`COMPLETE`,`FAILED`,`CANCELLED`,`UNTRACKED`].includes(t.status)||e.status!==`queued`&&St(e.sessionId,t.id,t=>({...t,status:e.status===`working`?`CHANGING`:e.status===`completed`?`COMPLETE`:e.status===`untracked`?`UNTRACKED`:`FAILED`,currentOperation:e.status===`working`?`Agent is working on this request`:void 0,pendingRegions:e.status===`completed`?[]:t.pendingRegions,error:e.status===`error`?e.error||`Request execution failed.`:void 0,updatedAt:Date.now()}))}function ca(e){let t=Le(e,Di),n=ia(),r=e.onComposerSubmitted?.(oa)??(()=>void 0),i=e.onCaptureStatus?.(sa)??(()=>void 0);return async()=>{r(),i(),t(),await n().catch(()=>void 0)}}var la=me(ca),ua=ue({name:`author`,keys:`o a`,order:45});function da(e){if(typeof e!=`object`||!e)return null;let t=e;return t.version===1&&typeof t.panel==`function`?t:null}var fa=w({slot:`author.image-feedback`,description:`Provide an annotation and feedback panel for an image artifact admitted by Author.`,parse:da}),pa=w(ge),ma=w({slot:`author.open-source`,description:`Offer an action that opens a source file in an Author canvas or transient tab.`,parse:Un}),ha=w(Gn),ga=w({description:`Render preview launch controls in Author. The provider owns its preview tab and lifecycle.`});function _a(e){return``}function va(e){return e===null?[]:fe(e.content).map(e=>({text:e,tone:`dim`}))}function ya({toolName:e,args:n,result:i,running:a,isError:s}){let c=va(i),u=N(c,8,!1);return j(t,{tone:b({running:a,isError:s}),expandable:u.hidden>0,children:({expanded:t})=>{let i=t?N(c,8,!0):u;return P(m,{children:[j(l,{title:e,children:j(`span`,{"data-testid":`tool-call-${e}`,className:`min-w-0 flex-1 truncate text-po-text`,children:_a(n)})}),i.shown.length>0?P(de,{"data-testid":`tool-result-${e}`,className:`flex flex-col gap-1`,children:[j(o,{lines:i.shown}),i.hidden>0?P(r,{expands:!0,children:[i.hidden,` more line(s)`]}):null]}):null]})}})}var ba=f({tools:[`describe_author_tools`],message:ya});function xa(e,t,n,r){let i=Ei(e,r);t(i),n(i.id)}function Sa(e){if(typeof e?.details==`object`&&e.details!==null&&`path`in e.details)return typeof e.details.path==`string`?e.details.path:void 0}function Ca({args:e,result:n,running:i,isError:a,output:s,openTransientTab:c,openTab:u}){let d=Sa(n),f=!i&&!a&&n!==null&&d===void 0,p=a?(s??``).trim().split(/\r?\n/u).filter(Boolean).slice(0,4).map(e=>({text:e,tone:`error`})):[],h=typeof e.path==`string`?e.path:`document`,g=typeof n?.details==`object`&&n.details!==null&&`alias`in n.details&&typeof n.details.alias==`string`?n.details.alias:void 0;return j(t,{tone:b({running:i,isError:a||f}),children:()=>P(m,{children:[j(l,{title:`open_authoring_file`,children:j(`span`,{"data-testid":`tool-call-open_authoring_file`,className:`min-w-0 flex-1 truncate text-po-text`,children:g===void 0?h:`${g} · ${h}`})}),!a||p.length>0?P(de,{"data-testid":`tool-result-open_authoring_file`,className:`flex flex-col gap-1`,children:[p.length>0?j(o,{lines:p}):null,a?null:j(r,{tone:f?`error`:i?`running`:void 0,children:i?`validating`:f?`unavailable`:d===void 0?`waiting`:`ready`}),!i&&!a&&d!==void 0?j(L,{size:`xs`,variant:`outline`,"data-testid":`author-open-file`,onClick:()=>xa(d,c,u,g),children:`open in Author`}):null]}):null]})})}var wa=f({tools:[`open_authoring_file`],message:Ca,completionTab:({result:e})=>{let t=Sa(e),n=e?.details;return t===void 0?void 0:Ei(t,typeof n?.alias==`string`?n.alias:void 0)}});function Ta(e){return typeof e.name==`string`?e.name:``}function Ea(e){return e===null?[]:fe(e.content).map(e=>({text:e,tone:`dim`}))}function Da({toolName:e,args:n,result:i,running:a,isError:s}){let c=Ea(i),u=N(c,8,!1);return j(t,{tone:b({running:a,isError:s}),expandable:u.hidden>0,children:({expanded:t})=>{let i=t?N(c,8,!0):u;return P(m,{children:[j(l,{title:e,children:j(`span`,{"data-testid":`tool-call-${e}`,className:`min-w-0 flex-1 truncate text-po-text`,children:Ta(n)})}),i.shown.length>0?P(de,{"data-testid":`tool-result-${e}`,className:`flex flex-col gap-1`,children:[j(o,{lines:i.shown}),i.hidden>0?P(r,{expands:!0,children:[i.hidden,` more line(s)`]}):null]}):null]})}})}var Oa=f({tools:[`use_author_tools`],message:Da}),$=(e,t)=>t===void 0?void 0:{...e,...t},ka=_({id:`author`,session:{get channels(){return[$({channel:`author_webmcp`},Gt)]},get dockFaces(){return[$({id:`authoring`},Rn)]},get fileLinks(){return Oi},get fills(){return[$({slot:`author.open-source`,id:`author`},ki),$({slot:`help.guides`,id:`author`},Ai),$({slot:`author.image-feedback`,id:`image-feedback`},Fi),$({slot:`author.media-review`,id:`media-review`},Vi)]},get leaderBindings(){return[$({id:`author.author-toggle`},Hi)]},get minorModes(){return[$({name:`author`},ua)]},get slots(){return[$({slot:`author.image-feedback`},fa),$({slot:`author.media-review`},pa),$({slot:`author.open-source`},ma),$({slot:`author.preview-action`},ha),$({slot:`author.preview-provider`},ga)]},get start(){return la},get toolRenderers(){return[$({tools:[`describe_author_tools`]},ba),$({tools:[`open_authoring_file`]},wa),$({tools:[`use_author_tools`]},Oa)]}}});export{ka as webPlugin};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{St as e,br as t,hr as n}from"../chunks/po-web-runtime-BJDT6Lbw.js";var r={1:{ratio:.5,capTokens:2e5},2:{ratio:.75,capTokens:5e5},3:{ratio:.95,capTokens:8e5}},i=`autocompact`,a=[`modes`,i],o=`thresholds`,s=`inherit the session model`,c=`inherit`,l=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`],u=[`true`,`false`],d={id:i,label:`autocompact`,detail:`the model that writes checkpoint summaries, and when each compaction pass fires`,order:40,fields:[{id:`enabled`,label:`enabled`,keyPath:[...a,`enabled`],placeholder:`on`,detail:`off leaves compaction to Pi. unset is on.`,options:u},{id:`model`,label:`summarization model`,keyPath:[...a,`model`],placeholder:s,detail:`model that writes the checkpoint summaries.`,models:!0},{id:`thinking`,label:`summarization thinking`,keyPath:[...a,`thinking`],placeholder:c,detail:`thinking level appended to the summarization model.`,options:l},{id:`thresholds.pass1`,label:`pass 1 threshold`,keyPath:[...a,o,`pass1`],placeholder:String(r[1].ratio),detail:`fraction of the remaining context window at which the first pass fires.`},{id:`thresholds.pass2`,label:`pass 2 threshold`,keyPath:[...a,o,`pass2`],placeholder:String(r[2].ratio),detail:`second pass. a value below pass 1 is raised back to it.`},{id:`thresholds.pass3`,label:`pass 3 threshold`,keyPath:[...a,o,`pass3`],placeholder:String(r[3].ratio),detail:`last pass before Pi compacts natively. a value below pass 2 is raised back to it.`}].map(e=>({id:e.id,label:e.label,kind:e.models===!0||e.options!==void 0?`select`:`text`,keyPath:e.keyPath,detail:e.detail,placeholder:e.placeholder,...e.models===!0?{optionsFrom:`models`}:{},...e.options===void 0?{}:{options:e.options.map(e=>({value:e,label:e}))}}))},f=n({...d,icon:e}),p=n({...d,icon:e}),m=(e,t)=>t===void 0?void 0:{...e,...t},h=t({id:`autocompact`,global:{get settingsSections(){return[m({id:`autocompact`},f)]}},workspace:{get settingsSections(){return[m({id:`autocompact`},p)]}}});export{h as webPlugin};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{Bt as e,C as t,E as n,T as r,_r as i,a,br as o,cn as s,dn as c,kt as l,o as u,s as d,w as f}from"../chunks/po-web-runtime-BJDT6Lbw.js";var p=51200,m=1024;function h(e){return e.filter(e=>e!==void 0&&e.length>0)}function g(e,t){return typeof e==`number`&&Number.isFinite(e)?`${e} ${t}`:void 0}function _(e){return typeof e==`string`&&e.length>0?e:`.`}function v(e){return e<m?`${e}B`:e<m*m?`${(e/m).toFixed(1)}KB`:`${(e/(m*m)).toFixed(1)}MB`}function y(e,t){let n=typeof e.content==`string`?e.content:``,r=typeof e.path==`string`?e.path:``,i=`${n.length.toLocaleString(`en-US`)} chars`;if(n.length===0)return{path:r,size:i,preview:[],hidden:0,gutter:1};let a=n.replaceAll(` `,` `).replaceAll(`\r
|
|
2
|
+
`,`
|
|
3
|
+
`).split(`
|
|
4
|
+
`);for(;a.at(-1)===``;)a.pop();let o=t?a:a.slice(0,10);return{path:r,size:i,preview:o.map((e,t)=>({number:t+1,text:e})),hidden:a.length-o.length,gutter:String(o.length).length}}function b(e){return{primary:typeof e.pattern==`string`?e.pattern:``,details:h([_(e.path),g(e.limit,`results`)])}}function x(e){return{primary:_(e.path),details:h([g(e.limit,`entries`)])}}function S(e){let t=e.replace(/\/$/,``).lastIndexOf(`/`);return t<0?{name:e,folder:``}:{name:e.slice(t+1),folder:e.slice(0,t)}}function C(e,t){return e===null?t:e.content.flatMap(e=>{let t=typeof e==`object`&&e?e:{};return t.type===`text`&&typeof t.text==`string`?[t.text]:[]}).join(`
|
|
5
|
+
`)}function w(e,t,n,r,i){let a=C(e,t).trim(),o=a.length===0?[]:a.split(`
|
|
6
|
+
`),s=n?o:o.slice(0,20),c=typeof e?.details==`object`&&e.details!==null?e.details:{},l=c[r],u=typeof c.truncation==`object`&&c.truncation!==null?c.truncation:void 0,d=[];return typeof l==`number`&&l>0&&d.push(`${l} ${i} limit`),u?.truncated===!0&&d.push(`${v(typeof u.maxBytes==`number`?u.maxBytes:p)} limit`),{lines:s,hidden:o.length-s.length,truncated:d.length>0?`[Truncated: ${d.join(`, `)}]`:void 0}}function T({tool:e,limitKey:t,limitUnit:r,expanded:i,props:a}){let{result:o,output:s,running:c,isError:l}=a;if(l)return u(f,{"data-testid":`tool-result-${e}`,className:`flex flex-col`,children:u(`span`,{className:`whitespace-pre-wrap break-words text-po-red`,children:C(o,s)})});if(o===null)return c?u(f,{"data-testid":`tool-result-${e}`,children:u(n,{tone:`running`,children:`running`})}):null;let p=w(o,s,i,t,r);return p.lines.length===0&&p.truncated===void 0?null:d(f,{"data-testid":`tool-result-${e}`,className:`flex flex-col font-mono`,children:[p.lines.map((e,t)=>{let n=S(e);return d(`span`,{title:e,className:`flex min-w-0 items-baseline gap-2`,children:[u(`span`,{className:`max-w-full shrink-0 truncate text-po-text`,children:n.name}),n.folder.length>0?u(`span`,{className:`min-w-0 truncate text-po-dim`,children:n.folder}):null]},`${String(t)}-${e}`)}),p.hidden>0?d(n,{expands:!0,children:[p.hidden,` more lines`]}):null,p.truncated===void 0?null:u(`span`,{className:`text-po-yellow`,children:p.truncated})]})}var E=`resultLimitReached`,D=`results`;function O(e){let n=b(e.args);return u(t,{tone:s({running:e.running,isError:e.isError}),expandable:!0,children:({expanded:t})=>d(a,{children:[u(r,{title:`find`,children:d(`span`,{"data-testid":`tool-call-find`,className:`flex min-w-0 flex-1 items-center gap-2`,children:[u(`span`,{className:`truncate text-po-text`,children:n.primary}),n.details.length>0?d(`span`,{className:`shrink-0 text-po-faint`,children:[`· `,n.details.join(` · `)]}):null]})}),t?u(T,{tool:`find`,limitKey:E,limitUnit:D,expanded:!0,props:e}):null]})})}var k=i({message:O}),A=`entryLimitReached`,j=`entries`;function M(e){let n=x(e.args);return u(t,{tone:s({running:e.running,isError:e.isError}),expandable:!0,children:({expanded:t})=>d(a,{children:[u(r,{title:`ls`,children:d(`span`,{"data-testid":`tool-call-ls`,className:`flex min-w-0 flex-1 items-center gap-2`,children:[u(`span`,{className:`truncate text-po-text`,children:n.primary}),n.details.length>0?d(`span`,{className:`shrink-0 text-po-faint`,children:[`· `,n.details.join(` · `)]}):null]})}),t?u(T,{tool:`ls`,limitKey:A,limitUnit:j,expanded:!0,props:e}):null]})})}var N=i({message:M});function P({view:e,path:t}){let n=c(e.preview.map(e=>e.text).join(`
|
|
7
|
+
`),{path:t});return u(a,{children:e.preview.map((t,r)=>d(`span`,{className:`flex gap-2`,children:[u(`span`,{className:`shrink-0 text-right text-po-faint`,style:{width:`${String(e.gutter)}ch`},children:t.number}),u(l,{spans:n?.[r],text:t.text,className:`min-w-0 whitespace-pre-wrap break-words text-po-text`})]},t.number))})}function F({args:i,result:o,output:c,running:l,isError:p,fileTabFor:m,openTransientTab:h}){let g=y(i,!1),_=m(g.path);return u(t,{tone:s({running:l,isError:p}),expandable:!0,children:({expanded:t})=>{let s=t?y(i,!0):g;return d(a,{children:[u(r,{title:`write`,children:d(`span`,{"data-testid":`tool-call-write`,className:`flex min-w-0 flex-1 items-center gap-2`,children:[u(e,{path:s.path,..._===void 0?{}:{onOpen:()=>h(_)}}),d(`span`,{className:`shrink-0 text-po-faint`,children:[`· `,s.size]})]})}),t?p?u(f,{"data-testid":`tool-result-write`,className:`flex flex-col`,children:u(`span`,{className:`whitespace-pre-wrap break-words text-po-red`,children:C(o,c)})}):s.preview.length===0?l?u(f,{"data-testid":`tool-result-write`,children:u(n,{tone:`running`,children:`running`})}):null:d(f,{"data-testid":`tool-result-write`,className:`flex flex-col font-mono`,children:[u(P,{view:s,path:s.path}),s.hidden>0?d(n,{expands:!0,children:[s.hidden,` more lines`]}):null,l?u(n,{tone:`running`,children:`running`}):null]}):null]})}})}var I=i({message:F}),L=(e,t)=>t===void 0?void 0:{...e,...t},R=o({id:`builtin-tools`,session:{get toolRenderers(){return[L({tools:[`find`]},k),L({tools:[`ls`]},N),L({tools:[`write`]},I)]}}});export{R as webPlugin};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{$t as e,C as t,E as n,Ht as r,T as i,_r as a,a as o,b as s,br as c,cn as l,o as u,pn as d,s as f,w as p}from"../chunks/po-web-runtime-BJDT6Lbw.js";var m=`exec`,h=`discover`,g=120,_=160,v=50,y=/^image\/(?:png|jpeg|webp|gif)$/u,b=/^Saved as (\S+) \((.+)\)$/u,x=/^(?:#{1,6} |```)/mu;function S(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function C(e,t){return e.length<=t?e:`${e.slice(0,t-1)}…`}function w(e){return typeof e.code==`string`?e.code:``}function T(e){let t=w(e).split(`
|
|
2
|
+
`).map(e=>e.trim()).find(e=>e!==``);return t===void 0?`script`:C(t.replace(/^\/\/+\s*/u,``),g)}function E(e){let t=S(e);if(t===void 0||typeof t.name!=`string`||t.name===``)return;let n=S(t.result);return{name:t.name,args:S(t.args)??{},ok:t.ok!==!1,ms:typeof t.ms==`number`&&Number.isFinite(t.ms)&&t.ms>=0?Math.round(t.ms):0,...typeof t.tool==`string`&&t.tool!==``?{tool:t.tool}:{},...typeof t.error==`string`&&t.error!==``?{error:t.error}:{},...n!==void 0&&Array.isArray(n.content)?{result:{content:n.content,details:n.details}}:{}}}function D(e){let t=S(e)?.calls;return Array.isArray(t)?t.slice(0,v).map(E).filter(e=>e!==void 0):[]}function O(e){return C(Object.entries(e).map(([e,t])=>`${e}: ${typeof t==`string`?t:JSON.stringify(t)??String(t)}`).join(` · `),_)}function k(e){let t;try{t=JSON.parse(e)}catch{return e.split(`
|
|
3
|
+
`).join(` `)}let n=S(t);return n!==void 0&&Object.keys(n).length>0?O(n):C(JSON.stringify(t),_)}function A(e){if(e===null)return{lines:[],images:[]};let t,n=[],r=[];for(let i of e.content){let e=S(i);if(e?.type===`text`&&typeof e.text==`string`){let r=b.exec(e.text.trim());r?.[1]!==void 0&&r[2]!==void 0?t={id:r[1],path:r[2]}:n.push(e.text)}else e?.type===`image`&&typeof e.data==`string`&&typeof e.mimeType==`string`&&y.test(e.mimeType)&&r.push({mimeType:e.mimeType,data:e.data})}let i=n.join(`
|
|
4
|
+
`).replaceAll(`\r
|
|
5
|
+
`,`
|
|
6
|
+
`).replaceAll(`\r`,`
|
|
7
|
+
`).replaceAll(` `,` `).split(`
|
|
8
|
+
`);for(;i.length>0&&i.at(-1)?.trim()===``;)i.pop();return{lines:i,...t===void 0?{}:{saved:t},images:r}}function j(e){return x.test(e)}function M(e){return typeof e.namespace==`string`&&e.namespace!==``?e.namespace:typeof e.query==`string`&&e.query!==``?`find "${C(e.query,g)}"`:`namespaces and scripts`}function N({args:e,output:r,running:a,isError:s,defaultExpanded:c=!1}){let m=typeof e.namespace==`string`&&e.namespace!==``&&!s;return u(t,{tone:l({running:a,isError:s}),expandable:!0,defaultExpanded:c,children:({expanded:t})=>f(o,{children:[u(i,{title:h,children:u(`span`,{"data-testid":`tool-call-${h}`,className:`min-w-0 flex-1 truncate text-po-text`,children:M(e)})}),t?f(p,{"data-testid":`tool-result-${h}`,className:`flex flex-col gap-2`,children:[a&&r===``?u(n,{tone:`running`,children:`running`}):null,r===``?null:m?u(`div`,{className:`max-h-96 overflow-auto`,children:u(d,{text:r,className:`language-ts`})}):u(`pre`,{"data-testid":`tool-output`,className:`max-h-96 overflow-auto font-mono text-sm break-words whitespace-pre-wrap ${s?`text-po-red`:`text-po-text`}`,children:r})]}):null]})})}var P=a({message:N});function F({label:e,children:t}){return f(`section`,{className:`flex flex-col gap-1.5`,children:[u(`h4`,{className:`text-sm font-medium text-po-dim`,children:e}),t]})}var I=`relative before:absolute before:top-[1.125rem] before:-left-4 before:w-3 before:border-t before:border-po-border-soft`,L=`flex min-h-6 cursor-pointer list-none items-center gap-x-2 gap-y-0.5 [&::-webkit-details-marker]:hidden`;function R(){return u(`span`,{"aria-hidden":!0,className:`w-3 shrink-0 text-center text-po-dim transition-transform group-open:rotate-90`,children:`›`})}function z({text:e,images:t,label:n,review:i}){return f(o,{children:[j(e)?u(`div`,{"data-testid":`tool-output-document`,className:`max-h-96 overflow-auto text-sm`,children:u(s,{text:e,renderMediaReview:i})}):null,t.map((e,t)=>u(r,{src:`data:${e.mimeType};base64,${e.data}`,alt:`${n} image ${String(t+1)}`,renderReview:i,"data-testid":`tool-output-image`,className:`max-h-48 max-w-full rounded-md border border-po-border-soft`},`${e.mimeType}-${String(t)}`))]})}function B({call:e,review:t}){let n=A(e.result??null),r=n.lines.join(`
|
|
9
|
+
`),i=r!==``&&(!e.ok||!j(r)),a=Object.keys(e.args).length>0||i||e.error!==void 0,s=f(o,{children:[u(`span`,{className:`shrink-0 truncate font-mono font-semibold text-po-text max-sm:basis-full`,children:e.name}),u(`span`,{className:`min-w-0 flex-1 truncate font-mono text-po-dim group-open:invisible`,children:O(e.args)}),u(`span`,{"aria-hidden":!0,className:`w-3 shrink-0 text-center ${e.ok?`text-po-green`:`text-po-red`}`,children:e.ok?`✓`:`✗`}),u(`span`,{className:`sr-only`,children:e.ok?`completed`:`failed`}),f(`span`,{className:`w-16 shrink-0 text-right tabular-nums text-po-dim`,children:[e.ms,` ms`]})]});return f(`div`,{"data-testid":`exec-call`,className:`flex flex-col gap-2 py-1.5`,children:[a?f(`details`,{className:`group text-sm`,children:[f(`summary`,{className:`${L} flex-wrap`,children:[s,u(R,{})]}),f(`div`,{className:`mt-2 flex flex-col gap-2`,children:[Object.keys(e.args).length>0?u(d,{text:JSON.stringify(e.args,null,2),className:`language-json`}):null,i?u(`pre`,{"data-testid":`exec-call-output`,className:`max-h-72 overflow-auto font-mono text-sm break-words whitespace-pre-wrap text-po-text`,children:r}):null,e.error===void 0?null:u(`p`,{className:`text-sm break-words text-po-red`,children:e.error})]})]}):u(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-sm`,children:s}),u(z,{text:e.ok?r:``,images:n.images,label:e.name,review:t})]})}function V({result:e,isError:t,review:n}){let r=A(e),i=r.lines.join(`
|
|
10
|
+
`),a=t?`Error`:`Returned`,o=t?`text-po-red`:`text-po-text`;return f(`div`,{"data-testid":`tool-result-${m}`,className:`flex flex-col gap-2`,children:[r.lines.length===0?u(`p`,{className:`text-sm text-po-dim`,children:t?`Failed with no output.`:`Returned nothing.`}):!t&&j(i)?u(`p`,{className:`text-sm font-semibold text-po-dim`,children:a}):f(`details`,{className:`group text-sm`,children:[f(`summary`,{className:`${L} text-po-dim hover:text-po-blue`,children:[u(`span`,{className:`shrink-0 font-semibold`,children:a}),u(`span`,{className:`min-w-0 flex-1 truncate font-mono group-open:hidden ${o}`,children:k(i)}),u(R,{})]}),u(`pre`,{"data-testid":`tool-output`,className:`mt-1 max-h-72 overflow-auto font-mono text-sm break-words whitespace-pre-wrap ${o}`,children:i})]}),u(z,{text:t?``:i,images:r.images,label:`Script`,review:n})]})}function H(n){let{args:r,result:a,running:s,isError:c,defaultExpanded:h=!1,renderTool:g}=n,_=e(n),v=w(r),y=A(a).saved,b=D(a?.details),x=b.filter(e=>!e.ok).length,S=!s||a!==null;return u(t,{tone:l({running:s,isError:c}),expandable:v!==``,defaultExpanded:h,children:({expanded:e})=>f(o,{children:[f(i,{title:m,children:[u(`span`,{"data-testid":`tool-call-${m}`,className:`min-w-0 flex-1 truncate text-po-text`,children:T(r)}),b.length>0?f(`span`,{className:`shrink-0 text-sm text-po-dim`,children:[b.length,` `,b.length===1?`call`:`calls`,x>0?f(`span`,{className:`text-po-red`,children:[`, `,x,` failed`]}):null]}):null]}),e?f(p,{className:`flex flex-col gap-2`,children:[u(F,{label:`Code`,children:u(d,{text:v,className:`language-ts`})}),y===void 0?null:f(`p`,{className:`text-sm text-po-dim`,title:y.path,children:[`Saved as `,u(`span`,{className:`font-mono text-po-text`,children:y.id})]})]}):null,S?f(`ol`,{"aria-label":`Script calls`,className:`mx-4 mb-3 flex flex-col gap-2 border-l border-po-border-soft pl-4 sm:ml-[2.125rem]`,children:[b.map((e,t)=>{let n=e.tool===void 0||g===void 0?null:g({toolName:e.tool,args:e.args,result:e.result??null,isError:!e.ok});return u(`li`,{className:`${I} flex flex-col gap-2`,children:n===null?u(B,{call:e,review:_}):f(o,{children:[n,u(z,{text:``,images:A(e.result??null).images,label:e.name,review:_})]})},`${String(t)}-${e.name}`)}),u(`li`,{className:I,children:u(V,{result:a,isError:c,review:_})})]}):null]})})}var U=a({message:H}),W=(e,t)=>t===void 0?void 0:{...e,...t},G=c({id:`codemode`,session:{get toolRenderers(){return[W({tools:[`discover`]},P),W({tools:[`exec`]},U)]}}});export{G as webPlugin};
|