@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.
- package/dist/src/provider.js +40 -84
- package/package.json +1 -1
package/dist/src/provider.js
CHANGED
|
@@ -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
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
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
|
-
|
|
499
|
-
|
|
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] =
|
|
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
|
-
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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
|
|
574
|
-
const
|
|
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) {
|