1import type { Access, Connections, Consent, Resources } from "./types/mcp.ts";
2import type { Pool, Vdev, Disk, Dataset, Snapshot } from "./types/storage.ts";
3import type { Torrent, TorrentFile, ServerState } from "./types/seedbox.ts";
4import type { Video, Show, Job, Wall, Archive, Upscaler, Channels, ConfigFile, LibraryEntry, Ingest } from "./types/youtube.ts";
5import type { User, Group, Session, Credential } from "./types/users.ts";
6import type { Hono } from "hono";
7import type { Health } from "./types/model.ts";
8import type { Domain, History, NewDomain, VMLibrary } from "./types/vms.ts";
9import type { Me, ServiceSummary, ServiceDetail, ServiceDefinition, HostInfo, Issue, Series, LogLine, TraceSummary, Trace } from "./types/model.ts";
10import type { MapNode } from "./types/storage.index.ts";
11import type { ProgressNode, PaperCloverStats } from "./types/paperClover.ts";
12
13type Endpoint<Output, Input = {}, Status extends number = 200, Format extends string = "json"> = {
14 input: Input; output: Output; status: Status; outputFormat: Format;
15};
16
17type FileEntry = { name: string; dir: boolean; size: number | null; alloc: number | null; items: number | null; modified: number; inode: number; dataset: string | null; download: string | null; };
18
19type Explorer = {
20 "/list": {
21 $get: Endpoint<{ host: string; link: string | null; zip: string | null; entries: FileEntry[]; }, { query: { path?: string | undefined; }; }>;
22 };
23 "/tree": {
24 $post: Endpoint<{ folders: { [x: string]: FileEntry[]; }; sizes: { [x: string]: { size: number; alloc: number; files: number; }; }; complete: boolean; updated: number | null; }, { json: { path: string; expanded: string[] | "all"; }; }>;
25 };
26 "/match": {
27 $get: Endpoint<{ count: number; size: number | null; sample: string[]; rows: { [x: string]: number | "self"; }; }, { query: { path: string; pattern: string; }; }>;
28 };
29 "/peek": {
30 $get: Endpoint<{ text: string; more: boolean; }, { query: { path: string; }; }>;
31 };
32 "/ops": {
33 $get: Endpoint<{ id: string; label: string; at: number; undone: boolean; sample: string[]; count: number; }[]>;
34 };
35 "/folder": {
36 $post: Endpoint<{ id: `${string}-${string}-${string}-${string}-${string}`; label: string; }, { json: { path: string; name: string; }; }>;
37 };
38 "/rename": {
39 $post: Endpoint<{ id: `${string}-${string}-${string}-${string}-${string}`; label: string; }, { json: { renames: { path: string; name: string; }[]; }; }>;
40 };
41 "/move": {
42 $post: Endpoint<{ id: `${string}-${string}-${string}-${string}-${string}`; label: string; }, { json: { paths: string[]; to: string; }; }>;
43 };
44 "/delete": {
45 $post: Endpoint<{ id: `${string}-${string}-${string}-${string}-${string}`; label: string; }, { json: { paths: string[]; }; }>;
46 };
47 "/bulk": {
48 $post: Endpoint<{ id: `${string}-${string}-${string}-${string}-${string}`; label: string; }, { json: { path: string; pattern: string; count: number; action: "move" | "delete"; to?: string | undefined; }; }>;
49 };
50 "/ops/:id/undo": {
51 $post: Endpoint<null, { param: { id: string; }; }, 204, "body">;
52 };
53};
54type ExplorerRoutes<Prefix extends string> = { [P in keyof Explorer as `${Prefix}${P}`]: Explorer[P] };
55
56export type Api = Hono<{}, {
57 "/ai": { $get: Endpoint<{ endpoint: string; model: string; context: number }>; };
58 "/ai/key": { $post: Endpoint<{ key: string }>; };
59 "/mcp": { $get: Endpoint<Connections>; };
60 "/mcp/shale": { $get: Endpoint<{ linked: boolean; resources: Resources }>; $post: Endpoint<{ redirect: string }, { json: { request?: string } }>; $delete: Endpoint<null, {}, 204>; };
61 "/mcp/consent/:id": {
62 $get: Endpoint<Consent, { param: { id: string } }>;
63 $post: Endpoint<{ redirect: string }, { param: { id: string }; json: { resources: Access } | { deny: true } }>;
64 };
65 "/mcp/relay/pair": { $post: Endpoint<Connections["machines"][number], { json: { code: string } }>; };
66 "/mcp/relay/machines/:id": {
67 $patch: Endpoint<Connections["machines"][number], { param: { id: string }; json: { name: string } }>;
68 $delete: Endpoint<null, { param: { id: string } }, 204>;
69 };
70 "/mcp/relay/keys": { $post: Endpoint<{ key: string; id: string }, { json: { name: string; resources: string[]; write: boolean } }>; };
71 "/mcp/connections/:id": {
72 $get: Endpoint<{ resources: Resources; selected: Access; linked: boolean; resourceError: string | null }, { param: { id: string } }>;
73 $post: Endpoint<null, { param: { id: string }; json: { resources: Access } }, 204>;
74 $delete: Endpoint<null, { param: { id: string } }, 204>;
75 };
76
77 "/me": {
78 $get: Endpoint<Me>;
79 };
80 "/launcher": {
81 $get: Endpoint<{ id: string; name: string; tagline: string | null; url: string; urls: Record<string, string>; icon: { light: string; dark: string; } | null; health: Health | null; }[]>;
82 };
83 "/status": {
84 $get: Endpoint<{ load: number; issues: Issue[] | null }>;
85 };
86 "/host": {
87 $get: Endpoint<HostInfo>;
88 };
89 "/services": {
90 $get: Endpoint<ServiceSummary[]>;
91 };
92 "/services/:id": {
93 $get: Endpoint<ServiceDetail, { param: { id: string; }; }>;
94 };
95 "/services/:id/definition": {
96 $get: Endpoint<ServiceDefinition, { param: { id: string; }; }>;
97 };
98 "/services/:id/:action": {
99 $post: Endpoint<null, { param: { id: string; action: "stop" | "restart" | "start"; }; }, 204, "body">;
100 };
101 "/services/:id/restarts/acknowledge": {
102 $post: Endpoint<null, { param: { id: string; }; }, 204, "body">;
103 };
104 "/services/:id/secrets/:name": {
105 $get: Endpoint<{ value: string; }, { param: { name: string; } & { id: string; }; }>;
106 $put: Endpoint<null, { json: { value: string; }; } & { param: { name: string; } & { id: string; }; }, 204, "body">;
107 };
108 "/services/:id/secrets/:name/rotate": {
109 $post: Endpoint<null, { param: { name: string; } & { id: string; }; }, 204, "body">;
110 };
111 "/services/:id/logs": {
112 $get: Endpoint<LogLine[], { query: { q?: string | undefined; level?: "error" | "warn" | undefined; before?: string | string[] | undefined; after?: string | string[] | undefined; limit?: string | string[] | undefined; }; } & { param: { id: string; }; }>;
113 };
114 "/services/:id/metrics/:name": {
115 $get: Endpoint<Series[], { param: { id: string; name: string; }; } & { query: { range?: string | string[] | undefined; }; }>;
116 };
117 "/services/:id/traces": {
118 $get: Endpoint<TraceSummary[], { query: { q?: string | undefined; errors?: "1" | undefined; sort?: "newest" | "oldest" | "slowest" | "fastest" | undefined; limit?: string | string[] | undefined; }; } & { param: { id: string; }; }>;
119 };
120 "/traces/:id": {
121 $get: Endpoint<Trace, { param: { id: string; }; }>;
122 };
123 "/metrics/:metric": {
124 $get: Endpoint<Series[], { param: { metric: "host.cpu" | "host.memory" | "host.temperature" | "host.power" | "host.gpu" | "host.network" | "service.cpu" | "service.memory" | "vm.cpu" | "vm.memory"; }; } & { query: { range?: string | string[] | undefined; service?: string | undefined; }; }>;
125 };
126 "/live": {
127 $get: Endpoint<{}, {}, 200, string>;
128 };
129 "/icons/:id/:file": {
130 $get: Endpoint<Uint8Array, { param: { id: string; file: "icon.svg" | "icon-dark.svg" | "icon-light.svg"; }; }, 200, "body">;
131 };
132 "/storage": {
133 $get: Endpoint<{ pool: Omit<Pool, "vdevs"> & { vdevs: (Omit<Vdev, "disks"> & { disks: (Disk & { issue: string | null })[] })[] }; datasets: (Dataset & { link: string | null; media: string | null })[]; space: { live: number; held: number; free: number } }>;
134 };
135 "/storage/snapshots": {
136 $get: Endpoint<Snapshot[], { query: { dataset: string; }; }>;
137 };
138 "/storage/reclaim": {
139 $get: Endpoint<{ bytes: number; }, { query: { dataset: string; from: string; to: string; }; }>;
140 };
141 "/storage/removed": {
142 $get: Endpoint<{ count: number; largest: { path: string; size: number; }[]; }, { query: { dataset: string; snapshot: string; }; }>;
143 };
144 "/storage/destroy": {
145 $post: Endpoint<null, { json: { dataset: string; from: string; to: string; }; }, 204, "body">;
146 };
147 "/storage/files/map": {
148 $get: Endpoint<{ root: string; min: number; scanning: boolean; tree: MapNode | null }, { query: { width: string | string[]; height: string | string[]; path?: string | undefined; }; }>;
149 };
150 "/storage/files/largest": {
151 $get: Endpoint<{ link: string | null; path: string; size: number; alloc: number; mtime: number; }[]>;
152 };
153 "/media/refresh": {
154 $post: Endpoint<null, {}, 202, "body">;
155 };
156 "/seedbox": {
157 $get: Endpoint<{state: ServerState; downloads: string | null; torrents: (Torrent & {folder: string | null; zip: string | null})[]}>;
158 };
159 "/seedbox/history": {
160 $get: Endpoint<Series[]>;
161 };
162 "/seedbox/torrents": {
163 $post: Endpoint<null, { json: { url: string; }; }, 204, "body">;
164 };
165 "/seedbox/torrents/:hash/files": {
166 $get: Endpoint<(TorrentFile & {link: string | null})[], { param: { hash: string; }; }>;
167 };
168 "/seedbox/torrents/:hash/:action": {
169 $post: Endpoint<null, { param: { hash: string; action: "stop" | "start" | "topPrio" | "increasePrio" | "decreasePrio" | "bottomPrio"; }; }, 204, "body">;
170 };
171 "/seedbox/torrents/:hash": {
172 $delete: Endpoint<null, { param: { hash: string; }; } & { query: { files?: "0" | "1" | undefined; }; }, 204, "body">;
173 };
174 "/youtube": {
175 $get: Endpoint<{pending:Video[]; shows:Show[]; jobs:Job[]; wall:Wall; archive:Archive; upscaler:Upscaler}>;
176 };
177 "/youtube/channels": {
178 $get: Endpoint<Channels>;
179 $put: Endpoint<null, { json: Channels }, 204, "body">;
180 };
181 "/youtube/configs": {
182 $get: Endpoint<ConfigFile[]>;
183 };
184 "/youtube/configs/:name": {
185 $put: Endpoint<null, { json: { original: string; body: string; }; } & { param: { name: string; }; }, 204, "body">;
186 };
187 "/youtube/library": {
188 $get: Endpoint<LibraryEntry[]>;
189 };
190 "/youtube/library/rename": {
191 $post: Endpoint<null, { json: { path: string; title: string; season: number | null; episode: number | null; }; }, 204, "body">;
192 };
193 "/youtube/pending": {
194 $post: Endpoint<null, { json: { urls: string[]; }; }, 204, "body">;
195 };
196 "/youtube/pending/:key/ingest": {
197 $post: Endpoint<null, { json: Ingest; param: { key: string } }, 204, "body">;
198 };
199 "/youtube/pending/:key/skip": {
200 $post: Endpoint<null, { param: { key: string; }; }, 204, "body">;
201 };
202 "/youtube/jobs/:id/retry": {
203 $post: Endpoint<null, { param: { id: string; }; }, 204, "body">;
204 };
205 "/youtube/upscaler": {
206 $put: Endpoint<null, { json: { enabled: boolean; }; }, 204, "body">;
207 };
208 "/paper-clover": {
209 $get: Endpoint<PaperCloverStats & { browse: string | null }>;
210 };
211 "/paper-clover/activity": {
212 $get: Endpoint<ProgressNode[]>;
213 };
214 "/paper-clover/scan": {
215 $post: Endpoint<null, { json: { path: string | null; }; }, 202, "body">;
216 };
217 "/users": {
218 $get: Endpoint<{users:(User & {sessions:Session[]})[]; groups:Group[]}>;
219 $post: Endpoint<{ id: string; url: string | null }, { json: { profile: { email: string; firstName: string; lastName: string; username: string; }; groups: string[]; setup: { kind: "invite"; } | { kind: "password"; password: string; }; }; }, 201>;
220 };
221 "/users/:id": {
222 $patch: Endpoint<null, { param: { id: string; }; } & { json: { username?: string | undefined; email?: string | undefined; firstName?: string | undefined; lastName?: string | undefined; enabled?: boolean | undefined; emailVerified?: boolean | undefined; requiredActions?: string[] | undefined; }; }, 204, "body">;
223 $delete: Endpoint<null, { param: { id: string; }; }, 204, "body">;
224 };
225 "/users/groups": {
226 $put: Endpoint<null, { json: { users: string[]; add: string[]; remove: string[]; }; }, 204, "body">;
227 };
228 "/users/:id/groups/:group": {
229 $put: Endpoint<null, { param: { id: string; group: string; }; }, 204, "body">;
230 $delete: Endpoint<null, { param: { id: string; group: string; }; }, 204, "body">;
231 };
232 "/users/:id/credentials": {
233 $get: Endpoint<Credential[], { param: { id: string; }; }>;
234 };
235 "/users/:id/logout": {
236 $post: Endpoint<null, { param: { id: string; }; }, 204, "body">;
237 };
238 "/users/:id/setup-link": {
239 $post: Endpoint<{url:string}, { param: { id: string; }; }>;
240 $delete: Endpoint<null, { param: { id: string; }; }, 204, "body">;
241 };
242 "/users/:id/password": {
243 $put: Endpoint<null, { param: { id: string; }; } & { json: { password: string; temporary: boolean; }; }, 204, "body">;
244 };
245 "/deploys": {
246 $get: Endpoint<{ current: string | null; main: { release: string; commit: string; description: string } | null; recorded: boolean; history: { n: number; changed: string[] | null; redeploys: string[] | null; release: string; source: string; time: number; legacy: boolean; }[]; stages: { files: string | null; base: number | null; changed: string[] | null; behind: string[]; id: string; service: string; release: string | null; ready: boolean; overrides: string[]; created: number; clone: string | null; mount: string; hostname: string | null; health: Health | null; }[]; run: { id: string; title: string; target: string; code: number | null; } | null; }>;
247 };
248 "/deploys/changes": {
249 $get: Endpoint<{ id: string; lines: [op: " " | "-" | "+", text: string][]; }[], { query: { to: string; from?: string | undefined; }; }>;
250 };
251 "/deploys/stages/:id/runtime": {
252 $get: Endpoint<{ from: number; to: number | null; jobs: { id: string; allocations: { id: string; state: "pending" | "running" | "complete" | "failed" | "lost" | "unknown"; healthy: boolean | null; created: number; ended: number | null; tasks: { name: string; restarts: number; lastRestart: { t: number; reason: string; } | null; }[]; checks: { name: string; passing: boolean; output: string; }[]; }[]; cpu: { name: string; t: number[]; v: (number | null)[]; } | null; memory: { name: string; t: number[]; v: (number | null)[]; } | null; }[]; }, { param: { id: string; }; }>;
253 };
254 "/deploys/history/:n/runtime": {
255 $get: Endpoint<{ from: number; to: number | null; jobs: { id: string; allocations: { id: string; state: "pending" | "running" | "complete" | "failed" | "lost" | "unknown"; healthy: boolean | null; created: number; ended: number | null; tasks: { name: string; restarts: number; lastRestart: { t: number; reason: string; } | null; }[]; checks: { name: string; passing: boolean; output: string; }[]; }[]; cpu: { name: string; t: number[]; v: (number | null)[]; } | null; memory: { name: string; t: number[]; v: (number | null)[]; } | null; }[]; }, { param: { n: string; }; }>;
256 };
257 "/deploys/stages/:id/logs": {
258 $get: Endpoint<LogLine[], { param: { id: string }; query: { job?: string; after?: string | string[]; before?: string | string[]; limit?: string | string[] } }>;
259 };
260 "/deploys/history/:n/logs": {
261 $get: Endpoint<LogLine[], { param: { n: string }; query: { job?: string; after?: string | string[]; before?: string | string[]; limit?: string | string[] } }>;
262 };
263 "/deploys/stages/:id/output": {
264 $get: Endpoint<{ lines: string[] | null; }, { param: { id: string; }; }>;
265 };
266 "/deploys/history/:n/output": {
267 $get: Endpoint<{ lines: string[] | null; }, { param: { n: string; }; }>;
268 };
269 "/deploys/main/:release/deploy": {
270 $post: Endpoint<{ id: string; title: string; target: string; }, { param: { release: string; }; }>;
271 };
272 "/deploys/stages/:id/destroy": {
273 $post: Endpoint<{ id: string; title: string; target: string; }, { param: { id: string; }; }>;
274 };
275 "/deploys/history/:n/rollback": {
276 $post: Endpoint<{ id: string; title: string; target: string; }, { param: { n: string; }; }>;
277 };
278 "/deploys/runs/:id": {
279 $get: Endpoint<{}, { param: { id: string; }; }, 200, string>;
280 };
281 "/vms": {
282 $get: Endpoint<{ node: { cpus: number; memory: number; availableMemory: number }; domains: Domain[]; library: VMLibrary; canPublish: boolean }>;
283 $post: Endpoint<null, { json: NewDomain }, 204, "body">;
284 };
285 "/vms/history": {
286 $get: Endpoint<History, { query: { range?: string | string[]; name?: string } }>;
287 };
288 "/vms/:name": {
289 $patch: Endpoint<null, { param: { name: string; }; } & { json: { autostart?: boolean | undefined; description?: string | undefined; }; }, 204, "body">;
290 $delete: Endpoint<null, { param: { name: string; }; } & { query: { disks?: "0" | "1" | undefined; }; }, 204, "body">;
291 };
292 "/vms/:name/media": {
293 $put: Endpoint<null, { param: { name: string }; json: { image: string } }, 204, "body">;
294 };
295 "/vms/:name/access": {
296 $get: Endpoint<{ username: string; password: string; hostname: string } | null, { param: { name: string } }>;
297 };
298 "/vms/:name/preset": {
299 $post: Endpoint<null, { param: { name: string }; json: { id: string; os: string; description: string } }, 204, "body">;
300 };
301 "/vms/:name/:action": {
302 $post: Endpoint<null, { param: { name: string; action: "start" | "destroy" | "shutdown" | "reboot" | "resume"; }; }, 204, "body">;
303 };
304 "/account": {
305 $get: Endpoint<User & {picture: string | null; credentials:Credential[]}>;
306 $patch: Endpoint<null, { json: { firstName?: string | undefined; lastName?: string | undefined; email?: string | undefined; }; }, 204, "body">;
307 };
308 "/account/picture": {
309 $put: Endpoint<{ picture: string; }, { form: { picture: File; }; }>;
310 $delete: Endpoint<null, {}, 204, "body">;
311 };
312 "/account/pictures/:id": {
313 $get: Endpoint<Uint8Array, { param: { id: string; }; }, 200, "body">;
314 };
315 "/account/credentials/:id": {
316 $delete: Endpoint<null, { param: { id: string; }; }, 204, "body">;
317 };
318} & ExplorerRoutes<"/media"> & ExplorerRoutes<"/storage/files">>;