@reclaimprotocol/agent 0.1.23 → 0.1.25
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/README.md +56 -20
- package/lib/authoring/backend.d.ts +5 -4
- package/lib/authoring/tools.js +30 -30
- package/lib/cdp/capture-engine.js +8 -7
- package/lib/cdp/claims.d.ts +21 -0
- package/lib/cdp/claims.js +129 -0
- package/lib/cdp/container.d.ts +85 -0
- package/lib/cdp/container.js +481 -0
- package/lib/cdp/geo.d.ts +10 -0
- package/lib/cdp/geo.js +36 -0
- package/lib/cdp/index.d.ts +1 -0
- package/lib/cdp/index.js +1 -0
- package/lib/live/cloudflared.d.ts +15 -0
- package/lib/live/cloudflared.js +268 -0
- package/lib/live/tunnel.d.ts +26 -0
- package/lib/live/tunnel.js +160 -0
- package/lib/mcp/api/operations.gen.js +34 -26
- package/lib/mcp/api/to-zod.d.ts +1 -1
- package/lib/mcp/api/to-zod.js +1 -1
- package/lib/mcp/api/tools.js +1 -1
- package/lib/mcp/instructions.d.ts +15 -2
- package/lib/mcp/instructions.js +102 -38
- package/lib/mcp/start.js +62 -6
- package/lib/mcp/tools/agent/analyze.js +5 -1
- package/lib/mcp/tools/agent/attach.d.ts +29 -2
- package/lib/mcp/tools/agent/attach.js +310 -24
- package/lib/mcp/tools/agent/build.d.ts +18 -8
- package/lib/mcp/tools/agent/build.js +30 -12
- package/lib/mcp/tools/agent/capture.js +5 -1
- package/lib/mcp/tools/agent/eval.js +3 -1
- package/lib/mcp/tools/agent/find.js +6 -5
- package/lib/mcp/tools/agent/how-it-works.d.ts +15 -7
- package/lib/mcp/tools/agent/how-it-works.js +57 -17
- package/lib/mcp/tools/agent/index.d.ts +1 -2
- package/lib/mcp/tools/agent/index.js +1 -1
- package/lib/mcp/tools/agent/live-view.d.ts +17 -0
- package/lib/mcp/tools/agent/live-view.js +146 -0
- package/lib/mcp/tools/agent/pod-proof.d.ts +8 -0
- package/lib/mcp/tools/agent/pod-proof.js +64 -0
- package/lib/mcp/tools/agent/propose.js +4 -2
- package/lib/mcp/tools/agent/publish.js +47 -77
- package/lib/mcp/tools/agent/session.d.ts +16 -1
- package/lib/mcp/tools/agent/session.js +32 -7
- package/lib/mcp/tools/authenticate/authenticate.js +26 -13
- package/lib/mcp/tools/mode/mode.d.ts +1 -1
- package/lib/mcp/tools/mode/mode.js +10 -22
- package/lib/old/client.d.ts +1 -1
- package/lib/old/client.js +1 -1
- package/lib/old/instructions.d.ts +9 -1
- package/lib/old/instructions.js +4 -6
- package/lib/old/login-cdp.d.ts +2 -2
- package/lib/old/login-cdp.js +46 -6
- package/lib/old/to-register.d.ts +3 -2
- package/lib/old/to-register.js +1 -1
- package/lib/old/tools/authenticate.js +9 -1
- package/lib/old/tools/get-provider-info.js +6 -5
- package/lib/old/tools/issue-app-credentials.js +3 -2
- package/lib/old/tools/publish.d.ts +1 -1
- package/lib/old/tools/publish.js +90 -131
- package/lib/old/tools/update-provider-metadata.d.ts +1 -1
- package/lib/old/tools/update-provider-metadata.js +1 -1
- package/lib/old/tools/verify-sdk-setup.js +1 -1
- package/lib/proof/attestor.d.ts +3 -3
- package/lib/proof/debug-response-dump.js +4 -4
- package/lib/proof/index.d.ts +1 -0
- package/lib/proof/index.js +1 -0
- package/lib/proof/page-replay.d.ts +1 -1
- package/lib/proof/page-replay.js +1 -1
- package/lib/proof/pod-prover.d.ts +47 -0
- package/lib/proof/pod-prover.js +155 -0
- package/lib/provider/dom-xpath.js +11 -9
- package/lib/provider/draft.d.ts +10 -7
- package/lib/provider/draft.js +11 -9
- package/lib/provider/injection-doc.d.ts +23 -1
- package/lib/provider/injection-doc.js +34 -21
- package/lib/provider/match-redaction-warning.d.ts +2 -2
- package/lib/provider/match-redaction-warning.js +3 -3
- package/lib/provider/matcher.js +13 -12
- package/lib/provider/secrets.d.ts +3 -3
- package/lib/provider/secrets.js +3 -3
- package/lib/provider/to-version.d.ts +7 -6
- package/lib/provider/to-version.js +3 -3
- package/lib/tools/registry.d.ts +5 -5
- package/lib/tools/registry.js +5 -5
- package/package.json +3 -3
- package/samples/demo-server/README.md +7 -6
- package/skill/SKILL.builder.md +356 -189
- package/skill/SKILL.common.md +400 -97
- package/skill/SKILL.old.md +340 -155
- package/skill/builder-mode.md +60 -17
- package/skill/hash-validation.md +170 -0
- package/skill/interception.md +236 -0
- package/skill/js-sdk-integration.md +13 -7
- package/skill/old-mode.md +62 -21
- package/skill/user-script.md +61 -0
- package/src/authoring/backend.ts +5 -4
- package/src/authoring/tools.ts +31 -30
- package/src/cdp/capture-engine.ts +8 -7
- package/src/cdp/claims.ts +153 -0
- package/src/cdp/container.ts +593 -0
- package/src/cdp/geo.ts +52 -0
- package/src/cdp/index.ts +1 -0
- package/src/consts.ts +1 -0
- package/src/live/cloudflared.ts +348 -0
- package/src/live/tunnel.ts +208 -0
- package/src/mcp/api/operations.gen.ts +34 -26
- package/src/mcp/api/to-zod.ts +1 -1
- package/src/mcp/api/tools.ts +1 -1
- package/src/mcp/instructions.ts +122 -48
- package/src/mcp/start.ts +69 -5
- package/src/mcp/tools/agent/analyze.ts +5 -1
- package/src/mcp/tools/agent/attach.ts +367 -26
- package/src/mcp/tools/agent/build.ts +35 -16
- package/src/mcp/tools/agent/capture.ts +5 -1
- package/src/mcp/tools/agent/eval.ts +4 -1
- package/src/mcp/tools/agent/find.ts +6 -5
- package/src/mcp/tools/agent/how-it-works.ts +62 -21
- package/src/mcp/tools/agent/index.ts +6 -2
- package/src/mcp/tools/agent/live-view.ts +182 -0
- package/src/mcp/tools/agent/pod-proof.ts +90 -0
- package/src/mcp/tools/agent/propose.ts +4 -2
- package/src/mcp/tools/agent/publish.ts +52 -77
- package/src/mcp/tools/agent/session.ts +33 -6
- package/src/mcp/tools/authenticate/authenticate.ts +28 -13
- package/src/mcp/tools/mode/mode.ts +10 -22
- package/src/old/client.ts +2 -2
- package/src/old/instructions.ts +4 -10
- package/src/old/login-cdp.ts +50 -6
- package/src/old/to-register.ts +3 -2
- package/src/old/tools/authenticate.ts +9 -1
- package/src/old/tools/get-provider-info.ts +6 -5
- package/src/old/tools/issue-app-credentials.ts +3 -2
- package/src/old/tools/publish.ts +95 -131
- package/src/old/tools/update-provider-metadata.ts +1 -1
- package/src/old/tools/verify-sdk-setup.ts +1 -1
- package/src/proof/attestor.ts +3 -3
- package/src/proof/debug-response-dump.ts +4 -4
- package/src/proof/index.ts +8 -0
- package/src/proof/page-replay.ts +1 -1
- package/src/proof/pod-prover.ts +231 -0
- package/src/provider/dom-xpath.ts +11 -9
- package/src/provider/draft.ts +13 -10
- package/src/provider/injection-doc.ts +37 -24
- package/src/provider/match-redaction-warning.ts +3 -3
- package/src/provider/matcher.ts +13 -12
- package/src/provider/secrets.ts +3 -3
- package/src/provider/to-version.ts +11 -9
- package/src/tools/registry.ts +5 -5
- package/skill/injection-api.md +0 -364
|
@@ -6,6 +6,12 @@ import {
|
|
|
6
6
|
connectCdp,
|
|
7
7
|
connectCdpUrl,
|
|
8
8
|
} from '../../../cdp/client.ts'
|
|
9
|
+
import {
|
|
10
|
+
dockerAvailable,
|
|
11
|
+
dockerMissingMessage,
|
|
12
|
+
startContainer,
|
|
13
|
+
} from '../../../cdp/container.ts'
|
|
14
|
+
import { suggestCountryFromIp } from '../../../cdp/geo.ts'
|
|
9
15
|
import {
|
|
10
16
|
defaultProfileDir,
|
|
11
17
|
launchChrome,
|
|
@@ -15,7 +21,22 @@ import type { ConfigStore } from '../../../config/store.ts'
|
|
|
15
21
|
import { defaultConfigPath } from '../../../config/store.ts'
|
|
16
22
|
import { defineTool, type RegisteredTool } from '../../server.ts'
|
|
17
23
|
|
|
18
|
-
export type BrowserMode =
|
|
24
|
+
export type BrowserMode =
|
|
25
|
+
| 'dedicated'
|
|
26
|
+
| 'attach'
|
|
27
|
+
| 'builder'
|
|
28
|
+
| 'custom'
|
|
29
|
+
| 'container'
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Modes with a live view that `share_browser_view` can put behind a public URL.
|
|
33
|
+
*
|
|
34
|
+
* Only `container`: it runs the Reclaim browser runtime, whose viewer already
|
|
35
|
+
* serves on loopback, so sharing is a tunnel in front of it. `builder` gives a
|
|
36
|
+
* hosted `liveViewUrl` instead, and a plain local browser has nothing to
|
|
37
|
+
* show — one on this machine is watched by looking at it.
|
|
38
|
+
*/
|
|
39
|
+
export const SHAREABLE_MODES = new Set<BrowserMode>(['container'])
|
|
19
40
|
|
|
20
41
|
export interface AttachState {
|
|
21
42
|
handles: CdpHandles
|
|
@@ -24,6 +45,20 @@ export interface AttachState {
|
|
|
24
45
|
liveViewUrl?: string
|
|
25
46
|
browserSessionId?: string
|
|
26
47
|
orgId?: string
|
|
48
|
+
/** The Popcorn pod's own TEE api base (builder mode only) — lets
|
|
49
|
+
* `run_proof_via_pod` prove through the SAME enclave that holds the
|
|
50
|
+
* browser's TLS session (and its country-routed egress), instead of the
|
|
51
|
+
* local in-process attestor SDK. */
|
|
52
|
+
apiUrl?: string
|
|
53
|
+
/** The exit country this remote browser was allocated with, if any. */
|
|
54
|
+
countryCode?: string
|
|
55
|
+
/** Docker's name for a `container`-mode browser, for diagnostics. */
|
|
56
|
+
containerName?: string
|
|
57
|
+
/** Loopback port the container's own live viewer serves on, which is what
|
|
58
|
+
* `share_browser_view` tunnels. Never the CDP port. */
|
|
59
|
+
viewerPort?: number
|
|
60
|
+
/** Whether the runtime image had to be downloaded on this attach. */
|
|
61
|
+
imagePulled?: boolean
|
|
27
62
|
disposeRemote?: () => Promise<void>
|
|
28
63
|
}
|
|
29
64
|
|
|
@@ -40,49 +75,204 @@ interface AttachArgs {
|
|
|
40
75
|
orgId?: string
|
|
41
76
|
cdpUrl?: string
|
|
42
77
|
liveViewUrl?: string
|
|
78
|
+
/** Builder mode: the country the remote browser should browse from. */
|
|
79
|
+
countryCode?: string
|
|
80
|
+
/** Builder mode: allocate without geo-routing, skipping the country
|
|
81
|
+
* prompt. Geolocation is optional — this is how the caller says so. */
|
|
82
|
+
skipCountry?: boolean
|
|
83
|
+
/** Container mode: loopback port for the live viewer. */
|
|
84
|
+
viewerPort?: number
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The browser sources, written once and used twice: rendered into this tool's
|
|
89
|
+
* DESCRIPTION (so an agent can put the choice to the developer straight from
|
|
90
|
+
* the tool list, without a discovery round-trip) and returned verbatim as
|
|
91
|
+
* structured `options` when the tool is called without a `mode` anyway.
|
|
92
|
+
*
|
|
93
|
+
* Being the single source for both is the point — an option list that a model
|
|
94
|
+
* reads in the description but that disagrees with what the tool returns is
|
|
95
|
+
* worse than either alone.
|
|
96
|
+
*
|
|
97
|
+
* Ordered and labelled BY USE CASE, because that is the question a developer
|
|
98
|
+
* can actually answer. "Which CDP transport?" is not; "does anyone else need to
|
|
99
|
+
* get into this browser?" is, and it decides two of the four. `useCase` is the
|
|
100
|
+
* grouping key, so the rendered list reads as two pairs rather than four
|
|
101
|
+
* unrelated transports.
|
|
102
|
+
*/
|
|
103
|
+
const BROWSER_OPTIONS = [
|
|
104
|
+
{
|
|
105
|
+
mode: 'dedicated',
|
|
106
|
+
useCase: 'Working on your own machine',
|
|
107
|
+
label: 'Local Chrome, launched for you',
|
|
108
|
+
detail:
|
|
109
|
+
'Launches Chrome with a dedicated profile under '
|
|
110
|
+
+ '~/.reclaim/chrome-profile. Nothing to set up, and the profile '
|
|
111
|
+
+ 'persists, so a site you sign in to stays signed in. The easiest '
|
|
112
|
+
+ 'choice when you are doing the work yourself.',
|
|
113
|
+
requires: [],
|
|
114
|
+
liveView: 'None, and none needed — the browser is on your screen.',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
mode: 'attach',
|
|
118
|
+
useCase: 'Working on your own machine',
|
|
119
|
+
label: 'The Chrome you already have open',
|
|
120
|
+
detail:
|
|
121
|
+
'Connects to a Chrome you started yourself, keeping the tabs, '
|
|
122
|
+
+ 'extensions and logins already in it. That Chrome must have been '
|
|
123
|
+
+ 'started with BOTH --remote-debugging-port AND a non-default '
|
|
124
|
+
+ '--user-data-dir: since Chrome 136 the debug flag is silently '
|
|
125
|
+
+ 'ignored on the default profile.',
|
|
126
|
+
requires: ['port (default 9222)'],
|
|
127
|
+
liveView: 'None, and none needed — the browser is on your screen.',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
mode: 'container',
|
|
131
|
+
useCase: 'Someone else has to sign in, or you need a phone',
|
|
132
|
+
label: 'Reclaim runtime in Docker — free, runs on your machine',
|
|
133
|
+
detail:
|
|
134
|
+
'Runs the Reclaim browser runtime (the same image the remote browser '
|
|
135
|
+
+ 'uses) as a container on this machine, and gives you a link you can '
|
|
136
|
+
+ 'send to whoever holds the account. They open it in any browser, '
|
|
137
|
+
+ 'including a phone, and can see and click in it. Free — it is your '
|
|
138
|
+
+ 'Docker and your bandwidth. Costs a 432 MB first-run download and '
|
|
139
|
+
+ 'about 2 GB of RAM. The image is amd64, so Apple Silicon runs it '
|
|
140
|
+
+ 'translated. OrbStack handles that itself; Docker Desktop needs '
|
|
141
|
+
+ 'Rosetta enabled.',
|
|
142
|
+
requires: ['Docker running'],
|
|
143
|
+
liveView:
|
|
144
|
+
'Built in. This call returns a local `viewerUrl`, and '
|
|
145
|
+
+ 'share_browser_view turns that into a public link for the person '
|
|
146
|
+
+ 'helping you.',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
mode: 'builder',
|
|
150
|
+
useCase: 'Someone else has to sign in, or you need a phone',
|
|
151
|
+
label: 'Remote browser, hosted by Reclaim — CHARGEABLE',
|
|
152
|
+
detail:
|
|
153
|
+
'A browser allocated in Reclaim\'s cloud, billed against the '
|
|
154
|
+
+ 'organization\'s quota. Nothing to install, and the shareable link '
|
|
155
|
+
+ 'comes back immediately. It is also the only way to browse a site '
|
|
156
|
+
+ 'from a SPECIFIC COUNTRY — its whole egress is routed there. '
|
|
157
|
+
+ 'Geolocation is optional: omit countryCode to be offered a '
|
|
158
|
+
+ 'suggestion, or pass skipCountry to allocate without geo-routing.',
|
|
159
|
+
requires: [
|
|
160
|
+
'Builder authentication',
|
|
161
|
+
'orgId (auto-resolved when you have only one)',
|
|
162
|
+
'quota — this one costs money',
|
|
163
|
+
],
|
|
164
|
+
liveView:
|
|
165
|
+
'Included. This call returns a hosted liveViewUrl to pass on; '
|
|
166
|
+
+ 'share_browser_view does not apply.',
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
mode: 'custom',
|
|
170
|
+
useCase: 'Advanced',
|
|
171
|
+
label: 'A CDP endpoint you supply',
|
|
172
|
+
detail:
|
|
173
|
+
'Connects to any ws:// or wss:// CDP websocket — a browser you run '
|
|
174
|
+
+ 'elsewhere, or another tool\'s. The URL is treated as a credential: '
|
|
175
|
+
+ 'never logged, persisted, or returned. Only pick this if you were '
|
|
176
|
+
+ 'given an endpoint and know why.',
|
|
177
|
+
requires: ['cdpUrl'],
|
|
178
|
+
liveView:
|
|
179
|
+
'None, unless you pass your own liveViewUrl alongside the cdpUrl.',
|
|
180
|
+
},
|
|
181
|
+
] as const
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The options as prose, grouped by use case.
|
|
185
|
+
*
|
|
186
|
+
* The grouping is the useful part: it turns "pick one of five transports" into
|
|
187
|
+
* "answer one question, then pick one of two".
|
|
188
|
+
*/
|
|
189
|
+
function renderBrowserOptions(): string {
|
|
190
|
+
const seen = new Set<string>()
|
|
191
|
+
const lines: string[] = []
|
|
192
|
+
for(const option of BROWSER_OPTIONS) {
|
|
193
|
+
if(!seen.has(option.useCase)) {
|
|
194
|
+
seen.add(option.useCase)
|
|
195
|
+
lines.push(`— ${option.useCase.toUpperCase()} —`)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const needs = option.requires.length
|
|
199
|
+
? ` Needs: ${option.requires.join('; ')}.`
|
|
200
|
+
: ''
|
|
201
|
+
lines.push(
|
|
202
|
+
`(${option.mode}) ${option.label}. ${option.detail}${needs}`
|
|
203
|
+
+ ` Live view: ${option.liveView}`,
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return lines.join(' ')
|
|
43
208
|
}
|
|
44
209
|
|
|
45
210
|
interface AttachDependencies {
|
|
46
211
|
connectLocal: typeof connectCdp
|
|
47
212
|
connectRemote: typeof connectCdpUrl
|
|
213
|
+
/** Injected so container mode is testable without Docker installed. */
|
|
214
|
+
dockerAvailable: typeof dockerAvailable
|
|
215
|
+
startContainer: typeof startContainer
|
|
48
216
|
}
|
|
49
217
|
|
|
50
218
|
const DEFAULT_DEPENDENCIES: AttachDependencies = {
|
|
51
219
|
connectLocal: connectCdp,
|
|
52
220
|
connectRemote: connectCdpUrl,
|
|
221
|
+
dockerAvailable,
|
|
222
|
+
startContainer,
|
|
53
223
|
}
|
|
54
224
|
|
|
55
225
|
export function attachTool(
|
|
56
226
|
state: AttachRef,
|
|
57
227
|
builderClient?: ReclaimClient,
|
|
58
|
-
name: 'attach_browser' | 'attach_chrome' = 'attach_browser',
|
|
59
228
|
beforeReplace?: () => Promise<void>,
|
|
60
|
-
|
|
229
|
+
// Partial so a caller can stub one thing without restating the rest — the
|
|
230
|
+
// tests only ever care about a couple of these at a time.
|
|
231
|
+
dependencies: Partial<AttachDependencies> = {},
|
|
61
232
|
): RegisteredTool {
|
|
233
|
+
const deps: AttachDependencies = {
|
|
234
|
+
...DEFAULT_DEPENDENCIES, ...dependencies,
|
|
235
|
+
}
|
|
62
236
|
return defineTool<AttachArgs>(
|
|
63
237
|
{
|
|
64
|
-
name,
|
|
238
|
+
name: 'attach_browser',
|
|
65
239
|
description:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
240
|
+
'Connect the provider-authoring tools to a browser. Never choose '
|
|
241
|
+
+ 'for them, never assume a previous session\'s choice still '
|
|
242
|
+
+ 'applies, and call this ONCE with the `mode` they pick. '
|
|
243
|
+
+ 'ASK THIS FIRST, before listing anything: "Will you be doing this '
|
|
244
|
+
+ 'yourself, or does someone else need to sign in — for example the '
|
|
245
|
+
+ 'person whose account it is?" That answer decides half the list, '
|
|
246
|
+
+ 'and a developer can answer it without knowing what CDP is. '
|
|
247
|
+
+ 'THEMSELVES → offer `dedicated` or `attach`. SOMEONE ELSE, or the '
|
|
248
|
+
+ 'site only works on a phone → offer `container` or `builder`, '
|
|
249
|
+
+ 'which are the only two that produce a link another person can '
|
|
250
|
+
+ 'open. Say which of those two costs money: `container` is free '
|
|
251
|
+
+ 'but needs Docker, `builder` needs no install but is billed '
|
|
252
|
+
+ 'against the org\'s quota. '
|
|
253
|
+
+ 'Then relay the matching options with their live-view lines. You '
|
|
254
|
+
+ 'do not need a discovery call — the full list is here, and calling '
|
|
255
|
+
+ 'with no `mode` returns it as structured `options` if you would '
|
|
256
|
+
+ 'rather read it back verbatim. '
|
|
257
|
+
+ 'OPTIONS — ' + renderBrowserOptions() + ' '
|
|
258
|
+
+ 'A `container` browser returns a local `viewerUrl`; relay it. When '
|
|
259
|
+
+ 'someone remote needs in, call share_browser_view and relay the '
|
|
260
|
+
+ 'FULL public url verbatim, on its own line. `builder` returns a '
|
|
261
|
+
+ 'hosted `liveViewUrl` — relay that the same way. `dedicated`, '
|
|
262
|
+
+ '`attach` and `custom` cannot be shared at all: if they ask for a '
|
|
263
|
+
+ 'link after picking one, say so and offer to re-attach with '
|
|
264
|
+
+ '`container`. '
|
|
265
|
+
+ 'Builder and custom CDP credentials are held in memory and are '
|
|
266
|
+
+ 'never returned. '
|
|
267
|
+
+ 'More: how_it_works({ topic: "browser" }).',
|
|
80
268
|
inputSchema: {
|
|
81
269
|
type: 'object',
|
|
82
270
|
properties: {
|
|
83
271
|
mode: {
|
|
84
272
|
type: 'string',
|
|
85
|
-
enum: [
|
|
273
|
+
enum: [
|
|
274
|
+
'dedicated', 'attach', 'container', 'builder', 'custom',
|
|
275
|
+
],
|
|
86
276
|
},
|
|
87
277
|
attachMode: {
|
|
88
278
|
type: 'string',
|
|
@@ -93,21 +283,59 @@ export function attachTool(
|
|
|
93
283
|
orgId: { type: 'string', format: 'uuid' },
|
|
94
284
|
cdpUrl: { type: 'string', maxLength: 4000 },
|
|
95
285
|
liveViewUrl: { type: 'string', format: 'uri', maxLength: 4000 },
|
|
286
|
+
viewerPort: {
|
|
287
|
+
type: 'number',
|
|
288
|
+
minimum: 1024,
|
|
289
|
+
maximum: 60000,
|
|
290
|
+
description:
|
|
291
|
+
'`container` mode only. Loopback port for the built-in live '
|
|
292
|
+
+ 'viewer. Change it only to avoid a clash; the CDP port and '
|
|
293
|
+
+ 'the container name are derived from it.',
|
|
294
|
+
},
|
|
295
|
+
countryCode: {
|
|
296
|
+
type: 'string',
|
|
297
|
+
pattern: '^[A-Za-z]{2}$',
|
|
298
|
+
description:
|
|
299
|
+
'Builder mode only. ISO 3166-1 alpha-2 country the remote '
|
|
300
|
+
+ 'browser browses from, fixed for the whole session. Omit to '
|
|
301
|
+
+ 'get a suggested country back (needsChoice) instead of '
|
|
302
|
+
+ 'allocating a browser.',
|
|
303
|
+
},
|
|
304
|
+
skipCountry: {
|
|
305
|
+
type: 'boolean',
|
|
306
|
+
description:
|
|
307
|
+
'Builder mode only. Allocate without geo-routing, skipping '
|
|
308
|
+
+ 'the country prompt. Pass this once the developer has said '
|
|
309
|
+
+ 'they don\'t need a specific country.',
|
|
310
|
+
},
|
|
96
311
|
},
|
|
97
312
|
},
|
|
98
313
|
},
|
|
99
314
|
async(parsed) => {
|
|
100
315
|
const persisted = state.config.read()?.browser_agent
|
|
101
|
-
|
|
316
|
+
// Deliberately NOT falling back to the persisted mode: which browser
|
|
317
|
+
// to drive is the developer's call every time (a remote one costs
|
|
318
|
+
// quota, a local one exposes their own profile), and silently reusing
|
|
319
|
+
// last session's answer takes that decision away from them. The
|
|
320
|
+
// persisted choice is offered back as a default to suggest, not
|
|
321
|
+
// applied.
|
|
322
|
+
const mode = parsed.mode ?? parsed.attachMode
|
|
102
323
|
if(!mode) {
|
|
103
324
|
return {
|
|
104
325
|
needsChoice: true,
|
|
105
326
|
message:
|
|
106
|
-
'
|
|
107
|
-
+ '
|
|
108
|
-
+ '
|
|
109
|
-
+ '
|
|
110
|
-
+ '
|
|
327
|
+
'Ask FIRST whether they will be doing this themselves or '
|
|
328
|
+
+ 'someone else has to sign in — that answer decides half the '
|
|
329
|
+
+ 'list. Themselves: `dedicated` or `attach`. Someone else, or '
|
|
330
|
+
+ 'a phone-only site: `container` (free, needs Docker) or '
|
|
331
|
+
+ '`builder` (no install, chargeable) — the only two that give '
|
|
332
|
+
+ 'you a link to send. Then present the matching options and '
|
|
333
|
+
+ 'call attach_browser again with the `mode` they pick. Do not '
|
|
334
|
+
+ 'pick one for them.',
|
|
335
|
+
options: BROWSER_OPTIONS,
|
|
336
|
+
...(persisted?.attachMode
|
|
337
|
+
? { previouslyUsed: persisted.attachMode }
|
|
338
|
+
: {}),
|
|
111
339
|
configPath: defaultConfigPath(),
|
|
112
340
|
}
|
|
113
341
|
}
|
|
@@ -146,8 +374,51 @@ export function attachTool(
|
|
|
146
374
|
orgId = orgs[0].id
|
|
147
375
|
}
|
|
148
376
|
|
|
377
|
+
// A remote browser's exit country is fixed for the whole session —
|
|
378
|
+
// Popcorn applies it at allocation and it can't be changed later. So
|
|
379
|
+
// confirm it with the developer BEFORE spending a quota-accounted
|
|
380
|
+
// browser on the wrong one, the same way orgId is confirmed above.
|
|
381
|
+
// Geo-routing is OPTIONAL though, so this asks rather than demands:
|
|
382
|
+
// `skipCountry` is the "no particular country" answer, and it must be
|
|
383
|
+
// as reachable as naming one.
|
|
384
|
+
if(mode === 'builder' && !parsed.countryCode && !parsed.skipCountry) {
|
|
385
|
+
const suggestion = await suggestCountryFromIp()
|
|
386
|
+
return {
|
|
387
|
+
needsChoice: true,
|
|
388
|
+
message:
|
|
389
|
+
'Ask the developer which country this browser should browse '
|
|
390
|
+
+ 'from — its egress is routed through that country for the '
|
|
391
|
+
+ 'whole session and cannot be changed afterwards. Geolocation '
|
|
392
|
+
+ 'is optional; offer all three answers below. Nothing has been '
|
|
393
|
+
+ 'allocated yet, so this costs nothing.',
|
|
394
|
+
choices: [
|
|
395
|
+
{
|
|
396
|
+
answer: 'The suggested country',
|
|
397
|
+
howToCall: `attach_browser({ mode: "builder", countryCode: "${
|
|
398
|
+
suggestion.countryCode}" })`,
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
answer: 'A specific country the site must be seen from',
|
|
402
|
+
howToCall:
|
|
403
|
+
'attach_browser({ mode: "builder", countryCode: "<ISO '
|
|
404
|
+
+ '3166-1 alpha-2>" })',
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
answer: 'No particular country',
|
|
408
|
+
howToCall:
|
|
409
|
+
'attach_browser({ mode: "builder", skipCountry: true })',
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
suggestedCountryCode: suggestion.countryCode,
|
|
413
|
+
suggestionSource: 'caller-ip',
|
|
414
|
+
...(suggestion.country ? { country: suggestion.country } : {}),
|
|
415
|
+
...(suggestion.region ? { region: suggestion.region } : {}),
|
|
416
|
+
...(suggestion.city ? { city: suggestion.city } : {}),
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
149
420
|
const next = await connect(
|
|
150
|
-
mode, { ...parsed, orgId }, persisted, builderClient,
|
|
421
|
+
mode, { ...parsed, orgId }, persisted, builderClient, deps,
|
|
151
422
|
)
|
|
152
423
|
try {
|
|
153
424
|
await beforeReplace?.()
|
|
@@ -164,6 +435,11 @@ export function attachTool(
|
|
|
164
435
|
})
|
|
165
436
|
}
|
|
166
437
|
|
|
438
|
+
// How the developer watches this browser differs per mode, and none of
|
|
439
|
+
// it is guessable, so every mode says its own piece here.
|
|
440
|
+
const localView = mode === 'container'
|
|
441
|
+
const hostedView = Boolean(next.liveViewUrl) && !localView
|
|
442
|
+
const canShare = SHAREABLE_MODES.has(mode)
|
|
167
443
|
return {
|
|
168
444
|
attached: true,
|
|
169
445
|
mode,
|
|
@@ -172,6 +448,38 @@ export function attachTool(
|
|
|
172
448
|
? { browserSessionId: next.browserSessionId }
|
|
173
449
|
: {}),
|
|
174
450
|
...(next.liveViewUrl ? { liveViewUrl: next.liveViewUrl } : {}),
|
|
451
|
+
...(next.countryCode ? { countryCode: next.countryCode } : {}),
|
|
452
|
+
...(next.containerName ? { containerName: next.containerName } : {}),
|
|
453
|
+
...(canShare ? { liveViewAvailable: true } : {}),
|
|
454
|
+
_notes: [
|
|
455
|
+
...(next.imagePulled
|
|
456
|
+
? ['The browser runtime image was downloaded just now (about '
|
|
457
|
+
+ '432 MB, about 1.3 GB on disk). Mention it — later attaches '
|
|
458
|
+
+ 'reuse it. RECLAIM_BROWSER_RUNTIME_IMAGE points at a '
|
|
459
|
+
+ 'different or locally built image.']
|
|
460
|
+
: []),
|
|
461
|
+
...(localView
|
|
462
|
+
? ['This browser has its own live view, already running on this '
|
|
463
|
+
+ 'machine: relay `liveViewUrl` to the developer verbatim, on '
|
|
464
|
+
+ 'its own line, so they can watch and drive it. It is '
|
|
465
|
+
+ 'loopback-only, so only they can reach it. If someone ELSE '
|
|
466
|
+
+ 'needs to — a login only they can complete — call '
|
|
467
|
+
+ 'share_browser_view to put that same viewer behind a public '
|
|
468
|
+
+ 'URL.']
|
|
469
|
+
: []),
|
|
470
|
+
...(hostedView
|
|
471
|
+
? ['This browser has a hosted live view already. Relay '
|
|
472
|
+
+ '`liveViewUrl` to the developer verbatim, on its own line, '
|
|
473
|
+
+ 'so they can watch the run — share_browser_view does not '
|
|
474
|
+
+ 'apply here.']
|
|
475
|
+
: []),
|
|
476
|
+
...(!localView && !hostedView
|
|
477
|
+
? ['This browser has no live view: it runs on the developer\'s '
|
|
478
|
+
+ 'own machine, so they watch it by looking at it. If someone '
|
|
479
|
+
+ 'ELSE needs to see or drive it, say that `container` mode '
|
|
480
|
+
+ 'runs a browser with a shareable live view built in.']
|
|
481
|
+
: []),
|
|
482
|
+
],
|
|
175
483
|
}
|
|
176
484
|
},
|
|
177
485
|
)
|
|
@@ -197,8 +505,10 @@ async function connect(
|
|
|
197
505
|
if(mode === 'builder') {
|
|
198
506
|
assert(builderClient, badRequest('Builder browser service is unavailable'))
|
|
199
507
|
assert(parsed.orgId, badRequest('orgId is required for builder mode'))
|
|
508
|
+
const countryCode = parsed.countryCode?.trim().toUpperCase()
|
|
200
509
|
const { data } = await builderClient.call('CreateAgentBrowserSession', {
|
|
201
510
|
params: { orgId: parsed.orgId },
|
|
511
|
+
body: countryCode ? { countryCode } : {},
|
|
202
512
|
})
|
|
203
513
|
let handles: CdpHandles
|
|
204
514
|
try {
|
|
@@ -219,6 +529,8 @@ async function connect(
|
|
|
219
529
|
liveViewUrl: data.liveViewUrl,
|
|
220
530
|
browserSessionId: data.id,
|
|
221
531
|
orgId: parsed.orgId,
|
|
532
|
+
...(data.apiUrl ? { apiUrl: data.apiUrl } : {}),
|
|
533
|
+
...(countryCode ? { countryCode } : {}),
|
|
222
534
|
disposeRemote: async() => {
|
|
223
535
|
await builderClient.call('DisposeAgentBrowserSession', {
|
|
224
536
|
params: {
|
|
@@ -244,6 +556,35 @@ async function connect(
|
|
|
244
556
|
}
|
|
245
557
|
}
|
|
246
558
|
|
|
559
|
+
if(mode === 'container') {
|
|
560
|
+
assert(await dependencies.dockerAvailable(),
|
|
561
|
+
badRequest(dockerMissingMessage()))
|
|
562
|
+
// Ports are allocated per session unless the caller names one. A fixed
|
|
563
|
+
// default would give two concurrent sessions the SAME container — the
|
|
564
|
+
// name derives from the viewer port — so session two would silently
|
|
565
|
+
// drive session one's browser.
|
|
566
|
+
const container = await dependencies.startContainer({
|
|
567
|
+
...(parsed.viewerPort ? { viewerPort: parsed.viewerPort } : {}),
|
|
568
|
+
image: process.env.RECLAIM_BROWSER_RUNTIME_IMAGE?.trim() || undefined,
|
|
569
|
+
})
|
|
570
|
+
try {
|
|
571
|
+
return {
|
|
572
|
+
handles: await dependencies.connectRemote(container.cdpUrl),
|
|
573
|
+
mode,
|
|
574
|
+
liveViewUrl: container.viewerUrl,
|
|
575
|
+
containerName: container.name,
|
|
576
|
+
viewerPort: container.viewerPort,
|
|
577
|
+
imagePulled: container.pulled,
|
|
578
|
+
disposeRemote: container.stop,
|
|
579
|
+
}
|
|
580
|
+
} catch(err) {
|
|
581
|
+
// Never leave a 1.3 GB container running for a browser we could not
|
|
582
|
+
// talk to.
|
|
583
|
+
await container.stop().catch(() => {})
|
|
584
|
+
throw err
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
247
588
|
const port = parsed.port ?? persisted?.port ?? 9222
|
|
248
589
|
if(mode === 'dedicated') {
|
|
249
590
|
try {
|
|
@@ -19,33 +19,40 @@ import { type AttachState, attachTool } from './attach.ts'
|
|
|
19
19
|
import { type CaptureStore, captureTools, resetCaptures } from './capture.ts'
|
|
20
20
|
import { listTabsTool } from './eval.ts'
|
|
21
21
|
import { howItWorksTool } from './how-it-works.ts'
|
|
22
|
+
import { type LiveShareRef, liveViewTools } from './live-view.ts'
|
|
23
|
+
import { podProofTools } from './pod-proof.ts'
|
|
22
24
|
import { createVersionFromCaptureTool } from './publish.ts'
|
|
23
|
-
import { sessionTools } from './session.ts'
|
|
25
|
+
import { resetAll, sessionTools } from './session.ts'
|
|
24
26
|
import { sharedAuthoringTools } from './shared.ts'
|
|
25
27
|
|
|
26
28
|
export interface AgentState {
|
|
27
29
|
attach: { current?: AttachState, config: ConfigStore }
|
|
28
30
|
captures: CaptureStore
|
|
31
|
+
/** The one public live view, when `share_browser_view` has opened it. */
|
|
32
|
+
liveShare: LiveShareRef
|
|
29
33
|
}
|
|
30
34
|
|
|
31
|
-
/** Exported so a mode (
|
|
32
|
-
* can build the attach/capture state up front and share the SAME
|
|
33
|
-
* with `buildAgentTools` — letting that publish tool see the live
|
|
34
|
-
* state (
|
|
35
|
+
/** Exported so a mode (for example, old-devtools) that supplies its own
|
|
36
|
+
* publish tool can build the attach/capture state up front and share the SAME
|
|
37
|
+
* instance with `buildAgentTools` — letting that publish tool see the live
|
|
38
|
+
* attach state (for example, to remind the caller about a still-open browser
|
|
39
|
+
* session). */
|
|
35
40
|
export function buildAgentState(): AgentState {
|
|
36
41
|
return {
|
|
37
42
|
attach: { config: new ConfigStore() },
|
|
38
43
|
captures: { sessions: new Map() },
|
|
44
|
+
liveShare: {},
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
/** Build the flat list of `RegisteredTool` entries, ready for
|
|
43
49
|
* `registerToolList`.
|
|
44
50
|
* Pass `client` to include the builder `create_provider_version_from_capture`;
|
|
45
|
-
* omit it (
|
|
46
|
-
* capture/proof tools — old mode supplies its own publish
|
|
47
|
-
* Pass `externalState` to share attach/capture state with tools
|
|
48
|
-
* elsewhere (
|
|
51
|
+
* omit it (for example, OLD-devtools mode) to register only the
|
|
52
|
+
* backend-independent capture/proof tools — old mode supplies its own publish
|
|
53
|
+
* tool. Pass `externalState` to share attach/capture state with tools
|
|
54
|
+
* registered elsewhere (for example, old mode's publish tool) instead of
|
|
55
|
+
* building a fresh one. */
|
|
49
56
|
export function buildAgentTools(
|
|
50
57
|
client?: ReclaimClient,
|
|
51
58
|
builderClient: ReclaimClient | undefined = client,
|
|
@@ -58,18 +65,22 @@ export function buildAgentTools(
|
|
|
58
65
|
// client. No `client` ⇒ old-devtools mode (see `mcp/start.ts`).
|
|
59
66
|
tools.push(howItWorksTool(!client))
|
|
60
67
|
const beforeReplace = () => resetCaptures(state.captures)
|
|
61
|
-
tools.push(attachTool(
|
|
62
|
-
state.attach, builderClient, 'attach_browser', beforeReplace,
|
|
63
|
-
))
|
|
64
|
-
tools.push(attachTool(
|
|
65
|
-
state.attach, builderClient, 'attach_chrome', beforeReplace,
|
|
66
|
-
))
|
|
68
|
+
tools.push(attachTool(state.attach, builderClient, beforeReplace))
|
|
67
69
|
tools.push(listTabsTool(state.attach))
|
|
68
70
|
for(const t of captureTools(state.attach, state.captures)) {
|
|
69
71
|
tools.push(t)
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
for(const t of sessionTools(state.attach, state.captures)) {
|
|
74
|
+
for(const t of sessionTools(state.attach, state.captures, state.liveShare)) {
|
|
75
|
+
tools.push(t)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Local-CDP only: a builder-mode browser already has a hosted live view.
|
|
79
|
+
for(const t of liveViewTools(state.attach, state.liveShare)) {
|
|
80
|
+
tools.push(t)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for(const t of podProofTools(state.attach, state.captures)) {
|
|
73
84
|
tools.push(t)
|
|
74
85
|
}
|
|
75
86
|
|
|
@@ -87,3 +98,11 @@ export function buildAgentTools(
|
|
|
87
98
|
|
|
88
99
|
return tools
|
|
89
100
|
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Tear down an agent state on the way out. Safe to call more than once, and
|
|
104
|
+
* safe when nothing was ever attached.
|
|
105
|
+
*/
|
|
106
|
+
export async function disposeAgentState(state: AgentState): Promise<void> {
|
|
107
|
+
await resetAll(state.attach, state.captures, state.liveShare)
|
|
108
|
+
}
|
|
@@ -93,7 +93,11 @@ export function captureTools(
|
|
|
93
93
|
{
|
|
94
94
|
name: 'get_request',
|
|
95
95
|
description:
|
|
96
|
-
'Return full headers
|
|
96
|
+
'Return the full headers and bodies of one captured request. Use it '
|
|
97
|
+
+ 'to inspect a candidate that find_requests_containing ranked. '
|
|
98
|
+
+ 'Unlike every other tool here, the headers are RAW — cookie and '
|
|
99
|
+
+ 'authorization values are visible. Read them; never repeat them to '
|
|
100
|
+
+ 'the developer or write them to a file.',
|
|
97
101
|
inputSchema: {
|
|
98
102
|
type: 'object',
|
|
99
103
|
properties: {
|
|
@@ -10,7 +10,10 @@ export function listTabsTool(attachRef: {
|
|
|
10
10
|
return defineTool<Record<string, never>>(
|
|
11
11
|
{
|
|
12
12
|
name: 'list_tabs',
|
|
13
|
-
description:
|
|
13
|
+
description:
|
|
14
|
+
'List the open tabs in the attached browser, with their tabId, title '
|
|
15
|
+
+ 'and URL. Call it after attach_browser to pick the tabId to pass to '
|
|
16
|
+
+ 'start_capture.',
|
|
14
17
|
inputSchema: { type: 'object', properties: {} },
|
|
15
18
|
},
|
|
16
19
|
async() => {
|
|
@@ -22,9 +22,10 @@ export function findTool(resolveBackend: ResolveBackend): RegisteredTool {
|
|
|
22
22
|
+ 'URL/JSON/HTML-escaped, …). Returns a ranked candidate list with '
|
|
23
23
|
+ 'the matched variant, score, and a short snippet — used to locate '
|
|
24
24
|
+ 'the request that returns a target. Also finds SPLIT matches: when '
|
|
25
|
-
+ '`value` is multi-word (
|
|
26
|
-
+ 'every word SEPARATELY (a JSON profile API with
|
|
27
|
-
+ 'distinct fields) is returned with
|
|
25
|
+
+ '`value` is multi-word (for example, a full name), a response '
|
|
26
|
+
+ 'that carries every word SEPARATELY (a JSON profile API with '
|
|
27
|
+
+ 'first and last name in distinct fields) is returned with '
|
|
28
|
+
+ '`splitMatch:true` — prove those '
|
|
28
29
|
+ 'per-field (a redaction per part) rather than as one string. '
|
|
29
30
|
+ 'Server-side; bodies stay here.',
|
|
30
31
|
inputSchema: objectSchema(
|
|
@@ -77,8 +78,8 @@ export function findTool(resolveBackend: ResolveBackend): RegisteredTool {
|
|
|
77
78
|
continue
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
// Split match: every word present separately (
|
|
81
|
-
// in distinct JSON fields). Requires ≥2 tokens so it's specific.
|
|
81
|
+
// Split match: every word present separately (for example, first/last
|
|
82
|
+
// name in distinct JSON fields). Requires ≥2 tokens so it's specific.
|
|
82
83
|
if(tokens.length >= 2 && tokens.every((t) => body.includes(t))) {
|
|
83
84
|
ranked.push({
|
|
84
85
|
...publicRequest(r),
|