ARCH: подключить MCP discovery к runtime meta

This commit is contained in:
2026-04-20 11:54:04 +03:00
parent de4e064885
commit f0d7e81ec0
4 changed files with 171 additions and 4 deletions
@@ -1,4 +1,8 @@
import { runAssistantRoutePolicyRuntime } from "./assistantRoutePolicyRuntimeAdapter";
import {
runAssistantMcpDiscoveryRuntimeEntryPoint,
type RunAssistantMcpDiscoveryRuntimeEntryPointInput
} from "./assistantMcpDiscoveryRuntimeEntryPoint";
import { hasInventoryProfitabilityCue } from "./inventoryLifecycleCueHelpers";
@@ -43,6 +47,9 @@ export interface BuildAssistantAddressOrchestrationRuntimeInput {
carryover: AssistantAddressCarryoverLike | null,
addressPreDecompose: Record<string, unknown>
) => unknown;
runMcpDiscoveryRuntimeEntryPoint?: (
input: RunAssistantMcpDiscoveryRuntimeEntryPointInput
) => Promise<Record<string, unknown>>;
}
export interface AssistantAddressCarryoverLike {
@@ -62,6 +69,13 @@ export interface BuildAssistantAddressOrchestrationRuntimeOutput {
};
}
function toRecordObject(value: unknown): Record<string, unknown> | null {
if (!value || typeof value !== "object" || Array.isArray(value)) {
return null;
}
return value as Record<string, unknown>;
}
function hasSelectedObjectInventorySignal(text: string | null): boolean {
return /(?:по\s+выбранному\s+объекту|по\s+выбранной\s+позиции|по\s+этой\s+позиции|по\s+этому\s+товару|по\s+ним|selected\s+object)/iu.test(
String(text ?? "")
@@ -283,19 +297,36 @@ export async function buildAssistantAddressOrchestrationRuntime(
resolveAssistantOrchestrationDecision: input.resolveAssistantOrchestrationDecision
});
const orchestrationDecision = routePolicyRuntime.orchestrationDecision;
const orchestrationContract = toRecordObject(orchestrationDecision.orchestrationContract);
const predecomposeContract = toRecordObject(addressPreDecompose.predecomposeContract);
const dialogContinuationContract = input.buildAddressDialogContinuationContractV2(
input.userMessage,
addressInputMessage,
carryover,
addressPreDecompose
);
const runDiscoveryEntryPoint = input.runMcpDiscoveryRuntimeEntryPoint ?? runAssistantMcpDiscoveryRuntimeEntryPoint;
let mcpDiscoveryRuntimeEntryPoint: Record<string, unknown> | null = null;
let mcpDiscoveryRuntimeEntryPointError: string | null = null;
try {
mcpDiscoveryRuntimeEntryPoint = (await runDiscoveryEntryPoint({
userMessage: input.userMessage,
effectiveMessage: addressInputMessage,
assistantTurnMeaning: toRecordObject(orchestrationContract?.assistant_turn_meaning),
predecomposeContract
})) as Record<string, unknown>;
} catch (error) {
mcpDiscoveryRuntimeEntryPointError = String(error instanceof Error ? error.message : error ?? "unknown_error").slice(0, 280);
}
const addressRuntimeMeta = {
...addressPreDecompose,
toolGateDecision: orchestrationDecision.toolGateDecision ?? null,
toolGateReason: orchestrationDecision.toolGateReason ?? null,
dialogContinuationContract,
orchestrationContract: orchestrationDecision.orchestrationContract ?? null,
routePolicyContract: routePolicyRuntime.routePolicyContract
orchestrationContract: orchestrationContract ?? null,
routePolicyContract: routePolicyRuntime.routePolicyContract,
mcpDiscoveryRuntimeEntryPoint,
mcpDiscoveryRuntimeEntryPointError
};
return {