perso-interactive-sdk-web 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -1
- package/dist/client/index.cjs +1 -1
- package/dist/client/index.d.ts +174 -17
- 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 +236 -54
- package/dist/server/index.js +1 -1
- package/package.json +1 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -1,56 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Requests a new session creation ID by POSTing the desired runtime options to
|
|
17
|
-
* the Perso backend (`/api/v1/session/`).
|
|
18
|
-
* @param apiServer Perso API server URL.
|
|
19
|
-
* @param apiKey API key used for authentication.
|
|
20
|
-
* @param params {
|
|
21
|
-
* using_stf_webrtc: boolean;
|
|
22
|
-
* llm_type?: string;
|
|
23
|
-
* tts_type?: string;
|
|
24
|
-
* stt_type?: string;
|
|
25
|
-
* model_style: string;
|
|
26
|
-
* prompt: string;
|
|
27
|
-
* document?: string;
|
|
28
|
-
* background_image?: string;
|
|
29
|
-
* mcp_servers?: Array<string>;
|
|
30
|
-
* padding_left?: number;
|
|
31
|
-
* padding_top?: number;
|
|
32
|
-
* padding_height?: number;
|
|
33
|
-
* }
|
|
34
|
-
* @returns Session ID returned by the server.
|
|
35
|
-
*/
|
|
36
|
-
declare const createSessionId: (apiServer: string, apiKey: string, params: CreateSessionIdBody) => Promise<string>;
|
|
37
|
-
/**
|
|
38
|
-
* Retrieves the intro message for a specific prompt.
|
|
39
|
-
* @param apiServer Perso API server URL.
|
|
40
|
-
* @param apiKey API key used for authentication.
|
|
41
|
-
* @param promptId The prompt ID to fetch intro message for.
|
|
42
|
-
* @returns The intro message string.
|
|
43
|
-
*/
|
|
44
|
-
declare const getIntroMessage: (apiServer: string, apiKey: string, promptId: string) => Promise<string>;
|
|
45
|
-
|
|
46
|
-
declare class ApiError extends Error {
|
|
47
|
-
errorCode: number;
|
|
48
|
-
code: string;
|
|
49
|
-
detail: string;
|
|
50
|
-
attr?: string | undefined;
|
|
51
|
-
constructor(errorCode: number, code: string, detail: string, attr?: string | undefined);
|
|
1
|
+
declare enum SessionCapabilityName {
|
|
2
|
+
LLM = "LLM",
|
|
3
|
+
TTS = "TTS",
|
|
4
|
+
STT = "STT",
|
|
5
|
+
STF_ONPREMISE = "STF_ONPREMISE",
|
|
6
|
+
STF_WEBRTC = "STF_WEBRTC"
|
|
52
7
|
}
|
|
53
|
-
|
|
54
8
|
declare enum SessionEvent {
|
|
55
9
|
SESSION_START = "SESSION_START",
|
|
56
10
|
SESSION_DURING = "SESSION_DURING",
|
|
@@ -61,6 +15,11 @@ declare enum SessionEvent {
|
|
|
61
15
|
SESSION_STT = "SESSION_STT",
|
|
62
16
|
SESSION_LLM = "SESSION_LLM"
|
|
63
17
|
}
|
|
18
|
+
interface TextNormalizationDownload {
|
|
19
|
+
config_id: string;
|
|
20
|
+
config_name: string;
|
|
21
|
+
file_url: string;
|
|
22
|
+
}
|
|
64
23
|
declare class PersoUtil {
|
|
65
24
|
/**
|
|
66
25
|
* @param apiServer Perso Interactive API Server
|
|
@@ -134,9 +93,11 @@ declare class PersoUtil {
|
|
|
134
93
|
* "audio": string
|
|
135
94
|
* }
|
|
136
95
|
*/
|
|
137
|
-
static makeTTS(apiServer: string, { sessionId, text }: {
|
|
96
|
+
static makeTTS(apiServer: string, { sessionId, text, locale, output_format }: {
|
|
138
97
|
sessionId: string;
|
|
139
98
|
text: string;
|
|
99
|
+
locale?: string;
|
|
100
|
+
output_format?: string;
|
|
140
101
|
}): Promise<{
|
|
141
102
|
audio: string;
|
|
142
103
|
}>;
|
|
@@ -186,6 +147,49 @@ declare class PersoUtil {
|
|
|
186
147
|
* }
|
|
187
148
|
* ]
|
|
188
149
|
*/
|
|
150
|
+
/**
|
|
151
|
+
* @param apiServer Perso Interactive API Server
|
|
152
|
+
* @param apiKey Perso Interactive API Key
|
|
153
|
+
* @returns JSON
|
|
154
|
+
* [
|
|
155
|
+
* {
|
|
156
|
+
* "textnormalizationconfig_id": string,
|
|
157
|
+
* "name": string,
|
|
158
|
+
* "created_at": string
|
|
159
|
+
* }
|
|
160
|
+
* ]
|
|
161
|
+
*/
|
|
162
|
+
static getTextNormalizations(apiServer: string, apiKey: string): Promise<any>;
|
|
163
|
+
/**
|
|
164
|
+
* Downloads the ruleset data file for a Text Normalization Config.
|
|
165
|
+
* Returns a pre-signed Blob Storage URL for the CSV file.
|
|
166
|
+
* The client can download the file directly from this URL and leverage Azure Blob Storage ETag for caching.
|
|
167
|
+
* @param apiServer Perso Interactive API Server
|
|
168
|
+
* @param apiKey Perso Interactive API Key
|
|
169
|
+
* @param configId Text Normalization Config ID
|
|
170
|
+
* @returns JSON
|
|
171
|
+
* {
|
|
172
|
+
* "config_id": string,
|
|
173
|
+
* "config_name": string,
|
|
174
|
+
* "file_url": string
|
|
175
|
+
* }
|
|
176
|
+
*/
|
|
177
|
+
static downloadTextNormalization(apiServer: string, apiKey: string, configId: string): Promise<TextNormalizationDownload>;
|
|
178
|
+
/**
|
|
179
|
+
* Retrieves the list of session templates.
|
|
180
|
+
* @param apiServer Perso Interactive API Server
|
|
181
|
+
* @param apiKey Perso Interactive API Key
|
|
182
|
+
* @returns Array of SessionTemplate objects
|
|
183
|
+
*/
|
|
184
|
+
static getSessionTemplates(apiServer: string, apiKey: string): Promise<SessionTemplate[]>;
|
|
185
|
+
/**
|
|
186
|
+
* Retrieves a single session template by ID.
|
|
187
|
+
* @param apiServer Perso Interactive API Server
|
|
188
|
+
* @param apiKey Perso Interactive API Key
|
|
189
|
+
* @param sessionTemplateId Session Template ID
|
|
190
|
+
* @returns SessionTemplate object
|
|
191
|
+
*/
|
|
192
|
+
static getSessionTemplate(apiServer: string, apiKey: string, sessionTemplateId: string): Promise<SessionTemplate>;
|
|
189
193
|
static getMcpServers(apiServer: string, apiKey: string): Promise<any>;
|
|
190
194
|
/**
|
|
191
195
|
* @param apiServer Perso Interactive API Server
|
|
@@ -290,4 +294,182 @@ declare class PersoUtil {
|
|
|
290
294
|
static parseJson(response: Response): Promise<any>;
|
|
291
295
|
}
|
|
292
296
|
|
|
293
|
-
|
|
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
|
+
/**
|
|
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.
|
|
425
|
+
* @param apiServer Perso API server URL.
|
|
426
|
+
* @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.
|
|
431
|
+
*/
|
|
432
|
+
declare function createSessionId(apiServer: string, apiKey: string, sessionTemplateId: string): Promise<string>;
|
|
433
|
+
/**
|
|
434
|
+
* @overload Creates a session from explicit runtime options.
|
|
435
|
+
* @param apiServer Perso API server URL.
|
|
436
|
+
* @param apiKey API key used for authentication.
|
|
437
|
+
* @param params Runtime options for the session.
|
|
438
|
+
* @returns Session ID returned by the server.
|
|
439
|
+
*/
|
|
440
|
+
declare function createSessionId(apiServer: string, apiKey: string, params: CreateSessionIdBody): Promise<string>;
|
|
441
|
+
/**
|
|
442
|
+
* Retrieves the intro message for a specific prompt.
|
|
443
|
+
* @param apiServer Perso API server URL.
|
|
444
|
+
* @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
|
+
*/
|
|
448
|
+
/**
|
|
449
|
+
* Retrieves the list of session templates.
|
|
450
|
+
* @param apiServer Perso API server URL.
|
|
451
|
+
* @param apiKey API key used for authentication.
|
|
452
|
+
* @returns {Promise<SessionTemplate[]>} Array of available session templates.
|
|
453
|
+
*/
|
|
454
|
+
declare function getSessionTemplates(apiServer: string, apiKey: string): Promise<SessionTemplate[]>;
|
|
455
|
+
/**
|
|
456
|
+
* Retrieves a single session template by ID.
|
|
457
|
+
* @param apiServer Perso API server URL.
|
|
458
|
+
* @param apiKey API key used for authentication.
|
|
459
|
+
* @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
|
+
*/
|
|
463
|
+
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
|
+
}
|
|
473
|
+
|
|
474
|
+
export { ApiError, PersoUtil as PersoUtilServer, createSessionId, getIntroMessage, getSessionTemplate, getSessionTemplates };
|
|
475
|
+
export type { SessionTemplate };
|
package/dist/server/index.js
CHANGED
|
@@ -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}){const a=await fetch(`${t}/api/v1/session/${e}/tts/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({
|
|
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){const a=await fetch(`${t}/api/v1/session/${e}/event/create/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({detail:"",event:s})});await this.parseJson(a)}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};
|