@agent-fuel/sdk 0.3.0 → 0.3.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/CHANGELOG.md +6 -0
- package/dist/cli.cjs +38 -13
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +39 -14
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command, Option } from 'commander';
|
|
3
|
-
import { PublicKey, Keypair, SystemProgram, Transaction, sendAndConfirmTransaction,
|
|
3
|
+
import { PublicKey, Keypair, SystemProgram, Connection, Transaction, sendAndConfirmTransaction, TransactionInstruction } from '@solana/web3.js';
|
|
4
4
|
import { randomBytes } from 'crypto';
|
|
5
5
|
import { mkdirSync, writeFileSync, readFileSync } from 'fs';
|
|
6
6
|
import { dirname } from 'path';
|
|
@@ -4161,7 +4161,7 @@ async function safeText(res) {
|
|
|
4161
4161
|
}
|
|
4162
4162
|
|
|
4163
4163
|
// src/cli.ts
|
|
4164
|
-
var VERSION = "0.3.
|
|
4164
|
+
var VERSION = "0.3.1";
|
|
4165
4165
|
var RPC_DEFAULTS = {
|
|
4166
4166
|
"mainnet-beta": "https://api.mainnet-beta.solana.com",
|
|
4167
4167
|
devnet: "https://api.devnet.solana.com",
|
|
@@ -4279,6 +4279,16 @@ function jsonReplacer(_key, value) {
|
|
|
4279
4279
|
function errMsg(e) {
|
|
4280
4280
|
return e instanceof Error ? e.message : String(e);
|
|
4281
4281
|
}
|
|
4282
|
+
async function rephraseNotFound(fn, reword) {
|
|
4283
|
+
try {
|
|
4284
|
+
return await fn();
|
|
4285
|
+
} catch (e) {
|
|
4286
|
+
if (e instanceof AccountNotFoundError) {
|
|
4287
|
+
throw new Error(reword(e.account));
|
|
4288
|
+
}
|
|
4289
|
+
throw e;
|
|
4290
|
+
}
|
|
4291
|
+
}
|
|
4282
4292
|
function explorerUrl(cluster, sig) {
|
|
4283
4293
|
const suffix = cluster === "mainnet-beta" ? "" : `?cluster=${cluster}`;
|
|
4284
4294
|
return `https://explorer.solana.com/tx/${sig}${suffix}`;
|
|
@@ -4297,7 +4307,10 @@ program.command("score <agent>").description("Show the latest reputation snapsho
|
|
|
4297
4307
|
const g = readGlobalOpts(cmd);
|
|
4298
4308
|
const agentPk = parsePubkey(agent, "<agent>");
|
|
4299
4309
|
const fuel = readOnlyFuel(g);
|
|
4300
|
-
const score = await
|
|
4310
|
+
const score = await rephraseNotFound(
|
|
4311
|
+
() => fuel.getScore(agentPk),
|
|
4312
|
+
() => `no reputation data yet for agent ${agent} \u2014 the backend has no AgentProfile mirror for this agent (it hasn't received any recorded payments)`
|
|
4313
|
+
);
|
|
4301
4314
|
emit(g, () => formatScore(score), score);
|
|
4302
4315
|
});
|
|
4303
4316
|
program.command("vault <owner> <agent>").description("Show on-chain credit vault state for the (owner, agent) pair.").action(async (owner, agent, _opts, cmd) => {
|
|
@@ -4305,7 +4318,10 @@ program.command("vault <owner> <agent>").description("Show on-chain credit vault
|
|
|
4305
4318
|
const ownerPk = parsePubkey(owner, "<owner>");
|
|
4306
4319
|
const agentPk = parsePubkey(agent, "<agent>");
|
|
4307
4320
|
const fuel = readOnlyFuel(g);
|
|
4308
|
-
const vault = await
|
|
4321
|
+
const vault = await rephraseNotFound(
|
|
4322
|
+
() => fuel.getVaultBalance({ owner: ownerPk, agent: agentPk }),
|
|
4323
|
+
(pda) => `no vault found at ${pda} for owner=${owner} agent=${agent} \u2014 has init_vault been called for this pair?`
|
|
4324
|
+
);
|
|
4309
4325
|
emit(g, () => formatVault(vault), vault);
|
|
4310
4326
|
});
|
|
4311
4327
|
program.command("policy <owner> <agent>").description("Show the spend policy guarding an (owner, agent) vault.").action(async (owner, agent, _opts, cmd) => {
|
|
@@ -4313,14 +4329,20 @@ program.command("policy <owner> <agent>").description("Show the spend policy gua
|
|
|
4313
4329
|
const ownerPk = parsePubkey(owner, "<owner>");
|
|
4314
4330
|
const agentPk = parsePubkey(agent, "<agent>");
|
|
4315
4331
|
const fuel = readOnlyFuel(g);
|
|
4316
|
-
const policy = await
|
|
4332
|
+
const policy = await rephraseNotFound(
|
|
4333
|
+
() => fuel.getPolicy({ owner: ownerPk, agent: agentPk }),
|
|
4334
|
+
(pda) => `no spend policy found at ${pda} for owner=${owner} agent=${agent} \u2014 policy is created alongside the vault, so this usually means init_vault hasn't been called`
|
|
4335
|
+
);
|
|
4317
4336
|
emit(g, () => formatPolicy(policy), policy);
|
|
4318
4337
|
});
|
|
4319
4338
|
program.command("service <authority>").description("Look up a registered service by its authority pubkey.").action(async (authority, _opts, cmd) => {
|
|
4320
4339
|
const g = readGlobalOpts(cmd);
|
|
4321
4340
|
const authPk = parsePubkey(authority, "<authority>");
|
|
4322
4341
|
const fuel = readOnlyFuel(g);
|
|
4323
|
-
const svc = await
|
|
4342
|
+
const svc = await rephraseNotFound(
|
|
4343
|
+
() => fuel.checkService(authPk),
|
|
4344
|
+
(pda) => `no service registered for authority ${authority} (registry PDA ${pda} doesn't exist) \u2014 run \`agent-fuel register-service\` to create one`
|
|
4345
|
+
);
|
|
4324
4346
|
emit(g, () => formatService(svc), svc);
|
|
4325
4347
|
});
|
|
4326
4348
|
program.command("pay").description(
|
|
@@ -4336,14 +4358,17 @@ program.command("pay").description(
|
|
|
4336
4358
|
const owner = parsePubkey(opts.owner, "--owner");
|
|
4337
4359
|
const amountUsdc = parseAmountToMicro(opts.amount);
|
|
4338
4360
|
const receiptHash = parseReceiptHash(opts.receiptHash);
|
|
4339
|
-
const result = await
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4361
|
+
const result = await rephraseNotFound(
|
|
4362
|
+
() => pay({
|
|
4363
|
+
agent,
|
|
4364
|
+
service,
|
|
4365
|
+
owner,
|
|
4366
|
+
amountUsdc,
|
|
4367
|
+
receiptHash,
|
|
4368
|
+
connection: connectionFor(g)
|
|
4369
|
+
}),
|
|
4370
|
+
(pda) => `pay failed: account not found at ${pda} \u2014 either the vault for owner=${opts.owner} agent=${agent.publicKey.toBase58()} doesn't exist, or the spend policy hasn't been created. Try \`agent-fuel vault ${opts.owner} ${agent.publicKey.toBase58()}\` to verify.`
|
|
4371
|
+
);
|
|
4347
4372
|
emit(
|
|
4348
4373
|
g,
|
|
4349
4374
|
() => [
|