ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.39: вынос bootstrap пользовательского хода (нормализация текста + append/persist user-item) из handleMessage в отдельный runtime-адаптер. Это безопасно и дополнительно разгружает assistantService.
This commit is contained in:
+13
-21
@@ -81,6 +81,7 @@ const assistantDeepTurnRetrievalRuntimeAdapter_1 = __importStar(require("./assis
|
||||
const assistantAddressRuntimeAdapter_1 = __importStar(require("./assistantAddressRuntimeAdapter"));
|
||||
const assistantLivingChatHandlerRuntimeAdapter_1 = __importStar(require("./assistantLivingChatHandlerRuntimeAdapter"));
|
||||
const assistantLivingChatLlmRuntimeAdapter_1 = __importStar(require("./assistantLivingChatLlmRuntimeAdapter"));
|
||||
const assistantUserTurnBootstrapRuntimeAdapter_1 = __importStar(require("./assistantUserTurnBootstrapRuntimeAdapter"));
|
||||
const assistantQueryPlanning_1 = __importStar(require("./assistantQueryPlanning"));
|
||||
const iconv_lite_1 = __importDefault(require("iconv-lite"));
|
||||
const DATA_SCOPE_CACHE_TTL_MS = 60_000;
|
||||
@@ -4384,27 +4385,18 @@ class AssistantService {
|
||||
return this.sessions.getSession(sessionId);
|
||||
}
|
||||
async handleMessage(payload) {
|
||||
const session = this.sessions.ensureSession(payload.session_id);
|
||||
const sessionId = session.session_id;
|
||||
const userMessageRaw = String(payload.user_message ?? payload.message ?? "").trim();
|
||||
const repairedUserMessage = compactWhitespace(repairAddressMojibake(userMessageRaw));
|
||||
const userMessage = repairedUserMessage || userMessageRaw;
|
||||
const runtimeAnalysisContext = resolveRuntimeAnalysisContext(payload?.context);
|
||||
const userItem = {
|
||||
message_id: `msg-${(0, nanoid_1.nanoid)(10)}`,
|
||||
session_id: sessionId,
|
||||
role: "user",
|
||||
text: userMessage,
|
||||
reply_type: null,
|
||||
created_at: new Date().toISOString(),
|
||||
trace_id: null,
|
||||
debug: null
|
||||
};
|
||||
this.sessions.appendItem(sessionId, userItem);
|
||||
const sessionAfterUserAppend = this.sessions.getSession(sessionId);
|
||||
if (sessionAfterUserAppend) {
|
||||
this.sessionLogger.persistSession(sessionAfterUserAppend);
|
||||
}
|
||||
const { session, sessionId, userMessage, runtimeAnalysisContext, userItem } = (0, assistantUserTurnBootstrapRuntimeAdapter_1.runAssistantUserTurnBootstrapRuntime)({
|
||||
payload,
|
||||
ensureSession: (targetSessionId) => this.sessions.ensureSession(targetSessionId),
|
||||
appendItem: (targetSessionId, item) => this.sessions.appendItem(targetSessionId, item),
|
||||
getSession: (targetSessionId) => this.sessions.getSession(targetSessionId),
|
||||
persistSession: (sessionState) => this.sessionLogger.persistSession(sessionState),
|
||||
compactWhitespace,
|
||||
repairAddressMojibake,
|
||||
resolveRuntimeAnalysisContext,
|
||||
messageIdFactory: () => `msg-${(0, nanoid_1.nanoid)(10)}`,
|
||||
nowIso: () => new Date().toISOString()
|
||||
});
|
||||
const sessionOrganizationScope = resolveSessionOrganizationScopeContext(userMessage, session.items);
|
||||
const finalizeAddressLaneResponse = (addressLane, effectiveAddressUserMessage, carryoverMeta = null, llmPreDecomposeMeta = null) => {
|
||||
const runtime = (0, assistantAddressLaneResponseRuntimeAdapter_1.runAssistantAddressLaneResponseRuntime)({
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runAssistantUserTurnBootstrapRuntime = runAssistantUserTurnBootstrapRuntime;
|
||||
function runAssistantUserTurnBootstrapRuntime(input) {
|
||||
const session = input.ensureSession(String(input.payload.session_id ?? ""));
|
||||
const sessionId = session.session_id;
|
||||
const userMessageRaw = String(input.payload.user_message ?? input.payload.message ?? "").trim();
|
||||
const repairedUserMessage = input.compactWhitespace(input.repairAddressMojibake(userMessageRaw));
|
||||
const userMessage = repairedUserMessage || userMessageRaw;
|
||||
const runtimeAnalysisContext = input.resolveRuntimeAnalysisContext(input.payload?.context);
|
||||
const userItem = {
|
||||
message_id: (input.messageIdFactory ?? (() => "msg-unknown"))(),
|
||||
session_id: sessionId,
|
||||
role: "user",
|
||||
text: userMessage,
|
||||
reply_type: null,
|
||||
created_at: (input.nowIso ?? (() => new Date().toISOString()))(),
|
||||
trace_id: null,
|
||||
debug: null
|
||||
};
|
||||
input.appendItem(sessionId, userItem);
|
||||
const sessionAfterUserAppend = input.getSession(sessionId);
|
||||
if (sessionAfterUserAppend) {
|
||||
input.persistSession(sessionAfterUserAppend);
|
||||
}
|
||||
return {
|
||||
session,
|
||||
sessionId,
|
||||
userMessageRaw,
|
||||
userMessage,
|
||||
runtimeAnalysisContext,
|
||||
userItem
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user