perso-interactive-sdk-web 1.3.4 → 1.4.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.
@@ -1,3 +1,168 @@
1
+ type CreateSessionIdBody = {
2
+ using_stf_webrtc: boolean;
3
+ model_style: string;
4
+ prompt: string;
5
+ document?: string;
6
+ background_image?: string;
7
+ mcp_servers?: Array<string>;
8
+ padding_left?: number;
9
+ padding_top?: number;
10
+ padding_height?: number;
11
+ llm_type?: string;
12
+ tts_type?: string;
13
+ stt_type?: string;
14
+ text_normalization_config?: string;
15
+ text_normalization_locale?: string | null;
16
+ stt_text_normalization_config?: string;
17
+ stt_text_normalization_locale?: string | null;
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 {ApiError} If the template ID is invalid or API call fails.
31
+ */
32
+ declare function createSessionId(apiServer: string, apiKey: string, sessionTemplateId: string): Promise<string>;
33
+ /**
34
+ * @overload Creates a session from explicit runtime options.
35
+ * @param apiServer Perso API server URL.
36
+ * @param apiKey API key used for authentication.
37
+ * @param params Runtime options for the session.
38
+ * @returns Session ID returned by the server.
39
+ */
40
+ declare function createSessionId(apiServer: string, apiKey: string, params: CreateSessionIdBody): Promise<string>;
41
+ /**
42
+ * Retrieves the intro message for a specific prompt.
43
+ * @param apiServer Perso API server URL.
44
+ * @param apiKey API key used for authentication.
45
+ * @param promptId The prompt ID to fetch intro message for.
46
+ * @returns The intro message string.
47
+ */
48
+ declare const getIntroMessage: (apiServer: string, apiKey: string, promptId: string) => Promise<string>;
49
+
50
+ declare class ApiError extends Error {
51
+ errorCode: number;
52
+ code: string;
53
+ detail: string;
54
+ attr?: string | undefined;
55
+ constructor(errorCode: number, code: string, detail: string, attr?: string | undefined);
56
+ }
57
+
58
+ interface Prompt {
59
+ prompt_id: string;
60
+ name: string;
61
+ description?: string;
62
+ system_prompt: string;
63
+ require_document?: boolean;
64
+ intro_message?: string;
65
+ }
66
+ interface SessionCapability {
67
+ name: SessionCapabilityName;
68
+ description?: string | null;
69
+ }
70
+ interface Document {
71
+ document_id: string;
72
+ title: string;
73
+ file: string;
74
+ description?: string;
75
+ search_count?: number;
76
+ ef_search?: number | null;
77
+ processed: boolean;
78
+ processed_v2: boolean;
79
+ created_at: string;
80
+ updated_at: string;
81
+ }
82
+ interface LLMType {
83
+ name: string;
84
+ service?: string;
85
+ }
86
+ interface TTSType {
87
+ name: string;
88
+ streamable?: boolean;
89
+ service: string;
90
+ model?: string | null;
91
+ voice?: string | null;
92
+ voice_settings?: unknown | null;
93
+ style?: string | null;
94
+ voice_extra_data?: unknown | null;
95
+ }
96
+ interface STTType {
97
+ name: string;
98
+ service: string;
99
+ options?: unknown | null;
100
+ }
101
+ interface TextNormalizationConfig {
102
+ textnormalizationconfig_id: string;
103
+ name: string;
104
+ created_at: string;
105
+ }
106
+ interface ModelStyleConfig {
107
+ modelstyleconfig_id: string;
108
+ key: string;
109
+ value: string;
110
+ }
111
+ interface AIHumanModelFile {
112
+ name: string;
113
+ file?: string | null;
114
+ }
115
+ interface ModelStyle {
116
+ name: string;
117
+ model: string;
118
+ model_file?: string | null;
119
+ model_files: AIHumanModelFile[];
120
+ style: string;
121
+ file?: string | null;
122
+ platform_type?: string;
123
+ configs: ModelStyleConfig[];
124
+ }
125
+ interface BackgroundImage {
126
+ backgroundimage_id: string;
127
+ title: string;
128
+ image: string;
129
+ created_at: string;
130
+ }
131
+ interface MCPServer {
132
+ mcpserver_id: string;
133
+ name: string;
134
+ description?: string;
135
+ url: string;
136
+ transport_protocol?: string;
137
+ server_timeout_sec?: number;
138
+ extra_data?: unknown | null;
139
+ }
140
+ interface SessionTemplate {
141
+ sessiontemplate_id: string;
142
+ name: string;
143
+ description: string | null;
144
+ prompt: Prompt;
145
+ capability: SessionCapability[];
146
+ document: Document | null;
147
+ llm_type: LLMType;
148
+ tts_type: TTSType;
149
+ stt_type: STTType;
150
+ text_normalization_config?: TextNormalizationConfig | null;
151
+ text_normalization_locale?: string | null;
152
+ stt_text_normalization_config?: TextNormalizationConfig | null;
153
+ stt_text_normalization_locale?: string | null;
154
+ model_style: ModelStyle;
155
+ background_image: BackgroundImage | null;
156
+ agent: string | null;
157
+ padding_left: number | null;
158
+ padding_top: number | null;
159
+ padding_height: number | null;
160
+ extra_data: unknown | null;
161
+ mcp_servers?: MCPServer[];
162
+ created_at: string;
163
+ last_used_at: string | null;
164
+ }
165
+
1
166
  declare enum SessionCapabilityName {
2
167
  LLM = "LLM",
3
168
  TTS = "TTS",
@@ -294,162 +459,73 @@ declare class PersoUtil {
294
459
  static parseJson(response: Response): Promise<any>;
295
460
  }
296
461
 
297
- interface Prompt {
298
- prompt_id: string;
299
- name: string;
300
- description?: string;
301
- system_prompt: string;
302
- require_document?: boolean;
303
- intro_message?: string;
304
- }
305
- interface SessionCapability {
306
- name: SessionCapabilityName;
307
- description?: string | null;
308
- }
309
- interface Document {
310
- document_id: string;
311
- title: string;
312
- file: string;
313
- description?: string;
314
- search_count?: number;
315
- ef_search?: number | null;
316
- processed: boolean;
317
- processed_v2: boolean;
318
- created_at: string;
319
- updated_at: string;
320
- }
321
- interface LLMType {
322
- name: string;
323
- service?: string;
324
- }
325
- interface TTSType {
326
- name: string;
327
- streamable?: boolean;
328
- service: string;
329
- model?: string | null;
330
- voice?: string | null;
331
- voice_settings?: unknown | null;
332
- style?: string | null;
333
- voice_extra_data?: unknown | null;
334
- }
335
- interface STTType {
336
- name: string;
337
- service: string;
338
- options?: unknown | null;
339
- }
340
- interface TextNormalizationConfig {
341
- textnormalizationconfig_id: string;
342
- name: string;
343
- created_at: string;
344
- }
345
- interface ModelStyleConfig {
346
- modelstyleconfig_id: string;
347
- key: string;
348
- value: string;
349
- }
350
- interface AIHumanModelFile {
351
- name: string;
352
- file?: string | null;
353
- }
354
- interface ModelStyle {
355
- name: string;
356
- model: string;
357
- model_file?: string | null;
358
- model_files: AIHumanModelFile[];
359
- style: string;
360
- file?: string | null;
361
- platform_type?: string;
362
- configs: ModelStyleConfig[];
363
- }
364
- interface BackgroundImage {
365
- backgroundimage_id: string;
366
- title: string;
367
- image: string;
368
- created_at: string;
369
- }
370
- interface MCPServer {
371
- mcpserver_id: string;
372
- name: string;
373
- description?: string;
374
- url: string;
375
- transport_protocol?: string;
376
- server_timeout_sec?: number;
377
- extra_data?: unknown | null;
378
- }
379
- interface SessionTemplate {
380
- sessiontemplate_id: string;
381
- name: string;
382
- description: string | null;
383
- prompt: Prompt;
384
- capability: SessionCapability[];
385
- document: Document | null;
386
- llm_type: LLMType;
387
- tts_type: TTSType;
388
- stt_type: STTType;
389
- text_normalization_config?: TextNormalizationConfig | null;
390
- text_normalization_locale?: string | null;
391
- model_style: ModelStyle;
392
- background_image: BackgroundImage | null;
393
- agent: string | null;
394
- padding_left: number | null;
395
- padding_top: number | null;
396
- padding_height: number | null;
397
- extra_data: unknown | null;
398
- mcp_servers?: MCPServer[];
399
- created_at: string;
400
- last_used_at: string | null;
401
- }
402
-
403
- type CreateSessionIdBody = {
404
- using_stf_webrtc: boolean;
405
- model_style: string;
406
- prompt: string;
407
- document?: string;
408
- background_image?: string;
409
- mcp_servers?: Array<string>;
410
- padding_left?: number;
411
- padding_top?: number;
412
- padding_height?: number;
413
- llm_type?: string;
414
- tts_type?: string;
415
- stt_type?: string;
416
- text_normalization_config?: string;
417
- text_normalization_locale?: string | null;
418
- };
419
462
  /**
420
- * Requests a new session creation ID by POSTing the desired runtime options to
421
- * the Perso backend (`/api/v1/session/`).
422
- *
423
- * @overload Creates a session from a SessionTemplate ID. Internally calls
424
- * `getSessionTemplate` to resolve the template and maps it to the request body.
463
+ * Retrieves the list of available LLM providers from the API.
425
464
  * @param apiServer Perso API server URL.
426
465
  * @param apiKey API key used for authentication.
427
- * @param sessionTemplateId SessionTemplate ID to resolve configuration from.
428
- * @returns Session ID returned by the server.
429
- * @throws {Error} If the template's `model_style.platform_type` is not `"webrtc"`.
430
- * @throws {ApiError} If the template ID is invalid or API call fails.
466
+ * @returns Promise resolving with LLM metadata.
431
467
  */
432
- declare function createSessionId(apiServer: string, apiKey: string, sessionTemplateId: string): Promise<string>;
468
+ declare function getLLMs(apiServer: string, apiKey: string): Promise<any>;
433
469
  /**
434
- * @overload Creates a session from explicit runtime options.
470
+ * Retrieves available TTS providers.
435
471
  * @param apiServer Perso API server URL.
436
472
  * @param apiKey API key used for authentication.
437
- * @param params Runtime options for the session.
438
- * @returns Session ID returned by the server.
439
473
  */
440
- declare function createSessionId(apiServer: string, apiKey: string, params: CreateSessionIdBody): Promise<string>;
474
+ declare function getTTSs(apiServer: string, apiKey: string): Promise<any>;
441
475
  /**
442
- * Retrieves the intro message for a specific prompt.
476
+ * Retrieves available STT providers.
443
477
  * @param apiServer Perso API server URL.
444
478
  * @param apiKey API key used for authentication.
445
- * @param promptId The prompt ID to fetch intro message for.
446
- * @returns The intro message string.
447
479
  */
480
+ declare function getSTTs(apiServer: string, apiKey: string): Promise<any>;
481
+ /**
482
+ * Fetches avatar model styles.
483
+ * @param apiServer Perso API server URL.
484
+ * @param apiKey API key used for authentication.
485
+ */
486
+ declare function getModelStyles(apiServer: string, apiKey: string): Promise<any>;
487
+ /**
488
+ * Fetches preset background images.
489
+ * @param apiServer Perso API server URL.
490
+ * @param apiKey API key used for authentication.
491
+ */
492
+ declare function getBackgroundImages(apiServer: string, apiKey: string): Promise<any>;
493
+ /**
494
+ * Returns predefined prompt templates.
495
+ * @param apiServer Perso API server URL.
496
+ * @param apiKey API key used for authentication.
497
+ */
498
+ declare function getPrompts(apiServer: string, apiKey: string): Promise<any>;
499
+ /**
500
+ * Returns supporting document metadata usable by the session.
501
+ * @param apiServer Perso API server URL.
502
+ * @param apiKey API key used for authentication.
503
+ */
504
+ declare function getDocuments(apiServer: string, apiKey: string): Promise<any>;
505
+ /**
506
+ * Lists MCP server identifiers configured for the tenant.
507
+ * @param apiServer Perso API server URL.
508
+ * @param apiKey API key used for authentication.
509
+ */
510
+ declare function getMcpServers(apiServer: string, apiKey: string): Promise<any>;
511
+ /**
512
+ * Retrieves available text normalization options.
513
+ * @param apiServer Perso API server URL.
514
+ * @param apiKey API key used for authentication.
515
+ */
516
+ declare function getTextNormalizations(apiServer: string, apiKey: string): Promise<any>;
517
+ /**
518
+ * Downloads the ruleset data file for a Text Normalization Config.
519
+ * Returns a pre-signed Blob Storage URL for the CSV file.
520
+ * @param apiServer Perso API server URL.
521
+ * @param apiKey API key used for authentication.
522
+ * @param configId Text Normalization Config ID.
523
+ */
524
+ declare function getTextNormalization(apiServer: string, apiKey: string, configId: string): Promise<TextNormalizationDownload>;
448
525
  /**
449
526
  * Retrieves the list of session templates.
450
527
  * @param apiServer Perso API server URL.
451
528
  * @param apiKey API key used for authentication.
452
- * @returns {Promise<SessionTemplate[]>} Array of available session templates.
453
529
  */
454
530
  declare function getSessionTemplates(apiServer: string, apiKey: string): Promise<SessionTemplate[]>;
455
531
  /**
@@ -457,19 +533,46 @@ declare function getSessionTemplates(apiServer: string, apiKey: string): Promise
457
533
  * @param apiServer Perso API server URL.
458
534
  * @param apiKey API key used for authentication.
459
535
  * @param sessionTemplateId Session Template ID.
460
- * @returns {Promise<SessionTemplate>} The matching session template.
461
- * @throws {ApiError} If the template ID is invalid or API call fails.
462
536
  */
463
537
  declare function getSessionTemplate(apiServer: string, apiKey: string, sessionTemplateId: string): Promise<SessionTemplate>;
464
- declare const getIntroMessage: (apiServer: string, apiKey: string, promptId: string) => Promise<string>;
465
-
466
- declare class ApiError extends Error {
467
- errorCode: number;
468
- code: string;
469
- detail: string;
470
- attr?: string | undefined;
471
- constructor(errorCode: number, code: string, detail: string, attr?: string | undefined);
472
- }
538
+ /**
539
+ * Convenience helper that fetches every dropdown-friendly resource needed to
540
+ * build a Perso session configuration screen in one call chain.
541
+ * @param apiServer Perso API server URL.
542
+ * @param apiKey API key used for authentication.
543
+ * @returns Object containing arrays for LLMs, TTS/STT types, model styles, etc.
544
+ */
545
+ declare function getAllSettings(apiServer: string, apiKey: string): Promise<{
546
+ llms: any;
547
+ ttsTypes: any;
548
+ sttTypes: any;
549
+ modelStyles: any;
550
+ backgroundImages: any;
551
+ prompts: any;
552
+ documents: any;
553
+ mcpServers: any;
554
+ textNormalizations: any;
555
+ }>;
556
+ /**
557
+ * Sends text to the TTS API and returns Base64-encoded audio.
558
+ * @param apiServer Perso API server URL.
559
+ * @param params Session ID and text to synthesize.
560
+ * @returns Object with Base64 audio string.
561
+ */
562
+ declare function makeTTS(apiServer: string, params: {
563
+ sessionId: string;
564
+ text: string;
565
+ locale?: string;
566
+ output_format?: string;
567
+ }): Promise<{
568
+ audio: string;
569
+ }>;
570
+ /**
571
+ * Retrieves metadata for an existing session.
572
+ * @param apiServer Perso API server URL.
573
+ * @param sessionId Session id to inspect.
574
+ */
575
+ declare function getSessionInfo(apiServer: string, sessionId: string): Promise<any>;
473
576
 
474
- export { ApiError, PersoUtil as PersoUtilServer, createSessionId, getIntroMessage, getSessionTemplate, getSessionTemplates };
577
+ export { ApiError, PersoUtil as PersoUtilServer, createSessionId, getAllSettings, getBackgroundImages, getDocuments, getIntroMessage, getLLMs, getMcpServers, getModelStyles, getPrompts, getSTTs, getSessionInfo, getSessionTemplate, getSessionTemplates, getTTSs, getTextNormalization, getTextNormalizations, makeTTS };
475
578
  export type { SessionTemplate };
@@ -1 +1 @@
1
- class t extends Error{errorCode;code;detail;attr;constructor(t,e,s,a){let i;i=null!=a?`${t}:${a}_${s}`:`${t}:${s}`,super(i),this.errorCode=t,this.code=e,this.detail=s,this.attr=a}}var e,s;!function(t){t.LLM="LLM",t.TTS="TTS",t.STT="STT",t.STF_ONPREMISE="STF_ONPREMISE",t.STF_WEBRTC="STF_WEBRTC"}(e||(e={})),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"}(s||(s={}));class a{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:i}){const o={text:s};a&&(o.locale=a),i&&(o.output_format=i);const n=await fetch(`${t}/api/v1/session/${e}/tts/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});return await this.parseJson(n)}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 i=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(i)}static async makeSTT(t,e,s,a){const i=new FormData;i.append("audio",s),a&&i.append("language",a);const o=await fetch(`${t}/api/v1/session/${e}/stt/`,{method:"POST",body:i});return await this.parseJson(o)}static async makeLLM(e,s,a,i){const o=await fetch(`${e}/api/v1/session/${s}/llm/v2/`,{body:JSON.stringify(a),headers:{"Content-Type":"application/json"},method:"POST",signal:i});if(!o.ok){const e=await o.json(),s=e.errors?.[0]??{code:"UNKNOWN_ERROR",detail:`Server returned status ${o.status} with no error details`,attr:null};throw new t(o.status,s.code,s.detail,s.attr)}return o.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 i(t,s,i){let o;if("string"==typeof i){const n=await a.getSessionTemplate(t,s,i);if("webrtc"!==n.model_style.platform_type)throw new Error(`SessionTemplate "${i}" uses platform_type "${n.model_style.platform_type}", but only "webrtc" is supported`);o=function(t){const s=e=>t.capability.some(t=>t.name===e);return{using_stf_webrtc:s(e.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:s(e.LLM)?t.llm_type.name:void 0,tts_type:s(e.TTS)?t.tts_type.name:void 0,stt_type:s(e.STT)?t.stt_type.name:void 0,text_normalization_config:t.text_normalization_config?.textnormalizationconfig_id,text_normalization_locale:t.text_normalization_locale,padding_left:t.padding_left??void 0,padding_top:t.padding_top??void 0,padding_height:t.padding_height??void 0}}(n)}else o=i;const n={capability:[],...o};o.using_stf_webrtc&&n.capability.push("STF_WEBRTC"),o?.llm_type&&(n.capability.push("LLM"),n.llm_type=o.llm_type),o?.tts_type&&(n.capability.push("TTS"),n.tts_type=o.tts_type),o?.stt_type&&(n.capability.push("STT"),n.stt_type=o.stt_type);const r=await fetch(`${t}/api/v1/session/`,{body:JSON.stringify(n),headers:{"PersoLive-APIKey":s,"Content-Type":"application/json"},method:"POST"});return(await a.parseJson(r)).session_id}async function o(t,e){return await a.getSessionTemplates(t,e)}async function n(t,e,s){return await a.getSessionTemplate(t,e,s)}const r=async(e,s,i)=>{try{const t=(await a.getPrompts(e,s)).find(t=>t.prompt_id===i);if(!t)throw new Error(`Prompt (${i}) 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}};export{t as ApiError,a as PersoUtilServer,i as createSessionId,r as getIntroMessage,n as getSessionTemplate,o as getSessionTemplates};
1
+ class t extends Error{errorCode;code;detail;attr;constructor(t,e,a,s){let n;n=null!=s?`${t}:${s}_${a}`:`${t}:${a}`,super(n),this.errorCode=t,this.code=e,this.detail=a,this.attr=s}}var e,a;!function(t){t.LLM="LLM",t.TTS="TTS",t.STT="STT",t.STF_ONPREMISE="STF_ONPREMISE",t.STF_WEBRTC="STF_WEBRTC"}(e||(e={})),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"}(a||(a={}));class s{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:n}){const i={text:a};s&&(i.locale=s),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 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 n=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(n)}static async makeSTT(t,e,a,s){const n=new FormData;n.append("audio",a),s&&n.append("language",s);const i=await fetch(`${t}/api/v1/session/${e}/stt/`,{method:"POST",body:n});return await this.parseJson(i)}static async makeLLM(e,a,s,n){const i=await fetch(`${e}/api/v1/session/${a}/llm/v2/`,{body:JSON.stringify(s),headers:{"Content-Type":"application/json"},method:"POST",signal:n});if(!i.ok){const e=await i.json(),a=e.errors?.[0]??{code:"UNKNOWN_ERROR",detail:`Server returned status ${i.status} with no error details`,attr:null};throw new t(i.status,a.code,a.detail,a.attr)}return i.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(e){const a=await e.json();if(e.ok)return a;{const s=a.errors?.[0]??{code:"UNKNOWN_ERROR",detail:`Server returned status ${e.status} with no error details`,attr:null};throw new t(e.status,s.code,s.detail,s.attr)}}}async function n(t,e){return await s.getLLMs(t,e)}async function i(t,e){return await s.getTTSs(t,e)}async function o(t,e){return await s.getSTTs(t,e)}async function r(t,e){return await s.getModelStyles(t,e)}async function c(t,e){return await s.getBackgroundImages(t,e)}async function p(t,e){return await s.getPrompts(t,e)}async function d(t,e){return await s.getDocuments(t,e)}async function l(t,e){return await s.getMcpServers(t,e)}async function m(t,e){return await s.getTextNormalizations(t,e)}async function y(t,e,a){return await s.downloadTextNormalization(t,e,a)}async function _(t,e){return await s.getSessionTemplates(t,e)}async function S(t,e,a){return await s.getSessionTemplate(t,e,a)}async function u(t,e){const[a,s,y,_,S,u,h,T,g]=await Promise.all([n(t,e),i(t,e),o(t,e),r(t,e),c(t,e),p(t,e),d(t,e),l(t,e),m(t,e).catch(()=>[])]);return{llms:a,ttsTypes:s,sttTypes:y,modelStyles:_,backgroundImages:S,prompts:u,documents:h,mcpServers:T,textNormalizations:g}}async function h(t,e){return await s.makeTTS(t,e)}async function T(t,e){return await s.getSessionInfo(t,e)}async function g(t,a,n){let i;if("string"==typeof n){const o=await s.getSessionTemplate(t,a,n);if("webrtc"!==o.model_style.platform_type)throw new Error(`SessionTemplate "${n}" uses platform_type "${o.model_style.platform_type}", but only "webrtc" is supported`);i=function(t){const a=e=>t.capability.some(t=>t.name===e);return{using_stf_webrtc:a(e.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:a(e.LLM)?t.llm_type.name:void 0,tts_type:a(e.TTS)?t.tts_type.name:void 0,stt_type:a(e.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}}(o)}else i=n;const o={capability:[],...i};i.using_stf_webrtc&&o.capability.push("STF_WEBRTC"),i?.llm_type&&(o.capability.push("LLM"),o.llm_type=i.llm_type),i?.tts_type&&(o.capability.push("TTS"),o.tts_type=i.tts_type),i?.stt_type&&(o.capability.push("STT"),o.stt_type=i.stt_type);const r=await fetch(`${t}/api/v1/session/`,{body:JSON.stringify(o),headers:{"PersoLive-APIKey":a,"Content-Type":"application/json"},method:"POST"});return(await s.parseJson(r)).session_id}const w=async(e,a,n)=>{try{const t=(await s.getPrompts(e,a)).find(t=>t.prompt_id===n);if(!t)throw new Error(`Prompt (${n}) 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}};export{t as ApiError,s as PersoUtilServer,g as createSessionId,u as getAllSettings,c as getBackgroundImages,d as getDocuments,w as getIntroMessage,n as getLLMs,l as getMcpServers,r as getModelStyles,p as getPrompts,o as getSTTs,T as getSessionInfo,S as getSessionTemplate,_ as getSessionTemplates,i as getTTSs,y as getTextNormalization,m as getTextNormalizations,h as makeTTS};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perso-interactive-sdk-web",
3
- "version": "1.3.4",
3
+ "version": "1.4.0",
4
4
  "description": "Perso Interactive Web SDK - WebRTC-based real-time interactive AI avatar sessions",
5
5
  "type": "module",
6
6
  "private": false,