fix(edge): meter and size-cap knowledge embeddings in embed-chunks and search-knowledge
This commit is contained in:
parent
b35676c75c
commit
1afaea7214
12 changed files with 1111 additions and 270 deletions
30
server/supabase/functions/_shared/json-response.ts
Normal file
30
server/supabase/functions/_shared/json-response.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// server/supabase/functions/_shared/json-response.ts
|
||||
// JSON response + auth-error mapping shared by the knowledge functions.
|
||||
|
||||
import { corsHeaders } from './cors.ts'
|
||||
import type { AuthError } from './auth.ts'
|
||||
|
||||
export function jsonResponse(status: number, body: Record<string, unknown>): Response {
|
||||
return new Response(JSON.stringify(body), {
|
||||
status,
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
})
|
||||
}
|
||||
|
||||
export function isAuthError(error: unknown): error is AuthError {
|
||||
return Boolean(
|
||||
error
|
||||
&& typeof error === 'object'
|
||||
&& 'status' in error
|
||||
&& (error.status === 401 || error.status === 403)
|
||||
&& 'message' in error
|
||||
&& typeof error.message === 'string',
|
||||
)
|
||||
}
|
||||
|
||||
/** Map a thrown value to a response: auth errors keep their status, anything else is a 500. */
|
||||
export function errorResponse(error: unknown): Response {
|
||||
// Same shape as auth.ts authErrorResponse, without loading the Supabase client.
|
||||
if (isAuthError(error)) return jsonResponse(error.status, { error: error.message })
|
||||
return jsonResponse(500, { error: 'internal_error' })
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue