@startsimpli/integrations 0.2.203 → 0.2.205

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ /** The Library list: the shared DataTable with the Library's columns. Click a row to open the record. */
2
+ import * as React from 'react';
3
+
4
+ import { formatDate } from '../../documentText';
5
+ import { DataTable } from '../../table';
6
+ import type { DataTableProps } from '../../table';
7
+ import type { SourceDocument } from '../../../corpus/types';
8
+ import { folderCell, typeLabel, whoText } from './library-model';
9
+
10
+ type Shared = Pick<DataTableProps<SourceDocument>, 'sort' | 'onSort' | 'page' | 'pageSize' | 'total' | 'onPage' | 'onPageSize' | 'loading' | 'emptyMessage'>;
11
+
12
+ export function LibraryTable({ rows, onOpen, hidden, ...shared }: { rows: SourceDocument[]; onOpen: (id: string) => void; hidden?: Set<string> } & Shared) {
13
+ return (
14
+ <DataTable<SourceDocument>
15
+ tableId="library"
16
+ rows={rows}
17
+ rowKey={(d) => String(d.id)}
18
+ onRowClick={(d) => onOpen(String(d.id))}
19
+ columns={[
20
+ {
21
+ key: 'title', header: 'Title', className: 'w-full min-w-[8rem] max-w-0',
22
+ render: (d) => (
23
+ <button type="button" onClick={() => onOpen(String(d.id))} className="block w-full truncate text-left font-medium text-gray-900 hover:underline dark:text-gray-100" title={d.title}>
24
+ {d.title}
25
+ </button>
26
+ ),
27
+ },
28
+ { key: 'source', header: 'Source', hideOnPhone: true, className: 'whitespace-nowrap text-gray-700 dark:text-gray-300', render: (d) => d.sourceLabel || d.source },
29
+ {
30
+ key: 'folder', hidden: hidden?.has('folder'), header: 'Folder', hideOnPhone: true, className: 'whitespace-nowrap text-gray-600 dark:text-gray-400',
31
+ render: (d) => { const f = folderCell(d); return <span title={f.full || undefined}>{f.label}</span>; },
32
+ },
33
+ { key: 'type', hidden: hidden?.has('type'), header: 'Type', hideOnPhone: true, className: 'whitespace-nowrap text-gray-600 dark:text-gray-400', render: (d) => typeLabel(d.subtype) },
34
+ { key: 'date', header: 'Date', sortable: true, className: 'whitespace-nowrap text-gray-600 dark:text-gray-400', render: (d) => formatDate(d.occurredAt ?? d.ingestedAt) },
35
+ { key: 'who', hidden: hidden?.has('who'), header: 'Who', hideOnPhone: true, className: 'max-w-[9rem] truncate text-gray-600 dark:text-gray-400', render: (d) => whoText(d.participants) },
36
+ ]}
37
+ {...shared}
38
+ />
39
+ );
40
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * The Library's left tree: "All documents", then one node per connected source with its count.
3
+ * A source shows folders ONLY if it has some: each source's top-level folders are read once
4
+ * (`attr.source`), one source at a time and after the rows, and a source that returns none draws
5
+ * no arrow and no children. Selecting a folder means the folder and everything under it.
6
+ */
7
+ import * as React from 'react';
8
+
9
+ import { FolderTree } from '../../FolderTree';
10
+ import type { FolderSource } from '../../FolderTree';
11
+ import type { SourceFreshness } from '../../../corpus/types';
12
+
13
+ export interface LibrarySelection { source: string | null; folder: string | null }
14
+
15
+ export function LibraryTree({ api, sources, sourcesLoaded, selection, onSelect, hold, onUnavailable }: {
16
+ api: FolderSource;
17
+ sources: SourceFreshness[];
18
+ /** The source list has been read (an empty list before that does not mean there are none). */
19
+ sourcesLoaded: boolean;
20
+ selection: LibrarySelection;
21
+ onSelect: (next: LibrarySelection) => void;
22
+ /** Do not read any folders yet (the rows come first). */
23
+ hold: boolean;
24
+ /** The corpus cannot enumerate folders: the sources stay, the folder rows never appear. */
25
+ onUnavailable?: () => void;
26
+ }) {
27
+ // source key -> how many top-level folders it has, once known. A source is probed only after the one before it.
28
+ const [folders, setFolders] = React.useState<Record<string, number>>({});
29
+ const [open, setOpen] = React.useState<Record<string, boolean>>({});
30
+ const firstUnknown = sources.findIndex((s) => folders[s.source] === undefined);
31
+ const node = 'flex min-w-0 flex-1 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-sm';
32
+ const on = 'bg-gray-100 font-medium text-gray-900 dark:bg-gray-800 dark:text-gray-100';
33
+ const off = 'text-gray-700 hover:bg-gray-50 dark:text-gray-300 dark:hover:bg-gray-800/60';
34
+ const allSelected = !selection.source && !selection.folder;
35
+
36
+ return (
37
+ <nav aria-label="Sources and folders" className="space-y-0.5">
38
+ <button type="button" aria-current={allSelected ? 'true' : undefined} className={`${node} ${allSelected ? on : off}`} onClick={() => onSelect({ source: null, folder: null })}>
39
+ <span className="truncate">All documents</span>
40
+ </button>
41
+ {/* No connected source to hang folders on: the corpus's own top-level folders, so nothing is unreachable. */}
42
+ {sourcesLoaded && sources.length === 0 ? (
43
+ <FolderTree
44
+ api={api}
45
+ showRoot={false}
46
+ selected={selection.folder}
47
+ hold={hold}
48
+ onSelect={(folder) => onSelect({ source: null, folder })}
49
+ onUnavailable={onUnavailable}
50
+ />
51
+ ) : null}
52
+ {sources.map((source, index) => {
53
+ const has = (folders[source.source] ?? 0) > 0;
54
+ const active = selection.source === source.source;
55
+ const expanded = has && (open[source.source] ?? active);
56
+ return (
57
+ <div key={source.source}>
58
+ <div className="flex items-center">
59
+ {has ? (
60
+ <button type="button" aria-expanded={expanded} aria-label={`${expanded ? 'Collapse' : 'Expand'} ${source.label}`} className="w-4 shrink-0 text-xs text-gray-400 hover:text-gray-700"
61
+ onClick={() => setOpen((prev) => ({ ...prev, [source.source]: !expanded }))}>
62
+ {expanded ? '▾' : '▸'}
63
+ </button>
64
+ ) : <span aria-hidden className="w-4 shrink-0" />}
65
+ <button type="button" aria-current={active && !selection.folder ? 'true' : undefined} className={`${node} ${active && !selection.folder ? on : off}`}
66
+ onClick={() => { onSelect({ source: source.source, folder: null }); if (has) setOpen((prev) => ({ ...prev, [source.source]: true })); }}>
67
+ <span className="min-w-0 truncate">{source.label}</span>
68
+ {typeof source.documentCount === 'number' ? <span className="shrink-0 text-xs text-gray-400">{source.documentCount}</span> : null}
69
+ </button>
70
+ </div>
71
+ {/* Always mounted so the one probe happens, hidden until the source is open. */}
72
+ <div hidden={!expanded} className="ml-4">
73
+ <FolderTree
74
+ api={api}
75
+ source={source.source}
76
+ showRoot={false}
77
+ selected={active ? selection.folder : null}
78
+ hold={hold || (firstUnknown !== -1 && index > firstUnknown)}
79
+ onRootLoaded={(count) => setFolders((prev) => (prev[source.source] === count ? prev : { ...prev, [source.source]: count }))}
80
+ onSelect={(folder) => onSelect({ source: source.source, folder })}
81
+ onUnavailable={onUnavailable}
82
+ />
83
+ </div>
84
+ </div>
85
+ );
86
+ })}
87
+ </nav>
88
+ );
89
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * The sources table: one row per connected source. Source, status, records, last sync, next sync,
3
+ * one action. Plain words only: no vendor error text, no pills, no subtitle (bd startsim-c93vd).
4
+ */
5
+ import * as React from 'react';
6
+
7
+ import type { SourceFreshness } from '../../../corpus/types';
8
+
9
+ const STATUS_WORDS: Record<SourceFreshness['status'], string> = {
10
+ ok: 'Up to date',
11
+ stale: 'Stale',
12
+ error: 'Not syncing',
13
+ never: 'Waiting for first sync',
14
+ };
15
+
16
+ const SYNC_WORDS: Record<string, string> = {
17
+ limited: 'Slowed by the provider',
18
+ failing: 'Not syncing',
19
+ reauth: 'Reconnect needed',
20
+ waiting: 'Waiting for first sync',
21
+ };
22
+
23
+ export function statusText(source: SourceFreshness): string {
24
+ const sync = source.sync;
25
+ if (sync?.state === 'passive') return sync.note;
26
+ if (sync && sync.state !== 'ok') return SYNC_WORDS[sync.state] ?? STATUS_WORDS[source.status];
27
+ return STATUS_WORDS[source.status];
28
+ }
29
+
30
+ export function recordsOf(source: SourceFreshness): number | null {
31
+ const counted = source.documentCount;
32
+ if (counted) return counted;
33
+ if (source.sync && source.sync.state !== 'passive' && source.sync.records) return source.sync.records;
34
+ return counted ?? (source.sync ? source.sync.records : null);
35
+ }
36
+
37
+ function ago(value: string | null | undefined, now: number): string {
38
+ const at = value ? Date.parse(value) : NaN;
39
+ if (Number.isNaN(at)) return 'Never';
40
+ const minutes = Math.round((now - at) / 60000);
41
+ if (minutes < 1) return 'Just now';
42
+ if (minutes < 60) return `${minutes} min ago`;
43
+ const hours = Math.round(minutes / 60);
44
+ if (hours < 48) return `${hours}h ago`;
45
+ return `${Math.round(hours / 24)}d ago`;
46
+ }
47
+
48
+ function ahead(value: string | null | undefined, now: number): string {
49
+ const at = value ? Date.parse(value) : NaN;
50
+ if (Number.isNaN(at)) return '—';
51
+ const minutes = Math.round((at - now) / 60000);
52
+ if (minutes <= 1) return 'Within a minute';
53
+ if (minutes < 60) return `In ${minutes} min`;
54
+ const hours = Math.round(minutes / 60);
55
+ return hours < 48 ? `In ${hours}h` : `In ${Math.round(hours / 24)}d`;
56
+ }
57
+
58
+ function lastSyncText(source: SourceFreshness, now: number): string {
59
+ const done = ago(source.lastSyncedAt ?? source.sync?.lastSuccessAt, now);
60
+ const attempt = source.sync?.lastAttemptAt ?? source.lastAttemptAt;
61
+ if (!attempt || done === 'Never' && !attempt) return done;
62
+ const tried = ago(attempt, now);
63
+ return tried === done || source.status === 'ok' && source.sync?.state === 'ok' ? done : `${done} (tried ${tried.toLowerCase()})`;
64
+ }
65
+
66
+ function nextSyncText(source: SourceFreshness, now: number): string {
67
+ const state = source.sync?.state;
68
+ if (state === 'passive') return '—';
69
+ if (state === 'reauth') return 'After you reconnect';
70
+ if (source.sync && !source.sync.nextSyncAt) return 'Not scheduled';
71
+ return ahead(source.sync?.nextSyncAt, now);
72
+ }
73
+
74
+ export function SourcesTable({
75
+ sources, now, onManage, classNames,
76
+ }: {
77
+ sources: SourceFreshness[];
78
+ now: number;
79
+ /** Opens the connection for that source. The action reads "Reconnect" when the account needs it, otherwise "Manage". */
80
+ onManage?: (source: string) => void;
81
+ classNames: { section: string; muted: string };
82
+ }) {
83
+ if (sources.length === 0) return null;
84
+ const th = 'px-3 py-2 text-left text-xs font-medium text-gray-500 dark:text-gray-400';
85
+ const td = 'px-3 py-2 text-sm text-gray-800 dark:text-gray-100';
86
+ return (
87
+ <section className={classNames.section} aria-label="Source freshness">
88
+ <div className="overflow-x-auto rounded-lg border border-gray-200 dark:border-gray-700">
89
+ <table className="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
90
+ <thead>
91
+ <tr>
92
+ <th className={th} scope="col">Source</th>
93
+ <th className={th} scope="col">Status</th>
94
+ <th className={`${th} text-right`} scope="col">Records</th>
95
+ <th className={th} scope="col">Last sync</th>
96
+ <th className={th} scope="col">Next sync</th>
97
+ <th className={th} scope="col"><span className="sr-only">Action</span></th>
98
+ </tr>
99
+ </thead>
100
+ <tbody className="divide-y divide-gray-100 dark:divide-gray-800">
101
+ {sources.map((source) => {
102
+ const records = recordsOf(source);
103
+ const attention = source.sync ? source.sync.state === 'failing' || source.sync.state === 'reauth' : source.status === 'error';
104
+ return (
105
+ <tr key={source.source}>
106
+ <th scope="row" className={`${td} font-medium`}>{source.label}</th>
107
+ <td className={attention ? `${td} font-medium text-amber-700 dark:text-amber-400` : td}>{statusText(source)}</td>
108
+ <td className={`${td} text-right tabular-nums`}>{records === null ? '—' : records}
109
+ {source.sync?.windowDays ? (
110
+ <span className="block text-xs font-normal text-gray-500 dark:text-gray-400">last {source.sync.windowDays} days</span>
111
+ ) : null}
112
+ </td>
113
+ <td className={td}>{lastSyncText(source, now)}</td>
114
+ <td className={td}>{nextSyncText(source, now)}</td>
115
+ <td className={`${td} text-right`}>
116
+ {onManage && source.sync?.state !== 'passive' ? (
117
+ <button
118
+ type="button"
119
+ className="text-sm font-medium text-blue-700 hover:underline dark:text-blue-400"
120
+ onClick={() => onManage(source.source)}
121
+ >
122
+ {source.sync?.state === 'reauth' ? 'Reconnect' : 'Manage'}
123
+ </button>
124
+ ) : null}
125
+ </td>
126
+ </tr>
127
+ );
128
+ })}
129
+ </tbody>
130
+ </table>
131
+ </div>
132
+ </section>
133
+ );
134
+ }
@@ -0,0 +1,86 @@
1
+ /** Pure rules for the Library table: what each column says, and the Type and Date filters. */
2
+ import type { DocumentQuery, PartyRef, SourceDocument } from '../../../corpus/types';
3
+ import type { FilterOption } from '../../table';
4
+ import type { TableSort } from '../../table';
5
+
6
+ const TYPE_WORDS: Record<string, string> = {
7
+ document: 'Document', file: 'File', meeting: 'Meeting', voice_note: 'Voice note', email: 'Email',
8
+ issue: 'Issue', message: 'Message', note: 'Note', call: 'Call', transcript: 'Transcript',
9
+ };
10
+
11
+ /** A friendly word for a subtype the source gave, or the subtype tidied up; a dash when it gave none. */
12
+ export function typeLabel(subtype: string | undefined | null): string {
13
+ if (!subtype) return '—';
14
+ const known = TYPE_WORDS[subtype];
15
+ if (known) return known;
16
+ const words = subtype.replace(/[_-]+/g, ' ').trim();
17
+ return words ? words.charAt(0).toUpperCase() + words.slice(1) : '—';
18
+ }
19
+
20
+ /** Type filter options: "All types" plus the subtypes seen on screen so far (data, not a vendor list). */
21
+ export function typeOptions(seen: string[], active: string | undefined): FilterOption[] {
22
+ const values = Array.from(new Set([...seen, ...(active ? [active] : [])])).filter(Boolean).sort();
23
+ return [{ value: '', label: 'All types' }, ...values.map((value) => ({ value, label: typeLabel(value) }))];
24
+ }
25
+
26
+ export const DATE_FILTERS: FilterOption[] = [
27
+ { value: '', label: 'Any date' },
28
+ { value: '7', label: 'Past 7 days' },
29
+ { value: '30', label: 'Past 30 days' },
30
+ { value: '90', label: 'Past 90 days' },
31
+ { value: 'year', label: 'This year' },
32
+ ];
33
+
34
+ /** The `occurredAfter` instant for a Date option, from an explicit clock. */
35
+ export function dateAfter(key: string, now: number): string | undefined {
36
+ if (!key) return undefined;
37
+ const at = new Date(now);
38
+ if (key === 'year') return `${at.getUTCFullYear()}-01-01T00:00:00Z`;
39
+ const days = Number(key);
40
+ if (!Number.isFinite(days) || days <= 0) return undefined;
41
+ return new Date(now - days * 86_400_000).toISOString();
42
+ }
43
+
44
+ /** Which Date option an `occurredAfter` came from, so the dropdown shows the choice. */
45
+ export function dateKeyOf(after: string | undefined, now: number): string {
46
+ if (!after) return '';
47
+ for (const option of DATE_FILTERS) {
48
+ if (option.value && dateAfter(option.value, now) === after) return option.value;
49
+ }
50
+ return '';
51
+ }
52
+
53
+ /** The Date header sorts by when it happened: newest first or oldest first, always server-side. */
54
+ export function orderOf(sort: TableSort | null): DocumentQuery['order'] {
55
+ if (!sort || sort.key !== 'date') return undefined;
56
+ return sort.dir === 'asc' ? 'oldest' : 'recent';
57
+ }
58
+
59
+ /** "Ada, Grace +2": the people on a record, short. A dash when the source has none. */
60
+ export function whoText(people: PartyRef[]): string {
61
+ const names = people.map((p) => p.name).filter(Boolean);
62
+ if (names.length === 0) return '—';
63
+ if (names.length <= 2) return names.join(', ');
64
+ return `${names.slice(0, 2).join(', ')} +${names.length - 2}`;
65
+ }
66
+
67
+ /** The container shown in the Folder column: its last segment, a dash when the source has no folders. */
68
+ export function folderCell(document: SourceDocument): { label: string; full: string } {
69
+ const full = document.folder ?? '';
70
+ if (!full) return { label: '—', full: '' };
71
+ const segments = full.split('/').filter(Boolean);
72
+ return { label: segments[segments.length - 1] ?? full, full };
73
+ }
74
+
75
+ /**
76
+ * Columns with nothing in them on the loaded page: hidden, never shown as a column of dashes. `Who` waits for the
77
+ * people read (they arrive after the rows) so it does not blink out before they land.
78
+ */
79
+ export function emptyColumns(rows: SourceDocument[], peopleSettled: boolean): Set<string> {
80
+ const out = new Set<string>();
81
+ if (rows.length === 0) return out;
82
+ if (!rows.some((d) => d.subtype)) out.add('type');
83
+ if (!rows.some((d) => d.folder)) out.add('folder');
84
+ if (peopleSettled && !rows.some((d) => d.participants.length > 0)) out.add('who');
85
+ return out;
86
+ }
@@ -20,6 +20,8 @@ export interface DataTableColumn<Row> {
20
20
  className?: string;
21
21
  /** Hide this column under the `md` breakpoint (phones). */
22
22
  hideOnPhone?: boolean;
23
+ /** Drop this column entirely (no header, no cells): a column nothing on the loaded page has a value for is dead weight. */
24
+ hidden?: boolean;
23
25
  /** Visually hide the header text (checkbox and menu columns) while keeping it for screen readers. */
24
26
  srOnlyHeader?: boolean;
25
27
  render: (row: Row) => React.ReactNode;
@@ -52,9 +54,10 @@ export interface DataTableProps<Row> {
52
54
  const hide = (c: { hideOnPhone?: boolean }) => (c.hideOnPhone ? 'hidden md:table-cell' : '');
53
55
 
54
56
  export function DataTable<Row>({
55
- tableId, columns, rows, rowKey, sort, onSort, page = 1, pageSize = 25, total = rows.length, onPage, onPageSize,
57
+ tableId, columns: allColumns, rows, rowKey, sort, onSort, page = 1, pageSize = 25, total = rows.length, onPage, onPageSize,
56
58
  loading, emptyMessage = 'Nothing to show.', rowClassName, topRow, onRowClick,
57
59
  }: DataTableProps<Row>) {
60
+ const columns = allColumns.filter((c) => !c.hidden);
58
61
  return (
59
62
  <div className="w-full min-w-0 max-w-full overflow-hidden rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900" data-testid={`table-${tableId}`}>
60
63
  <div className="overflow-x-auto">
@@ -93,6 +93,7 @@ import type {
93
93
  ListSourcesOptions,
94
94
  PlanningApi,
95
95
  SourceFreshness,
96
+ SourceSync,
96
97
  } from './types';
97
98
 
98
99
  /**
@@ -449,6 +450,7 @@ function facetParams(query: FolderQuery, type: string) {
449
450
  page: query.page ?? 1,
450
451
  };
451
452
  if (query.pageSize) out.page_size = query.pageSize;
453
+ if (query.source) out['attr.source'] = query.source;
452
454
  return out;
453
455
  }
454
456
 
@@ -976,9 +978,14 @@ export function createCorpusApi(
976
978
  const lastError = String(connection.last_error ?? connection.lastError ?? '');
977
979
  const status = connection.status ?? '';
978
980
 
981
+ const sync = readSync(connection);
979
982
  let health: SourceFreshness['status'] = 'ok';
980
983
  let detail = '';
981
- if (error || status === 'error' || status === 'needs_reauth') {
984
+ if (sync?.state === 'limited' || sync?.state === 'passive') {
985
+ // The provider is pacing us and the run resumes by itself, or the source only receives
986
+ // data: neither is a failure, and neither carries vendor text.
987
+ if (sync.state === 'limited' && !lastSyncedAt && !sync.records) health = 'never';
988
+ } else if (error || status === 'error' || status === 'needs_reauth') {
982
989
  health = 'error';
983
990
  detail = error || `Connection status is ${String(status)}.`;
984
991
  } else if (failures > 0 || lastError || (lastAttemptAt && !lastSyncedAt)) {
@@ -1041,12 +1048,30 @@ export function createCorpusApi(
1041
1048
  // that wants the reason on its own — a tooltip, a copy button, the
1042
1049
  // control plane's card — does not have to unpick a composed sentence.
1043
1050
  ...(lastError ? { lastError } : {}),
1051
+ ...(sync ? { sync } : {}),
1044
1052
  };
1045
1053
  });
1046
1054
  },
1047
1055
  };
1048
1056
  }
1049
1057
 
1058
+ function readSync(connection: Record<string, unknown>): SourceSync | undefined {
1059
+ const raw = connection.sync as Record<string, unknown> | undefined;
1060
+ if (!raw || typeof raw !== 'object') return undefined;
1061
+ const pick = (snake: string, camel: string) => raw[snake] ?? raw[camel];
1062
+ const text = (v: unknown) => (typeof v === 'string' && v ? v : null);
1063
+ return {
1064
+ state: (String(raw.state ?? 'waiting') as SourceSync['state']),
1065
+ note: String(raw.note ?? ''),
1066
+ records: Number(raw.records ?? 0) || 0,
1067
+ lastAttemptAt: text(pick('last_attempt_at', 'lastAttemptAt')),
1068
+ lastSuccessAt: text(pick('last_success_at', 'lastSuccessAt')),
1069
+ nextSyncAt: text(pick('next_sync_at', 'nextSyncAt')),
1070
+ intervalMinutes: (pick('interval_minutes', 'intervalMinutes') as number | null) ?? null,
1071
+ windowDays: (pick('window_days', 'windowDays') as number | null) ?? null,
1072
+ };
1073
+ }
1074
+
1050
1075
  /**
1051
1076
  * `data` key -> the `FocusDraft` key that carries it.
1052
1077
  *
@@ -1077,7 +1077,9 @@ function facetRead(rows: TenantEntity[], params: Record<string, unknown>) {
1077
1077
  );
1078
1078
  }
1079
1079
  const type = params.type ? String(params.type) : '';
1080
+ const bySource = params['attr.source'] ? String(params['attr.source']) : '';
1080
1081
  const scoped = (type ? rows.filter((entity) => entity.entity_type === type) : rows)
1082
+ .filter((entity) => !bySource || (entity.data as Record<string, unknown> | undefined)?.source === bySource)
1081
1083
  .filter((entity) => {
1082
1084
  const value = (entity.data as Record<string, unknown> | undefined)?.[attribute];
1083
1085
  return typeof value === 'string' && value !== '';
@@ -1092,7 +1094,7 @@ function facetRead(rows: TenantEntity[], params: Record<string, unknown>) {
1092
1094
  const results = [...flat]
1093
1095
  .map(([value, count]) => ({ value, count }))
1094
1096
  .sort((a, b) => a.value.localeCompare(b.value));
1095
- return { ...slicePage(results, params), applied_filters: ['attr'] };
1097
+ return { ...slicePage(results, params), applied_filters: bySource ? ['attr', 'attr.source'] : ['attr'] };
1096
1098
  }
1097
1099
 
1098
1100
  const [self, descendants] = subtreeBound(params.under);
@@ -1115,7 +1117,7 @@ function facetRead(rows: TenantEntity[], params: Record<string, unknown>) {
1115
1117
  const results = [...groups]
1116
1118
  .map(([value, at]) => ({ value, count: at.count, has_children: at.deeper }))
1117
1119
  .sort((a, b) => a.value.localeCompare(b.value));
1118
- return { ...slicePage(results, params), applied_filters: ['attr', 'under'] };
1120
+ return { ...slicePage(results, params), applied_filters: bySource ? ['attr', 'attr.source', 'under'] : ['attr', 'under'] };
1119
1121
  }
1120
1122
 
1121
1123
  /** The same DRF envelope `slice()` builds, outside the closure that owns it. */
@@ -190,6 +190,19 @@ export interface MoneyEvent {
190
190
  * A corpus silently four days stale is what makes an AI answer confidently
191
191
  * wrong, so the Library states it per source and the Ask surface repeats it.
192
192
  */
193
+ export interface SourceSync {
194
+ state: 'ok' | 'limited' | 'failing' | 'reauth' | 'waiting' | 'passive';
195
+ /** One sentence the server wrote; '' when there is nothing to add. */
196
+ note: string;
197
+ records: number;
198
+ lastAttemptAt: string | null;
199
+ lastSuccessAt: string | null;
200
+ nextSyncAt: string | null;
201
+ intervalMinutes: number | null;
202
+ /** How far back this mailbox source reads (days); null for a source with no window. */
203
+ windowDays?: number | null;
204
+ }
205
+
193
206
  export interface SourceFreshness {
194
207
  source: SourceKey;
195
208
  label: string;
@@ -234,6 +247,12 @@ export interface SourceFreshness {
234
247
  lastCheckedAt?: string | null;
235
248
  /** How many syncs in a row have failed. `0` (or absent) means none. */
236
249
  consecutiveFailures?: number;
250
+ /**
251
+ * The server's own plain-language row for the sources table (state, a sentence, records,
252
+ * last attempt, next sync). Absent on a central that predates it; the table then falls back
253
+ * to `status`. Never carries vendor error text.
254
+ */
255
+ sync?: SourceSync;
237
256
  /**
238
257
  * `ok` — synced recently and cleanly.
239
258
  * `stale` — the last sync succeeded but was long enough ago to matter.
@@ -385,6 +404,8 @@ export interface CorpusFolder {
385
404
  */
386
405
  export interface FolderQuery {
387
406
  under: string;
407
+ /** Only the folders of ONE source (goes out as `attr.source`); the facet read honours it. */
408
+ source?: string;
388
409
  page?: number;
389
410
  pageSize?: number;
390
411
  }