@ynhcj/xiaoyi-channel 0.0.46-next → 0.0.47-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.
- package/dist/src/provider.js +36 -9
- package/package.json +1 -1
package/dist/src/provider.js
CHANGED
|
@@ -10,6 +10,18 @@ const HEADER_CONVERSATION_ID = "x-conversation-id";
|
|
|
10
10
|
const EXTRA_PARAM_TASK_ID = "x-task-id";
|
|
11
11
|
const EXTRA_PARAM_SESSION_ID = "x-session-id";
|
|
12
12
|
const EXTRA_PARAM_CONVERSATION_ID = "x-conversation-id";
|
|
13
|
+
/**
|
|
14
|
+
* Encode uid to base64 and take first 32 chars.
|
|
15
|
+
*/
|
|
16
|
+
function encodeUid(uid) {
|
|
17
|
+
return Buffer.from(uid).toString("base64").slice(0, 32);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get uid from plugin config (OpenClawConfig -> plugins -> xiaoyi-channel -> config).
|
|
21
|
+
*/
|
|
22
|
+
function getUidFromConfig(config) {
|
|
23
|
+
return config?.plugins?.entries?.["xiaoyi-channel"]?.config?.uid;
|
|
24
|
+
}
|
|
13
25
|
export const xiaoyiProvider = {
|
|
14
26
|
id: "xiaoyiprovider",
|
|
15
27
|
label: "Xiaoyi Provider",
|
|
@@ -19,19 +31,33 @@ export const xiaoyiProvider = {
|
|
|
19
31
|
* Inject dynamic session params into extraParams so they flow
|
|
20
32
|
* through to wrapStreamFn's ctx.extraParams.
|
|
21
33
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
34
|
+
* Priority:
|
|
35
|
+
* 1. Session context (from AsyncLocalStorage, set by bot.ts)
|
|
36
|
+
* 2. uid-based fallback: base64(uid)[:32]_timestamp
|
|
37
|
+
* 3. No uid available → return undefined (no headers injected)
|
|
25
38
|
*/
|
|
26
39
|
prepareExtraParams: (ctx) => {
|
|
27
40
|
const sessionCtx = getCurrentSessionContext();
|
|
28
|
-
if (
|
|
41
|
+
if (sessionCtx) {
|
|
42
|
+
return {
|
|
43
|
+
...ctx.extraParams,
|
|
44
|
+
[EXTRA_PARAM_TASK_ID]: sessionCtx.taskId,
|
|
45
|
+
[EXTRA_PARAM_SESSION_ID]: sessionCtx.sessionId,
|
|
46
|
+
[EXTRA_PARAM_CONVERSATION_ID]: sessionCtx.messageId,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// Fallback: uid-based values
|
|
50
|
+
const uid = getUidFromConfig(ctx.config);
|
|
51
|
+
if (!uid)
|
|
29
52
|
return undefined;
|
|
53
|
+
const prefix = encodeUid(uid);
|
|
54
|
+
const ts = Date.now();
|
|
55
|
+
const fallbackValue = `${prefix}_${ts}`;
|
|
30
56
|
return {
|
|
31
57
|
...ctx.extraParams,
|
|
32
|
-
[EXTRA_PARAM_TASK_ID]:
|
|
33
|
-
[EXTRA_PARAM_SESSION_ID]:
|
|
34
|
-
[EXTRA_PARAM_CONVERSATION_ID]:
|
|
58
|
+
[EXTRA_PARAM_TASK_ID]: fallbackValue,
|
|
59
|
+
[EXTRA_PARAM_SESSION_ID]: fallbackValue,
|
|
60
|
+
[EXTRA_PARAM_CONVERSATION_ID]: fallbackValue,
|
|
35
61
|
};
|
|
36
62
|
},
|
|
37
63
|
/**
|
|
@@ -61,10 +87,11 @@ export const xiaoyiProvider = {
|
|
|
61
87
|
return underlying;
|
|
62
88
|
return async (model, context, options) => {
|
|
63
89
|
// 记录输入
|
|
64
|
-
console.log(`[xiaoyiprovider] input messages: ${
|
|
90
|
+
console.log(`[xiaoyiprovider] input messages count: ${context.messages.length}`);
|
|
65
91
|
if (context.systemPrompt) {
|
|
66
|
-
console.log(`[xiaoyiprovider] system prompt: ${context.systemPrompt}`);
|
|
92
|
+
console.log(`[xiaoyiprovider] system prompt length: ${context.systemPrompt.length}`);
|
|
67
93
|
}
|
|
94
|
+
console.log(`[xiaoyiprovider] headers: ${JSON.stringify(dynamicHeaders)}`);
|
|
68
95
|
const stream = await underlying(model, context, {
|
|
69
96
|
...options,
|
|
70
97
|
headers: {
|