website-builder-backend / frontend /scripts /06_ai_chat_workspace.sh
David Prince
fix: add all missing local module stubs (remote_mcp_registry, mcp_auth, mcp_transport, etc)
cce8120
Raw
History Blame Contribute Delete
1.65 kB
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(pwd)"
mkdir -p components/chat
cat > components/chat/ProductionAIChat.jsx <<'EOC'
"use client";
import { useState } from "react";
const API =
process.env.NEXT_PUBLIC_API_URL ||
"http://127.0.0.1:8000";
export default function ProductionAIChat(){
const [prompt,setPrompt]=useState("");
const [messages,setMessages]=useState([]);
async function send(){
if(!prompt.trim()) return;
const user={
role:"user",
content:prompt
};
setMessages(v=>[...v,user]);
const res=await fetch(API+"/api/workspace/chat/message",{
method:"POST",
headers:{
"Content-Type":"application/json"
},
body:JSON.stringify({
message:prompt
})
});
const data=await res.json();
setMessages(v=>[
...v,
{
role:"assistant",
content:
data.message ||
data.response ||
JSON.stringify(data)
}
]);
setPrompt("");
}
return(
<div className="flex flex-col h-full bg-[#111827]">
<div className="flex-1 overflow-auto p-4 space-y-3">
{messages.map((m,i)=>(
<div
key={i}
className={
m.role==="assistant"
?
"bg-slate-700 rounded p-3"
:
"bg-blue-700 rounded p-3"
}
>
{m.content}
</div>
))}
</div>
<div className="border-t border-slate-700 p-3 flex gap-2">
<input
className="flex-1 rounded bg-slate-900 p-2"
value={prompt}
onChange={e=>setPrompt(e.target.value)}
placeholder="Ask Dolor3V..."
/>
<button
onClick={send}
className="bg-blue-600 px-4 rounded"
>
Send
</button>
</div>
</div>
);
}
EOC
cat > components/chat/index.js <<'EOC'
export {default} from "./ProductionAIChat";
EOC
echo "[1/4] Verify..."
test -f components/chat/ProductionAIChat.jsx
test -f components/chat/index.js
echo "[2/4] AI workspace installed."