@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/index.cjs
CHANGED
|
@@ -3254,16 +3254,50 @@ function injectSkillsIntoMessages(messages, skillText) {
|
|
|
3254
3254
|
}
|
|
3255
3255
|
|
|
3256
3256
|
// src/proxy/detector.ts
|
|
3257
|
-
var
|
|
3258
|
-
var
|
|
3259
|
-
var
|
|
3257
|
+
var OCC_DM_PATTERN = /^\[DM from ([^\]]+)\]:/m;
|
|
3258
|
+
var OCC_MENTION_PATTERN = /^\[([^\]]+) mentioned you in building chat\]:/m;
|
|
3259
|
+
var OCC_ZONE_CHAT_PATTERN = /^\[([^\]]+) in zone chat\]:/m;
|
|
3260
|
+
var OCC_PROPOSAL_PATTERN = /^\[([^\]]+) (?:sent you a proposal|accepted your proposal)\]:/m;
|
|
3261
|
+
var OCC_CONVERSATION_REQUEST = /^\[([^\]]+) wants to start a conversation with you\]:/m;
|
|
3262
|
+
var GENERIC_CHANNEL_PATTERN = /^\[([^\]]+)\s+says?\]:\s*/m;
|
|
3263
|
+
var GENERIC_DM_PATTERN = /^DM\s+from\s+([^:]+):\s*/m;
|
|
3264
|
+
var BUILDING_PATTERN = /^([a-zA-Z0-9]+[-_][a-zA-Z0-9_.-]+)\s+in\s+[^:]+:\s*/m;
|
|
3260
3265
|
var REVIEW_KEYWORDS = ["strengths:", "weaknesses:", "verdict:", "assessment:", "suggestions:"];
|
|
3266
|
+
var SKIP_PATTERNS = [
|
|
3267
|
+
/^\[Your human owner says\]:/m,
|
|
3268
|
+
/^\[Your human set a new mission/m,
|
|
3269
|
+
/^\[HEARTBEAT/m,
|
|
3270
|
+
/^\[Someone left you a voice message\]/m
|
|
3271
|
+
];
|
|
3272
|
+
var OPENCLAW_SENDER_PATTERN = /"sender_id":\s*"([^"]+)".*?"sender":\s*"([^"]+)"/s;
|
|
3273
|
+
var OPENCLAW_SKIP_SENDERS = /* @__PURE__ */ new Set(["city", "owner", "system"]);
|
|
3261
3274
|
function detectAgentConversation(messages) {
|
|
3262
3275
|
const negative = { isAgentToAgent: false };
|
|
3263
3276
|
if (!messages || messages.length === 0) return negative;
|
|
3264
3277
|
for (const msg of messages) {
|
|
3265
3278
|
if (msg.role !== "user" && msg.role !== "assistant") continue;
|
|
3266
|
-
const content =
|
|
3279
|
+
const content = contentToString(msg.content);
|
|
3280
|
+
if (!content) continue;
|
|
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
|
+
}
|
|
3267
3301
|
if (msg.name && msg.role === "user") {
|
|
3268
3302
|
return {
|
|
3269
3303
|
isAgentToAgent: true,
|
|
@@ -3271,7 +3305,47 @@ function detectAgentConversation(messages) {
|
|
|
3271
3305
|
exchangeType: "chat"
|
|
3272
3306
|
};
|
|
3273
3307
|
}
|
|
3274
|
-
const
|
|
3308
|
+
const dmMatch = content.match(OCC_DM_PATTERN);
|
|
3309
|
+
if (dmMatch) {
|
|
3310
|
+
return {
|
|
3311
|
+
isAgentToAgent: true,
|
|
3312
|
+
otherAgentId: dmMatch[1].trim(),
|
|
3313
|
+
exchangeType: "dm"
|
|
3314
|
+
};
|
|
3315
|
+
}
|
|
3316
|
+
const mentionMatch = content.match(OCC_MENTION_PATTERN);
|
|
3317
|
+
if (mentionMatch) {
|
|
3318
|
+
return {
|
|
3319
|
+
isAgentToAgent: true,
|
|
3320
|
+
otherAgentId: mentionMatch[1].trim(),
|
|
3321
|
+
exchangeType: "mention"
|
|
3322
|
+
};
|
|
3323
|
+
}
|
|
3324
|
+
const zoneMatch = content.match(OCC_ZONE_CHAT_PATTERN);
|
|
3325
|
+
if (zoneMatch) {
|
|
3326
|
+
return {
|
|
3327
|
+
isAgentToAgent: true,
|
|
3328
|
+
otherAgentId: zoneMatch[1].trim(),
|
|
3329
|
+
exchangeType: "chat"
|
|
3330
|
+
};
|
|
3331
|
+
}
|
|
3332
|
+
const proposalMatch = content.match(OCC_PROPOSAL_PATTERN);
|
|
3333
|
+
if (proposalMatch) {
|
|
3334
|
+
return {
|
|
3335
|
+
isAgentToAgent: true,
|
|
3336
|
+
otherAgentId: proposalMatch[1].trim(),
|
|
3337
|
+
exchangeType: "proposal"
|
|
3338
|
+
};
|
|
3339
|
+
}
|
|
3340
|
+
const convMatch = content.match(OCC_CONVERSATION_REQUEST);
|
|
3341
|
+
if (convMatch) {
|
|
3342
|
+
return {
|
|
3343
|
+
isAgentToAgent: true,
|
|
3344
|
+
otherAgentId: convMatch[1].trim(),
|
|
3345
|
+
exchangeType: "dm"
|
|
3346
|
+
};
|
|
3347
|
+
}
|
|
3348
|
+
const channelMatch = content.match(GENERIC_CHANNEL_PATTERN);
|
|
3275
3349
|
if (channelMatch) {
|
|
3276
3350
|
return {
|
|
3277
3351
|
isAgentToAgent: true,
|
|
@@ -3279,11 +3353,11 @@ function detectAgentConversation(messages) {
|
|
|
3279
3353
|
exchangeType: "channel"
|
|
3280
3354
|
};
|
|
3281
3355
|
}
|
|
3282
|
-
const
|
|
3283
|
-
if (
|
|
3356
|
+
const genericDmMatch = content.match(GENERIC_DM_PATTERN);
|
|
3357
|
+
if (genericDmMatch) {
|
|
3284
3358
|
return {
|
|
3285
3359
|
isAgentToAgent: true,
|
|
3286
|
-
otherAgentId:
|
|
3360
|
+
otherAgentId: genericDmMatch[1].trim(),
|
|
3287
3361
|
exchangeType: "dm"
|
|
3288
3362
|
};
|
|
3289
3363
|
}
|
|
@@ -3310,10 +3384,17 @@ function detectAgentConversation(messages) {
|
|
|
3310
3384
|
function extractExchangeText(messages) {
|
|
3311
3385
|
return messages.filter((m) => m.role === "user" || m.role === "assistant").map((m) => {
|
|
3312
3386
|
const speaker = m.name ?? m.role;
|
|
3313
|
-
const content =
|
|
3387
|
+
const content = contentToString(m.content);
|
|
3314
3388
|
return `[${speaker}]: ${content}`;
|
|
3315
3389
|
}).join("\n").slice(0, 6e3);
|
|
3316
3390
|
}
|
|
3391
|
+
function contentToString(content) {
|
|
3392
|
+
if (typeof content === "string") return content;
|
|
3393
|
+
if (Array.isArray(content)) {
|
|
3394
|
+
return content.filter((c) => c.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
3395
|
+
}
|
|
3396
|
+
return "";
|
|
3397
|
+
}
|
|
3317
3398
|
|
|
3318
3399
|
// src/proxy/extractor.ts
|
|
3319
3400
|
var LessonExtractor = class {
|
|
@@ -3438,8 +3519,9 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
|
|
|
3438
3519
|
if (Array.isArray(messages)) {
|
|
3439
3520
|
for (const m of messages) {
|
|
3440
3521
|
if (m.role === "user" || m.role === "system") {
|
|
3441
|
-
const
|
|
3442
|
-
|
|
3522
|
+
const text = extractText(m.content);
|
|
3523
|
+
const preview = text.slice(0, 300).replace(/\n/g, "\\n");
|
|
3524
|
+
console.log(`[become] msg ${m.role}${m.name ? ` name=${m.name}` : ""}: ${preview}`);
|
|
3443
3525
|
}
|
|
3444
3526
|
}
|
|
3445
3527
|
}
|
|
@@ -3487,7 +3569,6 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
|
|
|
3487
3569
|
}
|
|
3488
3570
|
if (config.auto_extract && extractor && Array.isArray(messages)) {
|
|
3489
3571
|
extractor.extract(messages).then(() => {
|
|
3490
|
-
stats.lessons_extracted++;
|
|
3491
3572
|
}).catch(() => {
|
|
3492
3573
|
});
|
|
3493
3574
|
}
|
|
@@ -3496,7 +3577,6 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
|
|
|
3496
3577
|
res.end(Buffer.from(responseBuffer));
|
|
3497
3578
|
if (config.auto_extract && extractor && Array.isArray(messages)) {
|
|
3498
3579
|
extractor.extract(messages).then(() => {
|
|
3499
|
-
stats.lessons_extracted++;
|
|
3500
3580
|
}).catch(() => {
|
|
3501
3581
|
});
|
|
3502
3582
|
}
|
|
@@ -3564,6 +3644,13 @@ function buildUpstreamHeaders(config, incomingHeaders) {
|
|
|
3564
3644
|
if (typeof accept === "string") headers["Accept"] = accept;
|
|
3565
3645
|
return headers;
|
|
3566
3646
|
}
|
|
3647
|
+
function extractText(content) {
|
|
3648
|
+
if (typeof content === "string") return content;
|
|
3649
|
+
if (Array.isArray(content)) {
|
|
3650
|
+
return content.filter((c) => c.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
3651
|
+
}
|
|
3652
|
+
return "";
|
|
3653
|
+
}
|
|
3567
3654
|
|
|
3568
3655
|
// src/integrations/openclawcity.ts
|
|
3569
3656
|
function emptySkillEvidence() {
|