@mgamadeus/ddd-agents 0.5.17 → 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 (99) hide show
  1. package/README.md +164 -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-BdKjYz31.js → browser-request-interception-BnzFbH0m.js} +2 -2
  14. package/dist/chunks/{browser-request-interception-BdKjYz31.js.map → browser-request-interception-BnzFbH0m.js.map} +1 -1
  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 +7 -7
  39. package/dist/index.js +6 -6
  40. package/dist/kit.js +2 -2
  41. package/dist/preview.js +7 -7
  42. package/dist/provider.js +1 -1
  43. package/dist/renderer.js +25 -24
  44. package/dist/renderer.js.map +1 -1
  45. package/dist/styles.css +531 -93
  46. package/dist/types/client/AgentsConversationClient.d.ts +4 -1
  47. package/dist/types/client/http/createAgentsHttpConversationClient.d.ts +2 -1
  48. package/dist/types/entries/voice-admin.d.ts +7 -0
  49. package/dist/types/entries/voice.d.ts +24 -0
  50. package/dist/types/ui/account-realtime.d.ts +50 -11
  51. package/dist/types/voice/AgentVoiceCallBand/AgentVoiceCallBand.d.ts +49 -0
  52. package/dist/types/voice/AgentVoiceCallBand/agent-voice-call-outcome-title-text-key.d.ts +8 -0
  53. package/dist/types/voice/AgentVoiceCallCaptions/AgentVoiceCallCaptions.d.ts +15 -0
  54. package/dist/types/voice/AgentVoiceCallCaptions/saved-messages-of-agent-voice-chat.d.ts +12 -0
  55. package/dist/types/voice/AgentVoiceCallProvider/AgentVoiceCallProvider.d.ts +21 -0
  56. package/dist/types/voice/AgentVoiceCallProvider/agent-voice-call-context.d.ts +17 -0
  57. package/dist/types/voice/AgentVoiceChatStartButton/AgentVoiceChatStartButton.d.ts +15 -0
  58. package/dist/types/voice/AgentVoiceIcons/AgentVoiceIcons.d.ts +10 -0
  59. package/dist/types/voice/AgentVoiceIncomingCall/AgentVoiceIncomingCall.d.ts +28 -0
  60. package/dist/types/voice/AgentVoiceInputGlow/AgentVoiceInputGlow.d.ts +11 -0
  61. package/dist/types/voice/AgentVoiceInputGlow/agent-voice-input-glow-voice.d.ts +8 -0
  62. package/dist/types/voice/admin/AgentVoiceCallConversationLink/AgentVoiceCallConversationLink.d.ts +10 -0
  63. package/dist/types/voice/admin/AgentVoiceCallDetailScreen/AgentVoiceCallDetailScreen.d.ts +27 -0
  64. package/dist/types/voice/admin/AgentVoiceCallStateBadges/AgentVoiceCallStateBadges.d.ts +12 -0
  65. package/dist/types/voice/admin/AgentVoiceCallsScreen/AgentVoiceCallsScreen.d.ts +33 -0
  66. package/dist/types/voice/admin/agent-voice-admin-api.d.ts +59 -0
  67. package/dist/types/voice/admin/agent-voice-admin-format.d.ts +38 -0
  68. package/dist/types/voice/admin/agent-voice-admin-types.d.ts +110 -0
  69. package/dist/types/voice/agent-voice-api.d.ts +114 -0
  70. package/dist/types/voice/call/agent-voice-call-elapsed-seconds.d.ts +6 -0
  71. package/dist/types/voice/call/agent-voice-call-end-reasons.d.ts +3 -0
  72. package/dist/types/voice/call/agent-voice-call-store.d.ts +111 -0
  73. package/dist/types/voice/call/agent-voice-call-turn.d.ts +4 -0
  74. package/dist/types/voice/call/build-unsaved-agent-voice-call-lines.d.ts +14 -0
  75. package/dist/types/voice/call/format-agent-voice-call-duration.d.ts +2 -0
  76. package/dist/types/voice/call/use-agent-voice-call-elapsed-seconds.d.ts +3 -0
  77. package/dist/types/voice/call/use-agent-voice-call-server-end.d.ts +15 -0
  78. package/dist/types/voice/call/use-agent-voice-call.d.ts +12 -0
  79. package/dist/types/voice/call/use-follow-agent-voice-call-conversation.d.ts +9 -0
  80. package/dist/types/voice/ring/agent-voice-caller-label.d.ts +21 -0
  81. package/dist/types/voice/ring/agent-voice-incoming-ring-list.d.ts +10 -0
  82. package/dist/types/voice/ring/agent-voice-incoming-ring-store.d.ts +47 -0
  83. package/dist/types/voice/ring/agent-voice-ring-source.d.ts +75 -0
  84. package/dist/types/voice/ring/agent-voice-ring.d.ts +35 -0
  85. package/dist/types/voice/ring/answer-incoming-agent-voice-call.d.ts +13 -0
  86. package/dist/types/voice/ring/use-agent-voice-incoming-rings.d.ts +14 -0
  87. package/dist/types/voice/ring/use-agent-voice-ring-tone.d.ts +6 -0
  88. package/dist/ui.js +82 -19
  89. package/dist/ui.js.map +1 -1
  90. package/dist/voice-admin.js +738 -0
  91. package/dist/voice-admin.js.map +1 -0
  92. package/dist/voice.js +1586 -0
  93. package/dist/voice.js.map +1 -0
  94. package/dist/widgets.js +4 -4
  95. package/package.json +27 -1
  96. package/public-api.json +156 -0
  97. package/dist/chunks/ConversationMessageInputComposerWidgets-B3Zf69rD.js.map +0 -1
  98. package/dist/chunks/canvas-title-slot-context-DK4sfhkl.js.map +0 -1
  99. package/dist/chunks/realtime-arrival-BTLE3jjt.js.map +0 -1
@@ -0,0 +1,114 @@
1
+ /**
2
+ * The adapter the application passes to `AgentVoiceCallProvider`, so the voice chat depends on no generated client:
3
+ * one function per voice route of `AgentVoiceSessionsTrait` (`open`, `hangUp`, `deviceStatus`, the call state read,
4
+ * `answer`, `decline`). Every function rejects with something `readAgentVoiceErrorCode` finds the route's error code in.
5
+ */
6
+ export interface AgentVoiceApi {
7
+ openSession(args: {
8
+ agentSpaceId?: number;
9
+ sdpOffer: string;
10
+ conversationId?: number;
11
+ callId?: number;
12
+ }): Promise<{
13
+ callId: number;
14
+ sdpAnswer: string;
15
+ conversationId: number;
16
+ }>;
17
+ hangUp(args: {
18
+ callId: number;
19
+ reason?: string;
20
+ }): Promise<void>;
21
+ reportDeviceStatus(args: {
22
+ callId: number;
23
+ status: string;
24
+ iceCandidateType?: string;
25
+ roundTripTimeMs?: number;
26
+ detail?: string;
27
+ occurredAtUnixMs?: number;
28
+ }): Promise<void>;
29
+ readCallState(args: {
30
+ callId: number;
31
+ }): Promise<{
32
+ callId: number;
33
+ endedAt?: string;
34
+ endReason?: string;
35
+ }>;
36
+ answerRing(args: {
37
+ callId: number;
38
+ answerToken: string;
39
+ }): Promise<{
40
+ won: boolean;
41
+ conversationId?: number;
42
+ }>;
43
+ declineRing(args: {
44
+ callId: number;
45
+ answerToken: string;
46
+ }): Promise<void>;
47
+ }
48
+ /** A refused or broken request of the voice routes; `code` is the route's error code (`call_already_running`, …). */
49
+ export declare class AgentVoiceApiError extends Error {
50
+ readonly code: string;
51
+ readonly httpStatus: number | undefined;
52
+ constructor(code: string, httpStatus?: number);
53
+ }
54
+ /**
55
+ * The error code of a rejected adapter call. The voice routes answer the code as the error message, so it is read
56
+ * where the common request layers put it: `error` (the JSON error body itself), `data.error` (the body below a status),
57
+ * `code`, or the message of an `Error`. Undefined when the failure names none (the network is down).
58
+ */
59
+ export declare const readAgentVoiceErrorCode: (failure: unknown) => string | undefined;
60
+ /** A request of the voice routes as the application's request layer receives it: path, method, JSON body. */
61
+ export interface AgentVoiceRequest {
62
+ url: string;
63
+ method?: "GET" | "POST";
64
+ body?: unknown;
65
+ }
66
+ /**
67
+ * The application's request layer as `createAgentVoiceApi` uses it. The call store runs outside React (the call
68
+ * outlives the chat that shows it), so the layer answers a Promise per request and offers no hooks: `request` sends
69
+ * with the application's origin, session and token refresh, resolves with the parsed JSON answer and rejects with the
70
+ * failure (see `readAgentVoiceErrorCode`). `createAgentVoiceFetchBaseApi` is one over `fetch`.
71
+ */
72
+ export interface AgentVoiceBaseApi {
73
+ request: <Answer>(request: AgentVoiceRequest) => Promise<Answer>;
74
+ }
75
+ export interface CreateAgentVoiceApiOptions {
76
+ /** The application's request layer. */
77
+ baseApi: AgentVoiceBaseApi;
78
+ /** Where the application mounts the voice session routes, without a trailing slash (`/api/agents/voiceSession`). */
79
+ apiPrefix: string;
80
+ }
81
+ /** The request of every operation, on `apiPrefix`, with the routes' own field names. Pure: nothing is sent. */
82
+ export declare const buildAgentVoiceRequests: (apiPrefix: string) => {
83
+ openSession: ({ agentSpaceId, sdpOffer, conversationId, callId, }: Parameters<AgentVoiceApi["openSession"]>[0]) => AgentVoiceRequest;
84
+ hangUp: ({ callId, reason }: Parameters<AgentVoiceApi["hangUp"]>[0]) => AgentVoiceRequest;
85
+ reportDeviceStatus: ({ callId, status, iceCandidateType, roundTripTimeMs, detail, occurredAtUnixMs, }: Parameters<AgentVoiceApi["reportDeviceStatus"]>[0]) => AgentVoiceRequest;
86
+ readCallState: ({ callId }: Parameters<AgentVoiceApi["readCallState"]>[0]) => AgentVoiceRequest;
87
+ answerRing: ({ callId, answerToken }: Parameters<AgentVoiceApi["answerRing"]>[0]) => AgentVoiceRequest;
88
+ declineRing: ({ callId, answerToken }: Parameters<AgentVoiceApi["declineRing"]>[0]) => AgentVoiceRequest;
89
+ };
90
+ /** The code of an `open` answer without a call id or a conversation: nothing the call could go on with. */
91
+ export declare const AGENT_VOICE_ERROR_CODE_INVALID_OPEN_ANSWER = "invalid_open_answer";
92
+ /**
93
+ * The adapter for an application whose routes are the voice trait's own paths below `apiPrefix`, with the agent space
94
+ * in the body of `open`:
95
+ * `export const agentVoiceApi = createAgentVoiceApi({ baseApi, apiPrefix: "/api/agents/voiceSession" });`
96
+ * An application whose `open` names its space another way (in the path) writes the six functions itself.
97
+ */
98
+ export declare const createAgentVoiceApi: ({ baseApi, apiPrefix }: CreateAgentVoiceApiOptions) => AgentVoiceApi;
99
+ /** What every request carries from the application: headers, credentials, mode, cache. */
100
+ export type AgentVoiceFetchOptions = Omit<RequestInit, "method" | "body">;
101
+ export interface CreateAgentVoiceFetchBaseApiOptions {
102
+ /**
103
+ * Request options every request carries (credentials, an authorization header). A function is called per request,
104
+ * so it may hand out a fresh token. Default: none (the browser's defaults: same-origin credentials).
105
+ */
106
+ fetchOptions?: AgentVoiceFetchOptions | (() => AgentVoiceFetchOptions | Promise<AgentVoiceFetchOptions>);
107
+ /** The fetch function. Default: the global `fetch`. */
108
+ fetch?: typeof fetch;
109
+ }
110
+ /**
111
+ * A request layer over `fetch`: JSON out, JSON in; a refused request rejects with `AgentVoiceApiError`, its code the
112
+ * `error` of the JSON error body (`http_<status>` without one).
113
+ */
114
+ export declare const createAgentVoiceFetchBaseApi: (options?: CreateAgentVoiceFetchBaseApiOptions) => AgentVoiceBaseApi;
@@ -0,0 +1,6 @@
1
+ import type { AgentVoiceCallSnapshot } from "./agent-voice-call-store";
2
+ /**
3
+ * Whole seconds from the moment the call connected to its end, or to `nowMs` while it has not ended; 0 before it
4
+ * connected, and never below 0 (a clock read before the connect moment).
5
+ */
6
+ export declare const agentVoiceCallElapsedSecondsAt: (call: Pick<AgentVoiceCallSnapshot, "connectedAtMs" | "endedAtMs">, nowMs: number) => number;
@@ -0,0 +1,3 @@
1
+ /** The call's end reasons the band words differently (`AgentVoiceCall::END_REASON_*`). */
2
+ export declare const AGENT_VOICE_CALL_END_REASON_ENDED_BY_AGENT = "ENDED_BY_AGENT";
3
+ export declare const AGENT_VOICE_CALL_END_REASON_LIMIT_REACHED = "LIMIT_REACHED";
@@ -0,0 +1,111 @@
1
+ import { type AgentVoiceApi } from "../agent-voice-api";
2
+ /**
3
+ * The voice chat with the agent in the browser window (the owner starts it, or answers the agent's ring). The audio
4
+ * runs peer to peer between the browser and the voice provider over WebRTC; the backend only relays the SDP handshake
5
+ * (`openSession`) and its session worker writes every spoken sentence into the call's conversation, which the chat
6
+ * shows live.
7
+ *
8
+ * Module-level on purpose: the call must outlive the chat that shows it (a closed chat window, a conversation switch, a
9
+ * remount), and the account can hold only one call at a time anyway.
10
+ */
11
+ export type AgentVoiceCallPhase = "idle" | "connecting" | "live" | "ended" | "failed";
12
+ export type AgentVoiceCallSpeaker = "agent" | "owner";
13
+ export interface AgentVoiceCallLine {
14
+ /** Increasing within the call: the line's React key. */
15
+ readonly id: number;
16
+ readonly speaker: AgentVoiceCallSpeaker;
17
+ readonly text: string;
18
+ }
19
+ export interface AgentVoiceCallSnapshot {
20
+ readonly phase: AgentVoiceCallPhase;
21
+ /** The agent space the call was started in, where the application has one. */
22
+ readonly agentSpaceId?: number;
23
+ /** The conversation the call writes its transcript into: known once `openSession` answered. */
24
+ readonly conversationId?: number;
25
+ readonly callId?: number;
26
+ /** Set on `session.started`: the moment the call counts as connected. */
27
+ readonly connectedAtMs?: number;
28
+ readonly endedAtMs?: number;
29
+ readonly isMuted: boolean;
30
+ /** The microphone delivered only silence for several seconds while not muted: a wrong or muted input device. */
31
+ readonly isMicrophoneSilent: boolean;
32
+ /** The agent's words are arriving right now (an output transcript delta within `AGENT_SPEAKING_HOLD_MS`). */
33
+ readonly isAgentSpeaking: boolean;
34
+ /** The owner's words are arriving right now (an input transcript delta within `OWNER_SPEAKING_HOLD_MS`). */
35
+ readonly isOwnerSpeaking: boolean;
36
+ /** Who spoke last, from the transcript deltas: drives the status line and the glow. */
37
+ readonly lastSpeaker?: AgentVoiceCallSpeaker;
38
+ /** What was said in this call, oldest first: one line per turn of a speaker, assembled from the transcript deltas. */
39
+ readonly lines: readonly AgentVoiceCallLine[];
40
+ /** The text key of a sentence for the owner when the call failed (it may carry `%agentName%`). */
41
+ readonly failureTextKey?: string;
42
+ /**
43
+ * Set when the SERVER ended the call (the agent hung up, a limit, the provider closed the session): the call's end
44
+ * reason (`ENDED_BY_AGENT`, `LIMIT_REACHED`, …), or `PROVIDER_CLOSED` when the provider closed the session before the
45
+ * call said why. Undefined when this browser ended the call. Picks the band's end text.
46
+ */
47
+ readonly endReason?: string;
48
+ }
49
+ export { AGENT_VOICE_CALL_END_REASON_ENDED_BY_AGENT, AGENT_VOICE_CALL_END_REASON_LIMIT_REACHED, } from "./agent-voice-call-end-reasons";
50
+ /** No voice chat: also what a chat shows of a voice chat that runs in another agent space. */
51
+ export declare const IDLE_AGENT_VOICE_CALL: AgentVoiceCallSnapshot;
52
+ /**
53
+ * The adapter the store sends its requests through. `AgentVoiceCallProvider` binds the one it was given; the binding
54
+ * stays after the provider is gone, because a running call still has to end on the server.
55
+ */
56
+ export declare const bindAgentVoiceApi: (api: AgentVoiceApi) => void;
57
+ /** The bound adapter (undefined before a provider was mounted): answering and declining a ring go through it too. */
58
+ export declare const readBoundAgentVoiceApi: () => AgentVoiceApi | undefined;
59
+ /** The call as it is now, outside React (a module that reacts to an event, a test). */
60
+ export declare const readAgentVoiceCallSnapshot: () => AgentVoiceCallSnapshot;
61
+ /** The call as the store holds it; it changes with the call, not with the clock (see `useAgentVoiceCall`). */
62
+ export declare const useAgentVoiceCallSnapshot: () => AgentVoiceCallSnapshot;
63
+ /**
64
+ * One field of the call, for a component that must not re-render on every transcript delta (the chat window's shell,
65
+ * the input's voice button). The selector must return a primitive so an unchanged value skips the render.
66
+ */
67
+ export declare const useAgentVoiceCallValue: <Value extends string | number | boolean | undefined>(selectValue: (call: AgentVoiceCallSnapshot) => Value) => Value;
68
+ export declare const isAgentVoiceCallActive: (phase: AgentVoiceCallPhase) => boolean;
69
+ /**
70
+ * Whether a chat of the agent space `agentSpaceId` shows this call: not when the call is known to run in another
71
+ * agent space. A chat or a call that names no agent space is never held apart.
72
+ */
73
+ export declare const isAgentVoiceCallShownInAgentSpace: (call: AgentVoiceCallSnapshot, agentSpaceId: number | undefined) => boolean;
74
+ /**
75
+ * Whether a voice chat is connecting or live; with `agentSpaceId`, whether one is that a chat of that agent space
76
+ * shows. An input shows the start button in its send spot only while none is, and the glow and the captions while one is.
77
+ */
78
+ export declare const useIsAgentVoiceCallActive: (agentSpaceId?: number) => boolean;
79
+ /** Put away the band of an ended or failed call (its Close): the chat is back to no call. */
80
+ export declare const dismissAgentVoiceCallOutcome: () => void;
81
+ /**
82
+ * The SERVER ended the call (the call has `endedAt`; or the provider closed the session): end this browser's side
83
+ * without telling the backend again: no hang-up request for a call the server already ended. Applies only while the
84
+ * call is connecting or live AND the call id is this call's, so a late answer for an earlier call, or a second trigger
85
+ * after the first one ended the call, changes nothing. `session.close` goes out unless the agent ended the call (its
86
+ * worker already closed the session); a `FAILED` end shows the failure, every other end the call's end text.
87
+ */
88
+ export declare const endAgentVoiceCallFromServer: (callId: number, endReason: string | undefined) => void;
89
+ /**
90
+ * Read the call's state (`readCallState`) and end the call here when the server ended it. Resolves to whether it did.
91
+ * One read at a time per call: the conversation's change signal, the data channel closing and the ICE watcher may all
92
+ * ask at once.
93
+ */
94
+ export declare const checkAgentVoiceCallEndedOnServer: () => Promise<boolean>;
95
+ /** End the call from this browser. Safe to call in any phase. */
96
+ export declare const hangUpAgentVoiceCall: (reason?: string) => void;
97
+ export declare const toggleAgentVoiceCallMute: () => void;
98
+ export interface StartAgentVoiceCallParams {
99
+ /** The agent space the call runs in, where the application has one; goes to `openSession` as it is. */
100
+ agentSpaceId?: number;
101
+ /** The chat's conversation the call continues; without one the backend creates a conversation for the call. */
102
+ conversationId?: number;
103
+ /** The rung call this browser already won through `answerRing` (see answerIncomingAgentVoiceCall.ts). */
104
+ callId?: number;
105
+ }
106
+ /**
107
+ * Start a voice chat (or attach to the answered call `callId`). Call it straight from the click: the microphone prompt
108
+ * and the audio playback need the user's gesture. Does nothing while a call is connecting or live, and nothing before
109
+ * an `AgentVoiceCallProvider` bound the adapter.
110
+ */
111
+ export declare const startAgentVoiceCall: (params?: StartAgentVoiceCallParams) => Promise<void>;
@@ -0,0 +1,4 @@
1
+ import type { AgentVoiceCallSnapshot } from "./agent-voice-call-store";
2
+ /** Whose turn it is on the line right now: the band's status line and the input glow read it. */
3
+ export type AgentVoiceCallTurn = "connecting" | "muted" | "silentMicrophone" | "agent" | "owner" | "thinking" | "listening";
4
+ export declare const turnOfAgentVoiceCall: (call: AgentVoiceCallSnapshot) => AgentVoiceCallTurn;
@@ -0,0 +1,14 @@
1
+ import type { AgentVoiceCallLine, AgentVoiceCallSpeaker } from "./agent-voice-call-store";
2
+ /** A message the chat already holds from this call: who wrote it and its text. */
3
+ export interface SavedAgentVoiceCallMessage {
4
+ readonly speaker: AgentVoiceCallSpeaker;
5
+ readonly text: string;
6
+ }
7
+ /**
8
+ * What was said in this call that the chat does not show yet: the call's lines with every sentence the backend has
9
+ * already saved as a message taken out, so only the unsaved rest streams at the chat's end and gives way to the real
10
+ * message once it arrives. Per speaker, the saved texts are read as one stream in order, and each sentence of the
11
+ * speaker's lines is looked for from where the last found one ended: the backend may cut sentences elsewhere, and a
12
+ * sentence said twice is matched twice. Lines with nothing unsaved left are dropped.
13
+ */
14
+ export declare const buildUnsavedAgentVoiceCallLines: (lines: readonly AgentVoiceCallLine[], savedMessages: readonly SavedAgentVoiceCallMessage[]) => AgentVoiceCallLine[];
@@ -0,0 +1,2 @@
1
+ /** `m:ss` for a call shorter than an hour (the backend caps a call's duration). */
2
+ export declare const formatAgentVoiceCallDuration: (elapsedSeconds: number) => string;
@@ -0,0 +1,3 @@
1
+ import type { AgentVoiceCallSnapshot } from "./agent-voice-call-store";
2
+ /** Seconds since the call connected, ticking while it is live; frozen at the end once it ended. */
3
+ export declare const useAgentVoiceCallElapsedSeconds: (call: AgentVoiceCallSnapshot) => number;
@@ -0,0 +1,15 @@
1
+ /** How an application reports the changes of a conversation: `onChange` on every change; returns the unsubscribe. */
2
+ export type AgentVoiceConversationChangeSubscription = (conversationId: number, onChange: () => void) => () => void;
3
+ /**
4
+ * Ends the voice chat here when the SERVER ended the call (the agent hung up, a limit, the reaper): listens to the
5
+ * change signal of the CALL's conversation, independent of the conversation the chat shows, while the call is active,
6
+ * and on a signal reads the call's state. The backend writes the call's end before its call-end marker and the signal,
7
+ * so the read after the signal sees the end. The signal is throttled here (one read per 1.2 s at most, the last signal
8
+ * of a burst still read) and the store runs one read at a time.
9
+ *
10
+ * The signal comes from `subscribeToConversationChanges` when the application passes one, otherwise from the
11
+ * conversation client in the React context (its `subscribeToConversationChanges`). Without
12
+ * either nothing is listened to: the call still ends through the store's own triggers (the provider's `session.closed`,
13
+ * the event channel closing, the media path dropping). `AgentVoiceCallProvider` mounts the hook.
14
+ */
15
+ export declare const useAgentVoiceCallServerEnd: (subscribeToConversationChanges?: AgentVoiceConversationChangeSubscription) => void;
@@ -0,0 +1,12 @@
1
+ import { type AgentVoiceCallSnapshot } from "./agent-voice-call-store";
2
+ /** The call with its clock: what `useAgentVoiceCall()` returns. */
3
+ export interface AgentVoiceCall extends AgentVoiceCallSnapshot {
4
+ /** Seconds since the call connected: ticking while it is live, frozen once it ended, 0 before it connected. */
5
+ readonly elapsedSeconds: number;
6
+ }
7
+ /**
8
+ * The voice chat as it is now: the phase, the call and its conversation, the spoken lines, mute, the end reason and
9
+ * the elapsed seconds. It renders again every second while the call is live; a component that needs one field only
10
+ * reads it with `useAgentVoiceCallValue`, one that needs no clock with `useAgentVoiceCallSnapshot`.
11
+ */
12
+ export declare const useAgentVoiceCall: () => AgentVoiceCall;
@@ -0,0 +1,9 @@
1
+ /** What the application does when the call's conversation is known: show that conversation beside the call. */
2
+ export type AgentVoiceConversationOfCallChangedHandler = (conversationId: number, agentSpaceId: number | undefined) => void;
3
+ /**
4
+ * Once per call and conversation, tells the application which conversation the call writes into: the one the chat
5
+ * continued, or the one the backend created when the call started from an empty chat or from the agent's ring. The
6
+ * application switches its chat there, so the transcript shows up beside the call. `agentSpaceId` is the call's agent
7
+ * space where the start or the ring named one.
8
+ */
9
+ export declare const useFollowAgentVoiceCallConversation: (onConversationOfCallChanged: AgentVoiceConversationOfCallChangedHandler | undefined) => void;
@@ -0,0 +1,21 @@
1
+ import type { AgentVoiceTranslateText } from "../AgentVoiceCallProvider/agent-voice-call-context";
2
+ import type { AgentVoiceRing } from "./agent-voice-ring";
3
+ /** The caller line as the incoming call and the band show it. */
4
+ export interface AgentVoiceCallerLabel {
5
+ /** Who is asking to talk, ready to show. */
6
+ text: string;
7
+ /** A second line under it: what tells an owner with several agent spaces which one is calling. */
8
+ detail?: string;
9
+ }
10
+ export interface AgentVoiceCallerLabelTextKey {
11
+ labelTextKey: string;
12
+ /** True for a key of this bundle (render through the text function), false for an unknown key of the backend. */
13
+ isTranslatable: boolean;
14
+ }
15
+ /** The text key of a ring's caller line; a ring without a label key gets the bundle's own line. */
16
+ export declare const pickAgentVoiceCallerLabelTextKey: (callerLabelKey: string) => AgentVoiceCallerLabelTextKey;
17
+ /**
18
+ * The caller line of a ring where the application resolves none: the ring's label key through `translate` (the voice
19
+ * components' text function, which fills `%agentName%`), an unknown key with `agentName` filled in.
20
+ */
21
+ export declare const buildAgentVoiceCallerLabel: (ring: AgentVoiceRing, translate: AgentVoiceTranslateText, agentName: string) => AgentVoiceCallerLabel;
@@ -0,0 +1,10 @@
1
+ import type { AgentVoiceRing } from "./agent-voice-ring";
2
+ /** The held rings with `ring` at the end: a ring that arrives replaces the one of the same call, so a call rings once. */
3
+ export declare const withAgentVoiceIncomingRing: (heldRings: readonly AgentVoiceRing[], ring: AgentVoiceRing) => readonly AgentVoiceRing[];
4
+ /** The held rings without the ring of the call `callId`: a cleared ring goes at once. */
5
+ export declare const withoutAgentVoiceIncomingRingOfCall: (heldRings: readonly AgentVoiceRing[], callId: number) => readonly AgentVoiceRing[];
6
+ /**
7
+ * The held rings whose deadline is after `nowMs`. The same list when none has passed its deadline, so a tick of the
8
+ * clock that drops nothing changes nothing.
9
+ */
10
+ export declare const agentVoiceIncomingRingsInDeadlineAt: (heldRings: readonly AgentVoiceRing[], nowMs: number) => readonly AgentVoiceRing[];
@@ -0,0 +1,47 @@
1
+ import type { AgentVoiceCallerLabel } from "./agent-voice-caller-label";
2
+ import type { AgentVoiceRing } from "./agent-voice-ring";
3
+ import { type AgentVoiceAnswerRefusal } from "./answer-incoming-agent-voice-call";
4
+ /**
5
+ * The agent ringing this client, shared between the one listener (`AgentVoiceIncomingCall`, mounted once) and where
6
+ * the ring is answered: the band over an open chat's input, or, with no chat in sight, the listener's own card.
7
+ */
8
+ export interface AgentVoiceIncomingRingSnapshot {
9
+ /** The ring this client shows, inside its deadline and not handled here yet. */
10
+ readonly ring?: AgentVoiceRing;
11
+ /** The caller line of `ring`, as the listener resolved it. */
12
+ readonly callerLabel?: AgentVoiceCallerLabel;
13
+ /** Calls answered, declined or let go in this client: never shown again, even before their ring is gone. */
14
+ readonly handledCallIds: ReadonlySet<number>;
15
+ readonly isAnswering: boolean;
16
+ /** Why the last Accept did not get the call; shown for a few seconds. */
17
+ readonly refusal?: AgentVoiceAnswerRefusal;
18
+ /** How many chats show the ring in their band right now (presented); with none, the listener shows its card. */
19
+ readonly bandHostCount: number;
20
+ /** How many surfaces cover the chats right now; with any, the listener shows its card. */
21
+ readonly ringCoverCount: number;
22
+ }
23
+ export declare const useAgentVoiceIncomingRing: () => AgentVoiceIncomingRingSnapshot;
24
+ /** The incoming ring as it is now, outside React (a test). */
25
+ export declare const readAgentVoiceIncomingRingSnapshot: () => AgentVoiceIncomingRingSnapshot;
26
+ /** What the listener's own card shows (the ring, else a refused Accept) while no chat band can be seen. */
27
+ export declare const pickAgentVoiceIncomingCard: (state: Pick<AgentVoiceIncomingRingSnapshot, "ring" | "refusal" | "bandHostCount" | "ringCoverCount">) => "ring" | "refusal" | undefined;
28
+ /** The listener publishes the ring it picked with its caller line (undefined when nothing rings). */
29
+ export declare const publishAgentVoiceIncomingRing: (ring: AgentVoiceRing | undefined, callerLabel: AgentVoiceCallerLabel | undefined) => void;
30
+ /**
31
+ * Accept: answers the ring and, when this client won, starts the call on the ring's own conversation and agent space
32
+ * (the ring may come from another agent space than the one the client shows). The application learns the call's
33
+ * conversation through `AgentVoiceCallProvider.onConversationOfCallChanged` and shows it.
34
+ */
35
+ export declare const acceptAgentVoiceIncomingRing: () => Promise<void>;
36
+ /**
37
+ * Decline: ends the ring for every open client of the account. The backend writes the declined call into its
38
+ * conversation once nothing rings any more.
39
+ */
40
+ export declare const declineAgentVoiceIncomingRing: () => void;
41
+ /** A chat that shows the ring in its band, while hosting: the listener's card stays away unless a cover is open. */
42
+ export declare const useAgentVoiceRingBandHost: (isHosting: boolean) => void;
43
+ /**
44
+ * A surface that covers the chats while covering (a settings sheet over them): their bands are out of sight then, so
45
+ * the listener shows its own card on top instead.
46
+ */
47
+ export declare const useAgentVoiceRingCover: (isCovering: boolean) => void;
@@ -0,0 +1,75 @@
1
+ import type { AccountRealtimePoll } from "../../ui/account-realtime";
2
+ import type { AgentRealtimeMessageDelivery } from "../../ui/realtime-arrival";
3
+ import { type AgentVoiceRing } from "./agent-voice-ring";
4
+ /**
5
+ * The stream of the agent's rings to this account. `AgentVoiceCallProvider` takes one; the incoming call subscribes
6
+ * while it is mounted. `onRing` gets every ring that arrives (a replaced one again); `onRingCleared` is called when
7
+ * the source learns that a ring ended before its deadline (answered on another client, declined, canceled). A source
8
+ * that cannot learn it never calls it: the ring then goes at its deadline, and an Accept after the end is refused by
9
+ * the backend.
10
+ */
11
+ export interface AgentVoiceRingSource {
12
+ subscribe(onRing: (ring: AgentVoiceRing) => void, onRingCleared: (callId: number) => void): () => void;
13
+ }
14
+ /**
15
+ * Starts the account realtime poll (`createAccountRealtimePoll` of `./ui`) with the arrival hook the ring source hands in:
16
+ * `onMessage => createAccountRealtimePoll({ readAccountRealtime: client.getAccountRealtimeMessages, onMessage })`.
17
+ * For an application that wants the poll to run only while a ring can show: the ring source starts it with its first
18
+ * subscriber and stops it with its last. An application that reads further message types from the same poll passes
19
+ * the poll itself instead and subscribes to it beside the ring source.
20
+ */
21
+ export type AgentVoiceAccountRealtimePollStarter = (onMessage: (message: AgentRealtimeMessageDelivery) => void) => AccountRealtimePoll;
22
+ interface AgentVoiceRingSubscriber {
23
+ onRing: (ring: AgentVoiceRing) => void;
24
+ onRingCleared: (callId: number) => void;
25
+ }
26
+ interface AgentVoiceKnownRing {
27
+ ring: AgentVoiceRing;
28
+ /** The subscribers the ring was handed to, as an arrival or when they came: only they are told its clear. */
29
+ handedTo: Set<AgentVoiceRingSubscriber>;
30
+ }
31
+ /**
32
+ * The ring source over the account realtime poll: every message of the type `agent.voice.ring` the poll delivers goes
33
+ * to the subscribers as a ring, and a ring message the poll reports as cleared (a read found it gone: answered or
34
+ * declined on another client, canceled, past its deadline) as a cleared ring. A subscriber is told `onRingCleared`
35
+ * only for a ring it was handed, as an arrival or in the hand-over when it subscribed.
36
+ *
37
+ * It listens while somebody is subscribed. Given the poll itself, it subscribes to it with the first subscriber and
38
+ * leaves it with the last; the poll stays the application's, which stops it. Given a function that starts the poll, it
39
+ * starts the poll with the first subscriber and stops it with the last.
40
+ */
41
+ export declare class AgentVoiceAccountRealtimeRingSource implements AgentVoiceRingSource {
42
+ protected readonly accountRealtimePollOrStarter: AccountRealtimePoll | AgentVoiceAccountRealtimePollStarter;
43
+ protected readonly subscribers: Set<AgentVoiceRingSubscriber>;
44
+ /** The rings delivered while it listens, by call: a subscriber that comes later still gets the ones in their deadline. */
45
+ protected readonly knownRingsByCallId: Map<number, AgentVoiceKnownRing>;
46
+ /** The poll a starter created; this source stops it. Undefined for a poll of the application. */
47
+ protected startedAccountRealtimePoll: AccountRealtimePoll | undefined;
48
+ /** Set while it listens to the poll. */
49
+ protected unsubscribeFromAccountRealtimePoll: (() => void) | undefined;
50
+ constructor(accountRealtimePollOrStarter: AccountRealtimePoll | AgentVoiceAccountRealtimePollStarter);
51
+ subscribe(onRing: (ring: AgentVoiceRing) => void, onRingCleared: (callId: number) => void): () => void;
52
+ /** Takes one message of the account's realtime messages; returns whether it was a ring. */
53
+ acceptRealtimeMessage(message: AgentRealtimeMessageDelivery): boolean;
54
+ /**
55
+ * Takes one message the account's realtime messages hold no more; returns whether it was a ring. The clear goes to
56
+ * the subscribers the ring of that call was handed to, and to nobody for a call this source holds no ring of.
57
+ */
58
+ acceptClearedRealtimeMessage(message: AgentRealtimeMessageDelivery): boolean;
59
+ /** Hands a ring to a subscriber and notes it on the known ring. */
60
+ protected handRing(knownRing: AgentVoiceKnownRing, subscriber: AgentVoiceRingSubscriber): void;
61
+ /**
62
+ * The poll hands over the messages open now, then every arrival and every clear. A started poll delivers its
63
+ * arrivals through the hook it was started with, so only the clears are subscribed there.
64
+ */
65
+ protected listenToAccountRealtimePoll(): void;
66
+ protected leaveAccountRealtimePoll(): void;
67
+ }
68
+ /**
69
+ * The ring source over the account realtime poll of `./ui`:
70
+ * `createAgentVoiceRingSource(createAccountRealtimePoll({ readAccountRealtime, … }))`. A function that starts the poll
71
+ * (`AgentVoiceAccountRealtimePollStarter`) is taken as well. An application with its own ring transport passes its own
72
+ * `AgentVoiceRingSource` instead.
73
+ */
74
+ export declare const createAgentVoiceRingSource: (accountRealtimePollOrStarter: AccountRealtimePoll | AgentVoiceAccountRealtimePollStarter) => AgentVoiceRingSource;
75
+ export {};
@@ -0,0 +1,35 @@
1
+ import type { AgentRealtimeMessageDelivery } from "../../ui/realtime-arrival";
2
+ /** The realtime message type of the agent ringing the owner's open clients. Its key is the call id. */
3
+ export declare const AGENT_VOICE_RING_MESSAGE_TYPE = "agent.voice.ring";
4
+ /**
5
+ * The agent ringing this account: what a client needs to show the ring and answer it. Written by the backend when the
6
+ * agent starts a call to the owner, for every open client of the account; it ends for a client when the call was
7
+ * answered or declined, when its deadline passed, or when the agent or the owner canceled.
8
+ */
9
+ export interface AgentVoiceRing {
10
+ callId: number;
11
+ conversationId?: number | null;
12
+ /** Single-use, bound to this call; redeemed by `answerRing` / `declineRing`. */
13
+ answerToken: string;
14
+ ringExpiresAt: string;
15
+ ringExpiresAtUnixMs: number;
16
+ /** A text key: the caller line of the incoming call. */
17
+ callerLabelKey: string;
18
+ /** What the application put into the ring for its own caller line (what tells an owner which space is calling). */
19
+ callerContext: Readonly<Record<string, unknown>>;
20
+ /**
21
+ * The agent space of the call, where the ring names it: passed to `openSession` when the owner accepts. An
22
+ * application whose `openSession` needs the space fills it in its ring source or sends it in the payload.
23
+ */
24
+ agentSpaceId?: number;
25
+ }
26
+ /**
27
+ * The ring a realtime message carries; null for a message of another type or a payload that is not a ring (no call id,
28
+ * no answer token, no deadline).
29
+ */
30
+ export declare const readAgentVoiceRingOfRealtimeMessage: (message: AgentRealtimeMessageDelivery) => AgentVoiceRing | null;
31
+ /**
32
+ * The ring this client shows: the newest one still inside its deadline and not already handled here (answered,
33
+ * declined or let go in this client).
34
+ */
35
+ export declare const pickRingingAgentVoiceCall: (rings: readonly AgentVoiceRing[], nowMs: number, handledCallIds: ReadonlySet<number>) => AgentVoiceRing | undefined;
@@ -0,0 +1,13 @@
1
+ import type { AgentVoiceRing } from "./agent-voice-ring";
2
+ /** Why the answer did not get the call: the sentence the band or the incoming call shows instead of the ring. */
3
+ export type AgentVoiceAnswerRefusal = "answeredElsewhere" | "ringEnded" | "failed";
4
+ export declare const AGENT_VOICE_ANSWER_REFUSAL_TEXT_KEYS: Readonly<Record<AgentVoiceAnswerRefusal, string>>;
5
+ /**
6
+ * Answering the agent's ring in the browser: `answerRing` with the ring's single-use token (the atomic first-wins
7
+ * claim: two clients pressing at once get exactly one winner), then the same WebRTC start as the chat's voice button
8
+ * with the call id, so `openSession` attaches to the claimed call. Returns undefined when this browser won and the
9
+ * call is starting.
10
+ */
11
+ export declare const answerIncomingAgentVoiceCall: (ring: AgentVoiceRing) => Promise<AgentVoiceAnswerRefusal | undefined>;
12
+ /** Decline in this browser: ends the ring for every open client of the account. */
13
+ export declare const declineIncomingAgentVoiceCall: (ring: AgentVoiceRing) => Promise<void>;
@@ -0,0 +1,14 @@
1
+ import type { AgentVoiceRing } from "./agent-voice-ring";
2
+ import type { AgentVoiceRingSource } from "./agent-voice-ring-source";
3
+ export interface AgentVoiceIncomingRings {
4
+ /** The rings that arrived and are still inside their deadline, one per call. */
5
+ rings: readonly AgentVoiceRing[];
6
+ /** The clock the deadlines were last read against: ticks every second while a ring is held. */
7
+ nowMs: number;
8
+ }
9
+ /**
10
+ * Listens for the agent's rings to this client while a ring source is given: a ring that arrives replaces the one of
11
+ * the same call, a cleared one goes at once, and one whose deadline passed goes with the next tick of the clock. No
12
+ * ring source (the application has no ring transport) or no ring: an empty list, and no clock running.
13
+ */
14
+ export declare const useAgentVoiceIncomingRings: (ringSource: AgentVoiceRingSource | undefined) => AgentVoiceIncomingRings;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A phone-like ring tone while `isRinging`, synthesized with Web Audio (no asset). Browsers block audio until the user
3
+ * has interacted with the page (autoplay policy): without that interaction this plays nothing and the visual ring is
4
+ * the whole signal.
5
+ */
6
+ export declare const useAgentVoiceRingTone: (isRinging: boolean) => void;