too-many-claw 1.0.21 → 1.0.22
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/cli.js +83 -10
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +83 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2817,7 +2817,8 @@ var BotMessageMonitor = class extends EventEmitter2 {
|
|
|
2817
2817
|
agentId,
|
|
2818
2818
|
timestamp: Date.now()
|
|
2819
2819
|
});
|
|
2820
|
-
this.
|
|
2820
|
+
this.forceLog(`\u{1F4DD} Registered pending: ${agentId} \u2192 "${content.substring(0, 40)}..."`);
|
|
2821
|
+
this.log(` Hash: ${hash.substring(0, 50)}`);
|
|
2821
2822
|
this.cleanupPendingMessages();
|
|
2822
2823
|
}
|
|
2823
2824
|
/**
|
|
@@ -2851,9 +2852,12 @@ var BotMessageMonitor = class extends EventEmitter2 {
|
|
|
2851
2852
|
lookupPendingAgent(content) {
|
|
2852
2853
|
const hash = this.hashContent(content);
|
|
2853
2854
|
const pending = this.pendingMessages.get(hash);
|
|
2855
|
+
this.log(`Looking up agent for content: "${content.substring(0, 40)}..."`);
|
|
2856
|
+
this.log(` Generated hash: ${hash.substring(0, 50)}`);
|
|
2857
|
+
this.log(` Pending messages count: ${this.pendingMessages.size}`);
|
|
2854
2858
|
if (pending && Date.now() - pending.timestamp < this.PENDING_MESSAGE_TTL) {
|
|
2855
2859
|
this.pendingMessages.delete(hash);
|
|
2856
|
-
this.
|
|
2860
|
+
this.forceLog(`\u2713 Found pending agent ${pending.agentId} via exact hash match`);
|
|
2857
2861
|
return pending.agentId;
|
|
2858
2862
|
}
|
|
2859
2863
|
const normalizedContent = content.trim().toLowerCase();
|
|
@@ -2862,11 +2866,17 @@ var BotMessageMonitor = class extends EventEmitter2 {
|
|
|
2862
2866
|
if (normalizedContent.includes(pendingContent.substring(0, 100)) || pendingContent.includes(normalizedContent.substring(0, 100))) {
|
|
2863
2867
|
if (Date.now() - data.timestamp < this.PENDING_MESSAGE_TTL) {
|
|
2864
2868
|
this.pendingMessages.delete(pendingHash);
|
|
2865
|
-
this.
|
|
2869
|
+
this.forceLog(`\u2713 Found pending agent ${data.agentId} via partial match`);
|
|
2866
2870
|
return data.agentId;
|
|
2867
2871
|
}
|
|
2868
2872
|
}
|
|
2869
2873
|
}
|
|
2874
|
+
if (this.pendingMessages.size > 0) {
|
|
2875
|
+
this.log(`No match found. Current pending messages:`);
|
|
2876
|
+
for (const [pendingHash, data] of this.pendingMessages) {
|
|
2877
|
+
this.log(` - ${data.agentId}: ${pendingHash.substring(0, 50)}...`);
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2870
2880
|
return null;
|
|
2871
2881
|
}
|
|
2872
2882
|
/**
|
|
@@ -2928,12 +2938,12 @@ var BotMessageMonitor = class extends EventEmitter2 {
|
|
|
2928
2938
|
if (pendingAgentId) {
|
|
2929
2939
|
agent = this.agentMapper.resolve(pendingAgentId) || this.agentMapper.getDefaultAgent();
|
|
2930
2940
|
cleanContent = message.content;
|
|
2931
|
-
this.
|
|
2941
|
+
this.forceLog(`\u2192 Using agent ${agent.emoji} ${agent.name} from Gateway event`);
|
|
2932
2942
|
} else {
|
|
2933
2943
|
const extracted = this.extractAgentFromContent(message.content);
|
|
2934
2944
|
agent = extracted.agent;
|
|
2935
2945
|
cleanContent = extracted.cleanContent;
|
|
2936
|
-
this.
|
|
2946
|
+
this.forceLog(`\u2192 Using agent ${agent.emoji} ${agent.name} from content extraction (fallback)`);
|
|
2937
2947
|
}
|
|
2938
2948
|
this.emit("intercepted", message.id, message.channel.id, agent.id);
|
|
2939
2949
|
this.forceLog(`\u{1F980} Intercepted message \u2192 ${agent.emoji} ${agent.name}`);
|
|
@@ -3086,6 +3096,10 @@ var AgentMapper = class {
|
|
|
3086
3096
|
this.idMap.set(agent.id.toLowerCase(), agent);
|
|
3087
3097
|
const normalizedName = this.normalizeName(agent.name);
|
|
3088
3098
|
this.nameMap.set(normalizedName, agent);
|
|
3099
|
+
const openClawName = `${agent.emoji} ${agent.name}`.toLowerCase();
|
|
3100
|
+
this.nameMap.set(openClawName, agent);
|
|
3101
|
+
this.nameMap.set(this.normalizeName(openClawName), agent);
|
|
3102
|
+
this.aliasMap.set(agent.emoji, agent);
|
|
3089
3103
|
this.buildAliases(agent);
|
|
3090
3104
|
}
|
|
3091
3105
|
}
|
|
@@ -3136,9 +3150,18 @@ var AgentMapper = class {
|
|
|
3136
3150
|
if (!identifier) {
|
|
3137
3151
|
return this.getDefaultAgent();
|
|
3138
3152
|
}
|
|
3139
|
-
|
|
3153
|
+
let cleanIdentifier = identifier.trim();
|
|
3154
|
+
const emojiMatch = cleanIdentifier.match(/^([\p{Emoji}])\s*/u);
|
|
3155
|
+
if (emojiMatch) {
|
|
3156
|
+
const emoji = emojiMatch[1];
|
|
3157
|
+
const byEmoji = this.aliasMap.get(emoji);
|
|
3158
|
+
if (byEmoji) return byEmoji;
|
|
3159
|
+
}
|
|
3160
|
+
const normalized = cleanIdentifier.toLowerCase().trim();
|
|
3140
3161
|
const byId = this.idMap.get(normalized);
|
|
3141
3162
|
if (byId) return byId;
|
|
3163
|
+
const byOpenClawName = this.nameMap.get(normalized);
|
|
3164
|
+
if (byOpenClawName) return byOpenClawName;
|
|
3142
3165
|
const byName = this.nameMap.get(this.normalizeName(identifier));
|
|
3143
3166
|
if (byName) return byName;
|
|
3144
3167
|
const byAlias = this.aliasMap.get(normalized);
|
|
@@ -3453,9 +3476,12 @@ var OpenClawDaemon = class extends EventEmitter3 {
|
|
|
3453
3476
|
*/
|
|
3454
3477
|
registerPendingMessageForMonitor(message) {
|
|
3455
3478
|
if (!this.botMessageMonitor) return;
|
|
3456
|
-
const agentIdentifier =
|
|
3479
|
+
const agentIdentifier = this.extractAgentIdentifier(message);
|
|
3457
3480
|
const agent = this.agentMapper.resolve(agentIdentifier);
|
|
3458
3481
|
const agentId = agent?.id || "base";
|
|
3482
|
+
if (this.config.verbose) {
|
|
3483
|
+
this.log(`registerPendingMessageForMonitor - identifier: ${agentIdentifier}, resolved to: ${agentId}`);
|
|
3484
|
+
}
|
|
3459
3485
|
let content = "";
|
|
3460
3486
|
if (typeof message.content === "string") {
|
|
3461
3487
|
content = message.content;
|
|
@@ -3487,6 +3513,15 @@ var OpenClawDaemon = class extends EventEmitter3 {
|
|
|
3487
3513
|
if (message.stream) {
|
|
3488
3514
|
this.log(` Stream: ${message.stream}`);
|
|
3489
3515
|
}
|
|
3516
|
+
if (message.agentId) {
|
|
3517
|
+
this.log(` AgentId: ${message.agentId}`);
|
|
3518
|
+
}
|
|
3519
|
+
if (message.runId) {
|
|
3520
|
+
this.log(` RunId: ${message.runId}`);
|
|
3521
|
+
}
|
|
3522
|
+
if (message.data) {
|
|
3523
|
+
this.log(` Data keys: ${Object.keys(message.data).join(", ")}`);
|
|
3524
|
+
}
|
|
3490
3525
|
}
|
|
3491
3526
|
}
|
|
3492
3527
|
/**
|
|
@@ -3495,7 +3530,10 @@ var OpenClawDaemon = class extends EventEmitter3 {
|
|
|
3495
3530
|
* because the message_sent event handler will intercept and resend via webhook.
|
|
3496
3531
|
*/
|
|
3497
3532
|
async handleAgentResponse(message) {
|
|
3498
|
-
const agentIdentifier =
|
|
3533
|
+
const agentIdentifier = this.extractAgentIdentifier(message);
|
|
3534
|
+
if (this.config.verbose) {
|
|
3535
|
+
this.log(`Agent response - extracted identifier: ${agentIdentifier}`);
|
|
3536
|
+
}
|
|
3499
3537
|
let content = "";
|
|
3500
3538
|
if (typeof message.content === "string") {
|
|
3501
3539
|
content = message.content;
|
|
@@ -3517,11 +3555,43 @@ var OpenClawDaemon = class extends EventEmitter3 {
|
|
|
3517
3555
|
}
|
|
3518
3556
|
await this.forwardToWebhook(agent, content);
|
|
3519
3557
|
}
|
|
3558
|
+
/**
|
|
3559
|
+
* Extract agent identifier from OpenClaw Gateway message
|
|
3560
|
+
* Checks multiple fields since OpenClaw may send agent info in different places
|
|
3561
|
+
*/
|
|
3562
|
+
extractAgentIdentifier(message) {
|
|
3563
|
+
if (message.agentId) return message.agentId;
|
|
3564
|
+
if (message.agentName) return message.agentName;
|
|
3565
|
+
if (message.agent) return message.agent;
|
|
3566
|
+
if (message.name) return message.name;
|
|
3567
|
+
const data = message.data;
|
|
3568
|
+
if (data) {
|
|
3569
|
+
if (data.agentId) return data.agentId;
|
|
3570
|
+
if (data.agentName) return data.agentName;
|
|
3571
|
+
if (data.agent) return data.agent;
|
|
3572
|
+
if (data.name) return data.name;
|
|
3573
|
+
}
|
|
3574
|
+
const runId = message.id || message.runId;
|
|
3575
|
+
if (runId && typeof runId === "string") {
|
|
3576
|
+
const runIdMatch = runId.match(/^([a-z][a-z0-9-]*)-[a-z0-9]+$/i);
|
|
3577
|
+
if (runIdMatch) {
|
|
3578
|
+
const potentialAgent = runIdMatch[1];
|
|
3579
|
+
if (this.agentMapper.resolve(potentialAgent)) {
|
|
3580
|
+
return potentialAgent;
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
if (this.config.verbose) {
|
|
3585
|
+
this.log(`Could not extract agent from message. Keys: ${Object.keys(message).join(", ")}`);
|
|
3586
|
+
this.log(` Full message: ${JSON.stringify(message).substring(0, 300)}`);
|
|
3587
|
+
}
|
|
3588
|
+
return "assistant";
|
|
3589
|
+
}
|
|
3520
3590
|
/**
|
|
3521
3591
|
* Handle streaming delta (partial response)
|
|
3522
3592
|
*/
|
|
3523
3593
|
handleAgentDelta(message) {
|
|
3524
|
-
const agentIdentifier =
|
|
3594
|
+
const agentIdentifier = this.extractAgentIdentifier(message);
|
|
3525
3595
|
let delta = "";
|
|
3526
3596
|
if (typeof message.delta === "string") {
|
|
3527
3597
|
delta = message.delta;
|
|
@@ -3573,7 +3643,10 @@ var OpenClawDaemon = class extends EventEmitter3 {
|
|
|
3573
3643
|
*/
|
|
3574
3644
|
async handleAgentEnd(message) {
|
|
3575
3645
|
const messageId = message.id || message.runId || message.agentId || message.agentName || "default";
|
|
3576
|
-
const agentIdentifier =
|
|
3646
|
+
const agentIdentifier = this.extractAgentIdentifier(message);
|
|
3647
|
+
if (this.config.verbose) {
|
|
3648
|
+
this.log(`Agent end - messageId: ${messageId}, extracted identifier: ${agentIdentifier}`);
|
|
3649
|
+
}
|
|
3577
3650
|
this.log(`Agent end event [${messageId}] from: ${agentIdentifier}`);
|
|
3578
3651
|
const skipWebhook = this.botMessageMonitor && this.botMessageMonitor.isEnabled();
|
|
3579
3652
|
const buffered = this.responseBuffers.get(messageId);
|