@onereach/step-voice 7.0.21-voiceagents.3 → 7.0.22-voiceagent.0
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.
- package/dst/Stop Voice Agent.d.ts +4 -0
- package/dst/Stop Voice Agent.js +14 -0
- package/dst/Transfer.d.ts +1 -0
- package/dst/Transfer.js +2 -1
- package/dst/Voice Agent Function Result.d.ts +9 -0
- package/dst/Voice Agent Function Result.js +31 -0
- package/dst/Voice Agent.d.ts +10 -0
- package/dst/Voice Agent.js +59 -3
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const voice_1 = tslib_1.__importDefault(require("./voice"));
|
|
5
|
+
class StopVoiceAgent extends voice_1.default {
|
|
6
|
+
async runStep() {
|
|
7
|
+
const call = await this.fetchData();
|
|
8
|
+
this.triggers.otherwise(async () => {
|
|
9
|
+
await this.sendCommands(call, [{ name: 'stopAgent' }]);
|
|
10
|
+
return this.exitStep('next');
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.default = StopVoiceAgent;
|
package/dst/Transfer.d.ts
CHANGED
package/dst/Transfer.js
CHANGED
|
@@ -52,7 +52,7 @@ class Transfer extends voice_1.default {
|
|
|
52
52
|
return this.exitFlow();
|
|
53
53
|
});
|
|
54
54
|
this.triggers.otherwise(async () => {
|
|
55
|
-
const { phoneNumber, sessionTimeout, destination, sipHeaders = [], sipHost, sipUser, sipPassword, sipProfile, refer, withReplaces, replacesConversation, replacesConversationThread, gatewaySettingsMode, from, muteRecording, } = this.data;
|
|
55
|
+
const { phoneNumber, sessionTimeout, destination, sipHeaders = [], sipHost, sipUser, sipPassword, sipProfile, refer, withReplaces, replacesConversation, replacesConversationThread, gatewaySettingsMode, from, muteRecording, disableRingback, } = this.data;
|
|
56
56
|
const destinationIsSip = (/^sip:/i).test(destination);
|
|
57
57
|
const destinationIsUser = (/^user:/i).test(destination);
|
|
58
58
|
const callerID = phoneNumber;
|
|
@@ -114,6 +114,7 @@ class Transfer extends voice_1.default {
|
|
|
114
114
|
gateway,
|
|
115
115
|
timeout,
|
|
116
116
|
maxLoops,
|
|
117
|
+
...(disableRingback && { ringback: 'silence_stream://-1' }),
|
|
117
118
|
...(replacesDialog && { replacesDialog }),
|
|
118
119
|
}
|
|
119
120
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const voice_1 = tslib_1.__importDefault(require("./voice"));
|
|
5
|
+
class VoiceAgentFunctionResult extends voice_1.default {
|
|
6
|
+
async runStep() {
|
|
7
|
+
const ctx = await this.thread.get('__voiceAgentContext') ?? {};
|
|
8
|
+
const { callId, callCallback, name: functionName, functionId } = ctx;
|
|
9
|
+
const { result, stopAgent } = this.data;
|
|
10
|
+
if (!callId) {
|
|
11
|
+
throw new Error('Voice Agent Function Result: missing call context (must be placed on a Voice Agent function exit)');
|
|
12
|
+
}
|
|
13
|
+
this.log.error("Voice Agent Function Result Params", ctx);
|
|
14
|
+
const event = {
|
|
15
|
+
target: this.helpers.providersAccountId,
|
|
16
|
+
name: 'out/voice/agent-function-result',
|
|
17
|
+
params: {
|
|
18
|
+
id: callId,
|
|
19
|
+
commands: [{ name: 'agentFunctionResult', params: { name: functionName, functionId, result, stopAgent } }]
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
this.log.error("Voice Agent Function Result", event);
|
|
23
|
+
await this.thread.eventManager.emit(event, {
|
|
24
|
+
target: callCallback,
|
|
25
|
+
invocationType: 'async',
|
|
26
|
+
timeout: 5000
|
|
27
|
+
});
|
|
28
|
+
this.exitStep('next');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = VoiceAgentFunctionResult;
|
package/dst/Voice Agent.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import VoiceStep from './voice';
|
|
2
|
+
interface Handler {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: string;
|
|
6
|
+
}
|
|
2
7
|
interface INPUT {
|
|
3
8
|
url: string;
|
|
9
|
+
handlers: Handler[];
|
|
10
|
+
system_instruction: string;
|
|
11
|
+
developer_messages: string[];
|
|
4
12
|
}
|
|
5
13
|
export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
|
|
6
14
|
runStep(): Promise<void>;
|
|
15
|
+
private findExitByLabel;
|
|
16
|
+
exitToThread(): Promise<void>;
|
|
7
17
|
}
|
|
8
18
|
export {};
|
package/dst/Voice Agent.js
CHANGED
|
@@ -1,13 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
4
5
|
const voice_1 = tslib_1.__importDefault(require("./voice"));
|
|
5
6
|
class VoiceAgent extends voice_1.default {
|
|
6
7
|
async runStep() {
|
|
7
|
-
const { url = "
|
|
8
|
+
const { url = "", // optional, default value configured on a voicer side
|
|
9
|
+
handlers = [], system_instruction = '', developer_messages = [] } = this.data;
|
|
8
10
|
const call = await this.fetchData();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
const tools = handlers.map(h => {
|
|
12
|
+
let parameters = h.parameters;
|
|
13
|
+
if (typeof parameters === 'string') {
|
|
14
|
+
try {
|
|
15
|
+
parameters = JSON.parse(parameters);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
parameters = {};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return { type: 'function', name: h.name, description: h.description, parameters: parameters || {} };
|
|
22
|
+
});
|
|
23
|
+
const config = {
|
|
24
|
+
system_instruction,
|
|
25
|
+
developer_messages,
|
|
26
|
+
tools
|
|
27
|
+
};
|
|
28
|
+
this.triggers.local(`in/voice/${call.id}`, async (event) => {
|
|
29
|
+
switch (event.params.type) {
|
|
30
|
+
case 'function_call': {
|
|
31
|
+
if (event.params.type !== 'function_call')
|
|
32
|
+
return;
|
|
33
|
+
const cb = this.thread.takeCallback();
|
|
34
|
+
const name = event.params.name ?? 'function_call';
|
|
35
|
+
const params = event.params.arguments ?? {};
|
|
36
|
+
const functionId = event.params.functionId ?? '';
|
|
37
|
+
const exitId = this.findExitByLabel(name) ?? this.getExitStepId('function_call');
|
|
38
|
+
if (exitId) {
|
|
39
|
+
this.exitStep(exitId, { [name]: params, name, functionId, __voicecb: cb, callId: call.id, callType: call.type, callCallback: call.callback }, true);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.log.warn('no exit for function_call', { name });
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
case 'hangup':
|
|
47
|
+
await this.handleHangup(call);
|
|
48
|
+
return await this.waitConvEnd();
|
|
49
|
+
case 'error':
|
|
50
|
+
return this.throwError(event.params.error);
|
|
51
|
+
case 'cancel':
|
|
52
|
+
return this.end();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
this.triggers.otherwise(async () => {
|
|
56
|
+
await this.sendCommands(call, [{ name: 'startAgent', params: { url, config } }]);
|
|
57
|
+
return this.exitFlow();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
findExitByLabel(label) {
|
|
61
|
+
const exit = lodash_1.default.find(this.step.exits, (e) => e.label === label);
|
|
62
|
+
return exit?.id;
|
|
63
|
+
}
|
|
64
|
+
async exitToThread() {
|
|
65
|
+
await this.thread.set('__voiceAgentContext', this.state.result);
|
|
66
|
+
this.thread.exitStep(this.state.exitStep, this.state.result);
|
|
11
67
|
}
|
|
12
68
|
}
|
|
13
69
|
exports.default = VoiceAgent;
|