@agimon-ai/po-computer-use 0.0.0-alpha.3 → 0.0.0-alpha.30
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 +149 -21
- package/README.md +2 -2
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/extensions/mcp-ui.mjs.map +1 -1
- package/dist/extensions/mcp.cjs +1 -1
- package/dist/extensions/mcp.cjs.map +1 -1
- package/dist/extensions/mcp.d.mts +1 -1
- package/dist/extensions/mcp.mjs +1 -1
- package/dist/extensions/mcp.mjs.map +1 -1
- package/dist/extensions/native.mjs +1 -1
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +120 -31
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts +2 -2
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +120 -31
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +273 -57
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +22 -22
- package/src/types/computerUseApi.ts +4 -4
|
@@ -5,7 +5,7 @@ Object.defineProperties(exports, {
|
|
|
5
5
|
const require_extensionService = require("../extensionService-Bp0q295i.cjs");
|
|
6
6
|
let node_path = require("node:path");
|
|
7
7
|
node_path = require_extensionService.__toESM(node_path, 1);
|
|
8
|
-
let
|
|
8
|
+
let _agimon_ai_po_core_serverPlugin = require("@agimon-ai/po-core/serverPlugin");
|
|
9
9
|
let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile");
|
|
10
10
|
let _agimon_ai_po_minor_mode = require("@agimon-ai/po-minor-mode");
|
|
11
11
|
let node_crypto = require("node:crypto");
|
|
@@ -15,7 +15,7 @@ let _agimon_ai_po_core_web = require("@agimon-ai/po-core/web");
|
|
|
15
15
|
const API_BASE_PATH = "computer-use";
|
|
16
16
|
const computerUseChannelType = "computer_use_state";
|
|
17
17
|
const COMPUTER_USE_MODE_ID = "computer-use";
|
|
18
|
-
const COMPUTER_USE_STATUS_KEY = "
|
|
18
|
+
const COMPUTER_USE_STATUS_KEY = "po-computer-use";
|
|
19
19
|
const COMPUTER_USE_CONFIRMATION_WINDOW_MS = 12e4;
|
|
20
20
|
/**
|
|
21
21
|
* Every path this API answers on, below its mount.
|
|
@@ -41,7 +41,7 @@ const COMPUTER_USE_ROUTES = {
|
|
|
41
41
|
const COMPUTER_USE_WAKE_LIMIT = 1e6;
|
|
42
42
|
//#endregion
|
|
43
43
|
//#region src/services/mcpTools/index.ts
|
|
44
|
-
const COMPUTER_USE_MCP_TOOLS_SERVICE = "
|
|
44
|
+
const COMPUTER_USE_MCP_TOOLS_SERVICE = "po/computer-use-mcp-tools";
|
|
45
45
|
function mountMcpTools(tools) {
|
|
46
46
|
return (context) => {
|
|
47
47
|
context.plugin((providerContext) => {
|
|
@@ -142,6 +142,19 @@ function computerScriptFailure(error) {
|
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
144
|
//#endregion
|
|
145
|
+
//#region src/types/desktopPermissions.ts
|
|
146
|
+
/** The macOS privacy permissions Desktop reports, in the order the settings page shows them. */
|
|
147
|
+
const DESKTOP_PERMISSIONS = [
|
|
148
|
+
"accessibility",
|
|
149
|
+
"screen-recording",
|
|
150
|
+
"microphone",
|
|
151
|
+
"automation",
|
|
152
|
+
"full-disk-access"
|
|
153
|
+
];
|
|
154
|
+
function isDesktopPermission(value) {
|
|
155
|
+
return typeof value === "string" && DESKTOP_PERMISSIONS.includes(value);
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
145
158
|
//#region src/types/apiRoutes.ts
|
|
146
159
|
/**
|
|
147
160
|
* This package's routes, as data.
|
|
@@ -234,6 +247,18 @@ var apiRoutes_default = (0, _agimon_ai_po_core_web.defineApiRoutes)({
|
|
|
234
247
|
method: "POST",
|
|
235
248
|
path: COMPUTER_USE_ROUTES.hubStop,
|
|
236
249
|
response: (0, _agimon_ai_po_core_web.apiResponse)()
|
|
250
|
+
},
|
|
251
|
+
/** Desktop's macOS permission states, served by the hub's `desktop-permissions` mount. */
|
|
252
|
+
desktopPermissions: {
|
|
253
|
+
method: "GET",
|
|
254
|
+
path: "/",
|
|
255
|
+
response: (0, _agimon_ai_po_core_web.apiResponse)()
|
|
256
|
+
},
|
|
257
|
+
/** Asks macOS for the body's permission on the Mac running Desktop; answers the states after. */
|
|
258
|
+
requestDesktopPermission: {
|
|
259
|
+
method: "POST",
|
|
260
|
+
path: "/",
|
|
261
|
+
response: (0, _agimon_ai_po_core_web.apiResponse)()
|
|
237
262
|
}
|
|
238
263
|
});
|
|
239
264
|
//#endregion
|
|
@@ -416,7 +441,7 @@ var ComputerUseRequestBroker = class ComputerUseRequestBroker {
|
|
|
416
441
|
async requestActivation(request) {
|
|
417
442
|
if (!this.desktop?.available || !(this.desktop.authorizeActivation?.(request.headers) ?? this.desktop.authorize(request.headers))) return jsonError("Not found.", 404);
|
|
418
443
|
if (this.desktop.enabled === false) return jsonError("Enable computer use in global Desktop settings first.", 409);
|
|
419
|
-
const stamped = (0, _agimon_ai_po_core_packageApi.
|
|
444
|
+
const stamped = (0, _agimon_ai_po_core_packageApi.poApiCallerFrom)(request.headers);
|
|
420
445
|
const caller = stamped?.locality === "remote" ? stamped : {
|
|
421
446
|
locality: "local",
|
|
422
447
|
stepUp: "not-required"
|
|
@@ -676,7 +701,7 @@ function createComputerUseServer(host, apiContext) {
|
|
|
676
701
|
const publishMode = () => modeOwner?.publish();
|
|
677
702
|
const applyState = (next) => {
|
|
678
703
|
state = next;
|
|
679
|
-
host.context.client.setStatus(COMPUTER_USE_STATUS_KEY, next === void 0 || next.phase === "inactive" ? void 0 : `computer use: ${next.phase}`);
|
|
704
|
+
host.context.client.setStatus(COMPUTER_USE_STATUS_KEY, next === void 0 || next.phase === "inactive" && !modeSelected() && next.artifact === void 0 ? void 0 : `computer use: ${next.phase}`);
|
|
680
705
|
publishMode();
|
|
681
706
|
for (const listener of restrictionListeners) listener();
|
|
682
707
|
};
|
|
@@ -990,13 +1015,18 @@ function createComputerUseServer(host, apiContext) {
|
|
|
990
1015
|
if (client && state?.phase !== "inactive" && state?.phase !== "failed") await client.stop();
|
|
991
1016
|
}
|
|
992
1017
|
}],
|
|
993
|
-
onDispose() {
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1018
|
+
async onDispose() {
|
|
1019
|
+
await (0, _agimon_ai_po_core_extensionFile.runCleanups)([
|
|
1020
|
+
() => {
|
|
1021
|
+
const stop = stopActivity;
|
|
1022
|
+
stopActivity = void 0;
|
|
1023
|
+
stop?.();
|
|
1024
|
+
},
|
|
1025
|
+
() => unsubscribeState?.(),
|
|
1026
|
+
() => broker.close(),
|
|
1027
|
+
() => restrictionListeners.clear(),
|
|
1028
|
+
() => host.context.client.setStatus(COMPUTER_USE_STATUS_KEY, void 0)
|
|
1029
|
+
], "Computer-use cleanup failed.");
|
|
1000
1030
|
}
|
|
1001
1031
|
};
|
|
1002
1032
|
}
|
|
@@ -1019,6 +1049,43 @@ var root_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoot)((cont
|
|
|
1019
1049
|
};
|
|
1020
1050
|
});
|
|
1021
1051
|
//#endregion
|
|
1052
|
+
//#region src/services/desktopPermissionsApi/index.ts
|
|
1053
|
+
/**
|
|
1054
|
+
* Desktop's macOS permissions for the settings page.
|
|
1055
|
+
*
|
|
1056
|
+
* Hub-scoped because the permissions belong to the Mac, not a session. The server's
|
|
1057
|
+
* Desktop link reads and requests them; without Desktop the mount answers 404, so
|
|
1058
|
+
* the page can say so instead of guessing.
|
|
1059
|
+
*/
|
|
1060
|
+
async function desktopPermissionsResponse(access, request) {
|
|
1061
|
+
const path = new URL(request.url).pathname;
|
|
1062
|
+
const change = request.method === apiRoutes_default.requestDesktopPermission.method;
|
|
1063
|
+
if (path !== apiRoutes_default.desktopPermissions.path || !change && request.method !== apiRoutes_default.desktopPermissions.method) return Response.json({ error: "Not found." }, { status: 404 });
|
|
1064
|
+
if (access === void 0) return Response.json({ error: "Po Desktop is not running this server." }, { status: 404 });
|
|
1065
|
+
if (!access.authorize(request.headers, change)) return Response.json({ error: "Open Po Desktop on that Mac, or confirm with your passkey." }, { status: 403 });
|
|
1066
|
+
let permission;
|
|
1067
|
+
if (change) {
|
|
1068
|
+
const body = await request.json().catch(() => void 0);
|
|
1069
|
+
if (!isDesktopPermission(body?.permission)) return Response.json({ error: "Name one permission to ask for." }, { status: 400 });
|
|
1070
|
+
permission = body.permission;
|
|
1071
|
+
}
|
|
1072
|
+
try {
|
|
1073
|
+
return Response.json(await access.request(permission));
|
|
1074
|
+
} catch (error) {
|
|
1075
|
+
return Response.json({ error: error instanceof Error ? error.message : String(error) }, { status: 502 });
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
//#endregion
|
|
1079
|
+
//#region src/extensions/(backend)/api/desktop-permissions/route.server.ts
|
|
1080
|
+
/** Mounts Desktop's macOS permissions at `desktop-permissions`, which the folder names. */
|
|
1081
|
+
var route_server_default$1 = (0, _agimon_ai_po_core_extensionFile.defineRoute)({
|
|
1082
|
+
basePath: "desktop-permissions",
|
|
1083
|
+
start: (context) => ({
|
|
1084
|
+
fetch: (request) => desktopPermissionsResponse(context.desktopPermissions, request),
|
|
1085
|
+
close: () => void 0
|
|
1086
|
+
})
|
|
1087
|
+
});
|
|
1088
|
+
//#endregion
|
|
1022
1089
|
//#region src/services/webComputerUseAvailability/index.ts
|
|
1023
1090
|
var MissingComputerUseApiError = class extends Error {};
|
|
1024
1091
|
function computerUseSessionApiError(status, value) {
|
|
@@ -1030,6 +1097,8 @@ function computerUseSessionApiError(status, value) {
|
|
|
1030
1097
|
//#region src/services/webComputerUseChannel/index.ts
|
|
1031
1098
|
/** Computer use runs on the Po Desktop host, so every other client declines it. */
|
|
1032
1099
|
const DESKTOP_UNAVAILABLE = "Po Desktop computer use is unavailable.";
|
|
1100
|
+
const SESSION_READY_ATTEMPTS = 5;
|
|
1101
|
+
const SESSION_READY_RETRY_MS = 200;
|
|
1033
1102
|
function record(value) {
|
|
1034
1103
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1035
1104
|
}
|
|
@@ -1070,12 +1139,21 @@ function createComputerUseChannel() {
|
|
|
1070
1139
|
const requests = /* @__PURE__ */ new Map();
|
|
1071
1140
|
let activeSessionId;
|
|
1072
1141
|
let closed = false;
|
|
1073
|
-
const sessionRequest = async (scope, path, method = "GET", value) =>
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1142
|
+
const sessionRequest = async (scope, path, method = "GET", value) => {
|
|
1143
|
+
const registeredScope = scopes.get(scope.sessionId);
|
|
1144
|
+
for (let attempt = 1;; attempt++) {
|
|
1145
|
+
if (closed || registeredScope === void 0 || scopes.get(scope.sessionId) !== registeredScope) throw new Error("Computer-use session is closed.");
|
|
1146
|
+
const response = await host.requestSessionApi(scope, {
|
|
1147
|
+
basePath: API_BASE_PATH,
|
|
1148
|
+
path,
|
|
1149
|
+
method,
|
|
1150
|
+
...value === void 0 ? {} : { body: JSON.stringify(value) }
|
|
1151
|
+
});
|
|
1152
|
+
if (response.status !== 503 || attempt >= SESSION_READY_ATTEMPTS) return response;
|
|
1153
|
+
if (record(await response.clone().json().catch(() => void 0))?.error !== "Session selection is not ready.") return response;
|
|
1154
|
+
await new Promise((resolve) => setTimeout(resolve, SESSION_READY_RETRY_MS));
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1079
1157
|
const publish = (scope, state) => {
|
|
1080
1158
|
if (state.phase === "active" || state.phase === "activating" || state.phase === "stopping") activeSessionId = scope.sessionId;
|
|
1081
1159
|
else if (activeSessionId === scope.sessionId) {
|
|
@@ -1341,17 +1419,28 @@ const via = (identity, value) => value === void 0 ? void 0 : {
|
|
|
1341
1419
|
...identity,
|
|
1342
1420
|
...value
|
|
1343
1421
|
};
|
|
1344
|
-
const
|
|
1422
|
+
const serverPlugin = (0, _agimon_ai_po_core_serverPlugin.defineServerPlugin)({
|
|
1345
1423
|
name: "@agimon-ai/po-computer-use",
|
|
1346
|
-
providerOverrides: (0,
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1424
|
+
providerOverrides: (0, _agimon_ai_po_core_serverPlugin.composeServerProviderOverrides)(root_server_default),
|
|
1425
|
+
injects: (0, _agimon_ai_po_core_extensionFile.composeRootInjects)({ session: [root_server_default] }),
|
|
1426
|
+
global: (context) => ({
|
|
1427
|
+
get api() {
|
|
1428
|
+
return [at(route_server_default$1, context)];
|
|
1429
|
+
},
|
|
1430
|
+
get channels() {
|
|
1431
|
+
return [() => via({ frameType: "computer_use" }, at(computer_use_server_default$2, context))];
|
|
1432
|
+
}
|
|
1433
|
+
}),
|
|
1434
|
+
workspace: (context) => ({
|
|
1435
|
+
get api() {
|
|
1436
|
+
return [at(route_server_default$1, context)];
|
|
1437
|
+
},
|
|
1438
|
+
get channels() {
|
|
1439
|
+
return defined([context.hosted("global") ? void 0 : () => via({ frameType: "computer_use" }, at(computer_use_server_default$2, context))]);
|
|
1440
|
+
}
|
|
1441
|
+
}),
|
|
1353
1442
|
session: async (context) => {
|
|
1354
|
-
const scopeSession = await root_server_default
|
|
1443
|
+
const scopeSession = await context.scopeRoot("session", root_server_default, context);
|
|
1355
1444
|
const contextSession = {
|
|
1356
1445
|
...context,
|
|
1357
1446
|
root: scopeSession.value
|
|
@@ -1359,10 +1448,10 @@ const facet = (0, _agimon_ai_po_core_serverFacet.defineServerPlugin)({
|
|
|
1359
1448
|
return {
|
|
1360
1449
|
...(0, _agimon_ai_po_core_extensionFile.composeRootHooks)(scopeSession),
|
|
1361
1450
|
get api() {
|
|
1362
|
-
return defined([at(route_server_default, contextSession)]);
|
|
1451
|
+
return defined([at(route_server_default$1, context), at(route_server_default, contextSession)]);
|
|
1363
1452
|
},
|
|
1364
1453
|
get channels() {
|
|
1365
|
-
return [() => via({ frameType: "computer_use" }, computer_use_server_default$2
|
|
1454
|
+
return defined([context.hosted("global") ? void 0 : () => via({ frameType: "computer_use" }, at(computer_use_server_default$2, context))]);
|
|
1366
1455
|
},
|
|
1367
1456
|
get commands() {
|
|
1368
1457
|
return defined([via({ name: "computer-use" }, at(computer_use_server_default$1, contextSession))]);
|
|
@@ -1388,7 +1477,7 @@ const facet = (0, _agimon_ai_po_core_serverFacet.defineServerPlugin)({
|
|
|
1388
1477
|
}
|
|
1389
1478
|
});
|
|
1390
1479
|
//#endregion
|
|
1391
|
-
exports.default =
|
|
1392
|
-
exports.
|
|
1480
|
+
exports.default = serverPlugin;
|
|
1481
|
+
exports.serverPlugin = serverPlugin;
|
|
1393
1482
|
|
|
1394
1483
|
//# sourceMappingURL=server.cjs.map
|