@popmelt.com/core 0.38.1 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/claude-plugin/.claude-plugin/plugin.json +1 -1
- package/codex-plugin/.codex-plugin/plugin.json +1 -1
- package/dist/{ExploreAttachment-IIEORQP3.mjs → ExploreAttachment-OA2PUTNR.mjs} +1 -1
- package/dist/PagePreviewLayer-HKADULHD.mjs +1 -0
- package/dist/ParticipantRuntime-IU2STHIT.mjs +1 -0
- package/dist/PhoneHostGate-CS3KFCP5.mjs +1 -0
- package/dist/PopmeltTasteConnectedPane-TRQCY5SM.mjs +1 -0
- package/dist/{SamplePlacementOverlay-EOJW6XGE.mjs → SamplePlacementOverlay-SNA4WB6Z.mjs} +1 -1
- package/dist/ShareProjectPane-QLHMNZNU.mjs +1 -0
- package/dist/SuppliedContext-SFOM3R3K.mjs +1 -0
- package/dist/{ThreadErrorCard-CTMVMETS.mjs → ThreadErrorCard-NJUVLWMU.mjs} +1 -1
- package/dist/ThreadPanel-RVCNMX7B.mjs +1 -0
- package/dist/adapter-react-three-fiber.mjs +1 -1
- package/dist/adapter-three.d.mts +9 -8
- package/dist/adapter-three.mjs +3 -3
- package/dist/bridge-entry.mjs +1 -1
- package/dist/{bridgeSSEStream-HUFNXYPG.mjs → bridgeSSEStream-2KKFO64A.mjs} +1 -1
- package/dist/{bridgeWebSocketStream-AS22Y2FP.mjs → bridgeWebSocketStream-XTHQPBPI.mjs} +1 -1
- package/dist/browser-runtime-BUC4RUD7.mjs +1 -0
- package/dist/browser.mjs +1 -1
- package/dist/canvas-chat-note-XMVKWL2J.mjs +1 -0
- package/dist/{checkFixture-UNTXJKRN.mjs → checkFixture-I2ALOQTM.mjs} +1 -1
- package/dist/chunk-4B6HUJCH.mjs +1 -0
- package/dist/{chunk-BJUSVIDN.mjs → chunk-4LN72RDZ.mjs} +1 -1
- package/dist/{chunk-3VOEPWRL.mjs → chunk-5TCWBNV4.mjs} +1 -1
- package/dist/chunk-742KV4YS.mjs +1 -0
- package/dist/{chunk-WJVRGXOS.mjs → chunk-7D4BUDKG.mjs} +1 -1
- package/dist/chunk-ADOCYY5I.mjs +1 -0
- package/dist/chunk-B4RLDY5H.mjs +1 -0
- package/dist/chunk-B4ZKGIGU.mjs +1 -0
- package/dist/{chunk-ZHXTB5IN.mjs → chunk-BDUWFDBP.mjs} +1 -1
- package/dist/chunk-CHK24QU5.mjs +1 -0
- package/dist/{chunk-TCGXG7UA.mjs → chunk-CPFVBR6Q.mjs} +1 -1
- package/dist/{chunk-GTVTUWGH.mjs → chunk-D3BHAI37.mjs} +1 -1
- package/dist/chunk-DKBVNKIG.mjs +24 -0
- package/dist/chunk-EOAWCUFT.mjs +1 -0
- package/dist/{chunk-QXFBFKN6.mjs → chunk-EWTZVC7E.mjs} +1 -1
- package/dist/{chunk-2WQXHUEQ.mjs → chunk-FD6IIFJC.mjs} +1 -1
- package/dist/{chunk-TEXVTTWA.mjs → chunk-FPSR4NAR.mjs} +1 -1
- package/dist/{chunk-KHDXOXYF.mjs → chunk-G6ITTTFD.mjs} +1 -1
- package/dist/chunk-H4GG2RS4.mjs +1 -0
- package/dist/chunk-HM6EBJVO.mjs +1 -0
- package/dist/chunk-HOWDQUPT.mjs +1 -0
- package/dist/{chunk-XJJDBMZI.mjs → chunk-HQVWOBYH.mjs} +1 -1
- package/dist/chunk-IWF42SDV.mjs +1 -0
- package/dist/{chunk-GLF7Z5IR.mjs → chunk-K22VZV3V.mjs} +1 -1
- package/dist/chunk-K2OUXYDM.mjs +1 -0
- package/dist/chunk-KOHR4LAQ.mjs +1 -0
- package/dist/chunk-KY4YVZ3O.mjs +1 -0
- package/dist/chunk-LLVF422C.mjs +1 -0
- package/dist/chunk-LSKP5UC6.mjs +1 -0
- package/dist/{chunk-F3VZQGPM.mjs → chunk-LUTP7QBD.mjs} +1 -1
- package/dist/chunk-ML7YV4RV.mjs +1 -0
- package/dist/{chunk-TXL2CR66.mjs → chunk-MLNC5TMP.mjs} +1 -1
- package/dist/chunk-MSWRCFPJ.mjs +1 -0
- package/dist/chunk-NC7YXD7Q.mjs +1 -0
- package/dist/{chunk-BEGAJYOY.mjs → chunk-OEJXPUAR.mjs} +1 -1
- package/dist/{chunk-43BZCDGL.mjs → chunk-OL7RDZ2R.mjs} +1 -1
- package/dist/{chunk-N3MHDOMU.mjs → chunk-P3IOAIYB.mjs} +1 -1
- package/dist/chunk-PQKSXNIZ.mjs +1 -0
- package/dist/{chunk-AEC67LMY.mjs → chunk-QDFQPABM.mjs} +1 -1
- package/dist/chunk-RALP6ENI.mjs +30 -0
- package/dist/chunk-RRB5IHBT.mjs +1 -0
- package/dist/{chunk-UOK5LOPJ.mjs → chunk-UFUH63SR.mjs} +1 -1
- package/dist/chunk-UIADZXVT.mjs +1 -0
- package/dist/{chunk-JAMYVQFC.mjs → chunk-V56MNQLF.mjs} +1 -1
- package/dist/{chunk-5F34UIKL.mjs → chunk-VWFST2IX.mjs} +1 -1
- package/dist/{chunk-FQLIJAUB.mjs → chunk-W5JUAOLA.mjs} +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/codex-note-context-4ORRY4CH.mjs +1 -0
- package/dist/codex-project-LMAR3FMS.mjs +1 -0
- package/dist/{codex-store-mount-WJAATWHT.mjs → codex-store-mount-MNIL3VK6.mjs} +1 -1
- package/dist/dev-server-ZLT7TAUF.mjs +1 -0
- package/dist/guest-admission.mjs +1 -1
- package/dist/guest-live-canvas.mjs +1 -1
- package/dist/{index-CHp2bgs1.d.mts → index-D6bSXWNT.d.mts} +1 -1
- package/dist/index.mjs +1 -1
- package/dist/memory-legacy.d.mts +1 -1
- package/dist/memory-legacy.mjs +1 -1
- package/dist/memory-store.d.mts +84 -84
- package/dist/memory-store.mjs +1 -1
- package/dist/{page-interaction-TV3P6B3X.mjs → page-interaction-GC2UN47Y.mjs} +1 -1
- package/dist/{page-planes-2ZepTpen.d.mts → page-planes-9GVbnVZa.d.mts} +240 -1
- package/dist/peer-client-XNTMFSOV.mjs +1 -0
- package/dist/plugin-astro.d.mts +1 -1
- package/dist/plugin-astro.mjs +1 -1
- package/dist/plugin-nuxt.mjs +1 -1
- package/dist/plugin-vite.d.mts +1 -1
- package/dist/plugin-vite.mjs +1 -1
- package/dist/server.d.mts +4 -2
- package/dist/server.mjs +1 -1
- package/dist/shared-page-JN7T4DDQ.mjs +1 -0
- package/infra/phone-pairing/README.md +25 -0
- package/infra/phone-pairing/binding.mjs +105 -0
- package/infra/phone-pairing/machine-config.mjs +134 -0
- package/infra/phone-pairing/machine-service.mjs +159 -0
- package/infra/phone-pairing/machine.mjs +98 -0
- package/infra/phone-pairing/managed-install.mjs +179 -0
- package/package.json +42 -25
- package/dist/PagePreviewLayer-AFSRCBAX.mjs +0 -1
- package/dist/ParticipantRuntime-ZNEFG34O.mjs +0 -1
- package/dist/PhoneHostGate-OCIMKPLM.mjs +0 -1
- package/dist/PopmeltTasteConnectedPane-N2A5XPRO.mjs +0 -1
- package/dist/ShareProjectPane-VYWTF3FW.mjs +0 -1
- package/dist/SuppliedContext-3S4HT6U6.mjs +0 -1
- package/dist/ThreadPanel-G7OKSWD4.mjs +0 -1
- package/dist/browser-runtime-Q26JF5EA.mjs +0 -1
- package/dist/canvas-chat-note-OLVVP55Y.mjs +0 -1
- package/dist/chunk-2IWVTTYX.mjs +0 -1
- package/dist/chunk-3OGSLX4V.mjs +0 -1
- package/dist/chunk-A4GARXVQ.mjs +0 -1
- package/dist/chunk-AGCS65LT.mjs +0 -1
- package/dist/chunk-AYZUOBFI.mjs +0 -1
- package/dist/chunk-BOZVNUHJ.mjs +0 -1
- package/dist/chunk-DBCBG5J6.mjs +0 -1
- package/dist/chunk-EFWBHWHP.mjs +0 -1
- package/dist/chunk-FYURSPM3.mjs +0 -1
- package/dist/chunk-G6BN5TAZ.mjs +0 -1
- package/dist/chunk-IW7V7WNL.mjs +0 -1
- package/dist/chunk-JJK4LAN6.mjs +0 -1
- package/dist/chunk-JJRKR4X3.mjs +0 -1
- package/dist/chunk-KF73S7MG.mjs +0 -1
- package/dist/chunk-KL5ODVJA.mjs +0 -1
- package/dist/chunk-L356S4EY.mjs +0 -1
- package/dist/chunk-OZBMHEOD.mjs +0 -1
- package/dist/chunk-P2WAXWAZ.mjs +0 -1
- package/dist/chunk-PRPXMDZ7.mjs +0 -1
- package/dist/chunk-QQPUMPKU.mjs +0 -1
- package/dist/chunk-TSQEBZYO.mjs +0 -1
- package/dist/chunk-UTP56NCY.mjs +0 -1
- package/dist/chunk-VG4ZV2OT.mjs +0 -30
- package/dist/chunk-WC7B5NU3.mjs +0 -24
- package/dist/chunk-X6I6KQDG.mjs +0 -1
- package/dist/codex-note-context-4X7I5AIJ.mjs +0 -1
- package/dist/codex-project-Q6YT5P37.mjs +0 -1
- package/dist/dev-server-NROXLQKM.mjs +0 -1
- package/dist/peer-client-DWC5F6JN.mjs +0 -1
- package/dist/shared-page-GO76UP7I.mjs +0 -1
- /package/dist/{chunk-L45FX4SU.mjs → chunk-CZJILD7T.mjs} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as e}from"./chunk-TCGXG7UA.mjs";import{d as t}from"./chunk-AYZUOBFI.mjs";import{D as r,I as a,K as o,L as i,M as n,N as s,O as l,a as p,h as c,s as d}from"./chunk-VG4ZV2OT.mjs";import{b as w,e as m}from"./chunk-JJK4LAN6.mjs";import{a as u}from"./chunk-YMWXWXPV.mjs";import{a as h,b as _}from"./chunk-NOHXTT24.mjs";import{spawn as g}from"child_process";import{closeSync as f,openSync as P}from"fs";import{appendFile as E,mkdir as T,readFile as O,realpath as y}from"fs/promises";import{dirname as v,join as R}from"path";import{fileURLToPath as M}from"url";import{spawn as I}from"child_process";import{mkdtemp as C,readFile as L,rm as S}from"fs/promises";import{tmpdir as b}from"os";import{join as A}from"path";import x from"ws";async function N(e,t){let r=Date.now()+25e3;for(;Date.now()<r;){let t=await e();if(t)return t;await new Promise(e=>setTimeout(e,100))}throw new Error(`Timed out waiting for ${t}`)}function j(e){let t=new URL(e);if("http:"!==t.protocol||!["localhost","127.0.0.1"].includes(t.hostname)||t.username||t.password||t.hash||t.search)throw new Error("Managed participants require an explicit local app URL");return async e=>{let r,a,o=await C(A(b(),"popmelt-participant-")),i=I(process.env.CHROME_PATH??("darwin"===process.platform?"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome":"google-chrome"),["--headless=new","--no-first-run","--no-default-browser-check","--remote-debugging-address=127.0.0.1","--remote-debugging-port=0","--window-size=1440,1000",`--user-data-dir=${o}`,"about:blank"],{stdio:["ignore","ignore","pipe"]}),n="",s=!1,l=0,p=new Map;i.on("error",e=>{r=e}),i.stderr.on("data",e=>{n=(n+e).slice(-4e3)});let c=()=>{for(let e of p.values())clearTimeout(e.timer),e.reject(new Error("Participant browser disconnected"));p.clear()},d=async()=>{if(!s){if(s=!0,c(),a?.close(),i.pid&&null===i.exitCode&&null===i.signalCode){let e=new Promise(e=>i.once("exit",()=>e()));i.kill("SIGTERM");let t=setTimeout(()=>i.kill("SIGKILL"),3e3);await e,clearTimeout(t)}await S(o,{recursive:!0,force:!0})}};try{let w=await N(async()=>{if(r)throw r;if(null!==i.exitCode||null!==i.signalCode)throw new Error(`Participant browser exited: ${n}`);return L(A(o,"DevToolsActivePort"),"utf8").then(e=>e.split("\n")[0]).catch(()=>null)},"participant browser startup"),m=(await(await fetch(`http://127.0.0.1:${w}/json/list`,{signal:AbortSignal.timeout(3e3)})).json()).find(e=>"page"===e.type);if(!m)throw new Error("Participant browser has no page");a=new x(m.webSocketDebuggerUrl,{handshakeTimeout:5e3}),await new Promise((e,t)=>{a.once("open",e),a.once("error",t)}),a.on("close",c),a.on("error",c),a.on("message",e=>{let t=JSON.parse(e.toString()),r=p.get(t.id);r&&(p.delete(t.id),clearTimeout(r.timer),t.error?r.reject(new Error(t.error.message??"Participant browser request failed")):r.resolve(t.result))});let u=(e,t={})=>new Promise((r,o)=>{if(s||a?.readyState!==x.OPEN)return void o(new Error("Participant browser is closed"));let i=++l,n=setTimeout(()=>{p.delete(i),o(new Error(`Participant browser timed out: ${e}. Action was not retried.`))},35e3);p.set(i,{resolve:r,reject:o,timer:n}),a.send(JSON.stringify({id:i,method:e,params:t}))}),h=async(e,t=!1)=>{let r=await u("Runtime.evaluate",{expression:e,userGesture:t,awaitPromise:!0,returnByValue:!0});if(r.exceptionDetails)throw new Error("Participant action failed: "+JSON.stringify(r.exceptionDetails));return r.result?.value};await u("Page.enable"),await u("Runtime.enable");let _=(await u("Page.getFrameTree")).frameTree.frame.id,g=new Set,f=!1;await u("Runtime.addBinding",{name:"__popmeltCapture"}),a.on("message",e=>{let r=JSON.parse(e.toString());if("Runtime.executionContextCreated"===r.method){let e=r.params.context;e.auxData?.isDefault&&e.auxData.frameId===_&&g.add(e.id)}if("Runtime.executionContextDestroyed"===r.method&&g.delete(r.params.executionContextId),"Runtime.executionContextsCleared"===r.method&&g.clear(),"Runtime.bindingCalled"!==r.method||"__popmeltCapture"!==r.params.name||!g.has(r.params.executionContextId))return;let a,o=r.params.executionContextId,i=r.params.payload;if(i.length>22e4)return;try{a=JSON.parse(i)}catch{return}if(!Number.isSafeInteger(a.id)||!Array.isArray(a.selectors)||a.selectors.length>200||a.selectors.some(e=>"string"!=typeof e||e.length>1024))return;let n=e=>u("Runtime.evaluate",{contextId:o,expression:`window.__POPMELT_CAPTURE_DELIVER__?.(${a.id},${JSON.stringify(e)})`}).catch(()=>{});f?n(null):(f=!0,(async()=>{try{if(!await h(`location.origin + location.pathname === ${JSON.stringify(t.href)}`))return null;let e=await h(`window.__POPMELT_AGENT_VIEW__.geometry(${JSON.stringify(a.selectors)})`),r=e.clip;if(![r.x,r.y,r.width,r.height].every(Number.isFinite)||r.x<0||r.y<0||r.width<=0||r.height<=0||r.width>4096||r.height>4096)return null;await h("window.__POPMELT_CAPTURE_CHROME__ = [...document.querySelectorAll('[data-popmelt-top-layer-host]:not([data-popmelt-capture-hidden])')]; window.__POPMELT_CAPTURE_CHROME__.forEach(element => element.setAttribute('data-popmelt-capture-hidden', ''));");try{let t=await u("Page.captureScreenshot",{format:"jpeg",quality:80,captureBeyondViewport:!0,clip:{...r,scale:Math.min(1,1280/Math.max(r.width,r.height))}});return"string"!=typeof t.data||t.data.length>5e5?null:{image:"data:image/jpeg;base64,"+t.data,targets:e.targets}}finally{await h("window.__POPMELT_CAPTURE_CHROME__?.forEach(element => element.removeAttribute('data-popmelt-capture-hidden')); delete window.__POPMELT_CAPTURE_CHROME__;").catch(()=>{})}}catch{return null}})().then(n).finally(()=>{f=!1}))}),await u("Page.addScriptToEvaluateOnNewDocument",{source:`if (location.origin + location.pathname === ${JSON.stringify(t.href)}) {\n window.__POPMELT_AGENT_CREDENTIAL__ = ${JSON.stringify(e)};\n const waiting = new Map(); let id = 0;\n window.__POPMELT_CAPTURE_DELIVER__ = (id, frame) => { const pending = waiting.get(id); if (!pending) return; waiting.delete(id); clearTimeout(pending.timer); pending.resolve(frame); };\n window.__POPMELT_MANAGED_CAPTURE__ = () => { let stopped = false; const owned = new Set(); return {\n frame: selectors => stopped ? Promise.resolve(null) : new Promise(resolve => { const key = ++id; owned.add(key); const timer = setTimeout(() => window.__POPMELT_CAPTURE_DELIVER__(key, null), 5000); waiting.set(key, {resolve: frame => { owned.delete(key); resolve(frame); }, timer}); window.__popmeltCapture(JSON.stringify({id: key, selectors})); }),\n stop: () => { stopped = true; for (const key of owned) window.__POPMELT_CAPTURE_DELIVER__(key, null); }\n }; };\n }`});let P=()=>N(()=>h(`location.origin + location.pathname === ${JSON.stringify(t.href)} && Boolean(window.__POPMELT_AGENT_VIEW__)`),"native participant canvas");a.on("message",e=>{"Page.loadEventFired"===JSON.parse(e.toString()).method&&P().then(()=>h("window.__POPMELT_AGENT_VIEW__.share()",!0)).catch(()=>{})}),await u("Page.navigate",{url:t.href}),await P(),await h("window.__POPMELT_AGENT_VIEW__.share()",!0);let E=Promise.resolve();return{act(e){let t=E.then(async()=>(await P(),h(`window.__POPMELT_AGENT_VIEW__.act(${JSON.stringify(e)})`)));return E=t.catch(()=>{}),t},close:d}}catch(e){throw await d(),e}}}async function D(e){return y(e).catch(()=>e)}async function k(e,t){let r=(await O(t,"utf8").catch(()=>"")).slice(-8e3).trim();return new Error(r?`${e}\nBridge log (${t}):\n${r}`:e)}async function $(e){if("production"===process.env.NODE_ENV&&!e?.force)throw new Error("[Bridge] Refusing to start in production. Pass { force: true } to override.");if((e={...e,experimentalEventTransport:d(e?.experimentalEventTransport)}).detached){let t=e.projectRoot??process.cwd(),l=await u(R(t,".popmelt","bridge-start.lock"),()=>async function(e){let t,l=e.port??1111,d=await D(e.projectRoot??process.cwd()),w=c(d),m=await o(d);for await(let{port:o,status:i}of n(d,l))if(i.projectId===w){if(i.version&&i.version!==r&&"detached"===i.restartMode){t??={port:o,status:i};continue}if("detached"===i.restartMode&&i.version===r&&(i.eventTransport??"sse")!==e.experimentalEventTransport)throw new Error(`[Bridge] Transport conflict on port ${o}: the project is using ${i.eventTransport??"sse"}, but this client requested ${e.experimentalEventTransport}. Use the running transport or stop the bridge before switching.`);if(!a(i,{projectId:w,version:r,restartMode:"detached",eventTransport:e.experimentalEventTransport}))continue;let n=e.devOrigin;if(n&&i.devOrigin!==n)try{await fetch(`http://127.0.0.1:${o}/config`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({devOrigin:n})})}catch{}return process.env.POPMELT_BRIDGE_PORT=String(o),process.env.POPMELT_PROJECT_ID=w,{port:o,projectId:w,storeId:m.storeId,close:async()=>{}}}t&&await s(t.port,w,t.status);let u=R(v(M(import.meta.url)),"bridge-entry.mjs"),h=R(d,".popmelt"),_=R(h,"bridge.log");await T(h,{recursive:!0}),await E(_,`\n[${(new Date).toISOString()}] Starting detached bridge\n`);let O,y=P(_,"a");try{O=g(process.execPath,[u],{detached:!0,stdio:["ignore","ignore",y],env:{...process.env,POPMELT_PORT:String(l),POPMELT_PROJECT_ROOT:d,POPMELT_DEV_ORIGIN:e.devOrigin??"",POPMELT_CURSOR_PATH:e.cursorPath??process.env.POPMELT_CURSOR_PATH??"",POPMELT_OPENCODE_PATH:e.opencodePath??"",POPMELT_COPILOT_PATH:e.copilotPath??"",POPMELT_EXPERIMENTAL_EVENT_TRANSPORT:e.experimentalEventTransport}})}finally{f(y)}let I=null;O.once("error",e=>{I=`spawn error: ${e.message}`}),O.once("exit",(e,t)=>{I=`child exited before becoming healthy (${t?`signal ${t}`:`code ${e??"unknown"}`})`}),O.unref();let C=Date.now()+3e4;for(;Date.now()<C;){if(await new Promise(e=>setTimeout(e,100)),I)throw await k(`[Bridge] Detached bridge ${I}`,_);let t=await p(d);if(t&&t.pid===O.pid){let o=await i(t.port);if(a(o,{projectId:w,version:r,restartMode:"detached",eventTransport:e.experimentalEventTransport}))return process.env.POPMELT_BRIDGE_PORT=String(t.port),process.env.POPMELT_PROJECT_ID=w,{port:t.port,projectId:w,storeId:m.storeId,close:async()=>{}}}}throw O.kill("SIGTERM"),await k(`[Bridge] Detached bridge failed to start within 30s (port ${l})`,_)}(e),4e4);if(!1===e.manageLease)return l;let d=await h({port:l.port,projectId:l.projectId});if(!d)return console.warn("[popmelt] detached bridge started without a process lease"),l;let w=_(d);return{...l,close:async()=>{w(),await d.release()}}}let t=await l(e);return process.env.POPMELT_BRIDGE_PORT=String(t.port),process.env.POPMELT_PROJECT_ID=t.projectId,t}async function G(r){let a,o=await D(r.projectRoot??process.cwd()),i=r.devOrigin,n=r.framework&&await e(o,r.framework,r.nextBundler),s=n?.planes,l=r.readGuestApp??t(o,()=>i,r.framework,o,r.nextBundler),p=w(()=>c,async e=>{let t=e.basePath??"/";return("/"===t?l:await(s?.pageReader(t)))?.(e)},s),c=await $({...r,projectRoot:o,participantSessions:{...p,planeApps:s,...s&&{planeEntry:async(e,t)=>{a?.planeMiddleware?(e.headers.host=new URL(i).host,await a.planeMiddleware(e,t,()=>t.writeHead(404).end())):t.writeHead(503).end()}},hostEntry:(e,t)=>{if(a)return a.hostEntry(e,t);t.writeHead(503).end()}}}).catch(async e=>{throw await(n?.close()),e});try{let e;return a=await m({projectRoot:o,bridge:c,origin:i,planeApps:s,guestInvites:"lan"}),console.info("[popmelt] Open the local app in any browser on this machine. Private recovery link: .popmelt/participant-host-link.json."),{...c,bootstrap:s?{...await a.read(),appVersion:void 0}:await a.read(),readBootstrap:e=>a.read(e),close:()=>e??=(async()=>{try{a?.dispose(),await p.stopGuestSharing(),await(n?.close())}finally{await c.close()}})(),async updateOrigin(e){a?.dispose(),i=e,a=await m({projectRoot:o,bridge:c,origin:i,planeApps:s,guestInvites:"lan"})}}}catch(e){throw a?.dispose(),await(n?.close()),await c.close(),e}}export{j as a,$ as b,G as c};
|
|
1
|
+
import{d as e}from"./chunk-CPFVBR6Q.mjs";import{d as t}from"./chunk-IWF42SDV.mjs";import{D as r,I as a,K as o,L as i,M as n,N as s,O as l,a as p,h as c,s as d}from"./chunk-RALP6ENI.mjs";import{b as w,e as m}from"./chunk-LLVF422C.mjs";import{a as u}from"./chunk-YMWXWXPV.mjs";import{a as h,b as g}from"./chunk-NOHXTT24.mjs";import{spawn as _}from"child_process";import{closeSync as f,openSync as P}from"fs";import{appendFile as E,mkdir as T,readFile as O,realpath as y}from"fs/promises";import{dirname as R,join as v}from"path";import{fileURLToPath as M}from"url";import{spawn as I}from"child_process";import{mkdtemp as L,readFile as C,rm as S}from"fs/promises";import{tmpdir as b}from"os";import{join as x}from"path";import A from"ws";async function N(e,t){let r=Date.now()+25e3;for(;Date.now()<r;){let t=await e();if(t)return t;await new Promise(e=>setTimeout(e,100))}throw new Error(`Timed out waiting for ${t}`)}function j(e){let t=new URL(e);if("http:"!==t.protocol||!["localhost","127.0.0.1"].includes(t.hostname)||t.username||t.password||t.hash||t.search)throw new Error("Managed participants require an explicit local app URL");return async e=>{let r,a,o=await L(x(b(),"popmelt-participant-")),i=I(process.env.CHROME_PATH??("darwin"===process.platform?"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome":"google-chrome"),["--headless=new","--no-first-run","--no-default-browser-check","--remote-debugging-address=127.0.0.1","--remote-debugging-port=0","--window-size=1440,1000",`--user-data-dir=${o}`,"about:blank"],{stdio:["ignore","ignore","pipe"]}),n="",s=!1,l=0,p=new Map;i.on("error",e=>{r=e}),i.stderr.on("data",e=>{n=(n+e).slice(-4e3)});let c=()=>{for(let e of p.values())clearTimeout(e.timer),e.reject(new Error("Participant browser disconnected"));p.clear()},d=async()=>{if(!s){if(s=!0,c(),a?.close(),i.pid&&null===i.exitCode&&null===i.signalCode){let e=new Promise(e=>i.once("exit",()=>e()));i.kill("SIGTERM");let t=setTimeout(()=>i.kill("SIGKILL"),3e3);await e,clearTimeout(t)}await S(o,{recursive:!0,force:!0})}};try{let w=await N(async()=>{if(r)throw r;if(null!==i.exitCode||null!==i.signalCode)throw new Error(`Participant browser exited: ${n}`);return C(x(o,"DevToolsActivePort"),"utf8").then(e=>e.split("\n")[0]).catch(()=>null)},"participant browser startup"),m=(await(await fetch(`http://127.0.0.1:${w}/json/list`,{signal:AbortSignal.timeout(3e3)})).json()).find(e=>"page"===e.type);if(!m)throw new Error("Participant browser has no page");a=new A(m.webSocketDebuggerUrl,{handshakeTimeout:5e3}),await new Promise((e,t)=>{a.once("open",e),a.once("error",t)}),a.on("close",c),a.on("error",c),a.on("message",e=>{let t=JSON.parse(e.toString()),r=p.get(t.id);r&&(p.delete(t.id),clearTimeout(r.timer),t.error?r.reject(new Error(t.error.message??"Participant browser request failed")):r.resolve(t.result))});let u=(e,t={})=>new Promise((r,o)=>{if(s||a?.readyState!==A.OPEN)return void o(new Error("Participant browser is closed"));let i=++l,n=setTimeout(()=>{p.delete(i),o(new Error(`Participant browser timed out: ${e}. Action was not retried.`))},35e3);p.set(i,{resolve:r,reject:o,timer:n}),a.send(JSON.stringify({id:i,method:e,params:t}))}),h=async(e,t=!1)=>{let r=await u("Runtime.evaluate",{expression:e,userGesture:t,awaitPromise:!0,returnByValue:!0});if(r.exceptionDetails)throw new Error("Participant action failed: "+JSON.stringify(r.exceptionDetails));return r.result?.value};await u("Page.enable"),await u("Runtime.enable");let g=(await u("Page.getFrameTree")).frameTree.frame.id,_=new Set,f=!1;await u("Runtime.addBinding",{name:"__popmeltCapture"}),a.on("message",e=>{let r=JSON.parse(e.toString());if("Runtime.executionContextCreated"===r.method){let e=r.params.context;e.auxData?.isDefault&&e.auxData.frameId===g&&_.add(e.id)}if("Runtime.executionContextDestroyed"===r.method&&_.delete(r.params.executionContextId),"Runtime.executionContextsCleared"===r.method&&_.clear(),"Runtime.bindingCalled"!==r.method||"__popmeltCapture"!==r.params.name||!_.has(r.params.executionContextId))return;let a,o=r.params.executionContextId,i=r.params.payload;if(i.length>22e4)return;try{a=JSON.parse(i)}catch{return}if(!Number.isSafeInteger(a.id)||!Array.isArray(a.selectors)||a.selectors.length>200||a.selectors.some(e=>"string"!=typeof e||e.length>1024))return;let n=e=>u("Runtime.evaluate",{contextId:o,expression:`window.__POPMELT_CAPTURE_DELIVER__?.(${a.id},${JSON.stringify(e)})`}).catch(()=>{});f?n(null):(f=!0,(async()=>{try{if(!await h(`location.origin + location.pathname === ${JSON.stringify(t.href)}`))return null;let e=await h(`window.__POPMELT_AGENT_VIEW__.geometry(${JSON.stringify(a.selectors)})`),r=e.clip;if(![r.x,r.y,r.width,r.height].every(Number.isFinite)||r.x<0||r.y<0||r.width<=0||r.height<=0||r.width>4096||r.height>4096)return null;await h("window.__POPMELT_CAPTURE_CHROME__ = [...document.querySelectorAll('[data-popmelt-top-layer-host]:not([data-popmelt-capture-hidden])')]; window.__POPMELT_CAPTURE_CHROME__.forEach(element => element.setAttribute('data-popmelt-capture-hidden', ''));");try{let t=await u("Page.captureScreenshot",{format:"jpeg",quality:80,captureBeyondViewport:!0,clip:{...r,scale:Math.min(1,1280/Math.max(r.width,r.height))}});return"string"!=typeof t.data||t.data.length>5e5?null:{image:"data:image/jpeg;base64,"+t.data,targets:e.targets}}finally{await h("window.__POPMELT_CAPTURE_CHROME__?.forEach(element => element.removeAttribute('data-popmelt-capture-hidden')); delete window.__POPMELT_CAPTURE_CHROME__;").catch(()=>{})}}catch{return null}})().then(n).finally(()=>{f=!1}))}),await u("Page.addScriptToEvaluateOnNewDocument",{source:`if (location.origin + location.pathname === ${JSON.stringify(t.href)}) {\n window.__POPMELT_AGENT_CREDENTIAL__ = ${JSON.stringify(e)};\n const waiting = new Map(); let id = 0;\n window.__POPMELT_CAPTURE_DELIVER__ = (id, frame) => { const pending = waiting.get(id); if (!pending) return; waiting.delete(id); clearTimeout(pending.timer); pending.resolve(frame); };\n window.__POPMELT_MANAGED_CAPTURE__ = () => { let stopped = false; const owned = new Set(); return {\n frame: selectors => stopped ? Promise.resolve(null) : new Promise(resolve => { const key = ++id; owned.add(key); const timer = setTimeout(() => window.__POPMELT_CAPTURE_DELIVER__(key, null), 5000); waiting.set(key, {resolve: frame => { owned.delete(key); resolve(frame); }, timer}); window.__popmeltCapture(JSON.stringify({id: key, selectors})); }),\n stop: () => { stopped = true; for (const key of owned) window.__POPMELT_CAPTURE_DELIVER__(key, null); }\n }; };\n }`});let P=()=>N(()=>h(`location.origin + location.pathname === ${JSON.stringify(t.href)} && Boolean(window.__POPMELT_AGENT_VIEW__)`),"native participant canvas");a.on("message",e=>{"Page.loadEventFired"===JSON.parse(e.toString()).method&&P().then(()=>h("window.__POPMELT_AGENT_VIEW__.share()",!0)).catch(()=>{})}),await u("Page.navigate",{url:t.href}),await P(),await h("window.__POPMELT_AGENT_VIEW__.share()",!0);let E=Promise.resolve();return{act(e){let t=E.then(async()=>(await P(),h(`window.__POPMELT_AGENT_VIEW__.act(${JSON.stringify(e)})`)));return E=t.catch(()=>{}),t},close:d}}catch(e){throw await d(),e}}}async function D(e){return y(e).catch(()=>e)}async function k(e,t){let r=(await O(t,"utf8").catch(()=>"")).slice(-8e3).trim();return new Error(r?`${e}\nBridge log (${t}):\n${r}`:e)}async function $(e){if("production"===process.env.NODE_ENV&&!e?.force)throw new Error("[Bridge] Refusing to start in production. Pass { force: true } to override.");if((e={...e,experimentalEventTransport:d(e?.experimentalEventTransport)}).detached){let t=e.projectRoot??process.cwd(),l=await u(v(t,".popmelt","bridge-start.lock"),()=>async function(e){let t,l=e.port??1111,d=await D(e.projectRoot??process.cwd()),w=c(d),m=await o(d);for await(let{port:o,status:i}of n(d,l))if(i.projectId===w){if(i.version&&i.version!==r&&"detached"===i.restartMode){t??={port:o,status:i};continue}if("detached"===i.restartMode&&i.version===r&&(i.eventTransport??"sse")!==e.experimentalEventTransport)throw new Error(`[Bridge] Transport conflict on port ${o}: the project is using ${i.eventTransport??"sse"}, but this client requested ${e.experimentalEventTransport}. Use the running transport or stop the bridge before switching.`);if(!a(i,{projectId:w,version:r,restartMode:"detached",eventTransport:e.experimentalEventTransport}))continue;let n=e.devOrigin;if(n&&i.devOrigin!==n)try{await fetch(`http://127.0.0.1:${o}/config`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({devOrigin:n})})}catch{}return process.env.POPMELT_BRIDGE_PORT=String(o),process.env.POPMELT_PROJECT_ID=w,{port:o,projectId:w,storeId:m.storeId,close:async()=>{}}}t&&await s(t.port,w,t.status);let u=v(R(M(import.meta.url)),"bridge-entry.mjs"),h=v(d,".popmelt"),g=v(h,"bridge.log");await T(h,{recursive:!0}),await E(g,`\n[${(new Date).toISOString()}] Starting detached bridge\n`);let O,y=P(g,"a");try{O=_(process.execPath,[u],{detached:!0,stdio:["ignore","ignore",y],env:{...process.env,POPMELT_PORT:String(l),POPMELT_PROJECT_ROOT:d,POPMELT_DEV_ORIGIN:e.devOrigin??"",POPMELT_CURSOR_PATH:e.cursorPath??process.env.POPMELT_CURSOR_PATH??"",POPMELT_OPENCODE_PATH:e.opencodePath??"",POPMELT_COPILOT_PATH:e.copilotPath??"",POPMELT_EXPERIMENTAL_EVENT_TRANSPORT:e.experimentalEventTransport}})}finally{f(y)}let I=null;O.once("error",e=>{I=`spawn error: ${e.message}`}),O.once("exit",(e,t)=>{I=`child exited before becoming healthy (${t?`signal ${t}`:`code ${e??"unknown"}`})`}),O.unref();let L=Date.now()+3e4;for(;Date.now()<L;){if(await new Promise(e=>setTimeout(e,100)),I)throw await k(`[Bridge] Detached bridge ${I}`,g);let t=await p(d);if(t&&t.pid===O.pid){let o=await i(t.port);if(a(o,{projectId:w,version:r,restartMode:"detached",eventTransport:e.experimentalEventTransport}))return process.env.POPMELT_BRIDGE_PORT=String(t.port),process.env.POPMELT_PROJECT_ID=w,{port:t.port,projectId:w,storeId:m.storeId,close:async()=>{}}}}throw O.kill("SIGTERM"),await k(`[Bridge] Detached bridge failed to start within 30s (port ${l})`,g)}(e),4e4);if(!1===e.manageLease)return l;let d=await h({port:l.port,projectId:l.projectId});if(!d)return console.warn("[popmelt] detached bridge started without a process lease"),l;let w=g(d);return{...l,close:async()=>{w(),await d.release()}}}let t=await l(e);return process.env.POPMELT_BRIDGE_PORT=String(t.port),process.env.POPMELT_PROJECT_ID=t.projectId,t}async function G(r){let a,o=await D(r.projectRoot??process.cwd()),i=r.devOrigin,n=r.framework&&await e(o,r.framework,r.nextBundler),s=n?.planes,l=r.readGuestApp??t(o,()=>i,r.framework,o,r.nextBundler),p=w(()=>c,async e=>{let t=e.basePath??"/";return("/"===t?l:await(s?.pageReader(t)))?.(e)},s),c=await $({...r,projectRoot:o,participantSessions:{...p,appOrigin:()=>i,planeApps:s,...s&&{planeEntry:async(e,t)=>{a?.planeMiddleware?(e.headers.host=new URL(i).host,await a.planeMiddleware(e,t,()=>t.writeHead(404).end())):t.writeHead(503).end()}},hostEntry:(e,t)=>{if(a)return a.hostEntry(e,t);t.writeHead(503).end()}}}).catch(async e=>{throw await(n?.close()),e});try{let e;return a=await m({projectRoot:o,bridge:c,origin:i,planeApps:s,guestInvites:"lan"}),console.info("[popmelt] Open the local app in any browser on this machine. Private recovery link: .popmelt/participant-host-link.json."),{...c,bootstrap:s?{...await a.read(),appVersion:void 0}:await a.read(),readBootstrap:e=>a.read(e),close:()=>e??=(async()=>{try{a?.dispose(),await p.stopGuestSharing(),await(n?.close())}finally{await c.close()}})(),async updateOrigin(e){a?.dispose(),i=e,a=await m({projectRoot:o,bridge:c,origin:i,planeApps:s,guestInvites:"lan"})}}}catch(e){throw a?.dispose(),await(n?.close()),await c.close(),e}}export{j as a,$ as b,G as c};
|