@clawchatsai/connector 0.0.73 → 0.0.75
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/package.json +1 -1
- package/server.js +33 -4
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -3081,7 +3081,7 @@ class GatewayClient {
|
|
|
3081
3081
|
name: data?.name || 'unknown',
|
|
3082
3082
|
phase: data?.phase || 'start',
|
|
3083
3083
|
toolCallId: data?.toolCallId,
|
|
3084
|
-
meta: data?.meta || (argsMeta ? String(argsMeta)
|
|
3084
|
+
meta: data?.meta || (argsMeta ? String(argsMeta) : undefined),
|
|
3085
3085
|
isError: data?.isError || false
|
|
3086
3086
|
};
|
|
3087
3087
|
|
|
@@ -4483,7 +4483,7 @@ export function createApp(config = {}) {
|
|
|
4483
4483
|
if (log._currentAssistantSegment && !log._currentAssistantSegment._sealed) { log._currentAssistantSegment._sealed = true; }
|
|
4484
4484
|
const _args = data?.args;
|
|
4485
4485
|
const _argsMeta = _args ? (_args.command || _args.path || _args.query || _args.url || Object.values(_args).find(v => typeof v === 'string') || '') : '';
|
|
4486
|
-
const step = { type: 'tool', timestamp: Date.now(), name: data?.name || 'unknown', phase: data?.phase || 'start', toolCallId: data?.toolCallId, meta: data?.meta || (_argsMeta ? String(_argsMeta)
|
|
4486
|
+
const step = { type: 'tool', timestamp: Date.now(), name: data?.name || 'unknown', phase: data?.phase || 'start', toolCallId: data?.toolCallId, meta: data?.meta || (_argsMeta ? String(_argsMeta) : undefined), isError: data?.isError || false };
|
|
4487
4487
|
if (data?.phase === 'result') {
|
|
4488
4488
|
const existing = log.steps.findLast(s => s.toolCallId === data.toolCallId && (s.phase === 'start' || s.phase === 'running'));
|
|
4489
4489
|
if (existing) { existing.phase = 'done'; existing.resultMeta = data?.meta; existing.isError = data?.isError || false; existing.durationMs = Date.now() - existing.timestamp; }
|
|
@@ -4793,6 +4793,7 @@ export function createApp(config = {}) {
|
|
|
4793
4793
|
ws.on('message', (data) => {
|
|
4794
4794
|
const msgStr = data.toString();
|
|
4795
4795
|
_debugLogger.logFrame('BR→SRV', msgStr);
|
|
4796
|
+
let msgToForward = msgStr;
|
|
4796
4797
|
try {
|
|
4797
4798
|
const msg = JSON.parse(msgStr);
|
|
4798
4799
|
if (msg.type === 'req' && msg.method === 'connect') {
|
|
@@ -4812,8 +4813,36 @@ export function createApp(config = {}) {
|
|
|
4812
4813
|
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; }
|
|
4813
4814
|
if (msg.action === 'debug-dump') { const { sessionId, files } = _debugLogger.saveDump(msg); ws.send(JSON.stringify({ type: 'clawchats', event: 'debug-saved', sessionId, files })); return; }
|
|
4814
4815
|
}
|
|
4815
|
-
|
|
4816
|
-
|
|
4816
|
+
// Save inline attachments to disk so the agent can access them as file paths
|
|
4817
|
+
if (msg.type === 'req' && msg.method === 'chat.send' && msg.params?.attachments?.length > 0) {
|
|
4818
|
+
const parsed = parseSessionKey(msg.params.sessionKey || '');
|
|
4819
|
+
const threadId = parsed?.threadId || 'misc';
|
|
4820
|
+
const uploadDir = path.join(_UPLOADS_DIR, threadId);
|
|
4821
|
+
fs.mkdirSync(uploadDir, { recursive: true });
|
|
4822
|
+
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' };
|
|
4823
|
+
const savedPaths = [];
|
|
4824
|
+
for (const att of msg.params.attachments) {
|
|
4825
|
+
if (!att.content || !att.mimeType) continue;
|
|
4826
|
+
try {
|
|
4827
|
+
const rawExt = att.mimeType.split('/')[1]?.split(';')[0] || 'bin';
|
|
4828
|
+
const ext = extMap[rawExt] || rawExt;
|
|
4829
|
+
const fileId = `${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
4830
|
+
const filePath = path.join(uploadDir, `${fileId}.${ext}`);
|
|
4831
|
+
fs.writeFileSync(filePath, Buffer.from(att.content, 'base64'));
|
|
4832
|
+
savedPaths.push(filePath);
|
|
4833
|
+
console.log(`[upload] Saved attachment to ${filePath}`);
|
|
4834
|
+
} catch (err) {
|
|
4835
|
+
console.error('[upload] Failed to save attachment:', err.message);
|
|
4836
|
+
}
|
|
4837
|
+
}
|
|
4838
|
+
if (savedPaths.length > 0) {
|
|
4839
|
+
const label = savedPaths.length === 1 ? 'Attached file saved on disk' : 'Attached files saved on disk';
|
|
4840
|
+
const note = `\n\n[${label}:\n${savedPaths.map(p => `- ${p}`).join('\n')}]`;
|
|
4841
|
+
msgToForward = JSON.stringify({ ...msg, params: { ...msg.params, message: (msg.params.message || '') + note } });
|
|
4842
|
+
}
|
|
4843
|
+
}
|
|
4844
|
+
} catch { /* Not JSON or not a ClawChats message, forward as-is */ }
|
|
4845
|
+
_gatewayClient.sendToGateway(msgToForward);
|
|
4817
4846
|
});
|
|
4818
4847
|
|
|
4819
4848
|
ws.on('close', () => { console.log('Browser client disconnected'); _debugLogger.handleClientDisconnect(ws); _gatewayClient.removeBrowserClient(ws); });
|