Архитектура: убрать legacy active-organization callback из session-scope bootstrap и упростить organization authority path
This commit is contained in:
-2
@@ -42,12 +42,10 @@ function resolveSessionOrganizationScopeContextRuntime(input) {
|
||||
...input.extractKnownOrganizationsFromHistory(input.items)
|
||||
].map((value) => [String(value).toLowerCase(), value])).values());
|
||||
const selectedOrganization = input.resolveOrganizationSelectionFromMessage(input.userMessage, knownOrganizations);
|
||||
const lastActiveOrganization = input.findLastAssistantActiveOrganization(input.items);
|
||||
const navigationActiveOrganization = resolveActiveOrganizationFromNavigationState(input.addressNavigationState, input.normalizeOrganizationScopeValue);
|
||||
const activeOrganization = selectedOrganization ??
|
||||
navigationActiveOrganization ??
|
||||
continuityActiveOrganization ??
|
||||
input.normalizeOrganizationScopeValue(lastActiveOrganization) ??
|
||||
(knownOrganizations.length === 1 ? knownOrganizations[0] : null);
|
||||
return {
|
||||
knownOrganizations,
|
||||
|
||||
@@ -4539,74 +4539,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) {
|
||||
@@ -4643,7 +4575,6 @@ function resolveSessionOrganizationScopeContext(userMessage, items, addressNavig
|
||||
addressNavigationState,
|
||||
extractKnownOrganizationsFromHistory: assistantDataScopePolicy.extractKnownOrganizationsFromHistory,
|
||||
resolveOrganizationSelectionFromMessage,
|
||||
findLastAssistantActiveOrganization: assistantDataScopePolicy.findLastAssistantActiveOrganization,
|
||||
normalizeOrganizationScopeValue
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ describe("assistant organization scope runtime adapter", () => {
|
||||
it("resolves selected organization from user message and promotes it to active scope", () => {
|
||||
const extractKnownOrganizationsFromHistory = vi.fn(() => ["Org A", "Org B"]);
|
||||
const resolveOrganizationSelectionFromMessage = vi.fn(() => "Org B");
|
||||
const findLastAssistantActiveOrganization = vi.fn(() => "Org A");
|
||||
const normalizeOrganizationScopeValue = vi.fn((value: unknown) =>
|
||||
typeof value === "string" && value.trim() ? value.trim() : null
|
||||
);
|
||||
@@ -18,7 +17,6 @@ describe("assistant organization scope runtime adapter", () => {
|
||||
items: [] as any[],
|
||||
extractKnownOrganizationsFromHistory,
|
||||
resolveOrganizationSelectionFromMessage,
|
||||
findLastAssistantActiveOrganization,
|
||||
normalizeOrganizationScopeValue
|
||||
});
|
||||
|
||||
@@ -39,7 +37,6 @@ describe("assistant organization scope runtime adapter", () => {
|
||||
items: [] as any[],
|
||||
extractKnownOrganizationsFromHistory: () => ["Org A"],
|
||||
resolveOrganizationSelectionFromMessage: () => null,
|
||||
findLastAssistantActiveOrganization: () => "Org A",
|
||||
normalizeOrganizationScopeValue
|
||||
});
|
||||
|
||||
@@ -48,7 +45,6 @@ describe("assistant organization scope runtime adapter", () => {
|
||||
selectedOrganization: null,
|
||||
activeOrganization: "Org A"
|
||||
});
|
||||
expect(normalizeOrganizationScopeValue).toHaveBeenCalledWith("Org A");
|
||||
});
|
||||
|
||||
it("prefers organization scope from address navigation state when present", () => {
|
||||
@@ -79,7 +75,6 @@ describe("assistant organization scope runtime adapter", () => {
|
||||
} as any,
|
||||
extractKnownOrganizationsFromHistory: () => ["Org A"],
|
||||
resolveOrganizationSelectionFromMessage: () => null,
|
||||
findLastAssistantActiveOrganization: () => "Org A",
|
||||
normalizeOrganizationScopeValue
|
||||
});
|
||||
|
||||
@@ -108,7 +103,6 @@ describe("assistant organization scope runtime adapter", () => {
|
||||
] as any[],
|
||||
extractKnownOrganizationsFromHistory: () => [],
|
||||
resolveOrganizationSelectionFromMessage: () => null,
|
||||
findLastAssistantActiveOrganization: () => null,
|
||||
normalizeOrganizationScopeValue
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user