@ynhcj/xiaoyi-channel 0.0.215-next → 0.0.216-next

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.
@@ -242,6 +242,10 @@ const HEADER_SESSION_ID = "x-session-id";
242
242
  const HEADER_INTERACTION_ID = "x-interaction-id";
243
243
  /** Internal key for passing fallback uid prefix from prepareExtraParams to wrapStreamFn. */
244
244
  const FALLBACK_PREFIX_KEY = "_xiaoyi_fallback_prefix";
245
+ // Module-level cache of the most recent trace context.
246
+ // resolveDynamicModel reads these so the LLM compaction path (which bypasses
247
+ // wrapStreamFn) still gets x-hag-trace-id on model.headers.
248
+ let globalTraceContext = null;
245
249
  const SELF_EVOLUTION_PROMPT_BEGIN = "<self_evolution_prompt>";
246
250
  const SELF_EVOLUTION_PROMPT_END = "</self_evolution_prompt>";
247
251
  const SELF_EVOLUTION_ENABLED_PROMPT_SECTION = `
@@ -454,8 +458,19 @@ export const xiaoyiProvider = {
454
458
  contextWindow: 256_000,
455
459
  maxTokens: 8192,
456
460
  ...(ctx.providerConfig?.headers && typeof ctx.providerConfig.headers === "object"
457
- ? { headers: ctx.providerConfig.headers }
458
- : {}),
461
+ ? { headers: {
462
+ ...ctx.providerConfig.headers,
463
+ ...(globalTraceContext ? {
464
+ [HEADER_TRACE_ID]: globalTraceContext.traceId,
465
+ [HEADER_SESSION_ID]: globalTraceContext.sessionId,
466
+ [HEADER_INTERACTION_ID]: globalTraceContext.interactionId,
467
+ } : {}),
468
+ } }
469
+ : (globalTraceContext ? { headers: {
470
+ [HEADER_TRACE_ID]: globalTraceContext.traceId,
471
+ [HEADER_SESSION_ID]: globalTraceContext.sessionId,
472
+ [HEADER_INTERACTION_ID]: globalTraceContext.interactionId,
473
+ } } : {})),
459
474
  };
460
475
  },
461
476
  /**
@@ -606,15 +621,14 @@ export const xiaoyiProvider = {
606
621
  logger.log(`[ALS-PROOF] provider headers source=uid-fallback (ALS miss)`);
607
622
  }
608
623
  }
609
- // Mutate model.headers so the LLM compaction path picks up trace context.
610
- // The LLM path (summarizeViaLLM summarizeInStages) bypasses wrapStreamFn
611
- // but reuses the same model object, so mutating model.headers here ensures
612
- // x-hag-trace-id et al are forwarded even when the custom compaction
613
- // provider is not reached (e.g. queued compaction with different sessionManager).
614
- if (model?.headers && dynamicHeaders[HEADER_TRACE_ID]) {
615
- model.headers[HEADER_TRACE_ID] = dynamicHeaders[HEADER_TRACE_ID];
616
- model.headers[HEADER_SESSION_ID] = dynamicHeaders[HEADER_SESSION_ID];
617
- model.headers[HEADER_INTERACTION_ID] = dynamicHeaders[HEADER_INTERACTION_ID];
624
+ // Cache trace context globally so resolveDynamicModel can inject
625
+ // x-hag-trace-id into model.headers for the LLM compaction path.
626
+ if (dynamicHeaders[HEADER_TRACE_ID]) {
627
+ globalTraceContext = {
628
+ traceId: dynamicHeaders[HEADER_TRACE_ID],
629
+ sessionId: dynamicHeaders[HEADER_SESSION_ID] ?? dynamicHeaders[HEADER_TRACE_ID],
630
+ interactionId: dynamicHeaders[HEADER_INTERACTION_ID] ?? dynamicHeaders[HEADER_TRACE_ID],
631
+ };
618
632
  }
619
633
  // 记录输入
620
634
  logger.log(`[xiaoyiprovider] input messages count: ${context.messages?.length ?? 0}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.215-next",
3
+ "version": "0.0.216-next",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",