/** API 请求/响应类型定义 */ // Hono context variable types declare module 'hono' { interface ContextVariableMap { userId?: string isAdmin?: boolean /** Bearer credential matched RCS_API_KEYS (admin API key, not a user token). */ isApiAdmin?: boolean jwtPayload?: { session_id: string; role: string; iat: number; exp: number } } } // --- Environment --- export interface RegisterEnvironmentRequest { machine_name?: string /** Startup/default session directory. */ directory?: string /** * Quick-pick directories for the Web UI. Advisory only — a session may be * created in any directory the worker's OS user can access. */ workspace_dirs?: string[] branch?: string git_repo_url?: string max_sessions?: number worker_type?: string bridge_id?: string capabilities?: Record } export interface RegisterEnvironmentResponse { id: string secret: string status: string } export interface WorkResponse { id: string type: 'work' environment_id: string state: string data: | { type: 'session' | 'healthcheck' id: string } | { /** * Environment-scoped RPC delivered through the poll channel. * `id` is the requestId the worker echoes on its HTTP response. */ type: 'env_rpc' id: string method: string params: Record } secret: string // Per-session spawn mode chosen in Web UI. Worker reads this to decide // whether to create a git worktree for the session. Undefined → worker // uses its startup default. spawn_mode?: 'same-dir' | 'worktree' /** Absolute session working directory. Undefined → worker startup dir. */ cwd?: string /** Session-level permission mode for the spawned child. */ permission_mode?: string | null created_at: string } export interface WorkSecretPayload { version: number session_ingress_token: string api_base_url: string sources: string[] auth: string[] use_code_sessions: boolean } // --- Session --- export interface CreateSessionRequest { environment_id?: string | null title?: string events?: unknown[] source?: string permission_mode?: string /** Absolute working directory for the session. */ cwd?: string spawn_mode?: 'same-dir' | 'worktree' } export interface SessionResponse { id: string environment_id: string | null title: string | null status: string source: string permission_mode: string | null cwd: string | null spawn_mode: 'same-dir' | 'worktree' | null worker_epoch: number username: string | null visibility: string created_at: number updated_at: number owner_type: 'user' | 'team' | null owner_id: string | null access_level?: 'owner' | 'write' | 'read' | null automation_state?: AutomationStateResponse worker?: SessionWorkerInfo | null work_item?: SessionWorkItemInfo | null environment?: SessionEnvironmentInfo | null /** 最近一次阻塞请求的详情(CLI 上报)。用于 Dashboard 区分在等什么。 */ requires_action_details?: { tool_name?: string action_description?: string request_id?: string } | null /** 服务端当前已知的阻塞请求数(目前一次只跟踪一条)。 */ pending_permission_count?: number } export interface SessionWorkerInfo { status: string | null last_heartbeat_at: number | null } export interface SessionWorkItemInfo { id: string state: string spawn_mode: 'same-dir' | 'worktree' | null cwd: string | null } export interface SessionEnvironmentInfo { id: string machine_name: string | null worker_type: string } export interface AutomationStateResponse { enabled: boolean phase: 'standby' | 'sleeping' | null next_tick_at: number | null sleep_until: number | null } // --- v2 Code Sessions --- export interface CreateCodeSessionRequest { title?: string source?: string permission_mode?: string } export interface BridgeResponse { api_base_url: string worker_epoch: number worker_jwt: string expires_in: number } // --- Web --- export interface EnvironmentResponse { id: string machine_name: string | null directory: string | null branch: string | null status: string username: string | null /** Peer address the worker registered from. Null when unresolvable. */ ip_address: string | null last_poll_at: number | null /** Unix seconds when the machine first registered (stable across restarts * within a server lifetime). Null only for legacy rows. */ created_at: number | null worker_type?: string /** Quick-pick directories (advisory; sessions may use any directory). */ workspace_dirs: string[] max_sessions: number active_sessions: number channel_group_id?: string | null capabilities?: Record | null team_id: string | null team_name: string | null owner_user_id: string | null /** Resolved username of the owning user (null if unowned/unresolvable). */ owner_username?: string | null /** Session Attach wait mode: registered to be assigned a session, none bound yet. */ attach_waiting?: boolean } export interface ServerInfoResponse { version: string uptime_seconds: number workers_active: number workers_total: number sessions_owned: number sessions_active: number } export interface SessionSummaryResponse { id: string title: string | null status: string source: string username: string | null visibility: string environment_id: string | null /** Absolute session working directory (null on legacy rows). */ cwd: string | null spawn_mode: 'same-dir' | 'worktree' | null owner_type: 'user' | 'team' | null owner_id: string | null access_level?: 'owner' | 'write' | 'read' | null environment: { id: string machine_name: string | null worker_type: string } | null updated_at: number requires_action_details?: { tool_name?: string action_description?: string request_id?: string } | null pending_permission_count?: number } // --- Web Auth --- export interface WebLoginRequest { apiKey: string username: string } export interface WebLoginResponse { token: string expires_in: number } export interface WebControlRequest { type: string content?: string [key: string]: unknown } // --- Error --- export interface ErrorResponse { error: { type: string message: string } } // --- Event --- export interface SessionEventPayload { id: string session_id: string type: string payload: unknown direction: 'inbound' | 'outbound' seq_num: number created_at: number }