ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.42: вынос finalizeAddressLaneResponse из assistantService в отдельный attempt-bridge (как для living chat), для уменьшения монолита без изменения поведения.
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runAssistantAddressLaneResponseAttemptRuntime = runAssistantAddressLaneResponseAttemptRuntime;
|
||||
const assistantAddressLaneResponseRuntimeAdapter_1 = require("./assistantAddressLaneResponseRuntimeAdapter");
|
||||
function runAssistantAddressLaneResponseAttemptRuntime(input) {
|
||||
const runAddressLaneResponseRuntimeSafe = input.runAddressLaneResponseRuntime ?? assistantAddressLaneResponseRuntimeAdapter_1.runAssistantAddressLaneResponseRuntime;
|
||||
const runtime = runAddressLaneResponseRuntimeSafe({
|
||||
sessionId: input.sessionId,
|
||||
userMessage: input.userMessage,
|
||||
effectiveAddressUserMessage: input.effectiveAddressUserMessage,
|
||||
addressLane: input.addressLane,
|
||||
carryoverMeta: input.carryoverMeta,
|
||||
llmPreDecomposeMeta: input.llmPreDecomposeMeta,
|
||||
knownOrganizations: input.knownOrganizations,
|
||||
activeOrganization: input.activeOrganization,
|
||||
sanitizeOutgoingAssistantText: input.sanitizeOutgoingAssistantText,
|
||||
buildAddressDebugPayload: input.buildAddressDebugPayload,
|
||||
buildAddressFollowupOffer: input.buildAddressFollowupOffer,
|
||||
mergeKnownOrganizations: input.mergeKnownOrganizations,
|
||||
toNonEmptyString: input.toNonEmptyString,
|
||||
appendItem: input.appendItem,
|
||||
getSession: input.getSession,
|
||||
persistSession: input.persistSession,
|
||||
cloneConversation: input.cloneConversation,
|
||||
logEvent: input.logEvent,
|
||||
messageIdFactory: input.messageIdFactory
|
||||
});
|
||||
return runtime.response;
|
||||
}
|
||||
+22
-25
@@ -65,7 +65,7 @@ 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 assistantAddressLaneResponseRuntimeAdapter_1 = __importStar(require("./assistantAddressLaneResponseRuntimeAdapter"));
|
||||
const assistantAddressLaneResponseAttemptRuntimeAdapter_1 = __importStar(require("./assistantAddressLaneResponseAttemptRuntimeAdapter"));
|
||||
const assistantCoverageGrounding_1 = __importStar(require("./assistantCoverageGrounding"));
|
||||
const assistantDeepTurnAnalysisRuntimeAdapter_1 = __importStar(require("./assistantDeepTurnAnalysisRuntimeAdapter"));
|
||||
const assistantDeepTurnCompositionRuntimeAdapter_1 = __importStar(require("./assistantDeepTurnCompositionRuntimeAdapter"));
|
||||
@@ -4398,30 +4398,27 @@ class AssistantService {
|
||||
nowIso: () => new Date().toISOString()
|
||||
});
|
||||
const sessionOrganizationScope = resolveSessionOrganizationScopeContext(userMessage, session.items);
|
||||
const finalizeAddressLaneResponse = (addressLane, effectiveAddressUserMessage, carryoverMeta = null, llmPreDecomposeMeta = null) => {
|
||||
const runtime = (0, assistantAddressLaneResponseRuntimeAdapter_1.runAssistantAddressLaneResponseRuntime)({
|
||||
sessionId,
|
||||
userMessage,
|
||||
effectiveAddressUserMessage,
|
||||
addressLane,
|
||||
carryoverMeta,
|
||||
llmPreDecomposeMeta,
|
||||
knownOrganizations: sessionOrganizationScope.knownOrganizations,
|
||||
activeOrganization: sessionOrganizationScope.activeOrganization,
|
||||
sanitizeOutgoingAssistantText,
|
||||
buildAddressDebugPayload,
|
||||
buildAddressFollowupOffer,
|
||||
mergeKnownOrganizations,
|
||||
toNonEmptyString,
|
||||
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 runtime.response;
|
||||
};
|
||||
const finalizeAddressLaneResponse = (addressLane, effectiveAddressUserMessage, carryoverMeta = null, llmPreDecomposeMeta = null) => (0, assistantAddressLaneResponseAttemptRuntimeAdapter_1.runAssistantAddressLaneResponseAttemptRuntime)({
|
||||
sessionId,
|
||||
userMessage,
|
||||
effectiveAddressUserMessage,
|
||||
addressLane,
|
||||
carryoverMeta,
|
||||
llmPreDecomposeMeta,
|
||||
knownOrganizations: sessionOrganizationScope.knownOrganizations,
|
||||
activeOrganization: sessionOrganizationScope.activeOrganization,
|
||||
sanitizeOutgoingAssistantText,
|
||||
buildAddressDebugPayload,
|
||||
buildAddressFollowupOffer,
|
||||
mergeKnownOrganizations,
|
||||
toNonEmptyString,
|
||||
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)}`
|
||||
});
|
||||
const tryHandleLivingChat = async (modeDecision, addressRuntimeMeta = null) => (0, assistantLivingChatAttemptRuntimeAdapter_1.runAssistantLivingChatAttemptRuntime)({
|
||||
sessionId,
|
||||
userMessage,
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import type { AssistantMessageResponsePayload } from "../types/assistant";
|
||||
import {
|
||||
runAssistantAddressLaneResponseRuntime,
|
||||
type RunAssistantAddressLaneResponseRuntimeInput,
|
||||
type RunAssistantAddressLaneResponseRuntimeOutput
|
||||
} from "./assistantAddressLaneResponseRuntimeAdapter";
|
||||
|
||||
export interface RunAssistantAddressLaneResponseAttemptRuntimeInput<
|
||||
ResponseType = AssistantMessageResponsePayload
|
||||
> extends RunAssistantAddressLaneResponseRuntimeInput<ResponseType> {
|
||||
runAddressLaneResponseRuntime?: (
|
||||
input: RunAssistantAddressLaneResponseRuntimeInput<ResponseType>
|
||||
) => RunAssistantAddressLaneResponseRuntimeOutput<ResponseType>;
|
||||
}
|
||||
|
||||
export function runAssistantAddressLaneResponseAttemptRuntime<
|
||||
ResponseType = AssistantMessageResponsePayload
|
||||
>(
|
||||
input: RunAssistantAddressLaneResponseAttemptRuntimeInput<ResponseType>
|
||||
): ResponseType {
|
||||
const runAddressLaneResponseRuntimeSafe =
|
||||
input.runAddressLaneResponseRuntime ?? runAssistantAddressLaneResponseRuntime;
|
||||
const runtime = runAddressLaneResponseRuntimeSafe({
|
||||
sessionId: input.sessionId,
|
||||
userMessage: input.userMessage,
|
||||
effectiveAddressUserMessage: input.effectiveAddressUserMessage,
|
||||
addressLane: input.addressLane,
|
||||
carryoverMeta: input.carryoverMeta,
|
||||
llmPreDecomposeMeta: input.llmPreDecomposeMeta,
|
||||
knownOrganizations: input.knownOrganizations,
|
||||
activeOrganization: input.activeOrganization,
|
||||
sanitizeOutgoingAssistantText: input.sanitizeOutgoingAssistantText,
|
||||
buildAddressDebugPayload: input.buildAddressDebugPayload,
|
||||
buildAddressFollowupOffer: input.buildAddressFollowupOffer,
|
||||
mergeKnownOrganizations: input.mergeKnownOrganizations,
|
||||
toNonEmptyString: input.toNonEmptyString,
|
||||
appendItem: input.appendItem,
|
||||
getSession: input.getSession,
|
||||
persistSession: input.persistSession,
|
||||
cloneConversation: input.cloneConversation,
|
||||
logEvent: input.logEvent,
|
||||
messageIdFactory: input.messageIdFactory
|
||||
});
|
||||
return runtime.response;
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import * as openaiResponsesClient_1 from "./openaiResponsesClient";
|
||||
import * as addressMcpClient_1 from "./addressMcpClient";
|
||||
import * as capabilitiesRegistry_1 from "./capabilitiesRegistry";
|
||||
import * as assistantCanon_1 from "./assistantCanon";
|
||||
import * as assistantAddressLaneResponseRuntimeAdapter_1 from "./assistantAddressLaneResponseRuntimeAdapter";
|
||||
import * as assistantAddressLaneResponseAttemptRuntimeAdapter_1 from "./assistantAddressLaneResponseAttemptRuntimeAdapter";
|
||||
import * as assistantCoverageGrounding_1 from "./assistantCoverageGrounding";
|
||||
import * as assistantDeepTurnAnalysisRuntimeAdapter_1 from "./assistantDeepTurnAnalysisRuntimeAdapter";
|
||||
import * as assistantDeepTurnCompositionRuntimeAdapter_1 from "./assistantDeepTurnCompositionRuntimeAdapter";
|
||||
@@ -4353,8 +4353,7 @@ export class AssistantService {
|
||||
nowIso: () => new Date().toISOString()
|
||||
});
|
||||
const sessionOrganizationScope = resolveSessionOrganizationScopeContext(userMessage, session.items);
|
||||
const finalizeAddressLaneResponse = (addressLane, effectiveAddressUserMessage, carryoverMeta = null, llmPreDecomposeMeta = null) => {
|
||||
const runtime = (0, assistantAddressLaneResponseRuntimeAdapter_1.runAssistantAddressLaneResponseRuntime)({
|
||||
const finalizeAddressLaneResponse = (addressLane, effectiveAddressUserMessage, carryoverMeta = null, llmPreDecomposeMeta = null) => (0, assistantAddressLaneResponseAttemptRuntimeAdapter_1.runAssistantAddressLaneResponseAttemptRuntime)({
|
||||
sessionId,
|
||||
userMessage,
|
||||
effectiveAddressUserMessage,
|
||||
@@ -4375,8 +4374,6 @@ export class AssistantService {
|
||||
logEvent: (payload) => (0, log_1.logJson)(payload),
|
||||
messageIdFactory: () => `msg-${(0, nanoid_1.nanoid)(10)}`
|
||||
});
|
||||
return runtime.response;
|
||||
};
|
||||
const tryHandleLivingChat = async (modeDecision, addressRuntimeMeta = null) => (0, assistantLivingChatAttemptRuntimeAdapter_1.runAssistantLivingChatAttemptRuntime)({
|
||||
sessionId,
|
||||
userMessage,
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { runAssistantAddressLaneResponseAttemptRuntime } from "../src/services/assistantAddressLaneResponseAttemptRuntimeAdapter";
|
||||
|
||||
function buildInput(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
sessionId: "asst-1",
|
||||
userMessage: "где хвост по оплате",
|
||||
effectiveAddressUserMessage: "где хвост по оплате",
|
||||
addressLane: {
|
||||
reply_text: "address reply",
|
||||
reply_type: "factual_with_explanation",
|
||||
debug: { extracted_filters: {} }
|
||||
},
|
||||
carryoverMeta: null,
|
||||
llmPreDecomposeMeta: null,
|
||||
knownOrganizations: [],
|
||||
activeOrganization: null,
|
||||
sanitizeOutgoingAssistantText: (value: unknown, fallback = "") => {
|
||||
const text = String(value ?? "").trim();
|
||||
return text || fallback;
|
||||
},
|
||||
buildAddressDebugPayload: () => ({}),
|
||||
buildAddressFollowupOffer: () => null,
|
||||
mergeKnownOrganizations: (value: string[]) => value,
|
||||
toNonEmptyString: (value: unknown) => (typeof value === "string" && value.trim() ? value.trim() : null),
|
||||
appendItem: () => {},
|
||||
getSession: () => ({
|
||||
session_id: "asst-1",
|
||||
updated_at: "",
|
||||
items: [],
|
||||
investigation_state: null
|
||||
}),
|
||||
persistSession: () => {},
|
||||
cloneConversation: (items: unknown[]) => items,
|
||||
logEvent: () => {},
|
||||
messageIdFactory: () => "msg-1",
|
||||
...overrides
|
||||
} as any;
|
||||
}
|
||||
|
||||
describe("assistant address lane response attempt runtime adapter", () => {
|
||||
it("returns delegated runtime response", () => {
|
||||
const runAddressLaneResponseRuntime = vi.fn(() => ({
|
||||
response: { ok: true, lane: "address" },
|
||||
debug: { marker: "v1" }
|
||||
}));
|
||||
|
||||
const response = runAssistantAddressLaneResponseAttemptRuntime(
|
||||
buildInput({ runAddressLaneResponseRuntime })
|
||||
);
|
||||
|
||||
expect(response).toEqual({ ok: true, lane: "address" });
|
||||
expect(runAddressLaneResponseRuntime).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
sessionId: "asst-1",
|
||||
userMessage: "где хвост по оплате"
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("forwards carryover and llm predecompose metadata", () => {
|
||||
const carryoverMeta = { previousReplyType: "partial_coverage" };
|
||||
const llmPreDecomposeMeta = { mode: "supported", confidence: "high" };
|
||||
const runAddressLaneResponseRuntime = vi.fn(() => ({
|
||||
response: { ok: true },
|
||||
debug: {}
|
||||
}));
|
||||
|
||||
runAssistantAddressLaneResponseAttemptRuntime(
|
||||
buildInput({
|
||||
carryoverMeta,
|
||||
llmPreDecomposeMeta,
|
||||
runAddressLaneResponseRuntime
|
||||
})
|
||||
);
|
||||
|
||||
expect(runAddressLaneResponseRuntime).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
carryoverMeta,
|
||||
llmPreDecomposeMeta
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user