turno-browser 0.2.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.
Files changed (121) hide show
  1. package/CHANGELOG.md +228 -0
  2. package/README.md +205 -16
  3. package/dist/act-model.d.ts +85 -0
  4. package/dist/act-model.js +116 -0
  5. package/dist/act.d.ts +37 -0
  6. package/dist/act.js +599 -0
  7. package/dist/api.d.ts +96 -0
  8. package/dist/api.js +88 -0
  9. package/dist/argv.d.ts +55 -3
  10. package/dist/argv.js +190 -10
  11. package/dist/batch.d.ts +19 -0
  12. package/dist/batch.js +148 -0
  13. package/dist/bench.d.ts +1 -1
  14. package/dist/bench.js +21 -5
  15. package/dist/bin/mcp.js +108 -12
  16. package/dist/captcha.d.ts +77 -0
  17. package/dist/captcha.js +333 -0
  18. package/dist/cdp-relay.d.ts +20 -0
  19. package/dist/cdp-relay.js +101 -0
  20. package/dist/chrome-features.d.ts +23 -0
  21. package/dist/chrome-features.js +44 -0
  22. package/dist/detectors.d.ts +11 -0
  23. package/dist/detectors.js +46 -4
  24. package/dist/diagnose.d.ts +45 -0
  25. package/dist/diagnose.js +326 -0
  26. package/dist/doctor.d.ts +85 -0
  27. package/dist/doctor.js +556 -0
  28. package/dist/engine-attach.d.ts +27 -0
  29. package/dist/engine-attach.js +165 -0
  30. package/dist/engine-camoufox.d.ts +32 -0
  31. package/dist/engine-camoufox.js +270 -0
  32. package/dist/engine-lightpanda.d.ts +72 -0
  33. package/dist/engine-lightpanda.js +292 -0
  34. package/dist/engine.d.ts +119 -0
  35. package/dist/engine.js +355 -0
  36. package/dist/flows.d.ts +127 -0
  37. package/dist/flows.js +294 -0
  38. package/dist/governor.d.ts +119 -0
  39. package/dist/governor.js +325 -0
  40. package/dist/health.d.ts +60 -0
  41. package/dist/health.js +86 -0
  42. package/dist/host.d.ts +95 -0
  43. package/dist/host.js +1181 -0
  44. package/dist/human-input.d.ts +84 -0
  45. package/dist/human-input.js +443 -0
  46. package/dist/humanize.d.ts +123 -0
  47. package/dist/humanize.js +241 -0
  48. package/dist/identities.d.ts +23 -10
  49. package/dist/identities.js +45 -37
  50. package/dist/idle-timer.d.ts +12 -0
  51. package/dist/idle-timer.js +25 -0
  52. package/dist/ids.d.ts +9 -0
  53. package/dist/ids.js +34 -0
  54. package/dist/index.d.ts +21 -6
  55. package/dist/index.js +19 -18
  56. package/dist/lifecycle.d.ts +99 -0
  57. package/dist/lifecycle.js +172 -0
  58. package/dist/live-client.d.ts +22 -0
  59. package/dist/live-client.js +93 -0
  60. package/dist/live-page.d.ts +11 -0
  61. package/dist/live-page.js +143 -0
  62. package/dist/live-server.d.ts +173 -0
  63. package/dist/live-server.js +640 -0
  64. package/dist/live.d.ts +120 -0
  65. package/dist/live.js +203 -0
  66. package/dist/login-tool.d.ts +45 -0
  67. package/dist/login-tool.js +233 -0
  68. package/dist/login.d.ts +8 -3
  69. package/dist/login.js +65 -26
  70. package/dist/network-chrome.d.ts +74 -0
  71. package/dist/network-chrome.js +178 -0
  72. package/dist/network.d.ts +125 -0
  73. package/dist/network.js +263 -0
  74. package/dist/opt-in-settings.d.ts +69 -0
  75. package/dist/opt-in-settings.js +151 -0
  76. package/dist/patchright.d.ts +4 -2
  77. package/dist/patchright.js +4 -2
  78. package/dist/recorder.d.ts +88 -0
  79. package/dist/recorder.js +538 -0
  80. package/dist/recordings.d.ts +116 -0
  81. package/dist/recordings.js +474 -0
  82. package/dist/redact.d.ts +34 -0
  83. package/dist/redact.js +135 -0
  84. package/dist/replay.d.ts +20 -0
  85. package/dist/replay.js +382 -0
  86. package/dist/reputation.d.ts +89 -0
  87. package/dist/reputation.js +203 -0
  88. package/dist/resources.d.ts +76 -0
  89. package/dist/resources.js +341 -0
  90. package/dist/runtime-lock.d.ts +59 -0
  91. package/dist/runtime-lock.js +131 -0
  92. package/dist/sealed.d.ts +8 -0
  93. package/dist/sealed.js +96 -0
  94. package/dist/session-export.d.ts +67 -0
  95. package/dist/session-export.js +194 -0
  96. package/dist/session.d.ts +20 -0
  97. package/dist/session.js +30 -0
  98. package/dist/settings.d.ts +246 -0
  99. package/dist/settings.js +530 -0
  100. package/dist/sharing.d.ts +96 -0
  101. package/dist/sharing.js +269 -0
  102. package/dist/snippet.d.ts +8 -0
  103. package/dist/snippet.js +22 -0
  104. package/dist/tab-locks.d.ts +63 -0
  105. package/dist/tab-locks.js +179 -0
  106. package/dist/tools.d.ts +111 -0
  107. package/dist/tools.js +59 -0
  108. package/dist/totp.d.ts +32 -0
  109. package/dist/totp.js +82 -0
  110. package/dist/tuning.d.ts +76 -0
  111. package/dist/tuning.js +69 -0
  112. package/dist/units.d.ts +8 -0
  113. package/dist/units.js +20 -0
  114. package/dist/upstream.d.ts +243 -0
  115. package/dist/upstream.js +46 -0
  116. package/dist/vault.d.ts +91 -0
  117. package/dist/vault.js +273 -0
  118. package/npm-shrinkwrap.json +1074 -3
  119. package/package.json +5 -4
  120. package/dist/paths.d.ts +0 -17
  121. package/dist/paths.js +0 -17
@@ -0,0 +1,116 @@
1
+ import { secretStore } from "turno-core/secrets";
2
+ /** A rough token count for budgets when a provider does not report one: 4 characters a token. */
3
+ export function estimateTokens(text) {
4
+ return Math.ceil(text.length / 4);
5
+ }
6
+ export class ModelError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "ModelError";
10
+ }
11
+ }
12
+ export function samplingModel(sample) {
13
+ return {
14
+ label: "MCP sampling (your client's model)",
15
+ async complete(request) {
16
+ const reply = await sample({
17
+ systemPrompt: request.system,
18
+ messages: request.messages.map((m) => ({ role: m.role, content: { type: "text", text: m.text } })),
19
+ maxTokens: request.maxTokens,
20
+ }, request.signal);
21
+ return { text: reply.text };
22
+ },
23
+ };
24
+ }
25
+ /** Longest provider error body kept in a message. */
26
+ const ERROR_CHARS = 300;
27
+ export function chatCompletionsModel(options) {
28
+ const url = `${options.endpoint.replace(/\/+$/, "")}/chat/completions`;
29
+ const host = new URL(options.endpoint).host;
30
+ const doFetch = options.fetch ?? fetch;
31
+ return {
32
+ label: `chat-completions ${options.model} at ${host}`,
33
+ async complete(request) {
34
+ const body = {
35
+ model: options.model,
36
+ messages: [
37
+ { role: "system", content: request.system },
38
+ ...request.messages.map((m) => ({ role: m.role, content: m.text })),
39
+ ],
40
+ max_tokens: request.maxTokens,
41
+ temperature: 0,
42
+ };
43
+ let res;
44
+ try {
45
+ res = await doFetch(url, {
46
+ method: "POST",
47
+ headers: {
48
+ "content-type": "application/json",
49
+ ...(options.key ? { authorization: `Bearer ${options.key}` } : {}),
50
+ },
51
+ body: JSON.stringify(body),
52
+ ...(request.signal ? { signal: request.signal } : {}),
53
+ });
54
+ }
55
+ catch (error) {
56
+ if (request.signal?.aborted)
57
+ throw new ModelError("the model did not answer in time");
58
+ throw new ModelError(`cannot reach ${host}: ${error.message}`);
59
+ }
60
+ const text = await res.text().catch(() => "");
61
+ if (!res.ok) {
62
+ const detail = text.replace(/\s+/g, " ").slice(0, ERROR_CHARS);
63
+ throw new ModelError(`${host} answered ${res.status}${detail ? `: ${detail}` : ""}`);
64
+ }
65
+ let parsed;
66
+ try {
67
+ parsed = JSON.parse(text);
68
+ }
69
+ catch {
70
+ throw new ModelError(`${host} did not answer with JSON`);
71
+ }
72
+ const content = parsed.choices?.[0]?.message?.content;
73
+ if (typeof content !== "string")
74
+ throw new ModelError(`${host} answered without a message`);
75
+ const input = parsed.usage?.prompt_tokens;
76
+ const output = parsed.usage?.completion_tokens;
77
+ return {
78
+ text: content,
79
+ ...(typeof input === "number" && typeof output === "number" ? { usage: { input, output } } : {}),
80
+ };
81
+ },
82
+ };
83
+ }
84
+ /**
85
+ * The model for one call: MCP sampling when the identity allows it and the client offers it,
86
+ * else the configured provider with its key from the secret store. The error says what to set
87
+ * when neither is there.
88
+ */
89
+ export async function resolveModel(options) {
90
+ const { settings, sample, redactor } = options;
91
+ if (settings.sampling !== false && sample)
92
+ return samplingModel(sample);
93
+ if (!settings.provider || !settings.endpoint || !settings.model) {
94
+ throw new ModelError(settings.sampling === false
95
+ ? `natural language actions of "${options.id}" have no provider (turno identity set browser:${options.id} --act-provider chat-completions --act-endpoint <url> --act-model <name>)`
96
+ : `this client does not offer MCP sampling and identity "${options.id}" names no provider: set one with turno identity set browser:${options.id} --act-provider chat-completions --act-endpoint <url> --act-model <name> [--act-key keychain:<item>]`);
97
+ }
98
+ let key;
99
+ if (settings.key) {
100
+ const item = settings.key.slice("keychain:".length);
101
+ const store = options.store ?? secretStore(options.env);
102
+ if (!store)
103
+ throw new ModelError(`act.key names ${settings.key}, but this machine has no secret store`);
104
+ key = await store.get(item).catch(() => undefined);
105
+ if (key === undefined)
106
+ throw new ModelError(`the secret store has no item "${item}" for act.key (store it with: turno secret set ${item})`);
107
+ redactor.add(key, "act model key");
108
+ }
109
+ return chatCompletionsModel({
110
+ endpoint: settings.endpoint,
111
+ model: settings.model,
112
+ ...(key ? { key } : {}),
113
+ ...(options.fetch ? { fetch: options.fetch } : {}),
114
+ });
115
+ }
116
+ //# sourceMappingURL=act-model.js.map
package/dist/act.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import type { StockAccess, TurnoTool } from "./tools.js";
2
+ /**
3
+ * Natural language actions, off by default (identity.json `act`): `browser_act` turns an
4
+ * instruction into stock tool calls, `browser_extract` reads data off the page, and
5
+ * `browser_observe` proposes the calls without running them. The model is the user's: MCP
6
+ * sampling when the client offers it, else the provider identity.json names (`act-model.ts`).
7
+ *
8
+ * What the model gets and what it can do is fixed here, not by the model:
9
+ *
10
+ * - The instruction and the current tab's accessibility snapshot, after the host's redactor:
11
+ * vault values never reach it, and before each snapshot the values of password, one-time
12
+ * code and card fields on the page join the redactor, so a sensitive field reads
13
+ * `[vault: sensitive value]`. An instruction that holds a redacted value is refused.
14
+ * - It answers with one stock call at a time, from `ACT_TOOLS` only: input on the current tab.
15
+ * It cannot navigate to a URL, open or close tabs, run script, upload files or call turno
16
+ * tools, so text on a page that tries to steer it can at worst click and type on that page.
17
+ * A call that would type into a password or one-time code field is refused.
18
+ * - Every call goes through the same path as the agent's own (`StockAccess.call`): the tab
19
+ * governor, human-like input, tab locks with `"sharing": "tabs"`, recordings. A recorded flow
20
+ * therefore holds the stock steps the model chose, never the instruction or the prompt.
21
+ * - Steps, tokens and time are bounded per call (`act.maxSteps`, `act.maxTokens`,
22
+ * `act.timeout`), and every step is listed in the result.
23
+ */
24
+ /** The stock tools a model may call: input on the current tab, nothing that leaves it. */
25
+ export declare const ACT_TOOLS: readonly string[];
26
+ /** The first JSON object in a reply, fences and chatter around it ignored. */
27
+ export declare function parseJsonReply(text: string): Record<string, unknown> | undefined;
28
+ /** A proposed call, checked against the allowed tools and the tool's own schema. */
29
+ export declare function checkCall(stock: Pick<StockAccess, "schemas" | "formatError">, tool: unknown, args: unknown): {
30
+ tool: string;
31
+ arguments: Record<string, unknown>;
32
+ } | {
33
+ error: string;
34
+ };
35
+ export declare function actTool(): TurnoTool;
36
+ export declare function extractTool(): TurnoTool;
37
+ export declare function observeTool(): TurnoTool;