The best way to control Claude Code, Codex and more from any computer or phone

main
ts 116 lines 3.97 KB
Raw
1 /**
2 * The `objects` group: commit, log, tree, blob, diff, and compare reads,
3 * plus the two raw streaming reads (DESIGN.md §5): a blob's bytes as an
4 * octet-stream, and a file at a path under a ref. The raw routes declare
5 * no success schema and answer with the response they build.
6 */
7 import * as HttpApiEndpoint from "effect/http-api/HttpApiEndpoint";
8 import * as HttpApiGroup from "effect/http-api/HttpApiGroup";
9 import * as Schema from "effect/Schema";
10 import {
11 CommitDiff,
12 CommitInfo,
13 Comparison,
14 NoMergeBase,
15 ObjectNotFound,
16 ObjectTooLarge,
17 Oid,
18 Paginated,
19 RefNotFound,
20 RepoNotFound,
21 RepoOidPath,
22 RepoPath,
23 TreeEntry,
24 WrongObjectType,
25 } from "./Schema.ts";
26
27 /** Reads one commit. */
28 export const GetCommit = HttpApiEndpoint.get("commit", "/repos/:owner/:repo/commits/:oid", {
29 params: RepoOidPath,
30 success: CommitInfo,
31 error: [RepoNotFound, ObjectNotFound, WrongObjectType],
32 });
33
34 /** Pages the commit history from a ref or oid. */
35 export const GetLog = HttpApiEndpoint.get("log", "/repos/:owner/:repo/log", {
36 params: RepoPath,
37 query: Schema.Struct({
38 /** Refname or oid to start from. @default HEAD */
39 ref: Schema.optional(Schema.String),
40 cursor: Schema.optional(Schema.String),
41 limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 }))),
42 }),
43 success: Paginated(CommitInfo),
44 error: [RepoNotFound, RefNotFound],
45 });
46
47 /** Reads one tree's entries. */
48 export const GetTree = HttpApiEndpoint.get("tree", "/repos/:owner/:repo/trees/:oid", {
49 params: RepoOidPath,
50 success: Schema.Struct({
51 oid: Oid,
52 entries: Schema.Array(TreeEntry),
53 }),
54 error: [RepoNotFound, ObjectNotFound, WrongObjectType],
55 });
56
57 /** Reads a small blob as base64 JSON (≤ 1 MiB; 422 otherwise — use /raw). */
58 export const GetBlob = HttpApiEndpoint.get("blob", "/repos/:owner/:repo/blobs/:oid", {
59 params: RepoOidPath,
60 success: Schema.Struct({
61 oid: Oid,
62 /** Uncompressed size in bytes. */
63 size: Schema.Number,
64 encoding: Schema.Literals(["base64"]),
65 /** Base64 content — blobs ≤ 1 MiB only (422 otherwise; use /raw). */
66 content: Schema.String,
67 }),
68 error: [RepoNotFound, ObjectNotFound, WrongObjectType, ObjectTooLarge],
69 });
70
71 /**
72 * The changed-file list of a commit vs its FIRST parent (empty tree for a
73 * root commit). Merge commits are diffed against parent[0] only — the
74 * GitHub default. No rename detection in v1: a rename appears as
75 * `removed` + `added`; clients may pair entries whose old/new oids match
76 * for a cheap exact-rename display.
77 */
78 export const GetDiff = HttpApiEndpoint.get("diff", "/repos/:owner/:repo/commits/:oid/diff", {
79 params: RepoOidPath,
80 success: CommitDiff,
81 error: [RepoNotFound, ObjectNotFound, WrongObjectType],
82 });
83
84 /**
85 * Three-dot comparison: merge base, ahead/behind counts, head-side
86 * commits, and the file diff of mergeBase..head. `base`/`head` accept a
87 * refname (short or full) or a 40-hex oid; annotated tags are peeled.
88 */
89 export const Compare = HttpApiEndpoint.get("compare", "/repos/:owner/:repo/compare", {
90 params: RepoPath,
91 query: Schema.Struct({
92 /** Refname or oid of the base side. */
93 base: Schema.String,
94 /** Refname or oid of the head side. */
95 head: Schema.String,
96 }),
97 success: Comparison,
98 error: [RepoNotFound, RefNotFound, ObjectNotFound, WrongObjectType, NoMergeBase],
99 });
100
101 /**
102 * A blob's bytes as an octet-stream, no size cap (the per-object 64 MiB
103 * ingest cap is the outer bound). Streams the response it builds.
104 */
105 export const GetBlobRaw = HttpApiEndpoint.get("blobRaw", "/repos/:owner/:repo/blobs/:oid/raw", {});
106
107 /**
108 * A file at `?path=` under `?ref=` (refname or oid; the default branch
109 * when absent), walked tree by tree, as an octet-stream.
110 */
111 export const GetFile = HttpApiEndpoint.get("file", "/repos/:owner/:repo/file", {});
112
113 /** The `objects` group, mounted at `/api/v1`. */
114 export class Objects extends HttpApiGroup.make("objects")
115 .add(GetCommit, GetLog, GetTree, GetBlob, GetDiff, Compare, GetBlobRaw, GetFile)
116 .prefix("/api/v1") {}