@@ -18,10 +18,10 @@ import {
1818import { logAskError } from "../exceptions" ;
1919import { Logger } from "../logger" ;
2020import { SmapiClientFactory } from "../runtime" ;
21- import { callAvsForRecognizeEvent } from "../utils /avs/simulateAVSHelper" ;
22- import { exportFileForReplay } from "../utils /simulateReplayHelper" ;
23- import * as simulateSkillHelper from "../utils /simulateSkillHelper" ;
24- import { getAvailableLocales } from "../utils /skillHelper" ;
21+ import { callAvsForRecognizeEvent } from "./avs/simulateAVSHelper" ;
22+ import { exportFileForReplay } from "./simulateReplayHelper" ;
23+ import * as simulateSkillHelper from "./simulateSkillHelper" ;
24+ import { getAvailableLocales } from "./skillHelper" ;
2525import { AVSClient } from "./avs/avsClient" ;
2626import { readDeviceToken } from "./avs/deviceTokenUtil" ;
2727
@@ -47,20 +47,47 @@ export async function handleSkillStatusMessageFromWebview(
4747 await simulateSkillHelper . enableSkill ( profile , skillId , context ) ;
4848 isSkillEnabled = true ;
4949 return SIMULATOR_WEBVIEW_MESSAGES . ENABLED_SKILL ;
50- } else if ( webviewMessage . message === SIMULATOR_WEBVIEW_MESSAGES . DISABLE_SKILL ) {
50+ }
51+ if ( webviewMessage . message === SIMULATOR_WEBVIEW_MESSAGES . DISABLE_SKILL ) {
5152 const skillEnabled = await simulateSkillHelper . checkSkillStatus ( profile , skillId , context ) ;
5253 if ( skillEnabled ) {
5354 await simulateSkillHelper . disableSkill ( profile , skillId , context ) ;
5455 }
5556 isSkillEnabled = false ;
5657 return SIMULATOR_WEBVIEW_MESSAGES . DISABLED_SKILL ;
57- } else if ( webviewMessage . message === SIMULATOR_WEBVIEW_MESSAGES . CHECK_SKILL_STATUS ) {
58+ }
59+ if ( webviewMessage . message === SIMULATOR_WEBVIEW_MESSAGES . CHECK_SKILL_STATUS ) {
5860 currentSkillId = skillId ;
5961 const skillEnabled = await simulateSkillHelper . checkSkillStatus ( profile , skillId , context ) ;
6062 isSkillEnabled = skillEnabled ;
6163 return skillEnabled ? SIMULATOR_WEBVIEW_MESSAGES . ENABLED_SKILL : SIMULATOR_WEBVIEW_MESSAGES . DISABLED_SKILL ;
62- } else {
63- throw logAskError ( ERRORS . UNRECOGNIZED_MESSAGE_FROM_WEBVIEW ) ;
64+ }
65+
66+ throw logAskError ( ERRORS . UNRECOGNIZED_MESSAGE_FROM_WEBVIEW ) ;
67+ }
68+
69+ /**
70+ * Call SMAPI to get the realtime invocation name.
71+ * @param profile
72+ * @param skillId
73+ * @param context
74+ */
75+ export async function getInvocationName ( profile : string , skillId : string , context : vscode . ExtensionContext ) {
76+ Logger . verbose ( `Calling method: simulateMessageHelper.getInvocationName` ) ;
77+ try {
78+ const smapiClient = SmapiClientFactory . getInstance ( profile , context ) ;
79+ const interactionModelResponse : model . v1 . skill . interactionModel . InteractionModelData = await smapiClient . getInteractionModelV1 (
80+ skillId ,
81+ "development" ,
82+ currentLocale ,
83+ ) ;
84+ const invocationName = `open ${ interactionModelResponse . interactionModel ?. languageModel ?. invocationName ?. toString ( ) } ` ;
85+ return invocationName ;
86+ } catch ( err ) {
87+ if ( err . statusCode === 404 ) {
88+ vscode . window . showErrorMessage ( `There is no interaction model for ${ currentLocale } . Select a different locale.` ) ;
89+ }
90+ return "open my skill" ;
6491 }
6592}
6693
@@ -96,7 +123,8 @@ export async function handleLocaleMessageFromWebview(
96123 invocationName,
97124 type : SIMULATOR_MESSAGE_TYPE . LOCALE ,
98125 } ;
99- } else if ( webviewMessage . message === SIMULATOR_WEBVIEW_MESSAGES . UPDATE_LOCALE ) {
126+ }
127+ if ( webviewMessage . message === SIMULATOR_WEBVIEW_MESSAGES . UPDATE_LOCALE ) {
100128 currentLocale = webviewMessage . skillLocale ;
101129 const invocationName = await getInvocationName ( profile , skillId , context ) ;
102130 if ( isAVSMode ) {
@@ -107,9 +135,9 @@ export async function handleLocaleMessageFromWebview(
107135 invocationName,
108136 type : SIMULATOR_MESSAGE_TYPE . LOCALE ,
109137 } ;
110- } else {
111- throw logAskError ( ERRORS . UNRECOGNIZED_MESSAGE_FROM_WEBVIEW ) ;
112138 }
139+
140+ throw logAskError ( ERRORS . UNRECOGNIZED_MESSAGE_FROM_WEBVIEW ) ;
113141}
114142
115143/**
@@ -127,9 +155,9 @@ export async function handleUtteranceMessageFromWebview(
127155 isAVSMode : boolean ,
128156) : Promise < void | Record < string , any > > {
129157 Logger . verbose ( `Calling method: simulateMessageHelper.handleUtteranceMessageFromWebview` ) ;
130- const userInput : string = webviewMessage . userInput ;
131- const skillLocale : string = webviewMessage . skillLocale ;
132- const sessionMode : boolean = webviewMessage . sessionMode ;
158+ const { userInput} = webviewMessage ;
159+ const { skillLocale} = webviewMessage ;
160+ const { sessionMode} = webviewMessage ;
133161 try {
134162 let returnMessage ;
135163 if ( isAVSMode ) {
@@ -179,11 +207,11 @@ export async function handleExportMessageFromWebview(
179207export function handleActionMessageFromWebview ( webviewMessage : Record < string , string > , skillId : string , isAVSMode : boolean ) : void {
180208 Logger . verbose ( `Calling method: simulateMessageHelper.handleActionMessageFromWebview` ) ;
181209 const platform = os . platform ( ) ;
182- //Show registry webview for windows and macOS when simulator in SMAPI mode and has APL document for preview.
210+ // Show registry webview for windows and macOS when simulator in SMAPI mode and has APL document for preview.
183211 if ( ! isAVSMode && simulateSkillHelper . aplDocument !== undefined ) {
184212 if ( platform === "darwin" || platform === "win32" ) {
185213 const register = "Register device" ;
186- void vscode . window
214+ vscode . window
187215 . showInformationMessage (
188216 `APL touch interactions require creating an AVS virtual device.
189217 [Learn more](https://developer.amazon.com/en-US/docs/alexa/ask-toolkit/vs-code-testing-simulator.html#register-device)` ,
@@ -199,41 +227,16 @@ export function handleActionMessageFromWebview(webviewMessage: Record<string, st
199227 locale = locale . replace ( "-" , "_" ) ;
200228 const goToConsole = "Go to Alexa Developer Console" ;
201229 const link = SKILL_ACTION_URLS . SIMULATOR ( skillId , locale ) ;
202- void vscode . window
230+ vscode . window
203231 . showInformationMessage (
204232 "This extension supports interacting with the Alexa Presentation Language on MacOS and Windows only. For other platforms please go to the developer console. " ,
205233 goToConsole ,
206234 )
207235 . then ( ( selection ) => {
208236 if ( selection === goToConsole ) {
209- void vscode . env . openExternal ( vscode . Uri . parse ( link ) ) ;
237+ vscode . env . openExternal ( vscode . Uri . parse ( link ) ) ;
210238 }
211239 } ) ;
212240 }
213241 }
214242}
215-
216- /**
217- * Call SMAPI to get the realtime invocation name.
218- * @param profile
219- * @param skillId
220- * @param context
221- */
222- export async function getInvocationName ( profile : string , skillId : string , context : vscode . ExtensionContext ) {
223- Logger . verbose ( `Calling method: simulateMessageHelper.getInvocationName` ) ;
224- try {
225- const smapiClient = SmapiClientFactory . getInstance ( profile , context ) ;
226- const interactionModelResponse : model . v1 . skill . interactionModel . InteractionModelData = await smapiClient . getInteractionModelV1 (
227- skillId ,
228- "development" ,
229- currentLocale ,
230- ) ;
231- const invocationName = "open " + interactionModelResponse . interactionModel ?. languageModel ?. invocationName ?. toString ( ) ;
232- return invocationName ;
233- } catch ( err ) {
234- if ( err . statusCode === 404 ) {
235- void vscode . window . showErrorMessage ( `There is no interaction model for ${ currentLocale } . Select a different locale.` ) ;
236- }
237- throw logAskError ( "There was a problem downloading the interaction model. Try the download again." , err ) ;
238- }
239- }
0 commit comments