@workser/runtime 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -2
  3. package/dist/cjs/client/follow.js +103 -0
  4. package/dist/cjs/client/index.js +6 -0
  5. package/dist/cjs/contract/actions.js +223 -0
  6. package/dist/cjs/contract/catalog.js +335 -0
  7. package/dist/cjs/contract/index.js +20 -0
  8. package/dist/cjs/contract/ordered-feed.js +94 -0
  9. package/dist/cjs/contract/types.js +9 -0
  10. package/dist/cjs/engine/engine.js +2 -0
  11. package/dist/cjs/index.js +27 -0
  12. package/dist/cjs/internal/async-queue.js +56 -0
  13. package/dist/cjs/internal/sse.js +170 -0
  14. package/dist/cjs/package.json +1 -0
  15. package/dist/cjs/place/place.js +2 -0
  16. package/dist/cjs/runner/index.js +6 -0
  17. package/dist/cjs/runner/journal.js +82 -0
  18. package/dist/cjs/runner/runner-client.js +477 -0
  19. package/dist/client/follow.d.ts +45 -0
  20. package/dist/client/follow.js +100 -0
  21. package/dist/client/follow.js.map +1 -0
  22. package/dist/client/index.d.ts +1 -0
  23. package/dist/client/index.js +2 -0
  24. package/dist/client/index.js.map +1 -0
  25. package/dist/contract/actions.d.ts +73 -0
  26. package/dist/contract/actions.js +217 -0
  27. package/dist/contract/actions.js.map +1 -0
  28. package/dist/contract/catalog.d.ts +97 -0
  29. package/dist/contract/catalog.js +328 -0
  30. package/dist/contract/catalog.js.map +1 -0
  31. package/dist/contract/index.d.ts +4 -0
  32. package/dist/contract/index.js +5 -0
  33. package/dist/contract/index.js.map +1 -0
  34. package/dist/contract/ordered-feed.d.ts +56 -0
  35. package/dist/contract/ordered-feed.js +91 -0
  36. package/dist/contract/ordered-feed.js.map +1 -0
  37. package/dist/contract/types.d.ts +311 -0
  38. package/dist/contract/types.js +9 -0
  39. package/dist/contract/types.js.map +1 -0
  40. package/dist/engine/engine.d.ts +39 -0
  41. package/dist/engine/engine.js +2 -0
  42. package/dist/engine/engine.js.map +1 -0
  43. package/dist/index.d.ts +10 -0
  44. package/dist/index.js +9 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/internal/async-queue.d.ts +14 -0
  47. package/dist/internal/async-queue.js +53 -0
  48. package/dist/internal/async-queue.js.map +1 -0
  49. package/dist/internal/sse.d.ts +57 -0
  50. package/dist/internal/sse.js +164 -0
  51. package/dist/internal/sse.js.map +1 -0
  52. package/dist/place/place.d.ts +81 -0
  53. package/dist/place/place.js +2 -0
  54. package/dist/place/place.js.map +1 -0
  55. package/dist/runner/index.d.ts +2 -0
  56. package/dist/runner/index.js +2 -0
  57. package/dist/runner/index.js.map +1 -0
  58. package/dist/runner/journal.d.ts +32 -0
  59. package/dist/runner/journal.js +79 -0
  60. package/dist/runner/journal.js.map +1 -0
  61. package/dist/runner/runner-client.d.ts +185 -0
  62. package/dist/runner/runner-client.js +473 -0
  63. package/dist/runner/runner-client.js.map +1 -0
  64. package/package.json +30 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Workser
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,72 @@
1
- # Temporary Holding Version
1
+ # @workser/runtime
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The run contract every Workser runner, screen and service speaks.
4
+
5
+ - **`@workser/runtime/contract`**: the run event catalog, with its checks and the resume-order rules (`OrderedFeed`), plus the types for briefs, commands, asks, handoffs, artifacts, checks and usage. core-api keeps a generated copy of the catalog and feed (`npm run sync:core-api`), so the server and every client agree on what an event is.
6
+ - **`@workser/runtime/runner`**: `RunnerClient`, for a Workser runner driving one run from a desktop, a sandbox or a cloud computer.
7
+ - **`@workser/runtime/client`**: `followRun` and `followProject`, for screens that watch runs live.
8
+ - **`Place` and `Engine`**: the interfaces a runner plugs together. The *place* is where the work happens; the *engine* is the AI agent loop.
9
+
10
+ It has no runtime dependencies and runs in Node 18+ and in browsers. It uses its own server-sent events (SSE) parser over `fetch`, not `EventSource`, because `EventSource` can't send a token.
11
+
12
+ ## Runner protocol v1
13
+
14
+ 1. **Attach.** Someone who can see the run calls `POST /v1/runs/:id/runner` with `{ place, lane }`. Our own services call `POST /v1/internal/runs/:id/runner` instead. The reply carries a `wsrn_` token, shown once. The token works for this one run only, and stops working when the run ends.
15
+ 2. **Brief.** `GET /v1/runner/runs/:id` returns the job and its cursors. Events are numbered from `cursors.runner_seq + 1`.
16
+ 3. **Commands.** `GET /v1/runner/runs/:id/commands` streams stop, pause, resume, answers and decisions. Reconnect with `?after=<last pos>`. On a first connect, the stream starts at the oldest command not yet acked.
17
+ 4. **Events.** `POST /v1/runner/runs/:id/events` with `{ events: [{ event_id, seq, type, data }] }`, up to 100 per call.
18
+ - `seq` numbers must follow each other with no gaps.
19
+ - Resending events that were already stored is safe.
20
+ - On a gap, core-api answers `409 { error: { code: 'event_gap', expected } }`. Resend from `expected`.
21
+ 5. **Heartbeat.** Send `POST …/heartbeat` about every 10 s. After three minutes of silence, core-api closes the run as `runner_lost`.
22
+ 6. **Asks and acks.**
23
+ - `POST …/asks` sends `{ kind: 'question' | 'permission' | 'spend', title, message, choices? }`. The owner's answer arrives as a command.
24
+ - Ack each command with `POST …/commands/:pos/ack` once you've acted on it.
25
+ 7. **Rotate.** For a long job, `POST …/token/rotate` returns a fresh token, and the old one stops working.
26
+ 8. **End.** Send `run.completed`, `run.failed` or `run.cancelled`. The token stops working.
27
+
28
+ `RunnerClient` does steps 2–8 for you: numbering, batching (150 ms, or at once for `run.*` events), retries with backoff, resending after a gap, heartbeats, command resume and acks, and token rotation.
29
+
30
+ ## Example runner
31
+
32
+ ```ts
33
+ import { RunnerClient } from '@workser/runtime/runner';
34
+
35
+ const runner = new RunnerClient({
36
+ baseUrl: 'https://api.workser.ai',
37
+ runId: process.env.WORKSER_RUN_ID!,
38
+ token: process.env.WORKSER_RUNNER_TOKEN!,
39
+ onError: (error) => console.error(error.message),
40
+ });
41
+
42
+ const brief = await runner.start();
43
+ let stopped = false;
44
+ void runner.commands(async (command) => {
45
+ if (command.kind === 'cancel') stopped = true;
46
+ });
47
+
48
+ runner.emit('run.started', { engine: 'example', place: 'sandbox' });
49
+ runner.emit('step.started', { step_id: 's1', title: 'Run the tests' });
50
+ // … do the work, through a Place …
51
+ runner.emit('step.completed', { step_id: 's1', status: 'ok' });
52
+ runner.emit('check.result', { name: 'tests', status: 'pass' });
53
+
54
+ if (stopped) await runner.finish('run.cancelled', { reason: 'Stopped by the owner' });
55
+ else await runner.finish('run.completed', { summary: `Did: ${String(brief.run.input.task ?? 'the job')}` });
56
+ ```
57
+
58
+ ## Watching a run
59
+
60
+ ```ts
61
+ import { followRun } from '@workser/runtime/client';
62
+
63
+ for await (const event of followRun({ baseUrl, runId, headers: { Authorization: `Bearer ${key}` } })) {
64
+ render(event); // in order, once each; resumes after the last position on every reconnect
65
+ }
66
+ ```
67
+
68
+ ## Working on this package
69
+
70
+ - `npm test`: runs the tests with Node's test runner, with no network.
71
+ - `npm run sync:core-api`: rewrites core-api's generated copies after any change to `src/contract/catalog.ts` or `src/contract/ordered-feed.ts`. A test fails when the copies drift.
72
+ # workser-runtime-sdk
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.followRun = followRun;
4
+ exports.followProject = followProject;
5
+ const catalog_js_1 = require("../contract/catalog.js");
6
+ const async_queue_js_1 = require("../internal/async-queue.js");
7
+ const sse_js_1 = require("../internal/sse.js");
8
+ /**
9
+ * One run's events, in order, once each, surviving drops: every reconnect
10
+ * resumes after the last position seen, and anything at or before it is
11
+ * dropped. Ends after the run's terminal event.
12
+ *
13
+ * for await (const event of followRun({ baseUrl, runId, headers })) { … }
14
+ */
15
+ function followRun(options) {
16
+ const base = options.baseUrl.replace(/\/+$/, '');
17
+ const abort = new AbortController();
18
+ options.signal?.addEventListener('abort', () => abort.abort(), { once: true });
19
+ const queue = new async_queue_js_1.AsyncQueue(() => abort.abort());
20
+ let last = Math.max(0, options.after ?? 0);
21
+ const url = options.url ??
22
+ ((after) => `${base}/v1/runs/${encodeURIComponent(options.runId)}/events${after > 0 ? `?after=${after}` : '?after=0'}`);
23
+ void (0, sse_js_1.connectSse)({
24
+ fetch: options.fetch ?? ((input, init) => fetch(input, init)),
25
+ signal: abort.signal,
26
+ url: () => url(last),
27
+ headers: () => options.headers ?? {},
28
+ onMessage: (message) => {
29
+ if (message.event === 'heartbeat')
30
+ return;
31
+ let frame;
32
+ try {
33
+ frame = JSON.parse(message.data);
34
+ }
35
+ catch {
36
+ return;
37
+ }
38
+ if (typeof frame.pos !== 'number' || frame.pos <= last)
39
+ return;
40
+ last = frame.pos;
41
+ queue.push(frame);
42
+ if (catalog_js_1.TERMINAL_EVENT_TYPES.has(frame.type)) {
43
+ queue.end();
44
+ abort.abort();
45
+ }
46
+ },
47
+ onError: (error) => {
48
+ options.onError?.(error);
49
+ },
50
+ }).then(() => queue.end(), (error) => queue.end(error));
51
+ return queue;
52
+ }
53
+ /**
54
+ * A project's runs, live: a `snapshot` on every (re)connect, then
55
+ * `summary` items. A summary at or before the position its run already
56
+ * showed is dropped, so a reconnect never repeats one.
57
+ */
58
+ function followProject(options) {
59
+ const base = options.baseUrl.replace(/\/+$/, '');
60
+ const abort = new AbortController();
61
+ options.signal?.addEventListener('abort', () => abort.abort(), { once: true });
62
+ const queue = new async_queue_js_1.AsyncQueue(() => abort.abort());
63
+ const seen = new Map();
64
+ void (0, sse_js_1.connectSse)({
65
+ fetch: options.fetch ?? ((input, init) => fetch(input, init)),
66
+ signal: abort.signal,
67
+ url: options.url ??
68
+ (() => `${base}/v1/projects/${encodeURIComponent(options.projectId)}/runs/stream`),
69
+ headers: () => options.headers ?? {},
70
+ onMessage: (message) => {
71
+ if (message.event === 'heartbeat')
72
+ return;
73
+ let data;
74
+ try {
75
+ data = JSON.parse(message.data);
76
+ }
77
+ catch {
78
+ return;
79
+ }
80
+ if (message.event === 'snapshot') {
81
+ const snapshot = data;
82
+ for (const run of snapshot.runs ?? []) {
83
+ seen.set(run.id, Math.max(seen.get(run.id) ?? 0, Number(run.event_pos) || 0));
84
+ }
85
+ queue.push({ type: 'snapshot', snapshot });
86
+ return;
87
+ }
88
+ if (message.event === 'run.summary') {
89
+ const summary = data;
90
+ if (typeof summary.pos !== 'number')
91
+ return;
92
+ if (summary.pos <= (seen.get(summary.run_id) ?? 0))
93
+ return;
94
+ seen.set(summary.run_id, summary.pos);
95
+ queue.push({ type: 'summary', summary });
96
+ }
97
+ },
98
+ onError: (error) => {
99
+ options.onError?.(error);
100
+ },
101
+ }).then(() => queue.end(), (error) => queue.end(error));
102
+ return queue;
103
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.followProject = exports.followRun = void 0;
4
+ var follow_js_1 = require("./follow.js");
5
+ Object.defineProperty(exports, "followRun", { enumerable: true, get: function () { return follow_js_1.followRun; } });
6
+ Object.defineProperty(exports, "followProject", { enumerable: true, get: function () { return follow_js_1.followProject; } });
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COMPUTER_TOOL_ALIASES = exports.COMPUTER_ACTION_IDS = exports.COMPUTER_ACTIONS = exports.ACTION_PLACES = void 0;
4
+ exports.computerToolName = computerToolName;
5
+ exports.resolveComputerTool = resolveComputerTool;
6
+ exports.normalizeActionInput = normalizeActionInput;
7
+ exports.runsWithoutOwnerScreen = runsWithoutOwnerScreen;
8
+ exports.ACTION_PLACES = ['desktop', 'cloud_computer', 'cloud_browser'];
9
+ const obj = (properties, required = []) => ({
10
+ type: 'object',
11
+ properties,
12
+ ...(required.length ? { required } : {}),
13
+ additionalProperties: false,
14
+ });
15
+ const str = (description) => ({ type: 'string', description });
16
+ const num = (description) => ({ type: 'number', description });
17
+ /** What to act on: an element id from the last look/read, or its words. */
18
+ const TARGET = str('The element to act on: its id from the last look or read, or its visible label');
19
+ const APP = str('The app it is in (the owner\'s computer); omit for the front window');
20
+ const ALL = ['desktop', 'cloud_computer', 'cloud_browser'];
21
+ exports.COMPUTER_ACTIONS = {
22
+ open_app: {
23
+ id: 'open_app', description: 'Open an app, or bring it forward.', places: ['desktop', 'cloud_computer'],
24
+ side_effect: true, background: true, input_schema: obj({ app: str('The app\'s name'), target: str('A file or address to open in it') }, ['app']),
25
+ },
26
+ open_url: {
27
+ id: 'open_url', description: 'Open a web address.', places: ALL,
28
+ side_effect: true, background: true, input_schema: obj({ url: str('The address') }, ['url']),
29
+ },
30
+ click: {
31
+ id: 'click', description: 'Click an element.', places: ['desktop', 'cloud_browser'],
32
+ side_effect: true, background: true, input_schema: obj({ target: TARGET, app: APP, double: { type: 'boolean' }, right: { type: 'boolean' } }, ['target']),
33
+ },
34
+ click_at: {
35
+ id: 'click_at', description: 'Click a point on the screen.', places: ['desktop', 'cloud_computer'],
36
+ // A point is on the screen: behind the owner's windows it has no meaning.
37
+ side_effect: true, background: false, input_schema: obj({ x: num('Pixels from the left'), y: num('Pixels from the top'), double: { type: 'boolean' } }, ['x', 'y']),
38
+ },
39
+ type: {
40
+ id: 'type', description: 'Type text, into an element or where the cursor is.', places: ALL,
41
+ side_effect: true, background: true, input_schema: obj({ text: str('What to type'), target: TARGET, app: APP, submit: { type: 'boolean', description: 'Press Enter after' } }, ['text']),
42
+ },
43
+ set_value: {
44
+ id: 'set_value', description: 'Set a field\'s value directly.', places: ['desktop', 'cloud_browser'],
45
+ side_effect: true, background: true, input_schema: obj({ target: TARGET, value: str('The value'), app: APP }, ['target', 'value']),
46
+ },
47
+ press: {
48
+ id: 'press', description: 'Press keys together, like ["cmd", "s"].', places: ALL,
49
+ side_effect: true, background: true, input_schema: obj({ keys: { type: 'array', items: { type: 'string' }, minItems: 1 }, app: APP }, ['keys']),
50
+ },
51
+ scroll: {
52
+ id: 'scroll', description: 'Scroll a window or element.', places: ALL,
53
+ side_effect: false, background: true,
54
+ input_schema: obj({ direction: { type: 'string', enum: ['up', 'down', 'left', 'right'] }, amount: { type: 'number', minimum: 1, maximum: 20 }, target: TARGET, app: APP }, ['direction']),
55
+ },
56
+ select: {
57
+ id: 'select', description: 'Choose an option in a list.', places: ['desktop', 'cloud_browser'],
58
+ side_effect: true, background: true, input_schema: obj({ target: TARGET, value: str('The option'), app: APP }, ['target', 'value']),
59
+ },
60
+ hover: {
61
+ id: 'hover', description: 'Point at an element without clicking.', places: ['desktop'],
62
+ side_effect: false, background: true, input_schema: obj({ target: TARGET, app: APP }, ['target']),
63
+ },
64
+ drag: {
65
+ id: 'drag', description: 'Drag from one element or point to another.', places: ['desktop'],
66
+ side_effect: true, background: true, input_schema: obj({ from: TARGET, to: TARGET, app: APP }, ['from', 'to']),
67
+ },
68
+ menu: {
69
+ id: 'menu', description: 'Choose a menu item by its path, like ["File", "Export…"].', places: ['desktop'],
70
+ side_effect: true, background: true, input_schema: obj({ path: { type: 'array', items: { type: 'string' }, minItems: 1 }, app: APP }, ['path']),
71
+ },
72
+ look: {
73
+ id: 'look', description: 'See the screen or one window (a picture).', places: ALL,
74
+ side_effect: false, background: true, input_schema: obj({ app: APP, window: str('Which window') }),
75
+ },
76
+ read: {
77
+ id: 'read', description: 'Read a window\'s or page\'s text and elements.', places: ALL,
78
+ side_effect: false, background: true, input_schema: obj({ app: APP, target: TARGET }),
79
+ },
80
+ wait: {
81
+ id: 'wait', description: 'Wait a few seconds.', places: ALL,
82
+ side_effect: false, background: true, input_schema: obj({ seconds: { type: 'number', minimum: 0, maximum: 60 } }, ['seconds']),
83
+ },
84
+ wait_for: {
85
+ id: 'wait_for', description: 'Wait until something shows up.', places: ['desktop', 'cloud_browser'],
86
+ side_effect: false, background: true, input_schema: obj({ text: str('Words to wait for'), target: TARGET, seconds: { type: 'number', minimum: 1, maximum: 120 } }),
87
+ },
88
+ clipboard_read: {
89
+ id: 'clipboard_read', description: 'Read the clipboard.', places: ['desktop'],
90
+ // The clipboard is the owner's: there is only one, shared with them.
91
+ side_effect: false, background: false, input_schema: obj({}),
92
+ },
93
+ clipboard_write: {
94
+ id: 'clipboard_write', description: 'Put text on the clipboard.', places: ['desktop'],
95
+ side_effect: true, background: false, input_schema: obj({ text: str('The text') }, ['text']),
96
+ },
97
+ fill_secret: {
98
+ id: 'fill_secret', description: 'Type a saved sign-in into the focused field, without seeing it.', places: ['cloud_computer', 'cloud_browser'],
99
+ side_effect: true, background: true,
100
+ input_schema: obj({ name: str('The saved sign-in'), field: { type: 'string', enum: ['username', 'password', 'totp', 'value'] } }, ['name', 'field']),
101
+ },
102
+ record_clip: {
103
+ id: 'record_clip', description: 'Record a short clip of the screen.', places: ['desktop', 'cloud_computer'],
104
+ side_effect: false, background: false, input_schema: obj({ seconds: { type: 'number', minimum: 1, maximum: 120 } }),
105
+ },
106
+ };
107
+ exports.COMPUTER_ACTION_IDS = Object.keys(exports.COMPUTER_ACTIONS);
108
+ const PREFIX = { desktop: 'desktop', cloud_computer: 'computer', cloud_browser: 'browser' };
109
+ /** The tool name a model calls: `computer_click_at`, `browser_open_url`, `desktop_type`. */
110
+ function computerToolName(place, action) {
111
+ return `${PREFIX[place]}_${action}`;
112
+ }
113
+ /** Older names, read as an action at a place. A bare desktop planner step name is read in `resolveComputerTool`. */
114
+ exports.COMPUTER_TOOL_ALIASES = {
115
+ // The cloud computer's names before the list.
116
+ computer_open: { place: 'cloud_computer', action: 'open_app' },
117
+ computer_click: { place: 'cloud_computer', action: 'click_at' },
118
+ computer_screenshot: { place: 'cloud_computer', action: 'look' },
119
+ computer_observe_ax: { place: 'cloud_computer', action: 'read' },
120
+ // The cloud browser (both tool sets).
121
+ browser_open: { place: 'cloud_browser', action: 'open_url' },
122
+ browser_navigate: { place: 'cloud_browser', action: 'open_url' },
123
+ browser_screenshot: { place: 'cloud_browser', action: 'look' },
124
+ browser_get_content: { place: 'cloud_browser', action: 'read' },
125
+ browser_press_keys: { place: 'cloud_browser', action: 'press' },
126
+ browser_fill_form: { place: 'cloud_browser', action: 'set_value' },
127
+ fill_login: { place: 'cloud_browser', action: 'fill_secret' },
128
+ // The desktop: planner steps that are another action's twin, and the local runner.
129
+ look_window: { place: 'desktop', action: 'look' },
130
+ record_session: { place: 'desktop', action: 'record_clip' },
131
+ desktop_see: { place: 'desktop', action: 'look' },
132
+ // Jev's operations (any place).
133
+ CLICK: { place: null, action: 'click' },
134
+ TYPE_TEXT: { place: null, action: 'type' },
135
+ SELECT: { place: null, action: 'select' },
136
+ KEY_PRESS: { place: null, action: 'press' },
137
+ SCROLL_DOWN: { place: null, action: 'scroll' },
138
+ SCROLL_UP: { place: null, action: 'scroll' },
139
+ NAVIGATE: { place: null, action: 'open_url' },
140
+ OPEN_APP: { place: null, action: 'open_app' },
141
+ WAIT: { place: null, action: 'wait' },
142
+ };
143
+ const isAction = (value) => typeof value === 'string' && Object.prototype.hasOwnProperty.call(exports.COMPUTER_ACTIONS, value);
144
+ /**
145
+ * Any name a computer action has gone by, read as one action. `input` is
146
+ * needed only for the local runner's `desktop_action`, which names the
147
+ * action in its arguments. Null: not a computer action (files, shell, apps).
148
+ */
149
+ function resolveComputerTool(name, input) {
150
+ if (typeof name !== 'string' || !name)
151
+ return null;
152
+ if (name === 'desktop_action') {
153
+ const action = input?.action;
154
+ return isAction(action) ? { place: 'desktop', action, alias: true } : null;
155
+ }
156
+ const alias = exports.COMPUTER_TOOL_ALIASES[name];
157
+ if (alias)
158
+ return { ...alias, alias: true };
159
+ for (const place of exports.ACTION_PLACES) {
160
+ const prefix = `${PREFIX[place]}_`;
161
+ if (name.startsWith(prefix)) {
162
+ const action = name.slice(prefix.length);
163
+ if (isAction(action) && exports.COMPUTER_ACTIONS[action].places.includes(place))
164
+ return { place, action, alias: false };
165
+ }
166
+ }
167
+ // A bare id: the desktop planner's own step names are the action ids.
168
+ if (isAction(name))
169
+ return { place: null, action: name, alias: false };
170
+ return null;
171
+ }
172
+ /**
173
+ * Arguments in the list's shape, from any older shape: keys as a string
174
+ * ("cmd+s") or array, Jev's SCROLL_UP/SCROLL_DOWN, `element`/`selector` for
175
+ * the target, `application`/`uri` for an app.
176
+ */
177
+ function normalizeActionInput(action, input, name) {
178
+ const out = { ...(input ?? {}) };
179
+ if (action === 'press' && out.keys !== undefined) {
180
+ const keys = out.keys;
181
+ out.keys = Array.isArray(keys)
182
+ ? keys.map(String)
183
+ : String(keys).split('+').map((one) => one.trim()).filter(Boolean);
184
+ }
185
+ if (action === 'scroll' && out.direction === undefined) {
186
+ if (name === 'SCROLL_UP')
187
+ out.direction = 'up';
188
+ if (name === 'SCROLL_DOWN')
189
+ out.direction = 'down';
190
+ }
191
+ if (out.target === undefined) {
192
+ const element = out.element ?? out.selector;
193
+ if (element !== undefined) {
194
+ out.target = String(element);
195
+ delete out.element;
196
+ delete out.selector;
197
+ }
198
+ }
199
+ if (action === 'open_app') {
200
+ if (out.app === undefined && out.application !== undefined) {
201
+ out.app = out.application;
202
+ delete out.application;
203
+ }
204
+ if (out.target === undefined && out.uri !== undefined) {
205
+ out.target = out.uri;
206
+ delete out.uri;
207
+ }
208
+ }
209
+ if (action === 'open_url' && out.url === undefined && typeof out.target === 'string') {
210
+ out.url = out.target;
211
+ delete out.target;
212
+ }
213
+ return out;
214
+ }
215
+ /**
216
+ * Whether this action can run without the owner's screen at this place. The
217
+ * cloud computer and the cloud browser are never the owner's screen.
218
+ */
219
+ function runsWithoutOwnerScreen(action, place) {
220
+ if (place !== 'desktop')
221
+ return true;
222
+ return exports.COMPUTER_ACTIONS[action].background;
223
+ }