g1t/packages/contracts/src/webhooks.ts
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.
| Webhooks: every event, to your own addresses, signed and retried | 1 | import type { User, Viewer } from "./identity"; |
| 2 | import type { RepoPath } from "./repos"; | |
| 3 | import type { Result } from "./result"; | |
| 4 | ||
| 5 | /** | |
| 6 | * Events, delivered to the addresses a repository or a workspace registers. | |
| 7 | * Mirrors `crates/contracts/src/webhooks.rs`. | |
| 8 | */ | |
| 9 | ||
| 10 | /** Every event a webhook can be sent, in the order people are shown them. */ | |
| 11 | export const EVENT_TYPES = [ | |
| 12 | "git.push", | |
| 13 | "repo.created", | |
| 14 | "repo.forked", | |
| 15 | "issue.opened", | |
| 16 | "issue.updated", | |
| 17 | "issue.assigned", | |
| 18 | "issue.closed", | |
| 19 | "issue.reopened", | |
| 20 | "comment.created", | |
| 21 | "pull.opened", | |
| 22 | "pull.ready", | |
| 23 | "pull.updated", | |
| 24 | "pull.merge_requested", | |
| 25 | "pull.merged", | |
| 26 | "pull.closed", | |
| Agents asked while not at work are woken to answer | 27 | "agent.asked", |
| Webhooks: every event, to your own addresses, signed and retried | 28 | "checks.completed", |
| 29 | "review.completed", | |
| Actions: workflow_run, workflow.completed, artifacts on the run page, Node 24 | 30 | "workflow.completed", |
| Webhooks: every event, to your own addresses, signed and retried | 31 | "queue.changed", |
| 32 | "session.appended", | |
| 33 | ] as const; | |
| 34 | ||
| 35 | export type Hook = { | |
| 36 | id: string; | |
| 37 | scope: "repo" | "workspace"; | |
| 38 | workspace: string; | |
| 39 | /** For a repository's webhook: `owner/name`. */ | |
| 40 | repo: string | null; | |
| 41 | url: string; | |
| 42 | /** Event types, or `["*"]` for all. */ | |
| 43 | events: string[]; | |
| 44 | active: boolean; | |
| 45 | secretHint: string; | |
| 46 | createdBy: string; | |
| 47 | createdAt: string; | |
| 48 | lastStatus: "delivered" | "pending" | "failed" | null; | |
| 49 | lastDeliveredAt: string | null; | |
| 50 | }; | |
| 51 | ||
| 52 | export type HookDelivery = { | |
| 53 | id: string; | |
| 54 | hookId: string; | |
| 55 | eventId: string; | |
| 56 | event: string; | |
| 57 | status: "pending" | "delivered" | "failed"; | |
| 58 | attempts: number; | |
| 59 | responseStatus: number | null; | |
| 60 | responseBody: string | null; | |
| 61 | error: string | null; | |
| 62 | durationMs: number | null; | |
| 63 | /** The JSON that was sent. */ | |
| 64 | payload: string; | |
| 65 | createdAt: string; | |
| 66 | deliveredAt: string | null; | |
| 67 | nextAttemptAt: string | null; | |
| 68 | }; | |
| 69 | ||
| 70 | /** A repository's webhooks, or with `repo` left out, the workspace's own. */ | |
| 71 | export type HookOwner = { workspace: string; repo?: RepoPath }; | |
| 72 | ||
| 73 | export interface WebhooksApi { | |
| 74 | list(viewer: Viewer, owner: HookOwner): Promise<Result<Hook[]>>; | |
| 75 | create( | |
| 76 | actor: User, | |
| 77 | owner: HookOwner, | |
| 78 | input: { url: string; events?: string[]; secret?: string }, | |
| 79 | ): Promise<Result<{ hook: Hook; secret: string | null }>>; | |
| 80 | update(actor: User, owner: HookOwner, id: string, input: { url?: string; events?: string[]; active?: boolean }): Promise<Result<Hook>>; | |
| 81 | delete(actor: User, owner: HookOwner, id: string): Promise<Result<boolean>>; | |
| 82 | ping(actor: User, owner: HookOwner, id: string): Promise<Result<HookDelivery>>; | |
| 83 | deliveries(viewer: Viewer, owner: HookOwner, id: string): Promise<Result<HookDelivery[]>>; | |
| 84 | redeliver(actor: User, owner: HookOwner, deliveryId: string): Promise<Result<HookDelivery>>; | |
| 85 | } |