playkit-sdk 1.2.13 → 1.4.0-beta.1
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.
- package/LICENSE +86 -86
- package/README.md +266 -244
- package/dist/playkit-sdk.cjs.js +1948 -1577
- package/dist/playkit-sdk.cjs.js.map +1 -1
- package/dist/playkit-sdk.d.ts +201 -7
- package/dist/playkit-sdk.esm.js +1948 -1578
- package/dist/playkit-sdk.esm.js.map +1 -1
- package/dist/playkit-sdk.umd.js +2042 -1646
- package/dist/playkit-sdk.umd.js.map +1 -1
- package/package.json +72 -70
package/dist/playkit-sdk.d.ts
CHANGED
|
@@ -413,6 +413,8 @@ interface SDKConfig {
|
|
|
413
413
|
defaultImageModel?: string;
|
|
414
414
|
/** Default transcription model to use */
|
|
415
415
|
defaultTranscriptionModel?: string;
|
|
416
|
+
/** Default text-to-speech model to use */
|
|
417
|
+
defaultTTSModel?: string;
|
|
416
418
|
/**
|
|
417
419
|
* Enable debug logging
|
|
418
420
|
* @deprecated Use `logging.level` instead. Will be removed in v2.0.
|
|
@@ -657,10 +659,12 @@ interface ChatCompletionResponse {
|
|
|
657
659
|
* Streaming chunk formats
|
|
658
660
|
*/
|
|
659
661
|
interface StreamChunk {
|
|
660
|
-
type: 'text-delta' | 'done' | 'error';
|
|
662
|
+
type: 'text-delta' | 'done' | 'finish' | 'abort' | 'error';
|
|
661
663
|
id?: string;
|
|
662
664
|
delta?: string;
|
|
663
665
|
error?: string;
|
|
666
|
+
errorText?: string;
|
|
667
|
+
reason?: string;
|
|
664
668
|
}
|
|
665
669
|
/**
|
|
666
670
|
* NPC Action parameter types
|
|
@@ -874,6 +878,85 @@ interface TranscriptionResponse {
|
|
|
874
878
|
segments?: TranscriptionSegment[];
|
|
875
879
|
}
|
|
876
880
|
|
|
881
|
+
/**
|
|
882
|
+
* Text-to-speech (TTS) type definitions
|
|
883
|
+
*/
|
|
884
|
+
/**
|
|
885
|
+
* Configuration for text-to-speech requests
|
|
886
|
+
*/
|
|
887
|
+
interface TTSConfig {
|
|
888
|
+
/**
|
|
889
|
+
* Text to synthesize into speech (max 10000 characters)
|
|
890
|
+
*/
|
|
891
|
+
text: string;
|
|
892
|
+
/**
|
|
893
|
+
* Model to use for synthesis
|
|
894
|
+
* Defaults to 'default-tts-model' (alias resolved by the backend)
|
|
895
|
+
*/
|
|
896
|
+
model?: string;
|
|
897
|
+
/**
|
|
898
|
+
* Voice id to use (e.g., 'male-qn-qingse')
|
|
899
|
+
*/
|
|
900
|
+
voice?: string;
|
|
901
|
+
/**
|
|
902
|
+
* Playback speed multiplier
|
|
903
|
+
*/
|
|
904
|
+
speed?: number;
|
|
905
|
+
/**
|
|
906
|
+
* Volume
|
|
907
|
+
*/
|
|
908
|
+
vol?: number;
|
|
909
|
+
/**
|
|
910
|
+
* Pitch adjustment
|
|
911
|
+
*/
|
|
912
|
+
pitch?: number;
|
|
913
|
+
/**
|
|
914
|
+
* Emotion of the speech (e.g., 'happy', 'sad')
|
|
915
|
+
*/
|
|
916
|
+
emotion?: string;
|
|
917
|
+
/**
|
|
918
|
+
* Output audio format (e.g., 'mp3', 'wav')
|
|
919
|
+
*/
|
|
920
|
+
format?: string;
|
|
921
|
+
/**
|
|
922
|
+
* Language boost hint to improve pronunciation for a specific language
|
|
923
|
+
*/
|
|
924
|
+
languageBoost?: string;
|
|
925
|
+
/**
|
|
926
|
+
* Passthrough voice settings object for advanced configuration
|
|
927
|
+
*/
|
|
928
|
+
voiceSetting?: Record<string, unknown>;
|
|
929
|
+
/**
|
|
930
|
+
* Passthrough audio settings object for advanced configuration
|
|
931
|
+
*/
|
|
932
|
+
audioSetting?: Record<string, unknown>;
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Options for simplified text-to-speech methods (everything except the text)
|
|
936
|
+
*/
|
|
937
|
+
type TTSOptions = Omit<TTSConfig, 'text'>;
|
|
938
|
+
/**
|
|
939
|
+
* Result of a text-to-speech request
|
|
940
|
+
*/
|
|
941
|
+
interface TTSResult {
|
|
942
|
+
/**
|
|
943
|
+
* Raw audio bytes
|
|
944
|
+
*/
|
|
945
|
+
audio: ArrayBuffer;
|
|
946
|
+
/**
|
|
947
|
+
* Audio format / content type (e.g., 'audio/mpeg' or 'mp3')
|
|
948
|
+
*/
|
|
949
|
+
format: string;
|
|
950
|
+
/**
|
|
951
|
+
* Number of characters billed for this request
|
|
952
|
+
*/
|
|
953
|
+
usageCharacters: number;
|
|
954
|
+
/**
|
|
955
|
+
* Length of the generated audio in milliseconds (if reported)
|
|
956
|
+
*/
|
|
957
|
+
audioLengthMs?: number;
|
|
958
|
+
}
|
|
959
|
+
|
|
877
960
|
/**
|
|
878
961
|
* Device Authorization Flow Manager
|
|
879
962
|
* Manages Device Auth polling flow for desktop/CLI/Unity applications
|
|
@@ -1261,7 +1344,7 @@ interface RechargeConfig {
|
|
|
1261
1344
|
checkBalanceAfterApiCall?: boolean;
|
|
1262
1345
|
/**
|
|
1263
1346
|
* Base URL for the recharge portal
|
|
1264
|
-
* @default 'https://playkit.ai/recharge'
|
|
1347
|
+
* @default 'https://players.playkit.ai/recharge'
|
|
1265
1348
|
*/
|
|
1266
1349
|
rechargePortalUrl?: string;
|
|
1267
1350
|
/**
|
|
@@ -1909,6 +1992,59 @@ declare class TranscriptionClient {
|
|
|
1909
1992
|
transcribeFile(file: File, options?: TranscriptionOptions): Promise<TranscriptionResult>;
|
|
1910
1993
|
}
|
|
1911
1994
|
|
|
1995
|
+
/**
|
|
1996
|
+
* TTS provider for HTTP communication with the text-to-speech API
|
|
1997
|
+
*/
|
|
1998
|
+
|
|
1999
|
+
declare class TTSProvider {
|
|
2000
|
+
private authManager;
|
|
2001
|
+
private config;
|
|
2002
|
+
private baseURL;
|
|
2003
|
+
private playerClient?;
|
|
2004
|
+
constructor(authManager: AuthManager, config: SDKConfig);
|
|
2005
|
+
/**
|
|
2006
|
+
* Set player client for balance checking
|
|
2007
|
+
*/
|
|
2008
|
+
setPlayerClient(playerClient: PlayerClient): void;
|
|
2009
|
+
/**
|
|
2010
|
+
* Synthesize text into speech audio
|
|
2011
|
+
*/
|
|
2012
|
+
synthesize(ttsConfig: TTSConfig): Promise<TTSResult>;
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
/**
|
|
2016
|
+
* High-level client for text-to-speech synthesis
|
|
2017
|
+
*/
|
|
2018
|
+
|
|
2019
|
+
declare class TTSClient {
|
|
2020
|
+
private provider;
|
|
2021
|
+
private model;
|
|
2022
|
+
constructor(provider: TTSProvider, model?: string);
|
|
2023
|
+
/**
|
|
2024
|
+
* Get the current model name
|
|
2025
|
+
*/
|
|
2026
|
+
get modelName(): string;
|
|
2027
|
+
/**
|
|
2028
|
+
* Synthesize text into speech audio
|
|
2029
|
+
* @param config - Full TTS configuration
|
|
2030
|
+
* @returns TTS result containing raw audio bytes and usage metadata
|
|
2031
|
+
*/
|
|
2032
|
+
synthesize(config: TTSConfig): Promise<TTSResult>;
|
|
2033
|
+
/**
|
|
2034
|
+
* Synthesize text into speech and return it as a Blob (browser-friendly)
|
|
2035
|
+
* @param config - Full TTS configuration
|
|
2036
|
+
* @returns Audio Blob with the appropriate MIME type
|
|
2037
|
+
*/
|
|
2038
|
+
synthesizeToBlob(config: TTSConfig): Promise<Blob>;
|
|
2039
|
+
/**
|
|
2040
|
+
* Synthesize text into speech and return an object URL (browser only)
|
|
2041
|
+
* @param config - Full TTS configuration
|
|
2042
|
+
* @returns An object URL that can be assigned to an <audio> element
|
|
2043
|
+
* @throws PlayKitError if URL.createObjectURL is unavailable (e.g. Node.js)
|
|
2044
|
+
*/
|
|
2045
|
+
synthesizeToObjectURL(config: TTSConfig): Promise<string>;
|
|
2046
|
+
}
|
|
2047
|
+
|
|
1912
2048
|
/**
|
|
1913
2049
|
* NPC Client for simplified conversation management
|
|
1914
2050
|
* Automatically handles conversation history
|
|
@@ -2034,10 +2170,11 @@ declare class NPCClient extends EventEmitter {
|
|
|
2034
2170
|
/**
|
|
2035
2171
|
* Manually generate reply predictions based on current conversation.
|
|
2036
2172
|
* Uses the fast model for quick generation.
|
|
2173
|
+
* @param tempPrompt Optional temporary prompt to influence the prediction style/tone
|
|
2037
2174
|
* @param count Number of predictions to generate (default: uses predictionCount property)
|
|
2038
2175
|
* @returns Array of predicted player replies, or empty array on failure
|
|
2039
2176
|
*/
|
|
2040
|
-
generateReplyPredictions(count?: number): Promise<string[]>;
|
|
2177
|
+
generateReplyPredictions(tempPrompt?: string, count?: number): Promise<string[]>;
|
|
2041
2178
|
/**
|
|
2042
2179
|
* Parse predictions from JSON array response
|
|
2043
2180
|
*/
|
|
@@ -2195,6 +2332,8 @@ declare class AIContextManager extends EventEmitter<AIContextManagerEvents> {
|
|
|
2195
2332
|
private static _instance;
|
|
2196
2333
|
private config;
|
|
2197
2334
|
private playerDescription;
|
|
2335
|
+
private playerPrompt;
|
|
2336
|
+
private playerMemories;
|
|
2198
2337
|
private npcStates;
|
|
2199
2338
|
private autoCompactTimer;
|
|
2200
2339
|
private chatClientFactory;
|
|
@@ -2233,6 +2372,47 @@ declare class AIContextManager extends EventEmitter<AIContextManagerEvents> {
|
|
|
2233
2372
|
* Clear the player description.
|
|
2234
2373
|
*/
|
|
2235
2374
|
clearPlayerDescription(): void;
|
|
2375
|
+
/**
|
|
2376
|
+
* Set the player's character prompt/persona.
|
|
2377
|
+
* This defines how the player character speaks and behaves.
|
|
2378
|
+
* Used when generating reply predictions to match the player's tone.
|
|
2379
|
+
* @param prompt The player character's persona/prompt
|
|
2380
|
+
*/
|
|
2381
|
+
setPlayerPrompt(prompt: string | null): void;
|
|
2382
|
+
/**
|
|
2383
|
+
* Get the current player prompt.
|
|
2384
|
+
* @returns The player prompt, or null if not set
|
|
2385
|
+
*/
|
|
2386
|
+
getPlayerPrompt(): string | null;
|
|
2387
|
+
/**
|
|
2388
|
+
* Set or update a memory for the player character.
|
|
2389
|
+
* Memories are appended to the player prompt to form the full player context.
|
|
2390
|
+
* Set memoryContent to null or empty to remove the memory.
|
|
2391
|
+
* @param memoryName The name/key of the memory
|
|
2392
|
+
* @param memoryContent The content of the memory. Null or empty to remove.
|
|
2393
|
+
*/
|
|
2394
|
+
setPlayerMemory(memoryName: string, memoryContent: string | null): void;
|
|
2395
|
+
/**
|
|
2396
|
+
* Get a specific player memory by name.
|
|
2397
|
+
* @param memoryName The name of the memory to retrieve
|
|
2398
|
+
* @returns The memory content, or undefined if not found
|
|
2399
|
+
*/
|
|
2400
|
+
getPlayerMemory(memoryName: string): string | undefined;
|
|
2401
|
+
/**
|
|
2402
|
+
* Get all player memory names currently stored.
|
|
2403
|
+
* @returns Array of memory names
|
|
2404
|
+
*/
|
|
2405
|
+
getPlayerMemoryNames(): string[];
|
|
2406
|
+
/**
|
|
2407
|
+
* Clear all player memories (but keep player prompt).
|
|
2408
|
+
*/
|
|
2409
|
+
clearPlayerMemories(): void;
|
|
2410
|
+
/**
|
|
2411
|
+
* Build the complete player context from PlayerPrompt + PlayerMemories.
|
|
2412
|
+
* Used by NPCClient for generating reply predictions.
|
|
2413
|
+
* @returns The combined player context string, or null if no context is set
|
|
2414
|
+
*/
|
|
2415
|
+
buildPlayerContext(): string | null;
|
|
2236
2416
|
/**
|
|
2237
2417
|
* Register an NPC for context management.
|
|
2238
2418
|
* @param npc The NPC client to register
|
|
@@ -2313,6 +2493,7 @@ declare class PlayKitSDK extends EventEmitter {
|
|
|
2313
2493
|
private chatProvider;
|
|
2314
2494
|
private imageProvider;
|
|
2315
2495
|
private transcriptionProvider;
|
|
2496
|
+
private ttsProvider;
|
|
2316
2497
|
private contextManager;
|
|
2317
2498
|
private schemaLibrary;
|
|
2318
2499
|
private initialized;
|
|
@@ -2382,6 +2563,11 @@ declare class PlayKitSDK extends EventEmitter {
|
|
|
2382
2563
|
* @param model - Transcription model to use (default: 'whisper-large')
|
|
2383
2564
|
*/
|
|
2384
2565
|
createTranscriptionClient(model?: string): TranscriptionClient;
|
|
2566
|
+
/**
|
|
2567
|
+
* Create a TTS client for text-to-speech
|
|
2568
|
+
* @param model - TTS model to use (default: 'default-tts-model')
|
|
2569
|
+
*/
|
|
2570
|
+
createTTSClient(model?: string): TTSClient;
|
|
2385
2571
|
/**
|
|
2386
2572
|
* Create an NPC client
|
|
2387
2573
|
* Automatically registers with AIContextManager
|
|
@@ -2682,8 +2868,8 @@ declare class TokenStorage {
|
|
|
2682
2868
|
declare class AuthFlowManager extends EventEmitter {
|
|
2683
2869
|
private baseURL;
|
|
2684
2870
|
private currentSessionId;
|
|
2685
|
-
private
|
|
2686
|
-
private
|
|
2871
|
+
private _uiContainer;
|
|
2872
|
+
private _isSuccess;
|
|
2687
2873
|
private currentLanguage;
|
|
2688
2874
|
private modal;
|
|
2689
2875
|
private identifierPanel;
|
|
@@ -2903,5 +3089,13 @@ declare class TokenValidator {
|
|
|
2903
3089
|
*/
|
|
2904
3090
|
declare const defaultTokenValidator: TokenValidator;
|
|
2905
3091
|
|
|
2906
|
-
|
|
2907
|
-
|
|
3092
|
+
declare global {
|
|
3093
|
+
interface Window {
|
|
3094
|
+
PlayKitSDK: typeof PlayKitSDK & {
|
|
3095
|
+
PlayKitSDK: typeof PlayKitSDK;
|
|
3096
|
+
};
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
|
|
3100
|
+
export { AIContextManager, AuthFlowManager, AuthManager, BrowserStorage, BufferLogHandler, CallbackLogHandler, ChatClient, DeviceAuthFlowManager, ImageClient, LogLevel, Logger, MemoryStorage, NPCClient, PlayKitError, PlayKitSDK, PlayerClient, RechargeManager, SchemaLibrary, StreamParser, TTSClient, TokenStorage, TokenValidator, TranscriptionClient, createMultimodalMessage, createStorage, createTextMessage, PlayKitSDK as default, defaultContextManager, defaultSchemaLibrary, defaultTokenValidator, isLocalStorageAvailable };
|
|
3101
|
+
export type { AIContextManagerConfig, AIContextManagerEvents, APIResult, AudioContentPart, AuthState, ChatCompletionResponse, ChatConfig, ChatResult, ChatStreamConfig, ChatWithToolsConfig, ChatWithToolsStreamConfig, ConversationSaveData, DeveloperTokenFallbackConfig, DeviceAuthFlowOptions, DeviceAuthInitResult, DeviceAuthResult, GameInfo, GeneratedImage, IStorage, ImageContentPart, ImageGenerationConfig, ImageGenerationResponse, ImageInput, ImageSize, LogConfig, LogEntry, LogHandler, MemoryEntry, Message, MessageContent, MessageContentPart, MessageRole, NPCConfig, PlayerInfo, RechargeConfig, RechargeEvents, RechargeModalOptions, SDKConfig, SDKMode, SchemaEntry, SetNicknameRequest, SetNicknameResponse, StreamChunk, StructuredGenerationConfig, StructuredOutputConfig, StructuredResult, TTSConfig, TTSOptions, TTSResult, TextContentPart, TokenRefreshResult, TokenScope, TokenStorageOptions, TokenValidatorOptions, TokenVerificationResult, TranscriptionConfig, TranscriptionOptions, TranscriptionResult, TranscriptionSegment, ValidatedPlayerInfo };
|