@clawchatsai/connector 0.1.23 → 0.1.24
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
|
}
|
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,16 +1,40 @@
|
|
|
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
7
|
|
|
8
|
+
// New-chat preset: what a new chat in the project starts with. Every field is optional;
|
|
9
|
+
// a missing field means the gateway default. `cwd` and `projectId` are exclusive places.
|
|
10
|
+
const PRESET_STRINGS = ['agentId', 'cwd', 'projectId', 'projectLabel', 'permissionMode', 'model', 'thinkingLevel'];
|
|
11
|
+
const PERMISSION_MODES = new Set(['read-only', 'guarded', 'workspace', 'full']);
|
|
12
|
+
|
|
13
|
+
export function cleanPreset(p) {
|
|
14
|
+
if (!p || typeof p !== 'object' || Array.isArray(p)) return null;
|
|
15
|
+
const out = {};
|
|
16
|
+
for (const k of PRESET_STRINGS) {
|
|
17
|
+
if (typeof p[k] === 'string' && p[k].trim()) out[k] = p[k].trim().slice(0, 1000);
|
|
18
|
+
}
|
|
19
|
+
if (out.permissionMode && !PERMISSION_MODES.has(out.permissionMode)) delete out.permissionMode;
|
|
20
|
+
if (out.projectId) delete out.cwd;
|
|
21
|
+
else delete out.projectLabel;
|
|
22
|
+
if (typeof p.fastMode === 'boolean') out.fastMode = p.fastMode;
|
|
23
|
+
return Object.keys(out).length ? out : null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function parsePreset(text) {
|
|
27
|
+
if (!text) return null;
|
|
28
|
+
try { return cleanPreset(JSON.parse(text)); } catch { return null; }
|
|
29
|
+
}
|
|
30
|
+
|
|
8
31
|
export function createExtrasStore(getGlobalDb) {
|
|
9
32
|
let ready = false;
|
|
10
33
|
function db() {
|
|
11
34
|
const g = getGlobalDb();
|
|
12
35
|
if (!ready) {
|
|
13
36
|
g.exec(`CREATE TABLE IF NOT EXISTS project_styles (name TEXT PRIMARY KEY, color TEXT, icon TEXT, updated_at INTEGER NOT NULL)`);
|
|
37
|
+
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
38
|
g.exec(`CREATE TABLE IF NOT EXISTS legacy_created (session_key TEXT PRIMARY KEY, created_at INTEGER NOT NULL)`);
|
|
15
39
|
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))`);
|
|
16
40
|
ready = true;
|
|
@@ -19,19 +43,22 @@ export function createExtrasStore(getGlobalDb) {
|
|
|
19
43
|
}
|
|
20
44
|
|
|
21
45
|
return {
|
|
22
|
-
/** { [groupName]: { color, icon } } */
|
|
46
|
+
/** { [groupName]: { color, icon, preset } } */
|
|
23
47
|
getProjectStyles() {
|
|
24
48
|
const out = {};
|
|
25
|
-
for (const r of db().prepare('SELECT name, color, icon FROM project_styles').all())
|
|
49
|
+
for (const r of db().prepare('SELECT name, color, icon, preset FROM project_styles').all()) {
|
|
50
|
+
out[r.name] = { color: r.color, icon: r.icon, preset: parsePreset(r.preset) };
|
|
51
|
+
}
|
|
26
52
|
return out;
|
|
27
53
|
},
|
|
28
54
|
|
|
29
|
-
/** Set color and/or
|
|
30
|
-
setProjectStyle(name, { color, icon } = {}) {
|
|
55
|
+
/** Set color, icon and/or new-chat preset; absent fields keep their value, null clears. */
|
|
56
|
+
setProjectStyle(name, { color, icon, preset } = {}) {
|
|
31
57
|
if (!name) return;
|
|
32
|
-
const cur = db().prepare('SELECT color, icon FROM project_styles WHERE name = ?').get(name) || {};
|
|
33
|
-
|
|
34
|
-
|
|
58
|
+
const cur = db().prepare('SELECT color, icon, preset FROM project_styles WHERE name = ?').get(name) || {};
|
|
59
|
+
const nextPreset = preset === undefined ? (cur.preset ?? null) : (cleanPreset(preset) ? JSON.stringify(cleanPreset(preset)) : null);
|
|
60
|
+
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')
|
|
61
|
+
.run(name, color !== undefined ? color : (cur.color ?? null), icon !== undefined ? icon : (cur.icon ?? null), nextPreset, Date.now());
|
|
35
62
|
},
|
|
36
63
|
|
|
37
64
|
renameProjectStyle(from, to) {
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
});
|