@ynhcj/xiaoyi-channel 0.0.146-beta → 0.0.148-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;
@@ -496,72 +475,45 @@ export const xiaoyiProvider = {
496
475
  }
497
476
  // ── Build dynamic headers ────────────────────────────
498
477
  // Priority:
499
- // 1. TaskId extracted from Conversation info in user messages (most reliable
500
- // based on message content, not mutable global state or cached values)
501
- // 2. UID-based fallback: sha256(uid).hex[:32]_timestamp
502
- // 3. Cached extraParams from prepareExtraParams (session keys)
503
- if (ctx.extraParams) {
504
- const fallbackPrefix = ctx.extraParams[FALLBACK_PREFIX_KEY];
505
- if (extractedTaskId) {
506
- // Session mode: taskId extracted from Conversation info
507
- const traceId = extractedTaskId;
508
- const sessionId = traceId.split("&")[0];
509
- const interactionId = traceId.split("&")[1] ?? "";
510
- const isCron = isCronTriggered(context.messages);
511
- dynamicHeaders[HEADER_TRACE_ID] = isCron ? `cron_${traceId}_${Date.now()}` : traceId;
512
- if (isCron) {
513
- const cronTitle = extractCronTitle(context.messages);
514
- if (cronTitle)
515
- dynamicHeaders["x-cron-title"] = encodeURIComponent(cronTitle);
516
- if (context.messages?.length === 1)
517
- dynamicHeaders["x-cron-flag"] = "begin";
518
- }
519
- dynamicHeaders[HEADER_SESSION_ID] = sessionId;
520
- dynamicHeaders[HEADER_INTERACTION_ID] = interactionId;
521
- }
522
- else if (typeof fallbackPrefix === "string") {
523
- // Fallback mode: generate fresh timestamp per request
524
- const isCron = isCronTriggered(context.messages);
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];
484
+ if (typeof fallbackPrefix === "string") {
525
485
  const fallbackValue = `${fallbackPrefix}_${Date.now()}`;
526
- dynamicHeaders[HEADER_TRACE_ID] = isCron ? `cron_${fallbackValue}` : fallbackValue;
486
+ dynamicHeaders[HEADER_TRACE_ID] = `cron_${fallbackValue}`;
527
487
  dynamicHeaders[HEADER_SESSION_ID] = fallbackValue;
528
488
  dynamicHeaders[HEADER_INTERACTION_ID] = fallbackValue;
529
- if (isCron) {
530
- const cronTitle = extractCronTitle(context.messages);
531
- if (cronTitle)
532
- dynamicHeaders["x-cron-title"] = encodeURIComponent(cronTitle);
533
- if (context.messages?.length === 1)
534
- dynamicHeaders["x-cron-flag"] = "begin";
535
- }
536
489
  }
537
490
  else {
538
- // Fallback: use extraParams cached values
539
- const traceId = ctx.extraParams[HEADER_TRACE_ID];
540
- const sessionId = ctx.extraParams[HEADER_SESSION_ID];
541
- const interactionId = ctx.extraParams[HEADER_INTERACTION_ID];
542
- const isCronCached = isCronTriggered(context.messages);
543
- if (isCronCached) {
544
- // Cron: generate fresh sessionId from cron UUID so each invocation
545
- // is independently tracked, regardless of stale activeSessions state.
546
- const cronUuid = extractCronUuid(context.messages) ?? "cron";
547
- const cronSessionId = `cron_${cronUuid}_${Date.now()}`;
548
- dynamicHeaders[HEADER_TRACE_ID] = cronSessionId;
549
- dynamicHeaders[HEADER_SESSION_ID] = cronUuid;
550
- dynamicHeaders[HEADER_INTERACTION_ID] = cronSessionId;
551
- const cronTitle = extractCronTitle(context.messages);
552
- if (cronTitle)
553
- dynamicHeaders["x-cron-title"] = encodeURIComponent(cronTitle);
554
- if (context.messages?.length === 1)
555
- dynamicHeaders["x-cron-flag"] = "begin";
556
- }
557
- else {
558
- if (typeof traceId === "string")
559
- dynamicHeaders[HEADER_TRACE_ID] = traceId;
560
- if (typeof sessionId === "string")
561
- dynamicHeaders[HEADER_SESSION_ID] = sessionId;
562
- if (typeof interactionId === "string")
563
- dynamicHeaders[HEADER_INTERACTION_ID] = interactionId;
564
- }
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;
565
517
  }
566
518
  }
567
519
  // 记录输入
@@ -575,9 +527,8 @@ export const xiaoyiProvider = {
575
527
  logger.log(`[xiaoyiprovider] system prompt length: ${context.systemPrompt.length}`);
576
528
  }
577
529
  // deviceType: prefer value extracted from Conversation info,
578
- // then extraParams, then ALS fallback.
579
- const extraParamsDeviceType = ctx.extraParams?.[DEVICE_TYPE_KEY] || undefined;
580
- const deviceType = (extractedDeviceType || extraParamsDeviceType)
530
+ // then ALS fallback.
531
+ const deviceType = extractedDeviceType
581
532
  ?? getCurrentSessionContext()?.deviceType;
582
533
  // 在发送给模型前,优化 systemPrompt 结构
583
534
  if (context.systemPrompt) {
@@ -60,7 +60,7 @@ async function callImageUnderstandingAPI(imageUrls, text, apiKey, uid, fileUploa
60
60
  "x-api-key": apiKey,
61
61
  "x-request-from": "openclaw",
62
62
  "x-uid": uid,
63
- "x-skill-id": "image_comprehension",
63
+ "x-skill-id": "xiaoyi_image_comprehension",
64
64
  "x-prd-pkg-name": "com.huawei.hag",
65
65
  };
66
66
  const payload = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.146-beta",
3
+ "version": "0.0.148-beta",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",