@onereach/step-voice 7.0.45-VOIC1805.0 → 7.0.45

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.
@@ -22,8 +22,8 @@ class IdleMusic extends voice_1.default {
22
22
  async runStep() {
23
23
  const call = await this.fetchData();
24
24
  const { idleDuration, idleMusicDelay, idleMusicEnabled, customIdleMusic, idleMusicUrl } = this.data;
25
- const idleDurationMs = (0, timestring_1.default)(lodash_1.default.get(idleDuration, 'input', '30s'), lodash_1.default.get(idleDuration, 'outputMode', 'ms'), {});
26
- const idleMusicDelayMs = (0, timestring_1.default)(lodash_1.default.get(idleMusicDelay, 'input', '3s'), lodash_1.default.get(idleMusicDelay, 'outputMode', 'ms'), {});
25
+ const idleDurationMs = (0, timestring_1.default)(lodash_1.default.get(idleDuration, 'input', '30s'), lodash_1.default.get(idleDuration, 'outputMode', 'ms'));
26
+ const idleMusicDelayMs = (0, timestring_1.default)(lodash_1.default.get(idleMusicDelay, 'input', '3s'), lodash_1.default.get(idleMusicDelay, 'outputMode', 'ms'));
27
27
  const { error: validationError } = await schema.validateAsync({
28
28
  idleMusicEnabled,
29
29
  customIdleMusic,
@@ -1,13 +1,10 @@
1
1
  import VoiceStep from './voice';
2
2
  type SystemInstructionMode = 'append' | 'replace' | 'off';
3
- type ToolResponseMode = 'sync' | 'async' | 'none';
4
3
  interface Tool {
5
4
  name: string;
6
5
  description: string;
7
6
  parameters: string | Record<string, unknown>;
8
7
  exitId?: string;
9
- timeout_seconds?: number | string | null;
10
- response_mode?: ToolResponseMode | string | null;
11
8
  }
12
9
  interface AgentServiceConfig {
13
10
  provider: string;
@@ -139,19 +139,12 @@ class UpdateVoiceAgent extends voice_1.default {
139
139
  else if (t.parameters && typeof t.parameters === 'object') {
140
140
  parameters = t.parameters;
141
141
  }
142
- const tool = {
142
+ return {
143
143
  type: 'function',
144
144
  name: lodash_1.default.trim(t.name),
145
145
  description: t.description || '',
146
146
  parameters,
147
147
  };
148
- if (t.timeout_seconds != null && t.timeout_seconds !== '') {
149
- tool.timeout_seconds = Number(t.timeout_seconds);
150
- }
151
- if (t.response_mode) {
152
- tool.response_mode = t.response_mode;
153
- }
154
- return tool;
155
148
  });
156
149
  }
157
150
  buildOptionalServiceOverride(label, service) {
@@ -24,22 +24,16 @@ interface SoftTimeoutConfig {
24
24
  phrases: string[];
25
25
  mode: SoftTimeoutMode;
26
26
  }
27
- type ToolResponseMode = 'sync' | 'async' | 'none';
28
27
  interface Handler {
29
28
  name: string;
30
29
  description: string;
31
30
  parameters: string;
32
31
  feedback?: PerToolConfig;
33
- timeout_seconds?: number | string | null;
34
- response_mode?: ToolResponseMode | string | null;
35
32
  }
36
- interface SubagentTool {
33
+ interface AgentSystemToolConfig {
37
34
  name: string;
38
- description: string;
39
- parameters: string;
40
- feedback?: PerToolConfig;
41
- timeout_seconds?: number | string | null;
42
- response_mode?: ToolResponseMode | string | null;
35
+ description?: string;
36
+ parameters?: Record<string, unknown>;
43
37
  }
44
38
  interface AgentServiceConfig {
45
39
  provider: string;
@@ -47,25 +41,8 @@ interface AgentServiceConfig {
47
41
  api_key?: string;
48
42
  options?: Record<string, unknown>;
49
43
  }
50
- type SubagentContextMode = 'own' | 'shared';
51
- interface Subagent {
52
- id: string;
53
- name: string;
54
- system_instruction: string;
55
- developer_messages?: string[];
56
- context?: SubagentContextMode;
57
- llm?: Partial<AgentServiceConfig> | null;
58
- tools: SubagentTool[];
59
- exitId?: string;
60
- }
61
- interface AgentSystemToolConfig {
62
- name: string;
63
- description?: string;
64
- parameters?: Record<string, unknown>;
65
- }
66
44
  interface INPUT {
67
45
  handlers: Handler[];
68
- subagents: Subagent[];
69
46
  system_instruction: string;
70
47
  developer_messages: string[];
71
48
  greeting_message: string;
@@ -96,11 +73,6 @@ interface INPUT {
96
73
  export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
97
74
  runStep(): Promise<void>;
98
75
  private normalizeIdlePrompts;
99
- private serializeTool;
100
- private serializeSubagents;
101
- private findSubagentForTool;
102
- private findSubagentByName;
103
- private resolveSubagentExit;
104
76
  private findExitByLabel;
105
77
  private validateToolFeedback;
106
78
  private isStepFlagEnabled;
@@ -11,48 +11,21 @@ class VoiceAgent extends voice_1.default {
11
11
  case 'tool_call': {
12
12
  if (event.params.type !== 'tool_call')
13
13
  return;
14
- const name = event.params.name ?? 'tool_call';
15
14
  const cb = this.thread.takeCallback();
15
+ const name = event.params.name ?? 'tool_call';
16
16
  const params = event.params.arguments ?? {};
17
17
  const toolCallId = event.params.toolCallId ?? '';
18
- const payload = {
19
- [name]: params,
20
- name,
21
- toolCallId,
22
- __voicecb: cb,
23
- callId: call.id,
24
- callType: call.type,
25
- callCallback: call.callback
26
- };
27
- const subagent = this.findSubagentForTool(name)
28
- || this.findSubagentByName(event.params.subagent);
29
- if (subagent) {
30
- const exitId = this.resolveSubagentExit(subagent);
31
- if (exitId) {
32
- this.log.info('Voice Agent: routing tool_call to subagent', {
33
- name,
34
- subagent: subagent.name,
35
- exitId
36
- });
37
- this.exitStep(exitId, {
38
- ...payload,
39
- arguments: params,
40
- subagent: subagent.name
41
- }, true);
42
- }
43
- else {
44
- this.log.warn('no exit for subagent tool_call', {
45
- name,
46
- subagent: subagent.name,
47
- exitId: subagent.exitId,
48
- exits: (this.step.exits || []).map((e) => ({ id: e.id, label: e.label }))
49
- });
50
- }
51
- return;
52
- }
53
18
  const exitId = this.findExitByLabel(name) ?? this.getExitStepId('tool_call');
54
19
  if (exitId) {
55
- this.exitStep(exitId, payload, true);
20
+ this.exitStep(exitId, {
21
+ [name]: params,
22
+ name,
23
+ toolCallId,
24
+ __voicecb: cb,
25
+ callId: call.id,
26
+ callType: call.type,
27
+ callCallback: call.callback
28
+ }, true);
56
29
  }
57
30
  else {
58
31
  this.log.warn('no exit for tool_call', { name });
@@ -79,11 +52,34 @@ class VoiceAgent extends voice_1.default {
79
52
  }
80
53
  });
81
54
  this.triggers.otherwise(async () => {
82
- const { handlers = [], subagents = [], 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 = '', dtmf_enabled = false, dtmf_timeout = 2, dtmf_termination_digit = '#', dtmf_prefix = 'DTMF: ', custom_config_enabled = false, agent_url_overwritten = false, tool_feedback, soft_timeout, system_tools, agent_url = '', mode = '', stt = {}, llm = {}, tts = {}, realtime = {} } = this.data;
55
+ 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 = '', dtmf_enabled = false, dtmf_timeout = 2, dtmf_termination_digit = '#', dtmf_prefix = 'DTMF: ', custom_config_enabled = false, agent_url_overwritten = false, tool_feedback, soft_timeout, system_tools, agent_url = '', mode = '', stt = {}, llm = {}, tts = {}, realtime = {} } = this.data;
83
56
  if (lodash_1.default.isEmpty(system_instruction)) {
84
57
  this.throwError(new Error('Voice Agent: system instruction is required'));
85
58
  }
86
- const tools = handlers.map(h => this.serializeTool(h));
59
+ const tools = handlers.map(h => {
60
+ let parameters = h.parameters;
61
+ if (typeof parameters === 'string') {
62
+ try {
63
+ parameters = JSON.parse(parameters);
64
+ }
65
+ catch {
66
+ parameters = {};
67
+ }
68
+ }
69
+ const tool = {
70
+ type: 'function',
71
+ name: h.name,
72
+ description: h.description,
73
+ parameters: parameters || {}
74
+ };
75
+ if (h.feedback != null) {
76
+ const validatedFeedback = this.validatePerToolFeedback(h.feedback, h.name);
77
+ if (validatedFeedback) {
78
+ tool.feedback = validatedFeedback;
79
+ }
80
+ }
81
+ return tool;
82
+ });
87
83
  const config = {
88
84
  system_instruction,
89
85
  developer_messages,
@@ -91,10 +87,6 @@ class VoiceAgent extends voice_1.default {
91
87
  prevent_greeting_interruption,
92
88
  tools
93
89
  };
94
- const serializedSubagents = this.serializeSubagents(subagents) || [];
95
- if (serializedSubagents.length > 0) {
96
- config.subagents = serializedSubagents;
97
- }
98
90
  if (this.isStepFlagEnabled(idle_detection_enabled)) {
99
91
  const timeoutSecs = Number(idle_timeout_secs);
100
92
  const maxRetries = Number(idle_max_retries);
@@ -168,83 +160,8 @@ class VoiceAgent extends voice_1.default {
168
160
  .map(item => typeof item === 'string' ? item : item?.prompt ?? '')
169
161
  .filter(prompt => !lodash_1.default.isEmpty(lodash_1.default.trim(String(prompt))));
170
162
  }
171
- serializeTool(h) {
172
- let parameters = h.parameters;
173
- if (typeof parameters === 'string') {
174
- try {
175
- parameters = JSON.parse(parameters);
176
- }
177
- catch {
178
- parameters = {};
179
- }
180
- }
181
- const tool = {
182
- type: 'function',
183
- name: h.name,
184
- description: h.description,
185
- parameters: parameters || {}
186
- };
187
- if (h.feedback != null) {
188
- const validatedFeedback = this.validatePerToolFeedback(h.feedback, h.name);
189
- if (validatedFeedback) {
190
- tool.feedback = validatedFeedback;
191
- }
192
- }
193
- if (h.timeout_seconds != null && h.timeout_seconds !== '') {
194
- tool.timeout_seconds = Number(h.timeout_seconds);
195
- }
196
- if (h.response_mode) {
197
- tool.response_mode = h.response_mode;
198
- }
199
- return tool;
200
- }
201
- serializeSubagents(subagents) {
202
- if (!Array.isArray(subagents))
203
- return [];
204
- return subagents
205
- .filter(sa => sa != null && !lodash_1.default.isEmpty(lodash_1.default.trim(sa.name)))
206
- .map(sa => {
207
- const name = lodash_1.default.trim(sa.name);
208
- const serialized = {
209
- name,
210
- system_instruction: sa.system_instruction || '',
211
- developer_messages: (sa.developer_messages || [])
212
- .map(msg => typeof msg === 'string' ? msg : '')
213
- .filter(msg => !lodash_1.default.isEmpty(lodash_1.default.trim(msg))),
214
- context: sa.context === 'shared' ? 'shared' : 'own',
215
- tools: (sa.tools || [])
216
- .filter(t => t != null && !lodash_1.default.isEmpty(lodash_1.default.trim(t.name)))
217
- .map(t => this.serializeTool(t))
218
- };
219
- const llm = this.buildAgentServiceConfig(`subagent "${name}" llm`, sa.llm || {});
220
- if (llm)
221
- serialized.llm = llm;
222
- return serialized;
223
- });
224
- }
225
- findSubagentForTool(toolName) {
226
- const needle = lodash_1.default.trim(toolName);
227
- if (!needle)
228
- return undefined;
229
- const subagents = this.data.subagents || [];
230
- return subagents.find(sa => (sa?.tools || []).some(t => t && lodash_1.default.trim(String(t.name || '')) === needle));
231
- }
232
- findSubagentByName(name) {
233
- if (typeof name !== 'string' || lodash_1.default.isEmpty(lodash_1.default.trim(name)))
234
- return undefined;
235
- const trimmed = lodash_1.default.trim(name);
236
- return (this.data.subagents || []).find(sa => lodash_1.default.trim(sa?.name || '') === trimmed);
237
- }
238
- resolveSubagentExit(subagent) {
239
- if (subagent.exitId && this.getExitStepId(subagent.exitId, false)) {
240
- return subagent.exitId;
241
- }
242
- const name = lodash_1.default.trim(subagent.name || '');
243
- return this.findExitByLabel(`subagent_${name}`) || this.findExitByLabel(name);
244
- }
245
163
  findExitByLabel(label) {
246
- const needle = lodash_1.default.trim(label);
247
- const exit = lodash_1.default.find(this.step.exits, (e) => lodash_1.default.trim(e.label || '') === needle);
164
+ const exit = lodash_1.default.find(this.step.exits, (e) => e.label === label);
248
165
  return exit?.id;
249
166
  }
250
167
  validateToolFeedback(config) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/step-voice",
3
- "version": "7.0.45-VOIC1805.0",
3
+ "version": "7.0.45",
4
4
  "author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
5
5
  "contributors": [
6
6
  "Roman Zolotarov",
@@ -16,7 +16,6 @@
16
16
  "@onereach/step-conversation": "^1.0.40",
17
17
  "lodash": "^4.17.21",
18
18
  "nanoid": "^3.3.4",
19
- "timestring": "^6.0.0",
20
19
  "uuid": "^9.0.0"
21
20
  },
22
21
  "devDependencies": {
@@ -1,11 +0,0 @@
1
- import VoiceStep from './voice';
2
- interface INPUT {
3
- subagentName?: string;
4
- }
5
- export default class SubagentToolsHandler extends VoiceStep<Partial<INPUT>> {
6
- runStep(): Promise<void>;
7
- private loadToolCallContext;
8
- private findExitByLabel;
9
- exitToThread(): Promise<void>;
10
- }
11
- export {};
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
5
- const voice_1 = tslib_1.__importDefault(require("./voice"));
6
- class SubagentToolsHandler extends voice_1.default {
7
- async runStep() {
8
- const call = await this.fetchData();
9
- const ctx = await this.loadToolCallContext();
10
- const toolName = lodash_1.default.trim(String(ctx.name ?? ''));
11
- const subagentName = lodash_1.default.trim(String(ctx.subagent ?? this.data.subagentName ?? ''));
12
- const arguments_ = (ctx.arguments && typeof ctx.arguments === 'object')
13
- ? ctx.arguments
14
- : (ctx[toolName] ?? {});
15
- const exitId = toolName ? this.findExitByLabel(toolName) : undefined;
16
- this.log.info('Subagent Tools Handler: incoming tool_call', {
17
- toolName,
18
- subagent: subagentName,
19
- exitId,
20
- threadId: this.thread.id,
21
- hasContext: !lodash_1.default.isEmpty(ctx)
22
- });
23
- if (!exitId) {
24
- this.log.warn('Subagent Tools Handler: no exit for tool_call', {
25
- name: toolName,
26
- subagent: subagentName,
27
- exits: (this.step.exits || []).map((e) => e.label)
28
- });
29
- this.exitFlow();
30
- return;
31
- }
32
- // Same hop as Voice Agent → tool: fork so Voice Agent Tool Result still
33
- // finds __voiceAgentContext_ on the child thread. Do not exitFlow() after
34
- // this — that would tear down the parent before the tool thread starts.
35
- await this.exitStep(exitId, {
36
- [toolName]: arguments_,
37
- name: toolName,
38
- toolCallId: ctx.toolCallId ?? '',
39
- arguments: arguments_,
40
- subagent: subagentName,
41
- __voicecb: ctx.__voicecb,
42
- callId: ctx.callId ?? call.id,
43
- callType: ctx.callType ?? call.type,
44
- callCallback: ctx.callCallback ?? call.callback
45
- }, true);
46
- }
47
- async loadToolCallContext() {
48
- const fromState = (this.state?.result && typeof this.state.result === 'object')
49
- ? this.state.result
50
- : {};
51
- let fromThread = {};
52
- try {
53
- const stored = await this.thread.get(`__voiceAgentContext_${this.thread.id}`);
54
- if (stored && typeof stored === 'object')
55
- fromThread = stored;
56
- }
57
- catch {
58
- // key absent on this thread — Voice Agent payload may still be in state.result
59
- }
60
- return { ...fromState, ...fromThread };
61
- }
62
- findExitByLabel(label) {
63
- const needle = lodash_1.default.trim(label);
64
- const exit = lodash_1.default.find(this.step.exits, (e) => lodash_1.default.trim(e.label || '') === needle);
65
- return exit?.id;
66
- }
67
- async exitToThread() {
68
- const result = this.state.result;
69
- await this.thread.set(`__voiceAgentContext_${this.thread.id}`, result);
70
- this.thread.exitStep(this.state.exitStep, result);
71
- }
72
- }
73
- exports.default = SubagentToolsHandler;