@iqai/adk-cli 0.2.8 → 0.2.9

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/index.mjs CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
 
4
4
  // src/index.ts
5
- import chalk5 from "chalk";
5
+ import chalk6 from "chalk";
6
6
  import { program } from "commander";
7
7
 
8
8
  // package.json
9
9
  var package_default = {
10
10
  name: "@iqai/adk-cli",
11
- version: "0.2.8",
11
+ version: "0.2.9",
12
12
  description: "CLI tool for creating, running, and testing ADK agents",
13
13
  main: "dist/index.js",
14
14
  types: "dist/index.d.ts",
@@ -288,20 +288,55 @@ async function createProject(projectName, options) {
288
288
  // src/commands/run.ts
289
289
  import * as p from "@clack/prompts";
290
290
  import { log, spinner as spinner2 } from "@clack/prompts";
291
- import chalk3 from "chalk";
291
+ import chalk4 from "chalk";
292
292
  import { marked } from "marked";
293
293
  import { markedTerminal } from "marked-terminal";
294
294
 
295
295
  // src/commands/serve.ts
296
296
  import { existsSync as existsSync3 } from "fs";
297
297
  import { resolve } from "path";
298
- import chalk2 from "chalk";
298
+ import chalk3 from "chalk";
299
299
 
300
300
  // src/server/index.ts
301
301
  import { serve } from "@hono/node-server";
302
302
  import { InMemorySessionService } from "@iqai/adk";
303
303
  import { Hono } from "hono";
304
304
 
305
+ // src/server/logger.ts
306
+ import chalk2 from "chalk";
307
+ var Logger = class {
308
+ name;
309
+ quiet;
310
+ debugEnabled;
311
+ constructor({ name, quiet = false }) {
312
+ this.name = name;
313
+ this.quiet = quiet;
314
+ this.debugEnabled = process.env.NODE_ENV === "development" || process.env.ADK_DEBUG === "true";
315
+ }
316
+ time() {
317
+ return (/* @__PURE__ */ new Date()).toLocaleTimeString();
318
+ }
319
+ prefix(icon, message) {
320
+ return `${this.time()} ${icon} [${this.name}] ${message}`;
321
+ }
322
+ debug(message, ...args) {
323
+ if (!this.debugEnabled || this.quiet) return;
324
+ console.debug(chalk2.blue(this.prefix("\u{1F41B}", message)), ...args);
325
+ }
326
+ info(message, ...args) {
327
+ if (this.quiet) return;
328
+ console.info(chalk2.cyan(this.prefix("\u2139\uFE0F", message)), ...args);
329
+ }
330
+ warn(message, ...args) {
331
+ if (this.quiet) return;
332
+ console.warn(chalk2.yellow(this.prefix("\u{1F6A7}", message)), ...args);
333
+ }
334
+ error(message, ...args) {
335
+ if (this.quiet) return;
336
+ console.error(chalk2.red(this.prefix("\u274C", message)), ...args);
337
+ }
338
+ };
339
+
305
340
  // src/server/routes.ts
306
341
  import { cors } from "hono/cors";
307
342
  function setupRoutes(app, agentManager, sessionManager, agentsDir) {
@@ -368,6 +403,10 @@ import { AgentBuilder } from "@iqai/adk";
368
403
  var AgentScanner = class {
369
404
  constructor(quiet = false) {
370
405
  this.quiet = quiet;
406
+ this.logger = new Logger({ name: "session-manager", quiet: this.quiet });
407
+ }
408
+ logger;
409
+ async getSessionMessages(loadedAgent) {
371
410
  }
372
411
  scanAgents(agentsDir, loadedAgents) {
373
412
  const agents = /* @__PURE__ */ new Map();
@@ -387,7 +426,6 @@ var AgentScanner = class {
387
426
  return skipDirs.includes(dirName);
388
427
  };
389
428
  const scanDirectory = (dir) => {
390
- if (!existsSync2(dir)) return;
391
429
  const items = readdirSync(dir);
392
430
  for (const item of items) {
393
431
  const fullPath = join2(dir, item);
@@ -419,9 +457,7 @@ var AgentScanner = class {
419
457
  }
420
458
  };
421
459
  scanDirectory(scanDir);
422
- if (!this.quiet) {
423
- console.log(`\u2705 Agent scan complete. Found ${agents.size} agents.`);
424
- }
460
+ this.logger.info(`Agent scan complete. Found ${agents.size} agents. \u2728`);
425
461
  return agents;
426
462
  }
427
463
  extractAgentNameFromFile(filePath) {
@@ -440,7 +476,9 @@ var AgentScanner = class {
440
476
  var AgentLoader = class {
441
477
  constructor(quiet = false) {
442
478
  this.quiet = quiet;
479
+ this.logger = new Logger({ name: "agent-loader", quiet: this.quiet });
443
480
  }
481
+ logger;
444
482
  /**
445
483
  * Import a TypeScript file by compiling it on-demand
446
484
  */
@@ -501,15 +539,11 @@ var AgentLoader = class {
501
539
  if (agentExport) {
502
540
  const isPrimitive = (v) => v == null || ["string", "number", "boolean"].includes(typeof v);
503
541
  if (isPrimitive(agentExport)) {
504
- if (!this.quiet) {
505
- console.log(
506
- `\u2139\uFE0F Ignoring primitive 'agent' export in ${filePath}; scanning module for factory...`
507
- );
508
- }
542
+ this.logger.info(
543
+ `Ignoring primitive 'agent' export in ${filePath}; scanning module for factory...`
544
+ );
509
545
  } else {
510
- if (!this.quiet) {
511
- console.log(`\u2705 TS agent imported via esbuild: ${filePath}`);
512
- }
546
+ this.logger.info(`TS agent imported via esbuild: ${filePath} \u2705`);
513
547
  return { agent: agentExport };
514
548
  }
515
549
  }
@@ -555,8 +589,8 @@ var AgentLoader = class {
555
589
  }
556
590
  }
557
591
  } catch (error) {
558
- console.warn(
559
- `\u26A0\uFE0F Warning: Could not load ${envFile} file: ${error instanceof Error ? error.message : String(error)}`
592
+ this.logger.warn(
593
+ `Warning: Could not load ${envFile} file: ${error instanceof Error ? error.message : String(error)}`
560
594
  );
561
595
  }
562
596
  }
@@ -637,11 +671,13 @@ var AgentManager = class {
637
671
  this.quiet = quiet;
638
672
  this.scanner = new AgentScanner(quiet);
639
673
  this.loader = new AgentLoader(quiet);
674
+ this.logger = new Logger({ name: "agent-manager", quiet: this.quiet });
640
675
  }
641
676
  agents = /* @__PURE__ */ new Map();
642
677
  loadedAgents = /* @__PURE__ */ new Map();
643
678
  scanner;
644
679
  loader;
680
+ logger;
645
681
  getAgents() {
646
682
  return this.agents;
647
683
  }
@@ -695,7 +731,10 @@ var AgentManager = class {
695
731
  agent.instance = exportedAgent;
696
732
  agent.name = exportedAgent.name;
697
733
  } catch (error) {
698
- console.error(`\u274C Failed to load agent "${agent.name}":`, error);
734
+ const agentName = agent?.name ?? agentPath;
735
+ this.logger.error(
736
+ `Failed to load agent "${agentName}": ${error instanceof Error ? error.message : String(error)}`
737
+ );
699
738
  throw new Error(
700
739
  `Failed to load agent: ${error instanceof Error ? error.message : String(error)}`
701
740
  );
@@ -736,9 +775,8 @@ var AgentManager = class {
736
775
  return response;
737
776
  } catch (error) {
738
777
  const errorMessage = error instanceof Error ? error.message : String(error);
739
- console.error(
740
- `Error sending message to agent ${agentPath}:`,
741
- errorMessage
778
+ this.logger.error(
779
+ `Error sending message to agent ${agentPath}: ${errorMessage}`
742
780
  );
743
781
  throw new Error(`Failed to send message to agent: ${errorMessage}`);
744
782
  }
@@ -750,9 +788,12 @@ var AgentManager = class {
750
788
  }
751
789
  };
752
790
  var SessionManager = class {
753
- constructor(sessionService) {
791
+ constructor(sessionService, quiet = false) {
754
792
  this.sessionService = sessionService;
793
+ this.quiet = quiet;
794
+ this.logger = new Logger({ name: "session-manager", quiet: this.quiet });
755
795
  }
796
+ logger;
756
797
  async getSessionMessages(loadedAgent) {
757
798
  try {
758
799
  const session = await this.sessionService.getSession(
@@ -773,7 +814,10 @@ var SessionManager = class {
773
814
  }));
774
815
  return messages;
775
816
  } catch (error) {
776
- console.error("Error fetching messages:", error);
817
+ this.logger.error(
818
+ "Error fetching messages:",
819
+ error instanceof Error ? error.message : String(error)
820
+ );
777
821
  return [];
778
822
  }
779
823
  }
@@ -787,13 +831,16 @@ var ADKServer = class {
787
831
  app;
788
832
  server;
789
833
  config;
834
+ logger;
790
835
  constructor(agentsDir, port = 8042, host = "localhost", quiet = false) {
791
836
  this.config = { agentsDir, port, host, quiet };
837
+ this.logger = new Logger({ name: "adk-server", quiet });
792
838
  this.sessionService = new InMemorySessionService();
793
839
  this.agentManager = new AgentManager(this.sessionService, quiet);
794
- this.sessionManager = new SessionManager(this.sessionService);
840
+ this.sessionManager = new SessionManager(this.sessionService, quiet);
795
841
  this.app = new Hono();
796
842
  setupRoutes(this.app, this.agentManager, this.sessionManager, agentsDir);
843
+ this.logger.info(`Starting agent scan in ${agentsDir} \u2728`);
797
844
  this.agentManager.scanAgents(agentsDir);
798
845
  }
799
846
  async start() {
@@ -804,16 +851,21 @@ var ADKServer = class {
804
851
  hostname: this.config.host
805
852
  });
806
853
  setTimeout(() => {
854
+ this.logger.info(
855
+ `Server listening on http://${this.config.host}:${this.config.port} \u{1F680}`
856
+ );
807
857
  resolve2();
808
858
  }, 100);
809
859
  });
810
860
  }
811
861
  async stop() {
812
862
  return new Promise((resolve2) => {
863
+ this.logger.info("Stopping server and all agents... \u{1F6D1}");
813
864
  this.agentManager.stopAllAgents();
814
865
  if (this.server) {
815
866
  this.server.close();
816
867
  }
868
+ this.logger.info("Server stopped");
817
869
  resolve2();
818
870
  });
819
871
  }
@@ -828,21 +880,21 @@ async function serveCommand(options = {}) {
828
880
  const host = options.host || "localhost";
829
881
  const agentsDir = resolve(options.dir || ".");
830
882
  if (!existsSync3(agentsDir)) {
831
- console.error(chalk2.red(`\u274C Directory not found: ${agentsDir}`));
883
+ console.error(chalk3.red(`\u274C Directory not found: ${agentsDir}`));
832
884
  process.exit(1);
833
885
  }
834
886
  if (!options.quiet) {
835
- console.log(chalk2.blue(`\u{1F680} ADK Server starting on http://${host}:${port}`));
887
+ console.log(chalk3.blue(`\u{1F680} ADK Server starting on http://${host}:${port}`));
836
888
  }
837
889
  const server = new ADKServer(agentsDir, port, host, options.quiet);
838
890
  try {
839
891
  await server.start();
840
892
  if (!options.quiet) {
841
- console.log(chalk2.green("\u2705 Server ready"));
893
+ console.log(chalk3.green("\u2705 Server ready"));
842
894
  }
843
895
  const cleanup = async () => {
844
896
  if (!options.quiet) {
845
- console.log(chalk2.yellow("\n\u{1F6D1} Stopping server..."));
897
+ console.log(chalk3.yellow("\n\u{1F6D1} Stopping server..."));
846
898
  }
847
899
  await server.stop();
848
900
  process.exit(0);
@@ -851,7 +903,7 @@ async function serveCommand(options = {}) {
851
903
  process.on("SIGTERM", cleanup);
852
904
  return server;
853
905
  } catch (error) {
854
- console.error(chalk2.red("\u274C Failed to start ADK server:"), error);
906
+ console.error(chalk3.red("\u274C Failed to start ADK server:"), error);
855
907
  process.exit(1);
856
908
  }
857
909
  }
@@ -974,7 +1026,7 @@ var AgentChatClient = class {
974
1026
  await this.sendMessage(message.trim());
975
1027
  }
976
1028
  } catch (error) {
977
- console.error(chalk3.red("Error in chat:"), error);
1029
+ console.error(chalk4.red("Error in chat:"), error);
978
1030
  break;
979
1031
  }
980
1032
  }
@@ -991,7 +1043,7 @@ async function runAgent(agentPath, options = {}) {
991
1043
  if (options.server) {
992
1044
  const apiPort = 8042;
993
1045
  const host = options.host || "localhost";
994
- console.log(chalk3.blue("\u{1F680} Starting ADK Server..."));
1046
+ console.log(chalk4.blue("\u{1F680} Starting ADK Server..."));
995
1047
  const serveOptions = {
996
1048
  port: apiPort,
997
1049
  dir: process.cwd(),
@@ -1000,16 +1052,16 @@ async function runAgent(agentPath, options = {}) {
1000
1052
  };
1001
1053
  try {
1002
1054
  const server = await serveCommand(serveOptions);
1003
- console.log(chalk3.cyan("Press Ctrl+C to stop the server"));
1055
+ console.log(chalk4.cyan("Press Ctrl+C to stop the server"));
1004
1056
  process.on("SIGINT", async () => {
1005
- console.log(chalk3.yellow("\n\u{1F6D1} Stopping server..."));
1057
+ console.log(chalk4.yellow("\n\u{1F6D1} Stopping server..."));
1006
1058
  await server.stop();
1007
1059
  process.exit(0);
1008
1060
  });
1009
1061
  return new Promise(() => {
1010
1062
  });
1011
1063
  } catch (error) {
1012
- console.error(chalk3.red("\u274C Failed to start server"));
1064
+ console.error(chalk4.red("\u274C Failed to start server"));
1013
1065
  process.exit(1);
1014
1066
  }
1015
1067
  }
@@ -1073,14 +1125,14 @@ async function runAgent(agentPath, options = {}) {
1073
1125
  }
1074
1126
 
1075
1127
  // src/commands/web.ts
1076
- import chalk4 from "chalk";
1128
+ import chalk5 from "chalk";
1077
1129
  async function webCommand(options = {}) {
1078
1130
  const apiPort = options.port || 8042;
1079
1131
  const webPort = options.webPort || 3e3;
1080
1132
  const host = options.host || "localhost";
1081
1133
  const useLocal = options.local || false;
1082
1134
  const webUrl = options.webUrl || "https://adk-web.iqai.com";
1083
- console.log(chalk4.blue("\u{1F310} Starting ADK Web Interface..."));
1135
+ console.log(chalk5.blue("\u{1F310} Starting ADK Web Interface..."));
1084
1136
  const serveOptions = {
1085
1137
  port: apiPort,
1086
1138
  dir: options.dir,
@@ -1102,9 +1154,9 @@ async function webCommand(options = {}) {
1102
1154
  webAppUrl = `${webUrl}?port=${apiPort}`;
1103
1155
  }
1104
1156
  }
1105
- console.log(chalk4.cyan(`\u{1F517} Open this URL in your browser: ${webAppUrl}`));
1106
- console.log(chalk4.gray(` API Server: http://${host}:${apiPort}`));
1107
- console.log(chalk4.cyan("Press Ctrl+C to stop the API server"));
1157
+ console.log(chalk5.cyan(`\u{1F517} Open this URL in your browser: ${webAppUrl}`));
1158
+ console.log(chalk5.gray(` API Server: http://${host}:${apiPort}`));
1159
+ console.log(chalk5.cyan("Press Ctrl+C to stop the API server"));
1108
1160
  }
1109
1161
 
1110
1162
  // src/index.ts
@@ -1116,7 +1168,7 @@ program.command("new").description("Create a new ADK project").argument("[projec
1116
1168
  try {
1117
1169
  await createProject(projectName, options);
1118
1170
  } catch (error) {
1119
- console.error(chalk5.red("Error creating project:"), error);
1171
+ console.error(chalk6.red("Error creating project:"), error);
1120
1172
  process.exit(1);
1121
1173
  }
1122
1174
  });
@@ -1131,7 +1183,7 @@ program.command("run").description("Start an interactive chat with an agent").ar
1131
1183
  try {
1132
1184
  await runAgent(agentPath, options);
1133
1185
  } catch (error) {
1134
- console.error(chalk5.red("Error running agent:"), error);
1186
+ console.error(chalk6.red("Error running agent:"), error);
1135
1187
  process.exit(1);
1136
1188
  }
1137
1189
  });
@@ -1151,7 +1203,7 @@ program.command("web").description("Start a web interface for testing agents").o
1151
1203
  try {
1152
1204
  await webCommand(options);
1153
1205
  } catch (error) {
1154
- console.error(chalk5.red("Error starting web UI:"), error);
1206
+ console.error(chalk6.red("Error starting web UI:"), error);
1155
1207
  process.exit(1);
1156
1208
  }
1157
1209
  });
@@ -1163,7 +1215,7 @@ program.command("serve").description("Start an API server for agent management")
1163
1215
  try {
1164
1216
  await serveCommand(options);
1165
1217
  } catch (error) {
1166
- console.error(chalk5.red("Error starting server:"), error);
1218
+ console.error(chalk6.red("Error starting server:"), error);
1167
1219
  process.exit(1);
1168
1220
  }
1169
1221
  });