diff --git a/.prettierrc.json b/.prettierrc.json index 0b779fb0..45775a3c 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -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", diff --git a/demo/app.tsx b/demo/app.tsx index 585bb987..5df62f90 100644 --- a/demo/app.tsx +++ b/demo/app.tsx @@ -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'; diff --git a/demo/hooks/useAgentManager.ts b/demo/hooks/useAgentManager.ts index b35bb3ec..600359b2 100644 --- a/demo/hooks/useAgentManager.ts +++ b/demo/hooks/useAgentManager.ts @@ -1,4 +1,4 @@ -import { createAgentManager } from '$/services/agent-manager'; +import { createAgentManager } from '@sdk/services/agent-manager'; import { AgentActivityState, AgentManager, @@ -8,7 +8,7 @@ import { Message, StreamType, StreamingState, -} from '$/types'; +} from '@sdk/types'; import { useCallback, useEffect, useState } from 'preact/hooks'; interface UseAgentManagerOptions { diff --git a/jest.config.cjs b/jest.config.cjs index 703c51cf..327ae18b 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -5,7 +5,7 @@ module.exports = { testMatch: ['**/**.spec.ts', '**/**.test.ts', '**/**.test.tsx'], transform: { '^.+\\.tsx?$': ['ts-jest', { useESM: true, tsconfig: '/tsconfig.json' }] }, extensionsToTreatAsEsm: ['.ts', '.tsx'], - moduleNameMapper: { '^\\$/(.*)$': '/src/$1', '^%/(.*)$': '/src/types/$1' }, + moduleNameMapper: { '^@sdk/(.*)$': '/src/$1', '^%/(.*)$': '/src/types/$1' }, setupFiles: ['/jest.setup.ts'], ...(process.env.CI && { reporters: ['summary'] }), diff --git a/package.json b/package.json index bb849b78..5b93eb57 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/api/agents.ts b/src/api/agents.ts index afcb5656..35fbae32 100644 --- a/src/api/agents.ts +++ b/src/api/agents.ts @@ -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'; diff --git a/src/api/apiClient.ts b/src/api/apiClient.ts index 725da135..e1810881 100644 --- a/src/api/apiClient.ts +++ b/src/api/apiClient.ts @@ -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'; diff --git a/src/api/knowledge.ts b/src/api/knowledge.ts index e748a140..a941ccf0 100644 --- a/src/api/knowledge.ts +++ b/src/api/knowledge.ts @@ -6,7 +6,7 @@ import { KnowledgePayload, QueryResult, RecordData, -} from '$/types/index'; +} from '@sdk/types/index'; import { didApiUrl } from '../config/environment'; import { createClient } from './apiClient'; diff --git a/src/api/streams/streamApi.ts b/src/api/streams/streamApi.ts index d4fd971e..0ff77646 100644 --- a/src/api/streams/streamApi.ts +++ b/src/api/streams/streamApi.ts @@ -8,7 +8,7 @@ import { SendStreamPayloadResponse, SendTalkStreamPayload, Status, -} from '$/types/index'; +} from '@sdk/types/index'; import { createClient } from '../apiClient'; export function createStreamApi( diff --git a/src/api/streams/streamsApiV2.ts b/src/api/streams/streamsApiV2.ts index 8613a298..da256947 100644 --- a/src/api/streams/streamsApiV2.ts +++ b/src/api/streams/streamsApiV2.ts @@ -1,4 +1,4 @@ -import { Auth, CreateStreamV2Options, CreateStreamV2Response } from '$/types'; +import { Auth, CreateStreamV2Options, CreateStreamV2Response } from '@sdk/types'; import { createClient } from '../apiClient'; export function createStreamApiV2( diff --git a/src/auth/get-auth-header.ts b/src/auth/get-auth-header.ts index 7b10fea7..10668863 100644 --- a/src/auth/get-auth-header.ts +++ b/src/auth/get-auth-header.ts @@ -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) { diff --git a/src/errors/chat/chat-creation-failed.ts b/src/errors/chat/chat-creation-failed.ts index 46247708..0ddce8ba 100644 --- a/src/errors/chat/chat-creation-failed.ts +++ b/src/errors/chat/chat-creation-failed.ts @@ -1,4 +1,4 @@ -import { ChatMode } from '$/types'; +import { ChatMode } from '@sdk/types'; import { BaseError } from '../base-error'; export class ChatCreationFailed extends BaseError { diff --git a/src/errors/chat/chat-mode-downgraded.ts b/src/errors/chat/chat-mode-downgraded.ts index c659c888..5f1d7cf7 100644 --- a/src/errors/chat/chat-mode-downgraded.ts +++ b/src/errors/chat/chat-mode-downgraded.ts @@ -1,4 +1,4 @@ -import { ChatMode } from '$/types'; +import { ChatMode } from '@sdk/types'; import { BaseError } from '../base-error'; export class ChatModeDowngraded extends BaseError { diff --git a/src/services/agent-manager/connect-to-manager.test.ts b/src/services/agent-manager/connect-to-manager.test.ts index 75755538..22dfa89c 100644 --- a/src/services/agent-manager/connect-to-manager.test.ts +++ b/src/services/agent-manager/connect-to-manager.test.ts @@ -1,3 +1,4 @@ +import { createStreamingManager, StreamApiVersion } from '@sdk/services/streaming-manager'; import { Agent, AgentActivityState, @@ -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', diff --git a/src/services/agent-manager/connect-to-manager.ts b/src/services/agent-manager/connect-to-manager.ts index 100381da..8151904f 100644 --- a/src/services/agent-manager/connect-to-manager.ts +++ b/src/services/agent-manager/connect-to-manager.ts @@ -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, @@ -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'; diff --git a/src/services/agent-manager/index.ts b/src/services/agent-manager/index.ts index 47bf26e5..6c0d81f5 100644 --- a/src/services/agent-manager/index.ts +++ b/src/services/agent-manager/index.ts @@ -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'; diff --git a/src/services/analytics/mixpanel.ts b/src/services/analytics/mixpanel.ts index 2291c868..76dd775b 100644 --- a/src/services/analytics/mixpanel.ts +++ b/src/services/analytics/mixpanel.ts @@ -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; diff --git a/src/services/chat/index.ts b/src/services/chat/index.ts index d7ae33ad..82f75687 100644 --- a/src/services/chat/index.ts +++ b/src/services/chat/index.ts @@ -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> { diff --git a/src/services/chat/intial-messages.ts b/src/services/chat/intial-messages.ts index 0976a860..fa042aff 100644 --- a/src/services/chat/intial-messages.ts +++ b/src/services/chat/intial-messages.ts @@ -1,4 +1,4 @@ -import { Message } from '$/types'; +import { Message } from '@sdk/types'; export function getInitialMessages(initialMessages?: Message[]): Message[] { if (initialMessages && initialMessages.length > 0) { diff --git a/src/services/interrupt/index.ts b/src/services/interrupt/index.ts index 95d196c3..5864a4ba 100644 --- a/src/services/interrupt/index.ts +++ b/src/services/interrupt/index.ts @@ -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( diff --git a/src/services/socket-manager/index.ts b/src/services/socket-manager/index.ts index bbe0e622..2696417d 100644 --- a/src/services/socket-manager/index.ts +++ b/src/services/socket-manager/index.ts @@ -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; diff --git a/src/services/socket-manager/message-queue.ts b/src/services/socket-manager/message-queue.ts index 6400e03e..4380d0a2 100644 --- a/src/services/socket-manager/message-queue.ts +++ b/src/services/socket-manager/message-queue.ts @@ -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'; diff --git a/src/services/streaming-manager/common.ts b/src/services/streaming-manager/common.ts index 25f51e7a..e34d4f2a 100644 --- a/src/services/streaming-manager/common.ts +++ b/src/services/streaming-manager/common.ts @@ -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 ?? ''); diff --git a/src/services/streaming-manager/factory.ts b/src/services/streaming-manager/factory.ts index 7f73383d..865f7019 100644 --- a/src/services/streaming-manager/factory.ts +++ b/src/services/streaming-manager/factory.ts @@ -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'; diff --git a/src/services/streaming-manager/livekit-manager.ts b/src/services/streaming-manager/livekit-manager.ts index 86d8c594..addf97a0 100644 --- a/src/services/streaming-manager/livekit-manager.ts +++ b/src/services/streaming-manager/livekit-manager.ts @@ -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'; diff --git a/src/services/streaming-manager/stats/poll.ts b/src/services/streaming-manager/stats/poll.ts index 226aefe3..d0f1d7b4 100644 --- a/src/services/streaming-manager/stats/poll.ts +++ b/src/services/streaming-manager/stats/poll.ts @@ -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; diff --git a/src/services/streaming-manager/stats/report.ts b/src/services/streaming-manager/stats/report.ts index e8b2b3b8..2d5363df 100644 --- a/src/services/streaming-manager/stats/report.ts +++ b/src/services/streaming-manager/stats/report.ts @@ -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: { diff --git a/src/services/streaming-manager/webrtc-manager.ts b/src/services/streaming-manager/webrtc-manager.ts index d918e2b5..d5416cf5 100644 --- a/src/services/streaming-manager/webrtc-manager.ts +++ b/src/services/streaming-manager/webrtc-manager.ts @@ -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, @@ -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'; diff --git a/src/types/entities/agents/manager.ts b/src/types/entities/agents/manager.ts index 1b52db29..44aeb2ab 100644 --- a/src/types/entities/agents/manager.ts +++ b/src/types/entities/agents/manager.ts @@ -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, @@ -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'; diff --git a/src/types/entities/agents/presenter.ts b/src/types/entities/agents/presenter.ts index 46b0e2e3..6f20af93 100644 --- a/src/types/entities/agents/presenter.ts +++ b/src/types/entities/agents/presenter.ts @@ -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'; diff --git a/src/types/stream/stream.ts b/src/types/stream/stream.ts index 76fb22ff..a915e842 100644 --- a/src/types/stream/stream.ts +++ b/src/types/stream/stream.ts @@ -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'; diff --git a/src/utils/agent.ts b/src/utils/agent.ts index a85a1a35..58d50d0a 100644 --- a/src/utils/agent.ts +++ b/src/utils/agent.ts @@ -1,4 +1,4 @@ -import { Agent, VideoType } from '$/types'; +import { Agent, VideoType } from '@sdk/types'; type AgentType = 'clip_v2' | Agent['presenter']['type']; diff --git a/src/utils/analytics.ts b/src/utils/analytics.ts index 562a5a67..25705a47 100644 --- a/src/utils/analytics.ts +++ b/src/utils/analytics.ts @@ -1,4 +1,4 @@ -import { Agent } from '$/types/index'; +import { Agent } from '@sdk/types/index'; import { getAgentType } from './agent'; export function getAnalyticsInfo(agent: Agent) { diff --git a/src/utils/chat.ts b/src/utils/chat.ts index cb722025..06d683ec 100644 --- a/src/utils/chat.ts +++ b/src/utils/chat.ts @@ -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); diff --git a/tsconfig.json b/tsconfig.json index 5636db0c..fb763543 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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" }] } diff --git a/vite.config.ts b/vite.config.ts index 8f0b7523..b58eb8ee 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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'), }, },