@voctiv/agent-sdk 0.2.2 → 0.2.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @voctiv/agent-sdk
2
2
 
3
- TypeScript SDK for scripts executed by the `node-asr-tts-connector` scripting runtime.
3
+ TypeScript SDK for scripts executed by the `ScriptEngine` scripting runtime.
4
4
 
5
5
  The package exports the `defineScript()` identity helper and the public runtime types for voice channels, SIP calls, ASR, TTS, VAD, Smart Turn, LLM, dialog context, logging, and Voctiv legacy platform compatibility APIs.
6
6
 
@@ -20,24 +20,53 @@ Scripts export a function created with `defineScript()`. The runtime loads the m
20
20
 
21
21
  ```ts
22
22
  import { defineScript } from '@voctiv/agent-sdk';
23
- import { firstValueFrom } from 'rxjs';
23
+ import { filter, map, merge } from 'rxjs';
24
+
25
+ const TTS_QUEUE = 1;
24
26
 
25
- export default defineScript(async ({ channel, logger, context, platform }) => {
26
- logger.log('Script started', { dialogUuid: context.dialogUuid });
27
+ export default defineScript(async ({ channel, logger, context }) => {
28
+ channel.sip.answer(); // No-op on WS/headless channels.
29
+ channel.sendMessage({ event: 'status', payload: 'ready' });
27
30
 
28
31
  const asr = await channel.createAsr({
29
32
  language: context.language || 'ru-RU',
30
- smartTurn: { enabled: true },
33
+ vad: { preSpeechFrames: 20, postSpeechFrames: 4 },
34
+ smartTurn: { enabled: true, triggerFrames: 3, confirmMs: 50 },
31
35
  });
32
36
 
33
- await channel.audio.say('Hello! How can I help you?');
34
- const userText = await firstValueFrom(asr.result$);
37
+ // Barge-in: user speech stops only the agent TTS queue.
38
+ merge(asr.speechStart$, asr.partial$.pipe(filter((p) => !!p.text?.trim()))).subscribe(() => {
39
+ channel.audio.stop(TTS_QUEUE);
40
+ });
35
41
 
36
- const nlu = await platform.nlu.extract(userText);
37
- logger.log('NLU result', { nlu });
42
+ await channel.audio.say('Hi! Say anything and I will answer briefly.', {
43
+ queue: TTS_QUEUE,
44
+ alias: 'greeting',
45
+ });
38
46
 
39
- asr.destroy();
40
- return { output: { userText, nlu } };
47
+ asr.result$.pipe(filter((text) => !!text.trim())).subscribe((userText) => {
48
+ logger.log('User said', { userText });
49
+
50
+ const reply$ = channel.llm
51
+ .stream(`Reply briefly to the user: "${userText}"`, {
52
+ agentUuid: context.agentUuid,
53
+ dialogUuid: context.dialogUuid,
54
+ })
55
+ .pipe(map((chunk) => chunk.content));
56
+
57
+ void channel.audio.say(reply$, {
58
+ queue: TTS_QUEUE,
59
+ alias: 'reply',
60
+ ttsStrategy: 'sentence',
61
+ });
62
+ });
63
+
64
+ return new Promise((resolve) => {
65
+ channel.events.terminated$.subscribe(() => {
66
+ asr.destroy();
67
+ resolve({ output: { dialogUuid: context.dialogUuid } });
68
+ });
69
+ });
41
70
  });
42
71
  ```
43
72
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @packageDocumentation
3
- * **Agent scripting SDK** for `node-asr-tts-connector`: typed **`defineScript`** context,
3
+ * **Agent scripting SDK** for `ScriptEngine`: typed **`defineScript`** context,
4
4
  * {@link import('./types/media-channel').MediaChannel}, ASR/TTS, LLM, SIP, and Voctiv platform (LE-compat) helpers.
5
5
  * These exports are types plus the `defineScript` identity helper; behavior is provided by
6
6
  * the `apps/api` scripting runtime that loads and executes your script.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /**
3
3
  * @packageDocumentation
4
- * **Agent scripting SDK** for `node-asr-tts-connector`: typed **`defineScript`** context,
4
+ * **Agent scripting SDK** for `ScriptEngine`: typed **`defineScript`** context,
5
5
  * {@link import('./types/media-channel').MediaChannel}, ASR/TTS, LLM, SIP, and Voctiv platform (LE-compat) helpers.
6
6
  * These exports are types plus the `defineScript` identity helper; behavior is provided by
7
7
  * the `apps/api` scripting runtime that loads and executes your script.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voctiv/agent-sdk",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Voctiv TypeScript agent SDK: defineScript and platform types for the voice/dialog scripting runtime.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "",