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
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"importOrder": ["^@d-id/tests$", "^@d-id/(.*)$", "^@/(.*)$", "^[./]"],
"importOrderSeparation": true,
"importOrderParserPlugins": ["typescript", "decorators-legacy"],
"plugins": ["prettier-plugin-organize-imports"],
"plugins": ["@trivago/prettier-plugin-sort-imports", "prettier-plugin-organize-imports"],
"overrides": [
{
"files": "*.yml",
Expand Down
2 changes: 1 addition & 1 deletion demo/app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatMode, ConnectionState } from '$/types';
import { ChatMode, ConnectionState } from '@sdk/types';
import { useEffect, useRef, useState } from 'preact/hooks';

import './app.css';
Expand Down
4 changes: 2 additions & 2 deletions demo/hooks/useAgentManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createAgentManager } from '$/services/agent-manager';
import { createAgentManager } from '@sdk/services/agent-manager';
import {
AgentActivityState,
AgentManager,
Expand All @@ -8,7 +8,7 @@ import {
Message,
StreamType,
StreamingState,
} from '$/types';
} from '@sdk/types';
import { useCallback, useEffect, useState } from 'preact/hooks';

interface UseAgentManagerOptions {
Expand Down
2 changes: 1 addition & 1 deletion jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
testMatch: ['**/**.spec.ts', '**/**.test.ts', '**/**.test.tsx'],
transform: { '^.+\\.tsx?$': ['ts-jest', { useESM: true, tsconfig: '<rootDir>/tsconfig.json' }] },
extensionsToTreatAsEsm: ['.ts', '.tsx'],
moduleNameMapper: { '^\\$/(.*)$': '<rootDir>/src/$1', '^%/(.*)$': '<rootDir>/src/types/$1' },
moduleNameMapper: { '^@sdk/(.*)$': '<rootDir>/src/$1', '^%/(.*)$': '<rootDir>/src/types/$1' },
setupFiles: ['<rootDir>/jest.setup.ts'],
...(process.env.CI && { reporters: ['summary'] }),

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@d-id/client-sdk",
"private": false,
"version": "1.1.15",
"version": "1.1.16",
"type": "module",
"description": "d-id client sdk",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
RatingEntity,
RatingPayload,
STTTokenResponse,
} from '$/types/index';
} from '@sdk/types/index';
import { didApiUrl } from '../config/environment';
import { RequestOptions, createClient } from './apiClient';

Expand Down
4 changes: 2 additions & 2 deletions src/api/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Auth } from '$/types/auth';
import { retryOperation } from '$/utils/retry-operation';
import { Auth } from '@sdk/types/auth';
import { retryOperation } from '@sdk/utils/retry-operation';
import { getAuthHeader } from '../auth/get-auth-header';
import { didApiUrl } from '../config/environment';

Expand Down
2 changes: 1 addition & 1 deletion src/api/knowledge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
KnowledgePayload,
QueryResult,
RecordData,
} from '$/types/index';
} from '@sdk/types/index';
import { didApiUrl } from '../config/environment';
import { createClient } from './apiClient';

Expand Down
2 changes: 1 addition & 1 deletion src/api/streams/streamApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SendStreamPayloadResponse,
SendTalkStreamPayload,
Status,
} from '$/types/index';
} from '@sdk/types/index';
import { createClient } from '../apiClient';

export function createStreamApi(
Expand Down
2 changes: 1 addition & 1 deletion src/api/streams/streamsApiV2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Auth, CreateStreamV2Options, CreateStreamV2Response } from '$/types';
import { Auth, CreateStreamV2Options, CreateStreamV2Response } from '@sdk/types';
import { createClient } from '../apiClient';

export function createStreamApiV2(
Expand Down
4 changes: 2 additions & 2 deletions src/auth/get-auth-header.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Auth } from '$/types/auth';
import { getRandom } from '$/utils';
import { Auth } from '@sdk/types/auth';
import { getRandom } from '@sdk/utils';

export function getExternalId(externalId?: string): string {
if (externalId !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/errors/chat/chat-creation-failed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatMode } from '$/types';
import { ChatMode } from '@sdk/types';
import { BaseError } from '../base-error';

export class ChatCreationFailed extends BaseError {
Expand Down
2 changes: 1 addition & 1 deletion src/errors/chat/chat-mode-downgraded.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatMode } from '$/types';
import { ChatMode } from '@sdk/types';
import { BaseError } from '../base-error';

export class ChatModeDowngraded extends BaseError {
Expand Down
6 changes: 3 additions & 3 deletions src/services/agent-manager/connect-to-manager.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createStreamingManager, StreamApiVersion } from '@sdk/services/streaming-manager';
import {
Agent,
AgentActivityState,
Expand All @@ -12,13 +13,12 @@ import {
} from '../../types';
import { Analytics } from '../analytics/mixpanel';
import { createChat } from '../chat';
import { createStreamingManager, StreamApiVersion } from '../streaming-manager';
import { initializeStreamAndChat } from './connect-to-manager';

// Mock dependencies
jest.mock('../streaming-manager');
jest.mock('@sdk/services/streaming-manager');
jest.mock('../chat');
jest.mock('$/config/consts', () => ({ CONNECTION_RETRY_TIMEOUT_MS: 5000 }));
jest.mock('@sdk/config/consts', () => ({ CONNECTION_RETRY_TIMEOUT_MS: 5000 }));
jest.mock('../../config/environment', () => ({
didApiUrl: 'https://api.d-id.com',
didSocketApiUrl: 'wss://api.d-id.com',
Expand Down
8 changes: 4 additions & 4 deletions src/services/agent-manager/connect-to-manager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ChatModeDowngraded } from '$/errors';
import { ChatModeDowngraded } from '@sdk/errors';
import {
ExtendedStreamOptions,
StreamApiVersion,
StreamingManager,
createStreamingManager,
} from '$/services/streaming-manager';
} from '@sdk/services/streaming-manager';
import {
Agent,
AgentActivityState,
Expand All @@ -19,8 +19,8 @@ import {
StreamType,
StreamingState,
TransportProvider,
} from '$/types';
import { isStreamsV2Agent } from '$/utils/agent';
} from '@sdk/types';
import { isStreamsV2Agent } from '@sdk/utils/agent';
import { Analytics } from '../analytics/mixpanel';
import { interruptTimestampTracker, latencyTimestampTracker } from '../analytics/timestamp-tracker';
import { createChat } from '../chat';
Expand Down
10 changes: 5 additions & 5 deletions src/services/agent-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
SupportedStreamScript,
} from '../../types';

import { CONNECTION_RETRY_TIMEOUT_MS } from '$/config/consts';
import { didApiUrl, didSocketApiUrl, mixpanelKey } from '$/config/environment';
import { ChatCreationFailed, ValidationError } from '$/errors';
import { getRandom } from '$/utils';
import { isChatModeWithoutChat, isTextualChat } from '$/utils/chat';
import { CONNECTION_RETRY_TIMEOUT_MS } from '@sdk/config/consts';
import { didApiUrl, didSocketApiUrl, mixpanelKey } from '@sdk/config/environment';
import { ChatCreationFailed, ValidationError } from '@sdk/errors';
import { getRandom } from '@sdk/utils';
import { isChatModeWithoutChat, isTextualChat } from '@sdk/utils/chat';
import { createAgentsApi } from '../../api/agents';
import { getAgentInfo, getAnalyticsInfo } from '../../utils/analytics';
import { retryOperation } from '../../utils/retry-operation';
Expand Down
4 changes: 2 additions & 2 deletions src/services/analytics/mixpanel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getExternalId } from '$/auth/get-auth-header';
import { getRandom } from '$/utils';
import { getExternalId } from '@sdk/auth/get-auth-header';
import { getRandom } from '@sdk/utils';

export interface AnalyticsOptions {
token: string;
Expand Down
8 changes: 4 additions & 4 deletions src/services/chat/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PLAYGROUND_HEADER } from '$/config/consts';
import type { Agent, AgentsAPI, Chat } from '$/types';
import { ChatMode } from '$/types';
import { isChatModeWithoutChat } from '$/utils/chat';
import { PLAYGROUND_HEADER } from '@sdk/config/consts';
import type { Agent, AgentsAPI, Chat } from '@sdk/types';
import { ChatMode } from '@sdk/types';
import { isChatModeWithoutChat } from '@sdk/utils/chat';
import { Analytics } from '../analytics/mixpanel';

export function getRequestHeaders(chatMode?: ChatMode): Record<string, Record<string, string>> {
Expand Down
2 changes: 1 addition & 1 deletion src/services/chat/intial-messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message } from '$/types';
import { Message } from '@sdk/types';

export function getInitialMessages(initialMessages?: Message[]): Message[] {
if (initialMessages && initialMessages.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/interrupt/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreateStreamOptions, StreamEvents, StreamInterruptPayload, StreamType } from '$/types';
import { CreateStreamOptions, StreamEvents, StreamInterruptPayload, StreamType } from '@sdk/types';
import { StreamingManager } from '../streaming-manager';

export function validateInterrupt(
Expand Down
10 changes: 5 additions & 5 deletions src/services/socket-manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getAuthHeader } from '$/auth/get-auth-header';
import { WsError } from '$/errors';
import { ChatProgressCallback } from '$/types';
import { Auth } from '$/types/auth';
import { sleep } from '$/utils';
import { getAuthHeader } from '@sdk/auth/get-auth-header';
import { WsError } from '@sdk/errors';
import { ChatProgressCallback } from '@sdk/types';
import { Auth } from '@sdk/types/auth';
import { sleep } from '@sdk/utils';

interface Options {
auth: Auth;
Expand Down
4 changes: 2 additions & 2 deletions src/services/socket-manager/message-queue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Agent, AgentManagerOptions, ChatProgress, StreamEvents } from '$/types';
import { getStreamAnalyticsProps } from '$/utils/analytics';
import { Agent, AgentManagerOptions, ChatProgress, StreamEvents } from '@sdk/types';
import { getStreamAnalyticsProps } from '@sdk/utils/analytics';
import { AgentManagerItems } from '../agent-manager';
import { Analytics } from '../analytics/mixpanel';

Expand Down
2 changes: 1 addition & 1 deletion src/services/streaming-manager/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreateStreamOptions, CreateStreamV2Options, PayloadType, StreamType } from '$/types';
import { CreateStreamOptions, CreateStreamV2Options, PayloadType, StreamType } from '@sdk/types';

export const createStreamingLogger = (debug: boolean, prefix: string) => (message: string, extra?: any) =>
debug && console.log(`[${prefix}] ${message}`, extra ?? '');
Expand Down
8 changes: 7 additions & 1 deletion src/services/streaming-manager/factory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Agent, CreateStreamOptions, CreateStreamV2Options, StreamingManagerOptions, TransportProvider } from '$/types';
import {
Agent,
CreateStreamOptions,
CreateStreamV2Options,
StreamingManagerOptions,
TransportProvider,
} from '@sdk/types';
import { StreamingManager } from './common';
import { createWebRTCStreamingManager } from './webrtc-manager';

Expand Down
2 changes: 1 addition & 1 deletion src/services/streaming-manager/livekit-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
StreamingState,
StreamType,
TransportProvider,
} from '$/types';
} from '@sdk/types';
import { createStreamApiV2 } from '../../api/streams/streamsApiV2';
import { didApiUrl } from '../../config/environment';
import { createStreamingLogger, StreamingManager } from './common';
Expand Down
2 changes: 1 addition & 1 deletion src/services/streaming-manager/stats/poll.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConnectivityState, SlimRTCStatsReport, StreamingState } from '$/types';
import { ConnectivityState, SlimRTCStatsReport, StreamingState } from '@sdk/types';
import { VideoRTCStatsReport, createVideoStatsReport, formatStats } from './report';

const interval = 100;
Expand Down
4 changes: 2 additions & 2 deletions src/services/streaming-manager/stats/report.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AnalyticsRTCStatsReport, SlimRTCStatsReport } from '$/types';
import { average } from '$/utils/analytics';
import { AnalyticsRTCStatsReport, SlimRTCStatsReport } from '@sdk/types';
import { average } from '@sdk/utils/analytics';

export interface VideoRTCStatsReport {
webRTCStats: {
Expand Down
6 changes: 3 additions & 3 deletions src/services/streaming-manager/webrtc-manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createStreamApi } from '$/api/streams';
import { didApiUrl } from '$/config/environment';
import { createStreamApi } from '@sdk/api/streams';
import { didApiUrl } from '@sdk/config/environment';
import {
AgentActivityState,
ConnectionState,
Expand All @@ -9,7 +9,7 @@ import {
StreamingManagerOptions,
StreamingState,
StreamType,
} from '$/types';
} from '@sdk/types';
import { createStreamingLogger, StreamingManager } from './common';
import { pollStats } from './stats/poll';
import { VideoRTCStatsReport } from './stats/report';
Expand Down
8 changes: 4 additions & 4 deletions src/types/entities/agents/manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { STTTokenResponse } from '$/types';
import { Auth } from '$/types/auth';
import { STTTokenResponse } from '@sdk/types';
import { Auth } from '@sdk/types/auth';
import {
AgentActivityState,
CompatibilityMode,
Expand All @@ -9,8 +9,8 @@ import {
StreamEvents,
StreamType,
StreamingState,
} from '$/types/stream';
import { SupportedStreamScript } from '$/types/stream-script';
} from '@sdk/types/stream';
import { SupportedStreamScript } from '@sdk/types/stream-script';
import type { ManagerCallbacks as StreamManagerCallbacks } from '../../stream/stream';
import { Agent } from './agent';
import { ChatMode, ChatResponse, Interrupt, Message, RatingEntity } from './chat';
Expand Down
2 changes: 1 addition & 1 deletion src/types/entities/agents/presenter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExtendedTextToSpeechProviders } from '$/types/voice/tts';
import { ExtendedTextToSpeechProviders } from '@sdk/types/voice/tts';
import { Rect } from '../../face-rect';

export type videoType = 'talk' | 'clip' | 'expressive';
Expand Down
4 changes: 2 additions & 2 deletions src/types/stream/stream.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Analytics } from '$/services/analytics/mixpanel';
import { VideoRTCStatsReport } from '$/services/streaming-manager/stats/report';
import { Analytics } from '@sdk/services/analytics/mixpanel';
import { VideoRTCStatsReport } from '@sdk/services/streaming-manager/stats/report';
import { Auth } from '../auth';
import { CreateClipStreamRequest, CreateTalkStreamRequest, SendClipStreamPayload, SendTalkStreamPayload } from './api';
import { ICreateStreamRequestResponse, IceCandidate, SendStreamPayloadResponse, Status } from './rtc';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Agent, VideoType } from '$/types';
import { Agent, VideoType } from '@sdk/types';

type AgentType = 'clip_v2' | Agent['presenter']['type'];

Expand Down
2 changes: 1 addition & 1 deletion src/utils/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Agent } from '$/types/index';
import { Agent } from '@sdk/types/index';
import { getAgentType } from './agent';

export function getAnalyticsInfo(agent: Agent) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/chat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatMode } from '$/types';
import { ChatMode } from '@sdk/types';

export const isTextualChat = (chatMode: ChatMode) =>
[ChatMode.TextOnly, ChatMode.Playground, ChatMode.Maintenance].includes(chatMode);
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
"noFallthroughCasesInSwitch": true,
"types": ["node", "jest"],
"paths": {
"$/*": ["src/*"],
"@sdk/*": ["src/*"],
"%/*": ["src/types/*"]
}
},
"include": ["src", "demo"],
"exclude": ["node_modules", "**/*.test.ts"],
"exclude": ["node_modules"],
"references": [{ "path": "./tsconfig.node.json" }]
}
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default ({ mode }) => {
plugins: [preact(), dts({ include: [resolve(__dirname, './src/**/*.{ts,tsx}')] })],
resolve: {
alias: {
$: resolve(__dirname, './src'),
'@sdk': resolve(__dirname, './src'),
'%': resolve(__dirname, './types'),
},
},
Expand Down
Loading