@clawchatsai/connector 0.0.96 → 0.0.98
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 +12 -1
- package/package.json +1 -1
- package/server/controllers/threads.js +1 -0
- package/server/gateway.js +4 -4
- package/server/index.js +1 -0
package/dist/index.js
CHANGED
|
@@ -613,7 +613,18 @@ function processAuthenticatedMessage(dc, connectionId, msg, ctx) {
|
|
|
613
613
|
}
|
|
614
614
|
case 'gateway-msg':
|
|
615
615
|
if (app?.gatewayClient && typeof msg['payload'] === 'string') {
|
|
616
|
-
|
|
616
|
+
const _gwPayload = msg['payload'];
|
|
617
|
+
// Persist model when sessions.patch is called
|
|
618
|
+
try {
|
|
619
|
+
const _gwMsg = JSON.parse(_gwPayload);
|
|
620
|
+
if (_gwMsg.method === 'sessions.patch' && _gwMsg.params?.model && _gwMsg.params?.key) {
|
|
621
|
+
const _db = app.getActiveDb();
|
|
622
|
+
_db.prepare('UPDATE threads SET model = ?, updated_at = ? WHERE session_key = ?')
|
|
623
|
+
.run(_gwMsg.params.model, Date.now(), _gwMsg.params.key);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
catch { /* ignore parse/db errors */ }
|
|
627
|
+
app.gatewayClient.sendToGateway(normalizeGatewayPayload(_gwPayload));
|
|
617
628
|
}
|
|
618
629
|
break;
|
|
619
630
|
case 'gateway-msg-chunk': {
|
package/package.json
CHANGED
|
@@ -86,6 +86,7 @@ export class ThreadController {
|
|
|
86
86
|
if (body.pinned !== undefined) { fields.push('pinned = ?'); values.push(body.pinned ? 1 : 0); }
|
|
87
87
|
if (body.pin_order !== undefined) { fields.push('pin_order = ?'); values.push(body.pin_order); }
|
|
88
88
|
if (body.sort_order !== undefined) { fields.push('sort_order = ?'); values.push(body.sort_order); }
|
|
89
|
+
if (body.metadata !== undefined) { fields.push('metadata = ?'); values.push(typeof body.metadata === 'string' ? body.metadata : JSON.stringify(body.metadata)); }
|
|
89
90
|
if (fields.length) {
|
|
90
91
|
fields.push('updated_at = ?');
|
|
91
92
|
values.push(Date.now(), params.id);
|
package/server/gateway.js
CHANGED
|
@@ -80,7 +80,7 @@ export class GatewayClient {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
handleChatEvent(params, rawData) {
|
|
83
|
-
const { sessionKey, state, message, seq } = params;
|
|
83
|
+
const { sessionKey, state, message, seq, errorMessage: gwErrorMessage } = params;
|
|
84
84
|
const bareSessionKey = sessionKey.replace(/^agent:[^:]+:/, '');
|
|
85
85
|
|
|
86
86
|
// --- Utility session routing (connector-side) ---
|
|
@@ -95,7 +95,7 @@ export class GatewayClient {
|
|
|
95
95
|
} else if (state === 'final' || state === 'aborted') {
|
|
96
96
|
if (content) this.broadcastToBrowsers(JSON.stringify({ type: 'clawchats', event: 'utility-response', session: utilityName, state: state === 'final' ? 'final' : 'aborted', content }));
|
|
97
97
|
} else if (state === 'error') {
|
|
98
|
-
this.broadcastToBrowsers(JSON.stringify({ type: 'clawchats', event: 'utility-response', session: utilityName, state: 'error', errorMessage: message?.error || 'Unknown error' }));
|
|
98
|
+
this.broadcastToBrowsers(JSON.stringify({ type: 'clawchats', event: 'utility-response', session: utilityName, state: 'error', errorMessage: gwErrorMessage || message?.error || message?.content || 'Unknown error' }));
|
|
99
99
|
}
|
|
100
100
|
this.broadcastToBrowsers(rawData); // dual-emit: browser guard skips raw handling for utility sessions
|
|
101
101
|
return;
|
|
@@ -179,7 +179,7 @@ export class GatewayClient {
|
|
|
179
179
|
this.broadcastToBrowsers(rawData); // dual-emit
|
|
180
180
|
if (parsed) {
|
|
181
181
|
const activity = this._popActivityLogForSession(sessionKey);
|
|
182
|
-
this.broadcastToBrowsers(JSON.stringify({ type: 'clawchats', event: 'streaming-end', threadId: parsed.threadId, workspace: parsed.workspace, reason: 'error', errorMessage: message?.error || 'Unknown error', ...(activity || {}) }));
|
|
182
|
+
this.broadcastToBrowsers(JSON.stringify({ type: 'clawchats', event: 'streaming-end', threadId: parsed.threadId, workspace: parsed.workspace, reason: 'error', errorMessage: gwErrorMessage || message?.error || message?.content || 'Unknown error', ...(activity || {}) }));
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
}
|
|
@@ -271,7 +271,7 @@ export class GatewayClient {
|
|
|
271
271
|
if (!db.prepare('SELECT id FROM threads WHERE id = ?').get(parsed.threadId)) return;
|
|
272
272
|
const now = Date.now();
|
|
273
273
|
try {
|
|
274
|
-
db.prepare('INSERT INTO messages (id, thread_id, role, content, status, metadata, timestamp, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)').run(`gw-error-${parsed.threadId}-${now}`, parsed.threadId, 'system', `[error] ${message?.error || message?.content || 'Unknown error'}`, 'sent', '{"transient":true}', now, now);
|
|
274
|
+
db.prepare('INSERT INTO messages (id, thread_id, role, content, status, metadata, timestamp, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)').run(`gw-error-${parsed.threadId}-${now}`, parsed.threadId, 'system', `[error] ${gwErrorMessage || message?.error || message?.content || 'Unknown error'}`, 'sent', '{"transient":true}', now, now);
|
|
275
275
|
// Clear stale pending flag so browsers reloading the chat don't re-derive "thinking..." state.
|
|
276
276
|
db.prepare("UPDATE messages SET metadata = json_remove(metadata, '$.pending') WHERE thread_id = ? AND role = 'assistant' AND json_extract(metadata, '$.pending') = 1").run(parsed.threadId);
|
|
277
277
|
} catch (e) { console.error('Failed to save error marker:', e.message); }
|
package/server/index.js
CHANGED
|
@@ -340,6 +340,7 @@ function migrate(db) {
|
|
|
340
340
|
`);
|
|
341
341
|
try { db.exec('ALTER TABLE threads ADD COLUMN sort_order INTEGER DEFAULT 0'); } catch { /* exists */ }
|
|
342
342
|
try { db.exec('ALTER TABLE threads ADD COLUMN unread_count INTEGER DEFAULT 0'); } catch { /* exists */ }
|
|
343
|
+
try { db.prepare('ALTER TABLE threads ADD COLUMN metadata TEXT DEFAULT NULL').run(); } catch {}
|
|
343
344
|
db.exec(`CREATE TABLE IF NOT EXISTS unread_messages (thread_id TEXT NOT NULL, message_id TEXT NOT NULL, created_at INTEGER NOT NULL, PRIMARY KEY (thread_id, message_id), FOREIGN KEY (thread_id) REFERENCES threads(id) ON DELETE CASCADE)`);
|
|
344
345
|
db.exec('CREATE INDEX IF NOT EXISTS idx_unread_thread ON unread_messages(thread_id)');
|
|
345
346
|
ensureFts(db);
|