@onereach/step-voice 7.0.26-agenttimeout.10 → 7.0.26-agenttimeout.12
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.
|
@@ -4,88 +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
|
|
8
|
-
this.
|
|
9
|
-
|
|
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
|
-
// Attempt to get functionId from multiple sources to handle parallel function calls.
|
|
17
|
-
// Session storage is race-prone when multiple function_call threads run concurrently.
|
|
18
|
-
const threadStateFunctionId = this.state?.result?.functionId;
|
|
19
|
-
const resolvedFunctionId = inputFunctionId || threadStateFunctionId;
|
|
20
|
-
this.log.info("VoiceAgentFunctionResult: resolvedFunctionId", {
|
|
21
|
-
resolvedFunctionId,
|
|
22
|
-
source: inputFunctionId ? 'data.functionId' : threadStateFunctionId ? 'state.result.functionId' : 'none',
|
|
23
|
-
});
|
|
24
|
-
let ctx = null;
|
|
25
|
-
let ctxSource = 'none';
|
|
26
|
-
// Priority 1: functionId-keyed context (race-safe, unique per function call)
|
|
27
|
-
if (resolvedFunctionId) {
|
|
28
|
-
ctx = await this.thread.get(`__voiceAgentContext_fn_${resolvedFunctionId}`);
|
|
29
|
-
if (ctx) {
|
|
30
|
-
ctxSource = `__voiceAgentContext_fn_${resolvedFunctionId}`;
|
|
31
|
-
this.log.info("VoiceAgentFunctionResult: ctx from fn-keyed store", { ctxSource, functionId: ctx.functionId });
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
this.log.info("VoiceAgentFunctionResult: fn-keyed store miss", { key: `__voiceAgentContext_fn_${resolvedFunctionId}` });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// Priority 2: Thread-specific context
|
|
38
|
-
if (!ctx) {
|
|
39
|
-
ctx = await this.thread.get(`__voiceAgentContext_${this.thread.id}`);
|
|
40
|
-
if (ctx) {
|
|
41
|
-
ctxSource = `__voiceAgentContext_${this.thread.id}`;
|
|
42
|
-
this.log.info("VoiceAgentFunctionResult: ctx from thread-specific store", { ctxSource, functionId: ctx.functionId });
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.log.info("VoiceAgentFunctionResult: thread-specific store miss", { key: `__voiceAgentContext_${this.thread.id}` });
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// Priority 3: Use state.result directly if it has callId (from exitToThread → exitStep chain)
|
|
49
|
-
if (!ctx && this.state?.result?.callId) {
|
|
50
|
-
ctx = this.state.result;
|
|
51
|
-
ctxSource = 'state.result';
|
|
52
|
-
this.log.info("VoiceAgentFunctionResult: ctx from state.result", { functionId: ctx.functionId, callId: ctx.callId });
|
|
53
|
-
}
|
|
54
|
-
// Priority 4: Shared session context (backward compat, NOT race-safe for parallel calls)
|
|
55
|
-
if (!ctx) {
|
|
56
|
-
ctx = await this.thread.get('__voiceAgentContext') ?? {};
|
|
57
|
-
ctxSource = '__voiceAgentContext (shared session)';
|
|
58
|
-
this.log.info("VoiceAgentFunctionResult: ctx from shared session", { functionId: ctx?.functionId, callId: ctx?.callId });
|
|
59
|
-
}
|
|
60
|
-
const { callId, callCallback, name: functionName, functionId } = ctx;
|
|
61
|
-
this.log.info("VoiceAgentFunctionResult: resolved context", {
|
|
62
|
-
ctxSource,
|
|
63
|
-
callId,
|
|
64
|
-
functionId,
|
|
65
|
-
functionName,
|
|
66
|
-
hasCallback: !!callCallback,
|
|
67
|
-
});
|
|
68
|
-
if (!callId) {
|
|
7
|
+
const { result, stopAgent } = this.data;
|
|
8
|
+
const ctx = await this.thread.get(`__voiceAgentContext_${this.thread.id}`);
|
|
9
|
+
if (!ctx?.callId) {
|
|
69
10
|
throw new Error('Voice Agent Function Result: missing call context (must be placed on a Voice Agent function exit)');
|
|
70
11
|
}
|
|
12
|
+
const { callId, callCallback, name: functionName, functionId } = ctx;
|
|
13
|
+
this.log.info("Voice Agent Function Result", { functionId, callId, threadId: this.thread.id });
|
|
71
14
|
const params = {
|
|
72
|
-
functionName
|
|
73
|
-
functionId
|
|
74
|
-
result
|
|
75
|
-
options: {
|
|
76
|
-
stop: stopAgent
|
|
77
|
-
}
|
|
15
|
+
functionName,
|
|
16
|
+
functionId,
|
|
17
|
+
result,
|
|
18
|
+
options: { stop: stopAgent }
|
|
78
19
|
};
|
|
79
|
-
|
|
20
|
+
await this.thread.eventManager.emit({
|
|
80
21
|
target: this.helpers.providersAccountId,
|
|
81
22
|
name: 'out/voice/voicer',
|
|
82
23
|
params: {
|
|
83
24
|
id: callId,
|
|
84
25
|
commands: [{ name: 'agentFunctionResult', params }]
|
|
85
26
|
}
|
|
86
|
-
}
|
|
87
|
-
this.log.info("VoiceAgentFunctionResult: sending", { functionId, functionName, callId });
|
|
88
|
-
await this.thread.eventManager.emit(event, {
|
|
27
|
+
}, {
|
|
89
28
|
target: callCallback,
|
|
90
29
|
invocationType: 'async',
|
|
91
30
|
timeout: 5000
|
package/dst/Voice Agent.js
CHANGED
|
@@ -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
|
}
|