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

commands.ts

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