amai 0.0.2 → 0.0.3

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.
package/dist/cli.cjs CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  var pc4 = require('picocolors');
5
5
  var WebSocket = require('ws');
6
+ var events = require('events');
6
7
  var zod = require('zod');
7
8
  var promises = require('fs/promises');
8
9
  var path9 = require('path');
@@ -1261,10 +1262,50 @@ var startHttpServer = (connection) => {
1261
1262
  }
1262
1263
  const app = new hono.Hono();
1263
1264
  app.use(cors.cors());
1264
- app.post("/daemon/status/stream", (c) => {
1265
+ app.post("/daemon/status", (c) => {
1265
1266
  const status = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1266
1267
  return c.json({ connected: status === "open" });
1267
1268
  });
1269
+ app.get("/daemon/status/stream", (c) => {
1270
+ const encoder = new TextEncoder();
1271
+ const stream = new ReadableStream({
1272
+ start(controller) {
1273
+ const initialStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1274
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: initialStatus === "open" })}
1275
+
1276
+ `));
1277
+ const statusHandler = (data) => {
1278
+ try {
1279
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}
1280
+
1281
+ `));
1282
+ } catch {
1283
+ }
1284
+ };
1285
+ statusEmitter.on("status", statusHandler);
1286
+ const heartbeatInterval = setInterval(() => {
1287
+ try {
1288
+ const currentStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1289
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: currentStatus === "open" })}
1290
+
1291
+ `));
1292
+ } catch {
1293
+ }
1294
+ }, 15e3);
1295
+ c.req.raw.signal.addEventListener("abort", () => {
1296
+ statusEmitter.off("status", statusHandler);
1297
+ clearInterval(heartbeatInterval);
1298
+ });
1299
+ }
1300
+ });
1301
+ return new Response(stream, {
1302
+ headers: {
1303
+ "Content-Type": "text/event-stream",
1304
+ "Cache-Control": "no-cache",
1305
+ "Connection": "keep-alive"
1306
+ }
1307
+ });
1308
+ });
1268
1309
  app.get("context", async (c) => {
1269
1310
  const context = getContext(process.cwd());
1270
1311
  return c.body(JSON.stringify(context));
@@ -1508,6 +1549,7 @@ async function login() {
1508
1549
  }
1509
1550
 
1510
1551
  // src/server.ts
1552
+ var statusEmitter = new events.EventEmitter();
1511
1553
  var toolExecutors = {
1512
1554
  editFile: editFiles,
1513
1555
  deleteFile,
@@ -1533,6 +1575,7 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
1533
1575
  });
1534
1576
  ws.on("open", () => {
1535
1577
  console.log(pc4__default.default.green("Connected to server agent streams"));
1578
+ statusEmitter.emit("status", { connected: true });
1536
1579
  });
1537
1580
  ws.on("message", async (data) => {
1538
1581
  const message = JSON.parse(data.toString());
@@ -1562,10 +1605,12 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
1562
1605
  });
1563
1606
  ws.on("close", () => {
1564
1607
  console.log(pc4__default.default.red("Disconnected from server. Reconnecting in 5s..."));
1608
+ statusEmitter.emit("status", { connected: false });
1565
1609
  setTimeout(() => connectToServer2(serverUrl), 5e3);
1566
1610
  });
1567
1611
  ws.on("error", (error) => {
1568
1612
  console.error(pc4__default.default.red(`WebSocket error: ${error.message}`));
1613
+ statusEmitter.emit("status", { connected: false });
1569
1614
  });
1570
1615
  return ws;
1571
1616
  }
@@ -1762,7 +1807,7 @@ function getDaemonPid() {
1762
1807
  return null;
1763
1808
  }
1764
1809
  }
1765
- var VERSION = "0.0.2";
1810
+ var VERSION = "0.0.3";
1766
1811
  var PROJECT_DIR = process.cwd();
1767
1812
  function promptUser(question) {
1768
1813
  const rl = readline__default.default.createInterface({
package/dist/cli.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import pc4 from 'picocolors';
3
3
  import WebSocket from 'ws';
4
+ import { EventEmitter } from 'events';
4
5
  import { z } from 'zod';
5
6
  import { readFile, writeFile, stat, access, readdir, glob, unlink, mkdir } from 'fs/promises';
6
7
  import path9, { dirname } from 'path';
@@ -1249,10 +1250,50 @@ var startHttpServer = (connection) => {
1249
1250
  }
1250
1251
  const app = new Hono();
1251
1252
  app.use(cors());
1252
- app.post("/daemon/status/stream", (c) => {
1253
+ app.post("/daemon/status", (c) => {
1253
1254
  const status = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1254
1255
  return c.json({ connected: status === "open" });
1255
1256
  });
1257
+ app.get("/daemon/status/stream", (c) => {
1258
+ const encoder = new TextEncoder();
1259
+ const stream = new ReadableStream({
1260
+ start(controller) {
1261
+ const initialStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1262
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: initialStatus === "open" })}
1263
+
1264
+ `));
1265
+ const statusHandler = (data) => {
1266
+ try {
1267
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}
1268
+
1269
+ `));
1270
+ } catch {
1271
+ }
1272
+ };
1273
+ statusEmitter.on("status", statusHandler);
1274
+ const heartbeatInterval = setInterval(() => {
1275
+ try {
1276
+ const currentStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1277
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: currentStatus === "open" })}
1278
+
1279
+ `));
1280
+ } catch {
1281
+ }
1282
+ }, 15e3);
1283
+ c.req.raw.signal.addEventListener("abort", () => {
1284
+ statusEmitter.off("status", statusHandler);
1285
+ clearInterval(heartbeatInterval);
1286
+ });
1287
+ }
1288
+ });
1289
+ return new Response(stream, {
1290
+ headers: {
1291
+ "Content-Type": "text/event-stream",
1292
+ "Cache-Control": "no-cache",
1293
+ "Connection": "keep-alive"
1294
+ }
1295
+ });
1296
+ });
1256
1297
  app.get("context", async (c) => {
1257
1298
  const context = getContext(process.cwd());
1258
1299
  return c.body(JSON.stringify(context));
@@ -1496,6 +1537,7 @@ async function login() {
1496
1537
  }
1497
1538
 
1498
1539
  // src/server.ts
1540
+ var statusEmitter = new EventEmitter();
1499
1541
  var toolExecutors = {
1500
1542
  editFile: editFiles,
1501
1543
  deleteFile,
@@ -1521,6 +1563,7 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
1521
1563
  });
1522
1564
  ws.on("open", () => {
1523
1565
  console.log(pc4.green("Connected to server agent streams"));
1566
+ statusEmitter.emit("status", { connected: true });
1524
1567
  });
1525
1568
  ws.on("message", async (data) => {
1526
1569
  const message = JSON.parse(data.toString());
@@ -1550,10 +1593,12 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
1550
1593
  });
1551
1594
  ws.on("close", () => {
1552
1595
  console.log(pc4.red("Disconnected from server. Reconnecting in 5s..."));
1596
+ statusEmitter.emit("status", { connected: false });
1553
1597
  setTimeout(() => connectToServer2(serverUrl), 5e3);
1554
1598
  });
1555
1599
  ws.on("error", (error) => {
1556
1600
  console.error(pc4.red(`WebSocket error: ${error.message}`));
1601
+ statusEmitter.emit("status", { connected: false });
1557
1602
  });
1558
1603
  return ws;
1559
1604
  }
@@ -1750,7 +1795,7 @@ function getDaemonPid() {
1750
1795
  return null;
1751
1796
  }
1752
1797
  }
1753
- var VERSION = "0.0.2";
1798
+ var VERSION = "0.0.3";
1754
1799
  var PROJECT_DIR = process.cwd();
1755
1800
  function promptUser(question) {
1756
1801
  const rl = readline.createInterface({
@@ -2,6 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  var WebSocket = require('ws');
5
+ var events = require('events');
5
6
  var zod = require('zod');
6
7
  var promises = require('fs/promises');
7
8
  var path9 = require('path');
@@ -1256,10 +1257,50 @@ var startHttpServer = (connection) => {
1256
1257
  }
1257
1258
  const app = new hono.Hono();
1258
1259
  app.use(cors.cors());
1259
- app.post("/daemon/status/stream", (c) => {
1260
+ app.post("/daemon/status", (c) => {
1260
1261
  const status = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1261
1262
  return c.json({ connected: status === "open" });
1262
1263
  });
1264
+ app.get("/daemon/status/stream", (c) => {
1265
+ const encoder = new TextEncoder();
1266
+ const stream = new ReadableStream({
1267
+ start(controller) {
1268
+ const initialStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1269
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: initialStatus === "open" })}
1270
+
1271
+ `));
1272
+ const statusHandler = (data) => {
1273
+ try {
1274
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}
1275
+
1276
+ `));
1277
+ } catch {
1278
+ }
1279
+ };
1280
+ statusEmitter.on("status", statusHandler);
1281
+ const heartbeatInterval = setInterval(() => {
1282
+ try {
1283
+ const currentStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1284
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: currentStatus === "open" })}
1285
+
1286
+ `));
1287
+ } catch {
1288
+ }
1289
+ }, 15e3);
1290
+ c.req.raw.signal.addEventListener("abort", () => {
1291
+ statusEmitter.off("status", statusHandler);
1292
+ clearInterval(heartbeatInterval);
1293
+ });
1294
+ }
1295
+ });
1296
+ return new Response(stream, {
1297
+ headers: {
1298
+ "Content-Type": "text/event-stream",
1299
+ "Cache-Control": "no-cache",
1300
+ "Connection": "keep-alive"
1301
+ }
1302
+ });
1303
+ });
1263
1304
  app.get("context", async (c) => {
1264
1305
  const context = getContext(process.cwd());
1265
1306
  return c.body(JSON.stringify(context));
@@ -1363,6 +1404,7 @@ function getTokens() {
1363
1404
  }
1364
1405
 
1365
1406
  // src/server.ts
1407
+ var statusEmitter = new events.EventEmitter();
1366
1408
  var toolExecutors = {
1367
1409
  editFile: editFiles,
1368
1410
  deleteFile,
@@ -1388,6 +1430,7 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
1388
1430
  });
1389
1431
  ws.on("open", () => {
1390
1432
  console.log(pc2__default.default.green("Connected to server agent streams"));
1433
+ statusEmitter.emit("status", { connected: true });
1391
1434
  });
1392
1435
  ws.on("message", async (data) => {
1393
1436
  const message = JSON.parse(data.toString());
@@ -1417,10 +1460,12 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
1417
1460
  });
1418
1461
  ws.on("close", () => {
1419
1462
  console.log(pc2__default.default.red("Disconnected from server. Reconnecting in 5s..."));
1463
+ statusEmitter.emit("status", { connected: false });
1420
1464
  setTimeout(() => connectToServer2(serverUrl), 5e3);
1421
1465
  });
1422
1466
  ws.on("error", (error) => {
1423
1467
  console.error(pc2__default.default.red(`WebSocket error: ${error.message}`));
1468
+ statusEmitter.emit("status", { connected: false });
1424
1469
  });
1425
1470
  return ws;
1426
1471
  }
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import WebSocket from 'ws';
3
+ import { EventEmitter } from 'events';
3
4
  import { z } from 'zod';
4
5
  import { readFile, writeFile, stat, access, readdir, glob, unlink, mkdir } from 'fs/promises';
5
6
  import path9 from 'path';
@@ -1246,10 +1247,50 @@ var startHttpServer = (connection) => {
1246
1247
  }
1247
1248
  const app = new Hono();
1248
1249
  app.use(cors());
1249
- app.post("/daemon/status/stream", (c) => {
1250
+ app.post("/daemon/status", (c) => {
1250
1251
  const status = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1251
1252
  return c.json({ connected: status === "open" });
1252
1253
  });
1254
+ app.get("/daemon/status/stream", (c) => {
1255
+ const encoder = new TextEncoder();
1256
+ const stream = new ReadableStream({
1257
+ start(controller) {
1258
+ const initialStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1259
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: initialStatus === "open" })}
1260
+
1261
+ `));
1262
+ const statusHandler = (data) => {
1263
+ try {
1264
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}
1265
+
1266
+ `));
1267
+ } catch {
1268
+ }
1269
+ };
1270
+ statusEmitter.on("status", statusHandler);
1271
+ const heartbeatInterval = setInterval(() => {
1272
+ try {
1273
+ const currentStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1274
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: currentStatus === "open" })}
1275
+
1276
+ `));
1277
+ } catch {
1278
+ }
1279
+ }, 15e3);
1280
+ c.req.raw.signal.addEventListener("abort", () => {
1281
+ statusEmitter.off("status", statusHandler);
1282
+ clearInterval(heartbeatInterval);
1283
+ });
1284
+ }
1285
+ });
1286
+ return new Response(stream, {
1287
+ headers: {
1288
+ "Content-Type": "text/event-stream",
1289
+ "Cache-Control": "no-cache",
1290
+ "Connection": "keep-alive"
1291
+ }
1292
+ });
1293
+ });
1253
1294
  app.get("context", async (c) => {
1254
1295
  const context = getContext(process.cwd());
1255
1296
  return c.body(JSON.stringify(context));
@@ -1353,6 +1394,7 @@ function getTokens() {
1353
1394
  }
1354
1395
 
1355
1396
  // src/server.ts
1397
+ var statusEmitter = new EventEmitter();
1356
1398
  var toolExecutors = {
1357
1399
  editFile: editFiles,
1358
1400
  deleteFile,
@@ -1378,6 +1420,7 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
1378
1420
  });
1379
1421
  ws.on("open", () => {
1380
1422
  console.log(pc2.green("Connected to server agent streams"));
1423
+ statusEmitter.emit("status", { connected: true });
1381
1424
  });
1382
1425
  ws.on("message", async (data) => {
1383
1426
  const message = JSON.parse(data.toString());
@@ -1407,10 +1450,12 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
1407
1450
  });
1408
1451
  ws.on("close", () => {
1409
1452
  console.log(pc2.red("Disconnected from server. Reconnecting in 5s..."));
1453
+ statusEmitter.emit("status", { connected: false });
1410
1454
  setTimeout(() => connectToServer2(serverUrl), 5e3);
1411
1455
  });
1412
1456
  ws.on("error", (error) => {
1413
1457
  console.error(pc2.red(`WebSocket error: ${error.message}`));
1458
+ statusEmitter.emit("status", { connected: false });
1414
1459
  });
1415
1460
  return ws;
1416
1461
  }
package/dist/server.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  var WebSocket = require('ws');
5
+ var events = require('events');
5
6
  var zod = require('zod');
6
7
  var promises = require('fs/promises');
7
8
  var path9 = require('path');
@@ -1256,10 +1257,50 @@ var startHttpServer = (connection) => {
1256
1257
  }
1257
1258
  const app = new hono.Hono();
1258
1259
  app.use(cors.cors());
1259
- app.post("/daemon/status/stream", (c) => {
1260
+ app.post("/daemon/status", (c) => {
1260
1261
  const status = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1261
1262
  return c.json({ connected: status === "open" });
1262
1263
  });
1264
+ app.get("/daemon/status/stream", (c) => {
1265
+ const encoder = new TextEncoder();
1266
+ const stream = new ReadableStream({
1267
+ start(controller) {
1268
+ const initialStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1269
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: initialStatus === "open" })}
1270
+
1271
+ `));
1272
+ const statusHandler = (data) => {
1273
+ try {
1274
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}
1275
+
1276
+ `));
1277
+ } catch {
1278
+ }
1279
+ };
1280
+ statusEmitter.on("status", statusHandler);
1281
+ const heartbeatInterval = setInterval(() => {
1282
+ try {
1283
+ const currentStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1284
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: currentStatus === "open" })}
1285
+
1286
+ `));
1287
+ } catch {
1288
+ }
1289
+ }, 15e3);
1290
+ c.req.raw.signal.addEventListener("abort", () => {
1291
+ statusEmitter.off("status", statusHandler);
1292
+ clearInterval(heartbeatInterval);
1293
+ });
1294
+ }
1295
+ });
1296
+ return new Response(stream, {
1297
+ headers: {
1298
+ "Content-Type": "text/event-stream",
1299
+ "Cache-Control": "no-cache",
1300
+ "Connection": "keep-alive"
1301
+ }
1302
+ });
1303
+ });
1263
1304
  app.get("context", async (c) => {
1264
1305
  const context = getContext(process.cwd());
1265
1306
  return c.body(JSON.stringify(context));
@@ -1363,6 +1404,7 @@ function getTokens() {
1363
1404
  }
1364
1405
 
1365
1406
  // src/server.ts
1407
+ var statusEmitter = new events.EventEmitter();
1366
1408
  var toolExecutors = {
1367
1409
  editFile: editFiles,
1368
1410
  deleteFile,
@@ -1388,6 +1430,7 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
1388
1430
  });
1389
1431
  ws.on("open", () => {
1390
1432
  console.log(pc2__default.default.green("Connected to server agent streams"));
1433
+ statusEmitter.emit("status", { connected: true });
1391
1434
  });
1392
1435
  ws.on("message", async (data) => {
1393
1436
  const message = JSON.parse(data.toString());
@@ -1417,10 +1460,12 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
1417
1460
  });
1418
1461
  ws.on("close", () => {
1419
1462
  console.log(pc2__default.default.red("Disconnected from server. Reconnecting in 5s..."));
1463
+ statusEmitter.emit("status", { connected: false });
1420
1464
  setTimeout(() => connectToServer2(serverUrl), 5e3);
1421
1465
  });
1422
1466
  ws.on("error", (error) => {
1423
1467
  console.error(pc2__default.default.red(`WebSocket error: ${error.message}`));
1468
+ statusEmitter.emit("status", { connected: false });
1424
1469
  });
1425
1470
  return ws;
1426
1471
  }
@@ -1435,3 +1480,4 @@ async function main() {
1435
1480
  exports.connectToServer = connectToServer2;
1436
1481
  exports.getConnectionStatus = getConnectionStatus;
1437
1482
  exports.main = main;
1483
+ exports.statusEmitter = statusEmitter;
package/dist/server.d.cts CHANGED
@@ -1,7 +1,9 @@
1
1
  import WebSocket from 'ws';
2
+ import { EventEmitter } from 'events';
2
3
 
4
+ declare const statusEmitter: EventEmitter<[never]>;
3
5
  declare function getConnectionStatus(ws: WebSocket): 'connecting' | 'open' | 'closing' | 'closed';
4
6
  declare function connectToServer(serverUrl?: string): WebSocket;
5
7
  declare function main(): Promise<void>;
6
8
 
7
- export { connectToServer, getConnectionStatus, main };
9
+ export { connectToServer, getConnectionStatus, main, statusEmitter };
package/dist/server.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import WebSocket from 'ws';
2
+ import { EventEmitter } from 'events';
2
3
 
4
+ declare const statusEmitter: EventEmitter<[never]>;
3
5
  declare function getConnectionStatus(ws: WebSocket): 'connecting' | 'open' | 'closing' | 'closed';
4
6
  declare function connectToServer(serverUrl?: string): WebSocket;
5
7
  declare function main(): Promise<void>;
6
8
 
7
- export { connectToServer, getConnectionStatus, main };
9
+ export { connectToServer, getConnectionStatus, main, statusEmitter };
package/dist/server.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import WebSocket from 'ws';
3
+ import { EventEmitter } from 'events';
3
4
  import { z } from 'zod';
4
5
  import { readFile, writeFile, stat, access, readdir, glob, unlink, mkdir } from 'fs/promises';
5
6
  import path9 from 'path';
@@ -1246,10 +1247,50 @@ var startHttpServer = (connection) => {
1246
1247
  }
1247
1248
  const app = new Hono();
1248
1249
  app.use(cors());
1249
- app.post("/daemon/status/stream", (c) => {
1250
+ app.post("/daemon/status", (c) => {
1250
1251
  const status = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1251
1252
  return c.json({ connected: status === "open" });
1252
1253
  });
1254
+ app.get("/daemon/status/stream", (c) => {
1255
+ const encoder = new TextEncoder();
1256
+ const stream = new ReadableStream({
1257
+ start(controller) {
1258
+ const initialStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1259
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: initialStatus === "open" })}
1260
+
1261
+ `));
1262
+ const statusHandler = (data) => {
1263
+ try {
1264
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}
1265
+
1266
+ `));
1267
+ } catch {
1268
+ }
1269
+ };
1270
+ statusEmitter.on("status", statusHandler);
1271
+ const heartbeatInterval = setInterval(() => {
1272
+ try {
1273
+ const currentStatus = wsConnection ? getConnectionStatus(wsConnection) : "closed";
1274
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify({ connected: currentStatus === "open" })}
1275
+
1276
+ `));
1277
+ } catch {
1278
+ }
1279
+ }, 15e3);
1280
+ c.req.raw.signal.addEventListener("abort", () => {
1281
+ statusEmitter.off("status", statusHandler);
1282
+ clearInterval(heartbeatInterval);
1283
+ });
1284
+ }
1285
+ });
1286
+ return new Response(stream, {
1287
+ headers: {
1288
+ "Content-Type": "text/event-stream",
1289
+ "Cache-Control": "no-cache",
1290
+ "Connection": "keep-alive"
1291
+ }
1292
+ });
1293
+ });
1253
1294
  app.get("context", async (c) => {
1254
1295
  const context = getContext(process.cwd());
1255
1296
  return c.body(JSON.stringify(context));
@@ -1353,6 +1394,7 @@ function getTokens() {
1353
1394
  }
1354
1395
 
1355
1396
  // src/server.ts
1397
+ var statusEmitter = new EventEmitter();
1356
1398
  var toolExecutors = {
1357
1399
  editFile: editFiles,
1358
1400
  deleteFile,
@@ -1378,6 +1420,7 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
1378
1420
  });
1379
1421
  ws.on("open", () => {
1380
1422
  console.log(pc2.green("Connected to server agent streams"));
1423
+ statusEmitter.emit("status", { connected: true });
1381
1424
  });
1382
1425
  ws.on("message", async (data) => {
1383
1426
  const message = JSON.parse(data.toString());
@@ -1407,10 +1450,12 @@ function connectToServer2(serverUrl = DEFAULT_SERVER_URL) {
1407
1450
  });
1408
1451
  ws.on("close", () => {
1409
1452
  console.log(pc2.red("Disconnected from server. Reconnecting in 5s..."));
1453
+ statusEmitter.emit("status", { connected: false });
1410
1454
  setTimeout(() => connectToServer2(serverUrl), 5e3);
1411
1455
  });
1412
1456
  ws.on("error", (error) => {
1413
1457
  console.error(pc2.red(`WebSocket error: ${error.message}`));
1458
+ statusEmitter.emit("status", { connected: false });
1414
1459
  });
1415
1460
  return ws;
1416
1461
  }
@@ -1422,4 +1467,4 @@ async function main() {
1422
1467
  startHttpServer(connection);
1423
1468
  }
1424
1469
 
1425
- export { connectToServer2 as connectToServer, getConnectionStatus, main };
1470
+ export { connectToServer2 as connectToServer, getConnectionStatus, main, statusEmitter };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "amai",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "description": "ama rpc daemon",
6
6
  "keywords": [
7
7
  "ama",