/** API 请求/响应类型定义 */ // Hono context variable types declare module 'hono' { interface ContextVariableMap { userId?: string isAdmin?: boolean jwtPayload?: { session_id: string; role: string; iat: number; exp: number } } } // --- Environment --- export interface RegisterEnvironmentRequest { machine_name?: string directory?: 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 } 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' 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 } export interface SessionResponse { id: string environment_id: string | null title: string | null status: string source: string permission_mode: string | 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 } export interface SessionWorkerInfo { status: string | null last_heartbeat_at: number | null } export interface SessionWorkItemInfo { id: string state: string spawn_mode: 'same-dir' | 'worktree' | 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 last_poll_at: number | null worker_type?: string channel_group_id?: string | null capabilities?: Record | null team_id: string | null team_name: string | null owner_user_id: string | null } 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 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 } // --- 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 }