openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
139 lines (138 loc) • 4.03 kB
JavaScript
import { t as formatErrorMessage } from "../../errors-BKzCeTYb.mjs";
import { r as createLazyRuntimeModule } from "../../lazy-runtime-zGjszCtt.mjs";
import "../../error-runtime-BM740gJj.mjs";
import { t as definePluginEntry } from "../../plugin-entry-CiJdaHtx.mjs";
import { n as isCanvasHostEnabled, t as canvasConfigSchema } from "../../config-EJug56wU.mjs";
import { n as CANVAS_PRESENT_COMMAND, r as isEligibleCanvasNode, t as canvasToolDefinition } from "../../tool-schema-tDjqPm0h.mjs";
import { randomUUID } from "node:crypto";
//#region extensions/canvas/index.ts
const DEFAULT_CANVAS_NODE_INVOKE_TIMEOUT_MS = 3e4;
const CANVAS_NODE_COMMANDS = [
"canvas.present",
"canvas.hide",
"canvas.navigate"
];
function createLazyCanvasTool(e) {
const t = createLazyRuntimeModule(() => import("../../tool-ByQWBqAq.mjs").then(({ createCanvasTool: t }) => t({ agentSessionKey: e })));
return {
...canvasToolDefinition,
execute: async (...e) => await (await t()).execute(...e)
};
}
var canvas_default = definePluginEntry({
id: "canvas",
name: "Canvas",
description: "Presents hosted widget documents on paired macOS panels.",
configSchema: canvasConfigSchema,
register(e) {
if (isCanvasHostEnabled(e.config)) {
const t = e.runtime.nodes;
async function selectCanvasNode() {
const { selectDefaultNodeFromList: e } = await import("../../plugin-sdk/agent-harness-runtime.js");
const { nodes: n } = await t.list({ connected: true });
return e(n.filter(isEligibleCanvasNode), {
capability: "canvas",
fallback: "first",
preferLocalMac: true
});
}
e.registerWidgetPresenter({
target: "node_panel",
description: "Show on a connected device panel",
async availability() {
try {
return await selectCanvasNode() ? {
ok: true,
value: { available: true }
} : {
ok: false,
error: {
code: "no_eligible_node",
message: "No connected canvas-capable device is available."
}
};
} catch (e) {
return {
ok: false,
error: {
code: "node_error",
message: formatErrorMessage(e)
}
};
}
},
async present({ document: e, context: n }) {
if (!e.hostedUrl) return {
ok: false,
error: {
code: "node_error",
message: "The widget document is not hosted for device presentation."
}
};
let r;
try {
r = await selectCanvasNode();
} catch (e) {
return {
ok: false,
error: {
code: "node_error",
message: formatErrorMessage(e)
}
};
}
if (!r) return {
ok: false,
error: {
code: "no_eligible_node",
message: "No connected canvas-capable device is available."
}
};
try {
await t.invoke({
nodeId: r.nodeId,
command: CANVAS_PRESENT_COMMAND,
params: { url: e.hostedUrl },
timeoutMs: DEFAULT_CANVAS_NODE_INVOKE_TIMEOUT_MS,
idempotencyKey: randomUUID(),
...n.sessionKey ? { sessionKey: n.sessionKey } : {}
});
return {
ok: true,
value: {
kind: "node",
nodeId: r.nodeId,
...r.displayName ? { nodeName: r.displayName } : {}
}
};
} catch (e) {
return {
ok: false,
error: {
code: "node_error",
message: formatErrorMessage(e),
nodeId: r.nodeId
}
};
}
}
});
}
e.registerNodeInvokePolicy({
commands: CANVAS_NODE_COMMANDS,
defaultPlatforms: ["macos"],
handle: async (e) => await e.invokeNode()
});
e.registerTool((e) => createLazyCanvasTool(e.sessionKey));
e.registerNodeCliFeature(async ({ program: e }) => {
const { registerNodesCanvasCommands: t } = await import("../../cli-C3YvBTwf.mjs");
t(e);
}, { descriptors: [{
name: "canvas",
description: "Present widget documents on a paired macOS panel",
hasSubcommands: true
}] });
}
});
//#endregion
export { canvas_default as default };