@kortix/ui 0.14.17 → 0.14.19
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 +2 -2
- package/dist/_vendor/kortix-shared.js +38 -2
- package/dist/_vendor/shared/channel-descriptors.d.ts +20 -1
- package/dist/_vendor/shared/channel-message.d.ts +1 -1
- package/dist/_vendor/shared/my-kortix-agent.d.ts +1 -1
- package/dist/_vendor/shared/space-slug.d.ts +3 -4
- package/dist/_vendor/shared/utils/ambiguous-write.d.ts +3 -3
- package/dist/customize/agents/agent-instructions.d.ts +8 -0
- package/dist/customize/agents/agent-instructions.js +38 -12
- package/dist/customize/agents/agent-overview.d.ts +6 -3
- package/dist/customize/agents/agent-overview.js +8 -2
- package/dist/customize/agents/agent-page-chrome.d.ts +45 -27
- package/dist/customize/agents/agent-page-chrome.js +60 -37
- package/dist/customize/agents/agent-page.js +88 -99
- package/dist/customize/agents/agent-tabs.d.ts +15 -14
- package/dist/customize/agents/agent-tabs.js +19 -16
- package/dist/customize/agents/agents-page.js +8 -6
- package/dist/customize/connectors/detail/account-info.js +1 -1
- package/dist/customize/project-settings/project-admin-sections.d.ts +6 -2
- package/dist/customize/project-settings/project-admin-sections.js +5 -3
- package/dist/customize/project-settings/project-settings-sections.js +1 -1
- package/dist/customize/sections/component/channel-access-panel.js +16 -0
- package/dist/customize/sections/component/channel-mocks.d.ts +5 -0
- package/dist/customize/sections/component/channel-mocks.js +14 -2
- package/dist/customize/sections/component/discord-channel-row.d.ts +6 -0
- package/dist/customize/sections/component/discord-channel-row.js +48 -0
- package/dist/customize/sections/gateway-access-tab.js +1 -1
- package/dist/customize/sections/view/channels-view.js +18 -1
- package/dist/customize/sections/view/git-view.js +2 -2
- package/dist/customize/sections/view/secret-delivery.js +1 -1
- package/dist/customize/sections/view/secrets-view.js +1 -1
- package/dist/customize/settings/rail.js +2 -2
- package/dist/customize/settings/tabs/experimental-tab.d.ts +2 -2
- package/dist/customize/settings/tabs/experimental-tab.js +2 -2
- package/dist/customize/settings/tabs/general-tab.js +5 -4
- package/dist/customize/shared/capability-library.js +19 -22
- package/dist/customize/shared/customize-tab-bar.d.ts +1 -2
- package/dist/customize/shared/customize-tab-bar.js +10 -11
- package/dist/files/project/components/drive-create-dialog.js +3 -3
- package/dist/i18n/en.d.ts +51 -4
- package/dist/i18n/en.js +66 -19
- package/dist/i18n/ui-catalog/remaining-ui-translation-keys.generated.js +1 -1
- package/dist/internal/branding/branding-provider.d.ts +15 -4
- package/dist/internal/branding/branding-provider.js +12 -7
- package/dist/internal/connector-logo/connector-logo.js +2 -0
- package/dist/internal/connector-logo/connector-mark-files.js +1 -0
- package/dist/internal/hooks/channels/use-channels-installations.d.ts +7 -2
- package/dist/internal/hooks/channels/use-channels-installations.js +31 -1
- package/dist/internal/hooks/projects/use-new-project-session.d.ts +6 -14
- package/dist/internal/hooks/projects/use-new-project-session.js +12 -97
- package/dist/internal/hooks/use-notification-center.d.ts +11 -8
- package/dist/internal/hooks/use-notification-center.js +22 -10
- package/dist/internal/icons/discord.d.ts +9 -0
- package/dist/internal/icons/discord.js +9 -0
- package/dist/internal/layout/connect-mcp-modal.js +1 -1
- package/dist/internal/lib/browser-noise/rules/expected-states.js +1 -1
- package/dist/internal/lib/error-handler.js +1 -1
- package/dist/internal/lib/use-project-feature-flags.js +5 -3
- package/dist/markdown/markdown-frontmatter.d.ts +0 -3
- package/dist/markdown/markdown-frontmatter.js +45 -5
- package/dist/session/actions/project-session-list-helpers.d.ts +4 -14
- package/dist/session/actions/project-session-list-helpers.js +5 -16
- package/dist/session/actions/session-label.d.ts +5 -9
- package/dist/session/actions/session-label.js +6 -10
- package/dist/session/participants/session-participants.d.ts +7 -5
- package/dist/session/participants/session-participants.js +11 -7
- package/dist/session/status/provisioning-failure.d.ts +4 -5
- package/dist/session/status/provisioning-failure.js +4 -5
- package/dist/session/thread/optimistic-turn.js +11 -2
- package/dist/session/thread/session-chat.js +73 -25
- package/dist/session/thread/transcript.d.ts +9 -0
- package/dist/session/thread/transcript.js +44 -5
- package/dist/session/tool/tools/channel-send-card.js +1 -0
- package/dist/session/turn/channel-brand.js +4 -0
- package/dist/session/turn/message-author.d.ts +13 -8
- package/dist/session/turn/message-author.js +34 -16
- package/dist/session/turn/peer-message-row.js +24 -6
- package/dist/session/turn/user-message.js +1 -1
- package/dist/session/voice/call-audio.d.ts +32 -0
- package/dist/session/voice/call-audio.js +146 -0
- package/dist/session/voice/screen-share.d.ts +24 -0
- package/dist/session/voice/screen-share.js +75 -0
- package/dist/session/voice/use-voice-call.d.ts +15 -0
- package/dist/session/voice/use-voice-call.js +220 -0
- package/dist/session/voice/voice-call-bar.d.ts +4 -0
- package/dist/session/voice/voice-call-bar.js +39 -0
- package/dist/session/voice/voice-call-state.d.ts +96 -0
- package/dist/session/voice/voice-call-state.js +103 -0
- package/dist/session/voice/voice-call-store.d.ts +12 -0
- package/dist/session/voice/voice-call-store.js +10 -0
- package/dist/session/voice/voice-call-url.d.ts +24 -0
- package/dist/session/voice/voice-call-url.js +33 -0
- package/dist/session/voice/voice-call.d.ts +15 -0
- package/dist/session/voice/voice-call.js +54 -0
- package/dist/styles.css +1 -1
- package/dist/workspace/admin/project-admin-dashboard.js +9 -4
- package/dist/workspace/layout/project-home.js +13 -14
- package/dist/workspace/sidebar/footer/project-manifest-issues-alert.d.ts +1 -1
- package/dist/workspace/sidebar/footer/project-manifest-issues-alert.js +4 -3
- package/dist/workspace/sidebar/project-session-list.js +1 -0
- package/dist/workspace/sidebar/session-filter-menu.js +1 -0
- package/dist/workspace/sidebar/session-grouping.d.ts +4 -0
- package/dist/workspace/sidebar/session-grouping.js +2 -0
- package/dist/workspace/sidebar/session-source-icons.js +2 -0
- package/dist/workspace/space/space-page.js +2 -2
- package/package.json +9 -9
- package/skills/kortix-ui/SKILL.md +2 -2
- package/skills/kortix-ui/references/custom-dashboard.md +1 -1
- package/dist/customize/agents/agent-section-rail.d.ts +0 -21
- package/dist/customize/agents/agent-section-rail.js +0 -23
- package/dist/internal/hooks/projects/use-warm-project-session.d.ts +0 -270
- package/dist/internal/hooks/projects/use-warm-project-session.js +0 -362
- package/dist/internal/hooks/projects/warm-session-seed.d.ts +0 -66
- package/dist/internal/hooks/projects/warm-session-seed.js +0 -80
- package/dist/internal/hooks/projects/warm-session-taken-registry.d.ts +0 -61
- package/dist/internal/hooks/projects/warm-session-taken-registry.js +0 -141
|
@@ -5,13 +5,16 @@ import { ArrowBendDownLeftIcon, CaretRightIcon, ChatTeardropTextIcon, CheckCircl
|
|
|
5
5
|
import { useId, useState } from 'react';
|
|
6
6
|
import { useTranslations } from '../../i18n/index.js';
|
|
7
7
|
import { cn } from '../../lib/utils.js';
|
|
8
|
+
import { UnifiedMarkdown } from '../../markdown/unified-markdown.js';
|
|
8
9
|
/**
|
|
9
|
-
* A message another Kortix session sent this one (`send_message`)
|
|
10
|
-
*
|
|
11
|
-
* finished",
|
|
12
|
-
*
|
|
13
|
-
* the
|
|
14
|
-
*
|
|
10
|
+
* A message another Kortix session sent this one (`send_message`): one dim
|
|
11
|
+
* line that says where it came from, "Message from @reviewer · Schema
|
|
12
|
+
* migration finished", then the whole message as Markdown behind a left rule,
|
|
13
|
+
* so it reads as one text and never as this session's own reply. The header
|
|
14
|
+
* and the footer the API wrapped around it (`peerMessagePromptText`) are for
|
|
15
|
+
* the agent, not the reader, so neither renders. An idle notice says only that
|
|
16
|
+
* a teammate finished: it stays one line that opens in place. A shutdown
|
|
17
|
+
* request and a shutdown answer get their own words.
|
|
15
18
|
*/
|
|
16
19
|
const KIND_ICON = {
|
|
17
20
|
message: ChatTeardropTextIcon,
|
|
@@ -44,6 +47,21 @@ export function peerMessagePreview(info) {
|
|
|
44
47
|
return lines[0] ?? '';
|
|
45
48
|
}
|
|
46
49
|
export function PeerMessageRow({ info, actions }) {
|
|
50
|
+
if (info.kind !== 'idle_notice')
|
|
51
|
+
return _jsx(PeerMessageBody, { info: info, actions: actions });
|
|
52
|
+
return _jsx(PeerIdleRow, { info: info, actions: actions });
|
|
53
|
+
}
|
|
54
|
+
/** A message, a shutdown request or a shutdown answer: the source line, then the full text. */
|
|
55
|
+
function PeerMessageBody({ info, actions }) {
|
|
56
|
+
const t = useTranslations('multiAgent.peer');
|
|
57
|
+
const KindIcon = KIND_ICON[info.kind];
|
|
58
|
+
const headline = t(KIND_KEY.get(info.kind) ?? 'message', { from: peerHandleLabel(info.from) });
|
|
59
|
+
const summary = info.summary?.trim();
|
|
60
|
+
const body = info.text.trim();
|
|
61
|
+
return (_jsxs("div", { "data-testid": "peer-message-turn", "data-peer-kind": info.kind, "data-peer-message-id": info.messageId, className: "flex min-w-0 flex-col gap-1.5", children: [_jsxs("div", { className: "text-muted-foreground flex w-full min-w-0 items-center gap-1.5 text-xs", children: [_jsx(KindIcon, { "aria-hidden": true, className: "size-3.5 shrink-0" }), _jsx("span", { className: "shrink-0", children: headline }), summary && (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, className: "shrink-0", children: "\u00B7" }), _jsx("span", { className: "min-w-0 truncate", title: summary, children: summary })] }))] }), body && (_jsx("div", { "data-slot": "peer-message-body", className: "border-border ml-1.5 min-w-0 border-l pl-3 text-sm", children: _jsx(UnifiedMarkdown, { content: body, trust: "agent", isStreaming: false }) })), actions] }));
|
|
62
|
+
}
|
|
63
|
+
/** An idle notice: one line that opens in place to the rest. */
|
|
64
|
+
function PeerIdleRow({ info, actions }) {
|
|
47
65
|
const t = useTranslations('multiAgent.peer');
|
|
48
66
|
const [open, setOpen] = useState(false);
|
|
49
67
|
const bodyId = useId();
|
|
@@ -1126,5 +1126,5 @@ export function UserMessage({ message, author, showAuthor, agentNames, commandIn
|
|
|
1126
1126
|
_jsxs("div", { className: cn('ml-auto flex w-full flex-col items-end gap-2 self-end',
|
|
1127
1127
|
// The bubble hugs its own text (`w-fit`), so lifting the cap widens
|
|
1128
1128
|
// ONLY the plan card — the message itself does not stretch.
|
|
1129
|
-
showPlan ? 'max-w-full' : 'max-w-[80%]'), children: [showAuthor && author?.kind === 'session' && _jsx(MessageAuthorLabel, { author: author }), (allAttachments.length > 0 || uploadStatus?.state === 'failed') && (_jsx(MessageAttachments, { attachments: allAttachments, status: uploadStatus, onOpenPastedContent: onOpenPastedContent })), systemNotifications.length > 0 && !effectiveCommandInfo && (_jsx("div", { className: "mt-1 flex w-full flex-col gap-1.5", children: withContentKeys(systemNotifications, (n) => `mixed-${n.tag}`).map(({ key, item }) => (_jsx(SystemNotificationCard, { notification: item }, key))) })), (bodyText || quotedPieces || effectiveCommandInfo) && (_jsx(MessageSenderAbove, { sender: showAuthor && author?.kind === 'member' ? author : null, children: _jsx(UserMessageBubble, { tail: showAuthor && author?.kind
|
|
1129
|
+
showPlan ? 'max-w-full' : 'max-w-[80%]'), children: [showAuthor && author?.kind === 'session' && _jsx(MessageAuthorLabel, { author: author }), (allAttachments.length > 0 || uploadStatus?.state === 'failed') && (_jsx(MessageAttachments, { attachments: allAttachments, status: uploadStatus, onOpenPastedContent: onOpenPastedContent })), systemNotifications.length > 0 && !effectiveCommandInfo && (_jsx("div", { className: "mt-1 flex w-full flex-col gap-1.5", children: withContentKeys(systemNotifications, (n) => `mixed-${n.tag}`).map(({ key, item }) => (_jsx(SystemNotificationCard, { notification: item }, key))) })), (bodyText || quotedPieces || effectiveCommandInfo) && (_jsx(MessageSenderAbove, { sender: showAuthor && author?.kind === 'member' ? author : null, reserve: showAuthor && !author, children: _jsx(UserMessageBubble, { tail: showAuthor && author?.kind !== 'session', canExpand: canExpand, expanded: expanded, onToggle: () => setExpanded(!expanded), textId: `${message.message_id}-text`, textRef: textRef, quoted: Boolean(quotedPieces), children: quotedPieces ? (_jsx(QuotedMessageBody, { pieces: quotedPieces, renderText: renderQuotedRun })) : ((bodyText || effectiveCommandInfo) && (_jsxs(_Fragment, { children: [commandLead, renderSegments(segments)] }))) }) })), actions, showPlan && (_jsx("div", { className: "w-full", children: _jsx(PlanCard, { sessionId: sessionId }) }))] }));
|
|
1130
1130
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface CallAudioStart {
|
|
2
|
+
inRate: number;
|
|
3
|
+
outRate: number;
|
|
4
|
+
/** The playback state the speaker starts in (`createPlayback().current()`). */
|
|
5
|
+
held: boolean;
|
|
6
|
+
ducked: boolean;
|
|
7
|
+
muted: () => boolean;
|
|
8
|
+
/** One 20 ms microphone frame, 16-bit mono PCM at `inRate`. */
|
|
9
|
+
onFrame: (pcm: ArrayBuffer) => void;
|
|
10
|
+
}
|
|
11
|
+
/** One call's speaker and microphone. `stop` releases both, at any point of `start`. */
|
|
12
|
+
export declare class CallAudio {
|
|
13
|
+
private output?;
|
|
14
|
+
private input?;
|
|
15
|
+
private stream?;
|
|
16
|
+
private speaker?;
|
|
17
|
+
private gain?;
|
|
18
|
+
private analyser?;
|
|
19
|
+
private pending;
|
|
20
|
+
private stopped;
|
|
21
|
+
private readonly samples;
|
|
22
|
+
/** The speaker first, then the microphone. Resolves false when there is no microphone to use. */
|
|
23
|
+
start(opts: CallAudioStart): Promise<boolean>;
|
|
24
|
+
/** One frame of the voice, 16-bit mono PCM at `outRate`. */
|
|
25
|
+
play(pcm: ArrayBuffer): void;
|
|
26
|
+
post(message: 'clear' | 'pause' | 'resume'): void;
|
|
27
|
+
level(value: number): void;
|
|
28
|
+
mute(on: boolean): void;
|
|
29
|
+
/** The voice's output level now (RMS of the last 512 samples). */
|
|
30
|
+
voiceLevel(): number;
|
|
31
|
+
stop(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { DUCK_GAIN } from './voice-call-state.js';
|
|
2
|
+
/**
|
|
3
|
+
* A call's audio, ported from the voice lab's call page. `Mic` cuts the microphone into 20 ms Int16 frames at
|
|
4
|
+
* the context's rate. `Spk` plays the voice's Int16 frames from a queue: `clear` drops it, `pause` holds it, and
|
|
5
|
+
* `resume` goes on from the last pause in the speech (a run of 160 ms below 300), so a held sentence restarts
|
|
6
|
+
* at a word, not mid-word.
|
|
7
|
+
*/
|
|
8
|
+
const WORKLET = `
|
|
9
|
+
class Mic extends AudioWorkletProcessor {
|
|
10
|
+
// rate: the relay's, when this context runs at the device's own (Firefox); each output sample averages the input
|
|
11
|
+
// samples of its period, a box filter against aliasing. Unset, the context already runs at the relay's rate.
|
|
12
|
+
constructor(o) { super(); this.r = o?.processorOptions?.rate || sampleRate; this.step = sampleRate / this.r; this.t = 0; this.a = 0; this.c = 0
|
|
13
|
+
this.b = new Int16Array(this.r / 50); this.n = 0 }
|
|
14
|
+
put(x) { this.b[this.n++] = Math.max(-1, Math.min(1, x)) * 0x7fff
|
|
15
|
+
if (this.n === this.b.length) { this.port.postMessage(this.b.buffer, [this.b.buffer]); this.b = new Int16Array(this.r / 50); this.n = 0 } }
|
|
16
|
+
process([i]) { const c = i[0]; if (!c) return true
|
|
17
|
+
if (this.step === 1) { for (let k = 0; k < c.length; k++) this.put(c[k]); return true }
|
|
18
|
+
for (let k = 0; k < c.length; k++) { this.a += c[k]; this.c++; if (++this.t >= this.step) { this.t -= this.step; this.put(this.a / this.c); this.a = 0; this.c = 0 } }
|
|
19
|
+
return true }
|
|
20
|
+
}
|
|
21
|
+
class Spk extends AudioWorkletProcessor {
|
|
22
|
+
constructor() { super(); this.q = []; this.o = 0; this.p = false; this.h = new Int16Array(sampleRate * 0.6); this.n = 0
|
|
23
|
+
this.port.onmessage = (e) => e.data === 'clear' ? (this.q = [], this.o = 0, this.p = false, this.n = 0) : e.data === 'pause' ? (this.p = true) : e.data === 'resume' ? (this.rewind(), this.p = false) : this.q.push(new Int16Array(e.data)) }
|
|
24
|
+
rewind() { const H = this.h.length, n = Math.min(this.n, H), at = (k) => this.h[(this.n - k) % H]
|
|
25
|
+
let back = 0; for (let k = 1, quiet = 0; k <= n; k++) { quiet = Math.abs(at(k)) < 300 ? quiet + 1 : 0; if (quiet >= sampleRate * 0.16) { back = k - quiet; break } }
|
|
26
|
+
if (!back) return; const r = new Int16Array(back); for (let k = 0; k < back; k++) r[k] = at(back - k)
|
|
27
|
+
if (this.q[0]) this.q[0] = this.q[0].subarray(this.o); this.o = 0; this.q.unshift(r); this.n -= back }
|
|
28
|
+
process(_, [out]) { const o = out[0]
|
|
29
|
+
for (let k = 0; k < o.length; k++) { const h = !this.p && this.q[0]; if (!h) { o[k] = 0; continue }
|
|
30
|
+
const s = h[this.o++]; o[k] = s / 0x8000; this.h[this.n++ % this.h.length] = s; if (this.o >= h.length) { this.q.shift(); this.o = 0 } }
|
|
31
|
+
return true }
|
|
32
|
+
}
|
|
33
|
+
registerProcessor('mic', Mic); registerProcessor('spk', Spk)`;
|
|
34
|
+
let workletUrl;
|
|
35
|
+
const workletModule = () => (workletUrl ??= URL.createObjectURL(new Blob([WORKLET], { type: 'text/javascript' })));
|
|
36
|
+
// Plain echo cancellation: Chrome's own AEC removes this page's playout from the microphone.
|
|
37
|
+
const MICROPHONE = {
|
|
38
|
+
audio: { echoCancellation: true, noiseSuppression: true, autoGainControl: true, channelCount: 1 },
|
|
39
|
+
};
|
|
40
|
+
/** Voice frames that arrive before the speaker is set up (the greeting) wait, up to this many. */
|
|
41
|
+
const PENDING_MAX = 1500;
|
|
42
|
+
/** One call's speaker and microphone. `stop` releases both, at any point of `start`. */
|
|
43
|
+
export class CallAudio {
|
|
44
|
+
output;
|
|
45
|
+
input;
|
|
46
|
+
stream;
|
|
47
|
+
speaker;
|
|
48
|
+
gain;
|
|
49
|
+
analyser;
|
|
50
|
+
pending = [];
|
|
51
|
+
stopped = false;
|
|
52
|
+
samples = new Float32Array(512);
|
|
53
|
+
/** The speaker first, then the microphone. Resolves false when there is no microphone to use. */
|
|
54
|
+
async start(opts) {
|
|
55
|
+
const output = (this.output = new AudioContext({ sampleRate: opts.outRate }));
|
|
56
|
+
await output.audioWorklet.addModule(workletModule());
|
|
57
|
+
if (this.stopped)
|
|
58
|
+
return false;
|
|
59
|
+
const speaker = new AudioWorkletNode(output, 'spk');
|
|
60
|
+
const gain = output.createGain();
|
|
61
|
+
const analyser = output.createAnalyser();
|
|
62
|
+
analyser.fftSize = 512;
|
|
63
|
+
speaker.connect(gain).connect(output.destination);
|
|
64
|
+
gain.connect(analyser);
|
|
65
|
+
if (opts.held) {
|
|
66
|
+
gain.gain.value = 0;
|
|
67
|
+
speaker.port.postMessage('pause');
|
|
68
|
+
}
|
|
69
|
+
else if (opts.ducked)
|
|
70
|
+
gain.gain.value = DUCK_GAIN;
|
|
71
|
+
this.speaker = speaker;
|
|
72
|
+
this.gain = gain;
|
|
73
|
+
this.analyser = analyser;
|
|
74
|
+
for (const pcm of this.pending)
|
|
75
|
+
speaker.port.postMessage(pcm, [pcm]);
|
|
76
|
+
this.pending = [];
|
|
77
|
+
if (output.state === 'suspended')
|
|
78
|
+
output.resume().catch(() => { });
|
|
79
|
+
const stream = await navigator.mediaDevices?.getUserMedia(MICROPHONE).catch(() => null);
|
|
80
|
+
if (this.stopped) {
|
|
81
|
+
stream?.getTracks().forEach((track) => track.stop());
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
if (!stream)
|
|
85
|
+
return false;
|
|
86
|
+
this.stream = stream;
|
|
87
|
+
let input = (this.input = new AudioContext({ sampleRate: opts.inRate }));
|
|
88
|
+
await input.audioWorklet.addModule(workletModule());
|
|
89
|
+
if (this.stopped)
|
|
90
|
+
return false;
|
|
91
|
+
let mic = new AudioWorkletNode(input, 'mic', { numberOfOutputs: 0 });
|
|
92
|
+
try {
|
|
93
|
+
input.createMediaStreamSource(stream).connect(mic);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Firefox joins a microphone only to a context at the device's rate: there the worklet brings it to inRate.
|
|
97
|
+
void input.close();
|
|
98
|
+
input = this.input = new AudioContext();
|
|
99
|
+
await input.audioWorklet.addModule(workletModule());
|
|
100
|
+
if (this.stopped)
|
|
101
|
+
return false;
|
|
102
|
+
mic = new AudioWorkletNode(input, 'mic', { numberOfOutputs: 0, processorOptions: { rate: opts.inRate } });
|
|
103
|
+
input.createMediaStreamSource(stream).connect(mic);
|
|
104
|
+
}
|
|
105
|
+
// Muted, the track sends silence: the relay keeps receiving frames.
|
|
106
|
+
mic.port.onmessage = (event) => opts.onFrame(event.data);
|
|
107
|
+
this.mute(opts.muted());
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
/** One frame of the voice, 16-bit mono PCM at `outRate`. */
|
|
111
|
+
play(pcm) {
|
|
112
|
+
if (this.speaker)
|
|
113
|
+
this.speaker.port.postMessage(pcm, [pcm]);
|
|
114
|
+
else if (!this.stopped && this.pending.length < PENDING_MAX)
|
|
115
|
+
this.pending.push(pcm);
|
|
116
|
+
}
|
|
117
|
+
post(message) {
|
|
118
|
+
this.speaker?.port.postMessage(message);
|
|
119
|
+
}
|
|
120
|
+
level(value) {
|
|
121
|
+
this.gain?.gain.setTargetAtTime(value, this.gain.context.currentTime, 0.03);
|
|
122
|
+
}
|
|
123
|
+
mute(on) {
|
|
124
|
+
this.stream?.getAudioTracks().forEach((track) => (track.enabled = !on));
|
|
125
|
+
}
|
|
126
|
+
/** The voice's output level now (RMS of the last 512 samples). */
|
|
127
|
+
voiceLevel() {
|
|
128
|
+
if (!this.analyser)
|
|
129
|
+
return 0;
|
|
130
|
+
this.analyser.getFloatTimeDomainData(this.samples);
|
|
131
|
+
let sum = 0;
|
|
132
|
+
for (const sample of this.samples)
|
|
133
|
+
sum += sample * sample;
|
|
134
|
+
return Math.sqrt(sum / this.samples.length);
|
|
135
|
+
}
|
|
136
|
+
stop() {
|
|
137
|
+
this.stopped = true;
|
|
138
|
+
this.stream?.getTracks().forEach((track) => track.stop());
|
|
139
|
+
if (this.input && this.input.state !== 'closed')
|
|
140
|
+
void this.input.close().catch(() => { });
|
|
141
|
+
if (this.output && this.output.state !== 'closed')
|
|
142
|
+
void this.output.close().catch(() => { });
|
|
143
|
+
this.speaker = this.gain = this.analyser = undefined;
|
|
144
|
+
this.pending = [];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A shared screen, as frames for the relay: ported from the voice lab's call page (its Present button and
|
|
3
|
+
* frame sampler). The first frame goes as soon as there is a picture, then one when the picture changed (its
|
|
4
|
+
* 32x18 grey thumbnail differs) at most every 3 s, and one at least every 20 s. JPEG, longest side 1280 px.
|
|
5
|
+
*/
|
|
6
|
+
/** The capture a share asks for. */
|
|
7
|
+
export declare const SCREEN_MEDIA: DisplayMediaStreamOptions;
|
|
8
|
+
export declare const THUMB_WIDTH = 32;
|
|
9
|
+
export declare const THUMB_HEIGHT = 18;
|
|
10
|
+
/** The mean per-pixel difference of two thumbnails from which the picture counts as changed. */
|
|
11
|
+
export declare const MOVED_MEAN = 4;
|
|
12
|
+
/** A browser that can share a screen (mobile browsers cannot). */
|
|
13
|
+
export declare const canShareScreen: () => boolean;
|
|
14
|
+
/** The grey value of each pixel of a 32x18 RGBA thumbnail. */
|
|
15
|
+
export declare function greyThumb(rgba: ArrayLike<number>): Uint8Array;
|
|
16
|
+
/** The picture changed since `last` (no frame sent yet counts as changed). */
|
|
17
|
+
export declare function thumbMoved(last: Uint8Array | undefined, next: Uint8Array): boolean;
|
|
18
|
+
export interface ScreenSampler {
|
|
19
|
+
stop(): void;
|
|
20
|
+
/** Sends the frame now, past both gates (the relay asked to look); false while there is no picture. */
|
|
21
|
+
snap(): boolean;
|
|
22
|
+
}
|
|
23
|
+
/** Samples a playing `video` of the shared screen and passes each frame to `send` as JPEG base64. */
|
|
24
|
+
export declare function sampleScreen(video: HTMLVideoElement, send: (jpeg: string) => void): ScreenSampler;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A shared screen, as frames for the relay: ported from the voice lab's call page (its Present button and
|
|
3
|
+
* frame sampler). The first frame goes as soon as there is a picture, then one when the picture changed (its
|
|
4
|
+
* 32x18 grey thumbnail differs) at most every 3 s, and one at least every 20 s. JPEG, longest side 1280 px.
|
|
5
|
+
*/
|
|
6
|
+
/** The capture a share asks for. */
|
|
7
|
+
export const SCREEN_MEDIA = { video: { frameRate: { ideal: 10, max: 15 } } };
|
|
8
|
+
const MIN_GAP_MS = 3_000;
|
|
9
|
+
const MAX_GAP_MS = 20_000;
|
|
10
|
+
const SIDE_PX = 1280;
|
|
11
|
+
const QUALITY = 0.7;
|
|
12
|
+
const CHECK_MS = 500;
|
|
13
|
+
export const THUMB_WIDTH = 32;
|
|
14
|
+
export const THUMB_HEIGHT = 18;
|
|
15
|
+
const THUMB_PIXELS = THUMB_WIDTH * THUMB_HEIGHT;
|
|
16
|
+
/** The mean per-pixel difference of two thumbnails from which the picture counts as changed. */
|
|
17
|
+
export const MOVED_MEAN = 4;
|
|
18
|
+
/** A browser that can share a screen (mobile browsers cannot). */
|
|
19
|
+
export const canShareScreen = () => typeof navigator !== 'undefined' && typeof navigator.mediaDevices?.getDisplayMedia === 'function';
|
|
20
|
+
/** The grey value of each pixel of a 32x18 RGBA thumbnail. */
|
|
21
|
+
export function greyThumb(rgba) {
|
|
22
|
+
const grey = new Uint8Array(THUMB_PIXELS);
|
|
23
|
+
for (let i = 0; i < THUMB_PIXELS; i++)
|
|
24
|
+
grey[i] = (rgba[4 * i] + rgba[4 * i + 1] + rgba[4 * i + 2]) / 3;
|
|
25
|
+
return grey;
|
|
26
|
+
}
|
|
27
|
+
/** The picture changed since `last` (no frame sent yet counts as changed). */
|
|
28
|
+
export function thumbMoved(last, next) {
|
|
29
|
+
if (!last)
|
|
30
|
+
return true;
|
|
31
|
+
let sum = 0;
|
|
32
|
+
for (let i = 0; i < next.length; i++)
|
|
33
|
+
sum += Math.abs(next[i] - last[i]);
|
|
34
|
+
return sum / next.length >= MOVED_MEAN;
|
|
35
|
+
}
|
|
36
|
+
/** Samples a playing `video` of the shared screen and passes each frame to `send` as JPEG base64. */
|
|
37
|
+
export function sampleScreen(video, send) {
|
|
38
|
+
const thumb = document.createElement('canvas');
|
|
39
|
+
thumb.width = THUMB_WIDTH;
|
|
40
|
+
thumb.height = THUMB_HEIGHT;
|
|
41
|
+
const thumbContext = thumb.getContext('2d', { willReadFrequently: true });
|
|
42
|
+
let last;
|
|
43
|
+
let sentAt = -Infinity;
|
|
44
|
+
let stopped = false;
|
|
45
|
+
const check = (now = false) => {
|
|
46
|
+
if (stopped || !thumbContext || !video.videoWidth)
|
|
47
|
+
return false;
|
|
48
|
+
const since = performance.now() - sentAt;
|
|
49
|
+
if (!now && since < MIN_GAP_MS)
|
|
50
|
+
return false;
|
|
51
|
+
thumbContext.drawImage(video, 0, 0, THUMB_WIDTH, THUMB_HEIGHT);
|
|
52
|
+
const grey = greyThumb(thumbContext.getImageData(0, 0, THUMB_WIDTH, THUMB_HEIGHT).data);
|
|
53
|
+
if (!now && !thumbMoved(last, grey) && since < MAX_GAP_MS)
|
|
54
|
+
return false;
|
|
55
|
+
last = grey;
|
|
56
|
+
sentAt = performance.now();
|
|
57
|
+
const scale = Math.min(1, SIDE_PX / Math.max(video.videoWidth, video.videoHeight));
|
|
58
|
+
const frame = document.createElement('canvas');
|
|
59
|
+
frame.width = Math.round(video.videoWidth * scale);
|
|
60
|
+
frame.height = Math.round(video.videoHeight * scale);
|
|
61
|
+
frame.getContext('2d')?.drawImage(video, 0, 0, frame.width, frame.height);
|
|
62
|
+
send(frame.toDataURL('image/jpeg', QUALITY).split(',')[1] ?? '');
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
const timer = setInterval(() => check(), CHECK_MS);
|
|
66
|
+
video.addEventListener('loadeddata', () => check(), { once: true });
|
|
67
|
+
check();
|
|
68
|
+
return {
|
|
69
|
+
stop: () => {
|
|
70
|
+
stopped = true;
|
|
71
|
+
clearInterval(timer);
|
|
72
|
+
},
|
|
73
|
+
snap: () => check(true),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type CallState } from './voice-call-state.js';
|
|
2
|
+
/**
|
|
3
|
+
* One voice call with the session `sessionId` (the Kortix session id), for as long as the caller is mounted.
|
|
4
|
+
* It dials the box's relay, plays the voice, sends the microphone and a shared screen, redials a live call
|
|
5
|
+
* that drops, and releases everything on unmount and when the tab closes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useVoiceCall(sessionId: string): {
|
|
8
|
+
state: CallState;
|
|
9
|
+
muted: boolean;
|
|
10
|
+
toggleMute: () => void;
|
|
11
|
+
sharing: boolean;
|
|
12
|
+
canShare: boolean;
|
|
13
|
+
toggleShare: () => Promise<void>;
|
|
14
|
+
callAgain: () => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { getAuthToken, getSandboxUrlForExternalId, probePreviewPort } from '@kortix/sdk';
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { useSandboxProxy } from '../../internal/hooks/use-sandbox-proxy.js';
|
|
5
|
+
import { CallAudio } from './call-audio.js';
|
|
6
|
+
import { canShareScreen, sampleScreen, SCREEN_MEDIA } from './screen-share.js';
|
|
7
|
+
import { AUDIBLE_RMS, createPlayback, DIAL_MS, INITIAL_CALL, reduceCall, REDIAL_MS, SPEAKING_HOLD_MS, } from './voice-call-state.js';
|
|
8
|
+
import { useVoiceCallStore } from './voice-call-store.js';
|
|
9
|
+
import { VOICE_PORT, voiceCallSocketUrl, voiceRelayHealthUrl } from './voice-call-url.js';
|
|
10
|
+
/** The relay asks for a fresh screen frame at most this often (`{type:'snap'}`). */
|
|
11
|
+
const SNAP_GAP_MS = 700;
|
|
12
|
+
/**
|
|
13
|
+
* One voice call with the session `sessionId` (the Kortix session id), for as long as the caller is mounted.
|
|
14
|
+
* It dials the box's relay, plays the voice, sends the microphone and a shared screen, redials a live call
|
|
15
|
+
* that drops, and releases everything on unmount and when the tab closes.
|
|
16
|
+
*/
|
|
17
|
+
export function useVoiceCall(sessionId) {
|
|
18
|
+
const { subdomainOpts, isReady } = useSandboxProxy();
|
|
19
|
+
const sandboxId = isReady ? subdomainOpts.sandboxId : '';
|
|
20
|
+
const [state, setState] = useState(INITIAL_CALL);
|
|
21
|
+
const [muted, setMuted] = useState(false);
|
|
22
|
+
const [sharing, setSharing] = useState(false);
|
|
23
|
+
const [attempt, setAttempt] = useState(0);
|
|
24
|
+
const mutedRef = useRef(false);
|
|
25
|
+
const liveRef = useRef(null);
|
|
26
|
+
const shareRef = useRef(null);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!sandboxId)
|
|
29
|
+
return;
|
|
30
|
+
const portUrl = getSandboxUrlForExternalId(sandboxId, VOICE_PORT);
|
|
31
|
+
let current = INITIAL_CALL;
|
|
32
|
+
let disposed = false;
|
|
33
|
+
let socket;
|
|
34
|
+
let audio;
|
|
35
|
+
let redial;
|
|
36
|
+
let frame = 0;
|
|
37
|
+
let heardAt = -Infinity;
|
|
38
|
+
let snapAt = -Infinity;
|
|
39
|
+
const send = (message) => {
|
|
40
|
+
if (socket?.readyState !== WebSocket.OPEN)
|
|
41
|
+
return false;
|
|
42
|
+
socket.send(JSON.stringify(message));
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
const playback = createPlayback({ post: (m) => audio?.post(m), level: (v) => audio?.level(v) });
|
|
46
|
+
const dropAudio = () => {
|
|
47
|
+
cancelAnimationFrame(frame);
|
|
48
|
+
audio?.stop();
|
|
49
|
+
audio = undefined;
|
|
50
|
+
};
|
|
51
|
+
const step = (event) => {
|
|
52
|
+
current = reduceCall(current, event);
|
|
53
|
+
setState(current);
|
|
54
|
+
if (current.phase === 'ended') {
|
|
55
|
+
clearTimeout(redial);
|
|
56
|
+
dropAudio();
|
|
57
|
+
shareRef.current?.stop(false);
|
|
58
|
+
socket?.close();
|
|
59
|
+
}
|
|
60
|
+
return current;
|
|
61
|
+
};
|
|
62
|
+
liveRef.current = { send, mute: (on) => audio?.mute(on) };
|
|
63
|
+
const listen = (target) => {
|
|
64
|
+
const now = performance.now();
|
|
65
|
+
if (target.voiceLevel() > AUDIBLE_RMS)
|
|
66
|
+
heardAt = now;
|
|
67
|
+
const speaking = now - heardAt < SPEAKING_HOLD_MS;
|
|
68
|
+
if (speaking !== current.speaking)
|
|
69
|
+
step({ type: 'speaking', on: speaking });
|
|
70
|
+
frame = requestAnimationFrame(() => listen(target));
|
|
71
|
+
};
|
|
72
|
+
const onReady = (message) => {
|
|
73
|
+
step({ type: 'ready' });
|
|
74
|
+
// A redialed call is a new call on the relay: it sees the shared screen again.
|
|
75
|
+
shareRef.current?.sampler.snap();
|
|
76
|
+
const started = (audio = new CallAudio());
|
|
77
|
+
started
|
|
78
|
+
.start({
|
|
79
|
+
inRate: message.inRate ?? 0,
|
|
80
|
+
outRate: message.outRate ?? 0,
|
|
81
|
+
...playback.current(),
|
|
82
|
+
muted: () => mutedRef.current,
|
|
83
|
+
onFrame: (pcm) => {
|
|
84
|
+
if (socket?.readyState === WebSocket.OPEN)
|
|
85
|
+
socket.send(pcm);
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
.then((microphone) => {
|
|
89
|
+
if (audio === started && !microphone)
|
|
90
|
+
step({ type: 'mic-blocked' });
|
|
91
|
+
})
|
|
92
|
+
.catch(() => {
|
|
93
|
+
if (audio === started)
|
|
94
|
+
step({ type: 'audio-failed' });
|
|
95
|
+
});
|
|
96
|
+
frame = requestAnimationFrame(() => listen(started));
|
|
97
|
+
};
|
|
98
|
+
const onMessage = (event) => {
|
|
99
|
+
if (event.data instanceof ArrayBuffer)
|
|
100
|
+
return void audio?.play(event.data);
|
|
101
|
+
let message;
|
|
102
|
+
try {
|
|
103
|
+
message = JSON.parse(event.data);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (playback.handle(message))
|
|
109
|
+
return;
|
|
110
|
+
switch (message.type) {
|
|
111
|
+
case 'ready':
|
|
112
|
+
return onReady(message);
|
|
113
|
+
case 'text':
|
|
114
|
+
return void step({ type: 'text', role: message.role, who: message.who, text: message.text });
|
|
115
|
+
case 'snap': {
|
|
116
|
+
const share = shareRef.current;
|
|
117
|
+
if (!share || performance.now() - snapAt < SNAP_GAP_MS)
|
|
118
|
+
return;
|
|
119
|
+
snapAt = performance.now();
|
|
120
|
+
return void share.sampler.snap();
|
|
121
|
+
}
|
|
122
|
+
case 'closed':
|
|
123
|
+
return void step({ type: 'closed' });
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const dial = async (again) => {
|
|
127
|
+
const token = await getAuthToken().catch(() => null);
|
|
128
|
+
if (disposed)
|
|
129
|
+
return;
|
|
130
|
+
const opened = new WebSocket(voiceCallSocketUrl(portUrl, { session: sessionId, token, redial: again, securePage: location.protocol === 'https:' }));
|
|
131
|
+
opened.binaryType = 'arraybuffer';
|
|
132
|
+
socket = opened;
|
|
133
|
+
opened.onmessage = onMessage;
|
|
134
|
+
opened.onclose = () => {
|
|
135
|
+
if (disposed || socket !== opened)
|
|
136
|
+
return;
|
|
137
|
+
dropAudio();
|
|
138
|
+
if (current.phase === 'connecting') {
|
|
139
|
+
// Before the first `ready`: dialed again while a box that just started opens the relay's port (DIAL_MS).
|
|
140
|
+
// After the last try, a port nothing listens on is a sandbox without the relay: the proxy answers that
|
|
141
|
+
// itself (502/503/504), and the probe tells it from a failed dial.
|
|
142
|
+
void probePreviewPort(voiceRelayHealthUrl(portUrl)).then((relay) => {
|
|
143
|
+
if (disposed)
|
|
144
|
+
return;
|
|
145
|
+
const next = step({ type: 'drop', relay });
|
|
146
|
+
if (next.phase === 'connecting')
|
|
147
|
+
redial = setTimeout(() => void dial(false), DIAL_MS[next.redials - 1]);
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const next = step({ type: 'drop' });
|
|
152
|
+
if (next.phase === 'reconnecting')
|
|
153
|
+
redial = setTimeout(() => void dial(true), REDIAL_MS[next.redials]);
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
const teardown = () => {
|
|
157
|
+
disposed = true;
|
|
158
|
+
clearTimeout(redial);
|
|
159
|
+
dropAudio();
|
|
160
|
+
shareRef.current?.stop(false);
|
|
161
|
+
socket?.close();
|
|
162
|
+
liveRef.current = null;
|
|
163
|
+
};
|
|
164
|
+
// Closing the tab (or leaving it for the back-forward cache) ends the call and its bar.
|
|
165
|
+
const onPageHide = () => {
|
|
166
|
+
teardown();
|
|
167
|
+
useVoiceCallStore.getState().close(sessionId);
|
|
168
|
+
};
|
|
169
|
+
window.addEventListener('pagehide', onPageHide);
|
|
170
|
+
void dial(false);
|
|
171
|
+
return () => {
|
|
172
|
+
window.removeEventListener('pagehide', onPageHide);
|
|
173
|
+
teardown();
|
|
174
|
+
};
|
|
175
|
+
}, [sandboxId, sessionId, attempt]);
|
|
176
|
+
const toggleMute = useCallback(() => {
|
|
177
|
+
const next = !mutedRef.current;
|
|
178
|
+
mutedRef.current = next;
|
|
179
|
+
setMuted(next);
|
|
180
|
+
liveRef.current?.mute(next);
|
|
181
|
+
}, []);
|
|
182
|
+
const toggleShare = useCallback(async () => {
|
|
183
|
+
if (shareRef.current)
|
|
184
|
+
return shareRef.current.stop(true);
|
|
185
|
+
const stream = await navigator.mediaDevices.getDisplayMedia(SCREEN_MEDIA).catch(() => null);
|
|
186
|
+
if (!stream)
|
|
187
|
+
return;
|
|
188
|
+
const call = liveRef.current;
|
|
189
|
+
const video = document.createElement('video');
|
|
190
|
+
video.muted = true;
|
|
191
|
+
video.playsInline = true;
|
|
192
|
+
video.srcObject = stream;
|
|
193
|
+
await video.play().catch(() => { });
|
|
194
|
+
if (!call || liveRef.current !== call || shareRef.current) {
|
|
195
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const sampler = sampleScreen(video, (data) => liveRef.current?.send({ type: 'image', data, from: 'screen' }));
|
|
199
|
+
const stop = (tell) => {
|
|
200
|
+
if (shareRef.current?.stop !== stop)
|
|
201
|
+
return;
|
|
202
|
+
shareRef.current = null;
|
|
203
|
+
sampler.stop();
|
|
204
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
205
|
+
video.srcObject = null;
|
|
206
|
+
if (tell)
|
|
207
|
+
liveRef.current?.send({ type: 'image', data: '', from: 'screen' });
|
|
208
|
+
setSharing(false);
|
|
209
|
+
};
|
|
210
|
+
shareRef.current = { sampler, stop };
|
|
211
|
+
// The browser's own "Stop sharing" ends the track.
|
|
212
|
+
stream.getVideoTracks()[0]?.addEventListener('ended', () => stop(true), { once: true });
|
|
213
|
+
setSharing(true);
|
|
214
|
+
}, []);
|
|
215
|
+
const callAgain = useCallback(() => {
|
|
216
|
+
setState(INITIAL_CALL);
|
|
217
|
+
setAttempt((n) => n + 1);
|
|
218
|
+
}, []);
|
|
219
|
+
return { state, muted, toggleMute, sharing, canShare: canShareScreen(), toggleShare, callAgain };
|
|
220
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { MicrophoneIcon, MicrophoneSlashIcon, PhoneDisconnectIcon, PhoneIcon, ScreencastIcon, XIcon, } from '@phosphor-icons/react';
|
|
4
|
+
import { useTranslations } from '../../i18n/index.js';
|
|
5
|
+
import { cn } from '../../lib/utils.js';
|
|
6
|
+
import { Button } from '../../primitives/button.js';
|
|
7
|
+
import { ButtonGroup } from '../../primitives/button-group.js';
|
|
8
|
+
import Hint from '../../primitives/hint.js';
|
|
9
|
+
import Loading from '../../primitives/loading.js';
|
|
10
|
+
import { useVoiceCall } from './use-voice-call.js';
|
|
11
|
+
import { useVoiceCallStore } from './voice-call-store.js';
|
|
12
|
+
// The queued messages' card chrome: the call is one more card in the stack above the composer.
|
|
13
|
+
const BAR = 'bg-background border-border flex w-full items-center gap-2 rounded-lg border p-1 pl-3 not-last:mb-2';
|
|
14
|
+
const TOGGLE = 'text-muted-foreground hover:text-foreground aria-pressed:bg-foreground/10 aria-pressed:text-foreground transition-colors active:scale-[0.96]';
|
|
15
|
+
const ENDED = {
|
|
16
|
+
closed: { key: 'ended', dot: null },
|
|
17
|
+
unavailable: { key: 'unavailable', dot: 'bg-kortix-orange' },
|
|
18
|
+
failed: { key: 'failed', dot: 'bg-kortix-red' },
|
|
19
|
+
lost: { key: 'lost', dot: 'bg-kortix-red' },
|
|
20
|
+
};
|
|
21
|
+
/** A live voice call with this session, as one card above its composer. */
|
|
22
|
+
export function VoiceCallBar({ sessionId }) {
|
|
23
|
+
const t = useTranslations('voiceCall');
|
|
24
|
+
const close = useVoiceCallStore((s) => s.close);
|
|
25
|
+
const { state, muted, toggleMute, sharing, canShare, toggleShare, callAgain } = useVoiceCall(sessionId);
|
|
26
|
+
const hangUp = () => close(sessionId);
|
|
27
|
+
if (state.phase === 'ended' && state.end) {
|
|
28
|
+
const { key, dot } = ENDED[state.end];
|
|
29
|
+
return (_jsxs("section", { "aria-label": t('title'), className: BAR, children: [dot && _jsx("span", { "aria-hidden": true, className: cn('size-2 shrink-0 rounded-full', dot) }), _jsx("p", { role: "status", className: "text-muted-foreground min-w-0 flex-1 text-sm text-pretty", children: t(key) }), _jsxs(ButtonGroup, { className: "shrink-0", children: [state.end !== 'unavailable' && (_jsxs(Button, { variant: "ghost", size: "xs", onClick: callAgain, children: [_jsx(PhoneIcon, { className: "size-3.5" }), t('callAgain')] })), _jsx(BarButton, { label: t('close'), onClick: hangUp, children: _jsx(XIcon, { className: "size-3.5" }) })] })] }));
|
|
30
|
+
}
|
|
31
|
+
const live = state.phase === 'live';
|
|
32
|
+
const status = live ? (state.speaking ? 'speaking' : 'listening') : state.phase;
|
|
33
|
+
const muteLabel = muted ? t('unmute') : t('mute');
|
|
34
|
+
const shareLabel = sharing ? t('stopSharing') : t('shareScreen');
|
|
35
|
+
return (_jsxs("section", { "aria-label": t('title'), className: BAR, children: [_jsxs("span", { className: "text-muted-foreground flex shrink-0 items-center gap-1.5 text-xs", children: [live ? (_jsx("span", { "aria-hidden": true, className: "bg-kortix-green size-2 shrink-0 rounded-full" })) : (_jsx(Loading, { className: "size-3.5 shrink-0" })), t(status)] }), _jsx("p", { className: "text-foreground min-w-0 flex-1 truncate text-sm", children: state.micBlocked ? (_jsx("span", { className: "text-muted-foreground", children: t('noMicrophone') })) : (state.line && (_jsxs(_Fragment, { children: [_jsx("span", { className: "text-muted-foreground", children: state.line.role === 'agent' ? state.line.who : t('you') }), ' ', state.line.text] }))) }), _jsxs(ButtonGroup, { className: "shrink-0", children: [_jsx(BarButton, { label: muteLabel, pressed: muted, disabled: state.micBlocked, onClick: toggleMute, children: muted || state.micBlocked ? _jsx(MicrophoneSlashIcon, { className: "size-3.5" }) : _jsx(MicrophoneIcon, { className: "size-3.5" }) }), canShare && (_jsx(BarButton, { label: shareLabel, pressed: sharing, disabled: !live && !sharing, onClick: () => void toggleShare(), children: _jsx(ScreencastIcon, { className: "size-3.5" }) })), _jsx(BarButton, { label: t('end'), onClick: hangUp, children: _jsx(PhoneDisconnectIcon, { className: "size-3.5" }) })] })] }));
|
|
36
|
+
}
|
|
37
|
+
function BarButton({ label, pressed, disabled, onClick, children, }) {
|
|
38
|
+
return (_jsx(Hint, { side: "top", sideOffset: 4, delayDuration: 300, label: label, children: _jsx(Button, { variant: "ghost", size: "icon", "aria-label": label, "aria-pressed": pressed, disabled: disabled, onClick: onClick, className: TOGGLE, children: children }) }));
|
|
39
|
+
}
|