@agent-fuel/sdk 0.3.0 → 0.3.2

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/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, Connection, TransactionInstruction } from '@solana/web3.js';
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';
@@ -3832,9 +3832,16 @@ async function pay(args) {
3832
3832
  receiptUsed: receipt,
3833
3833
  systemProgram: SystemProgram.programId
3834
3834
  });
3835
- const spendIx = await spendBuilder.instruction();
3836
- const recordIx = await recordBuilder.instruction();
3837
- const tx = new Transaction().add(createAtaIx, spendIx, recordIx);
3835
+ const computeBuilder = rep.methods.computeScore().accounts({
3836
+ caller: agent.publicKey,
3837
+ agentProfile
3838
+ });
3839
+ const [spendIx, recordIx, computeIx] = await Promise.all([
3840
+ spendBuilder.instruction(),
3841
+ recordBuilder.instruction(),
3842
+ computeBuilder.instruction()
3843
+ ]);
3844
+ const tx = new Transaction().add(createAtaIx, spendIx, recordIx, computeIx);
3838
3845
  try {
3839
3846
  const signature = await sendAndConfirmTransaction(
3840
3847
  connection,
@@ -4161,7 +4168,7 @@ async function safeText(res) {
4161
4168
  }
4162
4169
 
4163
4170
  // src/cli.ts
4164
- var VERSION = "0.3.0";
4171
+ var VERSION = "0.3.2";
4165
4172
  var RPC_DEFAULTS = {
4166
4173
  "mainnet-beta": "https://api.mainnet-beta.solana.com",
4167
4174
  devnet: "https://api.devnet.solana.com",
@@ -4279,6 +4286,16 @@ function jsonReplacer(_key, value) {
4279
4286
  function errMsg(e) {
4280
4287
  return e instanceof Error ? e.message : String(e);
4281
4288
  }
4289
+ async function rephraseNotFound(fn, reword) {
4290
+ try {
4291
+ return await fn();
4292
+ } catch (e) {
4293
+ if (e instanceof AccountNotFoundError) {
4294
+ throw new Error(reword(e.account));
4295
+ }
4296
+ throw e;
4297
+ }
4298
+ }
4282
4299
  function explorerUrl(cluster, sig) {
4283
4300
  const suffix = cluster === "mainnet-beta" ? "" : `?cluster=${cluster}`;
4284
4301
  return `https://explorer.solana.com/tx/${sig}${suffix}`;
@@ -4297,7 +4314,10 @@ program.command("score <agent>").description("Show the latest reputation snapsho
4297
4314
  const g = readGlobalOpts(cmd);
4298
4315
  const agentPk = parsePubkey(agent, "<agent>");
4299
4316
  const fuel = readOnlyFuel(g);
4300
- const score = await fuel.getScore(agentPk);
4317
+ const score = await rephraseNotFound(
4318
+ () => fuel.getScore(agentPk),
4319
+ () => `no reputation data yet for agent ${agent} \u2014 the backend has no AgentProfile mirror for this agent (it hasn't received any recorded payments)`
4320
+ );
4301
4321
  emit(g, () => formatScore(score), score);
4302
4322
  });
4303
4323
  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 +4325,10 @@ program.command("vault <owner> <agent>").description("Show on-chain credit vault
4305
4325
  const ownerPk = parsePubkey(owner, "<owner>");
4306
4326
  const agentPk = parsePubkey(agent, "<agent>");
4307
4327
  const fuel = readOnlyFuel(g);
4308
- const vault = await fuel.getVaultBalance({ owner: ownerPk, agent: agentPk });
4328
+ const vault = await rephraseNotFound(
4329
+ () => fuel.getVaultBalance({ owner: ownerPk, agent: agentPk }),
4330
+ (pda) => `no vault found at ${pda} for owner=${owner} agent=${agent} \u2014 has init_vault been called for this pair?`
4331
+ );
4309
4332
  emit(g, () => formatVault(vault), vault);
4310
4333
  });
4311
4334
  program.command("policy <owner> <agent>").description("Show the spend policy guarding an (owner, agent) vault.").action(async (owner, agent, _opts, cmd) => {
@@ -4313,14 +4336,20 @@ program.command("policy <owner> <agent>").description("Show the spend policy gua
4313
4336
  const ownerPk = parsePubkey(owner, "<owner>");
4314
4337
  const agentPk = parsePubkey(agent, "<agent>");
4315
4338
  const fuel = readOnlyFuel(g);
4316
- const policy = await fuel.getPolicy({ owner: ownerPk, agent: agentPk });
4339
+ const policy = await rephraseNotFound(
4340
+ () => fuel.getPolicy({ owner: ownerPk, agent: agentPk }),
4341
+ (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`
4342
+ );
4317
4343
  emit(g, () => formatPolicy(policy), policy);
4318
4344
  });
4319
4345
  program.command("service <authority>").description("Look up a registered service by its authority pubkey.").action(async (authority, _opts, cmd) => {
4320
4346
  const g = readGlobalOpts(cmd);
4321
4347
  const authPk = parsePubkey(authority, "<authority>");
4322
4348
  const fuel = readOnlyFuel(g);
4323
- const svc = await fuel.checkService(authPk);
4349
+ const svc = await rephraseNotFound(
4350
+ () => fuel.checkService(authPk),
4351
+ (pda) => `no service registered for authority ${authority} (registry PDA ${pda} doesn't exist) \u2014 run \`agent-fuel register-service\` to create one`
4352
+ );
4324
4353
  emit(g, () => formatService(svc), svc);
4325
4354
  });
4326
4355
  program.command("pay").description(
@@ -4336,14 +4365,17 @@ program.command("pay").description(
4336
4365
  const owner = parsePubkey(opts.owner, "--owner");
4337
4366
  const amountUsdc = parseAmountToMicro(opts.amount);
4338
4367
  const receiptHash = parseReceiptHash(opts.receiptHash);
4339
- const result = await pay({
4340
- agent,
4341
- service,
4342
- owner,
4343
- amountUsdc,
4344
- receiptHash,
4345
- connection: connectionFor(g)
4346
- });
4368
+ const result = await rephraseNotFound(
4369
+ () => pay({
4370
+ agent,
4371
+ service,
4372
+ owner,
4373
+ amountUsdc,
4374
+ receiptHash,
4375
+ connection: connectionFor(g)
4376
+ }),
4377
+ (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.`
4378
+ );
4347
4379
  emit(
4348
4380
  g,
4349
4381
  () => [