@voctiv/agent-sdk 0.1.2 → 0.2.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,7 +1,8 @@
1
1
  import type { BehaviorSubject, Observable } from 'rxjs';
2
- import { MediaChannel } from './types/media-channel';
2
+ import type { MediaChannel } from './types/media-channel';
3
3
  import { ScriptLogger } from './types/logger';
4
4
  import type { NluExtractOptions, NluInferResult } from './types/nlu';
5
+ import type { LegacyGetRecordsParams, LegacyPhraseRecord } from './types/legacy-phrase';
5
6
  /**
6
7
  * NLU (Natural Language Understanding) API.
7
8
  *
@@ -23,11 +24,11 @@ export interface NluScriptApi {
23
24
  extract$(utterance: string, options?: NluExtractOptions): Observable<NluInferResult>;
24
25
  }
25
26
  /**
26
- * Typed first-level dialog context passed to every script.
27
- * Contains all metadata about the current session: caller info,
28
- * script identity, routing params, and legacy compat fields.
27
+ * First-level **`context`** passed to every **`defineScript`** handler.
29
28
  *
30
- * Index signature allows arbitrary extra fields for forward compat.
29
+ * Combines **identity** (dialog, script, agent), **telephony** (caller/destination),
30
+ * **payload** (**`initialData`** vs **`dialogParams`**), **Voctiv platform** rows (**`dialogEntity`**),
31
+ * and **runtime** (**`env$`**, **`runTime`**). The index signature allows extra host-specific keys.
31
32
  */
32
33
  export interface ScriptDialogContext {
33
34
  /** Short language code, e.g. `"ru"`, `"en"`. */
@@ -52,11 +53,27 @@ export interface ScriptDialogContext {
52
53
  agentUuid?: string;
53
54
  /** Numeric NLU agent ID used for extract() calls. */
54
55
  agentId: number;
55
- /** Original params snapshot at session start (immutable). */
56
- initialParams: Record<string, unknown>;
57
- /** Mutable merged params (channel + session + route). */
58
- params: Record<string, unknown>;
59
- /** Whether legacy V3 compatibility mode is active. */
56
+ /**
57
+ * **Snapshot** of dialog/session payload when the script run started.
58
+ *
59
+ * Shallow copy of the merge **`channelParams` + `sessionParams`** after the server removes
60
+ * untrusted keys (e.g. client cannot spoof **`agentUuid`** here). **Do not mutate** — use
61
+ * **`dialogParams`** for the live map. Compare with **`dialogParams`** to see what changed
62
+ * during the call (if the host updates the live object).
63
+ */
64
+ initialData: Record<string, unknown>;
65
+ /**
66
+ * **Live** dialog/session parameter map for this run (same merge as **`initialData`** at start).
67
+ *
68
+ * The host may add or overwrite keys while the session progresses. For media scripts this
69
+ * aligns with {@link import('./types/media-channel').MediaChannel.params} (Omni defaults, route,
70
+ * Voctiv platform ASR/TTS: **`defaultAsrName`**, **`defaultTtsName`**, **`asrVendor`**, **`ttsVendor`**,
71
+ * **`asrConfig`**, **`ttsConfig`**, **`authentication_data`**, **`legacyAsrKeysByName`** /
72
+ * **`legacyTtsKeysByName`**, etc.). **Read/write** according to your integration; scripts should
73
+ * treat unknown keys as opaque.
74
+ */
75
+ dialogParams: Record<string, unknown>;
76
+ /** Whether Voctiv platform compatibility mode is active. */
60
77
  legacyV3Compat: boolean;
61
78
  /** `true` when the script runs without a real media channel (offline / queue / messaging). */
62
79
  headless: boolean;
@@ -70,14 +87,19 @@ export interface ScriptDialogContext {
70
87
  * **Persistence:** On script completion (success or error), the runtime snapshots `env$` and
71
88
  * persists it; the script return value must not carry env (see {@link ScriptResult}).
72
89
  *
73
- * Only active in legacy V3 compatibility mode.
90
+ * Only active in Voctiv platform compatibility mode.
74
91
  */
75
92
  env$?: BehaviorSubject<Record<string, unknown> | undefined>;
76
- /** Raw `dialog` table row from legacy DB. */
93
+ /** Raw `dialog` table row from the Voctiv platform database. */
77
94
  dialogEntity?: Record<string, unknown>;
78
- /** Raw `call` table row from legacy DB. */
95
+ /** Raw `call` table row from the Voctiv platform database. */
79
96
  callEntity?: Record<string, unknown>;
80
- /** Available TTS/ASR media key identifiers (legacy compat). */
97
+ /**
98
+ * Optional catalog of media keys exposed to the script (Voctiv platform / Omni), e.g. UUIDs or labels
99
+ * for UI or logging. **Credentials** still come from **`dialogParams.authentication_data`**
100
+ * (and the channel mirror); use **`name`** on {@link import('./types/asr-handle').AsrConfig} /
101
+ * {@link import('./types/mixer').PlayOptions} to select **`key_storage.name`** when LE credential maps exist.
102
+ */
81
103
  availableMediaKeys?: string[];
82
104
  /** Script entry point for routing (e.g. `"on_recall"`, `"on_message_api_received"`). */
83
105
  entryPoint?: string;
@@ -89,13 +111,39 @@ export interface ScriptDialogContext {
89
111
  recallDelay?: number;
90
112
  /** Inbound message that triggered this headless session (messaging). */
91
113
  inboundMessage?: InboundMessage;
114
+ /**
115
+ * Async-phase execution budget: remaining time, extension pool, {@link ScriptRunTime.extend}.
116
+ * Injected by the runtime; absent only in tests or non-standard hosts.
117
+ */
118
+ runTime?: ScriptRunTime;
92
119
  /** @internal NLU runtime config — opaque to scripts. */
93
120
  _nlu?: unknown;
94
121
  [key: string]: unknown;
95
122
  }
123
+ /**
124
+ * Time budget for the script async phase (after VM load). Lets scripts check remaining time
125
+ * and request limited extensions (capped by the runtime).
126
+ */
127
+ export interface ScriptRunTime {
128
+ /** Initial budget in ms before any {@link extend}. */
129
+ readonly budgetMs: number;
130
+ /** Maximum total extra ms grantable across all {@link extend} calls for this session. */
131
+ readonly maxExtendMs: number;
132
+ /** Milliseconds left until the runtime stops the async script phase. */
133
+ remainingMs(): number;
134
+ /** Extension quota not yet granted (ms). */
135
+ remainingExtendMs(): number;
136
+ /**
137
+ * Grants up to `requestedMs` additional runtime, limited by remaining extension quota.
138
+ * @returns Granted milliseconds (0 if nothing could be granted).
139
+ */
140
+ extend(requestedMs: number): number;
141
+ }
96
142
  /** Error info attached to {@link ScriptResult} when a script fails. */
97
143
  export interface ScriptError {
98
- /** Error category: `"script_error"` | `"server_error"` (mirrors old LE stat names). */
144
+ /**
145
+ * Machine-readable category, e.g. `script_error`, `script_load_failed`, `time_limit_exceeded`.
146
+ */
99
147
  code: string;
100
148
  /** Human-readable error description. */
101
149
  message: string;
@@ -113,7 +161,7 @@ export interface ScriptResult {
113
161
  error?: ScriptError;
114
162
  }
115
163
  /**
116
- * Result after the runtime attaches the final `env$` snapshot (legacy persistence).
164
+ * Result after the runtime attaches the final `env$` snapshot (Voctiv platform persistence).
117
165
  * Scripts never construct this type — use {@link ScriptResult} from `defineScript` handlers.
118
166
  */
119
167
  export interface PersistedScriptResult extends ScriptResult {
@@ -150,7 +198,7 @@ export interface ScheduleCallOptions {
150
198
  * Dialog state API — read and update dialog routing metadata.
151
199
  *
152
200
  * Setting `entryPoint` or `result` immediately persists the change
153
- * to the legacy DB (non-blocking, fire-and-forget).
201
+ * to the Voctiv platform database (non-blocking, fire-and-forget).
154
202
  */
155
203
  export interface DialogApi {
156
204
  /** Current script entry point (e.g. `"on_recall"`). Set to change routing for next call. */
@@ -206,10 +254,10 @@ export interface MessagingApi {
206
254
  readonly message$: Observable<InboundMessage>;
207
255
  }
208
256
  /**
209
- * Platform API — legacy-compatible operations available to scripts.
257
+ * Platform API — Voctiv platform–compatible operations available to scripts.
210
258
  *
211
259
  * Provides access to NLU, dialog state management, outbound call scheduling,
212
- * and messaging. Only functional in legacy V3 compatibility mode
260
+ * and messaging. Only functional in Voctiv platform compatibility mode
213
261
  * (except `nlu` which is always available).
214
262
  */
215
263
  export interface PlatformApi {
@@ -226,6 +274,13 @@ export interface PlatformApi {
226
274
  * @param options - Scheduling, routing, and retry options.
227
275
  */
228
276
  call(msisdn: string, options?: ScheduleCallOptions): Promise<void>;
277
+ /**
278
+ * Voctiv platform only: load `record_phrase` / `record_phrase_file` rows from the LE PostgreSQL database
279
+ * (same filters as old `RecordPhrase.get_records`). Returns playable phrase record objects.
280
+ * Requires numeric `agent_id` on the dialog (params or `NLU_DEFAULT_AGENT_ID`) and
281
+ * `LEGACY_V3_RECORD_PHRASE_ROOT` pointing at the phrase file storage root.
282
+ */
283
+ getRecords?(params: LegacyGetRecordsParams): Promise<LegacyPhraseRecord[]>;
229
284
  }
230
285
  /**
231
286
  * Top-level context passed to every script function.
@@ -257,7 +312,7 @@ export interface ScriptContext {
257
312
  channel: MediaChannel;
258
313
  /** Structured logger — writes to system log and optionally to `dialog_stats` DB table. */
259
314
  logger: ScriptLogger;
260
- /** Dialog context with session metadata, routing params, and legacy fields. */
315
+ /** Dialog context with session metadata, routing params, and Voctiv platform fields. */
261
316
  context: ScriptDialogContext;
262
317
  /** Platform API — NLU, dialog state, messaging, outbound calls. */
263
318
  platform: PlatformApi;
@@ -268,15 +323,27 @@ export interface ScriptContext {
268
323
  */
269
324
  export type ScriptFn = (ctx: ScriptContext) => void | ScriptResult | Promise<void | ScriptResult>;
270
325
  /**
271
- * Define a script entry point.
272
- * Wrap your script function with this to enable type checking and runtime registration.
326
+ * Mark the default export as a typed script entry point (identity wrapper; no runtime transform).
327
+ *
328
+ * The host loads this module, invokes the function with {@link ScriptContext}, and persists
329
+ * {@link ScriptResult} / {@link ScriptDialogContext.env$} according to Voctiv platform rules.
330
+ *
331
+ * @param fn - Handler receiving **`{ channel, logger, context, platform }`**.
332
+ * - Use **`channel`** for ASR/TTS (see {@link import('./types/asr-handle').AsrConfig.name},
333
+ * {@link import('./types/mixer').PlayOptions.name} for LE **`key_storage.name`** selection).
334
+ * - Use **`context.dialogParams`** / **`context.dialogUuid`** for routing; **`platform`** for NLU, calls, messaging.
335
+ * @returns The same **`fn`** reference.
273
336
  *
274
337
  * @example
275
338
  * ```ts
276
339
  * import { defineScript } from '@lib/scripting-sdk';
277
340
  *
278
341
  * export default defineScript(async ({ channel, logger, context, platform }) => {
279
- * // your script logic here
342
+ * const asr = await channel.createAsr({
343
+ * name: 'my-yandex-key',
344
+ * vendor: 'Y',
345
+ * language: 'ru-RU',
346
+ * });
280
347
  * });
281
348
  * ```
282
349
  */
@@ -1 +1 @@
1
- {"version":3,"file":"define-script.d.ts","sourceRoot":"","sources":["../src/define-script.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,K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D;IAC1D,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE;;;;;OAKG;IACH,UAAU,CAAC,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;CAC5E;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,OAAO,EAAE,YAAY,CAAC;IACtB,0FAA0F;IAC1F,MAAM,EAAE,YAAY,CAAC;IACrB,wFAAwF;IACxF,OAAO,EAAE,mBAAmB,CAAC;IAC7B,mEAAmE;IACnE,QAAQ,EAAE,WAAW,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,CACrB,GAAG,EAAE,aAAa,KACf,IAAI,GAAG,YAAY,GAAG,OAAO,CAAC,IAAI,GAAG,YAAY,CAAC,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,QAAQ,GAAG,QAAQ,CAEnD"}
@@ -2,15 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineScript = defineScript;
4
4
  /**
5
- * Define a script entry point.
6
- * Wrap your script function with this to enable type checking and runtime registration.
5
+ * Mark the default export as a typed script entry point (identity wrapper; no runtime transform).
6
+ *
7
+ * The host loads this module, invokes the function with {@link ScriptContext}, and persists
8
+ * {@link ScriptResult} / {@link ScriptDialogContext.env$} according to Voctiv platform rules.
9
+ *
10
+ * @param fn - Handler receiving **`{ channel, logger, context, platform }`**.
11
+ * - Use **`channel`** for ASR/TTS (see {@link import('./types/asr-handle').AsrConfig.name},
12
+ * {@link import('./types/mixer').PlayOptions.name} for LE **`key_storage.name`** selection).
13
+ * - Use **`context.dialogParams`** / **`context.dialogUuid`** for routing; **`platform`** for NLU, calls, messaging.
14
+ * @returns The same **`fn`** reference.
7
15
  *
8
16
  * @example
9
17
  * ```ts
10
18
  * import { defineScript } from '@lib/scripting-sdk';
11
19
  *
12
20
  * export default defineScript(async ({ channel, logger, context, platform }) => {
13
- * // your script logic here
21
+ * const asr = await channel.createAsr({
22
+ * name: 'my-yandex-key',
23
+ * vendor: 'Y',
24
+ * language: 'ru-RU',
25
+ * });
14
26
  * });
15
27
  * ```
16
28
  */
@@ -1 +1 @@
1
- {"version":3,"file":"define-script.js","sourceRoot":"","sources":["../src/define-script.ts"],"names":[],"mappings":";;AA4TA,oCAEC;AAfD;;;;;;;;;;;;GAYG;AACH,SAAgB,YAAY,CAAC,EAAY;IACvC,OAAO,EAAE,CAAC;AACZ,CAAC"}
1
+ {"version":3,"file":"define-script.js","sourceRoot":"","sources":["../src/define-script.ts"],"names":[],"mappings":";;AAoYA,oCAEC;AA3BD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,YAAY,CAAC,EAAY;IACvC,OAAO,EAAE,CAAC;AACZ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,29 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * **Agent scripting SDK** for `node-asr-tts-connector`: typed **`defineScript`** context,
4
+ * {@link import('./types/media-channel').MediaChannel}, ASR/TTS, LLM, SIP, and Voctiv platform (LE-compat) helpers.
5
+ *
6
+ * ### Selecting ASR/TTS credentials by `key_storage.name` (Voctiv platform)
7
+ *
8
+ * When the host enables Voctiv platform PostgreSQL key auth, **`channel.params.authentication_data`**
9
+ * may contain:
10
+ * - **`legacyAsrKeysByName`**: map **`name`** → `{ platform, flat }` for ASR
11
+ * - **`legacyTtsKeysByName`**: same for TTS
12
+ *
13
+ * Rows are scoped to **this dialog’s agent and company** (no agent UUID in the script). Use:
14
+ * - {@link import('./types/asr-handle').AsrConfig.name} or **`data.name`** on **`createAsr`**
15
+ * - {@link import('./types/mixer').PlayOptions.name} or **`ttsConfig.name`** on **`say`/`play`/`presay`**
16
+ *
17
+ * Channel defaults **`defaultAsrName`** / **`defaultTtsName`** apply when **`name`** is omitted.
18
+ */
1
19
  export { defineScript } from './define-script';
2
- export type { ScriptContext, ScriptDialogContext, ScriptResult, PersistedScriptResult, ScriptError, ScriptFn, NluScriptApi, PlatformApi, DialogApi, ScheduleCallOptions, SendMessageOptions, InboundMessage, MessagingApi, } from './define-script';
20
+ export type { ScriptContext, ScriptDialogContext, ScriptRunTime, ScriptResult, PersistedScriptResult, ScriptError, ScriptFn, NluScriptApi, PlatformApi, DialogApi, ScheduleCallOptions, SendMessageOptions, InboundMessage, MessagingApi, } from './define-script';
3
21
  export type { ScriptLogger } from './types/logger';
4
- export type { MediaChannel, ChannelAudio, ChannelEvents, ChannelLlm, ChannelSip, LlmOptions, LlmStreamChunk, ExtractOptions, } from './types/media-channel';
22
+ export type { MediaChannel, ChannelAudio, ChannelEvents, ChannelLlm, ChannelSip, LlmOptions, LlmStreamChunk, ExtractOptions, PersistentLlmStreamHandle, } from './types/media-channel';
5
23
  export type { AsrHandle, AsrConfig, AsrVadConfig, AsrSmartTurnConfig } from './types/asr-handle';
6
24
  export type { MixerQueueControl, PlayOptions, TtsStrategy, TtsVendor } from './types/mixer';
25
+ export type { LegacyPhraseRecord, LegacyGetRecordsParams, LegacySavePhraseOptions, } from './types/legacy-phrase';
26
+ export { LEGACY_PHRASE_RECORD_BRAND, isLegacyPhraseRecord, } from './types/legacy-phrase';
7
27
  export type { TextInput } from './types/text-input';
8
28
  export type { DtmfEvent, SipInfo, SipSignal, DataMessage, } from './types/events';
9
29
  export type { NluExtractOptions, NluInferResult } from './types/nlu';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,YAAY,EAC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M,uBAAuB,CAAC;AAC/B,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACjG,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC5F,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EACV,SAAS,EACT,OAAO,EACP,SAAS,EACT,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,27 @@
1
1
  "use strict";
2
+ /**
3
+ * @packageDocumentation
4
+ * **Agent scripting SDK** for `node-asr-tts-connector`: typed **`defineScript`** context,
5
+ * {@link import('./types/media-channel').MediaChannel}, ASR/TTS, LLM, SIP, and Voctiv platform (LE-compat) helpers.
6
+ *
7
+ * ### Selecting ASR/TTS credentials by `key_storage.name` (Voctiv platform)
8
+ *
9
+ * When the host enables Voctiv platform PostgreSQL key auth, **`channel.params.authentication_data`**
10
+ * may contain:
11
+ * - **`legacyAsrKeysByName`**: map **`name`** → `{ platform, flat }` for ASR
12
+ * - **`legacyTtsKeysByName`**: same for TTS
13
+ *
14
+ * Rows are scoped to **this dialog’s agent and company** (no agent UUID in the script). Use:
15
+ * - {@link import('./types/asr-handle').AsrConfig.name} or **`data.name`** on **`createAsr`**
16
+ * - {@link import('./types/mixer').PlayOptions.name} or **`ttsConfig.name`** on **`say`/`play`/`presay`**
17
+ *
18
+ * Channel defaults **`defaultAsrName`** / **`defaultTtsName`** apply when **`name`** is omitted.
19
+ */
2
20
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineScript = void 0;
21
+ exports.isLegacyPhraseRecord = exports.LEGACY_PHRASE_RECORD_BRAND = exports.defineScript = void 0;
4
22
  var define_script_1 = require("./define-script");
5
23
  Object.defineProperty(exports, "defineScript", { enumerable: true, get: function () { return define_script_1.defineScript; } });
24
+ var legacy_phrase_1 = require("./types/legacy-phrase");
25
+ Object.defineProperty(exports, "LEGACY_PHRASE_RECORD_BRAND", { enumerable: true, get: function () { return legacy_phrase_1.LEGACY_PHRASE_RECORD_BRAND; } });
26
+ Object.defineProperty(exports, "isLegacyPhraseRecord", { enumerable: true, get: function () { return legacy_phrase_1.isLegacyPhraseRecord; } });
6
27
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAAtC,6GAAA,YAAY,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AAqCrB,uDAG+B;AAF7B,2HAAA,0BAA0B,OAAA;AAC1B,qHAAA,oBAAoB,OAAA"}
@@ -1,5 +1,8 @@
1
1
  import { Observable } from 'rxjs';
2
- /** Voice Activity Detection (VAD) tuning parameters. */
2
+ /**
3
+ * Voice Activity Detection (VAD) tuning — used when the runtime attaches an energy/Silero-based
4
+ * VAD in front of the ASR connector. Exact semantics depend on the telephony VAD implementation.
5
+ */
3
6
  export interface AsrVadConfig {
4
7
  /** Energy threshold to start speech detection (0.0–1.0). */
5
8
  positiveThreshold?: number;
@@ -11,70 +14,117 @@ export interface AsrVadConfig {
11
14
  energyFloor?: number;
12
15
  /** Smoothing factor for noise floor estimation (0.0–1.0). */
13
16
  noiseFloorAlpha?: number;
14
- /** Frames of audio to include before detected speech start. */
17
+ /** Frames of PCM (typically 20 ms @ 8 kHz) to prepend before detected speech start. */
15
18
  preSpeechFrames?: number;
16
19
  /** Silence frames after speech before confirming end-of-speech. */
17
20
  postSpeechFrames?: number;
18
21
  }
19
- /** Smart turn-taking configuration — controls when to finalize ASR during conversation. */
22
+ /**
23
+ * Smart turn-taking — controls when the runtime finalizes an utterance (end-of-turn) while
24
+ * streaming audio to ASR. Reduces cutting off the user mid-sentence when enabled.
25
+ */
20
26
  export interface AsrSmartTurnConfig {
21
- /** Enable smart turn-taking (default: false). */
27
+ /** When `true`, turn-taking heuristics are applied (defaults vary by host). */
22
28
  enabled?: boolean;
23
- /** Frames of speech before starting a turn. */
29
+ /** Frames of speech that must be seen before a turn” can start. */
24
30
  triggerFrames?: number;
25
- /** Frames to wait before retrying after a short pause. */
31
+ /** Frames to wait before retrying after a short pause inside an utterance. */
26
32
  retryFrames?: number;
27
- /** Max silence frames before force-finalizing the turn. */
33
+ /** Max silence frames before force-finalizing the current turn. */
28
34
  maxSilenceFrames?: number;
29
- /** Milliseconds to wait for confirmation after potential end-of-turn. */
35
+ /** Milliseconds to wait for confirmation after a candidate end-of-turn. */
30
36
  confirmMs?: number;
31
- /** Hard timeout: finalize after this many ms of silence regardless. */
37
+ /** Hard cap: finalize after this many milliseconds of silence regardless of other rules. */
32
38
  silenceTimeoutMs?: number;
33
39
  }
34
- /** Configuration for creating an ASR (speech recognition) handle. */
40
+ /**
41
+ * Arguments for {@link import('./media-channel').MediaChannel.createAsr}.
42
+ *
43
+ * ### Voctiv platform + logic-executor `key_storage`
44
+ *
45
+ * When Voctiv platform compatibility is on and the connector loaded credentials from PostgreSQL, the session’s
46
+ * `authentication_data` includes **`legacyAsrKeysByName`**: a map from **`key_storage.name`**
47
+ * (string) to flat connector parameters (`api_key`, `base_url`, …) for **this dialog’s agent
48
+ * and company**. You do **not** pass agent UUID in the script — the dialog already belongs to an agent.
49
+ *
50
+ * - **`name`**: pick which row from that map to use (same value as in LE admin for the key).
51
+ * - If omitted, the channel default **`defaultAsrName`** (from Omni / route) is used.
52
+ * - If neither is set, credentials fall back to the usual **`authentication_data.asr.&lt;engine&gt;`**
53
+ * blob for the resolved vendor (main/reserved keys on the agent).
54
+ *
55
+ * You may also set the same selector as **`data.name`**; it must not be sent to the ASR vendor
56
+ * as a connector field — the runtime strips it when merging config.
57
+ *
58
+ * ### Vendor
59
+ *
60
+ * **`vendor`** is resolved via internal aliases (`"yandex"`, `"Y"`, `"neuro_v3"`, …). If you set
61
+ * **`name`** but omit **`vendor`**, the runtime may infer vendor from the key row’s **`platform`**
62
+ * in the catalog.
63
+ */
35
64
  export interface AsrConfig {
36
- /** ASR vendor / engine identifier. */
65
+ /**
66
+ * ASR vendor / engine hint: single-letter code (`"Y"`, `"D"`, …) or legacy name
67
+ * (`"yandex"`, `"neuro_v3"`, …). See host `media-vendor-aliases` mapping.
68
+ */
37
69
  vendor?: string;
38
- /** Recognition language (BCP-47, e.g. `"ru-RU"`). */
70
+ /**
71
+ * logic-executor **`key_storage.name`** for this dialog’s agent + company. Selects credentials
72
+ * from **`authentication_data.legacyAsrKeysByName[name]`** when Voctiv platform PostgreSQL key auth is enabled.
73
+ * Overrides channel **`defaultAsrName`**.
74
+ */
75
+ name?: string;
76
+ /** Recognition language (BCP-47), e.g. `"ru-RU"`. Passed through to the connector as `language`. */
39
77
  language?: string;
40
- /** Vendor-specific configuration parameters. */
78
+ /**
79
+ * Vendor-specific connection parameters (URLs, timeouts, model ids, …). Merged last over
80
+ * catalog credentials so the script can override per call. Primitive values are stringified.
81
+ * Do not rely on **`name`** here for third-party “model name” fields — use a key not consumed
82
+ * as the storage row selector, or set **`name`** only at the top level.
83
+ */
41
84
  data?: Record<string, unknown>;
42
- /** VAD tuning. */
85
+ /** Optional VAD tuning for this session (see host implementation). */
43
86
  vad?: AsrVadConfig;
44
- /** Smart turn-taking tuning. */
87
+ /** Optional smart-turn tuning for this session. */
45
88
  smartTurn?: AsrSmartTurnConfig;
46
89
  }
47
90
  /**
48
- * ASR handle a live speech recognition session.
91
+ * Live speech recognition session returned by {@link import('./media-channel').MediaChannel.createAsr}.
49
92
  *
50
- * Created via `channel.createAsr(config)`. Emits partial and final
51
- * recognition results as Observables. Must be destroyed when no longer needed.
93
+ * Subscribe to **`partial$`** / **`result$`** for transcripts; wire **`speechStart$`** /
94
+ * **`speechEnd$`** / **`interrupt$`** for barge-in and UI. Always call **`destroy()`** when done
95
+ * (e.g. on `channel.events.terminated$`) to release connector and subscriptions.
52
96
  */
53
97
  export interface AsrHandle {
54
- /** Unique handle identifier. */
98
+ /** Opaque id (passed to `channel.textInput` helpers in automated tests). */
55
99
  readonly id: string;
56
- /** Emits final recognition results (complete utterances). */
100
+ /**
101
+ * Emits one string per finalized utterance (end-of-turn). Empty strings may occur;
102
+ * filter in application code if needed.
103
+ */
57
104
  readonly result$: Observable<string>;
58
- /** Emits partial (intermediate) recognition results. `isFinal` = true on last partial. */
105
+ /**
106
+ * Streaming partial hypotheses. **`isFinal: true`** marks the last partial before a finalize
107
+ * or end-of-turn aligned with **`result$`**.
108
+ */
59
109
  readonly partial$: Observable<{
60
110
  text: string;
61
111
  isFinal: boolean;
62
112
  }>;
63
- /** Fires when speech is detected in the audio stream. */
113
+ /** Fires when VAD detects speech start (user started talking). */
64
114
  readonly speechStart$: Observable<void>;
65
- /** Fires when speech ends. */
115
+ /** Fires when VAD detects speech end (user stopped). */
66
116
  readonly speechEnd$: Observable<void>;
67
- /** Fires when ASR determines the user is interrupting (barge-in). */
117
+ /** Fires on barge-in / interrupt signals from the ASR stack (host-specific). */
68
118
  readonly interrupt$: Observable<void>;
69
- /** VAD probability stream (0.0–1.0) useful for visualization. */
119
+ /** Normalized voice-activity probability 0–1 when the host exposes it; else may be inert. */
70
120
  readonly vadProbability$: Observable<number>;
71
- /** Temporarily pause recognition (audio is still buffered). */
121
+ /** Pause audio consumption by the recognizer (implementation may buffer). */
72
122
  pause(): void;
73
- /** Resume recognition after pause. */
123
+ /** Resume after {@link pause}. */
74
124
  resume(): void;
75
- /** Force-finalize the current utterance (trigger result$ immediately). */
125
+ /** Force end of current utterance and flush **`result$`** as soon as possible. */
76
126
  finalize(): void;
77
- /** Destroy this ASR handle and release all resources. */
127
+ /** Tear down streams, connector, and subscriptions. Idempotent-safe on well-behaved hosts. */
78
128
  destroy(): void;
79
129
  }
80
130
  //# sourceMappingURL=asr-handle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"asr-handle.d.ts","sourceRoot":"","sources":["../../src/types/asr-handle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,wDAAwD;AACxD,MAAM,WAAW,YAAY;IAC3B,4DAA4D;IAC5D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,0DAA0D;IAC1D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iEAAiE;IACjE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6DAA6D;IAC7D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+DAA+D;IAC/D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,2FAA2F;AAC3F,MAAM,WAAW,kBAAkB;IACjC,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,+CAA+C;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0DAA0D;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2DAA2D;IAC3D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,qEAAqE;AACrE,MAAM,WAAW,SAAS;IACxB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qDAAq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CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACrC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAClE,kEAAkE;IAClE,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IACxC,wDAAwD;IACxD,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IACtC,gFAAgF;IAChF,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IACtC,6FAA6F;IAC7F,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAE7C,6EAA6E;IAC7E,KAAK,IAAI,IAAI,CAAC;IACd,kCAAkC;IAClC,MAAM,IAAI,IAAI,CAAC;IACf,kFAAkF;IAClF,QAAQ,IAAI,IAAI,CAAC;IACjB,8FAA8F;IAC9F,OAAO,IAAI,IAAI,CAAC;CACjB"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Marker for pre-recorded phrase rows loaded from the Voctiv platform LE PostgreSQL DB
3
+ * ({@link PlatformApi.getRecords}). Pass to {@link ChannelAudio.play} instead of a URL/path string.
4
+ *
5
+ * Only used when Voctiv platform compatibility mode is enabled.
6
+ */
7
+ export declare const LEGACY_PHRASE_RECORD_BRAND: "__legacyPhraseRecord";
8
+ export interface LegacyPhraseRecord {
9
+ readonly [LEGACY_PHRASE_RECORD_BRAND]: true;
10
+ /** Absolute filesystem path passed to the audio decoder (same layout as old logic-executor `nv.say`). */
11
+ readonly path: string;
12
+ /** Phrase transcript / label from DB. */
13
+ readonly text: string;
14
+ /** Phrase name (`record_phrase.name`). */
15
+ readonly phraseName: string;
16
+ }
17
+ export declare function isLegacyPhraseRecord(source: unknown): source is LegacyPhraseRecord;
18
+ /** Parameters for {@link PlatformApi.getRecords} (Voctiv platform LE `RecordPhrase` / `record_phrase_file`). */
19
+ export interface LegacyGetRecordsParams {
20
+ phraseName: string;
21
+ flag: string;
22
+ language: string;
23
+ }
24
+ /**
25
+ * When set on {@link PlayOptions}, after TTS the audio is copied under the Voctiv platform record-phrase root
26
+ * and a `record_phrase` / `record_phrase_file` row is inserted so {@link PlatformApi.getRecords}
27
+ * can retrieve it. Also registers the PCM in the TTS file cache for subsequent `say`/`presay`.
28
+ *
29
+ * Only honored when Voctiv platform compatibility mode is active and `LEGACY_V3_RECORD_PHRASE_ROOT` is set.
30
+ */
31
+ export interface LegacySavePhraseOptions {
32
+ phraseName: string;
33
+ /** Defaults to dialog `flag` from channel params when omitted. */
34
+ flag?: string;
35
+ /** Defaults to dialog language from channel params when omitted. */
36
+ language?: string;
37
+ }
38
+ //# sourceMappingURL=legacy-phrase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-phrase.d.ts","sourceRoot":"","sources":["../../src/types/legacy-phrase.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,wBAAkC,CAAC;AAE1E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,CAAC,0BAA0B,CAAC,EAAE,IAAI,CAAC;IAC5C,yGAAyG;IACzG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,kBAAkB,CAOlF;AAED,gHAAgH;AAChH,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LEGACY_PHRASE_RECORD_BRAND = void 0;
4
+ exports.isLegacyPhraseRecord = isLegacyPhraseRecord;
5
+ /**
6
+ * Marker for pre-recorded phrase rows loaded from the Voctiv platform LE PostgreSQL DB
7
+ * ({@link PlatformApi.getRecords}). Pass to {@link ChannelAudio.play} instead of a URL/path string.
8
+ *
9
+ * Only used when Voctiv platform compatibility mode is enabled.
10
+ */
11
+ exports.LEGACY_PHRASE_RECORD_BRAND = '__legacyPhraseRecord';
12
+ function isLegacyPhraseRecord(source) {
13
+ return (typeof source === 'object' &&
14
+ source !== null &&
15
+ source[exports.LEGACY_PHRASE_RECORD_BRAND] === true &&
16
+ typeof source.path === 'string');
17
+ }
18
+ //# sourceMappingURL=legacy-phrase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-phrase.js","sourceRoot":"","sources":["../../src/types/legacy-phrase.ts"],"names":[],"mappings":";;;AAkBA,oDAOC;AAzBD;;;;;GAKG;AACU,QAAA,0BAA0B,GAAG,sBAA+B,CAAC;AAY1E,SAAgB,oBAAoB,CAAC,MAAe;IAClD,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACd,MAA6B,CAAC,kCAA0B,CAAC,KAAK,IAAI;QACnE,OAAQ,MAA6B,CAAC,IAAI,KAAK,QAAQ,CACxD,CAAC;AACJ,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Structured logger available to scripts.
3
3
  *
4
- * In legacy compat mode, log entries are also batch-written
4
+ * In Voctiv platform compatibility mode, log entries are also batch-written
5
5
  * to the `dialog_stats` DB table (equivalent of old LE `nn.log`).
6
6
  */
7
7
  export interface ScriptLogger {
@@ -2,180 +2,205 @@ import { Observable } from 'rxjs';
2
2
  import { AsrConfig, AsrHandle } from './asr-handle';
3
3
  import { DtmfEvent, SipInfo, SipSignal, DataMessage } from './events';
4
4
  import { MixerQueueControl, PlayOptions } from './mixer';
5
+ import type { LegacyPhraseRecord } from './legacy-phrase';
5
6
  import { TextInput } from './text-input';
6
7
  /**
7
- * Audio playback API — TTS synthesis, file playback, and queue management.
8
+ * Audio playback API — TTS synthesis, file/URL playback, caching, and multi-queue mixing.
8
9
  *
9
- * Audio is routed through a multi-queue mixer. Each queue can play items
10
- * independently with its own volume. Default queue index is 0.
10
+ * Audio is routed through a **multi-queue mixer** (indices **0–4**). Each queue has its own
11
+ * volume and lifecycle; use different **`queue`** values in {@link PlayOptions} so earcons,
12
+ * hold music, and agent TTS can be **`stop`**ped independently.
11
13
  */
12
14
  export interface ChannelAudio {
13
15
  /**
14
- * Synthesize text via TTS and play it.
15
- * Accepts a plain string or an RxJS Observable of string chunks (for streaming TTS).
16
- * Resolves when playback finishes.
16
+ * Synthesize text with TTS and play the result on the selected mixer queue.
17
+ *
18
+ * @param input - Plain string, or `Observable<string>` of chunks for streaming synthesis.
19
+ * @param options - Queue, alias, volume, {@link PlayOptions.ttsVendor}, {@link PlayOptions.name}
20
+ * (LE `key_storage` row), {@link PlayOptions.ttsConfig}, {@link PlayOptions.ttsStrategy}, etc.
21
+ * @returns Resolves when playback of this **`say`** invocation has finished (queue may still
22
+ * contain other items).
17
23
  */
18
24
  say(input: string | Observable<string>, options?: PlayOptions): Promise<void>;
19
25
  /**
20
- * Play a pre-recorded audio file from URL or local path.
21
- * Resolves when playback finishes.
26
+ * Play audio from a URL/path string, or a {@link LegacyPhraseRecord} from the Voctiv platform phrase DB.
27
+ *
28
+ * @param source - HTTP(S) URL, local path, or structured {@link LegacyPhraseRecord} (no TTS).
29
+ * @param options - Queue, alias, volume, loop; **`tts*`** fields apply only if the host
30
+ * ever wraps playback (normally ignored for raw audio).
31
+ */
32
+ play(source: string | LegacyPhraseRecord, options?: PlayOptions): Promise<void>;
33
+ /**
34
+ * Download/decode **`source`** and cache PCM so a later **`say`/`play`** with the same source
35
+ * starts faster.
36
+ * @param source - URL or file path accepted by the host’s fetch layer.
22
37
  */
23
- play(source: string, options?: PlayOptions): Promise<void>;
24
- /** Download, decode and cache audio (URL or file path) as PCM for instant playback. */
25
38
  preload(source: string): Promise<void>;
26
- /** Pre-synthesize text via TTS and store in file cache for instant `say()` playback. */
39
+ /**
40
+ * Run TTS ahead of time and store audio in the host cache (exact semantics depend on connector).
41
+ * @param text - Full text to synthesize.
42
+ * @param options - Same TTS-related options as **`say`** (vendor, **`name`**, **`ttsConfig`**).
43
+ */
27
44
  presay(text: string, options?: PlayOptions): Promise<void>;
28
- /** Access a specific mixer queue by index (0–4). */
45
+ /**
46
+ * @param index - Mixer queue **0–4**.
47
+ * @returns Control handle for that queue’s volume and item lifecycle observables.
48
+ */
29
49
  queue(index: number): MixerQueueControl;
30
- /** Remove a specific item by alias from a queue. */
50
+ /**
51
+ * Remove one item by **`alias`** from a queue (default queue **0** if omitted).
52
+ * @param alias - **`PlayOptions.alias`** of the item to drop.
53
+ * @param queue - Queue index; defaults to **0**.
54
+ */
31
55
  remove(alias: string, queue?: number): void;
32
- /** Stop and clear all items in a specific queue. */
56
+ /**
57
+ * Stop playback and clear all pending items on a single queue.
58
+ * @param queue - Queue index **0–4**.
59
+ */
33
60
  stop(queue: number): void;
34
- /** Stop and clear all queues. */
61
+ /** Stop and clear **all** queues (nuclear option for teardown). */
35
62
  stopAll(): void;
36
63
  }
37
- /** Observables for channel-level events (speech detection, termination, data messages). */
64
+ /** Channel-level observables: VAD-related speech, barge-in, session end, and arbitrary data messages. */
38
65
  export interface ChannelEvents {
39
- /** Fires when the caller starts speaking (VAD-based). */
66
+ /** User started speaking (VAD speech start). */
40
67
  readonly speechStart$: Observable<void>;
41
- /** Fires when the caller stops speaking. */
68
+ /** User stopped speaking (VAD speech end). */
42
69
  readonly speechEnd$: Observable<void>;
43
- /** Fires when caller speech interrupts bot playback. */
70
+ /** User speech caused an interrupt of bot audio (barge-in path). */
44
71
  readonly interrupt$: Observable<void>;
45
- /** Fires when the session ends (hangup, timeout, or explicit destroy). */
72
+ /** Session is ending: hangup, client disconnect, or explicit **`channel.destroy()`**. */
46
73
  readonly terminated$: Observable<void>;
47
- /** Fires on incoming data messages (e.g. from WS client). */
74
+ /** Structured messages from the WS client or bridge (event + payload). */
48
75
  readonly message$: Observable<DataMessage>;
49
76
  }
50
- /** Options for LLM `ask()` and `stream()` calls. */
77
+ /** Options for **`channel.llm.ask`** / **`stream`** / **`makePersistentStream`**. */
51
78
  export interface LlmOptions {
52
- /** Override dialog UUID for LLM context tracking. */
79
+ /** Override dialog UUID for Omni/LLM tracing (defaults to script dialog). */
53
80
  dialogUuid?: string;
54
- /** System role hint (e.g. `"assistant"`, `"user"`). */
81
+ /** Chat role hint, e.g. **`"assistant"`**, **`"user"`**. */
55
82
  role?: string;
56
- /** If `true`, the message is added to history but not displayed. */
83
+ /** When `true`, message may be hidden from user-visible transcript (host-dependent). */
57
84
  hidden?: boolean;
58
- /** Speaker name for multi-turn dialogs. */
85
+ /**
86
+ * **LLM-only**: speaker / persona label in multi-party chat. **Not** related to
87
+ * {@link PlayOptions.name} (TTS **`key_storage.name`**).
88
+ */
59
89
  name?: string;
60
- /** Override agent UUID for routing to a specific LLM agent. */
90
+ /** Route the request to a specific Omni agent profile (UUID). */
61
91
  agentUuid?: string;
62
- /** Current agent alias for multi-agent scenarios. */
92
+ /** Multi-agent: current alias for routing. */
63
93
  currentAgentAlias?: string;
64
- /** Arbitrary payload forwarded to the LLM backend. */
94
+ /** Opaque payload forwarded to the LLM backend. */
65
95
  payload?: Record<string, any>;
66
- /** Enable debug logging for this request. */
96
+ /** Verbose logging on the LLM path. */
67
97
  debug?: boolean;
68
- /** Restrict response to specific agent aliases. */
98
+ /** Restrict which agent aliases may handle the request. */
69
99
  agentAliasFilter?: string[];
70
100
  }
71
- /** Options for LLM structured extraction. */
101
+ /** Options for **`channel.llm.extract`**. */
72
102
  export interface ExtractOptions {
73
- /** Override dialog UUID. */
74
103
  dialogUuid?: string;
75
- /** Extraction prompt / instruction. */
76
104
  prompt?: string;
77
- /** LLM model name. */
78
105
  model?: string;
79
- /** Top-p (nucleus) sampling parameter. */
80
106
  topP?: number;
81
- /** Temperature sampling parameter. */
82
107
  temperature?: number;
83
- /** Custom model configuration. */
84
108
  customModel?: Record<string, any>;
85
109
  [key: string]: unknown;
86
110
  }
87
- /** A single chunk from an LLM streaming response. */
111
+ /** One chunk from **`channel.llm.stream`**. */
88
112
  export interface LlmStreamChunk {
89
- /** Request ID. */
90
113
  id: string;
91
- /** Sequential chunk number. */
92
114
  chunkId: number;
93
- /** Text content of this chunk. */
94
115
  content: string;
95
- /** Non-null when the stream is done (e.g. `"stop"`, `"length"`). */
96
116
  finishReason: string | null;
97
- /** Raw SSE event data. */
98
117
  event: any;
99
- /** Tool call messages (function calling). */
100
118
  toolMessages?: any[];
101
- /** Full raw response object. */
102
119
  raw: Record<string, any>;
103
120
  }
104
121
  /**
105
- * LLM (Large Language Model) API text generation and structured extraction.
122
+ * Long-lived LLM Socket.IO stream amortizes connection setup across many user turns.
106
123
  */
124
+ export interface PersistentLlmStreamHandle {
125
+ readonly stream$: Observable<LlmStreamChunk>;
126
+ send(message: string, options?: LlmOptions): void;
127
+ disconnect(): void;
128
+ reconnect(): void;
129
+ }
130
+ /** LLM facade on the media channel. */
107
131
  export interface ChannelLlm {
108
- /** Send a message and get a complete response. */
132
+ /** Single-shot completion for **`message`**. */
109
133
  ask(message: string, options?: LlmOptions): Promise<string>;
110
- /** Send a message and get a streaming response (Observable of chunks). */
134
+ /** Token/chunk stream for **`message`**. */
111
135
  stream(message: string, options?: LlmOptions): Observable<LlmStreamChunk>;
112
- /** Structured data extraction using LLM (e.g. filling a form from conversation). */
136
+ /** Structured extraction / JSON-style fill from conversation context. */
113
137
  extract(options?: ExtractOptions): Promise<Record<string, any>>;
138
+ /**
139
+ * Open a persistent Omni chat stream (see host docs for URL and auth).
140
+ * @param options - Default **`agentUuid`**, **`dialogUuid`**, etc.; per-**`send`** overrides allowed.
141
+ */
142
+ makePersistentStream(options?: LlmOptions): PersistentLlmStreamHandle;
114
143
  }
115
- /**
116
- * SIP telephony controls — DTMF, call control, bridging.
117
- */
144
+ /** SIP: DTMF, INFO, hold/mute/hangup, outbound **`makeCall`**, **`bridge`**. */
118
145
  export interface ChannelSip {
119
- /** Observable of DTMF digit events. */
120
146
  readonly dtmf$: Observable<DtmfEvent>;
121
- /** Observable of SIP INFO messages. */
122
147
  readonly sipInfo$: Observable<SipInfo>;
123
- /** Observable of SIP call state changes (e.g. ringing, confirmed, terminated). */
124
148
  readonly sipSignal$: Observable<SipSignal>;
125
- /** Send a DTMF digit to the remote party. */
126
149
  sendDtmf(digit: string, duration?: number): void;
127
- /** Send a SIP INFO message. */
128
150
  sendInfo(contentType: string, body: string): void;
129
- /** Put the call on hold. */
130
151
  hold(): void;
131
- /** Resume a held call. */
132
152
  unhold(): void;
133
- /** Mute outgoing audio. */
134
153
  mute(): void;
135
- /** Unmute outgoing audio. */
136
154
  unmute(): void;
137
- /** Hang up the call. */
138
155
  hangup(): void;
139
- /** Answer an incoming call. */
140
156
  answer(): void;
141
- /** Originate a new outbound SIP call and return its media channel. */
142
157
  makeCall(opts: {
143
158
  sipUri: string;
144
159
  fromUri?: string;
145
160
  }): Promise<MediaChannel>;
146
- /** Bridge two channels together (conference). Returns a teardown function. */
147
161
  bridge(other: MediaChannel): () => void;
148
162
  }
149
163
  /**
150
- * Media channel the main interface for voice, audio, SIP, and LLM interaction.
164
+ * Primary script API for real-time voice: ASR, TTS/audio, SIP, LLM, and **`params`** from the host.
151
165
  *
152
- * Every script receives a `channel` object. In headless mode,
153
- * audio and SIP methods are no-ops or stubs.
166
+ * **`type`** is **`"sip"`** for telephony or **`"ws"`** for WebSocket/script-manager sessions.
167
+ * In **headless** mode (see {@link import('./define-script').ScriptDialogContext.headless}),
168
+ * audio/SIP may be no-ops while **`llm`** / **`platform`** still work.
154
169
  */
155
170
  export interface MediaChannel {
156
- /** Channel transport type: `"sip"` for phone calls, `"ws"` for WebSocket sessions. */
157
171
  readonly type: 'sip' | 'ws';
158
- /** Inbound caller ID (phone number or WS client ID). */
159
172
  readonly callerId: string;
160
- /** Called number / destination DID. */
161
173
  readonly calledNumber: string;
162
- /** Channel-level params (merged from route, agent defaults, etc.). */
174
+ /**
175
+ * Merged session parameters from env, Omni, Voctiv platform defaults, and route.
176
+ *
177
+ * Relevant to ASR/TTS when **Voctiv platform** compatibility is on (host-dependent keys), for example:
178
+ * - **`asrVendor`**, **`ttsVendor`**, **`asrConfig`**, **`ttsConfig`**
179
+ * - **`defaultAsrName`**, **`defaultTtsName`**: default **`key_storage.name`** when the script
180
+ * omits **`name`** on {@link AsrConfig} / {@link PlayOptions}
181
+ * - **`authentication_data`**: may include **`legacyAsrKeysByName`**, **`legacyTtsKeysByName`**
182
+ * (built from LE DB for this dialog’s agent + company)
183
+ *
184
+ * Treat as read-only unless your integration explicitly documents mutable keys.
185
+ */
163
186
  readonly params: Record<string, unknown>;
164
- /** Create a new ASR (speech recognition) handle with optional config. */
187
+ /**
188
+ * Create a speech recognizer for this session.
189
+ *
190
+ * @param config - Optional {@link AsrConfig}: **`vendor`**, **`name`** (storage row), **`language`**,
191
+ * **`data`** overlays, VAD / smart-turn tuning.
192
+ * @returns A handle you must {@link AsrHandle.destroy} when the session ends.
193
+ */
165
194
  createAsr(config?: AsrConfig): Promise<AsrHandle>;
166
- /** Virtual text input for testing push text as if ASR recognized it. */
195
+ /** Push synthetic ASR results (testing / WS debug). */
167
196
  readonly textInput: TextInput;
168
- /** Audio playback and TTS. */
169
197
  readonly audio: ChannelAudio;
170
- /** Channel events (speech, termination, data messages). */
171
198
  readonly events: ChannelEvents;
172
- /** LLM text generation and extraction. */
173
199
  readonly llm: ChannelLlm;
174
- /** SIP telephony controls. */
175
200
  readonly sip: ChannelSip;
176
- /** Send a data message to the remote party (WS). */
201
+ /** Emit a structured message to the remote peer (WS). */
177
202
  sendMessage(data: DataMessage): void;
178
- /** Terminate the channel and release all resources. */
203
+ /** Release connectors, mixer, and subscriptions. */
179
204
  destroy(): void;
180
205
  }
181
206
  //# sourceMappingURL=media-channel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"media-channel.d.ts","sourceRoot":"","sources":["../../src/types/media-channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E;;;OAGG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,uFAAuF;IACvF,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,wFAAwF;IACxF,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,oDAAoD;IACpD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAAC;IACxC,oDAAoD;IACpD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,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AI,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzC;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAElD,uDAAuD;IACvD,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAE9B,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IAEzB,yDAAyD;IACzD,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IACrC,oDAAoD;IACpD,OAAO,IAAI,IAAI,CAAC;CACjB"}
@@ -1,42 +1,106 @@
1
1
  import { Observable } from 'rxjs';
2
- /** TTS synthesis strategy. Default: `sentence`. */
2
+ import type { LegacySavePhraseOptions } from './legacy-phrase';
3
+ /**
4
+ * How TTS audio is chunked and fed to the mixer.
5
+ *
6
+ * - **`sentence`**: split on sentence boundaries (default).
7
+ * - **`streaming`**: incremental chunks as they arrive (mainly for streaming-capable vendors, e.g. ElevenLabs).
8
+ * - **`full`**: synthesize the entire utterance as one segment before playback.
9
+ */
3
10
  export type TtsStrategy = 'sentence' | 'streaming' | 'full';
4
- /** TTS vendor identifier. */
11
+ /**
12
+ * Internal TTS vendor code used by the connector factory.
13
+ *
14
+ * - **`A`**: default / Neuro-style path.
15
+ * - **`E`** / **`ES`**: ElevenLabs (`ES` = persistent streaming session where supported).
16
+ * - **`V`**, **`G`**: host-specific vendors (e.g. Voctiv, Google).
17
+ */
5
18
  export type TtsVendor = 'A' | 'E' | 'ES' | 'V' | 'G';
6
- /** Options for `say()` and `play()` calls. */
19
+ /**
20
+ * Options for {@link import('./media-channel').ChannelAudio.say},
21
+ * {@link import('./media-channel').ChannelAudio.play}, and
22
+ * {@link import('./media-channel').ChannelAudio.presay}.
23
+ *
24
+ * ### Voctiv platform + `key_storage` (TTS credentials)
25
+ *
26
+ * Same idea as ASR: when Voctiv platform compatibility is on and keys are loaded from PostgreSQL, **`authentication_data`**
27
+ * contains **`legacyTtsKeysByName`**, keyed by **`key_storage.name`** for **this dialog’s agent
28
+ * and company** (agent is implied by the dialog — no UUID in the script).
29
+ *
30
+ * - **`name`** on **`PlayOptions`**: select that row’s flat credentials for this synthesis.
31
+ * - Alternative: **`ttsConfig.name`** (the **`name`** entry is stripped before vendor params).
32
+ * - If omitted, **`defaultTtsName`** on the channel (Omni / route) applies.
33
+ * - Otherwise credentials come from **`authentication_data.tts.&lt;engine&gt;`** for the resolved vendor.
34
+ *
35
+ * ### Note on the field **`name`**
36
+ *
37
+ * This **`name`** is **not** the same as {@link import('./media-channel').LlmOptions.name}
38
+ * (speaker label for LLM). It only selects the TTS key row when LE key catalogs (`legacyTtsKeysByName`, etc.) are present.
39
+ */
7
40
  export interface PlayOptions {
8
- /** Target mixer queue index (0–4). Default: 0. */
41
+ /**
42
+ * Mixer queue index **0–4**. Use separate queues to layer music, earcons, and agent TTS
43
+ * so **`stop(queue)`** does not cut unrelated audio.
44
+ * @defaultValue 0
45
+ */
9
46
  queue?: number;
10
- /** Unique alias for this item — used to remove or track it. */
47
+ /**
48
+ * Stable id for this queue item — used with **`remove`**, debug UIs, and completion tracking.
49
+ * Should be unique per logical utterance if you need to cancel a specific playback.
50
+ */
11
51
  alias?: string;
12
- /** Loop playback until explicitly stopped. */
52
+ /** When `true`, the item restarts after it finishes until **`stop`** / **`remove`**. */
13
53
  loop?: boolean;
14
- /** Delay in milliseconds between loop iterations. */
54
+ /** Milliseconds of silence between loop iterations (if **`loop`**). */
15
55
  loopDelayMs?: number;
16
- /** Queue volume 0.0 (silent) – 1.0 (full). Applied to the target queue for this call. */
56
+ /** Linear gain for this queue **0.0** (mute) – **1.0** (unity). */
17
57
  volume?: number;
18
- /** TTS synthesis strategy: `sentence` | `streaming` | `full` (entire utterance). Default: `sentence`. */
58
+ /** Chunking strategy for TTS; see {@link TtsStrategy}. */
19
59
  ttsStrategy?: TtsStrategy;
20
- /** TTS vendor override. */
60
+ /**
61
+ * Force a specific TTS vendor for this call, overriding **`channel.params.ttsVendor`**.
62
+ * Ignored for **`play()`** when the source is raw audio (no synthesis).
63
+ */
21
64
  ttsVendor?: TtsVendor;
22
- /** Vendor-specific TTS config (voice name, speed, pitch, etc.). */
65
+ /**
66
+ * logic-executor **`key_storage.name`**: use **`authentication_data.legacyTtsKeysByName[name]`**
67
+ * for credentials. Overrides **`defaultTtsName`** on the channel.
68
+ */
69
+ name?: string;
70
+ /**
71
+ * Flat string map passed to the TTS connector (voice id, model, `output_format`, …).
72
+ * Merged after catalog credentials; later wins. The key **`name`** is reserved for the
73
+ * storage-row selector and is removed before sending to the vendor.
74
+ */
23
75
  ttsConfig?: Record<string, string>;
76
+ /**
77
+ * Voctiv platform only: after synthesis, persist audio under **`record_phrase`** + filesystem root so
78
+ * {@link import('./define-script').PlatformApi.getRecords} can return a {@link import('./legacy-phrase').LegacyPhraseRecord}.
79
+ */
80
+ legacySavePhrase?: LegacySavePhraseOptions;
24
81
  }
25
- /** Control interface for a single mixer queue. */
82
+ /**
83
+ * Per-queue mixer control: volume, observability, and manual removal.
84
+ *
85
+ * Obtain via **`channel.audio.queue(index)`**.
86
+ */
26
87
  export interface MixerQueueControl {
27
- /** Queue index (0–4). */
88
+ /** Queue index **0–4** (matches **`PlayOptions.queue`**). */
28
89
  readonly index: number;
29
- /** Current volume (0.0–1.0). Set to change. */
90
+ /** Current linear volume **0.0–1.0**; assign to change gain for this queue. */
30
91
  volume: number;
31
- /** Fires when an item starts playing (emits alias). */
92
+ /** Emits **`alias`** when an item in this queue starts playing. */
32
93
  readonly itemStarted$: Observable<string>;
33
- /** Fires when an item finishes playing (emits alias). */
94
+ /** Emits **`alias`** when an item finishes (natural end or skip). */
34
95
  readonly itemFinished$: Observable<string>;
35
- /** Fires when the queue becomes empty. */
96
+ /** Emits once when the queue has no pending items. */
36
97
  readonly queueEmpty$: Observable<void>;
37
- /** Remove a specific item from this queue by alias. */
98
+ /**
99
+ * Remove a single item by **`alias`**.
100
+ * @param alias - Same string passed in **`PlayOptions.alias`** for that item.
101
+ */
38
102
  remove(alias: string): void;
39
- /** Clear all items from this queue. */
103
+ /** Drop all queued and current items on this queue. */
40
104
  clear(): void;
41
105
  }
42
106
  //# sourceMappingURL=mixer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mixer.d.ts","sourceRoot":"","sources":["../../src/types/mixer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,mDAAmD;AACnD,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,WAAW,GAAG,MAAM,CAAC;AAE5D,6BAA6B;AAC7B,MAAM,MAAM,SAAS,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;AAErD,8CAA8C;AAC9C,MAAM,WAAW,WAAW;IAC1B,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yFAAyF;IACzF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yGAAyG;IACzG,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,2BAA2B;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,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AE,WAAW,CAAC;IAC1B;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;CAC5C;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;IAEf,mEAAmE;IACnE,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAC1C,qEAAqE;IACrE,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAC3C,sDAAsD;IACtD,QAAQ,CAAC,WAAW,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAEvC;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,uDAAuD;IACvD,KAAK,IAAI,IAAI,CAAC;CACf"}
@@ -1,9 +1,23 @@
1
1
  /**
2
- * Virtual text input — pushes text directly into an AsrHandle's streams
3
- * as if ASR recognized it. For automated testing via WS API without real audio.
2
+ * Virtual ASR injection — pushes transcript text into a live {@link import('./asr-handle').AsrHandle}
3
+ * as if the speech recognizer had produced it. Used by WebSocket test clients and automation
4
+ * **without** sending real microphone audio.
5
+ *
6
+ * Methods require the **`asrId`** returned by **`AsrHandle.id`** from **`channel.createAsr()`**.
4
7
  */
5
8
  export interface TextInput {
9
+ /**
10
+ * Inject a **final** transcript for the given ASR instance.
11
+ * @param asrId - Value of **`(await channel.createAsr()).id`**.
12
+ * @param text - Full utterance text (final result).
13
+ */
6
14
  pushResult(asrId: string, text: string): void;
15
+ /**
16
+ * Inject a partial or final hypothesis.
17
+ * @param asrId - Target ASR **`id`**.
18
+ * @param text - Partial or final text.
19
+ * @param isFinal - When `true`, marks this partial as the last before a final (host may align with **`result$`**).
20
+ */
7
21
  pushPartial(asrId: string, text: string, isFinal?: boolean): void;
8
22
  }
9
23
  //# sourceMappingURL=text-input.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"text-input.d.ts","sourceRoot":"","sources":["../../src/types/text-input.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACnE"}
1
+ {"version":3,"file":"text-input.d.ts","sourceRoot":"","sources":["../../src/types/text-input.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACnE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voctiv/agent-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Voctiv TypeScript agent SDK: defineScript and platform types for the voice/dialog scripting runtime.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "",