@whoz-oss/coday-web 0.18.7 → 0.18.8

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/package.json CHANGED
@@ -7,5 +7,5 @@
7
7
  "dependencies": {
8
8
  "sharp": "^0.33.5"
9
9
  },
10
- "version": "0.18.7"
10
+ "version": "0.18.8"
11
11
  }
package/server/server.js CHANGED
@@ -116392,7 +116392,7 @@ function debugLog(context, ...args) {
116392
116392
 
116393
116393
  // apps/web/server/server-client.ts
116394
116394
  var ServerClient = class _ServerClient {
116395
- // 10 seconds
116395
+ // 30 seconds (optimized for proxy stability)
116396
116396
  constructor(clientId, response, interactor, options, username, logger2, webhookService2) {
116397
116397
  this.clientId = clientId;
116398
116398
  this.response = response;
@@ -116403,10 +116403,7 @@ var ServerClient = class _ServerClient {
116403
116403
  this.webhookService = webhookService2;
116404
116404
  if (response) {
116405
116405
  this.subscription = this.interactor.events.subscribe((event) => {
116406
- const data = `data: ${JSON.stringify(event)}
116407
-
116408
- `;
116409
- this.response?.write(data);
116406
+ this.writeSSEEvent(event);
116410
116407
  });
116411
116408
  }
116412
116409
  this.heartbeatInterval = setInterval(() => this.sendHeartbeat(), _ServerClient.HEARTBEAT_INTERVAL);
@@ -116417,7 +116414,7 @@ var ServerClient = class _ServerClient {
116417
116414
  coday;
116418
116415
  static SESSION_TIMEOUT = 8 * 60 * 60 * 1e3;
116419
116416
  // 8 hours in milliseconds
116420
- static HEARTBEAT_INTERVAL = 1e4;
116417
+ static HEARTBEAT_INTERVAL = 3e4;
116421
116418
  /**
116422
116419
  * Update client connection with new response object.
116423
116420
  * Called when client reconnects with same clientId.
@@ -116485,7 +116482,10 @@ var ServerClient = class _ServerClient {
116485
116482
  logger: this.logger,
116486
116483
  webhook: this.webhookService
116487
116484
  });
116488
- this.coday.run().finally(() => {
116485
+ this.coday.run().catch((error) => {
116486
+ debugLog("CODAY", `Error during Coday run for client ${this.clientId}:`, error);
116487
+ console.error(`Coday run failed for client ${this.clientId}:`, error);
116488
+ }).finally(() => {
116489
116489
  debugLog("CODAY", `Coday run finished for client ${this.clientId}`);
116490
116490
  this.terminate(true);
116491
116491
  });
@@ -116524,8 +116524,35 @@ var ServerClient = class _ServerClient {
116524
116524
  isExpired() {
116525
116525
  return Date.now() - this.lastConnected >= _ServerClient.SESSION_TIMEOUT;
116526
116526
  }
116527
+ /**
116528
+ * Write an SSE event safely with error handling
116529
+ * @param event The event to write
116530
+ * @returns true if write was successful, false otherwise
116531
+ */
116532
+ writeSSEEvent(event) {
116533
+ try {
116534
+ if (!this.response || this.response.writableEnded) {
116535
+ debugLog("SSE", `Response no longer writable for client ${this.clientId}`);
116536
+ return false;
116537
+ }
116538
+ const data = `data: ${JSON.stringify(event)}
116539
+
116540
+ `;
116541
+ this.response.write(data);
116542
+ return true;
116543
+ } catch (error) {
116544
+ debugLog("SSE", `Error writing event to client ${this.clientId}:`, error);
116545
+ this.terminate();
116546
+ return false;
116547
+ }
116548
+ }
116527
116549
  sendHeartbeat() {
116528
116550
  try {
116551
+ if (!this.response || this.response.writableEnded) {
116552
+ debugLog("HEARTBEAT", `Response no longer writable for client ${this.clientId}, terminating`);
116553
+ this.terminate();
116554
+ return;
116555
+ }
116529
116556
  const heartBeatEvent = new HeartBeatEvent({});
116530
116557
  this.interactor.sendEvent(heartBeatEvent);
116531
116558
  } catch (error) {