|
70 | 70 |
|
71 | 71 | const { isStreaming, chatMessages, currentMessageSnapshot, lastError } = storeToRefs(chatStore);
|
72 | 72 |
|
73 |
| - return {isStreaming, chatMessages, lastError, currentMessageSnapshot, chatStore, connectionStore} |
| 73 | + const { isConnected } = storeToRefs(connectionStore); |
| 74 | +
|
| 75 | + return {isStreaming, chatMessages, lastError, currentMessageSnapshot, chatStore, connectionStore, isConnected} |
74 | 76 | },
|
75 | 77 | data() {
|
76 | 78 | return {
|
77 | 79 | isOpen: false,
|
78 | 80 | userInput: '',
|
79 | 81 | sessionId: uuidv4(),
|
| 82 | + awaitingConnection: !this.isConnected, |
80 | 83 | isLoading: false,
|
81 | 84 | obpApiHost: null,
|
82 | 85 | isLoggedIn: null,
|
|
117 | 120 | try {
|
118 | 121 | token = await getOpeyJWT()
|
119 | 122 | } catch (error) {
|
| 123 | + console.log('Error creating JWT for opey: ', error) |
120 | 124 | this.errorState = true
|
121 | 125 | ElMessage({
|
122 | 126 | message: 'Error getting Opey JWT token',
|
123 | 127 | type: 'error'
|
124 | 128 | });
|
125 |
| - console.log(error) |
126 |
| - token = '' |
| 129 | + |
127 | 130 | }
|
128 | 131 |
|
129 | 132 | // Establish the WebSocket connection
|
130 | 133 | console.log('Establishing WebSocket connection');
|
131 |
| - this.connectionStore.connect(token) |
| 134 | + try{ |
| 135 | + this.connectionStore.connect(token) |
| 136 | + } catch (error) { |
| 137 | + console.log('Error establishing WebSocket connection: ', error) |
| 138 | + this.errorState = true |
| 139 | + ElMessage({ |
| 140 | + message: 'Error establishing WebSocket connection', |
| 141 | + type: 'error' |
| 142 | + }); |
| 143 | + } |
132 | 144 |
|
133 | 145 | },
|
134 | 146 | async sendMessage() {
|
|
257 | 269 | <span>Chat with Opey</span>
|
258 | 270 | <img alt="Powered by OpenAI" src="@/assets/powered-by-openai-badge-outlined-on-dark.svg" height="32">
|
259 | 271 | </div>
|
260 |
| - <div v-if="this.isLoggedIn" class="chat-messages" ref="messages"> |
| 272 | + <div v-if="this.isLoggedIn" v-loading="this.awaitingConnection" element-loading-text="Awaiting Connection..." class="chat-messages" ref="messages"> |
261 | 273 | <div v-for="(message, index) in chatMessages" :key="index" :class="['chat-message', message.role]">
|
262 | 274 | <div v-if="(this.isStreaming)&&(index === this.chatMessages.length -1)">
|
263 | 275 | <div v-html="renderMarkdown(this.currentMessageSnapshot)"></div>
|
|
300 | 312 | <div class="dot"></div>
|
301 | 313 | <div class="dot"></div>
|
302 | 314 | </div>
|
| 315 | + |
| 316 | + |
303 | 317 | </div>
|
304 | 318 | <div v-else class="chat-messages">
|
305 | 319 | <p>Opey is only availabled when logged in. <a v-bind:href="'/api/connect'">Log In</a> </p>
|
|
317 | 331 | placeholder="Type your message..."
|
318 | 332 | @keypress="submitEnter"
|
319 | 333 | type="textarea"
|
320 |
| - :disabled="!isLoggedIn ? '' : disabled" |
| 334 | + :disabled="!isLoggedIn || this.awaitingConnection ? '' : disabled" |
321 | 335 | >
|
322 | 336 | </el-input>
|
323 | 337 | <!--<textarea v-model="userInput" placeholder="Type your message..." @keypress="submitEnter"></textarea>-->
|
324 | 338 | <button
|
325 | 339 | @click="sendMessage"
|
326 |
| - :disabled="!isLoggedIn ? '' : disabled" |
327 |
| - :style="!isLoggedIn ? 'background-color:#929292; cursor:not-allowed' : ''" |
| 340 | + :disabled="!isLoggedIn || this.awaitingConnection ? '' : disabled" |
| 341 | + :style="!isLoggedIn || this.awaitingConnection ? 'background-color:#929292; cursor:not-allowed' : ''" |
328 | 342 | >
|
329 | 343 | Send
|
330 | 344 | </button>
|
|
0 commit comments