@agimon-ai/po-computer-use 0.0.0-alpha.21 → 0.0.0-alpha.210
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/LICENSE +110 -149
- package/README.md +9 -8
- package/dist/apiContracts.cjs +65 -45
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.d.mts +2 -2
- package/dist/apiContracts.d.mts.map +1 -1
- package/dist/apiContracts.mjs +65 -45
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/extensionService-BKBTsnkI.cjs +1243 -0
- package/dist/extensionService-BKBTsnkI.cjs.map +1 -0
- package/dist/extensionService-DqtoB79s.mjs +1077 -0
- package/dist/extensionService-DqtoB79s.mjs.map +1 -0
- package/dist/extensions/mcp-ui.mjs +12 -9
- package/dist/extensions/mcp-ui.mjs.map +1 -1
- package/dist/extensions/mcp.cjs +13 -5
- package/dist/extensions/mcp.cjs.map +1 -1
- package/dist/extensions/mcp.d.mts.map +1 -1
- package/dist/extensions/mcp.mjs +13 -5
- package/dist/extensions/mcp.mjs.map +1 -1
- package/dist/extensions/native.mjs +1493 -8
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +1035 -645
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +1020 -630
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +1004 -480
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/index.cjs +14 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +67 -10
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +14 -5
- package/dist/index.mjs.map +1 -1
- package/dist/po-runtime-identity.json +1 -0
- package/docs/computer-scripts.md +1 -1
- package/docs/remote-computer-use.md +11 -0
- package/llms.txt +1 -1
- package/locales/vi.json +153 -0
- package/locales/zh-CN.json +153 -0
- package/package.json +84 -24
- package/src/prompts/codemode-how-to-computer-use/SKILL.md +83 -0
- package/src/types/computerUse.ts +72 -7
- package/src/types/computerUseApi.ts +24 -5
- package/dist/extensionService-Bp0q295i.cjs +0 -504
- package/dist/extensionService-Bp0q295i.cjs.map +0 -1
- package/dist/extensionService-DXvF7esO.mjs +0 -434
- package/dist/extensionService-DXvF7esO.mjs.map +0 -1
- package/src/prompts/po-use-computer-use/SKILL.md +0 -34
|
@@ -1,40 +1,13 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
import { composeRootHooks, composeRootInjects, defineChannel, defineRoot, defineRoutedContribution, runCleanups } from "@agimon-ai/po-core/extensionFile";
|
|
5
|
-
import { defineMinorMode, serverMinorModes } from "@agimon-ai/po-minor-mode";
|
|
1
|
+
import { C as COMPUTER_USE_WINDOW_MAX_BYTES, S as COMPUTER_USE_TRACE_MAX_BYTES, a as routes, b as COMPUTER_USE_REQUEST_TOOL_NAMES, c as COMPUTER_USE_MODE_ID, d as computerUseChannelType, f as COMMAND_DESCRIPTION, g as COMPUTER_USE_CODEMODE_GUIDANCE, h as COMPUTER_USE_ARTIFACT_DIRECTORY, i as createComputerUseApi, l as COMPUTER_USE_ROUTES, m as COMPUTER_USE_ARTIFACTS_SERVICE, n as ComputerScriptExecutionError, o as isDesktopPermission, p as COMMAND_NAME, r as ComputerScriptRunner, s as API_BASE_PATH, t as DefaultComputerUseExtensionService, u as COMPUTER_USE_STATUS_KEY, v as COMPUTER_USE_RECORDING_CHUNK_BYTES, x as COMPUTER_USE_TOOL_NAMES } from "../extensionService-DqtoB79s.mjs";
|
|
2
|
+
import path, { join, resolve } from "node:path";
|
|
3
|
+
import { BACKGROUND_CONTEXT, PO_FS_SERVICE, getOrThrow, requirePoFs, withAbortSignal } from "@agimon-ai/po-core/platform";
|
|
6
4
|
import { randomUUID } from "node:crypto";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const COMPUTER_USE_STATUS_KEY = "po-computer-use";
|
|
14
|
-
const COMPUTER_USE_CONFIRMATION_WINDOW_MS = 12e4;
|
|
15
|
-
/**
|
|
16
|
-
* Every path this API answers on, below its mount.
|
|
17
|
-
*
|
|
18
|
-
* The typed route table in `./apiRoutes` is built from this, the dispatcher
|
|
19
|
-
* reads that table, and the hub channel addresses the broker with these same
|
|
20
|
-
* strings, so a route cannot move on one side alone.
|
|
21
|
-
*/
|
|
22
|
-
const COMPUTER_USE_ROUTES = {
|
|
23
|
-
activate: "/activate",
|
|
24
|
-
artifact: "/artifact",
|
|
25
|
-
agentState: "/agent/state",
|
|
26
|
-
agentObserve: "/agent/observe",
|
|
27
|
-
agentAction: "/agent/action",
|
|
28
|
-
agentStop: "/agent/stop",
|
|
29
|
-
hubState: "/hub/state",
|
|
30
|
-
hubActivation: "/hub/activation",
|
|
31
|
-
hubAuthorization: "/hub/authorization",
|
|
32
|
-
hubNext: "/hub/next",
|
|
33
|
-
hubComplete: "/hub/complete",
|
|
34
|
-
hubStop: "/hub/stop"
|
|
35
|
-
};
|
|
36
|
-
const COMPUTER_USE_WAKE_LIMIT = 1e6;
|
|
37
|
-
//#endregion
|
|
5
|
+
import { composeServerProviderOverrides, defineServerPlugin, packageResourcePath, readPackageResource } from "@agimon-ai/po-core/serverPlugin";
|
|
6
|
+
import { composeRootHooks, composeRootInjects, defineChannel, defineHook, defineResource, defineRoot, defineRoute, defineRoutedContribution, runCleanups } from "@agimon-ai/po-core/extensionFile";
|
|
7
|
+
import { PO_CODEMODE_SERVICE, readPoCodemode } from "@agimon-ai/po-core/codemode";
|
|
8
|
+
import { formatMessage, readPoLang, readPoPersonLocale } from "@agimon-ai/po-core/locale";
|
|
9
|
+
import { defineMode, serverModes } from "@agimon-ai/po-mode";
|
|
10
|
+
import { PoComputerUseHostError } from "@agimon-ai/po-core/hubChannel";
|
|
38
11
|
//#region src/services/mcpTools/index.ts
|
|
39
12
|
const COMPUTER_USE_MCP_TOOLS_SERVICE = "po/computer-use-mcp-tools";
|
|
40
13
|
function mountMcpTools(tools) {
|
|
@@ -54,9 +27,9 @@ function modeState(state, enabled = false) {
|
|
|
54
27
|
const modeEnabled = enabled || phase !== "inactive" && phase !== "failed";
|
|
55
28
|
return {
|
|
56
29
|
activation: modeEnabled ? phase === "stopping" ? "deactivating" : phase === "awaiting_confirmation" || phase === "activating" ? "activating" : "active" : "inactive",
|
|
57
|
-
condition: phase === "
|
|
58
|
-
...modeEnabled && phase === "inactive" ? { detail: "
|
|
59
|
-
...phase === "awaiting_confirmation" ? { detail: "
|
|
30
|
+
condition: phase === "failed" ? "failed" : phase === "awaiting_confirmation" || phase === "activating" || phase === "stopping" ? "queued" : "ready",
|
|
31
|
+
...modeEnabled && phase === "inactive" ? { detail: "Po asks before it takes control" } : {},
|
|
32
|
+
...phase === "awaiting_confirmation" || phase === "activating" ? { detail: "starting computer use" } : {},
|
|
60
33
|
actions: [
|
|
61
34
|
{
|
|
62
35
|
id: "activate",
|
|
@@ -76,6 +49,207 @@ function modeState(state, enabled = false) {
|
|
|
76
49
|
};
|
|
77
50
|
}
|
|
78
51
|
//#endregion
|
|
52
|
+
//#region src/services/computerNamespace/index.ts
|
|
53
|
+
const NOT_ACTIVE$1 = "Computer use is not active for this session.";
|
|
54
|
+
const REQUEST_DECLARATIONS = `declare const computer: {
|
|
55
|
+
/** Lists possible control targets, without screen contents. */
|
|
56
|
+
targets(): Promise<ComputerUseTarget[]>;
|
|
57
|
+
/** Requests human approval. Returns a pending approval; the outcome arrives as a new message. */
|
|
58
|
+
request(options: { target: ComputerUseTarget; durationMinutes: 5 | 15 | 30; reason: string; keepTrace?: boolean }): Promise<unknown>;
|
|
59
|
+
};
|
|
60
|
+
type ComputerUseTarget = { scope: 'desktop' } | {
|
|
61
|
+
bundleId: string; applicationName: string; processId: number; windowId: string; windowTitle: string;
|
|
62
|
+
};`;
|
|
63
|
+
const CONTROL_DECLARATIONS = `
|
|
64
|
+
/**
|
|
65
|
+
* Read-only. Observes the authorized window or whole desktop. A screenshot is shown to the model unless includeScreenshot is false.
|
|
66
|
+
* save: true also keeps the screenshot in session artifacts and returns its path as screenshotArtifact.
|
|
67
|
+
* root narrows to one subtree (an element ref, or on the desktop 'dock', 'menubar' or a window root id).
|
|
68
|
+
* label (substring, any case) and role (exact, e.g. 'AXButton') filter elements.
|
|
69
|
+
* skeleton: true returns only the outline (containers and interactive elements); use it first on large windows.
|
|
70
|
+
* offset/limit page through matches; pass nextOffset back while it is present.
|
|
71
|
+
*/
|
|
72
|
+
state(options?: {
|
|
73
|
+
includeScreenshot?: boolean;
|
|
74
|
+
skeleton?: boolean;
|
|
75
|
+
save?: boolean;
|
|
76
|
+
root?: string;
|
|
77
|
+
label?: string;
|
|
78
|
+
role?: string;
|
|
79
|
+
offset?: number;
|
|
80
|
+
limit?: number;
|
|
81
|
+
}): Promise<Record<string, unknown>>;
|
|
82
|
+
/**
|
|
83
|
+
* Changes the application. One semantic action using ids from the latest state().
|
|
84
|
+
* set_value accepts {{ env.NAME }} or {{ secrets.NAME }}. Secrets need an approved single-window app and seal observations.
|
|
85
|
+
* expand, collapse, toggle, check, uncheck and scroll_to take only the element; select takes value; type takes text.
|
|
86
|
+
* scroll amount is 'line', 'page' or a whole number from 1 to 100.
|
|
87
|
+
* perform runs one of the element's nativeActions, such as 'AXShowMenu'.
|
|
88
|
+
* launch opens an installed app by bundle id or name on a whole-desktop grant; it needs no snapshot.
|
|
89
|
+
*/
|
|
90
|
+
act(
|
|
91
|
+
action:
|
|
92
|
+
| {
|
|
93
|
+
kind:
|
|
94
|
+
| 'press' | 'focus' | 'set_value' | 'scroll' | 'perform'
|
|
95
|
+
| 'expand' | 'collapse' | 'toggle' | 'check' | 'uncheck' | 'select' | 'scroll_to' | 'type';
|
|
96
|
+
snapshotId: string;
|
|
97
|
+
elementRef: string;
|
|
98
|
+
value?: string;
|
|
99
|
+
direction?: 'up' | 'down' | 'left' | 'right';
|
|
100
|
+
amount?: 'line' | 'page' | number;
|
|
101
|
+
text?: string;
|
|
102
|
+
action?: string;
|
|
103
|
+
}
|
|
104
|
+
| { kind: 'launch'; app: string },
|
|
105
|
+
): Promise<Record<string, unknown>>;
|
|
106
|
+
/** Changes the application. Runs an allowlisted script with only the authorized program API. No screenshot unless asked. */
|
|
107
|
+
run(options: { scriptPath: string; input: unknown; trusted?: boolean; includeScreenshot?: boolean }): Promise<Record<string, unknown>>;
|
|
108
|
+
/** Ends the current grant. It never activates anything or changes settings. */
|
|
109
|
+
stop(): Promise<{ phase: string }>;`;
|
|
110
|
+
/** Detached JSON: screenshots (base64) never travel through the return value. */
|
|
111
|
+
function detach(value) {
|
|
112
|
+
return JSON.parse(JSON.stringify(value ?? null, (key, entry) => key === "screenshot" ? void 0 : entry) ?? "null");
|
|
113
|
+
}
|
|
114
|
+
function plain(value, member, allowed) {
|
|
115
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`computer.${member} expects an object.`);
|
|
116
|
+
const unknown = Object.keys(value).find((key) => !allowed.includes(key));
|
|
117
|
+
if (unknown !== void 0) throw new TypeError(`computer.${member} does not accept "${unknown}".`);
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
function optionalBoolean(options, member, key) {
|
|
121
|
+
const value = options[key];
|
|
122
|
+
if (value !== void 0 && typeof value !== "boolean") throw new TypeError(`computer.${member} ${key} must be a boolean.`);
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
function failureMessage(details) {
|
|
126
|
+
if (typeof details === "string") return details;
|
|
127
|
+
const failure = details ?? {};
|
|
128
|
+
const message = typeof failure.error === "string" ? failure.error : "Computer use failed.";
|
|
129
|
+
return failure.completedActions === void 0 ? message : `${message} (completedActions: ${JSON.stringify(failure.completedActions)}, outcomeUncertain: ${String(failure.outcomeUncertain)})`;
|
|
130
|
+
}
|
|
131
|
+
function createComputerNamespace(deps) {
|
|
132
|
+
const operations = deps.operations;
|
|
133
|
+
return {
|
|
134
|
+
name: "computer",
|
|
135
|
+
summary: operations ? "Request human approval, observe or act within the authorized target, run an allowlisted script, or stop control." : "List computer-use targets and request a time-limited, recorded grant with human approval.",
|
|
136
|
+
declarations: operations ? REQUEST_DECLARATIONS.replace("};", `${CONTROL_DECLARATIONS}\n};`) : REQUEST_DECLARATIONS,
|
|
137
|
+
approval: { request: deps.request.policy },
|
|
138
|
+
bind(run) {
|
|
139
|
+
const guard = () => {
|
|
140
|
+
if (run.sessionId !== deps.sessionId) throw new Error("Computer use belongs to another session.");
|
|
141
|
+
run.signal.throwIfAborted();
|
|
142
|
+
deps.lifetime.throwIfAborted();
|
|
143
|
+
return AbortSignal.any([run.signal, deps.lifetime]);
|
|
144
|
+
};
|
|
145
|
+
const ready = {
|
|
146
|
+
targets: async () => detach(await deps.request.targets(guard())),
|
|
147
|
+
request: async (input) => {
|
|
148
|
+
guard();
|
|
149
|
+
return detach(await deps.request.activate(input, run.approvedCall?.approvalId, run.signal));
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
if (!operations) return Object.assign(Object.create(null), ready);
|
|
153
|
+
const finish = (member, tool, args, started, result) => {
|
|
154
|
+
const details = detach(result.details);
|
|
155
|
+
const ok = result.isError !== true;
|
|
156
|
+
run.record?.({
|
|
157
|
+
name: `computer.${member}`,
|
|
158
|
+
tool,
|
|
159
|
+
args: detach(args),
|
|
160
|
+
ok,
|
|
161
|
+
ms: Date.now() - started,
|
|
162
|
+
...ok ? {} : { error: failureMessage(details).slice(0, 512) },
|
|
163
|
+
result: {
|
|
164
|
+
content: result.content.filter((block) => block.type === "text"),
|
|
165
|
+
details
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
if (!ok) throw new Error(failureMessage(details));
|
|
169
|
+
const warnings = [];
|
|
170
|
+
for (const block of result.content) {
|
|
171
|
+
if (block.type !== "image") continue;
|
|
172
|
+
const shown = run.emitImage?.({
|
|
173
|
+
data: block.data,
|
|
174
|
+
mimeType: block.mimeType
|
|
175
|
+
});
|
|
176
|
+
if (shown?.emitted !== true) warnings.push(shown?.warning ?? "Image not shown to the model: this host cannot show images.");
|
|
177
|
+
}
|
|
178
|
+
return warnings.length > 0 ? {
|
|
179
|
+
...details,
|
|
180
|
+
warning: warnings.join(" ")
|
|
181
|
+
} : details;
|
|
182
|
+
};
|
|
183
|
+
const call = async (member, tool, args, operation) => {
|
|
184
|
+
const signal = guard();
|
|
185
|
+
if (!deps.isActive()) throw new Error(NOT_ACTIVE$1);
|
|
186
|
+
return finish(member, tool, args, Date.now(), await operation(signal));
|
|
187
|
+
};
|
|
188
|
+
return Object.assign(Object.create(null), {
|
|
189
|
+
...ready,
|
|
190
|
+
state: async (options) => {
|
|
191
|
+
const parsed = options === void 0 ? {} : plain(options, "state", [
|
|
192
|
+
"includeScreenshot",
|
|
193
|
+
"skeleton",
|
|
194
|
+
"save",
|
|
195
|
+
"root",
|
|
196
|
+
"label",
|
|
197
|
+
"role",
|
|
198
|
+
"offset",
|
|
199
|
+
"limit"
|
|
200
|
+
]);
|
|
201
|
+
const includeScreenshot = optionalBoolean(parsed, "state", "includeScreenshot");
|
|
202
|
+
const saveScreenshot = optionalBoolean(parsed, "state", "save");
|
|
203
|
+
const { save: _save, includeScreenshot: _include, ...query } = parsed;
|
|
204
|
+
const args = {
|
|
205
|
+
...query,
|
|
206
|
+
...includeScreenshot === void 0 ? {} : { includeScreenshot },
|
|
207
|
+
...saveScreenshot === void 0 ? {} : { saveScreenshot }
|
|
208
|
+
};
|
|
209
|
+
return call("state", "computer_state", args, (signal) => operations.state(args, signal));
|
|
210
|
+
},
|
|
211
|
+
act: async (action) => {
|
|
212
|
+
const parsed = plain(action, "act", [
|
|
213
|
+
"kind",
|
|
214
|
+
"snapshotId",
|
|
215
|
+
"elementRef",
|
|
216
|
+
"value",
|
|
217
|
+
"direction",
|
|
218
|
+
"amount",
|
|
219
|
+
"action",
|
|
220
|
+
"app"
|
|
221
|
+
]);
|
|
222
|
+
return call("act", "computer_action", parsed, (signal) => operations.act(parsed, signal));
|
|
223
|
+
},
|
|
224
|
+
run: async (options) => {
|
|
225
|
+
const parsed = plain(options, "run", [
|
|
226
|
+
"scriptPath",
|
|
227
|
+
"input",
|
|
228
|
+
"trusted",
|
|
229
|
+
"includeScreenshot"
|
|
230
|
+
]);
|
|
231
|
+
if (typeof parsed.scriptPath !== "string" || parsed.scriptPath.length === 0) throw new TypeError("computer.run scriptPath must be a non-empty string.");
|
|
232
|
+
if (!("input" in parsed)) throw new TypeError("computer.run requires input.");
|
|
233
|
+
const trusted = optionalBoolean(parsed, "run", "trusted");
|
|
234
|
+
const includeScreenshot = optionalBoolean(parsed, "run", "includeScreenshot");
|
|
235
|
+
const args = {
|
|
236
|
+
scriptPath: parsed.scriptPath,
|
|
237
|
+
input: parsed.input,
|
|
238
|
+
trusted,
|
|
239
|
+
includeScreenshot
|
|
240
|
+
};
|
|
241
|
+
return call("run", "computer_exec", args, (signal) => operations.run(args, signal));
|
|
242
|
+
},
|
|
243
|
+
stop: async () => {
|
|
244
|
+
const signal = guard();
|
|
245
|
+
if (!deps.isActive()) throw new Error(NOT_ACTIVE$1);
|
|
246
|
+
return detach(await operations.stop(signal));
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
79
253
|
//#region src/services/computerToolOutput/index.ts
|
|
80
254
|
const MAX_TEXT_BYTES = 262144;
|
|
81
255
|
const MAX_IMAGE_DATA_LENGTH = 8388608;
|
|
@@ -137,486 +311,141 @@ function computerScriptFailure(error) {
|
|
|
137
311
|
};
|
|
138
312
|
}
|
|
139
313
|
//#endregion
|
|
140
|
-
//#region src/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
* each demand a host-issued bearer token and answer 404 without one; they are
|
|
156
|
-
* declared here because they are this API's surface, not because a page calls
|
|
157
|
-
* them.
|
|
158
|
-
*/
|
|
159
|
-
var apiRoutes_default = defineApiRoutes({
|
|
160
|
-
artifact: {
|
|
161
|
-
method: "GET",
|
|
162
|
-
path: COMPUTER_USE_ROUTES.artifact,
|
|
163
|
-
query: ["artifactId", "offset"],
|
|
164
|
-
raw: true
|
|
165
|
-
},
|
|
166
|
-
activationState: {
|
|
167
|
-
method: "GET",
|
|
168
|
-
path: COMPUTER_USE_ROUTES.activate,
|
|
169
|
-
response: apiResponse()
|
|
170
|
-
},
|
|
171
|
-
cancelActivation: {
|
|
172
|
-
method: "DELETE",
|
|
173
|
-
path: COMPUTER_USE_ROUTES.activate,
|
|
174
|
-
response: apiResponse()
|
|
175
|
-
},
|
|
176
|
-
activate: {
|
|
177
|
-
method: "POST",
|
|
178
|
-
path: COMPUTER_USE_ROUTES.activate,
|
|
179
|
-
response: apiResponse()
|
|
180
|
-
},
|
|
181
|
-
agentState: {
|
|
182
|
-
method: "GET",
|
|
183
|
-
path: COMPUTER_USE_ROUTES.agentState,
|
|
184
|
-
response: apiResponse()
|
|
185
|
-
},
|
|
186
|
-
/** Answers whatever the admitted Desktop provider returned, which is runtime-defined JSON. */
|
|
187
|
-
agentObserve: {
|
|
188
|
-
method: "POST",
|
|
189
|
-
path: COMPUTER_USE_ROUTES.agentObserve,
|
|
190
|
-
response: apiResponse()
|
|
191
|
-
},
|
|
192
|
-
agentAction: {
|
|
193
|
-
method: "POST",
|
|
194
|
-
path: COMPUTER_USE_ROUTES.agentAction,
|
|
195
|
-
response: apiResponse()
|
|
196
|
-
},
|
|
197
|
-
agentStop: {
|
|
198
|
-
method: "POST",
|
|
199
|
-
path: COMPUTER_USE_ROUTES.agentStop,
|
|
200
|
-
response: apiResponse()
|
|
201
|
-
},
|
|
202
|
-
hubState: {
|
|
203
|
-
method: "GET",
|
|
204
|
-
path: COMPUTER_USE_ROUTES.hubState,
|
|
205
|
-
response: apiResponse()
|
|
206
|
-
},
|
|
207
|
-
/** Null until a reader has confirmed one; reading it moves the session to `activating`. */
|
|
208
|
-
hubActivation: {
|
|
209
|
-
method: "GET",
|
|
210
|
-
path: COMPUTER_USE_ROUTES.hubActivation,
|
|
211
|
-
response: apiResponse()
|
|
212
|
-
},
|
|
213
|
-
hubAuthorization: {
|
|
214
|
-
method: "GET",
|
|
215
|
-
path: COMPUTER_USE_ROUTES.hubAuthorization,
|
|
216
|
-
response: apiResponse()
|
|
217
|
-
},
|
|
218
|
-
hubNext: {
|
|
219
|
-
method: "GET",
|
|
220
|
-
path: COMPUTER_USE_ROUTES.hubNext,
|
|
221
|
-
response: apiResponse()
|
|
222
|
-
},
|
|
223
|
-
hubComplete: {
|
|
224
|
-
method: "POST",
|
|
225
|
-
path: COMPUTER_USE_ROUTES.hubComplete,
|
|
226
|
-
response: apiResponse()
|
|
227
|
-
},
|
|
228
|
-
hubStop: {
|
|
229
|
-
method: "POST",
|
|
230
|
-
path: COMPUTER_USE_ROUTES.hubStop,
|
|
231
|
-
response: apiResponse()
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
//#endregion
|
|
235
|
-
//#region src/services/computerUseApi/index.ts
|
|
236
|
-
function jsonError(message, status) {
|
|
237
|
-
return Response.json({ error: message }, { status });
|
|
238
|
-
}
|
|
239
|
-
function record$1(value) {
|
|
240
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
241
|
-
}
|
|
242
|
-
async function body(request) {
|
|
243
|
-
try {
|
|
244
|
-
return record$1(await request.json()) ?? {};
|
|
245
|
-
} catch {
|
|
246
|
-
return {};
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
function semanticAction(value) {
|
|
250
|
-
if (!(typeof value.snapshotId === "string" && value.snapshotId.length > 0 && typeof value.elementRef === "string" && value.elementRef.length > 0)) return false;
|
|
251
|
-
const allowed = (keys) => Object.keys(value).every((key) => keys.includes(key));
|
|
252
|
-
if (value.kind === "press" || value.kind === "focus") return allowed([
|
|
253
|
-
"kind",
|
|
254
|
-
"snapshotId",
|
|
255
|
-
"elementRef"
|
|
256
|
-
]);
|
|
257
|
-
if (value.kind === "set_value") return typeof value.value === "string" && allowed([
|
|
258
|
-
"kind",
|
|
259
|
-
"snapshotId",
|
|
260
|
-
"elementRef",
|
|
261
|
-
"value"
|
|
262
|
-
]);
|
|
263
|
-
if (value.kind === "scroll") return [
|
|
264
|
-
"up",
|
|
265
|
-
"down",
|
|
266
|
-
"left",
|
|
267
|
-
"right"
|
|
268
|
-
].includes(value.direction) && (value.amount === "line" || value.amount === "page") && allowed([
|
|
269
|
-
"kind",
|
|
270
|
-
"snapshotId",
|
|
271
|
-
"elementRef",
|
|
272
|
-
"direction",
|
|
273
|
-
"amount"
|
|
274
|
-
]);
|
|
275
|
-
return false;
|
|
276
|
-
}
|
|
277
|
-
function artifactView(value) {
|
|
278
|
-
const input = record$1(value);
|
|
279
|
-
if (typeof input?.artifactId !== "string" || input.status !== "ready" && input.status !== "failed") return void 0;
|
|
280
|
-
const safeUrl = (candidate) => typeof candidate === "string" && candidate.startsWith("/api/") ? candidate : void 0;
|
|
281
|
-
const downloadUrl = safeUrl(input.downloadUrl);
|
|
282
|
-
const previewUrl = safeUrl(input.previewUrl);
|
|
283
|
-
const artifactFailure = record$1(input.failure);
|
|
284
|
-
const safeFailure = typeof artifactFailure?.code === "string" && typeof artifactFailure.message === "string" ? {
|
|
285
|
-
code: artifactFailure.code.slice(0, 128),
|
|
286
|
-
message: artifactFailure.message.slice(0, 512)
|
|
287
|
-
} : void 0;
|
|
288
|
-
return {
|
|
289
|
-
artifactId: input.artifactId,
|
|
290
|
-
status: input.status,
|
|
291
|
-
...typeof input.sizeBytes === "number" && Number.isSafeInteger(input.sizeBytes) && input.sizeBytes > 0 ? { sizeBytes: input.sizeBytes } : {},
|
|
292
|
-
...downloadUrl === void 0 ? {} : { downloadUrl },
|
|
293
|
-
...previewUrl === void 0 ? {} : { previewUrl },
|
|
294
|
-
...typeof input.actionCount === "number" ? { actionCount: input.actionCount } : {},
|
|
295
|
-
...typeof input.completedAt === "string" ? { completedAt: input.completedAt } : {},
|
|
296
|
-
...safeFailure === void 0 ? {} : { failure: safeFailure }
|
|
297
|
-
};
|
|
314
|
+
//#region src/services/computerUseArtifacts/index.ts
|
|
315
|
+
const PNG_SIGNATURE = Buffer.from([
|
|
316
|
+
137,
|
|
317
|
+
80,
|
|
318
|
+
78,
|
|
319
|
+
71,
|
|
320
|
+
13,
|
|
321
|
+
10,
|
|
322
|
+
26,
|
|
323
|
+
10
|
|
324
|
+
]);
|
|
325
|
+
const MAX_SCREENSHOT_BYTES = 8388608;
|
|
326
|
+
const SAFE_SEGMENT = /^[A-Za-z0-9_-]{1,128}$/u;
|
|
327
|
+
function stamp() {
|
|
328
|
+
return `${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/gu, "-")}-${randomUUID().slice(0, 8)}`;
|
|
298
329
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
this.phase = "failed";
|
|
335
|
-
this.grantId = void 0;
|
|
336
|
-
this.failure = {
|
|
337
|
-
code: "desktop_unavailable",
|
|
338
|
-
message: "Desktop disconnected."
|
|
339
|
-
};
|
|
340
|
-
} else if (this.phase !== "inactive" && this.phase !== "failed") {
|
|
341
|
-
this.phase = "stopping";
|
|
342
|
-
this.rejectPending("Control was stopped by Desktop.");
|
|
343
|
-
}
|
|
344
|
-
this.changed();
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
state() {
|
|
348
|
-
return Object.freeze({
|
|
349
|
-
sessionId: this.sessionId,
|
|
350
|
-
revision: this.revision,
|
|
351
|
-
wake: this.wake,
|
|
352
|
-
phase: this.phase,
|
|
353
|
-
...this.activation === void 0 ? {} : {
|
|
354
|
-
requestId: this.activation.requestId,
|
|
355
|
-
target: this.activation.target,
|
|
356
|
-
durationMs: this.activation.durationSeconds * 1e3
|
|
357
|
-
},
|
|
358
|
-
...this.expiresAt === void 0 ? {} : { expiresAt: this.expiresAt },
|
|
359
|
-
...this.failure === void 0 ? {} : { failure: this.failure },
|
|
360
|
-
...this.artifact === void 0 ? {} : { artifact: this.artifact }
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
/** Tools and the API share this broker. No socket, credential discovery, or second state store. */
|
|
364
|
-
sessionClient() {
|
|
365
|
-
const result = async (response) => {
|
|
366
|
-
const value = await response.json();
|
|
367
|
-
if (!response.ok) throw new Error(value.error ?? `Computer-use request failed (${response.status}).`);
|
|
368
|
-
return value;
|
|
369
|
-
};
|
|
370
|
-
const requireDesktop = () => {
|
|
371
|
-
if (this.closed || !this.desktop?.available || this.desktop.enabled === false) throw new Error("Desktop computer use is unavailable.");
|
|
372
|
-
};
|
|
373
|
-
return {
|
|
374
|
-
state: async () => this.state(),
|
|
375
|
-
subscribeStatus: (listener) => {
|
|
376
|
-
this.listeners.add(listener);
|
|
377
|
-
return () => {
|
|
378
|
-
this.listeners.delete(listener);
|
|
379
|
-
};
|
|
380
|
-
},
|
|
381
|
-
observe: async (signal, options = {}) => {
|
|
382
|
-
requireDesktop();
|
|
383
|
-
return result(await this.enqueue("observe", options, signal));
|
|
384
|
-
},
|
|
385
|
-
act: async (action, signal) => {
|
|
386
|
-
requireDesktop();
|
|
387
|
-
if (!semanticAction(action)) throw new Error("A valid semantic action is required.");
|
|
388
|
-
return result(await this.enqueue("act", action, signal));
|
|
389
|
-
},
|
|
390
|
-
stop: async (signal) => {
|
|
391
|
-
signal?.throwIfAborted();
|
|
392
|
-
if (this.phase !== "inactive" && this.phase !== "failed") {
|
|
393
|
-
this.phase = "stopping";
|
|
394
|
-
this.rejectPending("Computer use was stopped.");
|
|
395
|
-
this.changed();
|
|
396
|
-
}
|
|
397
|
-
return this.state();
|
|
330
|
+
/** One queue per session. Callers pass bytes or a host-bound recording, never a filesystem location. */
|
|
331
|
+
function createComputerUseArtifacts(sessionId, environment, binding, mountSignal) {
|
|
332
|
+
let pending = Promise.resolve();
|
|
333
|
+
const enqueue = (segments, write, requestSignal) => {
|
|
334
|
+
const run = pending.catch(() => void 0).then(async () => {
|
|
335
|
+
const active = binding();
|
|
336
|
+
if (!active) throw new Error("Session artifacts are unavailable.");
|
|
337
|
+
const signal = AbortSignal.any([
|
|
338
|
+
mountSignal,
|
|
339
|
+
active.signal,
|
|
340
|
+
...requestSignal ? [requestSignal] : []
|
|
341
|
+
]);
|
|
342
|
+
const context = withAbortSignal(signal, BACKGROUND_CONTEXT);
|
|
343
|
+
const { fs, storage } = active;
|
|
344
|
+
const check = () => {
|
|
345
|
+
signal.throwIfAborted();
|
|
346
|
+
if (binding() !== active) throw new Error("Session artifact storage changed.");
|
|
347
|
+
};
|
|
348
|
+
const safeDirectory = async (path) => {
|
|
349
|
+
const absolute = resolve(path);
|
|
350
|
+
if (getOrThrow(await fs.fileInfo(absolute, context)).kind !== "directory" || getOrThrow(await fs.canonicalPath(absolute, context)) !== absolute) throw new Error("Unsafe artifact directory.");
|
|
351
|
+
};
|
|
352
|
+
check();
|
|
353
|
+
const root = await storage.rootForSession(sessionId, environment);
|
|
354
|
+
check();
|
|
355
|
+
if (!root) throw new Error("Session artifacts are unavailable.");
|
|
356
|
+
await safeDirectory(root);
|
|
357
|
+
const folders = [root];
|
|
358
|
+
for (const segment of [COMPUTER_USE_ARTIFACT_DIRECTORY, ...segments]) {
|
|
359
|
+
const directory = join(folders.at(-1), segment);
|
|
360
|
+
const info = await fs.fileInfo(directory, context);
|
|
361
|
+
if (!info.ok && info.error.code === "not_found") getOrThrow(await fs.createDir(directory, void 0, context));
|
|
362
|
+
else getOrThrow(info);
|
|
363
|
+
await safeDirectory(directory);
|
|
364
|
+
folders.push(directory);
|
|
398
365
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
authorized(request, token) {
|
|
409
|
-
return token !== void 0 && request.headers.get("authorization") === `Bearer ${token}`;
|
|
410
|
-
}
|
|
411
|
-
async requestActivation(request) {
|
|
412
|
-
if (!this.desktop?.available || !(this.desktop.authorizeActivation?.(request.headers) ?? this.desktop.authorize(request.headers))) return jsonError("Not found.", 404);
|
|
413
|
-
if (this.desktop.enabled === false) return jsonError("Enable computer use in global Desktop settings first.", 409);
|
|
414
|
-
const stamped = poApiCallerFrom(request.headers);
|
|
415
|
-
const caller = stamped?.locality === "remote" ? stamped : {
|
|
416
|
-
locality: "local",
|
|
417
|
-
stepUp: "not-required"
|
|
418
|
-
};
|
|
419
|
-
if (this.phase !== "inactive" && this.phase !== "failed") return jsonError("Computer use is already busy.", 409);
|
|
420
|
-
const input = await body(request);
|
|
421
|
-
const target = record$1(input.target);
|
|
422
|
-
const durationMs = input.durationMs;
|
|
423
|
-
if (target === void 0 && (input.target !== void 0 || caller.locality !== "remote") || target !== void 0 && (typeof target.windowId !== "string" || typeof target.bundleId !== "string")) return jsonError("A Desktop target is required, or a remote request must leave selection to the Mac.", 400);
|
|
424
|
-
if (typeof durationMs !== "number" || !Number.isInteger(durationMs) || durationMs < 1e3 || durationMs > 18e5) return jsonError("The requested duration is invalid.", 400);
|
|
425
|
-
try {
|
|
426
|
-
this.desktop.claim(request.headers);
|
|
427
|
-
await this.beforeActivate?.();
|
|
428
|
-
} catch (error) {
|
|
429
|
-
return jsonError(error instanceof Error ? error.message : String(error), 409);
|
|
430
|
-
}
|
|
431
|
-
if (this.closed || !this.desktop.available || this.phase !== "inactive" && this.phase !== "failed") return jsonError("Computer use is unavailable or already busy.", 409);
|
|
432
|
-
const createdAt = Date.now();
|
|
433
|
-
this.activation = Object.freeze({
|
|
434
|
-
requestId: randomUUID(),
|
|
435
|
-
...target === void 0 ? {} : { target: Object.freeze({ ...target }) },
|
|
436
|
-
durationSeconds: durationMs / 1e3,
|
|
437
|
-
createdAt,
|
|
438
|
-
confirmationExpiresAt: createdAt + COMPUTER_USE_CONFIRMATION_WINDOW_MS,
|
|
439
|
-
caller: Object.freeze({ ...caller })
|
|
440
|
-
});
|
|
441
|
-
this.phase = "awaiting_confirmation";
|
|
442
|
-
this.failure = void 0;
|
|
443
|
-
this.artifact = void 0;
|
|
444
|
-
this.changed();
|
|
445
|
-
return Response.json(this.state(), { status: 202 });
|
|
446
|
-
}
|
|
447
|
-
rejectPending(message) {
|
|
448
|
-
const pending = this.pending;
|
|
449
|
-
if (pending === void 0) return;
|
|
450
|
-
this.pending = void 0;
|
|
451
|
-
pending.dispose();
|
|
452
|
-
pending.reject(new Error(message));
|
|
453
|
-
}
|
|
454
|
-
stopAfterUncertainRequest(message) {
|
|
455
|
-
if (this.phase === "active") {
|
|
456
|
-
this.phase = "stopping";
|
|
457
|
-
this.changed();
|
|
458
|
-
}
|
|
459
|
-
this.rejectPending(message);
|
|
460
|
-
}
|
|
461
|
-
async enqueue(operation, payload, signal) {
|
|
462
|
-
if (this.phase !== "active" || this.grantId === void 0) return jsonError("Computer use is not active.", 409);
|
|
463
|
-
if (this.pending !== void 0) return jsonError("Another computer-use request is live.", 409);
|
|
464
|
-
if (signal?.aborted === true) return jsonError("The computer-use request was cancelled.", 499);
|
|
465
|
-
const sequence = operation === "act" ? ++this.actionSequence : void 0;
|
|
466
|
-
const request = {
|
|
467
|
-
id: randomUUID(),
|
|
468
|
-
operation,
|
|
469
|
-
grantId: this.grantId,
|
|
470
|
-
...sequence === void 0 ? {} : { sequence },
|
|
471
|
-
...payload === void 0 ? {} : { payload }
|
|
472
|
-
};
|
|
473
|
-
const completion = new Promise((resolve, reject) => {
|
|
474
|
-
const onAbort = () => this.stopAfterUncertainRequest("The computer-use request was cancelled.");
|
|
475
|
-
const timer = setTimeout(() => this.stopAfterUncertainRequest("The computer-use request timed out."), this.requestTimeoutMs);
|
|
476
|
-
timer.unref?.();
|
|
477
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
478
|
-
this.pending = {
|
|
479
|
-
request,
|
|
480
|
-
resolve,
|
|
481
|
-
reject,
|
|
482
|
-
dispose: () => {
|
|
483
|
-
clearTimeout(timer);
|
|
484
|
-
signal?.removeEventListener("abort", onAbort);
|
|
366
|
+
return write({
|
|
367
|
+
fs,
|
|
368
|
+
context,
|
|
369
|
+
relative: [COMPUTER_USE_ARTIFACT_DIRECTORY, ...segments].join("/"),
|
|
370
|
+
directory: folders.at(-1),
|
|
371
|
+
check,
|
|
372
|
+
recheck: async () => {
|
|
373
|
+
for (const folder of folders) await safeDirectory(folder);
|
|
485
374
|
}
|
|
486
|
-
};
|
|
375
|
+
});
|
|
487
376
|
});
|
|
488
|
-
|
|
377
|
+
pending = run;
|
|
378
|
+
return run;
|
|
379
|
+
};
|
|
380
|
+
/** Writes `.<name>.tmp`, which the artifact list skips, then renames it into place. */
|
|
381
|
+
const place = async (target, name, fill) => {
|
|
382
|
+
const { fs, context, directory } = target;
|
|
383
|
+
const temporary = join(directory, `.${name}.tmp`);
|
|
384
|
+
const destination = join(directory, name);
|
|
385
|
+
if (getOrThrow(await fs.exists(temporary, context)) || getOrThrow(await fs.exists(destination, context))) throw new Error("Artifact filename is already in use.");
|
|
489
386
|
try {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
const path = url.pathname;
|
|
499
|
-
if (request.method === "GET" && path === apiRoutes_default.artifact.path) {
|
|
500
|
-
if (!(this.desktop?.authorizeRecording?.(request.headers) ?? this.desktop?.authorize(request.headers)) || !this.desktop?.fetchRecording) return jsonError("Not found.", 404);
|
|
501
|
-
const artifactId = url.searchParams.get("artifactId") ?? "";
|
|
502
|
-
const offsetText = url.searchParams.get("offset") ?? "";
|
|
503
|
-
const offset = Number(offsetText);
|
|
504
|
-
if (!/^[0-9]+$/u.test(offsetText) || !Number.isSafeInteger(offset) || offset < 0 || offset > 134217728) return jsonError("Invalid recording offset.", 400);
|
|
505
|
-
return this.desktop.fetchRecording(artifactId, `bytes=${offset}-${offset + 1048576 - 1}`);
|
|
506
|
-
}
|
|
507
|
-
if (path === apiRoutes_default.activate.path && request.method === "GET") {
|
|
508
|
-
if (!this.desktop?.authorizePending?.(request.headers) && !(this.desktop?.authorizeRecording?.(request.headers) ?? this.desktop?.authorize(request.headers))) return jsonError("Not found.", 404);
|
|
509
|
-
return Response.json(this.state());
|
|
510
|
-
}
|
|
511
|
-
if (path === apiRoutes_default.activate.path && request.method === "DELETE") {
|
|
512
|
-
if (!this.desktop?.authorizePending?.(request.headers)) return jsonError("Not found.", 404);
|
|
513
|
-
if (this.phase !== "awaiting_confirmation" && this.phase !== "activating") return jsonError("No activation is pending.", 409);
|
|
514
|
-
this.phase = "stopping";
|
|
515
|
-
this.rejectPending("The activation was cancelled.");
|
|
516
|
-
this.changed();
|
|
517
|
-
return Response.json(this.state(), { status: 202 });
|
|
518
|
-
}
|
|
519
|
-
if (request.method === "POST" && path === apiRoutes_default.activate.path) return this.requestActivation(request);
|
|
520
|
-
const agent = path.startsWith("/agent/");
|
|
521
|
-
const hub = path.startsWith("/hub/");
|
|
522
|
-
if (agent && !this.authorized(request, this.internalToken) || hub && !this.authorized(request, this.hubToken)) return jsonError("Not found.", 404);
|
|
523
|
-
if (request.method === "GET" && (path === apiRoutes_default.agentState.path || path === apiRoutes_default.hubState.path)) return Response.json(this.state());
|
|
524
|
-
if (request.method === "POST" && path === apiRoutes_default.agentObserve.path) return this.enqueue("observe", void 0, request.signal);
|
|
525
|
-
if (request.method === "POST" && path === apiRoutes_default.agentAction.path) {
|
|
526
|
-
const action = await body(request);
|
|
527
|
-
if (!semanticAction(action)) return jsonError("A valid semantic action is required.", 400);
|
|
528
|
-
return this.enqueue("act", action, request.signal);
|
|
529
|
-
}
|
|
530
|
-
if (request.method === "POST" && path === apiRoutes_default.agentStop.path) {
|
|
531
|
-
if (this.phase !== "active") return jsonError("Computer use is not active.", 409);
|
|
532
|
-
this.phase = "stopping";
|
|
533
|
-
this.rejectPending("The computer-use request was stopped.");
|
|
534
|
-
this.changed();
|
|
535
|
-
return Response.json(this.state(), { status: 202 });
|
|
387
|
+
target.check();
|
|
388
|
+
await fill(temporary);
|
|
389
|
+
await target.recheck();
|
|
390
|
+
target.check();
|
|
391
|
+
getOrThrow(await fs.renameFile(temporary, destination, context));
|
|
392
|
+
return `artifact:${target.relative}/${name}`;
|
|
393
|
+
} finally {
|
|
394
|
+
getOrThrow(await fs.remove(temporary, { force: true }, BACKGROUND_CONTEXT));
|
|
536
395
|
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
return
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
if (typeof input.error === "string") {
|
|
566
|
-
this.phase = "failed";
|
|
567
|
-
this.failure = {
|
|
568
|
-
code: "desktop_unavailable",
|
|
569
|
-
message: input.error.slice(0, 512)
|
|
570
|
-
};
|
|
571
|
-
this.activation = void 0;
|
|
572
|
-
} else {
|
|
573
|
-
const host = record$1(input.host);
|
|
574
|
-
if (typeof host?.grantId !== "string" || !Number.isFinite(host.expiresAt) || host.expiresAt <= Date.now()) return jsonError("Desktop did not issue a complete grant.", 502);
|
|
575
|
-
const selectedTarget = record$1(host.target);
|
|
576
|
-
if (this.activation !== void 0 && selectedTarget !== void 0) this.activation = Object.freeze({
|
|
577
|
-
...this.activation,
|
|
578
|
-
target: Object.freeze({ ...selectedTarget })
|
|
579
|
-
});
|
|
580
|
-
this.grantId = host.grantId;
|
|
581
|
-
this.expiresAt = host.expiresAt;
|
|
582
|
-
this.actionSequence = 0;
|
|
583
|
-
this.phase = "active";
|
|
584
|
-
clearTimeout(this.expiryTimer);
|
|
585
|
-
this.expiryTimer = setTimeout(() => {
|
|
586
|
-
if (this.closed || this.phase !== "active") return;
|
|
587
|
-
this.phase = "stopping";
|
|
588
|
-
this.rejectPending("The computer-use grant expired.");
|
|
589
|
-
this.changed();
|
|
590
|
-
}, Math.max(0, this.expiresAt - Date.now()));
|
|
591
|
-
this.expiryTimer.unref?.();
|
|
396
|
+
};
|
|
397
|
+
return {
|
|
398
|
+
/** Saves one observation screenshot (base64 PNG) under its run folder and returns its `artifact:` path. */
|
|
399
|
+
saveScreenshot(data, runId, signal) {
|
|
400
|
+
if (!SAFE_SEGMENT.test(runId)) return Promise.reject(/* @__PURE__ */ new Error("The computer-use run id is invalid."));
|
|
401
|
+
const bytes = Buffer.from(data, "base64");
|
|
402
|
+
if (bytes.length <= PNG_SIGNATURE.length || bytes.length > MAX_SCREENSHOT_BYTES || !bytes.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)) return Promise.reject(/* @__PURE__ */ new Error("The screenshot is not a PNG within the size limit."));
|
|
403
|
+
return enqueue([runId], (target) => place(target, `screenshot-${stamp()}.png`, async (temporary) => {
|
|
404
|
+
getOrThrow(await target.fs.writeFile(temporary, bytes, target.context));
|
|
405
|
+
}), signal);
|
|
406
|
+
},
|
|
407
|
+
/** Copies a consented trace file (JSONL or window PNG) beside the recording, in the host store's bounded ranges. */
|
|
408
|
+
saveTraceFile(kind, source, recordingStamp, signal) {
|
|
409
|
+
const size = source.sizeBytes;
|
|
410
|
+
const limit = kind === "trace" ? COMPUTER_USE_TRACE_MAX_BYTES : COMPUTER_USE_WINDOW_MAX_BYTES;
|
|
411
|
+
if (!SAFE_SEGMENT.test(recordingStamp) || !Number.isSafeInteger(size) || size < 1 || size > limit) return Promise.reject(/* @__PURE__ */ new Error("The trace file exceeds the permitted size."));
|
|
412
|
+
const name = kind === "trace" ? `trace-${recordingStamp}.jsonl` : `window-${recordingStamp}-${source.sequence ?? 0}.png`;
|
|
413
|
+
return enqueue([], (target) => place(target, name, async (temporary) => {
|
|
414
|
+
getOrThrow(await target.fs.writeFile(temporary, /* @__PURE__ */ new Uint8Array(), target.context));
|
|
415
|
+
const chunks = [];
|
|
416
|
+
for (let offset = 0; offset < size; offset += COMPUTER_USE_RECORDING_CHUNK_BYTES) {
|
|
417
|
+
target.check();
|
|
418
|
+
const end = Math.min(offset + COMPUTER_USE_RECORDING_CHUNK_BYTES, size) - 1;
|
|
419
|
+
const response = await source.read(`bytes=${offset}-${end}`);
|
|
420
|
+
if (response.status !== 206 || response.headers.get("content-range") !== `bytes ${offset}-${end}/${size}`) throw new Error("The trace file is unavailable or changed.");
|
|
421
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
422
|
+
if (bytes.byteLength !== end - offset + 1) throw new Error("The trace file response is incomplete.");
|
|
423
|
+
chunks.push(bytes);
|
|
592
424
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
return
|
|
425
|
+
const all = Buffer.concat(chunks);
|
|
426
|
+
if (kind === "window" && !all.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)) throw new Error("The window image is not a PNG.");
|
|
427
|
+
if (kind === "trace") new TextDecoder("utf-8", { fatal: true }).decode(all);
|
|
428
|
+
getOrThrow(await target.fs.appendFile(temporary, all, target.context));
|
|
429
|
+
}), signal);
|
|
430
|
+
},
|
|
431
|
+
/** Copies a finished recording in the host store's own bounded ranges and returns its `artifact:` path. */
|
|
432
|
+
saveRecording(source, signal) {
|
|
433
|
+
const size = source.sizeBytes;
|
|
434
|
+
if (!Number.isSafeInteger(size) || size < 1 || size > 134217728) return Promise.reject(/* @__PURE__ */ new Error("The recording exceeds the permitted size."));
|
|
435
|
+
return enqueue([], (target) => place(target, `recording-${stamp()}.mp4`, async (temporary) => {
|
|
436
|
+
getOrThrow(await target.fs.writeFile(temporary, /* @__PURE__ */ new Uint8Array(), target.context));
|
|
437
|
+
for (let offset = 0; offset < size; offset += COMPUTER_USE_RECORDING_CHUNK_BYTES) {
|
|
438
|
+
target.check();
|
|
439
|
+
const end = Math.min(offset + COMPUTER_USE_RECORDING_CHUNK_BYTES, size) - 1;
|
|
440
|
+
const response = await source.read(`bytes=${offset}-${end}`);
|
|
441
|
+
if (response.status !== 206 || response.headers.get("content-range") !== `bytes ${offset}-${end}/${size}`) throw new Error("The recording is unavailable or changed.");
|
|
442
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
443
|
+
if (bytes.byteLength !== end - offset + 1) throw new Error("The recording response is incomplete.");
|
|
444
|
+
getOrThrow(await target.fs.appendFile(temporary, bytes, target.context));
|
|
445
|
+
}
|
|
446
|
+
}), signal);
|
|
604
447
|
}
|
|
605
|
-
|
|
606
|
-
}
|
|
607
|
-
close() {
|
|
608
|
-
if (this.closed) return;
|
|
609
|
-
this.closed = true;
|
|
610
|
-
clearTimeout(this.expiryTimer);
|
|
611
|
-
this.unsubscribeDesktop?.();
|
|
612
|
-
this.listeners.clear();
|
|
613
|
-
this.rejectPending("Computer-use broker closed.");
|
|
614
|
-
this.grantId = void 0;
|
|
615
|
-
this.expiresAt = void 0;
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
function createComputerUseApi(options) {
|
|
619
|
-
return new ComputerUseRequestBroker(options);
|
|
448
|
+
};
|
|
620
449
|
}
|
|
621
450
|
//#endregion
|
|
622
451
|
//#region src/services/computerUseServer/index.ts
|
|
@@ -624,6 +453,7 @@ function createComputerUseApi(options) {
|
|
|
624
453
|
const SOURCE = "@agimon-ai/po-computer-use";
|
|
625
454
|
const SCRIPT_PATHS_ENV = "PO_COMPUTER_USE_SCRIPT_PATHS";
|
|
626
455
|
const GUIDANCE = "[COMPUTER USE ACTIVE]\nUse computer_state before acting and after any action that may change the interface. Use only element refs and snapshot ids returned by computer_state. Never infer coordinates or bypass secure elements.";
|
|
456
|
+
const NOT_ACTIVE = "Computer use is not active for this session.";
|
|
627
457
|
function output(value, isError = false) {
|
|
628
458
|
return {
|
|
629
459
|
content: [{
|
|
@@ -635,21 +465,29 @@ function output(value, isError = false) {
|
|
|
635
465
|
};
|
|
636
466
|
}
|
|
637
467
|
function createComputerUseServer(host, apiContext) {
|
|
468
|
+
let localeContext;
|
|
469
|
+
const t = (key, fallback, vars) => (localeContext && readPoLang(localeContext)?.t(readPoPersonLocale(localeContext)?.read(), key, fallback, vars)) ?? formatMessage(fallback, vars);
|
|
470
|
+
const bindLocale = (context) => {
|
|
471
|
+
localeContext = context;
|
|
472
|
+
context.effect(() => () => {
|
|
473
|
+
localeContext = void 0;
|
|
474
|
+
});
|
|
475
|
+
};
|
|
638
476
|
if (!apiContext?.computerUse?.available || !apiContext.directEvents) return {
|
|
639
477
|
tools: [],
|
|
640
478
|
commands: []
|
|
641
479
|
};
|
|
642
480
|
const desktop = apiContext.computerUse;
|
|
481
|
+
let profileRuntime;
|
|
643
482
|
const broker = createComputerUseApi({
|
|
644
483
|
sessionId: host.context.sessionId,
|
|
645
484
|
internalToken: apiContext.internalToken,
|
|
646
485
|
hubToken: apiContext.hubToken,
|
|
647
486
|
directEvents: apiContext.directEvents,
|
|
648
487
|
desktop,
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
if (!activity.isIdle || activity.hasPendingMessages) throw new Error("Wait for the agent and its queued prompts to finish before granting computer use.");
|
|
488
|
+
profileRuntime: () => profileRuntime,
|
|
489
|
+
beforeActivate: () => {
|
|
490
|
+
if (!modeSelected()) throw new Error("Enable computer use mode before requesting control.");
|
|
653
491
|
}
|
|
654
492
|
});
|
|
655
493
|
const client = broker.sessionClient();
|
|
@@ -665,21 +503,95 @@ function createComputerUseServer(host, apiContext) {
|
|
|
665
503
|
};
|
|
666
504
|
let state = broker.state();
|
|
667
505
|
const restrictionListeners = /* @__PURE__ */ new Set();
|
|
506
|
+
let codemodeLive = false;
|
|
668
507
|
let stopActivity;
|
|
669
508
|
let modeOwner;
|
|
670
|
-
const
|
|
509
|
+
const lifetime = new AbortController();
|
|
510
|
+
let artifactBinding;
|
|
511
|
+
const artifacts = createComputerUseArtifacts(host.context.sessionId, host.context.environment ?? {}, () => artifactBinding, lifetime.signal);
|
|
512
|
+
const savedRecordings = /* @__PURE__ */ new Set();
|
|
513
|
+
const saveRecording = (artifact) => {
|
|
514
|
+
const fetchRecording = desktop.fetchRecording?.bind(desktop);
|
|
515
|
+
if (artifact?.status === "failed" && !savedRecordings.has(artifact.artifactId)) {
|
|
516
|
+
savedRecordings.add(artifact.artifactId);
|
|
517
|
+
Promise.resolve().then(() => host.context.client.notify({
|
|
518
|
+
body: `The computer-use recording failed: ${artifact.failure?.message ?? "no detail was reported."}`,
|
|
519
|
+
localization: { body: {
|
|
520
|
+
key: "computerUse.notification.recordingFailed",
|
|
521
|
+
fallback: "The computer-use recording failed: {error}",
|
|
522
|
+
vars: { error: artifact.failure?.message ?? t("computerUse.notification.noDetail", "no detail was reported.") }
|
|
523
|
+
} },
|
|
524
|
+
level: "warning"
|
|
525
|
+
})).catch(() => void 0);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
if (artifact?.status !== "ready" || !artifact.sizeBytes || !fetchRecording || savedRecordings.has(artifact.artifactId)) return;
|
|
529
|
+
savedRecordings.add(artifact.artifactId);
|
|
530
|
+
const { artifactId, sizeBytes } = artifact;
|
|
531
|
+
const extras = [...artifact.trace ? [{
|
|
532
|
+
kind: "trace",
|
|
533
|
+
file: artifact.trace
|
|
534
|
+
}] : [], ...(artifact.windows ?? []).slice(0, 32).map((file) => ({
|
|
535
|
+
kind: "window",
|
|
536
|
+
file
|
|
537
|
+
}))];
|
|
538
|
+
const label = artifactId.replace(/[^A-Za-z0-9_-]/gu, "").slice(0, 16) || "trace";
|
|
539
|
+
for (const { kind, file } of extras) artifacts.saveTraceFile(kind, {
|
|
540
|
+
artifactId: file.artifactId,
|
|
541
|
+
sizeBytes: file.sizeBytes,
|
|
542
|
+
...file.sequence === void 0 ? {} : { sequence: file.sequence },
|
|
543
|
+
read: (range) => fetchRecording(file.artifactId, range)
|
|
544
|
+
}, label).catch((error) => {
|
|
545
|
+
if (lifetime.signal.aborted) return;
|
|
546
|
+
return host.context.client.notify({
|
|
547
|
+
body: `A computer-use trace file was not saved to artifacts: ${error instanceof Error ? error.message : String(error)}`,
|
|
548
|
+
localization: { body: {
|
|
549
|
+
key: "computerUse.notification.traceNotSaved",
|
|
550
|
+
fallback: "A computer-use trace file was not saved to artifacts: {error}",
|
|
551
|
+
vars: { error: error instanceof Error ? error.message : String(error) }
|
|
552
|
+
} },
|
|
553
|
+
level: "warning"
|
|
554
|
+
});
|
|
555
|
+
}).catch(() => void 0);
|
|
556
|
+
artifacts.saveRecording({
|
|
557
|
+
artifactId,
|
|
558
|
+
sizeBytes,
|
|
559
|
+
read: (range) => fetchRecording(artifactId, range)
|
|
560
|
+
}).then((saved) => host.context.client.notify({
|
|
561
|
+
body: `Computer-use recording saved to ${saved}.`,
|
|
562
|
+
localization: { body: {
|
|
563
|
+
key: "computerUse.notification.recordingSaved",
|
|
564
|
+
fallback: "Computer-use recording saved to {path}.",
|
|
565
|
+
vars: { path: saved }
|
|
566
|
+
} },
|
|
567
|
+
level: "info"
|
|
568
|
+
}), (error) => {
|
|
569
|
+
if (lifetime.signal.aborted) return;
|
|
570
|
+
return host.context.client.notify({
|
|
571
|
+
body: `The computer-use recording was not saved to artifacts: ${error instanceof Error ? error.message : String(error)}`,
|
|
572
|
+
localization: { body: {
|
|
573
|
+
key: "computerUse.notification.recordingNotSaved",
|
|
574
|
+
fallback: "The computer-use recording was not saved to artifacts: {error}",
|
|
575
|
+
vars: { error: error instanceof Error ? error.message : String(error) }
|
|
576
|
+
} },
|
|
577
|
+
level: "warning"
|
|
578
|
+
});
|
|
579
|
+
}).catch(() => void 0);
|
|
580
|
+
};
|
|
581
|
+
const modeSelected = () => (host.context.selection.state?.["mode"] ?? []).includes(COMPUTER_USE_MODE_ID);
|
|
671
582
|
const publishMode = () => modeOwner?.publish();
|
|
672
583
|
const applyState = (next) => {
|
|
673
584
|
state = next;
|
|
585
|
+
saveRecording(next?.artifact);
|
|
674
586
|
host.context.client.setStatus(COMPUTER_USE_STATUS_KEY, next === void 0 || next.phase === "inactive" ? void 0 : `computer use: ${next.phase}`);
|
|
675
587
|
publishMode();
|
|
676
588
|
for (const listener of restrictionListeners) listener();
|
|
677
589
|
};
|
|
678
590
|
const selectMode = async (enabled) => {
|
|
679
|
-
const modes = (host.context.selection.state?.["
|
|
591
|
+
const modes = (host.context.selection.state?.["mode"] ?? []).filter((mode) => mode !== COMPUTER_USE_MODE_ID);
|
|
680
592
|
await host.changeSelection({
|
|
681
593
|
axis: "state",
|
|
682
|
-
key: "
|
|
594
|
+
key: "mode",
|
|
683
595
|
values: enabled ? [...modes, COMPUTER_USE_MODE_ID] : modes
|
|
684
596
|
});
|
|
685
597
|
publishMode();
|
|
@@ -695,36 +607,209 @@ function createComputerUseServer(host, apiContext) {
|
|
|
695
607
|
applyState(void 0);
|
|
696
608
|
}
|
|
697
609
|
};
|
|
610
|
+
const isActive = () => desktop.available && desktop.enabled !== false && modeSelected() && state?.phase === "active";
|
|
698
611
|
const requireActive = () => {
|
|
699
|
-
if (!
|
|
612
|
+
if (!isActive()) throw new Error(NOT_ACTIVE);
|
|
700
613
|
return client;
|
|
701
614
|
};
|
|
702
|
-
|
|
615
|
+
const canRequest = () => desktop.available && desktop.enabled !== false && desktop.claimApproved !== void 0 && modeSelected();
|
|
616
|
+
const windowFields = {
|
|
617
|
+
bundleId: 512,
|
|
618
|
+
applicationName: 256,
|
|
619
|
+
windowId: 256,
|
|
620
|
+
windowTitle: 1024
|
|
621
|
+
};
|
|
622
|
+
const isWindow = (target) => Object.keys(target).length === 5 && Number.isSafeInteger(target.processId) && target.processId > 0 && Object.entries(windowFields).every(([key, max]) => {
|
|
623
|
+
const value = target[key];
|
|
624
|
+
return typeof value === "string" && value.trim().length > 0 && value.length <= max;
|
|
625
|
+
});
|
|
626
|
+
const isDesktop = (target) => Object.keys(target).length === 1 && target.scope === "desktop";
|
|
627
|
+
const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
628
|
+
const readRequest = (input) => {
|
|
629
|
+
if (!canRequest()) throw new Error("Enable computer use before requesting control.");
|
|
630
|
+
if (state?.phase !== "inactive" && state?.phase !== "failed") throw new Error("Computer use is already busy.");
|
|
631
|
+
const request = record(input);
|
|
632
|
+
if (!request || Object.keys(request).some((key) => ![
|
|
633
|
+
"target",
|
|
634
|
+
"durationMinutes",
|
|
635
|
+
"reason",
|
|
636
|
+
"keepTrace"
|
|
637
|
+
].includes(key))) throw new Error("Supply a target, duration and reason for computer use.");
|
|
638
|
+
const target = record(request.target);
|
|
639
|
+
if (!target || !isDesktop(target) && !isWindow(target)) throw new Error("Choose a target from computer.targets().");
|
|
640
|
+
const { durationMinutes, reason, keepTrace } = request;
|
|
641
|
+
if (durationMinutes !== 5 && durationMinutes !== 15 && durationMinutes !== 30) throw new Error("Choose 5, 15 or 30 minutes for computer use.");
|
|
642
|
+
if (typeof reason !== "string" || !reason.trim() || reason.length > 400) throw new Error("Give a reason for requesting computer use, up to 400 characters.");
|
|
643
|
+
if (keepTrace !== void 0 && (typeof keepTrace !== "boolean" || keepTrace && isDesktop(target))) throw new Error("Extra trace capture is only available for one approved window.");
|
|
644
|
+
return {
|
|
645
|
+
target,
|
|
646
|
+
durationMinutes,
|
|
647
|
+
reason,
|
|
648
|
+
keepTrace: keepTrace === true
|
|
649
|
+
};
|
|
650
|
+
};
|
|
651
|
+
const targetInventory = async (signal) => {
|
|
652
|
+
signal.throwIfAborted();
|
|
653
|
+
if (!canRequest()) throw new Error("Enable computer use before listing targets.");
|
|
654
|
+
const windows = await desktop.targets?.(signal);
|
|
655
|
+
signal.throwIfAborted();
|
|
656
|
+
if (!canRequest()) throw new Error("Computer use is no longer enabled.");
|
|
657
|
+
return [{ scope: "desktop" }, ...Array.isArray(windows) ? windows.flatMap((window) => {
|
|
658
|
+
const candidate = record(window);
|
|
659
|
+
return candidate && isWindow(candidate) ? [{ ...candidate }] : [];
|
|
660
|
+
}) : []];
|
|
661
|
+
};
|
|
662
|
+
const requestPolicy = {
|
|
663
|
+
requirement: "human",
|
|
664
|
+
ownerOnly: true,
|
|
665
|
+
resolve: ([input]) => [readRequest(input)],
|
|
666
|
+
describe(input) {
|
|
667
|
+
const { target, durationMinutes, reason, keepTrace } = readRequest(input);
|
|
668
|
+
const labelText = (label) => {
|
|
669
|
+
switch (label) {
|
|
670
|
+
case "Application": return t("computerUse.approval.application", "Application");
|
|
671
|
+
case "Window": return t("computerUse.approval.window", "Window");
|
|
672
|
+
case "Bundle ID": return t("computerUse.approval.bundleId", "Bundle ID");
|
|
673
|
+
case "Process ID": return t("computerUse.approval.processId", "Process ID");
|
|
674
|
+
case "Window ID": return t("computerUse.approval.windowId", "Window ID");
|
|
675
|
+
case "Reason": return t("computerUse.approval.reason", "Reason");
|
|
676
|
+
default: return label;
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
const content = [];
|
|
680
|
+
const detail = (label, value) => {
|
|
681
|
+
if (value.length <= 300) return {
|
|
682
|
+
label: labelText(label),
|
|
683
|
+
value
|
|
684
|
+
};
|
|
685
|
+
content.push(`${label}:\n${value}`);
|
|
686
|
+
return {
|
|
687
|
+
label: labelText(label),
|
|
688
|
+
value: t("computerUse.approval.fullValue", "See full {label} below.", { label: labelText(label).toLowerCase() })
|
|
689
|
+
};
|
|
690
|
+
};
|
|
691
|
+
const details = isDesktop(target) ? [{
|
|
692
|
+
label: t("computerUse.approval.target", "Target"),
|
|
693
|
+
value: t("computerUse.approval.wholeDesktop", "Whole desktop")
|
|
694
|
+
}] : [
|
|
695
|
+
detail("Application", String(target.applicationName)),
|
|
696
|
+
detail("Window", String(target.windowTitle)),
|
|
697
|
+
detail("Bundle ID", String(target.bundleId)),
|
|
698
|
+
detail("Process ID", String(target.processId)),
|
|
699
|
+
detail("Window ID", String(target.windowId))
|
|
700
|
+
];
|
|
701
|
+
const reasonDetail = detail("Reason", reason);
|
|
702
|
+
const fullContent = content.join("\n\n");
|
|
703
|
+
if (fullContent.length > 65536) throw new Error("Computer-use approval content is too long.");
|
|
704
|
+
return {
|
|
705
|
+
source: t("computerUse.approval.source", "Computer use"),
|
|
706
|
+
title: t("computerUse.approval.title", "Let Po control your computer"),
|
|
707
|
+
summary: isDesktop(target) ? t("computerUse.approval.desktopSummary", "Po can see and control your whole desktop for {minutes} minutes.", { minutes: durationMinutes }) : t("computerUse.approval.windowSummary", "Po can see and control the selected window for {minutes} minutes.", { minutes: durationMinutes }),
|
|
708
|
+
details: [
|
|
709
|
+
...details,
|
|
710
|
+
{
|
|
711
|
+
label: t("computerUse.approval.duration", "Duration"),
|
|
712
|
+
value: t("computerUse.approval.minutes", "{minutes} minutes", { minutes: durationMinutes })
|
|
713
|
+
},
|
|
714
|
+
reasonDetail,
|
|
715
|
+
{
|
|
716
|
+
label: t("computerUse.approval.recording", "Recording"),
|
|
717
|
+
value: keepTrace ? t("computerUse.approval.recordingWithTrace", "Screen and audio recording, action trace and window images") : t("computerUse.approval.recordingOn", "Screen and audio recording on")
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
label: t("computerUse.approval.savedTo", "Saved to"),
|
|
721
|
+
value: t("computerUse.approval.location", "This session’s artifacts, in computer-use/.")
|
|
722
|
+
},
|
|
723
|
+
{
|
|
724
|
+
label: t("computerUse.approval.whoCanOpen", "Who can open it"),
|
|
725
|
+
value: t("computerUse.approval.access", "The session’s agent and paired clients can access session artifacts.")
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
label: t("computerUse.approval.stop", "Stop"),
|
|
729
|
+
value: t("computerUse.approval.stopHint", "You can stop control at any time in Activity.")
|
|
730
|
+
}
|
|
731
|
+
],
|
|
732
|
+
...fullContent ? { content: fullContent } : {}
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
const requestOperations = {
|
|
737
|
+
policy: requestPolicy,
|
|
738
|
+
targets: targetInventory,
|
|
739
|
+
async activate(input, approvalId, signal) {
|
|
740
|
+
if (!approvalId) throw new Error("Human approval is required before taking control.");
|
|
741
|
+
signal.throwIfAborted();
|
|
742
|
+
const { target, durationMinutes, keepTrace } = readRequest(input);
|
|
743
|
+
if (!isDesktop(target) && !(await targetInventory(signal)).some((candidate) => Object.entries(target).every(([key, value]) => candidate[key] === value))) throw new Error("The approved window is no longer available. Request approval for a current target.");
|
|
744
|
+
signal.throwIfAborted();
|
|
745
|
+
const { requestId } = broker.activateApproved(approvalId, target, durationMinutes * 6e4, keepTrace);
|
|
746
|
+
const deadline = AbortSignal.any([
|
|
747
|
+
signal,
|
|
748
|
+
AbortSignal.timeout(3e4),
|
|
749
|
+
lifetime.signal
|
|
750
|
+
]);
|
|
751
|
+
let unsubscribe;
|
|
752
|
+
let abort;
|
|
753
|
+
try {
|
|
754
|
+
return await new Promise((resolve, reject) => {
|
|
755
|
+
const inspect = (next) => {
|
|
756
|
+
if (next.phase === "failed") reject(new Error(next.failure?.message ?? "Computer use could not start."));
|
|
757
|
+
else if (next.requestId !== requestId || next.phase === "stopping") reject(/* @__PURE__ */ new Error("Computer use was cancelled before it started."));
|
|
758
|
+
else if (next.phase === "active") resolve({
|
|
759
|
+
phase: next.phase,
|
|
760
|
+
target: next.target,
|
|
761
|
+
expiresAt: next.expiresAt
|
|
762
|
+
});
|
|
763
|
+
};
|
|
764
|
+
abort = () => reject(/* @__PURE__ */ new Error("Computer use did not start before the approval execution ended."));
|
|
765
|
+
unsubscribe = client.subscribeStatus?.(inspect);
|
|
766
|
+
deadline.addEventListener("abort", abort, { once: true });
|
|
767
|
+
if (deadline.aborted) abort();
|
|
768
|
+
else inspect(broker.state());
|
|
769
|
+
});
|
|
770
|
+
} catch (error) {
|
|
771
|
+
if (deadline.aborted && broker.state().requestId === requestId) await client.stop();
|
|
772
|
+
throw error;
|
|
773
|
+
} finally {
|
|
774
|
+
unsubscribe?.();
|
|
775
|
+
if (abort) deadline.removeEventListener("abort", abort);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
modeOwner = defineMode({
|
|
703
780
|
descriptor: {
|
|
704
781
|
source: SOURCE,
|
|
705
782
|
id: COMPUTER_USE_MODE_ID,
|
|
706
783
|
label: "Computer Use",
|
|
784
|
+
labelKey: "mode.computer-use.computerUse",
|
|
707
785
|
description: "Session-scoped semantic control through Po Desktop.",
|
|
786
|
+
descriptionKey: "mode.computer-use.sessionScopedSemanticControlThroughPoDesktop",
|
|
708
787
|
order: 450,
|
|
709
788
|
actions: [
|
|
710
789
|
{
|
|
711
790
|
id: "activate",
|
|
712
791
|
label: "Activate",
|
|
792
|
+
labelKey: "mode.computer-use.activate",
|
|
713
793
|
description: "Enable computer use for this session.",
|
|
794
|
+
descriptionKey: "mode.computer-use.enableComputerUseForThisSession",
|
|
714
795
|
contexts: ["headless"],
|
|
715
796
|
parameters: []
|
|
716
797
|
},
|
|
717
798
|
{
|
|
718
799
|
id: "deactivate",
|
|
719
800
|
label: "Deactivate",
|
|
801
|
+
labelKey: "mode.computer-use.deactivate",
|
|
720
802
|
description: "Stop this session computer-use run.",
|
|
803
|
+
descriptionKey: "mode.computer-use.stopThisSessionComputerUseRun",
|
|
721
804
|
contexts: ["headless"],
|
|
722
805
|
parameters: []
|
|
723
806
|
},
|
|
724
807
|
{
|
|
725
808
|
id: "doctor",
|
|
726
809
|
label: "Doctor",
|
|
810
|
+
labelKey: "mode.computer-use.doctor",
|
|
727
811
|
description: "Report Desktop availability and session state.",
|
|
812
|
+
descriptionKey: "mode.computer-use.reportDesktopAvailabilityAndSessionState",
|
|
728
813
|
contexts: ["headless"],
|
|
729
814
|
parameters: []
|
|
730
815
|
}
|
|
@@ -736,11 +821,11 @@ function createComputerUseServer(host, apiContext) {
|
|
|
736
821
|
...mode,
|
|
737
822
|
condition: "blocked",
|
|
738
823
|
detail: "Enable computer use in global Desktop settings.",
|
|
739
|
-
actions: mode.actions.map((action) =>
|
|
824
|
+
actions: mode.actions.map((action) => action.id === "deactivate" ? action : {
|
|
740
825
|
...action,
|
|
741
826
|
enabled: false,
|
|
742
827
|
disabledReason: "Enable computer use in global Desktop settings."
|
|
743
|
-
})
|
|
828
|
+
})
|
|
744
829
|
} : mode;
|
|
745
830
|
},
|
|
746
831
|
async handleAction(_runtime, actionId, _argumentsValue, execution) {
|
|
@@ -749,7 +834,7 @@ function createComputerUseServer(host, apiContext) {
|
|
|
749
834
|
if (!desktop.available || desktop.enabled === false) throw new Error("Enable computer use in global Desktop settings first.");
|
|
750
835
|
await selectMode(true);
|
|
751
836
|
await refresh(execution.signal);
|
|
752
|
-
return { message: "Computer use is
|
|
837
|
+
return { message: t("computerUse.mode.activated", "Computer use is on. Po asks for approval before it takes control.") };
|
|
753
838
|
}
|
|
754
839
|
if (actionId === "doctor") {
|
|
755
840
|
await refresh(execution.signal);
|
|
@@ -759,30 +844,141 @@ function createComputerUseServer(host, apiContext) {
|
|
|
759
844
|
if (client && state?.phase !== void 0 && state.phase !== "inactive" && state.phase !== "failed") await client.stop(execution.signal);
|
|
760
845
|
await selectMode(false);
|
|
761
846
|
await refresh(execution.signal);
|
|
762
|
-
return { message: "Computer use deactivated." };
|
|
847
|
+
return { message: t("computerUse.mode.deactivated", "Computer use deactivated.") };
|
|
763
848
|
}
|
|
764
849
|
throw new Error(`Unknown computer-use action: ${actionId}`);
|
|
765
850
|
}
|
|
766
851
|
}).createOwner(void 0);
|
|
852
|
+
const handlers = {
|
|
853
|
+
async state(parameters, signal) {
|
|
854
|
+
try {
|
|
855
|
+
const { saveScreenshot, ...query } = parameters;
|
|
856
|
+
const save = saveScreenshot === true;
|
|
857
|
+
const observation = await requireActive().observe(signal, {
|
|
858
|
+
...query,
|
|
859
|
+
includeScreenshot: save || parameters.includeScreenshot !== false
|
|
860
|
+
});
|
|
861
|
+
if (!save) return computerObservationOutput(observation);
|
|
862
|
+
if (!observation.screenshot) throw new Error("Desktop returned no screenshot to save.");
|
|
863
|
+
const screenshotArtifact = await artifacts.saveScreenshot(observation.screenshot.data, observation.runId, signal);
|
|
864
|
+
return computerObservationOutput({
|
|
865
|
+
...observation,
|
|
866
|
+
...parameters.includeScreenshot === false ? { screenshot: void 0 } : {},
|
|
867
|
+
screenshotArtifact
|
|
868
|
+
});
|
|
869
|
+
} catch (error) {
|
|
870
|
+
return output(error instanceof Error ? error.message : String(error), true);
|
|
871
|
+
}
|
|
872
|
+
},
|
|
873
|
+
async act(parameters, signal) {
|
|
874
|
+
try {
|
|
875
|
+
const result = await requireActive().act(parameters, signal);
|
|
876
|
+
await refresh(signal);
|
|
877
|
+
return output(result);
|
|
878
|
+
} catch (error) {
|
|
879
|
+
return output(error instanceof Error ? error.message : String(error), true);
|
|
880
|
+
}
|
|
881
|
+
},
|
|
882
|
+
async run(parameters, signal) {
|
|
883
|
+
try {
|
|
884
|
+
requireActive();
|
|
885
|
+
if (!dependencies.scriptRunner) throw new Error("Computer script execution is unavailable.");
|
|
886
|
+
return computerScriptOutput(await dependencies.scriptRunner.execute(parameters.scriptPath, parameters.input, signal, parameters));
|
|
887
|
+
} catch (error) {
|
|
888
|
+
return computerScriptFailure(error);
|
|
889
|
+
}
|
|
890
|
+
},
|
|
891
|
+
async stop(signal) {
|
|
892
|
+
await requireActive().stop(signal);
|
|
893
|
+
await refresh(signal);
|
|
894
|
+
return { phase: state?.phase ?? "inactive" };
|
|
895
|
+
}
|
|
896
|
+
};
|
|
767
897
|
const unsubscribeState = client.subscribeStatus?.(applyState);
|
|
768
898
|
return {
|
|
769
899
|
api: [{
|
|
770
900
|
basePath: API_BASE_PATH,
|
|
771
901
|
start: () => broker
|
|
772
902
|
}],
|
|
773
|
-
services: [
|
|
774
|
-
|
|
775
|
-
context
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
903
|
+
services: [
|
|
904
|
+
bindLocale,
|
|
905
|
+
(context) => {
|
|
906
|
+
context.inject(["po/profile-runtime"], (child) => {
|
|
907
|
+
const profile = child.get("po/profile-runtime");
|
|
908
|
+
profileRuntime = profile;
|
|
909
|
+
return () => {
|
|
910
|
+
if (profileRuntime === profile) profileRuntime = void 0;
|
|
911
|
+
};
|
|
912
|
+
});
|
|
913
|
+
},
|
|
914
|
+
(context) => {
|
|
915
|
+
context.inject([PO_FS_SERVICE, COMPUTER_USE_ARTIFACTS_SERVICE], (child) => {
|
|
916
|
+
const controller = new AbortController();
|
|
917
|
+
const binding = {
|
|
918
|
+
fs: requirePoFs(child),
|
|
919
|
+
storage: child.get(COMPUTER_USE_ARTIFACTS_SERVICE),
|
|
920
|
+
signal: controller.signal
|
|
921
|
+
};
|
|
922
|
+
artifactBinding = binding;
|
|
923
|
+
return () => {
|
|
924
|
+
controller.abort();
|
|
925
|
+
if (artifactBinding === binding) artifactBinding = void 0;
|
|
926
|
+
};
|
|
927
|
+
});
|
|
928
|
+
},
|
|
929
|
+
(context) => {
|
|
930
|
+
const fiber = context.plugin(serverModes([modeOwner]));
|
|
931
|
+
context.effect(() => desktop.subscribe(() => {
|
|
932
|
+
if (!desktop.available) fiber.dispose();
|
|
933
|
+
}));
|
|
934
|
+
},
|
|
935
|
+
(context) => {
|
|
936
|
+
context.inject([PO_CODEMODE_SERVICE], (scoped) => {
|
|
937
|
+
const codemode = readPoCodemode(scoped);
|
|
938
|
+
if (!codemode) return void 0;
|
|
939
|
+
const restriction = host.registerToolRestriction({ excludedTools: [...COMPUTER_USE_TOOL_NAMES, ...COMPUTER_USE_REQUEST_TOOL_NAMES] });
|
|
940
|
+
let registration;
|
|
941
|
+
let namespaceLifetime;
|
|
942
|
+
let activeGrant = false;
|
|
943
|
+
const revoke = () => {
|
|
944
|
+
namespaceLifetime?.abort(/* @__PURE__ */ new Error(NOT_ACTIVE));
|
|
945
|
+
namespaceLifetime = void 0;
|
|
946
|
+
registration?.dispose();
|
|
947
|
+
registration = void 0;
|
|
948
|
+
codemodeLive = false;
|
|
949
|
+
};
|
|
950
|
+
const sync = () => {
|
|
951
|
+
const active = isActive();
|
|
952
|
+
const ready = canRequest();
|
|
953
|
+
if (registration && (!ready || active !== activeGrant)) revoke();
|
|
954
|
+
if (ready && !registration) {
|
|
955
|
+
namespaceLifetime = new AbortController();
|
|
956
|
+
registration = codemode.register(SOURCE, createComputerNamespace({
|
|
957
|
+
sessionId: host.context.sessionId,
|
|
958
|
+
request: requestOperations,
|
|
959
|
+
operations: active ? handlers : void 0,
|
|
960
|
+
isActive,
|
|
961
|
+
lifetime: namespaceLifetime.signal
|
|
962
|
+
}));
|
|
963
|
+
activeGrant = active;
|
|
964
|
+
codemodeLive = true;
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
restrictionListeners.add(sync);
|
|
968
|
+
const unsubscribeDesktop = desktop.subscribe(sync);
|
|
969
|
+
sync();
|
|
970
|
+
return () => {
|
|
971
|
+
unsubscribeDesktop();
|
|
972
|
+
restrictionListeners.delete(sync);
|
|
973
|
+
revoke();
|
|
974
|
+
restriction.dispose();
|
|
975
|
+
};
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
],
|
|
779
979
|
toolRestrictions: [{
|
|
780
980
|
source: SOURCE,
|
|
781
|
-
restrict: () => ({ excludedTools:
|
|
782
|
-
"computer_state",
|
|
783
|
-
"computer_action",
|
|
784
|
-
"computer_exec"
|
|
785
|
-
] }),
|
|
981
|
+
restrict: () => ({ excludedTools: [...isActive() ? [] : COMPUTER_USE_TOOL_NAMES, ...canRequest() ? [] : COMPUTER_USE_REQUEST_TOOL_NAMES] }),
|
|
786
982
|
subscribe: (listener) => {
|
|
787
983
|
restrictionListeners.add(listener);
|
|
788
984
|
return () => {
|
|
@@ -792,10 +988,10 @@ function createComputerUseServer(host, apiContext) {
|
|
|
792
988
|
}],
|
|
793
989
|
activities: [{
|
|
794
990
|
when: {
|
|
795
|
-
state: {
|
|
991
|
+
state: { mode: COMPUTER_USE_MODE_ID },
|
|
796
992
|
attribution: {
|
|
797
|
-
kind: "
|
|
798
|
-
|
|
993
|
+
kind: "mode",
|
|
994
|
+
name: COMPUTER_USE_MODE_ID
|
|
799
995
|
}
|
|
800
996
|
},
|
|
801
997
|
name: SOURCE,
|
|
@@ -811,42 +1007,121 @@ function createComputerUseServer(host, apiContext) {
|
|
|
811
1007
|
}
|
|
812
1008
|
}],
|
|
813
1009
|
tools: [
|
|
1010
|
+
{
|
|
1011
|
+
when: { state: { mode: COMPUTER_USE_MODE_ID } },
|
|
1012
|
+
name: "computer_targets",
|
|
1013
|
+
label: "Computer Use Targets",
|
|
1014
|
+
description: "List targets for an approval request, without reading any screen contents.",
|
|
1015
|
+
parameters: {
|
|
1016
|
+
type: "object",
|
|
1017
|
+
properties: {},
|
|
1018
|
+
additionalProperties: false
|
|
1019
|
+
},
|
|
1020
|
+
mainAgentOnly: true,
|
|
1021
|
+
async execute(_id, _parameters, signal) {
|
|
1022
|
+
return output(await targetInventory(signal ?? lifetime.signal));
|
|
1023
|
+
}
|
|
1024
|
+
},
|
|
1025
|
+
{
|
|
1026
|
+
when: { state: { mode: COMPUTER_USE_MODE_ID } },
|
|
1027
|
+
name: "computer_request",
|
|
1028
|
+
label: "Request Computer Use",
|
|
1029
|
+
description: "Ask for a recorded computer-use grant. Requires human approval before any access.",
|
|
1030
|
+
parameters: {
|
|
1031
|
+
type: "object",
|
|
1032
|
+
properties: {
|
|
1033
|
+
target: {
|
|
1034
|
+
type: "object",
|
|
1035
|
+
description: "The exact target returned by computer_targets."
|
|
1036
|
+
},
|
|
1037
|
+
durationMinutes: {
|
|
1038
|
+
type: "integer",
|
|
1039
|
+
enum: [
|
|
1040
|
+
5,
|
|
1041
|
+
15,
|
|
1042
|
+
30
|
|
1043
|
+
]
|
|
1044
|
+
},
|
|
1045
|
+
reason: {
|
|
1046
|
+
type: "string",
|
|
1047
|
+
minLength: 1,
|
|
1048
|
+
maxLength: 400
|
|
1049
|
+
},
|
|
1050
|
+
keepTrace: { type: "boolean" }
|
|
1051
|
+
},
|
|
1052
|
+
required: [
|
|
1053
|
+
"target",
|
|
1054
|
+
"durationMinutes",
|
|
1055
|
+
"reason"
|
|
1056
|
+
],
|
|
1057
|
+
additionalProperties: false
|
|
1058
|
+
},
|
|
1059
|
+
mainAgentOnly: true,
|
|
1060
|
+
approval: requestPolicy,
|
|
1061
|
+
async execute(_id, parameters, signal, _update, execution) {
|
|
1062
|
+
if (execution?.sessionId !== host.context.sessionId) throw new Error("Computer use belongs to another session.");
|
|
1063
|
+
return output(await requestOperations.activate(parameters, execution.approvedCall?.approvalId, signal ?? lifetime.signal));
|
|
1064
|
+
}
|
|
1065
|
+
},
|
|
814
1066
|
{
|
|
815
1067
|
when: {
|
|
816
|
-
state: {
|
|
1068
|
+
state: { mode: COMPUTER_USE_MODE_ID },
|
|
817
1069
|
attribution: {
|
|
818
|
-
kind: "
|
|
819
|
-
|
|
1070
|
+
kind: "mode",
|
|
1071
|
+
name: COMPUTER_USE_MODE_ID
|
|
820
1072
|
}
|
|
821
1073
|
},
|
|
822
1074
|
name: "computer_state",
|
|
823
1075
|
label: "Computer State",
|
|
824
|
-
description: "Observe the authorized application window and return semantic accessibility state.",
|
|
1076
|
+
description: "Observe the authorized application window or whole desktop and return semantic accessibility state. root narrows to one subtree (an element ref, or dock, menubar or a window root on the desktop); label and role filter; offset and limit page through matches (pass nextOffset back). saveScreenshot:true also keeps the screenshot in session artifacts and returns its path.",
|
|
825
1077
|
parameters: {
|
|
826
1078
|
type: "object",
|
|
827
|
-
properties: {
|
|
1079
|
+
properties: {
|
|
1080
|
+
includeScreenshot: { type: "boolean" },
|
|
1081
|
+
saveScreenshot: { type: "boolean" },
|
|
1082
|
+
root: {
|
|
1083
|
+
type: "string",
|
|
1084
|
+
minLength: 1,
|
|
1085
|
+
maxLength: 256
|
|
1086
|
+
},
|
|
1087
|
+
label: {
|
|
1088
|
+
type: "string",
|
|
1089
|
+
minLength: 1,
|
|
1090
|
+
maxLength: 256
|
|
1091
|
+
},
|
|
1092
|
+
role: {
|
|
1093
|
+
type: "string",
|
|
1094
|
+
minLength: 1,
|
|
1095
|
+
maxLength: 256
|
|
1096
|
+
},
|
|
1097
|
+
skeleton: { type: "boolean" },
|
|
1098
|
+
offset: {
|
|
1099
|
+
type: "integer",
|
|
1100
|
+
minimum: 0,
|
|
1101
|
+
maximum: 2e3
|
|
1102
|
+
},
|
|
1103
|
+
limit: {
|
|
1104
|
+
type: "integer",
|
|
1105
|
+
minimum: 1,
|
|
1106
|
+
maximum: 500
|
|
1107
|
+
}
|
|
1108
|
+
},
|
|
828
1109
|
additionalProperties: false
|
|
829
1110
|
},
|
|
830
1111
|
executionMode: "serial",
|
|
831
|
-
|
|
832
|
-
try {
|
|
833
|
-
return computerObservationOutput(await requireActive().observe(signal, { includeScreenshot: _parameters.includeScreenshot !== false }));
|
|
834
|
-
} catch (error) {
|
|
835
|
-
return output(error instanceof Error ? error.message : String(error), true);
|
|
836
|
-
}
|
|
837
|
-
}
|
|
1112
|
+
execute: (_toolCallId, parameters, signal) => handlers.state(parameters, signal)
|
|
838
1113
|
},
|
|
839
1114
|
{
|
|
840
1115
|
when: {
|
|
841
|
-
state: {
|
|
1116
|
+
state: { mode: COMPUTER_USE_MODE_ID },
|
|
842
1117
|
attribution: {
|
|
843
|
-
kind: "
|
|
844
|
-
|
|
1118
|
+
kind: "mode",
|
|
1119
|
+
name: COMPUTER_USE_MODE_ID
|
|
845
1120
|
}
|
|
846
1121
|
},
|
|
847
1122
|
name: "computer_action",
|
|
848
1123
|
label: "Computer Action",
|
|
849
|
-
description: "Perform one constrained semantic action in the authorized application window.",
|
|
1124
|
+
description: "Perform one constrained semantic action in the authorized application window or desktop. set_value accepts {{ env.NAME }} and {{ secrets.NAME }} references resolved privately. Secrets require an approved single-window app and seal observations. perform runs one of the element nativeActions. launch opens an installed app by bundle id or name on a whole-desktop grant and needs only app.",
|
|
850
1125
|
parameters: {
|
|
851
1126
|
type: "object",
|
|
852
1127
|
properties: {
|
|
@@ -856,9 +1131,20 @@ function createComputerUseServer(host, apiContext) {
|
|
|
856
1131
|
"press",
|
|
857
1132
|
"focus",
|
|
858
1133
|
"set_value",
|
|
859
|
-
"scroll"
|
|
1134
|
+
"scroll",
|
|
1135
|
+
"perform",
|
|
1136
|
+
"launch",
|
|
1137
|
+
"expand",
|
|
1138
|
+
"collapse",
|
|
1139
|
+
"toggle",
|
|
1140
|
+
"check",
|
|
1141
|
+
"uncheck",
|
|
1142
|
+
"select",
|
|
1143
|
+
"scroll_to",
|
|
1144
|
+
"type"
|
|
860
1145
|
]
|
|
861
1146
|
},
|
|
1147
|
+
text: { type: "string" },
|
|
862
1148
|
snapshotId: {
|
|
863
1149
|
type: "string",
|
|
864
1150
|
minLength: 1
|
|
@@ -877,35 +1163,36 @@ function createComputerUseServer(host, apiContext) {
|
|
|
877
1163
|
"right"
|
|
878
1164
|
]
|
|
879
1165
|
},
|
|
880
|
-
amount: {
|
|
1166
|
+
amount: { anyOf: [{
|
|
881
1167
|
type: "string",
|
|
882
1168
|
enum: ["line", "page"]
|
|
1169
|
+
}, {
|
|
1170
|
+
type: "integer",
|
|
1171
|
+
minimum: 1,
|
|
1172
|
+
maximum: 100
|
|
1173
|
+
}] },
|
|
1174
|
+
action: {
|
|
1175
|
+
type: "string",
|
|
1176
|
+
pattern: "^AX[A-Za-z]{1,62}$"
|
|
1177
|
+
},
|
|
1178
|
+
app: {
|
|
1179
|
+
type: "string",
|
|
1180
|
+
minLength: 1,
|
|
1181
|
+
maxLength: 256
|
|
883
1182
|
}
|
|
884
1183
|
},
|
|
885
|
-
required: [
|
|
886
|
-
"kind",
|
|
887
|
-
"snapshotId",
|
|
888
|
-
"elementRef"
|
|
889
|
-
],
|
|
1184
|
+
required: ["kind"],
|
|
890
1185
|
additionalProperties: false
|
|
891
1186
|
},
|
|
892
1187
|
executionMode: "serial",
|
|
893
|
-
|
|
894
|
-
try {
|
|
895
|
-
const result = await requireActive().act(parameters, signal);
|
|
896
|
-
await refresh(signal);
|
|
897
|
-
return output(result);
|
|
898
|
-
} catch (error) {
|
|
899
|
-
return output(error instanceof Error ? error.message : String(error), true);
|
|
900
|
-
}
|
|
901
|
-
}
|
|
1188
|
+
execute: (_toolCallId, parameters, signal) => handlers.act(parameters, signal)
|
|
902
1189
|
},
|
|
903
1190
|
{
|
|
904
1191
|
when: {
|
|
905
|
-
state: {
|
|
1192
|
+
state: { mode: COMPUTER_USE_MODE_ID },
|
|
906
1193
|
attribution: {
|
|
907
|
-
kind: "
|
|
908
|
-
|
|
1194
|
+
kind: "mode",
|
|
1195
|
+
name: COMPUTER_USE_MODE_ID
|
|
909
1196
|
}
|
|
910
1197
|
},
|
|
911
1198
|
name: "computer_exec",
|
|
@@ -926,16 +1213,7 @@ function createComputerUseServer(host, apiContext) {
|
|
|
926
1213
|
additionalProperties: false
|
|
927
1214
|
},
|
|
928
1215
|
executionMode: "serial",
|
|
929
|
-
|
|
930
|
-
try {
|
|
931
|
-
requireActive();
|
|
932
|
-
if (!dependencies.scriptRunner) throw new Error("Computer script execution is unavailable.");
|
|
933
|
-
const input = parameters;
|
|
934
|
-
return computerScriptOutput(await dependencies.scriptRunner.execute(input.scriptPath, input.input, signal, input));
|
|
935
|
-
} catch (error) {
|
|
936
|
-
return computerScriptFailure(error);
|
|
937
|
-
}
|
|
938
|
-
}
|
|
1216
|
+
execute: (_toolCallId, parameters, signal) => handlers.run(parameters, signal)
|
|
939
1217
|
}
|
|
940
1218
|
],
|
|
941
1219
|
commands: [{
|
|
@@ -951,8 +1229,8 @@ function createComputerUseServer(host, apiContext) {
|
|
|
951
1229
|
await client.stop();
|
|
952
1230
|
await host.changeSelection({
|
|
953
1231
|
axis: "state",
|
|
954
|
-
key: "
|
|
955
|
-
values: (execution.selection.state?.["
|
|
1232
|
+
key: "mode",
|
|
1233
|
+
values: (execution.selection.state?.["mode"] ?? []).filter((mode) => mode !== COMPUTER_USE_MODE_ID)
|
|
956
1234
|
});
|
|
957
1235
|
await refresh();
|
|
958
1236
|
}
|
|
@@ -960,23 +1238,23 @@ function createComputerUseServer(host, apiContext) {
|
|
|
960
1238
|
}],
|
|
961
1239
|
hooks: [{
|
|
962
1240
|
when: {
|
|
963
|
-
state: {
|
|
1241
|
+
state: { mode: COMPUTER_USE_MODE_ID },
|
|
964
1242
|
attribution: {
|
|
965
|
-
kind: "
|
|
966
|
-
|
|
1243
|
+
kind: "mode",
|
|
1244
|
+
name: COMPUTER_USE_MODE_ID
|
|
967
1245
|
}
|
|
968
1246
|
},
|
|
969
1247
|
event: "before_agent_start",
|
|
970
1248
|
handle(event) {
|
|
971
|
-
if (
|
|
972
|
-
return { systemPrompt: `${typeof event.systemPrompt === "string" ? event.systemPrompt : ""}\n\n${GUIDANCE}`.trim() };
|
|
1249
|
+
if (!canRequest()) return void 0;
|
|
1250
|
+
return { systemPrompt: `${typeof event.systemPrompt === "string" ? event.systemPrompt : ""}\n\n${isActive() ? codemodeLive ? COMPUTER_USE_CODEMODE_GUIDANCE : GUIDANCE : `Computer use mode is on. If the task requires it, use ${codemodeLive ? "computer.targets() then computer.request() in exec" : "computer_targets then computer_request"} to ask for the narrowest grant. Wait for the approval outcome before acting.`}`.trim() };
|
|
973
1251
|
}
|
|
974
1252
|
}, {
|
|
975
1253
|
when: {
|
|
976
|
-
state: {
|
|
1254
|
+
state: { mode: COMPUTER_USE_MODE_ID },
|
|
977
1255
|
attribution: {
|
|
978
|
-
kind: "
|
|
979
|
-
|
|
1256
|
+
kind: "mode",
|
|
1257
|
+
name: COMPUTER_USE_MODE_ID
|
|
980
1258
|
}
|
|
981
1259
|
},
|
|
982
1260
|
event: "session_shutdown",
|
|
@@ -995,7 +1273,8 @@ function createComputerUseServer(host, apiContext) {
|
|
|
995
1273
|
() => unsubscribeState?.(),
|
|
996
1274
|
() => broker.close(),
|
|
997
1275
|
() => restrictionListeners.clear(),
|
|
998
|
-
() => host.context.client.setStatus(COMPUTER_USE_STATUS_KEY, void 0)
|
|
1276
|
+
() => host.context.client.setStatus(COMPUTER_USE_STATUS_KEY, void 0),
|
|
1277
|
+
() => lifetime.abort()
|
|
999
1278
|
], "Computer-use cleanup failed.");
|
|
1000
1279
|
}
|
|
1001
1280
|
};
|
|
@@ -1019,6 +1298,43 @@ var root_server_default = defineRoot((context) => {
|
|
|
1019
1298
|
};
|
|
1020
1299
|
});
|
|
1021
1300
|
//#endregion
|
|
1301
|
+
//#region src/services/desktopPermissionsApi/index.ts
|
|
1302
|
+
/**
|
|
1303
|
+
* Desktop's macOS permissions for the settings page.
|
|
1304
|
+
*
|
|
1305
|
+
* Hub-scoped because the permissions belong to the Mac, not a session. The server's
|
|
1306
|
+
* Desktop link reads and requests them; without Desktop the mount answers 404, so
|
|
1307
|
+
* the page can say so instead of guessing.
|
|
1308
|
+
*/
|
|
1309
|
+
async function desktopPermissionsResponse(access, request) {
|
|
1310
|
+
const path = new URL(request.url).pathname;
|
|
1311
|
+
const change = request.method === routes.requestDesktopPermission.method;
|
|
1312
|
+
if (path !== routes.desktopPermissions.path || !change && request.method !== routes.desktopPermissions.method) return Response.json({ error: "Not found." }, { status: 404 });
|
|
1313
|
+
if (access === void 0) return Response.json({ error: "Po Desktop is not running this server." }, { status: 404 });
|
|
1314
|
+
if (!access.authorize(request.headers, change)) return Response.json({ error: "Open Po Desktop on that Mac, or confirm with your passkey." }, { status: 403 });
|
|
1315
|
+
let permission;
|
|
1316
|
+
if (change) {
|
|
1317
|
+
const body = await request.json().catch(() => void 0);
|
|
1318
|
+
if (!isDesktopPermission(body?.permission)) return Response.json({ error: "Name one permission to ask for." }, { status: 400 });
|
|
1319
|
+
permission = body.permission;
|
|
1320
|
+
}
|
|
1321
|
+
try {
|
|
1322
|
+
return Response.json(await access.request(permission));
|
|
1323
|
+
} catch (error) {
|
|
1324
|
+
return Response.json({ error: error instanceof Error ? error.message : String(error) }, { status: 502 });
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
//#endregion
|
|
1328
|
+
//#region src/extensions/(backend)/api/desktop-permissions/route.server.ts
|
|
1329
|
+
/** Mounts Desktop's macOS permissions at `desktop-permissions`, which the folder names. */
|
|
1330
|
+
var route_server_default$1 = defineRoute({
|
|
1331
|
+
basePath: "desktop-permissions",
|
|
1332
|
+
start: (context) => ({
|
|
1333
|
+
fetch: (request) => desktopPermissionsResponse(context.desktopPermissions, request),
|
|
1334
|
+
close: () => void 0
|
|
1335
|
+
})
|
|
1336
|
+
});
|
|
1337
|
+
//#endregion
|
|
1022
1338
|
//#region src/services/webComputerUseAvailability/index.ts
|
|
1023
1339
|
var MissingComputerUseApiError = class extends Error {};
|
|
1024
1340
|
function computerUseSessionApiError(status, value) {
|
|
@@ -1030,12 +1346,14 @@ function computerUseSessionApiError(status, value) {
|
|
|
1030
1346
|
//#region src/services/webComputerUseChannel/index.ts
|
|
1031
1347
|
/** Computer use runs on the Po Desktop host, so every other client declines it. */
|
|
1032
1348
|
const DESKTOP_UNAVAILABLE = "Po Desktop computer use is unavailable.";
|
|
1349
|
+
const SESSION_READY_ATTEMPTS = 5;
|
|
1350
|
+
const SESSION_READY_RETRY_MS = 200;
|
|
1033
1351
|
function record(value) {
|
|
1034
1352
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1035
1353
|
}
|
|
1036
1354
|
function command(value) {
|
|
1037
1355
|
const input = record(value);
|
|
1038
|
-
return input?.action === "status" || input?.action === "
|
|
1356
|
+
return input?.action === "status" || input?.action === "stop" ? { action: input.action } : void 0;
|
|
1039
1357
|
}
|
|
1040
1358
|
async function responseJson(response) {
|
|
1041
1359
|
const value = await response.json();
|
|
@@ -1062,7 +1380,6 @@ function createComputerUseChannel() {
|
|
|
1062
1380
|
start(host) {
|
|
1063
1381
|
const scopes = /* @__PURE__ */ new Map();
|
|
1064
1382
|
const latest = /* @__PURE__ */ new Map();
|
|
1065
|
-
const targets = /* @__PURE__ */ new Map();
|
|
1066
1383
|
const grants = /* @__PURE__ */ new Map();
|
|
1067
1384
|
const subscriptions = /* @__PURE__ */ new Map();
|
|
1068
1385
|
const processing = /* @__PURE__ */ new Set();
|
|
@@ -1070,21 +1387,30 @@ function createComputerUseChannel() {
|
|
|
1070
1387
|
const requests = /* @__PURE__ */ new Map();
|
|
1071
1388
|
let activeSessionId;
|
|
1072
1389
|
let closed = false;
|
|
1073
|
-
const sessionRequest = async (scope, path, method = "GET", value) =>
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1390
|
+
const sessionRequest = async (scope, path, method = "GET", value) => {
|
|
1391
|
+
const registeredScope = scopes.get(scope.sessionId);
|
|
1392
|
+
for (let attempt = 1;; attempt++) {
|
|
1393
|
+
if (closed || registeredScope === void 0 || scopes.get(scope.sessionId) !== registeredScope) throw new Error("Computer-use session is closed.");
|
|
1394
|
+
const response = await host.requestSessionApi(scope, {
|
|
1395
|
+
basePath: API_BASE_PATH,
|
|
1396
|
+
path,
|
|
1397
|
+
method,
|
|
1398
|
+
...value === void 0 ? {} : { body: JSON.stringify(value) }
|
|
1399
|
+
});
|
|
1400
|
+
if (response.status !== 503 || attempt >= SESSION_READY_ATTEMPTS) return response;
|
|
1401
|
+
if (record(await response.clone().json().catch(() => void 0))?.error !== "Session selection is not ready.") return response;
|
|
1402
|
+
await new Promise((resolve) => setTimeout(resolve, SESSION_READY_RETRY_MS));
|
|
1403
|
+
}
|
|
1404
|
+
};
|
|
1079
1405
|
const publish = (scope, state) => {
|
|
1080
|
-
if (state.phase === "active" || state.phase === "activating" || state.phase === "stopping") activeSessionId
|
|
1406
|
+
if (state.phase === "active" || state.phase === "activating" || state.phase === "stopping") activeSessionId ??= scope.sessionId;
|
|
1081
1407
|
else if (activeSessionId === scope.sessionId) {
|
|
1082
1408
|
activeSessionId = void 0;
|
|
1083
1409
|
grants.delete(scope.sessionId);
|
|
1084
1410
|
}
|
|
1085
1411
|
const payload = {
|
|
1086
1412
|
state,
|
|
1087
|
-
targets:
|
|
1413
|
+
targets: [],
|
|
1088
1414
|
...activeSessionId !== void 0 && activeSessionId !== scope.sessionId ? { busy: true } : {}
|
|
1089
1415
|
};
|
|
1090
1416
|
latest.set(scope.sessionId, payload);
|
|
@@ -1109,6 +1435,7 @@ function createComputerUseChannel() {
|
|
|
1109
1435
|
sequence: pending.sequence,
|
|
1110
1436
|
action: pending.payload
|
|
1111
1437
|
} : {
|
|
1438
|
+
...record(pending.payload),
|
|
1112
1439
|
grantId: pending.grantId,
|
|
1113
1440
|
includeScreenshot: record(pending.payload)?.includeScreenshot !== false
|
|
1114
1441
|
}
|
|
@@ -1120,7 +1447,8 @@ function createComputerUseChannel() {
|
|
|
1120
1447
|
} catch (error) {
|
|
1121
1448
|
await responseJson(await sessionRequest(scope, COMPUTER_USE_ROUTES.hubComplete, "POST", {
|
|
1122
1449
|
id: pending.id,
|
|
1123
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1450
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1451
|
+
...error instanceof PoComputerUseHostError ? { code: error.code } : {}
|
|
1124
1452
|
}));
|
|
1125
1453
|
} finally {
|
|
1126
1454
|
if (requests.get(scope.sessionId) === controller) requests.delete(scope.sessionId);
|
|
@@ -1178,10 +1506,11 @@ function createComputerUseChannel() {
|
|
|
1178
1506
|
return;
|
|
1179
1507
|
}
|
|
1180
1508
|
}
|
|
1181
|
-
if (state.phase === "awaiting_confirmation"
|
|
1509
|
+
if (state.phase === "awaiting_confirmation") {
|
|
1510
|
+
const busy = activeSessionId !== void 0 && activeSessionId !== scope.sessionId;
|
|
1182
1511
|
const activation = await responseJson(await sessionRequest(scope, COMPUTER_USE_ROUTES.hubActivation));
|
|
1183
|
-
if (activation !== null && !host.computerUse?.available) {
|
|
1184
|
-
await responseJson(await sessionRequest(scope, COMPUTER_USE_ROUTES.hubStop, "POST", { error: DESKTOP_UNAVAILABLE }));
|
|
1512
|
+
if (activation !== null && (busy || !host.computerUse?.available)) {
|
|
1513
|
+
await responseJson(await sessionRequest(scope, COMPUTER_USE_ROUTES.hubStop, "POST", { error: busy ? "Computer use is active in another session." : DESKTOP_UNAVAILABLE }));
|
|
1185
1514
|
await refresh(scope);
|
|
1186
1515
|
return;
|
|
1187
1516
|
}
|
|
@@ -1230,7 +1559,7 @@ function createComputerUseChannel() {
|
|
|
1230
1559
|
const onState = (scope, payload) => {
|
|
1231
1560
|
const state = sessionState(payload);
|
|
1232
1561
|
if (state === void 0 || state.sessionId !== scope.sessionId) return;
|
|
1233
|
-
if (state.phase === "stopping" || state.phase === "failed" || state.phase === "inactive") requests.get(scope.sessionId)?.abort();
|
|
1562
|
+
if (state.phase === "stopping" && grants.has(scope.sessionId) || state.phase === "failed" || state.phase === "inactive") requests.get(scope.sessionId)?.abort();
|
|
1234
1563
|
publish(scope, state);
|
|
1235
1564
|
processScope(scope, state);
|
|
1236
1565
|
};
|
|
@@ -1239,10 +1568,11 @@ function createComputerUseChannel() {
|
|
|
1239
1568
|
if (parsed === void 0) return;
|
|
1240
1569
|
(async () => {
|
|
1241
1570
|
try {
|
|
1242
|
-
if (parsed.action === "
|
|
1243
|
-
const
|
|
1244
|
-
|
|
1245
|
-
|
|
1571
|
+
if (parsed.action === "stop") {
|
|
1572
|
+
const stopped = await responseJson(await sessionRequest(scope, COMPUTER_USE_ROUTES.hubRequestStop, "POST"));
|
|
1573
|
+
await processScope(scope, stopped);
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1246
1576
|
await refresh(scope);
|
|
1247
1577
|
processScope(scope);
|
|
1248
1578
|
} catch (error) {
|
|
@@ -1273,7 +1603,6 @@ function createComputerUseChannel() {
|
|
|
1273
1603
|
}).catch((error) => host.onNotice(`computer-use session cleanup failed (${error instanceof Error ? error.message : String(error)})`));
|
|
1274
1604
|
scopes.delete(sessionId);
|
|
1275
1605
|
latest.delete(sessionId);
|
|
1276
|
-
targets.delete(sessionId);
|
|
1277
1606
|
grants.delete(sessionId);
|
|
1278
1607
|
processing.delete(sessionId);
|
|
1279
1608
|
if (activeSessionId === sessionId) activeSessionId = void 0;
|
|
@@ -1290,11 +1619,10 @@ function createComputerUseChannel() {
|
|
|
1290
1619
|
if (scope !== void 0) host.computerUse.request(scope, {
|
|
1291
1620
|
operation: "stop",
|
|
1292
1621
|
payload: { grantId }
|
|
1293
|
-
}).catch(() =>
|
|
1622
|
+
}).catch((error) => host.onNotice(`computer-use Desktop stop failed during shutdown (${String(error)})`));
|
|
1294
1623
|
}
|
|
1295
1624
|
scopes.clear();
|
|
1296
1625
|
latest.clear();
|
|
1297
|
-
targets.clear();
|
|
1298
1626
|
grants.clear();
|
|
1299
1627
|
}
|
|
1300
1628
|
};
|
|
@@ -1316,10 +1644,43 @@ var route_server_default = defineRoutedContribution((context) => context.root.ap
|
|
|
1316
1644
|
var computer_use_server_default$1 = defineRoutedContribution((context) => context.root.commands.find((command) => command.name === "computer-use"), { cardinality: "optional" });
|
|
1317
1645
|
//#endregion
|
|
1318
1646
|
//#region src/extensions/workspaces/sessions/(backend)/hook/before-agent-start.server.ts
|
|
1319
|
-
var before_agent_start_server_default = defineRoutedContribution((context) =>
|
|
1647
|
+
var before_agent_start_server_default = defineRoutedContribution(defineHook((context) => {
|
|
1648
|
+
const hook = context.root.hooks?.find((hook) => hook.event === "before_agent_start");
|
|
1649
|
+
if (hook === void 0) return void 0;
|
|
1650
|
+
return {
|
|
1651
|
+
...hook,
|
|
1652
|
+
name: "inject-computer-use-guidance",
|
|
1653
|
+
description: "In computer-use mode with an available enabled desktop and approval capability, append active-control or narrow-grant request guidance."
|
|
1654
|
+
};
|
|
1655
|
+
}), { cardinality: "optional" });
|
|
1320
1656
|
//#endregion
|
|
1321
1657
|
//#region src/extensions/workspaces/sessions/(backend)/hook/session-shutdown.server.ts
|
|
1322
|
-
var session_shutdown_server_default = defineRoutedContribution((context) =>
|
|
1658
|
+
var session_shutdown_server_default = defineRoutedContribution(defineHook((context) => {
|
|
1659
|
+
const hook = context.root.hooks?.find((hook) => hook.event === "session_shutdown");
|
|
1660
|
+
if (hook === void 0) return void 0;
|
|
1661
|
+
return {
|
|
1662
|
+
...hook,
|
|
1663
|
+
name: "stop-computer-use-session",
|
|
1664
|
+
description: "In computer-use mode, stop the session activity and stop the desktop client unless it is inactive or failed."
|
|
1665
|
+
};
|
|
1666
|
+
}), { cardinality: "optional" });
|
|
1667
|
+
//#endregion
|
|
1668
|
+
//#region src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-computer-use.server.ts
|
|
1669
|
+
var codemode_how_to_computer_use_server_default = defineResource({
|
|
1670
|
+
name: "codemode-how-to-computer-use",
|
|
1671
|
+
description: "Observe and act on the application window, or the whole desktop, the person authorized through Po Desktop, using the computer namespace in exec. Use when Computer Use is on and the task needs the screen state, a semantic press, focus, set_value, scroll or native action, or an app launch.",
|
|
1672
|
+
kind: "skill",
|
|
1673
|
+
pinned: true,
|
|
1674
|
+
when: {
|
|
1675
|
+
state: { mode: COMPUTER_USE_MODE_ID },
|
|
1676
|
+
attribution: {
|
|
1677
|
+
kind: "mode",
|
|
1678
|
+
name: COMPUTER_USE_MODE_ID
|
|
1679
|
+
}
|
|
1680
|
+
},
|
|
1681
|
+
path: packageResourcePath(import.meta.url, "src/prompts/codemode-how-to-computer-use/SKILL.md"),
|
|
1682
|
+
read: () => readPackageResource(import.meta.url, "src/prompts/codemode-how-to-computer-use/SKILL.md")
|
|
1683
|
+
});
|
|
1323
1684
|
//#endregion
|
|
1324
1685
|
//#region src/extensions/workspaces/sessions/(backend)/tool-restriction/computer-use.server.ts
|
|
1325
1686
|
var computer_use_server_default = defineRoutedContribution((context) => context.root.toolRestrictions?.[0], { cardinality: "optional" });
|
|
@@ -1333,24 +1694,48 @@ var _10_computer_action_server_default = defineRoutedContribution((context) => c
|
|
|
1333
1694
|
//#region src/extensions/workspaces/sessions/(backend)/tool/20-computer-exec.server.ts
|
|
1334
1695
|
var _20_computer_exec_server_default = defineRoutedContribution((context) => context.root.tools.find((tool) => tool.name === "computer_exec"), { cardinality: "optional" });
|
|
1335
1696
|
//#endregion
|
|
1697
|
+
//#region src/extensions/workspaces/sessions/(backend)/tool/30-computer-targets.server.ts
|
|
1698
|
+
var _30_computer_targets_server_default = defineRoutedContribution((context) => context.root.tools.find((tool) => tool.name === "computer_targets"), { cardinality: "optional" });
|
|
1699
|
+
//#endregion
|
|
1700
|
+
//#region src/extensions/workspaces/sessions/(backend)/tool/40-computer-request.server.ts
|
|
1701
|
+
var _40_computer_request_server_default = defineRoutedContribution((context) => context.root.tools.find((tool) => tool.name === "computer_request"), { cardinality: "optional" });
|
|
1702
|
+
//#endregion
|
|
1336
1703
|
//#region generated/server.ts
|
|
1337
1704
|
const at = (value, context) => typeof value === "function" ? value(context) : value;
|
|
1338
1705
|
/* v8 ignore next -- generated normalization branch */
|
|
1339
1706
|
const defined = (values) => values.filter((value) => value !== void 0);
|
|
1340
|
-
const via = (identity, value) =>
|
|
1341
|
-
|
|
1342
|
-
|
|
1707
|
+
const via = (identity, value) => {
|
|
1708
|
+
if (value === void 0) return void 0;
|
|
1709
|
+
const declaration = value;
|
|
1710
|
+
return {
|
|
1711
|
+
...identity,
|
|
1712
|
+
...declaration,
|
|
1713
|
+
...declaration.relations === void 0 ? {} : { relations: declaration.relations.map((relation) => ({
|
|
1714
|
+
evidence: "declared",
|
|
1715
|
+
...relation
|
|
1716
|
+
})) }
|
|
1717
|
+
};
|
|
1343
1718
|
};
|
|
1344
1719
|
const serverPlugin = defineServerPlugin({
|
|
1345
1720
|
name: "@agimon-ai/po-computer-use",
|
|
1346
1721
|
providerOverrides: composeServerProviderOverrides(root_server_default),
|
|
1347
1722
|
injects: composeRootInjects({ session: [root_server_default] }),
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1723
|
+
host: (context) => ({
|
|
1724
|
+
get api() {
|
|
1725
|
+
return [at(route_server_default$1, context)];
|
|
1726
|
+
},
|
|
1727
|
+
get channels() {
|
|
1728
|
+
return [() => via({ frameType: "computer_use" }, at(computer_use_server_default$2, context))];
|
|
1729
|
+
}
|
|
1730
|
+
}),
|
|
1731
|
+
workspace: (context) => ({
|
|
1732
|
+
get api() {
|
|
1733
|
+
return [at(route_server_default$1, context)];
|
|
1734
|
+
},
|
|
1735
|
+
get channels() {
|
|
1736
|
+
return defined([context.hosted("host") ? void 0 : () => via({ frameType: "computer_use" }, at(computer_use_server_default$2, context))]);
|
|
1737
|
+
}
|
|
1738
|
+
}),
|
|
1354
1739
|
session: async (context) => {
|
|
1355
1740
|
const scopeSession = await context.scopeRoot("session", root_server_default, context);
|
|
1356
1741
|
const contextSession = {
|
|
@@ -1360,10 +1745,10 @@ const serverPlugin = defineServerPlugin({
|
|
|
1360
1745
|
return {
|
|
1361
1746
|
...composeRootHooks(scopeSession),
|
|
1362
1747
|
get api() {
|
|
1363
|
-
return defined([at(route_server_default, contextSession)]);
|
|
1748
|
+
return defined([at(route_server_default$1, context), at(route_server_default, contextSession)]);
|
|
1364
1749
|
},
|
|
1365
1750
|
get channels() {
|
|
1366
|
-
return defined([context.hosted("
|
|
1751
|
+
return defined([context.hosted("host") ? void 0 : () => via({ frameType: "computer_use" }, at(computer_use_server_default$2, context))]);
|
|
1367
1752
|
},
|
|
1368
1753
|
get commands() {
|
|
1369
1754
|
return defined([via({ name: "computer-use" }, at(computer_use_server_default$1, contextSession))]);
|
|
@@ -1371,6 +1756,9 @@ const serverPlugin = defineServerPlugin({
|
|
|
1371
1756
|
get hooks() {
|
|
1372
1757
|
return defined([via({ event: "before_agent_start" }, at(before_agent_start_server_default, contextSession)), via({ event: "session_shutdown" }, at(session_shutdown_server_default, contextSession))]);
|
|
1373
1758
|
},
|
|
1759
|
+
get resources() {
|
|
1760
|
+
return [at(codemode_how_to_computer_use_server_default, contextSession)];
|
|
1761
|
+
},
|
|
1374
1762
|
get toolRestrictions() {
|
|
1375
1763
|
return defined([at(computer_use_server_default, contextSession)]);
|
|
1376
1764
|
},
|
|
@@ -1378,7 +1766,9 @@ const serverPlugin = defineServerPlugin({
|
|
|
1378
1766
|
return defined([
|
|
1379
1767
|
via({ name: "00_computer_state" }, at(_00_computer_state_server_default, contextSession)),
|
|
1380
1768
|
via({ name: "10_computer_action" }, at(_10_computer_action_server_default, contextSession)),
|
|
1381
|
-
via({ name: "20_computer_exec" }, at(_20_computer_exec_server_default, contextSession))
|
|
1769
|
+
via({ name: "20_computer_exec" }, at(_20_computer_exec_server_default, contextSession)),
|
|
1770
|
+
via({ name: "30_computer_targets" }, at(_30_computer_targets_server_default, contextSession)),
|
|
1771
|
+
via({ name: "40_computer_request" }, at(_40_computer_request_server_default, contextSession))
|
|
1382
1772
|
]);
|
|
1383
1773
|
},
|
|
1384
1774
|
services: [...scopeSession.services ?? []],
|