@roam-agent/roam-computer-use 0.0.0-stage → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +80 -2
- package/assets/reference/img.jpg +0 -0
- package/docs/README.md +45 -0
- package/docs/content/docs/explanation/action-pipeline.mdx +36 -0
- package/docs/content/docs/explanation/architecture.mdx +161 -0
- package/docs/content/docs/explanation/index.mdx +19 -0
- package/docs/content/docs/explanation/meta.json +5 -0
- package/docs/content/docs/explanation/observation-pipeline.mdx +37 -0
- package/docs/content/docs/explanation/platform-boundary.mdx +37 -0
- package/docs/content/docs/explanation/state-and-scheduling.mdx +35 -0
- package/docs/content/docs/how-to-guides/develop-and-validate.mdx +112 -0
- package/docs/content/docs/how-to-guides/index.mdx +12 -0
- package/docs/content/docs/how-to-guides/linux.mdx +68 -0
- package/docs/content/docs/how-to-guides/meta.json +1 -0
- package/docs/content/docs/how-to-guides/troubleshooting.mdx +126 -0
- package/docs/content/docs/index.mdx +67 -0
- package/docs/content/docs/meta.json +5 -0
- package/docs/content/docs/reference/agent/contract.mdx +162 -0
- package/docs/content/docs/reference/agent/index.mdx +8 -0
- package/docs/content/docs/reference/agent/meta.json +8 -0
- package/docs/content/docs/reference/agent/tools.mdx +221 -0
- package/docs/content/docs/reference/codebase.mdx +139 -0
- package/docs/content/docs/reference/configuration.mdx +113 -0
- package/docs/content/docs/reference/index.mdx +28 -0
- package/docs/content/docs/reference/meta.json +10 -0
- package/docs/content/docs/reference/platforms/index.mdx +18 -0
- package/docs/content/docs/reference/platforms/macos/accessibility.mdx +61 -0
- package/docs/content/docs/reference/platforms/macos/actions.mdx +63 -0
- package/docs/content/docs/reference/platforms/macos/capture.mdx +58 -0
- package/docs/content/docs/reference/platforms/macos/implementation.mdx +98 -0
- package/docs/content/docs/reference/platforms/macos/index.mdx +16 -0
- package/docs/content/docs/reference/platforms/macos/meta.json +10 -0
- package/docs/content/docs/reference/platforms/macos/root-targeting.mdx +47 -0
- package/docs/content/docs/reference/platforms/meta.json +8 -0
- package/docs/content/docs/reference/platforms/windows.mdx +75 -0
- package/docs/content/docs/tutorials/getting-started.mdx +46 -0
- package/docs/content/docs/tutorials/index.mdx +10 -0
- package/docs/content/docs/tutorials/meta.json +1 -0
- package/extensions/computer-use.ts +235 -0
- package/native/linux/bridge-rs/Cargo.lock +1204 -0
- package/native/linux/bridge-rs/Cargo.toml +21 -0
- package/native/linux/bridge-rs/src/atspi.rs +670 -0
- package/native/linux/bridge-rs/src/error.rs +65 -0
- package/native/linux/bridge-rs/src/lib.rs +11 -0
- package/native/linux/bridge-rs/src/main.rs +1110 -0
- package/native/linux/bridge-rs/src/protocol.rs +49 -0
- package/native/linux/bridge-rs/src/state.rs +293 -0
- package/native/linux/bridge-rs/src/wayland.rs +89 -0
- package/native/linux/bridge-rs/src/x11.rs +909 -0
- package/native/linux/bridge-rs/tests/protocol_tests.rs +73 -0
- package/native/macos/activity_glow.swift +169 -0
- package/native/macos/bridge.swift +3968 -0
- package/native/windows/bridge-rs/Cargo.lock +396 -0
- package/native/windows/bridge-rs/Cargo.toml +30 -0
- package/native/windows/bridge-rs/src/capture.rs +561 -0
- package/native/windows/bridge-rs/src/error.rs +81 -0
- package/native/windows/bridge-rs/src/input.rs +501 -0
- package/native/windows/bridge-rs/src/lib.rs +85 -0
- package/native/windows/bridge-rs/src/main.rs +1683 -0
- package/native/windows/bridge-rs/src/protocol.rs +53 -0
- package/native/windows/bridge-rs/src/refs.rs +237 -0
- package/native/windows/bridge-rs/src/state.rs +55 -0
- package/native/windows/bridge-rs/src/uia.rs +1252 -0
- package/native/windows/bridge-rs/src/window.rs +718 -0
- package/native/windows/bridge-rs/tests/protocol_tests.rs +252 -0
- package/native/windows/bridge-rs/tests/refs_tests.rs +86 -0
- package/native/windows/bridge-rs/tests/state_tests.rs +33 -0
- package/package.json +105 -5
- package/prebuilt/macos/arm64/bridge +0 -0
- package/prebuilt/macos/x64/bridge +0 -0
- package/roam/README.md +52 -0
- package/roam/bridge/macos/arm64/bridge +0 -0
- package/roam/bridge/macos/x64/bridge +0 -0
- package/roam/bridge/manifest.json +20 -0
- package/roam/helper-path.d.mts +9 -0
- package/roam/helper-path.mjs +36 -0
- package/roam/identity.d.mts +16 -0
- package/roam/identity.mjs +64 -0
- package/roam/index.ts +51 -0
- package/roam/redirect.ts +51 -0
- package/roam/repair.ts +120 -0
- package/scripts/build-native.mjs +286 -0
- package/scripts/lib/roam-bridge.mjs +98 -0
- package/scripts/setup-helper.mjs +635 -0
- package/src/actions.ts +130 -0
- package/src/bridge.ts +2594 -0
- package/src/cdp.ts +658 -0
- package/src/config.ts +226 -0
- package/src/contract.ts +107 -0
- package/src/extension/index.ts +9 -0
- package/src/find-params.ts +21 -0
- package/src/note.ts +195 -0
- package/src/outline.ts +702 -0
- package/src/output.ts +134 -0
- package/src/permissions.ts +111 -0
- package/src/platform/architecture.ts +23 -0
- package/src/platform/coerce.ts +16 -0
- package/src/platform/index.ts +61 -0
- package/src/platform/linux/backend.ts +186 -0
- package/src/platform/linux/helper.ts +238 -0
- package/src/platform/macos/backend.ts +147 -0
- package/src/platform/macos/browser.ts +110 -0
- package/src/platform/macos/helper.ts +369 -0
- package/src/platform/macos/permissions.ts +146 -0
- package/src/platform/types.ts +229 -0
- package/src/platform/windows/backend.ts +142 -0
- package/src/platform/windows/helper.ts +140 -0
- package/src/root-selection.ts +25 -0
- package/src/runtime.ts +129 -0
- package/src/state.ts +146 -0
- package/src/view.ts +147 -0
package/src/actions.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { MouseButtonName, UiAction } from "./contract.ts";
|
|
2
|
+
import { INCIDENTAL_ACTIONS, type OutlineNode } from "./outline.ts";
|
|
3
|
+
import { toFiniteNumber } from "./platform/coerce.ts";
|
|
4
|
+
|
|
5
|
+
export type ActionTarget = { ref: string } | { x: number; y: number } | { focus: { x: number; y: number } };
|
|
6
|
+
|
|
7
|
+
export type PreparedAction =
|
|
8
|
+
| { action: "press" | "click"; target: ActionTarget; params: { button?: MouseButtonName; clickCount?: number }; establishesFocus: boolean; usesCurrentFocus: false; needsForeground: boolean }
|
|
9
|
+
| { action: "setText"; target: ActionTarget; params: { text: string }; establishesFocus: false; usesCurrentFocus: false; needsForeground: false }
|
|
10
|
+
| { action: "typeText"; target: ActionTarget; params: { text: string }; establishesFocus: false; usesCurrentFocus: boolean; needsForeground: false }
|
|
11
|
+
| { action: "keypress"; target: ActionTarget; params: { keys: string[] }; establishesFocus: false; usesCurrentFocus: boolean; needsForeground: false }
|
|
12
|
+
| { action: "scroll"; target: ActionTarget; params: { scrollX: number; scrollY: number }; establishesFocus: false; usesCurrentFocus: false; needsForeground: false }
|
|
13
|
+
| { action: "drag"; target: ActionTarget; params: { path: Array<{ x: number; y: number }> }; establishesFocus: false; usesCurrentFocus: false; needsForeground: false }
|
|
14
|
+
| { action: "moveMouse"; target: ActionTarget; params: Record<string, never>; establishesFocus: false; usesCurrentFocus: false; needsForeground: false }
|
|
15
|
+
| { action: "wait"; params: { ms: number }; establishesFocus: false; usesCurrentFocus: false; needsForeground: false };
|
|
16
|
+
|
|
17
|
+
export interface ActionState {
|
|
18
|
+
currentFocus: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ActionEnvironment {
|
|
22
|
+
headless: boolean;
|
|
23
|
+
image?: { width: number; height: number };
|
|
24
|
+
node(ref: string): OutlineNode;
|
|
25
|
+
center(node: OutlineNode): { x: number; y: number };
|
|
26
|
+
validatePoint(x: number, y: number, label?: string): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function mouseButton(value: unknown): MouseButtonName {
|
|
30
|
+
return value === "right" || value === "middle" ? value : "left";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function clickCount(value: unknown, fallback = 1): number {
|
|
34
|
+
return Math.max(1, Math.min(3, Math.round(toFiniteNumber(value, fallback))));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function scrollDelta(value: unknown): number {
|
|
38
|
+
return Math.max(-10_000, Math.min(10_000, Math.round(toFiniteNumber(value, 0))));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function keys(value: unknown): string[] {
|
|
42
|
+
if (!Array.isArray(value) || value.length === 0) throw new Error("keypress.keys must contain at least one key.");
|
|
43
|
+
return value.map((key) => String(key));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function path(value: UiAction["path"], env: ActionEnvironment): Array<{ x: number; y: number }> {
|
|
47
|
+
if (!Array.isArray(value) || value.length < 2) throw new Error("drag.path must contain at least two points.");
|
|
48
|
+
return value.map((point, index) => {
|
|
49
|
+
const x = Array.isArray(point) ? toFiniteNumber(point[0], NaN) : toFiniteNumber(point?.x, NaN);
|
|
50
|
+
const y = Array.isArray(point) ? toFiniteNumber(point[1], NaN) : toFiniteNumber(point?.y, NaN);
|
|
51
|
+
env.validatePoint(x, y, `Drag point ${index + 1}`);
|
|
52
|
+
return { x, y };
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function nativeTarget(action: UiAction, operation: PreparedAction["action"], env: ActionEnvironment): ActionTarget {
|
|
57
|
+
if (action.ref?.trim()) {
|
|
58
|
+
const node = env.node(action.ref.trim());
|
|
59
|
+
const semanticClick = operation === "click" || operation === "press";
|
|
60
|
+
if (semanticClick && node.isTextInput) {
|
|
61
|
+
const point = env.center(node);
|
|
62
|
+
env.validatePoint(point.x, point.y);
|
|
63
|
+
return point;
|
|
64
|
+
}
|
|
65
|
+
const onlyIncidentalActions = node.actions.every((candidate) => INCIDENTAL_ACTIONS.has(candidate));
|
|
66
|
+
if (node.wireRef && !node.pictureOnly && (!semanticClick || node.canPress || node.canFocus || node.canSetValue || !onlyIncidentalActions)) {
|
|
67
|
+
return { ref: node.wireRef };
|
|
68
|
+
}
|
|
69
|
+
const point = env.center(node);
|
|
70
|
+
env.validatePoint(point.x, point.y);
|
|
71
|
+
return point;
|
|
72
|
+
}
|
|
73
|
+
const x = toFiniteNumber(action.x, NaN);
|
|
74
|
+
const y = toFiniteNumber(action.y, NaN);
|
|
75
|
+
if (Number.isFinite(x) && Number.isFinite(y)) {
|
|
76
|
+
env.validatePoint(x, y);
|
|
77
|
+
return { x, y };
|
|
78
|
+
}
|
|
79
|
+
if (operation === "drag" && action.path?.length) return path(action.path, env)[0];
|
|
80
|
+
throw new Error(`${operation} requires either ref or both x and y.`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function focusedTarget(env: ActionEnvironment): ActionTarget {
|
|
84
|
+
if (!env.image) throw new Error("Focused keyboard input requires an image-bearing state.");
|
|
85
|
+
return { focus: { x: Math.floor(env.image.width / 2), y: Math.floor(env.image.height / 2) } };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function containsEditable(node: OutlineNode): boolean {
|
|
89
|
+
if (node.canSetValue || node.role.toLowerCase().includes("text")) return true;
|
|
90
|
+
return node.children.some(containsEditable);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function prepareAction(action: UiAction, state: ActionState, env: ActionEnvironment): PreparedAction {
|
|
94
|
+
const operation = action.action;
|
|
95
|
+
const usesCurrentFocus = !env.headless && state.currentFocus && !action.ref && (operation === "typeText" || operation === "keypress");
|
|
96
|
+
const target = usesCurrentFocus ? focusedTarget(env) : nativeTarget(action, operation, env);
|
|
97
|
+
const establishesFocus = !env.headless && Boolean(action.ref) && (operation === "click" || operation === "press") && containsEditable(env.node(action.ref!));
|
|
98
|
+
const needsForeground = !env.headless && (operation === "click" || operation === "press") && "x" in target;
|
|
99
|
+
|
|
100
|
+
switch (operation) {
|
|
101
|
+
case "press":
|
|
102
|
+
case "click": return { action: operation, target, params: { button: mouseButton(action.button), clickCount: clickCount(action.clickCount) }, establishesFocus, usesCurrentFocus: false, needsForeground };
|
|
103
|
+
case "setText": return { action: operation, target, params: { text: action.text ?? "" }, establishesFocus: false, usesCurrentFocus: false, needsForeground: false };
|
|
104
|
+
case "typeText": return { action: operation, target, params: { text: action.text ?? "" }, establishesFocus: false, usesCurrentFocus, needsForeground: false };
|
|
105
|
+
case "keypress": return { action: operation, target, params: { keys: keys(action.keys) }, establishesFocus: false, usesCurrentFocus, needsForeground: false };
|
|
106
|
+
case "scroll": return { action: operation, target, params: { scrollX: scrollDelta(action.scrollX), scrollY: scrollDelta(action.scrollY) }, establishesFocus: false, usesCurrentFocus: false, needsForeground: false };
|
|
107
|
+
case "drag": return { action: operation, target, params: { path: path(action.path, env) }, establishesFocus: false, usesCurrentFocus: false, needsForeground: false };
|
|
108
|
+
case "moveMouse": return { action: operation, target, params: {}, establishesFocus: false, usesCurrentFocus: false, needsForeground: false };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function canRetryInForeground(action: PreparedAction, outcome: "worked" | "didnt" | "unknown", headless: boolean): boolean {
|
|
113
|
+
return !headless && outcome === "didnt" && (action.action === "typeText" || action.action === "keypress");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function outcomeAfterCheck(current: "worked" | "didnt" | "unknown", check: "verified" | "preexisting" | "failed"): "worked" | "didnt" | "unknown" {
|
|
117
|
+
if (check === "verified") return "worked";
|
|
118
|
+
if (check === "failed") return "didnt";
|
|
119
|
+
return current;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function outcomeAfterObservedValues(
|
|
123
|
+
current: "worked" | "didnt" | "unknown",
|
|
124
|
+
actions: UiAction[],
|
|
125
|
+
valueForRef: (ref: string) => string | undefined,
|
|
126
|
+
): "worked" | "didnt" | "unknown" {
|
|
127
|
+
if (actions.length === 0 || actions.some((action) => action.action !== "setText" || !action.ref)) return current;
|
|
128
|
+
const matches = actions.every((action) => valueForRef(action.ref!) === (action.text ?? ""));
|
|
129
|
+
return matches ? "worked" : current;
|
|
130
|
+
}
|