g1t/packages/contracts/src/events.ts

74 lines2,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.

Initial g1t: services, event bus, intents and attempts1/**
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 automations.
5 *
6 * The envelope follows CloudEvents: `type` says what happened, `subject`
7 * says to what, `data` is the type-specific payload.
8 */
9export type EventPayloads = {
10 "repo.created": { repoId: string; namespace: string; name: string; isPrivate: boolean };
Issues and pull requests replace intents and attempts11 "repo.forked": { repoId: string; sourceRepoId: string; pullId: string };
Events service in Rust, with RFC 3339 times and accurate push events12 /**
13 * One branch moved by a push. `ref` is the full ref, `after` the commit it
14 * points to now, and `defaultBranch` whether it is the default branch.
15 */
16 "git.push": { repoId: string; ref: string; after: string; defaultBranch: boolean };
Issues and pull requests replace intents and attempts17 "issue.opened": { issueId: string; repoId: string; number: number; title: string };
18 "issue.updated": { issueId: string; repoId: string; number: number };
19 /** `resolvedBy` is the number of the pull request whose merge closed it. */
20 "issue.closed": {
21 issueId: string;
22 repoId: string;
23 number: number;
24 reason: "completed" | "not_planned";
25 resolvedBy?: number;
26 };
27 "issue.reopened": { issueId: string; repoId: string; number: number };
28 /** `issue` is the number of the issue the pull request is for. */
29 "pull.opened": { pullId: string; repoId: string; number: number; issue?: number; agent: string };
30 "pull.ready": { pullId: string; repoId: string; number: number; issue?: number };
31 "pull.closed": { pullId: string; repoId: string; number: number; issue?: number };
32 "pull.merged": { pullId: string; repoId: string; number: number; issue?: number; commit: string };
33 /** `number` is the issue or pull request commented on. */
34 "comment.created": { commentId: string; repoId: string; number: number };
35 "session.appended": { pullId: string; repoId: string; number: number; count: number };
Initial g1t: services, event bus, intents and attempts36};
37
38export type EventType = keyof EventPayloads;
39
40export type G1tEvent<T extends EventType = EventType> = {
41 [K in T]: {
42 id: string;
43 type: K;
44 /** The service that published it. */
45 source: string;
Events service in Rust, with RFC 3339 times and accurate push events46 /** RFC 3339. */
47 time: string;
Initial g1t: services, event bus, intents and attempts48 /** The repo the event concerns, used to scope timelines and deliveries. */
49 repoId: string | null;
50 /** The user or agent that caused it, if any. */
51 actor: string | null;
52 data: EventPayloads[K];
53 };
54}[T];
55
56/** What a publisher supplies; the bus fills in `id` and `time`. */
57export type NewEvent<T extends EventType = EventType> = {
58 [K in T]: Omit<G1tEvent<K>, "id" | "time">;
59}[T];
60
61export type EventQuery = {
62 repoId?: string;
63 types?: EventType[];
64 /** Return events older than this event id. */
65 before?: string;
66 limit?: number;
67};
68
69/** The event bus and its durable log. */
70export interface EventsApi {
71 publish(events: NewEvent[]): Promise<void>;
72 /** Newest first. */
73 list(query: EventQuery): Promise<G1tEvent[]>;
74}