GeezerVison is showing github.com — refactor(web): split two self-contained phases out of onSend · pingdotgg/t3code@bd54ae3
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatView.logic.test.ts +62-1Lines changed: 62 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { findRecordedWorktreeSetup, resolveVisibleWorktreeSetup } from "./ChatView.logic"; | | 1 | +import { | | 2 | + findRecordedWorktreeSetup, | | 3 | + mergeDirectPreviewAnnotation, | | 4 | + resolveVisibleWorktreeSetup, | | 5 | +} from "./ChatView.logic"; | 2 | 6 | import { | 3 | 7 | recallCheckoutIsRepo, | 4 | 8 | rememberCheckoutIsRepo, | @@ -17,6 +21,7 @@ import { | 17 | 21 | EventId, | 18 | 22 | MessageId, | 19 | 23 | ProjectId, | | 24 | + PROVIDER_SEND_TURN_MAX_ATTACHMENTS, | 20 | 25 | ProviderInstanceId, | 21 | 26 | ThreadId, | 22 | 27 | RunId, | @@ -2173,3 +2178,59 @@ describe("waitForRevertedMessage", () => { | 2173 | 2178 | vi.useRealTimers(); | 2174 | 2179 | }); | 2175 | 2180 | }); | | 2181 | + | | 2182 | +describe("mergeDirectPreviewAnnotation", () => { | | 2183 | + const annotation = (id: string) => | | 2184 | + ({ | | 2185 | + id, | | 2186 | + pageUrl: "http://localhost:5173/", | | 2187 | + pageTitle: null, | | 2188 | + comment: "tighten this", | | 2189 | + elements: [], | | 2190 | + regions: [], | | 2191 | + strokes: [], | | 2192 | + styleChanges: [], | | 2193 | + screenshot: { | | 2194 | + dataUrl: "data:image/png;base64,AAAA", | | 2195 | + width: 10, | | 2196 | + height: 10, | | 2197 | + cropRect: { x: 0, y: 0, width: 10, height: 10 }, | | 2198 | + }, | | 2199 | + createdAt: "2026-10-16T00:00:00.000Z", | | 2200 | + }) as const; | | 2201 | + const image = (id: string) => | | 2202 | + ({ id, type: "image", name: `${id}.png`, mimeType: "image/png", sizeBytes: 1 }) as never; | | 2203 | + | | 2204 | + it("appends the screenshot and claims the crop when the turn has room", () => { | | 2205 | + const result = mergeDirectPreviewAnnotation({ | | 2206 | + images: [], | | 2207 | + fileCount: 0, | | 2208 | + previewAnnotations: [], | | 2209 | + direct: { annotation: annotation("a"), image: image("crop") }, | | 2210 | + }); | | 2211 | + expect(result.images.map((entry) => entry.id)).toEqual(["crop"]); | | 2212 | + expect(result.previewAnnotations[0]?.screenshot?.dataUrl).toBe(""); | | 2213 | + }); | | 2214 | + | | 2215 | + it("drops the screenshot claim when the attachment cap is full", () => { | | 2216 | + const result = mergeDirectPreviewAnnotation({ | | 2217 | + images: [], | | 2218 | + fileCount: PROVIDER_SEND_TURN_MAX_ATTACHMENTS, | | 2219 | + previewAnnotations: [], | | 2220 | + direct: { annotation: annotation("a"), image: image("crop") }, | | 2221 | + }); | | 2222 | + expect(result.images).toEqual([]); | | 2223 | + expect(result.previewAnnotations[0]?.screenshot).toBeNull(); | | 2224 | + }); | | 2225 | + | | 2226 | + it("keeps an annotation already in the draft as it is", () => { | | 2227 | + const existing = [annotation("a")]; | | 2228 | + const result = mergeDirectPreviewAnnotation({ | | 2229 | + images: [], | | 2230 | + fileCount: 0, | | 2231 | + previewAnnotations: existing, | | 2232 | + direct: { annotation: annotation("a"), image: null }, | | 2233 | + }); | | 2234 | + expect(result.previewAnnotations).toBe(existing); | | 2235 | + }); | | 2236 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatView.logic.ts +48Lines changed: 48 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@ import * as Option from "effect/Option"; | 2 | 2 | import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; | 3 | 3 | import { | 4 | 4 | ANTIGRAVITY_DEFAULT_MODEL, | | 5 | + PROVIDER_SEND_TURN_MAX_ATTACHMENTS, | 5 | 6 | type AssetCreateUrlInput, | 6 | 7 | type AssetCreateUrlResult, | 7 | 8 | type ChatFileAttachment, | @@ -1291,3 +1292,50 @@ export function restorePlanFollowUpComposer(input: { | 1291 | 1292 | detectTrigger: true, | 1292 | 1293 | }); | 1293 | 1294 | } | | 1295 | + | | 1296 | +/** | | 1297 | + * Adds a directly sent preview annotation to the composer's images and | | 1298 | + * annotations. Its screenshot rides along only while the turn has room for | | 1299 | + * another attachment; over the cap the server rejects the whole turn. | | 1300 | + */ | | 1301 | +export function mergeDirectPreviewAnnotation(input: { | | 1302 | + readonly images: ReadonlyArray<ComposerImageAttachment>; | | 1303 | + readonly fileCount: number; | | 1304 | + readonly previewAnnotations: ReadonlyArray<PreviewAnnotationPayload>; | | 1305 | + readonly direct: | | 1306 | + | { | | 1307 | + readonly annotation: PreviewAnnotationPayload; | | 1308 | + readonly image: ComposerImageAttachment | null; | | 1309 | + } | | 1310 | + | undefined; | | 1311 | +}): { | | 1312 | + readonly images: ReadonlyArray<ComposerImageAttachment>; | | 1313 | + readonly previewAnnotations: ReadonlyArray<PreviewAnnotationPayload>; | | 1314 | +} { | | 1315 | + const { direct } = input; | | 1316 | + if (!direct) return { images: input.images, previewAnnotations: input.previewAnnotations }; | | 1317 | + const imageAlreadyAttached = | | 1318 | + direct.image !== null && input.images.some((image) => image.id === direct.image?.id); | | 1319 | + const imageAppended = | | 1320 | + direct.image !== null && | | 1321 | + !imageAlreadyAttached && | | 1322 | + input.images.length + input.fileCount < PROVIDER_SEND_TURN_MAX_ATTACHMENTS; | | 1323 | + const images = direct.image && imageAppended ? [...input.images, direct.image] : input.images; | | 1324 | + const previewAnnotations = input.previewAnnotations.some( | | 1325 | + (annotation) => annotation.id === direct.annotation.id, | | 1326 | + ) | | 1327 | + ? input.previewAnnotations | | 1328 | + : [ | | 1329 | + ...input.previewAnnotations, | | 1330 | + { | | 1331 | + ...direct.annotation, | | 1332 | + // Claim an attached crop only when the screenshot really rides | | 1333 | + // along; a cap-dropped image must not produce a lying prompt. | | 1334 | + screenshot: | | 1335 | + direct.annotation.screenshot && (imageAppended || imageAlreadyAttached) | | 1336 | + ? { ...direct.annotation.screenshot, dataUrl: "" } | | 1337 | + : null, | | 1338 | + }, | | 1339 | + ]; | | 1340 | + return { images, previewAnnotations }; | | 1341 | +} |
|