@clawchatsai/connector 0.1.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawchatsai/connector",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "ClawChats OpenClaw plugin — P2P tunnel + local API bridge",
6
6
  "main": "dist/index.js",
@@ -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 * FROM threads WHERE id IN (${ph}) ORDER BY pinned DESC, sort_order DESC, updated_at DESC LIMIT ? OFFSET ?`).all(...matchingIds, limit, offset);
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('SELECT * FROM threads ORDER BY pinned DESC, sort_order DESC, updated_at DESC LIMIT ? OFFSET ?').all(limit, offset);
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);