@d-id/client-sdk 2.0.6 → 2.0.7-staging.404

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.
@@ -1,5 +1,5 @@
1
1
  import { StreamingManager } from '../streaming-manager';
2
- import { Agent, AgentManagerOptions, AgentsAPI, AudioDetectionMetrics, Chat, ChatProgressCallback, CreateSessionV2Options, CreateStreamOptions } from '../../types';
2
+ import { Agent, AgentManagerOptions, AgentsAPI, AudioDetectionMetrics, Chat, ChatProgressCallback, CreateSessionV2Options, CreateStreamOptions, StreamingManagerOptions } from '../../types';
3
3
  import { Analytics } from '../analytics/mixpanel';
4
4
 
5
5
  type ConnectToManagerOptions = AgentManagerOptions & {
@@ -10,6 +10,7 @@ type ConnectToManagerOptions = AgentManagerOptions & {
10
10
  onFirstAudioDetected?: (metrics: AudioDetectionMetrics) => void;
11
11
  };
12
12
  chatId?: string;
13
+ rpcMethods?: StreamingManagerOptions['rpcMethods'];
13
14
  };
14
15
  export declare function initializeStreamAndChat(agent: Agent, options: ConnectToManagerOptions, agentsApi: AgentsAPI, analytics: Analytics, chat?: Chat): Promise<{
15
16
  chat?: Chat;
@@ -6,7 +6,7 @@ export interface ChatEventQueue {
6
6
  [sequence: number]: string;
7
7
  answer?: string;
8
8
  }
9
- export declare function createMessageEventQueue(analytics: Analytics, items: AgentManagerItems, options: AgentManagerOptions, agentEntity: Agent, onStreamDone: () => void): {
9
+ export declare function createMessageEventQueue(analytics: Analytics, items: AgentManagerItems, options: AgentManagerOptions, agentEntity: Agent, onStreamDone: (reason?: string) => void): {
10
10
  clearQueue: () => void;
11
11
  onMessage: (event: ChatProgress | StreamEvents, data: any) => void;
12
12
  };
@@ -1,5 +1 @@
1
- /**
2
- * Advanced functionality tests for streaming manager
3
- * Tests complex scenarios, edge cases, and advanced features
4
- */
5
1
  export {};
@@ -1,4 +1,5 @@
1
1
  import { CreateSessionV2Options, CreateStreamOptions, Interrupt, PayloadType, StreamType } from '../../types';
2
+ import { DataChannelTopic } from '../../types/stream/data-channel';
2
3
 
3
4
  export declare const createStreamingLogger: (debug: boolean, prefix: string) => (message: string, extra?: any) => false | void;
4
5
  /**
@@ -16,16 +17,13 @@ export type StreamingManager<T extends CreateStreamOptions | CreateSessionV2Opti
16
17
  */
17
18
  disconnect(): Promise<void>;
18
19
  /**
19
- * Method to send data channel messages to the server
20
- * @param payload The message payload to send
20
+ * The single send primitive: every message leaving the client goes out through here.
21
+ * V2 routes on the topic; V1 has no topic concept and ignores it.
22
+ * The promise tracks the send attempt and never rejects - failures go to `callbacks.onError`.
23
+ * @param topic Data-channel topic to send on
24
+ * @param payload The message payload to send, already serialized
21
25
  */
22
- sendDataChannelMessage(payload: string): void;
23
- /**
24
- * Method to send text messages to the server
25
- * @param payload The message payload to send
26
- * supported only for livekit manager
27
- */
28
- sendTextMessage?(payload: string): Promise<void>;
26
+ sendDataChannelMessage(topic: DataChannelTopic, payload: string): Promise<void>;
29
27
  /**
30
28
  * Publish a microphone stream to the DataChannel
31
29
  * Can be called after connection to add microphone input
@@ -81,19 +79,9 @@ export type StreamingManager<T extends CreateStreamOptions | CreateSessionV2Opti
81
79
  */
82
80
  isInterruptible: boolean;
83
81
  /**
84
- * Send an interrupt for the current stream segment.
85
- * Each implementation owns the validation/transport details (e.g. V1
86
- * sends a `stream/interrupt` payload over the data channel; V2 sends
87
- * `did.interrupt` and ignores `text` interrupts to avoid races).
82
+ * Send an interrupt for the current stream segment
88
83
  */
89
84
  interrupt(type: Interrupt['type']): void;
90
- /**
91
- * Switch the STT language mid-session.
92
- * Only available for Expressive (V4) agents.
93
- * supported only for livekit manager
94
- * @param language Language name or BCP-47 code (e.g. "English" or "en-US")
95
- */
96
- setSttLanguage?(language: string): Promise<void>;
97
85
  /**
98
86
  * Register an RPC method handler on the LiveKit room.
99
87
  * Used internally by the agent-manager for client tool delegation.
@@ -1,5 +1 @@
1
- /**
2
- * Edge cases and branch coverage tests for streaming manager
3
- * Tests detailed edge cases, error conditions, and branch coverage scenarios
4
- */
5
1
  export {};
@@ -1,12 +1,6 @@
1
1
  import { CreateSessionV2Options, CreateStreamOptions, StreamingManagerOptions } from '../../types';
2
2
  import { StreamingManager } from './common';
3
3
 
4
- export declare enum DataChannelTopic {
5
- Chat = "lk.chat",
6
- Speak = "did.speak",
7
- Interrupt = "did.interrupt",
8
- SttLanguage = "did.stt-language"
9
- }
10
4
  export declare function handleInitError(error: unknown, log: (message?: any, ...optionalParams: any[]) => void, callbacks: StreamingManagerOptions['callbacks']): void;
11
5
  export declare function createLiveKitStreamingManager<T extends CreateSessionV2Options>(agentId: string, sessionOptions: CreateSessionV2Options, options: StreamingManagerOptions): Promise<StreamingManager<T> & {
12
6
  reconnect(): Promise<void>;
@@ -1,5 +1 @@
1
- /**
2
- * Core functionality tests for streaming manager
3
- * Tests basic streaming manager creation, connection, and operations
4
- */
5
1
  export {};
@@ -41,6 +41,11 @@ export interface Agent {
41
41
  vm_account_id?: string;
42
42
  closed_captions_enabled?: boolean;
43
43
  };
44
+ ld_context?: {
45
+ key: string;
46
+ hash_key: string;
47
+ plan_group: string;
48
+ };
44
49
  }
45
50
  export interface AgentsAPI {
46
51
  getRuntimeById(id: string, options?: RequestInit): Promise<Agent>;
@@ -1,6 +1,6 @@
1
1
  import { STTTokenResponse } from '../..';
2
2
  import { Auth } from '../../auth';
3
- import { AgentActivityState, ClientToolHandler, CompatibilityMode, ConnectionState, ConnectivityState, SendStreamPayloadResponse, StreamEvents, StreamType, StreamingState } from '../../stream';
3
+ import { AgentActivityState, ClientToolHandler, CompatibilityMode, ConnectionState, ConnectivityState, PublicDataChannelTopic, SendStreamPayloadResponse, StreamEvents, StreamType, StreamingState } from '../../stream';
4
4
  import { SupportedStreamScript } from '../../stream-script';
5
5
  import { ManagerCallbacks as StreamManagerCallbacks } from '../../stream/stream';
6
6
  import { Agent } from './agent';
@@ -42,8 +42,9 @@ interface ManagerCallbacks {
42
42
  /**
43
43
  * Optional callback will be triggered each time the RTC connection changes state
44
44
  * @param state
45
+ * @param reason - a `StreamEndReason` when the server ended the stream, otherwise a diagnostic string
45
46
  */
46
- onConnectionStateChange?(state: ConnectionState): void;
47
+ onConnectionStateChange?(state: ConnectionState, reason?: string): void;
47
48
  /**
48
49
  * Optional callback function that will be triggered each time video events happen
49
50
  * @param state
@@ -292,6 +293,13 @@ export interface AgentManager {
292
293
  * @param language - Language name or BCP-47 code (e.g. "English" or "en-US")
293
294
  */
294
295
  setSttLanguage: (language: string) => Promise<void>;
296
+ /**
297
+ * Send a JSON payload to the agent over a data-channel topic
298
+ * Only available for Expressive (V4) agents
299
+ * @param topic - Data-channel topic to send on (see `PublicDataChannelTopic`)
300
+ * @param payload - Plain object, serialized as JSON
301
+ */
302
+ sendDataChannelMessage: (topic: PublicDataChannelTopic, payload: Record<string, unknown>) => Promise<void>;
295
303
  /**
296
304
  * Register a handler for a client tool. When the agent's LLM calls this tool,
297
305
  * the handler executes on the client and returns the result to the LLM.
@@ -1,8 +1,18 @@
1
- import { KnowledgeType } from './knowledge';
1
+ import { DocumentType, KnowledgeType } from './knowledge';
2
2
 
3
+ /**
4
+ * Lifecycle status of a document, as served by the knowledge API. The API stores the
5
+ * status as a prefixed event subject (`document/done`) but strips the prefix on read,
6
+ * so the wire value is always bare.
7
+ */
8
+ export type DocumentStatus = 'created' | 'processed' | 'done' | 'rejected' | 'error';
9
+ /**
10
+ * @deprecated The knowledge API has never served these prefixed values — it strips the
11
+ * subject prefix on read. Use `DocumentStatus` instead. Kept for backwards compatibility
12
+ * and will be removed in the next major.
13
+ */
3
14
  export declare enum Subject {
4
15
  KnowledgeProcessing = "knowledge/processing",
5
- KnowledgeIndexing = "knowledge/indexing",
6
16
  KnowledgeFailed = "knowledge/error",
7
17
  KnowledgeDone = "knowledge/done"
8
18
  }
@@ -12,7 +22,7 @@ export interface DocumentData {
12
22
  owner_id: string;
13
23
  id: string;
14
24
  created_by: string;
15
- status: Subject;
25
+ status: DocumentStatus;
16
26
  documentType: DocumentType;
17
27
  type: KnowledgeType;
18
28
  source_url: string;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Data-channel topics messages can be sent on.
3
+ * V2 (LiveKit) routes by topic; V1 (WebRTC) has no topic concept and ignores it.
4
+ *
5
+ * Internal on purpose: this module is deliberately left out of the `stream`
6
+ * barrel so the topics driven by dedicated methods (`chat`, `speak`,
7
+ * `interrupt`, `setSttLanguage`) never reach the package's public API.
8
+ * Customers get `PublicDataChannelTopic` instead.
9
+ */
10
+ export declare enum DataChannelTopic {
11
+ Chat = "lk.chat",
12
+ Speak = "did.speak",
13
+ Interrupt = "did.interrupt",
14
+ SttLanguage = "did.stt-language",
15
+ Presentation = "did.presentation"
16
+ }
@@ -3,6 +3,7 @@ import { VideoRTCStatsReport } from '../../services/streaming-manager/stats/repo
3
3
  import { Auth } from '../auth';
4
4
  import { ChatProgressCallback } from '../entities/agents/manager';
5
5
  import { CreateClipStreamRequest, CreateTalkStreamRequest, SendClipStreamPayload, SendTalkStreamPayload } from './api';
6
+ import { DataChannelTopic } from './data-channel';
6
7
  import { ICreateStreamRequestResponse, IceCandidate, SendStreamPayloadResponse, Status } from './rtc';
7
8
 
8
9
  export type CompatibilityMode = 'on' | 'off' | 'auto';
@@ -41,6 +42,20 @@ export declare enum StreamEvents {
41
42
  TurnStarted = "turn/started",
42
43
  TurnEnded = "turn/ended"
43
44
  }
45
+ /**
46
+ * Topics a customer can send on via `agentManager.sendDataChannelMessage`.
47
+ * The remaining `DataChannelTopic` members are driven by their own methods
48
+ * (`chat`, `speak`, `interrupt`, `setSttLanguage`), which own the payload shape
49
+ * and bookkeeping those topics expect, so they stay internal.
50
+ *
51
+ * A const object rather than a second enum: it borrows the value from
52
+ * `DataChannelTopic`, so there is one source of truth for the wire string and
53
+ * no cast is needed where the topic reaches the transport.
54
+ */
55
+ export declare const PublicDataChannelTopic: {
56
+ readonly Presentation: DataChannelTopic.Presentation;
57
+ };
58
+ export type PublicDataChannelTopic = (typeof PublicDataChannelTopic)[keyof typeof PublicDataChannelTopic];
44
59
  export declare enum ConnectionState {
45
60
  New = "new",
46
61
  Fail = "fail",
@@ -55,6 +70,10 @@ export declare enum StreamType {
55
70
  Legacy = "legacy",
56
71
  Fluent = "fluent"
57
72
  }
73
+ /** @internal */
74
+ export type RpcMethodHandler = (data: {
75
+ payload: string;
76
+ }) => Promise<string>;
58
77
  export interface ManagerCallbacks {
59
78
  onMessage?: ChatProgressCallback;
60
79
  onConnectionStateChange?: (state: ConnectionState, reason?: string) => void;
@@ -113,6 +132,12 @@ export interface StreamingManagerOptions {
113
132
  * Supported by LiveKit streaming managers.
114
133
  */
115
134
  microphoneStream?: MediaStream;
135
+ /**
136
+ * RPC methods to register on the room before it connects, so the agent can
137
+ * call them from the moment this participant joins.
138
+ * @internal
139
+ */
140
+ rpcMethods?: ReadonlyMap<string, RpcMethodHandler>;
116
141
  }
117
142
  export interface SlimRTCStatsReport {
118
143
  index: number;
@@ -225,6 +250,15 @@ export type ToolEventPayload = ToolCallStartedPayload | ToolCallDonePayload | To
225
250
  export interface TurnEventPayload {
226
251
  turn_id: number | null;
227
252
  }
253
+ export declare enum StreamEndReason {
254
+ Ok = "ok",
255
+ UnknownError = "unknown_error",
256
+ NetworkIssue = "network_issue",
257
+ MessageLimit = "message_limit",
258
+ TimeLimit = "time_limit",
259
+ Inactivity = "inactivity",
260
+ EndedByAgent = "ended_by_agent"
261
+ }
228
262
  export type ToolEventCallback = {
229
263
  (event: StreamEvents.ToolCallStarted, data: ToolCallStartedPayload): void;
230
264
  (event: StreamEvents.ToolCallDone, data: ToolCallDonePayload): void;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Legacy streams report the session end as `stream/done` with a `close_reason`.
3
+ * A reason we do not recognise is forwarded as-is rather than reported as an error.
4
+ */
5
+ export declare function toStreamEndReason(data: any): string | undefined;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@d-id/client-sdk",
3
3
  "private": false,
4
- "version": "2.0.6",
4
+ "version": "2.0.7-staging.404",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {