Files
8582b92f90 refactor(deps): Tailwind 4 (CSS-first) + Zod 4 + ESLint 10 + types/node 26 + ai-kit 0.6.2 (#168)
Tailwind 3.4 -> 4.3:
- tailwind.config.js DELETED; tokens now live in an @theme inline block in
  app/globals.css (semantic names unchanged: action, paper, edge, ink...)
- postcss.config.js -> @tailwindcss/postcss; autoprefixer dropped (built in)
- @tailwind directives -> @import 'tailwindcss'; forms/typography via @plugin
- daisyui removed (no daisyui class used anywhere)
- next/font vars renamed --font-inter/--font-fraunces to break the circular
  var() the old --font-sans binding would create inside @theme
- v4 deleted *-opacity-* utilities: every bg/text/ring-opacity-N rewritten to
  slash syntax (bg-action/90, ring-black/5, ...); dynamic accent tint gets a
  literal class map in lib/config/colors.ts so the scanner sees each class
- dead v3-era aspect-w/h custom utilities removed (unused; v4 has aspect-*)

Zod 3.24 -> 4.5:
- .errors -> .issues everywhere
- z.string().uuid( -> .guid( (v4 uuid() is RFC-variant-strict; DB ids aren't)
- z.record(z.unknown()) -> z.record(z.string(), z.unknown())
- object .default({}) -> .prefault({}) (v4 default takes the full output value)

ESLint 9 -> 10: eslint-plugin-react's version:'detect' calls the removed
context.getFilename; pin settings.react.version='19' AFTER the next configs.

Verify (format+lint+typecheck+selfhost+test+build) green: 272 tests pass.


Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn

Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-31 12:45:49 +00:00

145 lines
4.8 KiB
TypeScript

/**
* Custom Bot Validation Schemas
* @module lib/validations/custom-bot
*
* Zod schemas for validating custom bot API inputs
*/
import { z } from 'zod';
import { CustomBotAccentColorSchema } from '@/lib/config/colors';
/**
* Valid accent colors for bot themes
* Re-exported from SSOT in lib/config/colors.ts
*/
export const AccentColorSchema = CustomBotAccentColorSchema;
/**
* Bot menu item schema
*/
export const BotMenuItemSchema = z.object({
id: z.string().min(1),
label: z.string().min(1).max(50),
icon: z.string().optional(),
section: z.string().optional(),
});
/**
* Navigation config schema
*/
export const NavConfigSchema = z.object({
menuItems: z.array(BotMenuItemSchema).default([]),
});
/**
* Slug validation - lowercase alphanumeric with hyphens
*/
const slugRegex = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
/**
* Schema for creating a new custom bot
*/
export const CreateCustomBotSchema = z.object({
slug: z
.string()
.min(3, 'Slug must be at least 3 characters')
.max(50, 'Slug must be at most 50 characters')
.regex(slugRegex, 'Slug must be lowercase alphanumeric with hyphens (e.g., "hr-advisor")'),
title: z
.string()
.min(3, 'Title must be at least 3 characters')
.max(100, 'Title must be at most 100 characters'),
description: z.string().max(500, 'Description must be at most 500 characters').optional(),
emoji: z.string().max(10, 'Emoji must be at most 10 characters').optional().default('🤖'),
accent_color: AccentColorSchema.optional().default('blue'),
system_prompt: z
.string()
.min(50, 'System prompt must be at least 50 characters')
.max(10000, 'System prompt must be at most 10,000 characters'),
nav_config: NavConfigSchema.optional(),
});
/**
* Schema for updating an existing custom bot
*/
export const UpdateCustomBotSchema = z.object({
title: z
.string()
.min(3, 'Title must be at least 3 characters')
.max(100, 'Title must be at most 100 characters')
.optional(),
description: z
.string()
.max(500, 'Description must be at most 500 characters')
.nullable()
.optional(),
emoji: z.string().max(10, 'Emoji must be at most 10 characters').optional(),
accent_color: AccentColorSchema.optional(),
system_prompt: z
.string()
.min(50, 'System prompt must be at least 50 characters')
.max(10000, 'System prompt must be at most 10,000 characters')
.optional(),
nav_config: NavConfigSchema.optional(),
is_published: z.boolean().optional(),
is_public: z.boolean().optional(),
});
/**
* Schema for creating a knowledge chunk
*/
export const CreateKnowledgeChunkSchema = z.object({
bot_id: z.string().guid('Invalid bot ID'),
topic: z.string().max(200, 'Topic must be at most 200 characters').optional(),
question: z.string().max(500, 'Question must be at most 500 characters').optional(),
content: z
.string()
.min(10, 'Content must be at least 10 characters')
.max(10000, 'Content must be at most 10,000 characters'),
keywords: z.array(z.string().max(50)).max(20, 'Maximum 20 keywords').optional(),
source: z.string().max(500, 'Source must be at most 500 characters').optional(),
metadata: z.record(z.string(), z.unknown()).optional(),
});
/**
* Schema for updating a knowledge chunk
*/
export const UpdateKnowledgeChunkSchema = z.object({
topic: z.string().max(200, 'Topic must be at most 200 characters').nullable().optional(),
question: z.string().max(500, 'Question must be at most 500 characters').nullable().optional(),
content: z
.string()
.min(10, 'Content must be at least 10 characters')
.max(10000, 'Content must be at most 10,000 characters')
.optional(),
keywords: z.array(z.string().max(50)).max(20, 'Maximum 20 keywords').optional(),
source: z.string().max(500, 'Source must be at most 500 characters').nullable().optional(),
metadata: z.record(z.string(), z.unknown()).optional(),
});
/**
* Schema for bulk creating knowledge chunks
*/
export const BulkCreateKnowledgeChunksSchema = z.object({
bot_id: z.string().guid('Invalid bot ID'),
chunks: z
.array(
z.object({
topic: z.string().max(200).optional(),
question: z.string().max(500).optional(),
content: z.string().min(10).max(10000),
keywords: z.array(z.string().max(50)).max(20).optional(),
source: z.string().max(500).optional(),
}),
)
.min(1, 'At least one chunk required')
.max(100, 'Maximum 100 chunks per request'),
});
// Type exports inferred from schemas
export type CreateCustomBotInput = z.infer<typeof CreateCustomBotSchema>;
export type UpdateCustomBotInput = z.infer<typeof UpdateCustomBotSchema>;
export type CreateKnowledgeChunkInput = z.infer<typeof CreateKnowledgeChunkSchema>;
export type UpdateKnowledgeChunkInput = z.infer<typeof UpdateKnowledgeChunkSchema>;
export type BulkCreateKnowledgeChunksInput = z.infer<typeof BulkCreateKnowledgeChunksSchema>;