@onereach/step-voice 7.0.27 → 7.0.28-VOIC1701.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/Extend Voice Agent.d.ts +23 -0
- package/dst/Extend Voice Agent.js +69 -0
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import VoiceStep from './voice';
|
|
2
|
+
type SystemInstructionMode = 'append' | 'replace' | 'off';
|
|
3
|
+
interface Handler {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
parameters: string | Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
interface INPUT {
|
|
9
|
+
system_instruction_enabled: boolean;
|
|
10
|
+
system_instruction_mode: SystemInstructionMode;
|
|
11
|
+
system_instruction: string;
|
|
12
|
+
developer_messages: Array<string | {
|
|
13
|
+
message?: string;
|
|
14
|
+
}>;
|
|
15
|
+
handlers: Handler[];
|
|
16
|
+
}
|
|
17
|
+
export default class ExtendVoiceAgent extends VoiceStep<Partial<INPUT>> {
|
|
18
|
+
runStep(): Promise<void>;
|
|
19
|
+
private normalizeMessages;
|
|
20
|
+
private buildTools;
|
|
21
|
+
private isStepFlagEnabled;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
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 ExtendVoiceAgent extends voice_1.default {
|
|
7
|
+
async runStep() {
|
|
8
|
+
const call = await this.fetchData();
|
|
9
|
+
this.triggers.otherwise(async () => {
|
|
10
|
+
const { system_instruction_enabled = false, system_instruction_mode = 'append', system_instruction = '', developer_messages = [], handlers = [], } = this.data;
|
|
11
|
+
const params = {};
|
|
12
|
+
if (this.isStepFlagEnabled(system_instruction_enabled)
|
|
13
|
+
&& system_instruction_mode !== 'off'
|
|
14
|
+
&& !lodash_1.default.isEmpty(lodash_1.default.trim(String(system_instruction)))) {
|
|
15
|
+
params.system_instruction = {
|
|
16
|
+
mode: system_instruction_mode === 'replace' ? 'replace' : 'append',
|
|
17
|
+
text: String(system_instruction),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const rules = this.normalizeMessages(developer_messages);
|
|
21
|
+
if (rules.length > 0) {
|
|
22
|
+
params.developer_messages = rules;
|
|
23
|
+
}
|
|
24
|
+
const tools = this.buildTools(handlers);
|
|
25
|
+
if (tools && tools.length > 0) {
|
|
26
|
+
params.tools = tools;
|
|
27
|
+
}
|
|
28
|
+
if (!params.system_instruction && !params.developer_messages && !params.tools) {
|
|
29
|
+
this.throwError(new Error('Extend Voice Agent: provide a system instruction update, at least one rule, or at least one function'));
|
|
30
|
+
}
|
|
31
|
+
await this.sendCommands(call, [{ name: 'updateAgent', params }]);
|
|
32
|
+
return this.exitStep('next');
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
normalizeMessages(messages) {
|
|
36
|
+
return (messages || [])
|
|
37
|
+
.map(item => typeof item === 'string' ? item : item?.message ?? '')
|
|
38
|
+
.map(msg => lodash_1.default.trim(String(msg)))
|
|
39
|
+
.filter(msg => !lodash_1.default.isEmpty(msg));
|
|
40
|
+
}
|
|
41
|
+
buildTools(handlers) {
|
|
42
|
+
return (handlers || [])
|
|
43
|
+
.filter(h => h && !lodash_1.default.isEmpty(lodash_1.default.trim(h.name)))
|
|
44
|
+
.map(h => {
|
|
45
|
+
let parameters = {};
|
|
46
|
+
if (typeof h.parameters === 'string') {
|
|
47
|
+
try {
|
|
48
|
+
parameters = JSON.parse(h.parameters) || {};
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
parameters = {};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else if (h.parameters && typeof h.parameters === 'object') {
|
|
55
|
+
parameters = h.parameters;
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
type: 'function',
|
|
59
|
+
name: lodash_1.default.trim(h.name),
|
|
60
|
+
description: h.description || '',
|
|
61
|
+
parameters,
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
isStepFlagEnabled(value) {
|
|
66
|
+
return value === true || value === 'true' || value === 1 || value === '1';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.default = ExtendVoiceAgent;
|