@startsimpli/integrations 0.2.219 → 0.2.220
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 +1 -1
- package/src/__tests__/briefing-cold-latency.test.ts +57 -0
- package/src/__tests__/connections-progressive-load.test.tsx +120 -0
- package/src/__tests__/connections-sources-table.test.tsx +29 -0
- package/src/components/pages/ConnectionsPage.tsx +55 -23
- package/src/components/pages/library/SourcesTable.tsx +17 -1
- package/src/corpus/briefing/generate.ts +10 -3
- package/src/corpus/briefing/zone.ts +6 -6
- package/src/corpus/types.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.220",
|
|
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",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { generateBriefing, type BriefingDeps, type BriefingItem } from '../corpus/briefing';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* startsim-nghko.40: a cold first briefing (no zone sent, none remembered) spent its
|
|
7
|
+
* time in serial tenant round trips BEFORE any model call: up to 5 sequential
|
|
8
|
+
* remembered-zone lookups, then loadItems, then unsureCount, then the cache find.
|
|
9
|
+
* Every tenant call here costs LATENCY ms; the independent ones must overlap.
|
|
10
|
+
*/
|
|
11
|
+
const LATENCY = 100;
|
|
12
|
+
const NOW = Date.parse('2026-11-05T14:00:00Z');
|
|
13
|
+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
14
|
+
const item: BriefingItem = { id: 'a', title: 'Do a', status: 'open', ownerSub: 'me', dueAt: '2026-11-05', priority: 2 };
|
|
15
|
+
|
|
16
|
+
function coldDeps(): { deps: BriefingDeps; gets: ReturnType<typeof vi.fn> } {
|
|
17
|
+
const gets = vi.fn(async () => { await sleep(LATENCY); return { results: [] }; });
|
|
18
|
+
const deps: BriefingDeps = {
|
|
19
|
+
http: { get: gets, post: vi.fn(async (_p: string, body: any) => { await sleep(LATENCY); return { id: 1, ...body }; }) } as never,
|
|
20
|
+
orgId: 'org',
|
|
21
|
+
ownerSub: 'me',
|
|
22
|
+
loadItems: async () => { await sleep(LATENCY); return [item]; },
|
|
23
|
+
unsureCount: async () => { await sleep(LATENCY); return 0; },
|
|
24
|
+
synthesize: async () => ({ audio: new Uint8Array([1]), mimeType: 'audio/mpeg', model: 'm', provider: 'p', usage: {} }),
|
|
25
|
+
scriptLlm: null,
|
|
26
|
+
audio: { put: async () => 's3://x', url: async () => 'https://signed.example/x' },
|
|
27
|
+
now: () => NOW,
|
|
28
|
+
name: 'Quinn',
|
|
29
|
+
};
|
|
30
|
+
return { deps, gets };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('briefing cold-path latency', () => {
|
|
34
|
+
it('overlaps the independent tenant reads: before the script, a cold call costs ~3 round trips, not ~8', async () => {
|
|
35
|
+
const { deps } = coldDeps();
|
|
36
|
+
const started = Date.now();
|
|
37
|
+
await generateBriefing(deps, {});
|
|
38
|
+
const elapsed = Date.now() - started;
|
|
39
|
+
// reads: (zone x5 | items | unsure) in parallel, then the cache find; then save + nothing else serial.
|
|
40
|
+
// 3 reads-phases + 1 save = 4 round trips = ~400ms. Serial was 8 reads + 1 save = ~900ms.
|
|
41
|
+
expect(elapsed).toBeLessThan(LATENCY * 5.5);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('still falls back to UTC-free behaviour: a remembered zone from the nearest day wins', async () => {
|
|
45
|
+
const { deps, gets } = coldDeps();
|
|
46
|
+
gets.mockImplementation(async (_p: string, o: any) => {
|
|
47
|
+
await sleep(5);
|
|
48
|
+
const ext = String(o?.params?.external_id__in ?? '');
|
|
49
|
+
// only the day before `now` (UTC) has a stored row, in Tokyo
|
|
50
|
+
return ext.includes('2026-11-04')
|
|
51
|
+
? { results: [{ id: 9, external_id: ext, owner_sub: 'me', data: { briefing_context: { timeZone: 'Asia/Tokyo' } } }] }
|
|
52
|
+
: { results: [] };
|
|
53
|
+
});
|
|
54
|
+
const result = await generateBriefing(deps, {});
|
|
55
|
+
expect(result.context.timeZone).toBe('Asia/Tokyo');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Connections page paints as each request lands (bd startsim-nghko.37).
|
|
3
|
+
*
|
|
4
|
+
* It used to wait on `Promise.all([catalog, connections])`: the slowest leg held the whole page on
|
|
5
|
+
* "Loading…", and either leg failing replaced everything with one error. These pin the replacement:
|
|
6
|
+
* the connected accounts show the moment THEY arrive, the catalog fills in on its own clock, and each
|
|
7
|
+
* leg fails and retries by itself.
|
|
8
|
+
*/
|
|
9
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
10
|
+
import { render, screen, waitFor, within } from '@testing-library/react';
|
|
11
|
+
import userEvent from '@testing-library/user-event';
|
|
12
|
+
|
|
13
|
+
import { ConnectionsPage } from '../components/pages/ConnectionsPage';
|
|
14
|
+
import type { MemberConnectionsApi } from '../components/pages/types';
|
|
15
|
+
|
|
16
|
+
const GOOGLE = {
|
|
17
|
+
id: 'g1', public_id: 'pub-g1', name: 'Google', connector_key: 'google', connector_name: 'Google',
|
|
18
|
+
external_account_id: '', account_label: '', capabilities_enabled: [], config: {}, status: 'connected',
|
|
19
|
+
health: 'ok', auth_mode: 'oauth',
|
|
20
|
+
sync: { state: 'ok', note: '', records: 72, last_attempt_at: null, last_success_at: null,
|
|
21
|
+
next_sync_at: null, interval_minutes: 10, window_days: 14 },
|
|
22
|
+
};
|
|
23
|
+
const CATALOG_ROW = {
|
|
24
|
+
key: 'granola', name: 'Granola', description: 'Meeting notes', auth_mode: 'api_key', allowed: true,
|
|
25
|
+
availability: { available: true, reason: '' }, capabilities: ['poll'], credential_schema: [{ key: 'api_key', label: 'API key', type: 'secret', required: true }],
|
|
26
|
+
};
|
|
27
|
+
const PERMS = { view: true, manage: true, issue_tokens: false };
|
|
28
|
+
|
|
29
|
+
function deferred<T>() {
|
|
30
|
+
let resolve!: (v: T) => void;
|
|
31
|
+
let reject!: (e: unknown) => void;
|
|
32
|
+
const promise = new Promise<T>((res, rej) => { resolve = res; reject = rej; });
|
|
33
|
+
return { promise, resolve, reject };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function api(over: Partial<MemberConnectionsApi>): MemberConnectionsApi {
|
|
37
|
+
return {
|
|
38
|
+
connectorCatalog: vi.fn().mockResolvedValue({ results: [CATALOG_ROW] }),
|
|
39
|
+
connections: vi.fn().mockResolvedValue({ results: [GOOGLE], permissions: PERMS }),
|
|
40
|
+
...over,
|
|
41
|
+
} as unknown as MemberConnectionsApi;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('ConnectionsPage — each request paints on its own', () => {
|
|
45
|
+
it('shows the connected accounts while the catalog is still in flight', async () => {
|
|
46
|
+
const catalog = deferred<{ results: unknown[] }>();
|
|
47
|
+
const a = api({ connectorCatalog: vi.fn().mockReturnValue(catalog.promise) as never });
|
|
48
|
+
render(<ConnectionsPage mode="personal" api={a} />);
|
|
49
|
+
|
|
50
|
+
const table = await screen.findByRole('region', { name: 'Source freshness' });
|
|
51
|
+
expect(within(table).getByText('Google')).toBeInTheDocument();
|
|
52
|
+
// The catalog has not answered: its section says so, and does NOT claim nothing is connectable.
|
|
53
|
+
expect(screen.queryByText(/has not opened any connector/i)).toBeNull();
|
|
54
|
+
expect(screen.getByText(/Loading connectors/i)).toBeInTheDocument();
|
|
55
|
+
|
|
56
|
+
catalog.resolve({ results: [CATALOG_ROW] });
|
|
57
|
+
expect(await screen.findByText('Granola')).toBeInTheDocument();
|
|
58
|
+
expect(screen.queryByText(/Loading connectors/i)).toBeNull();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('shows the catalog while the connections are still in flight', async () => {
|
|
62
|
+
const conns = deferred<{ results: unknown[]; permissions: unknown }>();
|
|
63
|
+
const a = api({ connections: vi.fn().mockReturnValue(conns.promise) as never });
|
|
64
|
+
render(<ConnectionsPage mode="personal" api={a} />);
|
|
65
|
+
|
|
66
|
+
expect(await screen.findByText('Granola')).toBeInTheDocument();
|
|
67
|
+
expect(screen.getByText(/Loading your accounts/i)).toBeInTheDocument();
|
|
68
|
+
expect(screen.queryByText(/You have not connected an account yet/i)).toBeNull();
|
|
69
|
+
|
|
70
|
+
conns.resolve({ results: [GOOGLE], permissions: PERMS });
|
|
71
|
+
expect(await screen.findByRole('region', { name: 'Source freshness' })).toBeInTheDocument();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('a failed catalog keeps the accounts and retries only the catalog', async () => {
|
|
75
|
+
const user = userEvent.setup();
|
|
76
|
+
const connectorCatalog = vi.fn()
|
|
77
|
+
.mockRejectedValueOnce(new Error('catalog is down'))
|
|
78
|
+
.mockResolvedValue({ results: [CATALOG_ROW] });
|
|
79
|
+
const connections = vi.fn().mockResolvedValue({ results: [GOOGLE], permissions: PERMS });
|
|
80
|
+
render(<ConnectionsPage mode="personal" api={api({ connectorCatalog, connections } as never)} />);
|
|
81
|
+
|
|
82
|
+
expect(await screen.findByRole('region', { name: 'Source freshness' })).toBeInTheDocument();
|
|
83
|
+
const alert = await screen.findByRole('alert');
|
|
84
|
+
expect(alert).toHaveTextContent(/catalog is down/);
|
|
85
|
+
await user.click(within(alert).getByRole('button', { name: /try again/i }));
|
|
86
|
+
|
|
87
|
+
expect(await screen.findByText('Granola')).toBeInTheDocument();
|
|
88
|
+
expect(connectorCatalog).toHaveBeenCalledTimes(2);
|
|
89
|
+
expect(connections).toHaveBeenCalledTimes(1);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('failed accounts keep the catalog and retry only the accounts', async () => {
|
|
93
|
+
const user = userEvent.setup();
|
|
94
|
+
const connections = vi.fn()
|
|
95
|
+
.mockRejectedValueOnce(new Error('accounts are down'))
|
|
96
|
+
.mockResolvedValue({ results: [GOOGLE], permissions: PERMS });
|
|
97
|
+
const connectorCatalog = vi.fn().mockResolvedValue({ results: [CATALOG_ROW] });
|
|
98
|
+
render(<ConnectionsPage mode="personal" api={api({ connectorCatalog, connections } as never)} />);
|
|
99
|
+
|
|
100
|
+
expect(await screen.findByText('Granola')).toBeInTheDocument();
|
|
101
|
+
const alert = await screen.findByRole('alert');
|
|
102
|
+
expect(alert).toHaveTextContent(/accounts are down/);
|
|
103
|
+
await user.click(within(alert).getByRole('button', { name: /try again/i }));
|
|
104
|
+
|
|
105
|
+
expect(await screen.findByRole('region', { name: 'Source freshness' })).toBeInTheDocument();
|
|
106
|
+
expect(connections).toHaveBeenCalledTimes(2);
|
|
107
|
+
expect(connectorCatalog).toHaveBeenCalledTimes(1);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('LATENCY BUDGET: first content waits on the accounts leg only, never on the slowest request', async () => {
|
|
111
|
+
const slowCatalog = deferred<{ results: unknown[] }>(); // never answers inside this test
|
|
112
|
+
const a = api({ connectorCatalog: vi.fn().mockReturnValue(slowCatalog.promise) as never });
|
|
113
|
+
const t0 = performance.now();
|
|
114
|
+
render(<ConnectionsPage mode="personal" api={a} />);
|
|
115
|
+
await screen.findByRole('region', { name: 'Source freshness' });
|
|
116
|
+
// The accounts mock answers at once; with the catalog hung forever the page must still be useful.
|
|
117
|
+
expect(performance.now() - t0).toBeLessThan(1000);
|
|
118
|
+
await waitFor(() => expect(screen.queryByText(/Loading your accounts/i)).toBeNull());
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -39,6 +39,35 @@ const MICROSOFT = connection('m1', 'Microsoft', {
|
|
|
39
39
|
last_success_at: null, next_sync_at: null, interval_minutes: null, window_days: 14 },
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
+
const CONNECTING = connection('m2', 'Outlook', {
|
|
43
|
+
status: 'needs_reauth',
|
|
44
|
+
sync: { state: 'connecting', note: 'Finish signing in with the provider to connect', records: 0, last_attempt_at: null,
|
|
45
|
+
last_success_at: null, next_sync_at: null, interval_minutes: null, window_days: 14 },
|
|
46
|
+
});
|
|
47
|
+
const REFUSED = connection('m3', 'Outlook work', {
|
|
48
|
+
status: 'needs_reauth',
|
|
49
|
+
sync: { state: 'reauth', note: "Microsoft refused this sign-in: StartSimpli's Microsoft app is not set up for accounts outside its own organization yet.",
|
|
50
|
+
records: 0, last_attempt_at: null, last_success_at: null, next_sync_at: null, interval_minutes: null, window_days: 14 },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('ConnectionsPage — a connect that has not finished', () => {
|
|
54
|
+
it('says Connecting, not Reconnect needed, while the member is still at the provider', async () => {
|
|
55
|
+
render(<ConnectionsPage mode="personal" api={api([CONNECTING])} />);
|
|
56
|
+
const table = await screen.findByRole('region', { name: 'Source freshness' });
|
|
57
|
+
const row = within(table).getByText('Outlook').closest('tr')!;
|
|
58
|
+
expect(within(row).getByText('Connecting…')).toBeInTheDocument();
|
|
59
|
+
expect(within(row).queryByText('Reconnect needed')).toBeNull();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('shows why a refused connect needs reconnecting', async () => {
|
|
63
|
+
render(<ConnectionsPage mode="personal" api={api([REFUSED])} />);
|
|
64
|
+
const table = await screen.findByRole('region', { name: 'Source freshness' });
|
|
65
|
+
const row = within(table).getByText('Outlook work').closest('tr')!;
|
|
66
|
+
expect(within(row).getByText('Reconnect needed')).toBeInTheDocument();
|
|
67
|
+
expect(within(row).getByText(/not set up for accounts outside its own organization/)).toBeInTheDocument();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
42
71
|
describe('ConnectionsPage — the sources sync table', () => {
|
|
43
72
|
it('lists each synced connection as a row: status, records with its window, last and next sync', async () => {
|
|
44
73
|
render(<ConnectionsPage mode="personal" api={api([GOOGLE, MICROSOFT])} />);
|
|
@@ -69,33 +69,57 @@ export function ConnectionsPage(props: ConnectionsPageProps) {
|
|
|
69
69
|
const [permissions, setPermissions] = React.useState<ConnectionPermissions>({
|
|
70
70
|
view: true, manage: false, issue_tokens: false,
|
|
71
71
|
});
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
// TWO LEGS, TWO CLOCKS (bd startsim-nghko.37). The accounts list and the catalog are separate
|
|
73
|
+
// requests with separate failure modes: each paints when it lands, fails on its own, and retries
|
|
74
|
+
// alone. Gating the page on both (`Promise.all`) made the slowest request the page's latency and let
|
|
75
|
+
// either failure blank the other half.
|
|
76
|
+
const [catalogError, setCatalogError] = React.useState<string>('');
|
|
77
|
+
const [connectionsError, setConnectionsError] = React.useState<string>('');
|
|
78
|
+
const [catalogLoading, setCatalogLoading] = React.useState(true);
|
|
79
|
+
const [connectionsLoading, setConnectionsLoading] = React.useState(true);
|
|
74
80
|
/** The synced connection whose own card is open (the table's one action). */
|
|
75
81
|
const [openId, setOpenId] = React.useState<string | null>(null);
|
|
76
82
|
|
|
77
|
-
const
|
|
78
|
-
|
|
83
|
+
const loadCatalog = React.useCallback(async () => {
|
|
84
|
+
setCatalogLoading(true);
|
|
79
85
|
try {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
api.connectorCatalog(),
|
|
85
|
-
api.connections(),
|
|
86
|
-
]);
|
|
86
|
+
// In personal mode this is the ALLOWED catalog, already narrowed by the
|
|
87
|
+
// foundry's policy server-side. Rendered as handed: filtering here would
|
|
88
|
+
// put the withheld connectors in the browser to be filtered out of.
|
|
89
|
+
const cat = await api.connectorCatalog();
|
|
87
90
|
setCatalog(cat.results ?? []);
|
|
91
|
+
setCatalogError('');
|
|
92
|
+
} catch (err) {
|
|
93
|
+
setCatalogError(readFailureMessage(err, personal));
|
|
94
|
+
} finally {
|
|
95
|
+
setCatalogLoading(false);
|
|
96
|
+
}
|
|
97
|
+
}, [api, personal]);
|
|
98
|
+
|
|
99
|
+
const loadConnections = React.useCallback(async () => {
|
|
100
|
+
setConnectionsLoading(true);
|
|
101
|
+
try {
|
|
102
|
+
const conns = await api.connections();
|
|
88
103
|
setConnections(conns.results ?? []);
|
|
89
104
|
setPermissions(conns.permissions ?? { view: true, manage: false, issue_tokens: false });
|
|
90
|
-
|
|
105
|
+
setConnectionsError('');
|
|
91
106
|
} catch (err) {
|
|
92
|
-
|
|
107
|
+
setConnectionsError(readFailureMessage(err, personal));
|
|
93
108
|
} finally {
|
|
94
|
-
|
|
109
|
+
setConnectionsLoading(false);
|
|
95
110
|
}
|
|
96
111
|
}, [api, personal]);
|
|
97
112
|
|
|
98
|
-
|
|
113
|
+
/** After a change (connect, rotate, disconnect, policy flip): both halves can have moved. */
|
|
114
|
+
const reload = React.useCallback(async () => {
|
|
115
|
+
await Promise.all([loadCatalog(), loadConnections()]);
|
|
116
|
+
}, [loadCatalog, loadConnections]);
|
|
117
|
+
|
|
118
|
+
React.useEffect(() => { void loadConnections(); }, [loadConnections]);
|
|
119
|
+
React.useEffect(() => { void loadCatalog(); }, [loadCatalog]);
|
|
120
|
+
/** Still waiting for the FIRST answer; a refresh after a change keeps what is on screen. */
|
|
121
|
+
const loading = connectionsLoading;
|
|
122
|
+
const catalogPending = catalogLoading && catalog.length === 0;
|
|
99
123
|
|
|
100
124
|
const syncRows: SourceFreshness[] = connections.flatMap((connection) => {
|
|
101
125
|
const sync = readSync(connection as unknown as Record<string, unknown>);
|
|
@@ -112,10 +136,6 @@ export function ConnectionsPage(props: ConnectionsPageProps) {
|
|
|
112
136
|
} as SourceFreshness];
|
|
113
137
|
});
|
|
114
138
|
|
|
115
|
-
if (loadError) {
|
|
116
|
-
return <LoadError what="your connections" message={loadError} onRetry={() => { setLoadError(''); void reload(); }} />;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
139
|
return (
|
|
120
140
|
<div className={cn.root}>
|
|
121
141
|
<section className={cn.section}>
|
|
@@ -126,8 +146,14 @@ export function ConnectionsPage(props: ConnectionsPageProps) {
|
|
|
126
146
|
<h2 className={cn.heading}>
|
|
127
147
|
{personal ? 'Your connected accounts' : 'Connected accounts'}
|
|
128
148
|
</h2>
|
|
129
|
-
{
|
|
130
|
-
|
|
149
|
+
{connectionsError ? (
|
|
150
|
+
<LoadError what="your connections" message={connectionsError}
|
|
151
|
+
onRetry={() => { setConnectionsError(''); void loadConnections(); }} />
|
|
152
|
+
) : null}
|
|
153
|
+
{loading && connections.length === 0 && !connectionsError ? (
|
|
154
|
+
<p className={cn.muted}>{personal ? 'Loading your accounts…' : 'Loading connected accounts…'}</p>
|
|
155
|
+
) : null}
|
|
156
|
+
{!loading && !connectionsError && connections.length === 0 ? (
|
|
131
157
|
<p className={cn.muted}>
|
|
132
158
|
{personal
|
|
133
159
|
? 'You have not connected an account yet.'
|
|
@@ -163,12 +189,18 @@ export function ConnectionsPage(props: ConnectionsPageProps) {
|
|
|
163
189
|
</section>
|
|
164
190
|
|
|
165
191
|
{/* Nothing to offer is no section: a heading over a blank gap reads as a broken page. */}
|
|
166
|
-
{(personal ? connectableEntries(catalog, connections) : catalog).length > 0 ||
|
|
192
|
+
{(personal ? connectableEntries(catalog, connections) : catalog).length > 0 || catalogPending || catalogError
|
|
193
|
+
|| (personal && !catalogLoading && catalog.length === 0) ? (
|
|
167
194
|
<section className={cn.section}>
|
|
168
195
|
<h2 className={cn.heading}>
|
|
169
196
|
{personal ? 'Connect your own account' : 'Available connectors'}
|
|
170
197
|
</h2>
|
|
171
|
-
{
|
|
198
|
+
{catalogError ? (
|
|
199
|
+
<LoadError what="the connector list" message={catalogError}
|
|
200
|
+
onRetry={() => { setCatalogError(''); void loadCatalog(); }} />
|
|
201
|
+
) : null}
|
|
202
|
+
{catalogPending && !catalogError ? <p className={cn.muted}>Loading connectors…</p> : null}
|
|
203
|
+
{personal && !catalogLoading && !catalogError && catalog.length === 0 ? (
|
|
172
204
|
<p className={cn.muted}>
|
|
173
205
|
Your foundry has not opened any connector to members yet. An admin
|
|
174
206
|
decides which ones you may connect your own account on.
|
|
@@ -17,9 +17,18 @@ const SYNC_WORDS: Record<string, string> = {
|
|
|
17
17
|
limited: 'Slowed by the provider',
|
|
18
18
|
failing: 'Not syncing',
|
|
19
19
|
reauth: 'Reconnect needed',
|
|
20
|
+
connecting: 'Connecting…',
|
|
21
|
+
syncing: 'Syncing…',
|
|
20
22
|
waiting: 'Waiting for first sync',
|
|
21
23
|
};
|
|
22
24
|
|
|
25
|
+
/** Why a card needs attention, in the server's own sentence; '' when the status word says it all. */
|
|
26
|
+
export function reasonText(source: SourceFreshness): string {
|
|
27
|
+
const sync = source.sync;
|
|
28
|
+
if (!sync || (sync.state !== 'reauth' && sync.state !== 'connecting')) return '';
|
|
29
|
+
return sync.note === 'Reconnect this account to resume syncing' ? '' : sync.note;
|
|
30
|
+
}
|
|
31
|
+
|
|
23
32
|
export function statusText(source: SourceFreshness): string {
|
|
24
33
|
const sync = source.sync;
|
|
25
34
|
if (sync?.state === 'passive') return sync.note;
|
|
@@ -67,6 +76,7 @@ function nextSyncText(source: SourceFreshness, now: number): string {
|
|
|
67
76
|
const state = source.sync?.state;
|
|
68
77
|
if (state === 'passive') return '—';
|
|
69
78
|
if (state === 'reauth') return 'After you reconnect';
|
|
79
|
+
if (state === 'connecting') return '—';
|
|
70
80
|
if (source.sync && !source.sync.nextSyncAt) return 'Not scheduled';
|
|
71
81
|
return ahead(source.sync?.nextSyncAt, now);
|
|
72
82
|
}
|
|
@@ -104,7 +114,13 @@ export function SourcesTable({
|
|
|
104
114
|
return (
|
|
105
115
|
<tr key={source.source}>
|
|
106
116
|
<th scope="row" className={`${td} text-left font-medium`}>{source.label}</th>
|
|
107
|
-
<td className={attention ? `${td} font-medium text-amber-700 dark:text-amber-400` : td}>{statusText(source)}
|
|
117
|
+
<td className={attention ? `${td} font-medium text-amber-700 dark:text-amber-400` : td}>{statusText(source)}
|
|
118
|
+
{reasonText(source) ? (
|
|
119
|
+
<span className="block max-w-xs whitespace-normal text-xs font-normal text-gray-600 dark:text-gray-300" data-sync-reason>
|
|
120
|
+
{reasonText(source)}
|
|
121
|
+
</span>
|
|
122
|
+
) : null}
|
|
123
|
+
</td>
|
|
108
124
|
<td className={`${td} text-right tabular-nums`}>{records === null ? '—' : records}
|
|
109
125
|
{source.sync?.windowDays ? (
|
|
110
126
|
<span className="block whitespace-nowrap text-xs font-normal text-gray-500 dark:text-gray-400">last {source.sync.windowDays} days</span>
|
|
@@ -95,10 +95,17 @@ export async function generateBriefing(deps: BriefingDeps, request: BriefingRequ
|
|
|
95
95
|
const now = clock();
|
|
96
96
|
const ttl = Math.min(deps.audioTtlSeconds ?? DEFAULT_TTL, 600);
|
|
97
97
|
const store = deps.store ?? createEntityBriefingStore(deps.http, deps.ownerSub);
|
|
98
|
-
|
|
98
|
+
// The zone lookup, the to-do read and the open-question count do not depend on each other:
|
|
99
|
+
// overlap them so a cold call pays one tenant round trip here, not three-plus.
|
|
100
|
+
const givenZone = request.timeZone ?? deps.timeZone;
|
|
101
|
+
const [rememberedZone, items, unsure] = await Promise.all([
|
|
102
|
+
givenZone ? undefined : rememberedTimeZone(store, deps.ownerSub, now),
|
|
103
|
+
deps.loadItems(),
|
|
104
|
+
deps.unsureCount?.().catch(() => 0) ?? 0,
|
|
105
|
+
]);
|
|
106
|
+
const timeZone = givenZone ?? rememberedZone ?? 'UTC';
|
|
99
107
|
|
|
100
|
-
const composed = composeBriefing(
|
|
101
|
-
const unsure = await deps.unsureCount?.().catch(() => 0) ?? 0;
|
|
108
|
+
const composed = composeBriefing(items, { ownerSub: deps.ownerSub, now, timeZone });
|
|
102
109
|
const briefing = unsure > 0 ? { ...composed, unsure } : composed;
|
|
103
110
|
const hash = briefingContentHash(briefing);
|
|
104
111
|
const externalId = briefingExternalId(deps.ownerSub, briefing.context.localDate);
|
|
@@ -13,12 +13,12 @@ const utcDate = (ms: number) => new Date(ms).toISOString().slice(0, 10);
|
|
|
13
13
|
export async function rememberedTimeZone(
|
|
14
14
|
store: Pick<BriefingStore, 'find'>, ownerSub: string, now: number,
|
|
15
15
|
): Promise<string | undefined> {
|
|
16
|
-
|
|
16
|
+
// Looked up together (one round trip of wall time, not five); the nearest day with a zone still wins.
|
|
17
|
+
const zones = await Promise.all([1, 0, -1, -2, -3].map(async (offset) => {
|
|
17
18
|
try {
|
|
18
19
|
const row = await store.find(briefingExternalId(ownerSub, utcDate(now + offset * DAY)));
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return undefined;
|
|
20
|
+
return row?.context?.timeZone as string | undefined;
|
|
21
|
+
} catch { return undefined; /* a lookup failure only costs the fallback */ }
|
|
22
|
+
}));
|
|
23
|
+
return zones.find(Boolean);
|
|
24
24
|
}
|
package/src/corpus/types.ts
CHANGED
|
@@ -193,7 +193,7 @@ export interface MoneyEvent {
|
|
|
193
193
|
* wrong, so the Library states it per source and the Ask surface repeats it.
|
|
194
194
|
*/
|
|
195
195
|
export interface SourceSync {
|
|
196
|
-
state: 'ok' | 'limited' | 'failing' | 'reauth' | 'waiting' | 'passive';
|
|
196
|
+
state: 'ok' | 'limited' | 'failing' | 'reauth' | 'connecting' | 'syncing' | 'waiting' | 'passive';
|
|
197
197
|
/** One sentence the server wrote; '' when there is nothing to add. */
|
|
198
198
|
note: string;
|
|
199
199
|
records: number;
|