Skip to content
refs
83 lines · 4.7 KBRaw
1import type { Attribution, Role } from "./actor.ts";
2import type { Id, Timestamp } from "./common.ts";
3import type { Label, PersonRef, TaskStatus, Visibility } from "./views.ts";
4
5/**
6 * The thing an event belongs to. Streams use internal ids, which never change, so a
7 * repository rename or task transfer keeps its history. A task's timeline is its stream.
8 */
9export type Stream = "org" | `repo:${string}` | `task:${number}` | `pull:${number}`;
10
11interface Payloads {
12 "task.opened": { readonly title: string };
13 "task.commented": { readonly body: string; readonly html: string; readonly editedAt: Timestamp | null };
14 "task.closed": { readonly pull?: number };
15 "task.reopened": Record<string, never>;
16 "task.renamed": { readonly from: string; readonly to: string };
17 "task.assigned": { readonly assignee: PersonRef };
18 "task.unassigned": { readonly assignee: PersonRef };
19 "task.transferred": { readonly from: { readonly repo: string; readonly number: number }; readonly to: { readonly repo: string; readonly number: number } };
20 "task.labeled": { readonly label: Pick<Label, "name" | "color"> };
21 "task.unlabeled": { readonly label: Pick<Label, "name" | "color"> };
22 "pull.opened": { readonly title: string };
23 /** With `thread`, a comment in that review thread. */
24 "pull.commented": { readonly body: string; readonly html: string; readonly editedAt: Timestamp | null; readonly thread?: number };
25 "pull.thread_addressed": { readonly thread: number; readonly commit: string };
26 "pull.thread_resolved": { readonly thread: number };
27 "pull.thread_reopened": { readonly thread: number };
28 "pull.closed": Record<string, never>;
29 "pull.reopened": Record<string, never>;
30 "pull.merged": { readonly head: string };
31 "pull.renamed": { readonly from: string; readonly to: string };
32 "repo.created": { readonly name: string; readonly visibility: Visibility };
33 "repo.forked": { readonly name: string; readonly from: string };
34 "repo.imported": { readonly name: string; readonly url: string };
35 "repo.updated": { readonly description?: string; readonly visibility?: Visibility };
36 "repo.deleted": { readonly name: string };
37 "repo.pushed": { readonly updates: readonly { readonly ref: string; readonly from: string | null; readonly to: string | null }[] };
38 "session.started": { readonly runtime: string };
39 /** The session took a branch, or let it go with `branch: null`. The name is historical: sessions do not take tasks. */
40 "session.tasked": { readonly session: string; readonly branch?: string | null };
41 "agent.permission_requested": { readonly session: string; readonly request_id: string; readonly tool: string; readonly description: string; readonly preview: string };
42 "agent.permission_decided": { readonly session: string; readonly request_id: string; readonly behavior: "allow" | "deny" | "withdrawn" };
43 "agent.mentioned": { readonly session: string; readonly title: string; readonly comment: number | null; readonly body: string; readonly assigned: boolean; readonly run: boolean; readonly wake?: boolean; readonly pull: number; readonly thread?: number };
44 /** One model turn of a hosted agent's run: what it thought, when the model shares it, and the tools it called. */
45 "agent.step": { readonly session: string; readonly step: number; readonly thinking: string; readonly tools: readonly string[] };
46 "agent.run_finished": { readonly session: string; readonly run: string; readonly mention: string | null; readonly ok: boolean; readonly summary: string };
47 "session.problem": { readonly commit: string; readonly message: string };
48 "session.instructed": { readonly session: string; readonly body: string };
49 "session.ended": { readonly session: string; readonly outcome: "finished" | "failed"; readonly reason: string };
50 "member.invited": { readonly email: string; readonly role: Role };
51 "member.joined": { readonly person: PersonRef; readonly role: Role };
52 "invitation.revoked": { readonly email: string };
53}
54
55export type EventKind = keyof Payloads;
56
57export type RefsEvent = {
58 [K in EventKind]: {
59 readonly id: Id;
60 readonly stream: Stream;
61 readonly kind: K;
62 readonly data: Payloads[K];
63 readonly by: Attribution;
64 readonly at: Timestamp;
65 /**
66 * The event this one follows from, when it is not simply the previous event on its stream.
67 * Reserved for the code graph, where work can branch from any earlier point.
68 */
69 readonly parent: Id | null;
70 };
71}[EventKind];
72
73export type EventOf<K extends EventKind> = Extract<RefsEvent, { kind: K }>;
74
75/** A comment's status from the viewer's side, so the UI can offer edit and delete. */
76export interface CommentPermissions {
77 readonly edit: boolean;
78 readonly delete: boolean;
79}
80
81export type TimelineItem = RefsEvent & { readonly can?: CommentPermissions };
82
83export type { TaskStatus };