{"version":3,"file":"sessionsStore.mjs","names":[],"sources":["../../../src/web/stores/sessionsStore.ts"],"sourcesContent":["import {\n  COORDINATOR_SESSION_PROVENANCE,\n  VOICE_ORCHESTRATOR_SESSION_PROVENANCE,\n  WORKFLOW_DISPATCHER_SESSION_PROVENANCE,\n  WORKFLOW_STEP_SESSION_PROVENANCE,\n} from '@agimon-ai/po-core/hubChannel';\nimport type { HubLifecycleSnapshot } from '@agimon-ai/po-core/sessionProtocol';\nimport { bindSessionApiWorkspace } from '@agimon-ai/po-core/web';\nimport { useStore } from '@tanstack/react-store';\nimport { Store } from '@tanstack/store';\n\nimport type { SessionSummary, WorkspaceSummary } from '../../types/hub';\nimport { defaultHostId, qualifyHostId, splitHostId } from '../lib/hostIdentity';\nimport type { MentionableSession } from '../lib/sessionMentions';\nimport { hasSessionProtocol } from '../lib/sessionProtocolCommands';\nimport { railSessionStatus, workspaceName } from '../lib/sessionRailModel';\nimport { type AttachPhase, summaryValueEqual } from '../lib/sessionSummary';\nimport { traceStore } from '../lib/uiTrace';\n\nconst READY_CHECK_MS = 500;\nconst READY_TIMEOUT_MS = 30_000;\n\n/** One rail entry: the hub's summary plus this page's view of its connection. */\nexport interface SessionMeta {\n  summary: SessionSummary;\n  /** Caller-specific UI rights, never persisted in the shared session summary. */\n  canInteract?: boolean;\n  /** summary.attach adjusted for sticky refusals and a lost page socket. */\n  attach: AttachPhase;\n  reason: string;\n  /** Frames replayed into this page's timeline on the last subscribe. */\n  replayed: number;\n  /** Frames the hub's bounded ring lost before this page subscribed. */\n  dropped: number;\n}\n\nexport interface SessionsState {\n  /** Session ids in rail order: each parent immediately followed by its children. */\n  order: string[];\n  byId: Record<string, SessionMeta>;\n  activeId: string | null;\n  /** Retained separately because permission and session projections may arrive in either order. */\n  interactions?: Readonly<Record<string, boolean>>;\n  /** Optional startup state, replaced independently of session and transport state. */\n  lifecycle?: Readonly<Record<string, HubLifecycleSnapshot>>;\n  /** URL/tab ownership stays with the parent when a tab focuses another session. */\n  tabOwnerId?: string | null;\n  /** Destination shown while an autonomous voice handoff changes route and media ownership. */\n  transferringToId: string | null;\n  /** False until the first snapshot; routing waits for it before redirecting. */\n  hydrated: boolean;\n  /** The server needs newer client code. Only a reload clears it. */\n  updateRequired: boolean;\n  updateRequiredHosts?: Readonly<Record<string, boolean>>;\n}\n\n/** The one reason every session shows once the server needs newer client code. */\nexport const UPDATE_REQUIRED_REASON = 'This app is older than the Po server. Update Po to reconnect.';\n\nconst initialState: SessionsState = {\n  order: [],\n  byId: {},\n  activeId: null,\n  transferringToId: null,\n  hydrated: false,\n  updateRequired: false,\n};\n\nexport const sessionsStore = traceStore('sessions', new Store<SessionsState>(initialState));\nbindSessionApiWorkspace((sessionId) => sessionsStore.state.byId[sessionId]?.summary.workspaceId);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n  return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction asSummary(value: unknown): SessionSummary | undefined {\n  if (!isRecord(value) || typeof value.id !== 'string' || value.id === '') return undefined;\n  return value as unknown as SessionSummary;\n}\n\n/**\n * The parent this session nests under, or undefined when it renders at the top\n * level.\n *\n * A parent that has since closed, this session itself, a parent in another\n * workspace, or a cycle all resolve to undefined. The only safe failure is to\n * render the row where it can still be seen rather than to hide or duplicate it.\n */\nexport function resolveParentId(byId: Record<string, SessionMeta>, id: string, limit?: number): string | undefined {\n  const parent = byId[id]?.summary.parentSessionId;\n  if (\n    parent === undefined ||\n    parent === id ||\n    byId[parent] === undefined ||\n    byId[parent].summary.workspaceId !== byId[id].summary.workspaceId\n  )\n    return undefined;\n  let hops = 0;\n  const hopLimit = limit ?? Object.keys(byId).length;\n  for (let at: string | undefined = parent; at !== undefined; at = byId[at]?.summary.parentSessionId) {\n    if (at === id) return undefined;\n    if (++hops > hopLimit) return undefined;\n  }\n  return parent;\n}\n\n/**\n * Internal sessions keep their history but take no rail row or keyboard ordinal. A workflow step's\n * session takes a row under its workflow while it runs; once released, it is read from the workflow.\n */\nfunction railHidden(meta: SessionMeta): boolean {\n  const provenance = meta.summary.sessionProvenance;\n  return (\n    (provenance === WORKFLOW_STEP_SESSION_PROVENANCE && meta.summary.dormant === true) ||\n    provenance === WORKFLOW_DISPATCHER_SESSION_PROVENANCE ||\n    provenance === VOICE_ORCHESTRATOR_SESSION_PROVENANCE\n  );\n}\n\n/**\n * Where a session sits in the rail: under its nearest ancestor the rail shows.\n *\n * A fork or worktree a step session opens is a real session, and under a\n * parent the rail leaves out it would never be listed, so it moves up to the\n * first ancestor that is, or becomes a root.\n */\nfunction railParentId(byId: Record<string, SessionMeta>, id: string, limit: number): string | undefined {\n  let parent = resolveParentId(byId, id, limit);\n  let hops = 0;\n  while (parent !== undefined && railHidden(byId[parent]) && hops++ <= limit)\n    parent = resolveParentId(byId, parent, limit);\n  return parent;\n}\n\n/** Each nested rail row mapped to the row it renders under, matching `order`. */\nexport function railParentIds(byId: Record<string, SessionMeta>, order: readonly string[]): Map<string, string> {\n  const parents = new Map<string, string>();\n  for (const id of order) {\n    const parent = railParentId(byId, id, Object.keys(byId).length);\n    if (parent !== undefined) parents.set(id, parent);\n  }\n  return parents;\n}\n\n/**\n * The rail's order: roots by creation, each immediately followed by its own\n * children.\n *\n * Ordinal shortcuts index this array positionally, which is why a child sits\n * directly after its parent instead of in a separate group: a worktree spawned\n * from the focused session lands on the next digit. With no lineage present\n * every session is a root and this produces exactly the flat creation sort it\n * replaces.\n */\nfunction sortedOrder(byId: Record<string, SessionMeta>): string[] {\n  // A finished workflow step's session is read inside its workflow, never from the rail, so it\n  // takes no row. It stays in `byId` for that view to follow. A workflow dispatcher is a\n  // short-lived helper whose runs belong to its parent.\n  const byCreation = (left: string, right: string): number => {\n    const a = byId[left].summary;\n    const b = byId[right].summary;\n    return a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id);\n  };\n  const children = new Map<string, string[]>();\n  const roots: string[] = [];\n  const ids = Object.keys(byId);\n  for (const id of ids) {\n    if (railHidden(byId[id])) continue;\n    const parent = railParentId(byId, id, ids.length);\n    if (parent === undefined) {\n      roots.push(id);\n      continue;\n    }\n    const siblings = children.get(parent);\n    if (siblings === undefined) children.set(parent, [id]);\n    else siblings.push(id);\n  }\n  // Coordinators are pinned: they lead the order, so they head their workspace and take the first digits.\n  const coordinator = (id: string): number =>\n    Number(byId[id].summary.sessionProvenance === COORDINATOR_SESSION_PROVENANCE);\n  roots.sort((left, right) => coordinator(right) - coordinator(left) || byCreation(left, right));\n  for (const siblings of children.values()) siblings.sort(byCreation);\n  const order: string[] = [];\n  const visit = (id: string): void => {\n    order.push(id);\n    for (const child of children.get(id) ?? []) visit(child);\n  };\n  for (const root of roots) visit(root);\n  return order;\n}\n\n/** True when two rail entries differ at most in `summary.updatedAt`, which the hub bumps on every settled message. */\nexport function sameRailEntry(left: SessionMeta | undefined, right: SessionMeta | undefined): boolean {\n  if (left === right) return true;\n  if (left === undefined || right === undefined) return false;\n  return (\n    left.canInteract === right.canInteract &&\n    left.attach === right.attach &&\n    left.reason === right.reason &&\n    left.replayed === right.replayed &&\n    left.dropped === right.dropped &&\n    summaryValueEqual({ ...left.summary, updatedAt: '' }, { ...right.summary, updatedAt: '' })\n  );\n}\n\n/** `byId` compared the way the rail reads it: an `updatedAt`-only change is no change. */\nexport function sameRailEntries(left: Record<string, SessionMeta>, right: Record<string, SessionMeta>): boolean {\n  if (left === right) return true;\n  const ids = Object.keys(left);\n  return ids.length === Object.keys(right).length && ids.every((id) => sameRailEntry(left[id], right[id]));\n}\n\nfunction mergeSummary(\n  previous: SessionMeta | undefined,\n  summary: SessionSummary,\n  updateRequired: boolean,\n  canInteract: boolean,\n): SessionMeta {\n  // A refusal stays sticky while the hub retries. Only a successful attach clears it.\n  const sticky = previous?.attach === 'refused' && summary.attach === 'connecting';\n  // HTTP still lists sessions after the socket stopped for good.\n  const attach = updateRequired ? 'offline' : sticky ? 'refused' : summary.attach;\n  const reason = updateRequired ? UPDATE_REQUIRED_REASON : sticky ? previous.reason : (summary.attachReason ?? '');\n  const retainedSummary = previous && summaryValueEqual(previous.summary, summary) ? previous.summary : summary;\n  if (\n    previous &&\n    retainedSummary === previous.summary &&\n    attach === previous.attach &&\n    reason === previous.reason &&\n    canInteract === previous.canInteract\n  )\n    return previous;\n  return {\n    summary: retainedSummary,\n    canInteract,\n    attach,\n    reason,\n    replayed: previous?.replayed ?? 0,\n    dropped: previous?.dropped ?? 0,\n  };\n}\n\nfunction retainOrder(previous: string[], byId: Record<string, SessionMeta>): string[] {\n  const next = sortedOrder(byId);\n  return previous.length === next.length && previous.every((id, index) => id === next[index]) ? previous : next;\n}\n\nfunction hostSummary(summary: SessionSummary, hostId?: string): SessionSummary {\n  if (hostId === undefined) return summary;\n  return {\n    ...summary,\n    id: qualifyHostId(hostId, summary.id),\n    ...(summary.workspaceId === undefined ? {} : { workspaceId: qualifyHostId(hostId, summary.workspaceId) }),\n    ...(summary.parentSessionId === undefined\n      ? {}\n      : { parentSessionId: qualifyHostId(hostId, summary.parentSessionId) }),\n  };\n}\nfunction belongsToHost(key: string, hostId?: string): boolean {\n  return splitHostId(key)?.hostId === hostId;\n}\n/** A full caller-specific projection for one host. An absent right is never writable. */\nexport function applySessionInteractions(rights: Readonly<Record<string, boolean>>, hostId?: string): void {\n  sessionsStore.setState((state) => {\n    const previous = state.interactions ?? {};\n    const interactions = Object.fromEntries([\n      ...Object.entries(previous).filter(([id]) => !belongsToHost(id, hostId)),\n      ...Object.entries(rights).filter(([id, value]) => belongsToHost(id, hostId) && typeof value === 'boolean'),\n    ]);\n    let changed =\n      Object.keys(previous).length !== Object.keys(interactions).length ||\n      Object.keys(interactions).some((id) => previous[id] !== interactions[id]);\n    const byId = Object.fromEntries(\n      Object.entries(state.byId).map(([id, meta]) => {\n        const canInteract = interactions[id] === true;\n        if (!belongsToHost(id, hostId) || meta.canInteract === canInteract) return [id, meta];\n        changed = true;\n        return [id, { ...meta, canInteract }];\n      }),\n    );\n    return changed ? { ...state, interactions, byId } : state;\n  });\n}\n\n/** Replaces only this host's lifecycle projection. Empty clears stale startup state. */\nexport function applySessionLifecycleSnapshot(\n  snapshots: Readonly<Record<string, HubLifecycleSnapshot>>,\n  hostId?: string,\n): void {\n  sessionsStore.setState((state) => ({\n    ...state,\n    lifecycle: Object.fromEntries([\n      ...Object.entries(state.lifecycle ?? {}).filter(([id]) => !belongsToHost(id, hostId)),\n      ...Object.entries(snapshots).filter(([id, value]) => belongsToHost(id, hostId) && value.sessionId === id),\n    ]),\n  }));\n}\n\nfunction needsUpdate(state: SessionsState, key: string): boolean {\n  const hostId = splitHostId(key)?.hostId;\n  return hostId === undefined ? state.updateRequired : state.updateRequiredHosts?.[hostId] === true;\n}\n\nexport function applySessionsSnapshot(frame: Record<string, unknown>, hostId?: string): void {\n  if (!Array.isArray(frame.sessions)) return;\n  const summaries = frame.sessions\n    .map(asSummary)\n    .filter((summary): summary is SessionSummary => Boolean(summary))\n    .map((summary) => hostSummary(summary, hostId));\n  sessionsStore.setState((state) => {\n    const byId: Record<string, SessionMeta> = Object.fromEntries(\n      Object.entries(state.byId).filter(([id]) => !belongsToHost(id, hostId)),\n    );\n    for (const summary of summaries)\n      byId[summary.id] = mergeSummary(\n        state.byId[summary.id],\n        summary,\n        needsUpdate(state, summary.id),\n        state.interactions?.[summary.id] === true,\n      );\n    if (\n      state.hydrated &&\n      Object.keys(state.byId).length === Object.keys(byId).length &&\n      Object.keys(byId).every((id) => byId[id] === state.byId[id])\n    )\n      return state;\n    return { ...state, byId, order: retainOrder(state.order, byId), hydrated: true };\n  });\n}\n\nexport function applySessionUpsert(frame: Record<string, unknown>, hostId?: string): void {\n  const parsed = asSummary(frame.session);\n  if (!parsed) return;\n  const summary = hostSummary(parsed, hostId);\n  sessionsStore.setState((state) => {\n    const meta = mergeSummary(\n      state.byId[summary.id],\n      summary,\n      needsUpdate(state, summary.id),\n      state.interactions?.[summary.id] === true,\n    );\n    if (meta === state.byId[summary.id]) return state;\n    const byId = { ...state.byId, [summary.id]: meta };\n    return { ...state, byId, order: retainOrder(state.order, byId) };\n  });\n}\n\nexport function applySessionRemoved(frame: Record<string, unknown>, hostId?: string): void {\n  if (typeof frame.sessionId !== 'string') return;\n  const sessionId = hostId === undefined ? frame.sessionId : qualifyHostId(hostId, frame.sessionId);\n  sessionsStore.setState((state) => {\n    if (!(sessionId in state.byId)) return state;\n    const byId = { ...state.byId };\n    delete byId[sessionId];\n    return { ...state, byId, order: retainOrder(state.order, byId) };\n  });\n}\n\n/** Records what the hub replayed into this page when a subscription started. */\nexport function applySessionBacklog(sessionId: string, replayed: number, dropped: number): void {\n  sessionsStore.setState((state) => {\n    const meta = state.byId[sessionId];\n    if (!meta) return state;\n    return { ...state, byId: { ...state.byId, [sessionId]: { ...meta, replayed, dropped } } };\n  });\n}\n\n/**\n * The page socket died; every session is unreachable until it comes back.\n * Self-healing: the snapshot on reconnect restores the real states.\n */\nexport function markSocketClosed(hostId?: string): void {\n  sessionsStore.setState((state) => {\n    const byId: Record<string, SessionMeta> = {};\n    for (const [id, meta] of Object.entries(state.byId)) {\n      if (!belongsToHost(id, hostId)) {\n        byId[id] = meta;\n        continue;\n      }\n      byId[id] = {\n        ...meta,\n        attach: 'offline',\n        reason: needsUpdate(state, id) ? UPDATE_REQUIRED_REASON : 'The cockpit lost its bridge.',\n      };\n    }\n    return { ...state, byId };\n  });\n}\n\n/**\n * The server needs newer client code; every session is unreachable until the\n * page reloads with it. Unlike a closed socket nothing here heals on its own,\n * so later session lists keep the same state and reason.\n */\nexport function markUpdateRequired(hostId?: string): void {\n  sessionsStore.setState((state) => {\n    const byId: Record<string, SessionMeta> = {};\n    for (const [id, meta] of Object.entries(state.byId)) {\n      byId[id] = belongsToHost(id, hostId) ? { ...meta, attach: 'offline', reason: UPDATE_REQUIRED_REASON } : meta;\n    }\n    return hostId === undefined\n      ? { ...state, byId, updateRequired: true }\n      : { ...state, byId, updateRequiredHosts: { ...state.updateRequiredHosts, [hostId]: true } };\n  });\n}\n\nconst APPEAR_TIMEOUT_MS = 15_000;\n\n/**\n * Resolves once the session shows up in the rail, or false on timeout.\n *\n * A freshly created session exists on disk before its upsert reaches this\n * page; navigating to it too early trips the unknown-session fallback and\n * bounces the user back. Waiting here is what makes \"create, then land on it\"\n * one motion.\n */\nexport function waitForSession(sessionId: string, timeoutMs = APPEAR_TIMEOUT_MS): Promise<boolean> {\n  if (sessionId in sessionsStore.state.byId) return Promise.resolve(true);\n  return new Promise((resolve) => {\n    const finish = (found: boolean): void => {\n      clearTimeout(timer);\n      subscription.unsubscribe();\n      resolve(found);\n    };\n    const subscription = sessionsStore.subscribe(() => {\n      if (sessionId in sessionsStore.state.byId) finish(true);\n    });\n    const timer = setTimeout(() => finish(false), timeoutMs);\n  });\n}\n\n/**\n * Reads the focused session's rail entry, or null while nothing is focused. Like the rail, it\n * renders again only when more than `updatedAt` moved, which the hub bumps on unrelated pushes.\n */\nexport function useActiveSessionMeta(): SessionMeta | null {\n  return useStore(\n    sessionsStore,\n    (state) => (state.activeId !== null ? (state.byId[state.activeId] ?? null) : null),\n    (left, right) => sameRailEntry(left ?? undefined, right ?? undefined),\n  );\n}\n\n/**\n * Every rail entry, rendering again only when more than `updatedAt` moved. A\n * reader that needs that field fresh, such as a recency sort, reads\n * `sessionsStore.state` while it renders.\n */\nexport function useRailEntries(): Record<string, SessionMeta> {\n  return useStore(sessionsStore, (state) => state.byId, sameRailEntries);\n}\n\n/** One session's rail entry, rendering again only when more than `updatedAt` moved. */\nexport function useRailEntry(sessionId: string | null): SessionMeta | undefined {\n  return useStore(sessionsStore, (state) => (sessionId === null ? undefined : state.byId[sessionId]), sameRailEntry);\n}\n\n/**\n * True once the hub has answered and reported no sessions at all.\n *\n * Several surfaces stand down on this, so the rule is named once rather than\n * spelled out at each of them. The hydration half is what keeps it honest: an\n * empty order before the first snapshot only means the hub has not answered\n * yet, and treating that as \"no sessions\" would flash an onboarding screen at\n * someone who has ten.\n */\nexport function noSessions(state: SessionsState): boolean {\n  return state.hydrated && state.order.length === 0;\n}\n\nexport function useNoSessions(): boolean {\n  return useStore(sessionsStore, noSessions);\n}\n\n/**\n * Every session but `excludeId` on the same computer, in rail order and by that computer's own ids, as an `@session:`\n * mention offers it. The server reads a mention among its own sessions only, so another computer's are left out.\n */\nexport function mentionableSessions(\n  state: SessionsState,\n  workspaces: Readonly<Record<string, WorkspaceSummary>>,\n  excludeId: string | null,\n  now: number,\n): MentionableSession[] {\n  // An unqualified id is a session of the computer this page is attached to.\n  const owned = (key: string) => splitHostId(key) ?? { hostId: defaultHostId(), localId: key };\n  const host = excludeId === null ? defaultHostId() : owned(excludeId).hostId;\n  return state.order.flatMap((id) => {\n    const meta = state.byId[id];\n    const owner = owned(id);\n    if (id === excludeId || meta === undefined || owner.hostId !== host) return [];\n    const { workspaceId } = meta.summary;\n    const workspace = workspaceId === undefined ? undefined : workspaces[workspaceId];\n    return [\n      {\n        id: owner.localId,\n        name: meta.summary.name,\n        detail: railSessionStatus(meta, now).status,\n        // Home and workspace-free sessions show no workspace, as on the rail.\n        ...(workspace === undefined || workspace.kind === 'session' ? {} : { workspace: workspaceName(workspace) }),\n        ...(workspaceId === undefined ? {} : { workspaceId }),\n      },\n    ];\n  });\n}\n\nexport function setActiveSession(sessionId: string | null, tabOwnerId: string | null = sessionId): void {\n  sessionsStore.setState((state) =>\n    state.activeId === sessionId && (state.tabOwnerId ?? state.activeId) === tabOwnerId\n      ? state\n      : { ...state, activeId: sessionId, tabOwnerId },\n  );\n}\n\nexport function beginSessionTransfer(sessionId: string): void {\n  sessionsStore.setState((state) =>\n    state.transferringToId === sessionId ? state : { ...state, transferringToId: sessionId },\n  );\n}\n\nexport function completeSessionTransfer(sessionId: string): void {\n  sessionsStore.setState((state) =>\n    state.transferringToId === sessionId ? { ...state, transferringToId: null } : state,\n  );\n}\n\nexport function activeSessionId(): string | null {\n  return sessionsStore.state.activeId;\n}\n\n/**\n * Runs `run` once the session is attached and its protocol is bound, which only happens after its\n * page takes focus. Runs once, never retries, so an unacknowledged send cannot repeat; a session that\n * never gets ready in time skips it.\n */\nexport function whenSessionReady(sessionId: string, run: () => Promise<unknown> | void): Promise<void> {\n  return new Promise((resolve) => {\n    const started = Date.now();\n    const timer = setInterval(() => {\n      const ready = sessionsStore.state.byId[sessionId]?.attach === 'attached' && hasSessionProtocol(sessionId);\n      if (!ready && Date.now() - started < READY_TIMEOUT_MS) return;\n      clearInterval(timer);\n      if (ready) void Promise.resolve(run()).finally(resolve);\n      else resolve();\n    }, READY_CHECK_MS);\n  });\n}\n\nexport function resetSessions(): void {\n  sessionsStore.setState(() => initialState);\n}\n"],"mappings":";;;;;;;;;;AAmBA,MAAM,iBAAiB;AACvB,MAAM,mBAAmB;;AAqCzB,MAAa,yBAAyB;AAEtC,MAAM,eAA8B;CAClC,OAAO,CAAC;CACR,MAAM,CAAC;CACP,UAAU;CACV,kBAAkB;CAClB,UAAU;CACV,gBAAgB;AAClB;AAEA,MAAa,gBAAgB,WAAW,YAAY,IAAI,MAAqB,YAAY,CAAC;AAC1F,yBAAyB,cAAc,cAAc,MAAM,KAAK,UAAU,EAAE,QAAQ,WAAW;AAE/F,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,UAAU,OAA4C;CAC7D,IAAI,CAAC,SAAS,KAAK,KAAK,OAAO,MAAM,OAAO,YAAY,MAAM,OAAO,IAAI,OAAO,KAAA;CAChF,OAAO;AACT;;;;;;;;;AAUA,SAAgB,gBAAgB,MAAmC,IAAY,OAAoC;CACjH,MAAM,SAAS,KAAK,GAAG,EAAE,QAAQ;CACjC,IACE,WAAW,KAAA,KACX,WAAW,MACX,KAAK,YAAY,KAAA,KACjB,KAAK,OAAO,CAAC,QAAQ,gBAAgB,KAAK,GAAG,CAAC,QAAQ,aAEtD,OAAO,KAAA;CACT,IAAI,OAAO;CACX,MAAM,WAAW,SAAS,OAAO,KAAK,IAAI,CAAC,CAAC;CAC5C,KAAK,IAAI,KAAy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