@inkeep/agents-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 (75) hide show
  1. package/LICENSE.md +51 -0
  2. package/README.md +512 -0
  3. package/dist/__tests__/api.test.d.ts +1 -0
  4. package/dist/__tests__/api.test.js +257 -0
  5. package/dist/__tests__/cli.test.d.ts +1 -0
  6. package/dist/__tests__/cli.test.js +153 -0
  7. package/dist/__tests__/commands/config.test.d.ts +1 -0
  8. package/dist/__tests__/commands/config.test.js +154 -0
  9. package/dist/__tests__/commands/init.test.d.ts +1 -0
  10. package/dist/__tests__/commands/init.test.js +186 -0
  11. package/dist/__tests__/commands/pull-retry.test.d.ts +1 -0
  12. package/dist/__tests__/commands/pull-retry.test.js +156 -0
  13. package/dist/__tests__/commands/pull.test.d.ts +1 -0
  14. package/dist/__tests__/commands/pull.test.js +54 -0
  15. package/dist/__tests__/commands/push-spinner.test.d.ts +1 -0
  16. package/dist/__tests__/commands/push-spinner.test.js +127 -0
  17. package/dist/__tests__/commands/push.test.d.ts +1 -0
  18. package/dist/__tests__/commands/push.test.js +265 -0
  19. package/dist/__tests__/config-validation.test.d.ts +1 -0
  20. package/dist/__tests__/config-validation.test.js +106 -0
  21. package/dist/__tests__/package.test.d.ts +1 -0
  22. package/dist/__tests__/package.test.js +82 -0
  23. package/dist/__tests__/utils/json-comparator.test.d.ts +1 -0
  24. package/dist/__tests__/utils/json-comparator.test.js +174 -0
  25. package/dist/__tests__/utils/port-manager.test.d.ts +1 -0
  26. package/dist/__tests__/utils/port-manager.test.js +144 -0
  27. package/dist/__tests__/utils/ts-loader.test.d.ts +1 -0
  28. package/dist/__tests__/utils/ts-loader.test.js +233 -0
  29. package/dist/api.d.ts +23 -0
  30. package/dist/api.js +140 -0
  31. package/dist/commands/chat-enhanced.d.ts +7 -0
  32. package/dist/commands/chat-enhanced.js +396 -0
  33. package/dist/commands/chat.d.ts +5 -0
  34. package/dist/commands/chat.js +125 -0
  35. package/dist/commands/config.d.ts +6 -0
  36. package/dist/commands/config.js +128 -0
  37. package/dist/commands/init.d.ts +5 -0
  38. package/dist/commands/init.js +171 -0
  39. package/dist/commands/list-graphs.d.ts +6 -0
  40. package/dist/commands/list-graphs.js +131 -0
  41. package/dist/commands/mcp-list.d.ts +4 -0
  42. package/dist/commands/mcp-list.js +156 -0
  43. package/dist/commands/mcp-start-simple.d.ts +5 -0
  44. package/dist/commands/mcp-start-simple.js +193 -0
  45. package/dist/commands/mcp-start.d.ts +5 -0
  46. package/dist/commands/mcp-start.js +217 -0
  47. package/dist/commands/mcp-status.d.ts +1 -0
  48. package/dist/commands/mcp-status.js +96 -0
  49. package/dist/commands/mcp-stop.d.ts +5 -0
  50. package/dist/commands/mcp-stop.js +160 -0
  51. package/dist/commands/pull.d.ts +15 -0
  52. package/dist/commands/pull.js +313 -0
  53. package/dist/commands/pull.llm-generate.d.ts +10 -0
  54. package/dist/commands/pull.llm-generate.js +184 -0
  55. package/dist/commands/push.d.ts +6 -0
  56. package/dist/commands/push.js +268 -0
  57. package/dist/config.d.ts +43 -0
  58. package/dist/config.js +292 -0
  59. package/dist/exports.d.ts +2 -0
  60. package/dist/exports.js +2 -0
  61. package/dist/index.d.ts +2 -0
  62. package/dist/index.js +98 -0
  63. package/dist/types/config.d.ts +9 -0
  64. package/dist/types/config.js +3 -0
  65. package/dist/types/graph.d.ts +10 -0
  66. package/dist/types/graph.js +1 -0
  67. package/dist/utils/json-comparator.d.ts +60 -0
  68. package/dist/utils/json-comparator.js +222 -0
  69. package/dist/utils/mcp-runner.d.ts +6 -0
  70. package/dist/utils/mcp-runner.js +147 -0
  71. package/dist/utils/port-manager.d.ts +43 -0
  72. package/dist/utils/port-manager.js +92 -0
  73. package/dist/utils/ts-loader.d.ts +5 -0
  74. package/dist/utils/ts-loader.js +146 -0
  75. package/package.json +77 -0
package/LICENSE.md ADDED
@@ -0,0 +1,51 @@
1
+ <!--
2
+ AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
3
+ Source: ./LICENSE.md
4
+ This file is automatically copied from the root LICENSE.md during build.
5
+ Any changes should be made to the root LICENSE.md file.
6
+ -->
7
+
8
+ Elastic License
9
+ Acceptance
10
+ By using the software, you agree to all of the terms and conditions below.
11
+
12
+ Copyright License
13
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below.
14
+
15
+ Limitations
16
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
17
+
18
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
19
+
20
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
21
+
22
+ Patents
23
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
24
+
25
+ Notices
26
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
27
+
28
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
29
+
30
+ No Other Rights
31
+ These terms do not imply any licenses other than those expressly granted in these terms.
32
+
33
+ Termination
34
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
35
+
36
+ No Liability
37
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
38
+
39
+ Definitions
40
+ The licensor is the entity offering these terms, and the software is the software the licensor makes available under these terms, including any portion of it.
41
+
42
+ you refers to the individual or entity agreeing to these terms.
43
+
44
+ your company is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. control means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
45
+
46
+ your licenses are all the licenses granted to you for the software under these terms.
47
+
48
+ use means anything you do with the software requiring one of your licenses.
49
+
50
+ trademark means trademarks, service marks, and similar rights.
51
+
package/README.md ADDED
@@ -0,0 +1,512 @@
1
+ # Inkeep CLI
2
+
3
+ A command-line interface for managing and interacting with Inkeep Agent Framework graphs.
4
+
5
+ ## Installation & Setup
6
+
7
+ ### Prerequisites
8
+
9
+ - Node.js >= 20.x
10
+ - pnpm package manager
11
+ - Inkeep Agent Framework backend running (default: http://localhost:3002)
12
+
13
+ ### Quick Start
14
+
15
+ > **📖 For detailed setup instructions, see [SETUP.md](./SETUP.md)**
16
+
17
+ 1. **Install and build**
18
+ ```bash
19
+ # Navigate to the CLI directory
20
+ cd /path/to/agent-framework/agents-cli
21
+
22
+ # Install dependencies
23
+ pnpm install
24
+
25
+ # Build the CLI
26
+ pnpm build
27
+ ```
28
+
29
+ 2. **Install globally** (recommended)
30
+
31
+ **Option A: Using npm link (for development)**
32
+ ```bash
33
+ # Create global symlink from the agents-cli directory
34
+ npm link
35
+
36
+ # Verify installation
37
+ which inkeep # Should show path to inkeep command
38
+ ```
39
+
40
+ **Option B: Using pnpm/npm global install (after publishing)**
41
+ ```bash
42
+ # Install the scoped package globally
43
+ pnpm add -g @inkeep/agents-cli
44
+ # or
45
+ npm install -g @inkeep/agents-cli
46
+
47
+ # Verify installation
48
+ inkeep --version
49
+ ```
50
+
51
+ **Note:**
52
+ - For local development, use `npm link` (more reliable than `pnpm link --global`)
53
+ - The command is still `inkeep` even though the package name is `@inkeep/agents-cli`
54
+ - If linking fails, try unlinking first: `npm unlink -g @inkeep/agents-cli`
55
+
56
+ 3. **Configure tenant**
57
+ ```bash
58
+ # Set your tenant ID (required for most commands)
59
+ inkeep tenant your-tenant-id
60
+
61
+ # Verify configuration
62
+ inkeep tenant
63
+ ```
64
+
65
+ ## Configuration
66
+
67
+ ### Configuration Sources (priority order)
68
+
69
+ 1. **Command-line flags** - Highest priority (e.g., `--tenant-id`, `--api-url`)
70
+ 2. **Environment variables** - `INKEEP_TENANT_ID`, `INKEEP_API_URL`
71
+ 3. **`.env` file** - In current directory
72
+ 4. **Config file** - `inkeep.config.ts` or `.inkeeprc.ts/js`
73
+ 5. **Defaults** - Lowest priority (api-url defaults to `http://localhost:3002`)
74
+
75
+ ### Environment Variables
76
+
77
+ Create a `.env` file in your project directory:
78
+
79
+ ```bash
80
+ INKEEP_TENANT_ID=your-tenant-id
81
+ INKEEP_API_URL=http://localhost:3002
82
+ ```
83
+
84
+ Or export them in your shell:
85
+
86
+ ```bash
87
+ export INKEEP_TENANT_ID=your-tenant-id
88
+ export INKEEP_API_URL=http://localhost:3002
89
+ ```
90
+
91
+ ## Commands
92
+
93
+ ### `inkeep tenant [tenant-id]`
94
+
95
+ Manage tenant configuration.
96
+
97
+ ```bash
98
+ # Set tenant ID
99
+ inkeep tenant my-tenant
100
+
101
+ # View current tenant ID
102
+ inkeep tenant
103
+ ```
104
+
105
+ ### `inkeep list-graphs`
106
+
107
+ List all available graphs for the current tenant.
108
+
109
+ ```bash
110
+ inkeep list-graphs
111
+
112
+ # With custom API URL
113
+ inkeep list-graphs --url http://api.example.com:3002
114
+ ```
115
+
116
+ Output:
117
+ ```
118
+ ┌─────────────────────────┬────────────────────┬───────────────┬───────────┐
119
+ │ Graph ID │ Name │ Default Agent │ Created │
120
+ ├─────────────────────────┼────────────────────┼───────────────┼───────────┤
121
+ │ customer-support-graph │ Customer Support │ router │ 1/15/2025 │
122
+ │ qa-assistant │ QA Assistant │ qa-agent │ 1/14/2025 │
123
+ └─────────────────────────┴────────────────────┴───────────────┴───────────┘
124
+ ```
125
+
126
+ ### `inkeep push <config-path>`
127
+
128
+ Push a graph configuration to the backend.
129
+
130
+ ```bash
131
+ # Push a graph configuration
132
+ inkeep push ./my-graph.js
133
+
134
+ # With custom API URL
135
+ inkeep push ./graph.ts --url http://api.example.com:3002
136
+ ```
137
+
138
+ **Features:**
139
+ - Automatically injects tenant ID and API URL from `inkeep.config.ts`
140
+ - Validates exactly one AgentGraph is exported
141
+ - Warns about dangling resources (unreferenced agents/tools)
142
+ - Shows graph summary after successful push
143
+ - Handles graph initialization automatically
144
+
145
+ **Graph naming convention:** Graph files should follow the `*.graph.ts` naming pattern (e.g., `customer-support.graph.ts`, `qa-assistant.graph.ts`)
146
+
147
+ **Example graph configuration:**
148
+
149
+ ```javascript
150
+ // customer-support.graph.ts
151
+ import { agent, agentGraph, tool } from '@inkeep/agents-manage-api/builder';
152
+
153
+ const assistantAgent = agent({
154
+ id: 'assistant',
155
+ name: 'Assistant',
156
+ instructions: 'Help users with their questions',
157
+ tools: {
158
+ search: searchTool
159
+ }
160
+ // No tenantId needed - injected by CLI
161
+ });
162
+
163
+ // Must export exactly one graph
164
+ export const graph = agentGraph({
165
+ id: 'my-assistant',
166
+ name: 'My Assistant Graph',
167
+ defaultAgent: assistantAgent,
168
+ agents: {
169
+ assistant: assistantAgent
170
+ }
171
+ // No tenantId or apiUrl needed - CLI injects from config
172
+ });
173
+ // No graph.init() call - CLI handles initialization
174
+ ```
175
+
176
+ ### `inkeep chat [graph-id]`
177
+
178
+ Start an interactive chat session with a graph.
179
+
180
+ ```bash
181
+ # Chat with specific graph
182
+ inkeep chat my-graph-id
183
+
184
+ # Interactive graph selection (with search)
185
+ inkeep chat
186
+
187
+ # With custom API URL
188
+ inkeep chat --url http://api.example.com:3002
189
+ ```
190
+
191
+ **Interactive Features:**
192
+ - **Graph selection**: If no graph ID provided, shows searchable list
193
+ - **Chat commands**:
194
+ - `help` - Show available commands
195
+ - `clear` - Clear screen (preserves context)
196
+ - `history` - Show conversation history
197
+ - `reset` - Reset conversation context
198
+ - `exit` - End chat session
199
+
200
+ ### `inkeep mcp start <graph-file>`
201
+
202
+ Start MCP (Model Context Protocol) servers defined in a graph file.
203
+
204
+ ```bash
205
+ # Start MCP servers from a TypeScript graph file
206
+ inkeep mcp start examples/agent-configurations/graph.graph.ts
207
+
208
+ # Start from compiled JavaScript
209
+ inkeep mcp start dist/examples/agent-configurations/graph.graph.js
210
+
211
+ # Run in detached mode
212
+ inkeep mcp start graph.graph.ts --detached
213
+
214
+ # Show verbose output
215
+ inkeep mcp start graph.graph.ts --verbose
216
+ ```
217
+
218
+ **Features:**
219
+ - Supports both TypeScript (`.ts`) and JavaScript (`.js`) files
220
+ - Automatically allocates ports for local servers (3100-3200)
221
+ - Shows server names, ports, and URLs
222
+ - Distinguishes between local (🏠) and remote (☁️) servers
223
+
224
+ ### `inkeep mcp stop`
225
+
226
+ Stop running MCP servers.
227
+
228
+ ```bash
229
+ # Stop all servers
230
+ inkeep mcp stop --all
231
+
232
+ # Stop servers for a specific graph
233
+ inkeep mcp stop --graph customer-support-graph
234
+ ```
235
+
236
+ ### `inkeep mcp status`
237
+
238
+ Show status of all MCP servers.
239
+
240
+ ```bash
241
+ inkeep mcp status
242
+ ```
243
+
244
+ Output shows:
245
+ - Process ID
246
+ - Graph ID
247
+ - Tool name
248
+ - Port/URL
249
+ - Running status
250
+ - Uptime
251
+
252
+ ### `inkeep mcp list`
253
+
254
+ List all MCP servers with detailed information.
255
+
256
+ ```bash
257
+ # Default tree view
258
+ inkeep mcp list
259
+
260
+ # Table format
261
+ inkeep mcp list --format table
262
+
263
+ # Verbose output (includes descriptions)
264
+ inkeep mcp list --verbose
265
+ ```
266
+
267
+
268
+
269
+ ## Complete Workflow Example
270
+
271
+ ### Basic Setup
272
+ ```bash
273
+ # Install and link CLI
274
+ cd agents-cli
275
+ pnpm install
276
+ pnpm build
277
+ npm link
278
+
279
+ # Configure tenant
280
+ inkeep tenant test-tenant
281
+ ```
282
+
283
+ ### Working with Graphs and MCP Servers
284
+
285
+ 1. **Create a graph with MCP tools** (`my-graph.graph.ts`)
286
+ ```typescript
287
+ import { agent, agentGraph, mcpServer } from '@inkeep/agents-manage-api/builder';
288
+
289
+ // Define MCP servers (tools)
290
+ const randomNumberServer = mcpServer({
291
+ name: 'random_number',
292
+ description: 'Generates a random number',
293
+ execute: async () => Math.random()
294
+ });
295
+
296
+ const weatherServer = mcpServer({
297
+ name: 'weather_api',
298
+ description: 'Get weather information',
299
+ serverUrl: 'https://api.weather.example.com/mcp'
300
+ });
301
+
302
+ // Define agents
303
+ const assistantAgent = agent({
304
+ id: 'assistant',
305
+ name: 'Assistant',
306
+ instructions: 'Help users with various tasks',
307
+ tools: {
308
+ random: randomNumberServer,
309
+ weather: weatherServer
310
+ }
311
+ });
312
+
313
+ // Export the graph
314
+ export const graph = agentGraph({
315
+ id: 'my-assistant',
316
+ name: 'My Assistant',
317
+ defaultAgent: assistantAgent,
318
+ agents: { assistant: assistantAgent }
319
+ });
320
+
321
+ // Export servers for MCP management
322
+ export const servers = [randomNumberServer, weatherServer];
323
+ ```
324
+
325
+ 2. **Start MCP servers and chat**
326
+ ```bash
327
+ # Start MCP servers (works with TypeScript directly!)
328
+ inkeep mcp start my-graph.graph.ts
329
+
330
+ # In another terminal, start chatting
331
+ inkeep chat my-assistant
332
+
333
+ # Try commands like:
334
+ # > "Generate a random number"
335
+ # > "What's the weather like?"
336
+ ```
337
+
338
+ 3. **Monitor and manage servers**
339
+ ```bash
340
+ # Check server status
341
+ inkeep mcp status
342
+
343
+ # List all servers with details
344
+ inkeep mcp list
345
+
346
+ # Stop servers when done
347
+ inkeep mcp stop --all
348
+ ```
349
+
350
+ ## Working with Different Environments
351
+
352
+ ### Development
353
+ ```bash
354
+ # Using environment variable
355
+ INKEEP_API_URL=http://localhost:3002 inkeep list-graphs
356
+
357
+ # Using .env file
358
+ echo "INKEEP_API_URL=http://localhost:3002" > .env
359
+ inkeep chat my-graph
360
+ ```
361
+
362
+ ### Staging
363
+ ```bash
364
+ # Using command flag
365
+ inkeep push graph.js --url https://staging-api.example.com
366
+
367
+ # Set in config file
368
+ # Edit your inkeep.config.ts to set apiUrl: 'https://staging-api.example.com'
369
+ ```
370
+
371
+ ### Production
372
+ ```bash
373
+ # Using environment variables
374
+ export INKEEP_API_URL=https://api.example.com
375
+ export INKEEP_TENANT_ID=prod-tenant
376
+ inkeep list-graphs
377
+ ```
378
+
379
+ ## Development
380
+
381
+ ### Running from Source
382
+
383
+ ```bash
384
+ # Without building (using tsx)
385
+ pnpm tsx src/index.ts <command>
386
+
387
+ # After building
388
+ node dist/index.js <command>
389
+
390
+ # Watch mode (auto-rebuild on changes)
391
+ pnpm dev
392
+ ```
393
+
394
+ ### Testing
395
+
396
+ ```bash
397
+ # Run tests
398
+ pnpm test
399
+
400
+ # Watch mode
401
+ pnpm test:watch
402
+
403
+ # Coverage report
404
+ pnpm test:coverage
405
+ ```
406
+
407
+ ### Type Checking
408
+
409
+ ```bash
410
+ pnpm typecheck
411
+ ```
412
+
413
+ ### Project Structure
414
+
415
+ ```
416
+ agents-cli/
417
+ ├── src/
418
+ │ ├── index.ts # Main CLI entry point
419
+ │ ├── config.ts # Configuration management
420
+ │ ├── api.ts # API client for backend
421
+ │ ├── commands/ # Command implementations
422
+ │ │ ├── push.ts # Push graph configurations
423
+ │ │ ├── chat.ts # Basic chat interface
424
+ │ │ ├── chat-enhanced.ts # Enhanced chat with autocomplete
425
+ │ │ ├── tenant.ts # Tenant management
426
+ │ │ └── list-graphs.ts # List graphs
427
+ │ ├── types/ # TypeScript declarations
428
+ │ └── __tests__/ # Test files
429
+ ├── dist/ # Compiled JavaScript
430
+ ├── package.json
431
+ ├── tsconfig.json
432
+ └── README.md
433
+ ```
434
+
435
+ ## Troubleshooting
436
+
437
+ ### Common Issues
438
+
439
+ **"No tenant ID configured"**
440
+ ```bash
441
+ # Set tenant ID
442
+ inkeep tenant your-tenant-id
443
+
444
+ # Or use environment variable
445
+ export INKEEP_TENANT_ID=your-tenant-id
446
+ ```
447
+
448
+ **"Failed to fetch graphs" or connection errors**
449
+ ```bash
450
+ # Check if backend is running
451
+ curl http://localhost:3002/health
452
+
453
+ # Verify API URL
454
+ echo $INKEEP_API_URL
455
+
456
+ # Try with explicit URL
457
+ inkeep list-graphs --url http://localhost:3002
458
+ ```
459
+
460
+
461
+ **"Graph not found" when using chat**
462
+ ```bash
463
+ # List available graphs first
464
+ inkeep list-graphs
465
+
466
+ # Use interactive selection
467
+ inkeep chat
468
+ # (Select from list)
469
+ ```
470
+
471
+ **Command not found: inkeep**
472
+ ```bash
473
+ # Ensure CLI is linked globally
474
+ cd agents-cli
475
+ npm link
476
+
477
+ # Or if published, install globally
478
+ pnpm add -g @inkeep/agents-cli
479
+ # or
480
+ npm install -g @inkeep/agents-cli
481
+
482
+ # Or add to PATH manually (for development)
483
+ export PATH="$PATH:/path/to/agents-cli/dist"
484
+ ```
485
+
486
+ ## Dependencies
487
+
488
+ ### Runtime Dependencies
489
+ - **commander**: Command-line framework
490
+ - **chalk**: Terminal styling
491
+ - **dotenv**: Environment variable loading
492
+ - **ora**: Loading spinners
493
+ - **cli-table3**: Table formatting
494
+ - **inquirer**: Interactive prompts
495
+ - **inquirer-autocomplete-prompt**: Searchable selections
496
+
497
+ ### Development Dependencies
498
+ - **typescript**: TypeScript compiler
499
+ - **@types/node**: Node.js types
500
+ - **vitest**: Testing framework
501
+ - **@vitest/coverage-v8**: Coverage reporting
502
+
503
+ ## Requirements
504
+
505
+ - Node.js >= 20.x
506
+ - pnpm package manager
507
+ - TypeScript 5.x
508
+ - Inkeep Agent Framework backend
509
+
510
+ ## License
511
+
512
+ MIT
@@ -0,0 +1 @@
1
+ export {};