g1t/packages/contracts/src/clients.ts

251 lines14,167 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.

GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs1import type { ActionsApi } from "./actions";
Agents as a team: lifecycle, merge queue, billing and a new shell2import type { BillingApi } from "./billing";
Events service in Rust, with RFC 3339 times and accurate push events3import type { EventsApi } from "./events";
API and MCP server, Rust identity service, registration, site redesign4import type { IdentityApi } from "./identity";
Integrations: your own model provider, alerts that open issues, tickets agents read5import type { IntegrationsApi } from "./integrations";
Webhooks: every event, to your own addresses, signed and retried6import type { WebhooksApi } from "./webhooks";
Rust repos service with shipping; pull requests kept in the model7import type { ReposApi } from "./repos";
Work service in Rust, with RFC 3339 timestamps8import type { WorkApi } from "./work";
API and MCP server, Rust identity service, registration, site redesign9
10/** A service binding, as far as these clients need it. */
11export type ServiceBinding = {
12 fetch(input: string, init?: RequestInit): Promise<Response>;
13};
14
15/**
16 * Calls a method on a service that speaks the JSON protocol used by the
17 * Rust services: `POST /rpc/<method>` with the arguments as the body.
18 */
19async function rpc<T>(
20 service: ServiceBinding,
21 method: string,
22 args: object,
23): Promise<T> {
24 // The hostname is ignored; a service binding always reaches its service.
25 const response = await service.fetch(`https://service/rpc/${method}`, {
26 method: "POST",
27 headers: { "content-type": "application/json" },
28 body: JSON.stringify(args),
29 });
30 if (!response.ok) {
31 throw new Error(`${method} failed with status ${response.status}`);
32 }
Agents as a team: lifecycle, merge queue, billing and a new shell33 return (await response.json()) as T;
API and MCP server, Rust identity service, registration, site redesign34}
35
36export function identityClient(service: ServiceBinding): IdentityApi {
37 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
38 return {
39 register: (username, email, password) =>
40 call("register", { username, email, password }),
41 signIn: (username, password) => call("sign_in", { username, password }),
42 signOut: (sessionToken) => call("sign_out", { sessionToken }),
Email verification, password reset, and Git for AI scale positioning43 resendVerification: (user) => call("resend_verification", { user }),
44 verifyEmail: (token) => call("verify_email", { token }),
45 requestPasswordReset: (email) => call("request_password_reset", { email }),
46 resetPassword: (token, password) =>
47 call("reset_password", { token, password }),
Device sign-in replaces registering and minting tokens over the API48 deviceStart: (clientName) => call("device_start", { clientName }),
49 deviceLookup: (userCode) => call("device_lookup", { userCode }),
50 deviceResolve: (userCode, user, approve) =>
51 call("device_resolve", { userCode, user, approve }),
52 deviceClaim: (deviceCode) => call("device_claim", { deviceCode }),
OAuth 2.1 sign-in for MCP clients and other applications53 oauthAuthorize: (user, approval) => call("oauth_authorize", { user, ...approval }),
54 oauthExchange: (code, codeVerifier, clientId, redirectUri) =>
55 call("oauth_exchange", { code, codeVerifier, clientId, redirectUri }),
56 oauthRefresh: (refreshToken, clientId) =>
57 call("oauth_refresh", { refreshToken, clientId }),
58 listOAuthGrants: (user) => call("list_oauth_grants", { user }),
59 revokeOAuthGrant: (user, id) => call("revoke_oauth_grant", { user, id }),
Workspaces own repositories60 createWorkspace: (user, slug, name) => call("create_workspace", { user, slug, name }),
61 getWorkspace: (slug) => call("get_workspace", { slug }),
62 listMembers: (slug, viewer) => call("list_members", { slug, viewer }),
63 addMember: (actor, slug, username) => call("add_member", { actor, slug, username }),
64 removeMember: (actor, slug, username) =>
65 call("remove_member", { actor, slug, username }),
Agents as a team: lifecycle, merge queue, billing and a new shell66 updateWorkspace: (actor, slug, details) =>
67 call("update_workspace", { actor, slug, ...details }),
68 listWorkspaceTokens: (slug, viewer) => call("list_workspace_tokens", { slug, viewer }),
69 createWorkspaceToken: (actor, slug, name) =>
70 call("create_workspace_token", { actor, slug, name }),
71 removeWorkspaceToken: (actor, slug, id) =>
72 call("remove_workspace_token", { actor, slug, id }),
API and MCP server, Rust identity service, registration, site redesign73 userForSession: (sessionToken) => call("user_for_session", { sessionToken }),
74 userForGitCredentials: (username, secret) =>
75 call("user_for_git_credentials", { username, secret }),
76 userForAccessToken: (token) => call("user_for_access_token", { token }),
77 userForSshKey: (fingerprint) => call("user_for_ssh_key", { fingerprint }),
78 userByUsername: (username) => call("user_by_username", { username }),
What happened across an outcome, as a feed beside its graph79 usernames: (ids) => call("usernames", { ids }),
API and MCP server, Rust identity service, registration, site redesign80 listSshKeys: (user) => call("list_ssh_keys", { user }),
81 addSshKey: (user, title, publicKey) =>
82 call("add_ssh_key", { user, title, publicKey }),
83 removeSshKey: (user, id) => call("remove_ssh_key", { user, id }),
84 listAccessTokens: (user) => call("list_access_tokens", { user }),
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)85 createAccessToken: (user, name, ttlSeconds) =>
86 call("create_access_token", { user, name, ttlSeconds }),
Agents as a team: lifecycle, merge queue, billing and a new shell87 createAgentToken: (onBehalfOf, scope, ttlSeconds) =>
88 call("create_agent_token", { onBehalfOf, scope, ttlSeconds }),
API and MCP server, Rust identity service, registration, site redesign89 removeAccessToken: (user, id) => call("remove_access_token", { user, id }),
90 };
91}
Rust repos service with shipping; pull requests kept in the model92
93export function reposClient(service: ServiceBinding): ReposApi {
94 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
95 return {
96 get: (path, viewer) => call("get", { path, viewer }),
97 getById: (id, viewer) => call("get_by_id", { id, viewer }),
98 list: (viewer, options = {}) => call("list", { viewer, ...options }),
99 create: (owner, input) => call("create", { owner, ...input }),
Agents as a team: lifecycle, merge queue, billing and a new shell100 update: (actor, path, changes) => call("update", { actor, path, ...changes }),
Rust repos service with shipping; pull requests kept in the model101 tree: (path, viewer, ref, treePath) =>
102 call("tree", { path, viewer, ref, treePath }),
103 blob: (path, viewer, ref, filePath) =>
104 call("blob", { path, viewer, ref, filePath }),
105 log: (path, viewer, ref, limit) => call("log", { path, viewer, ref, limit }),
Agents as a team: lifecycle, merge queue, billing and a new shell106 blame: (path, viewer, ref, filePath) => call("blame", { path, viewer, ref, filePath }),
Issues and pull requests replace intents and attempts107 forkForPull: (sourceId, pullId, actor) =>
108 call("fork_for_pull", { sourceId, pullId, actor }),
Rust repos service with shipping; pull requests kept in the model109 gitAccess: (path, viewer, service) =>
110 call("git_access", { path, viewer, service }),
Pull requests from branches111 branches: (path, viewer) => call("branches", { path, viewer }),
112 land: (sourceId, actor, branch) => call("land", { sourceId, actor, branch }),
113 compare: (repoId, viewer, base, head) => call("compare", { repoId, viewer, base, head }),
Rust repos service with shipping; pull requests kept in the model114 };
115}
Work service in Rust, with RFC 3339 timestamps116
117export function workClient(service: ServiceBinding): WorkApi {
118 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
119 return {
Issues and pull requests replace intents and attempts120 openIssue: (actor, repo, input) => call("open_issue", { actor, repo, ...input }),
121 listIssues: (repo, viewer, filter = {}) => call("list_issues", { repo, viewer, ...filter }),
122 getIssue: (repo, number, viewer) => call("get_issue", { repo, number, viewer }),
123 updateIssue: (actor, repo, number, input) =>
124 call("update_issue", { actor, repo, number, ...input }),
125 closeIssue: (actor, repo, number, reason) =>
126 call("close_issue", { actor, repo, number, reason }),
127 reopenIssue: (actor, repo, number) => call("reopen_issue", { actor, repo, number }),
128 listLabels: (repo, viewer) => call("list_labels", { repo, viewer }),
129 counts: (repo, viewer) => call("counts", { repo, viewer }),
Acceptance checks in sandboxes, line comments and review verdicts130 addComment: (actor, repo, number, comment) =>
131 call("add_comment", { actor, repo, number, ...comment }),
132 startChecks: (pullId) => call("start_checks", { pullId }),
133 reportChecks: (runId, token, report) =>
134 call("report_checks", { runId, token, ...report }),
Agents as a team: lifecycle, merge queue, billing and a new shell135 startReview: (pullId) => call("start_review", { pullId }),
136 failReview: (runId, token, error) => call("report_review", { runId, token, error }),
137 advance: (pullId) => call("advance", { pullId }),
138 stall: (pullId, reason) => call("stall", { pullId, reason }),
139 managedPulls: (repoId) => call("managed_pulls", { repoId }),
140 queue: (repo, viewer) => call("queue", { repo, viewer }),
141 queueBuild: (repoId) => call("queue_build", { repoId }),
142 failQueue: (entryId, token, error) => call("report_queue", { entryId, token, error }),
143 removeFromQueue: (actor, repo, number) => call("remove_from_queue", { actor, repo, number }),
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request144 messageAgent: (actor, repo, number, body) => call("message_agent", { actor, repo, number, body }),
Agents as a team: lifecycle, merge queue, billing and a new shell145 catchUpJob: (pullId) => call("catch_up_job", { pullId }),
146 getSettings: (repo, viewer) => call("get_settings", { repo, viewer }),
147 updateSettings: (actor, repo, settings) =>
148 call("update_settings", { actor, repo, settings }),
Issues and pull requests replace intents and attempts149 openPull: (actor, repo, input) => call("open_pull", { actor, repo, ...input }),
150 listPulls: (repo, viewer, state) => call("list_pulls", { repo, viewer, state }),
151 getPull: (repo, number, viewer) => call("get_pull", { repo, number, viewer }),
Agents as a team: lifecycle, merge queue, billing and a new shell152 updatePull: (actor, repo, number, changes) =>
153 call("update_pull", { actor, repo, number, ...changes }),
Issues and pull requests replace intents and attempts154 readyPull: (actor, repo, number, summary) =>
155 call("ready_pull", { actor, repo, number, summary }),
156 closePull: (actor, repo, number) => call("close_pull", { actor, repo, number }),
Acceptance checks in sandboxes, line comments and review verdicts157 mergePull: (actor, repo, number, options = {}) =>
158 call("merge_pull", { actor, repo, number, ...options }),
Issues and pull requests replace intents and attempts159 listActivePulls: (viewer) => call("list_active_pulls", { viewer }),
Agents as a team: lifecycle, merge queue, billing and a new shell160 startPlan: (actor, repo, brief) => call("start_plan", { actor, repo, brief }),
161 failPlan: (planId, token, error) => call("report_plan", { planId, token, error }),
162 getPlan: (repo, viewer, id) => call("get_plan", { repo, viewer, id }),
163 listPlans: (repo, viewer) => call("list_plans", { repo, viewer }),
164 applyPlan: (actor, repo, id, options = {}) =>
165 call("apply_plan", { actor, repo, id, ...options }),
166 queueIssue: (actor, repo, number, queued) =>
167 call("queue_issue", { actor, repo, number, queued }),
168 readyIssues: (repoId) => call("ready_issues", { repoId }),
169 listAssignedIssues: (viewer) => call("list_assigned_issues", { viewer }),
Issues and pull requests replace intents and attempts170 appendSession: (actor, repo, number, entries) =>
171 call("append_session", { actor, repo, number, entries }),
172 readSession: (repo, number, viewer, afterSeq = 0) =>
173 call("read_session", { repo, number, viewer, afterSeq }),
Work service in Rust, with RFC 3339 timestamps174 };
175}
Events service in Rust, with RFC 3339 times and accurate push events176
Agents as a team: lifecycle, merge queue, billing and a new shell177export function billingClient(service: ServiceBinding): BillingApi {
178 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
179 return {
180 status: () => call("status", {}),
181 account: (workspace, viewer) => call("account", { workspace, viewer }),
182 ledger: (workspace, viewer) => call("ledger", { workspace, viewer }),
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request183 usage: (workspace, viewer, since) => call("usage", { workspace, viewer, since }),
Agents as a team: lifecycle, merge queue, billing and a new shell184 checkout: (actor, workspace, amountCents, returnUrl) =>
185 call("checkout", { actor, workspace, amountCents, returnUrl }),
186 confirm: (workspace, viewer, session) => call("confirm", { workspace, viewer, session }),
187 canStart: (workspace) => call("can_start", { workspace }),
188 startRun: (run) => call("start_run", run),
189 };
190}
191
Events service in Rust, with RFC 3339 times and accurate push events192export function eventsClient(service: ServiceBinding): EventsApi {
193 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
194 return {
195 publish: (events) => call("publish", { events }),
196 list: (query) => call("list", query),
197 };
198}
Integrations: your own model provider, alerts that open issues, tickets agents read199
200export function integrationsClient(service: ServiceBinding): IntegrationsApi {
201 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
202 return {
203 list: (workspace, viewer) => call("list", { workspace, viewer }),
204 connect: (actor, workspace, input) => call("connect", { actor, workspace, ...input }),
205 update: (actor, workspace, id, input) => call("update", { actor, workspace, id, ...input }),
206 disconnect: (actor, workspace, id) => call("disconnect", { actor, workspace, id }),
207 test: (actor, workspace, id) => call("test", { actor, workspace, id }),
208 deliveries: (workspace, viewer, id) => call("deliveries", { workspace, viewer, id }),
209 resolve: (workspace, viewer, reference) => call("resolve", { workspace, viewer, reference }),
210 references: (workspace, text, limit) => call("references", { workspace, text, limit }),
211 import: (actor, repo, reference, assign) => call("import", { actor, repo, reference, assign }),
212 links: (repo, number) => call("links", { repo, number }),
213 modelProvider: (workspace) => call("model_provider", { workspace }),
214 openModelSession: (run) => call("open_model_session", run),
215 modelUpstream: (token) => call("model_upstream", { token }),
Models per workspace: several providers, routed by kind of work216 routes: (workspace, viewer) => call("routes", { workspace, viewer }),
217 setRoutes: (actor, workspace, routes) => call("set_routes", { actor, workspace, routes }),
Integrations: your own model provider, alerts that open issues, tickets agents read218 };
219}
Webhooks: every event, to your own addresses, signed and retried220
221export function webhooksClient(service: ServiceBinding): WebhooksApi {
222 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
223 return {
224 list: (viewer, owner) => call("list", { viewer, ...owner }),
225 create: (actor, owner, input) => call("create", { actor, ...owner, ...input }),
226 update: (actor, owner, id, input) => call("update", { actor, ...owner, id, ...input }),
227 delete: (actor, owner, id) => call("delete", { actor, ...owner, id }),
228 ping: (actor, owner, id) => call("ping", { actor, ...owner, id }),
229 deliveries: (viewer, owner, id) => call("deliveries", { viewer, ...owner, id }),
230 redeliver: (actor, owner, deliveryId) => call("redeliver", { actor, ...owner, deliveryId }),
231 };
232}
Automations: rules in .g1t/automations that act when something happens233
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs234export function actionsClient(service: ServiceBinding): ActionsApi {
235 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
236 return {
237 workflows: (repo, viewer) => call("workflows", { repo, viewer }),
238 runs: (repo, viewer, filter = {}) => call("runs", { repo, viewer, ...filter }),
239 run: (repo, viewer, id) => call("run", { repo, viewer, id }),
240 logs: (repo, viewer, job, after = 0) => call("logs", { repo, viewer, job, after }),
241 dispatch: (actor, repo, workflow, ref, inputs) => call("dispatch", { actor, repo, workflow, ref, inputs }),
242 cancel: (actor, repo, id) => call("cancel", { actor, repo, id }),
243 rerun: (actor, repo, id, failedOnly = false) => call("rerun", { actor, repo, id, failed_only: failedOnly }),
244 setWorkflowEnabled: (actor, repo, workflow, enabled) =>
245 call("set_workflow_enabled", { actor, repo, workflow, enabled }),
246 settings: (actor, owner, kind) => call("settings", { actor, ...owner, kind }),
247 setSetting: (actor, owner, kind, name, value) => call("set_setting", { actor, ...owner, kind, name, value }),
248 deleteSetting: (actor, owner, kind, name) => call("delete_setting", { actor, ...owner, kind, name }),
249 };
250}
251