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