Open History to see the last commit
1import type { EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
2import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations";
3import { isAttachmentOnlyBootstrapPrompt } from "@t3tools/shared/composerContextReferences";
4
5export const REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL = "Remove queued message";
6
7export interface ThreadQueueRowControls {
8 readonly canDismiss: boolean;
9 readonly canEdit: boolean;
10 readonly canSend: boolean;
11 readonly dismissAccessibilityLabel: string;
12 readonly displayText: string;
13 readonly isEditing: boolean;
14}
15
16export function resolveThreadQueueRowControls(input: {
17 readonly busy: boolean;
18 readonly canPromoteToSteer: boolean;
19 readonly canSendNow: boolean;
20 readonly promoteSkipsCompaction?: boolean;
21 /** Something else holds the composer, such as an open question. */
22 readonly editBlocked?: boolean;
23 readonly isEditing?: boolean;
24 /** A guest's message keeps the guest's words; the owner can cancel it, not rewrite it. */
25 readonly isGuestMessage?: boolean;
26 readonly steerRejectionReason: string | null;
27 readonly text: string;
28}): ThreadQueueRowControls {
29 const mutationEnabled = !input.busy;
30 const isEditing = input.isEditing === true;
31
32 return {
33 canDismiss: !input.busy,
34 // Re-opening the row already in the composer would reload it and throw
35 // away whatever has been typed since.
36 canEdit:
37 mutationEnabled && !isEditing && input.isGuestMessage !== true && input.editBlocked !== true,
38 canSend:
39 mutationEnabled &&
40 !isEditing &&
41 (input.canSendNow ||
42 (input.canPromoteToSteer &&
43 (input.promoteSkipsCompaction === true || input.steerRejectionReason === null))),
44 dismissAccessibilityLabel: REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
45 // Editing and sending keep the original text so quoted citations stay linked.
46 displayText: isAttachmentOnlyBootstrapPrompt(input.text)
47 ? ""
48 : assistantCitationsToPlainText(input.text),
49 isEditing,
50 };
51}
52
53export function buildCancelQueuedRunCommand(input: {
54 readonly environmentId: EnvironmentId;
55 readonly runId: RunId;
56 readonly threadId: ThreadId;
57}): {
58 readonly environmentId: EnvironmentId;
59 readonly input: {
60 readonly runId: RunId;
61 readonly threadId: ThreadId;
62 };
63} {
64 return {
65 environmentId: input.environmentId,
66 input: {
67 runId: input.runId,
68 threadId: input.threadId,
69 },
70 };
71}