@onereach/step-voice 7.0.26-agenttimeout.11 → 7.0.26-agenttimeout.13

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.
@@ -2,7 +2,6 @@ import VoiceStep from './voice';
2
2
  interface INPUT {
3
3
  result: string;
4
4
  stopAgent: boolean;
5
- functionId?: string;
6
5
  }
7
6
  export default class VoiceAgentFunctionResult extends VoiceStep<INPUT> {
8
7
  runStep(): Promise<void>;
@@ -4,90 +4,27 @@ const tslib_1 = require("tslib");
4
4
  const voice_1 = tslib_1.__importDefault(require("./voice"));
5
5
  class VoiceAgentFunctionResult extends voice_1.default {
6
6
  async runStep() {
7
- const { result, stopAgent, functionId: inputFunctionId } = this.data;
8
- this.log.info("VoiceAgentFunctionResult: start", {
9
- threadId: this.thread.id,
10
- inputFunctionId,
11
- stateKeys: Object.keys(this.state || {}),
12
- stateDirect: this.state?.direct,
13
- stateResultFunctionId: this.state?.result?.functionId,
14
- stateResultCallId: this.state?.result?.callId,
15
- });
16
- // Read the voice call data to get the call context
17
- await this.fetchData();
18
- // Attempt to get functionId from multiple sources to handle parallel function calls.
19
- // Session storage (__voiceAgentContext) is race-prone when multiple threads run concurrently.
20
- const threadStateFunctionId = this.state?.result?.functionId;
21
- const resolvedFunctionId = inputFunctionId || threadStateFunctionId;
22
- this.log.info("VoiceAgentFunctionResult: resolvedFunctionId", {
23
- resolvedFunctionId,
24
- source: inputFunctionId ? 'data.functionId' : threadStateFunctionId ? 'state.result.functionId' : 'none',
25
- });
26
- let ctx = null;
27
- let ctxSource = 'none';
28
- // Priority 1: functionId-keyed context (race-safe, unique per function call)
29
- if (resolvedFunctionId) {
30
- ctx = await this.thread.get(`__voiceAgentContext_fn_${resolvedFunctionId}`);
31
- if (ctx) {
32
- ctxSource = `__voiceAgentContext_fn_${resolvedFunctionId}`;
33
- this.log.info("VoiceAgentFunctionResult: ctx from fn-keyed store", { ctxSource, functionId: ctx.functionId });
34
- }
35
- else {
36
- this.log.info("VoiceAgentFunctionResult: fn-keyed store miss", { key: `__voiceAgentContext_fn_${resolvedFunctionId}` });
37
- }
38
- }
39
- // Priority 2: Thread-specific context
40
- if (!ctx) {
41
- ctx = await this.thread.get(`__voiceAgentContext_${this.thread.id}`);
42
- if (ctx) {
43
- ctxSource = `__voiceAgentContext_${this.thread.id}`;
44
- this.log.info("VoiceAgentFunctionResult: ctx from thread-specific store", { ctxSource, functionId: ctx.functionId });
45
- }
46
- else {
47
- this.log.info("VoiceAgentFunctionResult: thread-specific store miss", { key: `__voiceAgentContext_${this.thread.id}` });
48
- }
49
- }
50
- // Priority 3: Use state.result directly if it has callId (from exitToThread → exitStep chain)
51
- if (!ctx && this.state?.result?.callId) {
52
- ctx = this.state.result;
53
- ctxSource = 'state.result';
54
- this.log.info("VoiceAgentFunctionResult: ctx from state.result", { functionId: ctx.functionId, callId: ctx.callId });
55
- }
56
- // Priority 4: Shared session context (backward compat, NOT race-safe for parallel calls)
57
- if (!ctx) {
58
- ctx = await this.thread.get('__voiceAgentContext') ?? {};
59
- ctxSource = '__voiceAgentContext (shared session - RACE PRONE)';
60
- this.log.info("VoiceAgentFunctionResult: WARNING using shared session ctx", { functionId: ctx?.functionId, callId: ctx?.callId });
61
- }
62
- const { callId, callCallback, name: functionName, functionId } = ctx;
63
- this.log.info("VoiceAgentFunctionResult: resolved context", {
64
- ctxSource,
65
- callId,
66
- functionId,
67
- functionName,
68
- hasCallback: !!callCallback,
69
- });
70
- if (!callId) {
7
+ const { result, stopAgent } = this.data;
8
+ const ctx = await this.thread.get(`__voiceAgentContext_${this.thread.id}`);
9
+ if (!ctx?.callId) {
71
10
  throw new Error('Voice Agent Function Result: missing call context (must be placed on a Voice Agent function exit)');
72
11
  }
12
+ const { callId, callCallback, name: functionName, functionId } = ctx;
13
+ this.log.info("Voice Agent Function Result", { functionId, callId, threadId: this.thread.id });
73
14
  const params = {
74
- functionName: functionName,
75
- functionId: functionId,
76
- result: result,
77
- options: {
78
- stop: stopAgent
79
- }
15
+ functionName,
16
+ functionId,
17
+ result,
18
+ options: { stop: stopAgent }
80
19
  };
81
- const event = {
20
+ await this.thread.eventManager.emit({
82
21
  target: this.helpers.providersAccountId,
83
22
  name: 'out/voice/voicer',
84
23
  params: {
85
24
  id: callId,
86
25
  commands: [{ name: 'agentFunctionResult', params }]
87
26
  }
88
- };
89
- this.log.info("VoiceAgentFunctionResult: sending response", { functionId, functionName, callId, ctxSource });
90
- await this.thread.eventManager.emit(event, {
27
+ }, {
91
28
  target: callCallback,
92
29
  invocationType: 'async',
93
30
  timeout: 5000
@@ -297,20 +297,7 @@ class VoiceAgent extends voice_1.default {
297
297
  }
298
298
  async exitToThread() {
299
299
  const result = this.state.result;
300
- this.log.info("VoiceAgent.exitToThread: writing context", {
301
- threadId: this.thread.id,
302
- functionId: result?.functionId,
303
- callId: result?.callId,
304
- name: result?.name,
305
- });
306
300
  await this.thread.set(`__voiceAgentContext_${this.thread.id}`, result);
307
- await this.thread.set('__voiceAgentContext', result);
308
- if (result?.functionId) {
309
- await this.thread.set(`__voiceAgentContext_fn_${result.functionId}`, result);
310
- this.log.info("VoiceAgent.exitToThread: wrote fn-keyed context", {
311
- key: `__voiceAgentContext_fn_${result.functionId}`,
312
- });
313
- }
314
301
  this.thread.exitStep(this.state.exitStep, result);
315
302
  }
316
303
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/step-voice",
3
- "version": "7.0.26-agenttimeout.11",
3
+ "version": "7.0.26-agenttimeout.13",
4
4
  "author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
5
5
  "contributors": [
6
6
  "Roman Zolotarov",