@reclaimprotocol/agent 0.1.0-dev.1

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 (191) hide show
  1. package/README.md +287 -0
  2. package/lib/cdp/capture.d.ts +22 -0
  3. package/lib/cdp/capture.js +159 -0
  4. package/lib/cdp/client.d.ts +9 -0
  5. package/lib/cdp/client.js +11 -0
  6. package/lib/cdp/eviction.d.ts +16 -0
  7. package/lib/cdp/eviction.js +38 -0
  8. package/lib/cdp/launcher.d.ts +14 -0
  9. package/lib/cdp/launcher.js +102 -0
  10. package/lib/cdp/tabs.d.ts +6 -0
  11. package/lib/cdp/tabs.js +10 -0
  12. package/lib/cli/args.d.ts +14 -0
  13. package/lib/cli/args.js +19 -0
  14. package/lib/cli/commands.d.ts +1 -0
  15. package/lib/cli/commands.js +19 -0
  16. package/lib/cli.d.ts +1 -0
  17. package/lib/cli.js +7 -0
  18. package/lib/config/store.d.ts +45 -0
  19. package/lib/config/store.js +46 -0
  20. package/lib/index.d.ts +3 -0
  21. package/lib/index.js +7 -0
  22. package/lib/logger.d.ts +2 -0
  23. package/lib/logger.js +7 -0
  24. package/lib/mcp/api/operations.gen.d.ts +152 -0
  25. package/lib/mcp/api/operations.gen.js +2300 -0
  26. package/lib/mcp/api/tools.d.ts +3 -0
  27. package/lib/mcp/api/tools.js +36 -0
  28. package/lib/mcp/remap_errors.d.ts +2 -0
  29. package/lib/mcp/remap_errors.js +27 -0
  30. package/lib/mcp/server.d.ts +38 -0
  31. package/lib/mcp/server.js +76 -0
  32. package/lib/mcp/start.d.ts +1 -0
  33. package/lib/mcp/start.js +63 -0
  34. package/lib/mcp/tools/agent/analyze.d.ts +3 -0
  35. package/lib/mcp/tools/agent/analyze.js +26 -0
  36. package/lib/mcp/tools/agent/attach.d.ts +11 -0
  37. package/lib/mcp/tools/agent/attach.js +72 -0
  38. package/lib/mcp/tools/agent/build.d.ts +33 -0
  39. package/lib/mcp/tools/agent/build.js +74 -0
  40. package/lib/mcp/tools/agent/capture.d.ts +10 -0
  41. package/lib/mcp/tools/agent/capture.js +142 -0
  42. package/lib/mcp/tools/agent/eval.d.ts +5 -0
  43. package/lib/mcp/tools/agent/eval.js +127 -0
  44. package/lib/mcp/tools/agent/find.d.ts +3 -0
  45. package/lib/mcp/tools/agent/find.js +60 -0
  46. package/lib/mcp/tools/agent/proof.d.ts +3 -0
  47. package/lib/mcp/tools/agent/proof.js +214 -0
  48. package/lib/mcp/tools/agent/propose.d.ts +9 -0
  49. package/lib/mcp/tools/agent/propose.js +75 -0
  50. package/lib/mcp/tools/agent/publish.d.ts +3 -0
  51. package/lib/mcp/tools/agent/publish.js +122 -0
  52. package/lib/mcp/tools/agent/replay.d.ts +3 -0
  53. package/lib/mcp/tools/agent/replay.js +46 -0
  54. package/lib/mcp/tools/agent/session.d.ts +10 -0
  55. package/lib/mcp/tools/agent/session.js +29 -0
  56. package/lib/mcp/tools/credentials/authenticate.d.ts +3 -0
  57. package/lib/mcp/tools/credentials/authenticate.js +108 -0
  58. package/lib/mcp/tools/credentials/build.d.ts +16 -0
  59. package/lib/mcp/tools/credentials/build.js +33 -0
  60. package/lib/mcp/tools/credentials/cache.d.ts +70 -0
  61. package/lib/mcp/tools/credentials/cache.js +114 -0
  62. package/lib/mcp/tools/credentials/env-file.d.ts +25 -0
  63. package/lib/mcp/tools/credentials/env-file.js +71 -0
  64. package/lib/mcp/tools/credentials/import.d.ts +2 -0
  65. package/lib/mcp/tools/credentials/import.js +52 -0
  66. package/lib/mcp/tools/credentials/issue.d.ts +2 -0
  67. package/lib/mcp/tools/credentials/issue.js +84 -0
  68. package/lib/mcp/tools/credentials/list-cached.d.ts +2 -0
  69. package/lib/mcp/tools/credentials/list-cached.js +55 -0
  70. package/lib/mcp/tools/credentials/register.d.ts +18 -0
  71. package/lib/mcp/tools/credentials/register.js +30 -0
  72. package/lib/mcp/tools/credentials/resolve-owner-key.d.ts +12 -0
  73. package/lib/mcp/tools/credentials/resolve-owner-key.js +68 -0
  74. package/lib/mcp/tools/credentials/session-cache.d.ts +14 -0
  75. package/lib/mcp/tools/credentials/session-cache.js +19 -0
  76. package/lib/mcp/tools/credentials/status.d.ts +3 -0
  77. package/lib/mcp/tools/credentials/status.js +62 -0
  78. package/lib/mcp-bin.d.ts +1 -0
  79. package/lib/mcp-bin.js +7 -0
  80. package/lib/old/client.d.ts +67 -0
  81. package/lib/old/client.js +146 -0
  82. package/lib/old/flag.d.ts +11 -0
  83. package/lib/old/flag.js +13 -0
  84. package/lib/old/identity.d.ts +22 -0
  85. package/lib/old/identity.js +47 -0
  86. package/lib/old/instructions.d.ts +7 -0
  87. package/lib/old/instructions.js +29 -0
  88. package/lib/old/login-cdp.d.ts +23 -0
  89. package/lib/old/login-cdp.js +125 -0
  90. package/lib/old/to-register.d.ts +47 -0
  91. package/lib/old/to-register.js +133 -0
  92. package/lib/old/tools/authenticate.d.ts +18 -0
  93. package/lib/old/tools/authenticate.js +127 -0
  94. package/lib/old/tools/build.d.ts +9 -0
  95. package/lib/old/tools/build.js +16 -0
  96. package/lib/old/tools/me-providers.d.ts +10 -0
  97. package/lib/old/tools/me-providers.js +32 -0
  98. package/lib/old/tools/publish.d.ts +16 -0
  99. package/lib/old/tools/publish.js +97 -0
  100. package/lib/paths.d.ts +11 -0
  101. package/lib/paths.js +32 -0
  102. package/lib/pkg.d.ts +3 -0
  103. package/lib/pkg.js +13 -0
  104. package/lib/proof/attestor.d.ts +39 -0
  105. package/lib/proof/attestor.js +207 -0
  106. package/lib/proof/replay.d.ts +8 -0
  107. package/lib/proof/replay.js +73 -0
  108. package/lib/provider/constraints.d.ts +2 -0
  109. package/lib/provider/constraints.js +122 -0
  110. package/lib/provider/draft.d.ts +6 -0
  111. package/lib/provider/draft.js +68 -0
  112. package/lib/provider/graphql.d.ts +2 -0
  113. package/lib/provider/graphql.js +35 -0
  114. package/lib/provider/matcher.d.ts +36 -0
  115. package/lib/provider/matcher.js +436 -0
  116. package/lib/provider/normalize.d.ts +4 -0
  117. package/lib/provider/normalize.js +51 -0
  118. package/lib/provider/schema.d.ts +76 -0
  119. package/lib/provider/schema.js +1 -0
  120. package/lib/provider/secrets.d.ts +5 -0
  121. package/lib/provider/secrets.js +22 -0
  122. package/lib/provider/to-version.d.ts +22 -0
  123. package/lib/provider/to-version.js +68 -0
  124. package/lib/types/openapi.d.ts +4 -0
  125. package/lib/types/openapi.js +1 -0
  126. package/package.json +88 -0
  127. package/scripts/download-zk-files.ts +42 -0
  128. package/scripts/prepend-shebang.ts +17 -0
  129. package/skill/SKILL.md +248 -0
  130. package/src/cdp/capture.ts +215 -0
  131. package/src/cdp/client.ts +20 -0
  132. package/src/cdp/eviction.ts +52 -0
  133. package/src/cdp/launcher.ts +133 -0
  134. package/src/cdp/tabs.ts +22 -0
  135. package/src/cli/args.ts +20 -0
  136. package/src/cli/commands.ts +27 -0
  137. package/src/cli.ts +7 -0
  138. package/src/config/store.ts +86 -0
  139. package/src/index.ts +12 -0
  140. package/src/logger.ts +8 -0
  141. package/src/mcp/api/operations.gen.ts +2397 -0
  142. package/src/mcp/api/tools.ts +45 -0
  143. package/src/mcp/remap_errors.ts +35 -0
  144. package/src/mcp/server.ts +119 -0
  145. package/src/mcp/start.ts +78 -0
  146. package/src/mcp/tools/agent/analyze.ts +34 -0
  147. package/src/mcp/tools/agent/attach.ts +95 -0
  148. package/src/mcp/tools/agent/build.ts +99 -0
  149. package/src/mcp/tools/agent/capture.ts +202 -0
  150. package/src/mcp/tools/agent/eval.ts +161 -0
  151. package/src/mcp/tools/agent/find.ts +73 -0
  152. package/src/mcp/tools/agent/proof.ts +272 -0
  153. package/src/mcp/tools/agent/propose.ts +111 -0
  154. package/src/mcp/tools/agent/publish.ts +155 -0
  155. package/src/mcp/tools/agent/replay.ts +58 -0
  156. package/src/mcp/tools/agent/session.ts +46 -0
  157. package/src/mcp/tools/credentials/authenticate.ts +135 -0
  158. package/src/mcp/tools/credentials/build.ts +37 -0
  159. package/src/mcp/tools/credentials/cache.ts +161 -0
  160. package/src/mcp/tools/credentials/env-file.ts +101 -0
  161. package/src/mcp/tools/credentials/import.ts +72 -0
  162. package/src/mcp/tools/credentials/issue.ts +107 -0
  163. package/src/mcp/tools/credentials/list-cached.ts +66 -0
  164. package/src/mcp/tools/credentials/register.ts +49 -0
  165. package/src/mcp/tools/credentials/resolve-owner-key.ts +78 -0
  166. package/src/mcp/tools/credentials/session-cache.ts +31 -0
  167. package/src/mcp/tools/credentials/status.ts +82 -0
  168. package/src/mcp-bin.ts +7 -0
  169. package/src/old/client.ts +236 -0
  170. package/src/old/flag.ts +13 -0
  171. package/src/old/identity.ts +56 -0
  172. package/src/old/instructions.ts +30 -0
  173. package/src/old/login-cdp.ts +153 -0
  174. package/src/old/to-register.ts +234 -0
  175. package/src/old/tools/authenticate.ts +152 -0
  176. package/src/old/tools/build.ts +21 -0
  177. package/src/old/tools/me-providers.ts +42 -0
  178. package/src/old/tools/publish.ts +135 -0
  179. package/src/paths.ts +37 -0
  180. package/src/pkg.ts +24 -0
  181. package/src/proof/attestor.ts +286 -0
  182. package/src/proof/replay.ts +102 -0
  183. package/src/provider/constraints.ts +150 -0
  184. package/src/provider/draft.ts +105 -0
  185. package/src/provider/graphql.ts +42 -0
  186. package/src/provider/matcher.ts +616 -0
  187. package/src/provider/normalize.ts +65 -0
  188. package/src/provider/schema.ts +92 -0
  189. package/src/provider/secrets.ts +29 -0
  190. package/src/provider/to-version.ts +90 -0
  191. package/src/types/openapi.ts +7 -0
@@ -0,0 +1,92 @@
1
+ import type { ProviderParams } from '@reclaimprotocol/attestor-core'
2
+
3
+ /** The attestor's HTTP provider parameters — the canonical source for the
4
+ * request/match/redaction shapes we draft. */
5
+ type HttpParams = ProviderParams<'http'>
6
+
7
+ /** HTTP methods the attestor accepts. */
8
+ export type HttpMethod = HttpParams['method']
9
+
10
+ /**
11
+ * A pattern the attestor checks against the revealed slice of the response.
12
+ * The prover selectively reveals portions of the TLS response (via
13
+ * responseRedactions), so the attestor only ever sees a substring —
14
+ * jsonPath/xPath belong on the redaction, not here.
15
+ */
16
+ export type ResponseMatch = HttpParams['responseMatches'][number]
17
+
18
+ /**
19
+ * Selector telling the prover which portion of the response to reveal:
20
+ * `xPath`/`jsonPath` narrows the slice, `regex` (with named groups) matches
21
+ * within, and `hash` applies an OPRF so the attestor sees a nullifier
22
+ * instead of the cleartext value.
23
+ */
24
+ export type ResponseRedaction =
25
+ NonNullable<HttpParams['responseRedactions']>[number]
26
+
27
+ /**
28
+ * OPRF mode for hashed redactions. `oprf-raw` is what the dev-loop defaults
29
+ * to when privacy is requested — the only variant that runs without external
30
+ * deps (gnark for `oprf`, a TEE for `oprf-mpc`). It is the weakest of the
31
+ * three (the attestor participates in hashing) and is meant to be swapped
32
+ * out before production.
33
+ */
34
+ export type OprfMode = NonNullable<ResponseRedaction['hash']>
35
+
36
+ /** A single captured request + response, as we store it server-side. */
37
+ export interface CapturedRequest {
38
+ requestId: string
39
+ method: string
40
+ url: string
41
+ status: number
42
+ contentType: string
43
+ size: number
44
+ requestHeaders: Record<string, string>
45
+ requestBody?: string
46
+ responseHeaders: Record<string, string>
47
+ responseBody?: string
48
+ /** Parsed GraphQL operationName if request body is a GraphQL query. */
49
+ graphqlOp?: string
50
+ /** ms since epoch when the response finished. */
51
+ finishedAt: number
52
+ }
53
+
54
+ /**
55
+ * Reclaim provider JSON shape we draft, then translate to the attestor's HTTP
56
+ * params (proof/attestor.ts) and the API version request (to-version.ts). The
57
+ * request fields derive from the attestor's own `HttpProviderParameters`, so
58
+ * the method enum and match/redaction shapes can't drift from what the
59
+ * attestor accepts. `body` is narrowed to `string` (the SDK also allows
60
+ * `Uint8Array`, but we only ever template text bodies).
61
+ */
62
+ export interface ReclaimProvider {
63
+ name: string
64
+ url: string
65
+ method: HttpMethod
66
+ headers?: Record<string, string>
67
+ body?: string
68
+ responseMatches: ResponseMatch[]
69
+ responseRedactions?: ResponseRedaction[]
70
+ /** Public param refs (templated into URL/body), populated by draft layer. */
71
+ paramValues?: Record<string, string>
72
+ }
73
+
74
+ /** A reference to a secret param. Raw value lives only in server memory. */
75
+ export interface SecretParamRef {
76
+ name: string
77
+ source: 'header' | 'cookie' | 'query'
78
+ redacted: true
79
+ }
80
+
81
+ /** Concerns flagged about a captured request. Informational, never blocking. */
82
+ export interface RequestConcern {
83
+ code:
84
+ | 'signedRequest'
85
+ | 'wasmSigned'
86
+ | 'botChallenge'
87
+ | 'csrfDependency'
88
+ | 'shortLivedToken'
89
+ | 'encryptedBody'
90
+ | 'graphql'
91
+ message: string
92
+ }
@@ -0,0 +1,29 @@
1
+ const SECRET_EXACT = new Set(['cookie', 'authorization', 'proxy-authorization'])
2
+
3
+ const SECRET_SUFFIXES = ['-token', '-key', '-secret', '-auth']
4
+
5
+ export function classifyHeader(name: string): boolean {
6
+ const lower = name.toLowerCase()
7
+ if(SECRET_EXACT.has(lower)) {
8
+ return true
9
+ }
10
+
11
+ return SECRET_SUFFIXES.some((s) => lower.endsWith(s))
12
+ }
13
+
14
+ export function splitSecrets(headers: Record<string, string>): {
15
+ secrets: Record<string, string>
16
+ publics: Record<string, string>
17
+ } {
18
+ const secrets: Record<string, string> = {}
19
+ const publics: Record<string, string> = {}
20
+ for(const [k, v] of Object.entries(headers)) {
21
+ if(classifyHeader(k)) {
22
+ secrets[k] = v
23
+ } else {
24
+ publics[k] = v
25
+ }
26
+ }
27
+
28
+ return { secrets, publics }
29
+ }
@@ -0,0 +1,90 @@
1
+ import type { ReclaimClient } from '@reclaimprotocol/client'
2
+ import type {
3
+ CreateProviderVersionRequest as CreateVersionBody,
4
+ ProviderVersionRef as VersionRef,
5
+ } from '../types/openapi.ts'
6
+ import type { ReclaimProvider } from './schema.ts'
7
+
8
+ /**
9
+ * Translate a drafted ReclaimProvider into the body for
10
+ * POST /providers/{providerId}/versions.
11
+ *
12
+ * `initialUrl` is the landing page the user navigated to during
13
+ * capture — distinct from `provider.url` which is the specific
14
+ * API URL the attestor replays.
15
+ *
16
+ * Secrets are NOT persisted — the verification client re-supplies
17
+ * them at runtime via `credentials: 'include'`.
18
+ */
19
+ export function providerToCreateVersionRequest(
20
+ provider: ReclaimProvider,
21
+ initialUrl: string,
22
+ notes?: string,
23
+ version?: VersionRef,
24
+ ): CreateVersionBody {
25
+ // Inline responseRedactions into matches[*].extract (1-to-1 by index).
26
+ const matches = (provider.responseMatches ?? []).map((match, i) => {
27
+ const redaction = provider.responseRedactions?.[i]
28
+ return {
29
+ type: match.type,
30
+ value: match.value,
31
+ isOptional: false,
32
+ ...(redaction ? { extract: redaction } : {}),
33
+ }
34
+ })
35
+
36
+ return {
37
+ version: version ?? { major: 1, minor: 0, patch: 0 },
38
+ initialUrl,
39
+ requests: [
40
+ {
41
+ url: provider.url,
42
+ method: provider.method,
43
+ credentials: 'include',
44
+ ...(provider.body ? { requestBodyTemplate: provider.body } : {}),
45
+ ...(matches.length > 0 ? { matches } : {}),
46
+ },
47
+ ],
48
+ allowedJsRequests: [],
49
+ webSettings: { geoLocation: '{{DYNAMIC_GEO}}' },
50
+ ...(provider.paramValues
51
+ ? { requiredParameters: provider.paramValues }
52
+ : {}),
53
+ ...(notes ? { notes } : {}),
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Fetch the current versions for a provider and return the next version above
59
+ * the highest existing one (bumping the patch number), or 1.0.0 when the
60
+ * provider has no versions yet. A failed lookup propagates — silently
61
+ * resetting to 1.0.0 would re-publish a v3 provider as v1.0.0.
62
+ */
63
+ export async function nextVersion(
64
+ client: ReclaimClient,
65
+ providerId: string,
66
+ ): Promise<VersionRef> {
67
+ const list = (await client.call('ListProviderVersions', {
68
+ params: { providerId },
69
+ query: {},
70
+ })) as { items?: Array<{ version: VersionRef }> }
71
+
72
+ if(!list.items?.length) {
73
+ return { major: 1, minor: 0, patch: 0 }
74
+ }
75
+
76
+ // Find the highest version and bump its patch
77
+ let hi = list.items[0].version
78
+ for(const item of list.items) {
79
+ const v = item.version
80
+ if(
81
+ v.major > hi.major ||
82
+ (v.major === hi.major && v.minor > hi.minor) ||
83
+ (v.major === hi.major && v.minor === hi.minor && v.patch > hi.patch)
84
+ ) {
85
+ hi = v
86
+ }
87
+ }
88
+
89
+ return { major: hi.major, minor: hi.minor, patch: hi.patch + 1 }
90
+ }
@@ -0,0 +1,7 @@
1
+ import type { components } from '@reclaimprotocol/client'
2
+
3
+ export type CredentialAttachSession =
4
+ components['schemas']['CredentialAttachSession']
5
+ export type CreateProviderVersionRequest =
6
+ components['schemas']['CreateProviderVersionRequest']
7
+ export type ProviderVersionRef = components['schemas']['ProviderVersionRef']