@startsimpli/integrations 0.2.157 → 0.2.160
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-weekly.test.ts +80 -0
- package/src/__tests__/corpus-ask-items.test.ts +108 -0
- package/src/__tests__/home-brief.test.tsx +10 -0
- package/src/__tests__/home-needs-your-call.test.tsx +68 -0
- package/src/__tests__/needs-your-call.test.tsx +151 -0
- package/src/__tests__/question-inbox.test.ts +51 -0
- package/src/components/index.ts +1 -0
- package/src/components/pages/AskPage.tsx +12 -2
- package/src/components/pages/home/BriefCard.tsx +31 -12
- package/src/components/pages/home/CompactItemRow.tsx +12 -2
- package/src/components/pages/home/DueAcrossProjects.tsx +4 -2
- package/src/components/pages/home/HomeBriefPage.tsx +32 -3
- package/src/components/pages/questions/NeedsYourCall.tsx +128 -0
- package/src/components/pages/questions/QuestionRow.tsx +78 -0
- package/src/components/pages/questions/index.ts +3 -0
- package/src/components/pages/questions/types.ts +36 -0
- package/src/corpus/ask-items-intent.ts +75 -0
- package/src/corpus/ask-items.ts +100 -0
- package/src/corpus/ask.ts +48 -5
- package/src/corpus/briefing/generate-weekly.ts +89 -0
- package/src/corpus/briefing/index.ts +5 -1
- package/src/corpus/briefing/respond.ts +11 -3
- package/src/corpus/briefing/types.ts +2 -0
- package/src/corpus/briefing/weekly.ts +155 -0
- package/src/corpus/index.ts +3 -0
- package/src/corpus/questions/inbox.ts +108 -0
- package/src/corpus/questions/index.ts +2 -0
- package/src/corpus/questions/types.ts +2 -0
- package/src/corpus/types.ts +4 -0
|
@@ -11,19 +11,35 @@ import * as React from 'react';
|
|
|
11
11
|
|
|
12
12
|
import type { BriefingResult } from '../../../corpus/briefing';
|
|
13
13
|
|
|
14
|
+
/** What the card shows: the daily briefing's result or the weekly summary's. */
|
|
15
|
+
export type BriefCardResult = Pick<BriefingResult, 'text' | 'audioUrl'> & { audioReason?: string; remaining?: number };
|
|
16
|
+
|
|
14
17
|
export interface BriefCardApi {
|
|
15
18
|
/** POST /corpus/briefing: cached per person per day on the server. */
|
|
16
|
-
fetch(): Promise<
|
|
19
|
+
fetch(): Promise<BriefCardResult>;
|
|
17
20
|
/** An object URL (or any playable URL) for the briefing's audio, fetched with the caller's credentials. */
|
|
18
|
-
loadAudio?(result:
|
|
21
|
+
loadAudio?(result: BriefCardResult): Promise<string | null>;
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
type State =
|
|
24
|
+
type State =
|
|
25
|
+
| { phase: 'idle' }
|
|
26
|
+
| { phase: 'loading' }
|
|
27
|
+
| { phase: 'error'; message: string }
|
|
28
|
+
| { phase: 'ready'; result: BriefCardResult };
|
|
29
|
+
|
|
30
|
+
export interface BriefCardProps {
|
|
31
|
+
api: BriefCardApi;
|
|
32
|
+
onAsk?: () => void;
|
|
33
|
+
/** Heading, default "Today’s brief". */
|
|
34
|
+
title?: string;
|
|
35
|
+
/** Wait for a tap instead of loading on mount (the weekly summary: it costs a voice the first time). */
|
|
36
|
+
onDemand?: boolean;
|
|
37
|
+
}
|
|
22
38
|
|
|
23
|
-
export function BriefCard({ api, onAsk
|
|
39
|
+
export function BriefCard({ api, onAsk, title = 'Today’s brief', onDemand = false }: BriefCardProps) {
|
|
24
40
|
const apiRef = React.useRef(api);
|
|
25
41
|
apiRef.current = api;
|
|
26
|
-
const [state, setState] = React.useState<State>({ phase: 'loading' });
|
|
42
|
+
const [state, setState] = React.useState<State>(onDemand ? { phase: 'idle' } : { phase: 'loading' });
|
|
27
43
|
const [playing, setPlaying] = React.useState(false);
|
|
28
44
|
const [audioError, setAudioError] = React.useState('');
|
|
29
45
|
const audio = React.useRef<HTMLAudioElement | null>(null);
|
|
@@ -33,16 +49,16 @@ export function BriefCard({ api, onAsk }: { api: BriefCardApi; onAsk?: () => voi
|
|
|
33
49
|
try { setState({ phase: 'ready', result: await apiRef.current.fetch() }); }
|
|
34
50
|
catch (err) { setState({ phase: 'error', message: (err as Error)?.message || 'The brief could not be loaded.' }); }
|
|
35
51
|
}, []);
|
|
36
|
-
React.useEffect(() => { void load(); }, [load]);
|
|
52
|
+
React.useEffect(() => { if (!onDemand) void load(); }, [load, onDemand]);
|
|
37
53
|
React.useEffect(() => () => { audio.current?.pause(); }, []);
|
|
38
54
|
|
|
39
|
-
const play = async (result:
|
|
55
|
+
const play = async (result: BriefCardResult) => {
|
|
40
56
|
setAudioError('');
|
|
41
57
|
if (playing) { audio.current?.pause(); setPlaying(false); return; }
|
|
42
58
|
try {
|
|
43
59
|
if (!audio.current) {
|
|
44
60
|
const url = await apiRef.current.loadAudio?.(result);
|
|
45
|
-
if (!url) { setAudioError(result.audioReason || 'There is no audio for
|
|
61
|
+
if (!url) { setAudioError(result.audioReason || 'There is no audio for this one.'); return; }
|
|
46
62
|
const el = new Audio(url);
|
|
47
63
|
el.onended = () => setPlaying(false);
|
|
48
64
|
el.onpause = () => setPlaying(false);
|
|
@@ -54,9 +70,9 @@ export function BriefCard({ api, onAsk }: { api: BriefCardApi; onAsk?: () => voi
|
|
|
54
70
|
};
|
|
55
71
|
|
|
56
72
|
return (
|
|
57
|
-
<section aria-label=
|
|
73
|
+
<section aria-label={title} className="rounded-lg border border-gray-200 bg-white p-4 shadow-sm" data-testid="brief-card">
|
|
58
74
|
<div className="flex items-center gap-2">
|
|
59
|
-
<h2 className="text-sm font-semibold uppercase tracking-wide text-gray-500">
|
|
75
|
+
<h2 className="text-sm font-semibold uppercase tracking-wide text-gray-500">{title}</h2>
|
|
60
76
|
<div className="ml-auto flex items-center gap-2">
|
|
61
77
|
{state.phase === 'ready' && apiRef.current.loadAudio ? (
|
|
62
78
|
<button type="button" className="rounded-md bg-gray-900 px-3 py-1.5 text-sm font-medium text-white" onClick={() => void play(state.result)}>
|
|
@@ -66,7 +82,10 @@ export function BriefCard({ api, onAsk }: { api: BriefCardApi; onAsk?: () => voi
|
|
|
66
82
|
{onAsk ? <button type="button" className="rounded-md border border-gray-300 px-3 py-1.5 text-sm font-medium text-gray-800" onClick={onAsk}>Ask</button> : null}
|
|
67
83
|
</div>
|
|
68
84
|
</div>
|
|
69
|
-
{state.phase === '
|
|
85
|
+
{state.phase === 'idle' ? (
|
|
86
|
+
<p className="mt-3"><button type="button" className="rounded-md bg-gray-900 px-3 py-1.5 text-sm font-medium text-white" onClick={() => void load()}>Show {title.toLowerCase()}</button></p>
|
|
87
|
+
) : null}
|
|
88
|
+
{state.phase === 'loading' ? <p className="mt-3 text-sm text-gray-500">Putting it together…</p> : null}
|
|
70
89
|
{state.phase === 'error' ? (
|
|
71
90
|
<p className="mt-3 text-sm text-red-600" role="alert">
|
|
72
91
|
{state.message} <button type="button" className="underline" onClick={() => void load()}>Try again</button>
|
|
@@ -75,7 +94,7 @@ export function BriefCard({ api, onAsk }: { api: BriefCardApi; onAsk?: () => voi
|
|
|
75
94
|
{state.phase === 'ready' ? (
|
|
76
95
|
<>
|
|
77
96
|
<p className="mt-3 whitespace-pre-line text-base leading-relaxed text-gray-900" data-testid="brief-text">{state.result.text}</p>
|
|
78
|
-
{state.result.remaining > 0 ? <p className="mt-2 text-xs text-gray-500">{state.result.remaining} more not read out.</p> : null}
|
|
97
|
+
{(state.result.remaining ?? 0) > 0 ? <p className="mt-2 text-xs text-gray-500">{state.result.remaining} more not read out.</p> : null}
|
|
79
98
|
</>
|
|
80
99
|
) : null}
|
|
81
100
|
{audioError ? <p className="mt-2 text-xs text-amber-800" role="status">{audioError}</p> : null}
|
|
@@ -33,11 +33,13 @@ export interface CompactItemRowProps {
|
|
|
33
33
|
actions?: React.ReactNode;
|
|
34
34
|
/** Show the status word for items that are not plainly open. Default true. */
|
|
35
35
|
showStatus?: boolean;
|
|
36
|
+
/** The due date is Tandem's guess, not confirmed: drawn lighter, never as a warning. */
|
|
37
|
+
guessedDue?: boolean;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
const CHIP = 'inline-flex max-w-[14rem] items-center truncate rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-xs text-gray-700';
|
|
39
41
|
|
|
40
|
-
export function CompactItemRow({ item, days, due, project, trackerName, onOpen, actions, showStatus = true }: CompactItemRowProps) {
|
|
42
|
+
export function CompactItemRow({ item, days, due, project, trackerName, onOpen, actions, showStatus = true, guessedDue }: CompactItemRowProps) {
|
|
41
43
|
const late = days !== null && days < 0 && item.status !== 'done';
|
|
42
44
|
const label = dueLabel(days, due);
|
|
43
45
|
return (
|
|
@@ -56,7 +58,15 @@ export function CompactItemRow({ item, days, due, project, trackerName, onOpen,
|
|
|
56
58
|
{project ? <span className={CHIP} title={project}>{project}</span> : null}
|
|
57
59
|
{showStatus && item.status !== 'open' && item.status !== 'done' ? <span className={CHIP} title={item.statusReason || undefined}>{item.status.replace('_', ' ')}</span> : null}
|
|
58
60
|
{item.sync ? <ExternalLinkChip sync={item.sync} trackerName={trackerName} className={CHIP} /> : null}
|
|
59
|
-
{label ?
|
|
61
|
+
{label ? (
|
|
62
|
+
<span
|
|
63
|
+
className={`w-16 text-right text-xs ${guessedDue ? 'italic text-gray-500' : late ? 'font-semibold text-red-700' : 'text-gray-500'}`}
|
|
64
|
+
title={guessedDue ? 'Tandem’s guess: confirm it under Needs your call' : undefined}
|
|
65
|
+
data-guess={guessedDue ? 'true' : undefined}
|
|
66
|
+
>
|
|
67
|
+
{guessedDue ? `~${label}` : label}
|
|
68
|
+
</span>
|
|
69
|
+
) : null}
|
|
60
70
|
{actions}
|
|
61
71
|
</div>
|
|
62
72
|
</li>
|
|
@@ -13,7 +13,7 @@ import { CompactItemRow } from './CompactItemRow';
|
|
|
13
13
|
const TONE: Record<string, string> = { overdue: 'text-red-700', today: 'text-gray-900', week: 'text-gray-900', later: 'text-gray-500' };
|
|
14
14
|
|
|
15
15
|
export function DueAcrossProjects({
|
|
16
|
-
due, projectNames = {}, perGroup = 6, trackerName, onOpen, onSeeAll,
|
|
16
|
+
due, projectNames = {}, perGroup = 6, trackerName, onOpen, onSeeAll, guessed,
|
|
17
17
|
}: {
|
|
18
18
|
due: DueGroups;
|
|
19
19
|
projectNames?: Record<string, string>;
|
|
@@ -22,6 +22,8 @@ export function DueAcrossProjects({
|
|
|
22
22
|
onOpen?: (item: Commitment) => void;
|
|
23
23
|
/** "Open the Tracker" — shown when there is more than the home lists. */
|
|
24
24
|
onSeeAll?: () => void;
|
|
25
|
+
/** Items whose date is still Tandem's guess: shown quietly. */
|
|
26
|
+
guessed?: ReadonlySet<string>;
|
|
25
27
|
}) {
|
|
26
28
|
const [open, setOpen] = React.useState<Record<string, boolean>>({});
|
|
27
29
|
if (due.total === 0) {
|
|
@@ -50,7 +52,7 @@ export function DueAcrossProjects({
|
|
|
50
52
|
key={entry.item.externalId}
|
|
51
53
|
item={entry.item} days={entry.days} due={entry.due}
|
|
52
54
|
project={entry.item.focusId ? projectNames[entry.item.focusId] : undefined}
|
|
53
|
-
trackerName={trackerName} onOpen={onOpen}
|
|
55
|
+
trackerName={trackerName} onOpen={onOpen} guessedDue={guessed?.has(entry.item.id)}
|
|
54
56
|
/>
|
|
55
57
|
))}
|
|
56
58
|
</ul>
|
|
@@ -17,6 +17,9 @@ import { isTask } from '../../../corpus/tracker-groups';
|
|
|
17
17
|
import { actionsByNote } from '../../../corpus/note-actions';
|
|
18
18
|
import { failureMessage } from '../../../corpus/work-item-logic';
|
|
19
19
|
import type { Commitment, CommitmentApi, CorpusApi, Focus, PlanningApi } from '../../../corpus/types';
|
|
20
|
+
import { applyAnswerToItem, type OpenQuestion, type QuestionAnswer } from '../../../corpus/questions';
|
|
21
|
+
import { NeedsYourCall } from '../questions/NeedsYourCall';
|
|
22
|
+
import type { NeedsYourCallApi } from '../questions/types';
|
|
20
23
|
import { BriefCard, type BriefCardApi } from './BriefCard';
|
|
21
24
|
import { DueAcrossProjects } from './DueAcrossProjects';
|
|
22
25
|
import { RecentNotes, type RecentNote } from './RecentNotes';
|
|
@@ -26,6 +29,8 @@ const DAY = 86_400_000;
|
|
|
26
29
|
|
|
27
30
|
export interface HomeBriefPageProps {
|
|
28
31
|
brief: BriefCardApi;
|
|
32
|
+
/** The weekly summary, shown on demand under the daily brief. Absent = no weekly card. */
|
|
33
|
+
weekly?: BriefCardApi;
|
|
29
34
|
corpus: CorpusApi & CommitmentApi;
|
|
30
35
|
/** Names the project chips. Absent = no chips. */
|
|
31
36
|
listFocuses?: PlanningApi['listFocuses'];
|
|
@@ -38,6 +43,8 @@ export interface HomeBriefPageProps {
|
|
|
38
43
|
onOpenItem?: (item: Commitment) => void;
|
|
39
44
|
/** How many recent notes to list. Default 6. */
|
|
40
45
|
noteCount?: number;
|
|
46
|
+
/** Tandem's open questions ("Needs your call"). Absent = no such section. */
|
|
47
|
+
questions?: NeedsYourCallApi;
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
interface Data { open: Commitment[]; recent: Commitment[]; notes: RecentNote[]; names: Record<string, string> }
|
|
@@ -52,7 +59,7 @@ function Section({ title, children }: { title: string; children: React.ReactNode
|
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
export function HomeBriefPage({
|
|
55
|
-
brief, corpus, listFocuses, timeZone, now, trackerName, onAsk, onOpenTracker, onOpenNote, onOpenItem, noteCount = 6,
|
|
62
|
+
brief, weekly, corpus, listFocuses, timeZone, now, trackerName, onAsk, onOpenTracker, onOpenNote, onOpenItem, noteCount = 6, questions,
|
|
56
63
|
}: HomeBriefPageProps) {
|
|
57
64
|
// Frozen once: a clock that changes every render re-fires the load effect.
|
|
58
65
|
const [mountedAt] = React.useState(() => Date.now());
|
|
@@ -91,15 +98,37 @@ export function HomeBriefPage({
|
|
|
91
98
|
return () => { live = false; };
|
|
92
99
|
}, [clock, noteCount, corpus]);
|
|
93
100
|
|
|
94
|
-
|
|
101
|
+
// An answer shows on its to-do the moment it is tapped; a failed save drops it again.
|
|
102
|
+
const [applied, setApplied] = React.useState<Record<string, { q: OpenQuestion; answer: QuestionAnswer }>>({});
|
|
103
|
+
const [guessed, setGuessed] = React.useState<ReadonlySet<string>>(new Set());
|
|
104
|
+
const due = React.useMemo(() => {
|
|
105
|
+
if (!data) return null;
|
|
106
|
+
const answers = Object.values(applied);
|
|
107
|
+
const open = answers.length ? data.open.map((item) => answers.reduce((cur, { q, answer }) => applyAnswerToItem(cur, q, answer), item)) : data.open;
|
|
108
|
+
return groupDue(open.filter(isTask), { now: clock, timeZone });
|
|
109
|
+
}, [data, applied, clock, timeZone]);
|
|
110
|
+
const titles = React.useMemo(() => new Map((data ? [...data.open, ...data.recent] : []).map((i) => [i.id, i.title])), [data]);
|
|
111
|
+
const onOpenQuestions = React.useCallback((open: OpenQuestion[]) => {
|
|
112
|
+
setGuessed(new Set(open.filter((q) => q.kind === 'due_date' && q.assumed?.value).map((q) => q.itemId)));
|
|
113
|
+
}, []);
|
|
95
114
|
|
|
96
115
|
return (
|
|
97
116
|
<div className="space-y-8">
|
|
98
117
|
<BriefCard api={brief} onAsk={onAsk} />
|
|
118
|
+
{weekly ? <BriefCard api={weekly} title="Your week" onDemand /> : null}
|
|
99
119
|
{error ? <p className="text-sm text-red-600" role="alert">{error}</p> : null}
|
|
120
|
+
{questions ? (
|
|
121
|
+
<NeedsYourCall
|
|
122
|
+
api={questions} itemTitle={(id) => titles.get(id)} projectNames={data?.names} timeZone={timeZone} now={now}
|
|
123
|
+
onOpenQuestions={onOpenQuestions}
|
|
124
|
+
onApplied={(q, answer) => setApplied((a) => ({ ...a, [q.id]: { q, answer } }))}
|
|
125
|
+
onReverted={(q) => setApplied(({ [q.id]: _gone, ...rest }) => rest)}
|
|
126
|
+
onOpenItem={onOpenItem ? (id) => { const item = data?.open.find((i) => i.id === id) ?? data?.recent.find((i) => i.id === id); if (item) onOpenItem(item); } : undefined}
|
|
127
|
+
/>
|
|
128
|
+
) : null}
|
|
100
129
|
<Section title="Due across projects">
|
|
101
130
|
{due && data ? (
|
|
102
|
-
<DueAcrossProjects due={due} projectNames={data.names} trackerName={trackerName} onOpen={onOpenItem} onSeeAll={onOpenTracker} />
|
|
131
|
+
<DueAcrossProjects due={due} projectNames={data.names} guessed={guessed} trackerName={trackerName} onOpen={onOpenItem} onSeeAll={onOpenTracker} />
|
|
103
132
|
) : error ? null : <p className="text-sm text-gray-500">Loading…</p>}
|
|
104
133
|
</Section>
|
|
105
134
|
<Section title="Recent notes">
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NEEDS YOUR CALL — Tandem's open clarifying questions on Home (bd startsim-tmrvi.7).
|
|
3
|
+
*
|
|
4
|
+
* Best first, a few at a time. A tap on a chip answers: the row leaves at once and
|
|
5
|
+
* the to-do it was about shows the new value (`onApplied`), then the answer is saved
|
|
6
|
+
* by the host's `api`; if that fails the row comes back where it was and the
|
|
7
|
+
* to-do is put back (`onReverted`). Writes happen in the click handlers, never in an effect.
|
|
8
|
+
* Nothing is kept past this component: the list is the caller's own, so it is
|
|
9
|
+
* re-read for whoever is signed in, never shared or cached across people.
|
|
10
|
+
*/
|
|
11
|
+
import * as React from 'react';
|
|
12
|
+
|
|
13
|
+
import { failureMessage } from '../../../corpus/work-item-logic';
|
|
14
|
+
import type { AnswerOption, OpenQuestion, QuestionAnswer } from '../../../corpus/questions';
|
|
15
|
+
import { QuestionRow } from './QuestionRow';
|
|
16
|
+
import type { NeedsYourCallProps } from './types';
|
|
17
|
+
|
|
18
|
+
type Phase = { name: 'loading' } | { name: 'error'; message: string } | { name: 'ready' };
|
|
19
|
+
|
|
20
|
+
const byScore = (a: OpenQuestion, b: OpenQuestion) => b.score - a.score;
|
|
21
|
+
|
|
22
|
+
export function NeedsYourCall({
|
|
23
|
+
api, itemTitle, projectNames, options, timeZone, now, pageSize = 5, onApplied, onReverted, onOpenQuestions, onOpenItem,
|
|
24
|
+
}: NeedsYourCallProps) {
|
|
25
|
+
const apiRef = React.useRef(api);
|
|
26
|
+
apiRef.current = api;
|
|
27
|
+
const [mountedAt] = React.useState(() => Date.now());
|
|
28
|
+
const [phase, setPhase] = React.useState<Phase>({ name: 'loading' });
|
|
29
|
+
const [questions, setQuestions] = React.useState<OpenQuestion[]>([]);
|
|
30
|
+
const [shown, setShown] = React.useState(pageSize);
|
|
31
|
+
const [notice, setNotice] = React.useState<{ tone: 'ok' | 'bad'; text: string } | null>(null);
|
|
32
|
+
const [extra, setExtra] = React.useState<Record<string, AnswerOption[]>>({});
|
|
33
|
+
const asked = React.useRef(new Set<string>());
|
|
34
|
+
const optionsRef = React.useRef(options);
|
|
35
|
+
optionsRef.current = options;
|
|
36
|
+
const onOpenRef = React.useRef(onOpenQuestions);
|
|
37
|
+
onOpenRef.current = onOpenQuestions;
|
|
38
|
+
|
|
39
|
+
const load = React.useCallback(async () => {
|
|
40
|
+
setPhase({ name: 'loading' });
|
|
41
|
+
setQuestions([]);
|
|
42
|
+
setExtra({});
|
|
43
|
+
asked.current = new Set();
|
|
44
|
+
try {
|
|
45
|
+
setQuestions((await apiRef.current.list()).filter((q) => q.status === 'open').sort(byScore));
|
|
46
|
+
setPhase({ name: 'ready' });
|
|
47
|
+
} catch (err) {
|
|
48
|
+
setPhase({ name: 'error', message: failureMessage(err) });
|
|
49
|
+
}
|
|
50
|
+
}, []);
|
|
51
|
+
React.useEffect(() => { void load(); }, [load, api]);
|
|
52
|
+
React.useEffect(() => { onOpenRef.current?.(questions); }, [questions]);
|
|
53
|
+
|
|
54
|
+
// Choices for team / owner questions the host can name; read once per question.
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
const read = optionsRef.current;
|
|
57
|
+
if (!read) return;
|
|
58
|
+
for (const q of questions.slice(0, shown)) {
|
|
59
|
+
if (q.kind === 'due_date' || asked.current.has(q.id)) continue;
|
|
60
|
+
asked.current.add(q.id);
|
|
61
|
+
read(q).then((list) => setExtra((e) => ({ ...e, [q.id]: list }))).catch(() => undefined);
|
|
62
|
+
}
|
|
63
|
+
}, [questions, shown]);
|
|
64
|
+
|
|
65
|
+
const settle = async (q: OpenQuestion, save: () => Promise<void>, revert: boolean) => {
|
|
66
|
+
const at = questions.findIndex((x) => x.id === q.id);
|
|
67
|
+
setQuestions((list) => list.filter((x) => x.id !== q.id));
|
|
68
|
+
setNotice(null);
|
|
69
|
+
try {
|
|
70
|
+
await save();
|
|
71
|
+
setNotice({ tone: 'ok', text: 'Saved.' });
|
|
72
|
+
} catch {
|
|
73
|
+
if (revert) onReverted?.(q);
|
|
74
|
+
setQuestions((list) => {
|
|
75
|
+
if (list.some((x) => x.id === q.id)) return list;
|
|
76
|
+
const next = [...list];
|
|
77
|
+
next.splice(Math.min(at < 0 ? next.length : at, next.length), 0, q);
|
|
78
|
+
return next;
|
|
79
|
+
});
|
|
80
|
+
setNotice({ tone: 'bad', text: 'That did not save. It is back in your list; try again.' });
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const answer = (q: OpenQuestion, a: QuestionAnswer) => {
|
|
85
|
+
onApplied?.(q, a);
|
|
86
|
+
void settle(q, () => apiRef.current.answer(q, a), true);
|
|
87
|
+
};
|
|
88
|
+
const skip = (q: OpenQuestion) => { void settle(q, () => apiRef.current.skip(q), false); };
|
|
89
|
+
|
|
90
|
+
const labelsFor = (q: OpenQuestion) => ({
|
|
91
|
+
labels: projectNames, timeZone, options: extra[q.id] ?? q.options,
|
|
92
|
+
});
|
|
93
|
+
const visible = questions.slice(0, shown);
|
|
94
|
+
const clock = now ?? mountedAt;
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<section aria-labelledby="needs-your-call-title" className="space-y-3" data-testid="needs-your-call">
|
|
98
|
+
<h2 id="needs-your-call-title" className="flex items-baseline gap-2 text-lg font-semibold text-gray-900">
|
|
99
|
+
Needs your call
|
|
100
|
+
{phase.name === 'ready' && questions.length ? <span className="text-xs font-normal text-gray-500">{questions.length}</span> : null}
|
|
101
|
+
</h2>
|
|
102
|
+
<p className="sr-only" role="status" aria-live="polite">{notice?.tone === 'ok' ? notice.text : ''}</p>
|
|
103
|
+
{notice?.tone === 'bad' ? <p className="text-sm text-gray-700" role="alert">{notice.text}</p> : null}
|
|
104
|
+
{phase.name === 'loading' ? <p className="text-sm text-gray-500">Loading…</p> : null}
|
|
105
|
+
{phase.name === 'error' ? (
|
|
106
|
+
<p className="text-sm text-gray-600">
|
|
107
|
+
{phase.message} <button type="button" className="text-blue-700 underline" onClick={() => void load()}>Try again</button>
|
|
108
|
+
</p>
|
|
109
|
+
) : null}
|
|
110
|
+
{phase.name === 'ready' && questions.length === 0 ? <p className="text-sm text-gray-500">Nothing needs your call.</p> : null}
|
|
111
|
+
{phase.name === 'ready' && visible.length ? (
|
|
112
|
+
<ul>
|
|
113
|
+
{visible.map((q) => (
|
|
114
|
+
<QuestionRow
|
|
115
|
+
key={q.id} question={q} title={itemTitle?.(q.itemId) || 'A to-do'} chipContext={labelsFor(q)} now={clock}
|
|
116
|
+
onAnswer={answer} onSkip={skip} onOpenItem={onOpenItem}
|
|
117
|
+
/>
|
|
118
|
+
))}
|
|
119
|
+
</ul>
|
|
120
|
+
) : null}
|
|
121
|
+
{phase.name === 'ready' && questions.length > visible.length ? (
|
|
122
|
+
<button type="button" className="text-sm text-blue-700 underline" onClick={() => setShown(shown + pageSize)}>
|
|
123
|
+
Show {Math.min(pageSize, questions.length - visible.length)} more
|
|
124
|
+
</button>
|
|
125
|
+
) : null}
|
|
126
|
+
</section>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONE QUESTION: the to-do it is about, the question, what Tandem is assuming
|
|
3
|
+
* (quiet, not a warning), answer chips (a tap answers), "Skip it", and a free
|
|
4
|
+
* answer for anything the chips do not say. Presentational: the list owns the saving.
|
|
5
|
+
*/
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
|
|
8
|
+
import { assumedLabel, chipsFor, readTypedAnswer, type ChipContext } from '../../../corpus/questions';
|
|
9
|
+
import type { OpenQuestion, QuestionAnswer } from '../../../corpus/questions';
|
|
10
|
+
|
|
11
|
+
const CHIP = 'inline-flex min-h-9 items-center rounded-full border border-gray-300 bg-white px-3 py-1 text-sm text-gray-800 hover:bg-gray-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500';
|
|
12
|
+
const KEEP = 'inline-flex min-h-9 items-center rounded-full border border-blue-200 bg-blue-50 px-3 py-1 text-sm text-blue-900 hover:bg-blue-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500';
|
|
13
|
+
|
|
14
|
+
export interface QuestionRowProps {
|
|
15
|
+
question: OpenQuestion;
|
|
16
|
+
title: string;
|
|
17
|
+
chipContext: ChipContext;
|
|
18
|
+
now: number;
|
|
19
|
+
onAnswer: (q: OpenQuestion, answer: QuestionAnswer) => void;
|
|
20
|
+
onSkip: (q: OpenQuestion) => void;
|
|
21
|
+
onOpenItem?: (itemId: string) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function QuestionRow({ question: q, title, chipContext, now, onAnswer, onSkip, onOpenItem }: QuestionRowProps) {
|
|
25
|
+
const [typing, setTyping] = React.useState(false);
|
|
26
|
+
const [text, setText] = React.useState('');
|
|
27
|
+
const [hint, setHint] = React.useState('');
|
|
28
|
+
const chips = chipsFor(q, chipContext);
|
|
29
|
+
const guess = assumedLabel(q, chipContext);
|
|
30
|
+
const inputId = `q-${q.id}-free`;
|
|
31
|
+
|
|
32
|
+
const submit = (event: React.FormEvent) => {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
if (!text.trim()) return;
|
|
35
|
+
const read = readTypedAnswer(q, text, { now, timeZone: chipContext.timeZone, options: chipContext.options, labels: chipContext.labels });
|
|
36
|
+
if (read.kind === 'answer') onAnswer(q, read.answer);
|
|
37
|
+
else if (read.kind === 'skip') onSkip(q);
|
|
38
|
+
else setHint(read.message);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<li className="space-y-2 border-b border-gray-100 py-3 last:border-b-0" data-testid="question-row">
|
|
43
|
+
{onOpenItem ? (
|
|
44
|
+
<button type="button" className="block max-w-full truncate text-left text-sm font-medium text-gray-900 hover:underline" onClick={() => onOpenItem(q.itemId)}>{title}</button>
|
|
45
|
+
) : <p className="truncate text-sm font-medium text-gray-900">{title}</p>}
|
|
46
|
+
<p className="text-sm text-gray-700">{q.question}</p>
|
|
47
|
+
{guess ? (
|
|
48
|
+
<p className="text-xs text-gray-500" title={q.assumed?.reason || undefined}>For now I am going with {guess}.</p>
|
|
49
|
+
) : null}
|
|
50
|
+
<div role="group" aria-label={`Answers for ${title}`} className="flex flex-wrap items-center gap-2">
|
|
51
|
+
{chips.map((chip) => (
|
|
52
|
+
<button
|
|
53
|
+
key={chip.value || 'none'} type="button" className={chip.assumed ? KEEP : CHIP} title={chip.reason || undefined}
|
|
54
|
+
onClick={() => onAnswer(q, { value: chip.value, label: chip.label })}
|
|
55
|
+
>
|
|
56
|
+
{chip.assumed ? `Keep ${chip.label}` : chip.label}
|
|
57
|
+
</button>
|
|
58
|
+
))}
|
|
59
|
+
<button type="button" className="min-h-9 px-2 text-sm text-gray-600 underline" aria-expanded={typing} onClick={() => setTyping(!typing)}>
|
|
60
|
+
{chips.length ? 'Something else' : 'Answer'}
|
|
61
|
+
</button>
|
|
62
|
+
<button type="button" className="min-h-9 px-2 text-sm text-gray-500 underline" onClick={() => onSkip(q)}>Skip it</button>
|
|
63
|
+
</div>
|
|
64
|
+
{typing ? (
|
|
65
|
+
<form className="flex flex-wrap items-center gap-2" onSubmit={submit}>
|
|
66
|
+
<label htmlFor={inputId} className="sr-only">Your answer for {title}</label>
|
|
67
|
+
<input
|
|
68
|
+
id={inputId} value={text} onChange={(e) => { setText(e.target.value); setHint(''); }}
|
|
69
|
+
placeholder={q.kind === 'due_date' ? 'A day, like next Friday' : 'Your answer'}
|
|
70
|
+
className="min-h-9 min-w-0 flex-1 rounded-md border border-gray-300 px-3 text-sm"
|
|
71
|
+
/>
|
|
72
|
+
<button type="submit" className={CHIP}>Save</button>
|
|
73
|
+
{hint ? <p className="w-full text-xs text-gray-600" role="status">{hint}</p> : null}
|
|
74
|
+
</form>
|
|
75
|
+
) : null}
|
|
76
|
+
</li>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AnswerOption, OpenQuestion, QuestionAnswer } from '../../../corpus/questions';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What the "Needs your call" card needs from its host (bd startsim-tmrvi.7). A tenant app wires it
|
|
5
|
+
* to its own routes (GET and POST /corpus/questions, and the skip press); nothing here
|
|
6
|
+
* knows a URL, so the card is not tied to one app.
|
|
7
|
+
*/
|
|
8
|
+
export interface NeedsYourCallApi {
|
|
9
|
+
/** The signed-in person's open questions, best first. Private items only ever arrive for their owner. */
|
|
10
|
+
list(): Promise<OpenQuestion[]>;
|
|
11
|
+
/** Save one answer. Rejects when it could not be saved. */
|
|
12
|
+
answer(question: OpenQuestion, answer: QuestionAnswer): Promise<void>;
|
|
13
|
+
/** Leave one for later. Rejects when it could not be saved. */
|
|
14
|
+
skip(question: OpenQuestion): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface NeedsYourCallProps {
|
|
18
|
+
api: NeedsYourCallApi;
|
|
19
|
+
/** The title of the to-do a question is about; unknown ids read "A to-do". */
|
|
20
|
+
itemTitle?: (itemId: string) => string | undefined;
|
|
21
|
+
/** Project id to name, for project chips. */
|
|
22
|
+
projectNames?: Record<string, string>;
|
|
23
|
+
/** Extra choices for a question (a team, an owner) when the host can name them. */
|
|
24
|
+
options?: (question: OpenQuestion) => Promise<AnswerOption[]>;
|
|
25
|
+
timeZone?: string;
|
|
26
|
+
now?: number;
|
|
27
|
+
/** How many to show before "Show more". Default 5. */
|
|
28
|
+
pageSize?: number;
|
|
29
|
+
/** Fires the moment an answer is tapped, before it is saved: update the to-do in place. */
|
|
30
|
+
onApplied?: (question: OpenQuestion, answer: QuestionAnswer) => void;
|
|
31
|
+
/** The save failed: undo whatever `onApplied` showed. */
|
|
32
|
+
onReverted?: (question: OpenQuestion) => void;
|
|
33
|
+
/** The questions still open, whenever they change (to mark guessed values on the to-do rows). */
|
|
34
|
+
onOpenQuestions?: (questions: OpenQuestion[]) => void;
|
|
35
|
+
onOpenItem?: (itemId: string) => void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an Ask question wants from the TRACKED ITEMS, decided in code (bd startsim-tmrvi).
|
|
3
|
+
*
|
|
4
|
+
* PURE: `now` and the reader's IANA zone come in. "What is due Friday" and "what
|
|
5
|
+
* is slipping" are questions about dates and states, which a keyword ranker over
|
|
6
|
+
* documents cannot answer and a model should not be left to compute: the window is
|
|
7
|
+
* worked out here, the matching items are selected here, and the model only phrases
|
|
8
|
+
* what it was handed.
|
|
9
|
+
*/
|
|
10
|
+
import { localDate } from './today';
|
|
11
|
+
|
|
12
|
+
export type ItemFocus = 'slipping' | 'due' | 'committed' | 'status';
|
|
13
|
+
|
|
14
|
+
export interface ItemIntent {
|
|
15
|
+
focus: ItemFocus;
|
|
16
|
+
/** Inclusive calendar days in the reader's zone. Absent = no date window. */
|
|
17
|
+
from?: string;
|
|
18
|
+
to?: string;
|
|
19
|
+
/** "I", "my": only the reader's own items. */
|
|
20
|
+
mine: boolean;
|
|
21
|
+
/** Today in the reader's zone, handed to the model so "overdue" has a reference. */
|
|
22
|
+
today: string;
|
|
23
|
+
/** What the window means, in words ("this week (2026-11-09 to 2026-11-15)"). */
|
|
24
|
+
windowLabel?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const WEEKDAYS = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
|
|
28
|
+
const ITEM_WORDS = /\b(commit(?:ted|ment|ments)?|promis(?:ed|e)|owe|due|deadline|deadlines|slipp(?:ing|ed)|behind|overdue|late|at risk|blocked|to-?dos?|tasks?|items?|status|on my plate|open|in progress|linear|assigned|owner)\b/i;
|
|
29
|
+
|
|
30
|
+
const addDays = (day: string, n: number): string => {
|
|
31
|
+
const d = new Date(`${day}T00:00:00Z`);
|
|
32
|
+
d.setUTCDate(d.getUTCDate() + n);
|
|
33
|
+
return d.toISOString().slice(0, 10);
|
|
34
|
+
};
|
|
35
|
+
const weekdayOf = (day: string): number => new Date(`${day}T00:00:00Z`).getUTCDay();
|
|
36
|
+
|
|
37
|
+
/** Monday-first week containing `day`. */
|
|
38
|
+
function weekOf(day: string): { from: string; to: string } {
|
|
39
|
+
const offset = (weekdayOf(day) + 6) % 7;
|
|
40
|
+
const from = addDays(day, -offset);
|
|
41
|
+
return { from, to: addDays(from, 6) };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The intent, or null when the question is not about tracked items at all. */
|
|
45
|
+
export function itemIntent(question: string, now: number, timeZone = 'UTC'): ItemIntent | null {
|
|
46
|
+
const q = question.toLowerCase();
|
|
47
|
+
if (!ITEM_WORDS.test(q)) return null;
|
|
48
|
+
const today = localDate(now, timeZone);
|
|
49
|
+
const mine = /\b(i|i'm|i've|my|me|mine)\b/.test(q);
|
|
50
|
+
|
|
51
|
+
let focus: ItemFocus = 'status';
|
|
52
|
+
if (/\b(slipp(?:ing|ed)|behind|overdue|late|at risk|missed)\b/.test(q)) focus = 'slipping';
|
|
53
|
+
else if (/\b(commit(?:ted|ment|ments)?|promis(?:ed|e)|owe)\b/.test(q)) focus = 'committed';
|
|
54
|
+
else if (/\b(due|deadline|deadlines)\b/.test(q)) focus = 'due';
|
|
55
|
+
|
|
56
|
+
let from: string | undefined;
|
|
57
|
+
let to: string | undefined;
|
|
58
|
+
let windowLabel: string | undefined;
|
|
59
|
+
const set = (a: string, b: string, label: string) => { from = a; to = b; windowLabel = `${label} (${a === b ? a : `${a} to ${b}`})`; };
|
|
60
|
+
|
|
61
|
+
const named = WEEKDAYS.find((w) => new RegExp(`\\b${w}\\b`).test(q));
|
|
62
|
+
if (/\bnext week\b/.test(q)) { const w = weekOf(addDays(today, 7)); set(w.from, w.to, 'next week'); }
|
|
63
|
+
else if (/\blast week\b/.test(q)) { const w = weekOf(addDays(today, -7)); set(w.from, w.to, 'last week'); }
|
|
64
|
+
else if (/\bthis week\b|\bthe week\b/.test(q)) { const w = weekOf(today); set(w.from, w.to, 'this week'); }
|
|
65
|
+
else if (/\btomorrow\b/.test(q)) set(addDays(today, 1), addDays(today, 1), 'tomorrow');
|
|
66
|
+
else if (/\btoday\b/.test(q)) set(today, today, 'today');
|
|
67
|
+
else if (/\byesterday\b/.test(q)) set(addDays(today, -1), addDays(today, -1), 'yesterday');
|
|
68
|
+
else if (named) {
|
|
69
|
+
// The NEXT such weekday, today included: "due Friday" on a Friday means today.
|
|
70
|
+
const delta = (WEEKDAYS.indexOf(named) - weekdayOf(today) + 7) % 7;
|
|
71
|
+
const day = addDays(today, delta);
|
|
72
|
+
set(day, day, named[0].toUpperCase() + named.slice(1));
|
|
73
|
+
}
|
|
74
|
+
return { focus, from, to, mine, today, ...(windowLabel ? { windowLabel } : {}) };
|
|
75
|
+
}
|