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

@ -3,7 +3,7 @@
// IO is injected through ports so the quota guard is testable offline.
import { handleCorsPreflightRequest } from '../_shared/cors.ts'
import { errorResponse, jsonResponse as json } from '../_shared/json-response.ts'
import { errorResponse, JsonBodyError, jsonResponse as json, readJsonBody } from '../_shared/json-response.ts'
import { type EmbeddingProvider, isEmbedding } from '../_shared/openai-embeddings.ts'
import {
EMBEDDING_LIMITS,
@ -45,10 +45,17 @@ export function createSearchKnowledgeHandler(deps: SearchKnowledgeDeps): (req: R
try {
const user = await deps.authenticate(req)
const body = await req.json().catch(() => null) as {
query?: unknown
count?: unknown
} | null
let body: { query?: unknown; count?: unknown } | null = null
try {
body = await readJsonBody(req, { maxBytes: 16 * 1024, requirePlainObject: true }) as {
query?: unknown
count?: unknown
}
} catch (error) {
if (error instanceof JsonBodyError && error.status === 413) {
return json(413, { error: 'request_too_large' })
}
}
const query = typeof body?.query === 'string' ? body.query.trim() : ''
const count = body?.count === undefined ? DEFAULT_MATCH_COUNT : body.count
if (!query || query.length > EMBEDDING_LIMITS.maxQueryChars) return json(400, { error: 'invalid_query' })