@agimon-ai/po-computer-use 0.0.0-alpha.21 → 0.0.0-alpha.211

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.
Files changed (49) hide show
  1. package/LICENSE +110 -149
  2. package/README.md +9 -8
  3. package/dist/apiContracts.cjs +65 -45
  4. package/dist/apiContracts.cjs.map +1 -1
  5. package/dist/apiContracts.d.mts +2 -2
  6. package/dist/apiContracts.d.mts.map +1 -1
  7. package/dist/apiContracts.mjs +65 -45
  8. package/dist/apiContracts.mjs.map +1 -1
  9. package/dist/extensionService-BKBTsnkI.cjs +1243 -0
  10. package/dist/extensionService-BKBTsnkI.cjs.map +1 -0
  11. package/dist/extensionService-DqtoB79s.mjs +1077 -0
  12. package/dist/extensionService-DqtoB79s.mjs.map +1 -0
  13. package/dist/extensions/mcp-ui.mjs +12 -9
  14. package/dist/extensions/mcp-ui.mjs.map +1 -1
  15. package/dist/extensions/mcp.cjs +13 -5
  16. package/dist/extensions/mcp.cjs.map +1 -1
  17. package/dist/extensions/mcp.d.mts.map +1 -1
  18. package/dist/extensions/mcp.mjs +13 -5
  19. package/dist/extensions/mcp.mjs.map +1 -1
  20. package/dist/extensions/native.mjs +1493 -8
  21. package/dist/extensions/native.mjs.map +1 -1
  22. package/dist/extensions/server.cjs +1035 -645
  23. package/dist/extensions/server.cjs.map +1 -1
  24. package/dist/extensions/server.d.mts.map +1 -1
  25. package/dist/extensions/server.mjs +1020 -630
  26. package/dist/extensions/server.mjs.map +1 -1
  27. package/dist/extensions/web.mjs +1004 -480
  28. package/dist/extensions/web.mjs.map +1 -1
  29. package/dist/index.cjs +14 -5
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.mts +67 -10
  32. package/dist/index.d.mts.map +1 -1
  33. package/dist/index.mjs +14 -5
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/po-runtime-identity.json +1 -0
  36. package/docs/computer-scripts.md +1 -1
  37. package/docs/remote-computer-use.md +11 -0
  38. package/llms.txt +1 -1
  39. package/locales/vi.json +153 -0
  40. package/locales/zh-CN.json +153 -0
  41. package/package.json +84 -24
  42. package/src/prompts/codemode-how-to-computer-use/SKILL.md +83 -0
  43. package/src/types/computerUse.ts +72 -7
  44. package/src/types/computerUseApi.ts +24 -5
  45. package/dist/extensionService-Bp0q295i.cjs +0 -504
  46. package/dist/extensionService-Bp0q295i.cjs.map +0 -1
  47. package/dist/extensionService-DXvF7esO.mjs +0 -434
  48. package/dist/extensionService-DXvF7esO.mjs.map +0 -1
  49. package/src/prompts/po-use-computer-use/SKILL.md +0 -34
@@ -1,37 +1,123 @@
1
- import { apiResponse, createApiClient, defineActivityGroup, defineApiRoutes, defineChannelFile, defineFill, defineMinorModeFile, defineSessionStore, defineSettingsSection, defineToolRenderer, defineWebPlugin, sessionApiAddress, toolResultTextLines } from "@agimon-ai/po-core/web";
2
- import { Button, MessageItem, MessageItemBody, MessageItemHeader, MessageItemStatus, MessageLines, collapseLines, toolTone } from "@agimon-ai/po-web-components";
3
- import { useStore } from "@tanstack/react-store";
4
- import { useEffect, useState } from "react";
5
- import { sealedTransport } from "@agimon-ai/po-web-security/browser";
1
+ import { createApiClient, defineActivityGroup, defineChannelFile, defineFill, defineModeFile, defineSessionStore, defineSettingsPanel, defineSettingsSection, defineToolRenderer, defineWebPlugin, sessionApiAddress, t, useT } from "@agimon-ai/po-core/web";
2
+ import { Badge, Button, CheckIcon, MessageItem, MessageItemBody, MessageItemHeader, MessageItemStatus, MonitorIcon, SettingsActions, SettingsCard, SettingsRow, SettingsRowDescription, SettingsRowText, SettingsRowTitle, SettingsSection, SettingsSectionDescription, SettingsSectionHeader, SettingsSectionTitle, ShieldIcon, toolTone } from "@agimon-ai/po-web-components";
3
+ import { useCallback, useEffect, useState } from "react";
4
+ import { browserTransport } from "@agimon-ai/po-web-security/browser";
6
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ import { useStore } from "@tanstack/react-store";
7
7
  //#region src/extensions/(frontend)/_lib/computerUseSettings.ts
8
8
  const computerUseSettingsSection = {
9
9
  id: "computer-use",
10
10
  desktopOnly: true,
11
- label: "computer use",
12
- detail: "control whether Po Desktop may expose session-scoped computer control",
11
+ get label() {
12
+ return t("computerUse.ui.computerUse", "computer use");
13
+ },
14
+ get detail() {
15
+ return t("computerUse.ui.controlWhetherPoDesktopMayExposeSession", "control whether Po Desktop may expose session-scoped computer control");
16
+ },
13
17
  order: 45,
14
18
  fields: [{
15
19
  id: "enabled",
16
- label: "enable computer use",
20
+ get label() {
21
+ return t("computerUse.ui.enableComputerUse", "enable computer use");
22
+ },
17
23
  kind: "toggle",
18
24
  keyPath: ["computerUse", "enabled"],
19
- detail: "Makes the computer-use minor mode available. Each control session still requires native confirmation."
25
+ get detail() {
26
+ return t("computerUse.ui.makesTheComputerUseModeAvailableEach", "Makes the computer-use mode available. Each control session still requires native confirmation.");
27
+ }
20
28
  }]
21
29
  };
22
30
  //#endregion
23
31
  //#region src/extensions/(frontend)/setting/computer-use.web.ts
24
- var computer_use_web_default$3 = defineSettingsSection({ settingsSections: [computerUseSettingsSection] }.settingsSections[0]);
32
+ var computer_use_web_default$3 = defineSettingsSection({
33
+ ...{ settingsSections: [computerUseSettingsSection] }.settingsSections[0],
34
+ icon: MonitorIcon
35
+ });
25
36
  //#endregion
26
- //#region src/extensions/workspaces/(frontend)/setting/computer-use.web.ts
27
- var computer_use_web_default$2 = defineSettingsSection({ settingsSections: [computerUseSettingsSection] }.settingsSections[0]);
37
+ //#region src/extensions/(frontend)/setting/desktop-environment.web.ts
38
+ var desktop_environment_web_default = defineSettingsSection({
39
+ ...{
40
+ id: "desktop-environment",
41
+ desktopOnly: true,
42
+ get label() {
43
+ return t("computerUse.ui.desktopEnvironment", "desktop environment");
44
+ },
45
+ get detail() {
46
+ return t("computerUse.ui.chooseWhichLoginShellVariablesPoDesktop", "choose which login-shell variables Po Desktop passes to agents");
47
+ },
48
+ order: 46,
49
+ groups: [{
50
+ id: "shell",
51
+ get label() {
52
+ return t("computerUse.ui.loginShell", "login shell");
53
+ },
54
+ get detail() {
55
+ return t("computerUse.ui.poDesktopReadsYourLoginShellOnce", "Po Desktop reads your login shell once at start. Changes apply the next time Po Desktop starts. Core variables and PO_ settings always pass.");
56
+ }
57
+ }],
58
+ fields: [
59
+ {
60
+ id: "inherit",
61
+ get label() {
62
+ return t("computerUse.ui.variablesToPass", "variables to pass");
63
+ },
64
+ kind: "select",
65
+ keyPath: ["desktopEnvironment", "inherit"],
66
+ group: "shell",
67
+ presentation: "cards",
68
+ defaultValue: "all",
69
+ options: [{
70
+ value: "all",
71
+ get label() {
72
+ return t("computerUse.ui.everything", "everything");
73
+ },
74
+ get detail() {
75
+ return t("computerUse.ui.everyExportedVariableIncludingAPIKeysMinus", "Every exported variable, including API keys, minus exclusions.");
76
+ }
77
+ }, {
78
+ value: "core",
79
+ get label() {
80
+ return t("computerUse.ui.coreOnly", "core only");
81
+ },
82
+ get detail() {
83
+ return t("computerUse.ui.hOMEPATHUSERAndSimilarAddOthers", "HOME, PATH, USER and similar. Add others under desktopEnvironment.set in ~/.po/config.yaml.");
84
+ }
85
+ }]
86
+ },
87
+ {
88
+ id: "exclude",
89
+ get label() {
90
+ return t("computerUse.ui.excluded", "excluded");
91
+ },
92
+ kind: "info",
93
+ keyPath: ["desktopEnvironment", "exclude"],
94
+ group: "shell",
95
+ get detail() {
96
+ return t("computerUse.ui.namePatternsKeptOutSuchAsTOKEN", "Name patterns kept out, such as *_TOKEN. Edit desktopEnvironment.exclude in ~/.po/config.yaml.");
97
+ }
98
+ },
99
+ {
100
+ id: "include-only",
101
+ get label() {
102
+ return t("computerUse.ui.onlyThese", "only these");
103
+ },
104
+ kind: "info",
105
+ keyPath: ["desktopEnvironment", "includeOnly"],
106
+ group: "shell",
107
+ get detail() {
108
+ return t("computerUse.ui.whenSetOnlyMatchingNamesPassEdit", "When set, only matching names pass. Edit desktopEnvironment.includeOnly in ~/.po/config.yaml.");
109
+ }
110
+ }
111
+ ]
112
+ },
113
+ icon: ShieldIcon
114
+ });
28
115
  //#endregion
29
116
  //#region src/types/computerUseApi.ts
30
117
  const computerUseChannelType = "computer_use_state";
31
118
  const COMPUTER_USE_MODE_ID = "computer-use";
32
119
  const COMPUTER_USE_STATUS_KEY = "po-computer-use";
33
120
  const COMPUTER_USE_MODE_STATUS_KEY = "po-computer-use-mode";
34
- const COMPUTER_USE_DEFAULT_DURATION_MS = 3e5;
35
121
  /**
36
122
  * Every path this API answers on, below its mount.
37
123
  *
@@ -40,7 +126,6 @@ const COMPUTER_USE_DEFAULT_DURATION_MS = 3e5;
40
126
  * strings, so a route cannot move on one side alone.
41
127
  */
42
128
  const COMPUTER_USE_ROUTES = {
43
- activate: "/activate",
44
129
  artifact: "/artifact",
45
130
  agentState: "/agent/state",
46
131
  agentObserve: "/agent/observe",
@@ -51,29 +136,19 @@ const COMPUTER_USE_ROUTES = {
51
136
  hubAuthorization: "/hub/authorization",
52
137
  hubNext: "/hub/next",
53
138
  hubComplete: "/hub/complete",
54
- hubStop: "/hub/stop"
139
+ hubStop: "/hub/stop",
140
+ hubRequestStop: "/hub/request-stop"
55
141
  };
56
- const computerUse = defineSessionStore({
57
- state: {
58
- sessionId: "",
59
- revision: 0,
60
- wake: 0,
61
- phase: "inactive"
62
- },
63
- targets: []
64
- });
65
- function isRecord(value) {
66
- return typeof value === "object" && value !== null && !Array.isArray(value);
67
- }
68
- const computerUseChannel = computerUse.channel({
69
- channel: computerUseChannelType,
70
- parse(input) {
71
- if (!isRecord(input) || !isRecord(input.state) || !Array.isArray(input.targets)) return null;
72
- if (typeof input.state.phase !== "string" || typeof input.state.revision !== "number") return null;
73
- return input;
74
- },
75
- reduce: (_current, payload) => payload
76
- });
142
+ //#endregion
143
+ //#region src/types/desktopPermissions.ts
144
+ /** The macOS privacy permissions Desktop reports, in the order the settings page shows them. */
145
+ const DESKTOP_PERMISSIONS = [
146
+ "accessibility",
147
+ "screen-recording",
148
+ "microphone",
149
+ "automation",
150
+ "full-disk-access"
151
+ ];
77
152
  //#endregion
78
153
  //#region src/types/apiRoutes.ts
79
154
  /**
@@ -89,142 +164,360 @@ const computerUseChannel = computerUse.channel({
89
164
  * disagreement this file exists to prevent. The dispatcher now reads this
90
165
  * table, so the page, the broker and the hub all resolve one set of strings.
91
166
  *
92
- * Activation, status, cancellation and recording reads are reachable from a browser. The `/agent/` and `/hub/` routes
167
+ * Recording reads can be reached from a browser with recording authorization. The `/agent/` and `/hub/` routes
93
168
  * each demand a host-issued bearer token and answer 404 without one; they are
94
169
  * declared here because they are this API's surface, not because a page calls
95
170
  * them.
96
171
  */
97
- var apiRoutes_default = defineApiRoutes({
172
+ const routes = {
98
173
  artifact: {
99
174
  method: "GET",
100
175
  path: COMPUTER_USE_ROUTES.artifact,
101
176
  query: ["artifactId", "offset"],
102
177
  raw: true
103
178
  },
104
- activationState: {
105
- method: "GET",
106
- path: COMPUTER_USE_ROUTES.activate,
107
- response: apiResponse()
108
- },
109
- cancelActivation: {
110
- method: "DELETE",
111
- path: COMPUTER_USE_ROUTES.activate,
112
- response: apiResponse()
113
- },
114
- activate: {
115
- method: "POST",
116
- path: COMPUTER_USE_ROUTES.activate,
117
- response: apiResponse()
118
- },
119
179
  agentState: {
120
180
  method: "GET",
121
181
  path: COMPUTER_USE_ROUTES.agentState,
122
- response: apiResponse()
182
+ response: void 0
123
183
  },
124
184
  /** Answers whatever the admitted Desktop provider returned, which is runtime-defined JSON. */
125
185
  agentObserve: {
126
186
  method: "POST",
127
187
  path: COMPUTER_USE_ROUTES.agentObserve,
128
- response: apiResponse()
188
+ response: void 0
129
189
  },
130
190
  agentAction: {
131
191
  method: "POST",
132
192
  path: COMPUTER_USE_ROUTES.agentAction,
133
- response: apiResponse()
193
+ response: void 0
134
194
  },
135
195
  agentStop: {
136
196
  method: "POST",
137
197
  path: COMPUTER_USE_ROUTES.agentStop,
138
- response: apiResponse()
198
+ response: void 0
139
199
  },
140
200
  hubState: {
141
201
  method: "GET",
142
202
  path: COMPUTER_USE_ROUTES.hubState,
143
- response: apiResponse()
203
+ response: void 0
144
204
  },
145
205
  /** Null until a reader has confirmed one; reading it moves the session to `activating`. */
146
206
  hubActivation: {
147
207
  method: "GET",
148
208
  path: COMPUTER_USE_ROUTES.hubActivation,
149
- response: apiResponse()
209
+ response: void 0
150
210
  },
151
211
  hubAuthorization: {
152
212
  method: "GET",
153
213
  path: COMPUTER_USE_ROUTES.hubAuthorization,
154
- response: apiResponse()
214
+ response: void 0
155
215
  },
156
216
  hubNext: {
157
217
  method: "GET",
158
218
  path: COMPUTER_USE_ROUTES.hubNext,
159
- response: apiResponse()
219
+ response: void 0
160
220
  },
161
221
  hubComplete: {
162
222
  method: "POST",
163
223
  path: COMPUTER_USE_ROUTES.hubComplete,
164
- response: apiResponse()
224
+ response: void 0
225
+ },
226
+ hubRequestStop: {
227
+ method: "POST",
228
+ path: COMPUTER_USE_ROUTES.hubRequestStop,
229
+ response: void 0
165
230
  },
166
231
  hubStop: {
167
232
  method: "POST",
168
233
  path: COMPUTER_USE_ROUTES.hubStop,
169
- response: apiResponse()
234
+ response: void 0
235
+ },
236
+ /** Desktop's macOS permission states, served by the hub's `desktop-permissions` mount. */
237
+ desktopPermissions: {
238
+ method: "GET",
239
+ path: "/",
240
+ response: void 0
241
+ },
242
+ /** Asks macOS for the body's permission on the Mac running Desktop; answers the states after. */
243
+ requestDesktopPermission: {
244
+ method: "POST",
245
+ path: "/",
246
+ response: void 0
170
247
  }
171
- });
172
- const api = createApiClient(apiRoutes_default, {
248
+ };
249
+ createApiClient(routes, {
173
250
  scopes: ["session"],
174
251
  basePath: "computer-use",
175
- transport: (input, init) => sealedTransport.fetch(input, init),
252
+ transport: (input, init) => browserTransport.fetch(input, init),
253
+ sessionAddress: sessionApiAddress
254
+ });
255
+ const desktopPermissions = createApiClient(routes, {
256
+ scopes: [
257
+ "host",
258
+ "workspace",
259
+ "session"
260
+ ],
261
+ basePath: "desktop-permissions",
262
+ transport: (input, init) => browserTransport.fetch(input, init),
176
263
  sessionAddress: sessionApiAddress
177
264
  });
178
265
  //#endregion
179
- //#region src/extensions/workspaces/sessions/(frontend)/_lib/computerUseRecording.ts
180
- const MAX_RECORDING_BYTES = 134217728;
181
- const CHUNK_BYTES = 1048576;
182
- /** Owns only a bounded sealed download and its disposable browser URL. */
183
- async function loadComputerUseRecording(sessionId, artifactId, sizeBytes, signal) {
184
- if (!Number.isSafeInteger(sizeBytes) || sizeBytes < 1 || sizeBytes > MAX_RECORDING_BYTES) throw new Error("Recording exceeds the permitted size.");
185
- const parts = [];
186
- for (let offset = 0; offset < sizeBytes; offset += CHUNK_BYTES) {
187
- signal.throwIfAborted();
188
- const result = await api.session(sessionId).artifact({
189
- query: {
190
- artifactId,
191
- offset
192
- },
193
- signal
194
- });
195
- if (!result.ok || result.status !== 206) throw new Error("The recording is unavailable or access was revoked.");
196
- const end = Math.min(offset + CHUNK_BYTES, sizeBytes) - 1;
197
- if (result.response.headers.get("content-range") !== `bytes ${offset}-${end}/${sizeBytes}`) throw new Error("The recording response is invalid.");
198
- const bytes = await result.response.arrayBuffer();
199
- signal.throwIfAborted();
200
- if (bytes.byteLength !== end - offset + 1) throw new Error("The recording response is incomplete.");
201
- parts.push(bytes);
202
- }
203
- signal.throwIfAborted();
204
- const url = URL.createObjectURL(new Blob(parts, { type: "video/mp4" }));
205
- let disposed = false;
206
- return {
207
- url,
208
- dispose() {
209
- if (!disposed) {
210
- disposed = true;
211
- URL.revokeObjectURL(url);
212
- }
266
+ //#region src/extensions/(frontend)/setting/_components/DesktopPermissionsView.tsx
267
+ const COPY = {
268
+ accessibility: {
269
+ get title() {
270
+ return t("computerUse.ui.accessibility", "Accessibility");
271
+ },
272
+ get detail() {
273
+ return t("computerUse.ui.letsPoPressButtonsFillFieldsAnd", "Lets Po press buttons, fill fields and scroll in the app window you approve for computer use.");
274
+ }
275
+ },
276
+ "screen-recording": {
277
+ get title() {
278
+ return t("computerUse.ui.screenAndSystemAudioRecording", "Screen and system audio recording");
279
+ },
280
+ get detail() {
281
+ return t("computerUse.ui.letsPoSeeAndRecordTheWindow", "Lets Po see and record the window you approve, with its sound. macOS asks you to reopen Po after you allow it.");
282
+ }
283
+ },
284
+ microphone: {
285
+ get title() {
286
+ return t("computerUse.ui.microphone", "Microphone");
287
+ },
288
+ get detail() {
289
+ return t("computerUse.ui.letsYouTalkToPoAndAdds", "Lets you talk to Po, and adds your voice to computer-use recordings.");
290
+ }
291
+ },
292
+ automation: {
293
+ get title() {
294
+ return t("computerUse.ui.automation", "Automation");
295
+ },
296
+ get detail() {
297
+ return t("computerUse.ui.letsPoAndItsAgentsControlOther", "Lets Po and its agents control other apps, such as Finder or Mail. macOS asks once for each app; your answers are listed in System Settings.");
298
+ }
299
+ },
300
+ "full-disk-access": {
301
+ get title() {
302
+ return t("computerUse.ui.fullDiskAccess", "Full Disk Access");
303
+ },
304
+ get detail() {
305
+ return t("computerUse.ui.optionalLetsAgentsAndTheirToolsRead", "Optional. Lets agents and their tools read Documents, Downloads and Mail without a prompt for each folder.");
213
306
  }
307
+ }
308
+ };
309
+ const BADGE = {
310
+ granted: {
311
+ get label() {
312
+ return t("computerUse.ui.allowed", "Allowed");
313
+ },
314
+ tone: "green"
315
+ },
316
+ denied: {
317
+ get label() {
318
+ return t("computerUse.ui.notAllowed", "Not allowed");
319
+ },
320
+ tone: "neutral"
321
+ },
322
+ "not-determined": {
323
+ get label() {
324
+ return t("computerUse.ui.notAskedYet", "Not asked yet");
325
+ },
326
+ tone: "neutral"
327
+ },
328
+ "per-app": {
329
+ get label() {
330
+ return t("computerUse.ui.askedPerApp", "Asked per app");
331
+ },
332
+ tone: "neutral"
333
+ }
334
+ };
335
+ function PermissionRow({ permission, state, asking, waiting, onAsk }) {
336
+ const t = useT();
337
+ const badge = BADGE[state];
338
+ return /* @__PURE__ */ jsx(SettingsRow, {
339
+ asChild: true,
340
+ className: "items-start",
341
+ "data-testid": `desktop-permission-${permission}`,
342
+ children: /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsxs(SettingsRowText, {
343
+ className: "gap-1",
344
+ children: [/* @__PURE__ */ jsxs(SettingsRowTitle, {
345
+ className: "flex min-h-6 items-center gap-2",
346
+ children: [COPY[permission].title, /* @__PURE__ */ jsx(Badge, {
347
+ tone: badge.tone,
348
+ children: badge.label
349
+ })]
350
+ }), /* @__PURE__ */ jsx(SettingsRowDescription, { children: COPY[permission].detail })]
351
+ }), state === "granted" ? null : /* @__PURE__ */ jsx(Button, {
352
+ variant: "outline",
353
+ size: "sm",
354
+ disabled: waiting,
355
+ onClick: () => onAsk(permission),
356
+ children: asking ? t("computerUse.ui.waitingForMacOS", "Waiting for macOS") : state === "not-determined" ? t("computerUse.ui.allow", "Allow") : t("computerUse.ui.openSystemSettings", "Open System Settings")
357
+ })] })
358
+ });
359
+ }
360
+ function Message({ title, detail, alert, action }) {
361
+ const t = useT();
362
+ return /* @__PURE__ */ jsx(SettingsRow, {
363
+ asChild: true,
364
+ role: alert ? "alert" : "status",
365
+ children: /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsxs(SettingsRowText, { children: [/* @__PURE__ */ jsx(SettingsRowTitle, { children: title }), /* @__PURE__ */ jsx(SettingsRowDescription, { children: detail })] }), action === void 0 ? null : /* @__PURE__ */ jsx(Button, {
366
+ variant: "outline",
367
+ size: "sm",
368
+ onClick: action,
369
+ children: t("computerUse.ui.tryAgain", "Try again")
370
+ })] })
371
+ });
372
+ }
373
+ /** The macOS permissions Po needs on the Mac running Desktop, each with the one step that changes it. */
374
+ function DesktopPermissionsView({ state, remote, onAsk, onRefresh }) {
375
+ const t = useT();
376
+ return /* @__PURE__ */ jsxs(SettingsSection, {
377
+ "data-testid": "desktop-permissions",
378
+ children: [/* @__PURE__ */ jsxs(SettingsSectionHeader, { children: [
379
+ /* @__PURE__ */ jsx(SettingsSectionTitle, { children: t("computerUse.ui.onThisMac", "On this Mac") }),
380
+ /* @__PURE__ */ jsx(SettingsSectionDescription, { children: remote ? t("computerUse.ui.theseBelongToTheMacRunningPo", "These belong to the Mac running Po Desktop. When you ask from here, macOS shows its prompt on that Mac.") : t("computerUse.ui.poAsksMacOSForEachOneWhenText", "Po asks macOS for each one when you are ready. You can change them any time in System Settings, Privacy and Security.") }),
381
+ state.status === "ready" ? /* @__PURE__ */ jsx(SettingsActions, { children: /* @__PURE__ */ jsx(Button, {
382
+ variant: "ghost",
383
+ size: "sm",
384
+ onClick: onRefresh,
385
+ children: t("computerUse.ui.checkAgain", "Check again")
386
+ }) }) : null
387
+ ] }), /* @__PURE__ */ jsx(SettingsCard, {
388
+ asChild: true,
389
+ children: /* @__PURE__ */ jsx("ul", { children: state.status === "loading" ? /* @__PURE__ */ jsx(Message, {
390
+ title: t("computerUse.ui.checkingWithMacOS", "Checking with macOS"),
391
+ detail: t("computerUse.ui.thisTakesAMoment", "This takes a moment.")
392
+ }) : state.status === "unavailable" ? /* @__PURE__ */ jsx(Message, {
393
+ title: t("computerUse.ui.poDesktopIsNotRunningHere", "Po Desktop is not running here"),
394
+ detail: t("computerUse.ui.permissionsBelongToTheMacRunningPo", "Permissions belong to the Mac running Po Desktop. Open Po Desktop there to see and change them.")
395
+ }) : state.status === "error" ? /* @__PURE__ */ jsx(Message, {
396
+ title: t("computerUse.ui.poCouldnTReadThePermissionsJust", "Po couldn't read the permissions just now"),
397
+ detail: state.error,
398
+ alert: true,
399
+ action: onRefresh
400
+ }) : DESKTOP_PERMISSIONS.map((permission) => /* @__PURE__ */ jsx(PermissionRow, {
401
+ permission,
402
+ state: state.states[permission],
403
+ asking: state.asking === permission,
404
+ waiting: state.asking !== void 0,
405
+ onAsk
406
+ }, permission)) })
407
+ })]
408
+ });
409
+ }
410
+ //#endregion
411
+ //#region src/extensions/(frontend)/setting/_components/DesktopPermissionsPanel.tsx
412
+ /** UI discovery only: picks the copy. The server checks Electron's injected proof, not this marker. */
413
+ function inDesktopWindow() {
414
+ return window.poDesktop?.platform === "desktop";
415
+ }
416
+ async function viewStateOf(pending) {
417
+ try {
418
+ const response = await pending;
419
+ if (response.status === 404) return { status: "unavailable" };
420
+ const body = await response.json().catch(() => void 0);
421
+ if (response.ok && body !== void 0 && !("error" in body)) return {
422
+ status: "ready",
423
+ states: body
424
+ };
425
+ return {
426
+ status: "error",
427
+ error: (typeof body?.error === "string" ? body.error : void 0) ?? t("computerUse.ui.poDesktopDidNotAnswer", "Po Desktop did not answer.")
428
+ };
429
+ } catch (error) {
430
+ return {
431
+ status: "error",
432
+ error: error instanceof Error ? error.message : String(error)
433
+ };
434
+ }
435
+ }
436
+ /** Reads Desktop's macOS permissions through the host's transport, and asks for one with step-up. */
437
+ function DesktopPermissionsPanel({ request, requestWithStepUp }) {
438
+ const [state, setState] = useState({ status: "loading" });
439
+ const load = useCallback(async () => {
440
+ setState(await viewStateOf(request(desktopPermissions.host.desktopPermissions.url())));
441
+ }, [request]);
442
+ useEffect(() => {
443
+ load();
444
+ const onFocus = () => void load();
445
+ window.addEventListener("focus", onFocus);
446
+ return () => window.removeEventListener("focus", onFocus);
447
+ }, [load]);
448
+ const ask = async (permission) => {
449
+ setState((current) => current.status === "ready" ? {
450
+ ...current,
451
+ asking: permission
452
+ } : current);
453
+ const route = desktopPermissions.host.requestDesktopPermission;
454
+ setState(await viewStateOf(requestWithStepUp(route.url(), {
455
+ method: route.spec.method,
456
+ headers: { "content-type": "application/json" },
457
+ body: JSON.stringify({ permission })
458
+ })));
214
459
  };
460
+ return /* @__PURE__ */ jsx(DesktopPermissionsView, {
461
+ state,
462
+ remote: !inDesktopWindow(),
463
+ onAsk: (permission) => void ask(permission),
464
+ onRefresh: () => void load()
465
+ });
466
+ }
467
+ //#endregion
468
+ //#region src/extensions/(frontend)/setting/desktop-permissions.panel.web.tsx
469
+ var desktop_permissions_panel_web_default = defineSettingsPanel({
470
+ label: "permissions",
471
+ pluginPage: "Computer use",
472
+ detail: "what Po may do on this Mac",
473
+ order: 46,
474
+ icon: ShieldIcon,
475
+ component: DesktopPermissionsPanel
476
+ });
477
+ //#endregion
478
+ //#region src/extensions/workspaces/(frontend)/setting/computer-use.web.ts
479
+ var computer_use_web_default$2 = defineSettingsSection({
480
+ ...{ settingsSections: [computerUseSettingsSection] }.settingsSections[0],
481
+ icon: MonitorIcon
482
+ });
483
+ const computerUse = defineSessionStore({
484
+ state: {
485
+ sessionId: "",
486
+ revision: 0,
487
+ wake: 0,
488
+ phase: "inactive"
489
+ },
490
+ targets: []
491
+ });
492
+ function isRecord(value) {
493
+ return typeof value === "object" && value !== null && !Array.isArray(value);
215
494
  }
495
+ const computerUseChannel = computerUse.channel({
496
+ channel: computerUseChannelType,
497
+ parse(input) {
498
+ if (!isRecord(input) || !isRecord(input.state) || !Array.isArray(input.targets)) return null;
499
+ if (typeof input.state.phase !== "string" || typeof input.state.revision !== "number") return null;
500
+ return input;
501
+ },
502
+ reduce: (_current, payload) => payload
503
+ });
216
504
  //#endregion
217
505
  //#region src/extensions/workspaces/sessions/(frontend)/fill/_components/ComputerUsePanel.tsx
218
- function text(value, fallback) {
506
+ function text$1(value, fallback) {
219
507
  return typeof value === "string" || typeof value === "number" ? String(value) : fallback;
220
508
  }
221
- function ComputerUsePanel({ sessionId, sendSessionFrame }) {
509
+ function remaining(ms) {
510
+ const seconds = Math.max(0, Math.ceil(ms / 1e3));
511
+ return t("computerUse.ui.remainingTime", "{time} left", { time: `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}` });
512
+ }
513
+ function ComputerUsePanel(props) {
514
+ return /* @__PURE__ */ jsx(SessionPanel, { ...props }, props.sessionId ?? "none");
515
+ }
516
+ function SessionPanel({ sessionId, sendSessionFrame }) {
517
+ const t = useT();
222
518
  const session = useStore(computerUse.store, (state) => computerUse.select(state, sessionId));
223
- const [selected, setSelected] = useState(0);
224
- const [confirmationTarget, setConfirmationTarget] = useState();
225
- const [error, setError] = useState();
226
- const [recordingUrl, setRecordingUrl] = useState();
227
- const [recordingAccessDenied, setRecordingAccessDenied] = useState(false);
519
+ const [now, setNow] = useState(Date.now);
520
+ const expiresAt = session.state.phase === "active" ? session.state.expiresAt : void 0;
228
521
  const send = (payload) => {
229
522
  if (sessionId !== null) sendSessionFrame(sessionId, {
230
523
  type: computerUseChannelType,
@@ -237,449 +530,626 @@ function ComputerUsePanel({ sessionId, sendSessionFrame }) {
237
530
  type: computerUseChannelType,
238
531
  payload: { action: "status" }
239
532
  });
240
- sendSessionFrame(sessionId, {
241
- type: computerUseChannelType,
242
- payload: { action: "targets" }
243
- });
244
533
  }, [sendSessionFrame, sessionId]);
245
534
  useEffect(() => {
246
- if (sessionId === null) return;
247
- const controller = new AbortController();
248
- let timer;
249
- const poll = async () => {
250
- try {
251
- const result = await api.session(sessionId).activationState({ signal: controller.signal });
252
- if (controller.signal.aborted) return;
253
- setRecordingAccessDenied(!result.ok);
254
- if (result.ok) computerUse.update(sessionId, (current) => result.data.revision >= current.state.revision ? {
255
- ...current,
256
- state: result.data
257
- } : current);
258
- } catch {
259
- if (!controller.signal.aborted) setRecordingAccessDenied(true);
260
- }
261
- if (!controller.signal.aborted) timer = setTimeout(() => void poll(), 2e3);
262
- };
263
- poll();
264
- return () => {
265
- controller.abort();
266
- clearTimeout(timer);
267
- };
268
- }, [sessionId]);
269
- const artifactId = session.state.artifact?.artifactId;
270
- const artifactSize = session.state.artifact?.sizeBytes;
271
- const artifactStatus = session.state.artifact?.status;
272
- useEffect(() => {
273
- setRecordingUrl(void 0);
274
- if (recordingAccessDenied || sessionId === null || artifactId === void 0 || artifactSize === void 0 || artifactStatus !== "ready") return;
275
- const controller = new AbortController();
276
- let asset;
277
- loadComputerUseRecording(sessionId, artifactId, artifactSize, controller.signal).then((loaded) => {
278
- if (controller.signal.aborted) loaded.dispose();
279
- else {
280
- asset = loaded;
281
- setRecordingUrl(loaded.url);
282
- }
283
- }).catch(() => {
284
- if (!controller.signal.aborted) setError("The recording is unavailable or access was revoked.");
285
- });
286
- return () => {
287
- controller.abort();
288
- asset?.dispose();
289
- };
290
- }, [
291
- sessionId,
292
- artifactId,
293
- artifactSize,
294
- artifactStatus,
295
- recordingAccessDenied
296
- ]);
535
+ if (expiresAt === void 0) return;
536
+ const timer = setInterval(() => setNow(Date.now()), 1e3);
537
+ return () => clearInterval(timer);
538
+ }, [expiresAt]);
297
539
  if (sessionId === null) return /* @__PURE__ */ jsx("p", {
298
540
  className: "px-1 text-sm text-po-dim",
299
- children: "Select a session."
541
+ children: t("computerUse.ui.selectASession", "Select a session.")
300
542
  });
301
543
  const state = session.state;
302
- const target = session.targets[selected];
303
544
  const artifact = state.artifact;
304
- const confirm = async (chosenTarget = confirmationTarget) => {
305
- setError(void 0);
306
- try {
307
- const result = await api.session(sessionId).activate({ body: {
308
- ...chosenTarget === void 0 ? {} : { target: chosenTarget },
309
- durationMs: COMPUTER_USE_DEFAULT_DURATION_MS
310
- } });
311
- if (!result.ok) {
312
- if (result.status === 0) setError("The session is unreachable.");
313
- else setError(result.error === "" ? `Activation failed with HTTP ${result.status}.` : result.error);
314
- return;
315
- }
316
- setConfirmationTarget(void 0);
317
- computerUse.update(sessionId, (current) => ({
318
- ...current,
319
- state: result.data
320
- }));
321
- send({ action: "status" });
322
- } catch {
323
- setError("The activation request is unavailable.");
324
- }
325
- };
545
+ if (state.phase === "inactive") return null;
546
+ const controlled = state.target?.scope === "desktop" ? t("computerUse.ui.yourWholeDesktop", "your whole desktop") : text$1(state.target?.applicationName, t("computerUse.ui.theChosenWindow", "the chosen window"));
547
+ const left = expiresAt === void 0 ? void 0 : expiresAt - now;
548
+ const total = state.durationMs ?? 3e5;
326
549
  return /* @__PURE__ */ jsxs("div", {
327
550
  "data-testid": "computer-use-panel",
328
- className: "flex flex-col gap-2 text-base text-po-text",
551
+ className: "flex flex-col gap-3 text-base text-po-text",
329
552
  children: [
330
553
  /* @__PURE__ */ jsxs("header", {
331
- className: "flex items-center justify-between gap-2",
332
- children: [/* @__PURE__ */ jsx("span", {
333
- className: "text-po-dim",
334
- children: state.phase.replaceAll("_", " ")
335
- }), /* @__PURE__ */ jsx(Button, {
336
- size: "sm",
337
- type: "button",
338
- className: "min-h-7 rounded border border-po-border bg-po-panel px-2 py-1",
339
- onClick: () => send({ action: "targets" }),
340
- children: "Refresh targets"
554
+ className: "flex items-center gap-2 border-b border-po-border-soft pb-2",
555
+ children: [/* @__PURE__ */ jsx(MonitorIcon, {
556
+ "aria-hidden": true,
557
+ className: "size-4 text-po-dim"
558
+ }), /* @__PURE__ */ jsx("strong", {
559
+ className: "flex-1 text-po-hi",
560
+ children: t("computerUse.ui.computerUseText", "Computer use")
341
561
  })]
342
562
  }),
343
- session.busy ? /* @__PURE__ */ jsx("p", {
344
- className: "rounded border border-po-yellow px-2 py-1",
345
- children: "Computer use is busy in another session"
346
- }) : null,
347
563
  state.failure ? /* @__PURE__ */ jsx("p", {
348
564
  className: "text-po-red",
349
565
  children: state.failure.message
350
566
  }) : null,
351
- error ? /* @__PURE__ */ jsx("p", {
567
+ artifact?.status === "ready" ? /* @__PURE__ */ jsxs("p", {
568
+ "data-testid": "computer-use-artifact",
569
+ className: "flex items-center gap-2",
570
+ children: [/* @__PURE__ */ jsx("span", {
571
+ "aria-hidden": true,
572
+ className: "flex size-5 items-center justify-center rounded-full bg-po-green text-po-rail",
573
+ children: /* @__PURE__ */ jsx(CheckIcon, { className: "size-3" })
574
+ }), t("computerUse.ui.recordingFinished", "Recording finished.")]
575
+ }) : null,
576
+ artifact?.failure ? /* @__PURE__ */ jsx("p", {
352
577
  className: "text-po-red",
353
- children: error
578
+ children: artifact.failure.message
354
579
  }) : null,
355
- (state.phase === "inactive" || state.phase === "failed") && confirmationTarget === void 0 ? /* @__PURE__ */ jsxs("div", {
580
+ state.phase === "awaiting_confirmation" || state.phase === "activating" ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", { children: t("computerUse.ui.desktopActivationIsPending", "Desktop activation is pending.") }), /* @__PURE__ */ jsx(Button, {
581
+ size: "sm",
582
+ type: "button",
583
+ onClick: () => send({ action: "stop" }),
584
+ children: t("computerUse.ui.cancelActivation", "Cancel activation")
585
+ })] }) : null,
586
+ state.phase === "active" || state.phase === "stopping" ? /* @__PURE__ */ jsxs("div", {
356
587
  className: "flex flex-col gap-2",
357
588
  children: [
358
- /* @__PURE__ */ jsx("label", {
359
- htmlFor: "computer-use-target",
360
- children: "Application window"
589
+ /* @__PURE__ */ jsxs("p", {
590
+ className: "flex items-center gap-2 text-po-green",
591
+ children: [/* @__PURE__ */ jsx("span", {
592
+ "aria-hidden": true,
593
+ className: "size-2 rounded-full bg-po-green"
594
+ }), state.phase === "stopping" ? t("computerUse.ui.poIsHandingControlBack", "Po is handing control back") : t("computerUse.ui.controlling", "Po is controlling {target}", { target: controlled })]
361
595
  }),
362
- /* @__PURE__ */ jsx("select", {
363
- id: "computer-use-target",
364
- value: selected,
365
- onChange: (event) => setSelected(Number(event.target.value)),
366
- className: "min-h-7 rounded border border-po-border bg-po-panel px-2 py-1",
367
- children: session.targets.map((item, index) => /* @__PURE__ */ jsx("option", {
368
- value: index,
369
- children: text(item.applicationName, text(item.windowTitle, text(item.windowId, "Window")))
370
- }, text(item.windowId, String(index))))
596
+ left === void 0 ? null : /* @__PURE__ */ jsxs("div", {
597
+ className: "flex items-center gap-2",
598
+ children: [/* @__PURE__ */ jsx("div", {
599
+ role: "progressbar",
600
+ "aria-label": t("computerUse.ui.timeLeft", "Time left"),
601
+ "aria-valuemin": 0,
602
+ "aria-valuemax": total,
603
+ "aria-valuenow": Math.max(0, left),
604
+ className: "h-1.5 flex-1 overflow-hidden rounded-full bg-po-border-soft",
605
+ children: /* @__PURE__ */ jsx("div", {
606
+ className: "h-full rounded-full bg-po-green",
607
+ style: { width: `${Math.min(100, Math.max(0, left / total * 100))}%` }
608
+ })
609
+ }), /* @__PURE__ */ jsx("span", {
610
+ className: "text-sm text-po-dim tabular-nums",
611
+ children: remaining(left)
612
+ })]
371
613
  }),
372
614
  /* @__PURE__ */ jsx(Button, {
373
615
  size: "sm",
374
616
  type: "button",
375
- disabled: Boolean(session.busy),
376
- variant: "primary",
377
- onClick: () => {
378
- if (target === void 0) confirm();
379
- else setConfirmationTarget(Object.freeze({ ...target }));
380
- },
381
- children: target === void 0 ? "Choose window on Mac" : "Request activation"
382
- })
383
- ]
384
- }) : null,
385
- confirmationTarget !== void 0 ? /* @__PURE__ */ jsxs("div", {
386
- className: "rounded border border-po-blue p-3",
387
- children: [
388
- /* @__PURE__ */ jsx("strong", { children: "Confirm computer control" }),
389
- /* @__PURE__ */ jsxs("p", {
390
- className: "my-2 text-po-text",
391
- children: [
392
- text(confirmationTarget.applicationName, "Application"),
393
- ":",
394
- " ",
395
- text(confirmationTarget.windowTitle, text(confirmationTarget.windowId, "Window"))
396
- ]
397
- }),
398
- /* @__PURE__ */ jsx("p", {
399
- className: "my-2 text-po-dim",
400
- children: "Confirm a 5 minute session for this exact application window."
401
- }),
402
- /* @__PURE__ */ jsxs("div", {
403
- className: "flex gap-2",
404
- children: [/* @__PURE__ */ jsx(Button, {
405
- size: "sm",
406
- type: "button",
407
- variant: "primary",
408
- onClick: () => void confirm(),
409
- children: "Confirm"
410
- }), /* @__PURE__ */ jsx(Button, {
411
- size: "sm",
412
- type: "button",
413
- className: "min-h-7 rounded border border-po-border bg-po-panel px-2 py-1",
414
- onClick: () => setConfirmationTarget(void 0),
415
- children: "Cancel"
416
- })]
617
+ disabled: state.phase === "stopping",
618
+ className: "min-h-7 rounded border border-po-border bg-po-panel px-2 py-1",
619
+ onClick: () => send({ action: "stop" }),
620
+ children: t("computerUse.ui.stopComputerUse", "Stop computer use")
417
621
  })
418
622
  ]
419
- }) : null,
420
- state.phase === "awaiting_confirmation" || state.phase === "activating" ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", { children: "Desktop activation is pending." }), /* @__PURE__ */ jsx(Button, {
421
- size: "sm",
422
- type: "button",
423
- onClick: () => {
424
- (async () => {
425
- try {
426
- const result = await api.session(sessionId).cancelActivation();
427
- if (!result.ok) setError("The activation could not be cancelled.");
428
- else computerUse.update(sessionId, (current) => ({
429
- ...current,
430
- state: result.data
431
- }));
432
- } catch {
433
- setError("The activation could not be cancelled.");
434
- }
435
- })();
436
- },
437
- children: "Cancel activation"
438
- })] }) : null,
439
- state.phase === "active" || state.phase === "stopping" ? /* @__PURE__ */ jsx(Button, {
440
- size: "sm",
441
- type: "button",
442
- disabled: state.phase === "stopping",
443
- className: "min-h-7 rounded border border-po-border bg-po-panel px-2 py-1",
444
- onClick: () => send({ action: "stop" }),
445
- children: "Stop computer use"
446
- }) : null,
447
- artifact ? /* @__PURE__ */ jsxs("div", {
448
- "data-testid": "computer-use-artifact",
449
- className: "rounded bg-po-panel p-2",
450
- children: [
451
- /* @__PURE__ */ jsx("strong", { children: artifact.status === "ready" ? "Completed recording" : "Recording unavailable" }),
452
- /* @__PURE__ */ jsxs("p", { children: ["ID: ", artifact.artifactId] }),
453
- /* @__PURE__ */ jsxs("p", { children: ["Status: ", artifact.status] }),
454
- artifact.failure ? /* @__PURE__ */ jsx("p", {
455
- className: "text-po-red",
456
- children: artifact.failure.message
457
- }) : null,
458
- artifact.completedAt ? /* @__PURE__ */ jsxs("p", { children: ["Completed: ", artifact.completedAt] }) : null,
459
- artifact.actionCount !== void 0 ? /* @__PURE__ */ jsxs("p", { children: ["Actions: ", artifact.actionCount] }) : null,
460
- artifact.status === "ready" && artifact.sizeBytes && !recordingUrl ? /* @__PURE__ */ jsx("p", { children: "Loading recording through the secure channel." }) : null,
461
- artifact.status === "ready" && recordingUrl ? /* @__PURE__ */ jsx("video", {
462
- className: "mt-2 w-full",
463
- controls: true,
464
- preload: "metadata",
465
- src: recordingUrl,
466
- children: /* @__PURE__ */ jsx("track", { kind: "captions" })
467
- }) : null,
468
- artifact.status === "ready" && recordingUrl ? /* @__PURE__ */ jsx("a", {
469
- className: "mt-2 inline-block text-po-blue",
470
- href: recordingUrl,
471
- download: "Po-recording.mp4",
472
- children: "Download recording"
473
- }) : null
474
- ]
475
623
  }) : null
476
624
  ]
477
625
  });
478
626
  }
479
- //#endregion
480
- //#region src/extensions/workspaces/sessions/(frontend)/tool/_lib/computerActionToolRender.ts
481
- const computerActionToolName = "computer_action";
482
- function computerActionCallSummary(args) {
483
- return [typeof args.kind === "string" ? args.kind : "", typeof args.elementRef === "string" ? args.elementRef : ""].filter(Boolean).join(" ");
627
+ const MS_PER_SECOND = 1e3;
628
+ /**
629
+ * The computer_action call as its two pieces: the action kind first, the element
630
+ * it targets second. Either may be missing; the empty ones are dropped.
631
+ */
632
+ function computerActionCallParts(args) {
633
+ return [typeof args.kind === "string" ? args.kind : "", typeof args.elementRef === "string" ? args.elementRef : ""].filter(Boolean);
634
+ }
635
+ /** The computer_exec call's summary: the script it ran. */
636
+ function computerExecCallSummary(args) {
637
+ return typeof args.scriptPath === "string" ? args.scriptPath : "";
484
638
  }
485
639
  /**
486
- * The body as toned lines: what the result's details say, or its text. Pure,
487
- * so a unit test can pin it without a DOM; the item decides how many to show.
640
+ * The script path as its folder and its file name, so a phone header can let the
641
+ * folder truncate while the script name stays whole.
488
642
  */
489
- function computerActionResultLines(result) {
490
- if (result === null) return [];
491
- return toolResultTextLines(result.content).map((text) => ({
492
- text,
493
- tone: "dim"
643
+ function computerExecPathParts(path) {
644
+ const cut = path.lastIndexOf("/");
645
+ return cut < 0 ? {
646
+ folder: "",
647
+ name: path
648
+ } : {
649
+ folder: path.slice(0, cut + 1),
650
+ name: path.slice(cut + 1)
651
+ };
652
+ }
653
+ function record(value) {
654
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
655
+ }
656
+ const text = (value) => typeof value === "string" ? value : "";
657
+ const count = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
658
+ /** The result's text blocks joined; images (the screenshot) are dropped, as the web cards drop them. */
659
+ function computerResultText(content) {
660
+ return content.flatMap((block) => {
661
+ const entry = record(block);
662
+ return entry?.type === "text" && typeof entry.text === "string" ? [entry.text] : [];
663
+ }).join("\n");
664
+ }
665
+ /** `AXTextField` as `text field`; a role without the AX prefix is kept as it came. */
666
+ function computerRoleWords(role) {
667
+ if (!role.startsWith("AX")) return role;
668
+ return role.slice(2).replace(/([a-z])([A-Z])/gu, "$1 $2").toLowerCase();
669
+ }
670
+ function element(value) {
671
+ const entry = record(value);
672
+ if (entry === void 0 || typeof entry.ref !== "string") return [];
673
+ return [{
674
+ ref: entry.ref,
675
+ role: computerRoleWords(text(entry.role)),
676
+ label: text(entry.label) || text(entry.value),
677
+ enabled: entry.enabled !== false,
678
+ secure: entry.secure === true
679
+ }];
680
+ }
681
+ /** An observation when the value is one: an application name and an element list. */
682
+ function computerObservationView(value) {
683
+ const entry = record(value);
684
+ if (entry === void 0 || typeof entry.applicationName !== "string" || !Array.isArray(entry.elements)) return void 0;
685
+ const nextOffset = count(entry.nextOffset);
686
+ const artifact = text(entry.screenshotArtifact);
687
+ return {
688
+ applicationName: entry.applicationName,
689
+ windowTitle: text(entry.windowTitle),
690
+ elements: entry.elements.flatMap(element),
691
+ truncated: entry.truncated === true || nextOffset !== void 0,
692
+ ...nextOffset === void 0 ? {} : { nextOffset },
693
+ ...artifact.length > 0 ? { screenshotArtifact: artifact } : {}
694
+ };
695
+ }
696
+ /** One value of a script result as a short phrase: scalars as they read, collections by their size. */
697
+ function phrase(value) {
698
+ if (value === null || value === void 0) return "none";
699
+ if (typeof value === "string") return value;
700
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
701
+ if (Array.isArray(value)) return `${String(value.length)} item${value.length === 1 ? "" : "s"}`;
702
+ const size = Object.keys(value).length;
703
+ return `${String(size)} field${size === 1 ? "" : "s"}`;
704
+ }
705
+ /** A script's return value as fields: an object's own keys, or one `result` field for anything else. */
706
+ function computerResultFields(value) {
707
+ if (value === void 0) return [];
708
+ const entry = record(value);
709
+ if (entry === void 0) return [{
710
+ key: "result",
711
+ value: phrase(value)
712
+ }];
713
+ return Object.entries(entry).map(([key, field]) => ({
714
+ key,
715
+ value: phrase(field)
494
716
  }));
495
717
  }
718
+ function run(entry) {
719
+ if (!Array.isArray(entry.logs)) return void 0;
720
+ const observation = computerObservationView(entry.observation);
721
+ const metrics = record(entry.metrics);
722
+ const actions = count(metrics?.actions);
723
+ const observations = count(metrics?.observations);
724
+ const durationMs = count(metrics?.durationMs);
725
+ return {
726
+ fields: computerResultFields(entry.result),
727
+ logs: entry.logs.filter((line) => typeof line === "string"),
728
+ ...actions === void 0 ? {} : { actions },
729
+ ...observations === void 0 ? {} : { observations },
730
+ ...durationMs === void 0 ? {} : { duration: `${(durationMs / MS_PER_SECOND).toFixed(1)}s` },
731
+ ...observation === void 0 ? {} : { observation }
732
+ };
733
+ }
734
+ function failure(entry) {
735
+ if (typeof entry.error !== "string") return void 0;
736
+ const completedActions = count(entry.completedActions);
737
+ return {
738
+ reason: entry.error,
739
+ ...completedActions === void 0 ? {} : { completedActions },
740
+ outcomeUncertain: entry.outcomeUncertain === true
741
+ };
742
+ }
743
+ /** The text as lines a card can count: CRLF folded, tabs widened, trailing blank lines dropped. */
744
+ function lines(value) {
745
+ if (value.length === 0) return [];
746
+ const split = value.replaceAll("\r\n", "\n").replaceAll(" ", " ").split("\n");
747
+ while (split.length > 0 && split.at(-1)?.trim() === "") split.pop();
748
+ return split;
749
+ }
750
+ /**
751
+ * A computer tool result as the card lays it out. The tools answer in JSON (an
752
+ * observation, an action's outcome, a script run, a script failure) or in a
753
+ * plain sentence when they fail early; anything that does not parse as a shape
754
+ * the card knows falls back to its text lines.
755
+ */
756
+ function computerResultView(content) {
757
+ const raw = computerResultText(content);
758
+ let parsed;
759
+ try {
760
+ parsed = JSON.parse(raw);
761
+ } catch {
762
+ return {
763
+ kind: "text",
764
+ lines: lines(raw)
765
+ };
766
+ }
767
+ const entry = record(parsed);
768
+ const observation = computerObservationView(parsed);
769
+ if (observation !== void 0) return {
770
+ kind: "observation",
771
+ observation
772
+ };
773
+ const ran = entry === void 0 ? void 0 : run(entry);
774
+ if (ran !== void 0) return {
775
+ kind: "run",
776
+ run: ran
777
+ };
778
+ const failed = entry === void 0 ? void 0 : failure(entry);
779
+ if (failed !== void 0) return {
780
+ kind: "failure",
781
+ failure: failed
782
+ };
783
+ if (entry?.launched === true && typeof entry.applicationName === "string") return {
784
+ kind: "launched",
785
+ applicationName: entry.applicationName,
786
+ bundleId: text(entry.bundleId)
787
+ };
788
+ if (entry?.applied === true) return { kind: "applied" };
789
+ return {
790
+ kind: "text",
791
+ lines: lines(raw)
792
+ };
793
+ }
794
+ /** How many rows the view holds back while collapsed, so the card offers expand only when it reveals something. */
795
+ function computerResultHidden(view) {
796
+ switch (view.kind) {
797
+ case "observation": return Math.max(0, view.observation.elements.length - 5);
798
+ case "run": return Math.max(0, view.run.logs.length - 3);
799
+ case "text": return Math.max(0, view.lines.length - 8);
800
+ default: return 0;
801
+ }
802
+ }
803
+ //#endregion
804
+ //#region src/extensions/workspaces/sessions/(frontend)/tool/_components/ComputerResultBody.tsx
805
+ /** The parsed result, or none before the tool answers. */
806
+ function computerResult(props) {
807
+ return props.result === null ? void 0 : computerResultView(props.result.content);
808
+ }
809
+ /** Whether the card has rows to reveal: the header offers expand only then, and never on a failure. */
810
+ function computerResultExpandable(props) {
811
+ const view = computerResult(props);
812
+ return !props.isError && view !== void 0 && computerResultHidden(view) > 0;
813
+ }
814
+ /**
815
+ * The body the three computer tool cards share on web, laid out from the same
816
+ * parsed view as the native body (ComputerResultBody.native.tsx): the window and
817
+ * its elements, a script's figures, fields and logs, an action's outcome. A
818
+ * preview shows while collapsed. A failure shows only its reason in red, with a
819
+ * quiet note of any actions that already ran; the header already says it failed.
820
+ */
821
+ function ComputerResultBody({ props, expanded }) {
822
+ const t = useT();
823
+ const { toolName, output, running, isError } = props;
824
+ const view = computerResult(props);
825
+ const testID = `tool-result-${toolName}`;
826
+ if (isError) {
827
+ const failure = view?.kind === "failure" ? view.failure : {
828
+ reason: view?.kind === "text" ? view.lines.join("\n") : output.trim(),
829
+ outcomeUncertain: false
830
+ };
831
+ return failure.reason.length === 0 ? null : /* @__PURE__ */ jsx(MessageItemBody, {
832
+ "data-testid": testID,
833
+ children: /* @__PURE__ */ jsx(FailureBlock, { failure })
834
+ });
835
+ }
836
+ if (view === void 0) return running ? /* @__PURE__ */ jsx(MessageItemBody, {
837
+ "data-testid": testID,
838
+ children: /* @__PURE__ */ jsx(MessageItemStatus, {
839
+ tone: "running",
840
+ children: t("computerUse.ui.running", "running")
841
+ })
842
+ }) : null;
843
+ if (view.kind === "text" && view.lines.length === 0) return null;
844
+ return /* @__PURE__ */ jsxs(MessageItemBody, {
845
+ "data-testid": testID,
846
+ className: "flex flex-col gap-2",
847
+ children: [
848
+ view.kind === "observation" ? /* @__PURE__ */ jsx(ObservationBlock, {
849
+ observation: view.observation,
850
+ expanded
851
+ }) : null,
852
+ view.kind === "run" ? /* @__PURE__ */ jsx(RunBlock, {
853
+ run: view.run,
854
+ expanded
855
+ }) : null,
856
+ view.kind === "applied" ? /* @__PURE__ */ jsx("span", {
857
+ className: "text-po-text",
858
+ children: t("computerUse.ui.appliedToTheElement", "Applied to the element.")
859
+ }) : null,
860
+ view.kind === "launched" ? /* @__PURE__ */ jsxs("div", {
861
+ className: "flex min-w-0 items-baseline gap-2",
862
+ children: [/* @__PURE__ */ jsxs("span", {
863
+ className: "max-w-[60%] shrink-0 truncate font-semibold text-po-text",
864
+ children: [
865
+ t("computerUse.ui.opened", "Opened"),
866
+ " ",
867
+ view.applicationName
868
+ ]
869
+ }), /* @__PURE__ */ jsx("span", {
870
+ className: "min-w-0 truncate font-mono text-sm text-po-faint",
871
+ children: view.bundleId
872
+ })]
873
+ }) : null,
874
+ view.kind === "text" ? /* @__PURE__ */ jsx(TextLines, {
875
+ lines: view.lines,
876
+ expanded
877
+ }) : null,
878
+ running ? /* @__PURE__ */ jsx(MessageItemStatus, {
879
+ tone: "running",
880
+ children: t("computerUse.ui.running", "running")
881
+ }) : null
882
+ ]
883
+ });
884
+ }
885
+ function FailureBlock({ failure }) {
886
+ const t = useT();
887
+ const done = failure.completedActions;
888
+ const note = [done === void 0 ? "" : done === 1 ? t("computerUse.ui.actionsRanOne", "{count} action already ran", { count: done }) : t("computerUse.ui.actionsRan", "{count} actions already ran", { count: done }), failure.outcomeUncertain ? t("computerUse.ui.theLastOutcomeIsUncertain", "the last outcome is uncertain") : ""].filter(Boolean);
889
+ return /* @__PURE__ */ jsxs("div", {
890
+ className: "flex flex-col gap-1",
891
+ children: [/* @__PURE__ */ jsx("span", {
892
+ className: "whitespace-pre-wrap break-words text-po-red",
893
+ children: failure.reason
894
+ }), note.length > 0 ? /* @__PURE__ */ jsxs("span", {
895
+ className: "text-sm text-po-faint",
896
+ children: [note.join(", "), "."]
897
+ }) : null]
898
+ });
899
+ }
900
+ function WindowLine({ observation, lead }) {
901
+ return /* @__PURE__ */ jsxs("div", {
902
+ className: "flex min-w-0 items-baseline gap-2",
903
+ children: [/* @__PURE__ */ jsxs("span", {
904
+ className: "max-w-[60%] shrink-0 truncate font-semibold text-po-text",
905
+ children: [lead === void 0 ? "" : `${lead} `, observation.applicationName]
906
+ }), observation.windowTitle.length > 0 ? /* @__PURE__ */ jsx("span", {
907
+ className: "min-w-0 truncate text-po-dim",
908
+ children: observation.windowTitle
909
+ }) : null]
910
+ });
911
+ }
912
+ function ElementRow({ element }) {
913
+ const t = useT();
914
+ const secure = element.secure && !element.role.includes("secure");
915
+ const traits = [
916
+ element.role,
917
+ element.enabled ? "" : t("computerUse.ui.disabled", "disabled"),
918
+ secure ? t("computerUse.ui.secure", "secure") : ""
919
+ ].filter(Boolean);
920
+ return /* @__PURE__ */ jsxs("li", {
921
+ className: "contents",
922
+ children: [
923
+ /* @__PURE__ */ jsx("span", {
924
+ className: `min-w-0 truncate ${element.enabled ? "text-po-text" : "text-po-faint"}`,
925
+ children: element.label.length > 0 ? element.label : element.role
926
+ }),
927
+ /* @__PURE__ */ jsx("span", {
928
+ className: "truncate text-sm text-po-faint",
929
+ children: traits.join(" · ")
930
+ }),
931
+ /* @__PURE__ */ jsx("span", {
932
+ className: "text-right font-mono text-sm text-po-faint",
933
+ children: element.ref
934
+ })
935
+ ]
936
+ });
937
+ }
938
+ function ObservationBlock({ observation, expanded }) {
939
+ const t = useT();
940
+ const { elements } = observation;
941
+ const shown = expanded ? elements : elements.slice(0, 5);
942
+ const hidden = elements.length - shown.length;
943
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
944
+ /* @__PURE__ */ jsxs("div", {
945
+ className: "flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1.5",
946
+ children: [/* @__PURE__ */ jsx(WindowLine, { observation }), /* @__PURE__ */ jsxs("div", {
947
+ className: "flex flex-wrap gap-1.5",
948
+ children: [/* @__PURE__ */ jsx(Badge, {
949
+ size: "xs",
950
+ children: elements.length === 1 ? t("computerUse.ui.elementCountOne", "{count} element", { count: elements.length }) : t("computerUse.ui.elementCount", "{count} elements", { count: elements.length })
951
+ }), observation.truncated ? /* @__PURE__ */ jsx(Badge, {
952
+ size: "xs",
953
+ tone: "yellow",
954
+ children: observation.nextOffset === void 0 ? t("computerUse.ui.moreNotShown", "more not shown") : t("computerUse.ui.moreFromOffset", "more from offset {offset}", { offset: observation.nextOffset })
955
+ }) : null]
956
+ })]
957
+ }),
958
+ shown.length > 0 ? /* @__PURE__ */ jsx("ul", {
959
+ "aria-label": t("computerUse.ui.elements", "Elements"),
960
+ className: "grid grid-cols-[minmax(0,1fr)_minmax(0,auto)_auto] items-baseline gap-x-4 gap-y-1",
961
+ children: shown.map((element) => /* @__PURE__ */ jsx(ElementRow, { element }, element.ref))
962
+ }) : null,
963
+ hidden > 0 ? /* @__PURE__ */ jsx(MessageItemStatus, {
964
+ expands: true,
965
+ children: hidden === 1 ? t("computerUse.ui.moreElementsOne", "{count} more element", { count: hidden }) : t("computerUse.ui.moreElements", "{count} more elements", { count: hidden })
966
+ }) : null,
967
+ observation.screenshotArtifact === void 0 ? null : /* @__PURE__ */ jsx("span", {
968
+ className: "break-all text-sm text-po-faint",
969
+ children: t("computerUse.ui.screenshotSaved", "Screenshot saved to {path}", { path: observation.screenshotArtifact })
970
+ })
971
+ ] });
972
+ }
973
+ function RunBlock({ run, expanded }) {
974
+ const t = useT();
975
+ const figures = [
976
+ run.actions === void 0 ? "" : run.actions === 1 ? t("computerUse.ui.actionCountOne", "{count} action", { count: run.actions }) : t("computerUse.ui.actionCount", "{count} actions", { count: run.actions }),
977
+ run.observations === void 0 ? "" : run.observations === 1 ? t("computerUse.ui.observationCountOne", "{count} observation", { count: run.observations }) : t("computerUse.ui.observationCount", "{count} observations", { count: run.observations }),
978
+ run.duration ?? ""
979
+ ].filter(Boolean);
980
+ const logs = expanded ? run.logs : run.logs.slice(0, 3);
981
+ const hidden = run.logs.length - logs.length;
982
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
983
+ figures.length > 0 ? /* @__PURE__ */ jsx("div", {
984
+ className: "flex flex-wrap gap-1.5",
985
+ children: figures.map((figure) => /* @__PURE__ */ jsx(Badge, {
986
+ size: "xs",
987
+ children: figure
988
+ }, figure))
989
+ }) : null,
990
+ run.fields.length > 0 ? /* @__PURE__ */ jsx("dl", {
991
+ "aria-label": t("computerUse.ui.result", "Result"),
992
+ className: "grid grid-cols-[minmax(0,auto)_minmax(0,1fr)] items-baseline gap-x-4 gap-y-1",
993
+ children: run.fields.map((field) => /* @__PURE__ */ jsxs("div", {
994
+ className: "contents",
995
+ children: [/* @__PURE__ */ jsx("dt", {
996
+ className: "max-w-48 truncate text-sm text-po-faint",
997
+ children: field.key
998
+ }), /* @__PURE__ */ jsx("dd", {
999
+ className: "min-w-0 truncate text-po-text",
1000
+ children: field.value
1001
+ })]
1002
+ }, field.key))
1003
+ }) : null,
1004
+ logs.length > 0 ? /* @__PURE__ */ jsx("ul", {
1005
+ "aria-label": t("computerUse.ui.logs", "Logs"),
1006
+ className: "flex flex-col gap-0.5",
1007
+ children: logs.map((line, index) => /* @__PURE__ */ jsx("li", {
1008
+ className: "min-w-0 truncate font-mono text-sm text-po-dim",
1009
+ children: line
1010
+ }, `${String(index)}-${line}`))
1011
+ }) : null,
1012
+ hidden > 0 ? /* @__PURE__ */ jsx(MessageItemStatus, {
1013
+ expands: true,
1014
+ children: hidden === 1 ? t("computerUse.ui.moreLogLinesOne", "{count} more log line", { count: hidden }) : t("computerUse.ui.moreLogLines", "{count} more log lines", { count: hidden })
1015
+ }) : null,
1016
+ run.observation === void 0 ? null : /* @__PURE__ */ jsx(WindowLine, {
1017
+ observation: run.observation,
1018
+ lead: t("computerUse.ui.endedOn", "Ended on")
1019
+ })
1020
+ ] });
1021
+ }
1022
+ function TextLines({ lines, expanded }) {
1023
+ const t = useT();
1024
+ const shown = expanded ? lines : lines.slice(0, 8);
1025
+ const hidden = lines.length - shown.length;
1026
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
1027
+ className: "flex flex-col gap-0.5",
1028
+ children: shown.map((line, index) => /* @__PURE__ */ jsx("span", {
1029
+ className: "whitespace-pre-wrap break-words text-po-dim",
1030
+ children: line
1031
+ }, `${String(index)}-${line}`))
1032
+ }), hidden > 0 ? /* @__PURE__ */ jsx(MessageItemStatus, {
1033
+ expands: true,
1034
+ children: hidden === 1 ? t("computerUse.ui.moreLinesOne", "{count} more line", { count: hidden }) : t("computerUse.ui.moreLines", "{count} more lines", { count: hidden })
1035
+ }) : null] });
1036
+ }
496
1037
  //#endregion
497
1038
  //#region src/extensions/workspaces/sessions/(frontend)/tool/_components/ComputerActionToolCard.tsx
498
1039
  /**
499
- * The computer_action tool's timeline item: Perform one constrained semantic action in the authorized application window. The shell owns
500
- * the frame, the outcome tone, the status badge, and the expand toggle; this
501
- * card supplies the header summary and the body lines, and says whether it
502
- * hides any so the toggle appears only when it reveals something.
1040
+ * The computer_action tool's timeline item: the action and the element it
1041
+ * targets in the header, the outcome as one line beneath. The action is what
1042
+ * Po did, so it stays whole; the element ref truncates first.
503
1043
  */
504
- function ComputerActionToolCard({ toolName, args, result, running, isError }) {
505
- const lines = computerActionResultLines(result);
506
- const collapsed = collapseLines(lines, 8, false);
1044
+ function ComputerActionToolCard(props) {
1045
+ const { toolName, args, running, isError } = props;
1046
+ const [kind, ...target] = computerActionCallParts(args);
507
1047
  return /* @__PURE__ */ jsx(MessageItem, {
508
1048
  tone: toolTone({
509
1049
  running,
510
1050
  isError
511
1051
  }),
512
- expandable: collapsed.hidden > 0,
513
- children: ({ expanded }) => {
514
- const view = expanded ? collapseLines(lines, 8, true) : collapsed;
515
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MessageItemHeader, {
516
- title: toolName,
517
- children: /* @__PURE__ */ jsx("span", {
518
- "data-testid": `tool-call-${toolName}`,
519
- className: "min-w-0 flex-1 truncate text-po-text",
520
- children: computerActionCallSummary(args)
521
- })
522
- }), view.shown.length > 0 || running || isError ? /* @__PURE__ */ jsxs(MessageItemBody, {
523
- "data-testid": `tool-result-${toolName}`,
524
- className: "flex flex-col gap-1",
525
- children: [
526
- view.shown.length > 0 ? /* @__PURE__ */ jsx(MessageLines, { lines: view.shown }) : null,
527
- view.hidden > 0 ? /* @__PURE__ */ jsxs(MessageItemStatus, {
528
- expands: true,
529
- children: [view.hidden, " more line(s)"]
530
- }) : null,
531
- running ? /* @__PURE__ */ jsx(MessageItemStatus, {
532
- tone: "running",
533
- children: "running"
534
- }) : null,
535
- isError ? /* @__PURE__ */ jsx(MessageItemStatus, {
536
- tone: "error",
537
- children: "failed"
538
- }) : null
539
- ]
540
- }) : null] });
541
- }
1052
+ expandable: computerResultExpandable(props),
1053
+ children: ({ expanded }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MessageItemHeader, {
1054
+ title: toolName,
1055
+ children: /* @__PURE__ */ jsxs("span", {
1056
+ "data-testid": `tool-call-${toolName}`,
1057
+ className: "flex min-w-0 flex-1 items-baseline gap-2",
1058
+ children: [kind === void 0 ? null : /* @__PURE__ */ jsx("span", {
1059
+ className: "max-w-[45%] shrink-0 truncate text-po-text",
1060
+ children: kind
1061
+ }), target.length > 0 ? /* @__PURE__ */ jsx("span", {
1062
+ className: "min-w-0 truncate text-po-dim",
1063
+ children: target.join(" ")
1064
+ }) : null]
1065
+ })
1066
+ }), /* @__PURE__ */ jsx(ComputerResultBody, {
1067
+ props,
1068
+ expanded
1069
+ })] })
542
1070
  });
543
1071
  }
544
1072
  //#endregion
545
- //#region src/extensions/workspaces/sessions/(frontend)/tool/_lib/computerExecToolRender.ts
546
- const computerExecToolName = "computer_exec";
547
- function computerExecCallSummary(args) {
548
- return typeof args.scriptPath === "string" ? args.scriptPath : "";
549
- }
550
- function computerExecResultLines(result) {
551
- if (result === null) return [];
552
- return toolResultTextLines(result.content).map((text) => ({
553
- text,
554
- tone: "dim"
555
- }));
556
- }
557
- //#endregion
558
1073
  //#region src/extensions/workspaces/sessions/(frontend)/tool/_components/ComputerExecToolCard.tsx
559
- function ComputerExecToolCard({ toolName, args, result, running, isError }) {
560
- const lines = computerExecResultLines(result);
561
- const collapsed = collapseLines(lines, 8, false);
1074
+ /**
1075
+ * The computer_exec tool's timeline item: the script path in the header, the
1076
+ * run laid out beneath it (figures, return value, first logs, final window).
1077
+ * A long path loses its folder first, so the script name stays readable.
1078
+ */
1079
+ function ComputerExecToolCard(props) {
1080
+ const { toolName, args, running, isError } = props;
1081
+ const path = computerExecPathParts(computerExecCallSummary(args));
562
1082
  return /* @__PURE__ */ jsx(MessageItem, {
563
1083
  tone: toolTone({
564
1084
  running,
565
1085
  isError
566
1086
  }),
567
- expandable: collapsed.hidden > 0,
568
- children: ({ expanded }) => {
569
- const view = expanded ? collapseLines(lines, 8, true) : collapsed;
570
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MessageItemHeader, {
571
- title: toolName,
572
- children: /* @__PURE__ */ jsx("span", {
573
- "data-testid": `tool-call-${toolName}`,
574
- className: "min-w-0 flex-1 truncate text-po-text",
575
- children: computerExecCallSummary(args)
576
- })
577
- }), view.shown.length > 0 || running || isError ? /* @__PURE__ */ jsxs(MessageItemBody, {
578
- "data-testid": `tool-result-${toolName}`,
579
- className: "flex flex-col gap-1",
580
- children: [
581
- view.shown.length > 0 ? /* @__PURE__ */ jsx(MessageLines, { lines: view.shown }) : null,
582
- view.hidden > 0 ? /* @__PURE__ */ jsxs(MessageItemStatus, {
583
- expands: true,
584
- children: [view.hidden, " more line(s)"]
585
- }) : null,
586
- running ? /* @__PURE__ */ jsx(MessageItemStatus, {
587
- tone: "running",
588
- children: "running"
589
- }) : null,
590
- isError ? /* @__PURE__ */ jsx(MessageItemStatus, {
591
- tone: "error",
592
- children: "failed"
593
- }) : null
594
- ]
595
- }) : null] });
596
- }
1087
+ expandable: computerResultExpandable(props),
1088
+ children: ({ expanded }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MessageItemHeader, {
1089
+ title: toolName,
1090
+ children: /* @__PURE__ */ jsxs("span", {
1091
+ "data-testid": `tool-call-${toolName}`,
1092
+ className: "flex min-w-0 flex-1 items-baseline",
1093
+ children: [path.folder.length > 0 ? /* @__PURE__ */ jsx("span", {
1094
+ className: "min-w-0 truncate text-po-dim",
1095
+ children: path.folder
1096
+ }) : null, /* @__PURE__ */ jsx("span", {
1097
+ className: "max-w-full shrink-0 truncate text-po-text",
1098
+ children: path.name
1099
+ })]
1100
+ })
1101
+ }), /* @__PURE__ */ jsx(ComputerResultBody, {
1102
+ props,
1103
+ expanded
1104
+ })] })
597
1105
  });
598
1106
  }
599
1107
  //#endregion
600
- //#region src/extensions/workspaces/sessions/(frontend)/tool/_lib/computerStateToolRender.ts
601
- const computerStateToolName = "computer_state";
602
- function computerStateCallSummary(_args) {
603
- return "authorized window";
604
- }
605
- /**
606
- * The body as toned lines: what the result's details say, or its text. Pure,
607
- * so a unit test can pin it without a DOM; the item decides how many to show.
608
- */
609
- function computerStateResultLines(result) {
610
- if (result === null) return [];
611
- return toolResultTextLines(result.content).map((text) => ({
612
- text,
613
- tone: "dim"
614
- }));
615
- }
616
- //#endregion
617
1108
  //#region src/extensions/workspaces/sessions/(frontend)/tool/_components/ComputerStateToolCard.tsx
618
1109
  /**
619
- * The computer_state tool's timeline item: Observe the authorized application window and semantic accessibility state. The shell owns
620
- * the frame, the outcome tone, the status badge, and the expand toggle; this
621
- * card supplies the header summary and the body lines, and says whether it
622
- * hides any so the toggle appears only when it reveals something.
1110
+ * The computer_state tool's timeline item: the observed window in the header,
1111
+ * the observation laid out beneath it (window, element count, element list).
1112
+ * The shell owns the frame, the outcome tone, the status badge, and the toggle.
623
1113
  */
624
- function ComputerStateToolCard({ toolName, args, result, running, isError }) {
625
- const lines = computerStateResultLines(result);
626
- const collapsed = collapseLines(lines, 8, false);
1114
+ function ComputerStateToolCard(props) {
1115
+ const t = useT();
1116
+ const { toolName, running, isError } = props;
627
1117
  return /* @__PURE__ */ jsx(MessageItem, {
628
1118
  tone: toolTone({
629
1119
  running,
630
1120
  isError
631
1121
  }),
632
- expandable: collapsed.hidden > 0,
633
- children: ({ expanded }) => {
634
- const view = expanded ? collapseLines(lines, 8, true) : collapsed;
635
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MessageItemHeader, {
636
- title: toolName,
637
- children: /* @__PURE__ */ jsx("span", {
638
- "data-testid": `tool-call-${toolName}`,
639
- className: "min-w-0 flex-1 truncate text-po-text",
640
- children: computerStateCallSummary(args)
641
- })
642
- }), view.shown.length > 0 || running || isError ? /* @__PURE__ */ jsxs(MessageItemBody, {
643
- "data-testid": `tool-result-${toolName}`,
644
- className: "flex flex-col gap-1",
645
- children: [
646
- view.shown.length > 0 ? /* @__PURE__ */ jsx(MessageLines, { lines: view.shown }) : null,
647
- view.hidden > 0 ? /* @__PURE__ */ jsxs(MessageItemStatus, {
648
- expands: true,
649
- children: [view.hidden, " more line(s)"]
650
- }) : null,
651
- running ? /* @__PURE__ */ jsx(MessageItemStatus, {
652
- tone: "running",
653
- children: "running"
654
- }) : null,
655
- isError ? /* @__PURE__ */ jsx(MessageItemStatus, {
656
- tone: "error",
657
- children: "failed"
658
- }) : null
659
- ]
660
- }) : null] });
661
- }
1122
+ expandable: computerResultExpandable(props),
1123
+ children: ({ expanded }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MessageItemHeader, {
1124
+ title: toolName,
1125
+ children: /* @__PURE__ */ jsx("span", {
1126
+ "data-testid": `tool-call-${toolName}`,
1127
+ className: "min-w-0 flex-1 truncate text-po-text",
1128
+ children: toolName === "computer_state" ? t("computerUse.ui.authorizedWindow", "authorized window") : null
1129
+ })
1130
+ }), /* @__PURE__ */ jsx(ComputerResultBody, {
1131
+ props,
1132
+ expanded
1133
+ })] })
662
1134
  });
663
1135
  }
664
1136
  //#endregion
665
1137
  //#region src/extensions/workspaces/sessions/(frontend)/_legacy/index.ts
666
1138
  var _legacy_default = {
667
- minorModes: [{
1139
+ modes: [{
668
1140
  name: "computer use",
669
1141
  modeId: COMPUTER_USE_MODE_ID,
670
1142
  keys: "c e",
1143
+ icon: MonitorIcon,
671
1144
  statusKey: COMPUTER_USE_MODE_STATUS_KEY,
672
1145
  hideWhenMissing: true,
673
- desktopOnly: true,
674
1146
  order: 70
675
1147
  }],
676
1148
  activityGroups: [{
677
1149
  name: "computer-use",
678
1150
  keys: "c e",
679
- order: 70,
680
1151
  statusKey: COMPUTER_USE_STATUS_KEY,
681
1152
  hideWhenEmpty: true,
682
- desktopOnly: true,
683
1153
  marksBackgroundWork: false
684
1154
  }],
685
1155
  activitySections: [{
@@ -689,22 +1159,29 @@ var _legacy_default = {
689
1159
  channels: [computerUseChannel],
690
1160
  toolRenderers: [
691
1161
  {
692
- tools: [computerStateToolName],
1162
+ tools: [
1163
+ "computer_state",
1164
+ "computer_targets",
1165
+ "computer_request"
1166
+ ],
693
1167
  message: ComputerStateToolCard
694
1168
  },
695
1169
  {
696
- tools: [computerActionToolName],
1170
+ tools: ["computer_action"],
697
1171
  message: ComputerActionToolCard
698
1172
  },
699
1173
  {
700
- tools: [computerExecToolName],
1174
+ tools: ["computer_exec"],
701
1175
  message: ComputerExecToolCard
702
1176
  }
703
1177
  ]
704
1178
  };
705
1179
  //#endregion
706
1180
  //#region src/extensions/workspaces/sessions/(frontend)/activity-group/computer-use.web.ts
707
- var computer_use_web_default$1 = defineActivityGroup(_legacy_default.activityGroups[0]);
1181
+ var computer_use_web_default$1 = defineActivityGroup({
1182
+ ..._legacy_default.activityGroups[0],
1183
+ label: (t) => t("computerUse.activityGroup.label", "Computer use")
1184
+ });
708
1185
  //#endregion
709
1186
  //#region src/extensions/workspaces/sessions/(frontend)/channel/computer-use.web.ts
710
1187
  var computer_use_web_default = defineChannelFile(_legacy_default.channels[0]);
@@ -715,8 +1192,38 @@ var ComputerUse_activity_computer_use_web_default = defineFill({
715
1192
  ..._legacy_default.activitySections[0]
716
1193
  });
717
1194
  //#endregion
1195
+ //#region src/extensions/workspaces/sessions/(frontend)/fill/Computeruse.help.guides.web.ts
1196
+ var Computeruse_help_guides_web_default = defineFill({
1197
+ slot: "help.guides",
1198
+ id: "Computeruse",
1199
+ order: 280,
1200
+ data: {
1201
+ version: 1,
1202
+ category: "tools",
1203
+ labelKey: "computerUse.guides.computerUse",
1204
+ label: "Computer use",
1205
+ guides: [{
1206
+ id: "about",
1207
+ questionKey: "computerUse.guides.whatCanComputerUseDoForMe",
1208
+ question: "What can computer use do for me?",
1209
+ order: 0,
1210
+ answerKey: "computerUse.guides.computerUseLetsPoControlAnApprovedWindowOrTheWholeDesktopOnASupportedMacOSPoDesktopYouChooseTheScopeAndDuration",
1211
+ answer: "Computer use lets Po control an approved window or the whole desktop on a supported macOS Po Desktop. You choose the scope and duration.",
1212
+ keywords: ["desktop", "permissions"]
1213
+ }, {
1214
+ id: "use",
1215
+ questionKey: "computerUse.guides.howDoIStartAndStopComputerUse",
1216
+ question: "How do I start and stop computer use?",
1217
+ order: 1,
1218
+ answerKey: "computerUse.guides.enableComputerUseInHostSettingsSelectComputerUseModeThenApprovePoSRequestStopInActivityOrPressCmdShiftEscOnMacOS",
1219
+ answer: "Enable Computer Use in host settings, select Computer Use mode, then approve Po's request. Stop in Activity or press Cmd+Shift+Esc on macOS.",
1220
+ keywords: ["stop", "approval"]
1221
+ }]
1222
+ }
1223
+ });
1224
+ //#endregion
718
1225
  //#region src/extensions/workspaces/sessions/(frontend)/mode/computer-use/mode.web.ts
719
- var mode_web_default = defineMinorModeFile(_legacy_default.minorModes[0]);
1226
+ var mode_web_default = defineModeFile(_legacy_default.modes[0]);
720
1227
  //#endregion
721
1228
  //#region src/extensions/workspaces/sessions/(frontend)/tool/computer-action.web.tsx
722
1229
  var computer_action_web_default = defineToolRenderer(_legacy_default.toolRenderers[1]);
@@ -728,15 +1235,29 @@ var computer_exec_web_default = defineToolRenderer(_legacy_default.toolRenderers
728
1235
  var computer_state_web_default = defineToolRenderer(_legacy_default.toolRenderers[0]);
729
1236
  //#endregion
730
1237
  //#region generated/web.ts
731
- const via = (identity, value) => value === void 0 ? void 0 : {
732
- ...identity,
733
- ...value
1238
+ const via = (identity, value) => {
1239
+ if (value === void 0) return void 0;
1240
+ const declaration = value;
1241
+ return {
1242
+ ...identity,
1243
+ ...declaration,
1244
+ ...declaration.relations === void 0 ? {} : { relations: declaration.relations.map((relation) => ({
1245
+ evidence: "declared",
1246
+ ...relation
1247
+ })) }
1248
+ };
734
1249
  };
735
1250
  const webPlugin = defineWebPlugin({
736
1251
  id: "computer-use",
737
- global: { get settingsSections() {
738
- return [via({ id: "computer-use" }, computer_use_web_default$3)];
739
- } },
1252
+ packageName: "@agimon-ai/po-computer-use",
1253
+ host: {
1254
+ get settingsPanels() {
1255
+ return [via({ id: "desktop-permissions" }, desktop_permissions_panel_web_default)];
1256
+ },
1257
+ get settingsSections() {
1258
+ return [via({ id: "computer-use" }, computer_use_web_default$3), via({ id: "desktop-environment" }, desktop_environment_web_default)];
1259
+ }
1260
+ },
740
1261
  workspace: { get settingsSections() {
741
1262
  return [via({ id: "computer-use" }, computer_use_web_default$2)];
742
1263
  } },
@@ -751,9 +1272,12 @@ const webPlugin = defineWebPlugin({
751
1272
  return [via({
752
1273
  slot: "activity.computer-use",
753
1274
  id: "computer-use"
754
- }, ComputerUse_activity_computer_use_web_default)];
1275
+ }, ComputerUse_activity_computer_use_web_default), via({
1276
+ slot: "help.guides",
1277
+ id: "computeruse"
1278
+ }, Computeruse_help_guides_web_default)];
755
1279
  },
756
- get minorModes() {
1280
+ get modes() {
757
1281
  return [via({ name: "computer-use" }, mode_web_default)];
758
1282
  },
759
1283
  get toolRenderers() {