@clawchatsai/connector 0.2.1 → 0.2.2
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 +8 -0
- package/package.json +1 -1
- package/server/gateway.js +23 -1
- package/server/gateway.test.js +16 -1
- package/server/session-lens.js +2 -0
- package/server/session-lens.test.js +18 -0
package/dist/index.js
CHANGED
|
@@ -648,6 +648,14 @@ function setupDataChannelHandler(dc, connectionId, ctx, dtls) {
|
|
|
648
648
|
}
|
|
649
649
|
connectedClients.set(connectionId, dc);
|
|
650
650
|
ctx.logger.info(`Browser authenticated: ${connectionId} (${label})`);
|
|
651
|
+
// The gateway's chat attachment limits (its hello-ok policy), which this browser checks files against.
|
|
652
|
+
const limits = app?.gatewayClient?.attachmentLimitsFrame();
|
|
653
|
+
if (limits) {
|
|
654
|
+
try {
|
|
655
|
+
dc.send(JSON.stringify({ type: 'gateway-event', payload: limits }));
|
|
656
|
+
}
|
|
657
|
+
catch { /* closed */ }
|
|
658
|
+
}
|
|
651
659
|
},
|
|
652
660
|
onMessage: (msg) => processAuthenticatedMessage(dc, connectionId, msg, ctx),
|
|
653
661
|
onLoginFailure: (reason) => {
|
package/package.json
CHANGED
package/server/gateway.js
CHANGED
|
@@ -24,6 +24,21 @@ export function gatewayError(error, fallback) {
|
|
|
24
24
|
return err;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* The chat attachment limits a 2026.11+ gateway advertises in hello-ok (policy.attachments: maxBytes,
|
|
29
|
+
* maxImageBytes) plus one send's byte budget, which has to fit a single frame: the Control UI's
|
|
30
|
+
* resolveChatAttachmentLimits (chat-attachment-admission.ts) and chat-attachment-frame-budget.ts.
|
|
31
|
+
* Null when the gateway doesn't say (older versions): then only the gateway itself checks.
|
|
32
|
+
*/
|
|
33
|
+
export function attachmentLimitsOf(hello) {
|
|
34
|
+
const policy = hello?.policy;
|
|
35
|
+
const a = policy?.attachments;
|
|
36
|
+
if (!a || !(a.maxBytes > 0)) return null;
|
|
37
|
+
const maxImageBytes = a.maxImageBytes > 0 ? Math.min(a.maxImageBytes, a.maxBytes) : a.maxBytes;
|
|
38
|
+
const maxBatchBytes = policy.maxPayload > 0 ? Math.max(0, Math.floor(((policy.maxPayload - 256 * 1024) * 3) / 4)) : null;
|
|
39
|
+
return { maxBytes: a.maxBytes, maxImageBytes, ...(maxBatchBytes ? { maxBatchBytes } : {}) };
|
|
40
|
+
}
|
|
41
|
+
|
|
27
42
|
export class GatewayClient {
|
|
28
43
|
constructor({ dataDir, debugLogger, gatewayWsUrl, authToken, approvalClientGraceMs = APPROVAL_CLIENT_GRACE_MS }) {
|
|
29
44
|
this.dataDir = dataDir;
|
|
@@ -120,7 +135,7 @@ export class GatewayClient {
|
|
|
120
135
|
this.ws.send(JSON.stringify({ type: 'req', id: 'gw-connect-1', method: 'connect', params: this._connectParams(msg.payload?.nonce || '', ['tool-events', 'chat-queue-status']) }));
|
|
121
136
|
return;
|
|
122
137
|
}
|
|
123
|
-
if (msg.type === 'res' && msg.payload?.type === 'hello-ok') { console.log('Gateway handshake complete'); this.connected = true; this.broadcastGatewayStatus(true); this.sync?.onConnected(); this.onConnected?.(); this.request('sessions.subscribe', {}).catch(e => console.warn(`[lens] sessions.subscribe failed: ${e.message}`)); this.lens?.seedWithRetry(); }
|
|
138
|
+
if (msg.type === 'res' && msg.payload?.type === 'hello-ok') { console.log('Gateway handshake complete'); this.connected = true; this.attachmentLimits = attachmentLimitsOf(msg.payload); this.broadcastGatewayStatus(true); if (this.attachmentLimits) this.broadcastToBrowsers(this.attachmentLimitsFrame()); this.sync?.onConnected(); this.onConnected?.(); this.request('sessions.subscribe', {}).catch(e => console.warn(`[lens] sessions.subscribe failed: ${e.message}`)); this.lens?.seedWithRetry(); }
|
|
124
139
|
// Session events arrive through the connector's own subscription; the lens filters them
|
|
125
140
|
// for the browser (session.message only for chats a browser subscribed to).
|
|
126
141
|
if (msg.type === 'event' && (msg.event === 'sessions.changed' || msg.event === 'session.message')) {
|
|
@@ -163,6 +178,11 @@ export class GatewayClient {
|
|
|
163
178
|
this.broadcastToBrowsers(JSON.stringify({ type: 'clawchats', event: 'gateway-status', connected }));
|
|
164
179
|
}
|
|
165
180
|
|
|
181
|
+
/** The gateway's attachment limits for browsers (sent on each hello-ok and to a browser that joins); null if unknown. */
|
|
182
|
+
attachmentLimitsFrame() {
|
|
183
|
+
return this.attachmentLimits ? JSON.stringify({ type: 'clawchats', event: 'attachment-limits', limits: this.attachmentLimits }) : null;
|
|
184
|
+
}
|
|
185
|
+
|
|
166
186
|
/** A frame from a browser: the lens may rewrite it or answer it itself. */
|
|
167
187
|
forwardFromBrowser(data) {
|
|
168
188
|
const out = this.lens ? this.lens.outbound(data) : data;
|
|
@@ -214,6 +234,8 @@ export class GatewayClient {
|
|
|
214
234
|
this.browsersChanged();
|
|
215
235
|
if (ws.readyState === WS.OPEN) {
|
|
216
236
|
ws.send(JSON.stringify({ type: 'clawchats', event: 'gateway-status', connected: this.connected }));
|
|
237
|
+
const limits = this.attachmentLimitsFrame();
|
|
238
|
+
if (limits) ws.send(limits);
|
|
217
239
|
}
|
|
218
240
|
}
|
|
219
241
|
|
package/server/gateway.test.js
CHANGED
|
@@ -4,7 +4,7 @@ import os from 'node:os';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import assert from 'node:assert/strict';
|
|
6
6
|
import { WebSocketServer } from 'ws';
|
|
7
|
-
import { GatewayClient } from './gateway.js';
|
|
7
|
+
import { GatewayClient, attachmentLimitsOf } from './gateway.js';
|
|
8
8
|
|
|
9
9
|
const logger = { logFrame() {} };
|
|
10
10
|
|
|
@@ -69,3 +69,18 @@ test('request() keeps the error fields the gateway sends (gatewayCode, retryable
|
|
|
69
69
|
await new Promise(r => wss.close(r));
|
|
70
70
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
71
71
|
});
|
|
72
|
+
|
|
73
|
+
test('attachment limits come from hello-ok policy (2026.11+); older gateways name none', () => {
|
|
74
|
+
const hello = { type: 'hello-ok', policy: { maxPayload: 25 * 1024 * 1024, attachments: { maxBytes: 20 * 1024 * 1024, maxImageBytes: 6 * 1024 * 1024 } } };
|
|
75
|
+
assert.deepEqual(attachmentLimitsOf(hello), { maxBytes: 20971520, maxImageBytes: 6291456, maxBatchBytes: Math.floor(((25 * 1024 * 1024 - 256 * 1024) * 3) / 4) });
|
|
76
|
+
assert.equal(attachmentLimitsOf({ type: 'hello-ok' }), null);
|
|
77
|
+
assert.equal(attachmentLimitsOf({ type: 'hello-ok', policy: { maxPayload: 1 } }), null);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('browsers hear the attachment limits once the gateway named them', () => {
|
|
81
|
+
const gw = new GatewayClient({ dataDir: '/tmp', debugLogger: logger, gatewayWsUrl: 'ws://127.0.0.1:1', authToken: '' });
|
|
82
|
+
assert.equal(gw.attachmentLimitsFrame(), null);
|
|
83
|
+
gw.attachmentLimits = { maxBytes: 10, maxImageBytes: 5 };
|
|
84
|
+
assert.deepEqual(JSON.parse(gw.attachmentLimitsFrame()), { type: 'clawchats', event: 'attachment-limits', limits: { maxBytes: 10, maxImageBytes: 5 } });
|
|
85
|
+
gw.close();
|
|
86
|
+
});
|
package/server/session-lens.js
CHANGED
|
@@ -40,6 +40,8 @@ export const ROW_FIELDS = new Set([
|
|
|
40
40
|
'model', 'modelProvider', 'thinkingLevel', 'contextTokens', 'totalTokens', 'totalTokensFresh',
|
|
41
41
|
'inputTokens', 'outputTokens', 'permissionMode', 'workspaceDir', 'contextBudgetStatus', 'fastMode', 'effectiveFastMode',
|
|
42
42
|
'startedAt', 'runtimeMs', 'ccParentKey',
|
|
43
|
+
// Subagents panel: a run waiting on its own runs, and the run's live headline.
|
|
44
|
+
'hasActiveSubagentRun', 'observerDigest',
|
|
43
45
|
]);
|
|
44
46
|
|
|
45
47
|
// `sessions.changed` envelope fields (snapshot fields are spread next to these).
|
|
@@ -147,6 +147,24 @@ test('trimRow keeps only allow-listed fields', () => {
|
|
|
147
147
|
assert.deepEqual(trimRow({ key: 'k', unread: true, participants: [], thinkingOptions: [] }), { key: 'k', unread: true });
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
+
test('trimRow keeps the Subagents panel fields (waiting on own runs, live headline)', () => {
|
|
151
|
+
const digest = { runId: 'r1', headline: 'Reading files', revision: 3 };
|
|
152
|
+
assert.deepEqual(trimRow({ key: 'k', hasActiveSubagentRun: true, observerDigest: digest, spawnDepth: 1 }),
|
|
153
|
+
{ key: 'k', hasActiveSubagentRun: true, observerDigest: digest });
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('a hidden run under a chat reaches the browser with its panel fields and parent', () => {
|
|
157
|
+
const { l } = lens();
|
|
158
|
+
l.observe(CHAT, { key: CHAT, kind: 'direct' });
|
|
159
|
+
const run = 'agent:main:subagent:w1';
|
|
160
|
+
const out = l.sessionsChanged({ sessionKey: run, reason: 'patch', session: { key: run, kind: 'direct', spawnedBy: CHAT,
|
|
161
|
+
status: 'running', hasActiveRun: true, activeRunIds: ['r1'], hasActiveSubagentRun: true, observerDigest: { runId: 'r1', headline: 'Grep' }, startedAt: 5 } });
|
|
162
|
+
assert.equal(out.payload.session.ccParentKey, CHAT);
|
|
163
|
+
assert.equal(out.payload.session.hasActiveSubagentRun, true);
|
|
164
|
+
assert.deepEqual(out.payload.session.observerDigest, { runId: 'r1', headline: 'Grep' });
|
|
165
|
+
assert.equal(out.payload.session.startedAt, 5);
|
|
166
|
+
});
|
|
167
|
+
|
|
150
168
|
test('chat.history passes through untouched (gateway enforces maxBytes)', () => {
|
|
151
169
|
const { l } = lens();
|
|
152
170
|
const f = JSON.stringify({ type: 'req', id: 'h', method: 'chat.history', params: { sessionKey: CHAT, limit: 80, maxBytes: 262144 } });
|