@onereach/step-voice 7.0.25-VOIC1724.0 → 7.0.25
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/dst/Voice Agent.d.ts +9 -0
- package/dst/Voice Agent.js +32 -12
- package/package.json +1 -1
package/dst/Voice Agent.d.ts
CHANGED
|
@@ -16,6 +16,13 @@ interface INPUT {
|
|
|
16
16
|
developer_messages: string[];
|
|
17
17
|
greeting_message: string;
|
|
18
18
|
prevent_greeting_interruption: boolean;
|
|
19
|
+
idle_detection_enabled: boolean;
|
|
20
|
+
idle_timeout_secs: number | string;
|
|
21
|
+
idle_max_retries: number | string;
|
|
22
|
+
idle_prompts: Array<string | {
|
|
23
|
+
prompt?: string;
|
|
24
|
+
}>;
|
|
25
|
+
idle_goodbye_message: string;
|
|
19
26
|
custom_config_enabled: boolean;
|
|
20
27
|
agent_url_overwritten: boolean;
|
|
21
28
|
agent_url: string;
|
|
@@ -27,7 +34,9 @@ interface INPUT {
|
|
|
27
34
|
}
|
|
28
35
|
export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
|
|
29
36
|
runStep(): Promise<void>;
|
|
37
|
+
private normalizeIdlePrompts;
|
|
30
38
|
private findExitByLabel;
|
|
39
|
+
private isStepFlagEnabled;
|
|
31
40
|
private isValidAgentUrl;
|
|
32
41
|
private buildAgentServiceConfig;
|
|
33
42
|
private parseAgentServiceOptions;
|
package/dst/Voice Agent.js
CHANGED
|
@@ -34,7 +34,7 @@ class VoiceAgent extends voice_1.default {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
this.triggers.otherwise(async () => {
|
|
37
|
-
const { handlers = [], system_instruction = '', developer_messages = [], greeting_message = '', prevent_greeting_interruption = false, custom_config_enabled = false, agent_url_overwritten = false, agent_url = '', mode = '', stt = {}, llm = {}, tts = {}, realtime = {} } = this.data;
|
|
37
|
+
const { handlers = [], system_instruction = '', developer_messages = [], greeting_message = '', prevent_greeting_interruption = false, idle_detection_enabled = false, idle_timeout_secs = 8, idle_max_retries = 3, idle_prompts = [], idle_goodbye_message = '', custom_config_enabled = false, agent_url_overwritten = false, agent_url = '', mode = '', stt = {}, llm = {}, tts = {}, realtime = {} } = this.data;
|
|
38
38
|
if (lodash_1.default.isEmpty(system_instruction)) {
|
|
39
39
|
this.throwError(new Error('Voice Agent: system instruction is required'));
|
|
40
40
|
}
|
|
@@ -57,15 +57,27 @@ class VoiceAgent extends voice_1.default {
|
|
|
57
57
|
prevent_greeting_interruption,
|
|
58
58
|
tools
|
|
59
59
|
};
|
|
60
|
+
if (this.isStepFlagEnabled(idle_detection_enabled)) {
|
|
61
|
+
const timeoutSecs = Number(idle_timeout_secs);
|
|
62
|
+
const maxRetries = Number(idle_max_retries);
|
|
63
|
+
const prompts = this.normalizeIdlePrompts(idle_prompts);
|
|
64
|
+
config.idle_detection = {
|
|
65
|
+
enabled: true,
|
|
66
|
+
timeout_secs: timeoutSecs,
|
|
67
|
+
max_retries: maxRetries,
|
|
68
|
+
prompts,
|
|
69
|
+
goodbye_message: lodash_1.default.isEmpty(lodash_1.default.trim(idle_goodbye_message)) ? undefined : idle_goodbye_message
|
|
70
|
+
};
|
|
71
|
+
}
|
|
60
72
|
let agentCustomUrl = '';
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!this.isValidAgentUrl(agent_url)) {
|
|
65
|
-
this.throwError(new Error(`Voice Agent: invalid agent url "${agent_url}"`));
|
|
66
|
-
}
|
|
67
|
-
agentCustomUrl = agent_url;
|
|
73
|
+
if (this.isStepFlagEnabled(agent_url_overwritten)) {
|
|
74
|
+
if (!this.isValidAgentUrl(agent_url)) {
|
|
75
|
+
this.throwError(new Error(`Voice Agent: invalid agent url "${agent_url}"`));
|
|
68
76
|
}
|
|
77
|
+
agentCustomUrl = agent_url;
|
|
78
|
+
}
|
|
79
|
+
if (this.isStepFlagEnabled(custom_config_enabled)) {
|
|
80
|
+
config.mode = mode;
|
|
69
81
|
switch (mode) {
|
|
70
82
|
case "waterfall" /* AgentPipelineMode.WATERFALL */:
|
|
71
83
|
config.stt = this.buildAgentServiceConfig('stt', stt);
|
|
@@ -79,18 +91,26 @@ class VoiceAgent extends voice_1.default {
|
|
|
79
91
|
this.throwError(new Error(`Voice Agent: unknown mode "${mode}"`));
|
|
80
92
|
}
|
|
81
93
|
}
|
|
82
|
-
const params = {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
94
|
+
const params = { config };
|
|
95
|
+
if (agentCustomUrl) {
|
|
96
|
+
params.url = agentCustomUrl;
|
|
97
|
+
}
|
|
86
98
|
await this.sendCommands(call, [{ name: 'startAgent', params }]);
|
|
87
99
|
return this.exitFlow();
|
|
88
100
|
});
|
|
89
101
|
}
|
|
102
|
+
normalizeIdlePrompts(idlePrompts) {
|
|
103
|
+
return (idlePrompts || [])
|
|
104
|
+
.map(item => typeof item === 'string' ? item : item?.prompt ?? '')
|
|
105
|
+
.filter(prompt => !lodash_1.default.isEmpty(lodash_1.default.trim(String(prompt))));
|
|
106
|
+
}
|
|
90
107
|
findExitByLabel(label) {
|
|
91
108
|
const exit = lodash_1.default.find(this.step.exits, (e) => e.label === label);
|
|
92
109
|
return exit?.id;
|
|
93
110
|
}
|
|
111
|
+
isStepFlagEnabled(value) {
|
|
112
|
+
return value === true || value === 'true';
|
|
113
|
+
}
|
|
94
114
|
isValidAgentUrl(value) {
|
|
95
115
|
return /^wss?:\/\/([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+|\[[a-fA-F0-9:]+\])(:\d+)?(\/\S*)?$/.test(value);
|
|
96
116
|
}
|