@clawchatsai/connector 0.0.63 → 0.0.64

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.
Files changed (2) hide show
  1. package/dist/index.js +26 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -125,8 +125,33 @@ 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, print a MEDIA: line to stdout during an exec call:
131
+
132
+ MEDIA:/absolute/path/to/file
133
+
134
+ - Supported for images (png, jpg, gif, webp, svg, etc.) and other file types
135
+ - Include it at the end of the same exec command that creates the file
136
+ - Example: \`python3 generate.py --output /tmp/result.png && echo "MEDIA:/tmp/result.png"\`
137
+ - Output each path once — duplicates are ignored automatically
138
+ `;
128
139
  async function startClawChats(ctx, api, mediaStash) {
129
140
  _stopRequested = false;
141
+ // Bootstrap CLAWCHATS.md in the agent workspace so the agent always knows the MEDIA: protocol.
142
+ // Written once on plugin start; never overwrites an existing file (user may have customised it).
143
+ try {
144
+ const workspaceDir = path.join(ctx.stateDir, 'workspace');
145
+ const clawchatsDoc = path.join(workspaceDir, 'CLAWCHATS.md');
146
+ if (!fs.existsSync(clawchatsDoc)) {
147
+ fs.mkdirSync(workspaceDir, { recursive: true });
148
+ fs.writeFileSync(clawchatsDoc, CLAWCHATS_MD_CONTENT, { encoding: 'utf8' });
149
+ ctx.logger.info('[clawchats] wrote CLAWCHATS.md to workspace');
150
+ }
151
+ }
152
+ catch (e) {
153
+ ctx.logger.warn(`[clawchats] could not write CLAWCHATS.md: ${e.message}`);
154
+ }
130
155
  let config = loadConfig();
131
156
  if (!config) {
132
157
  ctx.logger.info('ClawChats not configured. Waiting for setup...');
@@ -356,8 +381,6 @@ async function stopClawChats(ctx) {
356
381
  * guard checks MediaPath/MediaPaths but not inline base64 attachments).
357
382
  * Injecting a minimal placeholder ensures the agent run proceeds.
358
383
  */
359
- // Track which ClawChats thread sessions have received the file-hint (once per session).
360
- const _hintedSessions = new Set();
361
384
  function normalizeGatewayPayload(raw) {
362
385
  try {
363
386
  const parsed = JSON.parse(raw);
@@ -379,15 +402,6 @@ function normalizeGatewayPayload(raw) {
379
402
  parsed.params.message = '[Image]';
380
403
  return JSON.stringify(parsed);
381
404
  }
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
405
  }
392
406
  }
393
407
  catch {
@@ -1102,7 +1116,7 @@ const plugin = {
1102
1116
  if (!sessionKey)
1103
1117
  return;
1104
1118
  const existing = mediaStash.get(sessionKey) ?? [];
1105
- mediaStash.set(sessionKey, [...existing, ...paths]);
1119
+ mediaStash.set(sessionKey, [...new Set([...existing, ...paths])]);
1106
1120
  console.log(`[clawchats] media-capture: stashed ${paths.length} path(s) for ${sessionKey}:`, paths);
1107
1121
  }, { name: 'clawchats-media-capture', description: 'Captures MEDIA: paths from exec results for inline image rendering' });
1108
1122
  // Background service: signaling + gateway bridge + future WebRTC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawchatsai/connector",
3
- "version": "0.0.63",
3
+ "version": "0.0.64",
4
4
  "type": "module",
5
5
  "description": "ClawChats OpenClaw plugin — P2P tunnel + local API bridge",
6
6
  "main": "dist/index.js",