- Migration: app_settings table with admin-only RLS (ANTHROPIC_API_KEY, VOYAGE_API_KEY) - lib/settings.ts: getApiKey() reads DB first, falls back to env var - lib/claude/client.ts: factory createAnthropicClient(apiKey) replaces singleton - lib/claude/embed.ts: optional apiKey param, falls back to env - 3 Claude AI routes + similar route: fetch key from settings before calling AI - incidents/route.ts: fire-and-forget embed reads VOYAGE key from settings - GET/POST /api/settings: admin-only masked key management endpoint - /hse/settings page + ApiKeyForm client component Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FFDuBhMKvoWjrWT3ZnGmmr
16 lines
639 B
TypeScript
16 lines
639 B
TypeScript
export async function embedText(text: string, apiKey?: string): Promise<number[]> {
|
|
const key = apiKey ?? process.env.VOYAGE_API_KEY
|
|
if (!key) throw new Error('VOYAGE_API_KEY is not set')
|
|
const res = await fetch('https://api.voyageai.com/v1/embeddings', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': `Bearer ${key}`,
|
|
},
|
|
body: JSON.stringify({ input: [text], model: 'voyage-3-lite' }),
|
|
})
|
|
if (!res.ok) throw new Error(`Voyage embed failed: ${res.status}`)
|
|
const json = await res.json() as { data: Array<{ embedding: number[] }> }
|
|
return json.data[0].embedding
|
|
}
|