Архитектура: протянуть shared organization authority в data-scope history recovery и session bootstrap
This commit is contained in:
@@ -249,39 +249,18 @@ export function createAssistantDataScopePolicy(deps: AssistantDataScopePolicyDep
|
||||
}
|
||||
|
||||
function extractKnownOrganizationsFromHistory(items: unknown[]): string[] {
|
||||
const collected: unknown[] = [];
|
||||
const authority = resolveAssistantOrganizationAuthority({
|
||||
sessionItems: items,
|
||||
toNonEmptyString: normalizeOrganizationScopeValue,
|
||||
normalizeOrganizationScopeValue,
|
||||
mergeKnownOrganizations
|
||||
});
|
||||
const collected: unknown[] = [...authority.knownOrganizations];
|
||||
for (let index = (Array.isArray(items) ? items.length : 0) - 1; index >= 0; index -= 1) {
|
||||
const item = Array.isArray(items) ? items[index] : null;
|
||||
if (!item || typeof item !== "object" || (item as { role?: string }).role !== "assistant") {
|
||||
continue;
|
||||
}
|
||||
|
||||
const debug = (item as { debug?: Record<string, unknown> }).debug;
|
||||
if (debug && typeof debug === "object") {
|
||||
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((value): value is string => Boolean(value));
|
||||
|
||||
if (
|
||||
directFromProbe.length > 0 ||
|
||||
knownFromDebug.length > 0 ||
|
||||
directFromCandidates.length > 0 ||
|
||||
directFromResolved.length > 0
|
||||
) {
|
||||
collected.push(...directFromProbe, ...knownFromDebug, ...directFromCandidates, ...directFromResolved);
|
||||
}
|
||||
}
|
||||
|
||||
const parsedFromText = parseOrganizationsFromDataScopeAssistantText((item as { text?: unknown }).text);
|
||||
if (parsedFromText.length > 0) {
|
||||
collected.push(...parsedFromText);
|
||||
|
||||
Reference in New Issue
Block a user