Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 184 to 185

Compare

+67 −1 in 5 places
Lines 21–35 at 185 (were 21–28 at 184)
2121 */
2222export interface Grant {
2323 readonly projects: readonly { readonly project: string; readonly role: string }[];
24+ /** Version 2 grants (abso 663): member-all is every project of the approver's, now and later, at most this role. */
25+ readonly scopes?: readonly { readonly kind: string; readonly role: string }[];
2426}
2527
28+/** The role a box has in all its approver's projects, now and later, or null when its grant is a list (abso 663). */
29+export function allProjectsRole(grant: Grant): string | null {
30+ return grant.scopes?.find((scope) => scope.kind === "member-all")?.role ?? null;
31+}
2633/** Requested access is a suggestion for the person approving, never an authorization. */
2734export interface LoginRequest {
2835 readonly projects?: readonly { readonly project: string; readonly role: "reader" | "writer" | "owner" }[];
Lines 161–167 at 185 (were 154–159 at 184)
154161 body: unknown,
155162 credential: string | undefined,
156163 fetcher: typeof fetch,
164+ headers: Readonly<Record<string, string>> = {},
157165): Promise<Answer> {
158166 const secrets = credential ? [credential] : [];
159167 let response: Response;
Lines 170–176 at 185 (were 162–167 at 184)
162170 method: "POST",
163171 headers: {
164172 "content-type": "application/json",
173+ ...headers,
165174 ...(credential ? { authorization: `Box ${credential}` } : {}),
166175 },
167176 body: JSON.stringify(body),
Lines 325–384 at 185 (were 316–321 at 184)
316325 return { key, id };
317326}
318327
328+/** What a new project from this box starts with (abso 663): the website's own create, as the person who approved the box. */
329+export interface NewProject {
330+ readonly name: string;
331+ readonly owner?: string;
332+ readonly visibility?: "public" | "private";
333+ readonly files?: readonly (
334+ | { readonly path: string; readonly text: string }
335+ | { readonly path: string; readonly base64: string }
336+ )[];
337+}
339+/**
340+ * Makes a project as the person who approved this box (abso init, abso 663). One key for every try, so a retry after
341+ * a lost answer or a pending one is the same project, never a second.
342+ */
343+export async function boxCreateProject(
344+ record: BoxRecord,
345+ project: NewProject,
346+ key: string,
347+ fetcher: typeof fetch = fetch,
348+ sleep: (ms: number) => Promise<void> = (ms) => new Promise((done) => setTimeout(done, ms)),
349+): Promise<Record<string, unknown>> {
350+ for (let attempt = 1; ; attempt++) {
351+ const a = await call(record.server, "/box/projects", project, record.credential, fetcher, {
352+ "Idempotency-Key": key,
353+ });
354+ const pending = (a.body.operation as { state?: unknown } | undefined)?.state === "pending";
355+ if (!pending) return a.body;
356+ if (attempt >= 10)
357+ throw new UsageError(
358+ `${originOf(record.server)} is still making ${project.name}. Run the same abso init again in a minute: it picks up where this left off.`,
359+ );
360+ await sleep(1000 * attempt);
361+ }
362+}
364+/** Makes an organization as the person who approved this box (abso org new, abso 663). */
365+export async function boxCreateOrg(
366+ record: BoxRecord,
367+ name: string,
368+ displayName: string | undefined,
369+ fetcher: typeof fetch = fetch,
370+): Promise<Record<string, unknown>> {
371+ return (
372+ await call(
373+ record.server,
374+ "/box/orgs",
375+ { name, ...(displayName === undefined ? {} : { displayName }) },
376+ record.credential,
377+ fetcher,
378+ )
379+ ).body;
380+}
319382/** The agent name abso join takes when none is given: the box's name, lower-cased. */
320383export function defaultAgentName(): string {
321384 return boxName().toLowerCase();
Lines 438–449 at 185 (were 375–383 at 184)
375438 if (!record) return `This box isn't signed in to ${originOf(server)}. abso login signs it in.`;
376439 const g = record.grant;
377440 const expired = record.expiresAt <= now;
441+ const all = allProjectsRole(g);
378442 return [
379443 `Signed in to ${record.server} as box ${record.id}${expired ? ", but the sign-in has expired. abso login renews it." : "."}`,
380− `Projects: ${g.projects.map((p) => `${p.project} (${p.role})`).join(", ")}.`,
444+ all === null
445+ ? `Projects: ${g.projects.map((p) => `${p.project} (${p.role})`).join(", ")}.`
446+ : `Projects: all of yours, now and later (${all} at most). abso init makes a new one; abso org new makes an organization.`,
381447 `${expired ? "Expired" : "Expires"} ${day(record.expiresAt)} UTC.`,
382448 ].join("\n");
383449}
MCP
compare on this site's /mcp
CLI
abso diff 184 185 client/src/box.ts --json
JSON
/christopher/abso-core/compare/184..185?file=client%2Fsrc%2Fbox.ts&format=json