@mgamadeus/ddd-agents 0.6.0 → 0.6.2

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/dist/voice.js CHANGED
@@ -3,7 +3,7 @@ import { useSyncExternalStore, useState, useEffect, useMemo, useRef, useCallback
3
3
  import { t as textKey } from "./chunks/text-key-DnoZ4lAk.js";
4
4
  import { f as formatAgentVoiceCallDuration } from "./chunks/format-agent-voice-call-duration-C-3hRc9p.js";
5
5
  import { a as useOptionalAgentsConversationClient } from "./chunks/AgentsConversationClientContext-C4T7g_Qk.js";
6
- import { c as DEFAULT_AGENTS_TEXTS, ab as useAgentsTexts, K as getAgentDisplayName } from "./chunks/link-navigation-BUcy5qWW.js";
6
+ import { c as DEFAULT_AGENTS_TEXTS, ab as useAgentsTexts, K as getAgentDisplayName, a4 as useAgentsComponents, D as DEFAULT_AGENTS_COMPONENTS } from "./chunks/link-navigation-BUcy5qWW.js";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
8
  import { V as VoiceBarsIcon, C as ConversationMessageWidgets, a as ConversationMessageUser } from "./chunks/VoiceBarsIcon-BIcURsBF.js";
9
9
  import { a as useOptionalAgentsChatStore, u as useAgentsChatSelector } from "./chunks/use-agents-chat-store-CuIkCz9v.js";
@@ -24,7 +24,7 @@ const readAgentVoiceErrorCode = (failure) => {
24
24
  };
25
25
  const trimApiPrefix = (apiPrefix) => apiPrefix.replace(/\/+$/, "");
26
26
  const callPath = (callId) => `/${encodeURIComponent(String(callId))}`;
27
- const buildAgentVoiceRequests = (apiPrefix) => {
27
+ const buildAgentVoiceRequests = (apiPrefix, buildOpenPath) => {
28
28
  const prefix = trimApiPrefix(apiPrefix);
29
29
  return {
30
30
  openSession: ({
@@ -33,7 +33,7 @@ const buildAgentVoiceRequests = (apiPrefix) => {
33
33
  conversationId,
34
34
  callId
35
35
  }) => ({
36
- url: `${prefix}/open`,
36
+ url: buildOpenPath === void 0 ? `${prefix}/open` : buildOpenPath(agentSpaceId),
37
37
  method: "POST",
38
38
  body: { agentSpaceId, sdpOffer, conversationId, callId }
39
39
  }),
@@ -70,8 +70,8 @@ const buildAgentVoiceRequests = (apiPrefix) => {
70
70
  };
71
71
  };
72
72
  const AGENT_VOICE_ERROR_CODE_INVALID_OPEN_ANSWER = "invalid_open_answer";
73
- const createAgentVoiceApi = ({ baseApi, apiPrefix }) => {
74
- const requests = buildAgentVoiceRequests(apiPrefix);
73
+ const createAgentVoiceApi = ({ baseApi, apiPrefix, buildOpenPath }) => {
74
+ const requests = buildAgentVoiceRequests(apiPrefix, buildOpenPath);
75
75
  return {
76
76
  openSession: async (args) => {
77
77
  const openAnswer = await baseApi.request(requests.openSession(args));
@@ -632,6 +632,21 @@ const useAgentVoiceCallServerEnd = (subscribeToConversationChanges) => {
632
632
  };
633
633
  }, [isCallActive, callConversationId, callId, subscribeToConversationChanges, conversationClient]);
634
634
  };
635
+ const useFollowAgentVoiceCallConversation = (onConversationOfCallChanged) => {
636
+ const callPhase = useAgentVoiceCallValue((call) => call.phase);
637
+ const callId = useAgentVoiceCallValue((call) => call.callId);
638
+ const callConversationId = useAgentVoiceCallValue((call) => call.conversationId);
639
+ const callAgentSpaceId = useAgentVoiceCallValue((call) => call.agentSpaceId);
640
+ const reportedCallAndConversationRef = useRef(void 0);
641
+ useEffect(() => {
642
+ if (onConversationOfCallChanged === void 0) return;
643
+ if (!isAgentVoiceCallActive(callPhase) || callId === void 0 || callConversationId === void 0) return;
644
+ const callAndConversation = `${callId}:${callConversationId}`;
645
+ if (reportedCallAndConversationRef.current === callAndConversation) return;
646
+ reportedCallAndConversationRef.current = callAndConversation;
647
+ onConversationOfCallChanged(callConversationId, callAgentSpaceId);
648
+ }, [callPhase, callId, callConversationId, callAgentSpaceId, onConversationOfCallChanged]);
649
+ };
635
650
  const SENTENCE_PATTERN = /[^.!?…]+[.!?…]*\s*/g;
636
651
  const normalizeForMatching = (text) => text.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "");
637
652
  const buildUnsavedAgentVoiceCallLines = (lines, savedMessages) => {
@@ -680,10 +695,10 @@ const readAgentVoiceRingOfRealtimeMessage = (message) => {
680
695
  };
681
696
  const pickRingingAgentVoiceCall = (rings, nowMs, handledCallIds) => rings.filter((ring) => ring.ringExpiresAtUnixMs > nowMs && !handledCallIds.has(ring.callId)).sort((left, right) => right.callId - left.callId)[0];
682
697
  class AgentVoiceAccountRealtimeRingSource {
683
- constructor(accountRealtimePollOrStarter) {
698
+ constructor(accountRealtimePoll) {
684
699
  this.subscribers = /* @__PURE__ */ new Set();
685
700
  this.knownRingsByCallId = /* @__PURE__ */ new Map();
686
- this.accountRealtimePollOrStarter = accountRealtimePollOrStarter;
701
+ this.accountRealtimePoll = accountRealtimePoll;
687
702
  }
688
703
  subscribe(onRing, onRingCleared) {
689
704
  const subscriber = { onRing, onRingCleared };
@@ -726,28 +741,12 @@ class AgentVoiceAccountRealtimeRingSource {
726
741
  knownRing.handedTo.add(subscriber);
727
742
  subscriber.onRing(knownRing.ring);
728
743
  }
729
- /**
730
- * The poll hands over the messages open now, then every arrival and every clear. A started poll delivers its
731
- * arrivals through the hook it was started with, so only the clears are subscribed there.
732
- */
744
+ /** The poll hands over the messages open now, then every arrival and the clear of every message it handed over. */
733
745
  listenToAccountRealtimePoll() {
734
- const accountRealtimePollOrStarter = this.accountRealtimePollOrStarter;
735
- if (typeof accountRealtimePollOrStarter !== "function") {
736
- this.unsubscribeFromAccountRealtimePoll = accountRealtimePollOrStarter.subscribe({
737
- onMessage: (message) => {
738
- this.acceptRealtimeMessage(message);
739
- },
740
- onMessageCleared: (message) => {
741
- this.acceptClearedRealtimeMessage(message);
742
- }
743
- });
744
- return;
745
- }
746
- const startedAccountRealtimePoll = accountRealtimePollOrStarter((message) => {
747
- this.acceptRealtimeMessage(message);
748
- });
749
- this.startedAccountRealtimePoll = startedAccountRealtimePoll;
750
- this.unsubscribeFromAccountRealtimePoll = startedAccountRealtimePoll.subscribe({
746
+ this.unsubscribeFromAccountRealtimePoll = this.accountRealtimePoll.subscribe({
747
+ onMessage: (message) => {
748
+ this.acceptRealtimeMessage(message);
749
+ },
751
750
  onMessageCleared: (message) => {
752
751
  this.acceptClearedRealtimeMessage(message);
753
752
  }
@@ -756,12 +755,10 @@ class AgentVoiceAccountRealtimeRingSource {
756
755
  leaveAccountRealtimePoll() {
757
756
  this.unsubscribeFromAccountRealtimePoll?.();
758
757
  this.unsubscribeFromAccountRealtimePoll = void 0;
759
- this.startedAccountRealtimePoll?.stop();
760
- this.startedAccountRealtimePoll = void 0;
761
758
  this.knownRingsByCallId.clear();
762
759
  }
763
760
  }
764
- const createAgentVoiceRingSource = (accountRealtimePollOrStarter) => new AgentVoiceAccountRealtimeRingSource(accountRealtimePollOrStarter);
761
+ const createAgentVoiceRingSource = (accountRealtimePoll) => new AgentVoiceAccountRealtimeRingSource(accountRealtimePoll);
765
762
  const AGENT_VOICE_ANSWER_REFUSAL_TEXT_KEYS = {
766
763
  answeredElsewhere: textKey("You already answered %agentName% on another device."),
767
764
  ringEnded: textKey("%agentName% stopped asking to talk."),
@@ -917,21 +914,6 @@ const useAgentVoiceRingTone = (isRinging) => {
917
914
  };
918
915
  }, [isRinging]);
919
916
  };
920
- const useFollowAgentVoiceCallConversation = (onConversationOfCallChanged) => {
921
- const callPhase = useAgentVoiceCallValue((call) => call.phase);
922
- const callId = useAgentVoiceCallValue((call) => call.callId);
923
- const callConversationId = useAgentVoiceCallValue((call) => call.conversationId);
924
- const callAgentSpaceId = useAgentVoiceCallValue((call) => call.agentSpaceId);
925
- const reportedCallAndConversationRef = useRef(void 0);
926
- useEffect(() => {
927
- if (onConversationOfCallChanged === void 0) return;
928
- if (!isAgentVoiceCallActive(callPhase) || callId === void 0 || callConversationId === void 0) return;
929
- const callAndConversation = `${callId}:${callConversationId}`;
930
- if (reportedCallAndConversationRef.current === callAndConversation) return;
931
- reportedCallAndConversationRef.current = callAndConversation;
932
- onConversationOfCallChanged(callConversationId, callAgentSpaceId);
933
- }, [callPhase, callId, callConversationId, callAgentSpaceId, onConversationOfCallChanged]);
934
- };
935
917
  const AgentVoiceCallContext = createContext({ ringSource: void 0 });
936
918
  const useAgentVoiceRingSource = () => useContext(AgentVoiceCallContext).ringSource;
937
919
  const useAgentVoiceTranslateText = () => {
@@ -955,24 +937,32 @@ const startButton = "agents_startButton_DMqIXK";
955
937
  const styles$5 = {
956
938
  startButton
957
939
  };
940
+ const LABEL_TEXT_KEY = textKey("Talk to %agentName%");
958
941
  const AgentVoiceChatStartButton = (props) => {
959
- const { agentSpaceId, conversationId, disabled = false, testId = "agent-voice-chat-start" } = props;
942
+ const { agentSpaceId, conversationId, disabled = false, onStart, testId = "agent-voice-chat-start" } = props;
960
943
  const translateText = useAgentVoiceTranslateText();
961
944
  const isCallActive = useIsAgentVoiceCallActive();
962
- const label2 = translateText("Talk to %agentName%");
963
- return /* @__PURE__ */ jsx(
945
+ const { Tooltip } = useAgentsComponents();
946
+ const hasEnvironmentTooltip = Tooltip !== DEFAULT_AGENTS_COMPONENTS.Tooltip;
947
+ const label2 = translateText(LABEL_TEXT_KEY);
948
+ const startButton2 = /* @__PURE__ */ jsx(
964
949
  "button",
965
950
  {
966
951
  type: "button",
967
952
  className: styles$5.startButton,
968
- onClick: () => void startAgentVoiceCall({ agentSpaceId, conversationId }),
953
+ onClick: () => {
954
+ onStart?.();
955
+ void startAgentVoiceCall({ agentSpaceId, conversationId });
956
+ },
969
957
  disabled: disabled || isCallActive,
970
958
  "aria-label": label2,
971
- title: label2,
959
+ title: hasEnvironmentTooltip ? void 0 : label2,
972
960
  "data-testid": testId,
973
961
  children: /* @__PURE__ */ jsx(VoiceBarsIcon, { size: 18 })
974
962
  }
975
963
  );
964
+ if (!hasEnvironmentTooltip) return startButton2;
965
+ return /* @__PURE__ */ jsx(Tooltip, { text: LABEL_TEXT_KEY, replacements: { agentName: getAgentDisplayName() }, placement: "top", wrapsChild: true, children: startButton2 });
976
966
  };
977
967
  const icon = "agents_icon_VX-p0I";
978
968
  const styles$4 = {
@@ -988,6 +978,7 @@ const AgentVoiceHangUpIcon = (props) => renderLineIcon(
988
978
  /* @__PURE__ */ jsx("path", { d: "M3.5 14.5c4.7-4.7 12.3-4.7 17 0l-2.2 2.2-3.1-1.4v-2.4a9.6 9.6 0 0 0-6.4 0v2.4l-3.1 1.4-2.2-2.2Z" })
989
979
  );
990
980
  const AgentVoiceCloseIcon = (props) => renderLineIcon(props.size ?? 16, /* @__PURE__ */ jsx("path", { d: "M6 6l12 12M18 6 6 18" }));
981
+ const agentVoicePartTestId = (testId, part, defaultTestId) => testId === void 0 ? defaultTestId : `${testId}-${part}`;
991
982
  const endedAgentVoiceCallTitleTextKey = (call) => {
992
983
  if (call.endReason === AGENT_VOICE_CALL_END_REASON_ENDED_BY_AGENT) return textKey("%agentName% ended the voice chat");
993
984
  if (call.endReason === AGENT_VOICE_CALL_END_REASON_LIMIT_REACHED) return textKey("Voice chat limit reached");
@@ -1005,6 +996,7 @@ const status = "agents_status_saTxLl";
1005
996
  const title = "agents_title_PBN6ka";
1006
997
  const time = "agents_time_aaWlsN";
1007
998
  const actions$1 = "agents_actions_uyJzPl";
999
+ const applicationActions = "agents_applicationActions_b5QBp8";
1008
1000
  const action$1 = "agents_action_z96Tb1";
1009
1001
  const actionLabel = "agents_actionLabel_ItbQmp";
1010
1002
  const styles$3 = {
@@ -1016,6 +1008,7 @@ const styles$3 = {
1016
1008
  title,
1017
1009
  time,
1018
1010
  actions: actions$1,
1011
+ applicationActions,
1019
1012
  action: action$1,
1020
1013
  actionLabel
1021
1014
  };
@@ -1028,6 +1021,13 @@ const TURN_STATUS_TEXT_KEYS = {
1028
1021
  thinking: textKey("%agentName% is thinking"),
1029
1022
  listening: textKey("%agentName% is listening")
1030
1023
  };
1024
+ const DEFAULT_TEST_ID = "agent-voice-call-band";
1025
+ const hasApplicationActions = (actions2) => actions2 !== void 0 && actions2 !== null && actions2 !== false;
1026
+ const AgentVoiceBandApplicationActions = (props) => {
1027
+ const { actions: actions2, testId } = props;
1028
+ if (!hasApplicationActions(actions2)) return null;
1029
+ return /* @__PURE__ */ jsx("div", { className: styles$3.applicationActions, "data-testid": testId, children: actions2 });
1030
+ };
1031
1031
  const AgentVoiceBandAction = (props) => {
1032
1032
  const { label: label2, icon: icon2, onClick, testId, iconOnly = false, pressed, variant, disabled = false } = props;
1033
1033
  return /* @__PURE__ */ jsxs(
@@ -1049,20 +1049,29 @@ const AgentVoiceBandAction = (props) => {
1049
1049
  );
1050
1050
  };
1051
1051
  const AgentVoiceCallBandView = (props) => {
1052
- const { call, elapsedSeconds, onStartVoiceChat, incoming, agentSpot } = props;
1052
+ const { call, elapsedSeconds, onStartVoiceChat, incoming, agentSpot, actions: actions2, testId } = props;
1053
1053
  const translateText = useAgentVoiceTranslateText();
1054
1054
  const duration = formatAgentVoiceCallDuration(elapsedSeconds);
1055
1055
  const agentName = getAgentDisplayName();
1056
+ const bandTestId = testId ?? DEFAULT_TEST_ID;
1057
+ const applicationActions2 = /* @__PURE__ */ jsx(
1058
+ AgentVoiceBandApplicationActions,
1059
+ {
1060
+ actions: actions2,
1061
+ testId: agentVoicePartTestId(testId, "actions", "agent-voice-call-band-actions")
1062
+ }
1063
+ );
1056
1064
  const spot2 = agentSpot === void 0 || agentSpot === null ? null : /* @__PURE__ */ jsx("div", { className: styles$3.spot, children: agentSpot });
1057
1065
  if (isAgentVoiceCallActive(call.phase)) {
1058
- return /* @__PURE__ */ jsx("div", { className: styles$3.band, "data-testid": "agent-voice-call-band", "data-phase": call.phase, children: /* @__PURE__ */ jsxs("div", { className: styles$3.content, children: [
1066
+ return /* @__PURE__ */ jsx("div", { className: styles$3.band, "data-testid": bandTestId, "data-phase": call.phase, children: /* @__PURE__ */ jsxs("div", { className: styles$3.content, children: [
1059
1067
  spot2,
1060
1068
  /* @__PURE__ */ jsxs("div", { className: styles$3.who, "aria-live": "polite", children: [
1061
1069
  /* @__PURE__ */ jsx("span", { className: styles$3.title, children: agentName }),
1062
1070
  call.phase === "live" && /* @__PURE__ */ jsx("span", { className: styles$3.time, children: duration }),
1063
- /* @__PURE__ */ jsx("span", { className: styles$3.status, "data-testid": "agent-voice-call-status", children: translateText(TURN_STATUS_TEXT_KEYS[turnOfAgentVoiceCall(call)]) })
1071
+ /* @__PURE__ */ jsx("span", { className: styles$3.status, "data-testid": agentVoicePartTestId(testId, "status", "agent-voice-call-status"), children: translateText(TURN_STATUS_TEXT_KEYS[turnOfAgentVoiceCall(call)]) })
1064
1072
  ] }),
1065
1073
  /* @__PURE__ */ jsxs("div", { className: styles$3.actions, children: [
1074
+ applicationActions2,
1066
1075
  /* @__PURE__ */ jsx(
1067
1076
  AgentVoiceBandAction,
1068
1077
  {
@@ -1071,7 +1080,7 @@ const AgentVoiceCallBandView = (props) => {
1071
1080
  onClick: toggleAgentVoiceCallMute,
1072
1081
  pressed: call.isMuted,
1073
1082
  disabled: call.phase !== "live",
1074
- testId: "agent-voice-call-mute"
1083
+ testId: agentVoicePartTestId(testId, "mute", "agent-voice-call-mute")
1075
1084
  }
1076
1085
  ),
1077
1086
  /* @__PURE__ */ jsx(
@@ -1081,7 +1090,7 @@ const AgentVoiceCallBandView = (props) => {
1081
1090
  icon: /* @__PURE__ */ jsx(AgentVoiceHangUpIcon, {}),
1082
1091
  onClick: () => hangUpAgentVoiceCall(),
1083
1092
  variant: "end",
1084
- testId: "agent-voice-call-end"
1093
+ testId: agentVoicePartTestId(testId, "end", "agent-voice-call-end")
1085
1094
  }
1086
1095
  )
1087
1096
  ] })
@@ -1089,13 +1098,14 @@ const AgentVoiceCallBandView = (props) => {
1089
1098
  }
1090
1099
  if (incoming?.ring) {
1091
1100
  const callerLabel = incoming.callerLabel ?? buildAgentVoiceCallerLabel(incoming.ring, translateText, agentName);
1092
- return /* @__PURE__ */ jsx("div", { className: styles$3.band, "data-testid": "agent-voice-call-band", "data-phase": "incoming", children: /* @__PURE__ */ jsxs("div", { className: styles$3.content, children: [
1101
+ return /* @__PURE__ */ jsx("div", { className: styles$3.band, "data-testid": bandTestId, "data-phase": "incoming", children: /* @__PURE__ */ jsxs("div", { className: styles$3.content, children: [
1093
1102
  spot2,
1094
1103
  /* @__PURE__ */ jsxs("div", { className: styles$3.who, role: "alert", children: [
1095
1104
  /* @__PURE__ */ jsx("span", { className: styles$3.title, children: callerLabel.text }),
1096
1105
  callerLabel.detail ? /* @__PURE__ */ jsx("span", { className: styles$3.status, children: callerLabel.detail }) : null
1097
1106
  ] }),
1098
1107
  /* @__PURE__ */ jsxs("div", { className: styles$3.actions, children: [
1108
+ applicationActions2,
1099
1109
  /* @__PURE__ */ jsx(
1100
1110
  AgentVoiceBandAction,
1101
1111
  {
@@ -1104,7 +1114,7 @@ const AgentVoiceCallBandView = (props) => {
1104
1114
  onClick: incoming.onDecline,
1105
1115
  variant: "end",
1106
1116
  disabled: incoming.isAnswering,
1107
- testId: "agent-voice-call-incoming-decline"
1117
+ testId: agentVoicePartTestId(testId, "incoming-decline", "agent-voice-call-incoming-decline")
1108
1118
  }
1109
1119
  ),
1110
1120
  /* @__PURE__ */ jsx(
@@ -1115,32 +1125,43 @@ const AgentVoiceCallBandView = (props) => {
1115
1125
  onClick: incoming.onAccept,
1116
1126
  variant: "accept",
1117
1127
  disabled: incoming.isAnswering,
1118
- testId: "agent-voice-call-incoming-accept"
1128
+ testId: agentVoicePartTestId(testId, "incoming-accept", "agent-voice-call-incoming-accept")
1119
1129
  }
1120
1130
  )
1121
1131
  ] })
1122
1132
  ] }, "incoming") });
1123
1133
  }
1124
1134
  if (incoming?.refusal && call.phase === "idle") {
1125
- return /* @__PURE__ */ jsx("div", { className: styles$3.band, "data-testid": "agent-voice-call-band", "data-phase": "refused", children: /* @__PURE__ */ jsx("div", { className: styles$3.content, children: /* @__PURE__ */ jsx("div", { className: styles$3.who, role: "status", children: /* @__PURE__ */ jsx("span", { className: styles$3.status, "data-testid": "agent-voice-call-incoming-refusal", children: translateText(AGENT_VOICE_ANSWER_REFUSAL_TEXT_KEYS[incoming.refusal]) }) }) }, "refused") });
1135
+ return /* @__PURE__ */ jsx("div", { className: styles$3.band, "data-testid": bandTestId, "data-phase": "refused", children: /* @__PURE__ */ jsxs("div", { className: styles$3.content, children: [
1136
+ /* @__PURE__ */ jsx("div", { className: styles$3.who, role: "status", children: /* @__PURE__ */ jsx(
1137
+ "span",
1138
+ {
1139
+ className: styles$3.status,
1140
+ "data-testid": agentVoicePartTestId(testId, "incoming-refusal", "agent-voice-call-incoming-refusal"),
1141
+ children: translateText(AGENT_VOICE_ANSWER_REFUSAL_TEXT_KEYS[incoming.refusal])
1142
+ }
1143
+ ) }),
1144
+ hasApplicationActions(actions2) ? /* @__PURE__ */ jsx("div", { className: styles$3.actions, children: applicationActions2 }) : null
1145
+ ] }, "refused") });
1126
1146
  }
1127
1147
  if (call.phase !== "ended" && call.phase !== "failed") return null;
1128
1148
  const wasConnected = call.connectedAtMs !== void 0;
1129
1149
  const titleTextKey = agentVoiceCallOutcomeTitleTextKey(call);
1130
- return /* @__PURE__ */ jsx("div", { className: styles$3.band, "data-testid": "agent-voice-call-band", "data-phase": call.phase, "data-end-reason": call.endReason, children: /* @__PURE__ */ jsxs("div", { className: styles$3.content, children: [
1150
+ return /* @__PURE__ */ jsx("div", { className: styles$3.band, "data-testid": bandTestId, "data-phase": call.phase, "data-end-reason": call.endReason, children: /* @__PURE__ */ jsxs("div", { className: styles$3.content, children: [
1131
1151
  /* @__PURE__ */ jsxs("div", { className: styles$3.who, "aria-live": "polite", children: [
1132
1152
  /* @__PURE__ */ jsx(
1133
1153
  "span",
1134
1154
  {
1135
1155
  className: styles$3.title,
1136
- "data-testid": call.phase === "ended" && wasConnected ? "agent-voice-call-ended-status" : void 0,
1156
+ "data-testid": call.phase === "ended" && wasConnected ? agentVoicePartTestId(testId, "ended-status", "agent-voice-call-ended-status") : void 0,
1137
1157
  children: translateText(titleTextKey)
1138
1158
  }
1139
1159
  ),
1140
1160
  call.phase === "ended" && wasConnected && /* @__PURE__ */ jsx("span", { className: styles$3.time, children: duration }),
1141
- call.phase === "failed" && call.failureTextKey && /* @__PURE__ */ jsx("span", { className: styles$3.status, "data-testid": "agent-voice-call-failure", children: translateText(call.failureTextKey) })
1161
+ call.phase === "failed" && call.failureTextKey && /* @__PURE__ */ jsx("span", { className: styles$3.status, "data-testid": agentVoicePartTestId(testId, "failure", "agent-voice-call-failure"), children: translateText(call.failureTextKey) })
1142
1162
  ] }),
1143
1163
  /* @__PURE__ */ jsxs("div", { className: styles$3.actions, children: [
1164
+ applicationActions2,
1144
1165
  /* @__PURE__ */ jsx(
1145
1166
  AgentVoiceBandAction,
1146
1167
  {
@@ -1148,7 +1169,7 @@ const AgentVoiceCallBandView = (props) => {
1148
1169
  icon: /* @__PURE__ */ jsx(VoiceBarsIcon, { size: 16 }),
1149
1170
  onClick: onStartVoiceChat,
1150
1171
  variant: "accept",
1151
- testId: "agent-voice-call-start-again"
1172
+ testId: agentVoicePartTestId(testId, "start-again", "agent-voice-call-start-again")
1152
1173
  }
1153
1174
  ),
1154
1175
  /* @__PURE__ */ jsx(
@@ -1158,14 +1179,14 @@ const AgentVoiceCallBandView = (props) => {
1158
1179
  icon: /* @__PURE__ */ jsx(AgentVoiceCloseIcon, {}),
1159
1180
  onClick: dismissAgentVoiceCallOutcome,
1160
1181
  iconOnly: true,
1161
- testId: "agent-voice-call-band-close"
1182
+ testId: agentVoicePartTestId(testId, "close", "agent-voice-call-band-close")
1162
1183
  }
1163
1184
  )
1164
1185
  ] })
1165
1186
  ] }, call.phase) });
1166
1187
  };
1167
1188
  const AgentVoiceCallBand = (props) => {
1168
- const { renderAgentSpot, agentSpaceId, isPresented = true } = props;
1189
+ const { renderAgentSpot, agentSpaceId, isPresented = true, actions: actions2, testId } = props;
1169
1190
  const liveCall = useAgentVoiceCallSnapshot();
1170
1191
  const call = isAgentVoiceCallShownInAgentSpace(liveCall, agentSpaceId) ? liveCall : IDLE_AGENT_VOICE_CALL;
1171
1192
  const elapsedSeconds = useAgentVoiceCallElapsedSeconds(call);
@@ -1177,6 +1198,8 @@ const AgentVoiceCallBand = (props) => {
1177
1198
  call,
1178
1199
  elapsedSeconds,
1179
1200
  agentSpot: renderAgentSpot?.(call),
1201
+ actions: actions2,
1202
+ testId,
1180
1203
  onStartVoiceChat: () => void startAgentVoiceCall({ agentSpaceId: call.agentSpaceId ?? agentSpaceId, conversationId: call.conversationId }),
1181
1204
  incoming: {
1182
1205
  ring,
@@ -1202,7 +1225,7 @@ const styles$2 = {
1202
1225
  const NO_MESSAGES = [];
1203
1226
  const selectMessages = (state) => state.messages;
1204
1227
  const AgentVoiceCallCaptionLines = (props) => {
1205
- const { call, ownerMessageTheme } = props;
1228
+ const { call, ownerMessageTheme, testId } = props;
1206
1229
  const chatStore = useOptionalAgentsChatStore();
1207
1230
  const messages = useAgentsChatSelector(chatStore, selectMessages, null) ?? NO_MESSAGES;
1208
1231
  const [highestIndexBeforeVoiceChat, setHighestIndexBeforeVoiceChat] = useState(void 0);
@@ -1213,15 +1236,31 @@ const AgentVoiceCallCaptionLines = (props) => {
1213
1236
  () => highestIndexBeforeVoiceChat === void 0 ? [] : buildUnsavedAgentVoiceCallLines(call.lines, savedMessagesOfTheVoiceChat(messages, highestIndexBeforeVoiceChat)),
1214
1237
  [call.lines, messages, highestIndexBeforeVoiceChat]
1215
1238
  );
1216
- return /* @__PURE__ */ jsx("div", { className: styles$2.captions, "data-testid": "agent-voice-call-captions", children: unsavedLines.map(
1217
- (line2) => line2.speaker === "agent" ? /* @__PURE__ */ jsx("div", { className: styles$2.line, "data-testid": "agent-voice-call-caption-agent", children: /* @__PURE__ */ jsx(ConversationMessageWidgets, { message: line2.text, interactive: false, justDelivered: false, hideAssistantMeta: true }) }, line2.id) : /* @__PURE__ */ jsx("div", { className: styles$2.line, "data-testid": "agent-voice-call-caption-owner", children: /* @__PURE__ */ jsx(ConversationMessageUser, { text: line2.text, theme: ownerMessageTheme }) }, line2.id)
1239
+ return /* @__PURE__ */ jsx("div", { className: styles$2.captions, "data-testid": testId ?? "agent-voice-call-captions", children: unsavedLines.map(
1240
+ (line2) => line2.speaker === "agent" ? /* @__PURE__ */ jsx(
1241
+ "div",
1242
+ {
1243
+ className: styles$2.line,
1244
+ "data-testid": agentVoicePartTestId(testId, "caption-agent", "agent-voice-call-caption-agent"),
1245
+ children: /* @__PURE__ */ jsx(ConversationMessageWidgets, { message: line2.text, interactive: false, justDelivered: false, hideAssistantMeta: true })
1246
+ },
1247
+ line2.id
1248
+ ) : /* @__PURE__ */ jsx(
1249
+ "div",
1250
+ {
1251
+ className: styles$2.line,
1252
+ "data-testid": agentVoicePartTestId(testId, "caption-owner", "agent-voice-call-caption-owner"),
1253
+ children: /* @__PURE__ */ jsx(ConversationMessageUser, { text: line2.text, theme: ownerMessageTheme })
1254
+ },
1255
+ line2.id
1256
+ )
1218
1257
  ) });
1219
1258
  };
1220
1259
  const AgentVoiceCallCaptions = (props) => {
1221
- const { agentSpaceId, ownerMessageTheme } = props;
1260
+ const { agentSpaceId, ownerMessageTheme, testId } = props;
1222
1261
  const call = useAgentVoiceCallSnapshot();
1223
1262
  if (!isAgentVoiceCallActive(call.phase) || !isAgentVoiceCallShownInAgentSpace(call, agentSpaceId)) return null;
1224
- return /* @__PURE__ */ jsx(AgentVoiceCallCaptionLines, { call, ownerMessageTheme });
1263
+ return /* @__PURE__ */ jsx(AgentVoiceCallCaptionLines, { call, ownerMessageTheme, testId });
1225
1264
  };
1226
1265
  const glowVoiceOfAgentVoiceCallTurn = (turn) => {
1227
1266
  if (turn === "agent") return "agent";
@@ -1252,7 +1291,8 @@ const GLOW_COLOUR_PROPERTIES = [
1252
1291
  ["--agents-voice-glow-color-4", "#12ffff"],
1253
1292
  ["--agents-voice-glow-color-1", "#00495d"]
1254
1293
  ];
1255
- const AgentVoiceInputGlowCanvases = () => {
1294
+ const AgentVoiceInputGlowCanvases = (props) => {
1295
+ const { testId } = props;
1256
1296
  const voice = useAgentVoiceCallValue(
1257
1297
  (call) => isAgentVoiceCallActive(call.phase) ? glowVoiceOfAgentVoiceCallTurn(turnOfAgentVoiceCall(call)) : "quiet"
1258
1298
  );
@@ -1390,15 +1430,15 @@ const AgentVoiceInputGlowCanvases = () => {
1390
1430
  field?.removeEventListener("focusin", startBurst);
1391
1431
  };
1392
1432
  }, []);
1393
- return /* @__PURE__ */ jsxs("div", { ref: boxRef, className: styles$1.glow, "aria-hidden": true, "data-testid": "agent-voice-input-glow", children: [
1433
+ return /* @__PURE__ */ jsxs("div", { ref: boxRef, className: styles$1.glow, "aria-hidden": true, "data-testid": testId, children: [
1394
1434
  /* @__PURE__ */ jsx("canvas", { ref: haloCanvasRef, className: styles$1.halo }),
1395
1435
  /* @__PURE__ */ jsx("canvas", { ref: edgeCanvasRef, className: styles$1.edge })
1396
1436
  ] });
1397
1437
  };
1398
1438
  const AgentVoiceInputGlow = (props) => {
1399
- const { agentSpaceId } = props;
1439
+ const { agentSpaceId, testId = "agent-voice-input-glow" } = props;
1400
1440
  const isCallActiveHere = useIsAgentVoiceCallActive(agentSpaceId);
1401
- return isCallActiveHere ? /* @__PURE__ */ jsx(AgentVoiceInputGlowCanvases, {}) : null;
1441
+ return isCallActiveHere ? /* @__PURE__ */ jsx(AgentVoiceInputGlowCanvases, { testId }) : null;
1402
1442
  };
1403
1443
  const withAgentVoiceIncomingRing = (heldRings, ring) => [...heldRings.filter((heldRing) => heldRing.callId !== ring.callId), ring];
1404
1444
  const withoutAgentVoiceIncomingRingOfCall = (heldRings, callId) => heldRings.filter((heldRing) => heldRing.callId !== callId);
@@ -1453,7 +1493,7 @@ const styles = {
1453
1493
  action
1454
1494
  };
1455
1495
  const AgentVoiceIncomingCall = (props) => {
1456
- const { resolveCallerLabel, renderAgentSpot } = props;
1496
+ const { resolveCallerLabel, renderAgentSpot, zIndex, testId } = props;
1457
1497
  const translateText = useAgentVoiceTranslateText();
1458
1498
  const ringSource = useAgentVoiceRingSource();
1459
1499
  const isCallActive = useAgentVoiceCallValue((call) => isAgentVoiceCallActive(call.phase));
@@ -1473,10 +1513,20 @@ const AgentVoiceIncomingCall = (props) => {
1473
1513
  useAgentVoiceRingTone(ring !== void 0 && !isAnswering);
1474
1514
  const card = ringSource !== void 0 ? pickAgentVoiceIncomingCard({ ring, refusal, bandHostCount, ringCoverCount }) : void 0;
1475
1515
  const callerLabelId = useId();
1516
+ const layerStyle = zIndex === void 0 ? void 0 : { zIndex };
1476
1517
  if (card === void 0) return null;
1477
1518
  if (ring === void 0) {
1478
1519
  if (refusal === void 0) return null;
1479
- return /* @__PURE__ */ jsx("div", { className: styles.incomingCall, role: "status", "data-testid": "agent-voice-incoming-call-refusal", children: /* @__PURE__ */ jsx("span", { className: styles.detail, children: translateText(AGENT_VOICE_ANSWER_REFUSAL_TEXT_KEYS[refusal]) }) });
1520
+ return /* @__PURE__ */ jsx(
1521
+ "div",
1522
+ {
1523
+ className: styles.incomingCall,
1524
+ style: layerStyle,
1525
+ role: "status",
1526
+ "data-testid": agentVoicePartTestId(testId, "refusal", "agent-voice-incoming-call-refusal"),
1527
+ children: /* @__PURE__ */ jsx("span", { className: styles.detail, children: translateText(AGENT_VOICE_ANSWER_REFUSAL_TEXT_KEYS[refusal]) })
1528
+ }
1529
+ );
1480
1530
  }
1481
1531
  const shownCallerLabel = callerLabel ?? buildAgentVoiceCallerLabel(ring, translateText, getAgentDisplayName());
1482
1532
  return /* @__PURE__ */ jsxs(
@@ -1486,12 +1536,20 @@ const AgentVoiceIncomingCall = (props) => {
1486
1536
  role: "alertdialog",
1487
1537
  "aria-live": "assertive",
1488
1538
  "aria-labelledby": callerLabelId,
1489
- "data-testid": "agent-voice-incoming-call",
1539
+ style: layerStyle,
1540
+ "data-testid": testId ?? "agent-voice-incoming-call",
1490
1541
  children: [
1491
1542
  /* @__PURE__ */ jsx("div", { className: styles.spot, children: renderAgentSpot ? renderAgentSpot() : /* @__PURE__ */ jsx("span", { className: styles.mark, children: /* @__PURE__ */ jsx(VoiceBarsIcon, { size: 24 }) }) }),
1492
1543
  /* @__PURE__ */ jsxs("div", { className: styles.caller, id: callerLabelId, children: [
1493
1544
  /* @__PURE__ */ jsx("span", { className: styles.label, children: shownCallerLabel.text }),
1494
- shownCallerLabel.detail ? /* @__PURE__ */ jsx("span", { className: styles.detail, "data-testid": "agent-voice-incoming-call-detail", children: shownCallerLabel.detail }) : null
1545
+ shownCallerLabel.detail ? /* @__PURE__ */ jsx(
1546
+ "span",
1547
+ {
1548
+ className: styles.detail,
1549
+ "data-testid": agentVoicePartTestId(testId, "detail", "agent-voice-incoming-call-detail"),
1550
+ children: shownCallerLabel.detail
1551
+ }
1552
+ ) : null
1495
1553
  ] }),
1496
1554
  /* @__PURE__ */ jsxs("div", { className: styles.actions, children: [
1497
1555
  /* @__PURE__ */ jsxs(
@@ -1501,7 +1559,7 @@ const AgentVoiceIncomingCall = (props) => {
1501
1559
  className: styles.action,
1502
1560
  disabled: isAnswering,
1503
1561
  onClick: declineAgentVoiceIncomingRing,
1504
- "data-testid": "agent-voice-incoming-call-decline",
1562
+ "data-testid": agentVoicePartTestId(testId, "decline", "agent-voice-incoming-call-decline"),
1505
1563
  children: [
1506
1564
  /* @__PURE__ */ jsx(AgentVoiceCloseIcon, {}),
1507
1565
  /* @__PURE__ */ jsx("span", { children: translateText("Decline") })
@@ -1516,7 +1574,7 @@ const AgentVoiceIncomingCall = (props) => {
1516
1574
  "data-variant": "accept",
1517
1575
  disabled: isAnswering,
1518
1576
  onClick: () => void acceptAgentVoiceIncomingRing(),
1519
- "data-testid": "agent-voice-incoming-call-accept",
1577
+ "data-testid": agentVoicePartTestId(testId, "accept", "agent-voice-incoming-call-accept"),
1520
1578
  children: [
1521
1579
  /* @__PURE__ */ jsx(AgentVoiceMicrophoneIcon, {}),
1522
1580
  /* @__PURE__ */ jsx("span", { children: translateText("Accept") })
@@ -1581,6 +1639,7 @@ export {
1581
1639
  useAgentVoiceRingCover,
1582
1640
  useAgentVoiceRingTone,
1583
1641
  useAgentVoiceTranslateText,
1642
+ useFollowAgentVoiceCallConversation,
1584
1643
  useIsAgentVoiceCallActive
1585
1644
  };
1586
1645
  //# sourceMappingURL=voice.js.map