@clawchatsai/connector 0.1.23 → 0.1.25
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
CHANGED
package/server/index.js
CHANGED
|
@@ -174,7 +174,7 @@ export function createApp(config = {}) {
|
|
|
174
174
|
}
|
|
175
175
|
if ((p = matchRoute(method, urlPath, 'PUT /api/extras/project-styles/:name'))) {
|
|
176
176
|
const body = await parseBody(req);
|
|
177
|
-
extras.setProjectStyle(p.name, { color: body.color, icon: body.icon });
|
|
177
|
+
extras.setProjectStyle(p.name, { color: body.color, icon: body.icon, preset: body.preset });
|
|
178
178
|
broadcast(JSON.stringify({ type: 'clawchats', event: 'project-styles-changed' }));
|
|
179
179
|
return send(res, 200, { styles: extras.getProjectStyles() });
|
|
180
180
|
}
|
|
@@ -183,6 +183,23 @@ export function createApp(config = {}) {
|
|
|
183
183
|
broadcast(JSON.stringify({ type: 'clawchats', event: 'project-styles-changed' }));
|
|
184
184
|
return send(res, 200, { ok: true });
|
|
185
185
|
}
|
|
186
|
+
if (method === 'GET' && urlPath === '/api/extras/bookmarks') return send(res, 200, { bookmarks: extras.listBookmarks() });
|
|
187
|
+
if (method === 'POST' && urlPath === '/api/extras/bookmarks') {
|
|
188
|
+
const bookmark = extras.addBookmark(uuid(), await parseBody(req));
|
|
189
|
+
if (!bookmark) return sendError(res, 400, 'sessionKey and messageId are required');
|
|
190
|
+
broadcast(JSON.stringify({ type: 'clawchats', event: 'bookmarks-changed' }));
|
|
191
|
+
return send(res, 200, { bookmark });
|
|
192
|
+
}
|
|
193
|
+
if ((p = matchRoute(method, urlPath, 'PATCH /api/extras/bookmarks/:id'))) {
|
|
194
|
+
const bookmark = extras.renameBookmark(p.id, (await parseBody(req)).label);
|
|
195
|
+
if (!bookmark) return sendError(res, 404, 'Bookmark not found, or empty label');
|
|
196
|
+
broadcast(JSON.stringify({ type: 'clawchats', event: 'bookmarks-changed' }));
|
|
197
|
+
return send(res, 200, { bookmark });
|
|
198
|
+
}
|
|
199
|
+
if ((p = matchRoute(method, urlPath, 'DELETE /api/extras/bookmarks/:id'))) {
|
|
200
|
+
if (extras.deleteBookmark(p.id)) broadcast(JSON.stringify({ type: 'clawchats', event: 'bookmarks-changed' }));
|
|
201
|
+
return send(res, 200, { ok: true });
|
|
202
|
+
}
|
|
186
203
|
|
|
187
204
|
|
|
188
205
|
sendError(res, 404, `Not found: ${method} ${urlPath}`);
|
package/server/session-lens.js
CHANGED
|
@@ -29,7 +29,7 @@ export const ROW_FIELDS = new Set([
|
|
|
29
29
|
'createdAt', 'updatedAt', 'lastActivityAt', 'lastInteractionAt',
|
|
30
30
|
'status', 'hasActiveRun', 'activeRunIds', 'lastRunId', 'lastRunError', 'endedAt', 'agentStatus',
|
|
31
31
|
'model', 'modelProvider', 'thinkingLevel', 'contextTokens', 'totalTokens', 'totalTokensFresh',
|
|
32
|
-
'inputTokens', 'outputTokens', 'permissionMode', 'contextBudgetStatus', 'fastMode', 'effectiveFastMode',
|
|
32
|
+
'inputTokens', 'outputTokens', 'permissionMode', 'workspaceDir', 'contextBudgetStatus', 'fastMode', 'effectiveFastMode',
|
|
33
33
|
]);
|
|
34
34
|
|
|
35
35
|
// `sessions.changed` envelope fields (snapshot fields are spread next to these).
|
|
@@ -1,9 +1,43 @@
|
|
|
1
1
|
// ExtrasStore: ClawChats-only data the gateway has no place for. Lives in the global DB.
|
|
2
2
|
// Registry of what belongs here: EXTRAS.md at the repo root.
|
|
3
3
|
//
|
|
4
|
-
// project_styles color/icon per gateway session group (groups are just {name, position})
|
|
4
|
+
// project_styles color/icon and new-chat preset per gateway session group (groups are just {name, position})
|
|
5
5
|
// thread_extras per-session ClawChats data (Intelligence panel etc.), keyed by session key
|
|
6
6
|
// legacy_created creation time of chats from before the gateway recorded createdAt
|
|
7
|
+
// bookmarks messages the user bookmarked, keyed by id; one per (session key, message id)
|
|
8
|
+
|
|
9
|
+
// New-chat preset: what a new chat in the project starts with. Every field is optional;
|
|
10
|
+
// a missing field means the gateway default. `cwd` and `projectId` are exclusive places.
|
|
11
|
+
const PRESET_STRINGS = ['agentId', 'cwd', 'projectId', 'projectLabel', 'permissionMode', 'model', 'thinkingLevel'];
|
|
12
|
+
const PERMISSION_MODES = new Set(['read-only', 'guarded', 'workspace', 'full']);
|
|
13
|
+
|
|
14
|
+
export function cleanPreset(p) {
|
|
15
|
+
if (!p || typeof p !== 'object' || Array.isArray(p)) return null;
|
|
16
|
+
const out = {};
|
|
17
|
+
for (const k of PRESET_STRINGS) {
|
|
18
|
+
if (typeof p[k] === 'string' && p[k].trim()) out[k] = p[k].trim().slice(0, 1000);
|
|
19
|
+
}
|
|
20
|
+
if (out.permissionMode && !PERMISSION_MODES.has(out.permissionMode)) delete out.permissionMode;
|
|
21
|
+
if (out.projectId) delete out.cwd;
|
|
22
|
+
else delete out.projectLabel;
|
|
23
|
+
if (typeof p.fastMode === 'boolean') out.fastMode = p.fastMode;
|
|
24
|
+
return Object.keys(out).length ? out : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function parsePreset(text) {
|
|
28
|
+
if (!text) return null;
|
|
29
|
+
try { return cleanPreset(JSON.parse(text)); } catch { return null; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const str = (v) => typeof v === 'string' && v.trim() ? v.trim() : '';
|
|
33
|
+
const clip = (v, n) => str(v).slice(0, n);
|
|
34
|
+
|
|
35
|
+
function bookmarkRow(r) {
|
|
36
|
+
return {
|
|
37
|
+
id: r.id, sessionKey: r.session_key, messageId: r.message_id, role: r.role, label: r.label,
|
|
38
|
+
snippet: r.snippet, chatTitle: r.chat_title, createdAt: r.created_at, updatedAt: r.updated_at,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
7
41
|
|
|
8
42
|
export function createExtrasStore(getGlobalDb) {
|
|
9
43
|
let ready = false;
|
|
@@ -11,27 +45,32 @@ export function createExtrasStore(getGlobalDb) {
|
|
|
11
45
|
const g = getGlobalDb();
|
|
12
46
|
if (!ready) {
|
|
13
47
|
g.exec(`CREATE TABLE IF NOT EXISTS project_styles (name TEXT PRIMARY KEY, color TEXT, icon TEXT, updated_at INTEGER NOT NULL)`);
|
|
48
|
+
if (!g.prepare('PRAGMA table_info(project_styles)').all().some(c => c.name === 'preset')) g.exec('ALTER TABLE project_styles ADD COLUMN preset TEXT');
|
|
14
49
|
g.exec(`CREATE TABLE IF NOT EXISTS legacy_created (session_key TEXT PRIMARY KEY, created_at INTEGER NOT NULL)`);
|
|
15
50
|
g.exec(`CREATE TABLE IF NOT EXISTS thread_extras (session_key TEXT NOT NULL, kind TEXT NOT NULL, data TEXT NOT NULL, updated_at INTEGER NOT NULL, PRIMARY KEY (session_key, kind))`);
|
|
51
|
+
g.exec(`CREATE TABLE IF NOT EXISTS bookmarks (id TEXT PRIMARY KEY, session_key TEXT NOT NULL, message_id TEXT NOT NULL, role TEXT, label TEXT NOT NULL, snippet TEXT NOT NULL, chat_title TEXT, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL, UNIQUE (session_key, message_id))`);
|
|
16
52
|
ready = true;
|
|
17
53
|
}
|
|
18
54
|
return g;
|
|
19
55
|
}
|
|
20
56
|
|
|
21
57
|
return {
|
|
22
|
-
/** { [groupName]: { color, icon } } */
|
|
58
|
+
/** { [groupName]: { color, icon, preset } } */
|
|
23
59
|
getProjectStyles() {
|
|
24
60
|
const out = {};
|
|
25
|
-
for (const r of db().prepare('SELECT name, color, icon FROM project_styles').all())
|
|
61
|
+
for (const r of db().prepare('SELECT name, color, icon, preset FROM project_styles').all()) {
|
|
62
|
+
out[r.name] = { color: r.color, icon: r.icon, preset: parsePreset(r.preset) };
|
|
63
|
+
}
|
|
26
64
|
return out;
|
|
27
65
|
},
|
|
28
66
|
|
|
29
|
-
/** Set color and/or
|
|
30
|
-
setProjectStyle(name, { color, icon } = {}) {
|
|
67
|
+
/** Set color, icon and/or new-chat preset; absent fields keep their value, null clears. */
|
|
68
|
+
setProjectStyle(name, { color, icon, preset } = {}) {
|
|
31
69
|
if (!name) return;
|
|
32
|
-
const cur = db().prepare('SELECT color, icon FROM project_styles WHERE name = ?').get(name) || {};
|
|
33
|
-
|
|
34
|
-
|
|
70
|
+
const cur = db().prepare('SELECT color, icon, preset FROM project_styles WHERE name = ?').get(name) || {};
|
|
71
|
+
const nextPreset = preset === undefined ? (cur.preset ?? null) : (cleanPreset(preset) ? JSON.stringify(cleanPreset(preset)) : null);
|
|
72
|
+
db().prepare('INSERT INTO project_styles (name, color, icon, preset, updated_at) VALUES (?, ?, ?, ?, ?) ON CONFLICT(name) DO UPDATE SET color = excluded.color, icon = excluded.icon, preset = excluded.preset, updated_at = excluded.updated_at')
|
|
73
|
+
.run(name, color !== undefined ? color : (cur.color ?? null), icon !== undefined ? icon : (cur.icon ?? null), nextPreset, Date.now());
|
|
35
74
|
},
|
|
36
75
|
|
|
37
76
|
renameProjectStyle(from, to) {
|
|
@@ -86,7 +125,36 @@ export function createExtrasStore(getGlobalDb) {
|
|
|
86
125
|
},
|
|
87
126
|
|
|
88
127
|
deleteThreadExtras(sessionKey) {
|
|
89
|
-
if (sessionKey)
|
|
128
|
+
if (!sessionKey) return;
|
|
129
|
+
db().prepare('DELETE FROM thread_extras WHERE session_key = ?').run(sessionKey);
|
|
130
|
+
db().prepare('DELETE FROM bookmarks WHERE session_key = ?').run(sessionKey);
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
/** All bookmarks, newest first. */
|
|
134
|
+
listBookmarks() {
|
|
135
|
+
return db().prepare('SELECT * FROM bookmarks ORDER BY created_at DESC').all().map(bookmarkRow);
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
/** Bookmark a message; bookmarking it again returns the existing bookmark unchanged. */
|
|
139
|
+
addBookmark(id, { sessionKey, messageId, role, label, snippet, chatTitle } = {}) {
|
|
140
|
+
if (!id || !str(sessionKey) || !str(messageId)) return null;
|
|
141
|
+
const now = Date.now();
|
|
142
|
+
db().prepare('INSERT INTO bookmarks (id, session_key, message_id, role, label, snippet, chat_title, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(session_key, message_id) DO NOTHING')
|
|
143
|
+
.run(id, sessionKey, messageId, role === 'user' ? 'user' : 'assistant', clip(label, 200) || 'Bookmark', clip(snippet, 600), clip(chatTitle, 200) || null, now, now);
|
|
144
|
+
return bookmarkRow(db().prepare('SELECT * FROM bookmarks WHERE session_key = ? AND message_id = ?').get(sessionKey, messageId));
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
/** Rename; returns the updated bookmark, or null if it doesn't exist. */
|
|
148
|
+
renameBookmark(id, label) {
|
|
149
|
+
const l = clip(label, 200);
|
|
150
|
+
if (!l) return null;
|
|
151
|
+
db().prepare('UPDATE bookmarks SET label = ?, updated_at = ? WHERE id = ?').run(l, Date.now(), id);
|
|
152
|
+
const r = db().prepare('SELECT * FROM bookmarks WHERE id = ?').get(id);
|
|
153
|
+
return r ? bookmarkRow(r) : null;
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
deleteBookmark(id) {
|
|
157
|
+
return db().prepare('DELETE FROM bookmarks WHERE id = ?').run(id).changes > 0;
|
|
90
158
|
},
|
|
91
159
|
};
|
|
92
160
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { Database } from '../bootstrap/native.js';
|
|
4
|
+
import { createExtrasStore, cleanPreset } from './extras-store.js';
|
|
5
|
+
|
|
6
|
+
test('project preset: stored with the style, kept when only color changes, cleared by null, follows rename/delete', () => {
|
|
7
|
+
const db = new Database(':memory:');
|
|
8
|
+
const extras = createExtrasStore(() => db);
|
|
9
|
+
extras.setProjectStyle('Work', { color: 'red' });
|
|
10
|
+
assert.deepEqual(extras.getProjectStyles().Work, { color: 'red', icon: null, preset: null });
|
|
11
|
+
|
|
12
|
+
extras.setProjectStyle('Work', { preset: { agentId: 'dev', cwd: '/home/u/repos', permissionMode: 'full', thinkingLevel: 'high', fastMode: false } });
|
|
13
|
+
extras.setProjectStyle('Work', { color: 'blue' });
|
|
14
|
+
assert.deepEqual(extras.getProjectStyles().Work, {
|
|
15
|
+
color: 'blue', icon: null,
|
|
16
|
+
preset: { agentId: 'dev', cwd: '/home/u/repos', permissionMode: 'full', thinkingLevel: 'high', fastMode: false },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
extras.renameProjectStyle('Work', 'Job');
|
|
20
|
+
assert.equal(extras.getProjectStyles().Job.preset.agentId, 'dev');
|
|
21
|
+
extras.setProjectStyle('Job', { preset: null });
|
|
22
|
+
assert.equal(extras.getProjectStyles().Job.preset, null);
|
|
23
|
+
extras.deleteProjectStyle('Job');
|
|
24
|
+
assert.equal(extras.getProjectStyles().Job, undefined);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('project preset: adds the column to an existing table', () => {
|
|
28
|
+
const db = new Database(':memory:');
|
|
29
|
+
db.exec('CREATE TABLE project_styles (name TEXT PRIMARY KEY, color TEXT, icon TEXT, updated_at INTEGER NOT NULL)');
|
|
30
|
+
db.prepare('INSERT INTO project_styles VALUES (?, ?, ?, ?)').run('Old', 'green', null, 1);
|
|
31
|
+
const extras = createExtrasStore(() => db);
|
|
32
|
+
assert.deepEqual(extras.getProjectStyles().Old, { color: 'green', icon: null, preset: null });
|
|
33
|
+
extras.setProjectStyle('Old', { preset: { model: 'anthropic/claude-opus-5-5' } });
|
|
34
|
+
assert.deepEqual(extras.getProjectStyles().Old.preset, { model: 'anthropic/claude-opus-5-5' });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('cleanPreset: known fields only, valid permission mode, projectId wins over cwd', () => {
|
|
38
|
+
assert.equal(cleanPreset(null), null);
|
|
39
|
+
assert.equal(cleanPreset({}), null);
|
|
40
|
+
assert.equal(cleanPreset({ junk: 'x', agentId: ' ' }), null);
|
|
41
|
+
assert.deepEqual(cleanPreset({ permissionMode: 'yolo', agentId: 'dev' }), { agentId: 'dev' });
|
|
42
|
+
assert.deepEqual(cleanPreset({ cwd: '/a', projectId: 'p1', projectLabel: 'Repo' }), { projectId: 'p1', projectLabel: 'Repo' });
|
|
43
|
+
assert.deepEqual(cleanPreset({ cwd: '/a', projectLabel: 'Repo' }), { cwd: '/a' });
|
|
44
|
+
assert.deepEqual(cleanPreset({ fastMode: true }), { fastMode: true });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('bookmarks: add is idempotent per message, rename, delete, dropped with the session', () => {
|
|
48
|
+
const db = new Database(':memory:');
|
|
49
|
+
const extras = createExtrasStore(() => db);
|
|
50
|
+
const a = extras.addBookmark('b1', { sessionKey: 'agent:main:x', messageId: 'm1', role: 'assistant', label: ' Plan ', snippet: 'The plan…', chatTitle: 'Chat X' });
|
|
51
|
+
assert.equal(a.label, 'Plan');
|
|
52
|
+
assert.equal(a.chatTitle, 'Chat X');
|
|
53
|
+
// Same message again: the existing bookmark comes back unchanged.
|
|
54
|
+
const again = extras.addBookmark('b2', { sessionKey: 'agent:main:x', messageId: 'm1', label: 'Other' });
|
|
55
|
+
assert.equal(again.id, 'b1');
|
|
56
|
+
assert.equal(again.label, 'Plan');
|
|
57
|
+
assert.equal(extras.addBookmark('b3', { sessionKey: 'agent:main:x' }), null);
|
|
58
|
+
extras.addBookmark('b4', { sessionKey: 'agent:main:y', messageId: 'm9', role: 'user', label: '', snippet: 'hi' });
|
|
59
|
+
assert.deepEqual(extras.listBookmarks().map(b => [b.id, b.label]).sort(), [['b1', 'Plan'], ['b4', 'Bookmark']]);
|
|
60
|
+
|
|
61
|
+
assert.equal(extras.renameBookmark('b1', 'Bulk export plan').label, 'Bulk export plan');
|
|
62
|
+
assert.equal(extras.renameBookmark('b1', ' '), null);
|
|
63
|
+
assert.equal(extras.renameBookmark('nope', 'x'), null);
|
|
64
|
+
|
|
65
|
+
assert.equal(extras.deleteBookmark('b4'), true);
|
|
66
|
+
assert.equal(extras.deleteBookmark('b4'), false);
|
|
67
|
+
extras.deleteThreadExtras('agent:main:x');
|
|
68
|
+
assert.deepEqual(extras.listBookmarks(), []);
|
|
69
|
+
});
|