GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(web): split two self-contained phases out of onSend · pingdotgg/t3code@bd54ae3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components
    • ChatView.logic.test.ts
    • ChatView.logic.ts
    • ChatView.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/ChatView.logic.test.ts‎

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 numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { findRecordedWorktreeSetup, resolveVisibleWorktreeSetup } from "./ChatView.logic";
1+
import {
2+
findRecordedWorktreeSetup,
3+
mergeDirectPreviewAnnotation,
4+
resolveVisibleWorktreeSetup,
5+
} from "./ChatView.logic";
26
import {
37
recallCheckoutIsRepo,
48
rememberCheckoutIsRepo,
@@ -17,6 +21,7 @@ import {
1721
EventId,
1822
MessageId,
1923
ProjectId,
24+
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
2025
ProviderInstanceId,
2126
ThreadId,
2227
RunId,
@@ -2173,3 +2178,59 @@ describe("waitForRevertedMessage", () => {
21732178
vi.useRealTimers();
21742179
});
21752180
});
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

‎apps/web/src/components/ChatView.logic.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/ChatView.logic.ts
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as Option from "effect/Option";
22
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
33
import {
44
ANTIGRAVITY_DEFAULT_MODEL,
5+
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
56
type AssetCreateUrlInput,
67
type AssetCreateUrlResult,
78
type ChatFileAttachment,
@@ -1291,3 +1292,50 @@ export function restorePlanFollowUpComposer(input: {
12911292
detectTrigger: true,
12921293
});
12931294
}
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+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.