Open History to see the last commit
1import {
2 WS_METHODS,
3 type EnvironmentId,
4 type PullRequestActor,
5 type PullRequestActionInput,
6 type PullRequestDetail,
7 type PullRequestDiffInput,
8 type PullRequestRef,
9 type PullRequestMergeMethod,
10 PullRequestOperationError,
11 type PullRequestSummary,
12 type VcsStatusResult,
13} from "@t3tools/contracts";
14import * as Data from "effect/Data";
15import * as Effect from "effect/Effect";
16import * as Option from "effect/Option";
17import * as SubscriptionRef from "effect/SubscriptionRef";
18import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
19
20import {
21 createAtomCommandScheduler,
22 createEnvironmentRpcCommand,
23 createEnvironmentRpcQueryAtomFamily,
24 createEnvironmentRpcSubscriptionAtomFamily,
25 createEnvironmentQueryAtomFamily,
26} from "./runtime.ts";
27import { createPullRequestRouter } from "./pullRequestRouting.ts";
28import * as PullRequestDiffLoader from "./pullRequestDiffHttp.ts";
29import type { EnvironmentRegistry } from "../connection/registry.ts";
30import * as EnvironmentSupervisor from "../connection/supervisor.ts";
31
32export {
33 type PullRequestDiffLoadError,
34 PullRequestDiffCredentialRejectedError,
35} from "./pullRequestDiffHttp.ts";
36export * as PullRequestDiffLoader from "./pullRequestDiffHttp.ts";
37
38/** @public Required to name the error in consumers' inferred pull request results. */
39export class EnvironmentHttpConnectionNotReadyError extends Data.TaggedError(
40 "EnvironmentHttpConnectionNotReadyError",
41)<{ readonly message: string }> {}
42
43const LINKED_PULL_REQUEST_IDLE_TTL_MS = 5_000;
44
45/** Keep confirmed edits on the same cached reference regardless of input property order. */
46function writableQueryFamily<A, E>(
47 family: (target: {
48 readonly environmentId: EnvironmentId;
49 readonly input: PullRequestRef;
50 }) => Atom.Atom<AsyncResult.AsyncResult<A, E>>,
51) {
52 const writable = Atom.family((source: Atom.Atom<AsyncResult.AsyncResult<A, E>>) =>
53 Atom.writable(
54 (get) => {
55 const result = get(source);
56 if (result._tag === "Success" && !result.waiting) return result;
57 const previous = get.self<AsyncResult.AsyncResult<A, E>>();
58 const value = Option.flatMap(previous, AsyncResult.value);
59 if (Option.isNone(value)) return result;
60 return result._tag === "Failure"
61 ? AsyncResult.failureWithPrevious(result.cause, { previous, waiting: result.waiting })
62 : AsyncResult.success<A, E>(value.value, result);
63 },
64 (context, value: AsyncResult.AsyncResult<A, E>) => context.setSelf(value),
65 (refresh) => refresh(source),
66 ).pipe(Atom.setIdleTTL(5 * 60_000)),
67 );
68 return ({
69 environmentId,
70 input: { projectId, host, repository, number, allowStale },
71 }: Parameters<typeof family>[0]) =>
72 writable(
73 family({
74 environmentId,
75 input: {
76 projectId,
77 ...(host === undefined ? {} : { host }),
78 repository,
79 number,
80 ...(allowStale === undefined ? {} : { allowStale }),
81 },
82 }),
83 );
84}
85
86/** Restart pre-mutation reads before patching so they cannot restore stale values. */
87function updateCached<A, E>(
88 registry: AtomRegistry.AtomRegistry,
89 atom: Atom.Writable<AsyncResult.AsyncResult<A, E>>,
90 update: (value: A) => A,
91 refresh = false,
92) {
93 if (refresh || registry.get(atom).waiting) registry.refresh(atom);
94 registry.update(atom, AsyncResult.map(update));
95}
96
97function createPullRequestRefreshAtomFamily<R, E>(
98 runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
99) {
100 return createEnvironmentRpcSubscriptionAtomFamily(runtime, {
101 label: "environment-data:pull-requests:turn-refreshes",
102 tag: WS_METHODS.pullRequestsSubscribeRefreshes,
103 });
104}
105
106/** Refresh only the live fields a linked thread renders. */
107export function createLinkedPullRequestSummaryAtomFamily<R, E>(
108 runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
109 refreshes = createPullRequestRefreshAtomFamily(runtime),
110) {
111 const routedRequest = createPullRequestRouter();
112 return createEnvironmentRpcQueryAtomFamily(runtime, {
113 label: "environment-data:pull-requests:linked-summary",
114 tag: WS_METHODS.pullRequestsSummary,
115 execute: (input) => routedRequest(WS_METHODS.pullRequestsSummary, input),
116 staleTimeMs: 60_000,
117 refreshIntervalMs: 60_000,
118 idleTtlMs: LINKED_PULL_REQUEST_IDLE_TTL_MS,
119 refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
120 });
121}
122
123/** The host-native stack a pull request belongs to; null where it is not stacked. */
124export function createPullRequestStackAtomFamily<R, E>(
125 runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
126 refreshes = createPullRequestRefreshAtomFamily(runtime),
127) {
128 const routedRequest = createPullRequestRouter();
129 return createEnvironmentRpcQueryAtomFamily(runtime, {
130 label: "environment-data:pull-requests:stack",
131 tag: WS_METHODS.pullRequestsStack,
132 execute: (input) => routedRequest(WS_METHODS.pullRequestsStack, input),
133 staleTimeMs: 60_000,
134 idleTtlMs: LINKED_PULL_REQUEST_IDLE_TTL_MS,
135 refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
136 });
137}
138
139export function pullRequestDetailToVcsStatus(
140 detail: PullRequestDetail | PullRequestSummary,
141): NonNullable<VcsStatusResult["pr"]> {
142 return {
143 number: detail.number,
144 title: detail.title,
145 url: detail.url,
146 baseRef: detail.baseBranch,
147 headRef: detail.headBranch,
148 state: detail.state,
149 ...(detail.isDraft === true ? { isDraft: true } : {}),
150 updatedAt: detail.updatedAt,
151 };
152}
153
154/**
155 * Reopening a PR within a minute reuses detail and activity. Explicit refreshes and
156 * turn notifications still revalidate. Mutations run serially per environment: actions on the same
157 * pull request are order-sensitive. Confirmed label and reviewer edits update cached state.
158 */
159export function createPullRequestEnvironmentAtoms<R, E>(
160 runtime: Atom.AtomRuntime<
161 EnvironmentRegistry | PullRequestDiffLoader.PullRequestDiffLoader | R,
162 E
163 >,
164) {
165 const refreshes = createPullRequestRefreshAtomFamily(runtime);
166 const commandScheduler = createAtomCommandScheduler();
167 const routedRequest = createPullRequestRouter();
168 const serialPerEnvironment = {
169 mode: "serial",
170 key: ({ environmentId }: { readonly environmentId: string }) => environmentId,
171 } as const;
172 const activity = writableQueryFamily(
173 createEnvironmentRpcQueryAtomFamily(runtime, {
174 label: "environment-data:pull-requests:activity",
175 tag: WS_METHODS.pullRequestsActivity,
176 execute: (input) => routedRequest(WS_METHODS.pullRequestsActivity, input),
177 staleTimeMs: 60_000,
178 refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
179 }),
180 );
181 const detail = writableQueryFamily(
182 createEnvironmentRpcQueryAtomFamily(runtime, {
183 label: "environment-data:pull-requests:detail",
184 tag: WS_METHODS.pullRequestsDetail,
185 execute: (input) => routedRequest(WS_METHODS.pullRequestsDetail, input),
186 staleTimeMs: 60_000,
187 refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
188 }),
189 );
190 const preview = writableQueryFamily(
191 createEnvironmentRpcQueryAtomFamily(runtime, {
192 label: "environment-data:pull-requests:preview",
193 tag: WS_METHODS.pullRequestsPreview,
194 execute: (input) => routedRequest(WS_METHODS.pullRequestsPreview, input),
195 staleTimeMs: 60_000,
196 refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
197 }),
198 );
199 const labelCandidates = writableQueryFamily(
200 createEnvironmentRpcQueryAtomFamily(runtime, {
201 label: "environment-data:pull-requests:label-candidates",
202 tag: WS_METHODS.pullRequestsLabelCandidates,
203 execute: (input) => routedRequest(WS_METHODS.pullRequestsLabelCandidates, input),
204 staleTimeMs: 60_000,
205 }),
206 );
207 // The stored guide only changes when somebody generates one, which refreshes it below.
208 const reviewGuide = writableQueryFamily(
209 createEnvironmentRpcQueryAtomFamily(runtime, {
210 label: "environment-data:pull-requests:review-guide",
211 tag: WS_METHODS.pullRequestsReviewGuide,
212 execute: (input) => routedRequest(WS_METHODS.pullRequestsReviewGuide, input),
213 staleTimeMs: 60_000,
214 refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
215 }),
216 );
217 const reviewerCandidates = writableQueryFamily(
218 createEnvironmentRpcQueryAtomFamily(runtime, {
219 label: "environment-data:pull-requests:reviewer-candidates",
220 tag: WS_METHODS.pullRequestsReviewerCandidates,
221 execute: (input) => routedRequest(WS_METHODS.pullRequestsReviewerCandidates, input),
222 staleTimeMs: 60_000,
223 }),
224 );
225 return {
226 refreshes,
227 linkedThreads: createEnvironmentRpcQueryAtomFamily(runtime, {
228 label: "environment-data:pull-requests:linked-threads",
229 tag: WS_METHODS.pullRequestsLinkedThreads,
230 staleTimeMs: 0,
231 refreshIntervalMs: 10_000,
232 refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
233 }),
234 list: createEnvironmentRpcQueryAtomFamily(runtime, {
235 label: "environment-data:pull-requests:list",
236 tag: WS_METHODS.pullRequestsList,
237 staleTimeMs: 30_000,
238 refreshTrigger: ({ environmentId, input }) =>
239 input.cursors === undefined ? refreshes({ environmentId, input: {} }) : undefined,
240 }),
241 /**
242 * The line counts for rows the listing has already handed over. Its own query because the
243 * listing is quicker without them — measured over twelve repositories, ~4.0s against ~7.1s —
244 * so the rows arrive first and their stats a moment later. Kept longer than the listing:
245 * a change request's size only moves when somebody pushes to it.
246 */
247 listStats: createEnvironmentRpcQueryAtomFamily(runtime, {
248 label: "environment-data:pull-requests:list-stats",
249 tag: WS_METHODS.pullRequestsListStats,
250 staleTimeMs: 60_000,
251 refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
252 }),
253 detail,
254 preview,
255 checks: createEnvironmentRpcQueryAtomFamily(runtime, {
256 label: "environment-data:pull-requests:checks",
257 tag: WS_METHODS.pullRequestsChecks,
258 execute: (input) => routedRequest(WS_METHODS.pullRequestsChecks, input),
259 staleTimeMs: 45_000,
260 refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
261 }),
262 activity,
263 threadComments: createEnvironmentRpcCommand(runtime, {
264 label: "environment-data:pull-requests:thread-comments",
265 tag: WS_METHODS.pullRequestsThreadComments,
266 execute: (input) => routedRequest(WS_METHODS.pullRequestsThreadComments, input),
267 scheduler: commandScheduler,
268 concurrency: {
269 mode: "singleFlight",
270 key: ({ environmentId, input }) =>
271 JSON.stringify([environmentId, input.threadId, input.cursor]),
272 },
273 }),
274 diff: createEnvironmentQueryAtomFamily(runtime, {
275 label: "environment-data:pull-requests:diff",
276 staleTimeMs: 60_000,
277 execute: (input: PullRequestDiffInput) =>
278 Effect.gen(function* () {
279 const supervisor = yield* EnvironmentSupervisor.EnvironmentSupervisor;
280 const loader = yield* PullRequestDiffLoader.PullRequestDiffLoader;
281 const prepared = yield* SubscriptionRef.get(supervisor.prepared);
282 if (Option.isNone(prepared)) {
283 return yield* new EnvironmentHttpConnectionNotReadyError({
284 message: "The environment HTTP connection is not ready.",
285 });
286 }
287 return yield* loader.load(prepared.value, input);
288 }),
289 }),
290 diffFileContents: createEnvironmentRpcCommand(runtime, {
291 label: "environment-data:pull-requests:diff-file-contents",
292 tag: WS_METHODS.pullRequestsDiffFileContents,
293 execute: (input) => routedRequest(WS_METHODS.pullRequestsDiffFileContents, input),
294 scheduler: commandScheduler,
295 concurrency: {
296 mode: "singleFlight",
297 key: ({ environmentId, input }) =>
298 JSON.stringify([
299 environmentId,
300 input.projectId,
301 input.host?.toLowerCase() ?? null,
302 input.repository,
303 input.number,
304 input.commit ?? null,
305 input.changeType,
306 input.oldPath,
307 input.newPath,
308 ]),
309 },
310 }),
311 filesViewed: createEnvironmentRpcQueryAtomFamily(runtime, {
312 label: "environment-data:pull-requests:files-viewed",
313 tag: WS_METHODS.pullRequestsFilesViewed,
314 execute: (input) => routedRequest(WS_METHODS.pullRequestsFilesViewed, input),
315 staleTimeMs: 15_000,
316 }),
317 /**
318 * One write in flight per change request: the host applies these in order, and a reader
319 * ticking down a file list faster than the round trip would otherwise race their own presses.
320 */
321 setFilesViewed: createEnvironmentRpcCommand(runtime, {
322 label: "environment-data:pull-requests:set-files-viewed",
323 tag: WS_METHODS.pullRequestsSetFilesViewed,
324 execute: (input) => routedRequest(WS_METHODS.pullRequestsSetFilesViewed, input),
325 scheduler: commandScheduler,
326 concurrency: {
327 mode: "serial",
328 key: ({ environmentId, input }) =>
329 JSON.stringify([environmentId, input.projectId, input.repository, input.number]),
330 },
331 }),
332 runAction: createEnvironmentRpcCommand(runtime, {
333 tag: WS_METHODS.pullRequestsRunAction,
334 label: "environment-data:pull-requests:run-action",
335 // Preparation belongs to the write's lane. Refreshable queries would restart it after
336 // every preceding action, and preparing outside the lane could reorder the clicks.
337 execute: (
338 input: PullRequestActionInput & {
339 readonly resolveMergeMethod?: (detail: PullRequestDetail) => PullRequestMergeMethod;
340 },
341 ) =>
342 Effect.gen(function* () {
343 const { resolveMergeMethod, ...actionInput } = input;
344 let preparedInput = actionInput;
345 if (actionInput.action === "merge" && resolveMergeMethod !== undefined) {
346 const { projectId, host, repository, number } = actionInput;
347 const reference = { projectId, host, repository, number, allowStale: false };
348 const detail = yield* routedRequest(WS_METHODS.pullRequestsDetail, reference);
349 if (
350 detail.state !== "open" ||
351 detail.isDraft ||
352 !detail.capabilities.actions.includes("merge") ||
353 !detail.viewerPermissions.actions.includes("merge")
354 ) {
355 return yield* new PullRequestOperationError({
356 operation: "runAction",
357 detail: "This pull request cannot be merged.",
358 });
359 }
360 if (detail.capabilities.stackActions) {
361 const stack = yield* routedRequest(WS_METHODS.pullRequestsStack, reference);
362 if (stack !== null) {
363 return yield* new PullRequestOperationError({
364 operation: "runAction",
365 detail: "Open this pull request to merge its stack.",
366 });
367 }
368 }
369 const mergeMethod = yield* Effect.try({
370 try: () => resolveMergeMethod(detail),
371 catch: (cause) =>
372 new PullRequestOperationError({
373 operation: "runAction",
374 detail:
375 cause instanceof Error ? cause.message : "Could not choose a merge method.",
376 }),
377 });
378 preparedInput = { ...actionInput, mergeMethod };
379 }
380 return yield* routedRequest(WS_METHODS.pullRequestsRunAction, preparedInput);
381 }),
382 onSuccess: ({ environmentId, input }, registry) =>
383 Effect.sync(() => registry.refresh(preview({ environmentId, input }))),
384 scheduler: commandScheduler,
385 concurrency: serialPerEnvironment,
386 }),
387 update: createEnvironmentRpcCommand(runtime, {
388 label: "environment-data:pull-requests:update",
389 tag: WS_METHODS.pullRequestsUpdate,
390 execute: (input) => routedRequest(WS_METHODS.pullRequestsUpdate, input),
391 onSuccess: (target, registry) => Effect.sync(() => registry.refresh(preview(target))),
392 scheduler: commandScheduler,
393 concurrency: serialPerEnvironment,
394 }),
395 comment: createEnvironmentRpcCommand(runtime, {
396 label: "environment-data:pull-requests:comment",
397 tag: WS_METHODS.pullRequestsComment,
398 execute: (input) => routedRequest(WS_METHODS.pullRequestsComment, input),
399 scheduler: commandScheduler,
400 concurrency: serialPerEnvironment,
401 }),
402 updateComment: createEnvironmentRpcCommand(runtime, {
403 label: "environment-data:pull-requests:update-comment",
404 tag: WS_METHODS.pullRequestsUpdateComment,
405 execute: (input) => routedRequest(WS_METHODS.pullRequestsUpdateComment, input),
406 scheduler: commandScheduler,
407 concurrency: serialPerEnvironment,
408 onSuccess: ({ environmentId, input: { projectId, host, repository, number } }, registry) =>
409 Effect.sync(() =>
410 registry.refresh(
411 activity({
412 environmentId,
413 input: { projectId, ...(host === undefined ? {} : { host }), repository, number },
414 }),
415 ),
416 ),
417 }),
418 submitReview: createEnvironmentRpcCommand(runtime, {
419 label: "environment-data:pull-requests:submit-review",
420 tag: WS_METHODS.pullRequestsSubmitReview,
421 execute: (input) => routedRequest(WS_METHODS.pullRequestsSubmitReview, input),
422 scheduler: commandScheduler,
423 concurrency: serialPerEnvironment,
424 }),
425 replyToThread: createEnvironmentRpcCommand(runtime, {
426 label: "environment-data:pull-requests:reply-to-thread",
427 tag: WS_METHODS.pullRequestsReplyToThread,
428 execute: (input) => routedRequest(WS_METHODS.pullRequestsReplyToThread, input),
429 scheduler: commandScheduler,
430 concurrency: serialPerEnvironment,
431 }),
432 /**
433 * Its own query rather than part of the detail: the people who may be asked are only wanted
434 * once somebody opens the reviewer menu, so this atom is read then and not before. Kept fresh
435 * for a minute, because who has access to a repository changes far more slowly than the
436 * change request it is being read for.
437 */
438 reviewerCandidates,
439 requestReviewers: createEnvironmentRpcCommand(runtime, {
440 label: "environment-data:pull-requests:request-reviewers",
441 tag: WS_METHODS.pullRequestsRequestReviewers,
442 execute: (input) => routedRequest(WS_METHODS.pullRequestsRequestReviewers, input),
443 scheduler: commandScheduler,
444 concurrency: serialPerEnvironment,
445 onSuccess: (target, registry) =>
446 Effect.sync(() => {
447 const { reviewers, requested } = target.input;
448 const candidatesAtom = reviewerCandidates(target);
449 const candidates = Option.getOrNull(AsyncResult.value(registry.get(candidatesAtom)));
450 const selected =
451 candidates?.candidates.filter((candidate) =>
452 reviewers.some(
453 (reviewer) => reviewer.id === candidate.id && reviewer.kind === candidate.kind,
454 ),
455 ) ?? [];
456 const missingIdentities = selected.length < reviewers.length;
457 updateCached(registry, candidatesAtom, (value) => ({
458 ...value,
459 candidates: value.candidates.map((candidate) =>
460 selected.includes(candidate) ? { ...candidate, isRequested: requested } : candidate,
461 ),
462 }));
463 const selectedLogins = new Set(
464 selected.map((candidate) => candidate.login.toLowerCase()),
465 );
466 const updateReviewers = (
467 actors: ReadonlyArray<PullRequestActor>,
468 keep = (_actor: PullRequestActor) => false,
469 ) =>
470 requested
471 ? [
472 ...actors,
473 ...selected
474 .filter(
475 (candidate) =>
476 !actors.some(
477 (actor) => actor.login.toLowerCase() === candidate.login.toLowerCase(),
478 ),
479 )
480 .map(({ login, name, avatarUrl }) => ({ login, name, avatarUrl })),
481 ]
482 : actors.filter(
483 (actor) => !selectedLogins.has(actor.login.toLowerCase()) || keep(actor),
484 );
485 updateCached(
486 registry,
487 detail(target),
488 (value) => ({
489 ...value,
490 reviewers: updateReviewers(value.reviewers),
491 }),
492 missingIdentities,
493 );
494 updateCached(
495 registry,
496 activity(target),
497 (value) => ({
498 ...value,
499 reviewers:
500 value.reviewers === undefined
501 ? undefined
502 : updateReviewers(value.reviewers, (actor) =>
503 value.comments.some(
504 (comment) =>
505 (comment.kind === "review" || comment.kind === "review-comment") &&
506 comment.author?.login.toLowerCase() === actor.login.toLowerCase(),
507 ),
508 ),
509 }),
510 missingIdentities,
511 );
512 }),
513 }),
514 reviewGuide,
515 /** Runs a model on the environment; never fired without the reader asking for it. */
516 generateReviewGuide: createEnvironmentRpcCommand(runtime, {
517 label: "environment-data:pull-requests:generate-review-guide",
518 tag: WS_METHODS.pullRequestsGenerateReviewGuide,
519 execute: (input) => routedRequest(WS_METHODS.pullRequestsGenerateReviewGuide, input),
520 onSuccess: (target, registry) => Effect.sync(() => registry.refresh(reviewGuide(target))),
521 }),
522 /** Read when the label menu opens, and kept for a minute, like the reviewer candidates. */
523 labelCandidates,
524 setLabels: createEnvironmentRpcCommand(runtime, {
525 label: "environment-data:pull-requests:set-labels",
526 tag: WS_METHODS.pullRequestsSetLabels,
527 execute: (input) => routedRequest(WS_METHODS.pullRequestsSetLabels, input),
528 scheduler: commandScheduler,
529 concurrency: serialPerEnvironment,
530 onSuccess: (target, registry) =>
531 Effect.sync(() => {
532 const { labels, applied } = target.input;
533 const candidatesAtom = labelCandidates(target);
534 const candidates = Option.getOrNull(AsyncResult.value(registry.get(candidatesAtom)));
535 const names = new Set(labels);
536 updateCached(registry, candidatesAtom, (value) => ({
537 ...value,
538 candidates: value.candidates.map((candidate) =>
539 names.has(candidate.name) ? { ...candidate, isApplied: applied } : candidate,
540 ),
541 }));
542 updateCached(registry, detail(target), (value) => ({
543 ...value,
544 labels: applied
545 ? [
546 ...value.labels,
547 ...labels
548 .filter((name) => !value.labels.some((label) => label.name === name))
549 .map((name) => ({
550 name,
551 color:
552 candidates?.candidates.find((candidate) => candidate.name === name)
553 ?.color ?? null,
554 })),
555 ]
556 : value.labels.filter((label) => !names.has(label.name)),
557 }));
558 }),
559 }),
560 setThreadResolution: createEnvironmentRpcCommand(runtime, {
561 label: "environment-data:pull-requests:set-thread-resolution",
562 tag: WS_METHODS.pullRequestsSetThreadResolution,
563 execute: (input) => routedRequest(WS_METHODS.pullRequestsSetThreadResolution, input),
564 scheduler: commandScheduler,
565 concurrency: serialPerEnvironment,
566 }),
567 setReaction: createEnvironmentRpcCommand(runtime, {
568 label: "environment-data:pull-requests:set-reaction",
569 tag: WS_METHODS.pullRequestsSetReaction,
570 execute: (input) => routedRequest(WS_METHODS.pullRequestsSetReaction, input),
571 scheduler: commandScheduler,
572 concurrency: serialPerEnvironment,
573 }),
574 /**
575 * Explicit refresh: forget the server's cached answers, then re-run the reads. A separate
576 * request rather than a flag on a read, so only a person's refresh spends host requests
577 * while every silent re-read shares the cache.
578 */
579 invalidate: createEnvironmentRpcCommand(runtime, {
580 label: "environment-data:pull-requests:invalidate",
581 tag: WS_METHODS.pullRequestsInvalidate,
582 execute: (input) => routedRequest(WS_METHODS.pullRequestsInvalidate, input),
583 onSuccess: ({ environmentId, input }, registry) =>
584 Effect.sync(() => {
585 if (input.reference !== undefined) {
586 registry.refresh(preview({ environmentId, input: input.reference }));
587 }
588 }),
589 scheduler: commandScheduler,
590 concurrency: serialPerEnvironment,
591 }),
592 };
593}