@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,206 @@
1
+ import { DynamicStructuredTool } from "@langchain/core/tools";
2
+ import { isAddress, isHex } from "viem";
3
+ import { z } from "zod/v3";
4
+ import { discoverServices as defaultDiscoverServices, } from "../discovery/registry.js";
5
+ import { checkMandate } from "../mandates/mandate.js";
6
+ const addressSchema = z
7
+ .string()
8
+ .refine((value) => isAddress(value), "must be an EVM address");
9
+ const bytes32Schema = z
10
+ .string()
11
+ .refine((value) => isHex(value, { strict: true }) && value.length === 66, "must be bytes32 hex");
12
+ const decimalStringSchema = z.preprocess((value) => typeof value === "bigint" || typeof value === "number"
13
+ ? value.toString()
14
+ : value, z.string().regex(/^(0|[1-9]\d*)$/, "must be a base-10 integer string"));
15
+ const spendMandateInputSchema = z.object({
16
+ maxPerStreamUsdc: decimalStringSchema,
17
+ maxTotalUsdc: decimalStringSchema,
18
+ maxRatePerSecondUsdc: decimalStringSchema,
19
+ maxDurationSeconds: z.number().int().positive(),
20
+ allowedOperators: z.array(addressSchema).optional(),
21
+ expiresAt: z.number().int().positive(),
22
+ });
23
+ const signedSpendMandateInputSchema = z.object({
24
+ mandateId: bytes32Schema,
25
+ owner: addressSchema,
26
+ chainId: z.number().int().positive(),
27
+ issuedAt: z.number().int().nonnegative(),
28
+ mandate: spendMandateInputSchema,
29
+ signature: z
30
+ .string()
31
+ .refine((value) => isHex(value, { strict: true }) && value.length === 132, "must be a 65-byte signature"),
32
+ });
33
+ const hireToolSchema = z.object({
34
+ operator: addressSchema,
35
+ serviceRef: bytes32Schema,
36
+ budgetUsdc: decimalStringSchema,
37
+ ratePerSecondUsdc: decimalStringSchema,
38
+ maxDurationSeconds: z.number().int().positive(),
39
+ signedMandate: signedSpendMandateInputSchema,
40
+ });
41
+ const streamStatusToolSchema = z.object({
42
+ streamId: bytes32Schema,
43
+ });
44
+ const reclaimToolSchema = z.object({
45
+ streamId: bytes32Schema,
46
+ closeFirst: z.boolean().optional(),
47
+ signedMandate: signedSpendMandateInputSchema,
48
+ });
49
+ const closeToolSchema = z.object({
50
+ streamId: bytes32Schema,
51
+ signedMandate: signedSpendMandateInputSchema,
52
+ });
53
+ const discoverToolSchema = z.object({
54
+ category: z.string().min(1).optional(),
55
+ limit: z.number().int().positive().optional(),
56
+ });
57
+ const DEFAULT_MANDATE_STATE_RESOLVER = {
58
+ getSpentSoFarUsdc: async () => 0n,
59
+ getRevokedMandateIds: async () => [],
60
+ };
61
+ export function createLangChainVerifiedStreamTools(options) {
62
+ const resolver = {
63
+ ...DEFAULT_MANDATE_STATE_RESOLVER,
64
+ ...options.mandateStateResolver,
65
+ };
66
+ const now = options.now ?? (() => Math.floor(Date.now() / 1000));
67
+ const discoverImpl = options.discoverServices ?? defaultDiscoverServices;
68
+ const discover = new DynamicStructuredTool({
69
+ name: "discover_services",
70
+ description: "Discover verified third-party services on the Metrik marketplace. Returns operator + serviceRef + endpoint for listings whose operator signature is verified — the entry point before hire_verified_service.",
71
+ schema: discoverToolSchema,
72
+ func: async (input) => {
73
+ const listings = await discoverImpl({
74
+ ...(input.category === undefined ? {} : { category: input.category }),
75
+ ...(input.limit === undefined ? {} : { limit: input.limit }),
76
+ });
77
+ return { services: listings };
78
+ },
79
+ });
80
+ const hire = new DynamicStructuredTool({
81
+ name: "hire_verified_service",
82
+ description: "Open a verified payment stream with a signed mandate and hard budget limits.",
83
+ schema: hireToolSchema,
84
+ func: async (input) => {
85
+ const signedMandate = parseSignedMandateInput(input.signedMandate);
86
+ const nowSeconds = now();
87
+ const spentSoFarUsdc = await resolver.getSpentSoFarUsdc(signedMandate.owner);
88
+ const revokedMandateIds = await resolver.getRevokedMandateIds(signedMandate.owner);
89
+ const decision = await checkMandate(signedMandate, {
90
+ operator: input.operator,
91
+ budgetUsdc: BigInt(input.budgetUsdc),
92
+ ratePerSecondUsdc: BigInt(input.ratePerSecondUsdc),
93
+ maxDurationSeconds: input.maxDurationSeconds,
94
+ }, spentSoFarUsdc, {
95
+ nowSeconds,
96
+ revokedMandateIds,
97
+ });
98
+ if (!decision.allowed) {
99
+ throw new Error(`mandate denied: ${decision.reason ?? "unknown"}`);
100
+ }
101
+ const result = await options.agentClient.openVerifiedStream({
102
+ operator: input.operator,
103
+ serviceRef: input.serviceRef,
104
+ budgetUsdc: BigInt(input.budgetUsdc),
105
+ ratePerSecondUsdc: BigInt(input.ratePerSecondUsdc),
106
+ maxDurationSeconds: input.maxDurationSeconds,
107
+ signedMandate,
108
+ spentSoFarUsdc,
109
+ nowSeconds,
110
+ revokedMandateIds,
111
+ });
112
+ return {
113
+ streamId: result.streamId,
114
+ txHash: result.txHash,
115
+ approveTxHash: result.approveTxHash,
116
+ handle: result.handle,
117
+ };
118
+ },
119
+ });
120
+ const status = new DynamicStructuredTool({
121
+ name: "check_stream_status",
122
+ description: "Read the current stream status and whether the agent should stop work.",
123
+ schema: streamStatusToolSchema,
124
+ func: async ({ streamId }) => {
125
+ const result = await options.agentClient.getStreamStatus(streamId);
126
+ return serializeStreamStatus(result, streamId);
127
+ },
128
+ });
129
+ const reclaim = new DynamicStructuredTool({
130
+ name: "reclaim_unspent",
131
+ description: "Close and/or reclaim an existing stream under the same signed mandate controls.",
132
+ schema: reclaimToolSchema,
133
+ func: async (input) => {
134
+ const signedMandate = parseSignedMandateInput(input.signedMandate);
135
+ const nowSeconds = now();
136
+ const spentSoFarUsdc = await resolver.getSpentSoFarUsdc(signedMandate.owner);
137
+ const revokedMandateIds = await resolver.getRevokedMandateIds(signedMandate.owner);
138
+ const result = await options.agentClient.reclaimStream({
139
+ streamId: input.streamId,
140
+ signedMandate,
141
+ spentSoFarUsdc,
142
+ nowSeconds,
143
+ revokedMandateIds,
144
+ ...(input.closeFirst === undefined
145
+ ? {}
146
+ : { closeFirst: input.closeFirst }),
147
+ });
148
+ return {
149
+ closeTxHash: result.closeResult?.txHash ?? null,
150
+ reclaimTxHash: result.reclaimResult.txHash,
151
+ };
152
+ },
153
+ });
154
+ const close = new DynamicStructuredTool({
155
+ name: "close_stream",
156
+ description: "Close an existing stream, finalizing accrual and halting further payment, under the same signed mandate controls.",
157
+ schema: closeToolSchema,
158
+ func: async (input) => {
159
+ const signedMandate = parseSignedMandateInput(input.signedMandate);
160
+ const nowSeconds = now();
161
+ const spentSoFarUsdc = await resolver.getSpentSoFarUsdc(signedMandate.owner);
162
+ const revokedMandateIds = await resolver.getRevokedMandateIds(signedMandate.owner);
163
+ const result = await options.agentClient.closeStream({
164
+ streamId: input.streamId,
165
+ signedMandate,
166
+ spentSoFarUsdc,
167
+ nowSeconds,
168
+ revokedMandateIds,
169
+ });
170
+ return { closeTxHash: result.txHash };
171
+ },
172
+ });
173
+ return { discover, hire, status, reclaim, close };
174
+ }
175
+ function parseSignedMandateInput(value) {
176
+ const parsed = signedSpendMandateInputSchema.parse(value);
177
+ return {
178
+ ...parsed,
179
+ mandateId: parsed.mandateId,
180
+ owner: parsed.owner,
181
+ signature: parsed.signature,
182
+ mandate: {
183
+ ...parsed.mandate,
184
+ maxPerStreamUsdc: BigInt(parsed.mandate.maxPerStreamUsdc),
185
+ maxTotalUsdc: BigInt(parsed.mandate.maxTotalUsdc),
186
+ maxRatePerSecondUsdc: BigInt(parsed.mandate.maxRatePerSecondUsdc),
187
+ },
188
+ };
189
+ }
190
+ function serializeStreamStatus(result, streamId) {
191
+ return {
192
+ streamId,
193
+ shouldStop: result.stream.status !== "active",
194
+ stream: {
195
+ ...result.stream,
196
+ deposit: result.stream.deposit.toString(),
197
+ ratePerSecond: result.stream.ratePerSecond.toString(),
198
+ accrued: result.stream.accrued.toString(),
199
+ claimed: result.stream.claimed.toString(),
200
+ lastSequence: result.stream.lastSequence.toString(),
201
+ },
202
+ claimable: result.claimable.toString(),
203
+ reclaimable: result.reclaimable.toString(),
204
+ };
205
+ }
206
+ //# sourceMappingURL=langchain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"langchain.js","sourceRoot":"","sources":["../../src/frameworks/langchain.ts"],"names":[],"mappings":"AA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,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE;KAC3C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ export { createSpendMandateTypedData, spendMandateSchema, signedSpendMandateSchema, checkMandate, checkMandatePolicy, verifySignedMandate, verifyMandateOwnerSignature, spendMandateDomain, spendMandateTypedData, type SpendMandate, type SignedSpendMandate, type HireRequest, type MandateDecision, type MandateVerificationContext, } from "./mandates/mandate.js";
2
+ export { DEFAULT_SERVER_MANDATE_TTL_SECONDS, ServerMandateConfigError, parseServerMandateCapsEnv, signServerMandate, type ServerMandateCaps, type SignServerMandateOptions, } from "./mandates/env.js";
3
+ export { VerifiedStreamX402Facilitator, DeliveryProofUnavailableError, X402PayloadError, SettlementTargetMismatchError, X402_SCHEME, encodeX402PayloadHeader, parseX402ChallengeJson, parseX402PayloadHeader, verifiedStreamRequirementsSchema, x402StreamChallengeSchema, x402OpenPayloadSchema, type X402ConsumedHttpsResponseProofInput, type X402Facilitator, type X402OpenPayload, type X402StreamChallenge, type VerifiedStreamFacilitatorOptions, type VerifiedStreamRequirements, } from "./x402/facilitator.js";
4
+ export { DEFAULT_METRIK_REGISTRY_URL, discoverServices, type DiscoverServicesOptions, type ServiceListing, } from "./discovery/registry.js";
5
+ export { METRIK_MCP_TOOLS, STREAMPROOF_MCP_TOOLS, FileStreamRegistry, InMemoryStreamRegistry, createVerifiedStreamMcpServer, createVerifiedStreamMcpServerFromEnv, createVerifiedStreamMcpServerOptionsFromEnv, parseMetrikAgentEnv, startVerifiedStreamMcpServerStdio, type McpToolSpec, type ParsedMetrikAgentEnv, type StoredStreamRecord, type StreamRegistry, type VerifiedStreamMcpClient, type VerifiedStreamMcpServerOptions, type VerifiedStreamMcpServerRuntime, } from "./mcp/server.js";
6
+ export { StaticTenantResolver, createHostedMcpHttpServer, createHostedMcpTenants, parseHostedMcpServerConfig, startHostedMcpHttpServerFromEnv, type HostedMcpHttpServer, type HostedMcpHttpServerOptions, type HostedMcpServerConfig, type HostedMcpTenant, type HostedMcpTenantConfig, type TenantResolver, } from "./mcp/http.js";
7
+ export { MandateDeniedError, VerifiedStreamAgentClient, type AgentSdkClient, type AgentSdkClientFactory, type MandateAuthorizedStreamActionInput, type OpenVerifiedStreamInput, type ReclaimAuthorizedStreamInput, type ReclaimVerifiedStreamOptions, type ReclaimVerifiedStreamResult, type StreamStatusView, type VerifiedStreamAgentOpener, } from "./sdk/client.js";
8
+ export { AgentWalletConfigError, createWalletBackedAgentClient, parseAgentWalletEnv, resolveAgentWallet, type AgentWalletInput, type CdpClientLike, type CdpWalletConfig, type ResolvedAgentWallet, type WalletBackedAgentClient, } from "./wallet/provider.js";
9
+ export { ReclaimConsumerProofService, ResponseProofUnavailableError, ResponseProofVerificationError, createReclaimConsumerProofServiceFromEnv, parseReclaimProofEnv, type ConsumerDeliveryProofService, type DeliveryProofBinding, type HttpsResponseMatch, type HttpsResponseRedaction, type ParsedReclaimProofEnv, type ProveConsumedHttpsResponseInput, type ReclaimClientLike, type ReclaimProof, type ReclaimProofServiceConfig, type VerifiedConsumedHttpsResponseProof, type VerifyProofFn, } from "./zktls/reclaim.js";
10
+ export { createLangChainVerifiedStreamTools, type LangChainMandateStateResolver, type LangChainVerifiedStreamClient, type LangChainVerifiedStreamTools, type LangChainVerifiedStreamToolsOptions, } from "./frameworks/langchain.js";
11
+ export { METRIK_ELIZA_ACTION_NAMES, METRIK_ELIZA_SETTLEMENT_CHAIN_ID, createMetrikElizaPlugin, createMetrikElizaContent, metrikElizaPlugin, createElizaVerifiedStreamContent, createElizaVerifiedStreamPlugin, type MetrikElizaActionInputs, type MetrikElizaActionName, type MetrikElizaClient, type MetrikElizaMandateStateResolver, type MetrikElizaPluginOptions, } from "./frameworks/eliza.js";
12
+ export { CREWAI_VERIFIED_STREAM_TOOL_NAMES, createCrewAiVerifiedStreamMcpConfig, renderCrewAiVerifiedStreamPythonExample, type CrewAiVerifiedStreamMcpConfig, type CrewAiVerifiedStreamMcpConfigOptions, } from "./frameworks/crewai.js";
13
+ export { METRIK_BASE_SEPOLIA_CHAIN_ID, MetrikActionProvider, MetrikActionProviderConfigError, metrikActionProvider, createMetrikAgentKit, discoverServicesSchema, hireVerifiedServiceSchema, checkStreamStatusSchema, reclaimUnspentSchema, closeStreamSchema, type CreateMetrikAgentKitOptions, type MetrikActionProviderConfig, type MetrikAgentKitClient, type MetrikMandateStateResolver, } from "./frameworks/agentkit.js";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,wBAAwB,EACxB,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,0BAA0B,GAChC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kCAAkC,EAClC,wBAAwB,EACxB,yBAAyB,EACzB,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,GAC9B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,6BAA6B,EAC7B,6BAA6B,EAC7B,gBAAgB,EAChB,6BAA6B,EAC7B,WAAW,EACX,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,gCAAgC,EAChC,yBAAyB,EACzB,qBAAqB,EACrB,KAAK,mCAAmC,EACxC,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,gCAAgC,EACrC,KAAK,0BAA0B,GAChC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,KAAK,uBAAuB,EAC5B,KAAK,cAAc,GACpB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,gBAAgB,EAChB,q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C9B,KAAK,kCAAkC,EACvC,KAAK,aAAa,GACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,kCAAkC,EAClC,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EAClC,KAAK,4BAA4B,EACjC,KAAK,mCAAmC,GACzC,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EAChC,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,EAEjB,gCAAgC,EAChC,+BAA+B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,+BAA+B,EACpC,KAAK,wBAAwB,GAC9B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,iCAAiC,EACjC,mCAAmC,EACnC,uCAAuC,EACvC,KAAK,6BAA6B,EAClC,KAAK,oCAAoC,GAC1C,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,4BAA4B,EAC5B,oBAAoB,EACpB,+BAA+B,EAC/B,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EACzB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAC/B,KAAK,oBAAoB,EACzB,KAAK,0BAA0B,GAChC,MAAM,0BAA0B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ export { createSpendMandateTypedData, spendMandateSchema, signedSpendMandateSchema, checkMandate, checkMandatePolicy, verifySignedMandate, verifyMandateOwnerSignature, spendMandateDomain, spendMandateTypedData, } from "./mandates/mandate.js";
2
+ export { DEFAULT_SERVER_MANDATE_TTL_SECONDS, ServerMandateConfigError, parseServerMandateCapsEnv, signServerMandate, } from "./mandates/env.js";
3
+ export { VerifiedStreamX402Facilitator, DeliveryProofUnavailableError, X402PayloadError, SettlementTargetMismatchError, X402_SCHEME, encodeX402PayloadHeader, parseX402ChallengeJson, parseX402PayloadHeader, verifiedStreamRequirementsSchema, x402StreamChallengeSchema, x402OpenPayloadSchema, } from "./x402/facilitator.js";
4
+ export { DEFAULT_METRIK_REGISTRY_URL, discoverServices, } from "./discovery/registry.js";
5
+ export { METRIK_MCP_TOOLS, STREAMPROOF_MCP_TOOLS, FileStreamRegistry, InMemoryStreamRegistry, createVerifiedStreamMcpServer, createVerifiedStreamMcpServerFromEnv, createVerifiedStreamMcpServerOptionsFromEnv, parseMetrikAgentEnv, startVerifiedStreamMcpServerStdio, } from "./mcp/server.js";
6
+ export { StaticTenantResolver, createHostedMcpHttpServer, createHostedMcpTenants, parseHostedMcpServerConfig, startHostedMcpHttpServerFromEnv, } from "./mcp/http.js";
7
+ export { MandateDeniedError, VerifiedStreamAgentClient, } from "./sdk/client.js";
8
+ export { AgentWalletConfigError, createWalletBackedAgentClient, parseAgentWalletEnv, resolveAgentWallet, } from "./wallet/provider.js";
9
+ export { ReclaimConsumerProofService, ResponseProofUnavailableError, ResponseProofVerificationError, createReclaimConsumerProofServiceFromEnv, parseReclaimProofEnv, } from "./zktls/reclaim.js";
10
+ export { createLangChainVerifiedStreamTools, } from "./frameworks/langchain.js";
11
+ export { METRIK_ELIZA_ACTION_NAMES, METRIK_ELIZA_SETTLEMENT_CHAIN_ID, createMetrikElizaPlugin, createMetrikElizaContent, metrikElizaPlugin,
12
+ // Deprecated aliases retained for backward compatibility.
13
+ createElizaVerifiedStreamContent, createElizaVerifiedStreamPlugin, } from "./frameworks/eliza.js";
14
+ export { CREWAI_VERIFIED_STREAM_TOOL_NAMES, createCrewAiVerifiedStreamMcpConfig, renderCrewAiVerifiedStreamPythonExample, } from "./frameworks/crewai.js";
15
+ export { METRIK_BASE_SEPOLIA_CHAIN_ID, MetrikActionProvider, MetrikActionProviderConfigError, metrikActionProvider, createMetrikAgentKit, discoverServicesSchema, hireVerifiedServiceSchema, checkStreamStatusSchema, reclaimUnspentSchema, closeStreamSchema, } from "./frameworks/agentkit.js";
16
+ //# sourceMappingURL=index.js.map
@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AEnC,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EAChC,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB;AACjB,0DAA0D;AAC1D,gCAAgC,EAChC,+BAA+B,GAMhC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,iCAAiC,EACjC,mCAAmC,EACnC,uCAAuC,GAGxC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,4BAA4B,EAC5B,oBAAoB,EACpB,+BAA+B,EAC/B,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EACzB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,GAKlB,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { type Account } from "viem";
2
+ import { type SignedSpendMandate } from "./mandate.js";
3
+ /**
4
+ * Server-side spend-mandate provisioning.
5
+ *
6
+ * The MCP/x402 fund-moving surface is driven by autonomous callers (an LLM over
7
+ * MCP, a paying agent over x402) that CANNOT produce an EIP-712 signature. The
8
+ * spend mandate is therefore NOT a per-call argument — it is configured once, at
9
+ * the server's construction, exactly like the AgentKit action provider's
10
+ * `signedMandate`. The deploying operator declares the spend caps via env and the
11
+ * server self-signs the mandate from its OWN wallet (the wallet that opens and
12
+ * funds the streams is the mandate owner — signing your own spend ceiling is the
13
+ * correct trust relationship).
14
+ *
15
+ * Fail-closed: a fund-moving server with NO configured caps refuses to sign a
16
+ * mandate. There is no implicit "unbounded" mandate.
17
+ */
18
+ export declare class ServerMandateConfigError extends Error {
19
+ constructor(message: string);
20
+ }
21
+ /** Default mandate lifetime when `METRIK_AGENT_MANDATE_TTL_SECONDS` is unset. */
22
+ export declare const DEFAULT_SERVER_MANDATE_TTL_SECONDS: number;
23
+ export interface ServerMandateCaps {
24
+ readonly maxPerStreamUsdc: bigint;
25
+ readonly maxTotalUsdc: bigint;
26
+ readonly maxRatePerSecondUsdc: bigint;
27
+ readonly maxDurationSeconds: number;
28
+ readonly allowedOperators: readonly `0x${string}`[];
29
+ readonly ttlSeconds: number;
30
+ }
31
+ /**
32
+ * Parses the server mandate caps from env. Returns `null` when NONE of the
33
+ * `METRIK_AGENT_MANDATE_*` variables are set (so a caller can decide whether a
34
+ * mandate is required in that deployment). Throws {@link ServerMandateConfigError}
35
+ * when the caps are partially configured or malformed — fail closed, never
36
+ * silently fall back to an unbounded mandate.
37
+ */
38
+ export declare function parseServerMandateCapsEnv(env?: NodeJS.ProcessEnv): ServerMandateCaps | null;
39
+ export interface SignServerMandateOptions {
40
+ readonly chainId: number;
41
+ /** Unix seconds the mandate is issued at. Defaults to the wall clock. */
42
+ readonly nowSeconds?: number;
43
+ }
44
+ /**
45
+ * Self-signs a spend mandate from the server's own wallet, bounded by the
46
+ * configured caps. The signing account MUST be the account that will fund the
47
+ * streams (its address becomes the mandate `owner`, which every downstream
48
+ * `checkMandate` recovers the signature against).
49
+ */
50
+ export declare function signServerMandate(account: Account, caps: ServerMandateCaps, options: SignServerMandateOptions): Promise<SignedSpendMandate>;
51
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/mandates/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,OAAO,EACb,MAAM,MAAM,CAAC;AAGd,OAAO,EAGL,KAAK,kBAAkB,EAExB,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;GAcG;AAEH,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAI5B;AAmBD,iFAAiF;AACjF,eAAO,MAAM,kCAAkC,QAAe,CAAC;AAE/D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,gBAAgB,EAAE,SAAS,KAAK,MAAM,EAAE,EAAE,CAAC;IACpD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,iBAAiB,GAAG,IAAI,CA4D1B;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AA2BD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,kBAAkB,CAAC,CAyC7B"}
@@ -0,0 +1,148 @@
1
+ import { getAddress, isAddress, keccak256, stringToHex, } from "viem";
2
+ import { z } from "zod";
3
+ import { createSpendMandateTypedData, signedSpendMandateSchema, } from "./mandate.js";
4
+ /**
5
+ * Server-side spend-mandate provisioning.
6
+ *
7
+ * The MCP/x402 fund-moving surface is driven by autonomous callers (an LLM over
8
+ * MCP, a paying agent over x402) that CANNOT produce an EIP-712 signature. The
9
+ * spend mandate is therefore NOT a per-call argument — it is configured once, at
10
+ * the server's construction, exactly like the AgentKit action provider's
11
+ * `signedMandate`. The deploying operator declares the spend caps via env and the
12
+ * server self-signs the mandate from its OWN wallet (the wallet that opens and
13
+ * funds the streams is the mandate owner — signing your own spend ceiling is the
14
+ * correct trust relationship).
15
+ *
16
+ * Fail-closed: a fund-moving server with NO configured caps refuses to sign a
17
+ * mandate. There is no implicit "unbounded" mandate.
18
+ */
19
+ export class ServerMandateConfigError extends Error {
20
+ constructor(message) {
21
+ super(message);
22
+ this.name = "ServerMandateConfigError";
23
+ }
24
+ }
25
+ const decimalStringSchema = z
26
+ .string()
27
+ .regex(/^(0|[1-9]\d*)$/, "must be a base-10 integer string (USDC atomic units, 6 decimals)");
28
+ const positiveIntSchema = z.coerce.number().int().positive();
29
+ const mandateEnvSchema = z.object({
30
+ METRIK_AGENT_MANDATE_MAX_PER_STREAM_USDC: decimalStringSchema,
31
+ METRIK_AGENT_MANDATE_MAX_TOTAL_USDC: decimalStringSchema,
32
+ METRIK_AGENT_MANDATE_MAX_RATE_PER_SECOND_USDC: decimalStringSchema,
33
+ METRIK_AGENT_MANDATE_MAX_DURATION_SECONDS: positiveIntSchema,
34
+ METRIK_AGENT_MANDATE_ALLOWED_OPERATORS: z.string().optional(),
35
+ METRIK_AGENT_MANDATE_TTL_SECONDS: positiveIntSchema.optional(),
36
+ });
37
+ /** Default mandate lifetime when `METRIK_AGENT_MANDATE_TTL_SECONDS` is unset. */
38
+ export const DEFAULT_SERVER_MANDATE_TTL_SECONDS = 24 * 60 * 60;
39
+ /**
40
+ * Parses the server mandate caps from env. Returns `null` when NONE of the
41
+ * `METRIK_AGENT_MANDATE_*` variables are set (so a caller can decide whether a
42
+ * mandate is required in that deployment). Throws {@link ServerMandateConfigError}
43
+ * when the caps are partially configured or malformed — fail closed, never
44
+ * silently fall back to an unbounded mandate.
45
+ */
46
+ export function parseServerMandateCapsEnv(env = process.env) {
47
+ const anySet = [
48
+ env.METRIK_AGENT_MANDATE_MAX_PER_STREAM_USDC,
49
+ env.METRIK_AGENT_MANDATE_MAX_TOTAL_USDC,
50
+ env.METRIK_AGENT_MANDATE_MAX_RATE_PER_SECOND_USDC,
51
+ env.METRIK_AGENT_MANDATE_MAX_DURATION_SECONDS,
52
+ env.METRIK_AGENT_MANDATE_ALLOWED_OPERATORS,
53
+ env.METRIK_AGENT_MANDATE_TTL_SECONDS,
54
+ ].some((value) => value !== undefined);
55
+ if (!anySet) {
56
+ return null;
57
+ }
58
+ const parsed = mandateEnvSchema.safeParse(env);
59
+ if (!parsed.success) {
60
+ throw new ServerMandateConfigError(`invalid server mandate configuration: ${parsed.error.issues
61
+ .map((issue) => `${issue.path.join(".")} ${issue.message}`)
62
+ .join("; ")}`);
63
+ }
64
+ const allowedOperators = (parsed.data.METRIK_AGENT_MANDATE_ALLOWED_OPERATORS ?? "")
65
+ .split(",")
66
+ .map((entry) => entry.trim())
67
+ .filter((entry) => entry.length > 0);
68
+ for (const operator of allowedOperators) {
69
+ if (!isAddress(operator)) {
70
+ throw new ServerMandateConfigError(`METRIK_AGENT_MANDATE_ALLOWED_OPERATORS contains a non-address entry: ${operator}`);
71
+ }
72
+ }
73
+ const maxTotalUsdc = BigInt(parsed.data.METRIK_AGENT_MANDATE_MAX_TOTAL_USDC);
74
+ const maxPerStreamUsdc = BigInt(parsed.data.METRIK_AGENT_MANDATE_MAX_PER_STREAM_USDC);
75
+ if (maxPerStreamUsdc > maxTotalUsdc) {
76
+ throw new ServerMandateConfigError("METRIK_AGENT_MANDATE_MAX_PER_STREAM_USDC cannot exceed METRIK_AGENT_MANDATE_MAX_TOTAL_USDC");
77
+ }
78
+ return {
79
+ maxPerStreamUsdc,
80
+ maxTotalUsdc,
81
+ maxRatePerSecondUsdc: BigInt(parsed.data.METRIK_AGENT_MANDATE_MAX_RATE_PER_SECOND_USDC),
82
+ maxDurationSeconds: parsed.data.METRIK_AGENT_MANDATE_MAX_DURATION_SECONDS,
83
+ allowedOperators: allowedOperators.map((operator) => getAddress(operator)),
84
+ ttlSeconds: parsed.data.METRIK_AGENT_MANDATE_TTL_SECONDS ??
85
+ DEFAULT_SERVER_MANDATE_TTL_SECONDS,
86
+ };
87
+ }
88
+ /**
89
+ * Deterministic mandate id derived from the owner, caps, chain, and issuance
90
+ * time. Stable for identical inputs within the same second, so a restarted
91
+ * server with the same config and a wired revocation store can be revoked by id.
92
+ */
93
+ function deriveMandateId(owner, mandate, chainId, issuedAt) {
94
+ const canonical = [
95
+ owner.toLowerCase(),
96
+ chainId,
97
+ issuedAt,
98
+ mandate.expiresAt,
99
+ mandate.maxPerStreamUsdc.toString(),
100
+ mandate.maxTotalUsdc.toString(),
101
+ mandate.maxRatePerSecondUsdc.toString(),
102
+ mandate.maxDurationSeconds,
103
+ (mandate.allowedOperators ?? []).map((op) => op.toLowerCase()).join(","),
104
+ ].join("|");
105
+ return keccak256(stringToHex(canonical));
106
+ }
107
+ /**
108
+ * Self-signs a spend mandate from the server's own wallet, bounded by the
109
+ * configured caps. The signing account MUST be the account that will fund the
110
+ * streams (its address becomes the mandate `owner`, which every downstream
111
+ * `checkMandate` recovers the signature against).
112
+ */
113
+ export async function signServerMandate(account, caps, options) {
114
+ if (account.signTypedData === undefined) {
115
+ throw new ServerMandateConfigError("signing account does not support signTypedData; cannot self-sign a server mandate");
116
+ }
117
+ const owner = getAddress(account.address);
118
+ const issuedAt = options.nowSeconds ?? Math.floor(Date.now() / 1000);
119
+ const expiresAt = issuedAt + caps.ttlSeconds;
120
+ const mandate = {
121
+ maxPerStreamUsdc: caps.maxPerStreamUsdc,
122
+ maxTotalUsdc: caps.maxTotalUsdc,
123
+ maxRatePerSecondUsdc: caps.maxRatePerSecondUsdc,
124
+ maxDurationSeconds: caps.maxDurationSeconds,
125
+ ...(caps.allowedOperators.length > 0
126
+ ? { allowedOperators: [...caps.allowedOperators] }
127
+ : {}),
128
+ expiresAt,
129
+ };
130
+ const mandateId = deriveMandateId(owner, mandate, options.chainId, issuedAt);
131
+ const typedData = createSpendMandateTypedData({
132
+ mandateId,
133
+ owner,
134
+ chainId: options.chainId,
135
+ issuedAt,
136
+ mandate,
137
+ });
138
+ const signature = await account.signTypedData(typedData);
139
+ return signedSpendMandateSchema.parse({
140
+ mandateId,
141
+ owner,
142
+ chainId: options.chainId,
143
+ issuedAt,
144
+ mandate,
145
+ signature,
146
+ });
147
+ }
148
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/mandates/env.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,GAEZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,CAAC,EAAE,MAAM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