Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

778 linesCodeBlameRaw
1/**
2 * Every state change in g1t is published as an event. Services react to
3 * each other through events rather than direct calls, and the same stream
4 * feeds timelines, webhooks and workflows.
5 *
6 * The envelope follows CloudEvents: `type` says what happened, `subject`
7 * says to what, `data` is the type-specific payload.
8 */
9
10import type { Release } from "./about";
11import type { RepoRole } from "./access";
12import type { CheckRunEventData, CheckSuiteEventData, StatusEventData } from "./checks";
13import type { DeploymentStatus, RepoDeployment } from "./deployments";
14import type { TeamRole, TeamVisibility } from "./teams";
15import type { AgentRef, ClaimEventData, DependencyChangedData, OverlapDetectedData, SessionEventData, SessionProgressedData, Verdict } from "./work";
16
17/** What every `package.*` event names. */
18export type PackageEventData = {
19 packageId: string;
20 workspace: string;
21 ecosystem: string;
22 name: string;
23 repoId: string | null;
24};
25
26/** What `deployment.succeeded` and `deployment.failed` carry. */
27export type DeploymentEventData = {
28 deploymentId: string;
29 projectId: string;
30 repoId: string;
31 workspace: string;
32 project: string;
33 kind: "production" | "preview";
34 branch: string | null;
35 number: number | null;
36 commit: string;
37 path: string;
38 error: string | null;
39 recovered: boolean;
40 /** A username, or `g1t`. */
41 triggeredBy: string;
42};
43
44/** What every `release.*` event carries. */
45export type ReleaseEventData = {
46 releaseId: string;
47 repoId: string;
48 tagName: string;
49 release: Release;
50 /** On `release.edited`: what the title and notes were before. */
51 changes?: { name?: { from: string | null }; body?: { from: string } };
52 /** Set when a workflow job's token made the change: the run's id. */
53 causedByJob?: string;
54};
55
56/** The payload of the `repo.collaborator_*` events. */
57export type RepoCollaboratorData = {
58 repoId: string;
59 namespace: string;
60 name: string;
61 username: string;
62 role: RepoRole | null;
63 previousRole: RepoRole | null;
64};
65/** A team asked to review a pull request. */
66export type TeamRequested = { team: string; notified: string[]; assigned: string[] };
67
68/** The payload of the `team.*` events; each sets the fields that apply. */
69/** How someone came to be a member of a workspace (`workspace.member_joined`). */
70export type JoinedHow = "invitation" | "created" | "joined";
71
72/** The payload of `workspace.member_joined`. Mirrors `MemberJoined` in events.rs. */
73export type MemberJoinedData = {
74 workspaceId: string;
75 /** The workspace's slug. */
76 workspace: string;
77 userId: string;
78 username: string;
79 role: "owner" | "member";
80 how: JoinedHow;
81};
82
83export type TeamChangedData = {
84 workspace: string;
85 teamId: string;
86 team: string;
87 name: string;
88 visibility: TeamVisibility | null;
89 parent?: string;
90 changes?: string[];
91 username?: string;
92 role?: TeamRole;
93 previousRole?: TeamRole;
94 repoId?: string;
95 repo?: string;
96 repoRole?: RepoRole;
97 previousRepoRole?: RepoRole;
98};
99
100export type EventPayloads = {
101 /** `parentId`: the repository it was forked from, when it is a fork. */
102 "repo.created": { repoId: string; namespace: string; name: string; isPrivate: boolean; parentId?: string };
103 /** A repository was forked: into a workspace, or for a pull request (`pullId`). */
104 "repo.forked": { repoId: string; sourceRepoId: string; pullId?: string };
105 /** A fork left its fork network: detached, or its parent changed who can see it. */
106 "repo.detached": { repoId: string; parentId: string };
107 /**
108 * A repository's description, topics or visibility changed.
109 * `visibilityChanged` says whether it went public or private, which
110 * `repo.visibility_changed` also announces on its own.
111 */
112 "repo.updated": { repoId: string; namespace: string; name: string; isPrivate: boolean; visibilityChanged: boolean };
113 "repo.visibility_changed": { repoId: string; isPrivate: boolean };
114 /**
115 * A repository's name changed within its workspace `namespace`, from
116 * `from` to `to`, keeping its id. A path change like `repo.transferred`:
117 * services move rows kept under its path to its *current* path (see
118 * `repoMove`, `currentMovedPath`).
119 */
120 "repo.renamed": { repoId: string; namespace: string; from: string; to: string };
121 /**
122 * A repository was deleted. It is hidden and git refuses it, but it can
123 * be restored until `purgeAfter`: services stop what runs for it and hide
124 * it, and keep their rows until `repo.purged`.
125 */
126 "repo.deleted": {
127 repoId: string;
128 namespace: string;
129 name: string;
130 isPrivate: boolean;
131 purgeAfter: string;
132 /** It went with its workspace (`workspace.deleting`); deployments leaves it to that. */
133 withWorkspace?: boolean;
134 };
135 /** A deleted repository is back, as it was. Services start again what they stopped. */
136 "repo.restored": {
137 repoId: string;
138 namespace: string;
139 name: string;
140 isPrivate: boolean;
141 /** It came back with its workspace (`workspace.restored`). */
142 withWorkspace?: boolean;
143 };
144 /**
145 * A deleted repository is gone for good, its git data with it. Services
146 * drop every row they keep for it, except a workspace's history (ledgers,
147 * invoices, the audit log).
148 */
149 "repo.purged": { repoId: string; namespace: string; name: string };
150 /**
151 * A repository was archived (read-only: pushes, merges, agents and
152 * workflows refused; issues and pull requests locked; deployments keep
153 * serving), or unarchived.
154 */
155 "repo.archived": { repoId: string; namespace: string; name: string; archived: true };
156 "repo.unarchived": { repoId: string; namespace: string; name: string; archived: false };
157 /** The default branch is now `to`; `renamed` when `from` was renamed to it. */
158 "repo.default_branch_changed": { repoId: string; from: string; to: string; renamed: boolean };
159 /** A branch was renamed. Pull requests from it follow. */
160 "branch.renamed": { repoId: string; from: string; to: string; defaultBranch: boolean };
161 /** An account was made, or changed what its profile shows. Ask identity for the profile. */
162 "user.updated": { username: string };
163 /**
164 * An account was deleted, by the person or by g1t's staff; staff can
165 * restore it until `purgeAfter`. Its sessions, tokens and keys have ended
166 * and it has left every workspace. Services stop what they do for it and
167 * keep their rows; `user.restored` undoes that, and `user.deleted` follows
168 * once `purgeAfter` passes.
169 */
170 "user.deleting": { userId: string; username: string; byStaff: boolean; purgeAfter: string };
171 /** Staff brought a deleted account back. Services undo what they did on `user.deleting`. */
172 "user.restored": { userId: string; username: string };
173 /**
174 * An account is gone for good. Services drop what they keep for it alone
175 * and show what it wrote as `ghost` (`GHOST_USERNAME`, `GHOST_ID`).
176 * Ledgers, invoices and audit logs keep its username, which is never given
177 * to anyone again.
178 */
179 "user.deleted": { userId: string; username: string };
180 /** A workspace was made, or its name, description or icon changed. */
181 "workspace.updated": { workspaceId: string; slug: string };
182 /**
183 * A person became a member of a workspace. `how` says by which door;
184 * the workspace's creator is `created`, so a listener that greets new
185 * members leaves them out (the agents service's @g1t welcomes everyone
186 * else, once). Never for an agent or a token.
187 */
188 "workspace.member_joined": MemberJoinedData;
189 /** Someone, or g1t staff, made an invite. Never the code or the address. */
190 "invite.created": { inviteId: string; inviterId: string | null; workspaceId: string | null; bound: boolean };
191 /** An invite was used: by a new account, or by an account joining a workspace. */
192 "invite.redeemed": {
193 inviteId: string;
194 userId: string;
195 inviterId: string | null;
196 workspaceId: string | null;
197 createdAccount: boolean;
198 };
199 /**
200 * One branch moved by a push. `ref` is the full ref, `after` the commit it
201 * points to now, and `defaultBranch` whether it is the default branch.
202 */
203 /**
204 * `before` is where the ref pointed before; absent for a new branch or
205 * tag. `causedByJob` is set when a workflow job's token pushed: the run's id.
206 */
207 "git.push": {
208 repoId: string;
209 ref: string;
210 before?: string;
211 after: string;
212 defaultBranch: boolean;
213 causedByJob?: string;
214 /**
215 * How many commits the push brought to the branch, along its
216 * first-parent line from `after` back to `before` (a merge commit is
217 * one), at most 50; one for a new branch. Absent when it was not
218 * counted: a tag, a branch deleted, a pull request landed, a push the
219 * store could not read back, or one from before this was recorded.
220 */
221 commits?: number;
222 };
223 /**
224 * A branch or tag was deleted by a push. `before` is the commit it pointed
225 * to. `causedByJob` is set when a workflow job's token deleted it: the run's id.
226 */
227 "git.deleted": { repoId: string; ref: string; before: string; causedByJob?: string };
228 /**
229 * `author` is who opened it: g1t, for one its agent filed while at work,
230 * with `requestedBy` the person it was working for. Every issue and pull
231 * request event carries both.
232 */
233 "issue.opened": {
234 issueId: string;
235 repoId: string;
236 number: number;
237 title: string;
238 author?: { id: string; username: string };
239 requestedBy?: { id: string; username: string };
240 };
241 "issue.updated": { issueId: string; repoId: string; number: number };
242 /** The people an issue is assigned to changed; `assignees` is the new set, `added` those newly assigned. */
243 "issue.assigned": { issueId: string; repoId: string; number: number; assignees: string[]; added?: string[] };
244 /** `resolvedBy` is the number of the pull request whose merge closed it. */
245 "issue.closed": {
246 issueId: string;
247 repoId: string;
248 number: number;
249 reason: "completed" | "not_planned";
250 resolvedBy?: number;
251 /** The commit whose message closed it, when one pushed to the default branch did. */
252 commit?: string;
253 };
254 "issue.reopened": { issueId: string; repoId: string; number: number };
255 /**
256 * `issue` is the number of the issue the pull request is for. `author` is
257 * who opened it: g1t, for a change g1t made, with `requestedBy` the person
258 * who asked for it.
259 */
260 "pull.opened": {
261 pullId: string;
262 repoId: string;
263 number: number;
264 issue?: number;
265 agent: string;
266 author?: { id: string; username: string };
267 requestedBy?: { id: string; username: string };
268 };
269 "pull.ready": { pullId: string; repoId: string; number: number; issue?: number };
270 /** A push moved the head of a pull request that is ready for review. */
271 "pull.updated": { pullId: string; repoId: string; number: number; issue?: number; commit: string };
272 /** A merge was asked for while the pull request was behind; it has to catch up first. */
273 "pull.merge_requested": { pullId: string; repoId: string; number: number; issue?: number };
274 "pull.closed": { pullId: string; repoId: string; number: number; issue?: number };
275 /** A closed pull request was opened again. `commit` is its head. */
276 "pull.reopened": { pullId: string; repoId: string; number: number; issue?: number; commit?: string };
277 /** A pull request that was ready for review was turned back into a draft. */
278 "pull.converted_to_draft": { pullId: string; repoId: string; number: number; issue?: number };
279 /** People were assigned to a pull request: `assignees` is the new set, `added` those newly assigned. */
280 "pull.assigned": { pullId: string; repoId: string; number: number; issue?: number; assignees: string[]; added: string[] };
281 /** Reviewers were asked for a pull request (`reviewers`), or no longer are. */
282 "pull.review_requested": {
283 pullId: string;
284 repoId: string;
285 number: number;
286 issue?: number;
287 reviewers?: string[];
288 /** Teams asked: `team` is `workspace/slug`, `notified` who is told, `assigned` who review assignment picked. */
289 teams?: TeamRequested[];
290 /** Asked because they own files it changes (its CODEOWNERS file). */
291 codeOwners?: boolean;
292 };
293 "pull.review_request_removed": {
294 pullId: string;
295 repoId: string;
296 number: number;
297 issue?: number;
298 reviewers?: string[];
299 teams?: TeamRequested[];
300 };
301 /** g1t stopped seeing a pull request through until a person steps in; `detail` says why. */
302 "pull.stalled": { pullId: string; repoId: string; number: number; issue?: number; detail: string };
303 /** A pull request g1t had stopped on is going again. */
304 "pull.resumed": { pullId: string; repoId: string; number: number; issue?: number };
305 /**
306 * The pull request's head or its target moved and the files both changed
307 * overlap: a sandbox should find out whether it still merges cleanly.
308 * `commit` is its head.
309 */
310 "pull.mergecheck": { pullId: string; repoId: string; number: number; issue?: number; commit: string };
311 /** Whether the pull request merges cleanly was settled. */
312 "pull.mergeability": { pullId: string; repoId: string; number: number; issue?: number };
313 "pull.merged": { pullId: string; repoId: string; number: number; issue?: number; commit: string };
314 /** A run of the acceptance checks finished. `commit` is what was checked. */
315 "checks.completed": {
316 pullId: string;
317 repoId: string;
318 number: number;
319 status: "passed" | "failed" | "errored";
320 commit: string;
321 };
322 /** A status was set on a commit through the API. */
323 "status.created": StatusEventData;
324 /** A check run was reported on a commit through the API, completed, asked to run again, or had one of its buttons pressed (`requestedAction`). */
325 "check_run.created": CheckRunEventData;
326 "check_run.completed": CheckRunEventData;
327 "check_run.rerequested": CheckRunEventData;
328 "check_run.requested_action": CheckRunEventData;
329 /** A reporter's check runs on a commit all completed, or it was asked to run them again. */
330 "check_suite.completed": CheckSuiteEventData;
331 "check_suite.rerequested": CheckSuiteEventData;
332 /** A g1t agent finished reviewing a pull request; no verdict if it could not. No longer published: on older events only. */
333 "review.completed": {
334 pullId: string;
335 repoId: string;
336 number: number;
337 verdict?: "approve" | "request_changes";
338 };
339 /** A person was given a role on one repository directly, had it changed, or lost it. `role` is null once removed. */
340 "repo.collaborator_added": RepoCollaboratorData;
341 "repo.collaborator_removed": RepoCollaboratorData;
342 "repo.collaborator_role_changed": RepoCollaboratorData;
343 /** A team of a workspace was created, changed (`changes` says what) or deleted. */
344 "team.created": TeamChangedData;
345 "team.edited": TeamChangedData;
346 "team.deleted": TeamChangedData;
347 /** Someone joined a team, had their role in it changed, or left it. */
348 "team.member_added": TeamChangedData;
349 "team.member_role_changed": TeamChangedData;
350 "team.member_removed": TeamChangedData;
351 /** A team was given a role on a repository, had it changed, or lost it. */
352 "team.repo_added": TeamChangedData;
353 "team.repo_role_changed": TeamChangedData;
354 "team.repo_removed": TeamChangedData;
355 /** A repository's merge queue gained, lost or settled an entry. */
356 "queue.changed": { repoId: string };
357 /**
358 * A combined state in the merge queue failed. `pull` (also `number`)
359 * answers for it; `suspects` are the pull requests ahead it fails with,
360 * narrowed by building smaller combinations when `bisected`. With
361 * nothing ahead, though it passes its checks on its own, `landed` lists
362 * the pull requests merged into the default branch since it branched,
363 * newest first.
364 */
365 "integration.failed": {
366 repoId: string;
367 pullId: string;
368 number: number;
369 pull: number;
370 issue: number | null;
371 combination: number[];
372 check: { name: string; conclusion: string; url: string | null };
373 bisected: boolean;
374 suspects: number[];
375 otherPulls: number[];
376 landed: number[];
377 commit: string | null;
378 };
379 /** A combined state in the merge queue passed. */
380 "integration.passed": {
381 repoId: string;
382 pullId: string;
383 number: number;
384 pull: number;
385 issue: number | null;
386 combination: number[];
387 commit: string | null;
388 };
389 /** A decision record was kept on an issue or pull request (`number`). */
390 "decision.recorded": {
391 repoId: string;
392 number: number;
393 issue: number | null;
394 decision: {
395 id: string;
396 issue: number | null;
397 pull: number | null;
398 sessionId: string | null;
399 actor: string | null;
400 kind: string;
401 confidence: "claimed" | "tested" | "approved";
402 summary: string;
403 evidence: Record<string, unknown>;
404 createdAt: string;
405 };
406 };
407 /** `number` is the issue or pull request commented on. */
408 "comment.created": {
409 commentId: string;
410 repoId: string;
411 number: number;
412 /** Set when the comment is on a pull request. */
413 pullId?: string;
414 /** Set when the comment is a review. */
415 verdict?: Verdict;
416 /**
417 * Set when one of the workspace's agents wrote it, as itself; the
418 * event's actor is then the person it acted for (`actingFor`).
419 */
420 agent?: AgentRef;
421 actingFor?: { id: string; username: string };
422 /** An agent's review: its verdict is advisory and counts toward nothing. */
423 advisory?: boolean;
424 };
425 /** A comment's text changed; `changes.body.from` is what it said before. */
426 "comment.edited": {
427 commentId: string;
428 repoId: string;
429 number: number;
430 /** Set when the comment is on a pull request. */
431 pullId?: string;
432 changes: { body: { from: string } };
433 };
434 /** A comment was deleted; `comment` is the comment as it was. */
435 "comment.deleted": {
436 commentId: string;
437 repoId: string;
438 number: number;
439 /** Set when the comment was on a pull request. */
440 pullId?: string;
441 comment: {
442 id: string;
443 body: string;
444 author: { id: string; username: string };
445 createdAt: string;
446 path: string | null;
447 line: number | null;
448 };
449 };
450 "session.appended": { pullId: string; repoId: string; number: number; count: number };
451 /** A harness session started on the repository (not on an idempotent re-start). */
452 "session.started": SessionEventData;
453 /** A session ended, or timed out after 2 hours without a heartbeat. */
454 "session.ended": SessionEventData;
455 /** A session (or a subagent of it) recorded more: at most every few seconds each, for the pages showing it. */
456 "session.progressed": SessionProgressedData;
457 /** Someone claimed an issue; `others` are the other active claims on it. */
458 "work.claimed": ClaimEventData;
459 "work.released": ClaimEventData;
460 "work.claim_expired": ClaimEventData;
461 "work.handoff_requested": ClaimEventData;
462 /** An issue's blockers changed, or one of them closed or had its pull request merged. */
463 "dependency.changed": DependencyChangedData;
464 /** A push made a pull request change files another open one changes. */
465 "overlap.detected": OverlapDetectedData;
466 /**
467 * A build of a project finished, for production or one pull request's
468 * preview (`number`). `path` is the deployment's page on the site;
469 * `recovered`, on a success, says the build before it failed.
470 */
471 "deployment.succeeded": DeploymentEventData;
472 "deployment.failed": DeploymentEventData;
473 /**
474 * A deployment was made, wherever it runs: reported through the API, by
475 * a g1t Actions job with an `environment:`, or a g1t.page build. Its
476 * `payload` is left out: read the deployment for it.
477 */
478 "deployment.created": { repoId: string; deployment: Omit<RepoDeployment, "payload">; causedByJob?: string };
479 /**
480 * A deployment has a new status; `deployment` is as it is now.
481 * `causedByJob` (as on every event a workflow job's token causes) is the
482 * run whose job made it, so no workflow starts for it.
483 */
484 "deployment_status.created": {
485 repoId: string;
486 deployment: Omit<RepoDeployment, "payload">;
487 deploymentStatus: DeploymentStatus;
488 causedByJob?: string;
489 };
490 /**
491 * A release changed, one event per GitHub release activity it amounts
492 * to: made (`created`; a published one is also `published`, and
493 * `released` or `prereleased`), a draft published, edited, made a draft
494 * again (`unpublished`) or deleted. `release` is as it is now (as it was,
495 * for `release.deleted`).
496 */
497 "release.created": ReleaseEventData;
498 "release.published": ReleaseEventData;
499 "release.released": ReleaseEventData;
500 "release.prereleased": ReleaseEventData;
501 "release.edited": ReleaseEventData;
502 "release.unpublished": ReleaseEventData;
503 "release.deleted": ReleaseEventData;
504 /**
505 * A package version was published, such as an image pushed by
506 * `docker push`. `tags` are the tags that now point to it; `repoId` (and
507 * the event's) is the repository the package is linked to, if any.
508 */
509 "package.published": PackageEventData & { version: string; digest: string; size: number; tags: string[] };
510 /** One version of a package was deleted, with the tags that pointed to it. */
511 "package.version_deleted": PackageEventData & { version: string; digest: string };
512 /** A package was deleted with every version it had. */
513 "package.deleted": PackageEventData;
514 /** A package became public or private. */
515 "package.visibility_changed": PackageEventData & { visibility: "public" | "private" };
516 /**
517 * A workspace's slug changed from `from` to `to`. Services that store a
518 * slug move their rows to the workspace's *current* slug (see
519 * `currentWorkspaceSlug`), so a repeated or late delivery after a second
520 * rename still lands in the right place.
521 */
522 "workspace.renamed": { workspaceId: string; from: string; to: string };
523 /**
524 * A repository moved from workspace `from` to `to`, keeping its id and
525 * name. Services that store its path or its workspace's slug move those
526 * rows to its *current* path (ask repos `path_by_id`), so a repeated or
527 * late delivery after a second transfer still lands in the right place.
528 */
529 "repo.transferred": { repoId: string; name: string; from: string; to: string };
530 /**
531 * A workspace is gone. Services drop what they keep for it alone; ledgers,
532 * invoices and the audit log stay under its slug, which is never reused.
533 */
534 "workspace.deleted": { workspaceId: string; slug: string };
535 /**
536 * An owner deleted a workspace; staff can restore it until `purgeAfter`,
537 * and nobody can reach it meanwhile. Services hide what they keep for it
538 * and stop what runs for it, keeping their rows: repos deletes its
539 * repositories softly (`repo.deleted` with `withWorkspace`), deployments
540 * pauses its apps, search drops it. `workspace.restored` undoes exactly
541 * that; `workspace.deleted` follows once `purgeAfter` passes. `by` is the
542 * owner's username.
543 */
544 "workspace.deleting": { workspaceId: string; slug: string; by: string; purgeAfter: string };
545 /**
546 * Staff brought a deleted workspace back with its members and tokens.
547 * Services undo what they did on `workspace.deleting`, and only that.
548 */
549 "workspace.restored": { workspaceId: string; slug: string };
550 /**
551 * A sandbox was stopped because it looked like it was mining: CPU pinned
552 * with little I/O and no progress, or a miner seen by name. For g1t's
553 * staff, in sudo; published with no `repoId` so it never reaches a
554 * repository's timeline or webhooks. `metrics` is what the sandbox
555 * measured (`Verdict` in crates/runner abuse.rs), or null if it could
556 * not say.
557 */
558 "abuse.flagged": {
559 workspace: string;
560 repo: string | null;
561 /** The agent run, when the sandbox had one. */
562 run: string | null;
563 /** What the sandbox was for: agent, checks, queue, actions, deploy... */
564 kind: string;
565 sandbox: string;
566 metrics: Record<string, unknown> | null;
567 };
568 /**
569 * Docs (services/artifacts): a page was made. Published with no `repoId`, so
570 * a page (which may be in a private space) never reaches a repository's
571 * timeline or webhooks; `actor` is the user's or agent's id. Readers
572 * check access with the artifacts service before showing anything of it.
573 */
574 "doc.page.created": DocPageEventData;
575 /**
576 * A page's content changed: at most once per page every ten minutes of
577 * editing (when its history records a version), and for every agent
578 * edit, accepted suggestion and restore. `authors` are member keys
579 * (`user:<id>`, `agent:<id>`) of everyone whose changes are in it.
580 */
581 "doc.page.updated": DocPageEventData & { versionId: string; kind: "edit" | "agent" | "suggestion" | "restore"; authors: string[] };
582 /** A page went to the trash (with every page under it; one event for the page asked about). */
583 "doc.page.archived": DocPageEventData;
584 /**
585 * A page became possibly out of date: a merged pull request or a push to
586 * a repository's default branch changed code it cites. `repoId` is in
587 * `data`, not on the event, for the same reason as above. `owners` are
588 * member keys; an agent that owns the page can update it
589 * (`stalePagesForAgent` in docs.ts).
590 */
591 "doc.page.stale": DocPageEventData & { repoId: string; repo: string; commit: string; pull: number | null; paths: string[]; owners: string[] };
592 /**
593 * Artifacts (folios, services/artifacts): a folio was made. Like `doc.page.*`,
594 * published with no `repoId`, never offered to webhooks, and readers check
595 * access with the artifacts service before showing anything of it.
596 */
597 "folio.created": FolioEventData;
598 /** A folio's content changed: a version (`versionKind`) with everyone whose changes are in it. */
599 "folio.updated": FolioEventData & { versionId: string; versionKind: "edit" | "agent" | "suggestion" | "proposal" | "restore"; authors: string[] };
600 /** A folio went to the trash (with everything under it; one event for the folio asked about). */
601 "folio.trashed": FolioEventData;
602 "folio.restored": FolioEventData;
603 /**
604 * A folio was deleted for good from the trash (with everything under it;
605 * one event for each top that went): by someone with full access, by
606 * emptying the trash, or by the daily purge (`actor` null then).
607 */
608 "folio.deleted": FolioEventData;
609 /** Someone was given access: who (member keys) and the role. Never content. */
610 "folio.shared": FolioEventData & { principals: string[]; role: "view" | "comment" | "edit" | "manage" };
611 /** Code a folio cites changed. The repository is in `data` as `owner/name` only. */
612 "folio.stale": FolioEventData & { repo: string; commit: string; pull: number | null; paths: string[]; owners: string[] };
613 /**
614 * A space was deleted (services/artifacts): everything in it went to the
615 * trash (`trashed` counts the artifacts; this one event stands for them
616 * all). Like `folio.*`, published with no `repoId` and never offered to
617 * webhooks; `name` is null for a members-only space.
618 */
619 "doc.space.deleted": { workspace: string; workspaceId: string; spaceId: string; name: string | null; kind: "workspace" | "team" | "private"; trashed: number };
620};
621
622/**
623 * What every `folio.*` event carries. `title` is null unless every member
624 * of the workspace can read the folio, so a private folio's name never
625 * travels.
626 */
627export type FolioEventData = {
628 workspace: string;
629 workspaceId: string;
630 folioId: string;
631 kind: "doc" | "slides" | "design" | "dashboard";
632 spaceId: string | null;
633 title: string | null;
634};
635
636/** What every `doc.page.*` event carries. */
637export type DocPageEventData = {
638 workspace: string;
639 workspaceId: string;
640 pageId: string;
641 spaceId: string;
642 title: string;
643 /** The page's address on the site. */
644 path: string;
645};
646
647export type EventType = keyof EventPayloads;
648
649export type G1tEvent<T extends EventType = EventType> = {
650 [K in T]: {
651 id: string;
652 type: K;
653 /** The service that published it. */
654 source: string;
655 /** RFC 3339. */
656 time: string;
657 /** The repo the event concerns, used to scope timelines and deliveries. */
658 repoId: string | null;
659 /** The user or agent that caused it, if any. */
660 actor: string | null;
661 data: EventPayloads[K];
662 };
663}[T];
664
665/** What a publisher supplies; the bus fills in `id` and `time`. */
666export type NewEvent<T extends EventType = EventType> = {
667 [K in T]: Omit<G1tEvent<K>, "id" | "time">;
668}[T];
669
670/** The most repositories one `list` reads with `repoIds`. */
671export const MAX_LIST_REPOS = 100;
672
673export type EventQuery = {
674 repoId?: string;
675 /** Only events of these repositories, by id (at most `MAX_LIST_REPOS`); the caller has checked the viewer may read each. */
676 repoIds?: string[];
677 types?: EventType[];
678 /** Return events older than this event id. */
679 before?: string;
680 /** Only events by this account id. */
681 actor?: string;
682 /** Only events about these issues or pull requests (`number`, or the `issue` a comment or review is on). */
683 numbers?: number[];
684 /** Only events at or after this RFC 3339 time. */
685 since?: string;
686 limit?: number;
687};
688
689/**
690 * `activity_digest`: what happened in some repositories, and to a
691 * workspace's artifacts, over `[from, until)`, counted by who did it. Home
692 * reads it for what people and agents did since you were last there.
693 * snake_case, as the Rust service reads it
694 * (`g1t_contracts::events::ActivityDigestArgs`).
695 */
696export type ActivityDigestArgs = {
697 /** By id; the caller has checked the viewer may read each. At most `MAX_DIGEST_REPOS` are read. */
698 repo_ids: string[];
699 /** The workspace's slug, for its `folio.*` events (which carry no repository); null leaves artifacts out. */
700 workspace: string | null;
701 /** RFC 3339, inclusive. */
702 from: string;
703 /** RFC 3339, exclusive. */
704 until: string;
705};
706
707/** The most repositories one digest reads. */
708export const MAX_DIGEST_REPOS = 50;
709
710/**
711 * How many times one actor did something. The actor is a member key:
712 * `user:<id>` for a person (or g1t, `user:usr_g1t_agent`), `agent:<id>` for
713 * one of the workspace's agents acting as itself, or `""` when the event
714 * named nobody.
715 */
716export type ActorCount = { actor: string; count: number };
717
718/** Pushes by one actor, with the commits they brought. */
719export type PushesBy = { actor: string; count: number; commits: number };
720
721/** Pushes to a repository's branches (tags are not pushes here). A push whose commits were not counted counts as one commit. */
722export type PushDigest = {
723 count: number;
724 commits: number;
725 /** The branches pushed to, by name, sorted. */
726 branches: string[];
727 /** Most pushes first. */
728 by: PushesBy[];
729 /** Of those, the pushes straight to the default branch: what landed without a pull request. */
730 default_branch: { count: number; commits: number; by: PushesBy[]; last_at: string | null };
731};
732
733export type RepoDigest = {
734 repo_id: string;
735 pushes: PushDigest;
736 /** Pull requests opened, merged and closed without merging, each by who did it. */
737 pulls: { opened: ActorCount[]; merged: ActorCount[]; closed: ActorCount[] };
738 issues: { opened: ActorCount[]; closed: ActorCount[] };
739 /** `review.completed` (g1t's), and a comment with a verdict (a person's). */
740 reviews: ActorCount[];
741 /** Comments without a verdict; one by an agent as itself is the agent's. */
742 comments: ActorCount[];
743 /** Builds that finished, by who set them off; `production` is how many successes were production. */
744 deployments: { succeeded: ActorCount[]; failed: ActorCount[]; production: number };
745 /** Releases published, newest first, at most 50. */
746 releases: { tag: string; name: string | null; actor: string; at: string }[];
747 /** Package versions published, newest first, at most 50. */
748 packages: { ecosystem: string; name: string; version: string; actor: string; at: string }[];
749};
750
751/** A workspace's artifacts over the span. Never a title. */
752export type FolioDigest = {
753 created: ActorCount[];
754 /** Each folio whose content changed, once, with everyone whose changes are in it (member keys); at most 50. */
755 edited: { folio_id: string; kind: "doc" | "slides" | "design" | "dashboard" | string; authors: string[] }[];
756 /** How many folios changed, counting those past the cap. */
757 edited_count: number;
758};
759
760export type ActivityDigest = {
761 from: string;
762 until: string;
763 /** One per repository that had any event counted; none for a quiet one. */
764 repos: RepoDigest[];
765 /** When a workspace was named. */
766 folios: FolioDigest | null;
767 /** False when more events fell in the span than were read, or more repositories were named than are read, so counts are low. */
768 complete: boolean;
769};
770
771/** The event bus and its durable log. */
772export interface EventsApi {
773 publish(events: NewEvent[]): Promise<void>;
774 /** Newest first. */
775 list(query: EventQuery): Promise<G1tEvent[]>;
776 /** A span of some repositories' and a workspace's artifacts' events, counted by who did it. */
777 activityDigest(args: ActivityDigestArgs): Promise<ActivityDigest>;
778}