export interface WorldMapOrganization { id: string; name: string; shortName?: string; acronym?: string; region?: string; industry?: string; status?: string; summary?: string; mission?: string; businessServices?: string[]; domains?: string[]; weakPoints?: string[]; tags?: string[]; employees?: number; contextNotes?: string; } export interface WorldMapPerson { id: string; name: string; organizationId?: string; role?: string; department?: string; archetype?: string; favoriteQuestion?: string; summary?: string; strengths?: string[]; weaknesses?: string[]; tags?: string[]; } export interface WorldMapRelationship { id: string; label: string; subtitle: string; } export interface WorldMapRecord { id: string; kind: "organization" | "person" | "empty"; eyebrow: string; title: string; subtitle: string; summary: string; meta: string[]; details: string[]; highlights: string[]; weakPoints: string[]; tags: string[]; relationships: WorldMapRelationship[]; relatedRelationships: WorldMapRelationship[]; primaryAction: string; } export interface WorldMapRecordContext { organizationsById: Map; peopleById: Map; peopleByOrganization: Map; } export function createWorldMapRecordContext( organizations: WorldMapOrganization[], people: WorldMapPerson[], ): WorldMapRecordContext { const organizationsById = new Map(); const peopleById = new Map(); const peopleByOrganization = new Map(); for (const organization of organizations) { organizationsById.set(organization.id, organization); } for (const person of people) { peopleById.set(person.id, person); if (!person.organizationId) { continue; } const current = peopleByOrganization.get(person.organizationId) ?? []; current.push(person); peopleByOrganization.set(person.organizationId, current); } return { organizationsById, peopleById, peopleByOrganization, }; } export function compactList(values: string[]) { return values.filter((value) => Boolean(value && value.trim())); } export function buildWorldMapRecord(entityId: string, context: WorldMapRecordContext): WorldMapRecord { const organization = context.organizationsById.get(entityId); if (organization) { const roster = context.peopleByOrganization.get(organization.id) ?? []; return { id: organization.id, kind: "organization", eyebrow: organization.acronym || "Organization", title: organization.name, subtitle: organization.region || organization.industry || organization.status || "Operational dossier", summary: organization.summary || organization.contextNotes || "Markdown-backed organization profile.", meta: [ organization.industry ? `Industry: ${organization.industry}` : "Industry: n/a", organization.status ? `Status: ${organization.status}` : "Status: n/a", organization.employees ? `Employees: ${organization.employees}` : "Employees: n/a", roster.length ? `People: ${roster.length}` : "People: 0", ], details: compactList([organization.mission || "", organization.contextNotes || ""]), highlights: compactList(organization.businessServices?.length ? organization.businessServices : organization.domains || []), weakPoints: compactList(organization.weakPoints || []), tags: organization.tags || [], relationships: roster.map((person) => ({ id: person.id, label: person.name, subtitle: person.role || person.department || "Employee", })), relatedRelationships: [], primaryAction: roster[0]?.id ?? "", }; } const person = context.peopleById.get(entityId); if (person) { const organization = person.organizationId ? context.organizationsById.get(person.organizationId) : undefined; const coworkers = person.organizationId ? (context.peopleByOrganization.get(person.organizationId) ?? []).filter((candidate) => candidate.id !== person.id) : []; return { id: person.id, kind: "person", eyebrow: person.archetype || "Person", title: person.name, subtitle: person.role || person.department || organization?.shortName || "Individual dossier", summary: person.summary || person.favoriteQuestion || "Markdown-backed people profile.", meta: [ person.role ? `Role: ${person.role}` : "Role: n/a", person.department ? `Department: ${person.department}` : "Department: n/a", organization ? `Organization: ${organization.shortName}` : "Organization: n/a", ], details: compactList([ person.favoriteQuestion || "", organization ? organization.summary || organization.contextNotes || "" : "", ]), highlights: compactList(person.strengths?.length ? person.strengths : person.tags || []), weakPoints: compactList(person.weaknesses || []), tags: person.tags || [], relationships: organization ? [ { id: organization.id, label: organization.shortName || organization.name, subtitle: organization.industry || organization.region || "Organization", }, ] : [], relatedRelationships: coworkers.map((coworker) => ({ id: coworker.id, label: coworker.name, subtitle: coworker.role || coworker.department || "Colleague", })), primaryAction: organization?.id ?? "", }; } return { id: "", kind: "empty", eyebrow: "World map", title: "Select a company or person", subtitle: "The panel follows the topology selection.", summary: "Markdown content is explored through the scene and the side panel together.", meta: [], details: [], highlights: [], weakPoints: [], tags: [], relationships: [], relatedRelationships: [], primaryAction: "", }; }