@onereach/step-voice 7.0.22-voiceagent.2 → 7.0.22
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 +20 -1
- package/dst/Voice Agent.js +66 -8
- package/package.json +1 -1
package/dst/Voice Agent.d.ts
CHANGED
|
@@ -4,15 +4,34 @@ interface Handler {
|
|
|
4
4
|
description: string;
|
|
5
5
|
parameters: string;
|
|
6
6
|
}
|
|
7
|
+
interface AgentServiceConfig {
|
|
8
|
+
provider: string;
|
|
9
|
+
model: string;
|
|
10
|
+
api_key?: string;
|
|
11
|
+
options?: Record<string, unknown>;
|
|
12
|
+
}
|
|
7
13
|
interface INPUT {
|
|
8
|
-
url: string;
|
|
9
14
|
handlers: Handler[];
|
|
10
15
|
system_instruction: string;
|
|
11
16
|
developer_messages: string[];
|
|
17
|
+
greeting_message: string;
|
|
18
|
+
prevent_greeting_interruption: boolean;
|
|
19
|
+
custom_config_enabled: boolean;
|
|
20
|
+
agent_url_overwritten: boolean;
|
|
21
|
+
agent_url: string;
|
|
22
|
+
ssl_enabled: boolean;
|
|
23
|
+
mode: string;
|
|
24
|
+
stt: Partial<AgentServiceConfig>;
|
|
25
|
+
llm: Partial<AgentServiceConfig>;
|
|
26
|
+
tts: Partial<AgentServiceConfig>;
|
|
27
|
+
realtime: Partial<AgentServiceConfig>;
|
|
12
28
|
}
|
|
13
29
|
export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
|
|
14
30
|
runStep(): Promise<void>;
|
|
15
31
|
private findExitByLabel;
|
|
32
|
+
private isValidAgentUrl;
|
|
33
|
+
private buildAgentServiceConfig;
|
|
34
|
+
private parseAgentServiceOptions;
|
|
16
35
|
exitToThread(): Promise<void>;
|
|
17
36
|
}
|
|
18
37
|
export {};
|
package/dst/Voice Agent.js
CHANGED
|
@@ -34,8 +34,7 @@ class VoiceAgent extends voice_1.default {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
this.triggers.otherwise(async () => {
|
|
37
|
-
const {
|
|
38
|
-
handlers = [], system_instruction = '', developer_messages = [] } = this.data;
|
|
37
|
+
const { handlers = [], system_instruction = '', developer_messages = [], greeting_message = '', prevent_greeting_interruption = false, custom_config_enabled = false, agent_url_overwritten = false, agent_url = '', ssl_enabled = true, mode = '', stt = {}, llm = {}, tts = {}, realtime = {} } = this.data;
|
|
39
38
|
const tools = handlers.map(h => {
|
|
40
39
|
let parameters = h.parameters;
|
|
41
40
|
if (typeof parameters === 'string') {
|
|
@@ -48,13 +47,38 @@ class VoiceAgent extends voice_1.default {
|
|
|
48
47
|
}
|
|
49
48
|
return { type: 'function', name: h.name, description: h.description, parameters: parameters || {} };
|
|
50
49
|
});
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
const config = {
|
|
51
|
+
system_instruction,
|
|
52
|
+
developer_messages,
|
|
53
|
+
greeting_message,
|
|
54
|
+
prevent_greeting_interruption,
|
|
55
|
+
tools
|
|
56
|
+
};
|
|
57
|
+
let agentCustomUrl;
|
|
58
|
+
if (custom_config_enabled) {
|
|
59
|
+
config.mode = mode;
|
|
60
|
+
if (agent_url_overwritten) {
|
|
61
|
+
if (!this.isValidAgentUrl(agent_url)) {
|
|
62
|
+
this.throwError(new Error(`Voice Agent: invalid agent url "${agent_url}"`));
|
|
63
|
+
}
|
|
64
|
+
agentCustomUrl = `${ssl_enabled ? 'wss' : 'ws'}://${agent_url}`;
|
|
57
65
|
}
|
|
66
|
+
switch (mode) {
|
|
67
|
+
case "waterfall" /* AgentPipelineMode.WATERFALL */:
|
|
68
|
+
config.asr = this.buildAgentServiceConfig('stt', stt);
|
|
69
|
+
config.llm = this.buildAgentServiceConfig('llm', llm);
|
|
70
|
+
config.tts = this.buildAgentServiceConfig('tts', tts);
|
|
71
|
+
break;
|
|
72
|
+
case "realtime" /* AgentPipelineMode.REALTIME */:
|
|
73
|
+
config.realtime = this.buildAgentServiceConfig('realtime', realtime);
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
this.throwError(new Error(`Voice Agent: unknown mode "${mode}"`));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const params = {
|
|
80
|
+
url: agentCustomUrl,
|
|
81
|
+
config
|
|
58
82
|
};
|
|
59
83
|
await this.sendCommands(call, [{ name: 'startAgent', params }]);
|
|
60
84
|
return this.exitFlow();
|
|
@@ -64,6 +88,40 @@ class VoiceAgent extends voice_1.default {
|
|
|
64
88
|
const exit = lodash_1.default.find(this.step.exits, (e) => e.label === label);
|
|
65
89
|
return exit?.id;
|
|
66
90
|
}
|
|
91
|
+
isValidAgentUrl(value) {
|
|
92
|
+
if (lodash_1.default.isEmpty(value))
|
|
93
|
+
return true;
|
|
94
|
+
return /^([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*|\[[a-fA-F0-9:]+\])(:\d+)?$/.test(value);
|
|
95
|
+
}
|
|
96
|
+
buildAgentServiceConfig(label, service) {
|
|
97
|
+
if (lodash_1.default.isEmpty(service.provider))
|
|
98
|
+
return;
|
|
99
|
+
if (!lodash_1.default.isEmpty(service.provider) && lodash_1.default.isEmpty(service.model)) {
|
|
100
|
+
this.throwError(new Error(`Voice Agent: model is required for ${label} provider "${service.provider ?? ''}"`));
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
provider: service.provider ?? '',
|
|
104
|
+
model: service.model ?? '',
|
|
105
|
+
api_key: lodash_1.default.isEmpty(service.api_key) ? undefined : service.api_key,
|
|
106
|
+
options: this.parseAgentServiceOptions(label, service.options)
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
parseAgentServiceOptions(label, options) {
|
|
110
|
+
if (options == null || options === '')
|
|
111
|
+
return undefined;
|
|
112
|
+
if (typeof options === 'string') {
|
|
113
|
+
try {
|
|
114
|
+
options = JSON.parse(options);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
this.throwError(new Error(`Voice Agent: invalid options JSON for ${label}`));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (typeof options !== 'object' || Array.isArray(options)) {
|
|
121
|
+
this.throwError(new Error(`Voice Agent: options for ${label} must be a JSON object`));
|
|
122
|
+
}
|
|
123
|
+
return options;
|
|
124
|
+
}
|
|
67
125
|
async exitToThread() {
|
|
68
126
|
await this.thread.set('__voiceAgentContext', this.state.result);
|
|
69
127
|
this.thread.exitStep(this.state.exitStep, this.state.result);
|