@startsimpli/integrations 0.2.145 → 0.2.146
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-actions.test.ts +2 -0
- package/src/__tests__/briefing-reply.test.ts +334 -0
- package/src/__tests__/corpus-tracker.test.tsx +79 -0
- package/src/__tests__/owner-backfill.test.ts +114 -0
- package/src/__tests__/owner-link.test.ts +115 -0
- package/src/__tests__/owner-picker.test.tsx +70 -0
- package/src/__tests__/roster.test.ts +27 -0
- package/src/__tests__/tracker-sort.test.ts +28 -0
- package/src/components/index.ts +1 -0
- package/src/components/pages/TaskDetailPage.tsx +33 -2
- package/src/components/pages/TrackerPage.tsx +28 -6
- package/src/components/pages/task-tracker/OwnerPicker.tsx +82 -0
- package/src/components/pages/tracker/TrackerBoard.tsx +45 -0
- package/src/components/pages/tracker/TrackerToolbar.tsx +44 -0
- package/src/corpus/briefing/actions/execute.ts +5 -4
- package/src/corpus/briefing/actions/log.ts +1 -1
- package/src/corpus/briefing/actions/types.ts +21 -0
- package/src/corpus/briefing/index.ts +1 -0
- package/src/corpus/briefing/intent/model.ts +3 -0
- package/src/corpus/briefing/intent/resolve.ts +14 -6
- package/src/corpus/briefing/intent/types.ts +7 -0
- package/src/corpus/briefing/reply/handle.ts +174 -0
- package/src/corpus/briefing/reply/index.ts +6 -0
- package/src/corpus/briefing/reply/respond.ts +95 -0
- package/src/corpus/briefing/reply/types.ts +112 -0
- package/src/corpus/briefing/store.ts +14 -0
- package/src/corpus/client.ts +16 -18
- package/src/corpus/entities.ts +4 -0
- package/src/corpus/index.ts +4 -0
- package/src/corpus/owner-backfill.ts +200 -0
- package/src/corpus/owner-link.ts +160 -0
- package/src/corpus/roster.ts +53 -0
- package/src/corpus/tracker-groups.ts +8 -4
- package/src/corpus/tracker-sort.ts +51 -0
- package/src/corpus/types.ts +13 -1
- package/src/native/app/FoundryApp.tsx +25 -7
- package/src/native/app/__tests__/briefingLink.test.tsx +57 -0
- package/src/native/app/__tests__/briefingServices.test.ts +92 -0
- package/src/native/app/__tests__/launch.test.ts +2 -1
- package/src/native/app/briefingServices.ts +101 -0
- package/src/native/app/config/__tests__/briefingConfig.test.ts +49 -0
- package/src/native/app/config/links.ts +4 -1
- package/src/native/app/config/types.ts +13 -1
- package/src/native/app/config/validate.ts +20 -2
- package/src/native/app/data.ts +3 -3
- package/src/native/app/device.ts +3 -0
- package/src/native/app/launch.ts +4 -0
- package/src/native/app/registry.tsx +3 -1
- package/src/native/app/screens/RecordScreen.tsx +3 -2
- package/src/native/app/services.ts +11 -30
- package/src/native/app/strings.ts +28 -0
- package/src/native/briefing/BriefingCard.tsx +14 -2
- package/src/native/briefing/BriefingReply.tsx +68 -0
- package/src/native/briefing/__tests__/BriefingReply.test.tsx +144 -0
- package/src/native/briefing/__tests__/fakeReply.test.ts +46 -0
- package/src/native/briefing/__tests__/notify.test.ts +42 -1
- package/src/native/briefing/__tests__/replyApi.test.ts +43 -0
- package/src/native/briefing/__tests__/replyController.test.ts +230 -0
- package/src/native/briefing/__tests__/replyPosition.test.ts +116 -0
- package/src/native/briefing/audioPlayer.ts +9 -2
- package/src/native/briefing/controller.ts +50 -5
- package/src/native/briefing/fake.ts +25 -18
- package/src/native/briefing/fakeReply.ts +65 -0
- package/src/native/briefing/index.ts +8 -3
- package/src/native/briefing/notify.ts +42 -0
- package/src/native/briefing/reply.ts +261 -0
- package/src/native/briefing/replyApi.ts +82 -0
- package/src/native/recording/__tests__/deeplink.test.ts +20 -0
- package/src/native/recording/deeplink.ts +7 -0
- package/src/native/tracker/__tests__/itemsChanged.test.ts +13 -0
- package/src/native/tracker/tab.tsx +4 -1
|
@@ -83,3 +83,45 @@ export async function syncMorningNotification(
|
|
|
83
83
|
const id = await notifier.schedule(plan);
|
|
84
84
|
return id === null ? null : plan;
|
|
85
85
|
}
|
|
86
|
+
|
|
87
|
+
/** The person's own setting, as central serves it at `GET /api/v1/auth/briefing-schedule/`. */
|
|
88
|
+
export interface MorningSchedule {
|
|
89
|
+
enabled: boolean;
|
|
90
|
+
/** `HH:MM`, 24-hour, in the person's own zone. */
|
|
91
|
+
morningTime: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** This foundry's row from central's answer, or null when there is none (the person never turned it on). */
|
|
95
|
+
export function pickMorningSchedule(body: unknown, tenantSlug: string): MorningSchedule | null {
|
|
96
|
+
const rows = (body as { schedules?: Array<{ tenant?: string; enabled?: boolean; morningTime?: string }> } | undefined)?.schedules;
|
|
97
|
+
const hit = Array.isArray(rows) ? rows.find((r) => r?.tenant === tenantSlug) : undefined;
|
|
98
|
+
return hit && typeof hit.morningTime === 'string' ? { enabled: hit.enabled === true, morningTime: hit.morningTime } : null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Make the phone's morning notification match the setting on central. A missing or turned-off row cancels it; central
|
|
103
|
+
* being unreachable changes nothing (a notification already scheduled keeps firing). Returns the plan scheduled, if any.
|
|
104
|
+
*/
|
|
105
|
+
export async function syncMorningFromCentral(deps: {
|
|
106
|
+
notifier: MorningNotifier;
|
|
107
|
+
authorizedFetch: (url: string, init?: RequestInit) => Promise<Response>;
|
|
108
|
+
centralUrl: string;
|
|
109
|
+
/** The foundry's slug: central keeps one row per (person, foundry). */
|
|
110
|
+
tenantSlug: string;
|
|
111
|
+
scheme: string;
|
|
112
|
+
timeZone: string;
|
|
113
|
+
now?: number;
|
|
114
|
+
}): Promise<NotificationPlan | null> {
|
|
115
|
+
let body: unknown;
|
|
116
|
+
try {
|
|
117
|
+
const res = await deps.authorizedFetch(`${deps.centralUrl.replace(/\/+$/, '')}/api/v1/auth/briefing-schedule/`, { method: 'GET' });
|
|
118
|
+
if (!res.ok) return null;
|
|
119
|
+
body = await res.json();
|
|
120
|
+
} catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const row = pickMorningSchedule(body, deps.tenantSlug);
|
|
124
|
+
return syncMorningNotification(deps.notifier, {
|
|
125
|
+
enabled: Boolean(row?.enabled), morningTime: row?.morningTime ?? '', timeZone: deps.timeZone, scheme: deps.scheme, now: deps.now,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PUSH-TO-TALK REPLY to the briefing, as a framework-free controller (bd startsim-t1hsu).
|
|
3
|
+
*
|
|
4
|
+
* press -> take where the briefing is -> release the audio session (the 600 ms handoff) -> mic on
|
|
5
|
+
* release-> mic off -> POST the recording to the tenant (words, intent, edits, spoken confirmation)
|
|
6
|
+
* answer -> show what it did + Undo, say it; or ask the question and let the next press answer it
|
|
7
|
+
*
|
|
8
|
+
* The recording is NOT a voice note: it never enters the upload queue (whose recovery would file any
|
|
9
|
+
* leftover audio as a note); the file is deleted once the server has taken it, kept only while a retry is possible.
|
|
10
|
+
*/
|
|
11
|
+
import type { ReplyResult } from '../../corpus/briefing';
|
|
12
|
+
import { isSilent } from '../recording/levels';
|
|
13
|
+
import type { Permission } from '../recording/permissions';
|
|
14
|
+
import type { RecorderAudio } from '../recording/recorder';
|
|
15
|
+
import type { PlaybackSource, PlayerState } from './audioPlayer';
|
|
16
|
+
import type { BriefingPosition } from './controller';
|
|
17
|
+
import type { BriefingReplyApi, ReplySend } from './replyApi';
|
|
18
|
+
|
|
19
|
+
export type ReplyPhase = 'idle' | 'starting' | 'recording' | 'sending' | 'preview' | 'applied' | 'asked' | 'error';
|
|
20
|
+
|
|
21
|
+
export interface ReplyState {
|
|
22
|
+
phase: ReplyPhase;
|
|
23
|
+
/** What was heard, as words. */
|
|
24
|
+
utterance: string | null;
|
|
25
|
+
/** "Move Send the deck to Friday": shown BEFORE anything is applied in ask mode. */
|
|
26
|
+
understood: string | null;
|
|
27
|
+
/** What was done (or undone), in the sentence that is also spoken. */
|
|
28
|
+
confirmation: string | null;
|
|
29
|
+
question: string | null;
|
|
30
|
+
/** The next press answers `question`. */
|
|
31
|
+
awaitingAnswer: boolean;
|
|
32
|
+
/** The item the reply was about, so the transcript can mark it. */
|
|
33
|
+
targetId: string | null;
|
|
34
|
+
canUndo: boolean;
|
|
35
|
+
error: string | null;
|
|
36
|
+
/** A retry would send the same press again. */
|
|
37
|
+
retryable: boolean;
|
|
38
|
+
/** The spoken confirmation is playing. */
|
|
39
|
+
speaking: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ReplyMessages {
|
|
43
|
+
micDenied: string;
|
|
44
|
+
tooShort: string;
|
|
45
|
+
notHeard: string;
|
|
46
|
+
failed: string;
|
|
47
|
+
noAudio: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Shorter than this cannot hold a sentence: a tap, not a reply. */
|
|
51
|
+
const MIN_REPLY_MS = 500;
|
|
52
|
+
|
|
53
|
+
/** The slice of the briefing controller a reply needs. */
|
|
54
|
+
export interface ReplyBriefing {
|
|
55
|
+
getState(): { briefingId: string | null };
|
|
56
|
+
snapshotPosition(): BriefingPosition | null;
|
|
57
|
+
handoffToRecording(): Promise<void>;
|
|
58
|
+
resumeAfter(itemId: string | null): Promise<boolean>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The slice of the audio player that says the confirmation. */
|
|
62
|
+
export interface ReplySpeaker {
|
|
63
|
+
getState(): PlayerState;
|
|
64
|
+
subscribe(cb: (s: PlayerState) => void): () => void;
|
|
65
|
+
play(source: PlaybackSource): Promise<void>;
|
|
66
|
+
stop(): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const BLANK: ReplyState = {
|
|
70
|
+
phase: 'idle', utterance: null, understood: null, confirmation: null, question: null, awaitingAnswer: false,
|
|
71
|
+
targetId: null, canUndo: false, error: null, retryable: false, speaking: false,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export function createBriefingReplyController(deps: {
|
|
75
|
+
briefing: ReplyBriefing;
|
|
76
|
+
api: BriefingReplyApi;
|
|
77
|
+
audio: RecorderAudio;
|
|
78
|
+
speaker: ReplySpeaker;
|
|
79
|
+
removeFile(uri: string): Promise<void>;
|
|
80
|
+
ensurePermission(): Promise<Permission>;
|
|
81
|
+
/** `auto`: a sure reply is applied at once and shown with Undo. `ask`: show what was understood and wait for Do it. */
|
|
82
|
+
confirm: 'auto' | 'ask';
|
|
83
|
+
newId(): string;
|
|
84
|
+
strings: ReplyMessages;
|
|
85
|
+
/** Items changed on the server (a reply was applied or undone): reload what shows them. */
|
|
86
|
+
onChanged?(): void;
|
|
87
|
+
diag?: { log(event: string, fields?: Record<string, unknown>): void };
|
|
88
|
+
minReplyMs?: number;
|
|
89
|
+
/** Send a recording even when the microphone heard nothing (the fakes ignore the audio; a simulator has no voice to hear). */
|
|
90
|
+
allowSilence?: boolean;
|
|
91
|
+
}) {
|
|
92
|
+
let state: ReplyState = BLANK;
|
|
93
|
+
const listeners = new Set<() => void>();
|
|
94
|
+
const set = (patch: Partial<ReplyState>) => { state = { ...state, ...patch }; listeners.forEach((l) => l()); };
|
|
95
|
+
const log = (event: string, fields?: Record<string, unknown>) => deps.diag?.log(`reply.${event}`, fields);
|
|
96
|
+
|
|
97
|
+
let held = false;
|
|
98
|
+
/** The press in flight or waiting for a retry: its id, recording and position are what a retry resends. */
|
|
99
|
+
let attempt: ReplySend | null = null;
|
|
100
|
+
/** The press whose question the next recording answers. */
|
|
101
|
+
let asked: string | null = null;
|
|
102
|
+
let previewId: string | null = null;
|
|
103
|
+
/** Where the briefing was at the press in progress. */
|
|
104
|
+
let position0: BriefingPosition | null = null;
|
|
105
|
+
|
|
106
|
+
const fail = (message: string, retryable: boolean) => set({ phase: 'error', error: message, retryable, speaking: false });
|
|
107
|
+
const describe = (e: unknown): { message: string; retryable: boolean } => {
|
|
108
|
+
const err = e as { status?: number; code?: string; message?: string };
|
|
109
|
+
if (err.code === 'transcription_failed') return { message: deps.strings.notHeard, retryable: true };
|
|
110
|
+
if (err.status === 409 || err.status === 404 || err.status === 400) return { message: err.message || deps.strings.failed, retryable: false };
|
|
111
|
+
return { message: deps.strings.failed, retryable: true };
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
async function discard(uri: string) { await deps.removeFile(uri).catch(() => undefined); }
|
|
115
|
+
|
|
116
|
+
async function say(result: ReplyResult) {
|
|
117
|
+
if (!result.confirmation?.text) return;
|
|
118
|
+
try {
|
|
119
|
+
const source = await deps.api.confirmationSource(result);
|
|
120
|
+
if (!source) return;
|
|
121
|
+
set({ speaking: true });
|
|
122
|
+
await deps.speaker.play(source);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
log('speak-failed', { error: e instanceof Error ? e.message : String(e) });
|
|
125
|
+
set({ speaking: false });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function receive(result: ReplyResult, request: ReplySend) {
|
|
130
|
+
const targetId = result.actions.map((a) => ('itemId' in a ? a.itemId : null)).find(Boolean) ?? null;
|
|
131
|
+
const base = { utterance: result.utterance || state.utterance, understood: result.understood || null, targetId, error: null, retryable: false, speaking: false };
|
|
132
|
+
if (result.kind === 'preview') {
|
|
133
|
+
previewId = result.clientActionId;
|
|
134
|
+
set({ ...base, phase: 'preview', confirmation: null, question: null, awaitingAnswer: false, canUndo: false });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
previewId = null;
|
|
138
|
+
if (result.kind === 'clarify') {
|
|
139
|
+
asked = result.clientActionId;
|
|
140
|
+
set({ ...base, phase: 'asked', question: result.question, confirmation: null, awaitingAnswer: true, canUndo: false, targetId: null });
|
|
141
|
+
} else {
|
|
142
|
+
asked = null;
|
|
143
|
+
set({ ...base, phase: 'applied', confirmation: result.confirmation?.text ?? null, question: null, awaitingAnswer: false, canUndo: result.undoDepth > 0 });
|
|
144
|
+
}
|
|
145
|
+
if (result.refresh || request.undo) deps.onChanged?.();
|
|
146
|
+
await say(result);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function dispatch(request: ReplySend) {
|
|
150
|
+
set({ phase: 'sending', error: null, retryable: false });
|
|
151
|
+
try {
|
|
152
|
+
const result = await deps.api.send(request);
|
|
153
|
+
if (request.recording) { await discard(request.recording.uri); attempt = null; }
|
|
154
|
+
await receive(result, request);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
const { message, retryable } = describe(e);
|
|
157
|
+
log('failed', { status: (e as { status?: number }).status, code: (e as { code?: string }).code, error: (e as Error).message });
|
|
158
|
+
if (!retryable && request.recording) { await discard(request.recording.uri); attempt = null; }
|
|
159
|
+
// Kept for a retry: apply and undo carry no file, so they are retryable as they stand.
|
|
160
|
+
if (retryable) attempt = request;
|
|
161
|
+
fail(message, retryable);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function finishRecording() {
|
|
166
|
+
set({ phase: 'sending' });
|
|
167
|
+
let file;
|
|
168
|
+
try {
|
|
169
|
+
file = await deps.audio.stop();
|
|
170
|
+
} catch (e) {
|
|
171
|
+
log('stop-failed', { error: e instanceof Error ? e.message : String(e) });
|
|
172
|
+
return fail(deps.strings.failed, false);
|
|
173
|
+
}
|
|
174
|
+
if (file.durationMs < (deps.minReplyMs ?? MIN_REPLY_MS)) { await discard(file.uri); return fail(deps.strings.tooShort, false); }
|
|
175
|
+
if (!deps.allowSilence && file.peakDb !== undefined && isSilent({ peakDb: file.peakDb, samples: 1 })) { await discard(file.uri); return fail(deps.strings.noAudio, false); }
|
|
176
|
+
const briefingId = deps.briefing.getState().briefingId;
|
|
177
|
+
if (!briefingId) { await discard(file.uri); return fail(deps.strings.failed, false); }
|
|
178
|
+
const position = position0;
|
|
179
|
+
const request: ReplySend = {
|
|
180
|
+
briefingId, clientActionId: deps.newId(), mode: deps.confirm === 'ask' ? 'preview' : 'auto',
|
|
181
|
+
recording: { uri: file.uri, durationMs: file.durationMs }, ...(position ? { position } : {}),
|
|
182
|
+
...(asked ? { inReplyTo: asked } : {}),
|
|
183
|
+
};
|
|
184
|
+
await dispatch(request);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// The spoken confirmation ending (or being cut off) is not 'speaking' any more.
|
|
188
|
+
deps.speaker.subscribe((p) => { if (state.speaking && (p.phase === 'ended' || p.phase === 'idle' || p.phase === 'failed')) set({ speaking: false }); });
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
getState: () => state,
|
|
192
|
+
subscribe(listener: () => void) { listeners.add(listener); return () => { listeners.delete(listener); }; },
|
|
193
|
+
|
|
194
|
+
/** The button goes down. */
|
|
195
|
+
async pressStart(): Promise<void> {
|
|
196
|
+
if (state.phase === 'starting' || state.phase === 'recording' || state.phase === 'sending') return;
|
|
197
|
+
held = true;
|
|
198
|
+
await deps.speaker.stop().catch(() => undefined);
|
|
199
|
+
const keepAsked = state.awaitingAnswer;
|
|
200
|
+
// Before the handoff: it resets the player, and "this one" is where the briefing was.
|
|
201
|
+
position0 = deps.briefing.snapshotPosition();
|
|
202
|
+
set({ ...BLANK, phase: 'starting', awaitingAnswer: keepAsked, question: keepAsked ? state.question : null, targetId: state.targetId });
|
|
203
|
+
try {
|
|
204
|
+
await deps.briefing.handoffToRecording();
|
|
205
|
+
if ((await deps.ensurePermission()) === 'denied') { held = false; return fail(deps.strings.micDenied, false); }
|
|
206
|
+
await deps.audio.start({ onLevel: () => undefined });
|
|
207
|
+
} catch (e) {
|
|
208
|
+
held = false;
|
|
209
|
+
log('start-failed', { error: e instanceof Error ? e.message : String(e) });
|
|
210
|
+
return fail(deps.strings.failed, false);
|
|
211
|
+
}
|
|
212
|
+
if (!held) { await finishRecording(); return; }
|
|
213
|
+
set({ phase: 'recording' });
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
/** The button comes up. */
|
|
217
|
+
async pressEnd(): Promise<void> {
|
|
218
|
+
held = false;
|
|
219
|
+
if (state.phase === 'recording') await finishRecording();
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
/** Ask mode: do what was understood. */
|
|
223
|
+
async apply(): Promise<void> {
|
|
224
|
+
if (state.phase !== 'preview' || !previewId) return;
|
|
225
|
+
const briefingId = deps.briefing.getState().briefingId;
|
|
226
|
+
if (!briefingId) return;
|
|
227
|
+
await dispatch({ briefingId, clientActionId: previewId, apply: true });
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
/** The Undo button. */
|
|
231
|
+
async undo(): Promise<void> {
|
|
232
|
+
const briefingId = deps.briefing.getState().briefingId;
|
|
233
|
+
if (!briefingId || state.phase === 'sending') return;
|
|
234
|
+
await dispatch({ briefingId, clientActionId: deps.newId(), undo: true });
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
/** Send the same press again after a failure. */
|
|
238
|
+
async retry(): Promise<void> {
|
|
239
|
+
if (state.phase !== 'error' || !state.retryable || !attempt) return;
|
|
240
|
+
await dispatch(attempt);
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
/** Drop a preview or a failed press (and its recording). */
|
|
244
|
+
async cancel(): Promise<void> {
|
|
245
|
+
if (attempt?.recording) await discard(attempt.recording.uri);
|
|
246
|
+
attempt = null; previewId = null;
|
|
247
|
+
set({ ...BLANK, awaitingAnswer: false });
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
/** Carry on reading from the item after the one just answered. */
|
|
251
|
+
async continueBriefing(): Promise<void> {
|
|
252
|
+
await deps.speaker.stop().catch(() => undefined);
|
|
253
|
+
const target = state.targetId;
|
|
254
|
+
set({ ...BLANK });
|
|
255
|
+
asked = null; previewId = null;
|
|
256
|
+
await deps.briefing.resumeAfter(target);
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export type BriefingReplyController = ReturnType<typeof createBriefingReplyController>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ReplyResult } from '../../corpus/briefing';
|
|
2
|
+
import type { PlaybackSource } from './audioPlayer';
|
|
3
|
+
import type { BriefingPosition } from './controller';
|
|
4
|
+
|
|
5
|
+
type AuthorizedFetch = (url: string, init?: RequestInit) => Promise<Response>;
|
|
6
|
+
|
|
7
|
+
/** One press of the reply button, as the tenant's reply route takes it. */
|
|
8
|
+
export interface ReplySend {
|
|
9
|
+
briefingId: string;
|
|
10
|
+
/** Fresh per press; the same id again is a replay (a retry after a lost answer). */
|
|
11
|
+
clientActionId: string;
|
|
12
|
+
/** The recording to understand. Omit for `apply` and `undo`. */
|
|
13
|
+
recording?: { uri: string; durationMs: number };
|
|
14
|
+
/** Where the briefing was at the press ("this one"). */
|
|
15
|
+
position?: BriefingPosition | null;
|
|
16
|
+
/** `auto` applies a sure reply at once; `preview` only says what was understood. */
|
|
17
|
+
mode?: 'auto' | 'preview';
|
|
18
|
+
apply?: boolean;
|
|
19
|
+
undo?: boolean;
|
|
20
|
+
/** The id of the press whose question this one answers. */
|
|
21
|
+
inReplyTo?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface BriefingReplyApi {
|
|
25
|
+
send(request: ReplySend): Promise<ReplyResult>;
|
|
26
|
+
/** The spoken confirmation, owner-checked (needs the bearer), or null when there is only text. */
|
|
27
|
+
confirmationSource(result: ReplyResult): Promise<PlaybackSource | null>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* POST /corpus/briefing/reply. Audio goes up as multipart (the same `filePart` the recorder's uploads use); apply and undo
|
|
32
|
+
* are small JSON. A refusal throws with the route's `status` and `code` (`transcription_failed` is the one worth a retry).
|
|
33
|
+
*/
|
|
34
|
+
export function createBriefingReplyApi(deps: {
|
|
35
|
+
tandemUrl: string;
|
|
36
|
+
authorizedFetch: AuthorizedFetch;
|
|
37
|
+
bearer: () => Promise<string | null>;
|
|
38
|
+
filePart?: (uri: string) => Blob;
|
|
39
|
+
createForm?: () => FormData;
|
|
40
|
+
timeZone?: string;
|
|
41
|
+
}): BriefingReplyApi {
|
|
42
|
+
const base = deps.tandemUrl.replace(/\/+$/, '');
|
|
43
|
+
const timeZone = deps.timeZone ?? (() => { try { return Intl.DateTimeFormat().resolvedOptions().timeZone; } catch { return undefined; } })();
|
|
44
|
+
return {
|
|
45
|
+
async send(request) {
|
|
46
|
+
const fields: Record<string, string> = {
|
|
47
|
+
briefingId: request.briefingId,
|
|
48
|
+
clientActionId: request.clientActionId,
|
|
49
|
+
...(timeZone ? { timeZone } : {}),
|
|
50
|
+
...(request.mode ? { mode: request.mode } : {}),
|
|
51
|
+
...(request.apply ? { apply: 'true' } : {}),
|
|
52
|
+
...(request.undo ? { undo: 'true' } : {}),
|
|
53
|
+
...(request.inReplyTo ? { inReplyTo: request.inReplyTo } : {}),
|
|
54
|
+
...(request.position ? { position: JSON.stringify({ seconds: request.position.seconds, durationSeconds: request.position.durationSeconds }) } : {}),
|
|
55
|
+
};
|
|
56
|
+
let init: RequestInit;
|
|
57
|
+
if (request.recording) {
|
|
58
|
+
const body = (deps.createForm ?? (() => new FormData()))();
|
|
59
|
+
if (deps.filePart) body.append('audio', deps.filePart(request.recording.uri), 'reply.m4a');
|
|
60
|
+
else body.append('audio', { uri: request.recording.uri, name: 'reply.m4a', type: 'audio/mp4' } as unknown as Blob);
|
|
61
|
+
for (const [k, v] of Object.entries(fields)) body.append(k, v);
|
|
62
|
+
init = { method: 'POST', body };
|
|
63
|
+
} else {
|
|
64
|
+
const json: Record<string, unknown> = { ...fields };
|
|
65
|
+
if (request.position) json.position = { seconds: request.position.seconds, durationSeconds: request.position.durationSeconds };
|
|
66
|
+
init = { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(json) };
|
|
67
|
+
}
|
|
68
|
+
const res = await deps.authorizedFetch(`${base}/corpus/briefing/reply`, init);
|
|
69
|
+
if (!res.ok) {
|
|
70
|
+
const detail = await res.json().catch(() => ({})) as { detail?: string; code?: string };
|
|
71
|
+
throw Object.assign(new Error(detail.detail || `POST /corpus/briefing/reply failed (${res.status})`), { status: res.status, ...(detail.code ? { code: detail.code } : {}) });
|
|
72
|
+
}
|
|
73
|
+
return (await res.json()) as ReplyResult;
|
|
74
|
+
},
|
|
75
|
+
async confirmationSource(result) {
|
|
76
|
+
const url = result.confirmation?.audioUrl;
|
|
77
|
+
if (!url) return null;
|
|
78
|
+
const token = await deps.bearer();
|
|
79
|
+
return { uri: new URL(url, `${base}/`).toString(), ...(token ? { headers: { authorization: `Bearer ${token}` } } : {}) };
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -105,3 +105,23 @@ describe('deep link autostop test hook', () => {
|
|
|
105
105
|
expect(log).toHaveBeenCalledWith('deeplink', expect.objectContaining({ url: 'tandemgo://record', action: 'ignored-recording' }));
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
|
+
|
|
109
|
+
describe('deep link tandemgo://briefing', () => {
|
|
110
|
+
const withBriefing = createLinkResolver(resolveFoundryApp({ app: { name: 'Tandem Go', scheme: 'tandemgo' }, tenant: { url: 'https://t.example.com' }, features: { briefing: true } }));
|
|
111
|
+
it('waits for the session, then opens the briefing once', async () => {
|
|
112
|
+
const openBriefing = vi.fn();
|
|
113
|
+
const link = createDeepLink({ resolver: withBriefing, openBriefing, log: vi.fn() });
|
|
114
|
+
link.handle('tandemgo://briefing');
|
|
115
|
+
expect(openBriefing).not.toHaveBeenCalled();
|
|
116
|
+
await link.sessionReady();
|
|
117
|
+
await link.sessionReady();
|
|
118
|
+
expect(openBriefing).toHaveBeenCalledTimes(1);
|
|
119
|
+
});
|
|
120
|
+
it('opens at once when the session is already ready', async () => {
|
|
121
|
+
const openBriefing = vi.fn();
|
|
122
|
+
const link = createDeepLink({ resolver: withBriefing, openBriefing, log: vi.fn() });
|
|
123
|
+
await link.sessionReady();
|
|
124
|
+
link.handle('tandemgo://briefing');
|
|
125
|
+
expect(openBriefing).toHaveBeenCalledTimes(1);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -12,6 +12,8 @@ export function createDeepLink(deps: {
|
|
|
12
12
|
go?: (options: GoOptions) => Promise<void> | void;
|
|
13
13
|
/** Open a tab (optionally on one record): the shell navigator. */
|
|
14
14
|
open?: (tab: string, id?: string) => void;
|
|
15
|
+
/** Open the GO screen and play today's briefing (the morning notification's link). */
|
|
16
|
+
openBriefing?: () => void;
|
|
15
17
|
log?: (event: string, fields?: Record<string, unknown>) => void;
|
|
16
18
|
}) {
|
|
17
19
|
const log = deps.log ?? (() => undefined);
|
|
@@ -19,6 +21,11 @@ export function createDeepLink(deps: {
|
|
|
19
21
|
let pending: { action: LinkAction; url: string } | null = null;
|
|
20
22
|
|
|
21
23
|
const run = (action: LinkAction, url: string) => {
|
|
24
|
+
if (action.kind === 'briefing') {
|
|
25
|
+
log('deeplink', { url, action: 'briefing' });
|
|
26
|
+
deps.openBriefing?.();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
22
29
|
if (action.kind === 'open') {
|
|
23
30
|
log('deeplink', { url, action: 'open', tab: action.tab, id: action.id });
|
|
24
31
|
deps.open?.(action.tab, action.id);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { trackerTab } from '../tab';
|
|
3
|
+
|
|
4
|
+
describe('the to-do list re-reads when a reply edited items', () => {
|
|
5
|
+
it('test_items_changed_refreshes_the_list_controller', () => {
|
|
6
|
+
const listeners = new Set<() => void>();
|
|
7
|
+
const controller = { refresh: vi.fn(async () => undefined) };
|
|
8
|
+
trackerTab({ api: {} as never, controller: controller as never, itemsChanged: { subscribe: (l) => { listeners.add(l); return () => listeners.delete(l); } } });
|
|
9
|
+
expect(controller.refresh).not.toHaveBeenCalled();
|
|
10
|
+
listeners.forEach((l) => l());
|
|
11
|
+
expect(controller.refresh).toHaveBeenCalledTimes(1);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -18,10 +18,13 @@ export interface TrackerTabOptions {
|
|
|
18
18
|
memberConnections?: Pick<MemberConnectionsApi, 'connections' | 'connectorCatalog'>;
|
|
19
19
|
/** Opens a URL outside the app (`Linking.openURL`). A tracker link tries the tracker's app, then https. */
|
|
20
20
|
openUrl?: (url: string) => Promise<unknown>;
|
|
21
|
+
/** Something else edited items (a spoken reply): the list re-reads. */
|
|
22
|
+
itemsChanged?: { subscribe(listener: () => void): () => void };
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
/** The to-do tab as one `FoundryTabsShell` entry: list -> detail (with the source note link). */
|
|
24
|
-
export function trackerTab({ api, key = 'tracker', label = 'To-dos', notesKey = 'notes', controller = createTrackerController({ api }), memberConnections, openUrl }: TrackerTabOptions): FoundryTab {
|
|
26
|
+
export function trackerTab({ api, key = 'tracker', label = 'To-dos', notesKey = 'notes', controller = createTrackerController({ api }), memberConnections, openUrl, itemsChanged }: TrackerTabOptions): FoundryTab {
|
|
27
|
+
itemsChanged?.subscribe(() => { void controller.refresh(); });
|
|
25
28
|
const onOpenLink = openUrl ? (url: string) => { void openTrackerLink(url, openUrl).catch(() => undefined); } : undefined;
|
|
26
29
|
function Screen({ route, push, back, openTab }: { route: { id: string } | null; push: (id: string) => void; back: () => void; openTab: (tab: string, id?: string) => void }) {
|
|
27
30
|
const trackerName = useTrackerName(memberConnections);
|