@mgamadeus/ddd-agents 0.5.16 → 0.6.0

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.
Files changed (109) hide show
  1. package/README.md +170 -6
  2. package/boundary.json +13 -0
  3. package/dist/chat.js +148 -773
  4. package/dist/chat.js.map +1 -1
  5. package/dist/chunks/{canvas-title-slot-context-DK4sfhkl.js → ConversationMarkdown-BsCjyhj4.js} +14 -43
  6. package/dist/chunks/ConversationMarkdown-BsCjyhj4.js.map +1 -0
  7. package/dist/chunks/{ConversationMessageInputComposerWidgets-B3Zf69rD.js → ConversationMessageInputComposerWidgets-CE8LpyXY.js} +10 -37
  8. package/dist/chunks/ConversationMessageInputComposerWidgets-CE8LpyXY.js.map +1 -0
  9. package/dist/chunks/VoiceBarsIcon-BIcURsBF.js +643 -0
  10. package/dist/chunks/VoiceBarsIcon-BIcURsBF.js.map +1 -0
  11. package/dist/chunks/{WebSearchResultsConversationWidget-887v8Wen.js → WebSearchResultsConversationWidget-DXhfSikV.js} +2 -2
  12. package/dist/chunks/{WebSearchResultsConversationWidget-887v8Wen.js.map → WebSearchResultsConversationWidget-DXhfSikV.js.map} +1 -1
  13. package/dist/chunks/browser-request-interception-BnzFbH0m.js +335 -0
  14. package/dist/chunks/browser-request-interception-BnzFbH0m.js.map +1 -0
  15. package/dist/chunks/{canvas-reducers-CwFA3rQ6.js → canvas-reducers-D-YxAR4B.js} +2 -2
  16. package/dist/chunks/{canvas-reducers-CwFA3rQ6.js.map → canvas-reducers-D-YxAR4B.js.map} +1 -1
  17. package/dist/chunks/canvas-title-slot-context-D6UXrkdJ.js +36 -0
  18. package/dist/chunks/canvas-title-slot-context-D6UXrkdJ.js.map +1 -0
  19. package/dist/chunks/{canvasBodies-C7qqThc9.js → canvasBodies-CQEBkIVw.js} +4 -4
  20. package/dist/chunks/{canvasBodies-C7qqThc9.js.map → canvasBodies-CQEBkIVw.js.map} +1 -1
  21. package/dist/chunks/{canvasStorage-i2wKVSBf.js → canvasStorage-BbEI3h-8.js} +2 -2
  22. package/dist/chunks/{canvasStorage-i2wKVSBf.js.map → canvasStorage-BbEI3h-8.js.map} +1 -1
  23. package/dist/chunks/format-agent-voice-call-duration-C-3hRc9p.js +10 -0
  24. package/dist/chunks/format-agent-voice-call-duration-C-3hRc9p.js.map +1 -0
  25. package/dist/chunks/{link-navigation-CNX8Am2L.js → link-navigation-BUcy5qWW.js} +2 -2
  26. package/dist/chunks/{link-navigation-CNX8Am2L.js.map → link-navigation-BUcy5qWW.js.map} +1 -1
  27. package/dist/chunks/{realtime-arrival-BTLE3jjt.js → realtime-arrival-BfsAPwqQ.js} +8 -3
  28. package/dist/chunks/realtime-arrival-BfsAPwqQ.js.map +1 -0
  29. package/dist/chunks/use-agents-chat-store-CuIkCz9v.js +34 -0
  30. package/dist/chunks/use-agents-chat-store-CuIkCz9v.js.map +1 -0
  31. package/dist/chunks/{widget-name-resolver-BVEuAsW5.js → widget-name-resolver-B9k-s_cF.js} +3 -3
  32. package/dist/chunks/{widget-name-resolver-BVEuAsW5.js.map → widget-name-resolver-B9k-s_cF.js.map} +1 -1
  33. package/dist/chunks/withPollingChangeSubscription-CnQnubfK.js.map +1 -1
  34. package/dist/client-testing.js +4 -4
  35. package/dist/client.js +14 -3
  36. package/dist/client.js.map +1 -1
  37. package/dist/files/i18n-keys.json +1128 -100
  38. package/dist/image-render.js +65 -38
  39. package/dist/image-render.js.map +1 -1
  40. package/dist/index.js +6 -6
  41. package/dist/kit.js +2 -2
  42. package/dist/preview.js +23 -26
  43. package/dist/preview.js.map +1 -1
  44. package/dist/provider.js +1 -1
  45. package/dist/renderer.js +25 -24
  46. package/dist/renderer.js.map +1 -1
  47. package/dist/styles.css +531 -93
  48. package/dist/types/client/AgentsConversationClient.d.ts +4 -1
  49. package/dist/types/client/http/createAgentsHttpConversationClient.d.ts +2 -1
  50. package/dist/types/entries/voice-admin.d.ts +7 -0
  51. package/dist/types/entries/voice.d.ts +24 -0
  52. package/dist/types/image-render/frozen-widget-requests.d.ts +11 -2
  53. package/dist/types/image-render/widget-image-google-map.d.ts +5 -0
  54. package/dist/types/image-render/widget-image-static-assets.d.ts +2 -0
  55. package/dist/types/preview/widget-preview-requests.d.ts +6 -5
  56. package/dist/types/request-interception/browser-request-interception.d.ts +48 -0
  57. package/dist/types/request-interception/intercepted-xml-http-request-upload.d.ts +15 -0
  58. package/dist/types/ui/account-realtime.d.ts +50 -11
  59. package/dist/types/voice/AgentVoiceCallBand/AgentVoiceCallBand.d.ts +49 -0
  60. package/dist/types/voice/AgentVoiceCallBand/agent-voice-call-outcome-title-text-key.d.ts +8 -0
  61. package/dist/types/voice/AgentVoiceCallCaptions/AgentVoiceCallCaptions.d.ts +15 -0
  62. package/dist/types/voice/AgentVoiceCallCaptions/saved-messages-of-agent-voice-chat.d.ts +12 -0
  63. package/dist/types/voice/AgentVoiceCallProvider/AgentVoiceCallProvider.d.ts +21 -0
  64. package/dist/types/voice/AgentVoiceCallProvider/agent-voice-call-context.d.ts +17 -0
  65. package/dist/types/voice/AgentVoiceChatStartButton/AgentVoiceChatStartButton.d.ts +15 -0
  66. package/dist/types/voice/AgentVoiceIcons/AgentVoiceIcons.d.ts +10 -0
  67. package/dist/types/voice/AgentVoiceIncomingCall/AgentVoiceIncomingCall.d.ts +28 -0
  68. package/dist/types/voice/AgentVoiceInputGlow/AgentVoiceInputGlow.d.ts +11 -0
  69. package/dist/types/voice/AgentVoiceInputGlow/agent-voice-input-glow-voice.d.ts +8 -0
  70. package/dist/types/voice/admin/AgentVoiceCallConversationLink/AgentVoiceCallConversationLink.d.ts +10 -0
  71. package/dist/types/voice/admin/AgentVoiceCallDetailScreen/AgentVoiceCallDetailScreen.d.ts +27 -0
  72. package/dist/types/voice/admin/AgentVoiceCallStateBadges/AgentVoiceCallStateBadges.d.ts +12 -0
  73. package/dist/types/voice/admin/AgentVoiceCallsScreen/AgentVoiceCallsScreen.d.ts +33 -0
  74. package/dist/types/voice/admin/agent-voice-admin-api.d.ts +59 -0
  75. package/dist/types/voice/admin/agent-voice-admin-format.d.ts +38 -0
  76. package/dist/types/voice/admin/agent-voice-admin-types.d.ts +110 -0
  77. package/dist/types/voice/agent-voice-api.d.ts +114 -0
  78. package/dist/types/voice/call/agent-voice-call-elapsed-seconds.d.ts +6 -0
  79. package/dist/types/voice/call/agent-voice-call-end-reasons.d.ts +3 -0
  80. package/dist/types/voice/call/agent-voice-call-store.d.ts +111 -0
  81. package/dist/types/voice/call/agent-voice-call-turn.d.ts +4 -0
  82. package/dist/types/voice/call/build-unsaved-agent-voice-call-lines.d.ts +14 -0
  83. package/dist/types/voice/call/format-agent-voice-call-duration.d.ts +2 -0
  84. package/dist/types/voice/call/use-agent-voice-call-elapsed-seconds.d.ts +3 -0
  85. package/dist/types/voice/call/use-agent-voice-call-server-end.d.ts +15 -0
  86. package/dist/types/voice/call/use-agent-voice-call.d.ts +12 -0
  87. package/dist/types/voice/call/use-follow-agent-voice-call-conversation.d.ts +9 -0
  88. package/dist/types/voice/ring/agent-voice-caller-label.d.ts +21 -0
  89. package/dist/types/voice/ring/agent-voice-incoming-ring-list.d.ts +10 -0
  90. package/dist/types/voice/ring/agent-voice-incoming-ring-store.d.ts +47 -0
  91. package/dist/types/voice/ring/agent-voice-ring-source.d.ts +75 -0
  92. package/dist/types/voice/ring/agent-voice-ring.d.ts +35 -0
  93. package/dist/types/voice/ring/answer-incoming-agent-voice-call.d.ts +13 -0
  94. package/dist/types/voice/ring/use-agent-voice-incoming-rings.d.ts +14 -0
  95. package/dist/types/voice/ring/use-agent-voice-ring-tone.d.ts +6 -0
  96. package/dist/ui.js +82 -19
  97. package/dist/ui.js.map +1 -1
  98. package/dist/voice-admin.js +738 -0
  99. package/dist/voice-admin.js.map +1 -0
  100. package/dist/voice.js +1586 -0
  101. package/dist/voice.js.map +1 -0
  102. package/dist/widgets.js +4 -4
  103. package/package.json +23 -4
  104. package/public-api.json +156 -0
  105. package/dist/chunks/ConversationMessageInputComposerWidgets-B3Zf69rD.js.map +0 -1
  106. package/dist/chunks/canvas-title-slot-context-DK4sfhkl.js.map +0 -1
  107. package/dist/chunks/realtime-arrival-BTLE3jjt.js.map +0 -1
  108. package/dist/chunks/widget-image-readiness-signal-C58JkCQA.js +0 -25
  109. package/dist/chunks/widget-image-readiness-signal-C58JkCQA.js.map +0 -1
@@ -0,0 +1,738 @@
1
+ "use client";
2
+ import { trimApiPrefix, toQueryString, injectEndpointsOnce, staticQueryHook } from "@mgamadeus/ddd-admin-ui/logic/pure";
3
+ import { combineFilters, buildFieldFilter } from "@mgamadeus/ddd-web/query";
4
+ import { normalizeDddError } from "@mgamadeus/ddd-web/contract";
5
+ import { Bot, UserRound, Undo2, TimerOff, Ban, BellOff, CircleX, Gauge, CircleCheck, CircleStop, AudioLines, BellRing, RefreshCw, ChevronLeft, ChevronRight, MessagesSquare } from "lucide-react";
6
+ import { m, formatUiNumber, useTranslate } from "@mgamadeus/ddd-admin-ui/i18n";
7
+ import { defineStatusMap, useDebouncedValue } from "@mgamadeus/ddd-admin-ui/logic";
8
+ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
9
+ import { useLinkComponent, Button, cn, Skeleton, Card, CardContent } from "@mgamadeus/ddd-admin-ui/primitives";
10
+ import { StatusBadge, DateCell, EmptyValue, EntityListCard, EntityListBody, EntityListToolbar, FilterPanel, FilterText, FilterDateRange, FilterSelect } from "@mgamadeus/ddd-admin-ui/list";
11
+ import { useState } from "react";
12
+ import { PageHeader, StatusCallout, DefinitionList } from "@mgamadeus/ddd-admin-ui/page";
13
+ import { f as formatAgentVoiceCallDuration } from "./chunks/format-agent-voice-call-duration-C-3hRc9p.js";
14
+ const AGENT_VOICE_CALLS_TAG = "AdminUiAgentVoiceCalls";
15
+ const buildAgentVoiceAdminCallsFilters = (arg) => combineFilters(
16
+ arg.accountId !== void 0 && buildFieldFilter("accountId", arg.accountId, "eq"),
17
+ arg.conversationId !== void 0 && buildFieldFilter("aiConversationId", arg.conversationId, "eq"),
18
+ arg.createdFrom !== void 0 && arg.createdFrom !== "" && buildFieldFilter("created", arg.createdFrom, "ge"),
19
+ arg.createdTo !== void 0 && arg.createdTo !== "" && buildFieldFilter("created", arg.createdTo, "le"),
20
+ arg.bookedSecondsFrom !== void 0 && buildFieldFilter("bookedSeconds", arg.bookedSecondsFrom, "ge"),
21
+ arg.bookedSecondsTo !== void 0 && buildFieldFilter("bookedSeconds", arg.bookedSecondsTo, "le"),
22
+ arg.endReason !== void 0 && arg.endReason !== "" && buildFieldFilter("endReason", arg.endReason, "eq")
23
+ );
24
+ const buildAgentVoiceAdminRequests = (apiPrefix) => {
25
+ const prefix = trimApiPrefix(apiPrefix);
26
+ return {
27
+ calls: (arg = {}) => ({
28
+ url: `${prefix}/calls${toQueryString({ filters: buildAgentVoiceAdminCallsFilters(arg), top: arg.limit, skip: arg.offset })}`
29
+ }),
30
+ call: ({ callId }) => ({
31
+ url: `${prefix}/calls/${encodeURIComponent(String(callId))}`
32
+ })
33
+ };
34
+ };
35
+ const LIST = { type: AGENT_VOICE_CALLS_TAG, id: "LIST" };
36
+ const DETAIL = { type: AGENT_VOICE_CALLS_TAG, id: "DETAIL" };
37
+ const agentVoiceAdminEndpointDefinitions = (apiPrefix) => {
38
+ const requests = buildAgentVoiceAdminRequests(apiPrefix);
39
+ return {
40
+ adminUiAgentVoiceCalls: { kind: "query", request: requests.calls, providesTags: [LIST] },
41
+ adminUiAgentVoiceCall: { kind: "query", request: requests.call, providesTags: [DETAIL] }
42
+ };
43
+ };
44
+ const createAgentVoiceAdminApi = ({ baseApi, apiPrefix }) => injectEndpointsOnce(
45
+ baseApi,
46
+ `agentVoiceCalls:${trimApiPrefix(apiPrefix)}`,
47
+ [AGENT_VOICE_CALLS_TAG],
48
+ agentVoiceAdminEndpointDefinitions(apiPrefix),
49
+ (hookOf) => ({
50
+ useAgentVoiceCallsQuery: hookOf("adminUiAgentVoiceCalls"),
51
+ useAgentVoiceCallQuery: hookOf("adminUiAgentVoiceCall")
52
+ })
53
+ );
54
+ const createStaticAgentVoiceAdminApi = (data) => ({
55
+ useAgentVoiceCallsQuery: staticQueryHook((arg) => data.calls?.(arg ?? {})),
56
+ useAgentVoiceCallQuery: staticQueryHook((arg) => data.call?.(arg))
57
+ });
58
+ const AGENT_VOICE_CALL_STATE = defineStatusMap(
59
+ {
60
+ RINGING: {
61
+ label: m("Ringing", { context: "agent-voice-call-state" }),
62
+ tone: "warning",
63
+ icon: BellRing,
64
+ description: m("Nobody has answered yet", { context: "agent-voice-call-state" })
65
+ },
66
+ IN_PROGRESS: {
67
+ label: m("Running", { context: "agent-voice-call-state" }),
68
+ tone: "success",
69
+ icon: AudioLines,
70
+ description: m("The call was answered and is going on", { context: "agent-voice-call-state" })
71
+ },
72
+ ENDED: {
73
+ label: m("Ended", { context: "agent-voice-call-state" }),
74
+ tone: "neutral",
75
+ icon: CircleStop,
76
+ description: m("The call is over", { context: "agent-voice-call-state" })
77
+ }
78
+ },
79
+ { context: "agent-voice-call-state" }
80
+ );
81
+ const AGENT_VOICE_CALL_END_REASON = defineStatusMap(
82
+ {
83
+ COMPLETED: {
84
+ label: m("Completed", { context: "agent-voice-call-end-reason" }),
85
+ tone: "success",
86
+ icon: CircleCheck,
87
+ description: m("Both sides hung up normally", { context: "agent-voice-call-end-reason" })
88
+ },
89
+ ENDED_BY_AGENT: {
90
+ label: m("Ended by the agent", { context: "agent-voice-call-end-reason" }),
91
+ tone: "info",
92
+ icon: Bot,
93
+ description: m("The agent hung up the running call or withdrew its ring", { context: "agent-voice-call-end-reason" })
94
+ },
95
+ LIMIT_REACHED: {
96
+ label: m("Limit reached", { context: "agent-voice-call-end-reason" }),
97
+ tone: "warning",
98
+ icon: Gauge,
99
+ description: m("The call ran into its time, daily or budget limit", { context: "agent-voice-call-end-reason" })
100
+ },
101
+ FAILED: {
102
+ label: m("Failed", { context: "agent-voice-call-end-reason" }),
103
+ tone: "danger",
104
+ icon: CircleX,
105
+ description: m("The session ended on an error of the provider, the model or the worker", {
106
+ context: "agent-voice-call-end-reason"
107
+ })
108
+ },
109
+ NOT_ANSWERED: {
110
+ label: m("Not answered", { context: "agent-voice-call-end-reason" }),
111
+ tone: "neutral",
112
+ icon: BellOff,
113
+ description: m("Nobody picked up", { context: "agent-voice-call-end-reason" })
114
+ },
115
+ DECLINED: {
116
+ label: m("Declined", { context: "agent-voice-call-end-reason" }),
117
+ tone: "neutral",
118
+ icon: Ban,
119
+ description: m("Every client the call rang on declined it", { context: "agent-voice-call-end-reason" })
120
+ },
121
+ EXPIRED: {
122
+ label: m("Expired", { context: "agent-voice-call-end-reason" }),
123
+ tone: "neutral",
124
+ icon: TimerOff,
125
+ description: m("Nobody answered before the ringing stopped", { context: "agent-voice-call-end-reason" })
126
+ },
127
+ CANCELED: {
128
+ label: m("Canceled", { context: "agent-voice-call-end-reason" }),
129
+ tone: "neutral",
130
+ icon: Undo2,
131
+ description: m("The side that started the call withdrew it before anyone answered", {
132
+ context: "agent-voice-call-end-reason"
133
+ })
134
+ }
135
+ },
136
+ { context: "agent-voice-call-end-reason" }
137
+ );
138
+ const AGENT_VOICE_CALL_END_REASONS = [
139
+ "COMPLETED",
140
+ "ENDED_BY_AGENT",
141
+ "LIMIT_REACHED",
142
+ "FAILED",
143
+ "NOT_ANSWERED",
144
+ "DECLINED",
145
+ "EXPIRED",
146
+ "CANCELED"
147
+ ];
148
+ const AGENT_VOICE_CALL_DIRECTION = defineStatusMap(
149
+ {
150
+ INBOUND: {
151
+ label: m("The owner called", { context: "agent-voice-call-direction" }),
152
+ tone: "neutral",
153
+ icon: UserRound,
154
+ description: m("The owner started a voice chat with the agent", { context: "agent-voice-call-direction" })
155
+ },
156
+ OUTBOUND: {
157
+ label: m("The agent rang", { context: "agent-voice-call-direction" }),
158
+ tone: "neutral",
159
+ icon: Bot,
160
+ description: m("The agent rang the owner’s open clients", { context: "agent-voice-call-direction" })
161
+ }
162
+ },
163
+ { context: "agent-voice-call-direction" }
164
+ );
165
+ const momentOf = (dateTime) => {
166
+ if (!dateTime) return null;
167
+ const moment = Date.parse(`${dateTime.trim().replace(" ", "T")}Z`);
168
+ return Number.isNaN(moment) ? null : moment;
169
+ };
170
+ const agentVoiceAdminCallStartTimeOf = (call) => call.changeHistory?.createdTime ?? call.startedAt ?? null;
171
+ const agentVoiceAdminCallDurationInSecondsOf = (call) => {
172
+ const startedAt = momentOf(call.startedAt);
173
+ const endedAt = momentOf(call.endedAt);
174
+ if (startedAt === null || endedAt === null) return null;
175
+ return Math.max(0, Math.round((endedAt - startedAt) / 1e3));
176
+ };
177
+ const agentVoiceAdminCallDerivedValuesByCallIdOf = (agentVoiceCallDerivedValues) => {
178
+ const derivedValuesByCallId = /* @__PURE__ */ new Map();
179
+ for (const derivedValuesOfCall of agentVoiceCallDerivedValues ?? [])
180
+ derivedValuesByCallId.set(derivedValuesOfCall.callId, derivedValuesOfCall);
181
+ return derivedValuesByCallId;
182
+ };
183
+ const CALL_COSTS_FRACTION_DIGITS = { minimumFractionDigits: 2, maximumFractionDigits: 4 };
184
+ const formatAgentVoiceAdminCallCosts = (bookedCosts) => {
185
+ try {
186
+ return formatUiNumber(bookedCosts.amount, {
187
+ style: "currency",
188
+ currency: bookedCosts.currency.isoCode,
189
+ ...CALL_COSTS_FRACTION_DIGITS
190
+ });
191
+ } catch {
192
+ return `${formatUiNumber(bookedCosts.amount, CALL_COSTS_FRACTION_DIGITS)} ${bookedCosts.currency.isoCode}`;
193
+ }
194
+ };
195
+ const DAY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
196
+ const toUtcDateTime = (moment) => moment.toISOString().slice(0, 19).replace("T", " ");
197
+ const toAgentVoiceAdminDayBound = (day, isEndOfDay) => {
198
+ const dayParts = DAY_PATTERN.exec(day.trim());
199
+ if (!dayParts) return void 0;
200
+ const [year, month, dayOfMonth] = [Number(dayParts[1]), Number(dayParts[2]), Number(dayParts[3])];
201
+ const moment = isEndOfDay ? new Date(year, month - 1, dayOfMonth, 23, 59, 59) : new Date(year, month - 1, dayOfMonth, 0, 0, 0);
202
+ if (moment.getFullYear() !== year || moment.getMonth() !== month - 1 || moment.getDate() !== dayOfMonth) return void 0;
203
+ return toUtcDateTime(moment);
204
+ };
205
+ const readAgentVoiceAdminWholeNumber = (text) => {
206
+ const trimmedText = text.trim();
207
+ return /^\d{1,15}$/.test(trimmedText) ? Number(trimmedText) : void 0;
208
+ };
209
+ const AGENT_VOICE_ADMIN_ERROR_FEATURE_NOT_AVAILABLE = "feature_not_available";
210
+ const AGENT_VOICE_ADMIN_ERROR_CALL_NOT_FOUND = "call_not_found";
211
+ const isAgentVoiceAdminError = (error, errorCode) => {
212
+ if (error === void 0 || error === null) return false;
213
+ const normalizedError = normalizeDddError(error);
214
+ const errorBody = typeof normalizedError.body === "object" && normalizedError.body !== null ? normalizedError.body : {};
215
+ return [errorBody.errorEnglish, errorBody.error, normalizedError.message].includes(errorCode);
216
+ };
217
+ const AgentVoiceCallConversationLink = ({ conversationId, href, linkComponent }) => {
218
+ const Link = useLinkComponent(linkComponent);
219
+ if (!href) return /* @__PURE__ */ jsxs("span", { className: "font-mono text-xs", children: [
220
+ "#",
221
+ conversationId
222
+ ] });
223
+ return /* @__PURE__ */ jsxs(Link, { href, className: "font-mono text-xs underline-offset-2 hover:underline", children: [
224
+ "#",
225
+ conversationId
226
+ ] });
227
+ };
228
+ const AgentVoiceCallStateBadges = ({ callState, endReason }) => /* @__PURE__ */ jsxs("span", { className: "flex flex-wrap items-center gap-1.5", children: [
229
+ /* @__PURE__ */ jsx(StatusBadge, { value: callState, map: AGENT_VOICE_CALL_STATE }),
230
+ endReason ? /* @__PURE__ */ jsx(StatusBadge, { value: endReason, map: AGENT_VOICE_CALL_END_REASON }) : null
231
+ ] });
232
+ const AGENT_VOICE_CALLS_MAX_PAGE_SIZE = 200;
233
+ const NO_FILTER_VALUES = {
234
+ accountIdText: "",
235
+ createdFromDay: "",
236
+ createdToDay: "",
237
+ bookedSecondsFromText: "",
238
+ endReason: ""
239
+ };
240
+ const digitsOf = (text) => text.replace(/\D/g, "");
241
+ const AgentVoiceCallsScreen = ({
242
+ api,
243
+ title,
244
+ description,
245
+ headerActions,
246
+ onOpenCall,
247
+ accountId,
248
+ conversationId,
249
+ buildConversationHref,
250
+ linkComponent,
251
+ pageSize = 50
252
+ }) => {
253
+ const { t } = useTranslate();
254
+ const [filterValues, setFilterValues] = useState(NO_FILTER_VALUES);
255
+ const [offset, setOffset] = useState(0);
256
+ const debouncedAccountIdText = useDebouncedValue(filterValues.accountIdText);
257
+ const debouncedBookedSecondsFromText = useDebouncedValue(filterValues.bookedSecondsFromText);
258
+ const callsPerPage = Math.min(Math.max(Math.floor(pageSize), 1), AGENT_VOICE_CALLS_MAX_PAGE_SIZE);
259
+ const isAccountFilterShown = accountId === void 0;
260
+ const listQuery = api.useAgentVoiceCallsQuery({
261
+ accountId: accountId ?? readAgentVoiceAdminWholeNumber(debouncedAccountIdText),
262
+ conversationId,
263
+ createdFrom: toAgentVoiceAdminDayBound(filterValues.createdFromDay, false),
264
+ createdTo: toAgentVoiceAdminDayBound(filterValues.createdToDay, true),
265
+ bookedSecondsFrom: readAgentVoiceAdminWholeNumber(debouncedBookedSecondsFromText),
266
+ endReason: filterValues.endReason === "" ? void 0 : filterValues.endReason,
267
+ limit: callsPerPage + 1,
268
+ offset
269
+ });
270
+ const loadedCalls = listQuery.data?.agentVoiceCalls?.elements ?? [];
271
+ const calls = loadedCalls.slice(0, callsPerPage);
272
+ const hasOlderCalls = loadedCalls.length > callsPerPage;
273
+ const derivedValuesByCallId = agentVoiceAdminCallDerivedValuesByCallIdOf(listQuery.data?.agentVoiceCallDerivedValues);
274
+ const isVoiceSwitchedOff = listQuery.isError && isAgentVoiceAdminError(listQuery.error, AGENT_VOICE_ADMIN_ERROR_FEATURE_NOT_AVAILABLE);
275
+ const changeFilterValues = (changedFilterValues) => {
276
+ setFilterValues((currentFilterValues) => ({ ...currentFilterValues, ...changedFilterValues }));
277
+ setOffset(0);
278
+ };
279
+ const activeFilterCount = [
280
+ isAccountFilterShown && filterValues.accountIdText !== "",
281
+ filterValues.createdFromDay !== "" || filterValues.createdToDay !== "",
282
+ filterValues.bookedSecondsFromText !== "",
283
+ filterValues.endReason !== ""
284
+ ].filter(Boolean).length;
285
+ const clearFilters = () => changeFilterValues(NO_FILTER_VALUES);
286
+ const columns = [
287
+ {
288
+ id: "started",
289
+ header: t("Started", { context: "agent-voice-call" }),
290
+ width: "content",
291
+ cell: (call) => /* @__PURE__ */ jsx(DateCell, { value: agentVoiceAdminCallStartTimeOf(call) })
292
+ },
293
+ {
294
+ id: "account",
295
+ header: t("Account", { context: "agent-voice-call" }),
296
+ width: "content",
297
+ cell: (call) => call.accountId ? /* @__PURE__ */ jsxs("span", { className: "font-mono text-xs", children: [
298
+ "#",
299
+ call.accountId
300
+ ] }) : /* @__PURE__ */ jsx(EmptyValue, {})
301
+ },
302
+ {
303
+ id: "direction",
304
+ header: t("Started by", { context: "agent-voice-call" }),
305
+ width: "content",
306
+ cell: (call) => /* @__PURE__ */ jsx(StatusBadge, { value: call.direction, map: AGENT_VOICE_CALL_DIRECTION })
307
+ },
308
+ {
309
+ id: "state",
310
+ header: t("State", { context: "agent-voice-call" }),
311
+ width: "content",
312
+ cell: (call) => /* @__PURE__ */ jsx(AgentVoiceCallStateBadges, { callState: derivedValuesByCallId.get(call.id)?.callState, endReason: call.endReason })
313
+ },
314
+ {
315
+ id: "duration",
316
+ header: t("Duration", { context: "agent-voice-call" }),
317
+ width: "content",
318
+ align: "end",
319
+ cell: (call) => {
320
+ const durationInSeconds = agentVoiceAdminCallDurationInSecondsOf(call);
321
+ return durationInSeconds === null ? /* @__PURE__ */ jsx(EmptyValue, {}) : /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: formatAgentVoiceCallDuration(durationInSeconds) });
322
+ }
323
+ },
324
+ {
325
+ id: "bookedSeconds",
326
+ header: t("Booked seconds", { context: "agent-voice-call" }),
327
+ width: "content",
328
+ align: "end",
329
+ cell: (call) => /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: formatUiNumber(call.bookedSeconds ?? 0) })
330
+ },
331
+ {
332
+ id: "costs",
333
+ header: t("Costs", { context: "agent-voice-call" }),
334
+ width: "content",
335
+ align: "end",
336
+ cell: (call) => {
337
+ const bookedCosts = derivedValuesByCallId.get(call.id)?.bookedCosts;
338
+ return bookedCosts ? /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: formatAgentVoiceAdminCallCosts(bookedCosts) }) : /* @__PURE__ */ jsx(EmptyValue, {});
339
+ }
340
+ },
341
+ {
342
+ id: "task",
343
+ header: t("Task", { context: "agent-voice-call" }),
344
+ width: "2fr",
345
+ cell: (call) => call.callTask ? /* @__PURE__ */ jsx("span", { className: "block truncate", title: call.callTask, children: call.callTask }) : /* @__PURE__ */ jsx(EmptyValue, {})
346
+ },
347
+ {
348
+ id: "conversation",
349
+ header: t("Conversation", { context: "agent-voice-call" }),
350
+ width: "content",
351
+ cell: (call) => {
352
+ if (!call.aiConversationId) return /* @__PURE__ */ jsx(EmptyValue, {});
353
+ const conversationHref = buildConversationHref?.(call.aiConversationId) ?? null;
354
+ return /* @__PURE__ */ jsx("span", { "data-row-action-ignore": true, children: /* @__PURE__ */ jsx(
355
+ AgentVoiceCallConversationLink,
356
+ {
357
+ conversationId: call.aiConversationId,
358
+ href: conversationHref,
359
+ linkComponent
360
+ }
361
+ ) });
362
+ }
363
+ }
364
+ ];
365
+ const endReasonOptions = AGENT_VOICE_CALL_END_REASONS.map((endReason) => ({
366
+ value: endReason,
367
+ label: t(AGENT_VOICE_CALL_END_REASON[endReason].label, { context: AGENT_VOICE_CALL_END_REASON[endReason].context })
368
+ }));
369
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-6", "data-testid": "agent-voice-calls-screen", children: [
370
+ /* @__PURE__ */ jsx(
371
+ PageHeader,
372
+ {
373
+ title: title ?? t("Voice calls"),
374
+ description: description ?? t("The voice chats the owners started with the agent and the calls the agent rang them with, newest first."),
375
+ actions: /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
376
+ headerActions,
377
+ /* @__PURE__ */ jsxs(
378
+ Button,
379
+ {
380
+ type: "button",
381
+ variant: "outline",
382
+ "data-testid": "agent-voice-calls-refresh",
383
+ onClick: () => void listQuery.refetch?.(),
384
+ disabled: listQuery.isFetching,
385
+ children: [
386
+ /* @__PURE__ */ jsx(RefreshCw, { className: cn(listQuery.isFetching && "animate-spin") }),
387
+ t("Refresh")
388
+ ]
389
+ }
390
+ )
391
+ ] })
392
+ }
393
+ ),
394
+ isVoiceSwitchedOff ? /* @__PURE__ */ jsx("div", { "data-testid": "agent-voice-calls-switched-off", children: /* @__PURE__ */ jsx(
395
+ StatusCallout,
396
+ {
397
+ tone: "info",
398
+ title: t("Voice is switched off"),
399
+ description: t("The voice channel is switched off in this application, so its calls are not listed.")
400
+ }
401
+ ) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
402
+ /* @__PURE__ */ jsx(
403
+ EntityListCard,
404
+ {
405
+ label: m("Voice calls"),
406
+ isRefetching: listQuery.isFetching && !listQuery.isLoading,
407
+ toolbar: /* @__PURE__ */ jsx(
408
+ EntityListToolbar,
409
+ {
410
+ activeFilterCount,
411
+ onClearFilters: clearFilters,
412
+ filters: /* @__PURE__ */ jsxs(FilterPanel, { children: [
413
+ isAccountFilterShown && /* @__PURE__ */ jsx(
414
+ FilterText,
415
+ {
416
+ label: t("Account", { context: "agent-voice-call-filter" }),
417
+ placeholder: t("Account ID", { context: "agent-voice-call-filter" }),
418
+ inputMode: "numeric",
419
+ value: filterValues.accountIdText,
420
+ onChange: (accountIdText) => changeFilterValues({ accountIdText: digitsOf(accountIdText) })
421
+ }
422
+ ),
423
+ /* @__PURE__ */ jsx(
424
+ FilterDateRange,
425
+ {
426
+ label: t("Created", { context: "agent-voice-call-filter" }),
427
+ from: filterValues.createdFromDay,
428
+ to: filterValues.createdToDay,
429
+ onFromChange: (createdFromDay) => changeFilterValues({ createdFromDay }),
430
+ onToChange: (createdToDay) => changeFilterValues({ createdToDay })
431
+ }
432
+ ),
433
+ /* @__PURE__ */ jsx(
434
+ FilterText,
435
+ {
436
+ label: t("Booked seconds, at least", { context: "agent-voice-call-filter" }),
437
+ placeholder: t("Seconds", { context: "agent-voice-call-filter" }),
438
+ inputMode: "numeric",
439
+ value: filterValues.bookedSecondsFromText,
440
+ onChange: (bookedSecondsFromText) => changeFilterValues({ bookedSecondsFromText: digitsOf(bookedSecondsFromText) })
441
+ }
442
+ ),
443
+ /* @__PURE__ */ jsx(
444
+ FilterSelect,
445
+ {
446
+ label: t("End reason", { context: "agent-voice-call-filter" }),
447
+ allLabel: t("All", { context: "agent-voice-call-filter" }),
448
+ options: endReasonOptions,
449
+ value: filterValues.endReason,
450
+ onChange: (endReason) => changeFilterValues({ endReason })
451
+ }
452
+ )
453
+ ] })
454
+ }
455
+ ),
456
+ children: /* @__PURE__ */ jsx(
457
+ EntityListBody,
458
+ {
459
+ displayMode: "table",
460
+ columns,
461
+ items: calls,
462
+ getRowKey: (call) => String(call.id),
463
+ rowAction: onOpenCall ? (call) => () => onOpenCall(call.id) : void 0,
464
+ isLoading: listQuery.isLoading,
465
+ emptyMessage: t("No voice call yet: a call starts when an owner opens a voice chat or the agent rings."),
466
+ noResultsMessage: t("No voice call matches these filters."),
467
+ isSearchActive: activeFilterCount > 0,
468
+ onClearSearch: clearFilters,
469
+ loadingMessage: t("Loading the voice calls"),
470
+ error: listQuery.isError ? normalizeDddError(listQuery.error, t("The voice calls could not be loaded.")).message : void 0
471
+ }
472
+ )
473
+ }
474
+ ),
475
+ (offset > 0 || hasOlderCalls) && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-2", children: [
476
+ /* @__PURE__ */ jsxs(
477
+ Button,
478
+ {
479
+ type: "button",
480
+ variant: "outline",
481
+ size: "sm",
482
+ "data-testid": "agent-voice-calls-newer",
483
+ disabled: offset === 0 || listQuery.isFetching,
484
+ onClick: () => setOffset(Math.max(0, offset - callsPerPage)),
485
+ children: [
486
+ /* @__PURE__ */ jsx(ChevronLeft, {}),
487
+ t("Newer", { context: "agent-voice-pagination" })
488
+ ]
489
+ }
490
+ ),
491
+ /* @__PURE__ */ jsxs(
492
+ Button,
493
+ {
494
+ type: "button",
495
+ variant: "outline",
496
+ size: "sm",
497
+ "data-testid": "agent-voice-calls-older",
498
+ disabled: !hasOlderCalls || listQuery.isFetching,
499
+ onClick: () => setOffset(offset + callsPerPage),
500
+ children: [
501
+ t("Older", { context: "agent-voice-pagination" }),
502
+ /* @__PURE__ */ jsx(ChevronRight, {})
503
+ ]
504
+ }
505
+ )
506
+ ] })
507
+ ] })
508
+ ] });
509
+ };
510
+ const AgentVoiceCallDetailScreen = ({
511
+ api,
512
+ callId,
513
+ backLink,
514
+ headerActions,
515
+ buildConversationHref,
516
+ linkComponent
517
+ }) => {
518
+ const { t } = useTranslate();
519
+ const Link = useLinkComponent(linkComponent);
520
+ const callQuery = api.useAgentVoiceCallQuery({ callId });
521
+ const callResponse = callQuery.data;
522
+ const call = callResponse?.agentVoiceCall;
523
+ if (callQuery.isLoading) {
524
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
525
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-12 w-80" }),
526
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-32 w-full rounded-2xl" })
527
+ ] });
528
+ }
529
+ if (callQuery.isError && isAgentVoiceAdminError(callQuery.error, AGENT_VOICE_ADMIN_ERROR_FEATURE_NOT_AVAILABLE)) {
530
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-4", "data-testid": "agent-voice-call-switched-off", children: [
531
+ /* @__PURE__ */ jsx(PageHeader, { title: `#${callId}`, leading: backLink }),
532
+ /* @__PURE__ */ jsx(
533
+ StatusCallout,
534
+ {
535
+ tone: "info",
536
+ title: t("Voice is switched off"),
537
+ description: t("The voice channel is switched off in this application, so its calls cannot be read.")
538
+ }
539
+ )
540
+ ] });
541
+ }
542
+ if (!callResponse || !call) {
543
+ const isCallNotFound = !callQuery.isError || isAgentVoiceAdminError(callQuery.error, AGENT_VOICE_ADMIN_ERROR_CALL_NOT_FOUND);
544
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-4", "data-testid": "agent-voice-call-not-shown", children: [
545
+ /* @__PURE__ */ jsx(PageHeader, { title: `#${callId}`, leading: backLink }),
546
+ isCallNotFound ? /* @__PURE__ */ jsx(
547
+ StatusCallout,
548
+ {
549
+ tone: "destructive",
550
+ title: t("This voice call was not found."),
551
+ description: t("It does not exist, or it belongs to an account you may not read.")
552
+ }
553
+ ) : /* @__PURE__ */ jsx(
554
+ StatusCallout,
555
+ {
556
+ tone: "destructive",
557
+ title: t("The voice call could not be loaded."),
558
+ description: normalizeDddError(callQuery.error, "").message
559
+ }
560
+ )
561
+ ] });
562
+ }
563
+ const conversationId = callResponse.conversationId ?? call.aiConversationId ?? null;
564
+ const conversationHref = conversationId ? buildConversationHref?.(conversationId) ?? null : null;
565
+ const startedByAgentInConversationHref = call.startedByAgentInConversationId ? buildConversationHref?.(call.startedByAgentInConversationId) ?? null : null;
566
+ const bookedSeconds = callResponse.bookedSeconds ?? call.bookedSeconds ?? 0;
567
+ const bookedCosts = callResponse.bookedCosts ?? null;
568
+ const durationInSeconds = callResponse.durationInSeconds ?? null;
569
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-6", "data-testid": "agent-voice-call-detail-screen", children: [
570
+ /* @__PURE__ */ jsx(
571
+ PageHeader,
572
+ {
573
+ leading: backLink,
574
+ title: t("Voice call"),
575
+ description: /* @__PURE__ */ jsxs("span", { className: "font-mono text-xs", children: [
576
+ "#",
577
+ call.id
578
+ ] }),
579
+ actions: /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
580
+ headerActions,
581
+ /* @__PURE__ */ jsxs(
582
+ Button,
583
+ {
584
+ type: "button",
585
+ variant: "outline",
586
+ "data-testid": "agent-voice-call-refresh",
587
+ onClick: () => void callQuery.refetch?.(),
588
+ disabled: callQuery.isFetching,
589
+ children: [
590
+ /* @__PURE__ */ jsx(RefreshCw, { className: cn(callQuery.isFetching && "animate-spin") }),
591
+ t("Refresh")
592
+ ]
593
+ }
594
+ ),
595
+ conversationHref && /* @__PURE__ */ jsx(Button, { asChild: true, variant: "outline", "data-testid": "agent-voice-call-open-conversation", children: /* @__PURE__ */ jsxs(Link, { href: conversationHref, children: [
596
+ /* @__PURE__ */ jsx(MessagesSquare, {}),
597
+ t("Open the conversation", { context: "agent-voice-call" })
598
+ ] }) })
599
+ ] })
600
+ }
601
+ ),
602
+ /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, { className: "pt-6", children: /* @__PURE__ */ jsx(
603
+ DefinitionList,
604
+ {
605
+ items: [
606
+ {
607
+ id: "state",
608
+ label: t("State", { context: "agent-voice-call" }),
609
+ value: /* @__PURE__ */ jsx(
610
+ AgentVoiceCallStateBadges,
611
+ {
612
+ callState: callResponse.callState,
613
+ endReason: callResponse.endReason ?? call.endReason
614
+ }
615
+ )
616
+ },
617
+ {
618
+ id: "direction",
619
+ label: t("Started by", { context: "agent-voice-call" }),
620
+ value: /* @__PURE__ */ jsx(StatusBadge, { value: call.direction, map: AGENT_VOICE_CALL_DIRECTION })
621
+ },
622
+ {
623
+ id: "account",
624
+ label: t("Account", { context: "agent-voice-call" }),
625
+ value: call.accountId ? /* @__PURE__ */ jsxs("span", { className: "font-mono text-xs", children: [
626
+ "#",
627
+ call.accountId
628
+ ] }) : null
629
+ },
630
+ {
631
+ id: "conversation",
632
+ label: t("Conversation", { context: "agent-voice-call" }),
633
+ value: conversationId ? /* @__PURE__ */ jsx(
634
+ AgentVoiceCallConversationLink,
635
+ {
636
+ conversationId,
637
+ href: conversationHref,
638
+ linkComponent
639
+ }
640
+ ) : null,
641
+ hint: conversationId ? t("Its messages are what was said in the call.") : void 0
642
+ },
643
+ {
644
+ id: "startedByAgentInConversation",
645
+ label: t("Started by the agent in conversation", { context: "agent-voice-call" }),
646
+ value: call.startedByAgentInConversationId ? /* @__PURE__ */ jsx(
647
+ AgentVoiceCallConversationLink,
648
+ {
649
+ conversationId: call.startedByAgentInConversationId,
650
+ href: startedByAgentInConversationHref,
651
+ linkComponent
652
+ }
653
+ ) : null
654
+ },
655
+ {
656
+ id: "created",
657
+ label: t("Created", { context: "agent-voice-call" }),
658
+ value: call.changeHistory?.createdTime ? /* @__PURE__ */ jsx(DateCell, { value: call.changeHistory.createdTime }) : null
659
+ },
660
+ {
661
+ id: "answered",
662
+ label: t("Answered", { context: "agent-voice-call" }),
663
+ value: call.startedAt ? /* @__PURE__ */ jsx(DateCell, { value: call.startedAt }) : null
664
+ },
665
+ {
666
+ id: "ended",
667
+ label: t("Ended", { context: "agent-voice-call" }),
668
+ value: call.endedAt ? /* @__PURE__ */ jsx(DateCell, { value: call.endedAt }) : null
669
+ },
670
+ {
671
+ id: "ringDeadline",
672
+ label: t("Rings until", { context: "agent-voice-call" }),
673
+ value: call.ringDeadlineAt ? /* @__PURE__ */ jsx(DateCell, { value: call.ringDeadlineAt }) : null
674
+ },
675
+ {
676
+ id: "duration",
677
+ label: t("Duration", { context: "agent-voice-call" }),
678
+ value: durationInSeconds === null ? null : /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: formatAgentVoiceCallDuration(durationInSeconds) })
679
+ },
680
+ {
681
+ id: "bookedSeconds",
682
+ label: t("Booked seconds", { context: "agent-voice-call" }),
683
+ value: /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: formatUiNumber(bookedSeconds) })
684
+ },
685
+ {
686
+ id: "costs",
687
+ label: t("Costs", { context: "agent-voice-call" }),
688
+ value: bookedCosts ? /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: formatAgentVoiceAdminCallCosts(bookedCosts) }) : null,
689
+ hint: !bookedCosts && bookedSeconds > 0 ? t("No price is known for the model this call ran on.") : void 0
690
+ },
691
+ {
692
+ id: "voiceProvider",
693
+ label: t("Voice provider", { context: "agent-voice-call" }),
694
+ value: call.voiceProvider ? /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: call.voiceProvider }) : null
695
+ },
696
+ {
697
+ id: "providerCallId",
698
+ label: t("Provider call ID", { context: "agent-voice-call" }),
699
+ value: call.providerCallId ? /* @__PURE__ */ jsx("span", { className: "break-all font-mono text-xs", children: call.providerCallId }) : null
700
+ },
701
+ {
702
+ id: "task",
703
+ label: t("Task", { context: "agent-voice-call" }),
704
+ wide: true,
705
+ value: call.callTask ? /* @__PURE__ */ jsx("p", { className: "break-words whitespace-pre-wrap", children: call.callTask }) : null
706
+ }
707
+ ]
708
+ }
709
+ ) }) })
710
+ ] });
711
+ };
712
+ export {
713
+ AGENT_VOICE_ADMIN_ERROR_CALL_NOT_FOUND,
714
+ AGENT_VOICE_ADMIN_ERROR_FEATURE_NOT_AVAILABLE,
715
+ AGENT_VOICE_CALLS_MAX_PAGE_SIZE,
716
+ AGENT_VOICE_CALLS_TAG,
717
+ AGENT_VOICE_CALL_DIRECTION,
718
+ AGENT_VOICE_CALL_END_REASON,
719
+ AGENT_VOICE_CALL_END_REASONS,
720
+ AGENT_VOICE_CALL_STATE,
721
+ AgentVoiceCallConversationLink,
722
+ AgentVoiceCallDetailScreen,
723
+ AgentVoiceCallStateBadges,
724
+ AgentVoiceCallsScreen,
725
+ agentVoiceAdminCallDerivedValuesByCallIdOf,
726
+ agentVoiceAdminCallDurationInSecondsOf,
727
+ agentVoiceAdminCallStartTimeOf,
728
+ agentVoiceAdminEndpointDefinitions,
729
+ buildAgentVoiceAdminCallsFilters,
730
+ buildAgentVoiceAdminRequests,
731
+ createAgentVoiceAdminApi,
732
+ createStaticAgentVoiceAdminApi,
733
+ formatAgentVoiceAdminCallCosts,
734
+ isAgentVoiceAdminError,
735
+ readAgentVoiceAdminWholeNumber,
736
+ toAgentVoiceAdminDayBound
737
+ };
738
+ //# sourceMappingURL=voice-admin.js.map