MVP 0.95
This commit is contained in:
1 parent
4f37991ad1
commit
be11f82f84
39 files changed
+2490
-239
No files matched your search
@@ -20,6 +20,7 @@ import AdminGenerationPage from './pages/AdminGenerationPage.jsx'
|
||||
import AdminPlaceholdersPage from './pages/AdminPlaceholdersPage.jsx'
|
||||
import AdminFeaturesPage from './pages/AdminFeaturesPage.jsx'
|
||||
import AdminDialoguePage from './pages/AdminDialoguePage.jsx'
|
||||
import AdminDebugPage from './pages/AdminDebugPage.jsx'
|
||||
import AdminProvidersPage from './pages/AdminProvidersPage.jsx'
|
||||
import AdminIdentitiesPage from './pages/AdminIdentitiesPage.jsx'
|
||||
import RequireAdmin from './layouts/RequireAdmin.jsx'
|
||||
@@ -152,6 +153,7 @@ export default function App() {
|
||||
<Route path="providers" element={<AdminProvidersPage />} />
|
||||
<Route path="identities" element={<AdminIdentitiesPage />} />
|
||||
<Route path="dialogue" element={<AdminDialoguePage />} />
|
||||
<Route path="debug" element={<AdminDebugPage />} />
|
||||
</Route>
|
||||
</Route>
|
||||
</Route>
|
||||
|
||||
@@ -19,6 +19,35 @@ export async function api(path, { token, method = 'GET', body } = {}) {
|
||||
return data
|
||||
}
|
||||
|
||||
function filenameFromDisposition(header, fallback) {
|
||||
const raw = header || ''
|
||||
const utf = raw.match(/filename\*=UTF-8''([^;]+)/i)
|
||||
if (utf) return decodeURIComponent(utf[1])
|
||||
const plain = raw.match(/filename="?([^";]+)"?/i)
|
||||
return plain ? plain[1] : fallback
|
||||
}
|
||||
|
||||
export async function apiDownload(path, { token, filename } = {}) {
|
||||
const headers = {}
|
||||
if (token) headers['X-Auth-Token'] = token
|
||||
const response = await fetch(path, { headers })
|
||||
if (!response.ok) {
|
||||
const data = await response.json().catch(() => null)
|
||||
const detail = data?.detail
|
||||
const message = typeof detail === 'string' ? detail : (detail?.message || 'Download fehlgeschlagen')
|
||||
throw new Error(message)
|
||||
}
|
||||
const blob = await response.blob()
|
||||
const url = URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = filenameFromDisposition(response.headers.get('Content-Disposition'), filename || 'kansho-debug.json')
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
export async function apiUpload(path, { token, file, field = 'file' } = {}) {
|
||||
const headers = {}
|
||||
if (token) headers['X-Auth-Token'] = token
|
||||
|
||||
@@ -186,6 +186,12 @@ table.plain th, table.plain td { text-align: left; padding: 0.45rem 0.3rem; bord
|
||||
flex-wrap: wrap;
|
||||
list-style: none;
|
||||
}
|
||||
.row-item > button.ghost:first-child {
|
||||
flex: 1 1 16rem;
|
||||
justify-content: flex-start;
|
||||
text-align: left;
|
||||
white-space: normal;
|
||||
}
|
||||
.row-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }
|
||||
.row-actions > button,
|
||||
.row-actions > a {
|
||||
@@ -197,6 +203,20 @@ table.plain th, table.plain td { text-align: left; padding: 0.45rem 0.3rem; bord
|
||||
}
|
||||
ul.stack { padding: 0; }
|
||||
|
||||
.debug-tree { display: grid; gap: 0.6rem; }
|
||||
.debug-tree details { border-top: 1px solid var(--line); padding-top: 0.4rem; }
|
||||
.debug-tree summary {
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.45rem;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.debug-tree .debug-day,
|
||||
.debug-tree .debug-conversation { margin-left: 0.6rem; }
|
||||
.debug-tree summary .ghost { width: auto; flex: 0 0 auto; min-height: 2.2rem; }
|
||||
|
||||
.dialogue-page {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
@@ -404,6 +424,8 @@ label.button-file {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.journal-debug { margin-top: 1.4rem; }
|
||||
.journal-debug .trace-panel { margin-top: 0.4rem; }
|
||||
.trace-panel {
|
||||
margin-top: 1.2rem;
|
||||
padding-top: 0.8rem;
|
||||
|
||||
@@ -102,6 +102,23 @@ function stageTitle(stage, index) {
|
||||
return `Stufe ${index + 1}: ${layer}`
|
||||
}
|
||||
|
||||
function detectCoverageLabel(trace) {
|
||||
const chunks = trace?.chunk_count
|
||||
const ok = trace?.chunks_ok
|
||||
if (chunks == null && ok == null && trace?.full_detection_coverage == null) return 'nicht verfügbar'
|
||||
const processed = trace?.full_detection_coverage ? 'alle Chunks technisch verarbeitet' : 'Chunks unvollständig'
|
||||
if (chunks == null) return processed
|
||||
return `${ok ?? '–'}/${chunks} · ${processed}`
|
||||
}
|
||||
|
||||
function detectCertaintyLabel(trace) {
|
||||
if (trace?.purpose === 'local_source_artifact' || trace?.status === 'local_ok') {
|
||||
return 'nicht zutreffend'
|
||||
}
|
||||
if (trace?.semantic_identity_guaranteed === true) return 'garantiert'
|
||||
return 'nicht garantiert'
|
||||
}
|
||||
|
||||
function detectLabel(trace) {
|
||||
if (trace?.purpose === 'local_source_artifact' || trace?.status === 'local_ok') {
|
||||
return 'kein Detect — lokal'
|
||||
@@ -223,6 +240,22 @@ function StageView({ stage, index, journal }) {
|
||||
<dd>{layerLabel(stage)}</dd>
|
||||
<dt>Maskierung</dt>
|
||||
<dd>{detectLabel(stage)}</dd>
|
||||
<dt>Chunks technisch verarbeitet</dt>
|
||||
<dd>{detectCoverageLabel(stage)}</dd>
|
||||
<dt>Bestätigte Registry angewendet</dt>
|
||||
<dd>
|
||||
{stage?.confirmed_registry_applied == null
|
||||
? unavailable(stage?.confirmed_registry_hits)
|
||||
: stage.confirmed_registry_applied
|
||||
? `ja · ${stage.confirmed_registry_hits ?? 0} Treffer`
|
||||
: 'nein'}
|
||||
</dd>
|
||||
<dt>Semantische Treffer dieses Requests</dt>
|
||||
<dd>{unavailable(stage?.request_local_hits)}</dd>
|
||||
<dt>Detect-Modell</dt>
|
||||
<dd>{unavailable(stage?.detect_model)}</dd>
|
||||
<dt>Semantische Identitätserkennung</dt>
|
||||
<dd>{detectCertaintyLabel(stage)}</dd>
|
||||
<dt>Klasse</dt>
|
||||
<dd>{unavailable(stage?.data_class)}</dd>
|
||||
<dt>Masken</dt>
|
||||
@@ -239,6 +272,9 @@ function StageView({ stage, index, journal }) {
|
||||
/>
|
||||
<Block title={journal ? 'Antwort dieser Stufe' : 'Antwort dieses einen Calls (Operation + Impuls)'} value={stage?.raw} />
|
||||
<Block title="Lokal demaskiert" value={stage?.reply} />
|
||||
<Block title="Gespeicherter Entwurf" value={stage?.stored_body || stage?.stored_title
|
||||
? [stage?.stored_title, stage?.stored_body].filter(Boolean).join('\n\n')
|
||||
: ''} />
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -257,7 +293,8 @@ export default function CallTrace({ decision, trace }) {
|
||||
<ol className="muted">
|
||||
<li>
|
||||
Maskierung prüft den vollständigen gerenderten Egress (Detect plus lokale Maskierung),
|
||||
nicht nur Nutzerzeilen. Sie wählt keine Operation und schreibt keinen Impuls.
|
||||
nicht nur Nutzerzeilen. Technisch verarbeitete Chunks bedeuten keine vollständige
|
||||
semantische Identitätserkennung. Sie wählt keine Operation und schreibt keinen Impuls.
|
||||
</li>
|
||||
{journal ? (
|
||||
<>
|
||||
|
||||
@@ -8,6 +8,7 @@ export function getAdminNavItems() {
|
||||
{ to: '/admin/features', label: 'Kontingente' },
|
||||
{ to: '/admin/providers', label: 'Schnittstellen' },
|
||||
{ to: '/admin/identities', label: 'Identitäten' },
|
||||
{ to: '/admin/dialogue', label: 'Dialog' }
|
||||
{ to: '/admin/dialogue', label: 'Dialog' },
|
||||
{ to: '/admin/debug', label: 'Debug' }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { api, apiDownload } from '../api.js'
|
||||
import CallTrace from '../components/CallTrace.jsx'
|
||||
import { useAuth } from '../context/AuthContext.jsx'
|
||||
|
||||
function purposeLabel(purpose) {
|
||||
if (purpose === 'dialogue_turn') return 'Dialogzug'
|
||||
if (purpose === 'journal_generate') return 'Journalentwurf'
|
||||
if (purpose === 'profile_review') return 'Profilreview'
|
||||
return purpose || 'Schritt'
|
||||
}
|
||||
|
||||
function exportPath({ format = 'json', conversationId, journalDayId } = {}) {
|
||||
const params = new URLSearchParams({ format })
|
||||
if (conversationId) params.set('conversation_id', conversationId)
|
||||
if (journalDayId) params.set('journal_day_id', journalDayId)
|
||||
return `/api/admin/debug/export?${params}`
|
||||
}
|
||||
|
||||
export default function AdminDebugPage() {
|
||||
const { session } = useAuth()
|
||||
const [settings, setSettings] = useState(null)
|
||||
const [tree, setTree] = useState([])
|
||||
const [detail, setDetail] = useState(null)
|
||||
const [error, setError] = useState('')
|
||||
const [notice, setNotice] = useState('')
|
||||
const [busy, setBusy] = useState('')
|
||||
const [openStep, setOpenStep] = useState('')
|
||||
|
||||
const load = async () => {
|
||||
const [nextSettings, nextTree] = await Promise.all([
|
||||
api('/api/admin/debug', { token: session.token }),
|
||||
api('/api/admin/debug/tree', { token: session.token })
|
||||
])
|
||||
setSettings(nextSettings)
|
||||
setTree(nextTree.spaces || [])
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
load().catch((e) => setError(e.message))
|
||||
}, [session.token])
|
||||
|
||||
const toggle = async (enabled) => {
|
||||
setError('')
|
||||
setNotice('')
|
||||
setBusy('toggle')
|
||||
try {
|
||||
const payload = await api('/api/admin/debug', {
|
||||
token: session.token,
|
||||
method: 'PUT',
|
||||
body: { persist_enabled: enabled }
|
||||
})
|
||||
setSettings(payload)
|
||||
setNotice(enabled ? 'Persistenz ist an. Jeder Admin-Dialogschritt wird dem Gespräch zugeordnet.' : 'Persistenz ist aus. Vorhandene Läufe bleiben.')
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
} finally {
|
||||
setBusy('')
|
||||
}
|
||||
}
|
||||
|
||||
const open = async (id) => {
|
||||
setError('')
|
||||
setOpenStep(id)
|
||||
try {
|
||||
setDetail(await api(`/api/admin/debug/runs/${id}`, { token: session.token }))
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
}
|
||||
}
|
||||
|
||||
const remove = async (id) => {
|
||||
setError('')
|
||||
try {
|
||||
await api(`/api/admin/debug/runs/${id}`, { token: session.token, method: 'DELETE' })
|
||||
if (detail?.id === id) setDetail(null)
|
||||
await load()
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
}
|
||||
}
|
||||
|
||||
const clearAll = async () => {
|
||||
if (!window.confirm('Alle gespeicherten Debug-Läufe dieses Profils unwiderruflich löschen?')) return
|
||||
setError('')
|
||||
setBusy('clear')
|
||||
try {
|
||||
const result = await api('/api/admin/debug/runs/clear', { token: session.token, method: 'POST' })
|
||||
setDetail(null)
|
||||
setNotice(`${result.deleted || 0} Läufe gelöscht.`)
|
||||
await load()
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
} finally {
|
||||
setBusy('')
|
||||
}
|
||||
}
|
||||
|
||||
const download = async (opts) => {
|
||||
setError('')
|
||||
const key = opts.conversationId || opts.journalDayId || opts.format || 'json'
|
||||
setBusy(key)
|
||||
try {
|
||||
await apiDownload(exportPath(opts), { token: session.token })
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
} finally {
|
||||
setBusy('')
|
||||
}
|
||||
}
|
||||
|
||||
const payload = detail?.payload || {}
|
||||
const decision = payload.decision || detail?.decision
|
||||
const trace = payload.trace || detail?.trace
|
||||
const hasTree = tree.some((space) => (space.days || []).length)
|
||||
|
||||
return (
|
||||
<section className="card">
|
||||
<h1>Debug-Verlauf</h1>
|
||||
<p className="muted">
|
||||
Entwicklungsoption. Speichert die Testspur lokal je Dialogschritt, gegliedert nach Space / Tag / Gespräch.
|
||||
Mapping-Tabelle und Secrets bleiben ausgeschlossen. Nur das eigene Admin-Profil.
|
||||
</p>
|
||||
{error && <p className="error">{error}</p>}
|
||||
{notice && <p>{notice}</p>}
|
||||
{settings && (
|
||||
<>
|
||||
<label className="check">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={Boolean(settings.persist_enabled)}
|
||||
disabled={busy === 'toggle'}
|
||||
onChange={(e) => toggle(e.target.checked)}
|
||||
/>
|
||||
Debug persistieren
|
||||
</label>
|
||||
<dl className="meta">
|
||||
<dt>Status</dt>
|
||||
<dd>{settings.persist_enabled ? 'an' : 'aus'}</dd>
|
||||
<dt>Gespeicherte Schritte</dt>
|
||||
<dd>{settings.run_count}</dd>
|
||||
</dl>
|
||||
<div className="row-actions">
|
||||
<button type="button" className="ghost" onClick={() => download({ format: 'json' })} disabled={Boolean(busy)}>
|
||||
{busy === 'json' ? 'Lädt …' : 'Alles als JSON'}
|
||||
</button>
|
||||
<button type="button" className="ghost" onClick={() => download({ format: 'markdown' })} disabled={Boolean(busy)}>
|
||||
{busy === 'markdown' ? 'Lädt …' : 'Alles als Markdown'}
|
||||
</button>
|
||||
<button type="button" className="ghost" onClick={clearAll} disabled={busy === 'clear' || !settings.run_count}>
|
||||
Verlauf löschen
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<h2>Space / Tag / Gespräche</h2>
|
||||
{!hasTree && <p className="muted">Noch keine persistierten Schritte. Schalter an, dann im Journal oder Dev-Harness sprechen.</p>}
|
||||
<div className="debug-tree">
|
||||
{tree.map((space) => (
|
||||
<details key={space.id || 'unassigned-space'} open>
|
||||
<summary>{space.title || 'Ohne Space'}</summary>
|
||||
{(space.days || []).map((day) => (
|
||||
<details key={day.id || 'unassigned-day'} open className="debug-day">
|
||||
<summary>
|
||||
<span>{day.calendar_date || 'Ohne Tag'}</span>
|
||||
{day.id && (
|
||||
<button
|
||||
type="button"
|
||||
className="ghost"
|
||||
onClick={(event) => {
|
||||
event.preventDefault()
|
||||
download({ format: 'json', journalDayId: day.id })
|
||||
}}
|
||||
>
|
||||
Tag-JSON
|
||||
</button>
|
||||
)}
|
||||
</summary>
|
||||
<ul className="stack">
|
||||
{(day.conversations || []).map((conv) => (
|
||||
<li key={conv.id || conv.title}>
|
||||
<details open className="debug-conversation">
|
||||
<summary>
|
||||
<span>{conv.title || 'Gespräch'} · {conv.step_count} Schritte</span>
|
||||
{conv.id && (
|
||||
<button
|
||||
type="button"
|
||||
className="ghost"
|
||||
onClick={(event) => {
|
||||
event.preventDefault()
|
||||
download({ format: 'json', conversationId: conv.id })
|
||||
}}
|
||||
>
|
||||
Gespräch-JSON
|
||||
</button>
|
||||
)}
|
||||
</summary>
|
||||
<ul className="stack">
|
||||
{(conv.steps || []).map((step, index) => (
|
||||
<li key={step.id} className="row-item">
|
||||
<button
|
||||
type="button"
|
||||
className={openStep === step.id ? 'ghost active' : 'ghost'}
|
||||
onClick={() => open(step.id)}
|
||||
>
|
||||
{index + 1}. {purposeLabel(step.purpose)} · {step.created} · {step.summary}
|
||||
</button>
|
||||
<button type="button" className="ghost" onClick={() => remove(step.id)}>Löschen</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
</li>
|
||||
))}
|
||||
{(day.generates || []).map((step, index) => (
|
||||
<li key={step.id} className="row-item">
|
||||
<button
|
||||
type="button"
|
||||
className={openStep === step.id ? 'ghost active' : 'ghost'}
|
||||
onClick={() => open(step.id)}
|
||||
>
|
||||
Journalentwurf {index + 1} · {step.created} · {step.summary}
|
||||
</button>
|
||||
<button type="button" className="ghost" onClick={() => remove(step.id)}>Löschen</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
))}
|
||||
</details>
|
||||
))}
|
||||
</div>
|
||||
{detail && (
|
||||
<>
|
||||
<h2>Schritt</h2>
|
||||
<dl className="meta">
|
||||
<dt>Zweck</dt>
|
||||
<dd>{purposeLabel(detail.purpose)}</dd>
|
||||
<dt>Space</dt>
|
||||
<dd>{detail.space_title || '—'}</dd>
|
||||
<dt>Tag</dt>
|
||||
<dd>{detail.calendar_date || '—'}</dd>
|
||||
<dt>Gespräch</dt>
|
||||
<dd>{detail.conversation_title || detail.conversation_id || '—'}</dd>
|
||||
<dt>Zeit</dt>
|
||||
<dd>{detail.created}</dd>
|
||||
<dt>Status</dt>
|
||||
<dd>{detail.status}</dd>
|
||||
</dl>
|
||||
{payload.user?.body && (
|
||||
<details open>
|
||||
<summary>Nutzer</summary>
|
||||
<pre className="code">{payload.user.body}</pre>
|
||||
</details>
|
||||
)}
|
||||
{payload.assistant?.body && (
|
||||
<details open>
|
||||
<summary>Antwort</summary>
|
||||
<pre className="code">{payload.assistant.body}</pre>
|
||||
</details>
|
||||
)}
|
||||
<CallTrace decision={decision} trace={trace} />
|
||||
</>
|
||||
)}
|
||||
<p className="muted">
|
||||
<Link to="/dialog">Zum Dev/Test-Harness</Link>
|
||||
{' · '}
|
||||
<Link to="/journal">Zum Journal</Link>
|
||||
</p>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -34,8 +34,10 @@ export default function AdminHomePage() {
|
||||
<dd>{health.inventory?.providers?.generate?.ready ? 'bereit' : 'nicht bereit'}</dd>
|
||||
<dt>Maskierung</dt>
|
||||
<dd>{health.inventory?.providers?.detect?.ready ? 'bereit (semantisch)' : 'nicht bereit, fail-closed'}</dd>
|
||||
<dt>Debug-Schritte</dt>
|
||||
<dd>{health.inventory?.debug_runs ?? 0}{health.inventory?.debug_persist_enabled ? ' · an' : ' · aus'}</dd>
|
||||
</dl>
|
||||
<p className="muted">Weiter: <Link to="/admin/users">Nutzer</Link> · <Link to="/admin/prompts">Prompts</Link> · <Link to="/admin/generation">Generierungsrichtlinien</Link> · <Link to="/admin/placeholders">Platzhalter</Link> · <Link to="/admin/features">Kontingente</Link> · <Link to="/admin/providers">Schnittstellen</Link> · <Link to="/admin/identities">Identitäten</Link> · <Link to="/admin/dialogue">Dialog</Link></p>
|
||||
<p className="muted">Weiter: <Link to="/admin/users">Nutzer</Link> · <Link to="/admin/prompts">Prompts</Link> · <Link to="/admin/generation">Generierungsrichtlinien</Link> · <Link to="/admin/placeholders">Platzhalter</Link> · <Link to="/admin/features">Kontingente</Link> · <Link to="/admin/providers">Schnittstellen</Link> · <Link to="/admin/identities">Identitäten</Link> · <Link to="/admin/dialogue">Dialog</Link> · <Link to="/admin/debug">Debug</Link></p>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { api } from '../api.js'
|
||||
import CallTrace from '../components/CallTrace.jsx'
|
||||
import { api, apiDownload } from '../api.js'
|
||||
import { useAuth } from '../context/AuthContext.jsx'
|
||||
|
||||
function convLabel(item, index) {
|
||||
@@ -18,8 +17,7 @@ export default function DialoguePage() {
|
||||
const [error, setError] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [egress, setEgress] = useState(null)
|
||||
const [trace, setTrace] = useState(null)
|
||||
const [decision, setDecision] = useState(null)
|
||||
const [debugOn, setDebugOn] = useState(false)
|
||||
|
||||
const loadList = () =>
|
||||
api('/api/dialogue/conversations', { token: session.token })
|
||||
@@ -45,7 +43,12 @@ export default function DialoguePage() {
|
||||
api('/api/journal/egress-status', { token: session.token })
|
||||
.then(setEgress)
|
||||
.catch(() => setEgress(null))
|
||||
}, [session.token])
|
||||
if (isAdmin) {
|
||||
api('/api/admin/debug', { token: session.token })
|
||||
.then((data) => setDebugOn(Boolean(data.persist_enabled)))
|
||||
.catch(() => setDebugOn(false))
|
||||
}
|
||||
}, [session.token, isAdmin])
|
||||
|
||||
const start = async () => {
|
||||
setError('')
|
||||
@@ -69,8 +72,6 @@ export default function DialoguePage() {
|
||||
setError('')
|
||||
try {
|
||||
await api(`/api/dialogue/conversations/${activeId}`, { token: session.token, method: 'DELETE' })
|
||||
setDecision(null)
|
||||
setTrace(null)
|
||||
const items = await loadList()
|
||||
const next = items?.find((item) => item.id !== activeId) || items?.[0]
|
||||
if (next) await openConversation(next.id)
|
||||
@@ -83,6 +84,18 @@ export default function DialoguePage() {
|
||||
}
|
||||
}
|
||||
|
||||
const downloadDebug = async () => {
|
||||
if (!activeId) return
|
||||
setError('')
|
||||
try {
|
||||
await apiDownload(`/api/admin/debug/export?format=json&conversation_id=${encodeURIComponent(activeId)}`, {
|
||||
token: session.token
|
||||
})
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
}
|
||||
}
|
||||
|
||||
const send = async (e) => {
|
||||
e.preventDefault()
|
||||
if (!activeId || !draft.trim()) return
|
||||
@@ -96,13 +109,9 @@ export default function DialoguePage() {
|
||||
})
|
||||
setDraft('')
|
||||
setMessages(result.messages || [])
|
||||
setDecision(result.decision || null)
|
||||
setTrace(result.trace || null)
|
||||
await loadList()
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
setDecision(null)
|
||||
setTrace(null)
|
||||
if (activeId) await openConversation(activeId)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
@@ -140,6 +149,11 @@ export default function DialoguePage() {
|
||||
</div>
|
||||
{activeId && (
|
||||
<div className="row-actions dialogue-tools">
|
||||
{isAdmin && debugOn && (
|
||||
<button type="button" className="ghost" onClick={downloadDebug} disabled={busy}>
|
||||
Debug herunterladen
|
||||
</button>
|
||||
)}
|
||||
<button type="button" className="ghost" onClick={removeConversation} disabled={busy}>
|
||||
Löschen
|
||||
</button>
|
||||
@@ -163,7 +177,6 @@ export default function DialoguePage() {
|
||||
<button type="submit" disabled={busy}>{busy ? 'Antwortet …' : 'Senden'}</button>
|
||||
</form>
|
||||
)}
|
||||
{isAdmin && <CallTrace decision={decision} trace={trace} />}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Link, useNavigate, useParams } from 'react-router-dom'
|
||||
import { api } from '../api.js'
|
||||
import CallTrace from '../components/CallTrace.jsx'
|
||||
import { api, apiDownload } from '../api.js'
|
||||
import DayScratch from '../components/DayScratch.jsx'
|
||||
import RunLogPopup from '../components/RunLogPopup.jsx'
|
||||
import { useAuth } from '../context/AuthContext.jsx'
|
||||
@@ -48,6 +47,7 @@ export default function JournalDayPage() {
|
||||
const [logOpen, setLogOpen] = useState(false)
|
||||
const [logStatus, setLogStatus] = useState('ok')
|
||||
const [runLog, setRunLog] = useState([])
|
||||
const [debugOn, setDebugOn] = useState(false)
|
||||
|
||||
const loadDay = async (preferId) => {
|
||||
const data = await api(`/api/journal/days/${dayId}`, { token: session.token })
|
||||
@@ -75,17 +75,26 @@ export default function JournalDayPage() {
|
||||
.catch(() => setEgress(null))
|
||||
api('/api/journal/generation-settings', { token: session.token })
|
||||
.then((data) => {
|
||||
setGenerationSelection({
|
||||
transformation_id: data.selection?.transformation_id || '',
|
||||
detail_id: data.selection?.detail_id || '',
|
||||
voice_id: data.selection?.voice_id || '',
|
||||
narrative_id: data.selection?.narrative_id || ''
|
||||
})
|
||||
setGenerationOptions(data.options || {})
|
||||
setGenerationSelection((current) => {
|
||||
const filled = SLOT_SELECTS.every((item) => current[item.key])
|
||||
if (filled) return current
|
||||
return {
|
||||
transformation_id: data.selection?.transformation_id || '',
|
||||
detail_id: data.selection?.detail_id || '',
|
||||
voice_id: data.selection?.voice_id || '',
|
||||
narrative_id: data.selection?.narrative_id || ''
|
||||
}
|
||||
})
|
||||
setRememberSelection(false)
|
||||
})
|
||||
.catch(() => {})
|
||||
}, [session.token, dayId])
|
||||
if (isAdmin) {
|
||||
api('/api/admin/debug', { token: session.token })
|
||||
.then((data) => setDebugOn(Boolean(data.persist_enabled)))
|
||||
.catch(() => setDebugOn(false))
|
||||
}
|
||||
}, [session.token, dayId, isAdmin])
|
||||
|
||||
const startConversation = async () => {
|
||||
setError('')
|
||||
@@ -129,13 +138,9 @@ export default function JournalDayPage() {
|
||||
})
|
||||
setDraft('')
|
||||
setMessages(result.messages || [])
|
||||
setDecision(result.decision || null)
|
||||
setTrace(result.trace || null)
|
||||
await loadDay(activeId)
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
setDecision(null)
|
||||
setTrace(null)
|
||||
await loadDay(activeId)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
@@ -237,6 +242,21 @@ export default function JournalDayPage() {
|
||||
Löschen
|
||||
</button>
|
||||
)}
|
||||
{isAdmin && debugOn && activeId && (
|
||||
<button
|
||||
type="button"
|
||||
className="ghost"
|
||||
onClick={() =>
|
||||
apiDownload(
|
||||
`/api/admin/debug/export?format=json&conversation_id=${encodeURIComponent(activeId)}`,
|
||||
{ token: session.token }
|
||||
).catch((err) => setError(err.message))
|
||||
}
|
||||
disabled={busy}
|
||||
>
|
||||
Debug herunterladen
|
||||
</button>
|
||||
)}
|
||||
<button type="button" onClick={requestGenerate} disabled={busy || !conversations.length}>
|
||||
Tagebuch
|
||||
</button>
|
||||
@@ -299,24 +319,32 @@ export default function JournalDayPage() {
|
||||
{SLOT_SELECTS.map((item) => {
|
||||
const options = generationOptions[item.slot] || []
|
||||
const selected = options.find((option) => option.id === generationSelection[item.key])
|
||||
const selectedId = generationSelection[item.key]
|
||||
const stale = Boolean(selectedId && !selected)
|
||||
return (
|
||||
<label key={item.key} className="policy-select">
|
||||
<span>{item.title}</span>
|
||||
<select
|
||||
value={generationSelection[item.key]}
|
||||
value={selectedId}
|
||||
title={selected?.summary || ''}
|
||||
onChange={(event) => setGenerationSelection((current) => ({
|
||||
...current,
|
||||
[item.key]: event.target.value
|
||||
}))}
|
||||
>
|
||||
{stale && (
|
||||
<option value={selectedId}>
|
||||
Auswahl nicht mehr aktiv — bitte neu wählen
|
||||
</option>
|
||||
)}
|
||||
{options.map((option) => (
|
||||
<option key={option.id} value={option.id} title={option.summary || ''}>
|
||||
{option.label}
|
||||
{option.label}{option.revision != null ? ` · Rev. ${option.revision}` : ''}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{selected?.summary ? <small className="muted policy-summary">{selected.summary}</small> : null}
|
||||
{stale ? <small className="error">Diese Ausprägung ist nicht mehr wählbar.</small> : null}
|
||||
</label>
|
||||
)
|
||||
})}
|
||||
@@ -353,7 +381,6 @@ export default function JournalDayPage() {
|
||||
<button type="submit" disabled={busy}>{busy ? 'Antwortet …' : 'Senden'}</button>
|
||||
</form>
|
||||
)}
|
||||
{isAdmin && <CallTrace decision={decision} trace={trace} />}
|
||||
</div>
|
||||
<DayScratch
|
||||
key={dayId}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { Link, useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom'
|
||||
import { api, apiBlob, apiUpload } from '../api.js'
|
||||
import { api, apiBlob, apiDownload, apiUpload } from '../api.js'
|
||||
import CallTrace from '../components/CallTrace.jsx'
|
||||
import JournalDocumentEditor from '../components/JournalDocumentEditor.jsx'
|
||||
import RunLogPopup from '../components/RunLogPopup.jsx'
|
||||
@@ -8,6 +8,28 @@ import { useAuth } from '../context/AuthContext.jsx'
|
||||
import { useUnsavedChanges } from '../context/UnsavedChanges.jsx'
|
||||
import { entryTitle, formatWhen, originLabel } from '../journal/document.js'
|
||||
|
||||
function navTrace(state) {
|
||||
return state?.trace || null
|
||||
}
|
||||
|
||||
function navLog(state) {
|
||||
if (Array.isArray(state?.run_log) && state.run_log.length) return state.run_log
|
||||
const log = state?.trace?.log
|
||||
return Array.isArray(log) ? log : []
|
||||
}
|
||||
|
||||
function downloadLocalJson(payload, filename) {
|
||||
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json;charset=utf-8' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = filename
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
export default function JournalEditorPage() {
|
||||
const { spaceId, dayId } = useParams()
|
||||
const [params] = useSearchParams()
|
||||
@@ -34,10 +56,11 @@ export default function JournalEditorPage() {
|
||||
const [currentVersionId, setCurrentVersionId] = useState('')
|
||||
const { dirty, setDirty } = useUnsavedChanges()
|
||||
const savedRef = useRef({ title: '', body: '' })
|
||||
const [logOpen, setLogOpen] = useState(
|
||||
Boolean((location.state?.run_log || []).length || location.state?.trace)
|
||||
)
|
||||
const [logOpen, setLogOpen] = useState(false)
|
||||
const [generationSummary, setGenerationSummary] = useState('')
|
||||
const [trace, setTrace] = useState(() => navTrace(location.state))
|
||||
const [runLog, setRunLog] = useState(() => navLog(location.state))
|
||||
const [debugOn, setDebugOn] = useState(false)
|
||||
|
||||
const markClean = (nextTitle, nextBody) => {
|
||||
const titleValue = entryTitle(nextTitle || '')
|
||||
@@ -109,6 +132,41 @@ export default function JournalEditorPage() {
|
||||
hydrate().catch((err) => setError(err.message))
|
||||
}, [session.token, dayId, entryQuery, wantDraft])
|
||||
|
||||
useEffect(() => {
|
||||
const nextTrace = navTrace(location.state)
|
||||
const nextLog = navLog(location.state)
|
||||
if (nextTrace) setTrace(nextTrace)
|
||||
if (nextLog.length) setRunLog(nextLog)
|
||||
}, [location.state])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAdmin) return undefined
|
||||
let cancelled = false
|
||||
api('/api/admin/debug', { token: session.token })
|
||||
.then((data) => {
|
||||
if (!cancelled) setDebugOn(Boolean(data.persist_enabled))
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setDebugOn(false)
|
||||
})
|
||||
api(
|
||||
`/api/admin/debug/latest?journal_day_id=${encodeURIComponent(dayId)}&purpose=journal_generate`,
|
||||
{ token: session.token }
|
||||
)
|
||||
.then((payload) => {
|
||||
const run = payload?.run
|
||||
if (cancelled || !run) return
|
||||
const stored = run.trace || run.payload?.trace || null
|
||||
const log = run.run_log || run.payload?.run_log || stored?.log || []
|
||||
setTrace((current) => current || stored)
|
||||
setRunLog((current) => (current.length ? current : (Array.isArray(log) ? log : [])))
|
||||
})
|
||||
.catch(() => {})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [session.token, dayId, isAdmin])
|
||||
|
||||
useEffect(() => () => setDirty(false), [setDirty])
|
||||
|
||||
useEffect(() => {
|
||||
@@ -128,6 +186,34 @@ export default function JournalEditorPage() {
|
||||
}
|
||||
}, [media, session.token])
|
||||
|
||||
const downloadDebug = async () => {
|
||||
setError('')
|
||||
try {
|
||||
if (debugOn) {
|
||||
await apiDownload(
|
||||
`/api/admin/debug/export?format=json&journal_day_id=${encodeURIComponent(dayId)}&purpose=journal_generate`,
|
||||
{ token: session.token }
|
||||
)
|
||||
return
|
||||
}
|
||||
if (!trace && !runLog.length) return
|
||||
downloadLocalJson(
|
||||
{
|
||||
kind: 'kansho.debug_export',
|
||||
version: 2,
|
||||
scope: 'journal_generate',
|
||||
journal_day_id: dayId,
|
||||
note: 'Lokale Kopie der Journal-Testspur dieses Entwurfs. Mapping-Tabelle ist ausgeschlossen.',
|
||||
run_count: 1,
|
||||
runs: [{ purpose: 'journal_generate', trace, run_log: runLog }]
|
||||
},
|
||||
'kansho-debug-journal.json'
|
||||
)
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
}
|
||||
}
|
||||
|
||||
const persist = async (nextTitle, nextBody, nextEntryId = entryIdRef.current, origin) => {
|
||||
const saved = await api('/api/journal/entries', {
|
||||
token: session.token,
|
||||
@@ -267,12 +353,15 @@ export default function JournalEditorPage() {
|
||||
<p className="muted">
|
||||
<Link to={`/journal/${spaceId}/${dayId}`}>Zurück zum Tag</Link>
|
||||
{day?.day?.calendar_date ? ` · ${day.day.calendar_date}` : ''}
|
||||
{(location.state?.run_log || location.state?.trace) && (
|
||||
{isAdmin && (trace || runLog.length > 0) && (
|
||||
<>
|
||||
{' · '}
|
||||
<button type="button" className="ghost" onClick={() => setLogOpen(true)}>
|
||||
Ablauf anzeigen
|
||||
</button>
|
||||
<button type="button" className="ghost" onClick={downloadDebug} disabled={busy}>
|
||||
Debug herunterladen
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
@@ -352,7 +441,12 @@ export default function JournalEditorPage() {
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
{isAdmin && location.state?.trace && !logOpen && <CallTrace trace={location.state.trace} />}
|
||||
{isAdmin && trace && !logOpen && (
|
||||
<div className="journal-debug">
|
||||
<h2>Verlauf</h2>
|
||||
<CallTrace trace={trace} />
|
||||
</div>
|
||||
)}
|
||||
{versions.length > 0 && (
|
||||
<div className="stack">
|
||||
<h2>Versionen</h2>
|
||||
@@ -390,8 +484,8 @@ export default function JournalEditorPage() {
|
||||
open={logOpen}
|
||||
status="ok"
|
||||
title="Journalentwurf"
|
||||
log={location.state?.run_log || location.state?.trace?.log || []}
|
||||
trace={location.state?.trace}
|
||||
log={runLog.length ? runLog : (trace?.log || [])}
|
||||
trace={trace}
|
||||
showTrace={isAdmin}
|
||||
onClose={() => setLogOpen(false)}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user