@startsimpli/integrations 0.2.157 → 0.2.160

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.157",
3
+ "version": "0.2.160",
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,7 +50,7 @@
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.178",
53
+ "@startsimpli/ui": "^0.4.181",
54
54
  "@startsimpli/utils": "^0.4.18",
55
55
  "@startsimpli/auth": "^0.4.51"
56
56
  },
@@ -99,7 +99,7 @@
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.178",
102
+ "@startsimpli/ui": "0.4.181",
103
103
  "@startsimpli/ui-native": "0.1.14",
104
104
  "@startsimpli/auth": "0.4.51",
105
105
  "@startsimpli/utils": "0.4.18"
@@ -0,0 +1,80 @@
1
+ /** The weekly summary (bd startsim-tmrvi): pure composer, deterministic script, owner-only. */
2
+ import { describe, expect, it } from 'vitest';
3
+
4
+ import { composeWeekly, weeklyScript } from '../corpus/briefing/weekly';
5
+ import { generateWeekly } from '../corpus/briefing/generate-weekly';
6
+ import type { BriefingItem } from '../corpus/briefing/types';
7
+ import type { BriefingRecord, BriefingStore } from '../corpus/briefing/store';
8
+
9
+ const NOW = Date.parse('2026-11-11T15:00:00Z'); // Wednesday
10
+ const it_ = (id: string, over: Partial<BriefingItem>): BriefingItem => ({ id, title: `Thing ${id}`, status: 'open', ownerSub: 'q', ...over });
11
+ const ITEMS: BriefingItem[] = [
12
+ it_('d1', { status: 'done', resolvedAt: '2026-11-09T10:00:00Z' }),
13
+ it_('d2', { status: 'done', resolvedAt: '2026-10-01T10:00:00Z' }),
14
+ it_('d3', { status: 'done' }),
15
+ it_('s1', { dueAt: '2026-11-06' }),
16
+ it_('s2', { status: 'blocked' }),
17
+ it_('u1', { dueAt: '2026-11-13', focusName: 'Marketing' }),
18
+ it_('u2', { dueAt: '2026-11-30' }),
19
+ it_('x1', { dueAt: '2026-11-06', ownerSub: 'someone-else' }),
20
+ it_('x2', { dueAt: '2026-11-06', status: 'dropped' }),
21
+ ];
22
+
23
+ describe('composeWeekly', () => {
24
+ const w = composeWeekly(ITEMS, { ownerSub: 'q', now: NOW });
25
+ it('buckets by state and date, for the owner only', () => {
26
+ expect(w.done.map((e) => e.id)).toEqual(['d1']);
27
+ expect(w.slipping.map((e) => e.id)).toEqual(['s1', 's2']);
28
+ expect(w.upcoming.map((e) => e.id)).toEqual(['u1']);
29
+ expect(w.empty).toBe(false);
30
+ });
31
+ it('a done item with no finish time is not counted', () => {
32
+ expect(w.counts.done).toBe(1);
33
+ });
34
+ });
35
+
36
+ describe('weeklyScript', () => {
37
+ it('speaks all three sections and never leaks a numeric date', () => {
38
+ const text = weeklyScript(composeWeekly(ITEMS, { ownerSub: 'q', now: NOW }), { now: NOW, name: 'Quinn' }).text;
39
+ expect(text).toContain('Good afternoon, Quinn');
40
+ expect(text).toMatch(/finished one item/);
41
+ expect(text).toMatch(/Two items are slipping/);
42
+ expect(text).toMatch(/Coming up/);
43
+ expect(text).not.toMatch(/\d{4}-\d{2}-\d{2}/);
44
+ });
45
+ it('says so when the week is empty', () => {
46
+ const text = weeklyScript(composeWeekly([], { ownerSub: 'q', now: NOW }), { now: NOW }).text;
47
+ expect(text).toMatch(/Nothing was finished/);
48
+ });
49
+ });
50
+
51
+ describe('generateWeekly', () => {
52
+ function deps(saved: BriefingRecord[]) {
53
+ const store: BriefingStore = {
54
+ async find(id) { return saved.find((r) => r.externalId === id) ?? null; },
55
+ async get() { return null; },
56
+ async save(draft) { const r = { ...draft, id: `row${saved.length}` } as BriefingRecord; saved.push(r); return r; },
57
+ };
58
+ let speech = 0;
59
+ return {
60
+ speech: () => speech,
61
+ d: {
62
+ http: { get: async () => ({}), post: async () => ({}) } as never,
63
+ orgId: 'o', ownerSub: 'q', loadItems: async () => ITEMS, scriptLlm: null, store, now: () => NOW,
64
+ synthesize: async () => { speech += 1; return { audio: new Uint8Array([1]), mimeType: 'audio/mpeg', model: 'm', provider: 'p', usage: {} }; },
65
+ audio: { put: async () => 'ref', url: async () => 'http://audio' },
66
+ },
67
+ };
68
+ }
69
+ it('keeps one row, and a repeat tap does not synthesize again', async () => {
70
+ const saved: BriefingRecord[] = [];
71
+ const { d, speech } = deps(saved);
72
+ const first = await generateWeekly(d);
73
+ const second = await generateWeekly(d);
74
+ expect(first.cached).toBe(false);
75
+ expect(second.cached).toBe(true);
76
+ expect(saved).toHaveLength(1);
77
+ expect(speech()).toBe(1);
78
+ expect(saved[0].externalId).toBe('weekly:2026-11-11:q');
79
+ });
80
+ });
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Ask over tracked items (bd startsim-tmrvi): dates and states are decided in
3
+ * code, the answer must cite the item records, and an item question with nothing
4
+ * matching must say so instead of asking a model.
5
+ */
6
+ import { describe, expect, it } from 'vitest';
7
+
8
+ import { askCorpus } from '../corpus/ask';
9
+ import { itemIntent } from '../corpus/ask-items-intent';
10
+ import { selectItems } from '../corpus/ask-items';
11
+ import { createFixtureCorpusApi, FIXTURE_ORG } from '../corpus/fixtures';
12
+ import type { AnswerDraft, AnswerRequest, Commitment, CorpusLlm } from '../corpus/types';
13
+
14
+ const SCOPE = { orgId: FIXTURE_ORG };
15
+ // Wednesday 2026-11-11, noon UTC.
16
+ const NOW = Date.parse('2026-11-11T12:00:00Z');
17
+
18
+ function item(id: string, over: Partial<Commitment>): Commitment {
19
+ return {
20
+ id, externalId: `commit:${id}`, dedupeKey: id, subtype: 'task', title: `Item ${id}`, detail: '', status: 'open',
21
+ subjectKey: '', actionKey: '', mentions: [], firstSeenAt: '2026-10-01T00:00:00Z', lastSeenAt: null,
22
+ extractorVersion: 'x', source: 'voice', sourceLabel: 'Voice', scope: SCOPE, ownerSub: 'me', ...over,
23
+ } as Commitment;
24
+ }
25
+ const ITEMS = [
26
+ item('a', { title: 'Send the Acme deck', dueAt: '2026-11-13', ownerName: 'Quinn' }),
27
+ item('b', { title: 'Fix login bug', dueAt: '2026-11-05', status: 'in_progress', sync: { state: 'synced', key: 'TAN-7', stateName: 'In Progress' } }),
28
+ item('c', { title: 'Old finished thing', dueAt: '2026-11-05', status: 'done' }),
29
+ item('d', { title: 'Someone elses', dueAt: '2026-11-13', ownerSub: 'other' }),
30
+ item('e', { title: 'Next week thing', dueAt: '2026-11-17' }),
31
+ ];
32
+ const commitments = { listCommitments: async () => ({ count: ITEMS.length, next: null, previous: null, results: ITEMS }) };
33
+
34
+ function llmCiting(ids: string[], calls: AnswerRequest[] = []): CorpusLlm {
35
+ return {
36
+ describe: () => ({ provider: 'scripted', model: 's', live: false }),
37
+ async answer(input): Promise<AnswerDraft> {
38
+ calls.push(input);
39
+ return { answer: 'ok', citations: ids.map((documentId) => ({ documentId })) };
40
+ },
41
+ };
42
+ }
43
+
44
+ describe('itemIntent', () => {
45
+ it('is null for a question that is not about items', () => {
46
+ expect(itemIntent('what did Acme say about pricing', NOW)).toBeNull();
47
+ });
48
+ it('reads Friday as the coming Friday', () => {
49
+ const i = itemIntent('what is due Friday', NOW)!;
50
+ expect([i.focus, i.from, i.to]).toEqual(['due', '2026-11-13', '2026-11-13']);
51
+ });
52
+ it('reads this week as Monday to Sunday', () => {
53
+ const i = itemIntent('what did I commit to this week?', NOW)!;
54
+ expect([i.focus, i.from, i.to, i.mine]).toEqual(['committed', '2026-11-09', '2026-11-15', true]);
55
+ });
56
+ it('uses the reader zone for today', () => {
57
+ expect(itemIntent('what is overdue', Date.parse('2026-11-12T02:00:00Z'), 'America/New_York')!.today).toBe('2026-11-11');
58
+ });
59
+ });
60
+
61
+ describe('selectItems', () => {
62
+ const ctx = { now: NOW, ownerSub: 'me' };
63
+ it('slipping = unfinished and past due, never done ones', () => {
64
+ const ids = selectItems(ITEMS, itemIntent('what is slipping', NOW)!, ctx).map((i) => i.id);
65
+ expect(ids).toEqual(['b']);
66
+ });
67
+ it('due Friday, mine only when asked for mine', () => {
68
+ expect(selectItems(ITEMS, itemIntent('what is due Friday', NOW)!, ctx).map((i) => i.id)).toEqual(['a', 'd']);
69
+ expect(selectItems(ITEMS, itemIntent('what do I have due Friday', NOW)!, ctx).map((i) => i.id)).toEqual(['a']);
70
+ });
71
+ });
72
+
73
+ describe('askCorpus over items', () => {
74
+ const corpus = createFixtureCorpusApi({ scope: SCOPE });
75
+ it('puts the matching items first, cites them by item: id, and sends today', async () => {
76
+ const calls: AnswerRequest[] = [];
77
+ const result = await askCorpus(
78
+ { question: 'what is slipping?', mode: 'ask', scope: SCOPE },
79
+ { corpus, commitments, llm: llmCiting(['item:commit:b'], calls) },
80
+ { now: NOW, ownerSub: 'me' },
81
+ );
82
+ expect(calls).toHaveLength(1);
83
+ expect(calls[0].documents[0].id).toBe('item:commit:b');
84
+ expect(calls[0].documents[0].text).toContain('Linear: TAN-7 — In Progress');
85
+ expect(calls[0].today).toBe('2026-11-11');
86
+ expect(result.status).toBe('answered');
87
+ expect(result.citations[0].document.subtype).toBe('tracked_item');
88
+ });
89
+ it('does not touch the model when nothing matches and no documents do', async () => {
90
+ const calls: AnswerRequest[] = [];
91
+ const result = await askCorpus(
92
+ { question: 'what is due zzzqq tomorrow', mode: 'ask', scope: SCOPE },
93
+ { corpus, commitments, llm: llmCiting([], calls) },
94
+ { now: NOW, ownerSub: 'me' },
95
+ );
96
+ expect(result.status).toBe('no_evidence');
97
+ expect(calls).toHaveLength(0);
98
+ });
99
+ it('a non-item question never reads commitments', async () => {
100
+ let reads = 0;
101
+ await askCorpus(
102
+ { question: 'Acme renewal rate and seats', mode: 'ask', scope: SCOPE },
103
+ { corpus, commitments: { listCommitments: async () => { reads += 1; return { count: 0, next: null, previous: null, results: [] }; } }, llm: llmCiting([]) },
104
+ { now: NOW },
105
+ );
106
+ expect(reads).toBe(0);
107
+ });
108
+ });
@@ -50,6 +50,16 @@ describe('HomeBriefPage', () => {
50
50
  expect(fetch.mock.calls[0]).toHaveLength(0);
51
51
  });
52
52
 
53
+ it('shows the weekly summary only when asked, and never loads it on mount', async () => {
54
+ const weekly = vi.fn(async () => ({ text: 'Here is your week. You finished two items.', audioUrl: null, audioReason: 'No audio.' }));
55
+ render(<HomeBriefPage brief={{ fetch: async () => RESULT }} weekly={{ fetch: weekly }} corpus={corpus()} now={NOW} timeZone="UTC" />);
56
+ await screen.findByTestId('brief-text');
57
+ expect(weekly).not.toHaveBeenCalled();
58
+ await userEvent.click(screen.getByRole('button', { name: 'Show your week' }));
59
+ expect(await screen.findByText('Here is your week. You finished two items.')).toBeInTheDocument();
60
+ expect(weekly).toHaveBeenCalledTimes(1);
61
+ });
62
+
53
63
  it('groups what is due with the project as a chip', async () => {
54
64
  render(
55
65
  <HomeBriefPage
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Home with "Needs your call" (bd startsim-tmrvi.7): an answer shows on the to-do it was about
3
+ * straight away, a guessed date reads quietly, and a failed save puts everything back.
4
+ */
5
+ import * as React from 'react';
6
+ import { render, screen, waitFor, within } from '@testing-library/react';
7
+ import userEvent from '@testing-library/user-event';
8
+ import { describe, expect, it, vi } from 'vitest';
9
+
10
+ import { HomeBriefPage } from '../components/pages/home';
11
+ import type { NeedsYourCallApi } from '../components/pages/questions';
12
+ import type { BriefingResult } from '../corpus/briefing';
13
+ import type { OpenQuestion } from '../corpus/questions';
14
+ import type { Commitment, CommitmentApi, CorpusApi } from '../corpus/types';
15
+
16
+ const NOW = Date.parse('2026-11-06T17:00:00Z');
17
+ const RESULT = { briefingId: 'b1', text: 'Good morning.', audioUrl: null, items: [], remaining: 0, context: { itemIds: [], localDate: '2026-11-06', timeZone: 'UTC', offsets: [] }, scriptSource: 'template', cached: true, ms: 1 } as unknown as BriefingResult;
18
+
19
+ function item(id: string, over: Partial<Commitment> = {}): Commitment {
20
+ return {
21
+ id, externalId: `commit:${id}`, dedupeKey: id, subtype: 'action', title: id, detail: '', status: 'open', subjectKey: '', actionKey: '',
22
+ mentions: [], firstSeenAt: null, lastSeenAt: null, extractorVersion: 't', source: 'granola', sourceLabel: 'G', scope: { orgId: 'o' }, ...over,
23
+ } as Commitment;
24
+ }
25
+ const corpus = (): CorpusApi & CommitmentApi => ({
26
+ async listCommitments() { return { count: 1, next: null, previous: null, results: [item('Send the term sheet', { dueAt: '2026-11-13' })] }; },
27
+ async listDocuments() { return { count: 0, next: null, previous: null, results: [] }; },
28
+ }) as unknown as CorpusApi & CommitmentApi;
29
+
30
+ const QUESTION: OpenQuestion = {
31
+ id: 'q1', itemId: 'Send the term sheet', kind: 'due_date', question: 'Is next Friday right?', status: 'open', score: 80,
32
+ assumed: { value: '2026-11-13', confidence: 0.4, reason: '' }, candidates: [{ value: '2026-11-09', confidence: 0.3, reason: '' }],
33
+ ownerSub: 'u1', createdAt: '', updatedAt: '',
34
+ };
35
+ const questions = (answer: NeedsYourCallApi['answer']): NeedsYourCallApi => ({ list: async () => [QUESTION], answer, skip: async () => undefined });
36
+ const page = (api: NeedsYourCallApi) => <HomeBriefPage brief={{ fetch: async () => RESULT }} corpus={corpus()} now={NOW} timeZone="UTC" questions={api} />;
37
+
38
+ describe('Home: Needs your call', () => {
39
+ it('marks a guessed date lightly on its to-do', async () => {
40
+ render(page(questions(async () => undefined)));
41
+ const row = await screen.findByTestId('item-row');
42
+ await waitFor(() => expect(within(row).getByText('~in 7d')).toHaveAttribute('data-guess', 'true'));
43
+ });
44
+
45
+ it('moves the to-do to the answered day at once, and the guess mark goes', async () => {
46
+ render(page(questions(async () => undefined)));
47
+ await screen.findByText('Is next Friday right?');
48
+ await userEvent.click(screen.getByRole('button', { name: /^Mon, Nov 9$/ }));
49
+ const row = await screen.findByTestId('item-row');
50
+ expect(within(row).getByText('in 3d')).toBeInTheDocument();
51
+ expect(row.querySelector('[data-guess]')).toBeNull();
52
+ });
53
+
54
+ it('puts the date back when the save fails', async () => {
55
+ render(page(questions(async () => { throw new Error('boom'); })));
56
+ await screen.findByText('Is next Friday right?');
57
+ await userEvent.click(screen.getByRole('button', { name: /^Mon, Nov 9$/ }));
58
+ expect(await screen.findByRole('alert')).toBeInTheDocument();
59
+ const row = screen.getByTestId('item-row');
60
+ expect(within(row).getByText('~in 7d')).toBeInTheDocument();
61
+ });
62
+
63
+ it('shows no section without a questions api', async () => {
64
+ render(<HomeBriefPage brief={{ fetch: async () => RESULT }} corpus={corpus()} now={NOW} timeZone="UTC" />);
65
+ await screen.findByTestId('item-row');
66
+ expect(screen.queryByTestId('needs-your-call')).toBeNull();
67
+ });
68
+ });
@@ -0,0 +1,151 @@
1
+ /**
2
+ * "NEEDS YOUR CALL" (bd startsim-tmrvi.7): the open clarifying questions on Home, answered with a tap.
3
+ */
4
+ import * as React from 'react';
5
+ import { render, screen, waitFor, within } from '@testing-library/react';
6
+ import userEvent from '@testing-library/user-event';
7
+ import { describe, expect, it, vi } from 'vitest';
8
+
9
+ import { NeedsYourCall } from '../components/pages/questions';
10
+ import type { NeedsYourCallApi } from '../components/pages/questions';
11
+ import type { OpenQuestion } from '../corpus/questions';
12
+
13
+ const NOW = Date.parse('2026-11-06T17:00:00Z');
14
+
15
+ function q(id: string, over: Partial<OpenQuestion> = {}): OpenQuestion {
16
+ return {
17
+ id, itemId: `item-${id}`, kind: 'due_date', question: 'When is this due?', status: 'open', candidates: [], score: 70,
18
+ ownerSub: 'u1', createdAt: '2026-11-06T10:00:00Z', updatedAt: '2026-11-06T10:00:00Z', ...over,
19
+ };
20
+ }
21
+
22
+ const DUE = q('a', {
23
+ question: 'Is Friday the right due date?', score: 80,
24
+ assumed: { value: '2026-11-13', confidence: 0.4, reason: 'You said "end of the week".' },
25
+ candidates: [{ value: '2026-11-12', confidence: 0.3, reason: 'Thursday' }, { value: '2026-11-16', confidence: 0.2, reason: 'Monday' }],
26
+ });
27
+ const PROJECT = q('b', {
28
+ kind: 'project', question: 'Which project is this for?', score: 60,
29
+ candidates: [{ value: 'f1', confidence: 0.5, reason: '' }, { value: 'f2', confidence: 0.3, reason: '' }],
30
+ });
31
+ const TITLES: Record<string, string> = { 'item-a': 'Send the term sheet', 'item-b': 'Book the venue' };
32
+
33
+ function api(over: Partial<NeedsYourCallApi> = {}, list: OpenQuestion[] = [PROJECT, DUE]): NeedsYourCallApi {
34
+ return { list: vi.fn(async () => list), answer: vi.fn(async () => undefined), skip: vi.fn(async () => undefined), ...over };
35
+ }
36
+ const ui = (a: NeedsYourCallApi, extra: Partial<React.ComponentProps<typeof NeedsYourCall>> = {}) => (
37
+ <NeedsYourCall api={a} now={NOW} timeZone="UTC" itemTitle={(id) => TITLES[id]} projectNames={{ f1: 'Launch v2', f2: 'Ops' }} {...extra} />
38
+ );
39
+
40
+ describe('NeedsYourCall', () => {
41
+ it('lists the questions best first, each with its to-do and chips', async () => {
42
+ render(ui(api()));
43
+ const rows = await screen.findAllByTestId('question-row');
44
+ expect(rows).toHaveLength(2);
45
+ expect(within(rows[0]).getByText('Send the term sheet')).toBeInTheDocument();
46
+ expect(within(rows[0]).getByText('Is Friday the right due date?')).toBeInTheDocument();
47
+ expect(within(rows[1]).getByText('Book the venue')).toBeInTheDocument();
48
+ expect(within(rows[1]).getByRole('button', { name: 'Launch v2' })).toBeInTheDocument();
49
+ expect(screen.getByRole('region', { name: /needs your call/i })).toBeInTheDocument();
50
+ });
51
+
52
+ it('shows the assumed value quietly, as a plain sentence and a one-tap keep', async () => {
53
+ render(ui(api()));
54
+ const row = (await screen.findAllByTestId('question-row'))[0];
55
+ expect(within(row).getByText(/going with Fri, Nov 13/)).toBeInTheDocument();
56
+ expect(within(row).getByRole('button', { name: 'Keep Fri, Nov 13' })).toBeInTheDocument();
57
+ expect(within(row).queryByRole('alert')).toBeNull();
58
+ });
59
+
60
+ it('answers on a tap: the row leaves at once and the answer is saved', async () => {
61
+ const a = api();
62
+ const onApplied = vi.fn();
63
+ render(ui(a, { onApplied }));
64
+ const row = (await screen.findAllByTestId('question-row'))[1];
65
+ await userEvent.click(within(row).getByRole('button', { name: 'Launch v2' }));
66
+ expect(screen.getAllByTestId('question-row')).toHaveLength(1);
67
+ expect(a.answer).toHaveBeenCalledWith(expect.objectContaining({ id: 'b' }), { value: 'f1', label: 'Launch v2' });
68
+ expect(onApplied).toHaveBeenCalledWith(expect.objectContaining({ id: 'b' }), { value: 'f1', label: 'Launch v2' });
69
+ await waitFor(() => expect(screen.getByRole('status')).toHaveTextContent('Saved.'));
70
+ });
71
+
72
+ it('puts the question back and undoes the change when the save fails', async () => {
73
+ const a = api({ answer: vi.fn(async () => { throw new Error('boom'); }) });
74
+ const onReverted = vi.fn();
75
+ render(ui(a, { onReverted }));
76
+ const row = (await screen.findAllByTestId('question-row'))[1];
77
+ await userEvent.click(within(row).getByRole('button', { name: 'Launch v2' }));
78
+ expect(await screen.findByRole('alert')).toHaveTextContent('did not save');
79
+ const rows = screen.getAllByTestId('question-row');
80
+ expect(rows).toHaveLength(2);
81
+ expect(within(rows[1]).getByText('Book the venue')).toBeInTheDocument();
82
+ expect(onReverted).toHaveBeenCalledWith(expect.objectContaining({ id: 'b' }));
83
+ });
84
+
85
+ it('skips on request, and restores the question if that fails', async () => {
86
+ const a = api();
87
+ render(ui(a));
88
+ await userEvent.click(within((await screen.findAllByTestId('question-row'))[0]).getByRole('button', { name: 'Skip it' }));
89
+ expect(a.skip).toHaveBeenCalledWith(expect.objectContaining({ id: 'a' }));
90
+ expect(screen.getAllByTestId('question-row')).toHaveLength(1);
91
+ });
92
+
93
+ it('brings a skipped question back when the skip does not save', async () => {
94
+ render(ui(api({ skip: vi.fn(async () => { throw new Error('no'); }) })));
95
+ const rows = await screen.findAllByTestId('question-row');
96
+ await userEvent.click(within(rows[1]).getByRole('button', { name: 'Skip it' }));
97
+ expect(await screen.findByRole('alert')).toHaveTextContent('did not save');
98
+ expect(screen.getAllByTestId('question-row')).toHaveLength(2);
99
+ });
100
+
101
+ it('reads a typed answer like a spoken one', async () => {
102
+ const a = api();
103
+ render(ui(a));
104
+ const row = (await screen.findAllByTestId('question-row'))[0];
105
+ await userEvent.click(within(row).getByRole('button', { name: 'Something else' }));
106
+ await userEvent.type(within(row).getByLabelText(/your answer for send the term sheet/i), 'tomorrow{enter}');
107
+ expect(a.answer).toHaveBeenCalledWith(expect.objectContaining({ id: 'a' }), { value: '2026-11-07' });
108
+ });
109
+
110
+ it('asks again, without saving, when the typed words mean nothing', async () => {
111
+ const a = api();
112
+ render(ui(a));
113
+ const row = (await screen.findAllByTestId('question-row'))[0];
114
+ await userEvent.click(within(row).getByRole('button', { name: 'Something else' }));
115
+ await userEvent.type(within(row).getByLabelText(/your answer/i), 'purple{enter}');
116
+ expect(a.answer).not.toHaveBeenCalled();
117
+ expect(within(row).getByRole('status')).toHaveTextContent(/day/i);
118
+ });
119
+
120
+ it('is calm when nothing is open', async () => {
121
+ render(ui(api({}, [])));
122
+ expect(await screen.findByText('Nothing needs your call.')).toBeInTheDocument();
123
+ expect(screen.queryByRole('alert')).toBeNull();
124
+ });
125
+
126
+ it('shows a page at a time', async () => {
127
+ const many = Array.from({ length: 7 }, (_, i) => q(`n${i}`, { score: 70 - i }));
128
+ render(ui(api({}, many), { pageSize: 3 }));
129
+ expect(await screen.findAllByTestId('question-row')).toHaveLength(3);
130
+ await userEvent.click(screen.getByRole('button', { name: 'Show 3 more' }));
131
+ expect(screen.getAllByTestId('question-row')).toHaveLength(6);
132
+ });
133
+
134
+ it('says so, and offers a retry, when the list cannot be read', async () => {
135
+ const list = vi.fn().mockRejectedValueOnce(new Error('down')).mockResolvedValue([DUE]);
136
+ render(ui(api({ list })));
137
+ await userEvent.click(await screen.findByRole('button', { name: 'Try again' }));
138
+ expect(await screen.findByText('Is Friday the right due date?')).toBeInTheDocument();
139
+ });
140
+
141
+ it('asks the host for choices a team or owner question can name', async () => {
142
+ const team = q('t', { kind: 'team', question: 'Which team is this for?', itemId: 'item-b' });
143
+ const options = vi.fn(async () => [{ value: 'tm1', label: 'Platform' }]);
144
+ const a = api({}, [team]);
145
+ render(ui(a, { options }));
146
+ await screen.findByText('Which team is this for?');
147
+ const row = screen.getByTestId('question-row');
148
+ await userEvent.click(await within(row).findByRole('button', { name: 'Platform' }));
149
+ expect(a.answer).toHaveBeenCalledWith(expect.objectContaining({ id: 't' }), { value: 'tm1', label: 'Platform' });
150
+ });
151
+ });
@@ -0,0 +1,51 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { applyAnswerToItem, assumedLabel, chipsFor, formatAnswerValue, readTypedAnswer } from '../corpus/questions';
4
+ import type { OpenQuestion } from '../corpus/questions';
5
+
6
+ const base: OpenQuestion = {
7
+ id: 'q', itemId: 'i1', kind: 'project', question: 'Which project?', status: 'open', candidates: [], score: 1, ownerSub: 'u', createdAt: '', updatedAt: '',
8
+ };
9
+
10
+ describe('question inbox helpers', () => {
11
+ it('puts the assumed value first, names ids, and never repeats a value', () => {
12
+ const q = { ...base, assumed: { value: 'f1', confidence: 0.4, reason: 'said so' }, candidates: [{ value: 'f1', confidence: 1, reason: '' }, { value: 'f2', confidence: 0.2, reason: '' }] };
13
+ const chips = chipsFor(q, { labels: { f1: 'Launch', f2: 'Ops' } });
14
+ expect(chips.map((c) => [c.label, c.assumed])).toEqual([['Launch', true], ['Ops', false]]);
15
+ expect(assumedLabel(q, { labels: { f1: 'Launch' } })).toBe('Launch');
16
+ });
17
+
18
+ it('caps the chips', () => {
19
+ const q = { ...base, candidates: ['a', 'b', 'c', 'd', 'e'].map((value) => ({ value, confidence: 0.1, reason: '' })) };
20
+ expect(chipsFor(q)).toHaveLength(4);
21
+ });
22
+
23
+ it('formats a date and an empty date', () => {
24
+ expect(formatAnswerValue({ kind: 'due_date' }, '2026-11-13')).toMatch(/Nov/);
25
+ expect(formatAnswerValue({ kind: 'due_date' }, '')).toBe('No date');
26
+ });
27
+
28
+ it('turns typed words into an answer, a skip, or a question back', () => {
29
+ const due = { ...base, kind: 'due_date' as const };
30
+ const ctx = { now: Date.parse('2026-11-06T17:00:00Z'), timeZone: 'UTC' };
31
+ expect(readTypedAnswer(due, 'tomorrow', ctx)).toEqual({ kind: 'answer', answer: { value: '2026-11-07' } });
32
+ expect(readTypedAnswer(due, 'skip', ctx)).toEqual({ kind: 'skip' });
33
+ expect(readTypedAnswer(due, 'purple', ctx).kind).toBe('unclear');
34
+ expect(readTypedAnswer({ ...base, assumed: { value: 'f1', confidence: 0.5, reason: '' } }, 'yes', ctx)).toEqual({ kind: 'answer', answer: { value: 'f1' } });
35
+ });
36
+
37
+ it('applies an answer only to its own to-do', () => {
38
+ const items = [{ id: 'i1', dueAt: '2026-11-13' }, { id: 'i2', dueAt: '2026-11-13' }];
39
+ const out = items.map((i) => applyAnswerToItem(i, { kind: 'due_date', itemId: 'i1' }, { value: '' }));
40
+ expect(out).toEqual([{ id: 'i1', dueAt: null }, { id: 'i2', dueAt: '2026-11-13' }]);
41
+ expect(applyAnswerToItem({ id: 'i1', focusId: 'a' }, { kind: 'project', itemId: 'i1' }, { value: 'b' }).focusId).toBe('b');
42
+ });
43
+ });
44
+
45
+ describe('server-supplied options', () => {
46
+ it('names chips from the options a listing carries, and offers them when there are no candidates', () => {
47
+ const q: OpenQuestion = { ...base, kind: 'team', options: [{ value: 't1', label: 'Platform' }, { value: 't2', label: 'Growth' }] };
48
+ expect(chipsFor(q).map((c) => c.label)).toEqual(['Platform', 'Growth']);
49
+ expect(formatAnswerValue(q, 't2')).toBe('Growth');
50
+ });
51
+ });
@@ -72,4 +72,5 @@ export * from './pages/VoiceNotesPage';
72
72
  export { VoiceRecordButton, VOICE_MIME_CANDIDATES } from './pages/VoiceRecordButton';
73
73
  export type { VoiceRecordButtonProps, VoiceRecordClassNames } from './pages/VoiceRecordButton';
74
74
  export * from './pages/home';
75
+ export * from './pages/questions';
75
76
  export * from './pages/task-tracker/OwnerPicker';
@@ -31,6 +31,7 @@
31
31
  */
32
32
  import * as React from 'react';
33
33
 
34
+ import { itemIdOf } from '../../corpus/ask-items';
34
35
  import { Markdown, stripMarkdown } from '../Markdown';
35
36
  import {
36
37
  UNCITED_NOTICE, askFailureMessage as failureMessage, droppedNotice, freshnessNotice,
@@ -50,6 +51,8 @@ export interface AskPageProps {
50
51
  scope: CorpusScope;
51
52
  /** Click-through from a citation to the record, normally the Library route. */
52
53
  onOpenDocument?: (documentId: string) => void;
54
+ /** Click-through from a cited TRACKED ITEM (an `item:` record) to the item, by its external id. */
55
+ onOpenItem?: (itemId: string) => void;
53
56
  /** Prefill, e.g. from a `?q=` param. */
54
57
  initialQuestion?: string;
55
58
  initialMode?: AskMode;
@@ -102,6 +105,7 @@ export function AskPage({
102
105
  api,
103
106
  scope,
104
107
  onOpenDocument,
108
+ onOpenItem,
105
109
  initialQuestion = '',
106
110
  initialMode = 'ask',
107
111
  listProjects,
@@ -230,6 +234,7 @@ export function AskPage({
230
234
  result={result}
231
235
  classNames={cn}
232
236
  onOpenDocument={onOpenDocument}
237
+ onOpenItem={onOpenItem}
233
238
  canSave={canSave}
234
239
  saveState={saveState}
235
240
  onSave={async () => {
@@ -257,11 +262,12 @@ export function AskPage({
257
262
  // ---------------------------------------------------------------------------
258
263
 
259
264
  function AnswerPanel({
260
- result, classNames: cn, onOpenDocument, canSave, saveState, onSave,
265
+ result, classNames: cn, onOpenDocument, onOpenItem, canSave, saveState, onSave,
261
266
  }: {
262
267
  result: AskResult;
263
268
  classNames: Record<AskSlot, string>;
264
269
  onOpenDocument?: (documentId: string) => void;
270
+ onOpenItem?: (itemId: string) => void;
265
271
  canSave: boolean;
266
272
  saveState: 'idle' | 'saving' | 'saved';
267
273
  onSave: () => void;
@@ -327,7 +333,11 @@ function AnswerPanel({
327
333
  <button
328
334
  type="button"
329
335
  className="text-sm font-medium text-blue-700 underline"
330
- onClick={() => onOpenDocument?.(citation.documentId)}
336
+ onClick={() => {
337
+ const itemId = itemIdOf(citation.documentId);
338
+ if (itemId) onOpenItem?.(itemId);
339
+ else onOpenDocument?.(citation.documentId);
340
+ }}
331
341
  >
332
342
  {citation.document.title}
333
343
  </button>