perso-interactive-sdk-web 1.3.4 → 1.5.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 +57 -16
- package/dist/client/index.cjs +1 -1
- package/dist/client/index.d.ts +91 -20
- 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 +304 -150
- package/dist/server/index.js +1 -1
- package/package.json +1 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -1,3 +1,173 @@
|
|
|
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 {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
|
+
*/
|
|
34
|
+
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
|
+
*/
|
|
42
|
+
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>;
|
|
51
|
+
|
|
52
|
+
interface Prompt {
|
|
53
|
+
prompt_id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
system_prompt: string;
|
|
57
|
+
require_document?: boolean;
|
|
58
|
+
intro_message?: string;
|
|
59
|
+
}
|
|
60
|
+
interface SessionCapability {
|
|
61
|
+
name: SessionCapabilityName;
|
|
62
|
+
description?: string | null;
|
|
63
|
+
}
|
|
64
|
+
interface Document {
|
|
65
|
+
document_id: string;
|
|
66
|
+
title: string;
|
|
67
|
+
file: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
search_count?: number;
|
|
70
|
+
ef_search?: number | null;
|
|
71
|
+
processed: boolean;
|
|
72
|
+
processed_v2: boolean;
|
|
73
|
+
created_at: string;
|
|
74
|
+
updated_at: string;
|
|
75
|
+
}
|
|
76
|
+
interface LLMType {
|
|
77
|
+
name: string;
|
|
78
|
+
service?: string;
|
|
79
|
+
}
|
|
80
|
+
interface TTSType {
|
|
81
|
+
name: string;
|
|
82
|
+
streamable?: boolean;
|
|
83
|
+
service: string;
|
|
84
|
+
model?: string | null;
|
|
85
|
+
voice?: string | null;
|
|
86
|
+
voice_settings?: unknown | null;
|
|
87
|
+
style?: string | null;
|
|
88
|
+
voice_extra_data?: unknown | null;
|
|
89
|
+
}
|
|
90
|
+
interface STTType {
|
|
91
|
+
name: string;
|
|
92
|
+
service: string;
|
|
93
|
+
options?: unknown | null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Response from POST /api/v1/session/{session_id}/stt/.
|
|
97
|
+
* Mirrors STTResponse in the OpenAPI schema. All three fields are required;
|
|
98
|
+
* `normalized_text` may be empty or equal to `text` when the session has no
|
|
99
|
+
* STT text-normalization config configured.
|
|
100
|
+
*/
|
|
101
|
+
interface STTResponse {
|
|
102
|
+
text: string;
|
|
103
|
+
locale: string;
|
|
104
|
+
normalized_text: string;
|
|
105
|
+
}
|
|
106
|
+
interface TextNormalizationConfig {
|
|
107
|
+
textnormalizationconfig_id: string;
|
|
108
|
+
name: string;
|
|
109
|
+
created_at: string;
|
|
110
|
+
}
|
|
111
|
+
interface ModelStyleConfig {
|
|
112
|
+
modelstyleconfig_id: string;
|
|
113
|
+
key: string;
|
|
114
|
+
value: string;
|
|
115
|
+
}
|
|
116
|
+
interface AIHumanModelFile {
|
|
117
|
+
name: string;
|
|
118
|
+
file?: string | null;
|
|
119
|
+
}
|
|
120
|
+
interface ModelStyle {
|
|
121
|
+
name: string;
|
|
122
|
+
model: string;
|
|
123
|
+
model_file?: string | null;
|
|
124
|
+
model_files: AIHumanModelFile[];
|
|
125
|
+
style: string;
|
|
126
|
+
file?: string | null;
|
|
127
|
+
platform_type?: string;
|
|
128
|
+
configs: ModelStyleConfig[];
|
|
129
|
+
}
|
|
130
|
+
interface BackgroundImage {
|
|
131
|
+
backgroundimage_id: string;
|
|
132
|
+
title: string;
|
|
133
|
+
image: string;
|
|
134
|
+
created_at: string;
|
|
135
|
+
}
|
|
136
|
+
interface MCPServer {
|
|
137
|
+
mcpserver_id: string;
|
|
138
|
+
name: string;
|
|
139
|
+
description?: string;
|
|
140
|
+
url: string;
|
|
141
|
+
transport_protocol?: string;
|
|
142
|
+
server_timeout_sec?: number;
|
|
143
|
+
extra_data?: unknown | null;
|
|
144
|
+
}
|
|
145
|
+
interface SessionTemplate {
|
|
146
|
+
sessiontemplate_id: string;
|
|
147
|
+
name: string;
|
|
148
|
+
description: string | null;
|
|
149
|
+
prompt: Prompt;
|
|
150
|
+
capability: SessionCapability[];
|
|
151
|
+
document: Document | null;
|
|
152
|
+
llm_type: LLMType;
|
|
153
|
+
tts_type: TTSType;
|
|
154
|
+
stt_type: STTType;
|
|
155
|
+
text_normalization_config?: TextNormalizationConfig | null;
|
|
156
|
+
text_normalization_locale?: string | null;
|
|
157
|
+
stt_text_normalization_config?: TextNormalizationConfig | null;
|
|
158
|
+
stt_text_normalization_locale?: string | null;
|
|
159
|
+
model_style: ModelStyle;
|
|
160
|
+
background_image: BackgroundImage | null;
|
|
161
|
+
agent: string | null;
|
|
162
|
+
padding_left: number | null;
|
|
163
|
+
padding_top: number | null;
|
|
164
|
+
padding_height: number | null;
|
|
165
|
+
extra_data: unknown | null;
|
|
166
|
+
mcp_servers?: MCPServer[];
|
|
167
|
+
created_at: string;
|
|
168
|
+
last_used_at: string | null;
|
|
169
|
+
}
|
|
170
|
+
|
|
1
171
|
declare enum SessionCapabilityName {
|
|
2
172
|
LLM = "LLM",
|
|
3
173
|
TTS = "TTS",
|
|
@@ -255,14 +425,17 @@ declare class PersoUtil {
|
|
|
255
425
|
* @param sessionId Session ID for the current session
|
|
256
426
|
* @param audioFile Audio file (WAV format)
|
|
257
427
|
* @param language Optional language code (e.g., 'ko', 'en')
|
|
258
|
-
* @returns
|
|
428
|
+
* @returns STTResponse with transcription, locale, and normalized text.
|
|
259
429
|
* {
|
|
260
|
-
* "text": string
|
|
430
|
+
* "text": string,
|
|
431
|
+
* "locale": string,
|
|
432
|
+
* "normalized_text": string
|
|
261
433
|
* }
|
|
434
|
+
*
|
|
435
|
+
* `normalized_text` may be empty or equal to `text` when the session has
|
|
436
|
+
* no STT text-normalization config attached.
|
|
262
437
|
*/
|
|
263
|
-
static makeSTT(apiServer: string, sessionId: string, audioFile: File, language?: string): Promise<
|
|
264
|
-
text: string;
|
|
265
|
-
}>;
|
|
438
|
+
static makeSTT(apiServer: string, sessionId: string, audioFile: File, language?: string): Promise<STTResponse>;
|
|
266
439
|
/**
|
|
267
440
|
* Initiates an LLM streaming request and returns the response body reader.
|
|
268
441
|
* @param apiServer Perso Interactive API Server
|
|
@@ -294,162 +467,73 @@ declare class PersoUtil {
|
|
|
294
467
|
static parseJson(response: Response): Promise<any>;
|
|
295
468
|
}
|
|
296
469
|
|
|
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
470
|
/**
|
|
420
|
-
*
|
|
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.
|
|
471
|
+
* Retrieves the list of available LLM providers from the API.
|
|
425
472
|
* @param apiServer Perso API server URL.
|
|
426
473
|
* @param apiKey API key used for authentication.
|
|
427
|
-
* @
|
|
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.
|
|
474
|
+
* @returns Promise resolving with LLM metadata.
|
|
431
475
|
*/
|
|
432
|
-
declare function
|
|
476
|
+
declare function getLLMs(apiServer: string, apiKey: string): Promise<any>;
|
|
433
477
|
/**
|
|
434
|
-
*
|
|
478
|
+
* Retrieves available TTS providers.
|
|
435
479
|
* @param apiServer Perso API server URL.
|
|
436
480
|
* @param apiKey API key used for authentication.
|
|
437
|
-
* @param params Runtime options for the session.
|
|
438
|
-
* @returns Session ID returned by the server.
|
|
439
481
|
*/
|
|
440
|
-
declare function
|
|
482
|
+
declare function getTTSs(apiServer: string, apiKey: string): Promise<any>;
|
|
441
483
|
/**
|
|
442
|
-
* Retrieves
|
|
484
|
+
* Retrieves available STT providers.
|
|
443
485
|
* @param apiServer Perso API server URL.
|
|
444
486
|
* @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
487
|
*/
|
|
488
|
+
declare function getSTTs(apiServer: string, apiKey: string): Promise<any>;
|
|
489
|
+
/**
|
|
490
|
+
* Fetches avatar model styles.
|
|
491
|
+
* @param apiServer Perso API server URL.
|
|
492
|
+
* @param apiKey API key used for authentication.
|
|
493
|
+
*/
|
|
494
|
+
declare function getModelStyles(apiServer: string, apiKey: string): Promise<any>;
|
|
495
|
+
/**
|
|
496
|
+
* Fetches preset background images.
|
|
497
|
+
* @param apiServer Perso API server URL.
|
|
498
|
+
* @param apiKey API key used for authentication.
|
|
499
|
+
*/
|
|
500
|
+
declare function getBackgroundImages(apiServer: string, apiKey: string): Promise<any>;
|
|
501
|
+
/**
|
|
502
|
+
* Returns predefined prompt templates.
|
|
503
|
+
* @param apiServer Perso API server URL.
|
|
504
|
+
* @param apiKey API key used for authentication.
|
|
505
|
+
*/
|
|
506
|
+
declare function getPrompts(apiServer: string, apiKey: string): Promise<any>;
|
|
507
|
+
/**
|
|
508
|
+
* Returns supporting document metadata usable by the session.
|
|
509
|
+
* @param apiServer Perso API server URL.
|
|
510
|
+
* @param apiKey API key used for authentication.
|
|
511
|
+
*/
|
|
512
|
+
declare function getDocuments(apiServer: string, apiKey: string): Promise<any>;
|
|
513
|
+
/**
|
|
514
|
+
* Lists MCP server identifiers configured for the tenant.
|
|
515
|
+
* @param apiServer Perso API server URL.
|
|
516
|
+
* @param apiKey API key used for authentication.
|
|
517
|
+
*/
|
|
518
|
+
declare function getMcpServers(apiServer: string, apiKey: string): Promise<any>;
|
|
519
|
+
/**
|
|
520
|
+
* Retrieves available text normalization options.
|
|
521
|
+
* @param apiServer Perso API server URL.
|
|
522
|
+
* @param apiKey API key used for authentication.
|
|
523
|
+
*/
|
|
524
|
+
declare function getTextNormalizations(apiServer: string, apiKey: string): Promise<any>;
|
|
525
|
+
/**
|
|
526
|
+
* Downloads the ruleset data file for a Text Normalization Config.
|
|
527
|
+
* Returns a pre-signed Blob Storage URL for the CSV file.
|
|
528
|
+
* @param apiServer Perso API server URL.
|
|
529
|
+
* @param apiKey API key used for authentication.
|
|
530
|
+
* @param configId Text Normalization Config ID.
|
|
531
|
+
*/
|
|
532
|
+
declare function getTextNormalization(apiServer: string, apiKey: string, configId: string): Promise<TextNormalizationDownload>;
|
|
448
533
|
/**
|
|
449
534
|
* Retrieves the list of session templates.
|
|
450
535
|
* @param apiServer Perso API server URL.
|
|
451
536
|
* @param apiKey API key used for authentication.
|
|
452
|
-
* @returns {Promise<SessionTemplate[]>} Array of available session templates.
|
|
453
537
|
*/
|
|
454
538
|
declare function getSessionTemplates(apiServer: string, apiKey: string): Promise<SessionTemplate[]>;
|
|
455
539
|
/**
|
|
@@ -457,11 +541,46 @@ declare function getSessionTemplates(apiServer: string, apiKey: string): Promise
|
|
|
457
541
|
* @param apiServer Perso API server URL.
|
|
458
542
|
* @param apiKey API key used for authentication.
|
|
459
543
|
* @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
544
|
*/
|
|
463
545
|
declare function getSessionTemplate(apiServer: string, apiKey: string, sessionTemplateId: string): Promise<SessionTemplate>;
|
|
464
|
-
|
|
546
|
+
/**
|
|
547
|
+
* Convenience helper that fetches every dropdown-friendly resource needed to
|
|
548
|
+
* build a Perso session configuration screen in one call chain.
|
|
549
|
+
* @param apiServer Perso API server URL.
|
|
550
|
+
* @param apiKey API key used for authentication.
|
|
551
|
+
* @returns Object containing arrays for LLMs, TTS/STT types, model styles, etc.
|
|
552
|
+
*/
|
|
553
|
+
declare function getAllSettings(apiServer: string, apiKey: string): Promise<{
|
|
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
|
+
}>;
|
|
564
|
+
/**
|
|
565
|
+
* Sends text to the TTS API and returns Base64-encoded audio.
|
|
566
|
+
* @param apiServer Perso API server URL.
|
|
567
|
+
* @param params Session ID and text to synthesize.
|
|
568
|
+
* @returns Object with Base64 audio string.
|
|
569
|
+
*/
|
|
570
|
+
declare function makeTTS(apiServer: string, params: {
|
|
571
|
+
sessionId: string;
|
|
572
|
+
text: string;
|
|
573
|
+
locale?: string;
|
|
574
|
+
output_format?: string;
|
|
575
|
+
}): Promise<{
|
|
576
|
+
audio: string;
|
|
577
|
+
}>;
|
|
578
|
+
/**
|
|
579
|
+
* Retrieves metadata for an existing session.
|
|
580
|
+
* @param apiServer Perso API server URL.
|
|
581
|
+
* @param sessionId Session id to inspect.
|
|
582
|
+
*/
|
|
583
|
+
declare function getSessionInfo(apiServer: string, sessionId: string): Promise<any>;
|
|
465
584
|
|
|
466
585
|
declare class ApiError extends Error {
|
|
467
586
|
errorCode: number;
|
|
@@ -470,6 +589,41 @@ declare class ApiError extends Error {
|
|
|
470
589
|
attr?: string | undefined;
|
|
471
590
|
constructor(errorCode: number, code: string, detail: string, attr?: string | undefined);
|
|
472
591
|
}
|
|
592
|
+
/**
|
|
593
|
+
* Domain error thrown by `createSessionId()` (and the `getSessionTemplate`
|
|
594
|
+
* path) when the underlying API returns an `ApiError`. The raw
|
|
595
|
+
* `errorCode`, `code`, `detail`, and `attr` fields are preserved as-is —
|
|
596
|
+
* callers inspect them to decide how to react (e.g. treat
|
|
597
|
+
* `code === 'invalid'` with a "not found" detail as feature-unavailable
|
|
598
|
+
* per LIV-1681).
|
|
599
|
+
*
|
|
600
|
+
* Extends `ApiError`, so existing `instanceof ApiError` branches keep
|
|
601
|
+
* working.
|
|
602
|
+
*/
|
|
603
|
+
declare class SessionCreationError extends ApiError {
|
|
604
|
+
constructor(source: ApiError);
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Session creation failed because a referenced resource does not exist.
|
|
608
|
+
* Triggered when the server returns `code === 'does_not_exist'` — for
|
|
609
|
+
* example, a `prompt_id` that has been deleted or never existed. The
|
|
610
|
+
* `attr` field, when present, identifies which input field referenced
|
|
611
|
+
* the missing resource (e.g. `'prompt'`).
|
|
612
|
+
*/
|
|
613
|
+
declare class DoesNotExistError extends SessionCreationError {
|
|
614
|
+
constructor(source: ApiError);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Session creation failed because a referenced resource is not assigned
|
|
618
|
+
* to the caller's organization. Triggered when the server returns
|
|
619
|
+
* `code === 'not_in_organization'` — for example, an LLM/TTS/STT type
|
|
620
|
+
* that exists in the platform catalog but is not enabled for this
|
|
621
|
+
* organization. The `attr` field, when present, identifies which input
|
|
622
|
+
* field referenced the unavailable resource.
|
|
623
|
+
*/
|
|
624
|
+
declare class NotInOrganizationError extends SessionCreationError {
|
|
625
|
+
constructor(source: ApiError);
|
|
626
|
+
}
|
|
473
627
|
|
|
474
|
-
export { ApiError, PersoUtil as PersoUtilServer, createSessionId, getIntroMessage, getSessionTemplate, getSessionTemplates };
|
|
475
|
-
export type { SessionTemplate };
|
|
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 };
|
package/dist/server/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class t extends Error{errorCode;code;detail;attr;constructor(t,e,s,a){let
|
|
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};
|