uwonbot 1.4.0 → 1.5.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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/agent.js +37 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uwonbot",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Uwonbot AI Assistant CLI — Your AI controls your computer",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/agent.js CHANGED
@@ -892,16 +892,41 @@ end tell'`, { timeout: 3000 });
892
892
  console.log('');
893
893
  }
894
894
 
895
- const wss = new WebSocketServer({ port });
895
+ const UNGATED_CMDS = new Set(['ping', 'auth_session', 'screenshot', 'screen_size']);
896
896
 
897
- wss.on('connection', (ws, req) => {
898
- const origin = req.headers.origin || 'unknown';
897
+ function attachClientHandler(ws, req) {
898
+ const origin = req?.headers?.origin || 'unknown';
899
899
  console.log(chalk.green(` ✓ Client connected from ${origin}`));
900
900
 
901
+ let _authenticated = false;
902
+
901
903
  ws.on('message', async (data) => {
902
904
  const raw = data.toString();
903
- let _reqId;
904
- try { _reqId = JSON.parse(raw)._reqId; } catch {}
905
+ let _reqId, cmd;
906
+ try { cmd = JSON.parse(raw); _reqId = cmd._reqId; } catch {}
907
+
908
+ if (cmd?.type === 'auth_session') {
909
+ if (cmd.uid === uid) {
910
+ _authenticated = true;
911
+ console.log(chalk.green(' ✓ Client authenticated'));
912
+ const result = { ok: true, authenticated: true };
913
+ if (_reqId) result._reqId = _reqId;
914
+ ws.send(JSON.stringify(result));
915
+ } else {
916
+ const result = { ok: false, error: 'UID mismatch' };
917
+ if (_reqId) result._reqId = _reqId;
918
+ ws.send(JSON.stringify(result));
919
+ }
920
+ return;
921
+ }
922
+
923
+ if (!_authenticated && !UNGATED_CMDS.has(cmd?.type)) {
924
+ const result = { ok: false, error: 'auth_required', message: 'Authentication required. Send auth_session first.' };
925
+ if (_reqId) result._reqId = _reqId;
926
+ ws.send(JSON.stringify(result));
927
+ return;
928
+ }
929
+
905
930
  const result = await handleCommand(raw);
906
931
  if (_reqId) result._reqId = _reqId;
907
932
  ws.send(JSON.stringify(result));
@@ -909,12 +934,16 @@ end tell'`, { timeout: 3000 });
909
934
 
910
935
  ws.on('close', () => {
911
936
  console.log(chalk.yellow(' ○ Client disconnected'));
937
+ _authenticated = false;
912
938
  _assistantOpen = false;
913
939
  clearTimeout(_assistantOpenTimer);
914
940
  });
915
941
 
916
- ws.send(JSON.stringify({ type: 'welcome', agent: 'uwonbot', version: '1.1.2', uid }));
917
- });
942
+ ws.send(JSON.stringify({ type: 'welcome', agent: 'uwonbot', version: '1.5.0', uid, authRequired: true }));
943
+ }
944
+
945
+ const wss = new WebSocketServer({ port });
946
+ wss.on('connection', attachClientHandler);
918
947
 
919
948
  wss.on('error', async (err) => {
920
949
  if (err.code === 'EADDRINUSE') {
@@ -923,17 +952,7 @@ end tell'`, { timeout: 3000 });
923
952
  await new Promise(r => setTimeout(r, 2000));
924
953
  try {
925
954
  const retry = new WebSocketServer({ port });
926
- retry.on('connection', (ws, req) => {
927
- ws.on('message', async (data) => {
928
- const raw = data.toString();
929
- let _reqId;
930
- try { _reqId = JSON.parse(raw)._reqId; } catch {}
931
- const result = await handleCommand(raw);
932
- if (_reqId) result._reqId = _reqId;
933
- ws.send(JSON.stringify(result));
934
- });
935
- ws.send(JSON.stringify({ type: 'welcome', agent: 'uwonbot', version: '1.1.8', uid }));
936
- });
955
+ retry.on('connection', (ws, req) => attachClientHandler(ws, req));
937
956
  console.log(chalk.green(` ✓ 재시도 성공 — ws://localhost:${port}`));
938
957
  } catch {
939
958
  console.log(chalk.red(` ✗ 포트 ${port}를 사용할 수 없습니다.`));