@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.37
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/CHANGELOG.md +170 -0
- package/README.md +158 -52
- package/dist/attach-conformance-cli.d.ts +1 -0
- package/dist/attach-conformance-cli.js +18 -0
- package/dist/attach-conformance.d.ts +25 -0
- package/dist/attach-conformance.js +343 -0
- package/dist/browser-cost.d.ts +1 -1
- package/dist/browser-live.d.ts +20 -8
- package/dist/browser-live.js +50 -27
- package/dist/cap.d.ts +0 -17
- package/dist/cap.js +0 -91
- package/dist/catalog.d.ts +1 -12
- package/dist/catalog.js +3 -33
- package/dist/cli.js +13 -4
- package/dist/composio-preset.d.ts +36 -0
- package/dist/composio-preset.js +179 -0
- package/dist/computer-attach.d.ts +125 -0
- package/dist/computer-attach.js +330 -0
- package/dist/computer-calls.d.ts +48 -0
- package/dist/computer-calls.js +126 -0
- package/dist/computer-channel.d.ts +57 -0
- package/dist/computer-channel.js +115 -0
- package/dist/computer-commands.d.ts +1 -1
- package/dist/computer-held-routes.d.ts +35 -0
- package/dist/computer-held-routes.js +106 -0
- package/dist/computer-held.d.ts +48 -0
- package/dist/computer-held.js +87 -0
- package/dist/computer-keys.d.ts +21 -1
- package/dist/computer-keys.js +53 -11
- package/dist/computer-live.d.ts +160 -0
- package/dist/computer-live.js +643 -0
- package/dist/computer-view.d.ts +13 -0
- package/dist/computer-view.js +50 -3
- package/dist/computer-viewer.d.ts +6 -0
- package/dist/computer-viewer.js +297 -0
- package/dist/computers.d.ts +33 -7
- package/dist/computers.js +50 -8
- package/dist/console/assets/index-Cn6JX1uH.js +563 -0
- package/dist/console/assets/index-DRN62V5v.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/faux-computers.d.ts +9 -20
- package/dist/faux-computers.js +53 -25
- package/dist/github-connection.d.ts +10 -2
- package/dist/github-connection.js +65 -2
- package/dist/github-faux.js +1 -1
- package/dist/graph-view.d.ts +1 -1
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +35 -1
- package/dist/host-tools.d.ts +1 -1
- package/dist/hosted-search.d.ts +5 -4
- package/dist/hosted-search.js +2 -7
- package/dist/import-sources.d.ts +10 -0
- package/dist/import-sources.js +44 -2
- package/dist/import.d.ts +3 -3
- package/dist/import.js +37 -6
- package/dist/learn/check.d.ts +4 -1
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +4 -2
- package/dist/learn/commit.js +5 -5
- package/dist/learn/folder.d.ts +6 -0
- package/dist/learn/folder.js +4 -1
- package/dist/learn/general.d.ts +66 -0
- package/dist/learn/general.js +73 -0
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +22 -1
- package/dist/learn/reflect.d.ts +10 -1
- package/dist/learn/reflect.js +14 -4
- package/dist/learn/skills.d.ts +33 -5
- package/dist/learn/skills.js +53 -7
- package/dist/learned-workflow.d.ts +24 -0
- package/dist/learned-workflow.js +66 -3
- package/dist/learning-batch.d.ts +283 -0
- package/dist/learning-batch.js +574 -0
- package/dist/learning-evals.d.ts +33 -0
- package/dist/learning-evals.js +98 -0
- package/dist/learning-routes.d.ts +25 -2
- package/dist/learning-routes.js +39 -6
- package/dist/learning-words.d.ts +6 -0
- package/dist/learning-words.js +6 -0
- package/dist/learning.d.ts +28 -15
- package/dist/learning.js +84 -44
- package/dist/live/stream.js +6 -3
- package/dist/live/translate.d.ts +4 -3
- package/dist/live/translate.js +8 -4
- package/dist/live-reach.d.ts +37 -0
- package/dist/live-reach.js +62 -0
- package/dist/mcp-gateway.d.ts +9 -0
- package/dist/mcp-gateway.js +60 -11
- package/dist/mcp-oauth.d.ts +57 -7
- package/dist/mcp-oauth.js +133 -18
- package/dist/mcp-private-hosts.d.ts +4 -4
- package/dist/mcp-private-hosts.js +20 -12
- package/dist/mcp-probe.d.ts +19 -2
- package/dist/mcp-probe.js +44 -9
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +38 -15
- package/dist/mcp-servers-store.js +112 -20
- package/dist/mcp-store.d.ts +10 -4
- package/dist/mcp-store.js +17 -6
- package/dist/model-form.d.ts +26 -0
- package/dist/model-form.js +80 -0
- package/dist/model.js +23 -10
- package/dist/openapi.js +386 -21
- package/dist/page.d.ts +18 -0
- package/dist/page.js +48 -20
- package/dist/paid-calls.d.ts +1 -1
- package/dist/place-offers.d.ts +2 -3
- package/dist/place-offers.js +3 -7
- package/dist/place.js +1 -2
- package/dist/print.d.ts +15 -1
- package/dist/print.js +14 -3
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +13 -5
- package/dist/provider.js +3 -2
- package/dist/reflect-range.d.ts +8 -1
- package/dist/reflect-range.js +1 -1
- package/dist/run-launch.d.ts +14 -2
- package/dist/run-launch.js +9 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-repo.d.ts +20 -0
- package/dist/run-repo.js +63 -0
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-view.d.ts +3 -3
- package/dist/run-view.js +14 -7
- package/dist/runner/adapter-loop.d.ts +23 -7
- package/dist/runner/adapter-loop.js +648 -62
- package/dist/runner/adapter-run-spec.d.ts +11 -3
- package/dist/runner/adapter-run-spec.js +77 -22
- package/dist/runner/adapters/pi-computer.d.ts +7 -0
- package/dist/runner/adapters/pi-computer.js +43 -0
- package/dist/runner/adapters/pi.d.ts +9 -4
- package/dist/runner/adapters/pi.js +76 -14
- package/dist/runner/beside.d.ts +7 -3
- package/dist/runner/beside.js +21 -11
- package/dist/runner/claim-secrets.d.ts +4 -0
- package/dist/runner/claim-secrets.js +6 -1
- package/dist/runner/cli-run-spec.d.ts +20 -3
- package/dist/runner/cli-run-spec.js +113 -43
- package/dist/runner/commands.d.ts +3 -1
- package/dist/runner/commands.js +28 -3
- package/dist/runner/computer-channel.d.ts +34 -0
- package/dist/runner/computer-channel.js +61 -0
- package/dist/runner/conformance/harness.js +80 -14
- package/dist/runner/conformance/subject.d.ts +1 -1
- package/dist/runner/dispatch.js +3 -0
- package/dist/runner/end-of-run.d.ts +22 -12
- package/dist/runner/end-of-run.js +38 -16
- package/dist/runner/github-app.d.ts +2 -1
- package/dist/runner/github-app.js +4 -2
- package/dist/runner/harness-loops.js +15 -1
- package/dist/runner/held-run.d.ts +65 -0
- package/dist/runner/held-run.js +158 -0
- package/dist/runner/journal-kinds.d.ts +20 -1
- package/dist/runner/journal-kinds.js +14 -0
- package/dist/runner/journal-reader.d.ts +5 -4
- package/dist/runner/journal-reader.js +12 -10
- package/dist/runner/learning-ask.d.ts +7 -1
- package/dist/runner/learning-ask.js +21 -6
- package/dist/runner/learning-dispatch.d.ts +22 -0
- package/dist/runner/learning-dispatch.js +77 -10
- package/dist/runner/learning-end.d.ts +22 -1
- package/dist/runner/learning-end.js +92 -12
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +11 -5
- package/dist/runner/learning-loop.d.ts +67 -7
- package/dist/runner/learning-loop.js +173 -21
- package/dist/runner/learning-seed.d.ts +7 -0
- package/dist/runner/learning-seed.js +13 -0
- package/dist/runner/live-ticker.js +1 -0
- package/dist/runner/loop-contract.d.ts +8 -1
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +2 -1
- package/dist/runner/main.d.ts +13 -1
- package/dist/runner/main.js +27 -5
- package/dist/runner/mcp-claim.d.ts +10 -7
- package/dist/runner/mcp-claim.js +113 -24
- package/dist/runner/mcp-github.js +1 -1
- package/dist/runner/mcp-run.d.ts +5 -5
- package/dist/runner/mcp-run.js +15 -3
- package/dist/runner/metrics.d.ts +11 -2
- package/dist/runner/metrics.js +12 -2
- package/dist/runner/pr-checkout.d.ts +1 -0
- package/dist/runner/pr-checkout.js +1 -1
- package/dist/runner/reflect-hook.d.ts +18 -0
- package/dist/runner/reflect-hook.js +20 -8
- package/dist/runner/runner.d.ts +26 -0
- package/dist/runner/runner.js +184 -15
- package/dist/runner/scratch-sweep.d.ts +13 -0
- package/dist/runner/scratch-sweep.js +62 -0
- package/dist/runner/sessions.d.ts +1 -1
- package/dist/runner/store-port.d.ts +4 -2
- package/dist/runner/store-secrets.js +4 -3
- package/dist/runner/subagent.js +3 -1
- package/dist/runner/workflow-host.d.ts +6 -1
- package/dist/runner/workflow-host.js +1 -1
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-spec.d.ts +14 -2
- package/dist/runner/workflow-spec.js +56 -20
- package/dist/runs-over-store.d.ts +6 -1
- package/dist/runs-over-store.js +38 -9
- package/dist/seal-key.js +3 -3
- package/dist/sealed-settings-store.d.ts +5 -2
- package/dist/sealed-settings-store.js +10 -4
- package/dist/secret-writes.d.ts +5 -4
- package/dist/secret-writes.js +5 -4
- package/dist/server-secrets-store.d.ts +4 -3
- package/dist/server-secrets-store.js +15 -9
- package/dist/server-secrets.js +3 -2
- package/dist/server.d.ts +43 -14
- package/dist/server.js +472 -126
- package/dist/settings-wake.d.ts +21 -0
- package/dist/settings-wake.js +59 -0
- package/dist/standard-webhooks.d.ts +4 -1
- package/dist/standard-webhooks.js +8 -4
- package/dist/store/command-wake.d.ts +12 -0
- package/dist/store/command-wake.js +37 -0
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +5 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/journal/storage.d.ts +3 -2
- package/dist/store/journal/storage.js +13 -5
- package/dist/store/postgres/dialect.js +4 -0
- package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
- package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
- package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
- package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
- package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
- package/dist/store/schema.d.ts +1 -1
- package/dist/store/schema.js +77 -8
- package/dist/store/sqlite/run-patch.d.ts +7 -5
- package/dist/store/sqlite/run-patch.js +28 -13
- package/dist/store/sqlite/store.js +272 -54
- package/dist/store/store.d.ts +268 -9
- package/dist/store/store.js +12 -1
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +8 -1
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +1 -1
- package/dist/store-reads/import-summary.d.ts +1 -1
- package/dist/store-reads/journal.d.ts +5 -4
- package/dist/store-reads/journal.js +73 -15
- package/dist/store-reads/learning.d.ts +20 -4
- package/dist/store-reads/learning.js +74 -18
- package/dist/store-reads/runs.d.ts +1 -1
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +26 -11
- package/dist/template-eval.js +6 -4
- package/dist/template-github-permissions.d.ts +22 -8
- package/dist/template-github-permissions.js +35 -15
- package/dist/timeline/timeline.d.ts +27 -0
- package/dist/timeline/timeline.js +10 -9
- package/dist/timeline/util.d.ts +4 -0
- package/dist/timeline/util.js +14 -0
- package/dist/tool-budget.d.ts +19 -7
- package/dist/tool-budget.js +14 -8
- package/dist/tool-gate.d.ts +16 -9
- package/dist/tool-gate.js +53 -42
- package/dist/tool-plane.d.ts +16 -12
- package/dist/tool-plane.js +9 -4
- package/dist/tools.d.ts +13 -4
- package/dist/tools.js +13 -4
- package/dist/trigger-adapter.d.ts +4 -0
- package/dist/trigger-secrets-shown.d.ts +2 -2
- package/dist/trigger-secrets-shown.js +1 -1
- package/dist/trigger-signatures.d.ts +25 -6
- package/dist/trigger-signatures.js +41 -7
- package/dist/trigger-targets.d.ts +2 -0
- package/dist/trigger-targets.js +1 -0
- package/dist/trigger-webhook.js +5 -2
- package/dist/triggers.d.ts +7 -3
- package/dist/triggers.js +35 -5
- package/dist/turns.js +16 -1
- package/dist/validate.js +11 -1
- package/dist/web-fetch.d.ts +1 -1
- package/dist/web-search.d.ts +10 -5
- package/dist/web-search.js +7 -6
- package/dist/webhooks.d.ts +145 -102
- package/dist/webhooks.js +559 -322
- package/dist/workflow/decisions.d.ts +1 -1
- package/dist/workflow/node-runner.d.ts +2 -1
- package/dist/workflow/node.d.ts +2 -1
- package/dist/workflow/node.js +3 -1
- package/dist/workflow/pi-versions.d.ts +23 -0
- package/dist/workflow/pi-versions.js +57 -0
- package/dist/workflow/record-tool.d.ts +2 -1
- package/dist/workflow/store.d.ts +1 -1
- package/dist/workflow/task.js +3 -2
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/attached-computers.d.ts +41 -0
- package/dist/workspace/attached-computers.js +114 -0
- package/dist/workspace/computer-deps.d.ts +16 -9
- package/dist/workspace/computer-deps.js +19 -7
- package/dist/workspace/computer-for-claim.d.ts +17 -8
- package/dist/workspace/computer-for-claim.js +62 -21
- package/dist/workspace/computer-hold.d.ts +11 -27
- package/dist/workspace/computer-hold.js +36 -56
- package/dist/workspace/computer-ledger.d.ts +3 -1
- package/dist/workspace/computer-ledger.js +4 -0
- package/dist/workspace/computer-mcp.d.ts +25 -0
- package/dist/workspace/computer-mcp.js +41 -0
- package/dist/workspace/computer-ports.d.ts +4 -13
- package/dist/workspace/computer-ports.js +4 -107
- package/dist/workspace/computer-script.d.ts +37 -0
- package/dist/workspace/computer-script.js +138 -0
- package/dist/workspace/executors.d.ts +1 -1
- package/dist/workspace/index.d.ts +4 -2
- package/dist/workspace/index.js +3 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
- package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
- package/dist/workspace/resolve-computer.d.ts +3 -0
- package/dist/workspace/resolve-computer.js +8 -2
- package/dist/workspace/run-tools.d.ts +32 -15
- package/dist/workspace/run-tools.js +23 -30
- package/package.json +19 -16
- package/templates/market-monitor/agent.md +1 -1
- package/dist/console/assets/index-BI4Byidu.js +0 -550
- package/dist/console/assets/index-C19gUF2n.css +0 -1
- package/dist/run-db.d.ts +0 -53
- package/dist/run-db.js +0 -116
- package/dist/workflow/readers.d.ts +0 -36
- package/dist/workflow/readers.js +0 -145
- package/dist/workflow/wal.d.ts +0 -11
- package/dist/workflow/wal.js +0 -106
package/dist/computer-view.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import type { JournalEntry } from "./computer-commands.js";
|
|
1
2
|
import type { ViewerKind } from "./store/store.js";
|
|
3
|
+
export type { JournalEntry };
|
|
2
4
|
/** A run's computer: its agent's computer kind (`browser` for the browser tool), the store's viewer kind. */
|
|
3
5
|
export type ComputerKind = ViewerKind;
|
|
4
6
|
/** Who drives the run's computer now: the agent; `pending`, the person's Take over waits for the agent's step; the person. */
|
|
5
7
|
export type ComputerHold = "agent" | "pending" | "person";
|
|
8
|
+
/** Where a run's computer with no viewer open is: `unopened`, the run hasn't opened it so far; `opening`, it is being
|
|
9
|
+
* opened now; `closed`, the run opened one, which is not up now. */
|
|
10
|
+
export type ComputerSession = "unopened" | "opening" | "closed";
|
|
6
11
|
/** The run's computer as the server reads it: its kind, or why there is none here (in plain words). */
|
|
7
12
|
export type ComputerOf = {
|
|
8
13
|
kind: ComputerKind;
|
|
@@ -18,6 +23,7 @@ export type ComputerAnswer = {
|
|
|
18
23
|
state: "none";
|
|
19
24
|
kind: ComputerKind;
|
|
20
25
|
hold: ComputerHold;
|
|
26
|
+
session: ComputerSession;
|
|
21
27
|
ended?: {
|
|
22
28
|
at: string;
|
|
23
29
|
why: string;
|
|
@@ -36,6 +42,8 @@ export declare function computerView(deps: {
|
|
|
36
42
|
} | undefined>;
|
|
37
43
|
/** The run's computer, read only when no viewer is open. */
|
|
38
44
|
computer(): ComputerOf;
|
|
45
|
+
/** Where the run's computer of `kind` is with no viewer open (sessionIn over the run's journal). */
|
|
46
|
+
session(kind: ComputerKind): ComputerSession;
|
|
39
47
|
/** Who drives now. */
|
|
40
48
|
hold?(): ComputerHold;
|
|
41
49
|
/** Why the run's browser is not up, read only for a `none` browser: let go while the run waited for its person, and none
|
|
@@ -45,3 +53,8 @@ export declare function computerView(deps: {
|
|
|
45
53
|
why: string;
|
|
46
54
|
} | undefined>;
|
|
47
55
|
}): Promise<ComputerAnswer>;
|
|
56
|
+
/** Where the run's computer of `kind` is, read from the run's journal `entries` (in order), for a run with no viewer
|
|
57
|
+
* open. A desktop or a phone is opened by the run's claim at its start and held to its end: opening until its viewer
|
|
58
|
+
* answers. A browser is opened by the agent's browser steps (OPENS): unopened with no such call in the run; opening
|
|
59
|
+
* while one has no result yet; closed otherwise (released, or let go with its process). */
|
|
60
|
+
export declare function sessionIn(kind: ComputerKind, entries: readonly JournalEntry[]): ComputerSession;
|
package/dist/computer-view.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// GET /v2/runs/{run_id}/computer's answer: the run's computer live view, one family for every kind (browser, desktop,
|
|
2
2
|
// phone). The viewer comes first: a run's open viewer is served even when its computer would resolve off here now (the
|
|
3
|
-
// run holds the keys it started with). With none open, the run's computer says `none` with its kind
|
|
4
|
-
// there is no computer here. `hold` is who drives now.
|
|
3
|
+
// run holds the keys it started with). With none open, the run's computer says `none` with its kind and where its session
|
|
4
|
+
// is (never opened, opening, closed), or `off` with why there is no computer here. `hold` is who drives now.
|
|
5
|
+
import { KINDS } from "./runner/journal-kinds.js";
|
|
6
|
+
import { BROWSER_STEPS } from "./timeline/labels.js";
|
|
5
7
|
export async function computerView(deps) {
|
|
6
8
|
const hold = deps.hold?.() ?? "agent";
|
|
7
9
|
const open = await deps.viewer();
|
|
@@ -11,5 +13,50 @@ export async function computerView(deps) {
|
|
|
11
13
|
if ("off" in computer)
|
|
12
14
|
return { state: "off", hold: "agent", why: computer.off };
|
|
13
15
|
const ended = computer.kind === "browser" ? await deps.ended?.() : undefined;
|
|
14
|
-
|
|
16
|
+
if (ended)
|
|
17
|
+
return { state: "none", kind: computer.kind, hold, session: "closed", ended };
|
|
18
|
+
return { state: "none", kind: computer.kind, hold, session: deps.session(computer.kind) };
|
|
19
|
+
}
|
|
20
|
+
/** The browser's steps that open a session when none is open: every one of them but its release and its hand-over to a
|
|
21
|
+
* person, which is refused with no session open (a run, a snapshot, an upload or a relaunch alike goes through the
|
|
22
|
+
* session, which the first call launches). */
|
|
23
|
+
const OPENS = new Set([...BROWSER_STEPS].filter((name) => name !== "browser_release" && name !== "browser_request_handoff"));
|
|
24
|
+
const objOf = (value) => (value && typeof value === "object" && !Array.isArray(value) ? value : undefined);
|
|
25
|
+
const messageOf = (entry) => {
|
|
26
|
+
const model = entry.model;
|
|
27
|
+
return Array.isArray(model) ? objOf(model[0]) : undefined;
|
|
28
|
+
};
|
|
29
|
+
/** Where the run's computer of `kind` is, read from the run's journal `entries` (in order), for a run with no viewer
|
|
30
|
+
* open. A desktop or a phone is opened by the run's claim at its start and held to its end: opening until its viewer
|
|
31
|
+
* answers. A browser is opened by the agent's browser steps (OPENS): unopened with no such call in the run; opening
|
|
32
|
+
* while one has no result yet; closed otherwise (released, or let go with its process). */
|
|
33
|
+
export function sessionIn(kind, entries) {
|
|
34
|
+
if (kind !== "browser")
|
|
35
|
+
return "opening";
|
|
36
|
+
let asked = false;
|
|
37
|
+
const waiting = new Set();
|
|
38
|
+
const called = (id, name) => {
|
|
39
|
+
if (typeof id !== "string" || typeof name !== "string" || !OPENS.has(name))
|
|
40
|
+
return;
|
|
41
|
+
asked = true;
|
|
42
|
+
waiting.add(id);
|
|
43
|
+
};
|
|
44
|
+
for (const entry of entries) {
|
|
45
|
+
const message = messageOf(entry);
|
|
46
|
+
const data = objOf(entry.data);
|
|
47
|
+
// A pi run's calls are its assistant entries' toolCall blocks, answered by tool-result entries; a CLI harness's (Claude,
|
|
48
|
+
// Codex) are its record's call start and end entries.
|
|
49
|
+
if (entry.kind === "pi.assistant" && message && message.stopReason !== "error" && message.stopReason !== "aborted" && Array.isArray(message.content)) {
|
|
50
|
+
for (const block of message.content.map(objOf))
|
|
51
|
+
if (block?.type === "toolCall")
|
|
52
|
+
called(block.id, block.name);
|
|
53
|
+
}
|
|
54
|
+
else if (entry.kind === "pi.tool-result" && typeof message?.toolCallId === "string")
|
|
55
|
+
waiting.delete(message.toolCallId);
|
|
56
|
+
else if (entry.kind === KINDS.callStart)
|
|
57
|
+
called(data?.callId, data?.tool);
|
|
58
|
+
else if (entry.kind === KINDS.callEnd && typeof data?.callId === "string")
|
|
59
|
+
waiting.delete(data.callId);
|
|
60
|
+
}
|
|
61
|
+
return !asked ? "unopened" : waiting.size ? "opening" : "closed";
|
|
15
62
|
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// The computer viewer's page (a desktop's or a phone's screen), as three strings this server serves under the run's live
|
|
2
|
+
// path: the page at /v2/runs/{id}/computer/live/v/<id>, its script and style at computer-viewer.js and computer-viewer.css
|
|
3
|
+
// beside it, under LIVE_CSP (browser-live.ts), which allows no inline script or style. It is pi-browser's viewer
|
|
4
|
+
// generalized to a computer: one canvas, one WebSocket to this server's own origin, the token read from the fragment and
|
|
5
|
+
// sent once, in the hello (computer-live.ts has the protocol). Frames are drawn by their format (JPEG or PNG, told by their
|
|
6
|
+
// bytes) and acked once drawn, so the next comes only then. The bar has Take over and Hand back; no address bar, back or
|
|
7
|
+
// reload (a browser's). A desktop gets the mouse, the wheel and keys; a phone gets taps, swipes, its back, home and
|
|
8
|
+
// recents buttons, and keys (a soft keyboard's too, through beforeinput). Coordinates are the screen's real pixels, the w and h each frame carries. A swipe lasts 1,000 ms
|
|
9
|
+
// at most, as the computer takes it (createActionMapper's bound). Losing focus tells the endpoint ("blur"), which lets go of
|
|
10
|
+
// the buttons held.
|
|
11
|
+
const html = `<!doctype html>
|
|
12
|
+
<html lang="en">
|
|
13
|
+
<head>
|
|
14
|
+
<meta charset="utf-8">
|
|
15
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
16
|
+
<title>Live view</title>
|
|
17
|
+
<link rel="stylesheet" href="../computer-viewer.css">
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
<header id="bar">
|
|
21
|
+
<button id="hands" type="button" hidden>Take over</button>
|
|
22
|
+
<span id="phone" hidden>
|
|
23
|
+
<button id="back" type="button" title="Back" aria-label="Back">◀</button>
|
|
24
|
+
<button id="home" type="button" title="Home" aria-label="Home">●</button>
|
|
25
|
+
<button id="recents" type="button" title="Recents" aria-label="Recents">■</button>
|
|
26
|
+
</span>
|
|
27
|
+
<span id="spacer"></span>
|
|
28
|
+
<span id="drive" aria-live="polite"></span>
|
|
29
|
+
</header>
|
|
30
|
+
<div id="notice" role="status" hidden></div>
|
|
31
|
+
<main id="stage"><canvas id="screen" tabindex="0" aria-label="The computer's screen"></canvas><textarea id="sink" rows="1" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false" aria-label="Keyboard input for the computer"></textarea></main>
|
|
32
|
+
<script src="../computer-viewer.js"></script>
|
|
33
|
+
</body>
|
|
34
|
+
</html>
|
|
35
|
+
`;
|
|
36
|
+
const css = `* { box-sizing: border-box; }
|
|
37
|
+
html, body { margin: 0; height: 100%; background: #111; color: #eee; font: 14px system-ui, sans-serif; }
|
|
38
|
+
body { display: flex; flex-direction: column; }
|
|
39
|
+
#bar { display: flex; gap: 6px; align-items: center; padding: 6px 8px; background: #222; border-bottom: 1px solid #333; }
|
|
40
|
+
#bar button { background: #333; color: #eee; border: 1px solid #444; border-radius: 4px; padding: 4px 10px; cursor: pointer; }
|
|
41
|
+
#bar button:hover { background: #444; }
|
|
42
|
+
#bar button:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
43
|
+
#bar #hands { background: #1f4d2b; border-color: #2f6b3d; }
|
|
44
|
+
#bar #hands.holding { background: #5a3b00; border-color: #7a5410; }
|
|
45
|
+
#hands[hidden], #phone[hidden], #notice[hidden] { display: none; }
|
|
46
|
+
#phone { display: inline-flex; gap: 6px; }
|
|
47
|
+
#spacer { flex: 1; }
|
|
48
|
+
#drive { min-width: 9em; text-align: right; color: #aaa; }
|
|
49
|
+
#drive.agent, #drive.pending { color: #f0b429; }
|
|
50
|
+
#drive.person { color: #6cc070; }
|
|
51
|
+
.not-held #screen { cursor: not-allowed; }
|
|
52
|
+
#notice { padding: 6px 10px; background: #5a3b00; color: #ffe2a8; }
|
|
53
|
+
#notice.fatal { background: #5a1a1a; color: #ffc4c4; font-size: 18px; font-weight: 600; text-align: center; padding: 18px 16px; }
|
|
54
|
+
body.over #stage { opacity: 0.35; }
|
|
55
|
+
#stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
|
|
56
|
+
#screen { display: block; background: #000; outline: none; cursor: default; touch-action: none; }
|
|
57
|
+
#screen:focus, #stage:focus-within #screen { box-shadow: 0 0 0 2px #3b82f6; }
|
|
58
|
+
#sink { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; resize: none; overflow: hidden; pointer-events: none; font-size: 16px; }
|
|
59
|
+
`;
|
|
60
|
+
const js = `"use strict";
|
|
61
|
+
(function () {
|
|
62
|
+
var params = new URLSearchParams(location.hash.slice(1));
|
|
63
|
+
var token = params.get("t");
|
|
64
|
+
// The fragment never stays in the address bar, the history or a screenshot of it.
|
|
65
|
+
history.replaceState(null, "", location.pathname + location.search);
|
|
66
|
+
|
|
67
|
+
var $ = function (id) { return document.getElementById(id); };
|
|
68
|
+
var canvas = $("screen");
|
|
69
|
+
var sink = $("sink");
|
|
70
|
+
var ctx = canvas.getContext("2d");
|
|
71
|
+
var stage = $("stage");
|
|
72
|
+
var notice = $("notice");
|
|
73
|
+
var drive = $("drive");
|
|
74
|
+
var handsEl = $("hands");
|
|
75
|
+
function focusScreen() { try { sink.focus({ preventScroll: true }); } catch (e) { canvas.focus(); } }
|
|
76
|
+
function fit() {
|
|
77
|
+
if (!canvas.width || !canvas.height) return;
|
|
78
|
+
var box = stage.getBoundingClientRect();
|
|
79
|
+
var scale = Math.min(box.width / canvas.width, box.height / canvas.height);
|
|
80
|
+
if (!(scale > 0)) return;
|
|
81
|
+
canvas.style.width = Math.floor(canvas.width * scale) + "px";
|
|
82
|
+
canvas.style.height = Math.floor(canvas.height * scale) + "px";
|
|
83
|
+
}
|
|
84
|
+
if (typeof ResizeObserver === "function") new ResizeObserver(fit).observe(stage); else window.addEventListener("resize", fit);
|
|
85
|
+
|
|
86
|
+
var fatal = false;
|
|
87
|
+
function say(text, isFatal) {
|
|
88
|
+
if (!text) { notice.hidden = true; notice.textContent = ""; return; }
|
|
89
|
+
notice.hidden = false;
|
|
90
|
+
notice.textContent = text;
|
|
91
|
+
notice.className = isFatal ? "fatal" : "";
|
|
92
|
+
document.body.classList.toggle("over", !!isFatal);
|
|
93
|
+
}
|
|
94
|
+
var holding = false;
|
|
95
|
+
var kind = "";
|
|
96
|
+
var input = "";
|
|
97
|
+
var DRIVE = { agent: "the agent has the computer", pending: "taking over: the agent's step is ending", person: "you have the computer" };
|
|
98
|
+
function setDrive(state) { drive.className = state || ""; drive.textContent = DRIVE[state] || ""; }
|
|
99
|
+
function showHands() {
|
|
100
|
+
handsEl.hidden = false;
|
|
101
|
+
handsEl.textContent = holding ? "Hand back" : "Take over";
|
|
102
|
+
handsEl.className = holding ? "holding" : "";
|
|
103
|
+
document.body.classList.toggle("not-held", !holding);
|
|
104
|
+
["back", "home", "recents"].forEach(function (id) { $(id).disabled = !holding; });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!token) { fatal = true; say("This link has no token. Open the live view from the run's page.", true); return; }
|
|
108
|
+
var proto = location.protocol === "https:" ? "wss://" : "ws://";
|
|
109
|
+
var ws = new WebSocket(proto + location.host + location.pathname.replace(/\\/$/, "") + "/ws");
|
|
110
|
+
ws.binaryType = "arraybuffer";
|
|
111
|
+
var ready = false;
|
|
112
|
+
var closed = false;
|
|
113
|
+
say("Connecting to the computer.");
|
|
114
|
+
ws.onopen = function () { ws.send(JSON.stringify({ type: "hello", token: token })); token = null; };
|
|
115
|
+
function raw(message) { if (ws.readyState === 1) ws.send(JSON.stringify(message)); }
|
|
116
|
+
var NOT_TAKEN = "Take over to drive.";
|
|
117
|
+
function send(message) {
|
|
118
|
+
if (!ready) return;
|
|
119
|
+
if (!holding) { if (!(message.type === "mouse" && message.action === "move")) say(NOT_TAKEN); return; }
|
|
120
|
+
raw(message);
|
|
121
|
+
}
|
|
122
|
+
handsEl.addEventListener("click", function () {
|
|
123
|
+
if (!ready) return;
|
|
124
|
+
raw({ type: holding ? "give" : "take" });
|
|
125
|
+
if (!holding) say("Taking over the computer...");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Frames: one at a time; each is acked once drawn, and only then does the computer send the next.
|
|
129
|
+
var frame = { w: 0, h: 0 };
|
|
130
|
+
function formatOf(bytes) { return bytes.length > 3 && bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47 ? "image/png" : "image/jpeg"; }
|
|
131
|
+
function draw(buffer) {
|
|
132
|
+
if (buffer.byteLength <= 4) { raw({ type: "ack" }); return; }
|
|
133
|
+
var view = new DataView(buffer);
|
|
134
|
+
var w = view.getUint16(0);
|
|
135
|
+
var h = view.getUint16(2);
|
|
136
|
+
var bytes = new Uint8Array(buffer, 4);
|
|
137
|
+
createImageBitmap(new Blob([bytes], { type: formatOf(bytes) })).then(function (bitmap) {
|
|
138
|
+
if (canvas.width !== bitmap.width || canvas.height !== bitmap.height) { canvas.width = bitmap.width; canvas.height = bitmap.height; fit(); }
|
|
139
|
+
ctx.drawImage(bitmap, 0, 0);
|
|
140
|
+
if (bitmap.close) bitmap.close();
|
|
141
|
+
frame = { w: w || bitmap.width, h: h || bitmap.height };
|
|
142
|
+
document.body.dataset.frames = String(Number(document.body.dataset.frames || "0") + 1);
|
|
143
|
+
}, function () {}).then(function () { raw({ type: "ack" }); });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
var HOLD_ENDED = { given: "You handed the computer back to the agent.", answered: "The agent's request was answered, so the computer went back to the agent.", idle: "The computer went back to the agent: no input came from you for 15 minutes.", away: "The computer went back to the agent: the live view was closed.", released: "The computer's session ended while you had it." };
|
|
147
|
+
var REFUSED = { unauthorized: "This link's token was not accepted.", viewer_in_use: "Another viewer already has this computer.", released: "This computer has been released.", bad_message: "The host did not understand this viewer.", slow_viewer: "This view fell too far behind the computer's screen: open the live view again." };
|
|
148
|
+
var ENDED = { gone: "This computer has ended.", released: "This computer has been released.", ended: "This computer's session has ended.", unreachable: "The computer can't be reached right now.", refused: "The computer refused its live view.", unsupported: "This computer has no screen to show." };
|
|
149
|
+
ws.onmessage = function (event) {
|
|
150
|
+
if (typeof event.data !== "string") { draw(event.data); return; }
|
|
151
|
+
var m;
|
|
152
|
+
try { m = JSON.parse(event.data); } catch (e) { return; }
|
|
153
|
+
if (m.type === "ready") {
|
|
154
|
+
ready = true; kind = m.kind; input = m.input; holding = m.held === true;
|
|
155
|
+
$("phone").hidden = kind !== "phone";
|
|
156
|
+
document.body.dataset.kind = kind;
|
|
157
|
+
showHands(); setDrive(m.drive); say(""); focusScreen();
|
|
158
|
+
}
|
|
159
|
+
else if (m.type === "hold") {
|
|
160
|
+
holding = m.held === true;
|
|
161
|
+
showHands(); setDrive(holding ? "person" : "agent");
|
|
162
|
+
var extra = typeof m.message === "string" && m.message ? " " + m.message : "";
|
|
163
|
+
say(holding ? "" : (HOLD_ENDED[m.reason] || "The computer went back to the agent.") + extra);
|
|
164
|
+
if (holding) focusScreen();
|
|
165
|
+
}
|
|
166
|
+
else if (m.type === "status") { setDrive(m.drive); if (m.drive === "pending") say("Taking over: the agent's step is ending."); }
|
|
167
|
+
else if (m.type === "take_refused") say(m.message || "The computer could not be handed to you.");
|
|
168
|
+
else if (m.type === "held") say(m.message || "That input was held.");
|
|
169
|
+
else if (m.type === "refused") { fatal = true; ready = false; say(REFUSED[m.reason] || "The host refused this viewer.", true); }
|
|
170
|
+
else if (m.type === "ended") { fatal = true; ready = false; holding = false; handsEl.disabled = true; say(ENDED[m.reason] || "This computer has ended.", true); }
|
|
171
|
+
};
|
|
172
|
+
ws.onclose = function () { closed = true; ready = false; holding = false; handsEl.disabled = true; setDrive(""); if (!fatal) say("Disconnected. Open the live view again.", true); };
|
|
173
|
+
|
|
174
|
+
// Input, in the screen's real pixels: from the canvas's box and the latest frame's w and h.
|
|
175
|
+
function point(e) {
|
|
176
|
+
var rect = canvas.getBoundingClientRect();
|
|
177
|
+
if (!frame.w || !rect.width) return null;
|
|
178
|
+
var x = Math.round((e.clientX - rect.left) * (frame.w / rect.width));
|
|
179
|
+
var y = Math.round((e.clientY - rect.top) * (frame.h / rect.height));
|
|
180
|
+
return { x: Math.max(0, Math.min(frame.w - 1, x)), y: Math.max(0, Math.min(frame.h - 1, y)) };
|
|
181
|
+
}
|
|
182
|
+
function mods(e) { return (e.altKey ? 1 : 0) | (e.ctrlKey ? 2 : 0) | (e.metaKey ? 4 : 0) | (e.shiftKey ? 8 : 0); }
|
|
183
|
+
|
|
184
|
+
// A desktop: the mouse and the wheel. A button pressed on the screen is released wherever the mouse goes up (the bar
|
|
185
|
+
// around it, the empty stage): the release is heard on the window, at the screen's nearest point.
|
|
186
|
+
var pressed = {};
|
|
187
|
+
canvas.addEventListener("mousedown", function (e) {
|
|
188
|
+
focusScreen();
|
|
189
|
+
if (input !== "desktop") return;
|
|
190
|
+
var p = point(e); if (!p) return;
|
|
191
|
+
e.preventDefault();
|
|
192
|
+
pressed[e.button] = true;
|
|
193
|
+
send({ type: "mouse", action: "down", x: p.x, y: p.y, button: e.button, buttons: e.buttons, clickCount: Math.max(1, Math.min(3, e.detail || 1)), modifiers: mods(e) });
|
|
194
|
+
});
|
|
195
|
+
window.addEventListener("mouseup", function (e) {
|
|
196
|
+
if (input !== "desktop" || !pressed[e.button]) return;
|
|
197
|
+
delete pressed[e.button];
|
|
198
|
+
var p = point(e); if (!p) return;
|
|
199
|
+
if (e.target === canvas) e.preventDefault();
|
|
200
|
+
send({ type: "mouse", action: "up", x: p.x, y: p.y, button: e.button, buttons: e.buttons, clickCount: Math.max(1, Math.min(3, e.detail || 1)), modifiers: mods(e) });
|
|
201
|
+
});
|
|
202
|
+
var moved = null, scheduled = false;
|
|
203
|
+
canvas.addEventListener("mousemove", function (e) {
|
|
204
|
+
if (input !== "desktop" || !holding) return;
|
|
205
|
+
var p = point(e); if (!p) return;
|
|
206
|
+
moved = { type: "mouse", action: "move", x: p.x, y: p.y, button: 0, buttons: e.buttons, clickCount: 0, modifiers: mods(e) };
|
|
207
|
+
if (!scheduled) { scheduled = true; requestAnimationFrame(function () { scheduled = false; if (moved) { send(moved); moved = null; } }); }
|
|
208
|
+
});
|
|
209
|
+
canvas.addEventListener("contextmenu", function (e) { e.preventDefault(); });
|
|
210
|
+
// The viewer losing focus (another window, or the run's page around it) lets go of what the person holds down: the
|
|
211
|
+
// computer would never see its release.
|
|
212
|
+
window.addEventListener("blur", function () { if (holding) raw({ type: "blur" }); });
|
|
213
|
+
canvas.addEventListener("wheel", function (e) {
|
|
214
|
+
if (input !== "desktop") return;
|
|
215
|
+
var p = point(e); if (!p) return;
|
|
216
|
+
e.preventDefault();
|
|
217
|
+
var unit = e.deltaMode === 1 ? 40 : e.deltaMode === 2 ? frame.h : 1;
|
|
218
|
+
send({ type: "wheel", x: p.x, y: p.y, dx: Math.round(e.deltaX * unit), dy: Math.round(e.deltaY * unit) });
|
|
219
|
+
}, { passive: false });
|
|
220
|
+
|
|
221
|
+
// A phone: a short touch that stays put is a tap, anything else a swipe; and its three buttons.
|
|
222
|
+
var touchStart = null;
|
|
223
|
+
canvas.addEventListener("pointerdown", function (e) {
|
|
224
|
+
if (input === "desktop") return;
|
|
225
|
+
focusScreen();
|
|
226
|
+
var p = point(e); if (!p) return;
|
|
227
|
+
e.preventDefault();
|
|
228
|
+
// Captured: a mouse drag released outside the screen still ends here, as a swipe.
|
|
229
|
+
try { canvas.setPointerCapture(e.pointerId); } catch (_) { /* a pointer that is gone */ }
|
|
230
|
+
touchStart = { x: p.x, y: p.y, at: Date.now() };
|
|
231
|
+
});
|
|
232
|
+
canvas.addEventListener("pointerup", function (e) {
|
|
233
|
+
if (input === "desktop" || !touchStart) return;
|
|
234
|
+
var p = point(e); var from = touchStart; touchStart = null;
|
|
235
|
+
if (!p) return;
|
|
236
|
+
e.preventDefault();
|
|
237
|
+
var far = Math.abs(p.x - from.x) + Math.abs(p.y - from.y) > 12;
|
|
238
|
+
if (far) send({ type: "swipe", x1: from.x, y1: from.y, x2: p.x, y2: p.y, ms: Math.max(50, Math.min(1000, Date.now() - from.at)) });
|
|
239
|
+
else send({ type: "tap", x: p.x, y: p.y });
|
|
240
|
+
});
|
|
241
|
+
["back", "home", "recents"].forEach(function (name) { $(name).addEventListener("click", function () { send({ type: "button", name: name }); focusScreen(); }); });
|
|
242
|
+
|
|
243
|
+
// Keys, for both: a printable character typed goes as its char, everything else as its key. AltGr's character (which
|
|
244
|
+
// Windows reports with Ctrl and Alt held) is text, not a shortcut; a dead key is left to finish as the composition or
|
|
245
|
+
// the input it makes (compositionend, beforeinput).
|
|
246
|
+
var justComposed = null;
|
|
247
|
+
function onKeyDown(e) {
|
|
248
|
+
justComposed = null;
|
|
249
|
+
if (e.isComposing || e.keyCode === 229 || e.key === "Dead") return;
|
|
250
|
+
if ((e.ctrlKey || e.metaKey) && (e.key === "v" || e.key === "V")) return;
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
var altGraph = !!(e.getModifierState && e.getModifierState("AltGraph"));
|
|
253
|
+
var printable = e.key.length === 1 && (altGraph ? !e.metaKey : !e.ctrlKey && !e.metaKey && !e.altKey);
|
|
254
|
+
if (printable) send({ type: "key", action: "char", key: e.key, code: e.code || "", text: e.key, modifiers: altGraph ? (e.shiftKey ? 8 : 0) : mods(e) });
|
|
255
|
+
else send({ type: "key", action: "down", key: e.key, code: e.code || "", modifiers: mods(e) });
|
|
256
|
+
}
|
|
257
|
+
function onPaste(e) {
|
|
258
|
+
var text = e.clipboardData ? e.clipboardData.getData("text/plain") : "";
|
|
259
|
+
e.preventDefault();
|
|
260
|
+
if (text) send({ type: "text", text: text });
|
|
261
|
+
}
|
|
262
|
+
[canvas, sink].forEach(function (el) { el.addEventListener("keydown", onKeyDown); el.addEventListener("paste", onPaste); });
|
|
263
|
+
sink.addEventListener("compositionend", function (e) { justComposed = e.data || null; if (e.data) send({ type: "text", text: e.data }); sink.value = ""; });
|
|
264
|
+
// A soft keyboard (a phone's, a tablet's) sends keydown with keyCode 229 and no key, so its edits come as the sink's
|
|
265
|
+
// beforeinput alone. A desktop's typed key never reaches here: onKeyDown's preventDefault cancels the beforeinput it
|
|
266
|
+
// would have made. A composition's own steps are compositionend's, a paste the paste handler's.
|
|
267
|
+
function sendKey(key) { send({ type: "key", action: "down", key: key, code: "", modifiers: 0 }); }
|
|
268
|
+
var EDITS = {
|
|
269
|
+
// Some browsers follow compositionend with an insertText of the same word, with no key between: that repeat is the
|
|
270
|
+
// composition's, already sent; a key since (onKeyDown) or any other edit makes the same text a new one.
|
|
271
|
+
insertText: function (e) { if (e.data && e.data !== justComposed) send({ type: "text", text: e.data }); },
|
|
272
|
+
// Autocorrect swapping a word the computer already has: as many Backspaces as the replaced range, then the new word.
|
|
273
|
+
insertReplacementText: function (e) {
|
|
274
|
+
var text = e.data || (e.dataTransfer ? e.dataTransfer.getData("text/plain") : "");
|
|
275
|
+
var range = e.getTargetRanges ? e.getTargetRanges()[0] : null;
|
|
276
|
+
var gone = range && range.startContainer === range.endContainer ? Math.max(0, range.endOffset - range.startOffset) : 0;
|
|
277
|
+
for (var i = 0; i < gone; i++) sendKey("Backspace");
|
|
278
|
+
if (text) send({ type: "text", text: text });
|
|
279
|
+
},
|
|
280
|
+
insertLineBreak: function () { sendKey("Enter"); },
|
|
281
|
+
insertParagraph: function () { sendKey("Enter"); },
|
|
282
|
+
deleteContentBackward: function () { sendKey("Backspace"); },
|
|
283
|
+
deleteContentForward: function () { sendKey("Delete"); },
|
|
284
|
+
};
|
|
285
|
+
sink.addEventListener("beforeinput", function (e) {
|
|
286
|
+
var edit = Object.prototype.hasOwnProperty.call(EDITS, e.inputType) ? EDITS[e.inputType] : null;
|
|
287
|
+
if (!edit || e.isComposing) return;
|
|
288
|
+
e.preventDefault();
|
|
289
|
+
edit(e);
|
|
290
|
+
justComposed = null;
|
|
291
|
+
});
|
|
292
|
+
// Whatever a keyboard put in the sink that no beforeinput took (one it could not cancel) is let go, never sent twice.
|
|
293
|
+
sink.addEventListener("input", function (e) { if (!e.isComposing) sink.value = ""; });
|
|
294
|
+
})();
|
|
295
|
+
`;
|
|
296
|
+
/** The computer viewer's page and its two files, served by this server under LIVE_CSP. */
|
|
297
|
+
export const computerViewerAssets = Object.freeze({ html, js, css });
|
package/dist/computers.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type ComputerProvider, type GpuCapability } from "@parcha/agentrun-computer";
|
|
2
|
-
import { type KeyTable, type OptionsAnswer, type ProviderFactories, type ProviderSettings } from "./computer-keys.js";
|
|
2
|
+
import { type KeyChoice, type KeyTable, type OptionsAnswer, type ProviderFactories, type ProviderSettings } from "./computer-keys.js";
|
|
3
3
|
import { type ComputerKind, type ComputerSetting } from "./computer-setting.js";
|
|
4
4
|
import { type DockerDaemon } from "./docker-daemon.js";
|
|
5
5
|
import { type KeyEnv, type KeyMeta } from "./key-meta.js";
|
|
6
|
-
import type { Store } from "./store/index.js";
|
|
7
|
-
import {
|
|
6
|
+
import type { PairedComputerRow, Store } from "./store/index.js";
|
|
7
|
+
import type { PairedView } from "./computer-attach.js";
|
|
8
|
+
import { type ComputerSettingKind, type ShellPlace } from "./workspace/resolve-computer.js";
|
|
8
9
|
/** A setting kind as the kind registry's SETTING_KINDS gives it. */
|
|
9
10
|
export interface SettingKindSpec {
|
|
10
11
|
readonly machineKinds: readonly string[];
|
|
@@ -30,6 +31,7 @@ export interface ProviderEntry {
|
|
|
30
31
|
readonly keys: readonly {
|
|
31
32
|
readonly name: string;
|
|
32
33
|
readonly required: boolean;
|
|
34
|
+
readonly picked?: boolean;
|
|
33
35
|
}[];
|
|
34
36
|
/** The mounts its computers take; none means it cannot mount the run's folder. */
|
|
35
37
|
readonly mounts: readonly string[];
|
|
@@ -78,7 +80,7 @@ export interface ComputerRoutesOptions {
|
|
|
78
80
|
readonly settings?: ProviderSettings;
|
|
79
81
|
/** The map from a provider's key names to its options: serve's own unless given (--faux gives its own). */
|
|
80
82
|
readonly keyTable?: KeyTable;
|
|
81
|
-
/** The model-visible tools a kind brings
|
|
83
|
+
/** The model-visible tools a kind brings, by name (server.ts kindTools). */
|
|
82
84
|
readonly tools: (kind: ComputerKind) => readonly string[];
|
|
83
85
|
/** This server's folder mode, or how to read it at each call (folderModeOf: the Archil settings, the environment's or the saved row), so turning
|
|
84
86
|
* Archil on or off takes effect without building the routes again. */
|
|
@@ -91,19 +93,28 @@ export interface ComputerRoutesOptions {
|
|
|
91
93
|
/** Whether a provider that binds a folder of this machine (Docker) answers here now, or why not (the server's daemon
|
|
92
94
|
* check, docker-daemon.ts, which keeps its answer a while). Absent: taken as answering. */
|
|
93
95
|
readonly answers?: (provider: string) => Promise<DockerDaemon>;
|
|
96
|
+
/** The person's own computers paired with this server (computer-attach.ts): the store's rows and each one's view.
|
|
97
|
+
* Each is one more provider of its kind (attached-computers.ts pairedEntry), ready while it is attached. Absent:
|
|
98
|
+
* none. */
|
|
99
|
+
readonly paired?: {
|
|
100
|
+
rows(): Promise<readonly PairedComputerRow[]>;
|
|
101
|
+
viewOf(row: PairedComputerRow, serves: readonly ComputerSettingKind[]): PairedView;
|
|
102
|
+
};
|
|
94
103
|
}
|
|
95
104
|
/** A provider as Settings shows it: `metered` straight from the kind registry (its computers are billed by the vendor);
|
|
96
105
|
* its keys as SecretMeta under `secrets`, each named "computer:<provider>:<KEY>", and `required`, the names of the ones
|
|
97
106
|
* it needs. `network`: what this server's allow-list means for a vendor-hosted computer, in words (networkWords).
|
|
98
107
|
* `images`: the images it offers for the kind, by name, where it offers any to choose. `persistent`: present where an
|
|
99
108
|
* agent's computer of this kind can be kept between its runs (computer.persistent: true), with the images that keep one
|
|
100
|
-
* where it offers images to choose.
|
|
109
|
+
* where it offers images to choose. `picked`: the names of the secrets a person picks from the vendor's own list
|
|
110
|
+
* (GET /v2/computers/{provider}/choices) rather than pastes, where it has any. */
|
|
101
111
|
export type ProviderView = {
|
|
102
112
|
id: string;
|
|
103
113
|
name: string;
|
|
104
114
|
metered: boolean;
|
|
105
115
|
secrets: KeyMeta[];
|
|
106
116
|
required: string[];
|
|
117
|
+
picked?: string[];
|
|
107
118
|
ready: boolean;
|
|
108
119
|
why?: string;
|
|
109
120
|
network?: string;
|
|
@@ -155,6 +166,17 @@ export type TestView = {
|
|
|
155
166
|
ok: false;
|
|
156
167
|
why: string;
|
|
157
168
|
};
|
|
169
|
+
/** A picked key's choices (GET /v2/computers/{provider}/choices): its KEY, as PUT …/keys takes it, then the values the
|
|
170
|
+
* vendor's list offers, each saved as it is and shown by its label, and `saved`, the one whose value is saved now, where
|
|
171
|
+
* one is (it is among the options already, so it says nothing new); or why there are none to pick, in words. */
|
|
172
|
+
export type KeyChoicesView = {
|
|
173
|
+
key: string;
|
|
174
|
+
options: KeyChoice[];
|
|
175
|
+
saved?: string;
|
|
176
|
+
} | {
|
|
177
|
+
key: string;
|
|
178
|
+
why: string;
|
|
179
|
+
};
|
|
158
180
|
/** Why a key save is refused, before anything is saved: a name the provider does not declare, or a value that is not text. */
|
|
159
181
|
export declare class KeysRefused extends Error {
|
|
160
182
|
readonly fields: {
|
|
@@ -181,9 +203,13 @@ export declare function modeRefusal(kind: ComputerKind, provider: ProviderEntry,
|
|
|
181
203
|
export declare function createComputerRoutes(options: ComputerRoutesOptions): {
|
|
182
204
|
view: () => Promise<{
|
|
183
205
|
kinds: KindView[];
|
|
206
|
+
paired: PairedView[];
|
|
184
207
|
}>;
|
|
185
208
|
saveKeys: (providerId: string, body: Readonly<Record<string, unknown>>) => Promise<ProviderView | undefined>;
|
|
186
209
|
test: (providerId: string, signal?: AbortSignal) => Promise<TestView | undefined>;
|
|
210
|
+
choices: (providerId: string, signal?: AbortSignal) => Promise<{
|
|
211
|
+
choices: KeyChoicesView[];
|
|
212
|
+
} | undefined>;
|
|
187
213
|
claimRefusal: (computer: ComputerSetting) => Promise<string | undefined>;
|
|
188
214
|
claimOptions: (computer: ComputerSetting) => Promise<OptionsAnswer | undefined>;
|
|
189
215
|
providerFor: (providerId: string, image: string | undefined) => Promise<Pick<ComputerProvider, "release">>;
|
|
@@ -194,8 +220,8 @@ export type ComputerRoutes = ReturnType<typeof createComputerRoutes>;
|
|
|
194
220
|
export declare const folderModeOf: (store: {
|
|
195
221
|
settings: Pick<Store["settings"], "get">;
|
|
196
222
|
}, env?: KeyEnv) => () => Promise<FolderMode>;
|
|
197
|
-
/** Settings → Computers' routes, by their operation names: GET /v2/computers, PUT /v2/computers/{provider}/keys
|
|
198
|
-
* /v2/computers/{provider}/test. */
|
|
223
|
+
/** Settings → Computers' routes, by their operation names: GET /v2/computers, PUT /v2/computers/{provider}/keys, POST
|
|
224
|
+
* /v2/computers/{provider}/test and GET /v2/computers/{provider}/choices. */
|
|
199
225
|
export declare const COMPUTER_SETTINGS_ROUTES: ReadonlySet<string>;
|
|
200
226
|
/** One of Settings → Computers' routes at its handler, as serve's dispatch calls it: its answer (sent 200), or its refusal
|
|
201
227
|
* as an ApiError (sent with its status): an unknown provider is not_found; a key save's body that is not an object of
|