@clawchatsai/connector 0.0.63 → 0.0.65
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.js +33 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -125,8 +125,40 @@ async function ensureNativeModules(ctx) {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
+
const CLAWCHATS_MD_CONTENT = `# ClawChats — Inline File Delivery
|
|
129
|
+
|
|
130
|
+
To deliver a file inline in this chat, run an exec that outputs a MEDIA: line:
|
|
131
|
+
|
|
132
|
+
MEDIA:/absolute/path/to/file
|
|
133
|
+
|
|
134
|
+
**After creating any file** (via Write tool or exec), deliver it by running:
|
|
135
|
+
|
|
136
|
+
exec echo "MEDIA:/absolute/path/to/file"
|
|
137
|
+
|
|
138
|
+
For files created during an exec command, you can inline it at the end of the same command:
|
|
139
|
+
|
|
140
|
+
exec python3 generate.py --output /tmp/result.png && echo "MEDIA:/tmp/result.png"
|
|
141
|
+
|
|
142
|
+
Notes:
|
|
143
|
+
- Works for images (png, jpg, gif, webp, svg, etc.), documents, markdown, code files, and more
|
|
144
|
+
- Output each path once — duplicates are ignored automatically
|
|
145
|
+
`;
|
|
128
146
|
async function startClawChats(ctx, api, mediaStash) {
|
|
129
147
|
_stopRequested = false;
|
|
148
|
+
// Bootstrap CLAWCHATS.md in the agent workspace so the agent always knows the MEDIA: protocol.
|
|
149
|
+
// Written once on plugin start; never overwrites an existing file (user may have customised it).
|
|
150
|
+
try {
|
|
151
|
+
const workspaceDir = path.join(ctx.stateDir, 'workspace');
|
|
152
|
+
const clawchatsDoc = path.join(workspaceDir, 'CLAWCHATS.md');
|
|
153
|
+
if (!fs.existsSync(clawchatsDoc)) {
|
|
154
|
+
fs.mkdirSync(workspaceDir, { recursive: true });
|
|
155
|
+
fs.writeFileSync(clawchatsDoc, CLAWCHATS_MD_CONTENT, { encoding: 'utf8' });
|
|
156
|
+
ctx.logger.info('[clawchats] wrote CLAWCHATS.md to workspace');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (e) {
|
|
160
|
+
ctx.logger.warn(`[clawchats] could not write CLAWCHATS.md: ${e.message}`);
|
|
161
|
+
}
|
|
130
162
|
let config = loadConfig();
|
|
131
163
|
if (!config) {
|
|
132
164
|
ctx.logger.info('ClawChats not configured. Waiting for setup...');
|
|
@@ -356,8 +388,6 @@ async function stopClawChats(ctx) {
|
|
|
356
388
|
* guard checks MediaPath/MediaPaths but not inline base64 attachments).
|
|
357
389
|
* Injecting a minimal placeholder ensures the agent run proceeds.
|
|
358
390
|
*/
|
|
359
|
-
// Track which ClawChats thread sessions have received the file-hint (once per session).
|
|
360
|
-
const _hintedSessions = new Set();
|
|
361
391
|
function normalizeGatewayPayload(raw) {
|
|
362
392
|
try {
|
|
363
393
|
const parsed = JSON.parse(raw);
|
|
@@ -379,15 +409,6 @@ function normalizeGatewayPayload(raw) {
|
|
|
379
409
|
parsed.params.message = '[Image]';
|
|
380
410
|
return JSON.stringify(parsed);
|
|
381
411
|
}
|
|
382
|
-
// Hint injection: teach the agent to emit MEDIA:/path via exec after creating files.
|
|
383
|
-
// Injected once per ClawChats thread session (~15 tokens, invisible to user).
|
|
384
|
-
const sk = parsed.params.sessionKey || '';
|
|
385
|
-
if (sk.includes(':chat:') && !_hintedSessions.has(sk)) {
|
|
386
|
-
_hintedSessions.add(sk);
|
|
387
|
-
parsed.params.message += '\n[ClawChats: after creating or saving any file, run: exec echo "MEDIA:/absolute/path/to/file" — this delivers it inline to the chat]';
|
|
388
|
-
console.log(`[clawchats] hint-injected for session ${sk}`);
|
|
389
|
-
return JSON.stringify(parsed);
|
|
390
|
-
}
|
|
391
412
|
}
|
|
392
413
|
}
|
|
393
414
|
catch {
|
|
@@ -1102,7 +1123,7 @@ const plugin = {
|
|
|
1102
1123
|
if (!sessionKey)
|
|
1103
1124
|
return;
|
|
1104
1125
|
const existing = mediaStash.get(sessionKey) ?? [];
|
|
1105
|
-
mediaStash.set(sessionKey, [...existing, ...paths]);
|
|
1126
|
+
mediaStash.set(sessionKey, [...new Set([...existing, ...paths])]);
|
|
1106
1127
|
console.log(`[clawchats] media-capture: stashed ${paths.length} path(s) for ${sessionKey}:`, paths);
|
|
1107
1128
|
}, { name: 'clawchats-media-capture', description: 'Captures MEDIA: paths from exec results for inline image rendering' });
|
|
1108
1129
|
// Background service: signaling + gateway bridge + future WebRTC
|