MVP 1.0
This commit is contained in:
1 parent
be11f82f84
commit
e42f751fdc
47 files changed
+3359
-301
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { formatApiError } from './api.js'
|
||||
|
||||
test('structured provider failure keeps reason and cost note', () => {
|
||||
const message = formatApiError({
|
||||
detail: {
|
||||
code: 'provider_rejected',
|
||||
message: 'generate-Provider hat die Anfrage abgelehnt (HTTP 402): Insufficient credits',
|
||||
http_status: 402,
|
||||
cost_report: { note: 'Beim Anbieter sind Kosten entstanden: Detect 0,0015 USD.' }
|
||||
}
|
||||
}, 502)
|
||||
assert.match(message, /Insufficient credits/)
|
||||
assert.match(message, /provider_rejected/)
|
||||
assert.match(message, /Kosten entstanden/)
|
||||
})
|
||||
|
||||
test('validation arrays are not the generic fallback', () => {
|
||||
const message = formatApiError({
|
||||
detail: [{ type: 'missing', loc: ['body', 'title'], msg: 'Field required' }]
|
||||
}, 422)
|
||||
assert.match(message, /Field required/)
|
||||
assert.doesNotMatch(message, /^Anfrage fehlgeschlagen$/)
|
||||
})
|
||||
|
||||
test('empty non-json gateway timeout explains the gap', () => {
|
||||
const message = formatApiError(null, 504)
|
||||
assert.match(message, /HTTP 504/)
|
||||
assert.match(message, /Anbieter/)
|
||||
})
|
||||
+82
-16
@@ -1,19 +1,89 @@
|
||||
function validationMessage(detail) {
|
||||
if (!Array.isArray(detail) || !detail.length) return ''
|
||||
const first = detail[0] || {}
|
||||
const loc = Array.isArray(first.loc)
|
||||
? first.loc.filter((part) => part !== 'body' && part !== 'query').join('.')
|
||||
: ''
|
||||
const msg = first.msg || first.message || ''
|
||||
if (loc && msg) return `${msg} (${loc})`
|
||||
return msg || ''
|
||||
}
|
||||
|
||||
function costNote(detail) {
|
||||
if (!detail || typeof detail !== 'object' || Array.isArray(detail)) return ''
|
||||
return detail.cost_report?.note || detail.diagnostics?.cost_report?.note || ''
|
||||
}
|
||||
|
||||
export function formatApiError(data, status, fallback = 'Anfrage fehlgeschlagen') {
|
||||
const detail = data?.detail
|
||||
let message = fallback
|
||||
if (typeof detail === 'string' && detail.trim()) {
|
||||
message = detail.trim()
|
||||
} else if (Array.isArray(detail)) {
|
||||
message = validationMessage(detail) || fallback
|
||||
} else if (detail && typeof detail === 'object') {
|
||||
const parts = []
|
||||
if (detail.message) parts.push(detail.message)
|
||||
if (
|
||||
detail.provider_message
|
||||
&& !parts.some((part) => String(part).includes(detail.provider_message))
|
||||
) {
|
||||
parts.push(detail.provider_message)
|
||||
}
|
||||
const extras = []
|
||||
if (detail.code) extras.push(detail.code)
|
||||
const httpStatus = detail.http_status || detail.diagnostics?.http_status
|
||||
if (httpStatus && !parts.some((part) => String(part).includes(`HTTP ${httpStatus}`))) {
|
||||
extras.push(`HTTP ${httpStatus}`)
|
||||
}
|
||||
message = parts.join(' ') || fallback
|
||||
if (extras.length) message = `${message} (${extras.join(', ')})`
|
||||
} else if (!data) {
|
||||
if (status === 502 || status === 504) {
|
||||
message = `Keine auswertbare Antwort vom Server (HTTP ${status}). Die Anfrage kann beim Anbieter trotzdem angekommen sein.`
|
||||
} else if (status) {
|
||||
message = `${fallback} (HTTP ${status}).`
|
||||
}
|
||||
}
|
||||
const note = costNote(detail)
|
||||
if (note && !message.includes(note)) message = `${message}\n${note}`
|
||||
return message
|
||||
}
|
||||
|
||||
function attachError(error, data, status) {
|
||||
error.status = status
|
||||
error.payload = data
|
||||
error.code = data?.detail?.code
|
||||
error.costReport = data?.detail?.cost_report || data?.detail?.diagnostics?.cost_report || null
|
||||
error.diagnostics = data?.detail?.diagnostics || null
|
||||
return error
|
||||
}
|
||||
|
||||
export async function api(path, { token, method = 'GET', body } = {}) {
|
||||
const headers = {}
|
||||
if (token) headers['X-Auth-Token'] = token
|
||||
if (body !== undefined) headers['Content-Type'] = 'application/json'
|
||||
const response = await fetch(path, {
|
||||
method,
|
||||
headers,
|
||||
body: body !== undefined ? JSON.stringify(body) : undefined
|
||||
})
|
||||
let response
|
||||
try {
|
||||
response = await fetch(path, {
|
||||
method,
|
||||
headers,
|
||||
body: body !== undefined ? JSON.stringify(body) : undefined
|
||||
})
|
||||
} catch (err) {
|
||||
const error = new Error(
|
||||
'Keine Verbindung zum Server. Ob beim Anbieter Kosten entstanden sind, ist unbekannt.'
|
||||
)
|
||||
error.cause = err
|
||||
throw error
|
||||
}
|
||||
const data = await response.json().catch(() => null)
|
||||
if (!response.ok) {
|
||||
const detail = data?.detail
|
||||
const message = typeof detail === 'string' ? detail : (detail?.message || 'Anfrage fehlgeschlagen')
|
||||
const error = new Error(message)
|
||||
error.status = response.status
|
||||
error.payload = data
|
||||
const error = attachError(
|
||||
new Error(formatApiError(data, response.status)),
|
||||
data,
|
||||
response.status
|
||||
)
|
||||
throw error
|
||||
}
|
||||
return data
|
||||
@@ -33,9 +103,7 @@ export async function apiDownload(path, { token, filename } = {}) {
|
||||
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)
|
||||
throw attachError(new Error(formatApiError(data, response.status, 'Download fehlgeschlagen')), data, response.status)
|
||||
}
|
||||
const blob = await response.blob()
|
||||
const url = URL.createObjectURL(blob)
|
||||
@@ -56,9 +124,7 @@ export async function apiUpload(path, { token, file, field = 'file' } = {}) {
|
||||
const response = await fetch(path, { method: 'POST', headers, body })
|
||||
const data = await response.json().catch(() => null)
|
||||
if (!response.ok) {
|
||||
const detail = data?.detail
|
||||
const message = typeof detail === 'string' ? detail : (detail?.message || 'Upload fehlgeschlagen')
|
||||
throw new Error(message)
|
||||
throw attachError(new Error(formatApiError(data, response.status, 'Upload fehlgeschlagen')), data, response.status)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
+12
-1
@@ -36,7 +36,7 @@ h2 { font-size: 1.05rem; margin: 1.1rem 0 0.45rem; }
|
||||
p { line-height: 1.5; }
|
||||
.muted, .lede { color: var(--muted); }
|
||||
.lede { font-size: 0.9rem; }
|
||||
.error { color: var(--danger); }
|
||||
.error { color: var(--danger); white-space: pre-line; }
|
||||
.centered { min-height: 100dvh; display: grid; place-items: center; }
|
||||
|
||||
.card {
|
||||
@@ -329,6 +329,17 @@ ul.stack { padding: 0; }
|
||||
width: 100%;
|
||||
min-height: 10rem;
|
||||
}
|
||||
.generation-style-context {
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
margin: 0;
|
||||
padding: 0.7rem 0.85rem;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
}
|
||||
.generation-style-context legend {
|
||||
padding: 0 0.3rem;
|
||||
}
|
||||
.generation-admin-preview {
|
||||
margin-top: 1.4rem;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,34 @@ function styleLabel(meta) {
|
||||
return `${meta.count} · ${meta.chars || 0} Zeichen${kinds ? ` · ${kinds}` : ''}${meta.dropped ? ' · budgetentfernt' : ''}`
|
||||
}
|
||||
|
||||
function styleApplicationLabel(meta) {
|
||||
if (!meta) return 'nicht verfügbar'
|
||||
const requested = meta.requested || {}
|
||||
const effective = meta.effective || {}
|
||||
const name = [meta.label, meta.key ? `(${meta.key})` : '', meta.revision != null ? `Rev. ${meta.revision}` : '']
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
const id = meta.id ? ` · ${meta.id}` : ''
|
||||
const req = [
|
||||
requested.include_core ? 'Core' : null,
|
||||
requested.include_facet ? 'Facet' : null,
|
||||
requested.include_traits ? 'Traits' : null,
|
||||
requested.include_style_examples ? 'Beispiele' : null
|
||||
].filter(Boolean)
|
||||
const eff = `Core ${effective.include_core ? 'ja' : 'nein'}, Facet ${effective.include_facet ? 'ja' : 'nein'}, ${effective.trait_count ?? 0} Traits, ${effective.style_example_count ?? 0} Beispiele`
|
||||
const omitted = Array.isArray(meta.omitted) && meta.omitted.length
|
||||
? ` · ausgelassen: ${meta.omitted.map((item) => `${item.part} (${item.reason})`).join(', ')}`
|
||||
: ''
|
||||
const blocks = Array.isArray(effective.blocks)
|
||||
? effective.blocks
|
||||
.filter((item) => item.included)
|
||||
.map((item) => `${item.key} ${item.chars || 0} Z. / ${item.estimated_tokens || 0} Tok.`)
|
||||
.join('; ')
|
||||
: ''
|
||||
const predecessor = meta.cloned_from ? ` · Vorgänger ${meta.cloned_from}` : ''
|
||||
return `${name || 'vorhanden'}${id}${predecessor} · angefordert: ${req.length ? req.join(', ') : 'keine'} · wirksam: ${eff}${blocks ? ` · ${blocks}` : ''}${omitted}`
|
||||
}
|
||||
|
||||
function droppedLabel(dropped) {
|
||||
if (!dropped || (Array.isArray(dropped) && dropped.length === 0)) return 'keine'
|
||||
return Array.isArray(dropped) ? dropped.join(', ') : String(dropped)
|
||||
@@ -165,6 +193,8 @@ function BudgetMeta({ budget, trace, journal = false }) {
|
||||
</dd>
|
||||
<dt>Writing Profile</dt>
|
||||
<dd>{profileLabel(trace?.writing_profile)}</dd>
|
||||
<dt>Stilanwendung</dt>
|
||||
<dd>{styleApplicationLabel(trace?.style_application)}</dd>
|
||||
<dt>Stilquellen</dt>
|
||||
<dd>{styleLabel(trace?.style_examples)}</dd>
|
||||
<dt>Optionale Blöcke entfernt</dt>
|
||||
|
||||
@@ -16,6 +16,37 @@ const STATUS_LABEL = {
|
||||
archived: 'Archiviert'
|
||||
}
|
||||
|
||||
const STYLE_CONTEXT_FIELDS = [
|
||||
{ key: 'include_core', label: 'Writing-Profile-Core' },
|
||||
{ key: 'include_facet', label: 'Relevantes Facet' },
|
||||
{ key: 'include_traits', label: 'Traits' },
|
||||
{ key: 'include_style_examples', label: 'Stilbeispiele' }
|
||||
]
|
||||
|
||||
function emptyStyleContext() {
|
||||
return {
|
||||
include_core: false,
|
||||
include_facet: false,
|
||||
include_traits: false,
|
||||
include_style_examples: false
|
||||
}
|
||||
}
|
||||
|
||||
function styleContextOf(item) {
|
||||
return {
|
||||
...emptyStyleContext(),
|
||||
...(item?.style_context || {})
|
||||
}
|
||||
}
|
||||
|
||||
function styleContextSummary(context) {
|
||||
const data = styleContextOf({ style_context: context })
|
||||
const parts = STYLE_CONTEXT_FIELDS
|
||||
.filter((item) => data[item.key])
|
||||
.map((item) => item.label)
|
||||
return parts.length ? parts.join(', ') : 'keine'
|
||||
}
|
||||
|
||||
function statusLine(item) {
|
||||
const parts = [STATUS_LABEL[item.status] || item.status]
|
||||
if (item.is_default) parts.push('Standard')
|
||||
@@ -108,7 +139,8 @@ export default function AdminGenerationPage() {
|
||||
label: detail.label,
|
||||
summary: detail.summary,
|
||||
instruction: detail.instruction,
|
||||
sort_order: Number(detail.sort_order || 0)
|
||||
sort_order: Number(detail.sort_order || 0),
|
||||
...(tab === 'voice' ? { style_context: styleContextOf(detail) } : {})
|
||||
}
|
||||
}),
|
||||
'Entwurf angelegt.'
|
||||
@@ -126,7 +158,8 @@ export default function AdminGenerationPage() {
|
||||
label: detail.label,
|
||||
summary: detail.summary,
|
||||
instruction: detail.instruction,
|
||||
sort_order: Number(detail.sort_order || 0)
|
||||
sort_order: Number(detail.sort_order || 0),
|
||||
...(detail.slot === 'voice' || tab === 'voice' ? { style_context: styleContextOf(detail) } : {})
|
||||
}
|
||||
}),
|
||||
'Entwurf gespeichert.'
|
||||
@@ -227,7 +260,9 @@ export default function AdminGenerationPage() {
|
||||
instruction: '',
|
||||
sort_order: (catalog?.slots?.[tab] || []).length,
|
||||
status: 'draft',
|
||||
revision: 1
|
||||
revision: 1,
|
||||
slot: tab,
|
||||
style_context: emptyStyleContext()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -286,6 +321,9 @@ export default function AdminGenerationPage() {
|
||||
<span className="muted">{statusLine(item)}</span>
|
||||
</header>
|
||||
<p>{item.summary || 'Keine Kurzbeschreibung.'}</p>
|
||||
{item.slot === 'voice' || tab === 'voice' ? (
|
||||
<p className="muted">Stilquellen: {styleContextSummary(item.style_context)}</p>
|
||||
) : null}
|
||||
<div className="row-actions">
|
||||
<button type="button" className="ghost" onClick={() => openItem(item.id)}>Öffnen</button>
|
||||
<button type="button" className="ghost" onClick={() => cloneItem(item.id)}>Klonen</button>
|
||||
@@ -338,12 +376,38 @@ export default function AdminGenerationPage() {
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
{(detail.slot === 'voice' || tab === 'voice') && (
|
||||
<fieldset className="generation-style-context" disabled={!editable}>
|
||||
<legend>Stilquellen für diese Ausprägung</legend>
|
||||
<p className="muted">
|
||||
Nur freigegebene Bestandteile gelangen in den Prompt. Keine Gewichtungen.
|
||||
Promptanweisung und Stilkontext werden gemeinsam versioniert.
|
||||
</p>
|
||||
{STYLE_CONTEXT_FIELDS.map((field) => (
|
||||
<label key={field.key} className="check">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={Boolean(styleContextOf(detail)[field.key])}
|
||||
onChange={(event) => setDetail((current) => ({
|
||||
...current,
|
||||
style_context: {
|
||||
...styleContextOf(current),
|
||||
[field.key]: event.target.checked
|
||||
}
|
||||
}))}
|
||||
disabled={!editable}
|
||||
/>
|
||||
{field.label}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
)}
|
||||
<details>
|
||||
<summary>Technische Herkunft</summary>
|
||||
<p className="muted">
|
||||
ID: {detail.id || 'neu'}
|
||||
{detail.revision != null ? ` · Revision ${detail.revision}` : ''}
|
||||
{detail.cloned_from ? ` · geklont von ${detail.cloned_from}` : ''}
|
||||
{detail.cloned_from ? ` · Vorgänger ${detail.cloned_from}` : ''}
|
||||
{detail.seed_revision ? ` · Systemstand ${detail.seed_revision}` : ''}
|
||||
</p>
|
||||
</details>
|
||||
|
||||
@@ -18,6 +18,16 @@ const SLOT_SELECTS = [
|
||||
{ slot: 'narrative', key: 'narrative_id', title: 'Erzählgestaltung' }
|
||||
]
|
||||
|
||||
function styleSourcesLine(option) {
|
||||
const context = option?.style_context || {}
|
||||
const parts = []
|
||||
if (context.include_core) parts.push('Core')
|
||||
if (context.include_facet) parts.push('Facet')
|
||||
if (context.include_traits) parts.push('Traits')
|
||||
if (context.include_style_examples) parts.push('Stilbeispiele')
|
||||
return parts.length ? `Stilquellen: ${parts.join(', ')}` : 'Stilquellen: keine'
|
||||
}
|
||||
|
||||
const EMPTY_SELECTION = {
|
||||
transformation_id: '',
|
||||
detail_id: '',
|
||||
@@ -344,6 +354,9 @@ export default function JournalDayPage() {
|
||||
))}
|
||||
</select>
|
||||
{selected?.summary ? <small className="muted policy-summary">{selected.summary}</small> : null}
|
||||
{item.slot === 'voice' && selected ? (
|
||||
<small className="muted policy-summary">{styleSourcesLine(selected)}</small>
|
||||
) : null}
|
||||
{stale ? <small className="error">Diese Ausprägung ist nicht mehr wählbar.</small> : null}
|
||||
</label>
|
||||
)
|
||||
|
||||
@@ -582,6 +582,9 @@ export default function SettingsPage() {
|
||||
API-Analyse
|
||||
</button>
|
||||
</div>
|
||||
{reviewBusy && (
|
||||
<p className="muted">Analyse läuft … Detect und Generate können länger als eine Minute dauern.</p>
|
||||
)}
|
||||
{reviewPrompt && (
|
||||
<>
|
||||
<p className="muted">Diesen Prompt in einen bestehenden Chat mit deinen Texten einfügen. Das JSON-Ergebnis danach oben einfügen.</p>
|
||||
|
||||
@@ -24,8 +24,8 @@ export default defineConfig({
|
||||
globPatterns: ['**/*.{js,css,html,svg}'],
|
||||
runtimeCaching: [{
|
||||
urlPattern: /^\/api\//,
|
||||
handler: 'NetworkFirst',
|
||||
options: { cacheName: 'api-cache', expiration: { maxEntries: 50 } }
|
||||
handler: 'NetworkOnly',
|
||||
options: { cacheName: 'api-cache' }
|
||||
}]
|
||||
}
|
||||
})
|
||||
@@ -33,6 +33,12 @@ export default defineConfig({
|
||||
server: {
|
||||
port: 5188,
|
||||
strictPort: true,
|
||||
proxy: { '/api': 'http://127.0.0.1:8018' }
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://127.0.0.1:8018',
|
||||
timeout: 600000,
|
||||
proxyTimeout: 600000
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user