@d-id/client-sdk 3.0.0-staging.414 → 3.0.0-staging.416

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 (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/index-DCAt0P7O.js +2062 -0
  4. package/dist/index.d.ts +3525 -0
  5. package/dist/index.js +1 -1
  6. package/dist/index.umd.cjs +13 -13
  7. package/dist/{index-DBWnR72S.js → livekit-client.esm-QkbCKsng.js} +6234 -8269
  8. package/dist/livekit-manager-Cj0YXe2U.js +557 -0
  9. package/package.json +33 -9
  10. package/dist/livekit-manager-BM3JMzT5.js +0 -531
  11. package/dist/src/api/agents.d.ts +0 -18
  12. package/dist/src/api/apiClient.d.ts +0 -11
  13. package/dist/src/api/apiClient.test.d.ts +0 -1
  14. package/dist/src/api/knowledge.d.ts +0 -15
  15. package/dist/src/api/streams/index.d.ts +0 -1
  16. package/dist/src/api/streams/streamApi.d.ts +0 -3
  17. package/dist/src/api/streams/streamApi.test.d.ts +0 -1
  18. package/dist/src/api/streams/streamsApiV2.d.ts +0 -5
  19. package/dist/src/auth/get-auth-header.d.ts +0 -5
  20. package/dist/src/auth/get-auth-header.test.d.ts +0 -1
  21. package/dist/src/config/consts.d.ts +0 -3
  22. package/dist/src/config/environment.d.ts +0 -5
  23. package/dist/src/errors/base-error.d.ts +0 -182
  24. package/dist/src/errors/chat/chat-creation-failed.d.ts +0 -30
  25. package/dist/src/errors/chat/chat-mode-downgraded.d.ts +0 -35
  26. package/dist/src/errors/errors.test.d.ts +0 -1
  27. package/dist/src/errors/http-error.d.ts +0 -74
  28. package/dist/src/errors/index.d.ts +0 -9
  29. package/dist/src/errors/network-error.d.ts +0 -72
  30. package/dist/src/errors/request-meta.d.ts +0 -12
  31. package/dist/src/errors/stream-error.d.ts +0 -37
  32. package/dist/src/errors/validation-error.d.ts +0 -67
  33. package/dist/src/errors/ws-error.d.ts +0 -34
  34. package/dist/src/index.d.ts +0 -20
  35. package/dist/src/public-api.test.d.ts +0 -1
  36. package/dist/src/services/agent-manager/connect-to-manager.d.ts +0 -19
  37. package/dist/src/services/agent-manager/connect-to-manager.test.d.ts +0 -1
  38. package/dist/src/services/agent-manager/index.d.ts +0 -64
  39. package/dist/src/services/agent-manager/index.test.d.ts +0 -1
  40. package/dist/src/services/analytics/mixpanel.d.ts +0 -22
  41. package/dist/src/services/analytics/mixpanel.test.d.ts +0 -1
  42. package/dist/src/services/analytics/timestamp-tracker.d.ts +0 -15
  43. package/dist/src/services/chat/index.d.ts +0 -10
  44. package/dist/src/services/chat/index.test.d.ts +0 -1
  45. package/dist/src/services/chat/intial-messages.d.ts +0 -3
  46. package/dist/src/services/chat/intial-messages.test.d.ts +0 -1
  47. package/dist/src/services/socket-manager/index.d.ts +0 -12
  48. package/dist/src/services/socket-manager/message-queue.d.ts +0 -12
  49. package/dist/src/services/socket-manager/message-queue.test.d.ts +0 -1
  50. package/dist/src/services/streaming-manager/advanced.test.d.ts +0 -1
  51. package/dist/src/services/streaming-manager/business-flows.test.d.ts +0 -5
  52. package/dist/src/services/streaming-manager/common.d.ts +0 -101
  53. package/dist/src/services/streaming-manager/data-channel-handlers.d.ts +0 -3
  54. package/dist/src/services/streaming-manager/disconnect.test.d.ts +0 -5
  55. package/dist/src/services/streaming-manager/edge-cases.test.d.ts +0 -1
  56. package/dist/src/services/streaming-manager/factory.d.ts +0 -13
  57. package/dist/src/services/streaming-manager/factory.test.d.ts +0 -1
  58. package/dist/src/services/streaming-manager/index.d.ts +0 -5
  59. package/dist/src/services/streaming-manager/livekit-manager.d.ts +0 -10
  60. package/dist/src/services/streaming-manager/livekit-manager.test.d.ts +0 -1
  61. package/dist/src/services/streaming-manager/stats/av-sync.d.ts +0 -3
  62. package/dist/src/services/streaming-manager/stats/av-sync.test.d.ts +0 -1
  63. package/dist/src/services/streaming-manager/stats/poll.d.ts +0 -16
  64. package/dist/src/services/streaming-manager/stats/report.d.ts +0 -19
  65. package/dist/src/services/streaming-manager/stats/report.test.d.ts +0 -1
  66. package/dist/src/services/streaming-manager/webrtc-core.test.d.ts +0 -1
  67. package/dist/src/services/streaming-manager/webrtc-manager.d.ts +0 -12
  68. package/dist/src/services/streaming-manager/webrtc-utils.test.d.ts +0 -5
  69. package/dist/src/test-utils/factories/agent-manager.factory.d.ts +0 -3
  70. package/dist/src/test-utils/factories/agent.factory.d.ts +0 -4
  71. package/dist/src/test-utils/factories/agents-api.factory.d.ts +0 -1
  72. package/dist/src/test-utils/factories/analytics.factory.d.ts +0 -1
  73. package/dist/src/test-utils/factories/chat.factory.d.ts +0 -1
  74. package/dist/src/test-utils/factories/index.d.ts +0 -8
  75. package/dist/src/test-utils/factories/socket-manager.factory.d.ts +0 -1
  76. package/dist/src/test-utils/factories/stream-api.factory.d.ts +0 -1
  77. package/dist/src/test-utils/factories/streaming-manager.factory.d.ts +0 -4
  78. package/dist/src/types/auth.d.ts +0 -95
  79. package/dist/src/types/entities/agents/agent.d.ts +0 -202
  80. package/dist/src/types/entities/agents/chat.d.ts +0 -476
  81. package/dist/src/types/entities/agents/index.d.ts +0 -3
  82. package/dist/src/types/entities/agents/manager.d.ts +0 -897
  83. package/dist/src/types/entities/avatar.d.ts +0 -21
  84. package/dist/src/types/entities/index.d.ts +0 -3
  85. package/dist/src/types/entities/knowledge/document.d.ts +0 -31
  86. package/dist/src/types/entities/knowledge/index.d.ts +0 -4
  87. package/dist/src/types/entities/knowledge/knowledge.d.ts +0 -56
  88. package/dist/src/types/entities/knowledge/record.d.ts +0 -24
  89. package/dist/src/types/entities/knowledge/retrival.d.ts +0 -9
  90. package/dist/src/types/face-rect.d.ts +0 -6
  91. package/dist/src/types/index.d.ts +0 -6
  92. package/dist/src/types/stream/api/clip.d.ts +0 -122
  93. package/dist/src/types/stream/api/index.d.ts +0 -2
  94. package/dist/src/types/stream/api/talk.d.ts +0 -77
  95. package/dist/src/types/stream/data-channel.d.ts +0 -16
  96. package/dist/src/types/stream/index.d.ts +0 -4
  97. package/dist/src/types/stream/rtc.d.ts +0 -125
  98. package/dist/src/types/stream/stream.d.ts +0 -856
  99. package/dist/src/types/stream/streams-v2.d.ts +0 -28
  100. package/dist/src/types/stream-script.d.ts +0 -138
  101. package/dist/src/types/voice/stt.d.ts +0 -16
  102. package/dist/src/types/voice/tts.d.ts +0 -238
  103. package/dist/src/utils/agent.d.ts +0 -8
  104. package/dist/src/utils/analytics.d.ts +0 -31
  105. package/dist/src/utils/analytics.test.d.ts +0 -1
  106. package/dist/src/utils/chat.d.ts +0 -4
  107. package/dist/src/utils/content-parser.d.ts +0 -35
  108. package/dist/src/utils/content-parser.test.d.ts +0 -1
  109. package/dist/src/utils/defer.d.ts +0 -7
  110. package/dist/src/utils/error-analytics.d.ts +0 -4
  111. package/dist/src/utils/error-analytics.test.d.ts +0 -1
  112. package/dist/src/utils/index.d.ts +0 -3
  113. package/dist/src/utils/retry-operation.d.ts +0 -38
  114. package/dist/src/utils/stream-end.d.ts +0 -5
  115. package/dist/src/utils/stream-end.test.d.ts +0 -1
  116. package/dist/src/utils/tool-calls.d.ts +0 -27
  117. package/dist/src/utils/tool-calls.test.d.ts +0 -1
  118. package/dist/src/utils/user-context.d.ts +0 -15
  119. package/dist/src/utils/user-context.test.d.ts +0 -1
  120. package/dist/src/version.d.ts +0 -7
@@ -1,202 +0,0 @@
1
- import { AvatarType } from '../avatar';
2
- import { Chat, ChatPayload, ChatResponse } from './chat';
3
-
4
- /**
5
- * The end-of-call feedback form configured on an agent.
6
- *
7
- * It describes what to ask the user when the conversation ends; the SDK does not render anything
8
- * itself. Read it from {@link Agent.end_of_call_feedback}, show your own form when
9
- * {@link EndOfCallFeedbackConfig.enabled | enabled} is set, and send the result with
10
- * {@link AgentManager.submitFeedback | submitFeedback()}.
11
- *
12
- * @category Agent Manager
13
- */
14
- export interface EndOfCallFeedbackConfig {
15
- /** Whether the agent is configured to ask for feedback when a call ends. */
16
- enabled: boolean;
17
- /** The line to show the user as the call ends, before the rating is asked for. */
18
- closing_message?: string;
19
- /** Whether a free-text follow-up question should be asked after the rating. */
20
- follow_up_enabled?: boolean;
21
- /**
22
- * The follow-up question to ask, chosen by the score the user gave.
23
- *
24
- * Whichever one you show is what {@link AgentManager.submitFeedback | submitFeedback()} records
25
- * as {@link SubmitFeedbackResponse.question_shown | question_shown}.
26
- */
27
- follow_up_messages?: {
28
- /** Question for a score at the low end of the scale. */
29
- low?: string;
30
- /** Question for a score of 4. */
31
- four?: string;
32
- /** Question for a score of 5. */
33
- five?: string;
34
- };
35
- }
36
- /**
37
- * The avatar an agent speaks through: its rendering tier and the language of its voice.
38
- *
39
- * The value of {@link Agent.avatar}. Its `type` is the single most important field on an agent: it
40
- * decides which transport the session uses and therefore which SDK features work.
41
- *
42
- * @category Agent Manager
43
- */
44
- export interface AgentAvatar {
45
- /**
46
- * The kind of avatar: {@link AvatarType.Talk | talk} for Talks (V2), {@link AvatarType.Clip | clip}
47
- * for Clips (V3), {@link AvatarType.Expressive | expressive} for Expressive (V4).
48
- *
49
- * Talks (V2) and Clips (V3) agents stream over WebRTC and receive their events on the
50
- * notifications web socket; Expressive (V4) agents connect to a real-time session instead, which
51
- * is what makes the microphone, camera, client tool and data-channel methods of
52
- * {@link AgentManager} available.
53
- */
54
- type: AvatarType;
55
- /** The voice the agent speaks with. */
56
- voice?: {
57
- /**
58
- * Language of the configured voice. The SDK reports it in analytics; it does not change how
59
- * the session behaves.
60
- */
61
- language?: string;
62
- };
63
- }
64
- /**
65
- * An agent's profile, as the Agents API returns it.
66
- *
67
- * The SDK fetches it once while {@link createAgentManager} runs and exposes it as
68
- * {@link AgentManager.agent}, so everything here is available before
69
- * {@link AgentManager.connect | connect()} — which is what makes it useful for rendering the agent
70
- * before the video exists. The fields are the agent's configuration, whether it was set in D-ID Studio
71
- * or through the Agents API; most of them are for the application to use, and each one below says
72
- * where the SDK itself reads it.
73
- *
74
- * @see [Get an agent](https://docs.d-id.com/reference/agent-get)
75
- * @category Agent Manager
76
- */
77
- export interface Agent {
78
- /** Id of the agent: the same value passed to {@link createAgentManager}. */
79
- id: string;
80
- /** Id of the D-ID account that owns the agent. Set by the Agents API. */
81
- owner_id?: string;
82
- /** The agent's display name. */
83
- name?: string;
84
- /** `'public'` when the agent is configured for public access; omitted otherwise. */
85
- access?: 'public';
86
- /** URL of the agent's still image. Use it as the poster of your video element before
87
- * {@link AgentManager.connect | connect()} has a stream to show. */
88
- thumbnail?: string;
89
- /**
90
- * The greeting lines configured for the agent.
91
- *
92
- * The SDK never speaks them by itself: pass one to {@link AgentManager.speak | speak()} once
93
- * the agent is connected if you want the agent to open the conversation. Check what your own
94
- * agent does first — an Expressive (V4) session's server side may greet on its own, in which
95
- * case speaking a greeting as well says it twice.
96
- */
97
- greetings?: string[];
98
- /**
99
- * Suggested opening questions to offer the user.
100
- *
101
- * The SDK surfaces the same array as {@link AgentManager.starterMessages | starterMessages}.
102
- */
103
- starter_message?: string[];
104
- /**
105
- * URL of the agent's looping idle video.
106
- *
107
- * Show it while the agent is not speaking: put it on your video element's `src` when
108
- * {@link AgentManagerCallbacks.onVideoStateChange | onVideoStateChange} reports `STOP`.
109
- */
110
- idle_video?: string;
111
- /**
112
- * The knowledge base attached to the agent, when it has one.
113
- *
114
- * Its presence is what tells you the agent can cite sources; the citations themselves arrive on
115
- * each answer as {@link Message.matches | matches}.
116
- */
117
- knowledge?: {
118
- /**
119
- * Id of the knowledge base.
120
- *
121
- * The SDK sends it with every rating made by {@link AgentManager.rate | rate()}, and it is
122
- * the {@link RetrievalMetadata.knowledge_id | knowledge_id} of the citations on an answer.
123
- */
124
- id: string;
125
- /** The embedding model the knowledge base was indexed with. The SDK does not act on it. */
126
- embedder?: {
127
- /** Whether that embedding model covers only a limited set of languages, so knowledge
128
- * written in another language may not be retrieved well. */
129
- is_limited_language?: boolean;
130
- };
131
- };
132
- /**
133
- * The avatar the agent is built on.
134
- *
135
- * Its `type` is the single most important field on an agent: it decides which transport the
136
- * session uses and therefore which SDK features work. See {@link AgentAvatar}.
137
- */
138
- avatar: AgentAvatar;
139
- /**
140
- * Whether vision is enabled for the agent.
141
- *
142
- * Exposed so an application can decide whether to offer the camera; the SDK does not read it,
143
- * and publishing a camera stream is an Expressive (V4) feature — see
144
- * {@link AgentManager.publishCameraStream | publishCameraStream()}.
145
- */
146
- vision?: {
147
- /** `true` when the agent is configured to use the user's camera. */
148
- enabled: boolean;
149
- };
150
- /**
151
- * The end-of-call feedback form configured for the agent.
152
- *
153
- * The SDK does not read it: render your own form from it and submit the result with
154
- * {@link AgentManager.submitFeedback | submitFeedback()}. See
155
- * {@link EndOfCallFeedbackConfig}.
156
- */
157
- end_of_call_feedback?: EndOfCallFeedbackConfig;
158
- /** Whether the agent has triggers configured. The SDK does not act on them. */
159
- triggers_available?: boolean;
160
- /** Settings that change how D-ID's own surfaces present the agent. */
161
- advanced_settings?: {
162
- /**
163
- * Whether the SDK logs its streaming lifecycle to the browser console.
164
- *
165
- * When it is enabled the SDK turns debug logging on for every visitor, whatever
166
- * {@link AgentManagerOptions.debug | debug} was passed to {@link createAgentManager}.
167
- */
168
- ui_debug_mode?: boolean;
169
- /**
170
- * Account the agent's rendering VM is billed to.
171
- *
172
- * @internal D-ID internal; not part of the public SDK contract.
173
- */
174
- vm_account_id?: string;
175
- /** Whether the embedding UI should show closed captions. The SDK does not act on it. */
176
- closed_captions_enabled?: boolean;
177
- };
178
- /**
179
- * Feature-flag targeting context for the account this agent belongs to.
180
- *
181
- * @internal D-ID internal; not part of the public SDK contract.
182
- */
183
- ld_context?: {
184
- /** Key identifying the context. */
185
- key: string;
186
- /** Hashed form of the key. */
187
- hash_key: string;
188
- /** The plan group the account falls into. */
189
- plan_group: string;
190
- };
191
- }
192
- /**
193
- * Internal HTTP client surface used by the agent manager to talk to the Agents API.
194
- * @internal Implementation type; not part of the public SDK surface.
195
- */
196
- export interface AgentsAPI {
197
- getRuntimeById(id: string, options?: RequestInit): Promise<Agent>;
198
- newChat(agentId: string, payload: {
199
- persist: boolean;
200
- }, options?: RequestInit): Promise<Chat>;
201
- chat(agentId: string, chatId: string, payload: ChatPayload, options?: RequestInit): Promise<ChatResponse>;
202
- }
@@ -1,476 +0,0 @@
1
- /**
2
- * A rating stored against one message of a chat, as the Agents API returns it.
3
- *
4
- * Produced by {@link AgentManager.rate | rate()} and returned again by
5
- * {@link AgentManager.deleteRate | deleteRate()}. Keep {@link Rating.id | id} if the user may
6
- * change their mind: pass it back to {@link AgentManager.rate | rate()} as `rateId` to update the
7
- * rating, or to {@link AgentManager.deleteRate | deleteRate()} to remove it.
8
- *
9
- * @category Chat
10
- */
11
- export interface Rating {
12
- /**
13
- * Id of this rating.
14
- *
15
- * Pass it as the `rateId` argument of {@link AgentManager.rate | rate()} to update the rating,
16
- * or to {@link AgentManager.deleteRate | deleteRate()} to remove it.
17
- */
18
- id: string;
19
- /** Id of the D-ID account that owns the agent the rating was left on. Set by the Agents API. */
20
- owner_id: string;
21
- /** Id of the agent whose answer was rated. */
22
- agent_id: string;
23
- /**
24
- * The knowledge citations that were attached to the rated answer, as `[document_id, id]` pairs.
25
- *
26
- * The SDK builds them from the {@link Message.matches | matches} of the rated message, so a
27
- * negative rating can be traced back to the documents the answer was drawn from. Empty when the
28
- * answer cited nothing.
29
- */
30
- matches: [string, string][];
31
- /**
32
- * Id of the agent's knowledge base ({@link Agent.knowledge}) at the time of the rating.
33
- *
34
- * An empty string when the agent has no knowledge base.
35
- */
36
- knowledge_id: string;
37
- /**
38
- * The end-user identifier the Agents API recorded for the request.
39
- *
40
- * Derived from the credentials the SDK sends, which carry
41
- * {@link AgentManagerOptions.externalId | externalId} for `type: 'key'` authorization.
42
- */
43
- external_id: string;
44
- /** Identity the Agents API attributed the rating to. Set by the Agents API. */
45
- created_by: string;
46
- /** Id of the chat the rated message belongs to — the value
47
- * {@link AgentManagerCallbacks.onNewChat | onNewChat} reported. */
48
- chat_id: string;
49
- /** The score itself: `1` for a positive rating, `-1` for a negative one. */
50
- score: 1 | -1;
51
- /** When the rating was created, as an ISO 8601 timestamp. */
52
- created_at: string;
53
- /** When the rating was last changed, as an ISO 8601 timestamp. */
54
- modified_at: string;
55
- /** {@link Message.id | Id of the message} that was rated. */
56
- message_id: string;
57
- }
58
- /**
59
- * Request payload for rating a chat message, derived from `Rating`.
60
- * @internal Implementation type; not part of the public SDK surface.
61
- */
62
- export type RatingPayload = Omit<Rating, 'owner_id' | 'id' | 'created_at' | 'modified_at' | 'created_by' | 'external_id' | 'agent_id' | 'chat_id'>;
63
- /**
64
- * What the Agents API stored when end-of-call feedback was submitted.
65
- *
66
- * Returned by {@link AgentManager.submitFeedback | submitFeedback()}, which rates the conversation
67
- * as a whole rather than a single answer.
68
- *
69
- * @category Chat
70
- */
71
- export interface SubmitFeedbackResponse {
72
- /** Id of the chat the feedback belongs to — the value
73
- * {@link AgentManagerCallbacks.onNewChat | onNewChat} reported. */
74
- chat_id: string;
75
- /** The score that was submitted, on the agent's end-of-call scale of 1 to 5. */
76
- rating: number;
77
- /**
78
- * The follow-up question the user was asked, when one was recorded.
79
- *
80
- * Applications pick it from {@link EndOfCallFeedbackConfig.follow_up_messages}.
81
- */
82
- question_shown?: string;
83
- /** When the feedback was stored, as an ISO 8601 timestamp. */
84
- submitted_at: string;
85
- }
86
- /**
87
- * One renderable piece of a message: a run of text, an image, a video or a link.
88
- *
89
- * {@link parseMessageParts} splits a message's {@link Message.content | content} into these, and
90
- * the SDK keeps the result on {@link Message.parts}. Switch on `type` when rendering. Anything the
91
- * parser did not recognise is preserved verbatim as a `text` part, in its original order, and
92
- * nothing is dropped or reordered; a recognised image, video or link replaces the markup it was
93
- * written as, so the parts are not a concatenation of the original string.
94
- *
95
- * @category Chat
96
- */
97
- export type MessagePart = {
98
- /** Discriminant: plain text that the parser found no markup in. */
99
- type: 'text';
100
- /** The text itself, exactly as it appeared in {@link Message.content}. */
101
- text: string;
102
- } | {
103
- /** Discriminant: an image, from markdown image syntax such as `![alt](url)`. */
104
- type: 'image';
105
- /** URL of the image. */
106
- src: string;
107
- /** The alt text from the markdown, or an empty string when it had none. */
108
- alt: string;
109
- /**
110
- * `image/gif` when the URL itself ends in `.gif`, ignoring case; absent otherwise.
111
- *
112
- * The check looks at the whole URL, so a query string or fragment suppresses it —
113
- * `cat.gif?v=2` carries no `mimeType`. Video detection differs: it strips both before
114
- * looking at the extension.
115
- */
116
- mimeType?: string;
117
- } | {
118
- /**
119
- * Discriminant: a video, either from thumbnail syntax (`[![alt](thumb)](video)`) or from
120
- * an image whose URL ends in `.mp4`, `.webm`, `.mkv`, `.mov`, `.m4v` or `.ogv` once any
121
- * query string and fragment have been stripped.
122
- */
123
- type: 'video';
124
- /** URL of the video file. */
125
- src: string;
126
- /** The alt text from the markdown, or an empty string when it had none. */
127
- alt: string;
128
- /** URL of the poster image, when the thumbnail syntax supplied one. */
129
- thumbnail?: string;
130
- } | {
131
- /** Discriminant: a link, from markdown `[label](url)` or from an HTML `<a href>`. */
132
- type: 'link';
133
- /** Target of the link. */
134
- href: string;
135
- /** The text shown for the link. */
136
- label: string;
137
- };
138
- /**
139
- * One message of a chat: what the user asked, or what the agent answered.
140
- *
141
- * The SDK keeps the whole transcript and hands a fresh copy of it to
142
- * {@link AgentManagerCallbacks.onNewMessage | onNewMessage} every time a message is added or
143
- * changed, oldest first. While an answer streams in, the last message's
144
- * {@link Message.content | content} and {@link Message.parts | parts} are replaced with the latest
145
- * text on each `partial` callback — not appended to — and are final on `answer`. The same shape is
146
- * accepted by {@link AgentManagerOptions.initialMessages | initialMessages} to seed a transcript.
147
- *
148
- * @category Chat
149
- */
150
- export interface Message {
151
- /**
152
- * Id of this message.
153
- *
154
- * Pass it to {@link AgentManager.rate | rate()} to rate the answer. The SDK generates a random
155
- * id for the messages it creates locally, and uses the id sent with the message for those that
156
- * arrive from the agent.
157
- */
158
- id: string;
159
- /**
160
- * Who the message is from.
161
- *
162
- * The SDK itself only creates `user` (the end user) and `assistant` (the agent) messages; the
163
- * value on a transcribed or streamed message is whatever the server payload carried. `system`,
164
- * `function` and `tool` exist because the underlying chat protocol allows them.
165
- */
166
- role?: 'system' | 'assistant' | 'user' | 'function' | 'tool';
167
- /**
168
- * The message text.
169
- *
170
- * Plain text, which for agent answers may contain markdown. It is replaced by the latest text
171
- * on every `partial` callback while the answer streams in — and the final `answer` may be
172
- * shorter than the partials before it, which is exactly how the SDK spots an interruption — so
173
- * render it as it is rather than appending to what you rendered before.
174
- */
175
- content: string;
176
- /**
177
- * {@link Message.content | content} split into renderable pieces by {@link parseMessageParts}.
178
- *
179
- * Kept in step with `content` on every message the SDK creates, including while an answer
180
- * streams in. Render these instead of the raw string when the agent may answer with images,
181
- * videos or links; a message with no markup is a single `text` part, and an empty message is
182
- * an empty array.
183
- *
184
- * {@link AgentManagerOptions.initialMessages | initialMessages} are treated the same way: the
185
- * SDK runs the parser over the `content` of any of them that arrives with empty or missing
186
- * `parts`, so a restored transcript can pass `parts: []` and still render. A non-empty array
187
- * you built yourself is kept exactly as given.
188
- */
189
- parts: MessagePart[];
190
- /** When the message was added, as an ISO 8601 timestamp. */
191
- createdAt?: string;
192
- /**
193
- * The knowledge citations the answer was drawn from, as {@link RetrievalMetadata} entries.
194
- *
195
- * Present on an agent answer when the chat response carried them, so a UI can show its sources;
196
- * {@link AgentManager.rate | rate()} also sends them with a rating. The SDK strips this field
197
- * from the transcript it sends back to the Agents API with the next
198
- * {@link AgentManager.chat | chat()}.
199
- */
200
- matches?: ChatResponse['matches'];
201
- /**
202
- * The retrieved context the answer was generated from, as
203
- * {@link ChatResponse.context | the chat response} supplied it.
204
- *
205
- * Only ever set on an agent answer, and only when the answer came back from the Agents API.
206
- * Expressive (V4) agents chat over the data channel instead, so their answers carry no context
207
- * — except in {@link ChatMode.Playground}, which always takes the Agents API path.
208
- */
209
- context?: string;
210
- /**
211
- * `true` when the answer was cut short instead of being spoken to the end.
212
- *
213
- * Set on the last message by {@link AgentManager.interrupt | interrupt()}, and by the SDK when
214
- * the final answer turns out to be shorter than the partial text already received — which is
215
- * how it detects that the agent was interrupted mid-utterance.
216
- */
217
- interrupted?: boolean;
218
- /**
219
- * `true` when this user message came from speech-to-text rather than from
220
- * {@link AgentManager.chat | chat()}.
221
- *
222
- * It is what distinguishes an utterance the user spoke from one they typed.
223
- */
224
- transcribed?: boolean;
225
- /**
226
- * The sentiment the agent delivered this answer with, when the stream reported one.
227
- *
228
- * Taken from the metadata the server sends with the video it created, and attached to the most
229
- * recent agent answer. The SDK only ever fills it in from an Expressive (V4) session, and only
230
- * while {@link AgentManagerOptions.debug | debug} is enabled.
231
- */
232
- sentiment?: MessageSentiment;
233
- }
234
- /**
235
- * The sentiment an agent answer was delivered with, as the server reported it.
236
- *
237
- * The shape of {@link Message.sentiment}. It is an object rather than a string because the server
238
- * reports both the id of the sentiment it used and its name, where
239
- * {@link TextStreamScript.sentiment} — the sentiment the application *asks* for — is just the
240
- * name.
241
- *
242
- * @category Chat
243
- */
244
- export interface MessageSentiment {
245
- /** Id of the sentiment, as the server sent it. */
246
- id: string;
247
- /** Name of the sentiment, as the server sent it. */
248
- name: string;
249
- }
250
- /**
251
- * Request payload for sending a chat message to the Agents API.
252
- * @internal Implementation type; not part of the public SDK surface.
253
- */
254
- export interface ChatPayload {
255
- messages: Message[];
256
- streamId?: string;
257
- sessionId?: string;
258
- chatMode?: ChatMode;
259
- }
260
- /**
261
- * One knowledge citation: the passage of the agent's knowledge base an answer was drawn from.
262
- *
263
- * The Agents API returns these with an answer and the SDK keeps them on
264
- * {@link Message.matches | matches}, so a UI can show the sources behind a reply.
265
- *
266
- * @category Chat
267
- */
268
- export interface RetrievalMetadata {
269
- /** Id of this match. Sent back with a rating as the second half of a
270
- * {@link Rating.matches} pair. */
271
- id: string;
272
- /** The matched passage itself, as stored in the knowledge base. */
273
- data: string;
274
- /** Title of the document the passage comes from. */
275
- title: string;
276
- /** Id of the source document. Sent back with a rating as the first half of a
277
- * {@link Rating.matches} pair. */
278
- document_id: string;
279
- /** Id of the knowledge base the document belongs to — the agent's {@link Agent.knowledge}. */
280
- knowledge_id: string;
281
- /** URL of the original source, for linking the citation out of the chat. */
282
- source_url: string;
283
- }
284
- /**
285
- * How the agent answers: with a streamed video, as text only, or not at all.
286
- *
287
- * Chosen with {@link AgentManagerOptions.mode | mode} and changed later with
288
- * {@link AgentManager.changeMode | changeMode()}, which reports the new value through
289
- * {@link AgentManagerCallbacks.onModeChange | onModeChange}. Switching to anything other than
290
- * {@link ChatMode.Functional} disconnects the stream. What the mode decides at creation time is
291
- * narrower than it looks: whether a chat is created for the session, and whether the notifications
292
- * web socket is opened. {@link AgentManager.connect | connect()} establishes the video stream in
293
- * every mode. The server can also answer with a different mode than the one asked for when the chat
294
- * is created; the SDK then adopts it and reports a {@link ChatModeDowngraded} error through
295
- * {@link AgentManagerCallbacks.onError | onError}.
296
- *
297
- * @category Chat
298
- */
299
- export declare enum ChatMode {
300
- /**
301
- * Chat and video: the agent answers questions with its own LLM, in a streamed video.
302
- *
303
- * The default when {@link AgentManagerOptions.mode | mode} is omitted, and the only mode a
304
- * session can be in while a stream is connected and chat is available at the same time:
305
- * {@link AgentManager.changeMode | changeMode()} to any other value disconnects the stream.
306
- */
307
- Functional = "Functional",
308
- /**
309
- * Text answers only: the chat works, but no video is produced.
310
- *
311
- * {@link AgentManager.chat | chat()} still returns answers through
312
- * {@link AgentManagerCallbacks.onNewMessage | onNewMessage}, and
313
- * {@link AgentManager.speak | speak()} adds a text script to the transcript but streams no
314
- * video: it resolves with a `duration` of `0` and an empty `videoId`.
315
- */
316
- TextOnly = "TextOnly",
317
- /**
318
- * The agent is unavailable: {@link AgentManager.chat | chat()} throws a
319
- * {@link ValidationError}.
320
- *
321
- * The SDK switches to it by itself when connecting fails after its retries, so a UI can show
322
- * that the agent is temporarily out of service; the server can also return it when a chat is
323
- * created. Like {@link ChatMode.TextOnly} it produces no video.
324
- */
325
- Maintenance = "Maintenance",
326
- /**
327
- * A text-only test conversation, used by the agent playground in D-ID Studio.
328
- *
329
- * Produces no video, and marks each chat request with a playground header so the Agents API
330
- * can treat it as a test. Chats in this mode always go over the Agents API, even for
331
- * Expressive (V4) agents, which otherwise chat over the data channel. Applications normally
332
- * use {@link ChatMode.Functional} or {@link ChatMode.TextOnly} instead.
333
- */
334
- Playground = "Playground",
335
- /**
336
- * Speak-only: no chat is created for the session, while video still streams.
337
- *
338
- * Talks (V2) and Clips (V3) agents only; {@link createAgentManager} and
339
- * {@link AgentManager.changeMode | changeMode()} reject it with a {@link ValidationError} for
340
- * Expressive (V4) agents.
341
- *
342
- * {@link AgentManager.chat | chat()} throws a {@link ValidationError} — but only when this was
343
- * the mode {@link createAgentManager} was given, because that guard reads the creation-time
344
- * mode rather than the current one; arriving here later through
345
- * {@link AgentManager.changeMode | changeMode()} leaves {@link AgentManager.chat | chat()}
346
- * working. Chosen at creation time it also skips the notifications web socket. Use it when
347
- * the application drives the agent entirely through {@link AgentManager.speak | speak()} and
348
- * never asks its LLM anything. The stream keeps running only when this is the mode
349
- * {@link createAgentManager} was given; switching into it later with
350
- * {@link AgentManager.changeMode | changeMode()} disconnects the stream like any other
351
- * non-{@link ChatMode.Functional} mode.
352
- */
353
- DirectPlayback = "DirectPlayback",
354
- /**
355
- * Chat is switched off: no chat is created for the session, while video still streams.
356
- *
357
- * Talks (V2) and Clips (V3) agents only; {@link createAgentManager} and
358
- * {@link AgentManager.changeMode | changeMode()} reject it with a {@link ValidationError} for
359
- * Expressive (V4) agents.
360
- *
361
- * {@link AgentManager.chat | chat()} throws a {@link ValidationError} under the same
362
- * creation-time rule as {@link ChatMode.DirectPlayback}. The one difference between the two is
363
- * the notifications web socket: this mode still opens it on a Talks (V2) or Clips (V3) agent,
364
- * where {@link ChatMode.DirectPlayback} skips it. As with {@link ChatMode.DirectPlayback}, the
365
- * stream keeps running only when this is the mode set at creation; switching into it later with
366
- * {@link AgentManager.changeMode | changeMode()} disconnects the stream.
367
- */
368
- Off = "Off"
369
- }
370
- /**
371
- * What the Agents API answers a chat request with.
372
- *
373
- * Returned by {@link AgentManager.chat | chat()}. The SDK has already added the answer to the
374
- * transcript by the time you get it, so most applications render
375
- * {@link AgentManagerCallbacks.onNewMessage | onNewMessage} instead and use this only for the
376
- * fields that never reach a {@link Message}. Expressive (V4) agents chat over the data channel
377
- * rather than over the Agents API — except in {@link ChatMode.Playground} — so for them the
378
- * object is empty and the answer arrives through the callback.
379
- *
380
- * @category Chat
381
- */
382
- export interface ChatResponse {
383
- /**
384
- * The agent's answer.
385
- *
386
- * Empty or absent when the answer is delivered as it is generated instead, which is what
387
- * streaming modes do; the SDK then adds no message for it and the text arrives through
388
- * {@link AgentManagerCallbacks.onNewMessage | onNewMessage}.
389
- */
390
- result?: string;
391
- /**
392
- * The Agents API's own list of ids for the documents behind the answer. The SDK never reads it;
393
- * {@link ChatResponse.matches | matches} is what it keeps on the message.
394
- */
395
- documentIds?: string[];
396
- /**
397
- * The knowledge citations behind the answer.
398
- *
399
- * Copied onto the answer as {@link Message.matches | matches}.
400
- */
401
- matches?: RetrievalMetadata[];
402
- /**
403
- * The {@link ChatMode} the server handled the request in.
404
- *
405
- * It can differ from the mode that was asked for — see {@link ChatMode}.
406
- */
407
- chatMode?: ChatMode;
408
- /**
409
- * The retrieved context the answer was generated from.
410
- *
411
- * Copied onto the answer as {@link Message.context | context}.
412
- */
413
- context?: string;
414
- /** Id of the video generated for the answer, when the server reported one. */
415
- videoId?: string;
416
- }
417
- /**
418
- * A conversation with an agent, as the Agents API stores it.
419
- * @internal Wire type of the Agents API; not part of the public SDK surface. The only part an
420
- * application sees is the chat id, reported by
421
- * {@link AgentManagerCallbacks.onNewChat | onNewChat}.
422
- */
423
- export interface Chat {
424
- /** Id of the chat. The value handed to
425
- * {@link AgentManagerCallbacks.onNewChat | onNewChat}. */
426
- id: string;
427
- /** Id of the agent this conversation is with. */
428
- agent_id: string;
429
- /** When the chat was created, as an ISO 8601 timestamp. */
430
- created: string;
431
- /** When the chat was last changed, as an ISO 8601 timestamp. */
432
- modified: string;
433
- /** Id of the D-ID account that owns the chat. Set by the API; on the synthetic chat the SDK
434
- * builds for an Expressive (V4) session it is copied from {@link Agent.owner_id}. */
435
- owner_id: string;
436
- /**
437
- * The messages stored with the chat.
438
- *
439
- * The SDK never reads this array — the live transcript is the one handed to
440
- * {@link AgentManagerCallbacks.onNewMessage | onNewMessage} — and it is empty on the chat the
441
- * SDK builds for an Expressive (V4) session.
442
- */
443
- messages: Message[];
444
- /** A composite sort key the API uses to list an agent's chats by creation time. Not meaningful
445
- * to clients. */
446
- agent_id__created_at: string;
447
- /** A composite sort key the API uses to list an agent's chats by modification time. Not
448
- * meaningful to clients. */
449
- agent_id__modified_at: string;
450
- /**
451
- * The {@link ChatMode} the chat was created in.
452
- *
453
- * {@link AgentManager.connect | connect()} adopts it, which is how the server can downgrade the
454
- * mode an application asked for.
455
- */
456
- chat_mode?: ChatMode;
457
- }
458
- /**
459
- * What caused the user to interrupt the agent, passed to
460
- * {@link AgentManager.interrupt | interrupt()}.
461
- *
462
- * @category Chat
463
- */
464
- export interface InterruptOptions {
465
- /**
466
- * The cause: `text` when the user typed over the answer, `audio` when they started speaking,
467
- * `click` when they pressed a stop control, and `manual` for an interruption the application
468
- * decided on itself.
469
- *
470
- * The SDK records it with the interruption for analytics. It changes behaviour in one case
471
- * only: Expressive (V4) agents ignore a `text` interrupt, because their orchestrator does not
472
- * cancel the answer already in flight. Talks (V2) and Clips (V3) agents interrupt the current
473
- * video whatever the value.
474
- */
475
- type: 'text' | 'audio' | 'click' | 'manual';
476
- }
@@ -1,3 +0,0 @@
1
- export * from './agent';
2
- export * from './chat';
3
- export * from './manager';