@onereach/step-voice 5.0.9-fixsubflow.10 → 5.0.9-fixsubflow.11
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/Global Command.d.ts +1 -1
- package/dst/Global Command.js +17 -1
- package/dst/step.d.ts +0 -5
- package/dst/step.js +1 -164
- package/package.json +1 -1
package/dst/Global Command.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export default class GlobalCommand extends VoiceStep<Partial<INPUT>, OUTPUT, EVE
|
|
|
32
32
|
get useQueue(): boolean;
|
|
33
33
|
runStep(): Promise<void>;
|
|
34
34
|
initGrammar(): Promise<void>;
|
|
35
|
-
|
|
35
|
+
worker(): Promise<void>;
|
|
36
36
|
hangup(call: IVoiceCall): Promise<unknown>;
|
|
37
37
|
exitThread(event: ITypedEvent<EVENT>, type: string, stepExit: string): Promise<void>;
|
|
38
38
|
onAwake(): Promise<void>;
|
package/dst/Global Command.js
CHANGED
|
@@ -13,6 +13,22 @@ class GlobalCommand extends voice_1.default {
|
|
|
13
13
|
return this.isWorker;
|
|
14
14
|
}
|
|
15
15
|
async runStep() {
|
|
16
|
+
const worker = this.process.newThread(this.workerThreadId, thread => {
|
|
17
|
+
thread.state = {
|
|
18
|
+
name: 'worker',
|
|
19
|
+
step: this.step.id,
|
|
20
|
+
thread: this.dataThreadId
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
if (worker.isNewThread) {
|
|
24
|
+
worker.activate();
|
|
25
|
+
await worker.run();
|
|
26
|
+
await this._refreshCache();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
worker.state.step = this.step.id;
|
|
30
|
+
await this.initGrammar();
|
|
31
|
+
}
|
|
16
32
|
this.exitStep('no commands');
|
|
17
33
|
}
|
|
18
34
|
async initGrammar() {
|
|
@@ -45,7 +61,7 @@ class GlobalCommand extends voice_1.default {
|
|
|
45
61
|
}
|
|
46
62
|
]);
|
|
47
63
|
}
|
|
48
|
-
async
|
|
64
|
+
async worker() {
|
|
49
65
|
const call = await this.fetchData();
|
|
50
66
|
this.triggers.otherwise(async () => {
|
|
51
67
|
await this.initGrammar();
|
package/dst/step.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ export declare const enum ConvThreadType {
|
|
|
17
17
|
}
|
|
18
18
|
export default class ConvStep<TData extends IConversationData, TIn = unknown, TOut = unknown, TParams = any> extends Step<TIn & ConvStepDataIn, TOut, TParams> {
|
|
19
19
|
private convDataCache?;
|
|
20
|
-
_worker(_data: IConversationData): Promise<void>;
|
|
21
20
|
get cache(): TData | undefined;
|
|
22
21
|
get conversation(): string | IMergeField;
|
|
23
22
|
get conversationId(): string;
|
|
@@ -32,9 +31,7 @@ export default class ConvStep<TData extends IConversationData, TIn = unknown, TO
|
|
|
32
31
|
getConversation(): Promise<IConversation>;
|
|
33
32
|
updateData(): Promise<void>;
|
|
34
33
|
hasConversation(): Promise<boolean>;
|
|
35
|
-
protected worker(): Promise<void>;
|
|
36
34
|
runBefore(): Promise<void>;
|
|
37
|
-
runAfter(): Promise<void>;
|
|
38
35
|
waitForConversation(): Promise<void>;
|
|
39
36
|
protected onSkipEvent(): Promise<void>;
|
|
40
37
|
cancel(): Promise<void>;
|
|
@@ -51,8 +48,6 @@ export default class ConvStep<TData extends IConversationData, TIn = unknown, TO
|
|
|
51
48
|
onConvEnd(): Promise<void>;
|
|
52
49
|
pause(): Promise<void>;
|
|
53
50
|
resume(): Promise<void>;
|
|
54
|
-
/** @returns true if current conv is active */
|
|
55
|
-
/** @returns true if current conv was active */
|
|
56
51
|
startConversation(data: TData, { thread }?: {
|
|
57
52
|
thread?: IThreadId;
|
|
58
53
|
}): Promise<void>;
|
package/dst/step.js
CHANGED
|
@@ -13,7 +13,6 @@ const step_1 = tslib_1.__importDefault(require("@onereach/flow-sdk/dst/step"));
|
|
|
13
13
|
// step?: string // for debug
|
|
14
14
|
// }
|
|
15
15
|
class ConvStep extends step_1.default {
|
|
16
|
-
async _worker(_data) { }
|
|
17
16
|
get cache() {
|
|
18
17
|
return this.convDataCache;
|
|
19
18
|
}
|
|
@@ -76,16 +75,11 @@ class ConvStep extends step_1.default {
|
|
|
76
75
|
async hasConversation() {
|
|
77
76
|
return (await this._fetchCache())?._conv != null;
|
|
78
77
|
}
|
|
79
|
-
async worker() {
|
|
80
|
-
this.triggers.local('_conv');
|
|
81
|
-
if (this.cache == null)
|
|
82
|
-
return;
|
|
83
|
-
await this._worker(this.cache);
|
|
84
|
-
}
|
|
85
78
|
async runBefore() {
|
|
86
79
|
await super.runBefore();
|
|
87
80
|
if (this.thread.ending)
|
|
88
81
|
return;
|
|
82
|
+
this.triggers.local('_conv');
|
|
89
83
|
// ensure cache is reset between step runs, just in case
|
|
90
84
|
this._clearCache();
|
|
91
85
|
if (!await this.hasConversation())
|
|
@@ -97,79 +91,8 @@ class ConvStep extends step_1.default {
|
|
|
97
91
|
this.event.processed = true;
|
|
98
92
|
this.state.prevName = this.state.name;
|
|
99
93
|
this.state.name = this.event.action;
|
|
100
|
-
return;
|
|
101
94
|
}
|
|
102
|
-
console.log('BEFORE', {
|
|
103
|
-
event: this.event,
|
|
104
|
-
state: this.state,
|
|
105
|
-
name: this.constructor.name,
|
|
106
|
-
thread: this.thread.id,
|
|
107
|
-
...this.cache?._conv
|
|
108
|
-
});
|
|
109
|
-
// if (this.useQueue && !await this.pushConvStep()) {
|
|
110
|
-
// return await this.waitForConversation()
|
|
111
|
-
// }
|
|
112
|
-
if (this.cache == null)
|
|
113
|
-
return;
|
|
114
|
-
// const glb = this.cache._conv.glb
|
|
115
|
-
// if (!this.isGlobal && glb.length > 0 && glb[glb.length - 1].typ !== ConvThreadType.wrk) return
|
|
116
|
-
if (!this.isGlobal)
|
|
117
|
-
return;
|
|
118
|
-
if (this.thread.id !== this.workerThreadId) {
|
|
119
|
-
const worker = this.process.newThread(this.workerThreadId, thread => {
|
|
120
|
-
thread.state = {
|
|
121
|
-
name: 'worker',
|
|
122
|
-
step: this.step.id,
|
|
123
|
-
thread: this.dataThreadId
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
if (worker.isNewThread) {
|
|
127
|
-
worker.activate();
|
|
128
|
-
await worker.run();
|
|
129
|
-
await this._refreshCache();
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
worker.state.step = this.step.id;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
// public async runHandle (): Promise<unknown> {
|
|
137
|
-
// if (this.thread.ending || this.state.name === 'onConvEnd') {
|
|
138
|
-
// return await super.runHandle()
|
|
139
|
-
// }
|
|
140
|
-
// // const sid = this.cache?._conv.sid
|
|
141
|
-
// // if (sid != null && sid !== this.session.sessionId) {
|
|
142
|
-
// // this.triggers.refreshAll()
|
|
143
|
-
// // }
|
|
144
|
-
// return await super.runHandle()
|
|
145
|
-
// }
|
|
146
|
-
async runAfter() {
|
|
147
|
-
console.log('AFTER', {
|
|
148
|
-
name: this.constructor.name,
|
|
149
|
-
thread: this.thread.id,
|
|
150
|
-
...this.cache?._conv
|
|
151
|
-
});
|
|
152
|
-
// if (this.thread.ending || this.state.name === 'onConvEnd') {
|
|
153
|
-
// return await super.runAfter()
|
|
154
|
-
// }
|
|
155
|
-
// if (!await this.hasConversation()) return await super.runAfter()
|
|
156
|
-
// if (this.thread.hasControlAction()) {
|
|
157
|
-
// // await this.popConvStep()
|
|
158
|
-
// if (await this.popConvStep()) {
|
|
159
|
-
// // TODO: this seems not to be necessary now or not?
|
|
160
|
-
// await this.sendEventToStep({ toGlobal: this.isGlobal, action: 'onAwake' })
|
|
161
|
-
// }
|
|
162
|
-
// }
|
|
163
|
-
// if (this.isGlobal && !this.event.processed) {
|
|
164
|
-
// await this.sendEventToStep({ toGlobal: false, event: { ...this.event, processed: undefined, action: 'lcl' } })
|
|
165
|
-
// }
|
|
166
|
-
await super.runAfter();
|
|
167
95
|
}
|
|
168
|
-
// public async setLocalTriggers (): Promise<void> {
|
|
169
|
-
// if (!this.isGlobal && await this.hasActiveGlobal()) {
|
|
170
|
-
// this.triggers.config({ target: 'session' })
|
|
171
|
-
// }
|
|
172
|
-
// }
|
|
173
96
|
async waitForConversation() {
|
|
174
97
|
if (this.state.name !== 'waitForConversation') {
|
|
175
98
|
this.log.debug(this.state, 'conv.begin waitForConversation');
|
|
@@ -286,92 +209,6 @@ class ConvStep extends step_1.default {
|
|
|
286
209
|
// this.log.debug('conv.nothing to resume')
|
|
287
210
|
// }
|
|
288
211
|
}
|
|
289
|
-
// protected async sendEventToStep ({
|
|
290
|
-
// toGlobal = false,
|
|
291
|
-
// toStep,
|
|
292
|
-
// action,
|
|
293
|
-
// event = { name: '_conv', action }
|
|
294
|
-
// }: {
|
|
295
|
-
// action?: string
|
|
296
|
-
// event?: IEvent
|
|
297
|
-
// toStep?: IConversationStep
|
|
298
|
-
// toGlobal?: boolean
|
|
299
|
-
// }): Promise<IStepResult | undefined> {
|
|
300
|
-
// toStep ||= await this.activeStep(toGlobal)
|
|
301
|
-
// if (toStep != null) {
|
|
302
|
-
// const target = { type: 'session' as any, name: toStep.key, id: toStep.trd }
|
|
303
|
-
// return await this.thread.eventManager.emit(
|
|
304
|
-
// event,
|
|
305
|
-
// { invocationType: 'async', target }
|
|
306
|
-
// )
|
|
307
|
-
// }
|
|
308
|
-
// return undefined
|
|
309
|
-
// }
|
|
310
|
-
// async activeStep (toGlobal: boolean): Promise<IConversationStep | undefined> {
|
|
311
|
-
// const conv = await this.getConversation()
|
|
312
|
-
// const que = toGlobal ? conv.glb : conv.lcl
|
|
313
|
-
// if (que == null) return
|
|
314
|
-
// const lastItem = que[que.length - 1]
|
|
315
|
-
// if (toGlobal && lastItem?.typ === ConvThreadType.wrk) return undefined
|
|
316
|
-
// return que[que.length - 1]
|
|
317
|
-
// }
|
|
318
|
-
/** @returns true if current conv is active */
|
|
319
|
-
// protected async pushConvStep (): Promise<boolean> {
|
|
320
|
-
// const conv = await this.getConversation()
|
|
321
|
-
// const sessionKey = this.session.key
|
|
322
|
-
// if (sessionKey == null) throw new Error('session is required')
|
|
323
|
-
// const que = this.isWorker ? conv.glb : conv.lcl
|
|
324
|
-
// const lastItem = que[que.length - 1]
|
|
325
|
-
// const lastItemType = lastItem?.typ
|
|
326
|
-
// if (lastItemType === ConvThreadType.wrk) {
|
|
327
|
-
// console.log('POP', lastItem)
|
|
328
|
-
// que.pop() // remove last item, since it's temporary
|
|
329
|
-
// // TODO triggers.refreshAll!
|
|
330
|
-
// }
|
|
331
|
-
// const queIndex = que.findIndex(stp => stp.key === sessionKey && this.thread.id === stp.trd)
|
|
332
|
-
// if (queIndex < 0) {
|
|
333
|
-
// if (que.length > 0) {
|
|
334
|
-
// await this.sendEventToStep({ toGlobal: this.isGlobal, event: { name: '_conv', action: 'onPause', params: { byStep: this.step.label } } })
|
|
335
|
-
// }
|
|
336
|
-
// const type = this.threadType === ConvThreadType.wrk ? this.threadType : undefined
|
|
337
|
-
// que.push({ key: sessionKey, trd: this.thread.id, typ: type, name: this.constructor.name, label: this.label, step: this.id })
|
|
338
|
-
// console.log('PUSH', que[que.length - 1])
|
|
339
|
-
// await this.updateData()
|
|
340
|
-
// return true
|
|
341
|
-
// }
|
|
342
|
-
// // refresh data on step change
|
|
343
|
-
// que[queIndex].name = this.constructor.name
|
|
344
|
-
// que[queIndex].label = this.label
|
|
345
|
-
// que[queIndex].step = this.id
|
|
346
|
-
// return queIndex === que.length - 1
|
|
347
|
-
// }
|
|
348
|
-
/** @returns true if current conv was active */
|
|
349
|
-
// protected async popConvStep (popStep?: IConversationStep): Promise<boolean> {
|
|
350
|
-
// const conv = await this.getConversation()
|
|
351
|
-
// const sessionKey = this.session.key
|
|
352
|
-
// if (sessionKey == null) throw new Error('session is required')
|
|
353
|
-
// popStep ||= { key: sessionKey, trd: this.thread.id }
|
|
354
|
-
// const que = this.isWorker ? conv.glb : conv.lcl
|
|
355
|
-
// const queIndex = que.findIndex(stp => stp.key === popStep?.key && stp.trd === popStep.trd)
|
|
356
|
-
// if (queIndex >= 0) {
|
|
357
|
-
// // console.log('SPLICE1', this.thread.id, this.step.label, que)
|
|
358
|
-
// que.splice(queIndex, 1)
|
|
359
|
-
// // conv.sid = this.session.sessionId
|
|
360
|
-
// await this.updateData()
|
|
361
|
-
// return queIndex === que.length
|
|
362
|
-
// }
|
|
363
|
-
// // let updated = false
|
|
364
|
-
// // conv.stk.forEach((steps, stepsIdx) => {
|
|
365
|
-
// // const stpIdx = steps.findIndex(stp => stp.key === sessionKey && this.thread.id === stp.thread)
|
|
366
|
-
// // if (stpIdx>= 0) {
|
|
367
|
-
// // if (steps.length> 1) steps.splice(stpIdx, 1)
|
|
368
|
-
// // else conv.stk.splice(stepsIdx, 1)
|
|
369
|
-
// // updated = true
|
|
370
|
-
// // }
|
|
371
|
-
// // })
|
|
372
|
-
// // if (updated) await this.updateData()
|
|
373
|
-
// return false
|
|
374
|
-
// }
|
|
375
212
|
async startConversation(data, { thread: _thread } = {}) {
|
|
376
213
|
this.convDataCache = {
|
|
377
214
|
...data,
|