@clawchatsai/connector 0.0.95 → 0.0.97
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 +25 -0
- package/package.json +1 -1
- package/server/gateway.js +4 -4
package/dist/index.js
CHANGED
|
@@ -39,6 +39,8 @@ let healthServer = null;
|
|
|
39
39
|
let _stopRequested = false;
|
|
40
40
|
/** Model IDs that have 'input' explicitly set without 'image' support. */
|
|
41
41
|
let _imageRestrictedModels = [];
|
|
42
|
+
/** True if session.reset config risks wiping ClawChats history (daily reset or short idle). */
|
|
43
|
+
let _sessionResetWarning = false;
|
|
42
44
|
let _uploadsDir = null;
|
|
43
45
|
// ---------------------------------------------------------------------------
|
|
44
46
|
// Config helpers
|
|
@@ -174,6 +176,22 @@ async function startClawChats(ctx, api, mediaStash) {
|
|
|
174
176
|
ctx.logger.error('No gateway token available. Re-run: openclaw clawchats setup <token>');
|
|
175
177
|
return;
|
|
176
178
|
}
|
|
179
|
+
// Check session.reset config — warn if daily reset or short idle could wipe ClawChats history.
|
|
180
|
+
_sessionResetWarning = false;
|
|
181
|
+
try {
|
|
182
|
+
const sessionReset = gwCfg?.['session']?.['reset'];
|
|
183
|
+
if (sessionReset) {
|
|
184
|
+
const mode = sessionReset['mode'];
|
|
185
|
+
const idleMinutes = sessionReset['idleMinutes'];
|
|
186
|
+
if (mode === 'daily' || (mode === 'idle' && typeof idleMinutes === 'number' && idleMinutes < 43200)) {
|
|
187
|
+
_sessionResetWarning = true;
|
|
188
|
+
ctx.logger.warn(`[clawchats] session.reset may wipe chat history (mode=${mode}, idleMinutes=${idleMinutes ?? 'unset'}) — set mode=idle + idleMinutes=999999`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
// Non-fatal
|
|
194
|
+
}
|
|
177
195
|
// Check for model definitions with 'input' set but missing 'image' — they silently drop attachments.
|
|
178
196
|
_imageRestrictedModels = [];
|
|
179
197
|
try {
|
|
@@ -489,6 +507,13 @@ function setupDataChannelHandler(dc, connectionId, ctx) {
|
|
|
489
507
|
payload: JSON.stringify({ type: 'clawchats', event: 'image-capability-warning', models: _imageRestrictedModels }),
|
|
490
508
|
}));
|
|
491
509
|
}
|
|
510
|
+
// Warn if session.reset config risks wiping ClawChats history
|
|
511
|
+
if (_sessionResetWarning) {
|
|
512
|
+
dc.send(JSON.stringify({
|
|
513
|
+
type: 'gateway-event',
|
|
514
|
+
payload: JSON.stringify({ type: 'clawchats', event: 'session-reset-warning' }),
|
|
515
|
+
}));
|
|
516
|
+
}
|
|
492
517
|
// Persist backup code changes if any were consumed
|
|
493
518
|
if (authConfig.backupCodeHashes && config.backupCodeHashes) {
|
|
494
519
|
config.backupCodeHashes = authConfig.backupCodeHashes;
|
package/package.json
CHANGED
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); }
|