g1t/packages/contracts/src/clients.ts

277 lines15,731 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";
Deployments: a preview for every pull request, production on g1t.page3import type { DeploymentsApi } from "./deployments";
Events service in Rust, with RFC 3339 times and accurate push events4import type { EventsApi } from "./events";
API and MCP server, Rust identity service, registration, site redesign5import type { IdentityApi } from "./identity";
Integrations: your own model provider, alerts that open issues, tickets agents read6import type { IntegrationsApi } from "./integrations";
Webhooks: every event, to your own addresses, signed and retried7import type { WebhooksApi } from "./webhooks";
Rust repos service with shipping; pull requests kept in the model8import type { ReposApi } from "./repos";
Work service in Rust, with RFC 3339 timestamps9import type { WorkApi } from "./work";
API and MCP server, Rust identity service, registration, site redesign10
11/** A service binding, as far as these clients need it. */
12export type ServiceBinding = {
13 fetch(input: string, init?: RequestInit): Promise<Response>;
14};
15
16/**
17 * Calls a method on a service that speaks the JSON protocol used by the
18 * Rust services: `POST /rpc/<method>` with the arguments as the body.
19 */
20async function rpc<T>(
21 service: ServiceBinding,
22 method: string,
23 args: object,
24): Promise<T> {
25 // The hostname is ignored; a service binding always reaches its service.
26 const response = await service.fetch(`https://service/rpc/${method}`, {
27 method: "POST",
28 headers: { "content-type": "application/json" },
29 body: JSON.stringify(args),
30 });
31 if (!response.ok) {
32 throw new Error(`${method} failed with status ${response.status}`);
33 }
Agents as a team: lifecycle, merge queue, billing and a new shell34 return (await response.json()) as T;
API and MCP server, Rust identity service, registration, site redesign35}
36
37export function identityClient(service: ServiceBinding): IdentityApi {
38 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
39 return {
40 register: (username, email, password) =>
41 call("register", { username, email, password }),
42 signIn: (username, password) => call("sign_in", { username, password }),
43 signOut: (sessionToken) => call("sign_out", { sessionToken }),
Email verification, password reset, and Git for AI scale positioning44 resendVerification: (user) => call("resend_verification", { user }),
45 verifyEmail: (token) => call("verify_email", { token }),
46 requestPasswordReset: (email) => call("request_password_reset", { email }),
47 resetPassword: (token, password) =>
48 call("reset_password", { token, password }),
Device sign-in replaces registering and minting tokens over the API49 deviceStart: (clientName) => call("device_start", { clientName }),
50 deviceLookup: (userCode) => call("device_lookup", { userCode }),
51 deviceResolve: (userCode, user, approve) =>
52 call("device_resolve", { userCode, user, approve }),
53 deviceClaim: (deviceCode) => call("device_claim", { deviceCode }),
OAuth 2.1 sign-in for MCP clients and other applications54 oauthAuthorize: (user, approval) => call("oauth_authorize", { user, ...approval }),
55 oauthExchange: (code, codeVerifier, clientId, redirectUri) =>
56 call("oauth_exchange", { code, codeVerifier, clientId, redirectUri }),
57 oauthRefresh: (refreshToken, clientId) =>
58 call("oauth_refresh", { refreshToken, clientId }),
59 listOAuthGrants: (user) => call("list_oauth_grants", { user }),
60 revokeOAuthGrant: (user, id) => call("revoke_oauth_grant", { user, id }),
Workspaces own repositories61 createWorkspace: (user, slug, name) => call("create_workspace", { user, slug, name }),
62 getWorkspace: (slug) => call("get_workspace", { slug }),
63 listMembers: (slug, viewer) => call("list_members", { slug, viewer }),
64 addMember: (actor, slug, username) => call("add_member", { actor, slug, username }),
65 removeMember: (actor, slug, username) =>
66 call("remove_member", { actor, slug, username }),
Agents as a team: lifecycle, merge queue, billing and a new shell67 updateWorkspace: (actor, slug, details) =>
68 call("update_workspace", { actor, slug, ...details }),
69 listWorkspaceTokens: (slug, viewer) => call("list_workspace_tokens", { slug, viewer }),
70 createWorkspaceToken: (actor, slug, name) =>
71 call("create_workspace_token", { actor, slug, name }),
72 removeWorkspaceToken: (actor, slug, id) =>
73 call("remove_workspace_token", { actor, slug, id }),
API and MCP server, Rust identity service, registration, site redesign74 userForSession: (sessionToken) => call("user_for_session", { sessionToken }),
75 userForGitCredentials: (username, secret) =>
76 call("user_for_git_credentials", { username, secret }),
77 userForAccessToken: (token) => call("user_for_access_token", { token }),
78 userForSshKey: (fingerprint) => call("user_for_ssh_key", { fingerprint }),
79 userByUsername: (username) => call("user_by_username", { username }),
What happened across an outcome, as a feed beside its graph80 usernames: (ids) => call("usernames", { ids }),
API and MCP server, Rust identity service, registration, site redesign81 listSshKeys: (user) => call("list_ssh_keys", { user }),
82 addSshKey: (user, title, publicKey) =>
83 call("add_ssh_key", { user, title, publicKey }),
84 removeSshKey: (user, id) => call("remove_ssh_key", { user, id }),
85 listAccessTokens: (user) => call("list_access_tokens", { user }),
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)86 createAccessToken: (user, name, ttlSeconds) =>
87 call("create_access_token", { user, name, ttlSeconds }),
Agents as a team: lifecycle, merge queue, billing and a new shell88 createAgentToken: (onBehalfOf, scope, ttlSeconds) =>
89 call("create_agent_token", { onBehalfOf, scope, ttlSeconds }),
API and MCP server, Rust identity service, registration, site redesign90 removeAccessToken: (user, id) => call("remove_access_token", { user, id }),
91 };
92}
Rust repos service with shipping; pull requests kept in the model93
94export function reposClient(service: ServiceBinding): ReposApi {
95 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
96 return {
97 get: (path, viewer) => call("get", { path, viewer }),
98 getById: (id, viewer) => call("get_by_id", { id, viewer }),
99 list: (viewer, options = {}) => call("list", { viewer, ...options }),
100 create: (owner, input) => call("create", { owner, ...input }),
Agents as a team: lifecycle, merge queue, billing and a new shell101 update: (actor, path, changes) => call("update", { actor, path, ...changes }),
Rust repos service with shipping; pull requests kept in the model102 tree: (path, viewer, ref, treePath) =>
103 call("tree", { path, viewer, ref, treePath }),
104 blob: (path, viewer, ref, filePath) =>
105 call("blob", { path, viewer, ref, filePath }),
106 log: (path, viewer, ref, limit) => call("log", { path, viewer, ref, limit }),
Agents as a team: lifecycle, merge queue, billing and a new shell107 blame: (path, viewer, ref, filePath) => call("blame", { path, viewer, ref, filePath }),
Issues and pull requests replace intents and attempts108 forkForPull: (sourceId, pullId, actor) =>
109 call("fork_for_pull", { sourceId, pullId, actor }),
Rust repos service with shipping; pull requests kept in the model110 gitAccess: (path, viewer, service) =>
111 call("git_access", { path, viewer, service }),
Pull requests from branches112 branches: (path, viewer) => call("branches", { path, viewer }),
113 land: (sourceId, actor, branch) => call("land", { sourceId, actor, branch }),
114 compare: (repoId, viewer, base, head) => call("compare", { repoId, viewer, base, head }),
Rust repos service with shipping; pull requests kept in the model115 };
116}
Work service in Rust, with RFC 3339 timestamps117
118export function workClient(service: ServiceBinding): WorkApi {
119 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
120 return {
Issues and pull requests replace intents and attempts121 openIssue: (actor, repo, input) => call("open_issue", { actor, repo, ...input }),
122 listIssues: (repo, viewer, filter = {}) => call("list_issues", { repo, viewer, ...filter }),
123 getIssue: (repo, number, viewer) => call("get_issue", { repo, number, viewer }),
124 updateIssue: (actor, repo, number, input) =>
125 call("update_issue", { actor, repo, number, ...input }),
126 closeIssue: (actor, repo, number, reason) =>
127 call("close_issue", { actor, repo, number, reason }),
128 reopenIssue: (actor, repo, number) => call("reopen_issue", { actor, repo, number }),
129 listLabels: (repo, viewer) => call("list_labels", { repo, viewer }),
130 counts: (repo, viewer) => call("counts", { repo, viewer }),
Acceptance checks in sandboxes, line comments and review verdicts131 addComment: (actor, repo, number, comment) =>
132 call("add_comment", { actor, repo, number, ...comment }),
133 startChecks: (pullId) => call("start_checks", { pullId }),
134 reportChecks: (runId, token, report) =>
135 call("report_checks", { runId, token, ...report }),
Agents as a team: lifecycle, merge queue, billing and a new shell136 startReview: (pullId) => call("start_review", { pullId }),
137 failReview: (runId, token, error) => call("report_review", { runId, token, error }),
138 advance: (pullId) => call("advance", { pullId }),
139 stall: (pullId, reason) => call("stall", { pullId, reason }),
140 managedPulls: (repoId) => call("managed_pulls", { repoId }),
141 queue: (repo, viewer) => call("queue", { repo, viewer }),
142 queueBuild: (repoId) => call("queue_build", { repoId }),
143 failQueue: (entryId, token, error) => call("report_queue", { entryId, token, error }),
144 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 request145 messageAgent: (actor, repo, number, body) => call("message_agent", { actor, repo, number, body }),
Agents as a team: lifecycle, merge queue, billing and a new shell146 catchUpJob: (pullId) => call("catch_up_job", { pullId }),
Agents asked while not at work are woken to answer147 wakeForMessages: (pullId) => call("wake_for_messages", { pullId }),
Agents as a team: lifecycle, merge queue, billing and a new shell148 getSettings: (repo, viewer) => call("get_settings", { repo, viewer }),
149 updateSettings: (actor, repo, settings) =>
150 call("update_settings", { actor, repo, settings }),
Issues and pull requests replace intents and attempts151 openPull: (actor, repo, input) => call("open_pull", { actor, repo, ...input }),
152 listPulls: (repo, viewer, state) => call("list_pulls", { repo, viewer, state }),
153 getPull: (repo, number, viewer) => call("get_pull", { repo, number, viewer }),
Agents as a team: lifecycle, merge queue, billing and a new shell154 updatePull: (actor, repo, number, changes) =>
155 call("update_pull", { actor, repo, number, ...changes }),
Issues and pull requests replace intents and attempts156 readyPull: (actor, repo, number, summary) =>
157 call("ready_pull", { actor, repo, number, summary }),
158 closePull: (actor, repo, number) => call("close_pull", { actor, repo, number }),
Acceptance checks in sandboxes, line comments and review verdicts159 mergePull: (actor, repo, number, options = {}) =>
160 call("merge_pull", { actor, repo, number, ...options }),
Issues and pull requests replace intents and attempts161 listActivePulls: (viewer) => call("list_active_pulls", { viewer }),
Agents as a team: lifecycle, merge queue, billing and a new shell162 startPlan: (actor, repo, brief) => call("start_plan", { actor, repo, brief }),
163 failPlan: (planId, token, error) => call("report_plan", { planId, token, error }),
164 getPlan: (repo, viewer, id) => call("get_plan", { repo, viewer, id }),
165 listPlans: (repo, viewer) => call("list_plans", { repo, viewer }),
166 applyPlan: (actor, repo, id, options = {}) =>
167 call("apply_plan", { actor, repo, id, ...options }),
168 queueIssue: (actor, repo, number, queued) =>
169 call("queue_issue", { actor, repo, number, queued }),
170 readyIssues: (repoId) => call("ready_issues", { repoId }),
171 listAssignedIssues: (viewer) => call("list_assigned_issues", { viewer }),
Issues and pull requests replace intents and attempts172 appendSession: (actor, repo, number, entries) =>
173 call("append_session", { actor, repo, number, entries }),
174 readSession: (repo, number, viewer, afterSeq = 0) =>
175 call("read_session", { repo, number, viewer, afterSeq }),
Work service in Rust, with RFC 3339 timestamps176 };
177}
Events service in Rust, with RFC 3339 times and accurate push events178
Agents as a team: lifecycle, merge queue, billing and a new shell179export function billingClient(service: ServiceBinding): BillingApi {
180 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
181 return {
182 status: () => call("status", {}),
183 account: (workspace, viewer) => call("account", { workspace, viewer }),
184 ledger: (workspace, viewer) => call("ledger", { workspace, viewer }),
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request185 usage: (workspace, viewer, since) => call("usage", { workspace, viewer, since }),
Agents as a team: lifecycle, merge queue, billing and a new shell186 checkout: (actor, workspace, amountCents, returnUrl) =>
187 call("checkout", { actor, workspace, amountCents, returnUrl }),
188 confirm: (workspace, viewer, session) => call("confirm", { workspace, viewer, session }),
189 canStart: (workspace) => call("can_start", { workspace }),
A free allowance on g1t's models, so anyone can try its agents190 trial: (workspace, exempt) => call("trial", { workspace, exempt }),
Agents as a team: lifecycle, merge queue, billing and a new shell191 startRun: (run) => call("start_run", run),
Paid features: a workspace turns on Deployments with a monthly plan192 features: (workspace, viewer) => call("features", { workspace, viewer }),
193 subscribe: (actor, workspace, feature, returnUrl) =>
194 call("subscribe", { actor, workspace, feature, returnUrl }),
195 confirmSubscription: (workspace, viewer, session) =>
196 call("confirm_subscription", { workspace, viewer, session }),
197 cancelSubscription: (actor, workspace, feature, resume = false) =>
198 call("cancel_subscription", { actor, workspace, feature, resume }),
199 hasFeature: (workspace, feature) => call("has_feature", { workspace, feature }),
200 chargeFeature: (charge) => call("charge_feature", charge),
Agents as a team: lifecycle, merge queue, billing and a new shell201 };
202}
203
Events service in Rust, with RFC 3339 times and accurate push events204export function eventsClient(service: ServiceBinding): EventsApi {
205 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
206 return {
207 publish: (events) => call("publish", { events }),
208 list: (query) => call("list", query),
209 };
210}
Integrations: your own model provider, alerts that open issues, tickets agents read211
212export function integrationsClient(service: ServiceBinding): IntegrationsApi {
213 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
214 return {
215 list: (workspace, viewer) => call("list", { workspace, viewer }),
216 connect: (actor, workspace, input) => call("connect", { actor, workspace, ...input }),
217 update: (actor, workspace, id, input) => call("update", { actor, workspace, id, ...input }),
218 disconnect: (actor, workspace, id) => call("disconnect", { actor, workspace, id }),
219 test: (actor, workspace, id) => call("test", { actor, workspace, id }),
220 deliveries: (workspace, viewer, id) => call("deliveries", { workspace, viewer, id }),
221 resolve: (workspace, viewer, reference) => call("resolve", { workspace, viewer, reference }),
222 references: (workspace, text, limit) => call("references", { workspace, text, limit }),
223 import: (actor, repo, reference, assign) => call("import", { actor, repo, reference, assign }),
224 links: (repo, number) => call("links", { repo, number }),
225 modelProvider: (workspace) => call("model_provider", { workspace }),
226 openModelSession: (run) => call("open_model_session", run),
227 modelUpstream: (token) => call("model_upstream", { token }),
Models per workspace: several providers, routed by kind of work228 routes: (workspace, viewer) => call("routes", { workspace, viewer }),
229 setRoutes: (actor, workspace, routes) => call("set_routes", { actor, workspace, routes }),
Integrations: your own model provider, alerts that open issues, tickets agents read230 };
231}
Webhooks: every event, to your own addresses, signed and retried232
233export function webhooksClient(service: ServiceBinding): WebhooksApi {
234 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
235 return {
236 list: (viewer, owner) => call("list", { viewer, ...owner }),
237 create: (actor, owner, input) => call("create", { actor, ...owner, ...input }),
238 update: (actor, owner, id, input) => call("update", { actor, ...owner, id, ...input }),
239 delete: (actor, owner, id) => call("delete", { actor, ...owner, id }),
240 ping: (actor, owner, id) => call("ping", { actor, ...owner, id }),
241 deliveries: (viewer, owner, id) => call("deliveries", { viewer, ...owner, id }),
242 redeliver: (actor, owner, deliveryId) => call("redeliver", { actor, ...owner, deliveryId }),
243 };
244}
Automations: rules in .g1t/automations that act when something happens245
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs246export function actionsClient(service: ServiceBinding): ActionsApi {
247 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
248 return {
249 workflows: (repo, viewer) => call("workflows", { repo, viewer }),
250 runs: (repo, viewer, filter = {}) => call("runs", { repo, viewer, ...filter }),
251 run: (repo, viewer, id) => call("run", { repo, viewer, id }),
252 logs: (repo, viewer, job, after = 0) => call("logs", { repo, viewer, job, after }),
253 dispatch: (actor, repo, workflow, ref, inputs) => call("dispatch", { actor, repo, workflow, ref, inputs }),
254 cancel: (actor, repo, id) => call("cancel", { actor, repo, id }),
255 rerun: (actor, repo, id, failedOnly = false) => call("rerun", { actor, repo, id, failed_only: failedOnly }),
256 setWorkflowEnabled: (actor, repo, workflow, enabled) =>
257 call("set_workflow_enabled", { actor, repo, workflow, enabled }),
258 settings: (actor, owner, kind) => call("settings", { actor, ...owner, kind }),
Secrets and variables: one list, rows per environment, for workflows and deployments259 setSetting: (actor, owner, kind, name, value, options = {}) =>
260 call("set_setting", { actor, ...owner, kind, name, value, ...options }),
261 deleteSetting: (actor, owner, kind, name, id) => call("delete_setting", { actor, ...owner, kind, name, id }),
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs262 };
263}
264
Deployments: a preview for every pull request, production on g1t.page265
266export function deploymentsClient(service: ServiceBinding): DeploymentsApi {
267 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
268 return {
269 settings: (repo, viewer) => call("settings", { repo, viewer }),
270 updateSettings: (actor, repo, changes) => call("update_settings", { actor, repo, changes }),
271 list: (repo, viewer) => call("list", { repo, viewer }),
272 get: (repo, id, viewer) => call("get", { repo, id, viewer }),
273 redeploy: (actor, repo, number) => call("redeploy", { actor, repo, number }),
274 takeDown: (actor, repo, number) => call("take_down", { actor, repo, number }),
275 usage: (workspace, viewer) => call("usage", { workspace, viewer }),
276 };
277}