@startsimpli/integrations 0.2.223 → 0.2.225
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 +5 -5
- package/src/__tests__/attention-importance.test.ts +51 -0
- package/src/__tests__/attention-policy.test.ts +174 -0
- package/src/__tests__/attention-rhythm.test.ts +95 -0
- package/src/__tests__/attention-run.test.ts +132 -0
- package/src/__tests__/attention-settings-page.test.tsx +57 -0
- package/src/__tests__/attention-settings.test.ts +86 -0
- package/src/__tests__/converse-client.test.ts +6 -0
- package/src/__tests__/converse-meeting.test.ts +40 -0
- package/src/__tests__/converse-relay.test.ts +35 -0
- package/src/__tests__/converse-roci.test.ts +16 -1
- package/src/__tests__/converse-soak.test.ts +61 -0
- package/src/__tests__/converse-watchdog.test.ts +107 -0
- package/src/__tests__/decisions-page.test.tsx +1 -1
- package/src/__tests__/fleet-view.test.ts +1 -1
- package/src/__tests__/relay-items.test.ts +89 -0
- package/src/components/index.ts +1 -0
- package/src/components/pages/AttentionSettings.tsx +51 -0
- package/src/components/pages/DecisionsPage.tsx +13 -2
- package/src/corpus/attention/controller.ts +37 -0
- package/src/corpus/attention/importance.ts +17 -0
- package/src/corpus/attention/index.ts +9 -0
- package/src/corpus/attention/policy.ts +61 -0
- package/src/corpus/attention/push.ts +47 -0
- package/src/corpus/attention/queue.ts +26 -0
- package/src/corpus/attention/rhythm.ts +69 -0
- package/src/corpus/attention/run-steps.ts +90 -0
- package/src/corpus/attention/run.ts +65 -0
- package/src/corpus/attention/settings.ts +80 -0
- package/src/corpus/attention/types.ts +75 -0
- package/src/corpus/converse/client.ts +3 -2
- package/src/corpus/converse/handle.ts +18 -3
- package/src/corpus/converse/meeting-config.ts +15 -1
- package/src/corpus/converse/meeting.ts +100 -8
- package/src/corpus/converse/respond.ts +12 -2
- package/src/corpus/converse/roci.ts +11 -4
- package/src/corpus/converse/types.ts +11 -0
- package/src/corpus/index.ts +1 -0
- package/src/corpus/notify/client.ts +10 -2
- package/src/corpus/notify/handle.ts +9 -5
- package/src/corpus/notify/index.ts +2 -0
- package/src/corpus/notify/relay-items.ts +53 -0
- package/src/corpus/notify/respond.ts +7 -1
- package/src/corpus/notify/state.ts +4 -0
- package/src/corpus/notify/types.ts +14 -0
- package/src/native/app/converseServices.ts +1 -0
- package/src/native/app/notifyServices.ts +8 -1
- package/src/native/app/registry.tsx +4 -2
- package/src/native/app/services.ts +1 -1
- package/src/native/converse/DriveScreen.tsx +47 -0
- package/src/native/converse/__tests__/driveScreen.test.tsx +54 -0
- package/src/native/converse/api.ts +1 -0
- package/src/native/converse/fake.ts +4 -0
- package/src/native/converse/index.ts +1 -0
- package/src/native/converse/io.ts +1 -0
- package/src/native/push/AttentionCard.tsx +44 -0
- package/src/native/push/DecisionsScreen.tsx +12 -2
- package/src/native/push/NeedsYouCard.tsx +42 -0
- package/src/native/push/__tests__/decisionsApp.test.tsx +12 -1
- package/src/native/push/__tests__/needsYou.test.tsx +106 -0
- package/src/native/push/fake.ts +12 -1
- package/src/native/push/index.ts +3 -0
- package/src/native/push/needsYou.ts +29 -0
- package/src/native/push/tab.tsx +4 -2
- package/src/native/talk/TalkTab.tsx +24 -2
|
@@ -22,6 +22,8 @@ import type { MeetingController } from '../../corpus/converse/meeting';
|
|
|
22
22
|
import { converseTab } from '../converse/tab';
|
|
23
23
|
import type { SpeedStore } from '../converse/speed';
|
|
24
24
|
import { decisionsTab } from '../push/tab';
|
|
25
|
+
import type { AttentionController } from '../../corpus/attention/controller';
|
|
26
|
+
import type { NeedsYouController } from '../push/needsYou';
|
|
25
27
|
import type { DecisionsController } from '../push/decisions';
|
|
26
28
|
import type { PushController } from '../push/controller';
|
|
27
29
|
import type { VoiceNotesController } from '../voice/controller';
|
|
@@ -49,7 +51,7 @@ export interface ScreenDeps {
|
|
|
49
51
|
/** How fast Converse replies are spoken; null/absent hides the control. */
|
|
50
52
|
converseSpeed?: SpeedStore | null;
|
|
51
53
|
/** Decisions and push; null when `features.notifications` is off. */
|
|
52
|
-
notify?: { decisions: DecisionsController; push: PushController } | null;
|
|
54
|
+
notify?: { decisions: DecisionsController; push: PushController; needsYou?: NeedsYouController; attention?: AttentionController } | null;
|
|
53
55
|
itemsChanged?: { subscribe(listener: () => void): () => void };
|
|
54
56
|
/** "What's on the plate" (the spoken briefing); null when `features.briefing` is off. Drawn on the Home tab. */
|
|
55
57
|
briefing?: { controller: BriefingController; reply: BriefingReplyController | null } | null;
|
|
@@ -95,7 +97,7 @@ export const BUILTIN_FACTORIES: Record<string, ScreenFactory> = {
|
|
|
95
97
|
},
|
|
96
98
|
tracker: ({ config, corpus, member, openUrl, itemsChanged }, tab) => trackerTab({ api: corpus, itemsChanged, key: tab.key, label: tabLabel(tab), notesKey: firstKey(config, 'notes'), memberConnections: member.connections, openUrl }),
|
|
97
99
|
plan: ({ config, corpus, member, openUrl, itemsChanged }, tab) => planTab({ api: corpus, key: tab.key, label: tabLabel(tab), notesKey: firstKey(config, 'notes'), documentTab: firstKey(config, 'library'), memberConnections: member.connections, openUrl, itemsChanged }),
|
|
98
|
-
talk: ({ config, corpus, converse, converseSpeed }, tab) => talkTab({ api: corpus, converse, speed: converseSpeed, key: tab.key, label: tabLabel(tab), libraryKey: firstKey(config, 'library'), planKey: firstKey(config, 'plan') }),
|
|
100
|
+
talk: ({ config, corpus, converse, converseSpeed, notify }, tab) => talkTab({ api: corpus, converse, speed: converseSpeed, needsYou: notify?.needsYou, key: tab.key, label: tabLabel(tab), libraryKey: firstKey(config, 'library'), planKey: firstKey(config, 'plan') }),
|
|
99
101
|
library: ({ config, corpus }, tab) => libraryTab(corpus, { key: tab.key, label: tabLabel(tab), planKey: firstKey(config, 'plan') }),
|
|
100
102
|
ask: ({ corpus }, tab) => askTab(corpus, { key: tab.key, label: tabLabel(tab) }),
|
|
101
103
|
planning: ({ config, corpus }, tab) => createPlanningTab({ api: corpus, key: tab.key, label: tabLabel(tab), documentTab: firstKey(config, 'library') }),
|
|
@@ -163,7 +163,7 @@ export function createFoundryServices(deps: { config: FoundryAppConfig; device:
|
|
|
163
163
|
AppState.addEventListener('change', (state) => diag.log('app.state', { state }));
|
|
164
164
|
|
|
165
165
|
return {
|
|
166
|
-
diag, session, deepLink, recording, briefing, converse, notify: notify ? { decisions: notify.decisions, push: notify.push } : null,
|
|
166
|
+
diag, session, deepLink, recording, briefing, converse, notify: notify ? { decisions: notify.decisions, push: notify.push, needsYou: notify.needsYou, attention: notify.attention } : null,
|
|
167
167
|
/** The shell navigator calls this once it exists, so warm links can open tabs. */
|
|
168
168
|
bindOpen(fn: (tab: string, id?: string) => void) { open = fn; },
|
|
169
169
|
/** After sign-in/restore. */
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Pressable, Text as RNText, View } from 'react-native';
|
|
2
|
+
import { useTheme } from '@startsimpli/ui-native';
|
|
3
|
+
import { useControllerState } from '../components/useControllerState';
|
|
4
|
+
import type { MeetingController, MeetingPhase } from '../../corpus/converse/meeting';
|
|
5
|
+
import { MEETING_DEFAULTS } from '../../corpus/converse/meeting-config';
|
|
6
|
+
|
|
7
|
+
/** The word glanced at from a car: one of three states, huge. */
|
|
8
|
+
export function driveWord(phase: MeetingPhase): 'LISTENING' | 'SPEAKING' | 'THINKING' | 'READY' | 'SAVING' {
|
|
9
|
+
switch (phase) {
|
|
10
|
+
case 'listening': return 'LISTENING';
|
|
11
|
+
case 'speaking': return 'SPEAKING';
|
|
12
|
+
case 'thinking': return 'THINKING';
|
|
13
|
+
case 'ending': return 'SAVING';
|
|
14
|
+
default: return 'READY';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* DRIVE mode: nothing to tap per turn. It listens all the time, you can talk over it, and it heals itself when something sticks.
|
|
20
|
+
* One control: Start (idle), Interrupt (while it speaks or thinks), End (while it listens). Big state word, big last line.
|
|
21
|
+
*/
|
|
22
|
+
export function DriveScreen({ controller, onExit, assistantName = MEETING_DEFAULTS.assistantName }: { controller: MeetingController; onExit?: () => void; assistantName?: string }) {
|
|
23
|
+
const theme = useTheme();
|
|
24
|
+
const s = useControllerState({ getState: controller.getState, subscribe: (l: () => void) => controller.subscribe(l) });
|
|
25
|
+
const word = driveWord(s.phase);
|
|
26
|
+
const idle = word === 'READY' || s.phase === 'ended' || s.phase === 'stopped';
|
|
27
|
+
const talking = s.phase === 'speaking' || s.phase === 'thinking';
|
|
28
|
+
const last = [...s.lines].reverse().find((l) => l.role === 'assistant' || l.role === 'relay');
|
|
29
|
+
const color = word === 'LISTENING' ? theme.colors.success ?? theme.colors.primary : word === 'SPEAKING' ? theme.colors.primary : word === 'THINKING' ? theme.colors.mutedForeground : theme.colors.foreground;
|
|
30
|
+
const label = idle ? 'Start' : talking ? 'Interrupt' : 'End';
|
|
31
|
+
const press = () => { if (idle) controller.start(); else if (talking) controller.stop(); else void controller.end(); };
|
|
32
|
+
return (
|
|
33
|
+
<View testID="drive-screen" style={{ flex: 1, padding: theme.spacing.lg, gap: theme.spacing.lg, justifyContent: 'space-between' }}>
|
|
34
|
+
<View style={{ alignItems: 'center', gap: theme.spacing.md }}>
|
|
35
|
+
<RNText testID="drive-state" accessibilityLiveRegion="polite" style={{ color, fontSize: 56, fontWeight: '800', letterSpacing: 2 }}>{idle && s.phase !== 'stopped' ? 'READY' : word}</RNText>
|
|
36
|
+
{s.error ? <RNText testID="drive-error" style={{ color: theme.colors.destructive, fontSize: 22, textAlign: 'center' }}>{s.error}</RNText> : null}
|
|
37
|
+
</View>
|
|
38
|
+
<RNText testID="drive-line" style={{ color: theme.colors.foreground, fontSize: 30, lineHeight: 40, textAlign: 'center' }} numberOfLines={8}>{last?.text ?? `${assistantName} here. Tap Start, then just talk.`}</RNText>
|
|
39
|
+
<View style={{ gap: theme.spacing.md }}>
|
|
40
|
+
<Pressable testID="drive-control" accessibilityRole="button" accessibilityLabel={label} onPress={press} style={{ minHeight: 120, borderRadius: 60, backgroundColor: idle ? theme.colors.primary : talking ? theme.colors.destructive : theme.colors.muted, alignItems: 'center', justifyContent: 'center' }}>
|
|
41
|
+
<RNText style={{ color: idle || talking ? theme.colors.primaryForeground : theme.colors.foreground, fontSize: 36, fontWeight: '800' }}>{label}</RNText>
|
|
42
|
+
</Pressable>
|
|
43
|
+
{onExit && idle ? <Pressable testID="drive-exit" accessibilityRole="button" onPress={onExit}><RNText style={{ color: theme.colors.mutedForeground, fontSize: 18, textAlign: 'center' }}>Back to Talk</RNText></Pressable> : null}
|
|
44
|
+
</View>
|
|
45
|
+
</View>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
vi.mock('react-native', async () => ({ ...(await import('../../../../../ui-native/test/rn-stub')) }));
|
|
4
|
+
|
|
5
|
+
import { act, hostById, maybeById, render } from '../../../../../ui-native/test/render';
|
|
6
|
+
import type { MeetingController } from '../../../corpus/converse/meeting';
|
|
7
|
+
import { DriveScreen } from '../DriveScreen';
|
|
8
|
+
|
|
9
|
+
const make = (phase: string, lines: unknown[] = [{ role: 'assistant', text: 'Question 1 of 2: TEST SAMPLE. Yes or no?' }]) => {
|
|
10
|
+
const state = { phase, micOn: phase !== 'idle', retryable: false, lines, error: null, noAudio: null, conversationId: 'c1', saved: null, relayNotice: null, micLive: true };
|
|
11
|
+
const calls = { start: 0, end: 0, stop: 0 };
|
|
12
|
+
const controller = {
|
|
13
|
+
start() { calls.start += 1; }, stop() { calls.stop += 1; }, mic() {}, end: async () => { calls.end += 1; return null; },
|
|
14
|
+
getState: () => state, state: () => state, subscribe: () => () => undefined,
|
|
15
|
+
} as unknown as MeetingController;
|
|
16
|
+
return { controller, calls };
|
|
17
|
+
};
|
|
18
|
+
const text = (r: ReturnType<typeof render>, id: string) => String(hostById(r, id).props.children ?? '');
|
|
19
|
+
|
|
20
|
+
describe('Drive screen: one control, one big word', () => {
|
|
21
|
+
it.each([['listening', 'LISTENING'], ['thinking', 'THINKING'], ['speaking', 'SPEAKING']])('%s shows %s', (phase, word) => {
|
|
22
|
+
const r = render(<DriveScreen controller={make(phase).controller} />);
|
|
23
|
+
expect(text(r, 'drive-state')).toBe(word);
|
|
24
|
+
});
|
|
25
|
+
it('shows the last assistant line in big text', () => {
|
|
26
|
+
const r = render(<DriveScreen controller={make('speaking').controller} />);
|
|
27
|
+
expect(text(r, 'drive-line')).toContain('Question 1 of 2');
|
|
28
|
+
});
|
|
29
|
+
it('idle: the one control starts the drive; running: it interrupts when speaking and ends otherwise', async () => {
|
|
30
|
+
const idle = make('idle', []);
|
|
31
|
+
const r = render(<DriveScreen controller={idle.controller} />);
|
|
32
|
+
await act(async () => { hostById(r, 'drive-control').props.onPress(); });
|
|
33
|
+
expect(idle.calls.start).toBe(1);
|
|
34
|
+
const talking = make('speaking');
|
|
35
|
+
const r2 = render(<DriveScreen controller={talking.controller} />);
|
|
36
|
+
await act(async () => { hostById(r2, 'drive-control').props.onPress(); });
|
|
37
|
+
expect(talking.calls.stop).toBe(1);
|
|
38
|
+
const quiet = make('listening');
|
|
39
|
+
const r3 = render(<DriveScreen controller={quiet.controller} />);
|
|
40
|
+
await act(async () => { hostById(r3, 'drive-control').props.onPress(); });
|
|
41
|
+
expect(quiet.calls.end).toBe(1);
|
|
42
|
+
});
|
|
43
|
+
it('idle greets by the configured assistant name, default Roci', () => {
|
|
44
|
+
const r = render(<DriveScreen controller={make('idle', []).controller} />);
|
|
45
|
+
expect(text(r, 'drive-line')).toContain('Roci here');
|
|
46
|
+
const r2 = render(<DriveScreen controller={make('idle', []).controller} assistantName="Pip" />);
|
|
47
|
+
expect(text(r2, 'drive-line')).toContain('Pip here');
|
|
48
|
+
});
|
|
49
|
+
it('has no text box, no speed row, no Voice/Text switch', () => {
|
|
50
|
+
const r = render(<DriveScreen controller={make('listening').controller} />);
|
|
51
|
+
expect(maybeById(r, 'converse-input')).toHaveLength(0);
|
|
52
|
+
expect(maybeById(r, 'converse-speed')).toHaveLength(0);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -48,6 +48,7 @@ export function createNativeMeetingApi(deps: {
|
|
|
48
48
|
else body.append('audio', { uri: input.audio.uri, name: 'turn.m4a', type: 'audio/mp4' } as unknown as Blob);
|
|
49
49
|
}
|
|
50
50
|
if (input.text) body.append('text', input.text);
|
|
51
|
+
if (input.briefing) body.append('briefing', input.briefing);
|
|
51
52
|
if (input.conversationId) body.append('conversation_id', input.conversationId);
|
|
52
53
|
if (input.turnId) body.append('turn_id', input.turnId);
|
|
53
54
|
const zone = input.timeZone ?? (() => { try { return Intl.DateTimeFormat().resolvedOptions().timeZone; } catch { return undefined; } })();
|
|
@@ -23,6 +23,10 @@ export function createFakeMeeting(deps: { utteranceMs?: number; speakMs?: number
|
|
|
23
23
|
const api: NativeMeetingApi & { ended: string[] } = {
|
|
24
24
|
ended,
|
|
25
25
|
async turn(input) {
|
|
26
|
+
if (input.briefing === 'start') {
|
|
27
|
+
turn += 1;
|
|
28
|
+
return { conversation_id: input.conversationId ?? 'fake-conversation', turn_id: input.turnId ?? `t${turn}`, turn, transcript: '', reply_text: 'Question 1 of 2: TEST: sample question, pick a colour. Yes or no?', audio_url: '/fake/audio', audio_reason: null, briefing: { active: true, index: 0, of: 2 } };
|
|
29
|
+
}
|
|
26
30
|
const i = turn++;
|
|
27
31
|
const out: ConverseTurnResult = {
|
|
28
32
|
conversation_id: input.conversationId ?? 'fake-conversation', turn_id: input.turnId ?? `t${i}`, turn: i + 1,
|
|
@@ -79,6 +79,7 @@ export function createMeetingIO(deps: {
|
|
|
79
79
|
await deps.audio.start({
|
|
80
80
|
onLevel: (db) => {
|
|
81
81
|
const t = now();
|
|
82
|
+
hooks?.onActivity?.();
|
|
82
83
|
// While the reply plays the voice must be louder (config.bargeInLevel): the speaker leaking into the mic is not a barge-in.
|
|
83
84
|
const playing = deps.duplex === true && deps.speaker.getState().phase === 'playing';
|
|
84
85
|
const level = dbToLevel(db) * (playing ? config.speechLevel / config.bargeInLevel : 1);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Text as RNText, View } from 'react-native';
|
|
3
|
+
import { Alert, Button, Input, useTheme } from '@startsimpli/ui-native';
|
|
4
|
+
import { quietSummary } from '../../corpus/attention/controller';
|
|
5
|
+
import type { AttentionController } from '../../corpus/attention/controller';
|
|
6
|
+
import { useControllerState } from '../components/useControllerState';
|
|
7
|
+
|
|
8
|
+
const MODES = [{ id: 'off', label: 'Never quiet' }, { id: 'auto', label: 'Schedule' }, { id: 'on', label: 'Quiet now' }] as const;
|
|
9
|
+
|
|
10
|
+
/** Quiet mode (schedule, quiet now, never quiet) and the words that count as urgent. Urgent items always get through. */
|
|
11
|
+
export function AttentionCard({ attention }: { attention: AttentionController }) {
|
|
12
|
+
const theme = useTheme();
|
|
13
|
+
const s = useControllerState({ getState: attention.getState, subscribe: attention.subscribe });
|
|
14
|
+
const a = s.settings;
|
|
15
|
+
const [words, setWords] = useState<string | null>(null);
|
|
16
|
+
const [hours, setHours] = useState<{ start?: string; end?: string }>({});
|
|
17
|
+
useEffect(() => { void attention.load(); }, [attention]);
|
|
18
|
+
if (!a) return s.error ? <View style={{ paddingHorizontal: theme.spacing.lg }}><Alert variant="destructive">{s.error}</Alert></View> : null;
|
|
19
|
+
const commit = (k: 'start' | 'end') => {
|
|
20
|
+
const n = Number(hours[k]);
|
|
21
|
+
setHours((h) => ({ ...h, [k]: undefined }));
|
|
22
|
+
if (hours[k] !== undefined && hours[k] !== '' && Number.isInteger(n) && n >= 0 && n <= 23 && n !== a.quiet[k]) void attention.save({ quiet: { [k]: n } });
|
|
23
|
+
};
|
|
24
|
+
const muted = { color: theme.colors.mutedForeground, fontSize: theme.fontSizes.sm };
|
|
25
|
+
return (
|
|
26
|
+
<View testID="attention-card" style={{ marginHorizontal: theme.spacing.lg, marginBottom: theme.spacing.md, padding: theme.spacing.md, borderRadius: 12, backgroundColor: theme.colors.muted, gap: theme.spacing.sm }}>
|
|
27
|
+
<RNText style={{ color: theme.colors.foreground, fontSize: theme.fontSizes.base, fontWeight: '600' }}>Quiet mode</RNText>
|
|
28
|
+
<RNText testID="quiet-summary" style={muted}>{quietSummary(a)}</RNText>
|
|
29
|
+
<View style={{ flexDirection: 'row', gap: theme.spacing.sm }}>
|
|
30
|
+
{MODES.map((m) => <Button key={m.id} testID={`quiet-mode-${m.id}`} title={m.label} size="sm" variant={a.quiet_mode === m.id ? 'primary' : 'outline'} disabled={s.saving} onPress={() => void attention.save({ quiet_mode: m.id })} />)}
|
|
31
|
+
</View>
|
|
32
|
+
<View style={{ flexDirection: 'row', alignItems: 'center', gap: theme.spacing.sm }}>
|
|
33
|
+
<RNText style={muted}>Quiet from</RNText>
|
|
34
|
+
<Input testID="quiet-start" value={hours.start ?? String(a.quiet.start)} keyboardType="number-pad" style={{ width: 56 }} onChangeText={(v: string) => setHours({ ...hours, start: v })} onEndEditing={() => commit('start')} />
|
|
35
|
+
<RNText style={muted}>to</RNText>
|
|
36
|
+
<Input testID="quiet-end" value={hours.end ?? String(a.quiet.end)} keyboardType="number-pad" style={{ width: 56 }} onChangeText={(v: string) => setHours({ ...hours, end: v })} onEndEditing={() => commit('end')} />
|
|
37
|
+
</View>
|
|
38
|
+
<RNText style={{ color: theme.colors.foreground, fontSize: theme.fontSizes.base, fontWeight: '600' }}>What counts as urgent</RNText>
|
|
39
|
+
<Input testID="urgent-words" value={words ?? a.urgent_words.join(', ')} placeholder="overdue, sev1, invoice" onChangeText={setWords} />
|
|
40
|
+
<Button testID="urgent-words-save" title="Save words" size="sm" disabled={s.saving || words === null} onPress={() => { const list = (words ?? '').split(',').map((w) => w.trim()).filter(Boolean); void attention.save({ urgent_words: list }).then(() => setWords(null)); }} />
|
|
41
|
+
{s.error ? <Alert variant="destructive">{s.error}</Alert> : null}
|
|
42
|
+
</View>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -4,12 +4,20 @@ import { Alert, Button, EmptyState, Header, Input, ListRow, Switch, useTheme } f
|
|
|
4
4
|
import { useControllerState } from '../components/useControllerState';
|
|
5
5
|
import type { DecisionsController } from './decisions';
|
|
6
6
|
import type { PushController } from './controller';
|
|
7
|
+
import type { AttentionController } from '../../corpus/attention/controller';
|
|
8
|
+
import { AttentionCard } from './AttentionCard';
|
|
9
|
+
import { NeedsYouCard } from './NeedsYouCard';
|
|
10
|
+
import type { NeedsYouController, NeedsYouState } from './needsYou';
|
|
11
|
+
|
|
12
|
+
const NO_STATE: NeedsYouState = { queue: null, loading: false, error: null, briefRequested: false };
|
|
13
|
+
const NO_QUEUE = { getState: () => NO_STATE, subscribe: () => () => undefined };
|
|
7
14
|
|
|
8
15
|
/** Pending decisions the relay needs answered, and the notifications switch. A tapped push opens the decision here. */
|
|
9
|
-
export function DecisionsScreen({ decisions, push, focus }: { decisions: DecisionsController; push: PushController; focus?: string }) {
|
|
16
|
+
export function DecisionsScreen({ decisions, push, focus, attention, needsYou }: { decisions: DecisionsController; push: PushController; focus?: string; attention?: AttentionController; needsYou?: NeedsYouController }) {
|
|
10
17
|
const theme = useTheme();
|
|
11
18
|
const d = useControllerState({ getState: decisions.getState, subscribe: decisions.subscribe });
|
|
12
19
|
const p = useControllerState({ getState: push.getState, subscribe: push.subscribe });
|
|
20
|
+
const ny = useControllerState(needsYou ? { getState: needsYou.getState, subscribe: needsYou.subscribe } : NO_QUEUE);
|
|
13
21
|
useEffect(() => { void decisions.load(); if (focus) void decisions.openDecision(focus); }, [decisions, focus]);
|
|
14
22
|
|
|
15
23
|
if (d.open) return <DecisionDetail decisions={decisions} />;
|
|
@@ -26,6 +34,8 @@ export function DecisionsScreen({ decisions, push, focus }: { decisions: Decisio
|
|
|
26
34
|
</View>
|
|
27
35
|
<Switch testID="push-toggle" value={p.push !== false} disabled={p.busy || p.push === null} onValueChange={(on) => void push.setPush(on)} />
|
|
28
36
|
</View>
|
|
37
|
+
{needsYou ? <NeedsYouCard needsYou={needsYou} onOpenDecision={(id) => void decisions.openDecision(id)} /> : null}
|
|
38
|
+
{attention ? <AttentionCard attention={attention} /> : null}
|
|
29
39
|
{p.error ? <View style={{ paddingHorizontal: theme.spacing.lg }}><Alert variant="destructive">{p.error}</Alert></View> : null}
|
|
30
40
|
{d.error ? <View style={{ paddingHorizontal: theme.spacing.lg }}><Alert variant="destructive">{d.error}</Alert></View> : null}
|
|
31
41
|
<FlatList
|
|
@@ -35,7 +45,7 @@ export function DecisionsScreen({ decisions, push, focus }: { decisions: Decisio
|
|
|
35
45
|
refreshing={d.loading}
|
|
36
46
|
onRefresh={() => void decisions.load()}
|
|
37
47
|
contentContainerStyle={{ flexGrow: 1 }}
|
|
38
|
-
ListEmptyComponent={d.loading ? null : <EmptyState icon="check" title="Nothing waiting" description="When the relay needs a decision from you it shows up here." />}
|
|
48
|
+
ListEmptyComponent={d.loading || (ny.queue?.items.length ?? 0) > 0 ? null : <EmptyState icon="check" title="Nothing waiting" description="When the relay needs a decision from you it shows up here." />}
|
|
39
49
|
renderItem={({ item }) => <ListRow testID={`decision-${item.id}`} title={item.title} onPress={() => void decisions.openDecision(item.id)} />}
|
|
40
50
|
/>
|
|
41
51
|
</View>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { Pressable, Text as RNText, View } from 'react-native';
|
|
3
|
+
import { Button, useTheme } from '@startsimpli/ui-native';
|
|
4
|
+
import type { QueuedItem } from '../../corpus/attention/types';
|
|
5
|
+
import { useControllerState } from '../components/useControllerState';
|
|
6
|
+
import type { NeedsYouController } from './needsYou';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* What is waiting on you: ONE queue read from the server, drawn on Talk and on Decisions. A decision row opens its card;
|
|
10
|
+
* the button starts a conversation from the queue (Talk only). Hidden when nothing waits.
|
|
11
|
+
*/
|
|
12
|
+
export function NeedsYouCard({ needsYou, active = true, onTalk, onOpenDecision }: { needsYou: NeedsYouController; active?: boolean; onTalk?: () => void; onOpenDecision?: (decisionId: string) => void }) {
|
|
13
|
+
const theme = useTheme();
|
|
14
|
+
const s = useControllerState({ getState: needsYou.getState, subscribe: needsYou.subscribe });
|
|
15
|
+
useEffect(() => { if (active) void needsYou.refresh(); }, [needsYou, active]);
|
|
16
|
+
const items = (s.queue?.items ?? []).filter((i) => i.class === 'urgent' || i.class === 'needs-answer');
|
|
17
|
+
if (!s.queue || !items.length) return null;
|
|
18
|
+
const row = (i: QueuedItem, n: number) => {
|
|
19
|
+
const body = (
|
|
20
|
+
<View style={{ flexDirection: 'row', alignItems: 'flex-start', gap: theme.spacing.sm }}>
|
|
21
|
+
{i.class === 'urgent' ? (
|
|
22
|
+
<View testID={`needs-you-badge-${n}`} style={{ backgroundColor: theme.colors.destructive, borderRadius: 6, paddingHorizontal: 6, paddingVertical: 1, marginTop: 1 }}>
|
|
23
|
+
<RNText style={{ color: '#FFFFFF', fontSize: theme.fontSizes.xs ?? 11, fontWeight: '700' }}>URGENT</RNText>
|
|
24
|
+
</View>
|
|
25
|
+
) : null}
|
|
26
|
+
<RNText testID={`needs-you-${n}`} numberOfLines={2} style={{ flex: 1, color: theme.colors.foreground, fontSize: theme.fontSizes.sm }}>{i.text}</RNText>
|
|
27
|
+
</View>
|
|
28
|
+
);
|
|
29
|
+
return i.ref && onOpenDecision
|
|
30
|
+
? <Pressable key={i.id} testID={`needs-you-open-${n}`} accessibilityRole="button" accessibilityLabel={`Open: ${i.text}`} onPress={() => onOpenDecision(i.ref!)}>{body}</Pressable>
|
|
31
|
+
: <View key={i.id}>{body}</View>;
|
|
32
|
+
};
|
|
33
|
+
return (
|
|
34
|
+
<View testID="needs-you" style={{ marginHorizontal: theme.spacing.lg, marginBottom: theme.spacing.sm, padding: theme.spacing.md, borderRadius: 12, backgroundColor: theme.colors.muted, gap: theme.spacing.xs }}>
|
|
35
|
+
<RNText testID="needs-you-title" style={{ color: theme.colors.foreground, fontSize: theme.fontSizes.base, fontWeight: '600' }}>
|
|
36
|
+
{items.length === 1 ? '1 thing needs you' : `${items.length} things need you`}
|
|
37
|
+
</RNText>
|
|
38
|
+
{items.slice(0, 5).map(row)}
|
|
39
|
+
{onTalk ? <Button testID="needs-you-talk" title="Talk it through" size="sm" onPress={() => onTalk()} /> : null}
|
|
40
|
+
</View>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -40,7 +40,7 @@ const device = (): FoundryDevice => ({
|
|
|
40
40
|
fixture: { uri: 'fixture://briefing' },
|
|
41
41
|
},
|
|
42
42
|
});
|
|
43
|
-
const config = { app: { name: 'Acme Go', scheme: 'acmego' }, tenant: { url: 'https://acme.example.com' }, features: { converse: true, notifications: true, notes: false, ask: false, planning: false, connectClaude: false }, tabs: [{ screen: 'record' }, { screen: 'converse' }, { screen: 'decisions' }] };
|
|
43
|
+
const config = { app: { name: 'Acme Go', scheme: 'acmego' }, tenant: { url: 'https://acme.example.com' }, features: { converse: true, notifications: true, notes: false, ask: false, planning: false, connectClaude: false }, tabs: [{ screen: 'record' }, { screen: 'converse' }, { screen: 'decisions' }] } as never;
|
|
44
44
|
const open = (r: ReturnType<typeof render>) => { launchArgs.tgFakeTabs = '1'; launchArgs.tgFakeConverse = '1'; launchArgs.tgTab = 'record'; return r; };
|
|
45
45
|
|
|
46
46
|
describe('Decisions over the fakes', () => {
|
|
@@ -66,6 +66,17 @@ describe('Decisions over the fakes', () => {
|
|
|
66
66
|
expect(hostById(r, 'converse-screen')).toBeTruthy();
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
+
it('a tapped urgent / call-me push opens Talk straight in the hands-free briefing', async () => {
|
|
70
|
+
open({} as never);
|
|
71
|
+
const talkConfig = { ...(config as object), tabs: [{ screen: 'record' }, { screen: 'talk' }, { screen: 'decisions' }] } as never;
|
|
72
|
+
const r = render(<FoundryApp config={talkConfig} device={device()} />);
|
|
73
|
+
await tick();
|
|
74
|
+
await act(async () => { taps.cb?.({ kind: 'attention', ping_id: 'q-fake0001' }); await new Promise((res) => setTimeout(res, 150)); });
|
|
75
|
+
expect(hostById(r, 'talk-screen')).toBeTruthy();
|
|
76
|
+
expect(hostById(r, 'drive-screen')).toBeTruthy();
|
|
77
|
+
expect(hostById(r, 'drive-state')).toBeTruthy();
|
|
78
|
+
});
|
|
79
|
+
|
|
69
80
|
it('the list shows the pending decision and the notifications switch is on', async () => {
|
|
70
81
|
open({} as never);
|
|
71
82
|
launchArgs.tgTab = 'decisions';
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
vi.mock('react-native', async () => ({ ...(await import('../../../../../ui-native/test/rn-stub')) }));
|
|
4
|
+
import { act, allText, render } from '../../../../../ui-native/test/render';
|
|
5
|
+
import type { MeetingController } from '../../../corpus/converse/meeting';
|
|
6
|
+
import { createFakeNativeCorpusApi } from '../../corpus/fake';
|
|
7
|
+
import type { TabContext } from '../../components/FoundryTabsShell';
|
|
8
|
+
import { talkTab } from '../../talk/TalkTab';
|
|
9
|
+
import { createFakeNotify } from '../fake';
|
|
10
|
+
import { createNeedsYouController } from '../needsYou';
|
|
11
|
+
|
|
12
|
+
const tick = () => act(async () => { await new Promise((res) => setTimeout(res, 40)); });
|
|
13
|
+
const IDLE = { phase: 'idle', retryable: false, lines: [], error: null, noAudio: null, conversationId: null, saved: null, relayNotice: null };
|
|
14
|
+
const ctx = (over: Partial<TabContext> = {}): TabContext => ({ tab: 'talk', active: true, route: null, push: vi.fn(), back: vi.fn(), openTab: vi.fn(), ...over });
|
|
15
|
+
|
|
16
|
+
describe('needs-you on the Talk tab', () => {
|
|
17
|
+
it('shows what is waiting, urgent first, and one button makes the assistant itself start the briefing', async () => {
|
|
18
|
+
let started = 0;
|
|
19
|
+
const typed: string[] = [];
|
|
20
|
+
const controller = { start() {}, end: async () => null, sendText: async (t: string) => { typed.push(t); }, startBriefing: async () => { started += 1; }, dismissNotice() {}, getState: () => IDLE, subscribe: () => () => undefined } as unknown as MeetingController;
|
|
21
|
+
const needsYou = createNeedsYouController({ client: createFakeNotify().client });
|
|
22
|
+
const r = render(<>{talkTab({ api: createFakeNativeCorpusApi(), converse: controller, needsYou }).render(ctx())}</>);
|
|
23
|
+
await tick();
|
|
24
|
+
expect(allText(r)).toContain('3 things need you');
|
|
25
|
+
expect(allText(r)).toContain('TEST: urgent sample A');
|
|
26
|
+
await act(async () => { r.root.findByProps({ testID: 'needs-you-talk' }).props.onPress(); });
|
|
27
|
+
expect(started).toBe(1);
|
|
28
|
+
expect(typed).toEqual([]); // the card text is never posted as something he said
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('a tapped attention push drops straight into the hands-free screen with the briefing already speaking', async () => {
|
|
32
|
+
let started = 0; let began = 0;
|
|
33
|
+
const controller = { start() { began += 1; }, end: async () => null, sendText: async () => undefined, startBriefing: async () => { started += 1; }, dismissNotice() {}, getState: () => IDLE, subscribe: () => () => undefined } as unknown as MeetingController;
|
|
34
|
+
const needsYou = createNeedsYouController({ client: createFakeNotify().client });
|
|
35
|
+
const r = render(<>{talkTab({ api: createFakeNativeCorpusApi(), converse: controller, needsYou }).render(ctx())}</>);
|
|
36
|
+
await tick();
|
|
37
|
+
expect(r.root.findAllByProps({ testID: 'drive-screen' })).toHaveLength(0);
|
|
38
|
+
await act(async () => { needsYou.requestBriefing(); });
|
|
39
|
+
await tick();
|
|
40
|
+
expect(r.root.findAllByProps({ testID: 'drive-screen' }).length).toBeGreaterThan(0);
|
|
41
|
+
expect(began).toBe(1);
|
|
42
|
+
expect(started).toBe(1);
|
|
43
|
+
expect(needsYou.getState().briefRequested).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('draws nothing when nothing is waiting', async () => {
|
|
47
|
+
const empty = { needsYou: async () => ({ items: [], counts: { urgent: 0, 'needs-answer': 0, digest: 0, noise: 0 }, callMe: false, waiting: 0 }) };
|
|
48
|
+
const controller = { start() {}, end: async () => null, sendText: async () => undefined, dismissNotice() {}, getState: () => IDLE, subscribe: () => () => undefined } as unknown as MeetingController;
|
|
49
|
+
const r = render(<>{talkTab({ api: createFakeNativeCorpusApi(), converse: controller, needsYou: createNeedsYouController({ client: empty }) }).render(ctx())}</>);
|
|
50
|
+
await tick();
|
|
51
|
+
expect(r.root.findAllByProps({ testID: 'needs-you' })).toHaveLength(0);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('controller reports a failed read instead of throwing', async () => {
|
|
55
|
+
const c = createNeedsYouController({ client: { needsYou: async () => { throw new Error('offline'); } } });
|
|
56
|
+
await c.refresh();
|
|
57
|
+
expect(c.getState()).toMatchObject({ queue: null, error: 'offline', loading: false });
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('quiet mode on the Decisions tab', () => {
|
|
62
|
+
it('shows what quiet means, switches mode, and saves a schedule hour on end of editing', async () => {
|
|
63
|
+
const { createAttentionController } = await import('../../../corpus/attention/controller');
|
|
64
|
+
const { DecisionsScreen } = await import('../DecisionsScreen');
|
|
65
|
+
const { createDecisionsController } = await import('../decisions');
|
|
66
|
+
const { createPushController } = await import('../controller');
|
|
67
|
+
const { client } = createFakeNotify();
|
|
68
|
+
const save = vi.spyOn(client, 'setAttention');
|
|
69
|
+
const attention = createAttentionController({ client });
|
|
70
|
+
const r = render(<DecisionsScreen decisions={createDecisionsController({ client })} push={createPushController({ client, registry: { register: async () => ({ registered: true, devices: 0, push_enabled: true }), unregister: async () => undefined }, device: null })} attention={attention} />);
|
|
71
|
+
await tick();
|
|
72
|
+
expect(allText(r)).toContain('Never quiet. You can add a schedule (22:00 to 7:00)');
|
|
73
|
+
await act(async () => { r.root.findByProps({ testID: 'quiet-mode-on' }).props.onPress(); });
|
|
74
|
+
await tick();
|
|
75
|
+
expect(save).toHaveBeenCalledWith({ quiet_mode: 'on' });
|
|
76
|
+
expect(allText(r)).toContain('Quiet now: only urgent items reach you.');
|
|
77
|
+
await act(async () => { r.root.findByProps({ testID: 'quiet-start' }).props.onChangeText('23'); });
|
|
78
|
+
await act(async () => { r.root.findByProps({ testID: 'quiet-start' }).props.onEndEditing(); });
|
|
79
|
+
expect(save).toHaveBeenCalledWith({ quiet: { start: 23 } });
|
|
80
|
+
await act(async () => { r.root.findByProps({ testID: 'urgent-words' }).props.onChangeText('overdue, sev1'); });
|
|
81
|
+
await act(async () => { r.root.findByProps({ testID: 'urgent-words-save' }).props.onPress(); });
|
|
82
|
+
expect(save).toHaveBeenCalledWith({ urgent_words: ['overdue', 'sev1'] });
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('one queue on Talk and Decisions', () => {
|
|
87
|
+
it('Decisions lists the same needs-you items, urgent as a badge, a decision row opens its card, and never says Nothing waiting while items wait', async () => {
|
|
88
|
+
const { createDecisionsController } = await import('../decisions');
|
|
89
|
+
const { createPushController } = await import('../controller');
|
|
90
|
+
const { DecisionsScreen } = await import('../DecisionsScreen');
|
|
91
|
+
const { client } = createFakeNotify();
|
|
92
|
+
const needsYou = createNeedsYouController({ client: { needsYou: async () => ({ items: [
|
|
93
|
+
{ id: 'q-1', text: 'TEST: sample urgent item', source: 'fleet', class: 'urgent' },
|
|
94
|
+
{ id: 'q-2', text: 'Which build goes to Quinn first?', source: 'decision', class: 'needs-answer', ref: 'dec-1' },
|
|
95
|
+
], counts: { urgent: 1, 'needs-answer': 1, digest: 0, noise: 0 }, callMe: false, waiting: 2 }) } });
|
|
96
|
+
const decisions = createDecisionsController({ client });
|
|
97
|
+
const r = render(<DecisionsScreen decisions={decisions} push={createPushController({ client, registry: { register: async () => ({ registered: true, devices: 0, push_enabled: true }), unregister: async () => undefined }, device: null })} needsYou={needsYou} />);
|
|
98
|
+
await tick();
|
|
99
|
+
expect(allText(r)).toContain('2 things need you');
|
|
100
|
+
expect(allText(r)).toContain('URGENT');
|
|
101
|
+
expect(allText(r)).not.toContain('Nothing waiting');
|
|
102
|
+
await act(async () => { r.root.findByProps({ testID: 'needs-you-open-1' }).props.onPress(); });
|
|
103
|
+
await tick();
|
|
104
|
+
expect(decisions.getState().open?.id).toBe('dec-1');
|
|
105
|
+
});
|
|
106
|
+
});
|
package/src/native/push/fake.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { AttentionSettings } from '../../corpus/attention/settings';
|
|
1
2
|
import type { DecisionRecord, NotifyClient } from '../../corpus/notify';
|
|
2
3
|
|
|
3
4
|
/** A scripted tenant for `-tgFakeTabs`: one pending decision with two questions, an on-by-default push setting. Nothing leaves the phone. */
|
|
4
5
|
export function createFakeNotify(): { client: NotifyClient; registered: string[] } {
|
|
5
6
|
let push = true;
|
|
7
|
+
let attention: AttentionSettings = { quiet_mode: 'off', quiet: { enabled: true, start: 22, end: 7, timeZone: 'America/Los_Angeles' }, quiet_active: false, urgent_words: [], call_me_at: 3, brief_hour: 8, wrap_hour: 18, notify_scope: 'decisions+fleet' };
|
|
6
8
|
const decision: DecisionRecord = {
|
|
7
9
|
id: 'dec-1', title: 'Which build goes to Quinn first?', status: 'pending', created_at: '2026-11-13T12:00:00Z',
|
|
8
10
|
questions: [{ n: 1, text: 'Ship the Siri Shortcut build now?', options: ['Yes', 'Not yet'] }, { n: 2, text: 'Anything to change first?' }],
|
|
@@ -16,8 +18,17 @@ export function createFakeNotify(): { client: NotifyClient; registered: string[]
|
|
|
16
18
|
if (decision.questions.every((q) => decision.answers.some((a) => a.n === q.n))) decision.status = 'answered';
|
|
17
19
|
return { ...decision };
|
|
18
20
|
},
|
|
19
|
-
settings: async () => ({ push, devices: 0 }),
|
|
21
|
+
settings: async () => ({ push, devices: 0, attention }),
|
|
20
22
|
setPush: async (on) => { push = on; return { push, devices: 0 }; },
|
|
23
|
+
setAttention: async (patch) => { attention = { ...attention, ...patch, quiet: { ...attention.quiet, ...patch.quiet } } as AttentionSettings; attention.quiet_active = attention.quiet_mode === 'on'; return attention; },
|
|
24
|
+
needsYou: async () => ({
|
|
25
|
+
items: [
|
|
26
|
+
{ id: 'q-fake0001', text: 'TEST: urgent sample A, no action needed', source: 'fleet', class: 'urgent' },
|
|
27
|
+
{ id: 'q-fake0002', text: 'Approve the staging promote', source: 'fleet', class: 'needs-answer' },
|
|
28
|
+
{ id: 'q-fake0003', text: decision.title, source: 'decision', class: 'needs-answer' },
|
|
29
|
+
],
|
|
30
|
+
counts: { urgent: 1, 'needs-answer': 2, digest: 0, noise: 0 }, callMe: true, waiting: 3,
|
|
31
|
+
}),
|
|
21
32
|
};
|
|
22
33
|
return { client, registered: [] };
|
|
23
34
|
}
|
package/src/native/push/index.ts
CHANGED
|
@@ -5,3 +5,6 @@ export { createDecisionsController, type DecisionsController, type DecisionsStat
|
|
|
5
5
|
export { decisionsTab } from './tab';
|
|
6
6
|
export { DecisionsScreen } from './DecisionsScreen';
|
|
7
7
|
export { createFakeNotify } from './fake';
|
|
8
|
+
export { createNeedsYouController, type NeedsYouController, type NeedsYouState } from './needsYou';
|
|
9
|
+
export { AttentionCard } from './AttentionCard';
|
|
10
|
+
export { NeedsYouCard } from './NeedsYouCard';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** The "needs you" queue on the phone: read on demand (a tapped push, the Talk tab coming on screen). */
|
|
2
|
+
import type { NeedsYouQueue } from '../../corpus/attention/types';
|
|
3
|
+
import type { NotifyClient } from '../../corpus/notify';
|
|
4
|
+
|
|
5
|
+
export interface NeedsYouState { queue: NeedsYouQueue | null; loading: boolean; error: string | null; /** A tapped push asked for the briefing: Talk starts it (hands-free) and clears this. */ briefRequested: boolean }
|
|
6
|
+
export interface NeedsYouController {
|
|
7
|
+
getState(): NeedsYouState;
|
|
8
|
+
subscribe(l: () => void): () => void;
|
|
9
|
+
refresh(): Promise<void>;
|
|
10
|
+
/** A tapped attention push: drop straight into the spoken briefing. */
|
|
11
|
+
requestBriefing(): void;
|
|
12
|
+
clearBriefRequest(): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createNeedsYouController(deps: { client: Pick<NotifyClient, 'needsYou'> }): NeedsYouController {
|
|
16
|
+
let s: NeedsYouState = { queue: null, loading: false, error: null, briefRequested: false };
|
|
17
|
+
const ls = new Set<() => void>();
|
|
18
|
+
const set = (p: Partial<NeedsYouState>) => { s = { ...s, ...p }; ls.forEach((l) => l()); };
|
|
19
|
+
return {
|
|
20
|
+
getState: () => s,
|
|
21
|
+
requestBriefing: () => set({ briefRequested: true }),
|
|
22
|
+
clearBriefRequest: () => { if (s.briefRequested) set({ briefRequested: false }); },
|
|
23
|
+
subscribe: (l) => { ls.add(l); return () => ls.delete(l); },
|
|
24
|
+
async refresh() {
|
|
25
|
+
set({ loading: true, error: null });
|
|
26
|
+
try { set({ queue: await deps.client.needsYou() }); } catch (e) { set({ error: e instanceof Error ? e.message : String(e) }); } finally { set({ loading: false }); }
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
package/src/native/push/tab.tsx
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { FoundryTab } from '../components/FoundryTabsShell';
|
|
2
2
|
import { DecisionsScreen } from './DecisionsScreen';
|
|
3
3
|
import type { DecisionsController } from './decisions';
|
|
4
|
+
import type { AttentionController } from '../../corpus/attention/controller';
|
|
5
|
+
import type { NeedsYouController } from './needsYou';
|
|
4
6
|
import type { PushController } from './controller';
|
|
5
7
|
|
|
6
8
|
/** The Decisions tab: pending decisions plus the notifications switch. A deep link `<scheme>://tab/<key>/<decision id>` opens one. */
|
|
7
|
-
export function decisionsTab(controllers: { decisions: DecisionsController; push: PushController }, over: Partial<Pick<FoundryTab, 'key' | 'label'>> = {}): FoundryTab {
|
|
8
|
-
return { key: 'decisions', label: 'Decisions', resetOnLeave: true, ...over, render: ({ route }) => <DecisionsScreen decisions={controllers.decisions} push={controllers.push} focus={route?.id} /> };
|
|
9
|
+
export function decisionsTab(controllers: { decisions: DecisionsController; push: PushController; attention?: AttentionController; needsYou?: NeedsYouController }, over: Partial<Pick<FoundryTab, 'key' | 'label'>> = {}): FoundryTab {
|
|
10
|
+
return { key: 'decisions', label: 'Decisions', resetOnLeave: true, ...over, render: ({ route }) => <DecisionsScreen decisions={controllers.decisions} push={controllers.push} focus={route?.id} attention={controllers.attention} needsYou={controllers.needsYou} /> };
|
|
9
11
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { useControllerState } from '../components/useControllerState';
|
|
2
3
|
import { View } from 'react-native';
|
|
3
|
-
import { Header } from '@startsimpli/ui-native';
|
|
4
|
+
import { Button, Header } from '@startsimpli/ui-native';
|
|
4
5
|
import { TAB_COPY } from '../../corpus/nav-copy';
|
|
5
6
|
import { projectIdOf } from '../../corpus/ask-projects';
|
|
6
7
|
import type { MeetingController } from '../../corpus/converse/meeting';
|
|
7
8
|
import type { FoundryTab, TabContext } from '../components/FoundryTabsShell';
|
|
8
9
|
import type { NativeCorpusApi } from '../corpus/api';
|
|
9
10
|
import { ConverseScreen } from '../converse/ConverseScreen';
|
|
11
|
+
import { DriveScreen } from '../converse/DriveScreen';
|
|
10
12
|
import type { SpeedStore } from '../converse/speed';
|
|
13
|
+
import { NeedsYouCard } from '../push/NeedsYouCard';
|
|
14
|
+
import type { NeedsYouController } from '../push/needsYou';
|
|
11
15
|
import { AskScreen } from '../screens/ask/AskScreen';
|
|
12
16
|
import { createAskController } from '../screens/ask/controller';
|
|
13
17
|
|
|
@@ -20,6 +24,8 @@ export interface TalkTabOptions {
|
|
|
20
24
|
speed?: SpeedStore | null;
|
|
21
25
|
key?: string;
|
|
22
26
|
label?: string;
|
|
27
|
+
/** What is waiting on the person; drawn above the thread when anything is. Absent when notifications are off. */
|
|
28
|
+
needsYou?: NeedsYouController | null;
|
|
23
29
|
/** The Library tab, where a cited source opens. */
|
|
24
30
|
libraryKey?: string;
|
|
25
31
|
/** The Plan tab, where a cited PROJECT opens. */
|
|
@@ -28,11 +34,27 @@ export interface TalkTabOptions {
|
|
|
28
34
|
|
|
29
35
|
function TalkBody({ opts, ctx }: { opts: TalkTabOptions; ctx: TabContext }) {
|
|
30
36
|
const { api, converse, speed, libraryKey = 'library', planKey } = opts;
|
|
37
|
+
// Answers given in a briefing leave the queue: re-read it as the thread grows.
|
|
38
|
+
const lineCount = useControllerState(converse ? { getState: () => converse.getState().lines.length, subscribe: (l: () => void) => converse.subscribe(l) } : { getState: () => 0, subscribe: () => () => undefined });
|
|
39
|
+
useEffect(() => { if (lineCount > 0) void opts.needsYou?.refresh(); }, [lineCount, opts.needsYou]);
|
|
40
|
+
// DRIVE mode: no per-turn taps. A tapped attention push drops straight into it with the briefing already speaking.
|
|
41
|
+
const [drive, setDrive] = useState(false);
|
|
42
|
+
const briefRequested = useControllerState(opts.needsYou ? { getState: () => opts.needsYou!.getState().briefRequested, subscribe: (l: () => void) => opts.needsYou!.subscribe(l) } : { getState: () => false, subscribe: () => () => undefined });
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!briefRequested || !converse) return;
|
|
45
|
+
opts.needsYou?.clearBriefRequest();
|
|
46
|
+
setDrive(true);
|
|
47
|
+
converse.start();
|
|
48
|
+
void converse.startBriefing();
|
|
49
|
+
}, [briefRequested, converse, opts.needsYou]);
|
|
31
50
|
const ask = useMemo(() => (converse ? null : createAskController({ api: api.ask, scope: api.scope, listProjects: async () => (await api.corpus.listFocusChoices?.()) ?? [] })), [api, converse]);
|
|
51
|
+
if (drive && converse) return <View style={{ flex: 1 }} testID="talk-screen"><DriveScreen controller={converse} onExit={() => setDrive(false)} /></View>;
|
|
32
52
|
return (
|
|
33
53
|
<View style={{ flex: 1 }} testID="talk-screen">
|
|
34
54
|
<Header large testID="talk-header" title={TAB_COPY.talk.label} />
|
|
35
55
|
{/* ONE conversation: notes, questions, to-dos and the relay all go through the same thread, no modes. */}
|
|
56
|
+
{converse && opts.needsYou ? <NeedsYouCard needsYou={opts.needsYou} active={ctx.active} onTalk={() => void converse.startBriefing()} /> : null}
|
|
57
|
+
{converse ? <Button testID="talk-drive" title="Drive mode: hands-free" variant="outline" size="sm" onPress={() => { setDrive(true); converse.start(); }} /> : null}
|
|
36
58
|
{converse ? (
|
|
37
59
|
<ConverseScreen
|
|
38
60
|
controller={converse}
|