modality-kit 0.9.5 → 0.10.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.
package/dist/index.js
CHANGED
|
@@ -5659,6 +5659,8 @@ var logger3 = getLoggerInstance("WebSocket-Client");
|
|
|
5659
5659
|
|
|
5660
5660
|
class WebSocketClient {
|
|
5661
5661
|
ws = null;
|
|
5662
|
+
wsStream = null;
|
|
5663
|
+
streamWriter = null;
|
|
5662
5664
|
url;
|
|
5663
5665
|
config = {
|
|
5664
5666
|
initialReconnectDelay: 1000,
|
|
@@ -5742,24 +5744,60 @@ class WebSocketClient {
|
|
|
5742
5744
|
const url = new URL(this.url);
|
|
5743
5745
|
return url.searchParams.get("clientId") ?? (this.connectionId ? String(this.connectionId) : "");
|
|
5744
5746
|
}
|
|
5745
|
-
|
|
5746
|
-
if (
|
|
5747
|
+
async initializeWebSocketStream() {
|
|
5748
|
+
if (typeof WebSocketStream === "undefined") {
|
|
5749
|
+
logger3.warn("WebSocketStream not supported in this environment");
|
|
5750
|
+
return false;
|
|
5751
|
+
}
|
|
5752
|
+
try {
|
|
5753
|
+
this.wsStream = new WebSocketStream(this.url);
|
|
5754
|
+
const { writable } = await this.wsStream.opened;
|
|
5755
|
+
this.streamWriter = writable.getWriter();
|
|
5756
|
+
logger3.info("WebSocketStream initialized successfully");
|
|
5757
|
+
return true;
|
|
5758
|
+
} catch (error) {
|
|
5759
|
+
logger3.error("Failed to initialize WebSocketStream:", error);
|
|
5760
|
+
this.wsStream = null;
|
|
5761
|
+
this.streamWriter = null;
|
|
5762
|
+
return false;
|
|
5763
|
+
}
|
|
5764
|
+
}
|
|
5765
|
+
async send(data, useStream = false) {
|
|
5766
|
+
const message = JSON.stringify({
|
|
5767
|
+
...data,
|
|
5768
|
+
jsonrpc: "2.0",
|
|
5769
|
+
timestamp: new Date().toISOString()
|
|
5770
|
+
});
|
|
5771
|
+
if (useStream) {
|
|
5772
|
+
if (!this.streamWriter) {
|
|
5773
|
+
const streamInitialized = await this.initializeWebSocketStream();
|
|
5774
|
+
if (!streamInitialized) {
|
|
5775
|
+
logger3.warn("WebSocketStream not available, cannot send with streaming");
|
|
5776
|
+
return false;
|
|
5777
|
+
}
|
|
5778
|
+
}
|
|
5747
5779
|
try {
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
jsonrpc: "2.0",
|
|
5751
|
-
timestamp: new Date().toISOString()
|
|
5752
|
-
});
|
|
5753
|
-
this.ws.send(message);
|
|
5754
|
-
logger3.info("Message sent:", message);
|
|
5780
|
+
await this.streamWriter.write(message);
|
|
5781
|
+
logger3.info("Message sent via WebSocketStream:", message);
|
|
5755
5782
|
return true;
|
|
5756
5783
|
} catch (error) {
|
|
5757
|
-
logger3.error("Error sending
|
|
5784
|
+
logger3.error("Error sending via WebSocketStream:", error);
|
|
5758
5785
|
return false;
|
|
5759
5786
|
}
|
|
5760
5787
|
} else {
|
|
5761
|
-
|
|
5762
|
-
|
|
5788
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
5789
|
+
try {
|
|
5790
|
+
this.ws.send(message);
|
|
5791
|
+
logger3.info("Message sent:", message);
|
|
5792
|
+
return true;
|
|
5793
|
+
} catch (error) {
|
|
5794
|
+
logger3.error("Error sending message:", error);
|
|
5795
|
+
return false;
|
|
5796
|
+
}
|
|
5797
|
+
} else {
|
|
5798
|
+
logger3.warn("WebSocket is not connected during send operation.");
|
|
5799
|
+
return false;
|
|
5800
|
+
}
|
|
5763
5801
|
}
|
|
5764
5802
|
}
|
|
5765
5803
|
isConnected() {
|
|
@@ -5848,6 +5886,41 @@ class WebSocketClient {
|
|
|
5848
5886
|
}
|
|
5849
5887
|
}
|
|
5850
5888
|
}
|
|
5889
|
+
// src/lruCache.ts
|
|
5890
|
+
class LruCache {
|
|
5891
|
+
values = new Map;
|
|
5892
|
+
max;
|
|
5893
|
+
constructor(max = 100) {
|
|
5894
|
+
this.max = max;
|
|
5895
|
+
}
|
|
5896
|
+
has(key) {
|
|
5897
|
+
return this.values.has(key);
|
|
5898
|
+
}
|
|
5899
|
+
get(key) {
|
|
5900
|
+
const value = this.values.get(key);
|
|
5901
|
+
if (value) {
|
|
5902
|
+
this.values.delete(key);
|
|
5903
|
+
this.values.set(key, value);
|
|
5904
|
+
}
|
|
5905
|
+
return value;
|
|
5906
|
+
}
|
|
5907
|
+
set(key, value) {
|
|
5908
|
+
if (this.values.size >= this.max) {
|
|
5909
|
+
const itemsToEvictCount = Math.max(1, Math.floor(this.max * 0.25));
|
|
5910
|
+
const keys = this.values.keys();
|
|
5911
|
+
let count = 0;
|
|
5912
|
+
while (count < itemsToEvictCount) {
|
|
5913
|
+
const next = keys.next();
|
|
5914
|
+
if (next.done) {
|
|
5915
|
+
break;
|
|
5916
|
+
}
|
|
5917
|
+
this.values.delete(next.value);
|
|
5918
|
+
count++;
|
|
5919
|
+
}
|
|
5920
|
+
}
|
|
5921
|
+
this.values.set(key, value);
|
|
5922
|
+
}
|
|
5923
|
+
}
|
|
5851
5924
|
export {
|
|
5852
5925
|
withErrorHandling,
|
|
5853
5926
|
setupAITools,
|
|
@@ -5860,6 +5933,7 @@ export {
|
|
|
5860
5933
|
compressWithLanguageDetection as compressText,
|
|
5861
5934
|
WebSocketClient,
|
|
5862
5935
|
exports_schemas_symbol as SymbolTypes,
|
|
5936
|
+
LruCache,
|
|
5863
5937
|
JSONRPCUtils,
|
|
5864
5938
|
JSONRPCManager,
|
|
5865
5939
|
JSONRPCErrorCode,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,3 +15,4 @@ export type { JSONRPCMessage, JSONRPCRequest, JSONRPCNotification, JSONRPCRespon
|
|
|
15
15
|
export { JSONRPCManager } from "./jsonrpc-manager";
|
|
16
16
|
export type { JSONRPCManagerEvents, JSONRPCManagerConfig, } from "./jsonrpc-manager";
|
|
17
17
|
export { WebSocketClient } from "./websocket-client";
|
|
18
|
+
export { LruCache } from "./lruCache";
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import type { JSONRPCValidationResult } from "./schemas/jsonrpc";
|
|
2
|
+
declare global {
|
|
3
|
+
interface WebSocketStream {
|
|
4
|
+
readonly opened: Promise<{
|
|
5
|
+
readable: ReadableStream;
|
|
6
|
+
writable: WritableStream;
|
|
7
|
+
}>;
|
|
8
|
+
readonly closed: Promise<void>;
|
|
9
|
+
close(code?: number, reason?: string): void;
|
|
10
|
+
}
|
|
11
|
+
const WebSocketStream: {
|
|
12
|
+
new (url: string): WebSocketStream;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
2
15
|
interface WebSocketConfig {
|
|
3
16
|
maxReconnectAttempts: number;
|
|
4
17
|
initialReconnectDelay: number;
|
|
@@ -18,6 +31,8 @@ interface WebSocketInfo {
|
|
|
18
31
|
}
|
|
19
32
|
export declare class WebSocketClient {
|
|
20
33
|
private ws;
|
|
34
|
+
private wsStream;
|
|
35
|
+
private streamWriter;
|
|
21
36
|
private url;
|
|
22
37
|
private config;
|
|
23
38
|
private connectionId;
|
|
@@ -35,7 +50,8 @@ export declare class WebSocketClient {
|
|
|
35
50
|
private onOpen;
|
|
36
51
|
private onClose;
|
|
37
52
|
private getClientId;
|
|
38
|
-
|
|
53
|
+
private initializeWebSocketStream;
|
|
54
|
+
send(data: any, useStream?: boolean): Promise<boolean>;
|
|
39
55
|
isConnected(): boolean;
|
|
40
56
|
getInfo(): WebSocketInfo;
|
|
41
57
|
/**
|
package/package.json
CHANGED