@onereach/step-voice 7.0.41-subagents.1 → 7.0.41-tooltimeoutresponsemode.1

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,10 +1,13 @@
1
1
  import VoiceStep from './voice';
2
2
  type SystemInstructionMode = 'append' | 'replace' | 'off';
3
+ type ToolResponseMode = 'sync' | 'async' | 'none';
3
4
  interface Tool {
4
5
  name: string;
5
6
  description: string;
6
7
  parameters: string | Record<string, unknown>;
7
8
  exitId?: string;
9
+ timeout_seconds?: number | string | null;
10
+ response_mode?: ToolResponseMode | string | null;
8
11
  }
9
12
  interface AgentServiceConfig {
10
13
  provider: string;
@@ -38,5 +41,7 @@ export default class UpdateVoiceAgent extends VoiceStep<Partial<INPUT>> {
38
41
  private buildOptionalServiceOverride;
39
42
  private parseAgentServiceOptions;
40
43
  private isStepFlagEnabled;
44
+ private validateToolTimeout;
45
+ private validateToolResponseMode;
41
46
  }
42
47
  export {};
@@ -139,12 +139,21 @@ class UpdateVoiceAgent extends voice_1.default {
139
139
  else if (t.parameters && typeof t.parameters === 'object') {
140
140
  parameters = t.parameters;
141
141
  }
142
- return {
142
+ const tool = {
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;
148
157
  });
149
158
  }
150
159
  buildOptionalServiceOverride(label, service) {
@@ -182,5 +191,25 @@ class UpdateVoiceAgent extends voice_1.default {
182
191
  isStepFlagEnabled(value) {
183
192
  return value === true || value === 'true' || value === 1 || value === '1';
184
193
  }
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
+ }
185
214
  }
186
215
  exports.default = UpdateVoiceAgent;
@@ -24,24 +24,14 @@ interface SoftTimeoutConfig {
24
24
  phrases: string[];
25
25
  mode: SoftTimeoutMode;
26
26
  }
27
+ type ToolResponseMode = 'sync' | 'async' | 'none';
27
28
  interface Handler {
28
29
  name: string;
29
30
  description: string;
30
31
  parameters: string;
31
32
  feedback?: PerToolConfig;
32
- }
33
- interface SubagentTool {
34
- name: string;
35
- description: string;
36
- parameters: string;
37
- feedback?: PerToolConfig;
38
- }
39
- interface Subagent {
40
- id: string;
41
- name: string;
42
- system_instruction: string;
43
- tools: SubagentTool[];
44
- exitId?: string;
33
+ timeout_seconds?: number | string | null;
34
+ response_mode?: ToolResponseMode | string | null;
45
35
  }
46
36
  interface AgentSystemToolConfig {
47
37
  name: string;
@@ -56,7 +46,6 @@ interface AgentServiceConfig {
56
46
  }
57
47
  interface INPUT {
58
48
  handlers: Handler[];
59
- subagents: Subagent[];
60
49
  system_instruction: string;
61
50
  developer_messages: string[];
62
51
  greeting_message: string;
@@ -86,16 +75,7 @@ interface INPUT {
86
75
  }
87
76
  export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
88
77
  runStep(): Promise<void>;
89
- /**
90
- * Fork a thread per subagent exit so Subagent Tools Handler steps can
91
- * register tool_call listeners immediately after agent start.
92
- */
93
- private spawnSubagentHandlerThreads;
94
78
  private normalizeIdlePrompts;
95
- private serializeTool;
96
- private serializeSubagents;
97
- private isSubagentExitLabel;
98
- private isSubagentTool;
99
79
  private findExitByLabel;
100
80
  private validateToolFeedback;
101
81
  private isStepFlagEnabled;
@@ -105,6 +85,8 @@ export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
105
85
  private validateSoftTimeout;
106
86
  private validateSystemTools;
107
87
  private parseAgentServiceOptions;
88
+ private validateToolTimeout;
89
+ private validateToolResponseMode;
108
90
  exitToThread(): Promise<void>;
109
91
  }
110
92
  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,42 @@ 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
+ const validatedTimeout = this.validateToolTimeout(h.timeout_seconds, h.name);
82
+ if (validatedTimeout != null) {
83
+ tool.timeout_seconds = validatedTimeout;
84
+ }
85
+ const validatedResponseMode = this.validateToolResponseMode(h.response_mode, h.name);
86
+ if (validatedResponseMode != null) {
87
+ tool.response_mode = validatedResponseMode;
88
+ }
89
+ return tool;
90
+ });
64
91
  const config = {
65
92
  system_instruction,
66
93
  developer_messages,
@@ -68,10 +95,6 @@ class VoiceAgent extends voice_1.default {
68
95
  prevent_greeting_interruption,
69
96
  tools
70
97
  };
71
- const serializedSubagents = this.serializeSubagents(subagents) || [];
72
- if (serializedSubagents.length > 0) {
73
- config.subagents = serializedSubagents;
74
- }
75
98
  if (this.isStepFlagEnabled(idle_detection_enabled)) {
76
99
  const timeoutSecs = Number(idle_timeout_secs);
77
100
  const maxRetries = Number(idle_max_retries);
@@ -137,88 +160,14 @@ class VoiceAgent extends voice_1.default {
137
160
  params.url = agentCustomUrl;
138
161
  }
139
162
  await this.sendCommands(call, [{ name: 'startAgent', params }]);
140
- this.spawnSubagentHandlerThreads(call, subagents);
141
163
  return this.exitFlow();
142
164
  });
143
165
  }
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
166
  normalizeIdlePrompts(idlePrompts) {
170
167
  return (idlePrompts || [])
171
168
  .map(item => typeof item === 'string' ? item : item?.prompt ?? '')
172
169
  .filter(prompt => !lodash_1.default.isEmpty(lodash_1.default.trim(String(prompt))));
173
170
  }
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
- return tool;
197
- }
198
- serializeSubagents(subagents) {
199
- if (!Array.isArray(subagents))
200
- return [];
201
- return subagents
202
- .filter(sa => sa != null && !lodash_1.default.isEmpty(lodash_1.default.trim(sa.name)))
203
- .map(sa => ({
204
- name: lodash_1.default.trim(sa.name),
205
- system_instruction: sa.system_instruction || '',
206
- tools: (sa.tools || [])
207
- .filter(t => t != null && !lodash_1.default.isEmpty(lodash_1.default.trim(t.name)))
208
- .map(t => this.serializeTool(t))
209
- }));
210
- }
211
- isSubagentExitLabel(label) {
212
- const subagents = this.data.subagents || [];
213
- return subagents.some(sa => {
214
- const name = lodash_1.default.trim(sa?.name || '');
215
- return !!name && label === `subagent_${name}`;
216
- });
217
- }
218
- isSubagentTool(toolName) {
219
- const subagents = this.data.subagents || [];
220
- return subagents.some(sa => (sa?.tools || []).some(t => t && lodash_1.default.trim(t.name) === toolName));
221
- }
222
171
  findExitByLabel(label) {
223
172
  const exit = lodash_1.default.find(this.step.exits, (e) => e.label === label);
224
173
  return exit?.id;
@@ -390,6 +339,26 @@ class VoiceAgent extends voice_1.default {
390
339
  }
391
340
  return options;
392
341
  }
342
+ validateToolTimeout(value, toolName) {
343
+ if (value == null || value === '')
344
+ return null;
345
+ const timeout = Number(value);
346
+ if (!Number.isFinite(timeout) || timeout < 1 || timeout > 300) {
347
+ this.log.warn(`Voice Agent: invalid timeout_seconds for tool "${toolName}" (must be 1–300) — excluded`);
348
+ return null;
349
+ }
350
+ return timeout;
351
+ }
352
+ validateToolResponseMode(value, toolName) {
353
+ if (value == null || value === '')
354
+ return null;
355
+ const valid = ['sync', 'async', 'none'];
356
+ if (!valid.includes(value)) {
357
+ this.log.warn(`Voice Agent: invalid response_mode for tool "${toolName}" (must be sync/async/none) — excluded`);
358
+ return null;
359
+ }
360
+ return value;
361
+ }
393
362
  async exitToThread() {
394
363
  const result = this.state.result;
395
364
  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-subagents.1",
3
+ "version": "7.0.41-tooltimeoutresponsemode.1",
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;