feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes

This commit is contained in:
Yun Chan 2026-11-14 11:51:41 +09:00
parent 01ef3293cf
commit 66b6b45ba9
399 changed files with 17828 additions and 11330 deletions

View file

@ -1,3 +1,4 @@
import { isRecord, isUuid } from '@d3ro/core/guards'
import { SUPABASE_URL } from '@d3ro/core/supabase-config'
export type ChatRole = 'user' | 'assistant'
@ -44,11 +45,7 @@ export interface ReportableChatResult {
const MAX_MESSAGES = 40
const MAX_MESSAGE_CHARS = 8_000
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value)
}
export function normalizeChatMessages(messages: ChatRequestMessage[]): ChatRequestMessage[] {
if (messages.length === 0 || messages.length > MAX_MESSAGES) {
@ -135,7 +132,7 @@ async function sendChatRequest(
: response.headers?.get('X-D3RO-Generation-Id')?.trim() ?? ''
if (
generationPurpose !== null
&& (typeof generationId !== 'string' || !UUID_PATTERN.test(generationId))
&& (typeof generationId !== 'string' || !isUuid(generationId))
) {
throw new ChatServiceError('INVALID_RESPONSE', true)
}