@onereach/step-voice 7.0.22-voiceagent.1 → 7.0.22-voiceagent.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.
@@ -10,7 +10,7 @@ class VoiceAgentFunctionResult extends voice_1.default {
10
10
  if (!callId) {
11
11
  throw new Error('Voice Agent Function Result: missing call context (must be placed on a Voice Agent function exit)');
12
12
  }
13
- this.log.error("Voice Agent Function Result Params", ctx);
13
+ this.log.info("Voice Agent Function Result Params", ctx);
14
14
  const params = {
15
15
  functionName: functionName,
16
16
  functionId: functionId,
@@ -27,7 +27,7 @@ class VoiceAgentFunctionResult extends voice_1.default {
27
27
  commands: [{ name: 'agentFunctionResult', params }]
28
28
  }
29
29
  };
30
- this.log.error("Voice Agent Function Result", event);
30
+ this.log.info("Voice Agent Function Result", event);
31
31
  await this.thread.eventManager.emit(event, {
32
32
  target: callCallback,
33
33
  invocationType: 'async',
@@ -4,15 +4,31 @@ 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
+ custom_config_enabled: boolean;
18
+ agent_url_overwritten: boolean;
19
+ agent_url: string;
20
+ mode: string;
21
+ stt: Partial<AgentServiceConfig>;
22
+ llm: Partial<AgentServiceConfig>;
23
+ tts: Partial<AgentServiceConfig>;
24
+ realtime: Partial<AgentServiceConfig>;
12
25
  }
13
26
  export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
14
27
  runStep(): Promise<void>;
15
28
  private findExitByLabel;
29
+ private isValidAgentUrl;
30
+ private buildAgentServiceConfig;
31
+ private parseAgentServiceOptions;
16
32
  exitToThread(): Promise<void>;
17
33
  }
18
34
  export {};
@@ -34,8 +34,7 @@ class VoiceAgent extends voice_1.default {
34
34
  }
35
35
  });
36
36
  this.triggers.otherwise(async () => {
37
- const { url = "", // optional, default value configured on a voicer side
38
- handlers = [], system_instruction = '', developer_messages = [] } = this.data;
37
+ const { handlers = [], system_instruction = '', developer_messages = [], custom_config_enabled = false, agent_url_overwritten = false, agent_url = '', 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,36 @@ 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 params = {
52
- url,
53
- config: {
54
- system_instruction,
55
- developer_messages,
56
- tools,
50
+ const config = {
51
+ system_instruction,
52
+ developer_messages,
53
+ tools
54
+ };
55
+ let agentCustomUrl = '';
56
+ if (custom_config_enabled) {
57
+ config.mode = mode;
58
+ if (agent_url_overwritten) {
59
+ if (!this.isValidAgentUrl(agent_url)) {
60
+ this.throwError(new Error(`Voice Agent: invalid agent url "${agent_url}"`));
61
+ }
62
+ agentCustomUrl = agent_url;
57
63
  }
64
+ switch (mode) {
65
+ case "waterfall" /* AgentPipelineMode.WATERFALL */:
66
+ config.asr = this.buildAgentServiceConfig('stt', stt);
67
+ config.llm = this.buildAgentServiceConfig('llm', llm);
68
+ config.tts = this.buildAgentServiceConfig('tts', tts);
69
+ break;
70
+ case "realtime" /* AgentPipelineMode.REALTIME */:
71
+ config.realtime = this.buildAgentServiceConfig('realtime', realtime);
72
+ break;
73
+ default:
74
+ this.throwError(new Error(`Voice Agent: unknown mode "${mode}"`));
75
+ }
76
+ }
77
+ const params = {
78
+ url: agentCustomUrl,
79
+ config
58
80
  };
59
81
  await this.sendCommands(call, [{ name: 'startAgent', params }]);
60
82
  return this.exitFlow();
@@ -64,6 +86,38 @@ class VoiceAgent extends voice_1.default {
64
86
  const exit = lodash_1.default.find(this.step.exits, (e) => e.label === label);
65
87
  return exit?.id;
66
88
  }
89
+ isValidAgentUrl(value) {
90
+ return /^wss?:\/\/([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+|\[[a-fA-F0-9:]+\])(:\d+)?(\/\S*)?$/.test(value);
91
+ }
92
+ buildAgentServiceConfig(label, service) {
93
+ if (lodash_1.default.isEmpty(service.provider))
94
+ return;
95
+ if (!lodash_1.default.isEmpty(service.provider) && lodash_1.default.isEmpty(service.model)) {
96
+ this.throwError(new Error(`Voice Agent: model is required for ${label} provider "${service.provider ?? ''}"`));
97
+ }
98
+ return {
99
+ provider: service.provider ?? '',
100
+ model: service.model ?? '',
101
+ api_key: lodash_1.default.isEmpty(service.api_key) ? undefined : service.api_key,
102
+ options: this.parseAgentServiceOptions(label, service.options)
103
+ };
104
+ }
105
+ parseAgentServiceOptions(label, options) {
106
+ if (options == null || options === '')
107
+ return undefined;
108
+ if (typeof options === 'string') {
109
+ try {
110
+ options = JSON.parse(options);
111
+ }
112
+ catch {
113
+ this.throwError(new Error(`Voice Agent: invalid options JSON for ${label}`));
114
+ }
115
+ }
116
+ if (typeof options !== 'object' || Array.isArray(options)) {
117
+ this.throwError(new Error(`Voice Agent: options for ${label} must be a JSON object`));
118
+ }
119
+ return options;
120
+ }
67
121
  async exitToThread() {
68
122
  await this.thread.set('__voiceAgentContext', this.state.result);
69
123
  this.thread.exitStep(this.state.exitStep, this.state.result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/step-voice",
3
- "version": "7.0.22-voiceagent.1",
3
+ "version": "7.0.22-voiceagent.3",
4
4
  "author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
5
5
  "contributors": [
6
6
  "Roman Zolotarov",