g1t/packages/contracts/src/clients.ts

231 lines12,912 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";
Integrations: your own model provider, alerts that open issues, tickets agents read4import type { IntegrationsApi } from "./integrations";
Webhooks: every event, to your own addresses, signed and retried5import type { WebhooksApi } from "./webhooks";
Rust repos service with shipping; pull requests kept in the model6import type { ReposApi } from "./repos";
Work service in Rust, with RFC 3339 timestamps7import type { WorkApi } from "./work";
API and MCP server, Rust identity service, registration, site redesign8
9/** A service binding, as far as these clients need it. */
10export type ServiceBinding = {
11 fetch(input: string, init?: RequestInit): Promise<Response>;
12};
13
14/**
15 * Calls a method on a service that speaks the JSON protocol used by the
16 * Rust services: `POST /rpc/<method>` with the arguments as the body.
17 */
18async function rpc<T>(
19 service: ServiceBinding,
20 method: string,
21 args: object,
22): Promise<T> {
23 // The hostname is ignored; a service binding always reaches its service.
24 const response = await service.fetch(`https://service/rpc/${method}`, {
25 method: "POST",
26 headers: { "content-type": "application/json" },
27 body: JSON.stringify(args),
28 });
29 if (!response.ok) {
30 throw new Error(`${method} failed with status ${response.status}`);
31 }
Agents as a team: lifecycle, merge queue, billing and a new shell32 return (await response.json()) as T;
API and MCP server, Rust identity service, registration, site redesign33}
34
35export function identityClient(service: ServiceBinding): IdentityApi {
36 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
37 return {
38 register: (username, email, password) =>
39 call("register", { username, email, password }),
40 signIn: (username, password) => call("sign_in", { username, password }),
41 signOut: (sessionToken) => call("sign_out", { sessionToken }),
Email verification, password reset, and Git for AI scale positioning42 resendVerification: (user) => call("resend_verification", { user }),
43 verifyEmail: (token) => call("verify_email", { token }),
44 requestPasswordReset: (email) => call("request_password_reset", { email }),
45 resetPassword: (token, password) =>
46 call("reset_password", { token, password }),
Device sign-in replaces registering and minting tokens over the API47 deviceStart: (clientName) => call("device_start", { clientName }),
48 deviceLookup: (userCode) => call("device_lookup", { userCode }),
49 deviceResolve: (userCode, user, approve) =>
50 call("device_resolve", { userCode, user, approve }),
51 deviceClaim: (deviceCode) => call("device_claim", { deviceCode }),
OAuth 2.1 sign-in for MCP clients and other applications52 oauthAuthorize: (user, approval) => call("oauth_authorize", { user, ...approval }),
53 oauthExchange: (code, codeVerifier, clientId, redirectUri) =>
54 call("oauth_exchange", { code, codeVerifier, clientId, redirectUri }),
55 oauthRefresh: (refreshToken, clientId) =>
56 call("oauth_refresh", { refreshToken, clientId }),
57 listOAuthGrants: (user) => call("list_oauth_grants", { user }),
58 revokeOAuthGrant: (user, id) => call("revoke_oauth_grant", { user, id }),
Workspaces own repositories59 createWorkspace: (user, slug, name) => call("create_workspace", { user, slug, name }),
60 getWorkspace: (slug) => call("get_workspace", { slug }),
61 listMembers: (slug, viewer) => call("list_members", { slug, viewer }),
62 addMember: (actor, slug, username) => call("add_member", { actor, slug, username }),
63 removeMember: (actor, slug, username) =>
64 call("remove_member", { actor, slug, username }),
Agents as a team: lifecycle, merge queue, billing and a new shell65 updateWorkspace: (actor, slug, details) =>
66 call("update_workspace", { actor, slug, ...details }),
67 listWorkspaceTokens: (slug, viewer) => call("list_workspace_tokens", { slug, viewer }),
68 createWorkspaceToken: (actor, slug, name) =>
69 call("create_workspace_token", { actor, slug, name }),
70 removeWorkspaceToken: (actor, slug, id) =>
71 call("remove_workspace_token", { actor, slug, id }),
API and MCP server, Rust identity service, registration, site redesign72 userForSession: (sessionToken) => call("user_for_session", { sessionToken }),
73 userForGitCredentials: (username, secret) =>
74 call("user_for_git_credentials", { username, secret }),
75 userForAccessToken: (token) => call("user_for_access_token", { token }),
76 userForSshKey: (fingerprint) => call("user_for_ssh_key", { fingerprint }),
77 userByUsername: (username) => call("user_by_username", { username }),
What happened across an outcome, as a feed beside its graph78 usernames: (ids) => call("usernames", { ids }),
API and MCP server, Rust identity service, registration, site redesign79 listSshKeys: (user) => call("list_ssh_keys", { user }),
80 addSshKey: (user, title, publicKey) =>
81 call("add_ssh_key", { user, title, publicKey }),
82 removeSshKey: (user, id) => call("remove_ssh_key", { user, id }),
83 listAccessTokens: (user) => call("list_access_tokens", { user }),
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)84 createAccessToken: (user, name, ttlSeconds) =>
85 call("create_access_token", { user, name, ttlSeconds }),
Agents as a team: lifecycle, merge queue, billing and a new shell86 createAgentToken: (onBehalfOf, scope, ttlSeconds) =>
87 call("create_agent_token", { onBehalfOf, scope, ttlSeconds }),
API and MCP server, Rust identity service, registration, site redesign88 removeAccessToken: (user, id) => call("remove_access_token", { user, id }),
89 };
90}
Rust repos service with shipping; pull requests kept in the model91
92export function reposClient(service: ServiceBinding): ReposApi {
93 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
94 return {
95 get: (path, viewer) => call("get", { path, viewer }),
96 getById: (id, viewer) => call("get_by_id", { id, viewer }),
97 list: (viewer, options = {}) => call("list", { viewer, ...options }),
98 create: (owner, input) => call("create", { owner, ...input }),
Agents as a team: lifecycle, merge queue, billing and a new shell99 update: (actor, path, changes) => call("update", { actor, path, ...changes }),
Rust repos service with shipping; pull requests kept in the model100 tree: (path, viewer, ref, treePath) =>
101 call("tree", { path, viewer, ref, treePath }),
102 blob: (path, viewer, ref, filePath) =>
103 call("blob", { path, viewer, ref, filePath }),
104 log: (path, viewer, ref, limit) => call("log", { path, viewer, ref, limit }),
Agents as a team: lifecycle, merge queue, billing and a new shell105 blame: (path, viewer, ref, filePath) => call("blame", { path, viewer, ref, filePath }),
Issues and pull requests replace intents and attempts106 forkForPull: (sourceId, pullId, actor) =>
107 call("fork_for_pull", { sourceId, pullId, actor }),
Rust repos service with shipping; pull requests kept in the model108 gitAccess: (path, viewer, service) =>
109 call("git_access", { path, viewer, service }),
Pull requests from branches110 branches: (path, viewer) => call("branches", { path, viewer }),
111 land: (sourceId, actor, branch) => call("land", { sourceId, actor, branch }),
112 compare: (repoId, viewer, base, head) => call("compare", { repoId, viewer, base, head }),
Rust repos service with shipping; pull requests kept in the model113 };
114}
Work service in Rust, with RFC 3339 timestamps115
116export function workClient(service: ServiceBinding): WorkApi {
117 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
118 return {
Issues and pull requests replace intents and attempts119 openIssue: (actor, repo, input) => call("open_issue", { actor, repo, ...input }),
120 listIssues: (repo, viewer, filter = {}) => call("list_issues", { repo, viewer, ...filter }),
121 getIssue: (repo, number, viewer) => call("get_issue", { repo, number, viewer }),
122 updateIssue: (actor, repo, number, input) =>
123 call("update_issue", { actor, repo, number, ...input }),
124 closeIssue: (actor, repo, number, reason) =>
125 call("close_issue", { actor, repo, number, reason }),
126 reopenIssue: (actor, repo, number) => call("reopen_issue", { actor, repo, number }),
127 listLabels: (repo, viewer) => call("list_labels", { repo, viewer }),
128 counts: (repo, viewer) => call("counts", { repo, viewer }),
Acceptance checks in sandboxes, line comments and review verdicts129 addComment: (actor, repo, number, comment) =>
130 call("add_comment", { actor, repo, number, ...comment }),
131 startChecks: (pullId) => call("start_checks", { pullId }),
132 reportChecks: (runId, token, report) =>
133 call("report_checks", { runId, token, ...report }),
Agents as a team: lifecycle, merge queue, billing and a new shell134 startReview: (pullId) => call("start_review", { pullId }),
135 failReview: (runId, token, error) => call("report_review", { runId, token, error }),
136 advance: (pullId) => call("advance", { pullId }),
137 stall: (pullId, reason) => call("stall", { pullId, reason }),
138 managedPulls: (repoId) => call("managed_pulls", { repoId }),
139 queue: (repo, viewer) => call("queue", { repo, viewer }),
140 queueBuild: (repoId) => call("queue_build", { repoId }),
141 failQueue: (entryId, token, error) => call("report_queue", { entryId, token, error }),
142 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 request143 messageAgent: (actor, repo, number, body) => call("message_agent", { actor, repo, number, body }),
Agents as a team: lifecycle, merge queue, billing and a new shell144 catchUpJob: (pullId) => call("catch_up_job", { pullId }),
145 getSettings: (repo, viewer) => call("get_settings", { repo, viewer }),
146 updateSettings: (actor, repo, settings) =>
147 call("update_settings", { actor, repo, settings }),
Issues and pull requests replace intents and attempts148 openPull: (actor, repo, input) => call("open_pull", { actor, repo, ...input }),
149 listPulls: (repo, viewer, state) => call("list_pulls", { repo, viewer, state }),
150 getPull: (repo, number, viewer) => call("get_pull", { repo, number, viewer }),
Agents as a team: lifecycle, merge queue, billing and a new shell151 updatePull: (actor, repo, number, changes) =>
152 call("update_pull", { actor, repo, number, ...changes }),
Issues and pull requests replace intents and attempts153 readyPull: (actor, repo, number, summary) =>
154 call("ready_pull", { actor, repo, number, summary }),
155 closePull: (actor, repo, number) => call("close_pull", { actor, repo, number }),
Acceptance checks in sandboxes, line comments and review verdicts156 mergePull: (actor, repo, number, options = {}) =>
157 call("merge_pull", { actor, repo, number, ...options }),
Issues and pull requests replace intents and attempts158 listActivePulls: (viewer) => call("list_active_pulls", { viewer }),
Agents as a team: lifecycle, merge queue, billing and a new shell159 startPlan: (actor, repo, brief) => call("start_plan", { actor, repo, brief }),
160 failPlan: (planId, token, error) => call("report_plan", { planId, token, error }),
161 getPlan: (repo, viewer, id) => call("get_plan", { repo, viewer, id }),
162 listPlans: (repo, viewer) => call("list_plans", { repo, viewer }),
163 applyPlan: (actor, repo, id, options = {}) =>
164 call("apply_plan", { actor, repo, id, ...options }),
165 queueIssue: (actor, repo, number, queued) =>
166 call("queue_issue", { actor, repo, number, queued }),
167 readyIssues: (repoId) => call("ready_issues", { repoId }),
168 listAssignedIssues: (viewer) => call("list_assigned_issues", { viewer }),
Issues and pull requests replace intents and attempts169 appendSession: (actor, repo, number, entries) =>
170 call("append_session", { actor, repo, number, entries }),
171 readSession: (repo, number, viewer, afterSeq = 0) =>
172 call("read_session", { repo, number, viewer, afterSeq }),
Work service in Rust, with RFC 3339 timestamps173 };
174}
Events service in Rust, with RFC 3339 times and accurate push events175
Agents as a team: lifecycle, merge queue, billing and a new shell176export function billingClient(service: ServiceBinding): BillingApi {
177 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
178 return {
179 status: () => call("status", {}),
180 account: (workspace, viewer) => call("account", { workspace, viewer }),
181 ledger: (workspace, viewer) => call("ledger", { workspace, viewer }),
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request182 usage: (workspace, viewer, since) => call("usage", { workspace, viewer, since }),
Agents as a team: lifecycle, merge queue, billing and a new shell183 checkout: (actor, workspace, amountCents, returnUrl) =>
184 call("checkout", { actor, workspace, amountCents, returnUrl }),
185 confirm: (workspace, viewer, session) => call("confirm", { workspace, viewer, session }),
186 canStart: (workspace) => call("can_start", { workspace }),
187 startRun: (run) => call("start_run", run),
188 };
189}
190
Events service in Rust, with RFC 3339 times and accurate push events191export function eventsClient(service: ServiceBinding): EventsApi {
192 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
193 return {
194 publish: (events) => call("publish", { events }),
195 list: (query) => call("list", query),
196 };
197}
Integrations: your own model provider, alerts that open issues, tickets agents read198
199export function integrationsClient(service: ServiceBinding): IntegrationsApi {
200 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
201 return {
202 list: (workspace, viewer) => call("list", { workspace, viewer }),
203 connect: (actor, workspace, input) => call("connect", { actor, workspace, ...input }),
204 update: (actor, workspace, id, input) => call("update", { actor, workspace, id, ...input }),
205 disconnect: (actor, workspace, id) => call("disconnect", { actor, workspace, id }),
206 test: (actor, workspace, id) => call("test", { actor, workspace, id }),
207 deliveries: (workspace, viewer, id) => call("deliveries", { workspace, viewer, id }),
208 resolve: (workspace, viewer, reference) => call("resolve", { workspace, viewer, reference }),
209 references: (workspace, text, limit) => call("references", { workspace, text, limit }),
210 import: (actor, repo, reference, assign) => call("import", { actor, repo, reference, assign }),
211 links: (repo, number) => call("links", { repo, number }),
212 modelProvider: (workspace) => call("model_provider", { workspace }),
213 openModelSession: (run) => call("open_model_session", run),
214 modelUpstream: (token) => call("model_upstream", { token }),
Models per workspace: several providers, routed by kind of work215 routes: (workspace, viewer) => call("routes", { workspace, viewer }),
216 setRoutes: (actor, workspace, routes) => call("set_routes", { actor, workspace, routes }),
Integrations: your own model provider, alerts that open issues, tickets agents read217 };
218}
Webhooks: every event, to your own addresses, signed and retried219
220export function webhooksClient(service: ServiceBinding): WebhooksApi {
221 const call = <T>(method: string, args: object) => rpc<T>(service, method, args);
222 return {
223 list: (viewer, owner) => call("list", { viewer, ...owner }),
224 create: (actor, owner, input) => call("create", { actor, ...owner, ...input }),
225 update: (actor, owner, id, input) => call("update", { actor, ...owner, id, ...input }),
226 delete: (actor, owner, id) => call("delete", { actor, ...owner, id }),
227 ping: (actor, owner, id) => call("ping", { actor, ...owner, id }),
228 deliveries: (viewer, owner, id) => call("deliveries", { viewer, ...owner, id }),
229 redeliver: (actor, owner, deliveryId) => call("redeliver", { actor, ...owner, deliveryId }),
230 };
231}