Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.3 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.4 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.4 (pull_request) Has been skipped
CI / Browser-Tests (pull_request) Failing after 19m38s
CI / PHP 8.3 / mysql:8.4-1 (pull_request) Successful in 24m17s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 9m13s
CI / Build-Artefakte aktuell (pull_request) Successful in 6m4s
Antworten mit Quellen aus Seiten, QM-Dokumenten, Glossar und Neuigkeiten – nur aus Sichtbarem, über den KI-Assistenten (Anthropic, OpenAI, Ollama). Wissensquellen als Registry für Plugins, Auswertung ohne Personenbezug. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
191 lines
10 KiB
Vue
191 lines
10 KiB
Vue
<script setup>
|
||
import { computed, nextTick, onMounted, ref } from 'vue';
|
||
import { ArrowUpRight, LoaderCircle, MessageCircleQuestion, SearchX, Sparkles } from '@lucide/vue';
|
||
import AppLayout from '@/layouts/AppLayout.vue';
|
||
import PageHeader from '@/components/PageHeader.vue';
|
||
import Panel from '@/components/Panel.vue';
|
||
import { Button } from '@/components/ui/button';
|
||
import { http } from '@/lib/http';
|
||
|
||
const props = defineProps({
|
||
question: { type: String, default: '' },
|
||
sources: { type: Array, default: () => [] },
|
||
provider: { type: String, default: null },
|
||
});
|
||
|
||
const input = ref(props.question);
|
||
const asked = ref('');
|
||
const loading = ref(false);
|
||
const error = ref('');
|
||
const result = ref(null);
|
||
const field = ref(null);
|
||
|
||
const examples = ['Wie beantrage ich Urlaub?', 'Was mache ich bei einem Arbeitsunfall?', 'Wer ist in der Mitarbeitervertretung?'];
|
||
|
||
async function ask(question = input.value) {
|
||
const text = question.trim();
|
||
if (text.length < 3 || loading.value) return;
|
||
|
||
input.value = text;
|
||
asked.value = text;
|
||
loading.value = true;
|
||
error.value = '';
|
||
result.value = null;
|
||
|
||
// Frage in der Adresse, damit man sie teilen und zurückkehren kann
|
||
window.history.replaceState(window.history.state, '', `/frag-das-portal?frage=${encodeURIComponent(text)}`);
|
||
|
||
try {
|
||
result.value = await http.post('/frag-das-portal', { question: text });
|
||
} catch (e) {
|
||
error.value = e.status === 429 ? 'Sie haben gerade viele Fragen gestellt. Bitte einen Moment warten.' : (e.data?.errors?.question?.[0] ?? e.message);
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
}
|
||
|
||
// Antwort als Absätze und Listenpunkte; [2] wird zum Verweis auf die Quelle
|
||
const blocks = computed(() => {
|
||
if (!result.value?.found) return [];
|
||
const known = new Set(result.value.sources.map((s) => s.n));
|
||
const segments = (line) => line.split(/(\[\d+\])/).filter(Boolean).map((part) => {
|
||
const cite = part.match(/^\[(\d+)\]$/);
|
||
return cite && known.has(Number(cite[1])) ? { cite: Number(cite[1]) } : { text: part };
|
||
});
|
||
const out = [];
|
||
for (const raw of result.value.answer.split('\n')) {
|
||
const line = raw.trim();
|
||
if (!line) continue;
|
||
if (/^[-•*]\s+/.test(line)) {
|
||
const last = out[out.length - 1];
|
||
const item = segments(line.replace(/^[-•*]\s+/, ''));
|
||
last?.type === 'list' ? last.items.push(item) : out.push({ type: 'list', items: [item] });
|
||
} else {
|
||
out.push({ type: 'p', segments: segments(line) });
|
||
}
|
||
}
|
||
return out;
|
||
});
|
||
|
||
onMounted(() => {
|
||
if (props.question) ask(props.question);
|
||
else nextTick(() => field.value?.focus());
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<AppLayout title="Frag das Portal" width="medium">
|
||
<PageHeader
|
||
title="Frag das Portal"
|
||
:description="`Stellen Sie eine Frage – die Antwort kommt aus ${sources.length ? sources.join(', ') : 'den Inhalten des Portals'}.`"
|
||
icon="message-circle-question"
|
||
/>
|
||
|
||
<div class="grid min-w-0 grid-cols-1 gap-5">
|
||
<form class="grid min-w-0 gap-3" @submit.prevent="ask()">
|
||
<label for="ask-question" class="sr-only">Ihre Frage</label>
|
||
<div class="flex flex-col gap-2 rounded-xl border bg-card p-2 shadow-xs focus-within:border-brand-400 focus-within:ring-3 focus-within:ring-ring/30 sm:flex-row sm:items-end">
|
||
<textarea
|
||
id="ask-question"
|
||
ref="field"
|
||
v-model="input"
|
||
rows="2"
|
||
maxlength="300"
|
||
placeholder="z. B. Wie beantrage ich eine Fortbildung?"
|
||
class="min-h-14 w-full min-w-0 flex-1 resize-none bg-transparent px-2 py-1.5 text-base outline-none placeholder:text-muted-foreground"
|
||
@keydown.enter.exact.prevent="ask()"
|
||
/>
|
||
<Button type="submit" :disabled="loading || input.trim().length < 3" class="shrink-0">
|
||
<LoaderCircle v-if="loading" class="animate-spin" />
|
||
<Sparkles v-else />
|
||
Fragen
|
||
</Button>
|
||
</div>
|
||
<div v-if="!asked" class="flex flex-wrap gap-2">
|
||
<button
|
||
v-for="example in examples"
|
||
:key="example"
|
||
type="button"
|
||
class="rounded-pill border bg-card px-3.5 py-1.5 text-[13px] text-muted-foreground hover:bg-accent hover:text-foreground"
|
||
@click="ask(example)"
|
||
>{{ example }}</button>
|
||
</div>
|
||
</form>
|
||
|
||
<div aria-live="polite" class="grid min-w-0 grid-cols-1 gap-5">
|
||
<Panel v-if="loading">
|
||
<div class="flex items-center gap-3 text-muted-foreground">
|
||
<LoaderCircle class="size-5 animate-spin text-brand" />
|
||
Ich suche im Portal nach einer Antwort …
|
||
</div>
|
||
</Panel>
|
||
|
||
<p v-else-if="error" class="rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive">{{ error }}</p>
|
||
|
||
<template v-else-if="result">
|
||
<Panel v-if="result.found">
|
||
<p class="mb-3 text-sm font-medium text-muted-foreground">{{ asked }}</p>
|
||
<div class="grid grid-cols-1 gap-3 text-base leading-relaxed">
|
||
<template v-for="(block, i) in blocks" :key="i">
|
||
<p v-if="block.type === 'p'">
|
||
<template v-for="(seg, j) in block.segments" :key="j">
|
||
<a v-if="seg.cite" :href="`#quelle-${seg.cite}`" class="mx-0.5 align-super text-xs font-semibold text-brand-text hover:underline" :aria-label="`Quelle ${seg.cite}`">[{{ seg.cite }}]</a>
|
||
<template v-else>{{ seg.text }}</template>
|
||
</template>
|
||
</p>
|
||
<ul v-else class="grid list-disc gap-1.5 pl-5">
|
||
<li v-for="(item, k) in block.items" :key="k">
|
||
<template v-for="(seg, j) in item" :key="j">
|
||
<a v-if="seg.cite" :href="`#quelle-${seg.cite}`" class="mx-0.5 align-super text-xs font-semibold text-brand-text hover:underline" :aria-label="`Quelle ${seg.cite}`">[{{ seg.cite }}]</a>
|
||
<template v-else>{{ seg.text }}</template>
|
||
</template>
|
||
</li>
|
||
</ul>
|
||
</template>
|
||
</div>
|
||
|
||
<h2 class="mt-6 mb-2 text-sm font-semibold">Quellen</h2>
|
||
<ol class="grid grid-cols-1 gap-2">
|
||
<li v-for="source in result.sources" :id="`quelle-${source.n}`" :key="source.n">
|
||
<a :href="source.url" class="group flex items-start gap-3 rounded-lg border bg-background px-3 py-2.5 hover:border-brand-300 hover:bg-accent">
|
||
<span class="grid size-6 shrink-0 place-items-center rounded-full bg-brand-soft text-xs font-semibold text-brand-text">{{ source.n }}</span>
|
||
<span class="min-w-0 flex-1">
|
||
<span class="block font-medium group-hover:underline">{{ source.title }}</span>
|
||
<span class="block truncate text-xs text-muted-foreground">{{ source.label }}<template v-if="source.meta"> · {{ source.meta }}</template></span>
|
||
</span>
|
||
<ArrowUpRight class="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
||
</a>
|
||
</li>
|
||
</ol>
|
||
<p class="mt-4 text-xs text-muted-foreground">Automatisch zusammengefasst – im Zweifel gilt, was in den Quellen steht.</p>
|
||
</Panel>
|
||
|
||
<Panel v-else>
|
||
<div class="flex items-start gap-3">
|
||
<SearchX class="mt-0.5 size-5 shrink-0 text-muted-foreground" />
|
||
<div class="grid gap-1">
|
||
<p class="font-medium">{{ result.answer }}</p>
|
||
<p class="text-sm text-muted-foreground">Versuchen Sie es mit anderen Worten – oder fragen Sie direkt Ihre Ansprechpersonen.</p>
|
||
</div>
|
||
</div>
|
||
<div v-if="result.suggestions.length" class="mt-4 grid grid-cols-1 gap-2">
|
||
<p class="text-sm font-medium">Vielleicht hilft Ihnen das weiter:</p>
|
||
<a v-for="item in result.suggestions" :key="item.url" :href="item.url" class="flex items-center justify-between gap-3 rounded-lg border bg-background px-3 py-2 text-sm hover:bg-accent">
|
||
<span class="min-w-0 truncate">{{ item.title }} <span class="text-muted-foreground">· {{ item.label }}</span></span>
|
||
<ArrowUpRight class="size-4 shrink-0 text-muted-foreground" />
|
||
</a>
|
||
</div>
|
||
</Panel>
|
||
</template>
|
||
</div>
|
||
|
||
<p class="flex items-start gap-2 text-xs text-muted-foreground">
|
||
<MessageCircleQuestion class="mt-px size-3.5 shrink-0" />
|
||
<span>
|
||
Gesucht wird nur in Inhalten, die Sie sehen dürfen. Fragen werden ohne Ihren Namen gespeichert, damit die Redaktion fehlende Inhalte ergänzen kann.
|
||
<template v-if="provider"> Die Frage und passende Textstellen werden zur Beantwortung an {{ provider }} übermittelt.</template>
|
||
</span>
|
||
</p>
|
||
</div>
|
||
</AppLayout>
|
||
</template>
|