@kortix/ui 0.14.16 → 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/artifact-annotations.d.ts +126 -1
- package/dist/_vendor/shared/artifact-comments.d.ts +30 -1
- 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 +3 -6
- package/dist/customize/settings/tabs/general-tab.js +5 -4
- package/dist/customize/shared/capability-library.js +19 -22
- package/dist/customize/shared/channels-switch-dialog.d.ts +4 -8
- package/dist/customize/shared/channels-switch-dialog.js +5 -16
- package/dist/customize/shared/customize-tab-bar.d.ts +1 -2
- package/dist/customize/shared/customize-tab-bar.js +10 -11
- package/dist/customize/shared/feature-gate-screen.js +5 -7
- package/dist/files/drives/drive-path-param.d.ts +4 -0
- package/dist/files/drives/drive-path-param.js +50 -0
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.js +1 -0
- package/dist/files/project/components/drive-create-dialog.js +3 -3
- package/dist/i18n/en.d.ts +99 -18
- package/dist/i18n/en.js +125 -44
- 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/doc-editor/doc-menus.d.ts +6 -0
- package/dist/markdown/doc-editor/doc-menus.js +74 -9
- 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 +26 -6
- package/dist/session/status/provisioning-failure.js +39 -12
- 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 +14 -26
- package/dist/workspace/sidebar/session-brief-hover-card.d.ts +0 -3
- package/dist/workspace/sidebar/session-brief-hover-card.js +0 -3
- 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/skills/kortix-ui/references/modules.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
|
@@ -54,6 +54,8 @@ import { SubagentDialog } from '../agents/subagent-view.js';
|
|
|
54
54
|
import { parseNoticeBatch, parseSubagentNotice } from '../turn/subagent-notice.js';
|
|
55
55
|
import { SubagentNoticeRow } from '../turn/subagent-notice-row.js';
|
|
56
56
|
import { NoticeBatchGroup } from '../turn/notice-batch-group.js';
|
|
57
|
+
import { PeerMessageRow } from '../turn/peer-message-row.js';
|
|
58
|
+
import { parsePeerMessagePrompt } from '../../_vendor/kortix-shared.js';
|
|
57
59
|
import { ToolPartRenderer, TurnLiveContext } from '../tool/tool-renderers.js';
|
|
58
60
|
import { ImageGenDigestsContext, ImageGenPathsContext, ImageGenRunsContext, InTranscriptTurnContext, RecoveredCallsContext, } from '../tool/shared/infrastructure.js';
|
|
59
61
|
import { imageDigestsShownByImageGen, imagePathsShownByImageGen, sessionLogImageGenRuns, showDrawnByImageGen } from '@kortix/sdk';
|
|
@@ -589,6 +591,22 @@ function useAnsweredQuestionState({ turn, questions, sessionId, blocks, hasSteps
|
|
|
589
591
|
* A user message's text as its v1 text parts held it: a text block, or an
|
|
590
592
|
* `ignored` text (a model-invisible `harness` block whose data is the part).
|
|
591
593
|
*/
|
|
594
|
+
/**
|
|
595
|
+
* Whether a turn's prompt is a notice from another agent, not something a
|
|
596
|
+
* person wrote: a peer message (`send_message`), a subagent or teammate that
|
|
597
|
+
* finished, or a batch of those. The agent's work continues across it, so the
|
|
598
|
+
* thread spaces it like a continuation, not like a new prompt.
|
|
599
|
+
*/
|
|
600
|
+
export function isAgentNoticeTurn(turn) {
|
|
601
|
+
// A stream delta remakes the turns, not the prompt: read each prompt once.
|
|
602
|
+
const known = agentNoticeOf.get(turn.user);
|
|
603
|
+
if (known !== undefined)
|
|
604
|
+
return known;
|
|
605
|
+
const notice = promptTexts(turn.user).some((t) => !!parsePeerMessagePrompt(t.text) || !!parseSubagentNotice(t.text) || (parseNoticeBatch(t.text)?.length ?? 0) > 1);
|
|
606
|
+
agentNoticeOf.set(turn.user, notice);
|
|
607
|
+
return notice;
|
|
608
|
+
}
|
|
609
|
+
const agentNoticeOf = new WeakMap();
|
|
592
610
|
export function promptTexts(message) {
|
|
593
611
|
return message.blocks.flatMap((b) => {
|
|
594
612
|
if (b.type === 'text')
|
|
@@ -637,6 +655,21 @@ function useTurnUserContent({ turn, commandMessages, commands, }) {
|
|
|
637
655
|
}
|
|
638
656
|
return null;
|
|
639
657
|
}, [texts, sessionReport, noticeBatch]);
|
|
658
|
+
// A message from another Kortix session (`send_message`). The API delivers it as
|
|
659
|
+
// harness context (`synthetic`), so the bubble, which draws only what a person
|
|
660
|
+
// typed, never shows it: its row is drawn here. A typed one stays the bubble's.
|
|
661
|
+
const peerMessage = useMemo(() => {
|
|
662
|
+
if (sessionReport || noticeBatch)
|
|
663
|
+
return null;
|
|
664
|
+
for (const t of texts) {
|
|
665
|
+
if (!t.synthetic)
|
|
666
|
+
continue;
|
|
667
|
+
const info = parsePeerMessagePrompt(t.text);
|
|
668
|
+
if (info)
|
|
669
|
+
return info;
|
|
670
|
+
}
|
|
671
|
+
return null;
|
|
672
|
+
}, [texts, sessionReport, noticeBatch]);
|
|
640
673
|
// Extract kortix_system messages for inline rendering (goal continuations, etc.)
|
|
641
674
|
const systemMessages = useMemo(() => {
|
|
642
675
|
const msgs = [];
|
|
@@ -699,7 +732,7 @@ function useTurnUserContent({ turn, commandMessages, commands, }) {
|
|
|
699
732
|
const source = Array.isArray(commands) ? commands.find((c) => c.name === commandForTurn.name)?.source : undefined;
|
|
700
733
|
return source === 'skill' ? undefined : commandForTurn;
|
|
701
734
|
}, [commandForTurn, commands]);
|
|
702
|
-
return { sessionReport, noticeBatch, subagentNotice, systemMessages, hasVisibleUserContent, userMessageText, commandForTurn, commandOutput };
|
|
735
|
+
return { sessionReport, noticeBatch, subagentNotice, peerMessage, systemMessages, hasVisibleUserContent, userMessageText, commandForTurn, commandOutput };
|
|
703
736
|
}
|
|
704
737
|
/** The throttled working status of the working turn: one status change per
|
|
705
738
|
* 2.5 s, keyed on the turn's parts. */
|
|
@@ -982,11 +1015,11 @@ function TurnSessionReport({ report }) {
|
|
|
982
1015
|
* user bubble (hidden for notification-only turns). */
|
|
983
1016
|
function TurnUserBlock(props) {
|
|
984
1017
|
const { userContent } = props;
|
|
985
|
-
const { sessionReport, noticeBatch, subagentNotice, systemMessages, hasVisibleUserContent } = userContent;
|
|
1018
|
+
const { sessionReport, noticeBatch, subagentNotice, peerMessage, systemMessages, hasVisibleUserContent } = userContent;
|
|
986
1019
|
// P5.6: the note a partial restore left for the agent is a notice, not a person's prompt.
|
|
987
1020
|
if (isSessionLogRestoreNote(props.turn.user))
|
|
988
1021
|
return _jsx(RestoreNoteMarker, {});
|
|
989
|
-
return (_jsxs(_Fragment, { children: [noticeBatch ? (_jsx(NoticeBatchGroup, { items: noticeBatch })) : subagentNotice ? (_jsx(SubagentNoticeRow, { notice: subagentNotice })) : (sessionReport && _jsx(TurnSessionReport, { report: sessionReport })), !hasVisibleUserContent && !sessionReport && !noticeBatch && systemMessages.length > 0 && (_jsx(SystemMessageIndicator, { messages: systemMessages })), hasVisibleUserContent && _jsx(TurnUserBubble, { ...props })] }));
|
|
1022
|
+
return (_jsxs(_Fragment, { children: [noticeBatch ? (_jsx(NoticeBatchGroup, { items: noticeBatch })) : subagentNotice ? (_jsx(SubagentNoticeRow, { notice: subagentNotice })) : peerMessage ? (_jsx(PeerMessageRow, { info: peerMessage })) : (sessionReport && _jsx(TurnSessionReport, { report: sessionReport })), !hasVisibleUserContent && !sessionReport && !noticeBatch && !peerMessage && systemMessages.length > 0 && (_jsx(SystemMessageIndicator, { messages: systemMessages })), hasVisibleUserContent && _jsx(TurnUserBubble, { ...props })] }));
|
|
990
1023
|
}
|
|
991
1024
|
/** The user message bubble — dimmed while the prompt waits in the queue. */
|
|
992
1025
|
function TurnUserBubble(props) {
|
|
@@ -1160,7 +1193,7 @@ function TurnFooter(props) {
|
|
|
1160
1193
|
const { statusPhrase, statusElapsedLabel } = status;
|
|
1161
1194
|
const { retryInfo, retryMessage, retrySecondsLeft } = retry;
|
|
1162
1195
|
const { turnEndedAt, turnDurationMs, costInfo } = meta;
|
|
1163
|
-
return (_jsxs(_Fragment, { children: [_jsx(TurnBusyRow, { ...props, working: working, turnError: turnError, tHardcodedUi: tHardcodedUi }), turnErrorRow.text && !turn.autoRetry?.continued && (_jsx(TurnErrorDisplay, { errorText: turnErrorRow.text, errorDetails: turnErrorRowDetails, errorRaw: turnErrorRaw, isAbort: turnErrorRow.isAbort, modelOptions: modelOptions })), turnErrorRow.text && !turnErrorRow.isAbort && !turn.autoRetry?.continued && !!turn.autoRetry?.retries && (_jsx(TurnAutoRetryNote, { count: turn.autoRetry.retries })), !working && !turn.autoRetry?.continued && (stoppedBy || errors.turnErrorIsAbort) && _jsx(TurnStoppedBy, { name: stoppedBy ?? undefined }), !working && _jsx(TurnOutcomes, { turnKey: turn.id }), !working && !props.hideActionBar && (_jsx(TurnActionBar, { response: response, inlineContentParts: answered.inlineContentParts, turnEndedAt: turnEndedAt, turnDurationMs: turnDurationMs, costInfo: costInfo, servedModel: servedModel, tHardcodedUi: tHardcodedUi,
|
|
1196
|
+
return (_jsxs(_Fragment, { children: [_jsx(TurnBusyRow, { ...props, working: working, turnError: turnError, tHardcodedUi: tHardcodedUi }), turnErrorRow.text && !turn.autoRetry?.continued && (_jsx(TurnErrorDisplay, { errorText: turnErrorRow.text, errorDetails: turnErrorRowDetails, errorRaw: turnErrorRaw, isAbort: turnErrorRow.isAbort, modelOptions: modelOptions })), turnErrorRow.text && !turnErrorRow.isAbort && !turn.autoRetry?.continued && !!turn.autoRetry?.retries && (_jsx(TurnAutoRetryNote, { count: turn.autoRetry.retries })), !working && !turn.autoRetry?.continued && (stoppedBy || errors.turnErrorIsAbort) && _jsx(TurnStoppedBy, { name: stoppedBy ?? undefined }), !working && _jsx(TurnOutcomes, { turnKey: turn.id }), !working && !props.hideActionBar && hasCopyableResponse(response, answered.inlineContentParts) && (_jsx(TurnActionBar, { response: response, inlineContentParts: answered.inlineContentParts, turnEndedAt: turnEndedAt, turnDurationMs: turnDurationMs, costInfo: costInfo, servedModel: servedModel, tHardcodedUi: tHardcodedUi,
|
|
1164
1197
|
// A continuation turn's id names a compaction marker, not a user
|
|
1165
1198
|
// message, so it has no response of its own to share.
|
|
1166
1199
|
share: turn.continues
|
|
@@ -1187,6 +1220,12 @@ function TurnBusyRow(props) {
|
|
|
1187
1220
|
}
|
|
1188
1221
|
/** Copy + the turn's settled meta row — the hover-revealed bar at the end of
|
|
1189
1222
|
* a settled turn. Owns the copy state: it is the only consumer. */
|
|
1223
|
+
/** Whether the turn wrote any text: the response, or a text item of its inline content. */
|
|
1224
|
+
function hasCopyableResponse(response, inlineContentParts) {
|
|
1225
|
+
if (response.trim())
|
|
1226
|
+
return true;
|
|
1227
|
+
return !!inlineContentParts?.some((item) => item.type === 'text' && item.block.text.trim());
|
|
1228
|
+
}
|
|
1190
1229
|
function TurnActionBar({ response, inlineContentParts, turnEndedAt, turnDurationMs, costInfo, servedModel, tHardcodedUi, inToolbar = false, share, }) {
|
|
1191
1230
|
const [copied, setCopied] = useState(false);
|
|
1192
1231
|
// ---- Copy response ----
|
|
@@ -1289,7 +1328,7 @@ function SessionTurnImpl(props) {
|
|
|
1289
1328
|
: rows.owner;
|
|
1290
1329
|
const personName = person ? participantLabel(person) : '';
|
|
1291
1330
|
const showAnswer = turn.assistant.length > 0 || model.working || !!errors.turnErrorRow.text;
|
|
1292
|
-
return (_jsxs("div", { className: "text-factor-[2]", children: [userContent.hasVisibleUserContent || userContent.sessionReport || userContent.noticeBatch || userContent.systemMessages.length > 0 ? (_jsx(MessageRow
|
|
1331
|
+
return (_jsxs("div", { className: "text-factor-[2]", children: [userContent.hasVisibleUserContent || userContent.sessionReport || userContent.noticeBatch || userContent.peerMessage || userContent.systemMessages.length > 0 ? (_jsx(MessageRow
|
|
1293
1332
|
// The first message's turn clips its toolbar's overhang: it sits inside the row.
|
|
1294
1333
|
, {
|
|
1295
1334
|
// The first message's turn clips its toolbar's overhang: it sits inside the row.
|
|
@@ -12,6 +12,7 @@ const REPLIED_IN_KEY = {
|
|
|
12
12
|
Teams: 'text72b5b0c53de9',
|
|
13
13
|
Slack: 'textfc73e9ad2dae',
|
|
14
14
|
Telegram: 'text8faf56a14a8d',
|
|
15
|
+
Discord: 'text3416de570ab5',
|
|
15
16
|
};
|
|
16
17
|
/** "Replied in Microsoft Teams" — the row title for a channel send. */
|
|
17
18
|
export function channelSendTitle(platform, tI18nComplete) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { ChatCircleIcon } from '@phosphor-icons/react';
|
|
4
|
+
import { Discord, DISCORD_BLURPLE } from '../../internal/icons/discord.js';
|
|
4
5
|
import { Email } from '../../internal/icons/email.js';
|
|
5
6
|
import { MicrosoftTeams } from '../../internal/icons/microsoft-teams.js';
|
|
6
7
|
import { Slack } from '../../internal/icons/slack.js';
|
|
@@ -22,6 +23,7 @@ export const CHANNEL_BRAND_COLOR = {
|
|
|
22
23
|
Slack: undefined,
|
|
23
24
|
Teams: '#5B5FC7',
|
|
24
25
|
Email: undefined,
|
|
26
|
+
Discord: DISCORD_BLURPLE,
|
|
25
27
|
};
|
|
26
28
|
const TELEGRAM_PATH = 'M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm4.64 6.8c-.15 1.58-.8 5.42-1.13 7.19-.14.75-.42 1-.68 1.03-.58.05-1.02-.38-1.58-.75-.88-.58-1.38-.94-2.23-1.5-.99-.65-.35-1.01.22-1.59.15-.15 2.71-2.48 2.76-2.69a.2.2 0 00-.05-.18c-.06-.05-.14-.03-.21-.02-.09.02-1.49.95-4.22 2.79-.4.27-.76.41-1.08.4-.36-.01-1.04-.2-1.55-.37-.63-.2-1.12-.31-1.08-.66.02-.18.27-.36.74-.55 2.92-1.27 4.86-2.11 5.83-2.51 2.78-1.16 3.35-1.36 3.73-1.36.08 0 .27.02.39.12.1.08.13.19.14.27-.01.06.01.24 0 .38z';
|
|
27
29
|
/**
|
|
@@ -36,6 +38,8 @@ export function ChannelBrandMark({ platform, className = 'size-3.5 shrink-0', })
|
|
|
36
38
|
return _jsx(Slack, { className: className });
|
|
37
39
|
if (platform === 'Email')
|
|
38
40
|
return _jsx(Email, { className: className });
|
|
41
|
+
if (platform === 'Discord')
|
|
42
|
+
return _jsx(Discord, { className: className });
|
|
39
43
|
if (platform !== 'Telegram')
|
|
40
44
|
return _jsx(ChatCircleIcon, { className: className, "aria-hidden": "true" });
|
|
41
45
|
return (_jsx("svg", { className: className, viewBox: "0 0 24 24", fill: CHANNEL_BRAND_COLOR.Telegram, "aria-hidden": "true", children: _jsx("path", { d: TELEGRAM_PATH }) }));
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { SessionMessageAuthor, SessionMessageAuthors } from '@kortix/sdk';
|
|
1
|
+
import type { SessionMessageAuthor, SessionMessageAuthors, SessionParticipants } from '@kortix/sdk';
|
|
2
|
+
import type { UiViewer } from '../../providers/ui-provider.js';
|
|
2
3
|
interface TranscriptAuthors {
|
|
3
4
|
/** The author of each user message that has one, by runtime message id. */
|
|
4
5
|
byMessage: Map<string, SessionMessageAuthor>;
|
|
5
|
-
/** True when the transcript reads as a group chat: 2+ distinct authors. */
|
|
6
|
-
multiAuthor: boolean;
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
9
8
|
* Pairs each user message with its author. A spawned session's first message
|
|
@@ -27,12 +26,18 @@ export declare function missingAuthorKey(data: SessionMessageAuthors | undefined
|
|
|
27
26
|
*/
|
|
28
27
|
export declare function authorForTurn(resolved: TranscriptAuthors, data: SessionMessageAuthors | undefined, messageId: string, wireMessageId?: string): SessionMessageAuthor | undefined;
|
|
29
28
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
29
|
+
* The signed-in viewer as a message author. A prompt sent from this tab has no
|
|
30
|
+
* recorded author until the ledger writes it, a moment after the bubble
|
|
31
|
+
* paints: the viewer's own avatar stands in, so the bubble does not move when
|
|
32
|
+
* the recorded author arrives. Undefined with no viewer.
|
|
34
33
|
*/
|
|
35
|
-
export declare function
|
|
34
|
+
export declare function viewerAuthor(viewer: UiViewer | undefined): SessionMessageAuthor | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* A queued prompt's sender, from the people who can open the session: the
|
|
37
|
+
* prompt row names its `author_user_id` before the authors read lists it.
|
|
38
|
+
* Undefined when that person is not in the listed rows (the route lists 20).
|
|
39
|
+
*/
|
|
40
|
+
export declare function participantAuthor(participants: SessionParticipants | undefined, userId: string | null | undefined): SessionMessageAuthor | undefined;
|
|
36
41
|
/**
|
|
37
42
|
* Who to name under a turn someone ELSE stopped: "Stopped by <name>". Null
|
|
38
43
|
* when nobody is recorded, when the stop came from an agent session, and when
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/** One author, one key: two members never share it, nor do two sessions. */
|
|
2
|
-
function authorKey(author) {
|
|
3
|
-
return author.kind === 'member' ? `member:${author.user_id}` : `session:${author.session_id}`;
|
|
4
|
-
}
|
|
5
1
|
/**
|
|
6
2
|
* Pairs each user message with its author. A spawned session's first message
|
|
7
3
|
* has no prompt record of its own, so `initial_author` goes to the first user
|
|
@@ -18,8 +14,7 @@ export function resolveTranscriptAuthors(userMessageIds, data) {
|
|
|
18
14
|
initial = null;
|
|
19
15
|
byMessage.set(id, author);
|
|
20
16
|
}
|
|
21
|
-
|
|
22
|
-
return { byMessage, multiAuthor: distinct.size >= 2 };
|
|
17
|
+
return { byMessage };
|
|
23
18
|
}
|
|
24
19
|
/** When to ask again for an author that is not recorded yet: 2 s, 5 s, 12 s. */
|
|
25
20
|
export const AUTHOR_RETRY_DELAYS_MS = [2000, 5000, 12000];
|
|
@@ -45,17 +40,40 @@ export function authorForTurn(resolved, data, messageId, wireMessageId) {
|
|
|
45
40
|
(wireMessageId ? data?.authors[wireMessageId] : undefined));
|
|
46
41
|
}
|
|
47
42
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
43
|
+
* The signed-in viewer as a message author. A prompt sent from this tab has no
|
|
44
|
+
* recorded author until the ledger writes it, a moment after the bubble
|
|
45
|
+
* paints: the viewer's own avatar stands in, so the bubble does not move when
|
|
46
|
+
* the recorded author arrives. Undefined with no viewer.
|
|
47
|
+
*/
|
|
48
|
+
export function viewerAuthor(viewer) {
|
|
49
|
+
if (!viewer)
|
|
50
|
+
return undefined;
|
|
51
|
+
const name = viewer.metadata?.full_name ?? viewer.metadata?.name;
|
|
52
|
+
const avatar = viewer.metadata?.avatar_url;
|
|
53
|
+
return {
|
|
54
|
+
kind: 'member',
|
|
55
|
+
user_id: viewer.id,
|
|
56
|
+
name: typeof name === 'string' ? name : '',
|
|
57
|
+
email: viewer.email ?? null,
|
|
58
|
+
avatar_url: typeof avatar === 'string' ? avatar : null,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A queued prompt's sender, from the people who can open the session: the
|
|
63
|
+
* prompt row names its `author_user_id` before the authors read lists it.
|
|
64
|
+
* Undefined when that person is not in the listed rows (the route lists 20).
|
|
52
65
|
*/
|
|
53
|
-
export function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
export function participantAuthor(participants, userId) {
|
|
67
|
+
const person = userId ? participants?.participants.find((p) => p.user_id === userId) : undefined;
|
|
68
|
+
if (!person)
|
|
69
|
+
return undefined;
|
|
70
|
+
return {
|
|
71
|
+
kind: 'member',
|
|
72
|
+
user_id: person.user_id,
|
|
73
|
+
name: person.name ?? '',
|
|
74
|
+
email: person.email,
|
|
75
|
+
avatar_url: person.avatar_url,
|
|
76
|
+
};
|
|
59
77
|
}
|
|
60
78
|
/**
|
|
61
79
|
* Who to name under a turn someone ELSE stopped: "Stopped by <name>". Null
|
|
@@ -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
|
+
};
|