@agimon-ai/po-computer-use 0.0.0-alpha.176 → 0.0.0-alpha.178

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/README.md CHANGED
@@ -10,7 +10,7 @@ Session-scoped semantic computer control through the Po Desktop capability.
10
10
 
11
11
  ## Use
12
12
 
13
- In Desktop, enable Computer Use in host settings, then select the default-off **Computer Use** mode. Choose a target and duration and approve the request in the session’s Activity section. Only one session can hold a live Desktop run. Remote activation does not bypass Desktop opt-in or grant checks. To stop from another app on macOS, press **Cmd+Shift+Esc**. If macOS cannot register the shortcut, use **Computer Use → Stop Computer Use** in Po Desktop or stop from Activity.
13
+ In Desktop, enable Computer Use in host settings, then select the default-off **Computer Use** mode. When the agent needs control, it asks for a window or the whole desktop and a duration. Approve once from an owner-authenticated client. The computer-use Activity card monitors the live grant and offers Stop; there is no separate setup form. Only one session can hold a live Desktop run. Remote activation does not bypass Desktop opt-in or grant checks. To stop from another app on macOS, press **Cmd+Shift+Esc**. If macOS cannot register the shortcut, use **Computer Use → Stop Computer Use** in Po Desktop or stop from Activity.
14
14
 
15
15
  The `computer-use` mode exposes Activate, Deactivate, and Doctor actions. `/computer-use` reports the current state.
16
16
 
@@ -20,12 +20,12 @@ While active, the package exposes three tools:
20
20
  - `computer_action` performs one of the semantic actions advertised for an element in a current snapshot. Approved-window grants use the bundled, unmodified agent-desktop CLI and show a visual agent cursor. The cursor is not a separate keyboard or mouse. Whole-desktop grants continue to use the Swift backend for the existing cross-app, Dock and menu-bar behavior.
21
21
  - `computer_exec` executes a reusable JavaScript or erasable TypeScript function and its relative helpers in a restricted runtime, then returns a fresh semantic observation.
22
22
 
23
- Po’s Swift helper records MP4 and audio. Finished recordings are copied into session artifacts under `computer-use/` in bounded ranges. For a window grant, **Allow and keep trace** also keeps bounded JSONL action metadata and PNGs of that window. The trace does not contain element refs, entered text, or raw CLI debug output. Recording and tracing stop before sensitive input can be sent. Treat these artifacts as private desktop content.
23
+ Po’s Swift helper records MP4 and audio. Finished recordings are copied into session artifacts under `computer-use/` in bounded ranges. For a window grant, an approved request for extra trace capture also keeps bounded JSONL action metadata and PNGs of that window. The trace does not contain element refs, entered text, or raw CLI debug output. Recording and tracing stop before sensitive input can be sent. Treat these artifacts as private desktop content.
24
24
  Generated functions receive the authorized program API, JSON input, bounded logging, and cancellation. They do not receive Node or filesystem access. Script-internal observations omit screenshots by default, and `includeScreenshot: true` requests an image explicitly. Full Node execution requires both `trusted: true` and an exact host-configured `PO_COMPUTER_USE_SCRIPT_PATHS` allowlist. Trusted scripts remain unsandboxed, including their imported dependencies. See [Author computer functions](./docs/computer-scripts.md) for the contract, limits, trust boundary, and examples.
25
25
 
26
- With code mode, the same operations are the `computer` namespace in `exec` (`state`, `act`, `run`, `stop`), registered only while the native grant is active, and the three tools are withdrawn from the agent. The `codemode-how-to-computer-use` guide is listed whenever the mode is selected. MCP clients and hosts without code mode keep the tools.
26
+ With code mode, `computer.targets()` lists candidate windows and `computer.request()` asks for human approval. Hosts without code mode use `computer_targets` and `computer_request`. The `state`, `act`, `run` and `stop` members are available only during an active grant. The `codemode-how-to-computer-use` guide is listed whenever the mode is selected.
27
27
 
28
- All three tools remain unavailable during setup and are admitted only after the native grant becomes active. Disabling the mode or host opt-in, stopping control, expiry, or Desktop disconnection stops further actions. Once Desktop claims a session, browser and remote MCP clients cannot drive its agent, including previously attached clients. This is separate from requesting or cancelling an activation through the authorized client API. This ownership stays pinned for the server lifetime and is not restored from saved session data.
28
+ Disabling the mode or host opt-in, stopping control, expiry, or Desktop disconnection stops further actions. An approval does not change who can access the session. The owner can monitor or stop control from the same signed-in browser that approved it.
29
29
 
30
30
  ## Public API
31
31
 
@@ -159,51 +159,6 @@ const apiContracts = (0, _agimon_ai_po_core_apiContracts.defineApiContract)({
159
159
  }
160
160
  }
161
161
  }))),
162
- {
163
- id: "computer.activation.state",
164
- scope: "session",
165
- basePath: "computer-use",
166
- path: "/activate",
167
- method: "GET",
168
- authentication: "owner",
169
- description: "Read state as the matching pending requester or approved recording reader.",
170
- responses: (0, _agimon_ai_po_core_apiContracts.jsonApiResponses)(ComputerStateSchema)
171
- },
172
- {
173
- id: "computer.activation.cancel",
174
- scope: "session",
175
- basePath: "computer-use",
176
- path: "/activate",
177
- method: "DELETE",
178
- authentication: "owner",
179
- description: "Cancel only the matching requester pending activation.",
180
- responses: (0, _agimon_ai_po_core_apiContracts.jsonApiResponses)(ComputerStateSchema, 202)
181
- },
182
- {
183
- id: "computer.activate",
184
- scope: "session",
185
- basePath: "computer-use",
186
- path: "/activate",
187
- method: "POST",
188
- authentication: "owner",
189
- description: "Request confirmed Desktop access with admitted caller and remote step-up context. The target is one application window or the whole desktop; a remote caller may omit it so the local Mac selects.",
190
- body: {
191
- required: true,
192
- contentType: "application/json",
193
- schema: typebox.Type.Object({
194
- target: O(typebox.Type.Union([typebox.Type.Object({
195
- windowId: S,
196
- bundleId: S
197
- }), typebox.Type.Object({ scope: typebox.Type.Literal("desktop") })])),
198
- durationMs: typebox.Type.Integer({
199
- minimum: 1e3,
200
- maximum: 18e5
201
- }),
202
- traceConsent: O(typebox.Type.Boolean())
203
- })
204
- },
205
- responses: (0, _agimon_ai_po_core_apiContracts.jsonApiResponses)(ComputerStateSchema, 202)
206
- },
207
162
  {
208
163
  id: "computer.artifact",
209
164
  scope: "session",
@@ -231,6 +186,7 @@ const apiContracts = (0, _agimon_ai_po_core_apiContracts.defineApiContract)({
231
186
  },
232
187
  internal("GET", "/agent/state", ComputerStateSchema),
233
188
  internal("GET", "/hub/state", ComputerStateSchema),
189
+ internal("POST", "/hub/request-stop", ComputerStateSchema, void 0, 202),
234
190
  internal("POST", "/agent/observe", Json),
235
191
  internal("POST", "/agent/action", Json, ComputerActionSchema),
236
192
  internal("POST", "/agent/stop", ComputerStateSchema, void 0, 202),
@@ -1 +1 @@
1
- {"version":3,"file":"apiContracts.cjs","names":["Type","jsonApiResponses","defineApiContract"],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses, type PoHttpContract } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nconst S = Type.String();\nconst N = Type.Number();\nconst O = Type.Optional;\nconst values = <T extends string>(items: T[]) => Type.Union(items.map((item) => Type.Literal(item)));\nconst Json = Type.Unknown({\n description:\n 'Desktop provider JSON value. Targets, observations and action results are supplied by the admitted Desktop provider.',\n});\nconst Target = Type.Record(S, Json);\nconst Error = Type.Object({ code: S, message: S });\nconst Artifact = Type.Object({\n artifactId: S,\n status: values(['ready', 'failed']),\n sizeBytes: O(N),\n downloadUrl: O(S),\n previewUrl: O(S),\n actionCount: O(N),\n completedAt: O(S),\n failure: O(Error),\n});\nexport const ComputerStateSchema = Type.Object({\n sessionId: S,\n revision: N,\n wake: N,\n phase: values(['inactive', 'awaiting_confirmation', 'activating', 'active', 'stopping', 'failed']),\n requestId: O(S),\n target: O(Target),\n durationMs: O(N),\n expiresAt: O(N),\n failure: O(Error),\n artifact: O(Artifact),\n});\nconst Permission = values(['accessibility', 'screen-recording', 'microphone', 'automation', 'full-disk-access']);\nconst PermissionState = values(['granted', 'denied', 'not-determined', 'per-app']);\nexport const DesktopPermissionStatesSchema = Type.Object({\n accessibility: PermissionState,\n 'screen-recording': PermissionState,\n microphone: PermissionState,\n automation: PermissionState,\n 'full-disk-access': PermissionState,\n});\nconst Reference = {\n snapshotId: Type.String({ minLength: 1 }),\n elementRef: Type.String({ minLength: 1 }),\n};\nexport const ComputerActionSchema = Type.Union([\n Type.Object(\n { kind: values(['press', 'focus', 'expand', 'collapse', 'toggle', 'check', 'uncheck', 'scroll_to']), ...Reference },\n { additionalProperties: false },\n ),\n Type.Object({ kind: values(['set_value', 'select']), ...Reference, value: S }, { additionalProperties: false }),\n Type.Object({ kind: Type.Literal('type'), ...Reference, text: S }, { additionalProperties: false }),\n Type.Object(\n {\n kind: Type.Literal('scroll'),\n ...Reference,\n direction: values(['up', 'down', 'left', 'right']),\n amount: Type.Union([values(['line', 'page']), Type.Integer({ minimum: 1, maximum: 100 })]),\n },\n { additionalProperties: false },\n ),\n]);\nconst internal = (\n method: 'GET' | 'POST',\n path: string,\n output: object,\n body?: object,\n status = 200,\n): PoHttpContract => ({\n id: `computer.${path.slice(1).replaceAll('/', '.')}`,\n scope: 'session',\n basePath: 'computer-use',\n path,\n method,\n authentication: 'owner',\n description: `Computer use broker ${path}. Requires the host-issued ${path.startsWith('/agent/') ? 'agent' : 'hub'} bearer token.`,\n availability: 'Internal broker route; ordinary browser credentials are insufficient.',\n parameters: [\n {\n name: 'Authorization',\n in: 'header',\n required: true,\n schema: Type.String({ pattern: '^Bearer .+' }),\n },\n ],\n ...(body\n ? {\n body: { required: true, contentType: 'application/json', schema: body },\n }\n : {}),\n responses: jsonApiResponses(output, status),\n});\nexport const apiContracts = defineApiContract({\n version: 1,\n dynamic: ['Desktop provider target extensions, observations and operation results are runtime-defined JSON.'],\n http: [\n ...(['host', 'workspace', 'session'] as const).flatMap((scope) =>\n (['GET', 'POST'] as const).map((method) => ({\n id: `computer.permissions.${method === 'GET' ? 'read' : 'request'}`,\n scope,\n basePath: 'desktop-permissions',\n path: '/',\n method,\n authentication: 'owner' as const,\n description:\n method === 'GET'\n ? 'Read the Mac-owned permission states. Requires an authorized local Desktop caller or trusted remote caller.'\n : 'Ask macOS for one named permission. Requires an authorized local Desktop caller or remote passkey step-up.',\n availability: 'Requires Po Desktop to be running this server; otherwise returns 404.',\n ...(method === 'POST'\n ? {\n body: {\n required: true,\n contentType: 'application/json',\n schema: Type.Object({ permission: Permission }),\n },\n }\n : {}),\n responses: {\n ...jsonApiResponses(DesktopPermissionStatesSchema),\n '502': {\n description: 'Desktop permission request failed.',\n schema: Type.Object({ error: S }),\n },\n },\n })),\n ),\n {\n id: 'computer.activation.state',\n scope: 'session',\n basePath: 'computer-use',\n path: '/activate',\n method: 'GET',\n authentication: 'owner',\n description: 'Read state as the matching pending requester or approved recording reader.',\n responses: jsonApiResponses(ComputerStateSchema),\n },\n {\n id: 'computer.activation.cancel',\n scope: 'session',\n basePath: 'computer-use',\n path: '/activate',\n method: 'DELETE',\n authentication: 'owner',\n description: 'Cancel only the matching requester pending activation.',\n responses: jsonApiResponses(ComputerStateSchema, 202),\n },\n {\n id: 'computer.activate',\n scope: 'session',\n basePath: 'computer-use',\n path: '/activate',\n method: 'POST',\n authentication: 'owner',\n description:\n 'Request confirmed Desktop access with admitted caller and remote step-up context. The target is one application window or the whole desktop; a remote caller may omit it so the local Mac selects.',\n body: {\n required: true,\n contentType: 'application/json',\n schema: Type.Object({\n target: O(\n Type.Union([Type.Object({ windowId: S, bundleId: S }), Type.Object({ scope: Type.Literal('desktop') })]),\n ),\n durationMs: Type.Integer({ minimum: 1000, maximum: 1800000 }),\n traceConsent: O(Type.Boolean()),\n }),\n },\n responses: jsonApiResponses(ComputerStateSchema, 202),\n },\n {\n id: 'computer.artifact',\n scope: 'session',\n basePath: 'computer-use',\n path: '/artifact',\n method: 'GET',\n authentication: 'owner',\n description: 'Read at most 1 MiB of a recording belonging to this session and approved caller.',\n parameters: [\n { name: 'artifactId', in: 'query', required: true, schema: S },\n {\n name: 'offset',\n in: 'query',\n required: true,\n schema: Type.Integer({ minimum: 0 }),\n },\n ],\n responses: {\n 206: {\n description: 'Bounded recording bytes.',\n contentType: 'video/mp4',\n schema: Type.String({ format: 'binary' }),\n },\n },\n },\n internal('GET', '/agent/state', ComputerStateSchema),\n internal('GET', '/hub/state', ComputerStateSchema),\n internal('POST', '/agent/observe', Json),\n internal('POST', '/agent/action', Json, ComputerActionSchema),\n internal('POST', '/agent/stop', ComputerStateSchema, undefined, 202),\n internal(\n 'GET',\n '/hub/activation',\n Type.Union([\n Type.Null(),\n Type.Object({\n requestId: S,\n target: Target,\n durationSeconds: N,\n createdAt: N,\n confirmationExpiresAt: N,\n caller: Type.Object({\n locality: values(['local', 'remote']),\n stepUp: S,\n }),\n }),\n ]),\n ),\n internal('GET', '/hub/authorization', Type.Union([Type.Null(), Type.Object({ grantId: S, expiresAt: O(N) })])),\n internal(\n 'GET',\n '/hub/next',\n Type.Union([\n Type.Null(),\n Type.Object({\n id: S,\n operation: values(['observe', 'act']),\n payload: O(Json),\n grantId: S,\n sequence: O(N),\n }),\n ]),\n ),\n internal('POST', '/hub/complete', ComputerStateSchema, Type.Object({ id: S, error: O(S), result: O(Json) })),\n internal(\n 'POST',\n '/hub/stop',\n ComputerStateSchema,\n Type.Object({\n error: O(S),\n host: O(Type.Object({ grantId: S, expiresAt: N })),\n artifact: O(Artifact),\n }),\n ),\n ],\n sockets: (['host', 'workspace'] as const).flatMap((scope) => [\n {\n id: 'computer.state',\n scope,\n service: 'po.hub',\n member: 'computer_use_state',\n kind: 'channel',\n direction: 'server-to-client',\n description: 'Computer use channel payload.',\n input: Type.Object({\n state: ComputerStateSchema,\n targets: Type.Array(Target),\n busy: O(Type.Literal(true)),\n }),\n },\n {\n id: 'computer.command',\n scope,\n service: 'po.hub',\n member: 'computer_use_state',\n kind: 'channel',\n direction: 'client-to-server',\n description: 'Computer use browser channel command.',\n input: Type.Object({\n action: values(['status', 'targets', 'stop', 'artifacts']),\n }),\n },\n ]),\n});\nexport default apiContracts;\n"],"mappings":";;;;;;;AAGA,MAAM,IAAIA,QAAAA,KAAK,OAAO;AACtB,MAAM,IAAIA,QAAAA,KAAK,OAAO;AACtB,MAAM,IAAIA,QAAAA,KAAK;AACf,MAAM,UAA4B,UAAeA,QAAAA,KAAK,MAAM,MAAM,KAAK,SAASA,QAAAA,KAAK,QAAQ,IAAI,CAAC,CAAC;AACnG,MAAM,OAAOA,QAAAA,KAAK,QAAQ,EACxB,aACE,uHACJ,CAAC;AACD,MAAM,SAASA,QAAAA,KAAK,OAAO,GAAG,IAAI;AAClC,MAAM,QAAQA,QAAAA,KAAK,OAAO;CAAE,MAAM;CAAG,SAAS;AAAE,CAAC;AACjD,MAAM,WAAWA,QAAAA,KAAK,OAAO;CAC3B,YAAY;CACZ,QAAQ,OAAO,CAAC,SAAS,QA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AG,OAAO,EAAE,CAAC;GAAG,QAAQ,EAAE,IAAI;EAAE,CAAC,CAAC;EAC3G,SACE,QACA,aACA,qBACAA,QAAAA,KAAK,OAAO;GACV,OAAO,EAAE,CAAC;GACV,MAAM,EAAEA,QAAAA,KAAK,OAAO;IAAE,SAAS;IAAG,WAAW;GAAE,CAAC,CAAC;GACjD,UAAU,EAAE,QAAQ;EACtB,CAAC,CACH;CACF;CACA,SAAU,CAAC,QAAQ,WAAW,CAAC,CAAW,SAAS,UAAU,CAC3D;EACE,IAAI;EACJ;EACA,SAAS;EACT,QAAQ;EACR,MAAM;EACN,WAAW;EACX,aAAa;EACb,OAAOA,QAAAA,KAAK,OAAO;GACjB,OAAO;GACP,SAASA,QAAAA,KAAK,MAAM,MAAM;GAC1B,MAAM,EAAEA,QAAAA,KAAK,QAAQ,IAAI,CAAC;EAC5B,CAAC;CACH,GACA;EACE,IAAI;EACJ;EACA,SAAS;EACT,QAAQ;EACR,MAAM;EACN,WAAW;EACX,aAAa;EACb,OAAOA,QAAAA,KAAK,OAAO,EACjB,QAAQ,OAAO;GAAC;GAAU;GAAW;GAAQ;EAAW,CAAC,EAC3D,CAAC;CACH,CACF,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"apiContracts.cjs","names":["Type","jsonApiResponses","defineApiContract"],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses, type PoHttpContract } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nconst S = Type.String();\nconst N = Type.Number();\nconst O = Type.Optional;\nconst values = <T extends string>(items: T[]) => Type.Union(items.map((item) => Type.Literal(item)));\nconst Json = Type.Unknown({\n description:\n 'Desktop provider JSON value. Targets, observations and action results are supplied by the admitted Desktop provider.',\n});\nconst Target = Type.Record(S, Json);\nconst Error = Type.Object({ code: S, message: S });\nconst Artifact = Type.Object({\n artifactId: S,\n status: values(['ready', 'failed']),\n sizeBytes: O(N),\n downloadUrl: O(S),\n previewUrl: O(S),\n actionCount: O(N),\n completedAt: O(S),\n failure: O(Error),\n});\nexport const ComputerStateSchema = Type.Object({\n sessionId: S,\n revision: N,\n wake: N,\n phase: values(['inactive', 'awaiting_confirmation', 'activating', 'active', 'stopping', 'failed']),\n requestId: O(S),\n target: O(Target),\n durationMs: O(N),\n expiresAt: O(N),\n failure: O(Error),\n artifact: O(Artifact),\n});\nconst Permission = values(['accessibility', 'screen-recording', 'microphone', 'automation', 'full-disk-access']);\nconst PermissionState = values(['granted', 'denied', 'not-determined', 'per-app']);\nexport const DesktopPermissionStatesSchema = Type.Object({\n accessibility: PermissionState,\n 'screen-recording': PermissionState,\n microphone: PermissionState,\n automation: PermissionState,\n 'full-disk-access': PermissionState,\n});\nconst Reference = {\n snapshotId: Type.String({ minLength: 1 }),\n elementRef: Type.String({ minLength: 1 }),\n};\nexport const ComputerActionSchema = Type.Union([\n Type.Object(\n { kind: values(['press', 'focus', 'expand', 'collapse', 'toggle', 'check', 'uncheck', 'scroll_to']), ...Reference },\n { additionalProperties: false },\n ),\n Type.Object({ kind: values(['set_value', 'select']), ...Reference, value: S }, { additionalProperties: false }),\n Type.Object({ kind: Type.Literal('type'), ...Reference, text: S }, { additionalProperties: false }),\n Type.Object(\n {\n kind: Type.Literal('scroll'),\n ...Reference,\n direction: values(['up', 'down', 'left', 'right']),\n amount: Type.Union([values(['line', 'page']), Type.Integer({ minimum: 1, maximum: 100 })]),\n },\n { additionalProperties: false },\n ),\n]);\nconst internal = (\n method: 'GET' | 'POST',\n path: string,\n output: object,\n body?: object,\n status = 200,\n): PoHttpContract => ({\n id: `computer.${path.slice(1).replaceAll('/', '.')}`,\n scope: 'session',\n basePath: 'computer-use',\n path,\n method,\n authentication: 'owner',\n description: `Computer use broker ${path}. Requires the host-issued ${path.startsWith('/agent/') ? 'agent' : 'hub'} bearer token.`,\n availability: 'Internal broker route; ordinary browser credentials are insufficient.',\n parameters: [\n {\n name: 'Authorization',\n in: 'header',\n required: true,\n schema: Type.String({ pattern: '^Bearer .+' }),\n },\n ],\n ...(body\n ? {\n body: { required: true, contentType: 'application/json', schema: body },\n }\n : {}),\n responses: jsonApiResponses(output, status),\n});\nexport const apiContracts = defineApiContract({\n version: 1,\n dynamic: ['Desktop provider target extensions, observations and operation results are runtime-defined JSON.'],\n http: [\n ...(['host', 'workspace', 'session'] as const).flatMap((scope) =>\n (['GET', 'POST'] as const).map((method) => ({\n id: `computer.permissions.${method === 'GET' ? 'read' : 'request'}`,\n scope,\n basePath: 'desktop-permissions',\n path: '/',\n method,\n authentication: 'owner' as const,\n description:\n method === 'GET'\n ? 'Read the Mac-owned permission states. Requires an authorized local Desktop caller or trusted remote caller.'\n : 'Ask macOS for one named permission. Requires an authorized local Desktop caller or remote passkey step-up.',\n availability: 'Requires Po Desktop to be running this server; otherwise returns 404.',\n ...(method === 'POST'\n ? {\n body: {\n required: true,\n contentType: 'application/json',\n schema: Type.Object({ permission: Permission }),\n },\n }\n : {}),\n responses: {\n ...jsonApiResponses(DesktopPermissionStatesSchema),\n '502': {\n description: 'Desktop permission request failed.',\n schema: Type.Object({ error: S }),\n },\n },\n })),\n ),\n {\n id: 'computer.artifact',\n scope: 'session',\n basePath: 'computer-use',\n path: '/artifact',\n method: 'GET',\n authentication: 'owner',\n description: 'Read at most 1 MiB of a recording belonging to this session and approved caller.',\n parameters: [\n { name: 'artifactId', in: 'query', required: true, schema: S },\n {\n name: 'offset',\n in: 'query',\n required: true,\n schema: Type.Integer({ minimum: 0 }),\n },\n ],\n responses: {\n 206: {\n description: 'Bounded recording bytes.',\n contentType: 'video/mp4',\n schema: Type.String({ format: 'binary' }),\n },\n },\n },\n internal('GET', '/agent/state', ComputerStateSchema),\n internal('GET', '/hub/state', ComputerStateSchema),\n internal('POST', '/hub/request-stop', ComputerStateSchema, undefined, 202),\n internal('POST', '/agent/observe', Json),\n internal('POST', '/agent/action', Json, ComputerActionSchema),\n internal('POST', '/agent/stop', ComputerStateSchema, undefined, 202),\n internal(\n 'GET',\n '/hub/activation',\n Type.Union([\n Type.Null(),\n Type.Object({\n requestId: S,\n target: Target,\n durationSeconds: N,\n createdAt: N,\n confirmationExpiresAt: N,\n caller: Type.Object({\n locality: values(['local', 'remote']),\n stepUp: S,\n }),\n }),\n ]),\n ),\n internal('GET', '/hub/authorization', Type.Union([Type.Null(), Type.Object({ grantId: S, expiresAt: O(N) })])),\n internal(\n 'GET',\n '/hub/next',\n Type.Union([\n Type.Null(),\n Type.Object({\n id: S,\n operation: values(['observe', 'act']),\n payload: O(Json),\n grantId: S,\n sequence: O(N),\n }),\n ]),\n ),\n internal('POST', '/hub/complete', ComputerStateSchema, Type.Object({ id: S, error: O(S), result: O(Json) })),\n internal(\n 'POST',\n '/hub/stop',\n ComputerStateSchema,\n Type.Object({\n error: O(S),\n host: O(Type.Object({ grantId: S, expiresAt: N })),\n artifact: O(Artifact),\n }),\n ),\n ],\n sockets: (['host', 'workspace'] as const).flatMap((scope) => [\n {\n id: 'computer.state',\n scope,\n service: 'po.hub',\n member: 'computer_use_state',\n kind: 'channel',\n direction: 'server-to-client',\n description: 'Computer use channel payload.',\n input: Type.Object({\n state: ComputerStateSchema,\n targets: Type.Array(Target),\n busy: O(Type.Literal(true)),\n }),\n },\n {\n id: 'computer.command',\n scope,\n service: 'po.hub',\n member: 'computer_use_state',\n kind: 'channel',\n direction: 'client-to-server',\n description: 'Computer use browser channel command.',\n input: Type.Object({\n action: values(['status', 'targets', 'stop', 'artifacts']),\n }),\n },\n ]),\n});\nexport default apiContracts;\n"],"mappings":";;;;;;;AAGA,MAAM,IAAIA,QAAAA,KAAK,OAAO;AACtB,MAAM,IAAIA,QAAAA,KAAK,OAAO;AACtB,MAAM,IAAIA,QAAAA,KAAK;AACf,MAAM,UAA4B,UAAeA,QAAAA,KAAK,MAAM,MAAM,KAAK,SAASA,QAAAA,KAAK,QAAQ,IAAI,CAAC,CAAC;AACnG,MAAM,OAAOA,QAAAA,KAAK,QAAQ,EACxB,aACE,uHACJ,CAAC;AACD,MAAM,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QAAQ;EACR,MAAM;EACN,WAAW;EACX,aAAa;EACb,OAAOA,QAAAA,KAAK,OAAO,EACjB,QAAQ,OAAO;GAAC;GAAU;GAAW;GAAQ;EAAW,CAAC,EAC3D,CAAC;CACH,CACF,CAAC;AACH,CAAC"}
@@ -155,51 +155,6 @@ const apiContracts = defineApiContract({
155
155
  }
156
156
  }
157
157
  }))),
158
- {
159
- id: "computer.activation.state",
160
- scope: "session",
161
- basePath: "computer-use",
162
- path: "/activate",
163
- method: "GET",
164
- authentication: "owner",
165
- description: "Read state as the matching pending requester or approved recording reader.",
166
- responses: jsonApiResponses(ComputerStateSchema)
167
- },
168
- {
169
- id: "computer.activation.cancel",
170
- scope: "session",
171
- basePath: "computer-use",
172
- path: "/activate",
173
- method: "DELETE",
174
- authentication: "owner",
175
- description: "Cancel only the matching requester pending activation.",
176
- responses: jsonApiResponses(ComputerStateSchema, 202)
177
- },
178
- {
179
- id: "computer.activate",
180
- scope: "session",
181
- basePath: "computer-use",
182
- path: "/activate",
183
- method: "POST",
184
- authentication: "owner",
185
- description: "Request confirmed Desktop access with admitted caller and remote step-up context. The target is one application window or the whole desktop; a remote caller may omit it so the local Mac selects.",
186
- body: {
187
- required: true,
188
- contentType: "application/json",
189
- schema: Type.Object({
190
- target: O(Type.Union([Type.Object({
191
- windowId: S,
192
- bundleId: S
193
- }), Type.Object({ scope: Type.Literal("desktop") })])),
194
- durationMs: Type.Integer({
195
- minimum: 1e3,
196
- maximum: 18e5
197
- }),
198
- traceConsent: O(Type.Boolean())
199
- })
200
- },
201
- responses: jsonApiResponses(ComputerStateSchema, 202)
202
- },
203
158
  {
204
159
  id: "computer.artifact",
205
160
  scope: "session",
@@ -227,6 +182,7 @@ const apiContracts = defineApiContract({
227
182
  },
228
183
  internal("GET", "/agent/state", ComputerStateSchema),
229
184
  internal("GET", "/hub/state", ComputerStateSchema),
185
+ internal("POST", "/hub/request-stop", ComputerStateSchema, void 0, 202),
230
186
  internal("POST", "/agent/observe", Json),
231
187
  internal("POST", "/agent/action", Json, ComputerActionSchema),
232
188
  internal("POST", "/agent/stop", ComputerStateSchema, void 0, 202),
@@ -1 +1 @@
1
- {"version":3,"file":"apiContracts.mjs","names":[],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses, type PoHttpContract } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nconst S = Type.String();\nconst N = Type.Number();\nconst O = Type.Optional;\nconst values = <T extends string>(items: T[]) => Type.Union(items.map((item) => Type.Literal(item)));\nconst Json = Type.Unknown({\n description:\n 'Desktop provider JSON value. Targets, observations and action results are supplied by the admitted Desktop provider.',\n});\nconst Target = Type.Record(S, Json);\nconst Error = Type.Object({ code: S, message: S });\nconst Artifact = Type.Object({\n artifactId: S,\n status: values(['ready', 'failed']),\n sizeBytes: O(N),\n downloadUrl: O(S),\n previewUrl: O(S),\n actionCount: O(N),\n completedAt: O(S),\n failure: O(Error),\n});\nexport const ComputerStateSchema = Type.Object({\n sessionId: S,\n revision: N,\n wake: N,\n phase: values(['inactive', 'awaiting_confirmation', 'activating', 'active', 'stopping', 'failed']),\n requestId: O(S),\n target: O(Target),\n durationMs: O(N),\n expiresAt: O(N),\n failure: O(Error),\n artifact: O(Artifact),\n});\nconst Permission = values(['accessibility', 'screen-recording', 'microphone', 'automation', 'full-disk-access']);\nconst PermissionState = values(['granted', 'denied', 'not-determined', 'per-app']);\nexport const DesktopPermissionStatesSchema = Type.Object({\n accessibility: PermissionState,\n 'screen-recording': PermissionState,\n microphone: PermissionState,\n automation: PermissionState,\n 'full-disk-access': PermissionState,\n});\nconst Reference = {\n snapshotId: Type.String({ minLength: 1 }),\n elementRef: Type.String({ minLength: 1 }),\n};\nexport const ComputerActionSchema = Type.Union([\n Type.Object(\n { kind: values(['press', 'focus', 'expand', 'collapse', 'toggle', 'check', 'uncheck', 'scroll_to']), ...Reference },\n { additionalProperties: false },\n ),\n Type.Object({ kind: values(['set_value', 'select']), ...Reference, value: S }, { additionalProperties: false }),\n Type.Object({ kind: Type.Literal('type'), ...Reference, text: S }, { additionalProperties: false }),\n Type.Object(\n {\n kind: Type.Literal('scroll'),\n ...Reference,\n direction: values(['up', 'down', 'left', 'right']),\n amount: Type.Union([values(['line', 'page']), Type.Integer({ minimum: 1, maximum: 100 })]),\n },\n { additionalProperties: false },\n ),\n]);\nconst internal = (\n method: 'GET' | 'POST',\n path: string,\n output: object,\n body?: object,\n status = 200,\n): PoHttpContract => ({\n id: `computer.${path.slice(1).replaceAll('/', '.')}`,\n scope: 'session',\n basePath: 'computer-use',\n path,\n method,\n authentication: 'owner',\n description: `Computer use broker ${path}. Requires the host-issued ${path.startsWith('/agent/') ? 'agent' : 'hub'} bearer token.`,\n availability: 'Internal broker route; ordinary browser credentials are insufficient.',\n parameters: [\n {\n name: 'Authorization',\n in: 'header',\n required: true,\n schema: Type.String({ pattern: '^Bearer .+' }),\n },\n ],\n ...(body\n ? {\n body: { required: true, contentType: 'application/json', schema: body },\n }\n : {}),\n responses: jsonApiResponses(output, status),\n});\nexport const apiContracts = defineApiContract({\n version: 1,\n dynamic: ['Desktop provider target extensions, observations and operation results are runtime-defined JSON.'],\n http: [\n ...(['host', 'workspace', 'session'] as const).flatMap((scope) =>\n (['GET', 'POST'] as const).map((method) => ({\n id: `computer.permissions.${method === 'GET' ? 'read' : 'request'}`,\n scope,\n basePath: 'desktop-permissions',\n path: '/',\n method,\n authentication: 'owner' as const,\n description:\n method === 'GET'\n ? 'Read the Mac-owned permission states. Requires an authorized local Desktop caller or trusted remote caller.'\n : 'Ask macOS for one named permission. Requires an authorized local Desktop caller or remote passkey step-up.',\n availability: 'Requires Po Desktop to be running this server; otherwise returns 404.',\n ...(method === 'POST'\n ? {\n body: {\n required: true,\n contentType: 'application/json',\n schema: Type.Object({ permission: Permission }),\n },\n }\n : {}),\n responses: {\n ...jsonApiResponses(DesktopPermissionStatesSchema),\n '502': {\n description: 'Desktop permission request failed.',\n schema: Type.Object({ error: S }),\n },\n },\n })),\n ),\n {\n id: 'computer.activation.state',\n scope: 'session',\n basePath: 'computer-use',\n path: '/activate',\n method: 'GET',\n authentication: 'owner',\n description: 'Read state as the matching pending requester or approved recording reader.',\n responses: jsonApiResponses(ComputerStateSchema),\n },\n {\n id: 'computer.activation.cancel',\n scope: 'session',\n basePath: 'computer-use',\n path: '/activate',\n method: 'DELETE',\n authentication: 'owner',\n description: 'Cancel only the matching requester pending activation.',\n responses: jsonApiResponses(ComputerStateSchema, 202),\n },\n {\n id: 'computer.activate',\n scope: 'session',\n basePath: 'computer-use',\n path: '/activate',\n method: 'POST',\n authentication: 'owner',\n description:\n 'Request confirmed Desktop access with admitted caller and remote step-up context. The target is one application window or the whole desktop; a remote caller may omit it so the local Mac selects.',\n body: {\n required: true,\n contentType: 'application/json',\n schema: Type.Object({\n target: O(\n Type.Union([Type.Object({ windowId: S, bundleId: S }), Type.Object({ scope: Type.Literal('desktop') })]),\n ),\n durationMs: Type.Integer({ minimum: 1000, maximum: 1800000 }),\n traceConsent: O(Type.Boolean()),\n }),\n },\n responses: jsonApiResponses(ComputerStateSchema, 202),\n },\n {\n id: 'computer.artifact',\n scope: 'session',\n basePath: 'computer-use',\n path: '/artifact',\n method: 'GET',\n authentication: 'owner',\n description: 'Read at most 1 MiB of a recording belonging to this session and approved caller.',\n parameters: [\n { name: 'artifactId', in: 'query', required: true, schema: S },\n {\n name: 'offset',\n in: 'query',\n required: true,\n schema: Type.Integer({ minimum: 0 }),\n },\n ],\n responses: {\n 206: {\n description: 'Bounded recording bytes.',\n contentType: 'video/mp4',\n schema: Type.String({ format: 'binary' }),\n },\n },\n },\n internal('GET', '/agent/state', ComputerStateSchema),\n internal('GET', '/hub/state', ComputerStateSchema),\n internal('POST', '/agent/observe', Json),\n internal('POST', '/agent/action', Json, ComputerActionSchema),\n internal('POST', '/agent/stop', ComputerStateSchema, undefined, 202),\n internal(\n 'GET',\n '/hub/activation',\n Type.Union([\n Type.Null(),\n Type.Object({\n requestId: S,\n target: Target,\n durationSeconds: N,\n createdAt: N,\n confirmationExpiresAt: N,\n caller: Type.Object({\n locality: values(['local', 'remote']),\n stepUp: S,\n }),\n }),\n ]),\n ),\n internal('GET', '/hub/authorization', Type.Union([Type.Null(), Type.Object({ grantId: S, expiresAt: O(N) })])),\n internal(\n 'GET',\n '/hub/next',\n Type.Union([\n Type.Null(),\n Type.Object({\n id: S,\n operation: values(['observe', 'act']),\n payload: O(Json),\n grantId: S,\n sequence: O(N),\n }),\n ]),\n ),\n internal('POST', '/hub/complete', ComputerStateSchema, Type.Object({ id: S, error: O(S), result: O(Json) })),\n internal(\n 'POST',\n '/hub/stop',\n ComputerStateSchema,\n Type.Object({\n error: O(S),\n host: O(Type.Object({ grantId: S, expiresAt: N })),\n artifact: O(Artifact),\n }),\n ),\n ],\n sockets: (['host', 'workspace'] as const).flatMap((scope) => [\n {\n id: 'computer.state',\n scope,\n service: 'po.hub',\n member: 'computer_use_state',\n kind: 'channel',\n direction: 'server-to-client',\n description: 'Computer use channel payload.',\n input: Type.Object({\n state: ComputerStateSchema,\n targets: Type.Array(Target),\n busy: O(Type.Literal(true)),\n }),\n },\n {\n id: 'computer.command',\n scope,\n service: 'po.hub',\n member: 'computer_use_state',\n kind: 'channel',\n direction: 'client-to-server',\n description: 'Computer use browser channel command.',\n input: Type.Object({\n action: values(['status', 'targets', 'stop', 'artifacts']),\n }),\n },\n ]),\n});\nexport default apiContracts;\n"],"mappings":";;;AAGA,MAAM,IAAI,KAAK,OAAO;AACtB,MAAM,IAAI,KAAK,OAAO;AACtB,MAAM,IAAI,KAAK;AACf,MAAM,UAA4B,UAAe,KAAK,MAAM,MAAM,KAAK,SAAS,KAAK,QAAQ,IAAI,CAAC,CAAC;AACnG,MAAM,OAAO,KAAK,QAAQ,EACxB,aACE,uHACJ,CAAC;AACD,MAAM,SAAS,KAAK,OAAO,GAAG,IAAI;AAClC,MAAM,QAAQ,KAAK,OAAO;CAAE,MAAM;CAAG,SAAS;AAAE,CAAC;AAC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M;EACN,WAAW;EACX,aAAa;EACb,OAAO,KAAK,OAAO;GACjB,OAAO;GACP,SAAS,KAAK,MAAM,MAAM;GAC1B,MAAM,EAAE,KAAK,QAAQ,IAAI,CAAC;EAC5B,CAAC;CACH,GACA;EACE,IAAI;EACJ;EACA,SAAS;EACT,QAAQ;EACR,MAAM;EACN,WAAW;EACX,aAAa;EACb,OAAO,KAAK,OAAO,EACjB,QAAQ,OAAO;GAAC;GAAU;GAAW;GAAQ;EAAW,CAAC,EAC3D,CAAC;CACH,CACF,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"apiContracts.mjs","names":[],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses, type PoHttpContract } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nconst S = Type.String();\nconst N = Type.Number();\nconst O = Type.Optional;\nconst values = <T extends string>(items: T[]) => Type.Union(items.map((item) => Type.Literal(item)));\nconst Json = Type.Unknown({\n description:\n 'Desktop provider JSON value. Targets, observations and action results are supplied by the admitted Desktop provider.',\n});\nconst Target = Type.Record(S, Json);\nconst Error = Type.Object({ code: S, message: S });\nconst Artifact = Type.Object({\n artifactId: S,\n status: values(['ready', 'failed']),\n sizeBytes: O(N),\n downloadUrl: O(S),\n previewUrl: O(S),\n actionCount: O(N),\n completedAt: O(S),\n failure: O(Error),\n});\nexport const ComputerStateSchema = Type.Object({\n sessionId: S,\n revision: N,\n wake: N,\n phase: values(['inactive', 'awaiting_confirmation', 'activating', 'active', 'stopping', 'failed']),\n requestId: O(S),\n target: O(Target),\n durationMs: O(N),\n expiresAt: O(N),\n failure: O(Error),\n artifact: O(Artifact),\n});\nconst Permission = values(['accessibility', 'screen-recording', 'microphone', 'automation', 'full-disk-access']);\nconst PermissionState = values(['granted', 'denied', 'not-determined', 'per-app']);\nexport const DesktopPermissionStatesSchema = Type.Object({\n accessibility: PermissionState,\n 'screen-recording': PermissionState,\n microphone: PermissionState,\n automation: PermissionState,\n 'full-disk-access': PermissionState,\n});\nconst Reference = {\n snapshotId: Type.String({ minLength: 1 }),\n elementRef: Type.String({ minLength: 1 }),\n};\nexport const ComputerActionSchema = Type.Union([\n Type.Object(\n { kind: values(['press', 'focus', 'expand', 'collapse', 'toggle', 'check', 'uncheck', 'scroll_to']), ...Reference },\n { additionalProperties: false },\n ),\n Type.Object({ kind: values(['set_value', 'select']), ...Reference, value: S }, { additionalProperties: false }),\n Type.Object({ kind: Type.Literal('type'), ...Reference, text: S }, { additionalProperties: false }),\n Type.Object(\n {\n kind: Type.Literal('scroll'),\n ...Reference,\n direction: values(['up', 'down', 'left', 'right']),\n amount: Type.Union([values(['line', 'page']), Type.Integer({ minimum: 1, maximum: 100 })]),\n },\n { additionalProperties: false },\n ),\n]);\nconst internal = (\n method: 'GET' | 'POST',\n path: string,\n output: object,\n body?: object,\n status = 200,\n): PoHttpContract => ({\n id: `computer.${path.slice(1).replaceAll('/', '.')}`,\n scope: 'session',\n basePath: 'computer-use',\n path,\n method,\n authentication: 'owner',\n description: `Computer use broker ${path}. Requires the host-issued ${path.startsWith('/agent/') ? 'agent' : 'hub'} bearer token.`,\n availability: 'Internal broker route; ordinary browser credentials are insufficient.',\n parameters: [\n {\n name: 'Authorization',\n in: 'header',\n required: true,\n schema: Type.String({ pattern: '^Bearer .+' }),\n },\n ],\n ...(body\n ? {\n body: { required: true, contentType: 'application/json', schema: body },\n }\n : {}),\n responses: jsonApiResponses(output, status),\n});\nexport const apiContracts = defineApiContract({\n version: 1,\n dynamic: ['Desktop provider target extensions, observations and operation results are runtime-defined JSON.'],\n http: [\n ...(['host', 'workspace', 'session'] as const).flatMap((scope) =>\n (['GET', 'POST'] as const).map((method) => ({\n id: `computer.permissions.${method === 'GET' ? 'read' : 'request'}`,\n scope,\n basePath: 'desktop-permissions',\n path: '/',\n method,\n authentication: 'owner' as const,\n description:\n method === 'GET'\n ? 'Read the Mac-owned permission states. Requires an authorized local Desktop caller or trusted remote caller.'\n : 'Ask macOS for one named permission. Requires an authorized local Desktop caller or remote passkey step-up.',\n availability: 'Requires Po Desktop to be running this server; otherwise returns 404.',\n ...(method === 'POST'\n ? {\n body: {\n required: true,\n contentType: 'application/json',\n schema: Type.Object({ permission: Permission }),\n },\n }\n : {}),\n responses: {\n ...jsonApiResponses(DesktopPermissionStatesSchema),\n '502': {\n description: 'Desktop permission request failed.',\n schema: Type.Object({ error: S }),\n },\n },\n })),\n ),\n {\n id: 'computer.artifact',\n scope: 'session',\n basePath: 'computer-use',\n path: '/artifact',\n method: 'GET',\n authentication: 'owner',\n description: 'Read at most 1 MiB of a recording belonging to this session and approved caller.',\n parameters: [\n { name: 'artifactId', in: 'query', required: true, schema: S },\n {\n name: 'offset',\n in: 'query',\n required: true,\n schema: Type.Integer({ minimum: 0 }),\n },\n ],\n responses: {\n 206: {\n description: 'Bounded recording bytes.',\n contentType: 'video/mp4',\n schema: Type.String({ format: 'binary' }),\n },\n },\n },\n internal('GET', '/agent/state', ComputerStateSchema),\n internal('GET', '/hub/state', ComputerStateSchema),\n internal('POST', '/hub/request-stop', ComputerStateSchema, undefined, 202),\n internal('POST', '/agent/observe', Json),\n internal('POST', '/agent/action', Json, ComputerActionSchema),\n internal('POST', '/agent/stop', ComputerStateSchema, undefined, 202),\n internal(\n 'GET',\n '/hub/activation',\n Type.Union([\n Type.Null(),\n Type.Object({\n requestId: S,\n target: Target,\n durationSeconds: N,\n createdAt: N,\n confirmationExpiresAt: N,\n caller: Type.Object({\n locality: values(['local', 'remote']),\n stepUp: S,\n }),\n }),\n ]),\n ),\n internal('GET', '/hub/authorization', Type.Union([Type.Null(), Type.Object({ grantId: S, expiresAt: O(N) })])),\n internal(\n 'GET',\n '/hub/next',\n Type.Union([\n Type.Null(),\n Type.Object({\n id: S,\n operation: values(['observe', 'act']),\n payload: O(Json),\n grantId: S,\n sequence: O(N),\n }),\n ]),\n ),\n internal('POST', '/hub/complete', ComputerStateSchema, Type.Object({ id: S, error: O(S), result: O(Json) })),\n internal(\n 'POST',\n '/hub/stop',\n ComputerStateSchema,\n Type.Object({\n error: O(S),\n host: O(Type.Object({ grantId: S, expiresAt: N })),\n artifact: O(Artifact),\n }),\n ),\n ],\n sockets: (['host', 'workspace'] as const).flatMap((scope) => [\n {\n id: 'computer.state',\n scope,\n service: 'po.hub',\n member: 'computer_use_state',\n kind: 'channel',\n direction: 'server-to-client',\n description: 'Computer use channel payload.',\n input: Type.Object({\n state: ComputerStateSchema,\n targets: Type.Array(Target),\n busy: O(Type.Literal(true)),\n }),\n },\n {\n id: 'computer.command',\n scope,\n service: 'po.hub',\n member: 'computer_use_state',\n kind: 'channel',\n direction: 'client-to-server',\n description: 'Computer use browser channel command.',\n input: Type.Object({\n action: values(['status', 'targets', 'stop', 'artifacts']),\n }),\n },\n ]),\n});\nexport default apiContracts;\n"],"mappings":";;;AAGA,MAAM,IAAI,KAAK,OAAO;AACtB,MAAM,IAAI,KAAK,OAAO;AACtB,MAAM,IAAI,KAAK;AACf,MAAM,UAA4B,UAAe,KAAK,MAAM,MAAM,KAAK,SAAS,KAAK,QAAQ,IAAI,CAAC,CAAC;AACnG,MAAM,OAAO,KAAK,QAAQ,EACxB,aACE,uHACJ,CAAC;AACD,MAAM,SAAS,KAAK,OAAO,GAAG,IAAI;AAClC,MAAM,QAAQ,KAAK,OAAO;CAAE,MAAM;CAAG,SAAS;AAAE,CAAC;AACjD,MAAM,WAAW,KAAK,OAAO;CAC3B,YAAY;CACZ,QAAQ,OAAO,CAAC,SAAS,QAAQ,CAAC;CAClC,WAAW,EAAE,CAAC;CACd,aAAa,EAAE,CAAC;CAChB,YAAY,EAAE,CAAC;CACf,aAAa,EAAE,CAAC;CAChB,aAAa,EAAE,CAAC;CAChB,SAAS,EAAE,KAAK;AAClB,CAAC;AACD,MAAa,sBAAsB,KAAK,OAAO;CAC7C,WAAW;CACX,UAAU;CACV,MAAM;CACN,OAAO,OAAO;EAAC;EAAY;EAAyB;EAAc;EAAU;EAAY;CAAQ,CAAC;CACjG,WA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E,SAAS;IAAG,WAAW;GAAE,CAAC,CAAC;GACjD,UAAU,EAAE,QAAQ;EACtB,CAAC,CACH;CACF;CACA,SAAU,CAAC,QAAQ,WAAW,CAAC,CAAW,SAAS,UAAU,CAC3D;EACE,IAAI;EACJ;EACA,SAAS;EACT,QAAQ;EACR,MAAM;EACN,WAAW;EACX,aAAa;EACb,OAAO,KAAK,OAAO;GACjB,OAAO;GACP,SAAS,KAAK,MAAM,MAAM;GAC1B,MAAM,EAAE,KAAK,QAAQ,IAAI,CAAC;EAC5B,CAAC;CACH,GACA;EACE,IAAI;EACJ;EACA,SAAS;EACT,QAAQ;EACR,MAAM;EACN,WAAW;EACX,aAAa;EACb,OAAO,KAAK,OAAO,EACjB,QAAQ,OAAO;GAAC;GAAU;GAAW;GAAQ;EAAW,CAAC,EAC3D,CAAC;CACH,CACF,CAAC;AACH,CAAC"}
@@ -27,12 +27,12 @@ let node_fs_promises = require("node:fs/promises");
27
27
  let node_module = require("node:module");
28
28
  let node_crypto = require("node:crypto");
29
29
  let _agimon_ai_po_core_inputTemplate = require("@agimon-ai/po-core/inputTemplate");
30
- let _agimon_ai_po_core_packageApi = require("@agimon-ai/po-core/packageApi");
31
30
  //#region src/constants/computerUse.ts
32
31
  const COMPUTER_USE_GUIDANCE = `[COMPUTER USE ACTIVE]
33
32
  Use computer_state before acting and after any action that may change the interface. Use only element refs and snapshot ids returned by computer_state. Use computer_action for one semantic press, focus, set_value, or scroll at a time. Use computer_exec only for a trusted, explicitly allowed local TypeScript script. Never infer coordinates, inspect another application, bypass secure elements, or retry an uncertain outcome. Stop computer use when the task is complete.`;
34
33
  const COMMAND_NAME = "computer-use";
35
34
  const COMMAND_DESCRIPTION = "Inspect or manage the session computer use mode";
35
+ const COMPUTER_USE_REQUEST_TOOL_NAMES = ["computer_targets", "computer_request"];
36
36
  const COMPUTER_USE_TOOL_NAMES = [
37
37
  "computer_state",
38
38
  "computer_action",
@@ -46,7 +46,7 @@ const COMPUTER_USE_RECORDING_MAX_BYTES = 134217728;
46
46
  const COMPUTER_USE_TRACE_MAX_BYTES = 4194304;
47
47
  const COMPUTER_USE_WINDOW_MAX_BYTES = 8388608;
48
48
  const COMPUTER_USE_RECORDING_CHUNK_BYTES = 1048576;
49
- const COMPUTER_USE_CODEMODE_GUIDANCE = "[COMPUTER USE ACTIVE]\nUse computer.state() in exec before acting and after any action that may change the interface. Use only element refs and snapshot ids returned by computer.state(). Never infer coordinates or bypass secure elements. Call computer.stop() when the task is complete. Load codemode-how-to-computer-use for details.";
49
+ const COMPUTER_USE_CODEMODE_GUIDANCE = "[COMPUTER USE ACTIVE]\nUse computer.state() in exec before acting and after any action that may change the interface. Use only element refs and snapshot ids returned by computer.state(). Never infer coordinates or bypass secure elements. Re-observe after a rejected action. Never retry an uncertain action. Call computer.stop() when the task is complete. Load codemode-how-to-computer-use for details.";
50
50
  //#endregion
51
51
  //#region src/services/computerScriptWorker/index.ts
52
52
  /** Source for an isolated child process. Restricted modules execute in QuickJS, not in Node's realm. */
@@ -240,6 +240,12 @@ const API_BASE_PATH = "computer-use";
240
240
  const computerUseChannelType = "computer_use_state";
241
241
  const COMPUTER_USE_MODE_ID = "computer-use";
242
242
  const COMPUTER_USE_STATUS_KEY = "po-computer-use";
243
+ /** The session lengths a person can pick when granting control, up to the maximum. */
244
+ const COMPUTER_USE_DURATION_CHOICES_MS = [
245
+ 3e5,
246
+ 9e5,
247
+ 18e5
248
+ ];
243
249
  const COMPUTER_USE_CONFIRMATION_WINDOW_MS = 12e4;
244
250
  /**
245
251
  * Every path this API answers on, below its mount.
@@ -249,7 +255,6 @@ const COMPUTER_USE_CONFIRMATION_WINDOW_MS = 12e4;
249
255
  * strings, so a route cannot move on one side alone.
250
256
  */
251
257
  const COMPUTER_USE_ROUTES = {
252
- activate: "/activate",
253
258
  artifact: "/artifact",
254
259
  agentState: "/agent/state",
255
260
  agentObserve: "/agent/observe",
@@ -260,7 +265,8 @@ const COMPUTER_USE_ROUTES = {
260
265
  hubAuthorization: "/hub/authorization",
261
266
  hubNext: "/hub/next",
262
267
  hubComplete: "/hub/complete",
263
- hubStop: "/hub/stop"
268
+ hubStop: "/hub/stop",
269
+ hubRequestStop: "/hub/request-stop"
264
270
  };
265
271
  const COMPUTER_USE_WAKE_LIMIT = 1e6;
266
272
  //#endregion
@@ -291,7 +297,7 @@ function isDesktopPermission(value) {
291
297
  * disagreement this file exists to prevent. The dispatcher now reads this
292
298
  * table, so the page, the broker and the hub all resolve one set of strings.
293
299
  *
294
- * Activation, status, cancellation and recording reads are reachable from a browser. The `/agent/` and `/hub/` routes
300
+ * Recording reads can be reached from a browser with recording authorization. The `/agent/` and `/hub/` routes
295
301
  * each demand a host-issued bearer token and answer 404 without one; they are
296
302
  * declared here because they are this API's surface, not because a page calls
297
303
  * them.
@@ -303,21 +309,6 @@ const routes = {
303
309
  query: ["artifactId", "offset"],
304
310
  raw: true
305
311
  },
306
- activationState: {
307
- method: "GET",
308
- path: COMPUTER_USE_ROUTES.activate,
309
- response: void 0
310
- },
311
- cancelActivation: {
312
- method: "DELETE",
313
- path: COMPUTER_USE_ROUTES.activate,
314
- response: void 0
315
- },
316
- activate: {
317
- method: "POST",
318
- path: COMPUTER_USE_ROUTES.activate,
319
- response: void 0
320
- },
321
312
  agentState: {
322
313
  method: "GET",
323
314
  path: COMPUTER_USE_ROUTES.agentState,
@@ -365,6 +356,11 @@ const routes = {
365
356
  path: COMPUTER_USE_ROUTES.hubComplete,
366
357
  response: void 0
367
358
  },
359
+ hubRequestStop: {
360
+ method: "POST",
361
+ path: COMPUTER_USE_ROUTES.hubRequestStop,
362
+ response: void 0
363
+ },
368
364
  hubStop: {
369
365
  method: "POST",
370
366
  path: COMPUTER_USE_ROUTES.hubStop,
@@ -504,6 +500,7 @@ var ComputerUseRequestBroker = class ComputerUseRequestBroker {
504
500
  wake = 0;
505
501
  phase = "inactive";
506
502
  activation;
503
+ usedApprovals = /* @__PURE__ */ new Set();
507
504
  grantId;
508
505
  expiresAt;
509
506
  actionSequence = 0;
@@ -538,6 +535,7 @@ var ComputerUseRequestBroker = class ComputerUseRequestBroker {
538
535
  this.rejectPending("Desktop disconnected.");
539
536
  this.phase = "failed";
540
537
  this.grantId = void 0;
538
+ this.releaseActivation();
541
539
  this.failure = {
542
540
  code: "desktop_unavailable",
543
541
  message: "Desktop disconnected."
@@ -595,7 +593,7 @@ var ComputerUseRequestBroker = class ComputerUseRequestBroker {
595
593
  stop: async (signal) => {
596
594
  signal?.throwIfAborted();
597
595
  this.inputController?.abort();
598
- if (this.phase !== "inactive" && this.phase !== "failed") {
596
+ if (this.phase !== "inactive" && this.phase !== "failed" && this.phase !== "stopping") {
599
597
  this.phase = "stopping";
600
598
  this.rejectPending("Computer use was stopped.");
601
599
  this.changed();
@@ -614,29 +612,16 @@ var ComputerUseRequestBroker = class ComputerUseRequestBroker {
614
612
  authorized(request, token) {
615
613
  return token !== void 0 && request.headers.get("authorization") === `Bearer ${token}`;
616
614
  }
617
- async requestActivation(request) {
618
- if (!this.desktop?.available || !(this.desktop.authorizeActivation?.(request.headers) ?? this.desktop.authorize(request.headers))) return jsonError("Not found.", 404);
619
- if (this.desktop.enabled === false) return jsonError("Enable computer use in global Desktop settings first.", 409);
620
- const stamped = (0, _agimon_ai_po_core_packageApi.poApiCallerFrom)(request.headers);
621
- const caller = stamped?.locality === "remote" ? stamped : {
622
- locality: "local",
623
- stepUp: "not-required"
624
- };
625
- if (this.phase !== "inactive" && this.phase !== "failed") return jsonError("Computer use is already busy.", 409);
626
- const input = await body(request);
627
- if (input.confirmed !== true) return jsonError("Approve computer control in the in-app dialog first.", 400);
628
- const target = record(input.target);
629
- const durationMs = input.durationMs;
630
- const desktopTarget = target?.scope === "desktop" && Object.keys(target).length === 1;
631
- if (target === void 0 || !desktopTarget && (typeof target.windowId !== "string" || typeof target.bundleId !== "string")) return jsonError("An explicit application window or whole-desktop target is required.", 400);
632
- if (typeof durationMs !== "number" || !Number.isInteger(durationMs) || durationMs < 1e3 || durationMs > 18e5) return jsonError("The requested duration is invalid.", 400);
633
- try {
634
- this.desktop.claim(request.headers);
635
- await this.beforeActivate?.();
636
- } catch (error) {
637
- return jsonError(error instanceof Error ? error.message : String(error), 409);
638
- }
639
- if (this.closed || !this.desktop.available || this.phase !== "inactive" && this.phase !== "failed") return jsonError("Computer use is unavailable or already busy.", 409);
615
+ /** Only called by the in-process approved-operation handler. There is no HTTP activation route. */
616
+ activateApproved(approvalId, target, durationMs, traceConsent) {
617
+ if (this.closed || !this.desktop?.available || !this.desktop.claimApproved || this.desktop.enabled === false) throw new Error("Desktop computer use is unavailable.");
618
+ if (this.sensitiveInput) throw new Error("Computer use is sealed after sensitive input.");
619
+ if (this.phase !== "inactive" && this.phase !== "failed") throw new Error("Computer use is already busy.");
620
+ if (!approvalId || this.usedApprovals.has(approvalId)) throw new Error("This computer-use approval has already been used.");
621
+ if (!COMPUTER_USE_DURATION_CHOICES_MS.some((duration) => duration === durationMs)) throw new Error("The requested duration is invalid.");
622
+ this.beforeActivate?.();
623
+ this.desktop.claimApproved(approvalId);
624
+ this.usedApprovals.add(approvalId);
640
625
  const createdAt = Date.now();
641
626
  this.activation = Object.freeze({
642
627
  requestId: (0, node_crypto.randomUUID)(),
@@ -645,14 +630,21 @@ var ComputerUseRequestBroker = class ComputerUseRequestBroker {
645
630
  createdAt,
646
631
  confirmationExpiresAt: createdAt + COMPUTER_USE_CONFIRMATION_WINDOW_MS,
647
632
  confirmedAt: createdAt,
648
- traceConsent: input.traceConsent === true && !desktopTarget,
649
- caller: Object.freeze({ ...caller })
633
+ traceConsent: traceConsent && target.scope !== "desktop",
634
+ caller: Object.freeze({
635
+ locality: "approval",
636
+ approvalId
637
+ })
650
638
  });
651
639
  this.phase = "awaiting_confirmation";
652
640
  this.failure = void 0;
653
641
  this.artifact = void 0;
654
642
  this.changed();
655
- return Response.json(this.state(), { status: 202 });
643
+ return this.state();
644
+ }
645
+ releaseActivation() {
646
+ if (this.activation) this.desktop?.releaseApproved?.(this.activation.caller.approvalId);
647
+ this.activation = void 0;
656
648
  }
657
649
  rejectPending(message) {
658
650
  const pending = this.pending;
@@ -766,19 +758,6 @@ var ComputerUseRequestBroker = class ComputerUseRequestBroker {
766
758
  if (!/^[0-9]+$/u.test(offsetText) || !Number.isSafeInteger(offset) || offset < 0 || offset > 134217728) return jsonError("Invalid recording offset.", 400);
767
759
  return this.desktop.fetchRecording(artifactId, `bytes=${offset}-${offset + 1048576 - 1}`);
768
760
  }
769
- if (path === routes.activate.path && request.method === "GET") {
770
- if (!this.desktop?.authorizePending?.(request.headers) && !(this.desktop?.authorizeRecording?.(request.headers) ?? this.desktop?.authorize(request.headers))) return jsonError("Not found.", 404);
771
- return Response.json(this.state());
772
- }
773
- if (path === routes.activate.path && request.method === "DELETE") {
774
- if (!this.desktop?.authorizePending?.(request.headers)) return jsonError("Not found.", 404);
775
- if (this.phase !== "awaiting_confirmation" && this.phase !== "activating") return jsonError("No activation is pending.", 409);
776
- this.phase = "stopping";
777
- this.rejectPending("The activation was cancelled.");
778
- this.changed();
779
- return Response.json(this.state(), { status: 202 });
780
- }
781
- if (request.method === "POST" && path === routes.activate.path) return this.requestActivation(request);
782
761
  const agent = path.startsWith("/agent/");
783
762
  const hub = path.startsWith("/hub/");
784
763
  if (agent && !this.authorized(request, this.internalToken) || hub && !this.authorized(request, this.hubToken)) return jsonError("Not found.", 404);
@@ -789,12 +768,8 @@ var ComputerUseRequestBroker = class ComputerUseRequestBroker {
789
768
  if (!semanticAction(action)) return jsonError("A valid semantic action is required.", 400);
790
769
  return this.performAction(action, request.signal);
791
770
  }
792
- if (request.method === "POST" && path === routes.agentStop.path) {
793
- this.inputController?.abort();
794
- if (this.phase !== "active") return jsonError("Computer use is not active.", 409);
795
- this.phase = "stopping";
796
- this.rejectPending("The computer-use request was stopped.");
797
- this.changed();
771
+ if (request.method === "POST" && (path === routes.agentStop.path || path === routes.hubRequestStop.path)) {
772
+ await this.sessionClient().stop();
798
773
  return Response.json(this.state(), { status: 202 });
799
774
  }
800
775
  if (request.method === "GET" && path === routes.hubActivation.path) {
@@ -816,7 +791,7 @@ var ComputerUseRequestBroker = class ComputerUseRequestBroker {
816
791
  this.pending = void 0;
817
792
  pending.dispose();
818
793
  if (typeof input.error === "string") {
819
- this.phase = "stopping";
794
+ if (input.code !== "unsupported_action" && input.code !== "stale_request") this.phase = "stopping";
820
795
  pending.reject(new Error(input.error));
821
796
  } else pending.resolve(input.result);
822
797
  this.changed();
@@ -832,7 +807,7 @@ var ComputerUseRequestBroker = class ComputerUseRequestBroker {
832
807
  code: "desktop_unavailable",
833
808
  message: input.error.slice(0, 512)
834
809
  };
835
- this.activation = void 0;
810
+ this.releaseActivation();
836
811
  } else {
837
812
  const host = record(input.host);
838
813
  if (typeof host?.grantId !== "string" || !Number.isFinite(host.expiresAt) || host.expiresAt <= Date.now()) return jsonError("Desktop did not issue a complete grant.", 502);
@@ -856,13 +831,14 @@ var ComputerUseRequestBroker = class ComputerUseRequestBroker {
856
831
  }, Math.max(0, this.expiresAt - Date.now()));
857
832
  this.expiryTimer.unref?.();
858
833
  }
859
- } else {
834
+ } else if (this.phase === "stopping" && typeof record(input.host)?.grantId === "string") this.grantId = record(input.host).grantId;
835
+ else {
860
836
  clearTimeout(this.expiryTimer);
861
837
  this.rejectPending("The computer-use session stopped.");
862
838
  this.phase = "inactive";
863
839
  this.grantId = void 0;
864
840
  this.expiresAt = void 0;
865
- this.activation = void 0;
841
+ this.releaseActivation();
866
842
  this.nativeTarget = void 0;
867
843
  this.artifact = artifactView(input.artifact) ?? this.artifact;
868
844
  }
@@ -1179,6 +1155,12 @@ Object.defineProperty(exports, "COMPUTER_USE_RECORDING_MAX_BYTES", {
1179
1155
  return COMPUTER_USE_RECORDING_MAX_BYTES;
1180
1156
  }
1181
1157
  });
1158
+ Object.defineProperty(exports, "COMPUTER_USE_REQUEST_TOOL_NAMES", {
1159
+ enumerable: true,
1160
+ get: function() {
1161
+ return COMPUTER_USE_REQUEST_TOOL_NAMES;
1162
+ }
1163
+ });
1182
1164
  Object.defineProperty(exports, "COMPUTER_USE_ROUTES", {
1183
1165
  enumerable: true,
1184
1166
  get: function() {
@@ -1258,4 +1240,4 @@ Object.defineProperty(exports, "routes", {
1258
1240
  }
1259
1241
  });
1260
1242
 
1261
- //# sourceMappingURL=extensionService-C2-nz6jL.cjs.map
1243
+ //# sourceMappingURL=extensionService-BKBTsnkI.cjs.map