feat: enable S2S with native Viking memory
This commit is contained in:
@@ -34,8 +34,8 @@ function buildSessionPrompt(sessionConfig) {
|
||||
return sections.join("\n\n");
|
||||
}
|
||||
|
||||
function buildSessionUpdate(sessionConfig, eventID, modelMode = "llm") {
|
||||
const normalizedMode = String(modelMode || "llm").trim().toLowerCase();
|
||||
function buildSessionUpdate(sessionConfig, eventID, modelMode) {
|
||||
const normalizedMode = String(modelMode || sessionConfig.model_mode || "llm").trim().toLowerCase();
|
||||
if (!new Set(["llm", "s2s"]).has(normalizedMode)) throw new Error("智能体模型类型必须为 llm 或 s2s");
|
||||
const dialogID = requiredText(sessionConfig.dialog_id, "对话标识", 200);
|
||||
const systemPrompt = buildSessionPrompt(sessionConfig);
|
||||
@@ -52,8 +52,32 @@ function buildSessionUpdate(sessionConfig, eventID, modelMode = "llm") {
|
||||
},
|
||||
},
|
||||
};
|
||||
} else {
|
||||
config.LLMConfig = { SystemMessages: [systemPrompt] };
|
||||
}
|
||||
config.LLMConfig = { SystemMessages: [systemPrompt] };
|
||||
const memory = sessionConfig.memory;
|
||||
if (memory && typeof memory === "object") {
|
||||
const collectionName = requiredText(memory.collection_name, "Viking 记忆库名称", 200);
|
||||
const userID = requiredText(memory.user_id, "Viking 用户标识", 200);
|
||||
const memoryTypes = Array.isArray(memory.memory_types)
|
||||
? memory.memory_types.map((value) => requiredText(value, "Viking 记忆类型", 100))
|
||||
: [];
|
||||
if (!memoryTypes.length) throw new Error("Viking 记忆类型不能为空");
|
||||
const filter = { user_id: [userID], memory_type: memoryTypes };
|
||||
if (String(memory.assistant_id || "").trim()) {
|
||||
filter.assistant_id = [requiredText(memory.assistant_id, "Viking 助手标识", 200)];
|
||||
}
|
||||
config.MemoryConfig = {
|
||||
Enable: true,
|
||||
Provider: "volc",
|
||||
ProviderParams: {
|
||||
collection_name: collectionName,
|
||||
filter,
|
||||
limit: Number.isInteger(memory.limit) && memory.limit > 0 ? Math.min(memory.limit, 5) : 5,
|
||||
...(String(memory.transition_words || "").trim()
|
||||
? { transition_words: String(memory.transition_words).trim() }
|
||||
: {}),
|
||||
},
|
||||
};
|
||||
}
|
||||
return {
|
||||
event_id: eventID,
|
||||
|
||||
@@ -33,7 +33,25 @@ test("S2S session update maps persona and dialog id to provider dialog config",
|
||||
assert.equal(dialog.speaking_style, "亲切自然");
|
||||
assert.match(dialog.system_role, /只使用授权信息/);
|
||||
assert.match(dialog.system_role, /你是陪伴助手/);
|
||||
assert.equal("LLMConfig" in update.session.config, false);
|
||||
assert.match(update.session.config.LLMConfig.SystemMessages[0], /你是陪伴助手/);
|
||||
});
|
||||
|
||||
test("session update maps the bound user to native Viking memory without credentials", () => {
|
||||
const update = buildSessionUpdate({
|
||||
dialog_id: "conversation-memory", model_mode: "s2s", authorized_context: "authorized",
|
||||
memory: {
|
||||
collection_name: "memory", user_id: "u_subject_hash", assistant_id: "platform_companion_v1",
|
||||
memory_types: ["event_v1", "profile_v1"], limit: 5, transition_words: "自然承接历史记忆",
|
||||
},
|
||||
}, "event-memory");
|
||||
const memory = update.session.config.MemoryConfig;
|
||||
assert.equal(memory.Enable, true);
|
||||
assert.equal(memory.Provider, "volc");
|
||||
assert.equal(memory.ProviderParams.collection_name, "memory");
|
||||
assert.deepEqual(memory.ProviderParams.filter.user_id, ["u_subject_hash"]);
|
||||
assert.deepEqual(memory.ProviderParams.filter.assistant_id, ["platform_companion_v1"]);
|
||||
assert.deepEqual(memory.ProviderParams.filter.memory_type, ["event_v1", "profile_v1"]);
|
||||
assert.equal("token" in memory.ProviderParams, false);
|
||||
});
|
||||
|
||||
class FakeWebSocket extends EventEmitter {
|
||||
|
||||
Reference in New Issue
Block a user