openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
54 lines • 14.1 kB
JavaScript
import{n as e,r as t}from"./rolldown-runtime-CNOWq4Kh.js";import{El as n,Ml as r,Oa as i,Yl as a,et as o,eu as s,ka as c,tt as l,wa as u,xa as d}from"./control-ui-connection-Bfj9beF_.js";import{Xv as f,Yv as p}from"./control-ui-boot-shared-DFTSUQQ0.js";import{El as m,Tl as h}from"./control-ui-boot-chat-DewxEbIm.js";import{Hn as g,Vn as ee}from"./deferred-ui-support-D-VedBtc.js";var _,v;function y(){return(y=e((()=>{c(),_={browser:{nativeTab:`App tab`,remoteTab:`Agent browser tab`,stop:`Stop loading`,profile:`Browser profile: {profile}`,title:`Browser`,open:`Open`,openPanel:`Open browser panel`,moreActions:`More actions`,copyUrl:`Copy URL`,openNewTab:`Open in new tab`,openWithinOpenClaw:`Open in OpenClaw`,toggle:`Toggle browser panel`,close:`Close browser panel`,resize:`Resize browser panel`,newTab:`New tab`,closeTab:`Close tab`,untitledTab:`New tab`,tweetPost:`Post on X`,back:`Back`,forward:`Forward`,reload:`Reload`,openExternal:`Open in your browser`,urlPlaceholder:`Enter a URL and press Enter`,dockBottom:`Dock to bottom`,dockRight:`Dock to right`,annotate:`Annotate page`,inspect:`Inspect element`,annotateSend:`Send to chat`,annotateUndo:`Undo`,annotateClear:`Clear`,annotateDone:`Exit annotate mode`,annotateHint:`Draw on the page, then send the markup to your chat.`,inspectName:`Name`,inspectRole:`Role`,inspectFocusable:`Focusable`,loading:`Loading page…`,notRunning:`The gateway browser is not running.`,start:`Start browser`,errors:{pasteFailed:`Could not paste. Reconnect to a managed browser and try again.`,requestFailed:`Browser request failed: {error}`,downloadFailed:`Could not download this file: {error}. Try again, or open it in your browser to save it.`,downloadEmpty:`No file returned.`,screenshotPathMissing:`Browser screenshot did not return a media path.`,screenshotFetchTimedOut:`Screenshot fetch timed out.`,screenshotFetchFailed:`Screenshot fetch failed ({status}).`,screenshotReadFailed:`Screenshot read failed.`,screenshotDecodeFailed:`Screenshot decode failed.`,canvasUnavailable:`Canvas 2D context unavailable.`},annotatePrompt:{browserTarget:`Browser target: {target}`,introTitled:`I annotated the page at {url} (page-reported title: "{title}") — the attached screenshot shows my markup.`,introUntitled:`I annotated the page at {url} — the attached screenshot shows my markup.`,region:`Marked region {index}: centered around {x}% across / {y}% down, spanning about {width}% × {height}% of the view.`,moreRegions:`…plus {count} more marked region(s), all visible in the screenshot.`,elementDetail:`Marked element (page-reported): {descriptor} — {width}×{height}px at ({x}, {y}).`,outro:`Please look at the marked area and tell me what you make of it.`},address:`Page address`,go:`Go`,actions:`Browser actions`,navigation:`Browser navigation`,loadFailed:`Couldn’t load browser`,newBrowserTab:`New browser tab`,unavailable:`Browser control is unavailable for this connection. Reconnect with browser access.`,navigationBlocked:`The current browser navigation rules block this address. Select another tab or enter an allowed address.`,navigationCheckFailed:`OpenClaw couldn’t verify this tab’s address. Refresh to try again.`,tabUnavailable:`This tab is no longer available. Select another tab.`,noChatTarget:`Open a chat session first so the annotation has somewhere to go.`,annotationLimitReached:`Remove a browser annotation before retrying (maximum 4 cards and 8,000 characters of generated context).`,inspectUnavailable:`Element inspection is disabled (browser.evaluateEnabled=false).`,annotationSent:`Annotation added to the chat composer.`,dashboardSessionShared:`You and your agent share this isolated session browser`,dashboardShared:`You and your agent share this browser page`,dashboardStopped:`This dashboard's browser is stopped.`,dashboardStopping:`Browser stop is pending. Retry to finish closing its tab.`,dashboardStop:`Stop browser`,dashboardRetryStop:`Retry stop`,dashboardResume:`Resume browser`,dashboardReconnect:`Reconnect`,dashboardUnavailable:`Connect to a Gateway with browser access to use this dashboard.`,dashboardMissingIdentity:`Save this dashboard widget again before opening its browser.`,dashboardInvalidReply:`The browser response does not match this dashboard. Reconnect and try again.`,downloading:`Downloading…`,downloadFile:`Download file`,inputLabel:`Browser input: click a field in the page, then type or paste`,manualTextCorrection:`Autocorrect is unavailable in browser control. Edit the text directly.`}},v=Object.assign(()=>{let{errors:e,annotatePrompt:t,...n}=_.browser;Object.assign(i.browser,n),Object.assign(i.browser.errors,e),Object.assign(i.browser.annotatePrompt,t)},{catalog:_})})))()}var b;function x(){return(x=e((()=>{b=String.raw`function openclawInspectBrowserElement(x, y) {
const el = document.elementFromPoint(x, y);
if (!el) return null;
const rect = el.getBoundingClientRect();
const label = el.getAttribute("aria-label") || el.getAttribute("alt") || el.getAttribute("title") || "";
const text = (el.textContent || "").replace(/\s+/g, " ").trim();
const nameSource = label || text;
const nameLimit = 120;
// This serialized page function cannot call imported helpers; back up only when the cap splits a surrogate pair.
const nameEnd = (nameSource.codePointAt(nameLimit - 1) || 0) > 0xffff ? nameLimit - 1 : nameLimit;
return {
tag: el.tagName.toLowerCase(),
id: el.id || "",
classes: Array.from(el.classList).slice(0, 6),
role: el.getAttribute("role") || "",
name: nameSource.slice(0, nameEnd),
rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
focusable: typeof el.tabIndex === "number" && el.tabIndex >= 0,
};
}`})))()}var te=t({bindBrowserRequestClient:()=>T,captureBrowserScreenshot:()=>L,fetchBrowserScreenshotDataUrl:()=>X});async function S(e,t,n=`open`){let r=s(await e.request(t.sessionScoped?`browser.dashboard.request`:`browser.request`,{...t.sessionScoped?{sessionKey:t.sessionKey,...t.agentId?{agentId:t.agentId}:{},dashboard:{name:t.name,instanceId:t.instanceId}}:{target:`host`},method:n===`stop`?`DELETE`:n===`inspect`?`GET`:`POST`,path:`/dashboard`,...n===`inspect`?{query:t.sessionScoped?{}:t}:{body:{...t.sessionScoped?{}:t,...n===`resume`?{resume:!0}:{}}},timeoutMs:12e4},{timeoutMs:15e4})),i=m(r?.browserTab);if(typeof r?.sessionKey!=`string`||!r.sessionKey||r.name!==t.name||r.instanceId!==t.instanceId||typeof r.revision!=`number`||!Number.isSafeInteger(r.revision)||typeof r.paused!=`boolean`||typeof r.stopping!=`boolean`||r.stopping&&!r.paused||typeof r.url!=`string`||!r.paused&&!i&&n!==`inspect`)throw Error(u(`browser.dashboardInvalidReply`));return{sessionKey:r.sessionKey,name:t.name,instanceId:t.instanceId,revision:r.revision,paused:r.paused,stopping:r.stopping,url:r.url,...i?{browserTab:i}:{}}}function C(e){let t={...s(e)};for(let e of[`target`,`targetId`,`node`,`profile`])delete t[e];return t}function w(e){return e.slice(-64)}function T(e,t,n=()=>!0,r,i){return{async request(a,o,c){if(!n())throw new DOMException(`Browser request scope ended`,`AbortError`);let l=s(o),u=r?.sessionScoped?r:void 0,d=!r&&a===Z?i?.():void 0,f=u?`browser.dashboard.request`:a,p=u?{method:l?.method,path:l?.path,...l?.timeoutMs===void 0?{}:{timeoutMs:l.timeoutMs},...l?.query?{query:C(l.query)}:{},...l?.body?{body:C(l.body)}:{},sessionKey:u.sessionKey,...u.agentId?{agentId:u.agentId}:{},dashboard:{name:u.name,instanceId:u.instanceId}}:t||r||d?{...l,...t?{target:t.target,...t.target===`node`?{node:t.node}:{},query:{...s(l?.query),profile:t.profile}}:{},...r?{dashboard:r}:{},...d?{tabScope:{sessionKey:d.sessionKey,...l?.method===`GET`&&l.path===`/tabs`?{referencedTabs:w(d.referencedTabs)}:{}}}:{}}:o;return c?await e.request(f,p,c):await e.request(f,p)}}}function E(e,t,n){return n?e.request(Z,t,n):e.request(Z,t)}function D(e,t){return E(e,{method:`POST`,path:`/act`,body:t})}function O(e){return a(e)??``}function k(e){let t=s(e),n=O(t?.targetId);return n?{kind:`remote`,id:O(t?.tabId)||n,targetId:n,title:O(t?.title),url:O(t?.url),...t?.urlUnavailableReason===`navigation_blocked`||t?.urlUnavailableReason===`navigation_check_failed`?{urlUnavailableReason:t.urlUnavailableReason}:{}}:null}async function ne(e){let t=s(await E(e,{method:`GET`,path:`/tabs`})),n=Array.isArray(t?.tabs)?t.tabs.flatMap(e=>k(e)??[]):[];return{running:t?.running===!0,tabs:n,canAutoResizeViewport:t?.canAutoResizeViewport===!0}}async function re(e){await E(e,{method:`POST`,path:`/start`,body:{}})}async function A(e,t){return k(await E(e,{method:`POST`,path:`/tabs/open`,body:{url:t}}))}async function j(e,t){await E(e,{method:`POST`,path:`/tabs/focus`,body:{targetId:t}})}async function M(e,t){await E(e,{method:`DELETE`,path:`/tabs/${encodeURIComponent(t)}`})}async function N(e,t,n,r){let i=s(await e.request(Z,{method:`POST`,path:`/download`,body:{targetId:t,currentDocument:!0,expectedUrl:n,timeoutMs:12e4},timeoutMs:15e4},{signal:r,timeoutMs:15e4})),a=s(i?.download),o=O(a?.path),c=O(a?.suggestedFilename);if(!o||!c)throw Error(u(`browser.errors.downloadEmpty`));return{path:o,filename:c}}async function P(e,t){await E(e,{method:`POST`,path:`/navigate`,body:t})}async function F(e,t,n){let r=s(await E(e,{method:`POST`,path:`/screencast`,body:t},n)),i=O(r?.token),a=O(r?.wsPath);if(!i||!a)throw Error(`browser screencast response is malformed`);return a}function I(e){let t=s(e),n=s(t?.details);return n?.code===`SCREENCAST_UNSUPPORTED`||s(n?.body)?.code===`SCREENCAST_UNSUPPORTED`||s(t?.body)?.code===`SCREENCAST_UNSUPPORTED`}async function L(e,t){let n=s(await E(e,{method:`POST`,path:`/screenshot`,body:{targetId:t,type:`png`}})),r=O(n?.path);if(!r)throw Error(u(`browser.errors.screenshotPathMissing`));return{path:r,url:O(n?.url)}}async function R(e,t){await D(e,{kind:`clickCoords`,targetId:t.targetId,x:Math.max(0,Math.round(t.x)),y:Math.max(0,Math.round(t.y))})}async function z(e,t){await D(e,{kind:`press`,targetId:t.targetId,key:t.key})}async function B(e,t){try{await D(e,{kind:`insertText`,...t})}catch{throw Error(u(`browser.errors.pasteFailed`))}}async function V(e,t){await D(e,{kind:`resize`,targetId:t.targetId,width:Math.round(t.width),height:Math.round(t.height)})}async function H(e,t){return s(await D(e,{kind:`evaluate`,targetId:t.targetId,fn:t.fn}))?.result??null}function U(e){return e instanceof o&&s(e.details)?.reason===`navigation_blocked`}function W(e){if(!(e instanceof Error))return!1;let t=e instanceof o?s(e.details):null,n=t?.code;return n===void 0&&t?.unrecognizedCode!==!0?e.message.includes(`evaluateEnabled=false`):n===`ACT_EVALUATE_DISABLED`}async function G(e,t){let n=Math.round(t.deltaX),r=Math.round(t.deltaY),i=`() => {
const dx = ${n}, dy = ${r}, point = ${t.point?`[${Math.max(0,Math.round(t.point.x))}, ${Math.max(0,Math.round(t.point.y))}]`:`null`};
const scrolls = (value) => value === "auto" || value === "scroll" || value === "overlay";
const canScroll = (el) => {
const style = getComputedStyle(el);
const flexDirection = style.display.endsWith("flex") ? style.flexDirection : "";
const maxY = el.scrollHeight - el.clientHeight;
const reversedY = flexDirection === "column-reverse";
const y = dy !== 0 && scrolls(style.overflowY) &&
(dy > 0 ? el.scrollTop < (reversedY ? 0 : maxY) : el.scrollTop > (reversedY ? -maxY : 0));
const maxX = el.scrollWidth - el.clientWidth;
const reversedX = (style.direction === "rtl") !== (flexDirection === "row-reverse");
const minLeft = reversedX ? -maxX : 0;
const maxLeft = reversedX ? 0 : maxX;
const x = dx !== 0 && scrolls(style.overflowX) &&
(dx > 0 ? el.scrollLeft < maxLeft : el.scrollLeft > minLeft);
return x || y;
};
let el = point ? document.elementFromPoint(point[0], point[1]) : null;
while (el && el.shadowRoot) {
const inner = el.shadowRoot.elementFromPoint(point[0], point[1]);
if (!inner || inner === el) break;
el = inner;
}
while (el && el !== document.scrollingElement) {
if (canScroll(el)) {
el.scrollBy(dx, dy);
return true;
}
const root = el.getRootNode();
el = el.parentElement || (root instanceof ShadowRoot ? root.host : null);
}
window.scrollBy(${n}, ${r});
return true;
}`;await H(e,{targetId:t.targetId,fn:i})}async function K(e,t){await H(e,{targetId:t.targetId,fn:`() => { history.go(${t.delta}); return true; }`})}async function q(e,t){let r=s(await H(e,{targetId:t,fn:`() => ({ cssWidth: window.innerWidth, cssHeight: window.innerHeight, title: document.title, url: location.href })`})),i=n(r?.cssWidth),a=n(r?.cssHeight);return!i||!a||i<=0||a<=0?null:{cssWidth:i,cssHeight:a,title:O(r?.title),url:O(r?.url)}}async function J(e,t){let n=Math.max(0,Math.round(t.x)),r=Math.max(0,Math.round(t.y));return Y(await H(e,{targetId:t.targetId,fn:`() => { ${b}\nreturn openclawInspectBrowserElement(${n}, ${r}); }`}))}function Y(e){let t=s(e);if(!t)return null;let r=s(t.rect);return{tag:O(t.tag),id:O(t.id),classes:Array.isArray(t.classes)?t.classes.filter(e=>typeof e==`string`):[],role:O(t.role),name:O(t.name),rect:{x:n(r?.x)??0,y:n(r?.y)??0,width:n(r?.width)??0,height:n(r?.height)??0},focusable:t.focusable===!0}}async function X(e){let t=new Headers({Accept:`image/*`});e.authToken&&t.set(`Authorization`,`Bearer ${e.authToken}`);let n=new AbortController,r=setTimeout(()=>n.abort(new DOMException(u(`browser.errors.screenshotFetchTimedOut`),`TimeoutError`)),Q),i;try{let r=await fetch(ee(e.path,e.resourceBasePath),{method:`GET`,headers:t,credentials:`same-origin`,signal:n.signal});if(!r.ok)throw r.body?.cancel().catch(()=>void 0),Error(u(`browser.errors.screenshotFetchFailed`,{status:String(r.status)}));i=await r.blob()}finally{clearTimeout(r)}return f(i,()=>u(`browser.errors.screenshotReadFailed`))}var Z,Q;function $(){return($=e((()=>{r(),l(),g(),d(),y(),p(),x(),h(),v(),Z=`browser.request`,Q=3e4})))()}export{S as C,re as D,G as E,y as O,q as S,V as T,ne as _,R as a,z as b,X as c,$ as d,B as f,I as g,U as h,L as i,v as k,j as l,W as m,w as n,M as o,J as p,te as r,N as s,T as t,K as u,P as v,F as w,Y as x,A as y};