@startsimpli/integrations 0.2.124 → 0.2.126
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/__tests__/briefing-actions.test.ts +316 -0
- package/src/__tests__/briefing-compose.test.ts +6 -0
- package/src/__tests__/briefing-intent-table.ts +121 -0
- package/src/__tests__/briefing-intent.test.ts +281 -0
- package/src/corpus/briefing/actions/confirm.ts +65 -0
- package/src/corpus/briefing/actions/execute.ts +153 -0
- package/src/corpus/briefing/actions/index.ts +9 -0
- package/src/corpus/briefing/actions/log.ts +63 -0
- package/src/corpus/briefing/actions/seam.ts +50 -0
- package/src/corpus/briefing/actions/types.ts +90 -0
- package/src/corpus/briefing/compose.ts +3 -0
- package/src/corpus/briefing/index.ts +2 -0
- package/src/corpus/briefing/intent/dates.ts +195 -0
- package/src/corpus/briefing/intent/describe.ts +26 -0
- package/src/corpus/briefing/intent/grammar.ts +175 -0
- package/src/corpus/briefing/intent/ground.ts +95 -0
- package/src/corpus/briefing/intent/index.ts +11 -0
- package/src/corpus/briefing/intent/match.ts +56 -0
- package/src/corpus/briefing/intent/model.ts +135 -0
- package/src/corpus/briefing/intent/position.ts +49 -0
- package/src/corpus/briefing/intent/resolve.ts +49 -0
- package/src/corpus/briefing/intent/target.ts +72 -0
- package/src/corpus/briefing/intent/types.ts +61 -0
- package/src/corpus/client.ts +1 -0
- package/src/corpus/types.ts +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.126",
|
|
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,8 +50,8 @@
|
|
|
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.171",
|
|
54
53
|
"@startsimpli/auth": "^0.4.50",
|
|
54
|
+
"@startsimpli/ui": "^0.4.171",
|
|
55
55
|
"@startsimpli/utils": "^0.4.17"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
@@ -99,9 +99,9 @@
|
|
|
99
99
|
"react-native": "0.85.3",
|
|
100
100
|
"react-native-safe-area-context": "~5.7.0",
|
|
101
101
|
"@startsimpli/llm": "0.4.30",
|
|
102
|
+
"@startsimpli/ui": "0.4.171",
|
|
102
103
|
"@startsimpli/ui-native": "0.1.14",
|
|
103
104
|
"@startsimpli/auth": "0.4.50",
|
|
104
|
-
"@startsimpli/ui": "0.4.171",
|
|
105
105
|
"@startsimpli/utils": "0.4.17"
|
|
106
106
|
},
|
|
107
107
|
"scripts": {
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createPlanningApi } from '../corpus/client';
|
|
4
|
+
import {
|
|
5
|
+
commitmentEditSeam, createEntityActionLog, createMemoryActionLog, executeVoiceActions, speakConfirmation,
|
|
6
|
+
type ActionLogStore, type EditableItem, type ItemEditSeam, type VoiceAction,
|
|
7
|
+
} from '../corpus/briefing';
|
|
8
|
+
|
|
9
|
+
const ME = 'me';
|
|
10
|
+
const NOW = Date.parse('2026-11-04T15:00:00Z'); // Wednesday 10:00 in New York
|
|
11
|
+
const TZ = 'America/New_York';
|
|
12
|
+
|
|
13
|
+
/** The tenant's entity verbs in memory: shallow-merging upsert keyed by external_id, GET by id. */
|
|
14
|
+
function fakeTenant(rows: Array<{ id: string; title: string; status?: string; due_at?: string; priority?: number }>) {
|
|
15
|
+
const byExternal = new Map<string, any>();
|
|
16
|
+
let seq = 100;
|
|
17
|
+
for (const r of rows) {
|
|
18
|
+
byExternal.set(`item:${r.id}`, {
|
|
19
|
+
id: r.id, entity_type: 'commitment', external_id: `item:${r.id}`, name: r.title,
|
|
20
|
+
data: { title: r.title, status: r.status ?? 'open', owner_sub: ME, subtype: 'action', ...(r.due_at ? { due_at: r.due_at } : {}), ...(r.priority !== undefined ? { priority: r.priority } : {}) },
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const http = {
|
|
24
|
+
get: vi.fn(async (path: string, options?: { params?: Record<string, unknown> }) => {
|
|
25
|
+
const id = decodeURIComponent(path.split('/').pop() ?? '');
|
|
26
|
+
const hit = [...byExternal.values()].find((r) => String(r.id) === id);
|
|
27
|
+
if (hit) return hit;
|
|
28
|
+
if (options?.params?.external_id__in) return { results: [...byExternal.values()].filter((r) => r.external_id === options.params!.external_id__in) };
|
|
29
|
+
throw Object.assign(new Error('not found'), { status: 404 });
|
|
30
|
+
}),
|
|
31
|
+
post: vi.fn(async (_path: string, body: any) => {
|
|
32
|
+
const prev = byExternal.get(body.external_id);
|
|
33
|
+
const row = { id: prev?.id ?? String(++seq), entity_type: body.entity_type, external_id: body.external_id, name: body.name ?? prev?.name, data: { ...(prev?.data ?? {}), ...body.data } };
|
|
34
|
+
byExternal.set(body.external_id, row);
|
|
35
|
+
return row;
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
const get = (id: string) => byExternal.get(`item:${id}`);
|
|
39
|
+
return { http, get, byExternal };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function stack(rows: Parameters<typeof fakeTenant>[0], log: ActionLogStore = createMemoryActionLog()) {
|
|
43
|
+
const tenant = fakeTenant(rows);
|
|
44
|
+
const api = createPlanningApi({ http: tenant.http as never, scope: { orgId: 'org', userId: ME } as never });
|
|
45
|
+
const seam = commitmentEditSeam({ api, http: tenant.http as never, scope: { orgId: 'org', userId: ME } as never });
|
|
46
|
+
const run = (actions: VoiceAction[], id = `a${Math.random()}`, extra: object = {}) =>
|
|
47
|
+
executeVoiceActions({ actions, clientActionId: id, seam, log, ownerSub: ME, now: () => NOW, timeZone: TZ, ...extra });
|
|
48
|
+
return { tenant, seam, log, run, api };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const BENCH = { id: 'bench', title: "Order dad's bench", due_at: '2026-11-04' };
|
|
52
|
+
const PAPER = { id: 'paper', title: 'Pick up printer paper', due_at: '2026-11-04', priority: 3 };
|
|
53
|
+
|
|
54
|
+
describe('applying voice actions through the item edit path', () => {
|
|
55
|
+
it('test_defer_sets_due_at (a bare date, not an instant)', async () => {
|
|
56
|
+
const t = stack([BENCH]);
|
|
57
|
+
const out = await t.run([{ type: 'defer', itemId: 'bench', to: '2026-11-09', label: 'next week' }]);
|
|
58
|
+
expect(t.tenant.get('bench').data.due_at).toBe('2026-11-09');
|
|
59
|
+
expect(out.results[0]).toMatchObject({ status: 'applied', itemId: 'bench' });
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('test_later_clears_due_at', async () => {
|
|
63
|
+
const t = stack([BENCH]);
|
|
64
|
+
await t.run([{ type: 'defer', itemId: 'bench', to: 'later' }]);
|
|
65
|
+
expect(t.tenant.get('bench').data.due_at).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('test_pull_today_sets_due_at_today (the listener\'s today)', async () => {
|
|
69
|
+
const t = stack([{ id: 'x', title: 'X', due_at: '2026-11-20' }]);
|
|
70
|
+
await t.run([{ type: 'pull_today', itemId: 'x' }]);
|
|
71
|
+
expect(t.tenant.get('x').data.due_at).toBe('2026-11-04');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('test_done_sets_status_done_with_resolved_at', async () => {
|
|
75
|
+
const t = stack([BENCH]);
|
|
76
|
+
await t.run([{ type: 'done', itemId: 'bench' }]);
|
|
77
|
+
expect(t.tenant.get('bench').data).toMatchObject({ status: 'done', resolved_at: new Date(NOW).toISOString() });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('test_drop_sets_dropped', async () => {
|
|
81
|
+
const t = stack([BENCH]);
|
|
82
|
+
await t.run([{ type: 'drop', itemId: 'bench' }]);
|
|
83
|
+
expect(t.tenant.get('bench').data.status).toBe('dropped');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('test_priority_set', async () => {
|
|
87
|
+
const t = stack([BENCH]);
|
|
88
|
+
await t.run([{ type: 'set_priority', itemId: 'bench', priority: 1 }]);
|
|
89
|
+
expect(t.tenant.get('bench').data.priority).toBe(1);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('test_add_item_creates_commitment_owned_by_the_caller_with_due_date', async () => {
|
|
93
|
+
const t = stack([]);
|
|
94
|
+
const out = await t.run([{ type: 'add_item', title: 'Buy printer ink', dueDate: '2026-11-05' }]);
|
|
95
|
+
const created = [...t.tenant.byExternal.values()].find((r) => r.data.title === 'Buy printer ink');
|
|
96
|
+
expect(created).toBeTruthy();
|
|
97
|
+
expect(created.entity_type).toBe('commitment');
|
|
98
|
+
expect(created.data).toMatchObject({ due_at: '2026-11-05', owner_sub: ME, status: 'open' });
|
|
99
|
+
expect(out.results[0]).toMatchObject({ status: 'applied', itemId: created.id });
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('test_goes_through_existing_entity_mutation_path_not_a_side_door', async () => {
|
|
103
|
+
const t = stack([BENCH]);
|
|
104
|
+
await t.run([{ type: 'defer', itemId: 'bench', to: '2026-11-06' }]);
|
|
105
|
+
// The one write verb of the planning client: the shallow-merging upsert, carrying ONLY the changed keys.
|
|
106
|
+
const writes = t.tenant.http.post.mock.calls.filter(([, body]: any) => body.entity_type === 'commitment');
|
|
107
|
+
expect(writes).toHaveLength(1);
|
|
108
|
+
expect(writes[0][0]).toBe('api/v1/entities/upsert');
|
|
109
|
+
expect(writes[0][1]).toMatchObject({ external_id: 'item:bench', data: { due_at: '2026-11-06' } });
|
|
110
|
+
expect(Object.keys(writes[0][1].data)).toEqual(['due_at']);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('the seam is the one place an edit happens: a wrapper sees every update (where the Linear push hooks in)', async () => {
|
|
114
|
+
const t = stack([BENCH, PAPER]);
|
|
115
|
+
const seen: Array<[string, object]> = [];
|
|
116
|
+
const wrapped: ItemEditSeam = {
|
|
117
|
+
...t.seam,
|
|
118
|
+
update: async (item, patch) => { seen.push([item.id, patch]); return t.seam.update(item, patch); },
|
|
119
|
+
};
|
|
120
|
+
await executeVoiceActions({
|
|
121
|
+
actions: [{ type: 'done', itemId: 'bench' }, { type: 'defer', itemId: 'paper', to: 'later' }], clientActionId: 'w', seam: wrapped,
|
|
122
|
+
log: t.log, ownerSub: ME, now: () => NOW, timeZone: TZ,
|
|
123
|
+
});
|
|
124
|
+
expect(seen.map(([id]) => id)).toEqual(['bench', 'paper']);
|
|
125
|
+
expect(seen[1][1]).toEqual({ dueAt: null });
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('idempotency', () => {
|
|
130
|
+
it('test_idempotent_replay_of_same_action_id_applies_once', async () => {
|
|
131
|
+
const t = stack([BENCH]);
|
|
132
|
+
const first = await t.run([{ type: 'defer', itemId: 'bench', to: '2026-11-06' }], 'same-id');
|
|
133
|
+
const edits = () => t.tenant.http.post.mock.calls.filter(([, b]: any) => b.entity_type === 'commitment').length;
|
|
134
|
+
expect(edits()).toBe(1);
|
|
135
|
+
const second = await t.run([{ type: 'defer', itemId: 'bench', to: '2026-11-06' }], 'same-id');
|
|
136
|
+
expect(edits()).toBe(1);
|
|
137
|
+
expect(second.replayed).toBe(true);
|
|
138
|
+
expect(second.text).toBe(first.text);
|
|
139
|
+
// And the replay did not push a second entry on the undo stack.
|
|
140
|
+
expect(second.undoDepth).toBe(1);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('a replay survives a new executor over the same log row (the log is the tenant\'s, not the process\'s)', async () => {
|
|
144
|
+
const t = stack([BENCH]);
|
|
145
|
+
const rows = new Map<string, any>();
|
|
146
|
+
const http = {
|
|
147
|
+
get: async (_p: string, o?: { params?: Record<string, unknown> }) => ({ results: [...rows.values()].filter((r) => r.external_id === o?.params?.external_id__in) }),
|
|
148
|
+
post: async (_p: string, body: any) => { const row = { id: '1', owner_sub: ME, ...body, data: { ...(rows.get(body.external_id)?.data ?? {}), ...body.data } }; rows.set(body.external_id, row); return row; },
|
|
149
|
+
};
|
|
150
|
+
const log1 = createEntityActionLog(http as never, ME);
|
|
151
|
+
await executeVoiceActions({ actions: [{ type: 'done', itemId: 'bench' }], clientActionId: 'k', seam: t.seam, log: log1, ownerSub: ME, now: () => NOW, timeZone: TZ });
|
|
152
|
+
const log2 = createEntityActionLog(http as never, ME);
|
|
153
|
+
const again = await executeVoiceActions({ actions: [{ type: 'done', itemId: 'bench' }], clientActionId: 'k', seam: t.seam, log: log2, ownerSub: ME, now: () => NOW, timeZone: TZ });
|
|
154
|
+
expect(again.replayed).toBe(true);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('the action log is a source_document with no body, so the extractor ignores it, and another owner\'s row is not read', async () => {
|
|
158
|
+
const rows = new Map<string, any>();
|
|
159
|
+
const http = {
|
|
160
|
+
get: async (_p: string, o?: { params?: Record<string, unknown> }) => ({ results: [...rows.values()].filter((r) => r.external_id === o?.params?.external_id__in) }),
|
|
161
|
+
post: async (_p: string, body: any) => { const row = { id: '1', owner_sub: 'someone-else', ...body }; rows.set(body.external_id, row); return row; },
|
|
162
|
+
};
|
|
163
|
+
const mine = createEntityActionLog(http as never, ME);
|
|
164
|
+
await mine.save({ applied: { x: { status: 'applied', spoken: 'ok' } }, order: ['x'], stack: [] });
|
|
165
|
+
const row = [...rows.values()][0];
|
|
166
|
+
expect(row.entity_type).toBe('source_document');
|
|
167
|
+
expect(row.data.source).toBe('briefing_actions');
|
|
168
|
+
expect(row.data.body).toBeUndefined();
|
|
169
|
+
expect(row.data.summary).toBeUndefined();
|
|
170
|
+
expect((await mine.load()).applied).toEqual({}); // the stored row's owner_sub is not mine: treated as absent
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('undo', () => {
|
|
175
|
+
it('test_undo_restores_previous_values_for_last_action_and_pushes_the_reversal', async () => {
|
|
176
|
+
const t = stack([BENCH]);
|
|
177
|
+
await t.run([{ type: 'defer', itemId: 'bench', to: '2026-11-09' }]);
|
|
178
|
+
const out = await t.run([{ type: 'undo' }]);
|
|
179
|
+
// Restored exactly as it was read (the reader returns a stored bare date as that day at UTC midnight).
|
|
180
|
+
expect(t.tenant.get('bench').data.due_at).toMatch(/^2026-11-04/);
|
|
181
|
+
expect(out.results[0]).toMatchObject({ status: 'applied', itemId: 'bench' });
|
|
182
|
+
expect(out.text).toMatch(/undid/i);
|
|
183
|
+
expect(out.undoDepth).toBe(0);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('undoes a done: status and resolved_at come back', async () => {
|
|
187
|
+
const t = stack([BENCH]);
|
|
188
|
+
await t.run([{ type: 'done', itemId: 'bench' }]);
|
|
189
|
+
await t.run([{ type: 'undo' }]);
|
|
190
|
+
expect(t.tenant.get('bench').data).toMatchObject({ status: 'open', resolved_at: null });
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('undoes an added item by dropping it', async () => {
|
|
194
|
+
const t = stack([]);
|
|
195
|
+
await t.run([{ type: 'add_item', title: 'Buy ink', dueDate: null }]);
|
|
196
|
+
await t.run([{ type: 'undo' }]);
|
|
197
|
+
expect([...t.tenant.byExternal.values()].find((r) => r.data.title === 'Buy ink').data.status).toBe('dropped');
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('a second undo undoes the one before, and the stack holds five', async () => {
|
|
201
|
+
const rows = ['a', 'b', 'c', 'd', 'e', 'f', 'g'].map((id) => ({ id, title: `Item ${id}`, due_at: '2026-11-04' }));
|
|
202
|
+
const t = stack(rows);
|
|
203
|
+
for (const r of rows) await t.run([{ type: 'defer', itemId: r.id, to: '2026-11-10' }]);
|
|
204
|
+
let last = await t.run([{ type: 'undo' }]);
|
|
205
|
+
expect(last.undoDepth).toBe(4);
|
|
206
|
+
await t.run([{ type: 'undo' }]); await t.run([{ type: 'undo' }]); await t.run([{ type: 'undo' }]);
|
|
207
|
+
last = await t.run([{ type: 'undo' }]);
|
|
208
|
+
expect(last.undoDepth).toBe(0);
|
|
209
|
+
// g, f, e, d, c were restored; b and a fell off the stack of five and stay moved.
|
|
210
|
+
for (const id of ['g', 'f', 'e', 'd', 'c']) expect(t.tenant.get(id).data.due_at).toMatch(/^2026-11-04/);
|
|
211
|
+
for (const id of ['a', 'b']) expect(t.tenant.get(id).data.due_at).toBe('2026-11-10');
|
|
212
|
+
const none = await t.run([{ type: 'undo' }]);
|
|
213
|
+
expect(none.results[0].status).toBe('asked');
|
|
214
|
+
expect(none.text).toMatch(/nothing to undo/i);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('undo after the item changed elsewhere asks instead of overwriting', async () => {
|
|
218
|
+
const t = stack([BENCH]);
|
|
219
|
+
await t.run([{ type: 'defer', itemId: 'bench', to: '2026-11-09' }]);
|
|
220
|
+
t.tenant.get('bench').data.due_at = '2026-11-12'; // somebody else moved it (Linear, the web app)
|
|
221
|
+
const out = await t.run([{ type: 'undo' }]);
|
|
222
|
+
expect(out.results[0].status).toBe('asked');
|
|
223
|
+
expect(out.text).toMatch(/changed/i);
|
|
224
|
+
expect(t.tenant.get('bench').data.due_at).toBe('2026-11-12');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('priority undo from unset clears it', async () => {
|
|
228
|
+
const t = stack([{ id: 'p', title: 'P' }]);
|
|
229
|
+
await t.run([{ type: 'set_priority', itemId: 'p', priority: 0 }]);
|
|
230
|
+
await t.run([{ type: 'undo' }]);
|
|
231
|
+
expect(t.tenant.get('p').data.priority).toBeNull();
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe('what is said back', () => {
|
|
236
|
+
it('test_confirmation_text_uses_item_title_and_spoken_date', async () => {
|
|
237
|
+
const t = stack([BENCH, PAPER]);
|
|
238
|
+
expect((await t.run([{ type: 'defer', itemId: 'bench', to: '2026-11-09', label: 'next week' }])).text).toBe("Moved Order dad's bench to next week.");
|
|
239
|
+
expect((await t.run([{ type: 'defer', itemId: 'paper', to: '2026-11-06' }])).text).toBe('Moved Pick up printer paper to Friday.');
|
|
240
|
+
expect((await t.run([{ type: 'defer', itemId: 'paper', to: 'later' }])).text).toBe('Moved Pick up printer paper to later.');
|
|
241
|
+
expect((await t.run([{ type: 'pull_today', itemId: 'paper' }])).text).toBe('Pulled Pick up printer paper into today.');
|
|
242
|
+
expect((await t.run([{ type: 'done', itemId: 'bench' }])).text).toBe("Marked Order dad's bench done.");
|
|
243
|
+
expect((await t.run([{ type: 'set_priority', itemId: 'paper', priority: 1 }])).text).toBe('Made Pick up printer paper urgent.');
|
|
244
|
+
expect((await t.run([{ type: 'drop', itemId: 'paper' }])).text).toBe('Dropped Pick up printer paper.');
|
|
245
|
+
expect((await t.run([{ type: 'add_item', title: 'Buy printer ink', dueDate: '2026-11-05' }])).text).toBe('Added Buy printer ink for tomorrow.');
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('a clarification is spoken as the question, nothing is applied', async () => {
|
|
249
|
+
const t = stack([BENCH]);
|
|
250
|
+
const out = await t.run([{ type: 'clarify', question: 'Move it to when?' }]);
|
|
251
|
+
expect(out.text).toBe('Move it to when?');
|
|
252
|
+
expect(t.tenant.http.post).not.toHaveBeenCalled();
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('test_partial_failure_in_multi_action_reports_which_applied', async () => {
|
|
256
|
+
const t = stack([BENCH]);
|
|
257
|
+
const out = await t.run([
|
|
258
|
+
{ type: 'done', itemId: 'bench' },
|
|
259
|
+
{ type: 'defer', itemId: 'ghost', to: 'later' },
|
|
260
|
+
{ type: 'clarify', question: 'Which one?' },
|
|
261
|
+
]);
|
|
262
|
+
expect(out.results.map((r) => r.status)).toEqual(['applied', 'failed', 'asked']);
|
|
263
|
+
expect(out.text).toContain("Marked Order dad's bench done.");
|
|
264
|
+
expect(out.text).toMatch(/could not find/i);
|
|
265
|
+
expect(out.text).toContain('Which one?');
|
|
266
|
+
expect(out.applied).toBe(1);
|
|
267
|
+
expect(out.failed).toBe(1);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('a write that throws is reported on that action and the rest still run', async () => {
|
|
271
|
+
const t = stack([BENCH, PAPER]);
|
|
272
|
+
const real = t.tenant.http.post.getMockImplementation()!;
|
|
273
|
+
let calls = 0;
|
|
274
|
+
t.tenant.http.post.mockImplementation(async (p: string, b: any) => { calls += 1; if (calls === 1) throw new Error('503'); return real(p, b); });
|
|
275
|
+
const out = await t.run([{ type: 'done', itemId: 'bench' }, { type: 'drop', itemId: 'paper' }]);
|
|
276
|
+
expect(out.results.map((r) => r.status)).toEqual(['failed', 'applied']);
|
|
277
|
+
expect(out.text).toMatch(/could not update/i);
|
|
278
|
+
expect(out.undoDepth).toBe(1); // only what really changed can be undone
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('spoken confirmation audio', () => {
|
|
283
|
+
const synth = (fail = false) => vi.fn(async ({ text }: { text: string }) => {
|
|
284
|
+
if (fail) throw new Error('tts down');
|
|
285
|
+
return { audio: new Uint8Array([1, 2]), mimeType: 'audio/mpeg', model: 'm', provider: 'openai', usage: { characters: text.length } };
|
|
286
|
+
});
|
|
287
|
+
const audio = () => ({
|
|
288
|
+
put: vi.fn(async ({ noteId }: { noteId: string }) => `s3://voice/${noteId}.mp3`),
|
|
289
|
+
url: vi.fn(async (ref: string) => `https://signed/${encodeURIComponent(ref)}`),
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('test_confirmation_audio_via_tts_with_text_fallback', async () => {
|
|
293
|
+
const ok = await speakConfirmation({ text: 'Done.', clientActionId: 'k', synthesize: synth(), audio: audio() });
|
|
294
|
+
expect(ok.text).toBe('Done.');
|
|
295
|
+
expect(ok.audioUrl).toMatch(/^https:\/\/signed\//);
|
|
296
|
+
const down = await speakConfirmation({ text: 'Done.', clientActionId: 'k', synthesize: synth(true), audio: audio() });
|
|
297
|
+
expect(down).toMatchObject({ text: 'Done.', audioUrl: null });
|
|
298
|
+
expect(down.reason).toMatch(/tts down/);
|
|
299
|
+
const none = await speakConfirmation({ text: 'Done.', clientActionId: 'k' });
|
|
300
|
+
expect(none).toMatchObject({ text: 'Done.', audioUrl: null });
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
describe('a seam over anything', () => {
|
|
305
|
+
it('works with a hand-written seam (what the Linear-aware path will provide)', async () => {
|
|
306
|
+
const items = new Map<string, EditableItem>([['i', { id: 'i', title: 'Linear thing', status: 'open', dueAt: '2026-11-04' }]]);
|
|
307
|
+
const seam: ItemEditSeam = {
|
|
308
|
+
load: async (id) => items.get(id) ?? null,
|
|
309
|
+
update: async (item, patch) => { const next = { ...item, ...patch } as EditableItem; items.set(item.id, next); return next; },
|
|
310
|
+
create: async (draft) => { const item = { id: 'new', title: draft.title, status: 'open', dueAt: draft.dueAt ?? null } as EditableItem; items.set('new', item); return item; },
|
|
311
|
+
};
|
|
312
|
+
const out = await executeVoiceActions({ actions: [{ type: 'defer', itemId: 'i', to: '2026-11-07' }], clientActionId: 's', seam, log: createMemoryActionLog(), ownerSub: ME, now: () => NOW, timeZone: TZ });
|
|
313
|
+
expect(items.get('i')?.dueAt).toBe('2026-11-07');
|
|
314
|
+
expect(out.text).toBe('Moved Linear thing to Saturday.');
|
|
315
|
+
});
|
|
316
|
+
});
|
|
@@ -95,6 +95,12 @@ describe('composeBriefing', () => {
|
|
|
95
95
|
expect(b.items[0].kind).toBe('overdue');
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
+
it('reads a date the tenant stored bare (returned as UTC midnight) as THAT date, not the evening before', () => {
|
|
99
|
+
// A voice reply writes "Friday" as 2026-11-06; the reader hands it back as 2026-11-06T00:00:00.000Z.
|
|
100
|
+
const b = compose([item({ id: 'a', dueAt: '2026-11-05T00:00:00.000Z' }), item({ id: 'b', dueAt: '2026-11-06T00:00:00.000Z' })]);
|
|
101
|
+
expect(b.items.map((e) => [e.id, e.kind, e.dueDate])).toEqual([['a', 'due_today', '2026-11-05']]);
|
|
102
|
+
});
|
|
103
|
+
|
|
98
104
|
it('keeps an in-progress item even when it has no date, and tolerates unknown status words', () => {
|
|
99
105
|
const b = compose([item({ id: 'p', status: 'in_progress', dueAt: null }), item({ id: 'weird', status: 'whatever' as never })]);
|
|
100
106
|
expect(b.items.map((i) => i.id)).toEqual(['p', 'weird']);
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The utterance table for voice-reply intent parsing (bd startsim-8z2ah). Shared by the
|
|
3
|
+
* deterministic tests and by the one-off real-model accuracy probe, so the number the
|
|
4
|
+
* probe prints is measured on exactly the rows the tests pin.
|
|
5
|
+
*
|
|
6
|
+
* "Today" is Wednesday 2026-11-04 in New York. Item ids are readable on purpose.
|
|
7
|
+
*/
|
|
8
|
+
import type { IntentContext, IntentItem, VoiceAction } from '../corpus/briefing';
|
|
9
|
+
|
|
10
|
+
export const TZ = 'America/New_York';
|
|
11
|
+
// 2026-11-04 15:00 UTC = 10:00 in New York (Wednesday).
|
|
12
|
+
export const NOW = Date.parse('2026-11-04T15:00:00Z');
|
|
13
|
+
|
|
14
|
+
export const BRIEFED: IntentItem[] = [
|
|
15
|
+
{ id: 'wire', title: 'Send the marketing wireframes', focusName: 'Marketing' },
|
|
16
|
+
{ id: 'v2', title: 'Redeploy V2 to production', focusName: 'Platform' },
|
|
17
|
+
{ id: 'paper', title: 'Pick up printer paper' },
|
|
18
|
+
{ id: 'pr', title: 'Review the billing pull request', focusName: 'Platform' },
|
|
19
|
+
{ id: 'bench', title: "Order dad's bench" },
|
|
20
|
+
];
|
|
21
|
+
export const OTHER_OPEN: IntentItem[] = [
|
|
22
|
+
{ id: 'john', title: 'Call John about the lease' },
|
|
23
|
+
{ id: 'dentist', title: 'Dentist appointment follow-up' },
|
|
24
|
+
{ id: 'denver', title: 'Book flights for the Denver trip', focusName: 'Travel' },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
export const baseContext = (over: Partial<IntentContext> = {}): IntentContext => ({
|
|
28
|
+
utterance: '',
|
|
29
|
+
now: NOW,
|
|
30
|
+
timeZone: TZ,
|
|
31
|
+
briefed: BRIEFED,
|
|
32
|
+
open: OTHER_OPEN,
|
|
33
|
+
readingId: null,
|
|
34
|
+
hasUndo: true,
|
|
35
|
+
...over,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export type Category = 'defer' | 'reschedule' | 'pull_today' | 'done' | 'drop' | 'priority' | 'add' | 'undo'
|
|
39
|
+
| 'multi' | 'ambiguous' | 'unknown' | 'none';
|
|
40
|
+
|
|
41
|
+
export interface Row {
|
|
42
|
+
name: string;
|
|
43
|
+
category: Category;
|
|
44
|
+
say: string;
|
|
45
|
+
/** Item being read when the person pressed talk. */
|
|
46
|
+
reading?: string | null;
|
|
47
|
+
/** Expected actions, in order. A `clarify` is matched on type only. */
|
|
48
|
+
expect: VoiceAction[];
|
|
49
|
+
/** Rows the deterministic grammar is not expected to get (it asks to repeat instead). */
|
|
50
|
+
llmOnly?: boolean;
|
|
51
|
+
hasUndo?: boolean;
|
|
52
|
+
/** Open items outside the briefing; defaults to OTHER_OPEN. */
|
|
53
|
+
open?: IntentItem[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const defer = (itemId: string, to: string): VoiceAction => ({ type: 'defer', itemId, to } as VoiceAction);
|
|
57
|
+
const clarify = (): VoiceAction => ({ type: 'clarify', question: '' });
|
|
58
|
+
|
|
59
|
+
export const TABLE: Row[] = [
|
|
60
|
+
// defer to later
|
|
61
|
+
{ name: 'later, with the reason', category: 'defer', say: 'move this one to later, I am not doing that today', reading: 'paper', expect: [defer('paper', 'later')] },
|
|
62
|
+
{ name: 'push it out', category: 'defer', say: 'push this out', reading: 'pr', expect: [defer('pr', 'later')], llmOnly: true },
|
|
63
|
+
{ name: 'not today', category: 'defer', say: 'not today', reading: 'v2', expect: [defer('v2', 'later')] },
|
|
64
|
+
{ name: 'bare later', category: 'defer', say: 'later', reading: 'wire', expect: [defer('wire', 'later')] },
|
|
65
|
+
{ name: 'snooze', category: 'defer', say: 'snooze that one', reading: 'bench', expect: [defer('bench', 'later')] },
|
|
66
|
+
// reschedule to a date
|
|
67
|
+
{ name: 'to Friday', category: 'reschedule', say: 'push this to Friday', reading: 'paper', expect: [defer('paper', '2026-11-06')] },
|
|
68
|
+
{ name: 'next week', category: 'reschedule', say: 'next week', reading: 'v2', expect: [defer('v2', '2026-11-09')] },
|
|
69
|
+
{ name: 'tomorrow', category: 'reschedule', say: 'move this to tomorrow', reading: 'wire', expect: [defer('wire', '2026-11-05')] },
|
|
70
|
+
{ name: 'next Monday', category: 'reschedule', say: 'postpone this until next Monday', reading: 'pr', expect: [defer('pr', '2026-11-09')] },
|
|
71
|
+
{ name: 'in three days', category: 'reschedule', say: 'remind me about this in three days', reading: 'bench', expect: [defer('bench', '2026-11-07')], llmOnly: true },
|
|
72
|
+
{ name: 'month and day', category: 'reschedule', say: 'push this to November twelfth', reading: 'paper', expect: [defer('paper', '2026-11-12')] },
|
|
73
|
+
{ name: 'by name, with a date', category: 'reschedule', say: 'move the bench one to Thursday', expect: [defer('bench', '2026-11-05')] },
|
|
74
|
+
// pull into today
|
|
75
|
+
{ name: 'that other thing = the one open item not in the briefing', category: 'pull_today', say: 'what about that other thing, pull it up to today', reading: null, open: [OTHER_OPEN[0]], expect: [{ type: 'pull_today', itemId: 'john' }] },
|
|
76
|
+
{ name: 'that other thing is ambiguous with three unbriefed items', category: 'ambiguous', say: 'what about that other thing, pull it up to today', reading: null, expect: [clarify()] },
|
|
77
|
+
{ name: 'pull Call John', category: 'pull_today', say: 'pull the call John thing up to today', expect: [{ type: 'pull_today', itemId: 'john' }] },
|
|
78
|
+
{ name: 'bring the dentist in', category: 'pull_today', say: 'bring the dentist one into today', expect: [{ type: 'pull_today', itemId: 'dentist' }] },
|
|
79
|
+
{ name: 'do it today', category: 'pull_today', say: 'actually, I will do the Denver flights today', expect: [{ type: 'pull_today', itemId: 'denver' }], llmOnly: true },
|
|
80
|
+
{ name: 'move to today', category: 'pull_today', say: 'move the denver trip to today', expect: [{ type: 'pull_today', itemId: 'denver' }] },
|
|
81
|
+
// done
|
|
82
|
+
{ name: 'the bench one is done', category: 'done', say: 'the bench one is done', expect: [{ type: 'done', itemId: 'bench' }] },
|
|
83
|
+
{ name: 'done', category: 'done', say: 'done', reading: 'pr', expect: [{ type: 'done', itemId: 'pr' }] },
|
|
84
|
+
{ name: 'mark it complete', category: 'done', say: 'mark this as complete', reading: 'v2', expect: [{ type: 'done', itemId: 'v2' }] },
|
|
85
|
+
{ name: 'already did that', category: 'done', say: 'I already did that one', reading: 'paper', expect: [{ type: 'done', itemId: 'paper' }] },
|
|
86
|
+
{ name: 'finished the wireframes', category: 'done', say: 'I finished the wireframes', expect: [{ type: 'done', itemId: 'wire' }] },
|
|
87
|
+
// drop
|
|
88
|
+
{ name: 'drop the dentist thing', category: 'drop', say: 'drop the dentist thing', expect: [{ type: 'drop', itemId: 'dentist' }] },
|
|
89
|
+
{ name: 'forget this one', category: 'drop', say: 'forget about this one', reading: 'bench', expect: [{ type: 'drop', itemId: 'bench' }] },
|
|
90
|
+
{ name: 'scrap it', category: 'drop', say: 'scrap this', reading: 'paper', expect: [{ type: 'drop', itemId: 'paper' }] },
|
|
91
|
+
{ name: 'not doing it', category: 'drop', say: 'I am never doing the billing review, get rid of it', expect: [{ type: 'drop', itemId: 'pr' }], llmOnly: true },
|
|
92
|
+
// priority
|
|
93
|
+
{ name: 'urgent', category: 'priority', say: 'make this urgent', reading: 'v2', expect: [{ type: 'set_priority', itemId: 'v2', priority: 1 }] },
|
|
94
|
+
{ name: 'lowest', category: 'priority', say: 'make this lowest priority', reading: 'paper', expect: [{ type: 'set_priority', itemId: 'paper', priority: 4 }] },
|
|
95
|
+
{ name: 'critical by name', category: 'priority', say: 'mark the marketing wireframes as critical', expect: [{ type: 'set_priority', itemId: 'wire', priority: 0 }] },
|
|
96
|
+
{ name: 'priority number', category: 'priority', say: 'set the billing review to priority two', expect: [{ type: 'set_priority', itemId: 'pr', priority: 2 }] },
|
|
97
|
+
// add
|
|
98
|
+
{ name: 'add with a date', category: 'add', say: 'add buy printer ink for tomorrow', expect: [{ type: 'add_item', title: 'Buy printer ink', dueDate: '2026-11-05' }] },
|
|
99
|
+
{ name: 'add with no date', category: 'add', say: 'add call the plumber', expect: [{ type: 'add_item', title: 'Call the plumber', dueDate: null }] },
|
|
100
|
+
{ name: 'remind me', category: 'add', say: 'remind me to renew the passport on Friday', expect: [{ type: 'add_item', title: 'Renew the passport', dueDate: '2026-11-06' }] },
|
|
101
|
+
{ name: 'add and keeps and', category: 'add', say: 'add buy salt and pepper', expect: [{ type: 'add_item', title: 'Buy salt and pepper', dueDate: null }] },
|
|
102
|
+
// undo
|
|
103
|
+
{ name: 'undo', category: 'undo', say: 'undo', expect: [{ type: 'undo' }] },
|
|
104
|
+
{ name: 'never mind that', category: 'undo', say: 'never mind that', expect: [{ type: 'undo' }] },
|
|
105
|
+
{ name: 'put it back', category: 'undo', say: 'no wait, put it back', expect: [{ type: 'undo' }], llmOnly: true },
|
|
106
|
+
{ name: 'undo with nothing to undo', category: 'undo', say: 'undo', hasUndo: false, expect: [{ type: 'clarify', question: '' }] },
|
|
107
|
+
// multi
|
|
108
|
+
{ name: 'done and move the next one', category: 'multi', say: 'done with this, and move the next one to tomorrow', reading: 'v2', expect: [{ type: 'done', itemId: 'v2' }, defer('paper', '2026-11-05')] },
|
|
109
|
+
{ name: 'two by name', category: 'multi', say: 'drop the dentist thing and pull up the call John one to today', expect: [{ type: 'drop', itemId: 'dentist' }, { type: 'pull_today', itemId: 'john' }] },
|
|
110
|
+
// ambiguous
|
|
111
|
+
{ name: 'move that one, nothing being read', category: 'ambiguous', say: 'move that one', reading: null, expect: [clarify()] },
|
|
112
|
+
{ name: 'later, nothing being read', category: 'ambiguous', say: 'later', reading: null, expect: [clarify()] },
|
|
113
|
+
{ name: 'two items match', category: 'ambiguous', say: 'mark the platform one done', expect: [clarify()] },
|
|
114
|
+
{ name: 'no date given', category: 'ambiguous', say: 'move this one', reading: 'pr', expect: [clarify()] },
|
|
115
|
+
// unknown
|
|
116
|
+
{ name: 'tax thing', category: 'unknown', say: 'pull up the tax thing', expect: [clarify()] },
|
|
117
|
+
{ name: 'gardening', category: 'unknown', say: 'mark the gardening one done', expect: [clarify()] },
|
|
118
|
+
// none
|
|
119
|
+
{ name: 'chatter', category: 'none', say: 'what a lovely morning', expect: [clarify()] },
|
|
120
|
+
{ name: 'empty', category: 'none', say: ' ', expect: [clarify()] },
|
|
121
|
+
];
|