@openclawcity/become 1.0.25 → 1.0.28

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.cjs CHANGED
@@ -681,16 +681,29 @@ function injectSkillsIntoMessages(messages, skillText) {
681
681
  }
682
682
 
683
683
  // src/proxy/detector.ts
684
- var CHANNEL_PATTERN = /^\[([^\]]+)\s+says?\]:\s*/;
685
- var DM_PATTERN = /^DM\s+from\s+([^:]+):\s*/;
686
- var BUILDING_PATTERN = /^([a-zA-Z0-9]+[-_][a-zA-Z0-9_.-]+)\s+in\s+[^:]+:\s*/;
684
+ var OCC_DM_PATTERN = /^\[DM from ([^\]]+)\]:/m;
685
+ var OCC_MENTION_PATTERN = /^\[([^\]]+) mentioned you in building chat\]:/m;
686
+ var OCC_ZONE_CHAT_PATTERN = /^\[([^\]]+) in zone chat\]:/m;
687
+ var OCC_PROPOSAL_PATTERN = /^\[([^\]]+) (?:sent you a proposal|accepted your proposal)\]:/m;
688
+ var OCC_CONVERSATION_REQUEST = /^\[([^\]]+) wants to start a conversation with you\]:/m;
689
+ var GENERIC_CHANNEL_PATTERN = /^\[([^\]]+)\s+says?\]:\s*/m;
690
+ var GENERIC_DM_PATTERN = /^DM\s+from\s+([^:]+):\s*/m;
691
+ var BUILDING_PATTERN = /^([a-zA-Z0-9]+[-_][a-zA-Z0-9_.-]+)\s+in\s+[^:]+:\s*/m;
687
692
  var REVIEW_KEYWORDS = ["strengths:", "weaknesses:", "verdict:", "assessment:", "suggestions:"];
693
+ var SKIP_PATTERNS = [
694
+ /^\[Your human owner says\]:/m,
695
+ /^\[Your human set a new mission/m,
696
+ /^\[HEARTBEAT/m,
697
+ /^\[Someone left you a voice message\]/m
698
+ ];
688
699
  function detectAgentConversation(messages) {
689
700
  const negative = { isAgentToAgent: false };
690
701
  if (!messages || messages.length === 0) return negative;
691
702
  for (const msg of messages) {
692
703
  if (msg.role !== "user" && msg.role !== "assistant") continue;
693
- const content = typeof msg.content === "string" ? msg.content : "";
704
+ const content = contentToString(msg.content);
705
+ if (!content) continue;
706
+ if (SKIP_PATTERNS.some((p) => p.test(content))) continue;
694
707
  if (msg.name && msg.role === "user") {
695
708
  return {
696
709
  isAgentToAgent: true,
@@ -698,7 +711,47 @@ function detectAgentConversation(messages) {
698
711
  exchangeType: "chat"
699
712
  };
700
713
  }
701
- const channelMatch = content.match(CHANNEL_PATTERN);
714
+ const dmMatch = content.match(OCC_DM_PATTERN);
715
+ if (dmMatch) {
716
+ return {
717
+ isAgentToAgent: true,
718
+ otherAgentId: dmMatch[1].trim(),
719
+ exchangeType: "dm"
720
+ };
721
+ }
722
+ const mentionMatch = content.match(OCC_MENTION_PATTERN);
723
+ if (mentionMatch) {
724
+ return {
725
+ isAgentToAgent: true,
726
+ otherAgentId: mentionMatch[1].trim(),
727
+ exchangeType: "mention"
728
+ };
729
+ }
730
+ const zoneMatch = content.match(OCC_ZONE_CHAT_PATTERN);
731
+ if (zoneMatch) {
732
+ return {
733
+ isAgentToAgent: true,
734
+ otherAgentId: zoneMatch[1].trim(),
735
+ exchangeType: "chat"
736
+ };
737
+ }
738
+ const proposalMatch = content.match(OCC_PROPOSAL_PATTERN);
739
+ if (proposalMatch) {
740
+ return {
741
+ isAgentToAgent: true,
742
+ otherAgentId: proposalMatch[1].trim(),
743
+ exchangeType: "proposal"
744
+ };
745
+ }
746
+ const convMatch = content.match(OCC_CONVERSATION_REQUEST);
747
+ if (convMatch) {
748
+ return {
749
+ isAgentToAgent: true,
750
+ otherAgentId: convMatch[1].trim(),
751
+ exchangeType: "dm"
752
+ };
753
+ }
754
+ const channelMatch = content.match(GENERIC_CHANNEL_PATTERN);
702
755
  if (channelMatch) {
703
756
  return {
704
757
  isAgentToAgent: true,
@@ -706,11 +759,11 @@ function detectAgentConversation(messages) {
706
759
  exchangeType: "channel"
707
760
  };
708
761
  }
709
- const dmMatch = content.match(DM_PATTERN);
710
- if (dmMatch) {
762
+ const genericDmMatch = content.match(GENERIC_DM_PATTERN);
763
+ if (genericDmMatch) {
711
764
  return {
712
765
  isAgentToAgent: true,
713
- otherAgentId: dmMatch[1].trim(),
766
+ otherAgentId: genericDmMatch[1].trim(),
714
767
  exchangeType: "dm"
715
768
  };
716
769
  }
@@ -737,10 +790,17 @@ function detectAgentConversation(messages) {
737
790
  function extractExchangeText(messages) {
738
791
  return messages.filter((m) => m.role === "user" || m.role === "assistant").map((m) => {
739
792
  const speaker = m.name ?? m.role;
740
- const content = typeof m.content === "string" ? m.content : "";
793
+ const content = contentToString(m.content);
741
794
  return `[${speaker}]: ${content}`;
742
795
  }).join("\n").slice(0, 6e3);
743
796
  }
797
+ function contentToString(content) {
798
+ if (typeof content === "string") return content;
799
+ if (Array.isArray(content)) {
800
+ return content.filter((c) => c.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
801
+ }
802
+ return "";
803
+ }
744
804
 
745
805
  // src/proxy/extractor.ts
746
806
  var LessonExtractor = class {
@@ -862,6 +922,15 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
862
922
  const rawBody = await readBody(req);
863
923
  const body = JSON.parse(rawBody);
864
924
  const messages = body.messages;
925
+ if (Array.isArray(messages)) {
926
+ for (const m of messages) {
927
+ if (m.role === "user" || m.role === "system") {
928
+ const text = extractText(m.content);
929
+ const preview = text.slice(0, 300).replace(/\n/g, "\\n");
930
+ console.log(`[become] msg ${m.role}${m.name ? ` name=${m.name}` : ""}: ${preview}`);
931
+ }
932
+ }
933
+ }
865
934
  if (Array.isArray(messages)) {
866
935
  const skills = getSkills().slice(0, config.max_skills_per_call);
867
936
  if (skills.length > 0) {
@@ -983,6 +1052,13 @@ function buildUpstreamHeaders(config, incomingHeaders) {
983
1052
  if (typeof accept === "string") headers["Accept"] = accept;
984
1053
  return headers;
985
1054
  }
1055
+ function extractText(content) {
1056
+ if (typeof content === "string") return content;
1057
+ if (Array.isArray(content)) {
1058
+ return content.filter((c) => c.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
1059
+ }
1060
+ return "";
1061
+ }
986
1062
 
987
1063
  // src/dashboard/server.ts
988
1064
  var import_node_http2 = require("http");