@absolutejs/voice 0.0.22-beta.626 → 0.0.22-beta.627
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/dist/core/types.d.ts +6 -1
- package/dist/index.js +24 -2
- package/dist/testing/index.js +12 -1
- package/package.json +1 -1
package/dist/core/types.d.ts
CHANGED
|
@@ -46,6 +46,11 @@ export type VoiceLanguageStrategy = {
|
|
|
46
46
|
primaryLanguage?: string;
|
|
47
47
|
secondaryLanguages: string[];
|
|
48
48
|
};
|
|
49
|
+
export type VoiceLanguageStrategyResolver<TContext = unknown> = (input: {
|
|
50
|
+
context: TContext;
|
|
51
|
+
scenarioId?: string;
|
|
52
|
+
sessionId: string;
|
|
53
|
+
}) => Promise<VoiceLanguageStrategy | void> | VoiceLanguageStrategy | void;
|
|
49
54
|
export type VoicePhraseHint = {
|
|
50
55
|
text: string;
|
|
51
56
|
aliases?: string[];
|
|
@@ -825,7 +830,7 @@ export type VoicePluginConfig<TContext = unknown, TSession extends VoiceSessionR
|
|
|
825
830
|
}) => string | Promise<string>);
|
|
826
831
|
maxReprompts?: number;
|
|
827
832
|
};
|
|
828
|
-
languageStrategy?: VoiceLanguageStrategy
|
|
833
|
+
languageStrategy?: VoiceLanguageStrategy | VoiceLanguageStrategyResolver<TContext>;
|
|
829
834
|
lexicon?: VoiceLexiconEntry[] | VoiceLexiconResolver<TContext>;
|
|
830
835
|
phraseHints?: VoicePhraseHint[] | VoicePhraseHintResolver<TContext>;
|
|
831
836
|
preset?: VoiceRuntimePreset;
|
package/dist/index.js
CHANGED
|
@@ -25618,6 +25618,16 @@ var createTwilioMediaStreamBridge = (socket, options) => {
|
|
|
25618
25618
|
}
|
|
25619
25619
|
return normalizePhraseHints(options.phraseHints);
|
|
25620
25620
|
};
|
|
25621
|
+
const resolveLanguageStrategy = async () => {
|
|
25622
|
+
if (typeof options.languageStrategy === "function") {
|
|
25623
|
+
return await options.languageStrategy({
|
|
25624
|
+
context: options.context,
|
|
25625
|
+
scenarioId: bridgeState.scenarioId ?? undefined,
|
|
25626
|
+
sessionId: bridgeState.sessionId ?? ""
|
|
25627
|
+
}) ?? undefined;
|
|
25628
|
+
}
|
|
25629
|
+
return options.languageStrategy;
|
|
25630
|
+
};
|
|
25621
25631
|
const ensureSession = async () => {
|
|
25622
25632
|
if (sessionHandle) {
|
|
25623
25633
|
return sessionHandle;
|
|
@@ -25625,6 +25635,7 @@ var createTwilioMediaStreamBridge = (socket, options) => {
|
|
|
25625
25635
|
bridgeState.sessionId ??= `phone-${Date.now().toString(36)}`;
|
|
25626
25636
|
const lexicon = await resolveLexicon();
|
|
25627
25637
|
const phraseHints = await resolvePhraseHints();
|
|
25638
|
+
const languageStrategy = await resolveLanguageStrategy();
|
|
25628
25639
|
const normalizedOnTurn = normalizeOnTurn(options.onTurn);
|
|
25629
25640
|
const route = {
|
|
25630
25641
|
correctTurn: options.correctTurn,
|
|
@@ -25663,7 +25674,7 @@ var createTwilioMediaStreamBridge = (socket, options) => {
|
|
|
25663
25674
|
costTelephony: options.costTelephony,
|
|
25664
25675
|
greeting: options.greeting,
|
|
25665
25676
|
id: bridgeState.sessionId,
|
|
25666
|
-
languageStrategy
|
|
25677
|
+
languageStrategy,
|
|
25667
25678
|
lexicon,
|
|
25668
25679
|
logger,
|
|
25669
25680
|
phraseHints,
|
|
@@ -39823,6 +39834,12 @@ var resolveLexicon = async (config, input) => {
|
|
|
39823
39834
|
}
|
|
39824
39835
|
return normalizeLexicon2(config.lexicon);
|
|
39825
39836
|
};
|
|
39837
|
+
var resolveLanguageStrategy = async (config, input) => {
|
|
39838
|
+
if (typeof config.languageStrategy === "function") {
|
|
39839
|
+
return await config.languageStrategy(input) ?? undefined;
|
|
39840
|
+
}
|
|
39841
|
+
return config.languageStrategy;
|
|
39842
|
+
};
|
|
39826
39843
|
var resolveProfileSwitchGuard = async (config, runtime, input) => {
|
|
39827
39844
|
const guard = config.profileSwitchGuard;
|
|
39828
39845
|
if (!guard || runtime.profileSwitchGuardedSessions.has(input.sessionId)) {
|
|
@@ -39987,6 +40004,11 @@ var voice = (config) => {
|
|
|
39987
40004
|
scenarioId,
|
|
39988
40005
|
sessionId
|
|
39989
40006
|
});
|
|
40007
|
+
const languageStrategy = await resolveLanguageStrategy(config, {
|
|
40008
|
+
context,
|
|
40009
|
+
scenarioId,
|
|
40010
|
+
sessionId
|
|
40011
|
+
});
|
|
39990
40012
|
return createVoiceSession({
|
|
39991
40013
|
audioConditioning: sessionOptions.audioConditioning,
|
|
39992
40014
|
normalizeNumbers: sessionOptions.normalizeNumbers,
|
|
@@ -40000,7 +40022,7 @@ var voice = (config) => {
|
|
|
40000
40022
|
stuckCallClose: config.stuckCallClose,
|
|
40001
40023
|
idleReprompt: config.idleReprompt,
|
|
40002
40024
|
handoff: config.handoff,
|
|
40003
|
-
languageStrategy
|
|
40025
|
+
languageStrategy,
|
|
40004
40026
|
lexicon,
|
|
40005
40027
|
liveOps: config.liveOps,
|
|
40006
40028
|
logger: sessionOptions.logger,
|
package/dist/testing/index.js
CHANGED
|
@@ -14584,6 +14584,16 @@ var createTwilioMediaStreamBridge = (socket, options) => {
|
|
|
14584
14584
|
}
|
|
14585
14585
|
return normalizePhraseHints(options.phraseHints);
|
|
14586
14586
|
};
|
|
14587
|
+
const resolveLanguageStrategy = async () => {
|
|
14588
|
+
if (typeof options.languageStrategy === "function") {
|
|
14589
|
+
return await options.languageStrategy({
|
|
14590
|
+
context: options.context,
|
|
14591
|
+
scenarioId: bridgeState.scenarioId ?? undefined,
|
|
14592
|
+
sessionId: bridgeState.sessionId ?? ""
|
|
14593
|
+
}) ?? undefined;
|
|
14594
|
+
}
|
|
14595
|
+
return options.languageStrategy;
|
|
14596
|
+
};
|
|
14587
14597
|
const ensureSession = async () => {
|
|
14588
14598
|
if (sessionHandle) {
|
|
14589
14599
|
return sessionHandle;
|
|
@@ -14591,6 +14601,7 @@ var createTwilioMediaStreamBridge = (socket, options) => {
|
|
|
14591
14601
|
bridgeState.sessionId ??= `phone-${Date.now().toString(36)}`;
|
|
14592
14602
|
const lexicon = await resolveLexicon();
|
|
14593
14603
|
const phraseHints = await resolvePhraseHints();
|
|
14604
|
+
const languageStrategy = await resolveLanguageStrategy();
|
|
14594
14605
|
const normalizedOnTurn = normalizeOnTurn(options.onTurn);
|
|
14595
14606
|
const route = {
|
|
14596
14607
|
correctTurn: options.correctTurn,
|
|
@@ -14629,7 +14640,7 @@ var createTwilioMediaStreamBridge = (socket, options) => {
|
|
|
14629
14640
|
costTelephony: options.costTelephony,
|
|
14630
14641
|
greeting: options.greeting,
|
|
14631
14642
|
id: bridgeState.sessionId,
|
|
14632
|
-
languageStrategy
|
|
14643
|
+
languageStrategy,
|
|
14633
14644
|
lexicon,
|
|
14634
14645
|
logger,
|
|
14635
14646
|
phraseHints,
|