@startsimpli/integrations 0.2.200 → 0.2.202
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 +7 -7
- package/src/__tests__/briefing-actions.test.ts +11 -0
- package/src/__tests__/briefing-edits.test.ts +98 -0
- package/src/__tests__/briefing-markdown.test.ts +64 -0
- package/src/__tests__/converse-brain.test.ts +64 -1
- package/src/__tests__/converse-cards.test.ts +53 -0
- package/src/__tests__/converse-handoff.test.ts +8 -0
- package/src/__tests__/converse-meeting-brief.test.ts +72 -8
- package/src/__tests__/converse-meeting-duplex.test.ts +132 -0
- package/src/__tests__/converse-meeting-keep-speech.test.ts +87 -0
- package/src/__tests__/converse-meeting-vad.test.ts +1 -1
- package/src/__tests__/converse-page.test.tsx +148 -37
- package/src/__tests__/converse-roci.test.ts +22 -0
- package/src/__tests__/converse-spoken-form.test.ts +10 -0
- package/src/__tests__/converse-spoken-summary.test.ts +27 -6
- package/src/__tests__/converse-structure.test.ts +27 -0
- package/src/__tests__/converse-view.test.ts +46 -0
- package/src/__tests__/converse.test.ts +29 -2
- package/src/__tests__/corpus-ask.test.ts +22 -0
- package/src/__tests__/corpus-tracker.test.tsx +42 -174
- package/src/__tests__/data-table-logic.test.ts +75 -0
- package/src/__tests__/data-table.test.tsx +133 -0
- package/src/__tests__/extract-classify.test.ts +17 -0
- package/src/__tests__/fleet-page.test.tsx +57 -0
- package/src/__tests__/fleet-view.test.ts +149 -0
- package/src/__tests__/home-brief.test.tsx +25 -40
- package/src/__tests__/library-call-shape.test.tsx +164 -0
- package/src/__tests__/load-error.test.tsx +1 -1
- package/src/__tests__/mini-markdown.test.tsx +24 -0
- package/src/__tests__/overview-page.test.tsx +36 -6
- package/src/__tests__/plan-shell.test.tsx +6 -4
- package/src/__tests__/project-basis-entity.test.ts +19 -0
- package/src/__tests__/project-basis.test.ts +21 -0
- package/src/__tests__/relay-cli.test.ts +10 -1
- package/src/__tests__/task-detail-project-guess.test.tsx +46 -0
- package/src/__tests__/timeline-events.test.ts +65 -0
- package/src/__tests__/timeline-table.test.tsx +66 -0
- package/src/__tests__/todo-table-model.test.ts +75 -0
- package/src/__tests__/todo-table.test.tsx +202 -0
- package/src/__tests__/tracker-timeline-component.test.tsx +4 -4
- package/src/__tests__/tracker-timeline-reader.test.ts +1 -1
- package/src/comms/__tests__/app-sends-page.test.tsx +69 -0
- package/src/comms/api/comms.ts +23 -0
- package/src/comms/components/ResultsPanel.tsx +2 -2
- package/src/comms/components/SendLog.tsx +20 -8
- package/src/comms/components/index.ts +1 -0
- package/src/comms/components/pages/AppSendsPage.tsx +58 -0
- package/src/comms/hooks/index.ts +8 -3
- package/src/components/FolderTree.tsx +12 -3
- package/src/components/index.ts +4 -1
- package/src/components/pages/ConversePage.tsx +114 -105
- package/src/components/pages/FleetPage.tsx +115 -0
- package/src/components/pages/LibraryPage.tsx +63 -24
- package/src/components/pages/TaskDetailPage.tsx +27 -1
- package/src/components/pages/TrackerPage.tsx +170 -474
- package/src/components/pages/converse/CardView.tsx +72 -0
- package/src/components/pages/converse/SettingsMenu.tsx +37 -0
- package/src/components/pages/converse/Thread.tsx +48 -33
- package/src/components/pages/converse/useNeedsYou.ts +60 -0
- package/src/components/pages/home/BriefCard.tsx +16 -7
- package/src/components/pages/home/HomeBriefPage.tsx +6 -91
- package/src/components/pages/home/MiniMarkdown.tsx +51 -0
- package/src/components/pages/home/{DueSoonLine.tsx → dueSoonText.ts} +2 -11
- package/src/components/pages/home/index.ts +1 -1
- package/src/components/pages/overview/OverviewPage.tsx +46 -83
- package/src/components/pages/plan/TalkPage.tsx +5 -14
- package/src/components/pages/plan/TimelinePage.tsx +4 -2
- package/src/components/pages/task-tracker/ProjectGuess.tsx +42 -0
- package/src/components/pages/tracker/SweepPanel.tsx +108 -0
- package/src/components/pages/tracker/TimelineTable.tsx +70 -0
- package/src/components/pages/tracker/TrackerTimeline.tsx +32 -15
- package/src/components/table/DataTable.tsx +92 -0
- package/src/components/table/RowMenu.tsx +35 -0
- package/src/components/table/TablePagination.tsx +63 -0
- package/src/components/table/TableToolbar.tsx +56 -0
- package/src/components/table/TodoTable.tsx +142 -0
- package/src/components/table/index.ts +10 -0
- package/src/components/table/table-logic.ts +60 -0
- package/src/components/table/todo-model.ts +93 -0
- package/src/corpus/ask-items.ts +7 -4
- package/src/corpus/ask.ts +1 -1
- package/src/corpus/briefing/actions/confirm.ts +9 -1
- package/src/corpus/briefing/actions/execute.ts +71 -11
- package/src/corpus/briefing/actions/log.ts +1 -1
- package/src/corpus/briefing/actions/seam.ts +18 -2
- package/src/corpus/briefing/actions/types.ts +14 -0
- package/src/corpus/briefing/generate-weekly.ts +4 -0
- package/src/corpus/briefing/generate.ts +4 -0
- package/src/corpus/briefing/index.ts +1 -0
- package/src/corpus/briefing/intent/describe.ts +5 -1
- package/src/corpus/briefing/intent/edits.ts +92 -0
- package/src/corpus/briefing/intent/grammar.ts +3 -0
- package/src/corpus/briefing/intent/ground.ts +5 -1
- package/src/corpus/briefing/intent/match.ts +3 -1
- package/src/corpus/briefing/intent/model.ts +36 -3
- package/src/corpus/briefing/intent/resolve.ts +12 -1
- package/src/corpus/briefing/intent/types.ts +8 -0
- package/src/corpus/briefing/markdown.ts +71 -0
- package/src/corpus/briefing/speak.ts +13 -0
- package/src/corpus/client.ts +40 -146
- package/src/corpus/converse/brain.ts +41 -13
- package/src/corpus/converse/briefing-queue.ts +105 -27
- package/src/corpus/converse/cards.ts +69 -0
- package/src/corpus/converse/client.ts +6 -0
- package/src/corpus/converse/fleet-view.ts +126 -0
- package/src/corpus/converse/fleet.ts +18 -5
- package/src/corpus/converse/followups.ts +12 -2
- package/src/corpus/converse/handle.ts +21 -12
- package/src/corpus/converse/handoff.ts +7 -2
- package/src/corpus/converse/index.ts +11 -3
- package/src/corpus/converse/meeting-config.ts +8 -4
- package/src/corpus/converse/meeting.ts +66 -11
- package/src/corpus/converse/respond.ts +14 -2
- package/src/corpus/converse/roci.ts +13 -0
- package/src/corpus/converse/spoken-form.ts +9 -2
- package/src/corpus/converse/spoken-summary.ts +30 -8
- package/src/corpus/converse/store.ts +2 -0
- package/src/corpus/converse/structure.ts +39 -0
- package/src/corpus/converse/types.ts +14 -1
- package/src/corpus/converse/view.ts +34 -0
- package/src/corpus/entities.ts +2 -0
- package/src/corpus/extract.ts +9 -4
- package/src/corpus/index.ts +2 -0
- package/src/corpus/participants.ts +220 -0
- package/src/corpus/project-basis.ts +23 -0
- package/src/corpus/timeline-events.ts +83 -0
- package/src/corpus/tracker-sort.ts +9 -3
- package/src/corpus/tracker-timeline-client.ts +2 -0
- package/src/corpus/tracker-timeline.ts +4 -0
- package/src/corpus/types.ts +38 -5
- package/src/native/app/__tests__/plan-talk-registry.test.tsx +2 -1
- package/src/native/app/converseServices.ts +5 -3
- package/src/native/app/device.ts +2 -0
- package/src/native/converse/ConverseScreen.tsx +30 -4
- package/src/native/converse/__tests__/liveScreen.test.tsx +35 -2
- package/src/native/converse/__tests__/meetingIO.test.ts +55 -1
- package/src/native/converse/format.ts +2 -2
- package/src/native/converse/io.ts +15 -5
- package/src/native/home/HomeScreen.tsx +1 -1
- package/src/native/home/tab.tsx +1 -2
- package/src/native/plan/PlanTab.tsx +1 -2
- package/src/native/plan/__tests__/plan-tab.test.tsx +5 -5
- package/src/native/talk/TalkTab.tsx +1 -1
- package/src/native/talk/__tests__/talk-tab.test.tsx +1 -1
- package/src/__tests__/home-needs-your-call.test.tsx +0 -65
- package/src/components/pages/tracker/TrackerBoard.tsx +0 -45
- package/src/components/pages/tracker/TrackerToolbar.tsx +0 -44
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* Only what really changed is on the undo stack.
|
|
11
11
|
*/
|
|
12
12
|
import { localDate } from '../../today';
|
|
13
|
+
import { speakCount } from '../speak';
|
|
13
14
|
import type { VoiceAction } from '../intent/types';
|
|
14
15
|
import { confirmText, shortTitle, undoText } from './confirm';
|
|
15
16
|
import { REMEMBERED_ACTIONS, UNDO_DEPTH } from './log';
|
|
@@ -41,6 +42,10 @@ function snapshot(item: EditableItem, patch: ItemPatch): ItemPatch {
|
|
|
41
42
|
else if (key === 'resolvedAt') before.resolvedAt = item.resolvedAt ?? null;
|
|
42
43
|
else if (key === 'statusReason') before.statusReason = item.statusReason ?? '';
|
|
43
44
|
else if (key === 'status') before.status = item.status;
|
|
45
|
+
else if (key === 'title') before.title = item.title;
|
|
46
|
+
else if (key === 'detail') before.detail = item.detail ?? '';
|
|
47
|
+
else if (key === 'estimateMinutes') before.estimateMinutes = item.estimateMinutes ?? null;
|
|
48
|
+
else if (key === 'focusId') before.focusId = item.focusId ?? null;
|
|
44
49
|
}
|
|
45
50
|
return before;
|
|
46
51
|
}
|
|
@@ -50,9 +55,43 @@ function changedSince(item: EditableItem, after: ItemPatch): boolean {
|
|
|
50
55
|
if ('dueAt' in after && !sameDay(item.dueAt, after.dueAt)) return true;
|
|
51
56
|
if ('status' in after && item.status !== after.status) return true;
|
|
52
57
|
if ('priority' in after && (item.priority ?? null) !== (after.priority ?? null)) return true;
|
|
58
|
+
if ('title' in after && item.title !== after.title) return true;
|
|
59
|
+
if ('detail' in after && (item.detail ?? '') !== (after.detail ?? '')) return true;
|
|
60
|
+
if ('estimateMinutes' in after && (item.estimateMinutes ?? null) !== (after.estimateMinutes ?? null)) return true;
|
|
61
|
+
if ('focusId' in after && (item.focusId ?? null) !== (after.focusId ?? null)) return true;
|
|
53
62
|
return false;
|
|
54
63
|
}
|
|
55
64
|
|
|
65
|
+
const projectKey = (name: string) => name.toLowerCase().replace(/\b(?:the|project|projects)\b/g, ' ').replace(/[^a-z0-9]+/g, ' ').trim();
|
|
66
|
+
|
|
67
|
+
/** The project a spoken name means: an exact match, else the one project whose name holds it (or it holds). */
|
|
68
|
+
function findProject(name: string, focuses: Array<{ id: string; title: string }>) {
|
|
69
|
+
const key = projectKey(name);
|
|
70
|
+
if (!key) return null;
|
|
71
|
+
const exact = focuses.filter((f) => projectKey(f.title) === key);
|
|
72
|
+
if (exact.length === 1) return exact[0];
|
|
73
|
+
const near = focuses.filter((f) => { const k = projectKey(f.title); return k.includes(key) || key.includes(k); });
|
|
74
|
+
return near.length === 1 ? near[0] : null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
type Planned = { patch: ItemPatch; action: VoiceAction } | { ask: string };
|
|
78
|
+
|
|
79
|
+
async function planFor(action: VoiceAction, item: EditableItem, today: string, nowIso: string, seam: ItemEditSeam): Promise<Planned> {
|
|
80
|
+
switch (action.type) {
|
|
81
|
+
case 'rename': return { patch: { title: action.title }, action };
|
|
82
|
+
case 'add_detail': return { patch: { detail: item.detail ? `${item.detail}\n\n${action.detail}` : action.detail }, action };
|
|
83
|
+
case 'set_estimate': return { patch: { estimateMinutes: action.minutes }, action };
|
|
84
|
+
case 'set_project': {
|
|
85
|
+
if (action.project === null) return { patch: { focusId: null }, action };
|
|
86
|
+
if (!seam.listFocuses) throw new Error('This client cannot change projects.');
|
|
87
|
+
const focus = findProject(action.project, await seam.listFocuses());
|
|
88
|
+
if (!focus) return { ask: `I could not find a project called ${shortTitle(action.project)}.` };
|
|
89
|
+
return { patch: { focusId: focus.id }, action: { ...action, project: focus.title } };
|
|
90
|
+
}
|
|
91
|
+
default: return { patch: patchFor(action, today, nowIso) as ItemPatch, action };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
56
95
|
function patchFor(action: VoiceAction, today: string, nowIso: string): ItemPatch | null {
|
|
57
96
|
switch (action.type) {
|
|
58
97
|
case 'defer': return { dueAt: action.to === 'later' ? null : action.to };
|
|
@@ -75,10 +114,10 @@ function remember(log: ActionLog, key: string, result: ActionResult) {
|
|
|
75
114
|
while (log.order.length > REMEMBERED_ACTIONS) delete log.applied[log.order.shift() as string];
|
|
76
115
|
}
|
|
77
116
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
117
|
+
const groupOf = (entry: UndoEntry) => entry.actionId.split('#')[0];
|
|
118
|
+
|
|
119
|
+
/** Restores one entry. The caller has already taken it off the stack. */
|
|
120
|
+
async function undoEntry(entry: UndoEntry, input: ExecuteInput, now: number): Promise<ActionResult> {
|
|
82
121
|
try {
|
|
83
122
|
const item = await input.seam.load(entry.itemId);
|
|
84
123
|
if (!item) return { status: 'asked', spoken: `${shortTitle(entry.title)} is gone, so I could not undo that.`, itemId: entry.itemId };
|
|
@@ -93,11 +132,29 @@ async function undoOne(log: ActionLog, input: ExecuteInput, now: number): Promis
|
|
|
93
132
|
}
|
|
94
133
|
return { status: 'applied', spoken: undoText(entry, now, input.timeZone), itemId: entry.itemId };
|
|
95
134
|
} catch (error) {
|
|
96
|
-
log.stack.push(entry); // nothing changed: it can be tried again
|
|
97
135
|
return { status: 'failed', spoken: `I could not undo that: ${error instanceof Error ? error.message : 'the change did not go through'}.`, itemId: entry.itemId, reason: reasonOf(error) };
|
|
98
136
|
}
|
|
99
137
|
}
|
|
100
138
|
|
|
139
|
+
/** "Undo" reverts the last reply: every change made under the same client action id, newest first. */
|
|
140
|
+
async function undoLast(log: ActionLog, input: ExecuteInput, now: number): Promise<ActionResult> {
|
|
141
|
+
const top = log.stack[log.stack.length - 1];
|
|
142
|
+
if (!top) return { status: 'asked', spoken: 'There is nothing to undo.' };
|
|
143
|
+
const group = groupOf(top);
|
|
144
|
+
const entries: UndoEntry[] = [];
|
|
145
|
+
// Popped either way: an entry that cannot be restored must not block the ones under it.
|
|
146
|
+
while (log.stack.length && groupOf(log.stack[log.stack.length - 1]) === group) entries.push(log.stack.pop() as UndoEntry);
|
|
147
|
+
const results: ActionResult[] = [];
|
|
148
|
+
for (const entry of entries) {
|
|
149
|
+
const r = await undoEntry(entry, input, now);
|
|
150
|
+
if (r.status === 'failed') log.stack.push(entry); // nothing changed: it can be tried again
|
|
151
|
+
results.push(r);
|
|
152
|
+
}
|
|
153
|
+
if (results.length === 1) return results[0];
|
|
154
|
+
if (results.every((r) => r.status === 'applied')) return { status: 'applied', spoken: `Undid all ${speakCount(results.length)} changes.` };
|
|
155
|
+
return { status: results.some((r) => r.status === 'failed') ? 'failed' : 'asked', spoken: results.map((r) => r.spoken).join(' ') };
|
|
156
|
+
}
|
|
157
|
+
|
|
101
158
|
export async function executeVoiceActions(input: ExecuteInput): Promise<ExecuteOutcome> {
|
|
102
159
|
const now = (input.now ?? Date.now)();
|
|
103
160
|
const today = localDate(now, input.timeZone);
|
|
@@ -115,7 +172,7 @@ export async function executeVoiceActions(input: ExecuteInput): Promise<ExecuteO
|
|
|
115
172
|
let result: ActionResult;
|
|
116
173
|
if (action.type === 'clarify') result = { status: 'asked', spoken: action.question };
|
|
117
174
|
else if (action.type === 'none') result = { status: 'asked', spoken: 'Sorry, I did not catch that. Can you say that again?' };
|
|
118
|
-
else if (action.type === 'undo') result = await
|
|
175
|
+
else if (action.type === 'undo') result = await undoLast(log, input, now);
|
|
119
176
|
else if (action.type === 'add_item') {
|
|
120
177
|
try {
|
|
121
178
|
const created = await input.seam.create({ title: action.title, ownerSub: input.ownerSub, dueAt: action.dueDate });
|
|
@@ -125,17 +182,20 @@ export async function executeVoiceActions(input: ExecuteInput): Promise<ExecuteO
|
|
|
125
182
|
result = { status: 'failed', spoken: `I could not add ${shortTitle(action.title)}.`, reason: reasonOf(error) };
|
|
126
183
|
}
|
|
127
184
|
} else {
|
|
128
|
-
const patch = patchFor(action, today, nowIso) as ItemPatch;
|
|
129
185
|
let title = 'that item';
|
|
130
186
|
try {
|
|
131
187
|
const item = await input.seam.load(action.itemId);
|
|
132
188
|
if (!item) result = { status: 'failed', spoken: 'I could not find that item.', itemId: action.itemId };
|
|
133
189
|
else {
|
|
134
190
|
title = item.title;
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
191
|
+
const plan = await planFor(action, item, today, nowIso, input.seam);
|
|
192
|
+
if ('ask' in plan) result = { status: 'asked', spoken: plan.ask, itemId: item.id };
|
|
193
|
+
else {
|
|
194
|
+
const before = snapshot(item, plan.patch);
|
|
195
|
+
await input.seam.update(item, plan.patch);
|
|
196
|
+
pushUndo(log, { actionId: key, kind: 'edit', itemId: item.id, title: item.title, before, after: plan.patch, at: nowIso });
|
|
197
|
+
result = { status: 'applied', spoken: confirmText(plan.action, item.title, now, input.timeZone), itemId: item.id };
|
|
198
|
+
}
|
|
139
199
|
}
|
|
140
200
|
} catch (error) {
|
|
141
201
|
result = { status: 'failed', spoken: `I could not update ${shortTitle(title)}.`, itemId: action.itemId, reason: reasonOf(error) };
|
|
@@ -42,7 +42,7 @@ export function createEntityActionLog(http: LogHttp, ownerSub: string): ActionLo
|
|
|
42
42
|
});
|
|
43
43
|
const hit = (page.results ?? []).find((r) => (r.external_id ?? (r as { externalId?: string }).externalId) === externalId && mine(r));
|
|
44
44
|
const stored = ((hit?.data ?? {}) as Record<string, unknown>).action_log as Partial<ActionLog> | undefined;
|
|
45
|
-
return stored ? { applied: stored.applied ?? {}, order: stored.order ?? [], stack: stored.stack ?? [], pending: stored.pending ?? [] } : emptyLog();
|
|
45
|
+
return stored ? { applied: stored.applied ?? {}, order: stored.order ?? [], stack: stored.stack ?? [], pending: stored.pending ?? [], ...(stored.skips ? { skips: stored.skips } : {}) } : emptyLog();
|
|
46
46
|
},
|
|
47
47
|
async save(log) {
|
|
48
48
|
await http.post('api/v1/entities/upsert', {
|
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
import type { CorpusHttp } from '../../client';
|
|
3
3
|
import { isRecord, notFound } from '../../client';
|
|
4
4
|
import { toCommitment } from '../../entities';
|
|
5
|
+
import { listFocusChoices } from '../../filing';
|
|
5
6
|
import type { Commitment, CommitmentApi, CorpusScope } from '../../types';
|
|
6
7
|
import type { EditableItem, ItemEditSeam } from './types';
|
|
7
8
|
|
|
8
9
|
export function commitmentEditSeam(options: {
|
|
9
|
-
api: Pick<CommitmentApi, 'updateCommitment' | 'createCommitment'
|
|
10
|
+
api: Pick<CommitmentApi, 'updateCommitment' | 'createCommitment'> & Partial<Pick<CommitmentApi, 'fileCommitment'>>;
|
|
10
11
|
http: Pick<CorpusHttp, 'get'>;
|
|
11
12
|
scope: CorpusScope;
|
|
12
13
|
entitiesPath?: string;
|
|
14
|
+
/** The projects an item can be filed under. Default: every focus the tenant has. */
|
|
15
|
+
listFocuses?: () => Promise<Array<{ id: string; title: string }>>;
|
|
13
16
|
}): ItemEditSeam {
|
|
14
17
|
const { api, http, scope } = options;
|
|
15
18
|
const entities = options.entitiesPath ?? 'api/v1/entities';
|
|
@@ -19,6 +22,8 @@ export function commitmentEditSeam(options: {
|
|
|
19
22
|
id: c.id, externalId: c.externalId, title: c.title, status: c.status, dueAt: c.dueAt ?? null,
|
|
20
23
|
...(c.priority !== undefined ? { priority: c.priority } : {}),
|
|
21
24
|
resolvedAt: c.resolvedAt ?? null, ...(c.statusReason ? { statusReason: c.statusReason } : {}),
|
|
25
|
+
...(c.detail ? { detail: c.detail } : {}), ...(c.estimateMinutes !== undefined ? { estimateMinutes: c.estimateMinutes } : {}),
|
|
26
|
+
focusId: c.focusId ?? null,
|
|
22
27
|
};
|
|
23
28
|
raw.set(item, c);
|
|
24
29
|
return item;
|
|
@@ -38,8 +43,19 @@ export function commitmentEditSeam(options: {
|
|
|
38
43
|
if (!api.updateCommitment) throw new Error('This client cannot edit items.');
|
|
39
44
|
const row = raw.get(item) ?? ({ id: item.id, externalId: item.externalId } as Commitment);
|
|
40
45
|
if (!row.externalId) throw new Error('This item has no stable identity to edit.');
|
|
41
|
-
|
|
46
|
+
const { focusId, estimateMinutes, ...fields } = patch;
|
|
47
|
+
let current = item;
|
|
48
|
+
if (Object.keys(fields).length || estimateMinutes !== undefined) {
|
|
49
|
+
current = wrap(await api.updateCommitment(row, { ...fields, ...(estimateMinutes !== undefined ? { estimateMinutes } : {}) } as never));
|
|
50
|
+
}
|
|
51
|
+
if (focusId !== undefined) {
|
|
52
|
+
if (!api.fileCommitment) throw new Error('This client cannot change projects.');
|
|
53
|
+
await api.fileCommitment(row, focusId);
|
|
54
|
+
current = { ...current, focusId };
|
|
55
|
+
}
|
|
56
|
+
return current;
|
|
42
57
|
},
|
|
58
|
+
listFocuses: options.listFocuses ?? (() => listFocusChoices(http as CorpusHttp, { entities })),
|
|
43
59
|
async create(draft) {
|
|
44
60
|
if (!api.createCommitment) throw new Error('This client cannot add items.');
|
|
45
61
|
return wrap(await api.createCommitment({
|
|
@@ -19,6 +19,10 @@ export interface EditableItem {
|
|
|
19
19
|
resolvedAt?: string | null;
|
|
20
20
|
statusReason?: string;
|
|
21
21
|
externalId?: string;
|
|
22
|
+
detail?: string;
|
|
23
|
+
estimateMinutes?: number;
|
|
24
|
+
focusId?: string | null;
|
|
25
|
+
focusName?: string;
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
/** The fields a voice reply changes. `null` clears (due date, priority, resolved time). */
|
|
@@ -28,6 +32,12 @@ export interface ItemPatch {
|
|
|
28
32
|
dueAt?: string | null;
|
|
29
33
|
priority?: number | null;
|
|
30
34
|
resolvedAt?: string | null;
|
|
35
|
+
title?: string;
|
|
36
|
+
detail?: string;
|
|
37
|
+
/** Minutes; `null` clears it. */
|
|
38
|
+
estimateMinutes?: number | null;
|
|
39
|
+
/** The project's id; `null` takes the item out of its project. Written as an edge, not a field. */
|
|
40
|
+
focusId?: string | null;
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
export interface ItemDraft {
|
|
@@ -40,6 +50,8 @@ export interface ItemEditSeam {
|
|
|
40
50
|
load(id: string): Promise<EditableItem | null>;
|
|
41
51
|
update(item: EditableItem, patch: ItemPatch): Promise<EditableItem>;
|
|
42
52
|
create(draft: ItemDraft): Promise<EditableItem>;
|
|
53
|
+
/** The projects an item can be filed under. Absent: this seam cannot change projects. */
|
|
54
|
+
listFocuses?(): Promise<Array<{ id: string; title: string }>>;
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
export type ActionStatus = 'applied' | 'failed' | 'asked';
|
|
@@ -89,6 +101,8 @@ export interface ActionLog {
|
|
|
89
101
|
stack: UndoEntry[];
|
|
90
102
|
/** The latest replies understood, newest last (see `PendingReply`). */
|
|
91
103
|
pending?: PendingReply[];
|
|
104
|
+
/** What he skipped in a briefing today (by his local date): the next briefing does not bring it back. */
|
|
105
|
+
skips?: { date: string; keys: string[] };
|
|
92
106
|
}
|
|
93
107
|
|
|
94
108
|
export interface ActionLogStore {
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* best-effort. SAME deps, SAME store, SAME audio path; only the composer and the
|
|
6
6
|
* wording differ. The row is the OWNER'S: there is no delivery beyond the app.
|
|
7
7
|
*/
|
|
8
|
+
import { weeklyMarkdown } from './markdown';
|
|
8
9
|
import { hashString } from './cache-key';
|
|
9
10
|
import { composeWeekly, weeklyScript } from './weekly';
|
|
10
11
|
import { createEntityBriefingStore, type BriefingRecord } from './store';
|
|
@@ -17,6 +18,8 @@ export const weeklyExternalId = (ownerSub: string, localDate: string) => `weekly
|
|
|
17
18
|
export interface WeeklyResult {
|
|
18
19
|
summaryId: string;
|
|
19
20
|
text: string;
|
|
21
|
+
/** The same week as a short structured view for the screen. */
|
|
22
|
+
markdown?: string;
|
|
20
23
|
audioUrl: string | null;
|
|
21
24
|
audioReason?: string;
|
|
22
25
|
counts: WeeklySummary['counts'];
|
|
@@ -46,6 +49,7 @@ export async function generateWeekly(deps: BriefingDeps, request: BriefingReques
|
|
|
46
49
|
const result = (record: BriefingRecord, audioUrl: string | null, cached: boolean, reason?: string): WeeklyResult => ({
|
|
47
50
|
summaryId: record.id,
|
|
48
51
|
text: record.text,
|
|
52
|
+
markdown: weeklyMarkdown(summary),
|
|
49
53
|
audioUrl,
|
|
50
54
|
...(audioUrl ? {} : { audioReason: reason ?? record.audioReason ?? 'No audio was generated.' }),
|
|
51
55
|
counts: summary.counts,
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import type { CorpusHttp } from '../client';
|
|
16
16
|
import { briefingContentHash } from './cache-key';
|
|
17
17
|
import { composeBriefing } from './compose';
|
|
18
|
+
import { briefingMarkdown } from './markdown';
|
|
18
19
|
import { writeBriefingScript, type BriefingScriptLlm } from './script';
|
|
19
20
|
import {
|
|
20
21
|
briefingExternalId, createEntityBriefingStore, offsetsOf,
|
|
@@ -70,6 +71,8 @@ export interface BriefingRequest {
|
|
|
70
71
|
export interface BriefingResult {
|
|
71
72
|
briefingId: string;
|
|
72
73
|
text: string;
|
|
74
|
+
/** The same items as a short structured view for the screen (the spoken `text` is for the voice). */
|
|
75
|
+
markdown?: string;
|
|
73
76
|
audioUrl: string | null;
|
|
74
77
|
/** Why there is no audio, when there is none. */
|
|
75
78
|
audioReason?: string;
|
|
@@ -108,6 +111,7 @@ export async function generateBriefing(deps: BriefingDeps, request: BriefingRequ
|
|
|
108
111
|
const result = (record: BriefingRecord, audioUrl: string | null, cached: boolean, reason?: string): BriefingResult => ({
|
|
109
112
|
briefingId: record.id,
|
|
110
113
|
text: record.text,
|
|
114
|
+
markdown: briefingMarkdown(record.items, record.remaining),
|
|
111
115
|
audioUrl,
|
|
112
116
|
...(audioUrl ? {} : { audioReason: reason ?? record.audioReason ?? 'No audio was generated.' }),
|
|
113
117
|
items: record.items,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** One line saying what was understood, shown BEFORE anything is applied. */
|
|
2
2
|
import { localDate } from '../../today';
|
|
3
|
-
import { speakable } from '../speak';
|
|
3
|
+
import { speakable, spokenMinutes } from '../speak';
|
|
4
4
|
import { spokenWhen } from './dates';
|
|
5
5
|
import type { IntentContext, VoiceAction } from './types';
|
|
6
6
|
|
|
@@ -18,6 +18,10 @@ export function describeActions(actions: VoiceAction[], ctx: IntentContext): str
|
|
|
18
18
|
case 'drop': return `Drop ${name(a.itemId)}`;
|
|
19
19
|
case 'set_priority': return `Make ${name(a.itemId)} ${PRIORITY_NAMES[a.priority] ?? 'priority ' + a.priority}`;
|
|
20
20
|
case 'add_item': return `Add ${a.title}${a.dueDate ? ` for ${spokenWhen(a.dueDate, today)}` : ''}`;
|
|
21
|
+
case 'rename': return `Rename ${name(a.itemId)} to ${speakable(a.title, 10)}`;
|
|
22
|
+
case 'add_detail': return `Add a note to ${name(a.itemId)}`;
|
|
23
|
+
case 'set_estimate': return a.minutes === null ? `Clear the estimate on ${name(a.itemId)}` : `Set ${name(a.itemId)} to ${spokenMinutes(a.minutes)}`;
|
|
24
|
+
case 'set_project': return a.project === null ? `Take ${name(a.itemId)} out of its project` : `Move ${name(a.itemId)} to ${speakable(a.project, 6)}`;
|
|
21
25
|
case 'undo': return 'Undo the last change';
|
|
22
26
|
case 'clarify': return a.question;
|
|
23
27
|
default: return '';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The item edits that carry words of their own: rename, add a note, estimate, change project.
|
|
3
|
+
*
|
|
4
|
+
* Kept apart from the main grammar because their text is FREE (a new title, a note) and must keep the case it was
|
|
5
|
+
* said in, and because "move X to the Crochets project" must be read before "move X to <when>".
|
|
6
|
+
* Returns null when the reply is none of these, so the main grammar goes on as before.
|
|
7
|
+
*/
|
|
8
|
+
import { splitWhen } from './dates';
|
|
9
|
+
import { contentWords } from './match';
|
|
10
|
+
import { resolveTarget } from './target';
|
|
11
|
+
import type { IntentContext, VoiceAction } from './types';
|
|
12
|
+
|
|
13
|
+
const FILLER = /^(?:(?:hey|ok|okay|um|uh|so|well|actually|please|yeah|yes|alright|can you|could you|would you|will you|i want to|i would like to|i'd like to|let's|lets|i need you to|go ahead and|just)\b[,\s]*)+/;
|
|
14
|
+
const RENAME = /^(?:rename|retitle|(?:change|update)\s+(?:the\s+)?(?:name|title)\s+of)\s+(.+?)\s+(?:to|as)\s+(?=\S)/;
|
|
15
|
+
const DETAIL = /^(?:add|attach|put|write|append|leave)\s+(?:a\s+)?(?:note|detail|details|comment|description)s?\s+(?:to|on|for|onto)\s+(.+?)\s*(?::|,|\bsaying\b|\bthat says\b|\bwhich says\b|\bsays\b)\s*(?=\S)/;
|
|
16
|
+
const PROJECT = /^(?:move|file|put|add|assign|send|switch|change)\s+(.+?)\s+(?:to|into|in|under|onto)\s+(?:the\s+)?(.+)$/;
|
|
17
|
+
const ESTIMATE_TRIGGER = /\b(?:estimate|estimated|will take|should take|would take|takes|time ?box|budget)\b/;
|
|
18
|
+
|
|
19
|
+
const NUMBER_WORDS: Record<string, number> = { a: 1, an: 1, one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, ten: 10, fifteen: 15, twenty: 20, thirty: 30, forty: 40, 'forty five': 45, sixty: 60, ninety: 90 };
|
|
20
|
+
const DURATION = /\b(?:(an? hour and a half|half an hour|an? half hour)|(\d+(?:\.\d+)?|an?|one|two|three|four|five|six|seven|eight|nine|ten|fifteen|twenty|thirty|forty[ -]five|forty|sixty|ninety)(?:\s+and a half)?\s*(hours?|hrs?|minutes?|mins?))\b/;
|
|
21
|
+
|
|
22
|
+
/** "two hours" -> 120, "half an hour" -> 30, "an hour and a half" -> 90; null when it is not a length of time. */
|
|
23
|
+
export function parseDuration(text: string): { minutes: number; span: [number, number] } | null {
|
|
24
|
+
const m = DURATION.exec(text.toLowerCase());
|
|
25
|
+
if (!m) return null;
|
|
26
|
+
const span: [number, number] = [m.index, m.index + m[0].length];
|
|
27
|
+
if (m[1]) return { minutes: /half an hour|half hour/.test(m[1]) ? 30 : 90, span };
|
|
28
|
+
const n = Number(m[2]) || NUMBER_WORDS[m[2].replace('-', ' ')];
|
|
29
|
+
if (!n) return null;
|
|
30
|
+
const unit = /^h/.test(m[3]) ? 60 : 1;
|
|
31
|
+
return { minutes: Math.round(n * unit + (/and a half/.test(m[0]) ? unit / 2 : 0)), span };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const projectKey = (s: string) => s.toLowerCase().replace(/\b(?:the|project|projects)\b/g, ' ').replace(/[^a-z0-9]+/g, ' ').trim();
|
|
35
|
+
const TARGET_NOISE = /\b(?:set|give|make|put|the|an?|estimate|estimated|for|of|at|to|about|around|roughly|will|should|would|take|takes|time ?box|budget|is|as)\b/g;
|
|
36
|
+
|
|
37
|
+
export function parseItemEdit(ctx: IntentContext): VoiceAction[] | null {
|
|
38
|
+
const orig = ctx.utterance.replace(/[‘’]/g, "'").trim().replace(/[.!?]+$/, '');
|
|
39
|
+
const raw = orig.toLowerCase();
|
|
40
|
+
const off = FILLER.exec(raw)?.[0].length ?? 0;
|
|
41
|
+
const text = raw.slice(off);
|
|
42
|
+
const said = orig.slice(off);
|
|
43
|
+
const reading = ctx.readingId;
|
|
44
|
+
const pick = (phrase: string) => resolveTarget(phrase, ctx, reading);
|
|
45
|
+
|
|
46
|
+
const rename = RENAME.exec(text);
|
|
47
|
+
if (rename) {
|
|
48
|
+
const title = said.slice(rename[0].length).trim();
|
|
49
|
+
const target = pick(rename[1]);
|
|
50
|
+
if (!target.ok) return [{ type: 'clarify', question: target.question }];
|
|
51
|
+
return title ? [{ type: 'rename', itemId: target.item.id, title: title[0].toUpperCase() + title.slice(1) }] : [{ type: 'clarify', question: 'What should I call it?' }];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const detail = DETAIL.exec(text);
|
|
55
|
+
if (detail) {
|
|
56
|
+
const note = said.slice(detail[0].length).trim();
|
|
57
|
+
const target = pick(detail[1]);
|
|
58
|
+
if (!target.ok) return [{ type: 'clarify', question: target.question }];
|
|
59
|
+
return note ? [{ type: 'add_detail', itemId: target.item.id, detail: note[0].toUpperCase() + note.slice(1) }] : [{ type: 'clarify', question: 'What should the note say?' }];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (ESTIMATE_TRIGGER.test(text)) {
|
|
63
|
+
const length = parseDuration(text);
|
|
64
|
+
if (length) {
|
|
65
|
+
const phrase = (text.slice(0, length.span[0]) + ' ' + text.slice(length.span[1])).replace(TARGET_NOISE, ' ');
|
|
66
|
+
const target = pick(phrase);
|
|
67
|
+
if (!target.ok) return [{ type: 'clarify', question: target.question }];
|
|
68
|
+
return [{ type: 'set_estimate', itemId: target.item.id, minutes: length.minutes }];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const project = PROJECT.exec(text);
|
|
73
|
+
if (project) {
|
|
74
|
+
const dest = project[2].trim();
|
|
75
|
+
const mentionsProject = /\bproject\b/.test(text);
|
|
76
|
+
const known = new Set([...ctx.briefed, ...ctx.open].map((i) => projectKey(i.focusName ?? '')).filter(Boolean));
|
|
77
|
+
const key = projectKey(dest);
|
|
78
|
+
const isKnown = key.length > 0 && [...known].some((k) => k === key || k.includes(key) || key.includes(k));
|
|
79
|
+
// A date after "to" is a reschedule ("move it to Friday"); a project needs the word "project" or a name we know.
|
|
80
|
+
if ((mentionsProject || isKnown) && !(splitWhen(dest, ctx.now, ctx.timeZone) && !isKnown)) {
|
|
81
|
+
const spoken = dest.replace(/\s+project$/, '').trim();
|
|
82
|
+
const named = [...ctx.briefed, ...ctx.open].map((i) => i.focusName).find((f) => f && projectKey(f) === key);
|
|
83
|
+
const target = pick(project[1]);
|
|
84
|
+
if (!target.ok) return [{ type: 'clarify', question: target.question }];
|
|
85
|
+
return [{ type: 'set_project', itemId: target.item.id, project: named ?? spoken }];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Words of the phrase that describe an item (exported for tests). */
|
|
92
|
+
export const describing = (phrase: string) => contentWords(phrase);
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { localDate } from '../../today';
|
|
16
16
|
import { normalizeSpeech, splitWhen, type SpokenWhen } from './dates';
|
|
17
17
|
import { describeActions } from './describe';
|
|
18
|
+
import { parseItemEdit } from './edits';
|
|
18
19
|
import { contentWords } from './match';
|
|
19
20
|
import { resolveTarget } from './target';
|
|
20
21
|
import type { IntentContext, IntentResult, VoiceAction } from './types';
|
|
@@ -159,6 +160,8 @@ function deferTo(itemId: string, when: SpokenWhen, today: string): VoiceAction {
|
|
|
159
160
|
|
|
160
161
|
export function parseWithGrammar(ctx: IntentContext): IntentResult {
|
|
161
162
|
const raw = ctx.utterance.toLowerCase().replace(/[‘’]/g, "'").trim();
|
|
163
|
+
const edit = parseItemEdit(ctx);
|
|
164
|
+
if (edit) return { actions: edit, source: 'grammar', understood: describeActions(edit, ctx), notes: [] };
|
|
162
165
|
const actions: VoiceAction[] = [];
|
|
163
166
|
let reading = ctx.readingId;
|
|
164
167
|
for (const clause of clauses(raw)) {
|
|
@@ -55,7 +55,11 @@ export function ungrounded(actions: VoiceAction[], ctx: IntentContext): string |
|
|
|
55
55
|
const targeted = actions.filter((a): a is Extract<VoiceAction, { itemId: string }> => 'itemId' in a);
|
|
56
56
|
if (!targeted.length) return null;
|
|
57
57
|
const all = [...ctx.briefed, ...ctx.open.filter((o) => !ctx.briefed.some((b) => b.id === o.id))];
|
|
58
|
-
|
|
58
|
+
// What an edit WRITES (a new title, a note) is not a description of an item: only what was said before it is.
|
|
59
|
+
const written = actions.flatMap((a) => (a.type === 'rename' ? [a.title] : a.type === 'add_detail' ? [a.detail] : []));
|
|
60
|
+
const cutAt = written.map((w) => ctx.utterance.toLowerCase().lastIndexOf(w.toLowerCase())).filter((i) => i > 0);
|
|
61
|
+
const described = cutAt.length ? ctx.utterance.slice(0, Math.min(...cutAt)) : ctx.utterance;
|
|
62
|
+
const text = words(described);
|
|
59
63
|
const spoken = text.filter((w) => contentWords(w).length && !COMMAND.has(w));
|
|
60
64
|
const idx = ctx.readingId ? ctx.briefed.findIndex((i) => i.id === ctx.readingId) : -1;
|
|
61
65
|
const briefedIds = new Set(ctx.briefed.map((i) => i.id));
|
|
@@ -20,7 +20,9 @@ export const words = (text: string): string[] =>
|
|
|
20
20
|
/** The content words of a description: what is left after the filler. */
|
|
21
21
|
export const contentWords = (text: string): string[] => words(text).filter((w) => !STOP.has(w));
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
/** "dad" is "dad's" (the apostrophe is dropped, leaving "dads"). */
|
|
24
|
+
const bare = (w: string) => (w.length > 3 && w.endsWith('s') ? w.slice(0, -1) : w);
|
|
25
|
+
const same = (a: string, b: string) => a === b || bare(a) === bare(b) || (a.length >= 4 && b.length >= 4 && (a.startsWith(b.slice(0, 4)) && b.startsWith(a.slice(0, 4))));
|
|
24
26
|
|
|
25
27
|
export interface Scored { item: IntentItem; score: number }
|
|
26
28
|
|
|
@@ -11,7 +11,7 @@ import { isIsoDate, parseWhen, spokenWhen, weekdayName } from './dates';
|
|
|
11
11
|
import { PRIORITY_NAMES } from './describe';
|
|
12
12
|
import type { IntentContext, IntentItem, VoiceAction } from './types';
|
|
13
13
|
|
|
14
|
-
export const MAX_ACTIONS =
|
|
14
|
+
export const MAX_ACTIONS = 8;
|
|
15
15
|
const MAX_OPEN_SHOWN = 40;
|
|
16
16
|
|
|
17
17
|
export function intentSystemPrompt(): string {
|
|
@@ -23,7 +23,11 @@ export function intentSystemPrompt(): string {
|
|
|
23
23
|
'{"type":"done","item_id":ID} {"type":"drop","item_id":ID}',
|
|
24
24
|
'{"type":"set_priority","item_id":ID,"priority":0..4} 0 critical, 1 urgent or high, 2 medium, 3 low, 4 lowest',
|
|
25
25
|
'{"type":"add_item","title":"Imperative short title","due":null | "YYYY-MM-DD"} a NEW item the person asked to add',
|
|
26
|
-
'{"type":"
|
|
26
|
+
'{"type":"rename","item_id":ID,"title":"the new title"} change an item\'s title',
|
|
27
|
+
'{"type":"add_detail","item_id":ID,"detail":"the note, in the person\'s words"} add a note to an existing item (not a new item)',
|
|
28
|
+
'{"type":"set_estimate","item_id":ID,"minutes":number} how long it will take, in minutes (an hour is 60)',
|
|
29
|
+
'{"type":"set_project","item_id":ID,"project":"project name as said"} file an existing item under a project',
|
|
30
|
+
'{"type":"undo"} undo the last change (all of the last reply\'s changes)',
|
|
27
31
|
'{"type":"clarify","question":"one short spoken question"} when you cannot tell which item or when',
|
|
28
32
|
'RULES',
|
|
29
33
|
'- Acting on the wrong item is far worse than asking. When unsure, return a single clarify and nothing else.',
|
|
@@ -35,6 +39,9 @@ export function intentSystemPrompt(): string {
|
|
|
35
39
|
'- Match descriptions loosely against titles ("the bench one", "the lease call").',
|
|
36
40
|
'- Adding something new ("add X", "remind me to X", "I need to X by Friday") is add_item with the thing as an imperative title and the date as due. Do not add anything that already exists as an item.',
|
|
37
41
|
'- The title is the WORK itself, never the act of adding it. "add a to-do for the relay to keep the status current" is the title "Keep the status current" (say who it is for only when it matters); "remind me to call the bank" is "Call the bank". Never start a title with add, create, remind me, a to-do or a task. Keep every detail the person gave, in full: do not shorten it.',
|
|
42
|
+
'- "all of those", "both", "every one" mean EVERY item in the spoken list: one action per item.',
|
|
43
|
+
'- "add a note to X" is add_detail on the existing item X, never add_item. A new title or note is kept exactly as said, in full.',
|
|
44
|
+
'- "take it out of its project", "remove it from the X project", "unfile it" is set_project with "project": null, never the named project.',
|
|
38
45
|
'- Several instructions in one reply are several actions in the order spoken.',
|
|
39
46
|
'- Anything that is not an instruction about to-dos (greetings, chatter, questions): one clarify asking them to say it again.',
|
|
40
47
|
'- Dates: resolve against today in the person\'s zone. A bare weekday is the next such day after today; "next week" is Monday of next week; "next Friday" is Friday of next week. Never return a date before today.',
|
|
@@ -89,7 +96,7 @@ export function checkModelReply(reply: string, ctx: IntentContext): Checked {
|
|
|
89
96
|
if (!raw || typeof raw !== 'object') return { ok: false, reason: 'action is not an object' };
|
|
90
97
|
const type = raw.type;
|
|
91
98
|
const id = typeof raw.item_id === 'string' ? raw.item_id : '';
|
|
92
|
-
const needsItem = ['defer', 'pull_today', 'done', 'drop', 'set_priority'].includes(String(type));
|
|
99
|
+
const needsItem = ['defer', 'pull_today', 'done', 'drop', 'set_priority', 'rename', 'add_detail', 'set_estimate', 'set_project'].includes(String(type));
|
|
93
100
|
if (needsItem && !known.has(id)) return { ok: false, reason: `unknown item ${JSON.stringify(raw.item_id)}` };
|
|
94
101
|
switch (type) {
|
|
95
102
|
case 'defer': {
|
|
@@ -123,6 +130,32 @@ export function checkModelReply(reply: string, ctx: IntentContext): Checked {
|
|
|
123
130
|
out.push({ type: 'add_item', title: t[0].toUpperCase() + t.slice(1), dueDate: due });
|
|
124
131
|
break;
|
|
125
132
|
}
|
|
133
|
+
case 'rename': {
|
|
134
|
+
const t = typeof raw.title === 'string' ? raw.title.trim() : '';
|
|
135
|
+
if (!t || t.length > 200) return { ok: false, reason: 'bad title' };
|
|
136
|
+
out.push({ type: 'rename', itemId: id, title: t[0].toUpperCase() + t.slice(1) });
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
case 'add_detail': {
|
|
140
|
+
const d = typeof raw.detail === 'string' ? raw.detail.trim() : '';
|
|
141
|
+
if (!d || d.length > 2000) return { ok: false, reason: 'bad detail' };
|
|
142
|
+
out.push({ type: 'add_detail', itemId: id, detail: d[0].toUpperCase() + d.slice(1) });
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case 'set_estimate': {
|
|
146
|
+
const m = raw.minutes;
|
|
147
|
+
if (m === null) { out.push({ type: 'set_estimate', itemId: id, minutes: null }); break; }
|
|
148
|
+
if (typeof m !== 'number' || !Number.isFinite(m) || m <= 0 || m > 60 * 24 * 30) return { ok: false, reason: 'bad estimate' };
|
|
149
|
+
out.push({ type: 'set_estimate', itemId: id, minutes: Math.round(m) });
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case 'set_project': {
|
|
153
|
+
if (raw.project === null) { out.push({ type: 'set_project', itemId: id, project: null }); break; }
|
|
154
|
+
const p = typeof raw.project === 'string' ? raw.project.trim() : '';
|
|
155
|
+
if (!p || p.length > 100) return { ok: false, reason: 'bad project' };
|
|
156
|
+
out.push({ type: 'set_project', itemId: id, project: p });
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
126
159
|
case 'undo': out.push({ type: 'undo' }); break;
|
|
127
160
|
case 'clarify': {
|
|
128
161
|
const q = typeof raw.question === 'string' ? raw.question.trim() : '';
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* contradicts the data. A low-confidence model answer asks instead of acting.
|
|
7
7
|
* NEVER executes anything.
|
|
8
8
|
*/
|
|
9
|
+
import { matchItems } from './match';
|
|
9
10
|
import { describeActions } from './describe';
|
|
10
11
|
import { parseWithGrammar } from './grammar';
|
|
11
12
|
import { ungrounded } from './ground';
|
|
@@ -21,10 +22,20 @@ function byGrammar(ctx: IntentContext, notes: string[]): IntentResult {
|
|
|
21
22
|
return { ...out, confidence: out.actions.some((a) => a.type !== 'clarify' && a.type !== 'none') ? 1 : 0, notes };
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
* The words that answer "which one?": when they name exactly one open item, the earlier instruction is read again against that item
|
|
27
|
+
* alone, so "the dad one" settles "move the bench one to Friday". Otherwise both are read together.
|
|
28
|
+
*/
|
|
29
|
+
function withAnswer(asked: IntentContext, thread: { utterance: string; question: string }): IntentContext {
|
|
30
|
+
const found = matchItems(asked.utterance, [...asked.briefed, ...asked.open.filter((o) => !asked.briefed.some((b) => b.id === o.id))]);
|
|
31
|
+
if (found.kind === 'one') return { ...asked, utterance: thread.utterance, briefed: [found.item], open: [found.item], thread: undefined };
|
|
32
|
+
return { ...asked, utterance: `${thread.utterance} ${asked.utterance}` };
|
|
33
|
+
}
|
|
34
|
+
|
|
24
35
|
export async function resolveVoiceIntent(asked: IntentContext, options: IntentOptions = {}): Promise<IntentResult> {
|
|
25
36
|
const notes: string[] = [];
|
|
26
37
|
// An answer to our question is read WITH what was said first: dates and items come from either.
|
|
27
|
-
const ctx: IntentContext = asked.thread ?
|
|
38
|
+
const ctx: IntentContext = asked.thread ? withAnswer(asked, asked.thread) : asked;
|
|
28
39
|
if (!asked.utterance.trim()) return byGrammar(ctx, ['empty utterance']);
|
|
29
40
|
|
|
30
41
|
if (options.llm) {
|
|
@@ -42,6 +42,14 @@ export type VoiceAction =
|
|
|
42
42
|
/** 0 critical, 1 urgent, 2 medium, 3 low, 4 lowest. */
|
|
43
43
|
| { type: 'set_priority'; itemId: string; priority: number }
|
|
44
44
|
| { type: 'add_item'; title: string; dueDate: string | null }
|
|
45
|
+
/** Change an item's title. */
|
|
46
|
+
| { type: 'rename'; itemId: string; title: string }
|
|
47
|
+
/** Add a note to an item's detail (appended; what was there stays). */
|
|
48
|
+
| { type: 'add_detail'; itemId: string; detail: string }
|
|
49
|
+
/** How long it will take, in minutes; null clears it. */
|
|
50
|
+
| { type: 'set_estimate'; itemId: string; minutes: number | null }
|
|
51
|
+
/** File it under a project, by the name said; null takes it out of its project. */
|
|
52
|
+
| { type: 'set_project'; itemId: string; project: string | null }
|
|
45
53
|
| { type: 'undo' }
|
|
46
54
|
/** A short thing to say back when the reply was not clear enough to act on. */
|
|
47
55
|
| { type: 'clarify'; question: string }
|