Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 | 3x 3x 3x 3x 3x 10x 10x 3x 31x 31x 31x 31x 31x 31x 7x 31x 50x 31x 31x 4x 31x 31x 31x 1x 31x 1x 31x 10x 31x 50x 50x 2x 70x 2x 1x 1x 38x 22x 3x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 19x 144x 61x 61x 61x 61x 18x 61x 61x 2x 2x 2x 2x 1x 1x 2x 61x 3x 58x 2x 58x 1x 74x 4x 1x 37x 1x 5x 16x 2x 1x | import {
MetaGrid,
MetaItem,
Modal,
RUN_STATUS,
SectionCard,
SkeletonLines,
StatusBadge,
StatusScale,
} from "@/components/detail";
import {
Knowledge,
KnowledgeCrawl,
WebCrawlScope,
WebDiffLine,
WebPage,
WebPageDiff,
WebPageVersion,
WebPageVersionContent,
WebPageVersionPreview,
WebRefreshCadence,
} from "@/objects/Knowledge";
import { QUERY_KEYS } from "@/services/query_keys";
import { useApiHandler } from "@/services/useApiHandler";
import { errorDetail } from "@/util/apiError";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import {
ChevronRight,
Download,
ExternalLink,
FileClock,
Globe,
History,
Link2,
List,
Loader2,
Minus,
Network,
Plus,
RefreshCw,
Settings,
} from "lucide-react";
import { isSystemManaged } from "@/objects/Doc";
import React, { useState } from "react";
import { Link } from "react-router-dom";
import SnapshotPreviewFrame from "./SnapshotPreviewFrame";
import WebCrawlModal, {
CrawlCounts,
PageHistoryTarget,
TRIGGER_LABEL,
} from "./WebCrawlModal";
import WebLinkGraph from "./WebLinkGraph";
import {
WEB_PAGE_STATUS,
exactly,
webFormFromConfig,
when,
} from "./webSource";
/** A page read because a crawled page links to it, as opposed to one in the
* source's own scope. */
const PAGE_ORIGIN: StatusScale = { linked: "neutral" };
const SCOPE_LABEL: Record<WebCrawlScope, string> = {
page: "Only these pages",
section: "These pages and below",
site: "The whole site",
};
const REFRESH_LABEL: Record<WebRefreshCadence, string> = {
hourly: "Hourly",
daily: "Daily",
weekly: "Weekly",
manual: "Manual",
};
const buttonClass =
"flex items-center gap-1.5 text-xs px-2.5 py-1.5 rounded-lg border border-gray-200 dark:border-gray-600 text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed";
// ─── Snapshot diff ────────────────────────────────────────────────────────────
const DiffLines: React.FC<{ lines: WebDiffLine[] }> = ({ lines }) => (
<div className="space-y-0.5 font-mono text-xs">
{lines.map((line, i) => (
<div
key={i}
className={`whitespace-pre-wrap break-words rounded px-1.5 ${
line.op === "insert"
? "bg-green-50 dark:bg-green-950/40 text-green-800 dark:text-green-300"
: line.op === "delete"
? "bg-red-50 dark:bg-red-950/40 text-red-800 dark:text-red-300"
: line.op === "skip"
? "text-gray-400 dark:text-gray-500 italic"
: "text-gray-500 dark:text-gray-400"
}`}
>
{line.op === "insert" ? (
<Plus className="inline size-3 mr-1 -mt-px" />
) : line.op === "delete" ? (
<Minus className="inline size-3 mr-1 -mt-px" />
) : (
<span className="inline-block w-4" />
)}
{line.line || " "}
</div>
))}
</div>
);
// ─── Page history ─────────────────────────────────────────────────────────────
/**
* Every stored snapshot of one page: the text that was indexed from each,
* what changed between any two of them, and the HTML as the site served it
* (download only — it is somebody else's markup).
*
* Opens on the newest snapshot compared with the one before it, or on what
* `target` names: the crawl view opens a page as that crawl left it,
* compared with its current version.
*/
export const PageHistoryModal: React.FC<
PageHistoryTarget & { knowledgeId: string; onClose: () => void }
> = ({ knowledgeId, page, versionId, compareWith: initialCompare, onClose }) => {
const { getApiHandler } = useApiHandler();
const api = getApiHandler().knowledge_router;
const [selected, setSelected] = useState<string | null>(versionId ?? null);
const [mode, setMode] = useState<"changes" | "text" | "page">("changes");
// A version number, or null for "the version before".
const [compareWith, setCompareWith] = useState<number | null>(
initialCompare ?? null,
);
const { data: versionsData, isLoading } = useQuery<WebPageVersion[] | null>({
queryKey: [
QUERY_KEYS.GET.KNOWLEDGE_WEB_PAGE_VERSIONS,
knowledgeId,
page.document_id,
],
queryFn: () => api.listWebPageVersions(knowledgeId, page.document_id),
});
const versions: WebPageVersion[] = versionsData ?? [];
const current: WebPageVersion | undefined =
versions.find((v) => v.id === selected) ?? versions[0];
const newest = versions[0]?.version_number;
// The version the diff is against, unless it is the one being viewed.
const other =
compareWith != null && compareWith !== current?.version_number
? versions.find((v) => v.version_number === compareWith)
: undefined;
// Always older → newer, so what was added is what came later.
const [diffFrom, diffTo] = !current
? [undefined, undefined]
: !other
? [undefined, current.version_number]
: other.version_number < current.version_number
? [other.version_number, current.version_number]
: [current.version_number, other.version_number];
// A snapshot without kept HTML (a PDF's) has no page to preview, so the
// "page" tab falls back to the diff rather than showing an empty panel.
const view = mode === "page" && !current?.has_html ? "changes" : mode;
const { data: contentData, isLoading: loadingContent } =
useQuery<WebPageVersionContent | null>({
queryKey: ["web-page-version", knowledgeId, current?.id],
queryFn: () =>
current
? api.getWebPageVersion(knowledgeId, page.document_id, current.id)
: Promise.resolve(null),
enabled: !!current && view === "text",
});
const { data: previewData, isLoading: loadingPreview } =
useQuery<WebPageVersionPreview | null>({
queryKey: ["web-page-preview", knowledgeId, current?.id],
queryFn: () =>
current
? api.getWebPagePreview(knowledgeId, page.document_id, current.id)
: Promise.resolve(null),
enabled: !!current?.has_html && view === "page",
});
const { data: diffData, isLoading: loadingDiff } =
useQuery<WebPageDiff | null>({
queryKey: [
"web-page-diff",
knowledgeId,
page.document_id,
diffTo,
diffFrom ?? null,
],
queryFn: () =>
diffTo == null
? Promise.resolve(null)
: diffFrom == null
? api.diffWebPage(knowledgeId, page.document_id, diffTo)
: api.diffWebPage(knowledgeId, page.document_id, diffTo, diffFrom),
enabled: diffTo != null && view === "changes",
});
return (
<Modal
title={page.title || page.url}
icon={FileClock}
size="xl"
onClose={onClose}
description={
<a
href={page.url}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1 break-all hover:underline"
>
{page.url}
<ExternalLink className="size-3 shrink-0" />
</a>
}
>
{isLoading ? (
<SkeletonLines count={4} />
) : versions.length === 0 ? (
<p className="text-sm text-gray-400 dark:text-gray-500 italic">
No snapshot of this page has been stored yet.
</p>
) : (
<div className="grid gap-4 md:grid-cols-[13rem_1fr]">
<ol className="space-y-1" aria-label="Snapshots">
{versions.map((v) => {
const active = v.id === current?.id;
return (
<li key={v.id}>
<button
type="button"
onClick={() => setSelected(v.id)}
aria-current={active}
className={`flex w-full flex-col items-start rounded-lg px-3 py-2 text-left text-xs transition-colors ${
active
? "bg-gray-900 text-white dark:bg-gray-100 dark:text-gray-900"
: "hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300"
}`}
>
<span className="font-semibold">
Version {v.version_number}
{v.version_number === newest && (
<span className="ml-1 font-normal opacity-75">
· current
</span>
)}
</span>
<span className="block opacity-75" title={exactly(v.fetched_at)}>
{when(v.fetched_at)}
</span>
</button>
</li>
);
})}
</ol>
<div className="min-w-0 space-y-3">
<div className="flex flex-wrap items-center gap-2">
<div
role="tablist"
className="inline-flex rounded-lg border border-gray-200 dark:border-gray-600 p-0.5"
>
{(
[
["changes", "What changed"],
["text", "Snapshot text"],
// Only snapshots whose HTML was kept (not PDFs) have one.
...(current?.has_html
? ([["page", "Page as captured"]] as const)
: []),
] as const
).map(([value, label]) => (
<button
key={value}
role="tab"
type="button"
aria-selected={view === value}
onClick={() => setMode(value)}
className={`px-2.5 py-1 text-xs rounded-md transition-colors ${
view === value
? "bg-gray-900 text-white dark:bg-gray-100 dark:text-gray-900"
: "text-gray-600 dark:text-gray-300"
}`}
>
{label}
</button>
))}
</div>
{current?.has_html && (
<button
type="button"
className={buttonClass}
onClick={() =>
void api.downloadWebPageHtml(
knowledgeId,
page.document_id,
current,
)
}
>
<Download className="size-3.5" />
HTML as served
</button>
)}
</div>
{view === "page" && current?.has_html ? (
loadingPreview ? (
<SkeletonLines count={6} />
) : previewData ? (
<div className="space-y-2">
<p className="text-xs text-gray-500 dark:text-gray-400">
The page's content and structure as captured — shown
without its scripts, styles, images from the web or
working links, in an isolated frame that cannot reach the
network.
{previewData.truncated &&
" Very long: only the beginning is shown."}
</p>
<SnapshotPreviewFrame
html={previewData.html}
title={`Version ${current.version_number} of ${page.url}`}
/>
</div>
) : (
<p className="text-sm text-red-500">Could not load the preview.</p>
)
) : view === "changes" ? (
<div className="space-y-2">
{versions.length > 1 && (
<label className="flex flex-wrap items-center gap-2 text-xs text-gray-600 dark:text-gray-300">
Compare with
<select
value={other ? String(other.version_number) : "previous"}
onChange={(e) =>
setCompareWith(
e.target.value === "previous"
? null
: Number(e.target.value),
)
}
className="rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-800 px-2 py-1 text-xs text-gray-700 dark:text-gray-200"
>
<option value="previous">The version before</option>
{versions
.filter((v) => v.id !== current?.id)
.map((v) => (
<option key={v.id} value={v.version_number}>
Version {v.version_number}
{v.version_number === newest ? " (current)" : ""}
</option>
))}
</select>
</label>
)}
{loadingDiff ? (
<SkeletonLines count={5} />
) : diffData ? (
<>
<p className="text-xs text-gray-500 dark:text-gray-400">
{diffData.from_version
? `Version ${diffData.from_version.version_number} → ${diffData.to_version.version_number}: ${diffData.added_lines} line(s) added, ${diffData.removed_lines} removed.`
: "The first snapshot of this page — everything in it is new."}
</p>
<div className="max-h-[55vh] overflow-auto rounded-lg border border-gray-200 dark:border-gray-700 p-2">
<DiffLines lines={diffData.text_diff} />
</div>
</>
) : (
<p className="text-sm text-red-500">Could not load the changes.</p>
)}
</div>
) : loadingContent ? (
<SkeletonLines count={6} />
) : contentData ? (
<pre className="max-h-[55vh] overflow-auto rounded-lg border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900 p-3 text-xs font-mono text-gray-800 dark:text-gray-200 whitespace-pre-wrap break-words">
{contentData.markdown}
</pre>
) : (
<p className="text-sm text-red-500">Could not load the snapshot.</p>
)}
</div>
</div>
)}
</Modal>
);
};
// ─── The section ──────────────────────────────────────────────────────────────
/**
* A website source on its knowledge page: what it crawls, its latest crawl,
* every page it has stored, and the crawl history. Pages are the crawl's to
* add and remove, so there is no upload here — only "Refresh now".
*/
const WebKnowledgeSection: React.FC<{
knowledge: Knowledge;
editHref: string;
/** The caller may not change the source here (`can_change` false: a
* reader, or what a project inherits): it is crawled, not refreshed. */
readOnly?: boolean;
}> = ({ knowledge, editHref, readOnly = false }) => {
const { getApiHandler } = useApiHandler();
const api = getApiHandler().knowledge_router;
const queryClient = useQueryClient();
const config = webFormFromConfig(knowledge.source_config);
const urls = config.urls.split("\n").filter(Boolean);
// Built in (a News feed): kept current by the platform, never by hand.
const builtIn = isSystemManaged(knowledge);
const refreshable = !builtIn && !readOnly;
const [refreshing, setRefreshing] = useState(false);
const [refreshError, setRefreshError] = useState<string | null>(null);
const [historyOf, setHistoryOf] = useState<PageHistoryTarget | null>(null);
// A crawl opened to see the source as it left it. Kept while a page's
// history is open from it, so closing that history goes back to the crawl.
const [crawlOf, setCrawlOf] = useState<KnowledgeCrawl | null>(null);
const [pagesView, setPagesView] = useState<"list" | "graph">("list");
const crawlsKey = [QUERY_KEYS.GET.KNOWLEDGE_WEB_CRAWLS, knowledge.id];
const pagesKey = [QUERY_KEYS.GET.KNOWLEDGE_WEB_PAGES, knowledge.id];
const { data: crawlsData, isLoading: loadingCrawls } = useQuery<
KnowledgeCrawl[] | null
>({
queryKey: crawlsKey,
queryFn: () => api.listWebCrawls(knowledge.id),
enabled: urls.length > 0,
// Poll while a crawl runs, so its progress and the pages it finds
// appear without a reload; stop once it has finished.
refetchInterval: (query) =>
(query.state.data as KnowledgeCrawl[] | null | undefined)?.[0]
?.status === "running"
? 3000
: false,
});
const crawls: KnowledgeCrawl[] = crawlsData ?? [];
const latest: KnowledgeCrawl | undefined = crawls[0];
const running = latest?.status === "running";
const { data: pagesData, isLoading: loadingPages } = useQuery<
WebPage[] | null
>({
queryKey: pagesKey,
queryFn: () => api.listWebPages(knowledge.id),
enabled: urls.length > 0,
refetchInterval: running ? 3000 : false,
});
const pages: WebPage[] = pagesData ?? [];
const refresh = async () => {
setRefreshing(true);
setRefreshError(null);
try {
await api.crawlWebSource(knowledge.id);
await queryClient.invalidateQueries({ queryKey: crawlsKey });
} catch (e: unknown) {
setRefreshError(errorDetail(e, "Could not start a crawl."));
} finally {
setRefreshing(false);
}
};
if (urls.length === 0) {
return (
<SectionCard icon={Globe} title="Website">
<div className="flex flex-col items-start gap-3">
<p className="text-sm text-gray-600 dark:text-gray-300">
This source has no URLs yet, so there is nothing to crawl.
{refreshable && " Add the pages or sitemaps it should keep up to date."}
</p>
{refreshable && (
<Link to={editHref} className={buttonClass}>
<Settings className="size-3.5" />
Add URLs
</Link>
)}
</div>
</SectionCard>
);
}
return (
<>
<SectionCard
icon={Globe}
title="Website"
action={
!refreshable ? (
running ? (
<span className="flex items-center gap-1.5 text-xs text-gray-500 dark:text-gray-400">
<Loader2 className="size-3.5 animate-spin" />
Crawling…
</span>
) : undefined
) : (
<button
type="button"
onClick={() => void refresh()}
disabled={refreshing || running}
className={buttonClass}
>
{refreshing || running ? (
<Loader2 className="size-3.5 animate-spin" />
) : (
<RefreshCw className="size-3.5" />
)}
{running ? "Crawling…" : "Refresh now"}
</button>
)
}
>
<div className="space-y-4">
<ul className="space-y-1">
{urls.map((url) => (
<li key={url} className="flex items-center gap-2 text-sm min-w-0">
<Link2 className="size-3.5 shrink-0 text-gray-400" />
<a
href={url}
target="_blank"
rel="noopener noreferrer"
className="truncate text-gray-800 dark:text-gray-200 hover:underline"
>
{url}
</a>
</li>
))}
</ul>
<MetaGrid>
<MetaItem
label="Crawls"
value={
config.follow_external
? `${SCOPE_LABEL[config.scope]}, and the pages they link to`
: SCOPE_LABEL[config.scope]
}
/>
<MetaItem
label="Limits"
value={
config.scope === "page"
? `${config.max_pages} pages`
: `${config.max_pages} pages · ${config.max_depth} links deep`
}
/>
<MetaItem label="Refresh" value={REFRESH_LABEL[config.refresh]} />
<MetaItem label="Pages stored" value={String(pages.length)} />
{config.max_age_days && (
<MetaItem label="Keeps" value={`The last ${config.max_age_days} days`} />
)}
</MetaGrid>
{builtIn && (
<p className="text-xs text-gray-500 dark:text-gray-400">
Kept current by CHAIN-R: read hourly while any agent has its
repository granted, and never otherwise.
</p>
)}
{config.attribution && (
<p className="text-xs text-gray-500 dark:text-gray-400">
<span className="font-medium text-gray-600 dark:text-gray-300">
Credit:{" "}
</span>
{config.attribution}
{config.licence_url && (
<>
{" "}
<a
href={config.licence_url}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-0.5 hover:underline"
>
Licence
<ExternalLink className="size-3" />
</a>
</>
)}
</p>
)}
{loadingCrawls ? (
<SkeletonLines count={2} />
) : latest ? (
<div className="rounded-lg border border-gray-200 dark:border-gray-700 px-3 py-2.5 space-y-1.5">
<div className="flex flex-wrap items-center gap-2">
<span className="text-xs font-medium text-gray-700 dark:text-gray-300">
Latest crawl
</span>
<StatusBadge status={latest.status} scale={RUN_STATUS} size="xs" />
<span
className="text-xs text-gray-400 dark:text-gray-500"
title={exactly(latest.started_at)}
>
{when(latest.started_at)}
</span>
<CrawlCounts crawl={latest} />
<button
type="button"
onClick={() => setCrawlOf(latest)}
className={`${buttonClass} sm:ml-auto`}
>
<FileClock className="size-3.5" />
Pages from this crawl
</button>
</div>
{latest.note && (
<p className="text-xs text-gray-500 dark:text-gray-400 whitespace-pre-line break-words">
{latest.note}
</p>
)}
</div>
) : (
<p className="text-sm text-gray-400 dark:text-gray-500 italic">
Not crawled yet.
</p>
)}
{refreshError && (
<p role="alert" className="text-xs text-red-500">
{refreshError}
</p>
)}
</div>
</SectionCard>
<SectionCard
icon={FileClock}
title="Pages"
subtitle={pages.length ? String(pages.length) : undefined}
description="The newest snapshot of each page is what agents retrieve from; older snapshots are kept as a record."
bodyClassName="px-0 py-0"
action={
pages.length > 0 ? (
<div
role="group"
aria-label="Pages view"
className="inline-flex rounded-lg border border-gray-200 dark:border-gray-600 p-0.5"
>
{(
[
["list", "List", List],
["graph", "Link graph", Network],
] as const
).map(([value, label, Icon]) => (
<button
key={value}
type="button"
aria-pressed={pagesView === value}
onClick={() => setPagesView(value)}
className={`flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md transition-colors ${
pagesView === value
? "bg-gray-900 text-white dark:bg-gray-100 dark:text-gray-900"
: "text-gray-600 dark:text-gray-300"
}`}
>
<Icon className="size-3.5" />
{label}
</button>
))}
</div>
) : undefined
}
>
{loadingPages ? (
<div className="px-5 py-4">
<SkeletonLines count={3} />
</div>
) : pages.length === 0 ? (
<p className="px-5 py-4 text-sm text-gray-400 dark:text-gray-500 italic">
{running
? "The first pages will appear here as they are read."
: "No pages stored yet."}
</p>
) : pagesView === "graph" ? (
<WebLinkGraph
knowledgeId={knowledge.id}
pages={pages}
running={running}
onOpenHistory={(page) => setHistoryOf({ page })}
/>
) : (
<ul className="divide-y divide-gray-100 dark:divide-gray-700">
{pages.map((page) => (
<li
key={page.document_id}
className="flex flex-wrap items-center gap-x-4 gap-y-1 px-5 py-3"
>
{/* Full width on a phone, so wrapping the badges and actions
below it never squeezes the title to nothing. */}
<div className="min-w-0 basis-full sm:basis-0 sm:flex-1">
<div className="truncate text-sm font-medium text-gray-800 dark:text-gray-200">
{page.title || page.url}
</div>
<a
href={page.url}
target="_blank"
rel="noopener noreferrer"
className="block truncate text-xs text-gray-400 dark:text-gray-500 hover:underline"
>
{page.url}
</a>
{page.origin === "linked" && page.linked_from?.length ? (
// A deep citation's middle link: read because a crawled
// page points here.
<p className="truncate text-xs text-gray-500 dark:text-gray-400">
Linked from{" "}
{page.linked_from.map((ref, i) => (
<React.Fragment key={ref.url}>
{i > 0 && ", "}
<a
href={ref.url}
target="_blank"
rel="noopener noreferrer"
className="hover:underline"
>
{ref.title || ref.url}
</a>
</React.Fragment>
))}
</p>
) : null}
{page.last_error && page.status !== "active" && (
<p className="truncate text-xs text-red-500" title={page.last_error}>
{page.last_error}
</p>
)}
</div>
{page.origin === "linked" && (
<StatusBadge
status="linked"
scale={PAGE_ORIGIN}
size="xs"
label="Linked page"
/>
)}
<StatusBadge status={page.status} scale={WEB_PAGE_STATUS} size="xs" />
<span
className="whitespace-nowrap text-xs text-gray-500 dark:text-gray-400"
title={exactly(page.last_changed_at)}
>
{/* One version means the text has never changed since the
page was first stored. */}
{page.version_count > 1 ? "Changed" : "First stored"}{" "}
{when(page.last_changed_at)}
</span>
<button
type="button"
onClick={() => setHistoryOf({ page })}
className={buttonClass}
aria-label={`History of ${page.url}`}
>
<History className="size-3.5" />
{page.version_count} version
{page.version_count === 1 ? "" : "s"}
</button>
</li>
))}
</ul>
)}
</SectionCard>
{crawls.length > 1 && (
<SectionCard icon={History} title="Crawl history" bodyClassName="px-0 py-0">
<ul className="divide-y divide-gray-100 dark:divide-gray-700">
{crawls.map((crawl) => (
<li key={crawl.id}>
{/* Opens the source as this crawl left it, against now. */}
<button
type="button"
onClick={() => setCrawlOf(crawl)}
className="flex w-full flex-wrap items-center gap-x-3 gap-y-1 px-5 py-2.5 text-left transition-colors hover:bg-gray-50 dark:hover:bg-gray-700/50"
>
<span
title={crawl.status === "held" ? (crawl.note ?? undefined) : undefined}
>
<StatusBadge status={crawl.status} scale={RUN_STATUS} size="xs" />
</span>
<span
className="text-xs text-gray-700 dark:text-gray-300 w-24"
title={exactly(crawl.started_at)}
>
{when(crawl.started_at)}
</span>
<span className="text-xs text-gray-400 dark:text-gray-500 w-32">
{TRIGGER_LABEL[crawl.trigger] ?? crawl.trigger}
</span>
<CrawlCounts crawl={crawl} />
<span className="ml-auto flex items-center gap-0.5 text-xs text-gray-500 dark:text-gray-400">
View pages
<ChevronRight className="size-3.5" />
</span>
</button>
</li>
))}
</ul>
</SectionCard>
)}
{historyOf ? (
<PageHistoryModal
knowledgeId={knowledge.id}
{...historyOf}
onClose={() => setHistoryOf(null)}
/>
) : (
crawlOf && (
<WebCrawlModal
knowledgeId={knowledge.id}
crawl={crawlOf}
onOpenPage={setHistoryOf}
onClose={() => setCrawlOf(null)}
/>
)
)}
</>
);
};
export default WebKnowledgeSection;
|