@remitmd/sdk 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 (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +250 -0
  3. package/dist/a2a.d.ts +137 -0
  4. package/dist/a2a.d.ts.map +1 -0
  5. package/dist/a2a.js +121 -0
  6. package/dist/a2a.js.map +1 -0
  7. package/dist/client.d.ts +41 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +81 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/errors.d.ts +108 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +218 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/http.d.ts +23 -0
  16. package/dist/http.d.ts.map +1 -0
  17. package/dist/http.js +150 -0
  18. package/dist/http.js.map +1 -0
  19. package/dist/index.d.ts +18 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +21 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/integrations/vercel-ai.d.ts +44 -0
  24. package/dist/integrations/vercel-ai.d.ts.map +1 -0
  25. package/dist/integrations/vercel-ai.js +175 -0
  26. package/dist/integrations/vercel-ai.js.map +1 -0
  27. package/dist/models/bounty.d.ts +22 -0
  28. package/dist/models/bounty.d.ts.map +1 -0
  29. package/dist/models/bounty.js +2 -0
  30. package/dist/models/bounty.js.map +1 -0
  31. package/dist/models/common.d.ts +78 -0
  32. package/dist/models/common.d.ts.map +1 -0
  33. package/dist/models/common.js +3 -0
  34. package/dist/models/common.js.map +1 -0
  35. package/dist/models/deposit.d.ts +13 -0
  36. package/dist/models/deposit.d.ts.map +1 -0
  37. package/dist/models/deposit.js +2 -0
  38. package/dist/models/deposit.js.map +1 -0
  39. package/dist/models/escrow.d.ts +16 -0
  40. package/dist/models/escrow.d.ts.map +1 -0
  41. package/dist/models/escrow.js +2 -0
  42. package/dist/models/escrow.js.map +1 -0
  43. package/dist/models/index.d.ts +9 -0
  44. package/dist/models/index.d.ts.map +1 -0
  45. package/dist/models/index.js +9 -0
  46. package/dist/models/index.js.map +1 -0
  47. package/dist/models/invoice.d.ts +30 -0
  48. package/dist/models/invoice.d.ts.map +1 -0
  49. package/dist/models/invoice.js +2 -0
  50. package/dist/models/invoice.js.map +1 -0
  51. package/dist/models/reputation.d.ts +7 -0
  52. package/dist/models/reputation.d.ts.map +1 -0
  53. package/dist/models/reputation.js +2 -0
  54. package/dist/models/reputation.js.map +1 -0
  55. package/dist/models/stream.d.ts +15 -0
  56. package/dist/models/stream.d.ts.map +1 -0
  57. package/dist/models/stream.js +2 -0
  58. package/dist/models/stream.js.map +1 -0
  59. package/dist/models/tab.d.ts +21 -0
  60. package/dist/models/tab.d.ts.map +1 -0
  61. package/dist/models/tab.js +2 -0
  62. package/dist/models/tab.js.map +1 -0
  63. package/dist/provider.d.ts +135 -0
  64. package/dist/provider.d.ts.map +1 -0
  65. package/dist/provider.js +218 -0
  66. package/dist/provider.js.map +1 -0
  67. package/dist/signer.d.ts +31 -0
  68. package/dist/signer.d.ts.map +1 -0
  69. package/dist/signer.js +35 -0
  70. package/dist/signer.js.map +1 -0
  71. package/dist/testing/local.d.ts +31 -0
  72. package/dist/testing/local.d.ts.map +1 -0
  73. package/dist/testing/local.js +100 -0
  74. package/dist/testing/local.js.map +1 -0
  75. package/dist/testing/mock.d.ts +95 -0
  76. package/dist/testing/mock.d.ts.map +1 -0
  77. package/dist/testing/mock.js +407 -0
  78. package/dist/testing/mock.js.map +1 -0
  79. package/dist/wallet.d.ts +162 -0
  80. package/dist/wallet.d.ts.map +1 -0
  81. package/dist/wallet.js +365 -0
  82. package/dist/wallet.js.map +1 -0
  83. package/dist/x402.d.ts +78 -0
  84. package/dist/x402.d.ts.map +1 -0
  85. package/dist/x402.js +151 -0
  86. package/dist/x402.js.map +1 -0
  87. package/eslint.config.js +27 -0
  88. package/package.json +39 -0
  89. package/src/a2a.ts +241 -0
  90. package/src/client.ts +104 -0
  91. package/src/errors.ts +261 -0
  92. package/src/http.ts +190 -0
  93. package/src/index.ts +94 -0
  94. package/src/integrations/vercel-ai.ts +213 -0
  95. package/src/models/bounty.ts +23 -0
  96. package/src/models/common.ts +106 -0
  97. package/src/models/deposit.ts +13 -0
  98. package/src/models/escrow.ts +16 -0
  99. package/src/models/index.ts +8 -0
  100. package/src/models/invoice.ts +32 -0
  101. package/src/models/reputation.ts +7 -0
  102. package/src/models/stream.ts +15 -0
  103. package/src/models/tab.ts +22 -0
  104. package/src/provider.ts +281 -0
  105. package/src/signer.ts +70 -0
  106. package/src/testing/local.ts +118 -0
  107. package/src/testing/mock.ts +507 -0
  108. package/src/wallet.ts +546 -0
  109. package/src/x402.ts +202 -0
  110. package/tests/acceptance/bounty.test.ts +82 -0
  111. package/tests/acceptance/deposit.test.ts +70 -0
  112. package/tests/acceptance/direct.test.ts +53 -0
  113. package/tests/acceptance/escrow.test.ts +67 -0
  114. package/tests/acceptance/setup.ts +113 -0
  115. package/tests/acceptance/stream.test.ts +98 -0
  116. package/tests/acceptance/tab.test.ts +108 -0
  117. package/tests/acceptance/x402.test.ts +140 -0
  118. package/tests/compliance/auth.ts +69 -0
  119. package/tests/compliance/escrows.ts +96 -0
  120. package/tests/compliance/helpers.ts +90 -0
  121. package/tests/compliance/payments.ts +69 -0
  122. package/tests/compliance/tabs.ts +52 -0
  123. package/tests/test_a2a.ts +151 -0
  124. package/tests/test_errors.ts +80 -0
  125. package/tests/test_golden_vectors.ts +162 -0
  126. package/tests/test_integrations.ts +115 -0
  127. package/tests/test_mock.ts +217 -0
  128. package/tests/test_permit.ts +216 -0
  129. package/tests/test_provider.ts +304 -0
  130. package/tests/test_wallet.ts +108 -0
  131. package/tests/test_x402.ts +302 -0
  132. package/tsconfig.json +19 -0
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Typed error classes for remit.md error codes.
3
+ *
4
+ * Every API error code maps to a specific class so callers can handle precisely:
5
+ *
6
+ * try {
7
+ * await wallet.pay(invoice);
8
+ * } catch (e) {
9
+ * if (e instanceof InsufficientBalanceError) {
10
+ * await wallet.requestTestnetFunds();
11
+ * }
12
+ * }
13
+ */
14
+ export declare class RemitError extends Error {
15
+ readonly code: string;
16
+ readonly httpStatus: number;
17
+ constructor(message: string, code?: string, httpStatus?: number);
18
+ }
19
+ export declare class InvalidSignatureError extends RemitError {
20
+ constructor(msg?: string);
21
+ }
22
+ export declare class NonceReusedError extends RemitError {
23
+ constructor(msg?: string);
24
+ }
25
+ export declare class TimestampExpiredError extends RemitError {
26
+ constructor(msg?: string);
27
+ }
28
+ export declare class UnauthorizedError extends RemitError {
29
+ constructor(msg?: string);
30
+ }
31
+ export declare class InsufficientBalanceError extends RemitError {
32
+ constructor(msg?: string);
33
+ }
34
+ export declare class BelowMinimumError extends RemitError {
35
+ constructor(msg?: string);
36
+ }
37
+ export declare class EscrowNotFoundError extends RemitError {
38
+ constructor(msg?: string);
39
+ }
40
+ export declare class EscrowAlreadyFundedError extends RemitError {
41
+ constructor(msg?: string);
42
+ }
43
+ export declare class EscrowExpiredError extends RemitError {
44
+ constructor(msg?: string);
45
+ }
46
+ export declare class InvalidInvoiceError extends RemitError {
47
+ constructor(msg?: string);
48
+ }
49
+ export declare class DuplicateInvoiceError extends RemitError {
50
+ constructor(msg?: string);
51
+ }
52
+ export declare class SelfPaymentError extends RemitError {
53
+ constructor(msg?: string);
54
+ }
55
+ export declare class InvalidPaymentTypeError extends RemitError {
56
+ constructor(msg?: string);
57
+ }
58
+ export declare class TabDepletedError extends RemitError {
59
+ constructor(msg?: string);
60
+ }
61
+ export declare class TabExpiredError extends RemitError {
62
+ constructor(msg?: string);
63
+ }
64
+ export declare class TabNotFoundError extends RemitError {
65
+ constructor(msg?: string);
66
+ }
67
+ export declare class StreamNotFoundError extends RemitError {
68
+ constructor(msg?: string);
69
+ }
70
+ export declare class RateExceedsCapError extends RemitError {
71
+ constructor(msg?: string);
72
+ }
73
+ export declare class BountyExpiredError extends RemitError {
74
+ constructor(msg?: string);
75
+ }
76
+ export declare class BountyClaimedError extends RemitError {
77
+ constructor(msg?: string);
78
+ }
79
+ export declare class BountyMaxAttemptsError extends RemitError {
80
+ constructor(msg?: string);
81
+ }
82
+ export declare class BountyNotFoundError extends RemitError {
83
+ constructor(msg?: string);
84
+ }
85
+ export declare class ChainMismatchError extends RemitError {
86
+ constructor(msg?: string);
87
+ }
88
+ export declare class ChainUnsupportedError extends RemitError {
89
+ constructor(msg?: string);
90
+ }
91
+ export declare class RateLimitedError extends RemitError {
92
+ constructor(msg?: string);
93
+ }
94
+ export declare class CancelBlockedClaimStartError extends RemitError {
95
+ constructor(msg?: string);
96
+ }
97
+ export declare class CancelBlockedEvidenceError extends RemitError {
98
+ constructor(msg?: string);
99
+ }
100
+ export declare class VersionMismatchError extends RemitError {
101
+ constructor(msg?: string);
102
+ }
103
+ export declare class NetworkError extends RemitError {
104
+ constructor(msg?: string);
105
+ }
106
+ /** Map an API error code + message into the appropriate typed error. */
107
+ export declare function fromErrorCode(code: string, message?: string): RemitError;
108
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,qBAAa,UAAW,SAAQ,KAAK;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,OAAO,EAAE,MAAM,EAAE,IAAI,SAAkB,EAAE,UAAU,SAAM;CAMtE;AAID,qBAAa,qBAAsB,SAAQ,UAAU;gBACvC,GAAG,SAA+B;CAG/C;AAED,qBAAa,gBAAiB,SAAQ,UAAU;gBAClC,GAAG,SAAiC;CAGjD;AAED,qBAAa,qBAAsB,SAAQ,UAAU;gBACvC,GAAG,SAAmC;CAGnD;AAED,qBAAa,iBAAkB,SAAQ,UAAU;gBACnC,GAAG,SAA6B;CAG7C;AAID,qBAAa,wBAAy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AAQ,UAAU;gBAClC,GAAG,SAA0C;CAG1D;AAID,qBAAa,4BAA6B,SAAQ,UAAU;gBAC9C,GAAG,SAAqC;CAGrD;AAED,qBAAa,0BAA2B,SAAQ,UAAU;gBAC5C,GAAG,SAAoD;CAGpE;AAID,qBAAa,oBAAqB,SAAQ,UAAU;gBACtC,GAAG,SAAyD;CAGzE;AAED,qBAAa,YAAa,SAAQ,UAAU;gBAC9B,GAAG,SAA4B;CAG5C;AAmCD,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAIxE"}
package/dist/errors.js ADDED
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Typed error classes for remit.md error codes.
3
+ *
4
+ * Every API error code maps to a specific class so callers can handle precisely:
5
+ *
6
+ * try {
7
+ * await wallet.pay(invoice);
8
+ * } catch (e) {
9
+ * if (e instanceof InsufficientBalanceError) {
10
+ * await wallet.requestTestnetFunds();
11
+ * }
12
+ * }
13
+ */
14
+ export class RemitError extends Error {
15
+ code;
16
+ httpStatus;
17
+ constructor(message, code = "UNKNOWN_ERROR", httpStatus = 500) {
18
+ super(message);
19
+ this.name = this.constructor.name;
20
+ this.code = code;
21
+ this.httpStatus = httpStatus;
22
+ }
23
+ }
24
+ // ─── Auth errors ─────────────────────────────────────────────────────────────
25
+ export class InvalidSignatureError extends RemitError {
26
+ constructor(msg = "Invalid EIP-712 signature.") {
27
+ super(msg, "INVALID_SIGNATURE", 401);
28
+ }
29
+ }
30
+ export class NonceReusedError extends RemitError {
31
+ constructor(msg = "Nonce has already been used.") {
32
+ super(msg, "NONCE_REUSED", 401);
33
+ }
34
+ }
35
+ export class TimestampExpiredError extends RemitError {
36
+ constructor(msg = "Request timestamp has expired.") {
37
+ super(msg, "TIMESTAMP_EXPIRED", 401);
38
+ }
39
+ }
40
+ export class UnauthorizedError extends RemitError {
41
+ constructor(msg = "Authentication required.") {
42
+ super(msg, "UNAUTHORIZED", 401);
43
+ }
44
+ }
45
+ // ─── Balance / funds ──────────────────────────────────────────────────────────
46
+ export class InsufficientBalanceError extends RemitError {
47
+ constructor(msg = "Wallet does not have enough USDC for this transaction + fee.") {
48
+ super(msg, "INSUFFICIENT_BALANCE", 402);
49
+ }
50
+ }
51
+ export class BelowMinimumError extends RemitError {
52
+ constructor(msg = "Transaction amount is below $0.01 minimum.") {
53
+ super(msg, "BELOW_MINIMUM", 400);
54
+ }
55
+ }
56
+ // ─── Escrow errors ────────────────────────────────────────────────────────────
57
+ export class EscrowNotFoundError extends RemitError {
58
+ constructor(msg = "Escrow not found.") {
59
+ super(msg, "ESCROW_NOT_FOUND", 404);
60
+ }
61
+ }
62
+ export class EscrowAlreadyFundedError extends RemitError {
63
+ constructor(msg = "This invoice already has a funded escrow.") {
64
+ super(msg, "ESCROW_ALREADY_FUNDED", 409);
65
+ }
66
+ }
67
+ export class EscrowExpiredError extends RemitError {
68
+ constructor(msg = "Escrow has expired.") {
69
+ super(msg, "ESCROW_EXPIRED", 410);
70
+ }
71
+ }
72
+ // ─── Invoice errors ───────────────────────────────────────────────────────────
73
+ export class InvalidInvoiceError extends RemitError {
74
+ constructor(msg = "Invoice is malformed or invalid.") {
75
+ super(msg, "INVALID_INVOICE", 400);
76
+ }
77
+ }
78
+ export class DuplicateInvoiceError extends RemitError {
79
+ constructor(msg = "An invoice with this ID already exists.") {
80
+ super(msg, "DUPLICATE_INVOICE", 409);
81
+ }
82
+ }
83
+ export class SelfPaymentError extends RemitError {
84
+ constructor(msg = "Cannot pay yourself.") {
85
+ super(msg, "SELF_PAYMENT", 400);
86
+ }
87
+ }
88
+ export class InvalidPaymentTypeError extends RemitError {
89
+ constructor(msg = "Payment type is not valid for this invoice.") {
90
+ super(msg, "INVALID_PAYMENT_TYPE", 400);
91
+ }
92
+ }
93
+ // ─── Tab errors ───────────────────────────────────────────────────────────────
94
+ export class TabDepletedError extends RemitError {
95
+ constructor(msg = "Tab has reached its spending limit.") {
96
+ super(msg, "TAB_DEPLETED", 402);
97
+ }
98
+ }
99
+ export class TabExpiredError extends RemitError {
100
+ constructor(msg = "Tab has expired.") {
101
+ super(msg, "TAB_EXPIRED", 410);
102
+ }
103
+ }
104
+ export class TabNotFoundError extends RemitError {
105
+ constructor(msg = "Tab not found.") {
106
+ super(msg, "TAB_NOT_FOUND", 404);
107
+ }
108
+ }
109
+ // ─── Stream errors ────────────────────────────────────────────────────────────
110
+ export class StreamNotFoundError extends RemitError {
111
+ constructor(msg = "Stream not found.") {
112
+ super(msg, "STREAM_NOT_FOUND", 404);
113
+ }
114
+ }
115
+ export class RateExceedsCapError extends RemitError {
116
+ constructor(msg = "Streaming rate exceeds the maximum allowed.") {
117
+ super(msg, "RATE_EXCEEDS_CAP", 422);
118
+ }
119
+ }
120
+ // ─── Bounty errors ────────────────────────────────────────────────────────────
121
+ export class BountyExpiredError extends RemitError {
122
+ constructor(msg = "Bounty has expired.") {
123
+ super(msg, "BOUNTY_EXPIRED", 410);
124
+ }
125
+ }
126
+ export class BountyClaimedError extends RemitError {
127
+ constructor(msg = "Bounty has already been awarded.") {
128
+ super(msg, "BOUNTY_CLAIMED", 409);
129
+ }
130
+ }
131
+ export class BountyMaxAttemptsError extends RemitError {
132
+ constructor(msg = "Bounty has reached maximum submission attempts.") {
133
+ super(msg, "BOUNTY_MAX_ATTEMPTS", 422);
134
+ }
135
+ }
136
+ export class BountyNotFoundError extends RemitError {
137
+ constructor(msg = "Bounty not found.") {
138
+ super(msg, "BOUNTY_NOT_FOUND", 404);
139
+ }
140
+ }
141
+ // ─── Chain errors ─────────────────────────────────────────────────────────────
142
+ export class ChainMismatchError extends RemitError {
143
+ constructor(msg = "Invoice chain does not match wallet chain.") {
144
+ super(msg, "CHAIN_MISMATCH", 409);
145
+ }
146
+ }
147
+ export class ChainUnsupportedError extends RemitError {
148
+ constructor(msg = "This chain is not supported.") {
149
+ super(msg, "CHAIN_UNSUPPORTED", 422);
150
+ }
151
+ }
152
+ // ─── Rate limiting ────────────────────────────────────────────────────────────
153
+ export class RateLimitedError extends RemitError {
154
+ constructor(msg = "Rate limit exceeded. Try again later.") {
155
+ super(msg, "RATE_LIMITED", 429);
156
+ }
157
+ }
158
+ // ─── Cancellation errors ──────────────────────────────────────────────────────
159
+ export class CancelBlockedClaimStartError extends RemitError {
160
+ constructor(msg = "Cannot cancel after claim start.") {
161
+ super(msg, "CANCEL_BLOCKED_CLAIM_START", 409);
162
+ }
163
+ }
164
+ export class CancelBlockedEvidenceError extends RemitError {
165
+ constructor(msg = "Cannot cancel while evidence is pending review.") {
166
+ super(msg, "CANCEL_BLOCKED_EVIDENCE", 409);
167
+ }
168
+ }
169
+ // ─── Protocol errors ──────────────────────────────────────────────────────────
170
+ export class VersionMismatchError extends RemitError {
171
+ constructor(msg = "SDK version is not compatible with this API version.") {
172
+ super(msg, "VERSION_MISMATCH", 422);
173
+ }
174
+ }
175
+ export class NetworkError extends RemitError {
176
+ constructor(msg = "Network request failed.") {
177
+ super(msg, "NETWORK_ERROR", 503);
178
+ }
179
+ }
180
+ // ─── Factory ──────────────────────────────────────────────────────────────────
181
+ const ERROR_MAP = {
182
+ INVALID_SIGNATURE: InvalidSignatureError,
183
+ NONCE_REUSED: NonceReusedError,
184
+ TIMESTAMP_EXPIRED: TimestampExpiredError,
185
+ UNAUTHORIZED: UnauthorizedError,
186
+ INSUFFICIENT_BALANCE: InsufficientBalanceError,
187
+ BELOW_MINIMUM: BelowMinimumError,
188
+ ESCROW_NOT_FOUND: EscrowNotFoundError,
189
+ ESCROW_ALREADY_FUNDED: EscrowAlreadyFundedError,
190
+ ESCROW_EXPIRED: EscrowExpiredError,
191
+ INVALID_INVOICE: InvalidInvoiceError,
192
+ DUPLICATE_INVOICE: DuplicateInvoiceError,
193
+ SELF_PAYMENT: SelfPaymentError,
194
+ INVALID_PAYMENT_TYPE: InvalidPaymentTypeError,
195
+ TAB_DEPLETED: TabDepletedError,
196
+ TAB_EXPIRED: TabExpiredError,
197
+ TAB_NOT_FOUND: TabNotFoundError,
198
+ STREAM_NOT_FOUND: StreamNotFoundError,
199
+ RATE_EXCEEDS_CAP: RateExceedsCapError,
200
+ BOUNTY_EXPIRED: BountyExpiredError,
201
+ BOUNTY_CLAIMED: BountyClaimedError,
202
+ BOUNTY_MAX_ATTEMPTS: BountyMaxAttemptsError,
203
+ BOUNTY_NOT_FOUND: BountyNotFoundError,
204
+ CHAIN_MISMATCH: ChainMismatchError,
205
+ CHAIN_UNSUPPORTED: ChainUnsupportedError,
206
+ RATE_LIMITED: RateLimitedError,
207
+ CANCEL_BLOCKED_CLAIM_START: CancelBlockedClaimStartError,
208
+ CANCEL_BLOCKED_EVIDENCE: CancelBlockedEvidenceError,
209
+ VERSION_MISMATCH: VersionMismatchError,
210
+ };
211
+ /** Map an API error code + message into the appropriate typed error. */
212
+ export function fromErrorCode(code, message) {
213
+ const Cls = ERROR_MAP[code];
214
+ if (Cls)
215
+ return new Cls(message);
216
+ return new RemitError(message ?? `Unknown error: ${code}`, code);
217
+ }
218
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC1B,IAAI,CAAS;IACb,UAAU,CAAS;IAE5B,YAAY,OAAe,EAAE,IAAI,GAAG,eAAe,EAAE,UAAU,GAAG,GAAG;QACnE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED,gFAAgF;AAEhF,MAAM,OAAO,qBAAsB,SAAQ,UAAU;IACnD,YAAY,GAAG,GAAG,4BAA4B;QAC5C,KAAK,CAAC,GAAG,EAAE,mBAAmB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;IACrC,gBAAgB,EAAE,mBAAmB;IACrC,cAAc,EAAE,kBAAkB;IAClC,cAAc,EAAE,kBAAkB;IAClC,mBAAmB,EAAE,sBAAsB;IAC3C,gBAAgB,EAAE,mBAAmB;IACrC,cAAc,EAAE,kBAAkB;IAClC,iBAAiB,EAAE,qBAAqB;IACxC,YAAY,EAAE,gBAAgB;IAC9B,0BAA0B,EAAE,4BAA4B;IACxD,uBAAuB,EAAE,0BAA0B;IACnD,gBAAgB,EAAE,oBAAoB;CACvC,CAAC;AAEF,wEAAwE;AACxE,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,OAAgB;IAC1D,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,GAAG;QAAE,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,IAAI,UAAU,CAAC,OAAO,IAAI,kBAAkB,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;AACnE,CAAC"}
package/dist/http.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Authenticated HTTP client.
3
+ * - Signs every request with EIP-712 (method, path, timestamp, nonce)
4
+ * - Auto-retry with exponential backoff on 429 and 5xx (up to 3 retries)
5
+ * - Adds idempotency key header on all POST/PATCH/PUT requests
6
+ * - Maps API error codes to typed RemitError subclasses
7
+ */
8
+ import type { Signer } from "./signer.js";
9
+ export interface HttpClientOptions {
10
+ signer: Signer;
11
+ baseUrl: string;
12
+ chainId: number;
13
+ verifyingContract?: string;
14
+ }
15
+ export declare class AuthenticatedClient {
16
+ #private;
17
+ constructor({ signer, baseUrl, chainId, verifyingContract }: HttpClientOptions);
18
+ get<T>(path: string): Promise<T>;
19
+ post<T>(path: string, body?: unknown): Promise<T>;
20
+ put<T>(path: string, body?: unknown): Promise<T>;
21
+ delete<T>(path: string): Promise<T>;
22
+ }
23
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAsD1C,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,qBAAa,mBAAmB;;gBAUlB,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,iBAAsB,EAAE,EAAE,iBAAiB;IAU7E,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIhC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAIjD,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAIhD,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CAsF1C"}
package/dist/http.js ADDED
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Authenticated HTTP client.
3
+ * - Signs every request with EIP-712 (method, path, timestamp, nonce)
4
+ * - Auto-retry with exponential backoff on 429 and 5xx (up to 3 retries)
5
+ * - Adds idempotency key header on all POST/PATCH/PUT requests
6
+ * - Maps API error codes to typed RemitError subclasses
7
+ */
8
+ import { randomBytes } from "node:crypto";
9
+ import { fromErrorCode, NetworkError, RateLimitedError } from "./errors.js";
10
+ // EIP-712 typed struct definition — must match server's auth.rs exactly.
11
+ // Struct name: APIRequest (not Request)
12
+ // Timestamp type: uint256 (not uint64 or uint32)
13
+ // Nonce type: bytes32 (not string)
14
+ const EIP712_TYPES = {
15
+ APIRequest: [
16
+ { name: "method", type: "string" },
17
+ { name: "path", type: "string" },
18
+ { name: "timestamp", type: "uint256" },
19
+ { name: "nonce", type: "bytes32" },
20
+ ],
21
+ };
22
+ /** 32-byte hex nonce with 0x prefix — required for bytes32 EIP-712 field. */
23
+ function newNonce() {
24
+ return `0x${randomBytes(32).toString("hex")}`;
25
+ }
26
+ function newIdempotencyKey() {
27
+ return randomBytes(16).toString("hex");
28
+ }
29
+ /** Convert a snake_case key to camelCase (e.g. "tx_hash" → "txHash"). */
30
+ function toCamel(key) {
31
+ return key.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
32
+ }
33
+ /** Recursively transform all object keys from snake_case to camelCase.
34
+ * The server (Rust/serde) emits snake_case; TypeScript SDK uses camelCase. */
35
+ function camelizeKeys(value) {
36
+ if (Array.isArray(value))
37
+ return value.map(camelizeKeys);
38
+ if (value !== null && typeof value === "object") {
39
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [toCamel(k), camelizeKeys(v)]));
40
+ }
41
+ return value;
42
+ }
43
+ const RETRYABLE = new Set([429, 500, 502, 503, 504]);
44
+ const DELAY_MS = [200, 600, 1800]; // exponential-ish
45
+ async function sleep(ms) {
46
+ return new Promise((resolve) => setTimeout(resolve, ms));
47
+ }
48
+ export class AuthenticatedClient {
49
+ #signer;
50
+ #baseUrl;
51
+ #chainId;
52
+ #verifyingContract;
53
+ /** Path prefix extracted from baseUrl (e.g. "/api/v0") to prepend when signing.
54
+ * The server verifies the full path (/api/v0/payments/direct) via OriginalUri,
55
+ * not just the relative segment (/payments/direct). */
56
+ #signPathPrefix;
57
+ constructor({ signer, baseUrl, chainId, verifyingContract = "" }) {
58
+ this.#signer = signer;
59
+ this.#baseUrl = baseUrl.replace(/\/$/, "");
60
+ this.#chainId = chainId;
61
+ this.#verifyingContract = verifyingContract;
62
+ // Parse path prefix from baseUrl so signed path matches OriginalUri on server.
63
+ const parsedUrl = new URL(this.#baseUrl);
64
+ this.#signPathPrefix = parsedUrl.pathname.replace(/\/$/, "");
65
+ }
66
+ async get(path) {
67
+ return this.#request("GET", path);
68
+ }
69
+ async post(path, body) {
70
+ return this.#request("POST", path, body);
71
+ }
72
+ async put(path, body) {
73
+ return this.#request("PUT", path, body);
74
+ }
75
+ async delete(path) {
76
+ return this.#request("DELETE", path);
77
+ }
78
+ async #request(method, path, body, attempt = 0) {
79
+ const timestamp = Math.floor(Date.now() / 1000);
80
+ const nonce = newNonce();
81
+ const domain = {
82
+ name: "remit.md",
83
+ version: "0.1",
84
+ chainId: this.#chainId,
85
+ verifyingContract: this.#verifyingContract,
86
+ };
87
+ // Sign the full path (prefix + relative path only, no query string) so it matches
88
+ // the path OriginalUri on the server. The server verifies only the path component.
89
+ // e.g. baseUrl "http://…/api/v0" + path "/events?wallet=0x…" → signed "/api/v0/events"
90
+ const pathOnly = path.split("?")[0];
91
+ const signedPath = `${this.#signPathPrefix}${pathOnly}`;
92
+ // Sign the request metadata (never body — body may be large)
93
+ const signature = await this.#signer.signTypedData(domain,
94
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
+ EIP712_TYPES, { method, path: signedPath, timestamp: BigInt(timestamp), nonce });
96
+ const headers = {
97
+ "Content-Type": "application/json",
98
+ "X-Remit-Agent": this.#signer.getAddress(),
99
+ "X-Remit-Signature": signature,
100
+ "X-Remit-Timestamp": String(timestamp),
101
+ "X-Remit-Nonce": nonce,
102
+ };
103
+ if (method === "POST" || method === "PUT" || method === "PATCH") {
104
+ headers["X-Idempotency-Key"] = newIdempotencyKey();
105
+ }
106
+ let response;
107
+ try {
108
+ response = await fetch(`${this.#baseUrl}${path}`, {
109
+ method,
110
+ headers,
111
+ body: body !== undefined ? JSON.stringify(body) : undefined,
112
+ });
113
+ }
114
+ catch (err) {
115
+ throw new NetworkError(`Network request failed: ${String(err)}`);
116
+ }
117
+ if (response.ok) {
118
+ if (response.status === 204)
119
+ return undefined;
120
+ return camelizeKeys(await response.json());
121
+ }
122
+ // Retryable errors
123
+ if (RETRYABLE.has(response.status) && attempt < DELAY_MS.length) {
124
+ if (response.status === 429) {
125
+ // Respect Retry-After header if present
126
+ const retryAfter = response.headers.get("Retry-After");
127
+ const delay = retryAfter ? parseInt(retryAfter) * 1000 : DELAY_MS[attempt];
128
+ await sleep(delay);
129
+ }
130
+ else {
131
+ await sleep(DELAY_MS[attempt]);
132
+ }
133
+ return this.#request(method, path, body, attempt + 1);
134
+ }
135
+ // Parse error body
136
+ let errorBody = {};
137
+ try {
138
+ errorBody = (await response.json());
139
+ }
140
+ catch {
141
+ // ignore parse failures
142
+ }
143
+ const code = errorBody.error?.code ?? errorBody.code ?? `HTTP_${response.status}`;
144
+ const message = errorBody.error?.message ?? errorBody.message ?? response.statusText;
145
+ if (response.status === 429)
146
+ throw new RateLimitedError(message);
147
+ throw fromErrorCode(code, message);
148
+ }
149
+ }
150
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG5E,yEAAyE;AACzE,wCAAwC;AACxC,iDAAiD;AACjD,mCAAmC;AACnC,MAAM,YAAY,GAAG;IACnB,UAAU,EAAE;QACV,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;QAClC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;QAChC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;QACtC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;KACnC;CACO,CAAC;AAQX,6EAA6E;AAC7E,SAAS,QAAQ;IACf,OAAO,KAAK,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;AAChD,CAAC;A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AAM,CAAC;YACP,wBAAwB;QAC1B,CAAC;QAED,MAAM,IAAI,GACR,SAAS,CAAC,KAAK,EAAE,IAAI,IAAI,SAAS,CAAC,IAAI,IAAI,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC;QACvE,MAAM,OAAO,GACX,SAAS,CAAC,KAAK,EAAE,OAAO,IAAI,SAAS,CAAC,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC;QAEvE,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;YAAE,MAAM,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACjE,MAAM,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ export { discoverAgent, A2AClient, getTaskTxHash, } from "./a2a.js";
2
+ export type { AgentCard, A2ACapabilities, A2AExtension, A2ASkill, A2AX402, A2AFees, A2ATask, A2ATaskStatus, A2AArtifact, A2AArtifactPart, IntentMandate, SendOptions, A2AClientOptions, } from "./a2a.js";
3
+ export { RemitClient } from "./client.js";
4
+ export { Wallet } from "./wallet.js";
5
+ export type { WalletOptions, OpenTabOptions, CloseTabOptions, ChargeTabOptions, OpenStreamOptions, PostBountyOptions, PlaceDepositOptions, PermitSignature, SignPermitOptions, } from "./wallet.js";
6
+ export { PrivateKeySigner } from "./signer.js";
7
+ export type { Signer, TypedDataDomain, TypedDataTypes } from "./signer.js";
8
+ export { RemitError, fromErrorCode, InvalidSignatureError, NonceReusedError, TimestampExpiredError, UnauthorizedError, InsufficientBalanceError, BelowMinimumError, EscrowNotFoundError, EscrowAlreadyFundedError, EscrowExpiredError, InvalidInvoiceError, DuplicateInvoiceError, SelfPaymentError, InvalidPaymentTypeError, TabDepletedError, TabExpiredError, TabNotFoundError, StreamNotFoundError, RateExceedsCapError, BountyExpiredError, BountyClaimedError, BountyMaxAttemptsError, BountyNotFoundError, ChainMismatchError, ChainUnsupportedError, RateLimitedError, CancelBlockedClaimStartError, CancelBlockedEvidenceError, VersionMismatchError, NetworkError, } from "./errors.js";
9
+ export * from "./models/index.js";
10
+ export { MockRemit, MockWallet } from "./testing/mock.js";
11
+ export { LocalChain } from "./testing/local.js";
12
+ export { X402Client, AllowanceExceededError } from "./x402.js";
13
+ export type { X402ClientOptions } from "./x402.js";
14
+ export { X402Paywall } from "./provider.js";
15
+ export type { PaywallOptions, CheckResult } from "./provider.js";
16
+ export { remitTools } from "./integrations/vercel-ai.js";
17
+ export type { RemitToolDescriptor } from "./integrations/vercel-ai.js";
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,SAAS,EACT,aAAa,GACd,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,SAAS,EACT,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,OAAO,EACP,OAAO,EACP,aAAa,EACb,WAAW,EACX,eAAe,EACf,aAAa,EACb,WAAW,EACX,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EACV,aAAa,EACb,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG3E,OAAO,EACL,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,4BAA4B,EAC5B,0BAA0B,EAC1B,oBAAoB,EACpB,YAAY,GACb,MAAM,aAAa,CAAC;AAGrB,cAAc,mBAAmB,CAAC;AAGlC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAC/D,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGjE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,YAAY,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ // A2A / AP2
2
+ export { discoverAgent, A2AClient, getTaskTxHash, } from "./a2a.js";
3
+ // Core classes
4
+ export { RemitClient } from "./client.js";
5
+ export { Wallet } from "./wallet.js";
6
+ // Signers
7
+ export { PrivateKeySigner } from "./signer.js";
8
+ // Errors
9
+ export { RemitError, fromErrorCode, InvalidSignatureError, NonceReusedError, TimestampExpiredError, UnauthorizedError, InsufficientBalanceError, BelowMinimumError, EscrowNotFoundError, EscrowAlreadyFundedError, EscrowExpiredError, InvalidInvoiceError, DuplicateInvoiceError, SelfPaymentError, InvalidPaymentTypeError, TabDepletedError, TabExpiredError, TabNotFoundError, StreamNotFoundError, RateExceedsCapError, BountyExpiredError, BountyClaimedError, BountyMaxAttemptsError, BountyNotFoundError, ChainMismatchError, ChainUnsupportedError, RateLimitedError, CancelBlockedClaimStartError, CancelBlockedEvidenceError, VersionMismatchError, NetworkError, } from "./errors.js";
10
+ // Models
11
+ export * from "./models/index.js";
12
+ // Testing utilities
13
+ export { MockRemit, MockWallet } from "./testing/mock.js";
14
+ export { LocalChain } from "./testing/local.js";
15
+ // x402 client middleware
16
+ export { X402Client, AllowanceExceededError } from "./x402.js";
17
+ // x402 provider middleware
18
+ export { X402Paywall } from "./provider.js";
19
+ // Integrations
20
+ export { remitTools } from "./integrations/vercel-ai.js";
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,OAAO,EACL,aAAa,EACb,SAAS,EACT,aAAa,GACd,MAAM,UAAU,CAAC;AAiBlB,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAarC,UAAU;AACV,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,SAAS;AACT,OAAO,EACL,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,4BAA4B,EAC5B,0BAA0B,EAC1B,oBAAoB,EACpB,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,SAAS;AACT,cAAc,mBAAmB,CAAC;AAElC,oBAAoB;AACpB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,yBAAyB;AACzB,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAG/D,2BAA2B;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,eAAe;AACf,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Vercel AI SDK integration for remit.md.
3
+ *
4
+ * Usage with the Vercel AI SDK:
5
+ *
6
+ * import { generateText } from "ai";
7
+ * import { anthropic } from "@ai-sdk/anthropic";
8
+ * import { Wallet } from "@remitmd/sdk";
9
+ * import { remitTools } from "@remitmd/sdk/integrations/vercel-ai";
10
+ *
11
+ * const wallet = Wallet.fromEnv();
12
+ * const result = await generateText({
13
+ * model: anthropic("claude-opus-4-6"),
14
+ * tools: remitTools(wallet),
15
+ * prompt: "Pay agent@example.com $5 for the data analysis.",
16
+ * });
17
+ *
18
+ * Note: This module exports plain tool descriptors compatible with the AI SDK tool()
19
+ * format. Import `tool` from "ai" and `z` from "zod" in your application — we don't
20
+ * bundle them to avoid version conflicts.
21
+ */
22
+ import type { Wallet } from "../wallet.js";
23
+ /** Parameter schema for a remit tool (zod-compatible shape description). */
24
+ interface ToolParam {
25
+ type: "string" | "number" | "boolean";
26
+ description: string;
27
+ optional?: boolean;
28
+ }
29
+ /** Lightweight tool descriptor — compatible with Vercel AI SDK `tool()` format. */
30
+ export interface RemitToolDescriptor {
31
+ description: string;
32
+ parameters: Record<string, ToolParam>;
33
+ execute: (...args: unknown[]) => Promise<unknown>;
34
+ }
35
+ /**
36
+ * Returns remit.md payment tools configured for the given wallet.
37
+ * Pass the result directly as the `tools` parameter to `generateText` / `streamText`.
38
+ *
39
+ * Compatible with Vercel AI SDK v3+. Each entry is a plain object with
40
+ * `description`, `parameters`, and `execute` — wrap with `tool()` from "ai" if needed.
41
+ */
42
+ export declare function remitTools(wallet: Wallet): Record<string, RemitToolDescriptor>;
43
+ export {};
44
+ //# sourceMappingURL=vercel-ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vercel-ai.d.ts","sourceRoot":"","sources":["../../src/integrations/vercel-ai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,4EAA4E;AAC5E,UAAU,SAAS;IACjB,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,mFAAmF;AACnF,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACtC,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACnD;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAuK9E"}