ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.25 финализацию address-ветки в отдельный adapter \ Переподключил assistantService на новый adapter (без смены поведения)
This commit is contained in:
+118
@@ -0,0 +1,118 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.finalizeAssistantAddressTurn = finalizeAssistantAddressTurn;
|
||||
const nanoid_1 = require("nanoid");
|
||||
const assistantTurnCommitRuntimeAdapter_1 = require("./assistantTurnCommitRuntimeAdapter");
|
||||
function toTraceId(debug) {
|
||||
const value = debug?.trace_id;
|
||||
if (typeof value !== "string") {
|
||||
return null;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length > 0 ? trimmed : null;
|
||||
}
|
||||
function buildAddressProcessedLogDetails(input, assistantItem) {
|
||||
const laneDebug = input.addressLaneDebug;
|
||||
const llmMeta = input.llmPreDecomposeMeta;
|
||||
const carryover = input.carryoverMeta;
|
||||
return {
|
||||
session_id: input.sessionId,
|
||||
message_id: assistantItem.message_id,
|
||||
user_message: input.userMessage,
|
||||
effective_address_user_message: input.effectiveAddressUserMessage,
|
||||
address_followup_context_applied: Boolean(carryover),
|
||||
address_followup_context_previous_intent: carryover?.previousAddressIntent ?? null,
|
||||
address_followup_context_previous_anchor: carryover?.previousAddressAnchor ?? null,
|
||||
address_llm_predecompose_attempted: Boolean(llmMeta?.attempted),
|
||||
address_llm_predecompose_applied: Boolean(llmMeta?.applied),
|
||||
address_llm_predecompose_provider: llmMeta?.provider ?? null,
|
||||
address_llm_predecompose_trace_id: llmMeta?.traceId ?? null,
|
||||
address_llm_predecompose_reason: llmMeta?.reason ?? null,
|
||||
address_fallback_rule_hit: llmMeta?.fallbackRuleHit ?? null,
|
||||
address_sanitized_user_message: llmMeta?.sanitizedUserMessage ?? null,
|
||||
address_tool_gate_decision: llmMeta?.toolGateDecision ?? null,
|
||||
address_tool_gate_reason: llmMeta?.toolGateReason ?? null,
|
||||
address_dialog_continuation_decision: llmMeta?.dialogContinuationContract?.decision ?? null,
|
||||
address_dialog_continuation_target_intent: llmMeta?.dialogContinuationContract?.target_intent ?? null,
|
||||
address_retry_attempted: Boolean(llmMeta?.addressRetryAudit?.attempted),
|
||||
address_retry_reason: llmMeta?.addressRetryAudit?.reason ?? null,
|
||||
address_retry_initial_limited_category: llmMeta?.addressRetryAudit?.initial_limited_category ?? null,
|
||||
address_retry_result_category: llmMeta?.addressRetryAudit?.retry_result_category ?? null,
|
||||
address_llm_predecompose_contract_intent: llmMeta?.predecomposeContract?.intent ?? null,
|
||||
address_llm_predecompose_contract_aggregation_profile: llmMeta?.predecomposeContract?.aggregation_profile ?? null,
|
||||
address_llm_predecompose_contract_period_scope: llmMeta?.predecomposeContract?.period?.scope ?? null,
|
||||
detected_mode: laneDebug.detected_mode,
|
||||
query_shape: laneDebug.query_shape,
|
||||
detected_intent: laneDebug.detected_intent,
|
||||
extracted_filters: laneDebug.extracted_filters,
|
||||
selected_recipe: laneDebug.selected_recipe,
|
||||
mcp_call_status_legacy: laneDebug.mcp_call_status_legacy,
|
||||
account_scope_mode: laneDebug.account_scope_mode,
|
||||
account_scope_fallback_applied: laneDebug.account_scope_fallback_applied,
|
||||
anchor_type: laneDebug.anchor_type,
|
||||
resolver_confidence: laneDebug.resolver_confidence,
|
||||
match_failure_stage: laneDebug.match_failure_stage,
|
||||
match_failure_reason: laneDebug.match_failure_reason,
|
||||
mcp_call_status: laneDebug.mcp_call_status,
|
||||
rows_fetched: laneDebug.rows_fetched,
|
||||
raw_rows_received: laneDebug.raw_rows_received,
|
||||
rows_after_account_scope: laneDebug.rows_after_account_scope,
|
||||
rows_after_recipe_filter: laneDebug.rows_after_recipe_filter,
|
||||
rows_materialized: laneDebug.rows_materialized,
|
||||
rows_matched: laneDebug.rows_matched,
|
||||
materialization_drop_reason: laneDebug.materialization_drop_reason,
|
||||
account_token_raw: laneDebug.account_token_raw,
|
||||
account_token_normalized: laneDebug.account_token_normalized,
|
||||
account_scope_fields_checked: laneDebug.account_scope_fields_checked,
|
||||
account_scope_match_strategy: laneDebug.account_scope_match_strategy,
|
||||
account_scope_drop_reason: laneDebug.account_scope_drop_reason,
|
||||
runtime_readiness: laneDebug.runtime_readiness,
|
||||
limited_reason_category: laneDebug.limited_reason_category,
|
||||
response_type: laneDebug.response_type,
|
||||
limitations: laneDebug.limitations,
|
||||
assistant_reply: assistantItem.text,
|
||||
reply_type: assistantItem.reply_type,
|
||||
trace_id: assistantItem.trace_id
|
||||
};
|
||||
}
|
||||
function finalizeAssistantAddressTurn(input) {
|
||||
const nowIso = input.nowIso ?? (() => new Date().toISOString());
|
||||
const messageIdFactory = input.messageIdFactory ?? (() => `msg-${(0, nanoid_1.nanoid)(10)}`);
|
||||
const commitSafe = input.commitFn ?? assistantTurnCommitRuntimeAdapter_1.commitAssistantTurnAndLog;
|
||||
const assistantItem = {
|
||||
message_id: messageIdFactory(),
|
||||
session_id: input.sessionId,
|
||||
role: "assistant",
|
||||
text: input.assistantReply,
|
||||
reply_type: input.replyType,
|
||||
created_at: nowIso(),
|
||||
trace_id: toTraceId(input.debug),
|
||||
debug: input.debug
|
||||
};
|
||||
const logDetails = buildAddressProcessedLogDetails(input, assistantItem);
|
||||
const commitResult = commitSafe({
|
||||
sessionId: input.sessionId,
|
||||
assistantItem,
|
||||
eventType: "assistant_message_address",
|
||||
logDetails,
|
||||
appendItem: input.appendItem,
|
||||
getSession: input.getSession,
|
||||
persistSession: input.persistSession,
|
||||
cloneConversation: input.cloneConversation,
|
||||
logEvent: input.logEvent
|
||||
});
|
||||
const response = {
|
||||
ok: true,
|
||||
session_id: input.sessionId,
|
||||
assistant_reply: assistantItem.text,
|
||||
reply_type: assistantItem.reply_type,
|
||||
conversation_item: assistantItem,
|
||||
debug: input.debug,
|
||||
conversation: commitResult.conversation
|
||||
};
|
||||
return {
|
||||
assistantItem,
|
||||
commitResult,
|
||||
response
|
||||
};
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.finalizeAssistantDeepTurn = finalizeAssistantDeepTurn;
|
||||
const assistantDeepTurnResponseBuilder_1 = require("./assistantDeepTurnResponseBuilder");
|
||||
const assistantTurnCommitRuntimeAdapter_1 = require("./assistantTurnCommitRuntimeAdapter");
|
||||
function finalizeAssistantDeepTurn(input) {
|
||||
const commitSafe = input.commitFn ?? assistantTurnCommitRuntimeAdapter_1.commitAssistantTurnAndLog;
|
||||
const buildResponseSafe = input.buildResponseFn ?? assistantDeepTurnResponseBuilder_1.buildAssistantDeepTurnSuccessResponse;
|
||||
const commitResult = commitSafe({
|
||||
sessionId: input.sessionId,
|
||||
assistantItem: input.assistantItem,
|
||||
eventType: "assistant_message",
|
||||
logDetails: input.deepAnalysisLogDetails,
|
||||
appendItem: input.appendItem,
|
||||
getSession: input.getSession,
|
||||
persistSession: input.persistSession,
|
||||
cloneConversation: input.cloneConversation,
|
||||
logEvent: input.logEvent
|
||||
});
|
||||
const response = buildResponseSafe({
|
||||
sessionId: input.sessionId,
|
||||
assistantReply: input.assistantReply,
|
||||
replyType: input.replyType,
|
||||
conversationItem: input.assistantItem,
|
||||
debug: input.debug,
|
||||
conversation: commitResult.conversation
|
||||
});
|
||||
return {
|
||||
commitResult,
|
||||
response
|
||||
};
|
||||
}
|
||||
+24
-104
@@ -65,17 +65,17 @@ const openaiResponsesClient_1 = __importStar(require("./openaiResponsesClient"))
|
||||
const addressMcpClient_1 = __importStar(require("./addressMcpClient"));
|
||||
const capabilitiesRegistry_1 = __importStar(require("./capabilitiesRegistry"));
|
||||
const assistantCanon_1 = __importStar(require("./assistantCanon"));
|
||||
const assistantAddressTurnFinalizeRuntimeAdapter_1 = __importStar(require("./assistantAddressTurnFinalizeRuntimeAdapter"));
|
||||
const assistantCoverageGrounding_1 = __importStar(require("./assistantCoverageGrounding"));
|
||||
const assistantDeepTurnResponseBuilder_1 = __importStar(require("./assistantDeepTurnResponseBuilder"));
|
||||
const assistantDeepTurnCompositionRuntimeAdapter_1 = __importStar(require("./assistantDeepTurnCompositionRuntimeAdapter"));
|
||||
const assistantDeepTurnContextRuntimeAdapter_1 = __importStar(require("./assistantDeepTurnContextRuntimeAdapter"));
|
||||
const assistantDeepTurnFinalizeRuntimeAdapter_1 = __importStar(require("./assistantDeepTurnFinalizeRuntimeAdapter"));
|
||||
const assistantDeepTurnGuardRuntimeAdapter_1 = __importStar(require("./assistantDeepTurnGuardRuntimeAdapter"));
|
||||
const assistantDeepTurnGroundingRuntimeAdapter_1 = __importStar(require("./assistantDeepTurnGroundingRuntimeAdapter"));
|
||||
const assistantDeepTurnPackagingRuntimeAdapter_1 = __importStar(require("./assistantDeepTurnPackagingRuntimeAdapter"));
|
||||
const assistantDeepTurnPlanRuntimeAdapter_1 = __importStar(require("./assistantDeepTurnPlanRuntimeAdapter"));
|
||||
const assistantDeepTurnRetrievalRuntimeAdapter_1 = __importStar(require("./assistantDeepTurnRetrievalRuntimeAdapter"));
|
||||
const assistantQueryPlanning_1 = __importStar(require("./assistantQueryPlanning"));
|
||||
const assistantTurnCommitRuntimeAdapter_1 = __importStar(require("./assistantTurnCommitRuntimeAdapter"));
|
||||
const iconv_lite_1 = __importDefault(require("iconv-lite"));
|
||||
const DATA_SCOPE_CACHE_TTL_MS = 60_000;
|
||||
const dataScopeProbeCache = new Map();
|
||||
@@ -4439,98 +4439,24 @@ class AssistantService {
|
||||
if (debugActiveOrganization) {
|
||||
debug.assistant_active_organization = debugActiveOrganization;
|
||||
}
|
||||
const assistantItem = {
|
||||
message_id: `msg-${(0, nanoid_1.nanoid)(10)}`,
|
||||
session_id: sessionId,
|
||||
role: "assistant",
|
||||
text: safeAddressReply,
|
||||
reply_type: addressLane.reply_type,
|
||||
created_at: new Date().toISOString(),
|
||||
trace_id: debug.trace_id,
|
||||
debug
|
||||
};
|
||||
this.sessions.appendItem(sessionId, assistantItem);
|
||||
const current = this.sessions.getSession(sessionId);
|
||||
if (current) {
|
||||
this.sessionLogger.persistSession(current);
|
||||
}
|
||||
const conversation = cloneItems(current?.items ?? []);
|
||||
(0, log_1.logJson)({
|
||||
timestamp: new Date().toISOString(),
|
||||
level: "info",
|
||||
service: "assistant_loop",
|
||||
message: "assistant_message_processed",
|
||||
const finalization = (0, assistantAddressTurnFinalizeRuntimeAdapter_1.finalizeAssistantAddressTurn)({
|
||||
sessionId,
|
||||
eventType: "assistant_message_address",
|
||||
details: {
|
||||
session_id: sessionId,
|
||||
message_id: assistantItem.message_id,
|
||||
user_message: userMessage,
|
||||
effective_address_user_message: effectiveAddressUserMessage,
|
||||
address_followup_context_applied: Boolean(carryoverMeta),
|
||||
address_followup_context_previous_intent: carryoverMeta?.previousAddressIntent ?? null,
|
||||
address_followup_context_previous_anchor: carryoverMeta?.previousAddressAnchor ?? null,
|
||||
address_llm_predecompose_attempted: Boolean(llmPreDecomposeMeta?.attempted),
|
||||
address_llm_predecompose_applied: Boolean(llmPreDecomposeMeta?.applied),
|
||||
address_llm_predecompose_provider: llmPreDecomposeMeta?.provider ?? null,
|
||||
address_llm_predecompose_trace_id: llmPreDecomposeMeta?.traceId ?? null,
|
||||
address_llm_predecompose_reason: llmPreDecomposeMeta?.reason ?? null,
|
||||
address_fallback_rule_hit: llmPreDecomposeMeta?.fallbackRuleHit ?? null,
|
||||
address_sanitized_user_message: llmPreDecomposeMeta?.sanitizedUserMessage ?? null,
|
||||
address_tool_gate_decision: llmPreDecomposeMeta?.toolGateDecision ?? null,
|
||||
address_tool_gate_reason: llmPreDecomposeMeta?.toolGateReason ?? null,
|
||||
address_dialog_continuation_decision: llmPreDecomposeMeta?.dialogContinuationContract?.decision ?? null,
|
||||
address_dialog_continuation_target_intent: llmPreDecomposeMeta?.dialogContinuationContract?.target_intent ?? null,
|
||||
address_retry_attempted: Boolean(llmPreDecomposeMeta?.addressRetryAudit?.attempted),
|
||||
address_retry_reason: llmPreDecomposeMeta?.addressRetryAudit?.reason ?? null,
|
||||
address_retry_initial_limited_category: llmPreDecomposeMeta?.addressRetryAudit?.initial_limited_category ?? null,
|
||||
address_retry_result_category: llmPreDecomposeMeta?.addressRetryAudit?.retry_result_category ?? null,
|
||||
address_llm_predecompose_contract_intent: llmPreDecomposeMeta?.predecomposeContract?.intent ?? null,
|
||||
address_llm_predecompose_contract_aggregation_profile: llmPreDecomposeMeta?.predecomposeContract?.aggregation_profile ?? null,
|
||||
address_llm_predecompose_contract_period_scope: llmPreDecomposeMeta?.predecomposeContract?.period?.scope ?? null,
|
||||
detected_mode: addressLane.debug.detected_mode,
|
||||
query_shape: addressLane.debug.query_shape,
|
||||
detected_intent: addressLane.debug.detected_intent,
|
||||
extracted_filters: addressLane.debug.extracted_filters,
|
||||
selected_recipe: addressLane.debug.selected_recipe,
|
||||
mcp_call_status_legacy: addressLane.debug.mcp_call_status_legacy,
|
||||
account_scope_mode: addressLane.debug.account_scope_mode,
|
||||
account_scope_fallback_applied: addressLane.debug.account_scope_fallback_applied,
|
||||
anchor_type: addressLane.debug.anchor_type,
|
||||
resolver_confidence: addressLane.debug.resolver_confidence,
|
||||
match_failure_stage: addressLane.debug.match_failure_stage,
|
||||
match_failure_reason: addressLane.debug.match_failure_reason,
|
||||
mcp_call_status: addressLane.debug.mcp_call_status,
|
||||
rows_fetched: addressLane.debug.rows_fetched,
|
||||
raw_rows_received: addressLane.debug.raw_rows_received,
|
||||
rows_after_account_scope: addressLane.debug.rows_after_account_scope,
|
||||
rows_after_recipe_filter: addressLane.debug.rows_after_recipe_filter,
|
||||
rows_materialized: addressLane.debug.rows_materialized,
|
||||
rows_matched: addressLane.debug.rows_matched,
|
||||
materialization_drop_reason: addressLane.debug.materialization_drop_reason,
|
||||
account_token_raw: addressLane.debug.account_token_raw,
|
||||
account_token_normalized: addressLane.debug.account_token_normalized,
|
||||
account_scope_fields_checked: addressLane.debug.account_scope_fields_checked,
|
||||
account_scope_match_strategy: addressLane.debug.account_scope_match_strategy,
|
||||
account_scope_drop_reason: addressLane.debug.account_scope_drop_reason,
|
||||
runtime_readiness: addressLane.debug.runtime_readiness,
|
||||
limited_reason_category: addressLane.debug.limited_reason_category,
|
||||
response_type: addressLane.debug.response_type,
|
||||
limitations: addressLane.debug.limitations,
|
||||
assistant_reply: assistantItem.text,
|
||||
reply_type: assistantItem.reply_type,
|
||||
trace_id: assistantItem.trace_id
|
||||
}
|
||||
});
|
||||
return {
|
||||
ok: true,
|
||||
session_id: sessionId,
|
||||
assistant_reply: assistantItem.text,
|
||||
reply_type: assistantItem.reply_type,
|
||||
conversation_item: assistantItem,
|
||||
userMessage,
|
||||
effectiveAddressUserMessage,
|
||||
assistantReply: safeAddressReply,
|
||||
replyType: addressLane.reply_type,
|
||||
addressLaneDebug: addressLane.debug,
|
||||
debug,
|
||||
conversation
|
||||
};
|
||||
carryoverMeta,
|
||||
llmPreDecomposeMeta,
|
||||
appendItem: (targetSessionId, item) => this.sessions.appendItem(targetSessionId, item),
|
||||
getSession: (targetSessionId) => this.sessions.getSession(targetSessionId),
|
||||
persistSession: (sessionState) => this.sessionLogger.persistSession(sessionState),
|
||||
cloneConversation: (items) => cloneItems(items),
|
||||
logEvent: (payload) => (0, log_1.logJson)(payload),
|
||||
messageIdFactory: () => `msg-${(0, nanoid_1.nanoid)(10)}`
|
||||
});
|
||||
return finalization.response;
|
||||
};
|
||||
const tryHandleLivingChat = async (modeDecision, addressRuntimeMeta = null) => {
|
||||
try {
|
||||
@@ -5098,26 +5024,20 @@ class AssistantService {
|
||||
const debug = packagingRuntime.debug;
|
||||
const assistantItem = packagingRuntime.assistantItem;
|
||||
const deepAnalysisLogDetails = packagingRuntime.deepAnalysisLogDetails;
|
||||
const commitResult = (0, assistantTurnCommitRuntimeAdapter_1.commitAssistantTurnAndLog)({
|
||||
const finalization = (0, assistantDeepTurnFinalizeRuntimeAdapter_1.finalizeAssistantDeepTurn)({
|
||||
sessionId,
|
||||
assistantReply: safeAssistantReply,
|
||||
replyType: composition.reply_type,
|
||||
assistantItem,
|
||||
eventType: "assistant_message",
|
||||
logDetails: deepAnalysisLogDetails,
|
||||
debug,
|
||||
deepAnalysisLogDetails,
|
||||
appendItem: (targetSessionId, item) => this.sessions.appendItem(targetSessionId, item),
|
||||
getSession: (targetSessionId) => this.sessions.getSession(targetSessionId),
|
||||
persistSession: (sessionState) => this.sessionLogger.persistSession(sessionState),
|
||||
cloneConversation: (items) => cloneItems(items),
|
||||
logEvent: (payload) => (0, log_1.logJson)(payload)
|
||||
});
|
||||
const conversation = commitResult.conversation;
|
||||
return (0, assistantDeepTurnResponseBuilder_1.buildAssistantDeepTurnSuccessResponse)({
|
||||
sessionId,
|
||||
assistantReply: safeAssistantReply,
|
||||
replyType: composition.reply_type,
|
||||
conversationItem: assistantItem,
|
||||
debug,
|
||||
conversation
|
||||
});
|
||||
return finalization.response;
|
||||
}
|
||||
}
|
||||
exports.AssistantService = AssistantService;
|
||||
|
||||
Reference in New Issue
Block a user