openany-cli-dev 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +472 -2
- package/bin/openany.js +3 -0
- package/package.json +27 -4
- package/skills/openany/SKILL.md +353 -0
- package/skills/openany/SKILL.zh-CN.md +496 -0
- package/skills/openany-provider/SKILL.md +26 -0
- package/skills/openany-provider/SKILL.zh-CN.md +26 -0
- package/skills/openany-provider/references/apis.md +60 -0
- package/skills/openany-provider/references/apis.zh-CN.md +55 -0
- package/skills/openany-provider/references/application.md +49 -0
- package/skills/openany-provider/references/application.zh-CN.md +51 -0
- package/skills/openany-provider/references/auth.md +3 -0
- package/skills/openany-provider/references/auth.zh-CN.md +3 -0
- package/skills/openany-provider/references/connections.md +36 -0
- package/skills/openany-provider/references/connections.zh-CN.md +36 -0
- package/skills/openany-provider/references/imports.md +57 -0
- package/skills/openany-provider/references/imports.zh-CN.md +57 -0
- package/skills/openany-provider/references/listing.md +29 -0
- package/skills/openany-provider/references/listing.zh-CN.md +11 -0
- package/skills/openany-provider/references/login.md +57 -0
- package/skills/openany-provider/references/login.zh-CN.md +57 -0
- package/skills/openany-provider/references/model-import.md +11 -0
- package/skills/openany-provider/references/model-import.zh-CN.md +11 -0
- package/skills/openany-provider/references/models.md +107 -0
- package/skills/openany-provider/references/models.zh-CN.md +68 -0
- package/skills/openany-provider/references/publishing.md +40 -0
- package/skills/openany-provider/references/publishing.zh-CN.md +40 -0
- package/skills/openany-provider/references/reviews.md +22 -0
- package/skills/openany-provider/references/reviews.zh-CN.md +20 -0
- package/skills/openany-provider/templates/api-metadata.json +27 -0
- package/skills/openany-provider/templates/bindings.json +1 -0
- package/skills/openany-provider/templates/models-v2.json +545 -0
- package/skills/openany-provider/templates/models.json +10 -0
- package/skills/openany-provider/templates/provider-agent-api-template.json +697 -0
- package/skills/openany-provider/templates/seller-agent-api-import-template.json +822 -0
- package/skills/openany-provider/templates/seller-registration.json +26 -0
- package/src/auth-recovery.js +179 -0
- package/src/auth.js +1001 -0
- package/src/catalog.js +306 -0
- package/src/cli.js +605 -0
- package/src/config.js +260 -0
- package/src/errors.js +53 -0
- package/src/http.js +238 -0
- package/src/model-curl.js +359 -0
- package/src/model-materials.js +58 -0
- package/src/model-request.js +402 -0
- package/src/model-validation.js +56 -0
- package/src/models.js +188 -0
- package/src/native/config-acl.ps1 +34 -0
- package/src/native/connection-macos.js +109 -0
- package/src/native/connection-windows.ps1 +98 -0
- package/src/native/setup-macos.js +72 -0
- package/src/native/setup-windows.ps1 +83 -0
- package/src/native-prompt.js +85 -0
- package/src/payment-signing.js +362 -0
- package/src/prompt.js +69 -0
- package/src/provider-api-import-v2.js +72 -0
- package/src/provider-apis.js +3 -0
- package/src/provider-client.js +153 -0
- package/src/provider-connections.js +152 -0
- package/src/provider-import-format.js +289 -0
- package/src/provider-imports.js +402 -0
- package/src/provider-json.js +49 -0
- package/src/provider-model-import-v2.js +61 -0
- package/src/provider-models.js +253 -0
- package/src/provider-profile.js +65 -0
- package/src/provider-reviews.js +61 -0
- package/src/provider-state.js +176 -0
- package/src/provider.js +75 -0
- package/src/setup.js +201 -0
- package/src/tasks.js +53 -0
- package/src/topups.js +845 -0
- package/src/vendor/provider-apply/market-taxonomy.mjs +22 -0
- package/src/vendor/provider-apply/provenance.json +8 -0
- package/src/vendor/provider-apply/registration.mjs +151 -0
- package/src/vendor/provider-import/api-categories.json +29 -0
- package/src/vendor/provider-import/api-fields.json +33 -0
- package/src/vendor/provider-import/model-fields.json +44 -0
- package/src/wallet.js +213 -0
- package/src/windows-permissions.js +22 -0
package/src/topups.js
ADDED
|
@@ -0,0 +1,845 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { CLIError, requireValue } from "./errors.js";
|
|
4
|
+
import { unwrap } from "./http.js";
|
|
5
|
+
import { AuthService, SIGNING_ORIGIN } from "./auth.js";
|
|
6
|
+
import { getWallet, sameWallet, isEVM } from "./wallet.js";
|
|
7
|
+
import {
|
|
8
|
+
preparePayment,
|
|
9
|
+
completePayment,
|
|
10
|
+
integer,
|
|
11
|
+
BASE_NETWORK,
|
|
12
|
+
SOLANA_NETWORK,
|
|
13
|
+
} from "./payment-signing.js";
|
|
14
|
+
const label = (value) => {
|
|
15
|
+
if (
|
|
16
|
+
typeof value !== "string" ||
|
|
17
|
+
!/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(value) ||
|
|
18
|
+
["constructor", "prototype", "__proto__"].includes(value)
|
|
19
|
+
)
|
|
20
|
+
throw new CLIError(
|
|
21
|
+
"INPUT_INVALID",
|
|
22
|
+
"scope/intent must contain 1–64 safe label characters.",
|
|
23
|
+
);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
const identifier = (value) => {
|
|
27
|
+
if (
|
|
28
|
+
typeof value !== "string" ||
|
|
29
|
+
!value ||
|
|
30
|
+
/[\/\\?#\s%]/.test(value) ||
|
|
31
|
+
value === "." ||
|
|
32
|
+
value === ".."
|
|
33
|
+
)
|
|
34
|
+
throw new CLIError("INPUT_INVALID", "Invalid order ID.");
|
|
35
|
+
return encodeURIComponent(value);
|
|
36
|
+
};
|
|
37
|
+
export function usdToMicro(value) {
|
|
38
|
+
if (typeof value !== "string" || !/^\d+(?:\.\d{1,6})?$/.test(value))
|
|
39
|
+
throw new CLIError(
|
|
40
|
+
"INPUT_INVALID",
|
|
41
|
+
"USD amounts must be positive numeric strings with at most six decimal places.",
|
|
42
|
+
);
|
|
43
|
+
const [whole, fraction = ""] = value.split(".");
|
|
44
|
+
const amount = BigInt(whole) * 1000000n + BigInt(fraction.padEnd(6, "0"));
|
|
45
|
+
if (amount <= 0n || amount > BigInt(Number.MAX_SAFE_INTEGER))
|
|
46
|
+
throw new CLIError("INPUT_INVALID", "The amount must be positive and within the safe integer range.");
|
|
47
|
+
return String(amount);
|
|
48
|
+
}
|
|
49
|
+
function summary(intent) {
|
|
50
|
+
return {
|
|
51
|
+
intent: intent.name,
|
|
52
|
+
scope: intent.scope,
|
|
53
|
+
identity: intent.identity,
|
|
54
|
+
network: intent.network,
|
|
55
|
+
phase: intent.phase,
|
|
56
|
+
orderId: intent.orderId,
|
|
57
|
+
quote: intent.order?.quote,
|
|
58
|
+
paymentStatus: intent.order?.paymentStatus,
|
|
59
|
+
creditStatus: intent.order?.creditStatus,
|
|
60
|
+
paymentExpiresAt: intent.order?.paymentExpiresAt,
|
|
61
|
+
accountUsable: intent.order?.accountUsable,
|
|
62
|
+
credited:
|
|
63
|
+
intent.order?.paymentStatus === "paid" &&
|
|
64
|
+
intent.order?.creditStatus === "credited" &&
|
|
65
|
+
(intent.identity === "email" || intent.order?.accountUsable === true),
|
|
66
|
+
reservedMicroUsd: intent.reservedMicroUsd,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function consumed(state, scope, exclude) {
|
|
70
|
+
return Object.values(state.intents)
|
|
71
|
+
.filter((i) => i.scope === scope && i.name !== exclude)
|
|
72
|
+
.reduce((sum, i) => sum + BigInt(i.reservedMicroUsd || "0"), 0n);
|
|
73
|
+
}
|
|
74
|
+
function budget(state, policy, amount, exclude) {
|
|
75
|
+
if (
|
|
76
|
+
BigInt(amount) > BigInt(policy.maxSingleMicroUsd) ||
|
|
77
|
+
consumed(state, policy.scope, exclude) + BigInt(amount) >
|
|
78
|
+
BigInt(policy.maxTotalMicroUsd)
|
|
79
|
+
)
|
|
80
|
+
throw new CLIError(
|
|
81
|
+
"BUDGET_EXCEEDED",
|
|
82
|
+
"The top-up amount, including fees and reserved orders, exceeds the authorized budget.",
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
const incompleteSnapshot = (record) =>
|
|
86
|
+
!record.order?.quote ||
|
|
87
|
+
!record.order?.paymentRequired ||
|
|
88
|
+
(record.identity === "wallet" && !record.order?.availableNetworks);
|
|
89
|
+
const recoverableSnapshot = (record) =>
|
|
90
|
+
record.submissionStartedAt === undefined &&
|
|
91
|
+
record.order?.paymentStatus === "created" &&
|
|
92
|
+
record.order?.creditStatus === "uncredited" &&
|
|
93
|
+
incompleteSnapshot(record);
|
|
94
|
+
export class TopupService {
|
|
95
|
+
constructor(ctx) {
|
|
96
|
+
this.env = ctx.env || process.env;
|
|
97
|
+
this.store = ctx.store;
|
|
98
|
+
this.http = ctx.http;
|
|
99
|
+
this.now = ctx.now || (() => Date.now());
|
|
100
|
+
this.secrets = ctx.secrets || [];
|
|
101
|
+
this.auth = new AuthService({ ...ctx, now: this.now });
|
|
102
|
+
}
|
|
103
|
+
async credential(identity, { workspace, walletAddress } = {}) {
|
|
104
|
+
if (identity === "email") return this.auth.emailCredential({ workspace });
|
|
105
|
+
if (identity !== "wallet")
|
|
106
|
+
throw new CLIError(
|
|
107
|
+
"INPUT_INVALID",
|
|
108
|
+
"--identity must be wallet or email.",
|
|
109
|
+
);
|
|
110
|
+
const session = (await this.store.read()).sessions.wallet;
|
|
111
|
+
if (
|
|
112
|
+
!session?.token ||
|
|
113
|
+
!Number.isFinite(Date.parse(session.expiresAt)) ||
|
|
114
|
+
Date.parse(session.expiresAt) <= this.now()
|
|
115
|
+
)
|
|
116
|
+
throw new CLIError(
|
|
117
|
+
"CONFIG_REQUIRED",
|
|
118
|
+
"Run auth wallet first to obtain a valid session.",
|
|
119
|
+
{ missing: ["wallet_session"] },
|
|
120
|
+
);
|
|
121
|
+
const address =
|
|
122
|
+
walletAddress ||
|
|
123
|
+
getWallet(this.env, { requirePrivateKey: false }).address;
|
|
124
|
+
if (!sameWallet(session.walletAddress, address))
|
|
125
|
+
throw new CLIError("ACCOUNT_MISMATCH", "The wallet session does not match the target payment wallet.");
|
|
126
|
+
this.secrets.push(session.token);
|
|
127
|
+
return { token: session.token };
|
|
128
|
+
}
|
|
129
|
+
async target(identity, { workspace, walletAddress } = {}) {
|
|
130
|
+
if (!this.http.apiKey)
|
|
131
|
+
throw new CLIError("CONFIG_REQUIRED", "Configure an API key for the target account first.", {
|
|
132
|
+
missing: ["OPENANY_DEV_API_KEY"],
|
|
133
|
+
});
|
|
134
|
+
const credential = await this.credential(identity, {
|
|
135
|
+
workspace,
|
|
136
|
+
walletAddress,
|
|
137
|
+
});
|
|
138
|
+
const account = unwrap(
|
|
139
|
+
await this.http.backend("/api/v1/agent-api-account", { auth: "apiKey" }),
|
|
140
|
+
);
|
|
141
|
+
if (!account?.accountId)
|
|
142
|
+
throw new CLIError("INVALID_RESPONSE", "The balance response is missing the account ID.");
|
|
143
|
+
if (identity === "wallet") {
|
|
144
|
+
const loggedIn = unwrap(
|
|
145
|
+
await this.http.backend("/api/v1/agent-api-account", { credential }),
|
|
146
|
+
);
|
|
147
|
+
if (loggedIn?.accountId !== account.accountId)
|
|
148
|
+
throw new CLIError(
|
|
149
|
+
"ACCOUNT_MISMATCH",
|
|
150
|
+
"The API key and wallet session do not belong to the same balance account.",
|
|
151
|
+
);
|
|
152
|
+
} else {
|
|
153
|
+
if (!account.apiKey?.id)
|
|
154
|
+
throw new CLIError("INVALID_RESPONSE", "The balance response is missing the current API key ID.");
|
|
155
|
+
const seen = new Set();
|
|
156
|
+
let found = false;
|
|
157
|
+
for (let offset = 0; offset < 100000; offset += 100) {
|
|
158
|
+
const keys = unwrap(
|
|
159
|
+
await this.http.backend("/api/v1/key-market/api-keys", {
|
|
160
|
+
credential,
|
|
161
|
+
query: { limit: 100, offset },
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
if (!Array.isArray(keys))
|
|
165
|
+
throw new CLIError("INVALID_RESPONSE", "The server key list has an invalid format.");
|
|
166
|
+
if (keys.some((k) => k.id === account.apiKey.id)) {
|
|
167
|
+
found = true;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
if (keys.length < 100) break;
|
|
171
|
+
const fingerprint = JSON.stringify(keys.map((k) => k.id));
|
|
172
|
+
if (seen.has(fingerprint))
|
|
173
|
+
throw new CLIError("PAGINATION_STALLED", "Key list pagination did not advance.");
|
|
174
|
+
seen.add(fingerprint);
|
|
175
|
+
}
|
|
176
|
+
if (!found)
|
|
177
|
+
throw new CLIError(
|
|
178
|
+
"ACCOUNT_MISMATCH",
|
|
179
|
+
"The current API key does not belong to the selected workspace.",
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
accountId: account.accountId,
|
|
184
|
+
workspaceId: credential.workspaceId,
|
|
185
|
+
credential,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
async authorize({
|
|
189
|
+
identity,
|
|
190
|
+
network,
|
|
191
|
+
maxSingleUsd,
|
|
192
|
+
maxTotalUsd,
|
|
193
|
+
scope,
|
|
194
|
+
expiresAt,
|
|
195
|
+
workspace,
|
|
196
|
+
} = {}) {
|
|
197
|
+
label(scope);
|
|
198
|
+
if (!["wallet", "email"].includes(identity))
|
|
199
|
+
throw new CLIError("INPUT_REQUIRED", "Specify --identity wallet|email.");
|
|
200
|
+
const networks = String(requireValue(network, "--network")).split(",");
|
|
201
|
+
if (
|
|
202
|
+
networks.some(
|
|
203
|
+
(n) => !/^eip155:[1-9][0-9]*$/.test(n) && n !== SOLANA_NETWORK,
|
|
204
|
+
) ||
|
|
205
|
+
new Set(networks).size !== networks.length
|
|
206
|
+
)
|
|
207
|
+
throw new CLIError("INPUT_INVALID", "The network must be an explicit CAIP-2 identifier.");
|
|
208
|
+
if (
|
|
209
|
+
identity === "email" &&
|
|
210
|
+
networks.some((n) => ![BASE_NETWORK, SOLANA_NETWORK].includes(n))
|
|
211
|
+
)
|
|
212
|
+
throw new CLIError(
|
|
213
|
+
"INPUT_INVALID",
|
|
214
|
+
"Email accounts only support Base and Solana mainnet.",
|
|
215
|
+
);
|
|
216
|
+
if (identity === "wallet" && networks.some((n) => !n.startsWith("eip155:")))
|
|
217
|
+
throw new CLIError("INPUT_INVALID", "Wallet agent top-ups only support EVM networks.");
|
|
218
|
+
const wallet = getWallet(this.env, { requirePrivateKey: false });
|
|
219
|
+
if (
|
|
220
|
+
(networks.some((n) => n.startsWith("eip155:")) &&
|
|
221
|
+
!isEVM(wallet.address)) ||
|
|
222
|
+
(networks.includes(SOLANA_NETWORK) && isEVM(wallet.address))
|
|
223
|
+
)
|
|
224
|
+
throw new CLIError("WALLET_MISMATCH", "The authorized network does not match the payment wallet type.");
|
|
225
|
+
const maxSingleMicroUsd = usdToMicro(maxSingleUsd),
|
|
226
|
+
maxTotalMicroUsd = usdToMicro(maxTotalUsd);
|
|
227
|
+
if (
|
|
228
|
+
!Number.isFinite(Date.parse(expiresAt)) ||
|
|
229
|
+
Date.parse(expiresAt) <= this.now()
|
|
230
|
+
)
|
|
231
|
+
throw new CLIError(
|
|
232
|
+
"INPUT_INVALID",
|
|
233
|
+
"Specify a future ISO timestamp for --expires-at.",
|
|
234
|
+
);
|
|
235
|
+
const target = await this.target(identity, {
|
|
236
|
+
workspace,
|
|
237
|
+
walletAddress: wallet.address,
|
|
238
|
+
});
|
|
239
|
+
const policy = {
|
|
240
|
+
scope,
|
|
241
|
+
identity,
|
|
242
|
+
networks,
|
|
243
|
+
walletAddress: wallet.address,
|
|
244
|
+
accountId: target.accountId,
|
|
245
|
+
workspaceId: target.workspaceId,
|
|
246
|
+
maxSingleMicroUsd,
|
|
247
|
+
maxTotalMicroUsd,
|
|
248
|
+
expiresAt,
|
|
249
|
+
};
|
|
250
|
+
await this.store.update((s) => {
|
|
251
|
+
s.paymentPolicies ||= {};
|
|
252
|
+
const old = s.paymentPolicies[scope];
|
|
253
|
+
if (
|
|
254
|
+
old &&
|
|
255
|
+
(old.identity !== identity ||
|
|
256
|
+
old.accountId !== policy.accountId ||
|
|
257
|
+
old.walletAddress !== policy.walletAddress ||
|
|
258
|
+
old.workspaceId !== policy.workspaceId)
|
|
259
|
+
)
|
|
260
|
+
throw new CLIError(
|
|
261
|
+
"POLICY_TARGET_CHANGED",
|
|
262
|
+
"The top-up target cannot be changed within the same scope.",
|
|
263
|
+
);
|
|
264
|
+
if (consumed(s, scope) > BigInt(maxTotalMicroUsd))
|
|
265
|
+
throw new CLIError("BUDGET_EXCEEDED", "The new budget is below the amount already reserved or paid.");
|
|
266
|
+
s.paymentPolicies[scope] = policy;
|
|
267
|
+
});
|
|
268
|
+
return {
|
|
269
|
+
authorized: true,
|
|
270
|
+
...policy,
|
|
271
|
+
reservedMicroUsd: String(consumed(await this.store.read(), scope)),
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
async policy(scope) {
|
|
275
|
+
label(scope);
|
|
276
|
+
const policy = (await this.store.read()).paymentPolicies?.[scope];
|
|
277
|
+
if (!policy || Date.parse(policy.expiresAt) <= this.now())
|
|
278
|
+
throw new CLIError(
|
|
279
|
+
"PAYMENT_AUTH_REQUIRED",
|
|
280
|
+
"Obtain user authorization and configure a valid top-up policy first.",
|
|
281
|
+
{ scope },
|
|
282
|
+
);
|
|
283
|
+
return policy;
|
|
284
|
+
}
|
|
285
|
+
async create({
|
|
286
|
+
scope,
|
|
287
|
+
intent,
|
|
288
|
+
amountUsd,
|
|
289
|
+
network,
|
|
290
|
+
prepare = false,
|
|
291
|
+
resume = false,
|
|
292
|
+
} = {}) {
|
|
293
|
+
label(intent);
|
|
294
|
+
const policy = await this.policy(scope),
|
|
295
|
+
amount = usdToMicro(amountUsd);
|
|
296
|
+
if (!policy.networks.includes(network))
|
|
297
|
+
throw new CLIError("PAYMENT_AUTH_REQUIRED", "The selected network is not authorized.");
|
|
298
|
+
const signer = getWallet(this.env, { requirePrivateKey: !prepare });
|
|
299
|
+
if (!sameWallet(signer.address, policy.walletAddress))
|
|
300
|
+
throw new CLIError("WALLET_MISMATCH", "The wallet has changed.");
|
|
301
|
+
const agentId = this.env.OPENANY_DEV_AGENT_ID;
|
|
302
|
+
if (
|
|
303
|
+
policy.identity === "wallet" &&
|
|
304
|
+
(!agentId || !/^[A-Za-z0-9._:-]{6,128}$/.test(agentId))
|
|
305
|
+
)
|
|
306
|
+
throw new CLIError("CONFIG_REQUIRED", "Configure OPENANY_DEV_AGENT_ID.", {
|
|
307
|
+
missing: ["OPENANY_DEV_AGENT_ID"],
|
|
308
|
+
});
|
|
309
|
+
let record = (await this.store.read()).intents[intent];
|
|
310
|
+
if (record) {
|
|
311
|
+
if (
|
|
312
|
+
record.scope !== scope ||
|
|
313
|
+
record.inputMicroUsd !== amount ||
|
|
314
|
+
record.network !== network
|
|
315
|
+
)
|
|
316
|
+
throw new CLIError(
|
|
317
|
+
"INTENT_CONFLICT",
|
|
318
|
+
"The account, amount and network cannot be changed within the same intent.",
|
|
319
|
+
);
|
|
320
|
+
if (record.orderId) {
|
|
321
|
+
if (
|
|
322
|
+
!resume ||
|
|
323
|
+
record.submissionStartedAt !== undefined ||
|
|
324
|
+
!incompleteSnapshot(record)
|
|
325
|
+
)
|
|
326
|
+
return summary(record);
|
|
327
|
+
await this.get({ intent });
|
|
328
|
+
record = (await this.store.read()).intents[intent];
|
|
329
|
+
if (!recoverableSnapshot(record)) return summary(record);
|
|
330
|
+
}
|
|
331
|
+
if (
|
|
332
|
+
!resume ||
|
|
333
|
+
(record.phase === "creating" && this.now() - record.startedAt < 120000)
|
|
334
|
+
)
|
|
335
|
+
throw new CLIError(
|
|
336
|
+
"CREATE_UNCERTAIN",
|
|
337
|
+
"The creation result is unconfirmed; wait for the in-flight request to finish, then resume with the same parameters and --resume.",
|
|
338
|
+
{ intent },
|
|
339
|
+
);
|
|
340
|
+
} else budget(await this.store.read(), policy, amount);
|
|
341
|
+
const target = await this.target(policy.identity, {
|
|
342
|
+
workspace: policy.workspaceId,
|
|
343
|
+
walletAddress: policy.walletAddress,
|
|
344
|
+
});
|
|
345
|
+
if (target.accountId !== policy.accountId)
|
|
346
|
+
throw new CLIError("ACCOUNT_MISMATCH", "The top-up target for the current key has changed.");
|
|
347
|
+
const body =
|
|
348
|
+
policy.identity === "wallet"
|
|
349
|
+
? { agentId, inputAmountMicroUsd: amount }
|
|
350
|
+
: {
|
|
351
|
+
amountMicroUsd: Number(amount),
|
|
352
|
+
walletAddress: policy.walletAddress,
|
|
353
|
+
network,
|
|
354
|
+
};
|
|
355
|
+
await this.store.update((s) => {
|
|
356
|
+
const current = s.intents[intent];
|
|
357
|
+
if (
|
|
358
|
+
current?.orderId &&
|
|
359
|
+
(!resume ||
|
|
360
|
+
current.orderId !== record?.orderId ||
|
|
361
|
+
!recoverableSnapshot(current))
|
|
362
|
+
)
|
|
363
|
+
throw new CLIError("INTENT_CONFLICT", "The order has already been created; query the original order.");
|
|
364
|
+
if (current && !resume)
|
|
365
|
+
throw new CLIError("CREATE_UNCERTAIN", "A creation request with this name already exists.");
|
|
366
|
+
budget(s, policy, amount, intent);
|
|
367
|
+
record = current || {
|
|
368
|
+
name: intent,
|
|
369
|
+
scope,
|
|
370
|
+
identity: policy.identity,
|
|
371
|
+
accountId: policy.accountId,
|
|
372
|
+
workspaceId: policy.workspaceId,
|
|
373
|
+
walletAddress: policy.walletAddress,
|
|
374
|
+
network,
|
|
375
|
+
inputMicroUsd: amount,
|
|
376
|
+
body,
|
|
377
|
+
idempotencyKey: randomUUID(),
|
|
378
|
+
};
|
|
379
|
+
if (
|
|
380
|
+
record.scope !== scope ||
|
|
381
|
+
record.inputMicroUsd !== amount ||
|
|
382
|
+
record.network !== network ||
|
|
383
|
+
JSON.stringify(record.body) !== JSON.stringify(body)
|
|
384
|
+
)
|
|
385
|
+
throw new CLIError("INTENT_CONFLICT", "The resumed request body differs from the original request.");
|
|
386
|
+
record.phase = "creating";
|
|
387
|
+
record.startedAt = this.now();
|
|
388
|
+
record.reservedMicroUsd = String(
|
|
389
|
+
BigInt(record.reservedMicroUsd || "0") > BigInt(amount)
|
|
390
|
+
? BigInt(record.reservedMicroUsd)
|
|
391
|
+
: BigInt(amount),
|
|
392
|
+
);
|
|
393
|
+
s.intents[intent] = record;
|
|
394
|
+
});
|
|
395
|
+
const path =
|
|
396
|
+
record.identity === "wallet"
|
|
397
|
+
? "/api/v1/agent-topups"
|
|
398
|
+
: "/api/v1/key-market/x402/topups";
|
|
399
|
+
let response;
|
|
400
|
+
try {
|
|
401
|
+
response = await this.http.backend(path, {
|
|
402
|
+
method: "POST",
|
|
403
|
+
json: record.body,
|
|
404
|
+
headers: { "Idempotency-Key": record.idempotencyKey },
|
|
405
|
+
credential: target.credential,
|
|
406
|
+
allowStatuses: [402],
|
|
407
|
+
});
|
|
408
|
+
} catch (error) {
|
|
409
|
+
await this.store.update((s) => {
|
|
410
|
+
s.intents[intent].phase = "create_uncertain";
|
|
411
|
+
});
|
|
412
|
+
throw error;
|
|
413
|
+
}
|
|
414
|
+
const result = unwrap(response);
|
|
415
|
+
if (!result?.orderId)
|
|
416
|
+
throw new CLIError(
|
|
417
|
+
"INVALID_RESPONSE",
|
|
418
|
+
"The creation response is missing the order ID; keep the intent and resume with the same idempotency key.",
|
|
419
|
+
{ intent },
|
|
420
|
+
);
|
|
421
|
+
if (record.orderId && record.orderId !== result.orderId)
|
|
422
|
+
throw new CLIError(
|
|
423
|
+
"INVALID_RESPONSE",
|
|
424
|
+
"The resumed response order ID differs from the original order; keep the original order.",
|
|
425
|
+
{ intent, orderId: record.orderId },
|
|
426
|
+
);
|
|
427
|
+
let order = { ...result, walletAddress: record.walletAddress, network };
|
|
428
|
+
// Preserve recovered identity before interpreting a replayed or malformed response.
|
|
429
|
+
await this.store.update((s) => {
|
|
430
|
+
s.intents[intent].orderId = result.orderId;
|
|
431
|
+
s.intents[intent].order = order;
|
|
432
|
+
s.intents[intent].phase = result.paymentStatus || "created";
|
|
433
|
+
});
|
|
434
|
+
if (record.identity === "wallet") {
|
|
435
|
+
if (response.status !== 402) return this.get({ intent });
|
|
436
|
+
try {
|
|
437
|
+
order.paymentRequired = JSON.parse(
|
|
438
|
+
Buffer.from(
|
|
439
|
+
response.headers.get("payment-required") || "",
|
|
440
|
+
"base64",
|
|
441
|
+
).toString("utf8"),
|
|
442
|
+
);
|
|
443
|
+
} catch {
|
|
444
|
+
throw new CLIError(
|
|
445
|
+
"INVALID_RESPONSE",
|
|
446
|
+
"A valid PAYMENT-REQUIRED payload is missing; nothing was signed.",
|
|
447
|
+
{ intent, orderId: result.orderId },
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
await this.store.update((s) => {
|
|
452
|
+
s.intents[intent].orderId = result.orderId;
|
|
453
|
+
s.intents[intent].order = order;
|
|
454
|
+
s.intents[intent].phase = "created";
|
|
455
|
+
});
|
|
456
|
+
if (record.identity === "wallet") {
|
|
457
|
+
await this.get({ intent });
|
|
458
|
+
order = (await this.store.read()).intents[intent].order;
|
|
459
|
+
}
|
|
460
|
+
if (integer(order.quote?.inputAmountMicroUsd) !== BigInt(amount))
|
|
461
|
+
throw new CLIError("PAYMENT_INVALID", "The quote input amount does not match the original request.");
|
|
462
|
+
// This validates resource, quote and network without producing a usable payment signature.
|
|
463
|
+
if (network !== SOLANA_NETWORK)
|
|
464
|
+
preparePayment(order, {
|
|
465
|
+
identity: record.identity,
|
|
466
|
+
network,
|
|
467
|
+
walletAddress: record.walletAddress,
|
|
468
|
+
now: this.now(),
|
|
469
|
+
signingOrigin: SIGNING_ORIGIN,
|
|
470
|
+
});
|
|
471
|
+
await this.store.update((s) => {
|
|
472
|
+
budget(s, policy, String(integer(order.quote.payAmountMicroUsd)), intent);
|
|
473
|
+
s.intents[intent].reservedMicroUsd = String(
|
|
474
|
+
integer(order.quote.payAmountMicroUsd),
|
|
475
|
+
);
|
|
476
|
+
});
|
|
477
|
+
return summary((await this.store.read()).intents[intent]);
|
|
478
|
+
}
|
|
479
|
+
async get({ intent, id, identity, workspace } = {}) {
|
|
480
|
+
let record;
|
|
481
|
+
if (intent) {
|
|
482
|
+
label(intent);
|
|
483
|
+
record = (await this.store.read()).intents[intent];
|
|
484
|
+
if (!record?.orderId)
|
|
485
|
+
throw new CLIError(
|
|
486
|
+
"ORDER_NOT_FOUND",
|
|
487
|
+
"No order ID is saved locally; resume creation with the original intent first.",
|
|
488
|
+
);
|
|
489
|
+
id = record.orderId;
|
|
490
|
+
identity = record.identity;
|
|
491
|
+
workspace = record.workspaceId;
|
|
492
|
+
}
|
|
493
|
+
const credential = await this.credential(identity, {
|
|
494
|
+
workspace,
|
|
495
|
+
walletAddress: record?.walletAddress,
|
|
496
|
+
});
|
|
497
|
+
const path =
|
|
498
|
+
identity === "wallet"
|
|
499
|
+
? "/api/v1/agent-topups/"
|
|
500
|
+
: "/api/v1/key-market/x402/topups/";
|
|
501
|
+
const order = unwrap(
|
|
502
|
+
await this.http.backend(
|
|
503
|
+
path + identifier(requireValue(id, "--id or --intent")),
|
|
504
|
+
{ credential },
|
|
505
|
+
),
|
|
506
|
+
);
|
|
507
|
+
if (order?.orderId !== id)
|
|
508
|
+
throw new CLIError("INVALID_RESPONSE", "The query returned a different order ID.");
|
|
509
|
+
if (record) {
|
|
510
|
+
await this.store.update((s) => {
|
|
511
|
+
const current = s.intents[intent];
|
|
512
|
+
if (
|
|
513
|
+
current.order?.quote &&
|
|
514
|
+
order.quote &&
|
|
515
|
+
JSON.stringify(current.order.quote) !== JSON.stringify(order.quote)
|
|
516
|
+
)
|
|
517
|
+
throw new CLIError("PAYMENT_INVALID", "The frozen order quote has changed.");
|
|
518
|
+
if (
|
|
519
|
+
current.order?.paymentRequired &&
|
|
520
|
+
order.paymentRequired &&
|
|
521
|
+
JSON.stringify(current.order.paymentRequired) !==
|
|
522
|
+
JSON.stringify(order.paymentRequired)
|
|
523
|
+
)
|
|
524
|
+
throw new CLIError("PAYMENT_INVALID", "The order payment requirements have changed.");
|
|
525
|
+
current.order = { ...current.order, ...order };
|
|
526
|
+
if (order.paymentStatus === "paid") current.phase = "paid";
|
|
527
|
+
else if (
|
|
528
|
+
[
|
|
529
|
+
"failed",
|
|
530
|
+
"expired",
|
|
531
|
+
"requires_review",
|
|
532
|
+
"settlement_pending",
|
|
533
|
+
"settling",
|
|
534
|
+
].includes(order.paymentStatus)
|
|
535
|
+
)
|
|
536
|
+
current.phase = order.paymentStatus;
|
|
537
|
+
});
|
|
538
|
+
return summary((await this.store.read()).intents[intent]);
|
|
539
|
+
}
|
|
540
|
+
return order;
|
|
541
|
+
}
|
|
542
|
+
async pay({ intent, prepare = false, signatureFile } = {}) {
|
|
543
|
+
label(intent);
|
|
544
|
+
let record = (await this.store.read()).intents[intent];
|
|
545
|
+
if (!record?.orderId)
|
|
546
|
+
throw new CLIError("ORDER_NOT_FOUND", "Create and save a top-up order first.");
|
|
547
|
+
if (record.submissionStartedAt !== undefined)
|
|
548
|
+
throw new CLIError(
|
|
549
|
+
"PAYMENT_ALREADY_SUBMITTED",
|
|
550
|
+
"The order has been submitted or its result is unknown; use topups get to check it. Do not pay again.",
|
|
551
|
+
{ intent, orderId: record.orderId },
|
|
552
|
+
);
|
|
553
|
+
const policy = await this.policy(record.scope);
|
|
554
|
+
const signer = getWallet(this.env, {
|
|
555
|
+
requirePrivateKey: !prepare && !signatureFile,
|
|
556
|
+
});
|
|
557
|
+
if (
|
|
558
|
+
!sameWallet(signer.address, record.walletAddress) ||
|
|
559
|
+
record.accountId !== policy.accountId ||
|
|
560
|
+
record.walletAddress !== policy.walletAddress ||
|
|
561
|
+
!policy.networks.includes(record.network)
|
|
562
|
+
)
|
|
563
|
+
throw new CLIError("ACCOUNT_MISMATCH", "The order does not match the currently authorized identity.");
|
|
564
|
+
const target = await this.target(record.identity, {
|
|
565
|
+
workspace: record.workspaceId,
|
|
566
|
+
walletAddress: record.walletAddress,
|
|
567
|
+
});
|
|
568
|
+
if (target.accountId !== record.accountId)
|
|
569
|
+
throw new CLIError("ACCOUNT_MISMATCH", "The current API key does not match the order account.");
|
|
570
|
+
await this.get({ intent });
|
|
571
|
+
record = (await this.store.read()).intents[intent];
|
|
572
|
+
if (
|
|
573
|
+
record.order.paymentStatus !== "created" ||
|
|
574
|
+
record.order.creditStatus !== "uncredited"
|
|
575
|
+
)
|
|
576
|
+
throw new CLIError("ORDER_NOT_PAYABLE", "The order cannot be paid; check its status.", {
|
|
577
|
+
intent,
|
|
578
|
+
paymentStatus: record.order.paymentStatus,
|
|
579
|
+
});
|
|
580
|
+
if (
|
|
581
|
+
integer(record.order.quote?.inputAmountMicroUsd) !==
|
|
582
|
+
BigInt(record.inputMicroUsd)
|
|
583
|
+
)
|
|
584
|
+
throw new CLIError(
|
|
585
|
+
"PAYMENT_INVALID",
|
|
586
|
+
"The quote input amount does not match the original intent; payment was refused.",
|
|
587
|
+
);
|
|
588
|
+
let prepared = record.prepared;
|
|
589
|
+
if (
|
|
590
|
+
!prepared ||
|
|
591
|
+
(prepared.kind === "evm" &&
|
|
592
|
+
Number(prepared.message.validBefore) * 1000 <= this.now() + 10000) ||
|
|
593
|
+
(prepared.kind === "solana" && this.now() - prepared.preparedAt > 60000)
|
|
594
|
+
) {
|
|
595
|
+
if (signatureFile)
|
|
596
|
+
throw new CLIError(
|
|
597
|
+
"PAYMENT_EXPIRED",
|
|
598
|
+
"The signing payload is missing or expired; prepare the original order again.",
|
|
599
|
+
);
|
|
600
|
+
let transaction;
|
|
601
|
+
if (record.network === SOLANA_NETWORK) {
|
|
602
|
+
const result = unwrap(
|
|
603
|
+
await this.http.backend(
|
|
604
|
+
`/api/v1/key-market/x402/topups/${identifier(record.orderId)}/transaction`,
|
|
605
|
+
{ method: "POST", json: {}, credential: target.credential },
|
|
606
|
+
),
|
|
607
|
+
);
|
|
608
|
+
transaction = result?.transaction;
|
|
609
|
+
}
|
|
610
|
+
prepared = preparePayment(
|
|
611
|
+
record.order,
|
|
612
|
+
{
|
|
613
|
+
identity: record.identity,
|
|
614
|
+
network: record.network,
|
|
615
|
+
walletAddress: record.walletAddress,
|
|
616
|
+
now: this.now(),
|
|
617
|
+
signingOrigin: SIGNING_ORIGIN,
|
|
618
|
+
},
|
|
619
|
+
transaction,
|
|
620
|
+
);
|
|
621
|
+
const preparedId = randomUUID();
|
|
622
|
+
await this.store.update((s) => {
|
|
623
|
+
const current = s.intents[intent];
|
|
624
|
+
if (current.submissionStartedAt !== undefined)
|
|
625
|
+
throw new CLIError("PAYMENT_ALREADY_SUBMITTED", "The order has already been submitted.");
|
|
626
|
+
budget(
|
|
627
|
+
s,
|
|
628
|
+
policy,
|
|
629
|
+
String(integer(record.order.quote.payAmountMicroUsd)),
|
|
630
|
+
intent,
|
|
631
|
+
);
|
|
632
|
+
current.reservedMicroUsd = String(
|
|
633
|
+
integer(record.order.quote.payAmountMicroUsd),
|
|
634
|
+
);
|
|
635
|
+
current.prepared = prepared;
|
|
636
|
+
current.preparedId = preparedId;
|
|
637
|
+
record = { ...current };
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
if (prepared) {
|
|
641
|
+
const validated = preparePayment(
|
|
642
|
+
record.order,
|
|
643
|
+
{
|
|
644
|
+
identity: record.identity,
|
|
645
|
+
network: record.network,
|
|
646
|
+
walletAddress: record.walletAddress,
|
|
647
|
+
now: this.now(),
|
|
648
|
+
signingOrigin: SIGNING_ORIGIN,
|
|
649
|
+
},
|
|
650
|
+
prepared.transaction,
|
|
651
|
+
);
|
|
652
|
+
for (const name of [
|
|
653
|
+
"kind",
|
|
654
|
+
"resource",
|
|
655
|
+
"accepted",
|
|
656
|
+
"walletAddress",
|
|
657
|
+
"domain",
|
|
658
|
+
"types",
|
|
659
|
+
])
|
|
660
|
+
if (JSON.stringify(validated[name]) !== JSON.stringify(prepared[name]))
|
|
661
|
+
throw new CLIError(
|
|
662
|
+
"PAYMENT_INVALID",
|
|
663
|
+
"The saved signing payload no longer matches the order.",
|
|
664
|
+
);
|
|
665
|
+
if (
|
|
666
|
+
prepared.kind === "evm" &&
|
|
667
|
+
(["from", "to", "value", "validAfter"].some(
|
|
668
|
+
(name) => prepared.message[name] !== validated.message[name],
|
|
669
|
+
) ||
|
|
670
|
+
Number(prepared.message.validBefore) * 1000 >
|
|
671
|
+
Date.parse(record.order.paymentExpiresAt) ||
|
|
672
|
+
Number(prepared.message.validBefore) * 1000 >
|
|
673
|
+
prepared.preparedAt + prepared.accepted.maxTimeoutSeconds * 1000)
|
|
674
|
+
)
|
|
675
|
+
throw new CLIError("PAYMENT_INVALID", "The saved payment authorization does not match the order.");
|
|
676
|
+
}
|
|
677
|
+
let external = {};
|
|
678
|
+
if (signatureFile) {
|
|
679
|
+
try {
|
|
680
|
+
external = JSON.parse(await readFile(signatureFile, "utf8"));
|
|
681
|
+
} catch {
|
|
682
|
+
throw new CLIError(
|
|
683
|
+
"INPUT_INVALID",
|
|
684
|
+
"The signature file must contain JSON with a signature or transaction field.",
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
let signature;
|
|
689
|
+
await this.store.update(async (s) => {
|
|
690
|
+
const current = s.intents[intent];
|
|
691
|
+
if (
|
|
692
|
+
!current ||
|
|
693
|
+
current.submissionStartedAt !== undefined ||
|
|
694
|
+
current.preparedId !== record.preparedId ||
|
|
695
|
+
JSON.stringify(current.prepared) !== JSON.stringify(prepared)
|
|
696
|
+
)
|
|
697
|
+
throw new CLIError(
|
|
698
|
+
"PAYMENT_ALREADY_SUBMITTED",
|
|
699
|
+
"The order has been submitted or the signing payload has changed.",
|
|
700
|
+
);
|
|
701
|
+
const active = s.paymentPolicies?.[record.scope];
|
|
702
|
+
if (
|
|
703
|
+
!active ||
|
|
704
|
+
!Number.isFinite(Date.parse(active.expiresAt)) ||
|
|
705
|
+
Date.parse(active.expiresAt) <= this.now() ||
|
|
706
|
+
!active.networks.includes(record.network)
|
|
707
|
+
)
|
|
708
|
+
throw new CLIError(
|
|
709
|
+
"PAYMENT_AUTH_REQUIRED",
|
|
710
|
+
"The payment authorization has expired or the network is no longer authorized.",
|
|
711
|
+
);
|
|
712
|
+
if (
|
|
713
|
+
active.identity !== record.identity ||
|
|
714
|
+
active.accountId !== record.accountId ||
|
|
715
|
+
active.workspaceId !== record.workspaceId ||
|
|
716
|
+
!sameWallet(active.walletAddress, record.walletAddress)
|
|
717
|
+
)
|
|
718
|
+
throw new CLIError("ACCOUNT_MISMATCH", "The order does not match the currently authorized identity.");
|
|
719
|
+
const amount = String(integer(record.order.quote.payAmountMicroUsd));
|
|
720
|
+
budget(s, active, amount, intent);
|
|
721
|
+
current.reservedMicroUsd = amount;
|
|
722
|
+
if (prepare) return;
|
|
723
|
+
// Keep policy and prepared content locked through signing and submission reservation.
|
|
724
|
+
signature = await completePayment(
|
|
725
|
+
prepared,
|
|
726
|
+
signatureFile
|
|
727
|
+
? { signature: external.signature, transaction: external.transaction }
|
|
728
|
+
: { signer },
|
|
729
|
+
this.now(),
|
|
730
|
+
);
|
|
731
|
+
current.phase = "submitted";
|
|
732
|
+
current.submissionStartedAt = this.now();
|
|
733
|
+
});
|
|
734
|
+
if (prepare)
|
|
735
|
+
return {
|
|
736
|
+
intent,
|
|
737
|
+
orderId: record.orderId,
|
|
738
|
+
status: "signature_required",
|
|
739
|
+
preparedId: record.preparedId,
|
|
740
|
+
...prepared,
|
|
741
|
+
};
|
|
742
|
+
this.secrets.push(signature, external.signature, external.transaction);
|
|
743
|
+
const path =
|
|
744
|
+
record.identity === "wallet"
|
|
745
|
+
? "/api/v1/agent-topups"
|
|
746
|
+
: `/api/v1/key-market/x402/topups/${identifier(record.orderId)}/pay`;
|
|
747
|
+
try {
|
|
748
|
+
const result = unwrap(
|
|
749
|
+
await this.http.backend(path, {
|
|
750
|
+
method: "POST",
|
|
751
|
+
json: record.identity === "wallet" ? record.body : {},
|
|
752
|
+
headers: {
|
|
753
|
+
"PAYMENT-SIGNATURE": signature,
|
|
754
|
+
...(record.identity === "wallet"
|
|
755
|
+
? { "Idempotency-Key": record.idempotencyKey }
|
|
756
|
+
: {}),
|
|
757
|
+
},
|
|
758
|
+
credential: target.credential,
|
|
759
|
+
}),
|
|
760
|
+
);
|
|
761
|
+
if (result?.orderId !== record.orderId)
|
|
762
|
+
throw new CLIError(
|
|
763
|
+
"INVALID_RESPONSE",
|
|
764
|
+
"The payment result order ID does not match; check the original order.",
|
|
765
|
+
);
|
|
766
|
+
await this.store.update((s) => {
|
|
767
|
+
const current = s.intents[intent];
|
|
768
|
+
current.order = { ...current.order, ...result };
|
|
769
|
+
current.phase = result.paymentStatus || "submitted";
|
|
770
|
+
delete current.prepared;
|
|
771
|
+
});
|
|
772
|
+
} catch (error) {
|
|
773
|
+
await this.store.update((s) => {
|
|
774
|
+
s.intents[intent].phase = "uncertain";
|
|
775
|
+
delete s.intents[intent].prepared;
|
|
776
|
+
});
|
|
777
|
+
throw error;
|
|
778
|
+
}
|
|
779
|
+
return this.get({ intent });
|
|
780
|
+
}
|
|
781
|
+
async config({ workspace } = {}) {
|
|
782
|
+
const credential = await this.auth.emailCredential({ workspace });
|
|
783
|
+
return unwrap(
|
|
784
|
+
await this.http.backend("/api/v1/key-market/x402/config", { credential }),
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
async quote({ workspace, amountUsd, network } = {}) {
|
|
788
|
+
const amount = usdToMicro(amountUsd);
|
|
789
|
+
if (![BASE_NETWORK, SOLANA_NETWORK].includes(network))
|
|
790
|
+
throw new CLIError("INPUT_REQUIRED", "Select the Base or Solana network.");
|
|
791
|
+
const credential = await this.auth.emailCredential({ workspace });
|
|
792
|
+
return unwrap(
|
|
793
|
+
await this.http.backend("/api/v1/key-market/x402/quote", {
|
|
794
|
+
method: "POST",
|
|
795
|
+
json: { amountMicroUsd: Number(amount), network },
|
|
796
|
+
credential,
|
|
797
|
+
}),
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
export async function runTopups(args, ctx) {
|
|
802
|
+
const service = new TopupService(ctx),
|
|
803
|
+
o = ctx.options;
|
|
804
|
+
const action = args[1];
|
|
805
|
+
if (action === "authorize")
|
|
806
|
+
return service.authorize({
|
|
807
|
+
identity: o.identity,
|
|
808
|
+
network: o.network,
|
|
809
|
+
maxSingleUsd: o["max-single-usd"],
|
|
810
|
+
maxTotalUsd: o["max-total-usd"],
|
|
811
|
+
scope: o.scope,
|
|
812
|
+
expiresAt: o["expires-at"],
|
|
813
|
+
workspace: o.workspace,
|
|
814
|
+
});
|
|
815
|
+
if (action === "create")
|
|
816
|
+
return service.create({
|
|
817
|
+
scope: o.scope,
|
|
818
|
+
intent: o.intent,
|
|
819
|
+
amountUsd: o["amount-usd"],
|
|
820
|
+
network: o.network,
|
|
821
|
+
prepare: o.prepare,
|
|
822
|
+
resume: o.resume,
|
|
823
|
+
});
|
|
824
|
+
if (action === "get")
|
|
825
|
+
return service.get({
|
|
826
|
+
intent: o.intent,
|
|
827
|
+
id: o.id,
|
|
828
|
+
identity: o.identity,
|
|
829
|
+
workspace: o.workspace,
|
|
830
|
+
});
|
|
831
|
+
if (action === "pay")
|
|
832
|
+
return service.pay({
|
|
833
|
+
intent: o.intent,
|
|
834
|
+
prepare: o.prepare,
|
|
835
|
+
signatureFile: o["signature-file"],
|
|
836
|
+
});
|
|
837
|
+
if (action === "config") return service.config({ workspace: o.workspace });
|
|
838
|
+
if (action === "quote")
|
|
839
|
+
return service.quote({
|
|
840
|
+
workspace: o.workspace,
|
|
841
|
+
amountUsd: o["amount-usd"],
|
|
842
|
+
network: o.network,
|
|
843
|
+
});
|
|
844
|
+
throw new CLIError("COMMAND_INVALID", "Unknown top-up command.");
|
|
845
|
+
}
|