@clawchatsai/connector 0.0.75 → 0.0.77

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 +31 -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');
@@ -421,6 +423,35 @@ function normalizeGatewayPayload(raw) {
421
423
  console.log(`[clawchats] capability-note injected for session ${sk}`);
422
424
  return JSON.stringify(parsed);
423
425
  }
426
+ // Save inline base64 attachments to disk so the agent can reference them as file paths.
427
+ // Runs last so image-restricted warning and capability note fire normally first.
428
+ if (Array.isArray(parsed.params?.attachments) && parsed.params.attachments.length > 0 && _uploadsDir) {
429
+ const skMatch = (parsed.params.sessionKey || '').match(/^agent:[^:]+:[^:]+:chat:([^:]+)$/);
430
+ const threadId = skMatch?.[1] || 'misc';
431
+ const uploadDir = path.join(_uploadsDir, threadId);
432
+ 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' };
433
+ const savedPaths = [];
434
+ for (const att of parsed.params.attachments) {
435
+ if (!att.content || !att.mimeType)
436
+ continue;
437
+ try {
438
+ const rawExt = att.mimeType.split('/')[1]?.split(';')[0] || 'bin';
439
+ const ext = extMap[rawExt] || rawExt;
440
+ const fileId = `${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
441
+ const filePath = path.join(uploadDir, `${fileId}.${ext}`);
442
+ fs.mkdirSync(uploadDir, { recursive: true });
443
+ fs.writeFileSync(filePath, Buffer.from(att.content, 'base64'));
444
+ savedPaths.push(filePath);
445
+ }
446
+ catch { /* skip attachment on error */ }
447
+ }
448
+ if (savedPaths.length > 0) {
449
+ const label = savedPaths.length === 1 ? 'Attached file saved on disk' : 'Attached files saved on disk';
450
+ parsed.params.message = parsed.params.message.trimEnd() +
451
+ `\n\n[${label}:\n${savedPaths.map((p) => `- ${p}`).join('\n')}]`;
452
+ return JSON.stringify(parsed);
453
+ }
454
+ }
424
455
  }
425
456
  }
426
457
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawchatsai/connector",
3
- "version": "0.0.75",
3
+ "version": "0.0.77",
4
4
  "type": "module",
5
5
  "description": "ClawChats OpenClaw plugin — P2P tunnel + local API bridge",
6
6
  "main": "dist/index.js",