@reclaimprotocol/agent 0.1.4 → 0.1.6
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 +5 -5
- package/lib/authoring/backend.d.ts +71 -0
- package/lib/authoring/backend.js +24 -0
- package/lib/authoring/find.d.ts +3 -0
- package/lib/authoring/find.js +54 -0
- package/lib/authoring/index.d.ts +4 -0
- package/lib/authoring/index.js +6 -0
- package/lib/authoring/propose.d.ts +3 -0
- package/lib/authoring/propose.js +109 -0
- package/lib/authoring/replay.d.ts +10 -0
- package/lib/authoring/replay.js +34 -0
- package/lib/authoring/tools.d.ts +16 -0
- package/lib/authoring/tools.js +193 -0
- package/lib/authoring/util.d.ts +27 -0
- package/lib/authoring/util.js +21 -0
- package/lib/cdp/capture-engine.js +1 -1
- package/lib/consts.d.ts +6 -1
- package/lib/consts.js +9 -2
- package/lib/mcp/api/operations.gen.js +46 -18
- package/lib/mcp/server.d.ts +2 -25
- package/lib/mcp/server.js +4 -17
- package/lib/mcp/start.js +4 -2
- package/lib/mcp/tools/agent/analyze.js +3 -3
- package/lib/mcp/tools/agent/build.d.ts +4 -4
- package/lib/mcp/tools/agent/build.js +13 -15
- package/lib/mcp/tools/agent/capture.d.ts +13 -1
- package/lib/mcp/tools/agent/capture.js +18 -85
- package/lib/mcp/tools/agent/eval.d.ts +5 -2
- package/lib/mcp/tools/agent/eval.js +11 -121
- package/lib/mcp/tools/agent/find.d.ts +10 -3
- package/lib/mcp/tools/agent/find.js +25 -31
- package/lib/mcp/tools/agent/proof.d.ts +13 -3
- package/lib/mcp/tools/agent/proof.js +81 -132
- package/lib/mcp/tools/agent/propose.d.ts +10 -9
- package/lib/mcp/tools/agent/propose.js +87 -64
- package/lib/mcp/tools/agent/publish.js +2 -2
- package/lib/mcp/tools/agent/replay.d.ts +10 -3
- package/lib/mcp/tools/agent/replay.js +29 -36
- package/lib/mcp/tools/agent/session.d.ts +1 -3
- package/lib/mcp/tools/agent/session.js +5 -5
- package/lib/mcp/tools/agent/shared.d.ts +8 -0
- package/lib/mcp/tools/agent/shared.js +125 -0
- package/lib/old/client.d.ts +35 -0
- package/lib/old/client.js +18 -0
- package/lib/old/login-cdp.d.ts +24 -0
- package/lib/old/login-cdp.js +28 -3
- package/lib/old/sdk-client.d.ts +39 -0
- package/lib/old/sdk-client.js +85 -0
- package/lib/old/to-register.d.ts +69 -0
- package/lib/old/to-register.js +52 -2
- package/lib/old/tools/build.d.ts +6 -1
- package/lib/old/tools/build.js +11 -1
- package/lib/old/tools/get-provider-info.d.ts +16 -0
- package/lib/old/tools/get-provider-info.js +73 -0
- package/lib/old/tools/get-version-config.d.ts +17 -0
- package/lib/old/tools/get-version-config.js +47 -0
- package/lib/old/tools/publish.js +189 -2
- package/lib/old/tools/update-provider-metadata.d.ts +16 -0
- package/lib/old/tools/update-provider-metadata.js +61 -0
- package/lib/proof/attestor.d.ts +6 -3
- package/lib/proof/attestor.js +10 -1
- package/lib/proof/debug-response-dump.d.ts +4 -0
- package/lib/proof/debug-response-dump.js +55 -0
- package/lib/proof/patch-domhandler.d.ts +1 -0
- package/lib/proof/patch-domhandler.js +59 -0
- package/lib/proof/proof-core.d.ts +1 -1
- package/lib/proof/proof-core.js +1 -1
- package/lib/proof/zk-files.js +7 -6
- package/lib/provider/dom-xpath.d.ts +17 -0
- package/lib/provider/dom-xpath.js +187 -0
- package/lib/provider/draft.d.ts +30 -2
- package/lib/provider/draft.js +117 -28
- package/lib/provider/index.d.ts +4 -0
- package/lib/provider/index.js +7 -0
- package/lib/provider/injection-doc.js +6 -0
- package/lib/provider/matcher.d.ts +17 -20
- package/lib/provider/matcher.js +394 -280
- package/lib/provider/schema.d.ts +7 -5
- package/lib/tools/registry.d.ts +50 -0
- package/lib/tools/registry.js +49 -0
- package/package.json +9 -1
- package/skill/SKILL.builder.md +55 -32
- package/skill/SKILL.old.md +20 -12
- package/skill/builder-mode.md +1 -1
- package/skill/injection-api.md +117 -0
- package/src/authoring/backend.ts +98 -0
- package/src/authoring/index.ts +20 -0
- package/src/authoring/tools.ts +273 -0
- package/src/authoring/util.ts +42 -0
- package/src/cdp/capture-engine.ts +1 -1
- package/src/consts.ts +15 -2
- package/src/mcp/api/operations.gen.ts +46 -18
- package/src/mcp/server.ts +9 -39
- package/src/mcp/start.ts +4 -1
- package/src/mcp/tools/agent/analyze.ts +3 -3
- package/src/mcp/tools/agent/build.ts +13 -21
- package/src/mcp/tools/agent/capture.ts +31 -115
- package/src/mcp/tools/agent/eval.ts +19 -155
- package/src/mcp/tools/agent/find.ts +33 -36
- package/src/mcp/tools/agent/proof.ts +87 -160
- package/src/mcp/tools/agent/propose.ts +93 -85
- package/src/mcp/tools/agent/publish.ts +2 -2
- package/src/mcp/tools/agent/replay.ts +32 -42
- package/src/mcp/tools/agent/session.ts +4 -5
- package/src/mcp/tools/agent/shared.ts +152 -0
- package/src/old/client.ts +56 -0
- package/src/old/login-cdp.ts +28 -3
- package/src/old/sdk-client.ts +105 -0
- package/src/old/to-register.ts +98 -6
- package/src/old/tools/build.ts +12 -0
- package/src/old/tools/get-provider-info.ts +91 -0
- package/src/old/tools/get-version-config.ts +56 -0
- package/src/old/tools/publish.ts +244 -1
- package/src/old/tools/update-provider-metadata.ts +72 -0
- package/src/proof/attestor.ts +16 -4
- package/src/proof/debug-response-dump.ts +70 -0
- package/src/proof/patch-domhandler.ts +68 -0
- package/src/proof/proof-core.ts +1 -1
- package/src/proof/zk-files.ts +7 -6
- package/src/provider/dom-xpath.ts +225 -0
- package/src/provider/draft.ts +168 -35
- package/src/provider/index.ts +8 -0
- package/src/provider/injection-doc.ts +6 -0
- package/src/provider/matcher.ts +477 -357
- package/src/provider/schema.ts +7 -5
- package/src/tools/registry.ts +92 -0
package/src/old/tools/publish.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { Boom, isBoom } from '@hapi/boom'
|
|
2
2
|
import { defineTool, type RegisteredTool } from '../../mcp/server.ts'
|
|
3
|
+
import { INJECTION_GUIDE } from '../../provider/injection-doc.ts'
|
|
3
4
|
import {
|
|
4
5
|
countsFor,
|
|
5
6
|
matchRedactionWarnings,
|
|
6
7
|
} from '../../provider/match-redaction-warning.ts'
|
|
7
8
|
import type { ReclaimProvider } from '../../provider/schema.ts'
|
|
9
|
+
import type { AllowedJsRequest } from '../../provider/to-version.ts'
|
|
8
10
|
import type { ReclaimOldClient } from '../client.ts'
|
|
9
11
|
import {
|
|
10
12
|
bumpPatchString,
|
|
11
13
|
extractVersions,
|
|
14
|
+
injectedRequestDataFrom,
|
|
15
|
+
type OldInjectedRequestData,
|
|
12
16
|
type OldProviderOpts,
|
|
13
17
|
providerToConfigBody,
|
|
14
18
|
providerToRegisterBody,
|
|
@@ -16,6 +20,56 @@ import {
|
|
|
16
20
|
|
|
17
21
|
const DEFAULT_VERSION_INFO = 'Updated from MCP browser capture'
|
|
18
22
|
|
|
23
|
+
/** Fields with no partial-patch equivalent on this backend: a version always
|
|
24
|
+
* replaces the WHOLE `providerConfig`, so omitting one of these on
|
|
25
|
+
* add-version must carry forward the current value rather than publish it
|
|
26
|
+
* blank. `allowedInjectedRequestData` is handled alongside these (see
|
|
27
|
+
* `resolveInjectedRequests`) since it needs translation when freshly
|
|
28
|
+
* authored, unlike these — which pass through unchanged either way. */
|
|
29
|
+
const PRESERVABLE_KEYS = [
|
|
30
|
+
'customInjection',
|
|
31
|
+
'userAgent',
|
|
32
|
+
'pageTitle',
|
|
33
|
+
'stepsToFollow',
|
|
34
|
+
'useIncognitoWebview',
|
|
35
|
+
'extensionConfig',
|
|
36
|
+
] as const
|
|
37
|
+
|
|
38
|
+
/** Pull `providerConfig` out of a `get_provider_version_config` /
|
|
39
|
+
* `getProviderConfig` response, tolerant of a missing/malformed shape. */
|
|
40
|
+
function extractProviderConfig(
|
|
41
|
+
resp: unknown,
|
|
42
|
+
): Record<string, unknown> | undefined {
|
|
43
|
+
if(resp && typeof resp === 'object') {
|
|
44
|
+
const cfg = (resp as { providerConfig?: unknown }).providerConfig
|
|
45
|
+
if(cfg && typeof cfg === 'object') {
|
|
46
|
+
return cfg as Record<string, unknown>
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return undefined
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Prefer the caller's explicit value; otherwise fall back to `current`'s
|
|
54
|
+
* value (if any) and record `fieldName` as carried forward. */
|
|
55
|
+
function resolveField<T>(
|
|
56
|
+
explicit: T | undefined,
|
|
57
|
+
current: unknown,
|
|
58
|
+
fieldName: string,
|
|
59
|
+
carried: string[],
|
|
60
|
+
): T | undefined {
|
|
61
|
+
if(explicit !== undefined) {
|
|
62
|
+
return explicit
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if(current !== undefined) {
|
|
66
|
+
carried.push(fieldName)
|
|
67
|
+
return current as T
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return undefined
|
|
71
|
+
}
|
|
72
|
+
|
|
19
73
|
/**
|
|
20
74
|
* The old backend lets you add a version only to a provider YOU own. A
|
|
21
75
|
* `providerId` for a public provider (or anyone else's) comes back as
|
|
@@ -71,6 +125,13 @@ export function createVersionFromCaptureTool(
|
|
|
71
125
|
useProxy?: boolean
|
|
72
126
|
providerType?: 'PRIVATE' | 'PUBLIC'
|
|
73
127
|
notes?: string
|
|
128
|
+
customInjection?: string
|
|
129
|
+
userAgent?: { ios?: string, android?: string }
|
|
130
|
+
pageTitle?: string
|
|
131
|
+
allowedInjectedRequestData?: AllowedJsRequest[]
|
|
132
|
+
stepsToFollow?: string
|
|
133
|
+
useIncognitoWebview?: boolean
|
|
134
|
+
extensionConfig?: unknown
|
|
74
135
|
}>(
|
|
75
136
|
{
|
|
76
137
|
name: 'create_provider_version_from_capture',
|
|
@@ -92,6 +153,23 @@ export function createVersionFromCaptureTool(
|
|
|
92
153
|
'must come from get_me_providers. To publish your own version of a ' +
|
|
93
154
|
"PUBLIC provider you don't own, omit `providerId` to register your " +
|
|
94
155
|
'own copy (you cannot edit someone else\'s provider here). \n\n' +
|
|
156
|
+
'For data gated behind login/navigation, pass `customInjection` — a ' +
|
|
157
|
+
'page-injection script (old-devtools\' name for the builder\'s ' +
|
|
158
|
+
'jsUserScripts) that drives the page to where the request fires. \n\n' +
|
|
159
|
+
'This backend has NO partial-patch endpoint — adding a version ' +
|
|
160
|
+
'always replaces the WHOLE providerConfig. When `providerId` is ' +
|
|
161
|
+
'set, any of `customInjection`, `userAgent`, `pageTitle`, ' +
|
|
162
|
+
'`allowedInjectedRequestData`, `stepsToFollow`, ' +
|
|
163
|
+
'`useIncognitoWebview`, `extensionConfig` that you OMIT is carried ' +
|
|
164
|
+
'forward unchanged from the currently-published version (so ' +
|
|
165
|
+
're-publishing requestData never wipes a working login script or ' +
|
|
166
|
+
'other config someone set via the dashboard). Pass an explicit ' +
|
|
167
|
+
'value (`""`, `[]`, `false`, ...) to intentionally clear one of ' +
|
|
168
|
+
'them instead, or call get_provider_version_config first to see ' +
|
|
169
|
+
'exactly what is live today before deciding what to change. ' +
|
|
170
|
+
'`allowedInjectedRequestData`/`useIncognitoWebview`/' +
|
|
171
|
+
'`extensionConfig` only take effect on add-version — the register ' +
|
|
172
|
+
'endpoint (no `providerId`) ignores them. \n\n' +
|
|
95
173
|
'Captured requests must be GET/POST. OPRF redactions are supported.',
|
|
96
174
|
inputSchema: {
|
|
97
175
|
type: 'object',
|
|
@@ -171,6 +249,78 @@ export function createVersionFromCaptureTool(
|
|
|
171
249
|
'Change note for the new version (update only; must be ≥10 ' +
|
|
172
250
|
'chars or a default is used).',
|
|
173
251
|
},
|
|
252
|
+
customInjection: {
|
|
253
|
+
type: 'string',
|
|
254
|
+
description:
|
|
255
|
+
'Plain JavaScript injected into the provider page before every ' +
|
|
256
|
+
'page load — old-devtools\' name for what the builder calls ' +
|
|
257
|
+
'`webSettings.jsUserScripts`. Use standard browser APIs ' +
|
|
258
|
+
'(window.location, element.click(), forms) to drive login/' +
|
|
259
|
+
'navigation so the target request fires — window.Reclaim is ' +
|
|
260
|
+
'only for rare edge cases, not navigation. The backend rejects ' +
|
|
261
|
+
'a few deprecated injection APIs (e.g. window.payloadData, ' +
|
|
262
|
+
'window.ReclaimInjected) with a 400. Guide:\n\n' +
|
|
263
|
+
INJECTION_GUIDE,
|
|
264
|
+
},
|
|
265
|
+
userAgent: {
|
|
266
|
+
type: 'object',
|
|
267
|
+
description:
|
|
268
|
+
'Per-platform user-agent override for the verification ' +
|
|
269
|
+
'webview. Accepted on register too.',
|
|
270
|
+
properties: {
|
|
271
|
+
ios: { type: 'string' },
|
|
272
|
+
android: { type: 'string' },
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
pageTitle: {
|
|
276
|
+
type: 'string',
|
|
277
|
+
description: 'Page title metadata. Accepted on register too.',
|
|
278
|
+
},
|
|
279
|
+
allowedInjectedRequestData: {
|
|
280
|
+
type: 'array',
|
|
281
|
+
description:
|
|
282
|
+
'Extra requests the customInjection script is allowed to ' +
|
|
283
|
+
'fire (e.g. pagination) — add-version ONLY, the register ' +
|
|
284
|
+
'endpoint ignores this. Each item has the same shape as ' +
|
|
285
|
+
'`provider`, plus `multiple`/`required` (default true).',
|
|
286
|
+
items: {
|
|
287
|
+
type: 'object',
|
|
288
|
+
properties: {
|
|
289
|
+
url: { type: 'string' },
|
|
290
|
+
method: { type: 'string' },
|
|
291
|
+
body: { type: 'string' },
|
|
292
|
+
responseMatches: { type: 'array' },
|
|
293
|
+
responseRedactions: { type: 'array' },
|
|
294
|
+
multiple: {
|
|
295
|
+
type: 'boolean',
|
|
296
|
+
description: 'Allow matching many requests. Default true.',
|
|
297
|
+
},
|
|
298
|
+
required: {
|
|
299
|
+
type: 'boolean',
|
|
300
|
+
description:
|
|
301
|
+
'Fail validation if none match. Default true.',
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
required: ['url', 'method'],
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
stepsToFollow: {
|
|
308
|
+
type: 'string',
|
|
309
|
+
description:
|
|
310
|
+
'Free-text setup/manual-verification steps shown to the ' +
|
|
311
|
+
'dev/verifier. Add-version ONLY.',
|
|
312
|
+
},
|
|
313
|
+
useIncognitoWebview: {
|
|
314
|
+
type: 'boolean',
|
|
315
|
+
description:
|
|
316
|
+
'Run the verification webview in incognito mode. ' +
|
|
317
|
+
'Add-version ONLY.',
|
|
318
|
+
},
|
|
319
|
+
extensionConfig: {
|
|
320
|
+
description:
|
|
321
|
+
'Free-form JSON passed through to the client. Add-version ' +
|
|
322
|
+
'ONLY.',
|
|
323
|
+
},
|
|
174
324
|
},
|
|
175
325
|
required: ['initialUrl'],
|
|
176
326
|
},
|
|
@@ -207,11 +357,16 @@ export function createVersionFromCaptureTool(
|
|
|
207
357
|
opts.providerType = args.providerType
|
|
208
358
|
}
|
|
209
359
|
|
|
360
|
+
if(args.customInjection !== undefined) {
|
|
361
|
+
opts.customInjection = args.customInjection
|
|
362
|
+
}
|
|
363
|
+
|
|
210
364
|
// Non-blocking advisory per request — never alters or blocks the
|
|
211
365
|
// publish; the author keeps full control. Attaches under `_notes`.
|
|
212
366
|
const notes = matchRedactionWarnings(
|
|
213
367
|
providers.map((p, i) => countsFor(`Request ${i + 1}`, p)),
|
|
214
368
|
)
|
|
369
|
+
|
|
215
370
|
const withNotes = (result: unknown) => {
|
|
216
371
|
if(notes.length && result && typeof result === 'object') {
|
|
217
372
|
return { ...result, _notes: notes }
|
|
@@ -220,8 +375,46 @@ export function createVersionFromCaptureTool(
|
|
|
220
375
|
return result
|
|
221
376
|
}
|
|
222
377
|
|
|
223
|
-
// New provider.
|
|
378
|
+
// New provider — no prior version to carry anything forward from.
|
|
379
|
+
// `allowedInjectedRequestData` / `useIncognitoWebview` /
|
|
380
|
+
// `extensionConfig` are accepted on the schema but the register
|
|
381
|
+
// controller never reads them from the body — warn rather than
|
|
382
|
+
// silently drop, so a dev doesn't think they took effect.
|
|
224
383
|
if(!args.providerId) {
|
|
384
|
+
if(opts.customInjection?.trim()) {
|
|
385
|
+
notes.push(
|
|
386
|
+
'customInjection will run in the verification client before ' +
|
|
387
|
+
'every page load (before navigating to initialUrl), matching ' +
|
|
388
|
+
'the builder\'s jsUserScripts.',
|
|
389
|
+
)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const REGISTER_IGNORED_KEYS = [
|
|
393
|
+
'allowedInjectedRequestData',
|
|
394
|
+
'useIncognitoWebview',
|
|
395
|
+
'extensionConfig',
|
|
396
|
+
] as const
|
|
397
|
+
const ignoredOnRegister = REGISTER_IGNORED_KEYS
|
|
398
|
+
.filter((k) => args[k] !== undefined)
|
|
399
|
+
if(ignoredOnRegister.length) {
|
|
400
|
+
notes.push(
|
|
401
|
+
`${ignoredOnRegister.join(', ')} ${
|
|
402
|
+
ignoredOnRegister.length > 1 ? 'are' : 'is'
|
|
403
|
+
} ignored on register (no providerId) — the old backend only ` +
|
|
404
|
+
'reads them when adding a version. Publish once to create ' +
|
|
405
|
+
'the provider, then call this again WITH the returned ' +
|
|
406
|
+
'providerId to set them.',
|
|
407
|
+
)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if(args.userAgent !== undefined) {
|
|
411
|
+
opts.userAgent = args.userAgent
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if(args.pageTitle !== undefined) {
|
|
415
|
+
opts.pageTitle = args.pageTitle
|
|
416
|
+
}
|
|
417
|
+
|
|
225
418
|
const body = providerToRegisterBody(providers, opts)
|
|
226
419
|
return withNotes(await client.registerProvider(body))
|
|
227
420
|
}
|
|
@@ -232,6 +425,56 @@ export function createVersionFromCaptureTool(
|
|
|
232
425
|
// workaround instead of a bare permission error.
|
|
233
426
|
const providerId = args.providerId
|
|
234
427
|
try {
|
|
428
|
+
// This backend has no partial-patch endpoint — a version always
|
|
429
|
+
// replaces the WHOLE providerConfig. Anything the caller didn't
|
|
430
|
+
// pass at all is carried forward from the currently-published
|
|
431
|
+
// version instead of going out blank. Pass an explicit empty
|
|
432
|
+
// value ("", [], false) to intentionally clear one.
|
|
433
|
+
const needsCurrent = PRESERVABLE_KEYS.some((k) => args[k] === undefined)
|
|
434
|
+
|| args.allowedInjectedRequestData === undefined
|
|
435
|
+
const current = needsCurrent
|
|
436
|
+
? extractProviderConfig(await client.getProviderConfig(providerId))
|
|
437
|
+
: undefined
|
|
438
|
+
|
|
439
|
+
const carried: string[] = []
|
|
440
|
+
for(const key of PRESERVABLE_KEYS) {
|
|
441
|
+
const resolved = resolveField(args[key], current?.[key], key, carried)
|
|
442
|
+
if(resolved !== undefined) {
|
|
443
|
+
(opts as unknown as Record<string, unknown>)[key] = resolved
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const freshInjected = args.allowedInjectedRequestData !== undefined
|
|
448
|
+
? injectedRequestDataFrom(args.allowedInjectedRequestData)
|
|
449
|
+
: undefined
|
|
450
|
+
const resolvedInjected = resolveField<OldInjectedRequestData[]>(
|
|
451
|
+
freshInjected,
|
|
452
|
+
current?.allowedInjectedRequestData,
|
|
453
|
+
'allowedInjectedRequestData',
|
|
454
|
+
carried,
|
|
455
|
+
)
|
|
456
|
+
if(resolvedInjected !== undefined) {
|
|
457
|
+
opts.allowedInjectedRequestData = resolvedInjected
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if(carried.length) {
|
|
461
|
+
notes.push(
|
|
462
|
+
'Not passed, carried forward unchanged from the current ' +
|
|
463
|
+
`published version: ${carried.join(', ')}. Pass an explicit ` +
|
|
464
|
+
'value ("", [], false, ...) to override any of them, or ' +
|
|
465
|
+
'call get_provider_version_config first to see what is ' +
|
|
466
|
+
'live today.',
|
|
467
|
+
)
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if(args.customInjection !== undefined && opts.customInjection?.trim()) {
|
|
471
|
+
notes.push(
|
|
472
|
+
'customInjection will run in the verification client before ' +
|
|
473
|
+
'every page load (before navigating to initialUrl), matching ' +
|
|
474
|
+
'the builder\'s jsUserScripts.',
|
|
475
|
+
)
|
|
476
|
+
}
|
|
477
|
+
|
|
235
478
|
const versionsResp = await client.listVersions(providerId)
|
|
236
479
|
const version = bumpPatchString(extractVersions(versionsResp))
|
|
237
480
|
const versionInfo =
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { defineTool, type RegisteredTool } from '../../mcp/server.ts'
|
|
2
|
+
import type { ReclaimOldClient, UpdateProviderMetadataBody } from '../client.ts'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Edit provider-level metadata on the old devtools backend
|
|
6
|
+
* (`POST /api/providers/:providerId`) — a genuine PARTIAL update on the
|
|
7
|
+
* PROVIDER document itself, distinct from both
|
|
8
|
+
* `create_provider_version_from_capture` paths: it does NOT touch
|
|
9
|
+
* `providerConfig`/versions at all, and only the fields you pass here
|
|
10
|
+
* change — everything else on the provider is left untouched (no need to
|
|
11
|
+
* re-supply `requestData`/`customInjection`/etc., and
|
|
12
|
+
* no new version is created).
|
|
13
|
+
*
|
|
14
|
+
* The backend 403s if you don't own the provider (and aren't an admin) —
|
|
15
|
+
* surfaced verbatim, same as any other auth failure from this client.
|
|
16
|
+
*/
|
|
17
|
+
export function updateProviderMetadataTool(
|
|
18
|
+
client: ReclaimOldClient,
|
|
19
|
+
): RegisteredTool {
|
|
20
|
+
return defineTool<UpdateProviderMetadataBody & { providerId: string }>(
|
|
21
|
+
{
|
|
22
|
+
name: 'update_provider_metadata',
|
|
23
|
+
description:
|
|
24
|
+
'Rename, redescribe, retag, flip providerType (PRIVATE/PUBLIC), or ' +
|
|
25
|
+
'toggle isActive on a provider YOU own — WITHOUT creating a new ' +
|
|
26
|
+
'version. Only the fields you pass change; everything else ' +
|
|
27
|
+
'(requestData, customInjection, versions, ...) is untouched. Pass ' +
|
|
28
|
+
'at least one of the optional fields. Get a `providerId` from ' +
|
|
29
|
+
'get_me_providers.',
|
|
30
|
+
inputSchema: {
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
providerId: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
description: 'UUID of the provider to update.',
|
|
36
|
+
},
|
|
37
|
+
name: { type: 'string', description: 'New provider name.' },
|
|
38
|
+
description: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
description: 'New provider description.',
|
|
41
|
+
},
|
|
42
|
+
providerType: {
|
|
43
|
+
type: 'string',
|
|
44
|
+
enum: ['PRIVATE', 'PUBLIC'],
|
|
45
|
+
description: 'Change PRIVATE/PUBLIC visibility.',
|
|
46
|
+
},
|
|
47
|
+
tags: {
|
|
48
|
+
type: 'array',
|
|
49
|
+
items: { type: 'string' },
|
|
50
|
+
description: 'Replace the provider\'s tag list.',
|
|
51
|
+
},
|
|
52
|
+
isActive: {
|
|
53
|
+
type: 'boolean',
|
|
54
|
+
description: 'Whether the provider is active.',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
required: ['providerId'],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
async({ providerId, ...body }) => {
|
|
61
|
+
const hasAnyField = Object.values(body).some((v) => v !== undefined)
|
|
62
|
+
if(!hasAnyField) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
'Pass at least one of: name, description, providerType, tags, ' +
|
|
65
|
+
'isActive.',
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return client.updateProviderMetadata(providerId, body)
|
|
70
|
+
},
|
|
71
|
+
)
|
|
72
|
+
}
|
package/src/proof/attestor.ts
CHANGED
|
@@ -10,9 +10,14 @@ import { bytesToHex } from '@noble/hashes/utils.js'
|
|
|
10
10
|
import {
|
|
11
11
|
createClaimOnAttestor, type Logger,
|
|
12
12
|
} from '@reclaimprotocol/attestor-core'
|
|
13
|
+
// Side-effect: make external domhandler nodes DOM-like so attestor-core's
|
|
14
|
+
// bundled `xpath` accepts them (see patch-domhandler.ts). Must load before any
|
|
15
|
+
// proof runs its response-redaction extraction.
|
|
16
|
+
import './patch-domhandler.ts'
|
|
13
17
|
import { agentTraceEnabled } from '../consts.ts'
|
|
14
18
|
import { resolveEthKey } from '../mcp/tools/authenticate/eth-key.ts'
|
|
15
19
|
import type { ReclaimProvider } from '../provider/schema.ts'
|
|
20
|
+
import { installResponseDump } from './debug-response-dump.ts'
|
|
16
21
|
import {
|
|
17
22
|
buildHttpParams, ensureAttestorCrypto, parseClaim, resolveAttestorUrl,
|
|
18
23
|
} from './proof-core.ts'
|
|
@@ -47,9 +52,11 @@ export interface RunAttestorProofOptions {
|
|
|
47
52
|
/** Sign with this key directly (e.g. the app/VC's ephemeral per-session key)
|
|
48
53
|
* instead of resolving from env/.env/file. */
|
|
49
54
|
ownerPrivateKey?: string
|
|
50
|
-
/** ZK engine for `createClaimOnAttestor`. Defaults to `'
|
|
51
|
-
*
|
|
52
|
-
|
|
55
|
+
/** ZK engine for `createClaimOnAttestor`. Defaults to `'stwo'` — a pure-WASM
|
|
56
|
+
* prover that runs everywhere (no native shared library, so it works on
|
|
57
|
+
* Windows where `'gnark'` fails to load its `.dll`). Server-side paths that
|
|
58
|
+
* want gnark's speed pin it explicitly (e.g. the verify runner). */
|
|
59
|
+
zkEngine?: 'gnark' | 'snarkjs' | 'stwo'
|
|
53
60
|
/** Extract the structured {@link AttestorClaim} (claim + attestor signature)
|
|
54
61
|
* onto the result for nested-proof construction. */
|
|
55
62
|
includeAttestorClaim?: boolean
|
|
@@ -249,6 +256,11 @@ export async function runAttestorProof(
|
|
|
249
256
|
const capture = traceEnabled ? makeCaptureLogger() : undefined
|
|
250
257
|
const attestorLogs = capture?.entries
|
|
251
258
|
|
|
259
|
+
// Debug (RECLAIM_AGENT_DUMP_RESPONSE): dump the exact response the
|
|
260
|
+
// attestor validates against, so "Response does not contain X" is
|
|
261
|
+
// diagnosable against the attestor's real server-side fetch.
|
|
262
|
+
installResponseDump()
|
|
263
|
+
|
|
252
264
|
let claim: unknown
|
|
253
265
|
try {
|
|
254
266
|
claim = await createClaimOnAttestor({
|
|
@@ -259,7 +271,7 @@ export async function runAttestorProof(
|
|
|
259
271
|
},
|
|
260
272
|
ownerPrivateKey,
|
|
261
273
|
client: { url: resolveAttestorUrl(opts.attestorUrl) },
|
|
262
|
-
zkEngine: opts.zkEngine ?? '
|
|
274
|
+
zkEngine: opts.zkEngine ?? 'stwo',
|
|
263
275
|
...(capture !== undefined && { logger: capture.logger as Logger }),
|
|
264
276
|
})
|
|
265
277
|
} catch(err) {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Debug helper (gated by RECLAIM_AGENT_DUMP_RESPONSE): capture the EXACT
|
|
2
|
+
// response bytes the attestor validates a claim against, plus a per-match
|
|
3
|
+
// presence check. A "Response does not contain X" failure means the attestor's
|
|
4
|
+
// server-side re-fetch differs from what the browser (replay) saw — e.g. GitHub
|
|
5
|
+
// embeds nav/userMenu data for browser requests but not for the attestor's raw
|
|
6
|
+
// fetch. Seeing the attestor's actual response is the only way to tell what it
|
|
7
|
+
// really returned.
|
|
8
|
+
//
|
|
9
|
+
// On each getResponseRedactions call it writes the response to
|
|
10
|
+
// `attestor-last-response.html` in the process CWD and logs the byte count +,
|
|
11
|
+
// for every responseMatch (paramValues substituted), whether it's present.
|
|
12
|
+
import { providers } from '@reclaimprotocol/attestor-core'
|
|
13
|
+
import { writeFileSync } from 'node:fs'
|
|
14
|
+
import { join } from 'node:path'
|
|
15
|
+
|
|
16
|
+
interface RedactionArg {
|
|
17
|
+
response: Uint8Array
|
|
18
|
+
params: {
|
|
19
|
+
responseMatches?: Array<{ value?: string }>
|
|
20
|
+
paramValues?: Record<string, string>
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let installed = false
|
|
25
|
+
|
|
26
|
+
/** Wrap attestor-core's http `getResponseRedactions` to dump the response it
|
|
27
|
+
* runs against. Idempotent; no-op unless RECLAIM_AGENT_DUMP_RESPONSE is
|
|
28
|
+
* set. */
|
|
29
|
+
export function installResponseDump(): void {
|
|
30
|
+
if(installed || !process.env['RECLAIM_AGENT_DUMP_RESPONSE']) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const http = providers['http'] as unknown as {
|
|
35
|
+
getResponseRedactions?: (arg: RedactionArg) => unknown
|
|
36
|
+
}
|
|
37
|
+
const original = http.getResponseRedactions
|
|
38
|
+
if(typeof original !== 'function') {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
installed = true
|
|
43
|
+
http.getResponseRedactions = function(this: unknown, arg: RedactionArg) {
|
|
44
|
+
try {
|
|
45
|
+
const bytes = Buffer.from(arg.response)
|
|
46
|
+
const text = bytes.toString('utf8')
|
|
47
|
+
const paramValues = arg.params.paramValues ?? {}
|
|
48
|
+
const matches = (arg.params.responseMatches ?? []).map((m) => {
|
|
49
|
+
let value = m.value ?? ''
|
|
50
|
+
for(const [key, val] of Object.entries(paramValues)) {
|
|
51
|
+
value = value.split(`{{${key}}}`).join(val)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { value, present: text.includes(value) }
|
|
55
|
+
})
|
|
56
|
+
const path = join(process.cwd(), 'attestor-last-response.html')
|
|
57
|
+
writeFileSync(path, text)
|
|
58
|
+
process.stderr.write(`${JSON.stringify({
|
|
59
|
+
tag: 'attestor-response-dump',
|
|
60
|
+
bytes: bytes.length,
|
|
61
|
+
path,
|
|
62
|
+
matches,
|
|
63
|
+
})}\n`)
|
|
64
|
+
} catch{
|
|
65
|
+
// diagnostic only — never break proving
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return original.call(this, arg)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Side-effect module: make `domhandler` nodes DOM-like for the `xpath` engine.
|
|
2
|
+
//
|
|
3
|
+
// WHY THIS EXISTS
|
|
4
|
+
// `@reclaimprotocol/attestor-core`'s published `lib` bundles its own inlined
|
|
5
|
+
// copy of `domhandler` and applies a DOM-compat patch (nodeName / localName +
|
|
6
|
+
// a NamedNodeMap `item()` shim) to THAT copy. But at proof time the HTML tree
|
|
7
|
+
// is built by the *external* `parse5-htmlparser2-tree-adapter`, which uses the
|
|
8
|
+
// separately-installed `domhandler` — a different, UNPATCHED copy. The `xpath`
|
|
9
|
+
// engine then fails `isNodeLike()` on every node (it needs a string `nodeName`)
|
|
10
|
+
// and throws "Context node does not appear to be a valid DOM node", so ALL
|
|
11
|
+
// xPath / xPath+jsonPath response redactions fail during `runAttestorProof`'s
|
|
12
|
+
// receipt validation. (Regex-only redactions escape it — they never touch the
|
|
13
|
+
// parse5/xpath path.) Running attestor-core from source works because there is
|
|
14
|
+
// then a single shared `domhandler`; the bug is only in the bundled `lib`.
|
|
15
|
+
//
|
|
16
|
+
// Rather than fork attestor-core, apply the identical patch to the external
|
|
17
|
+
// `domhandler` the adapter actually uses, so its tree nodes are DOM-like. This
|
|
18
|
+
// mirrors attestor-core's own `patch-parse5-tree`. Idempotent and
|
|
19
|
+
// version-agnostic. Import it before any proving path runs.
|
|
20
|
+
//
|
|
21
|
+
// Remove once attestor-core externalizes `domhandler` in its build (one shared
|
|
22
|
+
// copy → its own patch suffices).
|
|
23
|
+
import { Element, Node } from 'domhandler'
|
|
24
|
+
|
|
25
|
+
const PATCH_FLAG = Symbol.for('reclaim.domhandler.domCompatPatched')
|
|
26
|
+
const proto = Node.prototype as unknown as Record<PropertyKey, unknown>
|
|
27
|
+
|
|
28
|
+
if(!proto[PATCH_FLAG]) {
|
|
29
|
+
// `xpath`'s isNodeLike() requires a string `nodeName`; domhandler nodes carry
|
|
30
|
+
// the tag under `.name`.
|
|
31
|
+
Object.defineProperty(Node.prototype, 'nodeName', {
|
|
32
|
+
configurable: true,
|
|
33
|
+
get(this: { name?: string }) {
|
|
34
|
+
return this.name
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
Object.defineProperty(Node.prototype, 'localName', {
|
|
38
|
+
configurable: true,
|
|
39
|
+
get(this: { name?: string }) {
|
|
40
|
+
return this.name
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// Attribute-predicate steps (`[@id=…]`, `contains(@class,…)`) walk the
|
|
45
|
+
// NamedNodeMap via `.item(i)`; give each returned attribute node the DOM
|
|
46
|
+
// shape `xpath` expects (nodeType 2 + localName).
|
|
47
|
+
const attrsGetter =
|
|
48
|
+
Object.getOwnPropertyDescriptor(Element.prototype, 'attributes')?.get
|
|
49
|
+
if(attrsGetter) {
|
|
50
|
+
Object.defineProperty(Element.prototype, 'attributes', {
|
|
51
|
+
configurable: true,
|
|
52
|
+
get(this: unknown) {
|
|
53
|
+
const attrs = attrsGetter.call(this) as
|
|
54
|
+
(Record<number, { name: string }> & {
|
|
55
|
+
item?: (i: number) => unknown
|
|
56
|
+
})
|
|
57
|
+
attrs.item = (i: number) => {
|
|
58
|
+
const attr = attrs[i]
|
|
59
|
+
return { ...attr, nodeType: 2, localName: attr.name }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return attrs
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
proto[PATCH_FLAG] = true
|
|
68
|
+
}
|
package/src/proof/proof-core.ts
CHANGED
|
@@ -38,7 +38,7 @@ export function resolveAttestorUrl(override?: string): string {
|
|
|
38
38
|
)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
/** Map a
|
|
41
|
+
/** Map a provider's recipe straight to the attestor's HTTP
|
|
42
42
|
* params — never synthesized from captured traffic. */
|
|
43
43
|
export function buildHttpParams(
|
|
44
44
|
provider: ReclaimProvider,
|
package/src/proof/zk-files.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Lazy download of the @reclaimprotocol/zk-symmetric-crypto circuit resources
|
|
2
|
-
//
|
|
3
|
-
//
|
|
2
|
+
// the proof engines need (the downloader fetches every engine — stwo, snarkjs,
|
|
3
|
+
// gnark — as one bundle). These are ~280MB and are NOT fetched in a
|
|
4
|
+
// `postinstall` (that blocked the MCP server's first launch past the connect
|
|
4
5
|
// timeout — see the install notes). Instead we fetch them on the first proof,
|
|
5
6
|
// once, so the server starts immediately and only `run_proof` pays the cost.
|
|
6
7
|
|
|
@@ -43,12 +44,12 @@ async function download(): Promise<void> {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
// mainPath is <pkg>/lib/index.js → resources live at <pkg>/resources, the
|
|
46
|
-
// downloader at <pkg>/lib/scripts/download-files.js.
|
|
47
|
-
//
|
|
48
|
-
//
|
|
47
|
+
// downloader at <pkg>/lib/scripts/download-files.js. Proofs default to the
|
|
48
|
+
// stwo (WASM) engine, so its resource dir being present is the signal that
|
|
49
|
+
// the circuits are ready (the downloader fetches all engines together).
|
|
49
50
|
const libDir = dirname(mainPath)
|
|
50
51
|
const pkgDir = dirname(libDir)
|
|
51
|
-
if(existsSync(join(pkgDir, 'resources', '
|
|
52
|
+
if(existsSync(join(pkgDir, 'resources', 'stwo'))) {
|
|
52
53
|
return
|
|
53
54
|
}
|
|
54
55
|
|