@startsimpli/integrations 0.2.60 → 0.2.62
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 +3 -3
- package/src/__tests__/filed-under-multi.test.tsx +33 -0
- package/src/__tests__/fixtures/voice-multitopic.ts +60 -0
- package/src/__tests__/voice-eval.test.ts +32 -0
- package/src/__tests__/voice-notes-page.test.tsx +36 -0
- package/src/__tests__/voice-quality.test.ts +1 -1
- package/src/__tests__/voice-sections.test.ts +306 -0
- package/src/components/FiledUnder.tsx +19 -13
- package/src/components/pages/VoiceNotesPage.tsx +42 -14
- package/src/corpus/client.ts +9 -2
- package/src/corpus/commitments.ts +5 -0
- package/src/corpus/entities.ts +4 -0
- package/src/corpus/extract.ts +24 -4
- package/src/corpus/filing.ts +57 -0
- package/src/corpus/index.ts +11 -0
- package/src/corpus/llm.ts +35 -10
- package/src/corpus/types.ts +23 -1
- package/src/corpus/voice-sections.ts +140 -0
- package/src/corpus/voice.ts +86 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.62",
|
|
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
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -79,9 +79,9 @@
|
|
|
79
79
|
"vitest": "^3.0.0",
|
|
80
80
|
"react-native": "0.85.3",
|
|
81
81
|
"react-native-safe-area-context": "~5.7.0",
|
|
82
|
-
"@startsimpli/
|
|
82
|
+
"@startsimpli/llm": "0.4.28",
|
|
83
83
|
"@startsimpli/ui": "0.4.167",
|
|
84
|
-
"@startsimpli/
|
|
84
|
+
"@startsimpli/ui-native": "0.1.0"
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|
|
87
87
|
"type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { cleanup, render, screen } from '@testing-library/react';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { FiledUnder } from '../components/FiledUnder';
|
|
7
|
+
|
|
8
|
+
afterEach(cleanup);
|
|
9
|
+
const cn = { badge: 'b', input: 'i', muted: 'm', error: 'e' };
|
|
10
|
+
const choices = async () => [{ id: 'a', title: 'A' }, { id: 'b', title: 'B' }];
|
|
11
|
+
|
|
12
|
+
describe('FiledUnder with several projects (a multi-topic voice note)', () => {
|
|
13
|
+
it('shows a chip per project and no single control that would collapse them', async () => {
|
|
14
|
+
const api = {
|
|
15
|
+
getDocumentFilings: vi.fn(async () => [{ id: 'a', title: '287A' }, { id: 'b', title: 'Debug' }]),
|
|
16
|
+
fileDocument: vi.fn(async () => undefined), listFocusChoices: choices,
|
|
17
|
+
};
|
|
18
|
+
render(<FiledUnder api={api} documentId="d" classNames={cn} />);
|
|
19
|
+
expect(await screen.findByText('287A')).toBeTruthy();
|
|
20
|
+
expect(screen.getByText('Debug')).toBeTruthy();
|
|
21
|
+
expect(screen.queryByLabelText('Change project')).toBeNull();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('one project keeps the change control; a client with only getDocumentFiling still works', async () => {
|
|
25
|
+
const api = {
|
|
26
|
+
getDocumentFiling: vi.fn(async () => ({ id: 'a', title: '287A' })),
|
|
27
|
+
fileDocument: vi.fn(async () => undefined), listFocusChoices: choices,
|
|
28
|
+
};
|
|
29
|
+
render(<FiledUnder api={api} documentId="d" classNames={cn} />);
|
|
30
|
+
expect(await screen.findByText('287A')).toBeTruthy();
|
|
31
|
+
expect(await screen.findByLabelText('Change project')).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A MULTI-TOPIC VOICE NOTE (bd startsim-ij1lw.6), in the shape of a real 3:28
|
|
3
|
+
* recording: four blocks, the last one introduced by the speaker as personal.
|
|
4
|
+
* Before sections it was filed wholly under 287A with 13 to-dos in one flat list.
|
|
5
|
+
*/
|
|
6
|
+
export const MULTI_FOCUSES = [
|
|
7
|
+
{ id: 'f-287a', title: '287A', detail: 'Legacy 287A matter-tracking product, port to Foundry' },
|
|
8
|
+
{ id: 'f-debug', title: 'Debug', detail: 'DebuggAI browser testing product' },
|
|
9
|
+
{ id: 'f-agents', title: 'Marketing agents', detail: 'OGMC marketing agents tenant' },
|
|
10
|
+
{ id: 'f-crochet', title: 'Crochets', detail: 'Crochet pattern marketplace' },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
export const MULTI_TRANSCRIPT = [
|
|
14
|
+
'Okay, a few things for the day. First, 287A. I need to port the matter import to Foundry, and Malin should review the schema mapping.',
|
|
15
|
+
'We also have to backfill the legacy matter owners, and make sure the invoice export matches the old report.',
|
|
16
|
+
'Next, Debug. I need to fix the tunnel timeout on the local runner, rerun the failing signup suite, and update the probe page docs.',
|
|
17
|
+
'Now marketing agents. Rotate the classifier prompt for the GCC feed, ask Dana to check the curated topics, and schedule the weekly digest review.',
|
|
18
|
+
'And on a personal note, I need to renew my passport, book the dentist for next month, and buy a birthday gift for my sister.',
|
|
19
|
+
].join(' ');
|
|
20
|
+
|
|
21
|
+
/** What a careful human would write down: sections, projects, and every to-do. */
|
|
22
|
+
export const MULTI_REPLY = {
|
|
23
|
+
title: 'Daily plan across projects',
|
|
24
|
+
summary: 'A day of work across 287A, Debug and marketing agents, plus personal errands.',
|
|
25
|
+
sections: [
|
|
26
|
+
{
|
|
27
|
+
label: '287A', kind: 'project', focusId: 'f-287a', summary: 'Port and cleanup work for the legacy matters.',
|
|
28
|
+
items: [
|
|
29
|
+
{ title: 'Port the matter import to Foundry' },
|
|
30
|
+
{ title: 'Review the schema mapping', owner: 'Malin' },
|
|
31
|
+
{ title: 'Backfill the legacy matter owners' },
|
|
32
|
+
{ title: 'Match the invoice export to the old report' },
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
label: 'Debug', kind: 'project', focusId: 'f-debug', summary: 'Runner and docs fixes.',
|
|
37
|
+
items: [
|
|
38
|
+
{ title: 'Fix the tunnel timeout on the local runner' },
|
|
39
|
+
{ title: 'Rerun the failing signup suite' },
|
|
40
|
+
{ title: 'Update the probe page docs' },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
label: 'Marketing agents', kind: 'project', focusId: 'f-agents', summary: 'GCC feed and digest upkeep.',
|
|
45
|
+
items: [
|
|
46
|
+
{ title: 'Rotate the classifier prompt for the GCC feed' },
|
|
47
|
+
{ title: 'Check the curated topics', owner: 'Dana' },
|
|
48
|
+
{ title: 'Schedule the weekly digest review' },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
label: 'Personal', kind: 'personal', focusId: null, summary: 'Errands, introduced as personal.',
|
|
53
|
+
items: [
|
|
54
|
+
{ title: 'Renew my passport' },
|
|
55
|
+
{ title: 'Book the dentist for next month' },
|
|
56
|
+
{ title: 'Buy a birthday gift for my sister' },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
};
|
|
@@ -13,6 +13,7 @@ import { describe, expect, it } from 'vitest';
|
|
|
13
13
|
|
|
14
14
|
import { createVoiceAnalyzer, createVoiceTranscriber } from '../corpus/llm';
|
|
15
15
|
import { GOLDEN_CLIPS, GOLDEN_FOCUSES } from './fixtures/voice-golden';
|
|
16
|
+
import { MULTI_FOCUSES, MULTI_REPLY, MULTI_TRANSCRIPT } from './fixtures/voice-multitopic';
|
|
16
17
|
import { aggregate, commitmentsFromSummary, scoreClip, PRECISION_FLOOR, RECALL_FLOOR } from './helpers/voice-eval';
|
|
17
18
|
|
|
18
19
|
const enabled = process.env.VOICE_EVAL === '1';
|
|
@@ -52,3 +53,34 @@ describe.skipIf(!enabled || !hasSay)('golden clips with real models', () => {
|
|
|
52
53
|
expect(focusRight).toBe(GOLDEN_CLIPS.length);
|
|
53
54
|
}, 600_000);
|
|
54
55
|
});
|
|
56
|
+
|
|
57
|
+
/** bd startsim-ij1lw.6: the multi-topic shape with a real model, text only (no audio, so no `say` needed). */
|
|
58
|
+
describe.skipIf(!enabled)('multi-topic note with a real model', () => {
|
|
59
|
+
it('splits into the four sections, files three projects, keeps personal unfiled, finds the to-dos', async () => {
|
|
60
|
+
const out = await createVoiceAnalyzer().analyze({ transcript: MULTI_TRANSCRIPT, focuses: MULTI_FOCUSES });
|
|
61
|
+
console.log(JSON.stringify({ calls: out.usage?.calls, sections: out.sections?.map((x) => [x.label, x.kind, x.focusId, x.items.length]) }));
|
|
62
|
+
expect(out.usage?.calls).toBe(1);
|
|
63
|
+
const byFocus = new Map(out.sections!.map((x) => [x.focusId, x]));
|
|
64
|
+
for (const want of MULTI_REPLY.sections.filter((x) => x.focusId)) expect(byFocus.has(want.focusId)).toBe(true);
|
|
65
|
+
const personal = out.sections!.find((x) => x.kind === 'personal');
|
|
66
|
+
expect(personal?.focusId).toBeNull();
|
|
67
|
+
expect(personal?.items.length).toBeGreaterThanOrEqual(3);
|
|
68
|
+
expect(commitmentsFromSummary(out.summary).length).toBeGreaterThanOrEqual(12);
|
|
69
|
+
}, 120_000);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
/** The existing golden clips, text only: proves the sections prompt did not lower recall on single-topic notes. */
|
|
73
|
+
describe.skipIf(!enabled)('golden clip text with the sections prompt', () => {
|
|
74
|
+
it('holds the recall and precision floors', async () => {
|
|
75
|
+
const analyzer = createVoiceAnalyzer();
|
|
76
|
+
const scores = [];
|
|
77
|
+
for (const clip of GOLDEN_CLIPS) {
|
|
78
|
+
const a = await analyzer.analyze({ transcript: clip.text, focuses: GOLDEN_FOCUSES });
|
|
79
|
+
scores.push(scoreClip(clip, commitmentsFromSummary(a.summary)));
|
|
80
|
+
}
|
|
81
|
+
const agg = aggregate(scores);
|
|
82
|
+
console.log(JSON.stringify(agg));
|
|
83
|
+
expect(agg.recall).toBeGreaterThanOrEqual(RECALL_FLOOR);
|
|
84
|
+
expect(agg.precision).toBeGreaterThanOrEqual(PRECISION_FLOOR);
|
|
85
|
+
}, 300_000);
|
|
86
|
+
});
|
|
@@ -32,6 +32,42 @@ describe('helpers', () => {
|
|
|
32
32
|
it('formats m:ss', () => expect(formatDuration(65_000)).toBe('1:05'));
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
+
describe('VoiceNotesPage: a note with sections', () => {
|
|
36
|
+
const sectioned = () => note({
|
|
37
|
+
summary: 'Overall.\n\n## 287A\n- **Port the matter import**\n\n## Personal\n- **Renew my passport now**',
|
|
38
|
+
focusId: 'f1', focusIds: ['f1'],
|
|
39
|
+
sections: [
|
|
40
|
+
{ label: '287A', kind: 'project', focusId: 'f1' },
|
|
41
|
+
{ label: 'Personal', kind: 'personal', focusId: null },
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('shows one project control per section, the personal one unfiled, and no single project control', async () => {
|
|
46
|
+
render(<VoiceNotesPage api={api({ list: vi.fn(async () => [sectioned()]), fileSection: vi.fn(async () => undefined) })} />);
|
|
47
|
+
const first = await screen.findByLabelText('Project for 287A') as HTMLSelectElement;
|
|
48
|
+
const personal = await screen.findByLabelText('Project for Personal') as HTMLSelectElement;
|
|
49
|
+
await waitFor(() => expect(first.value).toBe('f1'));
|
|
50
|
+
expect(personal.value).toBe('');
|
|
51
|
+
expect(screen.queryByLabelText('Project for Checkout bug')).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('changing one section calls fileSection with its index, and rolls back on failure', async () => {
|
|
55
|
+
const fileSection = vi.fn(async () => { throw new Error('refused'); });
|
|
56
|
+
render(<VoiceNotesPage api={api({ list: vi.fn(async () => [sectioned()]), fileSection })} />);
|
|
57
|
+
const personal = await screen.findByLabelText('Project for Personal') as HTMLSelectElement;
|
|
58
|
+
await waitFor(() => expect(personal.options.length).toBe(3));
|
|
59
|
+
fireEvent.change(personal, { target: { value: 'f2' } });
|
|
60
|
+
expect(fileSection).toHaveBeenCalledWith('n1', 1, 'f2');
|
|
61
|
+
expect((await screen.findByRole('alert')).textContent).toMatch(/refused/);
|
|
62
|
+
await waitFor(() => expect(personal.value).toBe(''));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('a client without fileSection keeps the single control (it moves the whole note)', async () => {
|
|
66
|
+
render(<VoiceNotesPage api={api({ list: vi.fn(async () => [sectioned()]) })} />);
|
|
67
|
+
expect(await screen.findByLabelText('Project for Checkout bug')).toBeTruthy();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
35
71
|
describe('VoiceNotesPage', () => {
|
|
36
72
|
it('shows the note with its project selected, summary, and transcript', async () => {
|
|
37
73
|
render(<VoiceNotesPage api={api()} />);
|
|
@@ -115,7 +115,7 @@ describe('a summary that lost the to-dos gets one repair of the same call', () =
|
|
|
115
115
|
// The repair is the SAME call plus what went wrong, not a new prompt.
|
|
116
116
|
const [secondUser, secondSystem] = service.chat.mock.calls[1];
|
|
117
117
|
expect(secondUser).toContain(service.chat.mock.calls[0][0]);
|
|
118
|
-
expect(secondUser).toMatch(/
|
|
118
|
+
expect(secondUser).toMatch(/no section has any items|items entry/i);
|
|
119
119
|
expect(secondSystem).toBe(service.chat.mock.calls[0][1]);
|
|
120
120
|
});
|
|
121
121
|
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { toSourceDocument } from '../corpus/entities';
|
|
4
|
+
import { rulesExtract } from '../corpus/extract';
|
|
5
|
+
import { createVoiceAnalyzer, parseVoiceAnalysis, renderVoicePrompt, voiceSystemPrompt } from '../corpus/llm';
|
|
6
|
+
import { createCorpusApi } from '../corpus/client';
|
|
7
|
+
import { extractCommitments } from '../corpus/extract';
|
|
8
|
+
import { createVoiceApi, finishVoiceNote, startVoiceNote, toVoiceNote, voiceToEntity, type VoiceDeps } from '../corpus/voice';
|
|
9
|
+
import { commitmentsFromSummary } from './helpers/voice-eval';
|
|
10
|
+
import { MULTI_FOCUSES, MULTI_REPLY, MULTI_TRANSCRIPT } from './fixtures/voice-multitopic';
|
|
11
|
+
|
|
12
|
+
const reply = (over: Record<string, unknown> = {}) => JSON.stringify({ ...MULTI_REPLY, ...over });
|
|
13
|
+
function fakeService(replies: string[]) {
|
|
14
|
+
const chat = vi.fn(async () => ({
|
|
15
|
+
content: replies[Math.min(chat.mock.calls.length - 1, replies.length - 1)],
|
|
16
|
+
usage: { promptTokens: 900, completionTokens: 400, totalTokens: 1300 }, model: 'm', provider: 'p',
|
|
17
|
+
}));
|
|
18
|
+
return { chat, isAvailable: () => true, getAvailableProviders: () => ['p'] } as any;
|
|
19
|
+
}
|
|
20
|
+
const voiceDoc = (summary: string, extra: Record<string, unknown> = {}, source = 'voice') =>
|
|
21
|
+
toSourceDocument({ id: 'doc-1', name: 'n', data: { source, title: 't', summary, body: MULTI_TRANSCRIPT, ...extra } } as never, { orgId: 'o' } as never);
|
|
22
|
+
|
|
23
|
+
describe('multi-topic note: parse + render', () => {
|
|
24
|
+
const parsed = parseVoiceAnalysis(reply(), MULTI_FOCUSES)!;
|
|
25
|
+
|
|
26
|
+
it('returns four sections, with the personal one unfiled but labelled', () => {
|
|
27
|
+
expect(parsed.sections!.map((s) => [s.label, s.kind, s.focusId])).toEqual([
|
|
28
|
+
['287A', 'project', 'f-287a'], ['Debug', 'project', 'f-debug'],
|
|
29
|
+
['Marketing agents', 'project', 'f-agents'], ['Personal', 'personal', null],
|
|
30
|
+
]);
|
|
31
|
+
expect(parsed.sections!.map((s) => s.items.length)).toEqual([4, 3, 3, 3]);
|
|
32
|
+
expect(parsed.focusId).toBe('f-287a'); // dominant = first filed section, for old callers
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('writes one overall sentence, then a ## heading per section with bold bullets', () => {
|
|
36
|
+
const lines = parsed.summary.split('\n');
|
|
37
|
+
expect(lines[0]).toBe(MULTI_REPLY.summary);
|
|
38
|
+
expect(parsed.summary.match(/^## /gm)).toHaveLength(4);
|
|
39
|
+
expect(parsed.summary).toContain('## Personal\n');
|
|
40
|
+
expect(parsed.summary).toContain('- **Review the schema mapping** (Malin)');
|
|
41
|
+
expect(parsed.summary).not.toContain('## Next Steps');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('drops a focus id that was not offered and keeps the section', () => {
|
|
45
|
+
const out = parseVoiceAnalysis(reply({ sections: [{ ...MULTI_REPLY.sections[0], focusId: 'f-attacker' }] }), MULTI_FOCUSES)!;
|
|
46
|
+
expect(out.sections![0].focusId).toBeNull();
|
|
47
|
+
expect(out.focusId).toBeNull();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('cleans labels so they cannot forge headings, and keeps duplicate labels distinct', () => {
|
|
51
|
+
const s = (label: string) => ({ ...MULTI_REPLY.sections[1], label });
|
|
52
|
+
const out = parseVoiceAnalysis(reply({ sections: [s('## Debug\n## Evil'), s('Debug'), s('debug')] }), MULTI_FOCUSES)!;
|
|
53
|
+
const labels = out.sections!.map((x) => x.label);
|
|
54
|
+
expect(new Set(labels.map((l) => l.toLowerCase())).size).toBe(3);
|
|
55
|
+
expect(labels.every((l) => !/[#\n]/.test(l))).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('still reads the old single-focus shape', () => {
|
|
59
|
+
const out = parseVoiceAnalysis('{"title":"T","summary":"One.\\n\\n## Next Steps\\n- **Fix the checkout bug**","focusId":"f-crochet"}', MULTI_FOCUSES)!;
|
|
60
|
+
expect(out.focusId).toBe('f-crochet');
|
|
61
|
+
expect(out.sections ?? []).toEqual([]);
|
|
62
|
+
expect(out.summary).toContain('## Next Steps');
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('every to-do still becomes a commitment (the format contract)', () => {
|
|
67
|
+
const parsed = parseVoiceAnalysis(reply(), MULTI_FOCUSES)!;
|
|
68
|
+
|
|
69
|
+
it('rulesExtract finds all 13, owners intact, personal ones included', () => {
|
|
70
|
+
const found = commitmentsFromSummary(parsed.summary);
|
|
71
|
+
expect(found).toHaveLength(13);
|
|
72
|
+
expect(found.find((c) => /schema mapping/.test(c.title))?.owner).toBe('Malin');
|
|
73
|
+
expect(found.some((c) => /passport/.test(c.title))).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('only a VOICE note reads bullets under any heading — other sources keep the outcome-heading rule', () => {
|
|
77
|
+
const summary = 'Talk.\n\n## Discussion\n- **Fix the checkout bug now**';
|
|
78
|
+
expect(rulesExtract(voiceDoc(summary, {}, 'voice'))).toHaveLength(1);
|
|
79
|
+
expect(rulesExtract(voiceDoc(summary, {}, 'fathom'))).toHaveLength(0);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('each draft carries its section project; personal and unmatched are unfiled', () => {
|
|
83
|
+
const doc = voiceDoc(parsed.summary, { voice_sections: [
|
|
84
|
+
{ label: '287A', kind: 'project', focus_id: 'f-287a' }, { label: 'Debug', kind: 'project', focus_id: 'f-debug' },
|
|
85
|
+
{ label: 'Marketing agents', kind: 'project', focus_id: 'f-agents' }, { label: 'Personal', kind: 'personal', focus_id: null },
|
|
86
|
+
] });
|
|
87
|
+
const drafts = rulesExtract(doc);
|
|
88
|
+
const by = (re: RegExp) => drafts.find((d) => re.test(d.title))!.focusId;
|
|
89
|
+
expect(by(/matter import/)).toBe('f-287a');
|
|
90
|
+
expect(by(/tunnel timeout/)).toBe('f-debug');
|
|
91
|
+
expect(by(/digest review/)).toBe('f-agents');
|
|
92
|
+
expect(by(/passport/)).toBeUndefined();
|
|
93
|
+
// camelCase spelling (the API client camel-cases inside data) reads the same
|
|
94
|
+
const camel = voiceDoc(parsed.summary, { voiceSections: [{ label: 'Debug', kind: 'project', focusId: 'f-debug' }] });
|
|
95
|
+
expect(rulesExtract(camel).find((d) => /tunnel/.test(d.title))!.focusId).toBe('f-debug');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('section bullets are not extracted twice (sections live under voice_sections, not data.sections)', () => {
|
|
99
|
+
const entity = voiceToEntity({ noteId: 'n', title: 'T', status: 'ready', occurredAt: 'x', summary: parsed.summary, body: MULTI_TRANSCRIPT, sections: parsed.sections });
|
|
100
|
+
expect(entity.data).not.toHaveProperty('sections');
|
|
101
|
+
expect(entity.data.voice_sections).toEqual([
|
|
102
|
+
{ label: '287A', kind: 'project', focus_id: 'f-287a' }, { label: 'Debug', kind: 'project', focus_id: 'f-debug' },
|
|
103
|
+
{ label: 'Marketing agents', kind: 'project', focus_id: 'f-agents' }, { label: 'Personal', kind: 'personal', focus_id: null },
|
|
104
|
+
]);
|
|
105
|
+
expect(rulesExtract(toSourceDocument({ id: 'd', name: 'n', data: entity.data } as never, { orgId: 'o' } as never))).toHaveLength(13);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('the analyzer: still ONE model call', () => {
|
|
110
|
+
it('asks for sections and honours spoken cues', () => {
|
|
111
|
+
const system = voiceSystemPrompt();
|
|
112
|
+
expect(system).toMatch(/sections/);
|
|
113
|
+
expect(system).toMatch(/personal/i);
|
|
114
|
+
expect(system).toMatch(/at least three words/);
|
|
115
|
+
expect(renderVoicePrompt({ transcript: MULTI_TRANSCRIPT, focuses: MULTI_FOCUSES })).toContain('f-287a');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('one call for the real-shaped note, sections out', async () => {
|
|
119
|
+
const service = fakeService([reply()]);
|
|
120
|
+
const out = await createVoiceAnalyzer({ service }).analyze({ transcript: MULTI_TRANSCRIPT, focuses: MULTI_FOCUSES });
|
|
121
|
+
expect(service.chat).toHaveBeenCalledTimes(1);
|
|
122
|
+
expect(out.usage?.calls).toBe(1);
|
|
123
|
+
expect(out.sections).toHaveLength(4);
|
|
124
|
+
expect(commitmentsFromSummary(out.summary)).toHaveLength(13);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('a reply with sections but no items gets the single repair, which asks for sections', async () => {
|
|
128
|
+
const empty = reply({ sections: MULTI_REPLY.sections.map((s) => ({ ...s, items: [] })) });
|
|
129
|
+
const service = fakeService([empty, reply()]);
|
|
130
|
+
const out = await createVoiceAnalyzer({ service }).analyze({ transcript: MULTI_TRANSCRIPT, focuses: MULTI_FOCUSES });
|
|
131
|
+
expect(service.chat).toHaveBeenCalledTimes(2);
|
|
132
|
+
expect((service.chat.mock.calls as any)[1][0]).toMatch(/sections/);
|
|
133
|
+
expect(out.sections![0].items).toHaveLength(4);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe('filing: one about_focus edge per section project', () => {
|
|
138
|
+
const sub = { noteId: 'n1', audio: new Uint8Array([1]), mimeType: 'audio/webm' };
|
|
139
|
+
function harness(analysis: unknown, failTarget?: string) {
|
|
140
|
+
const posts: Array<{ path: string; body: any }> = [];
|
|
141
|
+
const d: VoiceDeps = {
|
|
142
|
+
http: { get: vi.fn(), post: vi.fn(async (path: string, body: any) => {
|
|
143
|
+
if (failTarget && body?.target === failTarget) throw new Error('refused');
|
|
144
|
+
posts.push({ path, body }); return { id: 'doc-1' } as never;
|
|
145
|
+
}) } as never,
|
|
146
|
+
transcriber: { transcribe: vi.fn(async () => MULTI_TRANSCRIPT) },
|
|
147
|
+
analyzer: { analyze: vi.fn(async () => analysis as never) },
|
|
148
|
+
store: { put: vi.fn(async () => 's3://x') },
|
|
149
|
+
listFocuses: async () => MULTI_FOCUSES,
|
|
150
|
+
now: () => new Date('2026-11-02T12:00:00Z'),
|
|
151
|
+
};
|
|
152
|
+
return { d, posts };
|
|
153
|
+
}
|
|
154
|
+
const analysis = () => parseVoiceAnalysis(reply(), MULTI_FOCUSES)!;
|
|
155
|
+
const edges = (posts: any[]) => posts.filter((p) => p.path === 'api/v1/relationships').map((p) => p.body);
|
|
156
|
+
|
|
157
|
+
it('writes three edges (not four: personal has none), saves voice_sections on the row', async () => {
|
|
158
|
+
const { d, posts } = harness(analysis());
|
|
159
|
+
const done = await finishVoiceNote(await startVoiceNote(sub, d), sub, d);
|
|
160
|
+
expect(edges(posts).map((e) => e.target)).toEqual(['f-287a', 'f-debug', 'f-agents']);
|
|
161
|
+
expect(edges(posts).every((e) => e.rel_type === 'about_focus' && e.source === 'doc-1')).toBe(true);
|
|
162
|
+
expect(done.focusIds).toEqual(['f-287a', 'f-debug', 'f-agents']);
|
|
163
|
+
const ready = posts.find((p) => p.body?.data?.voice_status === 'ready')!;
|
|
164
|
+
expect(ready.body.data.voice_sections).toHaveLength(4);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('two sections under one project share one edge', async () => {
|
|
168
|
+
const a = analysis();
|
|
169
|
+
a.sections![1].focusId = 'f-287a';
|
|
170
|
+
const { d, posts } = harness(a);
|
|
171
|
+
await finishVoiceNote(await startVoiceNote(sub, d), sub, d);
|
|
172
|
+
expect(edges(posts).filter((e) => e.target === 'f-287a')).toHaveLength(1);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('a refused edge leaves the rest filed and reports the error', async () => {
|
|
176
|
+
const { d, posts } = harness(analysis(), 'f-debug');
|
|
177
|
+
const done = await finishVoiceNote(await startVoiceNote(sub, d), sub, d);
|
|
178
|
+
expect(edges(posts).map((e) => e.target)).toEqual(['f-287a', 'f-agents']);
|
|
179
|
+
expect(done.filingError).toMatch(/refused/);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('an old-shape analysis (no sections) files one edge exactly as before', async () => {
|
|
183
|
+
const { d, posts } = harness({ title: 'T', summary: '- fix', focusId: 'f-crochet' });
|
|
184
|
+
const done = await finishVoiceNote(await startVoiceNote(sub, d), sub, d);
|
|
185
|
+
expect(edges(posts)).toEqual([{ rel_type: 'about_focus', source: 'doc-1', target: 'f-crochet' }]);
|
|
186
|
+
expect(done.focusId).toBe('f-crochet');
|
|
187
|
+
expect(posts.find((p) => p.body?.data?.voice_status === 'ready')!.body.data).not.toHaveProperty('voice_sections');
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe('the page client: many projects per note, each changeable', () => {
|
|
192
|
+
const row = {
|
|
193
|
+
id: 'doc-1', name: 'Plan', external_id: 'voice:n1',
|
|
194
|
+
data: { source: 'voice', title: 'Plan', voice_status: 'ready', summary: 's', voice_sections: [
|
|
195
|
+
{ label: '287A', kind: 'project', focus_id: 'f-287a' }, { label: 'Personal', kind: 'personal', focus_id: null },
|
|
196
|
+
] },
|
|
197
|
+
};
|
|
198
|
+
it('toVoiceNote exposes sections and the focus ids of its edges', () => {
|
|
199
|
+
const note = toVoiceNote(row as never, ['f-287a']);
|
|
200
|
+
expect(note.focusIds).toEqual(['f-287a']);
|
|
201
|
+
expect(note.focusId).toBe('f-287a');
|
|
202
|
+
expect(note.sections).toEqual([
|
|
203
|
+
{ label: '287A', kind: 'project', focusId: 'f-287a' }, { label: 'Personal', kind: 'personal', focusId: null },
|
|
204
|
+
]);
|
|
205
|
+
expect(toVoiceNote({ id: 'x', name: 'n', data: {} } as never, null).sections).toEqual([]);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
function api() {
|
|
209
|
+
const posts: any[] = []; const deletes: string[] = [];
|
|
210
|
+
let edgeRows: any[] = [{ id: 'e1', source: 'doc-1', target: 'f-287a' }, { id: 'e2', source: 'doc-1', target: 'f-old' }];
|
|
211
|
+
const http = {
|
|
212
|
+
get: vi.fn(async (path: string) => path === 'api/v1/entities' ? { results: [row] } : path === 'api/v1/relationships' ? { results: edgeRows } : row),
|
|
213
|
+
post: vi.fn(async (path: string, body: unknown) => { posts.push({ path, body }); return row; }),
|
|
214
|
+
delete: vi.fn(async (path: string) => { deletes.push(path); }),
|
|
215
|
+
};
|
|
216
|
+
return { posts, deletes, http, voice: createVoiceApi({ http: http as never, scope: { orgId: 'o' } as never, upload: async () => ({ id: 'x' }) }) };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
it('list() keeps every edge of a note', async () => {
|
|
220
|
+
const { voice } = api();
|
|
221
|
+
const [note] = await voice.list();
|
|
222
|
+
expect(note.focusIds).toEqual(['f-287a', 'f-old']);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('fileSection rewrites that section in voice_sections and replaces the edges with the union', async () => {
|
|
226
|
+
const { voice, posts, deletes } = api();
|
|
227
|
+
await voice.fileSection!('doc-1', 1, 'f-crochet');
|
|
228
|
+
const upsert = posts.find((p) => p.path === 'api/v1/entities/upsert')!;
|
|
229
|
+
expect(upsert.body.external_id).toBe('voice:n1');
|
|
230
|
+
expect(upsert.body.data.voice_sections).toEqual([
|
|
231
|
+
{ label: '287A', kind: 'project', focus_id: 'f-287a' }, { label: 'Personal', kind: 'personal', focus_id: 'f-crochet' },
|
|
232
|
+
]);
|
|
233
|
+
expect(deletes).toEqual(['api/v1/relationships/e2']); // only the edge no section wants
|
|
234
|
+
expect(posts.filter((p) => p.path === 'api/v1/relationships').map((p) => p.body.target)).toEqual(['f-crochet']);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('fileSection(null) unfiles one section without touching the others', async () => {
|
|
238
|
+
const { voice, posts, deletes } = api();
|
|
239
|
+
await voice.fileSection!('doc-1', 0, null);
|
|
240
|
+
const upsert = posts.find((p) => p.path === 'api/v1/entities/upsert')!;
|
|
241
|
+
expect(upsert.body.data.voice_sections[0].focus_id).toBeNull();
|
|
242
|
+
expect(deletes.sort()).toEqual(['api/v1/relationships/e1', 'api/v1/relationships/e2']);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe('commitments land in their section\'s project', () => {
|
|
247
|
+
const parsed = parseVoiceAnalysis(reply(), MULTI_FOCUSES)!;
|
|
248
|
+
const filings = parsed.sections!.map((x) => ({ label: x.label, kind: x.kind, focus_id: x.focusId }));
|
|
249
|
+
const doc = () => voiceDoc(parsed.summary, { voice_sections: filings });
|
|
250
|
+
const noModel = { extract: async () => ({ items: [], resolutions: [] }), verify: async () => [], describe: () => 'none' } as never;
|
|
251
|
+
|
|
252
|
+
function corpus(stored: any[] = []) {
|
|
253
|
+
const calls: Array<{ n: number; options: any }> = [];
|
|
254
|
+
return {
|
|
255
|
+
calls,
|
|
256
|
+
api: {
|
|
257
|
+
listDocuments: async () => ({ count: 1, next: null, previous: null, results: [doc()] }),
|
|
258
|
+
getDocument: async () => doc(),
|
|
259
|
+
listParties: async () => ({ count: 0, next: null, previous: null, results: [] }),
|
|
260
|
+
listSources: async () => [],
|
|
261
|
+
listCommitments: async () => ({ count: stored.length, next: null, previous: null, results: stored }),
|
|
262
|
+
saveCommitments: async (items: any[], options?: any) => { calls.push({ n: items.length, options }); stored.splice(0, stored.length, ...items); },
|
|
263
|
+
} as never,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
it('files the 13 created rows by section project: 10 under projects, the personal 3 unfiled', async () => {
|
|
268
|
+
const { api, calls } = corpus();
|
|
269
|
+
await extractCommitments({ scope: { orgId: 'o' } as never }, { corpus: api, extractor: noModel });
|
|
270
|
+
expect(calls).toHaveLength(1);
|
|
271
|
+
expect(calls[0].n).toBe(13);
|
|
272
|
+
const targets = Object.values(calls[0].options.fileUnder as Record<string, string>);
|
|
273
|
+
expect(targets).toHaveLength(10);
|
|
274
|
+
expect(targets.filter((t) => t === 'f-287a')).toHaveLength(4);
|
|
275
|
+
expect(targets.filter((t) => t === 'f-debug')).toHaveLength(3);
|
|
276
|
+
expect(targets.filter((t) => t === 'f-agents')).toHaveLength(3);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('a second run files nothing again (a person may have moved a row)', async () => {
|
|
280
|
+
const stored: any[] = [];
|
|
281
|
+
const { api, calls } = corpus(stored);
|
|
282
|
+
await extractCommitments({ scope: { orgId: 'o' } as never }, { corpus: api, extractor: noModel });
|
|
283
|
+
await extractCommitments({ scope: { orgId: 'o' } as never }, { corpus: api, extractor: noModel });
|
|
284
|
+
expect(calls.slice(1).every((c) => !c.options?.fileUnder)).toBe(true);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('the client writes in_focus with the id the tenant returned, for the rows named', async () => {
|
|
288
|
+
const posts: Array<{ path: string; body: any }> = [];
|
|
289
|
+
const http = {
|
|
290
|
+
get: vi.fn(async () => ({ results: [] })),
|
|
291
|
+
post: vi.fn(async (path: string, body: any) => { posts.push({ path, body }); return { id: `ent-${body.external_id ?? 'x'}` }; }),
|
|
292
|
+
};
|
|
293
|
+
const api = createCorpusApi({ http: http as never, scope: { orgId: 'o' } as never });
|
|
294
|
+
const real: any[] = [];
|
|
295
|
+
const { api: stub } = corpus();
|
|
296
|
+
await extractCommitments({ scope: { orgId: 'o' } as never }, {
|
|
297
|
+
corpus: { ...(stub as object), saveCommitments: async (items: any[]) => { real.push(...items); } } as never,
|
|
298
|
+
extractor: noModel,
|
|
299
|
+
});
|
|
300
|
+
const one = real.find((c) => /tunnel/.test(c.title));
|
|
301
|
+
const two = real.find((c) => /passport/.test(c.title));
|
|
302
|
+
await api.saveCommitments!([one, two], { fileUnder: { [one.externalId]: 'f-debug' } });
|
|
303
|
+
const edges = posts.filter((p) => p.path === 'api/v1/relationships');
|
|
304
|
+
expect(edges).toEqual([{ path: 'api/v1/relationships', body: { rel_type: 'in_focus', source: `ent-${one.externalId}`, target: 'f-debug' } }]);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
@@ -16,29 +16,33 @@ type Slots = Record<'badge' | 'input' | 'muted' | 'error', string>;
|
|
|
16
16
|
export function FiledUnder({
|
|
17
17
|
api, documentId, classNames: cn,
|
|
18
18
|
}: {
|
|
19
|
-
api: Pick<CorpusApi, 'getDocumentFiling' | 'fileDocument' | 'listFocusChoices'>;
|
|
19
|
+
api: Pick<CorpusApi, 'getDocumentFiling' | 'getDocumentFilings' | 'fileDocument' | 'listFocusChoices'>;
|
|
20
20
|
documentId: string;
|
|
21
21
|
classNames: Slots;
|
|
22
22
|
}) {
|
|
23
23
|
const apiRef = React.useRef(api);
|
|
24
24
|
apiRef.current = api;
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
// Every project the document is filed under (several for a multi-topic voice note).
|
|
27
|
+
const [filings, setFilings] = React.useState<Array<{ id: string; title: string }> | undefined>(undefined);
|
|
27
28
|
const [choices, setChoices] = React.useState<Array<{ id: string; title: string }>>([]);
|
|
28
29
|
const [busy, setBusy] = React.useState(false);
|
|
29
30
|
const [error, setError] = React.useState('');
|
|
30
31
|
|
|
31
|
-
const canRead = Boolean(api.getDocumentFiling);
|
|
32
|
+
const canRead = Boolean(api.getDocumentFilings || api.getDocumentFiling);
|
|
32
33
|
const canFile = Boolean(api.fileDocument && api.listFocusChoices);
|
|
33
34
|
|
|
34
35
|
React.useEffect(() => {
|
|
35
36
|
if (!canRead) return undefined;
|
|
36
37
|
let live = true;
|
|
37
|
-
|
|
38
|
+
setFilings(undefined);
|
|
38
39
|
setError('');
|
|
39
|
-
apiRef.current.
|
|
40
|
-
.
|
|
41
|
-
.
|
|
40
|
+
const read = apiRef.current.getDocumentFilings
|
|
41
|
+
? apiRef.current.getDocumentFilings(documentId)
|
|
42
|
+
: apiRef.current.getDocumentFiling!(documentId).then((one) => (one ? [one] : []));
|
|
43
|
+
read
|
|
44
|
+
.then((result) => { if (live) setFilings(result); })
|
|
45
|
+
.catch(() => { if (live) { setFilings(undefined); setError('Where this is filed could not be read.'); } });
|
|
42
46
|
return () => { live = false; };
|
|
43
47
|
}, [canRead, documentId]);
|
|
44
48
|
|
|
@@ -59,7 +63,7 @@ export function FiledUnder({
|
|
|
59
63
|
try {
|
|
60
64
|
await apiRef.current.fileDocument!(documentId, focusId);
|
|
61
65
|
const chosen = choices.find((choice) => choice.id === focusId);
|
|
62
|
-
|
|
66
|
+
setFilings(chosen ? [{ id: chosen.id, title: chosen.title }] : []);
|
|
63
67
|
} catch (err) {
|
|
64
68
|
setError((err as { message?: string })?.message || 'That could not be filed.');
|
|
65
69
|
} finally {
|
|
@@ -70,16 +74,18 @@ export function FiledUnder({
|
|
|
70
74
|
return (
|
|
71
75
|
<div className="mt-3 flex flex-wrap items-center gap-2">
|
|
72
76
|
<p className="text-sm font-medium text-gray-900">Filed under</p>
|
|
73
|
-
{
|
|
74
|
-
{filing
|
|
75
|
-
{
|
|
76
|
-
{
|
|
77
|
+
{filings === undefined && !error ? <span className={cn.muted}>…</span> : null}
|
|
78
|
+
{filings?.map((filing) => <span key={filing.id} className={cn.badge}>{filing.title}</span>)}
|
|
79
|
+
{filings?.length === 0 ? <span className={cn.muted}>Not filed under a project</span> : null}
|
|
80
|
+
{/* Several projects (a multi-topic voice note): one control would collapse them
|
|
81
|
+
to one, so each is changed per section on the Voice notes page instead. */}
|
|
82
|
+
{canFile && filings !== undefined && filings.length <= 1 ? (
|
|
77
83
|
<label>
|
|
78
84
|
<span className="sr-only">Change project</span>
|
|
79
85
|
<select
|
|
80
86
|
className={cn.input}
|
|
81
87
|
disabled={busy}
|
|
82
|
-
value={
|
|
88
|
+
value={filings?.[0]?.id ?? ''}
|
|
83
89
|
onChange={(event) => { void move(event.target.value || null); }}
|
|
84
90
|
>
|
|
85
91
|
<option value="">Not filed</option>
|