Skip to content

Commit 89b0e92

Browse files
adam.wilsoncursoragent
andcommitted
fix(web): resolve TypeScript build errors for chat preferences
`next build` (which runs `tsc` strictly) caught three issues that the looser ESLint pass missed. None are behavior changes — all are type-correctness fixes. 1. `chatPreferencesPage.tsx`: `toggleVariants` only defines `size: { default: ... }` (an icon-sized square), so `size="sm"` on `<ToggleGroup>` was a type error. Removed the prop and overrode sizing on each `<ToggleGroupItem>` via `className="h-9 w-auto min-w-0 px-3"` so the text labels actually fit. 2. `features/chat/actions.ts` and `app/api/(server)/chat/route.ts`: `chatPreferencesSchema` is built dynamically with `z.enum(string[])`, which widens each level value to `string` in the inferred type. Assigning `parsed.data` to the narrower `ChatPreferences` literal-union map therefore failed strict typecheck. Added an `as ChatPreferences` cast in both consumers with a comment explaining why the cast is sound (runtime validation still constrains each value to its per-dimension level list). 3. `__mocks__/prisma.ts`: `MOCK_USER_WITH_ACCOUNTS` was missing the two new User fields. Added `chatPreferences: {}` and `chatCustomInstructions: null` so test code compiles against the updated Prisma type. Refs #1242, #1243 Co-authored-by: Cursor <[email protected]>
1 parent bdcdc0b commit 89b0e92

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

packages/web/src/__mocks__/prisma.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export const MOCK_USER_WITH_ACCOUNTS: User & { accounts: Account[] } = {
4242
emailVerified: null,
4343
image: null,
4444
sessionVersion: 0,
45+
chatPreferences: {},
46+
chatCustomInstructions: null,
4547
accounts: [],
4648
}
4749

packages/web/src/app/(app)/settings/chatPreferences/chatPreferencesPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ export function ChatPreferencesPage({
152152
value={currentValue}
153153
onValueChange={(value) => handleDimensionChange(dimension, value)}
154154
variant="outline"
155-
size="sm"
156155
className="flex-wrap justify-start gap-2"
157156
aria-label={spec.label}
158157
>
@@ -161,6 +160,7 @@ export function ChatPreferencesPage({
161160
key={level.value}
162161
value={level.value}
163162
aria-label={`${spec.label}: ${level.label}`}
163+
className="h-9 w-auto min-w-0 px-3"
164164
>
165165
{level.label}
166166
</ToggleGroupItem>

packages/web/src/app/api/(server)/chat/route.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,14 @@ export const POST = apiHandler(async (req: NextRequest) => {
108108
});
109109
if (row) {
110110
const parsed = chatPreferencesSchema.safeParse(row.chatPreferences);
111+
// Cast back to the narrower literal-union map: the schema
112+
// is built dynamically so its inferred type widens to
113+
// `string`, but the runtime validation still constrains
114+
// each value to its per-dimension level list.
111115
userPreferences = {
112-
preferences: parsed.success ? parsed.data : {},
116+
preferences: parsed.success
117+
? (parsed.data as ResolvedChatUserPreferences["preferences"])
118+
: {},
113119
customInstructions: row.chatCustomInstructions,
114120
};
115121
}

packages/web/src/features/chat/actions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,13 @@ export const getChatPreferences = async (): Promise<{
582582
}
583583

584584
const parsed = chatPreferencesSchema.safeParse(row.chatPreferences);
585-
const preferences: ChatPreferences = parsed.success ? parsed.data : {};
585+
// The schema is built with a dynamic `z.enum(string[])` so its inferred
586+
// type widens each level to `string`. The runtime values are still
587+
// validated against the per-dimension level lists, so the cast back to
588+
// the narrower `ChatPreferences` literal-union map is sound.
589+
const preferences: ChatPreferences = parsed.success
590+
? (parsed.data as ChatPreferences)
591+
: {};
586592

587593
return {
588594
preferences,

0 commit comments

Comments
 (0)