import React, { useEffect, useState } from 'react'; import { __ } from '@wordpress/i18n'; import { api } from '../api'; import { Card, Button, Badge, Notice, Segmented } from './ui'; import { IconDoc } from './icons'; /** * The knowledge base: what every AI call — on every engine — is briefed with. * * Two layers, shown as two tabs. The template is fixed and identical for all * providers: what this plugin is, what GEO means, the house rules, and the * live facts about this site. The owner's layer is free text, appended after * it. "Preview" shows the assembled briefing exactly as the model receives * it, because a summary of what is being said on your behalf is not the same * as reading it. */ export default function KnowledgeBase() { const [data, setData] = useState(null); const [draft, setDraft] = useState(null); const [tab, setTab] = useState('custom'); const [busy, setBusy] = useState(false); const [saved, setSaved] = useState(false); const [error, setError] = useState(null); useEffect(() => { api .get('/ai/knowledge') .then(setData) .catch((e) => setError(e.message)); }, []); if (!data) { return ( }> {error ? {error} : {__('Loading…', 'ai-rank-suite')}} ); } const stored = data.custom || ''; const value = draft === null ? stored : draft; const dirty = draft !== null && draft !== stored; const save = async () => { setBusy(true); setError(null); try { const next = await api.put('/ai/knowledge', { custom: value }); setData(next); setDraft(null); setSaved(true); setTimeout(() => setSaved(false), 1800); } catch (e) { setError(e.message); } finally { setBusy(false); } }; const cancel = () => setDraft(null); // The fixed part of the briefing is everything before the owner's section. const briefing = data.briefing || ''; const cut = briefing.indexOf("## About this business, in the owner's words"); const fixed = cut > 0 ? briefing.slice(0, cut).trim() : briefing; return ( } action={
{saved && ✓ {__('Saved', 'ai-rank-suite')}}
} > {error && {error}} {tab === 'custom' && (

{__( 'Tell the writer what a new colleague would need to know: what you sell, to whom, where, in which languages, what you never claim, and how you sound. Plain text; the fixed template already covers SEO and GEO rules.', 'ai-rank-suite' )}