@d-id/client-sdk 2.0.10 → 3.0.0-staging.413

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 (49) hide show
  1. package/README.md +54 -265
  2. package/dist/{index-K6rHpqny.js → index-BOeL7MEm.js} +3002 -2825
  3. package/dist/index.js +23 -31
  4. package/dist/index.umd.cjs +5 -5
  5. package/dist/{livekit-manager-25aUaO_G.js → livekit-manager-D-B3qdMq.js} +53 -50
  6. package/dist/src/api/agents.d.ts +1 -1
  7. package/dist/src/api/apiClient.d.ts +1 -1
  8. package/dist/src/api/knowledge.d.ts +1 -1
  9. package/dist/src/api/streams/streamApi.d.ts +1 -1
  10. package/dist/src/api/streams/streamsApiV2.d.ts +1 -1
  11. package/dist/src/errors/base-error.d.ts +170 -1
  12. package/dist/src/errors/chat/chat-creation-failed.d.ts +24 -0
  13. package/dist/src/errors/chat/chat-mode-downgraded.d.ts +29 -0
  14. package/dist/src/errors/http-error.d.ts +67 -5
  15. package/dist/src/errors/index.d.ts +1 -0
  16. package/dist/src/errors/network-error.d.ts +62 -8
  17. package/dist/src/errors/request-meta.d.ts +12 -0
  18. package/dist/src/errors/stream-error.d.ts +32 -0
  19. package/dist/src/errors/validation-error.d.ts +62 -1
  20. package/dist/src/errors/ws-error.d.ts +29 -0
  21. package/dist/src/index.d.ts +18 -4
  22. package/dist/src/public-api.test.d.ts +1 -0
  23. package/dist/src/services/agent-manager/index.d.ts +46 -6
  24. package/dist/src/services/chat/intial-messages.test.d.ts +1 -0
  25. package/dist/src/services/streaming-manager/common.d.ts +8 -3
  26. package/dist/src/types/auth.d.ts +78 -6
  27. package/dist/src/types/entities/agents/agent.d.ts +152 -6
  28. package/dist/src/types/entities/agents/chat.d.ts +384 -12
  29. package/dist/src/types/entities/agents/manager.d.ts +795 -215
  30. package/dist/src/types/entities/avatar.d.ts +21 -0
  31. package/dist/src/types/entities/index.d.ts +1 -1
  32. package/dist/src/types/entities/knowledge/document.d.ts +7 -8
  33. package/dist/src/types/entities/knowledge/knowledge.d.ts +20 -0
  34. package/dist/src/types/entities/knowledge/record.d.ts +8 -0
  35. package/dist/src/types/entities/knowledge/retrival.d.ts +4 -0
  36. package/dist/src/types/stream/api/clip.d.ts +8 -9
  37. package/dist/src/types/stream/api/talk.d.ts +8 -9
  38. package/dist/src/types/stream/rtc.d.ts +54 -4
  39. package/dist/src/types/stream/stream.d.ts +553 -34
  40. package/dist/src/types/stream/streams-v2.d.ts +12 -0
  41. package/dist/src/types/stream-script.d.ts +92 -19
  42. package/dist/src/types/voice/stt.d.ts +12 -0
  43. package/dist/src/types/voice/tts.d.ts +149 -64
  44. package/dist/src/utils/analytics.d.ts +2 -2
  45. package/dist/src/utils/content-parser.d.ts +31 -0
  46. package/dist/src/utils/tool-calls.d.ts +21 -2
  47. package/dist/src/version.d.ts +6 -0
  48. package/package.json +7 -3
  49. package/dist/src/types/entities/video.d.ts +0 -6
@@ -1,12 +1,74 @@
1
1
  import { BaseError, ErrorJson } from './base-error';
2
+ import { RequestMeta } from './request-meta';
2
3
 
4
+ /**
5
+ * A request to the Agents API came back with a non-2xx status.
6
+ *
7
+ * Raised for every REST call the SDK makes on the application's behalf: fetching the agent in
8
+ * {@link createAgentManager}, creating the stream and the chat during
9
+ * {@link AgentManager.connect | connect()}, sending a message with
10
+ * {@link AgentManager.chat | chat()}, and the rating and feedback calls. The same error is both
11
+ * handed to {@link AgentManagerCallbacks.onError | onError} and thrown, so it also rejects the
12
+ * promise of whichever method made the request — catch it around that call, or handle it centrally
13
+ * in the callback. For the message-send request behind {@link AgentManager.chat | chat()} the
14
+ * callback may not fire; the error is still thrown. Typical cases are `401` or `403` for a client
15
+ * key that is not authorized for the agent or the calling domain, and `404` for an unknown agent
16
+ * id; an account that is out of credits comes back with {@link BaseError.kind | kind}
17
+ * `'InsufficientCreditsError'`. A `429` is retried twice, one second apart (three attempts in
18
+ * total), before it surfaces.
19
+ *
20
+ * {@link BaseError.kind | kind} is the server's own classification when the response body is D-ID's
21
+ * `{ kind, description }` envelope — the `'InsufficientCreditsError'` above is one — and
22
+ * `'HttpError'` otherwise, so a message-independent branch on a specific API failure is possible.
23
+ *
24
+ * The message is the envelope's `description` when the body is that JSON, and the raw body
25
+ * otherwise — truncated to 256 characters either way, because a gateway can answer a 5xx with a
26
+ * whole HTML page.
27
+ *
28
+ * @category Errors
29
+ */
3
30
  export declare class HttpError extends BaseError {
31
+ /**
32
+ * The server's own classification of the failure, and `'HttpError'` when the response body was
33
+ * not D-ID's `{ kind, description }` envelope.
34
+ *
35
+ * The only {@link BaseError.kind | kind} in the SDK that is not a fixed literal, so it stays
36
+ * typed `string`: an account out of credits comes back as `'InsufficientCreditsError'`, for
37
+ * instance. Use {@link HttpError.status | status} for the transport-level branch and this for
38
+ * the API-level one.
39
+ */
40
+ readonly kind: string;
41
+ /**
42
+ * HTTP status code of the response, such as `401`, `404` or `500`.
43
+ */
4
44
  readonly status: number;
5
- readonly url?: string;
45
+ /**
46
+ * Path of the request that failed, relative to the API client's base path — for example
47
+ * `/agt_x/chat/cht_y` for a message sent to a chat.
48
+ *
49
+ * Absent when the error was constructed without call context. {@link NetworkError.endpoint}
50
+ * is the same value on a transport failure.
51
+ */
52
+ readonly endpoint?: string;
53
+ /**
54
+ * HTTP method of the request that failed, such as `GET` or `POST`.
55
+ *
56
+ * Absent when the error was constructed without call context.
57
+ */
6
58
  readonly method?: string;
7
- constructor(status: number, body: string, meta?: {
8
- url?: string;
9
- method?: string;
10
- });
59
+ /**
60
+ * Builds the error from the failing response.
61
+ * @internal The SDK builds this itself; applications catch the error rather than construct it.
62
+ */
63
+ constructor(status: number, body: string, meta?: RequestMeta);
64
+ /**
65
+ * Serializes the error, adding the failing call to what
66
+ * {@link BaseError.toJson | BaseError.toJson()} already returns.
67
+ *
68
+ * Adds `httpStatus` from {@link HttpError.status | status}, and `endpoint` and `method` when the
69
+ * call context is known. The raw `status` property is serialized as `httpStatus`.
70
+ *
71
+ * @returns The error as plain, JSON-serializable data.
72
+ */
11
73
  toJson(): ErrorJson;
12
74
  }
@@ -3,6 +3,7 @@ export * from './chat/chat-creation-failed';
3
3
  export * from './chat/chat-mode-downgraded';
4
4
  export * from './http-error';
5
5
  export * from './network-error';
6
+ export * from './request-meta';
6
7
  export * from './stream-error';
7
8
  export * from './validation-error';
8
9
  export * from './ws-error';
@@ -1,18 +1,72 @@
1
1
  import { BaseError, ErrorJson } from './base-error';
2
+ import { RequestMeta } from './request-meta';
2
3
 
3
- export interface NetworkErrorMeta {
4
- url?: string;
5
- method?: string;
6
- durationMs?: number;
7
- online?: boolean;
8
- visibility?: DocumentVisibilityState;
9
- }
4
+ /**
5
+ * A request to the Agents API never reached the server, so no response came back.
6
+ *
7
+ * This is the transport failure counterpart of {@link HttpError}, where the server did answer: the
8
+ * browser's `fetch` rejected outright because the device is offline, DNS or TLS failed, the
9
+ * connection was refused or the request was blocked, for instance by CORS or an extension. Like
10
+ * {@link HttpError} it is both handed to {@link AgentManagerCallbacks.onError | onError} and
11
+ * thrown, so it also rejects the promise of the method that made the request; for the message-send
12
+ * request behind {@link AgentManager.chat | chat()} the callback may not fire, but the error is
13
+ * still thrown. A request the SDK cancelled itself is not reported this way — the browser's own
14
+ * `AbortError` is rethrown unchanged.
15
+ *
16
+ * The message is always `'Network request failed'`; the browser's own wording, such as
17
+ * `'Failed to fetch'`, is kept in {@link BaseError.originalError | originalError} and appears as
18
+ * `cause` in {@link NetworkError.toJson | toJson()}. The remaining properties record what was
19
+ * happening at the time, which is usually what distinguishes a dropped connection from a tab that
20
+ * was backgrounded.
21
+ *
22
+ * @category Errors
23
+ */
10
24
  export declare class NetworkError extends BaseError {
25
+ /**
26
+ * Always `'NetworkError'`. Branch on it to tell this failure from the other SDK errors.
27
+ */
28
+ readonly kind: 'NetworkError';
29
+ /**
30
+ * Path of the request that failed, relative to the API client's base path — for example
31
+ * `/agt_x/chat/cht_y`.
32
+ */
11
33
  readonly endpoint?: string;
34
+ /**
35
+ * HTTP method of the request that failed, such as `GET` or `POST`.
36
+ */
12
37
  readonly method?: string;
38
+ /**
39
+ * How long the request ran before it failed, in milliseconds.
40
+ *
41
+ * A value close to zero usually means the request never left the browser; a large one points
42
+ * at a connection that was established and then lost.
43
+ */
13
44
  readonly durationMs?: number;
45
+ /**
46
+ * The browser's `navigator.onLine` at the moment of the failure — `false` when the device
47
+ * reported itself offline.
48
+ */
14
49
  readonly online?: boolean;
50
+ /**
51
+ * The page's `document.visibilityState` at the moment of the failure.
52
+ *
53
+ * `'hidden'` means the tab was in the background, where browsers throttle or suspend network
54
+ * activity.
55
+ */
15
56
  readonly visibility?: DocumentVisibilityState;
16
- constructor(originalError?: unknown, meta?: NetworkErrorMeta);
57
+ /**
58
+ * Wraps a rejected `fetch` together with what was known about the call.
59
+ * @internal The SDK builds this itself; applications catch the error rather than construct it.
60
+ */
61
+ constructor(originalError?: unknown, meta?: RequestMeta);
62
+ /**
63
+ * Serializes the error, adding the captured context to what
64
+ * {@link BaseError.toJson | BaseError.toJson()} already returns.
65
+ *
66
+ * Each of `endpoint`, `method`, `durationMs`, `online` and `visibility` is included only when it
67
+ * was captured.
68
+ *
69
+ * @returns The error as plain, JSON-serializable data.
70
+ */
17
71
  toJson(): ErrorJson;
18
72
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Request context recorded on an error: what was requested, how long it took and what the tab
3
+ * could see of the network at the time. Shared by `HttpError` and `NetworkError`.
4
+ * @internal Implementation type; not part of the public SDK surface.
5
+ */
6
+ export interface RequestMeta {
7
+ endpoint?: string;
8
+ method?: string;
9
+ durationMs?: number;
10
+ online?: boolean;
11
+ visibility?: DocumentVisibilityState;
12
+ }
@@ -1,5 +1,37 @@
1
1
  import { BaseError } from './base-error';
2
2
 
3
+ /**
4
+ * Something went wrong inside the live audio and video stream.
5
+ *
6
+ * Unlike {@link HttpError} and {@link NetworkError}, which come from REST calls, this one comes
7
+ * from the transport carrying the agent's video, so it is only ever delivered to
8
+ * {@link AgentManagerCallbacks.onError | onError} — no call of yours is necessarily in flight when
9
+ * it happens, and nothing throws it. The SDK raises it when:
10
+ *
11
+ * - no media track is subscribed within the timeout after the LiveKit room used by Expressive (V4)
12
+ * agents connects, after which the SDK disconnects the stream;
13
+ * - the LiveKit room reports a media-device or encryption failure;
14
+ * - a message cannot be put on the data channel — the WebRTC channel used by Talks (V2) and Clips
15
+ * (V3) is not open, or the LiveKit room is not connected or rejects the send;
16
+ * - the server reports that the stream itself failed, with the message
17
+ * `Stream failed with event <event>`.
18
+ *
19
+ * Most of these leave the session unusable, so the useful response is to tell the user and call
20
+ * {@link AgentManager.reconnect | reconnect()}. {@link BaseError.kind | kind} is `'StreamError'`.
21
+ * The message describes the failure, and is the plain `'Stream Error'` when the transport gave no
22
+ * detail; the underlying error, where there was one, is kept as
23
+ * {@link BaseError.originalError | originalError}.
24
+ *
25
+ * @category Errors
26
+ */
3
27
  export declare class StreamError extends BaseError {
28
+ /**
29
+ * Always `'StreamError'`. Branch on it to tell this failure from the other SDK errors.
30
+ */
31
+ readonly kind: 'StreamError';
32
+ /**
33
+ * Wraps a streaming failure.
34
+ * @internal The SDK builds this itself; applications catch the error rather than construct it.
35
+ */
4
36
  constructor(message: string, originalError?: unknown);
5
37
  }
@@ -1,6 +1,67 @@
1
1
  import { BaseError } from './base-error';
2
2
 
3
+ /**
4
+ * A method was called with arguments, or in a state, that the SDK will not send to the Agents
5
+ * API.
6
+ *
7
+ * This is one of the two SDK errors that only ever reach the caller and are never delivered to
8
+ * {@link AgentManagerCallbacks.onError | onError} (the other is {@link ChatCreationFailed}): it is
9
+ * the direct answer to the call you just made, and every method that raises it rejects the promise
10
+ * it returned, so `await` the call inside a `try`/`catch` or attach a `.catch()`. The SDK raises it
11
+ * from
12
+ * {@link AgentManager.chat | chat()} when the message is empty or 2000 characters or longer, when
13
+ * the session's {@link ChatMode} has chat disabled or is in maintenance, and when the chat or the
14
+ * stream has not been initialized yet; from {@link AgentManager.speak | speak()} when it is called
15
+ * before {@link AgentManager.connect | connect()}; and from
16
+ * {@link AgentManager.rate | rate()}, {@link AgentManager.deleteRate | deleteRate()} and
17
+ * {@link AgentManager.submitFeedback | submitFeedback()} when no chat has started, plus, for
18
+ * `rate()` alone, when no message with the given id is in the transcript. It is also raised from
19
+ * {@link createAgentManager} and {@link AgentManager.changeMode | changeMode()} when an Expressive
20
+ * (V4) agent is asked for {@link ChatMode.Off} or {@link ChatMode.DirectPlayback}, which only Talks
21
+ * (V2) and Clips (V3) agents support. The five Expressive-only media methods —
22
+ * {@link AgentManager.publishMicrophoneStream | publishMicrophoneStream()},
23
+ * {@link AgentManager.replaceMicrophoneTrack | replaceMicrophoneTrack()},
24
+ * {@link AgentManager.publishCameraStream | publishCameraStream()},
25
+ * {@link AgentManager.setSttLanguage | setSttLanguage()} and
26
+ * {@link AgentManager.sendDataChannelMessage | sendDataChannelMessage()} — raise it the other way
27
+ * round: when the session is a Talks (V2) or Clips (V3) one, or
28
+ * {@link AgentManager.connect | connect()} has not run yet.
29
+ *
30
+ * Nothing was sent to the Agents API when this is raised, so the session stays usable: fix the
31
+ * argument or wait for {@link ConnectionState.Connected | 'connected'} and call again.
32
+ * {@link BaseError.kind | kind} is `'ValidationError'`.
33
+ *
34
+ * @category Errors
35
+ */
3
36
  export declare class ValidationError extends BaseError {
37
+ /**
38
+ * Name of the field the failure is about.
39
+ *
40
+ * The SDK does not populate it — every validation it raises passes the message alone — so it
41
+ * is only set on a `ValidationError` an application constructed itself. It is also left out
42
+ * of {@link BaseError.toJson | toJson()}, so a serialized validation error carries only its
43
+ * kind and message.
44
+ */
4
45
  readonly key?: string | undefined;
5
- constructor(message: string, key?: string | undefined);
46
+ /**
47
+ * Always `'ValidationError'`. Branch on it to tell this failure from the other SDK errors.
48
+ */
49
+ readonly kind: 'ValidationError';
50
+ /**
51
+ * Builds a validation failure. The SDK does this itself before it performs a request.
52
+ *
53
+ * @param message - What was wrong with the call, such as `'Message cannot be empty'`.
54
+ * @param key - Name of the field the failure is about. The SDK's own validations leave it
55
+ * unset.
56
+ */
57
+ constructor(message: string,
58
+ /**
59
+ * Name of the field the failure is about.
60
+ *
61
+ * The SDK does not populate it — every validation it raises passes the message alone — so it
62
+ * is only set on a `ValidationError` an application constructed itself. It is also left out
63
+ * of {@link BaseError.toJson | toJson()}, so a serialized validation error carries only its
64
+ * kind and message.
65
+ */
66
+ key?: string | undefined);
6
67
  }
@@ -1,5 +1,34 @@
1
1
  import { BaseError } from './base-error';
2
2
 
3
+ /**
4
+ * The web socket the SDK uses for chat notifications failed to connect.
5
+ *
6
+ * Talks (V2) and Clips (V3) sessions open a web socket alongside the video stream; the agent's
7
+ * answer arrives over it as `partial` and `answer` events, which is what drives
8
+ * {@link AgentManagerCallbacks.onNewMessage | onNewMessage}. This error is raised when that socket
9
+ * emits an `error` event, once per failed attempt while
10
+ * {@link AgentManager.connect | connect()} is retrying. It is only delivered to
11
+ * {@link AgentManagerCallbacks.onError | onError} and never thrown, so there is nothing to catch
12
+ * around `connect()` for it; if every attempt fails, `connect()` rejects with the browser's own
13
+ * socket event instead.
14
+ *
15
+ * The socket is not opened at all for Expressive (V4) agents, which receive the same events over
16
+ * the LiveKit data channel, nor in {@link ChatMode.DirectPlayback | DirectPlayback} mode, so the
17
+ * error cannot occur in either case.
18
+ *
19
+ * {@link BaseError.kind | kind} is `'WSError'`, and the message is
20
+ * `'Websocket failed to connect'`.
21
+ *
22
+ * @category Errors
23
+ */
3
24
  export declare class WsError extends BaseError {
25
+ /**
26
+ * Always `'WSError'` — note the capitalization, which does not match the class name.
27
+ */
28
+ readonly kind: 'WSError';
29
+ /**
30
+ * Wraps a web socket failure, built from the socket's `error` event.
31
+ * @internal The SDK builds this itself; applications catch the error rather than construct it.
32
+ */
4
33
  constructor(message: string);
5
34
  }
@@ -1,6 +1,20 @@
1
- export * from './errors';
2
- export * from './services/agent-manager';
3
- export * from './types';
1
+ export { createAgentManager } from './services/agent-manager';
2
+ export type { Auth, BasicAuth, BearerToken, ClientKeyAuth } from './types/auth';
3
+ export type { Agent, AgentAvatar, EndOfCallFeedbackConfig } from './types/entities/agents/agent';
4
+ export type { AgentManager, AgentManagerCallbacks, AgentManagerOptions, StreamOptions, } from './types/entities/agents/manager';
5
+ export { AvatarType } from './types/entities/avatar';
6
+ export type { STTTokenResponse } from './types/voice/stt';
7
+ export { AgentActivityState, ConnectionState, ConnectivityState, PublicDataChannelTopic, StreamEndReason, StreamEvents, StreamingState, } from './types/stream/stream';
8
+ export type { ClientToolHandler, RunningToolCall, StreamCreatedInfo, ToolCallDonePayload, ToolCallErrorPayload, ToolCallStartedPayload, ToolEventCallback, ToolExecutionMode, } from './types/stream/stream';
9
+ export type { SendStreamPayloadResponse } from './types/stream/rtc';
10
+ export { StreamType } from './types/stream/stream';
11
+ export type { CompatibilityMode } from './types/stream/stream';
12
+ export type { AudioStreamScript, SupportedStreamScript, TextStreamScript } from './types/stream-script';
13
+ export { ChatMode } from './types/entities/agents/chat';
14
+ export type { ChatResponse, Interrupt, Message, MessagePart, MessageSentiment, RatingEntity, RetrievalMetadata, SubmitFeedbackResponse, } from './types/entities/agents/chat';
4
15
  export { parseMessageParts } from './utils/content-parser';
5
16
  export { isAwaitingTool } from './utils/tool-calls';
6
- export { SDK_VERSION } from './version';
17
+ export { Providers, VoiceAccess } from './types/voice/tts';
18
+ export type { AmazonTtsProvider, AzureOpenAiTtsProvider, ElevenlabsTtsProvider, MicrosoftTtsProvider, StreamTextToSpeechProviders, Voice, VoiceConfigElevenlabs, VoiceConfigMicrosoft, } from './types/voice/tts';
19
+ export { BaseError, ChatCreationFailed, ChatModeDowngraded, HttpError, NetworkError, StreamError, ValidationError, WsError, isDIDError, } from './errors';
20
+ export type { ErrorJson } from './errors';
@@ -0,0 +1 @@
1
+ export {};
@@ -2,6 +2,10 @@ import { AgentManager, AgentManagerOptions, Chat, ChatMode, CreateStreamOptions,
2
2
  import { SocketManager } from '../socket-manager';
3
3
  import { StreamingManager } from '../streaming-manager';
4
4
 
5
+ /**
6
+ * Mutable state shared between the agent manager's connect/chat/stream helpers.
7
+ * @internal Implementation type; not part of the public SDK surface.
8
+ */
5
9
  export interface AgentManagerItems {
6
10
  chat?: Chat;
7
11
  streamingManager?: StreamingManager<CreateStreamOptions>;
@@ -10,15 +14,51 @@ export interface AgentManagerItems {
10
14
  chatMode: ChatMode;
11
15
  }
12
16
  /**
13
- * Creates a new Agent Manager instance for interacting with an agent, chat, and related connections.
17
+ * Creates an {@link AgentManager} for one agent: its chat, its video stream and its connections.
18
+ *
19
+ * Fetches the agent from the Agents API before it resolves, so the returned manager already has
20
+ * {@link AgentManager.agent | agent} and {@link AgentManager.starterMessages | starterMessages}
21
+ * filled in. No stream is opened until {@link AgentManager.connect | connect()} is called.
22
+ * {@link AgentManagerOptions.callbacks | callbacks} must include
23
+ * {@link AgentManagerCallbacks.onSrcObjectReady | onSrcObjectReady}, which is what attaches the
24
+ * streamed media to a video element.
14
25
  *
15
- * @param {string} agent - The ID or instance of the agent to chat with.
16
- * @param {AgentManagerOptions} options - Configurations for the Agent Manager API.
17
- * * @returns {Promise<AgentManager>} - A promise that resolves to an instance of the AgentsAPI interface.
26
+ * One option is checked here: an Expressive (V4) agent asked for {@link ChatMode.Off} or
27
+ * {@link ChatMode.DirectPlayback}, which only Talks (V2) and Clips (V3) agents support, rejects
28
+ * with a {@link ValidationError}. Every other bad argument surfaces later, as a
29
+ * {@link ValidationError} rejected by the method that was called on the returned manager, such as
30
+ * {@link AgentManager.chat | chat()} or {@link AgentManager.speak | speak()}.
18
31
  *
19
- * @throws {Error} Throws an error if the agent is not initialized.
32
+ * @param agent - Id of the agent to talk to: the `data-agent-id` from its Embed snippet, or the `id`
33
+ * returned by the Agents API.
34
+ * @param options - Credentials, callbacks and everything else the manager needs. See
35
+ * {@link AgentManagerOptions}.
36
+ * @returns A manager for that agent, ready to {@link AgentManager.connect | connect()}.
37
+ * @throws {@link ValidationError} When an Expressive (V4) agent is created with
38
+ * {@link ChatMode.Off} or {@link ChatMode.DirectPlayback}.
39
+ * @throws {@link HttpError} When the agent cannot be fetched — an unknown id, or a client key that
40
+ * is not authorized for the agent or the calling domain.
41
+ * @throws {@link NetworkError} When the request for the agent never reaches the server: the browser
42
+ * is offline, DNS or TLS fails, or the request is blocked.
20
43
  *
21
44
  * @example
22
- * const agentManager = await createAgentManager('id-agent123', { auth: { type: 'key', clientKey: '123', externalId: '123' } });
45
+ * ```ts
46
+ * import * as sdk from '@d-id/client-sdk';
47
+ *
48
+ * const agentManager = await sdk.createAgentManager('agt_fumf1234', {
49
+ * auth: { type: 'key', clientKey: 'YOUR_CLIENT_KEY' },
50
+ * callbacks: {
51
+ * // Required: hand the streamed media to your video element.
52
+ * onSrcObjectReady(value) {
53
+ * videoElement.srcObject = value;
54
+ * },
55
+ * },
56
+ * });
57
+ *
58
+ * await agentManager.connect();
59
+ * await agentManager.chat('What is the distance to the moon?');
60
+ * ```
61
+ *
62
+ * @category Agent Manager
23
63
  */
24
64
  export declare function createAgentManager(agent: string, options: AgentManagerOptions): Promise<AgentManager>;
@@ -0,0 +1 @@
1
+ export {};
@@ -79,9 +79,14 @@ export type StreamingManager<T extends CreateStreamOptions | CreateSessionV2Opti
79
79
  */
80
80
  isInterruptible: boolean;
81
81
  /**
82
- * Send an interrupt for the current stream segment
83
- */
84
- interrupt(type: Interrupt['type']): void;
82
+ * Send an interrupt for the current stream segment.
83
+ *
84
+ * Returns whether an interrupt was actually sent: `false` when there is nothing to interrupt
85
+ * (the stream does not support it, it is not a Fluent stream, no video is playing, or the
86
+ * interrupt type is one this transport drops), and `false` when the transport could not carry
87
+ * it because the connection or the data channel is not up.
88
+ */
89
+ interrupt(type: Interrupt['type']): boolean;
85
90
  /**
86
91
  * Register an RPC method handler on the LiveKit room.
87
92
  * Used internally by the agent-manager for client tool delegation.
@@ -1,23 +1,95 @@
1
+ /**
2
+ * A bearer token for the Agents API.
3
+ *
4
+ * Account-wide, so it is meant for a trusted environment — a server, a build step, an internal
5
+ * tool. Anyone who reads the token can spend the account's credits, so do not ship one in a page
6
+ * you serve to users; use {@link ClientKeyAuth} there. The SDK sends it as
7
+ * `Authorization: Bearer <token>~<connectionId>`, appending a per-connection id the D-ID
8
+ * authorizer strips before it validates the token.
9
+ *
10
+ * @category Authentication
11
+ */
1
12
  export interface BearerToken {
13
+ /**
14
+ * Discriminator selecting this variant of {@link Auth}.
15
+ */
2
16
  type: 'bearer';
17
+ /**
18
+ * The bearer token itself, sent in the `Authorization` header.
19
+ */
3
20
  token: string;
4
21
  }
22
+ /**
23
+ * HTTP basic credentials for the Agents API, given either pre-encoded or as a username and
24
+ * password.
25
+ *
26
+ * Like {@link BearerToken} these are account-wide and belong in a trusted environment, never in a
27
+ * client bundle. The SDK sends them as `Authorization: Basic <credentials>~<connectionId>`, where
28
+ * the `token` form is used as the credentials as-is and the `username`/`password` form is
29
+ * base64-encoded as `username:password` first; the trailing per-connection id is stripped by the
30
+ * D-ID authorizer before the credentials are validated.
31
+ *
32
+ * @category Authentication
33
+ */
5
34
  export type BasicAuth = {
35
+ /**
36
+ * Discriminator selecting this variant of {@link Auth}.
37
+ */
6
38
  type: 'basic';
39
+ /**
40
+ * Credentials that are already base64-encoded, as `username:password`. Used as they
41
+ * are, so they are not encoded a second time.
42
+ */
7
43
  token: string;
8
44
  } | {
45
+ /**
46
+ * Discriminator selecting this variant of {@link Auth}.
47
+ */
9
48
  type: 'basic';
49
+ /**
50
+ * The account's user name; base64-encoded with the password before it is sent.
51
+ */
10
52
  username: string;
53
+ /**
54
+ * The account's password; base64-encoded with the user name before it is sent.
55
+ */
11
56
  password: string;
12
57
  };
58
+ /**
59
+ * A client key for the Agents API — the credential to use in a browser.
60
+ *
61
+ * This is the one shape that is safe to ship in a page: a client key is scoped to a single agent
62
+ * and only works from the domains allowed for it, so it cannot be reused elsewhere. Copy it from the
63
+ * agent's Embed snippet, where it appears as `data-client-key`, or create one with the Agents API
64
+ * (see the link below). The SDK sends it
65
+ * as `Authorization: Client-Key <clientKey>.<externalId>_<connectionId>`, where the external id is
66
+ * either {@link AgentManagerOptions.externalId | externalId} or a per-browser id the SDK keeps in
67
+ * `localStorage`.
68
+ *
69
+ * @see [Create a client key](https://docs.d-id.com/reference/createclientkey)
70
+ * @category Authentication
71
+ */
13
72
  export interface ClientKeyAuth {
73
+ /**
74
+ * Discriminator selecting this variant of {@link Auth}.
75
+ */
14
76
  type: 'key';
77
+ /**
78
+ * The client key: the `data-client-key` value from the agent's Embed snippet, or a key created with
79
+ * the Agents API.
80
+ */
15
81
  clientKey: string;
16
82
  }
83
+ /**
84
+ * The credentials {@link createAgentManager} accepts, as
85
+ * {@link AgentManagerOptions.auth | options.auth}.
86
+ *
87
+ * Pick {@link ClientKeyAuth} (`{ type: 'key', clientKey }`) for anything that runs in a browser: it
88
+ * is the only variant scoped to one agent and to the domains you allowed. {@link BearerToken} and
89
+ * {@link BasicAuth} carry account-wide credentials and belong in a trusted environment. Whichever
90
+ * you pass is used for every request the SDK makes — the REST calls, the video stream and the
91
+ * notifications web socket.
92
+ *
93
+ * @category Authentication
94
+ */
17
95
  export type Auth = BearerToken | BasicAuth | ClientKeyAuth;
18
- export interface GetAuthParams {
19
- token?: string | null;
20
- username?: string | null;
21
- password?: string | null;
22
- clientKey?: string | null;
23
- }