@clawchatsai/connector 0.0.75 → 0.0.76

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 +30 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ let healthServer = null;
39
39
  let _stopRequested = false;
40
40
  /** Model IDs that have 'input' explicitly set without 'image' support. */
41
41
  let _imageRestrictedModels = [];
42
+ let _uploadsDir = null;
42
43
  // ---------------------------------------------------------------------------
43
44
  // Config helpers
44
45
  // ---------------------------------------------------------------------------
@@ -220,6 +221,7 @@ async function startClawChats(ctx, api, mediaStash) {
220
221
  // 4. Import server.js and create app instance with plugin paths
221
222
  const dataDir = path.join(ctx.stateDir, 'clawchats', 'data');
222
223
  const uploadsDir = path.join(ctx.stateDir, 'clawchats', 'uploads');
224
+ _uploadsDir = uploadsDir;
223
225
  // Dynamic import of server.js (plain JS, no type declarations)
224
226
  // @ts-expect-error — server.js is plain JS with no .d.ts
225
227
  const serverModule = await import('../server.js');
@@ -394,6 +396,34 @@ function normalizeGatewayPayload(raw) {
394
396
  try {
395
397
  const parsed = JSON.parse(raw);
396
398
  if (parsed.method === 'chat.send' && typeof parsed.params?.message === 'string') {
399
+ // Save inline base64 attachments to disk so the agent can reference them as file paths.
400
+ if (Array.isArray(parsed.params?.attachments) && parsed.params.attachments.length > 0 && _uploadsDir) {
401
+ const skMatch = (parsed.params.sessionKey || '').match(/^agent:[^:]+:[^:]+:chat:([^:]+)$/);
402
+ const threadId = skMatch?.[1] || 'misc';
403
+ const uploadDir = path.join(_uploadsDir, threadId);
404
+ const extMap = { jpeg: 'jpg', jpg: 'jpg', png: 'png', gif: 'gif', webp: 'webp', pdf: 'pdf', 'svg+xml': 'svg', mp3: 'mp3', mp4: 'mp4', wav: 'wav', webm: 'webm' };
405
+ const savedPaths = [];
406
+ for (const att of parsed.params.attachments) {
407
+ if (!att.content || !att.mimeType)
408
+ continue;
409
+ try {
410
+ const rawExt = att.mimeType.split('/')[1]?.split(';')[0] || 'bin';
411
+ const ext = extMap[rawExt] || rawExt;
412
+ const fileId = `${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
413
+ const filePath = path.join(uploadDir, `${fileId}.${ext}`);
414
+ fs.mkdirSync(uploadDir, { recursive: true });
415
+ fs.writeFileSync(filePath, Buffer.from(att.content, 'base64'));
416
+ savedPaths.push(filePath);
417
+ }
418
+ catch { /* skip attachment on error */ }
419
+ }
420
+ if (savedPaths.length > 0) {
421
+ const label = savedPaths.length === 1 ? 'Attached file saved on disk' : 'Attached files saved on disk';
422
+ parsed.params.message = parsed.params.message.trimEnd() +
423
+ `\n\n[${label}:\n${savedPaths.map((p) => `- ${p}`).join('\n')}]`;
424
+ return JSON.stringify(parsed);
425
+ }
426
+ }
397
427
  // Warn user in-chat if they're sending image attachments to an image-restricted model.
398
428
  // The warning is appended to the message so the AI echoes it back — impossible to miss.
399
429
  if (Array.isArray(parsed.params?.attachments) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawchatsai/connector",
3
- "version": "0.0.75",
3
+ "version": "0.0.76",
4
4
  "type": "module",
5
5
  "description": "ClawChats OpenClaw plugin — P2P tunnel + local API bridge",
6
6
  "main": "dist/index.js",