@agentick/cli 0.0.1

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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +353 -0
  3. package/dist/bin.d.ts +6 -0
  4. package/dist/bin.d.ts.map +1 -0
  5. package/dist/bin.js +44 -0
  6. package/dist/bin.js.map +1 -0
  7. package/dist/chat-session.d.ts +37 -0
  8. package/dist/chat-session.d.ts.map +1 -0
  9. package/dist/chat-session.js +201 -0
  10. package/dist/chat-session.js.map +1 -0
  11. package/dist/cli.d.ts +84 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +147 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/commands/chat.d.ts +13 -0
  16. package/dist/commands/chat.d.ts.map +1 -0
  17. package/dist/commands/chat.js +22 -0
  18. package/dist/commands/chat.js.map +1 -0
  19. package/dist/commands/send.d.ts +14 -0
  20. package/dist/commands/send.d.ts.map +1 -0
  21. package/dist/commands/send.js +77 -0
  22. package/dist/commands/send.js.map +1 -0
  23. package/dist/commands/status.d.ts +11 -0
  24. package/dist/commands/status.d.ts.map +1 -0
  25. package/dist/commands/status.js +22 -0
  26. package/dist/commands/status.js.map +1 -0
  27. package/dist/config.d.ts +36 -0
  28. package/dist/config.d.ts.map +1 -0
  29. package/dist/config.js +83 -0
  30. package/dist/config.js.map +1 -0
  31. package/dist/index.d.ts +12 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +12 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/ui/renderer.d.ts +85 -0
  36. package/dist/ui/renderer.d.ts.map +1 -0
  37. package/dist/ui/renderer.js +163 -0
  38. package/dist/ui/renderer.js.map +1 -0
  39. package/package.json +47 -0
  40. package/src/bin.ts +50 -0
  41. package/src/chat-session.ts +244 -0
  42. package/src/cli.ts +206 -0
  43. package/src/commands/chat.ts +34 -0
  44. package/src/commands/send.ts +95 -0
  45. package/src/commands/status.ts +32 -0
  46. package/src/config.ts +123 -0
  47. package/src/index.ts +12 -0
  48. package/src/types.d.ts +33 -0
  49. package/src/ui/renderer.ts +194 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Agentick Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,353 @@
1
+ # @agentick/cli
2
+
3
+ Terminal client for Agentick agents.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Global install
9
+ npm install -g @agentick/cli
10
+
11
+ # Or use npx
12
+ npx @agentick/cli chat --url http://localhost:3000/api/agent
13
+
14
+ # Or add to your project
15
+ pnpm add @agentick/cli
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ```bash
21
+ # Start interactive chat
22
+ agentick chat --url http://localhost:3000/api/agent
23
+
24
+ # Send a single message
25
+ agentick send "What is 2+2?" --url http://localhost:3000/api/agent
26
+
27
+ # Check server status
28
+ agentick status --url http://localhost:3000/api/agent
29
+ ```
30
+
31
+ ## Commands
32
+
33
+ ### `agentick chat`
34
+
35
+ Interactive chat mode with streaming responses.
36
+
37
+ ```bash
38
+ agentick chat [options]
39
+
40
+ Options:
41
+ -u, --url <url> Server URL (or set TENTICKLE_URL)
42
+ -s, --session <id> Session ID (optional)
43
+ -t, --token <token> Authentication token (or set TENTICKLE_TOKEN)
44
+ --no-stream Disable streaming (wait for complete response)
45
+ --debug Enable debug mode
46
+ ```
47
+
48
+ **In-chat commands:**
49
+
50
+ | Command | Description |
51
+ | ------------------ | ----------------------- |
52
+ | `/help` | Show available commands |
53
+ | `/quit` or `/exit` | Exit the chat |
54
+ | `/status` | Show session status |
55
+ | `/clear` | Clear the screen |
56
+ | `/debug` | Toggle debug mode |
57
+
58
+ ### `agentick send`
59
+
60
+ Send a single message and print the response. Great for scripting.
61
+
62
+ ```bash
63
+ agentick send <message> [options]
64
+
65
+ Options:
66
+ -u, --url <url> Server URL
67
+ -s, --session <id> Session ID
68
+ -t, --token <token> Authentication token
69
+ --stdin Read additional context from stdin
70
+ -f, --format <format> Output format: plain, json, markdown (default: plain)
71
+ --no-stream Disable streaming
72
+ ```
73
+
74
+ **Examples:**
75
+
76
+ ```bash
77
+ # Simple message
78
+ agentick send "Hello, agent!" --url http://localhost:3000/api/agent
79
+
80
+ # Pipe file content
81
+ cat document.txt | agentick send "Summarize this:" --stdin --url $URL
82
+
83
+ # JSON output for scripting
84
+ agentick send "List 5 ideas" --format json --url $URL | jq '.response'
85
+
86
+ # Non-streaming (wait for complete response)
87
+ agentick send "Complex question" --no-stream --url $URL
88
+ ```
89
+
90
+ ### `agentick status`
91
+
92
+ Show server and session status.
93
+
94
+ ```bash
95
+ agentick status [options]
96
+
97
+ Options:
98
+ -u, --url <url> Server URL
99
+ -s, --session <id> Session ID
100
+ -t, --token <token> Authentication token
101
+ ```
102
+
103
+ ## Configuration
104
+
105
+ ### Environment Variables
106
+
107
+ ```bash
108
+ export TENTICKLE_URL="http://localhost:3000/api/agent"
109
+ export TENTICKLE_TOKEN="your-auth-token"
110
+ export TENTICKLE_SESSION="my-session"
111
+ export TENTICKLE_DEBUG="1"
112
+ ```
113
+
114
+ ### Config File
115
+
116
+ Create `~/.agentick/config.json`:
117
+
118
+ ```json
119
+ {
120
+ "defaultUrl": "http://localhost:3000/api/agent",
121
+ "defaultToken": "your-auth-token",
122
+ "debug": false,
123
+ "aliases": {
124
+ "local": "http://localhost:3000/api/agent",
125
+ "prod": "https://api.example.com/agent"
126
+ }
127
+ }
128
+ ```
129
+
130
+ With aliases, you can use:
131
+
132
+ ```bash
133
+ agentick chat --url local
134
+ agentick chat --url prod
135
+ ```
136
+
137
+ ### Priority
138
+
139
+ Configuration is loaded in this order (later overrides earlier):
140
+
141
+ 1. Config file (`~/.agentick/config.json`)
142
+ 2. Environment variables
143
+ 3. CLI arguments
144
+
145
+ ## Output Formats
146
+
147
+ ### Plain (default)
148
+
149
+ Raw text output, suitable for reading or piping.
150
+
151
+ ```bash
152
+ agentick send "Hello" --format plain
153
+ # Hello! How can I help you today?
154
+ ```
155
+
156
+ ### JSON
157
+
158
+ Structured output for scripting.
159
+
160
+ ```bash
161
+ agentick send "Hello" --format json
162
+ # {
163
+ # "response": "Hello! How can I help you today?",
164
+ # "sessionId": "sess-abc123"
165
+ # }
166
+ ```
167
+
168
+ ### Markdown
169
+
170
+ Rendered markdown in terminal (with colors and formatting).
171
+
172
+ ```bash
173
+ agentick send "Show me code" --format markdown
174
+ ```
175
+
176
+ ## Features
177
+
178
+ ### Streaming
179
+
180
+ By default, responses stream to your terminal as they're generated:
181
+
182
+ ```
183
+ You: What's the weather like?
184
+
185
+ Agent: Let me check that for you...
186
+ [tool: web_search] Searching...
187
+
188
+ The current weather in your area is 72°F with partly cloudy skies.
189
+ ```
190
+
191
+ Disable with `--no-stream` to wait for the complete response.
192
+
193
+ ### Tool Execution
194
+
195
+ Tool calls are shown inline:
196
+
197
+ ```
198
+ Agent: I'll search for that information.
199
+ [tool: web_search] {"query": "latest news"}
200
+
201
+ Based on my search, here are the top stories...
202
+ ```
203
+
204
+ ### Debug Mode
205
+
206
+ Enable debug mode to see what's happening under the hood:
207
+
208
+ ```bash
209
+ agentick chat --debug
210
+
211
+ # Or toggle during chat
212
+ /debug
213
+ ```
214
+
215
+ Debug output shows:
216
+
217
+ - Request/response details
218
+ - Stream events
219
+ - Token usage
220
+
221
+ ## Architecture
222
+
223
+ ```
224
+ ┌─────────────┐ ┌──────────────────┐ ┌─────────────────┐
225
+ │ CLI │────►│ @agentick/client │────►│ Agentick Server│
226
+ │ │ │ │ │ │
227
+ │ - chat │ │ - SSE transport │ │ - Express │
228
+ │ - send │ │ - Session mgmt │ │ - Gateway │
229
+ │ - status │ │ - Event stream │ │ │
230
+ └─────────────┘ └──────────────────┘ └─────────────────┘
231
+ ```
232
+
233
+ The CLI uses `@agentick/client` under the hood, which means:
234
+
235
+ - Works with any Agentick server (Express, Gateway, etc.)
236
+ - Automatic transport detection (SSE for http://, WebSocket for ws://)
237
+ - Same session management as web clients
238
+
239
+ ## Development
240
+
241
+ ```bash
242
+ # Clone the repo
243
+ git clone https://github.com/your-org/agentick.git
244
+ cd agentick
245
+
246
+ # Install dependencies
247
+ pnpm install
248
+
249
+ # Run CLI in development
250
+ cd packages/cli
251
+ pnpm cli --help
252
+ pnpm cli chat --url http://localhost:3000/api/agent
253
+ ```
254
+
255
+ ### Building
256
+
257
+ ```bash
258
+ pnpm build
259
+ ```
260
+
261
+ ### Testing
262
+
263
+ ```bash
264
+ pnpm test
265
+ ```
266
+
267
+ ## Programmatic Usage
268
+
269
+ The CLI can also be used as a library:
270
+
271
+ ```typescript
272
+ import { CLI, createCLI } from '@agentick/cli';
273
+
274
+ const cli = createCLI({
275
+ url: 'http://localhost:3000/api/agent',
276
+ token: 'your-token',
277
+ });
278
+
279
+ // Listen for events
280
+ cli.on('stream:delta', ({ text }) => {
281
+ process.stdout.write(text);
282
+ });
283
+
284
+ cli.on('tool:start', ({ name }) => {
285
+ console.log(`[tool: ${name}]`);
286
+ });
287
+
288
+ // Send a message
289
+ const response = await cli.send('Hello, agent!');
290
+ console.log('Response:', response);
291
+
292
+ // Stream a message
293
+ for await (const event of cli.stream('What is 2+2?')) {
294
+ console.log(event);
295
+ }
296
+
297
+ // Clean up
298
+ cli.destroy();
299
+ ```
300
+
301
+ ### ChatSession
302
+
303
+ For interactive sessions:
304
+
305
+ ```typescript
306
+ import { ChatSession } from '@agentick/cli';
307
+
308
+ const session = new ChatSession({
309
+ url: 'http://localhost:3000/api/agent',
310
+ markdown: true,
311
+ });
312
+
313
+ await session.start();
314
+ ```
315
+
316
+ ### Renderer
317
+
318
+ For custom terminal output:
319
+
320
+ ```typescript
321
+ import { Renderer } from '@agentick/cli';
322
+
323
+ const renderer = new Renderer({
324
+ markdown: true,
325
+ debug: false,
326
+ });
327
+
328
+ renderer.info('Starting...');
329
+ renderer.response('Hello! How can I help?');
330
+ renderer.error('Something went wrong');
331
+ renderer.toolStart('web_search', { query: 'test' });
332
+ ```
333
+
334
+ ## Roadmap
335
+
336
+ - [ ] Rich TUI with OpenTUI
337
+ - [ ] History navigation
338
+ - [ ] Context inspection (`/context`)
339
+ - [ ] Session management (`/sessions`, `/reset`)
340
+ - [ ] WebSocket support for Gateway
341
+ - [ ] Voice input (whisper)
342
+ - [ ] Image rendering (kitty/iTerm2)
343
+
344
+ ## Related Packages
345
+
346
+ - [`@agentick/core`](../core) - JSX runtime for agents
347
+ - [`@agentick/client`](../client) - Client SDK
348
+ - [`@agentick/server`](../server) - SSE server
349
+ - [`@agentick/express`](../express) - Express middleware
350
+
351
+ ## License
352
+
353
+ MIT
package/dist/bin.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Agentick CLI - Entry point
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;GAEG"}
package/dist/bin.js ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Agentick CLI - Entry point
4
+ */
5
+ import { program } from "commander";
6
+ import { chatCommand } from "./commands/chat.js";
7
+ import { sendCommand } from "./commands/send.js";
8
+ import { statusCommand } from "./commands/status.js";
9
+ program.name("agentick").description("Terminal client for Agentick agents").version("0.0.1");
10
+ // Chat command (interactive)
11
+ program
12
+ .command("chat")
13
+ .description("Interactive chat with a Agentick agent")
14
+ .option("-u, --url <url>", "Server URL (e.g., http://localhost:3000/api/agent)")
15
+ .option("-s, --session <id>", "Session ID")
16
+ .option("-t, --token <token>", "Authentication token")
17
+ .option("--no-stream", "Disable streaming (wait for complete response)")
18
+ .option("--debug", "Enable debug mode")
19
+ .action(chatCommand);
20
+ // Send command (non-interactive)
21
+ program
22
+ .command("send <message>")
23
+ .description("Send a single message and print the response")
24
+ .option("-u, --url <url>", "Server URL")
25
+ .option("-s, --session <id>", "Session ID")
26
+ .option("-t, --token <token>", "Authentication token")
27
+ .option("--stdin", "Read additional context from stdin")
28
+ .option("-f, --format <format>", "Output format: plain, json, markdown", "plain")
29
+ .option("--no-stream", "Disable streaming")
30
+ .action(sendCommand);
31
+ // Status command
32
+ program
33
+ .command("status")
34
+ .description("Show server and session status")
35
+ .option("-u, --url <url>", "Server URL")
36
+ .option("-s, --session <id>", "Session ID")
37
+ .option("-t, --token <token>", "Authentication token")
38
+ .action(statusCommand);
39
+ // Default to chat if no command specified
40
+ program.action(() => {
41
+ program.help();
42
+ });
43
+ program.parse();
44
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;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aAAa,CAAC,CAAC;AAEzB,0CAA0C;AAC1C,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE;IAClB,OAAO,CAAC,IAAI,EAAE,CAAC;AACjB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * ChatSession - Interactive chat session
3
+ */
4
+ import { type CLIConfig } from "./cli.js";
5
+ export interface ChatSessionOptions extends CLIConfig {
6
+ /** Custom prompt (default: "You: ") */
7
+ prompt?: string;
8
+ /** Enable markdown rendering (default: true) */
9
+ markdown?: boolean;
10
+ }
11
+ /**
12
+ * Interactive chat session
13
+ */
14
+ export declare class ChatSession {
15
+ private cli;
16
+ private renderer;
17
+ private options;
18
+ private rl?;
19
+ private isRunning;
20
+ private commands;
21
+ constructor(options: ChatSessionOptions);
22
+ private setupCommands;
23
+ private setupEventHandlers;
24
+ private showHelp;
25
+ private showStatus;
26
+ private handleCommand;
27
+ private handleMessage;
28
+ /**
29
+ * Start the interactive session
30
+ */
31
+ start(): Promise<void>;
32
+ /**
33
+ * Stop the session
34
+ */
35
+ stop(): void;
36
+ }
37
+ //# sourceMappingURL=chat-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-session.d.ts","sourceRoot":"","sources":["../src/chat-session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAO,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAG/C,MAAM,WAAW,kBAAmB,SAAQ,SAAS;IACnD,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AASD;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,EAAE,CAAC,CAAqB;IAChC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAwC;gBAE5C,OAAO,EAAE,kBAAkB;IAYvC,OAAO,CAAC,aAAa;IAuDrB,OAAO,CAAC,kBAAkB;IA0B1B,OAAO,CAAC,QAAQ;IAgBhB,OAAO,CAAC,UAAU;YAWJ,aAAa;YAYb,aAAa;IAQ3B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAsD5B;;OAEG;IACH,IAAI,IAAI,IAAI;CASb"}
@@ -0,0 +1,201 @@
1
+ /**
2
+ * ChatSession - Interactive chat session
3
+ */
4
+ import * as readline from "readline";
5
+ import { CLI } from "./cli.js";
6
+ import { Renderer } from "./ui/renderer.js";
7
+ /**
8
+ * Interactive chat session
9
+ */
10
+ export class ChatSession {
11
+ cli;
12
+ renderer;
13
+ options;
14
+ rl;
15
+ isRunning = false;
16
+ commands = new Map();
17
+ constructor(options) {
18
+ this.options = options;
19
+ this.cli = new CLI(options);
20
+ this.renderer = new Renderer({
21
+ markdown: options.markdown ?? true,
22
+ debug: options.debug,
23
+ });
24
+ this.setupCommands();
25
+ this.setupEventHandlers();
26
+ }
27
+ setupCommands() {
28
+ const commands = [
29
+ {
30
+ name: "help",
31
+ aliases: ["h", "?"],
32
+ description: "Show available commands",
33
+ handler: () => {
34
+ this.showHelp();
35
+ return true;
36
+ },
37
+ },
38
+ {
39
+ name: "quit",
40
+ aliases: ["exit", "q"],
41
+ description: "Exit the chat",
42
+ handler: () => false,
43
+ },
44
+ {
45
+ name: "status",
46
+ description: "Show session status",
47
+ handler: () => {
48
+ this.showStatus();
49
+ return true;
50
+ },
51
+ },
52
+ {
53
+ name: "clear",
54
+ aliases: ["cls"],
55
+ description: "Clear the screen",
56
+ handler: () => {
57
+ console.clear();
58
+ return true;
59
+ },
60
+ },
61
+ {
62
+ name: "debug",
63
+ description: "Toggle debug mode",
64
+ handler: () => {
65
+ this.renderer.toggleDebug();
66
+ this.renderer.info(`Debug mode: ${this.renderer.isDebug ? "on" : "off"}`);
67
+ return true;
68
+ },
69
+ },
70
+ ];
71
+ for (const cmd of commands) {
72
+ this.commands.set(cmd.name, cmd);
73
+ if (cmd.aliases) {
74
+ for (const alias of cmd.aliases) {
75
+ this.commands.set(alias, cmd);
76
+ }
77
+ }
78
+ }
79
+ }
80
+ setupEventHandlers() {
81
+ this.cli.on("stream:delta", ({ text }) => {
82
+ this.renderer.streamDelta(text);
83
+ });
84
+ this.cli.on("stream:start", () => {
85
+ this.renderer.streamStart();
86
+ });
87
+ this.cli.on("stream:end", () => {
88
+ this.renderer.streamEnd();
89
+ });
90
+ this.cli.on("tool:start", ({ name, args }) => {
91
+ this.renderer.toolStart(name, args);
92
+ });
93
+ this.cli.on("tool:end", ({ name, result }) => {
94
+ this.renderer.toolEnd(name, result);
95
+ });
96
+ this.cli.on("error", (error) => {
97
+ this.renderer.error(error.message);
98
+ });
99
+ }
100
+ showHelp() {
101
+ const uniqueCommands = new Map();
102
+ for (const [name, cmd] of this.commands) {
103
+ if (!uniqueCommands.has(cmd.name)) {
104
+ uniqueCommands.set(cmd.name, cmd);
105
+ }
106
+ }
107
+ this.renderer.info("\nAvailable commands:");
108
+ for (const [name, cmd] of uniqueCommands) {
109
+ const aliases = cmd.aliases?.length ? ` (${cmd.aliases.join(", ")})` : "";
110
+ this.renderer.info(` /${name}${aliases} - ${cmd.description}`);
111
+ }
112
+ console.log();
113
+ }
114
+ showStatus() {
115
+ const sessionId = this.cli.sessionId ?? "not connected";
116
+ const connected = this.cli.isConnected ? "yes" : "no";
117
+ this.renderer.info("\nSession Status:");
118
+ this.renderer.info(` Session ID: ${sessionId}`);
119
+ this.renderer.info(` Connected: ${connected}`);
120
+ this.renderer.info(` URL: ${this.options.url}`);
121
+ console.log();
122
+ }
123
+ async handleCommand(input) {
124
+ const [cmdName, ...args] = input.slice(1).split(/\s+/);
125
+ const cmd = this.commands.get(cmdName.toLowerCase());
126
+ if (!cmd) {
127
+ this.renderer.error(`Unknown command: /${cmdName}. Type /help for available commands.`);
128
+ return true;
129
+ }
130
+ return cmd.handler(args);
131
+ }
132
+ async handleMessage(message) {
133
+ try {
134
+ await this.cli.send(message);
135
+ }
136
+ catch (error) {
137
+ this.renderer.error(error instanceof Error ? error.message : String(error));
138
+ }
139
+ }
140
+ /**
141
+ * Start the interactive session
142
+ */
143
+ async start() {
144
+ if (this.isRunning)
145
+ return;
146
+ this.isRunning = true;
147
+ this.rl = readline.createInterface({
148
+ input: process.stdin,
149
+ output: process.stdout,
150
+ });
151
+ // Print welcome message
152
+ this.renderer.info(`Connected to ${this.options.url}`);
153
+ if (this.cli.sessionId) {
154
+ this.renderer.info(`Session: ${this.cli.sessionId}`);
155
+ }
156
+ this.renderer.info("Type /help for commands, /quit to exit\n");
157
+ const prompt = this.options.prompt ?? "You: ";
158
+ const promptForInput = () => {
159
+ if (!this.isRunning)
160
+ return;
161
+ this.rl.question(prompt, async (input) => {
162
+ const trimmed = input.trim();
163
+ if (!trimmed) {
164
+ promptForInput();
165
+ return;
166
+ }
167
+ // Handle commands
168
+ if (trimmed.startsWith("/")) {
169
+ const shouldContinue = await this.handleCommand(trimmed);
170
+ if (!shouldContinue) {
171
+ this.stop();
172
+ return;
173
+ }
174
+ promptForInput();
175
+ return;
176
+ }
177
+ // Handle regular message
178
+ await this.handleMessage(trimmed);
179
+ promptForInput();
180
+ });
181
+ };
182
+ // Handle Ctrl+C
183
+ this.rl.on("close", () => {
184
+ this.stop();
185
+ });
186
+ promptForInput();
187
+ }
188
+ /**
189
+ * Stop the session
190
+ */
191
+ stop() {
192
+ if (!this.isRunning)
193
+ return;
194
+ this.isRunning = false;
195
+ this.renderer.info("\nGoodbye!");
196
+ this.rl?.close();
197
+ this.cli.destroy();
198
+ process.exit(0);
199
+ }
200
+ }
201
+ //# sourceMappingURL=chat-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-session.js","sourceRoot":"","sources":["../src/chat-session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,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