feat(agent): move 'Vad din agent vet' into settings (Assistenten -> Kunskap) (#1008)
Relocates the ledger-knowledge surface off the top nav and into the assistant settings hub as a third tab (Minne / Kompetens / Kunskap), per the code's own "minne + kunskap under Assistenten" intent and the #935 flag that this was an easy call to change. Because both settings surfaces (the full-page rail and the intercepting settings modal) mount each section as a propless component via SETTINGS_SECTIONS, the knowledge data must be fetched client-side rather than passed as a server prop: - New GET /api/agent/knowledge aggregates buildLedgerContext + buildDeepEntities + buildAgentCompetence + company name (read-only, company-scoped via withRouteContext). - AgentKnowledgeView + AgentCompetenceSections converted from async server components to client components (getTranslations -> useTranslations; no other server-only usage). - New AgentKnowledgePanel client wrapper lazy-fetches the payload when the Kunskap tab opens (Radix unmounts inactive tabs), with Skeleton and error states matching the memory/skills panels. - Removed the Brain/agent-knowledge entry (and its now-unused import) from the Analys nav group. - /agent-knowledge kept as a redirect to /settings/assistant?view=knowledge so old links/bookmarks resolve. Tests: new route test (auth 401, no-company 400, happy-path aggregation). i18n: load_error_* keys added to both locales (parity kept). Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
4b51af3d80
commit
dcd33997b7
@@ -1,4 +1,6 @@
|
||||
import { getTranslations } from 'next-intl/server'
|
||||
'use client'
|
||||
|
||||
import { useTranslations } from 'next-intl'
|
||||
import Link from 'next/link'
|
||||
import { Pin, ArrowUpRight } from 'lucide-react'
|
||||
import { Card, CardHeader, CardTitle, CardDescription, CardContent } from '@/components/ui/card'
|
||||
@@ -14,8 +16,8 @@ import type { AgentCompetence, AtomTier, FactKind, FactSource } from '@/lib/agen
|
||||
|
||||
const TIER_ORDER: AtomTier[] = ['horizontal', 'vertical', 'modifier']
|
||||
|
||||
export async function CompetenceCard({ competence }: { competence: AgentCompetence }) {
|
||||
const t = await getTranslations('agentKnowledge')
|
||||
export function CompetenceCard({ competence }: { competence: AgentCompetence }) {
|
||||
const t = useTranslations('agentKnowledge')
|
||||
const { atoms } = competence
|
||||
const activeAtoms = atoms.filter((a) => a.active).length
|
||||
const tierLabel = (tier: AtomTier) =>
|
||||
@@ -69,8 +71,8 @@ export async function CompetenceCard({ competence }: { competence: AgentCompeten
|
||||
)
|
||||
}
|
||||
|
||||
export async function FactsCard({ competence }: { competence: AgentCompetence }) {
|
||||
const t = await getTranslations('agentKnowledge')
|
||||
export function FactsCard({ competence }: { competence: AgentCompetence }) {
|
||||
const t = useTranslations('agentKnowledge')
|
||||
const { facts, factsActiveTotal } = competence
|
||||
const kindLabel = (k: FactKind) =>
|
||||
k === 'fact' ? t('kind_fact') : k === 'preference' ? t('kind_preference') : k === 'pattern' ? t('kind_pattern') : t('kind_correction')
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { EmptyState } from '@/components/ui/empty-state'
|
||||
import { Brain } from 'lucide-react'
|
||||
import type { LedgerContext } from '@/lib/agent-context/ledger-context'
|
||||
import type { DeepLedgerContext } from '@/lib/agent-context/ledger-deep'
|
||||
import type { AgentCompetence } from '@/lib/agent-context/agent-competence'
|
||||
import { AgentKnowledgeView } from './AgentKnowledgeView'
|
||||
|
||||
interface KnowledgePayload {
|
||||
context: LedgerContext
|
||||
deep: DeepLedgerContext
|
||||
competence: AgentCompetence
|
||||
companyName: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Client wrapper for the "Vad din agent vet" view inside the assistant
|
||||
* settings hub. Fetches the ledger context from /api/agent/knowledge on mount
|
||||
* (lazy: this panel only renders when the Kunskap tab is opened, since Radix
|
||||
* unmounts inactive tabs). Fetching client-side rather than via a server prop
|
||||
* is deliberate: the settings sections mount as propless components in BOTH
|
||||
* the full-page rail and the routed settings modal, so a server fetch wouldn't
|
||||
* reach the modal.
|
||||
*/
|
||||
export function AgentKnowledgePanel() {
|
||||
const t = useTranslations('agentKnowledge')
|
||||
const [payload, setPayload] = useState<KnowledgePayload | null>(null)
|
||||
const [error, setError] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
fetch('/api/agent/knowledge')
|
||||
.then((res) => {
|
||||
if (!res.ok) throw new Error(`knowledge fetch failed: ${res.status}`)
|
||||
return res.json()
|
||||
})
|
||||
.then((json) => {
|
||||
if (!cancelled) setPayload(json.data as KnowledgePayload)
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setError(true)
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [])
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<EmptyState
|
||||
icon={Brain}
|
||||
title={t('load_error_title')}
|
||||
description={t('load_error_description')}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (!payload) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Skeleton className="h-64 w-full rounded-xl" />
|
||||
<Skeleton className="h-9 w-64" />
|
||||
<Skeleton className="h-48 w-full rounded-xl" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<AgentKnowledgeView
|
||||
context={payload.context}
|
||||
deep={payload.deep}
|
||||
competence={payload.competence}
|
||||
companyName={payload.companyName}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { getTranslations } from 'next-intl/server'
|
||||
'use client'
|
||||
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { Brain } from 'lucide-react'
|
||||
import {
|
||||
Card,
|
||||
@@ -49,7 +51,7 @@ function vatLabel(code: string | null): string | null {
|
||||
return VAT_LABELS[code] ?? code
|
||||
}
|
||||
|
||||
export async function AgentKnowledgeView({
|
||||
export function AgentKnowledgeView({
|
||||
context,
|
||||
deep,
|
||||
competence,
|
||||
@@ -60,7 +62,7 @@ export async function AgentKnowledgeView({
|
||||
competence: AgentCompetence
|
||||
companyName: string
|
||||
}) {
|
||||
const t = await getTranslations('agentKnowledge')
|
||||
const t = useTranslations('agentKnowledge')
|
||||
|
||||
const { meta, explicit_rules, vat_profile, conventions } = context
|
||||
|
||||
|
||||
Reference in New Issue
Block a user