@coinfello/agent-cli 0.0.2 → 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.
- package/dist/index.js +51 -15
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import { toMetaMaskSmartAccount, Implementation, createDelegation } from "@metamask/smart-accounts-kit";
|
|
4
4
|
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
|
|
5
|
-
import { createPublicClient, http } from "viem";
|
|
5
|
+
import { createPublicClient, http, serializeErc6492Signature } from "viem";
|
|
6
6
|
import * as chains from "viem/chains";
|
|
7
7
|
import { readFile, mkdir, writeFile } from "node:fs/promises";
|
|
8
8
|
import { homedir } from "node:os";
|
|
@@ -2646,7 +2646,7 @@ async function loadSessionToken(token, url) {
|
|
|
2646
2646
|
await cookieJar.setCookie(`better-auth.session_token=${token}`, url);
|
|
2647
2647
|
await cookieJar.setCookie(`logged_in=true`, url);
|
|
2648
2648
|
}
|
|
2649
|
-
const BASE_URL = "https://
|
|
2649
|
+
const BASE_URL = process.env.COINFELLO_BASE_URL || "https://hyp3r-58q8qto10-hyperplay.vercel.app/";
|
|
2650
2650
|
const BASE_URL_V1 = BASE_URL + "api/v1";
|
|
2651
2651
|
async function getCoinFelloAddress() {
|
|
2652
2652
|
const response = await fetchWithCookies(`${BASE_URL_V1}/automation/coinfello-address`);
|
|
@@ -2669,7 +2669,10 @@ async function getCoinFelloAgents() {
|
|
|
2669
2669
|
}
|
|
2670
2670
|
async function sendConversation({
|
|
2671
2671
|
prompt,
|
|
2672
|
-
signedSubdelegation
|
|
2672
|
+
signedSubdelegation,
|
|
2673
|
+
chatId,
|
|
2674
|
+
delegationArguments,
|
|
2675
|
+
callId
|
|
2673
2676
|
}) {
|
|
2674
2677
|
const agents = await getCoinFelloAgents();
|
|
2675
2678
|
const body = {
|
|
@@ -2680,11 +2683,23 @@ async function sendConversation({
|
|
|
2680
2683
|
body.agentId = agents[0].id;
|
|
2681
2684
|
}
|
|
2682
2685
|
if (signedSubdelegation !== void 0) {
|
|
2683
|
-
body.
|
|
2686
|
+
body.clientToolCallResponse = {
|
|
2687
|
+
output: JSON.stringify({
|
|
2688
|
+
success: true,
|
|
2689
|
+
delegation: signedSubdelegation,
|
|
2690
|
+
chainId: delegationArguments ? JSON.parse(delegationArguments).chainId : void 0
|
|
2691
|
+
}),
|
|
2692
|
+
type: "function_call_output",
|
|
2693
|
+
callId,
|
|
2694
|
+
name: "ask_for_delegation",
|
|
2695
|
+
arguments: delegationArguments
|
|
2696
|
+
};
|
|
2697
|
+
}
|
|
2698
|
+
if (chatId) {
|
|
2699
|
+
body.chatId = chatId;
|
|
2684
2700
|
}
|
|
2685
|
-
const response = await fetchWithCookies(`${BASE_URL}
|
|
2701
|
+
const response = await fetchWithCookies(`${BASE_URL}api/conversation`, {
|
|
2686
2702
|
method: "POST",
|
|
2687
|
-
headers: { "Content-Type": "application/json" },
|
|
2688
2703
|
body: JSON.stringify(body)
|
|
2689
2704
|
});
|
|
2690
2705
|
if (!response.ok) {
|
|
@@ -3537,7 +3552,9 @@ async function signInWithAgent(baseUrl, config) {
|
|
|
3537
3552
|
throw new Error("SIWE verification returned success: false");
|
|
3538
3553
|
}
|
|
3539
3554
|
console.log("saving token...");
|
|
3540
|
-
|
|
3555
|
+
const cookies = await cookieJar.getCookies(baseUrl);
|
|
3556
|
+
const sessionCookie = cookies.find((c) => c.key === "better-auth.session_token");
|
|
3557
|
+
config.session_token = sessionCookie?.value ?? result.token;
|
|
3541
3558
|
await saveConfig(config);
|
|
3542
3559
|
return result;
|
|
3543
3560
|
}
|
|
@@ -3638,7 +3655,7 @@ program.command("get_account").description("Display the current smart account ad
|
|
|
3638
3655
|
program.command("sign_in").description("Sign in to a server using SIWE with your smart account").option(
|
|
3639
3656
|
"--base-url <baseUrl>",
|
|
3640
3657
|
"The server base URL override (e.g. https://api.example.com)",
|
|
3641
|
-
|
|
3658
|
+
`${BASE_URL}api/auth`
|
|
3642
3659
|
).action(async (opts) => {
|
|
3643
3660
|
try {
|
|
3644
3661
|
console.log("Signing in with smart account...");
|
|
@@ -3694,16 +3711,16 @@ program.command("send_prompt").description("Send a prompt to CoinFello, creating
|
|
|
3694
3711
|
const initialResponse = await sendConversation({
|
|
3695
3712
|
prompt
|
|
3696
3713
|
});
|
|
3697
|
-
if (!initialResponse.
|
|
3714
|
+
if (!initialResponse.clientToolCalls?.length && !initialResponse.txn_id) {
|
|
3698
3715
|
console.log(initialResponse.responseText ?? "");
|
|
3699
3716
|
return;
|
|
3700
3717
|
}
|
|
3701
|
-
if (initialResponse.txn_id && !initialResponse.
|
|
3718
|
+
if (initialResponse.txn_id && !initialResponse.clientToolCalls?.length) {
|
|
3702
3719
|
console.log("Transaction submitted successfully.");
|
|
3703
3720
|
console.log(`Transaction ID: ${initialResponse.txn_id}`);
|
|
3704
3721
|
return;
|
|
3705
3722
|
}
|
|
3706
|
-
const delegationToolCall = initialResponse.
|
|
3723
|
+
const delegationToolCall = initialResponse.clientToolCalls?.find(
|
|
3707
3724
|
(tc) => tc.name === "ask_for_delegation"
|
|
3708
3725
|
);
|
|
3709
3726
|
if (!delegationToolCall) {
|
|
@@ -3729,17 +3746,36 @@ program.command("send_prompt").description("Send a prompt to CoinFello, creating
|
|
|
3729
3746
|
const signature = await smartAccount.signDelegation({
|
|
3730
3747
|
delegation: subdelegation
|
|
3731
3748
|
});
|
|
3732
|
-
|
|
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 };
|
|
3733
3766
|
console.log("Sending signed delegation...");
|
|
3734
3767
|
const finalResponse = await sendConversation({
|
|
3735
|
-
prompt,
|
|
3736
|
-
signedSubdelegation
|
|
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
|
|
3737
3773
|
});
|
|
3738
3774
|
if (finalResponse.txn_id) {
|
|
3739
3775
|
console.log("Transaction submitted successfully.");
|
|
3740
3776
|
console.log(`Transaction ID: ${finalResponse.txn_id}`);
|
|
3741
3777
|
} else {
|
|
3742
|
-
console.log("Response:", JSON.stringify(finalResponse, null, 2));
|
|
3778
|
+
console.log("Final Response:", JSON.stringify(finalResponse, null, 2));
|
|
3743
3779
|
}
|
|
3744
3780
|
} catch (err) {
|
|
3745
3781
|
console.error(`Failed to send prompt: ${err.message}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinfello/agent-cli",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "^25.2.1",
|
|
27
|
+
"dotenv": "^17.3.1",
|
|
27
28
|
"eslint": "^10.0.0",
|
|
28
29
|
"eslint-config-prettier": "^10.1.8",
|
|
29
30
|
"prettier": "^3.8.1",
|