import type { Node as KernelNode } from '@astrale-os/sdk/graph/node' /** Common result state for Shell React reads. */ export interface ReadState { /** A request is in flight. Last-good data may still be present. */ readonly pending: boolean /** Last request failure. Cleared when the next request begins. */ readonly error: unknown /** True only when an upstream subscription is active. */ readonly live: boolean /** Reserved journal position. Direct Graph reads report zero. */ readonly seq: number refetch(): Promise } export interface Windowed { readonly more: { readonly has: boolean readonly pending: boolean load(): Promise } } /** Options shared by point, Query, and neighbor reads. */ export interface ReadOptions { readonly signal?: AbortSignal readonly timeoutMs?: number /** Retain the previous successful value while the next request is pending. */ readonly keepPrevious?: boolean } export type Node = KernelNode export const EMPTY_NODES: readonly Node[] = Object.freeze([]) export const NO_MORE: Windowed['more'] = Object.freeze({ has: false, pending: false, load: () => Promise.resolve(), }) /** Stable failure for a retained hook whose required Kernel capability does not exist. */ export class UnsupportedFeatureError extends Error { readonly code = 'SHELL_REACT_UNSUPPORTED' as const readonly feature: string constructor(feature: string) { super(`${feature} is not supported by the current Kernel Graph contract.`) this.name = 'UnsupportedFeatureError' this.feature = feature } } export function idleReadState(): ReadState { return { pending: false, error: undefined, live: false, seq: 0, refetch: () => Promise.resolve(), } } export function unsupportedReadState(feature: string): ReadState { const error = new UnsupportedFeatureError(feature) return { pending: false, error, live: false, seq: 0, refetch: () => Promise.reject(error), } }