@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/cli.js CHANGED
@@ -657,6 +657,8 @@ var SKIP_PATTERNS = [
657
657
  /^\[HEARTBEAT/m,
658
658
  /^\[Someone left you a voice message\]/m
659
659
  ];
660
+ var OPENCLAW_SENDER_PATTERN = /"sender_id":\s*"([^"]+)".*?"sender":\s*"([^"]+)"/s;
661
+ var OPENCLAW_SKIP_SENDERS = /* @__PURE__ */ new Set(["city", "owner", "system"]);
660
662
  function detectAgentConversation(messages) {
661
663
  const negative = { isAgentToAgent: false };
662
664
  if (!messages || messages.length === 0) return negative;
@@ -665,6 +667,25 @@ function detectAgentConversation(messages) {
665
667
  const content = contentToString(msg.content);
666
668
  if (!content) continue;
667
669
  if (SKIP_PATTERNS.some((p) => p.test(content))) continue;
670
+ if (content.includes("untrusted metadata") || content.includes("sender_id")) {
671
+ const senderMatch = content.match(OPENCLAW_SENDER_PATTERN);
672
+ if (senderMatch) {
673
+ const [, senderId, senderName] = senderMatch;
674
+ if (!OPENCLAW_SKIP_SENDERS.has(senderId) && !OPENCLAW_SKIP_SENDERS.has(senderName.toLowerCase())) {
675
+ let exchangeType = "chat";
676
+ if (content.includes("[DM from")) exchangeType = "dm";
677
+ else if (content.includes("mentioned you")) exchangeType = "mention";
678
+ else if (content.includes("proposal")) exchangeType = "proposal";
679
+ else if (content.includes("zone chat")) exchangeType = "chat";
680
+ return {
681
+ isAgentToAgent: true,
682
+ otherAgentId: senderName,
683
+ exchangeType
684
+ };
685
+ }
686
+ }
687
+ continue;
688
+ }
668
689
  if (msg.name && msg.role === "user") {
669
690
  return {
670
691
  isAgentToAgent: true,
@@ -748,8 +769,29 @@ function detectAgentConversation(messages) {
748
769
  }
749
770
  return negative;
750
771
  }
751
- function extractExchangeText(messages) {
752
- return messages.filter((m) => m.role === "user" || m.role === "assistant").map((m) => {
772
+ function extractExchangeText(messages, otherAgentId) {
773
+ const relevant = messages.filter((m) => m.role === "user" || m.role === "assistant");
774
+ if (otherAgentId) {
775
+ let lastAgentMsgIndex = -1;
776
+ for (let i = relevant.length - 1; i >= 0; i--) {
777
+ const msg = relevant[i];
778
+ if (msg.role !== "user") continue;
779
+ const text = contentToString(msg.content);
780
+ if (msg.name === otherAgentId || text.includes(otherAgentId)) {
781
+ lastAgentMsgIndex = i;
782
+ break;
783
+ }
784
+ }
785
+ if (lastAgentMsgIndex >= 0) {
786
+ const slice = relevant.slice(lastAgentMsgIndex, lastAgentMsgIndex + 2);
787
+ return slice.map((m) => {
788
+ const speaker = m.name ?? m.role;
789
+ const content = contentToString(m.content);
790
+ return `[${speaker}]: ${content}`;
791
+ }).join("\n").slice(0, 6e3);
792
+ }
793
+ }
794
+ return relevant.map((m) => {
753
795
  const speaker = m.name ?? m.role;
754
796
  const content = contentToString(m.content);
755
797
  return `[${speaker}]: ${content}`;
@@ -780,7 +822,7 @@ var LessonExtractor = class {
780
822
  const trustLevel = this.trust.getLevel(agentId);
781
823
  if (trustLevel === "blocked") return;
782
824
  if (!this.trust.canLearn(agentId)) return;
783
- const exchangeText = extractExchangeText(messages);
825
+ const exchangeText = extractExchangeText(messages, agentId !== "unknown-agent" ? agentId : void 0);
784
826
  if (exchangeText.length < 20) return;
785
827
  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.
786
828
 
@@ -936,7 +978,6 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
936
978
  }
937
979
  if (config.auto_extract && extractor && Array.isArray(messages)) {
938
980
  extractor.extract(messages).then(() => {
939
- stats.lessons_extracted++;
940
981
  }).catch(() => {
941
982
  });
942
983
  }
@@ -945,7 +986,6 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
945
986
  res.end(Buffer.from(responseBuffer));
946
987
  if (config.auto_extract && extractor && Array.isArray(messages)) {
947
988
  extractor.extract(messages).then(() => {
948
- stats.lessons_extracted++;
949
989
  }).catch(() => {
950
990
  });
951
991
  }