@vectorize-io/hindsight-openclaw 0.4.9 → 0.4.10
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/dist/index.js +23 -9
- package/openclaw.plugin.json +1 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -447,15 +447,28 @@ export default function (api) {
|
|
|
447
447
|
const bankId = deriveBankId(ctx, pluginConfig);
|
|
448
448
|
console.log(`[Hindsight] before_agent_start - bank: ${bankId}, channel: ${ctx?.messageProvider}/${ctx?.channelId}`);
|
|
449
449
|
// Get the user's latest message for recall
|
|
450
|
-
|
|
450
|
+
// Prefer rawMessage (clean user text) over prompt (envelope-formatted)
|
|
451
|
+
let prompt = event.rawMessage ?? event.prompt;
|
|
451
452
|
if (!prompt || typeof prompt !== 'string' || prompt.length < 5) {
|
|
452
453
|
return; // Skip very short messages
|
|
453
454
|
}
|
|
454
|
-
//
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
455
|
+
// Strip envelope-formatted prompts from any channel
|
|
456
|
+
// The prompt may contain: System: lines, abort hints, [Channel ...] header, [from: ...] suffix
|
|
457
|
+
let cleaned = prompt;
|
|
458
|
+
// Remove leading "System: ..." lines (from prependSystemEvents)
|
|
459
|
+
cleaned = cleaned.replace(/^(?:System:.*\n)+\n?/, '');
|
|
460
|
+
// Remove session abort hint
|
|
461
|
+
cleaned = cleaned.replace(/^Note: The previous agent run was aborted[^\n]*\n\n/, '');
|
|
462
|
+
// Extract message after [ChannelName ...] envelope header
|
|
463
|
+
// Handles any channel: Telegram, Slack, Discord, WhatsApp, Signal, etc.
|
|
464
|
+
// Uses [\s\S]+ instead of .+ to support multiline messages
|
|
465
|
+
const envelopeMatch = cleaned.match(/\[[A-Z][A-Za-z]*(?:\s[^\]]+)?\]\s*([\s\S]+)$/);
|
|
466
|
+
if (envelopeMatch) {
|
|
467
|
+
cleaned = envelopeMatch[1];
|
|
458
468
|
}
|
|
469
|
+
// Remove trailing [from: SenderName] metadata (group chats)
|
|
470
|
+
cleaned = cleaned.replace(/\n\[from:[^\]]*\]\s*$/, '');
|
|
471
|
+
prompt = cleaned.trim() || prompt;
|
|
459
472
|
if (prompt.length < 5) {
|
|
460
473
|
return; // Skip very short messages after extraction
|
|
461
474
|
}
|
|
@@ -473,10 +486,10 @@ export default function (api) {
|
|
|
473
486
|
return;
|
|
474
487
|
}
|
|
475
488
|
console.log(`[Hindsight] Auto-recall for bank ${bankId}, prompt: ${prompt.substring(0, 50)}`);
|
|
476
|
-
// Recall relevant memories
|
|
489
|
+
// Recall relevant memories
|
|
477
490
|
const response = await client.recall({
|
|
478
491
|
query: prompt,
|
|
479
|
-
max_tokens:
|
|
492
|
+
max_tokens: 2048,
|
|
480
493
|
});
|
|
481
494
|
if (!response.results || response.results.length === 0) {
|
|
482
495
|
console.log('[Hindsight] No memories found for auto-recall');
|
|
@@ -547,8 +560,9 @@ User message: ${prompt}
|
|
|
547
560
|
console.log('[Hindsight Hook] Transcript too short, skipping');
|
|
548
561
|
return;
|
|
549
562
|
}
|
|
550
|
-
// Use
|
|
551
|
-
|
|
563
|
+
// Use unique document ID per conversation (sessionKey + timestamp)
|
|
564
|
+
// Static sessionKey (e.g. "agent:main:main") causes CASCADE delete of old memories
|
|
565
|
+
const documentId = `${effectiveCtx?.sessionKey || currentSessionKey || 'session'}-${Date.now()}`;
|
|
552
566
|
// Retain to Hindsight
|
|
553
567
|
await client.retain({
|
|
554
568
|
content: transcript,
|
package/openclaw.plugin.json
CHANGED
|
@@ -49,8 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"hindsightApiUrl": {
|
|
51
51
|
"type": "string",
|
|
52
|
-
"description": "External Hindsight API URL (e.g. 'https://mcp.hindsight.devcraft.team'). When set, skips local daemon and connects directly to this API."
|
|
53
|
-
"format": "uri"
|
|
52
|
+
"description": "External Hindsight API URL (e.g. 'https://mcp.hindsight.devcraft.team'). When set, skips local daemon and connects directly to this API."
|
|
54
53
|
},
|
|
55
54
|
"hindsightApiToken": {
|
|
56
55
|
"type": "string",
|
package/package.json
CHANGED