@tpmjs/cli 0.1.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 (97) hide show
  1. package/README.md +127 -0
  2. package/bin/run.js +5 -0
  3. package/dist/commands/agent/chat.d.ts +23 -0
  4. package/dist/commands/agent/chat.js +608 -0
  5. package/dist/commands/agent/chat.js.map +1 -0
  6. package/dist/commands/agent/create.d.ts +22 -0
  7. package/dist/commands/agent/create.js +549 -0
  8. package/dist/commands/agent/create.js.map +1 -0
  9. package/dist/commands/agent/delete.d.ts +19 -0
  10. package/dist/commands/agent/delete.js +529 -0
  11. package/dist/commands/agent/delete.js.map +1 -0
  12. package/dist/commands/agent/list.d.ts +16 -0
  13. package/dist/commands/agent/list.js +535 -0
  14. package/dist/commands/agent/list.js.map +1 -0
  15. package/dist/commands/agent/update.d.ts +25 -0
  16. package/dist/commands/agent/update.js +547 -0
  17. package/dist/commands/agent/update.js.map +1 -0
  18. package/dist/commands/auth/login.d.ts +21 -0
  19. package/dist/commands/auth/login.js +603 -0
  20. package/dist/commands/auth/login.js.map +1 -0
  21. package/dist/commands/auth/logout.d.ts +13 -0
  22. package/dist/commands/auth/logout.js +227 -0
  23. package/dist/commands/auth/logout.js.map +1 -0
  24. package/dist/commands/auth/status.d.ts +14 -0
  25. package/dist/commands/auth/status.js +542 -0
  26. package/dist/commands/auth/status.js.map +1 -0
  27. package/dist/commands/auth/whoami.d.ts +14 -0
  28. package/dist/commands/auth/whoami.js +500 -0
  29. package/dist/commands/auth/whoami.js.map +1 -0
  30. package/dist/commands/collection/add.d.ts +18 -0
  31. package/dist/commands/collection/add.js +509 -0
  32. package/dist/commands/collection/add.js.map +1 -0
  33. package/dist/commands/collection/create.d.ts +17 -0
  34. package/dist/commands/collection/create.js +521 -0
  35. package/dist/commands/collection/create.js.map +1 -0
  36. package/dist/commands/collection/delete.d.ts +19 -0
  37. package/dist/commands/collection/delete.js +531 -0
  38. package/dist/commands/collection/delete.js.map +1 -0
  39. package/dist/commands/collection/import.d.ts +18 -0
  40. package/dist/commands/collection/import.js +546 -0
  41. package/dist/commands/collection/import.js.map +1 -0
  42. package/dist/commands/collection/list.d.ts +16 -0
  43. package/dist/commands/collection/list.js +531 -0
  44. package/dist/commands/collection/list.js.map +1 -0
  45. package/dist/commands/collection/remove.d.ts +18 -0
  46. package/dist/commands/collection/remove.js +501 -0
  47. package/dist/commands/collection/remove.js.map +1 -0
  48. package/dist/commands/collection/update.d.ts +20 -0
  49. package/dist/commands/collection/update.js +522 -0
  50. package/dist/commands/collection/update.js.map +1 -0
  51. package/dist/commands/doctor.d.ts +14 -0
  52. package/dist/commands/doctor.js +592 -0
  53. package/dist/commands/doctor.js.map +1 -0
  54. package/dist/commands/mcp/config.d.ts +19 -0
  55. package/dist/commands/mcp/config.js +265 -0
  56. package/dist/commands/mcp/config.js.map +1 -0
  57. package/dist/commands/mcp/serve.d.ts +23 -0
  58. package/dist/commands/mcp/serve.js +689 -0
  59. package/dist/commands/mcp/serve.js.map +1 -0
  60. package/dist/commands/playground.d.ts +23 -0
  61. package/dist/commands/playground.js +666 -0
  62. package/dist/commands/playground.js.map +1 -0
  63. package/dist/commands/publish/check.d.ts +17 -0
  64. package/dist/commands/publish/check.js +544 -0
  65. package/dist/commands/publish/check.js.map +1 -0
  66. package/dist/commands/publish/preview.d.ts +19 -0
  67. package/dist/commands/publish/preview.js +291 -0
  68. package/dist/commands/publish/preview.js.map +1 -0
  69. package/dist/commands/tool/execute.d.ts +21 -0
  70. package/dist/commands/tool/execute.js +574 -0
  71. package/dist/commands/tool/execute.js.map +1 -0
  72. package/dist/commands/tool/info.d.ts +18 -0
  73. package/dist/commands/tool/info.js +537 -0
  74. package/dist/commands/tool/info.js.map +1 -0
  75. package/dist/commands/tool/init.d.ts +24 -0
  76. package/dist/commands/tool/init.js +461 -0
  77. package/dist/commands/tool/init.js.map +1 -0
  78. package/dist/commands/tool/search.d.ts +20 -0
  79. package/dist/commands/tool/search.js +566 -0
  80. package/dist/commands/tool/search.js.map +1 -0
  81. package/dist/commands/tool/trending.d.ts +15 -0
  82. package/dist/commands/tool/trending.js +523 -0
  83. package/dist/commands/tool/trending.js.map +1 -0
  84. package/dist/commands/tool/validate.d.ts +15 -0
  85. package/dist/commands/tool/validate.js +555 -0
  86. package/dist/commands/tool/validate.js.map +1 -0
  87. package/dist/commands/update.d.ts +15 -0
  88. package/dist/commands/update.js +228 -0
  89. package/dist/commands/update.js.map +1 -0
  90. package/dist/hooks/init.d.ts +5 -0
  91. package/dist/hooks/init.js +8 -0
  92. package/dist/hooks/init.js.map +1 -0
  93. package/dist/index.d.ts +262 -0
  94. package/dist/index.js +473 -0
  95. package/dist/index.js.map +1 -0
  96. package/oclif.manifest.json +1699 -0
  97. package/package.json +104 -0
@@ -0,0 +1,666 @@
1
+ import { Command, Flags } from '@oclif/core';
2
+ import * as readline from 'readline';
3
+ import Conf from 'conf';
4
+ import * as fs from 'fs';
5
+ import * as os from 'os';
6
+ import * as path from 'path';
7
+ import Table from 'cli-table3';
8
+ import ora from 'ora';
9
+ import pc from 'picocolors';
10
+
11
+ // src/commands/playground.ts
12
+ var CONFIG_DIR = path.join(os.homedir(), ".tpmjs");
13
+ var CREDENTIALS_FILE = path.join(CONFIG_DIR, "credentials.json");
14
+ path.join(CONFIG_DIR, "history");
15
+ function ensureConfigDir() {
16
+ if (!fs.existsSync(CONFIG_DIR)) {
17
+ fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 448 });
18
+ }
19
+ }
20
+ var configStore = new Conf({
21
+ projectName: "tpmjs",
22
+ cwd: CONFIG_DIR,
23
+ configName: "config",
24
+ defaults: {
25
+ apiUrl: "https://tpmjs.com/api",
26
+ defaultOutput: "human",
27
+ verbose: false,
28
+ analytics: false
29
+ }
30
+ });
31
+ function getConfigValue(key) {
32
+ return configStore.get(key);
33
+ }
34
+ function loadCredentials() {
35
+ ensureConfigDir();
36
+ if (!fs.existsSync(CREDENTIALS_FILE)) {
37
+ return null;
38
+ }
39
+ try {
40
+ const content = fs.readFileSync(CREDENTIALS_FILE, "utf-8");
41
+ return JSON.parse(content);
42
+ } catch {
43
+ return null;
44
+ }
45
+ }
46
+ function getApiKey() {
47
+ if (process.env.TPMJS_API_KEY) {
48
+ return process.env.TPMJS_API_KEY;
49
+ }
50
+ const creds = loadCredentials();
51
+ if (creds?.apiKey) {
52
+ return creds.apiKey;
53
+ }
54
+ return void 0;
55
+ }
56
+ function getApiUrl() {
57
+ return process.env.TPMJS_API_URL ?? getConfigValue("apiUrl") ?? "https://tpmjs.com/api";
58
+ }
59
+
60
+ // src/lib/api-client.ts
61
+ var TpmClient = class {
62
+ baseUrl;
63
+ apiKey;
64
+ timeout;
65
+ constructor(options = {}) {
66
+ this.baseUrl = options.baseUrl ?? getApiUrl();
67
+ this.apiKey = options.apiKey ?? getApiKey();
68
+ this.timeout = options.timeout ?? 3e4;
69
+ }
70
+ async request(endpoint, options = {}) {
71
+ const url = `${this.baseUrl}${endpoint}`;
72
+ const headers = {
73
+ "Content-Type": "application/json",
74
+ ...options.headers
75
+ };
76
+ if (this.apiKey) {
77
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
78
+ }
79
+ const controller = new AbortController();
80
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
81
+ try {
82
+ const response = await fetch(url, {
83
+ ...options,
84
+ headers,
85
+ signal: controller.signal
86
+ });
87
+ const data = await response.json();
88
+ if (!response.ok) {
89
+ throw new ApiError(
90
+ data.message || data.error || `HTTP ${response.status}`,
91
+ response.status,
92
+ data
93
+ );
94
+ }
95
+ return data;
96
+ } finally {
97
+ clearTimeout(timeoutId);
98
+ }
99
+ }
100
+ // Health check
101
+ async health() {
102
+ return this.request("/health");
103
+ }
104
+ // Stats
105
+ async getStats() {
106
+ return this.request("/stats");
107
+ }
108
+ // Tools
109
+ async searchTools(options = {}) {
110
+ const params = new URLSearchParams();
111
+ if (options.query) params.set("q", options.query);
112
+ if (options.category) params.set("category", options.category);
113
+ if (options.limit) params.set("limit", String(options.limit));
114
+ if (options.offset) params.set("offset", String(options.offset));
115
+ const queryString = params.toString();
116
+ const endpoint = queryString ? `/tools?${queryString}` : "/tools";
117
+ return this.request(endpoint);
118
+ }
119
+ async getTool(packageName, toolName) {
120
+ return this.request(`/tools/${encodeURIComponent(packageName)}/${encodeURIComponent(toolName)}`);
121
+ }
122
+ async getToolBySlug(slug) {
123
+ const searchResult = await this.searchTools({ query: slug, limit: 1 });
124
+ if (searchResult.data && searchResult.data.length > 0) {
125
+ const tool = searchResult.data.find((t) => t.slug === slug) || searchResult.data[0];
126
+ return { success: true, data: tool };
127
+ }
128
+ return { success: false, error: "Tool not found" };
129
+ }
130
+ async getTrendingTools(options = {}) {
131
+ const params = new URLSearchParams();
132
+ if (options.limit) params.set("limit", String(options.limit));
133
+ if (options.offset) params.set("offset", String(options.offset));
134
+ const queryString = params.toString();
135
+ const endpoint = queryString ? `/tools/trending?${queryString}` : "/tools/trending";
136
+ return this.request(endpoint);
137
+ }
138
+ async validateTpmjsField(field) {
139
+ return this.request("/tools/validate", {
140
+ method: "POST",
141
+ body: JSON.stringify(field)
142
+ });
143
+ }
144
+ async executeTool(slug, params) {
145
+ return this.request(`/tools/${encodeURIComponent(slug)}/execute`, {
146
+ method: "POST",
147
+ body: JSON.stringify(params)
148
+ });
149
+ }
150
+ async *executeToolStream(slug, params) {
151
+ const url = `${this.baseUrl}/tools/${encodeURIComponent(slug)}/execute`;
152
+ const headers = {
153
+ "Content-Type": "application/json",
154
+ "Accept": "text/event-stream"
155
+ };
156
+ if (this.apiKey) {
157
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
158
+ }
159
+ const response = await fetch(url, {
160
+ method: "POST",
161
+ headers,
162
+ body: JSON.stringify({ ...params, stream: true })
163
+ });
164
+ if (!response.ok) {
165
+ const errorText = await response.text();
166
+ throw new ApiError(errorText || `HTTP ${response.status}`, response.status);
167
+ }
168
+ if (!response.body) {
169
+ throw new ApiError("No response body", 0);
170
+ }
171
+ const reader = response.body.getReader();
172
+ const decoder = new TextDecoder();
173
+ let buffer = "";
174
+ try {
175
+ while (true) {
176
+ const { done, value } = await reader.read();
177
+ if (done) {
178
+ yield { type: "done", data: "" };
179
+ break;
180
+ }
181
+ buffer += decoder.decode(value, { stream: true });
182
+ const lines = buffer.split("\n");
183
+ buffer = lines.pop() ?? "";
184
+ for (const line of lines) {
185
+ if (line.startsWith("data: ")) {
186
+ const data = line.slice(6);
187
+ if (data === "[DONE]") {
188
+ yield { type: "done", data: "" };
189
+ return;
190
+ }
191
+ try {
192
+ const parsed = JSON.parse(data);
193
+ yield { type: parsed.type || "text", data: parsed.content || parsed.data || data };
194
+ } catch {
195
+ yield { type: "text", data };
196
+ }
197
+ }
198
+ }
199
+ }
200
+ } finally {
201
+ reader.releaseLock();
202
+ }
203
+ }
204
+ // Agents
205
+ async listAgents(options = {}) {
206
+ const params = new URLSearchParams();
207
+ if (options.limit) params.set("limit", String(options.limit));
208
+ if (options.offset) params.set("offset", String(options.offset));
209
+ const queryString = params.toString();
210
+ const endpoint = queryString ? `/agents?${queryString}` : "/agents";
211
+ return this.request(endpoint);
212
+ }
213
+ async getAgent(id) {
214
+ return this.request(`/agents/${id}`);
215
+ }
216
+ async createAgent(input) {
217
+ return this.request("/agents", {
218
+ method: "POST",
219
+ body: JSON.stringify(input)
220
+ });
221
+ }
222
+ async updateAgent(id, input) {
223
+ return this.request(`/agents/${id}`, {
224
+ method: "PATCH",
225
+ body: JSON.stringify(input)
226
+ });
227
+ }
228
+ async deleteAgent(id) {
229
+ return this.request(`/agents/${id}`, {
230
+ method: "DELETE"
231
+ });
232
+ }
233
+ // Collections
234
+ async listCollections(options = {}) {
235
+ const params = new URLSearchParams();
236
+ if (options.limit) params.set("limit", String(options.limit));
237
+ if (options.offset) params.set("offset", String(options.offset));
238
+ const queryString = params.toString();
239
+ const endpoint = queryString ? `/collections?${queryString}` : "/collections";
240
+ return this.request(endpoint);
241
+ }
242
+ async getCollection(id) {
243
+ return this.request(`/collections/${id}`);
244
+ }
245
+ async createCollection(input) {
246
+ return this.request("/collections", {
247
+ method: "POST",
248
+ body: JSON.stringify(input)
249
+ });
250
+ }
251
+ async updateCollection(id, input) {
252
+ return this.request(`/collections/${id}`, {
253
+ method: "PATCH",
254
+ body: JSON.stringify(input)
255
+ });
256
+ }
257
+ async deleteCollection(id) {
258
+ return this.request(`/collections/${id}`, {
259
+ method: "DELETE"
260
+ });
261
+ }
262
+ async addToolsToCollection(id, toolIds) {
263
+ for (const toolId of toolIds) {
264
+ await this.request(`/collections/${id}/tools/${toolId}`, {
265
+ method: "POST"
266
+ });
267
+ }
268
+ return { success: true };
269
+ }
270
+ async removeToolFromCollection(id, toolId) {
271
+ return this.request(`/collections/${id}/tools/${toolId}`, {
272
+ method: "DELETE"
273
+ });
274
+ }
275
+ // User
276
+ async whoami() {
277
+ return this.request("/user/profile");
278
+ }
279
+ async listApiKeys() {
280
+ return this.request("/user/tpmjs-api-keys");
281
+ }
282
+ // Check if authenticated
283
+ isAuthenticated() {
284
+ return !!this.apiKey;
285
+ }
286
+ };
287
+ var ApiError = class extends Error {
288
+ constructor(message, statusCode, data) {
289
+ super(message);
290
+ this.statusCode = statusCode;
291
+ this.data = data;
292
+ this.name = "ApiError";
293
+ }
294
+ };
295
+ var clientInstance = null;
296
+ function getClient(options) {
297
+ if (!clientInstance || options) {
298
+ clientInstance = new TpmClient(options);
299
+ }
300
+ return clientInstance;
301
+ }
302
+ var OutputFormatter = class {
303
+ options;
304
+ constructor(options = {}) {
305
+ this.options = options;
306
+ }
307
+ // Output as JSON
308
+ json(data) {
309
+ console.log(JSON.stringify(data, null, 2));
310
+ }
311
+ // Output a table
312
+ table(data, columns) {
313
+ if (this.options.json) {
314
+ this.json(data);
315
+ return;
316
+ }
317
+ const table = new Table({
318
+ head: columns.map((col) => pc.bold(col.header)),
319
+ colWidths: columns.map((col) => col.width ?? null),
320
+ style: {
321
+ head: [],
322
+ border: []
323
+ }
324
+ });
325
+ for (const row of data) {
326
+ table.push(columns.map((col) => String(row[col.key] ?? "")));
327
+ }
328
+ console.log(table.toString());
329
+ }
330
+ // Success message
331
+ success(message) {
332
+ if (this.options.json) return;
333
+ console.log(pc.green("\u2713"), message);
334
+ }
335
+ // Error message
336
+ error(message, details) {
337
+ if (this.options.json) {
338
+ this.json({ error: message, details });
339
+ return;
340
+ }
341
+ console.error(pc.red("\u2717"), message);
342
+ if (details && this.options.verbose) {
343
+ console.error(pc.dim(details));
344
+ }
345
+ }
346
+ // Warning message
347
+ warning(message) {
348
+ if (this.options.json) return;
349
+ console.log(pc.yellow("\u26A0"), message);
350
+ }
351
+ // Info message
352
+ info(message) {
353
+ if (this.options.json) return;
354
+ console.log(pc.blue("\u2139"), message);
355
+ }
356
+ // Debug message (only in verbose mode)
357
+ debug(message) {
358
+ if (this.options.json) return;
359
+ if (this.options.verbose) {
360
+ console.log(pc.dim(`[debug] ${message}`));
361
+ }
362
+ }
363
+ // Plain text output
364
+ text(message) {
365
+ if (this.options.json) return;
366
+ console.log(message);
367
+ }
368
+ // Heading
369
+ heading(text) {
370
+ if (this.options.json) return;
371
+ console.log();
372
+ console.log(pc.bold(pc.underline(text)));
373
+ console.log();
374
+ }
375
+ // Subheading
376
+ subheading(text) {
377
+ if (this.options.json) return;
378
+ console.log(pc.bold(text));
379
+ }
380
+ // Key-value pair
381
+ keyValue(key, value) {
382
+ if (this.options.json) return;
383
+ console.log(`${pc.dim(key + ":")} ${value ?? pc.dim("(not set)")}`);
384
+ }
385
+ // List item
386
+ listItem(text, indent = 0) {
387
+ if (this.options.json) return;
388
+ const prefix = " ".repeat(indent) + "\u2022";
389
+ console.log(`${prefix} ${text}`);
390
+ }
391
+ // Spinner
392
+ spinner(message) {
393
+ return ora({
394
+ text: message,
395
+ isSilent: this.options.json
396
+ }).start();
397
+ }
398
+ // Blank line
399
+ newLine() {
400
+ if (this.options.json) return;
401
+ console.log();
402
+ }
403
+ // Horizontal rule
404
+ hr() {
405
+ if (this.options.json) return;
406
+ console.log(pc.dim("\u2500".repeat(50)));
407
+ }
408
+ // Alias for hr
409
+ divider() {
410
+ this.hr();
411
+ }
412
+ // Code block
413
+ code(text, language) {
414
+ if (this.options.json) {
415
+ this.json({ code: text, language });
416
+ return;
417
+ }
418
+ console.log(pc.dim("```" + (language ?? "")));
419
+ console.log(text);
420
+ console.log(pc.dim("```"));
421
+ }
422
+ // Highlight text
423
+ highlight(text) {
424
+ return pc.cyan(text);
425
+ }
426
+ // Dim text
427
+ dim(text) {
428
+ return pc.dim(text);
429
+ }
430
+ // Bold text
431
+ bold(text) {
432
+ return pc.bold(text);
433
+ }
434
+ // Link (just returns text in terminal)
435
+ link(text, url) {
436
+ return `\x1B]8;;${url}\x07${pc.underline(pc.blue(text))}\x1B]8;;\x07`;
437
+ }
438
+ };
439
+ function createOutput(flags) {
440
+ return new OutputFormatter({
441
+ json: flags.json,
442
+ verbose: flags.verbose
443
+ });
444
+ }
445
+
446
+ // src/commands/playground.ts
447
+ var Playground = class _Playground extends Command {
448
+ static description = "Interactive playground for testing tools";
449
+ static examples = [
450
+ "<%= config.bin %> <%= command.id %>",
451
+ "<%= config.bin %> <%= command.id %> --tool firecrawl-scrape",
452
+ "<%= config.bin %> <%= command.id %> --web"
453
+ ];
454
+ static flags = {
455
+ tool: Flags.string({
456
+ char: "t",
457
+ description: "Start with a specific tool selected"
458
+ }),
459
+ web: Flags.boolean({
460
+ char: "w",
461
+ description: "Open the web playground instead",
462
+ default: false
463
+ }),
464
+ verbose: Flags.boolean({
465
+ char: "v",
466
+ description: "Show verbose output",
467
+ default: false
468
+ })
469
+ };
470
+ rl;
471
+ client = getClient();
472
+ selectedTool;
473
+ async run() {
474
+ const { flags } = await this.parse(_Playground);
475
+ const output = createOutput(flags);
476
+ if (flags.web) {
477
+ output.info("Opening web playground...");
478
+ const open = (await import('open')).default;
479
+ await open("https://tpmjs.com/playground");
480
+ return;
481
+ }
482
+ this.selectedTool = flags.tool;
483
+ this.rl = readline.createInterface({
484
+ input: process.stdin,
485
+ output: process.stdout
486
+ });
487
+ output.heading("TPMJS Playground");
488
+ output.text("");
489
+ output.text("Commands:");
490
+ output.listItem(".help - Show this help");
491
+ output.listItem(".tools - List available tools");
492
+ output.listItem(".select - Select a tool to use");
493
+ output.listItem(".info - Show info about selected tool");
494
+ output.listItem(".clear - Clear the screen");
495
+ output.listItem(".exit - Exit the playground");
496
+ output.text("");
497
+ if (this.selectedTool) {
498
+ output.info(`Selected tool: ${this.selectedTool}`);
499
+ } else {
500
+ output.text("No tool selected. Use .select to choose a tool.");
501
+ }
502
+ output.text("");
503
+ output.text("Enter JSON input to execute the selected tool.");
504
+ output.divider();
505
+ await this.repl(output, flags.verbose);
506
+ }
507
+ async repl(output, verbose) {
508
+ const prompt = () => {
509
+ const prefix = this.selectedTool ? `[${this.selectedTool}]` : "[no tool]";
510
+ this.rl?.question(`${prefix} > `, async (input) => {
511
+ const trimmed = input.trim();
512
+ if (!trimmed) {
513
+ prompt();
514
+ return;
515
+ }
516
+ if (trimmed.startsWith(".")) {
517
+ await this.handleCommand(trimmed, output, verbose);
518
+ if (trimmed !== ".exit") {
519
+ prompt();
520
+ }
521
+ return;
522
+ }
523
+ if (!this.selectedTool) {
524
+ output.warning("No tool selected. Use .select to choose a tool first.");
525
+ prompt();
526
+ return;
527
+ }
528
+ try {
529
+ const params = JSON.parse(trimmed);
530
+ await this.executeTool(params, output, verbose);
531
+ } catch {
532
+ output.error("Invalid JSON input. Enter valid JSON or use a command (.help)");
533
+ }
534
+ prompt();
535
+ });
536
+ };
537
+ prompt();
538
+ await new Promise((resolve) => {
539
+ this.rl?.on("close", resolve);
540
+ });
541
+ }
542
+ async handleCommand(command, output, verbose) {
543
+ const [cmd, ...args] = command.split(/\s+/);
544
+ switch (cmd) {
545
+ case ".help":
546
+ output.text("");
547
+ output.text("Commands:");
548
+ output.listItem(".help - Show this help");
549
+ output.listItem(".tools - List available tools");
550
+ output.listItem(".select <tool> - Select a tool to use");
551
+ output.listItem(".info - Show info about selected tool");
552
+ output.listItem(".clear - Clear the screen");
553
+ output.listItem(".exit - Exit the playground");
554
+ output.text("");
555
+ output.text("To execute a tool, enter JSON input:");
556
+ output.text(' {"url": "https://example.com"}');
557
+ output.text("");
558
+ break;
559
+ case ".tools":
560
+ await this.listTools(output);
561
+ break;
562
+ case ".select":
563
+ if (args.length === 0) {
564
+ output.warning("Usage: .select <tool-slug>");
565
+ } else {
566
+ this.selectedTool = args[0];
567
+ output.success(`Selected: ${this.selectedTool}`);
568
+ }
569
+ break;
570
+ case ".info":
571
+ await this.showToolInfo(output, verbose);
572
+ break;
573
+ case ".clear":
574
+ console.clear();
575
+ break;
576
+ case ".exit":
577
+ output.info("Goodbye!");
578
+ this.rl?.close();
579
+ break;
580
+ default:
581
+ output.warning(`Unknown command: ${cmd}. Type .help for available commands.`);
582
+ }
583
+ }
584
+ async listTools(output) {
585
+ const spinner = output.spinner("Loading tools...");
586
+ try {
587
+ const response = await this.client.getTrendingTools({ limit: 20 });
588
+ spinner.stop();
589
+ if (!response.data || response.data.length === 0) {
590
+ output.error("No tools found");
591
+ return;
592
+ }
593
+ output.text("");
594
+ output.text("Available tools:");
595
+ for (const tool of response.data) {
596
+ output.listItem(`${tool.slug} - ${tool.name}`);
597
+ }
598
+ output.text("");
599
+ output.text("Use .select <slug> to select a tool");
600
+ } catch {
601
+ spinner.fail("Failed to load tools");
602
+ }
603
+ }
604
+ async showToolInfo(output, verbose) {
605
+ if (!this.selectedTool) {
606
+ output.warning("No tool selected");
607
+ return;
608
+ }
609
+ const spinner = output.spinner("Loading tool info...");
610
+ try {
611
+ const response = await this.client.getToolBySlug(this.selectedTool);
612
+ spinner.stop();
613
+ if (!response.success || !response.data) {
614
+ output.error("Tool not found");
615
+ return;
616
+ }
617
+ const tool = response.data;
618
+ output.text("");
619
+ output.heading(tool.name);
620
+ output.text(`Slug: ${tool.slug}`);
621
+ output.text(`Category: ${tool.category}`);
622
+ output.text(`Version: ${tool.npmVersion}`);
623
+ output.text("");
624
+ output.text("Description:");
625
+ output.text(` ${tool.description || "(none)"}`);
626
+ if (tool.inputSchema) {
627
+ output.text("");
628
+ output.text("Input Schema:");
629
+ output.text(JSON.stringify(tool.inputSchema, null, 2));
630
+ }
631
+ if (verbose && tool.tools && tool.tools.length > 0) {
632
+ output.text("");
633
+ output.text("Available operations:");
634
+ for (const t of tool.tools) {
635
+ output.listItem(`${t.name}: ${t.description || ""}`);
636
+ }
637
+ }
638
+ output.text("");
639
+ } catch {
640
+ spinner.fail("Failed to load tool info");
641
+ }
642
+ }
643
+ async executeTool(params, output, verbose) {
644
+ if (!this.selectedTool) {
645
+ output.warning("No tool selected");
646
+ return;
647
+ }
648
+ const spinner = output.spinner("Executing...");
649
+ try {
650
+ const result = await this.client.executeTool(this.selectedTool, params);
651
+ spinner.stop();
652
+ output.success("Result:");
653
+ output.text(JSON.stringify(result, null, 2));
654
+ } catch (error) {
655
+ spinner.fail("Execution failed");
656
+ output.error(
657
+ error instanceof Error ? error.message : "Unknown error",
658
+ verbose ? String(error) : void 0
659
+ );
660
+ }
661
+ }
662
+ };
663
+
664
+ export { Playground as default };
665
+ //# sourceMappingURL=playground.js.map
666
+ //# sourceMappingURL=playground.js.map