@startsimpli/integrations 0.2.145 → 0.2.147

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.
Files changed (76) hide show
  1. package/package.json +3 -3
  2. package/src/__tests__/briefing-actions.test.ts +2 -0
  3. package/src/__tests__/briefing-reply.test.ts +334 -0
  4. package/src/__tests__/corpus-tracker.test.tsx +79 -0
  5. package/src/__tests__/extract-classify.test.ts +9 -4
  6. package/src/__tests__/owner-backfill.test.ts +114 -0
  7. package/src/__tests__/owner-link.test.ts +115 -0
  8. package/src/__tests__/owner-picker.test.tsx +70 -0
  9. package/src/__tests__/private-items.test.ts +63 -0
  10. package/src/__tests__/roster.test.ts +27 -0
  11. package/src/__tests__/task-detail-private.test.tsx +44 -0
  12. package/src/__tests__/tracker-sort.test.ts +28 -0
  13. package/src/components/index.ts +1 -0
  14. package/src/components/pages/TaskDetailPage.tsx +51 -2
  15. package/src/components/pages/TrackerPage.tsx +28 -6
  16. package/src/components/pages/task-tracker/OwnerPicker.tsx +82 -0
  17. package/src/components/pages/tracker/TrackerBoard.tsx +45 -0
  18. package/src/components/pages/tracker/TrackerToolbar.tsx +44 -0
  19. package/src/corpus/briefing/actions/execute.ts +5 -4
  20. package/src/corpus/briefing/actions/log.ts +1 -1
  21. package/src/corpus/briefing/actions/types.ts +21 -0
  22. package/src/corpus/briefing/index.ts +1 -0
  23. package/src/corpus/briefing/intent/model.ts +3 -0
  24. package/src/corpus/briefing/intent/resolve.ts +14 -6
  25. package/src/corpus/briefing/intent/types.ts +7 -0
  26. package/src/corpus/briefing/reply/handle.ts +174 -0
  27. package/src/corpus/briefing/reply/index.ts +6 -0
  28. package/src/corpus/briefing/reply/respond.ts +95 -0
  29. package/src/corpus/briefing/reply/types.ts +112 -0
  30. package/src/corpus/briefing/store.ts +14 -0
  31. package/src/corpus/client.ts +24 -18
  32. package/src/corpus/entities.ts +7 -0
  33. package/src/corpus/extract.ts +21 -0
  34. package/src/corpus/index.ts +4 -0
  35. package/src/corpus/owner-backfill.ts +200 -0
  36. package/src/corpus/owner-link.ts +160 -0
  37. package/src/corpus/roster.ts +53 -0
  38. package/src/corpus/tracker-groups.ts +8 -4
  39. package/src/corpus/tracker-sort.ts +51 -0
  40. package/src/corpus/types.ts +24 -1
  41. package/src/native/app/FoundryApp.tsx +25 -7
  42. package/src/native/app/__tests__/briefingLink.test.tsx +57 -0
  43. package/src/native/app/__tests__/briefingServices.test.ts +92 -0
  44. package/src/native/app/__tests__/launch.test.ts +2 -1
  45. package/src/native/app/briefingServices.ts +101 -0
  46. package/src/native/app/config/__tests__/briefingConfig.test.ts +49 -0
  47. package/src/native/app/config/links.ts +4 -1
  48. package/src/native/app/config/types.ts +13 -1
  49. package/src/native/app/config/validate.ts +20 -2
  50. package/src/native/app/data.ts +3 -3
  51. package/src/native/app/device.ts +3 -0
  52. package/src/native/app/launch.ts +4 -0
  53. package/src/native/app/registry.tsx +3 -1
  54. package/src/native/app/screens/RecordScreen.tsx +3 -2
  55. package/src/native/app/services.ts +11 -30
  56. package/src/native/app/strings.ts +28 -0
  57. package/src/native/briefing/BriefingCard.tsx +14 -2
  58. package/src/native/briefing/BriefingReply.tsx +68 -0
  59. package/src/native/briefing/__tests__/BriefingReply.test.tsx +144 -0
  60. package/src/native/briefing/__tests__/fakeReply.test.ts +46 -0
  61. package/src/native/briefing/__tests__/notify.test.ts +42 -1
  62. package/src/native/briefing/__tests__/replyApi.test.ts +43 -0
  63. package/src/native/briefing/__tests__/replyController.test.ts +230 -0
  64. package/src/native/briefing/__tests__/replyPosition.test.ts +116 -0
  65. package/src/native/briefing/audioPlayer.ts +9 -2
  66. package/src/native/briefing/controller.ts +50 -5
  67. package/src/native/briefing/fake.ts +25 -18
  68. package/src/native/briefing/fakeReply.ts +65 -0
  69. package/src/native/briefing/index.ts +8 -3
  70. package/src/native/briefing/notify.ts +42 -0
  71. package/src/native/briefing/reply.ts +261 -0
  72. package/src/native/briefing/replyApi.ts +82 -0
  73. package/src/native/recording/__tests__/deeplink.test.ts +20 -0
  74. package/src/native/recording/deeplink.ts +7 -0
  75. package/src/native/tracker/__tests__/itemsChanged.test.ts +13 -0
  76. package/src/native/tracker/tab.tsx +4 -1
@@ -0,0 +1,101 @@
1
+ import { createDiagnostics } from '../recording/diagnostics';
2
+ import { createPermissionFlow } from '../recording/permissions';
3
+ import { createRecorderAudio } from '../recording/recorderAudio';
4
+ import type { createSession } from '../recording/session';
5
+ import { createAudioPlayer } from '../briefing/audioPlayer';
6
+ import { createBriefingApi } from '../briefing/api';
7
+ import { createBriefingController } from '../briefing/controller';
8
+ import { createFakeBriefingApi } from '../briefing/fake';
9
+ import { createFakeBriefingReplyApi } from '../briefing/fakeReply';
10
+ import { syncMorningFromCentral, syncMorningNotification, type MorningNotifier } from '../briefing/notify';
11
+ import { createBriefingReplyController } from '../briefing/reply';
12
+ import { createBriefingReplyApi } from '../briefing/replyApi';
13
+ import type { FakeNativeCorpusApi } from '../corpus/fake';
14
+ import type { FoundryAppConfig } from './config/types';
15
+ import type { FoundryDevice } from './device';
16
+ import type { FoundryStrings } from './strings';
17
+
18
+ /** What `-tgFakeBriefing` runs over: the fake tenant the tabs read, and the lines `-tgFakeReply` "says". */
19
+ export interface FakeBriefingDeps {
20
+ corpus: FakeNativeCorpusApi;
21
+ script: string[];
22
+ }
23
+
24
+ const newReplyId = () => `br-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
25
+ const tick = (fn: () => void, ms: number) => { const h = setInterval(fn, ms); return () => clearInterval(h); };
26
+ const wait = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
27
+ const zone = () => { try { return Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC'; } catch { return 'UTC'; } };
28
+
29
+ /**
30
+ * 'What's on the plate': the briefing flow over the device's playback driver (sharing the recorder's session inspector),
31
+ * the hold-to-talk reply (its own recorder instance: a reply is never a voice note), and the morning notification.
32
+ */
33
+ export function createBriefing(deps: {
34
+ config: FoundryAppConfig;
35
+ device: FoundryDevice;
36
+ session: ReturnType<typeof createSession>;
37
+ diag: ReturnType<typeof createDiagnostics>;
38
+ strings: FoundryStrings;
39
+ fake: FakeBriefingDeps | null;
40
+ }) {
41
+ const { config, device, session, diag, strings, fake } = deps;
42
+ const dev = device.briefing;
43
+ if (!dev) throw new Error('features.briefing is on but the device supplies no briefing bindings');
44
+ const inspector = dev.session ?? device.recording?.session;
45
+ if (!inspector) throw new Error('features.briefing needs an audio-session inspector (device.briefing.session or device.recording.session)');
46
+ const makePlayer = () => createAudioPlayer({ driver: dev.driver, session: inspector, diag, poll: tick, sleep: wait });
47
+ const player = makePlayer();
48
+ const api = fake
49
+ ? createFakeBriefingApi(dev.fixture)
50
+ : createBriefingApi({ tandemUrl: config.tenant.url, authorizedFetch: session.authorizedFetch, bearer: session.bearer });
51
+ const controller = createBriefingController({
52
+ api, player, diag,
53
+ messages: { failed: strings.briefingFailed, empty: strings.briefingEmpty, textOnly: strings.briefingTextOnly, audioFailed: strings.briefingAudioFailed },
54
+ });
55
+
56
+ const changed = new Set<() => void>();
57
+ const itemsChanged = { subscribe(l: () => void) { changed.add(l); return () => { changed.delete(l); }; } };
58
+ let reply: ReturnType<typeof createBriefingReplyController> | null = null;
59
+ if (config.briefing.reply) {
60
+ const rec = device.recording;
61
+ if (!rec) throw new Error('features.briefing.reply needs the recording bindings (features.recording on, device.recording supplied)');
62
+ // Its own recorder audio: an interruption here cancels nothing else, and a reply never reaches the upload queue.
63
+ const audio = createRecorderAudio({
64
+ driver: rec.driver, session: rec.session, fs: { size: rec.fileSize }, poll: tick, sleep: wait, diag, onInterrupted: () => undefined,
65
+ });
66
+ const permissions = createPermissionFlow({ perms: rec.permissions, openSettings: rec.openSettings, log: diag.log });
67
+ const replyApi = fake
68
+ ? createFakeBriefingReplyApi({ corpus: fake.corpus, script: fake.script })
69
+ : createBriefingReplyApi({ tandemUrl: config.tenant.url, authorizedFetch: session.authorizedFetch, bearer: session.bearer, filePart: rec.filePart });
70
+ reply = createBriefingReplyController({
71
+ briefing: controller, api: replyApi, audio, speaker: makePlayer(), removeFile: rec.removeFile, ensurePermission: permissions.ensure,
72
+ confirm: config.briefing.confirm, newId: newReplyId, diag, allowSilence: Boolean(fake),
73
+ strings: { micDenied: strings.micDenied, tooShort: strings.replyTooShort, notHeard: strings.replyNotHeard, failed: strings.replyFailed, noAudio: strings.replyNoAudio },
74
+ onChanged: () => { diag.log('reply.changed'); changed.forEach((l) => l()); },
75
+ });
76
+ }
77
+
78
+ /** Make the phone's morning notification match the person's setting (a fixed 07:30 in the fake). Never throws. */
79
+ async function syncNotification(): Promise<void> {
80
+ if (!config.briefing.notification) return;
81
+ // The fakes never touch the device's notification centre: they log what would be scheduled.
82
+ const notifier: MorningNotifier | undefined = fake ? {
83
+ schedule: async (plan) => { diag.log('notification.scheduled', { time: plan.time, deepLink: plan.deepLink, repeat: plan.repeat }); return 'fake'; },
84
+ cancel: async () => { diag.log('notification.cancelled'); },
85
+ } : dev?.notifier;
86
+ if (!notifier) return;
87
+ try {
88
+ const plan = fake
89
+ ? await syncMorningNotification(notifier, { enabled: true, morningTime: '07:30', timeZone: zone(), scheme: config.app.scheme })
90
+ : await syncMorningFromCentral({
91
+ notifier, authorizedFetch: session.authorizedFetch, centralUrl: config.tenant.centralUrl,
92
+ tenantSlug: config.tenant.slug ?? config.brand.authApp, scheme: config.app.scheme, timeZone: zone(),
93
+ });
94
+ diag.log('notification.synced', { scheduled: Boolean(plan), time: plan?.time ?? null });
95
+ } catch (e) {
96
+ diag.log('notification.failed', { error: e instanceof Error ? e.message : String(e) });
97
+ }
98
+ }
99
+
100
+ return { controller, player, reply, syncNotification, itemsChanged };
101
+ }
@@ -0,0 +1,49 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createLinkResolver } from '../links';
3
+ import { resolveFoundryApp, validateFoundryApp } from '../validate';
4
+
5
+ const base = { app: { name: 'Acme Go', scheme: 'acmego' }, tenant: { url: 'https://acme.example.com' } };
6
+
7
+ describe('features.briefing', () => {
8
+ it('test_true_turns_the_briefing_on_with_reply_on_ask_free_auto_and_a_notification', () => {
9
+ const c = resolveFoundryApp({ ...base, features: { briefing: true } });
10
+ expect(c.features.briefing).toBe(true);
11
+ expect(c.briefing).toEqual({ reply: true, confirm: 'auto', notification: true });
12
+ });
13
+
14
+ it('test_off_by_default_and_the_options_are_inert_when_off', () => {
15
+ const c = resolveFoundryApp(base);
16
+ expect(c.features.briefing).toBe(false);
17
+ expect(c.briefing).toEqual({ reply: false, confirm: 'auto', notification: false });
18
+ });
19
+
20
+ it('test_an_object_turns_it_on_and_sets_the_options', () => {
21
+ const c = resolveFoundryApp({ ...base, features: { briefing: { reply: true, confirm: 'ask', notification: false } } });
22
+ expect(c.features.briefing).toBe(true);
23
+ expect(c.briefing).toEqual({ reply: true, confirm: 'ask', notification: false });
24
+ });
25
+
26
+ it('test_reply_can_be_switched_off_alone', () => {
27
+ expect(resolveFoundryApp({ ...base, features: { briefing: { reply: false } } }).briefing).toEqual({ reply: false, confirm: 'auto', notification: true });
28
+ });
29
+
30
+ it('test_bad_options_are_named_by_path', () => {
31
+ const r = validateFoundryApp({ ...base, features: { briefing: { reply: 'yes', confirm: 'maybe', morning: true } } });
32
+ expect(r.ok ? [] : r.issues.map((i) => i.path)).toEqual(['features.briefing.morning', 'features.briefing.reply', 'features.briefing.confirm']);
33
+ const s = validateFoundryApp({ ...base, features: { briefing: 'on' } });
34
+ expect(s.ok ? [] : s.issues.map((i) => i.path)).toEqual(['features.briefing']);
35
+ });
36
+ });
37
+
38
+ describe('the briefing link', () => {
39
+ it('test_scheme_briefing_opens_the_briefing_when_the_feature_is_on', () => {
40
+ const on = createLinkResolver(resolveFoundryApp({ ...base, features: { briefing: true } }));
41
+ expect(on.resolve('acmego://briefing')).toEqual({ kind: 'briefing' });
42
+ expect(on.resolve('acmego://briefing?from=notification')).toEqual({ kind: 'briefing' });
43
+ });
44
+ it('test_it_is_not_a_link_when_the_feature_is_off_or_the_recording_screen_is_missing', () => {
45
+ expect(createLinkResolver(resolveFoundryApp(base)).resolve('acmego://briefing')).toBeNull();
46
+ const noGo = createLinkResolver(resolveFoundryApp({ ...base, features: { briefing: true, recording: false } }));
47
+ expect(noGo.resolve('acmego://briefing')).toBeNull();
48
+ });
49
+ });
@@ -4,6 +4,8 @@ import type { FoundryAppConfig } from './types';
4
4
  /** What a link asks the app to do. */
5
5
  export type LinkAction =
6
6
  | { kind: 'record'; autostop?: number }
7
+ /** `<scheme>://briefing` (the morning notification): open the GO screen and play today's briefing. */
8
+ | { kind: 'briefing' }
7
9
  | { kind: 'open'; tab: string; id?: string };
8
10
 
9
11
  export interface LinkResolver {
@@ -31,7 +33,7 @@ function routeMatcher(pattern: string): (path: string) => string | null {
31
33
  }
32
34
 
33
35
  /**
34
- * The one deep-link table: `<scheme>://record[?autostop=N]`, `<scheme>://tab/<key>[/<id>]`,
36
+ * The one deep-link table: `<scheme>://record[?autostop=N]`, `<scheme>://briefing`, `<scheme>://tab/<key>[/<id>]`,
35
37
  * `<scheme>://entity/<type>/<id>`, `<scheme>://<key>[/<id>]`, plus the config's own `links.routes`; the same
36
38
  * paths on `https://<host>/...` for each host in `links.hosts` (universal links).
37
39
  */
@@ -59,6 +61,7 @@ export function createLinkResolver(config: LinkConfig): LinkResolver {
59
61
  const seconds = Number(new URLSearchParams(m[4] ?? '').get('autostop'));
60
62
  return Number.isFinite(seconds) && seconds > 0 ? { kind: 'record', autostop: seconds } : { kind: 'record' };
61
63
  }
64
+ if (head === 'briefing' && segs.length === 1 && config.features.briefing && config.features.recording) return { kind: 'briefing' };
62
65
  for (const r of routes) {
63
66
  const id = r.match(path);
64
67
  if (id !== null) return { kind: 'open', tab: r.tab, id };
@@ -27,6 +27,16 @@ export interface FoundryFeatures {
27
27
  briefing: boolean;
28
28
  }
29
29
 
30
+ /** What the briefing does beyond playing. `features.briefing` takes `true`, or an object with any of these. */
31
+ export interface BriefingSettings {
32
+ /** Hold-to-talk reply under the briefing (needs the tenant's /corpus/briefing/reply route and the recording bindings). */
33
+ reply: boolean;
34
+ /** `auto`: a sure reply is applied at once and shown with Undo. `ask`: show what was understood and wait for Do it. */
35
+ confirm: 'auto' | 'ask';
36
+ /** The morning notification that opens the briefing (the time is the person's own setting on central; needs a notifier from the device). */
37
+ notification: boolean;
38
+ }
39
+
30
40
  export interface FoundryTabConfig {
31
41
  /** Unique; also the launch-arg / deep-link name of the tab (`<scheme>://tab/<key>`). */
32
42
  key: string;
@@ -99,6 +109,8 @@ export interface FoundryAppConfig {
99
109
  };
100
110
  theme: { mode: 'dark' | 'light' | 'system' };
101
111
  features: FoundryFeatures;
112
+ /** The briefing's options; all off when `features.briefing` is. */
113
+ briefing: BriefingSettings;
102
114
  tabs: FoundryTabConfig[];
103
115
  /** Record types the Home tab counts, in order. */
104
116
  home: { types: FoundryHomeType[] };
@@ -124,7 +136,7 @@ export type FoundryAppInput = {
124
136
  brand?: Partial<FoundryAppConfig['brand']>;
125
137
  tenant: Pick<FoundryAppConfig['tenant'], 'url'> & Partial<FoundryAppConfig['tenant']>;
126
138
  theme?: Partial<FoundryAppConfig['theme']>;
127
- features?: Partial<FoundryFeatures>;
139
+ features?: Partial<Omit<FoundryFeatures, 'briefing'>> & { briefing?: boolean | Partial<BriefingSettings> };
128
140
  tabs?: FoundryTabConfig[];
129
141
  home?: Partial<FoundryAppConfig['home']>;
130
142
  entityTypes?: Record<string, FoundryEntityType>;
@@ -1,5 +1,5 @@
1
1
  import { ICON_PATHS } from '@startsimpli/ui-native/icons';
2
- import { BUILTIN_SCREENS, type ConfigIssue, type FoundryAppConfig, type FoundryAppInput, type FoundryTabConfig } from './types';
2
+ import { BUILTIN_SCREENS, type BriefingSettings, type ConfigIssue, type FoundryAppConfig, type FoundryAppInput, type FoundryTabConfig } from './types';
3
3
  import {
4
4
  DEFAULT_BASE, DEFAULT_CENTRAL_URL, DEFAULT_FEATURES, DEFAULT_HOME_TYPES, SCREEN_DEFAULTS, SCREEN_ENTITY_TYPES, SCREEN_FEATURE, defaultBrandTagline, defaultTabs,
5
5
  } from './defaults';
@@ -99,10 +99,27 @@ export function validateFoundryApp(input: unknown, options: ValidateOptions = {}
99
99
  const featuresIn = section('features');
100
100
  allowed(featuresIn, Object.keys(DEFAULT_FEATURES), 'features');
101
101
  const features = { ...DEFAULT_FEATURES };
102
+ let briefing: BriefingSettings = { reply: false, confirm: 'auto', notification: false };
102
103
  for (const k of Object.keys(DEFAULT_FEATURES) as Array<keyof typeof DEFAULT_FEATURES>) {
103
104
  const v = featuresIn[k];
104
105
  if (v === undefined) continue;
105
- if (typeof v !== 'boolean') bad(`features.${k}`, 'must be true or false'); else features[k] = v;
106
+ if (k === 'briefing' && isObj(v)) {
107
+ // The object form: it turns the briefing on and tunes it.
108
+ allowed(v, ['reply', 'confirm', 'notification'], 'features.briefing');
109
+ briefing = { reply: true, confirm: 'auto', notification: true };
110
+ for (const flag of ['reply', 'notification'] as const) {
111
+ if (v[flag] === undefined) continue;
112
+ if (typeof v[flag] !== 'boolean') bad(`features.briefing.${flag}`, 'must be true or false'); else briefing[flag] = v[flag] as boolean;
113
+ }
114
+ if (v.confirm !== undefined) {
115
+ if (v.confirm !== 'auto' && v.confirm !== 'ask') bad('features.briefing.confirm', 'must be "auto" or "ask"'); else briefing.confirm = v.confirm;
116
+ }
117
+ features.briefing = true;
118
+ } else if (typeof v !== 'boolean') bad(`features.${k}`, k === 'briefing' ? 'must be true, false or an object of options' : 'must be true or false');
119
+ else {
120
+ features[k] = v;
121
+ if (k === 'briefing' && v) briefing = { reply: true, confirm: 'auto', notification: true };
122
+ }
106
123
  }
107
124
 
108
125
  // tabs
@@ -199,6 +216,7 @@ export function validateFoundryApp(input: unknown, options: ValidateOptions = {}
199
216
  tenant: { url: trimSlash(tenant.url as string), centralUrl: trimSlash((tenant.centralUrl as string | undefined) ?? DEFAULT_CENTRAL_URL), ...(tenant.slug ? { slug: tenant.slug as string } : {}) },
200
217
  theme: { mode: (theme.mode as FoundryAppConfig['theme']['mode'] | undefined) ?? DEFAULT_BASE.theme.mode },
201
218
  features,
219
+ briefing,
202
220
  tabs,
203
221
  home: { types: homeTypes },
204
222
  entityTypes,
@@ -2,7 +2,7 @@ import { createConnectionsMeApi } from '../../api/connections';
2
2
  import { createMcpTokensApi, type McpTokensApi } from '../../api/mcp-tokens';
3
3
  import type { MemberConnectionsApi } from '../../components/pages/types';
4
4
  import { createNativeCorpusApi, type NativeCorpusApi } from '../corpus/api';
5
- import { createFakeNativeCorpusApi } from '../corpus/fake';
5
+ import { createFakeNativeCorpusApi, type FakeNativeCorpusApi } from '../corpus/fake';
6
6
  import { withScenario, type FakeScenario } from '../corpus/fake-scenarios';
7
7
  import { fakeEntityRows } from './fakeEntities';
8
8
  import { createFakeConnectionsApi } from '../screens/connections/fake';
@@ -26,14 +26,14 @@ export interface FoundryData {
26
26
  * The data layer every screen reads: the signed-in tenant over the session's authorized fetch, or in-memory fakes
27
27
  * (`fake`) for simulator checks that need no sign-in and no network.
28
28
  */
29
- export function createFoundryData(deps: { config: FoundryAppConfig; authorizedFetch: AuthorizedFetch; fake?: boolean; scenario?: FakeScenario }): FoundryData {
29
+ export function createFoundryData(deps: { config: FoundryAppConfig; authorizedFetch: AuthorizedFetch; fake?: boolean; scenario?: FakeScenario; /** The fake tenant to read, when something else (the fake briefing's replies) must write to the same rows. */ fakeCorpus?: FakeNativeCorpusApi }): FoundryData {
30
30
  const { config, authorizedFetch, fake, scenario } = deps;
31
31
  const wantsNotes = config.tabs.some((t) => t.screen === 'notes');
32
32
  if (fake) {
33
33
  const fakeConnections = createFakeConnectionsApi({ connections: scenario === 'empty' ? [] : undefined });
34
34
  return {
35
35
  openUrl: async () => { fakeConnections.completeConsent(); return { completed: true }; },
36
- corpus: createFakeNativeCorpusApi({ scenario, extraEntities: fakeEntityRows(config) }),
36
+ corpus: deps.fakeCorpus ?? createFakeNativeCorpusApi({ scenario, extraEntities: fakeEntityRows(config) }),
37
37
  notes: wantsNotes ? createVoiceNotesController({ api: createFakeVoiceApi({ scenario }) }) : null,
38
38
  member: {
39
39
  connections: withScenario(fakeConnections, scenario),
@@ -4,6 +4,7 @@ import type { BackgroundTasks } from '../recording/lifecycle';
4
4
  import type { PermissionsApi } from '../recording/permissions';
5
5
  import type { RecordingFile } from '../recording/recovery';
6
6
  import type { AudioPlayerDriver, PlaybackSource } from '../briefing/audioPlayer';
7
+ import type { MorningNotifier } from '../briefing/notify';
7
8
 
8
9
  export interface TextFiles {
9
10
  exists(path: string): Promise<boolean>;
@@ -32,6 +33,8 @@ export interface BriefingDevice {
32
33
  session?: SessionInspector;
33
34
  /** What `-tgFakeBriefing` plays: a bundled clip, since the fake briefing has no server behind it. */
34
35
  fixture?: PlaybackSource;
36
+ /** Schedules the morning notification (local, repeating) that opens `<scheme>://briefing`; `expo-notifications` in the template. Without one there is no morning notification. */
37
+ notifier?: MorningNotifier;
35
38
  }
36
39
 
37
40
  /**
@@ -12,6 +12,7 @@ import type { FoundryAppConfig } from './config/types';
12
12
  * -tgNote <id> open that note (device, real data)
13
13
  * -tgAutostop N start a timed recording after sign-in
14
14
  * -tgFakeBriefing 1 'What's on the plate' plays a bundled clip over a fixed briefing: no server, no sign-in (add -tgFakeTabs 1)
15
+ * -tgFakeReply "a|b" what the fake reply 'hears' on each hold-to-talk, in order (needs -tgFakeBriefing); default "move this one to later"
15
16
  * -tgHapticProbe 1 fire one haptic per interaction through the real engine; the diagnostics log shows each call and the engine's answer
16
17
  * -tgScheme light|dark override the config's theme mode (simulator checks of the light theme)
17
18
  */
@@ -26,6 +27,8 @@ export interface LaunchArgs {
26
27
  hapticProbe: boolean;
27
28
  /** `-tgFakeBriefing 1`: the briefing comes from a fixture with a bundled audio clip. */
28
29
  fakeBriefing: boolean;
30
+ /** `-tgFakeReply "a|b"`: what each recorded reply is taken to say, in order. */
31
+ fakeReply: string[];
29
32
  }
30
33
 
31
34
  export function readLaunch(get: (key: string) => unknown, config: Pick<FoundryAppConfig, 'tabs'>): LaunchArgs {
@@ -49,6 +52,7 @@ export function readLaunch(get: (key: string) => unknown, config: Pick<FoundryAp
49
52
  autostop: Number.isFinite(n) && n > 0 ? n : null,
50
53
  hapticProbe: str('tgHapticProbe') === '1',
51
54
  fakeBriefing: str('tgFakeBriefing') === '1',
55
+ fakeReply: str('tgFakeReply').split('|').map((l) => l.trim()).filter(Boolean),
52
56
  scheme: str('tgScheme') === 'light' ? 'light' : str('tgScheme') === 'dark' ? 'dark' : null,
53
57
  };
54
58
  }
@@ -30,6 +30,8 @@ export interface ScreenDeps {
30
30
  member: { connections: MemberConnectionsApi; mcpTokens: McpTokensApi };
31
31
  /** Opens a URL outside the app (`Linking.openURL`): a vendor's sign-in page, a tracker item. Absent in tests. */
32
32
  openUrl?: (url: string) => Promise<unknown>;
33
+ /** Fires when something outside a list changed its items (a spoken reply to the briefing): lists re-read. */
34
+ itemsChanged?: { subscribe(listener: () => void): () => void };
33
35
  }
34
36
 
35
37
  /** Builds one shell tab from its config entry. */
@@ -61,7 +63,7 @@ export const BUILTIN_FACTORIES: Record<string, ScreenFactory> = {
61
63
  : <NotesListScreen controller={notes} displays={corpus.schema?.displays} onOpen={(n) => push(n.id)} />),
62
64
  };
63
65
  },
64
- tracker: ({ config, corpus, member, openUrl }, tab) => trackerTab({ api: corpus, key: tab.key, label: tabLabel(tab), notesKey: firstKey(config, 'notes'), memberConnections: member.connections, openUrl }),
66
+ 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 }),
65
67
  library: ({ corpus }, tab) => libraryTab(corpus, { key: tab.key, label: tabLabel(tab) }),
66
68
  ask: ({ corpus }, tab) => askTab(corpus, { key: tab.key, label: tabLabel(tab) }),
67
69
  planning: ({ config, corpus }, tab) => createPlanningTab({ api: corpus, key: tab.key, label: tabLabel(tab), documentTab: firstKey(config, 'library') }),
@@ -6,6 +6,7 @@ import { noteSections } from '../../voice/sections';
6
6
  import { meterFraction } from '../../recording/levels';
7
7
  import { BriefingCard } from '../../briefing/BriefingCard';
8
8
  import type { BriefingController } from '../../briefing/controller';
9
+ import type { BriefingReplyController } from '../../briefing/reply';
9
10
  import type { RecorderState } from '../../recording/recorder';
10
11
  import type { FoundryServices } from '../services';
11
12
  import type { FoundryStrings } from '../strings';
@@ -13,7 +14,7 @@ import type { FoundryStrings } from '../strings';
13
14
  type Recording = NonNullable<FoundryServices['recording']>;
14
15
 
15
16
  /** The GO screen: one big button, a timer and level meter while recording, the last notes, and sign out. */
16
- export function RecordScreen({ recording, briefing, strings, onOpenDiagnostics, onSignOut }: { recording: Recording; briefing?: BriefingController | null; strings: FoundryStrings; onOpenDiagnostics: () => void; onSignOut: () => void }) {
17
+ export function RecordScreen({ recording, briefing, briefingReply, strings, onOpenDiagnostics, onSignOut }: { recording: Recording; briefing?: BriefingController | null; briefingReply?: BriefingReplyController | null; strings: FoundryStrings; onOpenDiagnostics: () => void; onSignOut: () => void }) {
17
18
  const theme = useTheme();
18
19
  const { recorder, notes: api, permissions } = recording;
19
20
  const [state, setState] = useState<RecorderState>(recorder.getState());
@@ -71,7 +72,7 @@ export function RecordScreen({ recording, briefing, strings, onOpenDiagnostics,
71
72
  void (isRecording ? recorder.stop() : (briefing?.handoffToRecording() ?? Promise.resolve()).then(() => recorder.go()));
72
73
  }}
73
74
  />
74
- {briefing && !isRecording ? <BriefingCard controller={briefing} strings={strings} /> : null}
75
+ {briefing && !isRecording ? <BriefingCard controller={briefing} reply={briefingReply} strings={strings} /> : null}
75
76
  {isRecording ? <Text testID="timer" style={[typeStyle(theme, 'largeTitle'), { textAlign: 'center', fontVariant: ['tabular-nums'] }]}>{mm}:{ss}</Text> : null}
76
77
  {state.phase === 'uploading' ? <Text variant="muted" style={{ textAlign: 'center' }}>{strings.sending}</Text> : null}
77
78
  {state.phase === 'sent' ? <Text variant="muted" style={{ textAlign: 'center' }} testID="status">{strings.sent}</Text> : null}
@@ -13,10 +13,7 @@ import type { Banners } from './banners';
13
13
  import { createLinkResolver } from './config/links';
14
14
  import type { FoundryAppConfig } from './config/types';
15
15
  import type { FoundryDevice, RecordingDevice } from './device';
16
- import { createAudioPlayer } from '../briefing/audioPlayer';
17
- import { createBriefingApi } from '../briefing/api';
18
- import { createBriefingController } from '../briefing/controller';
19
- import { createFakeBriefingApi } from '../briefing/fake';
16
+ import { createBriefing, type FakeBriefingDeps } from './briefingServices';
20
17
  import type { FoundryStrings } from './strings';
21
18
 
22
19
  const newId = () => `fa-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
@@ -103,35 +100,11 @@ function createRecording(deps: { config: FoundryAppConfig; device: FoundryDevice
103
100
  return { notes, queue, lifecycle, permissions, recorder, recoverAndDrain, pending };
104
101
  }
105
102
 
106
- /** 'What's on the plate': the briefing flow over the device's playback driver, sharing the recorder's session inspector. */
107
- function createBriefing(deps: { config: FoundryAppConfig; device: FoundryDevice; session: ReturnType<typeof createSession>; diag: ReturnType<typeof createDiagnostics>; strings: FoundryStrings; fake: boolean }) {
108
- const { config, device, session, diag, strings } = deps;
109
- const dev = device.briefing;
110
- if (!dev) throw new Error('features.briefing is on but the device supplies no briefing bindings');
111
- const inspector = dev.session ?? device.recording?.session;
112
- if (!inspector) throw new Error('features.briefing needs an audio-session inspector (device.briefing.session or device.recording.session)');
113
- const player = createAudioPlayer({
114
- driver: dev.driver,
115
- session: inspector,
116
- diag,
117
- poll: (fn, ms) => { const h = setInterval(fn, ms); return () => clearInterval(h); },
118
- sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
119
- });
120
- const api = deps.fake
121
- ? createFakeBriefingApi(dev.fixture)
122
- : createBriefingApi({ tandemUrl: config.tenant.url, authorizedFetch: session.authorizedFetch, bearer: session.bearer });
123
- const controller = createBriefingController({
124
- api, player, diag,
125
- messages: { failed: strings.briefingFailed, empty: strings.briefingEmpty, textOnly: strings.briefingTextOnly, audioFailed: strings.briefingAudioFailed },
126
- });
127
- return { controller, player };
128
- }
129
-
130
103
  /**
131
104
  * The composition root: session (sign-in, refresh, sign-out), diagnostics, the link router and, when recording is on,
132
105
  * the recorder with its upload queue. The app shell passes the device bindings; nothing here is Foundry-specific.
133
106
  */
134
- export function createFoundryServices(deps: { config: FoundryAppConfig; device: FoundryDevice; banners: Banners; strings: FoundryStrings; /** `-tgFakeBriefing`: a fixed briefing and the device's bundled clip. */ fakeBriefing?: boolean }) {
107
+ export function createFoundryServices(deps: { config: FoundryAppConfig; device: FoundryDevice; banners: Banners; strings: FoundryStrings; /** `-tgFakeBriefing`: a fixed briefing and the device's bundled clip over the fake tenant (and `-tgFakeReply`'s script). */ fakeBriefing?: FakeBriefingDeps | null }) {
135
108
  const { config, device, banners } = deps;
136
109
  const diagPath = device.documentUri('diagnostics.json');
137
110
  const diag = createDiagnostics({
@@ -152,10 +125,17 @@ export function createFoundryServices(deps: { config: FoundryAppConfig; device:
152
125
  ? createRecording({ config, device, rec: device.recording, session, diag, banners })
153
126
  : null;
154
127
 
155
- const briefing = config.features.briefing ? createBriefing({ config, device, session, diag, strings: deps.strings, fake: Boolean(deps.fakeBriefing) }) : null;
128
+ const briefing = config.features.briefing ? createBriefing({ config, device, session, diag, strings: deps.strings, fake: deps.fakeBriefing ?? null }) : null;
156
129
 
157
130
  let open: (tab: string, id?: string) => void = () => undefined;
131
+ const goTab = config.tabs.find((t) => t.screen === 'record')?.key;
158
132
  const deepLink = createDeepLink({
133
+ openBriefing: () => {
134
+ // The morning notification: land on GO and play today's briefing (a briefing already playing is left alone).
135
+ if (goTab) open(goTab);
136
+ const phase = briefing?.controller.getState().phase;
137
+ if (phase !== 'playing' && phase !== 'loading') void briefing?.controller.start();
138
+ },
159
139
  resolver: createLinkResolver(config),
160
140
  getPhase: () => recording?.recorder.getState().phase ?? 'idle',
161
141
  go: (o) => recording?.recorder.go(o),
@@ -172,6 +152,7 @@ export function createFoundryServices(deps: { config: FoundryAppConfig; device:
172
152
  /** After sign-in/restore. */
173
153
  async onReady() {
174
154
  if (recording) await recording.recoverAndDrain();
155
+ void briefing?.syncNotification();
175
156
  await deepLink.sessionReady();
176
157
  },
177
158
  /** App came to the foreground: renew a stale access token first (silently), then flush the upload queue. */
@@ -38,6 +38,20 @@ export interface FoundryStrings {
38
38
  briefingEmpty: string;
39
39
  briefingTextOnly: string;
40
40
  briefingAudioFailed: string;
41
+ replyTalk: string;
42
+ replyListening: string;
43
+ replySending: string;
44
+ replyApply: string;
45
+ replyCancel: string;
46
+ replyUndo: string;
47
+ replyContinue: string;
48
+ replyHoldToAnswer: string;
49
+ replyTooShort: string;
50
+ replyNotHeard: string;
51
+ replyFailed: string;
52
+ replyRetry: string;
53
+ replyNoAudio: string;
54
+ replyDone: string;
41
55
  waiting(n: number): string;
42
56
  offlineWaiting(n: number): string;
43
57
  }
@@ -84,6 +98,20 @@ export function foundryStrings(config: Pick<FoundryAppConfig, 'app' | 'brand' |
84
98
  briefingEmpty: 'Nothing on your plate today.',
85
99
  briefingTextOnly: 'The voice is unavailable right now. Here it is as text.',
86
100
  briefingAudioFailed: 'Could not play the audio. Here it is as text.',
101
+ replyTalk: 'Hold to reply',
102
+ replyListening: 'Listening... let go to send',
103
+ replySending: 'Understanding...',
104
+ replyApply: 'Do it',
105
+ replyCancel: 'Cancel',
106
+ replyUndo: 'Undo',
107
+ replyContinue: 'Continue',
108
+ replyHoldToAnswer: 'Hold to answer',
109
+ replyTooShort: 'Hold the button while you speak, then let go.',
110
+ replyNotHeard: 'I could not make that out. Try again.',
111
+ replyFailed: 'The reply did not go through. Try again.',
112
+ replyRetry: 'Try again',
113
+ replyNoAudio: 'No audio detected. Check the microphone is not covered.',
114
+ replyDone: 'Done',
87
115
  waiting: (n) => `${n} waiting to send`,
88
116
  offlineWaiting: (n) => `You are offline. ${n} waiting to send.`,
89
117
  };
@@ -2,19 +2,30 @@ import { View } from 'react-native';
2
2
  import { Alert, Button, Card, CardContent, Spinner, Text, useHaptics, useTheme } from '@startsimpli/ui-native';
3
3
  import { useControllerState } from '../components/useControllerState';
4
4
  import type { FoundryStrings } from '../app/strings';
5
+ import { BriefingReply } from './BriefingReply';
5
6
  import { transcriptParts, type BriefingController } from './controller';
7
+ import type { BriefingReplyController } from './reply';
8
+
9
+ const NO_STATE = { targetId: null as string | null };
10
+ const NO_REPLY = {
11
+ getState: () => NO_STATE,
12
+ subscribe: () => () => undefined,
13
+ };
6
14
 
7
15
  /**
8
16
  * 'What's on the plate' on the GO screen: one button that plays today's spoken briefing, with the transcript while it
9
17
  * plays (the item being spoken emphasised), stop and replay, and a plain message instead of a blank card on any failure.
10
18
  */
11
- export function BriefingCard({ controller, strings }: { controller: BriefingController; strings: FoundryStrings }) {
19
+ export function BriefingCard({ controller, reply, strings }: { controller: BriefingController; /** Hold-to-talk reply; omit for a briefing you can only listen to. */ reply?: BriefingReplyController | null; strings: FoundryStrings }) {
12
20
  const theme = useTheme();
13
21
  const haptic = useHaptics();
14
22
  const s = useControllerState(controller);
23
+ const r = useControllerState(reply ?? NO_REPLY);
15
24
  const live = s.phase === 'playing' || s.phase === 'paused';
16
25
  const loading = s.phase === 'loading';
17
26
  const hasText = s.text.length > 0;
27
+ // While the briefing is silent, the item a reply was about stays marked.
28
+ const marked = s.phase === 'playing' ? s.currentId : (r.targetId ?? s.currentId);
18
29
 
19
30
  return (
20
31
  <View style={{ gap: theme.spacing.sm }}>
@@ -43,7 +54,7 @@ export function BriefingCard({ controller, strings }: { controller: BriefingCont
43
54
  {s.note ? <Text variant="muted" testID="briefing-note">{s.note}</Text> : null}
44
55
  {hasText ? (
45
56
  <Text testID="briefing-transcript" accessibilityLabel={s.text}>
46
- {transcriptParts(s.text, s.offsets, s.currentId).map((p, i) => (
57
+ {transcriptParts(s.text, s.offsets, marked).map((p, i) => (
47
58
  p.current
48
59
  ? <Text key={i} testID="briefing-current" style={{ fontWeight: '700', color: theme.colors.primary }}>{p.text}</Text>
49
60
  : p.text
@@ -59,6 +70,7 @@ export function BriefingCard({ controller, strings }: { controller: BriefingCont
59
70
  onPress={() => { haptic('light', 'briefing.replay'); void (s.phase === 'text' ? controller.start() : controller.replay()); }}
60
71
  />
61
72
  ) : null}
73
+ {reply && hasText && s.briefingId && (live || s.phase === 'ended') ? <BriefingReply controller={reply} strings={strings} /> : null}
62
74
  </CardContent>
63
75
  </Card>
64
76
  )}
@@ -0,0 +1,68 @@
1
+ import { View } from 'react-native';
2
+ import { Alert, Button, Spinner, Text, useHaptics, useTheme } from '@startsimpli/ui-native';
3
+ import { useControllerState } from '../components/useControllerState';
4
+ import type { FoundryStrings } from '../app/strings';
5
+ import type { BriefingReplyController } from './reply';
6
+
7
+ /**
8
+ * The reply under the briefing: hold the button to talk, let go to send. Then what it understood (and Do it / Cancel in
9
+ * ask mode), or what it did with Undo and Continue, or the question it needs answered (the next hold answers it).
10
+ */
11
+ export function BriefingReply({ controller, strings }: { controller: BriefingReplyController; strings: FoundryStrings }) {
12
+ const theme = useTheme();
13
+ const haptic = useHaptics();
14
+ const s = useControllerState(controller);
15
+ const held = s.phase === 'starting' || s.phase === 'recording';
16
+ const busy = s.phase === 'sending';
17
+
18
+ return (
19
+ <View style={{ gap: theme.spacing.sm }} testID="briefing-reply">
20
+ {busy ? (
21
+ <View style={{ flexDirection: 'row', alignItems: 'center', gap: theme.spacing.sm }} testID="briefing-reply-sending">
22
+ <Spinner />
23
+ <Text variant="muted">{strings.replySending}</Text>
24
+ </View>
25
+ ) : (
26
+ <Button
27
+ testID="briefing-talk"
28
+ title={held ? strings.replyListening : s.awaitingAnswer ? strings.replyHoldToAnswer : strings.replyTalk}
29
+ variant={held ? 'primary' : 'outline'}
30
+ size="lg"
31
+ accessibilityLabel={held ? strings.replyListening : s.awaitingAnswer ? strings.replyHoldToAnswer : strings.replyTalk}
32
+ accessibilityHint={strings.replyTooShort}
33
+ onPressIn={() => { haptic('medium', 'briefing.talk'); void controller.pressStart(); }}
34
+ onPressOut={() => { void controller.pressEnd(); }}
35
+ />
36
+ )}
37
+ {s.utterance && !held ? <Text variant="muted" testID="briefing-heard">{`"${s.utterance}"`}</Text> : null}
38
+ {s.error ? (
39
+ <View style={{ gap: theme.spacing.sm }} testID="briefing-reply-error">
40
+ <Alert variant="destructive">{s.error}</Alert>
41
+ <View style={{ flexDirection: 'row', gap: theme.spacing.sm }}>
42
+ {s.retryable ? <Button testID="briefing-reply-retry" title={strings.replyRetry} variant="outline" onPress={() => { haptic('light', 'briefing.reply-retry'); void controller.retry(); }} /> : null}
43
+ <Button testID="briefing-reply-dismiss" title={strings.replyCancel} variant="outline" onPress={() => { void controller.cancel(); }} />
44
+ </View>
45
+ </View>
46
+ ) : null}
47
+ {s.phase === 'preview' ? (
48
+ <View style={{ gap: theme.spacing.sm }} testID="briefing-preview">
49
+ <Text testID="briefing-understood" style={{ fontWeight: '700' }}>{`${s.understood}?`}</Text>
50
+ <View style={{ flexDirection: 'row', gap: theme.spacing.sm }}>
51
+ <Button testID="briefing-apply" title={strings.replyApply} onPress={() => { haptic('success', 'briefing.apply'); void controller.apply(); }} />
52
+ <Button testID="briefing-cancel" title={strings.replyCancel} variant="outline" onPress={() => { void controller.cancel(); }} />
53
+ </View>
54
+ </View>
55
+ ) : null}
56
+ {s.phase === 'asked' && s.question ? <Text testID="briefing-question" style={{ fontWeight: '700' }}>{s.question}</Text> : null}
57
+ {s.phase === 'applied' ? (
58
+ <View style={{ gap: theme.spacing.sm }} testID="briefing-applied">
59
+ {s.confirmation ? <Text testID="briefing-confirmation" style={{ fontWeight: '700' }}>{s.confirmation}</Text> : null}
60
+ <View style={{ flexDirection: 'row', gap: theme.spacing.sm }}>
61
+ {s.canUndo ? <Button testID="briefing-undo" title={strings.replyUndo} variant="outline" onPress={() => { haptic('warning', 'briefing.undo'); void controller.undo(); }} /> : null}
62
+ <Button testID="briefing-continue" title={strings.replyContinue} variant="outline" onPress={() => { haptic('light', 'briefing.continue'); void controller.continueBriefing(); }} />
63
+ </View>
64
+ </View>
65
+ ) : null}
66
+ </View>
67
+ );
68
+ }