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, VpsService, 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";
12import type { AccountSecret, FolderGrant, LinkInput, ShareState } from "./types/shares.ts";
13
14type Endpoint<Output, Input = {}, Status extends number = 200, Format extends string = "json"> = {
15 input: Input; output: Output; status: Status; outputFormat: Format;
16};
17
18type FileEntry = { name: string; dir: boolean; size: number | null; alloc: number | null; items: number | null; modified: number; inode: number; dataset: string | null; download: string | null; };
19
20type Explorer = {
21 "/list": {
22 $get: Endpoint<{ host: string; link: string | null; zip: string | null; entries: FileEntry[]; }, { query: { path?: string | undefined; }; }>;
23 };
24 "/tree": {
25 $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"; }; }>;
26 };
27 "/match": {
28 $get: Endpoint<{ count: number; size: number | null; sample: string[]; rows: { [x: string]: number | "self"; }; }, { query: { path: string; pattern: string; }; }>;
29 };
30 "/peek": {
31 $get: Endpoint<{ text: string; more: boolean; }, { query: { path: string; }; }>;
32 };
33 "/ops": {
34 $get: Endpoint<{ id: string; label: string; at: number; undone: boolean; sample: string[]; count: number; }[]>;
35 };
36 "/folder": {
37 $post: Endpoint<{ id: `${string}-${string}-${string}-${string}-${string}`; label: string; }, { json: { path: string; name: string; }; }>;
38 };
39 "/rename": {
40 $post: Endpoint<{ id: `${string}-${string}-${string}-${string}-${string}`; label: string; }, { json: { renames: { path: string; name: string; }[]; }; }>;
41 };
42 "/move": {
43 $post: Endpoint<{ id: `${string}-${string}-${string}-${string}-${string}`; label: string; }, { json: { paths: string[]; to: string; }; }>;
44 };
45 "/delete": {
46 $post: Endpoint<{ id: `${string}-${string}-${string}-${string}-${string}`; label: string; }, { json: { paths: string[]; }; }>;
47 };
48 "/bulk": {
49 $post: Endpoint<{ id: `${string}-${string}-${string}-${string}-${string}`; label: string; }, { json: { path: string; pattern: string; count: number; action: "move" | "delete"; to?: string | undefined; }; }>;
50 };
51 "/ops/:id/undo": {
52 $post: Endpoint<null, { param: { id: string; }; }, 204, "body">;
53 };
54};
55type ExplorerRoutes<Prefix extends string> = { [P in keyof Explorer as `${Prefix}${P}`]: Explorer[P] };
56
57export type Api = Hono<{}, {
58 "/shares": { $get: Endpoint<ShareState>; };
59 "/shares/folders": { $get: Endpoint<{ path: string; directories: { name: string; path: string }[] }, { query: { path: string } }>; };
60 "/shares/accounts": { $post: Endpoint<AccountSecret, { json: { name: string } }>; };
61 "/shares/accounts/:id": {
62 $patch: Endpoint<ShareState, { param: { id: string }; json: { name: string } }>;
63 $delete: Endpoint<ShareState, { param: { id: string } }>;
64 };
65 "/shares/accounts/:id/rotate": { $post: Endpoint<AccountSecret, { param: { id: string } }>; };
66 "/shares/grants": { $post: Endpoint<ShareState, { json: Omit<FolderGrant, "id"> }>; };
67 "/shares/grants/:id": {
68 $patch: Endpoint<ShareState, { param: { id: string }; json: Omit<FolderGrant, "id"> }>;
69 $delete: Endpoint<ShareState, { param: { id: string } }>;
70 };
71 "/shares/links": { $post: Endpoint<ShareState, { json: LinkInput & { createFolder: boolean } }>; };
72 "/shares/links/:key": {
73 $patch: Endpoint<ShareState, { param: { key: string }; json: LinkInput & { mode: "retarget" | "move" } }>;
74 $delete: Endpoint<ShareState, { param: { key: string } }>;
75 };
76 "/ai": { $get: Endpoint<{ endpoint: string; model: string; context: number }>; };
77 "/ai/key": { $post: Endpoint<{ key: string }>; };
78 "/mcp": { $get: Endpoint<Connections>; };
79 "/mcp/shale": { $get: Endpoint<{ linked: boolean; resources: Resources }>; $post: Endpoint<{ redirect: string }, { json: { request?: string } }>; $delete: Endpoint<null, {}, 204>; };
80 "/mcp/consent/:id": {
81 $get: Endpoint<Consent, { param: { id: string } }>;
82 $post: Endpoint<{ redirect: string }, { param: { id: string }; json: { resources: Access } | { deny: true } }>;
83 };
84 "/mcp/connections/:id": {
85 $get: Endpoint<{ resources: Resources; selected: Access; linked: boolean; resourceError: string | null }, { param: { id: string } }>;
86 $post: Endpoint<null, { param: { id: string }; json: { resources: Access } }, 204>;
87 $delete: Endpoint<null, { param: { id: string } }, 204>;
88 };
89
90 "/me": {
91 $get: Endpoint<Me>;
92 };
93 "/launcher": {
94 $get: Endpoint<{ id: string; name: string; tagline: string | null; url: string; urls: Record<string, string>; icon: { light: string; dark: string; } | null; health: Health | null; }[]>;
95 };
96 "/status": {
97 $get: Endpoint<{ load: number; issues: Issue[] | null }>;
98 };
99 "/host": {
100 $get: Endpoint<HostInfo>;
101 };
102 "/services": {
103 $get: Endpoint<ServiceSummary[]>;
104 };
105 "/vps": {
106 $get: Endpoint<VpsService[]>;
107 };
108 "/services/:id": {
109 $get: Endpoint<ServiceDetail, { param: { id: string; }; }>;
110 };
111 "/services/:id/definition": {
112 $get: Endpoint<ServiceDefinition, { param: { id: string; }; }>;
113 };
114 "/services/:id/:action": {
115 $post: Endpoint<null, { param: { id: string; action: "stop" | "restart" | "start"; }; }, 204, "body">;
116 };
117 "/services/:id/restarts/acknowledge": {
118 $post: Endpoint<null, { param: { id: string; }; }, 204, "body">;
119 };
120 "/services/:id/secrets/:name": {
121 $get: Endpoint<{ value: string; }, { param: { name: string; } & { id: string; }; }>;
122 $put: Endpoint<null, { json: { value: string; }; } & { param: { name: string; } & { id: string; }; }, 204, "body">;
123 };
124 "/services/:id/secrets/:name/rotate": {
125 $post: Endpoint<null, { param: { name: string; } & { id: string; }; }, 204, "body">;
126 };
127 "/services/:id/logs": {
128 $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; }; }>;
129 };
130 "/services/:id/metrics/:name": {
131 $get: Endpoint<Series[], { param: { id: string; name: string; }; } & { query: { range?: string | string[] | undefined; }; }>;
132 };
133 "/services/:id/traces": {
134 $get: Endpoint<TraceSummary[], { query: { q?: string | undefined; errors?: "1" | undefined; sort?: "newest" | "oldest" | "slowest" | "fastest" | undefined; limit?: string | string[] | undefined; }; } & { param: { id: string; }; }>;
135 };
136 "/traces/:id": {
137 $get: Endpoint<Trace, { param: { id: string; }; }>;
138 };
139 "/metrics/:metric": {
140 $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; }; }>;
141 };
142 "/live": {
143 $get: Endpoint<{}, {}, 200, string>;
144 };
145 "/icons/:id/:file": {
146 $get: Endpoint<Uint8Array, { param: { id: string; file: "icon.svg" | "icon-dark.svg" | "icon-light.svg"; }; }, 200, "body">;
147 };
148 "/storage": {
149 $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 } }>;
150 };
151 "/storage/snapshots": {
152 $get: Endpoint<Snapshot[], { query: { dataset: string; }; }>;
153 };
154 "/storage/reclaim": {
155 $get: Endpoint<{ bytes: number; }, { query: { dataset: string; from: string; to: string; }; }>;
156 };
157 "/storage/removed": {
158 $get: Endpoint<{ count: number; largest: { path: string; size: number; }[]; }, { query: { dataset: string; snapshot: string; }; }>;
159 };
160 "/storage/destroy": {
161 $post: Endpoint<null, { json: { dataset: string; from: string; to: string; }; }, 204, "body">;
162 };
163 "/storage/files/map": {
164 $get: Endpoint<{ root: string; min: number; scanning: boolean; tree: MapNode | null }, { query: { width: string | string[]; height: string | string[]; path?: string | undefined; }; }>;
165 };
166 "/storage/files/largest": {
167 $get: Endpoint<{ link: string | null; path: string; size: number; alloc: number; mtime: number; }[]>;
168 };
169 "/media/refresh": {
170 $post: Endpoint<null, {}, 202, "body">;
171 };
172 "/seedbox": {
173 $get: Endpoint<{state: ServerState; downloads: string | null; torrents: (Torrent & {folder: string | null; zip: string | null})[]}>;
174 };
175 "/seedbox/history": {
176 $get: Endpoint<Series[]>;
177 };
178 "/seedbox/torrents": {
179 $post: Endpoint<null, { json: { url: string; }; }, 204, "body">;
180 };
181 "/seedbox/torrents/:hash/files": {
182 $get: Endpoint<(TorrentFile & {link: string | null})[], { param: { hash: string; }; }>;
183 };
184 "/seedbox/torrents/:hash/:action": {
185 $post: Endpoint<null, { param: { hash: string; action: "stop" | "start" | "topPrio" | "increasePrio" | "decreasePrio" | "bottomPrio"; }; }, 204, "body">;
186 };
187 "/seedbox/torrents/:hash": {
188 $delete: Endpoint<null, { param: { hash: string; }; } & { query: { files?: "0" | "1" | undefined; }; }, 204, "body">;
189 };
190 "/youtube": {
191 $get: Endpoint<{pending:Video[]; shows:Show[]; jobs:Job[]; wall:Wall; archive:Archive; upscaler:Upscaler}>;
192 };
193 "/youtube/channels": {
194 $get: Endpoint<Channels>;
195 $put: Endpoint<null, { json: Channels }, 204, "body">;
196 };
197 "/youtube/configs": {
198 $get: Endpoint<ConfigFile[]>;
199 };
200 "/youtube/configs/:name": {
201 $put: Endpoint<null, { json: { original: string; body: string; }; } & { param: { name: string; }; }, 204, "body">;
202 };
203 "/youtube/library": {
204 $get: Endpoint<LibraryEntry[]>;
205 };
206 "/youtube/library/rename": {
207 $post: Endpoint<null, { json: { path: string; title: string; season: number | null; episode: number | null; }; }, 204, "body">;
208 };
209 "/youtube/pending": {
210 $post: Endpoint<null, { json: { urls: string[]; }; }, 204, "body">;
211 };
212 "/youtube/pending/:key/ingest": {
213 $post: Endpoint<null, { json: Ingest; param: { key: string } }, 204, "body">;
214 };
215 "/youtube/pending/:key/skip": {
216 $post: Endpoint<null, { param: { key: string; }; }, 204, "body">;
217 };
218 "/youtube/jobs/:id/retry": {
219 $post: Endpoint<null, { param: { id: string; }; }, 204, "body">;
220 };
221 "/youtube/upscaler": {
222 $put: Endpoint<null, { json: { enabled: boolean; }; }, 204, "body">;
223 };
224 "/paper-clover": {
225 $get: Endpoint<PaperCloverStats & { browse: string | null }>;
226 };
227 "/paper-clover/activity": {
228 $get: Endpoint<ProgressNode[]>;
229 };
230 "/paper-clover/scan": {
231 $post: Endpoint<null, { json: { path: string | null; }; }, 202, "body">;
232 };
233 "/users": {
234 $get: Endpoint<{users:(User & {sessions:Session[]})[]; groups:Group[]}>;
235 $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; } | { kind: "astheno"; }; astheno?: string; }; }, 201>;
236 };
237 "/users/guests": {
238 $post: Endpoint<{ id: string; created: boolean }, { json: { provider: "github" | "astheno" | "atproto"; handle: string; }; }>;
239 };
240 "/users/:id": {
241 $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">;
242 $delete: Endpoint<null, { param: { id: string; }; }, 204, "body">;
243 };
244 "/users/groups": {
245 $put: Endpoint<null, { json: { users: string[]; add: string[]; remove: string[]; }; }, 204, "body">;
246 };
247 "/users/:id/astheno": {
248 $put: Endpoint<null, { param: { id: string; }; json: { handle: string; }; }, 204, "body">;
249 $delete: Endpoint<null, { param: { id: string; }; }, 204, "body">;
250 };
251 "/users/:id/groups/:group": {
252 $put: Endpoint<null, { param: { id: string; group: string; }; }, 204, "body">;
253 $delete: Endpoint<null, { param: { id: string; group: string; }; }, 204, "body">;
254 };
255 "/users/:id/commit-identity": {
256 $get: Endpoint<import("./types/users.ts").CommitIdentity, { param: { id: string } }>;
257 };
258 "/users/:id/commit-emails/:email": {
259 $put: Endpoint<null, { param: { id: string; email: string } }, 204, "body">;
260 };
261 "/users/:id/signing-keys/:fingerprint": {
262 $put: Endpoint<null, { param: { id: string; fingerprint: string } }, 204, "body">;
263 };
264 "/users/:id/credentials": {
265 $get: Endpoint<Credential[], { param: { id: string; }; }>;
266 };
267 "/users/:id/logout": {
268 $post: Endpoint<null, { param: { id: string; }; }, 204, "body">;
269 };
270 "/users/:id/setup-link": {
271 $post: Endpoint<{url:string}, { param: { id: string; }; }>;
272 $delete: Endpoint<null, { param: { id: string; }; }, 204, "body">;
273 };
274 "/users/:id/password": {
275 $put: Endpoint<null, { param: { id: string; }; } & { json: { password: string; temporary: boolean; }; }, 204, "body">;
276 };
277 "/deploys": {
278 $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; }>;
279 };
280 "/deploys/changes": {
281 $get: Endpoint<{ id: string; lines: [op: " " | "-" | "+", text: string][]; }[], { query: { to: string; from?: string | undefined; }; }>;
282 };
283 "/deploys/stages/:id/runtime": {
284 $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; }; }>;
285 };
286 "/deploys/history/:n/runtime": {
287 $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; }; }>;
288 };
289 "/deploys/stages/:id/logs": {
290 $get: Endpoint<LogLine[], { param: { id: string }; query: { job?: string; after?: string | string[]; before?: string | string[]; limit?: string | string[] } }>;
291 };
292 "/deploys/history/:n/logs": {
293 $get: Endpoint<LogLine[], { param: { n: string }; query: { job?: string; after?: string | string[]; before?: string | string[]; limit?: string | string[] } }>;
294 };
295 "/deploys/stages/:id/output": {
296 $get: Endpoint<{ lines: string[] | null; }, { param: { id: string; }; }>;
297 };
298 "/deploys/history/:n/output": {
299 $get: Endpoint<{ lines: string[] | null; }, { param: { n: string; }; }>;
300 };
301 "/deploys/main/:release/deploy": {
302 $post: Endpoint<{ id: string; title: string; target: string; }, { param: { release: string; }; }>;
303 };
304 "/deploys/stages/:id/destroy": {
305 $post: Endpoint<{ id: string; title: string; target: string; }, { param: { id: string; }; }>;
306 };
307 "/deploys/history/:n/rollback": {
308 $post: Endpoint<{ id: string; title: string; target: string; }, { param: { n: string; }; }>;
309 };
310 "/deploys/runs/:id": {
311 $get: Endpoint<{}, { param: { id: string; }; }, 200, string>;
312 };
313 "/vms": {
314 $get: Endpoint<{ node: { cpus: number; memory: number; availableMemory: number }; domains: Domain[]; library: VMLibrary; canPublish: boolean }>;
315 $post: Endpoint<null, { json: NewDomain }, 204, "body">;
316 };
317 "/vms/history": {
318 $get: Endpoint<History, { query: { range?: string | string[]; name?: string } }>;
319 };
320 "/vms/:name": {
321 $patch: Endpoint<null, { param: { name: string; }; } & { json: { autostart?: boolean | undefined; description?: string | undefined; }; }, 204, "body">;
322 $delete: Endpoint<null, { param: { name: string; }; } & { query: { disks?: "0" | "1" | undefined; }; }, 204, "body">;
323 };
324 "/vms/:name/media": {
325 $put: Endpoint<null, { param: { name: string }; json: { image: string } }, 204, "body">;
326 };
327 "/vms/:name/clipboard": {
328 $post: Endpoint<null, { param: { name: string }; json: { text: string } }>;
329 };
330 "/vms/:name/access": {
331 $get: Endpoint<{ username: string; password: string; hostname: string } | null, { param: { name: string } }>;
332 };
333 "/vms/:name/preset": {
334 $post: Endpoint<null, { param: { name: string }; json: { id: string; os: string; description: string } }, 204, "body">;
335 };
336 "/vms/:name/:action": {
337 $post: Endpoint<null, { param: { name: string; action: "start" | "destroy" | "shutdown" | "reboot" | "resume" | "suspend"; }; }, 204, "body">;
338 };
339 "/account": {
340 $get: Endpoint<User & {picture: string | null; credentials:Credential[]; commitIdentity: import("./types/users.ts").CommitIdentity}>;
341 $patch: Endpoint<null, { json: { firstName?: string | undefined; lastName?: string | undefined; email?: string | undefined; }; }, 204, "body">;
342 };
343 "/account/commit-emails": {
344 $post: Endpoint<null, { json: { email: string } }, 204, "body">;
345 };
346 "/account/commit-emails/:email": {
347 $put: Endpoint<null, { param: { email: string } }, 204, "body">;
348 $delete: Endpoint<null, { param: { email: string } }, 204, "body">;
349 };
350 "/account/signing-keys": {
351 $post: Endpoint<null, { json: { publicKey: string; label: string } }, 204, "body">;
352 };
353 "/account/signing-keys/:fingerprint": {
354 $put: Endpoint<null, { param: { fingerprint: string } }, 204, "body">;
355 $delete: Endpoint<null, { param: { fingerprint: string } }, 204, "body">;
356 };
357 "/account/picture": {
358 $put: Endpoint<{ picture: string; }, { form: { picture: File; }; }>;
359 $delete: Endpoint<null, {}, 204, "body">;
360 };
361 "/account/pictures/:id": {
362 $get: Endpoint<Uint8Array, { param: { id: string; }; }, 200, "body">;
363 };
364 "/account/credentials/:id": {
365 $delete: Endpoint<null, { param: { id: string; }; }, 204, "body">;
366 };
367} & ExplorerRoutes<"/media"> & ExplorerRoutes<"/storage/files">>;