@onereach/step-voice 7.0.20 → 7.0.21-VOIC1700.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.
@@ -0,0 +1,4 @@
1
+ import Step from '@onereach/flow-sdk/dst/step';
2
+ export default class VoiceAgentFunctionResult extends Step {
3
+ runStep(): Promise<void>;
4
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const step_1 = tslib_1.__importDefault(require("@onereach/flow-sdk/dst/step"));
5
+ class VoiceAgentFunctionResult extends step_1.default {
6
+ async runStep() {
7
+ const ctx = await this.thread.get('__voiceAgentContext') ?? {};
8
+ const { callId, callCallback, name: functionName, functionId } = ctx;
9
+ const result = this.data.result ?? '';
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 } }]
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;
@@ -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,70 @@
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 { url: configuredUrl, handlers = [], system_instruction = '', developer_messages = [] } = this.data;
9
+ const url = configuredUrl || `wss://bot.svc.${this.helpers.environment}.api.onereach.ai/ws`;
10
+ const call = await this.fetchData();
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.thread.set(name, params);
40
+ this.exitStep(exitId, { name, functionId, params, __voicecb: cb, callId: call.id, callType: call.type, callCallback: call.callback }, true);
41
+ }
42
+ else {
43
+ this.log.warn('no exit for function_call', { name });
44
+ }
45
+ return;
46
+ }
47
+ case 'hangup':
48
+ await this.handleHangup(call);
49
+ return await this.waitConvEnd();
50
+ case 'error':
51
+ return this.throwError(event.params.error);
52
+ case 'cancel':
53
+ return this.end();
54
+ }
55
+ });
56
+ this.triggers.otherwise(async () => {
57
+ await this.sendCommands(call, [{ name: 'startAgent', params: { url, config } }]);
58
+ return this.exitFlow();
59
+ });
60
+ }
61
+ findExitByLabel(label) {
62
+ const exit = lodash_1.default.find(this.step.exits, (e) => e.label === label);
63
+ return exit?.id;
64
+ }
65
+ async exitToThread() {
66
+ await this.thread.set('__voiceAgentContext', this.state.result);
67
+ this.thread.exitStep(this.state.exitStep, this.state.result);
68
+ }
69
+ }
70
+ exports.default = VoiceAgent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/step-voice",
3
- "version": "7.0.20",
3
+ "version": "7.0.21-VOIC1700.0",
4
4
  "author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
5
5
  "contributors": [
6
6
  "Roman Zolotarov",