@openclawcity/become 1.0.28 → 1.0.30

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.cjs CHANGED
@@ -3269,6 +3269,8 @@ var SKIP_PATTERNS = [
3269
3269
  /^\[HEARTBEAT/m,
3270
3270
  /^\[Someone left you a voice message\]/m
3271
3271
  ];
3272
+ var OPENCLAW_SENDER_PATTERN = /"sender_id":\s*"([^"]+)".*?"sender":\s*"([^"]+)"/s;
3273
+ var OPENCLAW_SKIP_SENDERS = /* @__PURE__ */ new Set(["city", "owner", "system"]);
3272
3274
  function detectAgentConversation(messages) {
3273
3275
  const negative = { isAgentToAgent: false };
3274
3276
  if (!messages || messages.length === 0) return negative;
@@ -3277,6 +3279,25 @@ function detectAgentConversation(messages) {
3277
3279
  const content = contentToString(msg.content);
3278
3280
  if (!content) continue;
3279
3281
  if (SKIP_PATTERNS.some((p) => p.test(content))) continue;
3282
+ if (content.includes("untrusted metadata") || content.includes("sender_id")) {
3283
+ const senderMatch = content.match(OPENCLAW_SENDER_PATTERN);
3284
+ if (senderMatch) {
3285
+ const [, senderId, senderName] = senderMatch;
3286
+ if (!OPENCLAW_SKIP_SENDERS.has(senderId) && !OPENCLAW_SKIP_SENDERS.has(senderName.toLowerCase())) {
3287
+ let exchangeType = "chat";
3288
+ if (content.includes("[DM from")) exchangeType = "dm";
3289
+ else if (content.includes("mentioned you")) exchangeType = "mention";
3290
+ else if (content.includes("proposal")) exchangeType = "proposal";
3291
+ else if (content.includes("zone chat")) exchangeType = "chat";
3292
+ return {
3293
+ isAgentToAgent: true,
3294
+ otherAgentId: senderName,
3295
+ exchangeType
3296
+ };
3297
+ }
3298
+ }
3299
+ continue;
3300
+ }
3280
3301
  if (msg.name && msg.role === "user") {
3281
3302
  return {
3282
3303
  isAgentToAgent: true,
@@ -3360,8 +3381,29 @@ function detectAgentConversation(messages) {
3360
3381
  }
3361
3382
  return negative;
3362
3383
  }
3363
- function extractExchangeText(messages) {
3364
- return messages.filter((m) => m.role === "user" || m.role === "assistant").map((m) => {
3384
+ function extractExchangeText(messages, otherAgentId) {
3385
+ const relevant = messages.filter((m) => m.role === "user" || m.role === "assistant");
3386
+ if (otherAgentId) {
3387
+ let lastAgentMsgIndex = -1;
3388
+ for (let i = relevant.length - 1; i >= 0; i--) {
3389
+ const msg = relevant[i];
3390
+ if (msg.role !== "user") continue;
3391
+ const text = contentToString(msg.content);
3392
+ if (msg.name === otherAgentId || text.includes(otherAgentId)) {
3393
+ lastAgentMsgIndex = i;
3394
+ break;
3395
+ }
3396
+ }
3397
+ if (lastAgentMsgIndex >= 0) {
3398
+ const slice = relevant.slice(lastAgentMsgIndex, lastAgentMsgIndex + 2);
3399
+ return slice.map((m) => {
3400
+ const speaker = m.name ?? m.role;
3401
+ const content = contentToString(m.content);
3402
+ return `[${speaker}]: ${content}`;
3403
+ }).join("\n").slice(0, 6e3);
3404
+ }
3405
+ }
3406
+ return relevant.map((m) => {
3365
3407
  const speaker = m.name ?? m.role;
3366
3408
  const content = contentToString(m.content);
3367
3409
  return `[${speaker}]: ${content}`;
@@ -3392,7 +3434,7 @@ var LessonExtractor = class {
3392
3434
  const trustLevel = this.trust.getLevel(agentId);
3393
3435
  if (trustLevel === "blocked") return;
3394
3436
  if (!this.trust.canLearn(agentId)) return;
3395
- const exchangeText = extractExchangeText(messages);
3437
+ const exchangeText = extractExchangeText(messages, agentId !== "unknown-agent" ? agentId : void 0);
3396
3438
  if (exchangeText.length < 20) return;
3397
3439
  const prompt = `Analyze this conversation between an AI agent and another agent. Extract concrete, actionable lessons that the first agent (the "assistant") can learn from the other agent.
3398
3440
 
@@ -3548,7 +3590,6 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
3548
3590
  }
3549
3591
  if (config.auto_extract && extractor && Array.isArray(messages)) {
3550
3592
  extractor.extract(messages).then(() => {
3551
- stats.lessons_extracted++;
3552
3593
  }).catch(() => {
3553
3594
  });
3554
3595
  }
@@ -3557,7 +3598,6 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
3557
3598
  res.end(Buffer.from(responseBuffer));
3558
3599
  if (config.auto_extract && extractor && Array.isArray(messages)) {
3559
3600
  extractor.extract(messages).then(() => {
3560
- stats.lessons_extracted++;
3561
3601
  }).catch(() => {
3562
3602
  });
3563
3603
  }