Архитектура: убрать legacy active-organization callback из session-scope bootstrap и упростить organization authority path

This commit is contained in:
2026-04-18 21:43:09 +03:00
parent 59656a44a0
commit 8111586d8d
6 changed files with 5 additions and 149 deletions
@@ -13,7 +13,6 @@ export interface ResolveSessionOrganizationScopeContextRuntimeInput<ItemType = u
addressNavigationState?: AddressNavigationState | null;
extractKnownOrganizationsFromHistory: (items: ItemType[]) => string[];
resolveOrganizationSelectionFromMessage: (userMessage: string, knownOrganizations: string[]) => string | null;
findLastAssistantActiveOrganization: (items: ItemType[]) => string | null;
normalizeOrganizationScopeValue: (value: unknown) => string | null;
}
@@ -82,7 +81,6 @@ export function resolveSessionOrganizationScopeContextRuntime<ItemType = unknown
input.userMessage,
knownOrganizations
);
const lastActiveOrganization = input.findLastAssistantActiveOrganization(input.items);
const navigationActiveOrganization = resolveActiveOrganizationFromNavigationState(
input.addressNavigationState,
input.normalizeOrganizationScopeValue
@@ -91,7 +89,6 @@ export function resolveSessionOrganizationScopeContextRuntime<ItemType = unknown
selectedOrganization ??
navigationActiveOrganization ??
continuityActiveOrganization ??
input.normalizeOrganizationScopeValue(lastActiveOrganization) ??
(knownOrganizations.length === 1 ? knownOrganizations[0] : null);
return {
@@ -4495,74 +4495,6 @@ function extractKnownOrganizationsFromNavigationState(addressNavigationState) {
}
return mergeKnownOrganizations(collected);
}
function extractKnownOrganizationsFromHistory(items, addressNavigationState = null) {
const collected = [];
const navigationOrganizations = extractKnownOrganizationsFromNavigationState(addressNavigationState);
if (navigationOrganizations.length > 0) {
collected.push(...navigationOrganizations);
}
for (let index = (Array.isArray(items) ? items.length : 0) - 1; index >= 0; index -= 1) {
const item = items[index];
if (!item || item.role !== "assistant") {
continue;
}
const debug = item.debug && typeof item.debug === "object" ? item.debug : null;
if (debug) {
const directFromProbe = Array.isArray(debug.living_chat_data_scope_probe_organizations)
? debug.living_chat_data_scope_probe_organizations
: [];
const knownFromDebug = Array.isArray(debug.assistant_known_organizations)
? debug.assistant_known_organizations
: [];
const directFromCandidates = Array.isArray(debug.organization_candidates)
? debug.organization_candidates
: [];
const directFromResolved = [
normalizeOrganizationScopeValue(debug.assistant_active_organization),
normalizeOrganizationScopeValue(debug.living_chat_selected_organization),
normalizeOrganizationScopeValue(debug.extracted_filters?.organization),
normalizeOrganizationScopeValue(debug.address_root_frame_context?.organization)
].filter(Boolean);
if (directFromProbe.length > 0 || knownFromDebug.length > 0 || directFromCandidates.length > 0 || directFromResolved.length > 0) {
collected.push(...directFromProbe, ...knownFromDebug, ...directFromCandidates, ...directFromResolved);
}
}
const parsedFromText = parseOrganizationsFromDataScopeAssistantText(item.text);
if (parsedFromText.length > 0) {
collected.push(...parsedFromText);
}
if (collected.length >= 20) {
break;
}
}
return mergeKnownOrganizations(collected);
}
function findLastAssistantActiveOrganization(items, addressNavigationState = null) {
const sessionContext = addressNavigationState && typeof addressNavigationState === "object"
? (addressNavigationState.session_context && typeof addressNavigationState.session_context === "object"
? addressNavigationState.session_context
: null)
: null;
const navigationOrganization = normalizeOrganizationScopeValue(sessionContext?.organization_scope);
if (navigationOrganization) {
return navigationOrganization;
}
for (let index = (Array.isArray(items) ? items.length : 0) - 1; index >= 0; index -= 1) {
const item = items[index];
if (!item || item.role !== "assistant" || !item.debug || typeof item.debug !== "object") {
continue;
}
const direct = normalizeOrganizationScopeValue(item.debug.assistant_active_organization);
if (direct) {
return direct;
}
const selected = normalizeOrganizationScopeValue(item.debug.living_chat_selected_organization);
if (selected) {
return selected;
}
}
return null;
}
function resolveOrganizationSelectionFromMessage(userMessage, knownOrganizations) {
const known = mergeKnownOrganizations(knownOrganizations);
if (!userMessage || known.length === 0) {
@@ -4599,7 +4531,6 @@ function resolveSessionOrganizationScopeContext(userMessage, items, addressNavig
addressNavigationState,
extractKnownOrganizationsFromHistory: assistantDataScopePolicy.extractKnownOrganizationsFromHistory,
resolveOrganizationSelectionFromMessage,
findLastAssistantActiveOrganization: assistantDataScopePolicy.findLastAssistantActiveOrganization,
normalizeOrganizationScopeValue
});
}