Files
codecraft/web/src/types.ts
T
Richard ZinkandClaude Sonnet 5.5 ce0d8afe69 Chat bubbles, icons for chats, more vivid and distinct colour tags
- Bubbles: own messages right-aligned in their own colour, agent answers left.
- Chat icons (22, validated on the server), shown in list, top bar, project page.
- Colour tags: eight fixed hues (new: pink) with theme-matched lightness and the
  highest chroma sRGB allows; stronger background tint.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 23:31:52 +01:00

242 lines
7.0 KiB
TypeScript

// Mirrors server/src/types.rs
export interface ImageData {
media_type: string;
/** Base64 bytes; absent when the server stores the image separately (blob). */
data?: string;
/** SHA-256 of a stored image: GET /api/blobs/<blob>. */
blob?: string;
/** Size in bytes of a stored image. */
size?: number;
}
export type Part =
| { type: "text"; text: string }
| { type: "image"; image: ImageData }
| { type: "reasoning"; text: string; signature?: string }
| { type: "tool_call"; id: string; name: string; input: any }
| {
type: "tool_result";
call_id: string;
name: string;
content: string;
images?: ImageData[];
is_error: boolean;
meta?: any;
}
| { type: "summary"; text: string; auto?: boolean; tokens?: number };
export interface Usage {
input_tokens: number;
output_tokens: number;
cache_read_tokens: number;
cache_write_tokens: number;
/** Cost of the request (charged, or valued at list prices for plan requests). */
cost?: number;
}
export interface Message {
id: string;
role: "user" | "assistant";
parts: Part[];
model?: string;
usage?: Usage;
created_at: number;
}
export interface Todo {
content: string;
status: "pending" | "in_progress" | "completed";
}
export interface Session {
id: string;
title: string;
cwd: string;
model: string;
agent: string;
permission_mode: "default" | "auto" | "accept_edits" | "bypass";
parent_id?: string;
created_at: number;
updated_at: number;
/** One line "where things stand" (small model), for the session list. */
summary?: string;
/** Colour tag: a palette name (red … purple), drawn in the colours of the theme. */
color?: string;
/** Icon name of the chat (from the picker). */
icon?: string;
todos: Todo[] | null;
last_usage?: Usage | null;
busy?: boolean;
owner_id?: string | null;
/** Craft: clean room (true) or deep (false); undefined = server default. */
clean_room?: boolean | null;
/** Craft workflow phase reported by the agent. */
phase?: string;
/** Isolated git worktree of the session. */
worktree?: { repo: string; path: string; branch: string; base: string; sub?: string } | null;
/** Listed because it was shared with the current user. */
shared?: boolean;
pinned?: boolean;
archived?: boolean;
folder?: string | null;
/** Instructions for this chat (added to the system prompt). */
instructions?: string;
/** Approvals and questions of this chat are not sent to Telegram. */
telegram_quiet?: boolean;
}
export interface QuestionOption {
label: string;
description?: string;
}
export interface Question {
question: string;
header?: string;
options: QuestionOption[];
multi_select?: boolean;
}
export interface PermissionRequest {
type: "permission_request";
id: string;
session_id: string;
root_session_id?: string;
tool: string;
title: string;
input: any;
diff?: string;
}
export interface QuestionRequest {
type: "question_request";
id: string;
session_id: string;
root_session_id?: string;
source: string;
questions: Question[];
}
/** Result of the project's check command after a turn. */
export type CheckStatus = "running" | "passed" | "failed" | "timeout";
export interface TurnCheckInfo {
message_id: string;
status: CheckStatus;
exit_code: number | null;
duration_ms: number;
output: string;
}
export type ServerEvent =
| { type: "session_updated"; session: Session }
| { type: "session_deleted"; session_id: string }
| { type: "session_status"; session_id: string; busy: boolean }
| { type: "message_added"; session_id: string; message: Message }
| { type: "text_delta"; session_id: string; message_id: string; text: string }
| { type: "reasoning_delta"; session_id: string; message_id: string; text: string }
| { type: "tool_started"; session_id: string; message_id: string; call_id: string; name: string; input: any }
| { type: "tool_progress"; session_id: string; call_id: string; output: string }
| PermissionRequest
| { type: "permission_resolved"; id: string; session_id: string }
| QuestionRequest
| { type: "question_resolved"; id: string; session_id: string }
| { type: "error"; session_id: string; message: string }
| { type: "waiting"; session_id: string; reason: string | null }
| { type: "queue_updated"; session_id: string; items: QueueItem[] }
| { type: "step_started"; session_id: string; message_id: string; started_at: number; prompt_tokens: number; estimated: boolean }
| { type: "check_result"; session_id: string; message_id: string; status: CheckStatus; exit_code: number | null; duration_ms: number; output: string }
| { type: "compaction"; session_id: string; state: "started" | "done" | "failed"; auto: boolean; tokens: number | null; limit: number | null }
| { type: "mcp_status"; servers: Record<string, McpServerStatus> }
| { type: "resync" };
export interface McpServerStatus {
status: { state: "disabled" | "connecting" | "connected" | "failed"; tools?: number; error?: string };
tools: { name: string; description: string }[];
}
export interface ModelInfo {
id: string;
name: string;
context?: number;
max_output?: number | null;
max_input?: number | null;
reasoning: boolean;
vision: boolean;
effort?: string | null;
input_price?: number | null;
output_price?: number | null;
cache_read_price?: number | null;
cache_write_price?: number | null;
}
export interface ProviderModels {
provider: string;
models: ModelInfo[];
}
export interface AgentInfo {
name: string;
description: string;
mode: "primary" | "subagent";
read_only: boolean;
/** "coding" or "chat" (plain conversation prompt). */
style?: "coding" | "chat";
model?: string | null;
tools?: string[] | null;
source: "builtin" | "config" | "file" | "personal";
max_parallel?: number | null;
refine?: { rounds: number; model?: string | null; criteria?: string | null; after_todos?: boolean } | null;
/** binary_info and decompile (Ghidra) available in this mode. */
reverse?: boolean;
/** Source file of Markdown agents. */
path?: string | null;
}
export interface Aggregate {
requests: number;
input_tokens: number;
output_tokens: number;
cache_read_tokens: number;
cache_write_tokens: number;
cost: number;
errors: number;
avg_ttft_ms: number;
output_tps: number;
prefill_tps: number;
cache_hit_rate: number;
duration_ms: number;
}
export interface User {
id: string;
username: string;
display_name: string;
role: "admin" | "user";
has_password: boolean;
oidc: boolean;
disabled: boolean;
created_at: number;
monthly_quota?: number | null;
}
export interface Info {
name: string;
version: string;
commit?: string;
/** Newer release (admins only). */
update?: { version: string; url: string; notes: string } | null;
setup_required: boolean;
/** Prebuilt terminal client binaries can be downloaded from this server. */
cli_builds?: boolean;
oidc: { label: string } | null;
user: User | null;
}
export interface QueueItem {
id: string;
parts: Part[];
source: "user" | "background";
created_at: number;
}