@xuda.ai/cli 0.1.0 → 0.1.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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/session.mjs +14 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.ai/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Xuda CLI — sign in to Xuda and run published AI agents from your terminal.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/session.mjs CHANGED
@@ -2,7 +2,7 @@ import readline from 'node:readline';
2
2
  import { io } from 'socket.io-client';
3
3
  import { API_URL } from './config.mjs';
4
4
 
5
- const CLI_VERSION = '0.1.0';
5
+ const CLI_VERSION = '0.1.1';
6
6
 
7
7
  export const runAgentSession = async ({ agentId, agentName, agentVersion, credentials }) => {
8
8
  const socket = io(API_URL, {
@@ -17,13 +17,14 @@ export const runAgentSession = async ({ agentId, agentName, agentVersion, creden
17
17
  },
18
18
  });
19
19
 
20
- let sessionId = null;
20
+ let conversationId = null;
21
21
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: process.stdin.isTTY });
22
22
  const prompt = () => {
23
23
  if (!process.stdin.isTTY) return;
24
24
  rl.setPrompt('› ');
25
25
  rl.prompt();
26
26
  };
27
+ const isOurs = (msg) => !conversationId || !msg?.conversation_id || msg.conversation_id === conversationId;
27
28
 
28
29
  await new Promise((resolve, reject) => {
29
30
  const t = setTimeout(() => reject(new Error('handshake timeout')), 15000);
@@ -34,7 +35,7 @@ export const runAgentSession = async ({ agentId, agentName, agentVersion, creden
34
35
 
35
36
  socket.on('handshake_ok', (msg) => {
36
37
  clearTimeout(t);
37
- sessionId = msg.session_id;
38
+ conversationId = msg.conversation_id || msg.session_id;
38
39
  const name = msg.agent_name || agentName || 'agent';
39
40
  console.log(`Connected to ${name}. (ctrl-c to exit)`);
40
41
  if (msg.welcome) console.log(`\n${msg.welcome}\n`);
@@ -53,9 +54,14 @@ export const runAgentSession = async ({ agentId, agentName, agentVersion, creden
53
54
  });
54
55
  });
55
56
 
56
- socket.on('stream_start', () => process.stdout.write('\n'));
57
- socket.on('stream_delta', (msg) => { if (msg?.text) process.stdout.write(msg.text); });
58
- socket.on('stream_end', () => { process.stdout.write('\n\n'); prompt(); });
57
+ socket.on('stream_start', (msg) => { if (isOurs(msg)) process.stdout.write('\n'); });
58
+ socket.on('response_start', (msg) => { if (isOurs(msg)) process.stdout.write('\n'); });
59
+ socket.on('stream_delta', (msg) => {
60
+ if (!isOurs(msg)) return;
61
+ const chunk = msg?.delta ?? msg?.text;
62
+ if (chunk) process.stdout.write(String(chunk));
63
+ });
64
+ socket.on('stream_end', (msg) => { if (isOurs(msg)) { process.stdout.write('\n\n'); prompt(); } });
59
65
  socket.on('error', (msg) => { console.error(`\nerror: ${msg?.message || 'unknown'}`); prompt(); });
60
66
 
61
67
  socket.on('disconnect', () => {
@@ -66,11 +72,11 @@ export const runAgentSession = async ({ agentId, agentName, agentVersion, creden
66
72
  rl.on('line', (line) => {
67
73
  const text = line.trim();
68
74
  if (!text) { prompt(); return; }
69
- socket.emit('prompt', { session_id: sessionId, text });
75
+ socket.emit('prompt', { conversation_id: conversationId, text });
70
76
  });
71
77
 
72
78
  rl.on('SIGINT', () => {
73
- try { socket.emit('close', { session_id: sessionId }); } catch {}
79
+ try { socket.emit('close', { conversation_id: conversationId }); } catch {}
74
80
  socket.disconnect();
75
81
  process.exit(0);
76
82
  });