@iqai/adk-cli 0.2.8 → 0.3.0

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 (157) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +1 -0
  3. package/dist/app.module.d.ts +3 -0
  4. package/dist/app.module.d.ts.map +1 -0
  5. package/dist/app.module.js +24 -0
  6. package/dist/app.module.js.map +1 -0
  7. package/dist/cli/cli.module.d.ts +3 -0
  8. package/dist/cli/cli.module.d.ts.map +1 -0
  9. package/dist/cli/cli.module.js +25 -0
  10. package/dist/cli/cli.module.js.map +1 -0
  11. package/dist/cli/new.command.d.ts +10 -0
  12. package/dist/cli/new.command.d.ts.map +1 -0
  13. package/dist/cli/new.command.js +273 -0
  14. package/dist/cli/new.command.js.map +1 -0
  15. package/dist/cli/run.command.d.ts +20 -0
  16. package/dist/cli/run.command.d.ts.map +1 -0
  17. package/dist/cli/run.command.js +342 -0
  18. package/dist/cli/run.command.js.map +1 -0
  19. package/dist/cli/serve.command.d.ts +20 -0
  20. package/dist/cli/serve.command.d.ts.map +1 -0
  21. package/dist/cli/serve.command.js +137 -0
  22. package/dist/cli/serve.command.js.map +1 -0
  23. package/dist/cli/web.command.d.ts +20 -0
  24. package/dist/cli/web.command.d.ts.map +1 -0
  25. package/dist/cli/web.command.js +146 -0
  26. package/dist/cli/web.command.js.map +1 -0
  27. package/dist/common/tokens.d.ts +5 -0
  28. package/dist/common/tokens.d.ts.map +1 -0
  29. package/dist/common/tokens.js +8 -0
  30. package/dist/common/tokens.js.map +1 -0
  31. package/dist/common/types.d.ts +91 -0
  32. package/dist/common/types.d.ts.map +1 -0
  33. package/dist/common/types.js +3 -0
  34. package/dist/common/types.js.map +1 -0
  35. package/dist/http/bootstrap.d.ts +17 -0
  36. package/dist/http/bootstrap.d.ts.map +1 -0
  37. package/dist/http/bootstrap.js +221 -0
  38. package/dist/http/bootstrap.js.map +1 -0
  39. package/dist/http/config/config.module.d.ts +6 -0
  40. package/dist/http/config/config.module.d.ts.map +1 -0
  41. package/dist/http/config/config.module.js +32 -0
  42. package/dist/http/config/config.module.js.map +1 -0
  43. package/dist/http/discovery/agents.controller.d.ts +13 -0
  44. package/dist/http/discovery/agents.controller.d.ts.map +1 -0
  45. package/dist/http/discovery/agents.controller.js +73 -0
  46. package/dist/http/discovery/agents.controller.js.map +1 -0
  47. package/dist/http/discovery/discovery.module.d.ts +3 -0
  48. package/dist/http/discovery/discovery.module.d.ts.map +1 -0
  49. package/dist/http/discovery/discovery.module.js +22 -0
  50. package/dist/http/discovery/discovery.module.js.map +1 -0
  51. package/dist/http/dto/api.dto.d.ts +70 -0
  52. package/dist/http/dto/api.dto.d.ts.map +1 -0
  53. package/dist/http/dto/api.dto.js +268 -0
  54. package/dist/http/dto/api.dto.js.map +1 -0
  55. package/dist/http/events/events.controller.d.ts +8 -0
  56. package/dist/http/events/events.controller.d.ts.map +1 -0
  57. package/dist/http/events/events.controller.js +55 -0
  58. package/dist/http/events/events.controller.js.map +1 -0
  59. package/dist/http/events/events.module.d.ts +3 -0
  60. package/dist/http/events/events.module.d.ts.map +1 -0
  61. package/dist/http/events/events.module.js +25 -0
  62. package/dist/http/events/events.module.js.map +1 -0
  63. package/dist/http/events/events.service.d.ts +8 -0
  64. package/dist/http/events/events.service.d.ts.map +1 -0
  65. package/dist/http/events/events.service.js +37 -0
  66. package/dist/http/events/events.service.js.map +1 -0
  67. package/dist/http/health/health.controller.d.ts +6 -0
  68. package/dist/http/health/health.controller.d.ts.map +1 -0
  69. package/dist/http/health/health.controller.js +37 -0
  70. package/dist/http/health/health.controller.js.map +1 -0
  71. package/dist/http/health/health.module.d.ts +3 -0
  72. package/dist/http/health/health.module.d.ts.map +1 -0
  73. package/dist/http/health/health.module.js +20 -0
  74. package/dist/http/health/health.module.js.map +1 -0
  75. package/dist/http/http.module.d.ts +6 -0
  76. package/dist/http/http.module.d.ts.map +1 -0
  77. package/dist/http/http.module.js +43 -0
  78. package/dist/http/http.module.js.map +1 -0
  79. package/dist/http/messaging/messaging.controller.d.ts +9 -0
  80. package/dist/http/messaging/messaging.controller.d.ts.map +1 -0
  81. package/dist/http/messaging/messaging.controller.js +83 -0
  82. package/dist/http/messaging/messaging.controller.js.map +1 -0
  83. package/dist/http/messaging/messaging.module.d.ts +3 -0
  84. package/dist/http/messaging/messaging.module.d.ts.map +1 -0
  85. package/dist/http/messaging/messaging.module.js +25 -0
  86. package/dist/http/messaging/messaging.module.js.map +1 -0
  87. package/dist/http/messaging/messaging.service.d.ts +11 -0
  88. package/dist/http/messaging/messaging.service.d.ts.map +1 -0
  89. package/dist/http/messaging/messaging.service.js +48 -0
  90. package/dist/http/messaging/messaging.service.js.map +1 -0
  91. package/dist/http/providers/agent-loader.service.d.ts +49 -0
  92. package/dist/http/providers/agent-loader.service.d.ts.map +1 -0
  93. package/dist/http/providers/agent-loader.service.js +416 -0
  94. package/dist/http/providers/agent-loader.service.js.map +1 -0
  95. package/dist/http/providers/agent-manager.service.d.ts +24 -0
  96. package/dist/http/providers/agent-manager.service.d.ts.map +1 -0
  97. package/dist/http/providers/agent-manager.service.js +222 -0
  98. package/dist/http/providers/agent-manager.service.js.map +1 -0
  99. package/dist/http/providers/agent-scanner.service.d.ts +9 -0
  100. package/dist/http/providers/agent-scanner.service.d.ts.map +1 -0
  101. package/dist/http/providers/agent-scanner.service.js +108 -0
  102. package/dist/http/providers/agent-scanner.service.js.map +1 -0
  103. package/dist/http/providers/providers.module.d.ts +3 -0
  104. package/dist/http/providers/providers.module.d.ts.map +1 -0
  105. package/dist/http/providers/providers.module.js +47 -0
  106. package/dist/http/providers/providers.module.js.map +1 -0
  107. package/dist/http/reload/hot-reload.service.d.ts +16 -0
  108. package/dist/http/reload/hot-reload.service.d.ts.map +1 -0
  109. package/dist/http/reload/hot-reload.service.js +79 -0
  110. package/dist/http/reload/hot-reload.service.js.map +1 -0
  111. package/dist/http/reload/reload.controller.d.ts +14 -0
  112. package/dist/http/reload/reload.controller.d.ts.map +1 -0
  113. package/dist/http/reload/reload.controller.js +50 -0
  114. package/dist/http/reload/reload.controller.js.map +1 -0
  115. package/dist/http/reload/reload.module.d.ts +3 -0
  116. package/dist/http/reload/reload.module.d.ts.map +1 -0
  117. package/dist/http/reload/reload.module.js +23 -0
  118. package/dist/http/reload/reload.module.js.map +1 -0
  119. package/dist/http/runtime-config.d.ts +22 -0
  120. package/dist/http/runtime-config.d.ts.map +1 -0
  121. package/dist/http/runtime-config.js +5 -0
  122. package/dist/http/runtime-config.js.map +1 -0
  123. package/dist/http/sessions/sessions.controller.d.ts +11 -0
  124. package/dist/http/sessions/sessions.controller.d.ts.map +1 -0
  125. package/dist/http/sessions/sessions.controller.js +116 -0
  126. package/dist/http/sessions/sessions.controller.js.map +1 -0
  127. package/dist/http/sessions/sessions.module.d.ts +3 -0
  128. package/dist/http/sessions/sessions.module.d.ts.map +1 -0
  129. package/dist/http/sessions/sessions.module.js +25 -0
  130. package/dist/http/sessions/sessions.module.js.map +1 -0
  131. package/dist/http/sessions/sessions.service.d.ts +54 -0
  132. package/dist/http/sessions/sessions.service.d.ts.map +1 -0
  133. package/dist/http/sessions/sessions.service.js +353 -0
  134. package/dist/http/sessions/sessions.service.js.map +1 -0
  135. package/dist/http/state/state.controller.d.ts +9 -0
  136. package/dist/http/state/state.controller.d.ts.map +1 -0
  137. package/dist/http/state/state.controller.js +76 -0
  138. package/dist/http/state/state.controller.js.map +1 -0
  139. package/dist/http/state/state.module.d.ts +3 -0
  140. package/dist/http/state/state.module.d.ts.map +1 -0
  141. package/dist/http/state/state.module.js +25 -0
  142. package/dist/http/state/state.module.js.map +1 -0
  143. package/dist/http/state/state.service.d.ts +9 -0
  144. package/dist/http/state/state.service.d.ts.map +1 -0
  145. package/dist/http/state/state.service.js +55 -0
  146. package/dist/http/state/state.service.js.map +1 -0
  147. package/dist/main.d.ts +3 -0
  148. package/dist/main.d.ts.map +1 -0
  149. package/dist/main.js +25 -0
  150. package/dist/main.js.map +1 -0
  151. package/package.json +18 -12
  152. package/dist/index.d.mts +0 -2
  153. package/dist/index.d.ts +0 -2
  154. package/dist/index.js +0 -1187
  155. package/dist/index.js.map +0 -1
  156. package/dist/index.mjs +0 -1171
  157. package/dist/index.mjs.map +0 -1
package/dist/index.js DELETED
@@ -1,1187 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- "use strict";
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
- // If the importer is in node compatibility mode or this is not an ESM
20
- // file that has been converted to a CommonJS file using a Babel-
21
- // compatible transform (i.e. "__esModule" has not been set), then set
22
- // "default" to the CommonJS "module.exports" for node compatibility.
23
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
- mod
25
- ));
26
-
27
- // src/index.ts
28
- var import_chalk5 = __toESM(require("chalk"));
29
- var import_commander = require("commander");
30
-
31
- // package.json
32
- var package_default = {
33
- name: "@iqai/adk-cli",
34
- version: "0.2.8",
35
- description: "CLI tool for creating, running, and testing ADK agents",
36
- main: "dist/index.js",
37
- types: "dist/index.d.ts",
38
- bin: {
39
- adk: "./dist/index.mjs"
40
- },
41
- scripts: {
42
- build: "tsup",
43
- dev: "tsup --watch",
44
- test: "vitest run",
45
- "test:watch": "vitest"
46
- },
47
- repository: {
48
- type: "git",
49
- url: "https://github.com/IQAIcom/adk-ts.git",
50
- directory: "packages/adk-cli"
51
- },
52
- keywords: [
53
- "ai",
54
- "llm",
55
- "agent",
56
- "cli",
57
- "adk",
58
- "typescript"
59
- ],
60
- author: "IQAI",
61
- license: "MIT",
62
- dependencies: {
63
- "@clack/prompts": "^0.11.0",
64
- "@hono/node-server": "^1.18.1",
65
- "@iqai/adk": "workspace:*",
66
- chalk: "^5.4.1",
67
- commander: "^12.1.0",
68
- dedent: "^1.6.0",
69
- giget: "^2.0.0",
70
- hono: "^4.6.13",
71
- marked: "^14.1.3",
72
- "marked-terminal": "^7.2.1",
73
- esbuild: "^0.23.0"
74
- },
75
- devDependencies: {
76
- "@iqai/tsconfig": "workspace:*",
77
- "@types/marked-terminal": "^6.1.1",
78
- "@types/node": "^20.17.30",
79
- tsup: "^8.4.0",
80
- typescript: "^5.3.2",
81
- vitest: "^3.1.3"
82
- },
83
- packageManager: "pnpm@9.0.0",
84
- engines: {
85
- node: ">=22.0"
86
- },
87
- files: [
88
- "dist",
89
- "!**/*.test.*",
90
- "!**/*.json",
91
- "CHANGELOG.md",
92
- "LICENSE",
93
- "README.md"
94
- ],
95
- publishConfig: {
96
- access: "public"
97
- }
98
- };
99
-
100
- // src/commands/new.ts
101
- var import_node_fs = require("fs");
102
- var import_node_path = require("path");
103
- var import_prompts = require("@clack/prompts");
104
- var import_chalk = __toESM(require("chalk"));
105
- var import_dedent = __toESM(require("dedent"));
106
- var import_giget = require("giget");
107
- var templates = [
108
- {
109
- value: "simple-agent",
110
- label: "\u{1F916} Simple Agent",
111
- hint: "Basic agent with chat capabilities",
112
- source: "github:IQAIcom/adk-ts/apps/starter-templates/simple-agent"
113
- },
114
- {
115
- value: "discord-bot",
116
- label: "\u{1F3AE} Discord Bot",
117
- hint: "Agent integrated with Discord",
118
- source: "github:IQAIcom/adk-ts/apps/starter-templates/discord-bot"
119
- },
120
- {
121
- value: "telegram-bot",
122
- label: "\u{1F4F1} Telegram Bot",
123
- hint: "Agent integrated with Telegram",
124
- source: "github:IQAIcom/adk-ts/apps/starter-templates/telegram-bot"
125
- },
126
- {
127
- value: "hono-server",
128
- label: "\u{1F680} Hono Server",
129
- hint: "Web server with agent endpoints",
130
- source: "github:IQAIcom/adk-ts/apps/starter-templates/hono-server"
131
- },
132
- {
133
- value: "shade-agent",
134
- label: "\u{1F313} Near Shade Agent",
135
- hint: "Starter that uses Near Shade Agent",
136
- source: "github:IQAIcom/adk-ts/apps/starter-templates/shade-agent"
137
- },
138
- {
139
- value: "mcp-starter",
140
- label: "\u{1F50C} MCP Integration",
141
- hint: "Model Context Protocol server",
142
- source: "github:IQAIcom/adk-ts/apps/starter-templates/mcp-starter"
143
- }
144
- ];
145
- var packageManagers = [
146
- { name: "npm", command: "npm", args: ["install"], label: "\u{1F4E6} npm" },
147
- { name: "pnpm", command: "pnpm", args: ["install"], label: "\u26A1 pnpm" },
148
- { name: "yarn", command: "yarn", args: ["install"], label: "\u{1F9F6} yarn" },
149
- { name: "bun", command: "bun", args: ["install"], label: "\u{1F35E} bun" }
150
- ];
151
- async function detectAvailablePackageManagers() {
152
- const { spawn } = await import("child_process");
153
- const available = [];
154
- for (const pm of packageManagers) {
155
- try {
156
- await new Promise((resolve2, reject) => {
157
- const child = spawn(pm.command, ["--version"], {
158
- stdio: "pipe"
159
- });
160
- child.on("close", (code) => {
161
- if (code === 0) {
162
- available.push(pm);
163
- }
164
- resolve2();
165
- });
166
- child.on("error", () => resolve2());
167
- });
168
- } catch {
169
- }
170
- }
171
- return available.length > 0 ? available : [packageManagers[0]];
172
- }
173
- async function createProject(projectName, options) {
174
- console.clear();
175
- (0, import_prompts.intro)(import_chalk.default.magentaBright("\u{1F9E0} Create new ADK-TS project"));
176
- let finalProjectName = projectName;
177
- if (!finalProjectName) {
178
- const response = await (0, import_prompts.text)({
179
- message: "What is your project name?",
180
- placeholder: "my-adk-project",
181
- validate: (value) => {
182
- if (!value) return "Project name is required";
183
- if (value.includes(" ")) return "Project name cannot contain spaces";
184
- if ((0, import_node_fs.existsSync)(value)) return `Directory "${value}" already exists`;
185
- return void 0;
186
- }
187
- });
188
- if (typeof response === "symbol") {
189
- (0, import_prompts.outro)("Operation cancelled");
190
- process.exit(0);
191
- }
192
- finalProjectName = response;
193
- }
194
- let selectedTemplate = options?.template;
195
- if (!selectedTemplate || !templates.find((t) => t.value === selectedTemplate)) {
196
- const framework = await (0, import_prompts.select)({
197
- message: "Which template would you like to use?",
198
- options: templates.map((t) => ({
199
- value: t.value,
200
- label: t.label,
201
- hint: t.hint
202
- }))
203
- });
204
- if (typeof framework === "symbol") {
205
- (0, import_prompts.outro)("Operation cancelled");
206
- process.exit(0);
207
- }
208
- selectedTemplate = framework;
209
- }
210
- const template = templates.find((t) => t.value === selectedTemplate);
211
- if (!template) {
212
- (0, import_prompts.outro)("Invalid template selected");
213
- process.exit(1);
214
- }
215
- if ((0, import_node_fs.existsSync)(finalProjectName)) {
216
- (0, import_prompts.outro)(import_chalk.default.red(`Directory "${finalProjectName}" already exists`));
217
- process.exit(1);
218
- }
219
- const s = (0, import_prompts.spinner)();
220
- s.start("Downloading template...");
221
- try {
222
- await (0, import_giget.downloadTemplate)(template.source, {
223
- dir: finalProjectName,
224
- registry: "gh"
225
- });
226
- s.stop("Template downloaded!");
227
- } catch (error) {
228
- s.stop("Failed to download template");
229
- (0, import_prompts.outro)(import_chalk.default.red(`Error: ${error}`));
230
- process.exit(1);
231
- }
232
- const availablePackageManagers = await detectAvailablePackageManagers();
233
- let selectedPackageManager;
234
- if (availablePackageManagers.length === 1) {
235
- selectedPackageManager = availablePackageManagers[0];
236
- } else {
237
- const packageManagerChoice = await (0, import_prompts.select)({
238
- message: "Which package manager would you like to use?",
239
- options: availablePackageManagers.map((pm) => ({
240
- value: pm.name,
241
- label: pm.label
242
- }))
243
- });
244
- if (typeof packageManagerChoice === "symbol") {
245
- (0, import_prompts.outro)("Operation cancelled");
246
- process.exit(0);
247
- }
248
- selectedPackageManager = availablePackageManagers.find(
249
- (pm) => pm.name === packageManagerChoice
250
- );
251
- }
252
- const shouldInstall = await (0, import_prompts.confirm)({
253
- message: "Install dependencies?",
254
- initialValue: true
255
- });
256
- if (typeof shouldInstall === "symbol") {
257
- (0, import_prompts.outro)("Operation cancelled");
258
- process.exit(0);
259
- }
260
- if (shouldInstall) {
261
- const s2 = (0, import_prompts.spinner)();
262
- s2.start(`Installing dependencies with ${selectedPackageManager.name}...`);
263
- const { spawn } = await import("child_process");
264
- const projectPath = (0, import_node_path.join)(process.cwd(), finalProjectName);
265
- try {
266
- await new Promise((resolve2, reject) => {
267
- const child = spawn(
268
- selectedPackageManager.command,
269
- selectedPackageManager.args,
270
- {
271
- cwd: projectPath,
272
- stdio: "pipe"
273
- }
274
- );
275
- child.on("close", (code) => {
276
- if (code === 0) {
277
- resolve2();
278
- } else {
279
- reject(new Error(`Package installation failed with code ${code}`));
280
- }
281
- });
282
- child.on("error", reject);
283
- });
284
- s2.stop("Dependencies installed!");
285
- } catch (error) {
286
- s2.stop("Failed to install dependencies");
287
- console.log(
288
- import_chalk.default.yellow("\nYou can install dependencies manually by running:")
289
- );
290
- console.log(
291
- import_chalk.default.cyan(
292
- `cd ${finalProjectName} && ${selectedPackageManager.command} ${selectedPackageManager.args.join(" ")}`
293
- )
294
- );
295
- }
296
- }
297
- (0, import_prompts.outro)(
298
- import_chalk.default.green(import_dedent.default`
299
- 🎉 Project created successfully!
300
-
301
- Next steps:
302
- ${import_chalk.default.cyan(`cd ${finalProjectName}`)}
303
- ${shouldInstall ? "" : import_chalk.default.cyan(`${selectedPackageManager.command} ${selectedPackageManager.args.join(" ")}`)}
304
- ${import_chalk.default.cyan("npm run dev")} or ${import_chalk.default.cyan("yarn dev")} or ${import_chalk.default.cyan("pnpm dev")}
305
-
306
- Happy coding! 🚀
307
- `)
308
- );
309
- }
310
-
311
- // src/commands/run.ts
312
- var p = __toESM(require("@clack/prompts"));
313
- var import_prompts2 = require("@clack/prompts");
314
- var import_chalk3 = __toESM(require("chalk"));
315
- var import_marked = require("marked");
316
- var import_marked_terminal = require("marked-terminal");
317
-
318
- // src/commands/serve.ts
319
- var import_node_fs3 = require("fs");
320
- var import_node_path3 = require("path");
321
- var import_chalk2 = __toESM(require("chalk"));
322
-
323
- // src/server/index.ts
324
- var import_node_server = require("@hono/node-server");
325
- var import_adk2 = require("@iqai/adk");
326
- var import_hono = require("hono");
327
-
328
- // src/server/routes.ts
329
- var import_cors = require("hono/cors");
330
- function setupRoutes(app, agentManager, sessionManager, agentsDir) {
331
- app.use("/*", (0, import_cors.cors)());
332
- app.get("/health", (c) => c.json({ status: "ok" }));
333
- app.get("/api/agents", (c) => {
334
- const agentsList = Array.from(
335
- agentManager.getAgents().values()
336
- ).map((agent) => ({
337
- path: agent.absolutePath,
338
- name: agent.name,
339
- directory: agent.absolutePath,
340
- relativePath: agent.relativePath
341
- }));
342
- return c.json({ agents: agentsList });
343
- });
344
- app.post("/api/agents/refresh", (c) => {
345
- agentManager.scanAgents(agentsDir);
346
- const agentsList = Array.from(
347
- agentManager.getAgents().values()
348
- ).map((agent) => ({
349
- path: agent.absolutePath,
350
- name: agent.name,
351
- directory: agent.absolutePath,
352
- relativePath: agent.relativePath
353
- }));
354
- return c.json({ agents: agentsList });
355
- });
356
- app.get("/api/agents/:id/messages", async (c) => {
357
- const agentPath = decodeURIComponent(c.req.param("id"));
358
- const loadedAgent = agentManager.getLoadedAgents().get(agentPath);
359
- if (!loadedAgent) {
360
- return c.json({ messages: [] });
361
- }
362
- const messages = await sessionManager.getSessionMessages(loadedAgent);
363
- const response = { messages };
364
- return c.json(response);
365
- });
366
- app.post("/api/agents/:id/message", async (c) => {
367
- const agentPath = decodeURIComponent(c.req.param("id"));
368
- const { message, attachments } = await c.req.json();
369
- const response = await agentManager.sendMessageToAgent(
370
- agentPath,
371
- message,
372
- attachments
373
- );
374
- const messageResponse = { response };
375
- return c.json(messageResponse);
376
- });
377
- }
378
-
379
- // src/server/services.ts
380
- var import_node_fs2 = require("fs");
381
- var import_node_path2 = require("path");
382
- var import_node_url = require("url");
383
- var import_adk = require("@iqai/adk");
384
- var AgentScanner = class {
385
- constructor(quiet = false) {
386
- this.quiet = quiet;
387
- }
388
- scanAgents(agentsDir, loadedAgents) {
389
- const agents = /* @__PURE__ */ new Map();
390
- const scanDir = !agentsDir || !(0, import_node_fs2.existsSync)(agentsDir) ? process.cwd() : agentsDir;
391
- const shouldSkipDirectory = (dirName) => {
392
- const skipDirs = [
393
- "node_modules",
394
- ".git",
395
- ".next",
396
- "dist",
397
- "build",
398
- ".turbo",
399
- "coverage",
400
- ".vscode",
401
- ".idea"
402
- ];
403
- return skipDirs.includes(dirName);
404
- };
405
- const scanDirectory = (dir) => {
406
- if (!(0, import_node_fs2.existsSync)(dir)) return;
407
- const items = (0, import_node_fs2.readdirSync)(dir);
408
- for (const item of items) {
409
- const fullPath = (0, import_node_path2.join)(dir, item);
410
- const stat = (0, import_node_fs2.statSync)(fullPath);
411
- if (stat.isDirectory()) {
412
- if (!shouldSkipDirectory(item)) {
413
- scanDirectory(fullPath);
414
- }
415
- } else if (item === "agent.ts" || item === "agent.js") {
416
- const relativePath = (0, import_node_path2.relative)(scanDir, dir);
417
- const loadedAgent = loadedAgents.get(relativePath);
418
- let agentName = relativePath.split("/").pop() || "unknown";
419
- if (loadedAgent?.agent?.name) {
420
- agentName = loadedAgent.agent.name;
421
- } else {
422
- try {
423
- const agentFilePath = (0, import_node_path2.join)(dir, item);
424
- agentName = this.extractAgentNameFromFile(agentFilePath) || agentName;
425
- } catch {
426
- }
427
- }
428
- agents.set(relativePath, {
429
- relativePath,
430
- name: agentName,
431
- absolutePath: dir,
432
- instance: loadedAgent?.agent
433
- });
434
- }
435
- }
436
- };
437
- scanDirectory(scanDir);
438
- if (!this.quiet) {
439
- console.log(`\u2705 Agent scan complete. Found ${agents.size} agents.`);
440
- }
441
- return agents;
442
- }
443
- extractAgentNameFromFile(filePath) {
444
- try {
445
- const content = (0, import_node_fs2.readFileSync)(filePath, "utf-8");
446
- const nameMatch = content.match(/name\s*:\s*["']([^"']+)["']/);
447
- if (nameMatch?.[1]) {
448
- return nameMatch[1];
449
- }
450
- return null;
451
- } catch {
452
- return null;
453
- }
454
- }
455
- };
456
- var AgentLoader = class {
457
- constructor(quiet = false) {
458
- this.quiet = quiet;
459
- }
460
- /**
461
- * Import a TypeScript file by compiling it on-demand
462
- */
463
- async importTypeScriptFile(filePath) {
464
- const startDir = (0, import_node_path2.dirname)(filePath);
465
- let projectRoot = startDir;
466
- while (projectRoot !== "/" && projectRoot !== (0, import_node_path2.dirname)(projectRoot)) {
467
- if ((0, import_node_fs2.existsSync)((0, import_node_path2.join)(projectRoot, "package.json")) || (0, import_node_fs2.existsSync)((0, import_node_path2.join)(projectRoot, ".env"))) {
468
- break;
469
- }
470
- projectRoot = (0, import_node_path2.dirname)(projectRoot);
471
- }
472
- if (projectRoot === "/") {
473
- projectRoot = startDir;
474
- }
475
- try {
476
- const { build } = await import("esbuild");
477
- const cacheDir = (0, import_node_path2.join)(projectRoot, ".adk-cache");
478
- if (!(0, import_node_fs2.existsSync)(cacheDir)) {
479
- (0, import_node_fs2.mkdirSync)(cacheDir, { recursive: true });
480
- }
481
- const outFile = (0, import_node_path2.join)(cacheDir, `agent-${Date.now()}.mjs`);
482
- const plugin = {
483
- name: "externalize-bare-imports",
484
- setup(build2) {
485
- build2.onResolve({ filter: /.*/ }, (args) => {
486
- if (args.path.startsWith(".") || args.path.startsWith("/") || args.path.startsWith("..")) {
487
- return;
488
- }
489
- return { path: args.path, external: true };
490
- });
491
- }
492
- };
493
- const tsconfigPath = (0, import_node_path2.join)(projectRoot, "tsconfig.json");
494
- await build({
495
- entryPoints: [filePath],
496
- outfile: outFile,
497
- bundle: true,
498
- format: "esm",
499
- platform: "node",
500
- target: ["node22"],
501
- sourcemap: false,
502
- logLevel: "silent",
503
- plugins: [plugin],
504
- absWorkingDir: projectRoot,
505
- // Use tsconfig if present for path aliases
506
- ...(0, import_node_fs2.existsSync)(tsconfigPath) ? { tsconfig: tsconfigPath } : {}
507
- });
508
- const mod = await import(`${(0, import_node_url.pathToFileURL)(outFile).href}?t=${Date.now()}`);
509
- let agentExport = mod?.agent;
510
- if (!agentExport && mod?.default) {
511
- agentExport = mod.default.agent ?? mod.default;
512
- }
513
- try {
514
- (0, import_node_fs2.unlinkSync)(outFile);
515
- } catch {
516
- }
517
- if (agentExport) {
518
- const isPrimitive = (v) => v == null || ["string", "number", "boolean"].includes(typeof v);
519
- if (isPrimitive(agentExport)) {
520
- if (!this.quiet) {
521
- console.log(
522
- `\u2139\uFE0F Ignoring primitive 'agent' export in ${filePath}; scanning module for factory...`
523
- );
524
- }
525
- } else {
526
- if (!this.quiet) {
527
- console.log(`\u2705 TS agent imported via esbuild: ${filePath}`);
528
- }
529
- return { agent: agentExport };
530
- }
531
- }
532
- return mod;
533
- } catch (e) {
534
- throw new Error(
535
- `Failed to import TS agent via esbuild: ${e instanceof Error ? e.message : String(e)}`
536
- );
537
- }
538
- }
539
- loadEnvironmentVariables(agentFilePath) {
540
- let projectRoot = (0, import_node_path2.dirname)(agentFilePath);
541
- while (projectRoot !== "/" && projectRoot !== (0, import_node_path2.dirname)(projectRoot)) {
542
- if ((0, import_node_fs2.existsSync)((0, import_node_path2.join)(projectRoot, "package.json")) || (0, import_node_fs2.existsSync)((0, import_node_path2.join)(projectRoot, ".env"))) {
543
- break;
544
- }
545
- projectRoot = (0, import_node_path2.dirname)(projectRoot);
546
- }
547
- const envFiles = [
548
- ".env.local",
549
- ".env.development.local",
550
- ".env.production.local",
551
- ".env.development",
552
- ".env.production",
553
- ".env"
554
- ];
555
- for (const envFile of envFiles) {
556
- const envPath = (0, import_node_path2.join)(projectRoot, envFile);
557
- if ((0, import_node_fs2.existsSync)(envPath)) {
558
- try {
559
- const envContent = (0, import_node_fs2.readFileSync)(envPath, "utf8");
560
- const envLines = envContent.split("\n");
561
- for (const line of envLines) {
562
- const trimmedLine = line.trim();
563
- if (trimmedLine && !trimmedLine.startsWith("#")) {
564
- const [key, ...valueParts] = trimmedLine.split("=");
565
- if (key && valueParts.length > 0) {
566
- const value = valueParts.join("=").replace(/^"(.*)"$/, "$1");
567
- if (!process.env[key.trim()]) {
568
- process.env[key.trim()] = value.trim();
569
- }
570
- }
571
- }
572
- }
573
- } catch (error) {
574
- console.warn(
575
- `\u26A0\uFE0F Warning: Could not load ${envFile} file: ${error instanceof Error ? error.message : String(error)}`
576
- );
577
- }
578
- }
579
- }
580
- }
581
- // Minimal resolution logic for agent exports: supports
582
- // 1) export const agent = new LlmAgent(...)
583
- // 2) export function agent() { return new LlmAgent(...) }
584
- // 3) export async function agent() { return new LlmAgent(...) }
585
- // 4) default export (object or function) returning or containing .agent
586
- async resolveAgentExport(mod) {
587
- let candidate = mod?.agent ?? mod?.default?.agent ?? mod?.default ?? mod;
588
- const isLikelyAgentInstance = (obj) => obj && typeof obj === "object" && typeof obj.name === "string";
589
- const isPrimitive = (v) => v == null || ["string", "number", "boolean"].includes(typeof v);
590
- const invokeMaybe = async (fn) => {
591
- let out = fn();
592
- if (out && typeof out === "object" && "then" in out) {
593
- out = await out;
594
- }
595
- return out;
596
- };
597
- if (!isLikelyAgentInstance(candidate) && isPrimitive(candidate) || !isLikelyAgentInstance(candidate) && candidate && candidate === mod) {
598
- candidate = mod;
599
- for (const [key, value] of Object.entries(mod)) {
600
- if (key === "default") continue;
601
- const keyLower = key.toLowerCase();
602
- if (isPrimitive(value)) continue;
603
- if (isLikelyAgentInstance(value)) {
604
- candidate = value;
605
- break;
606
- }
607
- if (value && typeof value === "object" && value.agent && isLikelyAgentInstance(value.agent)) {
608
- candidate = value.agent;
609
- break;
610
- }
611
- if (typeof value === "function" && (/(agent|build|create)/i.test(keyLower) || value.name && /(agent|build|create)/i.test(value.name.toLowerCase()))) {
612
- try {
613
- const maybe = await invokeMaybe(value);
614
- if (isLikelyAgentInstance(maybe)) {
615
- candidate = maybe;
616
- break;
617
- }
618
- if (maybe && typeof maybe === "object" && maybe.agent && isLikelyAgentInstance(maybe.agent)) {
619
- candidate = maybe.agent;
620
- break;
621
- }
622
- } catch (e) {
623
- }
624
- }
625
- }
626
- }
627
- if (typeof candidate === "function") {
628
- try {
629
- candidate = await invokeMaybe(candidate);
630
- } catch (e) {
631
- throw new Error(
632
- `Failed executing exported agent function: ${e instanceof Error ? e.message : String(e)}`
633
- );
634
- }
635
- }
636
- if (candidate && typeof candidate === "object" && candidate.agent && isLikelyAgentInstance(candidate.agent)) {
637
- candidate = candidate.agent;
638
- }
639
- if (candidate?.agent && isLikelyAgentInstance(candidate.agent)) {
640
- candidate = candidate.agent;
641
- }
642
- if (!candidate || !isLikelyAgentInstance(candidate)) {
643
- throw new Error(
644
- "No agent export resolved (expected variable, function, or function returning an agent)"
645
- );
646
- }
647
- return { agent: candidate };
648
- }
649
- };
650
- var AgentManager = class {
651
- constructor(sessionService, quiet = false) {
652
- this.sessionService = sessionService;
653
- this.quiet = quiet;
654
- this.scanner = new AgentScanner(quiet);
655
- this.loader = new AgentLoader(quiet);
656
- }
657
- agents = /* @__PURE__ */ new Map();
658
- loadedAgents = /* @__PURE__ */ new Map();
659
- scanner;
660
- loader;
661
- getAgents() {
662
- return this.agents;
663
- }
664
- getLoadedAgents() {
665
- return this.loadedAgents;
666
- }
667
- scanAgents(agentsDir) {
668
- this.agents = this.scanner.scanAgents(agentsDir, this.loadedAgents);
669
- }
670
- async startAgent(agentPath) {
671
- const agent = this.agents.get(agentPath);
672
- if (!agent) {
673
- throw new Error(`Agent not found: ${agentPath}`);
674
- }
675
- if (this.loadedAgents.has(agentPath)) {
676
- return;
677
- }
678
- try {
679
- let agentFilePath = (0, import_node_path2.join)(agent.absolutePath, "agent.js");
680
- if (!(0, import_node_fs2.existsSync)(agentFilePath)) {
681
- agentFilePath = (0, import_node_path2.join)(agent.absolutePath, "agent.ts");
682
- }
683
- if (!(0, import_node_fs2.existsSync)(agentFilePath)) {
684
- throw new Error(
685
- `No agent.js or agent.ts file found in ${agent.absolutePath}`
686
- );
687
- }
688
- this.loader.loadEnvironmentVariables(agentFilePath);
689
- const agentFileUrl = (0, import_node_url.pathToFileURL)(agentFilePath).href;
690
- const agentModule = agentFilePath.endsWith(".ts") ? await this.loader.importTypeScriptFile(agentFilePath) : await import(agentFileUrl);
691
- const resolved = await this.loader.resolveAgentExport(agentModule);
692
- const exportedAgent = resolved.agent;
693
- if (!exportedAgent?.name) {
694
- throw new Error(
695
- `Invalid agent export in ${agentFilePath}. Expected an LlmAgent instance with a name property.`
696
- );
697
- }
698
- const agentBuilder = import_adk.AgentBuilder.create(exportedAgent.name).withAgent(exportedAgent).withSessionService(this.sessionService, {
699
- userId: `user_${agentPath}`,
700
- appName: "adk-server"
701
- });
702
- const { runner, session } = await agentBuilder.build();
703
- const loadedAgent = {
704
- agent: exportedAgent,
705
- runner,
706
- sessionId: session.id,
707
- userId: `user_${agentPath}`,
708
- appName: "adk-server"
709
- };
710
- this.loadedAgents.set(agentPath, loadedAgent);
711
- agent.instance = exportedAgent;
712
- agent.name = exportedAgent.name;
713
- } catch (error) {
714
- console.error(`\u274C Failed to load agent "${agent.name}":`, error);
715
- throw new Error(
716
- `Failed to load agent: ${error instanceof Error ? error.message : String(error)}`
717
- );
718
- }
719
- }
720
- async stopAgent(agentPath) {
721
- this.loadedAgents.delete(agentPath);
722
- const agent = this.agents.get(agentPath);
723
- if (agent) {
724
- agent.instance = void 0;
725
- }
726
- }
727
- async sendMessageToAgent(agentPath, message, attachments) {
728
- if (!this.loadedAgents.has(agentPath)) {
729
- await this.startAgent(agentPath);
730
- }
731
- const loadedAgent = this.loadedAgents.get(agentPath);
732
- if (!loadedAgent) {
733
- throw new Error("Agent failed to start");
734
- }
735
- try {
736
- if (attachments && attachments.length > 0) {
737
- const request = {
738
- parts: [
739
- { text: message },
740
- ...attachments.map((file) => ({
741
- inlineData: {
742
- mimeType: file.mimeType,
743
- data: file.data
744
- }
745
- }))
746
- ]
747
- };
748
- const response2 = await loadedAgent.runner.ask(request);
749
- return response2;
750
- }
751
- const response = await loadedAgent.runner.ask(message);
752
- return response;
753
- } catch (error) {
754
- const errorMessage = error instanceof Error ? error.message : String(error);
755
- console.error(
756
- `Error sending message to agent ${agentPath}:`,
757
- errorMessage
758
- );
759
- throw new Error(`Failed to send message to agent: ${errorMessage}`);
760
- }
761
- }
762
- stopAllAgents() {
763
- for (const [agentPath] of this.loadedAgents.entries()) {
764
- this.stopAgent(agentPath);
765
- }
766
- }
767
- };
768
- var SessionManager = class {
769
- constructor(sessionService) {
770
- this.sessionService = sessionService;
771
- }
772
- async getSessionMessages(loadedAgent) {
773
- try {
774
- const session = await this.sessionService.getSession(
775
- loadedAgent.appName,
776
- loadedAgent.userId,
777
- loadedAgent.sessionId
778
- );
779
- if (!session || !session.events) {
780
- return [];
781
- }
782
- const messages = session.events.map((event, index) => ({
783
- id: index + 1,
784
- type: event.author === "user" ? "user" : "assistant",
785
- content: event.content?.parts?.map(
786
- (part) => typeof part === "object" && "text" in part ? part.text : ""
787
- ).join("") || "",
788
- timestamp: new Date(event.timestamp || Date.now()).toISOString()
789
- }));
790
- return messages;
791
- } catch (error) {
792
- console.error("Error fetching messages:", error);
793
- return [];
794
- }
795
- }
796
- };
797
-
798
- // src/server/index.ts
799
- var ADKServer = class {
800
- agentManager;
801
- sessionManager;
802
- sessionService;
803
- app;
804
- server;
805
- config;
806
- constructor(agentsDir, port = 8042, host = "localhost", quiet = false) {
807
- this.config = { agentsDir, port, host, quiet };
808
- this.sessionService = new import_adk2.InMemorySessionService();
809
- this.agentManager = new AgentManager(this.sessionService, quiet);
810
- this.sessionManager = new SessionManager(this.sessionService);
811
- this.app = new import_hono.Hono();
812
- setupRoutes(this.app, this.agentManager, this.sessionManager, agentsDir);
813
- this.agentManager.scanAgents(agentsDir);
814
- }
815
- async start() {
816
- return new Promise((resolve2) => {
817
- this.server = (0, import_node_server.serve)({
818
- fetch: this.app.fetch,
819
- port: this.config.port,
820
- hostname: this.config.host
821
- });
822
- setTimeout(() => {
823
- resolve2();
824
- }, 100);
825
- });
826
- }
827
- async stop() {
828
- return new Promise((resolve2) => {
829
- this.agentManager.stopAllAgents();
830
- if (this.server) {
831
- this.server.close();
832
- }
833
- resolve2();
834
- });
835
- }
836
- getPort() {
837
- return this.config.port;
838
- }
839
- };
840
-
841
- // src/commands/serve.ts
842
- async function serveCommand(options = {}) {
843
- const port = options.port || 8042;
844
- const host = options.host || "localhost";
845
- const agentsDir = (0, import_node_path3.resolve)(options.dir || ".");
846
- if (!(0, import_node_fs3.existsSync)(agentsDir)) {
847
- console.error(import_chalk2.default.red(`\u274C Directory not found: ${agentsDir}`));
848
- process.exit(1);
849
- }
850
- if (!options.quiet) {
851
- console.log(import_chalk2.default.blue(`\u{1F680} ADK Server starting on http://${host}:${port}`));
852
- }
853
- const server = new ADKServer(agentsDir, port, host, options.quiet);
854
- try {
855
- await server.start();
856
- if (!options.quiet) {
857
- console.log(import_chalk2.default.green("\u2705 Server ready"));
858
- }
859
- const cleanup = async () => {
860
- if (!options.quiet) {
861
- console.log(import_chalk2.default.yellow("\n\u{1F6D1} Stopping server..."));
862
- }
863
- await server.stop();
864
- process.exit(0);
865
- };
866
- process.on("SIGINT", cleanup);
867
- process.on("SIGTERM", cleanup);
868
- return server;
869
- } catch (error) {
870
- console.error(import_chalk2.default.red("\u274C Failed to start ADK server:"), error);
871
- process.exit(1);
872
- }
873
- }
874
-
875
- // src/commands/run.ts
876
- import_marked.marked.use((0, import_marked_terminal.markedTerminal)());
877
- async function renderMarkdown(text3) {
878
- try {
879
- const result = await (0, import_marked.marked)(text3);
880
- return typeof result === "string" ? result : text3;
881
- } catch (error) {
882
- return text3;
883
- }
884
- }
885
- var AgentChatClient = class {
886
- apiUrl;
887
- selectedAgent = null;
888
- constructor(apiUrl) {
889
- this.apiUrl = apiUrl;
890
- }
891
- async connect() {
892
- try {
893
- const response = await fetch(`${this.apiUrl}/health`);
894
- if (!response.ok) {
895
- throw new Error("Connection failed");
896
- }
897
- } catch (error) {
898
- throw new Error("\u274C Connection failed");
899
- }
900
- }
901
- async fetchAgents() {
902
- try {
903
- const response = await fetch(`${this.apiUrl}/api/agents`);
904
- if (!response.ok) {
905
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
906
- }
907
- const data = await response.json();
908
- if (Array.isArray(data)) {
909
- return data;
910
- }
911
- if (data && Array.isArray(data.agents)) {
912
- return data.agents;
913
- }
914
- throw new Error(`Unexpected response format: ${JSON.stringify(data)}`);
915
- } catch (error) {
916
- throw new Error(
917
- `Failed to fetch agents: ${error instanceof Error ? error.message : String(error)}`
918
- );
919
- }
920
- }
921
- async selectAgent() {
922
- const agents = await this.fetchAgents();
923
- if (agents.length === 0) {
924
- throw new Error("No agents found in the current directory");
925
- }
926
- if (agents.length === 1) {
927
- return agents[0];
928
- }
929
- const selectedAgent = await p.select({
930
- message: "Choose an agent to chat with:",
931
- options: agents.map((agent) => ({
932
- label: agent.name,
933
- value: agent,
934
- hint: agent.relativePath
935
- }))
936
- });
937
- if (p.isCancel(selectedAgent)) {
938
- p.cancel("Operation cancelled");
939
- process.exit(0);
940
- }
941
- return selectedAgent;
942
- }
943
- // No-op: agents are auto-loaded on message; keeping method removed
944
- async sendMessage(message) {
945
- if (!this.selectedAgent) {
946
- throw new Error("No agent selected");
947
- }
948
- const s = (0, import_prompts2.spinner)();
949
- s.start("\u{1F916} Thinking...");
950
- try {
951
- const response = await fetch(
952
- `${this.apiUrl}/api/agents/${encodeURIComponent(this.selectedAgent.relativePath)}/message`,
953
- {
954
- method: "POST",
955
- headers: {
956
- "Content-Type": "application/json"
957
- },
958
- body: JSON.stringify({ message })
959
- }
960
- );
961
- if (!response.ok) {
962
- const errorText = await response.text();
963
- s.stop("\u274C Failed to send message");
964
- throw new Error(`Failed to send message: ${errorText}`);
965
- }
966
- const result = await response.json();
967
- s.stop("\u{1F916} Assistant:");
968
- if (result.response) {
969
- const formattedResponse = await renderMarkdown(result.response);
970
- import_prompts2.log.message(formattedResponse.trim());
971
- }
972
- } catch (error) {
973
- import_prompts2.log.error("Failed to send message");
974
- }
975
- }
976
- async startChat() {
977
- if (!this.selectedAgent) {
978
- throw new Error("Agent not selected");
979
- }
980
- while (true) {
981
- try {
982
- const message = await p.text({
983
- message: "\u{1F4AC} Message:",
984
- placeholder: "Type your message here..."
985
- });
986
- if (p.isCancel(message)) {
987
- break;
988
- }
989
- if (message.trim()) {
990
- await this.sendMessage(message.trim());
991
- }
992
- } catch (error) {
993
- console.error(import_chalk3.default.red("Error in chat:"), error);
994
- break;
995
- }
996
- }
997
- }
998
- disconnect() {
999
- }
1000
- setSelectedAgent(agent) {
1001
- this.selectedAgent = agent;
1002
- }
1003
- };
1004
- async function runAgent(agentPath, options = {}) {
1005
- const envVerbose = process.env.ADK_VERBOSE;
1006
- const isVerbose = options.verbose ?? (envVerbose === "1" || envVerbose === "true");
1007
- if (options.server) {
1008
- const apiPort = 8042;
1009
- const host = options.host || "localhost";
1010
- console.log(import_chalk3.default.blue("\u{1F680} Starting ADK Server..."));
1011
- const serveOptions = {
1012
- port: apiPort,
1013
- dir: process.cwd(),
1014
- host,
1015
- quiet: !isVerbose
1016
- };
1017
- try {
1018
- const server = await serveCommand(serveOptions);
1019
- console.log(import_chalk3.default.cyan("Press Ctrl+C to stop the server"));
1020
- process.on("SIGINT", async () => {
1021
- console.log(import_chalk3.default.yellow("\n\u{1F6D1} Stopping server..."));
1022
- await server.stop();
1023
- process.exit(0);
1024
- });
1025
- return new Promise(() => {
1026
- });
1027
- } catch (error) {
1028
- console.error(import_chalk3.default.red("\u274C Failed to start server"));
1029
- process.exit(1);
1030
- }
1031
- }
1032
- const apiUrl = `http://${options.host || "localhost"}:8042`;
1033
- p.intro("\u{1F916} ADK Agent Chat");
1034
- try {
1035
- const healthResponse = await fetch(`${apiUrl}/health`).catch(() => null);
1036
- if (!healthResponse || !healthResponse.ok) {
1037
- const serverSpinner = (0, import_prompts2.spinner)();
1038
- serverSpinner.start("\u{1F680} Starting server...");
1039
- const serveOptions = {
1040
- port: 8042,
1041
- // Use new default port
1042
- dir: process.cwd(),
1043
- host: options.host || "localhost",
1044
- quiet: !isVerbose
1045
- };
1046
- await serveCommand(serveOptions);
1047
- await new Promise((resolve2) => setTimeout(resolve2, 1e3));
1048
- serverSpinner.stop("\u2705 Server ready");
1049
- }
1050
- const client = new AgentChatClient(apiUrl);
1051
- await client.connect();
1052
- const agentSpinner = (0, import_prompts2.spinner)();
1053
- agentSpinner.start("\u{1F50D} Scanning for agents...");
1054
- const agents = await client.fetchAgents();
1055
- let selectedAgent;
1056
- if (agents.length === 0) {
1057
- agentSpinner.stop("\u274C No agents found");
1058
- p.cancel("No agents found in the current directory");
1059
- process.exit(1);
1060
- } else if (agents.length === 1) {
1061
- selectedAgent = agents[0];
1062
- agentSpinner.stop(`\u{1F916} Found agent: ${selectedAgent.name}`);
1063
- } else {
1064
- agentSpinner.stop(`\u{1F916} Found ${agents.length} agents`);
1065
- const choice = await p.select({
1066
- message: "Choose an agent to chat with:",
1067
- options: agents.map((agent) => ({
1068
- label: agent.name,
1069
- value: agent,
1070
- hint: agent.relativePath
1071
- }))
1072
- });
1073
- if (p.isCancel(choice)) {
1074
- p.cancel("Operation cancelled");
1075
- process.exit(0);
1076
- }
1077
- selectedAgent = choice;
1078
- }
1079
- client.setSelectedAgent(selectedAgent);
1080
- await client.startChat();
1081
- client.disconnect();
1082
- p.outro("Chat ended");
1083
- } catch (error) {
1084
- p.cancel(
1085
- `Error: ${error instanceof Error ? error.message : String(error)}`
1086
- );
1087
- process.exit(1);
1088
- }
1089
- }
1090
-
1091
- // src/commands/web.ts
1092
- var import_chalk4 = __toESM(require("chalk"));
1093
- async function webCommand(options = {}) {
1094
- const apiPort = options.port || 8042;
1095
- const webPort = options.webPort || 3e3;
1096
- const host = options.host || "localhost";
1097
- const useLocal = options.local || false;
1098
- const webUrl = options.webUrl || "https://adk-web.iqai.com";
1099
- console.log(import_chalk4.default.blue("\u{1F310} Starting ADK Web Interface..."));
1100
- const serveOptions = {
1101
- port: apiPort,
1102
- dir: options.dir,
1103
- host,
1104
- quiet: true
1105
- };
1106
- await serveCommand(serveOptions);
1107
- let webAppUrl;
1108
- if (useLocal) {
1109
- if (apiPort === 8042) {
1110
- webAppUrl = `http://${host}:${webPort}`;
1111
- } else {
1112
- webAppUrl = `http://${host}:${webPort}?port=${apiPort}`;
1113
- }
1114
- } else {
1115
- if (apiPort === 8042) {
1116
- webAppUrl = webUrl;
1117
- } else {
1118
- webAppUrl = `${webUrl}?port=${apiPort}`;
1119
- }
1120
- }
1121
- console.log(import_chalk4.default.cyan(`\u{1F517} Open this URL in your browser: ${webAppUrl}`));
1122
- console.log(import_chalk4.default.gray(` API Server: http://${host}:${apiPort}`));
1123
- console.log(import_chalk4.default.cyan("Press Ctrl+C to stop the API server"));
1124
- }
1125
-
1126
- // src/index.ts
1127
- import_commander.program.name("adk").description(package_default.description).version(package_default.version);
1128
- import_commander.program.command("new").description("Create a new ADK project").argument("[project-name]", "Name of the project to create").option(
1129
- "-t, --template <template>",
1130
- "Template to use (simple-agent, discord-bot, telegram-bot, hono-server, mcp-starter)"
1131
- ).action(async (projectName, options) => {
1132
- try {
1133
- await createProject(projectName, options);
1134
- } catch (error) {
1135
- console.error(import_chalk5.default.red("Error creating project:"), error);
1136
- process.exit(1);
1137
- }
1138
- });
1139
- import_commander.program.command("run").description("Start an interactive chat with an agent").argument(
1140
- "[agent-path]",
1141
- "Path to specific agent (optional - will show selector if multiple agents found)"
1142
- ).option("-s, --server", "Start ADK server only (without chat interface)").option(
1143
- "-h, --host <host>",
1144
- "Host for server (when using --server)",
1145
- "localhost"
1146
- ).action(async (agentPath, options) => {
1147
- try {
1148
- await runAgent(agentPath, options);
1149
- } catch (error) {
1150
- console.error(import_chalk5.default.red("Error running agent:"), error);
1151
- process.exit(1);
1152
- }
1153
- });
1154
- import_commander.program.command("web").description("Start a web interface for testing agents").option("-p, --port <port>", "Port for API server", "8042").option("--web-port <port>", "Port for web app (when using --local)", "3000").option("-h, --host <host>", "Host for servers", "localhost").option(
1155
- "-d, --dir <directory>",
1156
- "Directory to scan for agents (default: current directory)",
1157
- "."
1158
- ).option(
1159
- "--local",
1160
- "Run local web app instead of opening production URL",
1161
- false
1162
- ).option(
1163
- "--web-url <url>",
1164
- "URL of the web application (used when not --local)",
1165
- "https://adk-web.iqai.com"
1166
- ).action(async (options) => {
1167
- try {
1168
- await webCommand(options);
1169
- } catch (error) {
1170
- console.error(import_chalk5.default.red("Error starting web UI:"), error);
1171
- process.exit(1);
1172
- }
1173
- });
1174
- import_commander.program.command("serve").description("Start an API server for agent management").option("-p, --port <port>", "Port for the server", "8042").option("-h, --host <host>", "Host for the server", "localhost").option(
1175
- "-d, --dir <directory>",
1176
- "Directory to scan for agents (default: current directory)",
1177
- "."
1178
- ).action(async (options) => {
1179
- try {
1180
- await serveCommand(options);
1181
- } catch (error) {
1182
- console.error(import_chalk5.default.red("Error starting server:"), error);
1183
- process.exit(1);
1184
- }
1185
- });
1186
- import_commander.program.parse();
1187
- //# sourceMappingURL=index.js.map