@startsimpli/integrations 0.2.186 → 0.2.188

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.
Files changed (38) hide show
  1. package/package.json +6 -6
  2. package/src/__tests__/connection-reconnect.test.tsx +69 -0
  3. package/src/__tests__/converse-activity.test.ts +14 -1
  4. package/src/__tests__/converse-brain.test.ts +44 -0
  5. package/src/__tests__/converse-meeting.test.ts +118 -0
  6. package/src/__tests__/converse-page.test.tsx +150 -83
  7. package/src/__tests__/converse.test.ts +32 -0
  8. package/src/__tests__/corpus-ask.test.ts +27 -0
  9. package/src/__tests__/corpus-tracker.test.tsx +37 -35
  10. package/src/__tests__/plan-shell.test.tsx +14 -11
  11. package/src/__tests__/possibly-done-extract.test.ts +90 -0
  12. package/src/__tests__/possibly-done-ui.test.tsx +80 -0
  13. package/src/components/pages/ConversePage.tsx +128 -83
  14. package/src/components/pages/TaskDetailPage.tsx +22 -0
  15. package/src/components/pages/TrackerPage.tsx +15 -141
  16. package/src/components/pages/connections/ConnectionCard.tsx +20 -0
  17. package/src/components/pages/connections/bound-api.ts +2 -0
  18. package/src/components/pages/converse/Thread.tsx +46 -0
  19. package/src/components/pages/converse/browserIO.ts +15 -5
  20. package/src/components/pages/home/CompactItemRow.tsx +4 -1
  21. package/src/components/pages/plan/TalkPage.tsx +8 -29
  22. package/src/components/pages/tracker/PossiblyDone.tsx +49 -0
  23. package/src/corpus/{converse/activity.ts → activity.ts} +35 -10
  24. package/src/corpus/ask.ts +22 -0
  25. package/src/corpus/client.ts +2 -0
  26. package/src/corpus/commitments.ts +27 -6
  27. package/src/corpus/converse/brain.ts +26 -18
  28. package/src/corpus/converse/handle.ts +24 -2
  29. package/src/corpus/converse/index.ts +4 -3
  30. package/src/corpus/converse/meeting.ts +70 -21
  31. package/src/corpus/converse/route.ts +4 -3
  32. package/src/corpus/converse/sources.ts +17 -0
  33. package/src/corpus/converse/types.ts +19 -0
  34. package/src/corpus/entities.ts +4 -0
  35. package/src/corpus/nav-copy.ts +3 -3
  36. package/src/corpus/possibly-done.ts +59 -0
  37. package/src/corpus/types.ts +17 -1
  38. package/src/native/converse/io.ts +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.186",
3
+ "version": "0.2.188",
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.186",
53
+ "@startsimpli/utils": "^0.4.20",
54
54
  "@startsimpli/auth": "^0.4.53",
55
- "@startsimpli/utils": "^0.4.20"
55
+ "@startsimpli/ui": "^0.4.186"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "react": {
@@ -99,10 +99,10 @@
99
99
  "react-native": "0.85.3",
100
100
  "react-native-safe-area-context": "~5.7.0",
101
101
  "@startsimpli/llm": "0.4.31",
102
- "@startsimpli/ui": "0.4.186",
103
102
  "@startsimpli/ui-native": "0.1.15",
104
- "@startsimpli/auth": "0.4.53",
105
- "@startsimpli/utils": "0.4.20"
103
+ "@startsimpli/ui": "0.4.186",
104
+ "@startsimpli/utils": "0.4.20",
105
+ "@startsimpli/auth": "0.4.53"
106
106
  },
107
107
  "scripts": {
108
108
  "type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
@@ -0,0 +1,69 @@
1
+ /**
2
+ * An OAuth card whose grant the vendor stopped accepting offers Reconnect (re-consent),
3
+ * not a paste-a-key form (bd startsim-vxyy9).
4
+ */
5
+ import { describe, expect, it, vi } from 'vitest';
6
+ import { render, screen, waitFor, within } from '@testing-library/react';
7
+ import userEvent from '@testing-library/user-event';
8
+
9
+ import { ConnectionsPage } from '../components/pages/ConnectionsPage';
10
+ import type { MemberConnectionsApi } from '../components/pages/types';
11
+
12
+ const ENTRY = {
13
+ key: 'linear', name: 'Linear', description: 'Issues', logo_url: '', docs_url: '',
14
+ capabilities: ['poll'], auth_mode: 'oauth',
15
+ credential_schema: { version: 1, fields: [] }, config_schema: { version: 1, fields: [] },
16
+ record_types: [], supports_webhooks: true, availability: { available: true, reason: '' },
17
+ };
18
+
19
+ function conn(status: string, authMode = 'oauth') {
20
+ return {
21
+ results: [{
22
+ id: 'c1', public_id: 'p1', name: 'My Linear', connector_key: 'linear', connector_name: 'Linear',
23
+ external_account_id: '', account_label: 'me', capabilities_enabled: ['poll'], config: {},
24
+ status, health: 'ok', auth_mode: authMode,
25
+ }],
26
+ permissions: { view: true, manage: true, issue_tokens: false },
27
+ };
28
+ }
29
+
30
+ function api(status: string, extra: Partial<MemberConnectionsApi> = {}, entry: object = ENTRY) {
31
+ return {
32
+ connectorCatalog: vi.fn().mockResolvedValue({ results: [entry] }),
33
+ connections: vi.fn().mockResolvedValue(conn(status)),
34
+ connect: vi.fn(), checkConnection: vi.fn(), rotateCredential: vi.fn(), disconnect: vi.fn(),
35
+ connectionRuns: vi.fn().mockResolvedValue({ results: [] }),
36
+ ...extra,
37
+ } as unknown as MemberConnectionsApi;
38
+ }
39
+
40
+ async function card(a: MemberConnectionsApi) {
41
+ render(<ConnectionsPage mode="personal" api={a} />);
42
+ const name = await screen.findByText('My Linear');
43
+ return (name.closest('div[data-connection]') ?? name.parentElement!) as HTMLElement;
44
+ }
45
+
46
+ describe('Reconnect on an OAuth card', () => {
47
+ it('needs_reauth shows Reconnect, not Replace key, and clicking restarts consent on the same card', async () => {
48
+ const oauthInitiate = vi.fn().mockResolvedValue({ authorization_url: 'about:blank#consent', state: 's', redirect_uri: 'r' });
49
+ const assign = vi.fn();
50
+ Object.defineProperty(window, 'location', { value: { ...window.location, assign, href: 'http://x/' }, writable: true });
51
+ const section = await card(api('needs_reauth', { oauthInitiate } as never));
52
+ expect(within(section).queryByRole('button', { name: /Replace key/i })).toBeNull();
53
+ await userEvent.click(within(section).getByRole('button', { name: /Reconnect/i }));
54
+ await waitFor(() => expect(oauthInitiate).toHaveBeenCalledWith('c1', expect.anything()));
55
+ expect(assign).toHaveBeenCalledWith('about:blank#consent');
56
+ });
57
+
58
+ it('a healthy OAuth card has no Reconnect', async () => {
59
+ const section = await card(api('connected', { oauthInitiate: vi.fn() } as never));
60
+ expect(within(section).queryByRole('button', { name: /Reconnect/i })).toBeNull();
61
+ });
62
+
63
+ it('an API-key card keeps Replace key', async () => {
64
+ const entry = { ...ENTRY, key: 'linear', auth_mode: 'api_key' };
65
+ const section = await card(api('needs_reauth', { oauthInitiate: vi.fn() } as never, entry));
66
+ expect(within(section).getByRole('button', { name: /Replace key/i })).toBeInTheDocument();
67
+ expect(within(section).queryByRole('button', { name: /Reconnect/i })).toBeNull();
68
+ });
69
+ });
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { describe, expect, it, vi } from 'vitest';
7
7
 
8
- import { ACTIVITY_QUESTION, activityOf, composeActivity, loadActivity } from '../corpus/converse/activity';
8
+ import { ACTIVITY_QUESTION, activityOf, composeActivity, forOwner, loadActivity } from '../corpus/activity';
9
9
  import { questionWindow } from '../corpus/ask-items-intent';
10
10
  import type { Commitment, SourceDocument } from '../corpus/types';
11
11
 
@@ -74,6 +74,19 @@ describe('what happened in the window', () => {
74
74
  });
75
75
  });
76
76
 
77
+ describe('only what is his', () => {
78
+ it("leaves out another member's to-dos and notes, keeps ones with no owner", () => {
79
+ const window = { from: '2026-11-15', to: '2026-11-15', label: 'yesterday' };
80
+ const items = [
81
+ todo('a', 'Mine', { status: 'done', resolvedAt: '2026-11-15T20:00:00Z', ownerSub: 'me' } as never),
82
+ todo('b', 'Theirs', { status: 'done', resolvedAt: '2026-11-15T20:00:00Z', ownerSub: 'qa-user' } as never),
83
+ todo('c', 'No owner', { status: 'done', resolvedAt: '2026-11-15T21:00:00Z' }),
84
+ ];
85
+ const got = forOwner(activityOf({ items, docs: [], window, timeZone: TZ }), 'me');
86
+ expect(got.finished.map((i) => i.title)).toEqual(['No owner', 'Mine']);
87
+ });
88
+ });
89
+
77
90
  describe('reading it', () => {
78
91
  it('asks the tenant for to-dos changed since the window start and notes inside the window, nothing else', async () => {
79
92
  const listCommitments = vi.fn(async () => ({ results: [todo('a', 'Ship', { status: 'done', resolvedAt: '2026-11-15T20:00:00Z' })], next: null }));
@@ -160,6 +160,50 @@ describe('conversation answers are short unless he asks for all of it', () => {
160
160
  });
161
161
  });
162
162
 
163
+ describe('ONE entry: the assistant decides what was said', () => {
164
+ const say = (utterance: string, over: object = {}) => ({ utterance, history: [], timeZone: TZ, now: NOW, ...over });
165
+ const routeSays = (route: string) => ({ write: vi.fn(async () => `{"route":"${route}"}`) }) as never;
166
+
167
+ it.each(['parse that note', 'just parse that note', 'that is it', "that's it", "I'm done", 'done', 'file it', 'wrap it up', 'okay, that is all', 'save the note'])('"%s" wraps the conversation up', async (said) => {
168
+ const s = setup();
169
+ const out = await createConverseBrain({ ...s.deps, routeLlm: routeSays('other') })(say(said));
170
+ expect(out).toMatchObject({ finish: true, intent: 'note' });
171
+ expect(s.ask).not.toHaveBeenCalled();
172
+ });
173
+
174
+ it('a plan or list with no question gets a short acknowledgement and stays open (the routing model calls it a note)', async () => {
175
+ const s = setup();
176
+ const out = await createConverseBrain({ ...s.deps, routeLlm: routeSays('note'), loadItems: async () => [] as never })(say('Today I want to review the checkout copy, then check the debug backend, and also look at the bench present'));
177
+ expect(out).toMatchObject({ text: 'Got it.', intent: 'note' });
178
+ expect(out.finish).toBeUndefined();
179
+ expect(s.ask).not.toHaveBeenCalled();
180
+ });
181
+
182
+ it('a QUESTION is never taken for a note, whatever the routing model says', async () => {
183
+ const s = setup();
184
+ const out = await createConverseBrain({ ...s.deps, routeLlm: routeSays('note') })(say('What is due this week?'));
185
+ expect(out.intent).toBe('question');
186
+ expect(out.text).not.toBe('Got it.');
187
+ expect(s.ask).toHaveBeenCalledTimes(1);
188
+ });
189
+
190
+ it('every kind of turn says what it was', async () => {
191
+ const s = setup();
192
+ const brain = createConverseBrain({ ...s.deps, routeLlm: routeSays('other'), loadItems: async () => [{ id: 'bench', title: "Order dad's bench", status: 'open', dueAt: '2026-11-04', ownerSub: ME, focusName: 'Home' }] as never, loadActivity: async () => ({ finished: [], added: [], notes: [] }) });
193
+ expect((await brain(say('hello'))).intent).toBe('chat');
194
+ expect((await brain(say('what is on my plate'))).intent).toBe('briefing');
195
+ expect((await brain(say('what did I do yesterday'))).intent).toBe('question');
196
+ expect((await createConverseBrain({ ...s.deps, routeLlm: routeSays('work') })(say('tell the relay to fix the bug'))).intent).toBe('relay');
197
+ expect((await brain(say("mark order dad's bench as done"))).intent).toBe('command');
198
+ });
199
+
200
+ it('an answer carries its sources (documents, items, projects) for the thread to show', async () => {
201
+ const s = setup();
202
+ const brain = createConverseBrain({ ...s.deps, ask: async () => ({ answer: 'The bench is due today.', sources: [{ kind: 'item', title: "Order dad's bench", id: 'item:bench' }] }) });
203
+ expect((await brain(say('what is due today'))).sources).toEqual([{ kind: 'item', title: "Order dad's bench", id: 'item:bench' }]);
204
+ });
205
+ });
206
+
163
207
  describe('what did I do yesterday', () => {
164
208
  it('is answered from the window read, not by Ask, and nothing is written', async () => {
165
209
  const s = setup();
@@ -219,6 +219,124 @@ describe('meeting controller', () => {
219
219
  });
220
220
  });
221
221
 
222
+ const sendFirst = (c: { sendText(t: string): Promise<void> }) => c.sendText('hello');
223
+
224
+ describe('micOn tells the truth from the start', () => {
225
+ it('is false before anything runs, true once the meeting listens, false after End', async () => {
226
+ const { c } = rig({ utterances: [] });
227
+ expect(c.state().micOn).toBe(false);
228
+ await c.sendText('typed first');
229
+ expect(c.state().micOn).toBe(false);
230
+ expect(c.state().phase).toBe('idle');
231
+ c.mic(true);
232
+ expect(c.state().micOn).toBe(true);
233
+ await c.end();
234
+ expect(c.state().micOn).toBe(false);
235
+ });
236
+ });
237
+
238
+ describe('the mic is a small control: mic(on)', () => {
239
+ /** listen() that, like the real io, hands back what was said so far when aborted with reason 'finish'. */
240
+ function micRig(spoke = true) {
241
+ const phases: string[] = [];
242
+ let n = 0;
243
+ const client: ConverseClient = {
244
+ turn: vi.fn(async (input) => turnResult(++n, { transcript: input.text ?? 'said by voice' })),
245
+ end: vi.fn(async () => ({ saved: true as const, conversation_id: 'conversation-1', record_id: '9', turns: n, asks: [], decisions: [] })),
246
+ };
247
+ const io: MeetingIO = {
248
+ listen: vi.fn((signal: AbortSignal) => new Promise((resolve) => {
249
+ signal.addEventListener('abort', () => resolve(spoke && signal.reason === 'finish' ? { audio: blob() } : { audio: null, cancelled: true }));
250
+ })),
251
+ speak: vi.fn(async () => undefined),
252
+ };
253
+ const c = createMeetingController({ client, io, config: {}, onChange: (st) => phases.push(st.phase) });
254
+ return { c, client, io };
255
+ }
256
+
257
+ it('mic(false) stops listening and SENDS what was recorded (tap to stop), the conversation stays open, the mic is off', async () => {
258
+ const { c, client, io } = micRig();
259
+ c.start();
260
+ expect(c.state().micOn).toBe(true);
261
+ await settle(() => (io.listen as any).mock.calls.length === 1);
262
+ c.mic(false);
263
+ await settle(() => (client.turn as any).mock.calls.length === 1);
264
+ expect((client.turn as any).mock.calls[0][0].audio).toBeInstanceOf(Blob);
265
+ expect(c.state().micOn).toBe(false);
266
+ expect(c.state().phase).toBe('idle');
267
+ expect(c.state().conversationId).toBe('conversation-1');
268
+ expect(client.end).not.toHaveBeenCalled();
269
+ });
270
+
271
+ it('with the mic off the loop does not listen again, but typing still works; mic(true) listens again', async () => {
272
+ const { c, io, client } = micRig(false);
273
+ c.start();
274
+ c.mic(false);
275
+ await new Promise((r) => setTimeout(r, 30));
276
+ const listens = (io.listen as any).mock.calls.length;
277
+ await c.sendText('typed while the mic is off');
278
+ expect((client.turn as any).mock.calls[0][0].text).toBe('typed while the mic is off');
279
+ await new Promise((r) => setTimeout(r, 30));
280
+ expect((io.listen as any).mock.calls.length).toBe(listens);
281
+ c.mic(true);
282
+ await settle(() => (io.listen as any).mock.calls.length > listens);
283
+ expect((io.listen as any).mock.calls.length).toBeGreaterThan(listens);
284
+ expect(c.state().micOn).toBe(true);
285
+ expect(c.state().phase).toBe('listening');
286
+ await c.end();
287
+ });
288
+
289
+ it('End works while the mic is off (the loop is not left waiting)', async () => {
290
+ const { c, client } = micRig(false);
291
+ c.start();
292
+ await sendFirst(c);
293
+ c.mic(false);
294
+ await new Promise((r) => setTimeout(r, 20));
295
+ const saved = await Promise.race([c.end(), new Promise((r) => setTimeout(() => r('hung'), 1000))]);
296
+ expect(saved).not.toBe('hung');
297
+ expect(client.end).toHaveBeenCalled();
298
+ });
299
+
300
+ it('mic(true) after typing (before any Start) continues the SAME conversation instead of starting a new one', async () => {
301
+ const { c, client } = micRig(false);
302
+ await c.sendText('typed first');
303
+ const id = c.state().conversationId;
304
+ expect(id).toBe('conversation-1');
305
+ c.mic(true);
306
+ await new Promise((r) => setTimeout(r, 20));
307
+ expect(c.state().conversationId).toBe(id);
308
+ expect(c.state().lines.map((l) => l.text)).toEqual(['typed first', 'reply 1']);
309
+ await c.end();
310
+ expect(client.end).toHaveBeenCalledWith('conversation-1');
311
+ });
312
+ });
313
+
314
+ describe('a turn that wraps the conversation up, and the intent and sources a reply carries', () => {
315
+ it('ended:true: a quiet Filed line, the next message starts a NEW conversation', async () => {
316
+ const turn = vi.fn()
317
+ .mockResolvedValueOnce(turnResult(1, { ended: true, filed: { note: true, todos: 2 }, intent: 'note' }))
318
+ .mockResolvedValueOnce(turnResult(1, { conversation_id: 'conversation-2' }));
319
+ const { c } = rig({ utterances: [], turn: turn as never });
320
+ c.start();
321
+ await c.sendText('parse that note');
322
+ expect(c.state().lines.at(-1)).toEqual({ role: 'system', text: 'Filed: 2 to-dos' });
323
+ expect(c.state().conversationId).toBeNull();
324
+ await c.sendText('next thing');
325
+ expect((turn.mock.calls[1][0] as any).conversationId).toBeUndefined();
326
+ expect(c.state().conversationId).toBe('conversation-2');
327
+ await c.end();
328
+ });
329
+
330
+ it('an assistant line keeps its intent and sources', async () => {
331
+ const sources = [{ kind: 'todo', title: 'Order the bench', id: 'item:1' }];
332
+ const { c } = rig({ utterances: [], turn: vi.fn(async () => turnResult(1, { intent: 'question', sources })) as never });
333
+ c.start();
334
+ await c.sendText('what is due');
335
+ expect(c.state().lines.at(-1)).toMatchObject({ role: 'assistant', intent: 'question', sources });
336
+ await c.end();
337
+ });
338
+ });
339
+
222
340
  describe('a recording with no words', () => {
223
341
  it('is dropped quietly: no line, no reply spoken, and the meeting listens again', async () => {
224
342
  const { c, speak } = rig({ utterances: [blob()], turn: vi.fn(async () => turnResult(1, { transcript: '', reply_text: 'Sorry, I did not catch that. Can you say that again?', audio_url: null, audio_reason: 'nothing was heard' })) as never });
@@ -1,9 +1,9 @@
1
1
  // @vitest-environment jsdom
2
2
  /**
3
- * The /converse page as a meeting (bd startsim-1jqce): Start once, it listens by itself, answers, listens again;
4
- * state and reply text are always visible; a missing reply sound is explained; End saves.
3
+ * The ONE converse screen (Talk and Ask are one thread): a readable thread, a text input with a small mic
4
+ * toggle and Send beside it, a small Done. No mode toggle, no start circle, nothing laid over the thread.
5
5
  */
6
- import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
6
+ import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
7
7
  import * as React from 'react';
8
8
  import { afterEach, describe, expect, it, vi } from 'vitest';
9
9
 
@@ -18,126 +18,193 @@ const turnResult = (n: number, over: object = {}) => ({
18
18
  audio_url: `/corpus/converse/conversation-1/turn/${n}/audio`, audio_reason: null, ...over,
19
19
  });
20
20
 
21
- function setup(over: { turn?: ConverseClient['turn']; openError?: Error; utterances?: number } = {}) {
21
+ interface Opts { turn?: ConverseClient['turn']; openError?: Error; heard?: boolean; thread?: ConverseClient['thread'] }
22
+
23
+ function setup(over: Opts = {}) {
22
24
  let n = 0;
23
25
  const client: ConverseClient = {
24
26
  turn: over.turn ?? vi.fn(async () => turnResult(++n)),
25
27
  end: vi.fn(async () => ({ saved: true as const, conversation_id: 'conversation-1', record_id: '7', turns: n, asks: [], decisions: [] })),
26
28
  audioUrl: vi.fn(async (p: string) => `blob:${p}`),
27
- thread: vi.fn(async () => ({ conversation_id: 'conversation-1', status: 'open' as const, updated_at: 't', turns: [] })),
29
+ thread: over.thread ?? vi.fn(async () => ({ conversation_id: 'conversation-1', status: 'open' as const, updated_at: 't', turns: [] })),
28
30
  };
29
- let left = over.utterances ?? 1;
30
31
  const speak = vi.fn(async () => undefined);
32
+ const listen = vi.fn((signal: AbortSignal) => new Promise<{ audio: Blob | null; cancelled?: boolean }>((resolve) => {
33
+ // Like the real recorder: tapping the mic off ('finish') hands back what was said; any other abort is a plain cancel.
34
+ signal.addEventListener('abort', () => resolve(signal.reason === 'finish' && over.heard !== false
35
+ ? { audio: new Blob([new Uint8Array([1])], { type: 'audio/mp4' }) } : { audio: null, cancelled: true }));
36
+ }));
31
37
  const io: BrowserMeetingIO = {
32
38
  open: vi.fn(async () => { if (over.openError) throw over.openError; }),
39
+ unlockPlayback: vi.fn(),
33
40
  close: vi.fn(),
34
41
  setSpeed: vi.fn(),
35
- listen: vi.fn((signal: AbortSignal) => new Promise<{ audio: Blob | null; cancelled?: boolean }>((resolve) => {
36
- if (left > 0) { left -= 1; resolve({ audio: new Blob([new Uint8Array([1])], { type: 'audio/mp4' }) }); return; }
37
- signal.addEventListener('abort', () => resolve({ audio: null, cancelled: true }));
38
- })),
42
+ listen,
39
43
  speak,
40
44
  };
41
- render(<ConversePage client={client} createIO={() => io} />);
42
- return { client, io, speak };
45
+ const view = render(<ConversePage client={client} createIO={() => io} meeting={{ relayPollMs: 5 }} />);
46
+ return { client, io, speak, listen, view };
43
47
  }
44
- const status = () => screen.getByTestId('converse-status').textContent ?? '';
48
+ const mic = () => screen.getByTestId('converse-mic');
49
+ const type = (text: string) => {
50
+ fireEvent.change(screen.getByLabelText('Type a message'), { target: { value: text } });
51
+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));
52
+ };
45
53
 
46
- describe('ConversePage (meeting)', () => {
47
- it('after Start the big start button is gone: a slim status row with a small End button replaces it', async () => {
54
+ describe('the one converse screen', () => {
55
+ it('has an input, a small mic and Send, and no Talk/Ask toggle and no start button', () => {
48
56
  setup();
49
- fireEvent.click(screen.getByTestId('converse-start'));
50
- await waitFor(() => expect(screen.getByTestId('converse-live-row')).toBeTruthy());
57
+ expect(screen.getByLabelText('Type a message')).toBeTruthy();
58
+ expect(mic().getAttribute('aria-pressed')).toBe('false');
59
+ expect(screen.queryByRole('tablist')).toBeNull();
60
+ expect(screen.queryAllByRole('tab')).toHaveLength(0);
51
61
  expect(screen.queryByTestId('converse-start')).toBeNull();
52
- expect(screen.getByTestId('converse-live-row').contains(screen.getByTestId('converse-end'))).toBe(true);
62
+ expect(screen.queryByText(/start talking/i)).toBeNull();
53
63
  });
54
64
 
55
- it('speech speed defaults to 1.25x, is remembered, and applies to the open conversation', async () => {
56
- const store = new Map<string, string>();
57
- vi.stubGlobal('localStorage', { getItem: (k: string) => store.get(k) ?? null, setItem: (k: string, v: string) => { store.set(k, v); } });
58
- const { io } = setup();
59
- const sel = screen.getByTestId('converse-speed') as HTMLSelectElement;
60
- expect(sel.value).toBe('1.25');
61
- fireEvent.click(screen.getByTestId('converse-start'));
62
- await waitFor(() => expect(io.open).toHaveBeenCalled());
63
- fireEvent.change(sel, { target: { value: '2' } });
64
- expect(io.setSpeed).toHaveBeenCalledWith(2);
65
- expect(store.get('tandem.converse.speed')).toBe('2');
66
- vi.unstubAllGlobals();
65
+ it('nothing is laid over the thread: no fixed or absolute element, thread is not covered', () => {
66
+ const { view } = setup();
67
+ const all = Array.from(view.container.querySelectorAll<HTMLElement>('*'));
68
+ const positioned = all.filter((el) => /(^|\s)(fixed|absolute|sticky)(\s|$)/.test(el.className?.toString() ?? '') || /fixed|absolute/.test(el.style.position));
69
+ expect(positioned).toEqual([]);
70
+ const thread = screen.getByTestId('converse-thread');
71
+ expect(thread.getAttribute('aria-label')).toBe('Conversation');
72
+ expect(thread.parentElement?.contains(mic())).toBe(true);
67
73
  });
68
74
 
69
- it('one Start tap, then it listens, answers, speaks and listens again by itself', async () => {
70
- const { client, io, speak } = setup({ utterances: 2 });
71
- fireEvent.click(screen.getByTestId('converse-start'));
72
- await waitFor(() => expect(screen.getByText('reply 2')).toBeTruthy());
75
+ it('the mic toggles mic on and off, shows the state, and tapping it off sends what was said as the user line', async () => {
76
+ const { client, io, listen } = setup();
77
+ fireEvent.click(mic());
78
+ await waitFor(() => expect(mic().getAttribute('aria-pressed')).toBe('true'));
73
79
  expect(io.open).toHaveBeenCalledTimes(1);
74
- expect(client.turn).toHaveBeenCalledTimes(2);
75
- expect(speak).toHaveBeenCalledTimes(2);
76
- expect(screen.getByText('said 1')).toBeTruthy();
77
- await waitFor(() => expect(status()).toMatch(/listening/i));
80
+ await waitFor(() => expect(listen).toHaveBeenCalled());
81
+ expect(screen.getByTestId('converse-status').textContent).toMatch(/listening/i);
82
+ fireEvent.click(mic());
83
+ await waitFor(() => expect(client.turn).toHaveBeenCalledTimes(1));
84
+ expect(mic().getAttribute('aria-pressed')).toBe('false');
85
+ expect((client.turn as any).mock.calls[0][0].audio).toBeInstanceOf(Blob);
86
+ await waitFor(() => expect(screen.getByText('said 1')).toBeTruthy());
87
+ expect(screen.getByText('reply 1')).toBeTruthy();
78
88
  });
79
89
 
80
- it('shows the state while it works', async () => {
81
- let release: (v: unknown) => void = () => undefined;
82
- setup({ turn: vi.fn(() => new Promise((r) => { release = r; })) as never });
83
- fireEvent.click(screen.getByTestId('converse-start'));
84
- await waitFor(() => expect(status()).toMatch(/thinking/i));
85
- release(turnResult(1));
90
+ it('typing and Send work with the mic off, without asking for the microphone, and the reply is read aloud', async () => {
91
+ const { client, io, speak } = setup();
92
+ type('hello there');
86
93
  await waitFor(() => expect(screen.getByText('reply 1')).toBeTruthy());
94
+ expect((client.turn as any).mock.calls[0][0].text).toBe('hello there');
95
+ expect(io.open).not.toHaveBeenCalled();
96
+ expect(io.unlockPlayback).toHaveBeenCalled();
97
+ expect(mic().getAttribute('aria-pressed')).toBe('false');
98
+ expect(speak).toHaveBeenCalledTimes(1);
99
+ expect((screen.getByLabelText('Type a message') as HTMLInputElement).value).toBe('');
87
100
  });
88
101
 
89
- it('a reply with no sound says so and why', async () => {
90
- setup({ turn: vi.fn(async () => turnResult(1, { audio_url: null, audio_reason: 'speech is not configured' })) as never });
91
- fireEvent.click(screen.getByTestId('converse-start'));
92
- await waitFor(() => expect(status()).toMatch(/no spoken reply.*speech is not configured/i));
102
+ it('a blocked microphone says so, the mic stays off and typing still works', async () => {
103
+ const { client } = setup({ openError: new Error('Microphone access was blocked. Allow it in the browser and try again.') });
104
+ fireEvent.click(mic());
105
+ await waitFor(() => expect(screen.getByRole('alert').textContent).toMatch(/blocked/));
106
+ expect(mic().getAttribute('aria-pressed')).toBe('false');
107
+ expect(client.turn).not.toHaveBeenCalled();
108
+ type('still typing');
109
+ await waitFor(() => expect(screen.getByText('reply 1')).toBeTruthy());
110
+ });
111
+
112
+ it('ended:true shows "Filed: 2 to-dos" and the next message starts a new conversation', async () => {
113
+ let n = 0;
114
+ const turn = vi.fn(async () => {
115
+ n += 1;
116
+ return n === 1 ? turnResult(1, { ended: true, filed: { note: true, todos: 2 }, intent: 'note' }) : turnResult(2, { conversation_id: 'conversation-2' });
117
+ });
118
+ setup({ turn: turn as never });
119
+ type('parse that note');
120
+ await waitFor(() => expect(screen.getByText('Filed: 2 to-dos')).toBeTruthy());
121
+ expect(screen.getByText('Filed: 2 to-dos').closest('li')?.getAttribute('data-from')).toBe('system');
122
+ type('what next');
123
+ await waitFor(() => expect(screen.getByText('reply 2')).toBeTruthy());
124
+ expect((turn.mock.calls[0] as any)[0].conversationId).toBeUndefined();
125
+ expect((turn.mock.calls[1] as any)[0].conversationId).toBeUndefined();
93
126
  });
94
127
 
95
- it('End and save saves, clears the screen and says so', async () => {
96
- const { client, io } = setup();
97
- fireEvent.click(screen.getByTestId('converse-start'));
128
+ it('a note with no to-dos says "Filed the note"; a normal turn keeps the conversation id', async () => {
129
+ const turn = vi.fn()
130
+ .mockResolvedValueOnce(turnResult(1))
131
+ .mockResolvedValueOnce(turnResult(2, { ended: true, filed: { note: true, todos: 0 } }));
132
+ setup({ turn: turn as never });
133
+ type('one');
98
134
  await waitFor(() => expect(screen.getByText('reply 1')).toBeTruthy());
99
- fireEvent.click(screen.getByTestId('converse-end'));
100
- await waitFor(() => expect(screen.getByTestId('converse-saved').textContent).toMatch(/Saved 1 turn/));
101
- expect(client.end).toHaveBeenCalledWith('conversation-1');
102
- expect(io.close).toHaveBeenCalled();
103
- expect(screen.getByTestId('converse-start')).toBeTruthy();
135
+ type('that is it');
136
+ await waitFor(() => expect(screen.getByText('Filed the note')).toBeTruthy());
137
+ expect((turn.mock.calls[1] as any)[0].conversationId).toBe('conversation-1');
104
138
  });
105
139
 
106
- it('Play reply plays the last reply again', async () => {
107
- const { speak } = setup();
108
- fireEvent.click(screen.getByTestId('converse-start'));
140
+ it('assistant lines show their sources as small chips (kind and title)', async () => {
141
+ const sources = [{ kind: 'todo', title: 'Call the landlord', id: 'item:1' }, { kind: 'note', title: 'Monday plan', id: 'n2' }];
142
+ setup({ turn: vi.fn(async () => turnResult(1, { intent: 'question', sources })) as never });
143
+ type('what did I do yesterday');
109
144
  await waitFor(() => expect(screen.getByText('reply 1')).toBeTruthy());
110
- const before = speak.mock.calls.length;
111
- fireEvent.click(screen.getByText('Play reply'));
112
- await waitFor(() => expect(speak.mock.calls.length).toBe(before + 1));
145
+ const chips = screen.getAllByTestId('converse-source');
146
+ expect(chips.map((c) => c.textContent)).toEqual(['todo: Call the landlord', 'note: Monday plan']);
113
147
  });
114
148
 
115
- it('typing works without the microphone path', async () => {
116
- const { client } = setup({ utterances: 0 });
117
- fireEvent.click(screen.getByTestId('converse-start'));
118
- await waitFor(() => expect(status()).toMatch(/listening/i));
119
- fireEvent.change(screen.getByLabelText('Type a message'), { target: { value: 'hello there' } });
120
- fireEvent.click(screen.getByText('Send'));
149
+ it('each assistant line has its own replay control that plays that line\'s audio', async () => {
150
+ const { speak } = setup();
151
+ type('one');
121
152
  await waitFor(() => expect(screen.getByText('reply 1')).toBeTruthy());
122
- expect((client.turn as any).mock.calls[0][0].text).toBe('hello there');
153
+ type('two');
154
+ await waitFor(() => expect(screen.getByText('reply 2')).toBeTruthy());
155
+ const buttons = screen.getAllByRole('button', { name: 'Play this reply' });
156
+ expect(buttons).toHaveLength(2);
157
+ speak.mockClear();
158
+ fireEvent.click(buttons[0]);
159
+ await waitFor(() => expect(speak).toHaveBeenCalledTimes(1));
160
+ expect((speak.mock.calls[0] as any)[0].audioUrl).toBe('/corpus/converse/conversation-1/turn/1/audio');
161
+ // user lines have none
162
+ expect(within(screen.getByText('said 1').closest('li') as HTMLElement).queryByRole('button', { name: 'Play this reply' })).toBeNull();
163
+ });
164
+
165
+ it('a reply with no sound says so and why', async () => {
166
+ setup({ turn: vi.fn(async () => turnResult(1, { audio_url: null, audio_reason: 'speech is not configured' })) as never });
167
+ type('hi');
168
+ await waitFor(() => expect(screen.getByTestId('converse-status').textContent).toMatch(/no spoken reply.*speech is not configured/i));
123
169
  });
124
170
 
125
- it('typing still works when the microphone is blocked, and says why there is no listening', async () => {
126
- const { client } = setup({ openError: new Error('Microphone access was blocked. Allow it in the browser and try again.'), utterances: 0 });
127
- fireEvent.change(screen.getByLabelText('Type a message'), { target: { value: 'hello there' } });
128
- fireEvent.click(screen.getByText('Send'));
171
+ it('Done saves the conversation and the next message starts fresh; the thread stays', async () => {
172
+ const { client } = setup();
173
+ type('hi');
129
174
  await waitFor(() => expect(screen.getByText('reply 1')).toBeTruthy());
130
- expect((client.turn as any).mock.calls[0][0].text).toBe('hello there');
131
- expect(screen.getByRole('alert').textContent).toMatch(/blocked/);
132
- expect(status()).not.toMatch(/speak whenever/i);
133
- expect(status()).toMatch(/type/i);
175
+ fireEvent.click(screen.getByRole('button', { name: 'Done' }));
176
+ await waitFor(() => expect(client.end).toHaveBeenCalledWith('conversation-1'));
177
+ await waitFor(() => expect(screen.getByTestId('converse-saved').textContent).toMatch(/Saved 1 turn/));
178
+ expect(screen.getByText('reply 1')).toBeTruthy();
179
+ type('again');
180
+ await waitFor(() => expect(screen.getByText('reply 1', { selector: 'li *, li' })).toBeTruthy());
181
+ expect((client.turn as any).mock.calls[1][0].conversationId).toBeUndefined();
134
182
  });
135
183
 
136
- it('a blocked microphone says so and nothing starts', async () => {
137
- const { client } = setup({ openError: new Error('Microphone access was blocked. Allow it in the browser and try again.') });
138
- fireEvent.click(screen.getByTestId('converse-start'));
139
- await waitFor(() => expect(screen.getByRole('alert').textContent).toMatch(/blocked/));
140
- expect(client.turn).not.toHaveBeenCalled();
141
- expect(screen.getByTestId('converse-start')).toBeTruthy();
184
+ it('relay lines are labelled as the relay', async () => {
185
+ const thread = vi.fn(async () => ({
186
+ conversation_id: 'conversation-1', status: 'open' as const, updated_at: 't',
187
+ turns: [{ turn: 2, who: 'relay' as const, transcript: '', reply_text: 'Ship it', audio_url: null, audio_reason: 'x', created_at: 't' }],
188
+ }));
189
+ setup({ thread: thread as never });
190
+ type('hi');
191
+ await waitFor(() => expect(screen.getByText('Ship it')).toBeTruthy());
192
+ const li = screen.getByText('Ship it').closest('li') as HTMLElement;
193
+ expect(li.getAttribute('data-from')).toBe('relay');
194
+ expect(li.textContent).toMatch(/^Relay:/);
195
+ });
196
+
197
+ it('speech speed defaults to 1.25x, is remembered, and applies to the open conversation', async () => {
198
+ const store = new Map<string, string>();
199
+ vi.stubGlobal('localStorage', { getItem: (k: string) => store.get(k) ?? null, setItem: (k: string, v: string) => { store.set(k, v); } });
200
+ const { io } = setup();
201
+ const sel = screen.getByTestId('converse-speed') as HTMLSelectElement;
202
+ expect(sel.value).toBe('1.25');
203
+ fireEvent.click(mic());
204
+ await waitFor(() => expect(io.open).toHaveBeenCalled());
205
+ fireEvent.change(sel, { target: { value: '2' } });
206
+ expect(io.setSpeed).toHaveBeenCalledWith(2);
207
+ expect(store.get('tandem.converse.speed')).toBe('2');
208
+ vi.unstubAllGlobals();
142
209
  });
143
210
  });