@deliverd/sdk 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -168,7 +168,7 @@ export interface CommentThread {
168
168
  }[];
169
169
  [key: string]: unknown;
170
170
  }
171
- export type WebhookEventName = "report.published" | "report.updated" | "report.shared" | "report.viewed" | "comment.created" | "access.requested" | "schedule.due" | "publish.held" | "approval.requested" | "approval.approved" | "approval.rejected" | "approval.expired" | "approval.question" | "approval.answered";
171
+ export type WebhookEventName = "report.published" | "report.updated" | "report.shared" | "report.viewed" | "comment.created" | "access.requested" | "schedule.due" | "publish.held" | "approval.requested" | "approval.approved" | "approval.rejected" | "approval.expired" | "approval.question" | "approval.answered" | "review.requested" | "review.approved" | "review.changes_requested";
172
172
  export interface WebhookEvent {
173
173
  event: WebhookEventName;
174
174
  sentAt: string;
@@ -176,4 +176,86 @@ export interface WebhookEvent {
176
176
  test?: boolean;
177
177
  data: Record<string, unknown>;
178
178
  }
179
+ export type ReviewStatus = "pending" | "approved" | "changes_requested" | "expired" | "cancelled";
180
+ export interface CreateReviewInput {
181
+ /** What is being reviewed, as a headline the reviewer sees first. */
182
+ title: string;
183
+ /**
184
+ * What to check. Without this a reviewer decides what "review" means, and
185
+ * usually decides it means "looks fine".
186
+ */
187
+ instructions?: string;
188
+ /** The published report under review; the reviewer reads it and comments on it. */
189
+ reportId?: string;
190
+ /** Pin a version, so publishing again mid-review does not move the ground. */
191
+ versionId?: string;
192
+ /**
193
+ * Emails or user ids. An active member, or a guest who can already open the
194
+ * report — anyone else is refused rather than emailed. You cannot name
195
+ * yourself.
196
+ */
197
+ reviewers: string[];
198
+ /**
199
+ * How many approvals settle it; one when omitted. A single "changes
200
+ * requested" settles it regardless.
201
+ */
202
+ requiredApprovals?: number;
203
+ /** After this the review expires unanswered. ISO 8601. */
204
+ expiresAt?: string;
205
+ /** Your own reference, returned unchanged and searchable. */
206
+ externalId?: string;
207
+ metadata?: Record<string, unknown>;
208
+ }
209
+ export interface ReviewerRef {
210
+ kind: "user" | "guest";
211
+ id: string;
212
+ label: string;
213
+ }
214
+ export interface ReviewVerdict {
215
+ verdict: "approved" | "changes_requested";
216
+ /** Who gave it, as a name rather than an id. */
217
+ by: string;
218
+ note: string | null;
219
+ at: string;
220
+ }
221
+ export interface ReviewData {
222
+ id: string;
223
+ status: ReviewStatus;
224
+ /** The page the reviewer reads and decides on. */
225
+ url: string;
226
+ title: string;
227
+ instructions: string | null;
228
+ reportId: string | null;
229
+ versionId: string | null;
230
+ externalId: string | null;
231
+ metadata: Record<string, unknown>;
232
+ requestedBy: string;
233
+ requiredApprovals: number;
234
+ reviewers: ReviewerRef[];
235
+ verdicts: ReviewVerdict[];
236
+ /** How many comment threads the reviewers opened while reading. */
237
+ threadCount: number;
238
+ settledAt: string | null;
239
+ expiresAt: string | null;
240
+ createdAt: string;
241
+ }
242
+ /** The answer, flattened — what `review()` hands back. */
243
+ export interface ReviewOutcome {
244
+ /** The one to branch on. False for changes requested, expired and cancelled. */
245
+ approved: boolean;
246
+ status: Exclude<ReviewStatus, "pending">;
247
+ /** Every verdict returned, in the order they arrived. */
248
+ verdicts: ReviewVerdict[];
249
+ /** How many comment threads to read before producing the next version. */
250
+ threadCount: number;
251
+ id: string;
252
+ url: string;
253
+ review: ReviewData;
254
+ }
255
+ export interface ListReviewsInput {
256
+ status?: ReviewStatus;
257
+ externalId?: string;
258
+ reportId?: string;
259
+ limit?: number;
260
+ }
179
261
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,CAAC;AAC3F,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UA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G,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,0DAA0D;AAC1D,MAAM,WAAW,aAAa;IAC5B,gFAAgF;IAChF,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IACzC,yDAAyD;IACzD,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,0EAA0E;IAC1E,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deliverd/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Add human approval to any AI agent. Ask a person, wait for the answer, act on it.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/dev.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ApprovalData } from "./types.js";
1
+ import type { ApprovalData, ReviewData } from "./types.js";
2
2
 
3
3
  /**
4
4
  * Development mode: the whole loop, on your machine, with nobody in it.
@@ -52,7 +52,7 @@ interface Stored {
52
52
  }
53
53
 
54
54
  /**
55
- * A `fetch` that serves the approvals API from memory.
55
+ * A `fetch` that serves the approvals and reviews APIs from memory.
56
56
  *
57
57
  * Deliberately narrow: it answers the calls the primitives make and 501s the
58
58
  * rest, with a message saying so, rather than pretending to be the whole API
@@ -60,6 +60,7 @@ interface Stored {
60
60
  */
61
61
  export function developmentFetch(options: DevelopmentOptions = {}): typeof globalThis.fetch {
62
62
  const store = new Map<string, Stored>();
63
+ const reviewStore = new Map<string, StoredReview>();
63
64
 
64
65
  return (async (input: string | URL | Request, init?: RequestInit) => {
65
66
  const url = new URL(String(input));
@@ -147,11 +148,80 @@ export function developmentFetch(options: DevelopmentOptions = {}): typeof globa
147
148
  return json(stored.data);
148
149
  }
149
150
 
151
+ if (method === "POST" && path === "/reviews") {
152
+ const id = `rev_dev_${++counter}`;
153
+ /*
154
+ * The same outcome switch as approvals, mapped onto a review's endings:
155
+ * a rejection is "changes requested", because that is what saying no to
156
+ * a piece of work means. A simulated question has nothing to ask about
157
+ * here — there is no question mechanism on a review — so it approves.
158
+ */
159
+ const outcome = resolveOutcome(options.outcome, body);
160
+ const verdict = outcome === "rejected" ? "changes_requested" : "approved";
161
+ const reviewers = ((body.reviewers as string[] | undefined) ?? []).map((email, i) => ({
162
+ kind: "user" as const,
163
+ id: `usr_dev_${i + 1}`,
164
+ label: email,
165
+ }));
166
+ const data: ReviewData = {
167
+ id,
168
+ status: "pending",
169
+ url: `https://deliverd.dev/reviews/${id}`,
170
+ title: String(body.title ?? "Untitled"),
171
+ instructions: (body.instructions as string | undefined) ?? null,
172
+ reportId: (body.reportId as string | undefined) ?? null,
173
+ versionId: (body.versionId as string | undefined) ?? null,
174
+ externalId: (body.externalId as string | undefined) ?? null,
175
+ metadata: (body.metadata as Record<string, unknown>) ?? {},
176
+ requestedBy: "You (development mode)",
177
+ requiredApprovals: (body.requiredApprovals as number | undefined) ?? 1,
178
+ reviewers,
179
+ verdicts: [],
180
+ threadCount: 0,
181
+ settledAt: null,
182
+ expiresAt: (body.expiresAt as string | undefined) ?? null,
183
+ createdAt: new Date().toISOString(),
184
+ };
185
+ reviewStore.set(id, {
186
+ data,
187
+ settleAt: Date.now() + (options.delay ?? 0),
188
+ verdict,
189
+ timeout: outcome === "timeout",
190
+ });
191
+ if (options.log !== false) announceReview(data, verdict, outcome === "timeout");
192
+ return json(data, 201);
193
+ }
194
+
195
+ const reviewMatch = /^\/reviews\/([^/]+)(\/cancel)?$/.exec(path);
196
+ if (reviewMatch) {
197
+ const stored = reviewStore.get(reviewMatch[1]!);
198
+ if (!stored) {
199
+ return json(
200
+ { error: { code: "not_found", message: "No such review in this development session." } },
201
+ 404
202
+ );
203
+ }
204
+ if (reviewMatch[2] === "/cancel") {
205
+ stored.data.status = "cancelled";
206
+ return json(stored.data);
207
+ }
208
+ settleReview(stored);
209
+ return json(stored.data);
210
+ }
211
+
212
+ if (method === "GET" && path === "/reviews") {
213
+ const externalId = url.searchParams.get("externalId");
214
+ const all = [...reviewStore.values()].map((r) => r.data);
215
+ return json({
216
+ reviews: externalId ? all.filter((r) => r.externalId === externalId) : all,
217
+ });
218
+ }
219
+
150
220
  return json(
151
221
  {
152
222
  error: {
153
223
  code: "not_in_development_mode",
154
- message: `Development mode simulates approvals only, and something called ${method} ${path}. Use a real API key for the rest of the API.`,
224
+ message: `Development mode simulates approvals and reviews only, and something called ${method} ${path}. Use a real API key for the rest of the API.`,
155
225
  },
156
226
  },
157
227
  501
@@ -211,3 +281,48 @@ function announce(data: ApprovalData, outcome: DevelopmentOutcome): void {
211
281
  );
212
282
  console.log(lines.join("\n"));
213
283
  }
284
+
285
+
286
+ interface StoredReview {
287
+ data: ReviewData;
288
+ settleAt: number;
289
+ verdict: "approved" | "changes_requested";
290
+ timeout: boolean;
291
+ }
292
+
293
+ /** Settle it once its moment has passed, unless it is meant to hang. */
294
+ function settleReview(stored: StoredReview): void {
295
+ if (stored.timeout || stored.data.status !== "pending") return;
296
+ if (Date.now() < stored.settleAt) return;
297
+ stored.data.verdicts = [
298
+ {
299
+ verdict: stored.verdict,
300
+ by: stored.data.reviewers[0]?.label ?? "A reviewer (development mode)",
301
+ note:
302
+ stored.verdict === "changes_requested"
303
+ ? "Simulated: the figures on page two do not tie back."
304
+ : null,
305
+ at: new Date().toISOString(),
306
+ },
307
+ ];
308
+ stored.data.status = stored.verdict;
309
+ stored.data.settledAt = new Date().toISOString();
310
+ }
311
+
312
+ function announceReview(
313
+ data: ReviewData,
314
+ verdict: "approved" | "changes_requested",
315
+ willHang: boolean
316
+ ): void {
317
+ const lines = [
318
+ ` ┌─ Deliverd · development mode ─────────────────────────`,
319
+ ` │ ${data.title}`,
320
+ ...(data.instructions ? [` │ Check: ${data.instructions}`] : []),
321
+ ` │ Reviewers: ${data.reviewers.map((r) => r.label).join(", ") || "nobody named"}`,
322
+ ` │`,
323
+ ` │ Simulating: ${willHang ? "nobody reviews it" : verdict.replace("_", " ")}`,
324
+ ` └───────────────────────────────────────────────────────`,
325
+ "",
326
+ ];
327
+ console.log(lines.join("\n"));
328
+ }
package/src/index.ts CHANGED
@@ -1,19 +1,23 @@
1
1
  import { HttpClient, type ClientOptions } from "./http.js";
2
2
  import { Approvals, FAST_POLL_SCHEDULE, type WaitOptions } from "./approvals.js";
3
3
  import { Comments, Reports } from "./reports.js";
4
+ import { Reviews, type ReviewWaitOptions } from "./reviews.js";
4
5
  import { Webhooks } from "./webhooks.js";
5
6
  import { developmentFetch, type DevelopmentOptions } from "./dev.js";
6
7
  import { durationMs, type Duration } from "./duration.js";
7
8
  import { DeliverdError } from "./errors.js";
8
9
  import type {
9
10
  CreateApprovalInput,
11
+ CreateReviewInput,
10
12
  Decision,
11
13
  PublishReportInput,
12
14
  PublishResult,
15
+ ReviewOutcome,
13
16
  } from "./types.js";
14
17
 
15
18
  export { Approval, Approvals, POLL_SCHEDULE, type WaitOptions } from "./approvals.js";
16
19
  export { Comments, Reports } from "./reports.js";
20
+ export { Review, Reviews, type ReviewWaitOptions } from "./reviews.js";
17
21
  export {
18
22
  constructEvent,
19
23
  DELIVERY_HEADER,
@@ -66,6 +70,24 @@ export interface ApproveOptions extends Omit<CreateApprovalInput, "expiresAt"> {
66
70
  reuse?: boolean;
67
71
  }
68
72
 
73
+ /** Everything `review()` takes, plus the conveniences it adds on top. */
74
+ export interface ReviewOptions extends Omit<CreateReviewInput, "expiresAt"> {
75
+ /** `"4h"`, `"30m"`, `"2d"`, or milliseconds. Default 24 hours. */
76
+ expiresIn?: Duration;
77
+ /** An exact moment instead, if you have one. */
78
+ expiresAt?: string;
79
+ /** Called after each poll — a progress line in a CLI. */
80
+ onPoll?: ReviewWaitOptions["onPoll"];
81
+ /** Give up waiting after this. The review stays open until it expires. */
82
+ timeout?: Duration;
83
+ signal?: AbortSignal;
84
+ /**
85
+ * With an `externalId`, reuse an existing review rather than filing a
86
+ * second one, so a restarted agent does not ask the same people twice.
87
+ */
88
+ reuse?: boolean;
89
+ }
90
+
69
91
  /**
70
92
  * Deliverd: you build the action, Deliverd handles the human.
71
93
  *
@@ -87,6 +109,7 @@ export interface ApproveOptions extends Omit<CreateApprovalInput, "expiresAt"> {
87
109
  */
88
110
  export class Deliverd {
89
111
  readonly approvals: Approvals;
112
+ readonly reviews: Reviews;
90
113
  readonly reports: Reports;
91
114
  readonly comments: Comments;
92
115
  readonly webhooks: Webhooks;
@@ -107,6 +130,7 @@ export class Deliverd {
107
130
  });
108
131
 
109
132
  this.approvals = new Approvals(this.http);
133
+ this.reviews = new Reviews(this.http);
110
134
  this.reports = new Reports(this.http);
111
135
  this.comments = new Comments(this.http);
112
136
  this.webhooks = new Webhooks();
@@ -177,6 +201,63 @@ export class Deliverd {
177
201
  return decision.approved;
178
202
  }
179
203
 
204
+ /**
205
+ * Ask people to read what you made, and wait for their answer.
206
+ *
207
+ * The other half of judgement. `approve()` asks permission before you act;
208
+ * this asks whether what you already produced is right, and comes back with
209
+ * the reviewers' verdicts and a count of the comment threads they opened.
210
+ *
211
+ * ```ts
212
+ * const outcome = await deliverd.review({
213
+ * title: "Q3 board pack",
214
+ * reportId: report.id,
215
+ * instructions: "Check the figures against the ledger.",
216
+ * reviewers: ["partner@firm.example"],
217
+ * });
218
+ * if (!outcome.approved) await revise(outcome.verdicts);
219
+ * ```
220
+ *
221
+ * Resolves on changes requested as well as approval, because that is an
222
+ * answer — usually the more useful one. Reviews expire after a day unless
223
+ * you say otherwise, so a wait always ends.
224
+ */
225
+ async review(options: ReviewOptions): Promise<ReviewOutcome> {
226
+ const { expiresIn, timeout, onPoll, signal, reuse, ...input } = options;
227
+
228
+ if (input.externalId && reuse !== false) {
229
+ const existing = await this.reviews.findByExternalId(input.externalId, signal);
230
+ if (existing) {
231
+ const settled = await existing.wait({
232
+ onPoll,
233
+ signal,
234
+ timeout: durationOrUndefined(timeout),
235
+ ...(this.development ? { pollIntervals: FAST_POLL_SCHEDULE } : {}),
236
+ });
237
+ return settled.toOutcome();
238
+ }
239
+ }
240
+
241
+ const review = await this.reviews.create(
242
+ {
243
+ ...input,
244
+ expiresAt:
245
+ options.expiresAt ??
246
+ new Date(Date.now() + durationMs(expiresIn ?? DEFAULT_EXPIRY)).toISOString(),
247
+ },
248
+ signal
249
+ );
250
+ const settled = await review.wait({
251
+ onPoll,
252
+ signal,
253
+ // Same reasoning as approve(): in development the reviewer is imaginary
254
+ // and instant, so a wait still running after a moment will never settle.
255
+ timeout: durationOrUndefined(timeout) ?? (this.development ? 2_000 : undefined),
256
+ ...(this.development ? { pollIntervals: FAST_POLL_SCHEDULE } : {}),
257
+ });
258
+ return settled.toOutcome();
259
+ }
260
+
180
261
  /** Publish HTML to a secure URL. The other half of the product, one call in. */
181
262
  publish(input: PublishReportInput, signal?: AbortSignal): Promise<PublishResult> {
182
263
  return this.reports.publish(input, signal);
package/src/reviews.ts ADDED
@@ -0,0 +1,208 @@
1
+ import { DeliverdError, DeliverdTimeoutError } from "./errors.js";
2
+ import type { HttpClient } from "./http.js";
3
+ import { POLL_SCHEDULE } from "./approvals.js";
4
+ import type {
5
+ CreateReviewInput,
6
+ ListReviewsInput,
7
+ ReviewData,
8
+ ReviewOutcome,
9
+ } from "./types.js";
10
+
11
+ /**
12
+ * Ask people to read what you made and say whether it is right.
13
+ *
14
+ * The sibling of approvals, and the difference is worth keeping straight: an
15
+ * approval asks permission for something that has not happened, a review asks
16
+ * judgement on something that has. The waiting is the same shape, so the
17
+ * polling is shared.
18
+ */
19
+
20
+ export interface ReviewWaitOptions {
21
+ /** Called after every poll, for a progress line in a CLI. */
22
+ onPoll?: (review: ReviewData) => void;
23
+ /**
24
+ * Give up after this many milliseconds and throw `DeliverdTimeoutError`.
25
+ * Omitted, the wait ends when the review does — which, for a review with no
26
+ * `expiresAt`, may be never. Set one or the other.
27
+ */
28
+ timeout?: number;
29
+ signal?: AbortSignal;
30
+ /** How long between polls, as the wait lengthens. Rarely worth changing. */
31
+ pollIntervals?: readonly number[];
32
+ }
33
+
34
+ function pollDelay(poll: number, schedule: readonly number[]): number {
35
+ const base = schedule[Math.min(poll, schedule.length - 1)] ?? 60_000;
36
+ // Jitter, so a hundred agents started by the same cron do not arrive together.
37
+ return base * 0.75 + Math.random() * base * 0.5;
38
+ }
39
+
40
+ /** A review, and what you can do with it. */
41
+ export class Review {
42
+ constructor(
43
+ private readonly http: HttpClient,
44
+ private data: ReviewData
45
+ ) {}
46
+
47
+ get id(): string { return this.data.id; }
48
+ get status(): ReviewData["status"] { return this.data.status; }
49
+ /** The page the reviewer reads and decides on. */
50
+ get url(): string { return this.data.url; }
51
+ get title(): string { return this.data.title; }
52
+ get verdicts(): ReviewData["verdicts"] { return this.data.verdicts; }
53
+ /** How many comment threads the reviewers opened while reading. */
54
+ get threadCount(): number { return this.data.threadCount; }
55
+
56
+ /** The one to branch on. False for changes requested, expired and cancelled. */
57
+ get approved(): boolean { return this.data.status === "approved"; }
58
+ get changesRequested(): boolean { return this.data.status === "changes_requested"; }
59
+ get expired(): boolean { return this.data.status === "expired"; }
60
+ get cancelled(): boolean { return this.data.status === "cancelled"; }
61
+ get pending(): boolean { return this.data.status === "pending"; }
62
+
63
+ /** Everything the API returned, if you want a field the getters do not name. */
64
+ toJSON(): ReviewData { return this.data; }
65
+
66
+ toOutcome(): ReviewOutcome {
67
+ const status = this.data.status === "pending" ? "expired" : this.data.status;
68
+ return {
69
+ approved: this.data.status === "approved",
70
+ status,
71
+ verdicts: this.data.verdicts,
72
+ threadCount: this.data.threadCount,
73
+ id: this.data.id,
74
+ url: this.data.url,
75
+ review: this.data,
76
+ } as ReviewOutcome;
77
+ }
78
+
79
+ async refresh(signal?: AbortSignal): Promise<this> {
80
+ this.data = await this.http.request<ReviewData>({
81
+ method: "GET",
82
+ path: `/reviews/${this.data.id}`,
83
+ signal,
84
+ });
85
+ return this;
86
+ }
87
+
88
+ /** Withdraw it. The row stays as evidence of what was asked and dropped. */
89
+ async cancel(signal?: AbortSignal): Promise<this> {
90
+ this.data = await this.http.request<ReviewData>({
91
+ method: "POST",
92
+ path: `/reviews/${this.data.id}/cancel`,
93
+ signal,
94
+ });
95
+ return this;
96
+ }
97
+
98
+ /**
99
+ * Block until the reviewers settle it, then return.
100
+ *
101
+ * Resolves on every ending, including changes requested — that is an answer
102
+ * and the most useful one, because it comes with the threads that say what
103
+ * to change. It throws only when the wait itself failed: a timeout, an
104
+ * abort, or an API that could not be reached.
105
+ */
106
+ async wait(options: ReviewWaitOptions = {}): Promise<this> {
107
+ const deadline = options.timeout !== undefined ? Date.now() + options.timeout : undefined;
108
+ let poll = 0;
109
+ if (!this.pending) return this;
110
+
111
+ for (;;) {
112
+ if (options.signal?.aborted) {
113
+ throw new DeliverdError(0, "aborted", "The wait was aborted.", undefined, {
114
+ cause: options.signal.reason,
115
+ });
116
+ }
117
+ if (deadline !== undefined && Date.now() >= deadline) {
118
+ throw new DeliverdTimeoutError(
119
+ `Nobody finished reviewing "${this.data.title}" within the timeout. It is still open at ${this.data.url}.`
120
+ );
121
+ }
122
+ const delay = pollDelay(poll++, options.pollIntervals ?? POLL_SCHEDULE);
123
+ const remaining = deadline === undefined ? delay : Math.min(delay, deadline - Date.now());
124
+ await sleep(Math.max(0, remaining), options.signal);
125
+
126
+ await this.refresh(options.signal);
127
+ options.onPoll?.(this.data);
128
+ if (!this.pending) return this;
129
+ }
130
+ }
131
+ }
132
+
133
+ function sleep(ms: number, signal?: AbortSignal): Promise<void> {
134
+ return new Promise((resolve, reject) => {
135
+ if (signal?.aborted) {
136
+ return reject(new DeliverdError(0, "aborted", "The wait was aborted."));
137
+ }
138
+ const timer = setTimeout(() => {
139
+ signal?.removeEventListener("abort", onAbort);
140
+ resolve();
141
+ }, ms);
142
+ const onAbort = () => {
143
+ clearTimeout(timer);
144
+ reject(new DeliverdError(0, "aborted", "The wait was aborted."));
145
+ };
146
+ signal?.addEventListener("abort", onAbort, { once: true });
147
+ });
148
+ }
149
+
150
+ export class Reviews {
151
+ constructor(private readonly http: HttpClient) {}
152
+
153
+ /**
154
+ * Ask. Returns as soon as the request is filed — the reviewers are being
155
+ * told while this resolves — so call `wait()` next, or keep the id and poll
156
+ * later.
157
+ */
158
+ async create(input: CreateReviewInput, signal?: AbortSignal): Promise<Review> {
159
+ const data = await this.http.request<ReviewData>({
160
+ method: "POST",
161
+ path: "/reviews",
162
+ body: input,
163
+ signal,
164
+ });
165
+ return new Review(this.http, data);
166
+ }
167
+
168
+ async get(id: string, signal?: AbortSignal): Promise<Review> {
169
+ const data = await this.http.request<ReviewData>({
170
+ method: "GET",
171
+ path: `/reviews/${id}`,
172
+ signal,
173
+ });
174
+ return new Review(this.http, data);
175
+ }
176
+
177
+ async list(input: ListReviewsInput = {}, signal?: AbortSignal): Promise<Review[]> {
178
+ const { reviews } = await this.http.request<{ reviews: ReviewData[] }>({
179
+ method: "GET",
180
+ path: "/reviews",
181
+ query: {
182
+ status: input.status,
183
+ externalId: input.externalId,
184
+ reportId: input.reportId,
185
+ limit: input.limit,
186
+ },
187
+ signal,
188
+ });
189
+ return reviews.map((r) => new Review(this.http, r));
190
+ }
191
+
192
+ /** Ask and wait, for the common case where there is nothing to do between. */
193
+ async request(input: CreateReviewInput, options: ReviewWaitOptions = {}): Promise<Review> {
194
+ const review = await this.create(input, options.signal);
195
+ return review.wait(options);
196
+ }
197
+
198
+ /**
199
+ * The same request as before, when there was one — so restarting a crashed
200
+ * agent does not ask the same people twice. The caveat is the one
201
+ * `approvals.findByExternalId` carries: two concurrent calls can still both
202
+ * find nothing and both create.
203
+ */
204
+ async findByExternalId(externalId: string, signal?: AbortSignal): Promise<Review | null> {
205
+ const found = await this.list({ externalId, limit: 1 }, signal);
206
+ return found[0] ?? null;
207
+ }
208
+ }