@startsimpli/integrations 0.2.151 → 0.2.153
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-script.test.ts +26 -0
- package/src/__tests__/question-learn.test.ts +124 -0
- package/src/__tests__/question-voice.test.ts +17 -0
- package/src/__tests__/voice-due-inherited.test.ts +37 -0
- package/src/corpus/briefing/cache-key.ts +2 -2
- package/src/corpus/briefing/generate.ts +5 -1
- package/src/corpus/briefing/script.ts +12 -3
- package/src/corpus/briefing/speak.ts +8 -0
- package/src/corpus/briefing/types.ts +2 -0
- package/src/corpus/questions/answer.ts +11 -1
- package/src/corpus/questions/index.ts +2 -0
- package/src/corpus/questions/learn.ts +135 -0
- package/src/corpus/questions/sync.ts +19 -3
- package/src/corpus/questions/types.ts +1 -1
- package/src/corpus/questions/voice.ts +6 -4
- package/src/corpus/voice-due.ts +29 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.153",
|
|
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",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"react-native-safe-area-context": ">=4.0.0",
|
|
53
53
|
"@startsimpli/auth": "^0.4.50",
|
|
54
54
|
"@startsimpli/utils": "^0.4.18",
|
|
55
|
-
"@startsimpli/ui": "^0.4.
|
|
55
|
+
"@startsimpli/ui": "^0.4.174"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"react": {
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"react-native": "0.85.3",
|
|
100
100
|
"react-native-safe-area-context": "~5.7.0",
|
|
101
101
|
"@startsimpli/llm": "0.4.31",
|
|
102
|
-
"@startsimpli/ui": "0.4.
|
|
102
|
+
"@startsimpli/ui": "0.4.174",
|
|
103
103
|
"@startsimpli/ui-native": "0.1.14",
|
|
104
104
|
"@startsimpli/auth": "0.4.50",
|
|
105
105
|
"@startsimpli/utils": "0.4.18"
|
|
@@ -142,3 +142,29 @@ describe('writeBriefingScript', () => {
|
|
|
142
142
|
expect(llm.write).not.toHaveBeenCalled();
|
|
143
143
|
});
|
|
144
144
|
});
|
|
145
|
+
|
|
146
|
+
describe('the pointer to the check-in (bd startsim-tmrvi)', () => {
|
|
147
|
+
it('ends the briefing with how many things are unsure, in the template and with the model', async () => {
|
|
148
|
+
const unsure = { ...briefing(), unsure: 2 };
|
|
149
|
+
for (const llm of [null, goodLlm()]) {
|
|
150
|
+
const script = await writeBriefingScript(unsure, llm, opts);
|
|
151
|
+
expect(script.text).toMatch(/I am also unsure about two things\. Say check in to go through them\.$/);
|
|
152
|
+
expect(script.segments[script.segments.length - 1].id).toBeNull();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('says nothing about it when nothing is open, and in the singular for one', async () => {
|
|
157
|
+
expect((await writeBriefingScript(briefing(), null, opts)).text).not.toMatch(/unsure/);
|
|
158
|
+
expect((await writeBriefingScript({ ...briefing(), unsure: 1 }, null, opts)).text).toMatch(/unsure about one thing\. Say check in to go through it\./);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('is said on a clear day too', async () => {
|
|
162
|
+
const clear = { ...brief([]), unsure: 3 };
|
|
163
|
+
expect((await writeBriefingScript(clear, null, opts)).text).toMatch(/Nothing is due today.*unsure about three things/);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('changes the cache key, so the next tap regenerates', async () => {
|
|
167
|
+
const { briefingContentHash } = await import('../corpus/briefing/cache-key');
|
|
168
|
+
expect(briefingContentHash({ ...briefing(), unsure: 2 })).not.toBe(briefingContentHash(briefing()));
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
/**
|
|
3
|
+
* Learning from answers, and using what was learned before asking (bd startsim-tmrvi.6, tmrvi.2).
|
|
4
|
+
* Two answers that agree make a habit; a habit that agrees with Tandem's guess saves a question.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { commitmentEditSeam } from '../corpus/briefing/actions/seam';
|
|
9
|
+
import { createPlanningApi } from '../corpus/client';
|
|
10
|
+
import { guessOf, unknownGuess } from '../corpus/extraction-fields';
|
|
11
|
+
import { answerQuestion, listOpenQuestions, syncOpenQuestions } from '../corpus/questions';
|
|
12
|
+
import { createPreferenceStore, learnFromAnswer, nextEvidence } from '../corpus/questions/learn';
|
|
13
|
+
import { tenant } from './helpers/question-tenant';
|
|
14
|
+
|
|
15
|
+
const SCOPE = { orgId: 'o' } as never;
|
|
16
|
+
const ME = 'me';
|
|
17
|
+
const NOW = Date.parse('2026-11-04T15:00:00Z');
|
|
18
|
+
const TZ = 'America/New_York';
|
|
19
|
+
|
|
20
|
+
describe('nextEvidence', () => {
|
|
21
|
+
it('counts agreement and notes conflict', () => {
|
|
22
|
+
let e = nextEvidence(undefined, 'a');
|
|
23
|
+
e = nextEvidence(e, 'a');
|
|
24
|
+
expect(e).toMatchObject({ value: 'a', count: 2, conflicts: 0 });
|
|
25
|
+
e = nextEvidence(e, 'b');
|
|
26
|
+
expect(e).toMatchObject({ value: 'a', count: 2, conflicts: 1 });
|
|
27
|
+
});
|
|
28
|
+
it('switches to the new answer when it wins', () => {
|
|
29
|
+
let e = nextEvidence(undefined, 'a');
|
|
30
|
+
e = nextEvidence(e, 'b');
|
|
31
|
+
e = nextEvidence(e, 'b');
|
|
32
|
+
expect(e.value).toBe('b');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const item = (id: string, data: Record<string, unknown> = {}) => ({
|
|
37
|
+
id, entity_type: 'commitment', external_id: `commit:${id}`, name: String(data.title ?? id),
|
|
38
|
+
data: { title: `Item ${id}`, status: 'open', mentions: [{ document_id: 'note1', quote: 'q' }], ...data },
|
|
39
|
+
});
|
|
40
|
+
const fields = (over: object) => ({ due: unknownGuess('x'), project: unknownGuess('x'), owner: unknownGuess('x'), priority: unknownGuess('x'), estimate: unknownGuess('x'), ...over });
|
|
41
|
+
const note = (records: unknown[]) => ({
|
|
42
|
+
id: 'note1', entity_type: 'source_document', external_id: 'voice:n1', name: 'n',
|
|
43
|
+
data: { source: 'voice', title: 'n', voice_items: JSON.stringify(records) },
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
function setup(rows: Parameters<typeof tenant>[0]) {
|
|
47
|
+
const t = tenant(rows);
|
|
48
|
+
const api = createPlanningApi({ http: t.http, scope: SCOPE, supportedFilters: [], resolveParticipants: false } as never);
|
|
49
|
+
const deps = {
|
|
50
|
+
http: t.http, scope: SCOPE, ownerSub: ME, now: () => NOW, timeZone: TZ,
|
|
51
|
+
seam: commitmentEditSeam({ api, http: t.http, scope: SCOPE }),
|
|
52
|
+
patchItem: vi.fn(async (id: string, wire: Record<string, unknown>) => { const r = t.rows.get(id)!; r.data = { ...r.data, ...wire }; }),
|
|
53
|
+
fileItem: vi.fn(async () => undefined),
|
|
54
|
+
};
|
|
55
|
+
return { t, deps };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('learning from answers', () => {
|
|
59
|
+
it('words in a title that keep going to one project become a habit; one answer is not yet', async () => {
|
|
60
|
+
const { t, deps } = setup([item('a', { title: 'Newsletter draft for November' })]);
|
|
61
|
+
const prefs = createPreferenceStore(deps);
|
|
62
|
+
await learnFromAnswer(deps, { kind: 'project', title: 'Newsletter draft for November', answer: { value: 'f-mkt' } });
|
|
63
|
+
expect((await prefs.confident('project_word', 'newsletter'))).toBeNull();
|
|
64
|
+
await learnFromAnswer(deps, { kind: 'project', title: 'Newsletter schedule', answer: { value: 'f-mkt' } });
|
|
65
|
+
expect((await prefs.confident('project_word', 'newsletter'))?.value).toBe('f-mkt');
|
|
66
|
+
expect(t.rows.size).toBeGreaterThan(0);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('a conflicting answer makes it unsure again', async () => {
|
|
70
|
+
const { deps } = setup([]);
|
|
71
|
+
const prefs = createPreferenceStore(deps);
|
|
72
|
+
for (const v of ['f-mkt', 'f-mkt', 'f-ops']) await learnFromAnswer(deps, { kind: 'project', title: 'Newsletter', answer: { value: v } });
|
|
73
|
+
expect(await prefs.confident('project_word', 'newsletter')).toBeNull();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('due dates learn the usual offset (today, tomorrow, no date) after three alike', async () => {
|
|
77
|
+
const { deps } = setup([]);
|
|
78
|
+
const prefs = createPreferenceStore(deps);
|
|
79
|
+
for (const d of ['2026-11-04', '2026-11-04']) await learnFromAnswer(deps, { kind: 'due_date', title: 'x', answer: { value: d } });
|
|
80
|
+
expect(await prefs.confident('due_offset', 'default')).toBeNull();
|
|
81
|
+
await learnFromAnswer(deps, { kind: 'due_date', title: 'y', answer: { value: '2026-11-04' } });
|
|
82
|
+
expect((await prefs.confident('due_offset', 'default'))?.value).toBe('0');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('answering a question teaches (the real path)', async () => {
|
|
86
|
+
const { deps } = setup([
|
|
87
|
+
item('a', { title: 'Newsletter draft', external_focus_id: 'f-web' }),
|
|
88
|
+
note([{ section: 's', title: 'Newsletter draft', fields: fields({ project: guessOf('f-web', 0.4, 'assumed', 'r', { question: 'Which project?' }) }) }]),
|
|
89
|
+
]);
|
|
90
|
+
await syncOpenQuestions(deps);
|
|
91
|
+
const [q] = await listOpenQuestions(deps);
|
|
92
|
+
await answerQuestion({ ...deps, learn: true } as never, q.id, { value: 'f-mkt' });
|
|
93
|
+
const stored = await createPreferenceStore(deps).all();
|
|
94
|
+
expect(stored.some((p) => p.kind === 'project_word' && p.key === 'newsletter' && p.value === 'f-mkt')).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('using what was learned before asking', () => {
|
|
99
|
+
const rows = () => [
|
|
100
|
+
item('a', { title: 'Newsletter draft', external_focus_id: 'f-mkt' }),
|
|
101
|
+
note([{ section: 's', title: 'Newsletter draft', fields: fields({ project: guessOf('f-mkt', 0.4, 'assumed', 'r', { question: 'Which project?' }) }) }]),
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
it('does not ask when a habit agrees with the guess, and records why', async () => {
|
|
105
|
+
const { deps } = setup(rows());
|
|
106
|
+
for (let i = 0; i < 2; i += 1) await learnFromAnswer(deps, { kind: 'project', title: 'Newsletter', answer: { value: 'f-mkt' } });
|
|
107
|
+
const counts = await syncOpenQuestions(deps);
|
|
108
|
+
expect(await listOpenQuestions(deps)).toEqual([]);
|
|
109
|
+
expect(counts).toMatchObject({ opened: 0, decidedByContext: 1 });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('still asks when the habit disagrees with the guess', async () => {
|
|
113
|
+
const { deps } = setup(rows());
|
|
114
|
+
for (let i = 0; i < 2; i += 1) await learnFromAnswer(deps, { kind: 'project', title: 'Newsletter', answer: { value: 'f-ops' } });
|
|
115
|
+
await syncOpenQuestions(deps);
|
|
116
|
+
expect(await listOpenQuestions(deps)).toHaveLength(1);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('still asks when nothing was learned', async () => {
|
|
120
|
+
const { deps } = setup(rows());
|
|
121
|
+
await syncOpenQuestions(deps);
|
|
122
|
+
expect(await listOpenQuestions(deps)).toHaveLength(1);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -206,3 +206,20 @@ describe('answerQuestionByVoice', () => {
|
|
|
206
206
|
await expect(answerQuestionByVoice(deps, { clientActionId: 'press-empty-1' })).rejects.toMatchObject({ status: 400 });
|
|
207
207
|
});
|
|
208
208
|
});
|
|
209
|
+
|
|
210
|
+
describe('what is read aloud', () => {
|
|
211
|
+
it('never says a numeric date: the next question is spoken with the day named', async () => {
|
|
212
|
+
const { deps } = setup([
|
|
213
|
+
held('bench', "Order dad's bench"),
|
|
214
|
+
item('t', { title: 'Buy a present', due_at: '2026-11-13' }),
|
|
215
|
+
note([{ section: 's', title: 'Buy a present', fields: fields({
|
|
216
|
+
due: guessOf('2026-11-13', 0.5, 'assumed', 'r', { question: 'Is "Buy a present" due 2026-11-13 too, or does it have no date?' }),
|
|
217
|
+
}) }]),
|
|
218
|
+
]);
|
|
219
|
+
await syncOpenQuestions(deps);
|
|
220
|
+
const out = await say(deps, 'engineering');
|
|
221
|
+
expect(out.next?.kind).toBe('due_date');
|
|
222
|
+
expect(out.spoken).not.toMatch(/2026-11-13/);
|
|
223
|
+
expect(out.spoken).toMatch(/Friday the thirteenth/);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A date said about ONE item must not quietly become the due date of the others (bd startsim-tmrvi, found in the
|
|
3
|
+
* live run of tmrvi.8). The model put "by Friday" (said about the vet) on the whole note.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { resolveItemFields } from '../corpus/voice-due';
|
|
8
|
+
import type { VoiceItem, VoiceSection } from '../corpus/voice-sections';
|
|
9
|
+
|
|
10
|
+
const TRANSCRIPT = 'Okay, quick brain dump. I need to call the vet by Friday. Also send the invoice to Sam for the website thing. And somebody has to fix the login bug soon. Oh, and buy a birthday present for my sister.';
|
|
11
|
+
const ctx = { now: Date.parse('2026-11-07T19:00:00Z'), timeZone: 'America/New_York', transcript: TRANSCRIPT, noteWhen: 'by Friday' };
|
|
12
|
+
const section: VoiceSection = { label: 'Personal', kind: 'personal', focusId: null, items: [] } as never;
|
|
13
|
+
const item = (title: string, when?: string): VoiceItem => ({ title, ...(when ? { when } : {}) });
|
|
14
|
+
|
|
15
|
+
describe('a date said about one item', () => {
|
|
16
|
+
it('stays the vet\'s, stated and sure', () => {
|
|
17
|
+
const f = resolveItemFields(item('Call the vet', 'by Friday'), section, ctx);
|
|
18
|
+
expect(f.due.source).toBe('stated');
|
|
19
|
+
expect(f.due.question).toBeUndefined();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('is only a doubtful guess for the others, and Tandem asks', () => {
|
|
23
|
+
for (const title of ['Buy a birthday present for my sister', 'Send the invoice to Sam for the website thing', 'Fix the login bug']) {
|
|
24
|
+
const f = resolveItemFields(item(title), section, ctx);
|
|
25
|
+
expect(f.due.confidence, title).toBeLessThanOrEqual(0.5);
|
|
26
|
+
expect(f.due.question, title).toMatch(/no date/i);
|
|
27
|
+
expect(f.due.candidates.map((c) => c.value)).toContain('');
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('a note-wide "these are all for Friday" is still a plain assumption, not a question', () => {
|
|
32
|
+
const wide = { ...ctx, transcript: 'Okay, these are all the things I need by Friday. Call the vet. Fix the login bug.', noteWhen: 'by Friday' };
|
|
33
|
+
const f = resolveItemFields(item('Fix the login bug'), section, wide);
|
|
34
|
+
expect(f.due.question).toBeUndefined();
|
|
35
|
+
expect(f.due.value).not.toBeNull();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Briefing } from './types';
|
|
2
2
|
|
|
3
3
|
/** Bump when the script wording or contract changes, so yesterday's cached script is not reused. */
|
|
4
|
-
export const SCRIPT_VERSION =
|
|
4
|
+
export const SCRIPT_VERSION = 2;
|
|
5
5
|
|
|
6
6
|
/** 53-bit string hash (cyrb53). A cache key, not a security boundary, and it needs no `crypto`. */
|
|
7
7
|
export function hashString(text: string): string {
|
|
@@ -24,5 +24,5 @@ export function hashString(text: string): string {
|
|
|
24
24
|
*/
|
|
25
25
|
export function briefingContentHash(briefing: Briefing): string {
|
|
26
26
|
const parts = briefing.items.map((e) => [e.id, e.title, e.kind, e.group, e.dueDate ?? '', e.priority ?? ''].join('␟'));
|
|
27
|
-
return hashString([`v${SCRIPT_VERSION}`, briefing.context.localDate, briefing.remaining, ...parts].join('␞'));
|
|
27
|
+
return hashString([`v${SCRIPT_VERSION}`, briefing.context.localDate, briefing.remaining, briefing.unsure ?? 0, ...parts].join('␞'));
|
|
28
28
|
}
|
|
@@ -45,6 +45,8 @@ export interface BriefingDeps {
|
|
|
45
45
|
ownerSub: string;
|
|
46
46
|
/** The caller's open to-dos (any owner may be returned; the composer scopes to `ownerSub`). */
|
|
47
47
|
loadItems(): Promise<BriefingItem[]>;
|
|
48
|
+
/** How many clarifying questions are open; said as a pointer at the end. Omit for none. */
|
|
49
|
+
unsureCount?(): Promise<number>;
|
|
48
50
|
synthesize: BriefingSynthesize;
|
|
49
51
|
scriptLlm: BriefingScriptLlm | null;
|
|
50
52
|
audio: BriefingAudio;
|
|
@@ -91,7 +93,9 @@ export async function generateBriefing(deps: BriefingDeps, request: BriefingRequ
|
|
|
91
93
|
const ttl = Math.min(deps.audioTtlSeconds ?? DEFAULT_TTL, 600);
|
|
92
94
|
const store = deps.store ?? createEntityBriefingStore(deps.http, deps.ownerSub);
|
|
93
95
|
|
|
94
|
-
const
|
|
96
|
+
const composed = composeBriefing(await deps.loadItems(), { ownerSub: deps.ownerSub, now, timeZone });
|
|
97
|
+
const unsure = await deps.unsureCount?.().catch(() => 0) ?? 0;
|
|
98
|
+
const briefing = unsure > 0 ? { ...composed, unsure } : composed;
|
|
95
99
|
const hash = briefingContentHash(briefing);
|
|
96
100
|
const externalId = briefingExternalId(deps.ownerSub, briefing.context.localDate);
|
|
97
101
|
const stored = request.force ? null : await store.find(externalId);
|
|
@@ -105,6 +105,12 @@ function summaryLine(briefing: Briefing): string {
|
|
|
105
105
|
return `You have ${speakCount(n)} ${noun} on your plate today${tail}.`;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
/** "I am also unsure about two things. Say check in to go through them." Empty when nothing is open. */
|
|
109
|
+
export function unsurePointer(unsure: number | undefined): string {
|
|
110
|
+
if (!unsure || unsure < 1) return '';
|
|
111
|
+
return `I am also unsure about ${speakCount(unsure)} ${unsure === 1 ? 'thing' : 'things'}. Say check in to go through ${unsure === 1 ? 'it' : 'them'}.`;
|
|
112
|
+
}
|
|
113
|
+
|
|
108
114
|
function signOff(briefing: Briefing): string {
|
|
109
115
|
const n = briefing.remaining;
|
|
110
116
|
return n > 0 ? `And ${speakCount(n)} more after that.` : 'That is everything.';
|
|
@@ -127,6 +133,8 @@ function assemble(briefing: Briefing, options: BriefingScriptOptions, parts: Par
|
|
|
127
133
|
if (parts.lead) add(parts.lead, null);
|
|
128
134
|
for (const say of parts.says) add(say.text, say.id);
|
|
129
135
|
add(signOff(briefing), null);
|
|
136
|
+
const pointer = unsurePointer(briefing.unsure);
|
|
137
|
+
if (pointer) add(pointer, null);
|
|
130
138
|
return { text, segments, source, words: wordCount(text) };
|
|
131
139
|
}
|
|
132
140
|
|
|
@@ -145,8 +153,9 @@ export function templateScript(briefing: Briefing, options: BriefingScriptOption
|
|
|
145
153
|
|
|
146
154
|
// -- the model path -----------------------------------------------------------
|
|
147
155
|
|
|
148
|
-
function emptyScript(options: BriefingScriptOptions): BriefingScript {
|
|
149
|
-
const
|
|
156
|
+
function emptyScript(briefing: Briefing, options: BriefingScriptOptions): BriefingScript {
|
|
157
|
+
const pointer = unsurePointer(briefing.unsure);
|
|
158
|
+
const text = `${greeting(options)} Nothing is due today, and nothing is overdue. ${pointer || 'Enjoy the clear day.'}`;
|
|
150
159
|
return { text, segments: [], source: 'template', words: wordCount(text) };
|
|
151
160
|
}
|
|
152
161
|
|
|
@@ -202,7 +211,7 @@ export async function writeBriefingScript(
|
|
|
202
211
|
llm: BriefingScriptLlm | null,
|
|
203
212
|
options: BriefingScriptOptions,
|
|
204
213
|
): Promise<BriefingScript> {
|
|
205
|
-
if (briefing.empty) return emptyScript(options);
|
|
214
|
+
if (briefing.empty) return emptyScript(briefing, options);
|
|
206
215
|
if (llm) {
|
|
207
216
|
const ms = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
208
217
|
try {
|
|
@@ -71,3 +71,11 @@ export function partOfDay(instant: number, timeZone: string): 'morning' | 'after
|
|
|
71
71
|
if (hour < 12) return 'morning';
|
|
72
72
|
return hour < 17 ? 'afternoon' : 'evening';
|
|
73
73
|
}
|
|
74
|
+
|
|
75
|
+
/** Numeric dates inside a sentence said the way a person would (`due 2026-11-13 too` -> `due Friday the thirteenth too`). */
|
|
76
|
+
export function speakDatesIn(text: string, today: string): string {
|
|
77
|
+
return text.replace(/\b(\d{4})-(\d{2})-(\d{2})\b/g, (m, y, mo, d) => {
|
|
78
|
+
const month = Number(mo);
|
|
79
|
+
return month >= 1 && month <= 12 && Number(d) >= 1 && Number(d) <= 31 ? speakDate(m, today) : m;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* release of a held item go through the tenant PATCH (`patchItem`).
|
|
6
6
|
*/
|
|
7
7
|
import type { ItemEditSeam } from '../briefing/actions/types';
|
|
8
|
+
import { learnFromAnswer } from './learn';
|
|
8
9
|
import { close, listOpenQuestions, storeFor, type QuestionDeps } from './sync';
|
|
9
10
|
import type { OpenQuestion, QuestionAnswer } from './types';
|
|
10
11
|
|
|
@@ -16,6 +17,9 @@ export interface AnswerDeps extends QuestionDeps {
|
|
|
16
17
|
fileItem?(itemId: string, focusId: string | null): Promise<void>;
|
|
17
18
|
/** Save the tracker's personal container on the member's connection (central). */
|
|
18
19
|
setPersonalContainer?(containerId: string): Promise<void>;
|
|
20
|
+
/** Remember the answer as a habit (default on). */
|
|
21
|
+
learn?: boolean;
|
|
22
|
+
timeZone?: string;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
/** The fields that send a held item on its way. */
|
|
@@ -64,5 +68,11 @@ export async function answerQuestion(
|
|
|
64
68
|
await deps.patchItem(q.itemId, { owner_sub: value, owner_name: answer.label ?? '' });
|
|
65
69
|
break;
|
|
66
70
|
}
|
|
67
|
-
|
|
71
|
+
const closed = await close(store, q, 'resolved', 'answered', at, answer);
|
|
72
|
+
if (deps.learn !== false && (q.kind === 'project' || q.kind === 'due_date')) {
|
|
73
|
+
// Learning is a bonus: a failure here never undoes an answer that has already been applied.
|
|
74
|
+
const title = (await deps.seam.load(q.itemId).catch(() => null))?.title ?? '';
|
|
75
|
+
await learnFromAnswer(deps, { kind: q.kind, title, answer }).catch(() => undefined);
|
|
76
|
+
}
|
|
77
|
+
return closed;
|
|
68
78
|
}
|
|
@@ -21,3 +21,5 @@ export { composeCheckIn } from './checkin';
|
|
|
21
21
|
export type { CheckIn, CheckInEntry, CheckInOptions } from './checkin';
|
|
22
22
|
export { buildCheckIn } from './checkin-handle';
|
|
23
23
|
export type { CheckInResult } from './checkin-handle';
|
|
24
|
+
export { createPreferenceStore, learnFromAnswer, nextEvidence, decideFromHabits, PREFERENCE_ATTRIBUTES, PREFERENCE_LABEL, PREFERENCE_TYPE } from './learn';
|
|
25
|
+
export type { Preference, PreferenceKind } from './learn';
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LEARN FROM ANSWERS, AND USE WHAT WAS LEARNED BEFORE ASKING (bd startsim-tmrvi.6, tmrvi.2).
|
|
3
|
+
*
|
|
4
|
+
* Every answer is evidence. Words in a to-do's title that keep going to one project become a habit
|
|
5
|
+
* ("newsletter" -> Marketing after two alike); so does the usual due date (today, tomorrow, none) after
|
|
6
|
+
* three alike. A habit that AGREES with the guess Tandem is already acting on settles the question without
|
|
7
|
+
* asking, and the row says what decided it. A habit that disagrees, or none at all, still asks: nothing
|
|
8
|
+
* learned ever changes an item by itself.
|
|
9
|
+
*/
|
|
10
|
+
import type { CorpusHttp } from '../client';
|
|
11
|
+
import type { TenantEntity } from '../entities';
|
|
12
|
+
import { addDays, isIsoDate } from '../briefing/intent/dates';
|
|
13
|
+
import { contentWords } from '../briefing/intent/match';
|
|
14
|
+
import { localDate } from '../today';
|
|
15
|
+
import type { CorpusScope } from '../types';
|
|
16
|
+
import type { QuestionAnswer, QuestionKind } from './types';
|
|
17
|
+
|
|
18
|
+
export const PREFERENCE_TYPE = 'assistant_preference';
|
|
19
|
+
export const PREFERENCE_LABEL = 'Assistant preference';
|
|
20
|
+
export const PREFERENCE_ATTRIBUTES: Array<[string, string]> = [
|
|
21
|
+
['kind', 'text'], ['key', 'text'], ['value', 'text'], ['count', 'integer'], ['conflicts', 'integer'],
|
|
22
|
+
['owner_sub', 'text'], ['updated_at', 'date'],
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export type PreferenceKind = 'project_word' | 'due_offset';
|
|
26
|
+
/** Alike answers needed before a habit is trusted. */
|
|
27
|
+
const NEEDED: Record<PreferenceKind, number> = { project_word: 2, due_offset: 3 };
|
|
28
|
+
const MAX_WORDS = 6;
|
|
29
|
+
const ENTITIES = 'api/v1/entities';
|
|
30
|
+
|
|
31
|
+
export interface Evidence { value: string; count: number; conflicts: number }
|
|
32
|
+
export interface Preference extends Evidence { kind: PreferenceKind; key: string }
|
|
33
|
+
|
|
34
|
+
/** One more answer: agreement builds a habit, disagreement erodes it, a winning newcomer replaces it. */
|
|
35
|
+
export function nextEvidence(prev: Evidence | undefined, value: string): Evidence {
|
|
36
|
+
if (!prev) return { value, count: 1, conflicts: 0 };
|
|
37
|
+
if (prev.value === value) return { ...prev, count: prev.count + 1 };
|
|
38
|
+
const conflicts = prev.conflicts + 1;
|
|
39
|
+
return conflicts > prev.count ? { value, count: conflicts, conflicts: prev.count } : { ...prev, conflicts };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface LearnDeps {
|
|
43
|
+
http: CorpusHttp;
|
|
44
|
+
scope: CorpusScope;
|
|
45
|
+
ownerSub: string;
|
|
46
|
+
entitiesPath?: string;
|
|
47
|
+
now?: () => number;
|
|
48
|
+
timeZone?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const text = (v: unknown) => (typeof v === 'string' ? v : v == null ? '' : String(v));
|
|
52
|
+
const externalId = (owner: string, kind: string, key: string) => `pref:${owner}:${kind}:${key}`;
|
|
53
|
+
|
|
54
|
+
export function createPreferenceStore(deps: LearnDeps) {
|
|
55
|
+
const path = deps.entitiesPath ?? ENTITIES;
|
|
56
|
+
async function all(): Promise<Preference[]> {
|
|
57
|
+
const out: Preference[] = [];
|
|
58
|
+
for (let page = 1; page <= 20; page += 1) {
|
|
59
|
+
const res = await deps.http.get<{ results?: TenantEntity[]; next?: string | null }>(path, { params: { type: PREFERENCE_TYPE, page, page_size: 200 } });
|
|
60
|
+
for (const row of res.results ?? []) {
|
|
61
|
+
const d = (row.data ?? {}) as Record<string, unknown>;
|
|
62
|
+
if (text(d.owner_sub) !== deps.ownerSub) continue;
|
|
63
|
+
out.push({ kind: text(d.kind) as PreferenceKind, key: text(d.key), value: text(d.value), count: Number(d.count) || 0, conflicts: Number(d.conflicts) || 0 });
|
|
64
|
+
}
|
|
65
|
+
if (!res.next || !(res.results ?? []).length) break;
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
all,
|
|
71
|
+
async confident(kind: PreferenceKind, key: string): Promise<Preference | null> {
|
|
72
|
+
return confidentIn(await all(), kind, key);
|
|
73
|
+
},
|
|
74
|
+
async record(kind: PreferenceKind, key: string, value: string, existing?: Preference): Promise<void> {
|
|
75
|
+
if (!deps.http.post) return;
|
|
76
|
+
const e = nextEvidence(existing, value);
|
|
77
|
+
await deps.http.post(`${path}/upsert`, {
|
|
78
|
+
entity_type: PREFERENCE_TYPE, external_id: externalId(deps.ownerSub, kind, key), name: `${kind}: ${key}`,
|
|
79
|
+
data: { kind, key, value: e.value, count: e.count, conflicts: e.conflicts, owner_sub: deps.ownerSub, updated_at: new Date((deps.now ?? Date.now)()).toISOString() },
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function confidentIn(prefs: Preference[], kind: PreferenceKind, key: string): Preference | null {
|
|
86
|
+
const p = prefs.find((x) => x.kind === kind && x.key === key);
|
|
87
|
+
return p && p.conflicts === 0 && p.count >= NEEDED[kind] ? p : null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const titleWords = (title: string): string[] => [...new Set(contentWords(title).filter((w) => w.length >= 4))].slice(0, MAX_WORDS);
|
|
91
|
+
|
|
92
|
+
/** A due date as the habit it shows: days from today (`0`, `1`, ...), or `later` for none. */
|
|
93
|
+
export function dueOffset(value: string | null | undefined, now: number, timeZone: string): string | null {
|
|
94
|
+
if (value === '' || value === null || value === undefined) return value === '' ? 'later' : null;
|
|
95
|
+
const day = value.slice(0, 10);
|
|
96
|
+
if (!isIsoDate(day)) return null;
|
|
97
|
+
const today = localDate(now, timeZone);
|
|
98
|
+
let n = 0;
|
|
99
|
+
for (let cursor = today; cursor < day && n < 400; n += 1) cursor = addDays(cursor, 1);
|
|
100
|
+
return day < today ? null : String(n);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function learnFromAnswer(
|
|
104
|
+
deps: LearnDeps,
|
|
105
|
+
input: { kind: QuestionKind; title: string; answer: QuestionAnswer },
|
|
106
|
+
): Promise<void> {
|
|
107
|
+
const store = createPreferenceStore(deps);
|
|
108
|
+
const prefs = await store.all();
|
|
109
|
+
const find = (kind: PreferenceKind, key: string) => prefs.find((p) => p.kind === kind && p.key === key);
|
|
110
|
+
if (input.kind === 'project' && input.answer.value) {
|
|
111
|
+
for (const word of titleWords(input.title)) await store.record('project_word', word, input.answer.value, find('project_word', word));
|
|
112
|
+
} else if (input.kind === 'due_date') {
|
|
113
|
+
const offset = dueOffset(input.answer.value, (deps.now ?? Date.now)(), deps.timeZone ?? 'UTC');
|
|
114
|
+
if (offset) await store.record('due_offset', 'default', offset, find('due_offset', 'default'));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** What a learned habit says about a guess: `agrees` settles the question; otherwise it is asked as before. */
|
|
119
|
+
export function decideFromHabits(
|
|
120
|
+
input: { kind: QuestionKind; title: string; assumed?: { value: string | null } },
|
|
121
|
+
prefs: Preference[], now: number, timeZone: string,
|
|
122
|
+
): { agrees: true; evidence: string } | null {
|
|
123
|
+
const assumed = input.assumed?.value;
|
|
124
|
+
if (!assumed) return null;
|
|
125
|
+
if (input.kind === 'project') {
|
|
126
|
+
for (const word of titleWords(input.title)) {
|
|
127
|
+
const p = confidentIn(prefs, 'project_word', word);
|
|
128
|
+
if (p?.value === assumed) return { agrees: true, evidence: `${word} -> ${assumed} (${p.count} alike)` };
|
|
129
|
+
}
|
|
130
|
+
} else if (input.kind === 'due_date') {
|
|
131
|
+
const p = confidentIn(prefs, 'due_offset', 'default');
|
|
132
|
+
if (p && dueOffset(assumed, now, timeZone) === p.value) return { agrees: true, evidence: `usual due date ${p.value} (${p.count} alike)` };
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
@@ -6,6 +6,7 @@ import type { CorpusHttp } from '../client';
|
|
|
6
6
|
import type { CorpusScope } from '../types';
|
|
7
7
|
import { CLOSED_STATUSES, deriveQuestions, scoreOf } from './derive';
|
|
8
8
|
import { readItemViews, readVoiceRecords } from './items';
|
|
9
|
+
import { createPreferenceStore, decideFromHabits } from './learn';
|
|
9
10
|
import { createQuestionStore } from './store';
|
|
10
11
|
import type { ItemView, OpenQuestion, QuestionResolution } from './types';
|
|
11
12
|
|
|
@@ -16,6 +17,8 @@ export interface QuestionDeps {
|
|
|
16
17
|
ownerSub: string;
|
|
17
18
|
entitiesPath?: string;
|
|
18
19
|
now?: () => number;
|
|
20
|
+
/** The listener's zone: "today" in a habit is theirs. */
|
|
21
|
+
timeZone?: string;
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
const ENTITIES = 'api/v1/entities';
|
|
@@ -24,7 +27,7 @@ const key = (itemId: string, kind: string) => `${itemId}:${kind}`;
|
|
|
24
27
|
export const storeFor = (deps: QuestionDeps) =>
|
|
25
28
|
createQuestionStore({ http: deps.http, ownerSub: deps.ownerSub, entitiesPath: deps.entitiesPath ?? ENTITIES });
|
|
26
29
|
|
|
27
|
-
export async function syncOpenQuestions(deps: QuestionDeps): Promise<{ opened: number; resolved: number; expired: number }> {
|
|
30
|
+
export async function syncOpenQuestions(deps: QuestionDeps): Promise<{ opened: number; resolved: number; expired: number; decidedByContext: number }> {
|
|
28
31
|
const path = deps.entitiesPath ?? ENTITIES;
|
|
29
32
|
const iso = () => new Date((deps.now ?? Date.now)()).toISOString();
|
|
30
33
|
const store = storeFor(deps);
|
|
@@ -36,7 +39,8 @@ export async function syncOpenQuestions(deps: QuestionDeps): Promise<{ opened: n
|
|
|
36
39
|
const derived = deriveQuestions(items, notes);
|
|
37
40
|
const existing = new Map((await store.all()).map((q) => [key(q.itemId, q.kind), q]));
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
const prefs = await createPreferenceStore(deps).all().catch(() => []);
|
|
43
|
+
let opened = 0, resolved = 0, expired = 0, decidedByContext = 0;
|
|
40
44
|
const wanted = new Set<string>();
|
|
41
45
|
|
|
42
46
|
for (const d of derived) {
|
|
@@ -50,6 +54,18 @@ export async function syncOpenQuestions(deps: QuestionDeps): Promise<{ opened: n
|
|
|
50
54
|
candidates: JSON.stringify(d.candidates),
|
|
51
55
|
...(d.noteId ? { note_id: d.noteId } : {}),
|
|
52
56
|
};
|
|
57
|
+
if (!have && d.assumed) {
|
|
58
|
+
// Context first: a learned habit that agrees with the guess settles it, and the row says why.
|
|
59
|
+
const hit = decideFromHabits({ kind: d.kind, title: byId.get(d.itemId)?.title ?? '', assumed: d.assumed }, prefs, (deps.now ?? Date.now)(), deps.timeZone ?? 'UTC');
|
|
60
|
+
if (hit) {
|
|
61
|
+
await store.put(d.itemId, d.kind, d.question, {
|
|
62
|
+
...body, status: 'resolved', resolution: 'context', resolved_at: iso(), created_at: iso(), updated_at: iso(),
|
|
63
|
+
answer: JSON.stringify({ value: d.assumed.value ?? '', label: `learned: ${hit.evidence}` }),
|
|
64
|
+
});
|
|
65
|
+
decidedByContext += 1;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
53
69
|
if (!have) {
|
|
54
70
|
await store.put(d.itemId, d.kind, d.question, { ...body, status: 'open', created_at: iso(), updated_at: iso() });
|
|
55
71
|
opened += 1;
|
|
@@ -70,7 +86,7 @@ export async function syncOpenQuestions(deps: QuestionDeps): Promise<{ opened: n
|
|
|
70
86
|
await close(store, q, item ? (resolution === 'item_closed' ? 'expired' : 'resolved') : 'expired', resolution, iso());
|
|
71
87
|
if (resolution === 'item_changed') resolved += 1; else expired += 1;
|
|
72
88
|
}
|
|
73
|
-
return { opened, resolved, expired };
|
|
89
|
+
return { opened, resolved, expired, decidedByContext };
|
|
74
90
|
}
|
|
75
91
|
|
|
76
92
|
export async function close(
|
|
@@ -13,7 +13,7 @@ export type QuestionKind = (typeof QUESTION_KINDS)[number];
|
|
|
13
13
|
export type QuestionStatus = 'open' | 'resolved' | 'expired';
|
|
14
14
|
|
|
15
15
|
/** Why a question left the queue. */
|
|
16
|
-
export type QuestionResolution = 'answered' | 'skipped' | 'item_changed' | 'item_closed' | 'item_gone';
|
|
16
|
+
export type QuestionResolution = 'answered' | 'skipped' | 'context' | 'item_changed' | 'item_closed' | 'item_gone';
|
|
17
17
|
|
|
18
18
|
export interface AssumedValue {
|
|
19
19
|
value: string | null;
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
import { speakConfirmation } from '../briefing/actions/confirm';
|
|
13
13
|
import type { ActionLog, ActionLogStore, PendingReply } from '../briefing/actions/types';
|
|
14
14
|
import type { BriefingAudio, BriefingSynthesize } from '../briefing/generate';
|
|
15
|
-
import { speakable } from '../briefing/speak';
|
|
15
|
+
import { speakDatesIn, speakable } from '../briefing/speak';
|
|
16
|
+
import { localDate } from '../today';
|
|
16
17
|
import { answerQuestion, type AnswerDeps } from './answer';
|
|
17
18
|
import { close, listOpenQuestions, storeFor } from './sync';
|
|
18
19
|
import type { OpenQuestion, QuestionAnswer } from './types';
|
|
@@ -78,9 +79,10 @@ export function validateAnswerRequest(req: VoiceAnswerRequest): void {
|
|
|
78
79
|
if (req.audio && req.audio.audio.byteLength > MAX_ANSWER_AUDIO_BYTES) throw new VoiceAnswerError('That recording is too long for an answer.', 413);
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
const asks = (q: OpenQuestion, title: string) => {
|
|
82
|
+
const asks = (q: OpenQuestion, title: string, today: string) => {
|
|
82
83
|
const t = speakable(title, 10);
|
|
83
|
-
|
|
84
|
+
const question = speakDatesIn(q.question, today);
|
|
85
|
+
return t ? `About ${t}: ${question}` : question;
|
|
84
86
|
};
|
|
85
87
|
|
|
86
88
|
async function titleOf(deps: VoiceAnswerDeps, q: OpenQuestion): Promise<string> {
|
|
@@ -166,7 +168,7 @@ export async function answerQuestionByVoice(deps: VoiceAnswerDeps, req: VoiceAns
|
|
|
166
168
|
): Promise<VoiceAnswerResult> => {
|
|
167
169
|
const remainingQs = (await listOpenQuestions(deps)).filter((q) => q.id !== answered?.id || kind === 'undone');
|
|
168
170
|
const next = asked ?? (kind === 'clarify' ? null : remainingQs.find((q) => q.id !== answered?.id) ?? null);
|
|
169
|
-
const tail = kind === 'clarify' ? '' : next ? ` ${asks(next, await titleOf(deps, next))}` : ' That is everything for now.';
|
|
171
|
+
const tail = kind === 'clarify' ? '' : next ? ` ${asks(next, await titleOf(deps, next), localDate(now, timeZone))}` : ' That is everything for now.';
|
|
170
172
|
const spoken = `${lead}${tail}`.trim();
|
|
171
173
|
const said = await speakConfirmation({
|
|
172
174
|
text: spoken, clientActionId: id, synthesize: deps.synthesize,
|
package/src/corpus/voice-due.ts
CHANGED
|
@@ -124,6 +124,20 @@ function fmtCandidate(c: { date: string; time?: string }): string {
|
|
|
124
124
|
return c.time ? `${c.date} ${c.time}` : c.date;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
/** Words that carry no task of their own (as `stem` cuts them). */
|
|
128
|
+
const FILLER = new Set(['the', 'and', 'but', 'for', 'you', 'all', 'oh', 'ok', 'okay', 'also', 'need', 'have', 'has', 'got', 'must', 'should', 'will', 'then', 'now', 'just', 'some', 'one', 'out', 'get', 'its', 'are', 'was', 'that', 'this', 'with', 'from', 'to', 'by', 'of', 'on', 'in', 'my', 'me', 'it', 'is', 'an', 'at', 'as', 'be', 'do', 'so', 'we', 'quick', 'thing', 'items', 'stuff', 'todos', 'tasks', 'these', 'those', 'every', 'anyth', 'today', 'tomor', 'soon', 'later', 'week', 'weeke', 'next', 'this', 'after', 'befor', 'somebo', 'somet', 'brain', 'dump', 'list']);
|
|
129
|
+
|
|
130
|
+
/** True when the sentence that holds `said` is about some other to-do (two or more words of its own, none of this item's). */
|
|
131
|
+
function saidAboutAnother(said: string, title: string, transcript: string): boolean {
|
|
132
|
+
const needle = said.toLowerCase();
|
|
133
|
+
const sentence = transcript.split(/(?<=[.!?])\s+/).find((t) => t.toLowerCase().includes(needle));
|
|
134
|
+
if (!sentence) return false;
|
|
135
|
+
const own = new Set(title.split(/\s+/).map(stem));
|
|
136
|
+
const words = [...new Set(sentence.replace(new RegExp(said.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i'), ' ').split(/\s+/).map(stem))]
|
|
137
|
+
.filter((w) => w.length >= 3 && !STOP.has(w) && !FILLER.has(w));
|
|
138
|
+
return words.length >= 2 && !words.some((w) => own.has(w));
|
|
139
|
+
}
|
|
140
|
+
|
|
127
141
|
function dueGuess(item: VoiceItem, section: VoiceSection, ctx: DueContext): { due: FieldGuess<string>; priority?: number } {
|
|
128
142
|
const resolve = (text: string | undefined) => (text ? resolveSpokenTime(text, ctx) : null);
|
|
129
143
|
const sentence = evidenceSentence(item.title, ctx.transcript);
|
|
@@ -136,12 +150,12 @@ function dueGuess(item: VoiceItem, section: VoiceSection, ctx: DueContext): { du
|
|
|
136
150
|
const itemLevel = modelWhen?.kind === 'unscheduled' && !heardOpen ? null : modelWhen;
|
|
137
151
|
|
|
138
152
|
// Most specific first. Each level is [text, how it counts, source].
|
|
139
|
-
const levels: Array<{ res: SpokenTime | null; source: 'stated' | 'assumed'; cap: number; where: string }> = [
|
|
153
|
+
const levels: Array<{ res: SpokenTime | null; source: 'stated' | 'assumed'; cap: number; where: string; said?: string }> = [
|
|
140
154
|
{ res: itemLevel, source: 'stated', cap: 1, where: 'the speaker' },
|
|
141
155
|
{ res: resolve(item.title), source: 'stated', cap: 1, where: 'the item' },
|
|
142
156
|
{ res: sentence ? resolve(sentence) : null, source: 'stated', cap: 0.9, where: 'the sentence it came from' },
|
|
143
|
-
{ res: resolve(section.when), source: 'assumed', cap: 0.75, where: 'the section' },
|
|
144
|
-
{ res: resolve(ctx.noteWhen), source: 'assumed', cap: 0.75, where: 'the note' },
|
|
157
|
+
{ res: resolve(section.when), source: 'assumed', cap: 0.75, where: 'the section', said: section.when },
|
|
158
|
+
{ res: resolve(ctx.noteWhen), source: 'assumed', cap: 0.75, where: 'the note', said: ctx.noteWhen },
|
|
145
159
|
{ res: noteWideWhen(ctx.transcript, ctx), source: 'assumed', cap: 0.6, where: 'the plan for the day' },
|
|
146
160
|
];
|
|
147
161
|
|
|
@@ -159,9 +173,20 @@ function dueGuess(item: VoiceItem, section: VoiceSection, ctx: DueContext): { du
|
|
|
159
173
|
const reason = level.source === 'assumed' ? `${level.where === 'the plan for the day' ? 'the plan for the day' : `${res.phrase} (${level.where})`}` : res.reason;
|
|
160
174
|
const candidates = res.candidates.map((c) => ({ value: c.dueAt, confidence: c.score, reason: c.reason }));
|
|
161
175
|
const gap = res.candidates.length > 1 ? res.candidates[0].score - res.candidates[1].score : 1;
|
|
162
|
-
|
|
176
|
+
let question = gap < AMBIGUITY_GAP
|
|
163
177
|
? `Due ${fmtCandidate(res.candidates[0])} or ${fmtCandidate(res.candidates[1])}?`
|
|
164
178
|
: undefined;
|
|
179
|
+
// A date the speaker tied to ANOTHER item, carried here by the note-level "when": a doubtful guess, so ask.
|
|
180
|
+
if (level.source === 'assumed' && level.said && saidAboutAnother(level.said, item.title, ctx.transcript)) {
|
|
181
|
+
const shown = res.time ? `${res.date} ${res.time}` : res.date;
|
|
182
|
+
return {
|
|
183
|
+
due: guessOf(res.dueAt as string, Math.min(confidence, 0.5), 'assumed', `${res.phrase} was said about another item`, {
|
|
184
|
+
candidates: [{ value: res.dueAt as string, confidence: 0.5, reason }, { value: '', confidence: 0.45, reason: 'nothing was said about when for this one' }],
|
|
185
|
+
question: `Is "${item.title}" due ${shown} too, or does it have no date?`, display,
|
|
186
|
+
}),
|
|
187
|
+
priority: res.priority,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
165
190
|
return {
|
|
166
191
|
due: guessOf(res.dueAt as string, confidence, level.source, reason, { candidates, question, display }),
|
|
167
192
|
priority: res.priority,
|