@reclaimprotocol/agent 0.1.1-dev.1 → 0.1.2
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 +1 -1
- package/lib/cdp/capture-engine.d.ts +66 -0
- package/lib/cdp/capture-engine.js +153 -0
- package/lib/cdp/capture.d.ts +9 -20
- package/lib/cdp/capture.js +14 -138
- package/lib/cdp/index.d.ts +3 -0
- package/lib/cdp/index.js +6 -0
- package/lib/cdp/launcher.js +4 -3
- package/lib/config/store.d.ts +7 -6
- package/lib/config/store.js +2 -2
- package/lib/consts.d.ts +68 -0
- package/lib/consts.js +134 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +1 -1
- package/lib/logger.js +2 -1
- package/lib/mcp/api/operations.gen.d.ts +100 -48
- package/lib/mcp/api/operations.gen.js +1129 -194
- package/lib/mcp/api/to-zod.d.ts +24 -0
- package/lib/mcp/api/to-zod.js +94 -0
- package/lib/mcp/api/tools.js +1 -1
- package/lib/mcp/credentials/authenticate.d.ts +3 -0
- package/lib/mcp/{tools/credentials → credentials}/authenticate.js +3 -3
- package/lib/mcp/credentials/build.d.ts +5 -0
- package/lib/mcp/credentials/build.js +18 -0
- package/lib/mcp/{tools/credentials → credentials}/cache.d.ts +9 -9
- package/lib/mcp/{tools/credentials → credentials}/cache.js +36 -19
- package/lib/mcp/credentials/import.d.ts +2 -0
- package/lib/mcp/{tools/credentials → credentials}/import.js +2 -2
- package/lib/mcp/credentials/issue.d.ts +2 -0
- package/lib/mcp/{tools/credentials → credentials}/issue.js +4 -4
- package/lib/mcp/credentials/keypair.d.ts +17 -0
- package/lib/mcp/credentials/keypair.js +48 -0
- package/lib/mcp/credentials/link.d.ts +3 -0
- package/lib/mcp/credentials/link.js +107 -0
- package/lib/mcp/{tools/credentials → credentials}/list-cached.d.ts +1 -1
- package/lib/mcp/{tools/credentials → credentials}/list-cached.js +5 -5
- package/lib/mcp/credentials/owner-key.d.ts +23 -0
- package/lib/mcp/credentials/owner-key.js +58 -0
- package/lib/mcp/credentials/paths.d.ts +12 -0
- package/lib/mcp/credentials/paths.js +35 -0
- package/lib/mcp/credentials/poll.d.ts +27 -0
- package/lib/mcp/credentials/poll.js +61 -0
- package/lib/mcp/{tools/credentials → credentials}/resolve-owner-key.d.ts +1 -1
- package/lib/mcp/{tools/credentials → credentials}/resolve-owner-key.js +2 -2
- package/lib/mcp/credentials/session-cache.d.ts +14 -0
- package/lib/mcp/credentials/session-cache.js +42 -0
- package/lib/mcp/{tools/credentials → credentials}/status.d.ts +1 -1
- package/lib/mcp/credentials/status.js +76 -0
- package/lib/mcp/instructions.d.ts +1 -0
- package/lib/mcp/instructions.js +11 -0
- package/lib/mcp/register.d.ts +38 -0
- package/lib/mcp/register.js +80 -0
- package/lib/mcp/server.d.ts +2 -8
- package/lib/mcp/server.js +3 -33
- package/lib/mcp/start.js +17 -11
- package/lib/mcp/tools/agent/build.d.ts +5 -9
- package/lib/mcp/tools/agent/build.js +7 -24
- package/lib/mcp/tools/agent/index.d.ts +2 -0
- package/lib/mcp/tools/agent/index.js +3 -0
- package/lib/mcp/tools/agent/proof.js +3 -7
- package/lib/mcp/tools/agent/propose.js +13 -2
- package/lib/mcp/tools/agent/publish.js +172 -75
- package/lib/mcp/tools/agent/replay.js +0 -5
- package/lib/mcp/tools/analyze.d.ts +3 -0
- package/lib/mcp/tools/analyze.js +26 -0
- package/lib/mcp/tools/attach.d.ts +11 -0
- package/lib/mcp/tools/attach.js +72 -0
- package/lib/mcp/tools/authenticate/authenticate.js +107 -0
- package/lib/mcp/tools/authenticate/build.d.ts +15 -0
- package/lib/mcp/tools/authenticate/build.js +28 -0
- package/lib/mcp/tools/authenticate/decrypt-key.d.ts +19 -0
- package/lib/mcp/tools/authenticate/decrypt-key.js +46 -0
- package/lib/mcp/tools/authenticate/eth-key.d.ts +31 -0
- package/lib/mcp/tools/authenticate/eth-key.js +116 -0
- package/lib/mcp/tools/authenticate/import.js +57 -0
- package/lib/mcp/tools/authenticate/index.d.ts +2 -0
- package/lib/mcp/tools/authenticate/index.js +4 -0
- package/lib/mcp/tools/authenticate/issue.js +42 -0
- package/lib/mcp/tools/authenticate/resolve-owner-key.d.ts +13 -0
- package/lib/mcp/tools/authenticate/resolve-owner-key.js +53 -0
- package/lib/mcp/tools/capture.d.ts +10 -0
- package/lib/mcp/tools/capture.js +142 -0
- package/lib/mcp/tools/eval.d.ts +5 -0
- package/lib/mcp/tools/eval.js +127 -0
- package/lib/mcp/tools/find.d.ts +3 -0
- package/lib/mcp/tools/find.js +60 -0
- package/lib/mcp/tools/index.d.ts +3 -0
- package/lib/mcp/tools/index.js +6 -0
- package/lib/mcp/tools/owner-key.d.ts +2 -0
- package/lib/mcp/tools/owner-key.js +63 -0
- package/lib/mcp/tools/proof.d.ts +3 -0
- package/lib/mcp/tools/proof.js +214 -0
- package/lib/mcp/tools/propose.d.ts +9 -0
- package/lib/mcp/tools/propose.js +75 -0
- package/lib/mcp/tools/publish.d.ts +3 -0
- package/lib/mcp/tools/publish.js +59 -0
- package/lib/mcp/tools/replay.d.ts +3 -0
- package/lib/mcp/tools/replay.js +46 -0
- package/lib/mcp/tools/session.d.ts +10 -0
- package/lib/mcp/tools/session.js +29 -0
- package/lib/mcp/tools/verification/build.d.ts +12 -0
- package/lib/mcp/tools/verification/build.js +14 -0
- package/lib/mcp/tools/verification/diagnose.d.ts +11 -0
- package/lib/mcp/tools/verification/diagnose.js +132 -0
- package/lib/mcp/tools/verification/index.d.ts +1 -0
- package/lib/mcp/tools/verification/index.js +2 -0
- package/lib/mcp/tools/verification/result.d.ts +11 -0
- package/lib/mcp/tools/verification/result.js +126 -0
- package/lib/mcp/verifications/build.d.ts +5 -0
- package/lib/mcp/verifications/build.js +14 -0
- package/lib/mcp/verifications/create.d.ts +3 -0
- package/lib/mcp/verifications/create.js +57 -0
- package/lib/mcp/verifications/find.d.ts +3 -0
- package/lib/mcp/verifications/find.js +37 -0
- package/lib/mcp/verifications/get.d.ts +3 -0
- package/lib/mcp/verifications/get.js +26 -0
- package/lib/mcp/verifications/update.d.ts +3 -0
- package/lib/mcp/verifications/update.js +78 -0
- package/lib/old/client.d.ts +3 -0
- package/lib/old/flag.d.ts +4 -1
- package/lib/old/flag.js +4 -3
- package/lib/old/identity.d.ts +0 -10
- package/lib/old/identity.js +8 -7
- package/lib/old/instructions.d.ts +0 -6
- package/lib/old/instructions.js +6 -24
- package/lib/old/login-cdp.d.ts +0 -3
- package/lib/old/login-cdp.js +2 -4
- package/lib/old/to-register.d.ts +3 -0
- package/lib/old/to-register.js +32 -7
- package/lib/old/tools/authenticate.js +2 -1
- package/lib/old/tools/publish.js +71 -10
- package/lib/paths.js +2 -2
- package/lib/proof/attestor.d.ts +33 -1
- package/lib/proof/attestor.js +67 -64
- package/lib/proof/index.d.ts +5 -0
- package/lib/proof/index.js +6 -0
- package/lib/proof/proof-core.d.ts +35 -0
- package/lib/proof/proof-core.js +84 -0
- package/lib/provider/index.d.ts +5 -0
- package/lib/provider/index.js +9 -0
- package/lib/provider/injection-doc.d.ts +1 -0
- package/lib/provider/injection-doc.js +17 -0
- package/lib/provider/match-redaction-warning.d.ts +25 -0
- package/lib/provider/match-redaction-warning.js +35 -0
- package/lib/provider/schema.d.ts +16 -0
- package/lib/provider/schema.js +11 -1
- package/lib/provider/to-version.d.ts +61 -12
- package/lib/provider/to-version.js +109 -24
- package/lib/provider/verification-checks.d.ts +12 -0
- package/lib/provider/verification-checks.js +30 -0
- package/lib/routes.gen.d.ts +271 -0
- package/lib/routes.gen.js +73 -0
- package/lib/types/openapi.gen.d.ts +3967 -0
- package/lib/types/openapi.gen.js +5 -0
- package/package.json +16 -7
- package/skill/SKILL.md +35 -14
- package/skill/builder-mode.md +13 -0
- package/skill/injection-api.md +42 -0
- package/skill/old-mode.md +15 -0
- package/src/cdp/capture-engine.ts +256 -0
- package/src/cdp/capture.ts +25 -185
- package/src/cdp/index.ts +6 -0
- package/src/cdp/launcher.ts +5 -4
- package/src/config/store.ts +7 -6
- package/src/consts.ts +164 -0
- package/src/index.ts +2 -4
- package/src/logger.ts +2 -1
- package/src/mcp/api/operations.gen.ts +1155 -194
- package/src/mcp/api/to-zod.ts +115 -0
- package/src/mcp/api/tools.ts +9 -3
- package/src/mcp/instructions.ts +15 -0
- package/src/mcp/server.ts +5 -50
- package/src/mcp/start.ts +27 -11
- package/src/mcp/tools/agent/build.ts +7 -27
- package/src/mcp/tools/agent/index.ts +4 -0
- package/src/mcp/tools/agent/proof.ts +3 -8
- package/src/mcp/tools/agent/propose.ts +13 -2
- package/src/mcp/tools/agent/publish.ts +218 -92
- package/src/mcp/tools/agent/replay.ts +0 -5
- package/src/mcp/tools/{credentials → authenticate}/authenticate.ts +9 -8
- package/src/mcp/tools/authenticate/build.ts +32 -0
- package/src/mcp/tools/authenticate/decrypt-key.ts +59 -0
- package/src/mcp/tools/authenticate/eth-key.ts +162 -0
- package/src/mcp/tools/authenticate/import.ts +73 -0
- package/src/mcp/tools/authenticate/index.ts +4 -0
- package/src/mcp/tools/authenticate/issue.ts +50 -0
- package/src/mcp/tools/authenticate/resolve-owner-key.ts +60 -0
- package/src/mcp/tools/index.ts +6 -0
- package/src/mcp/tools/verification/build.ts +16 -0
- package/src/mcp/tools/verification/index.ts +2 -0
- package/src/mcp/tools/verification/result.ts +154 -0
- package/src/old/client.ts +3 -0
- package/src/old/flag.ts +4 -3
- package/src/old/identity.ts +8 -7
- package/src/old/instructions.ts +10 -25
- package/src/old/login-cdp.ts +2 -5
- package/src/old/to-register.ts +58 -26
- package/src/old/tools/authenticate.ts +2 -1
- package/src/old/tools/publish.ts +92 -16
- package/src/paths.ts +2 -2
- package/src/proof/attestor.ts +114 -72
- package/src/proof/index.ts +21 -0
- package/src/proof/proof-core.ts +119 -0
- package/src/provider/index.ts +20 -0
- package/src/provider/injection-doc.ts +21 -0
- package/src/provider/match-redaction-warning.ts +53 -0
- package/src/provider/schema.ts +23 -0
- package/src/provider/to-version.ts +180 -33
- package/src/provider/verification-checks.ts +36 -0
- package/lib/mcp/tools/credentials/build.d.ts +0 -16
- package/lib/mcp/tools/credentials/build.js +0 -33
- package/lib/mcp/tools/credentials/status.js +0 -62
- package/src/mcp/tools/credentials/build.ts +0 -37
- package/src/mcp/tools/credentials/cache.ts +0 -161
- package/src/mcp/tools/credentials/env-file.ts +0 -101
- package/src/mcp/tools/credentials/import.ts +0 -72
- package/src/mcp/tools/credentials/issue.ts +0 -107
- package/src/mcp/tools/credentials/list-cached.ts +0 -66
- package/src/mcp/tools/credentials/register.ts +0 -49
- package/src/mcp/tools/credentials/resolve-owner-key.ts +0 -78
- package/src/mcp/tools/credentials/status.ts +0 -82
- package/src/types/openapi.ts +0 -7
- /package/lib/mcp/{tools/credentials → credentials}/env-file.d.ts +0 -0
- /package/lib/mcp/{tools/credentials → credentials}/env-file.js +0 -0
- /package/lib/mcp/{tools/credentials → credentials}/register.d.ts +0 -0
- /package/lib/mcp/{tools/credentials → credentials}/register.js +0 -0
- /package/lib/mcp/tools/{credentials → authenticate}/authenticate.d.ts +0 -0
- /package/lib/mcp/tools/{credentials → authenticate}/import.d.ts +0 -0
- /package/lib/mcp/tools/{credentials → authenticate}/issue.d.ts +0 -0
- /package/lib/mcp/tools/{credentials → authenticate}/session-cache.d.ts +0 -0
- /package/lib/mcp/tools/{credentials → authenticate}/session-cache.js +0 -0
- /package/src/mcp/tools/{credentials → authenticate}/session-cache.ts +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReclaimClient } from '@reclaimprotocol/client';
|
|
2
|
+
import type { RegisteredTool } from '../../server.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Local-only key tools — no backend client needed. These manage the eth
|
|
5
|
+
* proof-owner key entirely on disk (as a secp256k1 PEM) or via env: generate,
|
|
6
|
+
* import, and resolve which key to sign proofs with. No `~/.reclaim` caching;
|
|
7
|
+
* useful in BOTH builder and OLD-devtools mode.
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildLocalCredentialTools(): RegisteredTool[];
|
|
10
|
+
/**
|
|
11
|
+
* Full builder-mode credential set: the local key tools plus the backend
|
|
12
|
+
* `reclaim_authenticate` device-code flow. Old mode does NOT use the
|
|
13
|
+
* authenticate tool — it has its own.
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildCredentialTools(client: ReclaimClient): RegisteredTool[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { authenticateTool } from "./authenticate.js";
|
|
2
|
+
import { importTool } from "./import.js";
|
|
3
|
+
import { issueTool } from "./issue.js";
|
|
4
|
+
import { resolveOwnerKeyTool } from "./resolve-owner-key.js";
|
|
5
|
+
/**
|
|
6
|
+
* Local-only key tools — no backend client needed. These manage the eth
|
|
7
|
+
* proof-owner key entirely on disk (as a secp256k1 PEM) or via env: generate,
|
|
8
|
+
* import, and resolve which key to sign proofs with. No `~/.reclaim` caching;
|
|
9
|
+
* useful in BOTH builder and OLD-devtools mode.
|
|
10
|
+
*/
|
|
11
|
+
export function buildLocalCredentialTools() {
|
|
12
|
+
return [
|
|
13
|
+
resolveOwnerKeyTool(),
|
|
14
|
+
issueTool(),
|
|
15
|
+
importTool(),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Full builder-mode credential set: the local key tools plus the backend
|
|
20
|
+
* `reclaim_authenticate` device-code flow. Old mode does NOT use the
|
|
21
|
+
* authenticate tool — it has its own.
|
|
22
|
+
*/
|
|
23
|
+
export function buildCredentialTools(client) {
|
|
24
|
+
return [
|
|
25
|
+
authenticateTool(client),
|
|
26
|
+
...buildLocalCredentialTools(),
|
|
27
|
+
];
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional eth decryption key — only needed when testing ENCRYPTED callback
|
|
3
|
+
* payloads in the consumer role. The org's results are ECIES-encrypted to its
|
|
4
|
+
* eth public key; this is the matching eth PRIVATE key (`0x`-hex). Resolution:
|
|
5
|
+
*
|
|
6
|
+
* 1. The `RECLAIM_DECRYPT_KEY` env var (a `0x`-prefixed 32-byte hex key), or
|
|
7
|
+
* 2. A file named `reclaim-decrypt.key` in the project root holding that hex.
|
|
8
|
+
* 3. Absent — plaintext-only testing (no decryption key; encrypted
|
|
9
|
+
* deliveries surface a clear error).
|
|
10
|
+
*
|
|
11
|
+
* The hex is loaded via the client's `loadDecryptionKey` and passed straight
|
|
12
|
+
* through as `ReclaimConfig.credential` / to `decryptCallback`.
|
|
13
|
+
*/
|
|
14
|
+
import { type DecryptionKey } from '@reclaimprotocol/client';
|
|
15
|
+
/**
|
|
16
|
+
* Load the optional decryption key. Returns `undefined` when no key is
|
|
17
|
+
* configured (the consumer then handles only plaintext deliveries).
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveDecryptionKey(projectDir?: string): Promise<DecryptionKey | undefined>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional eth decryption key — only needed when testing ENCRYPTED callback
|
|
3
|
+
* payloads in the consumer role. The org's results are ECIES-encrypted to its
|
|
4
|
+
* eth public key; this is the matching eth PRIVATE key (`0x`-hex). Resolution:
|
|
5
|
+
*
|
|
6
|
+
* 1. The `RECLAIM_DECRYPT_KEY` env var (a `0x`-prefixed 32-byte hex key), or
|
|
7
|
+
* 2. A file named `reclaim-decrypt.key` in the project root holding that hex.
|
|
8
|
+
* 3. Absent — plaintext-only testing (no decryption key; encrypted
|
|
9
|
+
* deliveries surface a clear error).
|
|
10
|
+
*
|
|
11
|
+
* The hex is loaded via the client's `loadDecryptionKey` and passed straight
|
|
12
|
+
* through as `ReclaimConfig.credential` / to `decryptCallback`.
|
|
13
|
+
*/
|
|
14
|
+
import { loadDecryptionKey, } from '@reclaimprotocol/client';
|
|
15
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import { findProjectRoot } from "../../../paths.js";
|
|
18
|
+
/** Default eth decrypt-key filename the agent looks for in the project root. */
|
|
19
|
+
const DEFAULT_DECRYPT_KEY_FILE = 'reclaim-decrypt.key';
|
|
20
|
+
/**
|
|
21
|
+
* Read the raw eth decryption-key hex — from `RECLAIM_DECRYPT_KEY` or the
|
|
22
|
+
* default file — without loading it. Returns `undefined` when neither is
|
|
23
|
+
* present (plaintext-only).
|
|
24
|
+
*/
|
|
25
|
+
function resolveDecryptKeyInput(projectDir = findProjectRoot(process.cwd())) {
|
|
26
|
+
const fromEnv = process.env.RECLAIM_DECRYPT_KEY?.trim();
|
|
27
|
+
if (fromEnv) {
|
|
28
|
+
return fromEnv;
|
|
29
|
+
}
|
|
30
|
+
const keyPath = join(projectDir, DEFAULT_DECRYPT_KEY_FILE);
|
|
31
|
+
if (existsSync(keyPath)) {
|
|
32
|
+
return readFileSync(keyPath, 'utf8').trim();
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Load the optional decryption key. Returns `undefined` when no key is
|
|
38
|
+
* configured (the consumer then handles only plaintext deliveries).
|
|
39
|
+
*/
|
|
40
|
+
export async function resolveDecryptionKey(projectDir = findProjectRoot(process.cwd())) {
|
|
41
|
+
const input = resolveDecryptKeyInput(projectDir);
|
|
42
|
+
if (input === undefined) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return loadDecryptionKey(input);
|
|
46
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** The dotenv file the agent reads from / writes the key to. */
|
|
2
|
+
export declare const ENV_FILE = ".env";
|
|
3
|
+
/** Where the resolved eth key came from. */
|
|
4
|
+
export type EthKeySource = 'env' | 'dotenv' | 'file';
|
|
5
|
+
export type ResolvedEthKey = {
|
|
6
|
+
/** Raw 0x-hex 32-byte scalar. */
|
|
7
|
+
privateKey: string;
|
|
8
|
+
/** Lowercase eth address derived from the scalar. */
|
|
9
|
+
address: string;
|
|
10
|
+
source: EthKeySource;
|
|
11
|
+
/** Absolute path the key was read from (for `dotenv` / `file` sources). */
|
|
12
|
+
path?: string;
|
|
13
|
+
};
|
|
14
|
+
/** Validate + normalize a raw Ethereum private key to lowercase 0x-hex. */
|
|
15
|
+
export declare function normalizeEthHex(value: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve the eth proof-owner key without prompting. Returns `undefined` when
|
|
18
|
+
* no key is configured anywhere — the caller decides whether to generate or
|
|
19
|
+
* ask for one (see `resolve_owner_key`).
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveEthKey(projectDir?: string): ResolvedEthKey | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Persist a raw eth private key to the project `.env` as
|
|
24
|
+
* `RECLAIM_PRIVATE_KEY=0x…` (upsert; mode 0600; `.env` added to `.gitignore`).
|
|
25
|
+
* Used by `issue_credentials` (generate) and `import_credentials` (supplied
|
|
26
|
+
* hex). Returns the derived address and the `.env` path.
|
|
27
|
+
*/
|
|
28
|
+
export declare function writeEthKey(privateKeyHex: string, projectDir?: string): {
|
|
29
|
+
path: string;
|
|
30
|
+
address: string;
|
|
31
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eth proof-owner key resolution — the raw secp256k1 private key passed to
|
|
3
|
+
* attestor-core when the agent creates a local claim. It's a plain 0x-hex
|
|
4
|
+
* Ethereum private key (no PEM), resolved from, in order:
|
|
5
|
+
*
|
|
6
|
+
* 1. `process.env.RECLAIM_PRIVATE_KEY` — a 0x-hex 32-byte scalar.
|
|
7
|
+
* 2. A `.env` file in the project root — its `RECLAIM_PRIVATE_KEY=0x…` line.
|
|
8
|
+
* 3. A key file holding the raw 0x-hex scalar, at `RECLAIM_PRIVATE_KEY_FILE`
|
|
9
|
+
* (absolute or project-relative).
|
|
10
|
+
* 4. Absent — the caller offers to generate one or asks the dev for a key.
|
|
11
|
+
*
|
|
12
|
+
* Generated/imported keys are written to the project `.env` (mode 0600, and the
|
|
13
|
+
* file is added to `.gitignore`). NO `~/.reclaim` caching. This is a LOCAL
|
|
14
|
+
* signing key only — unrelated to org auth (the org secret) or encryption
|
|
15
|
+
* (the eth decrypt key).
|
|
16
|
+
*/
|
|
17
|
+
import { deriveFromPrivateKey } from '@reclaimprotocol/client';
|
|
18
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
19
|
+
import { isAbsolute, join } from 'node:path';
|
|
20
|
+
import { privateKey, privateKeyFile } from "../../../consts.js";
|
|
21
|
+
import { findProjectRoot } from "../../../paths.js";
|
|
22
|
+
const ENV_VAR = 'RECLAIM_PRIVATE_KEY';
|
|
23
|
+
/** The dotenv file the agent reads from / writes the key to. */
|
|
24
|
+
export const ENV_FILE = '.env';
|
|
25
|
+
/** Validate + normalize a raw Ethereum private key to lowercase 0x-hex. */
|
|
26
|
+
export function normalizeEthHex(value) {
|
|
27
|
+
const v = value.trim().replace(/^['"]|['"]$/g, '');
|
|
28
|
+
if (!/^(0x)?[0-9a-fA-F]{64}$/.test(v)) {
|
|
29
|
+
throw new Error('not a valid Ethereum private key (expected a 32-byte / 64-hex scalar)');
|
|
30
|
+
}
|
|
31
|
+
return '0x' + v.replace(/^0x/, '').toLowerCase();
|
|
32
|
+
}
|
|
33
|
+
/** Read `RECLAIM_PRIVATE_KEY` from a dotenv file (simple KEY=VALUE parse). */
|
|
34
|
+
function readDotenvKey(path) {
|
|
35
|
+
if (!existsSync(path)) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
for (const line of readFileSync(path, 'utf8').split('\n')) {
|
|
39
|
+
const m = line.match(/^\s*RECLAIM_PRIVATE_KEY\s*=\s*(.+?)\s*$/);
|
|
40
|
+
if (m) {
|
|
41
|
+
return m[1];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/** The explicit raw-hex key-file path, if `RECLAIM_PRIVATE_KEY_FILE` is set. */
|
|
47
|
+
function ethKeyFilePath(projectDir = findProjectRoot(process.cwd())) {
|
|
48
|
+
const p = privateKeyFile();
|
|
49
|
+
if (!p) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return isAbsolute(p) ? p : join(projectDir, p);
|
|
53
|
+
}
|
|
54
|
+
function resolved(privateKey, source, path) {
|
|
55
|
+
return {
|
|
56
|
+
privateKey,
|
|
57
|
+
address: deriveFromPrivateKey(privateKey).address,
|
|
58
|
+
source,
|
|
59
|
+
...(path ? { path } : {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Resolve the eth proof-owner key without prompting. Returns `undefined` when
|
|
64
|
+
* no key is configured anywhere — the caller decides whether to generate or
|
|
65
|
+
* ask for one (see `resolve_owner_key`).
|
|
66
|
+
*/
|
|
67
|
+
export function resolveEthKey(projectDir = findProjectRoot(process.cwd())) {
|
|
68
|
+
const env = privateKey();
|
|
69
|
+
if (env?.trim()) {
|
|
70
|
+
return resolved(normalizeEthHex(env), 'env');
|
|
71
|
+
}
|
|
72
|
+
const envPath = join(projectDir, ENV_FILE);
|
|
73
|
+
const fromDotenv = readDotenvKey(envPath);
|
|
74
|
+
if (fromDotenv) {
|
|
75
|
+
return resolved(normalizeEthHex(fromDotenv), 'dotenv', envPath);
|
|
76
|
+
}
|
|
77
|
+
const keyFile = ethKeyFilePath(projectDir);
|
|
78
|
+
if (keyFile && existsSync(keyFile)) {
|
|
79
|
+
return resolved(normalizeEthHex(readFileSync(keyFile, 'utf8')), 'file', keyFile);
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
/** Append `entry` to the project `.gitignore` if not already present. */
|
|
84
|
+
function ensureGitignored(projectDir, entry) {
|
|
85
|
+
const path = join(projectDir, '.gitignore');
|
|
86
|
+
const current = existsSync(path) ? readFileSync(path, 'utf8') : '';
|
|
87
|
+
if (current.split('\n').some((l) => l.trim() === entry)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const prefix = current && !current.endsWith('\n') ? '\n' : '';
|
|
91
|
+
writeFileSync(path, current + prefix + entry + '\n');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Persist a raw eth private key to the project `.env` as
|
|
95
|
+
* `RECLAIM_PRIVATE_KEY=0x…` (upsert; mode 0600; `.env` added to `.gitignore`).
|
|
96
|
+
* Used by `issue_credentials` (generate) and `import_credentials` (supplied
|
|
97
|
+
* hex). Returns the derived address and the `.env` path.
|
|
98
|
+
*/
|
|
99
|
+
export function writeEthKey(privateKeyHex, projectDir = findProjectRoot(process.cwd())) {
|
|
100
|
+
const hex = normalizeEthHex(privateKeyHex);
|
|
101
|
+
const envPath = join(projectDir, ENV_FILE);
|
|
102
|
+
const line = `${ENV_VAR}=${hex}`;
|
|
103
|
+
const existing = existsSync(envPath) ? readFileSync(envPath, 'utf8') : '';
|
|
104
|
+
const re = new RegExp(`^\\s*${ENV_VAR}\\s*=.*$`, 'm');
|
|
105
|
+
let next;
|
|
106
|
+
if (re.test(existing)) {
|
|
107
|
+
next = existing.replace(re, line);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const prefix = existing && !existing.endsWith('\n') ? '\n' : '';
|
|
111
|
+
next = existing + prefix + line + '\n';
|
|
112
|
+
}
|
|
113
|
+
writeFileSync(envPath, next, { mode: 0o600 });
|
|
114
|
+
ensureGitignored(projectDir, ENV_FILE);
|
|
115
|
+
return { path: envPath, address: deriveFromPrivateKey(hex).address };
|
|
116
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { findProjectRoot } from "../../../paths.js";
|
|
3
|
+
import { defineTool } from "../../server.js";
|
|
4
|
+
import { writeEthKey } from "./eth-key.js";
|
|
5
|
+
export function importTool() {
|
|
6
|
+
return defineTool({
|
|
7
|
+
name: 'import_credentials',
|
|
8
|
+
description: 'Import an eth proof-owner key the dev already holds and persist it ' +
|
|
9
|
+
'to the project `.env` as RECLAIM_PRIVATE_KEY=0x… (mode 0600; `.env` ' +
|
|
10
|
+
'added to .gitignore). Provide EITHER `privateKey` (raw 0x-hex, 64 ' +
|
|
11
|
+
'chars) OR `keyFile` (path to a file holding the raw 0x-hex key). ' +
|
|
12
|
+
'The address is derived locally; the private key is never ' +
|
|
13
|
+
'returned. This is a local signing key only (not registered ' +
|
|
14
|
+
'with any server, ' +
|
|
15
|
+
'unrelated to org auth or encryption).',
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
privateKey: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
pattern: '^0x?[0-9a-fA-F]{64}$',
|
|
22
|
+
description: 'Raw Ethereum private key, 0x-prefixed hex (64 hex chars).',
|
|
23
|
+
},
|
|
24
|
+
keyFile: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
description: 'Path to a file containing the raw 0x-hex private key ' +
|
|
27
|
+
'(absolute or project-relative).',
|
|
28
|
+
},
|
|
29
|
+
projectDir: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
description: 'Project directory whose `.env` the key is written to. ' +
|
|
32
|
+
'Defaults to the closest ancestor of cwd containing .git or ' +
|
|
33
|
+
'package.json.',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}, async (args) => {
|
|
38
|
+
if (!args.privateKey && !args.keyFile) {
|
|
39
|
+
throw new Error('Provide either `privateKey` (0x-hex) or `keyFile`.');
|
|
40
|
+
}
|
|
41
|
+
if (args.privateKey && args.keyFile) {
|
|
42
|
+
throw new Error('Provide only one of `privateKey` or `keyFile`.');
|
|
43
|
+
}
|
|
44
|
+
const projectDir = findProjectRoot(args.projectDir || process.cwd());
|
|
45
|
+
const privateKeyHex = args.keyFile
|
|
46
|
+
? readFileSync(args.keyFile, 'utf8')
|
|
47
|
+
: args.privateKey;
|
|
48
|
+
const { path, address } = writeEthKey(privateKeyHex, projectDir);
|
|
49
|
+
return {
|
|
50
|
+
address,
|
|
51
|
+
path,
|
|
52
|
+
note: 'Eth proof-owner key written to .env as RECLAIM_PRIVATE_KEY ' +
|
|
53
|
+
'(mode 0600). resolve_owner_key resolves it from .env. Keep .env ' +
|
|
54
|
+
'secret — it has been added to .gitignore.',
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Barrel for the credential tool group: local eth proof-owner key (env/PEM)
|
|
2
|
+
// and the org-token-authenticated builder tools. Import from here.
|
|
3
|
+
export { buildCredentialTools, buildLocalCredentialTools } from "./build.js";
|
|
4
|
+
export { readSession } from "./session-cache.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { generateKeypair } from '@reclaimprotocol/client';
|
|
2
|
+
import { findProjectRoot } from "../../../paths.js";
|
|
3
|
+
import { defineTool } from "../../server.js";
|
|
4
|
+
import { writeEthKey } from "./eth-key.js";
|
|
5
|
+
export function issueTool() {
|
|
6
|
+
return defineTool({
|
|
7
|
+
name: 'issue_credentials',
|
|
8
|
+
description: 'Generate a fresh secp256k1 eth proof-owner key-pair (the key ' +
|
|
9
|
+
'that signs local claim creation) and write the raw private key to ' +
|
|
10
|
+
'the project `.env` as RECLAIM_PRIVATE_KEY=0x… (mode 0600; `.env` ' +
|
|
11
|
+
'added to .gitignore). This is a LOCAL signing key only — it is NOT ' +
|
|
12
|
+
'registered with any server and is unrelated to org auth (the org ' +
|
|
13
|
+
'secret) or encryption (the eth decrypt key). ALWAYS confirm with ' +
|
|
14
|
+
'the dev before generating a new key. After writing, run_proof picks ' +
|
|
15
|
+
'it up automatically via resolve_owner_key. The private key is never ' +
|
|
16
|
+
'returned in the response.',
|
|
17
|
+
inputSchema: {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
projectDir: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'Project directory whose `.env` the key is written to. ' +
|
|
23
|
+
'Defaults to the closest ancestor of cwd containing .git or ' +
|
|
24
|
+
'package.json.',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}, async (args) => {
|
|
29
|
+
const projectDir = findProjectRoot(args.projectDir || process.cwd());
|
|
30
|
+
const keypair = generateKeypair();
|
|
31
|
+
const { path, address } = writeEthKey(keypair.privateKey, projectDir);
|
|
32
|
+
return {
|
|
33
|
+
address,
|
|
34
|
+
path,
|
|
35
|
+
note: 'Eth proof-owner key written to .env as RECLAIM_PRIVATE_KEY ' +
|
|
36
|
+
'(mode 0600); the private key is NOT in this response on purpose. ' +
|
|
37
|
+
'resolve_owner_key will now resolve it from .env (or set ' +
|
|
38
|
+
'RECLAIM_PRIVATE_KEY in the environment to override). Keep .env ' +
|
|
39
|
+
'secret — it has been added to .gitignore.',
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type RegisteredTool } from '../../server.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Decide which eth proof-owner key `run_proof` should sign with, BEFORE
|
|
4
|
+
* calling it. The key is a raw 0x-hex Ethereum private key, resolved (no
|
|
5
|
+
* `~/.reclaim` cache) from:
|
|
6
|
+
* 1. `RECLAIM_PRIVATE_KEY` in the MCP env
|
|
7
|
+
* 2. a `RECLAIM_PRIVATE_KEY=0x…` line in the project `.env`
|
|
8
|
+
* 3. a file at `RECLAIM_PRIVATE_KEY_FILE` holding the raw hex
|
|
9
|
+
* 4. none → ask the dev to generate (issue_credentials) or provide one
|
|
10
|
+
* (import_credentials), then call again.
|
|
11
|
+
* Never returns the private key — only the derived address.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveOwnerKeyTool(): RegisteredTool;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { findProjectRoot } from "../../../paths.js";
|
|
3
|
+
import { defineTool } from "../../server.js";
|
|
4
|
+
import { ENV_FILE, resolveEthKey } from "./eth-key.js";
|
|
5
|
+
/**
|
|
6
|
+
* Decide which eth proof-owner key `run_proof` should sign with, BEFORE
|
|
7
|
+
* calling it. The key is a raw 0x-hex Ethereum private key, resolved (no
|
|
8
|
+
* `~/.reclaim` cache) from:
|
|
9
|
+
* 1. `RECLAIM_PRIVATE_KEY` in the MCP env
|
|
10
|
+
* 2. a `RECLAIM_PRIVATE_KEY=0x…` line in the project `.env`
|
|
11
|
+
* 3. a file at `RECLAIM_PRIVATE_KEY_FILE` holding the raw hex
|
|
12
|
+
* 4. none → ask the dev to generate (issue_credentials) or provide one
|
|
13
|
+
* (import_credentials), then call again.
|
|
14
|
+
* Never returns the private key — only the derived address.
|
|
15
|
+
*/
|
|
16
|
+
export function resolveOwnerKeyTool() {
|
|
17
|
+
return defineTool({
|
|
18
|
+
name: 'resolve_owner_key',
|
|
19
|
+
description: 'Resolve which eth proof-owner key run_proof should sign with — ' +
|
|
20
|
+
'call this BEFORE run_proof. Checks, in order: RECLAIM_PRIVATE_KEY ' +
|
|
21
|
+
'in the MCP env, a RECLAIM_PRIVATE_KEY=0x… line in the project .env, ' +
|
|
22
|
+
'then a file at RECLAIM_PRIVATE_KEY_FILE holding the raw hex. ' +
|
|
23
|
+
'Returns { ready: true, address, source } when one is ' +
|
|
24
|
+
'available — pass `address` to run_proof as `ownerAddress`. ' +
|
|
25
|
+
'Returns { ready: false } ' +
|
|
26
|
+
'when none exists: then ask the dev to generate one ' +
|
|
27
|
+
'(issue_credentials) or import one they already hold ' +
|
|
28
|
+
'(import_credentials, accepts 0x-hex or a key-file path), and call ' +
|
|
29
|
+
'resolve_owner_key again. Never exposes the private key.',
|
|
30
|
+
inputSchema: { type: 'object', properties: {} },
|
|
31
|
+
}, async () => {
|
|
32
|
+
const projectDir = findProjectRoot(process.cwd());
|
|
33
|
+
const resolved = resolveEthKey(projectDir);
|
|
34
|
+
if (resolved) {
|
|
35
|
+
return {
|
|
36
|
+
ready: true,
|
|
37
|
+
address: resolved.address,
|
|
38
|
+
source: resolved.source,
|
|
39
|
+
...(resolved.path ? { path: resolved.path } : {}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
ready: false,
|
|
44
|
+
message: 'No eth proof-owner key available — no RECLAIM_PRIVATE_KEY in the ' +
|
|
45
|
+
`env, no RECLAIM_PRIVATE_KEY in ${join(projectDir, ENV_FILE)}, and ` +
|
|
46
|
+
'no RECLAIM_PRIVATE_KEY_FILE. Ask the dev to generate one via ' +
|
|
47
|
+
'issue_credentials, or import one they already hold via ' +
|
|
48
|
+
'import_credentials (0x-hex or a key-file path). Then call ' +
|
|
49
|
+
'resolve_owner_key again and pass its address to run_proof as ' +
|
|
50
|
+
'ownerAddress.',
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CaptureSession } from '../../cdp/capture.ts';
|
|
2
|
+
import { type RegisteredTool } from '../server.ts';
|
|
3
|
+
import type { AttachState } from './attach.ts';
|
|
4
|
+
export interface CaptureStore {
|
|
5
|
+
sessions: Map<string, CaptureSession>;
|
|
6
|
+
activeTab?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function captureTools(attachRef: {
|
|
9
|
+
current?: AttachState;
|
|
10
|
+
}, captures: CaptureStore): RegisteredTool[];
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { startCapture } from "../../cdp/capture.js";
|
|
2
|
+
import { defineTool } from "../server.js";
|
|
3
|
+
export function captureTools(attachRef, captures) {
|
|
4
|
+
const requireAttached = () => {
|
|
5
|
+
if (!attachRef.current) {
|
|
6
|
+
throw new Error('Not attached. Call attach_chrome first.');
|
|
7
|
+
}
|
|
8
|
+
return attachRef.current;
|
|
9
|
+
};
|
|
10
|
+
const startTool = defineTool({
|
|
11
|
+
name: 'start_capture',
|
|
12
|
+
description: 'Begin recording network requests on the specified tab. ' +
|
|
13
|
+
'Returns a captureId.',
|
|
14
|
+
inputSchema: {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: { tabId: { type: 'string' } },
|
|
17
|
+
required: ['tabId'],
|
|
18
|
+
},
|
|
19
|
+
}, async ({ tabId }) => {
|
|
20
|
+
const attached = requireAttached();
|
|
21
|
+
const tabClient = await attached.handles.attachToTab(tabId);
|
|
22
|
+
const session = await startCapture(tabClient);
|
|
23
|
+
captures.sessions.set(session.captureId, session);
|
|
24
|
+
captures.activeTab = tabId;
|
|
25
|
+
return { captureId: session.captureId };
|
|
26
|
+
});
|
|
27
|
+
const stopTool = defineTool({
|
|
28
|
+
name: 'stop_capture',
|
|
29
|
+
description: 'Stop recording on the given capture. ' +
|
|
30
|
+
'Captured data remains queryable until reset_session.',
|
|
31
|
+
inputSchema: {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: { captureId: { type: 'string' } },
|
|
34
|
+
required: ['captureId'],
|
|
35
|
+
},
|
|
36
|
+
}, async ({ captureId }) => {
|
|
37
|
+
const session = captures.sessions.get(captureId);
|
|
38
|
+
if (!session) {
|
|
39
|
+
throw new Error(`no capture ${captureId}`);
|
|
40
|
+
}
|
|
41
|
+
await session.stop();
|
|
42
|
+
return { stopped: true, requestCount: session.requests.size };
|
|
43
|
+
});
|
|
44
|
+
const listTool = defineTool({
|
|
45
|
+
name: 'list_requests',
|
|
46
|
+
description: 'List metadata for captured requests. ' +
|
|
47
|
+
'Filter by method, URL glob, status, content-type, ' +
|
|
48
|
+
'or graphqlOp. Returns only metadata, never bodies — ' +
|
|
49
|
+
'use get_request for those.',
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: {
|
|
53
|
+
captureId: { type: 'string' },
|
|
54
|
+
filter: {
|
|
55
|
+
type: 'object',
|
|
56
|
+
properties: {
|
|
57
|
+
method: { type: 'string' },
|
|
58
|
+
urlGlob: { type: 'string' },
|
|
59
|
+
statusMin: { type: 'number' },
|
|
60
|
+
statusMax: { type: 'number' },
|
|
61
|
+
contentType: { type: 'string' },
|
|
62
|
+
graphqlOp: { type: 'string' },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
required: ['captureId'],
|
|
67
|
+
},
|
|
68
|
+
}, async ({ captureId, filter }) => {
|
|
69
|
+
const session = captures.sessions.get(captureId);
|
|
70
|
+
if (!session) {
|
|
71
|
+
throw new Error(`no capture ${captureId}`);
|
|
72
|
+
}
|
|
73
|
+
const out = [];
|
|
74
|
+
for (const r of session.requests.values()) {
|
|
75
|
+
if (filter?.method && r.method !== filter.method.toUpperCase()) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (filter?.urlGlob && !globMatch(filter.urlGlob, r.url)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (filter?.statusMin !== undefined && r.status < filter.statusMin) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (filter?.statusMax !== undefined && r.status > filter.statusMax) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (filter?.contentType &&
|
|
88
|
+
!r.contentType.includes(filter.contentType)) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (filter?.graphqlOp && r.graphqlOp !== filter.graphqlOp) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const item = {
|
|
95
|
+
requestId: r.requestId,
|
|
96
|
+
method: r.method,
|
|
97
|
+
url: r.url,
|
|
98
|
+
status: r.status,
|
|
99
|
+
contentType: r.contentType,
|
|
100
|
+
size: r.size,
|
|
101
|
+
};
|
|
102
|
+
if (r.graphqlOp !== undefined) {
|
|
103
|
+
item.graphqlOp = r.graphqlOp;
|
|
104
|
+
}
|
|
105
|
+
out.push(item);
|
|
106
|
+
}
|
|
107
|
+
return { requests: out };
|
|
108
|
+
});
|
|
109
|
+
const getTool = defineTool({
|
|
110
|
+
name: 'get_request',
|
|
111
|
+
description: 'Return full headers + bodies for a specific captured request.',
|
|
112
|
+
inputSchema: {
|
|
113
|
+
type: 'object',
|
|
114
|
+
properties: {
|
|
115
|
+
captureId: { type: 'string' },
|
|
116
|
+
requestId: { type: 'string' },
|
|
117
|
+
},
|
|
118
|
+
required: ['captureId', 'requestId'],
|
|
119
|
+
},
|
|
120
|
+
}, async ({ captureId, requestId }) => {
|
|
121
|
+
const session = captures.sessions.get(captureId);
|
|
122
|
+
if (!session) {
|
|
123
|
+
throw new Error(`no capture ${captureId}`);
|
|
124
|
+
}
|
|
125
|
+
const r = session.requests.get(requestId);
|
|
126
|
+
if (!r) {
|
|
127
|
+
throw new Error(`no request ${requestId} in capture ${captureId}`);
|
|
128
|
+
}
|
|
129
|
+
const body = session.bodies.get(requestId);
|
|
130
|
+
if (!body.available) {
|
|
131
|
+
return { ...r, bodyAvailable: false, reason: body.reason };
|
|
132
|
+
}
|
|
133
|
+
return { ...r, responseBody: body.body, bodyAvailable: true };
|
|
134
|
+
});
|
|
135
|
+
return [startTool, stopTool, listTool, getTool];
|
|
136
|
+
}
|
|
137
|
+
function globMatch(pattern, str) {
|
|
138
|
+
const re = new RegExp('^' +
|
|
139
|
+
pattern.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*') +
|
|
140
|
+
'$');
|
|
141
|
+
return re.test(str);
|
|
142
|
+
}
|