@parcha/agentrun-kernel 0.1.0-beta.36 → 0.1.0-beta.38
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 +91 -0
- package/dist/host/index.d.ts +2 -4
- package/dist/host/index.js +2 -3
- package/dist/host/overhead.d.ts +42 -0
- package/dist/host/overhead.js +84 -10
- package/dist/host/proxy.d.ts +34 -15
- package/dist/host/proxy.js +99 -25
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/kernel/cap/index.d.ts +4 -4
- package/dist/kernel/cap/index.js +3 -3
- package/dist/kernel/cap/port.d.ts +14 -3
- package/dist/kernel/cap/port.js +29 -16
- package/dist/kernel/cap/price.d.ts +31 -6
- package/dist/kernel/cap/price.js +49 -15
- package/dist/kernel/cap/rule.d.ts +11 -1
- package/dist/kernel/cap/rule.js +30 -3
- package/dist/kernel/cap/run-cap.d.ts +9 -2
- package/dist/kernel/cap/run-cap.js +8 -3
- package/dist/kernel/cap/types.d.ts +11 -5
- package/dist/kernel/registry/computer-surface.generated.d.ts +9 -0
- package/dist/kernel/registry/computer-surface.generated.js +618 -0
- package/dist/kernel/registry/computer.d.ts +14 -0
- package/dist/kernel/registry/computer.js +75 -0
- package/dist/kernel/registry/defs.d.ts +1 -4
- package/dist/kernel/registry/defs.js +1 -13
- package/dist/kernel/registry/handoff.js +4 -4
- package/dist/kernel/registry/hands.d.ts +22 -115
- package/dist/kernel/registry/hands.js +0 -2
- package/dist/kernel/registry/index.d.ts +4 -4
- package/dist/kernel/registry/index.js +5 -5
- package/dist/kernel/registry/registry.d.ts +4 -5
- package/dist/kernel/registry/registry.js +27 -29
- package/dist/kernel/types.d.ts +10 -2
- package/dist/process/tools.d.ts +5 -1
- package/dist/process/tools.js +62 -8
- package/dist/run-booking.d.ts +3 -0
- package/dist/run-booking.js +7 -0
- package/dist/runner.d.ts +21 -2
- package/dist/runner.js +126 -11
- package/dist/testing.d.ts +6 -2
- package/dist/testing.js +5 -3
- package/dist/tool-deferral.d.ts +12 -0
- package/dist/tool-deferral.js +17 -0
- package/dist/types.d.ts +83 -39
- package/package.json +2 -2
- package/dist/host/mcp-route.d.ts +0 -14
- package/dist/host/mcp-route.js +0 -125
- package/dist/kernel/registry/desktop.d.ts +0 -11
- package/dist/kernel/registry/desktop.js +0 -90
- package/dist/kernel/registry/phone.d.ts +0 -15
- package/dist/kernel/registry/phone.js +0 -135
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ACT_STEPS, COMPUTER_TOOL_SCHEMAS, computerDeclarations } from "./computer-surface.generated.js";
|
|
2
|
+
import { answerOf, needsKindWords } from "./hands.js";
|
|
3
|
+
import { HANDOFF_TOOL, handoffDef, handoffExecutor } from "./handoff.js";
|
|
4
|
+
/** The computer's tools, in the order a run lists them (the hand-over last). */
|
|
5
|
+
export const COMPUTER_TOOLS = ["computer_observe", "computer_act", "computer_screenshot", "computer_script", HANDOFF_TOOL];
|
|
6
|
+
/** The tool a host runs itself: a script runs in the host's isolate, over the same port. */
|
|
7
|
+
export const SCRIPT_TOOL = "computer_script";
|
|
8
|
+
// The words are short on purpose: every request of a run with a computer carries them. The kind skill (desktop-computer,
|
|
9
|
+
// phone-computer) teaches how to work; a description says only what its tool does.
|
|
10
|
+
const OBSERVE = `An app's window as its elements, one line each (@e12 button "Save"), under a head line naming the state (s7). With no ui group: a screenshot.`;
|
|
11
|
+
const ACT = `Run steps on an app, each on an element's ref or at a point in the window (refused as stale once the window changed under it). The answer says how each step ran and whether the window changed. The first refused step stops the rest. steps: UiStep[]\n\`\`\`ts\n${ACT_STEPS}\n\`\`\``;
|
|
12
|
+
const SCREENSHOT = "The whole screen as an image, or a region of it.";
|
|
13
|
+
/** computer_script's words: what a script is, and the `computer` object's declarations for these groups. */
|
|
14
|
+
const scriptWords = (groups) => `Run JavaScript with \`computer\` bound: many steps in one call. Return only what you need; text() and image() show words and pictures. A refused step throws.\n\`\`\`ts\n${computerDeclarations(groups)}\n\`\`\``;
|
|
15
|
+
/** The tools a computer with `groups` offers: observe and act with the ui group, or a screen (observe) and input (act)
|
|
16
|
+
* without it; the screenshot with a screen; the script with any of them. */
|
|
17
|
+
export function computerToolsFor(groups) {
|
|
18
|
+
const has = (group) => groups.includes(group);
|
|
19
|
+
const input = has("input.pointer") || has("input.touch") || has("input.keys");
|
|
20
|
+
const observe = has("ui") || has("screen");
|
|
21
|
+
const act = has("ui") || input;
|
|
22
|
+
return [...(observe ? ["computer_observe"] : []), ...(act ? ["computer_act"] : []), ...(has("screen") ? ["computer_screenshot"] : []), ...(observe || act ? [SCRIPT_TOOL] : []), HANDOFF_TOOL];
|
|
23
|
+
}
|
|
24
|
+
/** computer_act's parameters on a computer with no ui group: no expect, which only the ui group checks, so neither the
|
|
25
|
+
* expect nor the wait on one (an empty act with an expect) is offered there. */
|
|
26
|
+
const ACT_WITHOUT_UI = (() => {
|
|
27
|
+
const schema = COMPUTER_TOOL_SCHEMAS.computer_act;
|
|
28
|
+
const { expect: _, ...properties } = schema.properties;
|
|
29
|
+
return { ...schema, properties: { ...properties, steps: { ...properties.steps, description: "Run in order." } } };
|
|
30
|
+
})();
|
|
31
|
+
const def = (kind, name, description, replaySafe, parameters = COMPUTER_TOOL_SCHEMAS[name]) => ({
|
|
32
|
+
name,
|
|
33
|
+
source: "host",
|
|
34
|
+
gateName: `host:${kind}/${name}`,
|
|
35
|
+
settingsKey: kind,
|
|
36
|
+
description,
|
|
37
|
+
parameters,
|
|
38
|
+
replaySafe,
|
|
39
|
+
});
|
|
40
|
+
/** The computer's tools in `kind`, under its settings key, for a computer with `groups` (the script's declarations
|
|
41
|
+
* hold only what they offer). A script and an act change the computer: never replayed. */
|
|
42
|
+
export function computerToolDefs(kind, groups) {
|
|
43
|
+
return Object.freeze([
|
|
44
|
+
// With apps and no ui group, an observe that names an app opens it first: it changes the screen, so it never runs again.
|
|
45
|
+
def(kind, "computer_observe", OBSERVE, groups.includes("ui") || !groups.includes("apps")),
|
|
46
|
+
def(kind, "computer_act", ACT, false, groups.includes("ui") ? undefined : ACT_WITHOUT_UI),
|
|
47
|
+
def(kind, "computer_screenshot", SCREENSHOT, true),
|
|
48
|
+
def(kind, "computer_script", scriptWords(groups), false),
|
|
49
|
+
handoffDef(kind),
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
/** A value with its images' data left out: they travel in the answer's images. */
|
|
53
|
+
const withoutImageData = (value) => {
|
|
54
|
+
if (Array.isArray(value))
|
|
55
|
+
return value.map(withoutImageData);
|
|
56
|
+
if (value === null || typeof value !== "object")
|
|
57
|
+
return value;
|
|
58
|
+
const record = value;
|
|
59
|
+
return Object.fromEntries(Object.entries(record).filter(([key]) => !(key === "data" && record.type === "image")).map(([key, entry]) => [key, withoutImageData(entry)]));
|
|
60
|
+
};
|
|
61
|
+
/** A tool's run on the hands' computer port: the surface's op, answered as its text, its images and its value. */
|
|
62
|
+
const surfaceExecutor = (kind, tool, op) => (args, call) => answerOf(call, async () => {
|
|
63
|
+
const port = call.hands.computer;
|
|
64
|
+
if (!port)
|
|
65
|
+
throw new Error(needsKindWords(tool, kind));
|
|
66
|
+
const answer = await port.call(op, args ?? {}, call.signal);
|
|
67
|
+
return { text: answer.text, ...(answer.images.length > 0 ? { images: answer.images } : {}), structured: (withoutImageData(answer.value) ?? null) };
|
|
68
|
+
});
|
|
69
|
+
/** The kernel's own executors of the computer's tools in `kind`: all but the script, which the host runs. */
|
|
70
|
+
export const computerExecutors = (kind) => ({
|
|
71
|
+
computer_observe: surfaceExecutor(kind, "computer_observe", "observe"),
|
|
72
|
+
computer_act: surfaceExecutor(kind, "computer_act", "act"),
|
|
73
|
+
computer_screenshot: surfaceExecutor(kind, "computer_screenshot", "screenshot"),
|
|
74
|
+
[HANDOFF_TOOL]: handoffExecutor(kind),
|
|
75
|
+
});
|
|
@@ -32,8 +32,5 @@ export declare function hostToolDefs(options: {
|
|
|
32
32
|
maxExecS: number;
|
|
33
33
|
shell: ShellPlace;
|
|
34
34
|
}): readonly ToolDef[];
|
|
35
|
-
/** The kinds
|
|
35
|
+
/** The kinds whose computer brings the computer's tools, each under its own settings key. */
|
|
36
36
|
export declare const CAPABILITY_KINDS: readonly CapabilityKind[];
|
|
37
|
-
/** A computer kind's own tools, which a run of that kind sees after its host tools: the desktop's (desktop.ts) or the
|
|
38
|
-
* phone's (phone.ts). */
|
|
39
|
-
export declare function capabilityToolDefs(kind: CapabilityKind): readonly ToolDef[];
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
// Every model-visible host tool's definition: its name, words, schema and replay, as main shows them today. read, write,
|
|
2
|
-
// edit and bash are pi's (pi 1.5.0's coding tools, MIT), with serve's additions: bash's timeout words and read's image
|
|
3
|
-
// sentence on a computer. The five background tools are serve's (background.ts). A test holds every one of them, in
|
|
4
|
-
// order, to serve's own on main. A computer of a kind past files and a shell adds its own tools after them
|
|
5
|
-
// (capabilityToolDefs): the desktop's, the phone's.
|
|
6
|
-
import { DESKTOP_TOOL_DEFS } from "./desktop.js";
|
|
7
|
-
import { PHONE_TOOL_DEFS } from "./phone.js";
|
|
8
1
|
import { BACKGROUND_INPUT_BYTES, BACKGROUND_LIST_MAX, BACKGROUND_LOG_BYTES, BACKGROUND_MAX, BACKGROUND_PAGE_BYTES, BACKGROUND_SIGNALS, BASH_DEFAULT_TIMEOUT_S } from "./limits.js";
|
|
9
2
|
const READ_WORDS = "Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to 2000 lines or 50KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.";
|
|
10
3
|
/** read's sentence on a computer: it opens an image anywhere in the computer. */
|
|
@@ -139,10 +132,5 @@ export function hostToolDefs(options) {
|
|
|
139
132
|
defs.push(host(tool.name, "shell", tool.description, tool.parameters, tool.replaySafe, tool.name === "bash_output" || tool.name === "bash_list" || tool.name === "bash_signal"));
|
|
140
133
|
return defs;
|
|
141
134
|
}
|
|
142
|
-
/** The kinds
|
|
135
|
+
/** The kinds whose computer brings the computer's tools, each under its own settings key. */
|
|
143
136
|
export const CAPABILITY_KINDS = Object.freeze(["desktop", "phone"]);
|
|
144
|
-
/** A computer kind's own tools, which a run of that kind sees after its host tools: the desktop's (desktop.ts) or the
|
|
145
|
-
* phone's (phone.ts). */
|
|
146
|
-
export function capabilityToolDefs(kind) {
|
|
147
|
-
return kind === "desktop" ? DESKTOP_TOOL_DEFS : PHONE_TOOL_DEFS;
|
|
148
|
-
}
|
|
@@ -4,14 +4,14 @@ export const HANDOFF_TOOL = "computer_request_handoff";
|
|
|
4
4
|
export const HANDOFF_DEFAULT_S = 600;
|
|
5
5
|
export const HANDOFF_MIN_S = 30;
|
|
6
6
|
export const HANDOFF_MAX_S = 3600;
|
|
7
|
-
const DESCRIPTION = `Hand the computer to the person for a step
|
|
7
|
+
const DESCRIPTION = `Hand the computer to the person for a step only they should do (their password, a captcha, a payment, their choice), and wait until they answer or the ask expires. The screen may have changed after.`;
|
|
8
8
|
const PARAMETERS = {
|
|
9
9
|
type: "object",
|
|
10
10
|
additionalProperties: false,
|
|
11
11
|
properties: {
|
|
12
|
-
instruction: { type: "string", minLength: 1, description: "What the person should do
|
|
13
|
-
completion_condition: { type: "string", minLength: 1, description: "
|
|
14
|
-
expires_in_s: { type: "integer", minimum: HANDOFF_MIN_S, maximum: HANDOFF_MAX_S, description: `
|
|
12
|
+
instruction: { type: "string", minLength: 1, description: "What the person should do." },
|
|
13
|
+
completion_condition: { type: "string", minLength: 1, description: "What the screen shows once it is done." },
|
|
14
|
+
expires_in_s: { type: "integer", minimum: HANDOFF_MIN_S, maximum: HANDOFF_MAX_S, description: `Default ${HANDOFF_DEFAULT_S}.` },
|
|
15
15
|
},
|
|
16
16
|
required: ["instruction", "completion_condition"],
|
|
17
17
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ToolImage } from "../../types.js";
|
|
1
|
+
import type { JsonValue, ToolImage } from "../../types.js";
|
|
2
2
|
/** How one exec ended: its exit code, or the signal that ended it (exitCode null), and whether its timeout did. */
|
|
3
3
|
export type ExecResult = {
|
|
4
4
|
readonly exitCode: number | null;
|
|
@@ -60,118 +60,23 @@ export type Processes = {
|
|
|
60
60
|
}>;
|
|
61
61
|
list(): Promise<readonly ProcessInfo[]>;
|
|
62
62
|
};
|
|
63
|
-
/** A computer's kind past files and a shell: each adds
|
|
63
|
+
/** A computer's kind past files and a shell: each adds the computer's tools to the run's (computer.ts COMPUTER_TOOLS). */
|
|
64
64
|
export type CapabilityKind = "desktop" | "phone";
|
|
65
65
|
/** A kind's tool refused in a run whose computer is not of that kind (or lacks the port): the words name the setting. */
|
|
66
66
|
export declare const needsKindWords: (tool: string, kind: CapabilityKind) => string;
|
|
67
|
-
/**
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
export type ScreenPoint = readonly [x: number, y: number];
|
|
71
|
-
/** A screenshot: its PNG's bytes, and its size in pixels (the coordinates input takes). */
|
|
72
|
-
export type Shot = {
|
|
73
|
-
readonly png: Uint8Array;
|
|
74
|
-
readonly width: number;
|
|
75
|
-
readonly height: number;
|
|
76
|
-
};
|
|
77
|
-
/** A desktop's screen (computerd's screen.shot): the whole screen, or a region of it in the whole screen's pixels. */
|
|
78
|
-
export type Screen = {
|
|
79
|
-
shot(options?: {
|
|
80
|
-
readonly region?: {
|
|
81
|
-
readonly x: number;
|
|
82
|
-
readonly y: number;
|
|
83
|
-
readonly w: number;
|
|
84
|
-
readonly h: number;
|
|
85
|
-
};
|
|
86
|
-
}): Promise<Shot>;
|
|
87
|
-
};
|
|
88
|
-
/** One action of a desktop's input, as computerd's input.actions takes it: the pointer's and the keyboard's, and
|
|
89
|
-
* nothing more. A key is a name of computerd's key table or one printable ASCII character. */
|
|
90
|
-
export type InputAction = {
|
|
91
|
-
readonly type: "move";
|
|
92
|
-
readonly at: ScreenPoint;
|
|
93
|
-
} | {
|
|
94
|
-
readonly type: "click";
|
|
95
|
-
readonly at?: ScreenPoint;
|
|
96
|
-
readonly button?: "left" | "right" | "middle";
|
|
97
|
-
readonly count?: 1 | 2 | 3;
|
|
98
|
-
} | {
|
|
99
|
-
readonly type: "drag";
|
|
100
|
-
readonly path: readonly ScreenPoint[];
|
|
101
|
-
readonly button?: "left" | "right" | "middle";
|
|
102
|
-
} | {
|
|
103
|
-
readonly type: "scroll";
|
|
104
|
-
readonly at?: ScreenPoint;
|
|
105
|
-
readonly dx?: number;
|
|
106
|
-
readonly dy?: number;
|
|
107
|
-
readonly unit: "clicks" | "px";
|
|
108
|
-
} | {
|
|
109
|
-
readonly type: "type";
|
|
67
|
+
/** One answer of the run's computer: the value a script gets, the text a model reads, and the images beside it. */
|
|
68
|
+
export type ComputerAnswer = {
|
|
69
|
+
readonly value: unknown;
|
|
110
70
|
readonly text: string;
|
|
111
|
-
|
|
112
|
-
readonly type: "key";
|
|
113
|
-
readonly keys: readonly string[];
|
|
114
|
-
};
|
|
115
|
-
/** A desktop's input (computerd's input.actions): the batch runs in order; a refusal throws its code and words. */
|
|
116
|
-
export type Input = {
|
|
117
|
-
actions(list: readonly InputAction[]): Promise<void>;
|
|
71
|
+
readonly images: readonly ToolImage[];
|
|
118
72
|
};
|
|
119
|
-
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
export type PhoneNode = {
|
|
127
|
-
readonly role: string;
|
|
128
|
-
readonly id?: string;
|
|
129
|
-
readonly text?: string;
|
|
130
|
-
readonly label?: string;
|
|
131
|
-
readonly bounds: {
|
|
132
|
-
readonly x: number;
|
|
133
|
-
readonly y: number;
|
|
134
|
-
readonly w: number;
|
|
135
|
-
readonly h: number;
|
|
136
|
-
};
|
|
137
|
-
readonly clickable: boolean;
|
|
138
|
-
readonly editable: boolean;
|
|
139
|
-
readonly focused?: boolean;
|
|
140
|
-
/** A node with no text or label of its own, named by its first inner text (else label): an Android list row, a
|
|
141
|
-
* clickable layout whose title sits on a child that is not clickable. */
|
|
142
|
-
readonly inner?: string;
|
|
143
|
-
};
|
|
144
|
-
/** A key a phone presses: its back and home buttons, and enter. */
|
|
145
|
-
export type PhoneKey = "back" | "home" | "enter";
|
|
146
|
-
/** A phone: its screen and the screen's structure, a tap, a swipe, typing into the field in focus, its keys, and its apps. */
|
|
147
|
-
export type Phone = {
|
|
148
|
-
shot(): Promise<Shot>;
|
|
149
|
-
/** The screen's structure, flattened (`total` the nodes the phone gave, `truncated` when it gave only part); absent on a
|
|
150
|
-
* phone that does not offer it. */
|
|
151
|
-
tree?(): Promise<{
|
|
152
|
-
readonly nodes: readonly PhoneNode[];
|
|
153
|
-
readonly total: number;
|
|
154
|
-
readonly truncated: boolean;
|
|
155
|
-
}>;
|
|
156
|
-
tap(at: PhonePoint): Promise<void>;
|
|
157
|
-
swipe(spec: {
|
|
158
|
-
readonly from: PhonePoint;
|
|
159
|
-
readonly to: PhonePoint;
|
|
160
|
-
readonly durationMs: number;
|
|
161
|
-
}): Promise<void>;
|
|
162
|
-
type(text: string): Promise<void>;
|
|
163
|
-
/** Absent on a phone that does not offer its keys. */
|
|
164
|
-
key?(name: PhoneKey): Promise<void>;
|
|
165
|
-
readonly apps: {
|
|
166
|
-
list(): Promise<{
|
|
167
|
-
readonly apps: readonly {
|
|
168
|
-
readonly id: string;
|
|
169
|
-
readonly name?: string;
|
|
170
|
-
}[];
|
|
171
|
-
readonly foreground: string | null;
|
|
172
|
-
}>;
|
|
173
|
-
open(id: string): Promise<void>;
|
|
174
|
-
};
|
|
73
|
+
/** The run's computer as its tools reach it: its groups (its hello's), and one call per op (observe, act, screenshot,
|
|
74
|
+
* input.act, apps.list, apps.open, shell.run, processes.start, files.read, files.write, files.list, files.stat), which
|
|
75
|
+
* @parcha/agentrun-computer's surface answers the same for a per-step tool, a script and the claim's MCP endpoint. A
|
|
76
|
+
* refusal throws an error with a `kind` (stale, unsupported, ...) and the computer's words; an abort throws. */
|
|
77
|
+
export type ComputerPort = {
|
|
78
|
+
readonly groups: readonly string[];
|
|
79
|
+
call(op: string, args: unknown, signal?: AbortSignal): Promise<ComputerAnswer>;
|
|
175
80
|
};
|
|
176
81
|
/** The agent's hand-over of a desktop or a phone to the person, through the run's hold: ask opens it (what the person is
|
|
177
82
|
* to do, how both will know it is done, when it expires, ISO time) and resolves with its first answer, or expired. An
|
|
@@ -222,11 +127,9 @@ export type Hands = {
|
|
|
222
127
|
}, signal?: AbortSignal): Promise<ExecResult>;
|
|
223
128
|
/** The attached computer's processes; absent with no computer, where the background tools are refused. */
|
|
224
129
|
readonly processes?: Processes;
|
|
225
|
-
/** A desktop's
|
|
226
|
-
|
|
227
|
-
readonly
|
|
228
|
-
/** A phone's screen, touch, typing and apps; absent where the computer is no phone. */
|
|
229
|
-
readonly phone?: Phone;
|
|
130
|
+
/** A desktop's or a phone's surface (computer_observe, computer_act, computer_screenshot, computer_script); absent
|
|
131
|
+
* where the computer is neither, and those tools are refused in words. */
|
|
132
|
+
readonly computer?: ComputerPort;
|
|
230
133
|
/** A desktop's or a phone's hand-over to the person (the run's hold); absent where there is none. */
|
|
231
134
|
readonly handoff?: Handoff;
|
|
232
135
|
};
|
|
@@ -237,6 +140,9 @@ export type ToolAnswer = {
|
|
|
237
140
|
readonly text: string;
|
|
238
141
|
readonly error?: string;
|
|
239
142
|
readonly images?: readonly ToolImage[];
|
|
143
|
+
/** The answer as a value, for a script that called the tool (Codex's code mode, an MCP client's structuredContent):
|
|
144
|
+
* the computer's tools give the surface's value, its images' data left out (they travel in `images`). */
|
|
145
|
+
readonly structured?: JsonValue;
|
|
240
146
|
readonly details?: unknown;
|
|
241
147
|
readonly isError?: boolean;
|
|
242
148
|
readonly diagnostics?: readonly {
|
|
@@ -257,5 +163,6 @@ export type ToolCall = {
|
|
|
257
163
|
export declare function answerOf(call: ToolCall, run: () => Promise<ToolAnswer>): Promise<ToolAnswer>;
|
|
258
164
|
/** A host tool's run. */
|
|
259
165
|
export type Executor = (args: unknown, call: ToolCall) => Promise<ToolAnswer>;
|
|
260
|
-
/** What the host gives the registry, by tool name: read, write and edit,
|
|
261
|
-
|
|
166
|
+
/** What the host gives the registry, by tool name: read, write and edit, bash's own run, which the registry bounds, and
|
|
167
|
+
* computer_script's run in the host's isolate (listed only where the host gives it). */
|
|
168
|
+
export type HostExecutors = Readonly<Partial<Record<"read" | "write" | "edit" | "bash" | "computer_script", Executor>>>;
|
|
@@ -13,8 +13,6 @@ export function exitCodeOf(result) {
|
|
|
13
13
|
}
|
|
14
14
|
/** A kind's tool refused in a run whose computer is not of that kind (or lacks the port): the words name the setting. */
|
|
15
15
|
export const needsKindWords = (tool, kind) => `${tool} needs a ${kind} computer: set this agent's computer to ${kind} (Settings → Computers).`;
|
|
16
|
-
/** A screenshot as a tool's answer: the words, and the PNG in the answer's images. */
|
|
17
|
-
export const shotAnswer = (text, shot) => ({ text, images: [{ mimeType: "image/png", data: Buffer.from(shot.png.buffer, shot.png.byteOffset, shot.png.byteLength).toString("base64") }] });
|
|
18
16
|
/** An executor's failure as an answer: an abort (the call's signal aborted) throws; any other error is its words. */
|
|
19
17
|
export async function answerOf(call, run) {
|
|
20
18
|
try {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export { BACKGROUND_EXECUTORS, endBackground, NEEDS_A_COMPUTER, NO_SHELL } from "./background.js";
|
|
2
2
|
export { boundedBash } from "./bash.js";
|
|
3
|
-
export { bashTimeoutWords, CAPABILITY_KINDS,
|
|
3
|
+
export { bashTimeoutWords, CAPABILITY_KINDS, hostToolDefs } from "./defs.js";
|
|
4
4
|
export type { ShellPlace, ToolDef } from "./defs.js";
|
|
5
|
-
export {
|
|
5
|
+
export { COMPUTER_TOOLS, computerExecutors, computerToolDefs, computerToolsFor, SCRIPT_TOOL } from "./computer.js";
|
|
6
|
+
export { COMPUTER_TOOL_SCHEMAS, computerDeclarations } from "./computer-surface.generated.js";
|
|
6
7
|
export { defaultPermissionOf, SHELL_FAMILY, SHELL_WATCHERS, shellPermission, shellToolOf } from "./gate.js";
|
|
7
8
|
export type { Permission } from "./gate.js";
|
|
8
9
|
export { answerOf, exitCodeOf, needsKindWords } from "./hands.js";
|
|
9
|
-
export type { CapabilityKind, ExecResult, Executor, Hands, HostExecutors,
|
|
10
|
-
export { PHONE_EXECUTORS, PHONE_KEYS, PHONE_SWIPE_MAX_MS, PHONE_SWIPE_MS, PHONE_TOOL_DEFS, PHONE_TREE_MAX_CHARS, PHONE_TREE_MAX_NODES } from "./phone.js";
|
|
10
|
+
export type { CapabilityKind, ComputerAnswer, ComputerPort, ExecResult, Executor, Hands, HostExecutors, ProcessInfo, Processes, ToolAnswer, ToolCall } from "./hands.js";
|
|
11
11
|
export { HANDOFF_DEFAULT_S, HANDOFF_MAX_S, HANDOFF_MIN_S, HANDOFF_TOOL } from "./handoff.js";
|
|
12
12
|
export type { Handoff } from "./hands.js";
|
|
13
13
|
export { BACKGROUND_DIR, BACKGROUND_INPUT_BYTES, BACKGROUND_LIST_MAX, BACKGROUND_LOG_BYTES, BACKGROUND_MAX, BACKGROUND_PAGE_BYTES, BACKGROUND_SIGNALS, BACKGROUND_TOOLS, BASH_DEFAULT_TIMEOUT_S, READ_IMAGE_MAX_BYTES, SHELL_TOOLS, } from "./limits.js";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// The kernel's one tool registry: the host tools' definitions, words and limits, the gate's shell family, the run's
|
|
2
|
-
// hands, and the executors the kernel owns; a
|
|
3
|
-
//
|
|
2
|
+
// hands, and the executors the kernel owns; a desktop's or a phone's computer tools and the one port they run on. A
|
|
3
|
+
// browser computer's tools are the host's browser tool's (serve's tools.ts, pi-browser's durable extension), not
|
|
4
4
|
// the registry's.
|
|
5
5
|
export { BACKGROUND_EXECUTORS, endBackground, NEEDS_A_COMPUTER, NO_SHELL } from "./background.js";
|
|
6
6
|
export { boundedBash } from "./bash.js";
|
|
7
|
-
export { bashTimeoutWords, CAPABILITY_KINDS,
|
|
8
|
-
export {
|
|
7
|
+
export { bashTimeoutWords, CAPABILITY_KINDS, hostToolDefs } from "./defs.js";
|
|
8
|
+
export { COMPUTER_TOOLS, computerExecutors, computerToolDefs, computerToolsFor, SCRIPT_TOOL } from "./computer.js";
|
|
9
|
+
export { COMPUTER_TOOL_SCHEMAS, computerDeclarations } from "./computer-surface.generated.js";
|
|
9
10
|
export { defaultPermissionOf, SHELL_FAMILY, SHELL_WATCHERS, shellPermission, shellToolOf } from "./gate.js";
|
|
10
11
|
export { answerOf, exitCodeOf, needsKindWords } from "./hands.js";
|
|
11
|
-
export { PHONE_EXECUTORS, PHONE_KEYS, PHONE_SWIPE_MAX_MS, PHONE_SWIPE_MS, PHONE_TOOL_DEFS, PHONE_TREE_MAX_CHARS, PHONE_TREE_MAX_NODES } from "./phone.js";
|
|
12
12
|
export { HANDOFF_DEFAULT_S, HANDOFF_MAX_S, HANDOFF_MIN_S, HANDOFF_TOOL } from "./handoff.js";
|
|
13
13
|
export { BACKGROUND_DIR, BACKGROUND_INPUT_BYTES, BACKGROUND_LIST_MAX, BACKGROUND_LOG_BYTES, BACKGROUND_MAX, BACKGROUND_PAGE_BYTES, BACKGROUND_SIGNALS, BACKGROUND_TOOLS, BASH_DEFAULT_TIMEOUT_S, READ_IMAGE_MAX_BYTES, SHELL_TOOLS, } from "./limits.js";
|
|
14
14
|
export { createRegistry } from "./registry.js";
|
|
@@ -6,14 +6,13 @@ export type Registry = {
|
|
|
6
6
|
get(name: string): ToolDef | undefined;
|
|
7
7
|
invoke(name: string, args: unknown, call: ToolCall): Promise<ToolAnswer>;
|
|
8
8
|
};
|
|
9
|
-
/** The registry of a run's host tools, by where its shell is, and its computer's
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* the model; one called anyway runs, and its port's absence answers in words. */
|
|
9
|
+
/** The registry of a run's host tools, by where its shell is, and its computer's kind (`kinds`: none, or the desktop or
|
|
10
|
+
* the phone it is) with its groups (`groups`, its hello's: which of the computer's tools it offers), with the host's
|
|
11
|
+
* executors. */
|
|
13
12
|
export declare function createRegistry(options: {
|
|
14
13
|
maxExecS: number;
|
|
15
14
|
shell: ShellPlace;
|
|
16
15
|
kinds?: readonly CapabilityKind[];
|
|
16
|
+
groups?: readonly string[];
|
|
17
17
|
executors: HostExecutors;
|
|
18
|
-
without?: readonly string[];
|
|
19
18
|
}): Registry;
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
// The kernel's one registry of host tools: the model-visible definitions (defs.ts), each with its executor. read,
|
|
2
2
|
// write and edit, and bash's own run, are the host's (pi's tools over the run's hands, until their semantics move
|
|
3
|
-
// here); the kernel bounds bash and runs the five background tools itself. A
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
3
|
+
// here); the kernel bounds bash and runs the five background tools itself. A desktop or a phone adds the computer's
|
|
4
|
+
// tools after them (computer.ts), as its groups offer them, under its kind's settings key: observe, act and screenshot
|
|
5
|
+
// run on the kernel's own executors over the hands' computer port; computer_script runs in the host's isolate, listed
|
|
6
|
+
// only where the host gives it. A registry missing an executor for a tool the model sees is refused when it is built,
|
|
7
|
+
// so a run never offers a tool it cannot run. A computer's tool the run does not have is refused in words that name
|
|
8
|
+
// the setting.
|
|
8
9
|
import { BACKGROUND_EXECUTORS, NEEDS_A_COMPUTER, NO_SHELL } from "./background.js";
|
|
9
10
|
import { boundedBash } from "./bash.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
11
|
+
import { COMPUTER_TOOLS, computerExecutors, computerToolDefs, computerToolsFor, SCRIPT_TOOL } from "./computer.js";
|
|
12
|
+
import { CAPABILITY_KINDS, hostToolDefs } from "./defs.js";
|
|
12
13
|
import { answerOf, needsKindWords } from "./hands.js";
|
|
13
14
|
import { BACKGROUND_TOOLS } from "./limits.js";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
* tools this run's computer does not offer (its capabilities lack them: an iPhone's tree and keys, say), not listed to
|
|
18
|
-
* the model; one called anyway runs, and its port's absence answers in words. */
|
|
15
|
+
/** The registry of a run's host tools, by where its shell is, and its computer's kind (`kinds`: none, or the desktop or
|
|
16
|
+
* the phone it is) with its groups (`groups`, its hello's: which of the computer's tools it offers), with the host's
|
|
17
|
+
* executors. */
|
|
19
18
|
export function createRegistry(options) {
|
|
20
19
|
const { shell, executors } = options;
|
|
21
|
-
const
|
|
20
|
+
const kind = CAPABILITY_KINDS.find((each) => options.kinds?.includes(each));
|
|
22
21
|
const own = hostToolDefs({ maxExecS: options.maxExecS, shell });
|
|
23
22
|
const runs = new Map();
|
|
24
23
|
for (const def of own) {
|
|
@@ -30,24 +29,21 @@ export function createRegistry(options) {
|
|
|
30
29
|
runs.set(def.name, run);
|
|
31
30
|
}
|
|
32
31
|
const defs = [...own];
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
if (kind) {
|
|
33
|
+
const groups = options.groups ?? [];
|
|
34
|
+
const offered = computerToolsFor(groups);
|
|
35
|
+
const kernel = computerExecutors(kind);
|
|
36
|
+
for (const def of computerToolDefs(kind, groups)) {
|
|
37
|
+
if (!offered.includes(def.name))
|
|
37
38
|
continue;
|
|
38
|
-
const run =
|
|
39
|
+
const run = def.name === SCRIPT_TOOL ? executors.computer_script : kernel[def.name];
|
|
40
|
+
// The script is the host's to run (its isolate): a host that gives none lists none.
|
|
39
41
|
if (!run)
|
|
40
|
-
|
|
42
|
+
continue;
|
|
41
43
|
runs.set(def.name, run);
|
|
42
|
-
|
|
43
|
-
defs.push(def);
|
|
44
|
+
defs.push(def);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
|
-
// Every kind's tool by name, the run's or not, for the refusal of one it does not have.
|
|
47
|
-
const kindOf = new Map([
|
|
48
|
-
...DESKTOP_TOOL_DEFS.map((def) => [def.name, "desktop"]),
|
|
49
|
-
...PHONE_TOOL_DEFS.map((def) => [def.name, "phone"]),
|
|
50
|
-
]);
|
|
51
47
|
const byName = new Map(defs.map((def) => [def.name, def]));
|
|
52
48
|
return {
|
|
53
49
|
list: () => defs,
|
|
@@ -63,9 +59,11 @@ export function createRegistry(options) {
|
|
|
63
59
|
// No shell at all: bash is not listed, and a call of it anyway says how to get one.
|
|
64
60
|
if (shell === "none" && name === "bash")
|
|
65
61
|
throw new Error(NO_SHELL);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
if (COMPUTER_TOOLS.includes(name)) {
|
|
63
|
+
if (kind)
|
|
64
|
+
throw new Error(`${name} is not offered by this ${kind} computer: it offers ${(options.groups ?? []).join(", ") || "no groups"}`);
|
|
65
|
+
throw new Error(`${needsKindWords(name, "desktop")} A phone computer has it too.`);
|
|
66
|
+
}
|
|
69
67
|
throw new Error(`there is no host tool ${name} in this run`);
|
|
70
68
|
});
|
|
71
69
|
},
|
package/dist/kernel/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { JsonValue, SessionWriter, ToolImage } from "../types.js";
|
|
1
|
+
import type { JsonValue, NestedCalls, SessionWriter, ToolImage } from "../types.js";
|
|
2
2
|
export type ReplayPolicy = "safe" | "never";
|
|
3
3
|
export type SubmissionKind = "prompt" | "steer" | "followUp" | "withdraw";
|
|
4
4
|
/** One input a person sent the session, as the host recorded it. */
|
|
@@ -104,19 +104,27 @@ export interface HostTool<Input = any> {
|
|
|
104
104
|
description: string;
|
|
105
105
|
inputSchema: object;
|
|
106
106
|
replay: ReplayPolicy;
|
|
107
|
+
/** It only calls the session's other tools, each a call of its own (HostToolIO `nested`): the bridge writes no effect
|
|
108
|
+
* of its own for it, so a crash leaves it to run again, its nested calls answered from their records. */
|
|
109
|
+
nests?: true;
|
|
110
|
+
/** Callable by name (a nested call) but never listed to the model (the bridge leaves it out of `tools`). */
|
|
111
|
+
deferred?: true;
|
|
107
112
|
/** Its answer: the text, or the text with the images it shows. Recorded as the call's outcome, so a call answered
|
|
108
113
|
* from the record answers with the same images. */
|
|
109
114
|
execute(input: Input, io: HostToolIO): Promise<string | ToolOutput>;
|
|
110
115
|
}
|
|
111
|
-
/** A tool's answer with images. */
|
|
116
|
+
/** A tool's answer with images, and its value where it gives one (a computer tool's: what a script reads). */
|
|
112
117
|
export interface ToolOutput {
|
|
113
118
|
text: string;
|
|
114
119
|
images?: readonly ToolImage[];
|
|
120
|
+
structured?: JsonValue;
|
|
115
121
|
}
|
|
116
122
|
export interface HostToolIO {
|
|
117
123
|
signal: AbortSignal;
|
|
118
124
|
progress(chunk: unknown): void;
|
|
119
125
|
ctx: DriveContext;
|
|
120
126
|
stepId?: string;
|
|
127
|
+
/** For a tool that `nests`: the session's other tools by their names on the bridge, each call one of its own. */
|
|
128
|
+
nested?: NestedCalls;
|
|
121
129
|
}
|
|
122
130
|
export type { JsonValue };
|
package/dist/process/tools.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DriveContext, type EffectError, type HostTool, type ReplayPolicy } from '../kernel/index.js';
|
|
2
|
-
import { type GateAnswer, type GateCall, type ToolImage } from '../types.js';
|
|
2
|
+
import { type GateAnswer, type GateCall, type JsonValue, type ToolImage } from '../types.js';
|
|
3
3
|
/**
|
|
4
4
|
* The tool bridge: `HostTool`s as a harness-neutral list a port maps onto its
|
|
5
5
|
* harness's own tool mechanism (Codex's dynamic tools).
|
|
@@ -26,8 +26,12 @@ export interface ToolResult {
|
|
|
26
26
|
interrupted?: boolean;
|
|
27
27
|
/** Images the tool answered with, as it gave them (recorded with its outcome). */
|
|
28
28
|
images?: readonly ToolImage[];
|
|
29
|
+
/** The answer as a value, where the tool gives one (recorded with its outcome): what a script's nested call reads. */
|
|
30
|
+
structured?: JsonValue;
|
|
29
31
|
/** The text was cut at HOST_RESULT_MAX_CHARS (`boundResult`); it says so in its last line. */
|
|
30
32
|
truncated?: true;
|
|
33
|
+
/** The gate refused the call: the text is its words, and nothing of the call was written or run. */
|
|
34
|
+
refused?: true;
|
|
31
35
|
}
|
|
32
36
|
/** One tool, harness-neutral. */
|
|
33
37
|
export interface BridgedTool {
|