* feat(agent): 'Vad din agent vet' page rendering the ledger context (P2) The human-facing surface for the openwiki ledger-context: a read-only page that renders the exact payload the AI agent reads (Accounted://ledger/context + the briefing digest) as a legible profile of how this company books. - Route app/(dashboard)/agent-knowledge (server component) calls the shared buildLedgerContext(supabase, companyId) directly: one payload, two renderers, no new API or data path. - Sections mirror the payload 1:1: coverage/freshness strip, counterparty patterns (monochrome confidence bars + seen/agree evidence), supplier patterns, explicit rules shown as authoritative instructions distinct from observed patterns, account usage, VAT profile, conventions. - Nav entry in the Analys group (icon Brain), ungated so it doubles as an upsell; flip requiredCapability to paywall. - Design per .claude/rules/design.md (PageHeader, Card, Table, Badge, AccountNumber BAS tooltips); sv + en strings (agentKnowledge namespace). VAT/BAS labels stay Swedish in both locales per i18n rules. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(agent): deep entity-resolved analysis + radial graph for the knowledge page Reworks the 'Vad din agent vet' page from tables into a radial-hub graph driven by a new full-history deep analysis, per founder feedback. - fix(rpc): median_booking_lag_days now measures real posting promptness via committed_at, not entry_date (which the bank flow sets to the transaction date, giving a ~0 tautology: 151/152 on prod). migration 20260708120000. - feat(rpc): get_ledger_deep_context (migration 20260708130000): full-history, deterministic, read-side. Merges counterparties by normalize_counterparty_key (e.g. Claude = 14 bookings across 12 name variants, weekly, 9 710 kr, always 5420), mines booked verifikat for SEK spend (coalesce amount_sek), detects recurrence cadence, dominant account + share, plus supplier entities. Storno excluded, corrections kept; 19xx/26xx excluded from the dominant contra. - LedgerGraph: radial SVG (company center, accounts inner ring, payees outer ring), hover/focus reveals variants + spend + cadence + account. Keyboard focusable nodes with per-node accessible names + a screen-reader data table. - Page fetches the deep context alongside the light context; coverage strip gains tracked-payee / recurring / tracked-spend stats. sv + en strings. - 14 pg tests (light + deep) green; both RPCs applied to prod + version-matched. Reviewed by an adversarial multi-lens pass (accounting/SQL, frontend/a11y, prod-fact verification); all four verified findings fixed (SEK currency, storno-lag guard, keyboard a11y, spacing tokens). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(agent): gentle mount fade-in for the radial map (reduced-motion safe) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(agent): render the page for a rules-only company (empty-state edge case) isEmpty ignored explicit_rules, so a company with configured mapping rules but no posted transactions hit the 'hasn't learned anything' empty state and lost its rules section. Rules are independent of bookings. (CodeRabbit) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(agent): show Kompetens (skills) + Fakta (memory) on the knowledge page The 'Vad din agent vet' page now shows the full picture of what the agent knows: alongside the booking map, a compact read-only view of its Kompetens (the Swedish accounting/tax knowledge atoms it ships with, grouped by tier as chips with active/dormant state) and the Fakta it remembers (top learned facts with kind + source), each linking to /settings/assistant for full management. Server-rendered via a new buildAgentCompetence() that mirrors GET /api/agent/skills + /api/agent/memory. Also renders in the no-bookings case so a new company still sees its agent's competence. sv + en strings. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * refactor(agent): restructure knowledge page - hero graph + tabbed detail Declutters the page per feedback: the booking map is the always-visible hero, and the supporting detail (Kompetens · Minne · Regler & profil) moves into tabs so only one view shows at a time instead of a long card stack. Split AgentCompetenceSections into standalone CompetenceCard + FactsCard for the tabs; removed the top stat row on request. sv + en. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(agent): Reconciliation Aurora rewrite of the ledger knowledge graph Full rewrite of LedgerGraph: node area = sqrt(spend), colour = cadence, shape = supplier/counterparty, confidence = depth-of-field; on-mount descriptor-collapse animation with xN badge; cadence pulse veins; deterministic seeded layout; framer-motion only (no new deps); keyboard navigation, reduced-motion and sr-only support. Build-verified; 3-lens adversarial review findings fixed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(agent): sample-size-honest confidence in the ledger knowledge graph dominant_account_share was raw cnt/total, so a counterparty with a single booking rendered as '100% säkerhet': fake certainty by construction (the data_quality_master Item-C / P3 finding). New migration replaces get_ledger_deep_context with a Laplace-smoothed share (cnt+1)/(total+2) (1/1 -> 0.67, 3/3 -> 0.80) and exposes the raw evidence as dominant_account_count / dominant_account_total. The detail card now shows 'Bokförd hit i k av n fall' under the confidence bar; the existing focus buckets, stroke widths and percent labels inherit the honest value unchanged. pg-real test updated to guard the n=1 case. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
129 lines
5.4 KiB
TypeScript
129 lines
5.4 KiB
TypeScript
import { getTranslations } from 'next-intl/server'
|
|
import Link from 'next/link'
|
|
import { Pin, ArrowUpRight } from 'lucide-react'
|
|
import { Card, CardHeader, CardTitle, CardDescription, CardContent } from '@/components/ui/card'
|
|
import { Badge } from '@/components/ui/badge'
|
|
import type { AgentCompetence, AtomTier, FactKind, FactSource } from '@/lib/agent-context/agent-competence'
|
|
|
|
/**
|
|
* Read-only views of the agent's competence (domain-knowledge atoms) and top
|
|
* learned facts, for the "Vad din agent vet" overview. Each is a standalone
|
|
* Card so it can sit in its own tab. Full editable management lives in
|
|
* /settings/assistant; each links there.
|
|
*/
|
|
|
|
const TIER_ORDER: AtomTier[] = ['horizontal', 'vertical', 'modifier']
|
|
|
|
export async function CompetenceCard({ competence }: { competence: AgentCompetence }) {
|
|
const t = await getTranslations('agentKnowledge')
|
|
const { atoms } = competence
|
|
const activeAtoms = atoms.filter((a) => a.active).length
|
|
const tierLabel = (tier: AtomTier) =>
|
|
tier === 'horizontal' ? t('tier_horizontal') : tier === 'vertical' ? t('tier_vertical') : t('tier_modifier')
|
|
|
|
return (
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="text-base">{t('comp_title')}</CardTitle>
|
|
<CardDescription>{t('comp_desc')}</CardDescription>
|
|
</CardHeader>
|
|
<CardContent className="space-y-6 pt-0">
|
|
{atoms.length === 0 ? (
|
|
<p className="text-sm text-muted-foreground">{t('comp_empty')}</p>
|
|
) : (
|
|
<>
|
|
{TIER_ORDER.map((tier) => {
|
|
const items = atoms.filter((a) => a.tier === tier)
|
|
if (items.length === 0) return null
|
|
return (
|
|
<div key={tier} className="space-y-2">
|
|
<h3 className="text-xs font-medium uppercase tracking-wider text-muted-foreground">
|
|
{tierLabel(tier)}
|
|
</h3>
|
|
<div className="flex flex-wrap gap-2">
|
|
{items.map((a) => (
|
|
<Badge
|
|
key={a.id}
|
|
variant={a.active ? 'secondary' : 'outline'}
|
|
className={a.active ? '' : 'text-muted-foreground'}
|
|
title={a.description}
|
|
>
|
|
{a.title}
|
|
{!a.active && tier !== 'horizontal' && (
|
|
<span className="ml-1.5 opacity-70">· {t('badge_dormant')}</span>
|
|
)}
|
|
</Badge>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)
|
|
})}
|
|
<div className="flex items-center justify-between pt-1 text-xs text-muted-foreground">
|
|
<span className="tabular-nums">{t('comp_count', { total: atoms.length, active: activeAtoms })}</span>
|
|
<ManageLink href="/settings/assistant?view=skills" label={t('comp_manage')} />
|
|
</div>
|
|
</>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
)
|
|
}
|
|
|
|
export async function FactsCard({ competence }: { competence: AgentCompetence }) {
|
|
const t = await getTranslations('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')
|
|
const sourceLabel = (s: FactSource) =>
|
|
s === 'composer' ? t('source_composer') : s === 'user_taught' ? t('source_user_taught') : s === 'agent_learned' ? t('source_agent_learned') : t('source_derived')
|
|
|
|
return (
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="text-base">{t('facts_title')}</CardTitle>
|
|
<CardDescription>{t('facts_desc')}</CardDescription>
|
|
</CardHeader>
|
|
<CardContent className="space-y-3 pt-0">
|
|
{facts.length === 0 ? (
|
|
<p className="text-sm text-muted-foreground">{t('facts_empty')}</p>
|
|
) : (
|
|
<>
|
|
<ul className="space-y-3">
|
|
{facts.map((f) => (
|
|
<li key={f.id} className="flex items-start gap-2">
|
|
{f.is_pinned ? (
|
|
<Pin className="mt-1 h-3.5 w-3.5 shrink-0 fill-current text-muted-foreground" aria-label={t('facts_pinned')} />
|
|
) : (
|
|
<span className="mt-1 h-3.5 w-3.5 shrink-0" aria-hidden />
|
|
)}
|
|
<div className="min-w-0 space-y-0.5">
|
|
<p className="text-sm text-foreground">{f.content}</p>
|
|
<p className="text-[11px] text-muted-foreground">
|
|
{kindLabel(f.kind)} · {sourceLabel(f.source)}
|
|
</p>
|
|
</div>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
<div className="flex items-center justify-between pt-1 text-xs text-muted-foreground">
|
|
<span className="tabular-nums">
|
|
{factsActiveTotal > facts.length ? t('facts_more', { n: factsActiveTotal - facts.length }) : ''}
|
|
</span>
|
|
<ManageLink href="/settings/assistant" label={t('facts_manage')} />
|
|
</div>
|
|
</>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
)
|
|
}
|
|
|
|
function ManageLink({ href, label }: { href: string; label: string }) {
|
|
return (
|
|
<Link href={href} className="inline-flex items-center gap-1 text-foreground underline underline-offset-2 hover:text-muted-foreground">
|
|
{label}
|
|
<ArrowUpRight className="h-3 w-3" />
|
|
</Link>
|
|
)
|
|
}
|