@onereach/step-voice 7.0.41-tooltimeoutresponsemode.3 → 7.0.41

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.
@@ -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;
@@ -41,7 +38,5 @@ export default class UpdateVoiceAgent extends VoiceStep<Partial<INPUT>> {
41
38
  private buildOptionalServiceOverride;
42
39
  private parseAgentServiceOptions;
43
40
  private isStepFlagEnabled;
44
- private validateToolTimeout;
45
- private validateToolResponseMode;
46
41
  }
47
42
  export {};
@@ -139,21 +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
- const validatedTimeout = this.validateToolTimeout(t.timeout_seconds, t.name);
149
- if (validatedTimeout != null) {
150
- tool.timeout_seconds = validatedTimeout;
151
- }
152
- const validatedResponseMode = this.validateToolResponseMode(t.response_mode, t.name);
153
- if (validatedResponseMode != null) {
154
- tool.response_mode = validatedResponseMode;
155
- }
156
- return tool;
157
148
  });
158
149
  }
159
150
  buildOptionalServiceOverride(label, service) {
@@ -191,25 +182,5 @@ class UpdateVoiceAgent extends voice_1.default {
191
182
  isStepFlagEnabled(value) {
192
183
  return value === true || value === 'true' || value === 1 || value === '1';
193
184
  }
194
- validateToolTimeout(value, toolName) {
195
- if (value == null || value === '')
196
- return null;
197
- const timeout = Number(value);
198
- if (!Number.isFinite(timeout) || timeout < 1 || timeout > 300) {
199
- this.log.warn(`Update Voice Agent: invalid timeout_seconds for tool "${toolName}" (must be 1–300) — excluded`);
200
- return null;
201
- }
202
- return timeout;
203
- }
204
- validateToolResponseMode(value, toolName) {
205
- if (value == null || value === '')
206
- return null;
207
- const valid = ['sync', 'async', 'none'];
208
- if (!valid.includes(value)) {
209
- this.log.warn(`Update Voice Agent: invalid response_mode for tool "${toolName}" (must be sync/async/none) — excluded`);
210
- return null;
211
- }
212
- return value;
213
- }
214
185
  }
215
186
  exports.default = UpdateVoiceAgent;
@@ -24,20 +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;
35
+ description?: string;
36
+ parameters?: Record<string, unknown>;
41
37
  }
42
38
  interface AgentServiceConfig {
43
39
  provider: string;
@@ -45,25 +41,8 @@ interface AgentServiceConfig {
45
41
  api_key?: string;
46
42
  options?: Record<string, unknown>;
47
43
  }
48
- type SubagentContextMode = 'own' | 'shared';
49
- interface Subagent {
50
- id: string;
51
- name: string;
52
- system_instruction: string;
53
- developer_messages?: string[];
54
- context?: SubagentContextMode;
55
- llm?: Partial<AgentServiceConfig> | null;
56
- tools: SubagentTool[];
57
- exitId?: string;
58
- }
59
- interface AgentSystemToolConfig {
60
- name: string;
61
- description?: string;
62
- parameters?: Record<string, unknown>;
63
- }
64
44
  interface INPUT {
65
45
  handlers: Handler[];
66
- subagents: Subagent[];
67
46
  system_instruction: string;
68
47
  developer_messages: string[];
69
48
  greeting_message: string;
@@ -93,16 +72,7 @@ interface INPUT {
93
72
  }
94
73
  export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
95
74
  runStep(): Promise<void>;
96
- /**
97
- * Fork a thread per subagent exit so Subagent Tools Handler steps can
98
- * register tool_call listeners immediately after agent start.
99
- */
100
- private spawnSubagentHandlerThreads;
101
75
  private normalizeIdlePrompts;
102
- private serializeTool;
103
- private serializeSubagents;
104
- private isSubagentExitLabel;
105
- private isSubagentTool;
106
76
  private findExitByLabel;
107
77
  private validateToolFeedback;
108
78
  private isStepFlagEnabled;
@@ -112,8 +82,6 @@ export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
112
82
  private validateSoftTimeout;
113
83
  private validateSystemTools;
114
84
  private parseAgentServiceOptions;
115
- private validateToolTimeout;
116
- private validateToolResponseMode;
117
85
  exitToThread(): Promise<void>;
118
86
  }
119
87
  export {};
@@ -11,12 +11,8 @@ 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
- // Subagent tools are handled by pre-spawned Subagent Tools Handler threads.
16
- if (event.params.subagent || this.isSubagentTool(name) || this.isSubagentExitLabel(name)) {
17
- return;
18
- }
19
14
  const cb = this.thread.takeCallback();
15
+ const name = event.params.name ?? 'tool_call';
20
16
  const params = event.params.arguments ?? {};
21
17
  const toolCallId = event.params.toolCallId ?? '';
22
18
  const exitId = this.findExitByLabel(name) ?? this.getExitStepId('tool_call');
@@ -56,11 +52,34 @@ class VoiceAgent extends voice_1.default {
56
52
  }
57
53
  });
58
54
  this.triggers.otherwise(async () => {
59
- 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;
60
56
  if (lodash_1.default.isEmpty(system_instruction)) {
61
57
  this.throwError(new Error('Voice Agent: system instruction is required'));
62
58
  }
63
- 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
+ });
64
83
  const config = {
65
84
  system_instruction,
66
85
  developer_messages,
@@ -68,10 +87,6 @@ class VoiceAgent extends voice_1.default {
68
87
  prevent_greeting_interruption,
69
88
  tools
70
89
  };
71
- const serializedSubagents = this.serializeSubagents(subagents) || [];
72
- if (serializedSubagents.length > 0) {
73
- config.subagents = serializedSubagents;
74
- }
75
90
  if (this.isStepFlagEnabled(idle_detection_enabled)) {
76
91
  const timeoutSecs = Number(idle_timeout_secs);
77
92
  const maxRetries = Number(idle_max_retries);
@@ -137,108 +152,14 @@ class VoiceAgent extends voice_1.default {
137
152
  params.url = agentCustomUrl;
138
153
  }
139
154
  await this.sendCommands(call, [{ name: 'startAgent', params }]);
140
- this.spawnSubagentHandlerThreads(call, subagents);
141
155
  return this.exitFlow();
142
156
  });
143
157
  }
144
- /**
145
- * Fork a thread per subagent exit so Subagent Tools Handler steps can
146
- * register tool_call listeners immediately after agent start.
147
- */
148
- spawnSubagentHandlerThreads(call, subagents) {
149
- if (!Array.isArray(subagents) || subagents.length === 0)
150
- return;
151
- for (const sa of subagents) {
152
- const name = lodash_1.default.trim(sa?.name || '');
153
- if (!name)
154
- continue;
155
- const exitId = sa.exitId || this.findExitByLabel(`subagent_${name}`);
156
- if (!exitId) {
157
- this.log.warn('Voice Agent: no exit for subagent; handler thread not started', { name });
158
- continue;
159
- }
160
- this.exitStep(exitId, {
161
- name,
162
- subagent: name,
163
- callId: call.id,
164
- callType: call.type,
165
- callCallback: call.callback
166
- }, true);
167
- }
168
- }
169
158
  normalizeIdlePrompts(idlePrompts) {
170
159
  return (idlePrompts || [])
171
160
  .map(item => typeof item === 'string' ? item : item?.prompt ?? '')
172
161
  .filter(prompt => !lodash_1.default.isEmpty(lodash_1.default.trim(String(prompt))));
173
162
  }
174
- serializeTool(h) {
175
- let parameters = h.parameters;
176
- if (typeof parameters === 'string') {
177
- try {
178
- parameters = JSON.parse(parameters);
179
- }
180
- catch {
181
- parameters = {};
182
- }
183
- }
184
- const tool = {
185
- type: 'function',
186
- name: h.name,
187
- description: h.description,
188
- parameters: parameters || {}
189
- };
190
- if (h.feedback != null) {
191
- const validatedFeedback = this.validatePerToolFeedback(h.feedback, h.name);
192
- if (validatedFeedback) {
193
- tool.feedback = validatedFeedback;
194
- }
195
- }
196
- const handler = h;
197
- const validatedTimeout = this.validateToolTimeout(handler.timeout_seconds, h.name);
198
- if (validatedTimeout != null) {
199
- tool.timeout_seconds = validatedTimeout;
200
- }
201
- const validatedResponseMode = this.validateToolResponseMode(handler.response_mode, h.name);
202
- if (validatedResponseMode != null) {
203
- tool.response_mode = validatedResponseMode;
204
- }
205
- return tool;
206
- }
207
- serializeSubagents(subagents) {
208
- if (!Array.isArray(subagents))
209
- return [];
210
- return subagents
211
- .filter(sa => sa != null && !lodash_1.default.isEmpty(lodash_1.default.trim(sa.name)))
212
- .map(sa => {
213
- const name = lodash_1.default.trim(sa.name);
214
- const serialized = {
215
- name,
216
- system_instruction: sa.system_instruction || '',
217
- developer_messages: (sa.developer_messages || [])
218
- .map(msg => typeof msg === 'string' ? msg : '')
219
- .filter(msg => !lodash_1.default.isEmpty(lodash_1.default.trim(msg))),
220
- context: sa.context === 'shared' ? 'shared' : 'own',
221
- tools: (sa.tools || [])
222
- .filter(t => t != null && !lodash_1.default.isEmpty(lodash_1.default.trim(t.name)))
223
- .map(t => this.serializeTool(t))
224
- };
225
- const llm = this.buildAgentServiceConfig(`subagent "${name}" llm`, sa.llm || {});
226
- if (llm)
227
- serialized.llm = llm;
228
- return serialized;
229
- });
230
- }
231
- isSubagentExitLabel(label) {
232
- const subagents = this.data.subagents || [];
233
- return subagents.some(sa => {
234
- const name = lodash_1.default.trim(sa?.name || '');
235
- return !!name && label === `subagent_${name}`;
236
- });
237
- }
238
- isSubagentTool(toolName) {
239
- const subagents = this.data.subagents || [];
240
- return subagents.some(sa => (sa?.tools || []).some(t => t && lodash_1.default.trim(t.name) === toolName));
241
- }
242
163
  findExitByLabel(label) {
243
164
  const exit = lodash_1.default.find(this.step.exits, (e) => e.label === label);
244
165
  return exit?.id;
@@ -363,11 +284,19 @@ class VoiceAgent extends voice_1.default {
363
284
  return null;
364
285
  }
365
286
  const validModes = ['static', 'auto'];
366
- if (!validModes.includes(cfg.mode)) {
287
+ const mode = cfg.mode;
288
+ const result = {
289
+ timeout_seconds: timeoutSeconds,
290
+ phrases: [],
291
+ mode
292
+ };
293
+ if (!validModes.includes(mode)) {
367
294
  this.log.warn('Voice Agent: invalid soft_timeout.mode — soft timeout config excluded');
368
295
  return null;
369
296
  }
370
- // Validate phrases
297
+ if (mode === 'auto') {
298
+ return result;
299
+ }
371
300
  const phrases = cfg.phrases;
372
301
  if (!Array.isArray(phrases) ||
373
302
  phrases.length < 1 ||
@@ -377,9 +306,8 @@ class VoiceAgent extends voice_1.default {
377
306
  return null;
378
307
  }
379
308
  return {
380
- timeout_seconds: timeoutSeconds,
381
- phrases: phrases,
382
- mode: cfg.mode
309
+ ...result,
310
+ phrases: phrases
383
311
  };
384
312
  }
385
313
  validateSystemTools(systemTools) {
@@ -410,26 +338,6 @@ class VoiceAgent extends voice_1.default {
410
338
  }
411
339
  return options;
412
340
  }
413
- validateToolTimeout(value, toolName) {
414
- if (value == null || value === '')
415
- return null;
416
- const timeout = Number(value);
417
- if (!Number.isFinite(timeout) || timeout < 1 || timeout > 300) {
418
- this.log.warn(`Voice Agent: invalid timeout_seconds for tool "${toolName}" (must be 1–300) — excluded`);
419
- return null;
420
- }
421
- return timeout;
422
- }
423
- validateToolResponseMode(value, toolName) {
424
- if (value == null || value === '')
425
- return null;
426
- const valid = ['sync', 'async', 'none'];
427
- if (!valid.includes(value)) {
428
- this.log.warn(`Voice Agent: invalid response_mode for tool "${toolName}" (must be sync/async/none) — excluded`);
429
- return null;
430
- }
431
- return value;
432
- }
433
341
  async exitToThread() {
434
342
  const result = this.state.result;
435
343
  await this.thread.set(`__voiceAgentContext_${this.thread.id}`, result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/step-voice",
3
- "version": "7.0.41-tooltimeoutresponsemode.3",
3
+ "version": "7.0.41",
4
4
  "author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
5
5
  "contributors": [
6
6
  "Roman Zolotarov",
@@ -1,10 +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 findExitByLabel;
8
- exitToThread(): Promise<void>;
9
- }
10
- export {};
@@ -1,80 +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
- let ctx = null;
10
- try {
11
- ctx = await this.thread.get(`__voiceAgentContext_${this.thread.id}`);
12
- }
13
- catch {
14
- ctx = null;
15
- }
16
- const callId = ctx?.callId ?? call.id;
17
- const callType = ctx?.callType ?? call.type;
18
- const callCallback = ctx?.callCallback ?? call.callback;
19
- const subagentName = ctx?.subagent ?? ctx?.name ?? this.data.subagentName ?? '';
20
- this.triggers.local(`in/voice/${callId}`, async (event) => {
21
- switch (event.params.type) {
22
- case 'tool_call': {
23
- const eventSubagent = event.params.subagent;
24
- if (eventSubagent && subagentName && eventSubagent !== subagentName) {
25
- return;
26
- }
27
- const cb = this.thread.takeCallback();
28
- const name = event.params.name ?? 'tool_call';
29
- const params = event.params.arguments ?? {};
30
- const toolCallId = event.params.toolCallId ?? '';
31
- const exitId = this.findExitByLabel(name);
32
- if (!exitId) {
33
- return;
34
- }
35
- this.exitStep(exitId, {
36
- [name]: params,
37
- name,
38
- toolCallId,
39
- subagent: subagentName,
40
- __voicecb: cb,
41
- callId,
42
- callType,
43
- callCallback
44
- }, true);
45
- return;
46
- }
47
- case 'hangup': {
48
- delete this.waits.timeout;
49
- await this.handleHangup(call);
50
- return await this.waitConvEnd();
51
- }
52
- case 'error': {
53
- delete this.waits.timeout;
54
- const exitId = this.getExitStepId('error');
55
- if (exitId)
56
- return this.exitStep(exitId, { error: event.params.error });
57
- return this.throwError(event.params.error);
58
- }
59
- case 'cancel':
60
- return this.end();
61
- }
62
- });
63
- this.triggers.otherwise(async () => {
64
- if (lodash_1.default.isEmpty(subagentName)) {
65
- this.log.warn('Subagent Tools Handler: no subagent context; waiting for tool calls on exits only');
66
- }
67
- return this.exitFlow();
68
- });
69
- }
70
- findExitByLabel(label) {
71
- const exit = lodash_1.default.find(this.step.exits, (e) => e.label === label);
72
- return exit?.id;
73
- }
74
- async exitToThread() {
75
- const result = this.state.result;
76
- await this.thread.set(`__voiceAgentContext_${this.thread.id}`, result);
77
- this.thread.exitStep(this.state.exitStep, result);
78
- }
79
- }
80
- exports.default = SubagentToolsHandler;