Skip to main content

ai_cortex_sdk/
models.rs

1use serde::{Deserialize, Serialize};
2
3// --- Device models ---
4
5/// 设备记录(user 维度:PAT 流程下设备绑定到用户)。
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct DeviceRecord {
8    pub id: String,
9    /// 旧 SDK/HMAC 流程的占位字段(PAT 流程下为空串)
10    pub client_id: String,
11    pub auth_app_id: String,
12    /// PAT 所属用户
13    pub user_id: String,
14    pub fingerprint: String,
15    pub device_info: String,
16    pub last_active_time: i64,
17    pub status: i32,
18    pub created_time: i64,
19    pub updated_time: i64,
20}
21
22// --- Software models ---
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct SoftwareInfo {
26    pub id: String,
27    pub name: String,
28    pub description: String,
29    pub software_type: i32,
30    pub icon: String,
31    pub status: i32,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct SoftwareVersion {
36    pub id: String,
37    pub software_id: String,
38    pub version: String,
39    pub release_notes: String,
40    pub download_url: String,
41    pub file_size: i64,
42    pub platform: String,
43    pub status: i32,
44    /// 是否强制更新(旧服务端无此列时默认 false,向后兼容)
45    #[serde(default)]
46    pub force_update: bool,
47    /// 最低兼容版本(旧服务端无此列时默认空串,向后兼容)
48    #[serde(default)]
49    pub min_compatible: String,
50    /// 发布通道(stable/beta/...,旧服务端无此列时默认空串,向后兼容)
51    #[serde(default)]
52    pub channel: String,
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize)]
56pub struct SoftwareStoreItem {
57    pub software: SoftwareInfo,
58    pub latest_version: Option<SoftwareVersion>,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct DownloadInfo {
63    pub download_url: String,
64    pub file_size: i64,
65    pub version: String,
66}
67
68// --- Auto update models ---
69
70/// 版本摘要(`sdk-check-update` 响应中的目标版本信息)
71#[derive(Debug, Clone, Deserialize)]
72pub struct VersionBrief {
73    pub id: String,
74    pub version: String,
75    pub release_notes: String,
76    pub download_url: String,
77    pub file_size: i64,
78    pub platform: String,
79    pub channel: String,
80    pub force_update: bool,
81    pub min_compatible: String,
82}
83
84/// `sdk-check-update` 响应:是否有更新、是否强制、当前版本、目标版本摘要。
85#[derive(Debug, Clone, Deserialize)]
86pub struct UpdateInfo {
87    pub has_update: bool,
88    pub force_update: bool,
89    pub current_version: String,
90    pub target_version: Option<VersionBrief>,
91}
92
93/// SSE 事件载荷(`data:` JSON)。`id` 为服务端单调递增序号,用于 Last-Event-ID 重连。
94#[derive(Debug, Clone, Deserialize)]
95pub struct UpdateEvent {
96    #[serde(default)]
97    pub id: u64,
98    pub software_id: String,
99    pub version: String,
100    pub platform: String,
101    pub channel: String,
102    pub force_update: bool,
103}
104
105// --- Generic API response wrapper ---
106// The server wraps responses in ApiResult format: { "success": bool, "data": ..., "message": "...", "code": ... }
107
108#[derive(Debug, Clone, Deserialize)]
109pub struct ApiResponse<T> {
110    pub success: bool,
111    #[serde(default)]
112    pub message: Option<String>,
113    #[serde(default)]
114    pub code: Option<i32>,
115    pub data: Option<T>,
116}
117
118// --- Offline license models ---
119
120/// 服务端下发的离线许可证文件(POST /api/offline-licenses/issue 响应 data)。
121#[derive(Debug, Clone, Deserialize)]
122pub struct OfflineLicenseFile {
123    /// 被签名的原文(LicensePayload 的 JSON 字符串,snake_case)
124    pub payload: String,
125    /// Ed25519 签名(hex 64 字节)
126    pub signature: String,
127    /// Ed25519 公钥(hex 32 字节)
128    pub public_key: String,
129}
130
131/// 解析后的离线许可证 payload。
132#[derive(Debug, Clone, Deserialize)]
133#[serde(rename_all = "snake_case")]
134pub struct OfflineLicensePayload {
135    pub license_id: String,
136    pub user_id: String,
137    pub software_id: String,
138    pub fingerprint: String,
139    pub max_devices: i32,
140    pub expire_time: i64,
141    pub issued_at: i64,
142}