@startsimpli/integrations 0.2.197 → 0.2.200
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 +4 -4
- package/src/__tests__/corpus-ask-items.test.ts +14 -0
- package/src/__tests__/spoken-time.test.ts +4 -0
- package/src/__tests__/voice-due-later-sentence.test.ts +26 -0
- package/src/corpus/ask-items-intent.ts +24 -0
- package/src/corpus/spoken-time.ts +18 -2
- package/src/corpus/voice-due.ts +24 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.200",
|
|
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,9 +50,9 @@
|
|
|
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/auth": "^0.4.53",
|
|
53
54
|
"@startsimpli/utils": "^0.4.20",
|
|
54
|
-
"@startsimpli/ui": "^0.4.
|
|
55
|
-
"@startsimpli/auth": "^0.4.53"
|
|
55
|
+
"@startsimpli/ui": "^0.4.192"
|
|
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.192",
|
|
103
103
|
"@startsimpli/ui-native": "0.1.15",
|
|
104
104
|
"@startsimpli/auth": "0.4.53",
|
|
105
105
|
"@startsimpli/utils": "0.4.20"
|
|
@@ -53,6 +53,20 @@ describe('itemIntent', () => {
|
|
|
53
53
|
const i = itemIntent('what did I commit to this week?', NOW)!;
|
|
54
54
|
expect([i.focus, i.from, i.to, i.mine]).toEqual(['committed', '2026-11-09', '2026-11-15', true]);
|
|
55
55
|
});
|
|
56
|
+
it('reads a month name as that whole month', () => {
|
|
57
|
+
const i = itemIntent('What is due in December?', NOW)!;
|
|
58
|
+
expect([i.focus, i.from, i.to]).toEqual(['due', '2026-12-01', '2026-12-31']);
|
|
59
|
+
expect(itemIntent('what is due in February 2027', NOW)!.to).toBe('2027-02-28');
|
|
60
|
+
});
|
|
61
|
+
it('reads a month already passed this year as next year, and the current month whole', () => {
|
|
62
|
+
expect(itemIntent('what is due in March', NOW)!.from).toBe('2027-03-01');
|
|
63
|
+
const nov = itemIntent('what is due in November', NOW)!;
|
|
64
|
+
expect([nov.from, nov.to]).toEqual(['2026-11-01', '2026-11-30']);
|
|
65
|
+
});
|
|
66
|
+
it('reads next month', () => {
|
|
67
|
+
const i = itemIntent('what is due next month', NOW)!;
|
|
68
|
+
expect([i.from, i.to]).toEqual(['2026-12-01', '2026-12-31']);
|
|
69
|
+
});
|
|
56
70
|
it('uses the reader zone for today', () => {
|
|
57
71
|
expect(itemIntent('what is overdue', Date.parse('2026-11-12T02:00:00Z'), 'America/New_York')!.today).toBe('2026-11-11');
|
|
58
72
|
});
|
|
@@ -37,6 +37,10 @@ describe('resolveSpokenTime', () => {
|
|
|
37
37
|
['by the end of the month', '2026-11-30'],
|
|
38
38
|
['on November 20', '2026-11-20'],
|
|
39
39
|
['by the 20th', '2026-11-20'],
|
|
40
|
+
['due on the fifteenth', '2026-11-15'],
|
|
41
|
+
['by the twenty-first', '2026-11-21'],
|
|
42
|
+
['on the third', '2026-12-03'],
|
|
43
|
+
['the thirtieth', '2026-11-30'],
|
|
40
44
|
['ASAP', '2026-11-06'],
|
|
41
45
|
['right away', '2026-11-06'],
|
|
42
46
|
['sometime in the next few hours', '2026-11-06'],
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A date stated in a LATER sentence about the same thing belongs to that item (bd startsim-tmrvi.23, found in the
|
|
3
|
+
* tmrvi.8 measurement): "Today I have to pay the AWS bill. The AWS bill is due on the fifteenth." was acted on as today.
|
|
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 = 'Today I have to call the vet and pay the AWS bill. The AWS bill is due on the fifteenth. Also fix the login bug.';
|
|
11
|
+
const ctx = { now: Date.parse('2026-11-09T17:00:00Z'), timeZone: 'America/Boise', transcript: TRANSCRIPT, noteWhen: 'today' };
|
|
12
|
+
const section: VoiceSection = { label: 'Work', kind: 'other', focusId: null, items: [], when: 'today' } as never;
|
|
13
|
+
const item = (title: string, when?: string): VoiceItem => ({ title, ...(when ? { when } : {}) });
|
|
14
|
+
|
|
15
|
+
describe('a date stated in a later sentence about the item', () => {
|
|
16
|
+
it('is the item\'s due date, stated, not the day of the note', () => {
|
|
17
|
+
const f = resolveItemFields(item('Pay the AWS bill'), section, ctx);
|
|
18
|
+
expect(f.due.value).toBe('2026-11-15');
|
|
19
|
+
expect(f.due.source).toBe('stated');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('does not reach items the sentence is not about', () => {
|
|
23
|
+
const f = resolveItemFields(item('Fix the login bug'), section, ctx);
|
|
24
|
+
expect(f.due.value).not.toBe('2026-11-15');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -32,6 +32,13 @@ export const addDays = (day: string, n: number): string => {
|
|
|
32
32
|
d.setUTCDate(d.getUTCDate() + n);
|
|
33
33
|
return d.toISOString().slice(0, 10);
|
|
34
34
|
};
|
|
35
|
+
const MONTHS = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
|
|
36
|
+
const monthBounds = (year: number, month0: number): { from: string; to: string } => {
|
|
37
|
+
const mm = String(month0 + 1).padStart(2, '0');
|
|
38
|
+
const first = `${year}-${mm}-01`;
|
|
39
|
+
const lastDay = new Date(Date.UTC(year, month0 + 1, 0)).getUTCDate();
|
|
40
|
+
return { from: first, to: `${year}-${mm}-${String(lastDay).padStart(2, '0')}` };
|
|
41
|
+
};
|
|
35
42
|
const weekdayOf = (day: string): number => new Date(`${day}T00:00:00Z`).getUTCDay();
|
|
36
43
|
|
|
37
44
|
/** Monday-first week containing `day`. */
|
|
@@ -41,6 +48,14 @@ function weekOf(day: string): { from: string; to: string } {
|
|
|
41
48
|
return { from, to: addDays(from, 6) };
|
|
42
49
|
}
|
|
43
50
|
|
|
51
|
+
/** A month name with an optional year ("in december", "february 2027"); "may" only after in/during/of. */
|
|
52
|
+
function monthNamed(q: string): { index: number; year?: number } | null {
|
|
53
|
+
const m = q.match(new RegExp(`\\b(?:(?:in|during|of|for|by)\\s+)?(${MONTHS.join('|')})\\b(?:\\s+(20\\d{2}))?`));
|
|
54
|
+
if (!m) return null;
|
|
55
|
+
if (m[1] === 'may' && !/\b(?:in|during|of|for|by)\s+may\b/.test(q)) return null;
|
|
56
|
+
return { index: MONTHS.indexOf(m[1]), ...(m[2] ? { year: Number(m[2]) } : {}) };
|
|
57
|
+
}
|
|
58
|
+
|
|
44
59
|
/** The calendar window a question names ("yesterday", "last week", "this month"), in the reader's zone, or null. */
|
|
45
60
|
export function questionWindow(question: string, now: number, timeZone = 'UTC'): { from: string; to: string; label: string } | null {
|
|
46
61
|
const q = question.toLowerCase();
|
|
@@ -53,6 +68,15 @@ export function questionWindow(question: string, now: number, timeZone = 'UTC'):
|
|
|
53
68
|
else if (/\bthis week\b|\bthe week\b/.test(q)) { const w = weekOf(today); set(w.from, w.to, 'this week'); }
|
|
54
69
|
else if (/\blast month\b/.test(q)) { const first = `${today.slice(0, 8)}01`; const end = addDays(first, -1); set(`${end.slice(0, 8)}01`, end, 'last month'); }
|
|
55
70
|
else if (/\bthis month\b/.test(q)) set(`${today.slice(0, 8)}01`, today, 'this month');
|
|
71
|
+
else if (/\bnext month\b/.test(q)) { const m = monthBounds(Number(today.slice(0, 4)), Number(today.slice(5, 7))); set(m.from, m.to, 'next month'); }
|
|
72
|
+
else if (monthNamed(q)) {
|
|
73
|
+
// "in December", "in February 2027". A bare month already past this year means the coming one.
|
|
74
|
+
const { index, year } = monthNamed(q)!;
|
|
75
|
+
const thisYear = Number(today.slice(0, 4));
|
|
76
|
+
const y = year ?? (index >= Number(today.slice(5, 7)) - 1 ? thisYear : thisYear + 1);
|
|
77
|
+
const m = monthBounds(y, index);
|
|
78
|
+
set(m.from, m.to, `${MONTHS[index][0].toUpperCase()}${MONTHS[index].slice(1)} ${y}`);
|
|
79
|
+
}
|
|
56
80
|
else if (/\btomorrow\b/.test(q)) set(addDays(today, 1), addDays(today, 1), 'tomorrow');
|
|
57
81
|
else if (/\btoday\b/.test(q)) set(today, today, 'today');
|
|
58
82
|
else if (/\byesterday\b/.test(q)) set(addDays(today, -1), addDays(today, -1), 'yesterday');
|
|
@@ -191,8 +191,8 @@ function findDay(text: string, today: string, wd: number, ctx: { now: number; ti
|
|
|
191
191
|
return hit(`${year}-${pad(month)}-${pad(day)}`, m[0], 0.95, 'exact', `said "${m[0]}"`);
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
if ((m =
|
|
195
|
-
const day =
|
|
194
|
+
if ((m = new RegExp(`\\bthe (\\d{1,2}(?:st|nd|rd|th)|${ORDINAL_WORD})\\b`, 'i').exec(text))) {
|
|
195
|
+
const day = ordinalDay(m[1]);
|
|
196
196
|
if (day >= 1 && day <= 31) {
|
|
197
197
|
let [y, mo] = [ty, tm];
|
|
198
198
|
if (`${y}-${pad(mo)}-${pad(day)}` < today) { mo += 1; if (mo > 12) { mo = 1; y += 1; } }
|
|
@@ -204,6 +204,22 @@ function findDay(text: string, today: string, wd: number, ctx: { now: number; ti
|
|
|
204
204
|
return null;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
const ORD_UNITS: Record<string, number> = { first: 1, second: 2, third: 3, fourth: 4, fifth: 5, sixth: 6, seventh: 7, eighth: 8, ninth: 9 };
|
|
208
|
+
const ORD_TEENS: Record<string, number> = {
|
|
209
|
+
tenth: 10, eleventh: 11, twelfth: 12, thirteenth: 13, fourteenth: 14, fifteenth: 15, sixteenth: 16, seventeenth: 17,
|
|
210
|
+
eighteenth: 18, nineteenth: 19, twentieth: 20, thirtieth: 30,
|
|
211
|
+
};
|
|
212
|
+
/** "fifteenth", "twenty-first" (or "twenty first"): the spoken form a transcript writes for a day of the month. */
|
|
213
|
+
const ORDINAL_WORD = `(?:(?:twenty|thirty)[- ](?:${Object.keys(ORD_UNITS).join('|')})|${Object.keys(ORD_TEENS).join('|')}|${Object.keys(ORD_UNITS).join('|')})`;
|
|
214
|
+
|
|
215
|
+
function ordinalDay(token: string): number {
|
|
216
|
+
const t = token.toLowerCase();
|
|
217
|
+
if (/^\d/.test(t)) return Number(t.replace(/\D/g, ''));
|
|
218
|
+
const [head, tail] = t.split(/[- ]/);
|
|
219
|
+
if (tail !== undefined) return (head === 'twenty' ? 20 : 30) + ORD_UNITS[tail];
|
|
220
|
+
return ORD_TEENS[t] ?? ORD_UNITS[t];
|
|
221
|
+
}
|
|
222
|
+
|
|
207
223
|
interface TimeHit { time: string; phrase: string; score: number; confidence: SpokenConfidence; alt?: string }
|
|
208
224
|
|
|
209
225
|
function findClock(text: string): TimeHit | null {
|
package/src/corpus/voice-due.ts
CHANGED
|
@@ -138,6 +138,29 @@ function saidAboutAnother(said: string, title: string, transcript: string): bool
|
|
|
138
138
|
return words.length >= 2 && !words.some((w) => own.has(w));
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
/**
|
|
142
|
+
* A date stated in ANOTHER sentence about the same thing: "...pay the AWS bill. The AWS bill is due on the fifteenth."
|
|
143
|
+
* `evidenceSentence` needs two long content words, which a short title ("Pay the AWS bill") does not have, so this
|
|
144
|
+
* looks at every sentence that shares ALL of the title's distinctive words (or two of them) and states a date of its
|
|
145
|
+
* own. An explicit date beats a day-plan ("today"), which is why it is picked over the sentence the item came from.
|
|
146
|
+
*/
|
|
147
|
+
function datedSentenceTime(title: string, transcript: string, ctx: DueContext): SpokenTime | null {
|
|
148
|
+
const words = [...new Set(title.split(/\s+/).map(stem).filter((w) => w.length >= 3 && !STOP.has(w) && !FILLER.has(w)))];
|
|
149
|
+
if (words.length === 0) return null;
|
|
150
|
+
const need = Math.min(2, words.length);
|
|
151
|
+
const today = resolveSpokenTime('today', ctx)?.date;
|
|
152
|
+
let fallback: SpokenTime | null = null;
|
|
153
|
+
for (const text of transcript.split(/(?<=[.!?])\s+/)) {
|
|
154
|
+
const have = new Set(text.split(/\s+/).map(stem));
|
|
155
|
+
if (words.filter((w) => have.has(w)).length < need) continue;
|
|
156
|
+
const res = resolveSpokenTime(text, ctx);
|
|
157
|
+
if (!res || res.kind !== 'dated') continue;
|
|
158
|
+
if (res.date !== today) return res;
|
|
159
|
+
fallback ??= res;
|
|
160
|
+
}
|
|
161
|
+
return fallback;
|
|
162
|
+
}
|
|
163
|
+
|
|
141
164
|
function dueGuess(item: VoiceItem, section: VoiceSection, ctx: DueContext): { due: FieldGuess<string>; priority?: number } {
|
|
142
165
|
const resolve = (text: string | undefined) => (text ? resolveSpokenTime(text, ctx) : null);
|
|
143
166
|
const sentence = evidenceSentence(item.title, ctx.transcript);
|
|
@@ -153,6 +176,7 @@ function dueGuess(item: VoiceItem, section: VoiceSection, ctx: DueContext): { du
|
|
|
153
176
|
const levels: Array<{ res: SpokenTime | null; source: 'stated' | 'assumed'; cap: number; where: string; said?: string }> = [
|
|
154
177
|
{ res: itemLevel, source: 'stated', cap: 1, where: 'the speaker' },
|
|
155
178
|
{ res: resolve(item.title), source: 'stated', cap: 1, where: 'the item' },
|
|
179
|
+
{ res: datedSentenceTime(item.title, ctx.transcript, ctx), source: 'stated', cap: 0.9, where: 'a sentence about it' },
|
|
156
180
|
{ res: sentence ? resolve(sentence) : null, source: 'stated', cap: 0.9, where: 'the sentence it came from' },
|
|
157
181
|
{ res: resolve(section.when), source: 'assumed', cap: 0.75, where: 'the section', said: section.when },
|
|
158
182
|
{ res: resolve(ctx.noteWhen), source: 'assumed', cap: 0.75, where: 'the note', said: ctx.noteWhen },
|