perso-interactive-sdk-web 1.5.0 → 1.6.0
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/README.md +133 -84
- package/dist/client/index.cjs +1 -1
- package/dist/client/index.d.ts +457 -68
- package/dist/client/index.iife.js +1 -1
- package/dist/client/index.js +1 -1
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.d.ts +183 -79
- package/dist/server/index.js +1 -1
- package/package.json +1 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -16,38 +16,30 @@ type CreateSessionIdBody = {
|
|
|
16
16
|
stt_text_normalization_config?: string;
|
|
17
17
|
stt_text_normalization_locale?: string | null;
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* @throws {DoesNotExistError} When the server response `code` is `'does_not_exist'` (subclass of `SessionCreationError`).
|
|
32
|
-
* @throws {NotInOrganizationError} When the server response `code` is `'not_in_organization'` (subclass of `SessionCreationError`).
|
|
33
|
-
*/
|
|
19
|
+
type CreateSessionIdObjectOptions = {
|
|
20
|
+
apiKey: string;
|
|
21
|
+
params: CreateSessionIdBody;
|
|
22
|
+
apiServer?: string;
|
|
23
|
+
} | {
|
|
24
|
+
apiKey: string;
|
|
25
|
+
sessionTemplateId: string;
|
|
26
|
+
apiServer?: string;
|
|
27
|
+
};
|
|
28
|
+
/** @overload Object-form. Uses DEFAULT_API_SERVER when apiServer is omitted. */
|
|
29
|
+
declare function createSessionId(options: CreateSessionIdObjectOptions): Promise<string>;
|
|
30
|
+
/** @overload Positional form — SessionTemplate ID. */
|
|
34
31
|
declare function createSessionId(apiServer: string, apiKey: string, sessionTemplateId: string): Promise<string>;
|
|
35
|
-
/**
|
|
36
|
-
* @overload Creates a session from explicit runtime options.
|
|
37
|
-
* @param apiServer Perso API server URL.
|
|
38
|
-
* @param apiKey API key used for authentication.
|
|
39
|
-
* @param params Runtime options for the session.
|
|
40
|
-
* @returns Session ID returned by the server.
|
|
41
|
-
*/
|
|
32
|
+
/** @overload Positional form — explicit params. */
|
|
42
33
|
declare function createSessionId(apiServer: string, apiKey: string, params: CreateSessionIdBody): Promise<string>;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
34
|
+
type GetIntroMessageObjectOptions = {
|
|
35
|
+
apiKey: string;
|
|
36
|
+
promptId: string;
|
|
37
|
+
apiServer?: string;
|
|
38
|
+
};
|
|
39
|
+
/** @overload Object-form. Uses DEFAULT_API_SERVER when apiServer is omitted. */
|
|
40
|
+
declare function getIntroMessage(options: GetIntroMessageObjectOptions): Promise<string>;
|
|
41
|
+
/** @overload Positional form. */
|
|
42
|
+
declare function getIntroMessage(apiServer: string, apiKey: string, promptId: string): Promise<string>;
|
|
51
43
|
|
|
52
44
|
interface Prompt {
|
|
53
45
|
prompt_id: string;
|
|
@@ -94,14 +86,12 @@ interface STTType {
|
|
|
94
86
|
}
|
|
95
87
|
/**
|
|
96
88
|
* Response from POST /api/v1/session/{session_id}/stt/.
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
89
|
+
*
|
|
90
|
+
* The wire payload includes additional fields (e.g., `locale`,
|
|
91
|
+
* `normalized_text`) that the SDK intentionally does not expose.
|
|
100
92
|
*/
|
|
101
93
|
interface STTResponse {
|
|
102
94
|
text: string;
|
|
103
|
-
locale: string;
|
|
104
|
-
normalized_text: string;
|
|
105
95
|
}
|
|
106
96
|
interface TextNormalizationConfig {
|
|
107
97
|
textnormalizationconfig_id: string;
|
|
@@ -425,15 +415,10 @@ declare class PersoUtil {
|
|
|
425
415
|
* @param sessionId Session ID for the current session
|
|
426
416
|
* @param audioFile Audio file (WAV format)
|
|
427
417
|
* @param language Optional language code (e.g., 'ko', 'en')
|
|
428
|
-
* @returns STTResponse with
|
|
429
|
-
* {
|
|
430
|
-
* "text": string,
|
|
431
|
-
* "locale": string,
|
|
432
|
-
* "normalized_text": string
|
|
433
|
-
* }
|
|
418
|
+
* @returns STTResponse with only the transcribed text.
|
|
434
419
|
*
|
|
435
|
-
*
|
|
436
|
-
*
|
|
420
|
+
* The server returns additional fields (e.g., `locale`, `normalized_text`)
|
|
421
|
+
* which are intentionally not exposed by the SDK.
|
|
437
422
|
*/
|
|
438
423
|
static makeSTT(apiServer: string, sessionId: string, audioFile: File, language?: string): Promise<STTResponse>;
|
|
439
424
|
/**
|
|
@@ -467,120 +452,239 @@ declare class PersoUtil {
|
|
|
467
452
|
static parseJson(response: Response): Promise<any>;
|
|
468
453
|
}
|
|
469
454
|
|
|
455
|
+
type ApiKeyOptions = {
|
|
456
|
+
apiKey: string;
|
|
457
|
+
apiServer?: string;
|
|
458
|
+
};
|
|
470
459
|
/**
|
|
471
460
|
* Retrieves the list of available LLM providers from the API.
|
|
461
|
+
*
|
|
462
|
+
* @param options.apiKey API key used for authentication.
|
|
463
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
464
|
+
*/
|
|
465
|
+
declare function getLLMs(options: ApiKeyOptions): ReturnType<typeof PersoUtil.getLLMs>;
|
|
466
|
+
/**
|
|
472
467
|
* @param apiServer Perso API server URL.
|
|
473
468
|
* @param apiKey API key used for authentication.
|
|
474
|
-
* @returns Promise resolving with LLM metadata.
|
|
475
469
|
*/
|
|
476
|
-
declare function getLLMs(apiServer: string, apiKey: string):
|
|
470
|
+
declare function getLLMs(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getLLMs>;
|
|
477
471
|
/**
|
|
478
472
|
* Retrieves available TTS providers.
|
|
473
|
+
*
|
|
474
|
+
* @param options.apiKey API key used for authentication.
|
|
475
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
476
|
+
*/
|
|
477
|
+
declare function getTTSs(options: ApiKeyOptions): ReturnType<typeof PersoUtil.getTTSs>;
|
|
478
|
+
/**
|
|
479
479
|
* @param apiServer Perso API server URL.
|
|
480
480
|
* @param apiKey API key used for authentication.
|
|
481
481
|
*/
|
|
482
|
-
declare function getTTSs(apiServer: string, apiKey: string):
|
|
482
|
+
declare function getTTSs(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getTTSs>;
|
|
483
483
|
/**
|
|
484
484
|
* Retrieves available STT providers.
|
|
485
|
+
*
|
|
486
|
+
* @param options.apiKey API key used for authentication.
|
|
487
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
488
|
+
*/
|
|
489
|
+
declare function getSTTs(options: ApiKeyOptions): ReturnType<typeof PersoUtil.getSTTs>;
|
|
490
|
+
/**
|
|
485
491
|
* @param apiServer Perso API server URL.
|
|
486
492
|
* @param apiKey API key used for authentication.
|
|
487
493
|
*/
|
|
488
|
-
declare function getSTTs(apiServer: string, apiKey: string):
|
|
494
|
+
declare function getSTTs(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getSTTs>;
|
|
489
495
|
/**
|
|
490
496
|
* Fetches avatar model styles.
|
|
497
|
+
*
|
|
498
|
+
* @param options.apiKey API key used for authentication.
|
|
499
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
500
|
+
*/
|
|
501
|
+
declare function getModelStyles(options: ApiKeyOptions): ReturnType<typeof PersoUtil.getModelStyles>;
|
|
502
|
+
/**
|
|
491
503
|
* @param apiServer Perso API server URL.
|
|
492
504
|
* @param apiKey API key used for authentication.
|
|
493
505
|
*/
|
|
494
|
-
declare function getModelStyles(apiServer: string, apiKey: string):
|
|
506
|
+
declare function getModelStyles(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getModelStyles>;
|
|
495
507
|
/**
|
|
496
508
|
* Fetches preset background images.
|
|
509
|
+
*
|
|
510
|
+
* @param options.apiKey API key used for authentication.
|
|
511
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
512
|
+
*/
|
|
513
|
+
declare function getBackgroundImages(options: ApiKeyOptions): ReturnType<typeof PersoUtil.getBackgroundImages>;
|
|
514
|
+
/**
|
|
497
515
|
* @param apiServer Perso API server URL.
|
|
498
516
|
* @param apiKey API key used for authentication.
|
|
499
517
|
*/
|
|
500
|
-
declare function getBackgroundImages(apiServer: string, apiKey: string):
|
|
518
|
+
declare function getBackgroundImages(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getBackgroundImages>;
|
|
501
519
|
/**
|
|
502
520
|
* Returns predefined prompt templates.
|
|
521
|
+
*
|
|
522
|
+
* @param options.apiKey API key used for authentication.
|
|
523
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
524
|
+
*/
|
|
525
|
+
declare function getPrompts(options: ApiKeyOptions): ReturnType<typeof PersoUtil.getPrompts>;
|
|
526
|
+
/**
|
|
503
527
|
* @param apiServer Perso API server URL.
|
|
504
528
|
* @param apiKey API key used for authentication.
|
|
505
529
|
*/
|
|
506
|
-
declare function getPrompts(apiServer: string, apiKey: string):
|
|
530
|
+
declare function getPrompts(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getPrompts>;
|
|
507
531
|
/**
|
|
508
532
|
* Returns supporting document metadata usable by the session.
|
|
533
|
+
*
|
|
534
|
+
* @param options.apiKey API key used for authentication.
|
|
535
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
536
|
+
*/
|
|
537
|
+
declare function getDocuments(options: ApiKeyOptions): ReturnType<typeof PersoUtil.getDocuments>;
|
|
538
|
+
/**
|
|
509
539
|
* @param apiServer Perso API server URL.
|
|
510
540
|
* @param apiKey API key used for authentication.
|
|
511
541
|
*/
|
|
512
|
-
declare function getDocuments(apiServer: string, apiKey: string):
|
|
542
|
+
declare function getDocuments(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getDocuments>;
|
|
513
543
|
/**
|
|
514
544
|
* Lists MCP server identifiers configured for the tenant.
|
|
545
|
+
*
|
|
546
|
+
* @param options.apiKey API key used for authentication.
|
|
547
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
548
|
+
*/
|
|
549
|
+
declare function getMcpServers(options: ApiKeyOptions): ReturnType<typeof PersoUtil.getMcpServers>;
|
|
550
|
+
/**
|
|
515
551
|
* @param apiServer Perso API server URL.
|
|
516
552
|
* @param apiKey API key used for authentication.
|
|
517
553
|
*/
|
|
518
|
-
declare function getMcpServers(apiServer: string, apiKey: string):
|
|
554
|
+
declare function getMcpServers(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getMcpServers>;
|
|
519
555
|
/**
|
|
520
556
|
* Retrieves available text normalization options.
|
|
557
|
+
*
|
|
558
|
+
* @param options.apiKey API key used for authentication.
|
|
559
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
560
|
+
*/
|
|
561
|
+
declare function getTextNormalizations(options: ApiKeyOptions): ReturnType<typeof PersoUtil.getTextNormalizations>;
|
|
562
|
+
/**
|
|
521
563
|
* @param apiServer Perso API server URL.
|
|
522
564
|
* @param apiKey API key used for authentication.
|
|
523
565
|
*/
|
|
524
|
-
declare function getTextNormalizations(apiServer: string, apiKey: string):
|
|
566
|
+
declare function getTextNormalizations(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getTextNormalizations>;
|
|
567
|
+
type GetTextNormalizationOptions = {
|
|
568
|
+
apiKey: string;
|
|
569
|
+
configId: string;
|
|
570
|
+
apiServer?: string;
|
|
571
|
+
};
|
|
525
572
|
/**
|
|
526
573
|
* Downloads the ruleset data file for a Text Normalization Config.
|
|
527
574
|
* Returns a pre-signed Blob Storage URL for the CSV file.
|
|
575
|
+
*
|
|
576
|
+
* @param options.apiKey API key used for authentication.
|
|
577
|
+
* @param options.configId Identifier of the Text Normalization Config to download.
|
|
578
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
579
|
+
*/
|
|
580
|
+
declare function getTextNormalization(options: GetTextNormalizationOptions): Promise<TextNormalizationDownload>;
|
|
581
|
+
/**
|
|
528
582
|
* @param apiServer Perso API server URL.
|
|
529
583
|
* @param apiKey API key used for authentication.
|
|
530
|
-
* @param configId Text Normalization Config
|
|
584
|
+
* @param configId Identifier of the Text Normalization Config to download.
|
|
531
585
|
*/
|
|
532
586
|
declare function getTextNormalization(apiServer: string, apiKey: string, configId: string): Promise<TextNormalizationDownload>;
|
|
533
587
|
/**
|
|
534
588
|
* Retrieves the list of session templates.
|
|
589
|
+
*
|
|
590
|
+
* @param options.apiKey API key used for authentication.
|
|
591
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
592
|
+
*/
|
|
593
|
+
declare function getSessionTemplates(options: ApiKeyOptions): Promise<SessionTemplate[]>;
|
|
594
|
+
/**
|
|
535
595
|
* @param apiServer Perso API server URL.
|
|
536
596
|
* @param apiKey API key used for authentication.
|
|
537
597
|
*/
|
|
538
598
|
declare function getSessionTemplates(apiServer: string, apiKey: string): Promise<SessionTemplate[]>;
|
|
599
|
+
type GetSessionTemplateOptions = {
|
|
600
|
+
apiKey: string;
|
|
601
|
+
sessionTemplateId: string;
|
|
602
|
+
apiServer?: string;
|
|
603
|
+
};
|
|
539
604
|
/**
|
|
540
605
|
* Retrieves a single session template by ID.
|
|
606
|
+
*
|
|
607
|
+
* @param options.apiKey API key used for authentication.
|
|
608
|
+
* @param options.sessionTemplateId Identifier of the session template to fetch.
|
|
609
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
610
|
+
*/
|
|
611
|
+
declare function getSessionTemplate(options: GetSessionTemplateOptions): Promise<SessionTemplate>;
|
|
612
|
+
/**
|
|
541
613
|
* @param apiServer Perso API server URL.
|
|
542
614
|
* @param apiKey API key used for authentication.
|
|
543
|
-
* @param sessionTemplateId
|
|
615
|
+
* @param sessionTemplateId Identifier of the session template to fetch.
|
|
544
616
|
*/
|
|
545
617
|
declare function getSessionTemplate(apiServer: string, apiKey: string, sessionTemplateId: string): Promise<SessionTemplate>;
|
|
618
|
+
type AllSettings = {
|
|
619
|
+
llms: Awaited<ReturnType<typeof PersoUtil.getLLMs>>;
|
|
620
|
+
ttsTypes: Awaited<ReturnType<typeof PersoUtil.getTTSs>>;
|
|
621
|
+
sttTypes: Awaited<ReturnType<typeof PersoUtil.getSTTs>>;
|
|
622
|
+
modelStyles: Awaited<ReturnType<typeof PersoUtil.getModelStyles>>;
|
|
623
|
+
backgroundImages: Awaited<ReturnType<typeof PersoUtil.getBackgroundImages>>;
|
|
624
|
+
prompts: Awaited<ReturnType<typeof PersoUtil.getPrompts>>;
|
|
625
|
+
documents: Awaited<ReturnType<typeof PersoUtil.getDocuments>>;
|
|
626
|
+
mcpServers: Awaited<ReturnType<typeof PersoUtil.getMcpServers>>;
|
|
627
|
+
textNormalizations: Awaited<ReturnType<typeof PersoUtil.getTextNormalizations>> | [];
|
|
628
|
+
};
|
|
546
629
|
/**
|
|
547
630
|
* Convenience helper that fetches every dropdown-friendly resource needed to
|
|
548
631
|
* build a Perso session configuration screen in one call chain.
|
|
549
|
-
*
|
|
550
|
-
* @param apiKey API key used for authentication.
|
|
551
|
-
* @
|
|
552
|
-
*/
|
|
553
|
-
declare function getAllSettings(
|
|
554
|
-
llms: any;
|
|
555
|
-
ttsTypes: any;
|
|
556
|
-
sttTypes: any;
|
|
557
|
-
modelStyles: any;
|
|
558
|
-
backgroundImages: any;
|
|
559
|
-
prompts: any;
|
|
560
|
-
documents: any;
|
|
561
|
-
mcpServers: any;
|
|
562
|
-
textNormalizations: any;
|
|
563
|
-
}>;
|
|
632
|
+
*
|
|
633
|
+
* @param options.apiKey API key used for authentication.
|
|
634
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
635
|
+
*/
|
|
636
|
+
declare function getAllSettings(options: ApiKeyOptions): Promise<AllSettings>;
|
|
564
637
|
/**
|
|
565
|
-
* Sends text to the TTS API and returns Base64-encoded audio.
|
|
566
638
|
* @param apiServer Perso API server URL.
|
|
567
|
-
* @param
|
|
568
|
-
* @returns Object with Base64 audio string.
|
|
639
|
+
* @param apiKey API key used for authentication.
|
|
569
640
|
*/
|
|
570
|
-
declare function
|
|
641
|
+
declare function getAllSettings(apiServer: string, apiKey: string): Promise<AllSettings>;
|
|
642
|
+
type MakeTTSParams = {
|
|
571
643
|
sessionId: string;
|
|
572
644
|
text: string;
|
|
573
645
|
locale?: string;
|
|
574
646
|
output_format?: string;
|
|
575
|
-
}
|
|
647
|
+
};
|
|
648
|
+
type MakeTTSOptions = MakeTTSParams & {
|
|
649
|
+
apiServer?: string;
|
|
650
|
+
};
|
|
651
|
+
/**
|
|
652
|
+
* Sends text to the TTS API and returns Base64-encoded audio.
|
|
653
|
+
*
|
|
654
|
+
* @param options.sessionId Identifier of the active session.
|
|
655
|
+
* @param options.text Text to synthesize.
|
|
656
|
+
* @param options.locale Optional locale override for the TTS voice.
|
|
657
|
+
* @param options.output_format Optional output audio format.
|
|
658
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
659
|
+
*/
|
|
660
|
+
declare function makeTTS(options: MakeTTSOptions): Promise<{
|
|
661
|
+
audio: string;
|
|
662
|
+
}>;
|
|
663
|
+
/**
|
|
664
|
+
* @param apiServer Perso API server URL.
|
|
665
|
+
* @param params TTS request parameters (`sessionId`, `text`, optional `locale`, `output_format`).
|
|
666
|
+
*/
|
|
667
|
+
declare function makeTTS(apiServer: string, params: MakeTTSParams): Promise<{
|
|
576
668
|
audio: string;
|
|
577
669
|
}>;
|
|
670
|
+
type GetSessionInfoOptions = {
|
|
671
|
+
sessionId: string;
|
|
672
|
+
apiServer?: string;
|
|
673
|
+
};
|
|
578
674
|
/**
|
|
579
675
|
* Retrieves metadata for an existing session.
|
|
676
|
+
*
|
|
677
|
+
* @param options.sessionId Identifier of the session to look up.
|
|
678
|
+
* @param options.apiServer Perso API server URL. Defaults to `https://platform.perso.ai`.
|
|
679
|
+
*/
|
|
680
|
+
declare function getSessionInfo(options: GetSessionInfoOptions): ReturnType<typeof PersoUtil.getSessionInfo>;
|
|
681
|
+
/**
|
|
580
682
|
* @param apiServer Perso API server URL.
|
|
581
|
-
* @param sessionId
|
|
683
|
+
* @param sessionId Identifier of the session to look up.
|
|
582
684
|
*/
|
|
583
|
-
declare function getSessionInfo(apiServer: string, sessionId: string):
|
|
685
|
+
declare function getSessionInfo(apiServer: string, sessionId: string): ReturnType<typeof PersoUtil.getSessionInfo>;
|
|
686
|
+
|
|
687
|
+
declare const DEFAULT_API_SERVER = "https://platform.perso.ai";
|
|
584
688
|
|
|
585
689
|
declare class ApiError extends Error {
|
|
586
690
|
errorCode: number;
|
|
@@ -625,5 +729,5 @@ declare class NotInOrganizationError extends SessionCreationError {
|
|
|
625
729
|
constructor(source: ApiError);
|
|
626
730
|
}
|
|
627
731
|
|
|
628
|
-
export { ApiError, DoesNotExistError, NotInOrganizationError, PersoUtil as PersoUtilServer, SessionCreationError, createSessionId, getAllSettings, getBackgroundImages, getDocuments, getIntroMessage, getLLMs, getMcpServers, getModelStyles, getPrompts, getSTTs, getSessionInfo, getSessionTemplate, getSessionTemplates, getTTSs, getTextNormalization, getTextNormalizations, makeTTS };
|
|
629
|
-
export type { STTResponse, SessionTemplate };
|
|
732
|
+
export { ApiError, DEFAULT_API_SERVER, DoesNotExistError, NotInOrganizationError, PersoUtil as PersoUtilServer, SessionCreationError, createSessionId, getAllSettings, getBackgroundImages, getDocuments, getIntroMessage, getLLMs, getMcpServers, getModelStyles, getPrompts, getSTTs, getSessionInfo, getSessionTemplate, getSessionTemplates, getTTSs, getTextNormalization, getTextNormalizations, makeTTS };
|
|
733
|
+
export type { ApiKeyOptions, GetSessionInfoOptions, GetSessionTemplateOptions, GetTextNormalizationOptions, MakeTTSOptions, STTResponse, SessionTemplate };
|
package/dist/server/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class t extends Error{errorCode;code;detail;attr;constructor(t,e,s,a){let n;n=null!=a?`${t}:${a}_${s}`:`${t}:${s}`,super(n),this.errorCode=t,this.code=e,this.detail=s,this.attr=a}}class e extends t{constructor(t){super(t.errorCode,t.code,t.detail,t.attr),this.name="SessionCreationError"}}class s extends e{constructor(t){super(t),this.name="DoesNotExistError"}}class a extends e{constructor(t){super(t),this.name="NotInOrganizationError"}}var n,i;!function(t){t.LLM="LLM",t.TTS="TTS",t.STT="STT",t.STF_ONPREMISE="STF_ONPREMISE",t.STF_WEBRTC="STF_WEBRTC"}(n||(n={})),function(t){t.SESSION_START="SESSION_START",t.SESSION_DURING="SESSION_DURING",t.SESSION_LOG="SESSION_LOG",t.SESSION_END="SESSION_END",t.SESSION_ERROR="SESSION_ERROR",t.SESSION_TTS="SESSION_TTS",t.SESSION_STT="SESSION_STT",t.SESSION_LLM="SESSION_LLM"}(i||(i={}));class o{static async getLLMs(t,e){const s=fetch(`${t}/api/v1/settings/llm_type/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),a=await s;return await this.parseJson(a)}static async getModelStyles(t,e){const s=fetch(`${t}/api/v1/settings/modelstyle/?platform_type=webrtc`,{headers:{"PersoLive-APIKey":e},method:"GET"}),a=await s;return await this.parseJson(a)}static async getBackgroundImages(t,e){const s=fetch(`${t}/api/v1/background_image/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),a=await s;return await this.parseJson(a)}static async getTTSs(t,e){const s=fetch(`${t}/api/v1/settings/tts_type/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),a=await s;return await this.parseJson(a)}static async getSTTs(t,e){const s=fetch(`${t}/api/v1/settings/stt_type/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),a=await s;return await this.parseJson(a)}static async makeTTS(t,{sessionId:e,text:s,locale:a,output_format:n}){const i={text:s};a&&(i.locale=a),n&&(i.output_format=n);const o=await fetch(`${t}/api/v1/session/${e}/tts/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});return await this.parseJson(o)}static async getPrompts(t,e){const s=fetch(`${t}/api/v1/prompt/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),a=await s;return await this.parseJson(a)}static async getDocuments(t,e){const s=fetch(`${t}/api/v1/document/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),a=await s;return await this.parseJson(a)}static async getTextNormalizations(t,e){const s=fetch(`${t}/api/v1/settings/text_normalization_config/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),a=await s;return await this.parseJson(a)}static async downloadTextNormalization(t,e,s){const a=await fetch(`${t}/api/v1/settings/text_normalization_config/${s}/download/`,{headers:{"PersoLive-APIKey":e},method:"GET"});return await this.parseJson(a)}static async getSessionTemplates(t,e){const s=await fetch(`${t}/api/v1/session_template/`,{headers:{"PersoLive-APIKey":e},method:"GET"});return await this.parseJson(s)}static async getSessionTemplate(t,e,s){const a=await fetch(`${t}/api/v1/session_template/${s}/`,{headers:{"PersoLive-APIKey":e},method:"GET"});return await this.parseJson(a)}static async getMcpServers(t,e){const s=fetch(`${t}/api/v1/settings/mcp_type/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),a=await s;return await this.parseJson(a)}static async getSessionInfo(t,e){const s=fetch(`${t}/api/v1/session/${e}/`,{method:"GET"}),a=await s;return await this.parseJson(a)}static async sessionEvent(t,e,s,a=""){const n=await fetch(`${t}/api/v1/session/${e}/event/create/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({detail:a,event:s})});await this.parseJson(n)}static async makeSTT(t,e,s,a){const n=new FormData;n.append("audio",s),a&&n.append("language",a);const i=await fetch(`${t}/api/v1/session/${e}/stt/`,{method:"POST",body:n});return await this.parseJson(i)}static async makeLLM(e,s,a,n){const i=await fetch(`${e}/api/v1/session/${s}/llm/v2/`,{body:JSON.stringify(a),headers:{"Content-Type":"application/json"},method:"POST",signal:n});if(!i.ok){const e=await i.json(),s=e.errors?.[0]??{code:"UNKNOWN_ERROR",detail:`Server returned status ${i.status} with no error details`,attr:null};throw new t(i.status,s.code,s.detail,s.attr)}return i.body.getReader()}static async getIceServers(t,e){const s=await fetch(`${t}/api/v1/session/${e}/ice-servers/`,{method:"GET"});return(await this.parseJson(s)).ice_servers}static async exchangeSDP(t,e,s){const a=await fetch(`${t}/api/v1/session/${e}/exchange/`,{body:JSON.stringify({client_sdp:s}),headers:{"Content-Type":"application/json"},method:"POST"});return(await this.parseJson(a)).server_sdp}static async parseJson(e){const s=await e.json();if(e.ok)return s;{const a=s.errors?.[0]??{code:"UNKNOWN_ERROR",detail:`Server returned status ${e.status} with no error details`,attr:null};throw new t(e.status,a.code,a.detail,a.attr)}}}async function r(i,r,c){try{let t;if("string"==typeof c){const e=await o.getSessionTemplate(i,r,c);if("webrtc"!==e.model_style.platform_type)throw new Error(`SessionTemplate "${c}" uses platform_type "${e.model_style.platform_type}", but only "webrtc" is supported`);t=function(t){const e=e=>t.capability.some(t=>t.name===e);return{using_stf_webrtc:e(n.STF_WEBRTC),model_style:t.model_style.name,prompt:t.prompt.prompt_id,document:t.document?.document_id,background_image:t.background_image?.backgroundimage_id,mcp_servers:t.mcp_servers?.length?t.mcp_servers?.map(t=>t.mcpserver_id):void 0,llm_type:e(n.LLM)?t.llm_type.name:void 0,tts_type:e(n.TTS)?t.tts_type.name:void 0,stt_type:e(n.STT)?t.stt_type.name:void 0,text_normalization_config:t.text_normalization_config?.textnormalizationconfig_id,text_normalization_locale:t.text_normalization_locale,stt_text_normalization_config:t.stt_text_normalization_config?.textnormalizationconfig_id,stt_text_normalization_locale:t.stt_text_normalization_locale,padding_left:t.padding_left??void 0,padding_top:t.padding_top??void 0,padding_height:t.padding_height??void 0}}(e)}else t=c;const e={capability:[],...t};t.using_stf_webrtc&&e.capability.push("STF_WEBRTC"),t?.llm_type&&(e.capability.push("LLM"),e.llm_type=t.llm_type),t?.tts_type&&(e.capability.push("TTS"),e.tts_type=t.tts_type),t?.stt_type&&(e.capability.push("STT"),e.stt_type=t.stt_type);const s=await fetch(`${i}/api/v1/session/`,{body:JSON.stringify(e),headers:{"PersoLive-APIKey":r,"Content-Type":"application/json"},method:"POST"});return(await o.parseJson(s)).session_id}catch(n){throw function(n){if(n instanceof e)return n;if(n instanceof t)switch(n.code){case"does_not_exist":return new s(n);case"not_in_organization":return new a(n);default:return new e(n)}return n}(n)}}const c=async(e,s,a)=>{try{const t=(await o.getPrompts(e,s)).find(t=>t.prompt_id===a);if(!t)throw new Error(`Prompt (${a}) not found`,{cause:404});return t.intro_message}catch(e){if(e instanceof t)throw new Error(e.detail,{cause:e.errorCode??500});throw e}};async function p(t,e){return await o.getLLMs(t,e)}async function d(t,e){return await o.getTTSs(t,e)}async function l(t,e){return await o.getSTTs(t,e)}async function u(t,e){return await o.getModelStyles(t,e)}async function m(t,e){return await o.getBackgroundImages(t,e)}async function _(t,e){return await o.getPrompts(t,e)}async function y(t,e){return await o.getDocuments(t,e)}async function S(t,e){return await o.getMcpServers(t,e)}async function h(t,e){return await o.getTextNormalizations(t,e)}async function T(t,e,s){return await o.downloadTextNormalization(t,e,s)}async function w(t,e){return await o.getSessionTemplates(t,e)}async function g(t,e,s){return await o.getSessionTemplate(t,e,s)}async function f(t,e){const[s,a,n,i,o,r,c,T,w]=await Promise.all([p(t,e),d(t,e),l(t,e),u(t,e),m(t,e),_(t,e),y(t,e),S(t,e),h(t,e).catch(()=>[])]);return{llms:s,ttsTypes:a,sttTypes:n,modelStyles:i,backgroundImages:o,prompts:r,documents:c,mcpServers:T,textNormalizations:w}}async function v(t,e){return await o.makeTTS(t,e)}async function E(t,e){return await o.getSessionInfo(t,e)}export{t as ApiError,s as DoesNotExistError,a as NotInOrganizationError,o as PersoUtilServer,e as SessionCreationError,r as createSessionId,f as getAllSettings,m as getBackgroundImages,y as getDocuments,c as getIntroMessage,p as getLLMs,S as getMcpServers,u as getModelStyles,_ as getPrompts,l as getSTTs,E as getSessionInfo,g as getSessionTemplate,w as getSessionTemplates,d as getTTSs,T as getTextNormalization,h as getTextNormalizations,v as makeTTS};
|
|
1
|
+
const t="https://platform.perso.ai";function e(e){const a=e?.trim();return(a||t).replace(/\/+$/,"")}class a extends Error{errorCode;code;detail;attr;constructor(t,e,a,s){let i;i=null!=s?`${t}:${s}_${a}`:`${t}:${a}`,super(i),this.errorCode=t,this.code=e,this.detail=a,this.attr=s}}class s extends a{constructor(t){super(t.errorCode,t.code,t.detail,t.attr),this.name="SessionCreationError"}}class i extends s{constructor(t){super(t),this.name="DoesNotExistError"}}class n extends s{constructor(t){super(t),this.name="NotInOrganizationError"}}var r,o;!function(t){t.LLM="LLM",t.TTS="TTS",t.STT="STT",t.STF_ONPREMISE="STF_ONPREMISE",t.STF_WEBRTC="STF_WEBRTC"}(r||(r={})),function(t){t.SESSION_START="SESSION_START",t.SESSION_DURING="SESSION_DURING",t.SESSION_LOG="SESSION_LOG",t.SESSION_END="SESSION_END",t.SESSION_ERROR="SESSION_ERROR",t.SESSION_TTS="SESSION_TTS",t.SESSION_STT="SESSION_STT",t.SESSION_LLM="SESSION_LLM"}(o||(o={}));class c{static async getLLMs(t,e){const a=fetch(`${t}/api/v1/settings/llm_type/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),s=await a;return await this.parseJson(s)}static async getModelStyles(t,e){const a=fetch(`${t}/api/v1/settings/modelstyle/?platform_type=webrtc`,{headers:{"PersoLive-APIKey":e},method:"GET"}),s=await a;return await this.parseJson(s)}static async getBackgroundImages(t,e){const a=fetch(`${t}/api/v1/background_image/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),s=await a;return await this.parseJson(s)}static async getTTSs(t,e){const a=fetch(`${t}/api/v1/settings/tts_type/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),s=await a;return await this.parseJson(s)}static async getSTTs(t,e){const a=fetch(`${t}/api/v1/settings/stt_type/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),s=await a;return await this.parseJson(s)}static async makeTTS(t,{sessionId:e,text:a,locale:s,output_format:i}){const n={text:a};s&&(n.locale=s),i&&(n.output_format=i);const r=await fetch(`${t}/api/v1/session/${e}/tts/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});return await this.parseJson(r)}static async getPrompts(t,e){const a=fetch(`${t}/api/v1/prompt/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),s=await a;return await this.parseJson(s)}static async getDocuments(t,e){const a=fetch(`${t}/api/v1/document/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),s=await a;return await this.parseJson(s)}static async getTextNormalizations(t,e){const a=fetch(`${t}/api/v1/settings/text_normalization_config/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),s=await a;return await this.parseJson(s)}static async downloadTextNormalization(t,e,a){const s=await fetch(`${t}/api/v1/settings/text_normalization_config/${a}/download/`,{headers:{"PersoLive-APIKey":e},method:"GET"});return await this.parseJson(s)}static async getSessionTemplates(t,e){const a=await fetch(`${t}/api/v1/session_template/`,{headers:{"PersoLive-APIKey":e},method:"GET"});return await this.parseJson(a)}static async getSessionTemplate(t,e,a){const s=await fetch(`${t}/api/v1/session_template/${a}/`,{headers:{"PersoLive-APIKey":e},method:"GET"});return await this.parseJson(s)}static async getMcpServers(t,e){const a=fetch(`${t}/api/v1/settings/mcp_type/`,{headers:{"PersoLive-APIKey":e},method:"GET"}),s=await a;return await this.parseJson(s)}static async getSessionInfo(t,e){const a=fetch(`${t}/api/v1/session/${e}/`,{method:"GET"}),s=await a;return await this.parseJson(s)}static async sessionEvent(t,e,a,s=""){const i=await fetch(`${t}/api/v1/session/${e}/event/create/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({detail:s,event:a})});await this.parseJson(i)}static async makeSTT(t,e,a,s){const i=new FormData;i.append("audio",a),s&&i.append("language",s);const n=await fetch(`${t}/api/v1/session/${e}/stt/`,{method:"POST",body:i});return{text:(await this.parseJson(n)).text}}static async makeLLM(t,e,s,i){const n=await fetch(`${t}/api/v1/session/${e}/llm/v2/`,{body:JSON.stringify(s),headers:{"Content-Type":"application/json"},method:"POST",signal:i});if(!n.ok){const t=await n.json(),e=t.errors?.[0]??{code:"UNKNOWN_ERROR",detail:`Server returned status ${n.status} with no error details`,attr:null};throw new a(n.status,e.code,e.detail,e.attr)}return n.body.getReader()}static async getIceServers(t,e){const a=await fetch(`${t}/api/v1/session/${e}/ice-servers/`,{method:"GET"});return(await this.parseJson(a)).ice_servers}static async exchangeSDP(t,e,a){const s=await fetch(`${t}/api/v1/session/${e}/exchange/`,{body:JSON.stringify({client_sdp:a}),headers:{"Content-Type":"application/json"},method:"POST"});return(await this.parseJson(s)).server_sdp}static async parseJson(t){const e=await t.json();if(t.ok)return e;{const s=e.errors?.[0]??{code:"UNKNOWN_ERROR",detail:`Server returned status ${t.status} with no error details`,attr:null};throw new a(t.status,s.code,s.detail,s.attr)}}}async function p(t,o,p){let d,y,S;if("object"==typeof t){const a=t;d=e(a.apiServer),y=a.apiKey,S="sessionTemplateId"in a?a.sessionTemplateId:a.params}else d=e(t),y=o,S=p;return await async function(t,e,o){try{let a;if("string"==typeof o){const s=await c.getSessionTemplate(t,e,o);if("webrtc"!==s.model_style.platform_type)throw new Error(`SessionTemplate "${o}" uses platform_type "${s.model_style.platform_type}", but only "webrtc" is supported`);a=function(t){const e=e=>t.capability.some(t=>t.name===e);return{using_stf_webrtc:e(r.STF_WEBRTC),model_style:t.model_style.name,prompt:t.prompt.prompt_id,document:t.document?.document_id,background_image:t.background_image?.backgroundimage_id,mcp_servers:t.mcp_servers?.length?t.mcp_servers?.map(t=>t.mcpserver_id):void 0,llm_type:e(r.LLM)?t.llm_type.name:void 0,tts_type:e(r.TTS)?t.tts_type.name:void 0,stt_type:e(r.STT)?t.stt_type.name:void 0,text_normalization_config:t.text_normalization_config?.textnormalizationconfig_id,text_normalization_locale:t.text_normalization_locale,stt_text_normalization_config:t.stt_text_normalization_config?.textnormalizationconfig_id,stt_text_normalization_locale:t.stt_text_normalization_locale,padding_left:t.padding_left??void 0,padding_top:t.padding_top??void 0,padding_height:t.padding_height??void 0}}(s)}else a=o;const s={capability:[],...a};a.using_stf_webrtc&&s.capability.push("STF_WEBRTC"),a?.llm_type&&(s.capability.push("LLM"),s.llm_type=a.llm_type),a?.tts_type&&(s.capability.push("TTS"),s.tts_type=a.tts_type),a?.stt_type&&(s.capability.push("STT"),s.stt_type=a.stt_type);const i=await fetch(`${t}/api/v1/session/`,{body:JSON.stringify(s),headers:{"PersoLive-APIKey":e,"Content-Type":"application/json"},method:"POST"});return(await c.parseJson(i)).session_id}catch(t){throw function(t){if(t instanceof s)return t;if(t instanceof a)switch(t.code){case"does_not_exist":return new i(t);case"not_in_organization":return new n(t);default:return new s(t)}return t}(t)}}(d,y,S)}async function d(t,s,i){let n,r,o;"object"==typeof t?(n=e(t.apiServer),r=t.apiKey,o=t.promptId):(n=e(t),r=s,o=i);try{const t=(await c.getPrompts(n,r)).find(t=>t.prompt_id===o);if(!t)throw new Error(`Prompt (${o}) not found`,{cause:404});return t.intro_message}catch(t){if(t instanceof a)throw new Error(t.detail,{cause:t.errorCode??500});throw t}}function y(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)&&"apiKey"in t}async function S(t,a){return y(t)?await c.getLLMs(e(t.apiServer),t.apiKey):await c.getLLMs(e(t),a)}async function l(t,a){return y(t)?await c.getTTSs(e(t.apiServer),t.apiKey):await c.getTTSs(e(t),a)}async function m(t,a){return y(t)?await c.getSTTs(e(t.apiServer),t.apiKey):await c.getSTTs(e(t),a)}async function u(t,a){return y(t)?await c.getModelStyles(e(t.apiServer),t.apiKey):await c.getModelStyles(e(t),a)}async function _(t,a){return y(t)?await c.getBackgroundImages(e(t.apiServer),t.apiKey):await c.getBackgroundImages(e(t),a)}async function g(t,a){return y(t)?await c.getPrompts(e(t.apiServer),t.apiKey):await c.getPrompts(e(t),a)}async function h(t,a){return y(t)?await c.getDocuments(e(t.apiServer),t.apiKey):await c.getDocuments(e(t),a)}async function T(t,a){return y(t)?await c.getMcpServers(e(t.apiServer),t.apiKey):await c.getMcpServers(e(t),a)}async function w(t,a){return y(t)?await c.getTextNormalizations(e(t.apiServer),t.apiKey):await c.getTextNormalizations(e(t),a)}async function f(t,a,s){return"object"==typeof t?await c.downloadTextNormalization(e(t.apiServer),t.apiKey,t.configId):await c.downloadTextNormalization(e(t),a,s)}async function v(t,a){return y(t)?await c.getSessionTemplates(e(t.apiServer),t.apiKey):await c.getSessionTemplates(e(t),a)}async function E(t,a,s){return"object"==typeof t?await c.getSessionTemplate(e(t.apiServer),t.apiKey,t.sessionTemplateId):await c.getSessionTemplate(e(t),a,s)}async function I(t,a){const s=y(t)?{apiServer:e(t.apiServer),apiKey:t.apiKey}:{apiServer:e(t),apiKey:a},[i,n,r,o,p,d,S,l,m]=await Promise.all([c.getLLMs(s.apiServer,s.apiKey),c.getTTSs(s.apiServer,s.apiKey),c.getSTTs(s.apiServer,s.apiKey),c.getModelStyles(s.apiServer,s.apiKey),c.getBackgroundImages(s.apiServer,s.apiKey),c.getPrompts(s.apiServer,s.apiKey),c.getDocuments(s.apiServer,s.apiKey),c.getMcpServers(s.apiServer,s.apiKey),c.getTextNormalizations(s.apiServer,s.apiKey).catch(()=>[])]);return{llms:i,ttsTypes:n,sttTypes:r,modelStyles:o,backgroundImages:p,prompts:d,documents:S,mcpServers:l,textNormalizations:m}}async function N(t,a){if("object"==typeof t){const{apiServer:a,...s}=t;return await c.makeTTS(e(a),s)}return await c.makeTTS(e(t),a)}async function P(t,a){return"object"==typeof t?await c.getSessionInfo(e(t.apiServer),t.sessionId):await c.getSessionInfo(e(t),a)}export{a as ApiError,t as DEFAULT_API_SERVER,i as DoesNotExistError,n as NotInOrganizationError,c as PersoUtilServer,s as SessionCreationError,p as createSessionId,I as getAllSettings,_ as getBackgroundImages,h as getDocuments,d as getIntroMessage,S as getLLMs,T as getMcpServers,u as getModelStyles,g as getPrompts,m as getSTTs,P as getSessionInfo,E as getSessionTemplate,v as getSessionTemplates,l as getTTSs,f as getTextNormalization,w as getTextNormalizations,N as makeTTS};
|