Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pr-prod-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
env:
E2E_USER_APIKEY: ${{ secrets.E2E_USER_APIKEY }}
VITE_CLIENT_KEY: ${{ secrets.VITE_CLIENT_KEY }}
ASSERT_CHAT_RESTART: 'false'
run: yarn test:prod

- name: Upload test results
Expand Down
92 changes: 46 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
{
"name": "@d-id/client-sdk",
"private": false,
"version": "1.1.7",
"type": "module",
"description": "d-id client sdk",
"repository": {
"type": "git",
"url": "https://github.com/de-id/agents-sdk"
},
"keywords": [
"d-id",
"sdk",
"client-sdk"
],
"license": "MIT",
"author": "d-id",
"files": [
"dist/*"
],
"main": "./dist/index.umd.cjs",
"module": "./dist/index.js",
"types": "./dist/src/index.d.ts",
"scripts": {
"dev": "vite",
"build": "node ./infra/build.js -m production",
"build:dev": "node ./infra/build.js -m development",
"dev:prod": "export NODE_ENV=production && vite --mode production",
"deploy:prod": "node ./infra/deploy.js --version beta",
"preview": "vite preview",
"test-build": "node .infra/build.js -m development",
"build:docs": "typedoc"
},
"devDependencies": {
"@preact/preset-vite": "^2.8.1",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/node": "^22.15.0",
"commander": "^11.1.0",
"glob": "^10.3.10",
"preact": "^10.19.6",
"prettier": "^3.2.5",
"prettier-plugin-organize-imports": "^3.2.4",
"typedoc": "^0.25.7",
"typescript": "^5.3.3",
"vite": "^5.1.4",
"vite-plugin-dts": "^3.7.3"
}
"name": "@d-id/client-sdk",
"private": false,
"version": "1.1.7",
"type": "module",
"description": "d-id client sdk",
"repository": {
"type": "git",
"url": "https://github.com/de-id/agents-sdk"
},
"keywords": [
"d-id",
"sdk",
"client-sdk"
],
"license": "MIT",
"author": "d-id",
"files": [
"dist/*"
],
"main": "./dist/index.umd.cjs",
"module": "./dist/index.js",
"types": "./dist/src/index.d.ts",
"scripts": {
"dev": "vite",
"build": "node ./infra/build.js -m production",
"build:dev": "node ./infra/build.js -m development",
"dev:prod": "export NODE_ENV=production && vite --mode production",
"deploy:prod": "node ./infra/deploy.js --version beta",
"preview": "vite preview",
"test-build": "node .infra/build.js -m development",
"build:docs": "typedoc"
},
"devDependencies": {
"@preact/preset-vite": "^2.8.1",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/node": "^22.15.0",
"commander": "^11.1.0",
"glob": "^10.3.10",
"preact": "^10.19.6",
"prettier": "^3.2.5",
"prettier-plugin-organize-imports": "^3.2.4",
"typedoc": "^0.25.7",
"typescript": "^5.3.3",
"vite": "^5.1.4",
"vite-plugin-dts": "^3.7.3"
}
}
3 changes: 1 addition & 2 deletions src/api/streams/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './clipStream'
export * from './talkStream'
export * from './streamApi';
17 changes: 6 additions & 11 deletions src/api/streams/clipStream.ts → src/api/streams/streamApi.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {
Auth,
ClipStreamOptions,
CreateStreamOptions,
ICreateStreamRequestResponse,
IceCandidate,
RtcApi,
SendClipStreamPayload,
SendStreamPayloadResponse,
SendTalkStreamPayload,
Status,
} from '$/types/index';
import { createClient } from '../apiClient';

export function createClipApi(
export function createStreamApi(
auth: Auth,
host: string,
agentId: string,
Expand All @@ -19,14 +20,8 @@ export function createClipApi(
const client = createClient(auth, `${host}/agents/${agentId}`, onError);

return {
createStream(options: ClipStreamOptions) {
return client.post<ICreateStreamRequestResponse>('/streams', {
output_resolution: options.output_resolution,
compatibility_mode: options.compatibility_mode,
stream_warmup: options.stream_warmup,
session_timeout: options.session_timeout,
fluent: options.fluent,
});
createStream(options: CreateStreamOptions) {
return client.post<ICreateStreamRequestResponse>('/streams', options);
},
startConnection(streamId: string, answer: RTCSessionDescriptionInit, sessionId?: string) {
return client.post<Status>(`/streams/${streamId}/sdp`, {
Expand All @@ -40,7 +35,7 @@ export function createClipApi(
...candidate,
});
},
sendStreamRequest(streamId: string, sessionId: string, payload: SendClipStreamPayload) {
sendStreamRequest(streamId: string, sessionId: string, payload: SendClipStreamPayload | SendTalkStreamPayload) {
return client.post<SendStreamPayloadResponse>(`/streams/${streamId}`, {
session_id: sessionId,
...payload,
Expand Down
63 changes: 0 additions & 63 deletions src/api/streams/talkStream.ts

This file was deleted.

26 changes: 11 additions & 15 deletions src/services/agent-manager/connect-to-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ import {
StreamEvents,
StreamType,
StreamingState,
mapVideoType,
} from '$/types';
import { Analytics } from '../analytics/mixpanel';
import { interruptTimestampTracker, latencyTimestampTracker } from '../analytics/timestamp-tracker';
import { createChat } from '../chat';

function getAgentStreamArgs(agent: Agent, options?: AgentManagerOptions): CreateStreamOptions {
function getAgentStreamArgs(options?: AgentManagerOptions): CreateStreamOptions {
const { streamOptions } = options ?? {};

return {
videoType: mapVideoType(agent.presenter.type),
output_resolution: streamOptions?.outputResolution,
session_timeout: streamOptions?.sessionTimeout,
stream_warmup: streamOptions?.streamWarmup,
Expand Down Expand Up @@ -142,7 +140,7 @@ function connectToManager(

return new Promise(async (resolve, reject) => {
try {
const streamingManager = await createStreamingManager(agent.id, getAgentStreamArgs(agent, options), {
const streamingManager = await createStreamingManager(agent.id, getAgentStreamArgs(options), {
...options,
analytics,
callbacks: {
Expand Down Expand Up @@ -196,27 +194,25 @@ export async function initializeStreamAndChat(
analytics: Analytics,
chat?: Chat
): Promise<{ chat?: Chat; streamingManager?: StreamingManager<CreateStreamOptions> }> {
const { chat: newChat, chatMode } = await createChat(
agent,
agentsApi,
analytics,
options.mode,
options.persistentChat,
chat
);
const createChatPromise = createChat(agent, agentsApi, analytics, options.mode, options.persistentChat, chat);
const connectToManagerPromise = connectToManager(agent, options, analytics);

const [chatResult, streamingManager] = await Promise.all([createChatPromise, connectToManagerPromise]);

const { chat: newChat, chatMode } = chatResult;

if (chatMode && chatMode !== options.mode) {
options.mode = chatMode;
options.callbacks.onModeChange?.(chatMode);

if (chatMode === ChatMode.TextOnly) {
if (chatMode !== ChatMode.Functional) {
options.callbacks.onError?.(new ChatModeDowngraded(chatMode));

streamingManager?.disconnect();

return { chat: newChat };
}
}

const streamingManager = await connectToManager(agent, options, analytics);

return { chat: newChat, streamingManager };
}
1 change: 1 addition & 0 deletions src/services/analytics/mixpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function initializeAnalytics(config: AnalyticsOptions): Analytics {
...sendProps,
agentId: this.agentId,
source,
token: this.token,
time: Date.now(),
$insert_id: this.getRandom(),
origin: window.location.href,
Expand Down
13 changes: 7 additions & 6 deletions src/services/streaming-manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createClipApi, createTalkApi } from '$/api/streams';
import { createStreamApi } from '$/api/streams';
import { didApiUrl } from '$/config/environment';
import {
AgentActivityState,
Expand All @@ -9,7 +9,6 @@ import {
StreamType,
StreamingManagerOptions,
StreamingState,
VideoType,
} from '$/types/index';
import { pollStats } from './stats/poll';
import { VideoRTCStatsReport } from './stats/report';
Expand Down Expand Up @@ -142,10 +141,12 @@ export async function createStreamingManager<T extends CreateStreamOptions>(
let dataChannelSignal: StreamingState = StreamingState.Stop;
let statsSignal: StreamingState = StreamingState.Stop;

const { startConnection, sendStreamRequest, close, createStream, addIceCandidate } =
agent.videoType === VideoType.Clip
? createClipApi(auth, baseURL, agentId, callbacks.onError)
: createTalkApi(auth, baseURL, agentId, callbacks.onError);
const { startConnection, sendStreamRequest, close, createStream, addIceCandidate } = createStreamApi(
auth,
baseURL,
agentId,
callbacks.onError
);

const {
id: streamIdFromServer,
Expand Down
3 changes: 0 additions & 3 deletions src/types/stream/stream.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Analytics } from '$/services/analytics/mixpanel';
import { VideoRTCStatsReport } from '$/services/streaming-manager/stats/report';
import { Auth } from '../auth';
import { VideoType } from '../entities';
import { CreateClipStreamRequest, CreateTalkStreamRequest, SendClipStreamPayload, SendTalkStreamPayload } from './api';
import { ICreateStreamRequestResponse, IceCandidate, SendStreamPayloadResponse, Status } from './rtc';

Expand Down Expand Up @@ -67,12 +66,10 @@ export interface ManagerCallbacks {

export type ManagerCallbackKeys = keyof ManagerCallbacks;
export interface TalkStreamOptions extends CreateTalkStreamRequest {
videoType: VideoType.Talk;
fluent?: boolean;
}

export interface ClipStreamOptions extends CreateClipStreamRequest {
videoType: VideoType.Clip;
fluent?: boolean;
}

Expand Down