@startsimpli/integrations 0.2.121 → 0.2.123
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__/briefing-route.test.ts +9 -1
- package/src/corpus/briefing/generate.ts +6 -5
- package/src/native/app/FoundryApp.tsx +3 -3
- package/src/native/app/__tests__/launch.test.ts +2 -1
- package/src/native/app/config/defaults.ts +1 -1
- package/src/native/app/config/types.ts +2 -0
- package/src/native/app/device.ts +12 -0
- package/src/native/app/launch.ts +4 -0
- package/src/native/app/screens/RecordScreen.tsx +8 -2
- package/src/native/app/services.ts +33 -2
- package/src/native/app/strings.ts +18 -0
- package/src/native/briefing/BriefingCard.tsx +67 -0
- package/src/native/briefing/__tests__/BriefingCard.test.tsx +113 -0
- package/src/native/briefing/__tests__/audioHandoff.test.ts +168 -0
- package/src/native/briefing/__tests__/briefingController.test.ts +149 -0
- package/src/native/briefing/__tests__/recordHandoff.test.tsx +50 -0
- package/src/native/briefing/api.ts +37 -0
- package/src/native/briefing/audioPlayer.ts +181 -0
- package/src/native/briefing/controller.ts +160 -0
- package/src/native/briefing/fake.ts +35 -0
- package/src/native/briefing/index.ts +7 -0
- package/src/native/index.ts +1 -0
- package/src/native/recording/session.ts +6 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The 'What's on the plate' flow as a framework-free controller: tap -> fetch (or today's cached briefing) -> play, with
|
|
3
|
+
* the transcript, the item being spoken, stop and replay. Text always survives: no audio or a player that cannot start
|
|
4
|
+
* leaves the words on screen with a note, and a failed request leaves a retry message, never a blank card.
|
|
5
|
+
*/
|
|
6
|
+
import type { BriefingEntry, BriefingResult } from '../../corpus/briefing';
|
|
7
|
+
import type { PlaybackSource, PlayerState } from './audioPlayer';
|
|
8
|
+
|
|
9
|
+
export type BriefingPhase = 'idle' | 'loading' | 'playing' | 'paused' | 'ended' | 'text' | 'error';
|
|
10
|
+
|
|
11
|
+
export interface BriefingState {
|
|
12
|
+
phase: BriefingPhase;
|
|
13
|
+
text: string;
|
|
14
|
+
items: BriefingEntry[];
|
|
15
|
+
/** The item being spoken right now (from the playback position), or null for greeting and sign-off. */
|
|
16
|
+
currentId: string | null;
|
|
17
|
+
/** A one-line explanation shown with the text (no audio, empty day). */
|
|
18
|
+
note: string | null;
|
|
19
|
+
error: string | null;
|
|
20
|
+
empty: boolean;
|
|
21
|
+
offsets: Array<{ id: string; start: number; end: number }>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface BriefingMessages {
|
|
25
|
+
failed: string;
|
|
26
|
+
empty: string;
|
|
27
|
+
textOnly: string;
|
|
28
|
+
audioFailed: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface BriefingApi {
|
|
32
|
+
fetch(options?: { force?: boolean }): Promise<BriefingResult>;
|
|
33
|
+
audioSource(result: BriefingResult): Promise<PlaybackSource | null>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface BriefingPlayer {
|
|
37
|
+
getState(): PlayerState;
|
|
38
|
+
subscribe(cb: (s: PlayerState) => void): () => void;
|
|
39
|
+
play(source: PlaybackSource): Promise<void>;
|
|
40
|
+
stop(): Promise<void>;
|
|
41
|
+
handoffToRecording(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const BLANK: BriefingState = { phase: 'idle', text: '', items: [], currentId: null, note: null, error: null, empty: false, offsets: [] };
|
|
45
|
+
|
|
46
|
+
export function createBriefingController(deps: {
|
|
47
|
+
api: BriefingApi;
|
|
48
|
+
player: BriefingPlayer;
|
|
49
|
+
messages: BriefingMessages;
|
|
50
|
+
now?: () => number;
|
|
51
|
+
diag?: { log(event: string, fields?: Record<string, unknown>): void };
|
|
52
|
+
}) {
|
|
53
|
+
const now = deps.now ?? Date.now;
|
|
54
|
+
let state: BriefingState = BLANK;
|
|
55
|
+
const listeners = new Set<() => void>();
|
|
56
|
+
let cache: { day: string; result: BriefingResult } | null = null;
|
|
57
|
+
let current: BriefingResult | null = null;
|
|
58
|
+
let busy = false;
|
|
59
|
+
const set = (patch: Partial<BriefingState>) => {
|
|
60
|
+
state = { ...state, ...patch };
|
|
61
|
+
listeners.forEach((l) => l());
|
|
62
|
+
};
|
|
63
|
+
const dayKey = () => new Date(now()).toDateString();
|
|
64
|
+
|
|
65
|
+
const currentOf = (p: PlayerState): string | null => {
|
|
66
|
+
if (!current || !p.durationMillis || p.positionMillis <= 0) return null;
|
|
67
|
+
const at = Math.floor((p.positionMillis / p.durationMillis) * current.text.length);
|
|
68
|
+
return state.offsets.find((o) => at >= o.start && at < o.end)?.id ?? null;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
deps.player.subscribe((p) => {
|
|
72
|
+
if (!current || busy) return;
|
|
73
|
+
if (p.phase === 'playing') set({ phase: 'playing', currentId: currentOf(p) });
|
|
74
|
+
else if (p.phase === 'paused') set({ phase: 'paused' });
|
|
75
|
+
else if (p.phase === 'ended') set({ phase: 'ended', currentId: null });
|
|
76
|
+
else if (p.phase === 'failed') set({ phase: 'text', note: deps.messages.audioFailed, currentId: null });
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
async function playCurrent(): Promise<void> {
|
|
80
|
+
if (!current) return;
|
|
81
|
+
const source = await deps.api.audioSource(current);
|
|
82
|
+
if (!source) { set({ phase: 'text', note: deps.messages.textOnly, currentId: null }); return; }
|
|
83
|
+
try {
|
|
84
|
+
await deps.player.play(source);
|
|
85
|
+
set({ phase: 'playing', currentId: null, note: state.empty ? deps.messages.empty : null });
|
|
86
|
+
} catch (e) {
|
|
87
|
+
deps.diag?.log('briefing.play-failed', { error: e instanceof Error ? e.message : String(e) });
|
|
88
|
+
set({ phase: 'text', note: deps.messages.audioFailed, currentId: null });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
getState: () => state,
|
|
94
|
+
subscribe(listener: () => void) {
|
|
95
|
+
listeners.add(listener);
|
|
96
|
+
return () => { listeners.delete(listener); };
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
/** The button: load today's briefing (once a day) and play it. Also the retry after an error. */
|
|
100
|
+
async start(): Promise<void> {
|
|
101
|
+
if (busy) return;
|
|
102
|
+
busy = true;
|
|
103
|
+
try {
|
|
104
|
+
if (!cache || cache.day !== dayKey()) {
|
|
105
|
+
set({ phase: 'loading', error: null, note: null });
|
|
106
|
+
try {
|
|
107
|
+
cache = { day: dayKey(), result: await deps.api.fetch() };
|
|
108
|
+
} catch (e) {
|
|
109
|
+
deps.diag?.log('briefing.failed', { error: e instanceof Error ? e.message : String(e), status: (e as { status?: number }).status });
|
|
110
|
+
set({ phase: 'error', error: deps.messages.failed, text: '', items: [], offsets: [] });
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
current = cache.result;
|
|
115
|
+
set({
|
|
116
|
+
text: current.text, items: current.items, offsets: current.context.offsets, error: null, currentId: null,
|
|
117
|
+
empty: current.items.length === 0, note: current.items.length === 0 ? deps.messages.empty : null, phase: 'loading',
|
|
118
|
+
});
|
|
119
|
+
await playCurrent();
|
|
120
|
+
} finally {
|
|
121
|
+
busy = false;
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
async stop(): Promise<void> {
|
|
126
|
+
await deps.player.stop();
|
|
127
|
+
set({ phase: 'ended', currentId: null });
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
async replay(): Promise<void> {
|
|
131
|
+
if (busy || !current) return;
|
|
132
|
+
busy = true;
|
|
133
|
+
try { await playCurrent(); } finally { busy = false; }
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
/** The reply press: playback ends and the session is released for the recorder. */
|
|
137
|
+
async handoffToRecording(): Promise<void> {
|
|
138
|
+
if (state.phase !== 'playing' && state.phase !== 'paused') return;
|
|
139
|
+
await deps.player.handoffToRecording();
|
|
140
|
+
set({ phase: 'ended', currentId: null });
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type BriefingController = ReturnType<typeof createBriefingController>;
|
|
146
|
+
|
|
147
|
+
/** The text cut into plain and current parts, for rendering the spoken item emphasised. Every character survives. */
|
|
148
|
+
export function transcriptParts(
|
|
149
|
+
text: string,
|
|
150
|
+
offsets: Array<{ id: string; start: number; end: number }>,
|
|
151
|
+
currentId: string | null,
|
|
152
|
+
): Array<{ text: string; current: boolean }> {
|
|
153
|
+
const hit = currentId ? offsets.find((o) => o.id === currentId) : undefined;
|
|
154
|
+
if (!hit) return [{ text, current: false }];
|
|
155
|
+
return [
|
|
156
|
+
{ text: text.slice(0, hit.start), current: false },
|
|
157
|
+
{ text: text.slice(hit.start, hit.end), current: true },
|
|
158
|
+
{ text: text.slice(hit.end), current: false },
|
|
159
|
+
].filter((p) => p.text.length > 0);
|
|
160
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BriefingResult } from '../../corpus/briefing';
|
|
2
|
+
import type { PlaybackSource } from './audioPlayer';
|
|
3
|
+
import type { BriefingApi } from './controller';
|
|
4
|
+
|
|
5
|
+
const TEXT = "Good morning. You have three things on your plate today. Send Dana the take-home assignment, it is overdue. Review the launch checklist, due today. Book the car service. That is everything.";
|
|
6
|
+
|
|
7
|
+
/** The fixed briefing `-tgFakeBriefing` returns: no network, no sign-in. `clip` is the bundled audio it plays. */
|
|
8
|
+
export function createFakeBriefingApi(clip: PlaybackSource | undefined, delayMs = 400): BriefingApi {
|
|
9
|
+
const at = (needle: string) => { const start = TEXT.indexOf(needle); return { start, end: start + needle.length }; };
|
|
10
|
+
const result: BriefingResult = {
|
|
11
|
+
briefingId: 'fake-briefing',
|
|
12
|
+
text: TEXT,
|
|
13
|
+
audioUrl: clip ? 'fixture://briefing' : null,
|
|
14
|
+
...(clip ? {} : { audioReason: 'No fixture audio is bundled.' }),
|
|
15
|
+
items: [
|
|
16
|
+
{ id: 't1', title: 'Send Dana the take-home assignment', kind: 'overdue', group: 'Hiring', dueDate: '2026-11-03' },
|
|
17
|
+
{ id: 't2', title: 'Review the launch checklist', kind: 'due_today', group: 'Launch', dueDate: '2026-11-05' },
|
|
18
|
+
{ id: 't3', title: 'Book the car service', kind: 'in_progress', group: 'Personal', dueDate: null },
|
|
19
|
+
],
|
|
20
|
+
remaining: 0,
|
|
21
|
+
context: {
|
|
22
|
+
itemIds: ['t1', 't2', 't3'], localDate: '2026-11-05', timeZone: 'UTC',
|
|
23
|
+
offsets: [
|
|
24
|
+
{ id: 't1', ...at('Send Dana the take-home assignment, it is overdue.') },
|
|
25
|
+
{ id: 't2', ...at('Review the launch checklist, due today.') },
|
|
26
|
+
{ id: 't3', ...at('Book the car service.') },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
scriptSource: 'template', cached: false, ms: delayMs,
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
fetch: () => new Promise((resolve) => setTimeout(() => resolve(result), delayMs)),
|
|
33
|
+
audioSource: async () => (clip ?? null),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createAudioPlayer } from './audioPlayer';
|
|
2
|
+
export type { AudioPlayer, AudioPlayerDriver, PlaybackSource, PlaybackStatus, PlayerPhase, PlayerState } from './audioPlayer';
|
|
3
|
+
export { createBriefingApi } from './api';
|
|
4
|
+
export { createBriefingController, transcriptParts } from './controller';
|
|
5
|
+
export type { BriefingApi, BriefingController, BriefingMessages, BriefingPhase, BriefingPlayer, BriefingState } from './controller';
|
|
6
|
+
export { createFakeBriefingApi } from './fake';
|
|
7
|
+
export { BriefingCard } from './BriefingCard';
|
package/src/native/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ export { NoteDetailScreen, type NoteDetailScreenProps } from './components/NoteD
|
|
|
15
15
|
export { NotesShell, type NotesShellProps } from './components/NotesShell';
|
|
16
16
|
export { FoundryTabsShell, type FoundryTab, type FoundryTabsShellProps, type TabContext } from './components/FoundryTabsShell';
|
|
17
17
|
export * from './recording';
|
|
18
|
+
export * from './briefing';
|
|
18
19
|
export * from './app';
|
|
19
20
|
export * from './shell/navigator';
|
|
20
21
|
export * from './shell/overflow';
|
|
@@ -103,6 +103,12 @@ export function createSession(deps: { centralUrl: string; storage: SecretStore;
|
|
|
103
103
|
deps.diag?.log('auth.signed-out', { reason: 'user' });
|
|
104
104
|
set('signedOut');
|
|
105
105
|
},
|
|
106
|
+
/** The current access token (renewed first when stale), for a request the player makes itself. Null when signed out. */
|
|
107
|
+
async bearer(): Promise<string | null> {
|
|
108
|
+
if (state !== 'signedIn') return null;
|
|
109
|
+
try { await auth.ensureFresh(); } catch (e) { if (await handleFailure(e)) return null; }
|
|
110
|
+
return auth.getAccessToken();
|
|
111
|
+
},
|
|
106
112
|
async authorizedFetch(url: string, init?: RequestInit) {
|
|
107
113
|
try {
|
|
108
114
|
const res = await auth.authorizedFetch(url, init);
|