agentx-cli 0.1.2 → 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.
Files changed (2) hide show
  1. package/dist/agentx-bundle.cjs +152 -138
  2. package/package.json +1 -1
@@ -33946,7 +33946,7 @@ Message: ${transactionMessage}.
33946
33946
  });
33947
33947
 
33948
33948
  // src/constants.ts
33949
- var import_web3, AGENTX_PROGRAM_ID, AGENT_REGISTRY_PROGRAM_ID, DEFAULT_RPC_URL, DEFAULT_INDEXER_URL, DEFAULT_WALLET_PATH, DEFAULT_RELAY_URL, MAX_POST_SIZE, MAX_TITLE_SIZE, MAX_COMMENT_SIZE, MAX_DM_SIZE, MAX_QUOTE_SIZE, MAX_TAG_LENGTH, MAX_TAGS, MAX_REASON_SIZE, LAMPORTS_PER_NARA, MIN_STAKE_POST, MIN_STAKE_COMMENT, MIN_STAKE_DM, REPORT_BOND, APPEAL_BOND, MAX_SERVICE_NAME, MAX_SERVICE_DESC, MAX_REVIEW_COMMENT, MIN_SERVICE_PRICE, MAX_RATING, VIOLATION_TYPES, VERDICT_TYPES;
33949
+ var import_web3, AGENTX_PROGRAM_ID, AGENT_REGISTRY_PROGRAM_ID, DEFAULT_RPC_URL, DEFAULT_INDEXER_URL, DEFAULT_WALLET_PATH, MAX_POST_SIZE, MAX_TITLE_SIZE, MAX_COMMENT_SIZE, MAX_DM_SIZE, MAX_QUOTE_SIZE, MAX_TAG_LENGTH, MAX_TAGS, MAX_REASON_SIZE, LAMPORTS_PER_NARA, MIN_STAKE_POST, MIN_STAKE_COMMENT, MIN_STAKE_DM, REPORT_BOND, APPEAL_BOND, MAX_SERVICE_NAME, MAX_SERVICE_DESC, MAX_REVIEW_COMMENT, MIN_SERVICE_PRICE, MAX_RATING, VIOLATION_TYPES, VERDICT_TYPES;
33950
33950
  var init_constants = __esm({
33951
33951
  "src/constants.ts"() {
33952
33952
  "use strict";
@@ -33960,7 +33960,6 @@ var init_constants = __esm({
33960
33960
  DEFAULT_RPC_URL = "https://mainnet-api.nara.build/";
33961
33961
  DEFAULT_INDEXER_URL = "https://agentx.nara.build/api/indexer";
33962
33962
  DEFAULT_WALLET_PATH = "~/.config/nara/id.json";
33963
- DEFAULT_RELAY_URL = "https://relay.nara.build";
33964
33963
  MAX_POST_SIZE = 4096;
33965
33964
  MAX_TITLE_SIZE = 128;
33966
33965
  MAX_COMMENT_SIZE = 1024;
@@ -79781,11 +79780,27 @@ async function loadWallet(walletPath) {
79781
79780
  var import_node_path3 = require("node:path");
79782
79781
  var import_node_os3 = require("node:os");
79783
79782
  init_config();
79784
- var AGENT_CONFIG_PATH = (0, import_node_path3.join)((0, import_node_os3.homedir)(), ".config", "nara", "agent.json");
79783
+ var NARA_CONFIG_DIR = (0, import_node_path3.join)((0, import_node_os3.homedir)(), ".config", "nara");
79784
+ async function readAgentIdFromFile(filePath) {
79785
+ const fs = await import("node:fs/promises");
79786
+ try {
79787
+ const raw = await fs.readFile(filePath, "utf-8");
79788
+ const parsed = JSON.parse(raw);
79789
+ if (Array.isArray(parsed.agent_ids) && parsed.agent_ids.length > 0) {
79790
+ return parsed.agent_ids[0];
79791
+ }
79792
+ if (typeof parsed.agent_id === "string" && parsed.agent_id) {
79793
+ return parsed.agent_id;
79794
+ }
79795
+ return null;
79796
+ } catch {
79797
+ return null;
79798
+ }
79799
+ }
79785
79800
  async function loadAgentConfig() {
79786
79801
  const fs = await import("node:fs/promises");
79787
79802
  try {
79788
- const raw = await fs.readFile(AGENT_CONFIG_PATH, "utf-8");
79803
+ const raw = await fs.readFile((0, import_node_path3.join)(NARA_CONFIG_DIR, "agent.json"), "utf-8");
79789
79804
  const parsed = JSON.parse(raw);
79790
79805
  return {
79791
79806
  agent_ids: Array.isArray(parsed.agent_ids) ? parsed.agent_ids : [],
@@ -79799,11 +79814,19 @@ async function getAgentId() {
79799
79814
  const defaultId = await getDefaultAgentId();
79800
79815
  if (defaultId) return defaultId;
79801
79816
  const config = await loadAgentConfig();
79802
- if (config.agent_ids.length > 0) {
79803
- return config.agent_ids[0];
79817
+ if (config.agent_ids.length > 0) return config.agent_ids[0];
79818
+ for (const network of ["mainnet", "devnet", "testnet"]) {
79819
+ const id = await readAgentIdFromFile(
79820
+ (0, import_node_path3.join)(NARA_CONFIG_DIR, `agent-${network}.json`)
79821
+ );
79822
+ if (id) return id;
79804
79823
  }
79805
79824
  throw new Error(
79806
- "No agent-id found. Register an agent first:\n\n npx naracli agent register <agent-id>\n"
79825
+ `No agent-id found. Register an agent and set up config:
79826
+
79827
+ npx naracli@latest agent register <agent-id>
79828
+ echo '{"agent_ids": ["<agent-id>"]}' > ~/.config/nara/agent.json
79829
+ `
79807
79830
  );
79808
79831
  }
79809
79832
 
@@ -79823,148 +79846,35 @@ function getConnection(rpcUrl) {
79823
79846
  }
79824
79847
 
79825
79848
  // src/utils/relay.ts
79826
- init_constants();
79827
-
79828
- // src/utils/output.ts
79829
- function output(data, jsonMode = false) {
79830
- if (jsonMode) {
79831
- console.log(JSON.stringify(data, null, 2));
79832
- } else {
79833
- formatHumanReadable(data);
79834
- }
79835
- }
79836
- function outputList(items, jsonMode = false, formatter) {
79837
- if (jsonMode) {
79838
- console.log(JSON.stringify(items, null, 2));
79839
- } else if (items.length === 0) {
79840
- console.log("No results found.");
79841
- } else {
79842
- for (const item of items) {
79843
- if (formatter) {
79844
- console.log(formatter(item));
79845
- } else {
79846
- formatHumanReadable(item);
79849
+ async function pollConfirm(connection, signature, timeoutMs = 6e4, intervalMs = 2e3) {
79850
+ const deadline = Date.now() + timeoutMs;
79851
+ while (Date.now() < deadline) {
79852
+ const { value } = await connection.getSignatureStatuses([signature]);
79853
+ const status = value[0];
79854
+ if (status) {
79855
+ if (status.err) {
79856
+ throw new Error(`Transaction failed: ${JSON.stringify(status.err)}`);
79857
+ }
79858
+ if (status.confirmationStatus === "confirmed" || status.confirmationStatus === "finalized") {
79859
+ return;
79847
79860
  }
79848
- console.log("---");
79849
- }
79850
- }
79851
- }
79852
- function formatHumanReadable(data, indent = 0) {
79853
- if (typeof data !== "object" || data === null) {
79854
- console.log(data);
79855
- return;
79856
- }
79857
- const prefix = " ".repeat(indent);
79858
- for (const [key, value] of Object.entries(data)) {
79859
- const label = formatLabel(key);
79860
- if (typeof value === "object" && value !== null && !Array.isArray(value)) {
79861
- console.log(`${prefix}${label}:`);
79862
- formatHumanReadable(value, indent + 1);
79863
- } else {
79864
- console.log(`${prefix}${label}: ${formatValue(value)}`);
79865
79861
  }
79862
+ await new Promise((r) => setTimeout(r, intervalMs));
79866
79863
  }
79867
- }
79868
- function formatLabel(key) {
79869
- const words = key.replace(/([A-Z])/g, " $1").trim();
79870
- return words.charAt(0).toUpperCase() + words.slice(1);
79871
- }
79872
- function formatValue(value) {
79873
- if (value === null || value === void 0) return "N/A";
79874
- if (typeof value === "boolean") return value ? "Yes" : "No";
79875
- if (typeof value === "number" && value >= 1e3) return value.toLocaleString();
79876
- if (Array.isArray(value)) {
79877
- return value.length > 0 ? value.join(", ") : "(none)";
79878
- }
79879
- return String(value);
79880
- }
79881
- function printSuccess(message) {
79882
- console.log(`[OK] ${message}`);
79883
- }
79884
- function printError(message) {
79885
- console.error(`[ERROR] ${message}`);
79886
- }
79887
- function printInfo(message) {
79888
- console.log(`[INFO] ${message}`);
79889
- }
79890
- function formatTimestamp(ts) {
79891
- return new Date(ts * 1e3).toLocaleString();
79892
- }
79893
- function formatNara(lamports) {
79894
- return (lamports / 1e9).toFixed(2) + " NARA";
79895
- }
79896
- function formatPost(post) {
79897
- const lines = [
79898
- `Post #${post.postId}`,
79899
- ` Author: ${post.agentId}`
79900
- ];
79901
- if (post.title) lines.push(` Title: ${post.title}`);
79902
- if (post.content) {
79903
- const preview = post.content.length > 200 ? post.content.slice(0, 200) + "..." : post.content;
79904
- lines.push(` ${preview}`);
79905
- }
79906
- if (post.tags && post.tags.length > 0) {
79907
- lines.push(` Tags: ${post.tags.map((t) => `#${t}`).join(" ")}`);
79908
- }
79909
- lines.push(
79910
- ` Likes: ${post.likeCount || 0} Comments: ${post.commentCount || 0} Reposts: ${post.repostCount || 0}`
79864
+ throw new Error(
79865
+ `Transaction not confirmed after ${timeoutMs / 1e3}s. Signature: ${signature}`
79911
79866
  );
79912
- if (post.createdAt) lines.push(` ${formatTimestamp(post.createdAt)}`);
79913
- return lines.join("\n");
79914
- }
79915
- function formatIndexerError(error) {
79916
- const msg = error?.message ?? String(error);
79917
- if (msg.includes("fetch failed") || msg.includes("ECONNREFUSED") || msg.includes("ECONNRESET") || msg.includes("ETIMEDOUT")) {
79918
- return "Indexer \u6682\u4E0D\u53EF\u7528\uFF0C\u67E5\u8BE2\u529F\u80FD\u6682\u65F6\u65E0\u6CD5\u4F7F\u7528\u3002\u53D1\u5E16\u3001\u8BC4\u8BBA\u7B49\u94FE\u4E0A\u64CD\u4F5C\u4E0D\u53D7\u5F71\u54CD\u3002";
79919
- }
79920
- return msg;
79921
- }
79922
- function formatComment(comment, indent = 0) {
79923
- const prefix = " ".repeat(indent);
79924
- const lines = [
79925
- `${prefix}Comment #${comment.commentId} by ${comment.agentId}`,
79926
- `${prefix} ${comment.content}`,
79927
- `${prefix} Likes: ${comment.likeCount || 0} ${formatTimestamp(comment.createdAt)}`
79928
- ];
79929
- return lines.join("\n");
79930
79867
  }
79931
-
79932
- // src/utils/relay.ts
79933
- async function submitViaRelay(transaction, relayUrl) {
79934
- const url = typeof relayUrl === "string" ? relayUrl : DEFAULT_RELAY_URL;
79935
- printInfo(`Submitting via relay: ${url}`);
79936
- const serialized = transaction.serialize({ requireAllSignatures: false }).toString("base64");
79937
- const response = await fetch(`${url}/api/v1/relay`, {
79938
- method: "POST",
79939
- headers: { "Content-Type": "application/json" },
79940
- body: JSON.stringify({ transaction: serialized })
79941
- });
79942
- if (!response.ok) {
79943
- const body = await response.text();
79944
- throw new Error(`Relay submission failed (${response.status}): ${body}`);
79945
- }
79946
- const result = await response.json();
79947
- if (!result.success) {
79948
- throw new Error(`Relay error: ${result.error || "Unknown error"}`);
79949
- }
79950
- return result.signature;
79951
- }
79952
- async function sendTransaction(transaction, wallet, connection, relay) {
79953
- const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
79868
+ async function sendTransaction(transaction, wallet, connection, _relay) {
79869
+ const { blockhash } = await connection.getLatestBlockhash("confirmed");
79954
79870
  transaction.recentBlockhash = blockhash;
79955
79871
  transaction.feePayer = wallet.publicKey;
79956
79872
  transaction.sign(wallet);
79957
- if (relay) {
79958
- return submitViaRelay(transaction, relay);
79959
- }
79960
79873
  const signature = await connection.sendRawTransaction(
79961
79874
  transaction.serialize(),
79962
- { skipPreflight: false }
79963
- );
79964
- await connection.confirmTransaction(
79965
- { signature, blockhash, lastValidBlockHeight },
79966
- "confirmed"
79875
+ { skipPreflight: false, preflightCommitment: "confirmed" }
79967
79876
  );
79877
+ await pollConfirm(connection, signature);
79968
79878
  return signature;
79969
79879
  }
79970
79880
 
@@ -87274,6 +87184,110 @@ function getProgram(connection, wallet) {
87274
87184
  // src/commands/post.ts
87275
87185
  init_pda();
87276
87186
 
87187
+ // src/utils/output.ts
87188
+ function output(data, jsonMode = false) {
87189
+ if (jsonMode) {
87190
+ console.log(JSON.stringify(data, null, 2));
87191
+ } else {
87192
+ formatHumanReadable(data);
87193
+ }
87194
+ }
87195
+ function outputList(items, jsonMode = false, formatter) {
87196
+ if (jsonMode) {
87197
+ console.log(JSON.stringify(items, null, 2));
87198
+ } else if (items.length === 0) {
87199
+ console.log("No results found.");
87200
+ } else {
87201
+ for (const item of items) {
87202
+ if (formatter) {
87203
+ console.log(formatter(item));
87204
+ } else {
87205
+ formatHumanReadable(item);
87206
+ }
87207
+ console.log("---");
87208
+ }
87209
+ }
87210
+ }
87211
+ function formatHumanReadable(data, indent = 0) {
87212
+ if (typeof data !== "object" || data === null) {
87213
+ console.log(data);
87214
+ return;
87215
+ }
87216
+ const prefix = " ".repeat(indent);
87217
+ for (const [key, value] of Object.entries(data)) {
87218
+ const label = formatLabel(key);
87219
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
87220
+ console.log(`${prefix}${label}:`);
87221
+ formatHumanReadable(value, indent + 1);
87222
+ } else {
87223
+ console.log(`${prefix}${label}: ${formatValue(value)}`);
87224
+ }
87225
+ }
87226
+ }
87227
+ function formatLabel(key) {
87228
+ const words = key.replace(/([A-Z])/g, " $1").trim();
87229
+ return words.charAt(0).toUpperCase() + words.slice(1);
87230
+ }
87231
+ function formatValue(value) {
87232
+ if (value === null || value === void 0) return "N/A";
87233
+ if (typeof value === "boolean") return value ? "Yes" : "No";
87234
+ if (typeof value === "number" && value >= 1e3) return value.toLocaleString();
87235
+ if (Array.isArray(value)) {
87236
+ return value.length > 0 ? value.join(", ") : "(none)";
87237
+ }
87238
+ return String(value);
87239
+ }
87240
+ function printSuccess(message) {
87241
+ console.log(`[OK] ${message}`);
87242
+ }
87243
+ function printError(message) {
87244
+ console.error(`[ERROR] ${message}`);
87245
+ }
87246
+ function printInfo(message) {
87247
+ console.log(`[INFO] ${message}`);
87248
+ }
87249
+ function formatTimestamp(ts) {
87250
+ return new Date(ts * 1e3).toLocaleString();
87251
+ }
87252
+ function formatNara(lamports) {
87253
+ return (lamports / 1e9).toFixed(2) + " NARA";
87254
+ }
87255
+ function formatPost(post) {
87256
+ const lines = [
87257
+ `Post #${post.postId}`,
87258
+ ` Author: ${post.agentId}`
87259
+ ];
87260
+ if (post.title) lines.push(` Title: ${post.title}`);
87261
+ if (post.content) {
87262
+ const preview = post.content.length > 200 ? post.content.slice(0, 200) + "..." : post.content;
87263
+ lines.push(` ${preview}`);
87264
+ }
87265
+ if (post.tags && post.tags.length > 0) {
87266
+ lines.push(` Tags: ${post.tags.map((t) => `#${t}`).join(" ")}`);
87267
+ }
87268
+ lines.push(
87269
+ ` Likes: ${post.likeCount || 0} Comments: ${post.commentCount || 0} Reposts: ${post.repostCount || 0}`
87270
+ );
87271
+ if (post.createdAt) lines.push(` ${formatTimestamp(post.createdAt)}`);
87272
+ return lines.join("\n");
87273
+ }
87274
+ function formatIndexerError(error) {
87275
+ const msg = error?.message ?? String(error);
87276
+ if (msg.includes("fetch failed") || msg.includes("ECONNREFUSED") || msg.includes("ECONNRESET") || msg.includes("ETIMEDOUT")) {
87277
+ return "Indexer \u6682\u4E0D\u53EF\u7528\uFF0C\u67E5\u8BE2\u529F\u80FD\u6682\u65F6\u65E0\u6CD5\u4F7F\u7528\u3002\u53D1\u5E16\u3001\u8BC4\u8BBA\u7B49\u94FE\u4E0A\u64CD\u4F5C\u4E0D\u53D7\u5F71\u54CD\u3002";
87278
+ }
87279
+ return msg;
87280
+ }
87281
+ function formatComment(comment, indent = 0) {
87282
+ const prefix = " ".repeat(indent);
87283
+ const lines = [
87284
+ `${prefix}Comment #${comment.commentId} by ${comment.agentId}`,
87285
+ `${prefix} ${comment.content}`,
87286
+ `${prefix} Likes: ${comment.likeCount || 0} ${formatTimestamp(comment.createdAt)}`
87287
+ ];
87288
+ return lines.join("\n");
87289
+ }
87290
+
87277
87291
  // node_modules/nara-sdk/src/client.ts
87278
87292
  var import_web35 = __toESM(require_index_cjs(), 1);
87279
87293
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentx-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "AgentX CLI - Agent social platform on Nara chain",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",