Spaces:
Running
import gradio as gr
Browse filesimport os
import sqlite3
import json
from typing import List, Dict, Any
from huggingface_hub import InferenceClient
import requests
from datetime import datetime
import hashlib
# Persistent memory setup using HF Spaces /data mount
MEMORY_DB = "/data/memory.db"
def init_memory():
"""Initialize persistent SQLite memory database"""
os.makedirs(os.path.dirname(MEMORY_DB), exist_ok=True)
conn = sqlite3.connect(MEMORY_DB)
conn.execute("""
CREATE TABLE IF NOT EXISTS conversations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id TEXT,
role TEXT,
content TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
embedding_hash TEXT
)
""")
conn.commit()
conn.close()
def save_memory(session_id: str, role: str, content: str):
"""Save conversation to persistent memory"""
content_hash = hashlib.md5(content.encode()).hexdigest()
conn = sqlite3.connect(MEMORY_DB)
conn.execute(
"INSERT INTO conversations (session_id, role, content, embedding_hash) VALUES (?, ?, ?, ?)",
(session_id, role, content, content_hash)
)
conn.commit()
conn.close()
def load_memory(session_id: str, limit: int = 10) -> List[Dict[str, str]]:
"""Load recent conversation history from persistent memory"""
conn = sqlite3.connect(MEMORY_DB)
cursor = conn.execute(
"SELECT role, content FROM conversations WHERE session_id = ? ORDER BY timestamp DESC LIMIT ?",
(session_id, limit)
)
history = [{"role": row[0], "content": row[1]} for row in cursor.fetchall()]
conn.close()
return list(reversed(history)) # Return oldest first
# Uncensored web search tool (Tavily API - get free key at tavily.com)
TAVILY_API_KEY = os.getenv("TAVILY_API_KEY", "your-tavily-key-here")
async def web_search(query: str) -> str:
"""Uncensored web search with full content extraction"""
if not TAVILY_API_KEY or TAVILY_API_KEY == "your-tavily-key-here":
return "Web search unavailable - add TAVILY_API_KEY to Space secrets"
url = "https://api.tavily.com/search"
payload = {
"api_key": TAVILY_API_KEY,
"query": query,
"search_depth": "advanced",
"include_answer": True,
"include_raw_content": True,
"max_results": 5
}
try:
response = requests.post(url, json=payload, timeout=10)
data = response.json()
results = []
for result in data.get("results", []):
results.append(f"**{result['title']}**
{result['content'][:500]}...
{result['url']}")
return "
".join(results)
except Exception as e:
return f"Search error: {str(e)}"
# Document upload processing (RAG-style)
from PyPDF2 import PdfReader
import docx
def process_document(file_path: str) -> str:
"""Extract text from uploaded documents"""
text = ""
try:
if file_path.endswith('.pdf'):
reader = PdfReader(file_path)
for page in reader.pages:
text += page.extract_text() + "
"
elif file_path.endswith('.docx'):
doc = docx.Document(file_path)
for para in doc.paragraphs:
text += para.text + "
"
elif file_path.endswith(('.txt', '.md')):
with open(file_path, 'r', encoding='utf-8') as f:
text = f.read()
return text[:4000] # Truncate for context
except:
return "Could not process document"
# Monaco Editor Component for code generation
def create_monaco_editor():
"""Monaco editor HTML/JS component for vibe-coding"""
return gr.HTML("""
<div id="monaco-container" style="height: 400px; border: 1px solid #ccc;"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.44.0/min/vs/loader.min.js"></script>
<script>
require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.44.0/min/vs' } });
require(['vs/editor/editor.main'], function() {
const editor = monaco.editor.create(document.getElementById('monaco-container'), {
value: '// AI-generated code will appear here\
// Start coding your vibe...',
language: 'python',
theme: 'vs-dark',
automaticLayout: true
});
window.monacoEditor = editor;
});
</script>
""")
# Main agent response function with tools
def agent_respond(
message: str,
history: List[Dict[str, str]],
system_message: str,
session_id: str,
documents: List[str],
max_tokens: int,
temperature: float,
top_p: float,
hf_token: gr.OAuthToken,
use_editor: bool = False
):
init_memory()
# Load persistent memory
memory_history = load_memory(session_id)
full_history = memory_history + history
# Process uploaded documents
doc_context = ""
for doc_file in documents:
if doc_file:
doc_context += process_document(doc_file) + "
"
# Enhanced system prompt with tools
tools_prompt = """
You are an advanced AI agent with these tools:
1. **web_search(query)** - Search web (uncensored, any content)
2. **process_docs** - Analyze uploaded documents
3. **code_editor** - Generate/edit code in Monaco editor
Format tool calls as: [TOOL_NAME: parameter="value"]
Available context:
""" + doc_context
enhanced_system = system_message + tools_prompt
messages = [{"role": "system", "content": enhanced_system}]
messages.extend(full_history)
messages.append({"role": "user", "content": message})
client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
# First pass: tool detection and execution
tool_response = ""
for chunk in client.chat_completion(
messages,
max_tokens=512,
stream=True,
temperature=0.1, # Low temp for tool detection
top_p=0.9,
):
if len(chunk.choices) and chunk.choices[0].delta.content:
tool_response += chunk.choices[0].delta.content
# Parse and execute tools
final_message = tool_response
if "[web_search:" in tool_response:
query_start = tool_response.find("[web_search:") + 12
query_end = tool_response.find("]", query_start)
query = tool_response[query_start:query_end].strip().strip('"')
search_results = gr.try_async(web_search)(query)
final_message = f"π Web search results for '{query}':
{search_results}
"
if use_editor and "code" in tool_response.lower():
final_message += "
π» Code generated - check Monaco editor below!"
# Save to persistent memory
save_memory(session_id, "user", message)
save_memory(session_id, "assistant", final_message)
# Second pass: generate final response with tool results
messages[-1]["content"] = message + "
" + final_message
response = ""
for chunk in client.chat_completion(
messages,
max_tokens=max_tokens,
stream=True,
temperature=temperature,
top_p=top_p,
):
if len(chunk.choices) and chunk.choices[0].delta.content:
token = chunk.choices[0].delta.content
response += token
yield response
# Gradio interface with all features
with gr.Blocks(title="AI Agent Workspace") as demo:
gr.Markdown("# π Advanced AI Agent with Tools & Persistent Memory")
with gr.Row():
with gr.Column(scale=2):
chatbot = gr.Chatbot(height=500)
with gr.Row():
msg = gr.Textbox(placeholder="Message your AI Agent...", scale=3)
submit = gr.Button("Send", variant="primary")
# Session management
with gr.Row():
session_id = gr.Textbox("session_001", label="Session ID", interactive=True)
clear_memory = gr.Button("π§Ή Clear Session Memory")
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### π Document Upload (RAG)")
doc_upload = gr.File(
file_count="multiple",
file_types=[".pdf", ".docx", ".txt", ".md"],
label="Upload documents for analysis"
)
process_docs = gr.Button("Process Documents")
with gr.Column(scale=2):
gr.Markdown("### π Tools & Settings")
system_msg = gr.Textbox(
value="You are an advanced AI agent. Use tools when needed.",
label="System Prompt",
lines=3
)
use_editor_cb = gr.Checkbox(label="Enable Code Editor", value=True)
with gr.Row():
max_tokens = gr.Slider(1, 2048, 512, step=1, label="Max Tokens")
temperature = gr.Slider(0.1, 4.0, 0.7, step=0.1, label="Temperature")
top_p = gr.Slider(0.1, 1.0, 0.95, step=0.05, label="Top-p")
# Monaco Code Editor
if use_editor_cb.value:
code_editor = create_monaco_editor()
# Event handlers
def process_and_respond(message, history, session_id, documents):
for response in agent_respond(
message, history, system_msg.value,
session_id, documents, max_tokens.value,
temperature.value, top_p.value, gr.State({}),
use_editor_cb.value
):
yield response, history + [{"role": "user", "content": message}, {"role": "assistant", "content": response}]
submit.click(
process_and_respond,
inputs=[msg, chatbot, session_id, doc_upload],
outputs=[msg, chatbot]
)
clear_memory.click(
lambda: [], outputs=chatbot
).then(
lambda sid: [], inputs=[session_id], outputs=[chatbot]
)
# Sidebar auth
with gr.Sidebar():
gr.Markdown("### π Setup Instructions")
gr.Markdown("""
1. Add **TAVILY_API_KEY** to Space secrets (free tier available)
2. Upgrade to **Persistent Storage** in Settings β survives restarts
3. Enable **Public** for sharing or **Private** for exclusive use
4. HF_TOKE
- README.md +7 -4
- components/chat-interface.js +236 -0
- components/navbar.js +65 -0
- components/sidebar.js +133 -0
- components/tools-panel.js +233 -0
- index.html +66 -19
- script.js +81 -0
- style.css +75 -19
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title: Synapse Coder Studio
|
| 3 |
-
emoji: π
|
| 4 |
colorFrom: yellow
|
| 5 |
-
colorTo:
|
|
|
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Synapse Coder Studio π€
|
|
|
|
| 3 |
colorFrom: yellow
|
| 4 |
+
colorTo: gray
|
| 5 |
+
emoji: π³
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://huggingface.co/deepsite).
|
|
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomChatInterface extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
:host {
|
| 7 |
+
display: flex;
|
| 8 |
+
flex-direction: column;
|
| 9 |
+
height: 100%;
|
| 10 |
+
position: relative;
|
| 11 |
+
}
|
| 12 |
+
.chat-history {
|
| 13 |
+
flex: 1;
|
| 14 |
+
overflow-y: auto;
|
| 15 |
+
padding: 1.5rem;
|
| 16 |
+
display: flex;
|
| 17 |
+
flex-direction: column;
|
| 18 |
+
gap: 1.5rem;
|
| 19 |
+
}
|
| 20 |
+
.message {
|
| 21 |
+
display: flex;
|
| 22 |
+
gap: 1rem;
|
| 23 |
+
max-width: 85%;
|
| 24 |
+
animation: fadeIn 0.3s ease-out;
|
| 25 |
+
}
|
| 26 |
+
.message.user {
|
| 27 |
+
align-self: flex-end;
|
| 28 |
+
flex-direction: row-reverse;
|
| 29 |
+
}
|
| 30 |
+
.message.ai {
|
| 31 |
+
align-self: flex-start;
|
| 32 |
+
}
|
| 33 |
+
.avatar {
|
| 34 |
+
width: 40px;
|
| 35 |
+
height: 40px;
|
| 36 |
+
border-radius: 0.5rem;
|
| 37 |
+
flex-shrink: 0;
|
| 38 |
+
}
|
| 39 |
+
.msg-bubble {
|
| 40 |
+
padding: 1rem;
|
| 41 |
+
border-radius: 1rem;
|
| 42 |
+
font-size: 0.95rem;
|
| 43 |
+
line-height: 1.5;
|
| 44 |
+
position: relative;
|
| 45 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
| 46 |
+
}
|
| 47 |
+
.user .msg-bubble {
|
| 48 |
+
background: #6366f1;
|
| 49 |
+
color: white;
|
| 50 |
+
border-bottom-right-radius: 0.25rem;
|
| 51 |
+
}
|
| 52 |
+
.ai .msg-bubble {
|
| 53 |
+
background: #1e293b;
|
| 54 |
+
color: #e2e8f0;
|
| 55 |
+
border: 1px solid #334155;
|
| 56 |
+
border-bottom-left-radius: 0.25rem;
|
| 57 |
+
}
|
| 58 |
+
.input-area {
|
| 59 |
+
padding: 1.5rem;
|
| 60 |
+
background: #0f172a;
|
| 61 |
+
border-top: 1px solid #334155;
|
| 62 |
+
display: flex;
|
| 63 |
+
gap: 1rem;
|
| 64 |
+
align-items: flex-end;
|
| 65 |
+
}
|
| 66 |
+
textarea {
|
| 67 |
+
flex: 1;
|
| 68 |
+
background: #1e293b;
|
| 69 |
+
border: 1px solid #334155;
|
| 70 |
+
color: white;
|
| 71 |
+
padding: 0.75rem;
|
| 72 |
+
border-radius: 0.5rem;
|
| 73 |
+
resize: none;
|
| 74 |
+
height: 50px;
|
| 75 |
+
min-height: 50px;
|
| 76 |
+
max-height: 150px;
|
| 77 |
+
font-family: inherit;
|
| 78 |
+
}
|
| 79 |
+
textarea:focus {
|
| 80 |
+
outline: none;
|
| 81 |
+
border-color: #6366f1;
|
| 82 |
+
}
|
| 83 |
+
.send-btn {
|
| 84 |
+
background: #6366f1;
|
| 85 |
+
color: white;
|
| 86 |
+
border: none;
|
| 87 |
+
width: 50px;
|
| 88 |
+
height: 50px;
|
| 89 |
+
border-radius: 0.5rem;
|
| 90 |
+
display: flex;
|
| 91 |
+
align-items: center;
|
| 92 |
+
justify-content: center;
|
| 93 |
+
cursor: pointer;
|
| 94 |
+
transition: background 0.2s;
|
| 95 |
+
}
|
| 96 |
+
.send-btn:hover {
|
| 97 |
+
background: #4f46e5;
|
| 98 |
+
}
|
| 99 |
+
.send-btn:disabled {
|
| 100 |
+
background: #334155;
|
| 101 |
+
cursor: not-allowed;
|
| 102 |
+
}
|
| 103 |
+
@keyframes fadeIn {
|
| 104 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 105 |
+
to { opacity: 1; transform: translateY(0); }
|
| 106 |
+
}
|
| 107 |
+
.typing-indicator span {
|
| 108 |
+
display: inline-block;
|
| 109 |
+
width: 6px;
|
| 110 |
+
height: 6px;
|
| 111 |
+
background-color: #94a3b8;
|
| 112 |
+
border-radius: 50%;
|
| 113 |
+
animation: typing 0.6s infinite;
|
| 114 |
+
margin: 0 2px;
|
| 115 |
+
}
|
| 116 |
+
@keyframes typing {
|
| 117 |
+
0%, 100% { transform: translateY(0); }
|
| 118 |
+
50% { transform: translateY(-3px); }
|
| 119 |
+
}
|
| 120 |
+
</style>
|
| 121 |
+
|
| 122 |
+
<div class="chat-history" id="chat-history">
|
| 123 |
+
<!-- Messages will be injected here -->
|
| 124 |
+
<div class="message ai">
|
| 125 |
+
<img src="http://static.photos/technology/200x200/5" class="avatar" alt="AI">
|
| 126 |
+
<div class="msg-bubble">
|
| 127 |
+
Hello! I am Synapse, your AI coding assistant. I can help you search the web, analyze documents, or generate code. What's on your mind today?
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|
| 130 |
+
</div>
|
| 131 |
+
|
| 132 |
+
<div class="input-area">
|
| 133 |
+
<textarea id="msg-input" placeholder="Type a message... (Shift+Enter for new line)"></textarea>
|
| 134 |
+
<button id="send-btn" class="send-btn">
|
| 135 |
+
<i data-feather="send"></i>
|
| 136 |
+
</button>
|
| 137 |
+
</div>
|
| 138 |
+
`;
|
| 139 |
+
|
| 140 |
+
const chatHistory = this.shadowRoot.getElementById('chat-history');
|
| 141 |
+
const msgInput = this.shadowRoot.getElementById('msg-input');
|
| 142 |
+
const sendBtn = this.shadowRoot.getElementById('send-btn');
|
| 143 |
+
let isProcessing = false;
|
| 144 |
+
|
| 145 |
+
const addMessage = (role, text) => {
|
| 146 |
+
const msgDiv = document.createElement('div');
|
| 147 |
+
msgDiv.className = `message ${role}`;
|
| 148 |
+
|
| 149 |
+
const avatarUrl = role === 'user'
|
| 150 |
+
? 'http://static.photos/people/200x200/12'
|
| 151 |
+
: 'http://static.photos/technology/200x200/5';
|
| 152 |
+
|
| 153 |
+
// Simple markdown-like parsing for bold/newlines
|
| 154 |
+
const formattedText = text
|
| 155 |
+
.replace(/\n/g, '<br>')
|
| 156 |
+
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
| 157 |
+
.replace(/\*(.*?)\*/g, '<em>$1</em>');
|
| 158 |
+
|
| 159 |
+
msgDiv.innerHTML = `
|
| 160 |
+
<img src="${avatarUrl}" class="avatar" alt="${role}">
|
| 161 |
+
<div class="msg-bubble message-content">${formattedText}</div>
|
| 162 |
+
`;
|
| 163 |
+
chatHistory.appendChild(msgDiv);
|
| 164 |
+
chatHistory.scrollTop = chatHistory.scrollHeight;
|
| 165 |
+
};
|
| 166 |
+
|
| 167 |
+
const showTyping = () => {
|
| 168 |
+
const typingDiv = document.createElement('div');
|
| 169 |
+
typingDiv.className = 'message ai typing-msg';
|
| 170 |
+
typingDiv.innerHTML = `
|
| 171 |
+
<img src="http://static.photos/technology/200x200/5" class="avatar" alt="AI">
|
| 172 |
+
<div class="msg-bubble typing-indicator">
|
| 173 |
+
<span></span><span></span><span></span>
|
| 174 |
+
</div>
|
| 175 |
+
`;
|
| 176 |
+
chatHistory.appendChild(typingDiv);
|
| 177 |
+
chatHistory.scrollTop = chatHistory.scrollHeight;
|
| 178 |
+
return typingDiv;
|
| 179 |
+
};
|
| 180 |
+
|
| 181 |
+
const handleSend = async () => {
|
| 182 |
+
const text = msgInput.value.trim();
|
| 183 |
+
if (!text || isProcessing) return;
|
| 184 |
+
|
| 185 |
+
addMessage('user', text);
|
| 186 |
+
msgInput.value = '';
|
| 187 |
+
msgInput.style.height = '50px'; // Reset height
|
| 188 |
+
isProcessing = true;
|
| 189 |
+
sendBtn.disabled = true;
|
| 190 |
+
|
| 191 |
+
// Save to Memory
|
| 192 |
+
if(window.MemoryDB) window.MemoryDB.save('user', text);
|
| 193 |
+
|
| 194 |
+
// Show typing indicator
|
| 195 |
+
const typingEl = showTyping();
|
| 196 |
+
|
| 197 |
+
// Get Response
|
| 198 |
+
try {
|
| 199 |
+
const response = await window.Agent.respond(text);
|
| 200 |
+
typingEl.remove();
|
| 201 |
+
addMessage('ai', response);
|
| 202 |
+
if(window.MemoryDB) window.MemoryDB.save('assistant', response);
|
| 203 |
+
} catch (error) {
|
| 204 |
+
typingEl.remove();
|
| 205 |
+
addMessage('ai', "Sorry, I encountered an error connecting to the neural net.");
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
isProcessing = false;
|
| 209 |
+
sendBtn.disabled = false;
|
| 210 |
+
msgInput.focus();
|
| 211 |
+
};
|
| 212 |
+
|
| 213 |
+
sendBtn.addEventListener('click', handleSend);
|
| 214 |
+
msgInput.addEventListener('keypress', (e) => {
|
| 215 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
| 216 |
+
e.preventDefault();
|
| 217 |
+
handleSend();
|
| 218 |
+
}
|
| 219 |
+
});
|
| 220 |
+
|
| 221 |
+
// Auto-resize textarea
|
| 222 |
+
msgInput.addEventListener('input', function() {
|
| 223 |
+
this.style.height = 'auto';
|
| 224 |
+
this.style.height = (this.scrollHeight) + 'px';
|
| 225 |
+
});
|
| 226 |
+
|
| 227 |
+
// Listen for clear memory event
|
| 228 |
+
window.appEvents.addEventListener('memory-cleared', () => {
|
| 229 |
+
chatHistory.innerHTML = '';
|
| 230 |
+
addMessage('ai', 'Session memory cleared. Ready for a new topic.');
|
| 231 |
+
});
|
| 232 |
+
|
| 233 |
+
feather.replace();
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
customElements.define('custom-chat-interface', CustomChatInterface);
|
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomNavbar extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
:host {
|
| 7 |
+
display: flex;
|
| 8 |
+
align-items: center;
|
| 9 |
+
justify-content: space-between;
|
| 10 |
+
padding: 0 1.5rem;
|
| 11 |
+
height: 100%;
|
| 12 |
+
background: rgba(15, 23, 42, 0.9);
|
| 13 |
+
border-bottom: 1px solid #334155;
|
| 14 |
+
}
|
| 15 |
+
.logo {
|
| 16 |
+
font-size: 1.25rem;
|
| 17 |
+
font-weight: 700;
|
| 18 |
+
color: #6366f1; /* Indigo-500 */
|
| 19 |
+
display: flex;
|
| 20 |
+
align-items: center;
|
| 21 |
+
gap: 0.5rem;
|
| 22 |
+
text-decoration: none;
|
| 23 |
+
}
|
| 24 |
+
.user-profile {
|
| 25 |
+
display: flex;
|
| 26 |
+
align-items: center;
|
| 27 |
+
gap: 0.75rem;
|
| 28 |
+
}
|
| 29 |
+
.avatar {
|
| 30 |
+
width: 36px;
|
| 31 |
+
height: 36px;
|
| 32 |
+
border-radius: 50%;
|
| 33 |
+
object-fit: cover;
|
| 34 |
+
border: 2px solid #6366f1;
|
| 35 |
+
}
|
| 36 |
+
.status-badge {
|
| 37 |
+
font-size: 0.75rem;
|
| 38 |
+
padding: 0.25rem 0.5rem;
|
| 39 |
+
border-radius: 999px;
|
| 40 |
+
background: rgba(16, 185, 129, 0.2);
|
| 41 |
+
color: #34d399;
|
| 42 |
+
display: flex;
|
| 43 |
+
align-items: center;
|
| 44 |
+
gap: 0.25rem;
|
| 45 |
+
}
|
| 46 |
+
.status-dot {
|
| 47 |
+
width: 6px;
|
| 48 |
+
height: 6px;
|
| 49 |
+
background: #34d399;
|
| 50 |
+
border-radius: 50%;
|
| 51 |
+
}
|
| 52 |
+
</style>
|
| 53 |
+
<a href="#" class="logo">
|
| 54 |
+
<i data-feather="cpu"></i> Synapse Studio
|
| 55 |
+
</a>
|
| 56 |
+
<div class="user-profile">
|
| 57 |
+
<div class="status-badge">
|
| 58 |
+
<span class="status-dot"></span> Online
|
| 59 |
+
</div>
|
| 60 |
+
<img src="http://static.photos/people/200x200/12" alt="User" class="avatar">
|
| 61 |
+
</div>
|
| 62 |
+
`;
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
customElements.define('custom-navbar', CustomNavbar);
|
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomSidebar extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
:host {
|
| 7 |
+
display: flex;
|
| 8 |
+
flex-direction: column;
|
| 9 |
+
padding: 1.5rem;
|
| 10 |
+
gap: 2rem;
|
| 11 |
+
overflow-y: auto;
|
| 12 |
+
background: rgba(30, 41, 59, 0.5);
|
| 13 |
+
}
|
| 14 |
+
h3 {
|
| 15 |
+
font-size: 0.875rem;
|
| 16 |
+
text-transform: uppercase;
|
| 17 |
+
letter-spacing: 0.05em;
|
| 18 |
+
color: #94a3b8;
|
| 19 |
+
margin-bottom: 1rem;
|
| 20 |
+
display: flex;
|
| 21 |
+
align-items: center;
|
| 22 |
+
gap: 0.5rem;
|
| 23 |
+
}
|
| 24 |
+
.control-group {
|
| 25 |
+
margin-bottom: 1.5rem;
|
| 26 |
+
}
|
| 27 |
+
label {
|
| 28 |
+
display: block;
|
| 29 |
+
font-size: 0.75rem;
|
| 30 |
+
margin-bottom: 0.5rem;
|
| 31 |
+
color: #cbd5e1;
|
| 32 |
+
}
|
| 33 |
+
input[type="text"], textarea, select {
|
| 34 |
+
width: 100%;
|
| 35 |
+
background: #0f172a;
|
| 36 |
+
border: 1px solid #334155;
|
| 37 |
+
color: white;
|
| 38 |
+
padding: 0.5rem;
|
| 39 |
+
border-radius: 0.375rem;
|
| 40 |
+
font-size: 0.875rem;
|
| 41 |
+
margin-bottom: 0.5rem;
|
| 42 |
+
box-sizing: border-box;
|
| 43 |
+
}
|
| 44 |
+
input[type="text"]:focus, textarea:focus, select:focus {
|
| 45 |
+
outline: none;
|
| 46 |
+
border-color: #6366f1;
|
| 47 |
+
box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
|
| 48 |
+
}
|
| 49 |
+
input[type="range"] {
|
| 50 |
+
width: 100%;
|
| 51 |
+
accent-color: #6366f1;
|
| 52 |
+
}
|
| 53 |
+
.range-value {
|
| 54 |
+
font-size: 0.75rem;
|
| 55 |
+
float: right;
|
| 56 |
+
color: #6366f1;
|
| 57 |
+
}
|
| 58 |
+
button.btn-block {
|
| 59 |
+
width: 100%;
|
| 60 |
+
padding: 0.5rem;
|
| 61 |
+
background: #334155;
|
| 62 |
+
color: white;
|
| 63 |
+
border: none;
|
| 64 |
+
border-radius: 0.375rem;
|
| 65 |
+
cursor: pointer;
|
| 66 |
+
transition: all 0.2s;
|
| 67 |
+
display: flex;
|
| 68 |
+
justify-content: center;
|
| 69 |
+
align-items: center;
|
| 70 |
+
gap: 0.5rem;
|
| 71 |
+
}
|
| 72 |
+
button.btn-block:hover {
|
| 73 |
+
background: #475569;
|
| 74 |
+
}
|
| 75 |
+
button.btn-danger {
|
| 76 |
+
background: rgba(239, 68, 68, 0.1);
|
| 77 |
+
color: #f87171;
|
| 78 |
+
border: 1px solid rgba(239, 68, 68, 0.2);
|
| 79 |
+
}
|
| 80 |
+
button.btn-danger:hover {
|
| 81 |
+
background: rgba(239, 68, 68, 0.2);
|
| 82 |
+
}
|
| 83 |
+
</style>
|
| 84 |
+
|
| 85 |
+
<div class="control-group">
|
| 86 |
+
<h3><i data-feather="database"></i> Session</h3>
|
| 87 |
+
<label>Session ID</label>
|
| 88 |
+
<input type="text" id="session-id" value="session_001">
|
| 89 |
+
</div>
|
| 90 |
+
|
| 91 |
+
<div class="control-group">
|
| 92 |
+
<h3><i data-feather="terminal"></i> Agent Settings</h3>
|
| 93 |
+
<label>System Prompt</label>
|
| 94 |
+
<textarea id="system-prompt" rows="3">You are an advanced AI agent. Use tools when needed.</textarea>
|
| 95 |
+
|
| 96 |
+
<label>Max Tokens <span class="range-value" id="tokens-val">512</span></label>
|
| 97 |
+
<input type="range" min="128" max="2048" value="512" id="max-tokens">
|
| 98 |
+
|
| 99 |
+
<label>Temperature <span class="range-value" id="temp-val">0.7</span></label>
|
| 100 |
+
<input type="range" min="0" max="1" step="0.1" value="0.7" id="temperature">
|
| 101 |
+
|
| 102 |
+
<label>Top-p <span class="range-value" id="topp-val">0.95</span></label>
|
| 103 |
+
<input type="range" min="0" max="1" step="0.05" value="0.95" id="top-p">
|
| 104 |
+
</div>
|
| 105 |
+
|
| 106 |
+
<div class="control-group" style="margin-top: auto;">
|
| 107 |
+
<button id="clear-mem" class="btn-block btn-danger">
|
| 108 |
+
<i data-feather="trash-2"></i> Clear Memory
|
| 109 |
+
</button>
|
| 110 |
+
</div>
|
| 111 |
+
`;
|
| 112 |
+
|
| 113 |
+
// Event Listeners for Range Sliders
|
| 114 |
+
this.shadowRoot.getElementById('max-tokens').addEventListener('input', (e) => {
|
| 115 |
+
this.shadowRoot.getElementById('tokens-val').textContent = e.target.value;
|
| 116 |
+
});
|
| 117 |
+
this.shadowRoot.getElementById('temperature').addEventListener('input', (e) => {
|
| 118 |
+
this.shadowRoot.getElementById('temp-val').textContent = e.target.value;
|
| 119 |
+
});
|
| 120 |
+
this.shadowRoot.getElementById('top-p').addEventListener('input', (e) => {
|
| 121 |
+
this.shadowRoot.getElementById('topp-val').textContent = e.target.value;
|
| 122 |
+
});
|
| 123 |
+
|
| 124 |
+
// Clear Memory Logic
|
| 125 |
+
this.shadowRoot.getElementById('clear-mem').addEventListener('click', () => {
|
| 126 |
+
if(window.MemoryDB) window.MemoryDB.clear();
|
| 127 |
+
});
|
| 128 |
+
|
| 129 |
+
// Replace Icons
|
| 130 |
+
feather.replace();
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
customElements.define('custom-sidebar', CustomSidebar);
|
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomToolsPanel extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
:host {
|
| 7 |
+
display: flex;
|
| 8 |
+
flex-direction: column;
|
| 9 |
+
height: 100%;
|
| 10 |
+
background: rgba(15, 23, 42, 0.5);
|
| 11 |
+
}
|
| 12 |
+
.tabs {
|
| 13 |
+
display: flex;
|
| 14 |
+
border-bottom: 1px solid #334155;
|
| 15 |
+
}
|
| 16 |
+
.tab-btn {
|
| 17 |
+
flex: 1;
|
| 18 |
+
background: transparent;
|
| 19 |
+
border: none;
|
| 20 |
+
color: #94a3b8;
|
| 21 |
+
padding: 1rem;
|
| 22 |
+
cursor: pointer;
|
| 23 |
+
display: flex;
|
| 24 |
+
align-items: center;
|
| 25 |
+
justify-content: center;
|
| 26 |
+
gap: 0.5rem;
|
| 27 |
+
transition: all 0.2s;
|
| 28 |
+
}
|
| 29 |
+
.tab-btn:hover {
|
| 30 |
+
background: rgba(255, 255, 255, 0.05);
|
| 31 |
+
color: #e2e8f0;
|
| 32 |
+
}
|
| 33 |
+
.tab-btn.active {
|
| 34 |
+
color: #6366f1;
|
| 35 |
+
border-bottom: 2px solid #6366f1;
|
| 36 |
+
background: rgba(99, 102, 241, 0.05);
|
| 37 |
+
}
|
| 38 |
+
.panel-content {
|
| 39 |
+
flex: 1;
|
| 40 |
+
overflow: hidden;
|
| 41 |
+
display: none;
|
| 42 |
+
flex-direction: column;
|
| 43 |
+
}
|
| 44 |
+
.panel-content.active {
|
| 45 |
+
display: flex;
|
| 46 |
+
}
|
| 47 |
+
.upload-area {
|
| 48 |
+
flex: 1;
|
| 49 |
+
display: flex;
|
| 50 |
+
flex-direction: column;
|
| 51 |
+
align-items: center;
|
| 52 |
+
justify-content: center;
|
| 53 |
+
padding: 2rem;
|
| 54 |
+
border: 2px dashed #334155;
|
| 55 |
+
margin: 1rem;
|
| 56 |
+
border-radius: 0.5rem;
|
| 57 |
+
text-align: center;
|
| 58 |
+
color: #94a3b8;
|
| 59 |
+
cursor: pointer;
|
| 60 |
+
transition: border-color 0.2s;
|
| 61 |
+
}
|
| 62 |
+
.upload-area:hover {
|
| 63 |
+
border-color: #6366f1;
|
| 64 |
+
color: #818cf8;
|
| 65 |
+
}
|
| 66 |
+
#monaco-container {
|
| 67 |
+
width: 100%;
|
| 68 |
+
height: 100%;
|
| 69 |
+
padding: 1rem;
|
| 70 |
+
box-sizing: border-box;
|
| 71 |
+
}
|
| 72 |
+
.file-list {
|
| 73 |
+
padding: 0 1rem;
|
| 74 |
+
overflow-y: auto;
|
| 75 |
+
}
|
| 76 |
+
.file-item {
|
| 77 |
+
display: flex;
|
| 78 |
+
align-items: center;
|
| 79 |
+
gap: 0.5rem;
|
| 80 |
+
padding: 0.5rem;
|
| 81 |
+
background: #1e293b;
|
| 82 |
+
margin-bottom: 0.5rem;
|
| 83 |
+
border-radius: 0.25rem;
|
| 84 |
+
font-size: 0.875rem;
|
| 85 |
+
}
|
| 86 |
+
</style>
|
| 87 |
+
|
| 88 |
+
<div class="tabs">
|
| 89 |
+
<button class="tab-btn active" data-tab="0">
|
| 90 |
+
<i data-feather="file-text"></i> Docs
|
| 91 |
+
</button>
|
| 92 |
+
<button class="tab-btn" data-tab="1">
|
| 93 |
+
<i data-feather="code"></i> Code
|
| 94 |
+
</button>
|
| 95 |
+
</div>
|
| 96 |
+
|
| 97 |
+
<div id="panel-0" class="panel-content active">
|
| 98 |
+
<div class="upload-area" id="drop-zone">
|
| 99 |
+
<i data-feather="upload-cloud" style="width: 48px; height: 48px; margin-bottom: 1rem;"></i>
|
| 100 |
+
<p>Drag & Drop PDF/Docx/Txt</p>
|
| 101 |
+
<p style="font-size: 0.75rem; margin-top: 0.5rem;">or click to browse</p>
|
| 102 |
+
<input type="file" id="file-input" multiple style="display: none;">
|
| 103 |
+
</div>
|
| 104 |
+
<div class="file-list" id="file-list">
|
| 105 |
+
<!-- Uploaded files appear here -->
|
| 106 |
+
</div>
|
| 107 |
+
</div>
|
| 108 |
+
|
| 109 |
+
<div id="panel-1" class="panel-content">
|
| 110 |
+
<div id="monaco-container"></div>
|
| 111 |
+
</div>
|
| 112 |
+
`;
|
| 113 |
+
|
| 114 |
+
// Tab Logic
|
| 115 |
+
const tabs = this.shadowRoot.querySelectorAll('.tab-btn');
|
| 116 |
+
const panels = this.shadowRoot.querySelectorAll('.panel-content');
|
| 117 |
+
|
| 118 |
+
tabs.forEach(tab => {
|
| 119 |
+
tab.addEventListener('click', () => {
|
| 120 |
+
tabs.forEach(t => t.classList.remove('active'));
|
| 121 |
+
panels.forEach(p => p.classList.remove('active'));
|
| 122 |
+
|
| 123 |
+
tab.classList.add('active');
|
| 124 |
+
this.shadowRoot.getElementById(`panel-${tab.dataset.tab}`).classList.add('active');
|
| 125 |
+
|
| 126 |
+
// Resize Monaco if code tab is active
|
| 127 |
+
if(tab.dataset.tab === "1" && window.monacoEditor) {
|
| 128 |
+
window.monacoEditor.layout();
|
| 129 |
+
}
|
| 130 |
+
});
|
| 131 |
+
});
|
| 132 |
+
|
| 133 |
+
// File Upload Logic (Mock)
|
| 134 |
+
const dropZone = this.shadowRoot.getElementById('drop-zone');
|
| 135 |
+
const fileInput = this.shadowRoot.getElementById('file-input');
|
| 136 |
+
const fileList = this.shadowRoot.getElementById('file-list');
|
| 137 |
+
|
| 138 |
+
const handleFiles = (files) => {
|
| 139 |
+
Array.from(files).forEach(file => {
|
| 140 |
+
const item = document.createElement('div');
|
| 141 |
+
item.className = 'file-item';
|
| 142 |
+
item.innerHTML = `
|
| 143 |
+
<i data-feather="file"></i>
|
| 144 |
+
<span style="flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">${file.name}</span>
|
| 145 |
+
<i data-feather="check-circle" style="color: #34d399; width: 16px;"></i>
|
| 146 |
+
`;
|
| 147 |
+
fileList.prepend(item);
|
| 148 |
+
feather.replace();
|
| 149 |
+
});
|
| 150 |
+
};
|
| 151 |
+
|
| 152 |
+
dropZone.addEventListener('click', () => fileInput.click());
|
| 153 |
+
fileInput.addEventListener('change', (e) => handleFiles(e.target.files));
|
| 154 |
+
|
| 155 |
+
dropZone.addEventListener('dragover', (e) => {
|
| 156 |
+
e.preventDefault();
|
| 157 |
+
dropZone.style.borderColor = '#6366f1';
|
| 158 |
+
});
|
| 159 |
+
|
| 160 |
+
dropZone.addEventListener('dragleave', () => {
|
| 161 |
+
dropZone.style.borderColor = '#334155';
|
| 162 |
+
});
|
| 163 |
+
|
| 164 |
+
dropZone.addEventListener('drop', (e) => {
|
| 165 |
+
e.preventDefault();
|
| 166 |
+
dropZone.style.borderColor = '#334155';
|
| 167 |
+
handleFiles(e.dataTransfer.files);
|
| 168 |
+
});
|
| 169 |
+
|
| 170 |
+
// Monaco Editor Loader
|
| 171 |
+
this.loadMonaco();
|
| 172 |
+
|
| 173 |
+
// Listen for Switch Tab Event (from Script.js when code is generated)
|
| 174 |
+
window.appEvents.addEventListener('switch-tab', (e) => {
|
| 175 |
+
const index = e.detail.index;
|
| 176 |
+
tabs[index].click();
|
| 177 |
+
});
|
| 178 |
+
|
| 179 |
+
// Listen for Code Update
|
| 180 |
+
window.appEvents.addEventListener('update-code', (e) => {
|
| 181 |
+
if(window.monacoEditor) {
|
| 182 |
+
window.monacoEditor.setValue(e.detail.code);
|
| 183 |
+
}
|
| 184 |
+
});
|
| 185 |
+
|
| 186 |
+
feather.replace();
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
loadMonaco() {
|
| 190 |
+
if (document.getElementById('monaco-script')) return; // Already loaded
|
| 191 |
+
|
| 192 |
+
const script = document.createElement('script');
|
| 193 |
+
script.id = 'monaco-script';
|
| 194 |
+
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.44.0/min/vs/loader.min.js';
|
| 195 |
+
script.onload = () => {
|
| 196 |
+
require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.44.0/min/vs' } });
|
| 197 |
+
require(['vs/editor/editor.main'], function() {
|
| 198 |
+
// Delay slightly to ensure container is rendered and has dimensions
|
| 199 |
+
setTimeout(() => {
|
| 200 |
+
if(document.getElementById('monaco-container')) {
|
| 201 |
+
// Access shadow root container
|
| 202 |
+
const container = this.shadowRoot.getElementById('monaco-container');
|
| 203 |
+
// Actually, the require callback scope 'this' might be lost, but standard monaco usage usually targets global or ID
|
| 204 |
+
// We need to be careful with Shadow DOM and Monaco.
|
| 205 |
+
// Monaco appends to the body by default for overlays, but we want it inside our component.
|
| 206 |
+
// Simplest way for this demo: Target by ID inside ShadowDOM
|
| 207 |
+
|
| 208 |
+
// Because Monaco is a bit complex with ShadowDOM encapsulation (styles/events),
|
| 209 |
+
// we might need to use global or trick it.
|
| 210 |
+
// For this demo, let's attach to the specific ID if possible, or use window.monacoEditor for control.
|
| 211 |
+
|
| 212 |
+
// Note: Monaco doesn't fully support ShadowDOM out of the box easily without configuration tweaks.
|
| 213 |
+
// We will try to render it. If it fails, it might be due to the shadow root encapsulation blocking some global styles/events needed by Monaco's widget logic.
|
| 214 |
+
// To make it robust, we often put the monaco container *outside* or pass specific options.
|
| 215 |
+
|
| 216 |
+
// Let's try standard initialization on the element found in the shadowRoot of the custom element.
|
| 217 |
+
const host = document.querySelector('custom-tools-panel').shadowRoot.getElementById('monaco-container');
|
| 218 |
+
|
| 219 |
+
window.monacoEditor = monaco.editor.create(host, {
|
| 220 |
+
value: '# AI-generated code will appear here\n# Start coding your vibe...',
|
| 221 |
+
language: 'python',
|
| 222 |
+
theme: 'vs-dark',
|
| 223 |
+
automaticLayout: true,
|
| 224 |
+
minimap: { enabled: false }
|
| 225 |
+
});
|
| 226 |
+
}
|
| 227 |
+
}, 500);
|
| 228 |
+
}.bind(this));
|
| 229 |
+
};
|
| 230 |
+
document.head.appendChild(script);
|
| 231 |
+
}
|
| 232 |
+
}
|
| 233 |
+
customElements.define('custom-tools-panel', CustomToolsPanel);
|
|
@@ -1,19 +1,66 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en" class="dark">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Synapse Coder Studio</title>
|
| 7 |
+
<link rel="icon" type="image/x-icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>π€</text></svg>">
|
| 8 |
+
<link rel="stylesheet" href="style.css">
|
| 9 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 10 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 11 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 12 |
+
<script>
|
| 13 |
+
tailwind.config = {
|
| 14 |
+
darkMode: 'class',
|
| 15 |
+
theme: {
|
| 16 |
+
extend: {
|
| 17 |
+
colors: {
|
| 18 |
+
primary: '#6366f1', // Indigo 500
|
| 19 |
+
secondary: '#1e293b', // Slate 800
|
| 20 |
+
darkbg: '#0f172a', // Slate 900
|
| 21 |
+
surface: '#1e293b', // Slate 800
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
</script>
|
| 27 |
+
</head>
|
| 28 |
+
<body class="bg-darkbg text-slate-200 font-sans h-screen flex flex-col overflow-hidden">
|
| 29 |
+
|
| 30 |
+
<!-- Navbar -->
|
| 31 |
+
<custom-navbar class="h-16 flex-shrink-0 border-b border-slate-700 bg-slate-900/80 backdrop-blur-md z-20"></custom-navbar>
|
| 32 |
+
|
| 33 |
+
<!-- Main Layout -->
|
| 34 |
+
<div class="flex flex-1 overflow-hidden">
|
| 35 |
+
|
| 36 |
+
<!-- Sidebar (Settings & Session) -->
|
| 37 |
+
<custom-sidebar class="w-80 hidden md:flex flex-col border-r border-slate-700 bg-slate-800/50 backdrop-blur-sm z-10 transition-all duration-300 transform -translate-x-full md:translate-x-0 absolute md:relative h-full" id="sidebar">
|
| 38 |
+
</custom-sidebar>
|
| 39 |
+
|
| 40 |
+
<!-- Mobile Toggle for Sidebar -->
|
| 41 |
+
<button id="sidebar-toggle" class="md:hidden fixed bottom-4 left-4 z-50 bg-primary p-3 rounded-full shadow-lg text-white">
|
| 42 |
+
<i data-feather="settings"></i>
|
| 43 |
+
</button>
|
| 44 |
+
|
| 45 |
+
<!-- Chat Area -->
|
| 46 |
+
<main class="flex-1 flex flex-col relative min-w-0 bg-darkbg">
|
| 47 |
+
<custom-chat-interface class="flex flex-col h-full w-full"></custom-chat-interface>
|
| 48 |
+
</main>
|
| 49 |
+
|
| 50 |
+
<!-- Tools Panel (Docs & Editor) -->
|
| 51 |
+
<custom-tools-panel class="w-96 hidden lg:flex flex-col border-l border-slate-700 bg-slate-800/30 backdrop-blur-sm relative transition-all duration-300" id="tools-panel">
|
| 52 |
+
</custom-tools-panel>
|
| 53 |
+
</div>
|
| 54 |
+
|
| 55 |
+
<!-- Component Scripts -->
|
| 56 |
+
<script src="components/navbar.js"></script>
|
| 57 |
+
<script src="components/sidebar.js"></script>
|
| 58 |
+
<script src="components/chat-interface.js"></script>
|
| 59 |
+
<script src="components/tools-panel.js"></script>
|
| 60 |
+
|
| 61 |
+
<!-- Main Logic -->
|
| 62 |
+
<script src="script.js"></script>
|
| 63 |
+
<script>feather.replace();</script>
|
| 64 |
+
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 65 |
+
</body>
|
| 66 |
+
</html>
|
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 2 |
+
// Toggle Sidebar on Mobile
|
| 3 |
+
const toggleBtn = document.getElementById('sidebar-toggle');
|
| 4 |
+
const sidebar = document.getElementById('sidebar');
|
| 5 |
+
|
| 6 |
+
if(toggleBtn && sidebar) {
|
| 7 |
+
toggleBtn.addEventListener('click', () => {
|
| 8 |
+
sidebar.classList.toggle('-translate-x-full');
|
| 9 |
+
});
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
// Simulate Global Event Bus for Components
|
| 13 |
+
window.appEvents = new EventTarget();
|
| 14 |
+
|
| 15 |
+
// Mock API Keys (In real app, these would be env vars)
|
| 16 |
+
window.API_KEYS = {
|
| 17 |
+
TAVILY: 'tvly-XXXXXXXXX',
|
| 18 |
+
HUGGINGFACE: 'hf_XXXXXXXXX'
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
// Mock Memory (LocalStorage)
|
| 22 |
+
const MEMORY_KEY = 'synapse_memory_db';
|
| 23 |
+
|
| 24 |
+
window.MemoryDB = {
|
| 25 |
+
save: (role, content) => {
|
| 26 |
+
const history = JSON.parse(localStorage.getItem(MEMORY_KEY) || '[]');
|
| 27 |
+
history.push({ role, content, timestamp: new Date().toISOString() });
|
| 28 |
+
localStorage.setItem(MEMORY_KEY, JSON.stringify(history));
|
| 29 |
+
},
|
| 30 |
+
load: () => {
|
| 31 |
+
return JSON.parse(localStorage.getItem(MEMORY_KEY) || '[]');
|
| 32 |
+
},
|
| 33 |
+
clear: () => {
|
| 34 |
+
localStorage.removeItem(MEMORY_KEY);
|
| 35 |
+
const event = new Event('memory-cleared');
|
| 36 |
+
window.appEvents.dispatchEvent(event);
|
| 37 |
+
}
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
// AI Simulation Logic
|
| 41 |
+
window.Agent = {
|
| 42 |
+
respond: async (message, context = {}) => {
|
| 43 |
+
return new Promise((resolve) => {
|
| 44 |
+
// Determine if it needs tools (mock)
|
| 45 |
+
const lowerMsg = message.toLowerCase();
|
| 46 |
+
let response = "";
|
| 47 |
+
let toolUsed = null;
|
| 48 |
+
|
| 49 |
+
if (lowerMsg.includes('search') || lowerMsg.includes('find')) {
|
| 50 |
+
toolUsed = 'web_search';
|
| 51 |
+
response = `I've searched the web for "${message}".\n\n**Found:**\n- *Latest AI Trends 2024* - The rise of multimodal agents is reshaping interfaces...\n- *Quantum Computing* - Breakthrough in error correction...\n\nSource: https://tech-news.daily/ai-trends`;
|
| 52 |
+
} else if (lowerMsg.includes('code') || lowerMsg.includes('function') || lowerMsg.includes('python')) {
|
| 53 |
+
toolUsed = 'code_editor';
|
| 54 |
+
response = `I've generated the Python code you requested. Check the code editor panel.\n\nHere is a summary of the logic:\n1. Initialize the class.\n2. Define the main loop.\n3. Handle exceptions gracefully.`;
|
| 55 |
+
// Trigger code injection event
|
| 56 |
+
setTimeout(() => {
|
| 57 |
+
const codeEvent = new CustomEvent('update-code', {
|
| 58 |
+
detail: {
|
| 59 |
+
code: `import os\n\nclass Agent:\n def __init__(self, name):\n self.name = name\n print(f"Agent {name} initialized")\n\n def run(self):\n print("Running logic...")\n\nif __name__ == "__main__":\n agent = Agent("Synapse")\n agent.run()`
|
| 60 |
+
}
|
| 61 |
+
});
|
| 62 |
+
window.appEvents.dispatchEvent(codeEvent);
|
| 63 |
+
|
| 64 |
+
// Trigger tab switch
|
| 65 |
+
const switchTabEvent = new CustomEvent('switch-tab', { detail: { index: 1 } });
|
| 66 |
+
window.appEvents.dispatchEvent(switchTabEvent);
|
| 67 |
+
}, 1000);
|
| 68 |
+
} else if (lowerMsg.includes('doc') || lowerMsg.includes('file')) {
|
| 69 |
+
response = "I've analyzed the uploaded documents. It appears to be a specification sheet for the API integration. Key points include the endpoint structure and authentication method.";
|
| 70 |
+
} else {
|
| 71 |
+
response = `I understand. You said: "${message}".\n\nAs an AI Agent, I can help you search the web, analyze documents, or write code. How would you like to proceed?`;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// Simulate Network Delay
|
| 75 |
+
setTimeout(() => {
|
| 76 |
+
resolve(response);
|
| 77 |
+
}, 1500);
|
| 78 |
+
});
|
| 79 |
+
}
|
| 80 |
+
};
|
| 81 |
+
});
|
|
@@ -1,28 +1,84 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
}
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
font-size: 15px;
|
| 14 |
-
margin-bottom: 10px;
|
| 15 |
-
margin-top: 5px;
|
| 16 |
}
|
| 17 |
|
| 18 |
-
.
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
}
|
| 25 |
|
| 26 |
-
.
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Custom Scrollbar */
|
| 2 |
+
::-webkit-scrollbar {
|
| 3 |
+
width: 8px;
|
| 4 |
+
height: 8px;
|
| 5 |
+
}
|
| 6 |
+
::-webkit-scrollbar-track {
|
| 7 |
+
background: #0f172a;
|
| 8 |
+
}
|
| 9 |
+
::-webkit-scrollbar-thumb {
|
| 10 |
+
background: #334155;
|
| 11 |
+
border-radius: 4px;
|
| 12 |
+
}
|
| 13 |
+
::-webkit-scrollbar-thumb:hover {
|
| 14 |
+
background: #475569;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/* Animations */
|
| 18 |
+
@keyframes fadeIn {
|
| 19 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 20 |
+
to { opacity: 1; transform: translateY(0); }
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
@keyframes pulse-glow {
|
| 24 |
+
0%, 100% { box-shadow: 0 0 10px rgba(99, 102, 241, 0.2); }
|
| 25 |
+
50% { box-shadow: 0 0 20px rgba(99, 102, 241, 0.5); }
|
| 26 |
}
|
| 27 |
|
| 28 |
+
@keyframes typing {
|
| 29 |
+
0% { transform: translateY(0); }
|
| 30 |
+
50% { transform: translateY(-3px); }
|
| 31 |
+
100% { transform: translateY(0); }
|
| 32 |
}
|
| 33 |
|
| 34 |
+
.animate-fade-in {
|
| 35 |
+
animation: fadeIn 0.3s ease-out forwards;
|
|
|
|
|
|
|
|
|
|
| 36 |
}
|
| 37 |
|
| 38 |
+
.message-content code {
|
| 39 |
+
background-color: #1e293b;
|
| 40 |
+
padding: 2px 6px;
|
| 41 |
+
border-radius: 4px;
|
| 42 |
+
font-family: 'Courier New', Courier, monospace;
|
| 43 |
+
color: #e2e8f0;
|
| 44 |
}
|
| 45 |
|
| 46 |
+
.message-content pre {
|
| 47 |
+
background-color: #0f172a;
|
| 48 |
+
padding: 1rem;
|
| 49 |
+
border-radius: 0.5rem;
|
| 50 |
+
overflow-x: auto;
|
| 51 |
+
border: 1px solid #334155;
|
| 52 |
+
margin: 0.5rem 0;
|
| 53 |
}
|
| 54 |
+
|
| 55 |
+
.message-content pre code {
|
| 56 |
+
background-color: transparent;
|
| 57 |
+
padding: 0;
|
| 58 |
+
border: none;
|
| 59 |
+
color: #a5b4fc;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/* Loader */
|
| 63 |
+
.typing-indicator span {
|
| 64 |
+
display: inline-block;
|
| 65 |
+
width: 6px;
|
| 66 |
+
height: 6px;
|
| 67 |
+
background-color: #6366f1;
|
| 68 |
+
border-radius: 50%;
|
| 69 |
+
animation: typing 0.6s infinite;
|
| 70 |
+
margin: 0 2px;
|
| 71 |
+
}
|
| 72 |
+
.typing-indicator span:nth-child(2) {
|
| 73 |
+
animation-delay: 0.1s;
|
| 74 |
+
}
|
| 75 |
+
.typing-indicator span:nth-child(3) {
|
| 76 |
+
animation-delay: 0.2s;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/* Monaco Editor Container Fixes */
|
| 80 |
+
#monaco-container {
|
| 81 |
+
width: 100%;
|
| 82 |
+
height: 100%;
|
| 83 |
+
overflow: hidden;
|
| 84 |
+
}
|