@onereach/step-voice 7.0.21 → 7.0.22-voiceagent.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.
@@ -0,0 +1,9 @@
1
+ import VoiceStep from './voice';
2
+ interface INPUT {
3
+ result: string;
4
+ stopAgent: boolean;
5
+ }
6
+ export default class VoiceAgentFunctionResult extends VoiceStep<INPUT> {
7
+ runStep(): Promise<void>;
8
+ }
9
+ export {};
@@ -0,0 +1,39 @@
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 params = {
15
+ functionName: functionName,
16
+ functionId: functionId,
17
+ result: result,
18
+ options: {
19
+ stop: stopAgent
20
+ }
21
+ };
22
+ const event = {
23
+ target: this.helpers.providersAccountId,
24
+ name: 'out/voice/voicer',
25
+ params: {
26
+ id: callId,
27
+ commands: [{ name: 'agentFunctionResult', params }]
28
+ }
29
+ };
30
+ this.log.error("Voice Agent Function Result", event);
31
+ await this.thread.eventManager.emit(event, {
32
+ target: callCallback,
33
+ invocationType: 'async',
34
+ timeout: 5000
35
+ });
36
+ this.exitStep('next');
37
+ }
38
+ }
39
+ exports.default = VoiceAgentFunctionResult;
@@ -0,0 +1,4 @@
1
+ import VoiceStep from './voice';
2
+ export default class VoiceAgentStop extends VoiceStep {
3
+ runStep(): Promise<void>;
4
+ }
@@ -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 VoiceAgentStop 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 = VoiceAgentStop;
@@ -0,0 +1,18 @@
1
+ import VoiceStep from './voice';
2
+ interface Handler {
3
+ name: string;
4
+ description: string;
5
+ parameters: string;
6
+ }
7
+ interface INPUT {
8
+ url: string;
9
+ handlers: Handler[];
10
+ system_instruction: string;
11
+ developer_messages: string[];
12
+ }
13
+ export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
14
+ runStep(): Promise<void>;
15
+ private findExitByLabel;
16
+ exitToThread(): Promise<void>;
17
+ }
18
+ export {};
@@ -0,0 +1,72 @@
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 VoiceAgent extends voice_1.default {
7
+ async runStep() {
8
+ const call = await this.fetchData();
9
+ this.triggers.local(`in/voice/${call.id}`, async (event) => {
10
+ switch (event.params.type) {
11
+ case 'function_call': {
12
+ if (event.params.type !== 'function_call')
13
+ return;
14
+ const cb = this.thread.takeCallback();
15
+ const name = event.params.name ?? 'function_call';
16
+ const params = event.params.arguments ?? {};
17
+ const functionId = event.params.functionId ?? '';
18
+ const exitId = this.findExitByLabel(name) ?? this.getExitStepId('function_call');
19
+ if (exitId) {
20
+ this.exitStep(exitId, { [name]: params, name, functionId, __voicecb: cb, callId: call.id, callType: call.type, callCallback: call.callback }, true);
21
+ }
22
+ else {
23
+ this.log.warn('no exit for function_call', { name });
24
+ }
25
+ return;
26
+ }
27
+ case 'hangup':
28
+ await this.handleHangup(call);
29
+ return await this.waitConvEnd();
30
+ case 'error':
31
+ return this.throwError(event.params.error);
32
+ case 'cancel':
33
+ return this.end();
34
+ }
35
+ });
36
+ this.triggers.otherwise(async () => {
37
+ const { url = "", // optional, default value configured on a voicer side
38
+ handlers = [], system_instruction = '', developer_messages = [] } = this.data;
39
+ const tools = handlers.map(h => {
40
+ let parameters = h.parameters;
41
+ if (typeof parameters === 'string') {
42
+ try {
43
+ parameters = JSON.parse(parameters);
44
+ }
45
+ catch {
46
+ parameters = {};
47
+ }
48
+ }
49
+ return { type: 'function', name: h.name, description: h.description, parameters: parameters || {} };
50
+ });
51
+ const params = {
52
+ url,
53
+ config: {
54
+ system_instruction,
55
+ developer_messages,
56
+ tools,
57
+ }
58
+ };
59
+ await this.sendCommands(call, [{ name: 'startAgent', params }]);
60
+ return this.exitFlow();
61
+ });
62
+ }
63
+ findExitByLabel(label) {
64
+ const exit = lodash_1.default.find(this.step.exits, (e) => e.label === label);
65
+ return exit?.id;
66
+ }
67
+ async exitToThread() {
68
+ await this.thread.set('__voiceAgentContext', this.state.result);
69
+ this.thread.exitStep(this.state.exitStep, this.state.result);
70
+ }
71
+ }
72
+ exports.default = VoiceAgent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/step-voice",
3
- "version": "7.0.21",
3
+ "version": "7.0.22-voiceagent.1",
4
4
  "author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
5
5
  "contributors": [
6
6
  "Roman Zolotarov",