Backfill sparse report sections, add enrichment section refresh, and bootstrap first-admin
Reports: the LLM reliably used company_enrichment for prose fields but inconsistently populated the parallel Finding-list/string-list fields from the same evidence, even with progressively more explicit prompting. Add a code-level backfill (products, recent developments, financial signals, strategic initiatives, regulatory signals, risks/opportunities mirrored from SWOT, unknowns, monitoring recommendations) that only ever fills in what the model left empty, never overwrites what it produced. Enrichment tab: reorder sections (Products/Recent updates before Customers/Competitors) and add a per-section "Refresh" button that re-fetches just one of NinjaPear's six independent per-company endpoints when it came back empty - confirmed live that a data-coverage gap (e.g. Amazon returning no products) is real provider behavior, not a bug. Auth: the first account registered on a deployment with zero existing admins is now auto-promoted to admin, closing the chicken-and-egg gap where the only path to admin access was direct DB access. Self-heals if the last admin ever deletes their account. Also bumps nginx's proxy_read_timeout for api.ciagent.org to cover the enrichment refresh's synchronous funding-endpoint call (up to 5 minutes per NinjaPear's docs). Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
ChevronRight,
|
||||
Loader2,
|
||||
Plus,
|
||||
RefreshCw,
|
||||
} from "lucide-react";
|
||||
import { CompanyPillLink } from "@/components/ui/company-pill";
|
||||
import { CopyableEmail } from "@/components/ui/copyable-email";
|
||||
@@ -23,6 +24,7 @@ import {
|
||||
useCompanies,
|
||||
useCompany,
|
||||
useDeleteCompany,
|
||||
useRefreshEnrichmentSection,
|
||||
useSetCompanyPaused,
|
||||
useUpdateMonitorConfiguration,
|
||||
} from "@/hooks/use-companies";
|
||||
@@ -37,7 +39,7 @@ import {
|
||||
import { useCompanyRuns, useRunCompanyNow } from "@/hooks/use-monitoring-runs";
|
||||
import { useCompanyReports, useGenerateReport } from "@/hooks/use-reports";
|
||||
import { useSnapshots } from "@/hooks/use-snapshots";
|
||||
import type { MonitoringFrequency } from "@/lib/types";
|
||||
import type { EnrichmentSection, MonitoringFrequency } from "@/lib/types";
|
||||
import {
|
||||
FREQUENCY_LABELS,
|
||||
MONITORING_FREQUENCIES,
|
||||
@@ -149,6 +151,30 @@ function EnrichmentErrorSummary({
|
||||
);
|
||||
}
|
||||
|
||||
function RefreshSectionButton({
|
||||
section,
|
||||
label,
|
||||
mutation,
|
||||
}: {
|
||||
section: EnrichmentSection;
|
||||
label: string;
|
||||
mutation: ReturnType<typeof useRefreshEnrichmentSection>;
|
||||
}) {
|
||||
const isRefreshing = mutation.isPending && mutation.variables === section;
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => mutation.mutate(section)}
|
||||
disabled={isRefreshing}
|
||||
title={`Re-fetch ${label} from NinjaPear`}
|
||||
className="focus-ring mt-2 inline-flex items-center gap-1.5 rounded-md border border-slate-300 px-2 py-1 text-xs font-medium text-slate-700 transition-colors duration-150 hover:bg-slate-50 disabled:opacity-60"
|
||||
>
|
||||
<RefreshCw className={`h-3 w-3 ${isRefreshing ? "animate-spin" : ""}`} aria-hidden />
|
||||
{isRefreshing ? "Refreshing…" : "Refresh"}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export default function CompanyDetailPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = use(params);
|
||||
return (
|
||||
@@ -176,6 +202,7 @@ function CompanyDetailPageInner({ id }: { id: string }) {
|
||||
const deleteSource = useDeleteSource(id);
|
||||
const testSource = useTestSource(id);
|
||||
const updateSource = useUpdateSource(id);
|
||||
const refreshEnrichmentSection = useRefreshEnrichmentSection(id);
|
||||
const { data: runs, isLoading: runsLoading } = useCompanyRuns(id);
|
||||
const runNow = useRunCompanyNow(id);
|
||||
const { data: reports, isLoading: reportsLoading } = useCompanyReports(id);
|
||||
@@ -532,7 +559,16 @@ function CompanyDetailPageInner({ id }: { id: string }) {
|
||||
| { total_raised?: string; rounds?: Record<string, unknown>[] }
|
||||
| undefined;
|
||||
if (!funding || (!funding.total_raised && !funding.rounds?.length)) {
|
||||
return <p className="mt-2 text-slate-500">No funding data found.</p>;
|
||||
return (
|
||||
<div className="animate-fade-in">
|
||||
<p className="mt-2 text-slate-500">No funding data found.</p>
|
||||
<RefreshSectionButton
|
||||
section="funding"
|
||||
label="funding data"
|
||||
mutation={refreshEnrichmentSection}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
@@ -574,7 +610,14 @@ function CompanyDetailPageInner({ id }: { id: string }) {
|
||||
<h2 className="font-medium text-slate-700">Leadership team</h2>
|
||||
{!Array.isArray(company.enrichment.data.leadership_team) ||
|
||||
(company.enrichment.data.leadership_team as unknown[]).length === 0 ? (
|
||||
<p className="mt-2 text-slate-500">No leadership team data found.</p>
|
||||
<div className="animate-fade-in">
|
||||
<p className="mt-2 text-slate-500">No leadership team data found.</p>
|
||||
<RefreshSectionButton
|
||||
section="details"
|
||||
label="leadership team"
|
||||
mutation={refreshEnrichmentSection}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="mt-2">
|
||||
{(
|
||||
@@ -613,37 +656,18 @@ function CompanyDetailPageInner({ id }: { id: string }) {
|
||||
</section>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<section className="rounded-lg border border-slate-200 bg-white p-5 text-sm">
|
||||
<h2 className="font-medium text-slate-700">Customers</h2>
|
||||
{!Array.isArray(company.enrichment.data.customers) ||
|
||||
(company.enrichment.data.customers as unknown[]).length === 0 ? (
|
||||
<p className="mt-2 text-slate-500">None found.</p>
|
||||
) : (
|
||||
<ul className="mt-2 flex flex-wrap gap-2">
|
||||
{(company.enrichment.data.customers as Record<string, unknown>[]).map(
|
||||
(c, i) => {
|
||||
const name = String(c.name ?? "");
|
||||
if (!name) return null;
|
||||
return (
|
||||
<li key={i}>
|
||||
<CompanyPillLink
|
||||
name={name}
|
||||
monitoredByName={monitoredByName}
|
||||
returnTo={returnTo}
|
||||
/>
|
||||
</li>
|
||||
);
|
||||
},
|
||||
)}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="rounded-lg border border-slate-200 bg-white p-5 text-sm">
|
||||
<h2 className="font-medium text-slate-700">Products</h2>
|
||||
{!Array.isArray(company.enrichment.data.products) ||
|
||||
(company.enrichment.data.products as unknown[]).length === 0 ? (
|
||||
<p className="mt-2 text-slate-500">None found.</p>
|
||||
<div className="animate-fade-in">
|
||||
<p className="mt-2 text-slate-500">None found.</p>
|
||||
<RefreshSectionButton
|
||||
section="products"
|
||||
label="products"
|
||||
mutation={refreshEnrichmentSection}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="mt-2 space-y-1.5">
|
||||
{(company.enrichment.data.products as Record<string, unknown>[]).map(
|
||||
@@ -662,14 +686,19 @@ function CompanyDetailPageInner({ id }: { id: string }) {
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<section className="rounded-lg border border-slate-200 bg-white p-5 text-sm">
|
||||
<h2 className="font-medium text-slate-700">Recent updates</h2>
|
||||
{!Array.isArray(company.enrichment.data.recent_updates) ||
|
||||
(company.enrichment.data.recent_updates as unknown[]).length === 0 ? (
|
||||
<p className="mt-2 text-slate-500">None found.</p>
|
||||
<div className="animate-fade-in">
|
||||
<p className="mt-2 text-slate-500">None found.</p>
|
||||
<RefreshSectionButton
|
||||
section="updates"
|
||||
label="recent updates"
|
||||
mutation={refreshEnrichmentSection}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="mt-2">
|
||||
{(
|
||||
@@ -693,6 +722,41 @@ function CompanyDetailPageInner({ id }: { id: string }) {
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<section className="rounded-lg border border-slate-200 bg-white p-5 text-sm">
|
||||
<h2 className="font-medium text-slate-700">Customers</h2>
|
||||
{!Array.isArray(company.enrichment.data.customers) ||
|
||||
(company.enrichment.data.customers as unknown[]).length === 0 ? (
|
||||
<div className="animate-fade-in">
|
||||
<p className="mt-2 text-slate-500">None found.</p>
|
||||
<RefreshSectionButton
|
||||
section="customers"
|
||||
label="customers"
|
||||
mutation={refreshEnrichmentSection}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="mt-2 flex flex-wrap gap-2">
|
||||
{(company.enrichment.data.customers as Record<string, unknown>[]).map(
|
||||
(c, i) => {
|
||||
const name = String(c.name ?? "");
|
||||
if (!name) return null;
|
||||
return (
|
||||
<li key={i}>
|
||||
<CompanyPillLink
|
||||
name={name}
|
||||
monitoredByName={monitoredByName}
|
||||
returnTo={returnTo}
|
||||
/>
|
||||
</li>
|
||||
);
|
||||
},
|
||||
)}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="rounded-lg border border-slate-200 bg-white p-5 text-sm">
|
||||
<h2 className="font-medium text-slate-700">
|
||||
@@ -701,7 +765,14 @@ function CompanyDetailPageInner({ id }: { id: string }) {
|
||||
</h2>
|
||||
{!Array.isArray(company.enrichment.data.competitors) ||
|
||||
(company.enrichment.data.competitors as unknown[]).length === 0 ? (
|
||||
<p className="mt-2 text-slate-500">None found.</p>
|
||||
<div className="animate-fade-in">
|
||||
<p className="mt-2 text-slate-500">None found.</p>
|
||||
<RefreshSectionButton
|
||||
section="competitors"
|
||||
label="competitors"
|
||||
mutation={refreshEnrichmentSection}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="mt-2 flex flex-wrap gap-2">
|
||||
{(
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
CompanyCreatePayload,
|
||||
CompanyResponse,
|
||||
CompanyUpdatePayload,
|
||||
EnrichmentSection,
|
||||
MonitorConfigurationUpdatePayload,
|
||||
} from "@/lib/types";
|
||||
|
||||
@@ -67,6 +68,17 @@ export function useSetCompanyPaused() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useRefreshEnrichmentSection(companyId: string) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (section: EnrichmentSection) =>
|
||||
api.refreshEnrichmentSection(companyId, section),
|
||||
onSuccess: (company) => {
|
||||
queryClient.setQueryData(["companies", companyId], company);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateMonitorConfiguration(companyId: string) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
|
||||
@@ -16,6 +16,7 @@ import type {
|
||||
DeleteAccountPayload,
|
||||
DiscoverCompanyRequest,
|
||||
DiscoveredCompanyProfile,
|
||||
EnrichmentSection,
|
||||
IpBan,
|
||||
LogEntry,
|
||||
LoginPayload,
|
||||
@@ -316,6 +317,12 @@ export const api = {
|
||||
resumeCompany: (companyId: string) =>
|
||||
request<CompanyResponse>(`/api/v1/companies/${companyId}/resume`, { method: "POST" }),
|
||||
|
||||
refreshEnrichmentSection: (companyId: string, section: EnrichmentSection) =>
|
||||
request<CompanyResponse>(
|
||||
`/api/v1/companies/${companyId}/enrichment/sections/${section}/refresh`,
|
||||
{ method: "POST" },
|
||||
),
|
||||
|
||||
updateMonitorConfiguration: (companyId: string, payload: MonitorConfigurationUpdatePayload) =>
|
||||
request<MonitorConfigurationResponse>(`/api/v1/companies/${companyId}/monitor`, {
|
||||
method: "PATCH",
|
||||
|
||||
@@ -221,6 +221,14 @@ export interface MonitorConfigurationUpdatePayload {
|
||||
|
||||
export type EnrichmentStatus = "pending" | "partial" | "complete" | "failed";
|
||||
|
||||
export type EnrichmentSection =
|
||||
| "details"
|
||||
| "funding"
|
||||
| "updates"
|
||||
| "competitors"
|
||||
| "products"
|
||||
| "customers";
|
||||
|
||||
export interface CompanyEnrichmentResponse {
|
||||
status: EnrichmentStatus;
|
||||
data: Record<string, unknown>;
|
||||
|
||||
Reference in New Issue
Block a user