@clankxyz/agent 0.1.1 → 0.1.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
@@ -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,52 @@ 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
- console.log(` \u2705 Task completed: ${task.taskId.slice(0, 16)}`);
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 tx = new Transaction();
1426
+ tx.setGasBudget(1e7);
1427
+ tx.moveCall({
1428
+ target: `${this.config.packageId}::task::submit`,
1429
+ arguments: [
1430
+ tx.object(taskId),
1431
+ tx.object(this.config.agentId),
1432
+ tx.pure.string(outputRef),
1433
+ tx.object("0x6")
1434
+ // Clock
1435
+ ]
1436
+ });
1437
+ const result = await this.suiClient.signAndExecuteTransaction({
1438
+ transaction: tx,
1439
+ signer: this.keypair,
1440
+ options: { showEffects: true }
1441
+ });
1442
+ if (result.effects?.status?.status !== "success") {
1443
+ throw new Error(`Transaction failed: ${result.effects?.status?.error || "unknown"}`);
1444
+ }
1445
+ console.log(` Tx: ${result.digest.slice(0, 15)}...`);
1446
+ }
1390
1447
  /**
1391
1448
  * Refresh skills list from API
1392
1449
  */
@@ -1685,6 +1742,7 @@ function loadConfig() {
1685
1742
  network: process.env.CLANK_NETWORK ?? "testnet",
1686
1743
  rpcUrl: process.env.SUI_RPC_URL,
1687
1744
  packageId: process.env.CLANK_PACKAGE_ID,
1745
+ privateKey: process.env.CLANK_PRIVATE_KEY,
1688
1746
  // Walrus configuration
1689
1747
  walrusAggregator: process.env.WALRUS_AGGREGATOR_URL,
1690
1748
  walrusPublisher: process.env.WALRUS_PUBLISHER_URL,