@startsimpli/integrations 0.2.202 → 0.2.204
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.
- package/package.json +5 -5
- package/src/__tests__/corpus-freshness.test.tsx +3 -3
- package/src/__tests__/corpus-pages.test.tsx +5 -4
- package/src/__tests__/corpus-source-strip.test.tsx +5 -4
- package/src/__tests__/library-failure-reason.test.tsx +5 -4
- package/src/__tests__/sources-table.test.tsx +86 -0
- package/src/components/pages/LibraryPage.tsx +6 -89
- package/src/components/pages/library/SourcesTable.tsx +134 -0
- package/src/corpus/client.ts +25 -1
- package/src/corpus/types.ts +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.204",
|
|
4
4
|
"description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://startsimpli.com",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"react-native": ">=0.74.0",
|
|
51
51
|
"@startsimpli/ui-native": ">=0.1.12",
|
|
52
52
|
"react-native-safe-area-context": ">=4.0.0",
|
|
53
|
+
"@startsimpli/auth": "^0.4.57",
|
|
53
54
|
"@startsimpli/utils": "^0.4.21",
|
|
54
|
-
"@startsimpli/ui": "^0.4.
|
|
55
|
-
"@startsimpli/auth": "^0.4.55"
|
|
55
|
+
"@startsimpli/ui": "^0.4.195"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"react": {
|
|
@@ -99,9 +99,9 @@
|
|
|
99
99
|
"react-native": "0.85.3",
|
|
100
100
|
"react-native-safe-area-context": "~5.7.0",
|
|
101
101
|
"@startsimpli/llm": "0.4.31",
|
|
102
|
-
"@startsimpli/ui": "0.4.
|
|
102
|
+
"@startsimpli/ui": "0.4.195",
|
|
103
103
|
"@startsimpli/ui-native": "0.1.15",
|
|
104
|
-
"@startsimpli/auth": "0.4.
|
|
104
|
+
"@startsimpli/auth": "0.4.57",
|
|
105
105
|
"@startsimpli/utils": "0.4.21"
|
|
106
106
|
},
|
|
107
107
|
"scripts": {
|
|
@@ -236,8 +236,8 @@ describe('the Library strip, rendered', () => {
|
|
|
236
236
|
|
|
237
237
|
render(<LibraryPage api={api} scope={SCOPE} />);
|
|
238
238
|
|
|
239
|
-
expect(await screen.
|
|
240
|
-
expect(screen.
|
|
241
|
-
expect(screen.queryByText(/
|
|
239
|
+
expect(await screen.findByRole('cell', { name: 'Waiting for first sync' })).toBeInTheDocument();
|
|
240
|
+
expect(screen.getByRole('cell', { name: 'Never' })).toBeInTheDocument();
|
|
241
|
+
expect(screen.queryByText(/just now|\d+ min ago/)).not.toBeInTheDocument();
|
|
242
242
|
});
|
|
243
243
|
});
|
|
@@ -81,8 +81,8 @@ describe('LibraryPage — the only connected source is Dropbox', () => {
|
|
|
81
81
|
expect(screen.getByRole('option', { name: 'Dropbox' })).toBeInTheDocument();
|
|
82
82
|
|
|
83
83
|
// Freshness is on the screen, and says the uncomfortable thing.
|
|
84
|
-
expect(screen.
|
|
85
|
-
expect(screen.
|
|
84
|
+
expect(screen.getByRole('cell', { name: 'Stale' })).toBeInTheDocument();
|
|
85
|
+
expect(screen.getByRole('cell', { name: /\d+[hd] ago/ })).toBeInTheDocument();
|
|
86
86
|
|
|
87
87
|
// Nothing in the chrome assumes a meeting.
|
|
88
88
|
expect(screen.queryByText(/transcript/i)).not.toBeInTheDocument();
|
|
@@ -235,8 +235,9 @@ describe('LibraryPage — the nothings', () => {
|
|
|
235
235
|
}],
|
|
236
236
|
});
|
|
237
237
|
render(<LibraryPage api={api} scope={SCOPE} />);
|
|
238
|
-
// "No results" would send the user to the wrong place entirely.
|
|
239
|
-
expect(await screen.
|
|
238
|
+
// "No results" would send the user to the wrong place entirely: the table names the source and says it is not syncing.
|
|
239
|
+
expect(await screen.findByRole('cell', { name: 'Not syncing' })).toBeInTheDocument();
|
|
240
|
+
expect(screen.getByRole('rowheader', { name: 'Google Drive' })).toBeInTheDocument();
|
|
240
241
|
});
|
|
241
242
|
|
|
242
243
|
it('renders a record that arrived with no text at all', async () => {
|
|
@@ -445,14 +445,14 @@ describe('the Library strip, counting', () => {
|
|
|
445
445
|
const { http } = corpusOver([SHARED_GRANOLA, SHARED_N8N], TANDEM_COUNTS);
|
|
446
446
|
render(<LibraryPage api={createCorpusApi({ http, scope: SCOPE })} scope={SCOPE} />);
|
|
447
447
|
|
|
448
|
-
expect((await strip()).
|
|
448
|
+
expect((await strip()).getByRole('cell', { name: '208' })).toBeInTheDocument();
|
|
449
449
|
});
|
|
450
450
|
|
|
451
451
|
it('says a source has delivered nothing, in words', async () => {
|
|
452
452
|
const { http } = corpusOver([SHARED_GRANOLA, SHARED_N8N], TANDEM_COUNTS);
|
|
453
453
|
render(<LibraryPage api={createCorpusApi({ http, scope: SCOPE })} scope={SCOPE} />);
|
|
454
454
|
|
|
455
|
-
expect((await strip()).
|
|
455
|
+
expect((await strip()).getByRole('cell', { name: '0' })).toBeInTheDocument();
|
|
456
456
|
});
|
|
457
457
|
|
|
458
458
|
it('prints no number at all when the count is unknown', async () => {
|
|
@@ -462,7 +462,8 @@ describe('the Library strip, counting', () => {
|
|
|
462
462
|
const shown = await strip();
|
|
463
463
|
// The freshness half of the card is unaffected — a count it could not get
|
|
464
464
|
// costs the reader the count, not the sentence.
|
|
465
|
-
expect(shown.
|
|
466
|
-
expect(shown.
|
|
465
|
+
expect(shown.getByRole('columnheader', { name: 'Last sync' })).toBeInTheDocument();
|
|
466
|
+
expect(shown.queryByRole('cell', { name: '208' })).not.toBeInTheDocument();
|
|
467
|
+
expect(shown.getAllByRole('cell', { name: '—' }).length).toBeGreaterThan(0);
|
|
467
468
|
});
|
|
468
469
|
});
|
|
@@ -163,9 +163,9 @@ describe('listSources — the strip carries the reason central sends', () => {
|
|
|
163
163
|
});
|
|
164
164
|
|
|
165
165
|
describe('the Library strip, rendered', () => {
|
|
166
|
-
it('
|
|
167
|
-
// The
|
|
168
|
-
//
|
|
166
|
+
it('says a failing source is not syncing in plain words and never prints the vendor text', async () => {
|
|
167
|
+
// The adapter still carries `lastError` for any surface that wants it, but the sources table
|
|
168
|
+
// is for reading at a glance: plain words, no raw error (bd startsim-c93vd).
|
|
169
169
|
render(
|
|
170
170
|
<LibraryPage
|
|
171
171
|
api={createCorpusApi({ http: httpOver([TANDEM_GRANOLA]), scope: SCOPE })}
|
|
@@ -173,6 +173,7 @@ describe('the Library strip, rendered', () => {
|
|
|
173
173
|
/>,
|
|
174
174
|
);
|
|
175
175
|
|
|
176
|
-
expect(await screen.
|
|
176
|
+
expect(await screen.findByRole('cell', { name: 'Not syncing' })).toBeInTheDocument();
|
|
177
|
+
expect(screen.queryByText(/262144-byte cap/)).not.toBeInTheDocument();
|
|
177
178
|
});
|
|
178
179
|
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { fireEvent, render, screen, within } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { SourcesTable } from '../components/pages/library/SourcesTable';
|
|
5
|
+
import type { SourceFreshness } from '../corpus/types';
|
|
6
|
+
|
|
7
|
+
const NOW = Date.parse('2026-11-20T12:00:00Z');
|
|
8
|
+
const mins = (m: number) => new Date(NOW + m * 60_000).toISOString();
|
|
9
|
+
const cls = { section: '', muted: '' };
|
|
10
|
+
|
|
11
|
+
function row(over: Partial<SourceFreshness> & { source: string; label: string }): SourceFreshness {
|
|
12
|
+
return { documentCount: null, lastSyncedAt: null, status: 'ok', ...over };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function renderTable(sources: SourceFreshness[], onManage = vi.fn()) {
|
|
16
|
+
render(<SourcesTable sources={sources} now={NOW} onManage={onManage} classNames={cls} />);
|
|
17
|
+
return onManage;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('SourcesTable', () => {
|
|
21
|
+
it('a throttled Gmail reads as slowed, with records, last attempt and a retry time, and no vendor text', () => {
|
|
22
|
+
renderTable([row({
|
|
23
|
+
source: 'google', label: 'Google', documentCount: null, status: 'ok', lastSyncedAt: mins(-30),
|
|
24
|
+
sync: { state: 'limited', note: 'The provider is limiting requests; it resumes on its own', records: 72,
|
|
25
|
+
lastAttemptAt: mins(-2), lastSuccessAt: mins(-30), nextSyncAt: mins(9), intervalMinutes: 10 },
|
|
26
|
+
})]);
|
|
27
|
+
const r = within(screen.getByRole('row', { name: /Google/ }));
|
|
28
|
+
expect(r.getByRole('cell', { name: 'Slowed by the provider' })).toBeInTheDocument();
|
|
29
|
+
expect(r.getByRole('cell', { name: '72' })).toBeInTheDocument();
|
|
30
|
+
expect(r.getByRole('cell', { name: /30 min ago \(tried 2 min ago\)/ })).toBeInTheDocument();
|
|
31
|
+
expect(r.getByRole('cell', { name: 'In 9 min' })).toBeInTheDocument();
|
|
32
|
+
expect(screen.queryByText(/Quota|403|rate_limited/)).not.toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('a source that only receives data says so plainly and has no action', () => {
|
|
36
|
+
renderTable([row({
|
|
37
|
+
source: 'n8n', label: 'n8n',
|
|
38
|
+
sync: { state: 'passive', note: 'Receives data only when one of your workflows sends it; nothing sent yet',
|
|
39
|
+
records: 0, lastAttemptAt: null, lastSuccessAt: null, nextSyncAt: null, intervalMinutes: null },
|
|
40
|
+
})]);
|
|
41
|
+
const r = within(screen.getByRole('row', { name: /n8n/ }));
|
|
42
|
+
expect(r.getByRole('cell', { name: /Receives data only when one of your workflows sends it; nothing sent yet/ })).toBeInTheDocument();
|
|
43
|
+
expect(r.queryByRole('button')).not.toBeInTheDocument();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('a task tracker shows the number of to-dos synced when the corpus holds no documents', () => {
|
|
47
|
+
renderTable([row({
|
|
48
|
+
source: 'linear', label: 'Linear', documentCount: 0, lastSyncedAt: mins(-5),
|
|
49
|
+
sync: { state: 'ok', note: '', records: 41, lastAttemptAt: mins(-5), lastSuccessAt: mins(-5), nextSyncAt: mins(5), intervalMinutes: 10 },
|
|
50
|
+
})]);
|
|
51
|
+
expect(within(screen.getByRole('row', { name: /Linear/ })).getByRole('cell', { name: '41' })).toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('a source needing a new sign-in offers Reconnect, and the action reports which source', () => {
|
|
55
|
+
const onManage = renderTable([row({
|
|
56
|
+
source: 'microsoft', label: 'Microsoft', status: 'error',
|
|
57
|
+
sync: { state: 'reauth', note: 'Reconnect this account to resume syncing', records: 1218, lastAttemptAt: null,
|
|
58
|
+
lastSuccessAt: mins(-60 * 24), nextSyncAt: null, intervalMinutes: 60 },
|
|
59
|
+
})]);
|
|
60
|
+
fireEvent.click(screen.getByRole('button', { name: 'Reconnect' }));
|
|
61
|
+
expect(onManage).toHaveBeenCalledWith('microsoft');
|
|
62
|
+
expect(screen.getByRole('cell', { name: 'After you reconnect' })).toBeInTheDocument();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('a source with no schedule says Not scheduled instead of a blank', () => {
|
|
66
|
+
renderTable([row({
|
|
67
|
+
source: 'google', label: 'Google',
|
|
68
|
+
sync: { state: 'waiting', note: '', records: 0, lastAttemptAt: null, lastSuccessAt: null, nextSyncAt: null, intervalMinutes: null },
|
|
69
|
+
})]);
|
|
70
|
+
expect(screen.getByRole('cell', { name: 'Not scheduled' })).toBeInTheDocument();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('a mailbox source shows its window under the record count', () => {
|
|
74
|
+
renderTable([row({
|
|
75
|
+
source: 'google', label: 'Google', documentCount: 72,
|
|
76
|
+
sync: { state: 'ok', note: '', records: 72, lastAttemptAt: mins(-1), lastSuccessAt: mins(-1), nextSyncAt: mins(9), intervalMinutes: 10, windowDays: 14 },
|
|
77
|
+
})]);
|
|
78
|
+
expect(within(screen.getByRole('row', { name: /Google/ })).getByText('last 14 days')).toBeInTheDocument();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('has exactly the six columns and no pills or subtitles', () => {
|
|
82
|
+
renderTable([row({ source: 'dropbox', label: 'Dropbox', documentCount: 37, lastSyncedAt: mins(-60) })]);
|
|
83
|
+
expect(screen.getAllByRole('columnheader').map((h) => h.textContent)).toEqual(
|
|
84
|
+
['Source', 'Status', 'Records', 'Last sync', 'Next sync', 'Action']);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
import * as React from 'react';
|
|
29
29
|
|
|
30
30
|
import { LoadError } from '../LoadError';
|
|
31
|
+
import { SourcesTable } from './library/SourcesTable';
|
|
31
32
|
|
|
32
33
|
import { DocumentDetail } from '../DocumentDetail';
|
|
33
34
|
import { formatDate, summaryOf } from '../documentText';
|
|
@@ -80,6 +81,8 @@ export interface LibraryPageProps {
|
|
|
80
81
|
*/
|
|
81
82
|
onRequestText?: (document: SourceDocument) => void | Promise<void>;
|
|
82
83
|
pageSize?: number;
|
|
84
|
+
/** Opens the connection behind a source row (its Reconnect / Manage action). Omit to show no action. */
|
|
85
|
+
onManageSource?: (source: string) => void;
|
|
83
86
|
classNames?: Partial<Record<LibrarySlot, string>>;
|
|
84
87
|
/** Theme slots for the folder tree, passed straight through. */
|
|
85
88
|
folderClassNames?: Partial<Record<FolderTreeSlot, string>>;
|
|
@@ -112,18 +115,6 @@ const DEFAULTS: Record<LibrarySlot, string> = {
|
|
|
112
115
|
warning: 'rounded-md border border-amber-300 bg-amber-50 p-2 text-sm text-amber-800',
|
|
113
116
|
};
|
|
114
117
|
|
|
115
|
-
function relative(value: string | null | undefined, now: number): string {
|
|
116
|
-
if (!value) return 'never';
|
|
117
|
-
const at = Date.parse(value);
|
|
118
|
-
if (Number.isNaN(at)) return 'never';
|
|
119
|
-
const minutes = Math.round((now - at) / 60000);
|
|
120
|
-
if (minutes < 1) return 'just now';
|
|
121
|
-
if (minutes < 60) return `${minutes} min ago`;
|
|
122
|
-
const hours = Math.round(minutes / 60);
|
|
123
|
-
if (hours < 48) return `${hours}h ago`;
|
|
124
|
-
return `${Math.round(hours / 24)}d ago`;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
118
|
// ---------------------------------------------------------------------------
|
|
128
119
|
|
|
129
120
|
export function LibraryPage({
|
|
@@ -135,6 +126,7 @@ export function LibraryPage({
|
|
|
135
126
|
initialFolder,
|
|
136
127
|
onSelectFolder,
|
|
137
128
|
onRequestText,
|
|
129
|
+
onManageSource,
|
|
138
130
|
pageSize = 20,
|
|
139
131
|
classNames = {},
|
|
140
132
|
folderClassNames = {},
|
|
@@ -391,7 +383,7 @@ export function LibraryPage({
|
|
|
391
383
|
|
|
392
384
|
return (
|
|
393
385
|
<div className={cn.root}>
|
|
394
|
-
<
|
|
386
|
+
<SourcesTable sources={shownSources} now={now} onManage={onManageSource} classNames={cn} />
|
|
395
387
|
|
|
396
388
|
<section className={cn.section}>
|
|
397
389
|
<form
|
|
@@ -791,72 +783,6 @@ function GetTextButton({
|
|
|
791
783
|
);
|
|
792
784
|
}
|
|
793
785
|
|
|
794
|
-
// ---------------------------------------------------------------------------
|
|
795
|
-
// freshness
|
|
796
|
-
// ---------------------------------------------------------------------------
|
|
797
|
-
|
|
798
|
-
const FRESHNESS_WORDS: Record<SourceFreshness['status'], string> = {
|
|
799
|
-
ok: 'Up to date',
|
|
800
|
-
stale: 'Stale',
|
|
801
|
-
error: 'Failing',
|
|
802
|
-
never: 'Nothing yet',
|
|
803
|
-
};
|
|
804
|
-
|
|
805
|
-
/**
|
|
806
|
-
* The count clause of a source card, or nothing at all (bd startsim-jevtu).
|
|
807
|
-
*
|
|
808
|
-
* THREE STATES, NOT TWO. `null` is "this workspace's API could not narrow the
|
|
809
|
-
* corpus by source, so the only number available describes every source at
|
|
810
|
-
* once" — printing it would put the same total on every card, which is the
|
|
811
|
-
* failure this replaced wearing a bigger number. Saying nothing is the honest
|
|
812
|
-
* option, and it costs the reader the count rather than the card.
|
|
813
|
-
*
|
|
814
|
-
* `0` is spelled out in words rather than left as a bare digit because "0
|
|
815
|
-
* records" is exactly what the broken version printed for years; a source that
|
|
816
|
-
* has genuinely delivered nothing deserves a sentence that could not be
|
|
817
|
-
* produced by not asking.
|
|
818
|
-
*
|
|
819
|
-
* NOTE THE SCOPE. This is the source's WHOLE contribution, unfiltered — the
|
|
820
|
-
* strip describes sources, while the list beneath it answers the current query.
|
|
821
|
-
* A card reading "208 records" above a list reading "3 records" under an active
|
|
822
|
-
* search is the two questions being different, not a disagreement.
|
|
823
|
-
*/
|
|
824
|
-
function countClause(count: SourceFreshness['documentCount']): string {
|
|
825
|
-
if (count === null || count === undefined) return '';
|
|
826
|
-
if (count === 0) return 'No records yet · ';
|
|
827
|
-
return `${count} record${count === 1 ? '' : 's'} · `;
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
function FreshnessStrip({
|
|
831
|
-
sources, classNames: cn, now,
|
|
832
|
-
}: { sources: SourceFreshness[]; classNames: Record<LibrarySlot, string>; now: number }) {
|
|
833
|
-
if (sources.length === 0) return null;
|
|
834
|
-
return (
|
|
835
|
-
<section className={cn.section} aria-label="Source freshness">
|
|
836
|
-
<div className="flex flex-wrap gap-2">
|
|
837
|
-
{sources.map((source) => (
|
|
838
|
-
<div key={source.source} className={cn.card}>
|
|
839
|
-
<div className="flex items-center gap-2">
|
|
840
|
-
<span className={cn.badge}>{source.label}</span>
|
|
841
|
-
<span
|
|
842
|
-
className={source.status === 'ok' ? 'text-xs text-gray-500' : 'text-xs font-medium text-amber-700'}
|
|
843
|
-
>
|
|
844
|
-
{FRESHNESS_WORDS[source.status]}
|
|
845
|
-
</span>
|
|
846
|
-
</div>
|
|
847
|
-
<p className={cn.muted}>
|
|
848
|
-
{countClause(source.documentCount)}synced {relative(source.lastSyncedAt, now)}
|
|
849
|
-
</p>
|
|
850
|
-
{/* A source that is failing says so HERE, next to the corpus it is
|
|
851
|
-
supposed to be filling — not on a settings page nobody opens. */}
|
|
852
|
-
{source.detail ? <p className="text-xs text-amber-700">{source.detail}</p> : null}
|
|
853
|
-
</div>
|
|
854
|
-
))}
|
|
855
|
-
</div>
|
|
856
|
-
</section>
|
|
857
|
-
);
|
|
858
|
-
}
|
|
859
|
-
|
|
860
786
|
// ---------------------------------------------------------------------------
|
|
861
787
|
// empty state
|
|
862
788
|
// ---------------------------------------------------------------------------
|
|
@@ -880,14 +806,5 @@ function EmptyState({
|
|
|
880
806
|
</p>
|
|
881
807
|
);
|
|
882
808
|
}
|
|
883
|
-
|
|
884
|
-
if (failing.length) {
|
|
885
|
-
return (
|
|
886
|
-
<p className={cn.warning} role="status">
|
|
887
|
-
Nothing has arrived yet, and {failing.map((source) => source.label).join(', ')}{' '}
|
|
888
|
-
{failing.length === 1 ? 'is' : 'are'} failing to sync.
|
|
889
|
-
</p>
|
|
890
|
-
);
|
|
891
|
-
}
|
|
892
|
-
return <p className={cn.muted}>Your sources are connected but have not delivered any records yet.</p>;
|
|
809
|
+
return <p className={cn.muted}>Nothing has arrived yet. The table above shows when each source syncs next.</p>;
|
|
893
810
|
}
|
|
@@ -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
|
+
}
|
package/src/corpus/client.ts
CHANGED
|
@@ -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
|
/**
|
|
@@ -976,9 +977,14 @@ export function createCorpusApi(
|
|
|
976
977
|
const lastError = String(connection.last_error ?? connection.lastError ?? '');
|
|
977
978
|
const status = connection.status ?? '';
|
|
978
979
|
|
|
980
|
+
const sync = readSync(connection);
|
|
979
981
|
let health: SourceFreshness['status'] = 'ok';
|
|
980
982
|
let detail = '';
|
|
981
|
-
if (
|
|
983
|
+
if (sync?.state === 'limited' || sync?.state === 'passive') {
|
|
984
|
+
// The provider is pacing us and the run resumes by itself, or the source only receives
|
|
985
|
+
// data: neither is a failure, and neither carries vendor text.
|
|
986
|
+
if (sync.state === 'limited' && !lastSyncedAt && !sync.records) health = 'never';
|
|
987
|
+
} else if (error || status === 'error' || status === 'needs_reauth') {
|
|
982
988
|
health = 'error';
|
|
983
989
|
detail = error || `Connection status is ${String(status)}.`;
|
|
984
990
|
} else if (failures > 0 || lastError || (lastAttemptAt && !lastSyncedAt)) {
|
|
@@ -1041,12 +1047,30 @@ export function createCorpusApi(
|
|
|
1041
1047
|
// that wants the reason on its own — a tooltip, a copy button, the
|
|
1042
1048
|
// control plane's card — does not have to unpick a composed sentence.
|
|
1043
1049
|
...(lastError ? { lastError } : {}),
|
|
1050
|
+
...(sync ? { sync } : {}),
|
|
1044
1051
|
};
|
|
1045
1052
|
});
|
|
1046
1053
|
},
|
|
1047
1054
|
};
|
|
1048
1055
|
}
|
|
1049
1056
|
|
|
1057
|
+
function readSync(connection: Record<string, unknown>): SourceSync | undefined {
|
|
1058
|
+
const raw = connection.sync as Record<string, unknown> | undefined;
|
|
1059
|
+
if (!raw || typeof raw !== 'object') return undefined;
|
|
1060
|
+
const pick = (snake: string, camel: string) => raw[snake] ?? raw[camel];
|
|
1061
|
+
const text = (v: unknown) => (typeof v === 'string' && v ? v : null);
|
|
1062
|
+
return {
|
|
1063
|
+
state: (String(raw.state ?? 'waiting') as SourceSync['state']),
|
|
1064
|
+
note: String(raw.note ?? ''),
|
|
1065
|
+
records: Number(raw.records ?? 0) || 0,
|
|
1066
|
+
lastAttemptAt: text(pick('last_attempt_at', 'lastAttemptAt')),
|
|
1067
|
+
lastSuccessAt: text(pick('last_success_at', 'lastSuccessAt')),
|
|
1068
|
+
nextSyncAt: text(pick('next_sync_at', 'nextSyncAt')),
|
|
1069
|
+
intervalMinutes: (pick('interval_minutes', 'intervalMinutes') as number | null) ?? null,
|
|
1070
|
+
windowDays: (pick('window_days', 'windowDays') as number | null) ?? null,
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1050
1074
|
/**
|
|
1051
1075
|
* `data` key -> the `FocusDraft` key that carries it.
|
|
1052
1076
|
*
|
package/src/corpus/types.ts
CHANGED
|
@@ -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.
|