@creature-ai/sdk 0.1.3 → 0.1.4
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/server/index.js +18 -5
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -13617,13 +13617,22 @@ var WebSocketConnectionInternal = class {
|
|
|
13617
13617
|
};
|
|
13618
13618
|
var WebSocketManager = class {
|
|
13619
13619
|
wss = null;
|
|
13620
|
+
httpServer = null;
|
|
13621
|
+
isAttached = false;
|
|
13620
13622
|
connections = /* @__PURE__ */ new Map();
|
|
13621
13623
|
/**
|
|
13622
|
-
*
|
|
13624
|
+
* Store the HTTP server reference for lazy WebSocket attachment.
|
|
13625
|
+
*/
|
|
13626
|
+
setServer(server) {
|
|
13627
|
+
this.httpServer = server;
|
|
13628
|
+
}
|
|
13629
|
+
/**
|
|
13630
|
+
* Lazily attach the WebSocket server when first needed.
|
|
13623
13631
|
*/
|
|
13624
|
-
|
|
13632
|
+
ensureAttached() {
|
|
13633
|
+
if (this.isAttached || !this.httpServer) return;
|
|
13625
13634
|
this.wss = new WebSocketServer({ noServer: true });
|
|
13626
|
-
|
|
13635
|
+
this.httpServer.on("upgrade", (request, socket, head) => {
|
|
13627
13636
|
const url = request.url || "";
|
|
13628
13637
|
if (!url.startsWith("/ws/")) {
|
|
13629
13638
|
socket.destroy();
|
|
@@ -13662,9 +13671,12 @@ var WebSocketManager = class {
|
|
|
13662
13671
|
connection.removeClient(ws);
|
|
13663
13672
|
});
|
|
13664
13673
|
});
|
|
13674
|
+
this.isAttached = true;
|
|
13675
|
+
console.log(`WebSocket available at ws://localhost:${this.httpServer.address()?.port || "?"}/ws`);
|
|
13665
13676
|
}
|
|
13666
13677
|
/**
|
|
13667
13678
|
* Create a WebSocket connection for an instance.
|
|
13679
|
+
* Lazily initializes the WebSocket server on first call.
|
|
13668
13680
|
*
|
|
13669
13681
|
* @param instanceId - The instance ID
|
|
13670
13682
|
* @param config - WebSocket configuration
|
|
@@ -13672,6 +13684,7 @@ var WebSocketManager = class {
|
|
|
13672
13684
|
* @returns A WebSocketConnection for bidirectional communication
|
|
13673
13685
|
*/
|
|
13674
13686
|
createWebSocket(instanceId, config, port) {
|
|
13687
|
+
this.ensureAttached();
|
|
13675
13688
|
const existing = this.connections.get(instanceId);
|
|
13676
13689
|
if (existing) {
|
|
13677
13690
|
existing.closeAll();
|
|
@@ -13723,6 +13736,7 @@ var WebSocketManager = class {
|
|
|
13723
13736
|
this.wss.close();
|
|
13724
13737
|
this.wss = null;
|
|
13725
13738
|
}
|
|
13739
|
+
this.isAttached = false;
|
|
13726
13740
|
}
|
|
13727
13741
|
};
|
|
13728
13742
|
|
|
@@ -13809,8 +13823,7 @@ var App = class {
|
|
|
13809
13823
|
this.httpServer = expressApp.listen(port, () => {
|
|
13810
13824
|
console.log(`MCP server ready on port ${port}`);
|
|
13811
13825
|
});
|
|
13812
|
-
this.websocketManager.
|
|
13813
|
-
console.log(`WebSocket available at ws://localhost:${port}/ws`);
|
|
13826
|
+
this.websocketManager.setServer(this.httpServer);
|
|
13814
13827
|
this.registerShutdownHandlers();
|
|
13815
13828
|
}
|
|
13816
13829
|
/**
|