GeezerVison is showing github.com — feat(web,mobile): queued messages show who sent them (#26159) · pingdotgg/t3code@b31de68
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/ThreadQueueControl.tsx +82-16Lines changed: 82 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | makeQueuedRunsAtom, | 5 | 5 | queuedRunEditBlockedReason, | 6 | 6 | } from "@t3tools/client-runtime/queued-run-edit"; | | 7 | +import { scopeThreadRef } from "@t3tools/client-runtime/environment"; | | 8 | +import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message"; | 7 | 9 | import type { ChatAttachment, EnvironmentId, RunId, ThreadId } from "@t3tools/contracts"; | 8 | 10 | import { Atom } from "effect/reactivity"; | 9 | 11 | import { Image } from "expo-image"; | @@ -27,6 +29,9 @@ import { scopedThreadKey } from "../../lib/scopedEntities"; | 27 | 29 | import { useUniwindTheme } from "../../lib/useUniwindTheme"; | 28 | 30 | import { NativeStackScreenOptions, nativeHeaderScrollEdgeEffects } from "../../native/StackHeader"; | 29 | 31 | import { useAssetUrl } from "../../state/assets"; | | 32 | +import { useQuietThreadShell } from "../../state/entities"; | | 33 | +import { useEnvironmentQuery } from "../../state/query"; | | 34 | +import { serverEnvironment } from "../../state/server"; | 30 | 35 | import { assetImageSource } from "../../lib/assetImageSource"; | 31 | 36 | import { beginQueuedRunEdit, useQueuedRunEdit } from "../../state/queued-run-edit"; | 32 | 37 | import { environmentThreadDetails, threadEnvironment } from "../../state/threads"; | @@ -58,6 +63,62 @@ export function useThreadQueuedCount(target: QueueTarget | null) { | 58 | 63 | ); | 59 | 64 | } | 60 | 65 |
| | 66 | +type QueuedRunMessage = NonNullable< | | 67 | + NonNullable<ReturnType<typeof useThreadQueueWorkflow>>["queuedRuns"][number]["message"] | | 68 | +>; | | 69 | + | | 70 | +/** Who sent a queued message, as its sent form shows it in the thread. */ | | 71 | +function QueuedRunSender(props: { | | 72 | + readonly environmentId: EnvironmentId; | | 73 | + readonly message: QueuedRunMessage; | | 74 | +}) { | | 75 | + const { attribution, scheduledTaskId } = resolveUserMessagePresentation(props.message); | | 76 | + const senderThreadId = attribution === "agent" ? props.message.senderThreadId : undefined; | | 77 | + const senderShell = useQuietThreadShell( | | 78 | + senderThreadId ? scopeThreadRef(props.environmentId, senderThreadId) : null, | | 79 | + ); | | 80 | + const tasks = useEnvironmentQuery( | | 81 | + scheduledTaskId | | 82 | + ? serverEnvironment.scheduledTasksLive({ environmentId: props.environmentId, input: {} }) | | 83 | + : null, | | 84 | + ); | | 85 | + const sender = | | 86 | + attribution === "automation" | | 87 | + ? { | | 88 | + icon: "calendar.badge.clock" as const, | | 89 | + label: | | 90 | + tasks.data?.tasks.find((task) => task.id === scheduledTaskId)?.title ?? "Automation", | | 91 | + } | | 92 | + : attribution === "agent" | | 93 | + ? { | | 94 | + icon: "bubble.left.and.bubble.right" as const, | | 95 | + label: senderShell?.title.trim() || "Agent", | | 96 | + } | | 97 | + : attribution === "t3code" | | 98 | + ? { icon: null, label: "Sent by T3 Code" } | | 99 | + : null; | | 100 | + if (sender === null) return null; | | 101 | + return ( | | 102 | + <View className="flex-row items-center gap-1"> | | 103 | + {sender.icon ? ( | | 104 | + <SymbolView | | 105 | + name={sender.icon} | | 106 | + size={11} | | 107 | + weight="medium" | | 108 | + tintColorClassName="accent-foreground-muted" | | 109 | + type="monochrome" | | 110 | + /> | | 111 | + ) : null} | | 112 | + <Text | | 113 | + numberOfLines={1} | | 114 | + className="min-w-0 shrink font-t3-medium text-2xs text-foreground-muted" | | 115 | + > | | 116 | + {sender.label} | | 117 | + </Text> | | 118 | + </View> | | 119 | + ); | | 120 | +} | | 121 | + | 61 | 122 | export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) { | 62 | 123 | const { layout } = useAdaptiveWorkspaceLayout(); | 63 | 124 | const target = route.params; | @@ -173,7 +234,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) { | 173 | 234 | No messages waiting in this queue. | 174 | 235 | </Text> | 175 | 236 | ) : null} | 176 | | - {queuedRuns.map(({ run, text, attachments, context }, index) => { | | 237 | + {queuedRuns.map(({ run, text, attachments, context, message }, index) => { | 177 | 238 | const controls = resolveThreadQueueRowControls({ | 178 | 239 | busy: busyRunId !== null, | 179 | 240 | canPromoteToSteer: workflow?.canPromoteToSteer ?? false, | @@ -240,21 +301,26 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) { | 240 | 301 | environmentId={target.environmentId} | 241 | 302 | attachments={attachments} | 242 | 303 | /> | 243 | | - <Text | 244 | | - className={ | 245 | | - controls.isEditing | 246 | | - ? "min-w-0 flex-1 text-sm text-foreground-muted" | 247 | | - : "min-w-0 flex-1 text-sm text-foreground" | 248 | | - } | 249 | | - numberOfLines={1} | 250 | | - > | 251 | | - {context?.guest === undefined ? null : ( | 252 | | - <Text className="font-t3-medium text-adaptive-fuchsia-600-300"> | 253 | | - {`${context.guest.name} `} | 254 | | - </Text> | 255 | | - )} | 256 | | - {title} | 257 | | - </Text> | | 304 | + <View className="min-w-0 flex-1 gap-0.5"> | | 305 | + {message ? ( | | 306 | + <QueuedRunSender environmentId={target.environmentId} message={message} /> | | 307 | + ) : null} | | 308 | + <Text | | 309 | + className={ | | 310 | + controls.isEditing | | 311 | + ? "text-sm text-foreground-muted" | | 312 | + : "text-sm text-foreground" | | 313 | + } | | 314 | + numberOfLines={1} | | 315 | + > | | 316 | + {context?.guest === undefined ? null : ( | | 317 | + <Text className="font-t3-medium text-adaptive-fuchsia-600-300"> | | 318 | + {`${context.guest.name} `} | | 319 | + </Text> | | 320 | + )} | | 321 | + {title} | | 322 | + </Text> | | 323 | + </View> | 258 | 324 | {controls.isEditing ? ( | 259 | 325 | <Text className="shrink-0 text-2xs uppercase tracking-wide text-primary"> | 260 | 326 | Editing | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatView.tsx +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2907,6 +2907,8 @@ export default function ChatView(props: ChatViewProps) { | 2907 | 2907 | })} | 2908 | 2908 | onEditQueuedRun={queuedRunEdit.beginEdit} | 2909 | 2909 | onCancelEdit={queuedRunEdit.cancelEdit} | | 2910 | + timestampFormat={timestampFormat} | | 2911 | + onOpenThread={onOpenRelatedThreadStable} | 2910 | 2912 | /> | 2911 | 2913 | </> | 2912 | 2914 | ) : null; | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx +75Lines changed: 75 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { EnvironmentId, MessageId, ThreadId } from "@t3tools/contracts"; | 2 | 2 | import { serializeAssistantCitation } from "@t3tools/shared/assistantCitations"; | | 3 | +import * as DateTime from "effect/DateTime"; | 3 | 4 | import type { ComponentProps } from "react"; | 4 | 5 | import { expect, it, vi } from "vite-plus/test"; | 5 | 6 | import { page } from "vite-plus/test/browser"; | @@ -17,6 +18,15 @@ vi.mock(import("@t3tools/client-runtime/state/thread-workflows"), async (importO | 17 | 18 | vi.mock(import("../../state/entities"), async (importOriginal) => ({ | 18 | 19 | ...(await importOriginal()), | 19 | 20 | useThreadProjection: (() => state.projection) as never, | | 21 | + useQuietThreadShell: ((target: unknown) => | | 22 | + target === null ? null : { title: "Release lead" }) as never, | | 23 | +})); | | 24 | + | | 25 | +vi.mock(import("../../state/query"), async (importOriginal) => ({ | | 26 | + ...(await importOriginal()), | | 27 | + useEnvironmentQuery: (() => ({ | | 28 | + data: { tasks: [{ id: "task:webhook", title: "PR dispatcher" }] }, | | 29 | + })) as never, | 20 | 30 | })); | 21 | 31 |
| 22 | 32 | vi.mock(import("../../state/use-atom-command"), async (importOriginal) => ({ | @@ -46,6 +56,8 @@ const baseProps = { | 46 | 56 | editBlockedReason: null, | 47 | 57 | onEditQueuedRun: () => undefined, | 48 | 58 | onCancelEdit: () => undefined, | | 59 | + timestampFormat: "locale", | | 60 | + onOpenThread: () => undefined, | 49 | 61 | } satisfies ComponentProps<typeof QueuedRunsControl>; | 50 | 62 |
| 51 | 63 | async function renderQueue(props: Partial<ComponentProps<typeof QueuedRunsControl>> = {}) { | @@ -97,3 +109,66 @@ it("previews assistant quotes as readable text and preserves the citation when e | 97 | 109 | expect.objectContaining({ text: quoteAndText }), | 98 | 110 | ); | 99 | 111 | }); | | 112 | + | | 113 | +it("shows who sent a queued message and folds automation and agent prompts", async () => { | | 114 | + setup(); | | 115 | + const message = (id: string, fields: Record<string, unknown>) => ({ | | 116 | + id, | | 117 | + role: "user", | | 118 | + createdAt: DateTime.makeUnsafe("2026-10-27T12:00:00.000Z"), | | 119 | + ...fields, | | 120 | + }); | | 121 | + state.projection = { projection: { messages: [] } }; | | 122 | + state.workflow = { | | 123 | + activeRun: { id: "run:active" }, | | 124 | + canPromoteToSteer: true, | | 125 | + queuedRuns: [ | | 126 | + [ | | 127 | + "run:automation", | | 128 | + "GitHub labeled a pull request.\nFollow the runbook.", | | 129 | + { | | 130 | + createdBy: "agent", | | 131 | + scheduledTaskId: "task:webhook", | | 132 | + }, | | 133 | + ], | | 134 | + [ | | 135 | + "run:agent", | | 136 | + "Review finished.", | | 137 | + { | | 138 | + createdBy: "agent", | | 139 | + creationSource: "provider", | | 140 | + senderThreadId: "thread:lead", | | 141 | + }, | | 142 | + ], | | 143 | + [ | | 144 | + "run:server", | | 145 | + "Continue where you left off.", | | 146 | + { | | 147 | + createdBy: "agent", | | 148 | + creationSource: "server", | | 149 | + }, | | 150 | + ], | | 151 | + ].map(([runId, text, fields]) => ({ | | 152 | + run: { id: runId, userMessageId: `${runId}:message` }, | | 153 | + text, | | 154 | + attachments: [], | | 155 | + message: message(`${runId}:message`, { text, ...(fields as object) }), | | 156 | + })), | | 157 | + }; | | 158 | + const onOpenThread = vi.fn(); | | 159 | + await using _screen = await renderQueue({ onOpenThread }); | | 160 | + | | 161 | + const automation = page.getByRole("button", { name: /PR dispatcher/ }); | | 162 | + await expect.element(automation).toHaveAttribute("aria-expanded", "false"); | | 163 | + await expect.element(page.getByText(/Follow the runbook/)).not.toBeInTheDocument(); | | 164 | + await automation.click(); | | 165 | + await expect.element(page.getByText(/Follow the runbook/)).toBeVisible(); | | 166 | + await expect.element(page.getByRole("link", { name: "Open automation" })).toBeInTheDocument(); | | 167 | + | | 168 | + await expect.element(page.getByRole("button", { name: /Release lead/ })).toBeVisible(); | | 169 | + await page.getByRole("button", { name: "Open thread" }).click({ force: true }); | | 170 | + expect(onOpenThread).toHaveBeenCalledExactlyOnceWith("thread:lead"); | | 171 | + | | 172 | + await expect.element(page.getByText("Sent by T3 Code")).toBeVisible(); | | 173 | + await expect.element(page.getByText("Continue where you left off.")).toBeVisible(); | | 174 | +}); |
|