@clawchatsai/connector 0.1.1 → 0.1.3
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.d.ts +3 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/server/controllers/threads.js +2 -2
- package/server/index.js +18 -0
package/dist/index.d.ts
CHANGED
|
@@ -39,7 +39,9 @@ interface PluginApi {
|
|
|
39
39
|
start: (ctx: PluginServiceContext) => Promise<void>;
|
|
40
40
|
stop: (ctx: PluginServiceContext) => Promise<void>;
|
|
41
41
|
}) => void;
|
|
42
|
-
registerCli: (handler: (ctx: PluginCliContext) => void
|
|
42
|
+
registerCli: (handler: (ctx: PluginCliContext) => void, opts?: {
|
|
43
|
+
commands?: string[];
|
|
44
|
+
}) => void;
|
|
43
45
|
registerCommand: (opts: {
|
|
44
46
|
name: string;
|
|
45
47
|
description: string;
|
package/dist/index.js
CHANGED
|
@@ -1340,7 +1340,7 @@ const plugin = {
|
|
|
1340
1340
|
cmd.command('import <path>')
|
|
1341
1341
|
.description('Import databases and config from a folder (e.g. migrate from old data directory)')
|
|
1342
1342
|
.action((srcPath) => handleImport(String(srcPath)));
|
|
1343
|
-
});
|
|
1343
|
+
}, { commands: ['clawchats'] });
|
|
1344
1344
|
// Slash command for status from any channel
|
|
1345
1345
|
api.registerCommand({
|
|
1346
1346
|
name: 'clawchats',
|
package/package.json
CHANGED
|
@@ -26,11 +26,11 @@ export class ThreadController {
|
|
|
26
26
|
if (!matchingIds.length) return send(res, 200, { threads: [], total: 0, page });
|
|
27
27
|
const ph = matchingIds.map(() => '?').join(',');
|
|
28
28
|
total = db.prepare(`SELECT COUNT(*) as c FROM threads WHERE id IN (${ph})`).get(...matchingIds).c;
|
|
29
|
-
threads = db.prepare(`SELECT
|
|
29
|
+
threads = db.prepare(`SELECT t.*, EXISTS(SELECT 1 FROM messages WHERE thread_id = t.id AND role = 'assistant' AND json_extract(metadata, '$.pending') = 1) as has_pending FROM threads t WHERE t.id IN (${ph}) ORDER BY t.pinned DESC, t.sort_order DESC, t.updated_at DESC LIMIT ? OFFSET ?`).all(...matchingIds, limit, offset);
|
|
30
30
|
} catch { return send(res, 200, { threads: [], total: 0, page }); }
|
|
31
31
|
} else {
|
|
32
32
|
total = db.prepare('SELECT COUNT(*) as c FROM threads').get().c;
|
|
33
|
-
threads = db.prepare(
|
|
33
|
+
threads = db.prepare(`SELECT t.*, EXISTS(SELECT 1 FROM messages WHERE thread_id = t.id AND role = 'assistant' AND json_extract(metadata, '$.pending') = 1) as has_pending FROM threads t ORDER BY t.pinned DESC, t.sort_order DESC, t.updated_at DESC LIMIT ? OFFSET ?`).all(limit, offset);
|
|
34
34
|
}
|
|
35
35
|
send(res, 200, { threads, total, page });
|
|
36
36
|
}
|
package/server/index.js
CHANGED
|
@@ -73,6 +73,7 @@ export function createApp(config = {}) {
|
|
|
73
73
|
_globalDb = new Database(path.join(DATA_DIR, 'global.db'));
|
|
74
74
|
_globalDb.exec('PRAGMA journal_mode = WAL');
|
|
75
75
|
_globalDb.exec(`CREATE TABLE IF NOT EXISTS custom_emojis (name TEXT NOT NULL, pack TEXT NOT NULL DEFAULT 'slackmojis', url TEXT NOT NULL, mime_type TEXT, created_at INTEGER DEFAULT (strftime('%s','now')), PRIMARY KEY (name, pack))`);
|
|
76
|
+
_globalDb.exec(`CREATE TABLE IF NOT EXISTS prompts (id TEXT PRIMARY KEY, title TEXT NOT NULL, content TEXT NOT NULL, category TEXT DEFAULT '', variables TEXT DEFAULT '[]', created_at INTEGER, updated_at INTEGER)`);
|
|
76
77
|
return _globalDb;
|
|
77
78
|
},
|
|
78
79
|
close() { if (_globalDb) { _globalDb.close(); _globalDb = null; } }
|
|
@@ -193,6 +194,23 @@ export function createApp(config = {}) {
|
|
|
193
194
|
if ((p = matchRoute(method, urlPath, 'PUT /api/memory/:id'))) return await memory.update(req, res, p);
|
|
194
195
|
if ((p = matchRoute(method, urlPath, 'DELETE /api/memory/:id'))) return await memory.delete(req, res, p);
|
|
195
196
|
|
|
197
|
+
// Prompt library
|
|
198
|
+
if (method === 'GET' && urlPath === '/api/prompts') {
|
|
199
|
+
const rows = globalDbCache.get().prepare('SELECT * FROM prompts ORDER BY created_at ASC').all();
|
|
200
|
+
return send(res, 200, rows.map(r => ({ id: r.id, title: r.title, content: r.content, category: r.category, variables: JSON.parse(r.variables || '[]'), createdAt: r.created_at, updatedAt: r.updated_at })));
|
|
201
|
+
}
|
|
202
|
+
if (method === 'PUT' && urlPath === '/api/prompts') {
|
|
203
|
+
const body = await parseBody(req);
|
|
204
|
+
const prompts = Array.isArray(body) ? body : [];
|
|
205
|
+
const db = globalDbCache.get();
|
|
206
|
+
const upsert = db.prepare('INSERT OR REPLACE INTO prompts (id, title, content, category, variables, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)');
|
|
207
|
+
db.transaction(() => {
|
|
208
|
+
db.prepare('DELETE FROM prompts').run();
|
|
209
|
+
for (const p of prompts) upsert.run(p.id, p.title, p.content, p.category || '', JSON.stringify(p.variables || []), p.createdAt || Date.now(), p.updatedAt || Date.now());
|
|
210
|
+
})();
|
|
211
|
+
return send(res, 200, { ok: true });
|
|
212
|
+
}
|
|
213
|
+
|
|
196
214
|
// Settings & misc
|
|
197
215
|
if (method === 'GET' && urlPath === '/api/settings') return handleGetSettings(req, res);
|
|
198
216
|
if (method === 'PUT' && urlPath === '/api/settings') return await handleSaveSettings(req, res, parseBody);
|