@clawchatsai/connector 0.0.32 → 0.0.34
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.d.ts +1 -1
- package/dist/index.js +41 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Spec: specs/multitenant-p2p.md sections 6.1-6.2
|
|
11
11
|
*/
|
|
12
12
|
export declare const PLUGIN_ID = "connector";
|
|
13
|
-
export declare const PLUGIN_VERSION
|
|
13
|
+
export declare const PLUGIN_VERSION: string;
|
|
14
14
|
interface PluginServiceContext {
|
|
15
15
|
stateDir: string;
|
|
16
16
|
logger: {
|
package/dist/index.js
CHANGED
|
@@ -21,11 +21,15 @@ import { generateSessionSecret } from './session-token.js';
|
|
|
21
21
|
// Inline from shared/api-version.ts to avoid rootDir conflict
|
|
22
22
|
const CURRENT_API_VERSION = 1;
|
|
23
23
|
export const PLUGIN_ID = 'connector';
|
|
24
|
-
|
|
24
|
+
// Read version from package.json so it stays in sync with npm publishes
|
|
25
|
+
const _pkgJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', 'package.json'), 'utf-8'));
|
|
26
|
+
export const PLUGIN_VERSION = _pkgJson.version;
|
|
25
27
|
/** Max DataChannel message size (~256KB, leave room for envelope) */
|
|
26
28
|
const MAX_DC_MESSAGE_SIZE = 256 * 1024;
|
|
27
29
|
/** Active DataChannel connections: connectionId → send function */
|
|
28
30
|
const connectedClients = new Map();
|
|
31
|
+
/** Reassembly buffers for chunked RPC requests from browser (large uploads). */
|
|
32
|
+
const rpcReqChunkBuffers = new Map();
|
|
29
33
|
/** Reassembly buffers for chunked gateway-msg from browser (large payloads like image attachments). */
|
|
30
34
|
const gatewayMsgChunkBuffers = new Map();
|
|
31
35
|
let app = null;
|
|
@@ -413,6 +417,42 @@ function processAuthenticatedMessage(dc, connectionId, msg, ctx) {
|
|
|
413
417
|
case 'rpc':
|
|
414
418
|
handleRpcMessage(dc, msg, ctx);
|
|
415
419
|
break;
|
|
420
|
+
case 'rpc-chunk-req': {
|
|
421
|
+
const chunkId = msg['id'];
|
|
422
|
+
const index = msg['index'];
|
|
423
|
+
const total = msg['total'];
|
|
424
|
+
const chunkData = msg['data'];
|
|
425
|
+
if (!chunkId || typeof index !== 'number' || typeof total !== 'number' || !chunkData) {
|
|
426
|
+
dc.send(JSON.stringify({ type: 'error', message: 'malformed rpc-chunk-req' }));
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
if (!rpcReqChunkBuffers.has(chunkId)) {
|
|
430
|
+
rpcReqChunkBuffers.set(chunkId, {
|
|
431
|
+
chunks: new Array(total),
|
|
432
|
+
received: 0,
|
|
433
|
+
total,
|
|
434
|
+
createdAt: Date.now(),
|
|
435
|
+
});
|
|
436
|
+
setTimeout(() => rpcReqChunkBuffers.delete(chunkId), 30_000);
|
|
437
|
+
}
|
|
438
|
+
const rpcBuf = rpcReqChunkBuffers.get(chunkId);
|
|
439
|
+
if (!rpcBuf.chunks[index]) {
|
|
440
|
+
rpcBuf.chunks[index] = chunkData;
|
|
441
|
+
rpcBuf.received++;
|
|
442
|
+
}
|
|
443
|
+
if (rpcBuf.received === rpcBuf.total) {
|
|
444
|
+
rpcReqChunkBuffers.delete(chunkId);
|
|
445
|
+
const fullMsg = rpcBuf.chunks.join('');
|
|
446
|
+
try {
|
|
447
|
+
const reassembled = JSON.parse(fullMsg);
|
|
448
|
+
handleRpcMessage(dc, reassembled, ctx);
|
|
449
|
+
}
|
|
450
|
+
catch (e) {
|
|
451
|
+
dc.send(JSON.stringify({ type: 'rpc-res', id: chunkId, status: 400, body: { error: 'Failed to reassemble chunked RPC' } }));
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
416
456
|
case 'gateway-msg':
|
|
417
457
|
if (app?.gatewayClient && typeof msg['payload'] === 'string') {
|
|
418
458
|
app.gatewayClient.sendToGateway(msg['payload']);
|