@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/index.d.cts CHANGED
@@ -847,11 +847,11 @@ declare function createProxyServer(config: ProxyConfig, analyzer?: ConversationA
847
847
  interface DetectionResult {
848
848
  isAgentToAgent: boolean;
849
849
  otherAgentId?: string;
850
- exchangeType?: 'channel' | 'dm' | 'peer_review' | 'collaboration' | 'chat';
850
+ exchangeType?: 'channel' | 'dm' | 'peer_review' | 'collaboration' | 'chat' | 'mention' | 'proposal';
851
851
  }
852
852
  declare function detectAgentConversation(messages: {
853
853
  role: string;
854
- content: string;
854
+ content: unknown;
855
855
  name?: string;
856
856
  }[]): DetectionResult;
857
857
  /**
@@ -859,7 +859,7 @@ declare function detectAgentConversation(messages: {
859
859
  */
860
860
  declare function extractExchangeText(messages: {
861
861
  role: string;
862
- content: string;
862
+ content: unknown;
863
863
  name?: string;
864
864
  }[]): string;
865
865
 
@@ -878,7 +878,7 @@ declare class LessonExtractor {
878
878
  */
879
879
  extract(messages: {
880
880
  role: string;
881
- content: string;
881
+ content: unknown;
882
882
  name?: string;
883
883
  }[]): Promise<void>;
884
884
  private parseLessons;
package/dist/index.d.ts CHANGED
@@ -847,11 +847,11 @@ declare function createProxyServer(config: ProxyConfig, analyzer?: ConversationA
847
847
  interface DetectionResult {
848
848
  isAgentToAgent: boolean;
849
849
  otherAgentId?: string;
850
- exchangeType?: 'channel' | 'dm' | 'peer_review' | 'collaboration' | 'chat';
850
+ exchangeType?: 'channel' | 'dm' | 'peer_review' | 'collaboration' | 'chat' | 'mention' | 'proposal';
851
851
  }
852
852
  declare function detectAgentConversation(messages: {
853
853
  role: string;
854
- content: string;
854
+ content: unknown;
855
855
  name?: string;
856
856
  }[]): DetectionResult;
857
857
  /**
@@ -859,7 +859,7 @@ declare function detectAgentConversation(messages: {
859
859
  */
860
860
  declare function extractExchangeText(messages: {
861
861
  role: string;
862
- content: string;
862
+ content: unknown;
863
863
  name?: string;
864
864
  }[]): string;
865
865
 
@@ -878,7 +878,7 @@ declare class LessonExtractor {
878
878
  */
879
879
  extract(messages: {
880
880
  role: string;
881
- content: string;
881
+ content: unknown;
882
882
  name?: string;
883
883
  }[]): Promise<void>;
884
884
  private parseLessons;
package/dist/index.js CHANGED
@@ -3181,16 +3181,50 @@ function injectSkillsIntoMessages(messages, skillText) {
3181
3181
  }
3182
3182
 
3183
3183
  // src/proxy/detector.ts
3184
- var CHANNEL_PATTERN = /^\[([^\]]+)\s+says?\]:\s*/;
3185
- var DM_PATTERN = /^DM\s+from\s+([^:]+):\s*/;
3186
- var BUILDING_PATTERN = /^([a-zA-Z0-9]+[-_][a-zA-Z0-9_.-]+)\s+in\s+[^:]+:\s*/;
3184
+ var OCC_DM_PATTERN = /^\[DM from ([^\]]+)\]:/m;
3185
+ var OCC_MENTION_PATTERN = /^\[([^\]]+) mentioned you in building chat\]:/m;
3186
+ var OCC_ZONE_CHAT_PATTERN = /^\[([^\]]+) in zone chat\]:/m;
3187
+ var OCC_PROPOSAL_PATTERN = /^\[([^\]]+) (?:sent you a proposal|accepted your proposal)\]:/m;
3188
+ var OCC_CONVERSATION_REQUEST = /^\[([^\]]+) wants to start a conversation with you\]:/m;
3189
+ var GENERIC_CHANNEL_PATTERN = /^\[([^\]]+)\s+says?\]:\s*/m;
3190
+ var GENERIC_DM_PATTERN = /^DM\s+from\s+([^:]+):\s*/m;
3191
+ var BUILDING_PATTERN = /^([a-zA-Z0-9]+[-_][a-zA-Z0-9_.-]+)\s+in\s+[^:]+:\s*/m;
3187
3192
  var REVIEW_KEYWORDS = ["strengths:", "weaknesses:", "verdict:", "assessment:", "suggestions:"];
3193
+ var SKIP_PATTERNS = [
3194
+ /^\[Your human owner says\]:/m,
3195
+ /^\[Your human set a new mission/m,
3196
+ /^\[HEARTBEAT/m,
3197
+ /^\[Someone left you a voice message\]/m
3198
+ ];
3199
+ var OPENCLAW_SENDER_PATTERN = /"sender_id":\s*"([^"]+)".*?"sender":\s*"([^"]+)"/s;
3200
+ var OPENCLAW_SKIP_SENDERS = /* @__PURE__ */ new Set(["city", "owner", "system"]);
3188
3201
  function detectAgentConversation(messages) {
3189
3202
  const negative = { isAgentToAgent: false };
3190
3203
  if (!messages || messages.length === 0) return negative;
3191
3204
  for (const msg of messages) {
3192
3205
  if (msg.role !== "user" && msg.role !== "assistant") continue;
3193
- const content = typeof msg.content === "string" ? msg.content : "";
3206
+ const content = contentToString(msg.content);
3207
+ if (!content) continue;
3208
+ if (SKIP_PATTERNS.some((p) => p.test(content))) continue;
3209
+ if (content.includes("untrusted metadata") || content.includes("sender_id")) {
3210
+ const senderMatch = content.match(OPENCLAW_SENDER_PATTERN);
3211
+ if (senderMatch) {
3212
+ const [, senderId, senderName] = senderMatch;
3213
+ if (!OPENCLAW_SKIP_SENDERS.has(senderId) && !OPENCLAW_SKIP_SENDERS.has(senderName.toLowerCase())) {
3214
+ let exchangeType = "chat";
3215
+ if (content.includes("[DM from")) exchangeType = "dm";
3216
+ else if (content.includes("mentioned you")) exchangeType = "mention";
3217
+ else if (content.includes("proposal")) exchangeType = "proposal";
3218
+ else if (content.includes("zone chat")) exchangeType = "chat";
3219
+ return {
3220
+ isAgentToAgent: true,
3221
+ otherAgentId: senderName,
3222
+ exchangeType
3223
+ };
3224
+ }
3225
+ }
3226
+ continue;
3227
+ }
3194
3228
  if (msg.name && msg.role === "user") {
3195
3229
  return {
3196
3230
  isAgentToAgent: true,
@@ -3198,7 +3232,47 @@ function detectAgentConversation(messages) {
3198
3232
  exchangeType: "chat"
3199
3233
  };
3200
3234
  }
3201
- const channelMatch = content.match(CHANNEL_PATTERN);
3235
+ const dmMatch = content.match(OCC_DM_PATTERN);
3236
+ if (dmMatch) {
3237
+ return {
3238
+ isAgentToAgent: true,
3239
+ otherAgentId: dmMatch[1].trim(),
3240
+ exchangeType: "dm"
3241
+ };
3242
+ }
3243
+ const mentionMatch = content.match(OCC_MENTION_PATTERN);
3244
+ if (mentionMatch) {
3245
+ return {
3246
+ isAgentToAgent: true,
3247
+ otherAgentId: mentionMatch[1].trim(),
3248
+ exchangeType: "mention"
3249
+ };
3250
+ }
3251
+ const zoneMatch = content.match(OCC_ZONE_CHAT_PATTERN);
3252
+ if (zoneMatch) {
3253
+ return {
3254
+ isAgentToAgent: true,
3255
+ otherAgentId: zoneMatch[1].trim(),
3256
+ exchangeType: "chat"
3257
+ };
3258
+ }
3259
+ const proposalMatch = content.match(OCC_PROPOSAL_PATTERN);
3260
+ if (proposalMatch) {
3261
+ return {
3262
+ isAgentToAgent: true,
3263
+ otherAgentId: proposalMatch[1].trim(),
3264
+ exchangeType: "proposal"
3265
+ };
3266
+ }
3267
+ const convMatch = content.match(OCC_CONVERSATION_REQUEST);
3268
+ if (convMatch) {
3269
+ return {
3270
+ isAgentToAgent: true,
3271
+ otherAgentId: convMatch[1].trim(),
3272
+ exchangeType: "dm"
3273
+ };
3274
+ }
3275
+ const channelMatch = content.match(GENERIC_CHANNEL_PATTERN);
3202
3276
  if (channelMatch) {
3203
3277
  return {
3204
3278
  isAgentToAgent: true,
@@ -3206,11 +3280,11 @@ function detectAgentConversation(messages) {
3206
3280
  exchangeType: "channel"
3207
3281
  };
3208
3282
  }
3209
- const dmMatch = content.match(DM_PATTERN);
3210
- if (dmMatch) {
3283
+ const genericDmMatch = content.match(GENERIC_DM_PATTERN);
3284
+ if (genericDmMatch) {
3211
3285
  return {
3212
3286
  isAgentToAgent: true,
3213
- otherAgentId: dmMatch[1].trim(),
3287
+ otherAgentId: genericDmMatch[1].trim(),
3214
3288
  exchangeType: "dm"
3215
3289
  };
3216
3290
  }
@@ -3237,10 +3311,17 @@ function detectAgentConversation(messages) {
3237
3311
  function extractExchangeText(messages) {
3238
3312
  return messages.filter((m) => m.role === "user" || m.role === "assistant").map((m) => {
3239
3313
  const speaker = m.name ?? m.role;
3240
- const content = typeof m.content === "string" ? m.content : "";
3314
+ const content = contentToString(m.content);
3241
3315
  return `[${speaker}]: ${content}`;
3242
3316
  }).join("\n").slice(0, 6e3);
3243
3317
  }
3318
+ function contentToString(content) {
3319
+ if (typeof content === "string") return content;
3320
+ if (Array.isArray(content)) {
3321
+ return content.filter((c) => c.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
3322
+ }
3323
+ return "";
3324
+ }
3244
3325
 
3245
3326
  // src/proxy/extractor.ts
3246
3327
  var LessonExtractor = class {
@@ -3365,8 +3446,9 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
3365
3446
  if (Array.isArray(messages)) {
3366
3447
  for (const m of messages) {
3367
3448
  if (m.role === "user" || m.role === "system") {
3368
- const preview = typeof m.content === "string" ? m.content.slice(0, 200) : "(non-string)";
3369
- console.log(`[become] msg ${m.role}${m.name ? ` name=${m.name}` : ""}: ${preview.replace(/\n/g, "\\n")}`);
3449
+ const text = extractText(m.content);
3450
+ const preview = text.slice(0, 300).replace(/\n/g, "\\n");
3451
+ console.log(`[become] msg ${m.role}${m.name ? ` name=${m.name}` : ""}: ${preview}`);
3370
3452
  }
3371
3453
  }
3372
3454
  }
@@ -3414,7 +3496,6 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
3414
3496
  }
3415
3497
  if (config.auto_extract && extractor && Array.isArray(messages)) {
3416
3498
  extractor.extract(messages).then(() => {
3417
- stats.lessons_extracted++;
3418
3499
  }).catch(() => {
3419
3500
  });
3420
3501
  }
@@ -3423,7 +3504,6 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
3423
3504
  res.end(Buffer.from(responseBuffer));
3424
3505
  if (config.auto_extract && extractor && Array.isArray(messages)) {
3425
3506
  extractor.extract(messages).then(() => {
3426
- stats.lessons_extracted++;
3427
3507
  }).catch(() => {
3428
3508
  });
3429
3509
  }
@@ -3491,6 +3571,13 @@ function buildUpstreamHeaders(config, incomingHeaders) {
3491
3571
  if (typeof accept === "string") headers["Accept"] = accept;
3492
3572
  return headers;
3493
3573
  }
3574
+ function extractText(content) {
3575
+ if (typeof content === "string") return content;
3576
+ if (Array.isArray(content)) {
3577
+ return content.filter((c) => c.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
3578
+ }
3579
+ return "";
3580
+ }
3494
3581
 
3495
3582
  // src/integrations/openclawcity.ts
3496
3583
  function emptySkillEvidence() {