@onereach/step-voice 7.0.49 → 7.0.50-VOIC1731livetranslation.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/Voice Agent.d.ts +18 -0
- package/dst/Voice Agent.js +17 -1
- package/dst/Voice Live Translation.d.ts +64 -0
- package/dst/Voice Live Translation.js +149 -0
- package/dst/voice.d.ts +1 -1
- package/package.json +1 -1
package/dst/Voice Agent.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ interface Subagent {
|
|
|
56
56
|
context?: SubagentContextMode;
|
|
57
57
|
llm?: Partial<AgentServiceConfig> | null;
|
|
58
58
|
tools: SubagentTool[];
|
|
59
|
+
mcp_servers?: AgentMcpServerConfig[];
|
|
59
60
|
exitId?: string;
|
|
60
61
|
}
|
|
61
62
|
interface AgentSystemToolConfig {
|
|
@@ -68,6 +69,21 @@ interface AgentKnowledgeConfig {
|
|
|
68
69
|
id: string;
|
|
69
70
|
mode: KnowledgeMode;
|
|
70
71
|
}
|
|
72
|
+
type McpTransport = 'streamable_http' | 'sse';
|
|
73
|
+
type McpToolPolicy = 'allow' | 'disallow';
|
|
74
|
+
interface AgentMcpToolConfig {
|
|
75
|
+
policy: McpToolPolicy;
|
|
76
|
+
description?: string;
|
|
77
|
+
parameters?: Record<string, unknown>;
|
|
78
|
+
}
|
|
79
|
+
interface AgentMcpServerConfig {
|
|
80
|
+
name: string;
|
|
81
|
+
url: string;
|
|
82
|
+
transport: McpTransport;
|
|
83
|
+
headers?: Record<string, string>;
|
|
84
|
+
tools: Record<string, AgentMcpToolConfig>;
|
|
85
|
+
timeout_seconds?: number;
|
|
86
|
+
}
|
|
71
87
|
type WorkingHoursDayKey = 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun';
|
|
72
88
|
interface WorkingHoursDayInput {
|
|
73
89
|
enabled?: boolean | string;
|
|
@@ -112,6 +128,7 @@ interface INPUT {
|
|
|
112
128
|
system_tools?: AgentSystemToolConfig[];
|
|
113
129
|
knowledge?: AgentKnowledgeConfig[];
|
|
114
130
|
working_hours?: WorkingHoursInput;
|
|
131
|
+
mcp_servers?: AgentMcpServerConfig[];
|
|
115
132
|
}
|
|
116
133
|
export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
|
|
117
134
|
runStep(): Promise<void>;
|
|
@@ -134,6 +151,7 @@ export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
|
|
|
134
151
|
private validateSoftTimeout;
|
|
135
152
|
private validateSystemTools;
|
|
136
153
|
private validateKnowledge;
|
|
154
|
+
private validateMcpServers;
|
|
137
155
|
private parseAgentServiceOptions;
|
|
138
156
|
exitToThread(): Promise<void>;
|
|
139
157
|
}
|
package/dst/Voice Agent.js
CHANGED
|
@@ -82,7 +82,7 @@ class VoiceAgent extends voice_1.default {
|
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
this.triggers.otherwise(async () => {
|
|
85
|
-
const { handlers = [], subagents = [], system_instruction = '', developer_messages = [], custom_config_enabled = false, agent_url_overwritten = false, system_tools, knowledge = [], agent_url = '', mode = '', stt = {}, llm = {}, tts = {}, realtime = {} } = this.data;
|
|
85
|
+
const { handlers = [], subagents = [], system_instruction = '', developer_messages = [], custom_config_enabled = false, agent_url_overwritten = false, system_tools, knowledge = [], mcp_servers = [], agent_url = '', mode = '', stt = {}, llm = {}, tts = {}, realtime = {} } = this.data;
|
|
86
86
|
if (lodash_1.default.isEmpty(system_instruction)) {
|
|
87
87
|
this.throwError(new Error('Voice Agent: system instruction is required'));
|
|
88
88
|
}
|
|
@@ -127,6 +127,9 @@ class VoiceAgent extends voice_1.default {
|
|
|
127
127
|
if (!lodash_1.default.isEmpty(knowledge)) {
|
|
128
128
|
config.knowledge = this.validateKnowledge(knowledge);
|
|
129
129
|
}
|
|
130
|
+
if (!lodash_1.default.isEmpty(mcp_servers)) {
|
|
131
|
+
config.mcp_servers = this.validateMcpServers(mcp_servers);
|
|
132
|
+
}
|
|
130
133
|
const params = { config };
|
|
131
134
|
if (agentCustomUrl) {
|
|
132
135
|
params.url = agentCustomUrl;
|
|
@@ -191,6 +194,8 @@ class VoiceAgent extends voice_1.default {
|
|
|
191
194
|
const llm = this.buildAgentServiceConfig(`subagent "${name}" llm`, sa.llm || {});
|
|
192
195
|
if (llm)
|
|
193
196
|
serialized.llm = llm;
|
|
197
|
+
if (!lodash_1.default.isEmpty(sa.mcp_servers))
|
|
198
|
+
serialized.mcp_servers = this.validateMcpServers(sa.mcp_servers);
|
|
194
199
|
return serialized;
|
|
195
200
|
});
|
|
196
201
|
}
|
|
@@ -484,6 +489,17 @@ class VoiceAgent extends voice_1.default {
|
|
|
484
489
|
}))
|
|
485
490
|
.filter(entry => !lodash_1.default.isEmpty(entry.id)), entry => entry.id);
|
|
486
491
|
}
|
|
492
|
+
// The agent validates names, urls and tools (and slugs the name); this only
|
|
493
|
+
// drops unusable entries and keeps the known fields, since the agent forbids extras.
|
|
494
|
+
validateMcpServers(servers) {
|
|
495
|
+
if (!Array.isArray(servers)) {
|
|
496
|
+
this.throwError(new Error('Voice Agent: mcp_servers must be an array'));
|
|
497
|
+
}
|
|
498
|
+
return servers
|
|
499
|
+
.filter(entry => entry != null && typeof entry === 'object')
|
|
500
|
+
.filter((entry) => !lodash_1.default.isEmpty(entry.name) && !lodash_1.default.isEmpty(entry.url))
|
|
501
|
+
.map((entry) => lodash_1.default.pick(entry, ['name', 'url', 'transport', 'headers', 'tools', 'timeout_seconds']));
|
|
502
|
+
}
|
|
487
503
|
parseAgentServiceOptions(label, options) {
|
|
488
504
|
if (options == null || options === '')
|
|
489
505
|
return undefined;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import VoiceStep, { VoiceEvent } from './voice';
|
|
2
|
+
declare const enum GATEWAY_SETTINGS_MODE {
|
|
3
|
+
DEFAULT = "default",
|
|
4
|
+
CUSTOM = "custom",
|
|
5
|
+
INHERIT = "inherit",
|
|
6
|
+
PROFILE = "profile"
|
|
7
|
+
}
|
|
8
|
+
declare const enum SIP_PROFILE {
|
|
9
|
+
DEFAULT = "default",
|
|
10
|
+
INTERNAL = "internal",
|
|
11
|
+
EXTERNAL = "external"
|
|
12
|
+
}
|
|
13
|
+
interface INPUT {
|
|
14
|
+
destination: string;
|
|
15
|
+
phoneNumber: string;
|
|
16
|
+
sessionTimeout: number;
|
|
17
|
+
sipHeaders: Array<{
|
|
18
|
+
name: string;
|
|
19
|
+
value: string;
|
|
20
|
+
}>;
|
|
21
|
+
from?: string;
|
|
22
|
+
gatewaySettingsMode?: GATEWAY_SETTINGS_MODE;
|
|
23
|
+
sipHost?: string;
|
|
24
|
+
sipUser?: string;
|
|
25
|
+
sipPassword?: string;
|
|
26
|
+
sipProfile?: SIP_PROFILE;
|
|
27
|
+
muteRecording?: boolean;
|
|
28
|
+
disableRingback?: boolean;
|
|
29
|
+
caller_language: string;
|
|
30
|
+
destination_language: string;
|
|
31
|
+
translator?: Partial<TranslatorConfig>;
|
|
32
|
+
echo_protection?: boolean;
|
|
33
|
+
dub?: Partial<DubConfig>;
|
|
34
|
+
agent_url_overwritten?: boolean;
|
|
35
|
+
agent_url?: string;
|
|
36
|
+
}
|
|
37
|
+
interface TranslatorConfig {
|
|
38
|
+
provider: 'pinch' | 'passthrough';
|
|
39
|
+
model: string;
|
|
40
|
+
api_key?: string;
|
|
41
|
+
options?: {
|
|
42
|
+
voice_type?: '' | 'male' | 'female';
|
|
43
|
+
voice_id?: string;
|
|
44
|
+
context?: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
interface DubConfig {
|
|
48
|
+
enabled: boolean;
|
|
49
|
+
original_level: number | string;
|
|
50
|
+
original_level_while_translating: number | string;
|
|
51
|
+
volume_change_ms: number | string;
|
|
52
|
+
restore_delay_ms: number | string;
|
|
53
|
+
}
|
|
54
|
+
interface EVENT extends VoiceEvent {
|
|
55
|
+
originateDisposition?: string;
|
|
56
|
+
reason?: string;
|
|
57
|
+
}
|
|
58
|
+
export default class VoiceLiveTranslation extends VoiceStep<INPUT, {}, EVENT> {
|
|
59
|
+
runStep(): Promise<void>;
|
|
60
|
+
translationParams(): Record<string, unknown>;
|
|
61
|
+
private isStepFlagEnabled;
|
|
62
|
+
private isValidAgentUrl;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
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 VoiceLiveTranslation 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 'bridge': {
|
|
12
|
+
await this.transcript(call, {
|
|
13
|
+
action: 'Live Translation Answered',
|
|
14
|
+
actionFromBot: true,
|
|
15
|
+
reportingSettingsKey: 'transcriptAnswered'
|
|
16
|
+
});
|
|
17
|
+
// Maximum call duration
|
|
18
|
+
this.triggers.timeout(60 * 60 * 1000, () => { });
|
|
19
|
+
return this.exitFlow();
|
|
20
|
+
}
|
|
21
|
+
case 'bridge/ended': {
|
|
22
|
+
const { error, originateDisposition } = event.params;
|
|
23
|
+
const isSuccess = error === 'NORMAL_CLEARING' &&
|
|
24
|
+
(lodash_1.default.isUndefined(originateDisposition) || originateDisposition === 'SUCCESS');
|
|
25
|
+
if (isSuccess) {
|
|
26
|
+
await this.transcript(call, {
|
|
27
|
+
action: 'Live Translation Ended - Answered',
|
|
28
|
+
actionFromBot: true,
|
|
29
|
+
reportingSettingsKey: 'transcriptEndedAnswered'
|
|
30
|
+
});
|
|
31
|
+
return this.exitStep('success');
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
await this.transcript(call, {
|
|
35
|
+
action: 'Live Translation Ended - Not Answered',
|
|
36
|
+
actionFromBot: true,
|
|
37
|
+
reportingSettingsKey: 'transcriptEndedNotAnswered'
|
|
38
|
+
});
|
|
39
|
+
return this.exitStep('no answer');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
case 'translation/started':
|
|
43
|
+
this.log.info('translation started');
|
|
44
|
+
break;
|
|
45
|
+
case 'translation/error':
|
|
46
|
+
this.log.warn('translation error', { message: event.params.error?.message });
|
|
47
|
+
break;
|
|
48
|
+
case 'translation/stopped':
|
|
49
|
+
this.log.info('translation stopped', { reason: event.params.reason });
|
|
50
|
+
break;
|
|
51
|
+
case 'hangup': {
|
|
52
|
+
await this.handleHangup(call);
|
|
53
|
+
return await this.waitConvEnd();
|
|
54
|
+
}
|
|
55
|
+
case 'error':
|
|
56
|
+
return this.throwError(event.params.error);
|
|
57
|
+
}
|
|
58
|
+
return this.exitFlow();
|
|
59
|
+
});
|
|
60
|
+
this.triggers.otherwise(async () => {
|
|
61
|
+
const { phoneNumber, sessionTimeout, destination, sipHeaders = [], sipHost, sipUser, sipPassword, sipProfile, gatewaySettingsMode, from, muteRecording, disableRingback, } = this.data;
|
|
62
|
+
const timeout = Number(sessionTimeout);
|
|
63
|
+
const inheritGatewaySetting = gatewaySettingsMode === 'inherit';
|
|
64
|
+
const headers = Object.fromEntries(sipHeaders.map(({ name, value }) => [name, value]));
|
|
65
|
+
let gateway;
|
|
66
|
+
const profile = sipProfile !== "default" /* SIP_PROFILE.DEFAULT */ ? sipProfile : undefined;
|
|
67
|
+
switch (gatewaySettingsMode) {
|
|
68
|
+
case "custom" /* GATEWAY_SETTINGS_MODE.CUSTOM */:
|
|
69
|
+
gateway = {
|
|
70
|
+
host: sipHost,
|
|
71
|
+
user: sipUser,
|
|
72
|
+
username: sipUser,
|
|
73
|
+
password: sipPassword,
|
|
74
|
+
profile
|
|
75
|
+
};
|
|
76
|
+
break;
|
|
77
|
+
case "profile" /* GATEWAY_SETTINGS_MODE.PROFILE */:
|
|
78
|
+
gateway = profile != null ? { profile } : undefined;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
const botNumber = inheritGatewaySetting ? from : call.botNumber;
|
|
82
|
+
const maxLoops = this.session.data?.loopPrevention?.enabled
|
|
83
|
+
? this.session.data.loopPrevention.maxLoops
|
|
84
|
+
: undefined;
|
|
85
|
+
const command = {
|
|
86
|
+
name: 'bridgeTranslated',
|
|
87
|
+
params: {
|
|
88
|
+
botNumber,
|
|
89
|
+
transferFrom: phoneNumber,
|
|
90
|
+
transferTo: destination,
|
|
91
|
+
headers,
|
|
92
|
+
gateway,
|
|
93
|
+
timeout,
|
|
94
|
+
maxLoops,
|
|
95
|
+
...(disableRingback && { ringback: 'silence_stream://-1' }),
|
|
96
|
+
...this.translationParams()
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const muteAfterAnswer = !!muteRecording;
|
|
100
|
+
await this.pauseRecording(call, command, {
|
|
101
|
+
muteStep: muteAfterAnswer,
|
|
102
|
+
muteBot: muteAfterAnswer,
|
|
103
|
+
muteUser: muteAfterAnswer
|
|
104
|
+
});
|
|
105
|
+
await this.transcript(call, {
|
|
106
|
+
action: 'Live Translation Start',
|
|
107
|
+
actionFromBot: true,
|
|
108
|
+
reportingSettingsKey: 'transcript'
|
|
109
|
+
});
|
|
110
|
+
return this.exitFlow();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
translationParams() {
|
|
114
|
+
const { caller_language, destination_language, translator = {}, echo_protection = true, dub, agent_url_overwritten = false, agent_url = '', } = this.data;
|
|
115
|
+
let agentCustomUrl = '';
|
|
116
|
+
if (this.isStepFlagEnabled(agent_url_overwritten)) {
|
|
117
|
+
if (!this.isValidAgentUrl(agent_url)) {
|
|
118
|
+
this.throwError(new Error(`Voice Live Translation: invalid agent url "${agent_url}"`));
|
|
119
|
+
}
|
|
120
|
+
agentCustomUrl = agent_url;
|
|
121
|
+
}
|
|
122
|
+
const options = lodash_1.default.omitBy(translator.options, lodash_1.default.isEmpty);
|
|
123
|
+
return {
|
|
124
|
+
...(agentCustomUrl && { agent_url: agentCustomUrl }),
|
|
125
|
+
caller_language,
|
|
126
|
+
destination_language,
|
|
127
|
+
translator: lodash_1.default.omitBy({
|
|
128
|
+
provider: translator.provider || 'pinch',
|
|
129
|
+
model: translator.model,
|
|
130
|
+
api_key: translator.api_key,
|
|
131
|
+
options: lodash_1.default.isEmpty(options) ? undefined : options
|
|
132
|
+
}, lodash_1.default.isEmpty),
|
|
133
|
+
echo_protection,
|
|
134
|
+
...(dub?.enabled && {
|
|
135
|
+
dub: {
|
|
136
|
+
enabled: true,
|
|
137
|
+
...lodash_1.default.mapValues(lodash_1.default.omitBy(lodash_1.default.omit(dub, 'enabled'), value => value === '' || lodash_1.default.isNil(value)), Number)
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
isStepFlagEnabled(value) {
|
|
143
|
+
return value === true || value === 'true';
|
|
144
|
+
}
|
|
145
|
+
isValidAgentUrl(value) {
|
|
146
|
+
return /^wss?:\/\/([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+|\[[a-fA-F0-9:]+\])(:\d+)?(\/\S*)?$/.test(value);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.default = VoiceLiveTranslation;
|
package/dst/voice.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface IVoiceCall extends IConversationData {
|
|
|
33
33
|
user: string;
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
export type EventType = 'hangup' | 'ack' | 'error' | 'cancel' | 'background' | 'avm-detected' | 'recognition' | 'digit' | 'digits' | 'conference-start' | 'conference-end' | 'playback' | 'timeout' | 'record' | 'bridge' | 'bridge/ended' | 'is_flow_ready' | 'call' | 'dtmf-sent';
|
|
36
|
+
export type EventType = 'hangup' | 'ack' | 'error' | 'cancel' | 'background' | 'avm-detected' | 'recognition' | 'digit' | 'digits' | 'conference-start' | 'conference-end' | 'playback' | 'timeout' | 'record' | 'bridge' | 'bridge/ended' | 'translation/started' | 'translation/error' | 'translation/stopped' | 'is_flow_ready' | 'call' | 'dtmf-sent';
|
|
37
37
|
export declare class VoiceStepError extends BasicError {
|
|
38
38
|
}
|
|
39
39
|
export type VoicerError = Error & {
|