ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.40: вынос runAddressLaneAttempt (с merge контекста и вызовом addressQueryService) в отдельный runtime-адаптер из handleMessage
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runAssistantAddressLaneAttemptRuntime = runAssistantAddressLaneAttemptRuntime;
|
||||
async function runAssistantAddressLaneAttemptRuntime(input) {
|
||||
const followupContext = input.carryMeta?.followupContext && typeof input.carryMeta.followupContext === "object"
|
||||
? input.carryMeta.followupContext
|
||||
: null;
|
||||
const scopedFollowupContext = input.mergeFollowupContextWithOrganizationScope(followupContext, input.activeOrganization);
|
||||
if (scopedFollowupContext) {
|
||||
return input.runAddressQueryTryHandle(input.messageUsed, {
|
||||
followupContext: scopedFollowupContext,
|
||||
analysisDateHint: input.analysisDateHint
|
||||
});
|
||||
}
|
||||
return input.runAddressQueryTryHandle(input.messageUsed, {
|
||||
analysisDateHint: input.analysisDateHint
|
||||
});
|
||||
}
|
||||
+9
-12
@@ -79,6 +79,7 @@ const assistantDeepTurnNormalizationRuntimeAdapter_1 = __importStar(require("./a
|
||||
const assistantDeepTurnResponseRuntimeAdapter_1 = __importStar(require("./assistantDeepTurnResponseRuntimeAdapter"));
|
||||
const assistantDeepTurnRetrievalRuntimeAdapter_1 = __importStar(require("./assistantDeepTurnRetrievalRuntimeAdapter"));
|
||||
const assistantAddressRuntimeAdapter_1 = __importStar(require("./assistantAddressRuntimeAdapter"));
|
||||
const assistantAddressLaneAttemptRuntimeAdapter_1 = __importStar(require("./assistantAddressLaneAttemptRuntimeAdapter"));
|
||||
const assistantLivingChatHandlerRuntimeAdapter_1 = __importStar(require("./assistantLivingChatHandlerRuntimeAdapter"));
|
||||
const assistantLivingChatLlmRuntimeAdapter_1 = __importStar(require("./assistantLivingChatLlmRuntimeAdapter"));
|
||||
const assistantUserTurnBootstrapRuntimeAdapter_1 = __importStar(require("./assistantUserTurnBootstrapRuntimeAdapter"));
|
||||
@@ -4476,18 +4477,14 @@ class AssistantService {
|
||||
});
|
||||
};
|
||||
let addressRuntimeMetaForDeep = null;
|
||||
const runAddressLaneAttempt = async (messageUsed, carryMeta, analysisDateHint) => {
|
||||
const scopedFollowupContext = mergeFollowupContextWithOrganizationScope(carryMeta?.followupContext ?? null, sessionOrganizationScope.activeOrganization);
|
||||
if (scopedFollowupContext) {
|
||||
return this.addressQueryService.tryHandle(messageUsed, {
|
||||
followupContext: scopedFollowupContext,
|
||||
analysisDateHint
|
||||
});
|
||||
}
|
||||
return this.addressQueryService.tryHandle(messageUsed, {
|
||||
analysisDateHint
|
||||
});
|
||||
};
|
||||
const runAddressLaneAttempt = async (messageUsed, carryMeta, analysisDateHint) => (0, assistantAddressLaneAttemptRuntimeAdapter_1.runAssistantAddressLaneAttemptRuntime)({
|
||||
messageUsed,
|
||||
carryMeta: carryMeta ?? null,
|
||||
analysisDateHint: analysisDateHint ?? null,
|
||||
activeOrganization: sessionOrganizationScope.activeOrganization,
|
||||
mergeFollowupContextWithOrganizationScope,
|
||||
runAddressQueryTryHandle: (laneMessageUsed, options) => this.addressQueryService.tryHandle(laneMessageUsed, options)
|
||||
});
|
||||
const addressRuntime = await (0, assistantAddressRuntimeAdapter_1.runAssistantAddressRuntime)({
|
||||
featureAssistantAddressQueryV1: config_1.FEATURE_ASSISTANT_ADDRESS_QUERY_V1,
|
||||
sessionId,
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import type { AssistantAddressLaneLike } from "./assistantAddressLaneRuntimeAdapter";
|
||||
import type { AssistantAddressCarryoverLike } from "./assistantAddressOrchestrationRuntimeAdapter";
|
||||
|
||||
export interface RunAssistantAddressLaneAttemptRuntimeInput {
|
||||
messageUsed: string;
|
||||
carryMeta: AssistantAddressCarryoverLike | null;
|
||||
analysisDateHint: string | null;
|
||||
activeOrganization: string | null;
|
||||
mergeFollowupContextWithOrganizationScope: (
|
||||
followupContext: Record<string, unknown> | null,
|
||||
organization: string | null
|
||||
) => Record<string, unknown> | null;
|
||||
runAddressQueryTryHandle: (
|
||||
messageUsed: string,
|
||||
options: {
|
||||
followupContext?: Record<string, unknown>;
|
||||
analysisDateHint?: string | null;
|
||||
}
|
||||
) => Promise<AssistantAddressLaneLike | null>;
|
||||
}
|
||||
|
||||
export async function runAssistantAddressLaneAttemptRuntime(
|
||||
input: RunAssistantAddressLaneAttemptRuntimeInput
|
||||
): Promise<AssistantAddressLaneLike | null> {
|
||||
const followupContext =
|
||||
input.carryMeta?.followupContext && typeof input.carryMeta.followupContext === "object"
|
||||
? (input.carryMeta.followupContext as Record<string, unknown>)
|
||||
: null;
|
||||
const scopedFollowupContext = input.mergeFollowupContextWithOrganizationScope(
|
||||
followupContext,
|
||||
input.activeOrganization
|
||||
);
|
||||
if (scopedFollowupContext) {
|
||||
return input.runAddressQueryTryHandle(input.messageUsed, {
|
||||
followupContext: scopedFollowupContext,
|
||||
analysisDateHint: input.analysisDateHint
|
||||
});
|
||||
}
|
||||
return input.runAddressQueryTryHandle(input.messageUsed, {
|
||||
analysisDateHint: input.analysisDateHint
|
||||
});
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import * as assistantDeepTurnNormalizationRuntimeAdapter_1 from "./assistantDeep
|
||||
import * as assistantDeepTurnResponseRuntimeAdapter_1 from "./assistantDeepTurnResponseRuntimeAdapter";
|
||||
import * as assistantDeepTurnRetrievalRuntimeAdapter_1 from "./assistantDeepTurnRetrievalRuntimeAdapter";
|
||||
import * as assistantAddressRuntimeAdapter_1 from "./assistantAddressRuntimeAdapter";
|
||||
import * as assistantAddressLaneAttemptRuntimeAdapter_1 from "./assistantAddressLaneAttemptRuntimeAdapter";
|
||||
import * as assistantLivingChatHandlerRuntimeAdapter_1 from "./assistantLivingChatHandlerRuntimeAdapter";
|
||||
import * as assistantLivingChatLlmRuntimeAdapter_1 from "./assistantLivingChatLlmRuntimeAdapter";
|
||||
import * as assistantUserTurnBootstrapRuntimeAdapter_1 from "./assistantUserTurnBootstrapRuntimeAdapter";
|
||||
@@ -4431,18 +4432,14 @@ export class AssistantService {
|
||||
});
|
||||
};
|
||||
let addressRuntimeMetaForDeep = null;
|
||||
const runAddressLaneAttempt = async (messageUsed, carryMeta, analysisDateHint) => {
|
||||
const scopedFollowupContext = mergeFollowupContextWithOrganizationScope(carryMeta?.followupContext ?? null, sessionOrganizationScope.activeOrganization);
|
||||
if (scopedFollowupContext) {
|
||||
return this.addressQueryService.tryHandle(messageUsed, {
|
||||
followupContext: scopedFollowupContext,
|
||||
analysisDateHint
|
||||
});
|
||||
}
|
||||
return this.addressQueryService.tryHandle(messageUsed, {
|
||||
analysisDateHint
|
||||
});
|
||||
};
|
||||
const runAddressLaneAttempt = async (messageUsed, carryMeta, analysisDateHint) => (0, assistantAddressLaneAttemptRuntimeAdapter_1.runAssistantAddressLaneAttemptRuntime)({
|
||||
messageUsed,
|
||||
carryMeta: carryMeta ?? null,
|
||||
analysisDateHint: analysisDateHint ?? null,
|
||||
activeOrganization: sessionOrganizationScope.activeOrganization,
|
||||
mergeFollowupContextWithOrganizationScope,
|
||||
runAddressQueryTryHandle: (laneMessageUsed, options) => this.addressQueryService.tryHandle(laneMessageUsed, options)
|
||||
});
|
||||
const addressRuntime = await (0, assistantAddressRuntimeAdapter_1.runAssistantAddressRuntime)({
|
||||
featureAssistantAddressQueryV1: config_1.FEATURE_ASSISTANT_ADDRESS_QUERY_V1,
|
||||
sessionId,
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { runAssistantAddressLaneAttemptRuntime } from "../src/services/assistantAddressLaneAttemptRuntimeAdapter";
|
||||
|
||||
describe("assistant address lane attempt runtime adapter", () => {
|
||||
it("uses scoped followup context when available", async () => {
|
||||
const runAddressQueryTryHandle = vi.fn(async () => ({
|
||||
response_type: "READY"
|
||||
}));
|
||||
const result = await runAssistantAddressLaneAttemptRuntime({
|
||||
messageUsed: "msg",
|
||||
carryMeta: {
|
||||
followupContext: {
|
||||
previous_intent: "docs_by_counterparty"
|
||||
}
|
||||
},
|
||||
analysisDateHint: "2020-07-31",
|
||||
activeOrganization: "ООО Тест",
|
||||
mergeFollowupContextWithOrganizationScope: () => ({
|
||||
previous_intent: "docs_by_counterparty",
|
||||
active_organization: "ООО Тест"
|
||||
}),
|
||||
runAddressQueryTryHandle
|
||||
});
|
||||
|
||||
expect(runAddressQueryTryHandle).toHaveBeenCalledWith("msg", {
|
||||
followupContext: {
|
||||
previous_intent: "docs_by_counterparty",
|
||||
active_organization: "ООО Тест"
|
||||
},
|
||||
analysisDateHint: "2020-07-31"
|
||||
});
|
||||
expect(result).toEqual({
|
||||
response_type: "READY"
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to plain attempt when scoped followup context is empty", async () => {
|
||||
const runAddressQueryTryHandle = vi.fn(async () => null);
|
||||
await runAssistantAddressLaneAttemptRuntime({
|
||||
messageUsed: "msg",
|
||||
carryMeta: null,
|
||||
analysisDateHint: null,
|
||||
activeOrganization: null,
|
||||
mergeFollowupContextWithOrganizationScope: () => null,
|
||||
runAddressQueryTryHandle
|
||||
});
|
||||
|
||||
expect(runAddressQueryTryHandle).toHaveBeenCalledWith("msg", {
|
||||
analysisDateHint: null
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user