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
|
|
@ -3,7 +3,7 @@
|
|||
// apps/admin/src/app/(admin)/models/page.tsx
|
||||
// D3RO Voice — Dynamic AI Models & Cloud STT Transcription Provider Manager (Midnight Glass v2)
|
||||
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import React, { useState, useEffect, useRef } from 'react'
|
||||
import {
|
||||
Box,
|
||||
Typography,
|
||||
|
|
@ -111,19 +111,29 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
const [llmCompletionCost, setLlmCompletionCost] = useState('0')
|
||||
const [llmMemo, setLlmMemo] = useState('')
|
||||
|
||||
const mountedRef = useRef(true)
|
||||
const loadSeqRef = useRef(0)
|
||||
|
||||
const loadData = async () => {
|
||||
const seq = ++loadSeqRef.current
|
||||
setDataError(null)
|
||||
try {
|
||||
const [sttData, llmData] = await Promise.all([fetchSttEndpointsClient(), fetchModelEndpointsClient()])
|
||||
if (!mountedRef.current || loadSeqRef.current !== seq) return
|
||||
setSttEndpoints(sttData)
|
||||
setLlmEndpoints(llmData)
|
||||
} catch (error) {
|
||||
if (!mountedRef.current || loadSeqRef.current !== seq) return
|
||||
setDataError(error instanceof Error ? error.message : '관리자 백엔드에서 엔드포인트를 불러오지 못했습니다.')
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
loadData()
|
||||
mountedRef.current = true
|
||||
void loadData()
|
||||
return () => {
|
||||
mountedRef.current = false
|
||||
}
|
||||
}, [])
|
||||
|
||||
// ── STT Handlers ──────────────────────────────────────────────────────────
|
||||
|
|
@ -160,11 +170,17 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
setSttFallbackPriority(ep.fallbackPriority)
|
||||
setSttIsDefault(ep.isDefault)
|
||||
setSttTestModalResult(null)
|
||||
setSttMemo('')
|
||||
setSttModalOpen(true)
|
||||
}
|
||||
|
||||
const handleSaveSttEndpoint = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
const parsedCostPerMinute = parseFloat(sttCostPerMinute)
|
||||
if (!Number.isFinite(parsedCostPerMinute) || parsedCostPerMinute < 0) {
|
||||
alert('분당 비용은 0 이상의 유효한 숫자여야 합니다.')
|
||||
return
|
||||
}
|
||||
setSttLoading(true)
|
||||
|
||||
try {
|
||||
|
|
@ -178,8 +194,8 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
language: sttLanguage,
|
||||
prompt: sttPrompt ? sttPrompt : undefined,
|
||||
temperature: 0.0,
|
||||
costPerMinute: parseFloat(sttCostPerMinute),
|
||||
costPerSecond: parseFloat(sttCostPerMinute) / 60,
|
||||
costPerMinute: parsedCostPerMinute,
|
||||
costPerSecond: parsedCostPerMinute / 60,
|
||||
isDefault: sttIsDefault,
|
||||
isActive: true,
|
||||
fallbackPriority: sttFallbackPriority,
|
||||
|
|
@ -193,11 +209,13 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
}
|
||||
|
||||
await loadData()
|
||||
setSttModalOpen(false)
|
||||
if (mountedRef.current) setSttModalOpen(false)
|
||||
} catch (err) {
|
||||
alert('Error saving STT endpoint: ' + (err instanceof Error ? err.message : String(err)))
|
||||
if (mountedRef.current) {
|
||||
alert('Error saving STT endpoint: ' + (err instanceof Error ? err.message : String(err)))
|
||||
}
|
||||
} finally {
|
||||
setSttLoading(false)
|
||||
if (mountedRef.current) setSttLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -206,6 +224,7 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
if (memo.length < 3) return
|
||||
try {
|
||||
await setDefaultSttEndpointClient(id, memo)
|
||||
if (!mountedRef.current) return
|
||||
setSttEndpoints((prev) =>
|
||||
prev.map((ep) => ({
|
||||
...ep,
|
||||
|
|
@ -213,7 +232,9 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
}))
|
||||
)
|
||||
} catch (err) {
|
||||
alert('Error: ' + (err instanceof Error ? err.message : String(err)))
|
||||
if (mountedRef.current) {
|
||||
alert('Error: ' + (err instanceof Error ? err.message : String(err)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -221,11 +242,13 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
setSttPingStatus((prev) => ({ ...prev, [id]: 'Testing...' }))
|
||||
try {
|
||||
const result = await testSttEndpointClient(id)
|
||||
if (!mountedRef.current) return
|
||||
setSttPingStatus((prev) => ({
|
||||
...prev,
|
||||
[id]: result.success ? `⚡ OK • ${result.latencyMs}ms` : `❌ ${result.message}`
|
||||
}))
|
||||
} catch (error) {
|
||||
if (!mountedRef.current) return
|
||||
setSttPingStatus((prev) => ({
|
||||
...prev,
|
||||
[id]: `❌ ${error instanceof Error ? error.message : 'Test failed'}`
|
||||
|
|
@ -238,19 +261,21 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
setSttTestModalResult(null)
|
||||
try {
|
||||
const result = await testSttEndpointClient(sttEditingId ?? 0, sttApiKey, sttEndpointUrl)
|
||||
if (!mountedRef.current) return
|
||||
setSttTestModalResult({
|
||||
success: result.success,
|
||||
message: result.message,
|
||||
ms: result.latencyMs,
|
||||
})
|
||||
} catch (err) {
|
||||
if (!mountedRef.current) return
|
||||
setSttTestModalResult({
|
||||
success: false,
|
||||
message: err instanceof Error ? err.message : 'Test failed',
|
||||
ms: 0,
|
||||
})
|
||||
} finally {
|
||||
setTestingInModal(false)
|
||||
if (mountedRef.current) setTestingInModal(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -260,9 +285,13 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
if (memo.length < 3) return
|
||||
try {
|
||||
await deleteSttEndpointClient(id, memo)
|
||||
setSttEndpoints((prev) => prev.filter((ep) => ep.id !== id))
|
||||
if (mountedRef.current) {
|
||||
setSttEndpoints((prev) => prev.filter((ep) => ep.id !== id))
|
||||
}
|
||||
} catch (err) {
|
||||
alert('Error: ' + (err instanceof Error ? err.message : String(err)))
|
||||
if (mountedRef.current) {
|
||||
alert('Error: ' + (err instanceof Error ? err.message : String(err)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -282,6 +311,15 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
|
||||
const handleAddLlmEndpoint = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
const parsedPromptCost = parseFloat(llmPromptCost)
|
||||
const parsedCompletionCost = parseFloat(llmCompletionCost)
|
||||
if (
|
||||
!Number.isFinite(parsedPromptCost) || parsedPromptCost < 0
|
||||
|| !Number.isFinite(parsedCompletionCost) || parsedCompletionCost < 0
|
||||
) {
|
||||
alert('토큰 비용은 0 이상의 유효한 숫자여야 합니다.')
|
||||
return
|
||||
}
|
||||
setLlmLoading(true)
|
||||
|
||||
try {
|
||||
|
|
@ -291,11 +329,12 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
provider: llmProvider,
|
||||
endpointUrl: llmEndpointUrl,
|
||||
apiKey: llmApiKey,
|
||||
costPer1kPromptTokens: parseFloat(llmPromptCost),
|
||||
costPer1kCompletionTokens: parseFloat(llmCompletionCost),
|
||||
costPer1kPromptTokens: parsedPromptCost,
|
||||
costPer1kCompletionTokens: parsedCompletionCost,
|
||||
memo: llmMemo.trim(),
|
||||
})
|
||||
await loadData()
|
||||
if (!mountedRef.current) return
|
||||
setLlmModalOpen(false)
|
||||
setLlmModelId('')
|
||||
setLlmModelName('')
|
||||
|
|
@ -303,9 +342,11 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
setLlmApiKey('')
|
||||
setLlmMemo('')
|
||||
} catch (err) {
|
||||
alert('Error: ' + (err instanceof Error ? err.message : String(err)))
|
||||
if (mountedRef.current) {
|
||||
alert('Error: ' + (err instanceof Error ? err.message : String(err)))
|
||||
}
|
||||
} finally {
|
||||
setLlmLoading(false)
|
||||
if (mountedRef.current) setLlmLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -315,9 +356,13 @@ export default function ServiceModelsPage(): React.ReactElement {
|
|||
if (memo.length < 3) return
|
||||
try {
|
||||
await deleteModelEndpointClient(id, memo)
|
||||
setLlmEndpoints((current) => current.filter((endpoint) => endpoint.id !== id))
|
||||
if (mountedRef.current) {
|
||||
setLlmEndpoints((current) => current.filter((endpoint) => endpoint.id !== id))
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Error: ' + (error instanceof Error ? error.message : String(error)))
|
||||
if (mountedRef.current) {
|
||||
alert('Error: ' + (error instanceof Error ? error.message : String(error)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue