@envarai/envarpay 0.2.0-alpha.2 → 0.2.0-alpha.20

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 (85) hide show
  1. package/README.md +18 -56
  2. package/dist/commerce/agent-setup.d.ts +19 -0
  3. package/dist/commerce/agent-setup.js +210 -0
  4. package/dist/commerce/alerts.d.ts +27 -0
  5. package/dist/commerce/alerts.js +71 -0
  6. package/dist/commerce/card.js +3 -3
  7. package/dist/commerce/cli.js +91 -119
  8. package/dist/commerce/config.d.ts +3 -2
  9. package/dist/commerce/config.js +19 -77
  10. package/dist/commerce/configure.d.ts +2 -0
  11. package/dist/commerce/configure.js +78 -0
  12. package/dist/commerce/discovery.d.ts +20 -0
  13. package/dist/commerce/discovery.js +162 -0
  14. package/dist/commerce/envar-balance.d.ts +25 -0
  15. package/dist/commerce/envar-balance.js +65 -0
  16. package/dist/commerce/envar-runtime.d.ts +3 -1
  17. package/dist/commerce/envar-runtime.js +28 -1
  18. package/dist/commerce/envar.d.ts +13 -31
  19. package/dist/commerce/envar.js +35 -83
  20. package/dist/commerce/external-agent.d.ts +26 -0
  21. package/dist/commerce/external-agent.js +129 -0
  22. package/dist/commerce/external-events.d.ts +76 -0
  23. package/dist/commerce/external-events.js +273 -0
  24. package/dist/commerce/external-mcp.d.ts +10 -0
  25. package/dist/commerce/external-mcp.js +199 -0
  26. package/dist/commerce/external-oauth.d.ts +12 -0
  27. package/dist/commerce/external-oauth.js +230 -0
  28. package/dist/commerce/external-runtime.d.ts +25 -0
  29. package/dist/commerce/external-runtime.js +244 -0
  30. package/dist/commerce/index.d.ts +1 -0
  31. package/dist/commerce/index.js +1 -0
  32. package/dist/commerce/managed.d.ts +3 -0
  33. package/dist/commerce/managed.js +143 -0
  34. package/dist/commerce/native-inventory.d.ts +9 -0
  35. package/dist/commerce/native-inventory.js +75 -0
  36. package/dist/commerce/native-skills.d.ts +32 -0
  37. package/dist/commerce/native-skills.js +174 -0
  38. package/dist/commerce/openclaw-setup.d.ts +28 -0
  39. package/dist/commerce/openclaw-setup.js +43 -0
  40. package/dist/commerce/operations.d.ts +8 -3
  41. package/dist/commerce/operations.js +21 -18
  42. package/dist/commerce/pricing.d.ts +0 -1
  43. package/dist/commerce/pricing.js +3 -5
  44. package/dist/commerce/runtime.d.ts +4 -2
  45. package/dist/commerce/runtime.js +4 -2
  46. package/dist/commerce/server.d.ts +3 -2
  47. package/dist/commerce/server.js +26 -10
  48. package/dist/commerce/setup.d.ts +25 -0
  49. package/dist/commerce/setup.js +379 -0
  50. package/dist/commerce/skill-gate.d.ts +54 -0
  51. package/dist/commerce/skill-gate.js +153 -0
  52. package/dist/commerce/store.d.ts +11 -1
  53. package/dist/commerce/store.js +36 -2
  54. package/dist/commerce/types.d.ts +6 -57
  55. package/examples/envar-integration-policy.json +1 -9
  56. package/examples/hermes-setup-probe.py +109 -0
  57. package/examples/hermes-skill-inventory.py +108 -0
  58. package/examples/native-skill-runner.py +197 -0
  59. package/examples/seller.json +143 -26
  60. package/package.json +5 -16
  61. package/schemas/envarpay.config.schema.json +28 -87
  62. package/dist/commerce/buyer-store.d.ts +0 -101
  63. package/dist/commerce/buyer-store.js +0 -168
  64. package/dist/commerce/buyer.d.ts +0 -132
  65. package/dist/commerce/buyer.js +0 -755
  66. package/dist/commerce/chain.d.ts +0 -24
  67. package/dist/commerce/chain.js +0 -146
  68. package/dist/commerce/client-runtime.d.ts +0 -8
  69. package/dist/commerce/client-runtime.js +0 -7
  70. package/dist/commerce/management.d.ts +0 -14
  71. package/dist/commerce/management.js +0 -138
  72. package/dist/commerce/mpp-client.d.ts +0 -59
  73. package/dist/commerce/mpp-client.js +0 -24
  74. package/dist/commerce/mpp-runtime.d.ts +0 -3
  75. package/dist/commerce/mpp-runtime.js +0 -3
  76. package/dist/commerce/mpp.d.ts +0 -53
  77. package/dist/commerce/mpp.js +0 -163
  78. package/dist/commerce/peer-proxy.d.ts +0 -44
  79. package/dist/commerce/peer-proxy.js +0 -673
  80. package/dist/commerce/stripe-provider.d.ts +0 -9
  81. package/dist/commerce/stripe-provider.js +0 -97
  82. package/dist/commerce/x402.d.ts +0 -37
  83. package/dist/commerce/x402.js +0 -174
  84. package/examples/buyer-policy.json +0 -18
  85. package/schemas/buyer-policy.schema.json +0 -253
@@ -1,52 +1,169 @@
1
1
  {
2
2
  "configVersion": 1,
3
- "agent": {"id": "hermes-researcher", "name": "我的研究助手"},
3
+ "agent": {
4
+ "id": "hermes-researcher",
5
+ "name": "我的研究助手"
6
+ },
4
7
  "paymentProfiles": {
5
- "base-usdc": {
6
- "adapter": "x402", "scheme": "exact", "network": "eip155:84532",
7
- "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
8
- "payTo": "0x2222222222222222222222222222222222222222",
9
- "facilitatorUrl": "https://facilitator.example"
10
- },
11
- "stripe-usd": {"adapter": "mpp", "method": "stripe", "intent": "charge", "currency": "usd", "accountRef": "seller-stripe"}
8
+ "envar-usd": {
9
+ "adapter": "envar_balance",
10
+ "currency": "usd",
11
+ "accountRef": "envar"
12
+ }
12
13
  },
13
14
  "services": [
14
15
  {
15
- "id": "research", "name": "竞品调研", "revision": 1,
16
- "execution": {"type": "a2a", "cardUrl": "http://hermes:9000/research/agent-card.json"},
16
+ "id": "research",
17
+ "name": "竞品调研",
18
+ "revision": 1,
19
+ "execution": {
20
+ "type": "a2a",
21
+ "cardUrl": "http://hermes:9000/research/agent-card.json"
22
+ },
17
23
  "contract": {
18
24
  "inputSchema": {
19
25
  "$schema": "https://json-schema.org/draft/2020-12/schema",
20
- "type": "object", "additionalProperties": false, "required": ["topic", "competitors"],
26
+ "type": "object",
27
+ "additionalProperties": false,
28
+ "required": [
29
+ "topic",
30
+ "competitors"
31
+ ],
21
32
  "properties": {
22
- "topic": {"type": "string", "minLength": 1, "maxLength": 500},
23
- "competitors": {"type": "array", "minItems": 1, "maxItems": 3, "uniqueItems": true, "items": {"type": "string", "minLength": 1, "maxLength": 120}}
33
+ "topic": {
34
+ "type": "string",
35
+ "minLength": 1,
36
+ "maxLength": 500
37
+ },
38
+ "competitors": {
39
+ "type": "array",
40
+ "minItems": 1,
41
+ "maxItems": 3,
42
+ "uniqueItems": true,
43
+ "items": {
44
+ "type": "string",
45
+ "minLength": 1,
46
+ "maxLength": 120
47
+ }
48
+ }
24
49
  }
25
50
  },
26
- "deliverables": ["report.md", "comparison.csv"], "targetDurationSeconds": 600, "includedRevisions": 0
51
+ "deliverables": [
52
+ "report.md",
53
+ "comparison.csv"
54
+ ],
55
+ "targetDurationSeconds": 600,
56
+ "includedRevisions": 0
27
57
  },
28
58
  "offers": [
29
- {"id": "usdc-once", "pricing": {"kind": "fixed", "amount": "3000000"}, "collection": {"kind": "upfront"}, "paymentProfile": "base-usdc"},
30
- {"id": "card-once", "pricing": {"kind": "fixed", "amount": "300"}, "collection": {"kind": "upfront"}, "paymentProfile": "stripe-usd"}
59
+ {
60
+ "id": "balance-once",
61
+ "pricing": {
62
+ "kind": "fixed",
63
+ "amount": "3000000"
64
+ },
65
+ "collection": {
66
+ "kind": "upfront"
67
+ },
68
+ "paymentProfile": "envar-usd"
69
+ }
31
70
  ]
32
71
  },
33
72
  {
34
- "id": "summary-preview", "name": "免费试读", "revision": 1,
35
- "execution": {"type": "a2a", "cardUrl": "http://hermes:9000/preview/agent-card.json"},
73
+ "id": "summary-preview",
74
+ "name": "免费试读",
75
+ "revision": 1,
76
+ "execution": {
77
+ "type": "a2a",
78
+ "cardUrl": "http://hermes:9000/preview/agent-card.json"
79
+ },
36
80
  "contract": {
37
- "inputSchema": {"type": "object", "additionalProperties": false, "required": ["text"], "properties": {"text": {"type": "string", "minLength": 1, "maxLength": 500}}},
38
- "deliverables": ["summary.txt"], "targetDurationSeconds": 60, "includedRevisions": 0
81
+ "inputSchema": {
82
+ "type": "object",
83
+ "additionalProperties": false,
84
+ "required": [
85
+ "text"
86
+ ],
87
+ "properties": {
88
+ "text": {
89
+ "type": "string",
90
+ "minLength": 1,
91
+ "maxLength": 500
92
+ }
93
+ }
94
+ },
95
+ "deliverables": [
96
+ "summary.txt"
97
+ ],
98
+ "targetDurationSeconds": 60,
99
+ "includedRevisions": 0
39
100
  },
40
- "offers": [{"id": "free", "pricing": {"kind": "free"}, "collection": {"kind": "none"}}]
101
+ "offers": [
102
+ {
103
+ "id": "free",
104
+ "pricing": {
105
+ "kind": "free"
106
+ },
107
+ "collection": {
108
+ "kind": "none"
109
+ }
110
+ }
111
+ ]
41
112
  },
42
113
  {
43
- "id": "translation", "name": "文档翻译", "revision": 1,
44
- "execution": {"type": "a2a", "cardUrl": "http://openclaw:9000/translate/agent-card.json"},
114
+ "id": "translation",
115
+ "name": "文档翻译",
116
+ "revision": 1,
117
+ "execution": {
118
+ "type": "a2a",
119
+ "cardUrl": "http://openclaw:9000/translate/agent-card.json"
120
+ },
45
121
  "contract": {
46
- "inputSchema": {"type": "object", "additionalProperties": false, "required": ["documents"], "properties": {"documents": {"type": "array", "minItems": 1, "maxItems": 20, "items": {"type": "string", "minLength": 1, "maxLength": 10000}}}},
47
- "deliverables": ["translations.json"], "targetDurationSeconds": 600, "includedRevisions": 0
122
+ "inputSchema": {
123
+ "type": "object",
124
+ "additionalProperties": false,
125
+ "required": [
126
+ "documents"
127
+ ],
128
+ "properties": {
129
+ "documents": {
130
+ "type": "array",
131
+ "minItems": 1,
132
+ "maxItems": 20,
133
+ "items": {
134
+ "type": "string",
135
+ "minLength": 1,
136
+ "maxLength": 10000
137
+ }
138
+ }
139
+ }
140
+ },
141
+ "deliverables": [
142
+ "translations.json"
143
+ ],
144
+ "targetDurationSeconds": 600,
145
+ "includedRevisions": 0
48
146
  },
49
- "offers": [{"id": "per-document", "pricing": {"kind": "quantity", "unit": "document", "unitAmount": "100000", "quantity": {"pointer": "/documents", "measure": "count", "min": 1, "max": 20}}, "collection": {"kind": "upfront"}, "paymentProfile": "base-usdc"}]
147
+ "offers": [
148
+ {
149
+ "id": "per-document",
150
+ "pricing": {
151
+ "kind": "quantity",
152
+ "unit": "document",
153
+ "unitAmount": "100000",
154
+ "quantity": {
155
+ "pointer": "/documents",
156
+ "measure": "count",
157
+ "min": 1,
158
+ "max": 20
159
+ }
160
+ },
161
+ "collection": {
162
+ "kind": "upfront"
163
+ },
164
+ "paymentProfile": "envar-usd"
165
+ }
166
+ ]
50
167
  }
51
168
  ]
52
169
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@envarai/envarpay",
3
- "version": "0.2.0-alpha.2",
4
- "description": "Independent A2A service commerce, budgeted buyers and x402/MPP payments",
3
+ "version": "0.2.0-alpha.20",
4
+ "description": "A2A services with Envar account-balance payments",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "engines": {
@@ -20,18 +20,10 @@
20
20
  "types": "./dist/commerce/runtime.d.ts",
21
21
  "import": "./dist/commerce/runtime.js"
22
22
  },
23
- "./client": {
24
- "types": "./dist/commerce/client-runtime.d.ts",
25
- "import": "./dist/commerce/client-runtime.js"
26
- },
27
23
  "./server": {
28
24
  "types": "./dist/commerce/runtime.d.ts",
29
25
  "import": "./dist/commerce/runtime.js"
30
26
  },
31
- "./mpp": {
32
- "types": "./dist/commerce/mpp-runtime.d.ts",
33
- "import": "./dist/commerce/mpp-runtime.js"
34
- },
35
27
  "./envar": {
36
28
  "types": "./dist/commerce/envar.d.ts",
37
29
  "import": "./dist/commerce/envar.js"
@@ -54,21 +46,18 @@
54
46
  "tag": "next"
55
47
  },
56
48
  "scripts": {
57
- "build": "tsc",
49
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc",
58
50
  "test": "npm run build && node --test test/*.test.mjs",
59
51
  "prepack": "npm run build"
60
52
  },
61
53
  "dependencies": {
62
54
  "@a2a-js/sdk": "1.2.1",
63
55
  "@modelcontextprotocol/sdk": "^1.31.0",
64
- "@x402/core": "2.24.0",
65
- "@x402/evm": "2.24.0",
66
- "@x402/extensions": "2.24.0",
67
56
  "ajv": "8.20.0",
68
57
  "ajv-formats": "3.0.1",
69
58
  "canonicalize": "2.1.0",
70
- "mppx": "0.13.1",
71
- "viem": "2.57.1"
59
+ "yaml": "2.8.2",
60
+ "zod": "4.6.5"
72
61
  },
73
62
  "devDependencies": {
74
63
  "@types/node": "^22.0.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "urn:envarpay:config:1",
3
+ "$id": "urn:envarpay:config:1-or-2",
4
4
  "title": "EnvarPay A2A commerce MVP configuration",
5
5
  "type": "object",
6
6
  "additionalProperties": false,
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "properties": {
14
14
  "configVersion": {
15
- "const": 1
15
+ "enum": [1, 2]
16
16
  },
17
17
  "agent": {
18
18
  "type": "object",
@@ -38,20 +38,11 @@
38
38
  "propertyNames": {
39
39
  "$ref": "#/$defs/id"
40
40
  },
41
- "additionalProperties": {
42
- "oneOf": [
43
- {
44
- "$ref": "#/$defs/x402"
45
- },
46
- {
47
- "$ref": "#/$defs/mpp"
48
- }
49
- ]
50
- }
41
+ "additionalProperties": { "$ref": "#/$defs/envarBalance" }
51
42
  },
52
43
  "services": {
53
44
  "type": "array",
54
- "minItems": 1,
45
+ "minItems": 0,
55
46
  "maxItems": 64,
56
47
  "items": {
57
48
  "$ref": "#/$defs/service"
@@ -67,77 +58,20 @@
67
58
  "type": "string",
68
59
  "pattern": "^[1-9][0-9]{0,77}$"
69
60
  },
70
- "address": {
71
- "type": "string",
72
- "pattern": "^0x[0-9a-fA-F]{40}$"
73
- },
74
61
  "httpUrl": {
75
62
  "type": "string",
76
63
  "format": "uri",
77
64
  "pattern": "^https?://",
78
65
  "maxLength": 2048
79
66
  },
80
- "x402": {
67
+ "envarBalance": {
81
68
  "type": "object",
82
69
  "additionalProperties": false,
83
- "required": [
84
- "adapter",
85
- "scheme",
86
- "network",
87
- "asset",
88
- "payTo",
89
- "facilitatorUrl"
90
- ],
70
+ "required": ["adapter", "currency", "accountRef"],
91
71
  "properties": {
92
- "adapter": {
93
- "const": "x402"
94
- },
95
- "scheme": {
96
- "const": "exact"
97
- },
98
- "network": {
99
- "type": "string",
100
- "pattern": "^eip155:[1-9][0-9]*$"
101
- },
102
- "asset": {
103
- "$ref": "#/$defs/address"
104
- },
105
- "payTo": {
106
- "$ref": "#/$defs/address"
107
- },
108
- "facilitatorUrl": {
109
- "type": "string",
110
- "format": "uri",
111
- "pattern": "^https://"
112
- }
113
- }
114
- },
115
- "mpp": {
116
- "type": "object",
117
- "additionalProperties": false,
118
- "required": [
119
- "adapter",
120
- "method",
121
- "intent",
122
- "currency",
123
- "accountRef"
124
- ],
125
- "properties": {
126
- "adapter": {
127
- "const": "mpp"
128
- },
129
- "method": {
130
- "const": "stripe"
131
- },
132
- "intent": {
133
- "const": "charge"
134
- },
135
- "currency": {
136
- "const": "usd"
137
- },
138
- "accountRef": {
139
- "$ref": "#/$defs/id"
140
- }
72
+ "adapter": { "const": "envar_balance" },
73
+ "currency": { "const": "usd" },
74
+ "accountRef": { "$ref": "#/$defs/id" }
141
75
  }
142
76
  },
143
77
  "service": {
@@ -165,20 +99,27 @@
165
99
  "maximum": 2147483647
166
100
  },
167
101
  "execution": {
168
- "type": "object",
169
- "additionalProperties": false,
170
- "required": [
171
- "type",
172
- "cardUrl"
173
- ],
174
- "properties": {
175
- "type": {
176
- "const": "a2a"
102
+ "oneOf": [
103
+ {
104
+ "type": "object",
105
+ "additionalProperties": false,
106
+ "required": ["type", "cardUrl"],
107
+ "properties": {
108
+ "type": { "const": "a2a" },
109
+ "cardUrl": { "$ref": "#/$defs/httpUrl" }
110
+ }
177
111
  },
178
- "cardUrl": {
179
- "$ref": "#/$defs/httpUrl"
112
+ {
113
+ "type": "object",
114
+ "additionalProperties": false,
115
+ "required": ["type", "cardUrl", "skillDigest"],
116
+ "properties": {
117
+ "type": { "const": "skill" },
118
+ "cardUrl": { "$ref": "#/$defs/httpUrl" },
119
+ "skillDigest": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
120
+ }
180
121
  }
181
- }
122
+ ]
182
123
  },
183
124
  "contract": {
184
125
  "type": "object",
@@ -1,101 +0,0 @@
1
- import type { PaymentRequired, PaymentRequirements, SettleResponse } from '@x402/core/types';
2
- import type { Challenge } from 'mppx';
3
- import type { MppReceipt } from './mpp-client.js';
4
- import { type BuyerPolicy, type Input } from './types.js';
5
- export interface BuyerQuote {
6
- messageId: string;
7
- payer: string;
8
- amount: string;
9
- currency: string | null;
10
- recipient: string | null;
11
- expiresAt: string;
12
- serviceId: string;
13
- serviceRevision: number;
14
- offerId: string;
15
- inputDigest: string;
16
- termsDigest: string;
17
- quoteId: string;
18
- /** Absent for the original seller-advertised EnvarPay contract. */
19
- termsSource?: 'local-policy';
20
- }
21
- export interface BuyerRecord {
22
- id: string;
23
- caller: string;
24
- peerId: string;
25
- cardUrl: string;
26
- endpoint: string;
27
- messageId: string;
28
- fingerprint: string;
29
- body: string;
30
- quoteToken: string;
31
- quote: BuyerQuote;
32
- input: Input;
33
- inputSchema: Record<string, unknown>;
34
- peerMode?: 'standard-a2a';
35
- standardBinding?: {
36
- policyDigest: string;
37
- bodyDigest: string;
38
- challengeDigest: string;
39
- };
40
- continuations?: {
41
- messageId: string;
42
- input: Input;
43
- body?: string;
44
- state: 'pending' | 'unknown' | 'resolved';
45
- beforeDigest: string;
46
- }[];
47
- protocol?: 'x402' | 'mpp' | 'free';
48
- mppChallenge?: Challenge.Challenge;
49
- tokenOperationId?: string;
50
- tokenRef?: string;
51
- mppMode?: 'test' | 'live';
52
- mppPaymentMethod?: string;
53
- required?: PaymentRequired;
54
- requirements?: PaymentRequirements;
55
- createdAt: string;
56
- updatedAt: string;
57
- state: 'previewed' | 'signing' | 'submitted' | 'unknown' | 'completed' | 'failed';
58
- paymentState: 'quoted' | 'reserved' | 'unknown' | 'confirmed' | 'rejected' | 'not_required';
59
- executionState: string;
60
- credentialRef?: string;
61
- nonce?: string;
62
- fromBlock?: string;
63
- receipt?: SettleResponse | MppReceipt;
64
- task?: Record<string, unknown>;
65
- result?: unknown;
66
- errorCode?: string;
67
- rejectionEvidence?: {
68
- kind: 'finalized_expired_unused';
69
- checkedAt: string;
70
- nonce: string;
71
- };
72
- }
73
- /** One wallet ledger, one process. Unknown authorizations retain cumulative budget. */
74
- export declare class BuyerStore {
75
- private readonly db;
76
- private readonly owner?;
77
- constructor(path: string);
78
- close(): void;
79
- private transaction;
80
- get(id: string, caller: string): BuyerRecord | undefined;
81
- assertMessageOwner(caller: string, messageId: string): void;
82
- find(caller: string, messageId: string): BuyerRecord | undefined;
83
- insert(value: Omit<BuyerRecord, 'id' | 'createdAt' | 'updatedAt' | 'state' | 'paymentState' | 'executionState'>): BuyerRecord;
84
- update(id: string, patch: Partial<Pick<BuyerRecord, 'state' | 'paymentState' | 'executionState' | 'credentialRef' | 'nonce' | 'fromBlock' | 'receipt' | 'task' | 'result' | 'errorCode' | 'continuations' | 'tokenOperationId' | 'tokenRef' | 'rejectionEvidence'>>): BuyerRecord;
85
- pendingTasks(): BuyerRecord[];
86
- usage(currency: string): {
87
- reserved: string;
88
- spent: string;
89
- };
90
- reserve(id: string, caller: string, policy: BuyerPolicy): {
91
- record: BuyerRecord;
92
- fresh: boolean;
93
- };
94
- beginFree(id: string, caller: string): {
95
- record: BuyerRecord;
96
- fresh: boolean;
97
- };
98
- rejectBeforeSigning(id: string, caller: string, errorCode: string): BuyerRecord;
99
- rejectExpiredAuthorization(id: string, caller: string): BuyerRecord;
100
- confirmed(id: string, receipt: SettleResponse | MppReceipt): BuyerRecord;
101
- }