Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

commands.ts

1,312 lines44.8 KB

1import { msg } from "gt-i18n";
2import { translatableMessage } from "../errors/translatable.ts";
3import { remapComposerContextAttachments } from "@t3tools/shared/composerContextReferences";
4import {
5 type ThreadLinkedPullRequest,
6 CommandId,
7 CheckpointId,
8 CheckpointScopeId,
9 ORCHESTRATION_V2_WS_METHODS,
10 OrchestrationV2CheckpointUnavailableError,
11 WS_METHODS,
12 type ChatAttachment,
13 MessageId,
14 type ModelSelection,
15 type NodeId,
16 type OrchestrationV2Command,
17 type OrchestrationV2CreationSource,
18 type PlanId,
19 type ProjectId,
20 type ProjectIconOverride,
21 type ProjectScript,
22 type ProjectTrackedFolder,
23 type ProviderApprovalDecision,
24 type ProviderInteractionMode,
25 type ProviderUserInputAnswers,
26 type RunId,
27 type RuntimeMode,
28 type RuntimeRequestId,
29 type ThreadId,
30 type ThreadEnvMode,
31 type UploadChatAttachment,
32 type GuestMessageId,
33} from "@t3tools/contracts";
34import { derivePendingBackgroundWork } from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
35import { visibleThreadPullRequests } from "@t3tools/shared/threadPullRequests";
36import * as SecureRandom from "effect/crypto/SecureRandom";
37import * as Cause from "effect/Cause";
38import * as Effect from "effect/Effect";
39import * as Exit from "effect/Exit";
40import * as Option from "effect/Option";
41import * as Stream from "effect/Stream";
42import * as SubscriptionRef from "effect/SubscriptionRef";
43​
44import * as EnvironmentSupervisor from "../connection/supervisor.ts";
45import {
46 EnvironmentRpcUnavailableError,
47 getInitialServerConfig,
48 isRpcClientError,
49 request,
50} from "../rpc/client.ts";
51import { repositoryCheckpointScopeIds } from "../state/threadRepositories.ts";
52​
53interface CommandMetadata {
54 readonly commandId?: CommandId;
55 readonly createdAt?: string;
56 readonly creationSource?: OrchestrationV2CreationSource;
58​
59export interface CreateProjectInput extends CommandMetadata {
60 readonly projectId: ProjectId;
61 readonly title: string;
62 readonly workspaceRoot: string;
63 readonly createWorkspaceRootIfMissing?: boolean;
64 readonly defaultModelSelection?: ModelSelection | null;
65 readonly scripts?: ReadonlyArray<ProjectScript>;
66 readonly trackedFolders?: ReadonlyArray<ProjectTrackedFolder>;
68​
69export interface UpdateProjectInput extends CommandMetadata {
70 readonly projectId: ProjectId;
71 readonly title?: string;
72 readonly workspaceRoot?: string;
73 readonly defaultModelSelection?: ModelSelection | null;
74 readonly autoPull?: boolean;
75 readonly projectIcon?: ProjectIconOverride | null;
76 readonly faviconPath?: string | null;
77 readonly defaultThreadEnvMode?: ThreadEnvMode | null;
78 readonly scripts?: ReadonlyArray<ProjectScript>;
79 /** Replaces the whole list. Paths only mean something on the project's own environment. */
80 readonly trackedFolders?: ReadonlyArray<ProjectTrackedFolder>;
81 /** Added to, and removed by path from, the list as the server has it. */
82 readonly trackFolders?: ReadonlyArray<ProjectTrackedFolder>;
83 readonly untrackFolders?: ReadonlyArray<string>;
84 readonly pinned?: boolean;
85 readonly archived?: boolean;
87​
88export interface DeleteProjectInput extends CommandMetadata {
89 readonly projectId: ProjectId;
90 readonly force?: boolean;
92​
93export interface CreateThreadInput extends CommandMetadata {
94 readonly threadId: ThreadId;
95 readonly projectId: ProjectId;
96 readonly title: string;
97 readonly modelSelection: ModelSelection;
98 readonly runtimeMode: RuntimeMode;
99 readonly interactionMode: ProviderInteractionMode;
100 readonly branch: string | null;
101 readonly worktreePath: string | null;
103​
104export interface ThreadCommandInput extends CommandMetadata {
105 readonly threadId: ThreadId;
107​
108export interface DeleteThreadInput extends ThreadCommandInput {
109 /** The server deletes only a thread with no runs and no messages. */
110 readonly onlyIfUnused?: boolean;
112export type ArchiveThreadInput = ThreadCommandInput;
113export type UnarchiveThreadInput = ThreadCommandInput;
114export type SettleThreadInput = ThreadCommandInput;
115​
116export interface UnsettleThreadInput extends ThreadCommandInput {
117 readonly reason: "user";
118 readonly restoreUnsettledAt?: string | null;
120​
121export interface PinThreadInput extends ThreadCommandInput {
122 readonly orderKey?: string;
124export type UnpinThreadInput = ThreadCommandInput;
125​
126export interface ReorderPinnedThreadInput extends ThreadCommandInput {
127 readonly orderKey: string;
129​
130export interface ReorderActiveThreadInput extends ThreadCommandInput {
131 readonly orderKey: string;
133​
134export interface SnoozeThreadInput extends ThreadCommandInput {
135 readonly snoozedUntil: string;
137​
138export interface UnsnoozeThreadInput extends ThreadCommandInput {
139 readonly reason: "user";
141​
142export interface VisitThreadInput extends ThreadCommandInput {
143 readonly visitedAt: string;
144 /** Counts toward search frecency; `searchQuery` is the palette query that picked it. */
145 readonly opened?: boolean;
146 readonly searchQuery?: string;
148​
149export type MarkThreadUnreadInput = ThreadCommandInput;
150​
151export interface UpdateThreadMetadataInput extends ThreadCommandInput {
152 readonly limitRecovery?: import("@t3tools/contracts").OrchestrationV2LimitRecoveryUpdate | null;
153 readonly title?: string;
154 readonly modelSelection?: ModelSelection;
155 readonly branch?: string | null;
156 readonly worktreePath?: string | null;
157 readonly regenerateTitle?: boolean;
158 readonly linkedPullRequest?: ThreadLinkedPullRequest | null;
159 readonly expectedEmpty?: boolean;
161​
162export interface SetThreadRuntimeModeInput extends ThreadCommandInput {
163 readonly runtimeMode: RuntimeMode;
165​
166export interface SetThreadInteractionModeInput extends ThreadCommandInput {
167 readonly interactionMode: ProviderInteractionMode;
169​
170interface StartThreadBootstrap {
171 readonly createThread?: {
172 readonly projectId: ProjectId;
173 readonly title: string;
174 readonly modelSelection: ModelSelection;
175 readonly runtimeMode: RuntimeMode;
176 readonly interactionMode: ProviderInteractionMode;
177 readonly branch: string | null;
178 readonly worktreePath: string | null;
179 readonly createdAt: string;
180 };
181 readonly prepareWorktree?: {
182 readonly requireWorktree?: boolean;
183 readonly projectCwd: string;
184 readonly baseBranch: string;
185 readonly branch?: string;
186 readonly startFromOrigin?: boolean;
187 /** Tracked repositories to give a worktree; absent leaves the choice to the server. */
188 readonly repositories?: ReadonlyArray<{ readonly path: string }>;
189 };
190 readonly runSetupScript?: boolean;
192​
193export interface StartThreadTurnInput extends ThreadCommandInput {
194 readonly manualContinuationOfRunId?: RunId;
195 readonly message: {
196 readonly messageId: MessageId;
197 readonly role: "user";
198 readonly text: string;
199 readonly attachments: ReadonlyArray<ChatAttachment | UploadChatAttachment>;
200 readonly context?: import("@t3tools/contracts").OrchestrationMessageContext;
201 readonly idleCompaction?: import("@t3tools/contracts").OrchestrationV2IdleCompaction;
202 };
203 readonly modelSelection?: ModelSelection;
204 readonly titleSeed?: string;
205 readonly runtimeMode: RuntimeMode;
206 readonly interactionMode: ProviderInteractionMode;
207 readonly bootstrap?: StartThreadBootstrap;
208 readonly sourceProposedPlan?: { readonly threadId: ThreadId; readonly planId: PlanId };
209 readonly dispatchMode?: "auto" | "queue" | "steer" | "restart" | "start";
210 /** Start a new provider session; needs the server's `freshContext` capability. */
211 readonly freshContext?: boolean;
212 /** Defaults to true. Callers with their own retry queue opt out so a dead socket fails fast. */
213 readonly resendAfterSocketLoss?: boolean;
215​
216export interface InterruptThreadTurnInput extends ThreadCommandInput {
217 readonly runId?: RunId;
218 readonly subagentId?: NodeId;
219 readonly turnId?: string;
221​
222export interface RespondToThreadApprovalInput extends ThreadCommandInput {
223 readonly requestId: RuntimeRequestId;
224 readonly decision: ProviderApprovalDecision;
225 readonly feedback?: string;
227​
228export interface RespondToThreadUserInputInput extends ThreadCommandInput {
229 readonly requestId: RuntimeRequestId;
230 readonly answers: ProviderUserInputAnswers;
231 readonly attachmentsByQuestionId?: import("@t3tools/contracts").UserInputAttachments;
233​
234export interface DismissThreadUserInputInput extends ThreadCommandInput {
235 readonly requestId: RuntimeRequestId;
237​
238export interface RevertThreadCheckpointInput extends ThreadCommandInput {
239 readonly restoreFiles?: boolean;
240 readonly checkpointId?: string;
241 readonly scopeId?: string;
242 readonly turnCount?: number;
244​
245export type StopThreadSessionInput = ThreadCommandInput;
246​
247export interface ForkThreadFromRunInput extends CommandMetadata {
248 readonly sourceThreadId: ThreadId;
249 readonly targetThreadId: ThreadId;
250 readonly runId: RunId;
251 readonly title?: string;
253​
254export interface ForkSideChatInput extends CommandMetadata {
255 readonly sourceThreadId: ThreadId;
256 readonly targetThreadId: ThreadId;
257 readonly title?: string;
259​
260export interface MergeThreadBackInput extends CommandMetadata {
261 readonly sourceThreadId: ThreadId;
262 readonly targetThreadId: ThreadId;
263 readonly runId: RunId;
265​
266export interface ResumeThreadQueueInput extends ThreadCommandInput {
267 readonly runId?: RunId;
269​
270export interface PromoteQueuedRunInput extends ThreadCommandInput {
271 readonly queuedRunId: RunId;
272 readonly targetRunId: RunId;
274​
275export interface CancelQueuedRunInput extends ThreadCommandInput {
276 readonly runId: RunId;
278​
279export interface RetryWorkspacePreparationInput extends ThreadCommandInput {
280 readonly runId: RunId;
282​
283export interface EditQueuedRunInput extends ThreadCommandInput {
284 readonly modelSelection?: ModelSelection;
285 readonly runId: RunId;
286 readonly text: string;
287 /**
288 * Full replacement attachment list for the queued message. Omitted =
289 * text-only edit that leaves attachments untouched.
290 */
291 readonly edit?: {
292 readonly messageId: MessageId;
293 readonly attachments: ReadonlyArray<ChatAttachment | UploadChatAttachment>;
294 readonly context?: import("@t3tools/contracts").OrchestrationMessageContext;
295 };
297​
298const allocateCommandId = Effect.fn("EnvironmentCommands.allocateCommandId")(function* (
299 input: CommandMetadata,
300) {
301 if (input.commandId !== undefined) return input.commandId;
302 const random = yield* SecureRandom.SecureRandom;
303 return CommandId.make(yield* random.uuidV4());
304});
305​
306const dispatch = (command: OrchestrationV2Command) =>
307 request(ORCHESTRATION_V2_WS_METHODS.dispatchCommand, command);
308​
309// The socket can close after the server accepted the frame but before it answered.
310// The server replays an accepted commandId from its receipt, so the same command
311// waits out reconnect backoff until the supervisor stops trying. The resend cap
312// stops a frame that kills the socket from looping.
313const MAX_LOST_TRANSPORT_RESENDS = 2;
314​
315// A live socket can still carry a command the host never answers; the heartbeat
316// alone would leave the send pending forever.
317const MESSAGE_DISPATCH_TIMEOUT = "60 seconds";
318​
319const resendAfterSocketLoss = Effect.fn("EnvironmentCommands.resendAfterSocketLoss")(function* <
320 A,
321 E,
322 R,
323>(attempt: Effect.Effect<A, E, R>) {
324 const supervisor = yield* EnvironmentSupervisor.EnvironmentSupervisor;
325 for (let resends = 0; ; resends += 1) {
326 const attemptSession = yield* SubscriptionRef.get(supervisor.session);
327 const exit = yield* Effect.exit(attempt);
328 if (Exit.isSuccess(exit)) return exit.value;
329 // Closing the session interrupts the request, which can beat the protocol error.
330 const lostTransport =
331 Cause.hasInterruptsOnly(exit.cause) ||
332 exit.cause.reasons.some((reason) => reason._tag === "Fail" && isRpcClientError(reason.error));
333 if (!lostTransport || resends >= MAX_LOST_TRANSPORT_RESENDS) return yield* exit;
334 const replacement = yield* Effect.raceFirst(
335 SubscriptionRef.changes(supervisor.session).pipe(
336 Stream.filter(
337 (session) =>
338 Option.isSome(session) &&
339 !(Option.isSome(attemptSession) && session.value === attemptSession.value),
340 ),
341 Stream.runHead,
342 ),
343 SubscriptionRef.changes(supervisor.state).pipe(
344 Stream.filter((state) => state.phase === "available" || state.phase === "blocked"),
345 Stream.runHead,
346 Effect.as(Option.none()),
347 ),
348 );
349 if (Option.isNone(replacement)) return yield* exit;
350 }
351});
352​
353const dispatchMessage = Effect.fn("EnvironmentCommands.dispatchMessage")(function* (
354 command: Extract<OrchestrationV2Command, { type: "message.dispatch" }>,
355 resend: boolean,
356) {
357 const supervisor = yield* EnvironmentSupervisor.EnvironmentSupervisor;
358 const attempt = dispatch(command).pipe(
359 Effect.timeoutOrElse({
360 duration: MESSAGE_DISPATCH_TIMEOUT,
361 orElse: () =>
362 Effect.fail(
363 new EnvironmentRpcUnavailableError({
364 environmentId: supervisor.target.environmentId,
365 ...translatableMessage(
366 msg("{host} did not confirm the message within 60 seconds.", {
367 host: supervisor.target.label,
368 }),
369 ),
370 }),
371 ),
372 }),
373 );
374 return yield* resend ? resendAfterSocketLoss(attempt) : attempt;
375});
376​
377const getProjection = (threadId: ThreadId) =>
378 request(ORCHESTRATION_V2_WS_METHODS.getThreadProjection, { threadId });
379​
380const persistAttachments = Effect.fn("EnvironmentCommands.persistAttachments")(function* (
381 threadId: ThreadId,
382 messageId: MessageId,
383 attachments: ReadonlyArray<ChatAttachment | UploadChatAttachment>,
384) {
385 const stored = attachments.filter(
386 (attachment): attachment is ChatAttachment => !("dataUrl" in attachment),
387 );
388 const uploads = attachments.filter(
389 (attachment): attachment is UploadChatAttachment => "dataUrl" in attachment,
390 );
391 if (uploads.length === 0) return stored;
392 const result = yield* request(WS_METHODS.assetsPersistChatAttachments, {
393 threadId,
394 messageId,
395 attachments: uploads,
396 });
397 if (stored.length === 0) return result.attachments;
398 const byUpload = new Map(
399 uploads.map((attachment, index) => [attachment, result.attachments[index]]),
400 );
401 return attachments.flatMap((attachment) => {
402 if (!("dataUrl" in attachment)) return [attachment];
403 const persisted = byUpload.get(attachment);
404 return persisted === undefined ? [] : [persisted];
405 });
406});
407​
408const mutateProject = Effect.fn("EnvironmentCommands.mutateProject")(function* (
409 mutation:
410 | {
411 readonly type: "project.create";
412 readonly commandId: CommandId;
413 readonly projectId: ProjectId;
414 readonly title: string;
415 readonly workspaceRoot: string;
416 readonly createWorkspaceRootIfMissing?: boolean;
417 readonly defaultModelSelection?: ModelSelection | null;
418 readonly scripts?: ReadonlyArray<ProjectScript>;
419 readonly trackedFolders?: ReadonlyArray<ProjectTrackedFolder>;
420 }
421 | {
422 readonly type: "project.update";
423 readonly commandId: CommandId;
424 readonly projectId: ProjectId;
425 readonly title?: string;
426 readonly workspaceRoot?: string;
427 readonly defaultModelSelection?: ModelSelection | null;
428 readonly scripts?: ReadonlyArray<ProjectScript>;
429 readonly trackedFolders?: ReadonlyArray<ProjectTrackedFolder>;
430 readonly trackFolders?: ReadonlyArray<ProjectTrackedFolder>;
431 readonly untrackFolders?: ReadonlyArray<string>;
432 }
433 | {
434 readonly type: "project.delete";
435 readonly commandId: CommandId;
436 readonly projectId: ProjectId;
437 readonly force?: boolean;
438 },
439) {
440 return yield* request(WS_METHODS.projectsMutate, mutation);
441});
442​
443export const createProject = Effect.fn("EnvironmentCommands.createProject")(function* (
444 input: CreateProjectInput,
445) {
446 return yield* mutateProject({
447 type: "project.create",
448 commandId: yield* allocateCommandId(input),
449 projectId: input.projectId,
450 title: input.title,
451 workspaceRoot: input.workspaceRoot,
452 ...(input.createWorkspaceRootIfMissing === undefined
453 ? {}
454 : { createWorkspaceRootIfMissing: input.createWorkspaceRootIfMissing }),
455 ...(input.defaultModelSelection === undefined
456 ? {}
457 : { defaultModelSelection: input.defaultModelSelection }),
458 ...(input.scripts === undefined ? {} : { scripts: input.scripts }),
459 ...(input.trackedFolders === undefined ? {} : { trackedFolders: input.trackedFolders }),
460 });
461});
462​
463export const updateProject = Effect.fn("EnvironmentCommands.updateProject")(function* (
464 input: UpdateProjectInput,
465) {
466 return yield* mutateProject({
467 type: "project.update",
468 commandId: yield* allocateCommandId(input),
469 projectId: input.projectId,
470 ...(input.title === undefined ? {} : { title: input.title }),
471 ...(input.workspaceRoot === undefined ? {} : { workspaceRoot: input.workspaceRoot }),
472 ...(input.defaultModelSelection === undefined
473 ? {}
474 : { defaultModelSelection: input.defaultModelSelection }),
475 ...(input.autoPull === undefined ? {} : { autoPull: input.autoPull }),
476 ...(input.projectIcon === undefined ? {} : { projectIcon: input.projectIcon }),
477 ...(input.faviconPath === undefined ? {} : { faviconPath: input.faviconPath }),
478 ...(input.defaultThreadEnvMode === undefined
479 ? {}
480 : { defaultThreadEnvMode: input.defaultThreadEnvMode }),
481 ...(input.scripts === undefined ? {} : { scripts: input.scripts }),
482 ...(input.trackedFolders === undefined ? {} : { trackedFolders: input.trackedFolders }),
483 ...(input.trackFolders === undefined ? {} : { trackFolders: input.trackFolders }),
484 ...(input.untrackFolders === undefined ? {} : { untrackFolders: input.untrackFolders }),
485 ...(input.pinned === undefined ? {} : { pinned: input.pinned }),
486 ...(input.archived === undefined ? {} : { archived: input.archived }),
487 });
488});
489​
490export const deleteProject = Effect.fn("EnvironmentCommands.deleteProject")(function* (
491 input: DeleteProjectInput,
492) {
493 return yield* mutateProject({
494 type: "project.delete",
495 commandId: yield* allocateCommandId(input),
496 projectId: input.projectId,
497 ...(input.force === undefined ? {} : { force: input.force }),
498 });
499});
500​
501export const createThread = Effect.fn("EnvironmentCommands.createThread")(function* (
502 input: CreateThreadInput,
503) {
504 return yield* dispatch({
505 type: "thread.create",
506 commandId: yield* allocateCommandId(input),
507 createdBy: "user",
508 creationSource: input.creationSource ?? "web",
509 threadId: input.threadId,
510 projectId: input.projectId,
511 title: input.title,
512 modelSelection: input.modelSelection,
513 runtimeMode: input.runtimeMode,
514 interactionMode: input.interactionMode,
515 branch: input.branch,
516 worktreePath: input.worktreePath,
517 });
518});
519​
520function simpleThreadCommand(
521 type:
522 | "thread.archive"
523 | "thread.unarchive"
524 | "thread.settle"
525 | "thread.pin"
526 | "thread.unpin"
527 | "thread.guest-share.close",
528 input: ThreadCommandInput,
529) {
530 return allocateCommandId(input).pipe(
531 Effect.flatMap((commandId) => dispatch({ type, commandId, threadId: input.threadId })),
532 );
534​
535export const deleteThread = Effect.fn("EnvironmentCommands.deleteThread")(function* (
536 input: DeleteThreadInput,
537) {
538 return yield* dispatch({
539 type: "thread.delete",
540 commandId: yield* allocateCommandId(input),
541 threadId: input.threadId,
542 ...(input.onlyIfUnused === undefined ? {} : { onlyIfUnused: input.onlyIfUnused }),
543 });
544});
545​
546export type CloseGuestShareInput = ThreadCommandInput;
547export const closeGuestShare = Effect.fn("EnvironmentCommands.closeGuestShare")(function* (
548 input: CloseGuestShareInput,
549) {
550 return yield* simpleThreadCommand("thread.guest-share.close", input);
551});
552​
553export interface ResolveGuestMessageInput extends ThreadCommandInput {
554 readonly guestMessageId: GuestMessageId;
555 readonly decision: "send" | "dismiss";
556 readonly creationSource?: "web" | "mobile";
558/** Send runs the guest's text as a normal turn; the server supplies the text, not the client. */
559export const resolveGuestMessage = Effect.fn("EnvironmentCommands.resolveGuestMessage")(function* (
560 input: ResolveGuestMessageInput,
561) {
562 const commandId = yield* allocateCommandId(input);
563 if (input.decision === "dismiss") {
564 return yield* dispatch({
565 type: "thread.guest-message.dismiss",
566 commandId,
567 threadId: input.threadId,
568 guestMessageId: input.guestMessageId,
569 });
570 }
571 return yield* dispatch({
572 type: "message.dispatch",
573 commandId,
574 threadId: input.threadId,
575 messageId: MessageId.make(commandId),
576 guestMessageId: input.guestMessageId,
577 text: "",
578 attachments: [],
579 dispatchMode: { type: "queue_after_active" },
580 createdBy: "user",
581 creationSource: input.creationSource ?? "web",
582 });
583});
584​
585export const archiveThread = Effect.fn("EnvironmentCommands.archiveThread")(function* (
586 input: ArchiveThreadInput,
587) {
588 return yield* simpleThreadCommand("thread.archive", input);
589});
590​
591export const unarchiveThread = Effect.fn("EnvironmentCommands.unarchiveThread")(function* (
592 input: UnarchiveThreadInput,
593) {
594 return yield* simpleThreadCommand("thread.unarchive", input);
595});
596​
597export const settleThread = Effect.fn("EnvironmentCommands.settleThread")(function* (
598 input: SettleThreadInput,
599) {
600 return yield* simpleThreadCommand("thread.settle", input);
601});
602​
603export const pinThread = Effect.fn("EnvironmentCommands.pinThread")(function* (
604 input: PinThreadInput,
605) {
606 const commandId = yield* allocateCommandId(input);
607 return yield* dispatch({
608 type: "thread.pin",
609 commandId,
610 threadId: input.threadId,
611 ...(input.orderKey === undefined ? {} : { orderKey: input.orderKey }),
612 });
613});
614​
615export interface SetThreadAutoSettleInput extends ThreadCommandInput {
616 readonly enabled: boolean;
618export const setThreadAutoSettle = Effect.fn("EnvironmentCommands.setThreadAutoSettle")(function* (
619 input: SetThreadAutoSettleInput,
620) {
621 return yield* dispatch({
622 type: "thread.auto-settle.set",
623 commandId: yield* allocateCommandId(input),
624 threadId: input.threadId,
625 enabled: input.enabled,
626 });
627});
628​
629export const reorderPinnedThread = Effect.fn("EnvironmentCommands.reorderPinnedThread")(function* (
630 input: ReorderPinnedThreadInput,
631) {
632 const commandId = yield* allocateCommandId(input);
633 return yield* dispatch({
634 type: "thread.pin.reorder",
635 commandId,
636 threadId: input.threadId,
637 orderKey: input.orderKey,
638 });
639});
640​
641export const reorderActiveThread = Effect.fn("EnvironmentCommands.reorderActiveThread")(function* (
642 input: ReorderActiveThreadInput,
643) {
644 return yield* dispatch({
645 type: "thread.active.reorder",
646 commandId: yield* allocateCommandId(input),
647 threadId: input.threadId,
648 orderKey: input.orderKey,
649 });
650});
651​
652export const unpinThread = Effect.fn("EnvironmentCommands.unpinThread")(function* (
653 input: UnpinThreadInput,
654) {
655 return yield* simpleThreadCommand("thread.unpin", input);
656});
657​
658export const unsettleThread = Effect.fn("EnvironmentCommands.unsettleThread")(function* (
659 input: UnsettleThreadInput,
660) {
661 return yield* dispatch({
662 type: "thread.unsettle",
663 commandId: yield* allocateCommandId(input),
664 threadId: input.threadId,
665 reason: input.reason,
666 ...(input.restoreUnsettledAt === undefined
667 ? {}
668 : { restoreUnsettledAt: input.restoreUnsettledAt }),
669 });
670});
671​
672export const snoozeThread = Effect.fn("EnvironmentCommands.snoozeThread")(function* (
673 input: SnoozeThreadInput,
674) {
675 return yield* dispatch({
676 type: "thread.snooze",
677 commandId: yield* allocateCommandId(input),
678 threadId: input.threadId,
679 snoozedUntil: input.snoozedUntil,
680 });
681});
682​
683export const unsnoozeThread = Effect.fn("EnvironmentCommands.unsnoozeThread")(function* (
684 input: UnsnoozeThreadInput,
685) {
686 return yield* dispatch({
687 type: "thread.unsnooze",
688 commandId: yield* allocateCommandId(input),
689 threadId: input.threadId,
690 reason: input.reason,
691 });
692});
693​
694export const visitThread = Effect.fn("EnvironmentCommands.visitThread")(function* (
695 input: VisitThreadInput,
696) {
697 return yield* dispatch({
698 type: "thread.visit",
699 commandId: yield* allocateCommandId(input),
700 threadId: input.threadId,
701 visitedAt: input.visitedAt,
702 ...(input.opened ? { opened: true } : {}),
703 ...(input.searchQuery ? { searchQuery: input.searchQuery } : {}),
704 });
705});
706​
707export const markThreadUnread = Effect.fn("EnvironmentCommands.markThreadUnread")(function* (
708 input: MarkThreadUnreadInput,
709) {
710 return yield* dispatch({
711 type: "thread.mark-unread",
712 commandId: yield* allocateCommandId(input),
713 threadId: input.threadId,
714 });
715});
716​
717export const updateThreadMetadata = Effect.fn("EnvironmentCommands.updateThreadMetadata")(
718 function* (input: UpdateThreadMetadataInput) {
719 const commandId = yield* allocateCommandId(input);
720 let result = null;
721 if (
722 input.title !== undefined ||
723 input.branch !== undefined ||
724 input.worktreePath !== undefined ||
725 input.regenerateTitle !== undefined ||
726 input.linkedPullRequest !== undefined ||
727 input.limitRecovery !== undefined
728 ) {
729 result = yield* dispatch({
730 type: "thread.metadata.update",
731 ...(input.limitRecovery === undefined ? {} : { limitRecovery: input.limitRecovery }),
732 commandId,
733 threadId: input.threadId,
734 ...(input.title === undefined ? {} : { title: input.title }),
735 ...(input.branch === undefined ? {} : { branch: input.branch }),
736 ...(input.worktreePath === undefined ? {} : { worktreePath: input.worktreePath }),
737 ...(input.expectedEmpty === true ? { expectedEmpty: true } : {}),
738 ...(input.regenerateTitle === undefined ? {} : { regenerateTitle: input.regenerateTitle }),
739 ...(input.linkedPullRequest === undefined
740 ? {}
741 : { linkedPullRequest: input.linkedPullRequest }),
742 });
743 }
744 if (input.modelSelection !== undefined) {
745 result = yield* dispatch({
746 type: "thread.model-selection.set",
747 commandId: result === null ? commandId : CommandId.make(`${commandId}:model-selection`),
748 threadId: input.threadId,
749 modelSelection: input.modelSelection,
750 });
751 }
752 return result ?? { sequence: 0 };
753 },
754);
755​
756export const setThreadRuntimeMode = Effect.fn("EnvironmentCommands.setThreadRuntimeMode")(
757 function* (input: SetThreadRuntimeModeInput) {
758 return yield* dispatch({
759 type: "thread.runtime-mode.set",
760 commandId: yield* allocateCommandId(input),
761 threadId: input.threadId,
762 runtimeMode: input.runtimeMode,
763 });
764 },
765);
766​
767export const setThreadInteractionMode = Effect.fn("EnvironmentCommands.setThreadInteractionMode")(
768 function* (input: SetThreadInteractionModeInput) {
769 return yield* dispatch({
770 type: "thread.interaction-mode.set",
771 commandId: yield* allocateCommandId(input),
772 threadId: input.threadId,
773 interactionMode: input.interactionMode,
774 });
775 },
776);
777​
778// Servers without native resume dispatch command.text verbatim; newer ones clear
779// it when manualContinuationOfRunId is set.
780const MANUAL_CONTINUATION_FALLBACK_TEXT = "Continue where you left off.";
781​
782export const startThreadTurn = Effect.fn("EnvironmentCommands.startThreadTurn")(function* (
783 input: StartThreadTurnInput,
784) {
785 const commandId = yield* allocateCommandId(input);
786 const attachments = yield* persistAttachments(
787 input.threadId,
788 input.message.messageId,
789 input.message.attachments,
790 );
791 const context = remapComposerContextAttachments(
792 input.message.context,
793 input.message.attachments,
794 attachments,
795 );
796 const resend = input.resendAfterSocketLoss ?? true;
797 const bootstrap = input.bootstrap?.createThread;
798 const prepareWorktree = input.bootstrap?.prepareWorktree;
799 if (bootstrap !== undefined || prepareWorktree !== undefined) {
800 const existingProjection =
801 bootstrap === undefined ? yield* getProjection(input.threadId) : null;
802 const thread = bootstrap ?? existingProjection!.thread;
803 const workspaceStrategy =
804 prepareWorktree !== undefined
805 ? {
806 type: "worktree" as const,
807 baseRef: prepareWorktree.baseBranch,
808 ...(prepareWorktree.branch === undefined ? {} : { branch: prepareWorktree.branch }),
809 ...(prepareWorktree.startFromOrigin === undefined
810 ? {}
811 : { startFromOrigin: prepareWorktree.startFromOrigin }),
812 ...(prepareWorktree.repositories === undefined
813 ? {}
814 : { repositories: prepareWorktree.repositories }),
815 }
816 : bootstrap?.worktreePath
817 ? {
818 type: "existing_worktree" as const,
819 worktreePath: bootstrap.worktreePath,
820 ...(bootstrap.branch === null ? {} : { branch: bootstrap.branch }),
821 }
822 : {
823 type: "root" as const,
824 ...(bootstrap?.branch === null || bootstrap?.branch === undefined
825 ? {}
826 : { branch: bootstrap.branch }),
827 };
828 const launch = request(ORCHESTRATION_V2_WS_METHODS.launchThread, {
829 commandId,
830 creationSource: input.creationSource ?? "web",
831 threadId: input.threadId,
832 ...(bootstrap === undefined ? { reuseExistingThread: true } : {}),
833 projectId: thread.projectId,
834 title: input.titleSeed ?? thread.title,
835 generateTitle: input.titleSeed !== undefined,
836 modelSelection: input.modelSelection ?? thread.modelSelection,
837 runtimeMode: input.runtimeMode,
838 interactionMode: input.interactionMode,
839 workspaceStrategy,
840 initialMessage: {
841 messageId: input.message.messageId,
842 text: input.message.text,
843 ...(context ? { context } : {}),
844 attachments,
845 },
846 });
847 return yield* resend ? resendAfterSocketLoss(launch) : launch;
848 }
849​
850 const requestedMode = input.dispatchMode ?? "auto";
851 if (requestedMode === "start") {
852 return yield* dispatchMessage(
853 {
854 type: "message.dispatch",
855 commandId,
856 createdBy: "user",
857 creationSource: input.creationSource ?? "web",
858 threadId: input.threadId,
859 messageId: input.message.messageId,
860 ...(input.manualContinuationOfRunId === undefined
861 ? {}
862 : { manualContinuationOfRunId: input.manualContinuationOfRunId }),
863 text:
864 input.manualContinuationOfRunId !== undefined &&
865 input.message.text.trim().length === 0 &&
866 attachments.length === 0
867 ? MANUAL_CONTINUATION_FALLBACK_TEXT
868 : input.message.text,
869 ...(context ? { context } : {}),
870 ...(input.message.idleCompaction === undefined
871 ? {}
872 : { idleCompaction: input.message.idleCompaction }),
873 attachments,
874 ...(input.modelSelection === undefined ? {} : { modelSelection: input.modelSelection }),
875 ...(input.sourceProposedPlan === undefined
876 ? {}
877 : { sourcePlanRef: input.sourceProposedPlan }),
878 ...(input.freshContext ? { freshContext: true } : {}),
879 dispatchMode: { type: "start_immediately" },
880 },
881 resend,
882 );
883 }
884​
885 const dispatchMode =
886 requestedMode === "queue"
887 ? ({ type: "queue_after_active" } as const)
888 : ({ type: "start_immediately" } as const);
889 return yield* dispatchMessage(
890 {
891 type: "message.dispatch",
892 commandId,
893 createdBy: "user",
894 creationSource: input.creationSource ?? "web",
895 threadId: input.threadId,
896 messageId: input.message.messageId,
897 text: input.message.text,
898 ...(context ? { context } : {}),
899 ...(input.message.idleCompaction === undefined
900 ? {}
901 : { idleCompaction: input.message.idleCompaction }),
902 attachments,
903 ...(input.titleSeed === undefined ? {} : { titleSeed: input.titleSeed }),
904 ...(input.modelSelection === undefined ? {} : { modelSelection: input.modelSelection }),
905 ...(input.sourceProposedPlan === undefined
906 ? {}
907 : { sourcePlanRef: input.sourceProposedPlan }),
908 ...(input.freshContext ? { freshContext: true } : {}),
909 ...(requestedMode !== "queue" ? { deliveryIntent: requestedMode } : {}),
910 dispatchMode,
911 },
912 resend,
913 );
914});
915​
916export const interruptThreadTurn = Effect.fn("EnvironmentCommands.interruptThreadTurn")(function* (
917 input: InterruptThreadTurnInput,
918) {
919 let threadId = input.threadId;
920 if (input.subagentId !== undefined) {
921 const projection = yield* getProjection(input.threadId);
922 const subagent = projection.subagents.find((agent) => agent.id === input.subagentId);
923 if (subagent?.origin === "app_owned" && subagent.childThreadId !== null) {
924 // The parent ends the task even when its child lost track of it. Older
925 // servers reject this for app-owned tasks, so the child stop below still runs.
926 if (subagent.runId !== null) {
927 yield* dispatch({
928 type: "subagent.stop",
929 commandId: yield* allocateCommandId({}),
930 threadId: input.threadId,
931 runId: subagent.runId,
932 subagentId: subagent.id,
933 }).pipe(Effect.ignore);
934 }
935 threadId = subagent.childThreadId;
936 } else {
937 if (subagent?.runId == null) return { sequence: 0 };
938 return yield* dispatch({
939 type: "subagent.stop",
940 commandId: yield* allocateCommandId(input),
941 threadId: input.threadId,
942 runId: subagent.runId,
943 subagentId: subagent.id,
944 });
945 }
946 }
947 // A run named by the caller belongs to the parent, not the rerouted child.
948 let runId =
949 threadId === input.threadId ? (input.runId ?? (input.turnId as RunId | undefined)) : undefined;
950 if (runId === undefined) {
951 const config = yield* getInitialServerConfig();
952 if (config.environment.capabilities.threadStop === true) {
953 // A paginated projection can omit commands still running from earlier turns.
954 return yield* dispatch({
955 type: "thread.stop",
956 commandId: yield* allocateCommandId(input),
957 threadId,
958 });
959 }
960 }
961 if (runId === undefined) {
962 const projection = yield* getProjection(threadId);
963 runId = projection.runs.findLast(
964 (run) =>
965 run.status === "preparing" ||
966 run.status === "starting" ||
967 run.status === "running" ||
968 run.status === "waiting",
969 )?.id;
970 if (runId === undefined) {
971 const latestRun = projection.runs.at(-1);
972 if (
973 derivePendingBackgroundWork({
974 latestRun,
975 providerThreads: projection.providerThreads,
976 turnItems: projection.turnItems,
977 activeProviderThreadId: projection.thread.activeProviderThreadId,
978 runs: projection.runs,
979 }).length > 0
980 ) {
981 runId = latestRun?.id;
982 }
983 }
984 if (runId === undefined) {
985 let result = { sequence: 0 };
986 for (const link of visibleThreadPullRequests(projection.thread.pullRequests ?? [])) {
987 if (link.watch === undefined) continue;
988 result = yield* dispatch({
989 type: "thread.pull-request.watch",
990 commandId: yield* allocateCommandId(result.sequence === 0 ? input : {}),
991 threadId,
992 host: link.host,
993 repository: link.repository,
994 number: link.number,
995 watching: false,
996 });
997 }
998 return result;
999 }
1001 if (runId === undefined) return { sequence: 0 };
1002 return yield* dispatch({
1003 type: "run.interrupt",
1004 commandId: yield* allocateCommandId(input),
1005 threadId,
1006 runId,
1007 holdQueue: true,
1008 });
1009});
1010​
1011export const respondToThreadApproval = Effect.fn("EnvironmentCommands.respondToThreadApproval")(
1012 function* (input: RespondToThreadApprovalInput) {
1013 return yield* dispatch({
1014 type: "runtime-request.respond",
1015 commandId: yield* allocateCommandId(input),
1016 threadId: input.threadId,
1017 requestId: input.requestId,
1018 decision: input.decision,
1019 ...(input.feedback === undefined ? {} : { feedback: input.feedback }),
1020 });
1021 },
1023​
1024export const respondToThreadUserInput = Effect.fn("EnvironmentCommands.respondToThreadUserInput")(
1025 function* (input: RespondToThreadUserInputInput) {
1026 return yield* dispatch({
1027 type: "runtime-request.respond",
1028 commandId: yield* allocateCommandId(input),
1029 threadId: input.threadId,
1030 requestId: input.requestId,
1031 answers: input.answers,
1032 ...(input.attachmentsByQuestionId === undefined
1033 ? {}
1034 : { attachmentsByQuestionId: input.attachmentsByQuestionId }),
1035 });
1036 },
1038​
1039export const dismissThreadUserInput = Effect.fn("EnvironmentCommands.dismissThreadUserInput")(
1040 function* (input: DismissThreadUserInputInput) {
1041 return yield* dispatch({
1042 type: "thread.user-input.dismiss",
1043 commandId: yield* allocateCommandId(input),
1044 threadId: input.threadId,
1045 requestId: input.requestId,
1046 });
1047 },
1049​
1050export const revertThreadCheckpoint = Effect.fn("EnvironmentCommands.revertThreadCheckpoint")(
1051 function* (input: RevertThreadCheckpointInput) {
1052 if (input.checkpointId !== undefined && input.scopeId !== undefined) {
1053 return yield* dispatch({
1054 type: "checkpoint.rollback",
1055 ...(input.restoreFiles === undefined ? {} : { restoreFiles: input.restoreFiles }),
1056 commandId: yield* allocateCommandId(input),
1057 threadId: input.threadId,
1058 scopeId: CheckpointScopeId.make(input.scopeId),
1059 checkpointId: CheckpointId.make(input.checkpointId),
1060 });
1062 const projection = yield* getProjection(input.threadId);
1063 // A tracked repository's baseline also sits at ordinal zero; it follows the thread's rewind.
1064 const repositoryScopeIds = repositoryCheckpointScopeIds(projection.checkpointScopes);
1065 const checkpoint =
1066 projection.checkpoints.find(
1067 (candidate) => candidate.id === input.checkpointId && candidate.scopeId === input.scopeId,
1068 ) ??
1069 projection.checkpoints.findLast(
1070 (candidate) =>
1071 !repositoryScopeIds.has(candidate.scopeId) &&
1072 (input.turnCount === 0
1073 ? candidate.ordinalWithinScope === 0 && candidate.appRunOrdinal === null
1074 : candidate.appRunOrdinal === input.turnCount),
1075 );
1076 if (
1077 checkpoint === undefined ||
1078 // Missing or failed snapshots support conversation rewind only.
1079 (checkpoint.status !== "ready" &&
1080 !(input.restoreFiles === false && checkpoint.status !== "stale"))
1081 ) {
1082 const target =
1083 input.checkpointId === undefined
1084 ? `run ordinal ${input.turnCount ?? "unknown"}`
1085 : `checkpoint ${input.checkpointId}`;
1086 return yield* new OrchestrationV2CheckpointUnavailableError({
1087 threadId: input.threadId,
1088 target,
1089 });
1091 return yield* dispatch({
1092 type: "checkpoint.rollback",
1093 ...(input.restoreFiles === undefined ? {} : { restoreFiles: input.restoreFiles }),
1094 commandId: yield* allocateCommandId(input),
1095 threadId: input.threadId,
1096 scopeId: checkpoint.scopeId,
1097 checkpointId: checkpoint.id,
1098 });
1099 },
1101​
1102export const stopThreadSession = Effect.fn("EnvironmentCommands.stopThreadSession")(function* (
1103 input: StopThreadSessionInput,
1104) {
1105 const projection = yield* getProjection(input.threadId);
1106 const commandId = yield* allocateCommandId(input);
1107 let result = { sequence: 0 };
1108 for (const session of projection.providerSessions) {
1109 result = yield* dispatch({
1110 type: "provider-session.detach",
1111 commandId: CommandId.make(`${commandId}:detach:${session.id}`),
1112 threadId: input.threadId,
1113 providerSessionId: session.id,
1114 reason: "client-requested",
1115 });
1117 return result;
1118});
1119​
1120export const forkThreadFromRun = Effect.fn("EnvironmentCommands.forkThreadFromRun")(function* (
1121 input: ForkThreadFromRunInput,
1122) {
1123 return yield* dispatch({
1124 type: "thread.fork",
1125 commandId: yield* allocateCommandId(input),
1126 createdBy: "user",
1127 creationSource: input.creationSource ?? "web",
1128 sourceThreadId: input.sourceThreadId,
1129 targetThreadId: input.targetThreadId,
1130 sourcePoint: { type: "run", runId: input.runId },
1131 ...(input.title === undefined ? {} : { title: input.title }),
1132 });
1133});
1134​
1135/** Forks the thread's latest stable point into a hidden side chat; works while it runs. */
1136export const forkSideChat = Effect.fn("EnvironmentCommands.forkSideChat")(function* (
1137 input: ForkSideChatInput,
1138) {
1139 return yield* dispatch({
1140 type: "thread.fork",
1141 commandId: yield* allocateCommandId(input),
1142 createdBy: "user",
1143 creationSource: input.creationSource ?? "web",
1144 sourceThreadId: input.sourceThreadId,
1145 targetThreadId: input.targetThreadId,
1146 sourcePoint: { type: "latest_stable" },
1147 sideChat: true,
1148 ...(input.title === undefined ? {} : { title: input.title }),
1149 });
1150});
1151​
1152export const mergeThreadBack = Effect.fn("EnvironmentCommands.mergeThreadBack")(function* (
1153 input: MergeThreadBackInput,
1154) {
1155 return yield* dispatch({
1156 type: "thread.merge_back",
1157 commandId: yield* allocateCommandId(input),
1158 createdBy: "user",
1159 creationSource: input.creationSource ?? "web",
1160 sourceThreadId: input.sourceThreadId,
1161 targetThreadId: input.targetThreadId,
1162 sourcePoint: { type: "run", runId: input.runId },
1163 });
1164});
1165​
1166export const resumeThreadQueue = Effect.fn("EnvironmentCommands.resumeThreadQueue")(function* (
1167 input: ResumeThreadQueueInput,
1168) {
1169 return yield* resendAfterSocketLoss(
1170 dispatch({
1171 ...(input.runId === undefined
1172 ? { type: "queue.resume" as const }
1173 : { type: "queued-run.start" as const, runId: input.runId }),
1174 commandId: yield* allocateCommandId(input),
1175 threadId: input.threadId,
1176 }),
1177 );
1178});
1179​
1180export const promoteQueuedRun = Effect.fn("EnvironmentCommands.promoteQueuedRun")(function* (
1181 input: PromoteQueuedRunInput,
1182) {
1183 return yield* resendAfterSocketLoss(
1184 dispatch({
1185 type: "queued-message.promote-to-steer",
1186 commandId: yield* allocateCommandId(input),
1187 threadId: input.threadId,
1188 queuedRunId: input.queuedRunId,
1189 targetRunId: input.targetRunId,
1190 }),
1191 );
1192});
1193​
1194export const cancelQueuedRun = Effect.fn("EnvironmentCommands.cancelQueuedRun")(function* (
1195 input: CancelQueuedRunInput,
1196) {
1197 return yield* dispatch({
1198 type: "queued-run.cancel",
1199 commandId: yield* allocateCommandId(input),
1200 threadId: input.threadId,
1201 runId: input.runId,
1202 });
1203});
1204​
1205export const retryWorkspacePreparation = Effect.fn("EnvironmentCommands.retryWorkspacePreparation")(
1206 function* (input: RetryWorkspacePreparationInput) {
1207 return yield* dispatch({
1208 type: "prepared-run.retry",
1209 commandId: yield* allocateCommandId(input),
1210 threadId: input.threadId,
1211 runId: input.runId,
1212 });
1213 },
1215​
1216export const editQueuedRun = Effect.fn("EnvironmentCommands.editQueuedRun")(function* (
1217 input: EditQueuedRunInput,
1218) {
1219 const attachments =
1220 input.edit === undefined
1221 ? undefined
1222 : yield* persistAttachments(input.threadId, input.edit.messageId, input.edit.attachments);
1223 return yield* dispatch({
1224 type: "queued-run.edit",
1225 commandId: yield* allocateCommandId(input),
1226 threadId: input.threadId,
1227 runId: input.runId,
1228 text: input.text,
1229 ...(input.modelSelection ? { modelSelection: input.modelSelection } : {}),
1230 ...(attachments === undefined ? {} : { attachments }),
1231 ...(input.edit?.context && attachments
1232 ? {
1233 context: remapComposerContextAttachments(
1234 input.edit.context,
1235 input.edit.attachments,
1236 attachments,
1237 ),
1239 : {}),
1240 });
1241});
1242​
1243export type LinkThreadPullRequestInput = Omit<
1244 Extract<OrchestrationV2Command, { type: "thread.pull-request.link" }>,
1245 "type" | "commandId"
1246> &
1247 CommandMetadata;
1248export type UnlinkThreadPullRequestInput = Omit<
1249 Extract<OrchestrationV2Command, { type: "thread.pull-request.unlink" }>,
1250 "type" | "commandId"
1251> &
1252 CommandMetadata;
1253export const linkThreadPullRequest = Effect.fn("EnvironmentCommands.linkThreadPullRequest")(
1254 function* (input: LinkThreadPullRequestInput) {
1255 return yield* dispatch({
1256 ...input,
1257 type: "thread.pull-request.link",
1258 commandId: yield* allocateCommandId(input),
1259 });
1260 },
1262export type LinkThreadIssueInput = Omit<
1263 Extract<OrchestrationV2Command, { type: "thread.issue.link" }>,
1264 "type" | "commandId"
1265> &
1266 CommandMetadata;
1267export type UnlinkThreadIssueInput = Omit<
1268 Extract<OrchestrationV2Command, { type: "thread.issue.unlink" }>,
1269 "type" | "commandId"
1270> &
1271 CommandMetadata;
1272export const linkThreadIssue = Effect.fn("EnvironmentCommands.linkThreadIssue")(function* (
1273 input: LinkThreadIssueInput,
1274) {
1275 return yield* dispatch({
1276 ...input,
1277 type: "thread.issue.link",
1278 commandId: yield* allocateCommandId(input),
1279 });
1280});
1281export const unlinkThreadIssue = Effect.fn("EnvironmentCommands.unlinkThreadIssue")(function* (
1282 input: UnlinkThreadIssueInput,
1283) {
1284 return yield* dispatch({
1285 ...input,
1286 type: "thread.issue.unlink",
1287 commandId: yield* allocateCommandId(input),
1288 });
1289});
1290export type WatchThreadPullRequestInput = Omit<
1291 Extract<OrchestrationV2Command, { type: "thread.pull-request.watch" }>,
1292 "type" | "commandId"
1293> &
1294 CommandMetadata;
1295export const watchThreadPullRequest = Effect.fn("EnvironmentCommands.watchThreadPullRequest")(
1296 function* (input: WatchThreadPullRequestInput) {
1297 return yield* dispatch({
1298 ...input,
1299 type: "thread.pull-request.watch",
1300 commandId: yield* allocateCommandId(input),
1301 });
1302 },
1304export const unlinkThreadPullRequest = Effect.fn("EnvironmentCommands.unlinkThreadPullRequest")(
1305 function* (input: UnlinkThreadPullRequestInput) {
1306 return yield* dispatch({
1307 ...input,
1308 type: "thread.pull-request.unlink",
1309 commandId: yield* allocateCommandId(input),
1310 });
1311 },