g1t/packages/contracts/src/clients.ts

193 lines10,463 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Agents as a team: lifecycle, merge queue, billing and a new shell1import type { BillingApi } from "./billing";
Events service in Rust, with RFC 3339 times and accurate push events2import type { EventsApi } from "./events";
API and MCP server, Rust identity service, registration, site redesign3import type { IdentityApi } from "./identity";
Rust repos service with shipping; pull requests kept in the model4import type { ReposApi } from "./repos";
Work service in Rust, with RFC 3339 timestamps5import type { WorkApi } from "./work";
API and MCP server, Rust identity service, registration, site redesign6
7/** A service binding, as far as these clients need it. */
8export type ServiceBinding = {
9 fetch(input: string, init?: RequestInit): Promise<Response>;
10};
11
12/**
13 * Calls a method on a service that speaks the JSON protocol used by the
14 * Rust services: `POST /rpc/<method>` with the arguments as the body.
15 */
16async function rpc<T>(
17 service: ServiceBinding,
18 method: string,
19 args: object,
20): Promise<T> {
21 // The hostname is ignored; a service binding always reaches its service.
22 const response = await service.fetch(`https://service/rpc/${method}`, {
23 method: "POST",
24 headers: { "content-type": "application/json" },
25 body: JSON.stringify(args),
26 });
27 if (!response.ok) {
28 throw new Error(`${method} failed with status ${response.status}`);
29 }
Agents as a team: lifecycle, merge queue, billing and a new shell30 return (await response.json()) as T;
API and MCP server, Rust identity service, registration, site redesign31}
32
33export function identityClient(service: ServiceBinding): IdentityApi {
34 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
35 return {
36 register: (username, email, password) =>
37 call("register", { username, email, password }),
38 signIn: (username, password) => call("sign_in", { username, password }),
39 signOut: (sessionToken) => call("sign_out", { sessionToken }),
Email verification, password reset, and Git for AI scale positioning40 resendVerification: (user) => call("resend_verification", { user }),
41 verifyEmail: (token) => call("verify_email", { token }),
42 requestPasswordReset: (email) => call("request_password_reset", { email }),
43 resetPassword: (token, password) =>
44 call("reset_password", { token, password }),
Device sign-in replaces registering and minting tokens over the API45 deviceStart: (clientName) => call("device_start", { clientName }),
46 deviceLookup: (userCode) => call("device_lookup", { userCode }),
47 deviceResolve: (userCode, user, approve) =>
48 call("device_resolve", { userCode, user, approve }),
49 deviceClaim: (deviceCode) => call("device_claim", { deviceCode }),
OAuth 2.1 sign-in for MCP clients and other applications50 oauthAuthorize: (user, approval) => call("oauth_authorize", { user, ...approval }),
51 oauthExchange: (code, codeVerifier, clientId, redirectUri) =>
52 call("oauth_exchange", { code, codeVerifier, clientId, redirectUri }),
53 oauthRefresh: (refreshToken, clientId) =>
54 call("oauth_refresh", { refreshToken, clientId }),
55 listOAuthGrants: (user) => call("list_oauth_grants", { user }),
56 revokeOAuthGrant: (user, id) => call("revoke_oauth_grant", { user, id }),
Workspaces own repositories57 createWorkspace: (user, slug, name) => call("create_workspace", { user, slug, name }),
58 getWorkspace: (slug) => call("get_workspace", { slug }),
59 listMembers: (slug, viewer) => call("list_members", { slug, viewer }),
60 addMember: (actor, slug, username) => call("add_member", { actor, slug, username }),
61 removeMember: (actor, slug, username) =>
62 call("remove_member", { actor, slug, username }),
Agents as a team: lifecycle, merge queue, billing and a new shell63 updateWorkspace: (actor, slug, details) =>
64 call("update_workspace", { actor, slug, ...details }),
65 listWorkspaceTokens: (slug, viewer) => call("list_workspace_tokens", { slug, viewer }),
66 createWorkspaceToken: (actor, slug, name) =>
67 call("create_workspace_token", { actor, slug, name }),
68 removeWorkspaceToken: (actor, slug, id) =>
69 call("remove_workspace_token", { actor, slug, id }),
API and MCP server, Rust identity service, registration, site redesign70 userForSession: (sessionToken) => call("user_for_session", { sessionToken }),
71 userForGitCredentials: (username, secret) =>
72 call("user_for_git_credentials", { username, secret }),
73 userForAccessToken: (token) => call("user_for_access_token", { token }),
74 userForSshKey: (fingerprint) => call("user_for_ssh_key", { fingerprint }),
75 userByUsername: (username) => call("user_by_username", { username }),
What happened across an outcome, as a feed beside its graph76 usernames: (ids) => call("usernames", { ids }),
API and MCP server, Rust identity service, registration, site redesign77 listSshKeys: (user) => call("list_ssh_keys", { user }),
78 addSshKey: (user, title, publicKey) =>
79 call("add_ssh_key", { user, title, publicKey }),
80 removeSshKey: (user, id) => call("remove_ssh_key", { user, id }),
81 listAccessTokens: (user) => call("list_access_tokens", { user }),
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)82 createAccessToken: (user, name, ttlSeconds) =>
83 call("create_access_token", { user, name, ttlSeconds }),
Agents as a team: lifecycle, merge queue, billing and a new shell84 createAgentToken: (onBehalfOf, scope, ttlSeconds) =>
85 call("create_agent_token", { onBehalfOf, scope, ttlSeconds }),
API and MCP server, Rust identity service, registration, site redesign86 removeAccessToken: (user, id) => call("remove_access_token", { user, id }),
87 };
88}
Rust repos service with shipping; pull requests kept in the model89
90export function reposClient(service: ServiceBinding): ReposApi {
91 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
92 return {
93 get: (path, viewer) => call("get", { path, viewer }),
94 getById: (id, viewer) => call("get_by_id", { id, viewer }),
95 list: (viewer, options = {}) => call("list", { viewer, ...options }),
96 create: (owner, input) => call("create", { owner, ...input }),
Agents as a team: lifecycle, merge queue, billing and a new shell97 update: (actor, path, changes) => call("update", { actor, path, ...changes }),
Rust repos service with shipping; pull requests kept in the model98 tree: (path, viewer, ref, treePath) =>
99 call("tree", { path, viewer, ref, treePath }),
100 blob: (path, viewer, ref, filePath) =>
101 call("blob", { path, viewer, ref, filePath }),
102 log: (path, viewer, ref, limit) => call("log", { path, viewer, ref, limit }),
Agents as a team: lifecycle, merge queue, billing and a new shell103 blame: (path, viewer, ref, filePath) => call("blame", { path, viewer, ref, filePath }),
Issues and pull requests replace intents and attempts104 forkForPull: (sourceId, pullId, actor) =>
105 call("fork_for_pull", { sourceId, pullId, actor }),
Rust repos service with shipping; pull requests kept in the model106 gitAccess: (path, viewer, service) =>
107 call("git_access", { path, viewer, service }),
Pull requests from branches108 branches: (path, viewer) => call("branches", { path, viewer }),
109 land: (sourceId, actor, branch) => call("land", { sourceId, actor, branch }),
110 compare: (repoId, viewer, base, head) => call("compare", { repoId, viewer, base, head }),
Rust repos service with shipping; pull requests kept in the model111 };
112}
Work service in Rust, with RFC 3339 timestamps113
114export function workClient(service: ServiceBinding): WorkApi {
115 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
116 return {
Issues and pull requests replace intents and attempts117 openIssue: (actor, repo, input) => call("open_issue", { actor, repo, ...input }),
118 listIssues: (repo, viewer, filter = {}) => call("list_issues", { repo, viewer, ...filter }),
119 getIssue: (repo, number, viewer) => call("get_issue", { repo, number, viewer }),
120 updateIssue: (actor, repo, number, input) =>
121 call("update_issue", { actor, repo, number, ...input }),
122 closeIssue: (actor, repo, number, reason) =>
123 call("close_issue", { actor, repo, number, reason }),
124 reopenIssue: (actor, repo, number) => call("reopen_issue", { actor, repo, number }),
125 listLabels: (repo, viewer) => call("list_labels", { repo, viewer }),
126 counts: (repo, viewer) => call("counts", { repo, viewer }),
Acceptance checks in sandboxes, line comments and review verdicts127 addComment: (actor, repo, number, comment) =>
128 call("add_comment", { actor, repo, number, ...comment }),
129 startChecks: (pullId) => call("start_checks", { pullId }),
130 reportChecks: (runId, token, report) =>
131 call("report_checks", { runId, token, ...report }),
Agents as a team: lifecycle, merge queue, billing and a new shell132 startReview: (pullId) => call("start_review", { pullId }),
133 failReview: (runId, token, error) => call("report_review", { runId, token, error }),
134 advance: (pullId) => call("advance", { pullId }),
135 stall: (pullId, reason) => call("stall", { pullId, reason }),
136 managedPulls: (repoId) => call("managed_pulls", { repoId }),
137 queue: (repo, viewer) => call("queue", { repo, viewer }),
138 queueBuild: (repoId) => call("queue_build", { repoId }),
139 failQueue: (entryId, token, error) => call("report_queue", { entryId, token, error }),
140 removeFromQueue: (actor, repo, number) => call("remove_from_queue", { actor, repo, number }),
141 catchUpJob: (pullId) => call("catch_up_job", { pullId }),
142 getSettings: (repo, viewer) => call("get_settings", { repo, viewer }),
143 updateSettings: (actor, repo, settings) =>
144 call("update_settings", { actor, repo, settings }),
Issues and pull requests replace intents and attempts145 openPull: (actor, repo, input) => call("open_pull", { actor, repo, ...input }),
146 listPulls: (repo, viewer, state) => call("list_pulls", { repo, viewer, state }),
147 getPull: (repo, number, viewer) => call("get_pull", { repo, number, viewer }),
Agents as a team: lifecycle, merge queue, billing and a new shell148 updatePull: (actor, repo, number, changes) =>
149 call("update_pull", { actor, repo, number, ...changes }),
Issues and pull requests replace intents and attempts150 readyPull: (actor, repo, number, summary) =>
151 call("ready_pull", { actor, repo, number, summary }),
152 closePull: (actor, repo, number) => call("close_pull", { actor, repo, number }),
Acceptance checks in sandboxes, line comments and review verdicts153 mergePull: (actor, repo, number, options = {}) =>
154 call("merge_pull", { actor, repo, number, ...options }),
Issues and pull requests replace intents and attempts155 listActivePulls: (viewer) => call("list_active_pulls", { viewer }),
Agents as a team: lifecycle, merge queue, billing and a new shell156 startPlan: (actor, repo, brief) => call("start_plan", { actor, repo, brief }),
157 failPlan: (planId, token, error) => call("report_plan", { planId, token, error }),
158 getPlan: (repo, viewer, id) => call("get_plan", { repo, viewer, id }),
159 listPlans: (repo, viewer) => call("list_plans", { repo, viewer }),
160 applyPlan: (actor, repo, id, options = {}) =>
161 call("apply_plan", { actor, repo, id, ...options }),
162 queueIssue: (actor, repo, number, queued) =>
163 call("queue_issue", { actor, repo, number, queued }),
164 readyIssues: (repoId) => call("ready_issues", { repoId }),
165 listAssignedIssues: (viewer) => call("list_assigned_issues", { viewer }),
Issues and pull requests replace intents and attempts166 appendSession: (actor, repo, number, entries) =>
167 call("append_session", { actor, repo, number, entries }),
168 readSession: (repo, number, viewer, afterSeq = 0) =>
169 call("read_session", { repo, number, viewer, afterSeq }),
Work service in Rust, with RFC 3339 timestamps170 };
171}
Events service in Rust, with RFC 3339 times and accurate push events172
Agents as a team: lifecycle, merge queue, billing and a new shell173export function billingClient(service: ServiceBinding): BillingApi {
174 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
175 return {
176 status: () => call("status", {}),
177 account: (workspace, viewer) => call("account", { workspace, viewer }),
178 ledger: (workspace, viewer) => call("ledger", { workspace, viewer }),
179 checkout: (actor, workspace, amountCents, returnUrl) =>
180 call("checkout", { actor, workspace, amountCents, returnUrl }),
181 confirm: (workspace, viewer, session) => call("confirm", { workspace, viewer, session }),
182 canStart: (workspace) => call("can_start", { workspace }),
183 startRun: (run) => call("start_run", run),
184 };
185}
186
Events service in Rust, with RFC 3339 times and accurate push events187export function eventsClient(service: ServiceBinding): EventsApi {
188 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
189 return {
190 publish: (events) => call("publish", { events }),
191 list: (query) => call("list", query),
192 };
193}