@net-protocol/cli 0.1.45 → 0.1.46

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.
@@ -7971,12 +7971,12 @@ async function resolveAuth(options) {
7971
7971
  );
7972
7972
  }
7973
7973
  const commonOptions = parseCommonOptionsWithDefault({
7974
- privateKey,
7974
+ privateKey: options.privateKey,
7975
7975
  chainId: options.chainId,
7976
7976
  rpcUrl: options.rpcUrl
7977
7977
  });
7978
7978
  const account = privateKeyToAccount(commonOptions.privateKey);
7979
- console.log(chalk4.blue("Creating session..."));
7979
+ console.error(chalk4.blue("Creating session..."));
7980
7980
  const { sessionToken: token } = await createRelaySession({
7981
7981
  apiUrl,
7982
7982
  chainId: commonOptions.chainId,
@@ -8013,24 +8013,42 @@ async function executeCreate(name, options) {
8013
8013
  const filters = buildFilters(options);
8014
8014
  if (filters) config.filters = filters;
8015
8015
  const profile = buildProfile(options);
8016
- console.log(chalk4.blue(`Creating agent "${name}"...`));
8016
+ if (!options.json) {
8017
+ console.log(chalk4.blue(`Creating agent "${name}"...`));
8018
+ }
8017
8019
  const result = await auth.client.createAgent({
8018
8020
  sessionToken: auth.sessionToken,
8019
8021
  config,
8020
8022
  profile
8021
8023
  });
8022
- if (!result.success) {
8023
- exitWithError(result.error || "Failed to create agent");
8024
- }
8025
8024
  if (options.json) {
8026
8025
  console.log(jsonStringify(result));
8026
+ if (!result.success) process.exit(1);
8027
8027
  return;
8028
8028
  }
8029
+ if (!result.success) {
8030
+ exitWithError(result.error || "Failed to create agent");
8031
+ }
8029
8032
  console.log(chalk4.green("Agent created successfully!"));
8030
8033
  console.log(` Agent ID: ${result.agentId}`);
8031
8034
  console.log(` Wallet: ${result.agentWalletAddress}`);
8032
8035
  if (result.scheduleError) {
8033
- console.log(chalk4.yellow(` Schedule warning: ${result.scheduleError}`));
8036
+ const isGasOut = /gas required exceeds allowance \(0\)/i.test(
8037
+ result.scheduleError
8038
+ );
8039
+ if (isGasOut) {
8040
+ console.log(
8041
+ chalk4.yellow(
8042
+ ` Profile metadata write failed: the agent's wallet (${result.agentWalletAddress}) has 0 ETH for gas. It will be auto-funded on first \`agent run\`, or you can transfer a small amount of ETH to the wallet manually.`
8043
+ )
8044
+ );
8045
+ console.log(chalk4.gray(` Underlying revert:`));
8046
+ } else {
8047
+ console.log(chalk4.yellow(` On-chain follow-up failed:`));
8048
+ }
8049
+ console.log(
8050
+ chalk4.gray(` ${result.scheduleError.replace(/\n/g, "\n ")}`)
8051
+ );
8034
8052
  }
8035
8053
  } catch (error) {
8036
8054
  exitWithError(
@@ -8123,20 +8141,23 @@ async function executeUpdate(agentId, options) {
8123
8141
  "No changes specified. Use --name, --system-prompt, --schedule, --display-name, --bio, or filter options."
8124
8142
  );
8125
8143
  }
8126
- console.log(chalk4.blue(`Updating agent ${agentId}...`));
8144
+ if (!options.json) {
8145
+ console.log(chalk4.blue(`Updating agent ${agentId}...`));
8146
+ }
8127
8147
  const result = await auth.client.updateAgent({
8128
8148
  sessionToken: auth.sessionToken,
8129
8149
  agentId,
8130
8150
  config: hasConfigChanges ? config : void 0,
8131
8151
  profile
8132
8152
  });
8133
- if (!result.success) {
8134
- exitWithError(result.error || "Failed to update agent");
8135
- }
8136
8153
  if (options.json) {
8137
8154
  console.log(jsonStringify(result));
8155
+ if (!result.success) process.exit(1);
8138
8156
  return;
8139
8157
  }
8158
+ if (!result.success) {
8159
+ exitWithError(result.error || "Failed to update agent");
8160
+ }
8140
8161
  console.log(chalk4.green("Agent updated successfully!"));
8141
8162
  if (result.profileError) {
8142
8163
  console.log(chalk4.yellow(` Profile warning: ${result.profileError}`));
@@ -8161,7 +8182,7 @@ async function executeToggleHidden(agentId, options, hide) {
8161
8182
  const past = hide ? "hidden" : "unhidden";
8162
8183
  try {
8163
8184
  const auth = await resolveAuth(options);
8164
- console.log(chalk4.blue(`${verb} agent ${agentId}...`));
8185
+ console.error(chalk4.blue(`${verb} agent ${agentId}...`));
8165
8186
  const result = hide ? await auth.client.hideAgent(auth.sessionToken, agentId) : await auth.client.unhideAgent(auth.sessionToken, agentId);
8166
8187
  if (!result.success) {
8167
8188
  exitWithError(result.error || `Failed to ${hide ? "hide" : "unhide"} agent`);
@@ -8189,7 +8210,9 @@ async function executeRun(agentId, options) {
8189
8210
  try {
8190
8211
  const auth = await resolveAuth(options);
8191
8212
  const mode = parseRunMode(options.mode);
8192
- console.log(chalk4.blue(`Running agent ${agentId} (mode: ${mode})...`));
8213
+ if (!options.json) {
8214
+ console.log(chalk4.blue(`Running agent ${agentId} (mode: ${mode})...`));
8215
+ }
8193
8216
  const result = await auth.client.runAgent({
8194
8217
  sessionToken: auth.sessionToken,
8195
8218
  agentId,
@@ -8197,6 +8220,7 @@ async function executeRun(agentId, options) {
8197
8220
  });
8198
8221
  if (options.json) {
8199
8222
  console.log(jsonStringify(result));
8223
+ if (!result.success) process.exit(1);
8200
8224
  return;
8201
8225
  }
8202
8226
  if (!result.success) {
@@ -8315,11 +8339,13 @@ async function executeDm(agentAddress, message, options) {
8315
8339
  const auth = await resolveAuth(options);
8316
8340
  const topic = options.topic ?? generateAgentChatTopic(agentAddress);
8317
8341
  const isNewConversation = !options.topic;
8318
- console.log(
8319
- chalk4.blue(
8320
- isNewConversation ? `Starting new conversation with ${agentAddress}...` : `Continuing conversation ${topic}...`
8321
- )
8322
- );
8342
+ if (!options.json) {
8343
+ console.log(
8344
+ chalk4.blue(
8345
+ isNewConversation ? `Starting new conversation with ${agentAddress}...` : `Continuing conversation ${topic}...`
8346
+ )
8347
+ );
8348
+ }
8323
8349
  const result = await auth.client.sendMessage(
8324
8350
  {
8325
8351
  sessionToken: auth.sessionToken,
@@ -8332,8 +8358,12 @@ async function executeDm(agentAddress, message, options) {
8332
8358
  );
8333
8359
  if (options.json) {
8334
8360
  console.log(jsonStringify(result));
8361
+ if (!result.success) process.exit(1);
8335
8362
  return;
8336
8363
  }
8364
+ if (!result.success) {
8365
+ exitWithError(result.error || "Failed to send DM");
8366
+ }
8337
8367
  console.log();
8338
8368
  console.log(chalk4.cyan("You: ") + message);
8339
8369
  console.log(chalk4.green("Agent: ") + result.aiMessage);
@@ -8369,7 +8399,9 @@ async function executeDmList(options) {
8369
8399
  );
8370
8400
  }
8371
8401
  const client = new AgentClient({ apiUrl, chainId });
8372
- console.log(chalk4.blue("Loading conversations..."));
8402
+ if (!options.json) {
8403
+ console.log(chalk4.blue("Loading conversations..."));
8404
+ }
8373
8405
  const conversations = await client.listConversations(operator, {
8374
8406
  limit: options.limit
8375
8407
  });
@@ -8417,7 +8449,9 @@ async function executeDmHistory(topic, options) {
8417
8449
  );
8418
8450
  }
8419
8451
  const client = new AgentClient({ apiUrl, chainId });
8420
- console.log(chalk4.blue("Loading conversation history..."));
8452
+ if (!options.json) {
8453
+ console.log(chalk4.blue("Loading conversation history..."));
8454
+ }
8421
8455
  const messages = await client.getConversationHistory(operator, topic, {
8422
8456
  limit: options.limit
8423
8457
  });
@@ -8570,7 +8604,10 @@ function registerAgentSessionCreateCommand(parent) {
8570
8604
  "--expires-at <timestamp>",
8571
8605
  "expiresAt value from session-encode (unix seconds)",
8572
8606
  (v) => parseInt(v, 10)
8573
- ).option("--chain-id <id>", "Chain ID (default: 8453)", (v) => parseInt(v, 10)).option("--api-url <url>", "Net Protocol API URL").action(async (options) => {
8607
+ ).option("--chain-id <id>", "Chain ID (default: 8453)", (v) => parseInt(v, 10)).option("--api-url <url>", "Net Protocol API URL").option(
8608
+ "--json",
8609
+ "Output as JSON (default behavior; included for consistency with peer commands)"
8610
+ ).action(async (options) => {
8574
8611
  await executeSessionCreate(options);
8575
8612
  });
8576
8613
  }