@clawchatsai/connector 0.0.49 → 0.0.51
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 +1 -1
- package/dist/index.js +29 -35
- package/package.json +1 -1
- package/server.js +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ interface PluginApi {
|
|
|
51
51
|
name: string;
|
|
52
52
|
description?: string;
|
|
53
53
|
}) => void;
|
|
54
|
-
|
|
54
|
+
on: (hookName: string, handler: (event: Record<string, unknown>, ctx: Record<string, unknown>) => void | Promise<void>, opts?: {
|
|
55
55
|
name?: string;
|
|
56
56
|
description?: string;
|
|
57
57
|
priority?: number;
|
package/dist/index.js
CHANGED
|
@@ -964,41 +964,35 @@ const plugin = {
|
|
|
964
964
|
const mediaStash = new Map();
|
|
965
965
|
// Capture MEDIA: paths from exec tool results before the gateway strips them from message text.
|
|
966
966
|
// Fires after every tool call; we filter to exec only and check for MEDIA: lines.
|
|
967
|
-
//
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
if (!sessionKey)
|
|
997
|
-
return;
|
|
998
|
-
const existing = mediaStash.get(sessionKey) ?? [];
|
|
999
|
-
mediaStash.set(sessionKey, [...existing, ...paths]);
|
|
1000
|
-
console.log(`[clawchats] media-capture: stashed ${paths.length} path(s) for ${sessionKey}:`, paths);
|
|
1001
|
-
}, { name: 'clawchats-media-capture', description: 'Captures MEDIA: paths from exec results for inline image rendering' });
|
|
967
|
+
// Uses api.on() — the correct public API for typed lifecycle hooks (NOT registerTypedHook).
|
|
968
|
+
api.on('after_tool_call', (event, ctx) => {
|
|
969
|
+
if (event.toolName !== 'exec' && event.toolName !== 'process')
|
|
970
|
+
return;
|
|
971
|
+
// result is { content: [{ type: 'text', text: '...' }] } — extract text defensively
|
|
972
|
+
const result = event.result;
|
|
973
|
+
let text = '';
|
|
974
|
+
if (typeof result?.text === 'string') {
|
|
975
|
+
text = result.text;
|
|
976
|
+
}
|
|
977
|
+
else if (Array.isArray(result?.content)) {
|
|
978
|
+
text = result.content
|
|
979
|
+
.filter(c => c.type === 'text' && typeof c.text === 'string')
|
|
980
|
+
.map(c => c.text)
|
|
981
|
+
.join('\n');
|
|
982
|
+
}
|
|
983
|
+
else if (result != null) {
|
|
984
|
+
text = String(result);
|
|
985
|
+
}
|
|
986
|
+
const paths = [...text.matchAll(/^MEDIA:\s*(\S+)/gm)].map(m => m[1].trim());
|
|
987
|
+
if (paths.length === 0)
|
|
988
|
+
return;
|
|
989
|
+
const sessionKey = ctx.sessionKey;
|
|
990
|
+
if (!sessionKey)
|
|
991
|
+
return;
|
|
992
|
+
const existing = mediaStash.get(sessionKey) ?? [];
|
|
993
|
+
mediaStash.set(sessionKey, [...existing, ...paths]);
|
|
994
|
+
console.log(`[clawchats] media-capture: stashed ${paths.length} path(s) for ${sessionKey}:`, paths);
|
|
995
|
+
}, { name: 'clawchats-media-capture', description: 'Captures MEDIA: paths from exec results for inline image rendering' });
|
|
1002
996
|
// Background service: signaling + gateway bridge + future WebRTC
|
|
1003
997
|
api.registerService({
|
|
1004
998
|
id: 'connector-service',
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -4112,7 +4112,7 @@ export function createApp(config = {}) {
|
|
|
4112
4112
|
const threadInfo = db.prepare('SELECT title FROM threads WHERE id = ?').get(parsed.threadId);
|
|
4113
4113
|
const unreadCount = db.prepare('SELECT COUNT(*) as c FROM unread_messages WHERE thread_id = ?').get(parsed.threadId).c;
|
|
4114
4114
|
const preview = content.length > 120 ? content.substring(0, 120) + '...' : content;
|
|
4115
|
-
this.broadcastToBrowsers(JSON.stringify({ type: 'clawchats', event: 'message-saved', threadId: parsed.threadId, workspace: parsed.workspace, messageId, timestamp: now, title: threadInfo?.title || 'Chat', preview, unreadCount }));
|
|
4115
|
+
this.broadcastToBrowsers(JSON.stringify({ type: 'clawchats', event: 'message-saved', threadId: parsed.threadId, workspace: parsed.workspace, messageId, timestamp: now, title: threadInfo?.title || 'Chat', preview, unreadCount, updatedContent: _pendingPaths.length > 0 ? content : undefined }));
|
|
4116
4116
|
const workspaceUnreadTotal = db.prepare('SELECT COALESCE(SUM(unread_count), 0) as total FROM threads').get().total;
|
|
4117
4117
|
this.broadcastToBrowsers(JSON.stringify({ type: 'clawchats', event: 'unread-update', workspace: parsed.workspace, threadId: parsed.threadId, messageId, action: 'new', unreadCount, workspaceUnreadTotal, title: threadInfo?.title || 'Chat', preview, timestamp: now }));
|
|
4118
4118
|
console.log(`Saved assistant message to ${parsed.workspace}/${parsed.threadId} (${pendingMsg ? 'merged into pending' : 'seq: ' + seq})`);
|