@octavus/agent 0.1.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 ADDED
@@ -0,0 +1,71 @@
1
+ # Octavus Agent CLI
2
+
3
+ The `@octavus/agent` package (the `octoagent` command). Run one of your cloud Octavus Agents on a Linux machine you control, using that machine as the agent's computer: the agent lives in the cloud (fully configured and observable) and the local machine only supplies the computer and the trigger.
4
+
5
+ The agent's brain (model, tools, sub-agents, skills, connections) runs on the Octavus platform exactly as it does everywhere else. The CLI just drives the browser, computer-use, filesystem, and shell on the machine you run it on, and every run shows up as a normal thread on the agent in the dashboard - live while it runs and afterward.
6
+
7
+ ## When to use it
8
+
9
+ This is the bring-your-own-computer way to run an agent: great for servers, CI, and benchmarks (ALE, OSWorld, and any "install a CLI, give it a key, run a prompt" harness). It is not the desktop app (an always-on, paired daemon) and not `@octavus/cli` (which manages platform agents) - it is locally triggered and ephemeral.
10
+
11
+ ## Set up the agent
12
+
13
+ In the dashboard, open the agent's **Computer** settings, choose **"Your own machine (CLI)"** (under "More options"), and confirm. That agent then has no managed computer, so its manual chat, schedule, and notifications are turned off - it is driven only from the CLI. Its threads stay visible.
14
+
15
+ Then mint an agent API key from the agent's **Settings -> API** tab.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ curl -fsSL https://octavus.ai/install/octoagent-cli.sh | sh
21
+ ```
22
+
23
+ The installer sets up the prerequisites a full computer needs on a standard Linux box (Node, a headless X display via Xvfb, the AT-SPI accessibility bus, Chrome for Testing) so "install and run" just works. A shell + filesystem only agent needs none of the display stack.
24
+
25
+ ## Use
26
+
27
+ ```bash
28
+ # Configure once with the agent's API key (the only credential you handle).
29
+ octoagent auth --api-key oct_agt_xxx
30
+
31
+ # Run a prompt in the current directory (the agent's filesystem/shell root).
32
+ cd ~/projects/my-task
33
+ octoagent run "Summarize the README and open the repo's homepage in the browser."
34
+ ```
35
+
36
+ The working directory you launch in is the agent's workspace (override with `--workdir`). Durable per-agent operational data - the browser profile (so logins persist across runs) and cached skills - lives under `~/.octavus/<env>/<agentId>/`, never in your working directory.
37
+
38
+ ### Commands
39
+
40
+ - `octoagent run "<prompt>"` - run one prompt to completion and exit.
41
+ - `--workdir <dir>` - the agent's filesystem/shell root (default: current directory).
42
+ - `--api-key <oct_agt_...>` - override the stored key for this run.
43
+ - `--platform-url <url>` - override the platform base URL.
44
+ - `--env <name>` - environment to use (default: `production`; see below).
45
+ - `--chrome-path <path>` - path to Chrome for Testing (else resolved from `PATH`).
46
+ - `--force` - allow running with the workspace at `$HOME` or `/`.
47
+ - `--verbose` - print diagnostics to stderr.
48
+ - `octoagent auth --api-key <oct_agt_...> [--platform-url <url>] [--env <name>]` - store credentials.
49
+ - `octoagent config [--env <name>]` - show the current configuration.
50
+ - `octoagent version [--env <name>]` - show the CLI and platform-supported versions.
51
+
52
+ Exit codes: `0` completed, `1` failed, `2` bad usage, `3` update required.
53
+
54
+ ### Environments
55
+
56
+ `--env <name>` (or `OCTAVUS_ENV`, default `production`) selects an environment. Each keeps its own credentials and browser profile under `~/.octavus/<env>/`, so you can configure and run more than one side by side without them clobbering each other:
57
+
58
+ ```bash
59
+ octoagent auth --api-key oct_agt_prod # production (default)
60
+ octoagent auth --env staging --api-key oct_agt_stg --platform-url <staging-url>
61
+ octoagent run --env staging "..."
62
+ ```
63
+
64
+ `production` targets `https://octavus.ai` with no extra config; any other environment needs its `--platform-url` set once (stored per environment).
65
+
66
+ ## Notes
67
+
68
+ - **One run per machine.** Runs on one machine share that machine's computer (browser profile, display), so running the same agent twice on one machine can collide. Running the same agent from many machines at once is fine and independent.
69
+ - **No resume (v1).** If the CLI stops, crashes, or loses its network mid-run, the run fails - start a new one. For long runs, run detached (e.g. `nohup`) so a closed terminal doesn't kill it.
70
+ - **Network identity is the machine's own.** Nothing is manufactured; a residential machine can pass strict logins, a datacenter box may be challenged.
71
+ - **Billing is unchanged** - the same hourly agent-time plus platform/provider cost as any run. Bringing your own computer doesn't change the bill.
@@ -0,0 +1,3 @@
1
+ (function(){const M=(()=>{if(window===window.top)return 0;try{const t=window.parent.frames;for(let e=0;e<t.length;e++)try{if(t[e]===window)return e+1}catch{}}catch{}return Math.floor(Math.random()*1e3)+100})(),p=window;p.__octavusElementMap===void 0&&(p.__octavusElementMap={});p.__octavusRefCounter===void 0&&(p.__octavusRefCounter=0);function O(){return p.__octavusElementMap}function V(){const t=p.__octavusRefCounter+1;return p.__octavusRefCounter=t,t}const G={a:"link",button:"button",select:"combobox",textarea:"textbox",nav:"navigation",main:"main",header:"banner",footer:"contentinfo",section:"region",article:"article",aside:"complementary",form:"form",table:"table",ul:"list",ol:"list",li:"listitem",label:"label",img:"image"};function j(t){var u;const e=t.getAttribute("role");if(e)return e;const o=t.tagName.toLowerCase();if(o==="input"){const c=(u=t.type)==null?void 0:u.toLowerCase();return c==="submit"||c==="button"||c==="file"?"button":c==="checkbox"?"checkbox":c==="radio"?"radio":"textbox"}return/^h[1-6]$/.test(o)?"heading":G[o]??""}function D(t){const e=window.getComputedStyle(t);return!(e.display==="none"||e.visibility==="hidden"||e.opacity==="0")}function P(t){const e=t.getBoundingClientRect();return e.top<window.innerHeight&&e.bottom>0&&e.left<window.innerWidth&&e.right>0}const W=new Set(["a","button","input","select","textarea","details","summary"]),L=new Set(["button","link","tab","menuitem","menuitemcheckbox","menuitemradio","option","switch","treeitem","combobox","slider","spinbutton","searchbox","textbox"]);function q(t){const e=t.tagName.toLowerCase();if(W.has(e)||t.getAttribute("onclick")!==null||t.getAttribute("tabindex")!==null)return!0;const o=t.getAttribute("role");return!!(o&&L.has(o)||t.getAttribute("contenteditable")==="true"||t.getAttribute("aria-haspopup")!==null||t.getAttribute("aria-expanded")!==null||t.getAttribute("aria-pressed")!==null||(e==="div"||e==="span")&&window.getComputedStyle(t).cursor==="pointer")}function B(t){var C,n,d,h,v,x;const e=t.tagName.toLowerCase();if(e==="select"){const r=t,f=r.options[r.selectedIndex];if(f!==void 0)return i(((C=f.textContent)==null?void 0:C.trim())??"")}const o=t.getAttribute("aria-label");if(o)return i(o);const u=t.getAttribute("placeholder");if(u)return i(u);const c=t.getAttribute("title");if(c)return i(c);const g=t.getAttribute("alt");if(g)return i(g);const w=t.getAttribute("id");if(w){const r=document.querySelector(`label[for="${CSS.escape(w)}"]`);if(r)return i(((n=r.textContent)==null?void 0:n.trim())??"")}if(e==="input"){const r=t;if(((d=r.type)==null?void 0:d.toLowerCase())==="submit"&&r.value||r.value&&r.value.length<50)return i(r.value)}if(["button","a","summary"].includes(e)){const r=E(t);if(r)return i(r);const f=((h=t.textContent)==null?void 0:h.trim())??"";if(f)return i(f)}const y=t.getAttribute("role");if(y&&L.has(y)){const r=((v=t.textContent)==null?void 0:v.trim())??"";if(r)return i(r)}if(/^h[1-6]$/.test(e))return i(((x=t.textContent)==null?void 0:x.trim())??"",100);const a=E(t);return a&&a.length>=3?i(a):""}function E(t){let e="";for(const o of t.childNodes)o.nodeType===Node.TEXT_NODE&&(e+=o.textContent??"");return e.replace(/\s+/g," ").trim()}function i(t,e=100){const o=t.replace(/\s+/g," ").trim();return o.length<=e?o:o.slice(0,e)+"..."}const H=new Set(["script","style","meta","link","title","noscript","br","hr"]);function K(t,e,o,u){const c=O(),g=[];let w=0,y=document.body??document.documentElement;if(u!==void 0&&u in c){const n=c[u].deref();n!==void 0&&(y=n)}function a(n,d){var R;if(w>=o)return;const h=n.tagName.toLowerCase();if(H.has(h)||!D(n))return;const v=j(n),x=B(n),r=q(n),f=P(n),_=v!==""||x!==""||r;if(t==="interactive"&&!r&&!v){for(const s of n.children)a(s,d);if(n.shadowRoot)for(const s of n.shadowRoot.children)a(s,d);return}if(_&&f){let s=null;for(const[l,b]of Object.entries(c))if(b.deref()===n){s=l;break}s||(s=`ref_${M}_${V()}`,c[s]=new WeakRef(n));const $=" ".repeat(d),S=v||"generic",k=x.replace(/"/g,'\\"');let m=`${$}${S}`;if(x&&(m+=` "${k}"`),m+=` [${s}]`,h==="a"){const l=n.getAttribute("href");l&&(m+=` href="${i(l,60)}"`)}if(h==="input"){const l=n.type;l&&(m+=` type="${l}"`);const b=n.getAttribute("placeholder");b&&(m+=` placeholder="${i(b,40)}"`)}if(g.push(m),w+=m.length+1,h==="select"){const l=n;for(const b of l.options){const I=((R=b.textContent)==null?void 0:R.trim())??"",N=b.selected?" (selected)":"",T=`${$} option "${i(I)}"${N} value="${b.value}"`;g.push(T),w+=T.length+1}return}}const A=_&&f?d+1:d;if(!(A>=e)){for(const s of n.children)a(s,A);if(n.shadowRoot)for(const s of n.shadowRoot.children)a(s,A)}}a(y,0);const C=Object.entries(c).filter(([,n])=>n.deref()===void 0).map(([n])=>n);for(const n of C)delete c[n];return g.length===0?"(empty page or no visible elements)":g.join(`
2
+ `)}p.__octavusGenerateAccessibilityTree=K;
3
+ })()
@@ -0,0 +1,8 @@
1
+ var q=Object.defineProperty;var B=(a,e,t)=>e in a?q(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var g=(a,e,t)=>B(a,typeof e!="symbol"?e+"":e,t);import{S as $,O as A}from"./messages-akAS58tQ.js";const F=25e3,U=2e4,O=8e3,V=5e3,W="render_wedged";class H extends Error{constructor(t){super(t);g(this,"code",W);this.name="RenderWedgedError"}}async function j(a,e,t){let r;try{return await Promise.race([a,new Promise((n,o)=>{r=setTimeout(()=>o(new Error(`${t} timed out after ${e}ms`)),e)})])}finally{r&&clearTimeout(r)}}function K(a){return new Promise(e=>{setTimeout(e,a)})}const X=33,G=50,J=45;class z{constructor(){g(this,"attached",new Set);g(this,"queues",new Map);g(this,"pendingDialogs",new Map);g(this,"fileChooserResolvers",new Map)}async enqueue(e,t){const r=this.queues.get(e)??Promise.resolve(),n=()=>{let i;return Promise.race([t().finally(()=>clearTimeout(i)),new Promise((s,c)=>{i=setTimeout(()=>c(new Error(`CDP operation timed out after ${F}ms`)),F)})])},o=r.then(n,n);return this.queues.set(e,o.then(()=>{},()=>{})),await o}async attach(e){if(!this.attached.has(e)){await chrome.debugger.attach({tabId:e},"1.3");try{await Promise.all([chrome.debugger.sendCommand({tabId:e},"Page.enable"),chrome.debugger.sendCommand({tabId:e},"DOM.enable"),chrome.debugger.sendCommand({tabId:e},"Accessibility.enable")])}catch(t){throw await chrome.debugger.detach({tabId:e}).catch(()=>{}),t}this.attached.add(e)}}async detach(e){if(this.attached.has(e)){try{await chrome.debugger.detach({tabId:e})}catch{}this.handleTabDetached(e)}}async captureScreenshot(e){return await this.enqueue(e,async()=>{await this.attach(e);const t=[{label:"surface",budgetMs:O,run:()=>this.captureFromSurface(e)},{label:"renderer",budgetMs:O,run:()=>this.captureFromRenderer(e)},{label:"visible-tab",budgetMs:V,run:()=>this.captureFromVisibleTab(e)}];let r;for(const n of t)try{return await j(n.run(),n.budgetMs,`screenshot(${n.label})`)}catch(o){r=o}throw new H(`Screenshot failed after all capture paths: the browser is not producing frames (render pipeline wedged). Last error: ${r instanceof Error?r.message:String(r)}`)})}async captureFromSurface(e){const t=await this.buildCssViewportClip(e);return(await chrome.debugger.sendCommand({tabId:e},"Page.captureScreenshot",{format:"jpeg",quality:75,...t&&{clip:t,captureBeyondViewport:!0}})).data}async captureFromRenderer(e){const t=await this.buildCssViewportClip(e).catch(()=>{});return(await chrome.debugger.sendCommand({tabId:e},"Page.captureScreenshot",{format:"jpeg",quality:75,fromSurface:!1,captureBeyondViewport:!1,...t&&{clip:t}})).data}async captureFromVisibleTab(e){const t=await chrome.tabs.get(e),[r]=await chrome.tabs.query({active:!0,windowId:t.windowId});if((r==null?void 0:r.id)!==e)throw new Error("target tab is not the active tab for captureVisibleTab");const n=await chrome.tabs.captureVisibleTab(t.windowId,{format:"jpeg",quality:75}),o=await this.getDevicePixelRatio(e).catch(()=>1);if(o>1){const s=await Y(n,1/o);if(s)return s}const[,i]=n.split(",",2);if(!i)throw new Error("captureVisibleTab returned an invalid image payload");return i}async buildCssViewportClip(e){const r=(await chrome.debugger.sendCommand({tabId:e},"Page.getLayoutMetrics")).cssLayoutViewport;if(!r||r.clientWidth<=0||r.clientHeight<=0)return;const n=await this.getDevicePixelRatio(e);return{x:r.pageX,y:r.pageY,width:r.clientWidth,height:r.clientHeight,scale:1/n}}async getDevicePixelRatio(e){var n;const r=(n=(await chrome.debugger.sendCommand({tabId:e},"Runtime.evaluate",{expression:"window.devicePixelRatio",returnByValue:!0})).result)==null?void 0:n.value;return typeof r=="number"&&r>0?r:1}async click(e,t,r){await this.enqueue(e,async()=>{await this.attach(e),await chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:"mousePressed",x:t,y:r,button:"left",clickCount:1}),await chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:"mouseReleased",x:t,y:r,button:"left",clickCount:1})})}async doubleClick(e,t,r){await this.enqueue(e,async()=>{await this.attach(e);for(let n=1;n<=2;n++)await chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:"mousePressed",x:t,y:r,button:"left",clickCount:n}),await chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:"mouseReleased",x:t,y:r,button:"left",clickCount:n})})}async rightClick(e,t,r){await this.enqueue(e,async()=>{await this.attach(e),await chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:"mousePressed",x:t,y:r,button:"right",clickCount:1}),await chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:"mouseReleased",x:t,y:r,button:"right",clickCount:1})})}async type(e,t){await this.enqueue(e,async()=>{await this.attach(e),await chrome.debugger.sendCommand({tabId:e},"Input.insertText",{text:t})})}async fill(e,t,r,n){await this.enqueue(e,async()=>{await this.attach(e),await chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:"mousePressed",x:t,y:r,button:"left",clickCount:1}),await chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:"mouseReleased",x:t,y:r,button:"left",clickCount:1}),await chrome.debugger.sendCommand({tabId:e},"Runtime.evaluate",{expression:"(() => { const el = document.activeElement; if (el && typeof el.select === 'function') el.select(); })()",returnByValue:!0,awaitPromise:!0}),await chrome.debugger.sendCommand({tabId:e},"Input.insertText",{text:n})})}async keyPress(e,t){await this.enqueue(e,async()=>{await this.attach(e);const r=t.split("+").map(c=>c.trim()).filter(Boolean),n=r.pop(),o=r.map(c=>c.toLowerCase());let i=0;(o.includes("alt")||o.includes("option"))&&(i|=1),(o.includes("control")||o.includes("ctrl"))&&(i|=2),(o.includes("meta")||o.includes("command")||o.includes("cmd"))&&(i|=4),o.includes("shift")&&(i|=8);const s=ce(n,i);await chrome.debugger.sendCommand({tabId:e},"Input.dispatchKeyEvent",{type:"rawKeyDown",key:s.key,code:s.code,windowsVirtualKeyCode:s.keyCode,modifiers:i}),await chrome.debugger.sendCommand({tabId:e},"Input.dispatchKeyEvent",{type:"keyUp",key:s.key,code:s.code,windowsVirtualKeyCode:s.keyCode,modifiers:i})})}async navigate(e,t){await this.enqueue(e,async()=>{await chrome.tabs.update(e,{url:t})})}async scrollPage(e,t,r){await this.enqueue(e,async()=>{await this.attach(e);const n=t==="down"?1:-1,o=c=>chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:"mouseWheel",x:100,y:300,deltaX:0,deltaY:c}),i=Math.min(Math.max(Math.ceil(Math.abs(r)/G),1),J),s=r/i;for(let c=0;c<i;c++)await o(n*s),c<i-1&&await K(X)})}async hover(e,t,r){await this.enqueue(e,async()=>{await this.attach(e),await chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:"mouseMoved",x:t,y:r})})}async drag(e,t,r,n,o){await this.enqueue(e,async()=>{await this.attach(e);const i=(l,d,u,h,m)=>chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:l,x:d,y:u,...h!==void 0&&{button:h},...m!==void 0&&{clickCount:m}});await i("mouseMoved",t,r),await i("mousePressed",t,r,"left",1);const s=Math.round((t+n)/2),c=Math.round((r+o)/2);await i("mouseMoved",s,c),await i("mouseMoved",n,o),await i("mouseReleased",n,o,"left",1)})}async evaluateScript(e,t){return await this.enqueue(e,async()=>{await this.attach(e);const r=await chrome.debugger.sendCommand({tabId:e},"Runtime.evaluate",{expression:t,returnByValue:!0,awaitPromise:!0});return{value:r.result.value,exceptionDetails:r.exceptionDetails}})}async getAccessibilityTree(e,t,r,n){return await this.enqueue(e,async()=>{await this.attach(e);const o=await chrome.debugger.sendCommand({tabId:e},"Page.getFrameTree"),i=N(o.frameTree),s=[];let c=n;for(const l of i){if(c<=0)break;let d;try{d=await chrome.debugger.sendCommand({tabId:e},"Accessibility.getFullAXTree",{frameId:l.id})}catch{continue}const h=l.id!==o.frameTree.frame.id?`--- iframe${l.url?` (${l.url})`:""} ---`:null,m=h?h.length+1:0,f=ee(d.nodes,t,r,c-m);f&&(h&&s.push(h),s.push(f),c-=m+f.length+1)}return s.join(`
2
+ `)})}async resolveBackendNodeCoordinates(e,t){return await this.enqueue(e,async()=>{await this.attach(e);let r;try{r=await chrome.debugger.sendCommand({tabId:e},"DOM.getBoxModel",{backendNodeId:t})}catch{throw new Error(`Element ax_${t} no longer in the DOM. Re-run get_accessibility_tree to get fresh refs.`)}const n=r.model.border.length>0?r.model.border:r.model.content;return ae(n)})}async getFrameElementOffset(e,t){return await this.enqueue(e,async()=>{await this.attach(e);const r=await chrome.debugger.sendCommand({tabId:e},"DOM.getFrameOwner",{frameId:t}),n=await chrome.debugger.sendCommand({tabId:e},"DOM.getBoxModel",{backendNodeId:r.backendNodeId}),o=n.model.border.length>0?n.model.border:n.model.content;if(o.length<8)throw new Error("Could not resolve iframe coordinates");return{x:Math.min(o[0],o[2],o[4],o[6]),y:Math.min(o[1],o[3],o[5],o[7])}})}async getFrameTree(e){return await this.enqueue(e,async()=>(await this.attach(e),(await chrome.debugger.sendCommand({tabId:e},"Page.getFrameTree")).frameTree))}async uploadFile(e,t,r,n){await this.enqueue(e,async()=>{await this.attach(e),await chrome.debugger.sendCommand({tabId:e},"Page.setInterceptFileChooserDialog",{enabled:!0});try{const o=new Promise(s=>{const c=setTimeout(()=>{this.fileChooserResolvers.delete(e),s(null)},U);this.fileChooserResolvers.set(e,l=>{clearTimeout(c),s(l)})});await chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:"mousePressed",x:t,y:r,button:"left",clickCount:1}),await chrome.debugger.sendCommand({tabId:e},"Input.dispatchMouseEvent",{type:"mouseReleased",x:t,y:r,button:"left",clickCount:1});const i=await o;if(i){await chrome.debugger.sendCommand({tabId:e},"DOM.setFileInputFiles",{files:n,backendNodeId:i.backendNodeId});return}await this.setFilesOnPageInput(e,n)}finally{await chrome.debugger.sendCommand({tabId:e},"Page.setInterceptFileChooserDialog",{enabled:!1}).catch(()=>{})}})}async setFilesOnPageInput(e,t){const r=await chrome.debugger.sendCommand({tabId:e},"DOM.getDocument",{depth:-1,pierce:!0}),n=ne(r.root);if(n.length===0)throw new Error('File chooser did not open and no file input was found on the page - the clicked element may not trigger a file upload. Open the upload control first (e.g. click the "Files" option in an upload menu), then call upload_file on it.');const o=n.filter(s=>!s.disabled&&!s.directory);let i=o.length===1?o[0]:void 0;if(!i&&o.length>1){const s=ie(t[0]),c=s?o.filter(l=>se(l.accept,s)):[];c.length===1&&(i=c[0])}if(!i)throw new Error(`File chooser did not open and the page has ${o.length} possible file inputs, so the upload target is ambiguous. Click the specific upload control and try again, or use the service's connector to upload or replace the file.`);await chrome.debugger.sendCommand({tabId:e},"DOM.setFileInputFiles",{files:t,backendNodeId:i.backendNodeId})}onFileChooserOpened(e,t){const r=this.fileChooserResolvers.get(e);r&&(this.fileChooserResolvers.delete(e),r({backendNodeId:t.backendNodeId}))}onDialogOpening(e,t){this.pendingDialogs.set(e,{type:t.type,message:t.message,defaultPrompt:t.defaultPrompt})}getPendingDialog(e){return this.pendingDialogs.get(e)}async handleDialog(e,t,r){await this.enqueue(e,async()=>{await this.attach(e),await chrome.debugger.sendCommand({tabId:e},"Page.handleJavaScriptDialog",{accept:t,...r!==void 0&&{promptText:r}}),this.pendingDialogs.delete(e)})}handleTabDetached(e){this.attached.delete(e),this.queues.delete(e),this.pendingDialogs.delete(e),this.fileChooserResolvers.delete(e)}}const Q=new Set(["button","checkbox","combobox","link","menuitem","menuitemcheckbox","menuitemradio","option","radio","searchbox","slider","spinbutton","switch","tab","textbox","treeitem"]),Z=new Set(["alertdialog","dialog","form","heading","main","navigation","region","search","tabpanel"]);async function Y(a,e){try{const t=await(await fetch(a)).blob(),r=await createImageBitmap(t),n=Math.max(1,Math.round(r.width*e)),o=Math.max(1,Math.round(r.height*e)),i=new OffscreenCanvas(n,o),s=i.getContext("2d");if(!s)return r.close(),null;s.drawImage(r,0,0,n,o),r.close();const c=await i.convertToBlob({type:"image/jpeg",quality:.75}),l=new Uint8Array(await c.arrayBuffer()),d=32768;let u="";for(let h=0;h<l.length;h+=d)u+=String.fromCharCode(...l.subarray(h,h+d));return btoa(u)}catch{return null}}function N(a){return[a.frame,...(a.childFrames??[]).flatMap(N)]}function ee(a,e,t,r){const n=new Map(a.map(d=>[d.nodeId,d])),o=new Set(a.flatMap(d=>d.childIds??[])),i=a.filter(d=>!o.has(d.nodeId)),s=[];let c=0;function l(d,u){if(c>=r)return;if(d.ignored===!0){for(const T of d.childIds??[]){const b=n.get(T);b&&l(b,u)}return}const h=v(d.role,!1),m=v(d.name)||v(d.description)||v(d.value),f=Q.has(h),p=Z.has(h),P=d.backendDOMNodeId!==void 0&&h!==""&&(e==="interactive"?f||p:f||p||m!=="");if(P){const T=" ".repeat(u),b=`ax_${d.backendDOMNodeId}`,x=m.replace(/"/g,'\\"');let C=`${T}${h}`;x&&(C+=` "${x}"`),C+=` [${b}]`;const _=v(d.value);_&&_!==m&&(C+=` value="${_.replace(/"/g,'\\"')}"`),te(d,"disabled")&&(C+=" disabled"),s.push(C),c+=C.length+1}const R=P?u+1:u;if(!(R>=t))for(const T of d.childIds??[]){const b=n.get(T);b&&l(b,R)}}for(const d of i)l(d,0);return s.length>0?s.join(`
3
+ `):""}function v(a,e=!0){const t=a==null?void 0:a.value;if(typeof t=="string"){const r=t.replace(/\s+/g," ").trim();return e?re(r):r}return typeof t=="number"||typeof t=="boolean"?String(t):""}function te(a,e){var t;return((t=a.properties)==null?void 0:t.some(r=>{var n;return r.name===e&&((n=r.value)==null?void 0:n.value)===!0}))??!1}function re(a,e=100){return a.length<=e?a:`${a.slice(0,e)}...`}function ae(a){if(a.length<8)throw new Error("Could not resolve element coordinates from backend node");const e=[a[0],a[2],a[4],a[6]],t=[a[1],a[3],a[5],a[7]];return{x:Math.round((Math.min(...e)+Math.max(...e))/2),y:Math.round((Math.min(...t)+Math.max(...t))/2)}}function ne(a){var r;const e=[],t=[a];for(;t.length>0;){const n=t.pop();if(((r=n.nodeName)==null?void 0:r.toUpperCase())==="INPUT"&&n.backendNodeId!==void 0){const o=oe(n.attributes);(o.type??"").toLowerCase()==="file"&&e.push({backendNodeId:n.backendNodeId,disabled:"disabled"in o,directory:"webkitdirectory"in o||"directory"in o,accept:o.accept})}for(const o of n.children??[])t.push(o);for(const o of n.shadowRoots??[])t.push(o);n.contentDocument&&t.push(n.contentDocument)}return e}function oe(a){const e={};if(!a)return e;for(let t=0;t+1<a.length;t+=2)e[a[t].toLowerCase()]=a[t+1];return e}function ie(a){if(!a)return"";const e=a.split(/[\\/]/).pop()??"",t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""}function se(a,e){if(!a)return!0;const t=a.toLowerCase().split(",").map(r=>r.trim()).filter(Boolean);return t.length===0||t.includes("*/*")||t.includes("*")?!0:t.includes(e)}function ce(a,e=0){const t=(e&8)!==0,r={Enter:{key:"Enter",code:"Enter",keyCode:13},Tab:{key:"Tab",code:"Tab",keyCode:9},Escape:{key:"Escape",code:"Escape",keyCode:27},Backspace:{key:"Backspace",code:"Backspace",keyCode:8},Delete:{key:"Delete",code:"Delete",keyCode:46},ArrowUp:{key:"ArrowUp",code:"ArrowUp",keyCode:38},ArrowDown:{key:"ArrowDown",code:"ArrowDown",keyCode:40},ArrowLeft:{key:"ArrowLeft",code:"ArrowLeft",keyCode:37},ArrowRight:{key:"ArrowRight",code:"ArrowRight",keyCode:39},Home:{key:"Home",code:"Home",keyCode:36},End:{key:"End",code:"End",keyCode:35},PageUp:{key:"PageUp",code:"PageUp",keyCode:33},PageDown:{key:"PageDown",code:"PageDown",keyCode:34},Space:{key:" ",code:"Space",keyCode:32}},n={"/":{code:"Slash",keyCode:191,shifted:"?"},".":{code:"Period",keyCode:190,shifted:">"},",":{code:"Comma",keyCode:188,shifted:"<"},";":{code:"Semicolon",keyCode:186,shifted:":"},"'":{code:"Quote",keyCode:222,shifted:'"'},"[":{code:"BracketLeft",keyCode:219,shifted:"{"},"]":{code:"BracketRight",keyCode:221,shifted:"}"},"\\":{code:"Backslash",keyCode:220,shifted:"|"},"-":{code:"Minus",keyCode:189,shifted:"_"},"=":{code:"Equal",keyCode:187,shifted:"+"},"`":{code:"Backquote",keyCode:192,shifted:"~"}},o={"?":"/",">":".","<":",",":":";",'"':"'","{":"[","}":"]","|":"\\",_:"-","+":"=","~":"`"},i=a.charAt(0).toUpperCase()+a.slice(1);if(i in r)return r[i];if(a.length===1){if(/[a-zA-Z]/.test(a)){const c=a.toUpperCase();return{key:t?c:a.toLowerCase(),code:`Key${c}`,keyCode:c.charCodeAt(0)}}if(/[0-9]/.test(a))return{key:a,code:`Digit${a}`,keyCode:a.charCodeAt(0)};if(a in n){const c=n[a];return{key:t?c.shifted:a,code:c.code,keyCode:c.keyCode}}if(a in o){const c=o[a],l=n[c];return{key:a,code:l.code,keyCode:l.keyCode}}const s=a.toUpperCase();return{key:a,code:`Key${s}`,keyCode:s.charCodeAt(0)}}return{key:a,code:a,keyCode:0}}class de{constructor(){g(this,"tabId",null);g(this,"tabs",[])}async getCurrentTabId(){if(this.tabId!==null)try{return await chrome.tabs.get(this.tabId),this.tabId}catch{this.tabId=null}const[e]=await chrome.tabs.query({active:!0,lastFocusedWindow:!0});if((e==null?void 0:e.id)!==void 0)return this.tabId=e.id,this.tabs.includes(e.id)||this.tabs.push(e.id),e.id;throw new Error("No active tab found")}setCurrentTab(e){this.tabId=e,this.tabs.includes(e)||this.tabs.push(e)}removeTab(e){this.tabs=this.tabs.filter(t=>t!==e),this.tabId===e&&(this.tabId=this.tabs[this.tabs.length-1]??null)}getTrackedTabs(){return[...this.tabs]}}const ue="src/offscreen/recording.html";function le(a){return new Promise((e,t)=>{chrome.tabCapture.getMediaStreamId({targetTabId:a},r=>{const n=chrome.runtime.lastError;n||!r?t(new Error((n==null?void 0:n.message)??"Failed to acquire tab media stream")):e(r)})})}async function he(a){try{const[e]=await chrome.scripting.executeScript({target:{tabId:a},func:()=>({width:Math.round(window.innerWidth*window.devicePixelRatio),height:Math.round(window.innerHeight*window.devicePixelRatio)})}),t=e==null?void 0:e.result;if(t&&t.width>0&&t.height>0)return t}catch{}return null}class me{constructor(e,t){g(this,"activeRecordingId",null);this.tabTracker=e,this.forward=t,chrome.runtime.onMessage.addListener(r=>{const n=r;(n==null?void 0:n.target)===$&&(this.forward(n),(n.type==="stopped"||n.type==="error")&&this.activeRecordingId===n.recordingId&&(this.activeRecordingId=null))})}async start(e){if(this.activeRecordingId)throw new Error("A recording is already in progress");const t=await this.tabTracker.getCurrentTabId(),r=await le(t),n=await he(t);await this.ensureOffscreenDocument();const o={target:A,type:"start",recordingId:e.recordingId,streamId:r,videoBitsPerSecond:e.videoBitsPerSecond,audio:e.audio,maxDurationMs:e.maxDurationMs,captureWidth:n==null?void 0:n.width,captureHeight:n==null?void 0:n.height};return await chrome.runtime.sendMessage(o),this.activeRecordingId=e.recordingId,{recordingId:e.recordingId,started:!0}}async stop(e){const t={target:A,type:"stop",recordingId:e};return await chrome.runtime.sendMessage(t),{recordingId:e,stopping:!0}}async ensureOffscreenDocument(){if(!await chrome.offscreen.hasDocument())try{await chrome.offscreen.createDocument({url:ue,reasons:[chrome.offscreen.Reason.USER_MEDIA],justification:"Record the agent browser tab to a video for demos and walkthroughs."})}catch(e){if(!await chrome.offscreen.hasDocument())throw e}}}const fe=async(a,e)=>{const t=await e.tabTracker.getCurrentTabId();return{image:await e.cdp.captureScreenshot(t),format:"jpeg"}},we=12e6,ge=480*6e4,pe=async(a,e)=>{const t=typeof a.recordingId=="string"?a.recordingId:crypto.randomUUID(),r=typeof a.videoBitsPerSecond=="number"?a.videoBitsPerSecond:we,n=typeof a.maxDurationMs=="number"?a.maxDurationMs:ge,o=a.audio===!0;return await e.recording.start({recordingId:t,videoBitsPerSecond:r,audio:o,maxDurationMs:n})},ye=async(a,e)=>{if(typeof a.recordingId!="string"||a.recordingId.length===0)throw new Error("recordingId is required to stop a recording");return await e.recording.stop(a.recordingId)},be=3e4;function S(a,e=be){return new Promise((t,r)=>{let n=null;const o=i=>{i.tabId===a&&i.frameId===0&&(n!==null&&clearTimeout(n),chrome.webNavigation.onCompleted.removeListener(o),t())};n=setTimeout(()=>{chrome.webNavigation.onCompleted.removeListener(o),r(new Error("Navigation timed out"))},e),chrome.webNavigation.onCompleted.addListener(o)})}const Ce=async(a,e)=>{const t=a.url;if(!t)throw new Error("navigate requires a url parameter");const r=await e.tabTracker.getCurrentTabId();return await e.cdp.navigate(r,t),await S(r),{success:!0,url:t}},Te=async(a,e)=>{const t=await e.tabTracker.getCurrentTabId();return await chrome.tabs.goBack(t),{success:!0}},ve=async(a,e)=>{const t=await e.tabTracker.getCurrentTabId();return await chrome.tabs.goForward(t),{success:!0}},Ee=async(a,e)=>{const t=await e.tabTracker.getCurrentTabId();return await chrome.tabs.reload(t),await S(t),{success:!0}};async function y(a,e,t){if(e.startsWith("ax_")){const u=Number(e.slice(3));if(!Number.isInteger(u))throw new Error(`Element ${e} is not a valid accessibility ref`);return await t.resolveBackendNodeCoordinates(a,u)}const r=await chrome.webNavigation.getAllFrames({tabId:a});if(!r||r.length===0)throw new Error(`Element ${e} not found. Re-run get_accessibility_tree to get fresh refs.`);const n=await ke(a,e,r);if(!n)throw new Error(`Element ${e} not found or garbage collected. Re-run get_accessibility_tree to get fresh refs.`);const{x:o,y:i,frameId:s}=n;if(s===0)return{x:o,y:i};const c=await t.getFrameTree(a),d=Me(r,c).get(s);if(!d)return{x:o,y:i};try{const u=await t.getFrameElementOffset(a,d);return{x:Math.round(o+u.x),y:Math.round(i+u.y)}}catch{return{x:o,y:i}}}async function ke(a,e,t){const r=await Promise.allSettled(t.map(async n=>{const[o]=await chrome.scripting.executeScript({target:{tabId:a,frameIds:[n.frameId]},func:_e,args:[e]});return{frameId:n.frameId,point:(o==null?void 0:o.result)??null}}));for(const n of r)if(n.status==="fulfilled"&&n.value.point!==null)return{x:n.value.point.x,y:n.value.point.y,frameId:n.value.frameId};return null}function _e(a){const e=window.__octavusElementMap;if(e===void 0)return null;const t=e[a];if(t===void 0)return null;const r=t.deref();if(!r)return null;const n=r.getBoundingClientRect();return{x:Math.round(n.left+n.width/2),y:Math.round(n.top+n.height/2)}}function Me(a,e){const t=new Map,r=new Map;for(const o of a){if(o.frameId===0)continue;const i=r.get(o.parentFrameId)??[];i.push(o),r.set(o.parentFrameId,i)}function n(o,i){t.set(o,i.frame.id);const s=[...i.childFrames??[]];for(const c of r.get(o)??[]){const l=s.findIndex(u=>u.frame.url===c.url);if(l===-1)continue;const[d]=s.splice(l,1);n(c.frameId,d)}}return n(0,e),t}const Ie=async(a,e)=>{const t=a.ref_id;if(!t)throw new Error("click requires a ref_id parameter");const r=await e.tabTracker.getCurrentTabId(),{x:n,y:o}=await y(r,t,e.cdp);return await e.cdp.click(r,n,o),{success:!0,ref_id:t,x:n,y:o}},Se=async(a,e)=>{const t=a.ref_id;if(!t)throw new Error("double_click requires a ref_id parameter");const r=await e.tabTracker.getCurrentTabId(),{x:n,y:o}=await y(r,t,e.cdp);return await e.cdp.doubleClick(r,n,o),{success:!0,ref_id:t,x:n,y:o}},De=async(a,e)=>{const t=a.ref_id;if(!t)throw new Error("right_click requires a ref_id parameter");const r=await e.tabTracker.getCurrentTabId(),{x:n,y:o}=await y(r,t,e.cdp);return await e.cdp.rightClick(r,n,o),{success:!0,ref_id:t,x:n,y:o}},Pe=async(a,e)=>{const t=a.ref_id;if(!t)throw new Error("hover requires a ref_id parameter");const r=await e.tabTracker.getCurrentTabId(),{x:n,y:o}=await y(r,t,e.cdp);return await e.cdp.hover(r,n,o),{success:!0,ref_id:t,x:n,y:o}},Re=async(a,e)=>{const t=a.from_ref_id,r=a.to_ref_id;if(!t)throw new Error("drag requires a from_ref_id parameter");if(!r)throw new Error("drag requires a to_ref_id parameter");const n=await e.tabTracker.getCurrentTabId(),o=await y(n,t,e.cdp),i=await y(n,r,e.cdp);return await e.cdp.drag(n,o.x,o.y,i.x,i.y),{success:!0,from_ref_id:t,to_ref_id:r}},xe=async(a,e)=>{const t=a.text;if(!t)throw new Error("type requires a text parameter");const r=await e.tabTracker.getCurrentTabId();return await e.cdp.type(r,t),{success:!0,text:t}},Ae=async(a,e)=>{const t=a.key;if(!t)throw new Error("key requires a key parameter");const r=await e.tabTracker.getCurrentTabId();return await e.cdp.keyPress(r,t),{success:!0,key:t}},Fe=500,Oe=async(a,e)=>{const t=a.direction;if(!t||t!=="up"&&t!=="down")throw new Error('scroll requires direction "up" or "down"');const r=a.amount??Fe,n=await e.tabTracker.getCurrentTabId();return await e.cdp.scrollPage(n,t,r),{success:!0,direction:t,amount:r}},Ne=async(a,e)=>{const t=a.filter??"all",r=a.maxDepth??15,n=a.maxLength??5e4,o=await e.tabTracker.getCurrentTabId();if(t==="interactive"){const d=await e.cdp.getAccessibilityTree(o,t,r,n);return d?{tree:d}:{tree:"Error: Could not generate accessibility tree"}}const i=await chrome.webNavigation.getAllFrames({tabId:o});if(!i||i.length===0)return{tree:"Error: Could not enumerate frames"};const s=await Promise.allSettled(i.map(async d=>{const[u]=await chrome.scripting.executeScript({target:{tabId:o,frameIds:[d.frameId]},func:(h,m,f)=>{const p=window.__octavusGenerateAccessibilityTree;return p===void 0?"":p(h,m,f)},args:[t,r,n]});return{frame:d,tree:(u==null?void 0:u.result)??""}})),c=[];for(const d of s){if(d.status!=="fulfilled")continue;const{frame:u,tree:h}=d.value;if(h){if(u.frameId!==0){const m=u.url?` (${u.url})`:"";c.push(`--- iframe${m} ---`)}c.push(h)}}const l=c.join(`
4
+ `);return l?{tree:l}:{tree:"Error: Could not generate accessibility tree"}},Le=async(a,e)=>({tabs:(await chrome.tabs.query({})).filter(r=>r.id!==void 0).map(r=>({tabId:r.id,title:r.title??"",url:r.url??"",active:r.active}))}),qe=async(a,e)=>{const t=a.url,r=await chrome.tabs.create({url:t??"about:blank",active:!0});if(r.id===void 0)throw new Error("Failed to create tab");return e.tabTracker.setCurrentTab(r.id),{success:!0,tabId:r.id,url:t??"about:blank"}},Be=async(a,e)=>{const t=a.tabId;if(t===void 0)throw new Error("switch_tab requires a tabId parameter");return await chrome.tabs.update(t,{active:!0}),e.tabTracker.setCurrentTab(t),{success:!0,tabId:t}},$e=async(a,e)=>{const t=a.tabId??await e.tabTracker.getCurrentTabId(),r=e.tabTracker.getTrackedTabs();if(r.length<=1&&r.includes(t))throw new Error("Cannot close the last tab.");return await e.cdp.detach(t),await chrome.tabs.remove(t),e.tabTracker.removeTab(t),{success:!0,closedTabId:t}},Ue=1e3,Ve=3e4,We=500,He=async(a,e)=>{const t=a.ms??Ue;if(a.for_navigation===!0){const r=await e.tabTracker.getCurrentTabId();return await S(r),{success:!0,waited_for:"navigation"}}return await new Promise(r=>{setTimeout(()=>r(),t)}),{success:!0,waited_ms:t}},je=async(a,e)=>{var d;const t=a.text;if(!Array.isArray(t)||t.length===0)throw new Error("wait_for requires a non-empty text array");const r=a.timeout??Ve,n=await e.tabTracker.getCurrentTabId(),i=`(() => {
5
+ const targets = ${JSON.stringify(t)};
6
+ const body = document.body?.innerText ?? '';
7
+ return targets.find(t => body.includes(t)) ?? null;
8
+ })()`;let s;const c=Date.now()+r;for(;Date.now()<c;){const{value:u,exceptionDetails:h}=await e.cdp.evaluateScript(n,i);if(h!==void 0){const m=h;s=((d=m.exception)==null?void 0:d.description)??m.text??"Script evaluation failed"}else{if(u!=null)return{success:!0,matchedText:u};s=void 0}await new Promise(m=>{setTimeout(()=>m(),We)})}const l=s?`Script error: ${s}`:`text not found: ${t.join(", ")}`;throw new Error(`Timed out after ${r}ms - ${l}`)},Ke=async(a,e)=>{const t=a.ref_id,r=a.value;if(!t)throw new Error("select_option requires a ref_id parameter");if(!r)throw new Error("select_option requires a value parameter");const n=await e.tabTracker.getCurrentTabId(),[o]=await chrome.scripting.executeScript({target:{tabId:n},func:(s,c)=>{var m;const l=window.__octavusElementMap;if(l===void 0)return{error:"Element map not available"};const d=l[s];if(d===void 0)return{error:`Element ${s} not found`};const u=d.deref();if(!u)return{error:`Element ${s} has been garbage collected`};if(!(u instanceof HTMLSelectElement))return{error:`Element ${s} is not a <select> element`};let h=!1;for(const f of u.options)if(f.value===c||((m=f.textContent)==null?void 0:m.trim())===c){f.selected=!0,h=!0;break}return h?(u.dispatchEvent(new Event("change",{bubbles:!0})),{success:!0,selected:c}):{error:`Option "${c}" not found in ${s}`,available:Array.from(u.options).map(f=>{var p;return{value:f.value,text:(p=f.textContent)==null?void 0:p.trim()}})}},args:[t,r]}),i=o==null?void 0:o.result;if(typeof(i==null?void 0:i.error)=="string")throw new Error(i.error);return i??{success:!0}},Xe=async(a,e)=>{const t=a.ref_id,r=a.value;if(!t)throw new Error("fill requires a ref_id parameter");if(r==null)throw new Error("fill requires a value parameter");const n=await e.tabTracker.getCurrentTabId(),{x:o,y:i}=await y(n,t,e.cdp);return await e.cdp.fill(n,o,i,r),{success:!0,ref_id:t}},Ge=async(a,e)=>{const t=a.action;if(t!=="accept"&&t!=="dismiss")throw new Error('handle_dialog requires action to be "accept" or "dismiss"');const r=a.promptText,n=await e.tabTracker.getCurrentTabId(),o=e.cdp.getPendingDialog(n);if(!o)throw new Error("No dialog is currently open on this tab");return await e.cdp.handleDialog(n,t==="accept",r),{success:!0,action:t,dialogType:o.type,dialogMessage:o.message}},Je=async(a,e)=>{var s;const t=a.function;if(!t)throw new Error("evaluate_script requires a function parameter");const r=`(${t})()`,n=await e.tabTracker.getCurrentTabId(),{value:o,exceptionDetails:i}=await e.cdp.evaluateScript(n,r);if(i!==void 0){const c=i,l=((s=c.exception)==null?void 0:s.description)??c.text??"Script evaluation failed";throw new Error(l)}return{success:!0,result:o}},ze=async(a,e)=>{const t=a.ref_id,r=a.filePath;if(!t)throw new Error("upload_file requires a ref_id parameter");if(!r)throw new Error("upload_file requires a filePath parameter");const n=await e.tabTracker.getCurrentTabId(),{x:o,y:i}=await y(n,t,e.cdp);return await e.cdp.uploadFile(n,o,i,[r]),{success:!0,ref_id:t,filePath:r}},Qe={screenshot:fe,start_recording:pe,stop_recording:ye,get_accessibility_tree:Ne,click:Ie,right_click:De,double_click:Se,hover:Pe,drag:Re,type:xe,key:Ae,fill:Xe,navigate:Ce,go_back:Te,go_forward:ve,reload:Ee,scroll:Oe,select_option:Ke,wait:He,wait_for:je,handle_dialog:Ge,evaluate_script:Je,upload_file:ze,list_tabs:Le,new_tab:qe,switch_tab:Be,close_tab:$e};async function Ze(a,e,t){const r=Qe[a];if(r===void 0)throw new Error(`Unknown command: ${a}`);return await r(e,t)}const Ye=2e4,et=1e3,tt=3e4,E=new z,D=new de,rt=new me(D,a=>I(a)),at={cdp:E,tabTracker:D,recording:rt};let w=null,k=null,M=0;async function nt(){const a=chrome.runtime.getURL("config.json"),e=await fetch(a);if(!e.ok)throw new Error(`Failed to load config.json: ${e.status}`);return await e.json()}function L(a){w=new WebSocket(`ws://127.0.0.1:${a}`),w.onopen=()=>{M=0,w.send(JSON.stringify({type:"ready"})),k=setInterval(()=>{(w==null?void 0:w.readyState)===WebSocket.OPEN&&w.send(JSON.stringify({type:"heartbeat"}))},Ye)},w.onmessage=e=>{ot(e.data)},w.onclose=()=>{it(),st(a)},w.onerror=()=>{}}async function ot(a){let e;try{e=JSON.parse(a)}catch{return}const{id:t,cmd:r,args:n}=e;if(!(!t||!r))try{const o=await Ze(r,n??{},at);I({id:t,result:o})}catch(o){const i=o==null?void 0:o.code,s=typeof i=="string"?i:void 0;I({id:t,error:o instanceof Error?o.message:String(o),...s!==void 0?{code:s}:{}})}}function I(a){(w==null?void 0:w.readyState)===WebSocket.OPEN&&w.send(JSON.stringify(a))}function it(){k&&(clearInterval(k),k=null)}function st(a){const e=Math.min(et*2**M,tt);M+=1,setTimeout(()=>L(a),e)}chrome.tabs.onRemoved.addListener(a=>{E.handleTabDetached(a),D.removeTab(a)});chrome.debugger.onDetach.addListener(a=>{a.tabId!==void 0&&E.handleTabDetached(a.tabId)});chrome.debugger.onEvent.addListener((a,e,t)=>{if(a.tabId===void 0)return;const r=t??{};e==="Page.javascriptDialogOpening"?E.onDialogOpening(a.tabId,r):e==="Page.fileChooserOpened"&&E.onFileChooserOpened(a.tabId,r)});nt().then(a=>L(a.wsPort)).catch(a=>console.error("[browser-extension] Failed to start:",a));
@@ -0,0 +1 @@
1
+ const o="offscreen-recording",r="sw-recording";export{o as O,r as S};
@@ -0,0 +1 @@
1
+ import{O as h,S as u}from"./messages-akAS58tQ.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))i(t);new MutationObserver(t=>{for(const n of t)if(n.type==="childList")for(const d of n.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&i(d)}).observe(document,{childList:!0,subtree:!0});function o(t){const n={};return t.integrity&&(n.integrity=t.integrity),t.referrerPolicy&&(n.referrerPolicy=t.referrerPolicy),t.crossOrigin==="use-credentials"?n.credentials="include":t.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function i(t){if(t.ep)return;t.ep=!0;const n=o(t);fetch(t.href,n)}})();const m=1e3;let c=null;function l(r){chrome.runtime.sendMessage(r)}function g(){const r=["video/mp4;codecs=avc1","video/mp4;codecs=avc1.42E01E","video/mp4;codecs=vp9","video/mp4"];for(const e of r)if(MediaRecorder.isTypeSupported(e))return e;return"video/mp4"}function y(r){return new Promise((e,o)=>{const i=new FileReader;i.onload=()=>{const t=i.result,n=t.indexOf(",");e(n>=0?t.slice(n+1):t)},i.onerror=()=>o(i.error??new Error("FileReader failed")),i.readAsDataURL(r)})}function v(r,e){const o={chromeMediaSource:"tab",chromeMediaSourceId:r.streamId};return e!=="none"&&r.captureWidth!==void 0&&r.captureHeight!==void 0&&(o.maxWidth=r.captureWidth,o.maxHeight=r.captureHeight,e==="exact"&&(o.minWidth=r.captureWidth,o.minHeight=r.captureHeight)),{audio:r.audio?{mandatory:{chromeMediaSource:"tab",chromeMediaSourceId:r.streamId}}:!1,video:{mandatory:o}}}async function I(r){const e=r.captureWidth!==void 0&&r.captureHeight!==void 0?["exact","max","none"]:["none"];let o;for(const i of e)try{return await navigator.mediaDevices.getUserMedia(v(r,i))}catch(t){o=t}throw o instanceof Error?o:new Error("Failed to open tab capture stream")}async function T(r){if(c){l({target:u,type:"error",recordingId:r.recordingId,message:"A recording is already in progress"});return}try{const e=await I(r);let o=null;r.audio&&e.getAudioTracks().length>0&&(o=new AudioContext,o.createMediaStreamSource(e).connect(o.destination));const i=e.getVideoTracks()[0],t=i==null?void 0:i.getSettings(),n=g(),d=new MediaRecorder(e,{mimeType:n,videoBitsPerSecond:r.videoBitsPerSecond}),s={recordingId:r.recordingId,recorder:d,stream:e,audioContext:o,mediaType:n.split(";")[0]??"video/mp4",startedAt:Date.now(),width:(t==null?void 0:t.width)??0,height:(t==null?void 0:t.height)??0,chunkChain:Promise.resolve(),maxDurationTimer:null};c=s,d.ondataavailable=a=>{if(a.data.size===0)return;const p=a.data;s.chunkChain=s.chunkChain.then(async()=>{try{const f=await y(p);l({target:u,type:"chunk",recordingId:s.recordingId,dataB64:f})}catch(f){console.error("[recording] failed to encode chunk",f)}})},d.onstop=()=>{const a=c;c=null,a&&(a.maxDurationTimer&&clearTimeout(a.maxDurationTimer),a.chunkChain.then(()=>{l({target:u,type:"stopped",recordingId:a.recordingId,mediaType:a.mediaType,durationMs:Date.now()-a.startedAt,width:a.width,height:a.height}),S(a)}))},i==null||i.addEventListener("ended",()=>{(c==null?void 0:c.recordingId)===s.recordingId&&d.state!=="inactive"&&d.stop()}),s.maxDurationTimer=setTimeout(()=>{(c==null?void 0:c.recordingId)===s.recordingId&&d.state!=="inactive"&&d.stop()},r.maxDurationMs),d.start(m)}catch(e){c=null,l({target:u,type:"error",recordingId:r.recordingId,message:e instanceof Error?e.message:String(e)})}}function w(r){const e=c;(e==null?void 0:e.recordingId)===r&&e.recorder.state!=="inactive"&&e.recorder.stop()}function S(r){for(const e of r.stream.getTracks())e.stop();r.audioContext&&r.audioContext.close()}chrome.runtime.onMessage.addListener(r=>{const e=r;(e==null?void 0:e.target)===h&&(e.type==="start"?T(e):e.type==="stop"&&typeof e.recordingId=="string"&&w(e.recordingId))});
@@ -0,0 +1,46 @@
1
+ {
2
+ "manifest_version": 3,
3
+ "name": "Octavus Browser",
4
+ "description": "Browser automation layer for Octavus OctoAgents",
5
+ "version": "0.1.0",
6
+ "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArizeHEUAbTqb17aDJTDausXhAHO8zmRYVU0vvh8Cm6k2VwyezPIpPlBVeN20UdyErM1gc/zeRvJ2o+RJKEchn0k1tDDKEw13QokGSnuAx+QXUTSDOo2C721cA8Wgtt83xblXjhifdGk0LKYrR9cwrTvtBSSYzSDdBFqV0iUKv0LwYMd5d5rNaKSriCCG93SkLTmjb3X+VEXwpqmRzP/spCZwMJEyKn9PtNIPbtX4dRBxXCpIi8ih5FvcDemsx9X9wnY8d9z07i8XNczaZDnyaD+ylC7T5pGmBi7Ltm+pDyypK8HPNCcE+wMi9IA9X1XC4AlJeMWPYSPy4ZA3JmI3DwIDAQAB",
7
+ "permissions": [
8
+ "debugger",
9
+ "activeTab",
10
+ "tabs",
11
+ "scripting",
12
+ "webNavigation",
13
+ "tabCapture",
14
+ "offscreen"
15
+ ],
16
+ "host_permissions": [
17
+ "<all_urls>"
18
+ ],
19
+ "background": {
20
+ "service_worker": "service-worker-loader.js",
21
+ "type": "module"
22
+ },
23
+ "content_scripts": [
24
+ {
25
+ "js": [
26
+ "assets/accessibility-tree.ts-5Nz2D1Mx.js"
27
+ ],
28
+ "matches": [
29
+ "<all_urls>"
30
+ ],
31
+ "run_at": "document_start",
32
+ "all_frames": true
33
+ }
34
+ ],
35
+ "web_accessible_resources": [
36
+ {
37
+ "matches": [
38
+ "<all_urls>"
39
+ ],
40
+ "resources": [
41
+ "assets/accessibility-tree.ts-5Nz2D1Mx.js"
42
+ ],
43
+ "use_dynamic_url": false
44
+ }
45
+ ]
46
+ }
@@ -0,0 +1 @@
1
+ import './assets/index.ts-Bis5r5UE.js';
@@ -0,0 +1,11 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Octavus recording</title>
6
+ <script type="module" crossorigin src="/assets/offscreen-BKXLIRW6.js"></script>
7
+ <link rel="modulepreload" crossorigin href="/assets/messages-akAS58tQ.js">
8
+ </head>
9
+ <body>
10
+ </body>
11
+ </html>