@ynhcj/xiaoyi-channel 0.0.146-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 -89
- 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;
|
|
@@ -496,72 +475,45 @@ export const xiaoyiProvider = {
|
|
|
496
475
|
}
|
|
497
476
|
// ── Build dynamic headers ────────────────────────────
|
|
498
477
|
// Priority:
|
|
499
|
-
// 1.
|
|
500
|
-
//
|
|
501
|
-
//
|
|
502
|
-
|
|
503
|
-
if (
|
|
504
|
-
const fallbackPrefix = ctx.extraParams[FALLBACK_PREFIX_KEY];
|
|
505
|
-
if (
|
|
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] =
|
|
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
|
-
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
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
|
|
579
|
-
const
|
|
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) {
|