@alfe.ai/openclaw-remote 0.0.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/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/plugin.cjs +304 -0
- package/dist/plugin.d.cts +72 -0
- package/dist/plugin.d.ts +72 -0
- package/dist/plugin.js +305 -0
- package/dist/plugin2.d.cts +2 -0
- package/dist/plugin2.d.ts +2 -0
- package/openclaw.plugin.json +28 -0
- package/package.json +52 -0
package/dist/index.cjs
ADDED
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/plugin.cjs
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
let _alfe_ai_config = require("@alfe.ai/config");
|
|
2
|
+
let _alfe_ai_agent_api_client = require("@alfe.ai/agent-api-client");
|
|
3
|
+
let _alfe_ai_remote = require("@alfe.ai/remote");
|
|
4
|
+
let _alfe_ai_browser = require("@alfe.ai/browser");
|
|
5
|
+
let _alfe_ai_terminal = require("@alfe.ai/terminal");
|
|
6
|
+
//#region src/plugin.ts
|
|
7
|
+
/**
|
|
8
|
+
* @alfe.ai/openclaw-remote — OpenClaw plugin for the interactive remote-control
|
|
9
|
+
* relay. Owns one outbound WS to the relay and routes per-session frames to the
|
|
10
|
+
* browser co-browse surface (@alfe.ai/browser) or the web terminal surface
|
|
11
|
+
* (@alfe.ai/terminal). Registers the agent-callable browser tools, including
|
|
12
|
+
* `request_browser_takeover` ("help me complete these").
|
|
13
|
+
*
|
|
14
|
+
* Follows the established Alfe plugin shape (see @alfe.ai/openclaw-webhooks):
|
|
15
|
+
* tools register on every activate(); the long-lived connection is guarded and
|
|
16
|
+
* created inside registerService.start.
|
|
17
|
+
*/
|
|
18
|
+
const pkg = (0, require("node:module").createRequire)(require("url").pathToFileURL(__filename).href)("../package.json");
|
|
19
|
+
const ACTIVATED_KEY = "__alfeRemotePluginActivated";
|
|
20
|
+
const DEFAULT_HANDOFF_TIMEOUT_MS = 600 * 1e3;
|
|
21
|
+
const DEFAULT_CHROME_PATH = "/usr/bin/google-chrome-stable";
|
|
22
|
+
let remoteClient = null;
|
|
23
|
+
let browserSurface = null;
|
|
24
|
+
let terminalSurface = null;
|
|
25
|
+
let apiClient = null;
|
|
26
|
+
let handoffTimeoutMs = DEFAULT_HANDOFF_TIMEOUT_MS;
|
|
27
|
+
const sessionSurfaces = /* @__PURE__ */ new Map();
|
|
28
|
+
function g() {
|
|
29
|
+
return globalThis;
|
|
30
|
+
}
|
|
31
|
+
/** Coerce an unknown tool param to a string (empty if not a string). */
|
|
32
|
+
function asStr(v) {
|
|
33
|
+
return typeof v === "string" ? v : "";
|
|
34
|
+
}
|
|
35
|
+
/** Coerce an unknown tool param to a string or undefined. */
|
|
36
|
+
function optStr(v) {
|
|
37
|
+
return typeof v === "string" ? v : void 0;
|
|
38
|
+
}
|
|
39
|
+
/** Route an inbound relay frame to the owning surface by session. */
|
|
40
|
+
function dispatchFrame(frame, log) {
|
|
41
|
+
if (frame.type === _alfe_ai_remote.RemoteFrameType.SESSION_OPEN) {
|
|
42
|
+
const open = (0, _alfe_ai_remote.decodeJson)(frame.payload);
|
|
43
|
+
if (!open) return;
|
|
44
|
+
const handler = open.surface === "terminal" ? terminalSurface : browserSurface;
|
|
45
|
+
if (!handler) {
|
|
46
|
+
log.warn(`No handler for surface ${open.surface}`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
sessionSurfaces.set(frame.sessionId, open.surface);
|
|
50
|
+
Promise.resolve(handler.openSession(frame.sessionId, open)).catch((err) => {
|
|
51
|
+
log.warn(`openSession failed: ${err.message}`);
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const surface = sessionSurfaces.get(frame.sessionId);
|
|
56
|
+
const handler = surface === "terminal" ? terminalSurface : surface === "browser" ? browserSurface : null;
|
|
57
|
+
if (!handler) return;
|
|
58
|
+
if (frame.type === _alfe_ai_remote.RemoteFrameType.SESSION_CLOSE) {
|
|
59
|
+
handler.closeSession(frame.sessionId);
|
|
60
|
+
sessionSurfaces.delete(frame.sessionId);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
handler.handleFrame(frame);
|
|
64
|
+
}
|
|
65
|
+
function startService(pluginConfig, workspaceDir, log) {
|
|
66
|
+
if (g()[ACTIVATED_KEY] === true) {
|
|
67
|
+
log.debug("Alfe Remote plugin already activated — skipping duplicate");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
g()[ACTIVATED_KEY] = true;
|
|
71
|
+
let alfeConfig = null;
|
|
72
|
+
try {
|
|
73
|
+
alfeConfig = (0, _alfe_ai_config.resolveConfig)();
|
|
74
|
+
} catch {
|
|
75
|
+
log.info("Could not resolve Alfe config — remote plugin idle");
|
|
76
|
+
}
|
|
77
|
+
const wsUrl = pluginConfig.remoteWsUrl;
|
|
78
|
+
const apiKey = alfeConfig?.apiKey;
|
|
79
|
+
const apiUrl = alfeConfig?.apiUrl;
|
|
80
|
+
if (!wsUrl || !apiKey || !apiUrl) {
|
|
81
|
+
log.info("Remote relay URL or credentials not configured — plugin running without relay");
|
|
82
|
+
g()[ACTIVATED_KEY] = false;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
handoffTimeoutMs = pluginConfig.handoffTimeoutMs ?? DEFAULT_HANDOFF_TIMEOUT_MS;
|
|
86
|
+
apiClient = new _alfe_ai_agent_api_client.AgentApiClient({
|
|
87
|
+
apiKey,
|
|
88
|
+
apiUrl
|
|
89
|
+
});
|
|
90
|
+
const sendFrame = (buf) => {
|
|
91
|
+
remoteClient?.sendFrame(buf);
|
|
92
|
+
};
|
|
93
|
+
browserSurface = new _alfe_ai_browser.BrowserSurface({
|
|
94
|
+
executablePath: pluginConfig.browserExecutablePath ?? DEFAULT_CHROME_PATH,
|
|
95
|
+
headless: pluginConfig.browserHeadless ?? true,
|
|
96
|
+
noSandbox: pluginConfig.browserNoSandbox ?? true,
|
|
97
|
+
userDataDir: `${workspaceDir ?? alfeConfig?.workspacePath ?? "."}/.alfe-browser-profile`,
|
|
98
|
+
logger: log
|
|
99
|
+
}, sendFrame);
|
|
100
|
+
terminalSurface = new _alfe_ai_terminal.TerminalSurface({
|
|
101
|
+
cwd: workspaceDir ?? alfeConfig?.workspacePath,
|
|
102
|
+
logger: log
|
|
103
|
+
}, sendFrame);
|
|
104
|
+
remoteClient = new _alfe_ai_remote.RemoteServiceClient({
|
|
105
|
+
wsUrl,
|
|
106
|
+
apiKey,
|
|
107
|
+
onFrame: (frame) => {
|
|
108
|
+
dispatchFrame(frame, log);
|
|
109
|
+
},
|
|
110
|
+
onConnectionChange: (connected) => {
|
|
111
|
+
log.info(`Remote relay connection: ${connected ? "connected" : "disconnected"}`);
|
|
112
|
+
},
|
|
113
|
+
logger: log
|
|
114
|
+
});
|
|
115
|
+
remoteClient.start();
|
|
116
|
+
log.info(`Remote plugin started — relay ${wsUrl}`);
|
|
117
|
+
}
|
|
118
|
+
function stopService(log) {
|
|
119
|
+
g()[ACTIVATED_KEY] = false;
|
|
120
|
+
remoteClient?.stop();
|
|
121
|
+
remoteClient = null;
|
|
122
|
+
browserSurface?.shutdown();
|
|
123
|
+
browserSurface = null;
|
|
124
|
+
terminalSurface?.shutdown();
|
|
125
|
+
terminalSurface = null;
|
|
126
|
+
apiClient = null;
|
|
127
|
+
sessionSurfaces.clear();
|
|
128
|
+
log.info("Remote plugin stopped");
|
|
129
|
+
}
|
|
130
|
+
function registerTools(api) {
|
|
131
|
+
const needBrowser = () => {
|
|
132
|
+
if (!browserSurface) throw new Error("Browser surface not available (remote relay not connected)");
|
|
133
|
+
return browserSurface;
|
|
134
|
+
};
|
|
135
|
+
api.registerTool({
|
|
136
|
+
name: "browser_navigate",
|
|
137
|
+
label: "browser_navigate",
|
|
138
|
+
description: "Navigate the shared browser to a URL. Returns the final URL and page title.",
|
|
139
|
+
parameters: {
|
|
140
|
+
type: "object",
|
|
141
|
+
properties: { url: {
|
|
142
|
+
type: "string",
|
|
143
|
+
description: "The URL to open"
|
|
144
|
+
} },
|
|
145
|
+
required: ["url"]
|
|
146
|
+
},
|
|
147
|
+
execute: async (_id, params) => needBrowser().automation.navigate(asStr(params.url))
|
|
148
|
+
});
|
|
149
|
+
api.registerTool({
|
|
150
|
+
name: "browser_click",
|
|
151
|
+
label: "browser_click",
|
|
152
|
+
description: "Click an element in the shared browser by CSS selector.",
|
|
153
|
+
parameters: {
|
|
154
|
+
type: "object",
|
|
155
|
+
properties: { selector: {
|
|
156
|
+
type: "string",
|
|
157
|
+
description: "CSS selector to click"
|
|
158
|
+
} },
|
|
159
|
+
required: ["selector"]
|
|
160
|
+
},
|
|
161
|
+
execute: async (_id, params) => {
|
|
162
|
+
await needBrowser().automation.click(asStr(params.selector));
|
|
163
|
+
return { ok: true };
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
api.registerTool({
|
|
167
|
+
name: "browser_type",
|
|
168
|
+
label: "browser_type",
|
|
169
|
+
description: "Type text into an element in the shared browser by CSS selector.",
|
|
170
|
+
parameters: {
|
|
171
|
+
type: "object",
|
|
172
|
+
properties: {
|
|
173
|
+
selector: {
|
|
174
|
+
type: "string",
|
|
175
|
+
description: "CSS selector of the input"
|
|
176
|
+
},
|
|
177
|
+
text: {
|
|
178
|
+
type: "string",
|
|
179
|
+
description: "Text to type"
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
required: ["selector", "text"]
|
|
183
|
+
},
|
|
184
|
+
execute: async (_id, params) => {
|
|
185
|
+
await needBrowser().automation.type(asStr(params.selector), asStr(params.text));
|
|
186
|
+
return { ok: true };
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
api.registerTool({
|
|
190
|
+
name: "browser_wait_for",
|
|
191
|
+
label: "browser_wait_for",
|
|
192
|
+
description: "Wait for a selector to appear, a URL substring to match, or a fixed delay.",
|
|
193
|
+
parameters: {
|
|
194
|
+
type: "object",
|
|
195
|
+
properties: {
|
|
196
|
+
selector: { type: "string" },
|
|
197
|
+
urlPattern: { type: "string" },
|
|
198
|
+
ms: { type: "number" }
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
execute: async (_id, params) => {
|
|
202
|
+
await needBrowser().automation.waitFor({
|
|
203
|
+
selector: optStr(params.selector),
|
|
204
|
+
urlPattern: optStr(params.urlPattern),
|
|
205
|
+
ms: typeof params.ms === "number" ? params.ms : void 0
|
|
206
|
+
});
|
|
207
|
+
return { ok: true };
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
api.registerTool({
|
|
211
|
+
name: "browser_screenshot",
|
|
212
|
+
label: "browser_screenshot",
|
|
213
|
+
description: "Capture a JPEG screenshot of the shared browser's current page (base64).",
|
|
214
|
+
parameters: {
|
|
215
|
+
type: "object",
|
|
216
|
+
properties: {}
|
|
217
|
+
},
|
|
218
|
+
execute: async () => ({ imageBase64: await needBrowser().automation.screenshot() })
|
|
219
|
+
});
|
|
220
|
+
api.registerTool({
|
|
221
|
+
name: "browser_evaluate",
|
|
222
|
+
label: "browser_evaluate",
|
|
223
|
+
description: "Evaluate a JavaScript expression in the shared browser page and return the result.",
|
|
224
|
+
parameters: {
|
|
225
|
+
type: "object",
|
|
226
|
+
properties: { expression: {
|
|
227
|
+
type: "string",
|
|
228
|
+
description: "JS expression to evaluate"
|
|
229
|
+
} },
|
|
230
|
+
required: ["expression"]
|
|
231
|
+
},
|
|
232
|
+
execute: async (_id, params) => ({ result: await needBrowser().automation.evaluate(asStr(params.expression)) })
|
|
233
|
+
});
|
|
234
|
+
api.registerTool({
|
|
235
|
+
name: "request_browser_takeover",
|
|
236
|
+
label: "request_browser_takeover",
|
|
237
|
+
description: "Ask a human to take over the browser you're currently looking at and complete a step you can't do yourself — logging in, solving a captcha, or clicking through a manual flow. The human sees your current live page, completes the instructions, and hands control back; you then resume on the same authenticated page. Blocks until the human is done or the request times out.",
|
|
238
|
+
parameters: {
|
|
239
|
+
type: "object",
|
|
240
|
+
properties: {
|
|
241
|
+
instructions: {
|
|
242
|
+
type: "string",
|
|
243
|
+
description: "What you need the human to do, e.g. 'Log in with the saved credentials and complete the 2FA prompt, then click Continue.'"
|
|
244
|
+
},
|
|
245
|
+
url: {
|
|
246
|
+
type: "string",
|
|
247
|
+
description: "Optional: the page you're stuck on (display only — the human sees your live page)."
|
|
248
|
+
},
|
|
249
|
+
conversationId: {
|
|
250
|
+
type: "string",
|
|
251
|
+
description: "Optional: the chat conversation to surface the request in."
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
required: ["instructions"]
|
|
255
|
+
},
|
|
256
|
+
execute: async (_id, params) => {
|
|
257
|
+
const surface = needBrowser();
|
|
258
|
+
if (!apiClient) throw new Error("Remote plugin not connected");
|
|
259
|
+
const { sessionId } = await apiClient.requestBrowserTakeover({
|
|
260
|
+
instructions: asStr(params.instructions),
|
|
261
|
+
url: optStr(params.url),
|
|
262
|
+
conversationId: optStr(params.conversationId)
|
|
263
|
+
});
|
|
264
|
+
try {
|
|
265
|
+
return {
|
|
266
|
+
sessionId,
|
|
267
|
+
...await surface.requestHandoff(handoffTimeoutMs)
|
|
268
|
+
};
|
|
269
|
+
} finally {
|
|
270
|
+
await apiClient.completeRemoteSession(sessionId).catch(() => {});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
const plugin = {
|
|
276
|
+
id: "@alfe.ai/openclaw-remote",
|
|
277
|
+
name: "Remote",
|
|
278
|
+
description: "Interactive remote control — browser co-browse takeover and web terminal",
|
|
279
|
+
version: pkg.version,
|
|
280
|
+
activate(api) {
|
|
281
|
+
const log = api.logger;
|
|
282
|
+
const pluginConfig = api.config?.plugins?.entries?.["@alfe.ai/openclaw-remote"]?.config ?? {};
|
|
283
|
+
pluginConfig.browserExecutablePath ??= api.config?.browser?.executablePath;
|
|
284
|
+
pluginConfig.browserHeadless ??= api.config?.browser?.headless;
|
|
285
|
+
pluginConfig.browserNoSandbox ??= api.config?.browser?.noSandbox;
|
|
286
|
+
registerTools(api);
|
|
287
|
+
api.registerService({
|
|
288
|
+
id: "alfe-remote",
|
|
289
|
+
start: (ctx) => {
|
|
290
|
+
startService(pluginConfig, ctx.workspaceDir, log);
|
|
291
|
+
},
|
|
292
|
+
stop: () => {
|
|
293
|
+
stopService(log);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
log.info("Alfe Remote plugin activated");
|
|
297
|
+
},
|
|
298
|
+
deactivate(api) {
|
|
299
|
+
stopService(api.logger);
|
|
300
|
+
api.logger.info("Alfe Remote plugin deactivated");
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
//#endregion
|
|
304
|
+
module.exports = plugin;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Types for the Alfe remote plugin.
|
|
4
|
+
*/
|
|
5
|
+
interface Logger {
|
|
6
|
+
info(msg: string, ...args: unknown[]): void;
|
|
7
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
8
|
+
error(msg: string, ...args: unknown[]): void;
|
|
9
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
10
|
+
}
|
|
11
|
+
interface RemotePluginConfig {
|
|
12
|
+
/** Relay WebSocket URL (e.g. wss://remote.dev.alfe.ai/ws). */
|
|
13
|
+
remoteWsUrl?: string;
|
|
14
|
+
/** Chrome binary path (from the headless-browser integration). */
|
|
15
|
+
browserExecutablePath?: string;
|
|
16
|
+
browserHeadless?: boolean;
|
|
17
|
+
browserNoSandbox?: boolean;
|
|
18
|
+
/** Default handoff timeout in ms (agent parks this long awaiting the human). */
|
|
19
|
+
handoffTimeoutMs?: number;
|
|
20
|
+
}
|
|
21
|
+
interface ToolDef {
|
|
22
|
+
name: string;
|
|
23
|
+
label: string;
|
|
24
|
+
description: string;
|
|
25
|
+
parameters: Record<string, unknown>;
|
|
26
|
+
execute: (toolCallId: string, params: Record<string, unknown>) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
interface OpenClawConfig {
|
|
29
|
+
plugins?: {
|
|
30
|
+
entries?: Record<string, {
|
|
31
|
+
config?: RemotePluginConfig;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}>;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
browser?: {
|
|
37
|
+
executablePath?: string;
|
|
38
|
+
headless?: boolean;
|
|
39
|
+
noSandbox?: boolean;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
};
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
interface PluginServiceContext {
|
|
45
|
+
config: Record<string, unknown>;
|
|
46
|
+
workspaceDir?: string;
|
|
47
|
+
stateDir: string;
|
|
48
|
+
logger: Logger;
|
|
49
|
+
}
|
|
50
|
+
interface OpenClawPluginApi {
|
|
51
|
+
logger: Logger;
|
|
52
|
+
registrationMode?: "full" | "setup-only" | "setup-runtime" | "cli-metadata";
|
|
53
|
+
config?: OpenClawConfig;
|
|
54
|
+
registerTool(tool: ToolDef): void;
|
|
55
|
+
registerService(service: {
|
|
56
|
+
id: string;
|
|
57
|
+
start: (ctx: PluginServiceContext) => void | Promise<void>;
|
|
58
|
+
stop?: (ctx: PluginServiceContext) => void | Promise<void>;
|
|
59
|
+
}): void;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/plugin.d.ts
|
|
63
|
+
declare const plugin: {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
description: string;
|
|
67
|
+
version: string;
|
|
68
|
+
activate(api: OpenClawPluginApi): void;
|
|
69
|
+
deactivate(api: OpenClawPluginApi): void;
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
export { RemotePluginConfig as n, plugin as t };
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Types for the Alfe remote plugin.
|
|
4
|
+
*/
|
|
5
|
+
interface Logger {
|
|
6
|
+
info(msg: string, ...args: unknown[]): void;
|
|
7
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
8
|
+
error(msg: string, ...args: unknown[]): void;
|
|
9
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
10
|
+
}
|
|
11
|
+
interface RemotePluginConfig {
|
|
12
|
+
/** Relay WebSocket URL (e.g. wss://remote.dev.alfe.ai/ws). */
|
|
13
|
+
remoteWsUrl?: string;
|
|
14
|
+
/** Chrome binary path (from the headless-browser integration). */
|
|
15
|
+
browserExecutablePath?: string;
|
|
16
|
+
browserHeadless?: boolean;
|
|
17
|
+
browserNoSandbox?: boolean;
|
|
18
|
+
/** Default handoff timeout in ms (agent parks this long awaiting the human). */
|
|
19
|
+
handoffTimeoutMs?: number;
|
|
20
|
+
}
|
|
21
|
+
interface ToolDef {
|
|
22
|
+
name: string;
|
|
23
|
+
label: string;
|
|
24
|
+
description: string;
|
|
25
|
+
parameters: Record<string, unknown>;
|
|
26
|
+
execute: (toolCallId: string, params: Record<string, unknown>) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
interface OpenClawConfig {
|
|
29
|
+
plugins?: {
|
|
30
|
+
entries?: Record<string, {
|
|
31
|
+
config?: RemotePluginConfig;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}>;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
browser?: {
|
|
37
|
+
executablePath?: string;
|
|
38
|
+
headless?: boolean;
|
|
39
|
+
noSandbox?: boolean;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
};
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
interface PluginServiceContext {
|
|
45
|
+
config: Record<string, unknown>;
|
|
46
|
+
workspaceDir?: string;
|
|
47
|
+
stateDir: string;
|
|
48
|
+
logger: Logger;
|
|
49
|
+
}
|
|
50
|
+
interface OpenClawPluginApi {
|
|
51
|
+
logger: Logger;
|
|
52
|
+
registrationMode?: "full" | "setup-only" | "setup-runtime" | "cli-metadata";
|
|
53
|
+
config?: OpenClawConfig;
|
|
54
|
+
registerTool(tool: ToolDef): void;
|
|
55
|
+
registerService(service: {
|
|
56
|
+
id: string;
|
|
57
|
+
start: (ctx: PluginServiceContext) => void | Promise<void>;
|
|
58
|
+
stop?: (ctx: PluginServiceContext) => void | Promise<void>;
|
|
59
|
+
}): void;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/plugin.d.ts
|
|
63
|
+
declare const plugin: {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
description: string;
|
|
67
|
+
version: string;
|
|
68
|
+
activate(api: OpenClawPluginApi): void;
|
|
69
|
+
deactivate(api: OpenClawPluginApi): void;
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
export { RemotePluginConfig as n, plugin as t };
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { resolveConfig } from "@alfe.ai/config";
|
|
3
|
+
import { AgentApiClient } from "@alfe.ai/agent-api-client";
|
|
4
|
+
import { RemoteFrameType, RemoteServiceClient, decodeJson } from "@alfe.ai/remote";
|
|
5
|
+
import { BrowserSurface } from "@alfe.ai/browser";
|
|
6
|
+
import { TerminalSurface } from "@alfe.ai/terminal";
|
|
7
|
+
//#region src/plugin.ts
|
|
8
|
+
/**
|
|
9
|
+
* @alfe.ai/openclaw-remote — OpenClaw plugin for the interactive remote-control
|
|
10
|
+
* relay. Owns one outbound WS to the relay and routes per-session frames to the
|
|
11
|
+
* browser co-browse surface (@alfe.ai/browser) or the web terminal surface
|
|
12
|
+
* (@alfe.ai/terminal). Registers the agent-callable browser tools, including
|
|
13
|
+
* `request_browser_takeover` ("help me complete these").
|
|
14
|
+
*
|
|
15
|
+
* Follows the established Alfe plugin shape (see @alfe.ai/openclaw-webhooks):
|
|
16
|
+
* tools register on every activate(); the long-lived connection is guarded and
|
|
17
|
+
* created inside registerService.start.
|
|
18
|
+
*/
|
|
19
|
+
const pkg = createRequire(import.meta.url)("../package.json");
|
|
20
|
+
const ACTIVATED_KEY = "__alfeRemotePluginActivated";
|
|
21
|
+
const DEFAULT_HANDOFF_TIMEOUT_MS = 600 * 1e3;
|
|
22
|
+
const DEFAULT_CHROME_PATH = "/usr/bin/google-chrome-stable";
|
|
23
|
+
let remoteClient = null;
|
|
24
|
+
let browserSurface = null;
|
|
25
|
+
let terminalSurface = null;
|
|
26
|
+
let apiClient = null;
|
|
27
|
+
let handoffTimeoutMs = DEFAULT_HANDOFF_TIMEOUT_MS;
|
|
28
|
+
const sessionSurfaces = /* @__PURE__ */ new Map();
|
|
29
|
+
function g() {
|
|
30
|
+
return globalThis;
|
|
31
|
+
}
|
|
32
|
+
/** Coerce an unknown tool param to a string (empty if not a string). */
|
|
33
|
+
function asStr(v) {
|
|
34
|
+
return typeof v === "string" ? v : "";
|
|
35
|
+
}
|
|
36
|
+
/** Coerce an unknown tool param to a string or undefined. */
|
|
37
|
+
function optStr(v) {
|
|
38
|
+
return typeof v === "string" ? v : void 0;
|
|
39
|
+
}
|
|
40
|
+
/** Route an inbound relay frame to the owning surface by session. */
|
|
41
|
+
function dispatchFrame(frame, log) {
|
|
42
|
+
if (frame.type === RemoteFrameType.SESSION_OPEN) {
|
|
43
|
+
const open = decodeJson(frame.payload);
|
|
44
|
+
if (!open) return;
|
|
45
|
+
const handler = open.surface === "terminal" ? terminalSurface : browserSurface;
|
|
46
|
+
if (!handler) {
|
|
47
|
+
log.warn(`No handler for surface ${open.surface}`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
sessionSurfaces.set(frame.sessionId, open.surface);
|
|
51
|
+
Promise.resolve(handler.openSession(frame.sessionId, open)).catch((err) => {
|
|
52
|
+
log.warn(`openSession failed: ${err.message}`);
|
|
53
|
+
});
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const surface = sessionSurfaces.get(frame.sessionId);
|
|
57
|
+
const handler = surface === "terminal" ? terminalSurface : surface === "browser" ? browserSurface : null;
|
|
58
|
+
if (!handler) return;
|
|
59
|
+
if (frame.type === RemoteFrameType.SESSION_CLOSE) {
|
|
60
|
+
handler.closeSession(frame.sessionId);
|
|
61
|
+
sessionSurfaces.delete(frame.sessionId);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
handler.handleFrame(frame);
|
|
65
|
+
}
|
|
66
|
+
function startService(pluginConfig, workspaceDir, log) {
|
|
67
|
+
if (g()[ACTIVATED_KEY] === true) {
|
|
68
|
+
log.debug("Alfe Remote plugin already activated — skipping duplicate");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
g()[ACTIVATED_KEY] = true;
|
|
72
|
+
let alfeConfig = null;
|
|
73
|
+
try {
|
|
74
|
+
alfeConfig = resolveConfig();
|
|
75
|
+
} catch {
|
|
76
|
+
log.info("Could not resolve Alfe config — remote plugin idle");
|
|
77
|
+
}
|
|
78
|
+
const wsUrl = pluginConfig.remoteWsUrl;
|
|
79
|
+
const apiKey = alfeConfig?.apiKey;
|
|
80
|
+
const apiUrl = alfeConfig?.apiUrl;
|
|
81
|
+
if (!wsUrl || !apiKey || !apiUrl) {
|
|
82
|
+
log.info("Remote relay URL or credentials not configured — plugin running without relay");
|
|
83
|
+
g()[ACTIVATED_KEY] = false;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
handoffTimeoutMs = pluginConfig.handoffTimeoutMs ?? DEFAULT_HANDOFF_TIMEOUT_MS;
|
|
87
|
+
apiClient = new AgentApiClient({
|
|
88
|
+
apiKey,
|
|
89
|
+
apiUrl
|
|
90
|
+
});
|
|
91
|
+
const sendFrame = (buf) => {
|
|
92
|
+
remoteClient?.sendFrame(buf);
|
|
93
|
+
};
|
|
94
|
+
browserSurface = new BrowserSurface({
|
|
95
|
+
executablePath: pluginConfig.browserExecutablePath ?? DEFAULT_CHROME_PATH,
|
|
96
|
+
headless: pluginConfig.browserHeadless ?? true,
|
|
97
|
+
noSandbox: pluginConfig.browserNoSandbox ?? true,
|
|
98
|
+
userDataDir: `${workspaceDir ?? alfeConfig?.workspacePath ?? "."}/.alfe-browser-profile`,
|
|
99
|
+
logger: log
|
|
100
|
+
}, sendFrame);
|
|
101
|
+
terminalSurface = new TerminalSurface({
|
|
102
|
+
cwd: workspaceDir ?? alfeConfig?.workspacePath,
|
|
103
|
+
logger: log
|
|
104
|
+
}, sendFrame);
|
|
105
|
+
remoteClient = new RemoteServiceClient({
|
|
106
|
+
wsUrl,
|
|
107
|
+
apiKey,
|
|
108
|
+
onFrame: (frame) => {
|
|
109
|
+
dispatchFrame(frame, log);
|
|
110
|
+
},
|
|
111
|
+
onConnectionChange: (connected) => {
|
|
112
|
+
log.info(`Remote relay connection: ${connected ? "connected" : "disconnected"}`);
|
|
113
|
+
},
|
|
114
|
+
logger: log
|
|
115
|
+
});
|
|
116
|
+
remoteClient.start();
|
|
117
|
+
log.info(`Remote plugin started — relay ${wsUrl}`);
|
|
118
|
+
}
|
|
119
|
+
function stopService(log) {
|
|
120
|
+
g()[ACTIVATED_KEY] = false;
|
|
121
|
+
remoteClient?.stop();
|
|
122
|
+
remoteClient = null;
|
|
123
|
+
browserSurface?.shutdown();
|
|
124
|
+
browserSurface = null;
|
|
125
|
+
terminalSurface?.shutdown();
|
|
126
|
+
terminalSurface = null;
|
|
127
|
+
apiClient = null;
|
|
128
|
+
sessionSurfaces.clear();
|
|
129
|
+
log.info("Remote plugin stopped");
|
|
130
|
+
}
|
|
131
|
+
function registerTools(api) {
|
|
132
|
+
const needBrowser = () => {
|
|
133
|
+
if (!browserSurface) throw new Error("Browser surface not available (remote relay not connected)");
|
|
134
|
+
return browserSurface;
|
|
135
|
+
};
|
|
136
|
+
api.registerTool({
|
|
137
|
+
name: "browser_navigate",
|
|
138
|
+
label: "browser_navigate",
|
|
139
|
+
description: "Navigate the shared browser to a URL. Returns the final URL and page title.",
|
|
140
|
+
parameters: {
|
|
141
|
+
type: "object",
|
|
142
|
+
properties: { url: {
|
|
143
|
+
type: "string",
|
|
144
|
+
description: "The URL to open"
|
|
145
|
+
} },
|
|
146
|
+
required: ["url"]
|
|
147
|
+
},
|
|
148
|
+
execute: async (_id, params) => needBrowser().automation.navigate(asStr(params.url))
|
|
149
|
+
});
|
|
150
|
+
api.registerTool({
|
|
151
|
+
name: "browser_click",
|
|
152
|
+
label: "browser_click",
|
|
153
|
+
description: "Click an element in the shared browser by CSS selector.",
|
|
154
|
+
parameters: {
|
|
155
|
+
type: "object",
|
|
156
|
+
properties: { selector: {
|
|
157
|
+
type: "string",
|
|
158
|
+
description: "CSS selector to click"
|
|
159
|
+
} },
|
|
160
|
+
required: ["selector"]
|
|
161
|
+
},
|
|
162
|
+
execute: async (_id, params) => {
|
|
163
|
+
await needBrowser().automation.click(asStr(params.selector));
|
|
164
|
+
return { ok: true };
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
api.registerTool({
|
|
168
|
+
name: "browser_type",
|
|
169
|
+
label: "browser_type",
|
|
170
|
+
description: "Type text into an element in the shared browser by CSS selector.",
|
|
171
|
+
parameters: {
|
|
172
|
+
type: "object",
|
|
173
|
+
properties: {
|
|
174
|
+
selector: {
|
|
175
|
+
type: "string",
|
|
176
|
+
description: "CSS selector of the input"
|
|
177
|
+
},
|
|
178
|
+
text: {
|
|
179
|
+
type: "string",
|
|
180
|
+
description: "Text to type"
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
required: ["selector", "text"]
|
|
184
|
+
},
|
|
185
|
+
execute: async (_id, params) => {
|
|
186
|
+
await needBrowser().automation.type(asStr(params.selector), asStr(params.text));
|
|
187
|
+
return { ok: true };
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
api.registerTool({
|
|
191
|
+
name: "browser_wait_for",
|
|
192
|
+
label: "browser_wait_for",
|
|
193
|
+
description: "Wait for a selector to appear, a URL substring to match, or a fixed delay.",
|
|
194
|
+
parameters: {
|
|
195
|
+
type: "object",
|
|
196
|
+
properties: {
|
|
197
|
+
selector: { type: "string" },
|
|
198
|
+
urlPattern: { type: "string" },
|
|
199
|
+
ms: { type: "number" }
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
execute: async (_id, params) => {
|
|
203
|
+
await needBrowser().automation.waitFor({
|
|
204
|
+
selector: optStr(params.selector),
|
|
205
|
+
urlPattern: optStr(params.urlPattern),
|
|
206
|
+
ms: typeof params.ms === "number" ? params.ms : void 0
|
|
207
|
+
});
|
|
208
|
+
return { ok: true };
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
api.registerTool({
|
|
212
|
+
name: "browser_screenshot",
|
|
213
|
+
label: "browser_screenshot",
|
|
214
|
+
description: "Capture a JPEG screenshot of the shared browser's current page (base64).",
|
|
215
|
+
parameters: {
|
|
216
|
+
type: "object",
|
|
217
|
+
properties: {}
|
|
218
|
+
},
|
|
219
|
+
execute: async () => ({ imageBase64: await needBrowser().automation.screenshot() })
|
|
220
|
+
});
|
|
221
|
+
api.registerTool({
|
|
222
|
+
name: "browser_evaluate",
|
|
223
|
+
label: "browser_evaluate",
|
|
224
|
+
description: "Evaluate a JavaScript expression in the shared browser page and return the result.",
|
|
225
|
+
parameters: {
|
|
226
|
+
type: "object",
|
|
227
|
+
properties: { expression: {
|
|
228
|
+
type: "string",
|
|
229
|
+
description: "JS expression to evaluate"
|
|
230
|
+
} },
|
|
231
|
+
required: ["expression"]
|
|
232
|
+
},
|
|
233
|
+
execute: async (_id, params) => ({ result: await needBrowser().automation.evaluate(asStr(params.expression)) })
|
|
234
|
+
});
|
|
235
|
+
api.registerTool({
|
|
236
|
+
name: "request_browser_takeover",
|
|
237
|
+
label: "request_browser_takeover",
|
|
238
|
+
description: "Ask a human to take over the browser you're currently looking at and complete a step you can't do yourself — logging in, solving a captcha, or clicking through a manual flow. The human sees your current live page, completes the instructions, and hands control back; you then resume on the same authenticated page. Blocks until the human is done or the request times out.",
|
|
239
|
+
parameters: {
|
|
240
|
+
type: "object",
|
|
241
|
+
properties: {
|
|
242
|
+
instructions: {
|
|
243
|
+
type: "string",
|
|
244
|
+
description: "What you need the human to do, e.g. 'Log in with the saved credentials and complete the 2FA prompt, then click Continue.'"
|
|
245
|
+
},
|
|
246
|
+
url: {
|
|
247
|
+
type: "string",
|
|
248
|
+
description: "Optional: the page you're stuck on (display only — the human sees your live page)."
|
|
249
|
+
},
|
|
250
|
+
conversationId: {
|
|
251
|
+
type: "string",
|
|
252
|
+
description: "Optional: the chat conversation to surface the request in."
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
required: ["instructions"]
|
|
256
|
+
},
|
|
257
|
+
execute: async (_id, params) => {
|
|
258
|
+
const surface = needBrowser();
|
|
259
|
+
if (!apiClient) throw new Error("Remote plugin not connected");
|
|
260
|
+
const { sessionId } = await apiClient.requestBrowserTakeover({
|
|
261
|
+
instructions: asStr(params.instructions),
|
|
262
|
+
url: optStr(params.url),
|
|
263
|
+
conversationId: optStr(params.conversationId)
|
|
264
|
+
});
|
|
265
|
+
try {
|
|
266
|
+
return {
|
|
267
|
+
sessionId,
|
|
268
|
+
...await surface.requestHandoff(handoffTimeoutMs)
|
|
269
|
+
};
|
|
270
|
+
} finally {
|
|
271
|
+
await apiClient.completeRemoteSession(sessionId).catch(() => {});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
const plugin = {
|
|
277
|
+
id: "@alfe.ai/openclaw-remote",
|
|
278
|
+
name: "Remote",
|
|
279
|
+
description: "Interactive remote control — browser co-browse takeover and web terminal",
|
|
280
|
+
version: pkg.version,
|
|
281
|
+
activate(api) {
|
|
282
|
+
const log = api.logger;
|
|
283
|
+
const pluginConfig = api.config?.plugins?.entries?.["@alfe.ai/openclaw-remote"]?.config ?? {};
|
|
284
|
+
pluginConfig.browserExecutablePath ??= api.config?.browser?.executablePath;
|
|
285
|
+
pluginConfig.browserHeadless ??= api.config?.browser?.headless;
|
|
286
|
+
pluginConfig.browserNoSandbox ??= api.config?.browser?.noSandbox;
|
|
287
|
+
registerTools(api);
|
|
288
|
+
api.registerService({
|
|
289
|
+
id: "alfe-remote",
|
|
290
|
+
start: (ctx) => {
|
|
291
|
+
startService(pluginConfig, ctx.workspaceDir, log);
|
|
292
|
+
},
|
|
293
|
+
stop: () => {
|
|
294
|
+
stopService(log);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
log.info("Alfe Remote plugin activated");
|
|
298
|
+
},
|
|
299
|
+
deactivate(api) {
|
|
300
|
+
stopService(api.logger);
|
|
301
|
+
api.logger.info("Alfe Remote plugin deactivated");
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
//#endregion
|
|
305
|
+
export { plugin as default };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "@alfe.ai/openclaw-remote",
|
|
3
|
+
"name": "Remote",
|
|
4
|
+
"description": "Interactive remote control — browser co-browse takeover and web terminal",
|
|
5
|
+
"entry": "./dist/plugin.js",
|
|
6
|
+
"activation": { "onStartup": true },
|
|
7
|
+
"contracts": {
|
|
8
|
+
"tools": [
|
|
9
|
+
"browser_navigate",
|
|
10
|
+
"browser_click",
|
|
11
|
+
"browser_type",
|
|
12
|
+
"browser_wait_for",
|
|
13
|
+
"browser_screenshot",
|
|
14
|
+
"browser_evaluate",
|
|
15
|
+
"request_browser_takeover"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"configSchema": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"additionalProperties": true,
|
|
21
|
+
"properties": {
|
|
22
|
+
"remoteWsUrl": { "type": "string" },
|
|
23
|
+
"browserExecutablePath": { "type": "string" },
|
|
24
|
+
"browserHeadless": { "type": "boolean" },
|
|
25
|
+
"browserNoSandbox": { "type": "boolean" }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alfe.ai/openclaw-remote",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "OpenClaw plugin for Alfe's interactive remote-control relay — browser co-browse + web terminal surfaces over one outbound WS",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/plugin.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./plugin": {
|
|
15
|
+
"types": "./dist/plugin.d.ts",
|
|
16
|
+
"require": "./dist/plugin.cjs",
|
|
17
|
+
"import": "./dist/plugin.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"openclaw": {
|
|
21
|
+
"extensions": [
|
|
22
|
+
"./dist/plugin.js"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"openclaw.plugin.json"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@alfe.ai/agent-api-client": "^0.3.0",
|
|
31
|
+
"@alfe.ai/browser": "^0.0.0",
|
|
32
|
+
"@alfe.ai/config": "0.1.0",
|
|
33
|
+
"@alfe.ai/remote": "^0.0.0",
|
|
34
|
+
"@alfe.ai/terminal": "^0.0.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"openclaw": ">=2026.3.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"openclaw": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"license": "UNLICENSED",
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsdown",
|
|
47
|
+
"dev": "tsdown --watch",
|
|
48
|
+
"test": "vitest run --passWithNoTests",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"lint": "eslint ."
|
|
51
|
+
}
|
|
52
|
+
}
|