@openclawcity/become 1.0.26 → 1.0.29
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 +100 -13
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +100 -13
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +100 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +100 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -642,16 +642,50 @@ function injectSkillsIntoMessages(messages, skillText) {
|
|
|
642
642
|
}
|
|
643
643
|
|
|
644
644
|
// src/proxy/detector.ts
|
|
645
|
-
var
|
|
646
|
-
var
|
|
647
|
-
var
|
|
645
|
+
var OCC_DM_PATTERN = /^\[DM from ([^\]]+)\]:/m;
|
|
646
|
+
var OCC_MENTION_PATTERN = /^\[([^\]]+) mentioned you in building chat\]:/m;
|
|
647
|
+
var OCC_ZONE_CHAT_PATTERN = /^\[([^\]]+) in zone chat\]:/m;
|
|
648
|
+
var OCC_PROPOSAL_PATTERN = /^\[([^\]]+) (?:sent you a proposal|accepted your proposal)\]:/m;
|
|
649
|
+
var OCC_CONVERSATION_REQUEST = /^\[([^\]]+) wants to start a conversation with you\]:/m;
|
|
650
|
+
var GENERIC_CHANNEL_PATTERN = /^\[([^\]]+)\s+says?\]:\s*/m;
|
|
651
|
+
var GENERIC_DM_PATTERN = /^DM\s+from\s+([^:]+):\s*/m;
|
|
652
|
+
var BUILDING_PATTERN = /^([a-zA-Z0-9]+[-_][a-zA-Z0-9_.-]+)\s+in\s+[^:]+:\s*/m;
|
|
648
653
|
var REVIEW_KEYWORDS = ["strengths:", "weaknesses:", "verdict:", "assessment:", "suggestions:"];
|
|
654
|
+
var SKIP_PATTERNS = [
|
|
655
|
+
/^\[Your human owner says\]:/m,
|
|
656
|
+
/^\[Your human set a new mission/m,
|
|
657
|
+
/^\[HEARTBEAT/m,
|
|
658
|
+
/^\[Someone left you a voice message\]/m
|
|
659
|
+
];
|
|
660
|
+
var OPENCLAW_SENDER_PATTERN = /"sender_id":\s*"([^"]+)".*?"sender":\s*"([^"]+)"/s;
|
|
661
|
+
var OPENCLAW_SKIP_SENDERS = /* @__PURE__ */ new Set(["city", "owner", "system"]);
|
|
649
662
|
function detectAgentConversation(messages) {
|
|
650
663
|
const negative = { isAgentToAgent: false };
|
|
651
664
|
if (!messages || messages.length === 0) return negative;
|
|
652
665
|
for (const msg of messages) {
|
|
653
666
|
if (msg.role !== "user" && msg.role !== "assistant") continue;
|
|
654
|
-
const content =
|
|
667
|
+
const content = contentToString(msg.content);
|
|
668
|
+
if (!content) continue;
|
|
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
|
+
}
|
|
655
689
|
if (msg.name && msg.role === "user") {
|
|
656
690
|
return {
|
|
657
691
|
isAgentToAgent: true,
|
|
@@ -659,7 +693,47 @@ function detectAgentConversation(messages) {
|
|
|
659
693
|
exchangeType: "chat"
|
|
660
694
|
};
|
|
661
695
|
}
|
|
662
|
-
const
|
|
696
|
+
const dmMatch = content.match(OCC_DM_PATTERN);
|
|
697
|
+
if (dmMatch) {
|
|
698
|
+
return {
|
|
699
|
+
isAgentToAgent: true,
|
|
700
|
+
otherAgentId: dmMatch[1].trim(),
|
|
701
|
+
exchangeType: "dm"
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
const mentionMatch = content.match(OCC_MENTION_PATTERN);
|
|
705
|
+
if (mentionMatch) {
|
|
706
|
+
return {
|
|
707
|
+
isAgentToAgent: true,
|
|
708
|
+
otherAgentId: mentionMatch[1].trim(),
|
|
709
|
+
exchangeType: "mention"
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
const zoneMatch = content.match(OCC_ZONE_CHAT_PATTERN);
|
|
713
|
+
if (zoneMatch) {
|
|
714
|
+
return {
|
|
715
|
+
isAgentToAgent: true,
|
|
716
|
+
otherAgentId: zoneMatch[1].trim(),
|
|
717
|
+
exchangeType: "chat"
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
const proposalMatch = content.match(OCC_PROPOSAL_PATTERN);
|
|
721
|
+
if (proposalMatch) {
|
|
722
|
+
return {
|
|
723
|
+
isAgentToAgent: true,
|
|
724
|
+
otherAgentId: proposalMatch[1].trim(),
|
|
725
|
+
exchangeType: "proposal"
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
const convMatch = content.match(OCC_CONVERSATION_REQUEST);
|
|
729
|
+
if (convMatch) {
|
|
730
|
+
return {
|
|
731
|
+
isAgentToAgent: true,
|
|
732
|
+
otherAgentId: convMatch[1].trim(),
|
|
733
|
+
exchangeType: "dm"
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
const channelMatch = content.match(GENERIC_CHANNEL_PATTERN);
|
|
663
737
|
if (channelMatch) {
|
|
664
738
|
return {
|
|
665
739
|
isAgentToAgent: true,
|
|
@@ -667,11 +741,11 @@ function detectAgentConversation(messages) {
|
|
|
667
741
|
exchangeType: "channel"
|
|
668
742
|
};
|
|
669
743
|
}
|
|
670
|
-
const
|
|
671
|
-
if (
|
|
744
|
+
const genericDmMatch = content.match(GENERIC_DM_PATTERN);
|
|
745
|
+
if (genericDmMatch) {
|
|
672
746
|
return {
|
|
673
747
|
isAgentToAgent: true,
|
|
674
|
-
otherAgentId:
|
|
748
|
+
otherAgentId: genericDmMatch[1].trim(),
|
|
675
749
|
exchangeType: "dm"
|
|
676
750
|
};
|
|
677
751
|
}
|
|
@@ -698,10 +772,17 @@ function detectAgentConversation(messages) {
|
|
|
698
772
|
function extractExchangeText(messages) {
|
|
699
773
|
return messages.filter((m) => m.role === "user" || m.role === "assistant").map((m) => {
|
|
700
774
|
const speaker = m.name ?? m.role;
|
|
701
|
-
const content =
|
|
775
|
+
const content = contentToString(m.content);
|
|
702
776
|
return `[${speaker}]: ${content}`;
|
|
703
777
|
}).join("\n").slice(0, 6e3);
|
|
704
778
|
}
|
|
779
|
+
function contentToString(content) {
|
|
780
|
+
if (typeof content === "string") return content;
|
|
781
|
+
if (Array.isArray(content)) {
|
|
782
|
+
return content.filter((c) => c.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
783
|
+
}
|
|
784
|
+
return "";
|
|
785
|
+
}
|
|
705
786
|
|
|
706
787
|
// src/proxy/extractor.ts
|
|
707
788
|
var LessonExtractor = class {
|
|
@@ -826,8 +907,9 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
|
|
|
826
907
|
if (Array.isArray(messages)) {
|
|
827
908
|
for (const m of messages) {
|
|
828
909
|
if (m.role === "user" || m.role === "system") {
|
|
829
|
-
const
|
|
830
|
-
|
|
910
|
+
const text = extractText(m.content);
|
|
911
|
+
const preview = text.slice(0, 300).replace(/\n/g, "\\n");
|
|
912
|
+
console.log(`[become] msg ${m.role}${m.name ? ` name=${m.name}` : ""}: ${preview}`);
|
|
831
913
|
}
|
|
832
914
|
}
|
|
833
915
|
}
|
|
@@ -875,7 +957,6 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
|
|
|
875
957
|
}
|
|
876
958
|
if (config.auto_extract && extractor && Array.isArray(messages)) {
|
|
877
959
|
extractor.extract(messages).then(() => {
|
|
878
|
-
stats.lessons_extracted++;
|
|
879
960
|
}).catch(() => {
|
|
880
961
|
});
|
|
881
962
|
}
|
|
@@ -884,7 +965,6 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
|
|
|
884
965
|
res.end(Buffer.from(responseBuffer));
|
|
885
966
|
if (config.auto_extract && extractor && Array.isArray(messages)) {
|
|
886
967
|
extractor.extract(messages).then(() => {
|
|
887
|
-
stats.lessons_extracted++;
|
|
888
968
|
}).catch(() => {
|
|
889
969
|
});
|
|
890
970
|
}
|
|
@@ -952,6 +1032,13 @@ function buildUpstreamHeaders(config, incomingHeaders) {
|
|
|
952
1032
|
if (typeof accept === "string") headers["Accept"] = accept;
|
|
953
1033
|
return headers;
|
|
954
1034
|
}
|
|
1035
|
+
function extractText(content) {
|
|
1036
|
+
if (typeof content === "string") return content;
|
|
1037
|
+
if (Array.isArray(content)) {
|
|
1038
|
+
return content.filter((c) => c.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
1039
|
+
}
|
|
1040
|
+
return "";
|
|
1041
|
+
}
|
|
955
1042
|
|
|
956
1043
|
// src/dashboard/server.ts
|
|
957
1044
|
import { createServer as createServer2 } from "http";
|