perso-interactive-sdk-web 1.5.1 → 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.
@@ -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
- * Requests a new session creation ID by POSTing the desired runtime options to
21
- * the Perso backend (`/api/v1/session/`).
22
- *
23
- * @overload Creates a session from a SessionTemplate ID. Internally calls
24
- * `getSessionTemplate` to resolve the template and maps it to the request body.
25
- * @param apiServer Perso API server URL.
26
- * @param apiKey API key used for authentication.
27
- * @param sessionTemplateId SessionTemplate ID to resolve configuration from.
28
- * @returns Session ID returned by the server.
29
- * @throws {Error} If the template's `model_style.platform_type` is not `"webrtc"`.
30
- * @throws {SessionCreationError} When the API returns an error during session creation.
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
- * Retrieves the intro message for a specific prompt.
45
- * @param apiServer Perso API server URL.
46
- * @param apiKey API key used for authentication.
47
- * @param promptId The prompt ID to fetch intro message for.
48
- * @returns The intro message string.
49
- */
50
- declare const getIntroMessage: (apiServer: string, apiKey: string, promptId: string) => Promise<string>;
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;
@@ -460,120 +452,239 @@ declare class PersoUtil {
460
452
  static parseJson(response: Response): Promise<any>;
461
453
  }
462
454
 
455
+ type ApiKeyOptions = {
456
+ apiKey: string;
457
+ apiServer?: string;
458
+ };
463
459
  /**
464
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
+ /**
465
467
  * @param apiServer Perso API server URL.
466
468
  * @param apiKey API key used for authentication.
467
- * @returns Promise resolving with LLM metadata.
468
469
  */
469
- declare function getLLMs(apiServer: string, apiKey: string): Promise<any>;
470
+ declare function getLLMs(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getLLMs>;
470
471
  /**
471
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
+ /**
472
479
  * @param apiServer Perso API server URL.
473
480
  * @param apiKey API key used for authentication.
474
481
  */
475
- declare function getTTSs(apiServer: string, apiKey: string): Promise<any>;
482
+ declare function getTTSs(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getTTSs>;
476
483
  /**
477
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
+ /**
478
491
  * @param apiServer Perso API server URL.
479
492
  * @param apiKey API key used for authentication.
480
493
  */
481
- declare function getSTTs(apiServer: string, apiKey: string): Promise<any>;
494
+ declare function getSTTs(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getSTTs>;
482
495
  /**
483
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
+ /**
484
503
  * @param apiServer Perso API server URL.
485
504
  * @param apiKey API key used for authentication.
486
505
  */
487
- declare function getModelStyles(apiServer: string, apiKey: string): Promise<any>;
506
+ declare function getModelStyles(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getModelStyles>;
488
507
  /**
489
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
+ /**
490
515
  * @param apiServer Perso API server URL.
491
516
  * @param apiKey API key used for authentication.
492
517
  */
493
- declare function getBackgroundImages(apiServer: string, apiKey: string): Promise<any>;
518
+ declare function getBackgroundImages(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getBackgroundImages>;
494
519
  /**
495
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
+ /**
496
527
  * @param apiServer Perso API server URL.
497
528
  * @param apiKey API key used for authentication.
498
529
  */
499
- declare function getPrompts(apiServer: string, apiKey: string): Promise<any>;
530
+ declare function getPrompts(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getPrompts>;
500
531
  /**
501
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
+ /**
502
539
  * @param apiServer Perso API server URL.
503
540
  * @param apiKey API key used for authentication.
504
541
  */
505
- declare function getDocuments(apiServer: string, apiKey: string): Promise<any>;
542
+ declare function getDocuments(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getDocuments>;
506
543
  /**
507
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
+ /**
508
551
  * @param apiServer Perso API server URL.
509
552
  * @param apiKey API key used for authentication.
510
553
  */
511
- declare function getMcpServers(apiServer: string, apiKey: string): Promise<any>;
554
+ declare function getMcpServers(apiServer: string, apiKey: string): ReturnType<typeof PersoUtil.getMcpServers>;
512
555
  /**
513
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
+ /**
514
563
  * @param apiServer Perso API server URL.
515
564
  * @param apiKey API key used for authentication.
516
565
  */
517
- declare function getTextNormalizations(apiServer: string, apiKey: string): Promise<any>;
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
+ };
518
572
  /**
519
573
  * Downloads the ruleset data file for a Text Normalization Config.
520
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
+ /**
521
582
  * @param apiServer Perso API server URL.
522
583
  * @param apiKey API key used for authentication.
523
- * @param configId Text Normalization Config ID.
584
+ * @param configId Identifier of the Text Normalization Config to download.
524
585
  */
525
586
  declare function getTextNormalization(apiServer: string, apiKey: string, configId: string): Promise<TextNormalizationDownload>;
526
587
  /**
527
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
+ /**
528
595
  * @param apiServer Perso API server URL.
529
596
  * @param apiKey API key used for authentication.
530
597
  */
531
598
  declare function getSessionTemplates(apiServer: string, apiKey: string): Promise<SessionTemplate[]>;
599
+ type GetSessionTemplateOptions = {
600
+ apiKey: string;
601
+ sessionTemplateId: string;
602
+ apiServer?: string;
603
+ };
532
604
  /**
533
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
+ /**
534
613
  * @param apiServer Perso API server URL.
535
614
  * @param apiKey API key used for authentication.
536
- * @param sessionTemplateId Session Template ID.
615
+ * @param sessionTemplateId Identifier of the session template to fetch.
537
616
  */
538
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
+ };
539
629
  /**
540
630
  * Convenience helper that fetches every dropdown-friendly resource needed to
541
631
  * build a Perso session configuration screen in one call chain.
542
- * @param apiServer Perso API server URL.
543
- * @param apiKey API key used for authentication.
544
- * @returns Object containing arrays for LLMs, TTS/STT types, model styles, etc.
545
- */
546
- declare function getAllSettings(apiServer: string, apiKey: string): Promise<{
547
- llms: any;
548
- ttsTypes: any;
549
- sttTypes: any;
550
- modelStyles: any;
551
- backgroundImages: any;
552
- prompts: any;
553
- documents: any;
554
- mcpServers: any;
555
- textNormalizations: any;
556
- }>;
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>;
557
637
  /**
558
- * Sends text to the TTS API and returns Base64-encoded audio.
559
638
  * @param apiServer Perso API server URL.
560
- * @param params Session ID and text to synthesize.
561
- * @returns Object with Base64 audio string.
639
+ * @param apiKey API key used for authentication.
562
640
  */
563
- declare function makeTTS(apiServer: string, params: {
641
+ declare function getAllSettings(apiServer: string, apiKey: string): Promise<AllSettings>;
642
+ type MakeTTSParams = {
564
643
  sessionId: string;
565
644
  text: string;
566
645
  locale?: string;
567
646
  output_format?: string;
568
- }): Promise<{
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<{
569
661
  audio: string;
570
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<{
668
+ audio: string;
669
+ }>;
670
+ type GetSessionInfoOptions = {
671
+ sessionId: string;
672
+ apiServer?: string;
673
+ };
571
674
  /**
572
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
+ /**
573
682
  * @param apiServer Perso API server URL.
574
- * @param sessionId Session id to inspect.
683
+ * @param sessionId Identifier of the session to look up.
575
684
  */
576
- declare function getSessionInfo(apiServer: string, sessionId: string): Promise<any>;
685
+ declare function getSessionInfo(apiServer: string, sessionId: string): ReturnType<typeof PersoUtil.getSessionInfo>;
686
+
687
+ declare const DEFAULT_API_SERVER = "https://platform.perso.ai";
577
688
 
578
689
  declare class ApiError extends Error {
579
690
  errorCode: number;
@@ -618,5 +729,5 @@ declare class NotInOrganizationError extends SessionCreationError {
618
729
  constructor(source: ApiError);
619
730
  }
620
731
 
621
- 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 };
622
- 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 };
@@ -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{text:(await this.parseJson(i)).text}}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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perso-interactive-sdk-web",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "Perso Interactive Web SDK - WebRTC-based real-time interactive AI avatar sessions",
5
5
  "type": "module",
6
6
  "private": false,