@onereach/step-voice 7.0.48 → 7.0.49-VOIC1799.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.
@@ -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;
@@ -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,48 @@ 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
+ const timezone = lodash_1.default.trim(String(working_hours_timezone || '')) || 'UTC';
322
+ const closedMessage = lodash_1.default.trim(String(working_hours_closed_message || '')) || DEFAULT_CLOSED_MESSAGE;
323
+ return {
324
+ working_hours: {
325
+ enabled: true,
326
+ timezone,
327
+ schedules,
328
+ closed_message: closedMessage
329
+ }
330
+ };
331
+ }
332
+ buildWorkingHoursSchedules(days) {
333
+ const groups = new Map();
334
+ const order = [];
335
+ for (const day of WORKING_HOURS_DAYS) {
336
+ const row = days[day];
337
+ if (!row || !this.isStepFlagEnabled(row.enabled))
338
+ continue;
339
+ const start = String(row.start || '');
340
+ const end = String(row.end || '');
341
+ if (!WORKING_HOURS_HHMM.test(start) || !WORKING_HOURS_HHMM.test(end)) {
342
+ this.throwError(new Error(`Voice Agent: working hours for ${day} must use HH:MM`));
343
+ }
344
+ if (start === end) {
345
+ this.throwError(new Error(`Voice Agent: working hours for ${day} start and end must differ`));
346
+ }
347
+ const key = `${start}|${end}`;
348
+ const existing = groups.get(key);
349
+ if (existing) {
350
+ existing.days.push(day);
351
+ continue;
352
+ }
353
+ groups.set(key, { days: [day], start, end });
354
+ order.push(key);
355
+ }
356
+ return order.map(key => groups.get(key));
357
+ }
312
358
  isValidAgentUrl(value) {
313
359
  return /^wss?:\/\/([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+|\[[a-fA-F0-9:]+\])(:\d+)?(\/\S*)?$/.test(value);
314
360
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/step-voice",
3
- "version": "7.0.48",
3
+ "version": "7.0.49-VOIC1799.1",
4
4
  "author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
5
5
  "contributors": [
6
6
  "Roman Zolotarov",