@ynhcj/xiaoyi-channel 0.0.144-beta → 0.0.145-beta

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/src/bot.js CHANGED
@@ -270,7 +270,7 @@ export async function handleXYMessage(params) {
270
270
  SenderId: parsed.sessionId,
271
271
  Provider: "xiaoyi-channel",
272
272
  Surface: "xiaoyi-channel",
273
- MessageSid: `${parsed.taskId}_${deviceType}`,
273
+ MessageSid: `xiaoyi_${parsed.taskId}_${deviceType}`,
274
274
  Timestamp: Date.now(),
275
275
  WasMentioned: false,
276
276
  CommandAuthorized: true,
@@ -532,7 +532,7 @@ async function dispatchSteerWhenReady(params) {
532
532
  SenderId: sessionId,
533
533
  Provider: "xiaoyi-channel",
534
534
  Surface: "xiaoyi-channel",
535
- MessageSid: `${params.parsed.taskId}_${params.deviceType}`,
535
+ MessageSid: `xiaoyi_${params.parsed.taskId}_${params.deviceType}`,
536
536
  Timestamp: Date.now(),
537
537
  WasMentioned: false,
538
538
  CommandAuthorized: true,
@@ -46,6 +46,11 @@ function getFirstUserText(messages) {
46
46
  }
47
47
  /** Regex to match `[cron:<uuid> <title>]` anywhere in text. */
48
48
  const CRON_TAG_RE = /\[cron:[^\s\]]+\s+([^\]]+)\]/;
49
+ /** Extract the cron job UUID from the first user message, e.g. `[cron:abc123 ...]` → `abc123`. */
50
+ function extractCronUuid(messages) {
51
+ const match = getFirstUserText(messages).match(/\[cron:([^\s\]]+)/i);
52
+ return match ? match[1] : undefined;
53
+ }
49
54
  /** Check if the request is triggered by a cron job by inspecting the first user message. */
50
55
  function isCronTriggered(messages) {
51
56
  return /\[cron:/i.test(getFirstUserText(messages));
@@ -392,7 +397,9 @@ function trimUserMetadata(text) {
392
397
  }
393
398
  /**
394
399
  * Extract A2A taskId and deviceType from Conversation info JSON.
395
- * bot.ts stores them as MessageSid = "taskId_deviceType".
400
+ * bot.ts stores them as MessageSid = "xiaoyi_taskId_deviceType".
401
+ * The "xiaoyi_" prefix ensures extraction only happens for messages
402
+ * routed through xiaoyi-channel, not other channels sharing the provider.
396
403
  */
397
404
  function extractA2AFromConversationInfo(text) {
398
405
  const match = text.match(/Conversation info \(untrusted metadata\):\n```json\n([\s\S]*?)\n```/);
@@ -402,9 +409,9 @@ function extractA2AFromConversationInfo(text) {
402
409
  if (!msgIdMatch)
403
410
  return null;
404
411
  const parts = msgIdMatch[1].split("_");
405
- if (parts.length < 2)
412
+ if (parts.length < 3 || parts[0] !== "xiaoyi")
406
413
  return null;
407
- return { taskId: parts[0], deviceType: parts[1] };
414
+ return { taskId: parts[1], deviceType: parts[2] };
408
415
  }
409
416
  export const xiaoyiProvider = {
410
417
  id: "xiaoyiprovider",
@@ -527,12 +534,29 @@ export const xiaoyiProvider = {
527
534
  const traceId = ctx.extraParams[HEADER_TRACE_ID];
528
535
  const sessionId = ctx.extraParams[HEADER_SESSION_ID];
529
536
  const interactionId = ctx.extraParams[HEADER_INTERACTION_ID];
530
- if (typeof traceId === "string")
531
- dynamicHeaders[HEADER_TRACE_ID] = traceId;
532
- if (typeof sessionId === "string")
533
- dynamicHeaders[HEADER_SESSION_ID] = sessionId;
534
- if (typeof interactionId === "string")
535
- dynamicHeaders[HEADER_INTERACTION_ID] = interactionId;
537
+ const isCronCached = isCronTriggered(context.messages);
538
+ if (isCronCached) {
539
+ // Cron: generate fresh sessionId from cron UUID so each invocation
540
+ // is independently tracked, regardless of stale activeSessions state.
541
+ const cronUuid = extractCronUuid(context.messages) ?? "cron";
542
+ const cronSessionId = `cron_${cronUuid}_${Date.now()}`;
543
+ dynamicHeaders[HEADER_TRACE_ID] = cronSessionId;
544
+ dynamicHeaders[HEADER_SESSION_ID] = cronUuid;
545
+ dynamicHeaders[HEADER_INTERACTION_ID] = cronSessionId;
546
+ const cronTitle = extractCronTitle(context.messages);
547
+ if (cronTitle)
548
+ dynamicHeaders["x-cron-title"] = encodeURIComponent(cronTitle);
549
+ if (context.messages?.length === 1)
550
+ dynamicHeaders["x-cron-flag"] = "begin";
551
+ }
552
+ else {
553
+ if (typeof traceId === "string")
554
+ dynamicHeaders[HEADER_TRACE_ID] = traceId;
555
+ if (typeof sessionId === "string")
556
+ dynamicHeaders[HEADER_SESSION_ID] = sessionId;
557
+ if (typeof interactionId === "string")
558
+ dynamicHeaders[HEADER_INTERACTION_ID] = interactionId;
559
+ }
536
560
  }
537
561
  }
538
562
  // 记录输入
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.144-beta",
3
+ "version": "0.0.145-beta",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",