feat(company-explorer): add wikipedia integration, robotics settings, and manual overrides

- Ported robust Wikipedia extraction logic (categories, first paragraph) from legacy system.
- Implemented database-driven Robotics Category configuration with frontend settings UI.
- Updated Robotics Potential analysis to use Chain-of-Thought infrastructure reasoning.
- Added Manual Override features for Wikipedia URL (with locking) and Website URL (with re-scrape trigger).
- Enhanced Inspector UI with Wikipedia profile, category tags, and action buttons.
This commit is contained in:
2026-01-08 10:08:21 +00:00
parent 3590e34490
commit e4b59b1571
12 changed files with 1320 additions and 160 deletions

View File

@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'
import axios from 'axios'
import { X, ExternalLink, Robot, Briefcase, Calendar } from 'lucide-react'
import { X, ExternalLink, Bot, Briefcase, Calendar, Globe, Users, DollarSign, MapPin, Tag, RefreshCw as RefreshCwIcon, Search as SearchIcon, Pencil, Check } from 'lucide-react'
import clsx from 'clsx'
interface InspectorProps {
@@ -16,6 +16,12 @@ type Signal = {
proof_text: string
}
type EnrichmentData = {
source_type: string
content: any
is_locked?: boolean
}
type CompanyDetail = {
id: number
name: string
@@ -24,25 +30,99 @@ type CompanyDetail = {
status: string
created_at: string
signals: Signal[]
enrichment_data: EnrichmentData[]
}
export function Inspector({ companyId, onClose, apiBase }: InspectorProps) {
const [data, setData] = useState<CompanyDetail | null>(null)
const [loading, setLoading] = useState(false)
const [isProcessing, setIsProcessing] = useState(false)
// Manual Override State
const [isEditingWiki, setIsEditingWiki] = useState(false)
const [wikiUrlInput, setWikiUrlInput] = useState("")
const [isEditingWebsite, setIsEditingWebsite] = useState(false)
const [websiteInput, setWebsiteInput] = useState("")
useEffect(() => {
const fetchData = () => {
if (!companyId) return
setLoading(true)
axios.get(`${apiBase}/companies/${companyId}`)
.then(res => setData(res.data))
.catch(console.error)
.finally(() => setLoading(false))
}
useEffect(() => {
fetchData()
setIsEditingWiki(false)
setIsEditingWebsite(false)
}, [companyId])
const handleDiscover = async () => {
if (!companyId) return
setIsProcessing(true)
try {
await axios.post(`${apiBase}/enrich/discover`, { company_id: companyId })
setTimeout(fetchData, 3000)
} catch (e) {
console.error(e)
} finally {
setIsProcessing(false)
}
}
const handleAnalyze = async () => {
if (!companyId) return
setIsProcessing(true)
try {
await axios.post(`${apiBase}/enrich/analyze`, { company_id: companyId })
setTimeout(fetchData, 5000)
} catch (e) {
console.error(e)
} finally {
setIsProcessing(false)
}
}
const handleWikiOverride = async () => {
if (!companyId) return
setIsProcessing(true)
try {
await axios.post(`${apiBase}/companies/${companyId}/override/wiki?url=${encodeURIComponent(wikiUrlInput)}`)
setIsEditingWiki(false)
fetchData()
} catch (e) {
alert("Update failed")
console.error(e)
} finally {
setIsProcessing(false)
}
}
const handleWebsiteOverride = async () => {
if (!companyId) return
setIsProcessing(true)
try {
await axios.post(`${apiBase}/companies/${companyId}/override/website?url=${encodeURIComponent(websiteInput)}`)
setIsEditingWebsite(false)
fetchData()
} catch (e) {
alert("Update failed")
console.error(e)
} finally {
setIsProcessing(false)
}
}
if (!companyId) return null
const wikiEntry = data?.enrichment_data?.find(e => e.source_type === 'wikipedia')
const wiki = wikiEntry?.content
const isLocked = wikiEntry?.is_locked
return (
<div className="fixed inset-y-0 right-0 w-[500px] bg-slate-900 border-l border-slate-800 shadow-2xl transform transition-transform duration-300 ease-in-out z-40 overflow-y-auto">
<div className="fixed inset-y-0 right-0 w-[550px] bg-slate-900 border-l border-slate-800 shadow-2xl transform transition-transform duration-300 ease-in-out z-40 overflow-y-auto">
{loading ? (
<div className="p-8 text-slate-500">Loading details...</div>
) : !data ? (
@@ -53,30 +133,241 @@ export function Inspector({ companyId, onClose, apiBase }: InspectorProps) {
<div className="p-6 border-b border-slate-800 bg-slate-950/50">
<div className="flex justify-between items-start mb-4">
<h2 className="text-xl font-bold text-white leading-tight">{data.name}</h2>
<button onClick={onClose} className="text-slate-400 hover:text-white">
<X className="h-6 w-6" />
</button>
<div className="flex items-center gap-2">
<button
onClick={fetchData}
className="p-1.5 text-slate-500 hover:text-white transition-colors"
title="Refresh"
>
<RefreshCwIcon className={clsx("h-4 w-4", loading && "animate-spin")} />
</button>
<button onClick={onClose} className="p-1.5 text-slate-400 hover:text-white transition-colors">
<X className="h-6 w-6" />
</button>
</div>
</div>
<div className="flex flex-wrap gap-2 text-sm">
{data.website && (
<a href={data.website} target="_blank" className="flex items-center gap-1 text-blue-400 hover:underline">
<ExternalLink className="h-3 w-3" /> {new URL(data.website).hostname.replace('www.', '')}
</a>
<div className="flex flex-wrap gap-2 text-sm items-center">
{!isEditingWebsite ? (
<div className="flex items-center gap-2">
{data.website && data.website !== "k.A." ? (
<a href={data.website} target="_blank" className="flex items-center gap-1 text-blue-400 hover:text-blue-300 transition-colors">
<ExternalLink className="h-3 w-3" /> {new URL(data.website).hostname.replace('www.', '')}
</a>
) : (
<span className="text-slate-500 italic">No website</span>
)}
<button
onClick={() => { setWebsiteInput(data.website && data.website !== "k.A." ? data.website : ""); setIsEditingWebsite(true); }}
className="p-1 text-slate-600 hover:text-white transition-colors"
title="Edit Website URL"
>
<Pencil className="h-3 w-3" />
</button>
</div>
) : (
<div className="flex items-center gap-1 animate-in fade-in zoom-in duration-200">
<input
type="text"
value={websiteInput}
onChange={e => setWebsiteInput(e.target.value)}
placeholder="https://..."
className="bg-slate-800 border border-slate-700 rounded px-2 py-0.5 text-xs text-white focus:ring-1 focus:ring-blue-500 outline-none w-48"
autoFocus
/>
<button
onClick={handleWebsiteOverride}
className="p-1 bg-green-900/50 text-green-400 rounded hover:bg-green-900 transition-colors"
>
<Check className="h-3 w-3" />
</button>
<button
onClick={() => setIsEditingWebsite(false)}
className="p-1 text-slate-500 hover:text-red-400 transition-colors"
>
<X className="h-3 w-3" />
</button>
</div>
)}
{data.industry_ai && (
<span className="flex items-center gap-1 px-2 py-0.5 bg-slate-800 text-slate-300 rounded border border-slate-700">
<Briefcase className="h-3 w-3" /> {data.industry_ai}
</span>
)}
<span className={clsx(
"px-2 py-0.5 rounded text-[10px] font-bold uppercase tracking-wider",
data.status === 'ENRICHED' ? "bg-green-900/40 text-green-400 border border-green-800/50" :
data.status === 'DISCOVERED' ? "bg-blue-900/40 text-blue-400 border border-blue-800/50" :
"bg-slate-800 text-slate-400 border border-slate-700"
)}>
{data.status}
</span>
</div>
{/* Action Bar */}
<div className="mt-6 flex gap-2">
<button
onClick={handleDiscover}
disabled={isProcessing}
className="flex-1 flex items-center justify-center gap-2 bg-slate-800 hover:bg-slate-700 disabled:opacity-50 text-white text-xs font-bold py-2 rounded-md border border-slate-700 transition-all"
>
<SearchIcon className="h-3.5 w-3.5" />
{isProcessing ? "Processing..." : "DISCOVER"}
</button>
<button
onClick={handleAnalyze}
disabled={isProcessing || !data.website || data.website === 'k.A.'}
className="flex-1 flex items-center justify-center gap-2 bg-blue-600 hover:bg-blue-500 disabled:opacity-50 text-white text-xs font-bold py-2 rounded-md transition-all shadow-lg shadow-blue-900/20"
>
<Bot className="h-3.5 w-3.5" />
{isProcessing ? "Analyzing..." : "ANALYZE POTENTIAL"}
</button>
</div>
</div>
{/* Robotics Scorecard */}
<div className="p-6 space-y-6">
<div className="p-6 space-y-8">
{/* Wikipedia Section */}
<div className="space-y-4">
<div className="flex items-center justify-between">
<h3 className="text-sm font-semibold text-slate-400 uppercase tracking-wider flex items-center gap-2">
<Globe className="h-4 w-4" /> Company Profile (Wikipedia)
</h3>
{!isEditingWiki ? (
<button
onClick={() => { setWikiUrlInput(wiki?.url || ""); setIsEditingWiki(true); }}
className="p-1 text-slate-500 hover:text-blue-400 transition-colors"
title="Edit / Override URL"
>
<Pencil className="h-3.5 w-3.5" />
</button>
) : (
<div className="flex items-center gap-1">
<button
onClick={handleWikiOverride}
className="p-1 bg-green-900/50 text-green-400 rounded hover:bg-green-900 transition-colors"
title="Save & Rescan"
>
<Check className="h-3.5 w-3.5" />
</button>
<button
onClick={() => setIsEditingWiki(false)}
className="p-1 text-slate-500 hover:text-red-400 transition-colors"
title="Cancel"
>
<X className="h-3.5 w-3.5" />
</button>
</div>
)}
</div>
{isEditingWiki && (
<div className="mb-2">
<input
type="text"
value={wikiUrlInput}
onChange={e => setWikiUrlInput(e.target.value)}
placeholder="Paste Wikipedia URL here..."
className="w-full bg-slate-800 border border-slate-700 rounded px-2 py-1 text-sm text-white focus:ring-1 focus:ring-blue-500 outline-none"
/>
<p className="text-[10px] text-slate-500 mt-1">Paste a valid URL. Saving will trigger a re-scan.</p>
</div>
)}
{wiki && wiki.url !== 'k.A.' && !isEditingWiki ? (
<div>
{/* ... existing wiki content ... */}
<div className="bg-slate-800/30 rounded-xl p-5 border border-slate-800/50 relative overflow-hidden">
<div className="absolute top-0 right-0 p-3 opacity-10">
<Globe className="h-16 w-16" />
</div>
{isLocked && (
<div className="absolute top-2 right-2 flex items-center gap-1 px-1.5 py-0.5 bg-yellow-900/30 border border-yellow-800/50 rounded text-[9px] text-yellow-500">
<Tag className="h-2.5 w-2.5" /> Manual Override
</div>
)}
<p className="text-sm text-slate-300 leading-relaxed italic mb-4">
"{wiki.first_paragraph}"
</p>
<div className="grid grid-cols-2 gap-y-4 gap-x-6">
<div className="flex items-center gap-3">
<div className="p-2 bg-slate-900 rounded-lg text-blue-400">
<Users className="h-4 w-4" />
</div>
<div>
<div className="text-[10px] text-slate-500 uppercase font-bold tracking-tight">Employees</div>
<div className="text-sm text-slate-200 font-medium">{wiki.mitarbeiter || 'k.A.'}</div>
</div>
</div>
<div className="flex items-center gap-3">
<div className="p-2 bg-slate-900 rounded-lg text-green-400">
<DollarSign className="h-4 w-4" />
</div>
<div>
<div className="text-[10px] text-slate-500 uppercase font-bold tracking-tight">Revenue</div>
<div className="text-sm text-slate-200 font-medium">{wiki.umsatz ? `${wiki.umsatz} Mio. €` : 'k.A.'}</div>
</div>
</div>
<div className="flex items-center gap-3">
<div className="p-2 bg-slate-900 rounded-lg text-orange-400">
<MapPin className="h-4 w-4" />
</div>
<div>
<div className="text-[10px] text-slate-500 uppercase font-bold tracking-tight">Headquarters</div>
<div className="text-sm text-slate-200 font-medium">{wiki.sitz_stadt}{wiki.sitz_land ? `, ${wiki.sitz_land}` : ''}</div>
</div>
</div>
<div className="flex items-center gap-3">
<div className="p-2 bg-slate-900 rounded-lg text-purple-400">
<Briefcase className="h-4 w-4" />
</div>
<div>
<div className="text-[10px] text-slate-500 uppercase font-bold tracking-tight">Wiki Industry</div>
<div className="text-sm text-slate-200 font-medium truncate max-w-[150px]" title={wiki.branche}>{wiki.branche || 'k.A.'}</div>
</div>
</div>
</div>
{wiki.categories && wiki.categories !== 'k.A.' && (
<div className="mt-6 pt-5 border-t border-slate-800/50">
<div className="flex items-start gap-2 text-xs text-slate-500 mb-2">
<Tag className="h-3 w-3 mt-0.5" /> Categories
</div>
<div className="flex flex-wrap gap-1.5">
{wiki.categories.split(',').map((cat: string) => (
<span key={cat} className="px-2 py-0.5 bg-slate-900 text-slate-400 rounded-full text-[10px] border border-slate-800">
{cat.trim()}
</span>
))}
</div>
</div>
)}
<div className="mt-4 flex justify-end">
<a href={wiki.url} target="_blank" className="text-[10px] text-blue-500 hover:text-blue-400 flex items-center gap-1 font-bold">
WIKIPEDIA <ExternalLink className="h-2.5 w-2.5" />
</a>
</div>
</div>
</div>
) : !isEditingWiki ? (
<div className="p-4 rounded-xl border border-dashed border-slate-800 text-center text-slate-600">
<Globe className="h-5 w-5 mx-auto mb-2 opacity-20" />
<p className="text-xs">No Wikipedia profile found yet.</p>
</div>
) : null}
</div>
{/* Robotics Scorecard */}
<div>
<h3 className="text-sm font-semibold text-slate-400 uppercase tracking-wider mb-3 flex items-center gap-2">
<Robot className="h-4 w-4" /> Robotics Potential
<Bot className="h-4 w-4" /> Robotics Potential
</h3>
<div className="grid grid-cols-2 gap-4">
@@ -110,10 +401,13 @@ export function Inspector({ companyId, onClose, apiBase }: InspectorProps) {
</div>
{/* Meta Info */}
<div className="pt-6 border-t border-slate-800">
<div className="text-xs text-slate-500 flex items-center gap-2">
<div className="pt-6 border-t border-slate-800 flex items-center justify-between">
<div className="text-[10px] text-slate-500 flex items-center gap-2 uppercase font-bold tracking-widest">
<Calendar className="h-3 w-3" /> Added: {new Date(data.created_at).toLocaleDateString()}
</div>
<div className="text-[10px] text-slate-600 italic">
ID: CE-{data.id.toString().padStart(4, '0')}
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,134 @@
import { useState, useEffect } from 'react'
import axios from 'axios'
import { X, Save, Settings, Loader2 } from 'lucide-react'
interface RoboticsSettingsProps {
isOpen: boolean
onClose: () => void
apiBase: string
}
type Category = {
id: number
key: string
name: string
description: string
reasoning_guide: string
}
export function RoboticsSettings({ isOpen, onClose, apiBase }: RoboticsSettingsProps) {
const [categories, setCategories] = useState<Category[]>([])
const [loading, setLoading] = useState(false)
const [savingId, setSavingId] = useState<number | null>(null)
useEffect(() => {
if (isOpen) {
setLoading(true)
axios.get(`${apiBase}/robotics/categories`)
.then(res => setCategories(res.data))
.catch(console.error)
.finally(() => setLoading(false))
}
}, [isOpen])
const handleSave = async (cat: Category) => {
setSavingId(cat.id)
try {
await axios.put(`${apiBase}/robotics/categories/${cat.id}`, {
description: cat.description,
reasoning_guide: cat.reasoning_guide
})
// Success indicator?
} catch (e) {
alert("Failed to save settings")
} finally {
setSavingId(null)
}
}
const handleChange = (id: number, field: keyof Category, value: string) => {
setCategories(prev => prev.map(c =>
c.id === id ? { ...c, [field]: value } : c
))
}
if (!isOpen) return null
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-sm">
<div className="bg-slate-900 border border-slate-800 rounded-xl shadow-2xl w-full max-w-4xl max-h-[90vh] flex flex-col">
{/* Header */}
<div className="p-6 border-b border-slate-800 flex justify-between items-center bg-slate-950/50 rounded-t-xl">
<div className="flex items-center gap-3">
<div className="p-2 bg-blue-600/20 rounded-lg text-blue-400">
<Settings className="h-6 w-6" />
</div>
<div>
<h2 className="text-xl font-bold text-white">Robotics Logic Configuration</h2>
<p className="text-sm text-slate-400">Define how the AI assesses potential for each category.</p>
</div>
</div>
<button onClick={onClose} className="text-slate-400 hover:text-white transition-colors">
<X className="h-6 w-6" />
</button>
</div>
{/* Content */}
<div className="flex-1 overflow-y-auto p-6 space-y-6">
{loading ? (
<div className="flex items-center justify-center py-20 text-slate-500">
<Loader2 className="h-8 w-8 animate-spin" />
</div>
) : (
<div className="grid grid-cols-1 gap-6">
{categories.map(cat => (
<div key={cat.id} className="bg-slate-800/30 border border-slate-700/50 rounded-lg p-5">
<div className="flex justify-between items-start mb-4">
<h3 className="text-lg font-bold text-white flex items-center gap-2">
<span className="capitalize">{cat.name}</span>
<span className="text-xs font-mono text-slate-500 bg-slate-900 px-1.5 py-0.5 rounded border border-slate-800">{cat.key}</span>
</h3>
<button
onClick={() => handleSave(cat)}
disabled={savingId === cat.id}
className="flex items-center gap-2 px-3 py-1.5 bg-blue-600 hover:bg-blue-500 disabled:opacity-50 text-white text-xs font-bold rounded transition-colors"
>
{savingId === cat.id ? <Loader2 className="h-3 w-3 animate-spin" /> : <Save className="h-3 w-3" />}
SAVE
</button>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div className="space-y-2">
<label className="text-xs font-bold text-slate-400 uppercase tracking-wider">Definition (When to trigger?)</label>
<textarea
value={cat.description}
onChange={(e) => handleChange(cat.id, 'description', e.target.value)}
className="w-full h-32 bg-slate-950 border border-slate-700 rounded p-3 text-sm text-slate-200 focus:ring-1 focus:ring-blue-500 outline-none resize-none font-mono leading-relaxed"
/>
<p className="text-[10px] text-slate-500">
Instructions for the AI on what business models or assets imply this need.
</p>
</div>
<div className="space-y-2">
<label className="text-xs font-bold text-slate-400 uppercase tracking-wider">Scoring Guide (High/Med/Low)</label>
<textarea
value={cat.reasoning_guide}
onChange={(e) => handleChange(cat.id, 'reasoning_guide', e.target.value)}
className="w-full h-32 bg-slate-950 border border-slate-700 rounded p-3 text-sm text-slate-200 focus:ring-1 focus:ring-blue-500 outline-none resize-none font-mono leading-relaxed"
/>
<p className="text-[10px] text-slate-500">
Explicit examples for scoring logic to ensure consistency.
</p>
</div>
</div>
</div>
))}
</div>
)}
</div>
</div>
</div>
)
}