2026-03-04 07:09:31 +00:00
|
|
|
<template>
|
2026-03-04 12:06:20 +00:00
|
|
|
<div class="chat-fullscreen">
|
2026-06-12 05:04:42 -04:00
|
|
|
<!-- Close button + connection indicator (desktop: top-right pill) -->
|
2026-06-12 06:01:24 -04:00
|
|
|
<div class="chat-mode-pill hidden md:flex">
|
2026-03-11 13:45:59 +00:00
|
|
|
<button class="chat-close-btn" :aria-label="t('chat.closeAssistant')" @click="closeChat">
|
2026-03-11 13:04:31 +00:00
|
|
|
<svg class="w-4 h-4" aria-hidden="true" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
2026-03-04 12:06:20 +00:00
|
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
2026-03-04 07:09:31 +00:00
|
|
|
</svg>
|
2026-03-11 13:45:59 +00:00
|
|
|
<span class="text-xs font-medium">{{ t('chat.close') }}</span>
|
2026-03-04 12:06:20 +00:00
|
|
|
</button>
|
2026-06-12 05:04:42 -04:00
|
|
|
<div
|
|
|
|
|
v-if="aiuiConnected"
|
|
|
|
|
class="w-2 h-2 rounded-full bg-green-400 ml-2 shadow-[0_0_6px_rgba(74,222,128,0.5)]"
|
|
|
|
|
:title="t('chat.aiuiConnected')"
|
|
|
|
|
/>
|
2026-06-12 06:01:24 -04:00
|
|
|
</div>
|
2026-06-12 05:04:42 -04:00
|
|
|
|
2026-07-30 20:19:28 -04:00
|
|
|
<!-- Loading indicator while iframe loads. pointer-events:none on the
|
|
|
|
|
wrapper (see <style>) so this never blocks clicks reaching the
|
|
|
|
|
iframe underneath even while shown; the bounded timeout below
|
|
|
|
|
(see aiuiLoadTimedOut) additionally guarantees it disappears
|
|
|
|
|
outright regardless of backend/handshake state, so it can never
|
|
|
|
|
wedge the UI permanently. -->
|
2026-03-04 14:34:02 +00:00
|
|
|
<Transition name="fade">
|
2026-07-30 20:19:28 -04:00
|
|
|
<div v-if="aiuiUrl && !aiuiConnected && !aiuiLoadTimedOut" class="chat-loading" role="status" aria-live="polite">
|
2026-03-04 14:34:02 +00:00
|
|
|
<div class="glass-card p-8 flex flex-col items-center gap-4">
|
2026-03-11 13:04:31 +00:00
|
|
|
<div class="chat-loading-spinner" aria-hidden="true" />
|
2026-03-12 12:56:59 +00:00
|
|
|
<p class="text-sm text-white/60">{{ t('chat.loadingAssistant') }}</p>
|
2026-03-04 14:34:02 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Transition>
|
|
|
|
|
|
2026-03-05 08:24:56 +00:00
|
|
|
<!-- AIUI iframe — on mobile, leave room for close bar + tab bar at bottom -->
|
2026-03-04 12:06:20 +00:00
|
|
|
<iframe
|
|
|
|
|
v-if="aiuiUrl"
|
|
|
|
|
ref="aiuiFrame"
|
|
|
|
|
:src="aiuiUrl"
|
2026-03-11 13:45:59 +00:00
|
|
|
:title="t('chat.aiAssistant')"
|
2026-03-05 08:24:56 +00:00
|
|
|
class="chat-iframe chat-iframe-mobile"
|
2026-03-04 12:06:20 +00:00
|
|
|
allow="microphone"
|
|
|
|
|
style="background: transparent"
|
|
|
|
|
/>
|
|
|
|
|
|
2026-06-12 05:04:42 -04:00
|
|
|
<!-- Fallback when no AIUI URL configured -->
|
|
|
|
|
<div v-else class="chat-placeholder">
|
|
|
|
|
<div class="chat-placeholder-inner">
|
2026-03-04 12:06:20 +00:00
|
|
|
<div class="chat-placeholder-icon">
|
2026-03-11 13:04:31 +00:00
|
|
|
<svg class="w-8 h-8 text-white/40" aria-hidden="true" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
2026-03-04 12:06:20 +00:00
|
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />
|
|
|
|
|
</svg>
|
|
|
|
|
</div>
|
2026-03-11 13:45:59 +00:00
|
|
|
<h2 class="text-2xl font-semibold text-white mb-2">{{ t('chat.aiAssistant') }}</h2>
|
2026-06-12 05:04:42 -04:00
|
|
|
<p class="text-white/60 mb-4 leading-relaxed">
|
2026-03-11 13:45:59 +00:00
|
|
|
{{ t('chat.notConfigured') }}
|
2026-03-04 12:06:20 +00:00
|
|
|
</p>
|
2026-06-12 05:04:42 -04:00
|
|
|
<p class="text-xs text-white/30">
|
2026-03-11 13:45:59 +00:00
|
|
|
{{ t('chat.deployCta') }}
|
2026-03-04 12:06:20 +00:00
|
|
|
</p>
|
2026-03-04 07:09:31 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-05 08:24:56 +00:00
|
|
|
|
2026-03-04 07:09:31 +00:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-08-03 16:45:33 -04:00
|
|
|
import { ref, computed, onActivated, onBeforeUnmount, onDeactivated, onMounted, watch } from 'vue'
|
|
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
2026-03-11 13:45:59 +00:00
|
|
|
import { useI18n } from 'vue-i18n'
|
2026-03-04 12:06:20 +00:00
|
|
|
import { ContextBroker } from '@/services/contextBroker'
|
2026-06-22 16:34:12 -04:00
|
|
|
import { IS_DEMO } from '@/composables/useDemoIntro'
|
2026-03-04 12:06:20 +00:00
|
|
|
|
2026-03-11 13:45:59 +00:00
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
2026-03-04 12:06:20 +00:00
|
|
|
const router = useRouter()
|
2026-08-03 16:45:33 -04:00
|
|
|
const route = useRoute()
|
2026-03-04 12:06:20 +00:00
|
|
|
const aiuiFrame = ref<HTMLIFrameElement | null>(null)
|
2026-06-12 05:04:42 -04:00
|
|
|
const aiuiConnected = ref(false)
|
2026-07-30 20:19:28 -04:00
|
|
|
// Belt-and-suspenders backstop (2026-07-30 live-testing follow-up): the
|
|
|
|
|
// loading overlay must never be able to wedge the UI permanently regardless
|
|
|
|
|
// of AIUI/backend state — a broken handshake, a misconfigured origin, or the
|
|
|
|
|
// AI provider being unreachable must not leave the user staring at a
|
|
|
|
|
// spinner forever with no way to interact with the panel underneath. This
|
|
|
|
|
// timeout dismisses the overlay unconditionally after a bounded wait even if
|
|
|
|
|
// 'ready' never arrives; it does not affect aiuiConnected itself (the
|
|
|
|
|
// connection indicator dot still reflects the real state).
|
|
|
|
|
const AIUI_LOAD_TIMEOUT_MS = 8000
|
|
|
|
|
const aiuiLoadTimedOut = ref(false)
|
|
|
|
|
let loadTimeout: ReturnType<typeof setTimeout> | null = null
|
2026-03-04 12:06:20 +00:00
|
|
|
let broker: ContextBroker | null = null
|
|
|
|
|
|
2026-07-30 18:26:52 -04:00
|
|
|
// D-14 presentation flags (Phase 02 Plan 07, 02-AIUI-D14.md): AIUI opens
|
|
|
|
|
// already expanded (chatExpanded) and, on a mobile viewport, on its chat view
|
|
|
|
|
// rather than its context view (mobileChat). Both are static strings — never
|
|
|
|
|
// derived from a reactive viewport read, connection state, or timestamp — so
|
|
|
|
|
// the computed below has no reactive dependencies and its value never
|
|
|
|
|
// changes after first evaluation, which is exactly what keeps the iframe
|
|
|
|
|
// `src` byte-identical across re-renders, resizes, and deactivate/reactivate
|
|
|
|
|
// cycles (the load-bearing constraint that lets the AIUI panel survive a tab
|
|
|
|
|
// switch without reloading). AIUI decides how to apply mobileChat against its
|
|
|
|
|
// own viewport rather than neode-ui's, per 02-AIUI-D14.md's D-14b rationale.
|
|
|
|
|
const D14_FLAGS = 'chatExpanded=true&mobileChat=true'
|
|
|
|
|
|
2026-03-04 12:06:20 +00:00
|
|
|
const aiuiUrl = computed(() => {
|
2026-06-22 16:34:12 -04:00
|
|
|
// Demo: ?mockArchy makes AIUI use its built-in mock node data (apps, system,
|
|
|
|
|
// network, wallet, bitcoin, files) and &seed pre-loads the example chats.
|
|
|
|
|
const demo = IS_DEMO ? '&mockArchy=1&seed=1' : ''
|
2026-03-04 12:06:20 +00:00
|
|
|
const envUrl = import.meta.env.VITE_AIUI_URL
|
2026-07-30 18:26:52 -04:00
|
|
|
if (envUrl) return `${envUrl}?embedded=true&hideClose=true&${D14_FLAGS}${demo}`
|
|
|
|
|
if (import.meta.env.PROD || IS_DEMO) return `/aiui/?embedded=true&hideClose=true&${D14_FLAGS}${demo}`
|
2026-03-04 12:06:20 +00:00
|
|
|
return ''
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-03 16:45:33 -04:00
|
|
|
// ⌘K → "Talk to AIUI about it" hands the typed text over as `?ask=`.
|
|
|
|
|
//
|
|
|
|
|
// It is delivered by postMessage, NOT by adding a query param to `aiuiUrl`.
|
|
|
|
|
// That is deliberate: the comment on D14_FLAGS above explains that aiuiUrl must
|
|
|
|
|
// have no reactive dependencies so the iframe `src` stays byte-identical and
|
|
|
|
|
// AIUI survives a tab switch. Threading `ask` through the URL would rebuild the
|
|
|
|
|
// src on every question and reload AIUI, discarding the conversation — the
|
|
|
|
|
// exact opposite of what this feature is for.
|
|
|
|
|
//
|
|
|
|
|
// The ask is queued rather than sent directly, because the common case is
|
|
|
|
|
// arriving from ⌘K on a cold Chat tab where the iframe has not handshaked yet.
|
|
|
|
|
// `ready` flushes it.
|
|
|
|
|
const pendingAsk = ref('')
|
|
|
|
|
|
|
|
|
|
function flushAsk() {
|
|
|
|
|
const text = pendingAsk.value
|
|
|
|
|
if (!text || !aiuiConnected.value) return
|
|
|
|
|
const frame = aiuiFrame.value
|
|
|
|
|
if (!frame?.contentWindow || !aiuiUrl.value) return
|
|
|
|
|
let targetOrigin: string
|
|
|
|
|
try {
|
|
|
|
|
targetOrigin = new URL(aiuiUrl.value, window.location.origin).origin
|
|
|
|
|
} catch { return }
|
|
|
|
|
frame.contentWindow.postMessage({ type: 'chat:prefill', text }, targetOrigin)
|
|
|
|
|
pendingAsk.value = ''
|
|
|
|
|
// Drop ask/askedAt from the URL so a refresh or a back-nav does not re-ask.
|
|
|
|
|
const { ask: _a, askedAt: _t, ...rest } = route.query
|
|
|
|
|
router.replace({ path: route.path, query: rest })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => route.query.askedAt,
|
|
|
|
|
() => {
|
|
|
|
|
const ask = route.query.ask
|
|
|
|
|
if (!ask) return
|
|
|
|
|
pendingAsk.value = String(ask)
|
|
|
|
|
flushAsk()
|
|
|
|
|
},
|
|
|
|
|
{ immediate: true },
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-04 12:06:20 +00:00
|
|
|
function closeChat() {
|
|
|
|
|
if (window.history.length > 1) {
|
|
|
|
|
router.back()
|
|
|
|
|
} else {
|
|
|
|
|
router.push('/dashboard')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 14:34:02 +00:00
|
|
|
function onAiuiMessage(event: MessageEvent) {
|
|
|
|
|
if (!aiuiUrl.value) return
|
2026-03-04 14:38:25 +00:00
|
|
|
// Validate origin — only accept messages from AIUI
|
|
|
|
|
try {
|
|
|
|
|
const expected = new URL(aiuiUrl.value, window.location.origin).origin
|
|
|
|
|
if (event.origin !== expected) return
|
|
|
|
|
} catch { return }
|
2026-03-14 04:14:04 +00:00
|
|
|
// Listen for ready messages from AIUI iframe
|
|
|
|
|
if (event.data?.type === 'ready') {
|
2026-06-12 05:04:42 -04:00
|
|
|
aiuiConnected.value = true
|
2026-07-30 20:19:28 -04:00
|
|
|
if (loadTimeout) { clearTimeout(loadTimeout); loadTimeout = null }
|
2026-08-03 16:45:33 -04:00
|
|
|
// A ⌘K ask that arrived before the handshake is waiting — send it now.
|
|
|
|
|
flushAsk()
|
2026-03-04 14:34:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-30 15:04:41 -04:00
|
|
|
// The window message listener and the ContextBroker are only-while-visible:
|
|
|
|
|
// Chat is a main tab that survives a tab switch (KeepAlive), so both follow
|
|
|
|
|
// activation rather than mount. Idempotent — remove/stop any existing
|
|
|
|
|
// listener/broker before starting a new one, so two consecutive activations
|
|
|
|
|
// (Vue fires onActivated on first mount too) never double-arm either.
|
|
|
|
|
// `aiuiConnected` is set by a one-time 'ready' message from the iframe; once
|
|
|
|
|
// the iframe survives deactivation that message will not be re-sent on
|
|
|
|
|
// re-entry, so it must NOT be reset on deactivate.
|
|
|
|
|
function armChatLive() {
|
|
|
|
|
window.removeEventListener('message', onAiuiMessage)
|
2026-03-04 14:34:02 +00:00
|
|
|
window.addEventListener('message', onAiuiMessage)
|
2026-07-30 15:04:41 -04:00
|
|
|
broker?.stop()
|
|
|
|
|
broker = null
|
2026-03-04 12:06:20 +00:00
|
|
|
if (aiuiUrl.value) {
|
|
|
|
|
broker = new ContextBroker(aiuiFrame, aiuiUrl.value)
|
|
|
|
|
broker.start()
|
|
|
|
|
}
|
2026-07-30 20:19:28 -04:00
|
|
|
if (loadTimeout) clearTimeout(loadTimeout)
|
|
|
|
|
loadTimeout = null
|
|
|
|
|
if (aiuiUrl.value && !aiuiConnected.value) {
|
|
|
|
|
loadTimeout = setTimeout(() => {
|
|
|
|
|
aiuiLoadTimedOut.value = true
|
|
|
|
|
loadTimeout = null
|
|
|
|
|
}, AIUI_LOAD_TIMEOUT_MS)
|
|
|
|
|
}
|
2026-07-30 15:04:41 -04:00
|
|
|
}
|
|
|
|
|
onActivated(() => armChatLive())
|
|
|
|
|
|
|
|
|
|
onDeactivated(() => {
|
|
|
|
|
window.removeEventListener('message', onAiuiMessage)
|
|
|
|
|
broker?.stop()
|
|
|
|
|
broker = null
|
2026-07-30 20:19:28 -04:00
|
|
|
if (loadTimeout) { clearTimeout(loadTimeout); loadTimeout = null }
|
2026-03-04 12:06:20 +00:00
|
|
|
})
|
|
|
|
|
|
2026-07-30 15:04:41 -04:00
|
|
|
// onActivated is a no-op outside a <KeepAlive> boundary — call it directly
|
|
|
|
|
// here too so a bare mount (a unit test, or any future non-KeepAlive usage)
|
|
|
|
|
// still gets the listener and the AIUI ContextBroker. Idempotent, so the
|
|
|
|
|
// redundant pass this causes on a KeepAlive-wrapped first mount is harmless.
|
|
|
|
|
onMounted(() => armChatLive())
|
|
|
|
|
|
2026-03-04 12:06:20 +00:00
|
|
|
onBeforeUnmount(() => {
|
2026-03-04 14:34:02 +00:00
|
|
|
window.removeEventListener('message', onAiuiMessage)
|
2026-03-04 12:06:20 +00:00
|
|
|
broker?.stop()
|
|
|
|
|
broker = null
|
2026-07-30 20:19:28 -04:00
|
|
|
if (loadTimeout) { clearTimeout(loadTimeout); loadTimeout = null }
|
2026-03-04 12:06:20 +00:00
|
|
|
})
|
2026-03-04 07:09:31 +00:00
|
|
|
</script>
|
2026-03-04 14:34:02 +00:00
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.chat-loading {
|
|
|
|
|
position: absolute;
|
|
|
|
|
inset: 0;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
z-index: 10;
|
2026-07-30 20:19:28 -04:00
|
|
|
/* Never let the loading state itself block interaction with the iframe
|
|
|
|
|
underneath — it has no interactive content of its own, so there is
|
|
|
|
|
nothing here that needs to capture clicks. */
|
|
|
|
|
pointer-events: none;
|
2026-03-04 14:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat-loading-spinner {
|
|
|
|
|
width: 32px;
|
|
|
|
|
height: 32px;
|
|
|
|
|
border: 3px solid rgba(255, 255, 255, 0.1);
|
|
|
|
|
border-top-color: #fb923c;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
animation: spin 0.8s linear infinite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@keyframes spin {
|
|
|
|
|
to { transform: rotate(360deg); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.fade-enter-active,
|
|
|
|
|
.fade-leave-active {
|
|
|
|
|
transition: opacity 0.3s ease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.fade-enter-from,
|
|
|
|
|
.fade-leave-to {
|
|
|
|
|
opacity: 0;
|
|
|
|
|
}
|
2026-03-11 13:04:31 +00:00
|
|
|
|
2026-03-04 14:34:02 +00:00
|
|
|
</style>
|