@absol-labs/agent 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +196 -0
  3. package/dist/discovery/registry.d.ts +68 -0
  4. package/dist/discovery/registry.d.ts.map +1 -0
  5. package/dist/discovery/registry.js +148 -0
  6. package/dist/discovery/registry.js.map +1 -0
  7. package/dist/frameworks/agentkit.d.ts +158 -0
  8. package/dist/frameworks/agentkit.d.ts.map +1 -0
  9. package/dist/frameworks/agentkit.js +339 -0
  10. package/dist/frameworks/agentkit.js.map +1 -0
  11. package/dist/frameworks/crewai.d.ts +19 -0
  12. package/dist/frameworks/crewai.d.ts.map +1 -0
  13. package/dist/frameworks/crewai.js +73 -0
  14. package/dist/frameworks/crewai.js.map +1 -0
  15. package/dist/frameworks/eliza.d.ts +393 -0
  16. package/dist/frameworks/eliza.d.ts.map +1 -0
  17. package/dist/frameworks/eliza.js +542 -0
  18. package/dist/frameworks/eliza.js.map +1 -0
  19. package/dist/frameworks/langchain.d.ts +31 -0
  20. package/dist/frameworks/langchain.d.ts.map +1 -0
  21. package/dist/frameworks/langchain.js +206 -0
  22. package/dist/frameworks/langchain.js.map +1 -0
  23. package/dist/index.d.ts +14 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +16 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/mandates/env.d.ts +51 -0
  28. package/dist/mandates/env.d.ts.map +1 -0
  29. package/dist/mandates/env.js +148 -0
  30. package/dist/mandates/env.js.map +1 -0
  31. package/dist/mandates/mandate.d.ts +214 -0
  32. package/dist/mandates/mandate.d.ts.map +1 -0
  33. package/dist/mandates/mandate.js +172 -0
  34. package/dist/mandates/mandate.js.map +1 -0
  35. package/dist/mcp/http-server.d.ts +2 -0
  36. package/dist/mcp/http-server.d.ts.map +1 -0
  37. package/dist/mcp/http-server.js +32 -0
  38. package/dist/mcp/http-server.js.map +1 -0
  39. package/dist/mcp/http.d.ts +114 -0
  40. package/dist/mcp/http.d.ts.map +1 -0
  41. package/dist/mcp/http.js +428 -0
  42. package/dist/mcp/http.js.map +1 -0
  43. package/dist/mcp/server.d.ts +119 -0
  44. package/dist/mcp/server.d.ts.map +1 -0
  45. package/dist/mcp/server.js +679 -0
  46. package/dist/mcp/server.js.map +1 -0
  47. package/dist/mcp/stdio.d.ts +2 -0
  48. package/dist/mcp/stdio.d.ts.map +1 -0
  49. package/dist/mcp/stdio.js +6 -0
  50. package/dist/mcp/stdio.js.map +1 -0
  51. package/dist/sdk/client.d.ts +78 -0
  52. package/dist/sdk/client.d.ts.map +1 -0
  53. package/dist/sdk/client.js +99 -0
  54. package/dist/sdk/client.js.map +1 -0
  55. package/dist/wallet/provider.d.ts +51 -0
  56. package/dist/wallet/provider.d.ts.map +1 -0
  57. package/dist/wallet/provider.js +107 -0
  58. package/dist/wallet/provider.js.map +1 -0
  59. package/dist/x402/facilitator.d.ts +315 -0
  60. package/dist/x402/facilitator.d.ts.map +1 -0
  61. package/dist/x402/facilitator.js +194 -0
  62. package/dist/x402/facilitator.js.map +1 -0
  63. package/dist/zktls/reclaim.d.ts +137 -0
  64. package/dist/zktls/reclaim.d.ts.map +1 -0
  65. package/dist/zktls/reclaim.js +245 -0
  66. package/dist/zktls/reclaim.js.map +1 -0
  67. package/package.json +86 -0
  68. package/src/discovery/registry.ts +255 -0
  69. package/src/frameworks/agentkit.ts +537 -0
  70. package/src/frameworks/crewai.ts +102 -0
  71. package/src/frameworks/eliza.ts +776 -0
  72. package/src/frameworks/langchain.ts +325 -0
  73. package/src/index.ts +179 -0
  74. package/src/mandates/env.ts +222 -0
  75. package/src/mandates/mandate.ts +280 -0
  76. package/src/mcp/http-server.ts +38 -0
  77. package/src/mcp/http.ts +620 -0
  78. package/src/mcp/server.ts +1006 -0
  79. package/src/mcp/stdio.ts +8 -0
  80. package/src/sdk/client.ts +222 -0
  81. package/src/wallet/provider.ts +197 -0
  82. package/src/x402/facilitator.ts +336 -0
  83. package/src/zktls/reclaim.ts +424 -0
@@ -0,0 +1,424 @@
1
+ import {
2
+ getHttpProviderClaimParamsFromProof,
3
+ getProviderHashRequirementsFromSpec,
4
+ verifyProof,
5
+ type Proof as ReclaimProtocolProof,
6
+ type RequestSpec,
7
+ type VerifyProofResult,
8
+ } from "@reclaimprotocol/js-sdk";
9
+ import { z } from "zod";
10
+
11
+ const addressSchema = z.string().regex(/^0x[0-9a-fA-F]{40}$/);
12
+ const bytes32Schema = z.string().regex(/^0x[0-9a-fA-F]{64}$/);
13
+ const httpMethodSchema = z.enum(["GET", "POST", "PUT"]);
14
+ const responseMatchSchema = z.object({
15
+ type: z.enum(["regex", "contains"]),
16
+ value: z.string().min(1, "response match value is required"),
17
+ invert: z.boolean().optional(),
18
+ isOptional: z.boolean().optional(),
19
+ });
20
+ const responseRedactionSchema = z
21
+ .object({
22
+ regex: z.string().optional(),
23
+ jsonPath: z.string().optional(),
24
+ xPath: z.string().optional(),
25
+ hash: z.enum(["oprf", "oprf-raw", "oprf-mpc"]).optional(),
26
+ })
27
+ .refine(
28
+ (value) =>
29
+ value.regex !== undefined ||
30
+ value.jsonPath !== undefined ||
31
+ value.xPath !== undefined,
32
+ "response redaction needs regex, jsonPath, or xPath",
33
+ );
34
+
35
+ export type HttpsResponseMatch = z.infer<typeof responseMatchSchema>;
36
+ export type HttpsResponseRedaction = z.infer<typeof responseRedactionSchema>;
37
+ export type ReclaimProof = ReclaimProtocolProof;
38
+
39
+ export interface DeliveryProofBinding {
40
+ readonly owner: `0x${string}`;
41
+ readonly streamId?: `0x${string}`;
42
+ readonly operator?: `0x${string}`;
43
+ readonly serviceRef?: `0x${string}`;
44
+ readonly mandateId?: `0x${string}`;
45
+ }
46
+
47
+ export interface ProveConsumedHttpsResponseInput {
48
+ readonly url: string;
49
+ readonly method?: "GET" | "POST" | "PUT";
50
+ readonly headers?: Record<string, string>;
51
+ readonly body?: string;
52
+ readonly secretHeaders?: Record<string, string>;
53
+ readonly responseMatches: readonly HttpsResponseMatch[];
54
+ readonly responseRedactions?: readonly HttpsResponseRedaction[];
55
+ readonly cookie?: string;
56
+ readonly secretParamValues?: Record<string, string>;
57
+ readonly geoLocation?: string;
58
+ readonly useTee?: boolean;
59
+ readonly zkEngine?: "snarkjs" | "stwo";
60
+ readonly delivery: DeliveryProofBinding;
61
+ }
62
+
63
+ export interface VerifiedConsumedHttpsResponseProof {
64
+ readonly proof: ReclaimProof;
65
+ readonly request: {
66
+ readonly url: string;
67
+ readonly method: "GET" | "POST" | "PUT";
68
+ readonly body: string | null;
69
+ readonly responseMatches: readonly HttpsResponseMatch[];
70
+ readonly responseRedactions: readonly HttpsResponseRedaction[];
71
+ };
72
+ readonly verification: {
73
+ readonly context: Record<string, unknown>;
74
+ readonly extractedParameters: Record<string, string>;
75
+ readonly publicData: unknown;
76
+ readonly isTeeAttestationVerified: boolean;
77
+ readonly isAttestorTeeAttestationVerified: boolean;
78
+ };
79
+ }
80
+
81
+ export interface ReclaimProofServiceConfig {
82
+ readonly applicationId: string;
83
+ readonly applicationSecret: string;
84
+ readonly logs?: boolean;
85
+ }
86
+
87
+ export interface ParsedReclaimProofEnv extends ReclaimProofServiceConfig {}
88
+
89
+ export interface ReclaimClientLike {
90
+ zkFetch(
91
+ url: string,
92
+ options?: {
93
+ method: string;
94
+ body?: string;
95
+ headers?: Record<string, string>;
96
+ geoLocation?: string;
97
+ context?: {
98
+ contextAddress: string;
99
+ contextMessage: string;
100
+ };
101
+ useTee?: boolean;
102
+ zkEngine?: "snarkjs" | "stwo";
103
+ },
104
+ secretOptions?: {
105
+ headers?: Record<string, string>;
106
+ responseMatches?: readonly HttpsResponseMatch[];
107
+ responseRedactions?: readonly HttpsResponseRedaction[];
108
+ cookieStr?: string;
109
+ paramValues?: Record<string, string>;
110
+ },
111
+ ): Promise<ReclaimProof | undefined>;
112
+ }
113
+
114
+ export type VerifyProofFn = (
115
+ proof: ReclaimProof,
116
+ config: Parameters<typeof verifyProof>[1],
117
+ ) => Promise<VerifyProofResult>;
118
+
119
+ export interface ConsumerDeliveryProofService {
120
+ proveConsumedHttpsResponse(
121
+ input: ProveConsumedHttpsResponseInput,
122
+ ): Promise<VerifiedConsumedHttpsResponseProof>;
123
+ }
124
+
125
+ export class ResponseProofUnavailableError extends Error {
126
+ constructor(message: string) {
127
+ super(message);
128
+ this.name = "ResponseProofUnavailableError";
129
+ }
130
+ }
131
+
132
+ export class ResponseProofVerificationError extends Error {
133
+ constructor(message: string) {
134
+ super(message);
135
+ this.name = "ResponseProofVerificationError";
136
+ }
137
+ }
138
+
139
+ const reclaimProofInputSchema = z.object({
140
+ url: z.string().url(),
141
+ method: httpMethodSchema.optional(),
142
+ headers: z.record(z.string()).optional(),
143
+ body: z.string().optional(),
144
+ secretHeaders: z.record(z.string()).optional(),
145
+ responseMatches: z
146
+ .array(responseMatchSchema)
147
+ .min(1, "at least one response match is required"),
148
+ responseRedactions: z.array(responseRedactionSchema).optional(),
149
+ cookie: z.string().optional(),
150
+ secretParamValues: z.record(z.string()).optional(),
151
+ geoLocation: z.string().optional(),
152
+ useTee: z.boolean().optional(),
153
+ zkEngine: z.enum(["snarkjs", "stwo"]).optional(),
154
+ delivery: z.object({
155
+ owner: addressSchema,
156
+ streamId: bytes32Schema.optional(),
157
+ operator: addressSchema.optional(),
158
+ serviceRef: bytes32Schema.optional(),
159
+ mandateId: bytes32Schema.optional(),
160
+ }),
161
+ });
162
+
163
+ export class ReclaimConsumerProofService implements ConsumerDeliveryProofService {
164
+ private readonly client: ReclaimClientLike;
165
+ private readonly config: ReclaimProofServiceConfig;
166
+ private readonly verifyProofImpl: VerifyProofFn;
167
+
168
+ constructor(
169
+ config: ReclaimProofServiceConfig,
170
+ options: {
171
+ readonly createClient?: (
172
+ applicationId: string,
173
+ applicationSecret: string,
174
+ logs: boolean,
175
+ ) => ReclaimClientLike;
176
+ readonly verifyProof?: VerifyProofFn;
177
+ } = {},
178
+ ) {
179
+ this.config = {
180
+ ...config,
181
+ logs: config.logs ?? false,
182
+ };
183
+ this.client = (options.createClient ?? defaultReclaimClientFactory)(
184
+ this.config.applicationId,
185
+ this.config.applicationSecret,
186
+ this.config.logs ?? false,
187
+ );
188
+ this.verifyProofImpl = options.verifyProof ?? verifyProof;
189
+ }
190
+
191
+ async proveConsumedHttpsResponse(
192
+ input: ProveConsumedHttpsResponseInput,
193
+ ): Promise<VerifiedConsumedHttpsResponseProof> {
194
+ const parsed = reclaimProofInputSchema.parse(input);
195
+ const method = parsed.method ?? "GET";
196
+ const proof = await this.client
197
+ .zkFetch(
198
+ parsed.url,
199
+ {
200
+ method,
201
+ ...(parsed.body === undefined ? {} : { body: parsed.body }),
202
+ ...(parsed.headers === undefined ? {} : { headers: parsed.headers }),
203
+ ...(parsed.geoLocation === undefined
204
+ ? {}
205
+ : { geoLocation: parsed.geoLocation }),
206
+ context: buildRequestContext(parsed.delivery),
207
+ ...(parsed.useTee === undefined ? {} : { useTee: parsed.useTee }),
208
+ ...(parsed.zkEngine === undefined
209
+ ? {}
210
+ : { zkEngine: parsed.zkEngine }),
211
+ },
212
+ {
213
+ ...(parsed.secretHeaders === undefined
214
+ ? {}
215
+ : { headers: parsed.secretHeaders }),
216
+ responseMatches: parsed.responseMatches,
217
+ ...(parsed.responseRedactions === undefined
218
+ ? {}
219
+ : { responseRedactions: parsed.responseRedactions }),
220
+ ...(parsed.cookie === undefined ? {} : { cookieStr: parsed.cookie }),
221
+ ...(parsed.secretParamValues === undefined
222
+ ? {}
223
+ : { paramValues: parsed.secretParamValues }),
224
+ },
225
+ )
226
+ .catch((error) => {
227
+ throw new ResponseProofUnavailableError(
228
+ `failed to generate zkTLS response proof: ${asErrorMessage(error)}`,
229
+ );
230
+ });
231
+
232
+ if (proof === undefined) {
233
+ throw new ResponseProofUnavailableError(
234
+ "reclaim returned no zkTLS response proof",
235
+ );
236
+ }
237
+
238
+ const verification = await this.verifyProofImpl(proof, {
239
+ ...getProviderHashRequirementsFromSpec({
240
+ requests: [toRequestSpec(parsed, method)],
241
+ }),
242
+ ...(parsed.useTee === true
243
+ ? {
244
+ teeAttestation: {
245
+ appSecret: this.config.applicationSecret,
246
+ },
247
+ }
248
+ : {}),
249
+ });
250
+ if (!verification.isVerified) {
251
+ throw new ResponseProofVerificationError(
252
+ `zkTLS response proof verification failed: ${asErrorMessage(
253
+ verification.error,
254
+ )}`,
255
+ );
256
+ }
257
+
258
+ const trusted = verification.data[0];
259
+ if (trusted === undefined) {
260
+ throw new ResponseProofVerificationError(
261
+ "zkTLS response proof verification returned no trusted data",
262
+ );
263
+ }
264
+
265
+ const request = getHttpProviderClaimParamsFromProof(proof);
266
+ return {
267
+ proof,
268
+ request: {
269
+ url: request.url,
270
+ method: request.method as "GET" | "POST" | "PUT",
271
+ body: request.body === "" ? null : (request.body ?? null),
272
+ responseMatches: request.responseMatches.map((match) => ({
273
+ value: match.value,
274
+ type: match.type,
275
+ invert: match.invert,
276
+ isOptional: match.isOptional,
277
+ })),
278
+ responseRedactions: request.responseRedactions.map((redaction) => ({
279
+ regex: redaction.regex,
280
+ jsonPath: redaction.jsonPath,
281
+ xPath: redaction.xPath,
282
+ hash: redaction.hash,
283
+ })),
284
+ },
285
+ verification: {
286
+ context: trusted.context,
287
+ extractedParameters: trusted.extractedParameters,
288
+ publicData: verification.publicData[0] ?? null,
289
+ isTeeAttestationVerified:
290
+ verification.isTeeAttestationVerified ?? false,
291
+ isAttestorTeeAttestationVerified:
292
+ verification.isAttestorTeeAttestationVerified ?? false,
293
+ },
294
+ };
295
+ }
296
+ }
297
+
298
+ export function parseReclaimProofEnv(
299
+ env: NodeJS.ProcessEnv = process.env,
300
+ ): ParsedReclaimProofEnv | null {
301
+ const applicationId = env.RECLAIM_APP_ID;
302
+ const applicationSecret = env.RECLAIM_APP_SECRET;
303
+ if (applicationId === undefined && applicationSecret === undefined) {
304
+ return null;
305
+ }
306
+ if (
307
+ applicationId === undefined ||
308
+ applicationId.trim() === "" ||
309
+ applicationSecret === undefined ||
310
+ applicationSecret.trim() === ""
311
+ ) {
312
+ throw new Error("RECLAIM_APP_ID and RECLAIM_APP_SECRET must both be set");
313
+ }
314
+
315
+ return {
316
+ applicationId,
317
+ applicationSecret,
318
+ logs: env.METRIK_AGENT_RECLAIM_LOGS === "true",
319
+ };
320
+ }
321
+
322
+ export function createReclaimConsumerProofServiceFromEnv(
323
+ env: NodeJS.ProcessEnv = process.env,
324
+ ): ReclaimConsumerProofService | null {
325
+ const parsed = parseReclaimProofEnv(env);
326
+ if (parsed === null) {
327
+ return null;
328
+ }
329
+ return new ReclaimConsumerProofService(parsed);
330
+ }
331
+
332
+ function defaultReclaimClientFactory(
333
+ applicationId: string,
334
+ applicationSecret: string,
335
+ logs: boolean,
336
+ ): ReclaimClientLike {
337
+ return new LazyReclaimClient(applicationId, applicationSecret, logs);
338
+ }
339
+
340
+ function buildRequestContext(
341
+ binding: z.infer<typeof reclaimProofInputSchema>["delivery"],
342
+ ): {
343
+ contextAddress: string;
344
+ contextMessage: string;
345
+ } {
346
+ return {
347
+ contextAddress: binding.owner,
348
+ contextMessage: JSON.stringify({
349
+ kind: "metrik-l4-http-response/v1",
350
+ streamId: binding.streamId ?? null,
351
+ operator: binding.operator ?? null,
352
+ serviceRef: binding.serviceRef ?? null,
353
+ mandateId: binding.mandateId ?? null,
354
+ }),
355
+ };
356
+ }
357
+
358
+ function toRequestSpec(
359
+ input: z.infer<typeof reclaimProofInputSchema>,
360
+ method: "GET" | "POST" | "PUT",
361
+ ): RequestSpec {
362
+ return {
363
+ url: input.url,
364
+ urlType: "full",
365
+ method,
366
+ bodySniff: {
367
+ enabled: input.body !== undefined,
368
+ template: input.body ?? "",
369
+ },
370
+ responseMatches: input.responseMatches.map((match) => ({
371
+ value: match.value,
372
+ type: match.type,
373
+ invert: match.invert,
374
+ isOptional: match.isOptional,
375
+ })),
376
+ responseRedactions: (input.responseRedactions ?? []).map((redaction) => ({
377
+ regex: redaction.regex ?? "",
378
+ jsonPath: redaction.jsonPath ?? "",
379
+ xPath: redaction.xPath ?? "",
380
+ ...(redaction.hash === undefined ? {} : { hash: redaction.hash }),
381
+ })),
382
+ required: true,
383
+ multiple: false,
384
+ };
385
+ }
386
+
387
+ function asErrorMessage(error: unknown): string {
388
+ return error instanceof Error ? error.message : String(error);
389
+ }
390
+
391
+ class LazyReclaimClient implements ReclaimClientLike {
392
+ private clientPromise?: Promise<ReclaimClientLike>;
393
+
394
+ constructor(
395
+ private readonly applicationId: string,
396
+ private readonly applicationSecret: string,
397
+ private readonly logs: boolean,
398
+ ) {}
399
+
400
+ async zkFetch(
401
+ url: string,
402
+ options?: Parameters<ReclaimClientLike["zkFetch"]>[1],
403
+ secretOptions?: Parameters<ReclaimClientLike["zkFetch"]>[2],
404
+ ): Promise<ReclaimProof | undefined> {
405
+ const client = await this.getClient();
406
+ return await client.zkFetch(url, options, secretOptions);
407
+ }
408
+
409
+ private async getClient(): Promise<ReclaimClientLike> {
410
+ if (this.clientPromise === undefined) {
411
+ this.clientPromise = import("@reclaimprotocol/zk-fetch").then(
412
+ (module) => {
413
+ const client = new module.ReclaimClient(
414
+ this.applicationId,
415
+ this.applicationSecret,
416
+ this.logs,
417
+ );
418
+ return client as ReclaimClientLike;
419
+ },
420
+ );
421
+ }
422
+ return await this.clientPromise;
423
+ }
424
+ }