@mgamadeus/ddd-agents 0.6.1 → 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/README.md CHANGED
@@ -293,8 +293,10 @@ What the application passes to `AgentVoiceCallProvider`:
293
293
  application whose routes are the trait's own paths with the agent space in the body of `open`; `baseApi` is the
294
294
  application's request layer as one function (`request({ url, method, body })` answering a Promise), for which
295
295
  `createAgentVoiceFetchBaseApi()` is the binding over `fetch`. An application whose `open` names its space in the path
296
- writes the six functions itself. A refused request rejects with the route's error code where
297
- `readAgentVoiceErrorCode` finds it (`error`, `data.error`, `code` or the message).
296
+ adds `buildOpenPath: (agentSpaceId) => string` (`AgentVoiceOpenPathBuilder`), the whole path of `open` for the space
297
+ the start was given (undefined when it named none); the body still carries `agentSpaceId`, the other five routes stay
298
+ below `apiPrefix`, and without the option `open` is `${apiPrefix}/open`. A refused request rejects with the route's
299
+ error code where `readAgentVoiceErrorCode` finds it (`error`, `data.error`, `code` or the message).
298
300
  - **`ringSource`** (`AgentVoiceRingSource`): the stream of the `agent.voice.ring` messages.
299
301
  `createAgentVoiceRingSource(accountRealtimePoll)` listens to the account realtime poll of `/ui` while the incoming
300
302
  call is mounted: a ring message that arrives rings, and one a read finds gone (answered or declined on another
@@ -304,7 +306,9 @@ What the application passes to `AgentVoiceCallProvider`:
304
306
  backend rings an account only while it knows one of its clients: the account read of the poll states the client's id
305
307
  (see `/ui`), with or without a `uiClient`.
306
308
  - **`onConversationOfCallChanged(conversationId, agentSpaceId)`**: called once per call when the conversation the call
307
- writes into is known; the application shows that conversation.
309
+ writes into is known; the application shows that conversation. The provider does it with
310
+ `useFollowAgentVoiceCallConversation(handler)`, which an application may also call itself in a component of its own
311
+ (a window that follows the call without the provider's handler).
308
312
 
309
313
  The call lives in a store at module level, so it goes on when the chat that shows it closes. `useAgentVoiceCall()`
310
314
  returns it: `phase` (`idle`, `connecting`, `live`, `ended`, `failed`), `callId`, `conversationId`, `lines` (what was
@@ -313,15 +317,27 @@ on every transcript delta. Actions: `startAgentVoiceCall({ agentSpaceId?, conver
313
317
  from the click: the microphone prompt needs the user's gesture), `hangUpAgentVoiceCall(reason?)`,
314
318
  `toggleAgentVoiceCallMute()`, `dismissAgentVoiceCallOutcome()`. The store asks for the microphone, opens the peer
315
319
  connection and the provider's event channel, reports the device status, and ends the call when the server says it ended.
320
+ A start that fails before `open` answers (a refused microphone, a refusal of `open` such as `no_ai_budget`) is the
321
+ store's `failed` phase with its `failureTextKey`, so every mounted band of that agent space shows it, inside a chat or
322
+ not.
316
323
 
317
324
  | Component | Where it goes | Props |
318
325
  |---|---|---|
319
326
  | `AgentVoiceCallProvider` | once, above every voice component, below the conversation client (`AgentsProvider`) | `api`, `ringSource`, `onConversationOfCallChanged` |
320
- | `AgentVoiceChatStartButton` | the chat input's send spot while nothing is typed | `agentSpaceId?`, `conversationId?`, `disabled?`, `testId?` |
321
- | `AgentVoiceCallBand` | over the chat input | `renderAgentSpot?(call)`, `agentSpaceId?`, `isPresented?` |
322
- | `AgentVoiceCallCaptions` | after the chat's message list, inside the chat | `agentSpaceId?`, `ownerMessageTheme?` |
323
- | `AgentVoiceInputGlow` | the chat input's underlay | `agentSpaceId?` |
324
- | `AgentVoiceIncomingCall` | once, outside the chat | `resolveCallerLabel?(ring)`, `renderAgentSpot?()` |
327
+ | `AgentVoiceChatStartButton` | the chat input's send spot while nothing is typed | `agentSpaceId?`, `conversationId?`, `disabled?`, `onStart?()`, `testId?` |
328
+ | `AgentVoiceCallBand` | over the chat input | `renderAgentSpot?(call)`, `agentSpaceId?`, `isPresented?`, `actions?`, `testId?` |
329
+ | `AgentVoiceCallCaptions` | after the chat's message list, inside the chat | `agentSpaceId?`, `ownerMessageTheme?`, `testId?` |
330
+ | `AgentVoiceInputGlow` | the chat input's underlay | `agentSpaceId?`, `testId?` |
331
+ | `AgentVoiceIncomingCall` | once, outside the chat | `resolveCallerLabel?(ring)`, `renderAgentSpot?()`, `zIndex?`, `testId?` |
332
+
333
+ - `onStart` of the start button runs in the click, synchronously, before the microphone prompt and `open`: the place
334
+ for what needs the user's gesture (opening a window for the chat). The button's label shows through the
335
+ environment's `Tooltip` when the application replaces it (`AgentsEnvironment.components.Tooltip`, with the text key
336
+ `Talk to %agentName%`); otherwise it is the button's `title`.
337
+ - `actions` of the band are the application's own controls, placed before the band's own buttons; they render only
338
+ while the band shows something (a call, a ring, a refused answer, an outcome).
339
+ - `zIndex` of the incoming call sets its stacking order over the page; without it the custom property
340
+ `--agents-voice-incoming-call-z-index` does.
325
341
 
326
342
  - The band also shows the agent's ring while a chat is in sight (`isPresented`); the incoming call then keeps its own
327
343
  card away. A surface that covers the chats reports it with `useAgentVoiceRingCover(true)`.
@@ -335,7 +351,10 @@ connection and the provider's event channel, reports the device status, and ends
335
351
  - The styles are part of `styles.css`. Every colour and size is a custom property starting with `--agents-voice-`,
336
352
  read with its default (`--agents-voice-surface`, `--agents-voice-on-surface`, `--agents-voice-end`,
337
353
  `--agents-voice-accept`, `--agents-voice-band-max-width`, `--agents-voice-glow-color-1` … `-4`, …; each component's
338
- SCSS module lists its own at the top). Test ids start with `agent-voice-`.
354
+ SCSS module lists its own at the top). Test ids start with `agent-voice-`; a component given `testId` takes it on its
355
+ root and `${testId}-<part>` on its inner elements (the band's `-mute`, `-end`, `-close`, …, the incoming call's
356
+ `-accept`, `-decline`, `-detail`, `-refusal`, the captions' `-caption-agent`, `-caption-owner`; the glow has no inner
357
+ test id), each component's docblock lists its parts.
339
358
 
340
359
  ### The admin screens of the calls (`/voice/admin`)
341
360
 
package/dist/styles.css CHANGED
@@ -5676,6 +5676,11 @@ thead + tbody .agents_row_VBlQR-:first-child {
5676
5676
  gap: 0.5rem;
5677
5677
  }
5678
5678
 
5679
+ /* The application's own controls (`actions`): part of the row, with the row's gap. */
5680
+ .agents_applicationActions_b5QBp8 {
5681
+ display: contents;
5682
+ }
5683
+
5679
5684
  /* A pill on the dark band. */
5680
5685
  .agents_action_z96Tb1 {
5681
5686
  position: relative;
@@ -5822,7 +5827,7 @@ thead + tbody .agents_row_VBlQR-:first-child {
5822
5827
  }/*
5823
5828
  * The incoming call: top centre, over every page. Custom properties, each read with its default:
5824
5829
  *
5825
- * --agents-voice-incoming-call-top, --agents-voice-incoming-call-z-index
5830
+ * --agents-voice-incoming-call-top, --agents-voice-incoming-call-z-index (the `zIndex` prop wins over it)
5826
5831
  * --agents-voice-card-surface, --agents-voice-card-text, --agents-voice-card-action-surface,
5827
5832
  * --agents-voice-card-padding, --agents-voice-card-radius, --agents-voice-card-shadow
5828
5833
  * --agents-voice-accept, --agents-voice-on-accept Accept
@@ -1,12 +1,12 @@
1
1
  export type { AgentVoiceAdminCall, AgentVoiceAdminCallDerivedValues, AgentVoiceAdminCallDirection, AgentVoiceAdminCallEndReason, AgentVoiceAdminCallIdArg, AgentVoiceAdminCallResponse, AgentVoiceAdminCallsArg, AgentVoiceAdminCallsResponse, AgentVoiceAdminCallState, AgentVoiceAdminChangeHistory, AgentVoiceAdminCurrency, AgentVoiceAdminElements, AgentVoiceAdminMoneyAmount, } from "../voice/admin/agent-voice-admin-types";
2
- export { AGENT_VOICE_ERROR_CODE_INVALID_OPEN_ANSWER, type AgentVoiceApi, AgentVoiceApiError, type AgentVoiceBaseApi, type AgentVoiceFetchOptions, type AgentVoiceRequest, buildAgentVoiceRequests, createAgentVoiceApi, type CreateAgentVoiceApiOptions, createAgentVoiceFetchBaseApi, type CreateAgentVoiceFetchBaseApiOptions, readAgentVoiceErrorCode, } from "../voice/agent-voice-api";
2
+ export { AGENT_VOICE_ERROR_CODE_INVALID_OPEN_ANSWER, type AgentVoiceApi, AgentVoiceApiError, type AgentVoiceBaseApi, type AgentVoiceFetchOptions, type AgentVoiceOpenPathBuilder, type AgentVoiceRequest, buildAgentVoiceRequests, createAgentVoiceApi, type CreateAgentVoiceApiOptions, createAgentVoiceFetchBaseApi, type CreateAgentVoiceFetchBaseApiOptions, readAgentVoiceErrorCode, } from "../voice/agent-voice-api";
3
3
  export { AGENT_VOICE_CALL_END_REASON_ENDED_BY_AGENT, AGENT_VOICE_CALL_END_REASON_LIMIT_REACHED, type AgentVoiceCallLine, type AgentVoiceCallPhase, type AgentVoiceCallSnapshot, type AgentVoiceCallSpeaker, bindAgentVoiceApi, checkAgentVoiceCallEndedOnServer, dismissAgentVoiceCallOutcome, endAgentVoiceCallFromServer, hangUpAgentVoiceCall, IDLE_AGENT_VOICE_CALL, isAgentVoiceCallActive, isAgentVoiceCallShownInAgentSpace, readAgentVoiceCallSnapshot, startAgentVoiceCall, type StartAgentVoiceCallParams, toggleAgentVoiceCallMute, useAgentVoiceCallSnapshot, useAgentVoiceCallValue, useIsAgentVoiceCallActive, } from "../voice/call/agent-voice-call-store";
4
4
  export { type AgentVoiceCall, useAgentVoiceCall } from "../voice/call/use-agent-voice-call";
5
5
  export { type AgentVoiceCallTurn, turnOfAgentVoiceCall } from "../voice/call/agent-voice-call-turn";
6
6
  export { formatAgentVoiceCallDuration } from "../voice/call/format-agent-voice-call-duration";
7
7
  export { useAgentVoiceCallElapsedSeconds } from "../voice/call/use-agent-voice-call-elapsed-seconds";
8
8
  export { type AgentVoiceConversationChangeSubscription, useAgentVoiceCallServerEnd, } from "../voice/call/use-agent-voice-call-server-end";
9
- export type { AgentVoiceConversationOfCallChangedHandler } from "../voice/call/use-follow-agent-voice-call-conversation";
9
+ export { type AgentVoiceConversationOfCallChangedHandler, useFollowAgentVoiceCallConversation, } from "../voice/call/use-follow-agent-voice-call-conversation";
10
10
  export { buildUnsavedAgentVoiceCallLines, type SavedAgentVoiceCallMessage, } from "../voice/call/build-unsaved-agent-voice-call-lines";
11
11
  export { AGENT_VOICE_RING_MESSAGE_TYPE, type AgentVoiceRing, pickRingingAgentVoiceCall, readAgentVoiceRingOfRealtimeMessage, } from "../voice/ring/agent-voice-ring";
12
12
  export { AgentVoiceAccountRealtimeRingSource, type AgentVoiceRingSource, createAgentVoiceRingSource, } from "../voice/ring/agent-voice-ring-source";
@@ -23,6 +23,18 @@ export interface AgentVoiceCallBandViewProps {
23
23
  incoming?: AgentVoiceCallIncomingRing;
24
24
  /** The application's avatar of the agent, before the name (while a call runs or the agent rings). */
25
25
  agentSpot?: ReactNode;
26
+ /**
27
+ * The application's own controls (a button that opens the chat in a window), in the band's row of buttons before
28
+ * the band's own. Rendered only while the band shows something (a call, a ring, a refused answer, an outcome).
29
+ * Default: none.
30
+ */
31
+ actions?: ReactNode;
32
+ /**
33
+ * The test id of the band; its inner elements take `${testId}-<part>` (`-status`, `-mute`, `-end`,
34
+ * `-incoming-decline`, `-incoming-accept`, `-incoming-refusal`, `-ended-status`, `-failure`, `-start-again`, `-close`,
35
+ * `-actions`). Default: `agent-voice-call-band`, the inner elements their fixed `agent-voice-call-…` ids.
36
+ */
37
+ testId?: string;
26
38
  }
27
39
  /**
28
40
  * The voice chat in the band over the chat input: before it, the agent asking to talk (Decline, Accept); during it,
@@ -40,6 +52,10 @@ export interface AgentVoiceCallBandProps {
40
52
  * and the incoming call shows its own card. Default true.
41
53
  */
42
54
  isPresented?: boolean;
55
+ /** The application's own controls in the band (see `AgentVoiceCallBandViewProps.actions`). Default: none. */
56
+ actions?: ReactNode;
57
+ /** The test id of the band and the prefix of its inner ids (see `AgentVoiceCallBandViewProps.testId`). */
58
+ testId?: string;
43
59
  }
44
60
  /**
45
61
  * The band of the agent ringing this client and of the running (or just finished) voice chat; renders nothing while
@@ -4,6 +4,12 @@ export interface AgentVoiceCallCaptionsProps {
4
4
  agentSpaceId?: number;
5
5
  /** The theme of the owner's line, as the chat renders the owner's messages. Default: the message component's own. */
6
6
  ownerMessageTheme?: ConversationMessageUserTheme;
7
+ /**
8
+ * The test id of the captions; the agent's and the owner's lines take `${testId}-caption-agent` and
9
+ * `${testId}-caption-owner`. Default: `agent-voice-call-captions`, the lines `agent-voice-call-caption-agent` and
10
+ * `agent-voice-call-caption-owner`.
11
+ */
12
+ testId?: string;
7
13
  }
8
14
  /**
9
15
  * The end of the chat while a voice chat runs: what is being said that the chat does not hold yet, streamed from the
@@ -5,11 +5,19 @@ export interface AgentVoiceChatStartButtonProps {
5
5
  conversationId?: number;
6
6
  /** The owner may not start a voice chat here (the application's own gate). */
7
7
  disabled?: boolean;
8
+ /**
9
+ * Called in the click, synchronously, before the voice chat starts (before the microphone prompt and `open`): the
10
+ * place for what needs the user's gesture, such as opening a window for the chat. Default: nothing.
11
+ */
12
+ onStart?: () => void;
8
13
  testId?: string;
9
14
  }
10
15
  /**
11
16
  * In a chat input's send spot while nothing is typed and no voice chat runs: starts a voice chat with the agent. An
12
17
  * input outside the chat uses it too; the application shows the call's conversation when the provider reports it
13
18
  * (`onConversationOfCallChanged`). Disabled while a voice chat is connecting or live.
19
+ *
20
+ * Its label shows through the environment's tooltip when the application replaces the package's `Tooltip`
21
+ * (`AgentsEnvironment.components.Tooltip`); otherwise it is the button's `title`, as the browser shows it.
14
22
  */
15
23
  export declare const AgentVoiceChatStartButton: (props: AgentVoiceChatStartButtonProps) => import("react/jsx-runtime").JSX.Element;
@@ -10,6 +10,17 @@ export interface AgentVoiceIncomingCallProps {
10
10
  resolveCallerLabel?: (ring: AgentVoiceRing) => AgentVoiceCallerLabel | undefined;
11
11
  /** The application's avatar of the agent on the card. Default: the voice chat's mark. */
12
12
  renderAgentSpot?: () => ReactNode;
13
+ /**
14
+ * The stacking order of the card over the page, for an application whose layers need another one than the custom
15
+ * property sets. Default: `--agents-voice-incoming-call-z-index` (itself defaulting to 2147483000).
16
+ */
17
+ zIndex?: number;
18
+ /**
19
+ * The test id of the card; its inner elements take `${testId}-<part>` (`-detail`, `-decline`, `-accept`) and the card
20
+ * of a refused answer `${testId}-refusal`. Default: `agent-voice-incoming-call`, the inner elements their fixed
21
+ * `agent-voice-incoming-call-…` ids.
22
+ */
23
+ testId?: string;
13
24
  }
14
25
  /**
15
26
  * The agent ringing the owner in the browser window: the one listener per client. While a ring is live it publishes it
@@ -1,6 +1,8 @@
1
1
  export interface AgentVoiceInputGlowProps {
2
2
  /** The chat's agent space, where the application has one: a voice chat running in another one glows nowhere here. */
3
3
  agentSpaceId?: number;
4
+ /** The test id of the glow's box (it has no inner element with a test id). Default: `agent-voice-input-glow`. */
5
+ testId?: string;
4
6
  }
5
7
  /**
6
8
  * The chat input's glow during a voice chat; renders nothing while no voice chat is connecting or live. Rendered as
@@ -77,9 +77,21 @@ export interface CreateAgentVoiceApiOptions {
77
77
  baseApi: AgentVoiceBaseApi;
78
78
  /** Where the application mounts the voice session routes, without a trailing slash (`/api/agents/voiceSession`). */
79
79
  apiPrefix: string;
80
+ /**
81
+ * The whole path of `open`, for an application whose route names the agent space in its path:
82
+ * `(agentSpaceId) => "/api/spaces/" + agentSpaceId + "/voiceSession/open"`. `agentSpaceId` is what the start was
83
+ * given (undefined when it named none). The body is unchanged and still carries `agentSpaceId`; the other five routes
84
+ * stay below `apiPrefix`. Default: `${apiPrefix}/open`.
85
+ */
86
+ buildOpenPath?: AgentVoiceOpenPathBuilder;
80
87
  }
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) => {
88
+ /** The path of `open` for the agent space of the start (see `CreateAgentVoiceApiOptions.buildOpenPath`). */
89
+ export type AgentVoiceOpenPathBuilder = (agentSpaceId: number | undefined) => string;
90
+ /**
91
+ * The request of every operation, on `apiPrefix`, with the routes' own field names; `open` on `buildOpenPath` when
92
+ * given. Pure: nothing is sent.
93
+ */
94
+ export declare const buildAgentVoiceRequests: (apiPrefix: string, buildOpenPath?: AgentVoiceOpenPathBuilder) => {
83
95
  openSession: ({ agentSpaceId, sdpOffer, conversationId, callId, }: Parameters<AgentVoiceApi["openSession"]>[0]) => AgentVoiceRequest;
84
96
  hangUp: ({ callId, reason }: Parameters<AgentVoiceApi["hangUp"]>[0]) => AgentVoiceRequest;
85
97
  reportDeviceStatus: ({ callId, status, iceCandidateType, roundTripTimeMs, detail, occurredAtUnixMs, }: Parameters<AgentVoiceApi["reportDeviceStatus"]>[0]) => AgentVoiceRequest;
@@ -93,9 +105,9 @@ export declare const AGENT_VOICE_ERROR_CODE_INVALID_OPEN_ANSWER = "invalid_open_
93
105
  * The adapter for an application whose routes are the voice trait's own paths below `apiPrefix`, with the agent space
94
106
  * in the body of `open`:
95
107
  * `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.
108
+ * An application whose `open` names the space in its path adds `buildOpenPath`.
97
109
  */
98
- export declare const createAgentVoiceApi: ({ baseApi, apiPrefix }: CreateAgentVoiceApiOptions) => AgentVoiceApi;
110
+ export declare const createAgentVoiceApi: ({ baseApi, apiPrefix, buildOpenPath }: CreateAgentVoiceApiOptions) => AgentVoiceApi;
99
111
  /** What every request carries from the application: headers, credentials, mode, cache. */
100
112
  export type AgentVoiceFetchOptions = Omit<RequestInit, "method" | "body">;
101
113
  export interface CreateAgentVoiceFetchBaseApiOptions {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The test id of an inner element of a voice component: `${testId}-<part>` when the application gave the component a
3
+ * `testId`, else the element's own fixed id (`agent-voice-…`), so an application that sets none sees the ids it had.
4
+ */
5
+ export declare const agentVoicePartTestId: (testId: string | undefined, part: string, defaultTestId: string) => string;