indieclaw-agent 2.4.3 → 2.4.5
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/index.js +42 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -277,6 +277,34 @@ async function detectOpenClaw() {
|
|
|
277
277
|
return { available: false, models: [], port: null };
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
+
// Extract text from OpenClaw chat event payload (handles all known shapes)
|
|
281
|
+
function extractChatText(p) {
|
|
282
|
+
// Direct string fields
|
|
283
|
+
if (typeof p.delta === 'string') return p.delta;
|
|
284
|
+
if (typeof p.text === 'string') return p.text;
|
|
285
|
+
if (typeof p.content === 'string') return p.content;
|
|
286
|
+
if (typeof p.message === 'string') return p.message;
|
|
287
|
+
// Nested in message object
|
|
288
|
+
if (p.message && typeof p.message === 'object') {
|
|
289
|
+
if (typeof p.message.content === 'string') return p.message.content;
|
|
290
|
+
if (typeof p.message.text === 'string') return p.message.text;
|
|
291
|
+
if (typeof p.message.delta === 'string') return p.message.delta;
|
|
292
|
+
// Content array (e.g. [{ type: 'text', text: '...' }])
|
|
293
|
+
if (Array.isArray(p.message.content)) {
|
|
294
|
+
return p.message.content
|
|
295
|
+
.filter(c => c.type === 'text' && c.text)
|
|
296
|
+
.map(c => c.text)
|
|
297
|
+
.join('');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// Nested in delta object
|
|
301
|
+
if (p.delta && typeof p.delta === 'object') {
|
|
302
|
+
if (typeof p.delta.content === 'string') return p.delta.content;
|
|
303
|
+
if (typeof p.delta.text === 'string') return p.delta.text;
|
|
304
|
+
}
|
|
305
|
+
return '';
|
|
306
|
+
}
|
|
307
|
+
|
|
280
308
|
// --- OpenClaw Gateway WebSocket Client ---
|
|
281
309
|
let ocGateway = null;
|
|
282
310
|
let ocReady = false;
|
|
@@ -348,19 +376,21 @@ function connectOcGateway() {
|
|
|
348
376
|
const cb = ocChatCallbacks.get(p.runId);
|
|
349
377
|
if (!cb) return;
|
|
350
378
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
379
|
+
// Log first few events to debug payload structure
|
|
380
|
+
if (!cb._logged) {
|
|
381
|
+
console.log(` [Chat] Event payload sample:`, JSON.stringify(p).substring(0, 500));
|
|
382
|
+
cb._logged = true;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (p.state === 'delta' || p.state === 'final') {
|
|
386
|
+
const text = extractChatText(p);
|
|
359
387
|
if (text) send(cb.ws, { type: 'chat.stream', id: cb.chatId, content: text });
|
|
360
|
-
|
|
361
|
-
|
|
388
|
+
if (p.state === 'final') {
|
|
389
|
+
send(cb.ws, { type: 'chat.done', id: cb.chatId });
|
|
390
|
+
ocChatCallbacks.delete(p.runId);
|
|
391
|
+
}
|
|
362
392
|
} else if (p.state === 'error') {
|
|
363
|
-
send(cb.ws, { type: 'chat.done', id: cb.chatId, error: p.errorMessage || 'OpenClaw error' });
|
|
393
|
+
send(cb.ws, { type: 'chat.done', id: cb.chatId, error: p.errorMessage || p.error || 'OpenClaw error' });
|
|
364
394
|
ocChatCallbacks.delete(p.runId);
|
|
365
395
|
} else if (p.state === 'aborted') {
|
|
366
396
|
send(cb.ws, { type: 'chat.done', id: cb.chatId });
|
|
@@ -1204,7 +1234,7 @@ async function handleChatSend(ws, { id, messages }) {
|
|
|
1204
1234
|
// Send chat request to gateway via WebSocket protocol
|
|
1205
1235
|
const result = await ocRequest('chat.send', {
|
|
1206
1236
|
sessionKey,
|
|
1207
|
-
message:
|
|
1237
|
+
message: lastUserMsg.content,
|
|
1208
1238
|
idempotencyKey,
|
|
1209
1239
|
});
|
|
1210
1240
|
|