turno-browser 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +98 -0
- package/README.md +32 -3
- package/dist/act-model.d.ts +85 -0
- package/dist/act-model.js +116 -0
- package/dist/act.d.ts +37 -0
- package/dist/act.js +599 -0
- package/dist/api.d.ts +29 -2
- package/dist/api.js +29 -2
- package/dist/argv.d.ts +16 -2
- package/dist/argv.js +100 -3
- package/dist/batch.d.ts +5 -0
- package/dist/batch.js +3 -3
- package/dist/bin/mcp.js +58 -1
- package/dist/captcha.d.ts +77 -0
- package/dist/captcha.js +333 -0
- package/dist/cdp-relay.d.ts +20 -0
- package/dist/cdp-relay.js +101 -0
- package/dist/chrome-features.d.ts +23 -0
- package/dist/chrome-features.js +44 -0
- package/dist/diagnose.d.ts +7 -0
- package/dist/diagnose.js +61 -6
- package/dist/doctor.d.ts +37 -3
- package/dist/doctor.js +230 -5
- package/dist/engine-attach.d.ts +27 -0
- package/dist/engine-attach.js +165 -0
- package/dist/engine-camoufox.d.ts +32 -0
- package/dist/engine-camoufox.js +270 -0
- package/dist/engine-lightpanda.d.ts +72 -0
- package/dist/engine-lightpanda.js +292 -0
- package/dist/engine.d.ts +63 -11
- package/dist/engine.js +104 -28
- package/dist/flows.d.ts +127 -0
- package/dist/flows.js +294 -0
- package/dist/governor.d.ts +42 -7
- package/dist/governor.js +82 -32
- package/dist/host.d.ts +17 -2
- package/dist/host.js +618 -41
- package/dist/human-input.d.ts +84 -0
- package/dist/human-input.js +443 -0
- package/dist/humanize.d.ts +123 -0
- package/dist/humanize.js +241 -0
- package/dist/identities.js +2 -0
- package/dist/idle-timer.d.ts +12 -0
- package/dist/idle-timer.js +25 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.js +5 -1
- package/dist/lifecycle.d.ts +9 -1
- package/dist/lifecycle.js +9 -1
- package/dist/live-client.d.ts +22 -0
- package/dist/live-client.js +93 -0
- package/dist/live-page.d.ts +11 -0
- package/dist/live-page.js +143 -0
- package/dist/live-server.d.ts +173 -0
- package/dist/live-server.js +640 -0
- package/dist/live.d.ts +120 -0
- package/dist/live.js +203 -0
- package/dist/login-tool.d.ts +13 -0
- package/dist/login-tool.js +5 -1
- package/dist/login.d.ts +4 -1
- package/dist/login.js +11 -2
- package/dist/network-chrome.d.ts +74 -0
- package/dist/network-chrome.js +178 -0
- package/dist/network.d.ts +125 -0
- package/dist/network.js +263 -0
- package/dist/opt-in-settings.d.ts +69 -0
- package/dist/opt-in-settings.js +151 -0
- package/dist/recorder.d.ts +88 -0
- package/dist/recorder.js +538 -0
- package/dist/recordings.d.ts +116 -0
- package/dist/recordings.js +474 -0
- package/dist/redact.d.ts +7 -0
- package/dist/redact.js +18 -0
- package/dist/replay.d.ts +20 -0
- package/dist/replay.js +382 -0
- package/dist/reputation.d.ts +24 -2
- package/dist/reputation.js +63 -17
- package/dist/session-export.js +1 -1
- package/dist/session.d.ts +10 -2
- package/dist/session.js +10 -2
- package/dist/settings.d.ts +104 -2
- package/dist/settings.js +204 -6
- package/dist/sharing.d.ts +96 -0
- package/dist/sharing.js +269 -0
- package/dist/snippet.d.ts +8 -2
- package/dist/snippet.js +10 -4
- package/dist/tab-locks.d.ts +63 -0
- package/dist/tab-locks.js +179 -0
- package/dist/tools.d.ts +38 -0
- package/dist/tools.js +20 -1
- package/dist/tuning.d.ts +14 -0
- package/dist/tuning.js +9 -0
- package/dist/upstream.d.ts +11 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { parseDuration } from "./units.js";
|
|
2
|
+
/**
|
|
3
|
+
* The format 8 keys of identity.json: natural language actions (`act`) and captcha solving
|
|
4
|
+
* (`captcha`). Both are off until the key is there, and both send page content to a third
|
|
5
|
+
* party the user picks, so neither has a default provider:
|
|
6
|
+
*
|
|
7
|
+
* "act": {
|
|
8
|
+
* "sampling": true, // ask the agent's own client (MCP sampling) first
|
|
9
|
+
* "provider": "chat-completions", // else this HTTP API
|
|
10
|
+
* "endpoint": "https://models.example.com/v1",
|
|
11
|
+
* "model": "example-model",
|
|
12
|
+
* "key": "keychain:act-model", // optional; a reference, never the key
|
|
13
|
+
* "maxSteps": 10, "maxTokens": 50000, "timeout": "2m"
|
|
14
|
+
* },
|
|
15
|
+
* "captcha": {
|
|
16
|
+
* "provider": "task-api",
|
|
17
|
+
* "endpoint": "https://solver.example.com",
|
|
18
|
+
* "key": "keychain:captcha-solver",
|
|
19
|
+
* "timeout": "3m"
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* A key is read from the secret store at use time (turno-core), never from a tool argument and
|
|
23
|
+
* never written here: a value that is not a `keychain:` reference is refused, and the message
|
|
24
|
+
* does not repeat it.
|
|
25
|
+
*/
|
|
26
|
+
/** The model providers `act` can name besides MCP sampling. */
|
|
27
|
+
const ACT_PROVIDERS = ["chat-completions"];
|
|
28
|
+
/** The captcha solver protocols `captcha` can name. */
|
|
29
|
+
const CAPTCHA_PROVIDERS = ["task-api"];
|
|
30
|
+
const ACT_DEFAULTS = { maxSteps: 10, maxTokens: 50_000, timeoutMs: 120_000 };
|
|
31
|
+
const MAX_STEPS = 30;
|
|
32
|
+
const MIN_TOKENS = 2_000;
|
|
33
|
+
const MAX_TOKENS = 1_000_000;
|
|
34
|
+
const MIN_TIMEOUT_MS = 10_000;
|
|
35
|
+
const MAX_TIMEOUT_MS = 600_000;
|
|
36
|
+
const CAPTCHA_DEFAULT_TIMEOUT_MS = 180_000;
|
|
37
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
38
|
+
/** True for https, or http on a loopback host (a model server on this machine). */
|
|
39
|
+
export function allowedEndpoint(value) {
|
|
40
|
+
let url;
|
|
41
|
+
try {
|
|
42
|
+
url = new URL(value);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (url.username || url.password)
|
|
48
|
+
return false;
|
|
49
|
+
if (url.protocol === "https:")
|
|
50
|
+
return true;
|
|
51
|
+
return url.protocol === "http:" && ["127.0.0.1", "localhost", "[::1]"].includes(url.hostname);
|
|
52
|
+
}
|
|
53
|
+
const KEYCHAIN = /^keychain:[A-Za-z0-9._\-/]{1,200}$/;
|
|
54
|
+
/** True for a `keychain:<item>` reference. */
|
|
55
|
+
function isKeychainRef(value) {
|
|
56
|
+
return typeof value === "string" && KEYCHAIN.test(value);
|
|
57
|
+
}
|
|
58
|
+
function timeoutProblem(key, v, out) {
|
|
59
|
+
if (v === undefined)
|
|
60
|
+
return;
|
|
61
|
+
const ms = typeof v === "string" ? parseDuration(v) : undefined;
|
|
62
|
+
if (ms === undefined || ms < MIN_TIMEOUT_MS || ms > MAX_TIMEOUT_MS)
|
|
63
|
+
out.push(`${key} must be a duration from "10s" to "10m", like "2m"`);
|
|
64
|
+
}
|
|
65
|
+
function keyProblem(key, v, out, required) {
|
|
66
|
+
if (v === undefined) {
|
|
67
|
+
if (required)
|
|
68
|
+
out.push(`${key} is required: a keychain:<item> reference (turno secret set <item>)`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// Never echo the value: a pasted key would land in a terminal or a log.
|
|
72
|
+
if (!isKeychainRef(v))
|
|
73
|
+
out.push(`${key} must be a keychain:<item> reference (store the key with turno secret set <item>), never the key itself`);
|
|
74
|
+
}
|
|
75
|
+
function endpointProblem(key, v, out) {
|
|
76
|
+
if (typeof v !== "string" || !allowedEndpoint(v))
|
|
77
|
+
out.push(`${key} must be an https:// URL (or http:// on 127.0.0.1, localhost or [::1]) without a user or password`);
|
|
78
|
+
}
|
|
79
|
+
/** Problems with `act`, in key order. */
|
|
80
|
+
export function actProblems(a, out) {
|
|
81
|
+
if (a === undefined)
|
|
82
|
+
return;
|
|
83
|
+
if (!isObject(a)) {
|
|
84
|
+
out.push('act must be an object, like {} (MCP sampling) or { "provider": "chat-completions", ... }');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (a.sampling !== undefined && typeof a.sampling !== "boolean")
|
|
88
|
+
out.push("act.sampling must be true or false");
|
|
89
|
+
if (a.provider !== undefined) {
|
|
90
|
+
if (!ACT_PROVIDERS.includes(a.provider))
|
|
91
|
+
out.push(`act.provider must be ${ACT_PROVIDERS.map((p) => `"${p}"`).join(", ")}`);
|
|
92
|
+
endpointProblem("act.endpoint", a.endpoint, out);
|
|
93
|
+
if (typeof a.model !== "string" || !a.model.trim() || a.model.length > 200)
|
|
94
|
+
out.push("act.model must be the model name the provider expects");
|
|
95
|
+
keyProblem("act.key", a.key, out, false);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
for (const k of ["endpoint", "model", "key"])
|
|
99
|
+
if (a[k] !== undefined)
|
|
100
|
+
out.push(`act.${k} needs act.provider`);
|
|
101
|
+
if (a.sampling === false)
|
|
102
|
+
out.push("act needs act.provider when act.sampling is false: nothing would answer");
|
|
103
|
+
}
|
|
104
|
+
if (a.maxSteps !== undefined &&
|
|
105
|
+
(typeof a.maxSteps !== "number" || !Number.isInteger(a.maxSteps) || a.maxSteps < 1 || a.maxSteps > MAX_STEPS))
|
|
106
|
+
out.push(`act.maxSteps must be a whole number from 1 to ${MAX_STEPS}`);
|
|
107
|
+
if (a.maxTokens !== undefined &&
|
|
108
|
+
(typeof a.maxTokens !== "number" ||
|
|
109
|
+
!Number.isInteger(a.maxTokens) ||
|
|
110
|
+
a.maxTokens < MIN_TOKENS ||
|
|
111
|
+
a.maxTokens > MAX_TOKENS))
|
|
112
|
+
out.push(`act.maxTokens must be a whole number from ${MIN_TOKENS} to ${MAX_TOKENS}`);
|
|
113
|
+
timeoutProblem("act.timeout", a.timeout, out);
|
|
114
|
+
for (const k of Object.keys(a))
|
|
115
|
+
if (!["sampling", "provider", "endpoint", "model", "key", "maxSteps", "maxTokens", "timeout"].includes(k))
|
|
116
|
+
out.push(`unknown key "act.${k}"`);
|
|
117
|
+
}
|
|
118
|
+
/** Problems with `captcha`, alone and with the engine keys. */
|
|
119
|
+
export function captchaProblems(c, settings, out) {
|
|
120
|
+
if (c === undefined)
|
|
121
|
+
return;
|
|
122
|
+
if (!isObject(c)) {
|
|
123
|
+
out.push('captcha must be an object with provider, endpoint and key, like { "provider": "task-api", ... }');
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (!CAPTCHA_PROVIDERS.includes(c.provider))
|
|
127
|
+
out.push(`captcha.provider must be ${CAPTCHA_PROVIDERS.map((p) => `"${p}"`).join(", ")}`);
|
|
128
|
+
endpointProblem("captcha.endpoint", c.endpoint, out);
|
|
129
|
+
keyProblem("captcha.key", c.key, out, true);
|
|
130
|
+
timeoutProblem("captcha.timeout", c.timeout, out);
|
|
131
|
+
for (const k of Object.keys(c))
|
|
132
|
+
if (!["provider", "endpoint", "key", "timeout"].includes(k))
|
|
133
|
+
out.push(`unknown key "captcha.${k}"`);
|
|
134
|
+
if (settings.engine === "lightpanda")
|
|
135
|
+
out.push('captcha does not go with engine "lightpanda": read mode runs no captcha widget to solve');
|
|
136
|
+
if (settings.engine === "camoufox")
|
|
137
|
+
out.push("captcha does not go with engine \"camoufox\": the token is set from Patchright's isolated script world and the widget's callback from the page's own, and Camoufox runs on stock Playwright");
|
|
138
|
+
}
|
|
139
|
+
/** The budgets of an `act` group, defaults filled in. */
|
|
140
|
+
export function actBudget(a) {
|
|
141
|
+
return {
|
|
142
|
+
maxSteps: a.maxSteps ?? ACT_DEFAULTS.maxSteps,
|
|
143
|
+
maxTokens: a.maxTokens ?? ACT_DEFAULTS.maxTokens,
|
|
144
|
+
timeoutMs: (a.timeout !== undefined ? parseDuration(a.timeout) : undefined) ?? ACT_DEFAULTS.timeoutMs,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** How long one captcha solve may wait. */
|
|
148
|
+
export function captchaTimeoutMs(c) {
|
|
149
|
+
return (c.timeout !== undefined ? parseDuration(c.timeout) : undefined) ?? CAPTCHA_DEFAULT_TIMEOUT_MS;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=opt-in-settings.js.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Page } from "patchright-core";
|
|
2
|
+
import type { IdentityRef } from "./engine.js";
|
|
3
|
+
import { type Flow, type FlowStep } from "./flows.js";
|
|
4
|
+
import type { Redactor } from "./redact.js";
|
|
5
|
+
import type { TurnoTool } from "./tools.js";
|
|
6
|
+
/** What the page says about an element, for its locators and to tell a secret field. */
|
|
7
|
+
interface ElementInfo {
|
|
8
|
+
tag: string;
|
|
9
|
+
type: string;
|
|
10
|
+
autocomplete: string;
|
|
11
|
+
name: string;
|
|
12
|
+
id: string;
|
|
13
|
+
text: string;
|
|
14
|
+
css: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const SECRET_AUTOCOMPLETE: RegExp;
|
|
17
|
+
export declare const SECRET_NAME: RegExp;
|
|
18
|
+
/** A field whose typed value must never be stored. */
|
|
19
|
+
export declare function secretField(info: Pick<ElementInfo, "type" | "autocomplete" | "name" | "id">): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The values a `browser_type` or `browser_fill_form` call is about to put into secret fields
|
|
22
|
+
* (`secretField`), so a recording can stop its trace first. A target the page cannot resolve
|
|
23
|
+
* counts as not secret: the call then fails the same way.
|
|
24
|
+
*/
|
|
25
|
+
export declare function secretValues(page: Page, tool: string, args: Record<string, unknown>): Promise<string[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Role and accessible name from Playwright's generated locator when it is a role locator
|
|
28
|
+
* (`internal:role=button[name="Sign in"i]`). Asking the element for its aria snapshot instead
|
|
29
|
+
* would renumber the page's refs and break the call the agent is making.
|
|
30
|
+
*/
|
|
31
|
+
export declare function roleFromSelector(selector: string): {
|
|
32
|
+
role: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
} | undefined;
|
|
35
|
+
/** A typed value of a step, before each draft gives it a parameter name. */
|
|
36
|
+
export interface Slot {
|
|
37
|
+
path: string;
|
|
38
|
+
value: string;
|
|
39
|
+
sensitive: boolean;
|
|
40
|
+
label?: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
}
|
|
43
|
+
/** A step captured before its tool ran; committed only when the tool worked. */
|
|
44
|
+
export interface PendingStep {
|
|
45
|
+
step: FlowStep;
|
|
46
|
+
slots: Slot[];
|
|
47
|
+
}
|
|
48
|
+
/** The recorder of one MCP session. */
|
|
49
|
+
export declare class FlowRecorder {
|
|
50
|
+
private readonly identity;
|
|
51
|
+
private readonly redactor;
|
|
52
|
+
/** identity.json `record.flows`: record every session as `auto-<time>`. */
|
|
53
|
+
private readonly autoFlows;
|
|
54
|
+
private named;
|
|
55
|
+
private overwrite;
|
|
56
|
+
private auto;
|
|
57
|
+
private suspended;
|
|
58
|
+
constructor(identity: IdentityRef, redactor: Redactor,
|
|
59
|
+
/** identity.json `record.flows`: record every session as `auto-<time>`. */
|
|
60
|
+
autoFlows: () => boolean);
|
|
61
|
+
/** True when a step would be kept now. */
|
|
62
|
+
get active(): boolean;
|
|
63
|
+
get recording(): {
|
|
64
|
+
name: string;
|
|
65
|
+
steps: number;
|
|
66
|
+
params: number;
|
|
67
|
+
full: boolean;
|
|
68
|
+
} | undefined;
|
|
69
|
+
start(name: string, description: string | undefined, overwrite: boolean): void;
|
|
70
|
+
/** Saves the named flow, with `sensitive` parameters' values dropped. */
|
|
71
|
+
stop(sensitive?: readonly string[], description?: string): {
|
|
72
|
+
flow: Flow;
|
|
73
|
+
file: string;
|
|
74
|
+
};
|
|
75
|
+
cancel(): boolean;
|
|
76
|
+
/** Runs `fn` without recording its steps (a replay is recorded as one step). */
|
|
77
|
+
suspend<T>(fn: () => Promise<T>): Promise<T>;
|
|
78
|
+
/** A stock tool call about to run, as a step; undefined when it is not one a flow keeps. */
|
|
79
|
+
capture(tool: string, args: Record<string, unknown>, page: Page | undefined): Promise<PendingStep | undefined>;
|
|
80
|
+
/** Keeps a captured step after its tool worked. */
|
|
81
|
+
commit(pending: PendingStep): void;
|
|
82
|
+
/** A turno tool as a step: `browser_login` (site only) or `browser_replay` (its flow and parameters). */
|
|
83
|
+
record(tool: "browser_login" | "browser_replay", args: Record<string, unknown>, slots?: Slot[]): void;
|
|
84
|
+
private commitAuto;
|
|
85
|
+
}
|
|
86
|
+
/** `browser_record`. */
|
|
87
|
+
export declare function recordTool(): TurnoTool;
|
|
88
|
+
export {};
|