// Pure classifier for errors thrown from the fullStream loop. Establishes the
// retry seam for when llama-swap gains restart-in-place-with-clear-partial
// semantics. No retry is performed today (partial-stream re-emit is
// non-idempotent at single-local-instance scale).
export type StreamErrorKind = 'stall' | 'transient' | 'non-retryable';

export function classifyStreamError(err: unknown): StreamErrorKind {
  if (err instanceof Error && err.name === 'AbortError') {
    return 'stall';
  }
  if (err != null && typeof err === 'object') {
    const status = (err as Record<string, unknown>).status;
    if (typeof status === 'number' && status >= 500 && status < 600) {
      return 'transient';
    }
  }
  return 'non-retryable';
}
