|
| 1 | +/*! |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import * as vscode from 'vscode' |
| 7 | +import globals from '../../shared/extensionGlobals' |
| 8 | +import path from 'path' |
| 9 | +import { MessagePublisher } from '../messages/messagePublisher' |
| 10 | +import { telemetry } from '../../shared/telemetry/telemetry' |
| 11 | +import { getLogger } from '../../shared/logger' |
| 12 | +import { placeholder } from '../../shared/vscode/commands2' |
| 13 | +import { focusAmazonQPanel } from '../../codewhispererChat/commands/registerCommands' |
| 14 | + |
| 15 | +export function welcome(context: vscode.ExtensionContext, cwcWebViewToAppsPublisher: MessagePublisher<any>): void { |
| 16 | + const panel = vscode.window.createWebviewPanel( |
| 17 | + 'amazonQWelcome', |
| 18 | + 'Meet Amazon Q (Preview)', |
| 19 | + vscode.ViewColumn.Active, |
| 20 | + { |
| 21 | + enableScripts: true, |
| 22 | + } |
| 23 | + ) |
| 24 | + |
| 25 | + // TODO: get svg gradient icon and use `getIcon` (currently only works with svg) |
| 26 | + panel.iconPath = vscode.Uri.file( |
| 27 | + globals.context.asAbsolutePath(path.join('resources', 'icons', 'aws', 'amazonq', 'q-gradient.svg')) |
| 28 | + ) |
| 29 | + |
| 30 | + panel.webview.html = getWebviewContent(panel.webview) |
| 31 | + |
| 32 | + // Handle messages from the webview |
| 33 | + panel.webview.onDidReceiveMessage( |
| 34 | + message => { |
| 35 | + telemetry.ui_click.run(() => { |
| 36 | + switch (message.command) { |
| 37 | + case 'sendToQ': |
| 38 | + telemetry.record({ elementId: 'amazonq_meet_askq' }) |
| 39 | + focusAmazonQPanel.execute(placeholder, 'sendToQ').then( |
| 40 | + () => { |
| 41 | + cwcWebViewToAppsPublisher.publish({ |
| 42 | + type: 'onboarding-page-cwc-button-clicked', |
| 43 | + command: 'onboarding-page-interaction', |
| 44 | + }) |
| 45 | + }, |
| 46 | + e => { |
| 47 | + getLogger().error('focusAmazonQPanel failed: %s', (e as Error).message) |
| 48 | + } |
| 49 | + ) |
| 50 | + |
| 51 | + return |
| 52 | + |
| 53 | + case 'goToHelp': |
| 54 | + telemetry.record({ elementId: 'amazonq_tryExamples' }) |
| 55 | + void vscode.commands.executeCommand('aws.codeWhisperer.gettingStarted') |
| 56 | + return |
| 57 | + } |
| 58 | + }) |
| 59 | + }, |
| 60 | + undefined, |
| 61 | + context.subscriptions |
| 62 | + ) |
| 63 | + |
| 64 | + // user closes webview |
| 65 | + // does this fire on IDE shutdown? |
| 66 | + panel.onDidDispose(() => { |
| 67 | + telemetry.ui_click.emit({ |
| 68 | + elementId: 'amazonq_closeWebview', |
| 69 | + passive: true, |
| 70 | + }) |
| 71 | + }) |
| 72 | +} |
| 73 | + |
| 74 | +function getWebviewContent(webview: vscode.Webview): string { |
| 75 | + const logo = webview.asWebviewUri( |
| 76 | + vscode.Uri.file( |
| 77 | + globals.context.asAbsolutePath(path.join('resources', 'icons', 'aws', 'amazonq', 'q-gradient.svg')) |
| 78 | + ) |
| 79 | + ) |
| 80 | + const bgLogoLight = webview.asWebviewUri( |
| 81 | + vscode.Uri.file( |
| 82 | + globals.context.asAbsolutePath(path.join('resources', 'icons', 'aws', 'amazonq', 'q-squid-ink.svg')) |
| 83 | + ) |
| 84 | + ) |
| 85 | + const bgLogoDark = webview.asWebviewUri( |
| 86 | + vscode.Uri.file( |
| 87 | + globals.context.asAbsolutePath(path.join('resources', 'icons', 'aws', 'amazonq', 'q-white.svg')) |
| 88 | + ) |
| 89 | + ) |
| 90 | + const cwLogoLight = webview.asWebviewUri( |
| 91 | + vscode.Uri.file( |
| 92 | + globals.context.asAbsolutePath(path.join('resources', 'icons', 'aws', 'codewhisperer', 'icon-black.svg')) |
| 93 | + ) |
| 94 | + ) |
| 95 | + const cwLogoDark = webview.asWebviewUri( |
| 96 | + vscode.Uri.file( |
| 97 | + globals.context.asAbsolutePath(path.join('resources', 'icons', 'aws', 'codewhisperer', 'icon-white.svg')) |
| 98 | + ) |
| 99 | + ) |
| 100 | + return ` |
| 101 | + <!DOCTYPE html> |
| 102 | + <html lang="en"> |
| 103 | + <head> |
| 104 | + <meta charset="UTF-8"> |
| 105 | + <meta http-equiv="Content-Security-Policy" |
| 106 | + content="default-src 'none'; |
| 107 | + font-src ${webview.cspSource}; |
| 108 | + script-src 'self' 'unsafe-inline'; |
| 109 | + style-src 'self' 'unsafe-inline' ${webview.cspSource}; |
| 110 | + img-src ${webview.cspSource}" |
| 111 | + > |
| 112 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 113 | + <style> |
| 114 | + body.vscode-light #bg { |
| 115 | + content: url(${bgLogoLight}); |
| 116 | + opacity: 0.05; |
| 117 | + } |
| 118 | + body.vscode-dark #bg { |
| 119 | + content: url(${bgLogoDark}); |
| 120 | + opacity: 0.05; |
| 121 | + } |
| 122 | + body.vscode-light #codewhispererLogo { |
| 123 | + content: url(${cwLogoLight}) |
| 124 | + } |
| 125 | + body.vscode-dark #codewhispererLogo { |
| 126 | + content: url(${cwLogoDark}) |
| 127 | + } |
| 128 | + body { |
| 129 | + height: 100vh; |
| 130 | + } |
| 131 | + #bg { |
| 132 | + position: fixed; |
| 133 | + left: 70%; |
| 134 | + top: -10%; |
| 135 | + overflow: hidden; |
| 136 | + transform: scale(2); |
| 137 | + pointer-events:none; |
| 138 | + user-select: none; |
| 139 | + } |
| 140 | + #sendToQButton { |
| 141 | + background: linear-gradient(14deg, rgba(52,20,120,1) 0%, rgba(91,41,196,1) 25%, rgba(117,55,247,1) 50%, rgba(73,125,254,1) 75%, rgba(170,233,255,1) 100%); |
| 142 | + color: white; |
| 143 | + border-radius: 6px; |
| 144 | + border: none; |
| 145 | + font-size: 20px; |
| 146 | + padding: 0.5em 1em; |
| 147 | + text-align: center; |
| 148 | + cursor: pointer; |
| 149 | + } |
| 150 | + #wrapper { |
| 151 | + height: 100%; |
| 152 | + width: 100%; |
| 153 | + min-width: 600px; |
| 154 | + overflow-y: auto; |
| 155 | + overflow-x: auto; |
| 156 | + display: flex; |
| 157 | + flex-direction: row; |
| 158 | + justify-content: center; |
| 159 | + align-items: center; |
| 160 | + } |
| 161 | + #content { |
| 162 | + max-width: 550px; |
| 163 | + padding: 30px; |
| 164 | + display: flex; |
| 165 | + flex-direction: column; |
| 166 | + gap: 30px; |
| 167 | + align-items: center; |
| 168 | + } |
| 169 | + #codewhisperer { |
| 170 | + display: flex; |
| 171 | + align-items: center; |
| 172 | + flex-direction: row; |
| 173 | + gap: 40px; |
| 174 | + flex-wrap: nowrap; |
| 175 | + } |
| 176 | + #codewhisperer div p { |
| 177 | + margin: 0px; |
| 178 | + font-size: 12pt; |
| 179 | + } |
| 180 | + #qLogo { |
| 181 | + width: 70px |
| 182 | + } |
| 183 | + #imageContainer { |
| 184 | + width: 40px; |
| 185 | + height: auto; |
| 186 | + flex-shrink: 0; |
| 187 | + flex-grow: 0; |
| 188 | + } |
| 189 | + #textWrapper { |
| 190 | + flex-shrink: 1; |
| 191 | + flex-grow: 1; |
| 192 | + } |
| 193 | + #header { |
| 194 | + text-align: center; |
| 195 | + margin: 0; |
| 196 | + } |
| 197 | + a { |
| 198 | + cursor: pointer; |
| 199 | + } |
| 200 | + .spacingrow { |
| 201 | + display: flex; |
| 202 | + flex-direction: row; |
| 203 | + gap: 40px; |
| 204 | + flex-wrap: nowrap; |
| 205 | + } |
| 206 | + </style> |
| 207 | + </head> |
| 208 | + <body> |
| 209 | + <img id="bg"> |
| 210 | + <div id="wrapper"> |
| 211 | + <div id="content"> |
| 212 | + <img id="qLogo" src="${logo}"/> |
| 213 | + <h1 id="header">Hello! I'm Amazon Q, your generative AI assistant.</h1> |
| 214 | + <div id="buttonContainer"> |
| 215 | + <button id="sendToQButton">Ask a question</button> |
| 216 | + </div> |
| 217 | + <!-- spacing --> |
| 218 | + <div class="spacingrow"> </div> |
| 219 | + <div class="spacingrow"> </div> |
| 220 | + <!-- end spacing --> |
| 221 | + <div id="codewhisperer"> |
| 222 | + <div id="imageContainer"> |
| 223 | + <img id="codewhispererLogo"/> |
| 224 | + </div> |
| 225 | + <div id="textWrapper"> |
| 226 | + <p>CodeWhisperer inline suggestions are also enabled.<br><a id="goToHelpLink">Try examples</a></p> |
| 227 | + </div> |
| 228 | + </div> |
| 229 | + </div> |
| 230 | + </div> |
| 231 | + <script> |
| 232 | + (function() { |
| 233 | + const vscode = acquireVsCodeApi() |
| 234 | + const sendToQ = () => { vscode.postMessage({ command: "sendToQ" }) } |
| 235 | + const goToHelp = () => { vscode.postMessage({ command: "goToHelp" }) } |
| 236 | + const sendToQButton = document.getElementById('sendToQButton') |
| 237 | + sendToQButton.onclick = sendToQ |
| 238 | + const goToHelpLink = document.getElementById('goToHelpLink') |
| 239 | + goToHelpLink.onclick = goToHelp |
| 240 | + }()) |
| 241 | + </script> |
| 242 | + </body> |
| 243 | + </html> |
| 244 | + ` |
| 245 | +} |
0 commit comments