ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.37 - вынос LLM-вызов живого чата из assistantService (большой prompt-блок) в отдельный адаптер, чтобы assistantService стал заметно чище.

This commit is contained in:
2026-04-10 22:56:32 +03:00
parent be116dcbde
commit 0cc8f71068
6 changed files with 340 additions and 103 deletions
+50 -1
View File
@@ -1186,7 +1186,56 @@ Validation:
- `assistantLivingRouter.test.ts`
- `assistantWave10SettlementCorrectiveRegression.test.ts`
Status: **In progress (Phase 2.1 + 2.2 + 2.3 + 2.4 + 2.5 + 2.6 + 2.7 + 2.8 + 2.9 + 2.10 + 2.11 + 2.12 + 2.13 + 2.14 + 2.15 + 2.16 + 2.17 + 2.18 + 2.19 + 2.20 + 2.21 + 2.22 + 2.23 + 2.24 + 2.25 + 2.26 + 2.27 + 2.28 + 2.29 + 2.30 + 2.31 + 2.32 + 2.33 + 2.34 + 2.35 + 2.36 completed)**
Implemented in current pass (Phase 2.37):
1. Extracted living-chat LLM call/build block from `assistantService` into dedicated runtime adapter:
- `assistantLivingChatLlmRuntimeAdapter.ts`
- introduced:
- `runAssistantLivingChatLlmRuntime(...)`
2. Centralized living LLM execution sequence (behavior-preserving):
- context window assembly from session history;
- canon excerpt loading and prompt composition;
- model/token selection with guard clamp;
- output sanitization with stable fallback.
3. Rewired `assistantService` `tryHandleLivingChat(...)` closure to consume the new LLM runtime adapter.
4. Added focused unit tests:
- `assistantLivingChatLlmRuntimeAdapter.test.ts`
Validation:
1. `npm run build` passed.
2. Targeted living/address/deep followup pack passed:
- `assistantLivingChatLlmRuntimeAdapter.test.ts`
- `assistantLivingChatHandlerRuntimeAdapter.test.ts`
- `assistantLivingChatRuntimeAdapter.test.ts`
- `assistantAddressRuntimeAdapter.test.ts`
- `assistantAddressLaneResponseRuntimeAdapter.test.ts`
- `assistantDeepTurnResponseRuntimeAdapter.test.ts`
- `assistantDeepTurnPackagingRuntimeAdapter.test.ts`
- `assistantWave10SettlementCorrectiveRegression.test.ts`
Implemented in current pass (Phase 2.38):
1. Internalized living-chat prompt/context builders into `assistantLivingChatLlmRuntimeAdapter`:
- removed external builder dependencies from runtime input contract;
- centralized compacting + clipping + context/prompt projection directly in adapter.
2. Simplified `assistantService` living LLM call wiring:
- removed `buildLivingChatContextWindow` / `buildLivingChatPrompt` injection from `executeLlmChat`.
3. Updated focused tests for adapter-owned prompt assembly:
- `assistantLivingChatLlmRuntimeAdapter.test.ts` now verifies context carryover and user-message prompt shape.
4. Applied cleanup inside `assistantService` after the wiring simplification:
- removed dead local living prompt/context helper functions.
Validation:
1. `npm run build` passed.
2. Targeted living/address/deep followup pack passed:
- `assistantLivingChatLlmRuntimeAdapter.test.ts`
- `assistantLivingChatHandlerRuntimeAdapter.test.ts`
- `assistantLivingChatRuntimeAdapter.test.ts`
- `assistantAddressRuntimeAdapter.test.ts`
- `assistantAddressLaneResponseRuntimeAdapter.test.ts`
- `assistantDeepTurnResponseRuntimeAdapter.test.ts`
- `assistantDeepTurnPackagingRuntimeAdapter.test.ts`
- `assistantWave10SettlementCorrectiveRegression.test.ts`
Status: **In progress (Phase 2.1 + 2.2 + 2.3 + 2.4 + 2.5 + 2.6 + 2.7 + 2.8 + 2.9 + 2.10 + 2.11 + 2.12 + 2.13 + 2.14 + 2.15 + 2.16 + 2.17 + 2.18 + 2.19 + 2.20 + 2.21 + 2.22 + 2.23 + 2.24 + 2.25 + 2.26 + 2.27 + 2.28 + 2.29 + 2.30 + 2.31 + 2.32 + 2.33 + 2.34 + 2.35 + 2.36 + 2.37 + 2.38 completed)**
## Stage 3 (P2): Hybrid Semantic Layer (LLM + Deterministic Guards)