@clawchatsai/connector 0.0.43 → 0.0.44

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/package.json +1 -1
  2. package/server.js +19 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawchatsai/connector",
3
- "version": "0.0.43",
3
+ "version": "0.0.44",
4
4
  "type": "module",
5
5
  "description": "ClawChats OpenClaw plugin — P2P tunnel + local API bridge",
6
6
  "main": "dist/index.js",
package/server.js CHANGED
@@ -1437,7 +1437,10 @@ function handleServeFile(req, res, query) {
1437
1437
  if (!filePath) return sendError(res, 400, 'Missing path parameter');
1438
1438
 
1439
1439
  // Resolve to prevent traversal attacks
1440
- const resolved = path.resolve(filePath);
1440
+ // Relative paths (./filename) resolve against the workspace directory
1441
+ const resolved = (filePath.startsWith('./') || filePath.startsWith('../'))
1442
+ ? path.resolve(MEMORY_CONFIG.workspaceDir, filePath)
1443
+ : path.resolve(filePath);
1441
1444
 
1442
1445
  // Security: only serve files from allowed directories
1443
1446
  const allowed = ALLOWED_FILE_DIRS.some(dir => resolved.startsWith(dir + '/') || resolved === dir);
@@ -4544,6 +4547,9 @@ export function createApp(config = {}) {
4544
4547
  }
4545
4548
 
4546
4549
  // ── Browser WebSocket setup (shared logic for standalone and plugin) ────────
4550
+ // Track which sessions have already received the ClawChats file hint (once per session)
4551
+ const _clawchatsHintedSessions = new Set();
4552
+
4547
4553
  function _setupBrowserWs(wssInstance) {
4548
4554
  wssInstance.on('connection', (ws) => {
4549
4555
  console.log('Browser client connected');
@@ -4554,6 +4560,7 @@ export function createApp(config = {}) {
4554
4560
  ws.on('message', (data) => {
4555
4561
  const msgStr = data.toString();
4556
4562
  _debugLogger.logFrame('BR→SRV', msgStr);
4563
+ let forwardStr = msgStr;
4557
4564
  try {
4558
4565
  const msg = JSON.parse(msgStr);
4559
4566
  if (msg.type === 'req' && msg.method === 'connect') {
@@ -4573,8 +4580,17 @@ export function createApp(config = {}) {
4573
4580
  if (msg.action === 'debug-start') { const result = _debugLogger.start(msg.ts, ws); if (result.error === 'already-active') ws.send(JSON.stringify({ type: 'clawchats', event: 'debug-error', error: 'Recording already active in another tab', sessionId: result.sessionId })); else ws.send(JSON.stringify({ type: 'clawchats', event: 'debug-started', sessionId: result.sessionId })); return; }
4574
4581
  if (msg.action === 'debug-dump') { const { sessionId, files } = _debugLogger.saveDump(msg); ws.send(JSON.stringify({ type: 'clawchats', event: 'debug-saved', sessionId, files })); return; }
4575
4582
  }
4576
- } catch { /* Not JSON or not a ClawChats message, forward to gateway */ }
4577
- _gatewayClient.sendToGateway(msgStr);
4583
+ // Inject ClawChats file hint once per session (first message only, ~15 tokens)
4584
+ if (msg.type === 'req' && msg.method === 'chat.send' && typeof msg.params?.message === 'string') {
4585
+ const sk = msg.params.sessionKey;
4586
+ if (sk && !_clawchatsHintedSessions.has(sk)) {
4587
+ _clawchatsHintedSessions.add(sk);
4588
+ msg.params.message += '\n[ClawChats context: MEDIA: tags are stripped by the gateway and will NOT display. To show images/files inline, use markdown syntax: ![alt](./filename.ext) for workspace files or ![alt](/abs/path.ext) for any path. Always use this instead of MEDIA:]';
4589
+ forwardStr = JSON.stringify(msg);
4590
+ }
4591
+ }
4592
+ } catch { /* Not JSON or not a ClawChats message, forward as-is */ }
4593
+ _gatewayClient.sendToGateway(forwardStr);
4578
4594
  });
4579
4595
 
4580
4596
  ws.on('close', () => { console.log('Browser client disconnected'); _debugLogger.handleClientDisconnect(ws); _gatewayClient.removeBrowserClient(ws); });