openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
67 lines (66 loc) • 2.86 kB
JavaScript
import { j as parseAgentSessionKey } from "./session-key-CqAyZeVk.mjs";
import { ni as NEVER } from "./json-schema-processors-CIhP-F53.mjs";
import { Fn as object, Jn as string, Nt as array, Pn as number, qn as strictObject, sr as unknown } from "./schemas-Cy6abvsu.mjs";
import "./routing-DmgGYTrU.mjs";
import { q as getBrowserStateRuntime } from "./session-tab-store-B94ME8MA.mjs";
//#region extensions/browser/src/browser-dashboard-definition.ts
const BROWSER_DASHBOARD_WIDGET_KIND = "browser:dashboard";
const dashboardUrl = string().min(1).max(4096).transform((e, t) => {
const n = URL.parse(e);
if (!n || !["http:", "https:"].includes(n.protocol) || n.username || n.password || n.href.length > 4096) {
t.addIssue({
code: "custom",
message: "Browser dashboard URL must be HTTP(S), without embedded credentials, and at most 4096 characters"
});
return NEVER;
}
return n.href;
});
const browserDashboardPropsSchema = strictObject({
url: dashboardUrl,
profile: string().trim().min(1).max(128).optional()
});
const boardSnapshotSchema = object({
sessionKey: string().min(1),
widgets: array(object({
name: string(),
instanceId: string().optional(),
revision: number().int().positive(),
contentKind: string(),
pluginKind: string().optional(),
props: unknown().optional(),
title: string().optional()
}))
});
/** Resolve the current board instance; a saved browser target is never authority. */
async function readBrowserDashboardDefinition(e, t = "openclaw") {
const n = getBrowserStateRuntime();
if (!n.gateway) throw new Error("Browser dashboards require an active Gateway");
const r = boardSnapshotSchema.parse(await n.gateway.request("board.get", {
sessionKey: e.sessionKey,
...e.agentId ? { agentId: e.agentId } : {}
}));
if (getBrowserStateRuntime() !== n) throw new Error("Browser dashboard runtime changed");
const i = parseAgentSessionKey(r.sessionKey)?.agentId;
if (!i) throw new Error("Board did not return a full agent-scoped session identity");
const a = r.widgets.find((t) => t.name === e.name);
if (!a || a.contentKind !== "plugin" || a.pluginKind !== BROWSER_DASHBOARD_WIDGET_KIND || !a.instanceId || e.instanceId && e.instanceId !== a.instanceId) return;
const o = browserDashboardPropsSchema.safeParse(a.props);
if (!o.success) return;
const s = o.data;
return {
sessionKey: r.sessionKey,
agentId: i,
name: a.name,
instanceId: a.instanceId,
revision: a.revision,
...a.title ? { title: a.title } : {},
url: s.url,
profile: s.profile ?? t
};
}
function sameBrowserDashboardDefinition(e, t) {
return Boolean(t && e.sessionKey === t.sessionKey && e.agentId === t.agentId && e.instanceId === t.instanceId && e.name === t.name && e.url === t.url && e.profile === t.profile);
}
//#endregion
export { sameBrowserDashboardDefinition as n, readBrowserDashboardDefinition as t };