Skip to content

Commit 8f9d72e

Browse files
committed
navid
1 parent 7e776bc commit 8f9d72e

File tree

1 file changed

+102
-0
lines changed
  • packages/sui-agent/src/tools/navi

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { NAVISDKClient } from 'navi-sdk';
2+
import { handleError } from '../../utils';
3+
4+
// Initialize NAVI SDK client
5+
let naviClient: NAVISDKClient | null = null;
6+
7+
/**
8+
* Initializes the NAVI SDK client
9+
* @param mnemonic - Optional mnemonic for account generation
10+
* @param networkType - Network type ('mainnet' or custom RPC)
11+
* @param numberOfAccounts - Number of accounts to generate
12+
* @returns JSON string with initialization status
13+
*/
14+
export async function initializeNaviClient(
15+
...args: (string | number | bigint | boolean)[]
16+
): Promise<string> {
17+
const [mnemonic, networkType, numberOfAccounts] = args as [
18+
string | undefined,
19+
string,
20+
number,
21+
];
22+
23+
try {
24+
naviClient = new NAVISDKClient({
25+
mnemonic,
26+
networkType,
27+
numberOfAccounts: numberOfAccounts || 5,
28+
});
29+
30+
return JSON.stringify([
31+
{
32+
reasoning: 'Successfully initialized NAVI SDK client',
33+
response: JSON.stringify(
34+
{
35+
numberOfAccounts: naviClient.accounts.length,
36+
networkType,
37+
},
38+
null,
39+
2,
40+
),
41+
status: 'success',
42+
query: 'Initialize NAVI SDK client',
43+
errors: [],
44+
},
45+
]);
46+
} catch (error: unknown) {
47+
return JSON.stringify([
48+
handleError(error, {
49+
reasoning: 'Failed to initialize NAVI SDK client',
50+
query: 'Attempted to initialize NAVI SDK client',
51+
}),
52+
]);
53+
}
54+
}
55+
56+
/**
57+
* Gets account information for a specific index
58+
* @param accountIndex - Index of the account to retrieve
59+
* @returns JSON string with account information
60+
*/
61+
export async function getNaviAccount(
62+
...args: (string | number | bigint | boolean)[]
63+
): Promise<string> {
64+
const [accountIndex] = args as [number];
65+
66+
try {
67+
if (!naviClient) {
68+
throw new Error('NAVI SDK client not initialized');
69+
}
70+
71+
const account = naviClient.accounts[accountIndex];
72+
if (!account) {
73+
throw new Error(`No account found at index ${accountIndex}`);
74+
}
75+
76+
return JSON.stringify([
77+
{
78+
reasoning: 'Successfully retrieved NAVI account information',
79+
response: JSON.stringify(
80+
{
81+
address: account.address,
82+
publicKey: account.getPublicKey(),
83+
},
84+
null,
85+
2,
86+
),
87+
status: 'success',
88+
query: `Get NAVI account at index ${accountIndex}`,
89+
errors: [],
90+
},
91+
]);
92+
} catch (error: unknown) {
93+
return JSON.stringify([
94+
handleError(error, {
95+
reasoning: 'Failed to retrieve NAVI account information',
96+
query: `Attempted to get NAVI account at index ${accountIndex}`,
97+
}),
98+
]);
99+
}
100+
}
101+
102+
// Add more NAVI-specific functions here...

0 commit comments

Comments
 (0)