g1t/packages/contracts/src/clients.ts

262 lines14,931 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 }),
Agents asked while not at work are woken to answer146 wakeForMessages: (pullId) => call("wake_for_messages", { pullId }),
Agents as a team: lifecycle, merge queue, billing and a new shell147 getSettings: (repo, viewer) => call("get_settings", { repo, viewer }),
148 updateSettings: (actor, repo, settings) =>
149 call("update_settings", { actor, repo, settings }),
Issues and pull requests replace intents and attempts150 openPull: (actor, repo, input) => call("open_pull", { actor, repo, ...input }),
151 listPulls: (repo, viewer, state) => call("list_pulls", { repo, viewer, state }),
152 getPull: (repo, number, viewer) => call("get_pull", { repo, number, viewer }),
Agents as a team: lifecycle, merge queue, billing and a new shell153 updatePull: (actor, repo, number, changes) =>
154 call("update_pull", { actor, repo, number, ...changes }),
Issues and pull requests replace intents and attempts155 readyPull: (actor, repo, number, summary) =>
156 call("ready_pull", { actor, repo, number, summary }),
157 closePull: (actor, repo, number) => call("close_pull", { actor, repo, number }),
Acceptance checks in sandboxes, line comments and review verdicts158 mergePull: (actor, repo, number, options = {}) =>
159 call("merge_pull", { actor, repo, number, ...options }),
Issues and pull requests replace intents and attempts160 listActivePulls: (viewer) => call("list_active_pulls", { viewer }),
Agents as a team: lifecycle, merge queue, billing and a new shell161 startPlan: (actor, repo, brief) => call("start_plan", { actor, repo, brief }),
162 failPlan: (planId, token, error) => call("report_plan", { planId, token, error }),
163 getPlan: (repo, viewer, id) => call("get_plan", { repo, viewer, id }),
164 listPlans: (repo, viewer) => call("list_plans", { repo, viewer }),
165 applyPlan: (actor, repo, id, options = {}) =>
166 call("apply_plan", { actor, repo, id, ...options }),
167 queueIssue: (actor, repo, number, queued) =>
168 call("queue_issue", { actor, repo, number, queued }),
169 readyIssues: (repoId) => call("ready_issues", { repoId }),
170 listAssignedIssues: (viewer) => call("list_assigned_issues", { viewer }),
Issues and pull requests replace intents and attempts171 appendSession: (actor, repo, number, entries) =>
172 call("append_session", { actor, repo, number, entries }),
173 readSession: (repo, number, viewer, afterSeq = 0) =>
174 call("read_session", { repo, number, viewer, afterSeq }),
Work service in Rust, with RFC 3339 timestamps175 };
176}
Events service in Rust, with RFC 3339 times and accurate push events177
Agents as a team: lifecycle, merge queue, billing and a new shell178export function billingClient(service: ServiceBinding): BillingApi {
179 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
180 return {
181 status: () => call("status", {}),
182 account: (workspace, viewer) => call("account", { workspace, viewer }),
183 ledger: (workspace, viewer) => call("ledger", { workspace, viewer }),
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request184 usage: (workspace, viewer, since) => call("usage", { workspace, viewer, since }),
Agents as a team: lifecycle, merge queue, billing and a new shell185 checkout: (actor, workspace, amountCents, returnUrl) =>
186 call("checkout", { actor, workspace, amountCents, returnUrl }),
187 confirm: (workspace, viewer, session) => call("confirm", { workspace, viewer, session }),
188 canStart: (workspace) => call("can_start", { workspace }),
A free allowance on g1t's models, so anyone can try its agents189 trial: (workspace, exempt) => call("trial", { workspace, exempt }),
Agents as a team: lifecycle, merge queue, billing and a new shell190 startRun: (run) => call("start_run", run),
Paid features: a workspace turns on Deployments with a monthly plan191 features: (workspace, viewer) => call("features", { workspace, viewer }),
192 subscribe: (actor, workspace, feature, returnUrl) =>
193 call("subscribe", { actor, workspace, feature, returnUrl }),
194 confirmSubscription: (workspace, viewer, session) =>
195 call("confirm_subscription", { workspace, viewer, session }),
196 cancelSubscription: (actor, workspace, feature, resume = false) =>
197 call("cancel_subscription", { actor, workspace, feature, resume }),
198 hasFeature: (workspace, feature) => call("has_feature", { workspace, feature }),
199 chargeFeature: (charge) => call("charge_feature", charge),
Agents as a team: lifecycle, merge queue, billing and a new shell200 };
201}
202
Events service in Rust, with RFC 3339 times and accurate push events203export function eventsClient(service: ServiceBinding): EventsApi {
204 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
205 return {
206 publish: (events) => call("publish", { events }),
207 list: (query) => call("list", query),
208 };
209}
Integrations: your own model provider, alerts that open issues, tickets agents read210
211export function integrationsClient(service: ServiceBinding): IntegrationsApi {
212 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
213 return {
214 list: (workspace, viewer) => call("list", { workspace, viewer }),
215 connect: (actor, workspace, input) => call("connect", { actor, workspace, ...input }),
216 update: (actor, workspace, id, input) => call("update", { actor, workspace, id, ...input }),
217 disconnect: (actor, workspace, id) => call("disconnect", { actor, workspace, id }),
218 test: (actor, workspace, id) => call("test", { actor, workspace, id }),
219 deliveries: (workspace, viewer, id) => call("deliveries", { workspace, viewer, id }),
220 resolve: (workspace, viewer, reference) => call("resolve", { workspace, viewer, reference }),
221 references: (workspace, text, limit) => call("references", { workspace, text, limit }),
222 import: (actor, repo, reference, assign) => call("import", { actor, repo, reference, assign }),
223 links: (repo, number) => call("links", { repo, number }),
224 modelProvider: (workspace) => call("model_provider", { workspace }),
225 openModelSession: (run) => call("open_model_session", run),
226 modelUpstream: (token) => call("model_upstream", { token }),
Models per workspace: several providers, routed by kind of work227 routes: (workspace, viewer) => call("routes", { workspace, viewer }),
228 setRoutes: (actor, workspace, routes) => call("set_routes", { actor, workspace, routes }),
Integrations: your own model provider, alerts that open issues, tickets agents read229 };
230}
Webhooks: every event, to your own addresses, signed and retried231
232export function webhooksClient(service: ServiceBinding): WebhooksApi {
233 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
234 return {
235 list: (viewer, owner) => call("list", { viewer, ...owner }),
236 create: (actor, owner, input) => call("create", { actor, ...owner, ...input }),
237 update: (actor, owner, id, input) => call("update", { actor, ...owner, id, ...input }),
238 delete: (actor, owner, id) => call("delete", { actor, ...owner, id }),
239 ping: (actor, owner, id) => call("ping", { actor, ...owner, id }),
240 deliveries: (viewer, owner, id) => call("deliveries", { viewer, ...owner, id }),
241 redeliver: (actor, owner, deliveryId) => call("redeliver", { actor, ...owner, deliveryId }),
242 };
243}
Automations: rules in .g1t/automations that act when something happens244
GitHub Actions on g1t, part three: .g1t/workflows, the pages, the docs245export function actionsClient(service: ServiceBinding): ActionsApi {
246 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
247 return {
248 workflows: (repo, viewer) => call("workflows", { repo, viewer }),
249 runs: (repo, viewer, filter = {}) => call("runs", { repo, viewer, ...filter }),
250 run: (repo, viewer, id) => call("run", { repo, viewer, id }),
251 logs: (repo, viewer, job, after = 0) => call("logs", { repo, viewer, job, after }),
252 dispatch: (actor, repo, workflow, ref, inputs) => call("dispatch", { actor, repo, workflow, ref, inputs }),
253 cancel: (actor, repo, id) => call("cancel", { actor, repo, id }),
254 rerun: (actor, repo, id, failedOnly = false) => call("rerun", { actor, repo, id, failed_only: failedOnly }),
255 setWorkflowEnabled: (actor, repo, workflow, enabled) =>
256 call("set_workflow_enabled", { actor, repo, workflow, enabled }),
257 settings: (actor, owner, kind) => call("settings", { actor, ...owner, kind }),
258 setSetting: (actor, owner, kind, name, value) => call("set_setting", { actor, ...owner, kind, name, value }),
259 deleteSetting: (actor, owner, kind, name) => call("delete_setting", { actor, ...owner, kind, name }),
260 };
261}
262