πŸ“„ File detail

server/types.ts

🧩 .tsπŸ“ 58 linesπŸ’Ύ 1,466 bytesπŸ“ text
← Back to All Files

🎯 Use case

This file lives under β€œserver/”, which covers local or auxiliary HTTP/WebSocket servers used by the product. On the API surface it exposes connectResponseSchema, ServerConfig, SessionState, SessionInfo, and SessionIndexEntry (and more) β€” mainly types, interfaces, or factory objects. Dependencies touch subprocess spawning and schema validation. It composes internal code from utils (relative imports).

Generated from folder role, exports, dependency roots, and inline comments β€” not hand-reviewed for every path.

🧠 Inline summary

import type { ChildProcess } from 'child_process' import { z } from 'zod/v4' import { lazySchema } from '../utils/lazySchema.js' export const connectResponseSchema = lazySchema(() =>

πŸ“€ Exports (heuristic)

  • connectResponseSchema
  • ServerConfig
  • SessionState
  • SessionInfo
  • SessionIndexEntry
  • SessionIndex

πŸ“š External import roots

Package roots from from "…" (relative paths omitted).

  • child_process
  • zod

πŸ–₯️ Source preview

import type { ChildProcess } from 'child_process'
import { z } from 'zod/v4'
import { lazySchema } from '../utils/lazySchema.js'

export const connectResponseSchema = lazySchema(() =>
  z.object({
    session_id: z.string(),
    ws_url: z.string(),
    work_dir: z.string().optional(),
  }),
)

export type ServerConfig = {
  port: number
  host: string
  authToken: string
  unix?: string
  /** Idle timeout for detached sessions (ms). 0 = never expire. */
  idleTimeoutMs?: number
  /** Maximum number of concurrent sessions. */
  maxSessions?: number
  /** Default workspace directory for sessions that don't specify cwd. */
  workspace?: string
}

export type SessionState =
  | 'starting'
  | 'running'
  | 'detached'
  | 'stopping'
  | 'stopped'

export type SessionInfo = {
  id: string
  status: SessionState
  createdAt: number
  workDir: string
  process: ChildProcess | null
  sessionKey?: string
}

/**
 * Stable session key β†’ session metadata. Persisted to ~/.claude/server-sessions.json
 * so sessions can be resumed across server restarts.
 */
export type SessionIndexEntry = {
  /** Server-assigned session ID (matches the subprocess's claude session). */
  sessionId: string
  /** The claude transcript session ID for --resume. Same as sessionId for direct sessions. */
  transcriptSessionId: string
  cwd: string
  permissionMode?: string
  createdAt: number
  lastActiveAt: number
}

export type SessionIndex = Record<string, SessionIndexEntry>