@coinfello/agent-cli 0.1.0 → 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.
Files changed (2) hide show
  1. package/dist/index.js +92 -99
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import { toMetaMaskSmartAccount, Implementation, createDelegation } from "@metam
4
4
  import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
5
5
  import { createPublicClient, http, serializeErc6492Signature } from "viem";
6
6
  import * as chains from "viem/chains";
7
+ import { randomBytes } from "node:crypto";
7
8
  import { readFile, mkdir, writeFile } from "node:fs/promises";
8
9
  import { homedir } from "node:os";
9
10
  import { join } from "node:path";
@@ -63,7 +64,8 @@ function createSubdelegation({
63
64
  to: delegateAddress,
64
65
  from: smartAccount.address,
65
66
  parentDelegation,
66
- environment: smartAccount.environment
67
+ environment: smartAccount.environment,
68
+ salt: `0x${randomBytes(32).toString("hex")}`
67
69
  });
68
70
  }
69
71
  const CONFIG_DIR = join(homedir(), ".clawdbot", "skills", "coinfello");
@@ -3682,107 +3684,98 @@ program.command("set_delegation").description("Store a signed delegation (JSON)
3682
3684
  process.exit(1);
3683
3685
  }
3684
3686
  });
3685
- program.command("send_prompt").description("Send a prompt to CoinFello, creating a delegation if requested by the server").argument("<prompt>", "The prompt to send").option("--use-redelegation", "Create a redelegation from a stored parent delegation").action(
3686
- async (prompt, opts) => {
3687
- try {
3688
- const config = await loadConfig();
3689
- if (!config.private_key) {
3690
- console.error("Error: No private key found in config. Run 'create_account' first.");
3691
- process.exit(1);
3692
- }
3693
- if (!config.smart_account_address) {
3694
- console.error("Error: No smart account found. Run 'create_account' first.");
3695
- process.exit(1);
3696
- }
3697
- if (!config.chain) {
3698
- console.error("Error: No chain found in config. Run 'create_account' first.");
3699
- process.exit(1);
3700
- }
3701
- if (opts.useRedelegation && !config.delegation) {
3702
- console.error(
3703
- "Error: --use-redelegation requires a parent delegation. Run 'set_delegation' first."
3704
- );
3705
- process.exit(1);
3706
- }
3707
- if (config.session_token) {
3708
- await loadSessionToken(config.session_token, BASE_URL_V1);
3709
- }
3710
- console.log("Sending prompt...");
3711
- const initialResponse = await sendConversation({
3712
- prompt
3713
- });
3714
- if (!initialResponse.clientToolCalls?.length && !initialResponse.txn_id) {
3715
- console.log(initialResponse.responseText ?? "");
3716
- return;
3717
- }
3718
- if (initialResponse.txn_id && !initialResponse.clientToolCalls?.length) {
3719
- console.log("Transaction submitted successfully.");
3720
- console.log(`Transaction ID: ${initialResponse.txn_id}`);
3721
- return;
3722
- }
3723
- const delegationToolCall = initialResponse.clientToolCalls?.find(
3724
- (tc) => tc.name === "ask_for_delegation"
3725
- );
3726
- if (!delegationToolCall) {
3727
- console.error("Error: No delegation request received from the server.");
3728
- console.log("Response:", JSON.stringify(initialResponse, null, 2));
3729
- process.exit(1);
3730
- }
3731
- const args = JSON.parse(delegationToolCall.arguments);
3732
- console.log(`Delegation requested: scope=${args.scope.type}, chainId=${args.chainId}`);
3733
- console.log("Fetching CoinFello delegate address...");
3734
- const delegateAddress = await getCoinFelloAddress();
3735
- console.log("Loading smart account...");
3736
- const smartAccount = await getSmartAccount(config.private_key, args.chainId);
3737
- const scope = parseScope(args.scope);
3738
- console.log("Creating subdelegation...");
3739
- const subdelegation = createSubdelegation({
3740
- smartAccount,
3741
- delegateAddress,
3742
- parentDelegation: opts.useRedelegation ? config.delegation : void 0,
3743
- scope
3744
- });
3745
- console.log("Signing subdelegation...");
3746
- const signature = await smartAccount.signDelegation({
3747
- delegation: subdelegation
3748
- });
3749
- let sig = signature;
3750
- const chain = resolveChainInput(config.chain);
3751
- const publicClient = createPublicClient({
3752
- chain,
3753
- transport: http()
3754
- });
3755
- const code = await publicClient.getCode({ address: smartAccount.address });
3756
- const isDeployed = !!(code && code !== "0x");
3757
- if (!isDeployed) {
3758
- const factoryArgs = await smartAccount.getFactoryArgs();
3759
- sig = serializeErc6492Signature({
3760
- signature,
3761
- address: factoryArgs.factory,
3762
- data: factoryArgs.factoryData
3763
- });
3764
- }
3765
- const signedSubdelegation = { ...subdelegation, signature: sig };
3766
- console.log("Sending signed delegation...");
3767
- const finalResponse = await sendConversation({
3768
- prompt: "Please refer to the previous conversation messages and redeem this delegation.",
3769
- signedSubdelegation,
3770
- chatId: initialResponse.chatId,
3771
- delegationArguments: JSON.stringify(args),
3772
- callId: delegationToolCall.callId
3773
- });
3774
- if (finalResponse.txn_id) {
3775
- console.log("Transaction submitted successfully.");
3776
- console.log(`Transaction ID: ${finalResponse.txn_id}`);
3777
- } else {
3778
- console.log("Final Response:", JSON.stringify(finalResponse, null, 2));
3779
- }
3780
- } catch (err) {
3781
- console.error(`Failed to send prompt: ${err.message}`);
3687
+ program.command("send_prompt").description("Send a prompt to CoinFello, creating a delegation if requested by the server").argument("<prompt>", "The prompt to send").action(async (prompt) => {
3688
+ try {
3689
+ const config = await loadConfig();
3690
+ if (!config.private_key) {
3691
+ console.error("Error: No private key found in config. Run 'create_account' first.");
3692
+ process.exit(1);
3693
+ }
3694
+ if (!config.smart_account_address) {
3695
+ console.error("Error: No smart account found. Run 'create_account' first.");
3696
+ process.exit(1);
3697
+ }
3698
+ if (!config.chain) {
3699
+ console.error("Error: No chain found in config. Run 'create_account' first.");
3700
+ process.exit(1);
3701
+ }
3702
+ if (config.session_token) {
3703
+ await loadSessionToken(config.session_token, BASE_URL_V1);
3704
+ }
3705
+ console.log("Sending prompt...");
3706
+ const initialResponse = await sendConversation({
3707
+ prompt
3708
+ });
3709
+ if (!initialResponse.clientToolCalls?.length && !initialResponse.txn_id) {
3710
+ console.log(initialResponse.responseText ?? "");
3711
+ return;
3712
+ }
3713
+ if (initialResponse.txn_id && !initialResponse.clientToolCalls?.length) {
3714
+ console.log("Transaction submitted successfully.");
3715
+ console.log(`Transaction ID: ${initialResponse.txn_id}`);
3716
+ return;
3717
+ }
3718
+ const delegationToolCall = initialResponse.clientToolCalls?.find(
3719
+ (tc) => tc.name === "ask_for_delegation"
3720
+ );
3721
+ if (!delegationToolCall) {
3722
+ console.error("Error: No delegation request received from the server.");
3723
+ console.log("Response:", JSON.stringify(initialResponse, null, 2));
3782
3724
  process.exit(1);
3783
3725
  }
3726
+ const args = JSON.parse(delegationToolCall.arguments);
3727
+ console.log(`Delegation requested: scope=${args.scope.type}, chainId=${args.chainId}`);
3728
+ console.log("Fetching CoinFello delegate address...");
3729
+ const delegateAddress = await getCoinFelloAddress();
3730
+ console.log("Loading smart account...");
3731
+ const smartAccount = await getSmartAccount(config.private_key, args.chainId);
3732
+ const scope = parseScope(args.scope);
3733
+ console.log("Creating subdelegation...");
3734
+ const subdelegation = createSubdelegation({
3735
+ smartAccount,
3736
+ delegateAddress,
3737
+ scope
3738
+ });
3739
+ console.log("Signing subdelegation...");
3740
+ const signature = await smartAccount.signDelegation({
3741
+ delegation: subdelegation
3742
+ });
3743
+ let sig = signature;
3744
+ const chain = resolveChainInput(config.chain);
3745
+ const publicClient = createPublicClient({
3746
+ chain,
3747
+ transport: http()
3748
+ });
3749
+ const code = await publicClient.getCode({ address: smartAccount.address });
3750
+ const isDeployed = !!(code && code !== "0x");
3751
+ if (!isDeployed) {
3752
+ const factoryArgs = await smartAccount.getFactoryArgs();
3753
+ sig = serializeErc6492Signature({
3754
+ signature,
3755
+ address: factoryArgs.factory,
3756
+ data: factoryArgs.factoryData
3757
+ });
3758
+ }
3759
+ const signedSubdelegation = { ...subdelegation, signature: sig };
3760
+ console.log("Sending signed delegation...");
3761
+ const finalResponse = await sendConversation({
3762
+ prompt: "Please refer to the previous conversation messages and redeem this delegation.",
3763
+ signedSubdelegation,
3764
+ chatId: initialResponse.chatId,
3765
+ delegationArguments: JSON.stringify(args),
3766
+ callId: delegationToolCall.callId
3767
+ });
3768
+ if (finalResponse.txn_id) {
3769
+ console.log("Transaction submitted successfully.");
3770
+ console.log(`Transaction ID: ${finalResponse.txn_id}`);
3771
+ } else {
3772
+ console.log("Final Response:", JSON.stringify(finalResponse, null, 2));
3773
+ }
3774
+ } catch (err) {
3775
+ console.error(`Failed to send prompt: ${err.message}`);
3776
+ process.exit(1);
3784
3777
  }
3785
- );
3778
+ });
3786
3779
  program.command("get_transaction_status").description("Check the status of a submitted transaction").argument("<txn_id>", "The transaction ID to check").action(async (txnId) => {
3787
3780
  try {
3788
3781
  const result = await getTransactionStatus(txnId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coinfello/agent-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",