@startsimpli/integrations 0.2.72 โ 0.2.73
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/README.md +2 -0
- package/package.json +1 -1
- package/src/__tests__/view-text.test.ts +31 -0
- package/src/components/Markdown.tsx +1 -15
- package/src/components/pages/AskPage.tsx +12 -59
- package/src/components/pages/LibraryPage.tsx +1 -45
- package/src/corpus/client.ts +8 -4
- package/src/corpus/entities.ts +1 -0
- package/src/corpus/types.ts +4 -0
- package/src/corpus/view-text.ts +113 -0
- package/src/native/components/NotesShell.tsx +9 -4
- package/src/native/corpus/fake-tenant.ts +6 -0
- package/src/native/index.ts +9 -0
- package/src/native/screens/__tests__/ask-controller.test.ts +135 -0
- package/src/native/screens/__tests__/ask-screen.test.tsx +96 -0
- package/src/native/screens/__tests__/library-controller.test.ts +185 -0
- package/src/native/screens/__tests__/library-screens.test.tsx +134 -0
- package/src/native/screens/__tests__/tabs.test.tsx +46 -0
- package/src/native/screens/ask/AskScreen.tsx +118 -0
- package/src/native/screens/ask/answer-view.ts +53 -0
- package/src/native/screens/ask/controller.ts +100 -0
- package/src/native/screens/library/LibraryDetailScreen.tsx +93 -0
- package/src/native/screens/library/LibraryListScreen.tsx +99 -0
- package/src/native/screens/library/controller.ts +196 -0
- package/src/native/screens/library/fake-library.ts +38 -0
- package/src/native/screens/store.ts +19 -0
- package/src/native/screens/tabs.tsx +41 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { act, allText, hostById, maybeById, press, render } from '../../../../../ui-native/test/render';
|
|
3
|
+
import type { CorpusAskApi } from '../../../corpus/types';
|
|
4
|
+
import { AskScreen } from '../ask/AskScreen';
|
|
5
|
+
import { createAskController } from '../ask/controller';
|
|
6
|
+
import { createFakeLibraryApi } from '../library/fake-library';
|
|
7
|
+
|
|
8
|
+
const tick = () => act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
9
|
+
|
|
10
|
+
async function mount(opts: { api?: CorpusAskApi; onOpenDocument?: (id: string) => void } = {}) {
|
|
11
|
+
const fake = createFakeLibraryApi();
|
|
12
|
+
const controller = createAskController({
|
|
13
|
+
api: opts.api ?? fake.ask, scope: fake.scope,
|
|
14
|
+
listProjects: async () => fake.corpus.listFocusChoices!(),
|
|
15
|
+
});
|
|
16
|
+
const onOpenDocument = opts.onOpenDocument ?? vi.fn();
|
|
17
|
+
const r = render(<AskScreen controller={controller} onOpenDocument={onOpenDocument} />);
|
|
18
|
+
await act(async () => { await controller.start(); });
|
|
19
|
+
return { r, controller, onOpenDocument };
|
|
20
|
+
}
|
|
21
|
+
const type = (r: ReturnType<typeof render>, text: string) => act(() => { hostById(r, 'ask-composer-input').props.onChangeText(text); });
|
|
22
|
+
const send = async (r: ReturnType<typeof render>) => { press(hostById(r, 'ask-composer-send')); await tick(); await tick(); };
|
|
23
|
+
|
|
24
|
+
describe('AskScreen', () => {
|
|
25
|
+
it('starts with an empty state that says what Ask is for', async () => {
|
|
26
|
+
const { r } = await mount();
|
|
27
|
+
expect(allText(r)).toContain('Ask your documents');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('asks, shows the question and a Markdown answer with its sources', async () => {
|
|
31
|
+
const { r } = await mount();
|
|
32
|
+
type(r, 'pricing Acme');
|
|
33
|
+
await send(r);
|
|
34
|
+
const text = allText(r);
|
|
35
|
+
expect(text).toContain('pricing Acme');
|
|
36
|
+
expect(text).toContain('1 source');
|
|
37
|
+
expect(text).toContain('Pricing call with Acme');
|
|
38
|
+
expect(text).toContain('Granola');
|
|
39
|
+
expect(text).toContain('no live model was called');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('tapping a citation opens that document', async () => {
|
|
43
|
+
const { r, onOpenDocument } = await mount();
|
|
44
|
+
type(r, 'pricing Acme');
|
|
45
|
+
await send(r);
|
|
46
|
+
press(hostById(r, 'ask-citation-d4'));
|
|
47
|
+
expect(onOpenDocument).toHaveBeenCalledWith('d4');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('a project chosen in the picker scopes the question server-side', async () => {
|
|
51
|
+
const seen: unknown[] = [];
|
|
52
|
+
const fake = createFakeLibraryApi();
|
|
53
|
+
const { r } = await mount({ api: { ask: (req) => { seen.push(req.filters); return fake.ask.ask(req); } } });
|
|
54
|
+
press(hostById(r, 'ask-project'));
|
|
55
|
+
press(hostById(r, 'ask-project-option-fma'));
|
|
56
|
+
type(r, 'pricing Acme');
|
|
57
|
+
await send(r);
|
|
58
|
+
expect(seen).toEqual([{ focus: 'fma' }]);
|
|
59
|
+
expect(allText(r)).toContain('Marketing agents');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('shows a loading bubble while the answer is coming', async () => {
|
|
63
|
+
let release!: () => void;
|
|
64
|
+
const fake = createFakeLibraryApi();
|
|
65
|
+
const { r } = await mount({ api: { ask: (req) => new Promise((res) => { release = () => res(fake.ask.ask(req) as never); }) } });
|
|
66
|
+
type(r, 'pricing Acme');
|
|
67
|
+
press(hostById(r, 'ask-composer-send'));
|
|
68
|
+
await tick();
|
|
69
|
+
expect(maybeById(r, 'ask-pending').length).toBeGreaterThan(0);
|
|
70
|
+
await act(async () => { release(); await new Promise((res) => setTimeout(res, 0)); });
|
|
71
|
+
expect(maybeById(r, 'ask-pending')).toHaveLength(0);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('a failure says why and Retry asks again', async () => {
|
|
75
|
+
const fake = createFakeLibraryApi();
|
|
76
|
+
let fail = true;
|
|
77
|
+
const { r } = await mount({ api: { ask: async (req) => { if (fail) throw Object.assign(new Error('x'), { status: 401 }); return fake.ask.ask(req); } } });
|
|
78
|
+
type(r, 'pricing Acme');
|
|
79
|
+
await send(r);
|
|
80
|
+
expect(allText(r)).toContain('Your session has expired. Sign in again.');
|
|
81
|
+
fail = false;
|
|
82
|
+
const retry = r.root.findAll((n) => typeof n.type === 'string' && String(n.props.testID ?? '').endsWith('-retry'))[0];
|
|
83
|
+
press(retry);
|
|
84
|
+
await tick(); await tick();
|
|
85
|
+
expect(allText(r)).toContain('Pricing call with Acme');
|
|
86
|
+
expect(allText(r)).not.toContain('Sign in again');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('an answer from no records is said plainly, not as an error', async () => {
|
|
90
|
+
const fake = createFakeLibraryApi();
|
|
91
|
+
const { r } = await mount({ api: { ask: async () => ({ ...(await fake.ask.ask({ question: 'zzzzqqq nothing', mode: 'ask', scope: fake.scope })) }) } });
|
|
92
|
+
type(r, 'zzzzqqq nothing');
|
|
93
|
+
await send(r);
|
|
94
|
+
expect(allText(r)).not.toContain('Something went wrong');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createNativeCorpusApi } from '../../corpus/api';
|
|
3
|
+
import { createFakeTenantHttp } from '../../corpus/fake-tenant';
|
|
4
|
+
import { sampleTenantEntities, sampleTenantRelationships } from '../../corpus/fake-data';
|
|
5
|
+
import { createLibraryController } from '../library/controller';
|
|
6
|
+
import { createFakeLibraryApi, libraryExtraEntities, libraryExtraRelationships } from '../library/fake-library';
|
|
7
|
+
|
|
8
|
+
type Req = { method: string; path: string; params: Record<string, unknown> };
|
|
9
|
+
function setup(options: Parameters<typeof createFakeLibraryApi>[0] = {}, pageSize?: number) {
|
|
10
|
+
const requests: Req[] = [];
|
|
11
|
+
const api = createFakeLibraryApi({ ...options, onRequest: (method, path, params) => requests.push({ method, path, params }) });
|
|
12
|
+
const controller = createLibraryController(api, { pageSize });
|
|
13
|
+
const documentReads = () => requests.filter((r) => r.method === 'GET' && r.path === 'api/v1/entities' && r.params.type === 'source_document');
|
|
14
|
+
return { api, controller, requests, documentReads };
|
|
15
|
+
}
|
|
16
|
+
const ids = (c: ReturnType<typeof createLibraryController>) => c.getState().list.items.map((d) => d.id);
|
|
17
|
+
|
|
18
|
+
describe('library controller: the list is the server\'s page', () => {
|
|
19
|
+
it('start() loads newest first, with the filter options and each row\'s project', async () => {
|
|
20
|
+
const { controller } = setup();
|
|
21
|
+
await controller.start();
|
|
22
|
+
const s = controller.getState();
|
|
23
|
+
expect(ids(controller)).toEqual(['d1', 'd2', 'd3', 'd4', 'd5']);
|
|
24
|
+
expect(s.list.count).toBe(5);
|
|
25
|
+
expect(s.projects.map((p) => p.label)).toEqual(['287A', 'Debug', 'Marketing agents']);
|
|
26
|
+
expect(s.sources.map((o) => o.value).sort()).toEqual(['drive', 'granola', 'voice']);
|
|
27
|
+
expect(s.types.map((o) => o.value).sort()).toEqual(['document', 'meeting', 'voice_note']);
|
|
28
|
+
expect(s.filings.d1.map((f) => f.title)).toEqual(['287A']);
|
|
29
|
+
expect(s.filings.d5).toEqual([]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('search is sent to the server, never filtered on the phone', async () => {
|
|
33
|
+
const { controller, documentReads } = setup();
|
|
34
|
+
await controller.start();
|
|
35
|
+
await controller.setSearch('checklist');
|
|
36
|
+
expect(ids(controller)).toEqual(['d3']);
|
|
37
|
+
expect(documentReads().at(-1)!.params.search).toBe('checklist');
|
|
38
|
+
await controller.setSearch('');
|
|
39
|
+
expect(ids(controller)).toHaveLength(5);
|
|
40
|
+
expect(documentReads().at(-1)!.params.search).toBeUndefined();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('source, type and project are server parameters', async () => {
|
|
44
|
+
const { controller, documentReads } = setup();
|
|
45
|
+
await controller.start();
|
|
46
|
+
await controller.setFilter('source', 'granola');
|
|
47
|
+
expect(ids(controller)).toEqual(['d2', 'd4']);
|
|
48
|
+
expect(documentReads().at(-1)!.params.source).toBe('granola');
|
|
49
|
+
await controller.setFilter('subtype', 'meeting');
|
|
50
|
+
expect(documentReads().at(-1)!.params['attr.subtype']).toBe('meeting');
|
|
51
|
+
await controller.setFilter('project', 'fma');
|
|
52
|
+
expect(ids(controller)).toEqual(['d2', 'd4']);
|
|
53
|
+
expect(documentReads().at(-1)!.params).toMatchObject({ related_to: 'fma', related_via: 'about_focus', related_direction: 'out' });
|
|
54
|
+
await controller.setFilter('source', null);
|
|
55
|
+
await controller.setFilter('subtype', null);
|
|
56
|
+
await controller.setFilter('project', '287a-none');
|
|
57
|
+
expect(ids(controller)).toEqual([]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('newest / oldest is the server\'s order', async () => {
|
|
61
|
+
const { controller, documentReads } = setup();
|
|
62
|
+
await controller.start();
|
|
63
|
+
await controller.setOrder('oldest');
|
|
64
|
+
expect(ids(controller)).toEqual(['d5', 'd4', 'd3', 'd2', 'd1']);
|
|
65
|
+
expect(documentReads().at(-1)!.params.order).toBe('oldest');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('pages: loadMore asks the server for the next page and appends', async () => {
|
|
69
|
+
const { controller, documentReads } = setup({}, 2);
|
|
70
|
+
await controller.start();
|
|
71
|
+
expect(ids(controller)).toEqual(['d1', 'd2']);
|
|
72
|
+
expect(controller.getState().list.hasMore).toBe(true);
|
|
73
|
+
await controller.loadMore();
|
|
74
|
+
expect(ids(controller)).toEqual(['d1', 'd2', 'd3', 'd4']);
|
|
75
|
+
expect(documentReads().at(-1)!.params.page).toBe(2);
|
|
76
|
+
await controller.loadMore();
|
|
77
|
+
expect(ids(controller)).toHaveLength(5);
|
|
78
|
+
expect(controller.getState().list.hasMore).toBe(false);
|
|
79
|
+
// Filings were fetched for the rows that arrived, once each.
|
|
80
|
+
expect(controller.getState().filings.d4.map((f) => f.title)).toEqual(['Marketing agents']);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('says so when the server ignores a filter, instead of showing an unfiltered list as filtered', async () => {
|
|
84
|
+
const { controller } = setup({ unsupported: ['attr.subtype'] });
|
|
85
|
+
await controller.start();
|
|
86
|
+
await controller.setFilter('subtype', 'meeting');
|
|
87
|
+
expect(controller.getState().list.ignoredFilters).toContain('subtype');
|
|
88
|
+
expect(ids(controller)).toHaveLength(5);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('clearFilters returns to the whole corpus', async () => {
|
|
92
|
+
const { controller } = setup();
|
|
93
|
+
await controller.start();
|
|
94
|
+
await controller.setSearch('acme');
|
|
95
|
+
await controller.setFilter('source', 'granola');
|
|
96
|
+
await controller.clearFilters();
|
|
97
|
+
expect(controller.getState().filters).toEqual({ search: '', source: null, subtype: null, project: null, order: 'recent' });
|
|
98
|
+
expect(ids(controller)).toHaveLength(5);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('library controller: open a document', () => {
|
|
103
|
+
it('uses the row already loaded', async () => {
|
|
104
|
+
const { controller, requests } = setup();
|
|
105
|
+
await controller.start();
|
|
106
|
+
const before = requests.length;
|
|
107
|
+
await controller.open('d4');
|
|
108
|
+
expect(controller.getState().selected).toMatchObject({ id: 'd4', loading: false, error: null });
|
|
109
|
+
expect(controller.getState().selected!.document!.summary).toContain('$4,800');
|
|
110
|
+
expect(requests.length).toBe(before);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('fetches the one record when it is not on the page (a citation or a link)', async () => {
|
|
114
|
+
const { controller, requests } = setup({}, 2);
|
|
115
|
+
await controller.start();
|
|
116
|
+
await controller.open('d5');
|
|
117
|
+
expect(controller.getState().selected!.document!.title).toBe('Office move notes');
|
|
118
|
+
expect(requests.some((r) => r.path === 'api/v1/entities/d5')).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('names the id when it is gone', async () => {
|
|
122
|
+
const { controller } = setup();
|
|
123
|
+
await controller.start();
|
|
124
|
+
await controller.open('nope');
|
|
125
|
+
const sel = controller.getState().selected!;
|
|
126
|
+
expect(sel.document).toBeNull();
|
|
127
|
+
expect(sel.error).toContain('nope');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('close() clears it', async () => {
|
|
131
|
+
const { controller } = setup();
|
|
132
|
+
await controller.start();
|
|
133
|
+
await controller.open('d1');
|
|
134
|
+
controller.close();
|
|
135
|
+
expect(controller.getState().selected).toBeNull();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('library controller: change the project (the existing filing code)', () => {
|
|
140
|
+
it('replaces the about_focus edge and updates the row at once', async () => {
|
|
141
|
+
const { controller, api } = setup();
|
|
142
|
+
await controller.start();
|
|
143
|
+
await controller.fileUnder('d1', 'fdbg');
|
|
144
|
+
expect(controller.getState().filings.d1.map((f) => f.title)).toEqual(['Debug']);
|
|
145
|
+
const edges = await api.relationships.list({ relType: 'about_focus', source: 'd1' });
|
|
146
|
+
expect(edges.items.map((e) => String(e.target))).toEqual(['fdbg']);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('files an unfiled document, and unfiles with null', async () => {
|
|
150
|
+
const { controller, api } = setup();
|
|
151
|
+
await controller.start();
|
|
152
|
+
await controller.fileUnder('d5', 'f287');
|
|
153
|
+
expect(controller.getState().filings.d5.map((f) => f.title)).toEqual(['287A']);
|
|
154
|
+
await controller.fileUnder('d5', null);
|
|
155
|
+
expect(controller.getState().filings.d5).toEqual([]);
|
|
156
|
+
expect((await api.relationships.list({ relType: 'about_focus', source: 'd5' })).items).toEqual([]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('says why when the write fails, and shows what the server holds', async () => {
|
|
160
|
+
const tenant = createFakeTenantHttp({
|
|
161
|
+
entities: [...sampleTenantEntities(), ...libraryExtraEntities()],
|
|
162
|
+
relationships: [...sampleTenantRelationships(), ...libraryExtraRelationships()],
|
|
163
|
+
});
|
|
164
|
+
const http = { ...tenant.http, post: async () => { throw Object.assign(new Error('Server hiccup'), { status: 500 }); } };
|
|
165
|
+
const controller = createLibraryController(createNativeCorpusApi({ http, scope: { orgId: 'tandem' } }));
|
|
166
|
+
await controller.start();
|
|
167
|
+
// Nothing was written for an unfiled document: it stays unfiled.
|
|
168
|
+
await controller.fileUnder('d5', 'fdbg');
|
|
169
|
+
expect(controller.getState().filingError).toBe('Server hiccup');
|
|
170
|
+
expect(controller.getState().filings.d5).toEqual([]);
|
|
171
|
+
expect(controller.getState().filingBusy).toBe(false);
|
|
172
|
+
// Moving d1 deletes its old edge first, so the server now holds it unfiled; the row says that, not a stale guess.
|
|
173
|
+
await controller.fileUnder('d1', 'fdbg');
|
|
174
|
+
expect(controller.getState().filings.d1).toEqual([]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('re-reads the page when a project filter is on, so a moved row leaves it', async () => {
|
|
178
|
+
const { controller } = setup();
|
|
179
|
+
await controller.start();
|
|
180
|
+
await controller.setFilter('project', 'f287');
|
|
181
|
+
expect(ids(controller)).toEqual(['d1']);
|
|
182
|
+
await controller.fileUnder('d1', 'fdbg');
|
|
183
|
+
expect(ids(controller)).toEqual([]);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { act, allText, hostById, maybeById, press, render } from '../../../../../ui-native/test/render';
|
|
3
|
+
import { createLibraryController } from '../library/controller';
|
|
4
|
+
import { createFakeLibraryApi } from '../library/fake-library';
|
|
5
|
+
import { LibraryDetailScreen } from '../library/LibraryDetailScreen';
|
|
6
|
+
import { LibraryListScreen } from '../library/LibraryListScreen';
|
|
7
|
+
|
|
8
|
+
async function mountList(onOpen = vi.fn()) {
|
|
9
|
+
const api = createFakeLibraryApi();
|
|
10
|
+
const controller = createLibraryController(api);
|
|
11
|
+
const r = render(<LibraryListScreen controller={controller} onOpen={onOpen} />);
|
|
12
|
+
await act(async () => { await controller.start(); });
|
|
13
|
+
return { r, controller, onOpen, api };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('LibraryListScreen', () => {
|
|
17
|
+
it('shows the documents with their source, date, preview and the project they are filed under', async () => {
|
|
18
|
+
const { r } = await mountList();
|
|
19
|
+
const text = allText(r);
|
|
20
|
+
for (const title of ['Hearing prep and a dentist reminder', 'Weekly sync with Rae', 'Pricing call with Acme', 'Office move notes']) expect(text).toContain(title);
|
|
21
|
+
expect(text).toContain('5 documents');
|
|
22
|
+
expect(text).toContain('Granola');
|
|
23
|
+
expect(text).toContain('Acme renews at $4,800 per month');
|
|
24
|
+
expect(maybeById(r, 'library-chip-d1-f287').length).toBeGreaterThan(0);
|
|
25
|
+
expect(allText(r)).toContain('287A');
|
|
26
|
+
expect(allText(r)).toContain('Unfiled');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('tapping a row opens that document', async () => {
|
|
30
|
+
const { r, onOpen } = await mountList();
|
|
31
|
+
press(hostById(r, 'library-row-d4'));
|
|
32
|
+
expect(onOpen).toHaveBeenCalledWith('d4');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('a filter picked in the sheet is a server query', async () => {
|
|
36
|
+
const { r, controller } = await mountList();
|
|
37
|
+
press(hostById(r, 'library-list-filter-source'));
|
|
38
|
+
press(hostById(r, 'library-list-filter-source-option-granola'));
|
|
39
|
+
await act(async () => { await Promise.resolve(); });
|
|
40
|
+
await act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
41
|
+
expect(controller.getState().filters.source).toBe('granola');
|
|
42
|
+
expect(controller.getState().list.items.map((d) => d.id)).toEqual(['d2', 'd4']);
|
|
43
|
+
expect(allText(r)).toContain('2 documents');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('newest / oldest changes the server order', async () => {
|
|
47
|
+
const { r, controller } = await mountList();
|
|
48
|
+
press(hostById(r, 'library-list-sort-oldest'));
|
|
49
|
+
await act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
50
|
+
expect(controller.getState().filters.order).toBe('oldest');
|
|
51
|
+
expect(controller.getState().list.items[0].id).toBe('d5');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('says so when a filter was not applied by the server', async () => {
|
|
55
|
+
const api = createFakeLibraryApi({ unsupported: ['attr.subtype'] });
|
|
56
|
+
const controller = createLibraryController(api);
|
|
57
|
+
const r = render(<LibraryListScreen controller={controller} onOpen={() => {}} />);
|
|
58
|
+
await act(async () => { await controller.start(); await controller.setFilter('subtype', 'meeting'); });
|
|
59
|
+
expect(allText(r)).toContain('does not filter by type');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('a failed first load is an error with Retry, not an empty library', async () => {
|
|
63
|
+
const api = createFakeLibraryApi();
|
|
64
|
+
let fail = true;
|
|
65
|
+
const realList = api.corpus.listDocuments!;
|
|
66
|
+
api.corpus.listDocuments = async (q) => { if (fail) throw new Error('Offline'); return realList(q); };
|
|
67
|
+
const controller = createLibraryController(api);
|
|
68
|
+
const r = render(<LibraryListScreen controller={controller} onOpen={() => {}} />);
|
|
69
|
+
await act(async () => { await controller.start(); });
|
|
70
|
+
expect(allText(r)).toContain('Offline');
|
|
71
|
+
fail = false;
|
|
72
|
+
await act(async () => { press(hostById(r, 'library-list-retry')); await new Promise((res) => setTimeout(res, 0)); });
|
|
73
|
+
expect(allText(r)).toContain('Office move notes');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
async function mountDetail(id: string, onBack = vi.fn()) {
|
|
78
|
+
const api = createFakeLibraryApi();
|
|
79
|
+
const controller = createLibraryController(api);
|
|
80
|
+
const r = render(<LibraryDetailScreen controller={controller} documentId={id} onBack={onBack} />);
|
|
81
|
+
await act(async () => { await controller.start(); await controller.open(id); });
|
|
82
|
+
return { r, controller, onBack, api };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
describe('LibraryDetailScreen', () => {
|
|
86
|
+
it('reads the summary as Markdown, with its source, date and project', async () => {
|
|
87
|
+
const { r } = await mountDetail('d4');
|
|
88
|
+
const text = allText(r);
|
|
89
|
+
expect(text).toContain('Pricing call with Acme');
|
|
90
|
+
expect(text).toContain('Decisions');
|
|
91
|
+
expect(text).toContain('$4,800 per month');
|
|
92
|
+
expect(text).not.toContain('**');
|
|
93
|
+
expect(text).not.toContain('## ');
|
|
94
|
+
expect(text).toContain('Granola');
|
|
95
|
+
expect(text).toContain('Filed under');
|
|
96
|
+
expect(text).toContain('Marketing agents');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('Back goes back', async () => {
|
|
100
|
+
const { r, onBack } = await mountDetail('d4');
|
|
101
|
+
press(hostById(r, 'library-detail-back'));
|
|
102
|
+
expect(onBack).toHaveBeenCalled();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('changes the project through the filing code and shows the new one', async () => {
|
|
106
|
+
const { r, controller, api } = await mountDetail('d4');
|
|
107
|
+
press(hostById(r, 'library-detail-project'));
|
|
108
|
+
press(hostById(r, 'library-detail-project-option-fdbg'));
|
|
109
|
+
await act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
110
|
+
expect(controller.getState().filings.d4.map((f) => f.title)).toEqual(['Debug']);
|
|
111
|
+
expect((await api.relationships.list({ relType: 'about_focus', source: 'd4' })).items.map((e) => String(e.target))).toEqual(['fdbg']);
|
|
112
|
+
expect(allText(r)).toContain('Debug');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('an unfiled document can be filed, and unfiled again with the clear row', async () => {
|
|
116
|
+
const { r, controller } = await mountDetail('d5');
|
|
117
|
+
expect(allText(r)).toContain('Unfiled');
|
|
118
|
+
press(hostById(r, 'library-detail-project'));
|
|
119
|
+
press(hostById(r, 'library-detail-project-option-f287'));
|
|
120
|
+
await act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
121
|
+
expect(controller.getState().filings.d5.map((f) => f.title)).toEqual(['287A']);
|
|
122
|
+
press(hostById(r, 'library-detail-project'));
|
|
123
|
+
press(hostById(r, 'library-detail-project-clear'));
|
|
124
|
+
await act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
125
|
+
expect(controller.getState().filings.d5).toEqual([]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('a record that is gone says which one, with a way back', async () => {
|
|
129
|
+
const { r, onBack } = await mountDetail('nope');
|
|
130
|
+
expect(allText(r)).toContain('nope');
|
|
131
|
+
press(hostById(r, 'library-detail-back'));
|
|
132
|
+
expect(onBack).toHaveBeenCalled();
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { act, allText, hostById, press, render } from '../../../../../ui-native/test/render';
|
|
3
|
+
import type { TabContext } from '../../components/FoundryTabsShell';
|
|
4
|
+
import { askTab, libraryAskTabs, libraryTab } from '../tabs';
|
|
5
|
+
import { createFakeLibraryApi } from '../library/fake-library';
|
|
6
|
+
|
|
7
|
+
const ctx = (over: Partial<TabContext> = {}): TabContext => ({
|
|
8
|
+
tab: 'library', active: true, route: null, push: vi.fn(), back: vi.fn(), openTab: vi.fn(), ...over,
|
|
9
|
+
});
|
|
10
|
+
const tick = () => act(async () => { await new Promise((res) => setTimeout(res, 20)); });
|
|
11
|
+
|
|
12
|
+
describe('Library and Ask tab config', () => {
|
|
13
|
+
it('registers two tabs with stable keys', () => {
|
|
14
|
+
expect(libraryAskTabs(createFakeLibraryApi()).map((t) => [t.key, t.label])).toEqual([['library', 'Library'], ['ask', 'Ask']]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('Library: the list, and a tapped row pushes the document id', async () => {
|
|
18
|
+
const c = ctx();
|
|
19
|
+
const r = render(<>{libraryTab(createFakeLibraryApi()).render(c)}</>);
|
|
20
|
+
await tick();
|
|
21
|
+
expect(allText(r)).toContain('Pricing call with Acme');
|
|
22
|
+
press(hostById(r, 'library-row-d4'));
|
|
23
|
+
expect(c.push).toHaveBeenCalledWith('d4');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('Library: with a route it shows that document (a deep link or a citation), Back pops', async () => {
|
|
27
|
+
const c = ctx({ route: { id: 'd4' } });
|
|
28
|
+
const r = render(<>{libraryTab(createFakeLibraryApi()).render(c)}</>);
|
|
29
|
+
await tick();
|
|
30
|
+
expect(allText(r)).toContain('$4,800 per month');
|
|
31
|
+
expect(allText(r)).toContain('Marketing agents');
|
|
32
|
+
press(hostById(r, 'library-detail-back'));
|
|
33
|
+
expect(c.back).toHaveBeenCalled();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('Ask: a citation opens the document in the Library tab', async () => {
|
|
37
|
+
const c = ctx({ tab: 'ask' });
|
|
38
|
+
const r = render(<>{askTab(createFakeLibraryApi()).render(c)}</>);
|
|
39
|
+
await tick();
|
|
40
|
+
act(() => { hostById(r, 'ask-composer-input').props.onChangeText('pricing Acme'); });
|
|
41
|
+
press(hostById(r, 'ask-composer-send'));
|
|
42
|
+
await tick();
|
|
43
|
+
press(hostById(r, 'ask-citation-d4'));
|
|
44
|
+
expect(c.openTab).toHaveBeenCalledWith('library', 'd4');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { FlatList, Pressable, View } from 'react-native';
|
|
3
|
+
import { Alert, Badge, Button, ChatComposer, EmptyState, Header, MessageBubble, Select, Text, useTheme } from '@startsimpli/ui-native';
|
|
4
|
+
import { useControllerState as useStore } from '../../components/useControllerState';
|
|
5
|
+
import type { AnswerView } from './answer-view';
|
|
6
|
+
import type { AskController, AskMessage } from './controller';
|
|
7
|
+
|
|
8
|
+
export interface AskScreenProps {
|
|
9
|
+
controller: AskController;
|
|
10
|
+
/** A citation was tapped: open that document (normally the Library tab). */
|
|
11
|
+
onOpenDocument: (documentId: string) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Ask your documents: pick a project to scope, ask, read a Markdown answer, tap a citation to open the record. */
|
|
15
|
+
export function AskScreen({ controller, onOpenDocument }: AskScreenProps) {
|
|
16
|
+
const s = useStore(controller);
|
|
17
|
+
const theme = useTheme();
|
|
18
|
+
const list = useRef<FlatList<AskMessage>>(null);
|
|
19
|
+
useEffect(() => { void controller.start(); }, [controller]);
|
|
20
|
+
const scope = s.projects.find((p) => p.id === s.projectId)?.title;
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<View style={{ flex: 1 }}>
|
|
24
|
+
<Header testID="ask-header" title="Ask" subtitle={scope ? `Scoped to ${scope}` : 'All projects'} />
|
|
25
|
+
{s.projects.length ? (
|
|
26
|
+
<View style={{ paddingHorizontal: theme.spacing.lg, paddingBottom: theme.spacing.sm, flexDirection: 'row' }}>
|
|
27
|
+
<Select
|
|
28
|
+
compact
|
|
29
|
+
testID="ask-project"
|
|
30
|
+
label="All projects"
|
|
31
|
+
title="Scope to a project"
|
|
32
|
+
options={s.projects.map((p) => ({ value: p.id, label: p.title }))}
|
|
33
|
+
value={s.projectId}
|
|
34
|
+
clearLabel="All projects"
|
|
35
|
+
onChange={(id) => controller.setProject(id)}
|
|
36
|
+
/>
|
|
37
|
+
</View>
|
|
38
|
+
) : null}
|
|
39
|
+
<FlatList
|
|
40
|
+
ref={list}
|
|
41
|
+
testID="ask-messages"
|
|
42
|
+
data={s.messages}
|
|
43
|
+
keyExtractor={(m) => m.id}
|
|
44
|
+
keyboardShouldPersistTaps="handled"
|
|
45
|
+
keyboardDismissMode="on-drag"
|
|
46
|
+
onContentSizeChange={() => list.current?.scrollToEnd?.({ animated: true })}
|
|
47
|
+
contentContainerStyle={{ padding: theme.spacing.lg, gap: theme.spacing.md, flexGrow: 1 }}
|
|
48
|
+
ListEmptyComponent={
|
|
49
|
+
<EmptyState icon="๐ฌ" title="Ask your documents" description="Answers come from your notes, meetings and files, with the records they used." />
|
|
50
|
+
}
|
|
51
|
+
renderItem={({ item }) => <Message message={item} onRetry={() => { void controller.retry(item.id); }} onOpenDocument={onOpenDocument} />}
|
|
52
|
+
/>
|
|
53
|
+
<ChatComposer testID="ask-composer" placeholder="Ask about your documents" sending={s.busy} onSend={(text) => { void controller.send(text); }} />
|
|
54
|
+
</View>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function Message({ message, onRetry, onOpenDocument }: { message: AskMessage; onRetry: () => void; onOpenDocument: (id: string) => void }) {
|
|
59
|
+
const theme = useTheme();
|
|
60
|
+
if (message.role === 'user') return <MessageBubble role="user" text={message.text} testID={`ask-msg-${message.id}`} />;
|
|
61
|
+
if (message.status === 'pending') return <MessageBubble role="assistant" text="" pending testID="ask-pending" />;
|
|
62
|
+
if (message.status === 'error') {
|
|
63
|
+
return (
|
|
64
|
+
<View style={{ gap: theme.spacing.sm, alignItems: 'flex-start' }} testID={`ask-msg-${message.id}`}>
|
|
65
|
+
<Alert variant="destructive">{message.error ?? 'That question could not be answered right now.'}</Alert>
|
|
66
|
+
<Button testID={`ask-msg-${message.id}-retry`} title="Retry" variant="outline" size="sm" onPress={onRetry} />
|
|
67
|
+
</View>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return (
|
|
71
|
+
<View style={{ gap: theme.spacing.sm }} testID={`ask-msg-${message.id}`}>
|
|
72
|
+
{message.view?.notices.map((n, i) => <Alert key={i} variant={n.tone === 'error' ? 'destructive' : 'default'}>{n.text}</Alert>)}
|
|
73
|
+
<MessageBubble role="assistant" text={message.text} />
|
|
74
|
+
{message.view ? <Sources view={message.view} onOpenDocument={onOpenDocument} /> : null}
|
|
75
|
+
</View>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function Sources({ view, onOpenDocument }: { view: AnswerView; onOpenDocument: (id: string) => void }) {
|
|
80
|
+
const theme = useTheme();
|
|
81
|
+
const [showUncited, setShowUncited] = useState(false);
|
|
82
|
+
const n = view.citations.length;
|
|
83
|
+
return (
|
|
84
|
+
<View style={{ gap: theme.spacing.sm }}>
|
|
85
|
+
{view.status !== 'no_evidence' ? <Text variant="caption">{`${n} source${n === 1 ? '' : 's'}`}</Text> : null}
|
|
86
|
+
{view.citations.map((c) => (
|
|
87
|
+
<Pressable
|
|
88
|
+
key={c.documentId}
|
|
89
|
+
testID={`ask-citation-${c.documentId}`}
|
|
90
|
+
accessibilityRole="button"
|
|
91
|
+
accessibilityLabel={`Open ${c.title}`}
|
|
92
|
+
onPress={() => onOpenDocument(c.documentId)}
|
|
93
|
+
style={({ pressed }) => ({ gap: 2, paddingVertical: theme.spacing.xs, opacity: pressed ? 0.6 : 1 })}
|
|
94
|
+
>
|
|
95
|
+
<View style={{ flexDirection: 'row', alignItems: 'center', gap: theme.spacing.sm }}>
|
|
96
|
+
<Badge label={c.sourceLabel} variant="outline" />
|
|
97
|
+
<Text variant="caption">{c.dateLabel}</Text>
|
|
98
|
+
</View>
|
|
99
|
+
<Text style={{ color: theme.colors.primary, fontWeight: '600' }}>{c.title}</Text>
|
|
100
|
+
{c.quote ? <Text variant="muted" style={{ fontStyle: 'italic' }} numberOfLines={3}>{`โ${c.quote}โ`}</Text> : null}
|
|
101
|
+
</Pressable>
|
|
102
|
+
))}
|
|
103
|
+
{view.uncited.length ? (
|
|
104
|
+
<View style={{ gap: theme.spacing.xs }}>
|
|
105
|
+
<Pressable accessibilityRole="button" testID="ask-uncited-toggle" onPress={() => setShowUncited((v) => !v)}>
|
|
106
|
+
<Text variant="caption">{`${view.uncited.length} more record${view.uncited.length === 1 ? ' was' : 's were'} searched but not cited`}</Text>
|
|
107
|
+
</Pressable>
|
|
108
|
+
{showUncited ? view.uncited.map((u) => (
|
|
109
|
+
<Pressable key={u.documentId} accessibilityRole="button" onPress={() => onOpenDocument(u.documentId)}>
|
|
110
|
+
<Text variant="muted">{`${u.sourceLabel} ยท ${u.title}`}</Text>
|
|
111
|
+
</Pressable>
|
|
112
|
+
)) : null}
|
|
113
|
+
</View>
|
|
114
|
+
) : null}
|
|
115
|
+
<Text variant="caption">{view.provider}</Text>
|
|
116
|
+
</View>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An `AskResult` as a phone shows it: the answer, the caveats it owes, the
|
|
3
|
+
* records it cites and the one-sentence provenance. Pure; the strings come from
|
|
4
|
+
* `corpus/view-text.ts`, the same ones the web `AskPage` renders, so an answer
|
|
5
|
+
* says the same thing on both. Citations are not optional: an answer with no
|
|
6
|
+
* resolvable citation carries the unsourced warning first.
|
|
7
|
+
*/
|
|
8
|
+
import { formatDate } from '../../../components/documentText';
|
|
9
|
+
import type { AskResult, AskStatus } from '../../../corpus/types';
|
|
10
|
+
import {
|
|
11
|
+
UNCITED_NOTICE, droppedNotice, freshnessNotice, providerSentence, stripMarkdown, unresolvedNotice, withheldNotice,
|
|
12
|
+
} from '../../../corpus/view-text';
|
|
13
|
+
|
|
14
|
+
export interface AnswerNotice { tone: 'warning' | 'error'; text: string }
|
|
15
|
+
export interface AnswerCitation { documentId: string; title: string; sourceLabel: string; dateLabel: string; quote: string }
|
|
16
|
+
export interface AnswerView {
|
|
17
|
+
status: AskStatus;
|
|
18
|
+
text: string;
|
|
19
|
+
notices: AnswerNotice[];
|
|
20
|
+
citations: AnswerCitation[];
|
|
21
|
+
/** Searched, offered to the model, but not cited - so "why not the contract?" is answerable. */
|
|
22
|
+
uncited: Array<{ documentId: string; title: string; sourceLabel: string }>;
|
|
23
|
+
provider: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function answerView(result: AskResult): AnswerView {
|
|
27
|
+
const notices: AnswerNotice[] = [];
|
|
28
|
+
const add = (tone: AnswerNotice['tone'], text: string) => { if (text) notices.push({ tone, text }); };
|
|
29
|
+
if (result.status === 'uncited') add('warning', UNCITED_NOTICE);
|
|
30
|
+
if (result.status !== 'no_evidence') {
|
|
31
|
+
add('warning', freshnessNotice(result));
|
|
32
|
+
add('warning', withheldNotice(result));
|
|
33
|
+
add('warning', unresolvedNotice(result));
|
|
34
|
+
}
|
|
35
|
+
add('error', droppedNotice(result));
|
|
36
|
+
const cited = new Set(result.citations.map((c) => c.documentId));
|
|
37
|
+
return {
|
|
38
|
+
status: result.status,
|
|
39
|
+
text: result.answer,
|
|
40
|
+
notices,
|
|
41
|
+
citations: result.citations.map((c) => ({
|
|
42
|
+
documentId: c.documentId,
|
|
43
|
+
title: c.document.title,
|
|
44
|
+
sourceLabel: c.document.sourceLabel || c.document.source,
|
|
45
|
+
dateLabel: formatDate(c.document.occurredAt),
|
|
46
|
+
quote: stripMarkdown(c.quote ?? ''),
|
|
47
|
+
})),
|
|
48
|
+
uncited: result.considered.filter((r) => !cited.has(r.document.id)).map((r) => ({
|
|
49
|
+
documentId: r.document.id, title: r.document.title, sourceLabel: r.document.sourceLabel || r.document.source,
|
|
50
|
+
})),
|
|
51
|
+
provider: providerSentence(result.provider),
|
|
52
|
+
};
|
|
53
|
+
}
|