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