GeezerVison is showing github.com — fix(clients): queued messages can't be edited while a question is ope… · pingdotgg/t3code@fe507c5
File treeExpand file treeCollapse file tree Open diff view settings mobile/src/features/threads
packages/client-runtime/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/ThreadDetailScreen.tsx +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,6 +26,7 @@ import type { ComposerTextPaste } from "../../native/T3ComposerEditor.types"; | 26 | 26 | import { type EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection"; | 27 | 27 | import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; | 28 | 28 | import type { HandoffEndpoints } from "@t3tools/client-runtime/handoff"; | | 29 | +import { queuedRunEditBlockedReason } from "@t3tools/client-runtime/queued-run-edit"; | 29 | 30 | import { | 30 | 31 | childThreadInputsTitle, | 31 | 32 | type CodexFeedbackSubmission, | @@ -777,6 +778,9 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) { | 777 | 778 | const activeUserInputRequestId = props.activePendingUserInput?.requestId ?? null; | 778 | 779 | const composerSlotHidden = | 779 | 780 | activeUserInputRequestId !== null || props.creationState?.kind === "failed"; | | 781 | + const pendingMessageEditBlocked = | | 782 | + queuedRunEditBlockedReason({ openQuestionCount: activeUserInputRequestId === null ? 0 : 1 }) !== | | 783 | + null; | 780 | 784 | const [usageLimitsPanel, setUsageLimitsPanel] = useState<{ | 781 | 785 | readonly key: string; | 782 | 786 | readonly threadKey: string; | @@ -1167,6 +1171,7 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) { | 1167 | 1171 | }; | 1168 | 1172 |
| 1169 | 1173 | const handleEditPendingMessage = async (message: QueuedThreadMessage) => { | | 1174 | + if (pendingMessageEditBlocked) return; | 1170 | 1175 | const scope = threadScope.current.signal; | 1171 | 1176 | const edited = await settlePromise(() => editPendingThreadMessage(message)); | 1172 | 1177 | if (AsyncResult.isFailure(edited)) { | @@ -1296,7 +1301,9 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) { | 1296 | 1301 | dispatchingMessageId={props.dispatchingMessageId} | 1297 | 1302 | // A native subagent has no composer to edit a pending message in; | 1298 | 1303 | // Cancel on the edit banner would discard it. | 1299 | | - onEditPendingMessage={isProviderSubagent ? null : handleEditPendingMessage} | | 1304 | + onEditPendingMessage={ | | 1305 | + isProviderSubagent || pendingMessageEditBlocked ? null : handleEditPendingMessage | | 1306 | + } | 1300 | 1307 | contentPresentation={props.contentPresentation} | 1301 | 1308 | agentLabel={agentLabel} | 1302 | 1309 | threadTitle={props.selectedThread.title} | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/ThreadQueueControl.tsx +14-2Lines changed: 14 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { type StaticScreenProps, useNavigation } from "@react-navigation/native"; | 2 | 2 | import { useAtomValue } from "@effect/atom-react"; | 3 | | -import { makeQueuedRunsAtom } from "@t3tools/client-runtime/queued-run-edit"; | | 3 | +import { | | 4 | + makeQueuedRunsAtom, | | 5 | + queuedRunEditBlockedReason, | | 6 | +} from "@t3tools/client-runtime/queued-run-edit"; | 4 | 7 | import type { ChatAttachment, EnvironmentId, RunId, ThreadId } from "@t3tools/contracts"; | 5 | 8 | import { Atom } from "effect/reactivity"; | 6 | 9 | import { Image } from "expo-image"; | @@ -75,6 +78,10 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) { | 75 | 78 | const workflow = useThreadQueueWorkflow(target); | 76 | 79 | const threadKey = scopedThreadKey(target.environmentId, target.threadId); | 77 | 80 | const editing = useQueuedRunEdit(threadKey); | | 81 | + const pendingRequests = useAtomValue(environmentThreadDetails.pendingRequestsAtom(target)); | | 82 | + const editBlockedReason = queuedRunEditBlockedReason({ | | 83 | + openQuestionCount: pendingRequests?.userInputs.length ?? 0, | | 84 | + }); | 78 | 85 | const reorder = useAtomCommand(threadEnvironment.reorderQueuedRun, "reorder queued message"); | 79 | 86 | const promote = useAtomCommand(threadEnvironment.promoteQueuedRun, "promote queued message"); | 80 | 87 | const cancel = useAtomCommand(threadEnvironment.cancelQueuedRun, "remove queued message"); | @@ -127,6 +134,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) { | 127 | 134 | return; | 128 | 135 | } | 129 | 136 | if (action === "edit") { | | 137 | + if (editBlockedReason !== null) return; | 130 | 138 | const entry = queuedRuns[index]!; | 131 | 139 | void Haptics.selectionAsync(); | 132 | 140 | beginQueuedRunEdit( | @@ -212,6 +220,9 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) { | 212 | 220 | /> | 213 | 221 | </View> | 214 | 222 | ) : null} | | 223 | + {editBlockedReason !== null && queuedRuns.length > 0 ? ( | | 224 | + <Text className="py-3 text-sm text-foreground-muted">{editBlockedReason}</Text> | | 225 | + ) : null} | 215 | 226 | {queuedRuns.length === 0 ? ( | 216 | 227 | <Text className="pt-6 text-center text-sm text-foreground-muted"> | 217 | 228 | No messages waiting in this queue. | @@ -231,6 +242,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) { | 231 | 242 | canPromoteToSteer: workflow?.canPromoteToSteer ?? false, | 232 | 243 | canSendNow: workflow?.canSendNow ?? false, | 233 | 244 | canReorder: workflow?.canReorder ?? false, | | 245 | + editBlocked: editBlockedReason !== null, | 234 | 246 | index, | 235 | 247 | isEditing: editing?.runId === run.id, | 236 | 248 | isGuestMessage: context?.guest !== undefined, | @@ -372,7 +384,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) { | 372 | 384 | accessibilityHint={ | 373 | 385 | controls.canEdit | 374 | 386 | ? "Opens this message in the composer for editing" | 375 | | - : undefined | | 387 | + : (editBlockedReason ?? undefined) | 376 | 388 | } | 377 | 389 | disabled={!controls.canEdit} | 378 | 390 | onPress={() => void act(run.id, "edit")} | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/threadQueueControlPresentation.ts +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,8 @@ export function resolveThreadQueueRowControls(input: { | 19 | 19 | readonly canPromoteToSteer: boolean; | 20 | 20 | readonly canSendNow: boolean; | 21 | 21 | readonly canReorder: boolean; | | 22 | + /** Something else holds the composer, such as an open question. */ | | 23 | + readonly editBlocked?: boolean; | 22 | 24 | readonly index: number; | 23 | 25 | readonly isEditing?: boolean; | 24 | 26 | /** A guest's message keeps the guest's words; the owner can cancel it, not rewrite it. */ | @@ -33,7 +35,8 @@ export function resolveThreadQueueRowControls(input: { | 33 | 35 | canDismiss: !input.busy, | 34 | 36 | // Re-opening the row already in the composer would reload it and throw | 35 | 37 | // away whatever has been typed since. | 36 | | - canEdit: mutationEnabled && !isEditing && input.isGuestMessage !== true, | | 38 | + canEdit: | | 39 | + mutationEnabled && !isEditing && input.isGuestMessage !== true && input.editBlocked !== true, | 37 | 40 | canMoveDown: mutationEnabled && input.canReorder && input.index < input.queuedCount - 1, | 38 | 41 | canMoveUp: mutationEnabled && input.canReorder && input.index > 0, | 39 | 42 | canSend: mutationEnabled && (input.canPromoteToSteer || input.canSendNow) && !isEditing, | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatView.tsx +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; | | 2 | +import { queuedRunEditBlockedReason } from "@t3tools/client-runtime/queued-run-edit"; | 2 | 3 | import { ScrollToEndButton, WorkspaceFileDropOverlay } from "./chat/TimelineOverlays"; | 3 | 4 | import { usePasteToFocusComposer } from "./chat/usePasteToFocusComposer"; | 4 | 5 | import { announcedRun, isDetailBehindShell } from "./chat/threadActivityAnnouncement"; | @@ -2924,6 +2925,9 @@ export default function ChatView(props: ChatViewProps) { | 2924 | 2925 | threadId={activeThread.id} | 2925 | 2926 | optimisticMessages={optimisticUserMessages} | 2926 | 2927 | editingRunId={queuedRunEdit.editingRunId} | | 2928 | + editBlockedReason={queuedRunEditBlockedReason({ | | 2929 | + openQuestionCount: pendingUserInputs.length, | | 2930 | + })} | 2927 | 2931 | onEditQueuedRun={queuedRunEdit.beginEdit} | 2928 | 2932 | onCancelEdit={queuedRunEdit.cancelEdit} | 2929 | 2933 | /> | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,6 +43,7 @@ const baseProps = { | 43 | 43 | optimisticMessages: [], | 44 | 44 | threadId: "thread:test" as never, | 45 | 45 | editingRunId: null, | | 46 | + editBlockedReason: null, | 46 | 47 | onEditQueuedRun: () => undefined, | 47 | 48 | onCancelEdit: () => undefined, | 48 | 49 | } satisfies ComponentProps<typeof QueuedRunsControl>; | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/QueuedRunsControl.tsx +29-23Lines changed: 29 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -74,6 +74,8 @@ export function QueuedRunsControl({ | 74 | 74 | Pick<ChatMessage, "id" | "inputIntent" | "text" | "attachments"> | 75 | 75 | >; | 76 | 76 | readonly editingRunId: RunId | null; | | 77 | + /** Set while something else holds the composer, such as an open question. */ | | 78 | + readonly editBlockedReason: string | null; | 77 | 79 | readonly onEditQueuedRun: (request: EditQueuedRunRequest) => void; | 78 | 80 | readonly onCancelEdit: () => void; | 79 | 81 | }) { | @@ -207,6 +209,7 @@ export function QueuedRunsControl({ | 207 | 209 | !latest || | 208 | 210 | latest.context?.guest !== undefined || | 209 | 211 | props.editingRunId !== null || | | 212 | + props.editBlockedReason !== null || | 210 | 213 | busyRunId !== null | 211 | 214 | ) { | 212 | 215 | return false; | @@ -413,32 +416,35 @@ export function QueuedRunsControl({ | 413 | 416 | ) : ( | 414 | 417 | <> | 415 | 418 | <Tooltip> | 416 | | - <TooltipTrigger | 417 | | - render={ | 418 | | - <Button | 419 | | - size="icon-xs" | 420 | | - variant="ghost-muted" | 421 | | - aria-label="Edit queued message" | 422 | | - disabled={ | 423 | | - item.runId === null || !item.editable || busyRunId !== null | | 419 | + {/* The span keeps the tooltip, and its reason, on a disabled button. */} | | 420 | + <TooltipTrigger render={<span className="flex shrink-0" />}> | | 421 | + <Button | | 422 | + size="icon-xs" | | 423 | + variant="ghost-muted" | | 424 | + aria-label="Edit queued message" | | 425 | + disabled={ | | 426 | + item.runId === null || | | 427 | + !item.editable || | | 428 | + busyRunId !== null || | | 429 | + props.editBlockedReason !== null | | 430 | + } | | 431 | + onClick={() => { | | 432 | + if (item.runId !== null && item.messageId !== null) { | | 433 | + props.onEditQueuedRun({ | | 434 | + runId: item.runId, | | 435 | + messageId: item.messageId, | | 436 | + text: item.text, | | 437 | + attachments: item.attachments, | | 438 | + }); | 424 | 439 | } | 425 | | - onClick={() => { | 426 | | - if (item.runId !== null && item.messageId !== null) { | 427 | | - props.onEditQueuedRun({ | 428 | | - runId: item.runId, | 429 | | - messageId: item.messageId, | 430 | | - text: item.text, | 431 | | - attachments: item.attachments, | 432 | | - }); | 433 | | - } | 434 | | - }} | 435 | | - /> | 436 | | - } | 437 | | - > | 438 | | - <PencilIcon /> | | 440 | + }} | | 441 | + > | | 442 | + <PencilIcon /> | | 443 | + </Button> | 439 | 444 | </TooltipTrigger> | 440 | 445 | <TooltipPopup> | 441 | | - {`Edit in the composer${item.serverIndex === queued.length - 1 && props.editShortcutLabel ? ` (${props.editShortcutLabel})` : ""}`} | | 446 | + {props.editBlockedReason ?? | | 447 | + `Edit in the composer${item.serverIndex === queued.length - 1 && props.editShortcutLabel ? ` (${props.editShortcutLabel})` : ""}`} | 442 | 448 | </TooltipPopup> | 443 | 449 | </Tooltip> | 444 | 450 | <Tooltip> | |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/queuedRunEdit.test.ts +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ import { describe, expect, it } from "vite-plus/test"; | 5 | 5 | import { | 6 | 6 | makeQueuedRunEditStore, | 7 | 7 | makeQueuedRunsAtom, | | 8 | + queuedRunEditBlockedReason, | 8 | 9 | resolveQueuedEditExit, | 9 | 10 | type QueuedRunStatus, | 10 | 11 | } from "./queuedRunEdit.ts"; | @@ -40,6 +41,15 @@ describe("resolveQueuedEditExit", () => { | 40 | 41 | }); | 41 | 42 | }); | 42 | 43 |
| | 44 | +describe("queuedRunEditBlockedReason", () => { | | 45 | + it("blocks edits only while a question holds the composer", () => { | | 46 | + expect(queuedRunEditBlockedReason({ openQuestionCount: 0 })).toBeNull(); | | 47 | + expect(queuedRunEditBlockedReason({ openQuestionCount: 1 })).toBe( | | 48 | + "Answer the question to edit queued messages", | | 49 | + ); | | 50 | + }); | | 51 | +}); | | 52 | + | 43 | 53 | describe("makeQueuedRunEditStore", () => { | 44 | 54 | it("fires once when the edited run leaves the queue, with the latest edit", () => { | 45 | 55 | const { registry, runs, store, exits, begin } = setup(); | |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/queuedRunEdit.ts +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,6 +61,17 @@ export function resolveQueuedEditExit(input: { | 61 | 61 | return input.threadDraftEmpty ? "kept" : "discarded"; | 62 | 62 | } | 63 | 63 |
| | 64 | +/** | | 65 | + * Why a queued message can't be opened in the composer now, or null when it | | 66 | + * can. An open question takes the composer over for its answer, so an edit | | 67 | + * begun then would happen out of sight and could be sent before it is seen. | | 68 | + */ | | 69 | +export function queuedRunEditBlockedReason(input: { | | 70 | + readonly openQuestionCount: number; | | 71 | +}): string | null { | | 72 | + return input.openQuestionCount > 0 ? "Answer the question to edit queued messages" : null; | | 73 | +} | | 74 | + | 64 | 75 | interface ExitWatch<E> { | 65 | 76 | readonly runs: QueuedRunsAtom; | 66 | 77 | readonly runId: RunId; | |
|