ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.49: вынос turnRuntimeDeps (фабрику зависимостей) из assistantService в отдельный deps-adapter, чтобы handleMessage стал совсем тонким.

This commit is contained in:
2026-04-11 00:47:38 +03:00
parent f1e621fccc
commit ca467cdecc
6 changed files with 465 additions and 147 deletions
@@ -0,0 +1,112 @@
import type { AssistantTurnRuntimeBuilderDeps } from "./assistantTurnRuntimeInputBuilder";
export interface AssistantTurnRuntimeDepsSessionsLike {
ensureSession: (sessionId: string) => unknown;
appendItem: (sessionId: string, item: unknown) => void;
getSession: (sessionId: string) => unknown;
setInvestigationState: (sessionId: string, snapshot: unknown) => void;
}
export interface AssistantTurnRuntimeDepsSessionLoggerLike {
persistSession: (sessionState: unknown) => void;
}
export interface AssistantTurnRuntimeDepsNormalizerLike {
normalize: (payload: unknown) => Promise<unknown>;
}
export interface AssistantTurnRuntimeDepsDataLayerLike {
executeRouteRuntime: (route: string, fragmentText: string, options?: unknown) => Promise<unknown>;
}
export interface AssistantTurnRuntimeDepsAddressQueryServiceLike {
tryHandle: (messageUsed: string, options?: unknown) => Promise<unknown>;
}
type BuilderDepsProvidedByAdapter = Pick<
AssistantTurnRuntimeBuilderDeps,
| "ensureSession"
| "appendItem"
| "getSession"
| "persistSession"
| "setInvestigationState"
| "normalize"
| "executeRouteRuntime"
| "tryAddressQueryHandle"
| "chatClient"
| "messageIdFactory"
| "nowIso"
| "defaultApiKey"
| "logEvent"
| "featureAssistantAddressQueryV1"
| "featureAddressLlmPredecomposeV1"
| "featureInvestigationStateV1"
| "featureStateFollowupBindingV1"
| "featureContractsV11"
| "featureAnswerPolicyV11"
| "featureProblemCentricAnswerV1"
| "featureLifecycleAnswerV1"
| "defaultModel"
| "defaultBaseUrl"
>;
type BuilderDepsPassThrough = Omit<AssistantTurnRuntimeBuilderDeps, keyof BuilderDepsProvidedByAdapter>;
export interface BuildAssistantTurnRuntimeDepsInput {
sessions: AssistantTurnRuntimeDepsSessionsLike;
sessionLogger: AssistantTurnRuntimeDepsSessionLoggerLike;
normalizerService: AssistantTurnRuntimeDepsNormalizerLike;
dataLayer: AssistantTurnRuntimeDepsDataLayerLike;
addressQueryService: AssistantTurnRuntimeDepsAddressQueryServiceLike;
chatClient: unknown;
messageIdFactory: () => string;
nowIso: () => string;
defaultApiKey: string;
logEvent: (payload: Record<string, unknown>) => void;
flags: {
featureAssistantAddressQueryV1: boolean;
featureAddressLlmPredecomposeV1: boolean;
featureInvestigationStateV1: boolean;
featureStateFollowupBindingV1: boolean;
featureContractsV11: boolean;
featureAnswerPolicyV11: boolean;
featureProblemCentricAnswerV1: boolean;
featureLifecycleAnswerV1: boolean;
};
defaults: {
defaultModel: string;
defaultBaseUrl: string;
};
helpers: BuilderDepsPassThrough;
}
export function buildAssistantTurnRuntimeDeps(
input: BuildAssistantTurnRuntimeDepsInput
): AssistantTurnRuntimeBuilderDeps {
return {
...input.helpers,
ensureSession: (sessionId) => input.sessions.ensureSession(sessionId) as any,
appendItem: (sessionId, item) => input.sessions.appendItem(sessionId, item as any),
getSession: (sessionId) => input.sessions.getSession(sessionId) as any,
persistSession: (sessionState) => input.sessionLogger.persistSession(sessionState as any),
setInvestigationState: (sessionId, snapshot) => input.sessions.setInvestigationState(sessionId, snapshot),
normalize: (payload) => input.normalizerService.normalize(payload),
executeRouteRuntime: (route, fragmentText, options) => input.dataLayer.executeRouteRuntime(route, fragmentText, options),
tryAddressQueryHandle: (messageUsed, options) => input.addressQueryService.tryHandle(messageUsed, options),
chatClient: input.chatClient,
messageIdFactory: input.messageIdFactory,
nowIso: input.nowIso,
defaultApiKey: input.defaultApiKey,
logEvent: input.logEvent,
featureAssistantAddressQueryV1: input.flags.featureAssistantAddressQueryV1,
featureAddressLlmPredecomposeV1: input.flags.featureAddressLlmPredecomposeV1,
featureInvestigationStateV1: input.flags.featureInvestigationStateV1,
featureStateFollowupBindingV1: input.flags.featureStateFollowupBindingV1,
featureContractsV11: input.flags.featureContractsV11,
featureAnswerPolicyV11: input.flags.featureAnswerPolicyV11,
featureProblemCentricAnswerV1: input.flags.featureProblemCentricAnswerV1,
featureLifecycleAnswerV1: input.flags.featureLifecycleAnswerV1,
defaultModel: input.defaults.defaultModel,
defaultBaseUrl: input.defaults.defaultBaseUrl
};
}