@clawchatsai/connector 0.0.97 → 0.0.99

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
@@ -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
- app.gatewayClient.sendToGateway(normalizeGatewayPayload(msg['payload']));
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawchatsai/connector",
3
- "version": "0.0.97",
3
+ "version": "0.0.99",
4
4
  "type": "module",
5
5
  "description": "ClawChats OpenClaw plugin — P2P tunnel + local API bridge",
6
6
  "main": "dist/index.js",
@@ -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
@@ -168,6 +168,12 @@ export class GatewayClient {
168
168
  }
169
169
  if (state === 'aborted') {
170
170
  const parsed = parseSessionKey(sessionKey);
171
+ // Clear pending flag from DB so a stale pending:true doesn't survive page reloads
172
+ // and trigger phantom "thinking..." state on next visit to this thread.
173
+ if (parsed) {
174
+ const db = this.getDb(parsed.workspace);
175
+ if (db) this._clearPendingFlag(db, parsed.threadId);
176
+ }
171
177
  this.broadcastToBrowsers(rawData); // dual-emit
172
178
  if (parsed) {
173
179
  const activity = this._popActivityLogForSession(sessionKey);
@@ -184,6 +190,15 @@ export class GatewayClient {
184
190
  }
185
191
  }
186
192
 
193
+ // Removes metadata.pending flag from any pending assistant message for a thread.
194
+ // Called on abort and by _cleanupSilentPending — keeps the SQL in one place.
195
+ _clearPendingFlag(db, threadId) {
196
+ db.prepare(
197
+ "UPDATE messages SET metadata = json_remove(metadata, '$.pending') " +
198
+ "WHERE thread_id = ? AND role = 'assistant' AND json_extract(metadata, '$.pending') = 1"
199
+ ).run(threadId);
200
+ }
201
+
187
202
  _cleanupSilentPending(sessionKey) {
188
203
  const parsed = parseSessionKey(sessionKey);
189
204
  if (!parsed) return;
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);