@startsimpli/integrations 0.2.225 → 0.2.227
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/__tests__/attention-orgs.test.ts +61 -0
- package/src/__tests__/attention-run.test.ts +3 -3
- package/src/__tests__/converse-meeting-interrupted.test.ts +74 -0
- package/src/__tests__/converse-meeting-vad.test.ts +25 -3
- package/src/__tests__/converse-meeting.test.ts +29 -0
- package/src/__tests__/converse-roci-transcript.test.ts +36 -0
- package/src/__tests__/converse-soak.test.ts +28 -0
- package/src/__tests__/converse-tts.test.ts +128 -0
- package/src/__tests__/converse.test.ts +38 -1
- package/src/__tests__/relay-items.test.ts +1 -1
- package/src/corpus/attention/importance.ts +1 -1
- package/src/corpus/attention/index.ts +1 -0
- package/src/corpus/attention/orgs.ts +41 -0
- package/src/corpus/attention/policy.ts +2 -0
- package/src/corpus/attention/push.ts +2 -1
- package/src/corpus/attention/queue.ts +3 -1
- package/src/corpus/attention/run-steps.ts +1 -1
- package/src/corpus/attention/run.ts +4 -3
- package/src/corpus/attention/types.ts +1 -1
- package/src/corpus/converse/handle.ts +12 -4
- package/src/corpus/converse/meeting-config.ts +8 -2
- package/src/corpus/converse/meeting.ts +24 -5
- package/src/corpus/converse/respond.ts +2 -2
- package/src/corpus/converse/speak-chunks.ts +33 -0
- package/src/corpus/converse/speak.ts +17 -4
- package/src/corpus/converse/types.ts +2 -0
- package/src/corpus/converse/vad.ts +16 -1
- package/src/corpus/notify/types.ts +2 -0
- package/src/native/app/FoundryApp.tsx +37 -2
- package/src/native/app/__tests__/briefingServices.test.ts +26 -0
- package/src/native/app/__tests__/haptics.test.tsx +55 -0
- package/src/native/app/__tests__/launch.test.ts +23 -1
- package/src/native/app/briefingServices.ts +9 -0
- package/src/native/app/converseServices.ts +17 -5
- package/src/native/app/device.ts +7 -0
- package/src/native/app/launch.ts +24 -0
- package/src/native/app/registry.tsx +6 -1
- package/src/native/app/services.ts +2 -2
- package/src/native/briefing/__tests__/playerPauseResume.test.ts +47 -0
- package/src/native/briefing/audioPlayer.ts +16 -1
- package/src/native/converse/ConverseScreen.tsx +45 -78
- package/src/native/converse/__tests__/bargeInIO.test.ts +49 -0
- package/src/native/converse/__tests__/liveScreen.test.tsx +59 -63
- package/src/native/converse/__tests__/meetingIO.test.ts +89 -23
- package/src/native/converse/__tests__/mock.test.ts +58 -0
- package/src/native/converse/__tests__/speedScreen.test.tsx +6 -2
- package/src/native/converse/index.ts +4 -1
- package/src/native/converse/io.ts +34 -20
- package/src/native/converse/mock.ts +136 -0
- package/src/native/converse/stateBanner.tsx +41 -0
- package/src/native/index.ts +1 -0
- package/src/native/push/NeedsYouCard.tsx +11 -7
- package/src/native/push/__tests__/decisionsApp.test.tsx +2 -3
- package/src/native/push/__tests__/needsYou.test.tsx +23 -9
- package/src/native/push/fake.ts +5 -5
- package/src/native/recording/recorder.ts +2 -1
- package/src/native/recording/recorderAudio.ts +14 -1
- package/src/native/talk/TalkTab.tsx +16 -13
- package/src/native/talk/__tests__/talk-tab.test.tsx +18 -0
- package/src/native/voice-session/__tests__/bargeIn.test.ts +93 -0
- package/src/native/voice-session/__tests__/bindings.test.ts +84 -0
- package/src/native/voice-session/__tests__/events.test.ts +72 -0
- package/src/native/voice-session/__tests__/inspector.test.ts +28 -0
- package/src/native/voice-session/__tests__/lifecycle.test.ts +197 -0
- package/src/native/voice-session/__tests__/music.test.ts +86 -0
- package/src/native/voice-session/__tests__/routes.test.ts +121 -0
- package/src/native/voice-session/__tests__/voiceSession.test.ts +177 -0
- package/src/native/voice-session/bindMeeting.ts +33 -0
- package/src/native/voice-session/fake.ts +21 -0
- package/src/native/voice-session/index.ts +142 -0
- package/src/native/voice-session/inspector.ts +14 -0
- package/src/native/voice-session/machine.ts +41 -0
- package/src/native/voice-session/nowPlaying.ts +35 -0
- package/src/native/voice-session/types.ts +45 -0
- package/src/native/voice-session/wire.ts +47 -0
- package/src/native/converse/DriveScreen.tsx +0 -47
- package/src/native/converse/__tests__/driveScreen.test.tsx +0 -54
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** The "needs you" queue: the fleet's waiting-on-Quinn lines plus his pending decisions, classified. */
|
|
2
2
|
import type { FleetView } from '../converse/fleet-view';
|
|
3
3
|
import type { DecisionIndexRow, RelayItem } from '../notify/types';
|
|
4
|
+
import type { OrgItem } from './orgs';
|
|
4
5
|
import { importanceOf } from './importance';
|
|
5
6
|
import { classifyItem, itemId } from './policy';
|
|
6
7
|
import type { AttentionClass, AttentionItem, AttentionPolicy, NeedsYouQueue, QueuedItem } from './types';
|
|
@@ -8,10 +9,11 @@ import type { AttentionClass, AttentionItem, AttentionPolicy, NeedsYouQueue, Que
|
|
|
8
9
|
const ORDER: AttentionClass[] = ['urgent', 'needs-answer', 'digest', 'noise'];
|
|
9
10
|
const clean = (s: string) => s.replace(/`|\*\*/g, '').replace(/\s+/g, ' ').trim();
|
|
10
11
|
|
|
11
|
-
export function buildNeedsYou(input: { view: Pick<FleetView, 'waitingOnQuinn'> | null; decisions: DecisionIndexRow[]; policy: AttentionPolicy; /** Items already answered (by id): they leave the queue. */ answered?: Record<string, unknown>; /** Questions the relay posted for him (their own list, never touched by the fleet snapshot). */ relay?: RelayItem[] }): NeedsYouQueue {
|
|
12
|
+
export function buildNeedsYou(input: { view: Pick<FleetView, 'waitingOnQuinn'> | null; decisions: DecisionIndexRow[]; policy: AttentionPolicy; /** Items already answered (by id): they leave the queue. */ answered?: Record<string, unknown>; /** Questions the relay posted for him (their own list, never touched by the fleet snapshot). */ relay?: RelayItem[]; /** Running QuinnAI orgs with asks or a hold for him (see orgs.ts). */ orgs?: OrgItem[] }): NeedsYouQueue {
|
|
12
13
|
type Raw = Omit<AttentionItem, 'id'> & { id?: string };
|
|
13
14
|
const rawIn: Raw[] = [
|
|
14
15
|
...(input.relay ?? []).map((r) => ({ id: `relay:${r.id}`, text: clean(r.text), source: 'relay' as const, ...(r.options?.length ? { options: r.options } : {}), ...(r.source ? { from: r.source } : {}), ...(r.link ? { link: r.link } : {}) })),
|
|
16
|
+
...(input.orgs ?? []).map((o) => ({ id: o.id, text: clean(o.text), source: 'org' as const, from: o.from, link: o.link })),
|
|
15
17
|
...input.decisions.filter((d) => d.status === 'pending').map((d) => ({ text: clean(d.title), source: 'decision' as const, ref: d.id })),
|
|
16
18
|
...(input.view?.waitingOnQuinn ?? []).map((t) => ({ text: clean(t), source: 'fleet' as const })),
|
|
17
19
|
];
|
|
@@ -45,7 +45,7 @@ const reply = (run: AttentionRunState, text: string, recorded?: RunReply['record
|
|
|
45
45
|
|
|
46
46
|
export function startRun(input: { conversationId: string; items: RunItem[]; now: string }): { run: AttentionRunState; reply: RunReply } {
|
|
47
47
|
const run: AttentionRunState = { conversation_id: input.conversationId, items: input.items, index: 0, answers: {}, skipped: [], status: input.items.length ? 'asking' : 'done', started_at: input.now };
|
|
48
|
-
if (!input.items.length) return { run, reply: reply(run, 'Nothing is waiting on you right now.') };
|
|
48
|
+
if (!input.items.length) return { run, reply: reply(run, 'Nothing is waiting on you right now. Ask me what is in flight for a short status.') };
|
|
49
49
|
const n = input.items.length;
|
|
50
50
|
return { run, reply: reply(run, `${n === 1 ? 'One thing needs you.' : `${n} things need you, most important first.`} ${questionText(run)}`) };
|
|
51
51
|
}
|
|
@@ -4,6 +4,7 @@ import { buildFleetView } from '../converse/fleet-view';
|
|
|
4
4
|
import { answerDecision, getDecision } from '../notify/handle';
|
|
5
5
|
import { loadState, saveState } from '../notify/state';
|
|
6
6
|
import type { NotifyDeps } from '../notify/types';
|
|
7
|
+
import { loadOrgItems } from './orgs';
|
|
7
8
|
import { buildNeedsYou } from './queue';
|
|
8
9
|
import { startRun, stepRun, type RunReply } from './run-steps';
|
|
9
10
|
import { policyFrom } from './settings';
|
|
@@ -18,16 +19,16 @@ export interface AttentionRunApi {
|
|
|
18
19
|
/** What the relay is told when he answers one of its questions. */
|
|
19
20
|
export interface RelayDelivery { id: string; text: string; answer: string; source?: string; link?: string }
|
|
20
21
|
|
|
21
|
-
export function createAttentionRun(deps: Pick<NotifyDeps, 'http' | 'ownerSub' | 'now'>, opts: { batch?: number; /** Tells the relay his answer (the server runs the bridge). A failure keeps the answer stored for the relay to read back. */ deliverRelay?: (d: RelayDelivery) => Promise<void> } = {}): AttentionRunApi {
|
|
22
|
+
export function createAttentionRun(deps: Pick<NotifyDeps, 'http' | 'ownerSub' | 'now' | 'orgs'>, opts: { batch?: number; /** Tells the relay his answer (the server runs the bridge). A failure keeps the answer stored for the relay to read back. */ deliverRelay?: (d: RelayDelivery) => Promise<void> } = {}): AttentionRunApi {
|
|
22
23
|
const nowIso = () => new Date((deps.now ?? Date.now)()).toISOString();
|
|
23
24
|
return {
|
|
24
25
|
async start(conversationId) {
|
|
25
26
|
const state = await loadState(deps);
|
|
26
27
|
const snap = await loadFleetSnapshot(deps as never).catch(() => null);
|
|
27
28
|
const policy = policyFrom(state.attention);
|
|
28
|
-
const queue = buildNeedsYou({ view: snap?.inputs ? buildFleetView(snap.inputs) : null, decisions: state.decisions, policy, answered: state.answered, relay: state.relay_items });
|
|
29
|
+
const queue = buildNeedsYou({ view: snap?.inputs ? buildFleetView(snap.inputs) : null, decisions: state.decisions, policy, answered: state.answered, relay: state.relay_items, orgs: await loadOrgItems(deps) });
|
|
29
30
|
// Fleet lines are prose, not questions: they stay in the queue (and still drive pushes) but are never asked as yes/no. The relay posts real questions through relay-items, with options.
|
|
30
|
-
const items = queue.items.filter((i) => i.source !== 'fleet' && (i.class === 'urgent' || i.class === 'needs-answer')).slice(0, opts.batch ?? policy.briefBatch).map((i) => ({ id: i.id, text: i.text, ...(i.ref ? { ref: i.ref } : {}), ...(i.options?.length ? { options: i.options } : {}) }));
|
|
31
|
+
const items = queue.items.filter((i) => i.source !== 'fleet' && i.source !== 'org' && (i.class === 'urgent' || i.class === 'needs-answer')).slice(0, opts.batch ?? policy.briefBatch).map((i) => ({ id: i.id, text: i.text, ...(i.ref ? { ref: i.ref } : {}), ...(i.options?.length ? { options: i.options } : {}) }));
|
|
31
32
|
const { run, reply } = startRun({ conversationId, items, now: nowIso() });
|
|
32
33
|
await saveState(deps as never, { ...state, attention_run: run });
|
|
33
34
|
return reply;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* approvals ping, self-answering routine questions) are fields here, never constants in the logic.
|
|
5
5
|
*/
|
|
6
6
|
export type AttentionClass = 'urgent' | 'needs-answer' | 'digest' | 'noise';
|
|
7
|
-
export type AttentionSource = 'fleet' | 'decision' | 'relay';
|
|
7
|
+
export type AttentionSource = 'fleet' | 'decision' | 'relay' | 'org';
|
|
8
8
|
|
|
9
9
|
export interface AttentionItem { id: string; text: string; source: AttentionSource; /** The decision id, for an item that is a pending decision (opens its card). */ ref?: string; /** A relay item's choices ("schedule" or "manual"): asked as a choice, not yes/no. */ options?: string[]; /** Who asked, in plain words (a relay item's source project). */ from?: string; /** Where to look at it, when there is somewhere. */ link?: string }
|
|
10
10
|
export interface QueuedItem extends AttentionItem { class: AttentionClass; /** 0-100; urgent 100. Orders the queue and gates call-me. */ importance: number }
|
|
@@ -12,6 +12,7 @@ import { unhandledAsks } from './handled-asks';
|
|
|
12
12
|
import { renderNextSteps, renderTranscript, renderWhatHeSaid, titleFor } from './transcript';
|
|
13
13
|
import { createEntityConversationStore } from './store';
|
|
14
14
|
import { speakSide } from './speak';
|
|
15
|
+
import { ASSISTANT_NAME } from './roci';
|
|
15
16
|
import { speakable } from '../briefing/speak';
|
|
16
17
|
import { localDate } from '../today';
|
|
17
18
|
import { toSpoken } from './spoken-form';
|
|
@@ -31,6 +32,10 @@ function filedText(filed: string[], project?: string | null): string {
|
|
|
31
32
|
const list = more > 0 ? `${titles.join(', ')}, and ${more} more` : titles.length <= 2 ? titles.join(' and ') : `${titles.slice(0, -1).join(', ')} and ${titles[titles.length - 1]}`;
|
|
32
33
|
return `Filed the note${where} and ${filed.length} to-do${filed.length === 1 ? '' : 's'}: ${list}.`;
|
|
33
34
|
}
|
|
35
|
+
/** A clip this big had real speech in it (about 3 s of AAC): when it comes back with no words, the apology is SPOKEN. Smaller is a cough or road noise: quiet. */
|
|
36
|
+
const SPEAK_NOT_HEARD_MIN_BYTES = 24_000;
|
|
37
|
+
/** The speech-to-text marks non-speech sounds like "[singing]" or "[music]": they are not words. */
|
|
38
|
+
const SOUND_TAGS = /\[[^\[\]]{1,40}\]/g;
|
|
34
39
|
const NOT_HEARD = 'Sorry, I did not catch that. Can you say that again?';
|
|
35
40
|
const BRAIN_FAILED = 'I am having trouble thinking right now. Your words are saved. Try again in a moment.';
|
|
36
41
|
|
|
@@ -77,7 +82,8 @@ export async function handleConverseTurn(deps: ConverseDeps, req: ConverseTurnRe
|
|
|
77
82
|
const n = (record?.turns.length ?? 0) + 1;
|
|
78
83
|
const turnId = req.turnId ?? `t${n}-${newId()}`.slice(0, 64).replace(/[^A-Za-z0-9_-]/g, '_').padEnd(8, '_');
|
|
79
84
|
const timeZone = req.timeZone || record?.timeZone || 'UTC';
|
|
80
|
-
|
|
85
|
+
// The assistant's own name leads: STT hears Rosie / Rochie / Rossi for Roci; earlier turns follow for context.
|
|
86
|
+
const hints = [ASSISTANT_NAME, ...(record?.turns ?? []).slice(-3).map((t) => t.user.text)];
|
|
81
87
|
|
|
82
88
|
const clock = { t0: Date.now(), last: Date.now() };
|
|
83
89
|
const timing: Record<string, number> = {};
|
|
@@ -85,10 +91,11 @@ export async function handleConverseTurn(deps: ConverseDeps, req: ConverseTurnRe
|
|
|
85
91
|
|
|
86
92
|
// 1. Words.
|
|
87
93
|
let utterance = req.text?.trim() ?? '';
|
|
88
|
-
|
|
94
|
+
// A recording with no bytes (the empty-file race) has nothing to transcribe: treated as silence.
|
|
95
|
+
if (req.audio && req.audio.audio.byteLength > 0) {
|
|
89
96
|
if (!deps.transcribe) throw new ConverseError('Speech to text is not set up.', 503, 'transcription_unavailable');
|
|
90
97
|
try {
|
|
91
|
-
utterance = (await deps.transcribe({ audio: req.audio.audio, mimeType: req.audio.mimeType, hints })).trim();
|
|
98
|
+
utterance = (await deps.transcribe({ audio: req.audio.audio, mimeType: req.audio.mimeType, hints })).replace(SOUND_TAGS, ' ').replace(/\s+/g, ' ').trim();
|
|
92
99
|
} catch (error) {
|
|
93
100
|
if (error instanceof Error && /no speech providers|provider is not configured|not configured/i.test(error.message)) {
|
|
94
101
|
throw new ConverseError('Voice is not set up on this server. You can type instead.', 503, 'speech_unavailable');
|
|
@@ -178,7 +185,8 @@ export async function handleConverseTurn(deps: ConverseDeps, req: ConverseTurnRe
|
|
|
178
185
|
}
|
|
179
186
|
lap('keep_user_audio');
|
|
180
187
|
// Nothing was heard: the page stays quiet and listens again, so there is nothing to speak (the text is still kept).
|
|
181
|
-
const
|
|
188
|
+
const quietMiss = Boolean(req.audio && !utterance && req.audio.audio.byteLength < SPEAK_NOT_HEARD_MIN_BYTES);
|
|
189
|
+
const assistant = quietMiss
|
|
182
190
|
? { text: replyText, audio_reason: 'nothing was heard' }
|
|
183
191
|
: await speakSide(deps, `${conversationId}-t${n}-reply`, replyText, spokenText ?? toSpoken(replyText, localDate(now, timeZone)) ?? undefined);
|
|
184
192
|
lap('tts');
|
|
@@ -11,6 +11,12 @@ export interface MeetingConfig {
|
|
|
11
11
|
maxUtteranceMs: number;
|
|
12
12
|
/** Mic level (0..1 RMS) that counts as speech. */
|
|
13
13
|
speechLevel: number;
|
|
14
|
+
/** Adaptive threshold: to START, the level must exceed the tracked background by this factor (never below `speechLevel`). */
|
|
15
|
+
startOverNoise: number;
|
|
16
|
+
/** To CONTINUE speaking, the level need only exceed the background by this factor. */
|
|
17
|
+
stayOverNoise: number;
|
|
18
|
+
/** The tracked background never counts as louder than this. */
|
|
19
|
+
noiseFloorMax: number;
|
|
14
20
|
/** The level must hold this long to count as the start of speech. */
|
|
15
21
|
speechStartMs: number;
|
|
16
22
|
/** Speaking during Tandem's reply stops the reply and listens (barge-in). Acts only when the io is duplex (echo-cancelled mic). */
|
|
@@ -38,14 +44,14 @@ export interface MeetingConfig {
|
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
export const MEETING_DEFAULTS: MeetingConfig = {
|
|
41
|
-
silenceMs:
|
|
47
|
+
silenceMs: 850, minUtteranceMs: 250, maxUtteranceMs: 60_000, speechLevel: 0.02, speechStartMs: 150, bargeInLevel: 0.08, startOverNoise: 3, stayOverNoise: 1.6, noiseFloorMax: 0.05,
|
|
42
48
|
interruptOnSpeech: true, idleRotateMs: 30_000, relayPollMs: 4000, resendMs: 3000,
|
|
43
49
|
thinkingMaxMs: 25_000, speakingMaxMs: 120_000, listenStallMs: 15_000, watchdogTickMs: 1000, listenRetryMs: 1500, assistantName: 'Roci',
|
|
44
50
|
};
|
|
45
51
|
|
|
46
52
|
export function resolveMeetingConfig(over: Partial<MeetingConfig> = {}): MeetingConfig {
|
|
47
53
|
const out: MeetingConfig = { ...MEETING_DEFAULTS };
|
|
48
|
-
for (const key of ['silenceMs', 'minUtteranceMs', 'maxUtteranceMs', 'speechLevel', 'speechStartMs', 'bargeInLevel', 'idleRotateMs', 'relayPollMs', 'resendMs', 'thinkingMaxMs', 'speakingMaxMs', 'listenStallMs', 'watchdogTickMs', 'listenRetryMs'] as const) {
|
|
54
|
+
for (const key of ['silenceMs', 'minUtteranceMs', 'maxUtteranceMs', 'speechLevel', 'speechStartMs', 'bargeInLevel', 'startOverNoise', 'stayOverNoise', 'noiseFloorMax', 'idleRotateMs', 'relayPollMs', 'resendMs', 'thinkingMaxMs', 'speakingMaxMs', 'listenStallMs', 'watchdogTickMs', 'listenRetryMs'] as const) {
|
|
49
55
|
const v = over[key];
|
|
50
56
|
if (typeof v === 'number' && Number.isFinite(v) && v > 0) out[key] = v;
|
|
51
57
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* and listening resumes; only a rejected session stops it.
|
|
9
9
|
*/
|
|
10
10
|
import { ConverseClientError } from './client';
|
|
11
|
+
import { normalizeAssistantName } from './roci';
|
|
11
12
|
import { resolveMeetingConfig, type MeetingConfig } from './meeting-config';
|
|
12
13
|
import type { ConverseEndResult, ConverseIntent, ConverseSource, ConverseThread, ConverseTurnResult } from './types';
|
|
13
14
|
|
|
@@ -18,6 +19,8 @@ export interface MeetingLine {
|
|
|
18
19
|
text: string;
|
|
19
20
|
intent?: ConverseIntent;
|
|
20
21
|
sources?: ConverseSource[];
|
|
22
|
+
/** The reply was cut off while it was being spoken (voice over it, or the Interrupt tap): the person heard only part of it. */
|
|
23
|
+
interrupted?: boolean;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
export interface MeetingState {
|
|
@@ -36,6 +39,8 @@ export interface MeetingState {
|
|
|
36
39
|
micOn: boolean;
|
|
37
40
|
/** True while the microphone is actually open. With a duplex io it stays true while the reply is thought about and spoken. */
|
|
38
41
|
micLive: boolean;
|
|
42
|
+
/** True from the moment the person's voice starts until that utterance is handed over (what the audio session calls `hearing`). */
|
|
43
|
+
hearing: boolean;
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
/** Why `listen` returned: the platform's detector says, the controller only needs `audio` and `cancelled`. */
|
|
@@ -106,7 +111,7 @@ export function createMeetingController<A = Blob>(options: {
|
|
|
106
111
|
}): MeetingController {
|
|
107
112
|
const { client, io } = options;
|
|
108
113
|
const config = resolveMeetingConfig(options.config);
|
|
109
|
-
let s: MeetingState = { phase: 'idle', retryable: false, lines: [], error: null, noAudio: null, conversationId: null, saved: null, relayNotice: null, micOn: false, micLive: false };
|
|
114
|
+
let s: MeetingState = { phase: 'idle', retryable: false, lines: [], error: null, noAudio: null, conversationId: null, saved: null, relayNotice: null, micOn: false, micLive: false, hearing: false };
|
|
110
115
|
const duplex = options.io.duplex === true;
|
|
111
116
|
let running = false;
|
|
112
117
|
/** Wakes the loop when the mic is turned back on. */
|
|
@@ -170,6 +175,14 @@ export function createMeetingController<A = Blob>(options: {
|
|
|
170
175
|
const startWatchdog = () => { if (!wdTimer) wdTimer = setInterval(watchdogTick, config.watchdogTickMs); };
|
|
171
176
|
const stopWatchdog = () => { if (wdTimer) clearInterval(wdTimer); wdTimer = null; };
|
|
172
177
|
|
|
178
|
+
/** The reply being spoken was cut short: its line says so, so the transcript never shows words he did not hear. */
|
|
179
|
+
const markInterrupted = (): Partial<MeetingState> => {
|
|
180
|
+
const i = s.lines.map((l) => l.role).lastIndexOf('assistant');
|
|
181
|
+
const j = s.lines.map((l) => l.role).lastIndexOf('relay');
|
|
182
|
+
const at = Math.max(i, j);
|
|
183
|
+
return at < 0 ? {} : { lines: s.lines.map((l, k) => (k === at ? { ...l, interrupted: true } : l)) };
|
|
184
|
+
};
|
|
185
|
+
|
|
173
186
|
async function playReply(reply: MeetingReply) {
|
|
174
187
|
// A reply (a relay message, a slow answer) never talks over him: wait until his utterance is over.
|
|
175
188
|
while (duplex && running && userSpeaking) await new Promise((r) => setTimeout(r, 50));
|
|
@@ -199,10 +212,12 @@ export function createMeetingController<A = Blob>(options: {
|
|
|
199
212
|
// A recording with no words in it (a cough, a pause, the room): no line, no "sorry", no sound. Listen again.
|
|
200
213
|
if (input.audio && !(out.transcript ?? '').trim()) {
|
|
201
214
|
set({ conversationId: out.conversation_id });
|
|
202
|
-
|
|
215
|
+
// A turn is never silent when he really spoke: the server then sends a spoken "did not catch that", shown and played like any reply.
|
|
216
|
+
if (!out.audio_url) { wdLog('no-words-quiet', { turn: out.turn }); return true; }
|
|
217
|
+
wdLog('no-words', { turn: out.turn });
|
|
203
218
|
}
|
|
204
|
-
// A briefing turn the assistant began itself has no words from him: nothing is shown as his message.
|
|
205
|
-
const hisWords =
|
|
219
|
+
// A briefing turn the assistant began itself, or a recording with no words, has no words from him: nothing is shown as his message.
|
|
220
|
+
const hisWords = !out.transcript ? [] : [{ role: 'user' as const, text: normalizeAssistantName(out.transcript, config.assistantName) }];
|
|
206
221
|
set({
|
|
207
222
|
conversationId: out.conversation_id,
|
|
208
223
|
lines: [...s.lines, ...hisWords, { role: 'assistant', text: out.reply_text, ...(out.intent ? { intent: out.intent } : {}), ...(out.sources?.length ? { sources: out.sources } : {}) }],
|
|
@@ -324,7 +339,9 @@ export function createMeetingController<A = Blob>(options: {
|
|
|
324
339
|
// Barge-in: the person starts talking while the reply is being read: cut it off, what they say is the next turn.
|
|
325
340
|
onSpeechStart: () => {
|
|
326
341
|
userSpeaking = true;
|
|
327
|
-
|
|
342
|
+
const cut = duplex && config.interruptOnSpeech && s.phase === 'speaking';
|
|
343
|
+
set({ hearing: true, ...(cut ? markInterrupted() : {}) });
|
|
344
|
+
if (cut) speakAbort.abort('barge-in');
|
|
328
345
|
},
|
|
329
346
|
});
|
|
330
347
|
listenFailures = 0;
|
|
@@ -338,6 +355,7 @@ export function createMeetingController<A = Blob>(options: {
|
|
|
338
355
|
continue;
|
|
339
356
|
}
|
|
340
357
|
userSpeaking = false;
|
|
358
|
+
if (s.hearing) set({ hearing: false });
|
|
341
359
|
if (!running) break;
|
|
342
360
|
// An io with no microphone cancels by itself: wait for End (typing still works) instead of spinning.
|
|
343
361
|
if (heard.cancelled && !listenAbort.signal.aborted) {
|
|
@@ -380,6 +398,7 @@ export function createMeetingController<A = Blob>(options: {
|
|
|
380
398
|
start() { begin(true); },
|
|
381
399
|
stop() {
|
|
382
400
|
stopEpoch += 1;
|
|
401
|
+
if (running && s.phase === 'speaking') set({ ...markInterrupted() });
|
|
383
402
|
speakAbort.abort('stop');
|
|
384
403
|
if (running && s.phase === 'speaking') set({ phase: restPhase() });
|
|
385
404
|
},
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* POST /corpus/converse/end JSON {conversation_id}
|
|
5
5
|
* GET /corpus/converse/<id>/turn/<n>/audio[?who=user] a turn's recording, to its owner only
|
|
6
6
|
*/
|
|
7
|
-
import { buildNeedsYou, policyFrom } from '../attention';
|
|
7
|
+
import { buildNeedsYou, loadOrgItems, policyFrom } from '../attention';
|
|
8
8
|
import { loadState } from '../notify/state';
|
|
9
9
|
import { parseTodoSyncRecord } from './sync-health';
|
|
10
10
|
import { isTimeZone } from '../spoken-time';
|
|
@@ -158,7 +158,7 @@ export async function converseFleetViewResponse(deps: ConverseDeps): Promise<Res
|
|
|
158
158
|
const snap = await loadFleetSnapshot(deps);
|
|
159
159
|
const view = snap?.inputs ? buildFleetView(snap.inputs) : null;
|
|
160
160
|
const state = await loadState(deps);
|
|
161
|
-
const needs_you = buildNeedsYou({ view, decisions: state.decisions, policy: policyFrom(state.attention), answered: state.answered, relay: state.relay_items });
|
|
161
|
+
const needs_you = buildNeedsYou({ view, decisions: state.decisions, policy: policyFrom(state.attention), answered: state.answered, relay: state.relay_items, orgs: await loadOrgItems(deps) });
|
|
162
162
|
const body = snap
|
|
163
163
|
? { snapshot: { text: snap.text, updatedAt: snap.updatedAt, view, todoSync: parseTodoSyncRecord(snap.inputs?.todo_sync) }, needs_you }
|
|
164
164
|
: { snapshot: null, needs_you };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Splits a reply into chunks for speech: each ends at a sentence boundary (or, for one huge sentence, a clause or space), never mid-word. */
|
|
2
|
+
export const MAX_CHUNK_CHARS = 400;
|
|
3
|
+
|
|
4
|
+
const SENTENCE = /[^.!?]+(?:[.!?]+["')\]]*|$)\s*/g;
|
|
5
|
+
|
|
6
|
+
function splitLong(sentence: string, max: number): string[] {
|
|
7
|
+
const out: string[] = [];
|
|
8
|
+
let rest = sentence.trim();
|
|
9
|
+
while (rest.length > max) {
|
|
10
|
+
const window = rest.slice(0, max + 1);
|
|
11
|
+
let cut = Math.max(window.lastIndexOf(', '), window.lastIndexOf('; '), window.lastIndexOf(': '));
|
|
12
|
+
if (cut < max / 2) cut = window.lastIndexOf(' ');
|
|
13
|
+
if (cut <= 0) cut = max;
|
|
14
|
+
else if (rest[cut] === ',' || rest[cut] === ';' || rest[cut] === ':') cut += 1;
|
|
15
|
+
out.push(rest.slice(0, cut).trim());
|
|
16
|
+
rest = rest.slice(cut).trim();
|
|
17
|
+
}
|
|
18
|
+
if (rest) out.push(rest);
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function chunkForSpeech(text: string, max: number = MAX_CHUNK_CHARS): string[] {
|
|
23
|
+
const clean = text.trim();
|
|
24
|
+
if (clean.length <= max) return clean ? [clean] : [];
|
|
25
|
+
const pieces = (clean.match(SENTENCE) ?? [clean]).map((s) => s.trim()).filter(Boolean).flatMap((s) => (s.length > max ? splitLong(s, max) : [s]));
|
|
26
|
+
const chunks: string[] = [];
|
|
27
|
+
let cur = '';
|
|
28
|
+
for (const p of pieces) {
|
|
29
|
+
if (cur && cur.length + 1 + p.length > max) { chunks.push(cur); cur = p; } else cur = cur ? `${cur} ${p}` : p;
|
|
30
|
+
}
|
|
31
|
+
if (cur) chunks.push(cur);
|
|
32
|
+
return chunks;
|
|
33
|
+
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/** Speak a line and keep the recording, for an assistant turn and a relay message alike. Never throws: the reason is kept instead. */
|
|
2
2
|
import type { ConverseDeps, ConverseSide } from './types';
|
|
3
|
+
import { chunkForSpeech } from './speak-chunks';
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* `text` is kept and shown; `spoken`, when given, is what the voice says instead (a shorter version of it).
|
|
7
|
+
* A long reply is split at sentence boundaries and the chunks are synthesised TOGETHER, so the first sound waits for the slowest
|
|
8
|
+
* chunk and not their sum; the pieces are stitched into one recording in reading order. One chunk failing fails the whole
|
|
9
|
+
* reply (a half-spoken answer is worse than the text alone).
|
|
10
|
+
*/
|
|
5
11
|
export async function speakSide(deps: Pick<ConverseDeps, 'synthesize' | 'audio'>, noteId: string, text: string, spoken?: string): Promise<ConverseSide> {
|
|
6
12
|
const side: ConverseSide = { text };
|
|
7
13
|
if (!deps.synthesize || !deps.audio) {
|
|
@@ -9,9 +15,16 @@ export async function speakSide(deps: Pick<ConverseDeps, 'synthesize' | 'audio'>
|
|
|
9
15
|
return side;
|
|
10
16
|
}
|
|
11
17
|
try {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
const synthesize = deps.synthesize;
|
|
19
|
+
const parts = await Promise.all(chunkForSpeech(spoken || text).map((chunk) => synthesize({ text: chunk })));
|
|
20
|
+
if (!parts.length) throw new Error('nothing to say');
|
|
21
|
+
const mimeType = parts[0].mimeType;
|
|
22
|
+
const total = parts.reduce((n, p) => n + p.audio.byteLength, 0);
|
|
23
|
+
const audio = new Uint8Array(total);
|
|
24
|
+
let at = 0;
|
|
25
|
+
for (const p of parts) { audio.set(p.audio, at); at += p.audio.byteLength; }
|
|
26
|
+
side.audio_ref = await deps.audio.put({ noteId, audio, mimeType });
|
|
27
|
+
side.audio_mime = mimeType;
|
|
15
28
|
} catch (error) {
|
|
16
29
|
side.audio_reason = error instanceof Error ? error.message : String(error);
|
|
17
30
|
}
|
|
@@ -214,6 +214,8 @@ export interface ConverseDeps {
|
|
|
214
214
|
/** After End has saved: files the conversation like a voice note (under a project, asks as to-dos). Default: none. See ./handoff. */
|
|
215
215
|
handoff?: (input: ConverseHandoffInput) => Promise<void | { project?: string | null }>;
|
|
216
216
|
store?: ConversationStore;
|
|
217
|
+
/** Running QuinnAI orgs that need him, as needs-you items (best-effort; absent or failing means none). */
|
|
218
|
+
orgs?: () => Promise<import('../attention/orgs').OrgItem[]>;
|
|
217
219
|
now?: () => number;
|
|
218
220
|
newId?: () => string;
|
|
219
221
|
/** How many earlier lines the brain sees. Default 24. */
|
|
@@ -20,13 +20,28 @@ export function createUtteranceDetector(config: Partial<MeetingConfig> = {}): Ut
|
|
|
20
20
|
let loudSince: number | null = null;
|
|
21
21
|
let startedAt: number | null = null;
|
|
22
22
|
let lastVoiceAt = 0;
|
|
23
|
+
/** The background level (road, wind, music): follows quiet down fast and noise up slowly, so the thresholds ride above it. */
|
|
24
|
+
let floor: number | null = null;
|
|
23
25
|
|
|
24
26
|
const reset = () => { loudSince = null; startedAt = null; lastVoiceAt = 0; };
|
|
27
|
+
const track = (level: number, speaking: boolean) => {
|
|
28
|
+
if (floor === null) { floor = Math.min(level, c.noiseFloorMax); return; }
|
|
29
|
+
const up = speaking ? 0.002 : 0.03;
|
|
30
|
+
floor = level < floor ? floor + (level - floor) * 0.3 : floor + (level - floor) * up;
|
|
31
|
+
floor = Math.min(Math.max(floor, 0.0005), c.noiseFloorMax);
|
|
32
|
+
};
|
|
25
33
|
|
|
26
34
|
return {
|
|
27
35
|
reset,
|
|
28
36
|
feed(level, now) {
|
|
29
|
-
|
|
37
|
+
// Adaptive: a voice must stand clear of the background to start, and only has to stay a little above it to continue.
|
|
38
|
+
if (floor === null) track(level, false); // the first sample calibrates the background
|
|
39
|
+
const f = floor ?? 0;
|
|
40
|
+
const startAt = Math.max(c.speechLevel, f * c.startOverNoise);
|
|
41
|
+
const stayAt = Math.max(c.speechLevel * 0.6, f * c.stayOverNoise);
|
|
42
|
+
const speaking = startedAt !== null;
|
|
43
|
+
const loud = level >= (speaking ? stayAt : startAt);
|
|
44
|
+
if (!loud || speaking) track(level, speaking);
|
|
30
45
|
if (startedAt === null) {
|
|
31
46
|
if (!loud) { loudSince = null; return null; }
|
|
32
47
|
loudSince ??= now;
|
|
@@ -65,6 +65,8 @@ export interface NotifyDeps {
|
|
|
65
65
|
sender?: PushSender;
|
|
66
66
|
now?: () => number;
|
|
67
67
|
newId?: () => string;
|
|
68
|
+
/** Running QuinnAI orgs that need him, as needs-you items. Optional and best-effort: absent or failing means none. */
|
|
69
|
+
orgs?: () => Promise<import('../attention/orgs').OrgItem[]>;
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
export class NotifyError extends Error {
|
|
@@ -56,7 +56,7 @@ function Root({ config, device, registry }: { config: FoundryAppConfig; device:
|
|
|
56
56
|
);
|
|
57
57
|
const { banners, services } = useMemo(() => {
|
|
58
58
|
const b = createBanners();
|
|
59
|
-
return { banners: b, services: createFoundryServices({ config, device, banners: b, strings, fakeConverse: launch.fakeConverse, fakeConverseSound: launch.fakeConverseSound, fakeBriefing: launch.fakeBriefing ? { corpus: fakeCorpus as FakeNativeCorpusApi, script: launch.fakeReply } : null }) };
|
|
59
|
+
return { banners: b, services: createFoundryServices({ config, device, banners: b, strings, fakeConverse: launch.fakeConverse, fakeConverseSound: launch.fakeConverseSound, voiceMock: launch.voiceMock, fakeBriefing: launch.fakeBriefing ? { corpus: fakeCorpus as FakeNativeCorpusApi, script: launch.fakeReply } : null }) };
|
|
60
60
|
}, [config, device, strings, launch, fakeCorpus]);
|
|
61
61
|
// The engine is the device's; a haptic that throws (no taptic hardware, simulator) never breaks a screen.
|
|
62
62
|
// Every call is logged to the diagnostics (`haptic`, then `haptic.result`) so a device run proves the engine was invoked.
|
|
@@ -150,7 +150,7 @@ function Root({ config, device, registry }: { config: FoundryAppConfig; device:
|
|
|
150
150
|
const recordRef = useRef<ReactNode>(record);
|
|
151
151
|
recordRef.current = record;
|
|
152
152
|
const tabs = useMemo(
|
|
153
|
-
() => buildFoundryTabs({ config: appConfig, corpus: data.corpus, notes: data.notes, record: () => recordRef.current, member: data.member, itemsChanged: services.briefing?.itemsChanged, briefing: services.briefing ? { controller: services.briefing.controller, reply: services.briefing.reply } : null, strings, converse: services.converse?.controller ?? null, converseSpeed: services.converse?.speed ?? null, notify: services.notify, openUrl: data.openUrl ?? ((url) => Linking.openURL(url)) }, registry),
|
|
153
|
+
() => buildFoundryTabs({ config: appConfig, corpus: data.corpus, notes: data.notes, record: () => recordRef.current, member: data.member, itemsChanged: services.briefing?.itemsChanged, briefing: services.briefing ? { controller: services.briefing.controller, reply: services.briefing.reply } : null, strings, converse: services.converse?.controller ?? null, converseSpeed: services.converse?.speed ?? null, converseDrive: services.converse?.drive ?? null, startInDrive: launch.drive, notify: services.notify, openUrl: data.openUrl ?? ((url) => Linking.openURL(url)) }, registry),
|
|
154
154
|
[appConfig, data, registry],
|
|
155
155
|
);
|
|
156
156
|
|
|
@@ -170,6 +170,41 @@ function Root({ config, device, registry }: { config: FoundryAppConfig; device:
|
|
|
170
170
|
// `start` is only read the first time the navigator is built.
|
|
171
171
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
172
172
|
}, [tabs, saved, schema]);
|
|
173
|
+
// Device-test hook: `-tgVoiceAuto 1` turns the Talk mic on once the shell is up, so an audio run needs no tap.
|
|
174
|
+
const voiceStarted = useRef(false);
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
if (!launch.voiceAuto || !nav || auth !== 'signedIn' || voiceStarted.current) return;
|
|
177
|
+
voiceStarted.current = true;
|
|
178
|
+
services.diag.log('voice.auto', { phase: services.converse?.controller.getState().phase ?? null });
|
|
179
|
+
services.converse?.controller.mic(true);
|
|
180
|
+
}, [launch, nav, auth, services]);
|
|
181
|
+
// Device-test hook: `-tgDevLogin 1` signs in as the local dev account on a local stack (never against *.startsimpli.com).
|
|
182
|
+
const devLoginTried = useRef(false);
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
if (!launch.devLogin || auth !== 'signedOut' || devLoginTried.current) return;
|
|
185
|
+
devLoginTried.current = true;
|
|
186
|
+
const host = (() => { try { return new URL(config.tenant.centralUrl).hostname; } catch { return ''; } })();
|
|
187
|
+
if (!host || /(^|\.)startsimpli\.com$/i.test(host)) { services.diag.log('devlogin.refused', { host }); return; }
|
|
188
|
+
services.diag.log('devlogin', { host });
|
|
189
|
+
void Promise.resolve(services.session.signIn('dev@local.test', 'localdev123')).catch((e: unknown) => services.diag.log('devlogin.failed', { error: String(e) }));
|
|
190
|
+
}, [launch, auth, services, config]);
|
|
191
|
+
// Device-test hook: `-tgAudioProbe MS` writes the AVAudioSession readback (category, mode, options, route, other audio, Now Playing) to the diagnostics log.
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
const session = device.recording?.session;
|
|
194
|
+
if (!launch.audioProbeMs || !session || auth !== 'signedIn') return undefined;
|
|
195
|
+
const tick = () => { void session.info().then((i) => services.diag.log('audio.info', { ...i }), (e: unknown) => services.diag.log('audio.info', { error: String(e) })); };
|
|
196
|
+
tick();
|
|
197
|
+
const t = setInterval(tick, launch.audioProbeMs);
|
|
198
|
+
return () => clearInterval(t);
|
|
199
|
+
}, [launch, device, auth, services]);
|
|
200
|
+
// Device-test hook: `-tgShotEvery MS` writes a JPEG of the window to Documents/shots, so a wireless run still has screenshots.
|
|
201
|
+
useEffect(() => {
|
|
202
|
+
const snap = device.recording?.session.snapshot;
|
|
203
|
+
if (!launch.shotEveryMs || !snap || auth !== 'signedIn') return undefined;
|
|
204
|
+
const shoot = () => { void snap(device.documentUri(`shots/${Date.now()}.jpg`)).catch(() => false); };
|
|
205
|
+
const t = setInterval(shoot, launch.shotEveryMs);
|
|
206
|
+
return () => clearInterval(t);
|
|
207
|
+
}, [launch, device, auth]);
|
|
173
208
|
useEffect(() => {
|
|
174
209
|
if (!nav) return undefined;
|
|
175
210
|
services.bindOpen((tab, id) => nav.open(tab, id ? { id } : null));
|
|
@@ -90,3 +90,29 @@ describe('briefing services', () => {
|
|
|
90
90
|
expect(notifier.schedule).not.toHaveBeenCalled();
|
|
91
91
|
});
|
|
92
92
|
});
|
|
93
|
+
|
|
94
|
+
describe('lock-screen Now Playing for the briefing', () => {
|
|
95
|
+
const nowPlaying = () => {
|
|
96
|
+
const cbs = new Set<(c: 'play' | 'pause' | 'stop') => void>();
|
|
97
|
+
return { set: vi.fn(), clear: vi.fn(), onCommand: (cb: (c: 'play' | 'pause' | 'stop') => void) => { cbs.add(cb); return () => { cbs.delete(cb); }; }, fire: (c: 'play' | 'pause' | 'stop') => cbs.forEach((cb) => cb(c)) };
|
|
98
|
+
};
|
|
99
|
+
const dev = (np: ReturnType<typeof nowPlaying>) => {
|
|
100
|
+
const base = device() as any;
|
|
101
|
+
return { ...base, briefing: { ...base.briefing, nowPlaying: np } } as never;
|
|
102
|
+
};
|
|
103
|
+
it('test_briefing_playback_registers_now_playing_and_the_stop_command_ends_it', async () => {
|
|
104
|
+
const np = nowPlaying();
|
|
105
|
+
const { services } = make({ briefing: true }, dev(np));
|
|
106
|
+
await services.briefing!.player.play({ uri: 'fixture://briefing' });
|
|
107
|
+
expect(np.set).toHaveBeenCalled();
|
|
108
|
+
expect(np.set.mock.calls.at(-1)![0]).toMatchObject({ rate: 1, durationMs: 1000 });
|
|
109
|
+
np.fire('stop');
|
|
110
|
+
await new Promise((r) => setTimeout(r, 0)); // stop() releases the driver asynchronously
|
|
111
|
+
expect(services.briefing!.player.getState().phase).toBe('idle');
|
|
112
|
+
expect(np.clear).toHaveBeenCalled();
|
|
113
|
+
});
|
|
114
|
+
it('test_without_a_now_playing_binding_nothing_is_registered', async () => {
|
|
115
|
+
const { services } = make({ briefing: true });
|
|
116
|
+
await expect(services.briefing!.player.play({ uri: 'fixture://briefing' })).resolves.toBeUndefined();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -61,6 +61,61 @@ describe('the device haptics engine reaches the screens', () => {
|
|
|
61
61
|
expect(engine).toHaveBeenCalledTimes(6);
|
|
62
62
|
}, 12000);
|
|
63
63
|
|
|
64
|
+
it('-tgVoiceAuto 1 turns the Talk mic on once, with no tap, and logs it', async () => {
|
|
65
|
+
launchArgs.tgFakeTabs = '1'; launchArgs.tgVoiceAuto = '1';
|
|
66
|
+
files.clear();
|
|
67
|
+
render(<FoundryApp config={config} device={device()} />);
|
|
68
|
+
await tick();
|
|
69
|
+
delete launchArgs.tgVoiceAuto;
|
|
70
|
+
const log = JSON.parse(files.get('file:///docs/diagnostics.json') ?? '[]') as Array<Record<string, unknown>>;
|
|
71
|
+
expect(log.filter((e) => e.event === 'voice.auto')).toHaveLength(1);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('-tgAudioProbe logs the session readback into the diagnostics, repeatedly', async () => {
|
|
75
|
+
launchArgs.tgFakeTabs = '1'; launchArgs.tgAudioProbe = '250';
|
|
76
|
+
files.clear();
|
|
77
|
+
const d = device();
|
|
78
|
+
const info = vi.fn(async () => ({ category: 'playAndRecord', mode: 'default', options: ['mixWithOthers'], sampleRate: 48000, inputs: [], otherAudioPlaying: false }));
|
|
79
|
+
// fake mode is signed in; the probe reads the recording binding's inspector
|
|
80
|
+
d.recording = { session: { info, onInterruption: () => () => {}, onRouteChange: () => () => {} } } as never;
|
|
81
|
+
const r = render(<FoundryApp config={config} device={d} />);
|
|
82
|
+
await act(async () => { await new Promise((res) => setTimeout(res, 700)); });
|
|
83
|
+
delete launchArgs.tgAudioProbe;
|
|
84
|
+
act(() => { r.unmount(); });
|
|
85
|
+
const log = JSON.parse(files.get('file:///docs/diagnostics.json') ?? '[]') as Array<Record<string, unknown>>;
|
|
86
|
+
const rows = log.filter((e) => e.event === 'audio.info');
|
|
87
|
+
expect(rows.length).toBeGreaterThanOrEqual(2);
|
|
88
|
+
expect(rows[0]).toMatchObject({ category: 'playAndRecord', options: ['mixWithOthers'], otherAudioPlaying: false });
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('-tgShotEvery asks the native session for a window snapshot under Documents/shots', async () => {
|
|
92
|
+
launchArgs.tgFakeTabs = '1'; launchArgs.tgShotEvery = '1000';
|
|
93
|
+
const d = device();
|
|
94
|
+
const snapshot = vi.fn(async () => true);
|
|
95
|
+
d.recording = { session: { info: async () => ({}), onInterruption: () => () => {}, onRouteChange: () => () => {}, snapshot } } as never;
|
|
96
|
+
const r = render(<FoundryApp config={config} device={d} />);
|
|
97
|
+
await act(async () => { await new Promise((res) => setTimeout(res, 1300)); });
|
|
98
|
+
delete launchArgs.tgShotEvery;
|
|
99
|
+
act(() => { r.unmount(); });
|
|
100
|
+
expect(snapshot).toHaveBeenCalledTimes(1);
|
|
101
|
+
expect((snapshot.mock.calls[0] as unknown as string[])[0]).toMatch(/^file:\/\/\/docs\/shots\/\d+\.jpg$/);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('-tgDevLogin refuses to sign in against a startsimpli.com server and says so in the diagnostics', async () => {
|
|
105
|
+
delete launchArgs.tgFakeTabs; launchArgs.tgDevLogin = '1';
|
|
106
|
+
files.clear();
|
|
107
|
+
const fetchSpy = vi.fn(async () => new Response('{}', { status: 400 }));
|
|
108
|
+
vi.stubGlobal('fetch', fetchSpy);
|
|
109
|
+
const r = render(<FoundryApp config={config} device={device()} />);
|
|
110
|
+
await tick(); await tick();
|
|
111
|
+
delete launchArgs.tgDevLogin;
|
|
112
|
+
act(() => { r.unmount(); });
|
|
113
|
+
vi.unstubAllGlobals();
|
|
114
|
+
const log = JSON.parse(files.get('file:///docs/diagnostics.json') ?? '[]') as Array<Record<string, unknown>>;
|
|
115
|
+
expect(log.find((e) => e.event === 'devlogin.refused')).toMatchObject({ host: 'api.startsimpli.com' });
|
|
116
|
+
expect(fetchSpy).not.toHaveBeenCalled();
|
|
117
|
+
});
|
|
118
|
+
|
|
64
119
|
it('a failing engine is logged as a failed result', async () => {
|
|
65
120
|
launchArgs.tgFakeTabs = '1';
|
|
66
121
|
files.clear();
|
|
@@ -7,7 +7,10 @@ const args = (o: Record<string, string>) => (k: string) => o[k];
|
|
|
7
7
|
|
|
8
8
|
describe('readLaunch', () => {
|
|
9
9
|
it('a plain launch is real mode with nothing to open', () => {
|
|
10
|
-
expect(readLaunch(args({}), config)).toEqual({ fake: false, scenario: 'normal', target: null, autostop: null, scheme: null, hapticProbe: false, fakeBriefing: false, fakeConverse: false, fakeConverseSound: false, fakeReply: [] });
|
|
10
|
+
expect(readLaunch(args({}), config)).toEqual({ fake: false, scenario: 'normal', target: null, autostop: null, scheme: null, hapticProbe: false, voiceAuto: false, voiceMock: null, devLogin: false, audioProbeMs: null, shotEveryMs: null, fakeBriefing: false, fakeConverse: false, fakeConverseSound: false, drive: false, fakeReply: [] });
|
|
11
|
+
});
|
|
12
|
+
it('-tgDrive 1 opens Talk in drive mode', () => {
|
|
13
|
+
expect(readLaunch(args({ tgDrive: '1' }), config).drive).toBe(true);
|
|
11
14
|
});
|
|
12
15
|
it('-tgFakeTabs with -tgTab and -tgDetail', () => {
|
|
13
16
|
expect(readLaunch(args({ tgFakeTabs: '1', tgTab: 'tracker', tgDetail: 'c1' }), config)).toMatchObject({ fake: true, target: { tab: 'tracker', id: 'c1' } });
|
|
@@ -22,6 +25,25 @@ describe('readLaunch', () => {
|
|
|
22
25
|
expect(readLaunch(args({ tgFakeBriefing: '1' }), config).fakeBriefing).toBe(true);
|
|
23
26
|
expect(readLaunch(args({ tgFakeReply: 'move this one to later | undo' }), config).fakeReply).toEqual(['move this one to later', 'undo']);
|
|
24
27
|
});
|
|
28
|
+
it('-tgVoiceAuto 1 asks for the voice session to start by itself', () => {
|
|
29
|
+
expect(readLaunch(args({ tgVoiceAuto: '1' }), config).voiceAuto).toBe(true);
|
|
30
|
+
expect(readLaunch(args({ tgVoiceAuto: '0' }), config).voiceAuto).toBe(false);
|
|
31
|
+
expect(readLaunch(args({ tgVoiceMock: 'barge-in' }), config).voiceMock).toBe('barge-in');
|
|
32
|
+
});
|
|
33
|
+
it('-tgAudioProbe MS polls the session readback, no faster than every 250 ms', () => {
|
|
34
|
+
expect(readLaunch(args({ tgAudioProbe: '1000' }), config).audioProbeMs).toBe(1000);
|
|
35
|
+
expect(readLaunch(args({ tgAudioProbe: '10' }), config).audioProbeMs).toBe(250);
|
|
36
|
+
expect(readLaunch(args({ tgAudioProbe: 'x' }), config).audioProbeMs).toBeNull();
|
|
37
|
+
});
|
|
38
|
+
it('-tgShotEvery MS writes window snapshots, no faster than every second', () => {
|
|
39
|
+
expect(readLaunch(args({ tgShotEvery: '3000' }), config).shotEveryMs).toBe(3000);
|
|
40
|
+
expect(readLaunch(args({ tgShotEvery: '5' }), config).shotEveryMs).toBe(1000);
|
|
41
|
+
expect(readLaunch(args({}), config).shotEveryMs).toBeNull();
|
|
42
|
+
});
|
|
43
|
+
it('-tgDevLogin 1 asks for the local dev sign-in', () => {
|
|
44
|
+
expect(readLaunch(args({ tgDevLogin: '1' }), config).devLogin).toBe(true);
|
|
45
|
+
expect(readLaunch(args({}), config).devLogin).toBe(false);
|
|
46
|
+
});
|
|
25
47
|
it('-tgFakeState and -tgAutostop', () => {
|
|
26
48
|
expect(readLaunch(args({ tgFakeTabs: '1', tgFakeState: 'empty', tgAutostop: '30' }), config)).toMatchObject({ scenario: 'empty', autostop: 30 });
|
|
27
49
|
expect(readLaunch(args({ tgAutostop: 'x' }), config).autostop).toBeNull();
|
|
@@ -3,6 +3,7 @@ import { createPermissionFlow } from '../recording/permissions';
|
|
|
3
3
|
import { createRecorderAudio } from '../recording/recorderAudio';
|
|
4
4
|
import type { createSession } from '../recording/session';
|
|
5
5
|
import { createAudioPlayer } from '../briefing/audioPlayer';
|
|
6
|
+
import { createNowPlaying } from '../voice-session/nowPlaying';
|
|
6
7
|
import { createBriefingApi } from '../briefing/api';
|
|
7
8
|
import { createBriefingController } from '../briefing/controller';
|
|
8
9
|
import { createFakeBriefingApi } from '../briefing/fake';
|
|
@@ -45,6 +46,14 @@ export function createBriefing(deps: {
|
|
|
45
46
|
if (!inspector) throw new Error('features.briefing needs an audio-session inspector (device.briefing.session or device.recording.session)');
|
|
46
47
|
const makePlayer = () => createAudioPlayer({ driver: dev.driver, session: inspector, diag, poll: tick, sleep: wait });
|
|
47
48
|
const player = makePlayer();
|
|
49
|
+
// Lock screen: only briefing playback (a non-mixing profile) may own Now Playing.
|
|
50
|
+
if (dev.nowPlaying) {
|
|
51
|
+
createNowPlaying({
|
|
52
|
+
native: dev.nowPlaying, title: () => "What's on the plate",
|
|
53
|
+
player: { subscribe: (cb) => player.subscribe(cb), pause: () => player.pause(), resume: () => player.resume(), stop: () => { void player.stop(); } },
|
|
54
|
+
mixing: () => device.voiceSession?.profile?.mixWithOthers === true,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
48
57
|
const api = fake
|
|
49
58
|
? createFakeBriefingApi(dev.fixture)
|
|
50
59
|
: createBriefingApi({ tandemUrl: config.tenant.url, authorizedFetch: session.authorizedFetch, bearer: session.bearer });
|