@onereach/step-voice 7.0.48 → 7.0.49-VOIC1799.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 +12 -0
- package/dst/Voice Agent.js +50 -1
- package/package.json +1 -1
package/dst/Voice Agent.d.ts
CHANGED
|
@@ -68,6 +68,12 @@ interface AgentKnowledgeConfig {
|
|
|
68
68
|
id: string;
|
|
69
69
|
mode: KnowledgeMode;
|
|
70
70
|
}
|
|
71
|
+
type WorkingHoursDayKey = 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun';
|
|
72
|
+
interface WorkingHoursDayInput {
|
|
73
|
+
enabled?: boolean | string;
|
|
74
|
+
start?: string;
|
|
75
|
+
end?: string;
|
|
76
|
+
}
|
|
71
77
|
interface INPUT {
|
|
72
78
|
handlers: Handler[];
|
|
73
79
|
subagents: Subagent[];
|
|
@@ -98,6 +104,10 @@ interface INPUT {
|
|
|
98
104
|
soft_timeout?: SoftTimeoutConfig;
|
|
99
105
|
system_tools?: AgentSystemToolConfig[];
|
|
100
106
|
knowledge?: AgentKnowledgeConfig[];
|
|
107
|
+
working_hours_enabled?: boolean | string;
|
|
108
|
+
working_hours_timezone?: string;
|
|
109
|
+
working_hours_closed_message?: string;
|
|
110
|
+
working_hours_days?: Partial<Record<WorkingHoursDayKey, WorkingHoursDayInput>>;
|
|
101
111
|
}
|
|
102
112
|
export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
|
|
103
113
|
runStep(): Promise<void>;
|
|
@@ -112,6 +122,8 @@ export default class VoiceAgent extends VoiceStep<Partial<INPUT>> {
|
|
|
112
122
|
private isStepFlagEnabled;
|
|
113
123
|
private isRealtimePipeline;
|
|
114
124
|
private buildGreetingAndCallBehavior;
|
|
125
|
+
private buildWorkingHours;
|
|
126
|
+
private buildWorkingHoursSchedules;
|
|
115
127
|
private isValidAgentUrl;
|
|
116
128
|
private buildAgentServiceConfig;
|
|
117
129
|
private validatePerToolFeedback;
|
package/dst/Voice Agent.js
CHANGED
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
5
5
|
const voice_1 = tslib_1.__importDefault(require("./voice"));
|
|
6
|
+
const WORKING_HOURS_DAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
|
|
7
|
+
const WORKING_HOURS_HHMM = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
8
|
+
const DEFAULT_CLOSED_MESSAGE = 'Our office is closed. Please call back Monday to Friday, 9am to 5pm.';
|
|
6
9
|
class VoiceAgent extends voice_1.default {
|
|
7
10
|
async runStep() {
|
|
8
11
|
const call = await this.fetchData();
|
|
@@ -89,7 +92,8 @@ class VoiceAgent extends voice_1.default {
|
|
|
89
92
|
system_instruction,
|
|
90
93
|
developer_messages,
|
|
91
94
|
tools,
|
|
92
|
-
...(realtimePipeline ? {} : this.buildGreetingAndCallBehavior())
|
|
95
|
+
...(realtimePipeline ? {} : this.buildGreetingAndCallBehavior()),
|
|
96
|
+
...this.buildWorkingHours()
|
|
93
97
|
};
|
|
94
98
|
const serializedSubagents = this.serializeSubagents(subagents) || [];
|
|
95
99
|
if (serializedSubagents.length > 0) {
|
|
@@ -309,6 +313,51 @@ class VoiceAgent extends voice_1.default {
|
|
|
309
313
|
}
|
|
310
314
|
return settings;
|
|
311
315
|
}
|
|
316
|
+
buildWorkingHours() {
|
|
317
|
+
const { working_hours_enabled = false, working_hours_timezone = 'UTC', working_hours_closed_message = DEFAULT_CLOSED_MESSAGE, working_hours_days = {} } = this.data;
|
|
318
|
+
if (!this.isStepFlagEnabled(working_hours_enabled))
|
|
319
|
+
return {};
|
|
320
|
+
const schedules = this.buildWorkingHoursSchedules(working_hours_days);
|
|
321
|
+
if (schedules.length === 0) {
|
|
322
|
+
this.throwError(new Error('Voice Agent: turn on at least one day when working hours are enabled'));
|
|
323
|
+
}
|
|
324
|
+
const timezone = lodash_1.default.trim(String(working_hours_timezone || '')) || 'UTC';
|
|
325
|
+
const closedMessage = lodash_1.default.trim(String(working_hours_closed_message || '')) || DEFAULT_CLOSED_MESSAGE;
|
|
326
|
+
return {
|
|
327
|
+
working_hours: {
|
|
328
|
+
enabled: true,
|
|
329
|
+
timezone,
|
|
330
|
+
schedules,
|
|
331
|
+
closed_message: closedMessage
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
buildWorkingHoursSchedules(days) {
|
|
336
|
+
const groups = new Map();
|
|
337
|
+
const order = [];
|
|
338
|
+
for (const day of WORKING_HOURS_DAYS) {
|
|
339
|
+
const row = days[day];
|
|
340
|
+
if (!row || !this.isStepFlagEnabled(row.enabled))
|
|
341
|
+
continue;
|
|
342
|
+
const start = String(row.start || '');
|
|
343
|
+
const end = String(row.end || '');
|
|
344
|
+
if (!WORKING_HOURS_HHMM.test(start) || !WORKING_HOURS_HHMM.test(end)) {
|
|
345
|
+
this.throwError(new Error(`Voice Agent: working hours for ${day} must use HH:MM`));
|
|
346
|
+
}
|
|
347
|
+
if (start === end) {
|
|
348
|
+
this.throwError(new Error(`Voice Agent: working hours for ${day} start and end must differ`));
|
|
349
|
+
}
|
|
350
|
+
const key = `${start}|${end}`;
|
|
351
|
+
const existing = groups.get(key);
|
|
352
|
+
if (existing) {
|
|
353
|
+
existing.days.push(day);
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
groups.set(key, { days: [day], start, end });
|
|
357
|
+
order.push(key);
|
|
358
|
+
}
|
|
359
|
+
return order.map(key => groups.get(key));
|
|
360
|
+
}
|
|
312
361
|
isValidAgentUrl(value) {
|
|
313
362
|
return /^wss?:\/\/([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+|\[[a-fA-F0-9:]+\])(:\d+)?(\/\S*)?$/.test(value);
|
|
314
363
|
}
|