@ciridae/voice-conversations-react 0.0.0-stage → 0.1.0-nightly.0.bootstrap
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/README.md +30 -2
- package/components/BrowserTalkButton.tsx +96 -0
- package/components/CallBanner.tsx +43 -0
- package/components/CallCaptions.tsx +38 -0
- package/components/CallEntry.tsx +89 -0
- package/components/CallTranscript.tsx +58 -0
- package/components/RecentCallEntries.tsx +211 -0
- package/components/describeBrowserTalkError.ts +39 -0
- package/components/formatCallClock.ts +9 -0
- package/components/useEndPresentCall.ts +45 -0
- package/components/voiceCall.css +225 -0
- package/dist/MalformedVoiceResponseError.d.ts +6 -0
- package/dist/MalformedVoiceResponseError.js +9 -0
- package/dist/NumberToCallQrCode.d.ts +12 -0
- package/dist/NumberToCallQrCode.js +29 -0
- package/dist/PhoneNumberDialog.d.ts +25 -0
- package/dist/PhoneNumberDialog.js +333 -0
- package/dist/PhoneNumbersAdminPanel.d.ts +11 -0
- package/dist/PhoneNumbersAdminPanel.js +85 -0
- package/dist/VoiceApiError.d.ts +18 -0
- package/dist/VoiceApiError.js +19 -0
- package/dist/VoiceRequestTimedOutError.d.ts +6 -0
- package/dist/VoiceRequestTimedOutError.js +9 -0
- package/dist/averageSpeechBinsIntoBands.d.ts +6 -0
- package/dist/averageSpeechBinsIntoBands.js +20 -0
- package/dist/browserApisForBrowserTalk.d.ts +17 -0
- package/dist/browserApisForBrowserTalk.js +42 -0
- package/dist/browserTalkError.d.ts +36 -0
- package/dist/browserTalkError.js +1 -0
- package/dist/chooseCallToShowCaptionsOf.d.ts +22 -0
- package/dist/chooseCallToShowCaptionsOf.js +26 -0
- package/dist/createBrowserTalk.d.ts +56 -0
- package/dist/createBrowserTalk.js +414 -0
- package/dist/createBrowserTalkErrorFollower.d.ts +17 -0
- package/dist/createBrowserTalkErrorFollower.js +76 -0
- package/dist/createCallPresenceWatcher.d.ts +25 -0
- package/dist/createCallPresenceWatcher.js +66 -0
- package/dist/createLiveCallCaptionsPoller.d.ts +24 -0
- package/dist/createLiveCallCaptionsPoller.js +58 -0
- package/dist/createVisibleTabPoller.d.ts +13 -0
- package/dist/createVisibleTabPoller.js +56 -0
- package/dist/deriveCallPresence.d.ts +23 -0
- package/dist/deriveCallPresence.js +58 -0
- package/dist/describePhoneNumberError.d.ts +7 -0
- package/dist/describePhoneNumberError.js +29 -0
- package/dist/entries/index.d.ts +26 -0
- package/dist/entries/index.js +22 -0
- package/dist/followBrowserTalkErrorAgainstPresence.d.ts +23 -0
- package/dist/followBrowserTalkErrorAgainstPresence.js +52 -0
- package/dist/formatPhoneNumberAsTyped.d.ts +31 -0
- package/dist/formatPhoneNumberAsTyped.js +85 -0
- package/dist/generated/index.d.ts +1 -0
- package/dist/generated/index.js +2 -0
- package/dist/generated/types.gen.d.ts +795 -0
- package/dist/generated/types.gen.js +2 -0
- package/dist/getBrowserTalkForThisTab.d.ts +3 -0
- package/dist/getBrowserTalkForThisTab.js +13 -0
- package/dist/getCallPresenceWatcherForThisTab.d.ts +3 -0
- package/dist/getCallPresenceWatcherForThisTab.js +9 -0
- package/dist/mapStartBrowserTalkFailureToBrowserTalkError.d.ts +7 -0
- package/dist/mapStartBrowserTalkFailureToBrowserTalkError.js +60 -0
- package/dist/parseVoiceApiResponses.d.ts +11 -0
- package/dist/parseVoiceApiResponses.js +344 -0
- package/dist/readCallSummaryUntilItHasDuration.d.ts +12 -0
- package/dist/readCallSummaryUntilItHasDuration.js +45 -0
- package/dist/readTheBrowsersTimeZone.d.ts +8 -0
- package/dist/readTheBrowsersTimeZone.js +17 -0
- package/dist/readTimestampMilliseconds.d.ts +8 -0
- package/dist/readTimestampMilliseconds.js +10 -0
- package/dist/requestEndOfCall.d.ts +7 -0
- package/dist/requestEndOfCall.js +11 -0
- package/dist/startBrowserTalkErrorFollowerForThisTab.d.ts +6 -0
- package/dist/startBrowserTalkErrorFollowerForThisTab.js +12 -0
- package/dist/useAdminPhoneNumbers.d.ts +47 -0
- package/dist/useAdminPhoneNumbers.js +76 -0
- package/dist/useBrowserTalk.d.ts +10 -0
- package/dist/useBrowserTalk.js +23 -0
- package/dist/useBrowserTalkErrorWhileItApplies.d.ts +10 -0
- package/dist/useBrowserTalkErrorWhileItApplies.js +13 -0
- package/dist/useCallPresence.d.ts +5 -0
- package/dist/useCallPresence.js +34 -0
- package/dist/useCallSummaries.d.ts +9 -0
- package/dist/useCallSummaries.js +22 -0
- package/dist/useCallSummary.d.ts +15 -0
- package/dist/useCallSummary.js +21 -0
- package/dist/useFinePointerWithHover.d.ts +10 -0
- package/dist/useFinePointerWithHover.js +19 -0
- package/dist/useLiveCallCaptions.d.ts +8 -0
- package/dist/useLiveCallCaptions.js +27 -0
- package/dist/useLiveCallCaptionsOfLatestCall.d.ts +13 -0
- package/dist/useLiveCallCaptionsOfLatestCall.js +23 -0
- package/dist/usePhoneNumber.d.ts +45 -0
- package/dist/usePhoneNumber.js +125 -0
- package/dist/voiceApiModels.d.ts +85 -0
- package/dist/voiceApiModels.js +1 -0
- package/dist/voiceConversationsApi.d.ts +44 -0
- package/dist/voiceConversationsApi.js +227 -0
- package/dist/voiceConversationsSettings.d.ts +20 -0
- package/dist/voiceConversationsSettings.js +26 -0
- package/package.json +41 -4
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useState } from "react";
|
|
3
|
+
import { useAdminPhoneNumbers } from "./useAdminPhoneNumbers.js";
|
|
4
|
+
/**
|
|
5
|
+
* The admin's "Phone numbers" panel: add one person's number by email, or upload a CSV with
|
|
6
|
+
* `email` and `phone_number` columns and see what happened to each row. People must be in the
|
|
7
|
+
* project; a pending invitee's number counts at once. Put it on a page only admins reach: the
|
|
8
|
+
* backend refuses anyone its `require_admin` dependency refuses.
|
|
9
|
+
*/
|
|
10
|
+
export function PhoneNumbersAdminPanel({ className }) {
|
|
11
|
+
const { state, addOne, uploadCsv } = useAdminPhoneNumbers();
|
|
12
|
+
const [member, setMember] = useState("");
|
|
13
|
+
const [typedPhoneNumber, setTypedPhoneNumber] = useState("");
|
|
14
|
+
const [file, setFile] = useState(null);
|
|
15
|
+
const memberId = useId();
|
|
16
|
+
const phoneId = useId();
|
|
17
|
+
const fileId = useId();
|
|
18
|
+
const sending = state.status === "sending";
|
|
19
|
+
async function submitOne(event) {
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
await addOne(member, typedPhoneNumber);
|
|
22
|
+
}
|
|
23
|
+
async function submitFile(event) {
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
if (file !== null)
|
|
26
|
+
await uploadCsv(file);
|
|
27
|
+
}
|
|
28
|
+
return (_jsxs("section", { className: className, style: panelStyle, "aria-label": "Phone numbers", children: [_jsxs("form", { style: rowFormStyle, onSubmit: (event) => void submitOne(event), children: [_jsx("h3", { style: headingStyle, children: "Add one number" }), _jsx("label", { htmlFor: memberId, style: labelStyle, children: "Email" }), _jsx("input", { id: memberId, type: "text", inputMode: "email", autoComplete: "off", value: member, placeholder: "ada@example.com", onChange: (event) => setMember(event.target.value), style: inputStyle }), _jsx("label", { htmlFor: phoneId, style: labelStyle, children: "Phone number" }), _jsx("input", { id: phoneId, type: "tel", value: typedPhoneNumber, placeholder: "(415) 555-0123", onChange: (event) => setTypedPhoneNumber(event.target.value), style: inputStyle }), _jsx("button", { type: "submit", disabled: sending || member.trim() === "" || typedPhoneNumber.trim() === "", style: buttonStyle, children: "Add" })] }), _jsxs("form", { style: rowFormStyle, onSubmit: (event) => void submitFile(event), children: [_jsx("h3", { style: headingStyle, children: "Upload a CSV" }), _jsxs("p", { style: mutedTextStyle, children: ["A header row with an ", _jsx("code", { children: "email" }), " column and a ", _jsx("code", { children: "phone_number" }), " column, up to 1000 rows. Each row is added or refused on its own."] }), _jsx("label", { htmlFor: fileId, style: labelStyle, children: "CSV file" }), _jsx("input", { id: fileId, type: "file", accept: ".csv,text/csv", onChange: (event) => setFile(event.target.files?.[0] ?? null) }), _jsx("button", { type: "submit", disabled: sending || file === null, style: buttonStyle, children: "Upload" })] }), _jsxs("div", { role: "status", style: mutedTextStyle, children: [state.status === "sending" ? "Saving…" : null, state.status === "added"
|
|
29
|
+
? `Saved ${state.added.phone_number_display} for ${state.added.member_email}${state.added.invite_status === "pending" ? " (invite pending; it counts now)" : ""}.`
|
|
30
|
+
: null, state.status === "uploaded"
|
|
31
|
+
? `${state.report.added_count} added, ${state.report.refused_count} refused.`
|
|
32
|
+
: null] }), state.status === "failed" ? (_jsx("p", { role: "alert", style: errorTextStyle, children: state.error })) : null, state.status === "uploaded" ? _jsx(UploadReportTable, { rows: state.report.rows }) : null] }));
|
|
33
|
+
}
|
|
34
|
+
function UploadReportTable({ rows }) {
|
|
35
|
+
return (_jsxs("table", { style: tableStyle, children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { style: cellStyle, children: "Row" }), _jsx("th", { style: cellStyle, children: "Member" }), _jsx("th", { style: cellStyle, children: "Result" })] }) }), _jsx("tbody", { children: rows.map((row) => (_jsxs("tr", { children: [_jsx("td", { style: cellStyle, children: row.row_number }), _jsx("td", { style: cellStyle, children: row.member }), _jsx("td", { style: row.outcome === "added" ? cellStyle : refusedCellStyle, children: row.outcome === "added"
|
|
36
|
+
? `Added ${row.phone_number_display}${row.invite_status === "pending" ? " (invite pending)" : ""}`
|
|
37
|
+
: REFUSAL_TEXT[row.reason] })] }, row.row_number))) })] }));
|
|
38
|
+
}
|
|
39
|
+
const REFUSAL_TEXT = {
|
|
40
|
+
missing_value: "Not added: the email or the number is blank",
|
|
41
|
+
member_not_found: "Not added: nobody in this project has this email",
|
|
42
|
+
invite_expired: "Not added: their invite expired; invite them again",
|
|
43
|
+
phone_number_not_e164: "Not added: not a valid phone number",
|
|
44
|
+
phone_number_held_by_another_member: "Not added: another member has this number",
|
|
45
|
+
};
|
|
46
|
+
const panelStyle = {
|
|
47
|
+
display: "grid",
|
|
48
|
+
gap: 20,
|
|
49
|
+
color: "var(--color-text, #1d1d1f)",
|
|
50
|
+
font: "inherit",
|
|
51
|
+
};
|
|
52
|
+
const rowFormStyle = { display: "grid", gap: 8, maxWidth: 420 };
|
|
53
|
+
const headingStyle = { margin: 0, fontSize: 15, fontWeight: 600 };
|
|
54
|
+
const labelStyle = { fontSize: 13, fontWeight: 500 };
|
|
55
|
+
const mutedTextStyle = {
|
|
56
|
+
margin: 0,
|
|
57
|
+
fontSize: 13,
|
|
58
|
+
color: "var(--color-text-muted, #6e6e73)",
|
|
59
|
+
};
|
|
60
|
+
const errorTextStyle = { ...mutedTextStyle, color: "var(--color-danger, #c0392b)" };
|
|
61
|
+
const inputStyle = {
|
|
62
|
+
padding: "8px 10px",
|
|
63
|
+
border: "1px solid var(--color-border, #dcdce0)",
|
|
64
|
+
borderRadius: "var(--radius-medium, 8px)",
|
|
65
|
+
background: "var(--color-surface, #ffffff)",
|
|
66
|
+
color: "inherit",
|
|
67
|
+
font: "inherit",
|
|
68
|
+
};
|
|
69
|
+
const buttonStyle = {
|
|
70
|
+
justifySelf: "start",
|
|
71
|
+
padding: "8px 14px",
|
|
72
|
+
border: "1px solid transparent",
|
|
73
|
+
borderRadius: "var(--radius-medium, 8px)",
|
|
74
|
+
background: "var(--color-primary, #1d1d1f)",
|
|
75
|
+
color: "var(--color-on-primary, #ffffff)",
|
|
76
|
+
font: "inherit",
|
|
77
|
+
cursor: "pointer",
|
|
78
|
+
};
|
|
79
|
+
const tableStyle = { borderCollapse: "collapse", fontSize: 13 };
|
|
80
|
+
const cellStyle = {
|
|
81
|
+
padding: "6px 10px",
|
|
82
|
+
borderBottom: "1px solid var(--color-border, #dcdce0)",
|
|
83
|
+
textAlign: "left",
|
|
84
|
+
};
|
|
85
|
+
const refusedCellStyle = { ...cellStyle, color: "var(--color-danger, #c0392b)" };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CallId } from "./voiceApiModels.js";
|
|
2
|
+
/**
|
|
3
|
+
* A non-2xx answer from a member route. `source` says who refused: the package, OpenAI passed
|
|
4
|
+
* through by the package, or the host (its auth dependency or a proxy) with a body the package
|
|
5
|
+
* did not write. A `provider` 401 or 403 never means the member is signed out.
|
|
6
|
+
*/
|
|
7
|
+
export declare class VoiceApiError extends Error {
|
|
8
|
+
readonly route: string;
|
|
9
|
+
readonly status: number;
|
|
10
|
+
readonly source: "voice_conversations" | "provider" | "host";
|
|
11
|
+
readonly code: string | null;
|
|
12
|
+
readonly callId: CallId | null;
|
|
13
|
+
/** The package's own sentence for the person, when the package refused; never the host's. */
|
|
14
|
+
readonly packageMessage: string | null;
|
|
15
|
+
constructor(route: string, status: number, source: "voice_conversations" | "provider" | "host", code: string | null, callId: CallId | null,
|
|
16
|
+
/** The package's own sentence for the person, when the package refused; never the host's. */
|
|
17
|
+
packageMessage?: string | null);
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A non-2xx answer from a member route. `source` says who refused: the package, OpenAI passed
|
|
3
|
+
* through by the package, or the host (its auth dependency or a proxy) with a body the package
|
|
4
|
+
* did not write. A `provider` 401 or 403 never means the member is signed out.
|
|
5
|
+
*/
|
|
6
|
+
export class VoiceApiError extends Error {
|
|
7
|
+
constructor(route, status, source, code, callId,
|
|
8
|
+
/** The package's own sentence for the person, when the package refused; never the host's. */
|
|
9
|
+
packageMessage = null) {
|
|
10
|
+
super(`Voice conversations ${route} answered ${status} (${source}${code ? ` ${code}` : ""})`);
|
|
11
|
+
this.route = route;
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.source = source;
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.callId = callId;
|
|
16
|
+
this.packageMessage = packageMessage;
|
|
17
|
+
this.name = "VoiceApiError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** A voice request whose answer did not begin within the bound, its auth headers included; handled as a failed call. */
|
|
2
|
+
export declare class VoiceRequestTimedOutError extends Error {
|
|
3
|
+
readonly route: string;
|
|
4
|
+
readonly timeoutMs: number;
|
|
5
|
+
constructor(route: string, timeoutMs: number);
|
|
6
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** A voice request whose answer did not begin within the bound, its auth headers included; handled as a failed call. */
|
|
2
|
+
export class VoiceRequestTimedOutError extends Error {
|
|
3
|
+
constructor(route, timeoutMs) {
|
|
4
|
+
super(`Voice conversations ${route} did not answer within ${String(timeoutMs)} ms`);
|
|
5
|
+
this.route = route;
|
|
6
|
+
this.timeoutMs = timeoutMs;
|
|
7
|
+
this.name = "VoiceRequestTimedOutError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The analyser's speech bins as `bands` levels from low to high pitch, each 0 to 1. The bins are
|
|
3
|
+
* split as evenly as whole bins allow; when `bands` exceeds the bins, neighbouring bands share a
|
|
4
|
+
* bin, so every level is still a number.
|
|
5
|
+
*/
|
|
6
|
+
export declare function averageSpeechBinsIntoBands(bins: Uint8Array, bands: number): number[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The analyser's speech band: its first 32 bins after bin 0, about 94 Hz each at 48 kHz with
|
|
2
|
+
// fftSize 512. Bin 0 is the hum below speech.
|
|
3
|
+
const SPEECH_BINS = 32;
|
|
4
|
+
const FIRST_SPEECH_BIN = 1;
|
|
5
|
+
const BYTE_MAX = 255;
|
|
6
|
+
/**
|
|
7
|
+
* The analyser's speech bins as `bands` levels from low to high pitch, each 0 to 1. The bins are
|
|
8
|
+
* split as evenly as whole bins allow; when `bands` exceeds the bins, neighbouring bands share a
|
|
9
|
+
* bin, so every level is still a number.
|
|
10
|
+
*/
|
|
11
|
+
export function averageSpeechBinsIntoBands(bins, bands) {
|
|
12
|
+
return Array.from({ length: bands }, (_, band) => {
|
|
13
|
+
const start = Math.floor((band * SPEECH_BINS) / bands);
|
|
14
|
+
const end = Math.max(start + 1, Math.floor(((band + 1) * SPEECH_BINS) / bands));
|
|
15
|
+
let sum = 0;
|
|
16
|
+
for (let bin = start; bin < end; bin++)
|
|
17
|
+
sum += bins[FIRST_SPEECH_BIN + bin] ?? 0;
|
|
18
|
+
return sum / (end - start) / BYTE_MAX;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BrowserReportedTimeZone } from "./voiceApiModels.js";
|
|
2
|
+
/** The browser features a browser talk uses, injected so tests drive a fake peer instead of real WebRTC. */
|
|
3
|
+
export interface BrowserApisForBrowserTalk {
|
|
4
|
+
requestMicrophone: () => Promise<MediaStream>;
|
|
5
|
+
createPeerConnection: () => RTCPeerConnection;
|
|
6
|
+
/** Plays the voice's reply and measures both voices for the level bars. */
|
|
7
|
+
createBrowserTalkAudio: (microphone: MediaStream) => BrowserTalkAudio;
|
|
8
|
+
listenForPageHide: (listener: () => void) => void;
|
|
9
|
+
readTimeZone: () => BrowserReportedTimeZone;
|
|
10
|
+
}
|
|
11
|
+
export interface BrowserTalkAudio {
|
|
12
|
+
playReply: (reply: MediaStream) => void;
|
|
13
|
+
/** Both voices now, as `bands` levels from low to high pitch, 0 to 1. */
|
|
14
|
+
readLevels: (bands: number) => number[];
|
|
15
|
+
close: () => void;
|
|
16
|
+
}
|
|
17
|
+
export declare const realBrowserApisForBrowserTalk: BrowserApisForBrowserTalk;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { averageSpeechBinsIntoBands } from "./averageSpeechBinsIntoBands.js";
|
|
2
|
+
import { readTheBrowsersTimeZone } from "./readTheBrowsersTimeZone.js";
|
|
3
|
+
// About 94 Hz per bin at 48 kHz, so the first 32 bins cover speech.
|
|
4
|
+
const FFT_SIZE = 512;
|
|
5
|
+
export const realBrowserApisForBrowserTalk = {
|
|
6
|
+
requestMicrophone: () => navigator.mediaDevices.getUserMedia({
|
|
7
|
+
audio: { echoCancellation: true, noiseSuppression: true },
|
|
8
|
+
}),
|
|
9
|
+
createPeerConnection: () => new RTCPeerConnection(),
|
|
10
|
+
createBrowserTalkAudio: createRealBrowserTalkAudio,
|
|
11
|
+
listenForPageHide: (listener) => {
|
|
12
|
+
window.addEventListener("pagehide", listener);
|
|
13
|
+
},
|
|
14
|
+
readTimeZone: readTheBrowsersTimeZone,
|
|
15
|
+
};
|
|
16
|
+
function createRealBrowserTalkAudio(microphone) {
|
|
17
|
+
const audio = new Audio();
|
|
18
|
+
audio.autoplay = true;
|
|
19
|
+
// One analyser hears both voices: the microphone now, the reply once its track arrives.
|
|
20
|
+
const context = new AudioContext();
|
|
21
|
+
const meter = context.createAnalyser();
|
|
22
|
+
meter.fftSize = FFT_SIZE;
|
|
23
|
+
const bins = new Uint8Array(meter.frequencyBinCount);
|
|
24
|
+
context.createMediaStreamSource(microphone).connect(meter);
|
|
25
|
+
return {
|
|
26
|
+
playReply: (reply) => {
|
|
27
|
+
audio.srcObject = reply;
|
|
28
|
+
audio.play().catch((error) => {
|
|
29
|
+
console.warn("The browser talk reply could not autoplay; the browser blocked it", error);
|
|
30
|
+
});
|
|
31
|
+
context.createMediaStreamSource(reply).connect(meter);
|
|
32
|
+
},
|
|
33
|
+
readLevels: (bands) => {
|
|
34
|
+
meter.getByteFrequencyData(bins);
|
|
35
|
+
return averageSpeechBinsIntoBands(bins, bands);
|
|
36
|
+
},
|
|
37
|
+
close: () => {
|
|
38
|
+
audio.srcObject = null;
|
|
39
|
+
void context.close();
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CallId } from "./voiceApiModels.js";
|
|
2
|
+
/** Why the last browser talk did not start or ended early. Each cause stays distinct so the UI can say it. */
|
|
3
|
+
export type BrowserTalkError = {
|
|
4
|
+
kind: "microphone_blocked";
|
|
5
|
+
} | {
|
|
6
|
+
kind: "no_microphone";
|
|
7
|
+
} | {
|
|
8
|
+
kind: "microphone_unavailable";
|
|
9
|
+
} | {
|
|
10
|
+
kind: "did_not_connect";
|
|
11
|
+
} | {
|
|
12
|
+
kind: "connection_dropped";
|
|
13
|
+
} | {
|
|
14
|
+
kind: "on_a_phone_call";
|
|
15
|
+
} | {
|
|
16
|
+
kind: "already_on_a_browser_talk";
|
|
17
|
+
callId: CallId | null;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "not_a_current_member";
|
|
20
|
+
} | {
|
|
21
|
+
kind: "voice_not_ready";
|
|
22
|
+
} | {
|
|
23
|
+
kind: "voice_unavailable";
|
|
24
|
+
} | {
|
|
25
|
+
kind: "phone_took_over";
|
|
26
|
+
} | {
|
|
27
|
+
kind: "time_limit_reached";
|
|
28
|
+
} | {
|
|
29
|
+
kind: "stopped_by_content_filter";
|
|
30
|
+
} | {
|
|
31
|
+
kind: "host_refused";
|
|
32
|
+
status: number;
|
|
33
|
+
} | {
|
|
34
|
+
kind: "provider_rejected";
|
|
35
|
+
status: number;
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CallId } from "./voiceApiModels.js";
|
|
2
|
+
/** The call whose captions the hook last showed, and the member who saw it. */
|
|
3
|
+
export interface FollowedCall {
|
|
4
|
+
signedInUserId: string;
|
|
5
|
+
callId: CallId;
|
|
6
|
+
}
|
|
7
|
+
export interface CallToShowCaptionsOf {
|
|
8
|
+
/** The call whose transcript to show, or null for none. */
|
|
9
|
+
callId: CallId | null;
|
|
10
|
+
/** What to remember as followed for the next render. */
|
|
11
|
+
followedCall: FollowedCall | null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Which call's transcript `useLiveCallCaptionsOfLatestCall` shows. A present call with an id is
|
|
15
|
+
* shown and followed. A present call without an id yet (this tab's browser talk while the microphone
|
|
16
|
+
* prompt is up or the connection is being set up) is a new call starting, so the previous call's
|
|
17
|
+
* transcript is dropped rather than shown beside it. With no present call, the last followed call
|
|
18
|
+
* stays shown, for the signed-in member who saw it only.
|
|
19
|
+
*/
|
|
20
|
+
export declare function chooseCallToShowCaptionsOf(presentCall: {
|
|
21
|
+
callId: CallId | null;
|
|
22
|
+
} | null, followedCall: FollowedCall | null, signedInUserId: string): CallToShowCaptionsOf;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which call's transcript `useLiveCallCaptionsOfLatestCall` shows. A present call with an id is
|
|
3
|
+
* shown and followed. A present call without an id yet (this tab's browser talk while the microphone
|
|
4
|
+
* prompt is up or the connection is being set up) is a new call starting, so the previous call's
|
|
5
|
+
* transcript is dropped rather than shown beside it. With no present call, the last followed call
|
|
6
|
+
* stays shown, for the signed-in member who saw it only.
|
|
7
|
+
*/
|
|
8
|
+
export function chooseCallToShowCaptionsOf(presentCall, followedCall, signedInUserId) {
|
|
9
|
+
if (presentCall !== null && presentCall.callId === null)
|
|
10
|
+
return { callId: null, followedCall: null };
|
|
11
|
+
const presentCallId = presentCall?.callId ?? null;
|
|
12
|
+
if (presentCallId !== null) {
|
|
13
|
+
// A call first seen by another member is theirs, even while the tab's shared presence still
|
|
14
|
+
// reports it after this member signed in: its poller and captions are dropped, not carried over.
|
|
15
|
+
if (followedCall?.callId === presentCallId)
|
|
16
|
+
return {
|
|
17
|
+
callId: followedCall.signedInUserId === signedInUserId ? presentCallId : null,
|
|
18
|
+
followedCall,
|
|
19
|
+
};
|
|
20
|
+
return { callId: presentCallId, followedCall: { signedInUserId, callId: presentCallId } };
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
callId: followedCall?.signedInUserId === signedInUserId ? followedCall.callId : null,
|
|
24
|
+
followedCall,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { BrowserApisForBrowserTalk } from "./browserApisForBrowserTalk.js";
|
|
2
|
+
import type { BrowserTalkError } from "./browserTalkError.js";
|
|
3
|
+
import type { CallId, CallCaptionsSoFar, StartBrowserTalkRequest, BrowserTalkStarted } from "./voiceApiModels.js";
|
|
4
|
+
import type { EndCallOutcome } from "./voiceConversationsApi.js";
|
|
5
|
+
/**
|
|
6
|
+
* The tab's one browser talk: a WebRTC peer to GPT-Live, created through the host backend's SDP proxy so
|
|
7
|
+
* no key reaches the browser. The data channel is receive-only
|
|
8
|
+
* (the server allows only lifecycle and transcript events). Every way a browser talk can end lets go of
|
|
9
|
+
* the microphone and tells the server: End, Cancel while connecting, a dropped peer and the tab
|
|
10
|
+
* closing. After End the microphone stays until `session.closed`, capped at 15 s.
|
|
11
|
+
*/
|
|
12
|
+
interface BrowserTalkTiming {
|
|
13
|
+
callId: CallId;
|
|
14
|
+
startedAt: string;
|
|
15
|
+
endsAt: string;
|
|
16
|
+
/** Server clock minus this browser's clock, from the start response's `server_now`. */
|
|
17
|
+
serverOffsetMs: number;
|
|
18
|
+
}
|
|
19
|
+
export type BrowserTalkState = {
|
|
20
|
+
status: "idle";
|
|
21
|
+
error: BrowserTalkError | null;
|
|
22
|
+
} | {
|
|
23
|
+
status: "requesting_microphone";
|
|
24
|
+
} | {
|
|
25
|
+
status: "connecting";
|
|
26
|
+
callId: CallId | null;
|
|
27
|
+
} | (BrowserTalkTiming & {
|
|
28
|
+
status: "live";
|
|
29
|
+
muted: boolean;
|
|
30
|
+
}) | (BrowserTalkTiming & {
|
|
31
|
+
status: "ending";
|
|
32
|
+
});
|
|
33
|
+
/** The routes a browser talk calls, injected so tests answer with a fake backend. */
|
|
34
|
+
export interface BrowserTalkBackend {
|
|
35
|
+
postStartBrowserTalk: (request: StartBrowserTalkRequest) => Promise<BrowserTalkStarted>;
|
|
36
|
+
postEndCall: (callId: CallId, delivery: "keepalive" | "normal") => Promise<EndCallOutcome>;
|
|
37
|
+
getCallCaptions: (callId: CallId) => Promise<CallCaptionsSoFar>;
|
|
38
|
+
}
|
|
39
|
+
export interface BrowserTalk {
|
|
40
|
+
subscribe: (listener: () => void) => () => void;
|
|
41
|
+
getState: () => BrowserTalkState;
|
|
42
|
+
start: () => Promise<void>;
|
|
43
|
+
cancel: () => void;
|
|
44
|
+
end: () => Promise<void>;
|
|
45
|
+
toggleMute: () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Clear why the last browser talk did not start or ended early, once it no longer applies: the member
|
|
48
|
+
* sent a message, or the call that caused it ended (`useBrowserTalkErrorWhileItApplies`). Does nothing
|
|
49
|
+
* unless the browser talk is idle with an error. A new browser talk clears it by itself.
|
|
50
|
+
*/
|
|
51
|
+
dismissError: () => void;
|
|
52
|
+
readVoiceLevels: (bands: number) => number[];
|
|
53
|
+
browserTalkStartedInThisTab: (callId: CallId) => boolean;
|
|
54
|
+
}
|
|
55
|
+
export declare function createBrowserTalk(browser: BrowserApisForBrowserTalk, backend: BrowserTalkBackend): BrowserTalk;
|
|
56
|
+
export {};
|