Some checks are pending
E2E / Playwright e2e (push) Waiting to run
- Added support for managing AI models within the AI assistant settings. - Introduced new hosted mail setup component for streamlined email configuration. - Updated environment variables for local development and proxy settings. - Enhanced error handling and user feedback in the chat page for API connectivity issues. - Improved routing for AI-related API calls in the Next.js configuration. - Added documentation for local development and agent management in CLAUDE.md.
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
"use client"
|
|
|
|
import { useEffect, useMemo, useRef } from "react"
|
|
import type { AiChatContext } from "@/lib/ai/chat-context"
|
|
import { buildEmbedSearchParams } from "@/lib/ai/chat-context"
|
|
import { buildAiEmbedUrl, resolveAiEmbedOrigin } from "@/lib/ai/embed-url"
|
|
import { useTheme } from "next-themes"
|
|
|
|
type AiChatIframeProps = {
|
|
publicPath?: string
|
|
context: AiChatContext
|
|
className?: string
|
|
}
|
|
|
|
export function AiChatIframe({ publicPath = "/ai", context, className }: AiChatIframeProps) {
|
|
const iframeRef = useRef<HTMLIFrameElement>(null)
|
|
const { resolvedTheme } = useTheme()
|
|
const embedOrigin = useMemo(() => resolveAiEmbedOrigin(publicPath), [publicPath])
|
|
const src = useMemo(() => {
|
|
const qs = buildEmbedSearchParams(context)
|
|
return buildAiEmbedUrl(publicPath, qs)
|
|
}, [publicPath, context])
|
|
|
|
useEffect(() => {
|
|
const iframe = iframeRef.current
|
|
if (!iframe?.contentWindow || !embedOrigin) return
|
|
iframe.contentWindow.postMessage(
|
|
{ type: "ULTI_THEME", theme: resolvedTheme === "dark" ? "dark" : "light" },
|
|
embedOrigin
|
|
)
|
|
}, [resolvedTheme, embedOrigin])
|
|
|
|
useEffect(() => {
|
|
const iframe = iframeRef.current
|
|
if (!iframe?.contentWindow || !embedOrigin) return
|
|
iframe.contentWindow.postMessage(
|
|
{
|
|
type: "ULTI_CONTEXT_UPDATE",
|
|
context,
|
|
systemPrompt: context.systemPromptExtra,
|
|
},
|
|
embedOrigin
|
|
)
|
|
}, [context, embedOrigin])
|
|
|
|
return (
|
|
<iframe
|
|
ref={iframeRef}
|
|
title="UltiAI"
|
|
src={src}
|
|
className={className}
|
|
sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-downloads"
|
|
allow="clipboard-read; clipboard-write"
|
|
/>
|
|
)
|
|
}
|