АРЧ АП11 - Архитектура после регресса: Архитектура: исправить deep-turn normalizer schema contract и вернуть hybrid follow-up authority в phase13 replay
This commit is contained in:
+30
-2
@@ -1,6 +1,24 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildAssistantDeepTurnNormalizationRuntime = buildAssistantDeepTurnNormalizationRuntime;
|
||||
const routeHintAdapter_1 = require("./routeHintAdapter");
|
||||
function resolveDeepTurnNormalizerPromptVersion(promptVersion) {
|
||||
const normalized = String(promptVersion ?? "").trim().toLowerCase();
|
||||
if (normalized === "normalizer_v2_0_2" ||
|
||||
normalized === "normalizer_v2_0_1" ||
|
||||
normalized === "normalizer_v2" ||
|
||||
normalized === "normalizer_v1") {
|
||||
return String(promptVersion);
|
||||
}
|
||||
return "normalizer_v2_0_2";
|
||||
}
|
||||
function canSynthesizeRouteSummary(normalized) {
|
||||
if (!normalized || typeof normalized !== "object") {
|
||||
return false;
|
||||
}
|
||||
const source = normalized;
|
||||
return Array.isArray(source.fragments);
|
||||
}
|
||||
async function buildAssistantDeepTurnNormalizationRuntime(input) {
|
||||
const investigationState = input.sessionInvestigationState;
|
||||
const canUseFollowupBinding = input.featureInvestigationStateV1 &&
|
||||
@@ -25,7 +43,8 @@ async function buildAssistantDeepTurnNormalizationRuntime(input) {
|
||||
baseUrl: input.payload.baseUrl,
|
||||
temperature: input.payload.temperature,
|
||||
maxOutputTokens: input.payload.maxOutputTokens,
|
||||
promptVersion: input.payload.promptVersion ?? "address_query_runtime_v1",
|
||||
promptVersion: resolveDeepTurnNormalizerPromptVersion(input.payload.promptVersion),
|
||||
schemaVersion: "v2_0_2",
|
||||
systemPrompt: input.payload.systemPrompt,
|
||||
developerPrompt: input.payload.developerPrompt,
|
||||
domainPrompt: input.payload.domainPrompt,
|
||||
@@ -35,9 +54,18 @@ async function buildAssistantDeepTurnNormalizationRuntime(input) {
|
||||
useMock: Boolean(input.payload.useMock)
|
||||
};
|
||||
const normalized = await input.normalize(normalizePayload);
|
||||
const normalizedPayload = normalized.normalized;
|
||||
const synthesizedRouteSummary = normalized.route_hint_summary ??
|
||||
(normalizedPayload && canSynthesizeRouteSummary(normalizedPayload) ? (0, routeHintAdapter_1.toRouteHintSummary)(normalizedPayload) : null);
|
||||
const normalizedWithRouteSummary = synthesizedRouteSummary === normalized.route_hint_summary
|
||||
? normalized
|
||||
: {
|
||||
...normalized,
|
||||
route_hint_summary: synthesizedRouteSummary
|
||||
};
|
||||
return {
|
||||
followupBinding,
|
||||
normalizePayload,
|
||||
normalized
|
||||
normalized: normalizedWithRouteSummary
|
||||
};
|
||||
}
|
||||
|
||||
+36
-2
@@ -2,6 +2,7 @@ import type { AssistantMessageRequestPayload } from "../types/assistant";
|
||||
import type { NormalizeRequestPayload, NormalizeResponsePayload } from "../types/normalizer";
|
||||
import type { InvestigationStateWithProblemUnits } from "../types/stage2ProblemUnits";
|
||||
import type { AssistantFollowupUsage } from "./assistantFollowupUsage";
|
||||
import { toRouteHintSummary } from "./routeHintAdapter";
|
||||
|
||||
export interface AssistantDeepTurnFollowupBinding {
|
||||
normalizedQuestion: string;
|
||||
@@ -29,6 +30,27 @@ export interface BuildAssistantDeepTurnNormalizationRuntimeOutput {
|
||||
normalized: NormalizeResponsePayload;
|
||||
}
|
||||
|
||||
function resolveDeepTurnNormalizerPromptVersion(promptVersion: NormalizeRequestPayload["promptVersion"]): string {
|
||||
const normalized = String(promptVersion ?? "").trim().toLowerCase();
|
||||
if (
|
||||
normalized === "normalizer_v2_0_2" ||
|
||||
normalized === "normalizer_v2_0_1" ||
|
||||
normalized === "normalizer_v2" ||
|
||||
normalized === "normalizer_v1"
|
||||
) {
|
||||
return String(promptVersion);
|
||||
}
|
||||
return "normalizer_v2_0_2";
|
||||
}
|
||||
|
||||
function canSynthesizeRouteSummary(normalized: NormalizeResponsePayload["normalized"]): boolean {
|
||||
if (!normalized || typeof normalized !== "object") {
|
||||
return false;
|
||||
}
|
||||
const source = normalized as unknown as Record<string, unknown>;
|
||||
return Array.isArray(source.fragments);
|
||||
}
|
||||
|
||||
export async function buildAssistantDeepTurnNormalizationRuntime(
|
||||
input: BuildAssistantDeepTurnNormalizationRuntimeInput
|
||||
): Promise<BuildAssistantDeepTurnNormalizationRuntimeOutput> {
|
||||
@@ -58,7 +80,8 @@ export async function buildAssistantDeepTurnNormalizationRuntime(
|
||||
baseUrl: input.payload.baseUrl,
|
||||
temperature: input.payload.temperature,
|
||||
maxOutputTokens: input.payload.maxOutputTokens,
|
||||
promptVersion: input.payload.promptVersion ?? "address_query_runtime_v1",
|
||||
promptVersion: resolveDeepTurnNormalizerPromptVersion(input.payload.promptVersion),
|
||||
schemaVersion: "v2_0_2",
|
||||
systemPrompt: input.payload.systemPrompt,
|
||||
developerPrompt: input.payload.developerPrompt,
|
||||
domainPrompt: input.payload.domainPrompt,
|
||||
@@ -69,10 +92,21 @@ export async function buildAssistantDeepTurnNormalizationRuntime(
|
||||
};
|
||||
|
||||
const normalized = await input.normalize(normalizePayload);
|
||||
const normalizedPayload = normalized.normalized;
|
||||
const synthesizedRouteSummary =
|
||||
normalized.route_hint_summary ??
|
||||
(normalizedPayload && canSynthesizeRouteSummary(normalizedPayload) ? toRouteHintSummary(normalizedPayload) : null);
|
||||
const normalizedWithRouteSummary: NormalizeResponsePayload =
|
||||
synthesizedRouteSummary === normalized.route_hint_summary
|
||||
? normalized
|
||||
: {
|
||||
...normalized,
|
||||
route_hint_summary: synthesizedRouteSummary
|
||||
};
|
||||
|
||||
return {
|
||||
followupBinding,
|
||||
normalizePayload,
|
||||
normalized
|
||||
normalized: normalizedWithRouteSummary
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ describe("assistant deep turn normalization runtime adapter", () => {
|
||||
temperature: 0.2,
|
||||
maxOutputTokens: 333,
|
||||
promptVersion: "normalizer_v2_0_2",
|
||||
schemaVersion: "v2_0_2",
|
||||
systemPrompt: "sys",
|
||||
developerPrompt: "dev",
|
||||
domainPrompt: "dom",
|
||||
@@ -123,7 +124,8 @@ describe("assistant deep turn normalization runtime adapter", () => {
|
||||
baseUrl: undefined,
|
||||
temperature: undefined,
|
||||
maxOutputTokens: undefined,
|
||||
promptVersion: "address_query_runtime_v1",
|
||||
promptVersion: "normalizer_v2_0_2",
|
||||
schemaVersion: "v2_0_2",
|
||||
systemPrompt: undefined,
|
||||
developerPrompt: undefined,
|
||||
domainPrompt: undefined,
|
||||
@@ -142,4 +144,110 @@ describe("assistant deep turn normalization runtime adapter", () => {
|
||||
usage: null
|
||||
});
|
||||
});
|
||||
|
||||
it("synthesizes route summary from normalized payload when normalize omits it", async () => {
|
||||
const normalize = vi.fn(async () => ({
|
||||
trace_id: "trace-3",
|
||||
ok: true,
|
||||
normalized: {
|
||||
schema_version: "normalized_query_v2_0_2",
|
||||
user_message_raw: "Разложи хвосты по поставщикам",
|
||||
message_in_scope: true,
|
||||
scope_confidence: "high",
|
||||
contains_multiple_tasks: false,
|
||||
discarded_fragments: [],
|
||||
global_notes: {
|
||||
needs_clarification: false,
|
||||
clarification_reason: null
|
||||
},
|
||||
fragments: [
|
||||
{
|
||||
fragment_id: "F1",
|
||||
raw_fragment_text: "Разложи хвосты по поставщикам: где разрыв между оплатой и документами выглядит системным.",
|
||||
normalized_fragment_text:
|
||||
"Разложи хвосты по поставщикам: где разрыв между оплатой и документами выглядит системным.",
|
||||
domain_relevance: "in_scope",
|
||||
business_scope: "company_specific_accounting",
|
||||
entity_hints: ["контрагент", "документ"],
|
||||
account_hints: ["60"],
|
||||
document_hints: ["документ"],
|
||||
register_hints: [],
|
||||
time_scope: {
|
||||
type: "missing",
|
||||
value: null,
|
||||
confidence: "low"
|
||||
},
|
||||
flags: {
|
||||
has_multi_entity_scope: true,
|
||||
asks_for_chain_explanation: true,
|
||||
asks_for_ranking_or_top: false,
|
||||
asks_for_period_summary: false,
|
||||
asks_for_rule_check: false,
|
||||
asks_for_anomaly_scan: true,
|
||||
asks_for_exact_object_trace: false,
|
||||
asks_for_evidence: true,
|
||||
mentions_period_close_context: false
|
||||
},
|
||||
semantic_hints: {
|
||||
scope_target_kind: "none",
|
||||
scope_target_text: null,
|
||||
date_scope_kind: "missing",
|
||||
self_scope_detected: false,
|
||||
selected_object_scope_detected: false
|
||||
},
|
||||
candidate_labels: ["cross_entity", "anomaly_probe"],
|
||||
confidence: "medium",
|
||||
execution_readiness: "executable_with_soft_assumptions",
|
||||
clarification_reason: null,
|
||||
soft_assumption_used: ["problem_scan_mode_enabled"],
|
||||
route_status: "routed",
|
||||
no_route_reason: null
|
||||
}
|
||||
]
|
||||
},
|
||||
route_hint_summary: null,
|
||||
raw_model_output: {},
|
||||
validation: { passed: true, errors: [] },
|
||||
usage: { input_tokens: 1, output_tokens: 1, total_tokens: 2 },
|
||||
latency_ms: 1,
|
||||
prompt_version: "normalizer_v2_0_2",
|
||||
schema_version: "normalized_query_v2_0_2",
|
||||
request_count_for_case: 1
|
||||
}));
|
||||
|
||||
const runtime = await buildAssistantDeepTurnNormalizationRuntime({
|
||||
userMessage: "Разложи хвосты по поставщикам",
|
||||
payload: {
|
||||
llmProvider: "openai",
|
||||
promptVersion: "address_query_runtime_v1",
|
||||
useMock: true
|
||||
},
|
||||
featureInvestigationStateV1: false,
|
||||
featureStateFollowupBindingV1: false,
|
||||
sessionInvestigationState: null,
|
||||
buildFollowupStateBinding: vi.fn(),
|
||||
normalize
|
||||
});
|
||||
|
||||
expect(runtime.normalized.route_hint_summary).toEqual(
|
||||
expect.objectContaining({
|
||||
mode: "deterministic_v2",
|
||||
fallback: expect.objectContaining({
|
||||
type: "none"
|
||||
}),
|
||||
decisions: [
|
||||
expect.objectContaining({
|
||||
fragment_id: "F1",
|
||||
route: "hybrid_store_plus_live"
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
expect(normalize).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
promptVersion: "normalizer_v2_0_2",
|
||||
schemaVersion: "v2_0_2"
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user