@clankxyz/agent 0.1.1 → 0.1.3
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 +61 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +61 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/cli.js
CHANGED
|
@@ -140,6 +140,10 @@ import chalk from "chalk";
|
|
|
140
140
|
init_state();
|
|
141
141
|
import { ClankClient } from "@clankxyz/sdk";
|
|
142
142
|
import { STATUS, VERIFICATION } from "@clankxyz/shared";
|
|
143
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
144
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
145
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
146
|
+
import { decodeSuiPrivateKey } from "@mysten/sui/cryptography";
|
|
143
147
|
|
|
144
148
|
// src/skills/types.ts
|
|
145
149
|
var SkillRegistry = class {
|
|
@@ -1125,6 +1129,9 @@ var ClankAgent = class {
|
|
|
1125
1129
|
skillRegistry;
|
|
1126
1130
|
running = false;
|
|
1127
1131
|
heartbeatTimer;
|
|
1132
|
+
// On-chain transaction capabilities
|
|
1133
|
+
keypair;
|
|
1134
|
+
suiClient;
|
|
1128
1135
|
// Queue for tasks to create in requester mode
|
|
1129
1136
|
taskCreationQueue = [];
|
|
1130
1137
|
constructor(config) {
|
|
@@ -1141,6 +1148,17 @@ var ClankAgent = class {
|
|
|
1141
1148
|
});
|
|
1142
1149
|
this.skillRegistry = new SkillRegistry();
|
|
1143
1150
|
this.skillRegistry.register(echoSkillHandler);
|
|
1151
|
+
if (config.privateKey) {
|
|
1152
|
+
try {
|
|
1153
|
+
const { secretKey } = decodeSuiPrivateKey(config.privateKey);
|
|
1154
|
+
this.keypair = Ed25519Keypair.fromSecretKey(secretKey);
|
|
1155
|
+
const rpcUrl = config.rpcUrl || (config.network === "mainnet" ? "https://fullnode.mainnet.sui.io:443" : "https://fullnode.testnet.sui.io:443");
|
|
1156
|
+
this.suiClient = new SuiClient({ url: rpcUrl });
|
|
1157
|
+
console.log(` \u{1F511} On-chain signing enabled: ${this.keypair.toSuiAddress().slice(0, 15)}...`);
|
|
1158
|
+
} catch (error) {
|
|
1159
|
+
console.error(` \u26A0\uFE0F Failed to load private key: ${error}`);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1144
1162
|
}
|
|
1145
1163
|
/**
|
|
1146
1164
|
* Register a custom skill handler
|
|
@@ -1380,13 +1398,54 @@ var ClankAgent = class {
|
|
|
1380
1398
|
console.log(` Handler executed successfully`);
|
|
1381
1399
|
const storedOutput = await this.client.walrus.storeJson(result.output);
|
|
1382
1400
|
console.log(` Output stored: ${storedOutput.blobId.slice(0, 20)}...`);
|
|
1383
|
-
|
|
1401
|
+
if (this.keypair && this.suiClient && this.config.packageId) {
|
|
1402
|
+
try {
|
|
1403
|
+
console.log(` Submitting on-chain...`);
|
|
1404
|
+
await this.submitTaskOnChain(task.taskId, storedOutput.blobId);
|
|
1405
|
+
console.log(` \u2705 Task submitted on-chain: ${task.taskId.slice(0, 16)}`);
|
|
1406
|
+
} catch (error) {
|
|
1407
|
+
console.error(` \u274C On-chain submission failed: ${error}`);
|
|
1408
|
+
}
|
|
1409
|
+
} else {
|
|
1410
|
+
console.log(` \u2705 Task completed (no on-chain key): ${task.taskId.slice(0, 16)}`);
|
|
1411
|
+
}
|
|
1384
1412
|
markTaskCompleted(this.state, task.taskId, task.paymentAmountMist);
|
|
1385
1413
|
} catch (error) {
|
|
1386
1414
|
console.error(` \u274C Execution error: ${error}`);
|
|
1387
1415
|
markTaskFailed(this.state, task.taskId);
|
|
1388
1416
|
}
|
|
1389
1417
|
}
|
|
1418
|
+
/**
|
|
1419
|
+
* Submit task output on-chain
|
|
1420
|
+
*/
|
|
1421
|
+
async submitTaskOnChain(taskId, outputRef) {
|
|
1422
|
+
if (!this.keypair || !this.suiClient || !this.config.packageId) {
|
|
1423
|
+
throw new Error("On-chain signing not configured");
|
|
1424
|
+
}
|
|
1425
|
+
const outputHash = outputRef;
|
|
1426
|
+
const tx = new Transaction();
|
|
1427
|
+
tx.setGasBudget(1e7);
|
|
1428
|
+
tx.moveCall({
|
|
1429
|
+
target: `${this.config.packageId}::task::submit`,
|
|
1430
|
+
arguments: [
|
|
1431
|
+
tx.object(taskId),
|
|
1432
|
+
tx.object(this.config.agentId),
|
|
1433
|
+
tx.pure.string(outputRef),
|
|
1434
|
+
tx.pure.string(outputHash),
|
|
1435
|
+
tx.object("0x6")
|
|
1436
|
+
// Clock
|
|
1437
|
+
]
|
|
1438
|
+
});
|
|
1439
|
+
const result = await this.suiClient.signAndExecuteTransaction({
|
|
1440
|
+
transaction: tx,
|
|
1441
|
+
signer: this.keypair,
|
|
1442
|
+
options: { showEffects: true }
|
|
1443
|
+
});
|
|
1444
|
+
if (result.effects?.status?.status !== "success") {
|
|
1445
|
+
throw new Error(`Transaction failed: ${result.effects?.status?.error || "unknown"}`);
|
|
1446
|
+
}
|
|
1447
|
+
console.log(` Tx: ${result.digest.slice(0, 15)}...`);
|
|
1448
|
+
}
|
|
1390
1449
|
/**
|
|
1391
1450
|
* Refresh skills list from API
|
|
1392
1451
|
*/
|
|
@@ -1685,6 +1744,7 @@ function loadConfig() {
|
|
|
1685
1744
|
network: process.env.CLANK_NETWORK ?? "testnet",
|
|
1686
1745
|
rpcUrl: process.env.SUI_RPC_URL,
|
|
1687
1746
|
packageId: process.env.CLANK_PACKAGE_ID,
|
|
1747
|
+
privateKey: process.env.CLANK_PRIVATE_KEY,
|
|
1688
1748
|
// Walrus configuration
|
|
1689
1749
|
walrusAggregator: process.env.WALRUS_AGGREGATOR_URL,
|
|
1690
1750
|
walrusPublisher: process.env.WALRUS_PUBLISHER_URL,
|