@clawchatsai/connector 0.0.98 → 0.1.0
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/package.json +1 -1
- package/server/gateway.js +15 -0
- package/server/index.js +8 -0
package/package.json
CHANGED
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
|
@@ -22,6 +22,7 @@ import { handleStatic } from './controllers/static.js';
|
|
|
22
22
|
import { handleAgents } from './controllers/agents.js';
|
|
23
23
|
import { createSettingsHandlers } from './controllers/settings.js';
|
|
24
24
|
import { createWorkspaceStore } from './store/workspace-store.js';
|
|
25
|
+
import { cleanGatewaySession } from './gateway-cleanup.js';
|
|
25
26
|
import { parseSessionKey } from './util/helpers.js';
|
|
26
27
|
import { send, sendError, parseBody, uuid, matchRoute, setCors } from './util/http.js';
|
|
27
28
|
|
|
@@ -241,6 +242,13 @@ export function createApp(config = {}) {
|
|
|
241
242
|
return send(res, 200, { ok: true });
|
|
242
243
|
}
|
|
243
244
|
|
|
245
|
+
if (method === 'POST' && urlPath === '/api/incognito/cleanup') {
|
|
246
|
+
const { sessionKey, threadId } = await parseBody(req);
|
|
247
|
+
if (sessionKey) cleanGatewaySession(sessionKey);
|
|
248
|
+
if (threadId) { try { fs.rmSync(path.join(UPLOADS_DIR, threadId), { recursive: true }); } catch { /* ok */ } }
|
|
249
|
+
return send(res, 200, { ok: true });
|
|
250
|
+
}
|
|
251
|
+
|
|
244
252
|
sendError(res, 404, `Not found: ${method} ${urlPath}`);
|
|
245
253
|
} catch (err) {
|
|
246
254
|
console.error(`Error handling ${method} ${urlPath}:`, err);
|