feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
|
|
@ -14,7 +14,8 @@
|
|||
// 공급자 에러 본문(조직 ID, 마스킹된 키 힌트 등)은 절대 응답에 싣지 않는다.
|
||||
// 상태 코드만 서버 로그에 남기고 고정 코드를 반환한다.
|
||||
|
||||
import { corsHeaders, handleCorsPreflightRequest } from '../_shared/cors.ts'
|
||||
import { handleCorsPreflightRequest } from '../_shared/cors.ts'
|
||||
import { createStatusJsonResponder, JsonBodyError, readJsonBody } from '../_shared/json-response.ts'
|
||||
import {
|
||||
buildRealtimeSessionConfig,
|
||||
type RealtimeSessionConfig,
|
||||
|
|
@ -75,21 +76,15 @@ export interface RealtimeTokenDeps {
|
|||
logger: RealtimeLogger
|
||||
}
|
||||
|
||||
function json(
|
||||
status: number,
|
||||
payload: Record<string, unknown>,
|
||||
): Response {
|
||||
return new Response(JSON.stringify(payload), {
|
||||
status,
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
})
|
||||
}
|
||||
const MAX_REQUEST_BYTES = 16 * 1024
|
||||
const json = createStatusJsonResponder()
|
||||
|
||||
async function readBody(req: Request): Promise<RealtimeTokenRequest> {
|
||||
const parsed: unknown = await req.json().catch(() => ({}))
|
||||
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
||||
? parsed as RealtimeTokenRequest
|
||||
: {}
|
||||
return await readJsonBody(req, {
|
||||
maxBytes: MAX_REQUEST_BYTES,
|
||||
allowEmptyObject: true,
|
||||
requirePlainObject: true,
|
||||
}) as RealtimeTokenRequest
|
||||
}
|
||||
|
||||
export function createRealtimeTokenHandler(deps: RealtimeTokenDeps): (req: Request) => Promise<Response> {
|
||||
|
|
@ -167,6 +162,9 @@ export function createRealtimeTokenHandler(deps: RealtimeTokenDeps): (req: Reque
|
|||
|
||||
return json(200, { ...minted.data, model: resolution.model, tier })
|
||||
} catch (err) {
|
||||
if (err instanceof JsonBodyError) {
|
||||
return json(err.status, { error: err.code })
|
||||
}
|
||||
logger.error('realtime-token failed', {
|
||||
kind: err instanceof Error ? err.name : typeof err,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue