@startsimpli/integrations 0.2.224 → 0.2.226
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 +6 -6
- package/src/__tests__/attention-importance.test.ts +51 -0
- package/src/__tests__/attention-policy.test.ts +7 -7
- package/src/__tests__/attention-run.test.ts +15 -6
- package/src/__tests__/attention-settings.test.ts +3 -3
- package/src/__tests__/converse-meeting-interrupted.test.ts +74 -0
- package/src/__tests__/converse-roci-transcript.test.ts +36 -0
- package/src/__tests__/converse-roci.test.ts +16 -1
- package/src/__tests__/converse-tts.test.ts +128 -0
- package/src/__tests__/converse.test.ts +15 -0
- package/src/__tests__/relay-items.test.ts +89 -0
- package/src/corpus/attention/importance.ts +17 -0
- package/src/corpus/attention/index.ts +1 -0
- package/src/corpus/attention/policy.ts +3 -1
- package/src/corpus/attention/push.ts +1 -1
- package/src/corpus/attention/queue.ts +11 -7
- package/src/corpus/attention/run-steps.ts +3 -2
- package/src/corpus/attention/run.ts +15 -5
- package/src/corpus/attention/types.ts +17 -5
- package/src/corpus/converse/handle.ts +5 -2
- package/src/corpus/converse/meeting.ts +20 -3
- package/src/corpus/converse/respond.ts +1 -1
- package/src/corpus/converse/roci.ts +11 -4
- package/src/corpus/converse/speak-chunks.ts +33 -0
- package/src/corpus/converse/speak.ts +17 -4
- package/src/corpus/notify/index.ts +2 -0
- package/src/corpus/notify/relay-items.ts +53 -0
- package/src/corpus/notify/respond.ts +6 -0
- package/src/corpus/notify/state.ts +1 -0
- package/src/corpus/notify/types.ts +6 -1
- package/src/native/app/FoundryApp.tsx +36 -1
- package/src/native/app/__tests__/briefingServices.test.ts +26 -0
- package/src/native/app/__tests__/haptics.test.tsx +55 -0
- package/src/native/app/__tests__/launch.test.ts +20 -1
- package/src/native/app/briefingServices.ts +9 -0
- package/src/native/app/converseServices.ts +15 -4
- package/src/native/app/device.ts +4 -0
- package/src/native/app/launch.ts +20 -0
- package/src/native/app/services.ts +2 -2
- package/src/native/briefing/__tests__/playerPauseResume.test.ts +47 -0
- package/src/native/briefing/audioPlayer.ts +14 -0
- package/src/native/converse/__tests__/bargeInIO.test.ts +46 -0
- package/src/native/converse/__tests__/meetingIO.test.ts +89 -23
- package/src/native/converse/__tests__/mock.test.ts +58 -0
- package/src/native/converse/index.ts +2 -0
- package/src/native/converse/io.ts +34 -20
- package/src/native/converse/mock.ts +136 -0
- package/src/native/index.ts +1 -0
- package/src/native/recording/recorder.ts +2 -1
- package/src/native/recording/recorderAudio.ts +14 -1
- package/src/native/voice-session/__tests__/bargeIn.test.ts +93 -0
- package/src/native/voice-session/__tests__/bindings.test.ts +84 -0
- package/src/native/voice-session/__tests__/events.test.ts +72 -0
- package/src/native/voice-session/__tests__/inspector.test.ts +28 -0
- package/src/native/voice-session/__tests__/lifecycle.test.ts +197 -0
- package/src/native/voice-session/__tests__/music.test.ts +86 -0
- package/src/native/voice-session/__tests__/routes.test.ts +121 -0
- package/src/native/voice-session/__tests__/voiceSession.test.ts +177 -0
- package/src/native/voice-session/bindMeeting.ts +33 -0
- package/src/native/voice-session/fake.ts +21 -0
- package/src/native/voice-session/index.ts +142 -0
- package/src/native/voice-session/inspector.ts +14 -0
- package/src/native/voice-session/machine.ts +41 -0
- package/src/native/voice-session/nowPlaying.ts +35 -0
- package/src/native/voice-session/types.ts +45 -0
- package/src/native/voice-session/wire.ts +47 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.226",
|
|
4
4
|
"description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://startsimpli.com",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"react-native": ">=0.74.0",
|
|
51
51
|
"@startsimpli/ui-native": ">=0.1.12",
|
|
52
52
|
"react-native-safe-area-context": ">=4.0.0",
|
|
53
|
-
"@startsimpli/ui": "^0.4.211",
|
|
54
53
|
"@startsimpli/auth": "^0.4.64",
|
|
55
|
-
"@startsimpli/utils": "^0.4.23"
|
|
54
|
+
"@startsimpli/utils": "^0.4.23",
|
|
55
|
+
"@startsimpli/ui": "^0.4.211"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"react": {
|
|
@@ -98,11 +98,11 @@
|
|
|
98
98
|
"vitest": "^3.0.0",
|
|
99
99
|
"react-native": "0.85.3",
|
|
100
100
|
"react-native-safe-area-context": "~5.7.0",
|
|
101
|
-
"@startsimpli/llm": "0.4.31",
|
|
102
101
|
"@startsimpli/ui": "0.4.211",
|
|
103
|
-
"@startsimpli/ui-native": "0.1.15",
|
|
104
102
|
"@startsimpli/auth": "0.4.64",
|
|
105
|
-
"@startsimpli/
|
|
103
|
+
"@startsimpli/ui-native": "0.1.15",
|
|
104
|
+
"@startsimpli/utils": "0.4.23",
|
|
105
|
+
"@startsimpli/llm": "0.4.31"
|
|
106
106
|
},
|
|
107
107
|
"scripts": {
|
|
108
108
|
"type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
/** Importance score (bd startsim-nd3qa.2): money, outward-facing and only-he-can-provide push an item up; call-me counts only important ones. */
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { ATTENTION_DEFAULTS, buildNeedsYou, importanceOf, itemId, resolveAttentionPolicy } from '../corpus/attention';
|
|
5
|
+
|
|
6
|
+
const P = ATTENTION_DEFAULTS;
|
|
7
|
+
const it_ = (text: string, source: 'fleet' | 'decision' = 'fleet') => ({ id: itemId(text), text, source });
|
|
8
|
+
const queue = (waiting: string[], policy = P) => buildNeedsYou({ view: { waitingOnQuinn: waiting }, decisions: [], policy });
|
|
9
|
+
|
|
10
|
+
describe('importanceOf', () => {
|
|
11
|
+
it('urgent is always the top score', () => { expect(importanceOf(it_('URGENT: prod is down'), 'urgent', P)).toBe(100); });
|
|
12
|
+
it('a plain needs-answer line scores low; money, outward-facing and only-he-can-provide each raise it', () => {
|
|
13
|
+
const plain = importanceOf(it_('Which colour for the button?'), 'needs-answer', P);
|
|
14
|
+
const money = importanceOf(it_('Approve the $400 invoice refund'), 'needs-answer', P);
|
|
15
|
+
const outward = importanceOf(it_('Send the launch email to customers'), 'needs-answer', P);
|
|
16
|
+
const onlyYou = importanceOf(it_('Need your Stripe API key'), 'needs-answer', P);
|
|
17
|
+
expect(plain).toBeLessThan(P.callMeMinImportance);
|
|
18
|
+
for (const s of [money, outward, onlyYou]) { expect(s).toBeGreaterThan(plain); expect(s).toBeGreaterThanOrEqual(P.callMeMinImportance); }
|
|
19
|
+
});
|
|
20
|
+
it('signals stack but never reach urgent; digest and noise stay below needs-answer', () => {
|
|
21
|
+
const all = importanceOf(it_('Pay the $900 invoice and email customers; need your approval'), 'needs-answer', P);
|
|
22
|
+
expect(all).toBeGreaterThan(60); expect(all).toBeLessThan(100);
|
|
23
|
+
expect(importanceOf(it_('Optional: send the newsletter'), 'digest', P)).toBeLessThan(P.callMeMinImportance);
|
|
24
|
+
expect(importanceOf(it_('FYI'), 'noise', P)).toBe(0);
|
|
25
|
+
});
|
|
26
|
+
it('a pending decision is something only he can answer', () => {
|
|
27
|
+
expect(importanceOf(it_('Which build goes first?', 'decision'), 'needs-answer', P)).toBeGreaterThanOrEqual(P.callMeMinImportance);
|
|
28
|
+
});
|
|
29
|
+
it('the patterns and threshold come from the policy', () => {
|
|
30
|
+
const custom = resolveAttentionPolicy({ moneyPatterns: ['\\bwidgets\\b'] });
|
|
31
|
+
expect(importanceOf(it_('Order more widgets'), 'needs-answer', custom)).toBeGreaterThan(importanceOf(it_('Order more widgets'), 'needs-answer', P));
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('queue: ordered by importance; call-me counts only the important', () => {
|
|
36
|
+
it('orders by importance score, urgent first', () => {
|
|
37
|
+
const q = queue(['Pick a colour', 'Send the launch email to customers', 'Pay the $900 invoice, need your approval', 'URGENT: checkout is down']);
|
|
38
|
+
expect(q.items.map((i) => i.text)[0]).toMatch(/URGENT/);
|
|
39
|
+
const scores = q.items.map((i) => i.importance);
|
|
40
|
+
expect(scores).toEqual([...scores].sort((a, b) => b - a));
|
|
41
|
+
expect(q.items[q.items.length - 1].text).toBe('Pick a colour');
|
|
42
|
+
});
|
|
43
|
+
it('three trivial questions do not trigger call-me; three important ones do', () => {
|
|
44
|
+
expect(queue(['Pick a colour', 'Pick a font', 'Pick an icon']).callMe).toBe(false);
|
|
45
|
+
const q = queue(['Send the launch email to customers', 'Pay the $900 invoice', 'Need your Stripe key']);
|
|
46
|
+
expect(q.callMe).toBe(true); expect(q.waiting).toBe(3);
|
|
47
|
+
});
|
|
48
|
+
it('lowering the threshold to 0 counts everything, like before', () => {
|
|
49
|
+
expect(queue(['Pick a colour', 'Pick a font', 'Pick an icon'], resolveAttentionPolicy({ callMeMinImportance: 0 })).callMe).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -73,16 +73,16 @@ describe('buildNeedsYou', () => {
|
|
|
73
73
|
it('queues fleet bullets and pending decisions, urgent first, noise dropped, ids stable', () => {
|
|
74
74
|
const q = buildNeedsYou({ view: view(LOOPS('Approve staging promote', 'FYI merged', 'TEST: urgent sample B, no action needed')), decisions: [{ id: 'dec-0001', title: 'Pick a colour', status: 'pending', created_at: '' }], policy: P });
|
|
75
75
|
expect(q.items.map((i) => i.class)).toEqual(['urgent', 'needs-answer', 'needs-answer']);
|
|
76
|
-
expect(q.items.map((i) => i.text)).toEqual(['TEST: urgent sample B, no action needed', '
|
|
76
|
+
expect(q.items.map((i) => i.text)).toEqual(['TEST: urgent sample B, no action needed', 'Approve staging promote', 'Pick a colour']);
|
|
77
77
|
expect(q.items[0].id).toBe(itemId('TEST: urgent sample B, no action needed'));
|
|
78
78
|
expect(q.counts).toEqual({ urgent: 1, 'needs-answer': 2, digest: 0, noise: 1 });
|
|
79
79
|
});
|
|
80
80
|
it('callMe turns on at the threshold of waiting items (urgent included)', () => {
|
|
81
|
-
const two = buildNeedsYou({ view: view(LOOPS('
|
|
81
|
+
const two = buildNeedsYou({ view: view(LOOPS('Pay invoice one', 'Pay invoice two')), decisions: [], policy: P });
|
|
82
82
|
expect(two.callMe).toBe(false);
|
|
83
|
-
const three = buildNeedsYou({ view: view(LOOPS('
|
|
83
|
+
const three = buildNeedsYou({ view: view(LOOPS('Pay invoice one', 'Pay invoice two', 'Pay invoice three')), decisions: [], policy: P });
|
|
84
84
|
expect(three.callMe).toBe(true);
|
|
85
|
-
expect(buildNeedsYou({ view: view(LOOPS('
|
|
85
|
+
expect(buildNeedsYou({ view: view(LOOPS('Pay invoice one', 'Pay invoice two', 'Pay invoice three')), decisions: [], policy: resolveAttentionPolicy({ callMeAt: 4 }) }).callMe).toBe(false);
|
|
86
86
|
});
|
|
87
87
|
it('an item id is the same however the line is spaced or cased', () => {
|
|
88
88
|
expect(itemId('Approve the PR ')).toBe(itemId('approve the pr'));
|
|
@@ -119,7 +119,7 @@ describe('runAttention: push on a fleet snapshot', () => {
|
|
|
119
119
|
});
|
|
120
120
|
it('sends one call-me ping when enough are waiting, and only once for that same set', async () => {
|
|
121
121
|
const { deps, sent } = setup();
|
|
122
|
-
const v = view(LOOPS('
|
|
122
|
+
const v = view(LOOPS('Pay invoice one', 'Pay invoice two', 'Pay invoice three'));
|
|
123
123
|
const out = await runAttention(deps, { view: v, now });
|
|
124
124
|
expect(out.pushed.map((p) => p.reason)).toEqual(['call-me']);
|
|
125
125
|
expect(sent[0]).toMatchObject({ title: expect.stringMatching(/3/), data: { kind: 'attention' } });
|
|
@@ -129,12 +129,12 @@ describe('runAttention: push on a fleet snapshot', () => {
|
|
|
129
129
|
it('quiet hours hold needs-answer and call-me, but urgent goes through', async () => {
|
|
130
130
|
const { deps, sent } = setup();
|
|
131
131
|
const quiet = at('2026-11-20T08:00:00Z'); // 00:00 PST
|
|
132
|
-
const v = view(LOOPS('
|
|
132
|
+
const v = view(LOOPS('Pay invoice one', 'Pay invoice two', 'Pay invoice three'));
|
|
133
133
|
const { setSettings } = await import('../corpus/notify');
|
|
134
134
|
await setSettings(deps, { attention: { quiet_mode: 'auto' } });
|
|
135
135
|
expect((await runAttention(deps, { view: v, now: quiet })).pushed).toEqual([]);
|
|
136
136
|
expect(sent).toHaveLength(0);
|
|
137
|
-
const u = view(LOOPS('TEST: urgent sample D', '
|
|
137
|
+
const u = view(LOOPS('TEST: urgent sample D', 'Pay invoice two', 'Pay invoice three'));
|
|
138
138
|
expect((await runAttention(deps, { view: u, now: quiet })).pushed.map((p) => p.reason)).toEqual(['urgent']);
|
|
139
139
|
});
|
|
140
140
|
it('sends nothing when the queue is empty', async () => {
|
|
@@ -81,8 +81,8 @@ function tenant() {
|
|
|
81
81
|
|
|
82
82
|
describe('the stored run', () => {
|
|
83
83
|
it('starts from the real queue, records answers into the queue, and answered items leave it', async () => {
|
|
84
|
-
const { deps
|
|
85
|
-
|
|
84
|
+
const { deps } = tenant();
|
|
85
|
+
for (const t of ['TEST: urgent sample A, no action needed', 'TEST: sample B', 'TEST: sample C']) await createDecision(deps, { title: t, questions: ['TEST: ok?'] });
|
|
86
86
|
const run = createAttentionRun(deps);
|
|
87
87
|
const start = await run.start('conv-0001');
|
|
88
88
|
expect(start).toMatchObject({ active: true, of: 3 });
|
|
@@ -92,13 +92,22 @@ describe('the stored run', () => {
|
|
|
92
92
|
expect(second!.text).toContain('Question 2 of 3');
|
|
93
93
|
const st = await loadState(deps);
|
|
94
94
|
expect(Object.keys(st.answered ?? {})).toHaveLength(1);
|
|
95
|
-
const q = buildNeedsYou({ view:
|
|
96
|
-
expect(q.items.map((i) => i.text)).toEqual(['TEST: sample B', 'TEST: sample C']);
|
|
95
|
+
const q = buildNeedsYou({ view: null, decisions: st.decisions.filter((d) => d.status === 'pending'), policy: policyFrom(st.attention), answered: st.answered });
|
|
96
|
+
expect(q.items.map((i) => i.text)).toEqual(expect.arrayContaining(['TEST: sample B', 'TEST: sample C']));
|
|
97
|
+
expect(q.items.map((i) => i.text)).not.toContain('TEST: urgent sample A, no action needed');
|
|
97
98
|
await run.answer('conv-0001', 'no');
|
|
98
99
|
const last = await run.answer('conv-0001', 'skip');
|
|
99
100
|
expect(last).toMatchObject({ active: false });
|
|
100
101
|
expect(await run.answer('conv-0001', 'yes')).toBeNull();
|
|
101
102
|
});
|
|
103
|
+
it('plain fleet lines are never asked (no yes/no on prose); they stay in the queue', async () => {
|
|
104
|
+
const { deps, fleet } = tenant();
|
|
105
|
+
fleet('Who owns the site?', 'Approve the staging promote');
|
|
106
|
+
expect(await createAttentionRun(deps).start('conv-0005')).toMatchObject({ text: 'Nothing is waiting on you right now.', active: false });
|
|
107
|
+
const st = await loadState(deps);
|
|
108
|
+
const q = buildNeedsYou({ view: buildFleetView({ loops: '## Waiting on Quinn\n- Who owns the site?\n- Approve the staging promote\n' }), decisions: [], policy: policyFrom(st.attention) });
|
|
109
|
+
expect(q.items).toHaveLength(2);
|
|
110
|
+
});
|
|
102
111
|
it('an answer to a one-question decision is delivered to that decision', async () => {
|
|
103
112
|
const { deps } = tenant();
|
|
104
113
|
const made = await createDecision(deps, { title: 'TEST: sample decision, pick a colour', questions: ['TEST: blue or green?'] });
|
|
@@ -115,8 +124,8 @@ describe('the stored run', () => {
|
|
|
115
124
|
expect(await createAttentionRun(deps).start('conv-0003')).toMatchObject({ text: 'Nothing is waiting on you right now.', active: false });
|
|
116
125
|
});
|
|
117
126
|
it('asks only a batch at a time, most important first', async () => {
|
|
118
|
-
const { deps
|
|
119
|
-
|
|
127
|
+
const { deps } = tenant();
|
|
128
|
+
for (let i = 1; i <= 8; i += 1) await createDecision(deps, { title: `TEST: sample ${i}`, questions: ['TEST: ok?'] });
|
|
120
129
|
const start = await createAttentionRun(deps, { batch: 3 }).start('conv-0004');
|
|
121
130
|
expect(start).toMatchObject({ of: 3 });
|
|
122
131
|
});
|
|
@@ -67,15 +67,15 @@ describe('runAttention uses the saved settings', () => {
|
|
|
67
67
|
it('manual quiet on holds the call-me but urgent still goes through', async () => {
|
|
68
68
|
const { deps, sent } = setup();
|
|
69
69
|
await setSettings(deps, { attention: { quiet_mode: 'on' } });
|
|
70
|
-
await runAttention(deps, { view: view('
|
|
70
|
+
await runAttention(deps, { view: view('Pay invoice one', 'Pay invoice two', 'Pay invoice three') });
|
|
71
71
|
expect(sent).toHaveLength(0);
|
|
72
|
-
await runAttention(deps, { view: view('TEST: urgent sample D', '
|
|
72
|
+
await runAttention(deps, { view: view('TEST: urgent sample D', 'Pay invoice two', 'Pay invoice three') });
|
|
73
73
|
expect(sent.map((m) => m.title)).toEqual([expect.stringContaining('TEST: urgent sample D')]);
|
|
74
74
|
});
|
|
75
75
|
it('quiet off pushes the call-me at night; a saved urgent word pushes; a raised threshold holds', async () => {
|
|
76
76
|
const { deps, sent } = setup();
|
|
77
77
|
await setSettings(deps, { attention: { quiet_mode: 'off', urgent_words: ['overdue'] } });
|
|
78
|
-
await runAttention(deps, { view: view('
|
|
78
|
+
await runAttention(deps, { view: view('Pay invoice one', 'Pay invoice two', 'Pay invoice three'), now: NIGHT });
|
|
79
79
|
expect(sent).toHaveLength(1);
|
|
80
80
|
await runAttention(deps, { view: view('Invoice overdue'), now: NIGHT });
|
|
81
81
|
expect(sent).toHaveLength(2);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { createMeetingController, type MeetingApi, type MeetingIO } from '../corpus/converse';
|
|
4
|
+
|
|
5
|
+
const blob = () => new Blob([new Uint8Array([1])], { type: 'audio/mp4' });
|
|
6
|
+
const turnResult = (n: number) => ({
|
|
7
|
+
conversation_id: 'c1', turn_id: `t${n}`, turn: n, transcript: `said ${n}`, reply_text: `reply ${n}`, audio_url: `/a/${n}`, audio_reason: null,
|
|
8
|
+
});
|
|
9
|
+
const settle = async (check: () => boolean) => { for (let i = 0; i < 300 && !check(); i += 1) await new Promise((r) => setTimeout(r, 5)); };
|
|
10
|
+
|
|
11
|
+
function rig() {
|
|
12
|
+
let n = 0;
|
|
13
|
+
const client: MeetingApi<Blob> = { turn: vi.fn(async () => turnResult(++n)), end: vi.fn(async () => ({ saved: true as const, conversation_id: 'c1', record_id: '1', turns: n, asks: [], decisions: [] })) as never };
|
|
14
|
+
const heard: Array<{ hooks?: { onSpeechStart?: () => void; onSpeechEnd?: () => void }; deliver: (a: Blob | null) => void }> = [];
|
|
15
|
+
let finishSpeak: () => void = () => undefined;
|
|
16
|
+
const io: MeetingIO<Blob> = {
|
|
17
|
+
duplex: true,
|
|
18
|
+
listen: vi.fn((signal: AbortSignal, _c: unknown, hooks?: { onSpeechStart?: () => void }) => new Promise((resolve) => {
|
|
19
|
+
heard.push({ hooks, deliver: (a) => resolve(a ? { audio: a } : { audio: null }) });
|
|
20
|
+
signal.addEventListener('abort', () => resolve({ audio: null, cancelled: true }));
|
|
21
|
+
})),
|
|
22
|
+
speak: vi.fn((_r: unknown, signal: AbortSignal) => new Promise<void>((resolve) => { finishSpeak = resolve; signal.addEventListener('abort', () => resolve()); })),
|
|
23
|
+
};
|
|
24
|
+
const c = createMeetingController({ client, io });
|
|
25
|
+
const startSpeaking = async () => {
|
|
26
|
+
c.start();
|
|
27
|
+
await settle(() => heard.length >= 1);
|
|
28
|
+
heard[0].deliver(blob());
|
|
29
|
+
await settle(() => c.state().phase === 'speaking');
|
|
30
|
+
await settle(() => heard.length >= 2);
|
|
31
|
+
};
|
|
32
|
+
return { c, heard, startSpeaking, finish: () => finishSpeak() };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('an interrupted reply is marked in the transcript (startsim-1x6kv.7)', () => {
|
|
36
|
+
it('speech over the reply marks that assistant line interrupted and nothing else', async () => {
|
|
37
|
+
const r = rig();
|
|
38
|
+
await r.startSpeaking();
|
|
39
|
+
r.heard[1].hooks?.onSpeechStart?.();
|
|
40
|
+
await settle(() => r.c.state().phase !== 'speaking');
|
|
41
|
+
const lines = r.c.state().lines;
|
|
42
|
+
expect(lines.map((l) => [l.role, l.interrupted === true])).toEqual([['user', false], ['assistant', true]]);
|
|
43
|
+
await r.c.end();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('the Interrupt tap (stop) marks it too', async () => {
|
|
47
|
+
const r = rig();
|
|
48
|
+
await r.startSpeaking();
|
|
49
|
+
r.c.stop();
|
|
50
|
+
expect(r.c.state().lines.at(-1)).toMatchObject({ role: 'assistant', interrupted: true });
|
|
51
|
+
await r.c.end();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('a reply that finishes on its own stays unmarked', async () => {
|
|
55
|
+
const r = rig();
|
|
56
|
+
await r.startSpeaking();
|
|
57
|
+
r.finish();
|
|
58
|
+
await settle(() => r.c.state().phase === 'listening');
|
|
59
|
+
expect(r.c.state().lines.some((l) => l.interrupted)).toBe(false);
|
|
60
|
+
await r.c.end();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('state.hearing is true from the moment the voice starts until the utterance is handed over', async () => {
|
|
64
|
+
const r = rig();
|
|
65
|
+
await r.startSpeaking();
|
|
66
|
+
expect(r.c.state().hearing).toBe(false);
|
|
67
|
+
r.heard[1].hooks?.onSpeechStart?.();
|
|
68
|
+
expect(r.c.state().hearing).toBe(true);
|
|
69
|
+
r.heard[1].deliver(null);
|
|
70
|
+
await settle(() => r.c.state().hearing === false);
|
|
71
|
+
expect(r.c.state().hearing).toBe(false);
|
|
72
|
+
await r.c.end();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
/** The transcriber writes the assistant's name the way it sounds; the transcript line shows Roci (startsim-1x6kv.3). Text only, no audio. */
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { createMeetingController, type MeetingApi, type MeetingIO } from '../corpus/converse';
|
|
5
|
+
|
|
6
|
+
const settle = async (check: () => boolean) => { for (let i = 0; i < 300 && !check(); i += 1) await new Promise((r) => setTimeout(r, 5)); };
|
|
7
|
+
|
|
8
|
+
async function heard(transcript: string) {
|
|
9
|
+
const client: MeetingApi<Blob> = { turn: vi.fn(async () => ({ conversation_id: 'c1', turn_id: 't1', turn: 1, transcript, reply_text: 'ok', audio_url: '/a', audio_reason: null })), end: vi.fn(async () => ({ saved: true as const, conversation_id: 'c1', record_id: '1', turns: 1, asks: [], decisions: [] })) as never };
|
|
10
|
+
const deliver: Array<(a: Blob) => void> = [];
|
|
11
|
+
const io: MeetingIO<Blob> = {
|
|
12
|
+
listen: vi.fn((signal: AbortSignal) => new Promise((resolve) => { deliver.push((a) => resolve({ audio: a })); signal.addEventListener('abort', () => resolve({ audio: null, cancelled: true })); })),
|
|
13
|
+
speak: vi.fn(async () => undefined),
|
|
14
|
+
};
|
|
15
|
+
const c = createMeetingController({ client, io });
|
|
16
|
+
c.start();
|
|
17
|
+
await settle(() => deliver.length >= 1);
|
|
18
|
+
deliver[0](new Blob([new Uint8Array([1])]));
|
|
19
|
+
await settle(() => c.state().lines.length >= 2);
|
|
20
|
+
const line = c.state().lines.find((l) => l.role === 'user')?.text;
|
|
21
|
+
await c.end();
|
|
22
|
+
return line;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('the spoken-transcript line uses the assistant name', () => {
|
|
26
|
+
it.each([
|
|
27
|
+
['Rochie, read my brief', 'Roci, read my brief'],
|
|
28
|
+
['Rossi what is due today', 'Roci what is due today'],
|
|
29
|
+
['hey Rosie move the car service', 'hey Roci move the car service'],
|
|
30
|
+
['Rosie, read my brief', 'Roci, read my brief'],
|
|
31
|
+
['Call Rosie about the invoice', 'Call Rosie about the invoice'],
|
|
32
|
+
['Roxy and Rossington are left alone', 'Roxy and Rossington are left alone'],
|
|
33
|
+
])('%s -> %s', async (said, shown) => {
|
|
34
|
+
expect(await heard(said)).toBe(shown);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -9,9 +9,24 @@ describe('normalizeAssistantName: the assistant is Roci; there is no wake word',
|
|
|
9
9
|
expect(normalizeAssistantName('ROSSI what is on my plate')).toBe('Roci what is on my plate');
|
|
10
10
|
});
|
|
11
11
|
it('leaves Rocky, Roxy, Rosie (real names and words) and words that merely contain Rossi alone', () => {
|
|
12
|
-
const same = ['
|
|
12
|
+
const same = ['book the Rocky Mountain trip', 'Roxy called', 'ask Rosie', 'Rossiter and the Rossini deal'];
|
|
13
13
|
for (const t of same) expect(normalizeAssistantName(t)).toBe(t);
|
|
14
14
|
});
|
|
15
|
+
it('turns the non-words the transcriber produces (Rochie, Rochi, Rossie) into Roci', () => {
|
|
16
|
+
expect(normalizeAssistantName('Rochie, what is due?')).toBe('Roci, what is due?');
|
|
17
|
+
expect(normalizeAssistantName('hey rochi read my brief')).toBe('hey Roci read my brief');
|
|
18
|
+
expect(normalizeAssistantName('Rossie are you there')).toBe('Roci are you there');
|
|
19
|
+
});
|
|
20
|
+
it('turns Rosie/Rocky into Roci ONLY when addressed (opening the utterance with a comma, or after hey/hi/ok/okay)', () => {
|
|
21
|
+
expect(normalizeAssistantName('Rosie, what is due today?')).toBe('Roci, what is due today?');
|
|
22
|
+
expect(normalizeAssistantName('Rocky what is due')).toBe('Rocky what is due');
|
|
23
|
+
expect(normalizeAssistantName('hey Rosie what is due')).toBe('hey Roci what is due');
|
|
24
|
+
expect(normalizeAssistantName('okay Rocky, read the brief')).toBe('okay Roci, read the brief');
|
|
25
|
+
expect(normalizeAssistantName('Ok, Rosie. Read it')).toBe('Ok, Roci. Read it');
|
|
26
|
+
});
|
|
27
|
+
it('leaves Rosie/Rocky alone when they are plainly someone else', () => {
|
|
28
|
+
for (const t of ['Tell Rosie, the dog is out', 'I saw Rocky yesterday', 'Rosie called me', 'meet with Rosie Rocky and Roxy']) expect(normalizeAssistantName(t)).toBe(t);
|
|
29
|
+
});
|
|
15
30
|
it('leaves Roci and empty text alone', () => {
|
|
16
31
|
expect(normalizeAssistantName('Roci is here')).toBe('Roci is here');
|
|
17
32
|
expect(normalizeAssistantName('')).toBe('');
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
/** TTS (bd startsim-1x6kv.5): prompt start, long replies chunked at sentence boundaries, failures never hang the meeting. */
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { createMeetingController, type MeetingApi, type MeetingIO } from '../corpus/converse';
|
|
5
|
+
import { speakSide } from '../corpus/converse/speak';
|
|
6
|
+
|
|
7
|
+
const sentences = (n: number) => Array.from({ length: n }, (_, i) => `This is sentence number ${i + 1} of a long reply that goes on.`).join(' ');
|
|
8
|
+
const bytesOf = (text: string) => new TextEncoder().encode(`[${text}]`);
|
|
9
|
+
|
|
10
|
+
function harness(over: { synthesize?: (a: { text: string }) => Promise<any> } = {}) {
|
|
11
|
+
const calls: string[] = [];
|
|
12
|
+
const kept: Array<{ audio: Uint8Array; mimeType: string }> = [];
|
|
13
|
+
const deps = {
|
|
14
|
+
synthesize: vi.fn(over.synthesize ?? (async ({ text }: { text: string }) => { calls.push(text); return { audio: bytesOf(text), mimeType: 'audio/mpeg' }; })),
|
|
15
|
+
audio: { put: vi.fn(async (a: { audio: Uint8Array; mimeType: string }) => { kept.push(a); return `mem://${kept.length}`; }), get: vi.fn() },
|
|
16
|
+
};
|
|
17
|
+
return { deps: deps as never, calls, kept, synthesize: deps.synthesize };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('long replies are chunked at sentence boundaries', () => {
|
|
21
|
+
it('a short reply is one synthesis call, unchanged', async () => {
|
|
22
|
+
const h = harness();
|
|
23
|
+
const side = await speakSide(h.deps, 'n1', 'Two things are due today.');
|
|
24
|
+
expect(h.synthesize).toHaveBeenCalledTimes(1);
|
|
25
|
+
expect(side.audio_ref).toBe('mem://1');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('a long reply is split into chunks that each end on a sentence boundary and together say every word in order', async () => {
|
|
29
|
+
const h = harness();
|
|
30
|
+
const text = sentences(40);
|
|
31
|
+
await speakSide(h.deps, 'n1', text);
|
|
32
|
+
expect(h.calls.length).toBeGreaterThan(1);
|
|
33
|
+
for (const chunk of h.calls) {
|
|
34
|
+
expect(chunk.length).toBeLessThanOrEqual(500);
|
|
35
|
+
expect(chunk).toMatch(/[.!?]$/);
|
|
36
|
+
}
|
|
37
|
+
expect(h.calls.join(' ')).toBe(text);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('the chunks are stitched back into ONE recording in reading order', async () => {
|
|
41
|
+
const h = harness();
|
|
42
|
+
await speakSide(h.deps, 'n1', sentences(40));
|
|
43
|
+
expect(h.kept).toHaveLength(1);
|
|
44
|
+
const expected = new TextDecoder().decode(h.kept[0].audio);
|
|
45
|
+
expect(expected).toBe(h.calls.map((c) => `[${c}]`).join(''));
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('chunks are synthesised together, not one after the other (first audio waits for the slowest chunk, not the sum)', async () => {
|
|
49
|
+
let inFlight = 0;
|
|
50
|
+
let peak = 0;
|
|
51
|
+
const h = harness({
|
|
52
|
+
synthesize: async ({ text }) => {
|
|
53
|
+
inFlight += 1; peak = Math.max(peak, inFlight);
|
|
54
|
+
await new Promise((r) => setTimeout(r, 20));
|
|
55
|
+
inFlight -= 1;
|
|
56
|
+
return { audio: bytesOf(text), mimeType: 'audio/mpeg' };
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
await speakSide(h.deps, 'n1', sentences(40));
|
|
60
|
+
expect(peak).toBeGreaterThan(1);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('one chunk failing fails the whole reply with a reason: never half a reply of audio', async () => {
|
|
64
|
+
let n = 0;
|
|
65
|
+
const h = harness({ synthesize: async ({ text }) => { if (++n === 2) throw new Error('tts chunk 2 failed'); return { audio: bytesOf(text), mimeType: 'audio/mpeg' }; } });
|
|
66
|
+
const side = await speakSide(h.deps, 'n1', sentences(40));
|
|
67
|
+
expect(side.audio_ref).toBeUndefined();
|
|
68
|
+
expect(side.audio_reason).toBe('tts chunk 2 failed');
|
|
69
|
+
expect(side.text).toBe(sentences(40));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('one sentence longer than a chunk is still split (at a clause or space), never sent whole and never cut mid-word', async () => {
|
|
73
|
+
const h = harness();
|
|
74
|
+
const run = Array.from({ length: 200 }, (_, i) => `word${i}`).join(' ') + '.';
|
|
75
|
+
await speakSide(h.deps, 'n1', run);
|
|
76
|
+
expect(h.calls.length).toBeGreaterThan(1);
|
|
77
|
+
expect(h.calls.join(' ')).toBe(run);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('a TTS failure on the phone never hangs the meeting', () => {
|
|
82
|
+
const turn = { conversation_id: 'c1', turn_id: 't1', turn: 1, transcript: 'hi', reply_text: 'hello', audio_url: '/a/1', audio_reason: null };
|
|
83
|
+
const settle = async (check: () => boolean) => { for (let i = 0; i < 300 && !check(); i += 1) await new Promise((r) => setTimeout(r, 5)); };
|
|
84
|
+
|
|
85
|
+
for (const duplex of [false, true]) {
|
|
86
|
+
it(`a reply that cannot be fetched or played returns to listening and says why (duplex=${duplex})`, async () => {
|
|
87
|
+
const client: MeetingApi<Blob> = { turn: vi.fn(async () => turn), end: vi.fn() as never };
|
|
88
|
+
const delivered: Array<(a: Blob | null) => void> = [];
|
|
89
|
+
const io: MeetingIO<Blob> = {
|
|
90
|
+
duplex,
|
|
91
|
+
listen: vi.fn((signal: AbortSignal) => new Promise((resolve) => {
|
|
92
|
+
delivered.push((a) => resolve({ audio: a }));
|
|
93
|
+
signal.addEventListener('abort', () => resolve({ audio: null, cancelled: true }));
|
|
94
|
+
})),
|
|
95
|
+
speak: vi.fn(async () => { throw new Error('reply audio could not be fetched'); }),
|
|
96
|
+
};
|
|
97
|
+
const c = createMeetingController({ client, io });
|
|
98
|
+
c.start();
|
|
99
|
+
await settle(() => delivered.length >= 1);
|
|
100
|
+
delivered[0](new Blob([new Uint8Array([1])]));
|
|
101
|
+
await settle(() => c.state().noAudio !== null);
|
|
102
|
+
expect(c.state().noAudio).toMatch(/could not be fetched/);
|
|
103
|
+
await settle(() => c.state().phase === 'listening');
|
|
104
|
+
expect(c.state().phase).toBe('listening');
|
|
105
|
+
await c.end();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
it('a reply that never finishes playing is cut off after a bound, and the meeting listens again', async () => {
|
|
110
|
+
const client: MeetingApi<Blob> = { turn: vi.fn(async () => turn), end: vi.fn() as never };
|
|
111
|
+
const delivered: Array<(a: Blob | null) => void> = [];
|
|
112
|
+
const io: MeetingIO<Blob> = {
|
|
113
|
+
listen: vi.fn((signal: AbortSignal) => new Promise((resolve) => {
|
|
114
|
+
delivered.push((a) => resolve({ audio: a }));
|
|
115
|
+
signal.addEventListener('abort', () => resolve({ audio: null, cancelled: true }));
|
|
116
|
+
})),
|
|
117
|
+
speak: vi.fn(() => new Promise<void>(() => undefined)),
|
|
118
|
+
};
|
|
119
|
+
const c = createMeetingController({ client, io, config: { speakingMaxMs: 150, watchdogTickMs: 20 } as never });
|
|
120
|
+
c.start();
|
|
121
|
+
await settle(() => delivered.length >= 1);
|
|
122
|
+
delivered[0](new Blob([new Uint8Array([1])]));
|
|
123
|
+
await settle(() => c.state().phase === 'speaking');
|
|
124
|
+
await settle(() => c.state().phase === 'listening');
|
|
125
|
+
expect(c.state().phase).toBe('listening');
|
|
126
|
+
await c.end();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -354,6 +354,21 @@ describe('an audio turn', () => {
|
|
|
354
354
|
expect(turn.assistant.audio_ref).toMatch(/^mem:\/\//);
|
|
355
355
|
});
|
|
356
356
|
|
|
357
|
+
it('always tells the transcriber the assistant is called Roci (STT hears Rosie / Rochie / Rossi), also on the first turn', async () => {
|
|
358
|
+
const { deps, transcribe } = setup();
|
|
359
|
+
await handleConverseTurn(deps, { audio });
|
|
360
|
+
const hints = (transcribe.mock.calls[0] as unknown as [{ hints: string[] }])[0].hints;
|
|
361
|
+
expect(hints).toContain('Roci');
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it('a recording with no audio bytes is dropped without calling the transcriber', async () => {
|
|
365
|
+
const { deps, transcribe, brain } = setup();
|
|
366
|
+
const out = await handleConverseTurn(deps, { audio: { audio: new Uint8Array(0), mimeType: 'audio/mp4' } });
|
|
367
|
+
expect(transcribe).not.toHaveBeenCalled();
|
|
368
|
+
expect(brain).not.toHaveBeenCalled();
|
|
369
|
+
expect(out.audio_url).toBeNull();
|
|
370
|
+
});
|
|
371
|
+
|
|
357
372
|
it('a transcription failure is retryable and keeps nothing', async () => {
|
|
358
373
|
const { t, deps } = setup({ transcribe: async () => { throw new Error('boom'); } });
|
|
359
374
|
await expect(handleConverseTurn(deps, { audio })).rejects.toMatchObject({ status: 502, code: 'transcription_failed' });
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
/** The relay's own feed into the needs-you queue, and the answers back to it (bd startsim-nd3qa). */
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { createAttentionRun } from '../corpus/attention/run';
|
|
5
|
+
import { buildNeedsYou, policyFrom } from '../corpus/attention';
|
|
6
|
+
import { postRelayItems, relayAnswers } from '../corpus/notify/relay-items';
|
|
7
|
+
import { loadState, saveState } from '../corpus/notify/state';
|
|
8
|
+
import { startRun } from '../corpus/attention/run-steps';
|
|
9
|
+
|
|
10
|
+
const NOW = '2026-11-20T00:00:00Z';
|
|
11
|
+
function tenant() {
|
|
12
|
+
const rows = new Map<string, any>();
|
|
13
|
+
let seq = 0;
|
|
14
|
+
const http = {
|
|
15
|
+
get: vi.fn(async (_p: string, o?: { params?: Record<string, unknown> }) => ({ results: [...rows.values()].filter((r) => r.external_id === o?.params?.external_id__in) })),
|
|
16
|
+
post: vi.fn(async (_p: string, b: any) => { const row = { id: String(++seq), external_id: b.external_id, data: b.data }; rows.set(b.external_id, row); return row; }),
|
|
17
|
+
};
|
|
18
|
+
return { deps: { http: http as never, ownerSub: 'me', now: () => Date.parse(NOW), newId: () => `generated-${++seq}` }, rows };
|
|
19
|
+
}
|
|
20
|
+
const Q1 = { id: 'prod-mail-poll', text: 'Should Google and Microsoft mail and calendar get scheduled polling on production?', source: 'Tandem sources' };
|
|
21
|
+
const Q2 = { id: 'local-scheduler', text: 'Should your local Tandem also run a scheduler for them, or stay manual?', options: ['schedule', 'manual'], source: 'Tandem sources' };
|
|
22
|
+
|
|
23
|
+
describe('posting relay items', () => {
|
|
24
|
+
it('stores them, idempotent by id: the same post twice is still two items; a changed text updates in place', async () => {
|
|
25
|
+
const { deps } = tenant();
|
|
26
|
+
await postRelayItems(deps, { items: [Q1, Q2] });
|
|
27
|
+
await postRelayItems(deps, { items: [Q1, { ...Q2, text: 'Should your local Tandem also run a scheduler?' }] });
|
|
28
|
+
const st = await loadState(deps);
|
|
29
|
+
expect(st.relay_items?.map((i) => i.id)).toEqual(['prod-mail-poll', 'local-scheduler']);
|
|
30
|
+
expect(st.relay_items?.[1].text).toBe('Should your local Tandem also run a scheduler?');
|
|
31
|
+
});
|
|
32
|
+
it('rejects a bad id or an empty question (400) and keeps what was stored', async () => {
|
|
33
|
+
const { deps } = tenant();
|
|
34
|
+
await expect(postRelayItems(deps, { items: [{ id: 'x y', text: 'ok question here' }] })).rejects.toMatchObject({ status: 400 });
|
|
35
|
+
await expect(postRelayItems(deps, { items: [{ id: 'good-id', text: ' ' }] })).rejects.toMatchObject({ status: 400 });
|
|
36
|
+
await expect(postRelayItems(deps, { items: 'nope' as never })).rejects.toMatchObject({ status: 400 });
|
|
37
|
+
});
|
|
38
|
+
it('an answered item is not re-opened by a repeated post, and can be removed by id', async () => {
|
|
39
|
+
const { deps } = tenant();
|
|
40
|
+
await postRelayItems(deps, { items: [Q1] });
|
|
41
|
+
const st = await loadState(deps);
|
|
42
|
+
await saveState(deps, { ...st, answered: { 'relay:prod-mail-poll': { answer: 'yes', at: NOW, conversation_id: 'c-1', source: 'relay' } } });
|
|
43
|
+
await postRelayItems(deps, { items: [Q1, Q2] });
|
|
44
|
+
const answers = await relayAnswers(deps);
|
|
45
|
+
expect(answers.find((a) => a.id === 'prod-mail-poll')).toMatchObject({ answered: true, answer: 'yes' });
|
|
46
|
+
expect(answers.find((a) => a.id === 'local-scheduler')).toMatchObject({ answered: false });
|
|
47
|
+
await postRelayItems(deps, { remove: ['local-scheduler'] });
|
|
48
|
+
expect((await relayAnswers(deps)).map((a) => a.id)).toEqual(['prod-mail-poll']);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('the queue and the briefing', () => {
|
|
53
|
+
it('relay items are needs-answer (never urgent, even with an urgent-sounding word), listed with their source, and leave when answered', () => {
|
|
54
|
+
const policy = policyFrom(undefined);
|
|
55
|
+
const relay = [{ id: 'a-1', text: 'This is urgent: should we ship it?', source: 'Tandem sources', at: NOW }];
|
|
56
|
+
const q = buildNeedsYou({ view: null, decisions: [], policy, relay });
|
|
57
|
+
expect(q.items).toHaveLength(1);
|
|
58
|
+
expect(q.items[0]).toMatchObject({ id: 'relay:a-1', class: 'needs-answer', source: 'relay', from: 'Tandem sources' });
|
|
59
|
+
expect(q.counts.urgent).toBe(0);
|
|
60
|
+
expect(buildNeedsYou({ view: null, decisions: [], policy, relay, answered: { 'relay:a-1': {} } }).items).toHaveLength(0);
|
|
61
|
+
});
|
|
62
|
+
it('a choice item is asked with its options, not "yes or no"', () => {
|
|
63
|
+
const { reply } = startRun({ conversationId: 'conv-0001', items: [{ id: 'relay:l', text: Q2.text, options: ['schedule', 'manual'] }], now: NOW });
|
|
64
|
+
expect(reply.text).toContain('Say schedule or manual.');
|
|
65
|
+
expect(reply.text).not.toContain('Yes or no');
|
|
66
|
+
});
|
|
67
|
+
it('his voice answer to a relay item is stored AND handed to the delivery hook once', async () => {
|
|
68
|
+
const { deps } = tenant();
|
|
69
|
+
await postRelayItems(deps, { items: [Q1] });
|
|
70
|
+
const delivered: Array<{ id: string; answer: string; text: string }> = [];
|
|
71
|
+
const run = createAttentionRun(deps, { deliverRelay: async (a) => { delivered.push({ id: a.id, answer: a.answer, text: a.text }); } });
|
|
72
|
+
const start = await run.start('conv-0001');
|
|
73
|
+
expect(start!.text).toContain('Question 1 of 1');
|
|
74
|
+
const done = await run.answer('conv-0001', 'yes');
|
|
75
|
+
expect(done!.text).toContain('That was the last one.');
|
|
76
|
+
expect(delivered).toEqual([{ id: 'prod-mail-poll', answer: 'yes', text: Q1.text }]);
|
|
77
|
+
expect((await relayAnswers(deps))[0]).toMatchObject({ answered: true, answer: 'yes', delivered: true });
|
|
78
|
+
// a second start finds nothing waiting
|
|
79
|
+
expect((await run.start('conv-0002'))!.text).toBe('Nothing is waiting on you right now.');
|
|
80
|
+
});
|
|
81
|
+
it('a failing delivery does not lose the answer: it stays stored, marked undelivered, for the relay to read back', async () => {
|
|
82
|
+
const { deps } = tenant();
|
|
83
|
+
await postRelayItems(deps, { items: [Q1] });
|
|
84
|
+
const run = createAttentionRun(deps, { deliverRelay: async () => { throw new Error('bridge down'); } });
|
|
85
|
+
await run.start('conv-0001');
|
|
86
|
+
await run.answer('conv-0001', 'no');
|
|
87
|
+
expect((await relayAnswers(deps))[0]).toMatchObject({ answered: true, answer: 'no', delivered: false });
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Importance score 0-100 (bd startsim-nd3qa.2). Pure. Urgent is 100; noise 0; the rest is a base by class plus what the item touches. */
|
|
2
|
+
import type { AttentionClass, AttentionItem, AttentionPolicy } from './types';
|
|
3
|
+
|
|
4
|
+
const BASE: Record<AttentionClass, number> = { urgent: 100, 'needs-answer': 20, digest: 5, noise: 0 };
|
|
5
|
+
const compile = (sources: string[]): RegExp[] => sources.flatMap((s) => { try { return [new RegExp(s, 'i')]; } catch { return []; } });
|
|
6
|
+
const hits = (sources: string[], text: string) => compile(sources).some((r) => r.test(text));
|
|
7
|
+
|
|
8
|
+
export function importanceOf(item: AttentionItem, cls: AttentionClass, policy: AttentionPolicy): number {
|
|
9
|
+
if (cls === 'urgent' || cls === 'noise') return BASE[cls];
|
|
10
|
+
const w = policy.importanceWeights;
|
|
11
|
+
let score = BASE[cls];
|
|
12
|
+
if (hits(policy.moneyPatterns, item.text)) score += w.money;
|
|
13
|
+
if (hits(policy.outwardPatterns, item.text)) score += w.outward;
|
|
14
|
+
if (item.source === 'decision' || hits(policy.onlyYouPatterns, item.text)) score += w.onlyYou;
|
|
15
|
+
// A digest line waits for the daily brief however much it touches; it never reaches the call-me threshold.
|
|
16
|
+
return Math.min(score, cls === 'digest' ? Math.max(0, policy.callMeMinImportance - 1) : 95);
|
|
17
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './types';
|
|
2
2
|
export { classifyItem, inQuietHours, isQuiet, type QuietMode, itemId, resolveAttentionPolicy } from './policy';
|
|
3
3
|
export { buildNeedsYou } from './queue';
|
|
4
|
+
export { importanceOf } from './importance';
|
|
4
5
|
export { callMeTitle, runAttention, type AttentionPush } from './push';
|
|
5
6
|
export { mergeAttention, policyFrom, settingsView, type AttentionSettings as AttentionSettingsValues, type StoredAttention } from './settings';
|
|
6
7
|
export { createAttentionController, quietSummary, type AttentionController, type AttentionState } from './controller';
|
|
@@ -5,13 +5,15 @@ export function resolveAttentionPolicy(over: AttentionPolicyInput = {}): Attenti
|
|
|
5
5
|
const d = ATTENTION_DEFAULTS;
|
|
6
6
|
return {
|
|
7
7
|
...d, ...over,
|
|
8
|
-
quiet: { ...d.quiet, ...over.quiet }, brief: { ...d.brief, ...over.brief }, wrap: { ...d.wrap, ...over.wrap },
|
|
8
|
+
quiet: { ...d.quiet, ...over.quiet }, importanceWeights: { ...d.importanceWeights, ...over.importanceWeights }, brief: { ...d.brief, ...over.brief }, wrap: { ...d.wrap, ...over.wrap },
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const compile = (sources: string[]): RegExp[] => sources.flatMap((s) => { try { return [new RegExp(s, 'i')]; } catch { return []; } });
|
|
13
13
|
|
|
14
14
|
export function classifyItem(item: AttentionItem, policy: AttentionPolicy): AttentionClass {
|
|
15
|
+
// The relay asks a question and waits for his answer: it never interrupts (needs-answer), whatever words the question has.
|
|
16
|
+
if (item.source === 'relay') return 'needs-answer';
|
|
15
17
|
const words = policy.urgentWords.map((w) => w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).filter(Boolean).map((w) => `(^|[^\\w])${w}($|[^\\w])`);
|
|
16
18
|
if (compile([...policy.urgentPatterns, ...words]).some((r) => r.test(item.text))) return 'urgent';
|
|
17
19
|
if (compile(policy.noisePatterns).some((r) => r.test(item.text))) return 'noise';
|