@startsimpli/integrations 0.2.183 → 0.2.185
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__/converse-activity.test.ts +89 -0
- package/src/__tests__/converse-brain.test.ts +155 -2
- package/src/__tests__/converse-meeting-brief.test.ts +122 -0
- package/src/__tests__/converse-spoken-summary.test.ts +30 -0
- package/src/__tests__/converse.test.ts +51 -0
- package/src/__tests__/corpus-ask.test.ts +23 -0
- package/src/corpus/ask-items-intent.ts +27 -16
- package/src/corpus/ask.ts +22 -22
- package/src/corpus/converse/activity.ts +100 -0
- package/src/corpus/converse/brain.ts +80 -6
- package/src/corpus/converse/briefing-queue.ts +169 -0
- package/src/corpus/converse/extract.ts +2 -1
- package/src/corpus/converse/handle.ts +13 -6
- package/src/corpus/converse/index.ts +2 -0
- package/src/corpus/converse/route.ts +1 -1
- package/src/corpus/converse/speak.ts +5 -4
- package/src/corpus/converse/spoken-summary.ts +43 -0
- package/src/corpus/converse/store.ts +2 -0
- package/src/corpus/converse/transcript.ts +9 -0
- package/src/corpus/converse/types.ts +12 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.185",
|
|
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",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"@startsimpli/ui-native": ">=0.1.12",
|
|
52
52
|
"react-native-safe-area-context": ">=4.0.0",
|
|
53
53
|
"@startsimpli/ui": "^0.4.186",
|
|
54
|
-
"@startsimpli/
|
|
55
|
-
"@startsimpli/
|
|
54
|
+
"@startsimpli/utils": "^0.4.20",
|
|
55
|
+
"@startsimpli/auth": "^0.4.53"
|
|
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/
|
|
101
|
+
"@startsimpli/llm": "0.4.31",
|
|
102
102
|
"@startsimpli/ui": "0.4.186",
|
|
103
|
+
"@startsimpli/ui-native": "0.1.15",
|
|
103
104
|
"@startsimpli/auth": "0.4.53",
|
|
104
|
-
"@startsimpli/utils": "0.4.20"
|
|
105
|
-
"@startsimpli/llm": "0.4.31"
|
|
105
|
+
"@startsimpli/utils": "0.4.20"
|
|
106
106
|
},
|
|
107
107
|
"scripts": {
|
|
108
108
|
"type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
/**
|
|
3
|
+
* "What did I do yesterday / this week": answered from WHEN things happened (to-dos finished or added, conversations,
|
|
4
|
+
* voice notes, meetings in that window), not by matching words. Read only.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { ACTIVITY_QUESTION, activityOf, composeActivity, loadActivity } from '../corpus/converse/activity';
|
|
9
|
+
import { questionWindow } from '../corpus/ask-items-intent';
|
|
10
|
+
import type { Commitment, SourceDocument } from '../corpus/types';
|
|
11
|
+
|
|
12
|
+
const NOW = Date.parse('2026-11-16T17:00:00Z'); // Monday 10:00 in Denver
|
|
13
|
+
const TZ = 'America/Denver';
|
|
14
|
+
|
|
15
|
+
describe('the question', () => {
|
|
16
|
+
it.each([
|
|
17
|
+
'What did I do yesterday?', 'what have I done this week', 'what did I get done today', 'What did I finish last week?',
|
|
18
|
+
'what did I work on yesterday', 'what happened yesterday', 'what did I accomplish this month', 'catch me up on yesterday', 'what have I been up to lately',
|
|
19
|
+
])('%s is an activity question', (q) => expect(ACTIVITY_QUESTION.test(q)).toBe(true));
|
|
20
|
+
it.each(['what is due this week', 'what did the relay do yesterday', 'add a to-do for yesterday', 'what is on my plate', 'what did I do', 'what did I do about the bench yesterday', 'what did I do with the roll this week'])('%s is not', (q) => {
|
|
21
|
+
expect(ACTIVITY_QUESTION.test(q)).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('the window', () => {
|
|
26
|
+
it('works out yesterday, last week and this month in his zone', () => {
|
|
27
|
+
expect(questionWindow('what did I do yesterday', NOW, TZ)).toMatchObject({ from: '2026-11-15', to: '2026-11-15', label: 'yesterday' });
|
|
28
|
+
expect(questionWindow('what did I do last week', NOW, TZ)).toMatchObject({ from: '2026-11-09', to: '2026-11-15' });
|
|
29
|
+
expect(questionWindow('what did I do this month', NOW, TZ)).toMatchObject({ from: '2026-11-01', to: '2026-11-16' });
|
|
30
|
+
expect(questionWindow('what did I do last month', NOW, TZ)).toMatchObject({ from: '2026-10-01', to: '2026-10-31' });
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const todo = (id: string, title: string, over: Partial<Commitment> = {}): Commitment => ({ id, externalId: id, title, status: 'open', firstSeenAt: '2026-10-01T10:00:00Z', lastSeenAt: '2026-10-01T10:00:00Z', ...over } as Commitment);
|
|
35
|
+
const doc = (id: string, title: string, source: string, occurredAt: string): SourceDocument => ({ id, title, source, sourceLabel: source, occurredAt, body: '', sections: [], participants: [] } as unknown as SourceDocument);
|
|
36
|
+
|
|
37
|
+
describe('what happened in the window', () => {
|
|
38
|
+
const window = { from: '2026-11-15', to: '2026-11-15', label: 'yesterday' };
|
|
39
|
+
const items = [
|
|
40
|
+
todo('a', 'Ship the roll', { status: 'done', resolvedAt: '2026-11-15T20:00:00Z' }),
|
|
41
|
+
todo('b', 'Call the bank', { status: 'done', resolvedAt: '2026-11-15T15:00:00Z' }),
|
|
42
|
+
todo('c', 'Old finished', { status: 'done', resolvedAt: '2026-11-10T15:00:00Z' }),
|
|
43
|
+
todo('d', 'Brand new', { firstSeenAt: '2026-11-15T12:00:00Z' }),
|
|
44
|
+
todo('e', 'Still open, old', {}),
|
|
45
|
+
todo('f', 'Dropped yesterday', { status: 'dropped', resolvedAt: '2026-11-15T18:00:00Z' }),
|
|
46
|
+
];
|
|
47
|
+
const docs = [doc('x', 'Conversation 2026-11-15: You there?', 'conversation', '2026-11-15T16:58:00Z'), doc('y', 'Relay and API Connector Updates', 'voice', '2026-11-15T18:47:00Z'), doc('z', 'Last week standup', 'meeting', '2026-11-09T18:00:00Z')];
|
|
48
|
+
|
|
49
|
+
it('picks the to-dos finished and added and the notes from that day only', () => {
|
|
50
|
+
const got = activityOf({ items, docs, window, timeZone: TZ });
|
|
51
|
+
expect(got.finished.map((i) => i.title)).toEqual(['Ship the roll', 'Call the bank']);
|
|
52
|
+
expect(got.added.map((i) => i.title)).toEqual(['Brand new']);
|
|
53
|
+
expect(got.notes.map((n) => n.title)).toEqual(['Conversation 2026-11-15: You there?', 'Relay and API Connector Updates']);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('a finished to-do with no resolved time is dated by when it was last touched', () => {
|
|
57
|
+
const got = activityOf({ items: [todo('g', 'No resolved time', { status: 'done', resolvedAt: null, lastSeenAt: '2026-11-15T19:00:00Z' })], docs: [], window, timeZone: TZ });
|
|
58
|
+
expect(got.finished.map((i) => i.title)).toEqual(['No resolved time']);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('says it short, in meeting style: what was finished, added, and the notes, with titles and a count', () => {
|
|
62
|
+
const said = composeActivity(window, activityOf({ items, docs, window, timeZone: TZ }));
|
|
63
|
+
expect(said).toBe('Yesterday you finished 2 things: Ship the roll and Call the bank. You added 1 new to-do: Brand new. You also have 1 conversation and 1 voice note from then.');
|
|
64
|
+
expect(said.split(/\s+/).length).toBeLessThanOrEqual(60);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('three titles then "and N more"', () => {
|
|
68
|
+
const many = Array.from({ length: 6 }, (_, i) => todo(`m${i}`, `Thing ${i + 1}`, { status: 'done', resolvedAt: '2026-11-15T15:00:00Z' }));
|
|
69
|
+
expect(composeActivity(window, activityOf({ items: many, docs: [], window, timeZone: TZ }))).toBe('Yesterday you finished 6 things: Thing 1, Thing 2, Thing 3, and 3 more.');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('nothing in the window says so plainly', () => {
|
|
73
|
+
expect(composeActivity(window, activityOf({ items: [], docs: [], window, timeZone: TZ }))).toBe('I found nothing from yesterday: no finished or new to-dos, and no conversations or notes.');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('reading it', () => {
|
|
78
|
+
it('asks the tenant for to-dos changed since the window start and notes inside the window, nothing else', async () => {
|
|
79
|
+
const listCommitments = vi.fn(async () => ({ results: [todo('a', 'Ship', { status: 'done', resolvedAt: '2026-11-15T20:00:00Z' })], next: null }));
|
|
80
|
+
const listDocuments = vi.fn(async () => ({ results: [doc('x', 'A note', 'voice', '2026-11-15T18:00:00Z')], next: null }));
|
|
81
|
+
const out = await loadActivity({ planning: { listCommitments } as never, corpus: { listDocuments } as never }, { from: '2026-11-15', to: '2026-11-15', label: 'yesterday' }, TZ);
|
|
82
|
+
expect(out.finished.map((i) => i.title)).toEqual(['Ship']);
|
|
83
|
+
expect((listCommitments.mock.calls[0] as any)[0]).toMatchObject({ sort: 'updated', status: 'done' });
|
|
84
|
+
expect((listCommitments.mock.calls[1] as any)[0]).toMatchObject({ sort: 'updated' });
|
|
85
|
+
expect((listCommitments.mock.calls[0] as any)[0].changedAfter).toBeUndefined();
|
|
86
|
+
expect(String((listCommitments.mock.calls[1] as any)[0].changedAfter)).toMatch(/^2026-11-1[45]/);
|
|
87
|
+
expect((listDocuments.mock.calls[0] as any)[0]).toMatchObject({ occurredAfter: expect.any(String), occurredBefore: expect.any(String) });
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -51,7 +51,7 @@ describe('a conversational turn never says "unanswerable"', () => {
|
|
|
51
51
|
return createConverseBrain({ ...(s.deps as any), ask: async () => ({ answer, status }) });
|
|
52
52
|
};
|
|
53
53
|
it.each([['unanswerable'], ['Unanswerable.'], [' '], ['']])('says what it cannot see instead of %j', async (answer) => {
|
|
54
|
-
const out = await brainWith(answer, 'no_evidence')({ utterance: 'What is
|
|
54
|
+
const out = await brainWith(answer, 'no_evidence')({ utterance: 'What is due this week?', history: [], timeZone: TZ, now: NOW });
|
|
55
55
|
expect(out.text.toLowerCase()).not.toContain('unanswerable');
|
|
56
56
|
expect(out.text).toMatch(/could not find|don't see|do not see/i);
|
|
57
57
|
});
|
|
@@ -100,6 +100,142 @@ describe('converse brain', () => {
|
|
|
100
100
|
});
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
+
describe('long answers: whole on the screen, short aloud; Ask starts beside routing', () => {
|
|
104
|
+
const input = (utterance: string) => ({ utterance, history: [], timeZone: TZ, now: NOW });
|
|
105
|
+
const LIST = 'This week, the following tasks are due: 1. Plan the week. 2. Build lead QC. 3. Launch lead. 4. Order the bench. 5. Call the bank.';
|
|
106
|
+
|
|
107
|
+
it('a list answer: the screen text is whole, the spoken version is three items and "and 2 more"', async () => {
|
|
108
|
+
const s = setup();
|
|
109
|
+
const brain = createConverseBrain({ ...s.deps, ask: async () => ({ answer: LIST }) });
|
|
110
|
+
const out = await brain(input('what is due this week'));
|
|
111
|
+
expect(out.text).toContain('5. Call the bank');
|
|
112
|
+
expect(out.spoken).toBe('This week, the following tasks are due. Plan the week. Build lead QC. Launch lead. And 2 more.');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('a short answer has no separate spoken version', async () => {
|
|
116
|
+
const s = setup();
|
|
117
|
+
const out = await createConverseBrain(s.deps)(input('what is due today'));
|
|
118
|
+
expect(out.spoken).toBeUndefined();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('Ask is already running while the routing model is still thinking', async () => {
|
|
122
|
+
const s = setup();
|
|
123
|
+
let askedWhileRouting = false;
|
|
124
|
+
let routing = false;
|
|
125
|
+
const routeLlm = { write: vi.fn(async () => { routing = true; await new Promise((r) => setTimeout(r, 40)); routing = false; return '{"route":"other"}'; }) };
|
|
126
|
+
const ask = vi.fn(async () => { askedWhileRouting = routing; return { answer: 'The bench.' }; });
|
|
127
|
+
const out = await createConverseBrain({ ...s.deps, routeLlm: routeLlm as never, ask })(input('what is due this week'));
|
|
128
|
+
expect(askedWhileRouting).toBe(true);
|
|
129
|
+
expect(ask).toHaveBeenCalledTimes(1);
|
|
130
|
+
expect(out.text).toContain('bench');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('when the routing model says it is for the relay, the early Ask answer is dropped', async () => {
|
|
134
|
+
const s = setup();
|
|
135
|
+
const ask = vi.fn(async () => ({ answer: 'should not be said' }));
|
|
136
|
+
const out = await createConverseBrain({ ...s.deps, routeLlm: { write: vi.fn(async () => '{"route":"work"}') } as never, ask })(input('what should we ship first'));
|
|
137
|
+
expect(out.forRelay).toBe(true);
|
|
138
|
+
expect(out.text).not.toContain('should not be said');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('a question about the agents does not start Ask at all', async () => {
|
|
142
|
+
const s = setup();
|
|
143
|
+
const ask = vi.fn(async () => ({ answer: 'x' }));
|
|
144
|
+
await createConverseBrain({ ...s.deps, routeLlm: { write: vi.fn(async () => '{"route":"status"}') } as never, ask, loadFleetStatus: async () => ({ text: 'fleet', updatedAt: new Date(NOW).toISOString() }), answerFrom: async () => 'fine' })(input('what are the agents doing'));
|
|
145
|
+
expect(ask).not.toHaveBeenCalled();
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe('conversation answers are short unless he asks for all of it', () => {
|
|
150
|
+
const ask = async (said: string) => {
|
|
151
|
+
const s = setup();
|
|
152
|
+
await createConverseBrain(s.deps)({ utterance: said, history: [], timeZone: TZ, now: NOW });
|
|
153
|
+
return String(s.ask.mock.calls[0][0].question);
|
|
154
|
+
};
|
|
155
|
+
it('asks Ask for at most 60 words, the top three of a list and a count', async () => {
|
|
156
|
+
expect(await ask('what is due this week')).toMatch(/at most 60 words[\s\S]*three most important items/);
|
|
157
|
+
});
|
|
158
|
+
it.each(['tell me more about the bench', 'list them all', 'give me the full list of what is due', 'what is due this week, in detail'])('"%s" gets the whole answer', async (said) => {
|
|
159
|
+
expect(await ask(said)).not.toMatch(/at most 60 words/);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('what did I do yesterday', () => {
|
|
164
|
+
it('is answered from the window read, not by Ask, and nothing is written', async () => {
|
|
165
|
+
const s = setup();
|
|
166
|
+
const loadActivity = vi.fn(async () => ({ finished: [{ id: 'a', title: 'Ship the roll', at: '2026-11-03T20:00:00Z' }], added: [], notes: [] }));
|
|
167
|
+
const brain = createConverseBrain({ ...s.deps, loadActivity });
|
|
168
|
+
const out = await brain({ utterance: 'What did I do yesterday?', history: [], timeZone: TZ, now: NOW });
|
|
169
|
+
expect(out.text).toBe('Yesterday you finished 1 thing: Ship the roll.');
|
|
170
|
+
expect(loadActivity).toHaveBeenCalledWith(expect.objectContaining({ from: '2026-11-03', to: '2026-11-03', label: 'yesterday' }), TZ);
|
|
171
|
+
expect(s.ask).not.toHaveBeenCalled();
|
|
172
|
+
expect(out.did).toBeUndefined();
|
|
173
|
+
});
|
|
174
|
+
it('without a window reader it falls back to Ask as before', async () => {
|
|
175
|
+
const s = setup();
|
|
176
|
+
await createConverseBrain(s.deps)({ utterance: 'What did I do yesterday?', history: [], timeZone: TZ, now: NOW });
|
|
177
|
+
expect(s.ask).toHaveBeenCalledTimes(1);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe('briefing one item at a time', () => {
|
|
182
|
+
const say = (utterance: string, briefing: any = null) => ({ utterance, history: [], timeZone: TZ, now: NOW, briefing });
|
|
183
|
+
|
|
184
|
+
it('"what is on my plate" starts the walk: one item and its question, not a paragraph, and the state to keep', async () => {
|
|
185
|
+
const s = setup();
|
|
186
|
+
const brain = createConverseBrain({ ...s.deps, loadItems: async () => [{ id: 'bench', title: "Order dad's bench", status: 'open', dueAt: '2026-11-04', ownerSub: ME, focusName: 'Home' }] as never });
|
|
187
|
+
const out = await brain(say('what is on my plate today'));
|
|
188
|
+
expect(out.text).toBe("Home, item 1: Order dad's bench, due today. Do it today?");
|
|
189
|
+
expect(out.briefing?.queue).toHaveLength(1);
|
|
190
|
+
expect(s.ask).not.toHaveBeenCalled();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('nothing due and nothing waiting: says so in one sentence', async () => {
|
|
194
|
+
const s = setup();
|
|
195
|
+
const brain = createConverseBrain({ ...s.deps, loadItems: async () => [] as never });
|
|
196
|
+
expect((await brain(say('what needs me'))).text).toBe('Nothing needs you right now.');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('an answer edits the item through the normal seam and says Noted.; the last item ends the briefing', async () => {
|
|
200
|
+
const s = setup();
|
|
201
|
+
const brain = createConverseBrain({ ...s.deps, loadItems: async () => [{ id: 'bench', title: "Order dad's bench", status: 'open', dueAt: '2026-11-04', ownerSub: ME, focusName: 'Home' }] as never });
|
|
202
|
+
const started = await brain(say('brief me'));
|
|
203
|
+
const out = await brain(say('done', started.briefing));
|
|
204
|
+
expect(out.text).toBe('Noted. That is everything.');
|
|
205
|
+
expect(out.briefing).toBeNull();
|
|
206
|
+
expect(s.rows.get('item:bench')?.data.status).not.toBe('open');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('an answer about something the relay waits on goes to the relay with the item named', async () => {
|
|
210
|
+
const s = setup();
|
|
211
|
+
const brain = createConverseBrain({ ...s.deps, loadItems: async () => [] as never, loadFleetStatus: async () => ({ text: '## Waiting on Quinn\n- Crochets: flip the 8 category pages Tuesday morning?', updatedAt: new Date(NOW).toISOString() }) });
|
|
212
|
+
const started = await brain(say('what do you need from me'));
|
|
213
|
+
expect(started.text).toBe('Crochets, item 1: Flip the 8 category pages Tuesday morning. Yes or no?');
|
|
214
|
+
const out = await brain(say('yes', started.briefing));
|
|
215
|
+
expect(out).toMatchObject({ text: 'Noted. That is everything.', forRelay: true, relayText: 'Answer on "Flip the 8 category pages Tuesday morning" (Crochets): yes' });
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('a question about the agents with something waiting on him is walked the same way', async () => {
|
|
219
|
+
const s = setup();
|
|
220
|
+
const brain = createConverseBrain({
|
|
221
|
+
...s.deps, routeLlm: { write: vi.fn(async () => '{"route":"status"}') } as never,
|
|
222
|
+
loadFleetStatus: async () => ({ text: '## Waiting on Quinn\n- Videos: pick an owner for episode 4', updatedAt: new Date(NOW).toISOString() }),
|
|
223
|
+
});
|
|
224
|
+
const out = await brain(say('what are the agents working on'));
|
|
225
|
+
expect(out.text).toBe('Videos, item 1: Pick an owner for episode 4. Yes or no?');
|
|
226
|
+
expect(out.briefing).toBeTruthy();
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('something that is not an answer goes to the normal assistant and the briefing stays open', async () => {
|
|
230
|
+
const s = setup();
|
|
231
|
+
const brain = createConverseBrain({ ...s.deps, loadItems: async () => [{ id: 'bench', title: "Order dad's bench", status: 'open', dueAt: '2026-11-04', ownerSub: ME, focusName: 'Home' }] as never });
|
|
232
|
+
const started = await brain(say('brief me'));
|
|
233
|
+
const out = await brain(say('what is the weather like', started.briefing));
|
|
234
|
+
expect(s.ask).toHaveBeenCalledTimes(1);
|
|
235
|
+
expect(out.briefing).toBeUndefined();
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
103
239
|
describe('a question never edits an item', () => {
|
|
104
240
|
it('"what did I do about the bench" is answered, not read as "I did the bench" (it once marked a real item done)', async () => {
|
|
105
241
|
const s = setup();
|
|
@@ -111,6 +247,23 @@ describe('a question never edits an item', () => {
|
|
|
111
247
|
});
|
|
112
248
|
});
|
|
113
249
|
|
|
250
|
+
describe('a status route needs fleet words', () => {
|
|
251
|
+
it('"What is due this week?" goes to Ask even when the routing model says status', async () => {
|
|
252
|
+
const s = setup();
|
|
253
|
+
const brain = createConverseBrain({ ...s.deps, routeLlm: { write: vi.fn(async () => '{"route":"status"}') } as never, loadFleetStatus: async () => ({ text: 'fleet text', updatedAt: new Date(NOW).toISOString() }), answerFrom: async () => 'from the fleet' });
|
|
254
|
+
const out = await brain({ utterance: 'What is due this week?', history: [], timeZone: TZ, now: NOW });
|
|
255
|
+
expect(out.text).not.toContain('fleet');
|
|
256
|
+
expect(s.ask).toHaveBeenCalledTimes(1);
|
|
257
|
+
});
|
|
258
|
+
it('a question about the agents still gets the fleet status', async () => {
|
|
259
|
+
const s = setup();
|
|
260
|
+
const brain = createConverseBrain({ ...s.deps, routeLlm: { write: vi.fn(async () => '{"route":"status"}') } as never, loadFleetStatus: async () => ({ text: 'fleet text', updatedAt: new Date(NOW).toISOString() }), answerFrom: async () => 'all agents are fine' });
|
|
261
|
+
const out = await brain({ utterance: 'What are the agents working on?', history: [], timeZone: TZ, now: NOW });
|
|
262
|
+
expect(out.text).toContain('all agents are fine');
|
|
263
|
+
expect(s.ask).not.toHaveBeenCalled();
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
114
267
|
describe('fast paths', () => {
|
|
115
268
|
const llmSaying = (route: string) => ({ write: vi.fn(async () => `{"route": "${route}"}`) });
|
|
116
269
|
const input = (utterance: string) => ({ utterance, history: [], timeZone: TZ, now: NOW });
|
|
@@ -203,7 +356,7 @@ describe('routing: work for the relay, fleet status, no filler', () => {
|
|
|
203
356
|
const s = setup();
|
|
204
357
|
const broken = { write: vi.fn(async () => { throw new Error('down'); }) };
|
|
205
358
|
const brain = createConverseBrain({ ...s.deps, routeLlm: broken });
|
|
206
|
-
await brain(input('what is
|
|
359
|
+
await brain(input('what is coming up this week'));
|
|
207
360
|
expect(s.ask.mock.calls[0][0].question).toMatch(/Do not ask whether to continue/);
|
|
208
361
|
});
|
|
209
362
|
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
/**
|
|
3
|
+
* The assistant briefs like a person in a meeting (Quinn): BY PROJECT, ONE ITEM AT A TIME. One sentence for the item plus
|
|
4
|
+
* the question, hold the rest until answered, "Noted." after each answer, details only on "tell me more".
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { buildQueue, firstPrompt, relayItemsFrom, stepBriefing, BRIEF_ME, NEEDS_ME } from '../corpus/converse/briefing-queue';
|
|
9
|
+
import type { BriefingItem } from '../corpus/briefing/types';
|
|
10
|
+
|
|
11
|
+
const NOW = Date.parse('2026-11-16T17:00:00Z');
|
|
12
|
+
const TZ = 'America/Denver';
|
|
13
|
+
const item = (id: string, title: string, focusName: string, dueAt: string, over: Partial<BriefingItem> = {}): BriefingItem => ({ id, title, status: 'open', dueAt, focusName, ownerSub: 'me', ...over });
|
|
14
|
+
|
|
15
|
+
const ITEMS = [
|
|
16
|
+
item('a', 'Flip the 8 category pages on Tuesday morning', 'Crochets', '2026-11-16'),
|
|
17
|
+
item('b', 'Review the checkout copy', 'Crochets', '2026-11-14'),
|
|
18
|
+
item('c', 'Ship the combined roll', 'Tandem', '2026-11-16'),
|
|
19
|
+
item('d', 'Plan next month', 'Tandem', '2026-12-30'),
|
|
20
|
+
item('e', 'Done already', 'Tandem', '2026-11-16', { status: 'done' }),
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
describe('the trigger', () => {
|
|
24
|
+
it.each(['what is on my plate', "What's on my plate today?", 'brief me', 'what needs me', 'give me a rundown', 'what do I have today', 'catch me up'])('%s starts a briefing', (said) => {
|
|
25
|
+
expect(BRIEF_ME.test(said)).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
it.each(['add a to-do for the relay', 'what did I do yesterday', 'hello', 'move the bench to Friday'])('%s does not', (said) => {
|
|
28
|
+
expect(BRIEF_ME.test(said)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('the queue', () => {
|
|
33
|
+
it('is ordered by project, overdue and due-today items only, done items left out', () => {
|
|
34
|
+
const q = buildQueue({ items: ITEMS, relayItems: [], now: NOW, timeZone: TZ });
|
|
35
|
+
expect(q.map((i) => `${i.project}:${i.itemId}`)).toEqual(['Crochets:b', 'Crochets:a', 'Tandem:c']);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('puts what the relay waits on Quinn for after his own items, under its project', () => {
|
|
39
|
+
const relayItems = relayItemsFrom('## Waiting on Quinn\n- Crochets: flip the 8 category pages Tuesday morning?\n- Videos: pick an owner for episode 4\n## Other\n- not this one');
|
|
40
|
+
expect(relayItems.map((i) => [i.project, i.text])).toEqual([['Crochets', 'Flip the 8 category pages Tuesday morning'], ['Videos', 'Pick an owner for episode 4']]);
|
|
41
|
+
const q = buildQueue({ items: [], relayItems, now: NOW, timeZone: TZ });
|
|
42
|
+
expect(q).toHaveLength(2);
|
|
43
|
+
expect(q[0].question).toBe('Yes or no?');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('what needs me puts the relay questions first', () => {
|
|
48
|
+
it('relay questions lead, his own due items follow, still grouped by project', () => {
|
|
49
|
+
const relayItems = relayItemsFrom('## Waiting on Quinn\n- Tandem: ship the roll today?');
|
|
50
|
+
const q = buildQueue({ items: ITEMS, relayItems, now: NOW, timeZone: TZ, relayFirst: true });
|
|
51
|
+
expect(q.map((i) => `${i.project}:${i.kind}`)).toEqual(['Tandem:relay', 'Tandem:todo', 'Crochets:todo', 'Crochets:todo']);
|
|
52
|
+
expect(NEEDS_ME.test('what do you need from me')).toBe(true);
|
|
53
|
+
expect(NEEDS_ME.test('what is on my plate')).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('one item at a time', () => {
|
|
58
|
+
const start = () => {
|
|
59
|
+
const queue = buildQueue({ items: ITEMS, relayItems: [], now: NOW, timeZone: TZ });
|
|
60
|
+
return { queue, index: 0 };
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
it('says one sentence and one question, nothing else', () => {
|
|
64
|
+
const s = start();
|
|
65
|
+
const said = firstPrompt(s);
|
|
66
|
+
expect(said).toBe('Crochets, item 1: Review the checkout copy, overdue. Do it today?');
|
|
67
|
+
expect(said.split(/[.?]\s/).length).toBeLessThanOrEqual(3);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('after an answer says Noted., then the next item; on a new project says that is the project first', () => {
|
|
71
|
+
let s = start();
|
|
72
|
+
let r = stepBriefing(s, 'yes');
|
|
73
|
+
expect(r.reply).toBe('Noted. Crochets, item 2: Flip the 8 category pages on Tuesday morning, due today. Do it today?');
|
|
74
|
+
expect(r.effect).toEqual({ kind: 'todo', action: { type: 'pull_today', itemId: 'b' } });
|
|
75
|
+
s = r.state!;
|
|
76
|
+
r = stepBriefing(s, 'later');
|
|
77
|
+
expect(r.reply).toBe('Noted. That is Crochets. Now Tandem, item 1: Ship the combined roll, due today. Do it today?');
|
|
78
|
+
expect(r.effect).toEqual({ kind: 'todo', action: { type: 'defer', itemId: 'a', to: 'later' } });
|
|
79
|
+
s = r.state!;
|
|
80
|
+
r = stepBriefing(s, 'done');
|
|
81
|
+
expect(r.reply).toBe('Noted. That is everything.');
|
|
82
|
+
expect(r.state).toBeNull();
|
|
83
|
+
expect(r.effect).toEqual({ kind: 'todo', action: { type: 'done', itemId: 'c' } });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('holds the rest until answered: "tell me more" gives the detail and asks the same question again', () => {
|
|
87
|
+
const s = start();
|
|
88
|
+
const r = stepBriefing(s, 'tell me more');
|
|
89
|
+
expect(r.reply).toMatch(/^Review the checkout copy/);
|
|
90
|
+
expect(r.reply).toMatch(/Do it today\?$/);
|
|
91
|
+
expect(r.state?.index).toBe(0);
|
|
92
|
+
expect(r.effect).toBeUndefined();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('skip moves on without a change; stop ends the briefing; repeat says the item again', () => {
|
|
96
|
+
const s = start();
|
|
97
|
+
expect(stepBriefing(s, 'skip').reply).toMatch(/^Noted\. Crochets, item 2:/);
|
|
98
|
+
expect(stepBriefing(s, 'skip').effect).toBeUndefined();
|
|
99
|
+
const stop = stepBriefing(s, "that's all");
|
|
100
|
+
expect(stop.reply).toBe('Okay, stopping.');
|
|
101
|
+
expect(stop.state).toBeNull();
|
|
102
|
+
expect(stepBriefing(s, 'say that again').reply).toBe(firstPrompt(s));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('a relay item: the answer goes to the relay with the item named, confirmed with Noted.', () => {
|
|
106
|
+
const relayItems = relayItemsFrom('## Waiting on Quinn\n- Crochets: flip the 8 category pages Tuesday morning?');
|
|
107
|
+
const queue = buildQueue({ items: [], relayItems, now: NOW, timeZone: TZ });
|
|
108
|
+
expect(firstPrompt({ queue, index: 0 })).toBe('Crochets, item 1: Flip the 8 category pages Tuesday morning. Yes or no?');
|
|
109
|
+
const r = stepBriefing({ queue, index: 0 }, 'yes');
|
|
110
|
+
expect(r.reply).toBe('Noted. That is everything.');
|
|
111
|
+
expect(r.effect).toEqual({ kind: 'relay', text: 'Answer on "Flip the 8 category pages Tuesday morning" (Crochets): yes' });
|
|
112
|
+
const free = stepBriefing({ queue, index: 0 }, 'yes but do it Wednesday instead');
|
|
113
|
+
expect(free.effect).toEqual({ kind: 'relay', text: 'Answer on "Flip the 8 category pages Tuesday morning" (Crochets): yes but do it Wednesday instead' });
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('something it does not understand about a to-do is left for the normal assistant, the briefing stays open', () => {
|
|
117
|
+
const s = start();
|
|
118
|
+
const r = stepBriefing(s, 'what is the weather like');
|
|
119
|
+
expect(r.passThrough).toBe(true);
|
|
120
|
+
expect(r.state?.index).toBe(0);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { spokenSummary } from '../corpus/converse/spoken-summary';
|
|
4
|
+
|
|
5
|
+
describe('what is said aloud for a long answer', () => {
|
|
6
|
+
it('a short answer is said whole', () => {
|
|
7
|
+
expect(spokenSummary('Two things are due today: the bench and printer paper.')).toBeUndefined();
|
|
8
|
+
expect(spokenSummary('1. Bench 2. Paper 3. Salt')).toBeUndefined();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('a numbered list: the lead-in, three items, and N more', () => {
|
|
12
|
+
const said = spokenSummary('This week, the following tasks are due: 1. Plan out the week ahead (due 2026-11-20). 2. Build lead QC on staging. 3. Launch lead for Crochet V2. 4. Order the bench. 5. Call the bank. 6. Pay the rent.');
|
|
13
|
+
expect(said).toBe('This week, the following tasks are due. Plan out the week ahead (due 2026-11-20). Build lead QC on staging. Launch lead for Crochet V2. And 3 more.');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('a long run-on list is cut at a comma and points to the screen', () => {
|
|
17
|
+
const long = 'Today, you have tasks that include checking the debug AI backend and UI updates, completing two sessions of 15 minutes on the debug UI, completing two sessions of 15 minutes on the marketing agent UI, running a quick check of the V2 marketing agent deployed app, reviewing and providing feedback on the animated video builder, creating two videos for top articles and one video for landing pages';
|
|
18
|
+
const said = spokenSummary(long)!;
|
|
19
|
+
expect(said.split(/\s+/).length).toBeLessThan(50);
|
|
20
|
+
expect(said).toMatch(/The rest is on your screen\.$/);
|
|
21
|
+
expect(said.startsWith('Today, you have tasks that include')).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('long prose is cut at a sentence', () => {
|
|
25
|
+
const prose = `${'The relay shipped the combined roll and verified production across every service. '.repeat(5)}`;
|
|
26
|
+
const said = spokenSummary(prose)!;
|
|
27
|
+
expect(said).toMatch(/The rest is on your screen\.$/);
|
|
28
|
+
expect(said.split(/\s+/).length).toBeLessThanOrEqual(60);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -56,6 +56,57 @@ function setup(over: Partial<ConverseDeps> = {}, owner = 'me') {
|
|
|
56
56
|
return { t, deps, brain, synthesize, put, transcribe, kept };
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
describe('a briefing in progress is kept on the conversation', () => {
|
|
60
|
+
const queue = [{ id: 'relay:0', kind: 'relay' as const, project: 'Crochets', text: 'Flip the pages', question: 'Yes or no?', more: 'More.' }];
|
|
61
|
+
|
|
62
|
+
it('hands the state to the next turn, clears it when the brain says it is over, and files a relay answer with its own words', async () => {
|
|
63
|
+
const { deps, t } = setup();
|
|
64
|
+
const seen: unknown[] = [];
|
|
65
|
+
const turns = [
|
|
66
|
+
{ text: 'Crochets, item 1: Flip the pages. Yes or no?', briefing: { queue, index: 0 } },
|
|
67
|
+
{ text: 'Noted. That is everything.', briefing: null, forRelay: true, relayText: 'Answer on "Flip the pages" (Crochets): yes' },
|
|
68
|
+
];
|
|
69
|
+
const withBrain = { ...deps, brain: async (input: any) => { seen.push(input.briefing); return turns.shift()!; } };
|
|
70
|
+
const first = await handleConverseTurn(withBrain, { text: 'brief me' });
|
|
71
|
+
const row = () => [...t.rows.values()].find((r) => r.data.source === 'conversation');
|
|
72
|
+
expect(row().data.briefing.index).toBe(0);
|
|
73
|
+
await handleConverseTurn(withBrain, { text: 'yes', conversationId: first.conversation_id });
|
|
74
|
+
expect(seen[0]).toBeNull();
|
|
75
|
+
expect((seen[1] as any).index).toBe(0);
|
|
76
|
+
expect(row().data.briefing).toBeNull();
|
|
77
|
+
const inbox = [...t.rows.values()].find((r) => r.data.source === 'relay_inbox');
|
|
78
|
+
expect(inbox.data.orders[0].text).toBe('Answer on "Flip the pages" (Crochets): yes');
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('long replies: the voice says the short version, the record keeps the whole', () => {
|
|
83
|
+
it('speaks `spoken` and stores `text`', async () => {
|
|
84
|
+
const { deps, t } = setup();
|
|
85
|
+
const said: string[] = [];
|
|
86
|
+
const withBrain = {
|
|
87
|
+
...deps,
|
|
88
|
+
brain: async () => ({ text: 'The whole long answer with five things.', spoken: 'The short one.' }),
|
|
89
|
+
synthesize: async ({ text }: { text: string }) => { said.push(text); return { audio: new Uint8Array([1]), mimeType: 'audio/mpeg' } as never; },
|
|
90
|
+
};
|
|
91
|
+
const out = await handleConverseTurn(withBrain as never, { text: 'what is due this week' });
|
|
92
|
+
expect(said).toEqual(['The short one.']);
|
|
93
|
+
expect(out.reply_text).toBe('The whole long answer with five things.');
|
|
94
|
+
expect([...t.rows.values()][0].data.turns[0].assistant.text).toBe('The whole long answer with five things.');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('what End pulls asks out of', () => {
|
|
99
|
+
it('is what HE said, never the assistant\'s own replies (a reply that lists to-dos was filed as new to-dos)', async () => {
|
|
100
|
+
const { deps } = setup();
|
|
101
|
+
let seen = '';
|
|
102
|
+
const withExtract = { ...deps, brain: async () => ({ text: 'Yesterday you added 3 new to-dos: Call the bank, Pay rent and Buy salt.' }), extract: async ({ transcript }: { transcript: string }) => { seen = transcript; return { asks: [], decisions: [] }; } };
|
|
103
|
+
const first = await handleConverseTurn(withExtract as never, { text: 'what did I do yesterday' });
|
|
104
|
+
await handleConverseEnd(withExtract as never, { conversationId: first.conversation_id });
|
|
105
|
+
expect(seen).toContain('what did I do yesterday');
|
|
106
|
+
expect(seen).not.toContain('Call the bank');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
59
110
|
describe('where the time went', () => {
|
|
60
111
|
it('reports each step of a fresh turn, with the brain steps, once, and not on a replay', async () => {
|
|
61
112
|
const { deps } = setup();
|
|
@@ -50,6 +50,29 @@ function retrievedFor(question: string): RetrievedDocument[] {
|
|
|
50
50
|
|
|
51
51
|
// ---------------------------------------------------------------------------
|
|
52
52
|
|
|
53
|
+
describe('the reads for one question run together, not one after another', () => {
|
|
54
|
+
it('asks for the source list while the document search is still in flight', async () => {
|
|
55
|
+
const base = createFixtureCorpusApi({ scope: SCOPE });
|
|
56
|
+
let searchDone = false;
|
|
57
|
+
let sourcesAskedBeforeSearchDone = false;
|
|
58
|
+
const corpus = {
|
|
59
|
+
...base,
|
|
60
|
+
listDocuments: async (...args: Parameters<typeof base.listDocuments>) => {
|
|
61
|
+
await new Promise((r) => setTimeout(r, 30));
|
|
62
|
+
const out = await base.listDocuments(...args);
|
|
63
|
+
searchDone = true;
|
|
64
|
+
return out;
|
|
65
|
+
},
|
|
66
|
+
listSources: async () => {
|
|
67
|
+
sourcesAskedBeforeSearchDone = !searchDone;
|
|
68
|
+
return base.listSources();
|
|
69
|
+
},
|
|
70
|
+
} as typeof base;
|
|
71
|
+
await askCorpus(ask('Acme renewal rate and seats'), { corpus, llm: scriptedLlm({ answer: 'ok', citations: [] }) });
|
|
72
|
+
expect(sourcesAskedBeforeSearchDone).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
53
76
|
describe('batching — N documents, ONE call', () => {
|
|
54
77
|
it('sends every retrieved document in a single request', async () => {
|
|
55
78
|
const calls: unknown[] = [];
|
|
@@ -27,7 +27,7 @@ export interface ItemIntent {
|
|
|
27
27
|
const WEEKDAYS = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
|
|
28
28
|
const ITEM_WORDS = /\b(commit(?:ted|ment|ments)?|promis(?:ed|e)|owe|due|deadline|deadlines|slipp(?:ing|ed)|behind|overdue|late|at risk|blocked|to-?dos?|tasks?|items?|status|on my plate|open|in progress|linear|assigned|owner)\b/i;
|
|
29
29
|
|
|
30
|
-
const addDays = (day: string, n: number): string => {
|
|
30
|
+
export const addDays = (day: string, n: number): string => {
|
|
31
31
|
const d = new Date(`${day}T00:00:00Z`);
|
|
32
32
|
d.setUTCDate(d.getUTCDate() + n);
|
|
33
33
|
return d.toISOString().slice(0, 10);
|
|
@@ -41,35 +41,46 @@ function weekOf(day: string): { from: string; to: string } {
|
|
|
41
41
|
return { from, to: addDays(from, 6) };
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/** The
|
|
45
|
-
export function
|
|
44
|
+
/** The calendar window a question names ("yesterday", "last week", "this month"), in the reader's zone, or null. */
|
|
45
|
+
export function questionWindow(question: string, now: number, timeZone = 'UTC'): { from: string; to: string; label: string } | null {
|
|
46
46
|
const q = question.toLowerCase();
|
|
47
|
-
if (!ITEM_WORDS.test(q)) return null;
|
|
48
47
|
const today = localDate(now, timeZone);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
let focus: ItemFocus = 'status';
|
|
52
|
-
if (/\b(slipp(?:ing|ed)|behind|overdue|late|at risk|missed)\b/.test(q)) focus = 'slipping';
|
|
53
|
-
else if (/\b(commit(?:ted|ment|ments)?|promis(?:ed|e)|owe)\b/.test(q)) focus = 'committed';
|
|
54
|
-
else if (/\b(due|deadline|deadlines)\b/.test(q)) focus = 'due';
|
|
55
|
-
|
|
56
|
-
let from: string | undefined;
|
|
57
|
-
let to: string | undefined;
|
|
58
|
-
let windowLabel: string | undefined;
|
|
59
|
-
const set = (a: string, b: string, label: string) => { from = a; to = b; windowLabel = `${label} (${a === b ? a : `${a} to ${b}`})`; };
|
|
60
|
-
|
|
48
|
+
let out: { from: string; to: string; label: string } | null = null;
|
|
49
|
+
const set = (a: string, b: string, label: string) => { out = { from: a, to: b, label }; };
|
|
61
50
|
const named = WEEKDAYS.find((w) => new RegExp(`\\b${w}\\b`).test(q));
|
|
62
51
|
if (/\bnext week\b/.test(q)) { const w = weekOf(addDays(today, 7)); set(w.from, w.to, 'next week'); }
|
|
63
52
|
else if (/\blast week\b/.test(q)) { const w = weekOf(addDays(today, -7)); set(w.from, w.to, 'last week'); }
|
|
64
53
|
else if (/\bthis week\b|\bthe week\b/.test(q)) { const w = weekOf(today); set(w.from, w.to, 'this week'); }
|
|
54
|
+
else if (/\blast month\b/.test(q)) { const first = `${today.slice(0, 8)}01`; const end = addDays(first, -1); set(`${end.slice(0, 8)}01`, end, 'last month'); }
|
|
55
|
+
else if (/\bthis month\b/.test(q)) set(`${today.slice(0, 8)}01`, today, 'this month');
|
|
65
56
|
else if (/\btomorrow\b/.test(q)) set(addDays(today, 1), addDays(today, 1), 'tomorrow');
|
|
66
57
|
else if (/\btoday\b/.test(q)) set(today, today, 'today');
|
|
67
58
|
else if (/\byesterday\b/.test(q)) set(addDays(today, -1), addDays(today, -1), 'yesterday');
|
|
59
|
+
else if (/\b(recently|lately)\b/.test(q)) set(addDays(today, -6), today, 'the last week');
|
|
68
60
|
else if (named) {
|
|
69
61
|
// The NEXT such weekday, today included: "due Friday" on a Friday means today.
|
|
70
62
|
const delta = (WEEKDAYS.indexOf(named) - weekdayOf(today) + 7) % 7;
|
|
71
63
|
const day = addDays(today, delta);
|
|
72
64
|
set(day, day, named[0].toUpperCase() + named.slice(1));
|
|
73
65
|
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The intent, or null when the question is not about tracked items at all. */
|
|
70
|
+
export function itemIntent(question: string, now: number, timeZone = 'UTC'): ItemIntent | null {
|
|
71
|
+
const q = question.toLowerCase();
|
|
72
|
+
if (!ITEM_WORDS.test(q)) return null;
|
|
73
|
+
const today = localDate(now, timeZone);
|
|
74
|
+
const mine = /\b(i|i'm|i've|my|me|mine)\b/.test(q);
|
|
75
|
+
|
|
76
|
+
let focus: ItemFocus = 'status';
|
|
77
|
+
if (/\b(slipp(?:ing|ed)|behind|overdue|late|at risk|missed)\b/.test(q)) focus = 'slipping';
|
|
78
|
+
else if (/\b(commit(?:ted|ment|ments)?|promis(?:ed|e)|owe)\b/.test(q)) focus = 'committed';
|
|
79
|
+
else if (/\b(due|deadline|deadlines)\b/.test(q)) focus = 'due';
|
|
80
|
+
|
|
81
|
+
const window = questionWindow(question, now, timeZone);
|
|
82
|
+
const from = window?.from;
|
|
83
|
+
const to = window?.to;
|
|
84
|
+
const windowLabel = window ? `${window.label} (${window.from === window.to ? window.from : `${window.from} to ${window.to}`})` : undefined;
|
|
74
85
|
return { focus, from, to, mine, today, ...(windowLabel ? { windowLabel } : {}) };
|
|
75
86
|
}
|