Skip to content
Source
Sign inSign up

threadQueueControlPresentation.ts

64 lines2.2 KB

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;
15​
16export function resolveThreadQueueRowControls(input: {
17 readonly busy: boolean;
18 readonly canPromoteToSteer: boolean;
19 readonly canSendNow: boolean;
20 /** Something else holds the composer, such as an open question. */
21 readonly editBlocked?: boolean;
22 readonly isEditing?: boolean;
23 /** A guest's message keeps the guest's words; the owner can cancel it, not rewrite it. */
24 readonly isGuestMessage?: boolean;
25 readonly text: string;
26}): ThreadQueueRowControls {
27 const mutationEnabled = !input.busy;
28 const isEditing = input.isEditing === true;
29​
30 return {
31 canDismiss: !input.busy,
32 // Re-opening the row already in the composer would reload it and throw
33 // away whatever has been typed since.
34 canEdit:
35 mutationEnabled && !isEditing && input.isGuestMessage !== true && input.editBlocked !== true,
36 canSend: mutationEnabled && (input.canPromoteToSteer || input.canSendNow) && !isEditing,
37 dismissAccessibilityLabel: REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
38 // Editing and sending keep the original text so quoted citations stay linked.
39 displayText: isAttachmentOnlyBootstrapPrompt(input.text)
40 ? ""
41 : assistantCitationsToPlainText(input.text),
42 isEditing,
43 };
45​
46export function buildCancelQueuedRunCommand(input: {
47 readonly environmentId: EnvironmentId;
48 readonly runId: RunId;
49 readonly threadId: ThreadId;
50}): {
51 readonly environmentId: EnvironmentId;
52 readonly input: {
53 readonly runId: RunId;
54 readonly threadId: ThreadId;
55 };
56} {
57 return {
58 environmentId: input.environmentId,
59 input: {
60 runId: input.runId,
61 threadId: input.threadId,
62 },
63 };