Skip to main content

claude_codes/
types.rs

1//! Core types used in the Claude Code protocol
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7/// Represents a unique identifier for various entities
8pub type Id = String;
9
10/// Represents a session identifier
11pub type SessionId = String;
12
13/// Represents a task identifier
14pub type TaskId = String;
15
16/// Represents a conversation identifier
17pub type ConversationId = String;
18
19/// Status of a task or operation
20#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
21#[serde(rename_all = "snake_case")]
22pub enum Status {
23    Pending,
24    InProgress,
25    Completed,
26    Failed,
27    Cancelled,
28}
29
30/// Priority levels for tasks
31#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
32#[serde(rename_all = "snake_case")]
33pub enum Priority {
34    Low,
35    Normal,
36    High,
37    Critical,
38}
39
40/// Tool types available in Claude Code
41#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
42#[serde(rename_all = "snake_case")]
43pub enum ToolType {
44    Bash,
45    Read,
46    Write,
47    Edit,
48    Search,
49    #[serde(rename = "web_search")]
50    WebSearch,
51    Other(String),
52}
53
54/// Represents metadata for a message or operation
55#[derive(Debug, Clone, Serialize, Deserialize, Default)]
56pub struct Metadata {
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub timestamp: Option<DateTime<Utc>>,
59
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub version: Option<String>,
62
63    #[serde(flatten)]
64    pub extra: HashMap<String, serde_json::Value>,
65}
66
67/// Represents an error detail in responses
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct ErrorDetail {
70    pub code: String,
71    pub message: String,
72
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub details: Option<serde_json::Value>,
75}
76
77/// Represents a capability or feature
78#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
79pub struct Capability {
80    pub name: String,
81    pub enabled: bool,
82
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub version: Option<String>,
85}