@ynhcj/xiaoyi-channel 0.0.145-beta → 0.0.147-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.
@@ -236,8 +236,6 @@ const HEADER_SESSION_ID = "x-session-id";
236
236
  const HEADER_INTERACTION_ID = "x-interaction-id";
237
237
  /** Internal key for passing fallback uid prefix from prepareExtraParams to wrapStreamFn. */
238
238
  const FALLBACK_PREFIX_KEY = "_xiaoyi_fallback_prefix";
239
- /** Internal key for passing deviceType from prepareExtraParams to wrapStreamFn. */
240
- const DEVICE_TYPE_KEY = "_xiaoyi_device_type";
241
239
  const SELF_EVOLUTION_PROMPT_BEGIN = "<self_evolution_prompt>";
242
240
  const SELF_EVOLUTION_PROMPT_END = "</self_evolution_prompt>";
243
241
  const SELF_EVOLUTION_ENABLED_PROMPT_SECTION = `
@@ -420,31 +418,12 @@ export const xiaoyiProvider = {
420
418
  auth: [],
421
419
  isCacheTtlEligible: () => true,
422
420
  /**
423
- * Inject dynamic session params into extraParams so they flow
424
- * through to wrapStreamFn's ctx.extraParams.
425
- *
426
- * Priority:
427
- * 1. Session context (from AsyncLocalStorage, set by bot.ts)
428
- * 2. uid-based fallback: sha256(uid).hex[:32]_timestamp
429
- * 3. No uid available → return undefined (no headers injected)
421
+ * Store uid-based fallback prefix for lazy timestamp generation in wrapStreamFn.
422
+ * Session-level headers (traceId / sessionId / interactionId) are resolved
423
+ * directly in wrapStreamFn via cron detection, Conversation info extraction,
424
+ * or uid fallback.
430
425
  */
431
426
  prepareExtraParams: (ctx) => {
432
- const sessionCtx = getCurrentSessionContext();
433
- if (sessionCtx) {
434
- const taskId = sessionCtx.taskId;
435
- const sessionId = taskId.split("&")[0];
436
- const interactionId = taskId.split("&")[1] || "";
437
- return {
438
- ...ctx.extraParams,
439
- [HEADER_TRACE_ID]: taskId,
440
- [HEADER_SESSION_ID]: sessionId,
441
- [HEADER_INTERACTION_ID]: interactionId,
442
- [DEVICE_TYPE_KEY]: sessionCtx.deviceType ?? "",
443
- };
444
- }
445
- // Fallback: store uid prefix for lazy timestamp generation in wrapStreamFn.
446
- // This ensures each model call gets a fresh timestamp instead of reusing
447
- // the same one across tool-use loops and retries.
448
427
  const uid = getUidFromConfig(ctx.config);
449
428
  if (!uid)
450
429
  return undefined;
@@ -495,68 +474,46 @@ export const xiaoyiProvider = {
495
474
  }
496
475
  }
497
476
  // ── Build dynamic headers ────────────────────────────
498
- if (ctx.extraParams) {
499
- const fallbackPrefix = ctx.extraParams[FALLBACK_PREFIX_KEY];
477
+ // Priority:
478
+ // 1. Cron-triggered: uid → cronUuid, with cron-specific headers
479
+ // 2. Xiaoyi A2A: taskId extracted from Conversation info (xiaoyi_ prefix)
480
+ // 3. UID-based fallback: sha256(uid).hex[:32]_timestamp
481
+ const isCron = isCronTriggered(context.messages);
482
+ if (isCron) {
483
+ const fallbackPrefix = ctx.extraParams?.[FALLBACK_PREFIX_KEY];
500
484
  if (typeof fallbackPrefix === "string") {
501
- // Fallback mode: generate fresh timestamp per request
502
- const isCron = isCronTriggered(context.messages);
503
485
  const fallbackValue = `${fallbackPrefix}_${Date.now()}`;
504
- dynamicHeaders[HEADER_TRACE_ID] = isCron ? `cron_${fallbackValue}` : fallbackValue;
486
+ dynamicHeaders[HEADER_TRACE_ID] = `cron_${fallbackValue}`;
505
487
  dynamicHeaders[HEADER_SESSION_ID] = fallbackValue;
506
488
  dynamicHeaders[HEADER_INTERACTION_ID] = fallbackValue;
507
- if (isCron) {
508
- const cronTitle = extractCronTitle(context.messages);
509
- if (cronTitle)
510
- dynamicHeaders["x-cron-title"] = encodeURIComponent(cronTitle);
511
- if (context.messages?.length === 1)
512
- dynamicHeaders["x-cron-flag"] = "begin";
513
- }
514
- }
515
- else if (extractedTaskId) {
516
- // Session mode: taskId extracted from Conversation info
517
- const traceId = extractedTaskId;
518
- const sessionId = traceId.split("&")[0];
519
- const interactionId = traceId.split("&")[1] ?? "";
520
- const isCron = isCronTriggered(context.messages);
521
- dynamicHeaders[HEADER_TRACE_ID] = isCron ? `cron_${traceId}_${Date.now()}` : traceId;
522
- if (isCron) {
523
- const cronTitle = extractCronTitle(context.messages);
524
- if (cronTitle)
525
- dynamicHeaders["x-cron-title"] = encodeURIComponent(cronTitle);
526
- if (context.messages?.length === 1)
527
- dynamicHeaders["x-cron-flag"] = "begin";
528
- }
529
- dynamicHeaders[HEADER_SESSION_ID] = sessionId;
530
- dynamicHeaders[HEADER_INTERACTION_ID] = interactionId;
531
489
  }
532
490
  else {
533
- // Fallback: use extraParams cached values
534
- const traceId = ctx.extraParams[HEADER_TRACE_ID];
535
- const sessionId = ctx.extraParams[HEADER_SESSION_ID];
536
- const interactionId = ctx.extraParams[HEADER_INTERACTION_ID];
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
- }
491
+ const cronUuid = extractCronUuid(context.messages) ?? "cron";
492
+ const cronSessionId = `cron_${cronUuid}_${Date.now()}`;
493
+ dynamicHeaders[HEADER_TRACE_ID] = cronSessionId;
494
+ dynamicHeaders[HEADER_SESSION_ID] = cronUuid;
495
+ dynamicHeaders[HEADER_INTERACTION_ID] = cronSessionId;
496
+ }
497
+ const cronTitle = extractCronTitle(context.messages);
498
+ if (cronTitle)
499
+ dynamicHeaders["x-cron-title"] = encodeURIComponent(cronTitle);
500
+ if (context.messages?.length === 1)
501
+ dynamicHeaders["x-cron-flag"] = "begin";
502
+ }
503
+ else if (extractedTaskId) {
504
+ const sessionId = extractedTaskId.split("&")[0];
505
+ const interactionId = extractedTaskId.split("&")[1] ?? "";
506
+ dynamicHeaders[HEADER_TRACE_ID] = extractedTaskId;
507
+ dynamicHeaders[HEADER_SESSION_ID] = sessionId;
508
+ dynamicHeaders[HEADER_INTERACTION_ID] = interactionId;
509
+ }
510
+ else {
511
+ const fallbackPrefix = ctx.extraParams?.[FALLBACK_PREFIX_KEY];
512
+ if (typeof fallbackPrefix === "string") {
513
+ const fallbackValue = `${fallbackPrefix}_${Date.now()}`;
514
+ dynamicHeaders[HEADER_TRACE_ID] = fallbackValue;
515
+ dynamicHeaders[HEADER_SESSION_ID] = fallbackValue;
516
+ dynamicHeaders[HEADER_INTERACTION_ID] = fallbackValue;
560
517
  }
561
518
  }
562
519
  // 记录输入
@@ -570,9 +527,8 @@ export const xiaoyiProvider = {
570
527
  logger.log(`[xiaoyiprovider] system prompt length: ${context.systemPrompt.length}`);
571
528
  }
572
529
  // deviceType: prefer value extracted from Conversation info,
573
- // then extraParams, then ALS fallback.
574
- const extraParamsDeviceType = ctx.extraParams?.[DEVICE_TYPE_KEY] || undefined;
575
- const deviceType = (extractedDeviceType || extraParamsDeviceType)
530
+ // then ALS fallback.
531
+ const deviceType = extractedDeviceType
576
532
  ?? getCurrentSessionContext()?.deviceType;
577
533
  // 在发送给模型前,优化 systemPrompt 结构
578
534
  if (context.systemPrompt) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.145-beta",
3
+ "version": "0.0.147-beta",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",