File size: 6,985 Bytes
cf9ada6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
class AiChat extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
max-width: 720px;
margin: 0 auto;
padding: 20px;
border: 1px solid #e5e7eb;
border-radius: 12px;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
}
.header {
font-size: 16px;
margin-top: 0;
margin-bottom: 10px;
}
.description {
color: rgb(107, 114, 128);
font-size: 15px;
margin-bottom: 20px;
}
.context-buttons {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 16px;
}
.context-button {
padding: 6px 12px;
border: none;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
}
.context-button:hover {
opacity: 0.9;
}
.chat-container {
margin-bottom: 16px;
padding: 16px;
border: 1px solid #e5e7eb;
border-radius: 8px;
background: #f9fafb;
height: 384px;
overflow-y: auto;
font-family: 'SF Mono', 'Roboto Mono', monospace;
font-size: 14px;
}
.message {
margin-bottom: 8px;
max-width: 80%;
}
.user-message {
margin-left: auto;
text-align: right;
}
.ai-message {
margin-right: auto;
text-align: left;
}
.message-content {
display: inline-block;
padding: 10px 12px;
border-radius: 8px;
}
.user-message .message-content {
background: #ebf5ff;
border-right: 3px solid #2563eb;
}
.ai-message .message-content {
background: #f3f4f6;
border-left: 3px solid #3b82f6;
}
.input-area {
display: flex;
}
.message-input {
flex: 1;
padding: 8px 12px;
border: 1px solid #e5e7eb;
border-radius: 8px 0 0 8px;
font-size: 14px;
}
.send-button {
padding: 8px 16px;
background: #3b82f6;
color: white;
border: none;
border-radius: 0 8px 8px 0;
cursor: pointer;
}
.send-button:hover {
background: #2563eb;
}
.command-buttons {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 8px;
margin-top: 16px;
}
.command-button {
padding: 8px 12px;
background: #f3f4f6;
border: none;
border-radius: 6px;
font-size: 14px;
cursor: pointer;
}
.command-button:hover {
background: #e5e7eb;
}
.typing-indicator {
text-align: left;
margin-bottom: 8px;
}
.typing-indicator .message-content {
background: #f3f4f6;
border-left: 3px solid #3b82f6;
}
</style>
<h1 class="header">AI Development Assistant</h1>
<p class="description">Smart coding help and automation</p>
<div class="context-buttons">
<button class="context-button" style="background: #374151; color: white;" data-context="hacking">Hacking</button>
<button class="context-button" style="background: #3b82f6; color: white;" data-context="integration">Integration</button>
<button class="context-button" style="background: #10b981; color: white;" data-context="debugging">Debugging</button>
<button class="context-button" style="background: #8b5cf6; color: white;" data-context="automation">Automation</button>
</div>
<div class="chat-container" id="chatContainer">
<!-- Messages will be added here -->
</div>
<div class="input-area">
<input type="text" class="message-input" id="messageInput" placeholder="Type your message or command...">
<button class="send-button" id="sendButton">Send</button>
</div>
<div class="command-buttons">
<button class="command-button" data-command="/explain">/explain</button>
<button class="command-button" data-command="/code">/code</button>
<button class="command-button" data-command="/api">/api</button>
<button class="command-button" data-command="/fix">/fix</button>
</div>
`;
this.initializeChat();
}
initializeChat() {
this.currentContext = 'general';
this.chatContainer = this.shadowRoot.getElementById('chatContainer');
this.messageInput = this.shadowRoot.getElementById('messageInput');
this.sendButton = this.shadowRoot.getElementById('sendButton');
// Add event listeners
this.sendButton.addEventListener('click', () => this.sendMessage());
this.messageInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
this.sendMessage();
}
});
// Context buttons
const contextButtons = this.shadowRoot.querySelectorAll('.context-button');
contextButtons.forEach(button => {
button.addEventListener('click', () => {
this.setContext(button.dataset.context);
});
});
// Command buttons
const commandButtons = this.shadowRoot.querySelectorAll('.command-button');
commandButtons.forEach(button => {
button.addEventListener('click', () => {
this.insertCommand(button.dataset.command);
});
});
// Initial welcome message
this.addMessage('ai', `👋 Welcome to DevAssistant!
I can help with:
- API Integrations (REST, GraphQL, WebSockets)
- Debugging (Chrome DevTools, Wireshark)
- Security (Burp Suite, OWASP ZAP)
- Automation (Selenium, Puppeteer)
Try commands like:
• /explain [concept] - Get detailed explanations
• /code [language] - Generate code samples
• /api [service] - Get API integration help
• /fix [error] - Debug and fix issues
Or click the context buttons above!`);
}
addMessage(sender, text) {
const messageDiv = document.createElement('div');
messageDiv.classList.add('message');
if (sender === 'user') {
messageDiv.classList.add('user-message');
messageDiv.innerHTML = `<div class="message-content">${this.escapeHtml(text)}</div>`;
} else {
messageDiv.classList.add('ai-message');
messageDiv.innerHTML = `<div class="message-content">${this.formatMessage(text)}</div>`;
}
this.chatContainer.appendChild(messageDiv);
this.chatContainer.scrollTop = this.chatContainer.scrollHeight;
}
formatMessage(text) {
// Simple formatting for code blocks
return text.replace(/ |